@decocms/blocks 8.7.0 → 8.9.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 (164) 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/analytics.d.ts +6 -2
  60. package/dist/v8/analytics.d.ts.map +1 -1
  61. package/dist/v8/analytics.js +24 -5
  62. package/dist/v8/analytics.js.map +1 -1
  63. package/dist/v8/builtins/data.d.ts +4 -0
  64. package/dist/v8/builtins/data.d.ts.map +1 -1
  65. package/dist/v8/builtins/data.js +6 -0
  66. package/dist/v8/builtins/data.js.map +1 -1
  67. package/dist/v8/builtins/index.d.ts +1 -4
  68. package/dist/v8/builtins/index.d.ts.map +1 -1
  69. package/dist/v8/builtins/index.js +1 -6
  70. package/dist/v8/builtins/index.js.map +1 -1
  71. package/dist/v8/builtins/legacy.d.ts +4 -4
  72. package/dist/v8/builtins/legacy.d.ts.map +1 -1
  73. package/dist/v8/builtins/legacy.js +4 -5
  74. package/dist/v8/builtins/legacy.js.map +1 -1
  75. package/dist/v8/cli/builtins.d.ts.map +1 -1
  76. package/dist/v8/cli/builtins.js +0 -1
  77. package/dist/v8/cli/builtins.js.map +1 -1
  78. package/dist/v8/cli/check/index.d.ts +1 -1
  79. package/dist/v8/cli/check/index.d.ts.map +1 -1
  80. package/dist/v8/cli/check/index.js +13 -33
  81. package/dist/v8/cli/check/index.js.map +1 -1
  82. package/dist/v8/cli/schema/builtinSchemas.d.ts.map +1 -1
  83. package/dist/v8/cli/schema/builtinSchemas.js +6 -8
  84. package/dist/v8/cli/schema/builtinSchemas.js.map +1 -1
  85. package/dist/v8/cli/schema/generate.d.ts.map +1 -1
  86. package/dist/v8/cli/schema/generate.js +1 -8
  87. package/dist/v8/cli/schema/generate.js.map +1 -1
  88. package/dist/v8/cli/schema/typeToSchema.d.ts +0 -1
  89. package/dist/v8/cli/schema/typeToSchema.d.ts.map +1 -1
  90. package/dist/v8/cli/schema/typeToSchema.js +5 -30
  91. package/dist/v8/cli/schema/typeToSchema.js.map +1 -1
  92. package/dist/v8/client.d.ts +1 -1
  93. package/dist/v8/client.d.ts.map +1 -1
  94. package/dist/v8/cms.d.ts.map +1 -1
  95. package/dist/v8/cms.js +5 -13
  96. package/dist/v8/cms.js.map +1 -1
  97. package/dist/v8/index.d.ts +1 -1
  98. package/dist/v8/index.d.ts.map +1 -1
  99. package/dist/v8/resolver.d.ts +1 -1
  100. package/dist/v8/resolver.d.ts.map +1 -1
  101. package/dist/v8/telemetry.d.ts +0 -2
  102. package/dist/v8/telemetry.d.ts.map +1 -1
  103. package/dist/v8/telemetry.js +5 -20
  104. package/dist/v8/telemetry.js.map +1 -1
  105. package/dist/v8/types.d.ts +4 -8
  106. package/dist/v8/types.d.ts.map +1 -1
  107. package/package.json +1 -6
  108. package/src/index.ts +1 -2
  109. package/src/protocol/conformance/cases/changes.ts +16 -4
  110. package/src/protocol/conformance/cases/guards.ts +19 -55
  111. package/src/protocol/conformance/cases/overlay.ts +195 -0
  112. package/src/protocol/conformance/cases/reads.ts +4 -4
  113. package/src/protocol/conformance/cases/writes.ts +15 -3
  114. package/src/protocol/conformance/context.ts +0 -7
  115. package/src/protocol/conformance/index.ts +2 -0
  116. package/src/protocol/server/content.ts +30 -4
  117. package/src/protocol/server/core.ts +0 -3
  118. package/src/protocol/server/methods/apply.ts +43 -38
  119. package/src/protocol/server/methods/changes.ts +42 -4
  120. package/src/protocol/server/methods/read.ts +2 -24
  121. package/src/protocol/storage/fs/index.ts +0 -18
  122. package/src/protocol/storage/memory.ts +124 -46
  123. package/src/protocol/storage.ts +69 -18
  124. package/src/protocol/types.ts +51 -8
  125. package/src/v8/analytics.ts +26 -5
  126. package/src/v8/builtins/data.ts +8 -0
  127. package/src/v8/builtins/index.ts +1 -6
  128. package/src/v8/builtins/legacy.ts +4 -5
  129. package/src/v8/cli/builtins.ts +0 -1
  130. package/src/v8/cli/check/index.ts +15 -34
  131. package/src/v8/cli/schema/builtinSchemas.ts +6 -8
  132. package/src/v8/cli/schema/generate.ts +1 -8
  133. package/src/v8/cli/schema/typeToSchema.ts +5 -31
  134. package/src/v8/client.ts +1 -1
  135. package/src/v8/cms.ts +5 -14
  136. package/src/v8/index.ts +0 -1
  137. package/src/v8/resolver.ts +1 -1
  138. package/src/v8/telemetry.ts +5 -20
  139. package/src/v8/types.ts +4 -5
  140. package/dist/protocol/ciphertext.d.ts +0 -7
  141. package/dist/protocol/ciphertext.d.ts.map +0 -1
  142. package/dist/protocol/ciphertext.js +0 -7
  143. package/dist/protocol/ciphertext.js.map +0 -1
  144. package/dist/protocol/secrets.d.ts +0 -22
  145. package/dist/protocol/secrets.d.ts.map +0 -1
  146. package/dist/protocol/secrets.js +0 -207
  147. package/dist/protocol/secrets.js.map +0 -1
  148. package/dist/v8/builtins/secret.d.ts +0 -7
  149. package/dist/v8/builtins/secret.d.ts.map +0 -1
  150. package/dist/v8/builtins/secret.js +0 -68
  151. package/dist/v8/builtins/secret.js.map +0 -1
  152. package/dist/v8/ciphertext.d.ts +0 -58
  153. package/dist/v8/ciphertext.d.ts.map +0 -1
  154. package/dist/v8/ciphertext.js +0 -134
  155. package/dist/v8/ciphertext.js.map +0 -1
  156. package/dist/v8/secrets.d.ts +0 -9
  157. package/dist/v8/secrets.d.ts.map +0 -1
  158. package/dist/v8/secrets.js +0 -14
  159. package/dist/v8/secrets.js.map +0 -1
  160. package/src/protocol/ciphertext.ts +0 -6
  161. package/src/protocol/secrets.ts +0 -239
  162. package/src/v8/builtins/secret.ts +0 -82
  163. package/src/v8/ciphertext.ts +0 -158
  164. package/src/v8/secrets.ts +0 -17
