@civitai/app-sdk 0.80.1 → 0.82.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.
@@ -116,7 +116,7 @@ export { isModelSlotContext, isPageSlotContext } from './types.js';
116
116
  * in `types.ts` for which of the two it uses and why.
117
117
  */
118
118
  export { isSignedIn } from './types.js';
119
- export type { BlockContext, KnownSlotId, ModelSlotId, PageSlotContext, PageSlotId, UnknownSlotContext, BlockAnalyticsDeclaration, BlockAnalyticsEventDeclaration, BlockAnalyticsPropertyDeclaration, BlockManifest, BlockManifestGood, BlockManifestV1, BlockSettings, BlockStorageCollectionDeclaration, BlockStorageDeclaration, BlockStorageIndexes, BlockStorageIndexType, BlockStoragePrivateCollectionDeclaration, BlockStorageSharedCollectionDeclaration, BlockToken, ContentRating, ManifestBooleanField, ManifestIframe, ManifestNumberField, ManifestPage, ManifestPreview, ManifestSettingField, ManifestSettings, ManifestStringField, ManifestTarget, ModelSlotContext, SettingScope, SettingWidget, Theme, ViewerInfo, BlockCheckpointInfo, BlockResourceInfo, BlockResourcePickerType, BlockSourceImage, BlockUploadedImageInfo, BlockGenerationSourceImageInfo, BlockImagePickerSource, BlockPickedImageInfo, BlockMediaKind, BlockMediaUploadInfo, BlockPendingImageInfo, BlockImageScanResult, BlockUploadPurpose, BlockNavigateScope, BlockTextToImageParams, BlockWorkflowSnapshot, BlockEstimateBatchAggregate, BlockModelSubstitution, ModelSubstitutionReason, KnownBlockWorkflowErrorCode, BlockStepToolCall, BlockTrainedEpoch, BlockPublishedModel, BuzzAccountType, ShowcaseImage, WorkflowBody, WorkflowBodyTextToImage, WorkflowBodyCustomComfy, WorkflowBodyCustomComfyRecipe, WorkflowBodyCustomComfyInline, InlineComfyNode, WorkflowBodyStep, WorkflowBodyPassThroughStep, WorkflowBodyWorkflow, WorkflowBodyWorkflowStep, WorkflowStepRef, WithWorkflowStepRefs, BlockWorkflowStepSnapshot, 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';
119
+ export type { BlockContext, KnownSlotId, ModelSlotId, PageSlotContext, PageSlotId, UnknownSlotContext, BlockAnalyticsDeclaration, BlockAnalyticsEventDeclaration, BlockAnalyticsPropertyDeclaration, BlockManifest, BlockManifestGood, BlockManifestV1, BlockSettings, BlockStorageCollectionDeclaration, 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, BlockCheckpointInfo, BlockResourceInfo, BlockResourcePickerType, BlockSourceImage, BlockUploadedImageInfo, BlockGenerationSourceImageInfo, BlockImagePickerSource, BlockPickedImageInfo, BlockMediaKind, BlockMediaUploadInfo, BlockPendingImageInfo, BlockImageScanResult, BlockUploadPurpose, BlockNavigateScope, BlockTextToImageParams, BlockWorkflowSnapshot, BlockEstimateBatchAggregate, BlockModelSubstitution, ModelSubstitutionReason, KnownBlockWorkflowErrorCode, BlockStepToolCall, BlockTrainedEpoch, BlockPublishedModel, BuzzAccountType, ShowcaseImage, WorkflowBody, WorkflowBodyTextToImage, WorkflowBodyCustomComfy, WorkflowBodyCustomComfyRecipe, WorkflowBodyCustomComfyInline, InlineComfyNode, WorkflowBodyStep, WorkflowBodyPassThroughStep, WorkflowBodyWorkflow, WorkflowBodyWorkflowStep, WorkflowStepRef, WithWorkflowStepRefs, BlockWorkflowStepSnapshot, 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';
120
120
  /**
121
121
  * Host bounds for an inline `customComfy` graph, mirrored from civitai/civitai —
122
122
  * see `WorkflowBodyCustomComfyInline.workflow`.
@@ -1031,6 +1031,7 @@ export type BlockToParentMessage = {
1031
1031
  type: 'REQUEST_CONSENT';
1032
1032
  payload?: {
1033
1033
  scopes?: string[];
1034
+ from?: string;
1034
1035
  };
1035
1036
  } | {
1036
1037
  type: 'TRACK_EVENT';
@@ -22,6 +22,7 @@ export declare const BLOCK_SCOPES: {
22
22
  readonly APPS_STORAGE_SHARED_WRITE: "apps:storage:shared:write";
23
23
  readonly APPS_STORAGE: "apps:storage";
24
24
  readonly APPS_STORAGE_PUBLISH: "apps:storage:publish";
25
+ readonly APPS_STORAGE_IMPORT: "apps:storage:import";
25
26
  readonly COLLECTIONS_READ_SELF: "collections:read:self";
26
27
  readonly COLLECTIONS_WRITE_SELF: "collections:write:self";
27
28
  readonly COLLECTIONS_READ_PRIVATE: "collections:read:private";
@@ -39,6 +39,11 @@ export const BLOCK_SCOPES = {
39
39
  // civitai/civitai `src/shared/constants/block-scope.constants.ts`.
40
40
  APPS_STORAGE: 'apps:storage',
41
41
  APPS_STORAGE_PUBLISH: 'apps:storage:publish',
42
+ // apps:storage:import — reach ANOTHER app's collections as the viewer, through
43
+ // the manifest's `storage.imports` (civitai/civitai#7494; a fork reading its
44
+ // parent). SENSITIVE (needs a `scopeJustifications` entry) and CONSENT-GATED:
45
+ // the viewer's grant is recorded per (viewer, this app, source app).
46
+ APPS_STORAGE_IMPORT: 'apps:storage:import',
42
47
  // collections:* — the App Blocks Collections surface. These have no OAuth bit
43
48
  // (they never touch the user's civitai resources via the OAuth surface); the
44
49
  // server gates them per-op server-side (collection visibility/ownership +
@@ -2690,6 +2690,109 @@ export interface BlockStorageIndexes {
2690
2690
  createdAt?: never;
2691
2691
  updatedAt?: never;
2692
2692
  }
2693
+ /** A JSON type name a {@link BlockStorageCollectionSchema} can require. */
2694
+ export type BlockStorageSchemaType = 'object' | 'array' | 'string' | 'number' | 'integer' | 'boolean' | 'null';
2695
+ /**
2696
+ * A collection's DOCUMENT SCHEMA (civitai/civitai#7491): a JSON Schema SUBSET that every
2697
+ * document's `data` in the collection must match. Opt-in: without one, documents are not
2698
+ * checked. The server checks every create and put, and refuses a document that does not match
2699
+ * with 400 `schema_violation`. The refusal's message and `details.pointer` name the FIRST
2700
+ * failing JSON pointer into `data` (for example `/title`), and `details.keyword` names the
2701
+ * keyword it failed. Counters and marks are not checked. Changing a schema does not re-check
2702
+ * stored documents; each is checked the next time it is written.
2703
+ *
2704
+ * Only these keywords exist; any other is refused at submit by name. Semantics: a keyword for
2705
+ * another type is ignored (`minLength` on a number), `integer` is a number with no fraction,
2706
+ * lengths count code points, `pattern` is an UNANCHORED JavaScript regular expression with the
2707
+ * `u` flag, and `enum`/`const` compare JSON values. "First" is: `type`, `const`, `enum`, the
2708
+ * string, number and array keywords (`maxLength` before `pattern`), `items` element by element,
2709
+ * then `required` in declared order, then the object's own keys in ascending order.
2710
+ *
2711
+ * Bounds (the server's, refused at submit): at most 16 schemas nested in one another, 16384
2712
+ * bytes of JSON and 16 patterns per collection schema, and 32 patterns across all of the
2713
+ * manifest's collection schemas together; a `pattern` is at most 256 characters,
2714
+ * must compile, needs a `maxLength` of at most 1000 on the same schema, and must not backtrack
2715
+ * catastrophically; no `min*` above its `max*`. Not allowed on a `write: 'none'` collection,
2716
+ * which has no document bodies. Mirrors the canonical schema's
2717
+ * `$defs.storageCollectionSchema`.
2718
+ */
2719
+ export interface BlockStorageCollectionSchema {
2720
+ /** One type, or a non-empty list of them without repeats. */
2721
+ type?: BlockStorageSchemaType | BlockStorageSchemaType[];
2722
+ /** Property name → the schema its value must match. */
2723
+ properties?: Record<string, BlockStorageCollectionSchema>;
2724
+ /** Property names that must be present (own keys), checked in this order. */
2725
+ required?: string[];
2726
+ /** `false` refuses undeclared keys; a schema checks their values; `true` (the default) allows them. */
2727
+ additionalProperties?: boolean | BlockStorageCollectionSchema;
2728
+ /** One schema every array element must match. */
2729
+ items?: BlockStorageCollectionSchema;
2730
+ /** The allowed JSON values (at least one). */
2731
+ enum?: unknown[];
2732
+ /** The one allowed JSON value. */
2733
+ const?: unknown;
2734
+ /** In code points. */
2735
+ minLength?: number;
2736
+ /** In code points. Required, at most 1000, on any schema that declares `pattern`. */
2737
+ maxLength?: number;
2738
+ /** A JavaScript regular expression (`u` flag), unanchored, at most 256 characters. */
2739
+ pattern?: string;
2740
+ /** Inclusive. */
2741
+ minimum?: number;
2742
+ /** Inclusive. */
2743
+ maximum?: number;
2744
+ minItems?: number;
2745
+ maxItems?: number;
2746
+ description?: string;
2747
+ }
2748
+ /**
2749
+ * The schema keyword of the one breaking change an `acknowledge`
2750
+ * {@link BlockStorageMigrationOp} accepts. `'required'` is not one: a newly required field can
2751
+ * only be covered by a `default`.
2752
+ */
2753
+ export type BlockStorageMigrationKeyword = 'type' | 'const' | 'enum' | 'minimum' | 'maximum' | 'minLength' | 'maxLength' | 'minItems' | 'maxItems' | 'pattern' | 'additionalProperties' | 'properties';
2754
+ /**
2755
+ * One declarative MIGRATION op on a collection's stored documents (civitai/civitai#7661),
2756
+ * discriminated on `op`. Mirrors the canonical schema's `$defs.storageMigrationOp`.
2757
+ *
2758
+ * At submit, civitai.com compares the collection's `schema` with the previous approved
2759
+ * version's (statically; stored documents are never read) and refuses every BREAKING change
2760
+ * (a newly required property, a narrowed type / enum / const / bound / pattern,
2761
+ * `additionalProperties` closed, a declared property removed under
2762
+ * `additionalProperties: false`, or a schema added where there was none) that no op covers:
2763
+ *
2764
+ * - `default` covers a newly required property at `path`, setting `value` where the field is
2765
+ * missing (its parent object exists). `value` must match the new schema there; at most 4096
2766
+ * bytes of JSON. It is the only op that can cover a newly required property.
2767
+ * - `rename` covers a declared property removed under `additionalProperties: false`, at `from`.
2768
+ * - `remove` covers any breaking change at or under a field the new schema does not require.
2769
+ * - `acknowledge` covers exactly the one breaking change whose pointer EQUALS `path` (never a
2770
+ * prefix) with that `keyword`, and changes nothing: documents that violate it are refused on
2771
+ * their next write until reshaped. Its `path` may be `""` (the document root) and may use the
2772
+ * segment `*` for a change inside `items` or an `additionalProperties` schema (`"/tags/*"`).
2773
+ *
2774
+ * The `path` / `from` / `to` of `default`, `rename` and `remove` are JSON Pointers to one field
2775
+ * of a document's `data` (`"/meta/title"`): 1 to 15 non-empty segments, `~` written `~0` and `/`
2776
+ * written `~1`, no `*` segment. Every op is idempotent, and the fields `default`, `rename` and
2777
+ * `remove` touch must be disjoint. Only the ops that cover a breaking change of THIS version run,
2778
+ * once, when it is approved; an op that covers nothing is reported at submit and never runs.
2779
+ */
2780
+ export type BlockStorageMigrationOp = {
2781
+ op: 'default';
2782
+ path: string;
2783
+ value: unknown;
2784
+ } | {
2785
+ op: 'rename';
2786
+ from: string;
2787
+ to: string;
2788
+ } | {
2789
+ op: 'remove';
2790
+ path: string;
2791
+ } | {
2792
+ op: 'acknowledge';
2793
+ path: string;
2794
+ keyword: BlockStorageMigrationKeyword;
2795
+ };
2693
2796
  /**
2694
2797
  * A PRIVATE collection — a separate key space per viewer, read and written
2695
2798
  * only by that viewer. Carries none of the shared-only fields (`write`,
@@ -2709,6 +2812,12 @@ export interface BlockStoragePrivateCollectionDeclaration {
2709
2812
  ttlSeconds?: number;
2710
2813
  /** RESERVED — see {@link BlockStorageSharedCollectionDeclaration.maxEntries}. */
2711
2814
  maxEntries?: number;
2815
+ /** See {@link BlockStorageSharedCollectionDeclaration.exportable}. */
2816
+ exportable?: boolean;
2817
+ /** See {@link BlockStorageCollectionSchema}. */
2818
+ schema?: BlockStorageCollectionSchema;
2819
+ /** See {@link BlockStorageSharedCollectionDeclaration.migrations}. */
2820
+ migrations?: BlockStorageMigrationOp[];
2712
2821
  }
2713
2822
  /**
2714
2823
  * A SHARED collection — one key space for the whole app, read by every viewer
@@ -2803,6 +2912,23 @@ export interface BlockStorageSharedCollectionDeclaration {
2803
2912
  * model later changes hands or is deleted.
2804
2913
  */
2805
2914
  ownedModelVersions?: string[];
2915
+ /**
2916
+ * Whether OTHER apps may reach this collection through their `storage.imports`,
2917
+ * with the viewer's consent (see {@link BlockStorageImport}). Default `true`;
2918
+ * `false` refuses every import of it with 403 `not_exportable`.
2919
+ */
2920
+ exportable?: boolean;
2921
+ /**
2922
+ * The schema every document's `data` must match — see {@link BlockStorageCollectionSchema}.
2923
+ * Not allowed with `write` `'none'` (no document bodies are written there).
2924
+ */
2925
+ schema?: BlockStorageCollectionSchema;
2926
+ /**
2927
+ * 1 to 32 ops applied to the documents ALREADY STORED when this version is approved, for a
2928
+ * `schema` change that would otherwise leave them unwritable — see
2929
+ * {@link BlockStorageMigrationOp}. Not allowed with `write` `'none'`.
2930
+ */
2931
+ migrations?: BlockStorageMigrationOp[];
2806
2932
  }
