@civitai/app-sdk 0.86.0 β†’ 0.88.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,384 +0,0 @@
1
- /**
2
- * The App Storage rejection MESSAGES the host puts on the wire β€” the only site
3
- * in this repository that spells them **in executable code**, sibling of
4
- * `appStorageLimits.ts`, which owns the numbers.
5
- *
6
- * πŸ”΄ **"IN EXECUTABLE CODE" IS THE WHOLE CLAIM β€” do not read it wider.** What
7
- * `tests/guards/app-storage-error-strings.test.mjs` actually enforces is
8
- * narrower still: every `error:` value inside an `APP_STORAGE_*_RESULT` payload
9
- * in the scanned mocks must NAME a constant from this module. It sees nothing
10
- * else. Hand-typed copies of these six strings live today in
11
- * `mockHost.ts`'s option docblocks (which ship in the published `.d.ts`),
12
- * in `blocks-react/test/validate.test.ts`'s fixture, in this guard's own
13
- * control assertions, and in both READMEs β€” and every one of them is invisible
14
- * to the guard. If the host rewords a message they go stale silently. Grep the
15
- * literal, not just the identifier, when a message moves.
16
- *
17
- * πŸ”΄ **THE WIRE CARRIES A MESSAGE, NOT A CODE.** The host's router throws a
18
- * `TRPCError` that has BOTH: `code: 'PAYLOAD_TOO_LARGE'` and a per-site
19
- * `message`. The bridge that answers `APP_STORAGE_SET` forwards
20
- * **`err.message`** and never the code, so `PAYLOAD_TOO_LARGE` is a string a
21
- * block CANNOT receive. `createMockHost` emitted it anyway for three releases:
22
- * a block that branched on it took the actionable branch under `dev:mock` and
23
- * the generic one in production, and nothing local could see the difference.
24
- * That is civitai/civitai-app-starters#343, and this module is its fix β€” one
25
- * spelling, shared by the mock, the example harness and any block matcher.
26
- *
27
- * ## πŸ”΄ There is NO list here of "every string a block can receive" β€” on purpose
28
- *
29
- * **This is the THIRD attempt at this section, and the absence of that list is
30
- * what the first two attempts cost. It is not an omission to be helpfully
31
- * filled in.** Both earlier drafts shipped, and each was wrong by more than its
32
- * author had checked:
33
- *
34
- * 1. **Draft 1 (RETRACTED)** presented six strings as "every storage-rejection
35
- * string the host can put on the wire". It had read only the
36
- * `PAYLOAD_TOO_LARGE` sites, so it missed the entire authorization family.
37
- * 2. **Draft 2 (RETRACTED)** kept the six, added a table of eight
38
- * authorization messages "measured in the same read", and presented THAT
39
- * as the surface. Also wrong: it missed four more messages in the same
40
- * host file, one of which was neither a ceiling nor an authorization
41
- * failure and so fit neither of its published tables.
42
- *
43
- * πŸ”΄ **Which messages those were, and which host code raises them, is
44
- * deliberately NOT recorded here.** The retracted drafts spelled it out down to
45
- * line numbers in the host's router β€” a citation nothing in this repository can
46
- * check, and one that any unrelated edit upstream invalidates silently. Read it
47
- * off the host when you need it (see "Re-deriving it" below); do not write the
48
- * answer back into this comment.
49
- *
50
- * Each enumeration was wider than the last and each was still short; the
51
- * router carries **21** `throw new TRPCError` sites and **17** distinct
52
- * messages, against draft 2's 14. A third list would be the same defect a third
53
- * time.
54
- *
55
- * πŸ”΄ **The completeness claim is the wrong SHAPE, not merely a stale list.** The
56
- * failure is not "this might go out of date" β€” it is that "the set of strings a
57
- * block can receive" is the host's whole error surface, which this repository
58
- * does not own, cannot observe from here, and has now mis-measured twice while
59
- * believing otherwise. Do not soften this into "the list below may be
60
- * incomplete" and restore one. What replaces it needs no completeness at all:
61
- *
62
- * - **This module classifies the `PAYLOAD_TOO_LARGE` family plus the bridge's
63
- * fallback β€” a set THIS REPOSITORY CHOSE, not a set the host guarantees
64
- * closed.** It is the five `PAYLOAD_TOO_LARGE` throws in `apps.router.ts`
65
- * (`:568`, `:783`, `:791`, `:845`, `:853`) and the `'storage request failed'`
66
- * literal at `IframeHost.tsx:287`. Naming what it classifies is a decision
67
- * about scope; it needs no completeness claim to be useful, and it must not
68
- * be dressed as one. πŸ”΄ **A ceiling the host enforces OUTSIDE that family
69
- * already exists** β€” see "Ceilings outside this set" below.
70
- * - **Every OTHER host rejection reaches a block on the same `error` field and
71
- * classifies `null`.** This is the whole of what a block author needs, it
72
- * requires no enumeration, and it stays true when the host adds, rewords or
73
- * deletes a message. It holds STRUCTURALLY, from two facts rather than from a
74
- * survey: the bridge's catch arms are **blanket** `catch (err)` with no code
75
- * filter (`IframeHost.tsx:2395` GET, `:2427` SET, `:2458` DELETE, `:2508`
76
- * LIST, `:2535` QUOTA), each forwarding `err.message` verbatim via
77
- * `storageErrorMessage()`; and {@link classifyAppStorageError} answers `null`
78
- * for everything outside the ceiling patterns, which is checkable in this
79
- * file without consulting the host at all.
80
- * - **The RECIPE beats any prose in this repository β€” and is still NOT a
81
- * completeness check.** It is strictly wider than every list anyone has
82
- * written: it found all 21 `TRPCError` sites, including the four draft 2
83
- * missed. It is NECESSARY, NOT SUFFICIENT β€” see "What the recipe cannot
84
- * see" under "Re-deriving it".
85
- *
86
- * ## Ceilings outside this set
87
- *
88
- * πŸ”΄ **The host enforces size ceilings that are NOT `TRPCError` throws and are
89
- * therefore invisible to both the recipe and this module.** They are zod
90
- * `.max()` bounds on the procedures' `.input()` schemas, so tRPC refuses the
91
- * call with `BAD_REQUEST` before any handler runs. Measured in
92
- * `apps.router.ts` on `civitai/civitai` `main`, 2026-09-21:
93
- *
94
- * - `const keyInput = z.string().min(1).max(200)` (`:460`) β€” the `key`
95
- * argument of `get` (`:471`), `set` (`:511`) and `delete` (`:939`);
96
- * - `list` (`:1025-1027`): `prefix: z.string().max(200)`,
97
- * `cursor: z.string().max(400)`, `limit: …int().min(1).max(200)`.
98
- *
99
- * πŸ”΄ **The 200-character KEY cap is the one a real block hits with no local
100
- * warning.** Derive a key from a URL, a model name or a title and 201
101
- * characters is ordinary. Nothing in this repository caps it: `useAppStorage`
102
- * and `createMockHost` forward the key verbatim and the mock enforces no length
103
- * gate (civitai/civitai-app-starters#370), so the write succeeds under
104
- * `dev:mock` and fails forever in production. The zod refusal arrives on the
105
- * same `error` field as everything else, so {@link classifyAppStorageError}
106
- * answers `null` β€” and the recommended `null` copy ("try reloading the page")
107
- * is WRONG for it: reloading re-mints the token and the write fails
108
- * identically. If a block builds keys from untrusted-length input, cap or hash
109
- * them at the block, and do not rely on a local run to tell you.
110
- *
111
- * πŸ”΄ **So: wherever a list of host strings still appears β€” in this repo's
112
- * READMEs, in the changeset, in `messages.ts`, in `@civitai/blocks-react`'s
113
- * `src/hooks/useAppStorage.ts`, in the `kv-storage` example's `src/App.tsx`
114
- * (which is where the "try reloading" copy lives), or in
115
- * `test/blocks/appStorageErrors.test.ts` β€” it is ILLUSTRATIVE, NOT EXHAUSTIVE,
116
- * and must be labelled as such.** Its job is to show a reader what the `null`
117
- * bucket typically contains, never to bound it.
118
- *
119
- * ## Re-deriving it
120
- *
121
- * πŸ”΄ **Not a `PAYLOAD_TOO_LARGE`-only grep** β€” that is structurally incapable of
122
- * seeing anything but the ceiling family, and is how draft 1 came to claim a
123
- * completeness it had not measured.
124
- *
125
- * ```sh
126
- * # EVERY throw, not one code. Read the whole output; do not count from memory.
127
- * gh api repos/civitai/civitai/contents/src/server/routers/apps.router.ts \
128
- * --jq '.content' | base64 -d | grep -n "new TRPCError" -A4
129
- * # …and confirm the catch arms are still blanket (no code filter), which is
130
- * # what makes "everything else classifies null" true:
131
- * gh api repos/civitai/civitai/contents/src/components/AppBlocks/IframeHost.tsx \
132
- * --jq '.content' | base64 -d | grep -n "storageErrorMessage" -B12
133
- * # …and the zod caps, which throw no TRPCError and so appear in NEITHER of the
134
- * # two commands above:
135
- * gh api repos/civitai/civitai/contents/src/server/routers/apps.router.ts \
136
- * --jq '.content' | base64 -d | grep -n "z\.string()\|z\.number()\|\.max("
137
- * ```
138
- *
139
- * ### What the recipe cannot see
140
- *
141
- * πŸ”΄ **A clean run of the three commands above is NOT proof of completeness β€”
142
- * do not treat it as one.** Measured blind spots, both of which bit this file:
143
- *
144
- * - **zod-enforced caps.** They are `.input()` bounds, not throws, so
145
- * `grep "new TRPCError"` cannot see them at all. That is why the third
146
- * command exists β€” and why "a new ceiling can only arrive as a new
147
- * `PAYLOAD_TOO_LARGE` throw" was deleted from this header: it was false
148
- * when it was written. See "Ceilings outside this set" above.
149
- * - **the bridge's own literal.** `'storage request failed'` is at
150
- * `IframeHost.tsx:287`, and `grep … -B12` prints the twelve lines BEFORE
151
- * each match β€” for the definition at `:282` that is 270–282, so line 287
152
- * never appears in the output. The recipe enumerates the CALL SITES of
153
- * `storageErrorMessage`, not its fallback. Read the function body.
154
- *
155
- * πŸ”΄ **DO NOT re-derive the ceiling strings from this comment** β€” re-read the
156
- * host. These are prose a server engineer wrote, not a published contract: they
157
- * can be reworded in any deploy, and nothing will tell you. Which is also why
158
- * {@link classifyAppStorageError} answers `null` rather than guessing, and why
159
- * a block must branch on the CLASSIFICATION and render its OWN copy β€” see the
160
- * warning on that function.
161
- *
162
- * One consequence worth stating plainly: `null` is a **BUSY** bucket, and its
163
- * dominant real-world occupant is an expired or revoked token, not a rare
164
- * unknown. Do not write a `default:` arm that assumes `null` means "transient,
165
- * retry" β€” see the warning on {@link classifyAppStorageError}.
166
- *
167
- * ## Which ceiling each message names
168
- *
169
- * Two scopes, and the remedies differ:
170
- *
171
- * - **per-user** (`'per-user storage quota exceeded'`, `'per-user row limit
172
- * exceeded'`) β€” this viewer has filled their own budget for this app. The
173
- * ceilings are `APP_STORAGE_MAX_BYTES` / `APP_STORAGE_MAX_ROWS`;
174
- * the viewer can free space by deleting their own rows.
175
- * - **app-wide** (`'app quota exceeded'`, `'app row limit exceeded'`) β€” the
176
- * app has filled a far larger umbrella shared across every viewer. One
177
- * viewer's delete will not reliably clear it; this is the developer's
178
- * problem, and `appStorageLimits.ts` deliberately does not export the
179
- * umbrella's value because nothing reports usage against it.
180
- *
181
- * A block will normally hit the per-user pair. Both are reachable, so a
182
- * matcher that handles only one is a matcher with a silent hole.
183
- */
184
- /**
185
- * The host's per-value-cap message, as a function of the cap β€” a mirror of the
186
- * template literal at `apps.router.ts:569`, which divides by 1024 and appends
187
- * `KB cap`.
188
- *
189
- * πŸ”΄ **THIS IS A TEMPLATE ON THE HOST, SO IT IS A TEMPLATE HERE.** Writing
190
- * `'value exceeds 64KB cap'` as a literal would be true only while the cap is
191
- * 64KB, and a string that silently stops matching the host the day the cap
192
- * moves is the exact defect #343 is about β€” one spelling that drifts, with
193
- * nothing able to notice. Derived from {@link APP_STORAGE_MAX_VALUE_BYTES} so
194
- * the two move together.
195
- *
196
- * Exported from this module (not from `@civitai/app-sdk/blocks`) so a test can
197
- * feed it a cap the constant cannot equal and watch the output move. Blocks
198
- * want {@link APP_STORAGE_ERROR_VALUE_TOO_LARGE}.
199
- */
200
- export declare function appStorageValueTooLargeMessage(capBytes?: number): string;
201
- /**
202
- * A single value exceeded the per-value wire cap
203
- * ({@link APP_STORAGE_MAX_VALUE_BYTES}). `apps.router.ts:568-569`.
204
- *
205
- * The only one of the six ceiling messages that is not a fixed string on the
206
- * host β€” see {@link appStorageValueTooLargeMessage}.
207
- */
208
- export declare const APP_STORAGE_ERROR_VALUE_TOO_LARGE: string;
209
- /** The APP-wide byte umbrella is full. `apps.router.ts:782-785`. */
210
- export declare const APP_STORAGE_ERROR_APP_QUOTA_EXCEEDED = "app quota exceeded";
211
- /** The APP-wide row umbrella is full. `apps.router.ts:790-793`. */
212
- export declare const APP_STORAGE_ERROR_APP_ROW_LIMIT = "app row limit exceeded";
213
- /**
214
- * This viewer's byte budget for this app (`APP_STORAGE_MAX_BYTES`) is
215
- * full. `apps.router.ts:844-847`.
216
- */
217
- export declare const APP_STORAGE_ERROR_USER_QUOTA_EXCEEDED = "per-user storage quota exceeded";
218
- /**
219
- * This viewer's row budget for this app (`APP_STORAGE_MAX_ROWS`) is
220
- * full. `apps.router.ts:852-855`.
221
- *
222
- * The ceiling a block reaches first in practice: rows run out long before
223
- * bytes do.
224
- */
225
- export declare const APP_STORAGE_ERROR_USER_ROW_LIMIT = "per-user row limit exceeded";
226
- /**
227
- * The bridge's fallback, used for any storage failure whose error carries no
228
- * usable message β€” a transport fault, a non-`Error` throw, an upstream 5xx.
229
- * `IframeHost.tsx:287`.
230
- *
231
- * πŸ”΄ It is NOT specific to writes. Every `APP_STORAGE_*` catch arm goes
232
- * through the same helper, so a `get`, `delete`, `list` or `getQuota` can
233
- * reject with it too. Retryable, unlike the five ceilings.
234
- */
235
- export declare const APP_STORAGE_ERROR_REQUEST_FAILED = "storage request failed";
236
- /**
237
- * The **`PAYLOAD_TOO_LARGE` family** β€” one string per `PAYLOAD_TOO_LARGE` site
238
- * in `apps.router.ts` β€” plus the bridge's fallback, as of the measurement in
239
- * this file's header.
240
- *
241
- * πŸ”΄ **NOT "every ceiling string the host can put on the wire", and NOT "every
242
- * string a block can receive".** Two separate reasons, and both are load-
243
- * bearing:
244
- *
245
- * - The bridge's catch arms are blanket, so every other rejection the host
246
- * raises arrives on the SAME field and is absent here on purpose. `invalid
247
- * block token`, `block instance revoked` and the `storage … scope` template
248
- * are examples of what that covers β€” **illustrations, not a bound.** See
249
- * this file's header for why no list of them lives in this repository.
250
- * - πŸ”΄ The host also enforces **size ceilings zod-side** (`key` capped at 200
251
- * characters on the `.input()` schema, and three more on `list`). Those
252
- * throw no `TRPCError`, so they are invisible to the re-derivation recipe
253
- * AND absent from this array, while being ceilings in every sense a block
254
- * cares about. See "Ceilings outside this set" in this file's header.
255
- *
256
- * This is the set `createMockHost` and the starter harnesses must draw from β€”
257
- * enforced by `tests/guards/app-storage-error-strings.test.mjs`, so a
258
- * hand-typed string cannot reappear at a mock rejection site.
259
- *
260
- * πŸ”΄ **NOT RE-EXPORTED FROM `@civitai/app-sdk/blocks`, ON PURPOSE.** Publishing
261
- * this array invites `APP_STORAGE_HOST_ERROR_MESSAGES.includes(err.message)`,
262
- * which is EQUALITY against a frozen snapshot β€” narrower than
263
- * {@link isAppStorageHostErrorMessage}, and narrower than
264
- * {@link classifyAppStorageError}, by exactly the per-value message, whose cap
265
- * the host is free to move. That is the matcher shape #343 exists to
266
- * eliminate, so it must not become public API. Reach it by file path from a
267
- * test or a guard; a block branches on the classifier's reason.
268
- *
269
- * πŸ”΄ **A CLOSED SET IS A CLAIM ABOUT A MEASUREMENT, NOT A CONTRACT β€” and this
270
- * measurement is narrow by construction, not merely stale.** Three separate
271
- * gaps, and only the first is about the future:
272
- *
273
- * 1. The host can add a `PAYLOAD_TOO_LARGE` site or reword an existing one
274
- * in any deploy, and nothing here will notice.
275
- * 2. **Today, already**, every non-ceiling rejection the host raises reaches
276
- * the block on the same field and is not in this array. πŸ”΄ This is not a
277
- * hole to be filled β€” two drafts tried and both came up short (see this
278
- * file's header). Those strings are the host's session, approval and
279
- * feature-flag prose, not ceiling vocabulary, and enumerating them here
280
- * would invite exactly the equality matching the rest of this comment
281
- * argues against.
282
- * 3. πŸ”΄ **Today, already, a SIZE ceiling the host enforces is missing from
283
- * here too** β€” the zod caps, which are not `TRPCError` throws at all.
284
- * Unlike gap 2 this one IS ceiling vocabulary, which is why the array's
285
- * scope is spelled as "the `PAYLOAD_TOO_LARGE` family" above rather than
286
- * as "the ceilings". See "Ceilings outside this set" in this file's
287
- * header.
288
- *
289
- * So an unrecognised string is "some storage failure, unknown which" β€” NOT
290
- * "some ceiling", and never "impossible".
291
- */
292
- export declare const APP_STORAGE_HOST_ERROR_MESSAGES: readonly [string, "app quota exceeded", "app row limit exceeded", "per-user storage quota exceeded", "per-user row limit exceeded", "storage request failed"];
293
- /**
294
- * Which rejection site a storage failure came from, as a closed set. `null`
295
- * means the string matched nothing known β€” see {@link classifyAppStorageError}.
296
- */
297
- export type AppStorageRejectionReason = 'value-too-large' | 'app-quota-exceeded' | 'app-row-limit' | 'user-quota-exceeded' | 'user-row-limit' | 'request-failed';
298
- /**
299
- * Turn a rejection β€” the `Error` `useAppStorage().set()` throws, or its raw
300
- * message β€” into the rejection site it came from, or `null` when the string
301
- * matches nothing this SDK version knows about.
302
- *
303
- * Branch on the RESULT; render your OWN copy.
304
- *
305
- * πŸ”΄ **NEVER RENDER THE MESSAGE ITSELF TO A VIEWER.** It is host-authored
306
- * server prose in the same class as a workflow `snapshot.error`: not
307
- * localized, not written for an end user, and free to change. Log it for
308
- * yourself (`console.warn`) and show copy your app owns.
309
- *
310
- * πŸ”΄ **`null` IS A REAL OUTCOME, NOT AN ERROR IN YOUR CODE β€” AND IT DOES NOT
311
- * MEAN "TRANSIENT".** THREE different things land here, and only one is a
312
- * retry:
313
- *
314
- * - a ceiling message this SDK version has not seen (the host reworded one,
315
- * or added a site, and your block compiled against an older SDK);
316
- * - πŸ”΄ **and, far more often in production, an authorization or kill-switch
317
- * failure.** The bridge's catch arms are blanket, so every other rejection
318
- * the host raises arrives on the same field and classifies `null` β€” for
319
- * example `invalid block token` (an expired token mid-session), `block
320
- * instance revoked`, or `storage set requires the apps:storage:write
321
- * scope`. πŸ”΄ **Those are ILLUSTRATIONS, not the set**:
322
- * see this module's header for why no list of them lives here.
323
- * - πŸ”΄ **and a zod INPUT-VALIDATION refusal, which never reaches a handler at
324
- * all.** tRPC parses `.input()` before the procedure body, so a bound
325
- * violated there is a `BAD_REQUEST` with a zod-generated message β€” no
326
- * `TRPCError` anywhere in the router, and nothing this module classifies.
327
- * The one a real block hits: the host caps `key` at **200 characters**
328
- * (`z.string().min(1).max(200)`), and neither `useAppStorage` nor
329
- * `createMockHost` caps it locally, so a key derived from a URL or a model
330
- * name can save fine under `dev:mock` and fail forever in production. πŸ”΄
331
- * **A RELOAD DOES NOT FIX THAT ONE** β€” see "Ceilings outside this set" in
332
- * this module's header.
333
- *
334
- * So **"Please try again" is the wrong copy for the `null` arm.** Retrying an
335
- * expired token forever is the failure this warning exists to prevent. Write a
336
- * generic arm that offers a RELOAD (which re-mints the token, and also covers
337
- * a genuine transport blip) and concedes that saving may be unavailable β€” and
338
- * keep `'request-failed'` separate if you want honest retry copy, since that
339
- * reason really is the transport one.
340
- *
341
- * @example
342
- * try {
343
- * await storage.set(key, note);
344
- * } catch (err) {
345
- * console.warn('[my-app] save failed:', err);
346
- * switch (classifyAppStorageError(err)) {
347
- * case 'value-too-large':
348
- * return 'That note is too long to save. Try shortening it.';
349
- * case 'user-row-limit':
350
- * case 'app-row-limit':
351
- * return 'You have no note slots left. Delete one to make room.';
352
- * case 'request-failed':
353
- * // The bridge's fallback: genuinely a transport fault. Retry is honest.
354
- * return 'Could not save that note. Please try again.';
355
- * default:
356
- * // `null`: an unknown ceiling OR β€” usually β€” an expired/revoked token.
357
- * return 'Could not save that note. Try reloading the page; if it keeps ' +
358
- * 'happening, saving may be unavailable for this app right now.';
359
- * }
360
- * }
361
- */
362
- export declare function classifyAppStorageError(error: unknown): AppStorageRejectionReason | null;
363
- /**
364
- * Is `message` one of the `PAYLOAD_TOO_LARGE`-family strings above (or the
365
- * bridge's fallback)?
366
- *
367
- * πŸ”΄ Not "a string the host can produce", and not "a ceiling" either β€” it
368
- * answers `false` for every non-ceiling rejection the host raises, all of which
369
- * the host produces and the bridge forwards on the same field, AND for the
370
- * host's zod-enforced size caps, which are ceilings it does not know about (see
371
- * "Ceilings outside this set" in this file's header). It is a membership test
372
- * over {@link APP_STORAGE_HOST_ERROR_MESSAGES}, nothing wider.
373
- *
374
- * Wider than `APP_STORAGE_HOST_ERROR_MESSAGES.includes(…)` by exactly one
375
- * case: the per-value message is a template on the host, so any cap spelling
376
- * is admitted β€” see {@link classifyAppStorageError}.
377
- *
378
- * Module-internal, like the array: it is a `classifyAppStorageError(…) !== null`
379
- * convenience for `tests/guards/app-storage-error-strings.test.mjs`, which
380
- * imports this file by PATH. A block wants the classifier's reason, not a
381
- * yes/no on host prose.
382
- */
383
- export declare function isAppStorageHostErrorMessage(message: unknown): message is string;
384
- //# sourceMappingURL=appStorageErrors.d.ts.map