Commit 36b228d
authored
feat(api): cute default box names (e.g. cozy-otter) (#853)
## Summary
Boxes created via the **cloud API** without an explicit name now get a
fun
default like `cozy-otter` instead of showing the bare box ID — drawn
from a
curated **80 adjective × 120 cute-animal** vocabulary (`nimble-otter`,
`cozy-quokka`, `brave-narwhal` …).
Scope: **apps/api only** (TypeScript). No Rust-core / local-SDK changes.
## Design decisions (per discussion)
- **Clean-first, box-id on collision.** The default is unsuffixed
(`cozy-otter`). Only when it hits the per-org
`@Unique(['organizationId','name'])` constraint do we fall back
**exactly
once** to `cozy-otter-{boxId}`. The box id is unique by construction,
so:
- common case = clean, no numbers, no id noise;
- the fallback **can never collide** → no retry loop, no namespace to
exhaust, works the same whether the org has 5 boxes or 50k.
- **Names stay unique** (Docker model). The cloud addresses boxes by *id
or
name* (`GET /boxes/:boxIdOrName`, stop/delete/resize/…), so duplicate
names
would make name-based ops ambiguous. Keeping `@Unique` means **zero DB
migration**.
- **Hyphen separator** — also a valid DNS label, in case box names ever
become
subdomains.
- **Both create paths covered**: fresh `insert` and warm-pool `claim`.
User-provided names are unchanged (one-shot, still 409 on conflict).
## Implementation
- `box-name-generator.ts`: `generateBoxName()` +
`persistWithGeneratedBoxName(boxId, persist)` — encapsulates the
generate → persist → id-fallback-on-23505 policy.
- `box.service.ts`: both `create` (insert) and `assignWarmPoolBox`
(update)
use it when no caller name is given, passing the box id.
## Test plan
- [x] `nx test api box-name-generator` — clean shape, variety,
clean-on-first,
id-appended-on-collision, no-fallback-on-unrelated-error
- [x] `nx build api` typechecks · `eslint` clean
- [ ] Dev smoke after merge: create a box without a name → expect e.g.
`cozy-otter` in the dashboard list
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **New Features**
* Automatically generate box names in an adjective-animal format when no
name is provided.
* **Bug Fixes**
* Improve uniqueness conflict handling during box creation, with clearer
messaging for caller-provided vs auto-generated names.
* Warm-pool box assignment now persists names more reliably, preventing
update failures related to name collision/guard logic.
* **Tests**
* Added Jest coverage for name generation formatting/variety and the
updated two-step collision retry behavior.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->1 parent df41adb commit 36b228d
3 files changed
Lines changed: 165 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
242 | 243 | | |
243 | 244 | | |
244 | 245 | | |
245 | | - | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
246 | 255 | | |
247 | 256 | | |
248 | 257 | | |
| |||
251 | 260 | | |
252 | 261 | | |
253 | 262 | | |
254 | | - | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
255 | 268 | | |
256 | 269 | | |
257 | 270 | | |
| |||
271 | 284 | | |
272 | 285 | | |
273 | 286 | | |
274 | | - | |
275 | | - | |
276 | | - | |
277 | | - | |
278 | 287 | | |
279 | 288 | | |
280 | 289 | | |
| |||
310 | 319 | | |
311 | 320 | | |
312 | 321 | | |
313 | | - | |
314 | | - | |
315 | | - | |
316 | | - | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
317 | 335 | | |
318 | 336 | | |
319 | 337 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
0 commit comments