@metamask-previews/profile-sync-controller 20.0.0-preview-988fbb56 → 20.0.0-preview-afb9460

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 (92) hide show
  1. package/CHANGELOG.md +2 -2
  2. package/dist/controllers/user-storage/UserStorageController.cjs +4 -16
  3. package/dist/controllers/user-storage/UserStorageController.cjs.map +1 -1
  4. package/dist/controllers/user-storage/UserStorageController.d.cts +10 -13
  5. package/dist/controllers/user-storage/UserStorageController.d.cts.map +1 -1
  6. package/dist/controllers/user-storage/UserStorageController.d.mts +10 -13
  7. package/dist/controllers/user-storage/UserStorageController.d.mts.map +1 -1
  8. package/dist/controllers/user-storage/UserStorageController.mjs +4 -16
  9. package/dist/controllers/user-storage/UserStorageController.mjs.map +1 -1
  10. package/dist/controllers/user-storage/account-syncing/controller-integration.cjs +166 -185
  11. package/dist/controllers/user-storage/account-syncing/controller-integration.cjs.map +1 -1
  12. package/dist/controllers/user-storage/account-syncing/controller-integration.d.cts +0 -3
  13. package/dist/controllers/user-storage/account-syncing/controller-integration.d.cts.map +1 -1
  14. package/dist/controllers/user-storage/account-syncing/controller-integration.d.mts +0 -3
  15. package/dist/controllers/user-storage/account-syncing/controller-integration.d.mts.map +1 -1
  16. package/dist/controllers/user-storage/account-syncing/controller-integration.mjs +166 -185
  17. package/dist/controllers/user-storage/account-syncing/controller-integration.mjs.map +1 -1
  18. package/dist/controllers/user-storage/account-syncing/types.cjs.map +1 -1
  19. package/dist/controllers/user-storage/account-syncing/types.d.cts +0 -2
  20. package/dist/controllers/user-storage/account-syncing/types.d.cts.map +1 -1
  21. package/dist/controllers/user-storage/account-syncing/types.d.mts +0 -2
  22. package/dist/controllers/user-storage/account-syncing/types.d.mts.map +1 -1
  23. package/dist/controllers/user-storage/account-syncing/types.mjs.map +1 -1
  24. package/dist/controllers/user-storage/contact-syncing/controller-integration.cjs +162 -224
  25. package/dist/controllers/user-storage/contact-syncing/controller-integration.cjs.map +1 -1
  26. package/dist/controllers/user-storage/contact-syncing/controller-integration.d.cts +0 -3
  27. package/dist/controllers/user-storage/contact-syncing/controller-integration.d.cts.map +1 -1
  28. package/dist/controllers/user-storage/contact-syncing/controller-integration.d.mts +0 -3
  29. package/dist/controllers/user-storage/contact-syncing/controller-integration.d.mts.map +1 -1
  30. package/dist/controllers/user-storage/contact-syncing/controller-integration.mjs +162 -224
  31. package/dist/controllers/user-storage/contact-syncing/controller-integration.mjs.map +1 -1
  32. package/dist/controllers/user-storage/contact-syncing/types.cjs.map +1 -1
  33. package/dist/controllers/user-storage/contact-syncing/types.d.cts +0 -2
  34. package/dist/controllers/user-storage/contact-syncing/types.d.cts.map +1 -1
  35. package/dist/controllers/user-storage/contact-syncing/types.d.mts +0 -2
  36. package/dist/controllers/user-storage/contact-syncing/types.d.mts.map +1 -1
  37. package/dist/controllers/user-storage/contact-syncing/types.mjs.map +1 -1
  38. package/dist/controllers/user-storage/index.cjs +1 -1
  39. package/dist/controllers/user-storage/index.cjs.map +1 -1
  40. package/dist/controllers/user-storage/index.d.cts +1 -1
  41. package/dist/controllers/user-storage/index.d.cts.map +1 -1
  42. package/dist/controllers/user-storage/index.d.mts +1 -1
  43. package/dist/controllers/user-storage/index.d.mts.map +1 -1
  44. package/dist/controllers/user-storage/index.mjs +1 -1
  45. package/dist/controllers/user-storage/index.mjs.map +1 -1
  46. package/dist/controllers/user-storage/mocks/mockResponses.cjs +1 -1
  47. package/dist/controllers/user-storage/mocks/mockResponses.cjs.map +1 -1
  48. package/dist/controllers/user-storage/mocks/mockResponses.d.cts +9 -9
  49. package/dist/controllers/user-storage/mocks/mockResponses.d.cts.map +1 -1
  50. package/dist/controllers/user-storage/mocks/mockResponses.d.mts +9 -9
  51. package/dist/controllers/user-storage/mocks/mockResponses.d.mts.map +1 -1
  52. package/dist/controllers/user-storage/mocks/mockResponses.mjs +1 -1
  53. package/dist/controllers/user-storage/mocks/mockResponses.mjs.map +1 -1
  54. package/dist/controllers/user-storage/types.cjs.map +1 -1
  55. package/dist/controllers/user-storage/types.d.cts +3 -3
  56. package/dist/controllers/user-storage/types.d.cts.map +1 -1
  57. package/dist/controllers/user-storage/types.d.mts +3 -3
  58. package/dist/controllers/user-storage/types.d.mts.map +1 -1
  59. package/dist/controllers/user-storage/types.mjs.map +1 -1
  60. package/dist/sdk/user-storage.cjs +3 -9
  61. package/dist/sdk/user-storage.cjs.map +1 -1
  62. package/dist/sdk/user-storage.d.cts +0 -1
  63. package/dist/sdk/user-storage.d.cts.map +1 -1
  64. package/dist/sdk/user-storage.d.mts +0 -1
  65. package/dist/sdk/user-storage.d.mts.map +1 -1
  66. package/dist/sdk/user-storage.mjs +3 -9
  67. package/dist/sdk/user-storage.mjs.map +1 -1
  68. package/dist/shared/storage-schema.cjs +9 -31
  69. package/dist/shared/storage-schema.cjs.map +1 -1
  70. package/dist/shared/storage-schema.d.cts +11 -42
  71. package/dist/shared/storage-schema.d.cts.map +1 -1
  72. package/dist/shared/storage-schema.d.mts +11 -42
  73. package/dist/shared/storage-schema.d.mts.map +1 -1
  74. package/dist/shared/storage-schema.mjs +8 -30
  75. package/dist/shared/storage-schema.mjs.map +1 -1
  76. package/package.json +1 -1
  77. package/dist/controllers/user-storage/constants/index.cjs +0 -18
  78. package/dist/controllers/user-storage/constants/index.cjs.map +0 -1
  79. package/dist/controllers/user-storage/constants/index.d.cts +0 -2
  80. package/dist/controllers/user-storage/constants/index.d.cts.map +0 -1
  81. package/dist/controllers/user-storage/constants/index.d.mts +0 -2
  82. package/dist/controllers/user-storage/constants/index.d.mts.map +0 -1
  83. package/dist/controllers/user-storage/constants/index.mjs +0 -2
  84. package/dist/controllers/user-storage/constants/index.mjs.map +0 -1
  85. package/dist/controllers/user-storage/constants/traces.cjs +0 -17
  86. package/dist/controllers/user-storage/constants/traces.cjs.map +0 -1
  87. package/dist/controllers/user-storage/constants/traces.d.cts +0 -12
  88. package/dist/controllers/user-storage/constants/traces.d.cts.map +0 -1
  89. package/dist/controllers/user-storage/constants/traces.d.mts +0 -12
  90. package/dist/controllers/user-storage/constants/traces.d.mts.map +0 -1
  91. package/dist/controllers/user-storage/constants/traces.mjs +0 -14
  92. package/dist/controllers/user-storage/constants/traces.mjs.map +0 -1