2807
2933
  /**
2808
2934
  * One collection declaration — see {@link BlockManifestV1.storage}.
@@ -2811,9 +2937,44 @@ export interface BlockStorageSharedCollectionDeclaration {
2811
2937
  * canonical schema's `storage.collections.*`.
2812
2938
  */
2813
2939
  export type BlockStorageCollectionDeclaration = BlockStoragePrivateCollectionDeclaration | BlockStorageSharedCollectionDeclaration;
2940
+ /**
2941
+ * One entry of the manifest's `storage.imports` (civitai/civitai#7494): collections of
2942
+ * ANOTHER app this app reaches as the viewer — for example a fork reading and writing its
2943
+ * parent's data. The SDK reaches one with `app.storage.collection(name, { from })`.
2944
+ *
2945
+ * Through an import the app acts AS THE VIEWER IN THE SOURCE APP: a private collection
2946
+ * gives that viewer's own documents, a shared one reads as the source shows it to them,
2947
+ * writes follow the source collection's write policy and schema, and usage counts against
2948
+ * the source app's ceilings. Nothing is reached until the viewer grants it: declaring any
2949
+ * import requires the sensitive, consent-gated `apps:storage:import` scope with a
2950
+ * `scopeJustifications` entry (and `apps:storage`), and the viewer's consent is recorded
2951
+ * per (viewer, this app, source app). A source collection declared `exportable: false`
2952
+ * refuses every import.
2953
+ *
2954
+ * Limits (the canonical's): at most 8 imports, one per source, never this app itself.
2955
+ */
2956
+ export interface BlockStorageImport {
2957
+ /** The source app's blockId (`^[a-z][a-z0-9-]{1,38}[a-z0-9]$`, 3 to 40 characters). */
2958
+ from: string;
2959
+ /** 1 to 16 distinct names of collections the source declares. */
2960
+ collections: string[];
2961
+ /**
2962
+ * `'read'`: reads only; every write, counter and mark is refused (`write_policy`).
2963
+ * `'readwrite'`: also writes, under the source collection's own write policy. A write,
2964
+ * counter or mark in one of the source's SHARED collections also needs the viewer's own
2965
+ * `apps:storage:publish` grant IN THE SOURCE APP; a private collection needs only the
2966
+ * import grant.
2967
+ */
2968
+ access: 'read' | 'readwrite';
2969
+ }
2814
2970
  /**
2815
2971
  * The manifest's `storage` object — see {@link BlockManifestV1.storage}.
2816
2972
  * Mirrors the canonical schema's `storage`; no other key is allowed.
2973
+ *
2974
+ * It declares `collections` (this app's own), `imports` (other apps'), or both.
2975
+ * AT LEAST ONE is required, which this type does not express: each is optional
2976
+ * here, and the canonical schema (so `defineBlock`) refuses a `storage` with
2977
+ * neither.
2817
2978
  */