@@ -6,8 +6,7 @@
6
6
  * base (what `changes.*` compares the content with: the files that differ
7
7
  * from it, and reading base bodies).
8
8
  * The protocol core (`createContentHandler`) owns everything else: the
9
- * JSON-RPC layer, validation, the file-name rule, the secret guard, limits and
10
- * retries. Storages deal in *files* inside `<root>/.deco/blocks`; entry names
9
+ * JSON-RPC layer, validation, the file-name rule, limits and retries. Storages deal in *files* inside `<root>/.deco/blocks`; entry names
11
10
  * are the core's business.
12
11
  *
13
12
  * Browser-safe: types and small error classes only.
@@ -34,8 +33,22 @@ export interface StorageFile {
34
33
  version: string;
35
34
  /** The file's size in bytes, when the storage knows it without reading the body. */
36
35
  size?: number;
36
+ /**
37
+ * `true` for a tombstone: a deletion an overlay storage records over its
38
+ * base, listed only by `writeSnapshot()`. It has no body, and its
39
+ * `version` is the tombstone's (see `TOMBSTONE_VERSION`).
40
+ */
41
+ deleted?: true;
37
42
  }
38
43
 
44
+ /**
45
+ * The version an overlay storage reports for a deletion it records (a
46
+ * tombstone), in `writeSnapshot()`, `changes()` and a commit's result. Any
47
+ * value no file content has works; the reference storage uses this one, and
48
+ * a storage that shares clients with it should too.
49
+ */
50
+ export const TOMBSTONE_VERSION = "tombstone";
51
+
39
52
  /** Every saved-block file at one point in time. */
