@metamask/profile-sync-controller 3.1.0 → 3.2.0
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/CHANGELOG.md +22 -1
- package/dist/controllers/authentication/services.cjs +10 -3
- package/dist/controllers/authentication/services.cjs.map +1 -1
- package/dist/controllers/authentication/services.d.cts.map +1 -1
- package/dist/controllers/authentication/services.d.mts.map +1 -1
- package/dist/controllers/authentication/services.mjs +14 -3
- package/dist/controllers/authentication/services.mjs.map +1 -1
- package/dist/controllers/user-storage/UserStorageController.cjs +39 -218
- package/dist/controllers/user-storage/UserStorageController.cjs.map +1 -1
- package/dist/controllers/user-storage/UserStorageController.d.cts +7 -2
- package/dist/controllers/user-storage/UserStorageController.d.cts.map +1 -1
- package/dist/controllers/user-storage/UserStorageController.d.mts +7 -2
- package/dist/controllers/user-storage/UserStorageController.d.mts.map +1 -1
- package/dist/controllers/user-storage/UserStorageController.mjs +36 -216
- package/dist/controllers/user-storage/UserStorageController.mjs.map +1 -1
- package/dist/controllers/user-storage/__fixtures__/mockMessenger.d.cts +1 -1
- package/dist/controllers/user-storage/__fixtures__/mockMessenger.d.mts +1 -1
- package/dist/controllers/user-storage/__fixtures__/test-utils.cjs +45 -1
- package/dist/controllers/user-storage/__fixtures__/test-utils.cjs.map +1 -1
- package/dist/controllers/user-storage/__fixtures__/test-utils.d.cts +21 -0
- package/dist/controllers/user-storage/__fixtures__/test-utils.d.cts.map +1 -1
- package/dist/controllers/user-storage/__fixtures__/test-utils.d.mts +21 -0
- package/dist/controllers/user-storage/__fixtures__/test-utils.d.mts.map +1 -1
- package/dist/controllers/user-storage/__fixtures__/test-utils.mjs +38 -0
- package/dist/controllers/user-storage/__fixtures__/test-utils.mjs.map +1 -1
- package/dist/controllers/user-storage/{__fixtures__ → account-syncing/__fixtures__}/mockAccounts.cjs +3 -3
- package/dist/controllers/user-storage/account-syncing/__fixtures__/mockAccounts.cjs.map +1 -0
- package/dist/controllers/user-storage/{__fixtures__ → account-syncing/__fixtures__}/mockAccounts.d.cts +6 -6
- package/dist/controllers/user-storage/account-syncing/__fixtures__/mockAccounts.d.cts.map +1 -0
- package/dist/controllers/user-storage/{__fixtures__ → account-syncing/__fixtures__}/mockAccounts.d.mts +6 -6
- package/dist/controllers/user-storage/account-syncing/__fixtures__/mockAccounts.d.mts.map +1 -0
- package/dist/controllers/user-storage/{__fixtures__ → account-syncing/__fixtures__}/mockAccounts.mjs +3 -4
- package/dist/controllers/user-storage/account-syncing/__fixtures__/mockAccounts.mjs.map +1 -0
- package/dist/controllers/user-storage/account-syncing/__fixtures__/test-utils.cjs +50 -0
- package/dist/controllers/user-storage/account-syncing/__fixtures__/test-utils.cjs.map +1 -0
- package/dist/controllers/user-storage/account-syncing/__fixtures__/test-utils.d.cts +85 -0
- package/dist/controllers/user-storage/account-syncing/__fixtures__/test-utils.d.cts.map +1 -0
- package/dist/controllers/user-storage/account-syncing/__fixtures__/test-utils.d.mts +85 -0
- package/dist/controllers/user-storage/account-syncing/__fixtures__/test-utils.d.mts.map +1 -0
- package/dist/controllers/user-storage/account-syncing/__fixtures__/test-utils.mjs +44 -0
- package/dist/controllers/user-storage/account-syncing/__fixtures__/test-utils.mjs.map +1 -0
- package/dist/controllers/user-storage/account-syncing/constants.cjs.map +1 -0
- package/dist/controllers/user-storage/account-syncing/constants.d.cts.map +1 -0
- package/dist/controllers/user-storage/account-syncing/constants.d.mts.map +1 -0
- package/dist/controllers/user-storage/account-syncing/constants.mjs.map +1 -0
- package/dist/controllers/user-storage/account-syncing/controller-integration.cjs +194 -0
- package/dist/controllers/user-storage/account-syncing/controller-integration.cjs.map +1 -0
- package/dist/controllers/user-storage/account-syncing/controller-integration.d.cts +31 -0
- package/dist/controllers/user-storage/account-syncing/controller-integration.d.cts.map +1 -0
- package/dist/controllers/user-storage/account-syncing/controller-integration.d.mts +31 -0
- package/dist/controllers/user-storage/account-syncing/controller-integration.d.mts.map +1 -0
- package/dist/controllers/user-storage/account-syncing/controller-integration.mjs +188 -0
- package/dist/controllers/user-storage/account-syncing/controller-integration.mjs.map +1 -0
- package/dist/controllers/user-storage/account-syncing/setup-subscriptions.cjs +35 -0
- package/dist/controllers/user-storage/account-syncing/setup-subscriptions.cjs.map +1 -0
- package/dist/controllers/user-storage/account-syncing/setup-subscriptions.d.cts +8 -0
- package/dist/controllers/user-storage/account-syncing/setup-subscriptions.d.cts.map +1 -0
- package/dist/controllers/user-storage/account-syncing/setup-subscriptions.d.mts +8 -0
- package/dist/controllers/user-storage/account-syncing/setup-subscriptions.d.mts.map +1 -0
- package/dist/controllers/user-storage/account-syncing/setup-subscriptions.mjs +31 -0
- package/dist/controllers/user-storage/account-syncing/setup-subscriptions.mjs.map +1 -0
- package/dist/controllers/user-storage/account-syncing/sync-utils.cjs +47 -0
- package/dist/controllers/user-storage/account-syncing/sync-utils.cjs.map +1 -0
- package/dist/controllers/user-storage/account-syncing/sync-utils.d.cts +20 -0
- package/dist/controllers/user-storage/account-syncing/sync-utils.d.cts.map +1 -0
- package/dist/controllers/user-storage/account-syncing/sync-utils.d.mts +20 -0
- package/dist/controllers/user-storage/account-syncing/sync-utils.d.mts.map +1 -0
- package/dist/controllers/user-storage/account-syncing/sync-utils.mjs +41 -0
- package/dist/controllers/user-storage/account-syncing/sync-utils.mjs.map +1 -0
- package/dist/controllers/user-storage/account-syncing/types.cjs +3 -0
- package/dist/controllers/user-storage/account-syncing/types.cjs.map +1 -0
- package/dist/controllers/user-storage/account-syncing/types.d.cts +26 -0
- package/dist/controllers/user-storage/account-syncing/types.d.cts.map +1 -0
- package/dist/controllers/user-storage/account-syncing/types.d.mts +26 -0
- package/dist/controllers/user-storage/account-syncing/types.d.mts.map +1 -0
- package/dist/controllers/user-storage/account-syncing/types.mjs +2 -0
- package/dist/controllers/user-storage/account-syncing/types.mjs.map +1 -0
- package/dist/controllers/user-storage/{accounts/user-storage.cjs → account-syncing/utils.cjs} +12 -2
- package/dist/controllers/user-storage/account-syncing/utils.cjs.map +1 -0
- package/dist/controllers/user-storage/account-syncing/utils.d.cts +23 -0
- package/dist/controllers/user-storage/account-syncing/utils.d.cts.map +1 -0
- package/dist/controllers/user-storage/account-syncing/utils.d.mts +23 -0
- package/dist/controllers/user-storage/account-syncing/utils.d.mts.map +1 -0
- package/dist/controllers/user-storage/{accounts/user-storage.mjs → account-syncing/utils.mjs} +10 -1
- package/dist/controllers/user-storage/account-syncing/utils.mjs.map +1 -0
- package/dist/controllers/user-storage/services.cjs +10 -10
- package/dist/controllers/user-storage/services.cjs.map +1 -1
- package/dist/controllers/user-storage/services.d.cts.map +1 -1
- package/dist/controllers/user-storage/services.d.mts.map +1 -1
- package/dist/controllers/user-storage/services.mjs +10 -10
- package/dist/controllers/user-storage/services.mjs.map +1 -1
- package/package.json +6 -5
- package/dist/controllers/user-storage/__fixtures__/mockAccounts.cjs.map +0 -1
- package/dist/controllers/user-storage/__fixtures__/mockAccounts.d.cts.map +0 -1
- package/dist/controllers/user-storage/__fixtures__/mockAccounts.d.mts.map +0 -1
- package/dist/controllers/user-storage/__fixtures__/mockAccounts.mjs.map +0 -1
- package/dist/controllers/user-storage/accounts/constants.cjs.map +0 -1
- package/dist/controllers/user-storage/accounts/constants.d.cts.map +0 -1
- package/dist/controllers/user-storage/accounts/constants.d.mts.map +0 -1
- package/dist/controllers/user-storage/accounts/constants.mjs.map +0 -1
- package/dist/controllers/user-storage/accounts/user-storage.cjs.map +0 -1
- package/dist/controllers/user-storage/accounts/user-storage.d.cts +0 -32
- package/dist/controllers/user-storage/accounts/user-storage.d.cts.map +0 -1
- package/dist/controllers/user-storage/accounts/user-storage.d.mts +0 -32
- package/dist/controllers/user-storage/accounts/user-storage.d.mts.map +0 -1
- package/dist/controllers/user-storage/accounts/user-storage.mjs.map +0 -1
- /package/dist/controllers/user-storage/{accounts → account-syncing}/constants.cjs +0 -0
- /package/dist/controllers/user-storage/{accounts → account-syncing}/constants.d.cts +0 -0
- /package/dist/controllers/user-storage/{accounts → account-syncing}/constants.d.mts +0 -0
- /package/dist/controllers/user-storage/{accounts → account-syncing}/constants.mjs +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"services.d.cts","sourceRoot":"","sources":["../../../src/controllers/user-storage/services.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,gCAAgC,EAChC,8BAA8B,EAC/B,wCAAoC;AAErC,OAAO,KAAK,EAAE,YAAY,EAAE,0CAAsC;AAIlE,eAAO,MAAM,gBAAgB,EAAE,MAAmC,CAAC;AACnE,eAAO,MAAM,qBAAqB,QAA2C,CAAC;AAE9E;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG;IAEnC,SAAS,EAAE,MAAM,CAAC;IAElB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,uCAAuC,GAAG;IAEpD,SAAS,EAAE,MAAM,CAAC;IAElB,IAAI,EAAE,MAAM,CAAC;CACd,EAAE,CAAC;AAEJ,MAAM,MAAM,sBAAsB,GAAG;IACnC,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,kBAAkB,CAAC,EAAE,YAAY,CAAC;CACnC,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG,sBAAsB,GAAG;IACxD,IAAI,EAAE,gCAAgC,CAAC;CACxC,CAAC;AAEF,MAAM,MAAM,mCAAmC,GAAG,sBAAsB,GAAG;IACzE,IAAI,EAAE,8BAA8B,CAAC;CACtC,CAAC;AAEF,MAAM,MAAM,6BAA6B,GAAG,mCAAmC,CAAC;AAEhF;;;;;GAKG;AACH,wBAAsB,cAAc,CAClC,IAAI,EAAE,kBAAkB,GACvB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"services.d.cts","sourceRoot":"","sources":["../../../src/controllers/user-storage/services.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,gCAAgC,EAChC,8BAA8B,EAC/B,wCAAoC;AAErC,OAAO,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CAkCf;AAED;;;;;;GAMG;AACH,wBAAsB,0DAA0D,CAC9E,aAAa,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,EACjC,IAAI,EAAE,6BAA6B,GAClC,OAAO,CAAC,IAAI,CAAC,CAyBf;AAED;;;;GAIG;AACH,wBAAsB,iBAAiB,CACrC,IAAI,EAAE,kBAAkB,GACvB,OAAO,CAAC,IAAI,CAAC,CAwBf;AAED;;;;;;GAMG;AACH,wBAAsB,sBAAsB,CAC1C,IAAI,EAAE,MAAM,EAAE,EACd,IAAI,EAAE,6BAA6B,GAClC,OAAO,CAAC,IAAI,CAAC,CA8Bf;AAED;;;;GAIG;AACH,wBAAsB,kCAAkC,CACtD,IAAI,EAAE,mCAAmC,GACxC,OAAO,CAAC,IAAI,CAAC,CAuBf"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"services.d.mts","sourceRoot":"","sources":["../../../src/controllers/user-storage/services.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,gCAAgC,EAChC,8BAA8B,EAC/B,wCAAoC;AAErC,OAAO,KAAK,EAAE,YAAY,EAAE,0CAAsC;AAIlE,eAAO,MAAM,gBAAgB,EAAE,MAAmC,CAAC;AACnE,eAAO,MAAM,qBAAqB,QAA2C,CAAC;AAE9E;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG;IAEnC,SAAS,EAAE,MAAM,CAAC;IAElB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,uCAAuC,GAAG;IAEpD,SAAS,EAAE,MAAM,CAAC;IAElB,IAAI,EAAE,MAAM,CAAC;CACd,EAAE,CAAC;AAEJ,MAAM,MAAM,sBAAsB,GAAG;IACnC,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,kBAAkB,CAAC,EAAE,YAAY,CAAC;CACnC,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG,sBAAsB,GAAG;IACxD,IAAI,EAAE,gCAAgC,CAAC;CACxC,CAAC;AAEF,MAAM,MAAM,mCAAmC,GAAG,sBAAsB,GAAG;IACzE,IAAI,EAAE,8BAA8B,CAAC;CACtC,CAAC;AAEF,MAAM,MAAM,6BAA6B,GAAG,mCAAmC,CAAC;AAEhF;;;;;GAKG;AACH,wBAAsB,cAAc,CAClC,IAAI,EAAE,kBAAkB,GACvB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"services.d.mts","sourceRoot":"","sources":["../../../src/controllers/user-storage/services.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,gCAAgC,EAChC,8BAA8B,EAC/B,wCAAoC;AAErC,OAAO,KAAK,EAAE,YAAY,EAAE,0CAAsC;AAIlE,eAAO,MAAM,gBAAgB,EAAE,MAAmC,CAAC;AACnE,eAAO,MAAM,qBAAqB,QAA2C,CAAC;AAE9E;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG;IAEnC,SAAS,EAAE,MAAM,CAAC;IAElB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,uCAAuC,GAAG;IAEpD,SAAS,EAAE,MAAM,CAAC;IAElB,IAAI,EAAE,MAAM,CAAC;CACd,EAAE,CAAC;AAEJ,MAAM,MAAM,sBAAsB,GAAG;IACnC,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,kBAAkB,CAAC,EAAE,YAAY,CAAC;CACnC,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG,sBAAsB,GAAG;IACxD,IAAI,EAAE,gCAAgC,CAAC;CACxC,CAAC;AAEF,MAAM,MAAM,mCAAmC,GAAG,sBAAsB,GAAG;IACzE,IAAI,EAAE,8BAA8B,CAAC;CACtC,CAAC;AAEF,MAAM,MAAM,6BAA6B,GAAG,mCAAmC,CAAC;AAEhF;;;;;GAKG;AACH,wBAAsB,cAAc,CAClC,IAAI,EAAE,kBAAkB,GACvB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAmDxB;AAED;;;;;GAKG;AACH,wBAAsB,+BAA+B,CACnD,IAAI,EAAE,mCAAmC,GACxC,OAAO,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,CA6E1B;AAED;;;;;GAKG;AACH,wBAAsB,iBAAiB,CACrC,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,kBAAkB,GACvB,OAAO,CAAC,IAAI,CAAC,CAyBf;AAED;;;;;;GAMG;AACH,wBAAsB,sBAAsB,CAC1C,IAAI,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,EACxB,IAAI,EAAE,6BAA6B,GAClC,OAAO,CAAC,IAAI,CAAC,CAkCf;AAED;;;;;;GAMG;AACH,wBAAsB,0DAA0D,CAC9E,aAAa,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,EACjC,IAAI,EAAE,6BAA6B,GAClC,OAAO,CAAC,IAAI,CAAC,CAyBf;AAED;;;;GAIG;AACH,wBAAsB,iBAAiB,CACrC,IAAI,EAAE,kBAAkB,GACvB,OAAO,CAAC,IAAI,CAAC,CAwBf;AAED;;;;;;GAMG;AACH,wBAAsB,sBAAsB,CAC1C,IAAI,EAAE,MAAM,EAAE,EACd,IAAI,EAAE,6BAA6B,GAClC,OAAO,CAAC,IAAI,CAAC,CA8Bf;AAED;;;;GAIG;AACH,wBAAsB,kCAAkC,CACtD,IAAI,EAAE,mCAAmC,GACxC,OAAO,CAAC,IAAI,CAAC,CAuBf"}
|
|
@@ -35,7 +35,7 @@ export async function getUserStorage(opts) {
|
|
|
35
35
|
return null;
|
|
36
36
|
}
|
|
37
37
|
if (userStorageResponse.status !== 200) {
|
|
38
|
-
throw new Error(
|
|
38
|
+
throw new Error(`Unable to get User Storage - HTTP ${userStorageResponse.status}`);
|
|
39
39
|
}
|
|
40
40
|
const userStorage = await userStorageResponse.json();
|
|
41
41
|
const encryptedData = userStorage?.Data ?? null;
|
|
@@ -77,7 +77,7 @@ export async function getUserStorageAllFeatureEntries(opts) {
|
|
|
77
77
|
return null;
|
|
78
78
|
}
|
|
79
79
|
if (userStorageResponse.status !== 200) {
|
|
80
|
-
throw new Error(
|
|
80
|
+
throw new Error(`Unable to get User Storage - HTTP ${userStorageResponse.status}`);
|
|
81
81
|
}
|
|
82
82
|
const userStorage = await userStorageResponse.json();
|
|
83
83
|
if (!Array.isArray(userStorage)) {
|
|
@@ -137,7 +137,7 @@ export async function upsertUserStorage(data, opts) {
|
|
|
137
137
|
body: JSON.stringify({ data: encryptedData }),
|
|
138
138
|
});
|
|
139
139
|
if (!res.ok) {
|
|
140
|
-
throw new Error(
|
|
140
|
+
throw new Error(`user-storage - unable to upsert data - HTTP ${res.status}`);
|
|
141
141
|
}
|
|
142
142
|
}
|
|
143
143
|
/**
|
|
@@ -170,7 +170,7 @@ export async function batchUpsertUserStorage(data, opts) {
|
|
|
170
170
|
body: JSON.stringify({ data: formattedData }),
|
|
171
171
|
});
|
|
172
172
|
if (!res.ok) {
|
|
173
|
-
throw new Error(
|
|
173
|
+
throw new Error(`user-storage - unable to batch upsert data - HTTP ${res.status}`);
|
|
174
174
|
}
|
|
175
175
|
}
|
|
176
176
|
/**
|
|
@@ -196,7 +196,7 @@ export async function batchUpsertUserStorageWithAlreadyHashedAndEncryptedEntries
|
|
|
196
196
|
body: JSON.stringify({ data: formattedData }),
|
|
197
197
|
});
|
|
198
198
|
if (!res.ok) {
|
|
199
|
-
throw new Error(
|
|
199
|
+
throw new Error(`user-storage - unable to batch upsert data - HTTP ${res.status}`);
|
|
200
200
|
}
|
|
201
201
|
}
|
|
202
202
|
/**
|
|
@@ -216,10 +216,10 @@ export async function deleteUserStorage(opts) {
|
|
|
216
216
|
},
|
|
217
217
|
});
|
|
218
218
|
if (userStorageResponse.status === 404) {
|
|
219
|
-
throw new Error(
|
|
219
|
+
throw new Error(`user-storage - feature/entry not found - HTTP ${userStorageResponse.status}`);
|
|
220
220
|
}
|
|
221
221
|
if (!userStorageResponse.ok) {
|
|
222
|
-
throw new Error(
|
|
222
|
+
throw new Error(`user-storage - unable to delete data - HTTP ${userStorageResponse.status}`);
|
|
223
223
|
}
|
|
224
224
|
}
|
|
225
225
|
/**
|
|
@@ -249,7 +249,7 @@ export async function batchDeleteUserStorage(data, opts) {
|
|
|
249
249
|
body: JSON.stringify({ batch_delete: encryptedData }),
|
|
250
250
|
});
|
|
251
251
|
if (!res.ok) {
|
|
252
|
-
throw new Error(
|
|
252
|
+
throw new Error(`user-storage - unable to batch delete data - HTTP ${res.status}`);
|
|
253
253
|
}
|
|
254
254
|
}
|
|
255
255
|
/**
|
|
@@ -268,10 +268,10 @@ export async function deleteUserStorageAllFeatureEntries(opts) {
|
|
|
268
268
|
},
|
|
269
269
|
});
|
|
270
270
|
if (userStorageResponse.status === 404) {
|
|
271
|
-
throw new Error(
|
|
271
|
+
throw new Error(`user-storage - feature not found - HTTP ${userStorageResponse.status}`);
|
|
272
272
|
}
|
|
273
273
|
if (!userStorageResponse.ok) {
|
|
274
|
-
throw new Error(
|
|
274
|
+
throw new Error(`user-storage - unable to delete data - HTTP ${userStorageResponse.status}`);
|
|
275
275
|
}
|
|
276
276
|
}
|
|
277
277
|
//# sourceMappingURL=services.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"services.mjs","sourceRoot":"","sources":["../../../src/controllers/user-storage/services.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,IAAG,iBAAiB;;AAE3B,OAAO,UAAU,EAAE,EAAE,gBAAgB,EAAE,0CAAgC;AACvE,OAAO,EAAE,WAAW,EAAE,8CAA0C;AAChE,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,6BAAyB;AAKnD,OAAO,EAAE,eAAe,EAAE,wCAAoC;AAG9D,MAAM,QAAQ,GAAG,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAErC,MAAM,CAAC,MAAM,gBAAgB,GAAW,QAAQ,CAAC,iBAAiB,CAAC;AACnE,MAAM,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I,KAAK,CAAC,4CAA4C,CAAC,CAAC;KAC/D;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,kCAAkC,CACtD,IAAyC;IAEzC,MAAM,EAAE,WAAW,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC;IACnC,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,GAAG,qBAAqB,IAAI,IAAI,EAAE,CAAC,CAAC;IAExD,MAAM,mBAAmB,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE;QACtD,MAAM,EAAE,QAAQ;QAChB,OAAO,EAAE;YACP,cAAc,EAAE,kBAAkB;YAClC,aAAa,EAAE,UAAU,WAAW,EAAE;SACvC;KACF,CAAC,CAAC;IAEH,IAAI,mBAAmB,CAAC,MAAM,KAAK,GAAG,EAAE;QACtC,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;KACrD;IAED,IAAI,CAAC,mBAAmB,CAAC,EAAE,EAAE;QAC3B,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;KACzD;AACH,CAAC","sourcesContent":["import log from 'loglevel';\n\nimport encryption, { createSHA256Hash } from '../../shared/encryption';\nimport { SHARED_SALT } from '../../shared/encryption/constants';\nimport { Env, getEnvUrls } from '../../shared/env';\nimport type {\n UserStoragePathWithFeatureAndKey,\n UserStoragePathWithFeatureOnly,\n} from '../../shared/storage-schema';\nimport { createEntryPath } from '../../shared/storage-schema';\nimport type { NativeScrypt } from '../../shared/types/encryption';\n\nconst ENV_URLS = getEnvUrls(Env.PRD);\n\nexport const USER_STORAGE_API: string = ENV_URLS.userStorageApiUrl;\nexport const USER_STORAGE_ENDPOINT = `${USER_STORAGE_API}/api/v1/userstorage`;\n\n/**\n * This is the Server Response shape for a feature entry.\n */\nexport type GetUserStorageResponse = {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n HashedKey: string;\n // eslint-disable-next-line @typescript-eslint/naming-convention\n Data: string;\n};\n\nexport type GetUserStorageAllFeatureEntriesResponse = {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n HashedKey: string;\n // eslint-disable-next-line @typescript-eslint/naming-convention\n Data: string;\n}[];\n\nexport type UserStorageBaseOptions = {\n bearerToken: string;\n storageKey: string;\n nativeScryptCrypto?: NativeScrypt;\n};\n\nexport type UserStorageOptions = UserStorageBaseOptions & {\n path: UserStoragePathWithFeatureAndKey;\n};\n\nexport type UserStorageAllFeatureEntriesOptions = UserStorageBaseOptions & {\n path: UserStoragePathWithFeatureOnly;\n};\n\nexport type UserStorageBatchUpsertOptions = UserStorageAllFeatureEntriesOptions;\n\n/**\n * User Storage Service - Get Storage Entry.\n *\n * @param opts - User Storage Options\n * @returns The storage entry, or null if fails to find entry\n */\nexport async function getUserStorage(\n opts: UserStorageOptions,\n): Promise<string | null> {\n try {\n const { bearerToken, path, storageKey, nativeScryptCrypto } = opts;\n\n const encryptedPath = createEntryPath(path, storageKey);\n const url = new URL(`${USER_STORAGE_ENDPOINT}/${encryptedPath}`);\n\n const userStorageResponse = await fetch(url.toString(), {\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${bearerToken}`,\n },\n });\n\n // Acceptable error - since indicates entry does not exist.\n if (userStorageResponse.status === 404) {\n return null;\n }\n\n if (userStorageResponse.status !== 200) {\n throw new Error('Unable to get User Storage');\n }\n\n const userStorage: GetUserStorageResponse | null =\n await userStorageResponse.json();\n const encryptedData = userStorage?.Data ?? null;\n\n /* istanbul ignore if - this is an edge case where our endpoint returns invalid JSON payload */\n if (!encryptedData) {\n return null;\n }\n\n const decryptedData = await encryption.decryptString(\n encryptedData,\n opts.storageKey,\n nativeScryptCrypto,\n );\n\n // Re-encrypt and re-upload the entry if the salt is random\n const salt = encryption.getSalt(encryptedData);\n if (salt.toString() !== SHARED_SALT.toString()) {\n await upsertUserStorage(decryptedData, opts);\n }\n\n return decryptedData;\n } catch (e) {\n log.error('Failed to get user storage', e);\n return null;\n }\n}\n\n/**\n * User Storage Service - Get all storage entries for a specific feature.\n *\n * @param opts - User Storage Options\n * @returns The storage entry, or null if fails to find entry\n */\nexport async function getUserStorageAllFeatureEntries(\n opts: UserStorageAllFeatureEntriesOptions,\n): Promise<string[] | null> {\n try {\n const { bearerToken, path, nativeScryptCrypto } = opts;\n const url = new URL(`${USER_STORAGE_ENDPOINT}/${path}`);\n\n const userStorageResponse = await fetch(url.toString(), {\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${bearerToken}`,\n },\n });\n\n // Acceptable error - since indicates feature does not exist.\n if (userStorageResponse.status === 404) {\n return null;\n }\n\n if (userStorageResponse.status !== 200) {\n throw new Error('Unable to get User Storage');\n }\n\n const userStorage: GetUserStorageAllFeatureEntriesResponse | null =\n await userStorageResponse.json();\n\n if (!Array.isArray(userStorage)) {\n return null;\n }\n\n const decryptedData: string[] = [];\n const reEncryptedEntries: [string, string][] = [];\n\n for (const entry of userStorage) {\n /* istanbul ignore if - unreachable if statement, but kept as edge case */\n if (!entry.Data) {\n continue;\n }\n\n try {\n const data = await encryption.decryptString(\n entry.Data,\n opts.storageKey,\n nativeScryptCrypto,\n );\n decryptedData.push(data);\n\n // Re-encrypt the entry if the salt is different from the shared one\n const salt = encryption.getSalt(entry.Data);\n if (salt.toString() !== SHARED_SALT.toString()) {\n reEncryptedEntries.push([\n entry.HashedKey,\n await encryption.encryptString(\n data,\n opts.storageKey,\n nativeScryptCrypto,\n ),\n ]);\n }\n } catch {\n // do nothing\n }\n }\n\n // Re-upload the re-encrypted entries\n if (reEncryptedEntries.length) {\n await batchUpsertUserStorageWithAlreadyHashedAndEncryptedEntries(\n reEncryptedEntries,\n opts,\n );\n }\n\n return decryptedData;\n } catch (e) {\n log.error('Failed to get user storage', e);\n return null;\n }\n}\n\n/**\n * User Storage Service - Set Storage Entry.\n *\n * @param data - data to store\n * @param opts - storage options\n */\nexport async function upsertUserStorage(\n data: string,\n opts: UserStorageOptions,\n): Promise<void> {\n const { bearerToken, path, storageKey, nativeScryptCrypto } = opts;\n\n const encryptedData = await encryption.encryptString(\n data,\n opts.storageKey,\n nativeScryptCrypto,\n );\n const encryptedPath = createEntryPath(path, storageKey);\n const url = new URL(`${USER_STORAGE_ENDPOINT}/${encryptedPath}`);\n\n const res = await fetch(url.toString(), {\n method: 'PUT',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${bearerToken}`,\n },\n body: JSON.stringify({ data: encryptedData }),\n });\n\n if (!res.ok) {\n throw new Error('user-storage - unable to upsert data');\n }\n}\n\n/**\n * User Storage Service - Set multiple storage entries for one specific feature.\n * You cannot use this method to set multiple features at once.\n *\n * @param data - data to store, in the form of an array of [entryKey, entryValue] pairs\n * @param opts - storage options\n */\nexport async function batchUpsertUserStorage(\n data: [string, string][],\n opts: UserStorageBatchUpsertOptions,\n): Promise<void> {\n if (!data.length) {\n return;\n }\n\n const { bearerToken, path, storageKey, nativeScryptCrypto } = opts;\n\n const encryptedData: string[][] = [];\n\n for (const d of data) {\n encryptedData.push([\n createSHA256Hash(d[0] + storageKey),\n await encryption.encryptString(d[1], opts.storageKey, nativeScryptCrypto),\n ]);\n }\n\n const url = new URL(`${USER_STORAGE_ENDPOINT}/${path}`);\n\n const formattedData = Object.fromEntries(encryptedData);\n\n const res = await fetch(url.toString(), {\n method: 'PUT',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${bearerToken}`,\n },\n body: JSON.stringify({ data: formattedData }),\n });\n\n if (!res.ok) {\n throw new Error('user-storage - unable to batch upsert data');\n }\n}\n\n/**\n * User Storage Service - Set multiple storage entries for one specific feature.\n * You cannot use this method to set multiple features at once.\n *\n * @param encryptedData - data to store, in the form of an array of [hashedKey, encryptedData] pairs\n * @param opts - storage options\n */\nexport async function batchUpsertUserStorageWithAlreadyHashedAndEncryptedEntries(\n encryptedData: [string, string][],\n opts: UserStorageBatchUpsertOptions,\n): Promise<void> {\n if (!encryptedData.length) {\n return;\n }\n\n const { bearerToken, path } = opts;\n\n const url = new URL(`${USER_STORAGE_ENDPOINT}/${path}`);\n\n const formattedData = Object.fromEntries(encryptedData);\n\n const res = await fetch(url.toString(), {\n method: 'PUT',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${bearerToken}`,\n },\n body: JSON.stringify({ data: formattedData }),\n });\n\n if (!res.ok) {\n throw new Error('user-storage - unable to batch upsert data');\n }\n}\n\n/**\n * User Storage Service - Delete Storage Entry.\n *\n * @param opts - User Storage Options\n */\nexport async function deleteUserStorage(\n opts: UserStorageOptions,\n): Promise<void> {\n const { bearerToken, path, storageKey } = opts;\n const encryptedPath = createEntryPath(path, storageKey);\n const url = new URL(`${USER_STORAGE_ENDPOINT}/${encryptedPath}`);\n\n const userStorageResponse = await fetch(url.toString(), {\n method: 'DELETE',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${bearerToken}`,\n },\n });\n\n if (userStorageResponse.status === 404) {\n throw new Error('user-storage - feature/entry not found');\n }\n\n if (!userStorageResponse.ok) {\n throw new Error('user-storage - unable to delete data');\n }\n}\n\n/**\n * User Storage Service - Delete multiple storage entries for one specific feature.\n * You cannot use this method to delete multiple features at once.\n *\n * @param data - data to delete, in the form of an array entryKey[]\n * @param opts - storage options\n */\nexport async function batchDeleteUserStorage(\n data: string[],\n opts: UserStorageBatchUpsertOptions,\n): Promise<void> {\n if (!data.length) {\n return;\n }\n\n const { bearerToken, path, storageKey } = opts;\n\n const encryptedData: string[] = [];\n\n for (const d of data) {\n encryptedData.push(createSHA256Hash(d + storageKey));\n }\n\n const url = new URL(`${USER_STORAGE_ENDPOINT}/${path}`);\n\n const res = await fetch(url.toString(), {\n method: 'PUT',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${bearerToken}`,\n },\n // eslint-disable-next-line @typescript-eslint/naming-convention\n body: JSON.stringify({ batch_delete: encryptedData }),\n });\n\n if (!res.ok) {\n throw new Error('user-storage - unable to batch delete data');\n }\n}\n\n/**\n * User Storage Service - Delete all storage entries for a specific feature.\n *\n * @param opts - User Storage Options\n */\nexport async function deleteUserStorageAllFeatureEntries(\n opts: UserStorageAllFeatureEntriesOptions,\n): Promise<void> {\n const { bearerToken, path } = opts;\n const url = new URL(`${USER_STORAGE_ENDPOINT}/${path}`);\n\n const userStorageResponse = await fetch(url.toString(), {\n method: 'DELETE',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${bearerToken}`,\n },\n });\n\n if (userStorageResponse.status === 404) {\n throw new Error('user-storage - feature not found');\n }\n\n if (!userStorageResponse.ok) {\n throw new Error('user-storage - unable to delete data');\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"services.mjs","sourceRoot":"","sources":["../../../src/controllers/user-storage/services.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,IAAG,iBAAiB;;AAE3B,OAAO,UAAU,EAAE,EAAE,gBAAgB,EAAE,0CAAgC;AACvE,OAAO,EAAE,WAAW,EAAE,8CAA0C;AAChE,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,6BAAyB;AAKnD,OAAO,EAAE,eAAe,EAAE,wCAAoC;AAG9D,MAAM,QAAQ,GAAG,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAErC,MAAM,CAAC,MAAM,gBAAgB,GAAW,QAAQ,CAAC,iBAAiB,CAAC;AACnE,MAAM,CAAC,MAAM,qBAAqB,GAAG,GAAG,gBAAgB,qBAAqB,CAAC;AAmC9E;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,IAAwB;IAExB,IAAI;QACF,MAAM,EAAE,WAAW,EAAE,IAAI,EAAE,UAAU,EAAE,kBAAkB,EAAE,GAAG,IAAI,CAAC;QAEnE,MAAM,aAAa,GAAG,eAAe,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;QACxD,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,GAAG,qBAAqB,IAAI,aAAa,EAAE,CAAC,CAAC;QAEjE,MAAM,mBAAmB,GAAG,MAAM,KAAK,CAAC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I,IAAI,EAAE,CAAC,CAAC;IAExD,MAAM,mBAAmB,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE;QACtD,MAAM,EAAE,QAAQ;QAChB,OAAO,EAAE;YACP,cAAc,EAAE,kBAAkB;YAClC,aAAa,EAAE,UAAU,WAAW,EAAE;SACvC;KACF,CAAC,CAAC;IAEH,IAAI,mBAAmB,CAAC,MAAM,KAAK,GAAG,EAAE;QACtC,MAAM,IAAI,KAAK,CACb,2CAA2C,mBAAmB,CAAC,MAAM,EAAE,CACxE,CAAC;KACH;IAED,IAAI,CAAC,mBAAmB,CAAC,EAAE,EAAE;QAC3B,MAAM,IAAI,KAAK,CACb,+CAA+C,mBAAmB,CAAC,MAAM,EAAE,CAC5E,CAAC;KACH;AACH,CAAC","sourcesContent":["import log from 'loglevel';\n\nimport encryption, { createSHA256Hash } from '../../shared/encryption';\nimport { SHARED_SALT } from '../../shared/encryption/constants';\nimport { Env, getEnvUrls } from '../../shared/env';\nimport type {\n UserStoragePathWithFeatureAndKey,\n UserStoragePathWithFeatureOnly,\n} from '../../shared/storage-schema';\nimport { createEntryPath } from '../../shared/storage-schema';\nimport type { NativeScrypt } from '../../shared/types/encryption';\n\nconst ENV_URLS = getEnvUrls(Env.PRD);\n\nexport const USER_STORAGE_API: string = ENV_URLS.userStorageApiUrl;\nexport const USER_STORAGE_ENDPOINT = `${USER_STORAGE_API}/api/v1/userstorage`;\n\n/**\n * This is the Server Response shape for a feature entry.\n */\nexport type GetUserStorageResponse = {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n HashedKey: string;\n // eslint-disable-next-line @typescript-eslint/naming-convention\n Data: string;\n};\n\nexport type GetUserStorageAllFeatureEntriesResponse = {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n HashedKey: string;\n // eslint-disable-next-line @typescript-eslint/naming-convention\n Data: string;\n}[];\n\nexport type UserStorageBaseOptions = {\n bearerToken: string;\n storageKey: string;\n nativeScryptCrypto?: NativeScrypt;\n};\n\nexport type UserStorageOptions = UserStorageBaseOptions & {\n path: UserStoragePathWithFeatureAndKey;\n};\n\nexport type UserStorageAllFeatureEntriesOptions = UserStorageBaseOptions & {\n path: UserStoragePathWithFeatureOnly;\n};\n\nexport type UserStorageBatchUpsertOptions = UserStorageAllFeatureEntriesOptions;\n\n/**\n * User Storage Service - Get Storage Entry.\n *\n * @param opts - User Storage Options\n * @returns The storage entry, or null if fails to find entry\n */\nexport async function getUserStorage(\n opts: UserStorageOptions,\n): Promise<string | null> {\n try {\n const { bearerToken, path, storageKey, nativeScryptCrypto } = opts;\n\n const encryptedPath = createEntryPath(path, storageKey);\n const url = new URL(`${USER_STORAGE_ENDPOINT}/${encryptedPath}`);\n\n const userStorageResponse = await fetch(url.toString(), {\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${bearerToken}`,\n },\n });\n\n // Acceptable error - since indicates entry does not exist.\n if (userStorageResponse.status === 404) {\n return null;\n }\n\n if (userStorageResponse.status !== 200) {\n throw new Error(\n `Unable to get User Storage - HTTP ${userStorageResponse.status}`,\n );\n }\n\n const userStorage: GetUserStorageResponse | null =\n await userStorageResponse.json();\n const encryptedData = userStorage?.Data ?? null;\n\n /* istanbul ignore if - this is an edge case where our endpoint returns invalid JSON payload */\n if (!encryptedData) {\n return null;\n }\n\n const decryptedData = await encryption.decryptString(\n encryptedData,\n opts.storageKey,\n nativeScryptCrypto,\n );\n\n // Re-encrypt and re-upload the entry if the salt is random\n const salt = encryption.getSalt(encryptedData);\n if (salt.toString() !== SHARED_SALT.toString()) {\n await upsertUserStorage(decryptedData, opts);\n }\n\n return decryptedData;\n } catch (e) {\n log.error('Failed to get user storage', e);\n return null;\n }\n}\n\n/**\n * User Storage Service - Get all storage entries for a specific feature.\n *\n * @param opts - User Storage Options\n * @returns The storage entry, or null if fails to find entry\n */\nexport async function getUserStorageAllFeatureEntries(\n opts: UserStorageAllFeatureEntriesOptions,\n): Promise<string[] | null> {\n try {\n const { bearerToken, path, nativeScryptCrypto } = opts;\n const url = new URL(`${USER_STORAGE_ENDPOINT}/${path}`);\n\n const userStorageResponse = await fetch(url.toString(), {\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${bearerToken}`,\n },\n });\n\n // Acceptable error - since indicates feature does not exist.\n if (userStorageResponse.status === 404) {\n return null;\n }\n\n if (userStorageResponse.status !== 200) {\n throw new Error(\n `Unable to get User Storage - HTTP ${userStorageResponse.status}`,\n );\n }\n\n const userStorage: GetUserStorageAllFeatureEntriesResponse | null =\n await userStorageResponse.json();\n\n if (!Array.isArray(userStorage)) {\n return null;\n }\n\n const decryptedData: string[] = [];\n const reEncryptedEntries: [string, string][] = [];\n\n for (const entry of userStorage) {\n /* istanbul ignore if - unreachable if statement, but kept as edge case */\n if (!entry.Data) {\n continue;\n }\n\n try {\n const data = await encryption.decryptString(\n entry.Data,\n opts.storageKey,\n nativeScryptCrypto,\n );\n decryptedData.push(data);\n\n // Re-encrypt the entry if the salt is different from the shared one\n const salt = encryption.getSalt(entry.Data);\n if (salt.toString() !== SHARED_SALT.toString()) {\n reEncryptedEntries.push([\n entry.HashedKey,\n await encryption.encryptString(\n data,\n opts.storageKey,\n nativeScryptCrypto,\n ),\n ]);\n }\n } catch {\n // do nothing\n }\n }\n\n // Re-upload the re-encrypted entries\n if (reEncryptedEntries.length) {\n await batchUpsertUserStorageWithAlreadyHashedAndEncryptedEntries(\n reEncryptedEntries,\n opts,\n );\n }\n\n return decryptedData;\n } catch (e) {\n log.error('Failed to get user storage', e);\n return null;\n }\n}\n\n/**\n * User Storage Service - Set Storage Entry.\n *\n * @param data - data to store\n * @param opts - storage options\n */\nexport async function upsertUserStorage(\n data: string,\n opts: UserStorageOptions,\n): Promise<void> {\n const { bearerToken, path, storageKey, nativeScryptCrypto } = opts;\n\n const encryptedData = await encryption.encryptString(\n data,\n opts.storageKey,\n nativeScryptCrypto,\n );\n const encryptedPath = createEntryPath(path, storageKey);\n const url = new URL(`${USER_STORAGE_ENDPOINT}/${encryptedPath}`);\n\n const res = await fetch(url.toString(), {\n method: 'PUT',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${bearerToken}`,\n },\n body: JSON.stringify({ data: encryptedData }),\n });\n\n if (!res.ok) {\n throw new Error(\n `user-storage - unable to upsert data - HTTP ${res.status}`,\n );\n }\n}\n\n/**\n * User Storage Service - Set multiple storage entries for one specific feature.\n * You cannot use this method to set multiple features at once.\n *\n * @param data - data to store, in the form of an array of [entryKey, entryValue] pairs\n * @param opts - storage options\n */\nexport async function batchUpsertUserStorage(\n data: [string, string][],\n opts: UserStorageBatchUpsertOptions,\n): Promise<void> {\n if (!data.length) {\n return;\n }\n\n const { bearerToken, path, storageKey, nativeScryptCrypto } = opts;\n\n const encryptedData: string[][] = [];\n\n for (const d of data) {\n encryptedData.push([\n createSHA256Hash(d[0] + storageKey),\n await encryption.encryptString(d[1], opts.storageKey, nativeScryptCrypto),\n ]);\n }\n\n const url = new URL(`${USER_STORAGE_ENDPOINT}/${path}`);\n\n const formattedData = Object.fromEntries(encryptedData);\n\n const res = await fetch(url.toString(), {\n method: 'PUT',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${bearerToken}`,\n },\n body: JSON.stringify({ data: formattedData }),\n });\n\n if (!res.ok) {\n throw new Error(\n `user-storage - unable to batch upsert data - HTTP ${res.status}`,\n );\n }\n}\n\n/**\n * User Storage Service - Set multiple storage entries for one specific feature.\n * You cannot use this method to set multiple features at once.\n *\n * @param encryptedData - data to store, in the form of an array of [hashedKey, encryptedData] pairs\n * @param opts - storage options\n */\nexport async function batchUpsertUserStorageWithAlreadyHashedAndEncryptedEntries(\n encryptedData: [string, string][],\n opts: UserStorageBatchUpsertOptions,\n): Promise<void> {\n if (!encryptedData.length) {\n return;\n }\n\n const { bearerToken, path } = opts;\n\n const url = new URL(`${USER_STORAGE_ENDPOINT}/${path}`);\n\n const formattedData = Object.fromEntries(encryptedData);\n\n const res = await fetch(url.toString(), {\n method: 'PUT',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${bearerToken}`,\n },\n body: JSON.stringify({ data: formattedData }),\n });\n\n if (!res.ok) {\n throw new Error(\n `user-storage - unable to batch upsert data - HTTP ${res.status}`,\n );\n }\n}\n\n/**\n * User Storage Service - Delete Storage Entry.\n *\n * @param opts - User Storage Options\n */\nexport async function deleteUserStorage(\n opts: UserStorageOptions,\n): Promise<void> {\n const { bearerToken, path, storageKey } = opts;\n const encryptedPath = createEntryPath(path, storageKey);\n const url = new URL(`${USER_STORAGE_ENDPOINT}/${encryptedPath}`);\n\n const userStorageResponse = await fetch(url.toString(), {\n method: 'DELETE',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${bearerToken}`,\n },\n });\n\n if (userStorageResponse.status === 404) {\n throw new Error(\n `user-storage - feature/entry not found - HTTP ${userStorageResponse.status}`,\n );\n }\n\n if (!userStorageResponse.ok) {\n throw new Error(\n `user-storage - unable to delete data - HTTP ${userStorageResponse.status}`,\n );\n }\n}\n\n/**\n * User Storage Service - Delete multiple storage entries for one specific feature.\n * You cannot use this method to delete multiple features at once.\n *\n * @param data - data to delete, in the form of an array entryKey[]\n * @param opts - storage options\n */\nexport async function batchDeleteUserStorage(\n data: string[],\n opts: UserStorageBatchUpsertOptions,\n): Promise<void> {\n if (!data.length) {\n return;\n }\n\n const { bearerToken, path, storageKey } = opts;\n\n const encryptedData: string[] = [];\n\n for (const d of data) {\n encryptedData.push(createSHA256Hash(d + storageKey));\n }\n\n const url = new URL(`${USER_STORAGE_ENDPOINT}/${path}`);\n\n const res = await fetch(url.toString(), {\n method: 'PUT',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${bearerToken}`,\n },\n // eslint-disable-next-line @typescript-eslint/naming-convention\n body: JSON.stringify({ batch_delete: encryptedData }),\n });\n\n if (!res.ok) {\n throw new Error(\n `user-storage - unable to batch delete data - HTTP ${res.status}`,\n );\n }\n}\n\n/**\n * User Storage Service - Delete all storage entries for a specific feature.\n *\n * @param opts - User Storage Options\n */\nexport async function deleteUserStorageAllFeatureEntries(\n opts: UserStorageAllFeatureEntriesOptions,\n): Promise<void> {\n const { bearerToken, path } = opts;\n const url = new URL(`${USER_STORAGE_ENDPOINT}/${path}`);\n\n const userStorageResponse = await fetch(url.toString(), {\n method: 'DELETE',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${bearerToken}`,\n },\n });\n\n if (userStorageResponse.status === 404) {\n throw new Error(\n `user-storage - feature not found - HTTP ${userStorageResponse.status}`,\n );\n }\n\n if (!userStorageResponse.ok) {\n throw new Error(\n `user-storage - unable to delete data - HTTP ${userStorageResponse.status}`,\n );\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/profile-sync-controller",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0",
|
|
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",
|
|
@@ -100,9 +100,9 @@
|
|
|
100
100
|
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
|
|
101
101
|
},
|
|
102
102
|
"dependencies": {
|
|
103
|
-
"@metamask/base-controller": "^7.0
|
|
104
|
-
"@metamask/keyring-api": "^
|
|
105
|
-
"@metamask/keyring-controller": "^19.0.
|
|
103
|
+
"@metamask/base-controller": "^7.1.0",
|
|
104
|
+
"@metamask/keyring-api": "^12.0.0",
|
|
105
|
+
"@metamask/keyring-controller": "^19.0.2",
|
|
106
106
|
"@metamask/network-controller": "^22.1.1",
|
|
107
107
|
"@metamask/snaps-sdk": "^6.7.0",
|
|
108
108
|
"@metamask/snaps-utils": "^8.3.0",
|
|
@@ -115,8 +115,9 @@
|
|
|
115
115
|
"devDependencies": {
|
|
116
116
|
"@lavamoat/allow-scripts": "^3.0.4",
|
|
117
117
|
"@lavamoat/preinstall-always-fail": "^2.1.0",
|
|
118
|
-
"@metamask/accounts-controller": "^20.0.
|
|
118
|
+
"@metamask/accounts-controller": "^20.0.2",
|
|
119
119
|
"@metamask/auto-changelog": "^3.4.4",
|
|
120
|
+
"@metamask/keyring-internal-api": "^1.0.0",
|
|
120
121
|
"@metamask/providers": "^18.1.1",
|
|
121
122
|
"@metamask/snaps-controllers": "^9.10.0",
|
|
122
123
|
"@types/jest": "^27.4.1",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mockAccounts.cjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/__fixtures__/mockAccounts.ts"],"names":[],"mappings":";;;AAAA,uDAA6E;AAC7E,qEAA4D;AAE5D,yDAAwE;AACxE,+DAAkF;AAElF;;;;;GAKG;AACH,MAAM,gDAAgD,GAAG,CACvD,gBAAmC,EACnC,EAAE,CAAC,gBAAgB,CAAC,GAAG,CAAC,qDAAsC,CAAC,CAAC;AAElE;;;GAGG;AACI,MAAM,+BAA+B,GAAG,GAAG,EAAE,CAClD,2CAA+B,CAC7B,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,2CAA+B,CAAC,MAAM,CAAC,CACnE,CAAC;AAHS,QAAA,+BAA+B,mCAGxC;AAES,QAAA,sBAAsB,GAAG;IACpC,KAAK,EAAE,EAAE;IACT,GAAG,EAAE;QACH;YACE,OAAO,EAAE,OAAO;YAChB,EAAE,EAAE,GAAG;YACP,IAAI,EAAE,4BAAc,CAAC,GAAG;YACxB,QAAQ,EAAE;gBACR,IAAI,EAAE,MAAM;gBACZ,iBAAiB,EAAE,CAAC;gBACpB,OAAO,EAAE;oBACP,IAAI,EAAE,iCAAY,CAAC,EAAE;iBACtB;aACF;SACF;KACF;IACD,gBAAgB,EAAE;QAChB;YACE,OAAO,EAAE,OAAO;YAChB,EAAE,E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;QAC/C;YACE,GAAG,8BAAsB,CAAC,oCAAoC,CAAC,CAAC,CAAC;YACjE,QAAQ,EAAE;gBACR,IAAI,EAAE,4DAA4D;aACnE;SACF;KACmB,CAAC;IACzB,iCAAiC,EAC/B,gDAAgD,CAAC;QAC/C;YACE,GAAG,8BAAsB,CAAC,oCAAoC,CAAC,CAAC,CAAC;YACjE,QAAQ,EAAE;gBACR,IAAI,EAAE,yDAAyD;gBAC/D,iBAAiB,EAAE,CAAC;aACrB;SACF;KACmB,CAAC;CAC1B,CAAC","sourcesContent":["import { EthAccountType, type InternalAccount } from '@metamask/keyring-api';\nimport { KeyringTypes } from '@metamask/keyring-controller';\n\nimport { LOCALIZED_DEFAULT_ACCOUNT_NAMES } from '../accounts/constants';\nimport { mapInternalAccountToUserStorageAccount } from '../accounts/user-storage';\n\n/**\n * Map an array of internal accounts to an array of user storage accounts\n * Only used for testing purposes\n * @param internalAccounts - An array of internal accounts\n * @returns An array of user storage accounts\n */\nconst mapInternalAccountsListToUserStorageAccountsList = (\n internalAccounts: InternalAccount[],\n) => internalAccounts.map(mapInternalAccountToUserStorageAccount);\n\n/**\n * Get a random default account name from the list of localized default account names\n * @returns A random default account name\n */\nexport const getMockRandomDefaultAccountName = () =>\n LOCALIZED_DEFAULT_ACCOUNT_NAMES[\n Math.floor(Math.random() * LOCALIZED_DEFAULT_ACCOUNT_NAMES.length)\n ];\n\nexport const MOCK_INTERNAL_ACCOUNTS = {\n EMPTY: [],\n ONE: [\n {\n address: '0x123',\n id: '1',\n type: EthAccountType.Eoa,\n metadata: {\n name: 'test',\n nameLastUpdatedAt: 1,\n keyring: {\n type: KeyringTypes.hd,\n },\n },\n },\n ],\n ONE_DEFAULT_NAME: [\n {\n address: '0x123',\n id: '1',\n type: EthAccountType.Eoa,\n metadata: {\n name: `${getMockRandomDefaultAccountName()} 1`,\n nameLastUpdatedAt: 1,\n keyring: {\n type: KeyringTypes.hd,\n },\n },\n },\n ],\n ONE_CUSTOM_NAME_WITHOUT_LAST_UPDATED: [\n {\n address: '0x123',\n id: '1',\n type: EthAccountType.Eoa,\n metadata: {\n name: 'Internal account custom name without nameLastUpdatedAt',\n keyring: {\n type: KeyringTypes.hd,\n },\n },\n },\n ],\n ONE_CUSTOM_NAME_WITH_LAST_UPDATED: [\n {\n address: '0x123',\n id: '1',\n type: EthAccountType.Eoa,\n metadata: {\n name: 'Internal account custom name with nameLastUpdatedAt',\n nameLastUpdatedAt: 1,\n keyring: {\n type: KeyringTypes.hd,\n },\n },\n },\n ],\n ONE_CUSTOM_NAME_WITH_LAST_UPDATED_MOST_RECENT: [\n {\n address: '0x123',\n id: '1',\n type: EthAccountType.Eoa,\n metadata: {\n name: 'Internal account custom name with nameLastUpdatedAt',\n nameLastUpdatedAt: 9999,\n keyring: {\n type: KeyringTypes.hd,\n },\n },\n },\n ],\n ALL: [\n {\n address: '0x123',\n id: '1',\n type: EthAccountType.Eoa,\n metadata: {\n name: 'test',\n nameLastUpdatedAt: 1,\n keyring: {\n type: KeyringTypes.hd,\n },\n },\n },\n {\n address: '0x456',\n id: '2',\n type: EthAccountType.Eoa,\n metadata: {\n name: 'Account 2',\n nameLastUpdatedAt: 2,\n keyring: {\n type: KeyringTypes.hd,\n },\n },\n },\n {\n address: '0x789',\n id: '3',\n type: EthAccountType.Eoa,\n metadata: {\n name: 'Účet 2',\n nameLastUpdatedAt: 3,\n keyring: {\n type: KeyringTypes.hd,\n },\n },\n },\n {\n address: '0xabc',\n id: '4',\n type: EthAccountType.Eoa,\n metadata: {\n name: 'My Account 4',\n nameLastUpdatedAt: 4,\n keyring: {\n type: KeyringTypes.hd,\n },\n },\n },\n ],\n};\n\nexport const MOCK_USER_STORAGE_ACCOUNTS = {\n SAME_AS_INTERNAL_ALL: mapInternalAccountsListToUserStorageAccountsList(\n MOCK_INTERNAL_ACCOUNTS.ALL as InternalAccount[],\n ),\n ONE: mapInternalAccountsListToUserStorageAccountsList(\n MOCK_INTERNAL_ACCOUNTS.ONE as InternalAccount[],\n ),\n TWO_DEFAULT_NAMES_WITH_ONE_BOGUS:\n mapInternalAccountsListToUserStorageAccountsList([\n ...MOCK_INTERNAL_ACCOUNTS.ONE_DEFAULT_NAME,\n {\n ...MOCK_INTERNAL_ACCOUNTS.ONE_DEFAULT_NAME[0],\n address: '0x000000',\n metadata: {\n name: `${getMockRandomDefaultAccountName()} 1`,\n nameLastUpdatedAt: 2,\n },\n },\n ] as InternalAccount[]),\n ONE_DEFAULT_NAME: mapInternalAccountsListToUserStorageAccountsList(\n MOCK_INTERNAL_ACCOUNTS.ONE_DEFAULT_NAME as InternalAccount[],\n ),\n ONE_CUSTOM_NAME_WITHOUT_LAST_UPDATED:\n mapInternalAccountsListToUserStorageAccountsList([\n {\n ...MOCK_INTERNAL_ACCOUNTS.ONE_CUSTOM_NAME_WITHOUT_LAST_UPDATED[0],\n metadata: {\n name: 'User storage account custom name without nameLastUpdatedAt',\n },\n },\n ] as InternalAccount[]),\n ONE_CUSTOM_NAME_WITH_LAST_UPDATED:\n mapInternalAccountsListToUserStorageAccountsList([\n {\n ...MOCK_INTERNAL_ACCOUNTS.ONE_CUSTOM_NAME_WITHOUT_LAST_UPDATED[0],\n metadata: {\n name: 'User storage account custom name with nameLastUpdatedAt',\n nameLastUpdatedAt: 3,\n },\n },\n ] as InternalAccount[]),\n};\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mockAccounts.d.cts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/__fixtures__/mockAccounts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAwB,8BAA8B;AAC7E,OAAO,EAAE,YAAY,EAAE,qCAAqC;AAe5D;;;GAGG;AACH,eAAO,MAAM,+BAA+B,mbAGzC,CAAC;AAEJ,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyHlC,CAAC;AAEF,eAAO,MAAM,0BAA0B;;;;;;;CAyCtC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mockAccounts.d.mts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/__fixtures__/mockAccounts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAwB,8BAA8B;AAC7E,OAAO,EAAE,YAAY,EAAE,qCAAqC;AAe5D;;;GAGG;AACH,eAAO,MAAM,+BAA+B,mbAGzC,CAAC;AAEJ,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyHlC,CAAC;AAEF,eAAO,MAAM,0BAA0B;;;;;;;CAyCtC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mockAccounts.mjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/__fixtures__/mockAccounts.ts"],"names":[],"mappings":";;AACA,OAAO,EAAE,YAAY,EAAE,qCAAqC;AAE5D,OAAO,EAAE,+BAA+B,EAAE,kCAA8B;AACxE,OAAO,EAAE,sCAAsC,EAAE,qCAAiC;AAElF;;;;;GAKG;AACH,MAAM,gDAAgD,GAAG,CACvD,gBAAmC,EACnC,EAAE,CAAC,gBAAgB,CAAC,GAAG,CAAC,sCAAsC,CAAC,CAAC;AAElE;;;GAGG;AACH,MAAM,CAAC,MAAM,+BAA+B,GAAG,GAAG,EAAE,CAClD,+BAA+B,CAC7B,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,+BAA+B,CAAC,MAAM,CAAC,CACnE,CAAC;AAEJ,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACpC,KAAK,EAAE,EAAE;IACT,GAAG,EAAE;QACH;YACE,OAAO,EAAE,OAAO;YAChB,EAAE,EAAE,GAAG;YACP,IAAI,EAAE,cAAc,CAAC,GAAG;YACxB,QAAQ,EAAE;gBACR,IAAI,EA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,IAAI;gBAC9C,iBAAiB,EAAE,CAAC;aACrB;SACF;KACmB,CAAC;IACzB,gBAAgB,EAAE,gDAAgD,CAChE,sBAAsB,CAAC,gBAAqC,CAC7D;IACD,oCAAoC,EAClC,gDAAgD,CAAC;QAC/C;YACE,GAAG,sBAAsB,CAAC,oCAAoC,CAAC,CAAC,CAAC;YACjE,QAAQ,EAAE;gBACR,IAAI,EAAE,4DAA4D;aACnE;SACF;KACmB,CAAC;IACzB,iCAAiC,EAC/B,gDAAgD,CAAC;QAC/C;YACE,GAAG,sBAAsB,CAAC,oCAAoC,CAAC,CAAC,CAAC;YACjE,QAAQ,EAAE;gBACR,IAAI,EAAE,yDAAyD;gBAC/D,iBAAiB,EAAE,CAAC;aACrB;SACF;KACmB,CAAC;CAC1B,CAAC","sourcesContent":["import { EthAccountType, type InternalAccount } from '@metamask/keyring-api';\nimport { KeyringTypes } from '@metamask/keyring-controller';\n\nimport { LOCALIZED_DEFAULT_ACCOUNT_NAMES } from '../accounts/constants';\nimport { mapInternalAccountToUserStorageAccount } from '../accounts/user-storage';\n\n/**\n * Map an array of internal accounts to an array of user storage accounts\n * Only used for testing purposes\n * @param internalAccounts - An array of internal accounts\n * @returns An array of user storage accounts\n */\nconst mapInternalAccountsListToUserStorageAccountsList = (\n internalAccounts: InternalAccount[],\n) => internalAccounts.map(mapInternalAccountToUserStorageAccount);\n\n/**\n * Get a random default account name from the list of localized default account names\n * @returns A random default account name\n */\nexport const getMockRandomDefaultAccountName = () =>\n LOCALIZED_DEFAULT_ACCOUNT_NAMES[\n Math.floor(Math.random() * LOCALIZED_DEFAULT_ACCOUNT_NAMES.length)\n ];\n\nexport const MOCK_INTERNAL_ACCOUNTS = {\n EMPTY: [],\n ONE: [\n {\n address: '0x123',\n id: '1',\n type: EthAccountType.Eoa,\n metadata: {\n name: 'test',\n nameLastUpdatedAt: 1,\n keyring: {\n type: KeyringTypes.hd,\n },\n },\n },\n ],\n ONE_DEFAULT_NAME: [\n {\n address: '0x123',\n id: '1',\n type: EthAccountType.Eoa,\n metadata: {\n name: `${getMockRandomDefaultAccountName()} 1`,\n nameLastUpdatedAt: 1,\n keyring: {\n type: KeyringTypes.hd,\n },\n },\n },\n ],\n ONE_CUSTOM_NAME_WITHOUT_LAST_UPDATED: [\n {\n address: '0x123',\n id: '1',\n type: EthAccountType.Eoa,\n metadata: {\n name: 'Internal account custom name without nameLastUpdatedAt',\n keyring: {\n type: KeyringTypes.hd,\n },\n },\n },\n ],\n ONE_CUSTOM_NAME_WITH_LAST_UPDATED: [\n {\n address: '0x123',\n id: '1',\n type: EthAccountType.Eoa,\n metadata: {\n name: 'Internal account custom name with nameLastUpdatedAt',\n nameLastUpdatedAt: 1,\n keyring: {\n type: KeyringTypes.hd,\n },\n },\n },\n ],\n ONE_CUSTOM_NAME_WITH_LAST_UPDATED_MOST_RECENT: [\n {\n address: '0x123',\n id: '1',\n type: EthAccountType.Eoa,\n metadata: {\n name: 'Internal account custom name with nameLastUpdatedAt',\n nameLastUpdatedAt: 9999,\n keyring: {\n type: KeyringTypes.hd,\n },\n },\n },\n ],\n ALL: [\n {\n address: '0x123',\n id: '1',\n type: EthAccountType.Eoa,\n metadata: {\n name: 'test',\n nameLastUpdatedAt: 1,\n keyring: {\n type: KeyringTypes.hd,\n },\n },\n },\n {\n address: '0x456',\n id: '2',\n type: EthAccountType.Eoa,\n metadata: {\n name: 'Account 2',\n nameLastUpdatedAt: 2,\n keyring: {\n type: KeyringTypes.hd,\n },\n },\n },\n {\n address: '0x789',\n id: '3',\n type: EthAccountType.Eoa,\n metadata: {\n name: 'Účet 2',\n nameLastUpdatedAt: 3,\n keyring: {\n type: KeyringTypes.hd,\n },\n },\n },\n {\n address: '0xabc',\n id: '4',\n type: EthAccountType.Eoa,\n metadata: {\n name: 'My Account 4',\n nameLastUpdatedAt: 4,\n keyring: {\n type: KeyringTypes.hd,\n },\n },\n },\n ],\n};\n\nexport const MOCK_USER_STORAGE_ACCOUNTS = {\n SAME_AS_INTERNAL_ALL: mapInternalAccountsListToUserStorageAccountsList(\n MOCK_INTERNAL_ACCOUNTS.ALL as InternalAccount[],\n ),\n ONE: mapInternalAccountsListToUserStorageAccountsList(\n MOCK_INTERNAL_ACCOUNTS.ONE as InternalAccount[],\n ),\n TWO_DEFAULT_NAMES_WITH_ONE_BOGUS:\n mapInternalAccountsListToUserStorageAccountsList([\n ...MOCK_INTERNAL_ACCOUNTS.ONE_DEFAULT_NAME,\n {\n ...MOCK_INTERNAL_ACCOUNTS.ONE_DEFAULT_NAME[0],\n address: '0x000000',\n metadata: {\n name: `${getMockRandomDefaultAccountName()} 1`,\n nameLastUpdatedAt: 2,\n },\n },\n ] as InternalAccount[]),\n ONE_DEFAULT_NAME: mapInternalAccountsListToUserStorageAccountsList(\n MOCK_INTERNAL_ACCOUNTS.ONE_DEFAULT_NAME as InternalAccount[],\n ),\n ONE_CUSTOM_NAME_WITHOUT_LAST_UPDATED:\n mapInternalAccountsListToUserStorageAccountsList([\n {\n ...MOCK_INTERNAL_ACCOUNTS.ONE_CUSTOM_NAME_WITHOUT_LAST_UPDATED[0],\n metadata: {\n name: 'User storage account custom name without nameLastUpdatedAt',\n },\n },\n ] as InternalAccount[]),\n ONE_CUSTOM_NAME_WITH_LAST_UPDATED:\n mapInternalAccountsListToUserStorageAccountsList([\n {\n ...MOCK_INTERNAL_ACCOUNTS.ONE_CUSTOM_NAME_WITHOUT_LAST_UPDATED[0],\n metadata: {\n name: 'User storage account custom name with nameLastUpdatedAt',\n nameLastUpdatedAt: 3,\n },\n },\n ] as InternalAccount[]),\n};\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.cjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/accounts/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,oBAAoB,GAAG,GAAG,CAAC;AAExC,4FAA4F;AAC/E,QAAA,wBAAwB,GAAkB,GAAY,CAAC;AAEpE,qGAAqG;AACxF,QAAA,+BAA+B,GAAG;IAC7C,SAAS;IACT,KAAK;IACL,QAAQ;IACR,QAAQ;IACR,YAAY;IACZ,QAAQ;IACR,MAAM;IACN,OAAO;IACP,aAAa;IACb,QAAQ;IACR,MAAM;IACN,MAAM;IACN,SAAS;IACT,OAAO;IACP,QAAQ;IACR,MAAM;IACN,OAAO;IACP,MAAM;IACN,MAAM;IACN,MAAM;IACN,OAAO;IACP,MAAM;IACN,IAAI;IACJ,SAAS;IACT,OAAO;IACP,WAAW;IACX,MAAM;IACN,OAAO;IACP,OAAO;IACP,MAAM;IACN,MAAM;IACN,OAAO;IACP,SAAS;IACT,QAAQ;IACR,MAAM;IACN,OAAO;IACP,OAAO;IACP,iBAAiB;IACjB,WAAW;IACX,IAAI;IACJ,IAAI;CACI,CAAC","sourcesContent":["export const USER_STORAGE_VERSION = '1';\n\n// Force cast. We don't really care about the type here since we treat it as a unique symbol\nexport const USER_STORAGE_VERSION_KEY: unique symbol = 'v' as never;\n\n// We need this in order to know if an account is a default account or not when we do account syncing\nexport const LOCALIZED_DEFAULT_ACCOUNT_NAMES = [\n 'Account',\n 'መለያ',\n 'الحساب',\n 'Профил',\n 'অ্যাকাউন্ট',\n 'Compte',\n 'Účet',\n 'Konto',\n 'Λογαριασμός',\n 'Cuenta',\n 'حساب',\n 'Tili',\n 'એકાઉન્ટ',\n 'חשבון',\n 'अकाउंट',\n 'खाता',\n 'Račun',\n 'Kont',\n 'Fiók',\n 'Akun',\n 'アカウント',\n 'ಖಾತೆ',\n '계정',\n 'Paskyra',\n 'Konts',\n 'അക്കൗണ്ട്',\n 'खाते',\n 'Akaun',\n 'Conta',\n 'Cont',\n 'Счет',\n 'налог',\n 'Akaunti',\n 'கணக்கு',\n 'ఖాతా',\n 'บัญชี',\n 'Hesap',\n 'Обліковий запис',\n 'Tài khoản',\n '账户',\n '帳戶',\n] as const;\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.cts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/accounts/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oBAAoB,MAAM,CAAC;AAGxC,eAAO,MAAM,wBAAwB,EAAE,OAAO,MAAqB,CAAC;AAGpE,eAAO,MAAM,+BAA+B,gZA0ClC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.mts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/accounts/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oBAAoB,MAAM,CAAC;AAGxC,eAAO,MAAM,wBAAwB,EAAE,OAAO,MAAqB,CAAC;AAGpE,eAAO,MAAM,+BAA+B,gZA0ClC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.mjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/accounts/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,oBAAoB,GAAG,GAAG,CAAC;AAExC,4FAA4F;AAC5F,MAAM,CAAC,MAAM,wBAAwB,GAAkB,GAAY,CAAC;AAEpE,qGAAqG;AACrG,MAAM,CAAC,MAAM,+BAA+B,GAAG;IAC7C,SAAS;IACT,KAAK;IACL,QAAQ;IACR,QAAQ;IACR,YAAY;IACZ,QAAQ;IACR,MAAM;IACN,OAAO;IACP,aAAa;IACb,QAAQ;IACR,MAAM;IACN,MAAM;IACN,SAAS;IACT,OAAO;IACP,QAAQ;IACR,MAAM;IACN,OAAO;IACP,MAAM;IACN,MAAM;IACN,MAAM;IACN,OAAO;IACP,MAAM;IACN,IAAI;IACJ,SAAS;IACT,OAAO;IACP,WAAW;IACX,MAAM;IACN,OAAO;IACP,OAAO;IACP,MAAM;IACN,MAAM;IACN,OAAO;IACP,SAAS;IACT,QAAQ;IACR,MAAM;IACN,OAAO;IACP,OAAO;IACP,iBAAiB;IACjB,WAAW;IACX,IAAI;IACJ,IAAI;CACI,CAAC","sourcesContent":["export const USER_STORAGE_VERSION = '1';\n\n// Force cast. We don't really care about the type here since we treat it as a unique symbol\nexport const USER_STORAGE_VERSION_KEY: unique symbol = 'v' as never;\n\n// We need this in order to know if an account is a default account or not when we do account syncing\nexport const LOCALIZED_DEFAULT_ACCOUNT_NAMES = [\n 'Account',\n 'መለያ',\n 'الحساب',\n 'Профил',\n 'অ্যাকাউন্ট',\n 'Compte',\n 'Účet',\n 'Konto',\n 'Λογαριασμός',\n 'Cuenta',\n 'حساب',\n 'Tili',\n 'એકાઉન્ટ',\n 'חשבון',\n 'अकाउंट',\n 'खाता',\n 'Račun',\n 'Kont',\n 'Fiók',\n 'Akun',\n 'アカウント',\n 'ಖಾತೆ',\n '계정',\n 'Paskyra',\n 'Konts',\n 'അക്കൗണ്ട്',\n 'खाते',\n 'Akaun',\n 'Conta',\n 'Cont',\n 'Счет',\n 'налог',\n 'Akaunti',\n 'கணக்கு',\n 'ఖాతా',\n 'บัญชี',\n 'Hesap',\n 'Обліковий запис',\n 'Tài khoản',\n '账户',\n '帳戶',\n] as const;\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"user-storage.cjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/accounts/user-storage.ts"],"names":[],"mappings":";;;AAEA,+CAIqB;AAkBrB;;;;;;GAMG;AAEI,MAAM,wBAAwB,GAAG,CAAC,IAAY,EAAE,EAAE;IACvD,OAAO,2CAA+B,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE;QACrD,OAAO,IAAI,MAAM,CAAC,IAAI,MAAM,YAAY,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC5D,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAJW,QAAA,wBAAwB,4BAInC;AAEF;;;;GAIG;AACI,MAAM,sCAAsC,GAAG,CACpD,eAAgC,EACZ,EAAE;IACtB,MAAM,EAAE,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,GAAG,eAAe,CAAC;IAClD,MAAM,EAAE,IAAI,EAAE,iBAAiB,EAAE,GAAG,QAAQ,CAAC;IAE7C,OAAO;QACL,CAAC,oCAAwB,CAAC,EAAE,gCAAoB;QAChD,CAAC,EAAE,OAAO;QACV,CAAC,EAAE,EAAE;QACL,CAAC,EAAE,IAAI;QACP,GAAG,CAAC,IAAA,gCAAwB,EAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,iBAAiB,EAAE,CAAC;KACtE,CAAC;AACJ,CAAC,CAAC;AAbW,QAAA,sCAAsC,0CAajD","sourcesContent":["import type { InternalAccount } from '@metamask/keyring-api';\n\nimport {\n USER_STORAGE_VERSION_KEY,\n USER_STORAGE_VERSION,\n LOCALIZED_DEFAULT_ACCOUNT_NAMES,\n} from './constants';\n\nexport type UserStorageAccount = {\n /**\n * The Version 'v' of the User Storage.\n * NOTE - will allow us to support upgrade/downgrades in the future\n */\n [USER_STORAGE_VERSION_KEY]: typeof USER_STORAGE_VERSION;\n /** the id 'i' of the account */\n i: string;\n /** the address 'a' of the account */\n a: string;\n /** the name 'n' of the account */\n n: string;\n /** the nameLastUpdatedAt timestamp 'nlu' of the account */\n nlu?: number;\n};\n\n/**\n * Tells if the given name is a default account name.\n * Default account names are localized names that are automatically generated by the clients.\n *\n * @param name - the name to check\n * @returns true if the name is a default account name, false otherwise\n */\n\nexport const isNameDefaultAccountName = (name: string) => {\n return LOCALIZED_DEFAULT_ACCOUNT_NAMES.some((prefix) => {\n return new RegExp(`^${prefix} ([0-9]+)$`, 'u').test(name);\n });\n};\n\n/**\n * Map an internal account to a user storage account\n * @param internalAccount - An internal account\n * @returns A user storage account\n */\nexport const mapInternalAccountToUserStorageAccount = (\n internalAccount: InternalAccount,\n): UserStorageAccount => {\n const { address, id, metadata } = internalAccount;\n const { name, nameLastUpdatedAt } = metadata;\n\n return {\n [USER_STORAGE_VERSION_KEY]: USER_STORAGE_VERSION,\n a: address,\n i: id,\n n: name,\n ...(isNameDefaultAccountName(name) ? {} : { nlu: nameLastUpdatedAt }),\n };\n};\n"]}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import type { InternalAccount } from "@metamask/keyring-api";
|
|
2
|
-
import { USER_STORAGE_VERSION_KEY, USER_STORAGE_VERSION } from "./constants.cjs";
|
|
3
|
-
export type UserStorageAccount = {
|
|
4
|
-
/**
|
|
5
|
-
* The Version 'v' of the User Storage.
|
|
6
|
-
* NOTE - will allow us to support upgrade/downgrades in the future
|
|
7
|
-
*/
|
|
8
|
-
[USER_STORAGE_VERSION_KEY]: typeof USER_STORAGE_VERSION;
|
|
9
|
-
/** the id 'i' of the account */
|
|
10
|
-
i: string;
|
|
11
|
-
/** the address 'a' of the account */
|
|
12
|
-
a: string;
|
|
13
|
-
/** the name 'n' of the account */
|
|
14
|
-
n: string;
|
|
15
|
-
/** the nameLastUpdatedAt timestamp 'nlu' of the account */
|
|
16
|
-
nlu?: number;
|
|
17
|
-
};
|
|
18
|
-
/**
|
|
19
|
-
* Tells if the given name is a default account name.
|
|
20
|
-
* Default account names are localized names that are automatically generated by the clients.
|
|
21
|
-
*
|
|
22
|
-
* @param name - the name to check
|
|
23
|
-
* @returns true if the name is a default account name, false otherwise
|
|
24
|
-
*/
|
|
25
|
-
export declare const isNameDefaultAccountName: (name: string) => boolean;
|
|
26
|
-
/**
|
|
27
|
-
* Map an internal account to a user storage account
|
|
28
|
-
* @param internalAccount - An internal account
|
|
29
|
-
* @returns A user storage account
|
|
30
|
-
*/
|
|
31
|
-
export declare const mapInternalAccountToUserStorageAccount: (internalAccount: InternalAccount) => UserStorageAccount;
|
|
32
|
-
//# sourceMappingURL=user-storage.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"user-storage.d.cts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/accounts/user-storage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,8BAA8B;AAE7D,OAAO,EACL,wBAAwB,EACxB,oBAAoB,EAErB,wBAAoB;AAErB,MAAM,MAAM,kBAAkB,GAAG;IAC/B;;;OAGG;IACH,CAAC,wBAAwB,CAAC,EAAE,OAAO,oBAAoB,CAAC;IACxD,gCAAgC;IAChC,CAAC,EAAE,MAAM,CAAC;IACV,qCAAqC;IACrC,CAAC,EAAE,MAAM,CAAC;IACV,kCAAkC;IAClC,CAAC,EAAE,MAAM,CAAC;IACV,2DAA2D;IAC3D,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,CAAC;AAEF;;;;;;GAMG;AAEH,eAAO,MAAM,wBAAwB,SAAU,MAAM,YAIpD,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,sCAAsC,oBAChC,eAAe,KAC/B,kBAWF,CAAC"}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import type { InternalAccount } from "@metamask/keyring-api";
|
|
2
|
-
import { USER_STORAGE_VERSION_KEY, USER_STORAGE_VERSION } from "./constants.mjs";
|
|
3
|
-
export type UserStorageAccount = {
|
|
4
|
-
/**
|
|
5
|
-
* The Version 'v' of the User Storage.
|
|
6
|
-
* NOTE - will allow us to support upgrade/downgrades in the future
|
|
7
|
-
*/
|
|
8
|
-
[USER_STORAGE_VERSION_KEY]: typeof USER_STORAGE_VERSION;
|
|
9
|
-
/** the id 'i' of the account */
|
|
10
|
-
i: string;
|
|
11
|
-
/** the address 'a' of the account */
|
|
12
|
-
a: string;
|
|
13
|
-
/** the name 'n' of the account */
|
|
14
|
-
n: string;
|
|
15
|
-
/** the nameLastUpdatedAt timestamp 'nlu' of the account */
|
|
16
|
-
nlu?: number;
|
|
17
|
-
};
|
|
18
|
-
/**
|
|
19
|
-
* Tells if the given name is a default account name.
|
|
20
|
-
* Default account names are localized names that are automatically generated by the clients.
|
|
21
|
-
*
|
|
22
|
-
* @param name - the name to check
|
|
23
|
-
* @returns true if the name is a default account name, false otherwise
|
|
24
|
-
*/
|
|
25
|
-
export declare const isNameDefaultAccountName: (name: string) => boolean;
|
|
26
|
-
/**
|
|
27
|
-
* Map an internal account to a user storage account
|
|
28
|
-
* @param internalAccount - An internal account
|
|
29
|
-
* @returns A user storage account
|
|
30
|
-
*/
|
|
31
|
-
export declare const mapInternalAccountToUserStorageAccount: (internalAccount: InternalAccount) => UserStorageAccount;
|
|
32
|
-
//# sourceMappingURL=user-storage.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"user-storage.d.mts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/accounts/user-storage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,8BAA8B;AAE7D,OAAO,EACL,wBAAwB,EACxB,oBAAoB,EAErB,wBAAoB;AAErB,MAAM,MAAM,kBAAkB,GAAG;IAC/B;;;OAGG;IACH,CAAC,wBAAwB,CAAC,EAAE,OAAO,oBAAoB,CAAC;IACxD,gCAAgC;IAChC,CAAC,EAAE,MAAM,CAAC;IACV,qCAAqC;IACrC,CAAC,EAAE,MAAM,CAAC;IACV,kCAAkC;IAClC,CAAC,EAAE,MAAM,CAAC;IACV,2DAA2D;IAC3D,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,CAAC;AAEF;;;;;;GAMG;AAEH,eAAO,MAAM,wBAAwB,SAAU,MAAM,YAIpD,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,sCAAsC,oBAChC,eAAe,KAC/B,kBAWF,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"user-storage.mjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/accounts/user-storage.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,wBAAwB,EACxB,oBAAoB,EACpB,+BAA+B,EAChC,wBAAoB;AAkBrB;;;;;;GAMG;AAEH,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,IAAY,EAAE,EAAE;IACvD,OAAO,+BAA+B,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE;QACrD,OAAO,IAAI,MAAM,CAAC,IAAI,MAAM,YAAY,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC5D,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,sCAAsC,GAAG,CACpD,eAAgC,EACZ,EAAE;IACtB,MAAM,EAAE,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,GAAG,eAAe,CAAC;IAClD,MAAM,EAAE,IAAI,EAAE,iBAAiB,EAAE,GAAG,QAAQ,CAAC;IAE7C,OAAO;QACL,CAAC,wBAAwB,CAAC,EAAE,oBAAoB;QAChD,CAAC,EAAE,OAAO;QACV,CAAC,EAAE,EAAE;QACL,CAAC,EAAE,IAAI;QACP,GAAG,CAAC,wBAAwB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,iBAAiB,EAAE,CAAC;KACtE,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import type { InternalAccount } from '@metamask/keyring-api';\n\nimport {\n USER_STORAGE_VERSION_KEY,\n USER_STORAGE_VERSION,\n LOCALIZED_DEFAULT_ACCOUNT_NAMES,\n} from './constants';\n\nexport type UserStorageAccount = {\n /**\n * The Version 'v' of the User Storage.\n * NOTE - will allow us to support upgrade/downgrades in the future\n */\n [USER_STORAGE_VERSION_KEY]: typeof USER_STORAGE_VERSION;\n /** the id 'i' of the account */\n i: string;\n /** the address 'a' of the account */\n a: string;\n /** the name 'n' of the account */\n n: string;\n /** the nameLastUpdatedAt timestamp 'nlu' of the account */\n nlu?: number;\n};\n\n/**\n * Tells if the given name is a default account name.\n * Default account names are localized names that are automatically generated by the clients.\n *\n * @param name - the name to check\n * @returns true if the name is a default account name, false otherwise\n */\n\nexport const isNameDefaultAccountName = (name: string) => {\n return LOCALIZED_DEFAULT_ACCOUNT_NAMES.some((prefix) => {\n return new RegExp(`^${prefix} ([0-9]+)$`, 'u').test(name);\n });\n};\n\n/**\n * Map an internal account to a user storage account\n * @param internalAccount - An internal account\n * @returns A user storage account\n */\nexport const mapInternalAccountToUserStorageAccount = (\n internalAccount: InternalAccount,\n): UserStorageAccount => {\n const { address, id, metadata } = internalAccount;\n const { name, nameLastUpdatedAt } = metadata;\n\n return {\n [USER_STORAGE_VERSION_KEY]: USER_STORAGE_VERSION,\n a: address,\n i: id,\n n: name,\n ...(isNameDefaultAccountName(name) ? {} : { nlu: nameLastUpdatedAt }),\n };\n};\n"]}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|