@decocms/blocks 8.1.0-next.4 → 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 (178) hide show
  1. package/dist/protocol/client.d.ts +1 -3
  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 +24 -53
  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 -20
  13. package/dist/protocol/conformance/cases/writes.js.map +1 -1
  14. package/dist/protocol/conformance/contentHashFixtures.d.ts +0 -29
  15. package/dist/protocol/conformance/contentHashFixtures.d.ts.map +1 -1
  16. package/dist/protocol/conformance/contentHashFixtures.js +0 -30
  17. package/dist/protocol/conformance/contentHashFixtures.js.map +1 -1
  18. package/dist/protocol/conformance/context.d.ts +4 -29
  19. package/dist/protocol/conformance/context.d.ts.map +1 -1
  20. package/dist/protocol/conformance/context.js +4 -13
  21. package/dist/protocol/conformance/context.js.map +1 -1
  22. package/dist/protocol/conformance/index.d.ts +1 -1
  23. package/dist/protocol/conformance/index.d.ts.map +1 -1
  24. package/dist/protocol/conformance/index.js +4 -4
  25. package/dist/protocol/conformance/index.js.map +1 -1
  26. package/dist/protocol/errors.d.ts +5 -9
  27. package/dist/protocol/errors.d.ts.map +1 -1
  28. package/dist/protocol/errors.js +4 -4
  29. package/dist/protocol/errors.js.map +1 -1
  30. package/dist/protocol/index.d.ts +3 -5
  31. package/dist/protocol/index.d.ts.map +1 -1
  32. package/dist/protocol/index.js +3 -5
  33. package/dist/protocol/index.js.map +1 -1
  34. package/dist/protocol/params.d.ts.map +1 -1
  35. package/dist/protocol/params.js +0 -4
  36. package/dist/protocol/params.js.map +1 -1
  37. package/dist/protocol/server/assets.d.ts +2 -3
  38. package/dist/protocol/server/assets.d.ts.map +1 -1
  39. package/dist/protocol/server/assets.js +2 -9
  40. package/dist/protocol/server/assets.js.map +1 -1
  41. package/dist/protocol/server/content.d.ts +2 -3
  42. package/dist/protocol/server/content.d.ts.map +1 -1
  43. package/dist/protocol/server/content.js +10 -22
  44. package/dist/protocol/server/content.js.map +1 -1
  45. package/dist/protocol/server/core.d.ts +8 -11
  46. package/dist/protocol/server/core.d.ts.map +1 -1
  47. package/dist/protocol/server/core.js +8 -24
  48. package/dist/protocol/server/core.js.map +1 -1
  49. package/dist/protocol/server/handler.d.ts.map +1 -1
  50. package/dist/protocol/server/handler.js +11 -23
  51. package/dist/protocol/server/handler.js.map +1 -1
  52. package/dist/protocol/server/http.d.ts +6 -4
  53. package/dist/protocol/server/http.d.ts.map +1 -1
  54. package/dist/protocol/server/http.js +1 -18
  55. package/dist/protocol/server/http.js.map +1 -1
  56. package/dist/protocol/server/index.d.ts +0 -1
  57. package/dist/protocol/server/index.d.ts.map +1 -1
  58. package/dist/protocol/server/index.js.map +1 -1
  59. package/dist/protocol/server/methods/apply.d.ts +2 -2
  60. package/dist/protocol/server/methods/apply.d.ts.map +1 -1
  61. package/dist/protocol/server/methods/apply.js +23 -71
  62. package/dist/protocol/server/methods/apply.js.map +1 -1
  63. package/dist/protocol/server/methods/read.d.ts +0 -6
  64. package/dist/protocol/server/methods/read.d.ts.map +1 -1
  65. package/dist/protocol/server/methods/read.js +7 -31
  66. package/dist/protocol/server/methods/read.js.map +1 -1
  67. package/dist/protocol/server/rpc.d.ts +1 -1
  68. package/dist/protocol/server/rpc.d.ts.map +1 -1
  69. package/dist/protocol/server/rpc.js +9 -39
  70. package/dist/protocol/server/rpc.js.map +1 -1
  71. package/dist/protocol/storage/fs/index.d.ts +0 -3
  72. package/dist/protocol/storage/fs/index.d.ts.map +1 -1
  73. package/dist/protocol/storage/fs/index.js +0 -5
  74. package/dist/protocol/storage/fs/index.js.map +1 -1
  75. package/dist/protocol/storage/memory.d.ts +1 -6
  76. package/dist/protocol/storage/memory.d.ts.map +1 -1
  77. package/dist/protocol/storage/memory.js +1 -30
  78. package/dist/protocol/storage/memory.js.map +1 -1
  79. package/dist/protocol/storage.d.ts +7 -50
  80. package/dist/protocol/storage.d.ts.map +1 -1
  81. package/dist/protocol/storage.js +1 -1
  82. package/dist/protocol/storage.js.map +1 -1
  83. package/dist/protocol/types.d.ts +23 -34
  84. package/dist/protocol/types.d.ts.map +1 -1
  85. package/dist/protocol/types.js +10 -10
  86. package/dist/protocol/types.js.map +1 -1
  87. package/dist/v8/boundedJson.d.ts +11 -0
  88. package/dist/v8/boundedJson.d.ts.map +1 -0
  89. package/dist/v8/boundedJson.js +44 -0
  90. package/dist/v8/boundedJson.js.map +1 -0
  91. package/dist/v8/canonical.d.ts +0 -35
  92. package/dist/v8/canonical.d.ts.map +1 -1
  93. package/dist/v8/canonical.js +0 -28
  94. package/dist/v8/canonical.js.map +1 -1
  95. package/dist/v8/cli/check/index.d.ts +5 -0
  96. package/dist/v8/cli/check/index.d.ts.map +1 -1
  97. package/dist/v8/cli/check/index.js +21 -1
  98. package/dist/v8/cli/check/index.js.map +1 -1
  99. package/dist/v8/cli/run.js +1 -1
  100. package/dist/v8/cli/schema/generate.d.ts +3 -1
  101. package/dist/v8/cli/schema/generate.d.ts.map +1 -1
  102. package/dist/v8/cli/schema/generate.js +2 -1
  103. package/dist/v8/cli/schema/generate.js.map +1 -1
  104. package/dist/v8/cli/serve/server.d.ts +1 -1
  105. package/dist/v8/cli/serve/server.d.ts.map +1 -1
  106. package/dist/v8/cli/serve/server.js +63 -23
  107. package/dist/v8/cli/serve/server.js.map +1 -1
  108. package/dist/v8/cms.d.ts.map +1 -1
  109. package/dist/v8/cms.js +7 -6
  110. package/dist/v8/cms.js.map +1 -1
  111. package/dist/v8/content.d.ts +6 -5
  112. package/dist/v8/content.d.ts.map +1 -1
  113. package/dist/v8/content.js +49 -39
  114. package/dist/v8/content.js.map +1 -1
  115. package/dist/v8/draft.d.ts +1 -1
  116. package/dist/v8/draft.d.ts.map +1 -1
  117. package/dist/v8/draft.js +24 -2
  118. package/dist/v8/draft.js.map +1 -1
  119. package/dist/v8/draftChanges.d.ts +44 -0
  120. package/dist/v8/draftChanges.d.ts.map +1 -0
  121. package/dist/v8/draftChanges.js +157 -0
  122. package/dist/v8/draftChanges.js.map +1 -0
  123. package/dist/v8/remoteLoader.d.ts +1 -1
  124. package/dist/v8/remoteLoader.d.ts.map +1 -1
  125. package/dist/v8/remoteLoader.js +19 -256
  126. package/dist/v8/remoteLoader.js.map +1 -1
  127. package/dist/v8/settings.d.ts.map +1 -1
  128. package/dist/v8/settings.js +9 -6
  129. package/dist/v8/settings.js.map +1 -1
  130. package/dist/v8/telemetry.d.ts +4 -0
  131. package/dist/v8/telemetry.d.ts.map +1 -1
  132. package/dist/v8/telemetry.js +49 -14
  133. package/dist/v8/telemetry.js.map +1 -1
  134. package/dist/v8/types.d.ts +20 -12
  135. package/dist/v8/types.d.ts.map +1 -1
  136. package/package.json +1 -1
  137. package/src/protocol/client.ts +1 -4
  138. package/src/protocol/conformance/cases/guards.ts +10 -188
  139. package/src/protocol/conformance/cases/reads.ts +29 -69
  140. package/src/protocol/conformance/cases/writes.ts +7 -35
  141. package/src/protocol/conformance/contentHashFixtures.ts +0 -57
  142. package/src/protocol/conformance/context.ts +9 -34
  143. package/src/protocol/conformance/index.ts +4 -9
  144. package/src/protocol/errors.ts +5 -10
  145. package/src/protocol/index.ts +2 -10
  146. package/src/protocol/params.ts +0 -4
  147. package/src/protocol/server/assets.ts +2 -12
  148. package/src/protocol/server/content.ts +10 -24
  149. package/src/protocol/server/core.ts +12 -34
  150. package/src/protocol/server/handler.ts +11 -30
  151. package/src/protocol/server/http.ts +1 -19
  152. package/src/protocol/server/index.ts +0 -1
  153. package/src/protocol/server/methods/apply.ts +22 -82
  154. package/src/protocol/server/methods/read.ts +7 -36
  155. package/src/protocol/server/rpc.ts +7 -47
  156. package/src/protocol/storage/fs/index.ts +0 -8
  157. package/src/protocol/storage/memory.ts +1 -36
  158. package/src/protocol/storage.ts +7 -39
  159. package/src/protocol/types.ts +21 -38
  160. package/src/v8/boundedJson.ts +47 -0
  161. package/src/v8/canonical.ts +0 -47
  162. package/src/v8/cli/check/index.ts +25 -1
  163. package/src/v8/cli/run.ts +1 -1
  164. package/src/v8/cli/schema/generate.ts +4 -1
  165. package/src/v8/cli/serve/server.ts +65 -29
  166. package/src/v8/cms.ts +7 -8
  167. package/src/v8/content.ts +55 -42
  168. package/src/v8/draft.ts +20 -2
  169. package/src/v8/draftChanges.ts +172 -0
  170. package/src/v8/remoteLoader.ts +23 -289
  171. package/src/v8/settings.ts +13 -6
  172. package/src/v8/telemetry.ts +58 -13
  173. package/src/v8/types.ts +23 -13
  174. package/dist/protocol/server/auth.d.ts +0 -31
  175. package/dist/protocol/server/auth.d.ts.map +0 -1
  176. package/dist/protocol/server/auth.js +0 -32
  177. package/dist/protocol/server/auth.js.map +0 -1
  178. package/src/protocol/server/auth.ts +0 -49