@@ -1,41 +1,17 @@
1
1
  /**
2
2
  * The User Storage Endpoint requires a feature name and a namespace key.
3
- * Developers can provide additional features and keys by extending these types below.
4
- *
5
- * Adding ALLOW_ARBITRARY_KEYS as the first key in the array allows for any key to be used for this feature.
6
- * This can be useful for features where keys are not deterministic (eg. accounts addresses).
3
+ * Any user storage path should be in the form of `feature.key`.
7
4
  */
8
- declare const ALLOW_ARBITRARY_KEYS: "ALLOW_ARBITRARY_KEYS";
9
- export declare const USER_STORAGE_FEATURE_NAMES: {
10
- readonly notifications: "notifications";
11
- readonly accounts: "accounts_v2";
12
- readonly networks: "networks";
13
- readonly addressBook: "addressBook";
14
- };
15
- export type UserStorageFeatureNames = (typeof USER_STORAGE_FEATURE_NAMES)[keyof typeof USER_STORAGE_FEATURE_NAMES];
16
- export declare const USER_STORAGE_SCHEMA: {
17
- readonly notifications: readonly ["notification_settings"];
18
- readonly accounts_v2: readonly ["ALLOW_ARBITRARY_KEYS"];
19
- readonly networks: readonly ["ALLOW_ARBITRARY_KEYS"];
20
- readonly addressBook: readonly ["ALLOW_ARBITRARY_KEYS"];
21
- };
22
- type UserStorageSchema = typeof USER_STORAGE_SCHEMA;
23
- export type UserStorageFeatureKeys<Feature extends UserStorageFeatureNames> = UserStorageSchema[Feature][0] extends typeof ALLOW_ARBITRARY_KEYS ? string : UserStorageSchema[Feature][number];
24
- type UserStorageFeatureAndKey = {
25
- feature: UserStorageFeatureNames;
26
- key: UserStorageFeatureKeys<UserStorageFeatureNames>;
27
- };
28
- export type UserStoragePathWithFeatureOnly = UserStorageFeatureNames;
29
- export type UserStoragePathWithFeatureAndKey = {
30
- [K in UserStorageFeatureNames]: `${K}.${UserStorageFeatureKeys<K>}`;
31
- }[UserStoragePathWithFeatureOnly];
32
5
  /**
33
- * The below types are mainly used for the SDK.
34
- * These exist so that the SDK can be used with arbitrary feature names and keys.
35
- *
36
- * We only type enforce feature names and keys when using UserStorageController.
37
- * This is done so we don't end up with magic strings within the applications.
6
+ * Helper object that contains the feature names used in the controllers and SDK.
7
+ * Developers don't need to add new feature names to this object anymore, as the schema enforcement has been deprecated.
38
8
  */
