@decocms/blocks 8.5.2 → 8.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. package/dist/async/default.d.ts +10 -0
  2. package/dist/async/default.d.ts.map +1 -0
  3. package/dist/async/default.js +5 -0
  4. package/dist/async/default.js.map +1 -0
  5. package/dist/async/node.d.ts +3 -0
  6. package/dist/async/node.d.ts.map +1 -0
  7. package/dist/async/node.js +11 -0
  8. package/dist/async/node.js.map +1 -0
  9. package/dist/async/types.d.ts +6 -0
  10. package/dist/async/types.d.ts.map +1 -0
  11. package/dist/async/types.js +2 -0
  12. package/dist/async/types.js.map +1 -0
  13. package/dist/index.d.ts +1 -1
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +1 -1
  16. package/dist/index.js.map +1 -1
  17. package/dist/v8/bucketing.d.ts +24 -0
  18. package/dist/v8/bucketing.d.ts.map +1 -0
  19. package/dist/v8/bucketing.js +78 -0
  20. package/dist/v8/bucketing.js.map +1 -0
  21. package/dist/v8/builtins/campaigns.d.ts +36 -0
  22. package/dist/v8/builtins/campaigns.d.ts.map +1 -0
  23. package/dist/v8/builtins/campaigns.js +107 -0
  24. package/dist/v8/builtins/campaigns.js.map +1 -0
  25. package/dist/v8/builtins/data.d.ts +2 -2
  26. package/dist/v8/builtins/data.js +2 -2
  27. package/dist/v8/builtins/experiments.d.ts +27 -0
  28. package/dist/v8/builtins/experiments.d.ts.map +1 -0
  29. package/dist/v8/builtins/experiments.js +62 -0
  30. package/dist/v8/builtins/experiments.js.map +1 -0
  31. package/dist/v8/builtins/index.d.ts.map +1 -1
  32. package/dist/v8/builtins/index.js +7 -2
  33. package/dist/v8/builtins/index.js.map +1 -1
  34. package/dist/v8/builtins/matchers.d.ts +0 -14
  35. package/dist/v8/builtins/matchers.d.ts.map +1 -1
  36. package/dist/v8/builtins/matchers.js +0 -19
  37. package/dist/v8/builtins/matchers.js.map +1 -1
  38. package/dist/v8/cli/builtins.d.ts +6 -0
  39. package/dist/v8/cli/builtins.d.ts.map +1 -1
  40. package/dist/v8/cli/builtins.js +19 -0
  41. package/dist/v8/cli/builtins.js.map +1 -1
  42. package/dist/v8/cli/check/index.d.ts.map +1 -1
  43. package/dist/v8/cli/check/index.js +231 -8
  44. package/dist/v8/cli/check/index.js.map +1 -1
  45. package/dist/v8/cli/schema/builtinSchemas.d.ts.map +1 -1
  46. package/dist/v8/cli/schema/builtinSchemas.js +76 -21
  47. package/dist/v8/cli/schema/builtinSchemas.js.map +1 -1
  48. package/dist/v8/cli/schema/generate.d.ts.map +1 -1
  49. package/dist/v8/cli/schema/generate.js +48 -2
  50. package/dist/v8/cli/schema/generate.js.map +1 -1
  51. package/dist/v8/client.d.ts +25 -0
  52. package/dist/v8/client.d.ts.map +1 -1
  53. package/dist/v8/client.js +58 -10
  54. package/dist/v8/client.js.map +1 -1
  55. package/dist/v8/cms.d.ts.map +1 -1
  56. package/dist/v8/cms.js +113 -44
  57. package/dist/v8/cms.js.map +1 -1
  58. package/dist/v8/content.d.ts +80 -1
  59. package/dist/v8/content.d.ts.map +1 -1
  60. package/dist/v8/content.js +149 -4
  61. package/dist/v8/content.js.map +1 -1
  62. package/dist/v8/current.d.ts +28 -0
  63. package/dist/v8/current.d.ts.map +1 -0
  64. package/dist/v8/current.js +77 -0
  65. package/dist/v8/current.js.map +1 -0
  66. package/dist/v8/draft.d.ts +40 -21
  67. package/dist/v8/draft.d.ts.map +1 -1
  68. package/dist/v8/draft.js +160 -25
  69. package/dist/v8/draft.js.map +1 -1
  70. package/dist/v8/experiments.d.ts +107 -0
  71. package/dist/v8/experiments.d.ts.map +1 -0
  72. package/dist/v8/experiments.js +292 -0
  73. package/dist/v8/experiments.js.map +1 -0
  74. package/dist/v8/hosts.d.ts +3 -2
  75. package/dist/v8/hosts.d.ts.map +1 -1
  76. package/dist/v8/hosts.js +3 -2
  77. package/dist/v8/hosts.js.map +1 -1
  78. package/dist/v8/index.d.ts +7 -5
  79. package/dist/v8/index.d.ts.map +1 -1
  80. package/dist/v8/index.js +6 -4
  81. package/dist/v8/index.js.map +1 -1
  82. package/dist/v8/preview/DraftBadge.d.ts +9 -1
  83. package/dist/v8/preview/DraftBadge.d.ts.map +1 -1
  84. package/dist/v8/preview/DraftBadge.js +42 -2
  85. package/dist/v8/preview/DraftBadge.js.map +1 -1
  86. package/dist/v8/remoteLoader.d.ts.map +1 -1
  87. package/dist/v8/remoteLoader.js +169 -21
  88. package/dist/v8/remoteLoader.js.map +1 -1
  89. package/dist/v8/resolver.d.ts +4 -2
  90. package/dist/v8/resolver.d.ts.map +1 -1
  91. package/dist/v8/resolver.js +11 -3
  92. package/dist/v8/resolver.js.map +1 -1
  93. package/dist/v8/settings.d.ts +16 -4
  94. package/dist/v8/settings.d.ts.map +1 -1
  95. package/dist/v8/settings.js +24 -21
  96. package/dist/v8/settings.js.map +1 -1
  97. package/dist/v8/types.d.ts +162 -22
  98. package/dist/v8/types.d.ts.map +1 -1
  99. package/package.json +35 -1
  100. package/src/async/default.ts +13 -0
  101. package/src/async/node.ts +12 -0
  102. package/src/async/types.ts +5 -0
  103. package/src/index.ts +4 -0
  104. package/src/v8/bucketing.ts +88 -0
  105. package/src/v8/builtins/campaigns.ts +120 -0
  106. package/src/v8/builtins/data.ts +2 -2
  107. package/src/v8/builtins/experiments.ts +72 -0
  108. package/src/v8/builtins/index.ts +7 -2
  109. package/src/v8/builtins/matchers.ts +0 -26
  110. package/src/v8/cli/builtins.ts +23 -0
  111. package/src/v8/cli/check/index.ts +289 -8
  112. package/src/v8/cli/schema/builtinSchemas.ts +82 -22
  113. package/src/v8/cli/schema/generate.ts +48 -3
  114. package/src/v8/client.ts +76 -10
  115. package/src/v8/cms.ts +134 -45
  116. package/src/v8/content.ts +168 -4
  117. package/src/v8/current.ts +98 -0
  118. package/src/v8/draft.ts +170 -30
  119. package/src/v8/experiments.ts +340 -0
  120. package/src/v8/hosts.ts +3 -2
  121. package/src/v8/index.ts +8 -4
  122. package/src/v8/preview/DraftBadge.tsx +72 -2
  123. package/src/v8/remoteLoader.ts +193 -26
  124. package/src/v8/resolver.ts +14 -4
  125. package/src/v8/settings.ts +35 -29
  126. package/src/v8/types.ts +163 -20
