@civitai/app-sdk 0.97.0 → 0.98.1

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.
package/README.md CHANGED
@@ -541,10 +541,15 @@ this plugin is the only way the manifest reaches `@civitai/sdk`.
541
541
 
542
542
  ### Web storage in a block (`@civitai/app-sdk/safe-storage`)
543
543
 
544
- Block iframes are sandboxed **without `allow-same-origin`**, so the document has
545
- an *opaque origin*. There is no origin to key web storage against, and the
546
- platform doesn't hand back an empty store — merely **reading** the property
547
- throws:
544
+ A published block is framed at its own origin, `https://<blockId>.civit.ai`
545
+ (on its run page, at its version path `/v/<sha>/`), where web storage, IndexedDB and the rest
546
+ work normally, scoped to the app
547
+ ([Frame origin and browser storage](https://developer.civitai.com/apps/guide/concepts#frame-origin)).
548
+ Some frames are still sandboxed **without `allow-same-origin`**: an unverified block that
549
+ declares an `apps:storage:shared:*` scope, and the frame a moderator reviews a
550
+ block in. There the document has an *opaque origin* (`self.origin === 'null'`),
551
+ there is no origin to key web storage against, and the platform doesn't hand
552
+ back an empty store — merely **reading** the property throws:
548
553
 
549
554
  ```
550
555
  SecurityError: Failed to read the 'localStorage' property from 'Window':
@@ -583,7 +588,8 @@ round-trip probe shows they're unusable. Rules:
583
588
  revoked `Proxy` or a throwing getter sitting on `localStorage` is classified,
584
589
  not propagated.
585
590
  - The fallback is **session-scoped** — nothing survives a reload. That's the
586
- honest semantic at an opaque origin. Treat storage as a cache; use the
591
+ honest semantic at an opaque origin. Even at a real origin, treat storage as a
592
+ cache (browsers may evict it); use the
587
593
  document store (`app.storage.collection(name)` in `@civitai/sdk`) for anything
588
594
  durable.
589
595
 
@@ -612,9 +618,10 @@ if you want the standalone `Storage` work-alike.
612
618
  ### Nested documents
613
619
 
614
620
  🔴 **A nested `<iframe src="…">` pointing at your own bundled content cannot
615
- load, and no manifest change fixes it** — your block's origin is opaque and the
616
- static host stamps `frame-ancestors` + `X-Frame-Options` on every path it
617
- serves. The full derivation, the dated external browser matrix (an
621
+ load, and no manifest change fixes it** — the static host stamps
622
+ `frame-ancestors` (Civitai's own sites only) + `X-Frame-Options` on every path
623
+ it serves, so a frame whose ancestors include your block's origin, opaque or
624
+ real, is refused. The full derivation, the dated external browser matrix (an
618
625
  observation of the platform — nothing in this repo verifies it) and the known
619
626
  limits
620
627
  are in one place: the header of
@@ -625,7 +632,7 @@ Phaser) is a `<canvas>` plus a JS loader that normally mounts straight into the
625
632
  document you hand it, which avoids the whole problem class.
626
633
 
627
634
  When a separate document is genuinely required, fetch it and inline it as the
628
- iframe's `srcdoc` — that frame inherits your opaque origin and carries no
635
+ iframe's `srcdoc` — that frame (opaque when sandboxed, as below) carries no
629
636
  response headers of its own:
630
637
 
631
638
  ```ts
@@ -88,7 +88,7 @@ export { isModelSlotContext, isPageSlotContext } from './types.js';
88
88
  * in `types.ts` for which of the two it uses and why.
89
89
  */
90
90
  export { isSignedIn } from './types.js';
91
- export type { BlockContext, KnownSlotId, ModelSlotId, PageSlotContext, PageSlotId, UnknownSlotContext, BlockAnalyticsDeclaration, BlockAnalyticsEventDeclaration, BlockAnalyticsPropertyDeclaration, BlockManifest, BlockManifestGood, BlockManifestV1, BlockSettings, BlockStorageCollectionDeclaration, BlockStorageCollectionHook, BlockStorageCollectionSchema, BlockStorageDeclaration, BlockStorageImport, BlockStorageIndexes, BlockStorageIndexType, BlockStorageMigrationKeyword, BlockStorageMigrationOp, BlockStoragePrivateCollectionDeclaration, BlockStorageSchemaType, BlockStorageSharedCollectionDeclaration, BlockToken, ContentRating, ManifestBooleanField, ManifestIframe, ManifestNumberField, ManifestPage, ManifestPreview, ManifestSettingField, ManifestSettings, ManifestStringField, ManifestTarget, ModelSlotContext, SettingScope, SettingWidget, Theme, ViewerInfo, ViewerImage, BlockCheckpointInfo, BlockResourceInfo, BlockResourcePickerType, BlockSourceImage, BlockUploadedImageInfo, BlockGenerationSourceImageInfo, BlockUploadedGenerationSource, BlockPersistGenerationSourceRequest, BlockPersistedGenerationSource, BlockImagePickerSource, BlockPickedImageInfo, BlockMediaKind, BlockMediaUploadInfo, BlockMediaUploadBatchItemResult, BlockPendingImageInfo, BlockSharedUploadImageInfo, BlockSharedPendingImageInfo, BlockImageScanResult, BlockUploadPurpose, BlockNavigateScope, BlockShareLinkMethod, BlockShareLinkRequest, BlockShareLinkResult, BlockTextToImageParams, BlockWorkflowSnapshot, RateLimitMeta, BlockEstimateBatchAggregate, BlockModelSubstitution, ModelSubstitutionReason, KnownBlockWorkflowErrorCode, BlockStepToolCall, BlockTrainedEpoch, BlockPublishedModel, BuzzAccountType, ShowcaseImage, WorkflowBody, WorkflowBodyTextToImage, WorkflowBodyCustomComfy, WorkflowBodyCustomComfyRecipe, WorkflowBodyCustomComfyInline, InlineComfyNode, WorkflowBodyStep, WorkflowBodyPassThroughStep, WorkflowBodyWorkflow, WorkflowBodyWorkflowStep, WorkflowStepRef, WithWorkflowStepRefs, BlockWorkflowStepSnapshot, BlockWorkflowStepQueue, BlockWorkflowEta, KnownBlockWorkflowQueueSupport, BlockWorkflowOutput, BlockWorkflowAvailableOutput, BlockWorkflowRestrictedOutput, BlockWorkflowPendingOutput, BlockWorkflowBlockedOutput, KnownBlockWorkflowOutputRating, KnownBlockWorkflowRestrictionReason, KnownBlockOutputUnlockOutcome, BlockOutputUnlockResult, WorkflowStatus, BlockBuzzTransaction, BlockBuzzAccount, BlockDailyCompensationResource, BlockViewer, BlockWildcardPack, BlockWildcardPackErrorCode, BlockResourceFile, BlockResourceFileEntry, BlockResourceFileEntryFormat, BlockResourceFileErrorCode, BlockResourceFileMeta, AppWorkflow, AppWorkflowImage, BlockGatedImage, BlockCollectionFollowErrorCode, BlockCollectionFollowResult, BlockPostSource, BlockCreatePostRequest, BlockCreatePostResult, BlockCreatePostHostError, WorkflowBodyTraining, AiToolkitTrainingParams, AiToolkitTrainingParamsBase, AiToolkitPlainEcosystem, AiToolkitLrScheduler, AiToolkitOptimizerType, BlockTrainingQuote, BlockTrainingDatasetItem, BlockTrainingDataImage, BlockTrainingDataUploadResult, BlockRunTrainingHostError, BlockStepQuote, BlockModel3dOutput, BlockRunConfirmedStepHostError, } from './types.js';
91
+ export type { BlockContext, KnownSlotId, ModelSlotId, PageSlotContext, PageSlotId, UnknownSlotContext, BlockAnalyticsDeclaration, BlockAnalyticsEventDeclaration, BlockAnalyticsPropertyDeclaration, BlockManifest, BlockManifestGood, BlockManifestV1, BlockSettings, BlockStorageCollectionDeclaration, BlockStorageCollectionExtends, BlockStorageCollectionHook, BlockStorageCollectionSchema, BlockStorageDeclaration, BlockStorageImport, BlockStorageIndexes, BlockStorageIndexType, BlockStorageMigrationKeyword, BlockStorageMigrationOp, BlockStoragePrivateCollectionDeclaration, BlockStorageSchemaType, BlockStorageSharedCollectionDeclaration, BlockToken, ContentRating, ManifestBooleanField, ManifestIframe, ManifestNumberField, ManifestPage, ManifestPreview, ManifestSettingField, ManifestSettings, ManifestStringField, ManifestTarget, ModelSlotContext, SettingScope, SettingWidget, Theme, ViewerInfo, ViewerImage, BlockCheckpointInfo, BlockResourceInfo, BlockResourcePickerType, BlockSourceImage, BlockUploadedImageInfo, BlockGenerationSourceImageInfo, BlockUploadedGenerationSource, BlockPersistGenerationSourceRequest, BlockPersistedGenerationSource, BlockImagePickerSource, BlockPickedImageInfo, BlockMediaKind, BlockMediaUploadInfo, BlockMediaUploadBatchItemResult, BlockPendingImageInfo, BlockSharedUploadImageInfo, BlockSharedPendingImageInfo, BlockImageScanResult, BlockUploadPurpose, BlockNavigateScope, BlockShareLinkMethod, BlockShareLinkRequest, BlockShareLinkResult, BlockTextToImageParams, BlockWorkflowSnapshot, RateLimitMeta, BlockEstimateBatchAggregate, BlockModelSubstitution, ModelSubstitutionReason, KnownBlockWorkflowErrorCode, BlockStepToolCall, BlockTrainedEpoch, BlockPublishedModel, BuzzAccountType, ShowcaseImage, WorkflowBody, WorkflowBodyTextToImage, WorkflowBodyCustomComfy, WorkflowBodyCustomComfyRecipe, WorkflowBodyCustomComfyInline, InlineComfyNode, WorkflowBodyStep, WorkflowBodyPassThroughStep, WorkflowBodyWorkflow, WorkflowBodyWorkflowStep, WorkflowStepRef, WithWorkflowStepRefs, BlockWorkflowStepSnapshot, BlockWorkflowStepQueue, BlockWorkflowEta, KnownBlockWorkflowQueueSupport, BlockWorkflowOutput, BlockWorkflowAvailableOutput, BlockWorkflowRestrictedOutput, BlockWorkflowPendingOutput, BlockWorkflowBlockedOutput, KnownBlockWorkflowOutputRating, KnownBlockWorkflowRestrictionReason, KnownBlockOutputUnlockOutcome, BlockOutputUnlockResult, WorkflowStatus, BlockBuzzTransaction, BlockBuzzAccount, BlockDailyCompensationResource, BlockViewer, BlockWildcardPack, BlockWildcardPackErrorCode, BlockResourceFile, BlockResourceFileEntry, BlockResourceFileEntryFormat, BlockResourceFileErrorCode, BlockResourceFileMeta, AppWorkflow, AppWorkflowImage, BlockGatedImage, BlockCollectionFollowErrorCode, BlockCollectionFollowResult, BlockPostSource, BlockCreatePostRequest, BlockCreatePostResult, BlockCreatePostHostError, WorkflowBodyTraining, AiToolkitTrainingParams, AiToolkitTrainingParamsBase, AiToolkitPlainEcosystem, AiToolkitLrScheduler, AiToolkitOptimizerType, BlockTrainingQuote, BlockTrainingDatasetItem, BlockTrainingDataImage, BlockTrainingDataUploadResult, BlockRunTrainingHostError, BlockStepQuote, BlockModel3dOutput, BlockRunConfirmedStepHostError, } from './types.js';
92
92
  /**
93
93
  * Host bounds for an inline `customComfy` graph, mirrored from civitai/civitai —
94
94
  * see `WorkflowBodyCustomComfyInline.workflow`.
@@ -8,7 +8,8 @@
8
8
  * all. Build-time manifest validation lives at `@civitai/app-sdk/manifest`
9
9
  * (node-only); see the note on `BlockManifestError` below.
10
10
  */
11
- // FIRST import, on purpose. Blocks are framed at an opaque origin (sandbox
11
+ // FIRST import, on purpose. Some block frames (moderator review; an unverified block that
12
+ // declares an `apps:storage:shared:*` scope) are at an opaque origin (sandbox
12
13
  // without `allow-same-origin`), where touching `localStorage`/`sessionStorage`
13
14
  // THROWS — including from third-party dependencies nobody can guard from the
14
15
  // outside. Importing this repairs those globals before anything else in the
@@ -8,12 +8,12 @@
8
8
  * bundled content by URL. Neither is a bug, and neither has a manifest-side
9
9
  * workaround:
10
10
  *
11
- * 1. A block's own frame is sandboxed with the manifest's `iframe.sandbox`
12
- * tokens intersected by a trust-tier allowlist. An unverified block keeps
13
- * `allow-scripts allow-forms` and nothing else — `allow-same-origin` is
14
- * refused at `civitai app validate` time ("forbidden outside the internal
15
- * trust tier") and re-stripped host-side even if it reached the manifest.
16
- * So the block document's origin is OPAQUE: `window.origin === "null"`.
11
+ * 1. A block cannot declare `allow-same-origin` (refused at `civitai app
12
+ * validate` time, "forbidden outside the internal trust tier", and
13
+ * re-stripped host-side); the HOST decides it. A published block is now
14
+ * framed at its own origin, `https://<blockId>.civit.ai`; a moderator-
15
+ * review frame, and an unverified block that declares an
16
+ * `apps:storage:shared:*` scope, stay OPAQUE: `window.origin === "null"`.
17
17
  *
18
18
  * 2. Every path served from `https://<blockId>.civit.ai/` — `.html`, `.js`,
19
19
  * `.wasm`, archive files, all of it — carries
@@ -27,7 +27,10 @@
27
27
  * then URL-parses it, and the string `"null"` fails that parse, returning
28
28
  * Blocked before any source matching happens. So widening the allowlist cannot
29
29
  * fix this, and `X-Frame-Options: SAMEORIGIN` blocks it a second time on its
30
- * own.
30
+ * own. At a REAL origin the result is the same by derivation, NOT by the
31
+ * measurement below (which covers the opaque case only): the platform's
32
+ * `frame-ancestors` lists Civitai's own sites and not the block's origin, so the
33
+ * block as an ancestor fails it.
31
34
  *
32
35
  * 🔴 EXTERNAL PLATFORM MEASUREMENT — NOTHING IN THIS REPO VERIFIES THE MATRIX
33
36
  * BELOW. It was taken on 2026-10-03 against a local two-origin Chromium replica
@@ -56,11 +59,13 @@
56
59
  * WHAT THIS MODULE DOES
57
60
  * =====================
58
61
  * The one thing that works: fetch the nested document's HTML (the static host
59
- * sends `Access-Control-Allow-Origin: *`, so a null-origin `fetch` succeeds
60
- * where a frame load does not), rewrite its base URL to the absolute location
61
- * it was fetched from, and hand the string to an iframe's `srcdoc`. A `srcdoc`
62
- * frame inherits the parent's opaque origin and carries NO response headers of
63
- * its own, so neither policy applies to it.
62
+ * sends `Access-Control-Allow-Origin: *`, so even a null-origin `fetch`
63
+ * succeeds where a frame load does not; from a published block's real origin
64
+ * the fetch of its own document is same-origin), rewrite its base URL to the
65
+ * absolute location it was fetched from, and hand the string to an iframe's
66
+ * `srcdoc`. A `srcdoc` frame carries NO response headers of its own, so neither
67
+ * policy applies to it. Its origin is the parent's only if it is not sandboxed:
68
+ * with the `sandbox="allow-scripts"` this module's callers set, it is opaque.
64
69
  *
65
70
  * 🔴 PREFER A SINGLE-DOCUMENT DESIGN. An engine build (Defold, Unity, Phaser,
66
71
  * …) is a `<canvas>` plus a JS loader and normally mounts straight into the
@@ -152,7 +157,7 @@ export interface InjectBaseHrefResult {
152
157
  *
153
158
  * This is the whole mechanism, and the reason it is a separate function with
154
159
  * tests of its own: a `srcdoc` document's own base URL is `about:srcdoc`, which
155
- * inherits the embedder's — an opaque origin — so every `src="loader.js"` and
160
+ * inherits the embedder's (and is opaque in a sandboxed frame) — so every `src="loader.js"` and
156
161
  * `url(font.woff2)` in the fetched markup resolves to nothing. A wrong or
157
162
  * missing `<base>` breaks every relative load in the document **with no error
158
163
  * naming the base**, which is why it is pinned by its own test.
@@ -8,12 +8,12 @@
8
8
  * bundled content by URL. Neither is a bug, and neither has a manifest-side
9
9
  * workaround:
10
10
  *
11
- * 1. A block's own frame is sandboxed with the manifest's `iframe.sandbox`
12
- * tokens intersected by a trust-tier allowlist. An unverified block keeps
13
- * `allow-scripts allow-forms` and nothing else — `allow-same-origin` is
14
- * refused at `civitai app validate` time ("forbidden outside the internal
15
- * trust tier") and re-stripped host-side even if it reached the manifest.
16
- * So the block document's origin is OPAQUE: `window.origin === "null"`.
11
+ * 1. A block cannot declare `allow-same-origin` (refused at `civitai app
12
+ * validate` time, "forbidden outside the internal trust tier", and
13
+ * re-stripped host-side); the HOST decides it. A published block is now
14
+ * framed at its own origin, `https://<blockId>.civit.ai`; a moderator-
15
+ * review frame, and an unverified block that declares an
16
+ * `apps:storage:shared:*` scope, stay OPAQUE: `window.origin === "null"`.
17
17
  *
18
18
  * 2. Every path served from `https://<blockId>.civit.ai/` — `.html`, `.js`,
19
19
  * `.wasm`, archive files, all of it — carries
@@ -27,7 +27,10 @@
27
27
  * then URL-parses it, and the string `"null"` fails that parse, returning
28
28
  * Blocked before any source matching happens. So widening the allowlist cannot
29
29
  * fix this, and `X-Frame-Options: SAMEORIGIN` blocks it a second time on its
30
- * own.
30
+ * own. At a REAL origin the result is the same by derivation, NOT by the
31
+ * measurement below (which covers the opaque case only): the platform's
32
+ * `frame-ancestors` lists Civitai's own sites and not the block's origin, so the
33
+ * block as an ancestor fails it.
31
34
  *
32
35
  * 🔴 EXTERNAL PLATFORM MEASUREMENT — NOTHING IN THIS REPO VERIFIES THE MATRIX
33
36
  * BELOW. It was taken on 2026-10-03 against a local two-origin Chromium replica
@@ -56,11 +59,13 @@
56
59
  * WHAT THIS MODULE DOES
57
60
  * =====================
58
61
  * The one thing that works: fetch the nested document's HTML (the static host
59
- * sends `Access-Control-Allow-Origin: *`, so a null-origin `fetch` succeeds
60
- * where a frame load does not), rewrite its base URL to the absolute location
61
- * it was fetched from, and hand the string to an iframe's `srcdoc`. A `srcdoc`
62
- * frame inherits the parent's opaque origin and carries NO response headers of
63
- * its own, so neither policy applies to it.
62
+ * sends `Access-Control-Allow-Origin: *`, so even a null-origin `fetch`
63
+ * succeeds where a frame load does not; from a published block's real origin
64
+ * the fetch of its own document is same-origin), rewrite its base URL to the
65
+ * absolute location it was fetched from, and hand the string to an iframe's
66
+ * `srcdoc`. A `srcdoc` frame carries NO response headers of its own, so neither
67
+ * policy applies to it. Its origin is the parent's only if it is not sandboxed:
68
+ * with the `sandbox="allow-scripts"` this module's callers set, it is opaque.
64
69
  *
65
70
  * 🔴 PREFER A SINGLE-DOCUMENT DESIGN. An engine build (Defold, Unity, Phaser,
66
71
  * …) is a `<canvas>` plus a JS loader and normally mounts straight into the
@@ -125,7 +130,7 @@ export class NestedDocumentError extends Error {
125
130
  *
126
131
  * This is the whole mechanism, and the reason it is a separate function with
127
132
  * tests of its own: a `srcdoc` document's own base URL is `about:srcdoc`, which
128
- * inherits the embedder's — an opaque origin — so every `src="loader.js"` and
133
+ * inherits the embedder's (and is opaque in a sandboxed frame) — so every `src="loader.js"` and
129
134
  * `url(font.woff2)` in the fetched markup resolves to nothing. A wrong or
130
135
  * missing `<base>` breaks every relative load in the document **with no error
131
136
  * naming the base**, which is why it is pinned by its own test.
@@ -248,8 +253,9 @@ export async function fetchNestedDocument(options) {
248
253
  // meaning what it means.
249
254
  if (options.signal?.aborted)
250
255
  throw cause;
251
- throw new NestedDocumentError(`fetchNestedDocument: request to ${url} failed. A block runs at an opaque origin, so the ` +
252
- 'host must answer with Access-Control-Allow-Origin.', { code: 'network-error', url, cause });
256
+ throw new NestedDocumentError(`fetchNestedDocument: request to ${url} failed. A URL cross-origin to the block's frame ` +
257
+ '(every URL, in an opaque-origin frame) needs the host to answer with ' +
258
+ 'Access-Control-Allow-Origin.', { code: 'network-error', url, cause });
253
259
  }
254
260
  if (!response.ok) {
255
261
  throw new NestedDocumentError(`fetchNestedDocument: ${url} returned HTTP ${response.status}.`, { code: 'http-error', url, status: response.status });
@@ -3525,6 +3525,29 @@ export interface BlockStorageCollectionHook {
3525
3525
  /** The most milliseconds one call may take: an integer from 1 to 500. Omitted means 50. */
3526
3526
  timeoutMs?: number;
3527
3527
  }
3528
+ /**
3529
+ * RESERVED — civitai.com refuses this field until extensions are enabled, so do
3530
+ * not declare it yet. The source of an EXTENSION collection: this private
3531
+ * collection's document under key `k` extends the viewer's document under the
3532
+ * same key `k` in `from`'s collection `collection`, and a reader merges the two
3533
+ * on read (the source's value wins a property both hold;
3534
+ * `@civitai/sdk`'s `app.storage.extended()`). The source is never written.
3535
+ *
3536
+ * Checked by the server, not by the schema: `storage.imports` must import
3537
+ * `collection` from `from` with access `'read'` (never `'readwrite'`); the
3538
+ * source must have an approved version declaring the collection, not
3539
+ * `exportable: false`, and not itself an extension; this collection's
3540
+ * `schema` may not declare a top-level property the source's also declares; at
3541
+ * most 4 collections may declare `extends`; and it cannot be added, removed or
3542
+ * changed on a collection any approved version declared. See
3543
+ * `KNOWN_GAPS['storage-extends-server-only-rules']`.
3544
+ */
3545
+ export interface BlockStorageCollectionExtends {
3546
+ /** The source app's blockId (its slug): `^[a-z][a-z0-9-]{1,38}[a-z0-9]$`. */
3547
+ from: string;
3548
+ /** The source app's collection name: `^[a-z][a-z0-9_]{0,31}$`. */
3549
+ collection: string;
3550
+ }
3528
3551
  /**
3529
3552
  * A PRIVATE collection — a separate key space per viewer, read and written
3530
3553
  * only by that viewer. Carries none of the shared-only fields (`write`,
@@ -3552,6 +3575,13 @@ export interface BlockStoragePrivateCollectionDeclaration {
3552
3575
  migrations?: BlockStorageMigrationOp[];
3553
3576
  /** Limited rollout — see {@link BlockStorageSharedCollectionDeclaration.hook}. */
3554
3577
  hook?: BlockStorageCollectionHook;
3578
+ /**
3579
+ * RESERVED — makes this collection an EXTENSION of another app's collection;
3580
+ * see {@link BlockStorageCollectionExtends}. Private collections of kind
3581
+ * `'docs'` only (the canonical refuses it with `kind` `'log'`, and it does
3582
+ * not exist on a shared collection).
3583
+ */
3584
+ extends?: BlockStorageCollectionExtends;
3555
3585
  }
3556
3586
  /**
3557
3587
  * A SHARED collection — one key space for the whole app, read by every viewer
package/dist/index.d.ts CHANGED
@@ -25,11 +25,11 @@
25
25
  *
26
26
  * - **`./blocks`** — importing it RUNS `./safe-storage` for its side effect
27
27
  * (repairing `localStorage`/`sessionStorage` at an opaque origin). Folding
28
- * 246 symbols and that side effect into the root would make every OAuth app
28
+ * 247 symbols and that side effect into the root would make every OAuth app
29
29
  * that writes `import { exchangeCode } from '@civitai/app-sdk'` pay for the
30
30
  * Civitai-Apps contract it does not use. Blocks and OAuth apps are disjoint
31
31
  * audiences; see this package's README.
32
- * 🔴 That 246 is ASSERTED, not merely quoted — by
32
+ * 🔴 That 247 is ASSERTED, not merely quoted — by
33
33
  * `packages/civitai-app-sdk/test/export-surface.test.ts`, which pins
34
34
  * `surface.get('./blocks').size`. It said 119 here against a real 125 until
35
35
  * 2026-10-04, because the existing checks pin the root as an exact union and
package/dist/index.js CHANGED
@@ -25,11 +25,11 @@
25
25
  *
26
26
  * - **`./blocks`** — importing it RUNS `./safe-storage` for its side effect
27
27
  * (repairing `localStorage`/`sessionStorage` at an opaque origin). Folding
28
- * 246 symbols and that side effect into the root would make every OAuth app
28
+ * 247 symbols and that side effect into the root would make every OAuth app
29
29
  * that writes `import { exchangeCode } from '@civitai/app-sdk'` pay for the
30
30
  * Civitai-Apps contract it does not use. Blocks and OAuth apps are disjoint
31
31
  * audiences; see this package's README.
32
- * 🔴 That 246 is ASSERTED, not merely quoted — by
32
+ * 🔴 That 247 is ASSERTED, not merely quoted — by
33
33
  * `packages/civitai-app-sdk/test/export-surface.test.ts`, which pins
34
34
  * `surface.get('./blocks').size`. It said 119 here against a real 125 until
35
35
  * 2026-10-04, because the existing checks pin the root as an exact union and
@@ -100,6 +100,7 @@ export declare const KNOWN_GAPS: {
100
100
  readonly 'storage-collection-schema-server-only-rules': string;
101
101
  readonly 'storage-migrations-server-only-rules': string;
102
102
  readonly 'storage-keyedBy-immutable': string;
103
+ readonly 'storage-extends-server-only-rules': string;
103
104
  readonly 'format-uri-not-enforced': string;
104
105
  };
105
106
  /** The canonical schema object, parsed once. Exported for tests and tooling. */
@@ -153,7 +153,7 @@ export const KNOWN_GAPS = {
153
153
  'already declare in the app\'s previous approved version; use a viewer-keyed collection, ' +
154
154
  '`keyedBy`, instead), and the ' +
155
155
  'RESERVED features (`kind` "log", `ttlSeconds`, `dailyWritesPerAuthor`, `registry`, ' +
156
- '`write` "anyone" / "owner") validate offline and are refused at submit. A new or changed ' +
156
+ '`write` "anyone" / "owner", `extends`) validate offline and are refused at submit. A new or changed ' +
157
157
  '`hook` is in a limited rollout: it validates offline and is refused at submit for an author ' +
158
158
  'the rollout does not include. A `hook`\'s `file` ' +
159
159
  'being outside `outputDir`, present in the bundle with its `sha256`, its size, and one file ' +
@@ -182,6 +182,13 @@ export const KNOWN_GAPS = {
182
182
  'exactly. That it cannot be added, removed or changed on a collection ANY previously ' +
183
183
  'approved version declared needs those approved manifests, so it is decided by the server at ' +
184
184
  'submit. A change to it validates here.',
185
+ 'storage-extends-server-only-rules': 'A collection\'s `extends` (an extension of another app\'s collection): the canonical encodes ' +
186
+ 'its shape (`from` a blockId, `collection` a collection name, nothing else) and that it sits ' +
187
+ 'only on a private collection of kind "docs", and Ajv enforces those exactly. The rest is the ' +
188
+ 'server\'s, at submit: a covering `storage.imports` entry with access "read", the source app\'s ' +
189
+ 'approved manifest declaring the collection, not `exportable: false` and not itself an ' +
190
+ 'extension, no top-level schema property shared with the source, at most 4 extensions, and ' +
191
+ 'that `extends` never changes on a collection any approved version declared. Those validate here.',
185
192
  'format-uri-not-enforced': '`assetBundleUrl` carries `format: "uri"` in addition to `pattern: "^https://"`. Ajv ignores ' +
186
193
  'unknown formats unless `ajv-formats` is installed, which would be a second optional peer for ' +
187
194
  'one field whose pattern is already enforced. The pattern IS enforced; the `uri` format is ' +
@@ -15,5 +15,5 @@
15
15
  export { defineBlock, SCHEMA_DIVERGENCES, KNOWN_GAPS, loadCanonicalSchema } from './defineBlock.js';
16
16
  export type { DefineBlockConfig } from './defineBlock.js';
17
17
  export { BlockManifestError } from '../blocks/manifestError.js';
18
- export type { BlockAnalyticsDeclaration, BlockAnalyticsEventDeclaration, BlockAnalyticsPropertyDeclaration, BlockManifest, BlockManifestGood, BlockManifestV1, BlockStorageCollectionDeclaration, BlockStorageCollectionHook, BlockStorageCollectionSchema, BlockStorageDeclaration, BlockStorageImport, BlockStorageIndexes, BlockStorageIndexType, BlockStorageMigrationKeyword, BlockStorageMigrationOp, BlockStoragePrivateCollectionDeclaration, BlockStorageSchemaType, BlockStorageSharedCollectionDeclaration, } from '../blocks/types.js';
18
+ export type { BlockAnalyticsDeclaration, BlockAnalyticsEventDeclaration, BlockAnalyticsPropertyDeclaration, BlockManifest, BlockManifestGood, BlockManifestV1, BlockStorageCollectionDeclaration, BlockStorageCollectionExtends, BlockStorageCollectionHook, BlockStorageCollectionSchema, BlockStorageDeclaration, BlockStorageImport, BlockStorageIndexes, BlockStorageIndexType, BlockStorageMigrationKeyword, BlockStorageMigrationOp, BlockStoragePrivateCollectionDeclaration, BlockStorageSchemaType, BlockStorageSharedCollectionDeclaration, } from '../blocks/types.js';
19
19
  //# sourceMappingURL=index.d.ts.map
@@ -7,11 +7,12 @@
7
7
  * `tests/guards/safe-storage-copy-parity.test.mjs`, so a fix here goes red
8
8
  * until it is applied there too.
9
9
  *
10
- * Civitai Apps run in an iframe sandboxed as `allow-scripts allow-forms`,
11
- * deliberately WITHOUT `allow-same-origin`. The document therefore has an
12
- * **opaque origin**, and there is no origin to key web storage against, so the
13
- * platform does not merely return an empty store — merely *reading* the
14
- * property throws:
10
+ * A published Civitai App runs at its own origin, where web storage works.
11
+ * Some frames (moderator review; an unverified block that declares an
12
+ * `apps:storage:shared:*` scope) are still sandboxed WITHOUT
13
+ * `allow-same-origin`. Such a document has an **opaque origin**, and there is
14
+ * no origin to key web storage against, so the platform does not merely return
15
+ * an empty store — merely *reading* the property throws:
15
16
  *
16
17
  * SecurityError: Failed to read the 'localStorage' property from 'Window':
17
18
  * The document is sandboxed and lacks the 'allow-same-origin' flag.
@@ -7,11 +7,12 @@
7
7
  * `tests/guards/safe-storage-copy-parity.test.mjs`, so a fix here goes red
8
8
  * until it is applied there too.
9
9
  *
10
- * Civitai Apps run in an iframe sandboxed as `allow-scripts allow-forms`,
11
- * deliberately WITHOUT `allow-same-origin`. The document therefore has an
12
- * **opaque origin**, and there is no origin to key web storage against, so the
13
- * platform does not merely return an empty store — merely *reading* the
14
- * property throws:
10
+ * A published Civitai App runs at its own origin, where web storage works.
11
+ * Some frames (moderator review; an unverified block that declares an
12
+ * `apps:storage:shared:*` scope) are still sandboxed WITHOUT
13
+ * `allow-same-origin`. Such a document has an **opaque origin**, and there is
14
+ * no origin to key web storage against, so the platform does not merely return
15
+ * an empty store — merely *reading* the property throws:
15
16
  *
16
17
  * SecurityError: Failed to read the 'localStorage' property from 'Window':
17
18
  * The document is sandboxed and lacks the 'allow-same-origin' flag.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@civitai/app-sdk",
3
- "version": "0.97.0",
3
+ "version": "0.98.1",
4
4
  "description": "OAuth + PKCE, encrypted-cookie sessions, scopes, and orchestrator helpers for building third-party Civitai apps.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -381,7 +381,7 @@
381
381
  },
382
382
  "storage": {
383
383
  "type": "object",
384
- "description": "Optional APP STORAGE declaration — every collection of JSON documents your app keeps, and who may read and write each one. Manifest-governed and REVIEW-GATED: a collection that is not declared here does not exist at runtime, and the moderator sees each collection's visibility, write policy, counters, marks and indexes. Declaring any collection also requires the `apps:storage` scope; declaring a shared collection that viewers write (`write` of \"own\" or \"anyone\") also requires the sensitive, consent-gated `apps:storage:publish` scope with a `scopeJustifications` entry; declaring any `imports` also requires the sensitive, consent-gated `apps:storage:import` scope with a `scopeJustifications` entry (and `apps:storage`); and requesting any of these scopes with nothing here for it to reach is rejected. At least one of `collections` and `imports` is required. This schema describes the WHOLE declaration, including features the platform does not accept yet: today the server's manifest validation refuses `kind` \"log\", `ttlSeconds`, `dailyWritesPerAuthor`, `write` \"anyone\" and `write` \"owner\" with a message saying they are not available yet, so those validate offline and are rejected at submit. Kept in lockstep with src/shared/constants/block-storage.constants.ts (a drift-guard test enforces equality); the imperative validator in that module is authoritative.",
384
+ "description": "Optional APP STORAGE declaration — every collection of JSON documents your app keeps, and who may read and write each one. Manifest-governed and REVIEW-GATED: a collection that is not declared here does not exist at runtime, and the moderator sees each collection's visibility, write policy, counters, marks and indexes. Declaring any collection also requires the `apps:storage` scope; declaring a shared collection that viewers write (`write` of \"own\" or \"anyone\") also requires the sensitive, consent-gated `apps:storage:publish` scope with a `scopeJustifications` entry; declaring any `imports` also requires the sensitive, consent-gated `apps:storage:import` scope with a `scopeJustifications` entry (and `apps:storage`); and requesting any of these scopes with nothing here for it to reach is rejected. At least one of `collections` and `imports` is required. This schema describes the WHOLE declaration, including features the platform does not accept yet: today the server's manifest validation refuses `kind` \"log\", `ttlSeconds`, `dailyWritesPerAuthor`, `write` \"anyone\", `write` \"owner\" and `extends` with a message saying they are not available yet, so those validate offline and are rejected at submit. Kept in lockstep with src/shared/constants/block-storage.constants.ts (a drift-guard test enforces equality); the imperative validator in that module is authoritative.",
385
385
  "additionalProperties": false,
386
386
  "anyOf": [{ "required": ["collections"] }, { "required": ["imports"] }],
387
387
  "properties": {
@@ -546,9 +546,24 @@
546
546
  "hook": {
547
547
  "description": "Optional, in a limited rollout: civitai.com accepts a new or changed hook only from authors the rollout includes, and refuses it otherwise. A permission hook: one ES module of the bundle whose default export decides, for every write to this collection, whether the write is allowed. It runs after the collection `schema` check, never instead of it. `file` is the hook's path in the submitted bundle, shipped verbatim — a committed source file, not a build output, so it must not be inside `outputDir` or `node_modules`; one self-contained module with no imports, at most 65536 bytes of UTF-8 text. `sha256` is the SHA-256 of that file's bytes as 64 lowercase hex characters: submit, the git-push path and approve each refuse a version whose file is missing or does not match it. `timeoutMs` is the most time one call may take, from 1 to 500 (omitted means 50). One file used by several collections must be pinned with the same sha256 in each.",
548
548
  "$ref": "#/$defs/storageCollectionHook"
549
+ },
550
+ "extends": {
551
+ "description": "RESERVED — civitai.com refuses this field until extensions are enabled, so do not declare it yet. Private collections of kind \"docs\" only, without `keyedBy`. Makes this collection an EXTENSION of another app's collection: the viewer's document here under key k extends that viewer's document under the same key k in the source collection, and a reader merges the two on read (the source's value wins a property both hold). The source is never written. `from` is the source app's blockId and must be imported by `storage.imports` with access \"read\" (never \"readwrite\") naming `collection`. Submit refuses an extension whose source has no approved version or does not declare the collection, declares it `exportable: false`, or itself extends another collection; and one whose `schema` declares a top-level property the source collection's schema also declares. At most 4 collections may declare `extends`. Cannot be added, removed or changed on a collection any approved version declared: declare a new collection instead. A moderator sees each extension at review.",
552
+ "$ref": "#/$defs/storageCollectionExtends"
549
553
  }
550
554
  },
551
555
  "allOf": [
556
+ {
557
+ "$comment": "An extension holds the viewer's own documents under the base collection's keys: private docs only (keyedBy is refused on private collections below).",
558
+ "if": { "required": ["extends"] },
559
+ "then": {
560
+ "required": ["visibility"],
561
+ "properties": {
562
+ "visibility": { "const": "private" },
563
+ "kind": { "const": "docs" }
564
+ }
565
+ }
566
+ },
552
567
  {
553
568
  "$comment": "No document body is ever written in a write:\"none\" collection, so a schema there would check nothing and a migration would migrate nothing.",
554
569
  "if": {
@@ -796,6 +811,26 @@
796
811
  "maximum": 500
797
812
  }
798
813
  }
814
+ },
815
+ "storageCollectionExtends": {
816
+ "type": "object",
817
+ "description": "The source of an extension (see `storage.collections.<name>.extends`). Whether `storage.imports` covers it with access \"read\", what the source app's approved manifest declares, the limit of 4, and that it never changes once approved are checked by the server, not by this schema.",
818
+ "additionalProperties": false,
819
+ "required": ["from", "collection"],
820
+ "properties": {
821
+ "from": {
822
+ "type": "string",
823
+ "description": "The source app's blockId (its slug).",
824
+ "minLength": 3,
825
+ "maxLength": 40,
826
+ "pattern": "^[a-z][a-z0-9-]{1,38}[a-z0-9]$"
827
+ },
828
+ "collection": {
829
+ "type": "string",
830
+ "description": "The name of the source app's collection this one extends.",
831
+ "pattern": "^[a-z][a-z0-9_]{0,31}$"
832
+ }
833
+ }
799
834
  }
800
835
  },
801
836
  "allOf": [