@decocms/blocks 8.1.0-next.5 → 8.1.0-next.6

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 (143) hide show
  1. package/dist/protocol/client.d.ts +0 -2
  2. package/dist/protocol/client.d.ts.map +1 -1
  3. package/dist/protocol/client.js +0 -2
  4. package/dist/protocol/client.js.map +1 -1
  5. package/dist/protocol/conformance/cases/guards.d.ts.map +1 -1
  6. package/dist/protocol/conformance/cases/guards.js +10 -173
  7. package/dist/protocol/conformance/cases/guards.js.map +1 -1
  8. package/dist/protocol/conformance/cases/reads.d.ts.map +1 -1
  9. package/dist/protocol/conformance/cases/reads.js +4 -49
  10. package/dist/protocol/conformance/cases/reads.js.map +1 -1
  11. package/dist/protocol/conformance/cases/writes.d.ts.map +1 -1
  12. package/dist/protocol/conformance/cases/writes.js +3 -21
  13. package/dist/protocol/conformance/cases/writes.js.map +1 -1
  14. package/dist/protocol/conformance/context.d.ts +1 -26
  15. package/dist/protocol/conformance/context.d.ts.map +1 -1
  16. package/dist/protocol/conformance/context.js +4 -13
  17. package/dist/protocol/conformance/context.js.map +1 -1
  18. package/dist/protocol/conformance/index.js +3 -3
  19. package/dist/protocol/errors.d.ts +5 -9
  20. package/dist/protocol/errors.d.ts.map +1 -1
  21. package/dist/protocol/errors.js +4 -4
  22. package/dist/protocol/errors.js.map +1 -1
  23. package/dist/protocol/index.d.ts +1 -1
  24. package/dist/protocol/index.d.ts.map +1 -1
  25. package/dist/protocol/index.js +1 -1
  26. package/dist/protocol/index.js.map +1 -1
  27. package/dist/protocol/params.d.ts.map +1 -1
  28. package/dist/protocol/params.js +0 -4
  29. package/dist/protocol/params.js.map +1 -1
  30. package/dist/protocol/server/assets.d.ts +2 -3
  31. package/dist/protocol/server/assets.d.ts.map +1 -1
  32. package/dist/protocol/server/assets.js +2 -9
  33. package/dist/protocol/server/assets.js.map +1 -1
  34. package/dist/protocol/server/content.d.ts +2 -3
  35. package/dist/protocol/server/content.d.ts.map +1 -1
  36. package/dist/protocol/server/content.js +10 -22
  37. package/dist/protocol/server/content.js.map +1 -1
  38. package/dist/protocol/server/core.d.ts +8 -11
  39. package/dist/protocol/server/core.d.ts.map +1 -1
  40. package/dist/protocol/server/core.js +8 -24
  41. package/dist/protocol/server/core.js.map +1 -1
  42. package/dist/protocol/server/handler.d.ts.map +1 -1
  43. package/dist/protocol/server/handler.js +11 -23
  44. package/dist/protocol/server/handler.js.map +1 -1
  45. package/dist/protocol/server/http.d.ts +6 -4
  46. package/dist/protocol/server/http.d.ts.map +1 -1
  47. package/dist/protocol/server/http.js +1 -18
  48. package/dist/protocol/server/http.js.map +1 -1
  49. package/dist/protocol/server/index.d.ts +0 -1
  50. package/dist/protocol/server/index.d.ts.map +1 -1
  51. package/dist/protocol/server/index.js.map +1 -1
  52. package/dist/protocol/server/methods/apply.d.ts +2 -2
  53. package/dist/protocol/server/methods/apply.d.ts.map +1 -1
  54. package/dist/protocol/server/methods/apply.js +23 -71
  55. package/dist/protocol/server/methods/apply.js.map +1 -1
  56. package/dist/protocol/server/methods/read.d.ts +0 -6
  57. package/dist/protocol/server/methods/read.d.ts.map +1 -1
  58. package/dist/protocol/server/methods/read.js +4 -31
  59. package/dist/protocol/server/methods/read.js.map +1 -1
  60. package/dist/protocol/server/rpc.d.ts +1 -1
  61. package/dist/protocol/server/rpc.d.ts.map +1 -1
  62. package/dist/protocol/server/rpc.js +9 -39
  63. package/dist/protocol/server/rpc.js.map +1 -1
  64. package/dist/protocol/storage/fs/index.d.ts +0 -3
  65. package/dist/protocol/storage/fs/index.d.ts.map +1 -1
  66. package/dist/protocol/storage/fs/index.js +0 -5
  67. package/dist/protocol/storage/fs/index.js.map +1 -1
  68. package/dist/protocol/storage/memory.d.ts +1 -6
  69. package/dist/protocol/storage/memory.d.ts.map +1 -1
  70. package/dist/protocol/storage/memory.js +1 -30
  71. package/dist/protocol/storage/memory.js.map +1 -1
  72. package/dist/protocol/storage.d.ts +7 -50
  73. package/dist/protocol/storage.d.ts.map +1 -1
  74. package/dist/protocol/storage.js +1 -1
  75. package/dist/protocol/storage.js.map +1 -1
  76. package/dist/protocol/types.d.ts +0 -34
  77. package/dist/protocol/types.d.ts.map +1 -1
  78. package/dist/protocol/types.js +0 -10
  79. package/dist/protocol/types.js.map +1 -1
  80. package/dist/v8/canonical.d.ts +0 -7
  81. package/dist/v8/canonical.d.ts.map +1 -1
  82. package/dist/v8/canonical.js +0 -9
  83. package/dist/v8/canonical.js.map +1 -1
  84. package/dist/v8/cms.d.ts.map +1 -1
  85. package/dist/v8/cms.js +2 -6
  86. package/dist/v8/cms.js.map +1 -1
  87. package/dist/v8/content.d.ts +2 -3
  88. package/dist/v8/content.d.ts.map +1 -1
  89. package/dist/v8/content.js +3 -3
  90. package/dist/v8/content.js.map +1 -1
  91. package/dist/v8/draft.d.ts +1 -1
  92. package/dist/v8/draft.js +2 -2
  93. package/dist/v8/draft.js.map +1 -1
  94. package/dist/v8/draftChanges.d.ts +23 -5
  95. package/dist/v8/draftChanges.d.ts.map +1 -1
  96. package/dist/v8/draftChanges.js +74 -19
  97. package/dist/v8/draftChanges.js.map +1 -1
  98. package/dist/v8/settings.d.ts +0 -7
  99. package/dist/v8/settings.d.ts.map +1 -1
  100. package/dist/v8/settings.js +0 -10
  101. package/dist/v8/settings.js.map +1 -1
  102. package/dist/v8/telemetry.d.ts +4 -0
  103. package/dist/v8/telemetry.d.ts.map +1 -1
  104. package/dist/v8/telemetry.js +49 -14
  105. package/dist/v8/telemetry.js.map +1 -1
  106. package/dist/v8/types.d.ts +4 -7
  107. package/dist/v8/types.d.ts.map +1 -1
  108. package/package.json +1 -1
  109. package/src/protocol/client.ts +0 -3
  110. package/src/protocol/conformance/cases/guards.ts +10 -188
  111. package/src/protocol/conformance/cases/reads.ts +7 -65
  112. package/src/protocol/conformance/cases/writes.ts +7 -36
  113. package/src/protocol/conformance/context.ts +6 -31
  114. package/src/protocol/conformance/index.ts +3 -3
  115. package/src/protocol/errors.ts +5 -10
  116. package/src/protocol/index.ts +0 -2
  117. package/src/protocol/params.ts +0 -4
  118. package/src/protocol/server/assets.ts +2 -12
  119. package/src/protocol/server/content.ts +10 -24
  120. package/src/protocol/server/core.ts +12 -34
  121. package/src/protocol/server/handler.ts +11 -30
  122. package/src/protocol/server/http.ts +1 -19
  123. package/src/protocol/server/index.ts +0 -1
  124. package/src/protocol/server/methods/apply.ts +22 -82
  125. package/src/protocol/server/methods/read.ts +4 -36
  126. package/src/protocol/server/rpc.ts +7 -47
  127. package/src/protocol/storage/fs/index.ts +0 -8
  128. package/src/protocol/storage/memory.ts +1 -36
  129. package/src/protocol/storage.ts +7 -39
  130. package/src/protocol/types.ts +0 -37
  131. package/src/v8/canonical.ts +0 -11
  132. package/src/v8/cms.ts +1 -6
  133. package/src/v8/content.ts +3 -4
  134. package/src/v8/draft.ts +2 -2
  135. package/src/v8/draftChanges.ts +81 -26
  136. package/src/v8/settings.ts +1 -15
  137. package/src/v8/telemetry.ts +58 -13
  138. package/src/v8/types.ts +4 -7
  139. package/dist/protocol/server/auth.d.ts +0 -31
  140. package/dist/protocol/server/auth.d.ts.map +0 -1
  141. package/dist/protocol/server/auth.js +0 -32
  142. package/dist/protocol/server/auth.js.map +0 -1
  143. package/src/protocol/server/auth.ts +0 -49
