datocms-plugin-sdk 0.3.26 → 0.3.33

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.
package/src/types.ts ADDED
@@ -0,0 +1,1449 @@
1
+ import {
2
+ Account,
3
+ Field,
4
+ Fieldset,
5
+ Item,
6
+ ModelBlock,
7
+ Plugin,
8
+ Role,
9
+ Site,
10
+ SsoUser,
11
+ Upload,
12
+ User,
13
+ } from './SiteApiSchema';
14
+
15
+ export type Icon = string | { type: 'svg'; viewBox: string; content: string };
16
+
17
+ /** A tab to be displayed in the top-bar of the UI */
18
+ export type MainNavigationTab = {
19
+ /** Label to be shown. Must be unique. */
20
+ label: string;
21
+ /**
22
+ * Icon to be shown alongside the label. Can be a FontAwesome icon name (ie.
23
+ * `"address-book"`) or a custom SVG definition. To maintain visual
24
+ * consistency with the rest of the interface, try to use FontAwesome icons
25
+ * whenever possible.
26
+ */
27
+ icon: Icon;
28
+ /** ID of the page linked to the tab */
29
+ pointsTo: {
30
+ pageId: string;
31
+ };
32
+ /**
33
+ * Expresses where you want to place the tab in the top-bar. If not specified,
34
+ * the tab will be placed after the standard tabs provided by DatoCMS itself.
35
+ */
36
+ placement?: [
37
+ 'before' | 'after',
38
+ 'content' | 'mediaArea' | 'apiExplorer' | 'settings',
39
+ ];
40
+ /**
41
+ * If different plugins specify the same `placement` for their tabs, they will
42
+ * be displayed by ascending `rank`. If you want to specify an explicit value
43
+ * for `rank`, make sure to offer a way for final users to customize it inside
44
+ * the plugin's settings form, otherwise the hardcoded value you choose might
45
+ * clash with the one of another plugin! *
46
+ */
47
+ rank?: number;
48
+ };
49
+
50
+ /** An item contained in a Settings Area group */
51
+ export type SettingsAreaSidebarItem = {
52
+ /** Label to be shown. Must be unique. */
53
+ label: string;
54
+ /**
55
+ * Icon to be shown alongside the label. Can be a FontAwesome icon name (ie.
56
+ * `"address-book"`) or a custom SVG definition. To maintain visual
57
+ * consistency with the rest of the interface, try to use FontAwesome icons
58
+ * whenever possible.
59
+ */
60
+ icon: Icon;
61
+ /** ID of the page linked to the item */
62
+ pointsTo: {
63
+ pageId: string;
64
+ };
65
+ };
66
+
67
+ /**
68
+ * The sidebar in the Settings Area presents a number of pages grouped by topic.
69
+ * This object represents a new group to be added in the sideebar to the
70
+ * standard ones DatoCMS provides.
71
+ */
72
+ export type SettingsAreaSidebarItemGroup = {
73
+ /** Label to be shown. Must be unique. */
74
+ label: string;
75
+ /** The list of items it contains * */
76
+ items: SettingsAreaSidebarItem[];
77
+ /**
78
+ * Expresses where you want the group to be placed inside the sidebar. If not
79
+ * specified, the item will be placed after the standard items provided by
80
+ * DatoCMS itself.
81
+ */
82
+ placement?: [
83
+ 'before' | 'after',
84
+ (
85
+ | 'environment'
86
+ | 'project'
87
+ | 'permissions'
88
+ | 'webhooks'
89
+ | 'deployment'
90
+ | 'sso'
91
+ | 'auditLog'
92
+ | 'usage'
93
+ ),
94
+ ];
95
+ /**
96
+ * If different plugins specify the same `placement` for their sections, they
97
+ * will be displayed by ascending `rank`. If you want to specify an explicit
98
+ * value for `rank`, make sure to offer a way for final users to customize it
99
+ * inside the plugin's settings form, otherwise the hardcoded value you choose
100
+ * might clash with the one of another plugin! *
101
+ */
102
+ rank?: number;
103
+ };
104
+
105
+ /**
106
+ * The sidebar in the Content Area presents a number of user-defined menu-items.
107
+ * This object represents a new item to be added in the sidebar.
108
+ */
109
+ export type ContentAreaSidebarItem = {
110
+ /** Label to be shown. Must be unique. */
111
+ label: string;
112
+ /**
113
+ * Icon to be shown alongside the label. Can be a FontAwesome icon name (ie.
114
+ * `"address-book"`) or a custom SVG definition. To maintain visual
115
+ * consistency with the rest of the interface, try to use FontAwesome icons
116
+ * whenever possible.
117
+ */
118
+ icon: Icon;
119
+ /** ID of the page linked to the item */
120
+ pointsTo: {
121
+ pageId: string;
122
+ };
123
+ /**
124
+ * Expresses where you want the item to be placed inside the sidebar. If not
125
+ * specified, the item will be placed after the standard items provided by
126
+ * DatoCMS itself.
127
+ */
128
+ placement?: ['before' | 'after', 'menuItems' | 'settings'];
129
+ /**
130
+ * If different plugins specify the same `placement` for their panels, they
131
+ * will be displayed by ascending `rank`. If you want to specify an explicit
132
+ * value for `rank`, make sure to offer a way for final users to customize it
133
+ * inside the plugin's settings form, otherwise the hardcoded value you choose
134
+ * might clash with the one of another plugin! *
135
+ */
136
+ rank?: number;
137
+ };
138
+
139
+ export type FieldExtensionType = 'editor' | 'addon';
140
+
141
+ export type FieldType =
142
+ | 'boolean'
143
+ | 'color'
144
+ | 'date_time'
145
+ | 'date'
146
+ | 'file'
147
+ | 'float'
148
+ | 'gallery'
149
+ | 'integer'
150
+ | 'json'
151
+ | 'lat_lon'
152
+ | 'link'
153
+ | 'links'
154
+ | 'rich_text'
155
+ | 'seo'
156
+ | 'slug'
157
+ | 'string'
158
+ | 'structured_text'
159
+ | 'text'
160
+ | 'video';
161
+
162
+ /**
163
+ * Field extensions extend the basic functionality of DatoCMS when it comes to
164
+ * presenting record's fields to the final user. Depending on the extension type
165
+ * (`editor` or `addon`) they will be shown in different places of the interface.
166
+ */
167
+ export type ManualFieldExtension = {
168
+ /**
169
+ * ID of field extension. Will be the first argument for the
170
+ * `renderFieldExtension` function
171
+ */
172
+ id: string;
173
+ /** Name to be shown when editing fields */
174
+ name: string;
175
+ /**
176
+ * Type of field extension. An `editor` extension replaces the default field
177
+ * editor that DatoCMS provides, while an `addon` extension is placed
178
+ * underneath the field editor to provide additional info/behaviour. You can
179
+ * setup multiple field addons for every field.
180
+ */
181
+ type: FieldExtensionType;
182
+ /**
183
+ * For `editor` extensions: moves the field to the sidebar of the record
184
+ * editing page, mimicking a sidebar panel
185
+ */
186
+ asSidebarPanel?: boolean | { startOpen: boolean };
187
+ /**
188
+ * The type of fields that the field extension in compatible with. You can use
189
+ * the shortcut `all` to target all types of fields
190
+ */
191
+ fieldTypes: 'all' | FieldType[];
192
+ /**
193
+ * Whether this field extension needs some configuration options before being
194
+ * installed in a field or not. Will trigger the
195
+ * `renderManualFieldExtensionConfigScreen` and
196
+ * `validateManualFieldExtensionParameters` methods
197
+ */
198
+ configurable?: boolean | { initialHeight: number };
199
+ /** The initial height to set for the iframe that will render the field extension */
200
+ initialHeight?: number;
201
+ };
202
+
203
+ export type ItemFormSidebarPanelPlacement = [
204
+ 'before' | 'after',
205
+ 'info' | 'actions' | 'links' | 'history',
206
+ ];
207
+
208
+ /** A sidebar panel to be shown inside the record's editing page */
209
+ export type ItemFormSidebarPanel = {
210
+ /**
211
+ * ID of the panel. Will be the first argument for the
212
+ * `renderItemFormSidebarPanel` function
213
+ */
214
+ id: string;
215
+ /** Label to be shown on the collapsible sidebar panel handle */
216
+ label: string;
217
+ /**
218
+ * An arbitrary configuration object that will be passed as the `parameters`
219
+ * property of the second argument of the `renderItemFormSidebarPanel` function
220
+ */
221
+ parameters?: Record<string, unknown>;
222
+ /** Whether the sidebar panel will start open or collapsed */
223
+ startOpen?: boolean;
224
+ /**
225
+ * Expresses where you want the item to be placed inside the sidebar. If not
226
+ * specified, the item will be placed after the standard panels provided by
227
+ * DatoCMS itself.
228
+ */
229
+ placement?: ItemFormSidebarPanelPlacement;
230
+ /**
231
+ * If multiple sidebar panels specify the same `placement`, they will be
232
+ * sorted by ascending `rank`. If you want to specify an explicit value for
233
+ * `rank`, make sure to offer a way for final users to customize it inside the
234
+ * plugin's settings form, otherwise the hardcoded value you choose might
235
+ * clash with the one of another plugin! *
236
+ */
237
+ rank?: number;
238
+ /** The initial height to set for the iframe that will render the sidebar panel */
239
+ initialHeight?: number;
240
+ };
241
+
242
+ /** A field editor/sidebar forced on a field */
243
+ export type EditorOverride = {
244
+ /**
245
+ * ID of field extension. Will be the first argument for the
246
+ * `renderFieldExtension` function
247
+ */
248
+ id: string;
249
+ /** Moves the field to the sidebar of the record editing page, mimicking a sidebar panel */
250
+ asSidebarPanel?:
251
+ | boolean
252
+ | { startOpen?: boolean; placement?: ItemFormSidebarPanelPlacement };
253
+ /**
254
+ * An arbitrary configuration object that will be passed as the `parameters`
255
+ * property of the second argument of the `renderFieldExtension` function
256
+ */
257
+ parameters?: Record<string, unknown>;
258
+ /**
259
+ * If multiple plugins override a field, the one with the highest `rank` will
260
+ * win. If you want to specify an explicit value for `rank`, make sure to
261
+ * offer a way for final users to customize it inside the plugin's settings
262
+ * form, otherwise the hardcoded value you choose might clash with the one of
263
+ * another plugin! *
264
+ */
265
+ rank?: number;
266
+ /** The initial height to set for the iframe that will render the field extension */
267
+ initialHeight?: number;
268
+ };
269
+
270
+ /** A field addon extension forced on a field */
271
+ export type AddonOverride = {
272
+ /**
273
+ * ID of field extension. Will be the first argument for the
274
+ * `renderFieldExtension` function
275
+ */
276
+ id: string;
277
+ /**
278
+ * An arbitrary configuration object that will be passed as the `parameters`
279
+ * property of the second argument of the `renderFieldExtension` function
280
+ */
281
+ parameters?: Record<string, unknown>;
282
+ /**
283
+ * If multiple addons are present for a field, they will be sorted by
284
+ * ascending `rank`. If you want to specify an explicit value for `rank`, make
285
+ * sure to offer a way for final users to customize it inside the plugin's
286
+ * settings form, otherwise the hardcoded value you choose might clash with
287
+ * the one of another plugin! *
288
+ */
289
+ rank?: number;
290
+ /** The initial height to set for the iframe that will render the field extension */
291
+ initialHeight?: number;
292
+ };
293
+
294
+ /** An object expressing some field extensions you want to force on a particular field */
295
+ export type FieldExtensionOverride = {
296
+ /** Force a field editor/sidebar extension on a field */
297
+ editor?: EditorOverride;
298
+ /** One or more field sidebar extensions to forcefully add to a field */
299
+ addons?: AddonOverride[];
300
+ };
301
+
302
+ /** An object containing the theme colors for the current DatoCMS project */
303
+ export type Theme = {
304
+ primaryColor: string;
305
+ accentColor: string;
306
+ semiTransparentAccentColor: string;
307
+ lightColor: string;
308
+ darkColor: string;
309
+ };
310
+
311
+ /** Focal point of an image asset */
312
+ export type FocalPoint = {
313
+ /** Horizontal position expressed as float between 0 and 1 */
314
+ x: number;
315
+ /** Vertical position expressed as float between 0 and 1 */
316
+ y: number;
317
+ };
318
+
319
+ /** The structure contained in a "single asset" field */
320
+ export type FileFieldValue = {
321
+ /** ID of the asset */
322
+ // eslint-disable-next-line camelcase
323
+ upload_id: string;
324
+ /** Alternate text for the asset */
325
+ alt: string | null;
326
+ /** Title for the asset */
327
+ title: string | null;
328
+ /** Focal point of an asset */
329
+ // eslint-disable-next-line camelcase
330
+ focal_point: FocalPoint | null;
331
+ /** Object with arbitrary metadata related to the asset */
332
+ // eslint-disable-next-line camelcase
333
+ custom_data: Record<string, string>;
334
+ };
335
+
336
+ /** A modal to present to the user */
337
+ export type Modal = {
338
+ /** ID of the modal. Will be the first argument for the `renderModal` function */
339
+ id: string;
340
+ /** Title for the modal. Ignored by `fullWidth` modals */
341
+ title?: string;
342
+ /** Whether to present a close button for the modal or not */
343
+ closeDisabled?: boolean;
344
+ /** Width of the modal. Can be a number, or one of the predefined sizes */
345
+ width?: 's' | 'm' | 'l' | 'xl' | 'fullWidth' | number;
346
+ /**
347
+ * An arbitrary configuration object that will be passed as the `parameters`
348
+ * property of the second argument of the `renderModal` function
349
+ */
350
+ parameters?: Record<string, unknown>;
351
+ /** The initial height to set for the iframe that will render the modal content */
352
+ initialHeight?: number;
353
+ };
354
+
355
+ /** An additional asset source */
356
+ export type AssetSource = {
357
+ /**
358
+ * ID of the asset source. Will be the first argument for the
359
+ * `renderAssetSource` function
360
+ */
361
+ id: string;
362
+ /** Name of the asset that will be shown to the user */
363
+ name: string;
364
+ /**
365
+ * Icon to be shown alongside the name. Can be a FontAwesome icon name (ie.
366
+ * `"address-book"`) or a custom SVG definition. To maintain visual
367
+ * consistency with the rest of the interface, try to use FontAwesome icons
368
+ * whenever possible.
369
+ */
370
+ icon: Icon;
371
+ /**
372
+ * Configuration options for the modal that will be opened to select a media
373
+ * file from this source
374
+ */
375
+ modal?: {
376
+ /** Width of the modal. Can be a number, or one of the predefined sizes */
377
+ width?: 's' | 'm' | 'l' | 'xl' | number;
378
+ /** The initial height to set for the iframe that will render the modal content */
379
+ initialHeight?: number;
380
+ };
381
+ };
382
+
383
+ /** A toast notification to present to the user */
384
+ export type Toast<CtaValue = unknown> = {
385
+ /** Message of the notification */
386
+ message: string;
387
+ /** Type of notification. Will present the toast in a different color accent. */
388
+ type: 'notice' | 'alert' | 'warning';
389
+ /** An optional button to show inside the toast */
390
+ cta?: {
391
+ /** Label for the button */
392
+ label: string;
393
+ /**
394
+ * The value to be returned by the `customToast` promise if the button is
395
+ * clicked by the user
396
+ */
397
+ value: CtaValue;
398
+ };
399
+ /** Whether the toast is to be automatically closed if the user changes page */
400
+ dismissOnPageChange?: boolean;
401
+ /**
402
+ * Whether the toast is to be automatically closed after some time (`true`
403
+ * will use the default DatoCMS time interval)
404
+ */
405
+ dismissAfterTimeout?: boolean | number;
406
+ };
407
+
408
+ /** A choice presented in a `openConfirm` panel */
409
+ export type ConfirmChoice = {
410
+ /** The label to be shown for the choice */
411
+ label: string;
412
+ /**
413
+ * The value to be returned by the `openConfirm` promise if the button is
414
+ * clicked by the user
415
+ */
416
+ value: unknown;
417
+ /** The intent of the button. Will present the button in a different color accent. */
418
+ intent?: 'positive' | 'negative';
419
+ };
420
+
421
+ /** Options for the `openConfirm` function */
422
+ export type ConfirmOptions = {
423
+ /** The title to be shown inside the confirmation panel */
424
+ title: string;
425
+ /** The main message to be shown inside the confirmation panel */
426
+ content: string;
427
+ /** The different options the user can choose from */
428
+ choices: ConfirmChoice[];
429
+ /** The cancel option to present to the user */
430
+ cancel: ConfirmChoice;
431
+ };
432
+
433
+ /** Generic properties available in all the hooks */
434
+ export type CommonProperties = {
435
+ /** The current DatoCMS project */
436
+ site: Site;
437
+ /** The ID of the current environment */
438
+ environment: string;
439
+ /** All the models of the current DatoCMS project, indexed by ID */
440
+ itemTypes: Partial<Record<string, ModelBlock>>;
441
+ /**
442
+ * The current DatoCMS user. It can either be the owner or one of the
443
+ * collaborators (regular or SSO).
444
+ */
445
+ currentUser: User | SsoUser | Account;
446
+ /** The role for the current DatoCMS user */
447
+ currentRole: Role;
448
+ /**
449
+ * The access token to perform API calls on behalf of the current user. Only
450
+ * available if `currentUserAccessToken` additional permission is granted
451
+ */
452
+ currentUserAccessToken: string | undefined;
453
+ /** The current plugin */
454
+ plugin: Plugin;
455
+ /**
456
+ * UI preferences of the current user (right now, only the preferred locale is
457
+ * available)
458
+ */
459
+ ui: {
460
+ /** Preferred locale */
461
+ locale: string;
462
+ };
463
+ };
464
+
465
+ export type InitAdditionalProperties = {
466
+ mode: 'init';
467
+ };
468
+
469
+ export type InitProperties = CommonProperties & InitAdditionalProperties;
470
+
471
+ export type InitMethods = {
472
+ getSettings: () => Promise<InitProperties>;
473
+ };
474
+
475
+ export type InitPropertiesAndMethods = InitMethods & InitProperties;
476
+
477
+ /** Additional properties available in all `renderXXX` hooks */
478
+ export type RenderAdditionalProperties = {
479
+ /**
480
+ * All the fields currently loaded for the current DatoCMS project, indexed by
481
+ * ID. It will always contain the current model fields and all the fields of
482
+ * the blocks it might contain via Modular Content/Structured Text fields. If
483
+ * some fields you need are not present, use the `loadItemTypeFields` function
484
+ * to load them.
485
+ */
486
+ fields: Partial<Record<string, Field>>;
487
+ /**
488
+ * All the fieldsets currently loaded for the current DatoCMS project, indexed
489
+ * by ID. It will always contain the current model fields and all the fields
490
+ * of the blocks it might contain via Modular Content/Structured Text fields.
491
+ * If some fields you need are not present, use the `loadItemTypeFieldsets`
492
+ * function to load them.
493
+ */
494
+ fieldsets: Partial<Record<string, Fieldset>>;
495
+ /** An object containing the theme colors for the current DatoCMS project */
496
+ theme: Theme;
497
+ /**
498
+ * All the regular users currently loaded for the current DatoCMS project,
499
+ * indexed by ID. It will always contain the current user. If some users you
500
+ * need are not present, use the `loadUsers` function to load them.
501
+ */
502
+ users: Partial<Record<string, User>>;
503
+ /**
504
+ * All the SSO users currently loaded for the current DatoCMS project, indexed
505
+ * by ID. It will always contain the current user. If some users you need are
506
+ * not present, use the `loadSsoUsers` function to load them.
507
+ */
508
+ ssoUsers: Partial<Record<string, SsoUser>>;
509
+ /** The project owner */
510
+ account: Account;
511
+ /** The padding in px that must be applied to the body */
512
+ bodyPadding: [number, number, number, number];
513
+ };
514
+
515
+ export type RenderProperties = CommonProperties & RenderAdditionalProperties;
516
+
517
+ export type FieldAppearanceChange =
518
+ | {
519
+ operation: 'removeEditor';
520
+ }
521
+ | {
522
+ operation: 'updateEditor';
523
+ newFieldExtensionId?: string;
524
+ newParameters?: Record<string, unknown>;
525
+ }
526
+ | {
527
+ operation: 'setEditor';
528
+ fieldExtensionId: string;
529
+ parameters: Record<string, unknown>;
530
+ }
531
+ | {
532
+ operation: 'removeAddon';
533
+ index: number;
534
+ }
535
+ | {
536
+ operation: 'updateAddon';
537
+ index: number;
538
+ newFieldExtensionId?: string;
539
+ newParameters?: Record<string, unknown>;
540
+ }
541
+ | {
542
+ operation: 'insertAddon';
543
+ index: number;
544
+ fieldExtensionId: string;
545
+ parameters: Record<string, unknown>;
546
+ };
547
+
548
+ /**
549
+ * These methods can be used to update both plugin parameters and manual field
550
+ * extensions configuration.
551
+ */
552
+ export type UpdateParametersMethods = {
553
+ /**
554
+ * Updates the plugin parameters.
555
+ *
556
+ * Always check `ctx.currentRole.meta.final_permissions.can_edit_schema`
557
+ * before calling this, as the user might not have the permission to perform
558
+ * the operation.
559
+ *
560
+ * @example
561
+ *
562
+ * ```js
563
+ * await ctx.updatePluginParameters({ debugMode: true });
564
+ * await ctx.notice('Plugin parameters successfully updated!');
565
+ * ```
566
+ */
567
+ updatePluginParameters: (params: Record<string, unknown>) => Promise<void>;
568
+ /**
569
+ * Performs changes in the appearance of a field. You can install/remove a
570
+ * manual field extension, or tweak their parameters. If multiple changes are
571
+ * passed, they will be applied sequencially.
572
+ *
573
+ * Always check `ctx.currentRole.meta.final_permissions.can_edit_schema`
574
+ * before calling this, as the user might not have the permission to perform
575
+ * the operation.
576
+ *
577
+ * @example
578
+ *
579
+ * ```js
580
+ * const fields = await ctx.loadFieldsUsingPlugin();
581
+ *
582
+ * if (fields.length === 0) {
583
+ * ctx.alert('No field is using this plugin as a manual extension!');
584
+ * return;
585
+ * }
586
+ *
587
+ * for (const field of fields) {
588
+ * const { appearance } = field.attributes;
589
+ * const operations = [];
590
+ *
591
+ * if (appearance.editor === ctx.plugin.id) {
592
+ * operations.push({
593
+ * operation: 'updateEditor',
594
+ * newParameters: {
595
+ * ...appearance.parameters,
596
+ * foo: 'bar',
597
+ * },
598
+ * });
599
+ * }
600
+ *
601
+ * appearance.addons.forEach((addon, i) => {
602
+ * if (addon.id !== ctx.plugin.id) {
603
+ * return;
604
+ * }
605
+ *
606
+ * operations.push({
607
+ * operation: 'updateAddon',
608
+ * index: i,
609
+ * newParameters: { ...addon.parameters, foo: 'bar' },
610
+ * });
611
+ * });
612
+ *
613
+ * await ctx.updateFieldAppearance(field.id, operations);
614
+ * ctx.notice(`Successfully edited field ${field.attributes.api_key}`);
615
+ * }
616
+ * ```
617
+ */
618
+ updateFieldAppearance: (
619
+ fieldId: string,
620
+ changes: FieldAppearanceChange[],
621
+ ) => Promise<void>;
622
+ };
623
+
624
+ /**
625
+ * These methods can be used to asyncronously load additional information your
626
+ * plugin needs to work
627
+ */
628
+ export type LoadDataMethods = {
629
+ /**
630
+ * Loads all the fields for a specific model (or block). Fields will be
631
+ * returned and will also be available in the the `fields` property.
632
+ *
633
+ * @example
634
+ *
635
+ * ```js
636
+ * const itemTypeId = prompt('Please insert a model ID:');
637
+ *
638
+ * const fields = await ctx.loadItemTypeFields(itemTypeId);
639
+ *
640
+ * ctx.notice(
641
+ * `Success! ${fields
642
+ * .map((field) => field.attributes.api_key)
643
+ * .join(', ')}`,
644
+ * );
645
+ * ```
646
+ */
647
+ loadItemTypeFields: (itemTypeId: string) => Promise<Field[]>;
648
+ /**
649
+ * Loads all the fieldsets for a specific model (or block). Fieldsets will be
650
+ * returned and will also be available in the the `fieldsets` property.
651
+ *
652
+ * @example
653
+ *
654
+ * ```js
655
+ * const itemTypeId = prompt('Please insert a model ID:');
656
+ *
657
+ * const fieldsets = await ctx.loadItemTypeFieldsets(itemTypeId);
658
+ *
659
+ * ctx.notice(
660
+ * `Success! ${fieldsets
661
+ * .map((fieldset) => fieldset.attributes.title)
662
+ * .join(', ')}`,
663
+ * );
664
+ * ```
665
+ */
666
+ loadItemTypeFieldsets: (itemTypeId: string) => Promise<Fieldset[]>;
667
+ /**
668
+ * Loads all the fields in the project that are currently using the plugin for
669
+ * one of its manual field extensions.
670
+ *
671
+ * @example
672
+ *
673
+ * ```js
674
+ * const fields = await ctx.loadFieldsUsingPlugin();
675
+ *
676
+ * ctx.notice(
677
+ * `Success! ${fields
678
+ * .map((field) => field.attributes.api_key)
679
+ * .join(', ')}`,
680
+ * );
681
+ * ```
682
+ */
683
+ loadFieldsUsingPlugin: () => Promise<Field[]>;
684
+ /**
685
+ * Loads all regular users. Users will be returned and will also be available
686
+ * in the the `users` property.
687
+ *
688
+ * @example
689
+ *
690
+ * ```js
691
+ * const users = await ctx.loadUsers();
692
+ *
693
+ * ctx.notice(`Success! ${users.map((user) => user.id).join(', ')}`);
694
+ * ```
695
+ */
696
+ loadUsers: () => Promise<User[]>;
697
+ /**
698
+ * Loads all SSO users. Users will be returned and will also be available in
699
+ * the the `ssoUsers` property.
700
+ *
701
+ * @example
702
+ *
703
+ * ```js
704
+ * const users = await ctx.loadSsoUsers();
705
+ *
706
+ * ctx.notice(`Success! ${users.map((user) => user.id).join(', ')}`);
707
+ * ```
708
+ */
709
+ loadSsoUsers: () => Promise<SsoUser[]>;
710
+ };
711
+
712
+ /** These methods let you open the standard DatoCMS dialogs needed to interact with records */
713
+ export type ItemDialogMethods = {
714
+ /**
715
+ * Opens a dialog for creating a new record. It returns a promise resolved
716
+ * with the newly created record or `null` if the user closes the dialog
717
+ * without creating anything.
718
+ *
719
+ * @example
720
+ *
721
+ * ```js
722
+ * const itemTypeId = prompt('Please insert a model ID:');
723
+ *
724
+ * const item = await ctx.createNewItem(itemTypeId);
725
+ *
726
+ * if (item) {
727
+ * ctx.notice(`Success! ${item.id}`);
728
+ * } else {
729
+ * ctx.alert('Closed!');
730
+ * }
731
+ * ```
732
+ */
733
+ createNewItem: (itemTypeId: string) => Promise<Item | null>;
734
+ /**
735
+ * Opens a dialog for selecting one (or multiple) record(s) from a list of
736
+ * existing records of type `itemTypeId`. It returns a promise resolved with
737
+ * the selected record(s), or `null` if the user closes the dialog without
738
+ * choosing any record.
739
+ *
740
+ * @example
741
+ *
742
+ * ```js
743
+ * const itemTypeId = prompt('Please insert a model ID:');
744
+ *
745
+ * const items = await ctx.selectItem(itemTypeId, { multiple: true });
746
+ *
747
+ * if (items) {
748
+ * ctx.notice(`Success! ${items.map((i) => i.id).join(', ')}`);
749
+ * } else {
750
+ * ctx.alert('Closed!');
751
+ * }
752
+ * ```
753
+ */
754
+ selectItem: {
755
+ (itemTypeId: string, options: { multiple: true }): Promise<Item[] | null>;
756
+ (itemTypeId: string, options?: { multiple: false }): Promise<Item | null>;
757
+ };
758
+ /**
759
+ * Opens a dialog for editing an existing record. It returns a promise
760
+ * resolved with the edited record, or `null` if the user closes the dialog
761
+ * without persisting any change.
762
+ *
763
+ * @example
764
+ *
765
+ * ```js
766
+ * const itemId = prompt('Please insert a record ID:');
767
+ *
768
+ * const item = await ctx.editItem(itemId);
769
+ *
770
+ * if (item) {
771
+ * ctx.notice(`Success! ${item.id}`);
772
+ * } else {
773
+ * ctx.alert('Closed!');
774
+ * }
775
+ * ```
776
+ */
777
+ editItem: (itemId: string) => Promise<Item | null>;
778
+ };
779
+
780
+ /** These methods can be used to show UI-consistent toast notifications to the end-user */
781
+ export type ToastMethods = {
782
+ /**
783
+ * Triggers an "error" toast displaying the selected message
784
+ *
785
+ * @example
786
+ *
787
+ * ```js
788
+ * const message = prompt(
789
+ * 'Please insert a message:',
790
+ * 'This is an alert message!',
791
+ * );
792
+ *
793
+ * await ctx.alert(message);
794
+ * ```
795
+ */
796
+ alert: (message: string) => Promise<void>;
797
+ /**
798
+ * Triggers a "success" toast displaying the selected message
799
+ *
800
+ * @example
801
+ *
802
+ * ```js
803
+ * const message = prompt(
804
+ * 'Please insert a message:',
805
+ * 'This is a notice message!',
806
+ * );
807
+ *
808
+ * await ctx.notice(message);
809
+ * ```
810
+ */
811
+ notice: (message: string) => Promise<void>;
812
+ /**
813
+ * Triggers a custom toast displaying the selected message (and optionally a CTA)
814
+ *
815
+ * @example
816
+ *
817
+ * ```js
818
+ * const result = await ctx.customToast({
819
+ * type: 'warning',
820
+ * message: 'Just a sample warning notification!',
821
+ * dismissOnPageChange: true,
822
+ * dismissAfterTimeout: 5000,
823
+ * cta: {
824
+ * label: 'Execute call-to-action',
825
+ * value: 'cta',
826
+ * },
827
+ * });
828
+ *
829
+ * if (result === 'cta') {
830
+ * ctx.notice(`Clicked CTA!`);
831
+ * }
832
+ * ```
833
+ */
834
+ customToast: <CtaValue = unknown>(
835
+ toast: Toast<CtaValue>,
836
+ ) => Promise<CtaValue | null>;
837
+ };
838
+
839
+ /**
840
+ * These methods let you open the standard DatoCMS dialogs needed to interact
841
+ * with Media Area assets
842
+ */
843
+ export type UploadDialogMethods = {
844
+ /**
845
+ * Opens a dialog for selecting one (or multiple) existing asset(s). It
846
+ * returns a promise resolved with the selected asset(s), or `null` if the
847
+ * user closes the dialog without selecting any upload.
848
+ *
849
+ * @example
850
+ *
851
+ * ```js
852
+ * const item = await ctx.selectUpload({ multiple: false });
853
+ *
854
+ * if (item) {
855
+ * ctx.notice(`Success! ${item.id}`);
856
+ * } else {
857
+ * ctx.alert('Closed!');
858
+ * }
859
+ * ```
860
+ */
861
+ selectUpload: {
862
+ (options: { multiple: true }): Promise<Upload[] | null>;
863
+ (options?: { multiple: false }): Promise<Upload | null>;
864
+ };
865
+
866
+ /**
867
+ * Opens a dialog for editing a Media Area asset. It returns a promise resolved with:
868
+ *
869
+ * - The updated asset, if the user persists some changes to the asset itself
870
+ * - `null`, if the user closes the dialog without persisting any change
871
+ * - An asset structure with an additional `deleted` property set to true, if
872
+ * the user deletes the asset
873
+ *
874
+ * @example
875
+ *
876
+ * ```js
877
+ * const uploadId = prompt('Please insert an asset ID:');
878
+ *
879
+ * const item = await ctx.editUpload(uploadId);
880
+ *
881
+ * if (item) {
882
+ * ctx.notice(`Success! ${item.id}`);
883
+ * } else {
884
+ * ctx.alert('Closed!');
885
+ * }
886
+ * ```
887
+ */
888
+ editUpload: (
889
+ uploadId: string,
890
+ ) => Promise<(Upload & { deleted?: true }) | null>;
891
+ /**
892
+ * Opens a dialog for editing a "single asset" field structure. It returns a
893
+ * promise resolved with the updated structure, or `null` if the user closes
894
+ * the dialog without persisting any change.
895
+ *
896
+ * @example
897
+ *
898
+ * ```js
899
+ * const uploadId = prompt('Please insert an asset ID:');
900
+ *
901
+ * const result = await ctx.editUploadMetadata({
902
+ * upload_id: uploadId,
903
+ * alt: null,
904
+ * title: null,
905
+ * custom_data: {},
906
+ * focal_point: null,
907
+ * });
908
+ *
909
+ * if (result) {
910
+ * ctx.notice(`Success! ${JSON.stringify(result)}`);
911
+ * } else {
912
+ * ctx.alert('Closed!');
913
+ * }
914
+ * ```
915
+ */
916
+ editUploadMetadata: (
917
+ /** The "single asset" field structure */
918
+ fileFieldValue: FileFieldValue,
919
+ /** Shows metadata information for a specific locale */
920
+ locale?: string,
921
+ ) => Promise<FileFieldValue | null>;
922
+ };
923
+
924
+ /** These methods can be used to open custom dialogs/confirmation panels */
925
+ export type CustomDialogMethods = {
926
+ /**
927
+ * Opens a custom modal. Returns a promise resolved with what the modal itself
928
+ * returns calling the `resolve()` function
929
+ *
930
+ * @example
931
+ *
932
+ * ```js
933
+ * const result = await ctx.openModal({
934
+ * id: 'regular',
935
+ * title: 'Custom title!',
936
+ * width: 'l',
937
+ * parameters: { foo: 'bar' },
938
+ * });
939
+ *
940
+ * if (result) {
941
+ * ctx.notice(`Success! ${JSON.stringify(result)}`);
942
+ * } else {
943
+ * ctx.alert('Closed!');
944
+ * }
945
+ * ```
946
+ */
947
+ openModal: (modal: Modal) => Promise<unknown>;
948
+ /**
949
+ * Opens a UI-consistent confirmation dialog. Returns a promise resolved with
950
+ * the value of the choice made by the user
951
+ *
952
+ * @example
953
+ *
954
+ * ```js
955
+ * const result = await ctx.openConfirm({
956
+ * title: 'Custom title',
957
+ * content:
958
+ * 'Lorem Ipsum is simply dummy text of the printing and typesetting industry',
959
+ * choices: [
960
+ * {
961
+ * label: 'Positive',
962
+ * value: 'positive',
963
+ * intent: 'positive',
964
+ * },
965
+ * {
966
+ * label: 'Negative',
967
+ * value: 'negative',
968
+ * intent: 'negative',
969
+ * },
970
+ * ],
971
+ * cancel: {
972
+ * label: 'Cancel',
973
+ * value: false,
974
+ * },
975
+ * });
976
+ *
977
+ * if (result) {
978
+ * ctx.notice(`Success! ${result}`);
979
+ * } else {
980
+ * ctx.alert('Cancelled!');
981
+ * }
982
+ * ```
983
+ */
984
+ openConfirm: (options: ConfirmOptions) => Promise<unknown>;
985
+ };
986
+
987
+ /** These methods can be used to take the user to different pages */
988
+ export type NavigateMethods = {
989
+ /**
990
+ * Moves the user to another URL internal to the backend
991
+ *
992
+ * @example
993
+ *
994
+ * ```js
995
+ * await ctx.navigateTo('/');
996
+ * ```
997
+ */
998
+ navigateTo: (path: string) => Promise<void>;
999
+ };
1000
+
1001
+ /** These methods can be used to set various properties of the containing iframe */
1002
+ export type IframeMethods = {
1003
+ /** Sets the height for the iframe */
1004
+ setHeight: (number: number) => Promise<void>;
1005
+ };
1006
+
1007
+ export type RenderMethods = LoadDataMethods &
1008
+ UpdateParametersMethods &
1009
+ ToastMethods &
1010
+ ItemDialogMethods &
1011
+ UploadDialogMethods &
1012
+ CustomDialogMethods &
1013
+ NavigateMethods;
1014
+
1015
+ /**
1016
+ * These information describe the current state of the form that's being shown
1017
+ * to the end-user to edit a record
1018
+ */
1019
+ export type ItemFormAdditionalProperties = {
1020
+ /** The currently active locale for the record */
1021
+ locale: string;
1022
+ /** If an already persisted record is being edited, returns the full record entity */
1023
+ item: Item | null;
1024
+ /** The model for the record being edited */
1025
+ itemType: ModelBlock;
1026
+ /** The complete internal form state */
1027
+ formValues: Record<string, unknown>;
1028
+ /** The current status of the record being edited */
1029
+ itemStatus: 'new' | 'draft' | 'updated' | 'published';
1030
+ /** Whether the form is currently submitting itself or not */
1031
+ isSubmitting: boolean;
1032
+ /** Whether the form has some non-persisted changes or not */
1033
+ isFormDirty: boolean;
1034
+ };
1035
+
1036
+ export type ItemFormProperties = RenderProperties &
1037
+ ItemFormAdditionalProperties;
1038
+
1039
+ /**
1040
+ * These methods can be used to interact with the form that's being shown to the
1041
+ * end-user to edit a record
1042
+ */
1043
+ export type ItemFormAdditionalMethods = {
1044
+ /**
1045
+ * Hides/shows a specific field in the form
1046
+ *
1047
+ * @example
1048
+ *
1049
+ * ```js
1050
+ * const fieldPath = prompt(
1051
+ * 'Please insert the path of a field in the form',
1052
+ * ctx.fieldPath,
1053
+ * );
1054
+ *
1055
+ * await ctx.toggleField(fieldPath, true);
1056
+ * ```
1057
+ */
1058
+ toggleField: (path: string, show: boolean) => Promise<void>;
1059
+ /**
1060
+ * Disables/re-enables a specific field in the form
1061
+ *
1062
+ * @example
1063
+ *
1064
+ * ```js
1065
+ * const fieldPath = prompt(
1066
+ * 'Please insert the path of a field in the form',
1067
+ * ctx.fieldPath,
1068
+ * );
1069
+ *
1070
+ * await ctx.disableField(fieldPath, true);
1071
+ * ```
1072
+ */
1073
+ disableField: (path: string, disable: boolean) => Promise<void>;
1074
+ /**
1075
+ * Smoothly navigates to a specific field in the form. If the field is
1076
+ * localized it will switch language tab and then navigate to the chosen field.
1077
+ *
1078
+ * @example
1079
+ *
1080
+ * ```js
1081
+ * const fieldPath = prompt(
1082
+ * 'Please insert the path of a field in the form',
1083
+ * ctx.fieldPath,
1084
+ * );
1085
+ *
1086
+ * await ctx.scrollToField(fieldPath);
1087
+ * ```
1088
+ */
1089
+ scrollToField: (path: string, locale?: string) => Promise<void>;
1090
+ /**
1091
+ * Changes a specific path of the `formValues` object
1092
+ *
1093
+ * @example
1094
+ *
1095
+ * ```js
1096
+ * const fieldPath = prompt(
1097
+ * 'Please insert the path of a field in the form',
1098
+ * ctx.fieldPath,
1099
+ * );
1100
+ *
1101
+ * await ctx.setFieldValue(fieldPath, 'new value');
1102
+ * ```
1103
+ */
1104
+ setFieldValue: (path: string, value: unknown) => Promise<void>;
1105
+ /**
1106
+ * Triggers a submit form for current record
1107
+ *
1108
+ * @example
1109
+ *
1110
+ * ```js
1111
+ * await ctx.saveCurrentItem();
1112
+ * ```
1113
+ */
1114
+ saveCurrentItem: () => Promise<void>;
1115
+ };
1116
+
1117
+ export type ItemFormMethods = RenderMethods &
1118
+ IframeMethods &
1119
+ ItemFormAdditionalMethods;
1120
+
1121
+ /** Information regarding the specific sidebar panel that you need to render */
1122
+ export type RenderSidebarPanelAdditionalProperties = {
1123
+ mode: 'renderItemFormSidebarPanel';
1124
+ /** The ID of the sidebar panel that needs to be rendered */
1125
+ sidebarPaneId: string;
1126
+ /**
1127
+ * The arbitrary `parameters` of the panel declared in the
1128
+ * `itemFormSidebarPanels` function
1129
+ */
1130
+ parameters: Record<string, unknown>;
1131
+ };
1132
+
1133
+ export type RenderSidebarPanelProperties = ItemFormProperties &
1134
+ RenderSidebarPanelAdditionalProperties;
1135
+
1136
+ export type RenderSidebarPanelAdditionalMethods = {
1137
+ getSettings: () => Promise<RenderSidebarPanelProperties>;
1138
+ };
1139
+
1140
+ export type RenderSidebarPanelMethods = ItemFormMethods &
1141
+ RenderSidebarPanelAdditionalMethods;
1142
+
1143
+ export type RenderSidebarPanePropertiesAndMethods = RenderSidebarPanelMethods &
1144
+ RenderSidebarPanelProperties;
1145
+
1146
+ /**
1147
+ * Information regarding the state of a specific field where you need to render
1148
+ * the field extension
1149
+ */
1150
+ export type RenderFieldExtensionAdditionalProperties = {
1151
+ mode: 'renderFieldExtension';
1152
+ /** The ID of the field extension that needs to be rendered */
1153
+ fieldExtensionId: string;
1154
+ /** The arbitrary `parameters` of the field extension */
1155
+ parameters: Record<string, unknown>;
1156
+ /** The placeholder for the field */
1157
+ placeholder: string;
1158
+ /** Whether the field is currently disabled or not */
1159
+ disabled: boolean;
1160
+ /** The path in the `formValues` object where to find the current value for the field */
1161
+ fieldPath: string;
1162
+ /** The field where the field extension is installed to */
1163
+ field: Field;
1164
+ /**
1165
+ * If the field extension is installed in a field of a block, returns the top
1166
+ * level Modular Content/Structured Text field containing the block itself
1167
+ */
1168
+ parentField: Field | undefined;
1169
+ };
1170
+
1171
+ export type RenderFieldExtensionProperties = ItemFormProperties &
1172
+ RenderFieldExtensionAdditionalProperties;
1173
+
1174
+ export type RenderFieldExtensionAdditionalMethods = {
1175
+ getSettings: () => Promise<RenderFieldExtensionProperties>;
1176
+ };
1177
+
1178
+ export type RenderFieldExtensionMethods = ItemFormMethods &
1179
+ RenderFieldExtensionAdditionalMethods;
1180
+
1181
+ export type RenderFieldExtensionPropertiesAndMethods = RenderFieldExtensionMethods &
1182
+ RenderFieldExtensionProperties;
1183
+
1184
+ /** Information regarding the specific custom modal that you need to render */
1185
+ export type RenderModalAdditionalProperties = {
1186
+ mode: 'renderModal';
1187
+ /** The ID of the modal that needs to be rendered */
1188
+ modalId: string;
1189
+ /** The arbitrary `parameters` of the modal declared in the `openModal` function */
1190
+ parameters: Record<string, unknown>;
1191
+ };
1192
+
1193
+ export type RenderModalProperties = RenderProperties &
1194
+ RenderModalAdditionalProperties;
1195
+
1196
+ /** These methods can be used to close the modal */
1197
+ export type RenderModalAdditionalMethods = {
1198
+ getSettings: () => Promise<RenderModalProperties>;
1199
+ /**
1200
+ * A function to be called by the plugin to close the modal. The `openModal`
1201
+ * call will be resolved with the passed return value
1202
+ *
1203
+ * @example
1204
+ *
1205
+ * ```js
1206
+ * const returnValue = prompt(
1207
+ * 'Please specify the value to return to the caller:',
1208
+ * 'success',
1209
+ * );
1210
+ *
1211
+ * await ctx.resolve(returnValue);
1212
+ * ```
1213
+ */
1214
+ resolve: (returnValue: unknown) => Promise<void>;
1215
+ };
1216
+
1217
+ export type RenderModalMethods = RenderMethods &
1218
+ IframeMethods &
1219
+ RenderModalAdditionalMethods;
1220
+
1221
+ export type RenderModalPropertiesAndMethods = RenderModalMethods &
1222
+ RenderModalProperties;
1223
+
1224
+ /** Information regarding the specific asset source browser that you need to render */
1225
+ export type RenderAssetSourceAdditionalProperties = {
1226
+ mode: 'renderAssetSource';
1227
+ /** The ID of the assetSource that needs to be rendered */
1228
+ assetSourceId: string;
1229
+ };
1230
+
1231
+ export type RenderAssetSourceProperties = RenderProperties &
1232
+ RenderAssetSourceAdditionalProperties;
1233
+
1234
+ export type NewUploadResourceAsUrl = {
1235
+ /**
1236
+ * URL for the resource. The URL must respond with a
1237
+ * `Access-Control-Allow-Origin` header — for instance `*`, which will allow
1238
+ * all hosts — allowing the image to be read by DatoCMS
1239
+ */
1240
+ url: string;
1241
+ /**
1242
+ * Optional filename to be used to generate the final DatoCMS URL. If not
1243
+ * passed, the URL will be used
1244
+ */
1245
+ filename?: string;
1246
+ };
1247
+
1248
+ export type NewUploadResourceAsBase64 = {
1249
+ /**
1250
+ * Base64 encoded data URI for the resource.
1251
+ *
1252
+ * Format:
1253
+ *
1254
+ * `data:[<mime type>][;charset=<charset>];base64,<encoded data>`
1255
+ */
1256
+ base64: string;
1257
+ /** Filename to be used to generate the final DatoCMS URL */
1258
+ filename: string;
1259
+ };
1260
+
1261
+ export type NewUpload = {
1262
+ /** The actual resource that will be uploaded */
1263
+ resource: NewUploadResourceAsUrl | NewUploadResourceAsBase64;
1264
+ /** Copyright to apply to the asset */
1265
+ copyright?: string;
1266
+ /** Author to apply to the asset */
1267
+ author?: string;
1268
+ /** Notes to apply to the asset */
1269
+ notes?: string;
1270
+ /** Tags to apply to the asset */
1271
+ tags?: string[];
1272
+ /**
1273
+ * An hash containing, for each locale of the project, the default metadata to
1274
+ * apply to the asset
1275
+ */
1276
+ default_field_metadata?: {
1277
+ [k: string]: {
1278
+ /** Alternate text for the asset */
1279
+ alt: string | null;
1280
+ /** Title for the asset */
1281
+ title: string | null;
1282
+ /** Object with arbitrary metadata */
1283
+ custom_data: {
1284
+ [k: string]: unknown;
1285
+ };
1286
+ /** Focal point (only for image assets) */
1287
+ focal_point?: {
1288
+ /** Horizontal position expressed as float between 0 and 1 */
1289
+ x: number;
1290
+ /** Vertical position expressed as float between 0 and 1 */
1291
+ y: number;
1292
+ } | null;
1293
+ };
1294
+ };
1295
+ };
1296
+
1297
+ /** Use these methods to confirm */
1298
+ export type RenderAssetSourceAdditionalMethods = {
1299
+ getSettings: () => Promise<RenderAssetSourceProperties>;
1300
+ /**
1301
+ * Function to be called when the user selects the asset: it will trigger the
1302
+ * creation of a new `Upload` that will be added in the Media Area.
1303
+ *
1304
+ * @example
1305
+ *
1306
+ * ```js
1307
+ * await ctx.select({
1308
+ * resource: {
1309
+ * url:
1310
+ * 'https://images.unsplash.com/photo-1416339306562-f3d12fefd36f',
1311
+ * filename: 'man-drinking-coffee.jpg',
1312
+ * },
1313
+ * copyright: 'Royalty free (Unsplash)',
1314
+ * author: 'Jeff Sheldon',
1315
+ * notes: 'A man drinking a coffee',
1316
+ * tags: ['man', 'coffee'],
1317
+ * });
1318
+ * ```
1319
+ */
1320
+ select: (newUpload: NewUpload) => void;
1321
+ };
1322
+
1323
+ export type RenderAssetSourceMethods = RenderMethods &
1324
+ IframeMethods &
1325
+ RenderAssetSourceAdditionalMethods;
1326
+
1327
+ export type RenderAssetSourcePropertiesAndMethods = RenderAssetSourceMethods &
1328
+ RenderAssetSourceProperties;
1329
+
1330
+ /** Information regarding the specific page that you need to render */
1331
+ export type RenderPageAdditionalProperties = {
1332
+ mode: 'renderPage';
1333
+ /** The ID of the page that needs to be rendered */
1334
+ pageId: string;
1335
+ };
1336
+
1337
+ export type RenderPageProperties = RenderProperties &
1338
+ RenderPageAdditionalProperties;
1339
+
1340
+ export type RenderPageAdditionalMethods = {
1341
+ getSettings: () => Promise<RenderPageProperties>;
1342
+ };
1343
+
1344
+ export type RenderPageMethods = RenderMethods & RenderPageAdditionalMethods;
1345
+
1346
+ export type RenderPagePropertiesAndMethods = RenderPageMethods &
1347
+ RenderPageProperties;
1348
+
1349
+ export type PendingField = {
1350
+ id?: string;
1351
+ type: 'field';
1352
+ attributes: {
1353
+ api_key: Field['attributes']['api_key'];
1354
+ appearance: Field['attributes']['appearance'];
1355
+ default_value: Field['attributes']['default_value'];
1356
+ field_type: Field['attributes']['field_type'];
1357
+ hint: Field['attributes']['hint'];
1358
+ label: Field['attributes']['label'];
1359
+ localized: Field['attributes']['localized'];
1360
+ validators: Field['attributes']['validators'];
1361
+ };
1362
+ };
1363
+
1364
+ /**
1365
+ * Information regarding the specific form that you need to render to let the
1366
+ * end-user edit the configuration object of a field extension
1367
+ */
1368
+ export type RenderManualFieldExtensionConfigScreenAdditionalProperties = {
1369
+ mode: 'renderManualFieldExtensionConfigScreen';
1370
+ /** The ID of the field extension for which we need to render the parameters form */
1371
+ fieldExtensionId: string;
1372
+ /**
1373
+ * The current value of the parameters (you can change the value with the
1374
+ * `setParameters` function)
1375
+ */
1376
+ parameters: Record<string, unknown>;
1377
+ /**
1378
+ * The current validation errors for the parameters (you can set them
1379
+ * implementing the `validateManualFieldExtensionParameters` function)
1380
+ */
1381
+ errors: Record<string, unknown>;
1382
+
1383
+ /** The field entity that is being edited in the form */
1384
+ pendingField: PendingField;
1385
+
1386
+ /** The model for the field being edited */
1387
+ itemType: ModelBlock;
1388
+ };
1389
+
1390
+ export type RenderManualFieldExtensionConfigScreenProperties = RenderProperties &
1391
+ RenderManualFieldExtensionConfigScreenAdditionalProperties;
1392
+
1393
+ /**
1394
+ * These methods can be used to update the configuration object of a specific
1395
+ * field extension
1396
+ */
1397
+ export type RenderManualFieldExtensionConfigScreenAdditionalMethods = {
1398
+ getSettings: () => Promise<RenderManualFieldExtensionConfigScreenProperties>;
1399
+ /**
1400
+ * Sets a new value for the parameters
1401
+ *
1402
+ * @example
1403
+ *
1404
+ * ```js
1405
+ * await ctx.setParameters({ color: '#ff0000' });
1406
+ * ```
1407
+ */
1408
+ setParameters: (params: Record<string, unknown>) => Promise<void>;
1409
+ };
1410
+
1411
+ export type RenderManualFieldExtensionConfigScreenMethods = RenderMethods &
1412
+ IframeMethods &
1413
+ RenderManualFieldExtensionConfigScreenAdditionalMethods;
1414
+
1415
+ export type RenderManualFieldExtensionConfigScreenPropertiesAndMethods = RenderManualFieldExtensionConfigScreenMethods &
1416
+ RenderManualFieldExtensionConfigScreenProperties;
1417
+
1418
+ export type RenderConfigScreenAdditionalProperties = {
1419
+ mode: 'renderConfigScreen';
1420
+ };
1421
+
1422
+ export type RenderConfigScreenProperties = RenderProperties &
1423
+ RenderConfigScreenAdditionalProperties;
1424
+
1425
+ /** These methods can be used to update the configuration object of your plugin */
1426
+ export type RenderConfigScreenAdditionalMethods = {
1427
+ getSettings: () => Promise<RenderConfigScreenProperties>;
1428
+ };
1429
+
1430
+ export type RenderConfigScreenMethods = RenderMethods &
1431
+ IframeMethods &
1432
+ RenderConfigScreenAdditionalMethods;
1433
+
1434
+ export type RenderConfigScreenPropertiesAndMethods = RenderConfigScreenMethods &
1435
+ RenderConfigScreenProperties;
1436
+
1437
+ export type OnBootAdditionalProperties = {
1438
+ mode: 'onBoot';
1439
+ };
1440
+
1441
+ export type OnBootProperties = RenderProperties & OnBootAdditionalProperties;
1442
+
1443
+ export type OnBootAdditionalMethods = {
1444
+ getSettings: () => Promise<OnBootProperties>;
1445
+ };
1446
+
1447
+ export type OnBootMethods = RenderMethods & OnBootAdditionalMethods;
1448
+
1449
+ export type OnBootPropertiesAndMethods = OnBootMethods & OnBootProperties;