2818
2979
  export interface BlockStorageDeclaration {
2819
2980
  /**
@@ -2823,7 +2984,9 @@ export interface BlockStorageDeclaration {
2823
2984
  * its visibility, is a NEW collection: the old one's documents are not
2824
2985
  * carried over.
2825
2986
  */
2826
- collections: Record<string, BlockStorageCollectionDeclaration>;
2987
+ collections?: Record<string, BlockStorageCollectionDeclaration>;
2988
+ /** Other apps' collections this app reaches as the viewer, 1 to 8 entries. See {@link BlockStorageImport}. */
2989
+ imports?: BlockStorageImport[];
2827
2990
  }
2828
2991
  /**
2829
2992
  * One entry of a manifest's `goods[]`. Mirrors the canonical schema exactly;
@@ -2972,8 +3135,11 @@ export interface BlockManifestV1 {
2972
3135
  * Declaring any collection requires the `apps:storage` scope; a shared
2973
3136
  * collection viewers write (`write` `'own'` or `'anyone'`) also requires the
2974
3137
  * sensitive, consent-gated `apps:storage:publish` scope with a
2975
- * `scopeJustifications` entry; and requesting either scope with nothing here
2976
- * for it to reach is rejected. Those couplings, and the RESERVED features
3138
+ * `scopeJustifications` entry; declaring any `imports` (another app's
3139
+ * collections, see {@link BlockStorageImport}) requires the sensitive,
3140
+ * consent-gated `apps:storage:import` scope with a `scopeJustifications`
3141
+ * entry; and requesting any of these scopes with nothing here for it to
3142
+ * reach is rejected. Those couplings, and the RESERVED features
2977
3143
  * (`kind: 'log'`, `ttlSeconds`, `dailyWritesPerAuthor`, `write` `'anyone'` /
2978
3144
  * `'owner'`), are enforced by the platform's manifest validator at submit,
2979
3145
  * not by `defineBlock` — see `KNOWN_GAPS['storage-server-only-rules']`.
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
- * 208 symbols and that side effect into the root would make every OAuth app
28
+ * 213 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 208 is ASSERTED, not merely quoted — by
32
+ * 🔴 That 213 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
- * 208 symbols and that side effect into the root would make every OAuth app
28
+ * 213 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 208 is ASSERTED, not merely quoted — by
32
+ * 🔴 That 213 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
@@ -97,6 +97,8 @@ export declare const KNOWN_GAPS: {
97
97
  readonly 'slotId-registry': string;
98
98
  readonly 'settings-meta-schema-not-vendored': string;
99
99
  readonly 'storage-server-only-rules': string;
100
+ readonly 'storage-collection-schema-server-only-rules': string;
101
+ readonly 'storage-migrations-server-only-rules': string;
100
102
  readonly 'format-uri-not-enforced': string;
101
103
  };
102
104
  /** The canonical schema object, parsed once. Exported for tests and tooling. */
