datocms-plugin-sdk 0.3.1 → 0.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,19 +10,15 @@ export declare type MainNavigationTab = {
10
10
  pageId: string;
11
11
  };
12
12
  /**
13
- * Expresses where you want to place the tab in the top-bar. If not specified,
14
- * the tab will be placed after the standard tabs provided by DatoCMS itself.
13
+ * Expresses where you want to place the tab in the top-bar. If not specified, the tab
14
+ * will be placed after the standard tabs provided by DatoCMS itself.
15
15
  */
16
- placement?: [
17
- 'before' | 'after',
18
- 'content' | 'mediaArea' | 'apiExplorer' | 'settings'
19
- ];
16
+ placement?: ['before' | 'after', 'content' | 'mediaArea' | 'apiExplorer' | 'settings'];
20
17
  /**
21
- * If different plugins specify the same `placement` for their tabs, they will
22
- * be displayed by ascending `rank`. If you want to specify an explicit value
23
- * for `rank`, make sure to offer a way for final users to customize it inside
24
- * the plugin's settings form, otherwise the hardcoded value you choose might
25
- * clash with the one of another plugin! *
18
+ * If different plugins specify the same `placement` for their tabs, they will be
19
+ * displayed by ascending `rank`. If you want to specify an explicit value for `rank`,
20
+ * make sure to offer a way for final users to customize it inside the plugin's settings
21
+ * form, otherwise the hardcoded value you choose might clash with the one of another plugin! *
26
22
  */
27
23
  rank?: number;
28
24
  };
@@ -38,9 +34,8 @@ export declare type SettingsAreaSidebarItem = {
38
34
  };
39
35
  };
40
36
  /**
41
- * The sidebar in the Settings Area presents a number of pages grouped by topic.
42
- * This object represents a new group to be added in the sideebar to the
43
- * standard ones DatoCMS provides.
37
+ * The sidebar in the Settings Area presents a number of pages grouped by topic. This
38
+ * object represents a new group to be added in the sideebar to the standard ones DatoCMS provides.
44
39
  */