9
+ export declare const USER_STORAGE_FEATURE_NAMES: {
10
+ notifications: string;
11
+ accounts: string;
12
+ networks: string;
13
+ addressBook: string;
14
+ };
39
15
  export type UserStorageGenericFeatureName = string;
40
16
  export type UserStorageGenericFeatureKey = string;
41
17
  export type UserStorageGenericPathWithFeatureAndKey = `${UserStorageGenericFeatureName}.${UserStorageGenericFeatureKey}`;
@@ -44,9 +20,7 @@ type UserStorageGenericFeatureAndKey = {
44
20
  feature: UserStorageGenericFeatureName;
45
21
  key: UserStorageGenericFeatureKey;
46
22
  };
47
- export declare const getFeatureAndKeyFromPath: <T extends boolean>(path: T extends true ? UserStoragePathWithFeatureAndKey : `${string}.${string}`, options?: {
48
- validateAgainstSchema: T;
49
- }) => T extends true ? UserStorageFeatureAndKey : UserStorageGenericFeatureAndKey;
23
+ export declare const getFeatureAndKeyFromPath: (path: UserStorageGenericPathWithFeatureAndKey) => UserStorageGenericFeatureAndKey;
50
24
  /**
51
25
  * Constructs a unique entry path for a user.
52
26
  * This can be done due to the uniqueness of the storage key (no users will share the same storage key).
@@ -54,13 +28,8 @@ export declare const getFeatureAndKeyFromPath: <T extends boolean>(path: T exten
54
28
  *
55
29
  * @param path - string in the form of `${feature}.${key}` that matches schema
56
30
  * @param storageKey - users storage key
57
- * @param options - options object
58
- * @param options.validateAgainstSchema - whether to validate the path against the schema.
59
- * This defaults to true, and should only be set to false when using the SDK with arbitrary feature names and keys.
60
31
  * @returns path to store entry
61
32
  */
62
- export declare function createEntryPath<T extends boolean>(path: T extends true ? UserStoragePathWithFeatureAndKey : UserStorageGenericPathWithFeatureAndKey, storageKey: string, options?: {
63
- validateAgainstSchema: T;
64
- }): string;
33
+ export declare function createEntryPath(path: UserStorageGenericPathWithFeatureAndKey, storageKey: string): string;
65
34
  export {};
66
35
  //# sourceMappingURL=storage-schema.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"storage-schema.d.mts","sourceRoot":"","sources":["../../src/shared/storage-schema.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,QAAA,MAAM,oBAAoB,wBAAkC,CAAC;AAE7D,eAAO,MAAM,0BAA0B;;;;;CAK7B,CAAC;AAEX,MAAM,MAAM,uBAAuB,GACjC,CAAC,OAAO,0BAA0B,CAAC,CAAC,MAAM,OAAO,0BAA0B,CAAC,CAAC;AAE/E,eAAO,MAAM,mBAAmB;;;;;CAKtB,CAAC;AAEX,KAAK,iBAAiB,GAAG,OAAO,mBAAmB,CAAC;AAEpD,MAAM,MAAM,sBAAsB,CAAC,OAAO,SAAS,uBAAuB,IACxE,iBAAiB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS,OAAO,oBAAoB,GAC7D,MAAM,GACN,iBAAiB,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC;AAEzC,KAAK,wBAAwB,GAAG;IAC9B,OAAO,EAAE,uBAAuB,CAAC;IACjC,GAAG,EAAE,sBAAsB,CAAC,uBAAuB,CAAC,CAAC;CACtD,CAAC;AAEF,MAAM,MAAM,8BAA8B,GAAG,uBAAuB,CAAC;AACrE,MAAM,MAAM,gCAAgC,GAAG;KAC5C,CAAC,IAAI,uBAAuB,GAAG,GAAG,CAAC,IAAI,sBAAsB,CAAC,CAAC,CAAC,EAAE;CACpE,CAAC,8BAA8B,CAAC,CAAC;AAElC;;;;;;GAMG;AAEH,MAAM,MAAM,6BAA6B,GAAG,MAAM,CAAC;AACnD,MAAM,MAAM,4BAA4B,GAAG,MAAM,CAAC;AAClD,MAAM,MAAM,uCAAuC,GACjD,GAAG,6BAA6B,IAAI,4BAA4B,EAAE,CAAC;AACrE,MAAM,MAAM,qCAAqC,GAC/C,6BAA6B,CAAC;AAEhC,KAAK,+BAA+B,GAAG;IACrC,OAAO,EAAE,6BAA6B,CAAC;IACvC,GAAG,EAAE,4BAA4B,CAAC;CACnC,CAAC;AAEF,eAAO,MAAM,wBAAwB;;iFAqDpC,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,wBAAgB,eAAe,CAAC,CAAC,SAAS,OAAO,EAC/C,IAAI,EAAE,CAAC,SAAS,IAAI,GAChB,gCAAgC,GAChC,uCAAuC,EAC3C,UAAU,EAAE,MAAM,EAClB,OAAO,GAAE;IACP,qBAAqB,EAAE,CAAC,CAAC;CACa,GACvC,MAAM,CAKR"}