@@ -10,7 +10,7 @@
10
10
  *
11
11
  * Browser-safe: types and small error classes only.
12
12
  */
13
- import type { Limits, StorageKind } from "./types.ts";
13
+ import type { StorageKind } from "./types.ts";
14
14
 
15
15
  /** What a storage tells `describe`. */
16
16
  export interface StorageDescription {
@@ -18,19 +18,10 @@ export interface StorageDescription {
18
18
  /** The app root, relative to the repository root (`"."` when they're the same). */
19
19
  root: string;
20
20
  readOnly: boolean;
21
- /** Branch support; `null` when the storage has no refs (`ref` params are then Unsupported). */
22
- refs: null | { default: string; autoCreate: boolean };
23
21
  /** Where uploads go; `null` when read-only or uploads go elsewhere. */
24
22
  assets: null | { dir: string; maxBytes: number };
25
- /**
26
- * Durable request-key receipts. Advertise only when `getReceipt` is
27
- * implemented and `commit` persists `attempt.receipt` with the mutation.
28
- */
29
- idempotency: null | { retentionMs: number };
30
23
  /** Overrides the poll interval (default: 2000 for a working tree, 30000 for git). */
31
24
  pollIntervalMs?: number;
32
- /** Lowers the protocol's default limits. Higher values are ignored. */
33
- limits?: Partial<Limits>;
34
25
  }
35
26
 
36
27
  /** One saved-block file in a snapshot. */
@@ -47,7 +38,7 @@ export interface StorageFile {
47
38
  export interface StorageSnapshot {
48
39
  /** An opaque revision of the whole set, compared only for equality. */
49
40
  revision: string;
50
- /** The ref actually read (it can differ from the requested one); `null` without refs. */
41
+ /** The branch actually read, for a storage that reads one; `null` for a working tree. */
51
42
  resolvedRef: string | null;
52
43
  files: StorageFile[];
53
44
  }
@@ -72,21 +63,8 @@ export interface StoredSchema {
72
63
  resolvedRef: string | null;
73
64
  }
74
65
 
75
- /** A durable receipt for one `blocks.apply` request key. */
76
- export interface StoredReceipt {
77
- /** The canonical digest of the request the key was first used with. */
78
- digest: string;
79
- /** The revision that commit produced. */
80
- revision: string;
81
- /** The versions of the files that commit wrote. */
82
- versions: Record<string, string>;
83
- /** The files that commit deleted (`attempt.delete`), so a replay reports the same names. */
84
- deleted?: string[];
85
- }
86
-
87
66
  /** One atomic commit attempt. */
88
67
  export interface CommitAttempt {
89
- ref?: string;
90
68
  /** The snapshot the core validated against. */
91
69
  base: StorageSnapshot;
92
70
  /** Files to write, by file name, with their full content. */
@@ -101,19 +79,11 @@ export interface CommitAttempt {
101
79
  expected: Record<string, string | null>;
102
80
  /**
103
81
  * The schema version the core validated against (`null` = no schema), when
104
- * the write depends on it (`ifSchemaMatch`, or the secret guard). When set,
82
+ * the write depends on it (the secret guard checks `set` against it). When set,
105
83
  * a storage MUST reject the attempt as stale if the schema's version at
106
84
  * commit time differs, checked atomically with `expected`.
107
85
  */
108
86
  expectedSchemaVersion?: string | null;
109
- /**
110
- * Persist this receipt atomically with the mutation (only when idempotency
111
- * is advertised). The key also reserves the request: a storage MUST reject
112
- * the attempt as stale when a receipt for `receipt.key` already exists,
113
- * including one written concurrently by another replica, so two requests
114
- * with the same key never both commit.
115
- */
116
- receipt?: { key: string; digest: string };
117
87
  }
118
88
 
119
89
  export type CommitResult =
@@ -129,9 +99,9 @@ export interface ContentStorage {
129
99
  describe(): StorageDescription | Promise<StorageDescription>;
130
100
  /**
131
101
  * Lists the saved-block files. Throws `StorageNotFoundError` when there's no
132
- * `.deco` folder at all, or the ref can't be read.
102
+ * `.deco` folder at all.
133
103
  */
134
- snapshot(options: { ref?: string }): Promise<StorageSnapshot>;
104
+ snapshot(): Promise<StorageSnapshot>;
135
105
  /**
136
106
  * Reads file bodies (UTF-8 text) from a snapshot, each with the version of
137
107
  * the bytes read. A file that vanished is left out. A storage that can't
@@ -140,18 +110,16 @@ export interface ContentStorage {
140
110
  */
141
111
  readFiles(snapshot: StorageSnapshot, files: string[]): Promise<Record<string, StoredFileBody>>;
142
112
  /** Reads `schema.gen.json`, falling back to `meta.gen.json`; `null` when neither exists. */
143
- readSchema(options: { ref?: string }): Promise<StoredSchema | null>;
113
+ readSchema(): Promise<StoredSchema | null>;
144
114
  /** Reads `<root>/.deco/secrets.pub`; `null` without one. */
145
115
  readSecretsPublicKey(): Promise<string | null>;
146
116
  /** One all-or-nothing commit attempt; durable when it resolves. */
147
117
  commit(attempt: CommitAttempt): Promise<CommitResult>;
148
- /** Looks up a receipt by its scoped key; `null` when unknown or expired. */
149
- getReceipt?(key: string): Promise<StoredReceipt | null>;
150
118
  /** Stores an uploaded file, never overwriting one; returns the stored file name. */
151
119
  putAsset?(name: string, body: Uint8Array): Promise<{ name: string }>;
152
120
  }
153
121
 
154
- /** Thrown by a storage when there's no `.deco` folder, or a ref can't be read or created. */
122
+ /** Thrown by a storage when there's no `.deco` folder. */
155
123
  export class StorageNotFoundError extends Error {
156
124
  constructor(message: string) {
157
125
  super(message);
@@ -30,33 +30,6 @@ export const MAX_BATCH_CALLS = 10;
30
30
  /** The URL prefix every uploaded asset is stored under in a field. */
31
31
  export const ASSETS_URL_PREFIX = "/assets/";
32
32
 
33
- export interface Limits {
34
- /** Names (set plus delete) in one `blocks.apply`. */
35
- maxOpsPerApply: number;
36
- /** Bytes of one stored entry. */
37
- maxBlockBytes: number;
38
- /** Bytes of one HTTP request body, uncompressed. */
39
- maxRequestBytes: number;
40
- /** Uncompressed bytes of the whole block list. */
41
- maxListBytes: number;
42
- /** Uncompressed bytes of the schema. */
43
- maxSchemaBytes: number;
44
- /** Uncompressed bytes of a whole batch response. */
45
- maxBatchResponseBytes: number;
46
- }
47
-
48
- const MiB = 1024 * 1024;
49
-
50
- /** The protocol's default limits. A storage or a server can lower them. */
51
- export const DEFAULT_LIMITS: Readonly<Limits> = Object.freeze({
52
- maxOpsPerApply: 500,
53
- maxBlockBytes: 1 * MiB,
54
- maxRequestBytes: 8 * MiB,
55
- maxListBytes: 16 * MiB,
56
- maxSchemaBytes: 16 * MiB,
57
- maxBatchResponseBytes: 32 * MiB,
58
- });
59
-
60
33
  export type StorageKind = "working-tree" | "git";
61
34
 
62
35
  export interface DescribeResult {
@@ -69,12 +42,8 @@ export interface DescribeResult {
69
42
  /** The app root: the folder that contains `.deco/`, relative to the repository root. */
70
43
  root: string;
71
44
  schemaFormat: typeof SCHEMA_FORMAT;
72
- /** Branches; `null` on the local server. */
73
- refs: null | { default: string; autoCreate: boolean };
74
- writes: { idempotency: null | { retentionMs: number }; schemaPreconditions: boolean };
75
45
  /** Local: 2000; git: 30000, plus on window focus. */
76
46
  pollIntervalMs: number;
77
- limits: Limits;
78
47
  /**
79
48
  * The app the site editor shows in its Preview tab (and where "open the real
80
49
  * page" points); the local server reports `deco serve --preview`. `null`: no preview.
@@ -94,7 +63,6 @@ export interface DecoMeta {
94
63
  }
95
64
 
96
65
  export interface ReadParams {
97
- ref?: string;
98
66
  ifNoneMatch?: string;
99
67
  }
100
68
 
@@ -142,11 +110,6 @@ export type BlocksListResult =
142
110
  };
143
111
 
144
112
  export interface BlocksApplyParams {
145
- ref?: string;
146
- /** Retry the same logical write; only when advertised. */
147
- requestKey?: string;
148
- /** Reject if the schema changed; only when advertised. */
149
- ifSchemaMatch?: string;
150
113
  /** Whole-entry replace (create or update). */
151
114
  set?: Record<string, Record<string, unknown>>;
152
115
  /** A missing name counts as deleted. */
@@ -104,14 +104,3 @@ export const CONTENT_HASH_FORMAT = 1;
104
104
  export async function computeContentRevision(blocks: Record<string, unknown>): Promise<string> {
105
105
  return sha256Hex(canonicalJson(blocks));
106
106
  }
107
-
108
- /** The domain prefix of `blocks.apply` request digests, so they never equal another hash. */
109
- export const APPLY_DIGEST_DOMAIN = "deco-content/blocks.apply@1\n";
110
-
111
- /**
112
- * The digest a request key is bound to: SHA-256 over the domain prefix and
113
- * the canonical JSON of every supplied parameter.
114
- */
115
- export function applyRequestDigest(params: object): Promise<string> {
116
- return sha256Hex(APPLY_DIGEST_DOMAIN + canonicalJson(params));
117
- }
package/src/v8/cms.ts CHANGED
@@ -21,7 +21,6 @@ import {
21
21
  defaultSettings,
22
22
  isStatic,
23
23
  parseCodeHosts,
24
- parseCodeSources,
25
24
  readSettings,
26
25
  type SettingsCaps,
27
26
  } from "./settings.ts";
@@ -73,8 +72,6 @@ class CMSInstance {
73
72
  readonly #builtIns: Readonly<Blocks>;
74
73
  readonly #telemetry: TelemetryPipeline | undefined;
75
74
  readonly #caps: SettingsCaps;
76
- /** The hosts a draft pointer may name (`preview.sources`): code only, never content. */
77
- readonly #sources: readonly HostPattern[];
78
75
  /** Settings of a `CMS` block with nothing to run, per release snapshot. */
79
76
  #staticSettings = new WeakMap<Snapshot, EffectiveSettings>();
80
77
  /** The release and time telemetry last read its section. */
@@ -96,7 +93,6 @@ class CMSInstance {
96
93
  hosts: parseCodeHosts(config.preview),
97
94
  limits: telemetryLimits(config.telemetry),
98
95
  };
99
- this.#sources = parseCodeSources(config.preview);
100
96
  const destination = resolveDestination(config.telemetry, config.site);
101
97
  if (destination !== null) {
102
98
  this.#telemetry = new TelemetryPipeline(destination);
@@ -151,7 +147,7 @@ class CMSInstance {
151
147
  */
152
148
  forDraft(blocks: Blocks, pointer: string): Client {
153
149
  this.#scheduleUpdate();
154
- const load = () => this.#store.draft(pointer, this.#sources);
150
+ const load = () => this.#store.draft(pointer);
155
151
  const variants = parseDraftPointer(pointer)?.variants;
156
152
  if (variants === undefined) return this.#client(blocks, load);
157
153
  return this.#client(blocks, () => load().then((snapshot) => forceVariants(snapshot, variants)));
@@ -388,7 +384,6 @@ function validate(config: CMSConfig): void {
388
384
  );
389
385
  }
390
386
  parseCodeHosts(config.preview);
391
- parseCodeSources(config.preview);
392
387
  }
393
388
 
394
389
  function resolveInterval(configured: number | undefined): number {
package/src/v8/content.ts CHANGED
@@ -12,7 +12,6 @@
12
12
  import { formatDraftPointer, parseDraftPointer } from "./draft.ts";
13
13
  import { type DraftChanges, fetchDraftChanges, LOCAL_VERSION, layerDraft } from "./draftChanges.ts";
14
14
  import { errors, isResolutionError } from "./errors.ts";
15
- import type { HostPattern } from "./hosts.ts";
16
15
  import { isPlainObject } from "./json.ts";
17
16
  import type { Loader, Snapshot } from "./types.ts";
18
17
 
@@ -99,14 +98,14 @@ export class ContentStore {
99
98
  }
100
99
 
101
100
  /**
102
- * The draft a pointer names: its changes, fetched from a host in `sources`,
101
+ * The draft a pointer names: its changes, fetched from a preview API domain,
103
102
  * layered over the release. A pointer that doesn't parse, or any failure, is
104
103
  * `LOADER_FAILED`, never a silent fallback to the release. A pointer whose
105
104
  * version is `local` names no draft: the release, with nothing fetched. The
106
105
  * changes are keyed by the pointer without its `__variant` parameters (every
107
106
  * variant of one draft shares one fetch) and reused for a minute.
108
107
  */
109
- draft(pointer: string, sources: readonly HostPattern[]): Promise<Snapshot> {
108
+ draft(pointer: string): Promise<Snapshot> {
110
109
  const parsed = parseDraftPointer(pointer);
111
110
  if (parsed === null) {
112
111
  return Promise.reject(errors.loaderFailed(`invalid draft pointer "${truncate(pointer)}"`));
@@ -117,7 +116,7 @@ export class ContentStore {
117
116
  let entry = this.#drafts.get(key);
118
117
  if (entry === undefined || Date.now() - entry.at >= DRAFT_TTL_MS) {
119
118
  const fetched: CachedDraft = {
120
- changes: fetchDraftChanges(parsed, sources).catch((error: unknown) => {
119
+ changes: fetchDraftChanges(parsed).catch((error: unknown) => {
121
120
  throw errors.loaderFailed("the draft's changes couldn't be fetched", error);
122
121
  }),
123
122
  at: Date.now(),
package/src/v8/draft.ts CHANGED
@@ -12,7 +12,7 @@
12
12
  import type { DraftPointer, ForcedVariant, RequestLike } from "./types.ts";
13
13
 
14
14
  /** The draft cookie's name. Not exported from the package: reading it directly would skip the host check. */
15
- const DRAFT_COOKIE = "deco-draft";
15
+ const DRAFT_COOKIE = "__deco_draft";
16
16
 
17
17
  const DRAFT_PARAM = "__draft";
18
18
  const DRAFT_OFF = "off";
@@ -157,7 +157,7 @@ function normalizeIPv6Host(authority: string): string | null {
157
157
 
158
158
  /**
159
159
  * The draft pointer a request carries: `?__draft=` from the URL first, then
160
- * the `deco-draft` cookie. `null` when neither is present, or when the URL
160
+ * the `__deco_draft` cookie. `null` when neither is present, or when the URL
161
161
  * says `?__draft=off`. The value is returned as is; `cms.forDraft` validates it.
162
162
  */
163
163
  export function readDraftPointer(request: RequestLike): string | null {
@@ -2,10 +2,13 @@
2
2
  * Draft changes (see /next/content-delivery#draft-previews): what a draft
3
3
  * pointer's address answers, and how the CMS layers it over production.
4
4
  *
5
- * - The pointer's host must be one of `preview.sources` (code only, default
6
- * `studio.decocms.com`); any other host is refused before anything is fetched.
7
- * - `GET https://<host><path>&v=<version>`: plain `http` only for loopback
8
- * hosts. The pointer's `__variant` parameters are already gone (the parser
5
+ * - The pointer's host must fall under one of the preview API domains (the
6
+ * same rule as v7): by default `*.decocms.com` (Studio, its PR previews,
7
+ * `local.studio.decocms.com`) and the loopback hosts; `DECO_PREVIEW_API_DOMAINS`
8
+ * replaces the list. Any other host is refused before anything is fetched.
9
+ * - `GET <scheme>://<host><path>&v=<version>`: the scheme comes from the
10
+ * domain that admitted the host, never from the pointer: plain `http` only
11
+ * for loopback hosts. The pointer's `__variant` parameters are already gone (the parser
9
12
  * lifts them out), no cookies or credentials are sent, and redirects aren't
10
13
  * followed (a response that was redirected anyway is refused).
11
14
  * - Only a 200 is accepted, within 10 s and up to 16 MiB, shaped exactly
@@ -13,7 +16,7 @@
13
16
  * `set` and `delete` disjoint.
14
17
  */
15
18
  import { readBoundedJson, timeoutSignal } from "./boundedJson.ts";
16
- import { allowsHost, type HostPattern } from "./hosts.ts";
19
+ import { readEnv } from "./identity.ts";
17
20
  import { isPlainObject } from "./json.ts";
18
21
  import type { DraftPointer, Snapshot } from "./types.ts";
19
22
 
@@ -31,22 +34,80 @@ export interface DraftChanges {
31
34
  delete: string[];
32
35
  }
33
36
 
34
- /** The URL the SDK fetches for a pointer: the scheme from its host, the version as `v`. */
35
- export function draftChangesUrl(pointer: DraftPointer): string {
36
- const scheme = isLoopback(pointer.host) ? "http" : "https";
37
+ /**
38
+ * The domains a draft pointer's host may fall under, the defaults v7 shipped.
39
+ * Deco operates every one of them, so the defaults add no SSRF surface. An
40
+ * entry starting with a dot matches any host that ends with it, on a label
41
+ * boundary (`evil-decocms.com` doesn't pass `.decocms.com`); any other entry
42
+ * matches that exact host. The first entry that matches decides whether a
43
+ * port and plain `http` are allowed.
44
+ */
45
+ export const DEFAULT_PREVIEW_API_DOMAINS: readonly string[] = [
46
+ "local.studio.decocms.com", // the Studio dev origin (https, with a port)
47
+ "localhost",
48
+ "127.0.0.1",
49
+ ".localhost",
50
+ ".decocms.com", // Studio and its preview deployments
51
+ ];
52
+
53
+ /** `DECO_PREVIEW_API_DOMAINS` (a comma list) when set, else the defaults. */
54
+ function previewApiDomains(): readonly string[] {
55
+ const configured = (readEnv("DECO_PREVIEW_API_DOMAINS") ?? "")
56
+ .split(",")
57
+ .map((domain) => domain.trim().toLowerCase())
58
+ .filter(Boolean);
59
+ return configured.length > 0 ? configured : DEFAULT_PREVIEW_API_DOMAINS;
60
+ }
61
+
62
+ /**
63
+ * The origin a pointer's host is fetched from, or `null` when no preview API
64
+ * domain admits it. Loopback domains (and `local.studio.decocms.com`) may
65
+ * carry a port; a public domain may not, so a pointer can't aim the fetch at
66
+ * an odd port. Loopback hosts are `http`; everything else is `https`.
67
+ */
68
+ export function previewApiOrigin(authority: string): string | null {
69
+ const lower = authority.toLowerCase();
70
+ const end = lower.startsWith("[") ? lower.indexOf("]") + 1 : -1;
71
+ const host = end > 0 ? lower.slice(0, end) : lower.split(":")[0]!;
72
+ const rest = end > 0 ? lower.slice(end) : lower.slice(host.length);
73
+ const port = rest.startsWith(":") ? rest.slice(1) : undefined;
74
+ if (!host) return null;
75
+ const domain = previewApiDomains().find((d) =>
76
+ d.startsWith(".") ? host.length > d.length && host.endsWith(d) : host === d,
77
+ );
78
+ if (domain === undefined) return null;
79
+ const insecure = isLoopbackDomain(domain);
80
+ if (port !== undefined && !insecure && domain !== "local.studio.decocms.com") return null;
81
+ return `${insecure ? "http" : "https"}://${host}${port === undefined ? "" : `:${port}`}`;
82
+ }
83
+
84
+ function isLoopbackDomain(domain: string): boolean {
85
+ return (
86
+ domain === "localhost" ||
87
+ domain === "127.0.0.1" ||
88
+ domain === "[::1]" ||
89
+ domain.endsWith(".localhost")
90
+ );
91
+ }
92
+
93
+ /**
94
+ * The URL the SDK fetches for a pointer: the origin its host is admitted
95
+ * under, the version as `v`. `null` when no preview API domain admits the host.
96
+ */
97
+ export function draftChangesUrl(pointer: DraftPointer): string | null {
98
+ const origin = previewApiOrigin(pointer.host);
99
+ if (origin === null) return null;
37
100
  const separator = pointer.path.includes("?") ? "&" : "?";
38
- return `${scheme}://${pointer.host}${pointer.path}${separator}v=${encodeURIComponent(pointer.version)}`;
101
+ return `${origin}${pointer.path}${separator}v=${encodeURIComponent(pointer.version)}`;
39
102
  }
40
103
 
41
- /** Fetches a draft's changes; rejects on a host outside `sources` (without fetching) or on any failure. */
42
- export async function fetchDraftChanges(
43
- pointer: DraftPointer,
44
- sources: readonly HostPattern[],
45
- ): Promise<DraftChanges> {
104
+ /** Fetches a draft's changes; rejects on a host no preview API domain admits (without fetching) or on any failure. */
105
+ export async function fetchDraftChanges(pointer: DraftPointer): Promise<DraftChanges> {
46
106
  const url = draftChangesUrl(pointer);
47
- if (!allowsHost(sources, url)) {
107
+ if (url === null) {
48
108
  throw new Error(
49
- `draft pointer names "${pointer.host}", which isn't in preview.sources; nothing was fetched`,
109
+ `draft pointer names "${pointer.host}", which isn't under a preview API domain ` +
110
+ "(DECO_PREVIEW_API_DOMAINS); nothing was fetched",
50
111
  );
51
112
  }
52
113
  const response = await fetch(url, {
@@ -56,7 +117,10 @@ export async function fetchDraftChanges(
56
117
  });
57
118
  // Some fetch polyfills (React Native, whatwg-fetch) ignore `redirect: "manual"`
58
119
  // and follow anyway: refuse a response that came from anywhere else.
59
- if (response.redirected || (response.url && !allowsHost(sources, response.url))) {
120
+ if (
121
+ response.redirected ||
122
+ (response.url && new URL(response.url).origin !== new URL(url).origin)
123
+ ) {
60
124
  await response.body?.cancel();
61
125
  throw new Error("draft changes: the pointer's address redirected; nothing was read");
62
126
  }
@@ -106,12 +170,3 @@ export function layerDraft(base: Snapshot, changes: DraftChanges, version: strin
106
170
  if (base.aliases !== undefined) view.aliases = base.aliases;
107
171
  return view;
108
172
  }
109
-
110
- function isLoopback(authority: string): boolean {
111
- const host = authority.startsWith("[")
112
- ? authority.slice(0, authority.indexOf("]") + 1)
113
- : authority.split(":")[0]!;
114
- return (
115
- host === "localhost" || host.endsWith(".localhost") || host === "127.0.0.1" || host === "[::1]"
116
- );
117
- }
@@ -46,23 +46,9 @@ export function parseCodeHosts(preview: CMSConfig["preview"]): HostPattern[] | u
46
46
  return parseCodePatterns(preview, "hosts");
47
47
  }
48
48
 
49
- /** The hosts a draft pointer may name when code sets no `preview.sources`. */
50
- export const DEFAULT_SOURCES: readonly string[] = ["studio.decocms.com"];
51
-
52
- /**
53
- * Code's `preview.sources`, parsed, or the default (`studio.decocms.com`).
54
- * Throws a `TypeError` like {@link parseCodeHosts}.
55
- */
56
- export function parseCodeSources(preview: CMSConfig["preview"]): HostPattern[] {
57
- return (
58
- parseCodePatterns(preview, "sources") ??
59
- DEFAULT_SOURCES.map((raw) => parseHostPattern(raw) as HostPattern)
60
- );
61
- }
62
-
63
49
  function parseCodePatterns(
64
50
  preview: CMSConfig["preview"],
65
- field: "hosts" | "sources",
51
+ field: "hosts",
66
52
  ): HostPattern[] | undefined {
67
53
  if (preview === undefined || preview === null) return undefined;
68
54
  if (typeof preview !== "object") {
@@ -3,8 +3,10 @@
3
3
  * /next/telemetry and /next/telemetry-internals.
4
4
  *
5
5
  * - **Where** comes from code: `createCMS({ telemetry })`, or the standard
6
- * `OTEL_EXPORTER_OTLP_ENDPOINT`/`OTEL_EXPORTER_OTLP_HEADERS` when it's left
7
- * out. `false` sends nothing.
6
+ * `OTEL_EXPORTER_OTLP_ENDPOINT`/`OTEL_EXPORTER_OTLP_HEADERS` (and the
7
+ * per-signal `OTEL_EXPORTER_OTLP_{METRICS,LOGS,TRACES}_ENDPOINT`) when it's
8
+ * left out. v7's `DECO_OTEL_*` names are read as aliases; the standard name
9
+ * wins when both are set. `false` sends nothing.
8
10
  * - **How much** comes from content: the `telemetry` section of the CMS
9
11
  * settings (`cms.settings()`, the release's `CMS` block), capped by
10
12
  * `telemetry.limits`. The CMS reads it outside any request, when the
@@ -49,8 +51,13 @@ export function telemetryLimits(config: false | TelemetryConfig | undefined): {
49
51
 
50
52
  type Attributes = Record<string, string | number | boolean | undefined>;
51
53
 
54
+ type Signal = "metrics" | "logs" | "traces";
55
+
52
56
  interface Destination {
57
+ /** The base URL each signal's `/v1/<signal>` is appended to; `""` with per-signal URLs only. */
53
58
  endpoint: string;
59
+ /** Full per-signal URLs, used as they are (the `OTEL_EXPORTER_OTLP_<SIGNAL>_ENDPOINT` form). */
60
+ signals?: Partial<Record<Signal, string>>;
54
61
  headers: Record<string, string>;
55
62
  site?: string;
56
63
  limits: { errorSampleRate: number; traceSampleRate: number };
@@ -99,12 +106,7 @@ export function resolveDestination(
99
106
  site?: string,
100
107
  ): Destination | null {
101
108
  if (config === false) return null;
102
- if (config === undefined || config === null) {
103
- const endpoint = readEnv("OTEL_EXPORTER_OTLP_ENDPOINT");
104
- if (!endpoint) return null;
105
- const headers = parseKeyValues(readEnv("OTEL_EXPORTER_OTLP_HEADERS"));
106
- return { endpoint, headers, site, limits: DEFAULT_LIMITS };
107
- }
109
+ if (config === undefined || config === null) return destinationFromEnv(site);
108
110
  const limits = telemetryLimits(config);
109
111
  if ("endpoint" in config) {
110
112
  if (typeof config.endpoint !== "string" || !config.endpoint) return null;
@@ -119,6 +121,46 @@ export function resolveDestination(
119
121
  };
120
122
  }
121
123
 
124
+ /** v7's names for the standard OTLP variables, read when the standard one is unset. */
125
+ const V7_ALIASES = {
126
+ OTEL_EXPORTER_OTLP_HEADERS: "DECO_OTEL_HEADERS",
127
+ OTEL_EXPORTER_OTLP_METRICS_ENDPOINT: "DECO_OTEL_METRICS_ENDPOINT",
128
+ OTEL_EXPORTER_OTLP_LOGS_ENDPOINT: "DECO_OTEL_LOGS_ENDPOINT",
129
+ OTEL_EXPORTER_OTLP_TRACES_ENDPOINT: "DECO_OTEL_TRACES_ENDPOINT",
130
+ } as const;
131
+
132
+ /** The standard variable, else its v7 alias. */
133
+ function readOtlpEnv(name: keyof typeof V7_ALIASES | "OTEL_EXPORTER_OTLP_ENDPOINT") {
134
+ return (
135
+ readEnv(name) ||
136
+ (name in V7_ALIASES ? readEnv(V7_ALIASES[name as keyof typeof V7_ALIASES]) : undefined)
137
+ );
138
+ }
139
+
140
+ /**
141
+ * The destination the environment names: the standard OTLP variables, with
142
+ * v7's `DECO_OTEL_*` names as aliases. `DECO_OTEL_AUTH_TOKEN` (v7's secret
143
+ * for the collector) becomes the `authorization` header unless the headers
144
+ * set one. `null` when no endpoint is set.
145
+ */
146
+ function destinationFromEnv(site: string | undefined): Destination | null {
147
+ const endpoint = readOtlpEnv("OTEL_EXPORTER_OTLP_ENDPOINT") ?? "";
148
+ const signals: Partial<Record<Signal, string>> = {};
149
+ for (const signal of ["metrics", "logs", "traces"] as const) {
150
+ const url = readOtlpEnv(
151
+ `OTEL_EXPORTER_OTLP_${signal.toUpperCase() as Uppercase<Signal>}_ENDPOINT`,
152
+ );
153
+ if (url) signals[signal] = url;
154
+ }
155
+ if (!endpoint && Object.keys(signals).length === 0) return null;
156
+ const token = readEnv("DECO_OTEL_AUTH_TOKEN");
157
+ const headers = {
158
+ ...(token ? { authorization: token } : {}),
159
+ ...parseKeyValues(readOtlpEnv("OTEL_EXPORTER_OTLP_HEADERS")),
160
+ };
161
+ return { endpoint, signals, headers, site, limits: DEFAULT_LIMITS };
162
+ }
163
+
122
164
  export class TelemetryPipeline {
123
165
  readonly #destination: Destination;
124
166
  #settings: Required<Telemetry> = { ...TELEMETRY_DEFAULTS };
@@ -273,7 +315,7 @@ export class TelemetryPipeline {
273
315
  const byName = new Map<string, Histogram[]>();
274
316
  for (const h of histograms) byName.set(h.name, [...(byName.get(h.name) ?? []), h]);
275
317
  sends.push(
276
- this.#send("/v1/metrics", {
318
+ this.#send("metrics", {
277
319
  resourceMetrics: [
278
320
  {
279
321
  resource,
@@ -307,7 +349,7 @@ export class TelemetryPipeline {
307
349
  }
308
350
  if (logs.length > 0) {
309
351
  sends.push(
310
- this.#send("/v1/logs", {
352
+ this.#send("logs", {
311
353
  resourceLogs: [
312
354
  {
313
355
  resource,
@@ -331,7 +373,7 @@ export class TelemetryPipeline {
331
373
  if (spans.length > 0) {
332
374
  const kinds = { internal: 1, server: 2, client: 3 };
333
375
  sends.push(
334
- this.#send("/v1/traces", {
376
+ this.#send("traces", {
335
377
  resourceSpans: [
336
378
  {
337
379
  resource,
@@ -401,8 +443,11 @@ export class TelemetryPipeline {
401
443
  };
402
444
  }
403
445
 
404
- async #send(path: string, payload: unknown): Promise<void> {
405
- const url = this.#destination.endpoint.replace(/\/+$/, "") + path;
446
+ async #send(signal: Signal, payload: unknown): Promise<void> {
447
+ const { endpoint, signals } = this.#destination;
448
+ const url =
449
+ signals?.[signal] ?? (endpoint ? `${endpoint.replace(/\/+$/, "")}/v1/${signal}` : "");
450
+ if (!url) return; // this signal has no destination
406
451
  const { body, gzipped } = await gzip(JSON.stringify(payload));
407
452
  const headers: Record<string, string> = {
408
453
  ...this.#destination.headers,
package/src/v8/types.ts CHANGED
@@ -234,11 +234,6 @@ export interface CMSConfig {
234
234
  * (/next/api-reference#host-patterns). Without it, content may allow any host.
235
235
  */
236
236
  hosts?: string[];
237
- /**
238
- * The hosts a draft pointer may name, in the host pattern format; code
239
- * only, never content. Default `["studio.decocms.com"]`.
240
- */
241
- sources?: string[];
242
237
  };
243
238
  /** The private key that decrypts `secret` blocks. */
244
239
  secrets?: { key?: string };
@@ -285,7 +280,9 @@ export interface CMS {
285
280
  forRelease(): Client;
286
281
  /**
287
282
  * A client reading the draft a pointer names: its changes, fetched from a
288
- * host in `preview.sources`, over this server's production content.
283
+ * preview API domain (`*.decocms.com` and loopback by default;
284
+ * `DECO_PREVIEW_API_DOMAINS` replaces the list), over this server's
285
+ * production content.
289
286
  */
290
287
  forDraft(pointer: string): Client;
291
288
  /** A client pinned to a revision this CMS has served; an unknown revision behaves like the release. */
@@ -299,7 +296,7 @@ export interface CMS {
299
296
  */
300
297
  settings(): Promise<EffectiveSettings>;
301
298
  /**
302
- * The request's draft pointer: `?__draft=` first, then the `deco-draft`
299
+ * The request's draft pointer: `?__draft=` first, then the `__deco_draft`
303
300
  * cookie. `null` when neither is present, for `?__draft=off`, and on a host
304
301
  * outside `settings().preview.hosts`, where the request gets the release.
305
302
  */
@@ -1,31 +0,0 @@
1
- /**
2
- * What an `authorize` hook decides:
3
- * - `true` or `{ scope }` — allowed. `scope` names the tenant and principal,
4
- * and scopes request-key receipts, so one tenant never replays another's.
5
- * - `false` or `"unauthorized"` — a missing or invalid bearer token (HTTP 401).
6
- * - `"forbidden"` — authenticated, but not allowed for this project.
7
- */
8
- export type AuthorizeResult = boolean | "unauthorized" | "forbidden" | {
9
- scope?: string;
10
- };
11
- export interface AuthOptions {
12
- /** When set, every request must carry `Authorization: Bearer <token>`. */
13
- token?: string;
14
- /** Decides whether a request may proceed (runs after the token check). */
15
- authorize?: (request: Request) => AuthorizeResult | Promise<AuthorizeResult>;
16
- }
17
- /**
18
- * Refuses options that would lock every client out by accident: an empty
19
- * token can never be presented, so every request would be 401.
20
- */
21
- export declare function assertAuthOptions(options: AuthOptions): void;
22
- type AuthOutcome = {
23
- ok: true;
24
- scope: string;
25
- } | {
26
- ok: false;
27
- reason: "unauthorized" | "forbidden";
28
- };
29
- export declare function authenticate(request: Request, options: AuthOptions): Promise<AuthOutcome>;
30
- export {};
31
- //# sourceMappingURL=auth.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../../src/protocol/server/auth.ts"],"names":[],"mappings":"AAKA;;;;;;GAMG;AACH,MAAM,MAAM,eAAe,GAAG,OAAO,GAAG,cAAc,GAAG,WAAW,GAAG;IAAE,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAE1F,MAAM,WAAW,WAAW;IAC1B,0EAA0E;IAC1E,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,0EAA0E;IAC1E,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,eAAe,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;CAC9E;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI,CAI5D;AAED,KAAK,WAAW,GACZ;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAC3B;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,cAAc,GAAG,WAAW,CAAA;CAAE,CAAC;AAExD,wBAAsB,YAAY,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,CAa/F"}