@@ -0,0 +1,10 @@
1
+ /**
2
+ * The async store where `node:async_hooks` isn't there to import (browsers,
3
+ * React Native, edge runtimes). A runtime that exposes `AsyncLocalStorage` as
4
+ * a global (Vercel's edge runtime) still gets one; elsewhere there is none,
5
+ * and `currentClient()` works from the start of a block function, before its
6
+ * first `await`. Picked by the `#async-store` import's `default` condition.
7
+ */
8
+ import type { AsyncStore } from "./types.ts";
9
+ export declare function createAsyncStore<T>(): AsyncStore<T> | undefined;
10
+ //# sourceMappingURL=default.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"default.d.ts","sourceRoot":"","sources":["../../src/async/default.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,wBAAgB,gBAAgB,CAAC,CAAC,KAAK,UAAU,CAAC,CAAC,CAAC,GAAG,SAAS,CAG/D"}
@@ -0,0 +1,5 @@
1
+ export function createAsyncStore() {
2
+ const Storage = globalThis.AsyncLocalStorage;
3
+ return typeof Storage === "function" ? new Storage() : undefined;
4
+ }
5
+ //# sourceMappingURL=default.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"default.js","sourceRoot":"","sources":["../../src/async/default.ts"],"names":[],"mappings":"AASA,MAAM,UAAU,gBAAgB;IAC9B,MAAM,OAAO,GAAI,UAA8D,CAAC,iBAAiB,CAAC;IAClG,OAAO,OAAO,OAAO,KAAK,UAAU,CAAC,CAAC,CAAC,IAAI,OAAO,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;AACnE,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { AsyncStore } from "./types.ts";
2
+ export declare function createAsyncStore<T>(): AsyncStore<T> | undefined;
3
+ //# sourceMappingURL=node.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../src/async/node.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,wBAAgB,gBAAgB,CAAC,CAAC,KAAK,UAAU,CAAC,CAAC,CAAC,GAAG,SAAS,CAE/D"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * The async store on servers with `AsyncLocalStorage` (Node, Bun, Deno, and
3
+ * Workers with `nodejs_compat`), so `currentClient()` survives `await`.
4
+ * Picked by the `#async-store` import's `node`, `workerd`, `bun` and `deno`
5
+ * conditions; the runtime core (`src/v8`) never imports a Node built-in.
6
+ */
7
+ import { AsyncLocalStorage } from "node:async_hooks";
8
+ export function createAsyncStore() {
9
+ return new AsyncLocalStorage();
10
+ }
11
+ //# sourceMappingURL=node.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node.js","sourceRoot":"","sources":["../../src/async/node.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAGrD,MAAM,UAAU,gBAAgB;IAC9B,OAAO,IAAI,iBAAiB,EAAK,CAAC;AACpC,CAAC"}
@@ -0,0 +1,6 @@
1
+ /** The part of `AsyncLocalStorage` the client slot uses. */
2
+ export interface AsyncStore<T> {
3
+ run<R>(value: T, fn: () => R): R;
4
+ getStore(): T | undefined;
5
+ }
6
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/async/types.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,MAAM,WAAW,UAAU,CAAC,CAAC;IAC3B,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC;IACjC,QAAQ,IAAI,CAAC,GAAG,SAAS,CAAC;CAC3B"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/async/types.ts"],"names":[],"mappings":""}
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { type Analytics, type Block, type BlockFunction, type Blocks, type Client, type CMS, type CMSError, type CMSSettings, createCMS, type DraftPointer, type EffectiveSettings, formatDraftPointer, type Lazy, type ListOptions, type Loader, type Match, matchRoute, type Page, parseDraftPointer, type Redirect, type RequestLike, type Result, type Route, remoteLoader, resetForTests, type Secret, type Seo, type Snapshot, type Telemetry, type TelemetryConfig, type Variant, } from "./v8/index.ts";
1
+ export { type Analytics, type Block, type BlockFunction, type Blocks, type Client, type ClientOptions, type CMS, type CMSError, type CMSSettings, createCMS, currentClient, type DraftPointer, type EffectiveSettings, formatDraftPointer, type Lazy, type ListOptions, type Loader, type Match, matchRoute, type Page, parseDraftPointer, parseVersion, type Redirect, type RequestLike, type RequestVersion, type Result, type Route, remoteLoader, resetForTests, type Secret, type Seo, type Snapshot, type Telemetry, type TelemetryConfig, type Variant, } from "./v8/index.ts";
2
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,SAAS,EACd,KAAK,KAAK,EACV,KAAK,aAAa,EAClB,KAAK,MAAM,EACX,KAAK,MAAM,EACX,KAAK,GAAG,EACR,KAAK,QAAQ,EACb,KAAK,WAAW,EAChB,SAAS,EACT,KAAK,YAAY,EACjB,KAAK,iBAAiB,EACtB,kBAAkB,EAClB,KAAK,IAAI,EACT,KAAK,WAAW,EAChB,KAAK,MAAM,EACX,KAAK,KAAK,EACV,UAAU,EACV,KAAK,IAAI,EACT,iBAAiB,EACjB,KAAK,QAAQ,EACb,KAAK,WAAW,EAChB,KAAK,MAAM,EACX,KAAK,KAAK,EACV,YAAY,EACZ,aAAa,EACb,KAAK,MAAM,EACX,KAAK,GAAG,EACR,KAAK,QAAQ,EACb,KAAK,SAAS,EACd,KAAK,eAAe,EACpB,KAAK,OAAO,GACb,MAAM,eAAe,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,SAAS,EACd,KAAK,KAAK,EACV,KAAK,aAAa,EAClB,KAAK,MAAM,EACX,KAAK,MAAM,EACX,KAAK,aAAa,EAClB,KAAK,GAAG,EACR,KAAK,QAAQ,EACb,KAAK,WAAW,EAChB,SAAS,EACT,aAAa,EACb,KAAK,YAAY,EACjB,KAAK,iBAAiB,EACtB,kBAAkB,EAClB,KAAK,IAAI,EACT,KAAK,WAAW,EAChB,KAAK,MAAM,EACX,KAAK,KAAK,EACV,UAAU,EACV,KAAK,IAAI,EACT,iBAAiB,EACjB,YAAY,EACZ,KAAK,QAAQ,EACb,KAAK,WAAW,EAChB,KAAK,cAAc,EACnB,KAAK,MAAM,EACX,KAAK,KAAK,EACV,YAAY,EACZ,aAAa,EACb,KAAK,MAAM,EACX,KAAK,GAAG,EACR,KAAK,QAAQ,EACb,KAAK,SAAS,EACd,KAAK,eAAe,EACpB,KAAK,OAAO,GACb,MAAM,eAAe,CAAC"}
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  // @decocms/blocks: the v8 runtime API. The CLI, protocol and helpers live on
2
2
  // their own subpaths (`/cli`, `/protocol`, `/fetch`, `/analytics`, `/secrets`).
