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 +1 -1
- package/dist/esm/types.d.ts +108 -48
- package/dist/types/types.d.ts +108 -48
- package/package.json +2 -2
- package/types.json +183 -174
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# `datocms-plugin-sdk`
|
|
2
2
|
|
|
3
|
-
|
|
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
|
|
package/dist/esm/types.d.ts
CHANGED
|
@@ -396,11 +396,11 @@ export declare type FieldAppearanceChange = {
|
|
|
396
396
|
operation: 'removeEditor';
|
|
397
397
|
} | {
|
|
398
398
|
operation: 'updateEditor';
|
|
399
|
-
newFieldExtensionId?:
|
|
399
|
+
newFieldExtensionId?: string;
|
|
400
400
|
newFieldExtensionParameters?: Record<string, unknown>;
|
|
401
401
|
} | {
|
|
402
402
|
operation: 'setEditor';
|
|
403
|
-
fieldExtensionId:
|
|
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?:
|
|
411
|
+
newFieldExtensionId?: string;
|
|
412
412
|
newParameters?: Record<string, unknown>;
|
|
413
413
|
} | {
|
|
414
414
|
operation: 'insertAddon';
|
|
415
415
|
index: number;
|
|
416
|
-
fieldExtensionId:
|
|
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 =
|
|
442
|
-
*
|
|
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
|
|
467
|
-
*
|
|
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
|
|
480
|
-
*
|
|
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
|
|
493
|
-
*
|
|
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
|
|
502
|
-
*
|
|
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
|
|
525
|
+
* const itemTypeId = prompt('Please insert a model ID:');
|
|
526
|
+
*
|
|
527
|
+
* const item = await ctx.createNewItem(itemTypeId);
|
|
528
|
+
*
|
|
515
529
|
* if (item) {
|
|
516
|
-
*
|
|
530
|
+
* ctx.notice(`Success! ${item.id}`);
|
|
517
531
|
* } else {
|
|
518
|
-
*
|
|
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
|
|
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
|
|
567
|
+
* const itemId = prompt('Please insert a record ID:');
|
|
568
|
+
*
|
|
569
|
+
* const item = await ctx.editItem(itemId);
|
|
551
570
|
*
|
|
552
571
|
* if (item) {
|
|
553
|
-
*
|
|
572
|
+
* ctx.notice(`Success! ${item.id}`);
|
|
554
573
|
* } else {
|
|
555
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
|
609
|
+
* const result = await ctx.customToast({
|
|
581
610
|
* type: 'warning',
|
|
582
611
|
* message: 'Just a sample warning notification!',
|
|
583
612
|
* dismissOnPageChange: true,
|
|
584
|
-
* dismissAfterTimeout:
|
|
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
|
-
*
|
|
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
|
|
637
|
+
* const item = await ctx.selectUpload({ multiple: false });
|
|
609
638
|
*
|
|
610
639
|
* if (item) {
|
|
611
|
-
*
|
|
640
|
+
* ctx.notice(`Success! ${item.id}`);
|
|
612
641
|
* } else {
|
|
613
|
-
*
|
|
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
|
|
662
|
+
* const uploadId = prompt('Please insert an asset ID:');
|
|
663
|
+
*
|
|
664
|
+
* const item = await ctx.editUpload(uploadId);
|
|
634
665
|
*
|
|
635
666
|
* if (item) {
|
|
636
|
-
*
|
|
667
|
+
* ctx.notice(`Success! ${item.id}`);
|
|
637
668
|
* } else {
|
|
638
|
-
*
|
|
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
|
|
651
|
-
*
|
|
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
|
-
*
|
|
692
|
+
* ctx.notice(`Success! ${JSON.stringify(result)}`);
|
|
660
693
|
* } else {
|
|
661
|
-
*
|
|
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
|
|
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
|
-
*
|
|
718
|
+
* ctx.notice(`Success! ${JSON.stringify(result)}`);
|
|
685
719
|
* } else {
|
|
686
|
-
*
|
|
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
|
|
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
|
-
*
|
|
752
|
+
* ctx.notice(`Success! ${result}`);
|
|
718
753
|
* } else {
|
|
719
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
|
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
|
};
|