@decocms/blocks 8.6.0 → 8.8.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.
Files changed (168) hide show
  1. package/dist/index.d.ts +1 -1
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +1 -1
  4. package/dist/index.js.map +1 -1
  5. package/dist/protocol/conformance/cases/changes.d.ts.map +1 -1
  6. package/dist/protocol/conformance/cases/changes.js +14 -3
  7. package/dist/protocol/conformance/cases/changes.js.map +1 -1
  8. package/dist/protocol/conformance/cases/guards.d.ts.map +1 -1
  9. package/dist/protocol/conformance/cases/guards.js +19 -42
  10. package/dist/protocol/conformance/cases/guards.js.map +1 -1
  11. package/dist/protocol/conformance/cases/overlay.d.ts +3 -0
  12. package/dist/protocol/conformance/cases/overlay.d.ts.map +1 -0
  13. package/dist/protocol/conformance/cases/overlay.js +164 -0
  14. package/dist/protocol/conformance/cases/overlay.js.map +1 -0
  15. package/dist/protocol/conformance/cases/reads.js +5 -5
  16. package/dist/protocol/conformance/cases/reads.js.map +1 -1
  17. package/dist/protocol/conformance/cases/writes.d.ts.map +1 -1
  18. package/dist/protocol/conformance/cases/writes.js +15 -3
  19. package/dist/protocol/conformance/cases/writes.js.map +1 -1
  20. package/dist/protocol/conformance/context.d.ts +0 -10
  21. package/dist/protocol/conformance/context.d.ts.map +1 -1
  22. package/dist/protocol/conformance/context.js.map +1 -1
  23. package/dist/protocol/conformance/index.d.ts.map +1 -1
  24. package/dist/protocol/conformance/index.js +2 -0
  25. package/dist/protocol/conformance/index.js.map +1 -1
  26. package/dist/protocol/server/content.d.ts +8 -1
  27. package/dist/protocol/server/content.d.ts.map +1 -1
  28. package/dist/protocol/server/content.js +18 -3
  29. package/dist/protocol/server/content.js.map +1 -1
  30. package/dist/protocol/server/core.d.ts +0 -6
  31. package/dist/protocol/server/core.d.ts.map +1 -1
  32. package/dist/protocol/server/core.js +0 -2
  33. package/dist/protocol/server/core.js.map +1 -1
  34. package/dist/protocol/server/methods/apply.d.ts +16 -5
  35. package/dist/protocol/server/methods/apply.d.ts.map +1 -1
  36. package/dist/protocol/server/methods/apply.js +42 -38
  37. package/dist/protocol/server/methods/apply.js.map +1 -1
  38. package/dist/protocol/server/methods/changes.d.ts.map +1 -1
  39. package/dist/protocol/server/methods/changes.js +31 -3
  40. package/dist/protocol/server/methods/changes.js.map +1 -1
  41. package/dist/protocol/server/methods/read.d.ts.map +1 -1
  42. package/dist/protocol/server/methods/read.js +2 -23
  43. package/dist/protocol/server/methods/read.js.map +1 -1
  44. package/dist/protocol/storage/fs/index.d.ts.map +1 -1
  45. package/dist/protocol/storage/fs/index.js +0 -18
  46. package/dist/protocol/storage/fs/index.js.map +1 -1
  47. package/dist/protocol/storage/memory.d.ts +11 -3
  48. package/dist/protocol/storage/memory.d.ts.map +1 -1
  49. package/dist/protocol/storage/memory.js +114 -45
  50. package/dist/protocol/storage/memory.js.map +1 -1
  51. package/dist/protocol/storage.d.ts +68 -18
  52. package/dist/protocol/storage.d.ts.map +1 -1
  53. package/dist/protocol/storage.js +7 -0
  54. package/dist/protocol/storage.js.map +1 -1
  55. package/dist/protocol/types.d.ts +51 -8
  56. package/dist/protocol/types.d.ts.map +1 -1
  57. package/dist/protocol/types.js +5 -3
  58. package/dist/protocol/types.js.map +1 -1
  59. package/dist/v8/builtins/index.d.ts +1 -4
  60. package/dist/v8/builtins/index.d.ts.map +1 -1
  61. package/dist/v8/builtins/index.js +1 -6
  62. package/dist/v8/builtins/index.js.map +1 -1
  63. package/dist/v8/builtins/legacy.d.ts +4 -4
  64. package/dist/v8/builtins/legacy.d.ts.map +1 -1
  65. package/dist/v8/builtins/legacy.js +4 -5
  66. package/dist/v8/builtins/legacy.js.map +1 -1
  67. package/dist/v8/cli/builtins.d.ts.map +1 -1
  68. package/dist/v8/cli/builtins.js +0 -1
  69. package/dist/v8/cli/builtins.js.map +1 -1
  70. package/dist/v8/cli/check/index.d.ts +1 -1
  71. package/dist/v8/cli/check/index.d.ts.map +1 -1
  72. package/dist/v8/cli/check/index.js +13 -33
  73. package/dist/v8/cli/check/index.js.map +1 -1
  74. package/dist/v8/cli/schema/builtinSchemas.d.ts.map +1 -1
  75. package/dist/v8/cli/schema/builtinSchemas.js +0 -8
  76. package/dist/v8/cli/schema/builtinSchemas.js.map +1 -1
  77. package/dist/v8/cli/schema/generate.d.ts.map +1 -1
  78. package/dist/v8/cli/schema/generate.js +1 -8
  79. package/dist/v8/cli/schema/generate.js.map +1 -1
  80. package/dist/v8/cli/schema/typeToSchema.d.ts +0 -1
  81. package/dist/v8/cli/schema/typeToSchema.d.ts.map +1 -1
  82. package/dist/v8/cli/schema/typeToSchema.js +5 -30
  83. package/dist/v8/cli/schema/typeToSchema.js.map +1 -1
  84. package/dist/v8/client.d.ts +1 -1
  85. package/dist/v8/client.d.ts.map +1 -1
  86. package/dist/v8/cms.d.ts.map +1 -1
  87. package/dist/v8/cms.js +31 -21
  88. package/dist/v8/cms.js.map +1 -1
  89. package/dist/v8/content.d.ts +35 -1
  90. package/dist/v8/content.d.ts.map +1 -1
  91. package/dist/v8/content.js +81 -2
  92. package/dist/v8/content.js.map +1 -1
  93. package/dist/v8/index.d.ts +1 -1
  94. package/dist/v8/index.d.ts.map +1 -1
  95. package/dist/v8/preview/DraftBadge.d.ts +9 -1
  96. package/dist/v8/preview/DraftBadge.d.ts.map +1 -1
  97. package/dist/v8/preview/DraftBadge.js +42 -2
  98. package/dist/v8/preview/DraftBadge.js.map +1 -1
  99. package/dist/v8/remoteLoader.d.ts.map +1 -1
  100. package/dist/v8/remoteLoader.js +3 -1
  101. package/dist/v8/remoteLoader.js.map +1 -1
  102. package/dist/v8/resolver.d.ts +1 -1
  103. package/dist/v8/resolver.d.ts.map +1 -1
  104. package/dist/v8/telemetry.d.ts +0 -2
  105. package/dist/v8/telemetry.d.ts.map +1 -1
  106. package/dist/v8/telemetry.js +5 -20
  107. package/dist/v8/telemetry.js.map +1 -1
  108. package/dist/v8/types.d.ts +37 -10
  109. package/dist/v8/types.d.ts.map +1 -1
  110. package/package.json +1 -6
  111. package/src/index.ts +1 -2
  112. package/src/protocol/conformance/cases/changes.ts +16 -4
  113. package/src/protocol/conformance/cases/guards.ts +19 -55
  114. package/src/protocol/conformance/cases/overlay.ts +195 -0
  115. package/src/protocol/conformance/cases/reads.ts +4 -4
  116. package/src/protocol/conformance/cases/writes.ts +15 -3
  117. package/src/protocol/conformance/context.ts +0 -7
  118. package/src/protocol/conformance/index.ts +2 -0
  119. package/src/protocol/server/content.ts +30 -4
  120. package/src/protocol/server/core.ts +0 -3
  121. package/src/protocol/server/methods/apply.ts +43 -38
  122. package/src/protocol/server/methods/changes.ts +42 -4
  123. package/src/protocol/server/methods/read.ts +2 -24
  124. package/src/protocol/storage/fs/index.ts +0 -18
  125. package/src/protocol/storage/memory.ts +124 -46
  126. package/src/protocol/storage.ts +69 -18
  127. package/src/protocol/types.ts +51 -8
  128. package/src/v8/builtins/index.ts +1 -6
  129. package/src/v8/builtins/legacy.ts +4 -5
  130. package/src/v8/cli/builtins.ts +0 -1
  131. package/src/v8/cli/check/index.ts +15 -34
  132. package/src/v8/cli/schema/builtinSchemas.ts +0 -8
  133. package/src/v8/cli/schema/generate.ts +1 -8
  134. package/src/v8/cli/schema/typeToSchema.ts +5 -31
  135. package/src/v8/client.ts +1 -1
  136. package/src/v8/cms.ts +37 -22
  137. package/src/v8/content.ts +82 -2
  138. package/src/v8/index.ts +0 -1
  139. package/src/v8/preview/DraftBadge.tsx +72 -2
  140. package/src/v8/remoteLoader.ts +3 -1
  141. package/src/v8/resolver.ts +1 -1
  142. package/src/v8/telemetry.ts +5 -20
  143. package/src/v8/types.ts +36 -7
  144. package/dist/protocol/ciphertext.d.ts +0 -7
  145. package/dist/protocol/ciphertext.d.ts.map +0 -1
  146. package/dist/protocol/ciphertext.js +0 -7
  147. package/dist/protocol/ciphertext.js.map +0 -1
  148. package/dist/protocol/secrets.d.ts +0 -22
  149. package/dist/protocol/secrets.d.ts.map +0 -1
  150. package/dist/protocol/secrets.js +0 -207
  151. package/dist/protocol/secrets.js.map +0 -1
  152. package/dist/v8/builtins/secret.d.ts +0 -7
  153. package/dist/v8/builtins/secret.d.ts.map +0 -1
  154. package/dist/v8/builtins/secret.js +0 -68
  155. package/dist/v8/builtins/secret.js.map +0 -1
  156. package/dist/v8/ciphertext.d.ts +0 -58
  157. package/dist/v8/ciphertext.d.ts.map +0 -1
  158. package/dist/v8/ciphertext.js +0 -134
  159. package/dist/v8/ciphertext.js.map +0 -1
  160. package/dist/v8/secrets.d.ts +0 -9
  161. package/dist/v8/secrets.d.ts.map +0 -1
  162. package/dist/v8/secrets.js +0 -14
  163. package/dist/v8/secrets.js.map +0 -1
  164. package/src/protocol/ciphertext.ts +0 -6
  165. package/src/protocol/secrets.ts +0 -239
  166. package/src/v8/builtins/secret.ts +0 -82
  167. package/src/v8/ciphertext.ts +0 -158
  168. package/src/v8/secrets.ts +0 -17