1
+ {"version":3,"file":"storage-schema.d.mts","sourceRoot":"","sources":["../../src/shared/storage-schema.ts"],"names":[],"mappings":"AAEA;;;GAGG;AAEH;;;GAGG;AACH,eAAO,MAAM,0BAA0B;;;;;CAKtC,CAAC;AAEF,MAAM,MAAM,6BAA6B,GAAG,MAAM,CAAC;AACnD,MAAM,MAAM,4BAA4B,GAAG,MAAM,CAAC;AAClD,MAAM,MAAM,uCAAuC,GACjD,GAAG,6BAA6B,IAAI,4BAA4B,EAAE,CAAC;AACrE,MAAM,MAAM,qCAAqC,GAC/C,6BAA6B,CAAC;AAEhC,KAAK,+BAA+B,GAAG;IACrC,OAAO,EAAE,6BAA6B,CAAC;IACvC,GAAG,EAAE,4BAA4B,CAAC;CACnC,CAAC;AAEF,eAAO,MAAM,wBAAwB,SAC7B,uCAAuC,KAC5C,+BAYF,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAC7B,IAAI,EAAE,uCAAuC,EAC7C,UAAU,EAAE,MAAM,GACjB,MAAM,CAKR"}
@@ -1,43 +1,24 @@
1
1
  import { createSHA256Hash } from "./encryption/index.mjs";
2
2
  /**
3
3
  * The User Storage Endpoint requires a feature name and a namespace key.
4
- * Developers can provide additional features and keys by extending these types below.
5
- *
6
- * Adding ALLOW_ARBITRARY_KEYS as the first key in the array allows for any key to be used for this feature.
7
- * This can be useful for features where keys are not deterministic (eg. accounts addresses).
4
+ * Any user storage path should be in the form of `feature.key`.
5
+ */
6
+ /**
7
+ * Helper object that contains the feature names used in the controllers and SDK.
8
+ * Developers don't need to add new feature names to this object anymore, as the schema enforcement has been deprecated.
8
9
  */
9
- const ALLOW_ARBITRARY_KEYS = 'ALLOW_ARBITRARY_KEYS';
10
10
  export const USER_STORAGE_FEATURE_NAMES = {
11
11
  notifications: 'notifications',
12
12
  accounts: 'accounts_v2',
13
13
  networks: 'networks',
14
14
  addressBook: 'addressBook',
15
15
  };
