@civitai/app-sdk 0.87.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,423 +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
- import { APP_STORAGE_MAX_VALUE_BYTES } from './appStorageLimits.js';
185
- /**
186
- * The host's per-value-cap message, as a function of the cap β€” a mirror of the
187
- * template literal at `apps.router.ts:569`, which divides by 1024 and appends
188
- * `KB cap`.
189
- *
190
- * πŸ”΄ **THIS IS A TEMPLATE ON THE HOST, SO IT IS A TEMPLATE HERE.** Writing
191
- * `'value exceeds 64KB cap'` as a literal would be true only while the cap is
192
- * 64KB, and a string that silently stops matching the host the day the cap
193
- * moves is the exact defect #343 is about β€” one spelling that drifts, with
194
- * nothing able to notice. Derived from {@link APP_STORAGE_MAX_VALUE_BYTES} so
195
- * the two move together.
196
- *
197
- * Exported from this module (not from `@civitai/app-sdk/blocks`) so a test can
198
- * feed it a cap the constant cannot equal and watch the output move. Blocks
199
- * want {@link APP_STORAGE_ERROR_VALUE_TOO_LARGE}.
200
- */
201
- export function appStorageValueTooLargeMessage(capBytes = APP_STORAGE_MAX_VALUE_BYTES) {
202
- return `value exceeds ${capBytes / 1024}KB cap`;
203
- }
204
- /**
205
- * A single value exceeded the per-value wire cap
206
- * ({@link APP_STORAGE_MAX_VALUE_BYTES}). `apps.router.ts:568-569`.
207
- *
208
- * The only one of the six ceiling messages that is not a fixed string on the
209
- * host β€” see {@link appStorageValueTooLargeMessage}.
210
- */
211
- export const APP_STORAGE_ERROR_VALUE_TOO_LARGE = appStorageValueTooLargeMessage();
212
- /** The APP-wide byte umbrella is full. `apps.router.ts:782-785`. */
213
- export const APP_STORAGE_ERROR_APP_QUOTA_EXCEEDED = 'app quota exceeded';
214
- /** The APP-wide row umbrella is full. `apps.router.ts:790-793`. */
215
- export const APP_STORAGE_ERROR_APP_ROW_LIMIT = 'app row limit exceeded';
216
- /**
217
- * This viewer's byte budget for this app (`APP_STORAGE_MAX_BYTES`) is
218
- * full. `apps.router.ts:844-847`.
219
- */
220
- export const APP_STORAGE_ERROR_USER_QUOTA_EXCEEDED = 'per-user storage quota exceeded';
221
- /**
222
- * This viewer's row budget for this app (`APP_STORAGE_MAX_ROWS`) is
223
- * full. `apps.router.ts:852-855`.
224
- *
225
- * The ceiling a block reaches first in practice: rows run out long before
226
- * bytes do.
227
- */
228
- export const APP_STORAGE_ERROR_USER_ROW_LIMIT = 'per-user row limit exceeded';
229
- /**
230
- * The bridge's fallback, used for any storage failure whose error carries no
231
- * usable message β€” a transport fault, a non-`Error` throw, an upstream 5xx.
232
- * `IframeHost.tsx:287`.
233
- *
234
- * πŸ”΄ It is NOT specific to writes. Every `APP_STORAGE_*` catch arm goes
235
- * through the same helper, so a `get`, `delete`, `list` or `getQuota` can
236
- * reject with it too. Retryable, unlike the five ceilings.
237
- */
238
- export const APP_STORAGE_ERROR_REQUEST_FAILED = 'storage request failed';
239
- /**
240
- * The **`PAYLOAD_TOO_LARGE` family** β€” one string per `PAYLOAD_TOO_LARGE` site
241
- * in `apps.router.ts` β€” plus the bridge's fallback, as of the measurement in
242
- * this file's header.
243
- *
244
- * πŸ”΄ **NOT "every ceiling string the host can put on the wire", and NOT "every
245
- * string a block can receive".** Two separate reasons, and both are load-
246
- * bearing:
247
- *
248
- * - The bridge's catch arms are blanket, so every other rejection the host
249
- * raises arrives on the SAME field and is absent here on purpose. `invalid
250
- * block token`, `block instance revoked` and the `storage … scope` template
251
- * are examples of what that covers β€” **illustrations, not a bound.** See
252
- * this file's header for why no list of them lives in this repository.
253
- * - πŸ”΄ The host also enforces **size ceilings zod-side** (`key` capped at 200
254
- * characters on the `.input()` schema, and three more on `list`). Those
255
- * throw no `TRPCError`, so they are invisible to the re-derivation recipe
256
- * AND absent from this array, while being ceilings in every sense a block
257
- * cares about. See "Ceilings outside this set" in this file's header.
258
- *
259
- * This is the set `createMockHost` and the starter harnesses must draw from β€”
260
- * enforced by `tests/guards/app-storage-error-strings.test.mjs`, so a
261
- * hand-typed string cannot reappear at a mock rejection site.
262
- *
263
- * πŸ”΄ **NOT RE-EXPORTED FROM `@civitai/app-sdk/blocks`, ON PURPOSE.** Publishing
264
- * this array invites `APP_STORAGE_HOST_ERROR_MESSAGES.includes(err.message)`,
265
- * which is EQUALITY against a frozen snapshot β€” narrower than
266
- * {@link isAppStorageHostErrorMessage}, and narrower than
267
- * {@link classifyAppStorageError}, by exactly the per-value message, whose cap
268
- * the host is free to move. That is the matcher shape #343 exists to
269
- * eliminate, so it must not become public API. Reach it by file path from a
270
- * test or a guard; a block branches on the classifier's reason.
271
- *
272
- * πŸ”΄ **A CLOSED SET IS A CLAIM ABOUT A MEASUREMENT, NOT A CONTRACT β€” and this
273
- * measurement is narrow by construction, not merely stale.** Three separate
274
- * gaps, and only the first is about the future:
275
- *
276
- * 1. The host can add a `PAYLOAD_TOO_LARGE` site or reword an existing one
277
- * in any deploy, and nothing here will notice.
278
- * 2. **Today, already**, every non-ceiling rejection the host raises reaches
279
- * the block on the same field and is not in this array. πŸ”΄ This is not a
280
- * hole to be filled β€” two drafts tried and both came up short (see this
281
- * file's header). Those strings are the host's session, approval and
282
- * feature-flag prose, not ceiling vocabulary, and enumerating them here
283
- * would invite exactly the equality matching the rest of this comment
284
- * argues against.
285
- * 3. πŸ”΄ **Today, already, a SIZE ceiling the host enforces is missing from
286
- * here too** β€” the zod caps, which are not `TRPCError` throws at all.
287
- * Unlike gap 2 this one IS ceiling vocabulary, which is why the array's
288
- * scope is spelled as "the `PAYLOAD_TOO_LARGE` family" above rather than
289
- * as "the ceilings". See "Ceilings outside this set" in this file's
290
- * header.
291
- *
292
- * So an unrecognised string is "some storage failure, unknown which" β€” NOT
293
- * "some ceiling", and never "impossible".
294
- */
295
- export const APP_STORAGE_HOST_ERROR_MESSAGES = [
296
- APP_STORAGE_ERROR_VALUE_TOO_LARGE,
297
- APP_STORAGE_ERROR_APP_QUOTA_EXCEEDED,
298
- APP_STORAGE_ERROR_APP_ROW_LIMIT,
299
- APP_STORAGE_ERROR_USER_QUOTA_EXCEEDED,
300
- APP_STORAGE_ERROR_USER_ROW_LIMIT,
301
- APP_STORAGE_ERROR_REQUEST_FAILED,
302
- ];
303
- /**
304
- * Turn a rejection β€” the `Error` `useAppStorage().set()` throws, or its raw
305
- * message β€” into the rejection site it came from, or `null` when the string
306
- * matches nothing this SDK version knows about.
307
- *
308
- * Branch on the RESULT; render your OWN copy.
309
- *
310
- * πŸ”΄ **NEVER RENDER THE MESSAGE ITSELF TO A VIEWER.** It is host-authored
311
- * server prose in the same class as a workflow `snapshot.error`: not
312
- * localized, not written for an end user, and free to change. Log it for
313
- * yourself (`console.warn`) and show copy your app owns.
314
- *
315
- * πŸ”΄ **`null` IS A REAL OUTCOME, NOT AN ERROR IN YOUR CODE β€” AND IT DOES NOT
316
- * MEAN "TRANSIENT".** THREE different things land here, and only one is a
317
- * retry:
318
- *
319
- * - a ceiling message this SDK version has not seen (the host reworded one,
320
- * or added a site, and your block compiled against an older SDK);
321
- * - πŸ”΄ **and, far more often in production, an authorization or kill-switch
322
- * failure.** The bridge's catch arms are blanket, so every other rejection
323
- * the host raises arrives on the same field and classifies `null` β€” for
324
- * example `invalid block token` (an expired token mid-session), `block
325
- * instance revoked`, or `storage set requires the apps:storage:write
326
- * scope`. πŸ”΄ **Those are ILLUSTRATIONS, not the set**:
327
- * see this module's header for why no list of them lives here.
328
- * - πŸ”΄ **and a zod INPUT-VALIDATION refusal, which never reaches a handler at
329
- * all.** tRPC parses `.input()` before the procedure body, so a bound
330
- * violated there is a `BAD_REQUEST` with a zod-generated message β€” no
331
- * `TRPCError` anywhere in the router, and nothing this module classifies.
332
- * The one a real block hits: the host caps `key` at **200 characters**
333
- * (`z.string().min(1).max(200)`), and neither `useAppStorage` nor
334
- * `createMockHost` caps it locally, so a key derived from a URL or a model
335
- * name can save fine under `dev:mock` and fail forever in production. πŸ”΄
336
- * **A RELOAD DOES NOT FIX THAT ONE** β€” see "Ceilings outside this set" in
337
- * this module's header.
338
- *
339
- * So **"Please try again" is the wrong copy for the `null` arm.** Retrying an
340
- * expired token forever is the failure this warning exists to prevent. Write a
341
- * generic arm that offers a RELOAD (which re-mints the token, and also covers
342
- * a genuine transport blip) and concedes that saving may be unavailable β€” and
343
- * keep `'request-failed'` separate if you want honest retry copy, since that
344
- * reason really is the transport one.
345
- *
346
- * @example
347
- * try {
348
- * await storage.set(key, note);
349
- * } catch (err) {
350
- * console.warn('[my-app] save failed:', err);
351
- * switch (classifyAppStorageError(err)) {
352
- * case 'value-too-large':
353
- * return 'That note is too long to save. Try shortening it.';
354
- * case 'user-row-limit':
355
- * case 'app-row-limit':
356
- * return 'You have no note slots left. Delete one to make room.';
357
- * case 'request-failed':
358
- * // The bridge's fallback: genuinely a transport fault. Retry is honest.
359
- * return 'Could not save that note. Please try again.';
360
- * default:
361
- * // `null`: an unknown ceiling OR β€” usually β€” an expired/revoked token.
362
- * return 'Could not save that note. Try reloading the page; if it keeps ' +
363
- * 'happening, saving may be unavailable for this app right now.';
364
- * }
365
- * }
366
- */
367
- export function classifyAppStorageError(error) {
368
- const message = error instanceof Error
369
- ? error.message
370
- : typeof error === 'string'
371
- ? error
372
- : typeof error === 'object' && error !== null && 'message' in error
373
- ? String(error.message)
374
- : '';
375
- // CONTAINMENT, not equality. `useAppStorage` throws `new Error(result.error)`
376
- // verbatim, so equality would be enough for a rejection caught directly off
377
- // `set()` β€” but a block that re-wraps ("could not save: <cause>") or logs a
378
- // joined string is ordinary, and equality would silently stop classifying it.
379
- // Containment costs nothing here: no host message is a substring of another
380
- // (checked by a control in `test/blocks/appStorageErrors.test.ts`).
381
- if (message.includes(APP_STORAGE_ERROR_USER_ROW_LIMIT))
382
- return 'user-row-limit';
383
- if (message.includes(APP_STORAGE_ERROR_USER_QUOTA_EXCEEDED))
384
- return 'user-quota-exceeded';
385
- if (message.includes(APP_STORAGE_ERROR_APP_ROW_LIMIT))
386
- return 'app-row-limit';
387
- if (message.includes(APP_STORAGE_ERROR_APP_QUOTA_EXCEEDED))
388
- return 'app-quota-exceeded';
389
- if (message.includes(APP_STORAGE_ERROR_REQUEST_FAILED))
390
- return 'request-failed';
391
- // LAST, and matched as a FAMILY rather than against the compiled constant.
392
- // The cap is the host's, this SDK carries a snapshot of it, and the two can
393
- // disagree across a release β€” so `value exceeds 32KB cap` from a host that
394
- // has moved the cap must still classify, which an equality test against
395
- // `APP_STORAGE_ERROR_VALUE_TOO_LARGE` would not do.
396
- if (/\bvalue exceeds \d+(?:\.\d+)?KB cap\b/.test(message))
397
- return 'value-too-large';
398
- return null;
399
- }
400
- /**
401
- * Is `message` one of the `PAYLOAD_TOO_LARGE`-family strings above (or the
402
- * bridge's fallback)?
403
- *
404
- * πŸ”΄ Not "a string the host can produce", and not "a ceiling" either β€” it
405
- * answers `false` for every non-ceiling rejection the host raises, all of which
406
- * the host produces and the bridge forwards on the same field, AND for the
407
- * host's zod-enforced size caps, which are ceilings it does not know about (see
408
- * "Ceilings outside this set" in this file's header). It is a membership test
409
- * over {@link APP_STORAGE_HOST_ERROR_MESSAGES}, nothing wider.
410
- *
411
- * Wider than `APP_STORAGE_HOST_ERROR_MESSAGES.includes(…)` by exactly one
412
- * case: the per-value message is a template on the host, so any cap spelling
413
- * is admitted β€” see {@link classifyAppStorageError}.
414
- *
415
- * Module-internal, like the array: it is a `classifyAppStorageError(…) !== null`
416
- * convenience for `tests/guards/app-storage-error-strings.test.mjs`, which
417
- * imports this file by PATH. A block wants the classifier's reason, not a
418
- * yes/no on host prose.
419
- */
420
- export function isAppStorageHostErrorMessage(message) {
421
- return typeof message === 'string' && classifyAppStorageError(message) !== null;
422
- }
423
- //# sourceMappingURL=appStorageErrors.js.map
@@ -1,113 +0,0 @@
1
- /**
2
- * The App Storage ceilings the host enforces β€” **the only RUNTIME or
3
- * DOCUMENTATION site in this repository that spells these numbers**.
4
- *
5
- * Every doc site, the mock host, the live dev host and the starter harnesses
6
- * reference these constants. That is the point of the module: seven
7
- * hand-copied literals is how the old figures came to agree with each other
8
- * and disagree with the host by 25x on bytes and 1000x on rows, with nothing
9
- * in any build, test or type-check able to notice.
10
- *
11
- * πŸ”΄ **"Only site" is a claim about what is ENFORCED, and the enforcement is
12
- * much narrower than the repo.** `tests/guards/app-storage-quota-literals.test.mjs`
13
- * bans the OLD figures, and pins the derivation at each runtime site, over
14
- * exactly this surface:
15
- *
16
- * - this file and `messages.ts`, here in `src/blocks/`;
17
- * - `useAppStorage.ts`, `internal/mockHost.ts` and `internal/liveHost.ts` in
18
- * `packages/civitai-blocks-react` β€” NAMED FILES, not the package: the
19
- * banned numbers are the TRUE ceilings of neighbouring features there
20
- * (the shared-storage app-wide quota, the iframe frame cap, Buzz figures),
21
- * and a value ban over the package failed the build for saying so;
22
- * - all of `starters/examples/kv-storage`;
23
- * - and, in `packages/civitai-blocks-react/README.md`,
24
- * `packages/civitai-app-sdk/README.md` and `starters/examples/README.md`,
25
- * ONLY the App-Storage REGION β€” sections whose heading names App Storage,
26
- * plus lines that name it themselves. `### useSharedStorage()` in the same
27
- * file is not read.
28
- *
29
- * It does NOT scan, and the rule does not apply to: the guard itself (it spells
30
- * every figure, as test data), `CHANGELOG.md` and `.changeset/*.md` (history,
31
- * which must not be rewritten to satisfy a guard), `scripts/`, `tests/`,
32
- * `claudedocs/`, the root README, other sections of the READMEs above, or any
33
- * other file in any package. If you are re-deriving after a host move, do not
34
- * assume those paths are empty β€” grep them.
35
- *
36
- * ## Provenance β€” measured, not assumed
37
- *
38
- * Read from `civitai/civitai` `main` on **2026-09-19** via `gh api` (not a
39
- * local checkout, which can lag), file
40
- * `src/server/routers/apps.router.ts`, blob `654f2d6`:
41
- *
42
- * ```ts
43
- * const PER_VALUE_BYTE_CAP = 64 * 1024; // :172
44
- * const USER_QUOTA_BYTES = 2 * 1024 * 1024; // :204
45
- * const USER_ROW_LIMIT = 1_000; // :205
46
- * ```
47
- *
48
- * and the `getQuota` procedure returns `limitBytes: USER_QUOTA_BYTES,
49
- * limitRows: USER_ROW_LIMIT` β€” so these are exactly the numbers a block reads
50
- * back from {@link https://github.com/civitai/civitai-app-starters | `useAppStorage().getQuota()`}.
51
- *
52
- * Re-derive with:
53
- *
54
- * ```sh
55
- * gh api repos/civitai/civitai/contents/src/server/routers/apps.router.ts \
56
- * --jq '.content' | base64 -d | grep -n 'USER_QUOTA_BYTES\|USER_ROW_LIMIT\|PER_VALUE_BYTE_CAP'
57
- * ```
58
- *
59
- * πŸ”΄ **DO NOT re-derive the numbers from this comment** β€” re-read the host.
60
- * The per-user clamp was sized against a measured distribution (the host's own
61
- * comment records: 2026-09-09, largest observed per-user footprint 0.65 MiB
62
- * across 49 rows, `2 MiB` chosen for ~3.1x headroom) and is expected to move
63
- * again when that distribution does.
64
- *
65
- * ## Which scope each number describes
66
- *
67
- * πŸ”΄ **THE NAMESPACE AND THE BUDGET HAVE DIFFERENT SCOPES, and the docs used
68
- * to quote one while naming the other.**
69
- *
70
- * - **Namespace** β€” rows are keyed `(block_instance_id, user_id, key)`. A key
71
- * written by one block instance is invisible to another. "Per (block
72
- * instance, viewer)" is correct, and unchanged.
73
- * - **Budget** β€” {@link APP_STORAGE_MAX_BYTES} and
74
- * {@link APP_STORAGE_MAX_ROWS} are enforced per **(app, viewer)**: the host
75
- * counter is keyed `(app_block_id, user_id)`, so every block instance of the
76
- * same app draws on ONE budget for that viewer. An app with three instances
77
- * on a viewer's page shares 1,000 rows between them, not 3,000.
78
- *
79
- * A far larger app-wide umbrella also exists above both. It is deliberately
80
- * NOT exported and its value is deliberately not written here: nothing reports
81
- * an app's usage against it, so no block can render a meaningful "x of y" for
82
- * it, and a constant nobody can act on is an invitation to build a UI that
83
- * lies. The per-viewer clamp below is what a block will actually hit β€” it is
84
- * orders of magnitude tighter.
85
- */
86
- /**
87
- * Largest single value one `set()` may send, in **wire** bytes
88
- * (`JSON.stringify(value)` measured as UTF-8).
89
- *
90
- * πŸ”΄ This bounds what one call SENDS, not what it STORES. The host checks it
91
- * in the wire unit while the byte budget below is enforced in the stored unit,
92
- * and they diverge: the host records that the largest value this cap admits
93
- * (65,535 wire bytes) stores 2,911,582 bytes β€” 44x, and on its own past
94
- * {@link APP_STORAGE_MAX_BYTES}. So passing this check is not evidence the
95
- * write will land.
96
- */
97
- export declare const APP_STORAGE_MAX_VALUE_BYTES: number;
98
- /**
99
- * Total stored bytes one viewer may hold across **all instances of one app**.
100
- *
101
- * This is the value `getQuota().limitBytes` reports.
102
- */
103
- export declare const APP_STORAGE_MAX_BYTES: number;
104
- /**
105
- * Total rows one viewer may hold across **all instances of one app**.
106
- *
107
- * This is the value `getQuota().limitRows` reports. It is the ceiling most
108
- * likely to surprise: a block caching one small row per item a viewer looks at
109
- * reaches it after a thousand items while using ~0.3 MB β€” well under
110
- * {@link APP_STORAGE_MAX_BYTES} β€” so a byte-only estimate will not predict it.
111
- */
112
- export declare const APP_STORAGE_MAX_ROWS = 1000;
113
- //# sourceMappingURL=appStorageLimits.d.ts.map
@@ -1,113 +0,0 @@
1
- /**
2
- * The App Storage ceilings the host enforces β€” **the only RUNTIME or
3
- * DOCUMENTATION site in this repository that spells these numbers**.
4
- *
5
- * Every doc site, the mock host, the live dev host and the starter harnesses
6
- * reference these constants. That is the point of the module: seven
7
- * hand-copied literals is how the old figures came to agree with each other
8
- * and disagree with the host by 25x on bytes and 1000x on rows, with nothing
9
- * in any build, test or type-check able to notice.
10
- *
11
- * πŸ”΄ **"Only site" is a claim about what is ENFORCED, and the enforcement is
12
- * much narrower than the repo.** `tests/guards/app-storage-quota-literals.test.mjs`
13
- * bans the OLD figures, and pins the derivation at each runtime site, over
14
- * exactly this surface:
15
- *
16
- * - this file and `messages.ts`, here in `src/blocks/`;
17
- * - `useAppStorage.ts`, `internal/mockHost.ts` and `internal/liveHost.ts` in
18
- * `packages/civitai-blocks-react` β€” NAMED FILES, not the package: the
19
- * banned numbers are the TRUE ceilings of neighbouring features there
20
- * (the shared-storage app-wide quota, the iframe frame cap, Buzz figures),
21
- * and a value ban over the package failed the build for saying so;
22
- * - all of `starters/examples/kv-storage`;
23
- * - and, in `packages/civitai-blocks-react/README.md`,
24
- * `packages/civitai-app-sdk/README.md` and `starters/examples/README.md`,
25
- * ONLY the App-Storage REGION β€” sections whose heading names App Storage,
26
- * plus lines that name it themselves. `### useSharedStorage()` in the same
27
- * file is not read.
28
- *
29
- * It does NOT scan, and the rule does not apply to: the guard itself (it spells
30
- * every figure, as test data), `CHANGELOG.md` and `.changeset/*.md` (history,
31
- * which must not be rewritten to satisfy a guard), `scripts/`, `tests/`,
32
- * `claudedocs/`, the root README, other sections of the READMEs above, or any
33
- * other file in any package. If you are re-deriving after a host move, do not
34
- * assume those paths are empty β€” grep them.
35
- *
36
- * ## Provenance β€” measured, not assumed
37
- *
38
- * Read from `civitai/civitai` `main` on **2026-09-19** via `gh api` (not a
39
- * local checkout, which can lag), file
40
- * `src/server/routers/apps.router.ts`, blob `654f2d6`:
41
- *
42
- * ```ts
43
- * const PER_VALUE_BYTE_CAP = 64 * 1024; // :172
44
- * const USER_QUOTA_BYTES = 2 * 1024 * 1024; // :204
45
- * const USER_ROW_LIMIT = 1_000; // :205
46
- * ```
47
- *
48
- * and the `getQuota` procedure returns `limitBytes: USER_QUOTA_BYTES,
49
- * limitRows: USER_ROW_LIMIT` β€” so these are exactly the numbers a block reads
50
- * back from {@link https://github.com/civitai/civitai-app-starters | `useAppStorage().getQuota()`}.
51
- *
52
- * Re-derive with:
53
- *
54
- * ```sh
55
- * gh api repos/civitai/civitai/contents/src/server/routers/apps.router.ts \
56
- * --jq '.content' | base64 -d | grep -n 'USER_QUOTA_BYTES\|USER_ROW_LIMIT\|PER_VALUE_BYTE_CAP'
57
- * ```
58
- *
59
- * πŸ”΄ **DO NOT re-derive the numbers from this comment** β€” re-read the host.
60
- * The per-user clamp was sized against a measured distribution (the host's own
61
- * comment records: 2026-09-09, largest observed per-user footprint 0.65 MiB
62
- * across 49 rows, `2 MiB` chosen for ~3.1x headroom) and is expected to move
63
- * again when that distribution does.
64
- *
65
- * ## Which scope each number describes
66
- *
67
- * πŸ”΄ **THE NAMESPACE AND THE BUDGET HAVE DIFFERENT SCOPES, and the docs used
68
- * to quote one while naming the other.**
69
- *
70
- * - **Namespace** β€” rows are keyed `(block_instance_id, user_id, key)`. A key
71
- * written by one block instance is invisible to another. "Per (block
72
- * instance, viewer)" is correct, and unchanged.
73
- * - **Budget** β€” {@link APP_STORAGE_MAX_BYTES} and
74
- * {@link APP_STORAGE_MAX_ROWS} are enforced per **(app, viewer)**: the host
75
- * counter is keyed `(app_block_id, user_id)`, so every block instance of the
76
- * same app draws on ONE budget for that viewer. An app with three instances
77
- * on a viewer's page shares 1,000 rows between them, not 3,000.
78
- *
79
- * A far larger app-wide umbrella also exists above both. It is deliberately
80
- * NOT exported and its value is deliberately not written here: nothing reports
81
- * an app's usage against it, so no block can render a meaningful "x of y" for
82
- * it, and a constant nobody can act on is an invitation to build a UI that
83
- * lies. The per-viewer clamp below is what a block will actually hit β€” it is
84
- * orders of magnitude tighter.
85
- */
86
- /**
87
- * Largest single value one `set()` may send, in **wire** bytes
88
- * (`JSON.stringify(value)` measured as UTF-8).
89
- *
90
- * πŸ”΄ This bounds what one call SENDS, not what it STORES. The host checks it
91
- * in the wire unit while the byte budget below is enforced in the stored unit,
92
- * and they diverge: the host records that the largest value this cap admits
93
- * (65,535 wire bytes) stores 2,911,582 bytes β€” 44x, and on its own past
94
- * {@link APP_STORAGE_MAX_BYTES}. So passing this check is not evidence the
95
- * write will land.
96
- */
97
- export const APP_STORAGE_MAX_VALUE_BYTES = 64 * 1024;
98
- /**
99
- * Total stored bytes one viewer may hold across **all instances of one app**.
100
- *
101
- * This is the value `getQuota().limitBytes` reports.
102
- */
103
- export const APP_STORAGE_MAX_BYTES = 2 * 1024 * 1024;
104
- /**
105
- * Total rows one viewer may hold across **all instances of one app**.
106
- *
107
- * This is the value `getQuota().limitRows` reports. It is the ceiling most
108
- * likely to surprise: a block caching one small row per item a viewer looks at
109
- * reaches it after a thousand items while using ~0.3 MB β€” well under
110
- * {@link APP_STORAGE_MAX_BYTES} β€” so a byte-only estimate will not predict it.
111
- */
112
- export const APP_STORAGE_MAX_ROWS = 1_000;
113
- //# sourceMappingURL=appStorageLimits.js.map