-
Notifications
You must be signed in to change notification settings - Fork 150
/
index.d.ts
506 lines (440 loc) Β· 21.3 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
import * as axios from 'axios'
export interface RunMigrationConfig {
filePath: string
accessToken?: string
spaceId?: string
environmentId?: string
proxy?: string
rawProxy?: boolean
yes?: boolean
}
export function runMigration (config: RunMigrationConfig): Promise<any>
export interface Movement {
toTheTop(): void
toTheBottom(): void
beforeField(field: string): void
afterField(field: string): void
}
type FieldType = 'Symbol' | 'Text' | 'Integer' | 'Number' | 'Date' | 'Boolean' | 'Object' | 'Location' | 'RichText' | 'Array' | 'Link'
export interface IFieldOptions {
newId?: string
/** (required) β Field name. */
name?: string
/** (required) β Field type */
type: FieldType
/** Object (required for type 'Array') β Defines the items of an Array field. */
items?: IFieldOptions
/** (required for type 'Link') β Type of the referenced entry. Can take the same values as the ones listed for type above. */
linkType?: 'Asset' | 'Entry'
/** Sets the field as required. */
required?: boolean
/** Validations for the field. */
validations?: Array<IValidation>
/** Sets the field as localized. */
localized?: boolean
/** Sets the field as disabled, hence not editable by authors. */
disabled?: boolean
/** Sets the field as omitted, hence not sent in response. */
omitted?: boolean
/** Sets the field as deleted. Requires to have been omitted first. You may prefer using the deleteField method. */
deleted?: boolean
}
export interface Field {
id: string
newId(id: string): Field
/** (required) β Field name. */
name(name: string): Field
/** (required) β Field type */
type(type: FieldType): Field
/** Object (required for type 'Array') β Defines the items of an Array field. */
items(items: IFieldOptions): Field
/** (required for type 'Link') β Type of the referenced entry. Can take the same values as the ones listed for type above. */
linkType(type: 'Asset' | 'Entry'): Field
/** Validations for the field. */
validations(validations: Array<IValidation>): Field
/** Sets the field as required. */
required(required: boolean): Field
/** Sets the field as localized. */
localized(localized: boolean): Field
/** Sets the field as disabled, hence not editable by authors. */
disabled(disabled: boolean): Field
/** Sets the field as omitted, hence not sent in response. */
omitted(omitted: boolean): Field
/** Sets the field as deleted. Requires to have been omitted first. You may prefer using the deleteField method. */
deleted(deleted: boolean): Field
}
type LinkMimetype = 'attachment' | 'plaintext' | 'image' | 'audio' | 'video' | 'richtext' |
'presentation' | 'spreadsheet' | 'pdfdocument' | 'archive' | 'code' | 'markup'
export interface IValidation {
/** Takes an array of content type ids and validates that the link points to an entry of that content type. */
linkContentType?: string[],
/** Takes an array of values and validates that the field value is in this array. */
in?: string[] | number[],
/** Takes a MIME type group name and validates that the link points to an asset of this group. */
linkMimetypeGroup?: LinkMimetype[],
/** Takes min and/or max parameters and validates the size of the array (number of objects in it). */
size?: { max?: number, min?: number },
/** Takes min and/or max parameters and validates the range of a value. */
range?: { max?: number, min?: number},
/** Takes a string that reflects a JS regex and flags, validates against a string. See JS reference for the parameters. */
regexp?: { pattern: string, flags?: string },
/** Validates that there are no other entries that have the same field value at the time of publication. */
unique?: true,
/** Validates that a value falls within a certain range of dates. */
dateRange?: { min?: string, max?: string },
/** Validates that an image asset is of a certain image dimension. */
assetImageDimensions?: { width: { min?: number, max?: number }, height: { min?: number, max?: number } }
/** Validates that an asset is of a certain file size. */
assetFileSize?: { max?: number, min?: number },
message?: string
/** Other validations */
[validation: string]: any
}
export type WidgetSettingsValue = number | boolean | string | undefined
export interface IEditorInterfaceOptions {
/** This help text will show up below the field. */
helpText?: string
/** (only for fields of type boolean) Shows this text next to the radio button that sets this value to true. Defaults to βYesβ. */
trueLabel?: string
/** (only for fields of type boolean) Shows this text next to the radio button that sets this value to false. Defaults to βNoβ. */
falseLabel?: string
/** (only for fields of type rating) Number of stars to select from. Defaults to 5. */
stars?: number
/** (only for fields of type datePicker) β One of "dateonly", "time", "timeZ" (default). Specifies whether to show the clock and/or timezone inputs. */
format?: 'dateonly' | 'time' | 'timeZ'
/** (only for fields of type datePicker) β Specifies which type of clock to use. Must be one of the strings "12" or "24" (default). */
ampm?: '12' | '24'
/** (only for References, many) Select whether to enable Bulk Editing mode */
bulkEditing?: boolean
/** (only for fields of type slugEditor) β Specifies the ID of the field that will be used to generate the slug value. */
trackingFieldId?: string
/** Instance settings for the sidebar widget as key-value pairs. */
[setting: string]: WidgetSettingsValue
}
export interface ISidebarWidgetSettings {
/** Instance settings for the sidebar widget as key-value pairs. */
[setting: string]: WidgetSettingsValue
}
export interface ContentType {
id: string
instanceId: string
/** Name of the content type. */
name(name: string): ContentType
/** Description of the content type. */
description(description: string): ContentType
/** ID of the field to use as the display field for the content type. */
displayField(displayField: string): ContentType
/** Creates a field with provided id. */
createField (id: string, init?: IFieldOptions): Field
/** Edits the field of provided id. */
editField (id: string, init?: IFieldOptions): Field
moveField (id: string): Movement
/** Shorthand method to omit a field, publish its content type, and then delete the field. This implies that associated content for the field will be lost. */
deleteField (id: string): void
/** Changes the field's ID. */
changeFieldId (oldId: string, newId: string): void
/**
*
* @param widgetNamespace The namespace of the widget. Use 'builtin' for standard widgets, 'extension' for UI extensions or 'app' for installed apps.
* @param widgetId The new widget ID for the field.
* @param settings Widget settings
*/
configureEntryEditor(widgetNamespace: 'builtin' | 'extension' | 'app', widgetId: string, settings?: IEditorInterfaceOptions): void
/**
* Changes the control of given field's ID.
*
* @param fieldId The ID of the field.
* @param widgetNamespace The namespace of the widget. Use 'builtin' for standard widgets, 'extension' for UI extensions or 'app' for installed apps.
* @param widgetId The new widget ID for the field.
* @param settings Widget settings
*/
changeFieldControl (fieldId: string, widgetNamespace: 'builtin' | 'extension' | 'app', widgetId: string, settings?: IEditorInterfaceOptions): void
/**
* @deprecated
* Use change field control instead
*/
changeEditorInterface (fieldId: string, widgetId: string, settings?: IEditorInterfaceOptions, widgetNamespace?: 'builtin' | 'extension'): void
/**
* Resets the field control of given field's ID.
*
* @param fieldId The ID of the field.
*/
resetFieldControl (fieldId: string): void
/**
* @deprecated
* Use resetFieldControl instead
*/
resetEditorInterface (fieldId: string): void
/**
* copies the control settings from a field to another field in the same content type.
*
* @param sourceFieldId The ID of the field to copy the control setting from.
* @param destinationFieldId The ID of the field to apply the copied control setting to.
*/
copyFieldControl (sourceFieldId: string, destinationFieldId: string): void
/**
* @deprecated
* Use copyFieldControl instead
*/
copyEditorInterface (sourceFieldId: string, destinationFieldId: string): void
/**
* Adds a builtin or custom widget to the sidebar of the content type.
*
* @param widgetNamespace The namespace of the widget. Use 'sidebar-builtin' for standard widgets or 'extension' for UI extensions.
* @param widgetId The ID of the builtin or extension widget to add.
* @param settings Instance settings for the widget
* @param insertBeforeWidgetId Insert widget above this widget in the sidebar. If null, the widget will be added to the end.
*/
addSidebarWidget (widgetNamespace: 'sidebar-builtin' | 'extension',
widgetId: string,
settings: ISidebarWidgetSettings,
insertBeforeWidgetId: string): void
/**
* Updates the configuration of a widget in the sidebar of the content type.
*
* @param widgetNamespace The namespace of the widget. Use 'sidebar-builtin' for standard widgets or 'extension' for UI extensions.
* @param widgetId The ID of the widget to update.
* @param settings Instance settings for the widget
*/
updateSidebarWidget (widgetNamespace: 'sidebar-builtin' | 'extension',
widgetId: string,
settings: ISidebarWidgetSettings): void
/**
* Removes a widget from the sidebar of the content type.
*
* @param widgetNamespace The namespace of the widget. Use 'sidebar-builtin' for standard widgets or 'extension' for UI extensions.
* @param widgetId The ID of the widget to remove.
*/
removeSidebarWidget (widgetNamespace: 'sidebar-builtin' | 'extension',
widgetId: string): void
/**
* Resets the sidebar of the content type to default
*/
resetSidebarToDefault (): void
}
export interface IContentTypeOptions {
/** Name of the content type. */
name: string,
/** Description of the content type. */
description?: string,
/** ID of the field to use as the display field for the content type. */
displayField?: string
}
type ContentFields = { [field: string]: { [locale: string]: any } }
export interface ITransformEntriesConfig {
/** (required) β Content type ID */
contentType: string,
/** (required) β Array of the source field IDs */
from: string[],
/** (required) β Array of the target field IDs */
to: string[],
/**
* (required) β Transformation function to be applied.
*
* fields is an object containing each of the from fields. Each field will contain their current localized values (i.e. from == {myField: {'en-US': 'my field value'}})
* locale one of the locales in the space being transformed
*
* The return value must be an object with the same keys as specified in to. Their values will be written to the respective entry fields for the current locale (i.e. {nameField: 'myNewValue'}). If it returns undefined, this the values for this locale on the entry will be left untouched.
*/
transformEntryForLocale: (fromFields: ContentFields, currentLocale: string) => any,
/** (optional) β If true, the transformed entries will be published. If false, they will remain in draft state. When the value is set to "preserve" items will be published only if the original entry was published as well (default true) */
shouldPublish?: boolean|"preserve"
}
export interface ITransformEntriesToTypeConfig {
/** (required) β Content type ID of source entries */
sourceContentType: string,
/** (required) β Targeted Content type ID */
targetContentType: string,
/** (optional) β Array of the source field IDs, returns complete list of fields if not configured */
from?: string[],
/** (required) - Function to create a new entry ID for the target entry */
identityKey: (fromFields: ContentFields) => string,
/** (optional) β Flag that specifies publishing of target entries, preserve will keep current states of the source entries (default false) */
shouldPublish?: boolean|"preserve",
/** (optional) β Flag that specifies if linking entries should be updated with target entries (default false) */
updateReferences?: boolean,
/** (optional) β Flag that specifies if source entries should be deleted (default false) */
removeOldEntries?: boolean,
/**
* (required) β Transformation function to be applied.
*
* fields is an object containing each of the from fields. Each field will contain their current localized values (i.e. from == {myField: {'en-US': 'my field value'}})
* locale one of the locales in the space being transformed
*
* The return value must be an object with the same keys as specified in to. Their values will be written to the respective entry fields for the current locale (i.e. {nameField: 'myNewValue'}). If it returns undefined, this the values for this locale on the entry will be left untouched.
*/
transformEntryForLocale: (fromFields: ContentFields, currentLocale: string) => any,
}
export interface IDeriveLinkedEntriesConfig {
/**
* (required) β Source content type ID
*
* This is the content type which has the 'from' fields
*/
contentType: string,
/**
* (required) β Target content type ID
*
* This is the content type that the link points to
*/
derivedContentType: string,
/**
* (required) β Array of the source field IDs
*
* The values in these fields on the source content type
* will be given to "deriveEntryForLocale"
*/
from: string[],
/** (required) β ID of the field on the source content type in which to insert the reference */
toReferenceField: string,
/**
* (required) β Array of the field IDs on the target content type
*
* The fields returned from "deriveEntryForLocale" will be written to these fields
* on the new instance of the derived content type.
*/
derivedFields: string[],
/**
* (required) - Called once per source entry. Returns the ID used for the derived entry, which is also used for de-duplication so that multiple source entries can link to the same derived entry.
* fields is an object containing each of the from fields. Each field will contain their current localized values (i.e. fields == {myField: {'en-US': 'my field value'}})
*/
identityKey: (fromFields: ContentFields) => string,
/** (optional) β If true, both the source and the derived entries will be published. If false, both will remain in draft state. If preserve, will keep current states of the source entries (default true) */
shouldPublish?: boolean | 'preserve',
/**
* (required) β Function that generates the field values for the derived entry.
* fields is an object containing each of the from fields. Each field will contain their current localized values (i.e. fields == {myField: {'en-US': 'my field value'}})
* locale one of the locales in the space being transformed
*
* The return value must be an object with the same keys as specified in derivedFields. Their values will be written to the respective new entry fields for the current locale (i.e. {nameField: 'myNewValue'})
*/
deriveEntryForLocale: (inputFields: ContentFields, locale: string) => { [field: string]: any }
}
export interface ITag {
id: string
instanceId: string
/** Name of the tag. */
name(name: string): ITag
}
export interface ITagOptions {
/** Name of the tag. */
name: string,
}
export interface ITagLink {
sys: {
id: string,
type: 'Link'
linkType: 'Tag'
}
}
export interface ISetTagsForEntriesConfig {
/** (required) β Content type ID */
contentType: string,
/** (required) β Array of the source field IDs */
from: string[],
/**
* (required) β Transformation function to be applied.
*
* entryFields is an object containing each of the from fields.
* entryTags is an array containing link objects of all tags already attached to the entry.
* apiTags is an array containing link objects of all tags available in the environment.
*
* The return value must be an array with TagLinks. The corresponding tags will be attached to the entry. If the transformation function returns undefined, the entry will be left untouched.
*
*/
setTagsForEntry: (entryFields: ContentFields, entryTags: ITagLink[], apiTags: ITagLink[]) => ITagLink[] | undefined
}
/**
* The main interface for creating and editing content types.
*/
export default interface Migration {
/**
* Creates a content type with provided id and returns a reference to the newly created content type.
*
* id : string β The ID of the content type.
*
* opts : Object β Content type definition, with the following options:
*
* * name : string β Name of the content type.
* * description : string β Description of the content type.
* * displayField : string β ID of the field to use as the display field for the content type.
*
* @param id string β The ID of the content type.
* @param init Object β Content type definition
*/
createContentType (id: string, init?: IContentTypeOptions): ContentType
/**
* Edits an existing content type of provided id and returns a reference to the content type. Uses the same options as createContentType.
* @param id string β The ID of the content type.
* @param changes Object β Content type definition
*/
editContentType (id: string, changes?: IContentTypeOptions): ContentType
/**
* Deletes the content type with the provided id and returns undefined. Note that the content type must not have any entries.
* @param id string β The ID of the content type.
*/
deleteContentType (id: string): void
/**
* For the given content type, transforms all its entries according to the user-provided transformEntryForLocale function. For each entry, the CLI will call this function once per locale in the space, passing in the from fields and the locale as arguments. The transform function is expected to return an object with the desired target fields. If it returns undefined, this entry locale will be left untouched.
* @param transformation
*/
transformEntries (transformation: ITransformEntriesConfig): void
/**
* For the given content type, transforms all its entries according to the user-provided transformEntryForLocale function into a new content type. For each entry, the CLI will call this function once per locale in the space, passing in the from fields and the locale as arguments. The transform function is expected to return an object with the desired target fields. If it returns undefined, this entry locale will be left untouched
* @param transformation
*/
transformEntriesToType (transformation: ITransformEntriesToTypeConfig): void
/**
* For each entry of the given content type (source entry), derives a new entry and sets up a reference to it on the source entry. The content of the new entry is generated by the user-provided deriveEntryForLocale function. For each source entry, this function will be called as many times as there are locales in the space. Each time, it will be called with the from fields and one of the locales as arguments. The derive function is expected to return an object with the desired target fields. If it returns undefined, the new entry will have no values for the current locale.
* @param transformation
*/
deriveLinkedEntries (transformation: IDeriveLinkedEntriesConfig): void
/**
* Creates a tag with provided id and returns a reference to the newly created tag.
*
* id : string β The ID of the tag.
*
* opts : Object β tag definition, with the following options:
*
* * name : string β Name of the tag.
*
* @param id string β The ID of the tag.
* @param init Object β Tag definition
*/
createTag (id: string, init?: ITagOptions): ITag
/**
* Edits an existing tag of provided id and returns a reference to the tag. Uses the same options as createTag.
* @param id string β The ID of the tag.
* @param changes Object β Tag definition
*/
editTag (id: string, changes?: ITagOptions): ITag
/**
* Deletes the tag with the provided id and returns undefined.
* @param id string β The ID of the tag.
*/
deleteTag (id: string): void
/**
* For the given content type, transforms all its entries according to the user-provided transformEntryForLocale function. For each entry, the CLI will call this function once per locale in the space, passing in the from fields and the locale as arguments. The transform function is expected to return an object with the desired target fields. If it returns undefined, this entry locale will be left untouched.
* @param transformation
*/
setTagsForEntries (transformation: ISetTagsForEntriesConfig): void
}
export interface ClientConfig {
accessToken?: string
spaceId?: string
environmentId?: string,
proxy?: string,
rawProxy?: boolean
}
export type MakeRequest = (requestConfig: axios.AxiosRequestConfig) => axios.AxiosResponse['data']
export type MigrationContext = ClientConfig & {
/**
* Makes a raw request to the API using Axios.
* The URL should be relative, `spaceId` and `environment` will be automatically prepended.
*/
makeRequest: MakeRequest
}
/**
* The shape of the migration function that should be exported.
*/
export type MigrationFunction = (migration: Migration, context?: MigrationContext) => void