@orunelle/theme-contract 0.0.0-stage → 2.0.0-alpha.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +83 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +30 -0
- package/dist/merchant-editing.d.ts +16 -0
- package/dist/merchant-editing.d.ts.map +1 -0
- package/dist/merchant-editing.js +115 -0
- package/dist/merchant-lifecycle.d.ts +86 -0
- package/dist/merchant-lifecycle.d.ts.map +1 -0
- package/dist/merchant-lifecycle.js +1 -0
- package/dist/merchant-schema.json +1180 -0
- package/dist/merchant-types.d.ts +168 -0
- package/dist/merchant-types.d.ts.map +1 -0
- package/dist/merchant-types.js +1 -0
- package/dist/merchant-validation.d.ts +13 -0
- package/dist/merchant-validation.d.ts.map +1 -0
- package/dist/merchant-validation.js +419 -0
- package/dist/preview.d.ts +559 -0
- package/dist/preview.d.ts.map +1 -0
- package/dist/preview.js +168 -0
- package/dist/store-text.d.ts +116 -0
- package/dist/store-text.d.ts.map +1 -0
- package/dist/store-text.js +68 -0
- package/dist/validators.generated.cjs +2 -0
- package/package.json +40 -3
- package/README.md +0 -3
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import type { LocalizedText } from "./index.js";
|
|
2
|
+
export interface ImageValue {
|
|
3
|
+
assetId: string;
|
|
4
|
+
alt: LocalizedText;
|
|
5
|
+
focalPoint?: {
|
|
6
|
+
x: number;
|
|
7
|
+
y: number;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
export interface ResourceValue {
|
|
11
|
+
kind: "product" | "collection" | "page";
|
|
12
|
+
id: string;
|
|
13
|
+
}
|
|
14
|
+
export interface Paragraph {
|
|
15
|
+
type: "paragraph";
|
|
16
|
+
children: {
|
|
17
|
+
text: string;
|
|
18
|
+
marks: ("bold" | "italic")[];
|
|
19
|
+
}[];
|
|
20
|
+
}
|
|
21
|
+
export interface ResponsiveValue {
|
|
22
|
+
base: number;
|
|
23
|
+
sm?: number;
|
|
24
|
+
lg?: number;
|
|
25
|
+
}
|
|
26
|
+
export interface MenuLink {
|
|
27
|
+
label: LocalizedText;
|
|
28
|
+
href: string;
|
|
29
|
+
}
|
|
30
|
+
/** One navigation entry; a single level of nested links is supported. */
|
|
31
|
+
export interface MenuItem extends MenuLink {
|
|
32
|
+
children?: MenuLink[];
|
|
33
|
+
}
|
|
34
|
+
export type SettingUnit = "px" | "%" | "rem" | "em" | "s" | "ms" | "deg" | "vh" | "vw";
|
|
35
|
+
export type LiteralValue = null | boolean | number | string | LocalizedText | ImageValue | ResourceValue | Paragraph[] | ResponsiveValue | MenuItem[] | ResourceValue[];
|
|
36
|
+
export type BindingSource = "store.name" | "store.logo" | "product.name" | "product.description" | "product.image" | "collection.name";
|
|
37
|
+
export interface BoundValue {
|
|
38
|
+
binding: BindingSource;
|
|
39
|
+
fallback: LiteralValue;
|
|
40
|
+
}
|
|
41
|
+
export type SettingValue = LiteralValue | BoundValue;
|
|
42
|
+
export type SettingValues = Record<string, SettingValue>;
|
|
43
|
+
interface SettingBase {
|
|
44
|
+
label: LocalizedText;
|
|
45
|
+
required?: boolean;
|
|
46
|
+
default?: LiteralValue;
|
|
47
|
+
}
|
|
48
|
+
export type SettingDefinition = SettingBase & ({
|
|
49
|
+
kind: "text" | "localizedText";
|
|
50
|
+
maxLength: number;
|
|
51
|
+
} | {
|
|
52
|
+
kind: "number" | "responsive";
|
|
53
|
+
min: number;
|
|
54
|
+
max: number;
|
|
55
|
+
/** Editor slider increment; values are not rounded to it. */
|
|
56
|
+
step?: number;
|
|
57
|
+
unit?: SettingUnit;
|
|
58
|
+
} | {
|
|
59
|
+
kind: "boolean" | "color" | "link" | "image" | "richtext";
|
|
60
|
+
} | {
|
|
61
|
+
kind: "resource";
|
|
62
|
+
resourceKind: ResourceValue["kind"];
|
|
63
|
+
} | {
|
|
64
|
+
kind: "resourceList";
|
|
65
|
+
resourceKind: ResourceValue["kind"];
|
|
66
|
+
maxItems: number;
|
|
67
|
+
}
|
|
68
|
+
/** maxItems counts top-level entries and nested links together. */
|
|
69
|
+
| {
|
|
70
|
+
kind: "menu";
|
|
71
|
+
maxItems: number;
|
|
72
|
+
} | {
|
|
73
|
+
kind: "select" | "font";
|
|
74
|
+
options: {
|
|
75
|
+
value: string;
|
|
76
|
+
label: LocalizedText;
|
|
77
|
+
}[];
|
|
78
|
+
});
|
|
79
|
+
export type SettingDefinitions = Record<string, SettingDefinition>;
|
|
80
|
+
export interface CompositionDefinition {
|
|
81
|
+
label: LocalizedText;
|
|
82
|
+
allowedRootTypes: string[];
|
|
83
|
+
minRoots?: number;
|
|
84
|
+
maxRoots: number;
|
|
85
|
+
}
|
|
86
|
+
export interface TemplateDefinition extends CompositionDefinition {
|
|
87
|
+
kind: "home" | "product" | "collection" | "page" | "search" | "cart" | "notFound";
|
|
88
|
+
}
|
|
89
|
+
/** A block created together with a preset; settings use the block's definitions. */
|
|
90
|
+
export interface PresetBlock {
|
|
91
|
+
type: string;
|
|
92
|
+
settings?: SettingValues;
|
|
93
|
+
blocks?: PresetBlock[];
|
|
94
|
+
}
|
|
95
|
+
/** A ready-made starting point offered when a merchant adds this node type. */
|
|
96
|
+
export interface NodePreset {
|
|
97
|
+
label: LocalizedText;
|
|
98
|
+
settings?: SettingValues;
|
|
99
|
+
blocks?: PresetBlock[];
|
|
100
|
+
}
|
|
101
|
+
export interface NodeDefinition {
|
|
102
|
+
kind: "section" | "block";
|
|
103
|
+
label: LocalizedText;
|
|
104
|
+
settings: SettingDefinitions;
|
|
105
|
+
allowedChildren: string[];
|
|
106
|
+
minChildren?: number;
|
|
107
|
+
maxChildren: number;
|
|
108
|
+
maxInstances?: number;
|
|
109
|
+
allowedLocations: string[];
|
|
110
|
+
presets?: NodePreset[];
|
|
111
|
+
}
|
|
112
|
+
/** A storefront text the merchant can override in each language. */
|
|
113
|
+
export interface StoreTextDefinition {
|
|
114
|
+
label: LocalizedText;
|
|
115
|
+
default: LocalizedText;
|
|
116
|
+
}
|
|
117
|
+
export interface EditorDefinition {
|
|
118
|
+
/** Theme-specific storefront texts; these also replace platform defaults. */
|
|
119
|
+
strings?: Record<string, StoreTextDefinition>;
|
|
120
|
+
settings: SettingDefinitions;
|
|
121
|
+
nodeTypes: Record<string, NodeDefinition>;
|
|
122
|
+
templates: Record<string, TemplateDefinition>;
|
|
123
|
+
groups: Record<string, CompositionDefinition>;
|
|
124
|
+
}
|
|
125
|
+
export interface MerchantManifest {
|
|
126
|
+
readonly schemaVersion: 2;
|
|
127
|
+
readonly runtimeAbi: "orunelle.react.v2/1";
|
|
128
|
+
readonly id: string;
|
|
129
|
+
readonly version: string;
|
|
130
|
+
readonly name: LocalizedText;
|
|
131
|
+
readonly editor?: EditorDefinition;
|
|
132
|
+
}
|
|
133
|
+
export interface ThemeNode {
|
|
134
|
+
id: string;
|
|
135
|
+
type: string;
|
|
136
|
+
parent: string | null;
|
|
137
|
+
children: string[];
|
|
138
|
+
settings: SettingValues;
|
|
139
|
+
hidden?: boolean;
|
|
140
|
+
}
|
|
141
|
+
export interface ConfigurationTemplate {
|
|
142
|
+
schemaVersion: 2;
|
|
143
|
+
configurationVersion: 1;
|
|
144
|
+
themeId: string;
|
|
145
|
+
settings: SettingValues;
|
|
146
|
+
groups: Record<string, {
|
|
147
|
+
roots: string[];
|
|
148
|
+
}>;
|
|
149
|
+
templates: Record<string, {
|
|
150
|
+
roots: string[];
|
|
151
|
+
}>;
|
|
152
|
+
nodes: ThemeNode[];
|
|
153
|
+
assignments: {
|
|
154
|
+
resource: ResourceValue;
|
|
155
|
+
template: string;
|
|
156
|
+
}[];
|
|
157
|
+
/** Merchant overrides of storefront texts; empty languages use the default. */
|
|
158
|
+
strings?: Record<string, LocalizedText>;
|
|
159
|
+
}
|
|
160
|
+
export interface ThemeConfiguration extends ConfigurationTemplate {
|
|
161
|
+
installationId: string;
|
|
162
|
+
}
|
|
163
|
+
export interface ContractProblem {
|
|
164
|
+
code: string;
|
|
165
|
+
path: string;
|
|
166
|
+
}
|
|
167
|
+
export {};
|
|
168
|
+
//# sourceMappingURL=merchant-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merchant-types.d.ts","sourceRoot":"","sources":["../src/merchant-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,aAAa,CAAC;IACnB,UAAU,CAAC,EAAE;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CACvC;AACD,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,SAAS,GAAG,YAAY,GAAG,MAAM,CAAC;IACxC,EAAE,EAAE,MAAM,CAAC;CACZ;AACD,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,WAAW,CAAC;IAClB,QAAQ,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,CAAC,MAAM,GAAG,QAAQ,CAAC,EAAE,CAAA;KAAE,EAAE,CAAC;CAC5D;AACD,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,EAAE,CAAC,EAAE,MAAM,CAAC;CACb;AACD,MAAM,WAAW,QAAQ;IACvB,KAAK,EAAE,aAAa,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;CACd;AACD,yEAAyE;AACzE,MAAM,WAAW,QAAS,SAAQ,QAAQ;IACxC,QAAQ,CAAC,EAAE,QAAQ,EAAE,CAAC;CACvB;AACD,MAAM,MAAM,WAAW,GACnB,IAAI,GACJ,GAAG,GACH,KAAK,GACL,IAAI,GACJ,GAAG,GACH,IAAI,GACJ,KAAK,GACL,IAAI,GACJ,IAAI,CAAC;AACT,MAAM,MAAM,YAAY,GACpB,IAAI,GACJ,OAAO,GACP,M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AE,MAAM,EAAE,CAAA;KAAE,CAAC,CAAC;IAC5C,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,KAAK,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC,CAAC;IAC/C,KAAK,EAAE,SAAS,EAAE,CAAC;IACnB,WAAW,EAAE;QAAE,QAAQ,EAAE,aAAa,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAC7D,+EAA+E;IAC/E,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;CACzC;AACD,MAAM,WAAW,kBAAmB,SAAQ,qBAAqB;IAC/D,cAAc,EAAE,MAAM,CAAC;CACxB;AACD,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ContractProblem, MerchantManifest, SettingDefinition, SettingDefinitions, SettingValue } from "./merchant-types.js";
|
|
2
|
+
export declare const MAX_MANIFEST_BYTES = 131072;
|
|
3
|
+
export declare const MAX_CONFIGURATION_BYTES = 196608;
|
|
4
|
+
export declare const MAX_NODE_DEPTH = 8;
|
|
5
|
+
export declare const MAX_MENU_LABEL_LENGTH = 100;
|
|
6
|
+
/** Values are structurally checked before this semantic type/bounds check. */
|
|
7
|
+
export declare function acceptsSetting(definition: SettingDefinition, input: unknown): boolean;
|
|
8
|
+
export declare function validateManifest(input: unknown): ContractProblem | undefined;
|
|
9
|
+
export declare function validateConfiguration(manifest: MerchantManifest, input: unknown, installationId?: string): ContractProblem | undefined;
|
|
10
|
+
export declare function validateConfigurationTemplate(manifest: MerchantManifest, input: unknown): ContractProblem | undefined;
|
|
11
|
+
/** Omission resets to the declared default; explicit null/empty values stay explicit. */
|
|
12
|
+
export declare function resolveSettingValues(definitions: SettingDefinitions, overrides: Record<string, SettingValue>): Record<string, SettingValue>;
|
|
13
|
+
//# sourceMappingURL=merchant-validation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merchant-validation.d.ts","sourceRoot":"","sources":["../src/merchant-validation.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,eAAe,EACf,gBAAgB,EAIhB,iBAAiB,EACjB,kBAAkB,EAClB,YAAY,EAGb,MAAM,qBAAqB,CAAC;AAE7B,eAAO,MAAM,kBAAkB,SAAS,CAAC;AACzC,eAAO,MAAM,uBAAuB,SAAS,CAAC;AAC9C,eAAO,MAAM,cAAc,IAAI,CAAC;AAiDhC,eAAO,MAAM,qBAAqB,MAAM,CAAC;AA6BzC,8EAA8E;AAC9E,wBAAgB,cAAc,CAC5B,UAAU,EAAE,iBAAiB,EAC7B,KAAK,EAAE,OAAO,GACb,OAAO,CAyGT;AA0BD,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,eAAe,GAAG,SAAS,CAoE5E;AA2DD,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,gBAAgB,EAC1B,KAAK,EAAE,OAAO,EACd,cAAc,CAAC,EAAE,MAAM,GACtB,eAAe,GAAG,SAAS,CAsI7B;AACD,wBAAgB,6BAA6B,CAC3C,QAAQ,EAAE,gBAAgB,EAC1B,KAAK,EAAE,OAAO,GACb,eAAe,GAAG,SAAS,CAM7B;AACD,yFAAyF;AACzF,wBAAgB,oBAAoB,CAClC,WAAW,EAAE,kBAAkB,EAC/B,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,GACtC,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAQ9B"}
|
|
@@ -0,0 +1,419 @@
|
|
|
1
|
+
import { manifest as manifestShape, configuration as configurationShape, configurationTemplate as templateShape, value as valueShape, } from "./validators.generated.cjs";
|
|
2
|
+
export const MAX_MANIFEST_BYTES = 131072;
|
|
3
|
+
export const MAX_CONFIGURATION_BYTES = 196608;
|
|
4
|
+
export const MAX_NODE_DEPTH = 8;
|
|
5
|
+
const has = (object, key) => Object.hasOwn(object, key);
|
|
6
|
+
const record = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
7
|
+
const problem = (code, path = "/") => ({ code, path });
|
|
8
|
+
const length = (value) => Array.from(value).length;
|
|
9
|
+
function bounded(value, limit) {
|
|
10
|
+
try {
|
|
11
|
+
const text = JSON.stringify(value);
|
|
12
|
+
if (typeof text !== "string")
|
|
13
|
+
return problem("shape");
|
|
14
|
+
if (new TextEncoder().encode(text).length > limit)
|
|
15
|
+
return problem("too-large");
|
|
16
|
+
const walk = (current, depth) => {
|
|
17
|
+
if (depth > 32)
|
|
18
|
+
return false;
|
|
19
|
+
return ((!record(current) && !Array.isArray(current)) ||
|
|
20
|
+
Object.values(current).every((child) => walk(child, depth + 1)));
|
|
21
|
+
};
|
|
22
|
+
if (!walk(value, 0))
|
|
23
|
+
return problem("json-depth");
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return problem("shape");
|
|
27
|
+
}
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
function safeLink(value) {
|
|
31
|
+
if (/[\\\s\x00-\x20\x7f-\x9f]/u.test(value) ||
|
|
32
|
+
/%(?![0-9a-f]{2})/iu.test(value))
|
|
33
|
+
return false;
|
|
34
|
+
if (!value || value.startsWith("#"))
|
|
35
|
+
return true;
|
|
36
|
+
if (value.startsWith("/"))
|
|
37
|
+
return !value.startsWith("//");
|
|
38
|
+
if (!/^https?:\/\//iu.test(value))
|
|
39
|
+
return false;
|
|
40
|
+
if (value
|
|
41
|
+
.slice(value.indexOf("://") + 3)
|
|
42
|
+
.split(/[/?#]/u, 1)[0]
|
|
43
|
+
.includes("@"))
|
|
44
|
+
return false;
|
|
45
|
+
try {
|
|
46
|
+
const url = new URL(value);
|
|
47
|
+
return !!url.hostname && !url.username && !url.password;
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
export const MAX_MENU_LABEL_LENGTH = 100;
|
|
54
|
+
function acceptsMenuLink(item) {
|
|
55
|
+
return (record(item) &&
|
|
56
|
+
typeof item.href === "string" &&
|
|
57
|
+
length(item.href) <= 2048 &&
|
|
58
|
+
safeLink(item.href) &&
|
|
59
|
+
record(item.label) &&
|
|
60
|
+
typeof item.label.en === "string" &&
|
|
61
|
+
typeof item.label.ar === "string" &&
|
|
62
|
+
length(item.label.en) <= MAX_MENU_LABEL_LENGTH &&
|
|
63
|
+
length(item.label.ar) <= MAX_MENU_LABEL_LENGTH);
|
|
64
|
+
}
|
|
65
|
+
function acceptsMenu(items, maxItems) {
|
|
66
|
+
let count = 0;
|
|
67
|
+
for (const item of items) {
|
|
68
|
+
if (!acceptsMenuLink(item))
|
|
69
|
+
return false;
|
|
70
|
+
const children = item.children;
|
|
71
|
+
if (children !== undefined) {
|
|
72
|
+
if (!Array.isArray(children) || !children.every(acceptsMenuLink))
|
|
73
|
+
return false;
|
|
74
|
+
count += children.length;
|
|
75
|
+
}
|
|
76
|
+
count++;
|
|
77
|
+
}
|
|
78
|
+
return count <= maxItems;
|
|
79
|
+
}
|
|
80
|
+
/** Values are structurally checked before this semantic type/bounds check. */
|
|
81
|
+
export function acceptsSetting(definition, input) {
|
|
82
|
+
if (!valueShape(input))
|
|
83
|
+
return false;
|
|
84
|
+
let value = input;
|
|
85
|
+
if (record(value) && has(value, "binding")) {
|
|
86
|
+
const kinds = {
|
|
87
|
+
"store.name": "localizedText",
|
|
88
|
+
"store.logo": "image",
|
|
89
|
+
"product.name": "localizedText",
|
|
90
|
+
"product.description": "localizedText",
|
|
91
|
+
"product.image": "image",
|
|
92
|
+
"collection.name": "localizedText",
|
|
93
|
+
};
|
|
94
|
+
if (kinds[String(value.binding)] !== definition.kind)
|
|
95
|
+
return false;
|
|
96
|
+
value = value.fallback;
|
|
97
|
+
}
|
|
98
|
+
if (definition.required && (value === null || value === ""))
|
|
99
|
+
return false;
|
|
100
|
+
switch (definition.kind) {
|
|
101
|
+
case "text":
|
|
102
|
+
return typeof value === "string" && length(value) <= definition.maxLength;
|
|
103
|
+
case "localizedText":
|
|
104
|
+
return (record(value) &&
|
|
105
|
+
Object.keys(value).length === 2 &&
|
|
106
|
+
typeof value.en === "string" &&
|
|
107
|
+
typeof value.ar === "string" &&
|
|
108
|
+
length(value.en) <= definition.maxLength &&
|
|
109
|
+
length(value.ar) <= definition.maxLength);
|
|
110
|
+
case "boolean":
|
|
111
|
+
return typeof value === "boolean";
|
|
112
|
+
case "number":
|
|
113
|
+
return (typeof value === "number" &&
|
|
114
|
+
Number.isFinite(value) &&
|
|
115
|
+
value >= definition.min &&
|
|
116
|
+
value <= definition.max);
|
|
117
|
+
case "responsive":
|
|
118
|
+
return (record(value) &&
|
|
119
|
+
has(value, "base") &&
|
|
120
|
+
Object.keys(value).every((key) => ["base", "sm", "lg"].includes(key) &&
|
|
121
|
+
typeof value[key] === "number" &&
|
|
122
|
+
Number.isFinite(value[key]) &&
|
|
123
|
+
value[key] >= definition.min &&
|
|
124
|
+
value[key] <= definition.max));
|
|
125
|
+
case "color":
|
|
126
|
+
return (typeof value === "string" &&
|
|
127
|
+
value.length === 7 &&
|
|
128
|
+
/^#[0-9a-f]{6}$/iu.test(value));
|
|
129
|
+
case "select":
|
|
130
|
+
case "font":
|
|
131
|
+
return (typeof value === "string" &&
|
|
132
|
+
definition.options.some((option) => option.value === value));
|
|
133
|
+
case "link":
|
|
134
|
+
return (typeof value === "string" && length(value) <= 2048 && safeLink(value));
|
|
135
|
+
case "image":
|
|
136
|
+
return value === null
|
|
137
|
+
? !definition.required
|
|
138
|
+
: record(value) && has(value, "assetId");
|
|
139
|
+
case "resource":
|
|
140
|
+
return value === null
|
|
141
|
+
? !definition.required
|
|
142
|
+
: record(value) &&
|
|
143
|
+
value.kind === definition.resourceKind &&
|
|
144
|
+
has(value, "id");
|
|
145
|
+
case "richtext":
|
|
146
|
+
return (Array.isArray(value) &&
|
|
147
|
+
value.every((item) => record(item) && item.type === "paragraph"));
|
|
148
|
+
case "menu":
|
|
149
|
+
return (Array.isArray(value) &&
|
|
150
|
+
!(definition.required && value.length === 0) &&
|
|
151
|
+
acceptsMenu(value, definition.maxItems));
|
|
152
|
+
case "resourceList": {
|
|
153
|
+
if (!Array.isArray(value) || value.length > definition.maxItems)
|
|
154
|
+
return false;
|
|
155
|
+
if (definition.required && value.length === 0)
|
|
156
|
+
return false;
|
|
157
|
+
const ids = new Set();
|
|
158
|
+
for (const item of value) {
|
|
159
|
+
if (!record(item) ||
|
|
160
|
+
item.kind !== definition.resourceKind ||
|
|
161
|
+
typeof item.id !== "string" ||
|
|
162
|
+
ids.has(item.id))
|
|
163
|
+
return false;
|
|
164
|
+
ids.add(item.id);
|
|
165
|
+
}
|
|
166
|
+
return true;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
function definitionsProblem(definitions, path) {
|
|
171
|
+
for (const id of Object.keys(definitions).sort()) {
|
|
172
|
+
const definition = definitions[id];
|
|
173
|
+
if ((definition.kind === "number" || definition.kind === "responsive") &&
|
|
174
|
+
definition.min > definition.max)
|
|
175
|
+
return problem("definition-bounds", `${path}/${id}`);
|
|
176
|
+
if ((definition.kind === "select" || definition.kind === "font") &&
|
|
177
|
+
new Set(definition.options.map((option) => option.value)).size !==
|
|
178
|
+
definition.options.length)
|
|
179
|
+
return problem("duplicate-option", `${path}/${id}`);
|
|
180
|
+
if (has(definition, "default") &&
|
|
181
|
+
!acceptsSetting(definition, definition.default))
|
|
182
|
+
return problem("invalid-default", `${path}/${id}/default`);
|
|
183
|
+
}
|
|
184
|
+
return undefined;
|
|
185
|
+
}
|
|
186
|
+
export function validateManifest(input) {
|
|
187
|
+
const bound = bounded(input, MAX_MANIFEST_BYTES);
|
|
188
|
+
if (bound)
|
|
189
|
+
return bound;
|
|
190
|
+
if (!manifestShape(input))
|
|
191
|
+
return problem("shape");
|
|
192
|
+
const manifest = input; // Generated JSON Schema established the structural type.
|
|
193
|
+
const editor = manifest.editor;
|
|
194
|
+
if (!editor)
|
|
195
|
+
return undefined;
|
|
196
|
+
let issue = definitionsProblem(editor.settings, "/editor/settings");
|
|
197
|
+
if (issue)
|
|
198
|
+
return issue;
|
|
199
|
+
const locations = new Set([
|
|
200
|
+
...Object.keys(editor.templates).map((id) => `template:${id}`),
|
|
201
|
+
...Object.keys(editor.groups).map((id) => `group:${id}`),
|
|
202
|
+
]);
|
|
203
|
+
for (const id of Object.keys(editor.nodeTypes).sort()) {
|
|
204
|
+
const definition = editor.nodeTypes[id];
|
|
205
|
+
if ((definition.minChildren ?? 0) > definition.maxChildren)
|
|
206
|
+
return problem("definition-bounds", `/editor/nodeTypes/${id}`);
|
|
207
|
+
for (const child of definition.allowedChildren)
|
|
208
|
+
if (!has(editor.nodeTypes, child) ||
|
|
209
|
+
editor.nodeTypes[child].kind !== "block")
|
|
210
|
+
return problem("definition-reference", `/editor/nodeTypes/${id}/allowedChildren`);
|
|
211
|
+
for (const location of definition.allowedLocations)
|
|
212
|
+
if (!locations.has(location))
|
|
213
|
+
return problem("definition-reference", `/editor/nodeTypes/${id}/allowedLocations`);
|
|
214
|
+
issue = definitionsProblem(definition.settings, `/editor/nodeTypes/${id}/settings`);
|
|
215
|
+
if (issue)
|
|
216
|
+
return issue;
|
|
217
|
+
for (const [index, preset] of (definition.presets ?? []).entries()) {
|
|
218
|
+
issue = presetProblem(editor, definition, preset, `/editor/nodeTypes/${id}/presets/${index}`, 1);
|
|
219
|
+
if (issue)
|
|
220
|
+
return issue;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
for (const [kind, compositions] of [
|
|
224
|
+
["templates", editor.templates],
|
|
225
|
+
["groups", editor.groups],
|
|
226
|
+
]) {
|
|
227
|
+
for (const id of Object.keys(compositions).sort()) {
|
|
228
|
+
const definition = compositions[id];
|
|
229
|
+
if ((definition.minRoots ?? 0) > definition.maxRoots)
|
|
230
|
+
return problem("definition-bounds", `/editor/${kind}/${id}`);
|
|
231
|
+
for (const type of definition.allowedRootTypes)
|
|
232
|
+
if (!has(editor.nodeTypes, type) ||
|
|
233
|
+
editor.nodeTypes[type].kind !== "section")
|
|
234
|
+
return problem("definition-reference", `/editor/${kind}/${id}/allowedRootTypes`);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
return undefined;
|
|
238
|
+
}
|
|
239
|
+
/** Presets must produce a subtree the configuration validator would accept. */
|
|
240
|
+
function presetProblem(editor, definition, preset, path, depth) {
|
|
241
|
+
if (depth > MAX_NODE_DEPTH)
|
|
242
|
+
return problem("preset", path);
|
|
243
|
+
if (settingsProblem(definition.settings, preset.settings ?? {}, path))
|
|
244
|
+
return problem("preset", `${path}/settings`);
|
|
245
|
+
const blocks = preset.blocks ?? [];
|
|
246
|
+
if (blocks.length < (definition.minChildren ?? 0) ||
|
|
247
|
+
blocks.length > definition.maxChildren)
|
|
248
|
+
return problem("preset", `${path}/blocks`);
|
|
249
|
+
for (const [index, block] of blocks.entries()) {
|
|
250
|
+
const child = has(editor.nodeTypes, block.type)
|
|
251
|
+
? editor.nodeTypes[block.type]
|
|
252
|
+
: undefined;
|
|
253
|
+
if (!child ||
|
|
254
|
+
child.kind !== "block" ||
|
|
255
|
+
!definition.allowedChildren.includes(block.type))
|
|
256
|
+
return problem("preset", `${path}/blocks/${index}`);
|
|
257
|
+
const issue = presetProblem(editor, child, block, `${path}/blocks/${index}`, depth + 1);
|
|
258
|
+
if (issue)
|
|
259
|
+
return issue;
|
|
260
|
+
}
|
|
261
|
+
return undefined;
|
|
262
|
+
}
|
|
263
|
+
function settingsProblem(definitions, values, path) {
|
|
264
|
+
for (const id of Object.keys(values).sort()) {
|
|
265
|
+
if (!has(definitions, id))
|
|
266
|
+
return problem("unknown-setting", `${path}/${id}`);
|
|
267
|
+
if (!acceptsSetting(definitions[id], values[id]))
|
|
268
|
+
return problem("setting-value", `${path}/${id}`);
|
|
269
|
+
}
|
|
270
|
+
for (const id of Object.keys(definitions).sort())
|
|
271
|
+
if (definitions[id].required &&
|
|
272
|
+
!has(values, id) &&
|
|
273
|
+
!has(definitions[id], "default"))
|
|
274
|
+
return problem("required-setting", `${path}/${id}`);
|
|
275
|
+
return undefined;
|
|
276
|
+
}
|
|
277
|
+
export function validateConfiguration(manifest, input, installationId) {
|
|
278
|
+
const invalidManifest = validateManifest(manifest);
|
|
279
|
+
if (invalidManifest)
|
|
280
|
+
return invalidManifest;
|
|
281
|
+
const bound = bounded(input, MAX_CONFIGURATION_BYTES);
|
|
282
|
+
if (bound)
|
|
283
|
+
return bound;
|
|
284
|
+
if (!configurationShape(input))
|
|
285
|
+
return problem("shape");
|
|
286
|
+
const configuration = input;
|
|
287
|
+
if (configuration.themeId !== manifest.id ||
|
|
288
|
+
(installationId !== undefined &&
|
|
289
|
+
configuration.installationId !== installationId))
|
|
290
|
+
return problem("identity");
|
|
291
|
+
const editor = manifest.editor ?? {
|
|
292
|
+
settings: {},
|
|
293
|
+
nodeTypes: {},
|
|
294
|
+
templates: {},
|
|
295
|
+
groups: {},
|
|
296
|
+
};
|
|
297
|
+
let issue = settingsProblem(editor.settings, configuration.settings, "/settings");
|
|
298
|
+
if (issue)
|
|
299
|
+
return issue;
|
|
300
|
+
const nodes = new Map(configuration.nodes.map((node) => [node.id, node]));
|
|
301
|
+
if (nodes.size !== configuration.nodes.length)
|
|
302
|
+
return problem("duplicate-node", "/nodes");
|
|
303
|
+
const counts = new Map();
|
|
304
|
+
for (const node of configuration.nodes) {
|
|
305
|
+
const definition = editor.nodeTypes[node.type];
|
|
306
|
+
if (!has(editor.nodeTypes, node.type) || !definition)
|
|
307
|
+
return problem("unknown-type", `/nodes/${node.id}`);
|
|
308
|
+
const count = (counts.get(node.type) ?? 0) + 1;
|
|
309
|
+
counts.set(node.type, count);
|
|
310
|
+
if (count > (definition.maxInstances ?? 500))
|
|
311
|
+
return problem("instance-limit", `/nodes/${node.id}`);
|
|
312
|
+
if (node.children.length < (definition.minChildren ?? 0) ||
|
|
313
|
+
node.children.length > definition.maxChildren)
|
|
314
|
+
return problem("child-limit", `/nodes/${node.id}`);
|
|
315
|
+
issue = settingsProblem(definition.settings, node.settings, `/nodes/${node.id}/settings`);
|
|
316
|
+
if (issue)
|
|
317
|
+
return issue;
|
|
318
|
+
if (node.parent !== null && !nodes.has(node.parent))
|
|
319
|
+
return problem("unknown-node", `/nodes/${node.id}/parent`);
|
|
320
|
+
for (const childId of node.children) {
|
|
321
|
+
const child = nodes.get(childId);
|
|
322
|
+
if (!child)
|
|
323
|
+
return problem("unknown-node", `/nodes/${node.id}/children`);
|
|
324
|
+
if (child.parent !== node.id)
|
|
325
|
+
return problem("parent-mismatch", `/nodes/${child.id}/parent`);
|
|
326
|
+
if (!definition.allowedChildren.includes(child.type))
|
|
327
|
+
return problem("child-type", `/nodes/${child.id}`);
|
|
328
|
+
}
|
|
329
|
+
if (node.parent !== null &&
|
|
330
|
+
!nodes.get(node.parent).children.includes(node.id))
|
|
331
|
+
return problem("parent-mismatch", `/nodes/${node.id}/parent`);
|
|
332
|
+
}
|
|
333
|
+
const colors = new Map();
|
|
334
|
+
const checkCycle = (id) => {
|
|
335
|
+
if (colors.get(id) === 1)
|
|
336
|
+
return false;
|
|
337
|
+
if (colors.get(id) === 2)
|
|
338
|
+
return true;
|
|
339
|
+
colors.set(id, 1);
|
|
340
|
+
for (const child of nodes.get(id).children)
|
|
341
|
+
if (!checkCycle(child))
|
|
342
|
+
return false;
|
|
343
|
+
colors.set(id, 2);
|
|
344
|
+
return true;
|
|
345
|
+
};
|
|
346
|
+
for (const node of configuration.nodes)
|
|
347
|
+
if (!checkCycle(node.id))
|
|
348
|
+
return problem("cycle", "/nodes");
|
|
349
|
+
const visited = new Set();
|
|
350
|
+
const visit = (id, location, depth) => {
|
|
351
|
+
if (visited.has(id))
|
|
352
|
+
return problem("multiple-parents", `/nodes/${id}`);
|
|
353
|
+
if (depth > MAX_NODE_DEPTH)
|
|
354
|
+
return problem("node-depth", `/nodes/${id}`);
|
|
355
|
+
visited.add(id);
|
|
356
|
+
const node = nodes.get(id);
|
|
357
|
+
if (!editor.nodeTypes[node.type].allowedLocations.includes(location))
|
|
358
|
+
return problem("location", `/nodes/${id}`);
|
|
359
|
+
for (const child of node.children) {
|
|
360
|
+
const issue = visit(child, location, depth + 1);
|
|
361
|
+
if (issue)
|
|
362
|
+
return issue;
|
|
363
|
+
}
|
|
364
|
+
return undefined;
|
|
365
|
+
};
|
|
366
|
+
for (const kind of ["groups", "templates"])
|
|
367
|
+
for (const compositionId of Object.keys(configuration[kind]).sort()) {
|
|
368
|
+
if (!has(editor[kind], compositionId))
|
|
369
|
+
return problem("unknown-composition", `/${kind}/${compositionId}`);
|
|
370
|
+
const composition = editor[kind][compositionId], roots = configuration[kind][compositionId].roots;
|
|
371
|
+
if (roots.length < (composition.minRoots ?? 0) ||
|
|
372
|
+
roots.length > composition.maxRoots)
|
|
373
|
+
return problem("root-limit", `/${kind}/${compositionId}`);
|
|
374
|
+
for (const id of roots) {
|
|
375
|
+
const node = nodes.get(id);
|
|
376
|
+
if (!node)
|
|
377
|
+
return problem("unknown-node", `/nodes/${id}`);
|
|
378
|
+
if (node.parent !== null)
|
|
379
|
+
return problem("parent-mismatch", `/nodes/${id}/parent`);
|
|
380
|
+
if (!composition.allowedRootTypes.includes(node.type))
|
|
381
|
+
return problem("root-type", `/nodes/${id}`);
|
|
382
|
+
issue = visit(id, `${kind === "groups" ? "group" : "template"}:${compositionId}`, 1);
|
|
383
|
+
if (issue)
|
|
384
|
+
return issue;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
if (visited.size !== nodes.size)
|
|
388
|
+
return problem("orphan-node", "/nodes");
|
|
389
|
+
const assignments = new Set();
|
|
390
|
+
for (const assignment of configuration.assignments) {
|
|
391
|
+
const key = `${assignment.resource.kind}:${assignment.resource.id}`;
|
|
392
|
+
if (assignments.has(key))
|
|
393
|
+
return problem("duplicate-assignment", "/assignments");
|
|
394
|
+
assignments.add(key);
|
|
395
|
+
if (!has(editor.templates, assignment.template) ||
|
|
396
|
+
editor.templates[assignment.template].kind !== assignment.resource.kind)
|
|
397
|
+
return problem("assignment-template", "/assignments");
|
|
398
|
+
}
|
|
399
|
+
return undefined;
|
|
400
|
+
}
|
|
401
|
+
export function validateConfigurationTemplate(manifest, input) {
|
|
402
|
+
if (!templateShape(input))
|
|
403
|
+
return problem("shape");
|
|
404
|
+
return validateConfiguration(manifest, {
|
|
405
|
+
...input,
|
|
406
|
+
installationId: "00000000-0000-4000-8000-000000000001",
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
/** Omission resets to the declared default; explicit null/empty values stay explicit. */
|
|
410
|
+
export function resolveSettingValues(definitions, overrides) {
|
|
411
|
+
const values = Object.create(null);
|
|
412
|
+
for (const id of Object.keys(definitions))
|
|
413
|
+
if (has(definitions[id], "default"))
|
|
414
|
+
values[id] = structuredClone(definitions[id].default);
|
|
415
|
+
for (const id of Object.keys(overrides))
|
|
416
|
+
if (has(definitions, id))
|
|
417
|
+
values[id] = structuredClone(overrides[id]);
|
|
418
|
+
return values;
|
|
419
|
+
}
|