45
40
  export declare type SettingsAreaSidebarItemGroup = {
46
41
  /** Label to be shown. Must be unique. */
@@ -48,26 +43,24 @@ export declare type SettingsAreaSidebarItemGroup = {
48
43
  /** The list of items it contains * */
49
44
  items: SettingsAreaSidebarItem[];
50
45
  /**
51
- * Expresses where you want the group to be placed inside the sidebar. If not
52
- * specified, the item will be placed after the standard items provided by
53
- * DatoCMS itself.
46
+ * Expresses where you want the group to be placed inside the sidebar. If not specified,
47
+ * the item will be placed after the standard items provided by DatoCMS itself.
54
48
  */
55
49
  placement?: [
56
50
  'before' | 'after',
57
51
  ('environment' | 'project' | 'permissions' | 'webhooks' | 'deployment' | 'sso' | 'auditLog' | 'usage')
58
52
  ];
59
53
  /**
60
- * If different plugins specify the same `placement` for their sections, they
61
- * will be displayed by ascending `rank`. If you want to specify an explicit
62
- * value for `rank`, make sure to offer a way for final users to customize it
63
- * inside the plugin's settings form, otherwise the hardcoded value you choose
64
- * might clash with the one of another plugin! *
54
+ * If different plugins specify the same `placement` for their sections, they will be
55
+ * displayed by ascending `rank`. If you want to specify an explicit value for `rank`,
56
+ * make sure to offer a way for final users to customize it inside the plugin's settings
57
+ * form, otherwise the hardcoded value you choose might clash with the one of another plugin! *
65
58
  */
66
59
  rank?: number;
67
60
  };
68
61
  /**
69
- * The sidebar in the Content Area presents a number of user-defined menu-items.
70
- * This object represents a new item to be added in the sidebar.
62
+ * The sidebar in the Content Area presents a number of user-defined menu-items. This
63
+ * object represents a new item to be added in the sidebar.
71
64
  */
72
65
  export declare type ContentAreaSidebarItem = {
73
66
  /** Label to be shown. Must be unique. */
@@ -79,44 +72,38 @@ export declare type ContentAreaSidebarItem = {
79
72
  pageId: string;
80
73
  };
81
74
  /**
82
- * Expresses where you want the item to be placed inside the sidebar. If not
83
- * specified, the item will be placed after the standard items provided by
84
- * DatoCMS itself.
75
+ * Expresses where you want the item to be placed inside the sidebar. If not specified,
76
+ * the item will be placed after the standard items provided by DatoCMS itself.
85
77
  */
86
78
  placement?: ['before' | 'after', 'menuItems' | 'settings'];
87
79
  /**
88
- * If different plugins specify the same `placement` for their panels, they
89
- * will be displayed by ascending `rank`. If you want to specify an explicit
90
- * value for `rank`, make sure to offer a way for final users to customize it
91
- * inside the plugin's settings form, otherwise the hardcoded value you choose
92
- * might clash with the one of another plugin! *
80
+ * If different plugins specify the same `placement` for their panels, they will be
81
+ * displayed by ascending `rank`. If you want to specify an explicit value for `rank`,
82
+ * make sure to offer a way for final users to customize it inside the plugin's settings
83
+ * form, otherwise the hardcoded value you choose might clash with the one of another plugin! *
93
84
  */
94
85
  rank?: number;
95
86
  };
96
87
  export declare type FieldExtensionType = 'editor' | 'addon';
97
88
  /**
98
- * Field extensions extend the basic functionality of DatoCMS when it comes to
99
- * presenting record's fields to the final user. Depending on the extension type
100
- * (`editor` or `addon`) they will be shown in different places of the interface.
89
+ * Field extensions extend the basic functionality of DatoCMS when it comes to presenting
90
+ * record's fields to the final user. Depending on the extension type (`editor` or
91
+ * `addon`) they will be shown in different places of the interface.
101
92
  */
102
93
  export declare type ManualFieldExtension = {
103
- /**
104
- * ID of field extension. Will be the first argument for the
105
- * `renderFieldExtension` function
106
- */
94
+ /** ID of field extension. Will be the first argument for the `renderFieldExtension` function */
107
95
  id: string;
108
96
  /** Name to be shown when editing fields */
109
97
  name: string;
110
98
  /**
111
- * Type of field extension. An `editor` extension replaces the default field
112
- * editor that DatoCMS provides, while an `addon` extension is placed
113
- * underneath the field editor to provide additional info/behaviour. You can
114
- * setup multiple field addons for every field.
99
+ * Type of field extension. An `editor` extension replaces the default field editor that
100
+ * DatoCMS provides, while an `addon` extension is placed underneath the field editor to
101
+ * provide additional info/behaviour. You can setup multiple field addons for every field.
115
102
  */
116
103
  type: FieldExtensionType;
117
104
  /**
118
- * For `editor` extensions: moves the field to the sidebar of the record
119
- * editing page, mimicking a sidebar panel
105
+ * For `editor` extensions: moves the field to the sidebar of the record editing page,
106
+ * mimicking a sidebar panel
120
107
  */
121
108
  asSidebarPanel?: boolean | {
122
109
  startOpen: boolean;
@@ -124,9 +111,8 @@ export declare type ManualFieldExtension = {
124
111
  /** The type of fields that the field extension in compatible with */
125
112
  fieldTypes: NonNullable<PluginAttributes['field_types']>;
126
113
  /**
127
- * Whether this field extension needs some configuration options before being
128
- * installed in a field or not. Will trigger the
129
- * `renderManualFieldExtensionConfigScreen` and
114
+ * Whether this field extension needs some configuration options before being installed
115
+ * in a field or not. Will trigger the `renderManualFieldExtensionConfigScreen` and
130
116
  * `validateManualFieldExtensionParameters` methods
131
117
  */
132
118
  configurable?: boolean | {
@@ -141,32 +127,27 @@ export declare type ItemFormSidebarPanelPlacement = [
141
127
  ];
142
128
  /** A sidebar panel to be shown inside the record's editing page */
143
129
  export declare type ItemFormSidebarPanel = {
144
- /**
145
- * ID of the panel. Will be the first argument for the
146
- * `renderItemFormSidebarPanel` function
147
- */
130
+ /** ID of the panel. Will be the first argument for the `renderItemFormSidebarPanel` function */
148
131
  id: string;
149
132
  /** Label to be shown on the collapsible sidebar panel handle */
150
133
  label: string;
151
134
  /**
152
- * An arbitrary configuration object that will be passed as the `parameters`
153
- * property of the second argument of the `renderItemFormSidebarPanel` function
135
+ * An arbitrary configuration object that will be passed as the `parameters` property of
136
+ * the second argument of the `renderItemFormSidebarPanel` function
154
137
  */
155
138
  parameters?: Record<string, unknown>;
156
139
  /** Whether the sidebar panel will start open or collapsed */
157
140
  startOpen?: boolean;
158
141
  /**
159
- * Expresses where you want the item to be placed inside the sidebar. If not
160
- * specified, the item will be placed after the standard panels provided by
161
- * DatoCMS itself.
142
+ * Expresses where you want the item to be placed inside the sidebar. If not specified,
143
+ * the item will be placed after the standard panels provided by DatoCMS itself.
162
144
  */
163
145
  placement?: ItemFormSidebarPanelPlacement;
164
146
  /**
165
- * If multiple sidebar panels specify the same `placement`, they will be
166
- * sorted by ascending `rank`. If you want to specify an explicit value for
167
- * `rank`, make sure to offer a way for final users to customize it inside the
168
- * plugin's settings form, otherwise the hardcoded value you choose might
169
- * clash with the one of another plugin! *
147
+ * If multiple sidebar panels specify the same `placement`, they will be sorted by
148
+ * ascending `rank`. If you want to specify an explicit value for `rank`, make sure to
149
+ * offer a way for final users to customize it inside the plugin's settings form,
150
+ * otherwise the hardcoded value you choose might clash with the one of another plugin! *
170
151
  */
171
152
  rank?: number;
172
153
  /** The initial height to set for the iframe that will render the sidebar panel */
@@ -174,10 +155,7 @@ export declare type ItemFormSidebarPanel = {
174
155
  };
175
156
  /** A field editor/sidebar forced on a field */
176
157
  export declare type EditorOverride = {
177
- /**
178
- * ID of field extension. Will be the first argument for the
179
- * `renderFieldExtension` function
180
- */
158
+ /** ID of field extension. Will be the first argument for the `renderFieldExtension` function */
181
159
  id: string;
182
160
  /** Moves the field to the sidebar of the record editing page, mimicking a sidebar panel */
183
161
  asSidebarPanel?: boolean | {
@@ -185,16 +163,15 @@ export declare type EditorOverride = {
185
163
  placement?: ItemFormSidebarPanelPlacement;
186
164
  };
187
165
  /**
188
- * An arbitrary configuration object that will be passed as the `parameters`
189
- * property of the second argument of the `renderFieldExtension` function
166
+ * An arbitrary configuration object that will be passed as the `parameters` property of
167
+ * the second argument of the `renderFieldExtension` function
190
168
  */
191
169
  parameters?: Record<string, unknown>;
192
170
  /**
193
- * If multiple plugins override a field, the one with the highest `rank` will
194
- * win. If you want to specify an explicit value for `rank`, make sure to
195
- * offer a way for final users to customize it inside the plugin's settings
196
- * form, otherwise the hardcoded value you choose might clash with the one of
197
- * another plugin! *
171
+ * If multiple plugins override a field, the one with the highest `rank` will win. If
172
+ * you want to specify an explicit value for `rank`, make sure to offer a way for final
173
+ * users to customize it inside the plugin's settings form, otherwise the hardcoded
174
+ * value you choose might clash with the one of another plugin! *
198
175
  */
199
176
  rank?: number;
200
177
  /** The initial height to set for the iframe that will render the field extension */
@@ -202,22 +179,18 @@ export declare type EditorOverride = {
202
179
  };
203
180
  /** A field addon extension forced on a field */
204
181
  export declare type AddonOverride = {
205
- /**
206
- * ID of field extension. Will be the first argument for the
207
- * `renderFieldExtension` function
208
- */
182
+ /** ID of field extension. Will be the first argument for the `renderFieldExtension` function */
209
183
  id: string;
210
184
  /**
211
- * An arbitrary configuration object that will be passed as the `parameters`
212
- * property of the second argument of the `renderFieldExtension` function
185
+ * An arbitrary configuration object that will be passed as the `parameters` property of
186
+ * the second argument of the `renderFieldExtension` function
213
187
  */
214
188
  parameters?: Record<string, unknown>;
215
189
  /**
216
- * If multiple addons are present for a field, they will be sorted by
217
- * ascending `rank`. If you want to specify an explicit value for `rank`, make
218
- * sure to offer a way for final users to customize it inside the plugin's
219
- * settings form, otherwise the hardcoded value you choose might clash with
220
- * the one of another plugin! *
190
+ * If multiple addons are present for a field, they will be sorted by ascending `rank`.
191
+ * If you want to specify an explicit value for `rank`, make sure to offer a way for
192
+ * final users to customize it inside the plugin's settings form, otherwise the
193
+ * hardcoded value you choose might clash with the one of another plugin! *
221
194
  */
222
195
  rank?: number;
223
196
  /** The initial height to set for the iframe that will render the field extension */
@@ -269,8 +242,8 @@ export declare type Modal = {
269
242
  /** Width of the modal. Can be a number, or one of the predefined sizes */
270
243
  width?: 's' | 'm' | 'l' | 'xl' | 'fullWidth' | number;
271
244
  /**
272
- * An arbitrary configuration object that will be passed as the `parameters`
273
- * property of the second argument of the `renderModal` function
245
+ * An arbitrary configuration object that will be passed as the `parameters` property of
246
+ * the second argument of the `renderModal` function
274
247
  */
275
248
  parameters?: Record<string, unknown>;
276
249
  /** The initial height to set for the iframe that will render the modal content */
@@ -286,17 +259,14 @@ export declare type Toast<CtaValue = unknown> = {
286
259
  cta?: {
287
260
  /** Label for the button */
288
261
  label: string;
289
- /**
290
- * The value to be returned by the `customToast` promise if the button is
291
- * clicked by the user
292
- */
262
+ /** The value to be returned by the `customToast` promise if the button is clicked by the user */
293
263
  value: CtaValue;
294
264
  };
295
265
  /** Whether the toast is to be automatically closed if the user changes page */
296
266
  dismissOnPageChange?: boolean;
297
267
  /**
298
- * Whether the toast is to be automatically closed after some time (`true`
299
- * will use the default DatoCMS time interval)
268
+ * Whether the toast is to be automatically closed after some time (`true` will use the
269
+ * default DatoCMS time interval)
300
270
  */
301
271
  dismissAfterTimeout?: boolean | number;
302
272
  };
@@ -304,10 +274,7 @@ export declare type Toast<CtaValue = unknown> = {
304
274
  export declare type ConfirmChoice = {
305
275
  /** The label to be shown for the choice */
306
276
  label: string;
307
- /**
308
- * The value to be returned by the `openConfirm` promise if the button is
309
- * clicked by the user
310
- */
277
+ /** The value to be returned by the `openConfirm` promise if the button is clicked by the user */
311
278
  value: unknown;
312
279
  /** The intent of the button. Will present the button in a different color accent. */
313
280
  intent?: 'positive' | 'negative';
@@ -332,23 +299,20 @@ export declare type CommonProperties = {
332
299
  /** All the models of the current DatoCMS project, indexed by ID */
333
300
  itemTypes: Partial<Record<string, ModelBlock>>;
334
301
  /**
335
- * The current DatoCMS user. It can either be the owner or one of the
336
- * collaborators (regular or SSO).
302
+ * The current DatoCMS user. It can either be the owner or one of the collaborators
303
+ * (regular or SSO).
337
304
  */
338
305
  currentUser: User | SsoUser | Account;
339
306
  /** The role for the current DatoCMS user */
340
307
  currentRole: Role;
341
308
  /**
342
- * The access token to perform API calls on behalf of the current user. Only
343
- * available if `currentAccessToken` permission is granted
309
+ * The access token to perform API calls on behalf of the current user. Only available
310
+ * if `currentAccessToken` permission is granted
344
311
  */
345
312
  currentAccessToken: string | undefined;
346
313
  /** The current plugin */
347
314
  plugin: Plugin;
348
- /**
349
- * UI preferences of the current user (right now, only the preferred locale is
350
- * available)
351
- */
315
+ /** UI preferences of the current user (right now, only the preferred locale is available) */
352
316
  ui: {
353
317
  /** Preferred locale */
354
318
  locale: string;
@@ -365,25 +329,24 @@ export declare type InitPropertiesAndMethods = InitMethods & InitProperties;
365
329
  /** Additional properties available in all `renderXXX` hooks */
366
330
  export declare type RenderAdditionalProperties = {
367
331
  /**
368
- * All the fields currently loaded for the current DatoCMS project, indexed by
369
- * ID. It will always contain the current model fields and all the fields of
370
- * the blocks it might contain via Modular Content/Structured Text fields. If
371
- * some fields you need are not present, use the `loadItemTypeFields` function
372
- * to load them.
332
+ * All the fields currently loaded for the current DatoCMS project, indexed by ID. It
333
+ * will always contain the current model fields and all the fields of the blocks it
334
+ * might contain via Modular Content/Structured Text fields. If some fields you need are
335
+ * not present, use the `loadItemTypeFields` function to load them.
373
336
  */
374
337
  fields: Partial<Record<string, Field>>;
375
338
  /** An object containing the theme colors for the current DatoCMS project */
376
339
  theme: Theme;
377
340
  /**
378
- * All the regular users currently loaded for the current DatoCMS project,
379
- * indexed by ID. It will always contain the current user. If some users you
380
- * need are not present, use the `loadUsers` function to load them.
341
+ * All the regular users currently loaded for the current DatoCMS project, indexed by
342
+ * ID. It will always contain the current user. If some users you need are not present,
343
+ * use the `loadUsers` function to load them.
381
344
  */
382
345
  users: Partial<Record<string, User>>;
383
346
  /**
384
- * All the SSO users currently loaded for the current DatoCMS project, indexed
385
- * by ID. It will always contain the current user. If some users you need are
386
- * not present, use the `loadSsoUsers` function to load them.
347
+ * All the SSO users currently loaded for the current DatoCMS project, indexed by ID. It
348
+ * will always contain the current user. If some users you need are not present, use the
349
+ * `loadSsoUsers` function to load them.
387
350
  */
388
351
  ssoUsers: Partial<Record<string, SsoUser>>;
389
352
  /** The project owner */
@@ -397,7 +360,7 @@ export declare type FieldAppearanceChange = {
397
360
  } | {
398
361
  operation: 'updateEditor';
399
362
  newFieldExtensionId?: string;
400
- newFieldExtensionParameters?: Record<string, unknown>;
363
+ newParameters?: Record<string, unknown>;
401
364
  } | {
402
365
  operation: 'setEditor';
403
366
  fieldExtensionId: string;
@@ -417,120 +380,146 @@ export declare type FieldAppearanceChange = {
417
380
  parameters: Record<string, unknown>;
418
381
  };
419
382
  /**
420
- * These methods can be used to update both plugin parameters and manual field
421
- * extensions configuration.
383
+ * These methods can be used to update both plugin parameters and manual field extensions
384
+ * configuration.
422
385
  */
423
386
  export declare type UpdateParametersMethods = {
424
387
  /**
425
388
  * Updates the plugin parameters.
426
389
  *
427
- * Always check `ctx.currentRole.meta.final_permissions.can_edit_schema`
428
- * before calling this, as the user might not have the permission to perform
429
- * the operation.
390
+ * Always check `ctx.currentRole.meta.final_permissions.can_edit_schema` before calling
391
+ * this, as the user might not have the permission to perform the operation.
430
392
  *
431
393
  * @example
432
- * ctx.updatePluginParameters({ debugMode: true });
394
+ * await ctx.updatePluginParameters({ debugMode: true });
395
+ * await ctx.notice('Plugin parameters successfully updated!');
433
396
  */
434
397
  updatePluginParameters: (params: Record<string, unknown>) => Promise<void>;
435
398
  /**
436
- * Performs changes in the appearance of a field. You can install/remove a
437
- * manual field extension, or tweak their parameters. If multiple changes are
438
- * passed, they will be applied sequencially.
399
+ * Performs changes in the appearance of a field. You can install/remove a manual field
400
+ * extension, or tweak their parameters. If multiple changes are passed, they will be
401
+ * applied sequencially.
439
402
  *
440
- * Always check `ctx.currentRole.meta.final_permissions.can_edit_schema`
441
- * before calling this, as the user might not have the permission to perform
442
- * the operation.
403
+ * Always check `ctx.currentRole.meta.final_permissions.can_edit_schema` before calling
404
+ * this, as the user might not have the permission to perform the operation.
443
405
  *
444
406
  * @example
445
- * const fieldId = 234;
446
- * ctx.updateFieldAppearance(234, [
447
- * {
448
- * operation: 'updateEditor',
449
- * newFieldExtensionParameters: { foo: 'bar' },
450
- * },
451
- * {
452
- * operation: 'updateAddon',
453
- * index: 2,
454
- * newFieldExtensionParameters: { bar: 'qux' },
455
- * },
456
- * ]);
407
+ * const fields = await ctx.loadFieldsUsingPlugin();
408
+ *
409
+ * if (fields.length === 0) {
410
+ * ctx.alert('No field is using this plugin as a manual extension!');
411
+ * return;
412
+ * }
413
+ *
414
+ * for (const field of fields) {
415
+ * const { appearance } = field.attributes;
416
+ * const operations = [];
417
+ *
418
+ * if (appearance.editor === ctx.plugin.id) {
419
+ * operations.push({
420
+ * operation: 'updateEditor',
421
+ * newParameters: {
422
+ * ...appearance.parameters,
423
+ * foo: 'bar',
424
+ * },
425
+ * });
426
+ * }
427
+ *
428
+ * appearance.addons.forEach((addon, i) => {
429
+ * if (addon.id !== ctx.plugin.id) {
430
+ * return;
431
+ * }
432
+ *
433
+ * operations.push({
434
+ * operation: 'updateAddon',
435
+ * index: i,
436
+ * newParameters: { ...addon.parameters, foo: 'bar' },
437
+ * });
438
+ * });
439
+ *
440
+ * await ctx.updateFieldAppearance(field.id, operations);
441
+ * ctx.notice(`Successfully edited field ${field.attributes.api_key}`);
442
+ * }
457
443
  */
458
444
  updateFieldAppearance: (fieldId: string, changes: FieldAppearanceChange[]) => Promise<void>;
459
445
  };
460
- /**
461
- * These methods can be used to asyncronously load additional information your
462
- * plugin needs to work
463
- */
446
+ /** These methods can be used to asyncronously load additional information your plugin needs to work */
464
447
  export declare type LoadDataMethods = {
465
448
  /**
466
- * Loads all the fields for a specific model (or block). Fields will be
467
- * returned and will also be available in the the `fields` property.
449
+ * Loads all the fields for a specific model (or block). Fields will be returned and
450
+ * will also be available in the the `fields` property.
468
451
  *
469
452
  * @example
470
- * const fields = await sdk.loadItemTypeFields('810907');
471
- * sdk.notice(
472
- * `Success! ${fields
473
- * .map((field) => field.attributes.api_key)
474
- * .join(', ')}`,
453
+ * const itemTypeId = prompt('Please insert a model ID:');
454
+ *
455
+ * const fields = await ctx.loadItemTypeFields(itemTypeId);
456
+ *
457
+ * ctx.notice(
458
+ * `Success! ${fields.map((field) => field.attributes.api_key).join(', ')}`,
475
459
  * );
476
460
  */
477
461
  loadItemTypeFields: (itemTypeId: string) => Promise<Field[]>;
478
462
  /**
479
- * Loads all the fields in the project that are currently using the plugin for
480
- * one of its manual field extensions.
463
+ * Loads all the fields in the project that are currently using the plugin for one of
464
+ * its manual field extensions.
481
465
  *
482
466
  * @example
483
- * const fields = await sdk.loadFieldsUsingPlugin();
484
- * sdk.notice(
485
- * `Success! ${fields
486
- * .map((field) => field.attributes.api_key)
487
- * .join(', ')}`,
467
+ * const fields = await ctx.loadFieldsUsingPlugin();
468
+ *
469
+ * ctx.notice(
470
+ * `Success! ${fields.map((field) => field.attributes.api_key).join(', ')}`,
488
471
  * );
489
472
  */
490
473
  loadFieldsUsingPlugin: () => Promise<Field[]>;
491
474
  /**
492
- * Loads all regular users. Users will be returned and will also be available
493
- * in the the `users` property.
475
+ * Loads all regular users. Users will be returned and will also be available in the the
476
+ * `users` property.
494
477
  *
495
478
  * @example
496
- * const users = await sdk.loadUsers();
497
- * sdk.notice(`Success! ${users.map((user) => i.id).join(', ')}`);
479
+ * const users = await ctx.loadUsers();
480
+ *
481
+ * ctx.notice(`Success! ${users.map((user) => user.id).join(', ')}`);
498
482
  */
499
483
  loadUsers: () => Promise<User[]>;
500
484
  /**
501
- * Loads all SSO users. Users will be returned and will also be available in
502
- * the the `ssoUsers` property.
485
+ * Loads all SSO users. Users will be returned and will also be available in the the
486
+ * `ssoUsers` property.
503
487
  *
504
488
  * @example
505
- * const users = await sdk.loadSsoUsers();
506
- * sdk.notice(`Success! ${users.map((user) => i.id).join(', ')}`);
489
+ * const users = await ctx.loadSsoUsers();
490
+ *
491
+ * ctx.notice(`Success! ${users.map((user) => user.id).join(', ')}`);
507
492
  */
508
493
  loadSsoUsers: () => Promise<SsoUser[]>;
509
494
  };
510
495
  /** These methods let you open the standard DatoCMS dialogs needed to interact with records */
511
496
  export declare type ItemDialogMethods = {
512
497
  /**
513
- * Opens a dialog for creating a new record. It returns a promise resolved
514
- * with the newly created record or `null` if the user closes the dialog
515
- * without creating anything.
498
+ * Opens a dialog for creating a new record. It returns a promise resolved with the
499
+ * newly created record or `null` if the user closes the dialog without creating anything.
516
500
  *
517
501
  * @example
518
- * const item = await sdk.createNewItem('810907');
502
+ * const itemTypeId = prompt('Please insert a model ID:');
503
+ *
504
+ * const item = await ctx.createNewItem(itemTypeId);
505
+ *
519
506
  * if (item) {
520
- * sdk.notice(`Success! ${item.id}`);
507
+ * ctx.notice(`Success! ${item.id}`);
521
508
  * } else {
522
- * sdk.alert('Closed!');
509
+ * ctx.alert('Closed!');
523
510
  * }
524
511
  */
525
512
  createNewItem: (itemTypeId: string) => Promise<Item | null>;
526
513
  /**
527
- * Opens a dialog for selecting one (or multiple) record(s) from a list of
528
- * existing records of type `itemTypeId`. It returns a promise resolved with
529
- * the selected record(s), or `null` if the user closes the dialog without
530
- * choosing any record.
514
+ * Opens a dialog for selecting one (or multiple) record(s) from a list of existing
515
+ * records of type `itemTypeId`. It returns a promise resolved with the selected
516
+ * record(s), or `null` if the user closes the dialog without choosing any record.
531
517
  *
532
518
  * @example
533
- * const items = await ctx.selectItem('810907', { multiple: true });
519
+ * const itemTypeId = prompt('Please insert a model ID:');
520
+ *
521
+ * const items = await ctx.selectItem(itemTypeId, { multiple: true });
522
+ *
534
523
  * if (items) {
535
524
  * ctx.notice(`Success! ${items.map((i) => i.id).join(', ')}`);
536
525
  * } else {
@@ -546,17 +535,18 @@ export declare type ItemDialogMethods = {
546
535
  }): Promise<Item | null>;
547
536
  };
548
537
  /**
549
- * Opens a dialog for editing an existing record. It returns a promise
550
- * resolved with the edited record, or `null` if the user closes the dialog
551
- * without persisting any change.
538
+ * Opens a dialog for editing an existing record. It returns a promise resolved with the
539
+ * edited record, or `null` if the user closes the dialog without persisting any change.
552
540
  *
553
541
  * @example
554
- * const item = await sdk.editItem('50479504');
542
+ * const itemId = prompt('Please insert a record ID:');
543
+ *
544
+ * const item = await ctx.editItem(itemId);
555
545
  *
556
546
  * if (item) {
557
- * sdk.notice(`Success! ${item.id}`);
547
+ * ctx.notice(`Success! ${item.id}`);
558
548
  * } else {
559
- * sdk.alert('Closed!');
549
+ * ctx.alert('Closed!');
560
550
  * }
561
551
  */
562
552
  editItem: (itemId: string) => Promise<Item | null>;
@@ -567,25 +557,29 @@ export declare type ToastMethods = {
567
557
  * Triggers an "error" toast displaying the selected message
568
558
  *
569
559
  * @example
570
- * sdk.alert('Alert!');
560
+ * const message = prompt('Please insert a message:', 'This is an alert message!');
561
+ *
562
+ * await ctx.alert(message);
571
563
  */
572
- alert: (message: string) => void;
564
+ alert: (message: string) => Promise<void>;
573
565
  /**
574
566
  * Triggers a "success" toast displaying the selected message
575
567
  *
576
568
  * @example
577
- * sdk.notice('Notice!');
569
+ * const message = prompt('Please insert a message:', 'This is a notice message!');
570
+ *
571
+ * await ctx.notice(message);
578
572
  */
579
- notice: (message: string) => void;
573
+ notice: (message: string) => Promise<void>;
580
574
  /**
581
575
  * Triggers a custom toast displaying the selected message (and optionally a CTA)
582
576
  *
583
577
  * @example
584
- * const result = await sdk.customToast({
578
+ * const result = await ctx.customToast({
585
579
  * type: 'warning',
586
580
  * message: 'Just a sample warning notification!',
587
581
  * dismissOnPageChange: true,
588
- * dismissAfterTimeout: 22000,
582
+ * dismissAfterTimeout: 5000,
589
583
  * cta: {
590
584
  * label: 'Execute call-to-action',
591
585
  * value: 'cta',
@@ -593,28 +587,25 @@ export declare type ToastMethods = {
593
587
  * });
594
588
  *
595
589
  * if (result === 'cta') {
596
- * sdk.notice(`Clicked CTA!`);
590
+ * ctx.notice(`Clicked CTA!`);
597
591
  * }
598
592
  */
599
593
  customToast: <CtaValue = unknown>(toast: Toast<CtaValue>) => Promise<CtaValue | null>;
600
594
  };
601
- /**
602
- * These methods let you open the standard DatoCMS dialogs needed to interact
603
- * with Media Area assets
604
- */
595
+ /** These methods let you open the standard DatoCMS dialogs needed to interact with Media Area assets */
605
596
  export declare type UploadDialogMethods = {
606
597
  /**
607
- * Opens a dialog for selecting one (or multiple) existing asset(s). It
608
- * returns a promise resolved with the selected asset(s), or `null` if the
609
- * user closes the dialog without selecting any upload.
598
+ * Opens a dialog for selecting one (or multiple) existing asset(s). It returns a
599
+ * promise resolved with the selected asset(s), or `null` if the user closes the dialog
600
+ * without selecting any upload.
610
601
  *
611
602
  * @example
612
- * const item = await sdk.selectUpload({ multiple: false });
603
+ * const item = await ctx.selectUpload({ multiple: false });
613
604
  *
614
605
  * if (item) {
615
- * sdk.notice(`Success! ${item.id}`);
606
+ * ctx.notice(`Success! ${item.id}`);
616
607
  * } else {
617
- * sdk.alert('Closed!');
608
+ * ctx.alert('Closed!');
618
609
  * }
619
610
  */
620
611
  selectUpload: {
@@ -630,29 +621,33 @@ export declare type UploadDialogMethods = {
630
621
  *
631
622
  * - The updated asset, if the user persists some changes to the asset itself
632
623
  * - `null`, if the user closes the dialog without persisting any change
633
- * - An asset structure with an additional `deleted` property set to true, if
634
- * the user deletes the asset
624
+ * - An asset structure with an additional `deleted` property set to true, if the user
625
+ * deletes the asset
635
626
  *
636
627
  * @example
637
- * const item = await sdk.editUpload('21717537');
628
+ * const uploadId = prompt('Please insert an asset ID:');
629
+ *
630
+ * const item = await ctx.editUpload(uploadId);
638
631
  *
639
632
  * if (item) {
640
- * sdk.notice(`Success! ${item.id}`);
633
+ * ctx.notice(`Success! ${item.id}`);
641
634
  * } else {
642
- * sdk.alert('Closed!');
635
+ * ctx.alert('Closed!');
643
636
  * }
644
637
  */
645
638
  editUpload: (uploadId: string) => Promise<(Upload & {
646
639
  deleted?: true;
647
640
  }) | null>;
648
641
  /**
649
- * Opens a dialog for editing a "single asset" field structure. It returns a
650
- * promise resolved with the updated structure, or `null` if the user closes
651
- * the dialog without persisting any change.
642
+ * Opens a dialog for editing a "single asset" field structure. It returns a promise
643
+ * resolved with the updated structure, or `null` if the user closes the dialog without
644
+ * persisting any change.
652
645
  *
653
646
  * @example
654
- * const result = await sdk.editUploadMetadata({
655
- * upload_id: '21717537',
647
+ * const uploadId = prompt('Please insert an asset ID:');
648
+ *
649
+ * const result = await ctx.editUploadMetadata({
650
+ * upload_id: uploadId,
656
651
  * alt: null,
657
652
  * title: null,
658
653
  * custom_data: {},
@@ -660,9 +655,9 @@ export declare type UploadDialogMethods = {
660
655
  * });
661
656
  *
662
657
  * if (result) {
663
- * sdk.notice(`Success! ${JSON.stringify(result)}`);
658
+ * ctx.notice(`Success! ${JSON.stringify(result)}`);
664
659
  * } else {
665
- * sdk.alert('Closed!');
660
+ * ctx.alert('Closed!');
666
661
  * }
667
662
  */
668
663
  editUploadMetadata: (
@@ -674,29 +669,30 @@ export declare type UploadDialogMethods = {
674
669
  /** These methods can be used to open custom dialogs/confirmation panels */
675
670
  export declare type CustomDialogMethods = {
676
671
  /**
677
- * Opens a custom modal. Returns a promise resolved with what the modal itself
678
- * returns calling the `resolve()` function
672
+ * Opens a custom modal. Returns a promise resolved with what the modal itself returns
673
+ * calling the `resolve()` function
679
674
  *
680
675
  * @example
681
- * const result = await sdk.openModal({
676
+ * const result = await ctx.openModal({
682
677
  * id: 'regular',
683
678
  * title: 'Custom title!',
684
679
  * width: 'l',
685
680
  * parameters: { foo: 'bar' },
686
681
  * });
682
+ *
687
683
  * if (result) {
688
- * sdk.notice(`Success! ${JSON.stringify(result)}`);
684
+ * ctx.notice(`Success! ${JSON.stringify(result)}`);
689
685
  * } else {
690
- * sdk.alert('Closed!');
686
+ * ctx.alert('Closed!');
691
687
  * }
692
688
  */
693
689
  openModal: (modal: Modal) => Promise<unknown>;
694
690
  /**
695
- * Opens a UI-consistent confirmation dialog. Returns a promise resolved with
696
- * the value of the choice made by the user
691
+ * Opens a UI-consistent confirmation dialog. Returns a promise resolved with the value
692
+ * of the choice made by the user
697
693
  *
698
694
  * @example
699
- * const result = await sdk.openConfirm({
695
+ * const result = await ctx.openConfirm({
700
696
  * title: 'Custom title',
701
697
  * content:
702
698
  * 'Lorem Ipsum is simply dummy text of the printing and typesetting industry',
@@ -717,10 +713,11 @@ export declare type CustomDialogMethods = {
717
713
  * value: false,
718
714
  * },
719
715
  * });
716
+ *
720
717
  * if (result) {
721
- * sdk.notice(`Success! ${result}`);
718
+ * ctx.notice(`Success! ${result}`);
722
719
  * } else {
723
- * sdk.alert('Cancelled!');
720
+ * ctx.alert('Cancelled!');
724
721
  * }
725
722
  */
726
723
  openConfirm: (options: ConfirmOptions) => Promise<unknown>;
@@ -731,19 +728,19 @@ export declare type NavigateMethods = {
731
728
  * Moves the user to another URL internal to the backend
732
729
  *
733
730
  * @example
734
- * sdk.navigateTo('/');
731
+ * await ctx.navigateTo('/');
735
732
  */
736
- navigateTo: (path: string) => void;
733
+ navigateTo: (path: string) => Promise<void>;
737
734
  };
738
735
  /** These methods can be used to set various properties of the containing iframe */
739
736
  export declare type IframeMethods = {
740
737
  /** Sets the height for the iframe */
741
- setHeight: (number: number) => void;
738
+ setHeight: (number: number) => Promise<void>;
742
739
  };
743
740
  export declare type RenderMethods = LoadDataMethods & UpdateParametersMethods & ToastMethods & CustomDialogMethods & NavigateMethods;
744
741
  /**
745
- * These information describe the current state of the form that's being shown
746
- * to the end-user to edit a record
742
+ * These information describe the current state of the form that's being shown to the
743
+ * end-user to edit a record
747
744
  */
748
745
  export declare type ItemFormAdditionalProperties = {
749
746
  /** The currently active locale for the record */
@@ -763,44 +760,64 @@ export declare type ItemFormAdditionalProperties = {
763
760
  };
764
761
  export declare type ItemFormProperties = RenderProperties & ItemFormAdditionalProperties;
765
762
  /**
766
- * These methods can be used to interact with the form that's being shown to the
767
- * end-user to edit a record
763
+ * These methods can be used to interact with the form that's being shown to the end-user
764
+ * to edit a record
768
765
  */
769
766
  export declare type ItemFormAdditionalMethods = {
770
767
  /**
771
768
  * Hides/shows a specific field in the form
772
769
  *
773
770
  * @example
774
- * sdk.toggleField(sdk.fieldPath, true);
771
+ * const fieldPath = prompt(
772
+ * 'Please insert the path of a field in the form',
773
+ * ctx.fieldPath,
774
+ * );
775
+ *
776
+ * await ctx.toggleField(fieldPath, true);
775
777
  */
776
- toggleField: (path: string, show: boolean) => void;
778
+ toggleField: (path: string, show: boolean) => Promise<void>;
777
779
  /**
778
780
  * Disables/re-enables a specific field in the form
779
781
  *
780
782
  * @example
781
- * sdk.disableField(sdk.fieldPath, true);
783
+ * const fieldPath = prompt(
784
+ * 'Please insert the path of a field in the form',
785
+ * ctx.fieldPath,
786
+ * );
787
+ *
788
+ * await ctx.disableField(fieldPath, true);
782
789
  */
783
- disableField: (path: string, disable: boolean) => void;
790
+ disableField: (path: string, disable: boolean) => Promise<void>;
784
791
  /**
785
- * Smoothly navigates to a specific field in the form. If the field is
786
- * localized it will switch language tab and then navigate to the chosen field.
792
+ * Smoothly navigates to a specific field in the form. If the field is localized it will
793
+ * switch language tab and then navigate to the chosen field.
787
794
  *
788
795
  * @example
789
- * sdk.scrollToField(sdk.fieldPath);
796
+ * const fieldPath = prompt(
797
+ * 'Please insert the path of a field in the form',
798
+ * ctx.fieldPath,
799
+ * );
800
+ *
801
+ * await ctx.scrollToField(fieldPath);
790
802
  */
791
- scrollToField: (path: string, locale?: string) => void;
803
+ scrollToField: (path: string, locale?: string) => Promise<void>;
792
804
  /**
793
805
  * Changes a specific path of the `formValues` object
794
806
  *
795
807
  * @example
796
- * sdk.setFieldValue(sdk.fieldPath, 'new value');
808
+ * const fieldPath = prompt(
809
+ * 'Please insert the path of a field in the form',
810
+ * ctx.fieldPath,
811
+ * );
812
+ *
813
+ * await ctx.setFieldValue(fieldPath, 'new value');
797
814
  */
798
- setFieldValue: (path: string, value: unknown) => void;
815
+ setFieldValue: (path: string, value: unknown) => Promise<void>;
799
816
  /**
800
817
  * Triggers a submit form for current record
801
818
  *
802
819
  * @example
803
- * await sdk.saveCurrentItem();
820
+ * await ctx.saveCurrentItem();
804
821
  */
805
822
  saveCurrentItem: () => Promise<void>;
806
823
  };
@@ -810,10 +827,7 @@ export declare type RenderSidebarPanelAdditionalProperties = {
810
827
  mode: 'renderItemFormSidebarPanel';
811
828
  /** The ID of the sidebar panel that needs to be rendered */
812
829
  sidebarPaneId: string;
813
- /**
814
- * The arbitrary `parameters` of the panel declared in the
815
- * `itemFormSidebarPanels` function
816
- */
830
+ /** The arbitrary `parameters` of the panel declared in the `itemFormSidebarPanels` function */
817
831
  parameters: Record<string, unknown>;
818
832
  };
819
833
  export declare type RenderSidebarPanelProperties = ItemFormProperties & RenderSidebarPanelAdditionalProperties;
@@ -822,10 +836,7 @@ export declare type RenderSidebarPanelAdditionalMethods = {
822
836
  };
823
837
  export declare type RenderSidebarPanelMethods = ItemFormMethods & RenderSidebarPanelAdditionalMethods;
824
838
  export declare type RenderSidebarPanePropertiesAndMethods = RenderSidebarPanelMethods & RenderSidebarPanelProperties;
825
- /**
826
- * Information regarding the state of a specific field where you need to render
827
- * the field extension
828
- */
839
+ /** Information regarding the state of a specific field where you need to render the field extension */
829
840
  export declare type RenderFieldExtensionAdditionalProperties = {
830
841
  mode: 'renderFieldExtension';
831
842
  /** The ID of the field extension that needs to be rendered */
@@ -841,8 +852,8 @@ export declare type RenderFieldExtensionAdditionalProperties = {
841
852
  /** The field where the field extension is installed to */
842
853
  field: Field;
843
854
  /**
844
- * If the field extension is installed in a field of a block, returns the top
845
- * level Modular Content/Structured Text field containing the block itself
855
+ * If the field extension is installed in a field of a block, returns the top level
856
+ * Modular Content/Structured Text field containing the block itself
846
857
  */
847
858
  parentField: Field | undefined;
848
859
  };
@@ -865,10 +876,18 @@ export declare type RenderModalProperties = RenderProperties & RenderModalAdditi
865
876
  export declare type RenderModalAdditionalMethods = {
866
877
  getSettings: () => Promise<RenderModalProperties>;
867
878
  /**
868
- * A function to be called by the plugin to close the modal. The `openModal`
869
- * call will be resolved with the passed return value
879
+ * A function to be called by the plugin to close the modal. The `openModal` call will
880
+ * be resolved with the passed return value
881
+ *
882
+ * @example
883
+ * const returnValue = prompt(
884
+ * 'Please specify the value to return to the caller:',
885
+ * 'success',
886
+ * );
887
+ *
888
+ * await ctx.resolve(returnValue);
870
889
  */
871
- resolve: (returnValue: unknown) => void;
890
+ resolve: (returnValue: unknown) => Promise<void>;
872
891
  };
873
892
  export declare type RenderModalMethods = RenderMethods & IframeMethods & RenderModalAdditionalMethods;
874
893
  export declare type RenderModalPropertiesAndMethods = RenderModalMethods & RenderModalProperties;
@@ -885,8 +904,8 @@ export declare type RenderPageAdditionalMethods = {
885
904
  export declare type RenderPageMethods = RenderMethods & RenderPageAdditionalMethods;
886
905
  export declare type RenderPagePropertiesAndMethods = RenderPageMethods & RenderPageProperties;
887
906
  /**
888
- * Information regarding the specific form that you need to render to let the
889
- * end-user edit the configuration object of a field extension
907
+ * Information regarding the specific form that you need to render to let the end-user
908
+ * edit the configuration object of a field extension
890
909
  */
891
910
  export declare type RenderManualFieldExtensionConfigScreenAdditionalProperties = {
892
911
  mode: 'renderManualFieldExtensionConfigScreen';
@@ -898,23 +917,20 @@ export declare type RenderManualFieldExtensionConfigScreenAdditionalProperties =
898
917
  */
899
918
  parameters: Record<string, unknown>;
900
919
  /**
901
- * The current validation errors for the parameters (you can set them
902
- * implementing the `validateManualFieldExtensionParameters` function)
920
+ * The current validation errors for the parameters (you can set them implementing the
921
+ * `validateManualFieldExtensionParameters` function)
903
922
  */
904
923
  errors: Record<string, unknown>;
905
924
  };
906
925
  export declare type RenderManualFieldExtensionConfigScreenProperties = RenderProperties & RenderManualFieldExtensionConfigScreenAdditionalProperties;
907
- /**
908
- * These methods can be used to update the configuration object of a specific
909
- * field extension
910
- */
926
+ /** These methods can be used to update the configuration object of a specific field extension */
911
927
  export declare type RenderManualFieldExtensionConfigScreenAdditionalMethods = {
912
928
  getSettings: () => Promise<RenderManualFieldExtensionConfigScreenProperties>;
913
929
  /**
914
930
  * Sets a new value for the parameters
915
931
  *
916
932
  * @example
917
- * ctx.setParameters({ color: '#ff0000' });
933
+ * await ctx.setParameters({ color: '#ff0000' });
918
934
  */
919
935
  setParameters: (params: Record<string, unknown>) => Promise<void>;
920
936
  };