datocms-plugin-sdk 0.3.24 → 0.3.32

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