@@ -145,11 +145,30 @@ export const KNOWN_GAPS = {
145
145
  'See SCHEMA_DIVERGENCES.settings.',
146
146
  'storage-server-only-rules': 'The canonical `storage` description states rules it does not encode: declaring any ' +
147
147
  'collection requires the `apps:storage` scope, a shared collection viewers write (`write` ' +
148
- '"own" or "anyone") also requires `apps:storage:publish`, requesting either scope with no ' +
149
- 'collection for it to reach is rejected, a counter may not share a name with a mark, and the ' +
148
+ '"own" or "anyone") also requires `apps:storage:publish`, declaring `imports` requires ' +
149
+ '`apps:storage:import` (and `apps:storage`), requesting any of these scopes with nothing for ' +
150
+ 'it to reach is rejected, an import never names this app itself and names each source at ' +
151
+ 'most once, a counter may not share a name with a mark, and the ' +
150
152
  'RESERVED features (`kind` "log", `ttlSeconds`, `dailyWritesPerAuthor`, `write` "anyone" / ' +
151
153
  '"owner") validate offline and are refused at submit. Ajv enforces the structural rules ' +
152
154
  'exactly; these are server-side.',
155
+ 'storage-collection-schema-server-only-rules': 'A collection `schema` (civitai/civitai#7491): the canonical encodes the keyword subset, each ' +
156
+ 'keyword\'s shape, the 256-character `pattern` bound, "a pattern needs a maxLength of at most ' +
157
+ '1000" and "no schema on write none", and Ajv enforces those exactly. It states in prose only ' +
158
+ 'the bounds the server checks at submit: at most 16384 bytes of JSON, 16 nested schemas and ' +
159
+ '16 patterns per collection schema, 32 patterns across the whole manifest, no min above ' +
160
+ 'its max, a pattern that compiles as a JavaScript regular expression with the `u` flag, ' +
161
+ 'and no pattern that can backtrack ' +
162
+ 'catastrophically. Those validate here and are refused at submit.',
163
+ 'storage-migrations-server-only-rules': 'A collection\'s `migrations` (civitai/civitai#7661): the canonical encodes each op\'s shape ' +
164
+ '(`default` / `rename` / `remove` / `acknowledge`), the JSON Pointer form of its paths, the ' +
165
+ 'acknowledge-only `""` and `*`, the `keyword` list, 1 to 32 ops and "no migrations on write ' +
166
+ 'none", and Ajv enforces those exactly. The rest is the server\'s, at submit. Which schema ' +
167
+ 'changes are breaking, and whether an op covers one, needs the PREVIOUS approved manifest, so ' +
168
+ 'a breaking change no op covers and an op that covers nothing (reported, never run) are ' +
169
+ 'decided there. So are the canonical\'s prose-only rules: a `default` value must match the new ' +
170
+ 'schema at its path and be at most 4096 bytes of JSON, and the ops must touch disjoint ' +
171
+ 'fields. All of those validate here.',
153
172
  'format-uri-not-enforced': '`assetBundleUrl` carries `format: "uri"` in addition to `pattern: "^https://"`. Ajv ignores ' +
154
173
  'unknown formats unless `ajv-formats` is installed, which would be a second optional peer for ' +
155
174
  '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, BlockStorageDeclaration, BlockStorageIndexes, BlockStorageIndexType, BlockStoragePrivateCollectionDeclaration, BlockStorageSharedCollectionDeclaration, } from '../blocks/types.js';
18
+ export type { BlockAnalyticsDeclaration, BlockAnalyticsEventDeclaration, BlockAnalyticsPropertyDeclaration, BlockManifest, BlockManifestGood, BlockManifestV1, BlockStorageCollectionDeclaration, BlockStorageCollectionSchema, BlockStorageDeclaration, BlockStorageImport, BlockStorageIndexes, BlockStorageIndexType, BlockStorageMigrationKeyword, BlockStorageMigrationOp, BlockStoragePrivateCollectionDeclaration, BlockStorageSchemaType, BlockStorageSharedCollectionDeclaration, } from '../blocks/types.js';
19
19
  //# sourceMappingURL=index.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@civitai/app-sdk",
3
- "version": "0.80.1",
3
+ "version": "0.82.0",
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",
@@ -55,15 +55,7 @@
55
55
  "category": {
56
56
  "type": "string",
57
57
  "description": "Optional marketplace category for the app's `/apps` store listing. When present it flows to the listing automatically on moderator-approve (only when a moderator has not already curated a category). Omit to let a moderator categorise the app. Must be one of the known marketplace categories — this enum is kept in lockstep with MARKETPLACE_CATEGORIES in src/server/services/blocks/marketplace-categories.constants.ts (a drift-guard test enforces equality).",
58
- "enum": [
59
- "generation",
60
- "games",
61
- "utility",
62
- "discovery",
63
- "moderation",
64
- "analytics",
65
- "other"
66
- ]
58
+ "enum": ["generation", "games", "utility", "discovery", "moderation", "analytics", "other"]
67
59
  },
68
60
  "renderMode": {
69
61
  "type": "string",
@@ -98,6 +90,7 @@
98
90
  "apps:storage:shared:write",
99
91
  "apps:storage",
100
92
  "apps:storage:publish",
93
+ "apps:storage:import",
101
94
  "collections:read:self",
102
95
  "collections:write:self",
103
96
  "collections:read:private",
@@ -111,7 +104,7 @@
111
104
  },
112
105
  "scopeJustifications": {
113
106
  "type": "object",
114
- "description": "Per-scope justification: a map of scope-id → free-text rationale explaining WHY the app needs that permission, shown to the moderator during review. REQUIRED for SENSITIVE scopes — any declared scope that can spend or read the viewer's Buzz, read the viewer's private data, or write data other users see (e.g. `ai:write:budgeted`, `social:tip:self`, `goods:purchase:self`, `buzz:read:self`, `collections:read:private`, `apps:storage:shared:write`, `apps:storage:publish`, `posts:write:self`, `apps:store:items:write`, `social:react:self`) MUST carry a non-empty justification here, or the manifest is rejected at submit time. OPTIONAL for non-sensitive scopes — omit those and the manifest stays valid. Every key MUST be a scope also present in `scopes` (justifications for scopes you don't request are rejected). Each value is a non-empty string of at most 500 characters. The requirement is enforced imperatively by the manifest validator (not expressed as JSON-Schema conditionals here). NOTE: the justification captures the developer's STATED rationale only; the platform does not verify the truth of the claims.",
107
+ "description": "Per-scope justification: a map of scope-id → free-text rationale explaining WHY the app needs that permission, shown to the moderator during review. REQUIRED for SENSITIVE scopes — any declared scope that can spend or read the viewer's Buzz, read the viewer's private data, or write data other users see (e.g. `ai:write:budgeted`, `social:tip:self`, `goods:purchase:self`, `buzz:read:self`, `collections:read:private`, `apps:storage:shared:write`, `apps:storage:publish`, `apps:storage:import`, `posts:write:self`, `apps:store:items:write`, `social:react:self`) MUST carry a non-empty justification here, or the manifest is rejected at submit time. OPTIONAL for non-sensitive scopes — omit those and the manifest stays valid. Every key MUST be a scope also present in `scopes` (justifications for scopes you don't request are rejected). Each value is a non-empty string of at most 500 characters. The requirement is enforced imperatively by the manifest validator (not expressed as JSON-Schema conditionals here). NOTE: the justification captures the developer's STATED rationale only; the platform does not verify the truth of the claims.",
115
108
  "additionalProperties": {
116
109
  "type": "string",
117
110
  "minLength": 1,
@@ -137,7 +130,10 @@
137
130
  "maxLength": 256,
138
131
  "allOf": [
139
132
  { "$comment": "no leading '/' (absolute path)", "not": { "pattern": "^/" } },
140
- { "$comment": "no backslash separators (Windows / '\\..' traversal)", "not": { "pattern": "\\\\" } },
133
+ {
134
+ "$comment": "no backslash separators (Windows / '\\..' traversal)",
135
+ "not": { "pattern": "\\\\" }
136
+ },
141
137
  { "$comment": "no '..' path-traversal segment", "not": { "pattern": "(^|/)\\.\\.(/|$)" } },
142
138
  { "$comment": "no Windows drive prefix (e.g. C:)", "not": { "pattern": "^[A-Za-z]:" } }
143
139
  ]
@@ -378,10 +374,43 @@
378
374
  },
379
375
  "storage": {
380
376
  "type": "object",
381
- "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; and requesting either scope with nothing here for it to reach is rejected. 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.",
377
+ "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.",
382
378
  "additionalProperties": false,
383
- "required": ["collections"],
379
+ "anyOf": [{ "required": ["collections"] }, { "required": ["imports"] }],
384
380
  "properties": {
381
+ "imports": {
382
+ "type": "array",
383
+ "description": "Collections of OTHER apps this app reaches as the viewer — for example a fork reading and writing its parent's data. Each import names the source app by its `blockId`, 1 to 16 distinct collection names the source declares, and the access wanted: \"read\" or \"readwrite\". At most 8 imports, one per source app, never this app itself. Through an import the app acts AS THE VIEWER IN THE SOURCE APP: a private collection gives that viewer's own documents, a shared one reads as the source shows it to them, writes follow the source collection's write policy, and usage counts against the source app's ceilings. Nothing is reached until the viewer grants it: the `apps:storage:import` consent is recorded per (viewer, this app, source app) and can be withdrawn under Apps → Permissions. A source collection with `exportable: false` refuses every import. The SDK reaches one with `app.storage.collection(name, { from: blockId })`.",
384
+ "minItems": 1,
385
+ "maxItems": 8,
386
+ "items": {
387
+ "type": "object",
388
+ "additionalProperties": false,
389
+ "required": ["from", "collections", "access"],
390
+ "properties": {
391
+ "from": {
392
+ "type": "string",
393
+ "description": "The source app's blockId (its slug).",
394
+ "minLength": 3,
395
+ "maxLength": 40,
396
+ "pattern": "^[a-z][a-z0-9-]{1,38}[a-z0-9]$"
397
+ },
398
+ "collections": {
399
+ "type": "array",
400
+ "description": "Names of the source app's collections this import reaches.",
401
+ "minItems": 1,
402
+ "maxItems": 16,
403
+ "uniqueItems": true,
404
+ "items": { "type": "string", "pattern": "^[a-z][a-z0-9_]{0,31}$" }
405
+ },
406
+ "access": {
407
+ "type": "string",
408
+ "description": "\"read\": reads only; every write is refused. \"readwrite\": reads and writes, under the source collection's own write policy. A create, update, counter, mark or unmark in one of the source's SHARED collections also needs the viewer's own `apps:storage:publish` grant in the source app, which the app asks the host to prompt for; a document delete, and any write to a private collection, needs only the import grant.",
409
+ "enum": ["read", "readwrite"]
410
+ }
411
+ }
412
+ }
413
+ },
385
414
  "collections": {
386
415
  "type": "object",
387
416
  "description": "Map of collection name → declaration. At least 1 and at most 16 collections. A collection name is lowercase snake_case: a letter, then up to 31 of a-z, 0-9 or _. Renaming a collection, or changing its visibility, is a NEW collection: the old one's documents are not carried over.",
@@ -470,6 +499,10 @@
470
499
  "minimum": 1,
471
500
  "maximum": 1000
472
501
  },
502
+ "exportable": {
503
+ "type": "boolean",
504
+ "description": "Whether other apps may reach this collection through their `storage.imports` (with the viewer's consent). Default true; false refuses every import of it with 403 `not_exportable`."
505
+ },
473
506
  "ownedModelVersions": {
474
507
  "type": "array",
475
508
  "description": "Shared collections with `write` \"own\" only. Fields of a document's `data` that, when present, must hold a Civitai model version id owned by the viewer writing the document — for example [\"/workflow/modelVersionId\"] for a collection where viewers publish their own workflows. Each entry is a pointer of 1 to 4 segments, each \"/\" then a letter or _ followed by up to 63 letters, digits or _; 1 to 4 distinct pointers. A pointer names one field of nested objects: it never indexes into an array, and a step through an array or any other non-object finds nothing. On every create and update the server resolves each pointer in the new `data`: a field that is absent is allowed; a field that is present must be a positive integer naming a model version whose model the writer owns, and is otherwise refused with 403 `resource_not_owned` — a version that is someone else's, missing or deleted, and a value that is not a positive integer, are all refused the same way. The check runs before moderation and before any write budget is spent. Ownership is checked when a document is written, not afterwards: if the model later changes hands or is deleted, documents already stored keep the id.",
@@ -480,9 +513,28 @@
480
513
  "type": "string",
481
514
  "pattern": "^(/[A-Za-z_][A-Za-z0-9_]{0,63}){1,4}$"
482
515
  }
516
+ },
517
+ "schema": {
518
+ "description": "Optional. A JSON Schema SUBSET that every document's `data` in this collection must match. The server checks it on every create and update and refuses a document that does not match with 400 `schema_violation`, whose message names the first failing JSON pointer into `data` (for example \"/title\"); counters and marks are not checked. Without a schema, documents are not checked. Supported keywords only: type (object, array, string, number, integer, boolean, null, or an array of them), properties, required, additionalProperties (true, false or a schema), items (one schema for every element), enum, const, minLength, maxLength, pattern, minimum, maximum, minItems, maxItems and description; any other keyword is refused at submit with a message naming it. Keywords that do not apply to a value's type are ignored; string lengths count code points; `pattern` is a JavaScript regular expression (the \"u\" flag), unanchored, of at most 256 characters, and a schema with a `pattern` must also declare a `maxLength` of at most 1000; a pattern that can backtrack catastrophically (analysed with the \"u\" flag, as the store runs it) is refused at submit. At most 16 patterns per schema and 32 across all of the manifest's collection schemas together, schemas nested at most 16 deep, and at most 16384 bytes of JSON. Not allowed on a `write` \"none\" collection. Changing a schema does not re-check documents already stored; they are checked when next written. A change that narrows the schema against the previous approved version (a newly required property; a type, enum, const, bound or pattern narrowed; `additionalProperties` closed or newly a schema; a declared property removed under `additionalProperties: false`; or a schema added where there was none) is refused at submit unless `migrations` covers it.",
519
+ "$ref": "#/$defs/storageCollectionSchema"
520
+ },
521
+ "migrations": {
522
+ "type": "array",
523
+ "description": "Optional. Declarative ops applied to this collection's documents ALREADY STORED in production when this version is approved, for a schema change that would otherwise leave them unwritable. Submit compares this collection's `schema` with the previous approved version's (statically; stored documents are never read) and refuses every BREAKING change no op here covers: \"default\" covers a newly required property at its `path` (`value` must match the new schema there) — the only op that can; \"rename\" covers a declared property removed under `additionalProperties: false`, at `from`; \"remove\" covers any breaking change at or under a field the new schema does not require; \"acknowledge\" covers exactly the one breaking change whose pointer is its `path` (\"\" for the document root, \"*\" for an `items` or `additionalProperties` schema, matched literally, never as a prefix) with its `keyword` and changes nothing — documents that violate it are refused on their next write until reshaped. A first schema on a collection that had none is compared with accept-anything, so each of its constraints is its own breaking change. The paths of default, rename and remove are JSON Pointers to one field of a document's data (\"/meta/title\"). Every op is idempotent, and default, rename and remove ops must touch disjoint fields, so a re-run changes nothing. Only the ops that cover a breaking change of THIS version run, once, in bounded batches; an op that covers nothing is reported at submit and never runs, so a list left in a later version is inert. Not allowed on a `write` \"none\" collection. 1 to 32 ops.",
524
+ "minItems": 1,
525
+ "maxItems": 32,
526
+ "items": { "$ref": "#/$defs/storageMigrationOp" }
483
527
  }
484
528
  },
485
529
  "allOf": [
530
+ {
531
+ "$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.",
532
+ "if": {
533
+ "required": ["write"],
534
+ "properties": { "write": { "const": "none" } }
535
+ },
536
+ "then": { "properties": { "schema": false, "migrations": false } }
537
+ },
486
538
  {
487
539
  "$comment": "A shared collection must state its write policy; a private one carries none of the shared-only fields.",
488
540
  "if": {
@@ -560,6 +612,124 @@
560
612
  }
561
613
  }
562
614
  },
615
+ "$defs": {
616
+ "storageCollectionSchema": {
617
+ "type": "object",
618
+ "description": "One schema of the storage collection-schema subset (see `storage.collections.<name>.schema`). Depth, size, pattern-count and min-greater-than-max limits, and whether a pattern compiles, are checked by the server, not by this schema.",
619
+ "additionalProperties": false,
620
+ "properties": {
621
+ "type": {
622
+ "anyOf": [
623
+ { "$ref": "#/$defs/storageCollectionSchemaType" },
624
+ {
625
+ "type": "array",
626
+ "minItems": 1,
627
+ "uniqueItems": true,
628
+ "items": { "$ref": "#/$defs/storageCollectionSchemaType" }
629
+ }
630
+ ]
631
+ },
632
+ "properties": {
633
+ "type": "object",
634
+ "additionalProperties": { "$ref": "#/$defs/storageCollectionSchema" }
635
+ },
636
+ "required": { "type": "array", "uniqueItems": true, "items": { "type": "string" } },
637
+ "additionalProperties": {
638
+ "anyOf": [{ "type": "boolean" }, { "$ref": "#/$defs/storageCollectionSchema" }]
639
+ },
640
+ "items": { "$ref": "#/$defs/storageCollectionSchema" },
641
+ "enum": { "type": "array", "minItems": 1 },
642
+ "const": {},
643
+ "minLength": { "type": "integer", "minimum": 0 },
644
+ "maxLength": { "type": "integer", "minimum": 0 },
645
+ "pattern": { "type": "string", "maxLength": 256 },
646
+ "minimum": { "type": "number" },
647
+ "maximum": { "type": "number" },
648
+ "minItems": { "type": "integer", "minimum": 0 },
649
+ "maxItems": { "type": "integer", "minimum": 0 },
650
+ "description": { "type": "string" }
651
+ },
652
+ "if": { "required": ["pattern"] },
653
+ "then": { "required": ["maxLength"], "properties": { "maxLength": { "maximum": 1000 } } }
654
+ },
655
+ "storageMigrationPath": {
656
+ "type": "string",
657
+ "description": "A JSON Pointer to one field of a document's data: 1 to 15 non-empty segments, each \"/\" then the field name with ~ written ~0 and / written ~1. No \"*\" segment.",
658
+ "maxLength": 512,
659
+ "pattern": "^(/([^/~]|~[01])+){1,15}$",
660
+ "not": { "pattern": "/\\*(/|$)" }
661
+ },
662
+ "storageMigrationOp": {
663
+ "description": "One migration op. See `storage.collections.<name>.migrations`.",
664
+ "oneOf": [
665
+ {
666
+ "type": "object",
667
+ "additionalProperties": false,
668
+ "required": ["op", "path", "value"],
669
+ "properties": {
670
+ "op": { "const": "default" },
671
+ "path": { "$ref": "#/$defs/storageMigrationPath" },
672
+ "value": {
673
+ "description": "Set where the field is missing (its parent object exists). Must match the new schema at `path`; at most 4096 bytes of JSON."
674
+ }
675
+ }
676
+ },
677
+ {
678
+ "type": "object",
679
+ "additionalProperties": false,
680
+ "required": ["op", "from", "to"],
681
+ "properties": {
682
+ "op": { "const": "rename" },
683
+ "from": { "$ref": "#/$defs/storageMigrationPath" },
684
+ "to": { "$ref": "#/$defs/storageMigrationPath" }
685
+ }
686
+ },
687
+ {
688
+ "type": "object",
689
+ "additionalProperties": false,
690
+ "required": ["op", "path"],
691
+ "properties": {
692
+ "op": { "const": "remove" },
693
+ "path": { "$ref": "#/$defs/storageMigrationPath" }
694
+ }
695
+ },
696
+ {
697
+ "type": "object",
698
+ "additionalProperties": false,
699
+ "required": ["op", "path", "keyword"],
700
+ "properties": {
701
+ "op": { "const": "acknowledge" },
702
+ "path": {
703
+ "type": "string",
704
+ "description": "The JSON Pointer of the one breaking change accepted, matched EXACTLY (never as a prefix): \"\" for a change at the document root, or up to 15 non-empty segments, where the segment \"*\" is the pointer of a change inside `items` or an `additionalProperties` schema (\"/tags/*\").",
705
+ "maxLength": 512,
706
+ "pattern": "^(/([^/~]|~[01])+){0,15}$"
707
+ },
708
+ "keyword": {
709
+ "description": "The schema keyword of the one breaking change accepted at `path`. A newly required field (\"required\") cannot be acknowledged: cover it with a \"default\".",
710
+ "enum": [
711
+ "type",
712
+ "const",
713
+ "enum",
714
+ "minimum",
715
+ "maximum",
716
+ "minLength",
717
+ "maxLength",
718
+ "minItems",
719
+ "maxItems",
720
+ "pattern",
721
+ "additionalProperties",
722
+ "properties"
723
+ ]
724
+ }
725
+ }
726
+ }
727
+ ]
728
+ },
729
+ "storageCollectionSchemaType": {
730
+ "enum": ["object", "array", "string", "number", "integer", "boolean", "null"]
731
+ }
732
+ },
563
733
  "allOf": [
564
734
  {
565
735
  "$comment": "outputDir is required whenever buildCommand is set. NOTE: the server-owned iframe.src and trustTier fields are rejected by the platform validator (and the CLI in Go) with clearer error messages than JSON Schema's `not`; they are declared in `properties` above only so the schema documents them.",