3
- export { createCMS, formatDraftPointer, matchRoute, parseDraftPointer, remoteLoader, resetForTests, } from "./v8/index.js";
3
+ export { createCMS, currentClient, formatDraftPointer, matchRoute, parseDraftPointer, parseVersion, remoteLoader, resetForTests, } from "./v8/index.js";
4
4
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,gFAAgF;AAChF,OAAO,EASL,SAAS,EAGT,kBAAkB,EAKlB,UAAU,EAEV,iBAAiB,EAKjB,YAAY,EACZ,aAAa,GAOd,MAAM,eAAe,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,gFAAgF;AAChF,OAAO,EAUL,SAAS,EACT,aAAa,EAGb,kBAAkB,EAKlB,UAAU,EAEV,iBAAiB,EACjB,YAAY,EAMZ,YAAY,EACZ,aAAa,GAOd,MAAM,eAAe,CAAC"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * The arithmetic behind `@decocms/blocks/experiments`: the hash, the roll and
3
+ * the visitor id. Internal: not in the exports map, so the public surface is
4
+ * `assign` and the visitor helpers alone, and the tests import this by path.
5
+ *
6
+ * A hash bug here fails silently: every visitor still gets an answer, it is
7
+ * just the wrong one, and the test's result is quietly meaningless. That is
8
+ * why `experiments.test.ts` pins MurmurHash3's published vectors and a table
9
+ * of rolls, and why changing anything here moves visitors already allocated.
10
+ */
11
+ /** Fills `bytes` with random values. `newId` takes one so tests can pin the id. */
12
+ export type RandomBytes = (bytes: Uint8Array<ArrayBuffer>) => void;
13
+ /** MurmurHash3 x86 32-bit, seed 0 by default, over `bytes`, as an unsigned 32-bit number. */
14
+ export declare function murmur3_32(bytes: Uint8Array, seed?: number): number;
15
+ /**
16
+ * This visitor's number for this experiment: a fixed value in [0, 100) with a
17
+ * step of 0.01, the same on every runtime. The visitor is in when it is below
18
+ * the allocation, which is what makes a ramp only ever add people: the roll
19
+ * does not move, the threshold does.
20
+ */
21
+ export declare function roll(name: string, id: string): number;
22
+ /** A fresh visitor id: 128 bits as 22 base64url characters. */
23
+ export declare function newId(random?: RandomBytes): string;
24
+ //# sourceMappingURL=bucketing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bucketing.d.ts","sourceRoot":"","sources":["../../src/v8/bucketing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,mFAAmF;AACnF,MAAM,MAAM,WAAW,GAAG,CAAC,KAAK,EAAE,UAAU,CAAC,WAAW,CAAC,KAAK,IAAI,CAAC;AAMnE,6FAA6F;AAC7F,wBAAgB,UAAU,CAAC,KAAK,EAAE,UAAU,EAAE,IAAI,SAAI,GAAG,MAAM,CAyC9D;AAED;;;;;GAKG;AACH,wBAAgB,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAErD;AAYD,+DAA+D;AAC/D,wBAAgB,KAAK,CAAC,MAAM,GAAE,WAA2B,GAAG,MAAM,CAIjE"}
@@ -0,0 +1,78 @@
1
+ /**
2
+ * The arithmetic behind `@decocms/blocks/experiments`: the hash, the roll and
3
+ * the visitor id. Internal: not in the exports map, so the public surface is
4
+ * `assign` and the visitor helpers alone, and the tests import this by path.
5
+ *
6
+ * A hash bug here fails silently: every visitor still gets an answer, it is
7
+ * just the wrong one, and the test's result is quietly meaningless. That is
8
+ * why `experiments.test.ts` pins MurmurHash3's published vectors and a table
9
+ * of rolls, and why changing anything here moves visitors already allocated.
10
+ */
11
+ const ID_BYTES = 16;
12
+ const encoder = new TextEncoder();
13
+ /** MurmurHash3 x86 32-bit, seed 0 by default, over `bytes`, as an unsigned 32-bit number. */
14
+ export function murmur3_32(bytes, seed = 0) {
15
+ const c1 = 0xcc9e2d51;
16
+ const c2 = 0x1b873593;
17
+ const len = bytes.length;
18
+ const blocks = len & ~3;
19
+ let h = seed >>> 0;
20
+ for (let i = 0; i < blocks; i += 4) {
21
+ let k = (bytes[i] |
22
+ (bytes[i + 1] << 8) |
23
+ (bytes[i + 2] << 16) |
24
+ (bytes[i + 3] << 24)) >>>
25
+ 0;
26
+ k = Math.imul(k, c1);
27
+ k = (k << 15) | (k >>> 17);
28
+ k = Math.imul(k, c2);
29
+ h ^= k;
30
+ h = (h << 13) | (h >>> 19);
31
+ h = (Math.imul(h, 5) + 0xe6546b64) | 0;
32
+ }
33
+ const tail = len & 3;
34
+ if (tail > 0) {
35
+ let k = 0;
36
+ if (tail === 3)
37
+ k ^= bytes[blocks + 2] << 16;
38
+ if (tail >= 2)
39
+ k ^= bytes[blocks + 1] << 8;
40
+ k ^= bytes[blocks];
41
+ k = Math.imul(k, c1);
42
+ k = (k << 15) | (k >>> 17);
43
+ k = Math.imul(k, c2);
44
+ h ^= k;
45
+ }
46
+ h ^= len;
47
+ h ^= h >>> 16;
48
+ h = Math.imul(h, 0x85ebca6b);
49
+ h ^= h >>> 13;
50
+ h = Math.imul(h, 0xc2b2ae35);
51
+ h ^= h >>> 16;
52
+ return h >>> 0;
53
+ }
54
+ /**
55
+ * This visitor's number for this experiment: a fixed value in [0, 100) with a
56
+ * step of 0.01, the same on every runtime. The visitor is in when it is below
57
+ * the allocation, which is what makes a ramp only ever add people: the roll
58
+ * does not move, the threshold does.
59
+ */
60
+ export function roll(name, id) {
61
+ return (murmur3_32(encoder.encode(`${name}:${id}`)) % 10000) / 100;
62
+ }
63
+ function toBase64Url(bytes) {
64
+ let binary = "";
65
+ for (const byte of bytes)
66
+ binary += String.fromCharCode(byte);
67
+ return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
68
+ }
69
+ const defaultRandom = (bytes) => {
70
+ crypto.getRandomValues(bytes);
71
+ };
72
+ /** A fresh visitor id: 128 bits as 22 base64url characters. */
73
+ export function newId(random = defaultRandom) {
74
+ const bytes = new Uint8Array(ID_BYTES);
75
+ random(bytes);
76
+ return toBase64Url(bytes);
77
+ }
78
+ //# sourceMappingURL=bucketing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bucketing.js","sourceRoot":"","sources":["../../src/v8/bucketing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAKH,MAAM,QAAQ,GAAG,EAAE,CAAC;AAEpB,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;AAElC,6FAA6F;AAC7F,MAAM,UAAU,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AC,IAAI,CAAC,CAAC;IAC9D,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;AACjF,CAAC;AAED,MAAM,aAAa,GAAgB,CAAC,KAAK,EAAE,EAAE;IAC3C,MAAM,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;AAChC,CAAC,CAAC;AAEF,+DAA+D;AAC/D,MAAM,UAAU,KAAK,CAAC,MAAM,GAAgB,aAAa;IACvD,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,QAAQ,CAAC,CAAC;IACvC,MAAM,CAAC,KAAK,CAAC,CAAC;IACd,OAAO,WAAW,CAAC,KAAK,CAAC,CAAC;AAC5B,CAAC"}
@@ -0,0 +1,36 @@
1
+ /** The saved block every `campaign` rule reads, and its built-in type. */
2
+ export declare const CAMPAIGNS_BLOCK = "campaigns";
3
+ export declare const CALENDAR_TYPE = "calendar";
4
+ /** The built-in rule that reads a campaign. */
5
+ export declare const CAMPAIGN_RULE = "campaign";
6
+ /** What resolving `campaigns` gives: each campaign and whether it is running. */
7
+ type Campaigns = Record<string, boolean>;
8
+ /**
9
+ * `calendar`: each campaign and whether the current client's date is inside
10
+ * its window, or, for a campaign the client was given, what it was given.
11
+ */
12
+ export declare const calendar: (windows?: Record<string, unknown>) => Campaigns;
13
+ /**
14
+ * A campaign bound's time in ms since the epoch: `undefined` when absent or
15
+ * empty (open), `null` when it can't be one. A bound is an ISO 8601
16
+ * date-time with an explicit offset (`Z` or `±hh:mm`), so it names the same
17
+ * moment on every runtime. A date without a time, a date-time without an
18
+ * offset (whose moment depends on where it is read), a day the calendar
19
+ * doesn't have and anything else, such as `"Nov 27 2026"`, can't be one,
20
+ * so that campaign never runs.
21
+ */
22
+ export declare function campaignTime(value: unknown): number | undefined | null;
23
+ /** Inputs of the built-in `campaign` rule. */
24
+ interface CampaignProps {
25
+ /** A campaign in the saved block `campaigns`. */
26
+ name?: string;
27
+ }
28
+ /**
29
+ * `campaign`: `true` while the campaign `name` of the saved block
30
+ * `campaigns` is running for the client. An unknown name, no `campaigns`
31
+ * block, or a rule without a name give `false`. The block is resolved once
32
+ * per client, however many rules ask.
33
+ */
34
+ export declare const campaign: ({ name }?: CampaignProps) => boolean | Promise<boolean>;
35
+ export {};
36
+ //# sourceMappingURL=campaigns.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"campaigns.d.ts","sourceRoot":"","sources":["../../../src/v8/builtins/campaigns.ts"],"names":[],"mappings":"AAoBA,0EAA0E;AAC1E,eAAO,MAAM,eAAe,cAAc,CAAC;AAC3C,eAAO,MAAM,aAAa,aAAa,CAAC;AAExC,+CAA+C;AAC/C,eAAO,MAAM,aAAa,aAAa,CAAC;AAExC,iFAAiF;AACjF,KAAK,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEzC;;;GAGG;AACH,eAAO,MAAM,QAAQ,aAAa,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAQ,SAYhE,CAAC;AAqBF;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,GAAG,IAAI,CAOtE;AASD,8CAA8C;AAC9C,UAAU,aAAa;IACrB,iDAAiD;IACjD,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,cAAc,aAAa,KAAQ,OAAO,GAAG,OAAO,CAAC,OAAO,CAMhF,CAAC"}
@@ -0,0 +1,107 @@
1
+ /**
2
+ * Campaign dates as content (see /next/built-in-blocks#calendar): the
3
+ * built-in type `calendar`, which the saved block `campaigns` has, and the
4
+ * built-in rule `campaign`.
5
+ *
6
+ * - `campaigns` maps each campaign's name to one window, `{ start?, end? }`,
7
+ * ISO date-times with an offset. Resolving it gives each name and whether
8
+ * the client's date is inside its window, never a date.
9
+ * - `campaign { name }` is `true` when that answer is `true`. A rule always
10
+ * names a campaign: there are no inline `{ start, end }` dates, so
11
+ * `calendar` is the only place date logic lives.
12
+ *
13
+ * The date is the client's (`client.date`: `cms.client({ date })`, or when
14
+ * the client was created), read through `currentClient()` before any
15
+ * `await`. A campaign the client is given (`cms.client({ campaigns })`) is
16
+ * on or off as given, whatever its window; a name the block doesn't have
17
+ * stays out.
18
+ */
19
+ import { campaignOverrides, currentClient } from "../current.js";
20
+ /** The saved block every `campaign` rule reads, and its built-in type. */
21
+ export const CAMPAIGNS_BLOCK = "campaigns";
22
+ export const CALENDAR_TYPE = "calendar";
23
+ /** The built-in rule that reads a campaign. */
24
+ export const CAMPAIGN_RULE = "campaign";
25
+ /**
26
+ * `calendar`: each campaign and whether the current client's date is inside
27
+ * its window, or, for a campaign the client was given, what it was given.
28
+ */
29
+ export const calendar = (windows = {}) => {
30
+ const client = currentClient();
31
+ const given = campaignOverrides(client);
32
+ const at = client.date.getTime();
33
+ const out = Object.create(null);
34
+ for (const name of Object.keys(windows)) {
35
+ out[name] =
36
+ given !== undefined && Object.hasOwn(given, name)
37
+ ? given[name] === true
38
+ : inside(windows[name], at);
39
+ }
40
+ return out;
41
+ };
42
+ /**
43
+ * Whether `at` (ms since the epoch) is inside `window`, `{ start?, end? }`:
44
+ * from `start` (inclusive) until `end` (exclusive); an empty or absent bound
45
+ * is open. A window that isn't an object, or a bound that isn't an ISO 8601
46
+ * date-time with an offset, is outside, so a typo can't switch a campaign
47
+ * on. See `campaignTime` for how a bound reads.
48
+ */
49
+ function inside(window, at) {
50
+ if (typeof window !== "object" || window === null || Array.isArray(window))
51
+ return false;
52
+ const { start, end } = window;
53
+ const from = campaignTime(start);
54
+ const until = campaignTime(end);
55
+ if (from === null || until === null)
56
+ return false;
57
+ return (from === undefined || at >= from) && (until === undefined || at < until);
58
+ }
59
+ /** An ISO 8601 date-time with its offset (`Z` or `±hh:mm`). */
60
+ const ISO_RE = /^(\d{4}-\d{2}-\d{2})T\d{2}:\d{2}(?::\d{2}(?:\.\d{1,9})?)?(?:Z|[+-]\d{2}:\d{2})$/;
61
+ /**
62
+ * A campaign bound's time in ms since the epoch: `undefined` when absent or
63
+ * empty (open), `null` when it can't be one. A bound is an ISO 8601
64
+ * date-time with an explicit offset (`Z` or `±hh:mm`), so it names the same
65
+ * moment on every runtime. A date without a time, a date-time without an
66
+ * offset (whose moment depends on where it is read), a day the calendar
67
+ * doesn't have and anything else, such as `"Nov 27 2026"`, can't be one,
68
+ * so that campaign never runs.
69
+ */
70
+ export function campaignTime(value) {
71
+ if (value === undefined || value === null || value === "")
72
+ return undefined;
73
+ if (typeof value !== "string")
74
+ return null;
75
+ const match = ISO_RE.exec(value);
76
+ if (match === null || !isCalendarDate(match[1]))
77
+ return null;
78
+ const time = Date.parse(value);
79
+ return Number.isNaN(time) ? null : time;
80
+ }
81
+ /** Whether `yyyy-mm-dd` is a day of the calendar (some runtimes roll February 30 into March, others refuse it). */
82
+ function isCalendarDate(date) {
83
+ const [y, m, d] = date.split("-").map(Number);
84
+ const day = new Date(Date.UTC(y, m - 1, d));
85
+ return day.getUTCFullYear() === y && day.getUTCMonth() === m - 1 && day.getUTCDate() === d;
86
+ }
87
+ /**
88
+ * `campaign`: `true` while the campaign `name` of the saved block
89
+ * `campaigns` is running for the client. An unknown name, no `campaigns`
90
+ * block, or a rule without a name give `false`. The block is resolved once
91
+ * per client, however many rules ask.
92
+ */
93
+ export const campaign = ({ name } = {}) => {
94
+ const client = currentClient();
95
+ if (typeof name !== "string")
96
+ return false;
97
+ return client
98
+ .resolve(CAMPAIGNS_BLOCK)
99
+ .then(([campaigns]) => isTrueAt(campaigns, name));
100
+ };
101
+ function isTrueAt(record, name) {
102
+ return (typeof record === "object" &&
103
+ record !== null &&
104
+ Object.hasOwn(record, name) &&
105
+ record[name] === true);
106
+ }
107
+ //# sourceMappingURL=campaigns.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":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IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAC5C,OAAO,GAAG,CAAC,cAAc,EAAE,KAAK,CAAC,IAAI,GAAG,CAAC,WAAW,EAAE,KAAK,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;AAC7F,CAAC;AAQD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,EAAE,IAAI,EAAE,GAAkB,EAAE,EAA8B,EAAE;IACnF,MAAM,MAAM,GAAG,aAAa,EAAE,CAAC;IAC/B,IAAI,OAAO,IAAI,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC3C,OAAO,MAAM;SACV,OAAO,CAA0B,eAAe,CAAC;SACjD,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,EAAE,EAAE,CAAC,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC;AACtD,CAAC,CAAC;AAEF,SAAS,QAAQ,CAAC,MAAe,EAAE,IAAY;IAC7C,OAAO,CACL,OAAO,MAAM,KAAK,QAAQ;QAC1B,MAAM,KAAK,IAAI;QACf,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC;QAC1B,MAAkC,CAAC,IAAI,CAAC,KAAK,IAAI,CACnD,CAAC;AACJ,CAAC"}
@@ -19,8 +19,8 @@ export declare function telemetrySection(section: unknown): Required<Telemetry>;
19
19
  export declare function analyticsSection(section: unknown): Required<Analytics>;