@@ -8,10 +8,12 @@ export const PROTOCOL_NAME = "deco-content";
8
8
 
9
9
  /**
10
10
  * Minors only add. A client refuses another major, and a server older than
11
- * `REQUIRED_PROTOCOL_MINOR` (1.1 added `changes.*`; 1.0 is `@decocms/blocks`
12
- * 8.1.x and older).
11
+ * `REQUIRED_PROTOCOL_MINOR`. 1.0 is `@decocms/blocks` 8.1.x and older; 1.1
12
+ * added `changes.*`; 1.2 added overlay endpoints (`describe.overlay`), and
13
+ * `blocks.apply` no longer reads the schema (`describe.secrets` is always
14
+ * `null`: secrets live in the deploy platform, not in content).
13
15
  */
14
- export const PROTOCOL_VERSION = { major: 1, minor: 1 } as const;
16
+ export const PROTOCOL_VERSION = { major: 1, minor: 2 } as const;
15
17
 
16
18
  /**
17
19
  * The oldest minor this package's client talks to. Bump it only when the
@@ -62,8 +64,24 @@ export interface DescribeResult {
62
64
  preview: null | { url: string };
63
65
  /** Dir relative to the repository root; `null` when read-only or uploads go to hosted storage. */
64
66
  assets: null | { dir: string; urlPrefix: typeof ASSETS_URL_PREFIX; maxBytes: number };
