@civitai/app-sdk 0.1.0 → 0.7.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.
- package/README.md +46 -1
- package/dist/blocks/defineBlock.d.ts +32 -0
- package/dist/blocks/defineBlock.d.ts.map +1 -0
- package/dist/blocks/defineBlock.js +270 -0
- package/dist/blocks/defineBlock.js.map +1 -0
- package/dist/blocks/index.d.ts +16 -0
- package/dist/blocks/index.d.ts.map +1 -0
- package/dist/blocks/index.js +12 -0
- package/dist/blocks/index.js.map +1 -0
- package/dist/blocks/messages.d.ts +289 -0
- package/dist/blocks/messages.d.ts.map +1 -0
- package/dist/blocks/messages.js +31 -0
- package/dist/blocks/messages.js.map +1 -0
- package/dist/blocks/scopes.d.ts +35 -0
- package/dist/blocks/scopes.d.ts.map +1 -0
- package/dist/blocks/scopes.js +33 -0
- package/dist/blocks/scopes.js.map +1 -0
- package/dist/blocks/types.d.ts +371 -0
- package/dist/blocks/types.d.ts.map +1 -0
- package/dist/blocks/types.js +8 -0
- package/dist/blocks/types.js.map +1 -0
- package/dist/oauth/token.d.ts +28 -0
- package/dist/oauth/token.d.ts.map +1 -1
- package/dist/oauth/token.js +28 -0
- package/dist/oauth/token.js.map +1 -1
- package/dist/orchestrator/index.d.ts +224 -0
- package/dist/orchestrator/index.d.ts.map +1 -1
- package/dist/orchestrator/index.js +207 -0
- package/dist/orchestrator/index.js.map +1 -1
- package/package.json +11 -5
- package/schemas/app-block/v1.json +184 -0
- package/dist/client/index.d.ts +0 -23
- package/dist/client/index.d.ts.map +0 -1
- package/dist/client/index.js +0 -19
- package/dist/client/index.js.map +0 -1
- package/dist/workflows/index.d.ts +0 -52
- package/dist/workflows/index.d.ts.map +0 -1
- package/dist/workflows/index.js +0 -77
- package/dist/workflows/index.js.map +0 -1
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* postMessage protocol between an embedding host page and an iframe-mode block.
|
|
3
|
+
*
|
|
4
|
+
* Discriminated by `type`. Both directions share this module so producers and
|
|
5
|
+
* consumers stay in lockstep — adding a parent→block message means the block
|
|
6
|
+
* side gets a compile error until it handles the new variant (and vice versa).
|
|
7
|
+
*
|
|
8
|
+
* Wire format: `window.postMessage({ type, payload }, targetOrigin)`.
|
|
9
|
+
*/
|
|
10
|
+
import type { BlockCheckpointInfo, BlockContext, BlockSettings, Theme, ViewerInfo, WorkflowBody, BlockWorkflowSnapshot } from './types.js';
|
|
11
|
+
/**
|
|
12
|
+
* The wrapped token shape the host sends to the block. `raw` is the JWT;
|
|
13
|
+
* `scopes`, `expiresAt`, and `buzzBudget` are extracted from the JWT claims
|
|
14
|
+
* so blocks don't have to decode it themselves. `buzzBudget` is only present
|
|
15
|
+
* when the manifest declares `ai:write:budgeted`.
|
|
16
|
+
*
|
|
17
|
+
* Mirrors the `token` field shape in civitai/civitai's `IframeHost.tsx`.
|
|
18
|
+
*/
|
|
19
|
+
export interface WrappedToken {
|
|
20
|
+
raw: string;
|
|
21
|
+
scopes: string[];
|
|
22
|
+
/** ISO-8601; consumers rehydrate to Date. */
|
|
23
|
+
expiresAt: string;
|
|
24
|
+
buzzBudget?: number;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Payload of the first `BLOCK_INIT` message a block receives. The host waits
|
|
28
|
+
* for both the iframe `load` event AND a minted token before sending this.
|
|
29
|
+
*
|
|
30
|
+
* Mirrors `BlockInitPayload` in civitai/civitai's
|
|
31
|
+
* `src/components/AppBlocks/types.ts`. Adding a field here without a
|
|
32
|
+
* matching change on the platform side (or vice versa) is the bug class
|
|
33
|
+
* `internal/validate.ts` exists to surface — keep the validator in lockstep
|
|
34
|
+
* with both sides.
|
|
35
|
+
*/
|
|
36
|
+
export interface BlockInitPayload {
|
|
37
|
+
blockInstanceId: string;
|
|
38
|
+
blockId: string;
|
|
39
|
+
/** The OauthClient (app) this block belongs to. */
|
|
40
|
+
appId: string;
|
|
41
|
+
token: WrappedToken;
|
|
42
|
+
context: BlockContext;
|
|
43
|
+
settings: BlockSettings;
|
|
44
|
+
/** `null` when the viewer is anonymous. */
|
|
45
|
+
viewer: ViewerInfo | null;
|
|
46
|
+
theme: Theme;
|
|
47
|
+
renderMode: 'iframe' | 'inline';
|
|
48
|
+
}
|
|
49
|
+
export type ParentToBlockMessage = {
|
|
50
|
+
type: 'BLOCK_INIT';
|
|
51
|
+
payload: BlockInitPayload;
|
|
52
|
+
} | {
|
|
53
|
+
type: 'TOKEN_REFRESH';
|
|
54
|
+
payload: {
|
|
55
|
+
token: WrappedToken;
|
|
56
|
+
};
|
|
57
|
+
} | {
|
|
58
|
+
type: 'TOKEN_REFRESH_RESPONSE';
|
|
59
|
+
payload: {
|
|
60
|
+
requestId?: string;
|
|
61
|
+
token: WrappedToken;
|
|
62
|
+
};
|
|
63
|
+
} | {
|
|
64
|
+
type: 'ESTIMATE_RESULT';
|
|
65
|
+
payload: {
|
|
66
|
+
requestId: string;
|
|
67
|
+
snapshot: BlockWorkflowSnapshot;
|
|
68
|
+
};
|
|
69
|
+
} | {
|
|
70
|
+
type: 'WORKFLOW_SUBMITTED';
|
|
71
|
+
payload: {
|
|
72
|
+
requestId: string;
|
|
73
|
+
snapshot: BlockWorkflowSnapshot;
|
|
74
|
+
};
|
|
75
|
+
} | {
|
|
76
|
+
type: 'WORKFLOW_STATUS';
|
|
77
|
+
payload: {
|
|
78
|
+
requestId: string;
|
|
79
|
+
snapshot: BlockWorkflowSnapshot;
|
|
80
|
+
};
|
|
81
|
+
} | {
|
|
82
|
+
type: 'WORKFLOW_CANCELED';
|
|
83
|
+
payload: {
|
|
84
|
+
requestId: string;
|
|
85
|
+
snapshot: BlockWorkflowSnapshot;
|
|
86
|
+
};
|
|
87
|
+
} | {
|
|
88
|
+
type: 'BUZZ_PURCHASE_RESULT';
|
|
89
|
+
payload: {
|
|
90
|
+
requestId: string;
|
|
91
|
+
purchased: boolean;
|
|
92
|
+
newBalance?: number;
|
|
93
|
+
};
|
|
94
|
+
} | {
|
|
95
|
+
type: 'CHECKPOINT_PICKER_RESULT';
|
|
96
|
+
payload: {
|
|
97
|
+
requestId: string;
|
|
98
|
+
selected?: BlockCheckpointInfo;
|
|
99
|
+
};
|
|
100
|
+
} | {
|
|
101
|
+
type: 'USER_CHECKPOINT_SET';
|
|
102
|
+
payload: {
|
|
103
|
+
requestId: string;
|
|
104
|
+
ok: boolean;
|
|
105
|
+
error?: string;
|
|
106
|
+
};
|
|
107
|
+
} | {
|
|
108
|
+
type: 'APP_STORAGE_GET_RESULT';
|
|
109
|
+
payload: {
|
|
110
|
+
requestId: string;
|
|
111
|
+
value: unknown;
|
|
112
|
+
error?: string;
|
|
113
|
+
};
|
|
114
|
+
} | {
|
|
115
|
+
type: 'APP_STORAGE_SET_RESULT';
|
|
116
|
+
payload: {
|
|
117
|
+
requestId: string;
|
|
118
|
+
ok: boolean;
|
|
119
|
+
error?: string;
|
|
120
|
+
sizeBytes?: number;
|
|
121
|
+
};
|
|
122
|
+
} | {
|
|
123
|
+
type: 'APP_STORAGE_DELETE_RESULT';
|
|
124
|
+
payload: {
|
|
125
|
+
requestId: string;
|
|
126
|
+
ok: boolean;
|
|
127
|
+
deleted: boolean;
|
|
128
|
+
error?: string;
|
|
129
|
+
};
|
|
130
|
+
} | {
|
|
131
|
+
type: 'APP_STORAGE_LIST_RESULT';
|
|
132
|
+
payload: {
|
|
133
|
+
requestId: string;
|
|
134
|
+
keys: Array<{
|
|
135
|
+
key: string;
|
|
136
|
+
updatedAt: string;
|
|
137
|
+
}>;
|
|
138
|
+
nextCursor?: string;
|
|
139
|
+
error?: string;
|
|
140
|
+
};
|
|
141
|
+
} | {
|
|
142
|
+
type: 'APP_STORAGE_QUOTA_RESULT';
|
|
143
|
+
payload: {
|
|
144
|
+
requestId: string;
|
|
145
|
+
usedBytes: number;
|
|
146
|
+
rowCount: number;
|
|
147
|
+
limitBytes: number;
|
|
148
|
+
limitRows: number;
|
|
149
|
+
error?: string;
|
|
150
|
+
};
|
|
151
|
+
} | {
|
|
152
|
+
type: 'SUSPEND';
|
|
153
|
+
payload?: undefined;
|
|
154
|
+
} | {
|
|
155
|
+
type: 'RESUME';
|
|
156
|
+
payload?: undefined;
|
|
157
|
+
};
|
|
158
|
+
export type ParentToBlockMessageType = ParentToBlockMessage['type'];
|
|
159
|
+
export type BlockToParentMessage = {
|
|
160
|
+
type: 'BLOCK_READY';
|
|
161
|
+
payload: {
|
|
162
|
+
height: number;
|
|
163
|
+
};
|
|
164
|
+
} | {
|
|
165
|
+
type: 'BLOCK_ERROR';
|
|
166
|
+
payload: {
|
|
167
|
+
message: string;
|
|
168
|
+
fatal: boolean;
|
|
169
|
+
};
|
|
170
|
+
} | {
|
|
171
|
+
type: 'REQUEST_TOKEN';
|
|
172
|
+
payload: {
|
|
173
|
+
requestId: string;
|
|
174
|
+
blockInstanceId: string;
|
|
175
|
+
};
|
|
176
|
+
} | {
|
|
177
|
+
type: 'RESIZE_IFRAME';
|
|
178
|
+
payload: {
|
|
179
|
+
height: number;
|
|
180
|
+
};
|
|
181
|
+
} | {
|
|
182
|
+
type: 'SUBMIT_WORKFLOW';
|
|
183
|
+
payload: {
|
|
184
|
+
requestId: string;
|
|
185
|
+
body: WorkflowBody;
|
|
186
|
+
};
|
|
187
|
+
} | {
|
|
188
|
+
type: 'ESTIMATE_WORKFLOW';
|
|
189
|
+
payload: {
|
|
190
|
+
requestId: string;
|
|
191
|
+
body: WorkflowBody;
|
|
192
|
+
};
|
|
193
|
+
} | {
|
|
194
|
+
type: 'POLL_WORKFLOW';
|
|
195
|
+
payload: {
|
|
196
|
+
requestId: string;
|
|
197
|
+
workflowId: string;
|
|
198
|
+
};
|
|
199
|
+
} | {
|
|
200
|
+
type: 'CANCEL_WORKFLOW';
|
|
201
|
+
payload: {
|
|
202
|
+
requestId: string;
|
|
203
|
+
workflowId: string;
|
|
204
|
+
};
|
|
205
|
+
} | {
|
|
206
|
+
type: 'OPEN_BUZZ_PURCHASE';
|
|
207
|
+
payload: {
|
|
208
|
+
requestId: string;
|
|
209
|
+
suggestedAmount?: number;
|
|
210
|
+
};
|
|
211
|
+
} | {
|
|
212
|
+
type: 'OPEN_CHECKPOINT_PICKER';
|
|
213
|
+
payload: {
|
|
214
|
+
requestId: string;
|
|
215
|
+
baseModelGroup: string;
|
|
216
|
+
/** Currently-selected versionId so the picker can pre-highlight it. */
|
|
217
|
+
currentVersionId?: number;
|
|
218
|
+
};
|
|
219
|
+
} | {
|
|
220
|
+
type: 'SET_USER_CHECKPOINT';
|
|
221
|
+
payload: {
|
|
222
|
+
requestId: string;
|
|
223
|
+
versionId: number | null;
|
|
224
|
+
};
|
|
225
|
+
} | {
|
|
226
|
+
type: 'NAVIGATE';
|
|
227
|
+
payload: {
|
|
228
|
+
path: string;
|
|
229
|
+
target: 'current' | 'new_tab';
|
|
230
|
+
};
|
|
231
|
+
} | {
|
|
232
|
+
type: 'TRACK_EVENT';
|
|
233
|
+
payload: {
|
|
234
|
+
eventName: string;
|
|
235
|
+
properties?: Record<string, unknown>;
|
|
236
|
+
};
|
|
237
|
+
} | {
|
|
238
|
+
type: 'APP_STORAGE_GET';
|
|
239
|
+
payload: {
|
|
240
|
+
requestId: string;
|
|
241
|
+
key: string;
|
|
242
|
+
};
|
|
243
|
+
} | {
|
|
244
|
+
type: 'APP_STORAGE_SET';
|
|
245
|
+
payload: {
|
|
246
|
+
requestId: string;
|
|
247
|
+
key: string;
|
|
248
|
+
value: unknown;
|
|
249
|
+
};
|
|
250
|
+
} | {
|
|
251
|
+
type: 'APP_STORAGE_DELETE';
|
|
252
|
+
payload: {
|
|
253
|
+
requestId: string;
|
|
254
|
+
key: string;
|
|
255
|
+
};
|
|
256
|
+
} | {
|
|
257
|
+
type: 'APP_STORAGE_LIST';
|
|
258
|
+
payload: {
|
|
259
|
+
requestId: string;
|
|
260
|
+
prefix?: string;
|
|
261
|
+
limit?: number;
|
|
262
|
+
cursor?: string;
|
|
263
|
+
};
|
|
264
|
+
} | {
|
|
265
|
+
type: 'APP_STORAGE_QUOTA';
|
|
266
|
+
payload: {
|
|
267
|
+
requestId: string;
|
|
268
|
+
};
|
|
269
|
+
};
|
|
270
|
+
export type BlockToParentMessageType = BlockToParentMessage['type'];
|
|
271
|
+
/**
|
|
272
|
+
* Narrowing helper for either-direction message handlers.
|
|
273
|
+
*
|
|
274
|
+
* **Discriminator-only.** This only checks `data.type`; it does NOT validate
|
|
275
|
+
* the `payload` shape. A peer sending `{ type: 'BLOCK_INIT' }` with no
|
|
276
|
+
* payload or a malformed payload will satisfy this guard, and downstream
|
|
277
|
+
* access to fields like `data.payload.token.raw` will throw at runtime.
|
|
278
|
+
* Transports that cross a trust boundary (e.g. iframe `postMessage`) MUST
|
|
279
|
+
* runtime-validate the payload at the boundary before passing it on.
|
|
280
|
+
*
|
|
281
|
+
* Example:
|
|
282
|
+
* if (isMessage(event.data, 'BLOCK_INIT')) {
|
|
283
|
+
* // narrowed to BlockInitPayload — still must be validated
|
|
284
|
+
* }
|
|
285
|
+
*/
|
|
286
|
+
export declare function isMessage<T extends ParentToBlockMessage | BlockToParentMessage, K extends T['type']>(data: unknown, type: K): data is Extract<T, {
|
|
287
|
+
type: K;
|
|
288
|
+
}>;
|
|
289
|
+
//# sourceMappingURL=messages.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../src/blocks/messages.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EACV,mBAAmB,EACnB,YAAY,EACZ,aAAa,EACb,KAAK,EACL,UAAU,EACV,YAAY,EACZ,qBAAqB,EACtB,MAAM,YAAY,CAAC;AAMpB;;;;;;;GAOG;AACH,MAAM,WAAW,YAAY;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,6CAA6C;IAC7C,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;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AC;CACtE,GAKD;IACE,IAAI,EAAE,iBAAiB,CAAC;IACxB,OAAO,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC;CAC7C,GACD;IACE,IAAI,EAAE,iBAAiB,CAAC;IACxB,OAAO,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,OAAO,CAAA;KAAE,CAAC;CAC7D,GACD;IACE,IAAI,EAAE,oBAAoB,CAAC;IAC3B,OAAO,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC;CAC7C,GACD;IACE,IAAI,EAAE,kBAAkB,CAAC;IACzB,OAAO,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAClF,GACD;IACE,IAAI,EAAE,mBAAmB,CAAC;IAC1B,OAAO,EAAE;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;CAChC,CAAC;AAEN,MAAM,MAAM,wBAAwB,GAAG,oBAAoB,CAAC,MAAM,CAAC,CAAC;AAEpE;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,oBAAoB,GAAG,oBAAoB,EAAE,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,EAClG,IAAI,EAAE,OAAO,EACb,IAAI,EAAE,CAAC,GACN,IAAI,IAAI,OAAO,CAAC,CAAC,EAAE;IAAE,IAAI,EAAE,CAAC,CAAA;CAAE,CAAC,CAOjC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* postMessage protocol between an embedding host page and an iframe-mode block.
|
|
3
|
+
*
|
|
4
|
+
* Discriminated by `type`. Both directions share this module so producers and
|
|
5
|
+
* consumers stay in lockstep — adding a parent→block message means the block
|
|
6
|
+
* side gets a compile error until it handles the new variant (and vice versa).
|
|
7
|
+
*
|
|
8
|
+
* Wire format: `window.postMessage({ type, payload }, targetOrigin)`.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Narrowing helper for either-direction message handlers.
|
|
12
|
+
*
|
|
13
|
+
* **Discriminator-only.** This only checks `data.type`; it does NOT validate
|
|
14
|
+
* the `payload` shape. A peer sending `{ type: 'BLOCK_INIT' }` with no
|
|
15
|
+
* payload or a malformed payload will satisfy this guard, and downstream
|
|
16
|
+
* access to fields like `data.payload.token.raw` will throw at runtime.
|
|
17
|
+
* Transports that cross a trust boundary (e.g. iframe `postMessage`) MUST
|
|
18
|
+
* runtime-validate the payload at the boundary before passing it on.
|
|
19
|
+
*
|
|
20
|
+
* Example:
|
|
21
|
+
* if (isMessage(event.data, 'BLOCK_INIT')) {
|
|
22
|
+
* // narrowed to BlockInitPayload — still must be validated
|
|
23
|
+
* }
|
|
24
|
+
*/
|
|
25
|
+
export function isMessage(data, type) {
|
|
26
|
+
return (typeof data === 'object' &&
|
|
27
|
+
data !== null &&
|
|
28
|
+
'type' in data &&
|
|
29
|
+
data.type === type);
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=messages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages.js","sourceRoot":"","sources":["../../src/blocks/messages.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAqOH;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,SAAS,CACvB,IAAa,EACb,IAAO;IAEP,OAAO,CACL,OAAO,IAAI,KAAK,QAAQ;QACxB,IAAI,KAAK,IAAI;QACb,MAAM,IAAI,IAAI;QACb,IAA0B,CAAC,IAAI,KAAK,IAAI,CAC1C,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Block-scope strings.
|
|
3
|
+
*
|
|
4
|
+
* Distinct from the OAuth `TokenScope` bitmask in `../scopes/`: block scopes
|
|
5
|
+
* are colon-separated lowercase identifiers that appear verbatim in the
|
|
6
|
+
* manifest and in block-scoped JWTs. The civitai/civitai server owns the
|
|
7
|
+
* mapping from these strings to OAuth bits.
|
|
8
|
+
*
|
|
9
|
+
* Format: `domain:verb:target`, all lowercase. `defineBlock` rejects any
|
|
10
|
+
* scope that does not match this pattern, including the PascalCase form
|
|
11
|
+
* used elsewhere in the SDK for OAuth bits.
|
|
12
|
+
*/
|
|
13
|
+
export declare const BLOCK_SCOPES: {
|
|
14
|
+
readonly MODELS_READ_SELF: "models:read:self";
|
|
15
|
+
readonly MEDIA_READ_OWNED: "media:read:owned";
|
|
16
|
+
readonly USER_READ_SELF: "user:read:self";
|
|
17
|
+
readonly AI_WRITE_BUDGETED: "ai:write:budgeted";
|
|
18
|
+
readonly BUZZ_READ_SELF: "buzz:read:self";
|
|
19
|
+
readonly BLOCK_SETTINGS_READ: "block:settings:read";
|
|
20
|
+
readonly BLOCK_SETTINGS_WRITE: "block:settings:write";
|
|
21
|
+
readonly SOCIAL_TIP_SELF: "social:tip:self";
|
|
22
|
+
};
|
|
23
|
+
export type BlockScopeKey = keyof typeof BLOCK_SCOPES;
|
|
24
|
+
export type BlockScope = (typeof BLOCK_SCOPES)[BlockScopeKey];
|
|
25
|
+
/**
|
|
26
|
+
* Regex enforced by `defineBlock` and the JSON schema.
|
|
27
|
+
*
|
|
28
|
+
* The 3-segment shape (`domain:verb:target`) is **intentional**: scope
|
|
29
|
+
* comparisons in token validation rely on it. Relaxing this (e.g. to allow
|
|
30
|
+
* 4+ segments like `ai:write:image:budgeted`) requires a coordinated change
|
|
31
|
+
* across the SDK, the JSON schema, the civitai/civitai token validator,
|
|
32
|
+
* and a `@civitai/app-sdk` major bump.
|
|
33
|
+
*/
|
|
34
|
+
export declare const BLOCK_SCOPE_PATTERN: RegExp;
|
|
35
|
+
//# sourceMappingURL=scopes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scopes.d.ts","sourceRoot":"","sources":["../../src/blocks/scopes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,YAAY;;;;;;;;;CASf,CAAC;AAEX,MAAM,MAAM,aAAa,GAAG,MAAM,OAAO,YAAY,CAAC;AACtD,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,aAAa,CAAC,CAAC;AAE9D;;;;;;;;GAQG;AACH,eAAO,MAAM,mBAAmB,QAA2B,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Block-scope strings.
|
|
3
|
+
*
|
|
4
|
+
* Distinct from the OAuth `TokenScope` bitmask in `../scopes/`: block scopes
|
|
5
|
+
* are colon-separated lowercase identifiers that appear verbatim in the
|
|
6
|
+
* manifest and in block-scoped JWTs. The civitai/civitai server owns the
|
|
7
|
+
* mapping from these strings to OAuth bits.
|
|
8
|
+
*
|
|
9
|
+
* Format: `domain:verb:target`, all lowercase. `defineBlock` rejects any
|
|
10
|
+
* scope that does not match this pattern, including the PascalCase form
|
|
11
|
+
* used elsewhere in the SDK for OAuth bits.
|
|
12
|
+
*/
|
|
13
|
+
export const BLOCK_SCOPES = {
|
|
14
|
+
MODELS_READ_SELF: 'models:read:self',
|
|
15
|
+
MEDIA_READ_OWNED: 'media:read:owned',
|
|
16
|
+
USER_READ_SELF: 'user:read:self',
|
|
17
|
+
AI_WRITE_BUDGETED: 'ai:write:budgeted',
|
|
18
|
+
BUZZ_READ_SELF: 'buzz:read:self',
|
|
19
|
+
BLOCK_SETTINGS_READ: 'block:settings:read',
|
|
20
|
+
BLOCK_SETTINGS_WRITE: 'block:settings:write',
|
|
21
|
+
SOCIAL_TIP_SELF: 'social:tip:self',
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Regex enforced by `defineBlock` and the JSON schema.
|
|
25
|
+
*
|
|
26
|
+
* The 3-segment shape (`domain:verb:target`) is **intentional**: scope
|
|
27
|
+
* comparisons in token validation rely on it. Relaxing this (e.g. to allow
|
|
28
|
+
* 4+ segments like `ai:write:image:budgeted`) requires a coordinated change
|
|
29
|
+
* across the SDK, the JSON schema, the civitai/civitai token validator,
|
|
30
|
+
* and a `@civitai/app-sdk` major bump.
|
|
31
|
+
*/
|
|
32
|
+
export const BLOCK_SCOPE_PATTERN = /^[a-z]+:[a-z]+:[a-z]+$/;
|
|
33
|
+
//# sourceMappingURL=scopes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scopes.js","sourceRoot":"","sources":["../../src/blocks/scopes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,gBAAgB,EAAE,kBAAkB;IACpC,gBAAgB,EAAE,kBAAkB;IACpC,cAAc,EAAE,gBAAgB;IAChC,iBAAiB,EAAE,mBAAmB;IACtC,cAAc,EAAE,gBAAgB;IAChC,mBAAmB,EAAE,qBAAqB;IAC1C,oBAAoB,EAAE,sBAAsB;IAC5C,eAAe,EAAE,iBAAiB;CAC1B,CAAC;AAKX;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,wBAAwB,CAAC"}
|