@@ -273,47 +273,19 @@ export const writeCases: ConformanceCase[] = [
273
273
  assert(!(from in after.blocks) && to in after.blocks, "the entry moved");
274
274
  },
275
275
  },
276
- {
277
- id: "apply/schema-precondition",
278
- title: "ifSchemaMatch rejects a write when the schema changed",
279
- async run(ctx) {
280
- const d = await writable(ctx);
281
- const name = ctx.name("schema-guarded");
282
- if (!d.writes.schemaPreconditions) {
283
- await expectError(
284
- ctx.client.blocksApply({ set: { [name]: {} }, ifSchemaMatch: "x" }),
285
- ErrorCode.Unsupported,
286
- "an unadvertised guard",
287
- );
288
- return;
289
- }
290
- if (ctx.options.hasSchema === false) return ctx.skip("no schema");
291
- const { version } = await ctx.client.schemaGet();
292
- const error = await expectError(
293
- ctx.client.blocksApply({ set: { [name]: {} }, ifSchemaMatch: `${version}-old` }),
294
- ErrorCode.Conflict,
295
- "a stale schema version",
296
- );
297
- assertEqual(
298
- (error.data as { schema?: unknown }).schema,
299
- { expected: `${version}-old`, actual: version },
300
- "the conflict's schema versions",
301
- );
302
- assert(!(name in (await list(ctx)).blocks), "nothing was written");
303
- await ctx.client.blocksApply({ set: { [name]: {} }, ifSchemaMatch: version });
304
- },
305
- },
306
276
  {
307
277
  id: "apply/unknown-params",
308
278
  title: "an unknown parameter is refused, so an unknown guard never becomes an unguarded write",
309
279
  async run(ctx) {
310
280
  await writable(ctx);
311
281
  const name = ctx.name("unknown-param");
312
- await expectError(
313
- ctx.client.call("blocks.apply", { set: { [name]: {} }, ifUnmodifiedSince: "x" } as never),
314
- ErrorCode.InvalidParams,
315
- "an unknown guard",
316
- );
282
+ for (const param of ["ifUnmodifiedSince", "ifSchemaMatch", "requestKey", "ref"]) {
283
+ await expectError(
284
+ ctx.client.call("blocks.apply", { set: { [name]: {} }, [param]: "x" } as never),
285
+ ErrorCode.InvalidParams,
286
+ `the unknown parameter ${param}`,
287
+ );
288
+ }
317
289
  assert(!(name in (await list(ctx)).blocks), "nothing was written");
318
290
  },
319
291
  },