65
- /** The contents of `<root>/.deco/secrets.pub`; `null` without one. */
67
+ /**
68
+ * Always `null` from protocol 1.2 on: content holds no secrets (they live
69
+ * in the deploy platform, and the site's code passes them as params). A
70
+ * 1.0 or 1.1 server reported `<root>/.deco/secrets.pub` here.
71
+ */
66
72
  secrets: null | { publicKey: string };
73
+ /**
74
+ * `true` when the endpoint writes to an overlay over its base, such as a
75
+ * hosted draft over the published branch (protocol 1.2). Then
76
+ * `blocks.apply`'s `ifMatch` compares with the overlay alone: an entry the
77
+ * overlay doesn't hold is `null`, whatever the base has, and an entry it
78
+ * holds has the `version` `changes.list` reports for it. A deletion the
79
+ * overlay records is held too: `changes.list` reports it as a `delete`
80
+ * with its tombstone version, which `ifMatch` must name (`null` fails).
81
+ * `changes.list` lists every entry the overlay holds, even one equal to the
82
+ * base. Absent: `ifMatch` compares with the content `blocks.list` reports.
83
+ */
84
+ overlay?: true;
67
85
  }
68
86
 
69
87
  /** The schema file, in the site editor's `deco-meta@1` format. */
@@ -125,12 +143,24 @@ export interface BlocksApplyParams {
125
143
  set?: Record<string, Record<string, unknown>>;
126
144
  /** A missing name counts as deleted. */
127
145
  delete?: string[];
128
- /** A version the entry must have; `null` = must not exist. */
146
+ /**
147
+ * A version the entry must have; `null` = must not exist. On an overlay
148
+ * endpoint (`describe.overlay`), the version it has in the overlay (for a
149
+ * deletion the overlay records, its tombstone version); `null` = the
150
+ * overlay doesn't hold it.
151
+ */
129
152
  ifMatch?: Record<string, string | null>;
130
153
  }
131
154
 
132
155
  export interface BlocksApplyResult {
133
156
  revision: string;
157
+ /**
158
+ * Every name written or deleted, with its version now: `null` for a
159
+ * deleted name, except on an overlay endpoint, where a deletion the
160
+ * overlay records reports its tombstone version (what the next `ifMatch`
161
+ * on it must name). An overlay may record one even for a name the base
162
+ * lacks; a client treats it like any tombstone.
163
+ */
134
164
  versions: Record<string, string | null>;
135
165
  }
136
166
 
