@contentchef/contentchef-types 11.0.0-alpha.4 → 11.0.0-alpha.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,466 +0,0 @@
1
- import { AuthorResponse } from './Author';
2
- import { PagedListResponse } from './common';
3
- import { ContentDefinitionId } from './ContentDefinition';
4
-
5
- /**
6
- * The segment unique id
7
- */
8
- export type SegmentId = number;
9
-
10
- /**
11
- * A segment's mnemonicId and every one of its keys must match this pattern: lowercase, digits,
12
- * underscore and hyphen. Stricter than the other authoring mnemonicIds on purpose, because both halves
13
- * travel in the delivery `segments` query param and are compared against strings a client supplies
14
- */
15
- export const SEGMENT_NAME_PATTERN = /^[a-z0-9_-]+$/;
16
-
17
- /**
18
- * This type represent one key of a segment, that is one of the values a visitor can have for it
19
- */
20
- export type SegmentKey = {
21
- /**
22
- * The key, matching [[SEGMENT_NAME_PATTERN]]
23
- */
24
- key: string;
25
- /**
26
- * A deprecated key cannot be referenced by new content rules, while every rule already written
27
- * keeps resolving. The flag toggles both ways
28
- */
29
- deprecated?: boolean;
30
- };
31
-
32
- /**
33
- * This type represent the model of a segment, that is a dimension a content can vary by - `gender`,
34
- * `loyalty`, `auth_status` - holding the fixed set of keys a visitor can have for it
35
- *
36
- * Contents reference a segment by mnemonicId and key inside their rules, and definitions by
37
- * mnemonicId, so segments are archived and never deleted, and a key can only be removed or renamed
38
- * while no content references it
39
- */
40
- export type SegmentResponse = {
41
- /**
42
- * The segment unique id
43
- */
44
- id: SegmentId;
45
- /**
46
- * The segment name
47
- */
48
- name: string;
49
- /**
50
- * The segment mnemonic id, matching [[SEGMENT_NAME_PATTERN]]
51
- */
52
- mnemonicId: string;
53
- /**
54
- * The keys a visitor can hold for this segment, each carrying its own deprecation state
55
- */
56
- keys: SegmentKey[];
57
- /**
58
- * The archived status of the segment
59
- */
60
- archived: boolean;
61
- /**
62
- * The archive date of the segment
63
- */
64
- archivedDate: Date | null;
65
- /**
66
- * The segment creation date
67
- */
68
- createdDate: Date;
69
- /**
70
- * The segment last modified date
71
- */
72
- lastModifiedDate: Date;
73
- /**
74
- * The segment author, resolved by `list` only
75
- */
76
- author?: AuthorResponse;
77
- /**
78
- * The segment last modified author, resolved by every endpoint but `get`
79
- */
80
- latestContributor?: AuthorResponse;
81
- };
82
-
83
- /**
84
- * This type represent all possible filters used to retrieve a list of segment
85
- */
86
- export type ListSegmentsFilters = {
87
- /**
88
- * This filter is used to retrieve archived or not archived segments. Defaults to not archived
89
- */
90
- archived?: boolean;
91
- };
92
-
93
- /**
94
- * This type represent the data needed to make a list segments API request
95
- */
96
- export type ListSegmentsRequest = {
97
- /**
98
- * The number of segments to skip (this value is used for pagination)
99
- */
100
- skip?: number;
101
- /**
102
- * The number of segments to take (this value is used for pagination), at most 100
103
- */
104
- take?: number;
105
- /**
106
- * The data used to filter the list of segments
107
- */
108
- filters?: ListSegmentsFilters;
109
- };
110
-
111
- /**
112
- * This type represent the item of a list segments API request
113
- */
114
- export type ListSegmentsItem = SegmentResponse;
115
-
116
- /**
117
- * This type represent the response of a list segments API request
118
- */
119
- export type ListSegmentsResponse = PagedListResponse<ListSegmentsItem>;
120
-
121
- /**
122
- * This type represent the usage of one key of a segment. A key with no entry is used by no content,
123
- * and is therefore the only kind of key that can be removed or renamed
124
- */
125
- export type SegmentKeyUsage = {
126
- /**
127
- * The key, or null for the rules that constrain the segment without naming any key - that is the
128
- * ones that only fire when the segment is unknown
129
- */
130
- key: string | null;
131
- /**
132
- * How many contents reference this key
133
- */
134
- contents: number;
135
- };
136
-
137
- /**
138
- * This type represent a content definition that declares a segment
139
- */
140
- export type DefinitionUsingSegment = {
141
- /**
142
- * The content definition unique id
143
- */
144
- id: ContentDefinitionId;
145
- /**
146
- * The content definition mnemonic id
147
- */
148
- mnemonicId: string;
149
- /**
150
- * The content definition name
151
- */
152
- name: string;
153
- };
154
-
155
- /**
156
- * This type represent the data needed to make a get segment API request
157
- */
158
- export type GetSegmentRequest = {
159
- /**
160
- * The unique segment id to retrieve
161
- */
162
- id: SegmentId;
163
- };
164
-
165
- /**
166
- * This type represent the response of a get segment API request: the segment, plus the two things the
167
- * editor cannot decide without, which keys are in use and which definitions vary by this segment
168
- */
169
- export type GetSegmentResponse = SegmentResponse & {
170
- /**
171
- * One entry per key at least one content references. A key absent from this list is unused
172
- */
173
- keyUsage: SegmentKeyUsage[];
174
- /**
175
- * The content definitions declaring this segment
176
- */
177
- definitions: DefinitionUsingSegment[];
178
- };
179
-
180
- /**
181
- * This type represent the data needed to make a create segment API request
182
- */
183
- export type CreateSegmentRequest = {
184
- /**
185
- * The segment name
186
- */
187
- name: string;
188
- /**
189
- * The segment mnemonic id, matching [[SEGMENT_NAME_PATTERN]]
190
- */
191
- mnemonicId: string;
192
- /**
193
- * The keys a visitor can hold for this segment, at least one, each key unique
194
- */
195
- keys: SegmentKey[];
196
- };
197
-
198
- /**
199
- * This type represent the response of a create segment API request
200
- */
201
- export type CreateSegmentResponse = SegmentResponse;
202
-
203
- /**
204
- * This type represent the data needed to make an update segment API request
205
- *
206
- * `keys` replaces the whole stored list, deprecation flags included. Adding keys and toggling
207
- * deprecation are always allowed, while removing or renaming a key is refused while a content still
208
- * references it. `mnemonicId` cannot be changed
209
- */
210
- export type UpdateSegmentRequest = {
211
- /**
212
- * The segment unique id
213
- */
214
- id: SegmentId;
215
- /**
216
- * The segment name to update
217
- */
218
- name: string;
219
- /**
220
- * The segment mnemonic id, which must be the stored one
221
- */
222
- mnemonicId: string;
223
- /**
224
- * The whole key list, replacing what is stored
225
- */
226
- keys: SegmentKey[];
227
- };
228
-
229
- /**
230
- * This type represent the response of an update segment API request
231
- */
232
- export type UpdateSegmentResponse = SegmentResponse;
233
-
234
- /**
235
- * This type represent the data needed to make a toggle archived segment API request
236
- */
237
- export type ToggleArchivedSegmentRequest = {
238
- /**
239
- * The segment unique id
240
- */
241
- id: SegmentId;
242
- /**
243
- * This value represent the archive status to set in the specified segment
244
- */
245
- archived: boolean;
246
- };
247
-
248
- /**
249
- * This type represent the response of a toggle archived segment API request
250
- */
251
- export type ToggleArchivedSegmentResponse = SegmentResponse;
252
-
253
- /**
254
- * This type represent the condition of one rule on a single segment: the visitor's value for
255
- * [[segment]] has to be one of [[in]]
256
- */
257
- export type SegmentPredicate = {
258
- /**
259
- * The mnemonic id of the segment this predicate constrains, which the field must declare
260
- */
261
- segment: string;
262
- /**
263
- * The keys of the segment that satisfy this predicate
264
- */
265
- in: string[];
266
- /**
267
- * Set this value to also satisfy the predicate when the segment was not provided at all
268
- *
269
- * Not-provided is not a key, so no list of keys can express it, and an enumeration would silently
270
- * narrow the moment a key is added to the segment. A key that was provided but is not listed does
271
- * not satisfy this flag: it falls through to the field's fallback
272
- */
273
- orUnset?: boolean;
274
- };
275
-
276
- /**
277
- * This type represent a condition satisfied when every child condition is satisfied
278
- */
279
- export type AllSegmentPredicate = {
280
- all: SegmentRuleCondition[];
281
- };
282
-
283
- /**
284
- * This type represent a condition satisfied when at least one child condition is satisfied
285
- */
286
- export type AnySegmentPredicate = {
287
- any: SegmentRuleCondition[];
288
- };
289
-
290
- /**
291
- * This type represent the condition of a rule
292
- *
293
- * The stored form is a tree so that new kinds of condition stay additive, but an editor only needs to
294
- * build an [[AllSegmentPredicate]] of one [[SegmentPredicate]] per segment: or within a segment, and
295
- * between segments. A segment the condition does not mention is unconstrained, which is a different
296
- * thing from one listed with [[SegmentPredicate.orUnset]]
297
- */
298
- export type SegmentRuleCondition = SegmentPredicate | AllSegmentPredicate | AnySegmentPredicate;
299
-
300
- /**
301
- * This type represent one rule of a segmented field: the condition, and the value to serve when it wins
302
- * @template T The type of the value served by the rule, which conforms to the field's `variantType`
303
- */
304
- export type SegmentRule<T = any> = {
305
- /**
306
- * The rule id, unique in the field. Used for diagnostics only, matching never reads it
307
- */
308
- id?: string;
309
- /**
310
- * The condition under which this rule wins
311
- */
312
- when: SegmentRuleCondition;
313
- /**
314
- * The value served when this rule wins
315
- */
316
- value: T;
317
- };
318
-
319
- /**
320
- * This type represent the value a segmented field holds in a content payload: an ordered list of
321
- * rules, first match wins, and the fallback served when no rule matches
322
- *
323
- * The fallback is mandatory exactly when the field is required, which keeps the delivery contract of a
324
- * segmented field the same as any other field. Zero rules is legal: the field is then just its fallback
325
- * @template T The type of the served values, which conform to the field's `variantType`
326
- */
327
- export type SegmentedFieldPayload<T = any> = {
328
- /**
329
- * The rules, in the order they are evaluated in
330
- */
331
- rules?: SegmentRule<T>[];
332
- /**
333
- * The value served when no rule matches
334
- */
335
- fallback?: T;
336
- };
337
-
338
- /**
339
- * This type represent the visitor's value per segment, as the rule engine reads it. A segment missing
340
- * from the map, or set to `undefined`, means "not provided" - which is what
341
- * [[SegmentPredicate.orUnset]] answers
342
- */
343
- export type SegmentAssignment = {
344
- [segmentMnemonicId: string]: string | undefined;
345
- };
346
-
347
- /**
348
- * The stand-in a coverage report uses for "a key none of the rules mention"
349
- *
350
- * Not a real key - it cannot be one, since keys match [[SEGMENT_NAME_PATTERN]]. A rule only ever tests
351
- * membership in its own list, so every unmentioned key behaves identically and one case covers them
352
- * all, which is what keeps the analysis exact and small. [[CoverageReport.otherKeys]] says which real
353
- * keys it stood for
354
- */
355
- export const OTHER_KEY = '<any other key>';
356
-
357
- /**
358
- * This type represent how much of a rule list one rule actually serves
359
- */
360
- export type RuleCoverage = {
361
- /**
362
- * The position of the rule in the analysed list
363
- */
364
- index: number;
365
- /**
366
- * The rule id, when it carries one
367
- */
368
- id?: string;
369
- /**
370
- * The condition in words, so a finding reads without decoding a predicate
371
- */
372
- condition: string;
373
- /**
374
- * How many of the analysed assignments this rule wins. Zero means it can never serve anyone
375
- */
376
- wins: number;
377
- };
378
-
379
- /**
380
- * This type represent what an ordered rule list covers, worked out from the rules and the segments'
381
- * keys alone - no request traffic is involved
382
- *
383
- * The findings are advisory and never validation violations: a gap is usually deliberate, that being
384
- * what a fallback is for, while an unreachable rule is almost always a mistake
385
- */
386
- export type CoverageReport = {
387
- /**
388
- * How many assignments were evaluated, after collapsing the keys no rule mentions
389
- */
390
- combinations: number;
391
- /**
392
- * One entry per analysed rule, in author order
393
- */
394
- rules: RuleCoverage[];
395
- /**
396
- * The rules that win nothing: shadowed by an earlier rule, or self-contradictory
397
- */
398
- unreachableRules: RuleCoverage[];
399
- /**
400
- * The assignments no rule claims, so they reach the fallback. Capped at 25 entries, while
401
- * [[fallbackCount]] is the real total
402
- */
403
- fallbackAssignments: SegmentAssignment[];
404
- /**
405
- * How many assignments reach the fallback, of [[combinations]]
406
- */
407
- fallbackCount: number;
408
- /**
409
- * The segments declared by the field but constrained by no rule, so they change nothing about what
410
- * it serves
411
- */
412
- unusedSegments: string[];
413
- /**
414
- * What [[OTHER_KEY]] stood for, per segment: the real unmentioned keys, capped at 10, with their
415
- * total. Only the segments that needed the stand-in appear
416
- */
417
- otherKeys: { [segment: string]: { keys: string[]; total: number } };
418
- /**
419
- * Set when the rules and their segments were too large to enumerate. Everything else is then
420
- * unpopulated rather than guessed, because a sampled "no gaps" is not a fact
421
- */
422
- notAnalysed?: { reason: 'tooManyCombinations'; combinations: number };
423
- };
424
-
425
- /**
426
- * This type represent one rule as the analyse rules API request takes it: the condition, and nothing
427
- * about what the rule serves. Coverage is decided by conditions only, so the values stay out of the
428
- * request - and a half written rule with no condition is analysed as one that matches nothing rather
429
- * than refused
430
- */
431
- export type SegmentRuleDraft = {
432
- /**
433
- * The rule id, when it carries one. Reported back on the finding, so a client can match a finding
434
- * to the rule on screen without relying on the index
435
- */
436
- id?: string;
437
- /**
438
- * The condition under which this rule wins
439
- */
440
- when?: SegmentRuleCondition;
441
- };
442
-
443
- /**
444
- * This type represent the data needed to make an analyse rules API request, which is what a field's
445
- * rule editor asks about the rules on screen, before anything is saved
446
- *
447
- * The keys of every segment are read from the space rather than taken from the request, so a client
448
- * never has to hold them or keep them current
449
- */
450
- export type AnalyseSegmentRulesRequest = {
451
- /**
452
- * The mnemonic ids of the segments the field varies by, at most 20. The analysis is bounded by
453
- * these, as the field's rules are
454
- */
455
- segments: string[];
456
- /**
457
- * The rules in author order, at most 200. The order is the whole point: first match wins, so a rule
458
- * being unreachable is a consequence of what precedes it
459
- */
460
- rules: SegmentRuleDraft[];
461
- };
462
-
463
- /**
464
- * This type represent the response of an analyse rules API request
465
- */
466
- export type AnalyseSegmentRulesResponse = CoverageReport;