20
20
  /**
21
21
  * `cms-settings`: the type of the well-known saved block `CMS`. Returns its
22
- * input with the telemetry and analytics defaults filled in; `preview` stays
23
- * as saved, since its default depends on code (`cms.settings()` applies it).
22
+ * input with the telemetry and analytics defaults filled in. Preview hosts
23
+ * aren't here: Studio writes them into the release metadata.
24
24
  */
25
25
  export declare const cmsSettings: (props?: CMSSettings) => CMSSettings & {
26
26
  telemetry: Required<Telemetry>;
@@ -39,8 +39,8 @@ export function analyticsSection(section) {
39
39
  }
40
40
  /**
41
41
  * `cms-settings`: the type of the well-known saved block `CMS`. Returns its
42
- * input with the telemetry and analytics defaults filled in; `preview` stays
43
- * as saved, since its default depends on code (`cms.settings()` applies it).
42
+ * input with the telemetry and analytics defaults filled in. Preview hosts
43
+ * aren't here: Studio writes them into the release metadata.
44
44
  */
45
45
  export const cmsSettings = (props = {}) => ({
46
46
  ...props,
@@ -0,0 +1,27 @@
1
+ import { type Assignments } from "../experiments.ts";
2
+ /** The saved block every `experiment` rule reads, and its built-in type. */
3
+ export declare const EXPERIMENTS_BLOCK = "experiments";
4
+ export declare const SPLIT_TRAFFIC_TYPE = "split-traffic";
5
+ /** The built-in rule that reads a test. */
6
+ export declare const EXPERIMENT_RULE = "experiment";
7
+ /**
8
+ * `split-traffic`: each test and whether the current client's visitor is in
9
+ * it (`assign` from `@decocms/blocks/experiments`), with the tests the
10
+ * client was given applied on top. Without a visitor every test it wasn't
11
+ * given is off.
12
+ */
13
+ export declare const splitTraffic: (allocations?: Record<string, number>) => Assignments;
14
+ /** Inputs of the built-in `experiment` rule. */
15
+ interface ExperimentProps {
16
+ /** A test in the saved block `experiments`. */
17
+ name?: string;
18
+ }
19
+ /**
20
+ * `experiment`: `true` when the current client's visitor is in the test
21
+ * `name` of the saved block `experiments`. An unknown name, no `experiments`
22
+ * block, or no visitor give `false`. The block is resolved once per client,
23
+ * however many rules ask.
24
+ */
25
+ export declare const experiment: ({ name }?: ExperimentProps) => boolean | Promise<boolean>;
26
+ export {};
27
+ //# sourceMappingURL=experiments.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"experiments.d.ts","sourceRoot":"","sources":["../../../src/v8/builtins/experiments.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,KAAK,WAAW,EAAU,MAAM,mBAAmB,CAAC;AAE7D,4EAA4E;AAC5E,eAAO,MAAM,iBAAiB,gBAAgB,CAAC;AAC/C,eAAO,MAAM,kBAAkB,kBAAkB,CAAC;AAElD,2CAA2C;AAC3C,eAAO,MAAM,eAAe,eAAe,CAAC;AAE5C;;;;;GAKG;AACH,eAAO,MAAM,YAAY,iBAAiB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KAAQ,WAUvE,CAAC;AAEF,gDAAgD;AAChD,UAAU,eAAe;IACvB,+CAA+C;IAC/C,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;;GAKG;AACH,eAAO,MAAM,UAAU,cAAc,eAAe,KAAQ,OAAO,GAAG,OAAO,CAAC,OAAO,CAMpF,CAAC"}
@@ -0,0 +1,62 @@
1
+ /**
2
+ * A/B tests as content (see /next/built-in-blocks#split-traffic): the
3
+ * built-in type `split-traffic`, which the saved block `experiments` has, and
4
+ * the built-in rule `experiment`.
5
+ *
6
+ * - `experiments` maps each test's name to the whole percentage of visitors
7
+ * in it (0–100: 0 off, 100 everyone). Resolving it gives each name and
8
+ * whether the client's visitor is in it, never a percentage.
9
+ * - `experiment { name }` is `true` when that answer is `true`.
10
+ *
11
+ * The visitor arrives as an argument to `cms.client({ visitor })`; these
12
+ * read it through `currentClient()`, before any `await`. A test the client
13
+ * is given (`cms.client({ experiments })`) is on or off as given, whatever
14
+ * the visitor and its percentage (a preview may switch on a test at 0%); a
15
+ * name the block doesn't have stays out.
16
+ */
17
+ import { currentClient, experimentOverrides } from "../current.js";
18
+ import { assign } from "../experiments.js";
19
+ /** The saved block every `experiment` rule reads, and its built-in type. */
20
+ export const EXPERIMENTS_BLOCK = "experiments";
21
+ export const SPLIT_TRAFFIC_TYPE = "split-traffic";
22
+ /** The built-in rule that reads a test. */
23
+ export const EXPERIMENT_RULE = "experiment";
24
+ /**
25
+ * `split-traffic`: each test and whether the current client's visitor is in
26
+ * it (`assign` from `@decocms/blocks/experiments`), with the tests the
27
+ * client was given applied on top. Without a visitor every test it wasn't
28
+ * given is off.
29
+ */
30
+ export const splitTraffic = (allocations = {}) => {
31
+ const client = currentClient();
32
+ const assignments = assign(allocations, client.visitor);
33
+ const given = experimentOverrides(client);
34
+ if (given !== undefined) {
35
+ for (const name of Object.keys(given)) {
36
+ if (Object.hasOwn(assignments, name))
37
+ assignments[name] = given[name] === true;
38
+ }
39
+ }
40
+ return assignments;
41
+ };
42
+ /**
43
+ * `experiment`: `true` when the current client's visitor is in the test
44
+ * `name` of the saved block `experiments`. An unknown name, no `experiments`
45
+ * block, or no visitor give `false`. The block is resolved once per client,
46
+ * however many rules ask.
47
+ */
48
+ export const experiment = ({ name } = {}) => {
49
+ const client = currentClient();
50
+ if (typeof name !== "string")
51
+ return false;
52
+ return client
53
+ .resolve(EXPERIMENTS_BLOCK)
54
+ .then(([tests]) => isTrueAt(tests, name));
55
+ };
56
+ function isTrueAt(record, name) {
57
+ return (typeof record === "object" &&
58
+ record !== null &&
59
+ Object.hasOwn(record, name) &&
60
+ record[name] === true);
61
+ }
62
+ //# sourceMappingURL=experiments.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"experiments.js","sourceRoot":"","sources":["../../../src/v8/builtins/experiments.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACnE,OAAO,EAAoB,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE7D,4EAA4E;AAC5E,MAAM,CAAC,MAAM,iBAAiB,GAAG,aAAa,CAAC;AAC/C,MAAM,CAAC,MAAM,kBAAkB,GAAG,eAAe,CAAC;AAElD,2CAA2C;AAC3C,MAAM,CAAC,MAAM,eAAe,GAAG,YAAY,CAAC;AAE5C;;;;;GAKG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,WAAW,GAA2B,EAAE,EAAe,EAAE;IACpF,MAAM,MAAM,GAAG,aAAa,EAAE,CAAC;IAC/B,MAAM,WAAW,GAAG,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;IACxD,MAAM,KAAK,GAAG,mBAAmB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EAAoE;AACpE,eAAO,MAAM,cAAc,EAAE,WAAW,CAAC,MAAM,CAAkC,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/v8/builtins/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AASjD;;;GAGG;AACH,eAAO,MAAM,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAa3D,CAAC;AAEH,oEAAoE;AACpE,eAAO,MAAM,cAAc,EAAE,WAAW,CAAC,MAAM,CAAkC,CAAC"}
@@ -1,6 +1,8 @@
1
+ import { CALENDAR_TYPE, calendar, campaign } from "./campaigns.js";
1
2
  import { cmsSettings, page, redirect, SETTINGS_TYPE } from "./data.js";
3
+ import { experiment, SPLIT_TRAFFIC_TYPE, splitTraffic } from "./experiments.js";
2
4
  import { lazy } from "./lazy.js";
3
- import { always, date, never } from "./matchers.js";
5
+ import { always, never } from "./matchers.js";
4
6
  import { multivariate } from "./multivariate.js";
5
7
  import { secretBlock } from "./secret.js";
6
8
  /**
@@ -12,11 +14,14 @@ export const builtIns = Object.freeze({
12
14
  multivariate,
13
15
  always,
14
16
  never,
15
- date,
17
+ experiment,
18
+ campaign,
16
19
  page,
17
20
  redirect,
18
21
  [SETTINGS_TYPE]: cmsSettings,
19
22
  secret: secretBlock(),
23
+ [SPLIT_TRAFFIC_TYPE]: splitTraffic,
24
+ [CALENDAR_TYPE]: calendar,
20
25
  });
21
26
  /** Names no saved block can take (see /next/saved-blocks#names). */
22
27
  export const RESERVED_NAMES = new Set(Object.keys(builtIns));
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/v8/builtins/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AACvE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CA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IACR,CAAC,aAAa,CAAC,EAAE,WAAW;IAC5B,MAAM,EAAE,WAAW,EAAE;IACrB,CAAC,kBAAkB,CAAC,EAAE,YAAY;IAClC,CAAC,aAAa,CAAC,EAAE,QAAQ;CAC1B,CAAC,CAAC;AAEH,oEAAoE;AACpE,MAAM,CAAC,MAAM,cAAc,GAAwB,IAAI,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC"}
@@ -2,18 +2,4 @@
2
2
  export declare const always: () => boolean;
3
3
  /** `never`: the rule the site editor uses to hide a block. */
4
4
  export declare const never: () => boolean;
5
- /** Inputs of the built-in `date` matcher: ISO 8601 strings, both optional. */
6
- interface DateProps {
7
- /** Inclusive. */
8
- start?: string;
9
- /** Exclusive: `end` itself doesn't match. */
10
- end?: string;
11
- }
12
- /**
13
- * `date`: `true` from `start` (inclusive) until `end` (exclusive). A date
14
- * without a time means midnight UTC. An unparseable bound never matches, so a
15
- * typo can't switch a campaign on.
16
- */
17
- export declare const date: ({ start, end }?: DateProps) => boolean;
18
- export {};
19
5
  //# sourceMappingURL=matchers.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"matchers.d.ts","sourceRoot":"","sources":["../../../src/v8/builtins/matchers.ts"],"names":[],"mappings":"AAAA,mCAAmC;AACnC,eAAO,MAAM,MAAM,QAAO,OAAe,CAAC;AAE1C,8DAA8D;AAC9D,eAAO,MAAM,KAAK,QAAO,OAAgB,CAAC;AAE1C,8EAA8E;AAC9E,UAAU,SAAS;IACjB,iBAAiB;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,6CAA6C;IAC7C,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED;;;;GAIG;AACH,eAAO,MAAM,IAAI,oBAAoB,SAAS,KAAQ,OAWrD,CAAC"}
1
+ {"version":3,"file":"matchers.d.ts","sourceRoot":"","sources":["../../../src/v8/builtins/matchers.ts"],"names":[],"mappings":"AAAA,mCAAmC;AACnC,eAAO,MAAM,MAAM,QAAO,OAAe,CAAC;AAE1C,8DAA8D;AAC9D,eAAO,MAAM,KAAK,QAAO,OAAgB,CAAC"}
@@ -2,23 +2,4 @@
2
2
  export const always = () => true;
3
3
  /** `never`: the rule the site editor uses to hide a block. */
4
4
  export const never = () => false;
5
- /**
6
- * `date`: `true` from `start` (inclusive) until `end` (exclusive). A date
7
- * without a time means midnight UTC. An unparseable bound never matches, so a
8
- * typo can't switch a campaign on.
9
- */
10
- export const date = ({ start, end } = {}) => {
11
- const now = Date.now();
12
- if (start !== undefined && start !== null && start !== "") {
13
- const from = Date.parse(start);
14
- if (Number.isNaN(from) || now < from)
15
- return false;
16
- }
17
- if (end !== undefined && end !== null && end !== "") {
18
- const until = Date.parse(end);
19
- if (Number.isNaN(until) || now >= until)
20
- return false;
21
- }
22
- return true;
23
- };
24
5
  //# sourceMappingURL=matchers.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"matchers.js","sourceRoot":"","sources":["../../../src/v8/builtins/matchers.ts"],"names":[],"mappings":"AAAA,mCAAmC;AACnC,MAAM,CAAC,MAAM,MAAM,GAAG,GAAY,EAAE,CAAC,IAAI,CAAC;AAE1C,8DAA8D;AAC9D,MAAM,CAAC,MAAM,KAAK,GAAG,GAAY,EAAE,CAAC,KAAK,CAAC;AAU1C;;;;GAIG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,GAAc,EAAE,EAAW,EAAE;IAC9D,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IACvB,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,EAAE,EAAE,CAAC;QAC1D,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAC/B,IAAI,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,GAAG,GAAG,IAAI;YAAE,OAAO,KAAK,CAAC;IACrD,CAAC;IACD,IAAI,GAAG,KAAK,SAAS,IAAI,GAAG,KAAK,IAAI,IAAI,GAAG,KAAK,EAAE,EAAE,CAAC;QACpD,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC9B,IAAI,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,GAAG,IAAI,KAAK;YAAE,OAAO,KAAK,CAAC;IACxD,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC"}
1
+ {"version":3,"file":"matchers.js","sourceRoot":"","sources":["../../../src/v8/builtins/matchers.ts"],"names":[],"mappings":"AAAA,mCAAmC;AACnC,MAAM,CAAC,MAAM,MAAM,GAAG,GAAY,EAAE,CAAC,IAAI,CAAC;AAE1C,8DAA8D;AAC9D,MAAM,CAAC,MAAM,KAAK,GAAG,GAAY,EAAE,CAAC,KAAK,CAAC"}
@@ -1,6 +1,12 @@
1
1
  /** Spec: built-in-blocks. Every block map gets these, in this order. */
2
2
  export declare const BUILT_IN_BLOCKS: readonly string[];
3
3
  export declare function isBuiltIn(name: string): boolean;
4
+ /**
5
+ * What relies on each built-in, in Studio and in the runtime: `deco check`
6
+ * names it when a block map replaces one (a site may mean to; it is told
7
+ * what it takes over, not that it's wrong).
8
+ */
9
+ export declare const BUILT_IN_USES: Readonly<Record<string, string>>;
4
10
  /**
5
11
  * The legacy alias table lives with the runtime's alias bridge, so the
6
12
  * schema, the content module and resolution share one list. The site
@@ -1 +1 @@
1
- {"version":3,"file":"builtins.d.ts","sourceRoot":"","sources":["../../../src/v8/cli/builtins.ts"],"names":[],"mappings":"AAMA,wEAAwE;AACxE,eAAO,MAAM,eAAe,EAAE,SAAS,MAAM,EAAwB,CAAC;AAEtE,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE/C;AAED;;;;;GAKG;AACH,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC"}
1
+ {"version":3,"file":"builtins.d.ts","sourceRoot":"","sources":["../../../src/v8/cli/builtins.ts"],"names":[],"mappings":"AAMA,wEAAwE;AACxE,eAAO,MAAM,eAAe,EAAE,SAAS,MAAM,EAAwB,CAAC;AAEtE,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE/C;AAED;;;;GAIG;AACH,eAAO,MAAM,aAAa,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAgBzD,CAAC;AAEH;;;;;GAKG;AACH,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC"}