16
- export const USER_STORAGE_SCHEMA = {
17
- [USER_STORAGE_FEATURE_NAMES.notifications]: ['notification_settings'],
18
- [USER_STORAGE_FEATURE_NAMES.accounts]: [ALLOW_ARBITRARY_KEYS],
19
- [USER_STORAGE_FEATURE_NAMES.networks]: [ALLOW_ARBITRARY_KEYS],
20
- [USER_STORAGE_FEATURE_NAMES.addressBook]: [ALLOW_ARBITRARY_KEYS], // keyed by address_chainId
21
- };
22
- export const getFeatureAndKeyFromPath = (path, options = { validateAgainstSchema: true }) => {
16
+ export const getFeatureAndKeyFromPath = (path) => {
23
17
  const pathRegex = /^\w+\.\w+$/u;
24
18
  if (!pathRegex.test(path)) {
25
19
  throw new Error(`user-storage - path is not in the correct format. Correct format: 'feature.key'`);
26
20
  }
27
21
  const [feature, key] = path.split('.');
28
- if (options.validateAgainstSchema) {
29
- const featureToValidate = feature;
30
- const keyToValidate = key;
31
- if (!(featureToValidate in USER_STORAGE_SCHEMA)) {
32
- throw new Error(`user-storage - invalid feature provided: ${featureToValidate}. Valid features: ${Object.keys(USER_STORAGE_SCHEMA).join(', ')}`);
33
- }
34
- const validFeature = USER_STORAGE_SCHEMA[featureToValidate];
35
- if (!validFeature.includes(keyToValidate) &&
36
- !validFeature.includes(ALLOW_ARBITRARY_KEYS)) {
37
- const validKeys = USER_STORAGE_SCHEMA[featureToValidate].join(', ');
38
- throw new Error(`user-storage - invalid key provided for this feature: ${keyToValidate}. Valid keys: ${validKeys}`);
39
- }
40
- }
41
22
  return { feature, key };
42
23
  };
43
24
  /**
@@ -47,13 +28,10 @@ export const getFeatureAndKeyFromPath = (path, options = { validateAgainstSchema
47
28
  *
48
29
  * @param path - string in the form of `${feature}.${key}` that matches schema
49
30
  * @param storageKey - users storage key
50
- * @param options - options object
51
- * @param options.validateAgainstSchema - whether to validate the path against the schema.
52
- * This defaults to true, and should only be set to false when using the SDK with arbitrary feature names and keys.
53
31
  * @returns path to store entry
54
32
  */
55
- export function createEntryPath(path, storageKey, options = { validateAgainstSchema: true }) {
56
- const { feature, key } = getFeatureAndKeyFromPath(path, options);
33
+ export function createEntryPath(path, storageKey) {
34
+ const { feature, key } = getFeatureAndKeyFromPath(path);
57
35
  const hashedKey = createSHA256Hash(key + storageKey);
58
36
  return `${feature}/${hashedKey}`;
59
37
  }
@@ -1 +1 @@
1
- {"version":3,"file":"storage-schema.mjs","sourceRoot":"","sources":["../../src/shared/storage-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,+BAAqB;AAEhD;;;;;;GAMG;AACH,MAAM,oBAAoB,GAAG,sBAA+B,CAAC;AAE7D,MAAM,CAAC,MAAM,0BAA0B,GAAG;IACxC,aAAa,EAAE,eAAe;IAC9B,QAAQ,EAAE,aAAa;IACvB,QAAQ,EAAE,UAAU;IACpB,WAAW,EAAE,aAAa;CAClB,CAAC;AAKX,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,CAAC,0BAA0B,CAAC,aAAa,CAAC,EAAE,CAAC,uBAAuB,CAAC;IACrE,CAAC,0BAA0B,CAAC,QAAQ,CAAC,EAAE,CAAC,oBAAoB,CAAC;IAC7D,CAAC,0BAA0B,CAAC,QAAQ,CAAC,EAAE,CAAC,oBAAoB,CAAC;IAC7D,CAAC,0BAA0B,CAAC,WAAW,CAAC,EAAE,CAAC,oBAAoB,CAAC,EAAE,2BAA2B;CACrF,CAAC;AAuCX,MAAM,CAAC,MAAM,wBAAwB,GAAG,CACtC,IAE2C,EAC3C,UAEI,EAAE,qBAAqB,EAAE,IAAS,EAAE,EAGN,EAAE;IACpC,MAAM,SAAS,GAAG,aAAa,CAAC;IAEhC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;QACzB,MAAM,IAAI,KAAK,CACb,iFAAiF,CAClF,CAAC;KACH;IAED,MAAM,CAAC,OAAO,EAAE,GAAG,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAEvC,IAAI,OAAO,CAAC,qBAAqB,EAAE;QACjC,MAAM,iBAAiB,GAAG,OAAkC,CAAC;QAC7D,MAAM,aAAa,GAAG,GAErB,CAAC;QAEF,IAAI,CAAC,CAAC,iBAAiB,IAAI,mBAAmB,CAAC,EAAE;YAC/C,MAAM,IAAI,KAAK,CACb,4CAA4C,iBAAiB,qBAAqB,MAAM,CAAC,IAAI,CAC3F,mBAAmB,CACpB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CACf,CAAC;SACH;QAED,MAAM,YAAY,GAAG,mBAAmB,CACtC,iBAAiB,CACG,CAAC;QAEvB,IACE,CAAC,YAAY,CAAC,QAAQ,CAAC,aAAa,CAAC;YACrC,CAAC,YAAY,CAAC,QAAQ,CAAC,oBAAoB,CAAC,EAC5C;YACA,MAAM,SAAS,GAAG,mBAAmB,CAAC,iBAAiB,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAEpE,MAAM,IAAI,KAAK,CACb,yDAAyD,aAAa,iBAAiB,SAAS,EAAE,CACnG,CAAC;SACH;KACF;IAED,OAAO,EAAE,OAAO,EAAE,GAAG,EAEc,CAAC;AACtC,CAAC,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,eAAe,CAC7B,IAE2C,EAC3C,UAAkB,EAClB,UAEI,EAAE,qBAAqB,EAAE,IAAS,EAAE;IAExC,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,wBAAwB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACjE,MAAM,SAAS,GAAG,gBAAgB,CAAC,GAAG,GAAG,UAAU,CAAC,CAAC;IAErD,OAAO,GAAG,OAAO,IAAI,SAAS,EAAE,CAAC;AACnC,CAAC","sourcesContent":["import { createSHA256Hash } from './encryption';\n\n/**\n * The User Storage Endpoint requires a feature name and a namespace key.\n * Developers can provide additional features and keys by extending these types below.\n *\n * Adding ALLOW_ARBITRARY_KEYS as the first key in the array allows for any key to be used for this feature.\n * This can be useful for features where keys are not deterministic (eg. accounts addresses).\n */\nconst ALLOW_ARBITRARY_KEYS = 'ALLOW_ARBITRARY_KEYS' as const;\n\nexport const USER_STORAGE_FEATURE_NAMES = {\n notifications: 'notifications',\n accounts: 'accounts_v2',\n networks: 'networks',\n addressBook: 'addressBook',\n} as const;\n\nexport type UserStorageFeatureNames =\n (typeof USER_STORAGE_FEATURE_NAMES)[keyof typeof USER_STORAGE_FEATURE_NAMES];\n\nexport const USER_STORAGE_SCHEMA = {\n [USER_STORAGE_FEATURE_NAMES.notifications]: ['notification_settings'],\n [USER_STORAGE_FEATURE_NAMES.accounts]: [ALLOW_ARBITRARY_KEYS], // keyed by account addresses\n [USER_STORAGE_FEATURE_NAMES.networks]: [ALLOW_ARBITRARY_KEYS], // keyed by chains/networks\n [USER_STORAGE_FEATURE_NAMES.addressBook]: [ALLOW_ARBITRARY_KEYS], // keyed by address_chainId\n} as const;\n\ntype UserStorageSchema = typeof USER_STORAGE_SCHEMA;\n\nexport type UserStorageFeatureKeys<Feature extends UserStorageFeatureNames> =\n UserStorageSchema[Feature][0] extends typeof ALLOW_ARBITRARY_KEYS\n ? string\n : UserStorageSchema[Feature][number];\n\ntype UserStorageFeatureAndKey = {\n feature: UserStorageFeatureNames;\n key: UserStorageFeatureKeys<UserStorageFeatureNames>;\n};\n\nexport type UserStoragePathWithFeatureOnly = UserStorageFeatureNames;\nexport type UserStoragePathWithFeatureAndKey = {\n [K in UserStorageFeatureNames]: `${K}.${UserStorageFeatureKeys<K>}`;\n}[UserStoragePathWithFeatureOnly];\n\n/**\n * The below types are mainly used for the SDK.\n * These exist so that the SDK can be used with arbitrary feature names and keys.\n *\n * We only type enforce feature names and keys when using UserStorageController.\n * This is done so we don't end up with magic strings within the applications.\n */\n\nexport type UserStorageGenericFeatureName = string;\nexport type UserStorageGenericFeatureKey = string;\nexport type UserStorageGenericPathWithFeatureAndKey =\n `${UserStorageGenericFeatureName}.${UserStorageGenericFeatureKey}`;\nexport type UserStorageGenericPathWithFeatureOnly =\n UserStorageGenericFeatureName;\n\ntype UserStorageGenericFeatureAndKey = {\n feature: UserStorageGenericFeatureName;\n key: UserStorageGenericFeatureKey;\n};\n\nexport const getFeatureAndKeyFromPath = <T extends boolean>(\n path: T extends true\n ? UserStoragePathWithFeatureAndKey\n : UserStorageGenericPathWithFeatureAndKey,\n options: {\n validateAgainstSchema: T;\n } = { validateAgainstSchema: true as T },\n): T extends true\n ? UserStorageFeatureAndKey\n : UserStorageGenericFeatureAndKey => {\n const pathRegex = /^\\w+\\.\\w+$/u;\n\n if (!pathRegex.test(path)) {\n throw new Error(\n `user-storage - path is not in the correct format. Correct format: 'feature.key'`,\n );\n }\n\n const [feature, key] = path.split('.');\n\n if (options.validateAgainstSchema) {\n const featureToValidate = feature as UserStorageFeatureNames;\n const keyToValidate = key as UserStorageFeatureKeys<\n typeof featureToValidate\n >;\n\n if (!(featureToValidate in USER_STORAGE_SCHEMA)) {\n throw new Error(\n `user-storage - invalid feature provided: ${featureToValidate}. Valid features: ${Object.keys(\n USER_STORAGE_SCHEMA,\n ).join(', ')}`,\n );\n }\n\n const validFeature = USER_STORAGE_SCHEMA[\n featureToValidate\n ] as readonly string[];\n\n if (\n !validFeature.includes(keyToValidate) &&\n !validFeature.includes(ALLOW_ARBITRARY_KEYS)\n ) {\n const validKeys = USER_STORAGE_SCHEMA[featureToValidate].join(', ');\n\n throw new Error(\n `user-storage - invalid key provided for this feature: ${keyToValidate}. Valid keys: ${validKeys}`,\n );\n }\n }\n\n return { feature, key } as T extends true\n ? UserStorageFeatureAndKey\n : UserStorageGenericFeatureAndKey;\n};\n\n/**\n * Constructs a unique entry path for a user.\n * This can be done due to the uniqueness of the storage key (no users will share the same storage key).\n * The users entry is a unique hash that cannot be reversed.\n *\n * @param path - string in the form of `${feature}.${key}` that matches schema\n * @param storageKey - users storage key\n * @param options - options object\n * @param options.validateAgainstSchema - whether to validate the path against the schema.\n * This defaults to true, and should only be set to false when using the SDK with arbitrary feature names and keys.\n * @returns path to store entry\n */\nexport function createEntryPath<T extends boolean>(\n path: T extends true\n ? UserStoragePathWithFeatureAndKey\n : UserStorageGenericPathWithFeatureAndKey,\n storageKey: string,\n options: {\n validateAgainstSchema: T;\n } = { validateAgainstSchema: true as T },\n): string {\n const { feature, key } = getFeatureAndKeyFromPath(path, options);\n const hashedKey = createSHA256Hash(key + storageKey);\n\n return `${feature}/${hashedKey}`;\n}\n"]}
1
+ {"version":3,"file":"storage-schema.mjs","sourceRoot":"","sources":["../../src/shared/storage-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,+BAAqB;AAEhD;;;GAGG;AAEH;;;GAGG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG;IACxC,aAAa,EAAE,eAAe;IAC9B,QAAQ,EAAE,aAAa;IACvB,QAAQ,EAAE,UAAU;IACpB,WAAW,EAAE,aAAa;CAC3B,CAAC;AAcF,MAAM,CAAC,MAAM,wBAAwB,GAAG,CACtC,IAA6C,EACZ,EAAE;IACnC,MAAM,SAAS,GAAG,aAAa,CAAC;IAEhC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;QACzB,MAAM,IAAI,KAAK,CACb,iFAAiF,CAClF,CAAC;KACH;IAED,MAAM,CAAC,OAAO,EAAE,GAAG,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAEvC,OAAO,EAAE,OAAO,EAAE,GAAG,EAAqC,CAAC;AAC7D,CAAC,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,UAAU,eAAe,CAC7B,IAA6C,EAC7C,UAAkB;IAElB,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,wBAAwB,CAAC,IAAI,CAAC,CAAC;IACxD,MAAM,SAAS,GAAG,gBAAgB,CAAC,GAAG,GAAG,UAAU,CAAC,CAAC;IAErD,OAAO,GAAG,OAAO,IAAI,SAAS,EAAE,CAAC;AACnC,CAAC","sourcesContent":["import { createSHA256Hash } from './encryption';\n\n/**\n * The User Storage Endpoint requires a feature name and a namespace key.\n * Any user storage path should be in the form of `feature.key`.\n */\n\n/**\n * Helper object that contains the feature names used in the controllers and SDK.\n * Developers don't need to add new feature names to this object anymore, as the schema enforcement has been deprecated.\n */\nexport const USER_STORAGE_FEATURE_NAMES = {\n notifications: 'notifications',\n accounts: 'accounts_v2',\n networks: 'networks',\n addressBook: 'addressBook',\n};\n\nexport type UserStorageGenericFeatureName = string;\nexport type UserStorageGenericFeatureKey = string;\nexport type UserStorageGenericPathWithFeatureAndKey =\n `${UserStorageGenericFeatureName}.${UserStorageGenericFeatureKey}`;\nexport type UserStorageGenericPathWithFeatureOnly =\n UserStorageGenericFeatureName;\n\ntype UserStorageGenericFeatureAndKey = {\n feature: UserStorageGenericFeatureName;\n key: UserStorageGenericFeatureKey;\n};\n\nexport const getFeatureAndKeyFromPath = (\n path: UserStorageGenericPathWithFeatureAndKey,\n): UserStorageGenericFeatureAndKey => {\n const pathRegex = /^\\w+\\.\\w+$/u;\n\n if (!pathRegex.test(path)) {\n throw new Error(\n `user-storage - path is not in the correct format. Correct format: 'feature.key'`,\n );\n }\n\n const [feature, key] = path.split('.');\n\n return { feature, key } as UserStorageGenericFeatureAndKey;\n};\n\n/**\n * Constructs a unique entry path for a user.\n * This can be done due to the uniqueness of the storage key (no users will share the same storage key).\n * The users entry is a unique hash that cannot be reversed.\n *\n * @param path - string in the form of `${feature}.${key}` that matches schema\n * @param storageKey - users storage key\n * @returns path to store entry\n */\nexport function createEntryPath(\n path: UserStorageGenericPathWithFeatureAndKey,\n storageKey: string,\n): string {\n const { feature, key } = getFeatureAndKeyFromPath(path);\n const hashedKey = createSHA256Hash(key + storageKey);\n\n return `${feature}/${hashedKey}`;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/profile-sync-controller",
3
- "version": "20.0.0-preview-988fbb56",
3
+ "version": "20.0.0-preview-afb9460",
4
4
  "description": "The profile sync helps developers synchronize data across multiple clients and devices in a privacy-preserving way. All data saved in the user storage database is encrypted client-side to preserve privacy. The user storage provides a modular design, giving developers the flexibility to construct and manage their storage spaces in a way that best suits their needs",
5
5
  "keywords": [
6
6
  "MetaMask",
@@ -1,18 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./traces.cjs"), exports);
18
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/constants/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAAyB","sourcesContent":["export * from './traces';\n"]}
@@ -1,2 +0,0 @@
1
- export * from "./traces.cjs";
2
- //# sourceMappingURL=index.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/constants/index.ts"],"names":[],"mappings":"AAAA,6BAAyB"}
@@ -1,2 +0,0 @@
1
- export * from "./traces.mjs";
2
- //# sourceMappingURL=index.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/constants/index.ts"],"names":[],"mappings":"AAAA,6BAAyB"}
@@ -1,2 +0,0 @@
1
- export * from "./traces.mjs";
2
- //# sourceMappingURL=index.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/constants/index.ts"],"names":[],"mappings":"AAAA,6BAAyB","sourcesContent":["export * from './traces';\n"]}
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TraceName = void 0;
4
- /**
5
- * Trace names for UserStorage syncing operations
6
- */
7
- exports.TraceName = {
8
- // Contact syncing traces
9
- ContactSyncFull: 'Contact Sync Full',
10
- ContactSyncSaveBatch: 'Contact Sync Save Batch',
11
- ContactSyncUpdateRemote: 'Contact Sync Update Remote',
12
- ContactSyncDeleteRemote: 'Contact Sync Delete Remote',
13
- // Account syncing traces
14
- AccountSyncFull: 'Account Sync Full',
15
- AccountSyncSaveIndividual: 'Account Sync Save Individual',
16
- };
17
- //# sourceMappingURL=traces.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"traces.cjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/constants/traces.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACU,QAAA,SAAS,GAAG;IACvB,yBAAyB;IACzB,eAAe,EAAE,mBAAmB;IACpC,oBAAoB,EAAE,yBAAyB;IAC/C,uBAAuB,EAAE,4BAA4B;IACrD,uBAAuB,EAAE,4BAA4B;IAErD,yBAAyB;IACzB,eAAe,EAAE,mBAAmB;IACpC,yBAAyB,EAAE,8BAA8B;CACjD,CAAC","sourcesContent":["/**\n * Trace names for UserStorage syncing operations\n */\nexport const TraceName = {\n // Contact syncing traces\n ContactSyncFull: 'Contact Sync Full',\n ContactSyncSaveBatch: 'Contact Sync Save Batch',\n ContactSyncUpdateRemote: 'Contact Sync Update Remote',\n ContactSyncDeleteRemote: 'Contact Sync Delete Remote',\n\n // Account syncing traces\n AccountSyncFull: 'Account Sync Full',\n AccountSyncSaveIndividual: 'Account Sync Save Individual',\n} as const;\n"]}
@@ -1,12 +0,0 @@
1
- /**
2
- * Trace names for UserStorage syncing operations
3
- */
4
- export declare const TraceName: {
5
- readonly ContactSyncFull: "Contact Sync Full";
6
- readonly ContactSyncSaveBatch: "Contact Sync Save Batch";
7
- readonly ContactSyncUpdateRemote: "Contact Sync Update Remote";
8
- readonly ContactSyncDeleteRemote: "Contact Sync Delete Remote";
9
- readonly AccountSyncFull: "Account Sync Full";
10
- readonly AccountSyncSaveIndividual: "Account Sync Save Individual";
11
- };
12
- //# sourceMappingURL=traces.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"traces.d.cts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/constants/traces.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,SAAS;;;;;;;CAUZ,CAAC"}
@@ -1,12 +0,0 @@
1
- /**
2
- * Trace names for UserStorage syncing operations
3
- */
4
- export declare const TraceName: {
5
- readonly ContactSyncFull: "Contact Sync Full";
6
- readonly ContactSyncSaveBatch: "Contact Sync Save Batch";
7
- readonly ContactSyncUpdateRemote: "Contact Sync Update Remote";
8
- readonly ContactSyncDeleteRemote: "Contact Sync Delete Remote";
9
- readonly AccountSyncFull: "Account Sync Full";
10
- readonly AccountSyncSaveIndividual: "Account Sync Save Individual";
11
- };
12
- //# sourceMappingURL=traces.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"traces.d.mts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/constants/traces.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,SAAS;;;;;;;CAUZ,CAAC"}
@@ -1,14 +0,0 @@
1
- /**
2
- * Trace names for UserStorage syncing operations
3
- */
4
- export const TraceName = {
5
- // Contact syncing traces
6
- ContactSyncFull: 'Contact Sync Full',
7
- ContactSyncSaveBatch: 'Contact Sync Save Batch',
8
- ContactSyncUpdateRemote: 'Contact Sync Update Remote',
9
- ContactSyncDeleteRemote: 'Contact Sync Delete Remote',
10
- // Account syncing traces
11
- AccountSyncFull: 'Account Sync Full',
12
- AccountSyncSaveIndividual: 'Account Sync Save Individual',
13
- };
14
- //# sourceMappingURL=traces.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"traces.mjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/constants/traces.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,yBAAyB;IACzB,eAAe,EAAE,mBAAmB;IACpC,oBAAoB,EAAE,yBAAyB;IAC/C,uBAAuB,EAAE,4BAA4B;IACrD,uBAAuB,EAAE,4BAA4B;IAErD,yBAAyB;IACzB,eAAe,EAAE,mBAAmB;IACpC,yBAAyB,EAAE,8BAA8B;CACjD,CAAC","sourcesContent":["/**\n * Trace names for UserStorage syncing operations\n */\nexport const TraceName = {\n // Contact syncing traces\n ContactSyncFull: 'Contact Sync Full',\n ContactSyncSaveBatch: 'Contact Sync Save Batch',\n ContactSyncUpdateRemote: 'Contact Sync Update Remote',\n ContactSyncDeleteRemote: 'Contact Sync Delete Remote',\n\n // Account syncing traces\n AccountSyncFull: 'Account Sync Full',\n AccountSyncSaveIndividual: 'Account Sync Save Individual',\n} as const;\n"]}