@decocms/blocks 8.9.1 → 8.10.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/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/protocol/channel.d.ts +98 -0
- package/dist/protocol/channel.d.ts.map +1 -0
- package/dist/protocol/channel.js +58 -0
- package/dist/protocol/channel.js.map +1 -0
- package/dist/protocol/client.js +2 -2
- package/dist/protocol/client.js.map +1 -1
- package/dist/protocol/conformance/blockMetaVectors.json +214 -0
- package/dist/protocol/conformance/contentHashFixtures.d.ts +22 -0
- package/dist/protocol/conformance/contentHashFixtures.d.ts.map +1 -1
- package/dist/protocol/conformance/contentHashFixtures.js +55 -0
- package/dist/protocol/conformance/contentHashFixtures.js.map +1 -1
- package/dist/protocol/conformance/index.d.ts +2 -1
- package/dist/protocol/conformance/index.d.ts.map +1 -1
- package/dist/protocol/conformance/index.js +2 -1
- package/dist/protocol/conformance/index.js.map +1 -1
- package/dist/protocol/conformance/vectors.d.ts +33 -0
- package/dist/protocol/conformance/vectors.d.ts.map +1 -0
- package/dist/protocol/conformance/vectors.js +3 -0
- package/dist/protocol/conformance/vectors.js.map +1 -0
- package/dist/protocol/index.d.ts +11 -1
- package/dist/protocol/index.d.ts.map +1 -1
- package/dist/protocol/index.js +11 -1
- package/dist/protocol/index.js.map +1 -1
- package/dist/protocol/keys.d.ts +1 -1
- package/dist/protocol/keys.js +1 -1
- package/dist/v8/background.d.ts +13 -0
- package/dist/v8/background.d.ts.map +1 -1
- package/dist/v8/background.js +41 -0
- package/dist/v8/background.js.map +1 -1
- package/dist/v8/blockMeta.d.ts +27 -0
- package/dist/v8/blockMeta.d.ts.map +1 -0
- package/dist/v8/blockMeta.js +75 -0
- package/dist/v8/blockMeta.js.map +1 -0
- package/dist/v8/blockStore.d.ts +43 -0
- package/dist/v8/blockStore.d.ts.map +1 -0
- package/dist/v8/blockStore.js +95 -0
- package/dist/v8/blockStore.js.map +1 -0
- package/dist/v8/boundedJson.d.ts +5 -0
- package/dist/v8/boundedJson.d.ts.map +1 -1
- package/dist/v8/boundedJson.js +10 -2
- package/dist/v8/boundedJson.js.map +1 -1
- package/dist/v8/boundedMap.d.ts +19 -0
- package/dist/v8/boundedMap.d.ts.map +1 -0
- package/dist/v8/boundedMap.js +52 -0
- package/dist/v8/boundedMap.js.map +1 -0
- package/dist/v8/builtins/data.d.ts +18 -2
- package/dist/v8/builtins/data.d.ts.map +1 -1
- package/dist/v8/builtins/data.js +17 -1
- package/dist/v8/builtins/data.js.map +1 -1
- package/dist/v8/builtins/index.d.ts.map +1 -1
- package/dist/v8/builtins/index.js +2 -1
- package/dist/v8/builtins/index.js.map +1 -1
- package/dist/v8/builtins/legacy.d.ts +6 -3
- package/dist/v8/builtins/legacy.d.ts.map +1 -1
- package/dist/v8/builtins/legacy.js +6 -3
- package/dist/v8/builtins/legacy.js.map +1 -1
- package/dist/v8/canonical.d.ts +8 -0
- package/dist/v8/canonical.d.ts.map +1 -1
- package/dist/v8/canonical.js +15 -0
- package/dist/v8/canonical.js.map +1 -1
- package/dist/v8/cli/builtins.d.ts.map +1 -1
- package/dist/v8/cli/builtins.js +1 -0
- package/dist/v8/cli/builtins.js.map +1 -1
- package/dist/v8/cli/check/index.d.ts +10 -0
- package/dist/v8/cli/check/index.d.ts.map +1 -1
- package/dist/v8/cli/check/index.js +91 -7
- package/dist/v8/cli/check/index.js.map +1 -1
- package/dist/v8/cli/content.d.ts +12 -25
- package/dist/v8/cli/content.d.ts.map +1 -1
- package/dist/v8/cli/content.js +46 -75
- package/dist/v8/cli/content.js.map +1 -1
- package/dist/v8/cli/index.d.ts +1 -2
- package/dist/v8/cli/index.d.ts.map +1 -1
- package/dist/v8/cli/index.js +1 -2
- package/dist/v8/cli/index.js.map +1 -1
- package/dist/v8/cli/remote/commands.d.ts +71 -0
- package/dist/v8/cli/remote/commands.d.ts.map +1 -0
- package/dist/v8/cli/remote/commands.js +644 -0
- package/dist/v8/cli/remote/commands.js.map +1 -0
- package/dist/v8/cli/remote/diff.d.ts +15 -0
- package/dist/v8/cli/remote/diff.d.ts.map +1 -0
- package/dist/v8/cli/remote/diff.js +102 -0
- package/dist/v8/cli/remote/diff.js.map +1 -0
- package/dist/v8/cli/remote/env.d.ts +35 -0
- package/dist/v8/cli/remote/env.d.ts.map +1 -0
- package/dist/v8/cli/remote/env.js +84 -0
- package/dist/v8/cli/remote/env.js.map +1 -0
- package/dist/v8/cli/remote/http.d.ts +149 -0
- package/dist/v8/cli/remote/http.d.ts.map +1 -0
- package/dist/v8/cli/remote/http.js +381 -0
- package/dist/v8/cli/remote/http.js.map +1 -0
- package/dist/v8/cli/remote/local.d.ts +90 -0
- package/dist/v8/cli/remote/local.d.ts.map +1 -0
- package/dist/v8/cli/remote/local.js +309 -0
- package/dist/v8/cli/remote/local.js.map +1 -0
- package/dist/v8/cli/root.d.ts +29 -0
- package/dist/v8/cli/root.d.ts.map +1 -1
- package/dist/v8/cli/root.js +28 -0
- package/dist/v8/cli/root.js.map +1 -1
- package/dist/v8/cli/run.d.ts +11 -1
- package/dist/v8/cli/run.d.ts.map +1 -1
- package/dist/v8/cli/run.js +281 -124
- package/dist/v8/cli/run.js.map +1 -1
- package/dist/v8/cli/schema/builtinSchemas.d.ts.map +1 -1
- package/dist/v8/cli/schema/builtinSchemas.js +28 -10
- package/dist/v8/cli/schema/builtinSchemas.js.map +1 -1
- package/dist/v8/cli/schema/generate.js +1 -1
- package/dist/v8/cli/schema/generate.js.map +1 -1
- package/dist/v8/client.d.ts +9 -9
- package/dist/v8/client.d.ts.map +1 -1
- package/dist/v8/client.js +138 -50
- package/dist/v8/client.js.map +1 -1
- package/dist/v8/cms.d.ts +2 -1
- package/dist/v8/cms.d.ts.map +1 -1
- package/dist/v8/cms.js +55 -46
- package/dist/v8/cms.js.map +1 -1
- package/dist/v8/content.d.ts +39 -78
- package/dist/v8/content.d.ts.map +1 -1
- package/dist/v8/content.js +155 -195
- package/dist/v8/content.js.map +1 -1
- package/dist/v8/contentIndex.d.ts +71 -0
- package/dist/v8/contentIndex.d.ts.map +1 -0
- package/dist/v8/contentIndex.js +137 -0
- package/dist/v8/contentIndex.js.map +1 -0
- package/dist/v8/draft.d.ts +7 -7
- package/dist/v8/draft.d.ts.map +1 -1
- package/dist/v8/draft.js +10 -9
- package/dist/v8/draft.js.map +1 -1
- package/dist/v8/draftChanges.d.ts +59 -32
- package/dist/v8/draftChanges.d.ts.map +1 -1
- package/dist/v8/draftChanges.js +139 -75
- package/dist/v8/draftChanges.js.map +1 -1
- package/dist/v8/errors.d.ts +21 -0
- package/dist/v8/errors.d.ts.map +1 -1
- package/dist/v8/errors.js +22 -0
- package/dist/v8/errors.js.map +1 -1
- package/dist/v8/hostedSource.d.ts +57 -0
- package/dist/v8/hostedSource.d.ts.map +1 -0
- package/dist/v8/hostedSource.js +18 -0
- package/dist/v8/hostedSource.js.map +1 -0
- package/dist/v8/identity.d.ts +1 -1
- package/dist/v8/identity.js +1 -1
- package/dist/v8/index.d.ts +1 -0
- package/dist/v8/index.d.ts.map +1 -1
- package/dist/v8/index.js +1 -0
- package/dist/v8/index.js.map +1 -1
- package/dist/v8/matchRoute.js +7 -4
- package/dist/v8/matchRoute.js.map +1 -1
- package/dist/v8/pin.d.ts +34 -0
- package/dist/v8/pin.d.ts.map +1 -0
- package/dist/v8/pin.js +156 -0
- package/dist/v8/pin.js.map +1 -0
- package/dist/v8/preview/StudioBridge.d.ts +8 -8
- package/dist/v8/preview/StudioBridge.d.ts.map +1 -1
- package/dist/v8/preview/StudioBridge.js +8 -10
- package/dist/v8/preview/StudioBridge.js.map +1 -1
- package/dist/v8/preview/StudioChannel.d.ts +51 -0
- package/dist/v8/preview/StudioChannel.d.ts.map +1 -0
- package/dist/v8/preview/StudioChannel.js +104 -0
- package/dist/v8/preview/StudioChannel.js.map +1 -0
- package/dist/v8/preview/index.d.ts +3 -0
- package/dist/v8/preview/index.d.ts.map +1 -1
- package/dist/v8/preview/index.js +3 -0
- package/dist/v8/preview/index.js.map +1 -1
- package/dist/v8/remoteLoader.d.ts +42 -5
- package/dist/v8/remoteLoader.d.ts.map +1 -1
- package/dist/v8/remoteLoader.js +317 -259
- package/dist/v8/remoteLoader.js.map +1 -1
- package/dist/v8/resolver.d.ts +22 -8
- package/dist/v8/resolver.d.ts.map +1 -1
- package/dist/v8/resolver.js +37 -32
- package/dist/v8/resolver.js.map +1 -1
- package/dist/v8/revisionId.d.ts +11 -0
- package/dist/v8/revisionId.d.ts.map +1 -0
- package/dist/v8/revisionId.js +13 -0
- package/dist/v8/revisionId.js.map +1 -0
- package/dist/v8/settings.d.ts +6 -6
- package/dist/v8/settings.d.ts.map +1 -1
- package/dist/v8/settings.js +8 -7
- package/dist/v8/settings.js.map +1 -1
- package/dist/v8/telemetry.d.ts +4 -2
- package/dist/v8/telemetry.d.ts.map +1 -1
- package/dist/v8/telemetry.js +2 -2
- package/dist/v8/telemetry.js.map +1 -1
- package/dist/v8/types.d.ts +52 -40
- package/dist/v8/types.d.ts.map +1 -1
- package/dist/v8/variants.d.ts +7 -2
- package/dist/v8/variants.d.ts.map +1 -1
- package/dist/v8/variants.js +21 -24
- package/dist/v8/variants.js.map +1 -1
- package/dist/v8/vite/index.d.ts +2 -2
- package/dist/v8/vite/index.js +1 -1
- package/dist/v8/vite/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +2 -0
- package/src/protocol/channel.ts +127 -0
- package/src/protocol/client.ts +2 -2
- package/src/protocol/conformance/blockMetaVectors.json +214 -0
- package/src/protocol/conformance/contentHashFixtures.ts +74 -0
- package/src/protocol/conformance/index.ts +9 -1
- package/src/protocol/conformance/vectors.ts +36 -0
- package/src/protocol/index.ts +32 -0
- package/src/protocol/keys.ts +1 -1
- package/src/v8/background.ts +42 -0
- package/src/v8/blockMeta.ts +100 -0
- package/src/v8/blockStore.ts +124 -0
- package/src/v8/boundedJson.ts +20 -2
- package/src/v8/boundedMap.ts +53 -0
- package/src/v8/builtins/data.ts +26 -2
- package/src/v8/builtins/index.ts +2 -1
- package/src/v8/builtins/legacy.ts +6 -3
- package/src/v8/canonical.ts +15 -0
- package/src/v8/cli/builtins.ts +1 -0
- package/src/v8/cli/check/index.ts +97 -7
- package/src/v8/cli/content.ts +49 -91
- package/src/v8/cli/index.ts +1 -2
- package/src/v8/cli/remote/commands.ts +834 -0
- package/src/v8/cli/remote/diff.ts +100 -0
- package/src/v8/cli/remote/env.ts +107 -0
- package/src/v8/cli/remote/http.ts +484 -0
- package/src/v8/cli/remote/local.ts +343 -0
- package/src/v8/cli/root.ts +40 -0
- package/src/v8/cli/run.ts +333 -136
- package/src/v8/cli/schema/builtinSchemas.ts +29 -10
- package/src/v8/cli/schema/generate.ts +1 -1
- package/src/v8/client.ts +162 -60
- package/src/v8/cms.ts +62 -53
- package/src/v8/content.ts +179 -229
- package/src/v8/contentIndex.ts +183 -0
- package/src/v8/draft.ts +15 -14
- package/src/v8/draftChanges.ts +151 -85
- package/src/v8/errors.ts +37 -0
- package/src/v8/hostedSource.ts +67 -0
- package/src/v8/identity.ts +1 -1
- package/src/v8/index.ts +1 -0
- package/src/v8/matchRoute.ts +7 -4
- package/src/v8/pin.ts +176 -0
- package/src/v8/preview/StudioBridge.ts +8 -10
- package/src/v8/preview/StudioChannel.ts +116 -0
- package/src/v8/preview/index.ts +3 -0
- package/src/v8/remoteLoader.ts +350 -286
- package/src/v8/resolver.ts +56 -33
- package/src/v8/revisionId.ts +14 -0
- package/src/v8/settings.ts +10 -9
- package/src/v8/telemetry.ts +3 -3
- package/src/v8/types.ts +52 -40
- package/src/v8/variants.ts +30 -26
- package/src/v8/vite/index.ts +3 -3
- package/dist/v8/cli/serve/server.d.ts +0 -29
- package/dist/v8/cli/serve/server.d.ts.map +0 -1
- package/dist/v8/cli/serve/server.js +0 -296
- package/dist/v8/cli/serve/server.js.map +0 -1
- package/src/v8/cli/serve/server.ts +0 -348
package/dist/v8/types.d.ts
CHANGED
|
@@ -17,36 +17,22 @@ export type Block = {
|
|
|
17
17
|
export type BlockFunction = (inputs: any) => unknown | Promise<unknown>;
|
|
18
18
|
/** A block map: what `.deco/index.ts` exports and the CLI reads. */
|
|
19
19
|
export type Blocks = Record<string, BlockFunction>;
|
|
20
|
-
/** One fixed copy of the content: what
|
|
20
|
+
/** One fixed copy of the content: what a content module exports and `load()` returns. */
|
|
21
21
|
export type Snapshot = {
|
|
22
22
|
revision: string;
|
|
23
23
|
/** The content map: entry name → saved JSON. */
|
|
24
24
|
blocks: Record<string, unknown>;
|
|
25
|
-
/**
|
|
25
|
+
/** An alias table: old type name → your type. */
|
|
26
26
|
aliases?: Record<string, string>;
|
|
27
27
|
/**
|
|
28
|
-
* The
|
|
29
|
-
*
|
|
30
|
-
* `
|
|
31
|
-
*/
|
|
32
|
-
schemaHash?: string;
|
|
33
|
-
/**
|
|
34
|
-
* The commit time of the git HEAD `deco content` built this content from
|
|
35
|
-
* (committer date, ISO 8601). A hosted release is swapped in only when its
|
|
36
|
-
* `publishedAt` is later; without one (a custom loader, an older content
|
|
37
|
-
* module, a build outside git), the bundled content counts as the oldest.
|
|
38
|
-
*/
|
|
39
|
-
committedAt?: string;
|
|
40
|
-
/**
|
|
41
|
-
* The hosts this release may be previewed on (host patterns), as Studio
|
|
42
|
-
* wrote them into the release metadata on delivery.decocms.com
|
|
43
|
-
* (`latest.json` and `revisions/<sha>.json`). Previews are checked against
|
|
44
|
-
* the current release's list; the bundled content has none.
|
|
28
|
+
* The hosts this content may be previewed on (host patterns), for content
|
|
29
|
+
* with no remote site. A hosted release's list is Studio's, in
|
|
30
|
+
* `latest.json` on delivery.decocms.com, and the CMS reads it from there.
|
|
45
31
|
*/
|
|
46
32
|
previewHosts?: string[];
|
|
47
33
|
};
|
|
48
34
|
/**
|
|
49
|
-
* The content module `
|
|
35
|
+
* The content module the CLI's `content()` writes: a snapshot plus `root`, the
|
|
50
36
|
* `.deco` folder it was generated from, which `createCMS` keys its instance
|
|
51
37
|
* on (see /next/api-reference#one-instance-per-process). Not exported.
|
|
52
38
|
*/
|
|
@@ -69,7 +55,7 @@ export interface DraftPointer {
|
|
|
69
55
|
host: string;
|
|
70
56
|
/** Starts with `/`; opaque to the app. Never carries the `__variant` parameters. */
|
|
71
57
|
path: string;
|
|
72
|
-
/** Opaque: identifies the editor's last save. `"local"` names no draft (
|
|
58
|
+
/** Opaque: identifies the editor's last save. `"local"` names no draft (the release itself). */
|
|
73
59
|
version: string;
|
|
74
60
|
/** The variants this preview forces (the query's `__variant` parameters); absent when none. */
|
|
75
61
|
variants?: ForcedVariant[];
|
|
@@ -114,7 +100,7 @@ export interface Redirect {
|
|
|
114
100
|
*/
|
|
115
101
|
from: string;
|
|
116
102
|
to: string;
|
|
117
|
-
/** `true` for a 301, `false` for a
|
|
103
|
+
/** `true` for a 301, `false` (a temporary redirect) for a 307. */
|
|
118
104
|
permanent: boolean;
|
|
119
105
|
/** Wins over `permanent`. */
|
|
120
106
|
status?: RedirectStatus;
|
|
@@ -241,17 +227,14 @@ export interface TelemetryConfig {
|
|
|
241
227
|
export interface CMSConfig {
|
|
242
228
|
/** Your block functions; the CMS uses `{ ...builtIns, ...blocks }`. */
|
|
243
229
|
blocks: Blocks;
|
|
244
|
-
/** The content module (`.deco/blocks.gen.ts`), or any {@link Loader}. */
|
|
245
|
-
content: ContentModule | Loader;
|
|
246
|
-
/** ms between `update()` checks of a content source that has one; minimum 60 000. */
|
|
247
|
-
interval?: number;
|
|
248
230
|
/**
|
|
249
|
-
*
|
|
250
|
-
*
|
|
251
|
-
*
|
|
252
|
-
* to override that, e.g. `dev: import.meta.env.DEV` or `dev: false`.
|
|
231
|
+
* The content without `site`: a snapshot, or any {@link Loader}. With
|
|
232
|
+
* `site`, leave it out: content comes from the delivery CDN at runtime,
|
|
233
|
+
* never from the bundle (passing both is an error).
|
|
253
234
|
*/
|
|
254
|
-
|
|
235
|
+
content?: ContentModule | Loader;
|
|
236
|
+
/** ms between `update()` checks of a content source that has one; minimum 60 000. */
|
|
237
|
+
interval?: number;
|
|
255
238
|
/** Where telemetry goes; see /next/telemetry. */
|
|
256
239
|
telemetry?: false | TelemetryConfig;
|
|
257
240
|
preview?: {
|
|
@@ -272,8 +255,11 @@ export interface CMSConfig {
|
|
|
272
255
|
draftHosts?: string[];
|
|
273
256
|
};
|
|
274
257
|
/**
|
|
275
|
-
* Your site ID (Studio's site slug):
|
|
276
|
-
* `delivery.decocms.com
|
|
258
|
+
* Your site ID (Studio's site slug): the content is the site's latest
|
|
259
|
+
* release on `delivery.decocms.com`, fetched at runtime (the first client
|
|
260
|
+
* loads it, with 10 s per fetch; until a load succeeds, clients answer
|
|
261
|
+
* `LOADER_FAILED` with a `ContentUnavailableError` cause) and followed
|
|
262
|
+
* every `interval`. Drafts don't need it.
|
|
277
263
|
*/
|
|
278
264
|
site?: string;
|
|
279
265
|
/**
|
|
@@ -304,7 +290,33 @@ export interface ListOptions<T> {
|
|
|
304
290
|
*/
|
|
305
291
|
export interface Client {
|
|
306
292
|
resolve<T = unknown>(target: unknown, options?: ResolveOptions): Promise<Result<T>>;
|
|
293
|
+
/**
|
|
294
|
+
* Every saved block of a type, read whole. For tools and type lists; routing
|
|
295
|
+
* reads `routes()` and `redirects()`, which need no body (a `page` or
|
|
296
|
+
* `redirect` list warns outside production).
|
|
297
|
+
*/
|
|
307
298
|
list<T = Block>(type: string, options?: ListOptions<T>): Promise<Result<T[]>>;
|
|
299
|
+
/**
|
|
300
|
+
* `{ name, path }` of every page (a saved block whose type is `page`, or an
|
|
301
|
+
* alias of it, with a `path`), from the index alone, in code-unit order of
|
|
302
|
+
* name so the same page wins a path conflict everywhere. The same array for
|
|
303
|
+
* the same revision, so `matchRoute` builds its trie once per revision.
|
|
304
|
+
* `name` is the saved block's name: `resolve(name)` reads the page.
|
|
305
|
+
*/
|
|
306
|
+
routes(): Promise<Result<Route[]>>;
|
|
307
|
+
/**
|
|
308
|
+
* The rules of the site's redirects block (the saved block of type
|
|
309
|
+
* `redirects`; the first in code-unit order of name when there are
|
|
310
|
+
* several), `[]` when there is none.
|
|
311
|
+
*/
|
|
312
|
+
redirects(): Promise<Result<Redirect[]>>;
|
|
313
|
+
/**
|
|
314
|
+
* Starts fetching the saved block `name` and everything it references,
|
|
315
|
+
* with the redirects block, in one parallel wave, so `redirects()` and
|
|
316
|
+
* `resolve(name)` find them in memory. Never throws; a block that can't be
|
|
317
|
+
* fetched fails where it is read.
|
|
318
|
+
*/
|
|
319
|
+
prefetch(name: string): void;
|
|
308
320
|
/**
|
|
309
321
|
* The revision this client reads (loads it on first use). Unlike `resolve`
|
|
310
322
|
* and `list`, it rejects with the `LOADER_FAILED` error when the content
|
|
@@ -314,8 +326,8 @@ export interface Client {
|
|
|
314
326
|
/** Who is visiting, as passed to `cms.client()` (a frozen copy); `null` for none. */
|
|
315
327
|
readonly visitor: Visitor | null;
|
|
316
328
|
/**
|
|
317
|
-
* The version it reads: the release's
|
|
318
|
-
* passed to `cms.client()`. For the current release, the
|
|
329
|
+
* The version it reads: the release's revision id, or the draft pointer, as
|
|
330
|
+
* passed to `cms.client()`. For the current release, the id of the release
|
|
319
331
|
* it loaded (`undefined` until its first `resolve`, `list` or `revision()`).
|
|
320
332
|
*/
|
|
321
333
|
readonly version: string | undefined;
|
|
@@ -332,7 +344,7 @@ export interface Client {
|
|
|
332
344
|
export interface ClientOptions {
|
|
333
345
|
/**
|
|
334
346
|
* What to read: `undefined` (or `null`) for the current release; a
|
|
335
|
-
* published release's
|
|
347
|
+
* published release's revision id (`<inv>-<uuidv7>`), read from hosted
|
|
336
348
|
* releases; or a draft pointer, the draft's changes over the current
|
|
337
349
|
* release. Only a version: a Studio link's moment and switched tests are
|
|
338
350
|
* the options below (`cms.readVersion(request)` reads all of them).
|
|
@@ -343,7 +355,7 @@ export interface ClientOptions {
|
|
|
343
355
|
* (`cms.checkRelease()`), so the draft waits for it instead of making a
|
|
344
356
|
* check of its own; one request, one read of the release metadata. An id
|
|
345
357
|
* this CMS didn't make (another process's) is a check of its own. Ignored
|
|
346
|
-
* for the release and a release's
|
|
358
|
+
* for the release and a release's revision id.
|
|
347
359
|
*/
|
|
348
360
|
releaseCheck?: string | null;
|
|
349
361
|
/**
|
|
@@ -376,7 +388,7 @@ export interface ClientOptions {
|
|
|
376
388
|
* in the shape of `ClientOptions`, so it spreads into `cms.client()`.
|
|
377
389
|
*/
|
|
378
390
|
export interface RequestVersion {
|
|
379
|
-
/** A draft pointer, or a published release's
|
|
391
|
+
/** A draft pointer, or a published release's revision id. */
|
|
380
392
|
version: string;
|
|
381
393
|
/** The moment the preview shows (`__at`). */
|
|
382
394
|
date?: Date;
|
|
@@ -435,7 +447,7 @@ export interface CMS {
|
|
|
435
447
|
settings(): Promise<EffectiveSettings>;
|
|
436
448
|
/**
|
|
437
449
|
* What a Studio link asks for: `?__draft=` first, then the `__deco_draft`
|
|
438
|
-
* cookie, holding a draft pointer or a published release's
|
|
450
|
+
* cookie, holding a draft pointer or a published release's revision id,
|
|
439
451
|
* with the preview's moment (`__at`) and switched tests (`__test`) and
|
|
440
452
|
* campaigns (`__campaign`) as `date`, `experiments` and `campaigns`.
|
|
441
453
|
* `null` when neither is present, for `?__draft=off`, on a host outside
|
|
@@ -445,7 +457,7 @@ export interface CMS {
|
|
|
445
457
|
* `preview.hosts`; no host while the metadata can't be read, besides
|
|
446
458
|
* `preview.hosts`), and for a value that doesn't parse (ignored,
|
|
447
459
|
* as if absent): in each case the request gets the current release. A
|
|
448
|
-
* draft and an older release's
|
|
460
|
+
* draft and an older release's id are both checked against the current
|
|
449
461
|
* release's list.
|
|
450
462
|
*
|
|
451
463
|
* ```ts
|
package/dist/v8/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/v8/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,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W,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;CAC3D"}
|
package/dist/v8/variants.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
import type { ForcedVariant
|
|
2
|
-
|
|
1
|
+
import type { ForcedVariant } from "./types.ts";
|
|
2
|
+
/**
|
|
3
|
+
* One saved block's body with the variants forced on it (those whose `block`
|
|
4
|
+
* is `name`), copied along the addressed paths only; the body itself when none
|
|
5
|
+
* applies. How a request applies forced variants to bodies it reads lazily.
|
|
6
|
+
*/
|
|
7
|
+
export declare function forceBody(name: string, body: unknown, variants: readonly ForcedVariant[], aliases: Readonly<Record<string, string>> | undefined): unknown;
|
|
3
8
|
//# sourceMappingURL=variants.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"variants.d.ts","sourceRoot":"","sources":["../../src/v8/variants.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,aAAa,EAAE,
|
|
1
|
+
{"version":3,"file":"variants.d.ts","sourceRoot":"","sources":["../../src/v8/variants.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD;;;;GAIG;AACH,wBAAgB,SAAS,CACvB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,OAAO,EACb,QAAQ,EAAE,SAAS,aAAa,EAAE,EAClC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GAAG,SAAS,GACpD,OAAO,CAOT"}
|
package/dist/v8/variants.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Forced variants (see /next/releases-and-drafts#preview-a-variant): the
|
|
3
|
-
* variants a draft pointer's `__variant` parameters name, applied to
|
|
4
|
-
*
|
|
5
|
-
* variant, with the rule `true`, so it shows that variant's
|
|
6
|
-
* rule runs.
|
|
7
|
-
* one is never touched.
|
|
3
|
+
* variants a draft pointer's `__variant` parameters name, applied to each body
|
|
4
|
+
* a preview request reads (see ./pin.ts). Each addressed multivariate keeps
|
|
5
|
+
* only the forced variant, with the rule `true`, so it shows that variant's
|
|
6
|
+
* value and no other rule runs. A body is copied along the addressed paths
|
|
7
|
+
* only; the shared one is never touched.
|
|
8
8
|
*
|
|
9
9
|
* An address that doesn't reach a multivariate block with that variant (a
|
|
10
10
|
* renamed block, a moved section, an index past the end) is ignored, so a
|
|
@@ -12,32 +12,29 @@
|
|
|
12
12
|
*/
|
|
13
13
|
import { LEGACY_ALIASES } from "./builtins/legacy.js";
|
|
14
14
|
import { isPlainObject, own } from "./json.js";
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
/**
|
|
16
|
+
* One saved block's body with the variants forced on it (those whose `block`
|
|
17
|
+
* is `name`), copied along the addressed paths only; the body itself when none
|
|
18
|
+
* applies. How a request applies forced variants to bodies it reads lazily.
|
|
19
|
+
*/
|
|
20
|
+
export function forceBody(name, body, variants, aliases) {
|
|
21
|
+
let out = body;
|
|
19
22
|
for (const { block, path, index } of variants) {
|
|
20
|
-
|
|
21
|
-
if (entry === undefined)
|
|
22
|
-
continue;
|
|
23
|
-
const keys = path === "" ? [] : path.split(".");
|
|
24
|
-
const next = forceAt(entry, keys, index, snapshot);
|
|
25
|
-
if (next === entry)
|
|
23
|
+
if (block !== name)
|
|
26
24
|
continue;
|
|
27
|
-
|
|
28
|
-
blocks[block] = next;
|
|
25
|
+
out = forceAt(out, path === "" ? [] : path.split("."), index, aliases);
|
|
29
26
|
}
|
|
30
|
-
return
|
|
27
|
+
return out;
|
|
31
28
|
}
|
|
32
|
-
function forceAt(node, keys, index,
|
|
29
|
+
function forceAt(node, keys, index, aliases) {
|
|
33
30
|
if (keys.length === 0)
|
|
34
|
-
return forceNode(node, index,
|
|
31
|
+
return forceNode(node, index, aliases);
|
|
35
32
|
const [key, ...rest] = keys;
|
|
36
33
|
if (Array.isArray(node)) {
|
|
37
34
|
const i = Number(key);
|
|
38
35
|
if (!Number.isInteger(i) || String(i) !== key || i < 0 || i >= node.length)
|
|
39
36
|
return node;
|
|
40
|
-
const child = forceAt(node[i], rest, index,
|
|
37
|
+
const child = forceAt(node[i], rest, index, aliases);
|
|
41
38
|
if (child === node[i])
|
|
42
39
|
return node;
|
|
43
40
|
const copy = node.slice();
|
|
@@ -46,15 +43,15 @@ function forceAt(node, keys, index, snapshot) {
|
|
|
46
43
|
}
|
|
47
44
|
if (!isPlainObject(node) || !Object.hasOwn(node, key))
|
|
48
45
|
return node;
|
|
49
|
-
const child = forceAt(node[key], rest, index,
|
|
46
|
+
const child = forceAt(node[key], rest, index, aliases);
|
|
50
47
|
return child === node[key] ? node : { ...node, [key]: child };
|
|
51
48
|
}
|
|
52
49
|
/** A multivariate block (by its own name or an alias) with only `variants[index]`, ruled `true`. */
|
|
53
|
-
function forceNode(node, index,
|
|
50
|
+
function forceNode(node, index, aliases) {
|
|
54
51
|
if (!isPlainObject(node) || typeof node.__resolveType !== "string")
|
|
55
52
|
return node;
|
|
56
53
|
const type = node.__resolveType;
|
|
57
|
-
const canonical = own(
|
|
54
|
+
const canonical = own(aliases, type) ?? own(LEGACY_ALIASES, type) ?? type;
|
|
58
55
|
if (canonical !== "multivariate" || !Array.isArray(node.variants))
|
|
59
56
|
return node;
|
|
60
57
|
const variant = node.variants[index];
|
package/dist/v8/variants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"variants.js","sourceRoot":"","sources":["../../src/v8/variants.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAG/C,MAAM,UAAU,
|
|
1
|
+
{"version":3,"file":"variants.js","sourceRoot":"","sources":["../../src/v8/variants.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO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AE,QAAQ,EAAE,CAAC,EAAE,GAAG,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC;AAC7D,CAAC"}
|
package/dist/v8/vite/index.d.ts
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
* block in open pages during `vite dev`. Vite sites add it to
|
|
4
4
|
* `vite.config.ts`; Next.js sites don't use it.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
6
|
+
* Whatever rewrites `.deco/blocks.gen.ts` (content without a site: the
|
|
7
|
+
* CLI's `content()`) triggers it. In `vite dev`, in the server
|
|
8
8
|
* environments, the plugin makes each module that imports it (usually
|
|
9
9
|
* `src/cms.ts`) accept that import's updates: the new content goes into the
|
|
10
10
|
* CMS already created for its `.deco` folder (`adoptContent`), and only then
|
package/dist/v8/vite/index.js
CHANGED
|
@@ -4,7 +4,7 @@ export const CONTENT_UPDATED_EVENT = "decocms:content-updated";
|
|
|
4
4
|
const RELOAD_DELAY_MS = 100;
|
|
5
5
|
/** The module the footer imports `adoptContent` from. */
|
|
6
6
|
const HOT_MODULE = "@decocms/blocks/vite/hot";
|
|
7
|
-
/** The content module `
|
|
7
|
+
/** The content module (the CLI's `content()` writes it), wherever the `.deco` folder is. */
|
|
8
8
|
const CONTENT_MODULE = /(?:^|[\\/])\.deco[\\/]blocks\.gen\.ts$/;
|
|
9
9
|
/** Source files whose imports the plugin reads. */
|
|
10
10
|
const SOURCE_FILE = /\.(?:[cm]?[jt]sx?)$/;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/v8/vite/index.ts"],"names":[],"mappings":"AA2BA,oHAAoH;AACpH,MAAM,CAAC,MAAM,qBAAqB,GAAG,yBAAyB,CAAC;AAE/D,iGAAiG;AACjG,MAAM,eAAe,GAAG,GAAG,CAAC;AAE5B,yDAAyD;AACzD,MAAM,UAAU,GAAG,0BAA0B,CAAC;AAE9C,
|
|
1
|
+
{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AI,CAAC;YACvC,qFAAqF;YACrF,KAAK,MAAM,SAAS,IAAI,kBAAkB,CAAC,IAAI,CAAC,EAAE,CAAC;gBACjD,IAAI,MAAM,SAAS,CAAC,SAAS,CAAC;oBAAE,OAAO,IAAI,CAAC;YAC9C,CAAC;YACD,sEAAsE;YACtE,OAAO,EAAE,IAAI,EAAE,IAAI,GAAG,cAAc,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC;QAC7D,CAAC;QACD,eAAe,CAAC,MAAM;YACpB,uEAAuE;YACvE,qEAAqE;YACrE,IAAI,KAAgD,CAAC;YACrD,MAAM,MAAM,GAAG,GAAG,EAAE;gBAClB,YAAY,CAAC,KAAK,CAAC,CAAC;gBACpB,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE;oBACtB,MAAM,MAAM,GAAG,MAAM,CAAC,YAAY,EAAE,MAAM,EAAE,GAAG,IAAI,MAAM,CAAC,GAAG,CAAC;oBAC9D,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE,CAAC,CAAC;gBACvC,CAAC,EAAE,eAAe,CAAC,CAAC;YACtB,CAAC,CAAC;YACF,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,YAAY,IAAI,EAAE,CAAC,CAAC,MAAM,CAClE,CAAC,WAAW,EAAE,EAAE,CAAC,WAAW,CAAC,MAAM,CAAC,QAAQ,KAAK,QAAQ,CAC1D,CAAC;YACF,KAAK,MAAM,WAAW,IAAI,YAAY,EAAE,CAAC;gBACvC,WAAW,CAAC,GAAG,CAAC,EAAE,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAC;YACpD,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Studio channel: how code that belongs to Deco Studio's site editor
|
|
3
|
+
* runs inside the site's page when Studio frames it. Browser-safe, no
|
|
4
|
+
* dependencies; types plus a few constants, shared by the page's bootstrap
|
|
5
|
+
* (`StudioChannel` in `@decocms/blocks/preview`, which every binding mounts on
|
|
6
|
+
* every page) and Studio, which hosts the modules.
|
|
7
|
+
*
|
|
8
|
+
* The page trusts a list of Studio origins (the binding's: Studio's production
|
|
9
|
+
* and staging origins by default, {@link DEFAULT_STUDIO_ORIGINS}), each
|
|
10
|
+
* compared exactly, no wildcard. It is the only way Studio runs code in the
|
|
11
|
+
* page: no message makes the page evaluate a script.
|
|
12
|
+
*
|
|
13
|
+
* 1. A framed page (`window.parent !== window`) posts `{ type: "deco:ready" }`
|
|
14
|
+
* to its parent once per trusted origin, each as the `targetOrigin` (the
|
|
15
|
+
* browser delivers it only if the parent is at that origin, so a parent of
|
|
16
|
+
* any other origin never receives it). Where the browser names the parent's
|
|
17
|
+
* origin (`location.ancestorOrigins`), the page posts to that origin alone,
|
|
18
|
+
* and only when it is trusted.
|
|
19
|
+
* 2. Studio answers `{ type: "deco:load", url }`: an absolute URL of an ES
|
|
20
|
+
* module on Studio's own origin (versioned, served with CORS).
|
|
21
|
+
* 3. The page accepts the message only when `event.origin` is one of the
|
|
22
|
+
* trusted origins, the sender is the parent window, and the module URL's
|
|
23
|
+
* origin is the origin of that message; then it `import()`s the URL, once
|
|
24
|
+
* per URL, and calls the module's default export with a
|
|
25
|
+
* {@link StudioChannelContext} bound to that origin. It answers
|
|
26
|
+
* `{ type: "deco:loaded", url }`, or `{ type: "deco:load-error", url,
|
|
27
|
+
* message }` (a failed URL may be sent again), to that origin.
|
|
28
|
+
* 4. Every later message from that origin whose `type` doesn't start with
|
|
29
|
+
* `deco:` (reserved for the channel) is handed to the listeners of each
|
|
30
|
+
* module it loaded; a module talks back with `send`, to that origin only.
|
|
31
|
+
*
|
|
32
|
+
* Not framed, framed by another origin, or a message that fails a check: the
|
|
33
|
+
* bootstrap does nothing. The binding adds the same origins to the page's
|
|
34
|
+
* Content Security Policy (`script-src`, for the modules, and
|
|
35
|
+
* `frame-ancestors`); the bootstrap's inline script takes the site's `nonce`.
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
/** Studio's production origin. */
|
|
39
|
+
export const DEFAULT_STUDIO_ORIGIN = "https://studio.decocms.com";
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* The origins a page trusts unless the binding option or `DECO_STUDIO_ORIGIN`
|
|
43
|
+
* (comma-separated) says otherwise: Studio's production and staging origins.
|
|
44
|
+
*/
|
|
45
|
+
export const DEFAULT_STUDIO_ORIGINS: readonly string[] = Object.freeze([
|
|
46
|
+
DEFAULT_STUDIO_ORIGIN,
|
|
47
|
+
"https://studio-stg.decocms.com",
|
|
48
|
+
]);
|
|
49
|
+
|
|
50
|
+
/** The channel's own message types; a module's message types never start with `deco:`. */
|
|
51
|
+
export const CHANNEL_MESSAGE = Object.freeze({
|
|
52
|
+
ready: "deco:ready",
|
|
53
|
+
load: "deco:load",
|
|
54
|
+
loaded: "deco:loaded",
|
|
55
|
+
loadError: "deco:load-error",
|
|
56
|
+
} as const);
|
|
57
|
+
|
|
58
|
+
/** Page → Studio: the framed page's bootstrap is listening. */
|
|
59
|
+
export interface ChannelReadyMessage {
|
|
60
|
+
type: "deco:ready";
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Studio → page: import this module (an absolute URL on Studio's origin). */
|
|
64
|
+
export interface ChannelLoadMessage {
|
|
65
|
+
type: "deco:load";
|
|
66
|
+
url: string;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Page → Studio: the module at `url` was imported and its default export ran. */
|
|
70
|
+
export interface ChannelLoadedMessage {
|
|
71
|
+
type: "deco:loaded";
|
|
72
|
+
url: string;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Page → Studio: the module at `url` failed to import or to start. */
|
|
76
|
+
export interface ChannelLoadErrorMessage {
|
|
77
|
+
type: "deco:load-error";
|
|
78
|
+
url: string;
|
|
79
|
+
message: string;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** What the page's bootstrap posts to Studio. */
|
|
83
|
+
export type PageChannelMessage =
|
|
84
|
+
| ChannelReadyMessage
|
|
85
|
+
| ChannelLoadedMessage
|
|
86
|
+
| ChannelLoadErrorMessage;
|
|
87
|
+
|
|
88
|
+
/** What the page's bootstrap acts on itself; any other message goes to the modules. */
|
|
89
|
+
export type StudioChannelMessage = ChannelLoadMessage;
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* A message between Studio and one of its modules: any structured-cloneable
|
|
93
|
+
* object with a `type` that doesn't start with `deco:` (by convention the
|
|
94
|
+
* module's name, `wireframe:hover`).
|
|
95
|
+
*/
|
|
96
|
+
export interface ModuleMessage {
|
|
97
|
+
type: string;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** What a module's default export is called with. */
|
|
101
|
+
export interface StudioChannelContext<
|
|
102
|
+
In extends ModuleMessage = ModuleMessage,
|
|
103
|
+
Out extends ModuleMessage = ModuleMessage,
|
|
104
|
+
> {
|
|
105
|
+
/** The Studio origin this module was loaded from (the `deco:load` message's, checked exactly). */
|
|
106
|
+
readonly studioOrigin: string;
|
|
107
|
+
/** The URL this module was loaded from. */
|
|
108
|
+
readonly url: string;
|
|
109
|
+
/** Posts a message to Studio (addressed to `studioOrigin` only). */
|
|
110
|
+
send(message: Out): void;
|
|
111
|
+
/** Listens to Studio's module messages from `studioOrigin`; returns the unsubscribe. */
|
|
112
|
+
on(listener: (message: In) => void): () => void;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** A module's default export. The page answers `deco:loaded` once it returns (or its promise resolves). */
|
|
116
|
+
export type StudioChannelModule<
|
|
117
|
+
In extends ModuleMessage = ModuleMessage,
|
|
118
|
+
Out extends ModuleMessage = ModuleMessage,
|
|
119
|
+
> = (context: StudioChannelContext<In, Out>) => void | Promise<void>;
|
|
120
|
+
|
|
121
|
+
/** Types a module's default export: `export default defineStudioModule<In, Out>((channel) => …)`. */
|
|
122
|
+
export function defineStudioModule<
|
|
123
|
+
In extends ModuleMessage = ModuleMessage,
|
|
124
|
+
Out extends ModuleMessage = ModuleMessage,
|
|
125
|
+
>(module: StudioChannelModule<In, Out>): StudioChannelModule<In, Out> {
|
|
126
|
+
return module;
|
|
127
|
+
}
|
package/src/protocol/client.ts
CHANGED
|
@@ -93,8 +93,8 @@ const REQUIRED_VERSION = { major: PROTOCOL_VERSION.major, minor: REQUIRED_PROTOC
|
|
|
93
93
|
/** The guidance for a server older than this client: update it. */
|
|
94
94
|
const OUTDATED_MESSAGE =
|
|
95
95
|
`the endpoint speaks an older ${PROTOCOL_NAME} than this client needs ` +
|
|
96
|
-
`(${REQUIRED_VERSION.major}.${REQUIRED_VERSION.minor} or newer): update @decocms/blocks
|
|
97
|
-
"(8.2.0 or newer)
|
|
96
|
+
`(${REQUIRED_VERSION.major}.${REQUIRED_VERSION.minor} or newer): update @decocms/blocks ` +
|
|
97
|
+
"(8.2.0 or newer) where the endpoint runs";
|
|
98
98
|
|
|
99
99
|
function unsupportedEndpoint(
|
|
100
100
|
message: string,
|