@metamask/snaps-sdk 6.0.0 → 6.1.1

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.
Files changed (44) hide show
  1. package/CHANGELOG.md +28 -1
  2. package/dist/index.js +138 -60
  3. package/dist/index.js.map +1 -1
  4. package/dist/index.mjs +170 -57
  5. package/dist/index.mjs.map +1 -1
  6. package/dist/jsx/index.js +143 -47
  7. package/dist/jsx/index.js.map +1 -1
  8. package/dist/jsx/index.mjs +149 -52
  9. package/dist/jsx/index.mjs.map +1 -1
  10. package/dist/jsx/jsx-dev-runtime.js +104 -25
  11. package/dist/jsx/jsx-dev-runtime.js.map +1 -1
  12. package/dist/jsx/jsx-dev-runtime.mjs +110 -30
  13. package/dist/jsx/jsx-dev-runtime.mjs.map +1 -1
  14. package/dist/tsconfig.build.tsbuildinfo +1 -1
  15. package/dist/types/internals/jsx.d.ts +1 -2
  16. package/dist/types/internals/structs.d.ts +12 -3
  17. package/dist/types/internals/svg.d.ts +1 -1
  18. package/dist/types/jsx/components/Card.d.ts +36 -0
  19. package/dist/types/jsx/components/Container.d.ts +34 -0
  20. package/dist/types/jsx/components/Footer.d.ts +28 -0
  21. package/dist/types/jsx/components/index.d.ts +7 -1
  22. package/dist/types/jsx/index.d.ts +1 -1
  23. package/dist/types/jsx/validation.d.ts +37 -5
  24. package/dist/types/types/handlers/user-input.d.ts +29 -29
  25. package/dist/types/types/interface.d.ts +7 -7
  26. package/dist/types/types/methods/dialog.d.ts +8 -2
  27. package/dist/types/types/methods/index.d.ts +1 -0
  28. package/dist/types/types/methods/methods.d.ts +2 -0
  29. package/dist/types/types/methods/resolve-interface.d.ts +15 -0
  30. package/dist/types/ui/builder.d.ts +1 -1
  31. package/dist/types/ui/components/address.d.ts +4 -4
  32. package/dist/types/ui/components/button.d.ts +7 -7
  33. package/dist/types/ui/components/copyable.d.ts +5 -5
  34. package/dist/types/ui/components/divider.d.ts +3 -3
  35. package/dist/types/ui/components/form.d.ts +7 -7
  36. package/dist/types/ui/components/heading.d.ts +4 -4
  37. package/dist/types/ui/components/image.d.ts +4 -4
  38. package/dist/types/ui/components/input.d.ts +9 -9
  39. package/dist/types/ui/components/panel.d.ts +1 -1
  40. package/dist/types/ui/components/row.d.ts +6 -6
  41. package/dist/types/ui/components/spinner.d.ts +3 -3
  42. package/dist/types/ui/components/text.d.ts +5 -5
  43. package/dist/types/ui/nodes.d.ts +6 -6
  44. package/package.json +6 -6
