@contentchef/contentchef-types 11.0.0-alpha.3 → 11.0.0-alpha.5

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,336 +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
- };