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