@squiz/dx-page-contents-lib 1.53.1-alpha.13 → 1.53.1-alpha.15

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.
@@ -188,17 +188,183 @@ export type LayoutVariationNode = z.infer<typeof VariationNode> & {
188
188
  variants: LayoutVariant[];
189
189
  };
190
190
  export declare const LayoutVariationNode: z.ZodType<LayoutVariationNode, z.ZodTypeDef, z.infer<typeof VariationNode>>;
191
- /**
192
- * Comprehensive list of all nodes and the existence of child nodes within
193
- */
194
- export type LayoutContentNodes = Exclude<BaseLayoutContentNodes, NodesWithChildren> | LayoutVariationNode | (NodesWithChildren & {
191
+ declare const BaseExperimentNode: z.ZodObject<{
192
+ type: z.ZodLiteral<"experiment">;
193
+ experimentId: z.ZodString;
194
+ }, "strip", z.ZodTypeAny, {
195
+ type: "experiment";
196
+ experimentId: string;
197
+ }, {
198
+ type: "experiment";
199
+ experimentId: string;
200
+ }>;
201
+ type OutputExperimentNode = z.infer<typeof BaseExperimentNode> & {
202
+ variants: Record<string, SimpleContentNodes[]>;
203
+ };
204
+ type InputExperimentNode = z.infer<typeof BaseExperimentNode> & {
205
+ variants: Record<string, BaseLayoutContentNodes[]>;
206
+ };
207
+ export declare const ExperimentNode: z.ZodType<OutputExperimentNode, z.ZodTypeDef, InputExperimentNode>;
208
+ export type ExperimentNode = z.infer<typeof ExperimentNode>;
209
+ type SimpleContentNodes = Exclude<BaseLayoutContentNodes, NodesWithChildren> | (NodesWithChildren & {
195
210
  children: LayoutContentNodes[];
196
211
  });
212
+ declare const SimpleContentNodes: z.ZodType<SimpleContentNodes, z.ZodTypeDef, BaseLayoutContentNodes>;
197
213
  /**
198
214
  * Schema for all possible layout content nodes with checks for children
199
215
  */
200
- export declare const LayoutContentNodes: z.ZodType<LayoutContentNodes, z.ZodTypeDef, z.infer<typeof VariationNode> | BaseLayoutContentNodes>;
201
- export type PageLayoutContent = LayoutContentNodes[];
216
+ export declare const LayoutContentNodes: z.ZodUnion<[z.ZodType<SimpleContentNodes, z.ZodTypeDef, {
217
+ value: string;
218
+ type: "text";
219
+ } | {
220
+ type: "tag";
221
+ tag: string;
222
+ attributes?: Record<string, string> | undefined;
223
+ font?: {
224
+ bold?: boolean | undefined;
225
+ italics?: boolean | undefined;
226
+ underline?: boolean | undefined;
227
+ color?: string | undefined;
228
+ size?: string | undefined;
229
+ fontFamily?: string | undefined;
230
+ } | undefined;
231
+ formattingOptions?: {
232
+ alignment: "left" | "center" | "right" | "justify";
233
+ } | undefined;
234
+ } | {
235
+ type: "link-to-matrix-asset";
236
+ matrixDomain: string;
237
+ matrixAssetId: string;
238
+ target: "_blank" | "_self" | "_parent" | "_top";
239
+ matrixIdentifier?: string | undefined;
240
+ formattingOptions?: {
241
+ alignment: "left" | "center" | "right" | "justify";
242
+ } | undefined;
243
+ } | {
244
+ type: "matrix-image";
245
+ matrixDomain: string;
246
+ matrixAssetId: string;
247
+ matrixIdentifier?: string | undefined;
248
+ formattingOptions?: {
249
+ alignment: "left" | "center" | "right" | "justify";
250
+ } | undefined;
251
+ } | {
252
+ type: "component";
253
+ componentId: string;
254
+ componentSet: string;
255
+ contentItem?: {
256
+ id: string;
257
+ } | {
258
+ content: Record<string, unknown>;
259
+ schemaName: string;
260
+ } | undefined;
261
+ }>, z.ZodType<LayoutVariationNode, z.ZodTypeDef, {
262
+ type: "variation";
263
+ default: {};
264
+ }>, z.ZodType<OutputExperimentNode, z.ZodTypeDef, InputExperimentNode>]>;
265
+ /**
266
+ * Comprehensive list of all nodes and the existence of child nodes within
267
+ */
268
+ export type LayoutContentNodes = z.infer<typeof LayoutContentNodes>;
269
+ export declare function getNestedNodes(nodes: LayoutContentNodes[]): LayoutContentNodes[];
270
+ export declare const PageLayoutContent: z.ZodEffects<z.ZodArray<z.ZodUnion<[z.ZodType<SimpleContentNodes, z.ZodTypeDef, {
271
+ value: string;
272
+ type: "text";
273
+ } | {
274
+ type: "tag";
275
+ tag: string;
276
+ attributes?: Record<string, string> | undefined;
277
+ font?: {
278
+ bold?: boolean | undefined;
279
+ italics?: boolean | undefined;
280
+ underline?: boolean | undefined;
281
+ color?: string | undefined;
282
+ size?: string | undefined;
283
+ fontFamily?: string | undefined;
284
+ } | undefined;
285
+ formattingOptions?: {
286
+ alignment: "left" | "center" | "right" | "justify";
287
+ } | undefined;
288
+ } | {
289
+ type: "link-to-matrix-asset";
290
+ matrixDomain: string;
291
+ matrixAssetId: string;
292
+ target: "_blank" | "_self" | "_parent" | "_top";
293
+ matrixIdentifier?: string | undefined;
294
+ formattingOptions?: {
295
+ alignment: "left" | "center" | "right" | "justify";
296
+ } | undefined;
297
+ } | {
298
+ type: "matrix-image";
299
+ matrixDomain: string;
300
+ matrixAssetId: string;
301
+ matrixIdentifier?: string | undefined;
302
+ formattingOptions?: {
303
+ alignment: "left" | "center" | "right" | "justify";
304
+ } | undefined;
305
+ } | {
306
+ type: "component";
307
+ componentId: string;
308
+ componentSet: string;
309
+ contentItem?: {
310
+ id: string;
311
+ } | {
312
+ content: Record<string, unknown>;
313
+ schemaName: string;
314
+ } | undefined;
315
+ }>, z.ZodType<LayoutVariationNode, z.ZodTypeDef, {
316
+ type: "variation";
317
+ default: {};
318
+ }>, z.ZodType<OutputExperimentNode, z.ZodTypeDef, InputExperimentNode>]>, "many">, (LayoutVariationNode | SimpleContentNodes | OutputExperimentNode)[], ({
319
+ value: string;
320
+ type: "text";
321
+ } | {
322
+ type: "tag";
323
+ tag: string;
324
+ attributes?: Record<string, string> | undefined;
325
+ font?: {
326
+ bold?: boolean | undefined;
327
+ italics?: boolean | undefined;
328
+ underline?: boolean | undefined;
329
+ color?: string | undefined;
330
+ size?: string | undefined;
331
+ fontFamily?: string | undefined;
332
+ } | undefined;
333
+ formattingOptions?: {
334
+ alignment: "left" | "center" | "right" | "justify";
335
+ } | undefined;
336
+ } | {
337
+ type: "link-to-matrix-asset";
338
+ matrixDomain: string;
339
+ matrixAssetId: string;
340
+ target: "_blank" | "_self" | "_parent" | "_top";
341
+ matrixIdentifier?: string | undefined;
342
+ formattingOptions?: {
343
+ alignment: "left" | "center" | "right" | "justify";
344
+ } | undefined;
345
+ } | {
346
+ type: "matrix-image";
347
+ matrixDomain: string;
348
+ matrixAssetId: string;
349
+ matrixIdentifier?: string | undefined;
350
+ formattingOptions?: {
351
+ alignment: "left" | "center" | "right" | "justify";
352
+ } | undefined;
353
+ } | {
354
+ type: "component";
355
+ componentId: string;
356
+ componentSet: string;
357
+ contentItem?: {
358
+ id: string;
359
+ } | {
360
+ content: Record<string, unknown>;
361
+ schemaName: string;
362
+ } | undefined;
363
+ } | {
364
+ type: "variation";
365
+ default: {};
366
+ } | InputExperimentNode)[]>;
367
+ export type PageLayoutContent = z.infer<typeof PageLayoutContent>;
202
368
  export type NodeResolver = (node: LayoutContentNodes) => Promise<LayoutContentNodes | void>;
203
369
  export type ContentResolver<K extends LayoutContentNodes['type']> = (node: Extract<LayoutContentNodes, {
204
370
  type: K;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PageLayoutContentResolver = exports.LayoutContentNodes = exports.LayoutVariationNode = void 0;
3
+ exports.PageLayoutContentResolver = exports.PageLayoutContent = exports.getNestedNodes = exports.LayoutContentNodes = exports.ExperimentNode = exports.LayoutVariationNode = void 0;
4
4
  const zod_1 = require("zod");
5
5
  const formatted_text_1 = require("./formatted-text");
6
6
  const resolvers_1 = require("./resolvers");
@@ -15,8 +15,7 @@ const BaseLayoutContentNodes = zod_1.z.discriminatedUnion('type', [
15
15
  * All the nodes which allow children
16
16
  */
17
17
  const NODES_WITH_CHILDREN = ['tag', 'link-to-matrix-asset'];
18
- exports.LayoutVariationNode = zod_1.z
19
- .object({
18
+ exports.LayoutVariationNode = formatted_text_1.VariationNode.extend({
20
19
  default: zod_1.z.object({
21
20
  node: zod_1.z.lazy(() => exports.LayoutContentNodes).nullable(),
22
21
  }),
@@ -26,26 +25,23 @@ exports.LayoutVariationNode = zod_1.z
26
25
  .array()
27
26
  .min(1)
28
27
  .refine((variants) => {
29
- const uniqueKeys = {};
30
- return (variants.findIndex((variant) => {
31
- const uniqueKey = JSON.stringify([variant.conditions.segment.code]);
32
- if (!uniqueKeys[uniqueKey]) {
33
- uniqueKeys[uniqueKey] = true;
34
- return false;
35
- }
36
- return true;
37
- }) < 0);
28
+ const codes = variants.map((v) => JSON.stringify([v.conditions.segment.code]));
29
+ return new Set(codes).size === codes.length;
38
30
  }, { message: 'The conditions assigned to a variant must be unique.' }),
39
- })
40
- .and(formatted_text_1.VariationNode);
41
- /**
42
- * Schema for all possible layout content nodes with checks for children
43
- */
44
- exports.LayoutContentNodes = zod_1.z
31
+ }).strict();
32
+ // ------- EXPERIMENT NODE --------------
33
+ const BaseExperimentNode = zod_1.z.object({
34
+ type: zod_1.z.literal('experiment'),
35
+ experimentId: zod_1.z.string(),
36
+ });
37
+ exports.ExperimentNode = BaseExperimentNode.extend({
38
+ variants: zod_1.z.record(zod_1.z.lazy(() => SimpleContentNodes.array())),
39
+ }).strict();
40
+ const SimpleContentNodes = zod_1.z
45
41
  .object({
46
42
  children: zod_1.z.lazy(() => zod_1.z.array(exports.LayoutContentNodes)).optional(),
47
43
  })
48
- .and(zod_1.z.union([exports.LayoutVariationNode, BaseLayoutContentNodes]))
44
+ .and(BaseLayoutContentNodes)
49
45
  .refine((value) => {
50
46
  // Only certain node types to contain children
51
47
  if ('children' in value && NODES_WITH_CHILDREN.includes(value.type) === false) {
@@ -53,6 +49,28 @@ exports.LayoutContentNodes = zod_1.z
53
49
  }
54
50
  return true;
55
51
  });
52
+ /**
53
+ * Schema for all possible layout content nodes with checks for children
54
+ */
55
+ exports.LayoutContentNodes = zod_1.z.union([SimpleContentNodes, exports.LayoutVariationNode, exports.ExperimentNode]);
56
+ function isRecursiveNode(node) {
57
+ return node.type === 'variation';
58
+ }
59
+ function pickNestedNodes(node) {
60
+ return [node.default.node].concat(node.variants.map((v) => v.node)).filter((n) => !!n);
61
+ }
62
+ function getNestedNodes(nodes) {
63
+ const topLevelNodes = nodes.filter(isRecursiveNode).map(pickNestedNodes);
64
+ return topLevelNodes.flatMap(getNestedNodes).concat(topLevelNodes.flat());
65
+ }
66
+ exports.getNestedNodes = getNestedNodes;
67
+ exports.PageLayoutContent = zod_1.z.array(exports.LayoutContentNodes).refine((nodes) => {
68
+ // Enforce singular experiment ID within the Page Content
69
+ return nodes
70
+ .concat(getNestedNodes(nodes))
71
+ .filter((n) => n.type === 'experiment')
72
+ .every((v, _, list) => v.experimentId === list[0].experimentId);
73
+ }, { message: 'all experiment nodes must have same experimentId' });
56
74
  /**
57
75
  * Walk through the layout content and resolve the content items.
58
76
  */
@@ -1 +1 @@
1
- {"version":3,"file":"layout-content.js","sourceRoot":"","sources":["../src/layout-content.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AACxB,qDAQ0B;AAC1B,2CAAuD;AAEvD,MAAM,sBAAsB,GAAG,OAAC,CAAC,kBAAkB,CAAC,MAAM,EAAE;IAC1D,8BAAa;IACb,yBAAQ;IACR,wBAAO;IACP,sCAAqB;IACrB,gCAAe;CAChB,CAAC,CAAC;AAEH;;GAEG;AACH,MAAM,mBAAmB,GAAG,CAAC,KAAK,EAAE,sBAAsB,CAAU,CAAC;AAcxD,QAAA,mBAAmB,GAAgF,OAAC;KAC9G,MAAM,CAAC;IACN,OAAO,EAAE,OAAC,CAAC,MAAM,CAAC;QAChB,IAAI,EAAE,OAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,0BAAkB,CAAC,CAAC,QAAQ,EAAE;KAClD,CAAC;IACF,QAAQ,EAAE,wBAAO,CAAC,GAAG,CACnB,OAAC,CAAC,MAAM,CAAC;QACP,IAAI,EAAE,OAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,0BAAkB,CAAC,CAAC,QAAQ,EAAE;KAClD,CAAC,CACH;SACE,KAAK,EAAE;SACP,GAAG,CAAC,CAAC,CAAC;SACN,MAAM,CACL,CAAC,Q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DA2BC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,139 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ const l = __importStar(require("./layout-content"));
27
+ describe('layout-content', () => {
28
+ describe('experiment nodes', () => {
29
+ it('allows experiment node within a personalized node', () => {
30
+ const experiment = {
31
+ type: 'experiment',
32
+ experimentId: 'experiment-id',
33
+ variants: {
34
+ a: [{ type: 'text', value: 'my-a-value' }],
35
+ b: [{ type: 'text', value: 'm-b-value' }],
36
+ },
37
+ };
38
+ const variant = {
39
+ type: 'variation',
40
+ default: {
41
+ node: experiment,
42
+ },
43
+ variants: [
44
+ {
45
+ conditions: { segment: { code: '123' } },
46
+ node: experiment,
47
+ },
48
+ ],
49
+ };
50
+ expect(() => l.LayoutVariationNode.parse(variant)).not.toThrow();
51
+ });
52
+ it('does not allow personalized node within an experiment node', () => {
53
+ const variant = {
54
+ type: 'variation',
55
+ default: {
56
+ node: { type: 'text', value: 'default' },
57
+ },
58
+ variants: [
59
+ {
60
+ conditions: { segment: { code: '123' } },
61
+ node: { type: 'text', value: 'segment' },
62
+ },
63
+ ],
64
+ };
65
+ const experiment = {
66
+ type: 'experiment',
67
+ variants: {
68
+ // @ts-expect-error variant not allowed
69
+ a: [variant],
70
+ b: [{ type: 'text', value: 'b' }],
71
+ },
72
+ };
73
+ expect(() => l.ExperimentNode.parse(experiment)).toThrow();
74
+ });
75
+ it('only allows a single experiment ID', () => {
76
+ const experiment = {
77
+ type: 'experiment',
78
+ experimentId: 'experiment-id',
79
+ variants: {
80
+ a: [{ type: 'text', value: 'my-a-value' }],
81
+ b: [{ type: 'text', value: 'm-b-value' }],
82
+ },
83
+ };
84
+ const otherExperiment = { ...experiment, experimentId: 'different-id' };
85
+ expect(() => l.PageLayoutContent.parse([experiment, otherExperiment])).toThrow();
86
+ });
87
+ it('only allows a single experiment ID in nested experiment blocks', () => {
88
+ const experiment = {
89
+ type: 'experiment',
90
+ experimentId: 'experiment-id',
91
+ variants: {
92
+ a: [{ type: 'text', value: 'my-a-value' }],
93
+ b: [{ type: 'text', value: 'm-b-value' }],
94
+ },
95
+ };
96
+ const variant = {
97
+ type: 'variation',
98
+ default: {
99
+ node: experiment,
100
+ },
101
+ variants: [
102
+ {
103
+ conditions: { segment: { code: '123' } },
104
+ node: experiment,
105
+ },
106
+ ],
107
+ };
108
+ const otherExperiment = { ...experiment, experimentId: 'other-experiment' };
109
+ expect(() => l.PageLayoutContent.parse([variant, otherExperiment])).toThrow();
110
+ });
111
+ });
112
+ describe('getNestedNodes', () => {
113
+ it('recurses through variation nodes', () => {
114
+ const experiment = {
115
+ type: 'experiment',
116
+ experimentId: 'experiment-id',
117
+ variants: {
118
+ a: [{ type: 'text', value: 'my-a-value' }],
119
+ b: [{ type: 'text', value: 'm-b-value' }],
120
+ },
121
+ };
122
+ const variant = {
123
+ type: 'variation',
124
+ default: {
125
+ node: experiment,
126
+ },
127
+ variants: [
128
+ {
129
+ conditions: { segment: { code: '123' } },
130
+ node: experiment,
131
+ },
132
+ ],
133
+ };
134
+ const otherVariant = { ...variant, default: { node: variant } };
135
+ expect(l.getNestedNodes([otherVariant])).toEqual(expect.arrayContaining([variant, experiment]));
136
+ });
137
+ });
138
+ });
139
+ //# sourceMappingURL=layout-content.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"layout-content.spec.js","sourceRoot":"","sources":["../src/layout-content.spec.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAAsC;AAEtC,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAC9B,QAAQ,CAAC,kBAAkB,EAAE,GAAG,EAAE;QAChC,EAAE,CAAC,mDAAmD,EAAE,GAAG,EAAE;YAC3D,MAAM,UAAU,GAAqB;gBACnC,IAAI,EAAE,YAAY;gBAClB,YAAY,EAAE,eAAe;gBAC7B,QAAQ,EAAE;oBACR,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,EAAE,CAAC;oBAC1C,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC;iBAC1C;aACF,CAAC;YAEF,MAAM,OAAO,GAA0B;gBACrC,IAAI,EAAE,WAAW;gBACjB,OAAO,EAAE;oBACP,IAAI,EAAE,UAAU;iBACjB;gBACD,QAAQ,EAAE;oBACR;wBACE,UAAU,EAAE,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE;wBACxC,IAAI,EAAE,UAAU;qBACjB;iBACF;aACF,CAAC;YAEF,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,mBAAmB,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;QACnE,CAAC,CAAC,CAAC;QACH,EAAE,CAAC,4DAA4D,EAAE,GAAG,EAAE;YACpE,MAAM,OAAO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