@metamask/profile-sync-controller 0.1.4 → 0.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 +29 -1
- package/dist/{chunk-5SXXO4MV.js → chunk-3TE6M5TV.js} +10 -8
- package/dist/chunk-3TE6M5TV.js.map +1 -0
- package/dist/{chunk-CSFHMILK.js → chunk-77LSWSGB.js} +8 -8
- package/dist/{chunk-CSFHMILK.js.map → chunk-77LSWSGB.js.map} +1 -1
- package/dist/{chunk-RT2GRG4S.mjs → chunk-7KMONAQI.mjs} +3 -3
- package/dist/{chunk-2XGRQBXI.mjs → chunk-FU7PSGFP.mjs} +10 -8
- package/dist/chunk-FU7PSGFP.mjs.map +1 -0
- package/dist/{chunk-P52TG263.js → chunk-FUPEFLXB.js} +18 -24
- package/dist/chunk-FUPEFLXB.js.map +1 -0
- package/dist/chunk-ILIZJQ6X.mjs +40 -0
- package/dist/chunk-ILIZJQ6X.mjs.map +1 -0
- package/dist/{chunk-3SNLHEYU.mjs → chunk-IQECLCH4.mjs} +5 -5
- package/dist/{chunk-3SNLHEYU.mjs.map → chunk-IQECLCH4.mjs.map} +1 -1
- package/dist/{chunk-TUMNNWY6.mjs → chunk-LNSB4L7K.mjs} +8 -8
- package/dist/chunk-LNSB4L7K.mjs.map +1 -0
- package/dist/{chunk-AXWK4Y23.mjs → chunk-NPH5AHLH.mjs} +19 -25
- package/dist/chunk-NPH5AHLH.mjs.map +1 -0
- package/dist/{chunk-3DMUUTKC.js → chunk-PSR2V3R4.js} +6 -6
- package/dist/{chunk-DDOYG42A.js → chunk-R2S3HIDN.js} +10 -10
- package/dist/chunk-R2S3HIDN.js.map +1 -0
- package/dist/chunk-SLHAVOTE.js +40 -0
- package/dist/chunk-SLHAVOTE.js.map +1 -0
- package/dist/{chunk-JFVONPMM.mjs → chunk-VYZPOR47.mjs} +15 -1
- package/dist/chunk-VYZPOR47.mjs.map +1 -0
- package/dist/{chunk-KUTU3NNS.js → chunk-XSSIP3PJ.js} +15 -1
- package/dist/chunk-XSSIP3PJ.js.map +1 -0
- package/dist/controllers/authentication/AuthenticationController.js +8 -3
- package/dist/controllers/authentication/AuthenticationController.mjs +8 -3
- package/dist/controllers/authentication/index.js +8 -3
- package/dist/controllers/authentication/index.mjs +8 -3
- package/dist/controllers/authentication/services.js +8 -3
- package/dist/controllers/authentication/services.mjs +8 -3
- package/dist/controllers/index.js +12 -12
- package/dist/controllers/index.mjs +11 -11
- package/dist/controllers/user-storage/UserStorageController.js +11 -11
- package/dist/controllers/user-storage/UserStorageController.mjs +10 -10
- package/dist/controllers/user-storage/index.js +15 -15
- package/dist/controllers/user-storage/index.mjs +14 -14
- package/dist/controllers/user-storage/schema.js +4 -2
- package/dist/controllers/user-storage/schema.mjs +7 -5
- package/dist/controllers/user-storage/services.js +10 -10
- package/dist/controllers/user-storage/services.mjs +9 -9
- package/dist/index.js +12 -12
- package/dist/index.mjs +11 -11
- package/dist/sdk/authentication.js +2 -2
- package/dist/sdk/authentication.mjs +1 -1
- package/dist/sdk/index.js +9 -4
- package/dist/sdk/index.mjs +8 -3
- package/dist/sdk/user-storage.js +7 -2
- package/dist/sdk/user-storage.mjs +6 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/controllers/user-storage/UserStorageController.d.ts +6 -6
- package/dist/types/controllers/user-storage/UserStorageController.d.ts.map +1 -1
- package/dist/types/controllers/user-storage/schema.d.ts +18 -10
- package/dist/types/controllers/user-storage/schema.d.ts.map +1 -1
- package/dist/types/controllers/user-storage/services.d.ts +2 -2
- package/dist/types/controllers/user-storage/services.d.ts.map +1 -1
- package/dist/types/sdk/__fixtures__/mock-userstorage.d.ts.map +1 -1
- package/dist/types/sdk/authentication.d.ts +1 -0
- package/dist/types/sdk/authentication.d.ts.map +1 -1
- package/dist/types/sdk/user-storage.d.ts +4 -3
- package/dist/types/sdk/user-storage.d.ts.map +1 -1
- package/package.json +11 -10
- package/dist/chunk-2XGRQBXI.mjs.map +0 -1
- package/dist/chunk-5SXXO4MV.js.map +0 -1
- package/dist/chunk-AUFUOKJW.mjs +0 -25
- package/dist/chunk-AUFUOKJW.mjs.map +0 -1
- package/dist/chunk-AXWK4Y23.mjs.map +0 -1
- package/dist/chunk-B6CSNLGE.js +0 -25
- package/dist/chunk-B6CSNLGE.js.map +0 -1
- package/dist/chunk-DDOYG42A.js.map +0 -1
- package/dist/chunk-JFVONPMM.mjs.map +0 -1
- package/dist/chunk-KUTU3NNS.js.map +0 -1
- package/dist/chunk-P52TG263.js.map +0 -1
- package/dist/chunk-TUMNNWY6.mjs.map +0 -1
- /package/dist/{chunk-RT2GRG4S.mjs.map → chunk-7KMONAQI.mjs.map} +0 -0
- /package/dist/{chunk-3DMUUTKC.js.map → chunk-PSR2V3R4.js.map} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,33 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.2.0]
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- Add and export object `USER_STORAGE_SCHEMA`, function `getFeatureAndKeyFromPath`, and type `UserStoragePath` ([#4543](https://github.com/MetaMask/core/pull/4543))
|
|
15
|
+
- Add `connectSnap` method to the `JwtBearerAuth` class for connecting to snap after initializing the Profile Sync SDK ([#4560](https://github.com/MetaMask/core/pull/4560))
|
|
16
|
+
|
|
17
|
+
### Changed
|
|
18
|
+
|
|
19
|
+
- **BREAKING:** Enforce `UserStorageSchema` usage in all functions that get or set user storage ([#4543](https://github.com/MetaMask/core/pull/4543))
|
|
20
|
+
- Keeps user storage entries consistent, and improves DX for consumers of user storage.
|
|
21
|
+
- **BREAKING:** Remove `entryKey` function parameter from `performGetStorage` and `performSetStorage` methods of `UserStorageController`, and replace with `path` parameter of type `UserStoragePath`.
|
|
22
|
+
- **BREAKING:** Remove `entryKey` function parameter from `createEntryPath`, and replace with `path` parameter of type `UserStoragePath`.
|
|
23
|
+
- **BREAKING:** Remove `entryKey` property from type `UserStorageOptions`, and replace with `path` property of type `UserStoragePath`.
|
|
24
|
+
- **BREAKING:** Bump peerDependency `@metamask/snaps-controllers` from `^8.1.1` to `^9.3.0` ([#3645](https://github.com/MetaMask/core/pull/3645))
|
|
25
|
+
- Remove `@metamask/snaps-controllers` dependency [#4556](https://github.com/MetaMask/core/pull/4556)
|
|
26
|
+
- This was listed under `peerDependencies` already, so it was redundant as a dependency.
|
|
27
|
+
- Widen `isProfileSyncingEnabled` property of the `UserStorageControllerState` type from `boolean` to `boolean | null` ([#4551](https://github.com/MetaMask/core/pull/4551))
|
|
28
|
+
- Upgrade TypeScript version to `~5.0.4` and set `moduleResolution` option to `Node16` ([#3645](https://github.com/MetaMask/core/pull/3645))
|
|
29
|
+
- Bump `@metamask/base-controller` from `^6.0.1` to `^6.0.2` ([#4544](https://github.com/MetaMask/core/pull/4544))
|
|
30
|
+
- Bump `@metamask/snaps-sdk` from `^4.2.0` to `^6.1.1` ([#3645](https://github.com/MetaMask/core/pull/3645), [#4547](https://github.com/MetaMask/core/pull/4547))
|
|
31
|
+
- Add new dependency `@metamask/snaps-utils` ([#3645](https://github.com/MetaMask/core/pull/3645), [#4547](https://github.com/MetaMask/core/pull/4547))
|
|
32
|
+
|
|
33
|
+
### Removed
|
|
34
|
+
|
|
35
|
+
- Remove object `USER_STORAGE_ENTRIES` and type `UserStorageEntryKeys` ([#4543](https://github.com/MetaMask/core/pull/4543))
|
|
36
|
+
|
|
10
37
|
## [0.1.4]
|
|
11
38
|
|
|
12
39
|
### Added
|
|
@@ -57,7 +84,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
57
84
|
|
|
58
85
|
- Initial release
|
|
59
86
|
|
|
60
|
-
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/profile-sync-controller@0.
|
|
87
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/profile-sync-controller@0.2.0...HEAD
|
|
88
|
+
[0.2.0]: https://github.com/MetaMask/core/compare/@metamask/profile-sync-controller@0.1.4...@metamask/profile-sync-controller@0.2.0
|
|
61
89
|
[0.1.4]: https://github.com/MetaMask/core/compare/@metamask/profile-sync-controller@0.1.3...@metamask/profile-sync-controller@0.1.4
|
|
62
90
|
[0.1.3]: https://github.com/MetaMask/core/compare/@metamask/profile-sync-controller@0.1.2...@metamask/profile-sync-controller@0.1.3
|
|
63
91
|
[0.1.2]: https://github.com/MetaMask/core/compare/@metamask/profile-sync-controller@0.1.1...@metamask/profile-sync-controller@0.1.2
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkSLHAVOTEjs = require('./chunk-SLHAVOTE.js');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
var _chunkAK7OTIWAjs = require('./chunk-AK7OTIWA.js');
|
|
@@ -15,12 +15,13 @@ var USER_STORAGE_API = ENV_URLS.userStorageApiUrl;
|
|
|
15
15
|
var USER_STORAGE_ENDPOINT = `${USER_STORAGE_API}/api/v1/userstorage`;
|
|
16
16
|
async function getUserStorage(opts) {
|
|
17
17
|
try {
|
|
18
|
-
const path
|
|
19
|
-
const
|
|
18
|
+
const { bearerToken, path, storageKey } = opts;
|
|
19
|
+
const encryptedPath = _chunkSLHAVOTEjs.createEntryPath.call(void 0, path, storageKey);
|
|
20
|
+
const url = new URL(`${USER_STORAGE_ENDPOINT}${encryptedPath}`);
|
|
20
21
|
const userStorageResponse = await fetch(url.toString(), {
|
|
21
22
|
headers: {
|
|
22
23
|
"Content-Type": "application/json",
|
|
23
|
-
Authorization: `Bearer ${
|
|
24
|
+
Authorization: `Bearer ${bearerToken}`
|
|
24
25
|
}
|
|
25
26
|
});
|
|
26
27
|
if (userStorageResponse.status === 404) {
|
|
@@ -45,14 +46,15 @@ async function getUserStorage(opts) {
|
|
|
45
46
|
}
|
|
46
47
|
}
|
|
47
48
|
async function upsertUserStorage(data, opts) {
|
|
49
|
+
const { bearerToken, path, storageKey } = opts;
|
|
48
50
|
const encryptedData = _chunkAK7OTIWAjs.encryption_default.encryptString(data, opts.storageKey);
|
|
49
|
-
const
|
|
50
|
-
const url = new URL(`${USER_STORAGE_ENDPOINT}${
|
|
51
|
+
const encryptedPath = _chunkSLHAVOTEjs.createEntryPath.call(void 0, path, storageKey);
|
|
52
|
+
const url = new URL(`${USER_STORAGE_ENDPOINT}${encryptedPath}`);
|
|
51
53
|
const res = await fetch(url.toString(), {
|
|
52
54
|
method: "PUT",
|
|
53
55
|
headers: {
|
|
54
56
|
"Content-Type": "application/json",
|
|
55
|
-
Authorization: `Bearer ${
|
|
57
|
+
Authorization: `Bearer ${bearerToken}`
|
|
56
58
|
},
|
|
57
59
|
body: JSON.stringify({ data: encryptedData })
|
|
58
60
|
});
|
|
@@ -67,4 +69,4 @@ async function upsertUserStorage(data, opts) {
|
|
|
67
69
|
|
|
68
70
|
|
|
69
71
|
exports.USER_STORAGE_API = USER_STORAGE_API; exports.USER_STORAGE_ENDPOINT = USER_STORAGE_ENDPOINT; exports.getUserStorage = getUserStorage; exports.upsertUserStorage = upsertUserStorage;
|
|
70
|
-
//# sourceMappingURL=chunk-
|
|
72
|
+
//# sourceMappingURL=chunk-3TE6M5TV.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/controllers/user-storage/services.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,SAAS;AAOhB,IAAM,WAAW,0BAAkB;AAE5B,IAAM,mBAA2B,SAAS;AAC1C,IAAM,wBAAwB,GAAG,gBAAgB;AAwBxD,eAAsB,eACpB,MACwB;AACxB,MAAI;AACF,UAAM,EAAE,aAAa,MAAM,WAAW,IAAI;AAE1C,UAAM,gBAAgB,gBAAgB,MAAM,UAAU;AACtD,UAAM,MAAM,IAAI,IAAI,GAAG,qBAAqB,GAAG,aAAa,EAAE;AAE9D,UAAM,sBAAsB,MAAM,MAAM,IAAI,SAAS,GAAG;AAAA,MACtD,SAAS;AAAA,QACP,gBAAgB;AAAA,QAChB,eAAe,UAAU,WAAW;AAAA,MACtC;AAAA,IACF,CAAC;AAGD,QAAI,oBAAoB,WAAW,KAAK;AACtC,aAAO;AAAA,IACT;AAEA,QAAI,oBAAoB,WAAW,KAAK;AACtC,YAAM,IAAI,MAAM,4BAA4B;AAAA,IAC9C;AAEA,UAAM,cACJ,MAAM,oBAAoB,KAAK;AACjC,UAAM,gBAAgB,aAAa,QAAQ;AAE3C,QAAI,CAAC,eAAe;AAClB,aAAO;AAAA,IACT;AAEA,UAAM,gBAAgB,mBAAW;AAAA,MAC/B;AAAA,MACA,KAAK;AAAA,IACP;AAEA,WAAO;AAAA,EACT,SAAS,GAAG;AACV,QAAI,MAAM,8BAA8B,CAAC;AACzC,WAAO;AAAA,EACT;AACF;AAQA,eAAsB,kBACpB,MACA,MACe;AACf,QAAM,EAAE,aAAa,MAAM,WAAW,IAAI;AAE1C,QAAM,gBAAgB,mBAAW,cAAc,MAAM,KAAK,UAAU;AACpE,QAAM,gBAAgB,gBAAgB,MAAM,UAAU;AACtD,QAAM,MAAM,IAAI,IAAI,GAAG,qBAAqB,GAAG,aAAa,EAAE;AAE9D,QAAM,MAAM,MAAM,MAAM,IAAI,SAAS,GAAG;AAAA,IACtC,QAAQ;AAAA,IACR,SAAS;AAAA,MACP,gBAAgB;AAAA,MAChB,eAAe,UAAU,WAAW;AAAA,IACtC;AAAA,IACA,MAAM,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AAAA,EAC9C,CAAC;AAED,MAAI,CAAC,IAAI,IAAI;AACX,UAAM,IAAI,MAAM,sCAAsC;AAAA,EACxD;AACF","sourcesContent":["import log from 'loglevel';\n\nimport { Env, getEnvUrls } from '../../sdk';\nimport encryption from './encryption';\nimport type { UserStoragePath } from './schema';\nimport { createEntryPath } from './schema';\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\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 UserStorageOptions = {\n path: UserStoragePath;\n bearerToken: string;\n storageKey: string;\n};\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 } = 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 if (!encryptedData) {\n return null;\n }\n\n const decryptedData = encryption.decryptString(\n encryptedData,\n opts.storageKey,\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 } = opts;\n\n const encryptedData = encryption.encryptString(data, opts.storageKey);\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"]}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
var
|
|
4
|
+
var _chunkR2S3HIDNjs = require('./chunk-R2S3HIDN.js');
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
var
|
|
7
|
+
var _chunk3TE6M5TVjs = require('./chunk-3TE6M5TV.js');
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _chunkSLHAVOTEjs = require('./chunk-SLHAVOTE.js');
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
var _chunkAK7OTIWAjs = require('./chunk-AK7OTIWA.js');
|
|
@@ -22,11 +22,11 @@ var _chunkIGY2S5BCjs = require('./chunk-IGY2S5BC.js');
|
|
|
22
22
|
// src/controllers/user-storage/index.ts
|
|
23
23
|
var user_storage_exports = {};
|
|
24
24
|
_chunkIGY2S5BCjs.__export.call(void 0, user_storage_exports, {
|
|
25
|
-
Controller: () =>
|
|
25
|
+
Controller: () => _chunkR2S3HIDNjs.UserStorageController,
|
|
26
26
|
Encryption: () => _chunkT3FNDVE3js.encryption_default,
|
|
27
27
|
Mocks: () => fixtures_exports,
|
|
28
28
|
createSHA256Hash: () => _chunkT3FNDVE3js.createSHA256Hash,
|
|
29
|
-
defaultState: () =>
|
|
29
|
+
defaultState: () => _chunkR2S3HIDNjs.defaultState
|
|
30
30
|
});
|
|
31
31
|
|
|
32
32
|
// src/controllers/user-storage/__fixtures__/index.ts
|
|
@@ -51,8 +51,8 @@ var MOCK_ENCRYPTED_STORAGE_DATA = _chunkAK7OTIWAjs.encryption_default.encryptStr
|
|
|
51
51
|
);
|
|
52
52
|
|
|
53
53
|
// src/controllers/user-storage/__fixtures__/mockResponses.ts
|
|
54
|
-
var MOCK_USER_STORAGE_NOTIFICATIONS_ENDPOINT = `${
|
|
55
|
-
"notificationSettings",
|
|
54
|
+
var MOCK_USER_STORAGE_NOTIFICATIONS_ENDPOINT = `${_chunk3TE6M5TVjs.USER_STORAGE_ENDPOINT}${_chunkSLHAVOTEjs.createEntryPath.call(void 0,
|
|
55
|
+
"notifications.notificationSettings",
|
|
56
56
|
MOCK_STORAGE_KEY
|
|
57
57
|
)}`;
|
|
58
58
|
var MOCK_GET_USER_STORAGE_RESPONSE = {
|
|
@@ -78,4 +78,4 @@ var getMockUserStoragePutResponse = () => {
|
|
|
78
78
|
|
|
79
79
|
|
|
80
80
|
exports.fixtures_exports = fixtures_exports; exports.user_storage_exports = user_storage_exports;
|
|
81
|
-
//# sourceMappingURL=chunk-
|
|
81
|
+
//# sourceMappingURL=chunk-77LSWSGB.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/controllers/user-storage/index.ts","../src/controllers/user-storage/__fixtures__/index.ts","../src/controllers/user-storage/__fixtures__/mockStorage.ts","../src/controllers/user-storage/__fixtures__/mockResponses.ts"],"names":["encryption_default"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEO,IAAM,6BAA6B;AACnC,IAAM,mBAAmB,iBAAiB,0BAA0B;AACpE,IAAM,oBAAoB,KAAK,UAAU,EAAE,OAAO,QAAQ,CAAC;AAC3D,IAAM,8BAA8BA,oBAAW;AAAA,EACpD;AAAA,EACA;AACF;;;ACGO,IAAM,2CAA2C,GAAG,qBAAqB,GAAG;AAAA,EACjF;AAAA,EACA;AACF,CAAC;AAED,IAAM,iCAAyD;AAAA,EAC7D,WAAW;AAAA,EACX,MAAM;AACR;AAEO,IAAM,gCAAgC,MAAM;AACjD,SAAO;AAAA,IACL,KAAK;AAAA,IACL,eAAe;AAAA,IACf,UAAU;AAAA,EACZ;AACF;AAEO,IAAM,gCAAgC,MAAM;AACjD,SAAO;AAAA,IACL,KAAK;AAAA,IACL,eAAe;AAAA,IACf,UAAU;AAAA,EACZ;AACF","sourcesContent":["import Controller from './UserStorageController';\n\nexport { Controller };\nexport * from './UserStorageController';\nexport * from './encryption';\nexport * as Mocks from './__fixtures__';\n","export * from './mockResponses';\nexport * from './mockStorage';\n","import encryption, { createSHA256Hash } from '../encryption';\n\nexport const MOCK_STORAGE_KEY_SIGNATURE = 'mockStorageKey';\nexport const MOCK_STORAGE_KEY = createSHA256Hash(MOCK_STORAGE_KEY_SIGNATURE);\nexport const MOCK_STORAGE_DATA = JSON.stringify({ hello: 'world' });\nexport const MOCK_ENCRYPTED_STORAGE_DATA = encryption.encryptString(\n MOCK_STORAGE_DATA,\n MOCK_STORAGE_KEY,\n);\n","import { createEntryPath } from '../schema';\nimport type { GetUserStorageResponse } from '../services';\nimport { USER_STORAGE_ENDPOINT } from '../services';\nimport { MOCK_ENCRYPTED_STORAGE_DATA, MOCK_STORAGE_KEY } from './mockStorage';\n\ntype MockResponse = {\n url: string;\n requestMethod: 'GET' | 'POST' | 'PUT';\n response: unknown;\n};\n\nexport const MOCK_USER_STORAGE_NOTIFICATIONS_ENDPOINT = `${USER_STORAGE_ENDPOINT}${createEntryPath(\n 'notificationSettings',\n MOCK_STORAGE_KEY,\n)}`;\n\nconst MOCK_GET_USER_STORAGE_RESPONSE: GetUserStorageResponse = {\n HashedKey: 'HASHED_KEY',\n Data: MOCK_ENCRYPTED_STORAGE_DATA,\n};\n\nexport const getMockUserStorageGetResponse = () => {\n return {\n url: MOCK_USER_STORAGE_NOTIFICATIONS_ENDPOINT,\n requestMethod: 'GET',\n response: MOCK_GET_USER_STORAGE_RESPONSE,\n } satisfies MockResponse;\n};\n\nexport const getMockUserStoragePutResponse = () => {\n return {\n url: MOCK_USER_STORAGE_NOTIFICATIONS_ENDPOINT,\n requestMethod: 'PUT',\n response: null,\n } satisfies MockResponse;\n};\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/controllers/user-storage/index.ts","../src/controllers/user-storage/__fixtures__/index.ts","../src/controllers/user-storage/__fixtures__/mockStorage.ts","../src/controllers/user-storage/__fixtures__/mockResponses.ts"],"names":["encryption_default"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEO,IAAM,6BAA6B;AACnC,IAAM,mBAAmB,iBAAiB,0BAA0B;AACpE,IAAM,oBAAoB,KAAK,UAAU,EAAE,OAAO,QAAQ,CAAC;AAC3D,IAAM,8BAA8BA,oBAAW;AAAA,EACpD;AAAA,EACA;AACF;;;ACGO,IAAM,2CAA2C,GAAG,qBAAqB,GAAG;AAAA,EACjF;AAAA,EACA;AACF,CAAC;AAED,IAAM,iCAAyD;AAAA,EAC7D,WAAW;AAAA,EACX,MAAM;AACR;AAEO,IAAM,gCAAgC,MAAM;AACjD,SAAO;AAAA,IACL,KAAK;AAAA,IACL,eAAe;AAAA,IACf,UAAU;AAAA,EACZ;AACF;AAEO,IAAM,gCAAgC,MAAM;AACjD,SAAO;AAAA,IACL,KAAK;AAAA,IACL,eAAe;AAAA,IACf,UAAU;AAAA,EACZ;AACF","sourcesContent":["import Controller from './UserStorageController';\n\nexport { Controller };\nexport * from './UserStorageController';\nexport * from './encryption';\nexport * as Mocks from './__fixtures__';\n","export * from './mockResponses';\nexport * from './mockStorage';\n","import encryption, { createSHA256Hash } from '../encryption';\n\nexport const MOCK_STORAGE_KEY_SIGNATURE = 'mockStorageKey';\nexport const MOCK_STORAGE_KEY = createSHA256Hash(MOCK_STORAGE_KEY_SIGNATURE);\nexport const MOCK_STORAGE_DATA = JSON.stringify({ hello: 'world' });\nexport const MOCK_ENCRYPTED_STORAGE_DATA = encryption.encryptString(\n MOCK_STORAGE_DATA,\n MOCK_STORAGE_KEY,\n);\n","import { createEntryPath } from '../schema';\nimport type { GetUserStorageResponse } from '../services';\nimport { USER_STORAGE_ENDPOINT } from '../services';\nimport { MOCK_ENCRYPTED_STORAGE_DATA, MOCK_STORAGE_KEY } from './mockStorage';\n\ntype MockResponse = {\n url: string;\n requestMethod: 'GET' | 'POST' | 'PUT';\n response: unknown;\n};\n\nexport const MOCK_USER_STORAGE_NOTIFICATIONS_ENDPOINT = `${USER_STORAGE_ENDPOINT}${createEntryPath(\n 'notifications.notificationSettings',\n MOCK_STORAGE_KEY,\n)}`;\n\nconst MOCK_GET_USER_STORAGE_RESPONSE: GetUserStorageResponse = {\n HashedKey: 'HASHED_KEY',\n Data: MOCK_ENCRYPTED_STORAGE_DATA,\n};\n\nexport const getMockUserStorageGetResponse = () => {\n return {\n url: MOCK_USER_STORAGE_NOTIFICATIONS_ENDPOINT,\n requestMethod: 'GET',\n response: MOCK_GET_USER_STORAGE_RESPONSE,\n } satisfies MockResponse;\n};\n\nexport const getMockUserStoragePutResponse = () => {\n return {\n url: MOCK_USER_STORAGE_NOTIFICATIONS_ENDPOINT,\n requestMethod: 'PUT',\n response: null,\n } satisfies MockResponse;\n};\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
JwtBearerAuth
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-VYZPOR47.mjs";
|
|
4
4
|
import {
|
|
5
5
|
SIWEJwtBearerAuth
|
|
6
6
|
} from "./chunk-BDO3VJEU.mjs";
|
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
import {
|
|
21
21
|
STORAGE_URL,
|
|
22
22
|
UserStorage
|
|
23
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-NPH5AHLH.mjs";
|
|
24
24
|
import {
|
|
25
25
|
Encryption,
|
|
26
26
|
createSHA256Hash
|
|
@@ -76,4 +76,4 @@ __export(sdk_exports, {
|
|
|
76
76
|
export {
|
|
77
77
|
sdk_exports
|
|
78
78
|
};
|
|
79
|
-
//# sourceMappingURL=chunk-
|
|
79
|
+
//# sourceMappingURL=chunk-7KMONAQI.mjs.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createEntryPath
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-ILIZJQ6X.mjs";
|
|
4
4
|
import {
|
|
5
5
|
encryption_default
|
|
6
6
|
} from "./chunk-5TOWF6UW.mjs";
|
|
@@ -15,12 +15,13 @@ var USER_STORAGE_API = ENV_URLS.userStorageApiUrl;
|
|
|
15
15
|
var USER_STORAGE_ENDPOINT = `${USER_STORAGE_API}/api/v1/userstorage`;
|
|
16
16
|
async function getUserStorage(opts) {
|
|
17
17
|
try {
|
|
18
|
-
const path =
|
|
19
|
-
const
|
|
18
|
+
const { bearerToken, path, storageKey } = opts;
|
|
19
|
+
const encryptedPath = createEntryPath(path, storageKey);
|
|
20
|
+
const url = new URL(`${USER_STORAGE_ENDPOINT}${encryptedPath}`);
|
|
20
21
|
const userStorageResponse = await fetch(url.toString(), {
|
|
21
22
|
headers: {
|
|
22
23
|
"Content-Type": "application/json",
|
|
23
|
-
Authorization: `Bearer ${
|
|
24
|
+
Authorization: `Bearer ${bearerToken}`
|
|
24
25
|
}
|
|
25
26
|
});
|
|
26
27
|
if (userStorageResponse.status === 404) {
|
|
@@ -45,14 +46,15 @@ async function getUserStorage(opts) {
|
|
|
45
46
|
}
|
|
46
47
|
}
|
|
47
48
|
async function upsertUserStorage(data, opts) {
|
|
49
|
+
const { bearerToken, path, storageKey } = opts;
|
|
48
50
|
const encryptedData = encryption_default.encryptString(data, opts.storageKey);
|
|
49
|
-
const
|
|
50
|
-
const url = new URL(`${USER_STORAGE_ENDPOINT}${
|
|
51
|
+
const encryptedPath = createEntryPath(path, storageKey);
|
|
52
|
+
const url = new URL(`${USER_STORAGE_ENDPOINT}${encryptedPath}`);
|
|
51
53
|
const res = await fetch(url.toString(), {
|
|
52
54
|
method: "PUT",
|
|
53
55
|
headers: {
|
|
54
56
|
"Content-Type": "application/json",
|
|
55
|
-
Authorization: `Bearer ${
|
|
57
|
+
Authorization: `Bearer ${bearerToken}`
|
|
56
58
|
},
|
|
57
59
|
body: JSON.stringify({ data: encryptedData })
|
|
58
60
|
});
|
|
@@ -67,4 +69,4 @@ export {
|
|
|
67
69
|
getUserStorage,
|
|
68
70
|
upsertUserStorage
|
|
69
71
|
};
|
|
70
|
-
//# sourceMappingURL=chunk-
|
|
72
|
+
//# sourceMappingURL=chunk-FU7PSGFP.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/controllers/user-storage/services.ts"],"sourcesContent":["import log from 'loglevel';\n\nimport { Env, getEnvUrls } from '../../sdk';\nimport encryption from './encryption';\nimport type { UserStoragePath } from './schema';\nimport { createEntryPath } from './schema';\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\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 UserStorageOptions = {\n path: UserStoragePath;\n bearerToken: string;\n storageKey: string;\n};\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 } = 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 if (!encryptedData) {\n return null;\n }\n\n const decryptedData = encryption.decryptString(\n encryptedData,\n opts.storageKey,\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 } = opts;\n\n const encryptedData = encryption.encryptString(data, opts.storageKey);\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"],"mappings":";;;;;;;;;;;AAAA,OAAO,SAAS;AAOhB,IAAM,WAAW,0BAAkB;AAE5B,IAAM,mBAA2B,SAAS;AAC1C,IAAM,wBAAwB,GAAG,gBAAgB;AAwBxD,eAAsB,eACpB,MACwB;AACxB,MAAI;AACF,UAAM,EAAE,aAAa,MAAM,WAAW,IAAI;AAE1C,UAAM,gBAAgB,gBAAgB,MAAM,UAAU;AACtD,UAAM,MAAM,IAAI,IAAI,GAAG,qBAAqB,GAAG,aAAa,EAAE;AAE9D,UAAM,sBAAsB,MAAM,MAAM,IAAI,SAAS,GAAG;AAAA,MACtD,SAAS;AAAA,QACP,gBAAgB;AAAA,QAChB,eAAe,UAAU,WAAW;AAAA,MACtC;AAAA,IACF,CAAC;AAGD,QAAI,oBAAoB,WAAW,KAAK;AACtC,aAAO;AAAA,IACT;AAEA,QAAI,oBAAoB,WAAW,KAAK;AACtC,YAAM,IAAI,MAAM,4BAA4B;AAAA,IAC9C;AAEA,UAAM,cACJ,MAAM,oBAAoB,KAAK;AACjC,UAAM,gBAAgB,aAAa,QAAQ;AAE3C,QAAI,CAAC,eAAe;AAClB,aAAO;AAAA,IACT;AAEA,UAAM,gBAAgB,mBAAW;AAAA,MAC/B;AAAA,MACA,KAAK;AAAA,IACP;AAEA,WAAO;AAAA,EACT,SAAS,GAAG;AACV,QAAI,MAAM,8BAA8B,CAAC;AACzC,WAAO;AAAA,EACT;AACF;AAQA,eAAsB,kBACpB,MACA,MACe;AACf,QAAM,EAAE,aAAa,MAAM,WAAW,IAAI;AAE1C,QAAM,gBAAgB,mBAAW,cAAc,MAAM,KAAK,UAAU;AACpE,QAAM,gBAAgB,gBAAgB,MAAM,UAAU;AACtD,QAAM,MAAM,IAAI,IAAI,GAAG,qBAAqB,GAAG,aAAa,EAAE;AAE9D,QAAM,MAAM,MAAM,MAAM,IAAI,SAAS,GAAG;AAAA,IACtC,QAAQ;AAAA,IACR,SAAS;AAAA,MACP,gBAAgB;AAAA,MAChB,eAAe,UAAU,WAAW;AAAA,IACtC;AAAA,IACA,MAAM,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AAAA,EAC9C,CAAC;AAED,MAAI,CAAC,IAAI,IAAI;AACX,UAAM,IAAI,MAAM,sCAAsC;AAAA,EACxD;AACF;","names":[]}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
+
var _chunkSLHAVOTEjs = require('./chunk-SLHAVOTE.js');
|
|
4
|
+
|
|
5
|
+
|
|
3
6
|
|
|
4
7
|
var _chunkP4DUDLMYjs = require('./chunk-P4DUDLMY.js');
|
|
5
8
|
|
|
@@ -8,7 +11,6 @@ var _chunkSMKTWM6Ijs = require('./chunk-SMKTWM6I.js');
|
|
|
8
11
|
|
|
9
12
|
|
|
10
13
|
|
|
11
|
-
|
|
12
14
|
var _chunkMBTBE4P5js = require('./chunk-MBTBE4P5.js');
|
|
13
15
|
|
|
14
16
|
|
|
@@ -16,7 +18,7 @@ var _chunkMBTBE4P5js = require('./chunk-MBTBE4P5.js');
|
|
|
16
18
|
var _chunkIGY2S5BCjs = require('./chunk-IGY2S5BC.js');
|
|
17
19
|
|
|
18
20
|
// src/sdk/user-storage.ts
|
|
19
|
-
var STORAGE_URL = (env,
|
|
21
|
+
var STORAGE_URL = (env, encryptedPath) => `${_chunkSMKTWM6Ijs.getEnvUrls.call(void 0, env).userStorageApiUrl}/api/v1/userstorage/${encryptedPath}`;
|
|
20
22
|
var _upsertUserStorage, upsertUserStorage_fn, _getUserStorage, getUserStorage_fn, _createEntryKey, createEntryKey_fn, _getAuthorizationHeader, getAuthorizationHeader_fn;
|
|
21
23
|
var UserStorage = class {
|
|
22
24
|
constructor(config, options) {
|
|
@@ -30,17 +32,11 @@ var UserStorage = class {
|
|
|
30
32
|
this.config = config;
|
|
31
33
|
this.options = options;
|
|
32
34
|
}
|
|
33
|
-
async setItem(
|
|
34
|
-
|
|
35
|
-
throw new (0, _chunkMBTBE4P5js.ValidationError)("feature or key cannot be empty strings");
|
|
36
|
-
}
|
|
37
|
-
await _chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _upsertUserStorage, upsertUserStorage_fn).call(this, feature, key, value);
|
|
35
|
+
async setItem(path, value) {
|
|
36
|
+
await _chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _upsertUserStorage, upsertUserStorage_fn).call(this, path, value);
|
|
38
37
|
}
|
|
39
|
-
async getItem(
|
|
40
|
-
|
|
41
|
-
throw new (0, _chunkMBTBE4P5js.ValidationError)("feature or key cannot be empty strings");
|
|
42
|
-
}
|
|
43
|
-
return _chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _getUserStorage, getUserStorage_fn).call(this, feature, key);
|
|
38
|
+
async getItem(path) {
|
|
39
|
+
return _chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _getUserStorage, getUserStorage_fn).call(this, path);
|
|
44
40
|
}
|
|
45
41
|
async getStorageKey() {
|
|
46
42
|
const storageKey = await this.options.storage?.getStorageKey();
|
|
@@ -57,14 +53,13 @@ var UserStorage = class {
|
|
|
57
53
|
}
|
|
58
54
|
};
|
|
59
55
|
_upsertUserStorage = new WeakSet();
|
|
60
|
-
upsertUserStorage_fn = async function(
|
|
56
|
+
upsertUserStorage_fn = async function(path, data) {
|
|
61
57
|
try {
|
|
62
58
|
const headers = await _chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _getAuthorizationHeader, getAuthorizationHeader_fn).call(this);
|
|
63
59
|
const storageKey = await this.getStorageKey();
|
|
64
60
|
const encryptedData = _chunkP4DUDLMYjs.encryption_default.encryptString(data, storageKey);
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
);
|
|
61
|
+
const encryptedPath = _chunkSLHAVOTEjs.createEntryPath.call(void 0, path, storageKey);
|
|
62
|
+
const url = new URL(STORAGE_URL(this.env, encryptedPath));
|
|
68
63
|
const response = await fetch(url.toString(), {
|
|
69
64
|
method: "PUT",
|
|
70
65
|
headers: {
|
|
@@ -85,18 +80,17 @@ upsertUserStorage_fn = async function(feature, key, data) {
|
|
|
85
80
|
} catch (e) {
|
|
86
81
|
const errorMessage = e instanceof Error ? e.message : JSON.stringify(e ?? "");
|
|
87
82
|
throw new (0, _chunkMBTBE4P5js.UserStorageError)(
|
|
88
|
-
`failed to upsert user storage for
|
|
83
|
+
`failed to upsert user storage for path '${path}'. ${errorMessage}`
|
|
89
84
|
);
|
|
90
85
|
}
|
|
91
86
|
};
|
|
92
87
|
_getUserStorage = new WeakSet();
|
|
93
|
-
getUserStorage_fn = async function(
|
|
88
|
+
getUserStorage_fn = async function(path) {
|
|
94
89
|
try {
|
|
95
90
|
const headers = await _chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _getAuthorizationHeader, getAuthorizationHeader_fn).call(this);
|
|
96
91
|
const storageKey = await this.getStorageKey();
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
);
|
|
92
|
+
const encryptedPath = _chunkSLHAVOTEjs.createEntryPath.call(void 0, path, storageKey);
|
|
93
|
+
const url = new URL(STORAGE_URL(this.env, encryptedPath));
|
|
100
94
|
const response = await fetch(url.toString(), {
|
|
101
95
|
headers: {
|
|
102
96
|
"Content-Type": "application/json",
|
|
@@ -105,7 +99,7 @@ getUserStorage_fn = async function(feature, key) {
|
|
|
105
99
|
});
|
|
106
100
|
if (response.status === 404) {
|
|
107
101
|
throw new (0, _chunkMBTBE4P5js.NotFoundError)(
|
|
108
|
-
`feature/key set not found for
|
|
102
|
+
`feature/key set not found for path '${path}'.`
|
|
109
103
|
);
|
|
110
104
|
}
|
|
111
105
|
if (!response.ok) {
|
|
@@ -122,7 +116,7 @@ getUserStorage_fn = async function(feature, key) {
|
|
|
122
116
|
}
|
|
123
117
|
const errorMessage = e instanceof Error ? e.message : JSON.stringify(e ?? "");
|
|
124
118
|
throw new (0, _chunkMBTBE4P5js.UserStorageError)(
|
|
125
|
-
`failed to get user storage for
|
|
119
|
+
`failed to get user storage for path '${path}'. ${errorMessage}`
|
|
126
120
|
);
|
|
127
121
|
}
|
|
128
122
|
};
|
|
@@ -141,4 +135,4 @@ getAuthorizationHeader_fn = async function() {
|
|
|
141
135
|
|
|
142
136
|
|
|
143
137
|
exports.STORAGE_URL = STORAGE_URL; exports.UserStorage = UserStorage;
|
|
144
|
-
//# sourceMappingURL=chunk-
|
|
138
|
+
//# sourceMappingURL=chunk-FUPEFLXB.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/sdk/user-storage.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAQO,IAAM,cAAc,CAAC,KAAU,kBACpC,GAAG,WAAW,GAAG,EAAE,iBAAiB,uB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U,KAAK,EAAE;AAEzD,UAAM,IAAI;AAAA,MACR,wCAAwC,IAAI,MAAM,YAAY;AAAA,IAChE;AAAA,EACF;AACF;AAEA;AAAA,oBAAe,SAAC,KAAa,YAA4B;AACvD,QAAM,YAAY,iBAAiB,MAAM,UAAU;AACnD,SAAO;AACT;AAIM;AAAA,4BAAuB,iBAAuC;AAClE,QAAM,cAAc,MAAM,KAAK,OAAO,KAAK,eAAe;AAC1D,SAAO,EAAE,eAAe,UAAU,WAAW,GAAG;AAClD","sourcesContent":["import type { UserStoragePath } from '../controllers/user-storage/schema';\nimport { createEntryPath } from '../controllers/user-storage/schema';\nimport type { IBaseAuth } from './authentication-jwt-bearer/types';\nimport encryption, { createSHA256Hash } from './encryption';\nimport type { Env } from './env';\nimport { getEnvUrls } from './env';\nimport { NotFoundError, UserStorageError } from './errors';\n\nexport const STORAGE_URL = (env: Env, encryptedPath: string) =>\n `${getEnvUrls(env).userStorageApiUrl}/api/v1/userstorage/${encryptedPath}`;\n\nexport type UserStorageConfig = {\n env: Env;\n auth: Pick<IBaseAuth, 'getAccessToken' | 'getUserProfile' | 'signMessage'>;\n};\n\nexport type StorageOptions = {\n getStorageKey: () => Promise<string | null>;\n setStorageKey: (val: string) => Promise<void>;\n};\n\nexport type UserStorageOptions = {\n storage?: StorageOptions;\n};\n\ntype ErrorMessage = {\n message: string;\n error: string;\n};\n\nexport class UserStorage {\n protected config: UserStorageConfig;\n\n protected options: UserStorageOptions;\n\n protected env: Env;\n\n constructor(config: UserStorageConfig, options: UserStorageOptions) {\n this.env = config.env;\n this.config = config;\n this.options = options;\n }\n\n async setItem(path: UserStoragePath, value: string): Promise<void> {\n await this.#upsertUserStorage(path, value);\n }\n\n async getItem(path: UserStoragePath): Promise<string> {\n return this.#getUserStorage(path);\n }\n\n async getStorageKey(): Promise<string> {\n const storageKey = await this.options.storage?.getStorageKey();\n if (storageKey) {\n return storageKey;\n }\n\n const userProfile = await this.config.auth.getUserProfile();\n const storageKeySignature = await this.config.auth.signMessage(\n `metamask:${userProfile.profileId}`,\n );\n const hashedStorageKeySignature = createSHA256Hash(storageKeySignature);\n await this.options.storage?.setStorageKey(hashedStorageKeySignature);\n return hashedStorageKeySignature;\n }\n\n async #upsertUserStorage(path: UserStoragePath, data: string): Promise<void> {\n try {\n const headers = await this.#getAuthorizationHeader();\n const storageKey = await this.getStorageKey();\n const encryptedData = encryption.encryptString(data, storageKey);\n const encryptedPath = createEntryPath(path, storageKey);\n\n const url = new URL(STORAGE_URL(this.env, encryptedPath));\n\n const response = await fetch(url.toString(), {\n method: 'PUT',\n headers: {\n 'Content-Type': 'application/json',\n ...headers,\n },\n body: JSON.stringify({ data: encryptedData }),\n });\n\n if (!response.ok) {\n const responseBody: ErrorMessage = await response.json().catch(() => ({\n message: 'unknown',\n error: 'unknown',\n }));\n throw new Error(\n `HTTP error message: ${responseBody.message}, error: ${responseBody.error}`,\n );\n }\n } catch (e) {\n /* istanbul ignore next */\n const errorMessage =\n e instanceof Error ? e.message : JSON.stringify(e ?? '');\n throw new UserStorageError(\n `failed to upsert user storage for path '${path}'. ${errorMessage}`,\n );\n }\n }\n\n async #getUserStorage(path: UserStoragePath): Promise<string> {\n try {\n const headers = await this.#getAuthorizationHeader();\n const storageKey = await this.getStorageKey();\n const encryptedPath = createEntryPath(path, storageKey);\n\n const url = new URL(STORAGE_URL(this.env, encryptedPath));\n\n const response = await fetch(url.toString(), {\n headers: {\n 'Content-Type': 'application/json',\n ...headers,\n },\n });\n\n if (response.status === 404) {\n throw new NotFoundError(\n `feature/key set not found for path '${path}'.`,\n );\n }\n\n if (!response.ok) {\n const responseBody = (await response.json()) as ErrorMessage;\n throw new Error(\n `HTTP error message: ${responseBody.message}, error: ${responseBody.error}`,\n );\n }\n\n const { Data: encryptedData } = await response.json();\n return encryption.decryptString(encryptedData, storageKey);\n } catch (e) {\n if (e instanceof NotFoundError) {\n throw e;\n }\n\n /* istanbul ignore next */\n const errorMessage =\n e instanceof Error ? e.message : JSON.stringify(e ?? '');\n\n throw new UserStorageError(\n `failed to get user storage for path '${path}'. ${errorMessage}`,\n );\n }\n }\n\n #createEntryKey(key: string, storageKey: string): string {\n const hashedKey = createSHA256Hash(key + storageKey);\n return hashedKey;\n }\n\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n async #getAuthorizationHeader(): Promise<{ Authorization: string }> {\n const accessToken = await this.config.auth.getAccessToken();\n return { Authorization: `Bearer ${accessToken}` };\n }\n}\n"]}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createSHA256Hash
|
|
3
|
+
} from "./chunk-K5UKU454.mjs";
|
|
4
|
+
|
|
5
|
+
// src/controllers/user-storage/schema.ts
|
|
6
|
+
var USER_STORAGE_SCHEMA = {
|
|
7
|
+
notifications: ["notificationSettings"]
|
|
8
|
+
};
|
|
9
|
+
var getFeatureAndKeyFromPath = (path) => {
|
|
10
|
+
const pathRegex = /^\w+\.\w+$/u;
|
|
11
|
+
if (!pathRegex.test(path)) {
|
|
12
|
+
throw new Error(
|
|
13
|
+
`user-storage - path is not in the correct format. Correct format: 'feature.key'`
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
const [feature, key] = path.split(".");
|
|
17
|
+
if (!(feature in USER_STORAGE_SCHEMA)) {
|
|
18
|
+
throw new Error(`user-storage - invalid feature provided: ${feature}`);
|
|
19
|
+
}
|
|
20
|
+
const validFeature = USER_STORAGE_SCHEMA[feature];
|
|
21
|
+
if (!validFeature.includes(key)) {
|
|
22
|
+
const validKeys = USER_STORAGE_SCHEMA[feature].join(", ");
|
|
23
|
+
throw new Error(
|
|
24
|
+
`user-storage - invalid key provided for this feature: ${key}. Valid keys: ${validKeys}`
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
return { feature, key };
|
|
28
|
+
};
|
|
29
|
+
function createEntryPath(path, storageKey) {
|
|
30
|
+
const { feature, key } = getFeatureAndKeyFromPath(path);
|
|
31
|
+
const hashedKey = createSHA256Hash(key + storageKey);
|
|
32
|
+
return `/${feature}/${hashedKey}`;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export {
|
|
36
|
+
USER_STORAGE_SCHEMA,
|
|
37
|
+
getFeatureAndKeyFromPath,
|
|
38
|
+
createEntryPath
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=chunk-ILIZJQ6X.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/controllers/user-storage/schema.ts"],"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\nexport const USER_STORAGE_SCHEMA = {\n notifications: ['notificationSettings'],\n} as const;\n\ntype UserStorageSchema = typeof USER_STORAGE_SCHEMA;\ntype UserStorageFeatures = keyof UserStorageSchema;\ntype UserStorageFeatureKeys<Feature extends UserStorageFeatures> =\n UserStorageSchema[Feature][number];\n\ntype UserStorageFeatureAndKey = {\n feature: UserStorageFeatures;\n key: UserStorageFeatureKeys<UserStorageFeatures>;\n};\n\nexport type UserStoragePath = {\n [K in keyof UserStorageSchema]: `${K}.${UserStorageSchema[K][number]}`;\n}[keyof UserStorageSchema];\n\nexport const getFeatureAndKeyFromPath = (\n path: UserStoragePath,\n): UserStorageFeatureAndKey => {\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('.') as [\n UserStorageFeatures,\n UserStorageFeatureKeys<UserStorageFeatures>,\n ];\n\n if (!(feature in USER_STORAGE_SCHEMA)) {\n throw new Error(`user-storage - invalid feature provided: ${feature}`);\n }\n\n const validFeature = USER_STORAGE_SCHEMA[feature] as readonly string[];\n\n if (!validFeature.includes(key)) {\n const validKeys = USER_STORAGE_SCHEMA[feature].join(', ');\n\n throw new Error(\n `user-storage - invalid key provided for this feature: ${key}. Valid keys: ${validKeys}`,\n );\n }\n\n return { feature, key };\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: UserStoragePath,\n storageKey: string,\n): string {\n const { feature, key } = getFeatureAndKeyFromPath(path);\n const hashedKey = createSHA256Hash(key + storageKey);\n\n return `/${feature}/${hashedKey}`;\n}\n"],"mappings":";;;;;AAOO,IAAM,sBAAsB;AAAA,EACjC,eAAe,CAAC,sBAAsB;AACxC;AAgBO,IAAM,2BAA2B,CACtC,SAC6B;AAC7B,QAAM,YAAY;AAElB,MAAI,CAAC,UAAU,KAAK,IAAI,GAAG;AACzB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,QAAM,CAAC,SAAS,GAAG,IAAI,KAAK,MAAM,GAAG;AAKrC,MAAI,EAAE,WAAW,sBAAsB;AACrC,UAAM,IAAI,MAAM,4CAA4C,OAAO,EAAE;AAAA,EACvE;AAEA,QAAM,eAAe,oBAAoB,OAAO;AAEhD,MAAI,CAAC,aAAa,SAAS,GAAG,GAAG;AAC/B,UAAM,YAAY,oBAAoB,OAAO,EAAE,KAAK,IAAI;AAExD,UAAM,IAAI;AAAA,MACR,yDAAyD,GAAG,iBAAiB,SAAS;AAAA,IACxF;AAAA,EACF;AAEA,SAAO,EAAE,SAAS,IAAI;AACxB;AAWO,SAAS,gBACd,MACA,YACQ;AACR,QAAM,EAAE,SAAS,IAAI,IAAI,yBAAyB,IAAI;AACtD,QAAM,YAAY,iBAAiB,MAAM,UAAU;AAEnD,SAAO,IAAI,OAAO,IAAI,SAAS;AACjC;","names":[]}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
UserStorageController,
|
|
3
3
|
defaultState
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-LNSB4L7K.mjs";
|
|
5
5
|
import {
|
|
6
6
|
USER_STORAGE_ENDPOINT
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-FU7PSGFP.mjs";
|
|
8
8
|
import {
|
|
9
9
|
createEntryPath
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-ILIZJQ6X.mjs";
|
|
11
11
|
import {
|
|
12
12
|
encryption_default as encryption_default2
|
|
13
13
|
} from "./chunk-5TOWF6UW.mjs";
|
|
@@ -52,7 +52,7 @@ var MOCK_ENCRYPTED_STORAGE_DATA = encryption_default2.encryptString(
|
|
|
52
52
|
|
|
53
53
|
// src/controllers/user-storage/__fixtures__/mockResponses.ts
|
|
54
54
|
var MOCK_USER_STORAGE_NOTIFICATIONS_ENDPOINT = `${USER_STORAGE_ENDPOINT}${createEntryPath(
|
|
55
|
-
"notificationSettings",
|
|
55
|
+
"notifications.notificationSettings",
|
|
56
56
|
MOCK_STORAGE_KEY
|
|
57
57
|
)}`;
|
|
58
58
|
var MOCK_GET_USER_STORAGE_RESPONSE = {
|
|
@@ -78,4 +78,4 @@ export {
|
|
|
78
78
|
fixtures_exports,
|
|
79
79
|
user_storage_exports
|
|
80
80
|
};
|
|
81
|
-
//# sourceMappingURL=chunk-
|
|
81
|
+
//# sourceMappingURL=chunk-IQECLCH4.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/controllers/user-storage/index.ts","../src/controllers/user-storage/__fixtures__/index.ts","../src/controllers/user-storage/__fixtures__/mockStorage.ts","../src/controllers/user-storage/__fixtures__/mockResponses.ts"],"sourcesContent":["import Controller from './UserStorageController';\n\nexport { Controller };\nexport * from './UserStorageController';\nexport * from './encryption';\nexport * as Mocks from './__fixtures__';\n","export * from './mockResponses';\nexport * from './mockStorage';\n","import encryption, { createSHA256Hash } from '../encryption';\n\nexport const MOCK_STORAGE_KEY_SIGNATURE = 'mockStorageKey';\nexport const MOCK_STORAGE_KEY = createSHA256Hash(MOCK_STORAGE_KEY_SIGNATURE);\nexport const MOCK_STORAGE_DATA = JSON.stringify({ hello: 'world' });\nexport const MOCK_ENCRYPTED_STORAGE_DATA = encryption.encryptString(\n MOCK_STORAGE_DATA,\n MOCK_STORAGE_KEY,\n);\n","import { createEntryPath } from '../schema';\nimport type { GetUserStorageResponse } from '../services';\nimport { USER_STORAGE_ENDPOINT } from '../services';\nimport { MOCK_ENCRYPTED_STORAGE_DATA, MOCK_STORAGE_KEY } from './mockStorage';\n\ntype MockResponse = {\n url: string;\n requestMethod: 'GET' | 'POST' | 'PUT';\n response: unknown;\n};\n\nexport const MOCK_USER_STORAGE_NOTIFICATIONS_ENDPOINT = `${USER_STORAGE_ENDPOINT}${createEntryPath(\n 'notificationSettings',\n MOCK_STORAGE_KEY,\n)}`;\n\nconst MOCK_GET_USER_STORAGE_RESPONSE: GetUserStorageResponse = {\n HashedKey: 'HASHED_KEY',\n Data: MOCK_ENCRYPTED_STORAGE_DATA,\n};\n\nexport const getMockUserStorageGetResponse = () => {\n return {\n url: MOCK_USER_STORAGE_NOTIFICATIONS_ENDPOINT,\n requestMethod: 'GET',\n response: MOCK_GET_USER_STORAGE_RESPONSE,\n } satisfies MockResponse;\n};\n\nexport const getMockUserStoragePutResponse = () => {\n return {\n url: MOCK_USER_STORAGE_NOTIFICATIONS_ENDPOINT,\n requestMethod: 'PUT',\n response: null,\n } satisfies MockResponse;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEO,IAAM,6BAA6B;AACnC,IAAM,mBAAmB,iBAAiB,0BAA0B;AACpE,IAAM,oBAAoB,KAAK,UAAU,EAAE,OAAO,QAAQ,CAAC;AAC3D,IAAM,8BAA8BA,oBAAW;AAAA,EACpD;AAAA,EACA;AACF;;;ACGO,IAAM,2CAA2C,GAAG,qBAAqB,GAAG;AAAA,EACjF;AAAA,EACA;AACF,CAAC;AAED,IAAM,iCAAyD;AAAA,EAC7D,WAAW;AAAA,EACX,MAAM;AACR;AAEO,IAAM,gCAAgC,MAAM;AACjD,SAAO;AAAA,IACL,KAAK;AAAA,IACL,eAAe;AAAA,IACf,UAAU;AAAA,EACZ;AACF;AAEO,IAAM,gCAAgC,MAAM;AACjD,SAAO;AAAA,IACL,KAAK;AAAA,IACL,eAAe;AAAA,IACf,UAAU;AAAA,EACZ;AACF;","names":["encryption_default"]}
|
|
1
|
+
{"version":3,"sources":["../src/controllers/user-storage/index.ts","../src/controllers/user-storage/__fixtures__/index.ts","../src/controllers/user-storage/__fixtures__/mockStorage.ts","../src/controllers/user-storage/__fixtures__/mockResponses.ts"],"sourcesContent":["import Controller from './UserStorageController';\n\nexport { Controller };\nexport * from './UserStorageController';\nexport * from './encryption';\nexport * as Mocks from './__fixtures__';\n","export * from './mockResponses';\nexport * from './mockStorage';\n","import encryption, { createSHA256Hash } from '../encryption';\n\nexport const MOCK_STORAGE_KEY_SIGNATURE = 'mockStorageKey';\nexport const MOCK_STORAGE_KEY = createSHA256Hash(MOCK_STORAGE_KEY_SIGNATURE);\nexport const MOCK_STORAGE_DATA = JSON.stringify({ hello: 'world' });\nexport const MOCK_ENCRYPTED_STORAGE_DATA = encryption.encryptString(\n MOCK_STORAGE_DATA,\n MOCK_STORAGE_KEY,\n);\n","import { createEntryPath } from '../schema';\nimport type { GetUserStorageResponse } from '../services';\nimport { USER_STORAGE_ENDPOINT } from '../services';\nimport { MOCK_ENCRYPTED_STORAGE_DATA, MOCK_STORAGE_KEY } from './mockStorage';\n\ntype MockResponse = {\n url: string;\n requestMethod: 'GET' | 'POST' | 'PUT';\n response: unknown;\n};\n\nexport const MOCK_USER_STORAGE_NOTIFICATIONS_ENDPOINT = `${USER_STORAGE_ENDPOINT}${createEntryPath(\n 'notifications.notificationSettings',\n MOCK_STORAGE_KEY,\n)}`;\n\nconst MOCK_GET_USER_STORAGE_RESPONSE: GetUserStorageResponse = {\n HashedKey: 'HASHED_KEY',\n Data: MOCK_ENCRYPTED_STORAGE_DATA,\n};\n\nexport const getMockUserStorageGetResponse = () => {\n return {\n url: MOCK_USER_STORAGE_NOTIFICATIONS_ENDPOINT,\n requestMethod: 'GET',\n response: MOCK_GET_USER_STORAGE_RESPONSE,\n } satisfies MockResponse;\n};\n\nexport const getMockUserStoragePutResponse = () => {\n return {\n url: MOCK_USER_STORAGE_NOTIFICATIONS_ENDPOINT,\n requestMethod: 'PUT',\n response: null,\n } satisfies MockResponse;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEO,IAAM,6BAA6B;AACnC,IAAM,mBAAmB,iBAAiB,0BAA0B;AACpE,IAAM,oBAAoB,KAAK,UAAU,EAAE,OAAO,QAAQ,CAAC;AAC3D,IAAM,8BAA8BA,oBAAW;AAAA,EACpD;AAAA,EACA;AACF;;;ACGO,IAAM,2CAA2C,GAAG,qBAAqB,GAAG;AAAA,EACjF;AAAA,EACA;AACF,CAAC;AAED,IAAM,iCAAyD;AAAA,EAC7D,WAAW;AAAA,EACX,MAAM;AACR;AAEO,IAAM,gCAAgC,MAAM;AACjD,SAAO;AAAA,IACL,KAAK;AAAA,IACL,eAAe;AAAA,IACf,UAAU;AAAA,EACZ;AACF;AAEO,IAAM,gCAAgC,MAAM;AACjD,SAAO;AAAA,IACL,KAAK;AAAA,IACL,eAAe;AAAA,IACf,UAAU;AAAA,EACZ;AACF;","names":["encryption_default"]}
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
import {
|
|
5
5
|
getUserStorage,
|
|
6
6
|
upsertUserStorage
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-FU7PSGFP.mjs";
|
|
8
8
|
import {
|
|
9
9
|
createSHA256Hash
|
|
10
10
|
} from "./chunk-K5UKU454.mjs";
|
|
@@ -161,14 +161,14 @@ var UserStorageController = class extends BaseController {
|
|
|
161
161
|
* Allows retrieval of stored data. Data stored is string formatted.
|
|
162
162
|
* Developers can extend the entry path and entry name through the `schema.ts` file.
|
|
163
163
|
*
|
|
164
|
-
* @param
|
|
164
|
+
* @param path - string in the form of `${feature}.${key}` that matches schema
|
|
165
165
|
* @returns the decrypted string contents found from user storage (or null if not found)
|
|
166
166
|
*/
|
|
167
|
-
async performGetStorage(
|
|
167
|
+
async performGetStorage(path) {
|
|
168
168
|
__privateMethod(this, _assertProfileSyncingEnabled, assertProfileSyncingEnabled_fn).call(this);
|
|
169
169
|
const { bearerToken, storageKey } = await __privateMethod(this, _getStorageKeyAndBearerToken, getStorageKeyAndBearerToken_fn).call(this);
|
|
170
170
|
const result = await getUserStorage({
|
|
171
|
-
|
|
171
|
+
path,
|
|
172
172
|
bearerToken,
|
|
173
173
|
storageKey
|
|
174
174
|
});
|
|
@@ -178,15 +178,15 @@ var UserStorageController = class extends BaseController {
|
|
|
178
178
|
* Allows storage of user data. Data stored must be string formatted.
|
|
179
179
|
* Developers can extend the entry path and entry name through the `schema.ts` file.
|
|
180
180
|
*
|
|
181
|
-
* @param
|
|
181
|
+
* @param path - string in the form of `${feature}.${key}` that matches schema
|
|
182
182
|
* @param value - The string data you want to store.
|
|
183
183
|
* @returns nothing. NOTE that an error is thrown if fails to store data.
|
|
184
184
|
*/
|
|
185
|
-
async performSetStorage(
|
|
185
|
+
async performSetStorage(path, value) {
|
|
186
186
|
__privateMethod(this, _assertProfileSyncingEnabled, assertProfileSyncingEnabled_fn).call(this);
|
|
187
187
|
const { bearerToken, storageKey } = await __privateMethod(this, _getStorageKeyAndBearerToken, getStorageKeyAndBearerToken_fn).call(this);
|
|
188
188
|
await upsertUserStorage(value, {
|
|
189
|
-
|
|
189
|
+
path,
|
|
190
190
|
bearerToken,
|
|
191
191
|
storageKey
|
|
192
192
|
});
|
|
@@ -278,4 +278,4 @@ export {
|
|
|
278
278
|
defaultState,
|
|
279
279
|
UserStorageController
|
|
280
280
|
};
|
|
281
|
-
//# sourceMappingURL=chunk-
|
|
281
|
+
//# sourceMappingURL=chunk-LNSB4L7K.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/controllers/user-storage/UserStorageController.ts"],"sourcesContent":["import type {\n RestrictedControllerMessenger,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type { HandleSnapRequest } from '@metamask/snaps-controllers';\n\nimport { createSnapSignMessageRequest } from '../authentication/auth-snap-requests';\nimport type {\n AuthenticationControllerGetBearerToken,\n AuthenticationControllerGetSessionProfile,\n AuthenticationControllerIsSignedIn,\n AuthenticationControllerPerformSignIn,\n AuthenticationControllerPerformSignOut,\n} from '../authentication/AuthenticationController';\nimport { createSHA256Hash } from './encryption';\nimport type { UserStoragePath } from './schema';\nimport { getUserStorage, upsertUserStorage } from './services';\n\n// TODO: fix external dependencies\nexport declare type NotificationServicesControllerDisableNotificationServices =\n {\n type: `NotificationServicesController:disableNotificationServices`;\n handler: () => Promise<void>;\n };\n\nexport declare type NotificationServicesControllerSelectIsNotificationServicesEnabled =\n {\n type: `NotificationServicesController:selectIsNotificationServicesEnabled`;\n handler: () => boolean;\n };\n\nconst controllerName = 'UserStorageController';\n\n// State\nexport type UserStorageControllerState = {\n /**\n * Condition used by UI and to determine if we can use some of the User Storage methods.\n */\n isProfileSyncingEnabled: boolean | null;\n /**\n * Loading state for the profile syncing update\n */\n isProfileSyncingUpdateLoading: boolean;\n};\n\nexport const defaultState: UserStorageControllerState = {\n isProfileSyncingEnabled: true,\n isProfileSyncingUpdateLoading: false,\n};\n\nconst metadata: StateMetadata<UserStorageControllerState> = {\n isProfileSyncingEnabled: {\n persist: true,\n anonymous: true,\n },\n isProfileSyncingUpdateLoading: {\n persist: false,\n anonymous: false,\n },\n};\n\n// Messenger Actions\ntype CreateActionsObj<Controller extends keyof UserStorageController> = {\n [K in Controller]: {\n type: `${typeof controllerName}:${K}`;\n handler: UserStorageController[K];\n };\n};\ntype ActionsObj = CreateActionsObj<\n | 'performGetStorage'\n | 'performSetStorage'\n | 'getStorageKey'\n | 'enableProfileSyncing'\n | 'disableProfileSyncing'\n>;\nexport type Actions = ActionsObj[keyof ActionsObj];\nexport type UserStorageControllerPerformGetStorage =\n ActionsObj['performGetStorage'];\nexport type UserStorageControllerPerformSetStorage =\n ActionsObj['performSetStorage'];\nexport type UserStorageControllerGetStorageKey = ActionsObj['getStorageKey'];\nexport type UserStorageControllerEnableProfileSyncing =\n ActionsObj['enableProfileSyncing'];\nexport type UserStorageControllerDisableProfileSyncing =\n ActionsObj['disableProfileSyncing'];\n\n// Allowed Actions\nexport type AllowedActions =\n // Snap Requests\n | HandleSnapRequest\n // Auth Requests\n | AuthenticationControllerGetBearerToken\n | AuthenticationControllerGetSessionProfile\n | AuthenticationControllerPerformSignIn\n | AuthenticationControllerIsSignedIn\n | AuthenticationControllerPerformSignOut\n // Metamask Notifications\n | NotificationServicesControllerDisableNotificationServices\n | NotificationServicesControllerSelectIsNotificationServicesEnabled;\n\n// Messenger\nexport type UserStorageControllerMessenger = RestrictedControllerMessenger<\n typeof controllerName,\n Actions | AllowedActions,\n never,\n AllowedActions['type'],\n never\n>;\n\n/**\n * Reusable controller that allows any team to store synchronized data for a given user.\n * These can be settings shared cross MetaMask clients, or data we want to persist when uninstalling/reinstalling.\n *\n * NOTE:\n * - data stored on UserStorage is FULLY encrypted, with the only keys stored/managed on the client.\n * - No one can access this data unless they are have the SRP and are able to run the signing snap.\n */\nexport default class UserStorageController extends BaseController<\n typeof controllerName,\n UserStorageControllerState,\n UserStorageControllerMessenger\n> {\n #auth = {\n getBearerToken: async () => {\n return await this.messagingSystem.call(\n 'AuthenticationController:getBearerToken',\n );\n },\n getProfileId: async () => {\n const sessionProfile = await this.messagingSystem.call(\n 'AuthenticationController:getSessionProfile',\n );\n return sessionProfile?.profileId;\n },\n isAuthEnabled: () => {\n return this.messagingSystem.call('AuthenticationController:isSignedIn');\n },\n signIn: async () => {\n return await this.messagingSystem.call(\n 'AuthenticationController:performSignIn',\n );\n },\n signOut: async () => {\n return this.messagingSystem.call(\n 'AuthenticationController:performSignOut',\n );\n },\n };\n\n #notificationServices = {\n disableNotificationServices: async () => {\n return await this.messagingSystem.call(\n 'NotificationServicesController:disableNotificationServices',\n );\n },\n selectIsNotificationServicesEnabled: async () => {\n return this.messagingSystem.call(\n 'NotificationServicesController:selectIsNotificationServicesEnabled',\n );\n },\n };\n\n getMetaMetricsState: () => boolean;\n\n constructor(params: {\n messenger: UserStorageControllerMessenger;\n state?: UserStorageControllerState;\n getMetaMetricsState: () => boolean;\n }) {\n super({\n messenger: params.messenger,\n metadata,\n name: controllerName,\n state: { ...defaultState, ...params.state },\n });\n\n this.getMetaMetricsState = params.getMetaMetricsState;\n this.#registerMessageHandlers();\n }\n\n /**\n * Constructor helper for registering this controller's messaging system\n * actions.\n */\n #registerMessageHandlers(): void {\n this.messagingSystem.registerActionHandler(\n 'UserStorageController:performGetStorage',\n this.performGetStorage.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'UserStorageController:performSetStorage',\n this.performSetStorage.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'UserStorageController:getStorageKey',\n this.getStorageKey.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'UserStorageController:enableProfileSyncing',\n this.enableProfileSyncing.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'UserStorageController:disableProfileSyncing',\n this.disableProfileSyncing.bind(this),\n );\n }\n\n public async enableProfileSyncing(): Promise<void> {\n try {\n this.#setIsProfileSyncingUpdateLoading(true);\n\n const authEnabled = this.#auth.isAuthEnabled();\n if (!authEnabled) {\n await this.#auth.signIn();\n }\n\n this.update((state) => {\n state.isProfileSyncingEnabled = true;\n });\n\n this.#setIsProfileSyncingUpdateLoading(false);\n } catch (e) {\n this.#setIsProfileSyncingUpdateLoading(false);\n const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);\n throw new Error(\n `${controllerName} - failed to enable profile syncing - ${errorMessage}`,\n );\n }\n }\n\n public async setIsProfileSyncingEnabled(\n isProfileSyncingEnabled: boolean,\n ): Promise<void> {\n this.update((state) => {\n state.isProfileSyncingEnabled = isProfileSyncingEnabled;\n });\n }\n\n public async disableProfileSyncing(): Promise<void> {\n const isAlreadyDisabled = !this.state.isProfileSyncingEnabled;\n if (isAlreadyDisabled) {\n return;\n }\n\n try {\n this.#setIsProfileSyncingUpdateLoading(true);\n\n const isNotificationServicesEnabled =\n await this.#notificationServices.selectIsNotificationServicesEnabled();\n\n if (isNotificationServicesEnabled) {\n await this.#notificationServices.disableNotificationServices();\n }\n\n const isMetaMetricsParticipation = this.getMetaMetricsState();\n\n if (!isMetaMetricsParticipation) {\n this.messagingSystem.call('AuthenticationController:performSignOut');\n }\n\n this.#setIsProfileSyncingUpdateLoading(false);\n\n this.update((state) => {\n state.isProfileSyncingEnabled = false;\n });\n } catch (e) {\n this.#setIsProfileSyncingUpdateLoading(false);\n const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);\n throw new Error(\n `${controllerName} - failed to disable profile syncing - ${errorMessage}`,\n );\n }\n }\n\n /**\n * Allows retrieval of stored data. Data stored is string formatted.\n * Developers can extend the entry path and entry name through the `schema.ts` file.\n *\n * @param path - string in the form of `${feature}.${key}` that matches schema\n * @returns the decrypted string contents found from user storage (or null if not found)\n */\n public async performGetStorage(\n path: UserStoragePath,\n ): Promise<string | null> {\n this.#assertProfileSyncingEnabled();\n\n const { bearerToken, storageKey } =\n await this.#getStorageKeyAndBearerToken();\n\n const result = await getUserStorage({\n path,\n bearerToken,\n storageKey,\n });\n\n return result;\n }\n\n /**\n * Allows storage of user data. Data stored must be string formatted.\n * Developers can extend the entry path and entry name through the `schema.ts` file.\n *\n * @param path - string in the form of `${feature}.${key}` that matches schema\n * @param value - The string data you want to store.\n * @returns nothing. NOTE that an error is thrown if fails to store data.\n */\n public async performSetStorage(\n path: UserStoragePath,\n value: string,\n ): Promise<void> {\n this.#assertProfileSyncingEnabled();\n\n const { bearerToken, storageKey } =\n await this.#getStorageKeyAndBearerToken();\n\n await upsertUserStorage(value, {\n path,\n bearerToken,\n storageKey,\n });\n }\n\n /**\n * Retrieves the storage key, for internal use only!\n *\n * @returns the storage key\n */\n public async getStorageKey(): Promise<string> {\n this.#assertProfileSyncingEnabled();\n const storageKey = await this.#createStorageKey();\n return storageKey;\n }\n\n #assertProfileSyncingEnabled(): void {\n if (!this.state.isProfileSyncingEnabled) {\n throw new Error(\n `${controllerName}: Unable to call method, user is not authenticated`,\n );\n }\n }\n\n /**\n * Utility to get the bearer token and storage key\n */\n async #getStorageKeyAndBearerToken(): Promise<{\n bearerToken: string;\n storageKey: string;\n }> {\n const bearerToken = await this.#auth.getBearerToken();\n if (!bearerToken) {\n throw new Error('UserStorageController - unable to get bearer token');\n }\n const storageKey = await this.#createStorageKey();\n\n return { bearerToken, storageKey };\n }\n\n /**\n * Rather than storing the storage key, we can compute the storage key when needed.\n *\n * @returns the storage key\n */\n async #createStorageKey(): Promise<string> {\n const id: string = await this.#auth.getProfileId();\n if (!id) {\n throw new Error('UserStorageController - unable to create storage key');\n }\n\n const storageKeySignature = await this.#snapSignMessage(`metamask:${id}`);\n const storageKey = createSHA256Hash(storageKeySignature);\n return storageKey;\n }\n\n #_snapSignMessageCache: Record<`metamask:${string}`, string> = {};\n\n /**\n * Signs a specific message using an underlying auth snap.\n *\n * @param message - A specific tagged message to sign.\n * @returns A Signature created by the snap.\n */\n async #snapSignMessage(message: `metamask:${string}`): Promise<string> {\n if (this.#_snapSignMessageCache[message]) {\n return this.#_snapSignMessageCache[message];\n }\n\n const result = (await this.messagingSystem.call(\n 'SnapController:handleRequest',\n createSnapSignMessageRequest(message),\n )) as string;\n\n this.#_snapSignMessageCache[message] = result;\n\n return result;\n }\n\n #setIsProfileSyncingUpdateLoading(\n isProfileSyncingUpdateLoading: boolean,\n ): void {\n this.update((state) => {\n state.isProfileSyncingUpdateLoading = isProfileSyncingUpdateLoading;\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAIA,SAAS,sBAAsB;AA4B/B,IAAM,iBAAiB;AAchB,IAAM,eAA2C;AAAA,EACtD,yBAAyB;AAAA,EACzB,+BAA+B;AACjC;AAEA,IAAM,WAAsD;AAAA,EAC1D,yBAAyB;AAAA,IACvB,SAAS;AAAA,IACT,WAAW;AAAA,EACb;AAAA,EACA,+BAA+B;AAAA,IAC7B,SAAS;AAAA,IACT,WAAW;AAAA,EACb;AACF;AA5DA;AAsHA,IAAqB,wBAArB,cAAmD,eAIjD;AAAA,EA2CA,YAAY,QAIT;AACD,UAAM;AAAA,MACJ,WAAW,OAAO;AAAA,MAClB;AAAA,MACA,MAAM;AAAA,MACN,OAAO,EAAE,GAAG,cAAc,GAAG,OAAO,MAAM;AAAA,IAC5C,CAAC;AAUH;AAAA;AAAA;AAAA;AAAA;AAyJA;AAWA;AAAA;AAAA;AAAA,uBAAM;AAkBN;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAM;AAmBN;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAM;AAeN;AAtRA,8BAAQ;AAAA,MACN,gBAAgB,YAAY;AAC1B,eAAO,MAAM,KAAK,gBAAgB;AAAA,UAChC;AAAA,QACF;AAAA,MACF;AAAA,MACA,cAAc,YAAY;AACxB,cAAM,iBAAiB,MAAM,KAAK,gBAAgB;AAAA,UAChD;AAAA,QACF;AACA,eAAO,gBAAgB;AAAA,MACzB;AAAA,MACA,eAAe,MAAM;AACnB,eAAO,KAAK,gBAAgB,KAAK,qCAAqC;AAAA,MACxE;AAAA,MACA,QAAQ,YAAY;AAClB,eAAO,MAAM,KAAK,gBAAgB;AAAA,UAChC;AAAA,QACF;AAAA,MACF;AAAA,MACA,SAAS,YAAY;AACnB,eAAO,KA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