@@ -77,60 +77,3 @@ export const contentHashFixtures: readonly ContentHashFixture[] = [
77
77
  revision: "6913c5e6aa28f441d3b0102177b372e4fb7c08bc09bdd8698df85e597282ac96",
78
78
  },
79
79
  ];
80
-
81
- /**
82
- * Golden fixtures for draft overlays (see /next/content-delivery#exact-draft-previews):
83
- * whatever prepares draft assets must produce these block hashes and overlay
84
- * versions, which the SDK checks on every asset it downloads.
85
- *
86
- * ```ts
87
- * import { draftOverlayFixtures } from "@decocms/blocks/protocol/conformance";
88
- * for (const f of draftOverlayFixtures) expect(await myOverlayVersion(f.overlay)).toBe(f.version);
89
- * ```
90
- */
91
- export interface DraftOverlayFixture {
92
- id: string;
93
- title: string;
94
- /** The changed entries, by name: each is stored under its block hash. */
95
- blocks: Record<string, unknown>;
96
- /** Each changed entry's block hash: SHA-256 of its canonical JSON. */
97
- hashes: Record<string, string>;
98
- /** The manifest. */
99
- overlay: { format: 1; set: Record<string, string>; delete: string[] };
100
- /** Its canonical JSON. */
101
- canonical: string;
102
- /** The overlay version: SHA-256 of the canonical manifest. */
103
- version: string;
104
- }
105
-
106
- export const draftOverlayFixtures: readonly DraftOverlayFixture[] = [
107
- {
108
- id: "empty",
109
- title: "a draft with no changes",
110
- blocks: {},
111
- hashes: {},
112
- overlay: { format: 1, set: {}, delete: [] },
113
- canonical: '{"delete":[],"format":1,"set":{}}',
114
- version: "8e740552419ba3858a3be4a30165178ab034372f8718e34d076518325bab75e4",
115
- },
116
- {
117
- id: "set-and-delete",
118
- title: "one replacement and one tombstone (the docs' example)",
119
- blocks: {
120
- HomeHero: {
121
- __resolveType: "hero",
122
- title: "Summer sale",
123
- image: { src: "/s.png", width: 1200 },
124
- },
125
- },
126
- hashes: { HomeHero: "81213bc231ca93365b7c45d26265c21814fc0a359b1c44078e36ecdcf895fd80" },
127
- overlay: {
128
- format: 1,
129
- set: { HomeHero: "81213bc231ca93365b7c45d26265c21814fc0a359b1c44078e36ecdcf895fd80" },
130
- delete: ["OldPromotion"],
131
- },
132
- canonical:
133
- '{"delete":["OldPromotion"],"format":1,"set":{"HomeHero":"81213bc231ca93365b7c45d26265c21814fc0a359b1c44078e36ecdcf895fd80"}}',
134
- version: "91a60f71f78b5cc373c2995b479fbc2c8932970d4f3ff2bec0404a573d1c440f",
135
- },
136
- ];
@@ -7,12 +7,13 @@ import { type ContentClient, createContentClient, readResponseJson } from "../cl
7
7
  import { ContentProtocolError } from "../errors.ts";