package/dist/index.mjs CHANGED
@@ -187,9 +187,11 @@ function getErrorData(error) {
187
187
  import {
188
188
  Struct,
189
189
  define,
190
+ is,
190
191
  literal as superstructLiteral,
191
192
  union as superstructUnion
192
- } from "superstruct";
193
+ } from "@metamask/superstruct";
194
+ import { hasProperty as hasProperty2, isPlainObject } from "@metamask/utils";
193
195
  function literal(value) {
194
196
  return define(
195
197
  JSON.stringify(value),
@@ -209,6 +211,41 @@ function union([
209
211
  function enumValue(constant) {
210
212
  return literal(constant);
211
213
  }
214
+ function typedUnion(structs) {
215
+ return new Struct({
216
+ type: "union",
217
+ schema: null,
218
+ *entries(value, context) {
219
+ if (!isPlainObject(value) || !hasProperty2(value, "type")) {
220
+ return;
221
+ }
222
+ const { type } = value;
223
+ const struct = structs.find(({ schema }) => is(type, schema.type));
224
+ if (!struct) {
225
+ return;
226
+ }
227
+ for (const entry of struct.entries(value, context)) {
228
+ yield entry;
229
+ }
230
+ },
231
+ validator(value, context) {
232
+ const types = structs.map(({ schema }) => schema.type.type);
233
+ if (!isPlainObject(value) || !hasProperty2(value, "type") || typeof value.type !== "string") {
234
+ return `Expected type to be one of: ${types.join(
235
+ ", "
236
+ )}, but received: undefined`;
237
+ }
238
+ const { type } = value;
239
+ const struct = structs.find(({ schema }) => is(type, schema.type));
240
+ if (struct) {
241
+ return struct.validator(value, context);
242
+ }
243
+ return `Expected type to be one of: ${types.join(
244
+ ", "
245
+ )}, but received: "${type}"`;
246
+ }
247
+ });
248
+ }
212
249
 
213
250
  // src/internals/jsx.ts
214
251
  function nullUnion(structs) {
@@ -216,7 +253,7 @@ function nullUnion(structs) {
216
253
  }
217
254
 
218
255
  // src/internals/svg.ts
219
- import { refine, string } from "superstruct";
256
+ import { refine, string } from "@metamask/superstruct";
220
257
  function svg() {
221
258
  return refine(string(), "SVG", (value) => {
222
259
  if (!value.includes("<svg")) {
@@ -266,14 +303,14 @@ var UserRejectedRequestError = createSnapError(
266
303
  import { assert, bytesToBase64 } from "@metamask/utils";
267
304
 
268
305
  // src/ui/components/address.ts
306
+ import { assign as assign2, literal as literal2, object as object2 } from "@metamask/superstruct";
269
307
  import { HexChecksumAddressStruct } from "@metamask/utils";
270
- import { assign as assign2, literal as literal2, object as object2 } from "superstruct";
271
308
 
272
309
  // src/ui/builder.ts
273
- import { assertStruct, isPlainObject } from "@metamask/utils";
310
+ import { assertStruct, isPlainObject as isPlainObject2 } from "@metamask/utils";
274
311
  function createBuilder(type, struct, keys = []) {
275
312
  return (...args) => {
276
- if (args.length === 1 && isPlainObject(args[0])) {
313
+ if (args.length === 1 && isPlainObject2(args[0])) {
277
314
  const node2 = { ...args[0], type };
278
315
  assertStruct(node2, struct, `Invalid ${type} component`);
279
316
  return node2;
@@ -296,7 +333,7 @@ function createBuilder(type, struct, keys = []) {
296
333
  }
297
334
 
298
335
  // src/ui/nodes.ts
299
- import { assign, object, string as string2, unknown } from "superstruct";
336
+ import { assign, object, string as string2, unknown } from "@metamask/superstruct";
300
337
  var NodeType = /* @__PURE__ */ ((NodeType2) => {
301
338
  NodeType2["Copyable"] = "copyable";
302
339
  NodeType2["Divider"] = "divider";
@@ -342,7 +379,7 @@ import {
342
379
  object as object3,
343
380
  optional,
344
381
  string as string3
345
- } from "superstruct";
382
+ } from "@metamask/superstruct";
346
383
  var CopyableStruct = assign3(
347
384
  LiteralStruct,
348
385
  object3({
@@ -357,7 +394,7 @@ var copyable = createBuilder("copyable" /* Copyable */, CopyableStruct, [
357
394
  ]);
358
395
 
359
396
  // src/ui/components/divider.ts
360
- import { assign as assign4, literal as literal4, object as object4 } from "superstruct";
397
+ import { assign as assign4, literal as literal4, object as object4 } from "@metamask/superstruct";
361
398
  var DividerStruct = assign4(
362
399
  NodeStruct,
363
400
  object4({
@@ -367,7 +404,7 @@ var DividerStruct = assign4(
367
404
  var divider = createBuilder("divider" /* Divider */, DividerStruct);
368
405
 
369
406
  // src/ui/components/heading.ts
370
- import { assign as assign5, literal as literal5, object as object5, string as string4 } from "superstruct";
407
+ import { assign as assign5, literal as literal5, object as object5, string as string4 } from "@metamask/superstruct";
371
408
  var HeadingStruct = assign5(
372
409
  LiteralStruct,
373
410
  object5({
@@ -380,7 +417,7 @@ var heading = createBuilder("heading" /* Heading */, HeadingStruct, [
380
417
  ]);
381
418
 
382
419
  // src/ui/components/image.ts
383
- import { assign as assign6, literal as literal6, object as object6 } from "superstruct";
420
+ import { assign as assign6, literal as literal6, object as object6 } from "@metamask/superstruct";
384
421
  var ImageStruct = assign6(
385
422
  NodeStruct,
386
423
  object6({
@@ -391,10 +428,17 @@ var ImageStruct = assign6(
391
428
  var image = createBuilder("image" /* Image */, ImageStruct, ["value"]);
392
429
 
393
430
  // src/ui/components/panel.ts
394
- import { array as array2, assign as assign13, lazy, literal as literal13, object as object13, union as union6 } from "superstruct";
431
+ import { array as array2, assign as assign13, lazy, literal as literal13, object as object13 } from "@metamask/superstruct";
395
432
 
396
433
  // src/ui/components/button.ts
397
- import { assign as assign7, literal as literal7, object as object7, optional as optional2, string as string5, union as union2 } from "superstruct";
434
+ import {
435
+ assign as assign7,
436
+ literal as literal7,
437
+ object as object7,
438
+ optional as optional2,
439
+ string as string5,
440
+ union as union2
441
+ } from "@metamask/superstruct";
398
442
  var ButtonVariant = /* @__PURE__ */ ((ButtonVariant2) => {
399
443
  ButtonVariant2["Primary"] = "primary";
400
444
  ButtonVariant2["Secondary"] = "secondary";
@@ -430,10 +474,24 @@ var button = createBuilder("button" /* Button */, ButtonStruct, [
430
474
  ]);
431
475
 
432
476
  // src/ui/components/form.ts
433
- import { array, assign as assign9, literal as literal9, object as object9, string as string7, union as union4 } from "superstruct";
477
+ import {
478
+ array,
479
+ assign as assign9,
480
+ literal as literal9,
481
+ object as object9,
482
+ string as string7,
483
+ union as union4
484
+ } from "@metamask/superstruct";
434
485
 
435
486
  // src/ui/components/input.ts
436
- import { assign as assign8, literal as literal8, object as object8, optional as optional3, string as string6, union as union3 } from "superstruct";
487
+ import {
488
+ assign as assign8,
489
+ literal as literal8,
490
+ object as object8,
491
+ optional as optional3,
492
+ string as string6,
493
+ union as union3
494
+ } from "@metamask/superstruct";
437
495
  var InputType = /* @__PURE__ */ ((InputType2) => {
438
496
  InputType2["Text"] = "text";
439
497
  InputType2["Number"] = "number";
@@ -482,7 +540,14 @@ var form = createBuilder("form" /* Form */, FormStruct, [
482
540
  ]);
483
541
 
484
542
  // src/ui/components/row.ts
485
- import { assign as assign11, literal as literal11, object as object11, string as string9, optional as optional5, union as union5 } from "superstruct";
543
+ import {
544
+ assign as assign11,
545
+ literal as literal11,
546
+ object as object11,
547
+ string as string9,
548
+ optional as optional5,
549
+ union as union5
550
+ } from "@metamask/superstruct";
486
551
 
487
552
  // src/ui/components/text.ts
488
553
  import {
@@ -492,7 +557,7 @@ import {
492
557
  object as object10,
493
558
  optional as optional4,
494
559
  string as string8
495
- } from "superstruct";
560
+ } from "@metamask/superstruct";
496
561
  var TextStruct = assign10(
497
562
  LiteralStruct,
498
563
  object10({
@@ -536,7 +601,7 @@ var row = createBuilder("row" /* Row */, RowStruct, [
536
601
  ]);
537
602
 
538
603
  // src/ui/components/spinner.ts
539
- import { assign as assign12, literal as literal12, object as object12 } from "superstruct";
604
+ import { assign as assign12, literal as literal12, object as object12 } from "@metamask/superstruct";
540
605
  var SpinnerStruct = assign12(
541
606
  NodeStruct,
542
607
  object12({
@@ -561,7 +626,7 @@ var PanelStruct = assign13(
561
626
  })
562
627
  );
563
628
  var panel = createBuilder("panel" /* Panel */, PanelStruct, ["children"]);
564
- var ComponentStruct = union6([
629
+ var ComponentStruct = typedUnion([
565
630
  CopyableStruct,
566
631
  DividerStruct,
567
632
  HeadingStruct,
@@ -577,10 +642,10 @@ var ComponentStruct = union6([
577
642
  ]);
578
643
 
579
644
  // src/ui/component.ts
645
+ import { is as is2 } from "@metamask/superstruct";
580
646
  import { assertStruct as assertStruct2 } from "@metamask/utils";
581
- import { is } from "superstruct";
582
647
  function isComponent(value) {
583
- return is(value, ComponentStruct);
648
+ return is2(value, ComponentStruct);
584
649
  }
585
650
  function assertIsComponent(value) {
586
651
  assertStruct2(value, ComponentStruct, "Invalid component");
@@ -644,9 +709,9 @@ import {
644
709
  optional as optional6,
645
710
  record,
646
711
  string as string10,
647
- union as union7,
712
+ union as union6,
648
713
  boolean as boolean3
649
- } from "superstruct";
714
+ } from "@metamask/superstruct";
650
715
  var UserInputEventType = /* @__PURE__ */ ((UserInputEventType2) => {
651
716
  UserInputEventType2["ButtonClickEvent"] = "ButtonClickEvent";
652
717
  UserInputEventType2["FormSubmitEvent"] = "FormSubmitEvent";
@@ -675,7 +740,7 @@ var FormSubmitEventStruct = assign14(
675
740
  GenericEventStruct,
676
741
  object14({
677
742
  type: literal14("FormSubmitEvent" /* FormSubmitEvent */),
678
- value: record(string10(), nullable(union7([string10(), FileStruct, boolean3()]))),
743
+ value: record(string10(), nullable(union6([string10(), FileStruct, boolean3()]))),
679
744
  name: string10()
680
745
  })
681
746
  );
@@ -684,7 +749,7 @@ var InputChangeEventStruct = assign14(
684
749
  object14({
685
750
  type: literal14("InputChangeEvent" /* InputChangeEvent */),
686
751
  name: string10(),
687
- value: union7([string10(), boolean3()])
752
+ value: union6([string10(), boolean3()])
688
753
  })
689
754
  );
690
755
  var FileUploadEventStruct = assign14(
@@ -695,7 +760,7 @@ var FileUploadEventStruct = assign14(
695
760
  file: nullable(FileStruct)
696
761
  })
697
762
  );
698
- var UserInputEventStruct = union7([
763
+ var UserInputEventStruct = union6([
699
764
  ButtonClickEventStruct,
700
765
  FormSubmitEventStruct,
701
766
  InputChangeEventStruct,
@@ -734,18 +799,18 @@ var NotificationType = /* @__PURE__ */ ((NotificationType2) => {
734
799
  })(NotificationType || {});
735
800
 
736
801
  // src/types/interface.ts
802
+ import {
803
+ boolean as boolean5,
804
+ nullable as nullable3,
805
+ record as record3,
806
+ string as string12,
807
+ union as union7
808
+ } from "@metamask/superstruct";
737
809
  import { JsonStruct as JsonStruct2 } from "@metamask/utils";
738
- import { boolean as boolean5, nullable as nullable3, record as record3, string as string12, union as union8 } from "superstruct";
739
810
 
740
811
  // src/jsx/validation.ts
741
812
  import {
742
- hasProperty as hasProperty2,
743
- HexChecksumAddressStruct as HexChecksumAddressStruct2,
744
- isPlainObject as isPlainObject2,
745
- JsonStruct
746
- } from "@metamask/utils";
747
- import {
748
- is as is2,
813
+ is as is3,
749
814
  boolean as boolean4,
750
815
  optional as optional7,
751
816
  array as array3,
@@ -756,7 +821,13 @@ import {
756
821
  record as record2,
757
822
  string as string11,
758
823
  tuple
759
- } from "superstruct";
824
+ } from "@metamask/superstruct";
825
+ import {
826
+ hasProperty as hasProperty3,
827
+ HexChecksumAddressStruct as HexChecksumAddressStruct2,
828
+ isPlainObject as isPlainObject3,
829
+ JsonStruct
830
+ } from "@metamask/utils";
760
831
  var KeyStruct = nullUnion([string11(), number2()]);
761
832
  var StringElementStruct = children([
762
833
  string11()
@@ -821,22 +892,32 @@ var FileInputStruct = element(
821
892
  compact: optional7(boolean4())
822
893
  }
823
894
  );
895
+ var BUTTON_INPUT = [InputStruct2, ButtonStruct2];
896
+ var FIELD_CHILDREN_ARRAY = [
897
+ InputStruct2,
898
+ DropdownStruct,
899
+ FileInputStruct,
900
+ CheckboxStruct
901
+ ];
902
+ var FieldChildUnionStruct = nullUnion([
903
+ ...FIELD_CHILDREN_ARRAY,
904
+ ...BUTTON_INPUT
905
+ ]);
906
+ var FieldChildStruct = nullUnion([
907
+ tuple(BUTTON_INPUT),
908
+ ...FIELD_CHILDREN_ARRAY
909
+ ]);
824
910
  var FieldStruct = element("Field", {
825
911
  label: optional7(string11()),
826
912
  error: optional7(string11()),
827
- children: nullUnion([
828
- tuple([InputStruct2, ButtonStruct2]),
829
- DropdownStruct,
830
- FileInputStruct,
831
- InputStruct2,
832
- CheckboxStruct
833
- ])
913
+ children: FieldChildStruct
834
914
  });
915
+ var FormChildStruct = children(
916
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
917
+ [FieldStruct, lazy2(() => BoxChildStruct)]
918
+ );
835
919
  var FormStruct2 = element("Form", {
836
- children: children(
837
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
838
- [FieldStruct, lazy2(() => BoxChildStruct)]
839
- ),
920
+ children: FormChildStruct,
840
921
  name: string11()
841
922
  });
842
923
  var BoldStruct = element("Bold", {
@@ -860,11 +941,12 @@ var FormattingStruct = nullUnion([
860
941
  var AddressStruct2 = element("Address", {
861
942
  address: HexChecksumAddressStruct2
862
943
  });
944
+ var BoxChildrenStruct = children(
945
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
946
+ [lazy2(() => BoxChildStruct)]
947
+ );
863
948
  var BoxStruct = element("Box", {
864
- children: children(
865
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
866
- [lazy2(() => BoxChildStruct)]
867
- ),
949
+ children: BoxChildrenStruct,
868
950
  direction: optional7(nullUnion([literal("horizontal"), literal("vertical")])),
869
951
  alignment: optional7(
870
952
  nullUnion([
@@ -876,6 +958,23 @@ var BoxStruct = element("Box", {
876
958
  ])
877
959
  )
878
960
  });
961
+ var FooterChildStruct = nullUnion([
962
+ tuple([ButtonStruct2, ButtonStruct2]),
963
+ ButtonStruct2
964
+ ]);
965
+ var FooterStruct = element("Footer", {
966
+ children: FooterChildStruct
967
+ });
968
+ var ContainerChildStruct = nullUnion([
969
+ tuple([BoxStruct, FooterStruct]),
970
+ BoxStruct
971
+ ]);
972
+ var ContainerStruct = element(
973
+ "Container",
974
+ {
975
+ children: ContainerChildStruct
976
+ }
977
+ );
879
978
  var CopyableStruct2 = element("Copyable", {
880
979
  value: string11(),
881
980
  sensitive: optional7(boolean4())
@@ -885,6 +984,13 @@ var ValueStruct = element("Value", {
885
984
  value: string11(),
886
985
  extra: string11()
887
986
  });
987
+ var CardStruct = element("Card", {
988
+ image: optional7(string11()),
989
+ title: string11(),
990
+ description: optional7(string11()),
991
+ value: string11(),
992
+ extra: optional7(string11())
993
+ });
888
994
  var HeadingStruct2 = element("Heading", {
889
995
  children: StringElementStruct
890
996
  });
@@ -930,7 +1036,7 @@ var RowStruct2 = element("Row", {
930
1036
  tooltip: optional7(string11())
931
1037
  });
932
1038
  var SpinnerStruct2 = element("Spinner");
933
- var BoxChildStruct = nullUnion([
1039
+ var BoxChildStruct = typedUnion([
934
1040
  AddressStruct2,
935
1041
  BoldStruct,
936
1042
  BoxStruct,
@@ -949,10 +1055,14 @@ var BoxChildStruct = nullUnion([
949
1055
  SpinnerStruct2,
950
1056
  TextStruct2,
951
1057
  TooltipStruct,
952
- CheckboxStruct
1058
+ CheckboxStruct,
1059
+ CardStruct
1060
+ ]);
1061
+ var RootJSXElementStruct = nullUnion([
1062
+ BoxChildStruct,
1063
+ ContainerStruct
953
1064
  ]);
954
- var RootJSXElementStruct = BoxChildStruct;
955
- var JSXElementStruct = nullUnion([
1065
+ var JSXElementStruct = typedUnion([
956
1066
  ButtonStruct2,
957
1067
  InputStruct2,
958
1068
  FileInputStruct,
@@ -974,17 +1084,20 @@ var JSXElementStruct = nullUnion([
974
1084
  OptionStruct,
975
1085
  ValueStruct,
976
1086
  TooltipStruct,
977
- CheckboxStruct
1087
+ CheckboxStruct,
1088
+ FooterStruct,
1089
+ ContainerStruct,
1090
+ CardStruct
978
1091
  ]);
979
1092
 
980
1093
  // src/types/interface.ts
981
- var StateStruct = union8([FileStruct, string12(), boolean5()]);
1094
+ var StateStruct = union7([FileStruct, string12(), boolean5()]);
982
1095
  var FormStateStruct = record3(string12(), nullable3(StateStruct));
983
1096
  var InterfaceStateStruct = record3(
984
1097
  string12(),
985
- union8([FormStateStruct, nullable3(StateStruct)])
1098
+ union7([FormStateStruct, nullable3(StateStruct)])
986
1099
  );
987
- var ComponentOrElementStruct = union8([
1100
+ var ComponentOrElementStruct = union7([
988
1101
  ComponentStruct,
989
1102
  RootJSXElementStruct
990
1103
  ]);