@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.
- 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/conformance/cases/changes.d.ts.map +1 -1
- package/dist/protocol/conformance/cases/changes.js +14 -3
- package/dist/protocol/conformance/cases/changes.js.map +1 -1
- package/dist/protocol/conformance/cases/guards.d.ts.map +1 -1
- package/dist/protocol/conformance/cases/guards.js +19 -42
- package/dist/protocol/conformance/cases/guards.js.map +1 -1
- package/dist/protocol/conformance/cases/overlay.d.ts +3 -0
- package/dist/protocol/conformance/cases/overlay.d.ts.map +1 -0
- package/dist/protocol/conformance/cases/overlay.js +164 -0
- package/dist/protocol/conformance/cases/overlay.js.map +1 -0
- package/dist/protocol/conformance/cases/reads.js +5 -5
- package/dist/protocol/conformance/cases/reads.js.map +1 -1
- package/dist/protocol/conformance/cases/writes.d.ts.map +1 -1
- package/dist/protocol/conformance/cases/writes.js +15 -3
- package/dist/protocol/conformance/cases/writes.js.map +1 -1
- package/dist/protocol/conformance/context.d.ts +0 -10
- package/dist/protocol/conformance/context.d.ts.map +1 -1
- package/dist/protocol/conformance/context.js.map +1 -1
- package/dist/protocol/conformance/index.d.ts.map +1 -1
- package/dist/protocol/conformance/index.js +2 -0
- package/dist/protocol/conformance/index.js.map +1 -1
- package/dist/protocol/server/content.d.ts +8 -1
- package/dist/protocol/server/content.d.ts.map +1 -1
- package/dist/protocol/server/content.js +18 -3
- package/dist/protocol/server/content.js.map +1 -1
- package/dist/protocol/server/core.d.ts +0 -6
- package/dist/protocol/server/core.d.ts.map +1 -1
- package/dist/protocol/server/core.js +0 -2
- package/dist/protocol/server/core.js.map +1 -1
- package/dist/protocol/server/methods/apply.d.ts +16 -5
- package/dist/protocol/server/methods/apply.d.ts.map +1 -1
- package/dist/protocol/server/methods/apply.js +42 -38
- package/dist/protocol/server/methods/apply.js.map +1 -1
- package/dist/protocol/server/methods/changes.d.ts.map +1 -1
- package/dist/protocol/server/methods/changes.js +31 -3
- package/dist/protocol/server/methods/changes.js.map +1 -1
- package/dist/protocol/server/methods/read.d.ts.map +1 -1
- package/dist/protocol/server/methods/read.js +2 -23
- package/dist/protocol/server/methods/read.js.map +1 -1
- package/dist/protocol/storage/fs/index.d.ts.map +1 -1
- package/dist/protocol/storage/fs/index.js +0 -18
- package/dist/protocol/storage/fs/index.js.map +1 -1
- package/dist/protocol/storage/memory.d.ts +11 -3
- package/dist/protocol/storage/memory.d.ts.map +1 -1
- package/dist/protocol/storage/memory.js +114 -45
- package/dist/protocol/storage/memory.js.map +1 -1
- package/dist/protocol/storage.d.ts +68 -18
- package/dist/protocol/storage.d.ts.map +1 -1
- package/dist/protocol/storage.js +7 -0
- package/dist/protocol/storage.js.map +1 -1
- package/dist/protocol/types.d.ts +51 -8
- package/dist/protocol/types.d.ts.map +1 -1
- package/dist/protocol/types.js +5 -3
- package/dist/protocol/types.js.map +1 -1
- package/dist/v8/builtins/index.d.ts +1 -4
- package/dist/v8/builtins/index.d.ts.map +1 -1
- package/dist/v8/builtins/index.js +1 -6
- package/dist/v8/builtins/index.js.map +1 -1
- package/dist/v8/builtins/legacy.d.ts +4 -4
- package/dist/v8/builtins/legacy.d.ts.map +1 -1
- package/dist/v8/builtins/legacy.js +4 -5
- package/dist/v8/builtins/legacy.js.map +1 -1
- package/dist/v8/cli/builtins.d.ts.map +1 -1
- package/dist/v8/cli/builtins.js +0 -1
- package/dist/v8/cli/builtins.js.map +1 -1
- package/dist/v8/cli/check/index.d.ts +1 -1
- package/dist/v8/cli/check/index.d.ts.map +1 -1
- package/dist/v8/cli/check/index.js +13 -33
- package/dist/v8/cli/check/index.js.map +1 -1
- package/dist/v8/cli/schema/builtinSchemas.d.ts.map +1 -1
- package/dist/v8/cli/schema/builtinSchemas.js +0 -8
- package/dist/v8/cli/schema/builtinSchemas.js.map +1 -1
- package/dist/v8/cli/schema/generate.d.ts.map +1 -1
- package/dist/v8/cli/schema/generate.js +1 -8
- package/dist/v8/cli/schema/generate.js.map +1 -1
- package/dist/v8/cli/schema/typeToSchema.d.ts +0 -1
- package/dist/v8/cli/schema/typeToSchema.d.ts.map +1 -1
- package/dist/v8/cli/schema/typeToSchema.js +5 -30
- package/dist/v8/cli/schema/typeToSchema.js.map +1 -1
- package/dist/v8/client.d.ts +1 -1
- package/dist/v8/client.d.ts.map +1 -1
- package/dist/v8/cms.d.ts.map +1 -1
- package/dist/v8/cms.js +31 -21
- package/dist/v8/cms.js.map +1 -1
- package/dist/v8/content.d.ts +35 -1
- package/dist/v8/content.d.ts.map +1 -1
- package/dist/v8/content.js +81 -2
- package/dist/v8/content.js.map +1 -1
- package/dist/v8/index.d.ts +1 -1
- package/dist/v8/index.d.ts.map +1 -1
- package/dist/v8/preview/DraftBadge.d.ts +9 -1
- package/dist/v8/preview/DraftBadge.d.ts.map +1 -1
- package/dist/v8/preview/DraftBadge.js +42 -2
- package/dist/v8/preview/DraftBadge.js.map +1 -1
- package/dist/v8/remoteLoader.d.ts.map +1 -1
- package/dist/v8/remoteLoader.js +3 -1
- package/dist/v8/remoteLoader.js.map +1 -1
- package/dist/v8/resolver.d.ts +1 -1
- package/dist/v8/resolver.d.ts.map +1 -1
- package/dist/v8/telemetry.d.ts +0 -2
- package/dist/v8/telemetry.d.ts.map +1 -1
- package/dist/v8/telemetry.js +5 -20
- package/dist/v8/telemetry.js.map +1 -1
- package/dist/v8/types.d.ts +37 -10
- package/dist/v8/types.d.ts.map +1 -1
- package/package.json +1 -6
- package/src/index.ts +1 -2
- package/src/protocol/conformance/cases/changes.ts +16 -4
- package/src/protocol/conformance/cases/guards.ts +19 -55
- package/src/protocol/conformance/cases/overlay.ts +195 -0
- package/src/protocol/conformance/cases/reads.ts +4 -4
- package/src/protocol/conformance/cases/writes.ts +15 -3
- package/src/protocol/conformance/context.ts +0 -7
- package/src/protocol/conformance/index.ts +2 -0
- package/src/protocol/server/content.ts +30 -4
- package/src/protocol/server/core.ts +0 -3
- package/src/protocol/server/methods/apply.ts +43 -38
- package/src/protocol/server/methods/changes.ts +42 -4
- package/src/protocol/server/methods/read.ts +2 -24
- package/src/protocol/storage/fs/index.ts +0 -18
- package/src/protocol/storage/memory.ts +124 -46
- package/src/protocol/storage.ts +69 -18
- package/src/protocol/types.ts +51 -8
- package/src/v8/builtins/index.ts +1 -6
- package/src/v8/builtins/legacy.ts +4 -5
- package/src/v8/cli/builtins.ts +0 -1
- package/src/v8/cli/check/index.ts +15 -34
- package/src/v8/cli/schema/builtinSchemas.ts +0 -8
- package/src/v8/cli/schema/generate.ts +1 -8
- package/src/v8/cli/schema/typeToSchema.ts +5 -31
- package/src/v8/client.ts +1 -1
- package/src/v8/cms.ts +37 -22
- package/src/v8/content.ts +82 -2
- package/src/v8/index.ts +0 -1
- package/src/v8/preview/DraftBadge.tsx +72 -2
- package/src/v8/remoteLoader.ts +3 -1
- package/src/v8/resolver.ts +1 -1
- package/src/v8/telemetry.ts +5 -20
- package/src/v8/types.ts +36 -7
- package/dist/protocol/ciphertext.d.ts +0 -7
- package/dist/protocol/ciphertext.d.ts.map +0 -1
- package/dist/protocol/ciphertext.js +0 -7
- package/dist/protocol/ciphertext.js.map +0 -1
- package/dist/protocol/secrets.d.ts +0 -22
- package/dist/protocol/secrets.d.ts.map +0 -1
- package/dist/protocol/secrets.js +0 -207
- package/dist/protocol/secrets.js.map +0 -1
- package/dist/v8/builtins/secret.d.ts +0 -7
- package/dist/v8/builtins/secret.d.ts.map +0 -1
- package/dist/v8/builtins/secret.js +0 -68
- package/dist/v8/builtins/secret.js.map +0 -1
- package/dist/v8/ciphertext.d.ts +0 -58
- package/dist/v8/ciphertext.d.ts.map +0 -1
- package/dist/v8/ciphertext.js +0 -134
- package/dist/v8/ciphertext.js.map +0 -1
- package/dist/v8/secrets.d.ts +0 -9
- package/dist/v8/secrets.d.ts.map +0 -1
- package/dist/v8/secrets.js +0 -14
- package/dist/v8/secrets.js.map +0 -1
- package/src/protocol/ciphertext.ts +0 -6
- package/src/protocol/secrets.ts +0 -239
- package/src/v8/builtins/secret.ts +0 -82
- package/src/v8/ciphertext.ts +0 -158
- package/src/v8/secrets.ts +0 -17
package/src/v8/content.ts
CHANGED
|
@@ -104,6 +104,17 @@ export class ContentStore {
|
|
|
104
104
|
#source: Snapshot | Loader;
|
|
105
105
|
#release: Promise<Snapshot> | undefined;
|
|
106
106
|
#updating: Promise<{ updated: boolean }> | undefined;
|
|
107
|
+
/** The check a draft read waits on when one was already running when it arrived (see `checkRelease`). */
|
|
108
|
+
#queued: Promise<string> | undefined;
|
|
109
|
+
/**
|
|
110
|
+
* Release checks a request can share (`checkRelease`): how many ended (a
|
|
111
|
+
* check's id is handed out only once it ended), and this store's prefix
|
|
112
|
+
* for their ids, so an id from another process (or another CMS) is never
|
|
113
|
+
* taken for one of these. The prefix is made on the first check, never at
|
|
114
|
+
* module scope.
|
|
115
|
+
*/
|
|
116
|
+
#checksDone = 0;
|
|
117
|
+
#checkPrefix: string | undefined;
|
|
107
118
|
readonly #drafts = new BoundedMap<string, CachedDraft>(CACHED_DRAFTS);
|
|
108
119
|
/** Draft reads in flight, so concurrent renders of one draft share one request. */
|
|
109
120
|
readonly #draftReads = new Map<string, Promise<CachedDraft>>();
|
|
@@ -149,8 +160,16 @@ export class ContentStore {
|
|
|
149
160
|
* changes are keyed by the pointer without its `__variant` parameters (every
|
|
150
161
|
* variant of one draft shares one body) and revalidated on every read: a
|
|
151
162
|
* `304` reuses the body held, a `200` replaces it.
|
|
163
|
+
*
|
|
164
|
+
* Before layering, a draft read checks the source for a newer release and
|
|
165
|
+
* waits for that check (see `checkRelease`), so a draft always shows over
|
|
166
|
+
* the latest release, even in a process that hasn't picked it up yet. The
|
|
167
|
+
* check runs beside the draft's own revalidation. With `releaseCheck` (the
|
|
168
|
+
* id `checkRelease` resolved with, for this request), it waits for that
|
|
169
|
+
* check instead of making its own; an id this store didn't make is a check
|
|
170
|
+
* of its own.
|
|
152
171
|
*/
|
|
153
|
-
draft(pointer: string): Promise<Snapshot> {
|
|
172
|
+
draft(pointer: string, releaseCheck?: string | null): Promise<Snapshot> {
|
|
154
173
|
const parsed = parseDraftPointer(pointer);
|
|
155
174
|
if (parsed === null) {
|
|
156
175
|
return Promise.reject(errors.loaderFailed(`invalid draft pointer "${truncate(pointer)}"`));
|
|
@@ -184,7 +203,8 @@ export class ContentStore {
|
|
|
184
203
|
const changes = read.catch((error: unknown) => {
|
|
185
204
|
throw errors.loaderFailed("the draft's changes couldn't be fetched", error);
|
|
186
205
|
});
|
|
187
|
-
|
|
206
|
+
const release = this.waitForCheck(releaseCheck).then(() => this.release());
|
|
207
|
+
return Promise.all([release, changes]).then(([base, entry]) => {
|
|
188
208
|
let view = entry.views.get(base);
|
|
189
209
|
if (view === undefined) {
|
|
190
210
|
// OPEN: the view is keyed by the body's ETag (the pointer outlives later saves); the version without one.
|
|
@@ -276,6 +296,66 @@ export class ContentStore {
|
|
|
276
296
|
return this.#updating;
|
|
277
297
|
}
|
|
278
298
|
|
|
299
|
+
/**
|
|
300
|
+
* The release check a draft request waits on (PO 2026-10-23: a draft always
|
|
301
|
+
* shows over the latest release), resolving with its id once it ends. With
|
|
302
|
+
* no check running, it starts one. With one running, that one started
|
|
303
|
+
* before this request, so it waits on the next one instead, shared by every
|
|
304
|
+
* request that arrives meanwhile: a burst makes at most two checks, and no
|
|
305
|
+
* request relies on a check that started before it. No time-based throttle:
|
|
306
|
+
* the request right after a publish always checks. One request shares one
|
|
307
|
+
* check: the binding passes the id on to the host check and every draft
|
|
308
|
+
* read (`waitForCheck`), so a preview request reads `latest.json` once.
|
|
309
|
+
* Never rejects (`update()` doesn't), and a check that hangs ends with the
|
|
310
|
+
* loader's fetch timeout, leaving the release held. Release reads never
|
|
311
|
+
* come here: they keep the background check.
|
|
312
|
+
*
|
|
313
|
+
* Given the id of a check this store made (one a proxy in front made for
|
|
314
|
+
* the same request, say; an id is handed out once its check ended), it
|
|
315
|
+
* resolves with that id at once; any other id is ignored and a check is
|
|
316
|
+
* made.
|
|
317
|
+
*/
|
|
318
|
+
checkRelease(releaseCheck?: string | null): Promise<string> {
|
|
319
|
+
if (!this.updatable) return Promise.resolve(this.#checkId(0));
|
|
320
|
+
if (typeof releaseCheck === "string" && this.#madeCheck(releaseCheck)) {
|
|
321
|
+
return Promise.resolve(releaseCheck);
|
|
322
|
+
}
|
|
323
|
+
const running = this.#updating;
|
|
324
|
+
if (running === undefined) return this.#startCheck();
|
|
325
|
+
this.#queued ??= running.then(() => {
|
|
326
|
+
this.#queued = undefined;
|
|
327
|
+
return this.#startCheck();
|
|
328
|
+
});
|
|
329
|
+
return this.#queued;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* Nothing to wait for when this store made the check `releaseCheck` names
|
|
334
|
+
* (it ended); with no id, or one this store didn't make, makes a check of
|
|
335
|
+
* its own (`checkRelease`). A source that can't change never waits.
|
|
336
|
+
*/
|
|
337
|
+
waitForCheck(releaseCheck: string | null | undefined): Promise<void> {
|
|
338
|
+
if (!this.updatable) return Promise.resolve();
|
|
339
|
+
return this.checkRelease(releaseCheck).then(() => undefined);
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
#startCheck(): Promise<string> {
|
|
343
|
+
return this.update().then(() => this.#checkId(++this.#checksDone));
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
#checkId(n: number): string {
|
|
347
|
+
this.#checkPrefix ??= `${globalThis.crypto.randomUUID()}:`;
|
|
348
|
+
return `${this.#checkPrefix}${n}`;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/** Whether `id` names a check this store made (and so one that ended). */
|
|
352
|
+
#madeCheck(id: string): boolean {
|
|
353
|
+
const prefix = this.#checkPrefix;
|
|
354
|
+
if (prefix === undefined || !id.startsWith(prefix)) return false;
|
|
355
|
+
const digits = id.slice(prefix.length);
|
|
356
|
+
return /^\d{1,15}$/.test(digits) && Number(digits) <= this.#checksDone;
|
|
357
|
+
}
|
|
358
|
+
|
|
279
359
|
/**
|
|
280
360
|
* Swaps the content in place, for a hot reload that hands the same CMS a new
|
|
281
361
|
* content module. Any new object swaps, even with the same `revision`: an
|
package/src/v8/index.ts
CHANGED
|
@@ -11,6 +11,9 @@
|
|
|
11
11
|
*
|
|
12
12
|
* - Renders nothing without a `pointer`, so a binding can mount it on every
|
|
13
13
|
* page and pass the request's draft pointer (or `null`).
|
|
14
|
+
* - `unavailable`: the link named a draft that can't be read anymore, and
|
|
15
|
+
* the page shows the published site. Outside a frame, a calm notice says
|
|
16
|
+
* so (nothing to fix, nothing to retry); inside Studio's frame, nothing.
|
|
14
17
|
* - Hidden inside a frame: Studio's site editor shows the draft in an iframe
|
|
15
18
|
* with its own chrome. A reviewer who opens a shared link in their own tab
|
|
16
19
|
* still sees it.
|
|
@@ -39,8 +42,17 @@ export interface DraftBadgeProps {
|
|
|
39
42
|
* `?__draft=off`, which clears the draft cookie.
|
|
40
43
|
*/
|
|
41
44
|
exitHref?: string;
|
|
45
|
+
/**
|
|
46
|
+
* The link's draft can't be read anymore (deleted, say): the binding
|
|
47
|
+
* rendered the published site instead. Shows a calm notice outside a frame.
|
|
48
|
+
*/
|
|
49
|
+
unavailable?: boolean;
|
|
42
50
|
}
|
|
43
51
|
|
|
52
|
+
/** What the notice says when a link's draft is gone. */
|
|
53
|
+
const DRAFT_UNAVAILABLE_MESSAGE =
|
|
54
|
+
"This draft isn't available anymore. You're seeing the published site.";
|
|
55
|
+
|
|
44
56
|
/**
|
|
45
57
|
* The link "Share preview" copies: the current URL with `?__draft=<pointer>`,
|
|
46
58
|
* so the recipient sees this exact draft version.
|
|
@@ -114,7 +126,7 @@ function ShareIcon() {
|
|
|
114
126
|
);
|
|
115
127
|
}
|
|
116
128
|
|
|
117
|
-
export function DraftBadge({ pointer, exitHref }: DraftBadgeProps): ReactNode {
|
|
129
|
+
export function DraftBadge({ pointer, exitHref, unavailable }: DraftBadgeProps): ReactNode {
|
|
118
130
|
const [open, setOpen] = useState(false);
|
|
119
131
|
const [copied, setCopied] = useState(false);
|
|
120
132
|
const [visible, setVisible] = useState(false);
|
|
@@ -161,7 +173,8 @@ export function DraftBadge({ pointer, exitHref }: DraftBadgeProps): ReactNode {
|
|
|
161
173
|
}
|
|
162
174
|
}, [pointer]);
|
|
163
175
|
|
|
164
|
-
if (!
|
|
176
|
+
if (!visible) return null;
|
|
177
|
+
if (!pointer) return unavailable ? <UnavailableNotice /> : null;
|
|
165
178
|
|
|
166
179
|
return (
|
|
167
180
|
<div
|
|
@@ -236,6 +249,63 @@ export function DraftBadge({ pointer, exitHref }: DraftBadgeProps): ReactNode {
|
|
|
236
249
|
);
|
|
237
250
|
}
|
|
238
251
|
|
|
252
|
+
/** The notice for a link whose draft is gone: the published site is what shows. */
|
|
253
|
+
function UnavailableNotice() {
|
|
254
|
+
const [dismissed, setDismissed] = useState(false);
|
|
255
|
+
if (dismissed) return null;
|
|
256
|
+
return (
|
|
257
|
+
<div
|
|
258
|
+
role="status"
|
|
259
|
+
data-deco-preview-unavailable=""
|
|
260
|
+
style={{
|
|
261
|
+
position: "fixed",
|
|
262
|
+
bottom: 16,
|
|
263
|
+
left: 16,
|
|
264
|
+
zIndex: 2147483647,
|
|
265
|
+
display: "flex",
|
|
266
|
+
alignItems: "center",
|
|
267
|
+
gap: 10,
|
|
268
|
+
maxWidth: "calc(100vw - 32px)",
|
|
269
|
+
padding: "8px 8px 8px 12px",
|
|
270
|
+
background: "#fff",
|
|
271
|
+
color: "#1a1a1a",
|
|
272
|
+
borderRadius: 12,
|
|
273
|
+
boxShadow: "0 8px 30px rgba(0,0,0,0.18), 0 0 0 1px rgba(0,0,0,0.05)",
|
|
274
|
+
fontFamily:
|
|
275
|
+
"-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif",
|
|
276
|
+
fontSize: 13,
|
|
277
|
+
lineHeight: 1.4,
|
|
278
|
+
}}
|
|
279
|
+
>
|
|
280
|
+
<img
|
|
281
|
+
src={DECO_MARK_DATA_URI}
|
|
282
|
+
alt=""
|
|
283
|
+
width={18}
|
|
284
|
+
height={18}
|
|
285
|
+
style={{ display: "block", borderRadius: 4, flexShrink: 0 }}
|
|
286
|
+
/>
|
|
287
|
+
<span>{DRAFT_UNAVAILABLE_MESSAGE}</span>
|
|
288
|
+
<button
|
|
289
|
+
type="button"
|
|
290
|
+
aria-label="Dismiss"
|
|
291
|
+
onClick={() => setDismissed(true)}
|
|
292
|
+
style={{
|
|
293
|
+
flexShrink: 0,
|
|
294
|
+
padding: "2px 8px",
|
|
295
|
+
background: "transparent",
|
|
296
|
+
border: "none",
|
|
297
|
+
color: "inherit",
|
|
298
|
+
cursor: "pointer",
|
|
299
|
+
fontSize: 16,
|
|
300
|
+
lineHeight: 1,
|
|
301
|
+
}}
|
|
302
|
+
>
|
|
303
|
+
×
|
|
304
|
+
</button>
|
|
305
|
+
</div>
|
|
306
|
+
);
|
|
307
|
+
}
|
|
308
|
+
|
|
239
309
|
function MenuItem({
|
|
240
310
|
onClick,
|
|
241
311
|
label,
|
package/src/v8/remoteLoader.ts
CHANGED
|
@@ -8,7 +8,9 @@
|
|
|
8
8
|
* last swapped in, or the fallback's content until then. Nothing persists
|
|
9
9
|
* across restarts: every boot starts from the fallback.
|
|
10
10
|
* - `update()` (the CMS calls it in the background, on first use and then
|
|
11
|
-
* every interval
|
|
11
|
+
* every interval, and once per draft request, which waits for it, so a
|
|
12
|
+
* draft always shows over the latest release: `cms.checkRelease()`) reads
|
|
13
|
+
* `sites/<site>/latest.json`,
|
|
12
14
|
* `{ revision, schemaHash, publishedAt, previewHosts }`. Whoever is newer wins: when it
|
|
13
15
|
* names a revision other than the one this process last swapped in, its
|
|
14
16
|
* `schemaHash` equals the fallback's, and its `publishedAt` is later than
|
package/src/v8/resolver.ts
CHANGED
|
@@ -33,7 +33,7 @@ type Path = (string | number)[];
|
|
|
33
33
|
interface ResolverOptions {
|
|
34
34
|
snapshot: Snapshot;
|
|
35
35
|
blocks: Blocks;
|
|
36
|
-
/** The built-
|
|
36
|
+
/** The built-in blocks. */
|
|
37
37
|
builtIns: Readonly<Blocks>;
|
|
38
38
|
/** The client this resolver belongs to: `currentClient()` while a block function runs. */
|
|
39
39
|
client?: Client;
|
package/src/v8/telemetry.ts
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* Workers, on an unref'd timer elsewhere); a send that fails is retried
|
|
16
16
|
* once on 429/502/503/504 and otherwise dropped.
|
|
17
17
|
* - Everything is scrubbed before encoding: no query strings, tokens,
|
|
18
|
-
* cookies or authorization values
|
|
18
|
+
* cookies or authorization values.
|
|
19
19
|
*/
|
|
20
20
|
import { hasBackgroundHook, later, runInBackground } from "./background.ts";
|
|
21
21
|
import { rate, TELEMETRY_DEFAULTS } from "./builtins/data.ts";
|
|
@@ -29,7 +29,6 @@ const SINK = Symbol.for("decocms.blocks.telemetry");
|
|
|
29
29
|
const FLUSH_MS = 10_000;
|
|
30
30
|
const MAX_LOGS = 200;
|
|
31
31
|
const MAX_SPANS = 1_000;
|
|
32
|
-
const MAX_SECRETS = 1_000;
|
|
33
32
|
const RETRY_STATUSES = new Set([429, 502, 503, 504]);
|
|
34
33
|
/** OpenTelemetry's recommended `http.*.request.duration` buckets, in seconds. */
|
|
35
34
|
const BOUNDS = [0.005, 0.01, 0.025, 0.05, 0.075, 0.1, 0.25, 0.5, 0.75, 1, 2.5, 5, 7.5, 10];
|
|
@@ -131,19 +130,12 @@ export class TelemetryPipeline {
|
|
|
131
130
|
#spans: (SpanInput & { spanId: string })[] = [];
|
|
132
131
|
#windowStart = Date.now();
|
|
133
132
|
#scheduled = false;
|
|
134
|
-
/** Values secret blocks decrypted, replaced with `[redacted]` wherever they'd be sent. */
|
|
135
|
-
readonly #secrets = new Set<string>();
|
|
136
133
|
|
|
137
134
|
constructor(destination: Destination) {
|
|
138
135
|
this.#destination = destination;
|
|
139
136
|
this.apply(TELEMETRY_DEFAULTS);
|
|
140
137
|
}
|
|
141
138
|
|
|
142
|
-
/** Never send `value`: it's replaced with `[redacted]` in every log, span and label. */
|
|
143
|
-
redact(value: string): void {
|
|
144
|
-
if (value.length > 0 && this.#secrets.size < MAX_SECRETS) this.#secrets.add(value);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
139
|
/** The release being served: its revision labels batches. */
|
|
148
140
|
useRelease(snapshot: Snapshot): void {
|
|
149
141
|
this.#release = snapshot.revision;
|
|
@@ -272,8 +264,7 @@ export class TelemetryPipeline {
|
|
|
272
264
|
this.#histograms = new Map();
|
|
273
265
|
this.#logs = [];
|
|
274
266
|
this.#spans = [];
|
|
275
|
-
const
|
|
276
|
-
const encode = (attributes: Attributes) => encodeAttributes(attributes, scrub);
|
|
267
|
+
const encode = encodeAttributes;
|
|
277
268
|
const resource = { attributes: encode(this.#resource()) };
|
|
278
269
|
const scope = { name: "@decocms/blocks" };
|
|
279
270
|
const sends: Promise<void>[] = [];
|
|
@@ -326,7 +317,7 @@ export class TelemetryPipeline {
|
|
|
326
317
|
timeUnixNano: nanos(log.time),
|
|
327
318
|
severityNumber: 17,
|
|
328
319
|
severityText: "ERROR",
|
|
329
|
-
body: { stringValue:
|
|
320
|
+
body: { stringValue: scrubText(log.message) },
|
|
330
321
|
attributes: encode(log.attributes),
|
|
331
322
|
})),
|
|
332
323
|
},
|
|
@@ -367,12 +358,6 @@ export class TelemetryPipeline {
|
|
|
367
358
|
await Promise.all(sends);
|
|
368
359
|
}
|
|
369
360
|
|
|
370
|
-
#scrub(text: string): string {
|
|
371
|
-
let out = text;
|
|
372
|
-
for (const secret of this.#secrets) out = out.split(secret).join("[redacted]");
|
|
373
|
-
return scrubText(out);
|
|
374
|
-
}
|
|
375
|
-
|
|
376
361
|
#schedule(): void {
|
|
377
362
|
if (this.#scheduled) return;
|
|
378
363
|
this.#scheduled = true;
|
|
@@ -480,14 +465,14 @@ function randomHex(bytes: number): string {
|
|
|
480
465
|
return Array.from(values, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
481
466
|
}
|
|
482
467
|
|
|
483
|
-
function encodeAttributes(attributes: Attributes
|
|
468
|
+
function encodeAttributes(attributes: Attributes) {
|
|
484
469
|
return Object.entries(attributes)
|
|
485
470
|
.filter(([, value]) => value !== undefined)
|
|
486
471
|
.map(([key, value]) => ({
|
|
487
472
|
key,
|
|
488
473
|
value:
|
|
489
474
|
typeof value === "string"
|
|
490
|
-
? { stringValue:
|
|
475
|
+
? { stringValue: scrubText(value) }
|
|
491
476
|
: typeof value === "boolean"
|
|
492
477
|
? { boolValue: value }
|
|
493
478
|
: Number.isInteger(value)
|
package/src/v8/types.ts
CHANGED
|
@@ -151,9 +151,6 @@ export interface LegacyRedirect {
|
|
|
151
151
|
};
|
|
152
152
|
}
|
|
153
153
|
|
|
154
|
-
/** A field the site editor saves encrypted, as a `secret` block. */
|
|
155
|
-
export type Secret = string & { readonly __secret: true };
|
|
156
|
-
|
|
157
154
|
/** A prop the built-in `lazy` block fills; resolves its value when called, at most once. */
|
|
158
155
|
export type Lazy<T> = () => Promise<T>;
|
|
159
156
|
|
|
@@ -298,8 +295,6 @@ export interface CMSConfig {
|
|
|
298
295
|
*/
|
|
299
296
|
draftHosts?: string[];
|
|
300
297
|
};
|
|
301
|
-
/** The private key that decrypts `secret` blocks. */
|
|
302
|
-
secrets?: { key?: string };
|
|
303
298
|
/**
|
|
304
299
|
* Your site ID (Studio's site slug): turns on hosted releases from
|
|
305
300
|
* `delivery.decocms.com`. Drafts don't need it.
|
|
@@ -371,6 +366,14 @@ export interface ClientOptions {
|
|
|
371
366
|
* the options below (`cms.readVersion(request)` reads all of them).
|
|
372
367
|
*/
|
|
373
368
|
version?: string | null;
|
|
369
|
+
/**
|
|
370
|
+
* For a draft: the release check made for this request
|
|
371
|
+
* (`cms.checkRelease()`), so the draft waits for it instead of making a
|
|
372
|
+
* check of its own; one request, one read of the release metadata. An id
|
|
373
|
+
* this CMS didn't make (another process's) is a check of its own. Ignored
|
|
374
|
+
* for the release and a release's SHA.
|
|
375
|
+
*/
|
|
376
|
+
releaseCheck?: string | null;
|
|
374
377
|
/**
|
|
375
378
|
* Who is visiting (`readVisitor`, `parseVisitor` or `newVisitor` from
|
|
376
379
|
* `@decocms/blocks/experiments`): the saved block `experiments` decides
|
|
@@ -412,6 +415,13 @@ export interface RequestVersion {
|
|
|
412
415
|
campaigns?: Assignments;
|
|
413
416
|
}
|
|
414
417
|
|
|
418
|
+
/**
|
|
419
|
+
* `cms.readVersion`'s and `cms.forDraft`'s options: the release check made
|
|
420
|
+
* for the request (`cms.checkRelease()`), so they share it instead of
|
|
421
|
+
* checking again.
|
|
422
|
+
*/
|
|
423
|
+
export type ReleaseCheckOptions = { releaseCheck?: string | null };
|
|
424
|
+
|
|
415
425
|
export interface CMS {
|
|
416
426
|
/**
|
|
417
427
|
* A client: the version it reads and the visitor it decides tests for, both
|
|
@@ -426,7 +436,22 @@ export interface CMS {
|
|
|
426
436
|
* default; `createCMS({ preview: { draftHosts } })` replaces the list) and
|
|
427
437
|
* laid over this server's production content.
|
|
428
438
|
*/
|
|
429
|
-
forDraft(pointer: string): Client;
|
|
439
|
+
forDraft(pointer: string, options?: ReleaseCheckOptions): Client;
|
|
440
|
+
/**
|
|
441
|
+
* Checks for the latest release now, as a draft read does before it
|
|
442
|
+
* renders, and resolves with that check's id once it ends; never rejects.
|
|
443
|
+
* A request arriving while a check runs waits for the next one, shared by
|
|
444
|
+
* every request arriving meanwhile; there is no time-based throttle. Pass
|
|
445
|
+
* the id as `releaseCheck` to `readVersion`, `forDraft` and `client` for
|
|
446
|
+
* the same request, so its host check, its draft reads and its render
|
|
447
|
+
* share one check: one read of `latest.json` per preview request. A
|
|
448
|
+
* binding (`@decocms/tanstack`'s worker, `@decocms/nextjs`'s proxy) makes
|
|
449
|
+
* one per draft request and hands it down. Given the id of a check this
|
|
450
|
+
* CMS made (one the proxy in front made for the same request), it waits
|
|
451
|
+
* for that check and resolves with the same id; an id it didn't make
|
|
452
|
+
* (another process's) is ignored, and it checks.
|
|
453
|
+
*/
|
|
454
|
+
checkRelease(releaseCheck?: string | null): Promise<string>;
|
|
430
455
|
/** Ask the content source for newer content now; never throws. */
|
|
431
456
|
update(): Promise<{ updated: boolean }>;
|
|
432
457
|
/**
|
|
@@ -453,8 +478,12 @@ export interface CMS {
|
|
|
453
478
|
* ```ts
|
|
454
479
|
* const client = cms.client({ visitor, ...(await cms.readVersion(request)) });
|
|
455
480
|
* ```
|
|
481
|
+
*
|
|
482
|
+
* With `releaseCheck` (the id `checkRelease()` resolved with for this
|
|
483
|
+
* request), the host check uses the preview hosts that check read instead
|
|
484
|
+
* of reading the release metadata again.
|
|
456
485
|
*/
|
|
457
|
-
readVersion(request: RequestLike): Promise<RequestVersion | null>;
|
|
486
|
+
readVersion(request: RequestLike, options?: ReleaseCheckOptions): Promise<RequestVersion | null>;
|
|
458
487
|
/** The version alone (`readVersion(request)`'s `version`), under its earlier name. */
|
|
459
488
|
draftPointer(request: RequestLike): Promise<string | null>;
|
|
460
489
|
/**
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The secret ciphertext format. The implementation is a dependency-free leaf
|
|
3
|
-
* module of the SDK (`src/v8/ciphertext.ts`), where the `secret` built-in
|
|
4
|
-
* decrypts it; the protocol re-exports it for its secret guard.
|
|
5
|
-
*/
|
|
6
|
-
export * from "../v8/ciphertext.ts";
|
|
7
|
-
//# sourceMappingURL=ciphertext.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ciphertext.d.ts","sourceRoot":"","sources":["../../src/protocol/ciphertext.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,cAAc,qBAAqB,CAAC"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The secret ciphertext format. The implementation is a dependency-free leaf
|
|
3
|
-
* module of the SDK (`src/v8/ciphertext.ts`), where the `secret` built-in
|
|
4
|
-
* decrypts it; the protocol re-exports it for its secret guard.
|
|
5
|
-
*/
|
|
6
|
-
export * from "../v8/ciphertext.js";
|
|
7
|
-
//# sourceMappingURL=ciphertext.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ciphertext.js","sourceRoot":"","sources":["../../src/protocol/ciphertext.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,cAAc,qBAAqB,CAAC"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { BlockViolation } from "./errors.ts";
|
|
2
|
-
import type { DecoMeta } from "./types.ts";
|
|
3
|
-
/** The built-in block type that holds an encrypted value. */
|
|
4
|
-
export declare const SECRET_BLOCK_TYPE = "secret";
|
|
5
|
-
/** The JSON Schema `format` that marks a `Secret` field. */
|
|
6
|
-
export declare const SECRET_FORMAT = "secret";
|
|
7
|
-
/**
|
|
8
|
-
* True when `ciphertext` is a well-formed secret ciphertext:
|
|
9
|
-
* `v1.<wrappedKey>.<iv>.<ciphertext>` with segment lengths an RSA-OAEP and
|
|
10
|
-
* AES-256-GCM encryption produces. Checking it needs no key.
|
|
11
|
-
*/
|
|
12
|
-
export declare function isWellFormedCiphertext(ciphertext: unknown): ciphertext is string;
|
|
13
|
-
/** True when a JSON Schema node describes a `Secret` field. */
|
|
14
|
-
export declare function isSecretFieldSchema(schema: unknown): boolean;
|
|
15
|
-
/** True when `value` is a `secret` block with a well-formed `ciphertext`. */
|
|
16
|
-
export declare function isSecretBlock(value: unknown): boolean;
|
|
17
|
-
/**
|
|
18
|
-
* Checks one entry against the secret guard. `meta` is the parsed schema;
|
|
19
|
-
* without one, only the `secret` blocks' ciphertexts can be checked.
|
|
20
|
-
*/
|
|
21
|
-
export declare function checkSecrets(name: string, entry: unknown, meta: DecoMeta | null): BlockViolation[];
|
|
22
|
-
//# sourceMappingURL=secrets.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"secrets.d.ts","sourceRoot":"","sources":["../../src/protocol/secrets.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C,6DAA6D;AAC7D,eAAO,MAAM,iBAAiB,WAAW,CAAC;AAE1C,4DAA4D;AAC5D,eAAO,MAAM,aAAa,WAAW,CAAC;AAsBtC;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,UAAU,EAAE,OAAO,GAAG,UAAU,IAAI,MAAM,CAEhF;AAED,+DAA+D;AAC/D,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAE5D;AAED,6EAA6E;AAC7E,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAIrD;AAmKD;;;GAGG;AACH,wBAAgB,YAAY,CAC1B,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,OAAO,EACd,IAAI,EAAE,QAAQ,GAAG,IAAI,GACpB,cAAc,EAAE,CAIlB"}
|