8
8
  import type { DescribeResult } from "../types.ts";
9
9
 
10
+ /** Names deleted per `blocks.apply` when a case cleans up. */
11
+ const CLEANUP_CHUNK = 100;
12
+
10
13
  export interface ConformanceOptions {
11
- /** The endpoint URL, such as `http://127.0.0.1:4545/rpc`. */
14
+ /** The endpoint URL, such as `http://localhost:4545/rpc`. */
12
15
  endpoint: string | URL;
13
- /** The bearer token the endpoint expects, if any. */
14
- token?: string;
15
- /** Extra headers on every request (an auth cookie, a tenant header). */
16
+ /** Extra headers on every request (such as the host's auth cookie). */
16
17
  headers?: Record<string, string>;
17
18
  /** A fetch implementation (defaults to the global one); use it to call a handler in process. */
18
19
  fetch?: (request: Request) => Promise<Response>;
@@ -23,28 +24,13 @@ export interface ConformanceOptions {
23
24
  secretField?: { blockType: string; field: string };
24
25
  /** The `.deco/secrets.pub` content the endpoint should report, if the harness wrote one. */
25
26
  secretsPublicKey?: string;
26
- /** Whether the endpoint has a schema (default true). `false` checks NotFound instead. */
27
+ /** Whether the endpoint has a schema (default true). `false` checks the `schema: null` result instead. */
27
28
  hasSchema?: boolean;
28
- /**
29
- * The endpoint serves a schema larger than its `limits.maxSchemaBytes`, so
30
- * reading it and writes that depend on it must be LimitExceeded. Run such
31
- * an endpoint with only the `limits/schema-bytes` case (pass a filter to
32
- * `runConformance` or `defineConformanceSuite`): every other case expects
33
- * a schema it can read.
34
- */
35
- schemaOverLimit?: boolean;
36
29
  /**
37
30
  * The URL prefix uploads are served under (`PUT <assetsEndpoint><name>`),
38
- * such as `http://127.0.0.1:4545/assets/`. Leave out to skip the upload cases.
31
+ * such as `http://localhost:4545/assets/`. Leave out to skip the upload cases.
39
32
  */
40
33
  assetsEndpoint?: string | URL;
41
- /**
42
- * Restarts the server, keeping its durable state, to check that request-key
43
- * receipts survive a restart. Leave out to skip that case.
44
- */
45
- restart?: () => Promise<void>;
46
- /** Credentials of another tenant on the same storage, to check receipt isolation. */
47
- otherTenant?: { token?: string; headers?: Record<string, string> };
48
34
  /** Prefix of every name the suite creates (default `conformance-<random>`). */
49
35
  namePrefix?: string;
50
36
  }
@@ -83,11 +69,6 @@ export class ConformanceContext {
83
69
  this.client = createContentClient(options);
84
70
  }
85
71
 
86
- /** A client with other credentials (for tenant isolation). */
87
- clientFor(credentials: { token?: string; headers?: Record<string, string> }): ContentClient {
88
- return createContentClient({ ...this.options, ...credentials });
89
- }
90
-
91
72
  async describe(): Promise<DescribeResult> {
92
73
  this.describeResult ??= await this.client.describe();
93
74
  return this.describeResult;
@@ -112,10 +93,8 @@ export class ConformanceContext {
112
93
  this.created.clear();
113
94
  const description = await this.describe();
114
95
  if (description.readOnly) return;
115
- for (let i = 0; i < names.length; i += description.limits.maxOpsPerApply) {
116
- await this.client
117
- .blocksApply({ delete: names.slice(i, i + description.limits.maxOpsPerApply) })
118
- .catch(() => {});
96
+ for (let i = 0; i < names.length; i += CLEANUP_CHUNK) {
97
+ await this.client.blocksApply({ delete: names.slice(i, i + CLEANUP_CHUNK) }).catch(() => {});
119
98
  }
120
99
  }
121
100
 
@@ -133,9 +112,6 @@ export class ConformanceContext {
133
112
  ...this.options.headers,
134
113
  ...init.headers,
135
114
  };
136
- if (this.options.token !== undefined && !("authorization" in headers)) {
137
- headers.authorization = `Bearer ${this.options.token}`;
138
- }
139
115
  for (const [key, value] of Object.entries(headers)) if (value === "") delete headers[key];
140
116
  const method = init.method ?? "POST";
141
117
  const doFetch = this.options.fetch ?? ((request: Request) => fetch(request));
@@ -163,7 +139,6 @@ export class ConformanceContext {
163
139
  ...this.options.headers,
164
140
  "content-type": contentType,
165
141
  };
166
- if (this.options.token !== undefined) headers.authorization = `Bearer ${this.options.token}`;
167
142
  const doFetch = this.options.fetch ?? ((request: Request) => fetch(request));
168
143
  const url = new URL(encodeURIComponent(name), new URL(String(base)).href.replace(/\/?$/, "/"));
169
144
  const response = await doFetch(
@@ -10,14 +10,14 @@
10
10
  * import { describe, it } from "vitest";
11
11
  * import { defineConformanceSuite } from "@decocms/blocks/protocol/conformance";
12
12
  *
13
- * defineConformanceSuite({ describe, it }, { endpoint: "http://127.0.0.1:4545/rpc", token });
13
+ * defineConformanceSuite({ describe, it }, { endpoint: "http://localhost:4545/rpc" });
14
14
  * ```
15
15
  *
16
16
  * or collect a report with `runConformance(options)`. The suite writes only
17
17
  * names under its own prefix and deletes them after each case (uploads, which
18
18
  * the protocol can't delete, stay in the asset folder). Cases that
19
- * don't apply to an endpoint (a read-only one, one without request keys)
20
- * skip themselves. Browser-safe: it only needs `fetch`.
19
+ * don't apply to an endpoint (a read-only one, one without a schema) skip
20
+ * themselves. Browser-safe: it only needs `fetch`.
21
21
  */
22
22
  import { assetCases } from "./cases/assets.ts";
23
23
  import { guardCases } from "./cases/guards.ts";
@@ -28,12 +28,7 @@ import { writeCases } from "./cases/writes.ts";
28
28
  import { ConformanceContext, type ConformanceOptions, SkipCase } from "./context.ts";
29
29
 
30
30
  export type { ConformanceCase } from "./cases/types.ts";
31
- export {
32
- type ContentHashFixture,
33
- contentHashFixtures,
34
- type DraftOverlayFixture,
35
- draftOverlayFixtures,
36
- } from "./contentHashFixtures.ts";
31
+ export { type ContentHashFixture, contentHashFixtures } from "./contentHashFixtures.ts";
37
32
  export type { ConformanceOptions } from "./context.ts";
38
33
 
39
34
  /** Every conformance case, in the order they run. */
@@ -1,7 +1,9 @@
1
1
  /**
2
2
  * Content-protocol errors. Every failure travels as a JSON-RPC 2.0 `error`
3
- * object (HTTP 200), except a missing or invalid bearer token (401) and a body
4
- * over the size limit (413), which apply to the whole batch.
3
+ * object (HTTP 200), except a body over the size limit (413), which applies
4
+ * to the whole batch. `Unauthorized` and `Forbidden` are for the server that
5
+ * mounts the handler and authenticates its callers (Studio's session); the
6
+ * handler itself never raises them.
5
7
  */
6
8
 
7
9
  export const ErrorCode = {
@@ -41,8 +43,7 @@ export interface VersionMismatch {
41
43
 
42
44
  /** `error.data` of a Conflict (-32002). */
43
45
  export interface ConflictData {
44
- entries?: Record<string, VersionMismatch>;
45
- schema?: { expected: string; actual: string | null };
46
+ entries: Record<string, VersionMismatch>;
46
47
  }
47
48
 
48
49
  /** One rule a `blocks.apply` breaks. */
@@ -134,9 +135,3 @@ export const parseError = () => new ContentProtocolError(ErrorCode.ParseError, "
134
135
 
135
136
  export const internalError = () =>
136
137
  new ContentProtocolError(ErrorCode.InternalError, "internal error");
137
-
138
- export const unauthorized = () =>
139
- new ContentProtocolError(ErrorCode.Unauthorized, "missing or invalid bearer token");
140
-
141
- export const forbidden = () =>
142
- new ContentProtocolError(ErrorCode.Forbidden, "not allowed for this project");
@@ -14,22 +14,14 @@
14
14
  *
15
15
  * The SDK's runtime never imports the protocol, so it never reaches an app
16
16
  * bundle. The canonical hash it re-exports is the SDK's own dependency-free
17
- * leaf module (see ./canonical.ts), including the draft overlay hashes
18
- * (`computeBlockHash`, `computeOverlayVersion`). Draft overlays themselves,
19
- * preview grants and the draft lifecycle are outside the protocol: overlays
20
- * are delivery assets (see /next/content-delivery#exact-draft-previews).
17
+ * leaf module (see ./canonical.ts). Draft previews and the draft lifecycle
18
+ * are outside the protocol (see /next/content-delivery#draft-previews).
21
19
  */
22
20
  export {
23
- APPLY_DIGEST_DOMAIN,
24
- applyRequestDigest,
25
21
  CanonicalJsonError,
26
22
  CONTENT_HASH_FORMAT,
27
23
  canonicalJson,
28
- computeBlockHash,
29
24
  computeContentRevision,
30
- computeOverlayVersion,
31
- DRAFT_OVERLAY_FORMAT,
32
- type DraftOverlay,
33
25
  sha256Hex,
34
26
  } from "./canonical.ts";
35
27
  export {
@@ -13,14 +13,10 @@ import type { BlocksApplyParams, MethodName, ReadParams } from "./types.ts";
13
13
  const opaque = z.string().min(1).max(1024);
14
14
 
15
15
  const readParams = z.strictObject({
16
- ref: z.string().min(1).max(255).optional(),
17
16
  ifNoneMatch: opaque.optional(),
18
17
  });
19
18
 
20
19
  const applyParams = z.strictObject({
21
- ref: z.string().min(1).max(255).optional(),
22
- requestKey: z.string().min(1).max(256).optional(),
23
- ifSchemaMatch: opaque.optional(),
24
20
  // Entry shapes are checked later and reported as InvalidBlock, all at once.
25
21
  set: z.record(z.string(), z.unknown()).optional(),
26
22
  delete: z.array(z.string()).optional(),
@@ -2,7 +2,7 @@
2
2
  * `createAssetHandler(storage)`: uploads beside the content protocol.
3
3
  *
4
4
  * Uploads aren't one of the four methods. The site editor sends each file to
5
- * `PUT /assets/<name>` with the same auth as the protocol; on that path the
5
+ * `PUT /assets/<name>`; on that path the
6
6
  * file's own image, video, font or PDF content type is accepted instead of
7
7
  * JSON, and the name's extension must match it (`banner.html` sent as
8
8
  * `image/png` is refused; a name without an extension gets the type's). SVG
@@ -21,21 +21,16 @@ import {
21
21
  import {
22
22
  type ContentProtocolError,
23
23
  ErrorCode,
24
- forbidden,
25
24
  invalidRequest,
26
25
  limitExceeded,
27
26
  readOnly,
28
- unauthorized,
29
27
  unsupported,
30
28
  } from "../errors.ts";
31
29
  import type { ContentStorage } from "../storage.ts";
32
30
  import { ASSETS_URL_PREFIX } from "../types.ts";
33
- import { type AuthOptions, assertAuthOptions, authenticate } from "./auth.ts";
34
31
  import { BodyEncodingError, BodyTooLargeError, jsonResponse, readBody } from "./http.ts";
35
32
 
36
33
  const STATUS: Record<number, number> = {
37
- [ErrorCode.Unauthorized]: 401,
38
- [ErrorCode.Forbidden]: 403,
39
34
  [ErrorCode.ReadOnly]: 403,
40
35
  [ErrorCode.Unsupported]: 404,
41
36
  [ErrorCode.LimitExceeded]: 413,
@@ -44,13 +39,12 @@ const STATUS: Record<number, number> = {
44
39
 
45
40
  export type AssetHandler = (request: Request) => Promise<Response>;
46
41
 
47
- export type AssetHandlerOptions = AuthOptions & AssetTypeOptions;
42
+ export type AssetHandlerOptions = AssetTypeOptions;
48
43
 
49
44
  export function createAssetHandler(
50
45
  storage: ContentStorage,
51
46
  options: AssetHandlerOptions = {},
52
47
  ): AssetHandler {
53
- assertAuthOptions(options);
54
48
  const fail = (request: Request, error: ContentProtocolError, status?: number) =>
55
49
  jsonResponse(
56
50
  request,
@@ -69,10 +63,6 @@ export function createAssetHandler(
69
63
  },
70
64
  );
71
65
  }
72
- const auth = await authenticate(request, options);
73
- if (!auth.ok)
74
- return fail(request, auth.reason === "unauthorized" ? unauthorized() : forbidden());
75
-
76
66
  const description = await storage.describe();
77
67
  if (description.readOnly) return fail(request, readOnly());
78
68
  if (description.assets === null || !storage.putAsset) {
@@ -4,11 +4,12 @@
4
4
  * Shared by `blocks.list` (which needs every body) and `blocks.apply` (which
5
5
  * needs bodies only to break ties between spellings).
6
6
  */
7
- import { limitExceeded, unavailable } from "../errors.ts";
7
+ import { unavailable } from "../errors.ts";
8
8
  import { entryHasPath, fullyDecodeFileName, isBlockFileName, resolveSpellings } from "../keys.ts";
9
9
  import type { ContentStorage, StorageFile, StorageSnapshot } from "../storage.ts";
10
- import type { Diagnostic, Limits } from "../types.ts";
10
+ import type { Diagnostic } from "../types.ts";
11
11
  import { type BodyCache, type ParsedBody, parseBody } from "./bodyCache.ts";
12
+ import { MAX_BLOCK_BYTES } from "./core.ts";
12
13
 
13
14
  export interface LoadedEntry {
14
15
  file: string;
@@ -38,14 +39,13 @@ export interface LoadedContent {
38
39
  interface Options {
39
40
  /** Read every body (`blocks.list`), not only the ones that break ties. */
40
41
  readAll: boolean;
41
- limits: Limits;
42
42
  cache: BodyCache;
43
43
  }
44
44
 
45
45
  async function loadContent(
46
46
  storage: ContentStorage,
47
47
  snapshot: StorageSnapshot,
48
- { readAll, limits, cache }: Options,
48
+ { readAll, cache }: Options,
49
49
  ): Promise<LoadedContent> {
50
50
  const files = snapshot.files.filter((f) => isBlockFileName(f.file));
51
51
  const groups = new Map<string, StorageFile[]>();
@@ -60,35 +60,27 @@ async function loadContent(
60
60
  let moved = false;
61
61
  const parsed = new Map<string, ParsedBody>();
62
62
  const toRead: StorageFile[] = [];
63
- let knownBytes = 0;
64
63
  for (const group of groups.values()) {
65
64
  if (!readAll && group.length < 2) continue;
66
65
  for (const file of group) {
67
- // An existing file over maxBlockBytes is unreadable, like invalid JSON: it's
66
+ // An existing file over MAX_BLOCK_BYTES is unreadable, like invalid JSON: it's
68
67
  // left out of the map and reported as a `too-large` diagnostic, so one
69
68
  // oversized hand edit can't take the whole editor down. The map plus its
70
- // diagnostics still accounts for every file in the snapshot; only the
71
- // aggregate (maxListBytes) answers LimitExceeded.
72
- if (file.size !== undefined && file.size > limits.maxBlockBytes) {
69
+ // diagnostics still accounts for every file in the snapshot.
70
+ if (file.size !== undefined && file.size > MAX_BLOCK_BYTES) {
73
71
  parsed.set(file.file, {
74
72
  ok: false,
75
73
  kind: "too-large",
76
74
  bytes: file.size,
77
- message: `the file is over ${limits.maxBlockBytes} bytes`,
75
+ message: `the file is over ${MAX_BLOCK_BYTES} bytes`,
78
76
  });
79
77
  continue;
80
78
  }
81
- knownBytes += file.size ?? 0;
82
79
  const hit = cache.get(file.file, file.version);
83
80
  if (hit) parsed.set(file.file, hit);
84
81
  else toRead.push(file);
85
82
  }
86
83
  }
87
- if (readAll && knownBytes > limits.maxListBytes) {
88
- throw limitExceeded(`the block list is over ${limits.maxListBytes} bytes`, {
89
- limit: "maxListBytes",
90
- });
91
- }
92
84
  if (toRead.length > 0) {
93
85
  const bodies = await storage.readFiles(
94
86
  snapshot,
@@ -100,7 +92,7 @@ async function loadContent(
100
92
  moved = true; // vanished since the snapshot
101
93
  continue;
102
94
  }
103
- const body = parseBody(read.text, limits.maxBlockBytes);
95
+ const body = parseBody(read.text, MAX_BLOCK_BYTES);
104
96
  // Cache under the version of the bytes actually read, never the snapshot's.
105
97
  cache.set(file.file, read.version, body);
106
98
  if (read.version !== file.version) {
@@ -127,11 +119,6 @@ async function loadContent(
127
119
  bytes += body.bytes;
128
120
  candidates.push({ ...file, hasPath: entryHasPath(body.value), value: body.value });
129
121
  }
130
- if (readAll && bytes > limits.maxListBytes) {
131
- throw limitExceeded(`the block list is over ${limits.maxListBytes} bytes`, {
132
- limit: "maxListBytes",
133
- });
134
- }
135
122
 
136
123
  const entries = new Map<string, LoadedEntry>();
137
124
  for (const { name, winner, shadowed } of resolveSpellings(candidates).values()) {
@@ -161,12 +148,11 @@ const MAX_SNAPSHOT_READS = 3;
161
148
  */
162
149
  export async function loadCurrentContent(
163
150
  storage: ContentStorage,
164
- ref: string | undefined,
165
151
  options: Options,
166
152
  shortCircuit?: (snapshot: StorageSnapshot) => boolean,
167
153
  ): Promise<{ snapshot: StorageSnapshot; content: LoadedContent | null }> {
168
154
  for (let read = 1; read <= MAX_SNAPSHOT_READS; read++) {
169
- const snapshot = await storage.snapshot({ ref });
155
+ const snapshot = await storage.snapshot();
170
156
  if (shortCircuit?.(snapshot)) return { snapshot, content: null };
171
157
  const content = await loadContent(storage, snapshot, options);
172
158
  if (!content.moved) return { snapshot, content };
@@ -1,13 +1,7 @@
1
1
  /**
2
2
  * The shared state of one content handler: its storage, options and caches.
3
3
  */
4
- import {
5
- ContentProtocolError,
6
- invalidBlock,
7
- notFound,
8
- unavailable,
9
- unsupported,
10
- } from "../errors.ts";
4
+ import { ContentProtocolError, invalidBlock, notFound, unavailable } from "../errors.ts";
11
5
  import { blockNameFromFile } from "../keys.ts";
12
6
  import {
13
7
  type ContentStorage,
@@ -16,15 +10,21 @@ import {
16
10
  StorageNotFoundError,
17
11
  StorageUnavailableError,
18
12
  } from "../storage.ts";
19
- import { DEFAULT_LIMITS, type DecoMeta, type Limits } from "../types.ts";
20
- import type { AuthOptions } from "./auth.ts";
13
+ import type { DecoMeta } from "../types.ts";
21
14
  import { BodyCache } from "./bodyCache.ts";
22
15
 
23
- export interface ContentHandlerOptions extends AuthOptions {
16
+ const MiB = 1024 * 1024;
17
+
18
+ /** `blocks.apply`'s own guards: names (set plus delete) in one call. Internal, not advertised. */
19
+ export const MAX_OPS_PER_APPLY = 500;
20
+ /** Bytes of one stored entry. */
21
+ export const MAX_BLOCK_BYTES = 1 * MiB;
22
+ /** Bytes of one HTTP request body, uncompressed. */
23
+ export const MAX_REQUEST_BYTES = 8 * MiB;
24
+
25
+ export interface ContentHandlerOptions {
24
26
  /** Reported by `describe`, such as `{ name: "deco-cli", version: "8.0.0" }`. */
25
27
  server?: { name: string; version: string };
26
- /** Lowers the protocol's default limits. Higher values are ignored. */
27
- limits?: Partial<Limits>;
28
28
  /** Overrides the poll interval the storage suggests. */
29
29
  pollIntervalMs?: number;
30
30
  /** The app the site editor previews, reported by `describe` (`{ url }`). */
@@ -48,8 +48,6 @@ const DEFAULT_RETRY_DELAY = { minMs: 50, maxMs: 200 };
48
48
 
49
49
  export class Core {
50
50
  readonly cache: BodyCache;
51
- /** Requests in flight per scoped request key, so simultaneous duplicates commit once. */
52
- readonly inflight = new Map<string, Promise<unknown>>();
53
51
  /** The last parsed schema, by version: the secret guard reads it on every write. */
54
52
  parsedSchema: { version: string; meta: DecoMeta } | null = null;
55
53
 
@@ -75,31 +73,11 @@ export class Core {
75
73
  return this.storage.describe();
76
74
  }
77
75
 
78
- /** The effective limits: the lowest of the defaults, the storage's and the options'. */
79
- limits(description: StorageDescription): Limits {
80
- const out = { ...DEFAULT_LIMITS };
81
- for (const source of [description.limits, this.options.limits]) {
82
- if (!source) continue;
83
- for (const key of Object.keys(out) as (keyof Limits)[]) {
84
- const value = source[key];
85
- if (typeof value === "number" && value > 0 && value < out[key]) out[key] = value;
86
- }
87
- }
88
- return out;
89
- }
90
-
91
76
  pollIntervalMs(description: StorageDescription): number {
92
77
  return (
93
78
  this.options.pollIntervalMs ?? description.pollIntervalMs ?? DEFAULT_POLL_MS[description.kind]
94
79
  );
95
80
  }
96
-
97
- /** Refuses a `ref` on a storage without branches. */
98
- checkRef(description: StorageDescription, ref: string | undefined): void {
99
- if (ref !== undefined && description.refs === null) {
100
- throw unsupported("this endpoint has no branches; omit ref");
101
- }
102
- }
103
81
  }
104
82
 
105
83
  /** Maps storage errors to protocol errors; anything unknown is rethrown. */
@@ -4,29 +4,21 @@
4
4
  *
5
5
  * `POST <endpoint>` with `Content-Type: application/json` and a body that's
6
6
  * one request object or a batch array. Errors come back in the JSON-RPC
7
- * `error` object with HTTP 200, except a missing or invalid bearer token (401)
8
- * and a body over the size limit (413), which apply to the whole batch, and
9
- * requests that aren't the protocol at all: a method other than POST (405),
7
+ * `error` object with HTTP 200, except a body over the size limit (413),
8
+ * which applies to the whole batch, and requests that aren't the protocol at all: a method other than POST (405),
10
9
  * or a body that isn't JSON or uses an unsupported encoding (415). Those carry
11
10
  * a JSON-RPC error body too, with a `null` id.
12
11
  * Responses are gzip-compressed when the request accepts it.
13
12
  *
14
13
  * The handler is path-agnostic: mount it where the endpoint lives (`/rpc` on
15
- * the local server). Transport security that depends on where it runs — CORS,
16
- * `Host` checks, Chrome's local-network preflight — belongs to the server
17
- * that mounts it (`deco serve`).
14
+ * the local server). The handler doesn't authenticate: who may call it, and
15
+ * transport security that depends on where it runs — CORS, `Host` checks,
16
+ * Chrome's local-network preflight — belong to the server that mounts it
17
+ * (`deco serve` on loopback; Studio behind its own session).
18
18
  */
19
- import {
20
- type ContentProtocolError,
21
- forbidden,
22
- invalidRequest,
23
- limitExceeded,
24
- parseError,
25
- unauthorized,
26
- } from "../errors.ts";
19
+ import { type ContentProtocolError, invalidRequest, limitExceeded, parseError } from "../errors.ts";
27
20
  import type { ContentStorage } from "../storage.ts";
28
- import { assertAuthOptions, authenticate } from "./auth.ts";
29
- import { type ContentHandlerOptions, Core } from "./core.ts";
21
+ import { type ContentHandlerOptions, Core, MAX_REQUEST_BYTES } from "./core.ts";
30
22
  import {
31
23
  BodyEncodingError,
32
24
  BodyTooLargeError,
@@ -45,21 +37,12 @@ export function createContentHandler(
45
37
  storage: ContentStorage,
46
38
  options: ContentHandlerOptions = {},
47
39
  ): ContentHandler {
48
- assertAuthOptions(options);
49
40
  const core = new Core(storage, options);
50
41
 
51
42
  return async (request) => {
52
43
  if (request.method !== "POST") {
53
44
  return jsonResponse(request, errorBody(invalidRequest("use POST")), 405, { allow: "POST" });
54
45
  }
55
- const auth = await authenticate(request, options);
56
- if (!auth.ok) {
57
- return auth.reason === "unauthorized"
58
- ? jsonResponse(request, errorBody(unauthorized()), 401, {
59
- "www-authenticate": 'Bearer realm="deco-content"',
60
- })
61
- : jsonResponse(request, errorBody(forbidden()));
62
- }
63
46
  if (!isJsonContentType(request)) {
64
47
  return jsonResponse(
65
48
  request,
@@ -68,16 +51,15 @@ export function createContentHandler(
68
51
  );
69
52
  }
70
53
 
71
- const limits = core.limits(await core.description());
72
54
  let bytes: Uint8Array;
73
55
  try {
74
- bytes = await readBody(request, limits.maxRequestBytes);
56
+ bytes = await readBody(request, MAX_REQUEST_BYTES);
75
57
  } catch (error) {
76
58
  if (error instanceof BodyTooLargeError) {
77
59
  return jsonResponse(
78
60
  request,
79
61
  errorBody(
80
- limitExceeded(`the request body is over ${limits.maxRequestBytes} bytes`, {
62
+ limitExceeded(`the request body is over ${MAX_REQUEST_BYTES} bytes`, {
81
63
  limit: "maxRequestBytes",
82
64
  }),
83
65
  ),
@@ -96,7 +78,6 @@ export function createContentHandler(
96
78
  } catch {
97
79
  return jsonResponse(request, errorBody(parseError()));
98
80
  }
99
- const response = await dispatch(core, body, auth.scope, limits.maxBatchResponseBytes);
100
- return jsonResponse(request, response);
81
+ return jsonResponse(request, await dispatch(core, body));
101
82
  };
102
83
  }