@decocms/blocks 8.5.2 → 8.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/async/default.d.ts +10 -0
- package/dist/async/default.d.ts.map +1 -0
- package/dist/async/default.js +5 -0
- package/dist/async/default.js.map +1 -0
- package/dist/async/node.d.ts +3 -0
- package/dist/async/node.d.ts.map +1 -0
- package/dist/async/node.js +11 -0
- package/dist/async/node.js.map +1 -0
- package/dist/async/types.d.ts +6 -0
- package/dist/async/types.d.ts.map +1 -0
- package/dist/async/types.js +2 -0
- package/dist/async/types.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/v8/bucketing.d.ts +24 -0
- package/dist/v8/bucketing.d.ts.map +1 -0
- package/dist/v8/bucketing.js +78 -0
- package/dist/v8/bucketing.js.map +1 -0
- package/dist/v8/builtins/campaigns.d.ts +36 -0
- package/dist/v8/builtins/campaigns.d.ts.map +1 -0
- package/dist/v8/builtins/campaigns.js +107 -0
- package/dist/v8/builtins/campaigns.js.map +1 -0
- package/dist/v8/builtins/data.d.ts +2 -2
- package/dist/v8/builtins/data.js +2 -2
- package/dist/v8/builtins/experiments.d.ts +27 -0
- package/dist/v8/builtins/experiments.d.ts.map +1 -0
- package/dist/v8/builtins/experiments.js +62 -0
- package/dist/v8/builtins/experiments.js.map +1 -0
- package/dist/v8/builtins/index.d.ts.map +1 -1
- package/dist/v8/builtins/index.js +7 -2
- package/dist/v8/builtins/index.js.map +1 -1
- package/dist/v8/builtins/matchers.d.ts +0 -14
- package/dist/v8/builtins/matchers.d.ts.map +1 -1
- package/dist/v8/builtins/matchers.js +0 -19
- package/dist/v8/builtins/matchers.js.map +1 -1
- package/dist/v8/cli/builtins.d.ts +6 -0
- package/dist/v8/cli/builtins.d.ts.map +1 -1
- package/dist/v8/cli/builtins.js +19 -0
- package/dist/v8/cli/builtins.js.map +1 -1
- package/dist/v8/cli/check/index.d.ts.map +1 -1
- package/dist/v8/cli/check/index.js +231 -8
- package/dist/v8/cli/check/index.js.map +1 -1
- package/dist/v8/cli/schema/builtinSchemas.d.ts.map +1 -1
- package/dist/v8/cli/schema/builtinSchemas.js +76 -21
- package/dist/v8/cli/schema/builtinSchemas.js.map +1 -1
- package/dist/v8/cli/schema/generate.d.ts.map +1 -1
- package/dist/v8/cli/schema/generate.js +48 -2
- package/dist/v8/cli/schema/generate.js.map +1 -1
- package/dist/v8/client.d.ts +25 -0
- package/dist/v8/client.d.ts.map +1 -1
- package/dist/v8/client.js +58 -10
- package/dist/v8/client.js.map +1 -1
- package/dist/v8/cms.d.ts.map +1 -1
- package/dist/v8/cms.js +93 -42
- package/dist/v8/cms.js.map +1 -1
- package/dist/v8/content.d.ts +45 -0
- package/dist/v8/content.d.ts.map +1 -1
- package/dist/v8/content.js +68 -2
- package/dist/v8/content.js.map +1 -1
- package/dist/v8/current.d.ts +28 -0
- package/dist/v8/current.d.ts.map +1 -0
- package/dist/v8/current.js +77 -0
- package/dist/v8/current.js.map +1 -0
- package/dist/v8/draft.d.ts +40 -21
- package/dist/v8/draft.d.ts.map +1 -1
- package/dist/v8/draft.js +160 -25
- package/dist/v8/draft.js.map +1 -1
- package/dist/v8/experiments.d.ts +107 -0
- package/dist/v8/experiments.d.ts.map +1 -0
- package/dist/v8/experiments.js +292 -0
- package/dist/v8/experiments.js.map +1 -0
- package/dist/v8/hosts.d.ts +3 -2
- package/dist/v8/hosts.d.ts.map +1 -1
- package/dist/v8/hosts.js +3 -2
- package/dist/v8/hosts.js.map +1 -1
- package/dist/v8/index.d.ts +7 -5
- package/dist/v8/index.d.ts.map +1 -1
- package/dist/v8/index.js +6 -4
- package/dist/v8/index.js.map +1 -1
- package/dist/v8/remoteLoader.d.ts.map +1 -1
- package/dist/v8/remoteLoader.js +166 -20
- package/dist/v8/remoteLoader.js.map +1 -1
- package/dist/v8/resolver.d.ts +4 -2
- package/dist/v8/resolver.d.ts.map +1 -1
- package/dist/v8/resolver.js +11 -3
- package/dist/v8/resolver.js.map +1 -1
- package/dist/v8/settings.d.ts +16 -4
- package/dist/v8/settings.d.ts.map +1 -1
- package/dist/v8/settings.js +24 -21
- package/dist/v8/settings.js.map +1 -1
- package/dist/v8/types.d.ts +126 -21
- package/dist/v8/types.d.ts.map +1 -1
- package/package.json +35 -1
- package/src/async/default.ts +13 -0
- package/src/async/node.ts +12 -0
- package/src/async/types.ts +5 -0
- package/src/index.ts +4 -0
- package/src/v8/bucketing.ts +88 -0
- package/src/v8/builtins/campaigns.ts +120 -0
- package/src/v8/builtins/data.ts +2 -2
- package/src/v8/builtins/experiments.ts +72 -0
- package/src/v8/builtins/index.ts +7 -2
- package/src/v8/builtins/matchers.ts +0 -26
- package/src/v8/cli/builtins.ts +23 -0
- package/src/v8/cli/check/index.ts +289 -8
- package/src/v8/cli/schema/builtinSchemas.ts +82 -22
- package/src/v8/cli/schema/generate.ts +48 -3
- package/src/v8/client.ts +76 -10
- package/src/v8/cms.ts +108 -43
- package/src/v8/content.ts +86 -2
- package/src/v8/current.ts +98 -0
- package/src/v8/draft.ts +170 -30
- package/src/v8/experiments.ts +340 -0
- package/src/v8/hosts.ts +3 -2
- package/src/v8/index.ts +8 -4
- package/src/v8/remoteLoader.ts +190 -25
- package/src/v8/resolver.ts +14 -4
- package/src/v8/settings.ts +35 -29
- package/src/v8/types.ts +128 -19
package/src/v8/builtins/index.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { BlockFunction } from "../types.ts";
|
|
2
|
+
import { CALENDAR_TYPE, calendar, campaign } from "./campaigns.ts";
|
|
2
3
|
import { cmsSettings, page, redirect, SETTINGS_TYPE } from "./data.ts";
|
|
4
|
+
import { experiment, SPLIT_TRAFFIC_TYPE, splitTraffic } from "./experiments.ts";
|
|
3
5
|
import { lazy } from "./lazy.ts";
|
|
4
|
-
import { always,
|
|
6
|
+
import { always, never } from "./matchers.ts";
|
|
5
7
|
import { multivariate } from "./multivariate.ts";
|
|
6
8
|
import { secretBlock } from "./secret.ts";
|
|
7
9
|
|
|
@@ -14,11 +16,14 @@ export const builtIns: Readonly<Record<string, BlockFunction>> = Object.freeze({
|
|
|
14
16
|
multivariate,
|
|
15
17
|
always,
|
|
16
18
|
never,
|
|
17
|
-
|
|
19
|
+
experiment,
|
|
20
|
+
campaign,
|
|
18
21
|
page,
|
|
19
22
|
redirect,
|
|
20
23
|
[SETTINGS_TYPE]: cmsSettings,
|
|
21
24
|
secret: secretBlock(),
|
|
25
|
+
[SPLIT_TRAFFIC_TYPE]: splitTraffic,
|
|
26
|
+
[CALENDAR_TYPE]: calendar,
|
|
22
27
|
});
|
|
23
28
|
|
|
24
29
|
/** Names no saved block can take (see /next/saved-blocks#names). */
|
|
@@ -3,29 +3,3 @@ export const always = (): boolean => true;
|
|
|
3
3
|
|
|
4
4
|
/** `never`: the rule the site editor uses to hide a block. */
|
|
5
5
|
export const never = (): boolean => false;
|
|
6
|
-
|
|
7
|
-
/** Inputs of the built-in `date` matcher: ISO 8601 strings, both optional. */
|
|
8
|
-
interface DateProps {
|
|
9
|
-
/** Inclusive. */
|
|
10
|
-
start?: string;
|
|
11
|
-
/** Exclusive: `end` itself doesn't match. */
|
|
12
|
-
end?: string;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* `date`: `true` from `start` (inclusive) until `end` (exclusive). A date
|
|
17
|
-
* without a time means midnight UTC. An unparseable bound never matches, so a
|
|
18
|
-
* typo can't switch a campaign on.
|
|
19
|
-
*/
|
|
20
|
-
export const date = ({ start, end }: DateProps = {}): boolean => {
|
|
21
|
-
const now = Date.now();
|
|
22
|
-
if (start !== undefined && start !== null && start !== "") {
|
|
23
|
-
const from = Date.parse(start);
|
|
24
|
-
if (Number.isNaN(from) || now < from) return false;
|
|
25
|
-
}
|
|
26
|
-
if (end !== undefined && end !== null && end !== "") {
|
|
27
|
-
const until = Date.parse(end);
|
|
28
|
-
if (Number.isNaN(until) || now >= until) return false;
|
|
29
|
-
}
|
|
30
|
-
return true;
|
|
31
|
-
};
|
package/src/v8/cli/builtins.ts
CHANGED
|
@@ -11,6 +11,29 @@ export function isBuiltIn(name: string): boolean {
|
|
|
11
11
|
return RESERVED_NAMES.has(name);
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
/**
|
|
15
|
+
* What relies on each built-in, in Studio and in the runtime: `deco check`
|
|
16
|
+
* names it when a block map replaces one (a site may mean to; it is told
|
|
17
|
+
* what it takes over, not that it's wrong).
|
|
18
|
+
*/
|
|
19
|
+
export const BUILT_IN_USES: Readonly<Record<string, string>> = Object.freeze({
|
|
20
|
+
lazy: "every Lazy<T> field relies on it, such as a variant's value, which runs only when chosen",
|
|
21
|
+
multivariate: "Studio's variants, the fields whose value changes by rule, rely on it",
|
|
22
|
+
always: "the default variant Studio adds to each list of variants relies on it",
|
|
23
|
+
never: "a variant Studio turns off relies on it",
|
|
24
|
+
experiment:
|
|
25
|
+
"Studio's A/B test rules rely on it, each naming a test of the saved block experiments",
|
|
26
|
+
campaign:
|
|
27
|
+
"Studio's campaign rules rely on it, each naming a campaign of the saved block campaigns",
|
|
28
|
+
page: "Studio's page list and page editor rely on it",
|
|
29
|
+
redirect: "Studio's redirect list relies on it",
|
|
30
|
+
"cms-settings": "the saved block CMS relies on it, and Studio's settings edit that block",
|
|
31
|
+
secret: "Studio's secret fields rely on it to keep their values encrypted",
|
|
32
|
+
"split-traffic":
|
|
33
|
+
"the saved block experiments relies on it, and Studio's Experiments view edits its percentages",
|
|
34
|
+
calendar: "the saved block campaigns relies on it, and Studio's Campaigns view edits its dates",
|
|
35
|
+
});
|
|
36
|
+
|
|
14
37
|
/**
|
|
15
38
|
* The legacy alias table lives with the runtime's alias bridge, so the
|
|
16
39
|
* schema, the content module and resolution share one list. The site
|
|
@@ -21,10 +21,21 @@ import fs from "node:fs";
|
|
|
21
21
|
import { Ajv, type ValidateFunction } from "ajv";
|
|
22
22
|
import { isWellFormedCiphertext } from "../../../protocol/secrets.ts";
|
|
23
23
|
import { BLOCKS_MAJOR } from "../../../protocol/types.ts";
|
|
24
|
+
import {
|
|
25
|
+
CALENDAR_TYPE,
|
|
26
|
+
CAMPAIGN_RULE,
|
|
27
|
+
CAMPAIGNS_BLOCK,
|
|
28
|
+
campaignTime,
|
|
29
|
+
} from "../../builtins/campaigns.ts";
|
|
24
30
|
import { SETTINGS_BLOCK, SETTINGS_TYPE } from "../../builtins/data.ts";
|
|
31
|
+
import {
|
|
32
|
+
EXPERIMENT_RULE,
|
|
33
|
+
EXPERIMENTS_BLOCK,
|
|
34
|
+
SPLIT_TRAFFIC_TYPE,
|
|
35
|
+
} from "../../builtins/experiments.ts";
|
|
25
36
|
import { isBlock, own } from "../../json.ts";
|
|
26
37
|
import { findRouteConflicts } from "../../matchRoute.ts";
|
|
27
|
-
import { isBuiltIn, storesPlainVariants } from "../builtins.ts";
|
|
38
|
+
import { BUILT_IN_BLOCKS, BUILT_IN_USES, isBuiltIn, storesPlainVariants } from "../builtins.ts";
|
|
28
39
|
import { paint } from "../color.ts";
|
|
29
40
|
import { readSavedBlocks, type SavedBlocks } from "../content.ts";
|
|
30
41
|
import { consoleReporter, type Reporter } from "../log.ts";
|
|
@@ -73,12 +84,36 @@ function blockDefinitionName(schema: Json): string | null {
|
|
|
73
84
|
return e && e.length === 1 && typeof schema.title === "string" && !schema.format ? e[0] : null;
|
|
74
85
|
}
|
|
75
86
|
|
|
76
|
-
/** Prerelease built-ins folded into the CMS settings block, with no alias. */
|
|
87
|
+
/** Prerelease built-ins folded into the CMS settings block, or renamed, with no alias. */
|
|
77
88
|
const FOLDED_BUILT_INS: Record<string, string> = {
|
|
78
89
|
telemetry: `the built-in is now the telemetry section of the "${SETTINGS_BLOCK}" block (type "${SETTINGS_TYPE}"); see /next/renames-and-migrations#site-settings`,
|
|
79
90
|
analytics: `the built-in is now the analytics section of the "${SETTINGS_BLOCK}" block (type "${SETTINGS_TYPE}"); see /next/renames-and-migrations#site-settings`,
|
|
91
|
+
"date-windows": `the built-in is now "${CALENDAR_TYPE}": set the saved block "${CAMPAIGNS_BLOCK}" to { "__resolveType": "${CALENDAR_TYPE}", … }`,
|
|
80
92
|
};
|
|
81
93
|
|
|
94
|
+
/** A `CMS` block saved with preview hosts, which Studio keeps now (in the release it publishes). */
|
|
95
|
+
const PREVIEW_FIELD_GONE =
|
|
96
|
+
"the site editor now keeps the addresses this site can be previewed on, so this field isn't read any more: you can delete it";
|
|
97
|
+
|
|
98
|
+
/** The prerelease `date` rule, which the `campaign` rule replaced. */
|
|
99
|
+
const OLD_DATE_RULE = "date";
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* What to write instead of a prerelease `date` rule: one naming a campaign
|
|
103
|
+
* becomes a `campaign` rule; one with its dates inline moves them into a
|
|
104
|
+
* campaign first.
|
|
105
|
+
*/
|
|
106
|
+
function oldDateRuleProblem(block: Record<string, Json>): string {
|
|
107
|
+
const rule = `{ "__resolveType": "${CAMPAIGN_RULE}", "name": … }`;
|
|
108
|
+
if (typeof block.campaign === "string") {
|
|
109
|
+
return `unknown block type "${OLD_DATE_RULE}": the date rule is now "${CAMPAIGN_RULE}", so write { "__resolveType": "${CAMPAIGN_RULE}", "name": ${JSON.stringify(block.campaign)} }`;
|
|
110
|
+
}
|
|
111
|
+
if ("start" in block || "end" in block) {
|
|
112
|
+
return `unknown block type "${OLD_DATE_RULE}": this date rule has its dates inline; move them into a campaign of the saved block "${CAMPAIGNS_BLOCK}" (type "${CALENDAR_TYPE}") and write ${rule} naming it`;
|
|
113
|
+
}
|
|
114
|
+
return `unknown block type "${OLD_DATE_RULE}": the date rule is now "${CAMPAIGN_RULE}": write ${rule} naming a campaign of the saved block "${CAMPAIGNS_BLOCK}"`;
|
|
115
|
+
}
|
|
116
|
+
|
|
82
117
|
// ---------------------------------------------------------------------------
|
|
83
118
|
// The validation document: the schema, with every field also accepting a block
|
|
84
119
|
// ---------------------------------------------------------------------------
|
|
@@ -216,8 +251,10 @@ function isDate(value: string): boolean {
|
|
|
216
251
|
/**
|
|
217
252
|
* The formats `deco check` enforces: the standard ones the schema's widgets
|
|
218
253
|
* write (`@format date`, `date-time`, `uri`). A date-time is a date, `T` (or a
|
|
219
|
-
* space) and a time whose seconds and zone are optional
|
|
220
|
-
* the site editor's date-time
|
|
254
|
+
* space) and a time whose seconds and zone are optional: content written by
|
|
255
|
+
* hand or by older tools may leave them out (the site editor's date-time
|
|
256
|
+
* picker saves the offset, as in `2026-11-27T00:00:00-03:00`). A campaign
|
|
257
|
+
* bound needs the offset, which `unreadableBound` checks. Every other format names a
|
|
221
258
|
* site-editor widget (`image-uri`, `color`, `rich-text`, …), not a rule, so it
|
|
222
259
|
* accepts any string.
|
|
223
260
|
*/
|
|
@@ -230,6 +267,35 @@ const STANDARD_FORMATS: Record<string, (value: string) => boolean> = {
|
|
|
230
267
|
uri: (value) => /^[a-z][a-z0-9+.-]*:/i.test(value) && URL.canParse(value),
|
|
231
268
|
};
|
|
232
269
|
|
|
270
|
+
/** The offset the examples in campaign messages show (São Paulo), to replace with the store's own. */
|
|
271
|
+
const CAMPAIGN_EXAMPLE_OFFSET = "-03:00";
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Why `deco check` rejects a campaign bound the runtime can't read
|
|
275
|
+
* (`campaignTime` is null), or null when it reads or is left to the generic
|
|
276
|
+
* date-time format error (not a date at all). A date or a date-time without
|
|
277
|
+
* an offset names a different moment depending on where it is read, so the
|
|
278
|
+
* message says to add the store's offset.
|
|
279
|
+
*/
|
|
280
|
+
function unreadableBound(campaign: string, bound: "start" | "end", value: unknown): string | null {
|
|
281
|
+
if (typeof value !== "string" || value === "" || campaignTime(value) !== null) return null;
|
|
282
|
+
const verb = bound === "start" ? "starts" : "ends";
|
|
283
|
+
const what = `the campaign "${campaign}" ${verb} at ${JSON.stringify(value)}`;
|
|
284
|
+
if (isDate(value)) {
|
|
285
|
+
const like = `${value}T00:00${CAMPAIGN_EXAMPLE_OFFSET}`;
|
|
286
|
+
return `${what}, a date without a time or offset, so it never runs: add the time and your store's offset, like ${JSON.stringify(like)}`;
|
|
287
|
+
}
|
|
288
|
+
if (!STANDARD_FORMATS["date-time"]?.(value)) return null;
|
|
289
|
+
const iso = `${value.slice(0, 10)}T${value.slice(11)}`;
|
|
290
|
+
if (!/(?:z|[+-]\d{2}:?\d{2})$/i.test(value)) {
|
|
291
|
+
const like = `${iso}${CAMPAIGN_EXAMPLE_OFFSET}`;
|
|
292
|
+
return `${what}, which has no offset, so it never runs: add your store's offset, like ${JSON.stringify(like)}`;
|
|
293
|
+
}
|
|
294
|
+
const fixed = iso.replace(/z$/i, "Z").replace(/([+-]\d{2})(\d{2})$/, "$1:$2");
|
|
295
|
+
const like = campaignTime(fixed) === null ? `${value.slice(0, 10)}T00:00Z` : fixed;
|
|
296
|
+
return `${what}, which isn't written as a campaign reads it, so it never runs: write the date, "T", the time and the offset as Z or ±hh:mm, like ${JSON.stringify(like)}`;
|
|
297
|
+
}
|
|
298
|
+
|
|
233
299
|
function formatsFor(doc: Json): Record<string, true | ((value: string) => boolean)> {
|
|
234
300
|
const formats: Record<string, true | ((value: string) => boolean)> = { ...STANDARD_FORMATS };
|
|
235
301
|
const seen = new Set<object>();
|
|
@@ -372,6 +438,112 @@ class Checker {
|
|
|
372
438
|
return this.underlyingType(entry.__resolveType, [...chain, name]);
|
|
373
439
|
}
|
|
374
440
|
|
|
441
|
+
/**
|
|
442
|
+
* Whether `name` is the built-in itself here: the block map didn't define
|
|
443
|
+
* the same key (which replaces the built-in, schema included).
|
|
444
|
+
*/
|
|
445
|
+
private isOwnBuiltIn(name: string): boolean {
|
|
446
|
+
return isBuiltIn(name) && this.siteNamespaceOf(name) === undefined;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
/** The namespace of the block map's own entry named `name`, if it has one. */
|
|
450
|
+
private siteNamespaceOf(name: string): string | undefined {
|
|
451
|
+
for (const entries of Object.values(this.meta.manifest?.blocks ?? {})) {
|
|
452
|
+
const entry = own(entries, name) as { namespace?: unknown } | undefined;
|
|
453
|
+
if (entry && entry.namespace !== "deco") return String(entry.namespace ?? "site");
|
|
454
|
+
}
|
|
455
|
+
return undefined;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
/**
|
|
459
|
+
* The names in the saved block `name` (the tests of `experiments`, the
|
|
460
|
+
* campaigns of `campaigns`), or null when there is no such block of `type`.
|
|
461
|
+
*/
|
|
462
|
+
private savedNames(name: string, type: string): Set<string> | null {
|
|
463
|
+
const entry = own(this.saved.blocks, name);
|
|
464
|
+
if (!isBlock(entry) || this.canonicalType(entry.__resolveType) !== type) return null;
|
|
465
|
+
return new Set(Object.keys(entry).filter((key) => key !== "__resolveType"));
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
/**
|
|
469
|
+
* The inputs a built-in `rule` (`experiment`, `campaign`) gets: the block's own,
|
|
470
|
+
* inline or over the saved block it names (whose inputs it may override).
|
|
471
|
+
* Undefined for any other block, or when the block map replaces the built-in.
|
|
472
|
+
*/
|
|
473
|
+
private ruleInputs(block: Json, rule: string): Record<string, Json> | undefined {
|
|
474
|
+
if (!isBlock(block) || !this.isOwnBuiltIn(rule)) return undefined;
|
|
475
|
+
if (this.canonicalType(block.__resolveType) !== null) {
|
|
476
|
+
return this.canonicalType(block.__resolveType) === rule ? block : undefined;
|
|
477
|
+
}
|
|
478
|
+
const saved = own(this.saved.blocks, block.__resolveType);
|
|
479
|
+
if (!isBlock(saved) || this.canonicalType(saved.__resolveType) !== rule) return undefined;
|
|
480
|
+
return { ...saved, ...block };
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
/** Whether `type` is the built-in `calendar` (not one the block map replaces). */
|
|
484
|
+
private isCalendar(type: unknown): boolean {
|
|
485
|
+
return this.canonicalType(type as string) === CALENDAR_TYPE && this.isOwnBuiltIn(CALENDAR_TYPE);
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
/**
|
|
489
|
+
* A `calendar` block wherever it is (the saved block `campaigns`, another
|
|
490
|
+
* saved block, or inline in a section's props): its props, then the dates
|
|
491
|
+
* of every campaign in it, whose own messages replace the generic
|
|
492
|
+
* date-time format error at the same path.
|
|
493
|
+
*/
|
|
494
|
+
private checkCalendar(ctx: Context, block: Record<string, Json>, path: string): void {
|
|
495
|
+
const before = ctx.problems.length;
|
|
496
|
+
this.checkProps(ctx, block, path, true);
|
|
497
|
+
const found = ctx.problems.splice(before);
|
|
498
|
+
const dates = this.checkCampaignWindows(ctx, block, path);
|
|
499
|
+
ctx.problems.push(
|
|
500
|
+
...found.filter((p) => !(dates.has(p.path) && p.message.endsWith("isn't a valid date-time"))),
|
|
501
|
+
);
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
/**
|
|
505
|
+
* Each campaign of a `calendar` block with a bound the runtime can't read
|
|
506
|
+
* (a date without a time, a date-time without an offset, or one not written
|
|
507
|
+
* as ISO 8601: `campaignTime`), which is an error since that campaign never
|
|
508
|
+
* runs, or whose end isn't after its start. Returns the paths of the dates
|
|
509
|
+
* reported here, whose generic format error says less and is dropped.
|
|
510
|
+
*/
|
|
511
|
+
private checkCampaignWindows(
|
|
512
|
+
ctx: Context,
|
|
513
|
+
entry: Record<string, Json>,
|
|
514
|
+
path: string,
|
|
515
|
+
): Set<string> {
|
|
516
|
+
const reported = new Set<string>();
|
|
517
|
+
for (const key of Object.keys(entry).sort()) {
|
|
518
|
+
if (key === "__resolveType") continue;
|
|
519
|
+
const window = entry[key];
|
|
520
|
+
if (!isObject(window)) continue;
|
|
521
|
+
const { start, end } = window;
|
|
522
|
+
const at = (bound: string) =>
|
|
523
|
+
joinPath(path, `/${key.replace(/~/g, "~0").replace(/\//g, "~1")}/${bound}`);
|
|
524
|
+
for (const [bound, value] of [
|
|
525
|
+
["start", start],
|
|
526
|
+
["end", end],
|
|
527
|
+
] as const) {
|
|
528
|
+
const problem = unreadableBound(key, bound, value);
|
|
529
|
+
if (problem === null) continue;
|
|
530
|
+
reported.add(at(bound));
|
|
531
|
+
this.report(ctx, at(bound), problem);
|
|
532
|
+
}
|
|
533
|
+
if (typeof start !== "string" || typeof end !== "string") continue;
|
|
534
|
+
const from = campaignTime(start);
|
|
535
|
+
const until = campaignTime(end);
|
|
536
|
+
if (typeof from !== "number" || typeof until !== "number" || until > from) continue;
|
|
537
|
+
this.report(
|
|
538
|
+
ctx,
|
|
539
|
+
at("end"),
|
|
540
|
+
`the campaign "${key}" ends before it starts, so it never runs: set an end after the start`,
|
|
541
|
+
"warning",
|
|
542
|
+
);
|
|
543
|
+
}
|
|
544
|
+
return reported;
|
|
545
|
+
}
|
|
546
|
+
|
|
375
547
|
private report(
|
|
376
548
|
ctx: Context,
|
|
377
549
|
path: string,
|
|
@@ -493,9 +665,11 @@ class Checker {
|
|
|
493
665
|
this.report(
|
|
494
666
|
ctx,
|
|
495
667
|
path,
|
|
496
|
-
|
|
497
|
-
?
|
|
498
|
-
:
|
|
668
|
+
name === OLD_DATE_RULE
|
|
669
|
+
? oldDateRuleProblem(block)
|
|
670
|
+
: Object.hasOwn(FOLDED_BUILT_INS, name)
|
|
671
|
+
? `unknown block type "${name}": ${FOLDED_BUILT_INS[name]}`
|
|
672
|
+
: `unknown block type "${name}"`,
|
|
499
673
|
);
|
|
500
674
|
return;
|
|
501
675
|
}
|
|
@@ -521,7 +695,8 @@ class Checker {
|
|
|
521
695
|
const target = this.saved.blocks[name];
|
|
522
696
|
const targetType = String(target.__resolveType);
|
|
523
697
|
const merged = { ...target, ...block, __resolveType: targetType };
|
|
524
|
-
if (this.
|
|
698
|
+
if (this.isCalendar(targetType)) this.checkCalendar(ctx, merged, path);
|
|
699
|
+
else if (this.canonicalType(targetType)) this.checkProps(ctx, merged, path, true);
|
|
525
700
|
}
|
|
526
701
|
return;
|
|
527
702
|
}
|
|
@@ -538,6 +713,10 @@ class Checker {
|
|
|
538
713
|
return;
|
|
539
714
|
}
|
|
540
715
|
|
|
716
|
+
if (this.isCalendar(name)) {
|
|
717
|
+
this.checkCalendar(ctx, block, path);
|
|
718
|
+
return;
|
|
719
|
+
}
|
|
541
720
|
switch (type) {
|
|
542
721
|
case "multivariate":
|
|
543
722
|
this.checkVariants(ctx, block, path, field);
|
|
@@ -555,6 +734,47 @@ class Checker {
|
|
|
555
734
|
}
|
|
556
735
|
return;
|
|
557
736
|
}
|
|
737
|
+
case EXPERIMENT_RULE: {
|
|
738
|
+
this.checkProps(ctx, block, path, true);
|
|
739
|
+
const name = this.ruleInputs(block, EXPERIMENT_RULE)?.name;
|
|
740
|
+
if (
|
|
741
|
+
typeof name === "string" &&
|
|
742
|
+
!this.savedNames(EXPERIMENTS_BLOCK, SPLIT_TRAFFIC_TYPE)?.has(name)
|
|
743
|
+
) {
|
|
744
|
+
this.report(
|
|
745
|
+
ctx,
|
|
746
|
+
joinPath(path, "/name"),
|
|
747
|
+
`no test "${name}" in the saved block "${EXPERIMENTS_BLOCK}": this rule is always false`,
|
|
748
|
+
"warning",
|
|
749
|
+
);
|
|
750
|
+
}
|
|
751
|
+
return;
|
|
752
|
+
}
|
|
753
|
+
case CAMPAIGN_RULE: {
|
|
754
|
+
this.checkProps(ctx, block, path, true);
|
|
755
|
+
const inputs = this.ruleInputs(block, CAMPAIGN_RULE);
|
|
756
|
+
const campaign = inputs?.name;
|
|
757
|
+
if (inputs !== undefined && typeof campaign !== "string") {
|
|
758
|
+
this.report(
|
|
759
|
+
ctx,
|
|
760
|
+
path,
|
|
761
|
+
`this campaign rule names no campaign, so it is always false: name a campaign of the saved block "${CAMPAIGNS_BLOCK}" (name)`,
|
|
762
|
+
"warning",
|
|
763
|
+
);
|
|
764
|
+
}
|
|
765
|
+
if (
|
|
766
|
+
typeof campaign === "string" &&
|
|
767
|
+
!this.savedNames(CAMPAIGNS_BLOCK, CALENDAR_TYPE)?.has(campaign)
|
|
768
|
+
) {
|
|
769
|
+
this.report(
|
|
770
|
+
ctx,
|
|
771
|
+
joinPath(path, "/name"),
|
|
772
|
+
`no campaign "${campaign}" in the saved block "${CAMPAIGNS_BLOCK}": this rule is always false`,
|
|
773
|
+
"warning",
|
|
774
|
+
);
|
|
775
|
+
}
|
|
776
|
+
return;
|
|
777
|
+
}
|
|
558
778
|
default:
|
|
559
779
|
this.checkProps(ctx, block, path, true);
|
|
560
780
|
}
|
|
@@ -674,12 +894,73 @@ class Checker {
|
|
|
674
894
|
"warning",
|
|
675
895
|
);
|
|
676
896
|
}
|
|
897
|
+
if (
|
|
898
|
+
name === EXPERIMENTS_BLOCK &&
|
|
899
|
+
this.canonicalType(entry.__resolveType) !== SPLIT_TRAFFIC_TYPE
|
|
900
|
+
) {
|
|
901
|
+
this.report(
|
|
902
|
+
ctx,
|
|
903
|
+
"",
|
|
904
|
+
`"${EXPERIMENTS_BLOCK}" is the saved block every experiment rule reads, of type ` +
|
|
905
|
+
`"${SPLIT_TRAFFIC_TYPE}"; with type "${entry.__resolveType}" every experiment rule is false`,
|
|
906
|
+
"warning",
|
|
907
|
+
);
|
|
908
|
+
}
|
|
909
|
+
if (name === CAMPAIGNS_BLOCK && this.isOwnBuiltIn(CALENDAR_TYPE)) {
|
|
910
|
+
if (this.canonicalType(entry.__resolveType) !== CALENDAR_TYPE) {
|
|
911
|
+
this.report(
|
|
912
|
+
ctx,
|
|
913
|
+
"",
|
|
914
|
+
`"${CAMPAIGNS_BLOCK}" is the saved block every campaign rule reads, of type ` +
|
|
915
|
+
`"${CALENDAR_TYPE}"; with type "${entry.__resolveType}" every campaign rule is false`,
|
|
916
|
+
"warning",
|
|
917
|
+
);
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
if (
|
|
921
|
+
name === SETTINGS_BLOCK &&
|
|
922
|
+
entry.__resolveType === SETTINGS_TYPE &&
|
|
923
|
+
Object.hasOwn(entry, "preview")
|
|
924
|
+
) {
|
|
925
|
+
// Saved by an earlier version: Studio now keeps where the site previews.
|
|
926
|
+
const before = problems.length;
|
|
927
|
+
this.checkBlock(ctx, entry, "", null);
|
|
928
|
+
const found = problems.splice(before);
|
|
929
|
+
problems.push(
|
|
930
|
+
...found.filter((p) => p.path !== "preview" && !p.path.startsWith("preview.")),
|
|
931
|
+
);
|
|
932
|
+
this.report(ctx, "preview", PREVIEW_FIELD_GONE, "warning");
|
|
933
|
+
continue;
|
|
934
|
+
}
|
|
677
935
|
this.checkBlock(ctx, entry, "", null);
|
|
678
936
|
}
|
|
937
|
+
problems.push(...this.builtInOverrides());
|
|
679
938
|
problems.push(...this.routeProblems());
|
|
680
939
|
return problems;
|
|
681
940
|
}
|
|
682
941
|
|
|
942
|
+
/**
|
|
943
|
+
* A block map entry named after a built-in replaces it, schema included.
|
|
944
|
+
* Often deliberate (a site's own `page` with fields of its own), so a
|
|
945
|
+
* warning that says what relies on the built-in, never an error.
|
|
946
|
+
*/
|
|
947
|
+
private builtInOverrides(): Problem[] {
|
|
948
|
+
const problems: Problem[] = [];
|
|
949
|
+
for (const name of BUILT_IN_BLOCKS) {
|
|
950
|
+
if (this.siteNamespaceOf(name) === undefined) continue;
|
|
951
|
+
problems.push({
|
|
952
|
+
file: ".deco/schema.gen.json",
|
|
953
|
+
path: name,
|
|
954
|
+
severity: "warning",
|
|
955
|
+
message:
|
|
956
|
+
`the block map has its own "${name}", in place of the built-in: ` +
|
|
957
|
+
`${BUILT_IN_USES[name] ?? "Studio relies on it"}. If that's intended, keep the ` +
|
|
958
|
+
"built-in's fields; to use the built-in again, rename yours",
|
|
959
|
+
});
|
|
960
|
+
}
|
|
961
|
+
return problems;
|
|
962
|
+
}
|
|
963
|
+
|
|
683
964
|
private routeProblems(): Problem[] {
|
|
684
965
|
type RouteEntry = { name: string; path: string };
|
|
685
966
|
const routes: RouteEntry[] = [];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The forms of the
|
|
2
|
+
* The forms of the twelve built-in blocks (spec: built-in-blocks, and the types
|
|
3
3
|
* in api-reference › Types). They're always in the schema, unless the block
|
|
4
4
|
* map declares the same key, which replaces the built-in.
|
|
5
5
|
*/
|
|
@@ -12,11 +12,14 @@ export const BUILT_IN_GROUPS: Record<string, ManifestGroup> = {
|
|
|
12
12
|
multivariate: "loaders",
|
|
13
13
|
always: "matchers",
|
|
14
14
|
never: "matchers",
|
|
15
|
-
|
|
15
|
+
experiment: "matchers",
|
|
16
|
+
campaign: "matchers",
|
|
16
17
|
page: "pages",
|
|
17
18
|
redirect: "redirects",
|
|
18
19
|
"cms-settings": "content",
|
|
19
20
|
secret: "loaders",
|
|
21
|
+
"split-traffic": "content",
|
|
22
|
+
calendar: "content",
|
|
20
23
|
};
|
|
21
24
|
|
|
22
25
|
const BUILT_IN_DOCS: Record<string, { title: string; description: string; icon?: string }> = {
|
|
@@ -28,21 +31,69 @@ const BUILT_IN_DOCS: Record<string, { title: string; description: string; icon?:
|
|
|
28
31
|
},
|
|
29
32
|
always: { title: "Always", description: "Always true: the fallback variant", icon: "eye" },
|
|
30
33
|
never: { title: "Never", description: "Always false: hides a block", icon: "eye-off" },
|
|
31
|
-
|
|
32
|
-
title: "
|
|
33
|
-
description: "True
|
|
34
|
+
experiment: {
|
|
35
|
+
title: "A/B test",
|
|
36
|
+
description: "True for the visitors in a test of the saved block experiments",
|
|
37
|
+
icon: "flask",
|
|
38
|
+
},
|
|
39
|
+
campaign: {
|
|
40
|
+
title: "Campaign",
|
|
41
|
+
description: "True while a campaign of the saved block campaigns is running",
|
|
34
42
|
icon: "calendar-event",
|
|
35
43
|
},
|
|
36
44
|
page: { title: "Page", description: "A page at a URL" },
|
|
37
45
|
redirect: { title: "Redirect", description: "Sends one URL to another" },
|
|
38
46
|
"cms-settings": {
|
|
39
47
|
title: "CMS settings",
|
|
40
|
-
description: "
|
|
48
|
+
description: "Telemetry and analytics: the saved block named CMS",
|
|
41
49
|
icon: "settings",
|
|
42
50
|
},
|
|
51
|
+
"split-traffic": {
|
|
52
|
+
title: "Split traffic",
|
|
53
|
+
description:
|
|
54
|
+
"A/B tests: each name with the percentage of visitors in it (0 off, 100 everyone); resolves to whether the visitor is in each. The type of the saved block experiments",
|
|
55
|
+
icon: "flask",
|
|
56
|
+
},
|
|
57
|
+
calendar: {
|
|
58
|
+
title: "Calendar",
|
|
59
|
+
description:
|
|
60
|
+
"Campaigns: each name with its start and end; resolves to whether each is running now. The type of the saved block campaigns",
|
|
61
|
+
icon: "calendar-event",
|
|
62
|
+
},
|
|
43
63
|
secret: { title: "Secret", description: "An encrypted value, decrypted on the server" },
|
|
44
64
|
};
|
|
45
65
|
|
|
66
|
+
/** The form of each test in a `split-traffic` block: a whole percentage. */
|
|
67
|
+
const ALLOCATION = {
|
|
68
|
+
type: "integer",
|
|
69
|
+
title: "Visitors in (%)",
|
|
70
|
+
description: "0 turns the test off, 100 shows it to everyone",
|
|
71
|
+
minimum: 0,
|
|
72
|
+
maximum: 100,
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
/** The form of each campaign in a `calendar` block: one window, both bounds optional. */
|
|
76
|
+
const CAMPAIGN_DATES = {
|
|
77
|
+
type: "object",
|
|
78
|
+
title: "Campaign dates",
|
|
79
|
+
properties: {
|
|
80
|
+
start: {
|
|
81
|
+
type: "string",
|
|
82
|
+
format: "date-time",
|
|
83
|
+
title: "Start",
|
|
84
|
+
description:
|
|
85
|
+
"The campaign runs from this moment on: a date and time with your store's offset (empty: since always)",
|
|
86
|
+
},
|
|
87
|
+
end: {
|
|
88
|
+
type: "string",
|
|
89
|
+
format: "date-time",
|
|
90
|
+
title: "End",
|
|
91
|
+
description:
|
|
92
|
+
"The campaign stops at this moment: a date and time with your store's offset (empty: never)",
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
|
|
46
97
|
function resolveTypeProperty(key: string) {
|
|
47
98
|
return { type: "string", enum: [key], default: key };
|
|
48
99
|
}
|
|
@@ -114,14 +165,34 @@ function builtInProps(name: string, ctx: BuiltInContext): any {
|
|
|
114
165
|
case "always":
|
|
115
166
|
case "never":
|
|
116
167
|
return { type: "object", properties: {} };
|
|
117
|
-
case "
|
|
168
|
+
case "experiment":
|
|
169
|
+
return {
|
|
170
|
+
type: "object",
|
|
171
|
+
required: ["name"],
|
|
172
|
+
properties: {
|
|
173
|
+
name: {
|
|
174
|
+
type: "string",
|
|
175
|
+
title: "Test",
|
|
176
|
+
description: "A test in the saved block experiments",
|
|
177
|
+
},
|
|
178
|
+
},
|
|
179
|
+
};
|
|
180
|
+
case "campaign":
|
|
118
181
|
return {
|
|
119
182
|
type: "object",
|
|
183
|
+
required: ["name"],
|
|
120
184
|
properties: {
|
|
121
|
-
|
|
122
|
-
|
|
185
|
+
name: {
|
|
186
|
+
type: "string",
|
|
187
|
+
title: "Campaign",
|
|
188
|
+
description: "A campaign in the saved block campaigns",
|
|
189
|
+
},
|
|
123
190
|
},
|
|
124
191
|
};
|
|
192
|
+
case "split-traffic":
|
|
193
|
+
case "calendar":
|
|
194
|
+
// The names are the content: every key but __resolveType is one (see builtInDefinition).
|
|
195
|
+
return { type: "object", properties: {} };
|
|
125
196
|
case "page":
|
|
126
197
|
return {
|
|
127
198
|
type: "object",
|
|
@@ -163,19 +234,6 @@ function builtInProps(name: string, ctx: BuiltInContext): any {
|
|
|
163
234
|
return {
|
|
164
235
|
type: "object",
|
|
165
236
|
properties: {
|
|
166
|
-
preview: {
|
|
167
|
-
type: "object",
|
|
168
|
-
title: "Preview",
|
|
169
|
-
properties: {
|
|
170
|
-
hosts: {
|
|
171
|
-
type: "array",
|
|
172
|
-
title: "Hosts",
|
|
173
|
-
description:
|
|
174
|
-
"Host patterns drafts may be previewed on, such as staging.example.com or *.example.com; empty turns previews off. Without it, every host (or the hosts code allows).",
|
|
175
|
-
items: { type: "string" },
|
|
176
|
-
},
|
|
177
|
-
},
|
|
178
|
-
},
|
|
179
237
|
telemetry: {
|
|
180
238
|
type: "object",
|
|
181
239
|
title: "Telemetry",
|
|
@@ -239,6 +297,8 @@ export function builtInDefinition(name: string, ctx: BuiltInContext): any {
|
|
|
239
297
|
return flatDefinition(name, builtInProps(name, ctx), {
|
|
240
298
|
description: docs.description,
|
|
241
299
|
...(docs.icon ? { icon: docs.icon } : {}),
|
|
300
|
+
...(name === "split-traffic" ? { additionalProperties: ALLOCATION } : {}),
|
|
301
|
+
...(name === "calendar" ? { additionalProperties: CAMPAIGN_DATES } : {}),
|
|
242
302
|
});
|
|
243
303
|
}
|
|
244
304
|
|