datocms-plugin-sdk 0.2.0-alpha.65 → 0.3.2

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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # `datocms-plugin-sdk`
2
2
 
3
- A set of Typescript types and helpers to work with DatoCMS Structured Text fields.
3
+ Typescript SDK to build DatoCMS plugins. You can read all about the SDK in [our documentation](https://www.datocms.com/docs/plugin-sdk).
4
4
 
5
5
  ## Installation
6
6
 
@@ -396,11 +396,11 @@ export declare type FieldAppearanceChange = {
396
396
  operation: 'removeEditor';
397
397
  } | {
398
398
  operation: 'updateEditor';
399
- newFieldExtensionId?: 'string';
399
+ newFieldExtensionId?: string;
400
400
  newFieldExtensionParameters?: Record<string, unknown>;
401
401
  } | {
402
402
  operation: 'setEditor';
403
- fieldExtensionId: 'string';
403
+ fieldExtensionId: string;
404
404
  parameters: Record<string, unknown>;
405
405
  } | {
406
406
  operation: 'removeAddon';
@@ -408,14 +408,18 @@ export declare type FieldAppearanceChange = {
408
408
  } | {
409
409
  operation: 'updateAddon';
410
410
  index: number;
411
- newFieldExtensionId?: 'string';
411
+ newFieldExtensionId?: string;
412
412
  newParameters?: Record<string, unknown>;
413
413
  } | {
414
414
  operation: 'insertAddon';
415
415
  index: number;
416
- fieldExtensionId: 'string';
416
+ fieldExtensionId: string;
417
417
  parameters: Record<string, unknown>;
418
418
  };
419
+ /**
420
+ * These methods can be used to update both plugin parameters and manual field
421
+ * extensions configuration.
422
+ */
419
423
  export declare type UpdateParametersMethods = {
420
424
  /**
421
425
  * Updates the plugin parameters.
@@ -438,8 +442,9 @@ export declare type UpdateParametersMethods = {
438
442
  * the operation.
439
443
  *
440
444
  * @example
441
- * const fieldId = 234;
442
- * ctx.updateFieldAppearance(234, [
445
+ * const fieldId = prompt('Please insert a field ID:');
446
+ *
447
+ * ctx.updateFieldAppearance(fieldId, [
443
448
  * {
444
449
  * operation: 'updateEditor',
445
450
  * newFieldExtensionParameters: { foo: 'bar' },
@@ -463,8 +468,11 @@ export declare type LoadDataMethods = {
463
468
  * returned and will also be available in the the `fields` property.
464
469
  *
465
470
  * @example
466
- * const fields = await sdk.loadItemTypeFields('810907');
467
- * sdk.notice(
471
+ * const fieldId = prompt('Please insert a field ID:');
472
+ *
473
+ * const fields = await ctx.loadItemTypeFields(fieldId);
474
+ *
475
+ * ctx.notice(
468
476
  * `Success! ${fields
469
477
  * .map((field) => field.attributes.api_key)
470
478
  * .join(', ')}`,
@@ -476,8 +484,9 @@ export declare type LoadDataMethods = {
476
484
  * one of its manual field extensions.
477
485
  *
478
486
  * @example
479
- * const fields = await sdk.loadFieldsUsingPlugin();
480
- * sdk.notice(
487
+ * const fields = await ctx.loadFieldsUsingPlugin();
488
+ *
489
+ * ctx.notice(
481
490
  * `Success! ${fields
482
491
  * .map((field) => field.attributes.api_key)
483
492
  * .join(', ')}`,
@@ -489,8 +498,9 @@ export declare type LoadDataMethods = {
489
498
  * in the the `users` property.
490
499
  *
491
500
  * @example
492
- * const users = await sdk.loadUsers();
493
- * sdk.notice(`Success! ${users.map((user) => i.id).join(', ')}`);
501
+ * const users = await ctx.loadUsers();
502
+ *
503
+ * ctx.notice(`Success! ${users.map((user) => i.id).join(', ')}`);
494
504
  */
495
505
  loadUsers: () => Promise<User[]>;
496
506
  /**
@@ -498,8 +508,9 @@ export declare type LoadDataMethods = {
498
508
  * the the `ssoUsers` property.
499
509
  *
500
510
  * @example
501
- * const users = await sdk.loadSsoUsers();
502
- * sdk.notice(`Success! ${users.map((user) => i.id).join(', ')}`);
511
+ * const users = await ctx.loadSsoUsers();
512
+ *
513
+ * ctx.notice(`Success! ${users.map((user) => i.id).join(', ')}`);
503
514
  */
504
515
  loadSsoUsers: () => Promise<SsoUser[]>;
505
516
  };
@@ -511,11 +522,14 @@ export declare type ItemDialogMethods = {
511
522
  * without creating anything.
512
523
  *
513
524
  * @example
514
- * const item = await sdk.createNewItem('810907');
525
+ * const itemTypeId = prompt('Please insert a model ID:');
526
+ *
527
+ * const item = await ctx.createNewItem(itemTypeId);
528
+ *
515
529
  * if (item) {
516
- * sdk.notice(`Success! ${item.id}`);
530
+ * ctx.notice(`Success! ${item.id}`);
517
531
  * } else {
518
- * sdk.alert('Closed!');
532
+ * ctx.alert('Closed!');
519
533
  * }
520
534
  */
521
535
  createNewItem: (itemTypeId: string) => Promise<Item | null>;
@@ -526,7 +540,10 @@ export declare type ItemDialogMethods = {
526
540
  * choosing any record.
527
541
  *
528
542
  * @example
529
- * const items = await ctx.selectItem('810907', { multiple: true });
543
+ * const itemTypeId = prompt('Please insert a model ID:');
544
+ *
545
+ * const items = await ctx.selectItem(itemTypeId, { multiple: true });
546
+ *
530
547
  * if (items) {
531
548
  * ctx.notice(`Success! ${items.map((i) => i.id).join(', ')}`);
532
549
  * } else {
@@ -547,12 +564,14 @@ export declare type ItemDialogMethods = {
547
564
  * without persisting any change.
548
565
  *
549
566
  * @example
550
- * const item = await sdk.editItem('50479504');
567
+ * const itemId = prompt('Please insert a record ID:');
568
+ *
569
+ * const item = await ctx.editItem(itemId);
551
570
  *
552
571
  * if (item) {
553
- * sdk.notice(`Success! ${item.id}`);
572
+ * ctx.notice(`Success! ${item.id}`);
554
573
  * } else {
555
- * sdk.alert('Closed!');
574
+ * ctx.alert('Closed!');
556
575
  * }
557
576
  */
558
577
  editItem: (itemId: string) => Promise<Item | null>;
@@ -563,25 +582,35 @@ export declare type ToastMethods = {
563
582
  * Triggers an "error" toast displaying the selected message
564
583
  *
565
584
  * @example
566
- * sdk.alert('Alert!');
585
+ * const message = prompt(
586
+ * 'Please insert a message:',
587
+ * 'This is an alert message!',
588
+ * );
589
+ *
590
+ * ctx.alert(message);
567
591
  */
568
592
  alert: (message: string) => void;
569
593
  /**
570
594
  * Triggers a "success" toast displaying the selected message
571
595
  *
572
596
  * @example
573
- * sdk.notice('Notice!');
597
+ * const message = prompt(
598
+ * 'Please insert a message:',
599
+ * 'This is a notice message!',
600
+ * );
601
+ *
602
+ * ctx.notice(message);
574
603
  */
575
604
  notice: (message: string) => void;
576
605
  /**
577
606
  * Triggers a custom toast displaying the selected message (and optionally a CTA)
578
607
  *
579
608
  * @example
580
- * const result = await sdk.customToast({
609
+ * const result = await ctx.customToast({
581
610
  * type: 'warning',
582
611
  * message: 'Just a sample warning notification!',
583
612
  * dismissOnPageChange: true,
584
- * dismissAfterTimeout: 22000,
613
+ * dismissAfterTimeout: 5000,
585
614
  * cta: {
586
615
  * label: 'Execute call-to-action',
587
616
  * value: 'cta',
@@ -589,7 +618,7 @@ export declare type ToastMethods = {
589
618
  * });
590
619
  *
591
620
  * if (result === 'cta') {
592
- * sdk.notice(`Clicked CTA!`);
621
+ * ctx.notice(`Clicked CTA!`);
593
622
  * }
594
623
  */
595
624
  customToast: <CtaValue = unknown>(toast: Toast<CtaValue>) => Promise<CtaValue | null>;
@@ -605,12 +634,12 @@ export declare type UploadDialogMethods = {
605
634
  * user closes the dialog without selecting any upload.
606
635
  *
607
636
  * @example
608
- * const item = await sdk.selectUpload({ multiple: false });
637
+ * const item = await ctx.selectUpload({ multiple: false });
609
638
  *
610
639
  * if (item) {
611
- * sdk.notice(`Success! ${item.id}`);
640
+ * ctx.notice(`Success! ${item.id}`);
612
641
  * } else {
613
- * sdk.alert('Closed!');
642
+ * ctx.alert('Closed!');
614
643
  * }
615
644
  */
616
645
  selectUpload: {
@@ -630,12 +659,14 @@ export declare type UploadDialogMethods = {
630
659
  * the user deletes the asset
631
660
  *
632
661
  * @example
633
- * const item = await sdk.editUpload('21717537');
662
+ * const uploadId = prompt('Please insert an asset ID:');
663
+ *
664
+ * const item = await ctx.editUpload(uploadId);
634
665
  *
635
666
  * if (item) {
636
- * sdk.notice(`Success! ${item.id}`);
667
+ * ctx.notice(`Success! ${item.id}`);
637
668
  * } else {
638
- * sdk.alert('Closed!');
669
+ * ctx.alert('Closed!');
639
670
  * }
640
671
  */
641
672
  editUpload: (uploadId: string) => Promise<(Upload & {
@@ -647,8 +678,10 @@ export declare type UploadDialogMethods = {
647
678
  * the dialog without persisting any change.
648
679
  *
649
680
  * @example
650
- * const result = await sdk.editUploadMetadata({
651
- * upload_id: '21717537',
681
+ * const uploadId = prompt('Please insert an asset ID:');
682
+ *
683
+ * const result = await ctx.editUploadMetadata({
684
+ * upload_id: uploadId,
652
685
  * alt: null,
653
686
  * title: null,
654
687
  * custom_data: {},
@@ -656,9 +689,9 @@ export declare type UploadDialogMethods = {
656
689
  * });
657
690
  *
658
691
  * if (result) {
659
- * sdk.notice(`Success! ${JSON.stringify(result)}`);
692
+ * ctx.notice(`Success! ${JSON.stringify(result)}`);
660
693
  * } else {
661
- * sdk.alert('Closed!');
694
+ * ctx.alert('Closed!');
662
695
  * }
663
696
  */
664
697
  editUploadMetadata: (
@@ -674,16 +707,17 @@ export declare type CustomDialogMethods = {
674
707
  * returns calling the `resolve()` function
675
708
  *
676
709
  * @example
677
- * const result = await sdk.openModal({
710
+ * const result = await ctx.openModal({
678
711
  * id: 'regular',
679
712
  * title: 'Custom title!',
680
713
  * width: 'l',
681
714
  * parameters: { foo: 'bar' },
682
715
  * });
716
+ *
683
717
  * if (result) {
684
- * sdk.notice(`Success! ${JSON.stringify(result)}`);
718
+ * ctx.notice(`Success! ${JSON.stringify(result)}`);
685
719
  * } else {
686
- * sdk.alert('Closed!');
720
+ * ctx.alert('Closed!');
687
721
  * }
688
722
  */
689
723
  openModal: (modal: Modal) => Promise<unknown>;
@@ -692,7 +726,7 @@ export declare type CustomDialogMethods = {
692
726
  * the value of the choice made by the user
693
727
  *
694
728
  * @example
695
- * const result = await sdk.openConfirm({
729
+ * const result = await ctx.openConfirm({
696
730
  * title: 'Custom title',
697
731
  * content:
698
732
  * 'Lorem Ipsum is simply dummy text of the printing and typesetting industry',
@@ -713,10 +747,11 @@ export declare type CustomDialogMethods = {
713
747
  * value: false,
714
748
  * },
715
749
  * });
750
+ *
716
751
  * if (result) {
717
- * sdk.notice(`Success! ${result}`);
752
+ * ctx.notice(`Success! ${result}`);
718
753
  * } else {
719
- * sdk.alert('Cancelled!');
754
+ * ctx.alert('Cancelled!');
720
755
  * }
721
756
  */
722
757
  openConfirm: (options: ConfirmOptions) => Promise<unknown>;
@@ -727,7 +762,7 @@ export declare type NavigateMethods = {
727
762
  * Moves the user to another URL internal to the backend
728
763
  *
729
764
  * @example
730
- * sdk.navigateTo('/');
765
+ * ctx.navigateTo('/');
731
766
  */
732
767
  navigateTo: (path: string) => void;
733
768
  };
@@ -767,14 +802,23 @@ export declare type ItemFormAdditionalMethods = {
767
802
  * Hides/shows a specific field in the form
768
803
  *
769
804
  * @example
770
- * sdk.toggleField(sdk.fieldPath, true);
805
+ * const fieldPath = prompt(
806
+ * 'Please insert the path of a field in the form',
807
+ * ctx.fieldPath,
808
+ * );
809
+ *
810
+ * ctx.toggleField(fieldPath, true);
771
811
  */
772
812
  toggleField: (path: string, show: boolean) => void;
773
813
  /**
774
814
  * Disables/re-enables a specific field in the form
775
815
  *
776
816
  * @example
777
- * sdk.disableField(sdk.fieldPath, true);
817
+ * const fieldPath = prompt(
818
+ * 'Please insert the path of a field in the form',
819
+ * ctx.fieldPath,
820
+ * );
821
+ * ctx.disableField(fieldPath, true);
778
822
  */
779
823
  disableField: (path: string, disable: boolean) => void;
780
824
  /**
@@ -782,21 +826,29 @@ export declare type ItemFormAdditionalMethods = {
782
826
  * localized it will switch language tab and then navigate to the chosen field.
783
827
  *
784
828
  * @example
785
- * sdk.scrollToField(sdk.fieldPath);
829
+ * const fieldPath = prompt(
830
+ * 'Please insert the path of a field in the form',
831
+ * ctx.fieldPath,
832
+ * );
833
+ * ctx.scrollToField(fieldPath);
786
834
  */
787
835
  scrollToField: (path: string, locale?: string) => void;
788
836
  /**
789
837
  * Changes a specific path of the `formValues` object
790
838
  *
791
839
  * @example
792
- * sdk.setFieldValue(sdk.fieldPath, 'new value');
840
+ * const fieldPath = prompt(
841
+ * 'Please insert the path of a field in the form',
842
+ * ctx.fieldPath,
843
+ * );
844
+ * ctx.setFieldValue(fieldPath, 'new value');
793
845
  */
794
846
  setFieldValue: (path: string, value: unknown) => void;
795
847
  /**
796
848
  * Triggers a submit form for current record
797
849
  *
798
850
  * @example
799
- * await sdk.saveCurrentItem();
851
+ * await ctx.saveCurrentItem();
800
852
  */
801
853
  saveCurrentItem: () => Promise<void>;
802
854
  };
@@ -863,6 +915,14 @@ export declare type RenderModalAdditionalMethods = {
863
915
  /**
864
916
  * A function to be called by the plugin to close the modal. The `openModal`
865
917
  * call will be resolved with the passed return value
918
+ *
919
+ * @example
920
+ * const returnValue = prompt(
921
+ * 'Please specify the value to return to the caller:',
922
+ * 'success',
923
+ * );
924
+ *
925
+ * ctx.resolve(returnValue);
866
926
  */
867
927
  resolve: (returnValue: unknown) => void;
868
928
  };