@@ -148,9 +178,18 @@ export interface ChangesBase {
148
178
 
149
179
  /** One entry that differs from the base. */
150
180
  export interface Change {
151
- /** `set`: the entry exists and differs from the base, or is new. `delete`: it's in the base and gone now. */
181
+ /**
182
+ * `set`: the entry exists and differs from the base, or is new. `delete`:
183
+ * it's in the base and gone now; on an overlay endpoint, also a tombstone
184
+ * the overlay holds for a name the base lacks (`baseVersion: null`).
185
+ */
152
186
  kind: "set" | "delete";
153
- /** The entry's current version, as `blocks.list` reports it (usable in `ifMatch`); `null` for a `delete`. */
187
+ /**
188
+ * The entry's current version, as `blocks.list` reports it (usable in
189
+ * `ifMatch`). For a `delete`, `null`, except on an overlay endpoint
190
+ * (`describe.overlay`), where it's the deletion's tombstone version: the
191
+ * overlay holds the deletion, so a save of the entry must name it.
192
+ */
154
193
  version: string | null;
155
194
  /**
156
195
  * The entry's version in the base; `null` when the base doesn't have it (a
@@ -207,7 +246,11 @@ export interface ChangesGetResult {
207
246
  export interface ChangesDiscardParams {
208
247
  /** Entries to drop back to the base. A name without a change is a no-op. */
209
248
  names: string[];
210
- /** A version the entry must have now; `null` = must not exist. As in `blocks.apply`. */
249
+ /**
250
+ * The version the entry must have now, as `changes.list` reports it; `null`
251
+ * = must not exist. On an overlay endpoint, a deletion the overlay holds
252
+ * has its tombstone version, and `null` on it fails.
253
+ */
211
254
  ifMatch?: Record<string, string | null>;
212
255
  }
213
256
 
@@ -5,12 +5,8 @@ import { experiment, SPLIT_TRAFFIC_TYPE, splitTraffic } from "./experiments.ts";
5
5
  import { lazy } from "./lazy.ts";
6
6
  import { always, never } from "./matchers.ts";
7
7
  import { multivariate } from "./multivariate.ts";
8
- import { secretBlock } from "./secret.ts";
9
8
 
10
- /**
11
- * The built-in blocks every block map gets. `secret` here has no key, so it
12
- * always fails; each CMS replaces it with one holding its `secrets.key`.
13
- */
9
+ /** The built-in blocks every block map gets. */
14
10
  export const builtIns: Readonly<Record<string, BlockFunction>> = Object.freeze({
15
11
  lazy,
16
12
  multivariate,
@@ -21,7 +17,6 @@ export const builtIns: Readonly<Record<string, BlockFunction>> = Object.freeze({
21
17
  page,
22
18
  redirect,
23
19
  [SETTINGS_TYPE]: cmsSettings,
24
- secret: secretBlock(),
25
20
  [SPLIT_TRAFFIC_TYPE]: splitTraffic,
26
21
  [CALENDAR_TYPE]: calendar,
27
22
  });
@@ -9,10 +9,10 @@
9
9
  *
10
10
  * - Redirects keep v7's nested shape: `redirect` returns its arguments as
11
11
  * saved, and `matchRoute` accepts both shapes.
12
- * - `website/loaders/secret.ts` resolves as `secret`, which needs the
13
- * `ciphertext` the one-time re-encryption writes (see
14
- * /next/renames-and-migrations#secrets); a v7 `encrypted` value fails that
15
- * block with `BLOCK_FAILED`.
12
+ * - `website/loaders/secret.ts` has no alias: secrets live in the deploy
13
+ * platform, read by the site's code and passed as params (see
14
+ * /next/renames-and-migrations#secrets), so a leftover v7 secret block
15
+ * fails with `UNKNOWN_BLOCK` and `deco check` points it out.
16
16
  * - Legacy variants are saved as plain values; on the way to `multivariate`
17
17
  * each one is wrapped in a `lazy` block, so only the chosen one runs.
18
18
  */
@@ -36,7 +36,6 @@ export const LEGACY_ALIASES: Readonly<Record<string, string>> = Object.freeze({
36
36
  "website/matchers/always.ts": "always",
37
37
  "website/matchers/never.ts": "never",
38
38
  "website/loaders/redirect.ts": "redirect",
39
- "website/loaders/secret.ts": "secret",
40
39
  });
41
40
 
42
41
  /**
@@ -28,7 +28,6 @@ export const BUILT_IN_USES: Readonly<Record<string, string>> = Object.freeze({
28
28
  page: "Studio's page list and page editor rely on it",
29
29
  redirect: "Studio's redirect list relies on it",
30
30
  "cms-settings": "the saved block CMS relies on it, and Studio's settings edit that block",
31
- secret: "Studio's secret fields rely on it to keep their values encrypted",
32
31
  "split-traffic":
33
32
  "the saved block experiments relies on it, and Studio's Experiments view edits its percentages",
34
33
  calendar: "the saved block campaigns relies on it, and Studio's Campaigns view edits its dates",
@@ -10,7 +10,7 @@
10
10
  * - the walk resolves each name (block type, built-in, alias or saved block),
11
11
  * checks that the block fits the field it sits in (by the field's list of
12
12
  * functions whose return type fits it), and handles the structural blocks
13
- * (`multivariate`, `lazy`, `secret`) and references;
13
+ * (`multivariate`, `lazy`) and references;
14
14
  * - Ajv checks one block's props at a time. Its schema is the generated one
15
15
  * with every field also accepting any block, so nested blocks never show up
16
16
  * as union noise in the parent: the walk checks them on their own, against
@@ -19,7 +19,6 @@
19
19
 
20
20
  import fs from "node:fs";
21
21
  import { Ajv, type ValidateFunction } from "ajv";
22
- import { isWellFormedCiphertext } from "../../../protocol/secrets.ts";
23
22
  import { BLOCKS_MAJOR } from "../../../protocol/types.ts";
24
23
  import {
25
24
  CALENDAR_TYPE,
@@ -72,23 +71,23 @@ function isLazyShape(schema: Json): boolean {
72
71
  return !!e && e.length === 1 && e[0] === "lazy" && !!schema.properties.value;
73
72
  }
74
73
 
75
- /** A `secret` block's shape inline in a field: the field is `Secret`. */
76
- function isSecretShape(schema: Json): boolean {
77
- const e = resolveTypeEnum(schema);
78
- return !!e && e.length === 1 && e[0] === "secret" && schema.format === "secret";
79
- }
80
-
81
74
  /** The definition key of a block type, if `schema` is a block type's definition. */
82
75
  function blockDefinitionName(schema: Json): string | null {
83
76
  const e = resolveTypeEnum(schema);
84
77
  return e && e.length === 1 && typeof schema.title === "string" && !schema.format ? e[0] : null;
85
78
  }
86
79
 
80
+ /** Where a secret goes instead of a block. */
81
+ const SECRETS_MOVED =
82
+ "secrets live in your deploy platform's secrets, not in content: read the value in your site's code and pass it as a param, then delete this block; see /next/built-in-blocks#secrets";
83
+
87
84
  /** Prerelease built-ins folded into the CMS settings block, or renamed, with no alias. */
88
85
  const FOLDED_BUILT_INS: Record<string, string> = {
89
86
  telemetry: `the built-in is now the telemetry section of the "${SETTINGS_BLOCK}" block (type "${SETTINGS_TYPE}"); see /next/renames-and-migrations#site-settings`,
90
87
  analytics: `the built-in is now the analytics section of the "${SETTINGS_BLOCK}" block (type "${SETTINGS_TYPE}"); see /next/renames-and-migrations#site-settings`,
91
88
  "date-windows": `the built-in is now "${CALENDAR_TYPE}": set the saved block "${CAMPAIGNS_BLOCK}" to { "__resolveType": "${CALENDAR_TYPE}", … }`,
89
+ secret: SECRETS_MOVED,
90
+ "website/loaders/secret.ts": SECRETS_MOVED,
92
91
  };
93
92
 
94
93
  /** A `CMS` block saved with preview hosts, which Studio keeps now (in the release it publishes). */
@@ -160,12 +159,12 @@ class ValidationDocument {
160
159
 
161
160
  private transform(node: Json, wrap: boolean, top = false): Json {
162
161
  if (!isObject(node)) return node;
163
- // Fields that hold a structural block (Lazy<T>, Secret), as a field or a
164
- // list item, are entirely the walk's job: it reports a plain value there
165
- // and checks a block on its own. Ajv accepts anything in them.
166
- if (!top && (isLazyShape(node) || isSecretShape(node))) {
162
+ // Fields that hold a structural block (Lazy<T>), as a field or a list
163
+ // item, are entirely the walk's job: it reports a plain value there and
164
+ // checks a block on its own. Ajv accepts anything in them.
165
+ if (!top && isLazyShape(node)) {
167
166
  // Still register the lazy value's form: the walk validates it.
168
- if (isLazyShape(node)) this.transform(node.properties.value, true);
167
+ this.transform(node.properties.value, true);
169
168
  return {};
170
169
  }
171
170
  const copy: Record<string, Json> = {};
@@ -315,8 +314,6 @@ function formatsFor(doc: Json): Record<string, true | ((value: string) => boolea
315
314
  return formats;
316
315
  }
317
316
 
318
- const CIPHERTEXT_PROBLEM = "not a well-formed ciphertext (v1.<wrappedKey>.<iv>.<ciphertext>)";
319
-
320
317
  // ---------------------------------------------------------------------------
321
318
  // The checker
322
319
  // ---------------------------------------------------------------------------
@@ -562,9 +559,6 @@ class Checker {
562
559
  return isLazyShape(resolved) ? null : "a lazy block only fits a Lazy<T> field";
563
560
  }
564
561
  if (isLazyShape(resolved)) return "this field is Lazy<T>: wrap the value in a lazy block";
565
- if (isSecretShape(resolved)) {
566
- return type === "secret" ? null : "this field is a Secret: it takes a secret block";
567
- }
568
562
  const allowed = this.allowedTypes(field);
569
563
  if (allowed.has(type)) return null;
570
564
  if (allowed.size === 0) return "this field takes a plain value";
@@ -589,9 +583,9 @@ class Checker {
589
583
 
590
584
  /**
591
585
  * A plain value in a field that only takes a structural block: `Lazy<T>`
592
- * needs a `lazy` block and `Secret` a `secret` block, in a list item or a
593
- * union member as much as in a field of its own. Reports it and returns
594
- * true when the field is one of those (nothing else to check then).
586
+ * needs a `lazy` block, in a list item or a union member as much as in a
587
+ * field of its own. Reports it and returns true when the field is one
588
+ * (nothing else to check then).
595
589
  */
596
590
  private structuralProblem(ctx: Context, value: Json, path: string, field: Json): boolean {
597
591
  const resolved = this.deref(field);
@@ -601,12 +595,6 @@ class Checker {
601
595
  }
602
596
  return true;
603
597
  }
604
- if (isSecretShape(resolved)) {
605
- if (value !== undefined && value !== null) {
606
- this.report(ctx, path, "plain text in a Secret field: save it as a secret block");
607
- }
608
- return true;
609
- }
610
598
  return false;
611
599
  }
612
600
 
@@ -727,13 +715,6 @@ class Checker {
727
715
  if ("value" in block) this.checkValue(ctx, block.value, joinPath(path, "/value"), inner);
728
716
  return;
729
717
  }
730
- case "secret": {
731
- this.checkProps(ctx, block, path, false);
732
- if ("ciphertext" in block && !isWellFormedCiphertext(block.ciphertext)) {
733
- this.report(ctx, joinPath(path, "/ciphertext"), CIPHERTEXT_PROBLEM);
734
- }
735
- return;
736
- }
737
718
  case EXPERIMENT_RULE: {
738
719
  this.checkProps(ctx, block, path, true);
739
720
  const name = this.ruleInputs(block, EXPERIMENT_RULE)?.name;
@@ -17,7 +17,6 @@ export const BUILT_IN_GROUPS: Record<string, ManifestGroup> = {
17
17
  page: "pages",
18
18
  redirect: "redirects",
19
19
  "cms-settings": "content",
20
- secret: "loaders",
21
20
  "split-traffic": "content",
22
21
  calendar: "content",
23
22
  };
@@ -60,7 +59,6 @@ const BUILT_IN_DOCS: Record<string, { title: string; description: string; icon?:
60
59
  "Campaigns: each name with its start and end; resolves to whether each is running now. The type of the saved block campaigns",
61
60
  icon: "calendar-event",
62
61
  },
63
- secret: { title: "Secret", description: "An encrypted value, decrypted on the server" },
64
62
  };
65
63
 
66
64
  /** The form of each test in a `split-traffic` block: a whole percentage. */
@@ -266,12 +264,6 @@ function builtInProps(name: string, ctx: BuiltInContext): any {
266
264
  },
267
265
  },
268
266
  };
269
- case "secret":
270
- return {
271
- type: "object",
272
- required: ["ciphertext"],
273
- properties: { ciphertext: { type: "string", title: "Ciphertext", writeOnly: true } },
274
- };
275
267
  }
276
268
  }
277
269
 
@@ -284,14 +284,7 @@ export async function generateSchema(paths: DecoPaths): Promise<SchemaResult> {
284
284
  // -------------------------------------------------------------------------
285
285
  // 2. Fields → blocks: which functions' return types fit an object field.
286
286
  // -------------------------------------------------------------------------
287
- const STRUCTURAL = new Set<string>([
288
- "lazy",
289
- "multivariate",
290
- "secret",
291
- "always",
292
- "never",
293
- "campaign",
294
- ]);
287
+ const STRUCTURAL = new Set<string>(["lazy", "multivariate", "always", "never", "campaign"]);
295
288
  const candidates: Pick<BlockInfo, "key" | "returnType">[] = infos.filter(
296
289
  (info) =>
297
290
  info.group !== "sections" &&
@@ -13,7 +13,6 @@
13
13
  * return type fits it, decided by TypeScript assignability, not by type
14
14
  * name (spec: schema › Interchangeable blocks).
15
15
  * - `Lazy<T>` is a `lazy` block whose `value` has the form of `T`.
16
- * - `Secret` holds a `secret` block, never a plain string.
17
16
  * - `@options` with a literal list becomes an `enum`; a function-backed list
18
17
  * falls back to a text field, since the site editor never runs site code.
19
18
  *
@@ -212,6 +211,8 @@ const WIDGET_TYPE_FORMATS: Record<string, string> = {
212
211
  TextArea: "textarea",
213
212
  Code: "code",
214
213
  DateTimeWidget: "date-time",
214
+ // v7's masked text box. A plain string in content: keep real secrets in the deploy platform.
215
+ Secret: "password",
215
216
  };
216
217
 
217
218
  /** Apply the format of a widget alias named in `typeHint` to the right inner schema. */
@@ -326,16 +327,6 @@ function lazyInner(type: Type, typeHint = ""): Type | null {
326
327
  return inner;
327
328
  }
328
329
 
329
- /** `Secret`, from `@decocms/blocks` (`string & { readonly __secret: true }`). */
330
- function isSecretType(type: Type, typeHint = ""): boolean {
331
- if (type.getAliasSymbol()?.getName() === "Secret") return true;
332
- if (/^(\w+\.)?Secret$/.test(typeHint.trim())) return true;
333
- return (
334
- type.isIntersection() &&
335
- type.getIntersectionTypes().some((t) => t.getProperty("__secret") !== undefined)
336
- );
337
- }
338
-
339
330
  /**
340
331
  * The awaited type: `Promise<T>` is `T`. With `strict`, anything that isn't a
341
332
  * promise returns null (used to recognize `() => Promise<T>`).
@@ -426,7 +417,7 @@ export function titleCase(name: string): string {
426
417
  .replace(/^./, (c) => c.toUpperCase());
427
418
  }
428
419
 
429
- /** `Secret | undefined` → `Secret`: the annotation without its nullish members. */
420
+ /** `Lazy<T> | undefined` → `Lazy<T>`: the annotation without its nullish members. */
430
421
  function stripNullish(typeHint: string): string {
431
422
  return typeHint.replace(/\s*\|\s*(null|undefined)\b/g, "").trim();
432
423
  }
@@ -447,20 +438,6 @@ export function lazySchema(value: any): any {
447
438
  };
448
439
  }
449
440
 
450
- /** The schema of a `secret` block: a write-only field saved encrypted. */
451
- function secretSchema(): any {
452
- return {
453
- type: "object",
454
- format: "secret",
455
- writeOnly: true,
456
- required: ["__resolveType", "ciphertext"],
457
- properties: {
458
- __resolveType: { type: "string", enum: ["secret"], default: "secret" },
459
- ciphertext: { type: "string" },
460
- },
461
- };
462
- }
463
-
464
441
  /**
465
442
  * The schema of one field: everything a type means at a property position,
466
443
  * before the property's own JSDoc and title are applied.
@@ -474,8 +451,6 @@ function fieldSchema(
474
451
  const lazy = lazyInner(nonNullable(propType), stripNullish(typeHint));
475
452
  if (lazy) return lazySchema(fieldSchema(lazy, lazy.getText(), ctx, visited));
476
453
 
477
- if (isSecretType(nonNullable(propType), stripNullish(typeHint))) return secretSchema();
478
-
479
454
  if (ctx && isObjectLike(propType) && !isSectionType(nonNullable(propType))) {
480
455
  const fits = ctx.fitting(propType);
481
456
  if (fits.length > 0) {
@@ -598,8 +573,7 @@ export function typeToJsonSchema(
598
573
  if (type.isAny() || type.isUnknown()) return {};
599
574
 
600
575
  // Structural blocks wherever the type appears, not only as a whole field:
601
- // `Secret[]` is a list of secret blocks, `Lazy<T>[]` a list of lazy ones.
602
- if (isSecretType(type)) return secretSchema();
576
+ // `Lazy<T>[]` is a list of lazy blocks.
603
577
  const lazy = lazyInner(type);
604
578
  if (lazy) return lazySchema(fieldSchema(lazy, lazy.getText(), ctx, visited));
605
579
 
@@ -742,7 +716,7 @@ export function typeToJsonSchema(
742
716
  const tags = getJsDocTags(prop);
743
717
  if (tags.ignore) continue;
744
718
 
745
- // The annotation as written (`ImageWidget`, `Section[]`, `Secret`),
719
+ // The annotation as written (`ImageWidget`, `Section[]`, `Lazy<T>`),
746
720
  // before the checker resolves aliases away.
747
721
  const typeNode = decl.getTypeNode();
748
722
  const typeHint: string = typeNode ? typeNode.getText() : propType.getText();
package/src/v8/client.ts CHANGED
@@ -25,7 +25,7 @@ interface ClientOptions {
25
25
  /** Loads this client's snapshot; called at most once. */
26
26
  load: () => Promise<Snapshot>;
27
27
  blocks: Blocks;
28
- /** The built-ins, with this CMS's `secret`. */
28
+ /** The built-in blocks. */
29
29
  builtIns: Readonly<Blocks>;
30
30
  /** Who is visiting (copied and frozen); `null` for none. */
31
31
  visitor?: Visitor | null;
package/src/v8/cms.ts CHANGED
@@ -9,7 +9,6 @@
9
9
  import { runInBackground } from "./background.ts";
10
10
  import { SETTINGS_BLOCK, SETTINGS_TYPE } from "./builtins/data.ts";
11
11
  import { builtIns } from "./builtins/index.ts";
12
- import { secretBlock } from "./builtins/secret.ts";
13
12
  import { CMSClient } from "./client.ts";
14
13
  import { ContentStore, isLoader, isSnapshot } from "./content.ts";
15
14
  import type { Overrides } from "./current.ts";
@@ -43,6 +42,7 @@ import type {
43
42
  CMSConfig,
44
43
  EffectiveSettings,
45
44
  Loader,
45
+ ReleaseCheckOptions,
46
46
  RequestLike,
47
47
  RequestVersion,
48
48
  Snapshot,
@@ -61,13 +61,12 @@ interface Fingerprint {
61
61
  interval: number;
62
62
  telemetry: string;
63
63
  preview: string;
64
- secrets: string;
65
64
  token: string;
66
65
  }
67
66
 
68
67
  /**
69
68
  * The state one content root shares across `createCMS` calls: the content
70
- * store, caps, telemetry and secret key. Each call gets its own handle
69
+ * store, caps and telemetry. Each call gets its own handle
71
70
  * holding its own block map (see `CMSHandle`).
72
71
  */
73
72
  class CMSInstance {
@@ -76,8 +75,6 @@ class CMSInstance {
76
75
  readonly #store: ContentStore;
77
76
  readonly #interval: number;
78
77
  readonly #warned = new Set<string>();
79
- /** The built-ins with a `secret` that holds this instance's key (the first call's). */
80
- readonly #builtIns: Readonly<Blocks>;
81
78
  readonly #telemetry: TelemetryPipeline | undefined;
82
79
  readonly #caps: SettingsCaps;
83
80
  /** Settings of a `CMS` block with nothing to run, per release snapshot. */
@@ -106,10 +103,6 @@ class CMSInstance {
106
103
  this.#telemetry = new TelemetryPipeline(destination);
107
104
  setCurrentTelemetry(this.#telemetry);
108
105
  }
109
- // Decrypted values never leave in telemetry: the pipeline redacts each one.
110
- const telemetry = this.#telemetry;
111
- const secret = secretBlock(config.secrets?.key, (value) => telemetry?.redact(value));
112
- this.#builtIns = Object.freeze({ ...builtIns, secret });
113
106
  }
114
107
 
115
108
  /**
@@ -132,12 +125,14 @@ class CMSInstance {
132
125
  if (version === undefined) return this.#client(blocks, this.#release(blocks), inputs);
133
126
  const parsed = parseClientVersion(version);
134
127
  // A version that doesn't parse fails on the first read, as an invalid pointer always has.
135
- if (parsed === null) return this.#client(blocks, () => this.#store.draft(version), inputs);
128
+ const check = options.releaseCheck;
129
+ if (parsed === null)
130
+ return this.#client(blocks, () => this.#store.draft(version, check), inputs);
136
131
  if (parsed.kind === "revision") {
137
132
  return this.#client(blocks, () => this.#store.revision(parsed.sha), inputs);
138
133
  }
139
134
  const { variants } = parsed.pointer;
140
- const load = () => this.#store.draft(version);
135
+ const load = () => this.#store.draft(version, check);
141
136
  if (variants === undefined) return this.#client(blocks, load, inputs);
142
137
  return this.#client(blocks, () => load().then((s) => forceVariants(s, variants)), inputs);
143
138
  }
@@ -167,12 +162,25 @@ class CMSInstance {
167
162
  return deepFreeze({ ...saved, preview: { hosts: previewHosts(hosts, this.#codeHosts) } });
168
163
  }
169
164
 
170
- async readVersion(request: RequestLike): Promise<RequestVersion | null> {
165
+ async readVersion(
166
+ request: RequestLike,
167
+ options: ReleaseCheckOptions = {},
168
+ ): Promise<RequestVersion | null> {
171
169
  const version = readVersion(request);
172
170
  if (version === null) return null;
171
+ // The request's release check first: it reads `latest.json`, the preview hosts with it.
172
+ if (typeof options.releaseCheck === "string") {
173
+ await this.#store.waitForCheck(options.releaseCheck);
174
+ }
173
175
  return (await this.#previewAllowed(request)) ? version : null;
174
176
  }
175
177
 
178
+ /** A release check for one draft request (see `ContentStore.checkRelease`); it counts as the background's too. */
179
+ checkRelease(releaseCheck?: string | null): Promise<string> {
180
+ if (this.#store.updatable) this.#nextCheck = this.#due();
181
+ return this.#store.checkRelease(releaseCheck);
182
+ }
183
+
176
184
  async draftCookie(request: RequestLike): Promise<string | null> {
177
185
  const cookie = draftCookieFor(request);
178
186
  if (cookie === null) return null;
@@ -217,7 +225,7 @@ class CMSInstance {
217
225
  new CMSClient({
218
226
  load: () => Promise.resolve(snapshot),
219
227
  blocks,
220
- builtIns: this.#builtIns,
228
+ builtIns,
221
229
  date: Date.now(),
222
230
  onCollision: (name) => this.#warnCollision(name),
223
231
  }),
@@ -282,7 +290,7 @@ class CMSInstance {
282
290
  return new CMSClient({
283
291
  load,
284
292
  blocks,
285
- builtIns: this.#builtIns,
293
+ builtIns,
286
294
  ...inputs,
287
295
  onCollision: (name) => this.#warnCollision(name),
288
296
  telemetry: this.#telemetry?.forClient(),
@@ -291,7 +299,8 @@ class CMSInstance {
291
299
 
292
300
  /**
293
301
  * Checks a content source with `update()` on first use and then every
294
- * `interval` (± up to 10 s), at an idle moment, never in front of a request.
302
+ * `interval` (± up to 10 s), at an idle moment, never in front of a release
303
+ * request (a draft read waits for a check of its own: `ContentStore.draft`).
295
304
  */
296
305
  #scheduleUpdate(): void {
297
306
  if (!this.#store.updatable) return;
@@ -319,8 +328,8 @@ const INSTANCE = Symbol.for("decocms.blocks.cms.instance");
319
328
 
320
329
  /**
321
330
  * What `createCMS` returns: the shared instance plus the block map of this
322
- * call. Every handle on one content root shares its content, caps, telemetry
323
- * and secret key; each resolves with the block map it was created with.
331
+ * call. Every handle on one content root shares its content, caps and
332
+ * telemetry; each resolves with the block map it was created with.
324
333
  */
325
334
  class CMSHandle implements CMS {
326
335
  readonly #instance: CMSInstance;
@@ -344,8 +353,15 @@ class CMSHandle implements CMS {
344
353
  return this.#instance.client(this.#blocks);
345
354
  }
346
355
 
347
- forDraft(pointer: string): Client {
348
- return this.#instance.client(this.#blocks, { version: pointer });
356
+ forDraft(pointer: string, options: ReleaseCheckOptions = {}): Client {
357
+ return this.#instance.client(this.#blocks, {
358
+ version: pointer,
359
+ releaseCheck: options.releaseCheck ?? null,
360
+ });
361
+ }
362
+
363
+ checkRelease(releaseCheck?: string | null): Promise<string> {
364
+ return this.#instance.checkRelease(releaseCheck);
349
365
  }
350
366
 
351
367
  update(): Promise<{ updated: boolean }> {
@@ -356,8 +372,8 @@ class CMSHandle implements CMS {
356
372
  return this.#instance.settings(this.#blocks);
357
373
  }
358
374
 
359
- readVersion(request: RequestLike): Promise<RequestVersion | null> {
360
- return this.#instance.readVersion(request);
375
+ readVersion(request: RequestLike, options?: ReleaseCheckOptions): Promise<RequestVersion | null> {
376
+ return this.#instance.readVersion(request, options);
361
377
  }
362
378
 
363
379
  async draftPointer(request: RequestLike): Promise<string | null> {
@@ -528,7 +544,6 @@ function fingerprintOf(config: CMSConfig, interval: number): Fingerprint {
528
544
  interval,
529
545
  telemetry: stableJson(config.telemetry ?? null),
530
546
  preview: stableJson(config.preview ?? null),
531
- secrets: config.secrets?.key ? fnv1a(config.secrets.key) : "",
532
547
  token: config.token ? fnv1a(config.token) : "",
533
548
  };
534
549
  }