40
53
  export interface StorageSnapshot {
41
54
  /** An opaque revision of the whole set, compared only for equality. */
@@ -67,25 +80,32 @@ export interface StoredSchema {
67
80
 
68
81
  /** One atomic commit attempt. */
69
82
  export interface CommitAttempt {
70
- /** The snapshot the core validated against. */
83
+ /**
84
+ * The snapshot the core validated against: `writeSnapshot()`'s for an
85
+ * overlay storage (`blocks.apply`), `snapshot()`'s otherwise.
86
+ */
71
87
  base: StorageSnapshot;
72
88
  /** Files to write, by file name, with their full content. */
73
89
  put: Record<string, string>;
74
- /** Files to delete. A file that's already gone is fine. */
90
+ /**
91
+ * Files to delete. A file that's already gone is fine. For an overlay
92
+ * storage, `blocks.apply` also names files the overlay doesn't hold: the
93
+ * storage records the deletion over its base (a file only the base has
94
+ * must disappear from `snapshot()`, and `writeSnapshot()` lists it as a
95
+ * tombstone). One neither side has it may drop, or record as a tombstone
96
+ * too (a storage whose write never reads the base can't tell them apart);
97
+ * the core treats such a tombstone like any other.
98
+ */
75
99
  delete: string[];
76
100
  /**
77
101
  * Versions the files must still have for the commit to land (`null` = must
78
- * not exist). A storage MUST reject the attempt as stale when any of them
79
- * changed, and MAY reject it when anything else changed since `base`.
102
+ * not exist), in the snapshot `base` came from (the overlay, for an overlay
103
+ * storage's `blocks.apply`, where a tombstone has its tombstone version
104
+ * and so is not `null`). A storage MUST reject the attempt as stale
105
+ * when any of them changed, and MAY reject it when anything else changed
106
+ * since `base`.
80
107
  */
81
108
  expected: Record<string, string | null>;
82
- /**
83
- * The schema version the core validated against (`null` = no schema), when
84
- * the write depends on it (the secret guard checks `set` against it). When set,
85
- * a storage MUST reject the attempt as stale if the schema's version at
86
- * commit time differs, checked atomically with `expected`.
87
- */
88
- expectedSchemaVersion?: string | null;
89
109
  /**
90
110
  * The base revision (`StorageBase.revision`) the core computed the write
91
111
  * from, when the write depends on it (`changes.discard` restores base
@@ -96,7 +116,9 @@ export interface CommitAttempt {
96
116
  /**
97
117
  * Why the core commits: `apply` (default) or `discard`. For logs, and a
98
118
  * storage with a staging area (the fs storage's git index) also unstages
99
- * the files a `discard` writes or deletes, in the same commit.
119
+ * the files a `discard` writes or deletes, in the same commit. An overlay
120
+ * storage applies a `discard` by dropping those files from the overlay, so
121
+ * the base shows through (`put` holds the base's own bytes).
100
122
  */
101
123
  reason?: "apply" | "discard";
102
124
  }
@@ -116,9 +138,18 @@ export interface StorageChanges {
116
138
  * in the base, in the base and not in the snapshot, or in both with
117
139
  * different content. A file whose content equals the base's (the storage
118
140
  * decides equality, such as honouring git's eol conversion) MUST NOT be
119
- * listed, so a file a discard just restored is never listed again.
141
+ * listed, so a file a discard just restored is never listed again. An
142
+ * overlay storage instead lists exactly the files its overlay holds, and
143
+ * the deletions it records of files the base has, even a file equal to the
144
+ * base's: the overlay's own entries are the changes.
120
145
  */
121
146
  files: string[];
147
+ /**
148
+ * An overlay storage: the tombstones among `files` (the deletions it
149
+ * records), with the versions `writeSnapshot()` lists them with, which
150
+ * `changes.list` reports as the deletions' versions. Absent otherwise.
151
+ */
152
+ tombstones?: StorageFile[];
122
153
  /**
123
154
  * The base's files, with their versions in the base: at least every file
124
155
  * whose spelling group (`spellingKey`) a file in `files` belongs to; more
@@ -130,8 +161,13 @@ export interface StorageChanges {
130
161
  export type CommitResult =
131
162
  | {
132
163
  status: "committed";
164
+ /** The revision `snapshot()` reports right after the commit (`blocks.list`'s). */
133
165
  revision: string;
134
- /** The new version of every file in `put`. */
166
+ /**
167
+ * The new version of every file in `put`, and for an overlay storage
168
+ * the tombstone version of every file in `delete` it recorded as a
169
+ * tombstone (not one it dropped because neither side has it).
170
+ */
135
171
  versions: Record<string, string>;
136
172
  }
137
173
  | { status: "stale" };
@@ -152,8 +188,23 @@ export interface ContentStorage {
152
188
  readFiles(snapshot: StorageSnapshot, files: string[]): Promise<Record<string, StoredFileBody>>;
153
189
  /** Reads `schema.gen.json`, falling back to `meta.gen.json`; `null` when neither exists. */
154
190
  readSchema(): Promise<StoredSchema | null>;
155
- /** Reads `<root>/.deco/secrets.pub`; `null` without one. */
156
- readSecretsPublicKey(): Promise<string | null>;
191
+ /**
192
+ * An overlay storage's own files: what it holds over its base (a hosted
193
+ * draft's blocks over the published branch), read without reading the
194
+ * base. Its presence makes the endpoint an overlay (`describe.overlay`):
195
+ * `blocks.apply` validates and checks `ifMatch` against this snapshot
196
+ * instead of `snapshot()`, and commits with it as `base`; `readFiles`
197
+ * reads its files too. A deletion the overlay records is listed as a
198
+ * tombstone (`deleted: true`, with its tombstone version): for a guard the
199
+ * overlay holds it, so `ifMatch: null` on it fails and its tombstone
200
+ * version passes. The
201
+ * revision `snapshot()` reports must move whenever the overlay does, even
202
+ * when the content it shows doesn't (an entry saved with the base's
203
+ * value). Absent
204
+ * for a storage that writes its content directly (a working tree, a
205
+ * branch).
206
+ */
207
+ writeSnapshot?(): Promise<StorageSnapshot>;
157
208
  /** One all-or-nothing commit attempt; durable when it resolves. */
158
209
  commit(attempt: CommitAttempt): Promise<CommitResult>;
159
210
  /**
@@ -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
 
@@ -7,6 +7,9 @@
7
7
  * `analytics` block's settings. In the browser it sends a page view on load
8
8
  * (once the page is visible, so prerendered pages don't count) and on every
9
9
  * navigation that changes the path, and exposes the sender `track` uses.
10
+ * Beside it, it renders the Deco Analytics tag (decocms/analytics), which
11
+ * collects on its own: from the collector's origin with `decoAnalyticsKey`, or
12
+ * from the site's own host with `decoAnalyticsFirstParty`.
10
13
  *
11
14
  * Wire format (pinned against onedollarstats' stonks.js tracker):
12
15
  * `{ u, e: [{ t, h, r, p }], debug }`, where `u` is the page URL without its
@@ -16,8 +19,12 @@
16
19
  * of the UTF-8 JSON>` when that's at most 1500 characters, otherwise with
17
20
  * `navigator.sendBeacon` or a `POST`.
18
21
  */
19
- import { createElement, type ReactNode } from "react";
20
- import { HOSTED_ANALYTICS_COLLECTOR } from "./builtins/data.ts";
22
+ import { createElement, Fragment, type ReactNode } from "react";
23
+ import {
24
+ DECO_ANALYTICS_ORIGIN,
25
+ DECO_ANALYTICS_SCRIPT,
26
+ HOSTED_ANALYTICS_COLLECTOR,
27
+ } from "./builtins/data.ts";
21
28
  import type { Analytics } from "./types.ts";
22
29
 
23
30
  const GLOBAL = "__decoAnalytics";
@@ -26,15 +33,29 @@ const GLOBAL = "__decoAnalytics";
26
33
  const TRACKER = `(function(){var s=document.currentScript,c=s&&s.getAttribute("data-url");if(!c||window.${GLOBAL})return;var last;function post(b){if(navigator.sendBeacon&&navigator.sendBeacon(c,b))return;fetch(c,{method:"POST",body:b,headers:{"Content-Type":"application/json"},keepalive:true}).catch(function(){})}function send(t,p){var u=new URL(location.href);u.search="";u.hash="";var r;try{if(document.referrer){var f=new URL(document.referrer);if(f.hostname!==u.hostname){f.search="";f.hash="";r=f.href}}}catch(e){}var b=JSON.stringify({u:u.href.replace(/\\/$/,""),e:[{t:t,h:false,r:r,p:p}],debug:false});var d=btoa(String.fromCharCode.apply(null,Array.from(new TextEncoder().encode(b))));if(d.length<=1500){new Image(1,1).src=c+"?data="+d}else post(b)}function view(){if(location.pathname===last)return;last=location.pathname;send("PageView")}window.${GLOBAL}={track:function(n,p){send(n,p)}};var h=history.pushState;history.pushState=function(){h.apply(this,arguments);requestAnimationFrame(view)};addEventListener("popstate",function(){requestAnimationFrame(view)});if(document.visibilityState==="visible")view();else document.addEventListener("visibilitychange",function v(){if(document.visibilityState==="visible"){document.removeEventListener("visibilitychange",v);view()}})})();`;
27
34
 
28
35
  /**
29
- * The tracking script. Render it in your root layout with the resolved
30
- * `analytics` block's settings; renders nothing when `enabled` is false.
36
+ * The Deco Analytics tag's URL. Null without a key: on the collector's origin
37
+ * nothing else identifies the site, so its events would be dropped.
38
+ */
39
+ function decoAnalyticsSrc(props: Analytics): string | null {
40
+ if (props.decoAnalyticsFirstParty === true) return DECO_ANALYTICS_SCRIPT;
41
+ if (!props.decoAnalyticsKey) return null;
42
+ return `${DECO_ANALYTICS_ORIGIN}${DECO_ANALYTICS_SCRIPT}?k=${encodeURIComponent(props.decoAnalyticsKey)}`;
43
+ }
44
+
45
+ /**
46
+ * The tracking script, and the Deco Analytics tag when the site has one. Render
47
+ * it in your root layout with the resolved `analytics` block's settings; renders
48
+ * nothing when `enabled` is false.
31
49
  */
32
50
  export function AnalyticsScript(props: Analytics = {}): ReactNode | null {
33
51
  if (props.enabled === false) return null;
34
- return createElement("script", {
52
+ const tracker = createElement("script", {
35
53
  "data-url": props.collector ?? HOSTED_ANALYTICS_COLLECTOR,
36
54
  dangerouslySetInnerHTML: { __html: TRACKER },
37
55
  });
56
+ const src = decoAnalyticsSrc(props);
57
+ if (!src) return tracker;
58
+ return createElement(Fragment, null, tracker, createElement("script", { async: true, src }));
38
59
  }
39
60
 
40
61
  /**
@@ -3,6 +3,12 @@ import type { Analytics, CMSSettings, Redirect, Telemetry } from "../types.ts";
3
3
  /** The hosted Deco CMS collector: where page views go when `collector` is left out. */
4
4
  export const HOSTED_ANALYTICS_COLLECTOR = "https://d.lilstts.com/events";
5
5
 
6
+ /** Where the Deco Analytics tag loads from unless the site opts into first-party. */
7
+ export const DECO_ANALYTICS_ORIGIN = "https://analytics.decocdn.com";
8
+
9
+ /** The Deco Analytics tag's path, on that origin or on a first-party site's own host. */
10
+ export const DECO_ANALYTICS_SCRIPT = "/_dq/a.js";
11
+
6
12
  /**
7
13
  * `page`: its inputs are already resolved (`seo` and every block in
8
14
  * `sections`), so the page is its input.
@@ -44,6 +50,8 @@ export function analyticsSection(section: unknown): Required<Analytics> {
44
50
  ? a.collector
45
51
  : HOSTED_ANALYTICS_COLLECTOR,
46
52
  enabled: typeof a.enabled === "boolean" ? a.enabled : true,
53
+ decoAnalyticsKey: typeof a.decoAnalyticsKey === "string" ? a.decoAnalyticsKey : "",
54
+ decoAnalyticsFirstParty: a.decoAnalyticsFirstParty === true,
47
55
  };
48
56
  }
49
57
 
@@ -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. */
@@ -262,16 +260,16 @@ function builtInProps(name: string, ctx: BuiltInContext): any {
262
260
  properties: {
263
261
  collector: { type: "string", title: "Collector" },
264
262
  enabled: { type: "boolean", title: "Enabled", default: true },
263
+ decoAnalyticsKey: { type: "string", title: "Deco Analytics key" },
264
+ decoAnalyticsFirstParty: {
265
+ type: "boolean",
266
+ title: "Deco Analytics first-party",
267
+ default: false,
268
+ },
265
269
  },
266
270
  },
267
271
  },
268
272
  };
269
- case "secret":
270
- return {
271
- type: "object",
272
- required: ["ciphertext"],
273
- properties: { ciphertext: { type: "string", title: "Ciphertext", writeOnly: true } },
274
- };
275
273
  }
276
274
  }
277
275
 
@@ -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();