@metamask/profile-sync-controller 8.1.1 → 10.0.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/README.md +32 -0
- package/auth/mocks/package.json +2 -2
- package/dist/controllers/authentication/AuthenticationController.cjs +53 -86
- package/dist/controllers/authentication/AuthenticationController.cjs.map +1 -1
- package/dist/controllers/authentication/AuthenticationController.d.cts +11 -23
- package/dist/controllers/authentication/AuthenticationController.d.cts.map +1 -1
- package/dist/controllers/authentication/AuthenticationController.d.mts +11 -23
- package/dist/controllers/authentication/AuthenticationController.d.mts.map +1 -1
- package/dist/controllers/authentication/AuthenticationController.mjs +53 -86
- package/dist/controllers/authentication/AuthenticationController.mjs.map +1 -1
- package/dist/controllers/authentication/index.cjs +1 -1
- package/dist/controllers/authentication/index.cjs.map +1 -1
- package/dist/controllers/authentication/index.d.cts +1 -1
- package/dist/controllers/authentication/index.d.cts.map +1 -1
- package/dist/controllers/authentication/index.d.mts +1 -1
- package/dist/controllers/authentication/index.d.mts.map +1 -1
- package/dist/controllers/authentication/index.mjs +1 -1
- package/dist/controllers/authentication/index.mjs.map +1 -1
- package/dist/controllers/authentication/mocks/index.cjs.map +1 -0
- package/dist/controllers/authentication/mocks/index.d.cts.map +1 -0
- package/dist/controllers/authentication/mocks/index.d.mts.map +1 -0
- package/dist/controllers/authentication/mocks/index.mjs.map +1 -0
- package/dist/controllers/authentication/mocks/mockResponses.cjs +34 -0
- package/dist/controllers/authentication/mocks/mockResponses.cjs.map +1 -0
- package/dist/controllers/authentication/mocks/mockResponses.d.cts +55 -0
- package/dist/controllers/authentication/mocks/mockResponses.d.cts.map +1 -0
- package/dist/controllers/authentication/mocks/mockResponses.d.mts +55 -0
- package/dist/controllers/authentication/mocks/mockResponses.d.mts.map +1 -0
- package/dist/controllers/authentication/mocks/mockResponses.mjs +28 -0
- package/dist/controllers/authentication/mocks/mockResponses.mjs.map +1 -0
- package/dist/controllers/user-storage/UserStorageController.cjs +71 -127
- package/dist/controllers/user-storage/UserStorageController.cjs.map +1 -1
- package/dist/controllers/user-storage/UserStorageController.d.cts +5 -4
- package/dist/controllers/user-storage/UserStorageController.d.cts.map +1 -1
- package/dist/controllers/user-storage/UserStorageController.d.mts +5 -4
- package/dist/controllers/user-storage/UserStorageController.d.mts.map +1 -1
- package/dist/controllers/user-storage/UserStorageController.mjs +71 -127
- package/dist/controllers/user-storage/UserStorageController.mjs.map +1 -1
- package/dist/controllers/user-storage/account-syncing/controller-integration.cjs +2 -2
- package/dist/controllers/user-storage/account-syncing/controller-integration.cjs.map +1 -1
- package/dist/controllers/user-storage/account-syncing/controller-integration.mjs +2 -2
- package/dist/controllers/user-storage/account-syncing/controller-integration.mjs.map +1 -1
- package/dist/controllers/user-storage/account-syncing/sync-utils.cjs +1 -0
- package/dist/controllers/user-storage/account-syncing/sync-utils.cjs.map +1 -1
- package/dist/controllers/user-storage/account-syncing/sync-utils.d.cts.map +1 -1
- package/dist/controllers/user-storage/account-syncing/sync-utils.d.mts.map +1 -1
- package/dist/controllers/user-storage/account-syncing/sync-utils.mjs +1 -0
- package/dist/controllers/user-storage/account-syncing/sync-utils.mjs.map +1 -1
- package/dist/controllers/user-storage/account-syncing/utils.cjs +2 -2
- package/dist/controllers/user-storage/account-syncing/utils.cjs.map +1 -1
- package/dist/controllers/user-storage/account-syncing/utils.mjs +2 -2
- package/dist/controllers/user-storage/account-syncing/utils.mjs.map +1 -1
- package/dist/controllers/user-storage/index.cjs +1 -1
- package/dist/controllers/user-storage/index.cjs.map +1 -1
- package/dist/controllers/user-storage/index.d.cts +1 -1
- package/dist/controllers/user-storage/index.d.cts.map +1 -1
- package/dist/controllers/user-storage/index.d.mts +1 -1
- package/dist/controllers/user-storage/index.d.mts.map +1 -1
- package/dist/controllers/user-storage/index.mjs +1 -1
- package/dist/controllers/user-storage/index.mjs.map +1 -1
- package/dist/controllers/user-storage/mocks/index.cjs.map +1 -0
- package/dist/controllers/user-storage/mocks/index.d.cts.map +1 -0
- package/dist/controllers/user-storage/mocks/index.d.mts.map +1 -0
- package/dist/controllers/user-storage/mocks/index.mjs.map +1 -0
- package/dist/controllers/user-storage/{__fixtures__ → mocks}/mockResponses.cjs +3 -3
- package/dist/controllers/user-storage/mocks/mockResponses.cjs.map +1 -0
- package/dist/controllers/user-storage/{__fixtures__ → mocks}/mockResponses.d.cts +1 -1
- package/dist/controllers/user-storage/mocks/mockResponses.d.cts.map +1 -0
- package/dist/controllers/user-storage/{__fixtures__ → mocks}/mockResponses.d.mts +1 -1
- package/dist/controllers/user-storage/mocks/mockResponses.d.mts.map +1 -0
- package/dist/controllers/user-storage/{__fixtures__ → mocks}/mockResponses.mjs +3 -3
- package/dist/controllers/user-storage/mocks/mockResponses.mjs.map +1 -0
- package/dist/controllers/user-storage/mocks/mockStorage.cjs.map +1 -0
- package/dist/controllers/user-storage/mocks/mockStorage.d.cts.map +1 -0
- package/dist/controllers/user-storage/mocks/mockStorage.d.mts.map +1 -0
- package/dist/controllers/user-storage/mocks/mockStorage.mjs.map +1 -0
- package/dist/controllers/user-storage/network-syncing/controller-integration.cjs +14 -14
- package/dist/controllers/user-storage/network-syncing/controller-integration.cjs.map +1 -1
- package/dist/controllers/user-storage/network-syncing/controller-integration.d.cts +3 -3
- package/dist/controllers/user-storage/network-syncing/controller-integration.d.cts.map +1 -1
- package/dist/controllers/user-storage/network-syncing/controller-integration.d.mts +3 -3
- package/dist/controllers/user-storage/network-syncing/controller-integration.d.mts.map +1 -1
- package/dist/controllers/user-storage/network-syncing/controller-integration.mjs +14 -14
- package/dist/controllers/user-storage/network-syncing/controller-integration.mjs.map +1 -1
- package/dist/controllers/user-storage/network-syncing/services.cjs +27 -23
- package/dist/controllers/user-storage/network-syncing/services.cjs.map +1 -1
- package/dist/controllers/user-storage/network-syncing/services.d.cts +16 -7
- package/dist/controllers/user-storage/network-syncing/services.d.cts.map +1 -1
- package/dist/controllers/user-storage/network-syncing/services.d.mts +16 -7
- package/dist/controllers/user-storage/network-syncing/services.d.mts.map +1 -1
- package/dist/controllers/user-storage/network-syncing/services.mjs +27 -23
- package/dist/controllers/user-storage/network-syncing/services.mjs.map +1 -1
- package/dist/controllers/user-storage/network-syncing/sync-mutations.cjs.map +1 -1
- package/dist/controllers/user-storage/network-syncing/sync-mutations.d.cts +13 -5
- package/dist/controllers/user-storage/network-syncing/sync-mutations.d.cts.map +1 -1
- package/dist/controllers/user-storage/network-syncing/sync-mutations.d.mts +13 -5
- package/dist/controllers/user-storage/network-syncing/sync-mutations.d.mts.map +1 -1
- package/dist/controllers/user-storage/network-syncing/sync-mutations.mjs.map +1 -1
- package/dist/controllers/user-storage/types.cjs +3 -0
- package/dist/controllers/user-storage/types.cjs.map +1 -0
- package/dist/controllers/user-storage/types.d.cts +23 -0
- package/dist/controllers/user-storage/types.d.cts.map +1 -0
- package/dist/controllers/user-storage/types.d.mts +23 -0
- package/dist/controllers/user-storage/types.d.mts.map +1 -0
- package/dist/controllers/user-storage/types.mjs +2 -0
- package/dist/controllers/user-storage/types.mjs.map +1 -0
- package/dist/sdk/authentication-jwt-bearer/flow-srp.cjs +7 -8
- package/dist/sdk/authentication-jwt-bearer/flow-srp.cjs.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/flow-srp.d.cts +2 -0
- package/dist/sdk/authentication-jwt-bearer/flow-srp.d.cts.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/flow-srp.d.mts +2 -0
- package/dist/sdk/authentication-jwt-bearer/flow-srp.d.mts.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/flow-srp.mjs +8 -9
- package/dist/sdk/authentication-jwt-bearer/flow-srp.mjs.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/services.cjs +10 -2
- package/dist/sdk/authentication-jwt-bearer/services.cjs.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/services.d.cts +3 -1
- package/dist/sdk/authentication-jwt-bearer/services.d.cts.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/services.d.mts +3 -1
- package/dist/sdk/authentication-jwt-bearer/services.d.mts.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/services.mjs +10 -2
- package/dist/sdk/authentication-jwt-bearer/services.mjs.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/types.cjs.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/types.mjs.map +1 -1
- package/dist/sdk/authentication.cjs.map +1 -1
- package/dist/sdk/authentication.d.cts +1 -1
- package/dist/sdk/authentication.d.cts.map +1 -1
- package/dist/sdk/authentication.d.mts +1 -1
- package/dist/sdk/authentication.d.mts.map +1 -1
- package/dist/sdk/authentication.mjs.map +1 -1
- package/dist/sdk/mocks/auth.cjs +44 -0
- package/dist/sdk/mocks/auth.cjs.map +1 -0
- package/dist/sdk/{__fixtures__/mock-auth.d.cts → mocks/auth.d.cts} +22 -25
- package/dist/sdk/mocks/auth.d.cts.map +1 -0
- package/dist/sdk/{__fixtures__/mock-auth.d.mts → mocks/auth.d.mts} +22 -25
- package/dist/sdk/mocks/auth.d.mts.map +1 -0
- package/dist/sdk/mocks/auth.mjs +41 -0
- package/dist/sdk/mocks/auth.mjs.map +1 -0
- package/dist/sdk/mocks/userstorage.cjs +43 -0
- package/dist/sdk/mocks/userstorage.cjs.map +1 -0
- package/dist/sdk/mocks/userstorage.d.cts +10 -0
- package/dist/sdk/mocks/userstorage.d.cts.map +1 -0
- package/dist/sdk/mocks/userstorage.d.mts +10 -0
- package/dist/sdk/mocks/userstorage.d.mts.map +1 -0
- package/dist/sdk/mocks/userstorage.mjs +15 -0
- package/dist/sdk/mocks/userstorage.mjs.map +1 -0
- package/dist/sdk/user-storage.cjs +34 -39
- package/dist/sdk/user-storage.cjs.map +1 -1
- package/dist/sdk/user-storage.d.cts +11 -6
- package/dist/sdk/user-storage.d.cts.map +1 -1
- package/dist/sdk/user-storage.d.mts +11 -6
- package/dist/sdk/user-storage.d.mts.map +1 -1
- package/dist/sdk/user-storage.mjs +34 -39
- package/dist/sdk/user-storage.mjs.map +1 -1
- package/dist/sdk/utils/messaging-signing-snap-requests.cjs +12 -1
- package/dist/sdk/utils/messaging-signing-snap-requests.cjs.map +1 -1
- package/dist/sdk/utils/messaging-signing-snap-requests.d.cts +6 -0
- package/dist/sdk/utils/messaging-signing-snap-requests.d.cts.map +1 -1
- package/dist/sdk/utils/messaging-signing-snap-requests.d.mts +6 -0
- package/dist/sdk/utils/messaging-signing-snap-requests.d.mts.map +1 -1
- package/dist/sdk/utils/messaging-signing-snap-requests.mjs +10 -0
- package/dist/sdk/utils/messaging-signing-snap-requests.mjs.map +1 -1
- package/dist/shared/types/services.cjs +3 -0
- package/dist/shared/types/services.cjs.map +1 -0
- package/dist/shared/types/services.d.cts +10 -0
- package/dist/shared/types/services.d.cts.map +1 -0
- package/dist/shared/types/services.d.mts +10 -0
- package/dist/shared/types/services.d.mts.map +1 -0
- package/dist/shared/types/services.mjs +2 -0
- package/dist/shared/types/services.mjs.map +1 -0
- package/package.json +14 -14
- package/user-storage/mocks/package.json +2 -2
- package/dist/controllers/authentication/__fixtures__/index.cjs.map +0 -1
- package/dist/controllers/authentication/__fixtures__/index.d.cts.map +0 -1
- package/dist/controllers/authentication/__fixtures__/index.d.mts.map +0 -1
- package/dist/controllers/authentication/__fixtures__/index.mjs.map +0 -1
- package/dist/controllers/authentication/__fixtures__/mockResponses.cjs +0 -47
- package/dist/controllers/authentication/__fixtures__/mockResponses.cjs.map +0 -1
- package/dist/controllers/authentication/__fixtures__/mockResponses.d.cts +0 -23
- package/dist/controllers/authentication/__fixtures__/mockResponses.d.cts.map +0 -1
- package/dist/controllers/authentication/__fixtures__/mockResponses.d.mts +0 -23
- package/dist/controllers/authentication/__fixtures__/mockResponses.d.mts.map +0 -1
- package/dist/controllers/authentication/__fixtures__/mockResponses.mjs +0 -41
- package/dist/controllers/authentication/__fixtures__/mockResponses.mjs.map +0 -1
- package/dist/controllers/authentication/__fixtures__/mockServices.cjs +0 -37
- package/dist/controllers/authentication/__fixtures__/mockServices.cjs.map +0 -1
- package/dist/controllers/authentication/__fixtures__/mockServices.d.cts +0 -10
- package/dist/controllers/authentication/__fixtures__/mockServices.d.cts.map +0 -1
- package/dist/controllers/authentication/__fixtures__/mockServices.d.mts +0 -10
- package/dist/controllers/authentication/__fixtures__/mockServices.d.mts.map +0 -1
- package/dist/controllers/authentication/__fixtures__/mockServices.mjs +0 -35
- package/dist/controllers/authentication/__fixtures__/mockServices.mjs.map +0 -1
- package/dist/controllers/authentication/services.cjs +0 -132
- package/dist/controllers/authentication/services.cjs.map +0 -1
- package/dist/controllers/authentication/services.d.cts +0 -72
- package/dist/controllers/authentication/services.d.cts.map +0 -1
- package/dist/controllers/authentication/services.d.mts +0 -72
- package/dist/controllers/authentication/services.d.mts.map +0 -1
- package/dist/controllers/authentication/services.mjs +0 -129
- package/dist/controllers/authentication/services.mjs.map +0 -1
- package/dist/controllers/user-storage/__fixtures__/index.cjs.map +0 -1
- package/dist/controllers/user-storage/__fixtures__/index.d.cts.map +0 -1
- package/dist/controllers/user-storage/__fixtures__/index.d.mts.map +0 -1
- package/dist/controllers/user-storage/__fixtures__/index.mjs.map +0 -1
- package/dist/controllers/user-storage/__fixtures__/mockMessenger.cjs +0 -167
- package/dist/controllers/user-storage/__fixtures__/mockMessenger.cjs.map +0 -1
- package/dist/controllers/user-storage/__fixtures__/mockMessenger.d.cts +0 -105
- package/dist/controllers/user-storage/__fixtures__/mockMessenger.d.cts.map +0 -1
- package/dist/controllers/user-storage/__fixtures__/mockMessenger.d.mts +0 -105
- package/dist/controllers/user-storage/__fixtures__/mockMessenger.d.mts.map +0 -1
- package/dist/controllers/user-storage/__fixtures__/mockMessenger.mjs +0 -162
- package/dist/controllers/user-storage/__fixtures__/mockMessenger.mjs.map +0 -1
- package/dist/controllers/user-storage/__fixtures__/mockResponses.cjs.map +0 -1
- package/dist/controllers/user-storage/__fixtures__/mockResponses.d.cts.map +0 -1
- package/dist/controllers/user-storage/__fixtures__/mockResponses.d.mts.map +0 -1
- package/dist/controllers/user-storage/__fixtures__/mockResponses.mjs.map +0 -1
- package/dist/controllers/user-storage/__fixtures__/mockServices.cjs +0 -82
- package/dist/controllers/user-storage/__fixtures__/mockServices.cjs.map +0 -1
- package/dist/controllers/user-storage/__fixtures__/mockServices.d.cts +0 -15
- package/dist/controllers/user-storage/__fixtures__/mockServices.d.cts.map +0 -1
- package/dist/controllers/user-storage/__fixtures__/mockServices.d.mts +0 -15
- package/dist/controllers/user-storage/__fixtures__/mockServices.d.mts.map +0 -1
- package/dist/controllers/user-storage/__fixtures__/mockServices.mjs +0 -76
- package/dist/controllers/user-storage/__fixtures__/mockServices.mjs.map +0 -1
- package/dist/controllers/user-storage/__fixtures__/mockStorage.cjs.map +0 -1
- package/dist/controllers/user-storage/__fixtures__/mockStorage.d.cts.map +0 -1
- package/dist/controllers/user-storage/__fixtures__/mockStorage.d.mts.map +0 -1
- package/dist/controllers/user-storage/__fixtures__/mockStorage.mjs.map +0 -1
- package/dist/controllers/user-storage/__fixtures__/test-utils.cjs +0 -78
- package/dist/controllers/user-storage/__fixtures__/test-utils.cjs.map +0 -1
- package/dist/controllers/user-storage/__fixtures__/test-utils.d.cts +0 -38
- package/dist/controllers/user-storage/__fixtures__/test-utils.d.cts.map +0 -1
- package/dist/controllers/user-storage/__fixtures__/test-utils.d.mts +0 -38
- package/dist/controllers/user-storage/__fixtures__/test-utils.d.mts.map +0 -1
- package/dist/controllers/user-storage/__fixtures__/test-utils.mjs +0 -68
- package/dist/controllers/user-storage/__fixtures__/test-utils.mjs.map +0 -1
- package/dist/controllers/user-storage/account-syncing/__fixtures__/mockAccounts.cjs +0 -178
- package/dist/controllers/user-storage/account-syncing/__fixtures__/mockAccounts.cjs.map +0 -1
- package/dist/controllers/user-storage/account-syncing/__fixtures__/mockAccounts.d.cts +0 -91
- package/dist/controllers/user-storage/account-syncing/__fixtures__/mockAccounts.d.cts.map +0 -1
- package/dist/controllers/user-storage/account-syncing/__fixtures__/mockAccounts.d.mts +0 -91
- package/dist/controllers/user-storage/account-syncing/__fixtures__/mockAccounts.d.mts.map +0 -1
- package/dist/controllers/user-storage/account-syncing/__fixtures__/mockAccounts.mjs +0 -174
- package/dist/controllers/user-storage/account-syncing/__fixtures__/mockAccounts.mjs.map +0 -1
- package/dist/controllers/user-storage/account-syncing/__fixtures__/test-utils.cjs +0 -58
- package/dist/controllers/user-storage/account-syncing/__fixtures__/test-utils.cjs.map +0 -1
- package/dist/controllers/user-storage/account-syncing/__fixtures__/test-utils.d.cts +0 -87
- package/dist/controllers/user-storage/account-syncing/__fixtures__/test-utils.d.cts.map +0 -1
- package/dist/controllers/user-storage/account-syncing/__fixtures__/test-utils.d.mts +0 -87
- package/dist/controllers/user-storage/account-syncing/__fixtures__/test-utils.d.mts.map +0 -1
- package/dist/controllers/user-storage/account-syncing/__fixtures__/test-utils.mjs +0 -52
- package/dist/controllers/user-storage/account-syncing/__fixtures__/test-utils.mjs.map +0 -1
- package/dist/controllers/user-storage/network-syncing/__fixtures__/mockNetwork.cjs +0 -43
- package/dist/controllers/user-storage/network-syncing/__fixtures__/mockNetwork.cjs.map +0 -1
- package/dist/controllers/user-storage/network-syncing/__fixtures__/mockNetwork.d.cts +0 -11
- package/dist/controllers/user-storage/network-syncing/__fixtures__/mockNetwork.d.cts.map +0 -1
- package/dist/controllers/user-storage/network-syncing/__fixtures__/mockNetwork.d.mts +0 -11
- package/dist/controllers/user-storage/network-syncing/__fixtures__/mockNetwork.d.mts.map +0 -1
- package/dist/controllers/user-storage/network-syncing/__fixtures__/mockNetwork.mjs +0 -36
- package/dist/controllers/user-storage/network-syncing/__fixtures__/mockNetwork.mjs.map +0 -1
- package/dist/controllers/user-storage/services.cjs +0 -306
- package/dist/controllers/user-storage/services.cjs.map +0 -1
- package/dist/controllers/user-storage/services.d.cts +0 -85
- package/dist/controllers/user-storage/services.d.cts.map +0 -1
- package/dist/controllers/user-storage/services.d.mts +0 -85
- package/dist/controllers/user-storage/services.d.mts.map +0 -1
- package/dist/controllers/user-storage/services.mjs +0 -276
- package/dist/controllers/user-storage/services.mjs.map +0 -1
- package/dist/sdk/__fixtures__/mock-auth.cjs +0 -124
- package/dist/sdk/__fixtures__/mock-auth.cjs.map +0 -1
- package/dist/sdk/__fixtures__/mock-auth.d.cts.map +0 -1
- package/dist/sdk/__fixtures__/mock-auth.d.mts.map +0 -1
- package/dist/sdk/__fixtures__/mock-auth.mjs +0 -119
- package/dist/sdk/__fixtures__/mock-auth.mjs.map +0 -1
- package/dist/sdk/__fixtures__/mock-userstorage.cjs +0 -111
- package/dist/sdk/__fixtures__/mock-userstorage.cjs.map +0 -1
- package/dist/sdk/__fixtures__/mock-userstorage.d.cts +0 -20
- package/dist/sdk/__fixtures__/mock-userstorage.d.cts.map +0 -1
- package/dist/sdk/__fixtures__/mock-userstorage.d.mts +0 -20
- package/dist/sdk/__fixtures__/mock-userstorage.d.mts.map +0 -1
- package/dist/sdk/__fixtures__/mock-userstorage.mjs +0 -81
- package/dist/sdk/__fixtures__/mock-userstorage.mjs.map +0 -1
- package/dist/sdk/__fixtures__/test-utils.cjs +0 -90
- package/dist/sdk/__fixtures__/test-utils.cjs.map +0 -1
- package/dist/sdk/__fixtures__/test-utils.d.cts +0 -37
- package/dist/sdk/__fixtures__/test-utils.d.cts.map +0 -1
- package/dist/sdk/__fixtures__/test-utils.d.mts +0 -37
- package/dist/sdk/__fixtures__/test-utils.d.mts.map +0 -1
- package/dist/sdk/__fixtures__/test-utils.mjs +0 -84
- package/dist/sdk/__fixtures__/test-utils.mjs.map +0 -1
- /package/dist/controllers/authentication/{__fixtures__ → mocks}/index.cjs +0 -0
- /package/dist/controllers/authentication/{__fixtures__ → mocks}/index.d.cts +0 -0
- /package/dist/controllers/authentication/{__fixtures__ → mocks}/index.d.mts +0 -0
- /package/dist/controllers/authentication/{__fixtures__ → mocks}/index.mjs +0 -0
- /package/dist/controllers/user-storage/{__fixtures__ → mocks}/index.cjs +0 -0
- /package/dist/controllers/user-storage/{__fixtures__ → mocks}/index.d.cts +0 -0
- /package/dist/controllers/user-storage/{__fixtures__ → mocks}/index.d.mts +0 -0
- /package/dist/controllers/user-storage/{__fixtures__ → mocks}/index.mjs +0 -0
- /package/dist/controllers/user-storage/{__fixtures__ → mocks}/mockStorage.cjs +0 -0
- /package/dist/controllers/user-storage/{__fixtures__ → mocks}/mockStorage.d.cts +0 -0
- /package/dist/controllers/user-storage/{__fixtures__ → mocks}/mockStorage.d.mts +0 -0
- /package/dist/controllers/user-storage/{__fixtures__ → mocks}/mockStorage.mjs +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.mjs","sourceRoot":"","sources":["../../../src/sdk/mocks/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,6BAAyB;AACvC,OAAO,EACL,SAAS,EACT,cAAc,EACd,aAAa,EACb,cAAc,EACd,gBAAgB,EACjB,kDAA8C;AAE/C,MAAM,CAAC,MAAM,cAAc,GAAG,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AACjD,MAAM,CAAC,MAAM,kBAAkB,GAAG,aAAa,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AACzD,MAAM,CAAC,MAAM,mBAAmB,GAAG,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAC3D,MAAM,CAAC,MAAM,mBAAmB,GAAG,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAC3D,MAAM,CAAC,MAAM,yBAAyB,GAAG,gBAAgB,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAEnE,MAAM,CAAC,MAAM,QAAQ,GACnB,opBAAopB,CAAC;AAEvpB,MAAM,CAAC,MAAM,eAAe,GAC1B,6JAA6J,CAAC;AAEhK,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,KAAK,EAAE,kBAAkB;IACzB,UAAU,EAAE,4CAA4C;IACxD,UAAU,EAAE,GAAG;CAChB,CAAC;AAEF,MAAM,CAAC,MAAM,wBAAwB,GAAG;IACtC,KAAK,EAAE,QAAQ;IACf,UAAU,EAAE,IAAI;IAChB,OAAO,EAAE;QACP,UAAU,EAAE,sCAAsC;QAClD,cAAc,EAAE,sCAAsC;QACtD,aAAa,EACX,kEAAkE;QACpE,eAAe,EAAE,MAAM;QACvB,qBAAqB,EAAE,iCAAiC;KACzD;CACF,CAAC;AAEF,MAAM,CAAC,MAAM,uBAAuB,GAAG;IACrC,KAAK,EAAE,QAAQ;IACf,UAAU,EAAE,IAAI;IAChB,OAAO,EAAE;QACP,UAAU,EAAE,sCAAsC;QAClD,cAAc,EAAE,sCAAsC;QACtD,aAAa,EACX,kEAAkE;QACpE,eAAe,EAAE,KAAK;QACtB,qBAAqB,EAAE,4BAA4B;KACpD;CACF,CAAC;AAEF,MAAM,CAAC,MAAM,wBAAwB,GAAG;IACtC,YAAY,EAAE,eAAe;IAC7B,UAAU,EAAE,IAAI;CACjB,CAAC","sourcesContent":["import { Env } from '../../shared/env';\nimport {\n NONCE_URL,\n SIWE_LOGIN_URL,\n SRP_LOGIN_URL,\n OIDC_TOKEN_URL,\n PAIR_IDENTIFIERS,\n} from '../authentication-jwt-bearer/services';\n\nexport const MOCK_NONCE_URL = NONCE_URL(Env.PRD);\nexport const MOCK_SRP_LOGIN_URL = SRP_LOGIN_URL(Env.PRD);\nexport const MOCK_OIDC_TOKEN_URL = OIDC_TOKEN_URL(Env.PRD);\nexport const MOCK_SIWE_LOGIN_URL = SIWE_LOGIN_URL(Env.PRD);\nexport const MOCK_PAIR_IDENTIFIERS_URL = PAIR_IDENTIFIERS(Env.PRD);\n\nexport const MOCK_JWT =\n 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImIwNzE2N2U2LWJjNWUtNDgyZC1hNjRhLWU1MjQ0MjY2MGU3NyJ9.eyJzdWIiOiI1MzE0ODc5YWM2NDU1OGI3OTQ5ZmI4NWIzMjg2ZjZjNjUwODAzYmFiMTY0Y2QyOWNmMmM3YzdmMjMzMWMwZTRlIiwiaWF0IjoxNzA2MTEzMDYyLCJleHAiOjE3NjkxODUwNjMsImlzcyI6ImF1dGgubWV0YW1hc2suaW8iLCJhdWQiOiJwb3J0Zm9saW8ubWV0YW1hc2suaW8ifQ.E5UL6oABNweS8t5a6IBTqTf7NLOJbrhJSmEcsr7kwLp4bGvcENJzACwnsHDkA6PlzfDV09ZhAGU_F3hlS0j-erbY0k0AFR-GAtyS7E9N02D8RgUDz5oDR65CKmzM8JilgFA8UvruJ6OJGogroaOSOqzRES_s8MjHpP47RJ9lXrUesajsbOudXbuksXWg5QmWip6LLvjwr8UUzcJzNQilyIhiEpo4WdzWM4R3VtTwr4rHnWEvtYnYCov1jmI2w3YQ48y0M-3Y9IOO0ov_vlITRrOnR7Y7fRUGLUFmU5msD8mNWRywjQFLHfJJ1yNP5aJ8TkuCK3sC6kcUH335IVvukQ';\n\nexport const MOCK_ACCESS_JWT =\n 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c';\n\nexport const MOCK_NONCE_RESPONSE = {\n nonce: 'xGMm9SoihEKeAEfV',\n identifier: '0xd8641601Cb79a94FD872fE42d5b4a067A44a7e88',\n expires_in: 300,\n};\n\nexport const MOCK_SIWE_LOGIN_RESPONSE = {\n token: MOCK_JWT,\n expires_in: 3600,\n profile: {\n profile_id: 'fa2bbf82-bd9a-4e6b-aabc-9ca0d0319b6e',\n metametrics_id: 'de742679-4960-4977-a415-4718b5f8e86c',\n identifier_id:\n 'ec9a4e9906836497efad2fd4d4290b34d2c6a2c0d93eb174aa3cd88a133adbaf',\n identifier_type: 'SIWE',\n encrypted_storage_key: '2c6a2c0d93eb174aa3cd88a133adbaf',\n },\n};\n\nexport const MOCK_SRP_LOGIN_RESPONSE = {\n token: MOCK_JWT,\n expires_in: 3600,\n profile: {\n profile_id: 'f88227bd-b615-41a3-b0be-467dd781a4ad',\n metametrics_id: '561ec651-a844-4b36-a451-04d6eac35740',\n identifier_id:\n 'da9a9fc7b09edde9cc23cec9b7e11a71fb0ab4d2ddd8af8af905306f3e1456fb',\n identifier_type: 'SRP',\n encrypted_storage_key: 'd2ddd8af8af905306f3e1456fb',\n },\n};\n\nexport const MOCK_OIDC_TOKEN_RESPONSE = {\n access_token: MOCK_ACCESS_JWT,\n expires_in: 3600,\n};\n"]}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.MOCK_STORAGE_RESPONSE = exports.MOCK_NOTIFICATIONS_DATA_ENCRYPTED = exports.MOCK_NOTIFICATIONS_DATA = exports.MOCK_STORAGE_KEY = exports.MOCK_STORAGE_URL_ALL_FEATURE_ENTRIES = exports.MOCK_STORAGE_URL = void 0;
|
|
27
|
+
const encryption_1 = __importStar(require("../../shared/encryption/index.cjs"));
|
|
28
|
+
const env_1 = require("../../shared/env.cjs");
|
|
29
|
+
const storage_schema_1 = require("../../shared/storage-schema.cjs");
|
|
30
|
+
const user_storage_1 = require("../user-storage.cjs");
|
|
31
|
+
// Example mock notifications storage entry (wildcard)
|
|
32
|
+
exports.MOCK_STORAGE_URL = (0, user_storage_1.STORAGE_URL)(env_1.Env.PRD, `${storage_schema_1.USER_STORAGE_FEATURE_NAMES.notifications}.notification_settings`);
|
|
33
|
+
exports.MOCK_STORAGE_URL_ALL_FEATURE_ENTRIES = (0, user_storage_1.STORAGE_URL)(env_1.Env.PRD, storage_schema_1.USER_STORAGE_FEATURE_NAMES.notifications);
|
|
34
|
+
exports.MOCK_STORAGE_KEY = (0, encryption_1.createSHA256Hash)('mockStorageKey');
|
|
35
|
+
exports.MOCK_NOTIFICATIONS_DATA = '{ is_compact: false }';
|
|
36
|
+
const MOCK_NOTIFICATIONS_DATA_ENCRYPTED = async (data) => await encryption_1.default.encryptString(data ?? exports.MOCK_NOTIFICATIONS_DATA, exports.MOCK_STORAGE_KEY);
|
|
37
|
+
exports.MOCK_NOTIFICATIONS_DATA_ENCRYPTED = MOCK_NOTIFICATIONS_DATA_ENCRYPTED;
|
|
38
|
+
const MOCK_STORAGE_RESPONSE = async (data) => ({
|
|
39
|
+
HashedKey: '8485d2c14c333ebca415140a276adaf546619b0efc204586b73a5d400a18a5e2',
|
|
40
|
+
Data: await (0, exports.MOCK_NOTIFICATIONS_DATA_ENCRYPTED)(data),
|
|
41
|
+
});
|
|
42
|
+
exports.MOCK_STORAGE_RESPONSE = MOCK_STORAGE_RESPONSE;
|
|
43
|
+
//# sourceMappingURL=userstorage.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"userstorage.cjs","sourceRoot":"","sources":["../../../src/sdk/mocks/userstorage.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gFAAuE;AACvE,8CAAuC;AACvC,oEAAyE;AACzE,sDAA8C;AAE9C,sDAAsD;AACzC,QAAA,gBAAgB,GAAG,IAAA,0BAAW,EACzC,SAAG,CAAC,GAAG,EACP,GAAG,2CAA0B,CAAC,aAAa,wBAAwB,CACpE,CAAC;AACW,QAAA,oCAAoC,GAAG,IAAA,0BAAW,EAC7D,SAAG,CAAC,GAAG,EACP,2CAA0B,CAAC,aAAa,CACzC,CAAC;AAEW,QAAA,gBAAgB,GAAG,IAAA,6BAAgB,EAAC,gBAAgB,CAAC,CAAC;AACtD,QAAA,uBAAuB,GAAG,uBAAuB,CAAC;AACxD,MAAM,iCAAiC,GAAG,KAAK,EAAE,IAAa,EAAE,EAAE,CACvE,MAAM,oBAAU,CAAC,aAAa,CAC5B,IAAI,IAAI,+BAAuB,EAC/B,wBAAgB,CACjB,CAAC;AAJS,QAAA,iCAAiC,qCAI1C;AAEG,MAAM,qBAAqB,GAAG,KAAK,EAAE,IAAa,EAAE,EAAE,CAAC,CAAC;IAC7D,SAAS,EAAE,kEAAkE;IAC7E,IAAI,EAAE,MAAM,IAAA,yCAAiC,EAAC,IAAI,CAAC;CACpD,CAAC,CAAC;AAHU,QAAA,qBAAqB,yBAG/B","sourcesContent":["import encryption, { createSHA256Hash } from '../../shared/encryption';\nimport { Env } from '../../shared/env';\nimport { USER_STORAGE_FEATURE_NAMES } from '../../shared/storage-schema';\nimport { STORAGE_URL } from '../user-storage';\n\n// Example mock notifications storage entry (wildcard)\nexport const MOCK_STORAGE_URL = STORAGE_URL(\n Env.PRD,\n `${USER_STORAGE_FEATURE_NAMES.notifications}.notification_settings`,\n);\nexport const MOCK_STORAGE_URL_ALL_FEATURE_ENTRIES = STORAGE_URL(\n Env.PRD,\n USER_STORAGE_FEATURE_NAMES.notifications,\n);\n\nexport const MOCK_STORAGE_KEY = createSHA256Hash('mockStorageKey');\nexport const MOCK_NOTIFICATIONS_DATA = '{ is_compact: false }';\nexport const MOCK_NOTIFICATIONS_DATA_ENCRYPTED = async (data?: string) =>\n await encryption.encryptString(\n data ?? MOCK_NOTIFICATIONS_DATA,\n MOCK_STORAGE_KEY,\n );\n\nexport const MOCK_STORAGE_RESPONSE = async (data?: string) => ({\n HashedKey: '8485d2c14c333ebca415140a276adaf546619b0efc204586b73a5d400a18a5e2',\n Data: await MOCK_NOTIFICATIONS_DATA_ENCRYPTED(data),\n});\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare const MOCK_STORAGE_URL: string;
|
|
2
|
+
export declare const MOCK_STORAGE_URL_ALL_FEATURE_ENTRIES: string;
|
|
3
|
+
export declare const MOCK_STORAGE_KEY: string;
|
|
4
|
+
export declare const MOCK_NOTIFICATIONS_DATA = "{ is_compact: false }";
|
|
5
|
+
export declare const MOCK_NOTIFICATIONS_DATA_ENCRYPTED: (data?: string) => Promise<string>;
|
|
6
|
+
export declare const MOCK_STORAGE_RESPONSE: (data?: string) => Promise<{
|
|
7
|
+
HashedKey: string;
|
|
8
|
+
Data: string;
|
|
9
|
+
}>;
|
|
10
|
+
//# sourceMappingURL=userstorage.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"userstorage.d.cts","sourceRoot":"","sources":["../../../src/sdk/mocks/userstorage.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,gBAAgB,QAG5B,CAAC;AACF,eAAO,MAAM,oCAAoC,QAGhD,CAAC;AAEF,eAAO,MAAM,gBAAgB,QAAqC,CAAC;AACnE,eAAO,MAAM,uBAAuB,0BAA0B,CAAC;AAC/D,eAAO,MAAM,iCAAiC,UAAiB,MAAM,oBAIlE,CAAC;AAEJ,eAAO,MAAM,qBAAqB,UAAiB,MAAM;;;EAGvD,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare const MOCK_STORAGE_URL: string;
|
|
2
|
+
export declare const MOCK_STORAGE_URL_ALL_FEATURE_ENTRIES: string;
|
|
3
|
+
export declare const MOCK_STORAGE_KEY: string;
|
|
4
|
+
export declare const MOCK_NOTIFICATIONS_DATA = "{ is_compact: false }";
|
|
5
|
+
export declare const MOCK_NOTIFICATIONS_DATA_ENCRYPTED: (data?: string) => Promise<string>;
|
|
6
|
+
export declare const MOCK_STORAGE_RESPONSE: (data?: string) => Promise<{
|
|
7
|
+
HashedKey: string;
|
|
8
|
+
Data: string;
|
|
9
|
+
}>;
|
|
10
|
+
//# sourceMappingURL=userstorage.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"userstorage.d.mts","sourceRoot":"","sources":["../../../src/sdk/mocks/userstorage.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,gBAAgB,QAG5B,CAAC;AACF,eAAO,MAAM,oCAAoC,QAGhD,CAAC;AAEF,eAAO,MAAM,gBAAgB,QAAqC,CAAC;AACnE,eAAO,MAAM,uBAAuB,0BAA0B,CAAC;AAC/D,eAAO,MAAM,iCAAiC,UAAiB,MAAM,oBAIlE,CAAC;AAEJ,eAAO,MAAM,qBAAqB,UAAiB,MAAM;;;EAGvD,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import encryption, { createSHA256Hash } from "../../shared/encryption/index.mjs";
|
|
2
|
+
import { Env } from "../../shared/env.mjs";
|
|
3
|
+
import { USER_STORAGE_FEATURE_NAMES } from "../../shared/storage-schema.mjs";
|
|
4
|
+
import { STORAGE_URL } from "../user-storage.mjs";
|
|
5
|
+
// Example mock notifications storage entry (wildcard)
|
|
6
|
+
export const MOCK_STORAGE_URL = STORAGE_URL(Env.PRD, `${USER_STORAGE_FEATURE_NAMES.notifications}.notification_settings`);
|
|
7
|
+
export const MOCK_STORAGE_URL_ALL_FEATURE_ENTRIES = STORAGE_URL(Env.PRD, USER_STORAGE_FEATURE_NAMES.notifications);
|
|
8
|
+
export const MOCK_STORAGE_KEY = createSHA256Hash('mockStorageKey');
|
|
9
|
+
export const MOCK_NOTIFICATIONS_DATA = '{ is_compact: false }';
|
|
10
|
+
export const MOCK_NOTIFICATIONS_DATA_ENCRYPTED = async (data) => await encryption.encryptString(data ?? MOCK_NOTIFICATIONS_DATA, MOCK_STORAGE_KEY);
|
|
11
|
+
export const MOCK_STORAGE_RESPONSE = async (data) => ({
|
|
12
|
+
HashedKey: '8485d2c14c333ebca415140a276adaf546619b0efc204586b73a5d400a18a5e2',
|
|
13
|
+
Data: await MOCK_NOTIFICATIONS_DATA_ENCRYPTED(data),
|
|
14
|
+
});
|
|
15
|
+
//# sourceMappingURL=userstorage.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"userstorage.mjs","sourceRoot":"","sources":["../../../src/sdk/mocks/userstorage.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,EAAE,EAAE,gBAAgB,EAAE,0CAAgC;AACvE,OAAO,EAAE,GAAG,EAAE,6BAAyB;AACvC,OAAO,EAAE,0BAA0B,EAAE,wCAAoC;AACzE,OAAO,EAAE,WAAW,EAAE,4BAAwB;AAE9C,sDAAsD;AACtD,MAAM,CAAC,MAAM,gBAAgB,GAAG,WAAW,CACzC,GAAG,CAAC,GAAG,EACP,GAAG,0BAA0B,CAAC,aAAa,wBAAwB,CACpE,CAAC;AACF,MAAM,CAAC,MAAM,oCAAoC,GAAG,WAAW,CAC7D,GAAG,CAAC,GAAG,EACP,0BAA0B,CAAC,aAAa,CACzC,CAAC;AAEF,MAAM,CAAC,MAAM,gBAAgB,GAAG,gBAAgB,CAAC,gBAAgB,CAAC,CAAC;AACnE,MAAM,CAAC,MAAM,uBAAuB,GAAG,uBAAuB,CAAC;AAC/D,MAAM,CAAC,MAAM,iCAAiC,GAAG,KAAK,EAAE,IAAa,EAAE,EAAE,CACvE,MAAM,UAAU,CAAC,aAAa,CAC5B,IAAI,IAAI,uBAAuB,EAC/B,gBAAgB,CACjB,CAAC;AAEJ,MAAM,CAAC,MAAM,qBAAqB,GAAG,KAAK,EAAE,IAAa,EAAE,EAAE,CAAC,CAAC;IAC7D,SAAS,EAAE,kEAAkE;IAC7E,IAAI,EAAE,MAAM,iCAAiC,CAAC,IAAI,CAAC;CACpD,CAAC,CAAC","sourcesContent":["import encryption, { createSHA256Hash } from '../../shared/encryption';\nimport { Env } from '../../shared/env';\nimport { USER_STORAGE_FEATURE_NAMES } from '../../shared/storage-schema';\nimport { STORAGE_URL } from '../user-storage';\n\n// Example mock notifications storage entry (wildcard)\nexport const MOCK_STORAGE_URL = STORAGE_URL(\n Env.PRD,\n `${USER_STORAGE_FEATURE_NAMES.notifications}.notification_settings`,\n);\nexport const MOCK_STORAGE_URL_ALL_FEATURE_ENTRIES = STORAGE_URL(\n Env.PRD,\n USER_STORAGE_FEATURE_NAMES.notifications,\n);\n\nexport const MOCK_STORAGE_KEY = createSHA256Hash('mockStorageKey');\nexport const MOCK_NOTIFICATIONS_DATA = '{ is_compact: false }';\nexport const MOCK_NOTIFICATIONS_DATA_ENCRYPTED = async (data?: string) =>\n await encryption.encryptString(\n data ?? MOCK_NOTIFICATIONS_DATA,\n MOCK_STORAGE_KEY,\n );\n\nexport const MOCK_STORAGE_RESPONSE = async (data?: string) => ({\n HashedKey: '8485d2c14c333ebca415140a276adaf546619b0efc204586b73a5d400a18a5e2',\n Data: await MOCK_NOTIFICATIONS_DATA_ENCRYPTED(data),\n});\n"]}
|
|
@@ -44,20 +44,20 @@ class UserStorage {
|
|
|
44
44
|
this.config = config;
|
|
45
45
|
this.options = options;
|
|
46
46
|
}
|
|
47
|
-
async setItem(path, value) {
|
|
48
|
-
await __classPrivateFieldGet(this, _UserStorage_instances, "m", _UserStorage_upsertUserStorage).call(this, path, value);
|
|
47
|
+
async setItem(path, value, options) {
|
|
48
|
+
await __classPrivateFieldGet(this, _UserStorage_instances, "m", _UserStorage_upsertUserStorage).call(this, path, value, options);
|
|
49
49
|
}
|
|
50
|
-
async batchSetItems(path, values) {
|
|
51
|
-
await __classPrivateFieldGet(this, _UserStorage_instances, "m", _UserStorage_batchUpsertUserStorage).call(this, path, values);
|
|
50
|
+
async batchSetItems(path, values, options) {
|
|
51
|
+
await __classPrivateFieldGet(this, _UserStorage_instances, "m", _UserStorage_batchUpsertUserStorage).call(this, path, values, options);
|
|
52
52
|
}
|
|
53
|
-
async getItem(path) {
|
|
54
|
-
return __classPrivateFieldGet(this, _UserStorage_instances, "m", _UserStorage_getUserStorage).call(this, path);
|
|
53
|
+
async getItem(path, options) {
|
|
54
|
+
return __classPrivateFieldGet(this, _UserStorage_instances, "m", _UserStorage_getUserStorage).call(this, path, options);
|
|
55
55
|
}
|
|
56
|
-
async getAllFeatureItems(path) {
|
|
57
|
-
return __classPrivateFieldGet(this, _UserStorage_instances, "m", _UserStorage_getUserStorageAllFeatureEntries).call(this, path);
|
|
56
|
+
async getAllFeatureItems(path, options) {
|
|
57
|
+
return __classPrivateFieldGet(this, _UserStorage_instances, "m", _UserStorage_getUserStorageAllFeatureEntries).call(this, path, options);
|
|
58
58
|
}
|
|
59
|
-
async deleteItem(path) {
|
|
60
|
-
return __classPrivateFieldGet(this, _UserStorage_instances, "m", _UserStorage_deleteUserStorage).call(this, path);
|
|
59
|
+
async deleteItem(path, options) {
|
|
60
|
+
return __classPrivateFieldGet(this, _UserStorage_instances, "m", _UserStorage_deleteUserStorage).call(this, path, options);
|
|
61
61
|
}
|
|
62
62
|
async deleteAllFeatureItems(path) {
|
|
63
63
|
return __classPrivateFieldGet(this, _UserStorage_instances, "m", _UserStorage_deleteUserStorageAllFeatureEntries).call(this, path);
|
|
@@ -78,13 +78,13 @@ class UserStorage {
|
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
80
|
exports.UserStorage = UserStorage;
|
|
81
|
-
_UserStorage_instances = new WeakSet(), _UserStorage_upsertUserStorage = async function _UserStorage_upsertUserStorage(path, data) {
|
|
81
|
+
_UserStorage_instances = new WeakSet(), _UserStorage_upsertUserStorage = async function _UserStorage_upsertUserStorage(path, data, options) {
|
|
82
82
|
try {
|
|
83
83
|
const headers = await __classPrivateFieldGet(this, _UserStorage_instances, "m", _UserStorage_getAuthorizationHeader).call(this);
|
|
84
84
|
const storageKey = await this.getStorageKey();
|
|
85
|
-
const encryptedData = await encryption_1.default.encryptString(data, storageKey);
|
|
85
|
+
const encryptedData = await encryption_1.default.encryptString(data, storageKey, options?.nativeScryptCrypto);
|
|
86
86
|
const encryptedPath = (0, storage_schema_1.createEntryPath)(path, storageKey, {
|
|
87
|
-
validateAgainstSchema:
|
|
87
|
+
validateAgainstSchema: Boolean(options?.validateAgainstSchema),
|
|
88
88
|
});
|
|
89
89
|
const url = new URL((0, exports.STORAGE_URL)(this.env, encryptedPath));
|
|
90
90
|
const response = await fetch(url.toString(), {
|
|
@@ -108,7 +108,7 @@ _UserStorage_instances = new WeakSet(), _UserStorage_upsertUserStorage = async f
|
|
|
108
108
|
const errorMessage = e instanceof Error ? e.message : JSON.stringify(e ?? '');
|
|
109
109
|
throw new errors_1.UserStorageError(`failed to upsert user storage for path '${path}'. ${errorMessage}`);
|
|
110
110
|
}
|
|
111
|
-
}, _UserStorage_batchUpsertUserStorage = async function _UserStorage_batchUpsertUserStorage(path, data) {
|
|
111
|
+
}, _UserStorage_batchUpsertUserStorage = async function _UserStorage_batchUpsertUserStorage(path, data, options) {
|
|
112
112
|
try {
|
|
113
113
|
if (!data.length) {
|
|
114
114
|
return;
|
|
@@ -118,7 +118,7 @@ _UserStorage_instances = new WeakSet(), _UserStorage_upsertUserStorage = async f
|
|
|
118
118
|
const encryptedData = await Promise.all(data.map(async (d) => {
|
|
119
119
|
return [
|
|
120
120
|
__classPrivateFieldGet(this, _UserStorage_instances, "m", _UserStorage_createEntryKey).call(this, d[0], storageKey),
|
|
121
|
-
await encryption_1.default.encryptString(d[1], storageKey),
|
|
121
|
+
await encryption_1.default.encryptString(d[1], storageKey, options?.nativeScryptCrypto),
|
|
122
122
|
];
|
|
123
123
|
}));
|
|
124
124
|
const url = new URL((0, exports.STORAGE_URL)(this.env, path));
|
|
@@ -145,9 +145,6 @@ _UserStorage_instances = new WeakSet(), _UserStorage_upsertUserStorage = async f
|
|
|
145
145
|
}
|
|
146
146
|
}, _UserStorage_batchUpsertUserStorageWithAlreadyHashedAndEncryptedEntries = async function _UserStorage_batchUpsertUserStorageWithAlreadyHashedAndEncryptedEntries(path, encryptedData) {
|
|
147
147
|
try {
|
|
148
|
-
if (!encryptedData.length) {
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
148
|
const headers = await __classPrivateFieldGet(this, _UserStorage_instances, "m", _UserStorage_getAuthorizationHeader).call(this);
|
|
152
149
|
const url = new URL((0, exports.STORAGE_URL)(this.env, path));
|
|
153
150
|
const response = await fetch(url.toString(), {
|
|
@@ -158,6 +155,7 @@ _UserStorage_instances = new WeakSet(), _UserStorage_upsertUserStorage = async f
|
|
|
158
155
|
},
|
|
159
156
|
body: JSON.stringify({ data: Object.fromEntries(encryptedData) }),
|
|
160
157
|
});
|
|
158
|
+
// istanbul ignore next
|
|
161
159
|
if (!response.ok) {
|
|
162
160
|
const responseBody = await response.json().catch(() => ({
|
|
163
161
|
message: 'unknown',
|
|
@@ -169,14 +167,15 @@ _UserStorage_instances = new WeakSet(), _UserStorage_upsertUserStorage = async f
|
|
|
169
167
|
catch (e) {
|
|
170
168
|
/* istanbul ignore next */
|
|
171
169
|
const errorMessage = e instanceof Error ? e.message : JSON.stringify(e ?? '');
|
|
170
|
+
// istanbul ignore next
|
|
172
171
|
throw new errors_1.UserStorageError(`failed to batch upsert user storage for path '${path}'. ${errorMessage}`);
|
|
173
172
|
}
|
|
174
|
-
}, _UserStorage_getUserStorage = async function _UserStorage_getUserStorage(path) {
|
|
173
|
+
}, _UserStorage_getUserStorage = async function _UserStorage_getUserStorage(path, options) {
|
|
175
174
|
try {
|
|
176
175
|
const headers = await __classPrivateFieldGet(this, _UserStorage_instances, "m", _UserStorage_getAuthorizationHeader).call(this);
|
|
177
176
|
const storageKey = await this.getStorageKey();
|
|
178
177
|
const encryptedPath = (0, storage_schema_1.createEntryPath)(path, storageKey, {
|
|
179
|
-
validateAgainstSchema:
|
|
178
|
+
validateAgainstSchema: Boolean(options?.validateAgainstSchema),
|
|
180
179
|
});
|
|
181
180
|
const url = new URL((0, exports.STORAGE_URL)(this.env, encryptedPath));
|
|
182
181
|
const response = await fetch(url.toString(), {
|
|
@@ -186,30 +185,31 @@ _UserStorage_instances = new WeakSet(), _UserStorage_upsertUserStorage = async f
|
|
|
186
185
|
},
|
|
187
186
|
});
|
|
188
187
|
if (response.status === 404) {
|
|
189
|
-
|
|
188
|
+
return null;
|
|
190
189
|
}
|
|
191
190
|
if (!response.ok) {
|
|
192
191
|
const responseBody = (await response.json());
|
|
193
192
|
throw new Error(`HTTP error message: ${responseBody.message}, error: ${responseBody.error}`);
|
|
194
193
|
}
|
|
195
|
-
const
|
|
196
|
-
const
|
|
194
|
+
const userStorage = await response.json();
|
|
195
|
+
const encryptedData = userStorage?.Data ?? null;
|
|
196
|
+
if (!encryptedData) {
|
|
197
|
+
return null;
|
|
198
|
+
}
|
|
199
|
+
const decryptedData = await encryption_1.default.decryptString(encryptedData, storageKey, options?.nativeScryptCrypto);
|
|
197
200
|
// Re-encrypt the entry if it was encrypted with a random salt
|
|
198
201
|
const salt = encryption_1.default.getSalt(encryptedData);
|
|
199
202
|
if (salt.toString() !== constants_1.SHARED_SALT.toString()) {
|
|
200
|
-
await __classPrivateFieldGet(this, _UserStorage_instances, "m", _UserStorage_upsertUserStorage).call(this, path, decryptedData);
|
|
203
|
+
await __classPrivateFieldGet(this, _UserStorage_instances, "m", _UserStorage_upsertUserStorage).call(this, path, decryptedData, options);
|
|
201
204
|
}
|
|
202
205
|
return decryptedData;
|
|
203
206
|
}
|
|
204
207
|
catch (e) {
|
|
205
|
-
if (e instanceof errors_1.NotFoundError) {
|
|
206
|
-
throw e;
|
|
207
|
-
}
|
|
208
208
|
/* istanbul ignore next */
|
|
209
209
|
const errorMessage = e instanceof Error ? e.message : JSON.stringify(e ?? '');
|
|
210
210
|
throw new errors_1.UserStorageError(`failed to get user storage for path '${path}'. ${errorMessage}`);
|
|
211
211
|
}
|
|
212
|
-
}, _UserStorage_getUserStorageAllFeatureEntries = async function _UserStorage_getUserStorageAllFeatureEntries(path) {
|
|
212
|
+
}, _UserStorage_getUserStorageAllFeatureEntries = async function _UserStorage_getUserStorageAllFeatureEntries(path, options) {
|
|
213
213
|
try {
|
|
214
214
|
const headers = await __classPrivateFieldGet(this, _UserStorage_instances, "m", _UserStorage_getAuthorizationHeader).call(this);
|
|
215
215
|
const storageKey = await this.getStorageKey();
|
|
@@ -221,7 +221,7 @@ _UserStorage_instances = new WeakSet(), _UserStorage_upsertUserStorage = async f
|
|
|
221
221
|
},
|
|
222
222
|
});
|
|
223
223
|
if (response.status === 404) {
|
|
224
|
-
|
|
224
|
+
return null;
|
|
225
225
|
}
|
|
226
226
|
if (!response.ok) {
|
|
227
227
|
const responseBody = (await response.json());
|
|
@@ -238,14 +238,14 @@ _UserStorage_instances = new WeakSet(), _UserStorage_upsertUserStorage = async f
|
|
|
238
238
|
continue;
|
|
239
239
|
}
|
|
240
240
|
try {
|
|
241
|
-
const data = await encryption_1.default.decryptString(entry.Data, storageKey);
|
|
241
|
+
const data = await encryption_1.default.decryptString(entry.Data, storageKey, options?.nativeScryptCrypto);
|
|
242
242
|
decryptedData.push(data);
|
|
243
243
|
// Re-encrypt the entry was encrypted with a random salt
|
|
244
244
|
const salt = encryption_1.default.getSalt(entry.Data);
|
|
245
245
|
if (salt.toString() !== constants_1.SHARED_SALT.toString()) {
|
|
246
246
|
reEncryptedEntries.push([
|
|
247
247
|
entry.HashedKey,
|
|
248
|
-
await encryption_1.default.encryptString(data, storageKey),
|
|
248
|
+
await encryption_1.default.encryptString(data, storageKey, options?.nativeScryptCrypto),
|
|
249
249
|
]);
|
|
250
250
|
}
|
|
251
251
|
}
|
|
@@ -260,19 +260,16 @@ _UserStorage_instances = new WeakSet(), _UserStorage_upsertUserStorage = async f
|
|
|
260
260
|
return decryptedData;
|
|
261
261
|
}
|
|
262
262
|
catch (e) {
|
|
263
|
-
if (e instanceof errors_1.NotFoundError) {
|
|
264
|
-
throw e;
|
|
265
|
-
}
|
|
266
263
|
/* istanbul ignore next */
|
|
267
264
|
const errorMessage = e instanceof Error ? e.message : JSON.stringify(e ?? '');
|
|
268
265
|
throw new errors_1.UserStorageError(`failed to get user storage for path '${path}'. ${errorMessage}`);
|
|
269
266
|
}
|
|
270
|
-
}, _UserStorage_deleteUserStorage = async function _UserStorage_deleteUserStorage(path) {
|
|
267
|
+
}, _UserStorage_deleteUserStorage = async function _UserStorage_deleteUserStorage(path, options) {
|
|
271
268
|
try {
|
|
272
269
|
const headers = await __classPrivateFieldGet(this, _UserStorage_instances, "m", _UserStorage_getAuthorizationHeader).call(this);
|
|
273
270
|
const storageKey = await this.getStorageKey();
|
|
274
271
|
const encryptedPath = (0, storage_schema_1.createEntryPath)(path, storageKey, {
|
|
275
|
-
validateAgainstSchema:
|
|
272
|
+
validateAgainstSchema: Boolean(options?.validateAgainstSchema),
|
|
276
273
|
});
|
|
277
274
|
const url = new URL((0, exports.STORAGE_URL)(this.env, encryptedPath));
|
|
278
275
|
const response = await fetch(url.toString(), {
|
|
@@ -358,9 +355,7 @@ _UserStorage_instances = new WeakSet(), _UserStorage_upsertUserStorage = async f
|
|
|
358
355
|
}, _UserStorage_createEntryKey = function _UserStorage_createEntryKey(key, storageKey) {
|
|
359
356
|
const hashedKey = (0, encryption_1.createSHA256Hash)(key + storageKey);
|
|
360
357
|
return hashedKey;
|
|
361
|
-
}, _UserStorage_getAuthorizationHeader =
|
|
362
|
-
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
363
|
-
async function _UserStorage_getAuthorizationHeader() {
|
|
358
|
+
}, _UserStorage_getAuthorizationHeader = async function _UserStorage_getAuthorizationHeader() {
|
|
364
359
|
const accessToken = await this.config.auth.getAccessToken();
|
|
365
360
|
return { Authorization: `Bearer ${accessToken}` };
|
|
366
361
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"user-storage.cjs","sourceRoot":"","sources":["../../src/sdk/user-storage.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,yCAA2D;AAC3D,6EAAoE;AACpE,kEAA6D;AAE7D,2CAA2C;AAO3C,iEAA2D;AAEpD,MAAM,WAAW,GAAG,CAAC,GAAQ,EAAE,aAAqB,EAAE,EAAE,CAC7D,GAAG,IAAA,gBAAU,EAAC,GAAG,CAAC,CAAC,iBAAiB,uBAAuB,aAAa,EAAE,CAAC;AADhE,QAAA,WAAW,eACqD;AA2B7E,MAAa,WAAW;IAOtB,YAAY,MAAyB,EAAE,OAA2B;;QAChE,IAAI,CAAC,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC;QACtB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED,KAAK,CAAC,OAAO,CACX,IAA6C,EAC7C,KAAa;QAEb,MAAM,uBAAA,IAAI,8DAAmB,MAAvB,IAAI,EAAoB,IAAI,EAAE,KAAK,CAAC,CAAC;IAC7C,CAAC;IAED,KAAK,CAAC,aAAa,CACjB,IAAmC,EACnC,MAAgD;QAEhD,MAAM,uBAAA,IAAI,mEAAwB,MAA5B,IAAI,EAAyB,IAAI,EAAE,MAAM,CAAC,CAAC;IACnD,CAAC;IAED,KAAK,CAAC,OAAO,CACX,IAA6C;QAE7C,OAAO,uBAAA,IAAI,2DAAgB,MAApB,IAAI,EAAiB,IAAI,CAAC,CAAC;IACpC,CAAC;IAED,KAAK,CAAC,kBAAkB,CACtB,IAAmC;QAEnC,OAAO,uBAAA,IAAI,4EAAiC,MAArC,IAAI,EAAkC,IAAI,CAAC,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KAAK,CAAC,GAAG,EAAE,CAAC,CAAC;gBACpE,OAAO,EAAE,SAAS;gBAClB,KAAK,EAAE,SAAS;aACjB,CAAC,CAAC,CAAC;YACJ,MAAM,IAAI,KAAK,CACb,uBAAuB,YAAY,CAAC,OAAO,YAAY,YAAY,CAAC,KAAK,EAAE,CAC5E,CAAC;SACH;KACF;IAAC,OAAO,CAAC,EAAE;QACV,0BAA0B;QAC1B,MAAM,YAAY,GAChB,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;QAC3D,MAAM,IAAI,yBAAgB,CACxB,iDAAiD,IAAI,MAAM,YAAY,EAAE,CAC1E,CAAC;KACH;AACH,CAAC,qEAEe,GAAW,EAAE,UAAkB;IAC7C,MAAM,SAAS,GAAG,IAAA,6BAAgB,EAAC,GAAG,GAAG,UAAU,CAAC,CAAC;IACrD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,gFAAgF;AAEhF,KAAK;IACH,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC;IAC5D,OAAO,EAAE,aAAa,EAAE,UAAU,WAAW,EAAE,EAAE,CAAC;AACpD,CAAC","sourcesContent":["import type { IBaseAuth } from './authentication-jwt-bearer/types';\nimport { NotFoundError, UserStorageError } from './errors';\nimport encryption, { createSHA256Hash } from '../shared/encryption';\nimport { SHARED_SALT } from '../shared/encryption/constants';\nimport type { Env } from '../shared/env';\nimport { getEnvUrls } from '../shared/env';\nimport type {\n UserStorageGenericFeatureKey,\n UserStorageGenericFeatureName,\n UserStorageGenericPathWithFeatureAndKey,\n UserStorageGenericPathWithFeatureOnly,\n} from '../shared/storage-schema';\nimport { createEntryPath } from '../shared/storage-schema';\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\nexport type GetUserStorageAllFeatureEntriesResponse = {\n HashedKey: string;\n\n Data: string;\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(\n path: UserStorageGenericPathWithFeatureAndKey,\n value: string,\n ): Promise<void> {\n await this.#upsertUserStorage(path, value);\n }\n\n async batchSetItems(\n path: UserStorageGenericFeatureName,\n values: [UserStorageGenericFeatureKey, string][],\n ) {\n await this.#batchUpsertUserStorage(path, values);\n }\n\n async getItem(\n path: UserStorageGenericPathWithFeatureAndKey,\n ): Promise<string> {\n return this.#getUserStorage(path);\n }\n\n async getAllFeatureItems(\n path: UserStorageGenericFeatureName,\n ): Promise<string[] | null> {\n return this.#getUserStorageAllFeatureEntries(path);\n }\n\n async deleteItem(\n path: UserStorageGenericPathWithFeatureAndKey,\n ): Promise<void> {\n return this.#deleteUserStorage(path);\n }\n\n async deleteAllFeatureItems(\n path: UserStorageGenericFeatureName,\n ): Promise<void> {\n return this.#deleteUserStorageAllFeatureEntries(path);\n }\n\n async batchDeleteItems(\n path: UserStorageGenericFeatureName,\n values: UserStorageGenericFeatureKey[],\n ) {\n return this.#batchDeleteUserStorage(path, values);\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(\n path: UserStorageGenericPathWithFeatureAndKey,\n data: string,\n ): Promise<void> {\n try {\n const headers = await this.#getAuthorizationHeader();\n const storageKey = await this.getStorageKey();\n const encryptedData = await encryption.encryptString(data, storageKey);\n const encryptedPath = createEntryPath(path, storageKey, {\n validateAgainstSchema: false,\n });\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 #batchUpsertUserStorage(\n path: UserStorageGenericPathWithFeatureOnly,\n data: [string, string][],\n ): Promise<void> {\n try {\n if (!data.length) {\n return;\n }\n\n const headers = await this.#getAuthorizationHeader();\n const storageKey = await this.getStorageKey();\n\n const encryptedData = await Promise.all(\n data.map(async (d) => {\n return [\n this.#createEntryKey(d[0], storageKey),\n await encryption.encryptString(d[1], storageKey),\n ];\n }),\n );\n\n const url = new URL(STORAGE_URL(this.env, path));\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: Object.fromEntries(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 batch upsert user storage for path '${path}'. ${errorMessage}`,\n );\n }\n }\n\n async #batchUpsertUserStorageWithAlreadyHashedAndEncryptedEntries(\n path: UserStorageGenericPathWithFeatureOnly,\n encryptedData: [string, string][],\n ): Promise<void> {\n try {\n if (!encryptedData.length) {\n return;\n }\n\n const headers = await this.#getAuthorizationHeader();\n\n const url = new URL(STORAGE_URL(this.env, path));\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: Object.fromEntries(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 batch upsert user storage for path '${path}'. ${errorMessage}`,\n );\n }\n }\n\n async #getUserStorage(\n path: UserStorageGenericPathWithFeatureAndKey,\n ): Promise<string> {\n try {\n const headers = await this.#getAuthorizationHeader();\n const storageKey = await this.getStorageKey();\n const encryptedPath = createEntryPath(path, storageKey, {\n validateAgainstSchema: false,\n });\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 const decryptedData = await encryption.decryptString(\n encryptedData,\n storageKey,\n );\n\n // Re-encrypt the entry if it was encrypted with a random salt\n const salt = encryption.getSalt(encryptedData);\n if (salt.toString() !== SHARED_SALT.toString()) {\n await this.#upsertUserStorage(path, decryptedData);\n }\n\n return decryptedData;\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 async #getUserStorageAllFeatureEntries(\n path: UserStorageGenericPathWithFeatureOnly,\n ): Promise<string[] | null> {\n try {\n const headers = await this.#getAuthorizationHeader();\n const storageKey = await this.getStorageKey();\n\n const url = new URL(STORAGE_URL(this.env, path));\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(`feature not found for path '${path}'.`);\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 userStorage: GetUserStorageAllFeatureEntriesResponse | null =\n await response.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 if (!entry.Data) {\n continue;\n }\n\n try {\n const data = await encryption.decryptString(entry.Data, storageKey);\n decryptedData.push(data);\n\n // Re-encrypt the entry was encrypted with a random salt\n const salt = encryption.getSalt(entry.Data);\n if (salt.toString() !== SHARED_SALT.toString()) {\n reEncryptedEntries.push([\n entry.HashedKey,\n await encryption.encryptString(data, storageKey),\n ]);\n }\n } catch {\n // do nothing\n }\n }\n\n // Re-upload the re-encrypted entries\n if (reEncryptedEntries.length) {\n await this.#batchUpsertUserStorageWithAlreadyHashedAndEncryptedEntries(\n path,\n reEncryptedEntries,\n );\n }\n\n return decryptedData;\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 async #deleteUserStorage(\n path: UserStorageGenericPathWithFeatureAndKey,\n ): Promise<void> {\n try {\n const headers = await this.#getAuthorizationHeader();\n const storageKey = await this.getStorageKey();\n const encryptedPath = createEntryPath(path, storageKey, {\n validateAgainstSchema: false,\n });\n\n const url = new URL(STORAGE_URL(this.env, encryptedPath));\n\n const response = await fetch(url.toString(), {\n method: 'DELETE',\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 } 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 delete user storage for path '${path}'. ${errorMessage}`,\n );\n }\n }\n\n async #deleteUserStorageAllFeatureEntries(\n path: UserStorageGenericPathWithFeatureOnly,\n ): Promise<void> {\n try {\n const headers = await this.#getAuthorizationHeader();\n\n const url = new URL(STORAGE_URL(this.env, path));\n\n const response = await fetch(url.toString(), {\n method: 'DELETE',\n headers: {\n 'Content-Type': 'application/json',\n ...headers,\n },\n });\n\n if (response.status === 404) {\n throw new NotFoundError(`feature not found for path '${path}'.`);\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 } 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 delete user storage for path '${path}'. ${errorMessage}`,\n );\n }\n }\n\n async #batchDeleteUserStorage(\n path: UserStorageGenericPathWithFeatureOnly,\n data: string[],\n ): Promise<void> {\n try {\n if (!data.length) {\n return;\n }\n\n const headers = await this.#getAuthorizationHeader();\n const storageKey = await this.getStorageKey();\n\n const encryptedData = await Promise.all(\n data.map(async (d) => this.#createEntryKey(d, storageKey)),\n );\n\n const url = new URL(STORAGE_URL(this.env, path));\n\n const response = await fetch(url.toString(), {\n method: 'PUT',\n headers: {\n 'Content-Type': 'application/json',\n ...headers,\n },\n\n body: JSON.stringify({ batch_delete: 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 batch delete 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\n async #getAuthorizationHeader(): Promise<{ Authorization: string }> {\n const accessToken = await this.config.auth.getAccessToken();\n return { Authorization: `Bearer ${accessToken}` };\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"user-storage.cjs","sourceRoot":"","sources":["../../src/sdk/user-storage.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,yCAA2D;AAC3D,6EAAoE;AACpE,kEAA6D;AAE7D,2CAA2C;AAO3C,iEAA2D;AAGpD,MAAM,WAAW,GAAG,CAAC,GAAQ,EAAE,aAAqB,EAAE,EAAE,CAC7D,GAAG,IAAA,gBAAU,EAAC,GAAG,CAAC,CAAC,iBAAiB,uBAAuB,aAAa,EAA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E,CAC5E,CAAC;SACH;KACF;IAAC,OAAO,CAAC,EAAE;QACV,0BAA0B;QAC1B,MAAM,YAAY,GAChB,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;QAC3D,MAAM,IAAI,yBAAgB,CACxB,iDAAiD,IAAI,MAAM,YAAY,EAAE,CAC1E,CAAC;KACH;AACH,CAAC,qEAEe,GAAW,EAAE,UAAkB;IAC7C,MAAM,SAAS,GAAG,IAAA,6BAAgB,EAAC,GAAG,GAAG,UAAU,CAAC,CAAC;IACrD,OAAO,SAAS,CAAC;AACnB,CAAC,wCAED,KAAK;IACH,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC;IAC5D,OAAO,EAAE,aAAa,EAAE,UAAU,WAAW,EAAE,EAAE,CAAC;AACpD,CAAC","sourcesContent":["import type { IBaseAuth } from './authentication-jwt-bearer/types';\nimport { NotFoundError, UserStorageError } from './errors';\nimport encryption, { createSHA256Hash } from '../shared/encryption';\nimport { SHARED_SALT } from '../shared/encryption/constants';\nimport type { Env } from '../shared/env';\nimport { getEnvUrls } from '../shared/env';\nimport type {\n UserStorageGenericFeatureKey,\n UserStorageGenericFeatureName,\n UserStorageGenericPathWithFeatureAndKey,\n UserStorageGenericPathWithFeatureOnly,\n} from '../shared/storage-schema';\nimport { createEntryPath } from '../shared/storage-schema';\nimport type { NativeScrypt } from '../shared/types/encryption';\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\nexport type GetUserStorageAllFeatureEntriesResponse = {\n HashedKey: string;\n\n Data: string;\n}[];\n\nexport type UserStorageMethodOptions = {\n validateAgainstSchema?: boolean;\n nativeScryptCrypto?: NativeScrypt;\n};\n\ntype ErrorMessage = {\n message: string;\n error: string;\n};\n\nexport class UserStorage {\n protected config: UserStorageConfig;\n\n public 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(\n path: UserStorageGenericPathWithFeatureAndKey,\n value: string,\n options?: UserStorageMethodOptions,\n ): Promise<void> {\n await this.#upsertUserStorage(path, value, options);\n }\n\n async batchSetItems(\n path: UserStorageGenericFeatureName,\n values: [UserStorageGenericFeatureKey, string][],\n options?: UserStorageMethodOptions,\n ) {\n await this.#batchUpsertUserStorage(path, values, options);\n }\n\n async getItem(\n path: UserStorageGenericPathWithFeatureAndKey,\n options?: UserStorageMethodOptions,\n ): Promise<string | null> {\n return this.#getUserStorage(path, options);\n }\n\n async getAllFeatureItems(\n path: UserStorageGenericFeatureName,\n options?: UserStorageMethodOptions,\n ): Promise<string[] | null> {\n return this.#getUserStorageAllFeatureEntries(path, options);\n }\n\n async deleteItem(\n path: UserStorageGenericPathWithFeatureAndKey,\n options?: UserStorageMethodOptions,\n ): Promise<void> {\n return this.#deleteUserStorage(path, options);\n }\n\n async deleteAllFeatureItems(\n path: UserStorageGenericFeatureName,\n ): Promise<void> {\n return this.#deleteUserStorageAllFeatureEntries(path);\n }\n\n async batchDeleteItems(\n path: UserStorageGenericFeatureName,\n values: UserStorageGenericFeatureKey[],\n ) {\n return this.#batchDeleteUserStorage(path, values);\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(\n path: UserStorageGenericPathWithFeatureAndKey,\n data: string,\n options?: UserStorageMethodOptions,\n ): Promise<void> {\n try {\n const headers = await this.#getAuthorizationHeader();\n const storageKey = await this.getStorageKey();\n const encryptedData = await encryption.encryptString(\n data,\n storageKey,\n options?.nativeScryptCrypto,\n );\n const encryptedPath = createEntryPath(path, storageKey, {\n validateAgainstSchema: Boolean(options?.validateAgainstSchema),\n });\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 #batchUpsertUserStorage(\n path: UserStorageGenericPathWithFeatureOnly,\n data: [string, string][],\n options?: UserStorageMethodOptions,\n ): Promise<void> {\n try {\n if (!data.length) {\n return;\n }\n\n const headers = await this.#getAuthorizationHeader();\n const storageKey = await this.getStorageKey();\n\n const encryptedData = await Promise.all(\n data.map(async (d) => {\n return [\n this.#createEntryKey(d[0], storageKey),\n await encryption.encryptString(\n d[1],\n storageKey,\n options?.nativeScryptCrypto,\n ),\n ];\n }),\n );\n\n const url = new URL(STORAGE_URL(this.env, path));\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: Object.fromEntries(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 batch upsert user storage for path '${path}'. ${errorMessage}`,\n );\n }\n }\n\n async #batchUpsertUserStorageWithAlreadyHashedAndEncryptedEntries(\n path: UserStorageGenericPathWithFeatureOnly,\n encryptedData: [string, string][],\n ): Promise<void> {\n try {\n const headers = await this.#getAuthorizationHeader();\n\n const url = new URL(STORAGE_URL(this.env, path));\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: Object.fromEntries(encryptedData) }),\n });\n\n // istanbul ignore next\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 // istanbul ignore next\n throw new UserStorageError(\n `failed to batch upsert user storage for path '${path}'. ${errorMessage}`,\n );\n }\n }\n\n async #getUserStorage(\n path: UserStorageGenericPathWithFeatureAndKey,\n options?: UserStorageMethodOptions,\n ): Promise<string | null> {\n try {\n const headers = await this.#getAuthorizationHeader();\n const storageKey = await this.getStorageKey();\n const encryptedPath = createEntryPath(path, storageKey, {\n validateAgainstSchema: Boolean(options?.validateAgainstSchema),\n });\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 return null;\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 userStorage = await response.json();\n const encryptedData = userStorage?.Data ?? null;\n\n if (!encryptedData) {\n return null;\n }\n\n const decryptedData = await encryption.decryptString(\n encryptedData,\n storageKey,\n options?.nativeScryptCrypto,\n );\n\n // Re-encrypt the entry if it was encrypted with a random salt\n const salt = encryption.getSalt(encryptedData);\n if (salt.toString() !== SHARED_SALT.toString()) {\n await this.#upsertUserStorage(path, decryptedData, options);\n }\n\n return decryptedData;\n } catch (e) {\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 async #getUserStorageAllFeatureEntries(\n path: UserStorageGenericPathWithFeatureOnly,\n options?: UserStorageMethodOptions,\n ): Promise<string[] | null> {\n try {\n const headers = await this.#getAuthorizationHeader();\n const storageKey = await this.getStorageKey();\n\n const url = new URL(STORAGE_URL(this.env, path));\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 return null;\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 userStorage: GetUserStorageAllFeatureEntriesResponse | null =\n await response.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 if (!entry.Data) {\n continue;\n }\n\n try {\n const data = await encryption.decryptString(\n entry.Data,\n storageKey,\n options?.nativeScryptCrypto,\n );\n decryptedData.push(data);\n\n // Re-encrypt the entry was encrypted with a random salt\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 storageKey,\n options?.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 this.#batchUpsertUserStorageWithAlreadyHashedAndEncryptedEntries(\n path,\n reEncryptedEntries,\n );\n }\n\n return decryptedData;\n } catch (e) {\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 async #deleteUserStorage(\n path: UserStorageGenericPathWithFeatureAndKey,\n options?: UserStorageMethodOptions,\n ): Promise<void> {\n try {\n const headers = await this.#getAuthorizationHeader();\n const storageKey = await this.getStorageKey();\n const encryptedPath = createEntryPath(path, storageKey, {\n validateAgainstSchema: Boolean(options?.validateAgainstSchema),\n });\n\n const url = new URL(STORAGE_URL(this.env, encryptedPath));\n\n const response = await fetch(url.toString(), {\n method: 'DELETE',\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 } 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 delete user storage for path '${path}'. ${errorMessage}`,\n );\n }\n }\n\n async #deleteUserStorageAllFeatureEntries(\n path: UserStorageGenericPathWithFeatureOnly,\n ): Promise<void> {\n try {\n const headers = await this.#getAuthorizationHeader();\n\n const url = new URL(STORAGE_URL(this.env, path));\n\n const response = await fetch(url.toString(), {\n method: 'DELETE',\n headers: {\n 'Content-Type': 'application/json',\n ...headers,\n },\n });\n\n if (response.status === 404) {\n throw new NotFoundError(`feature not found for path '${path}'.`);\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 } 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 delete user storage for path '${path}'. ${errorMessage}`,\n );\n }\n }\n\n async #batchDeleteUserStorage(\n path: UserStorageGenericPathWithFeatureOnly,\n data: string[],\n ): Promise<void> {\n try {\n if (!data.length) {\n return;\n }\n\n const headers = await this.#getAuthorizationHeader();\n const storageKey = await this.getStorageKey();\n\n const encryptedData = await Promise.all(\n data.map(async (d) => this.#createEntryKey(d, storageKey)),\n );\n\n const url = new URL(STORAGE_URL(this.env, path));\n\n const response = await fetch(url.toString(), {\n method: 'PUT',\n headers: {\n 'Content-Type': 'application/json',\n ...headers,\n },\n\n body: JSON.stringify({ batch_delete: 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 batch delete 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 async #getAuthorizationHeader(): Promise<{ Authorization: string }> {\n const accessToken = await this.config.auth.getAccessToken();\n return { Authorization: `Bearer ${accessToken}` };\n }\n}\n"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { IBaseAuth } from "./authentication-jwt-bearer/types.cjs";
|
|
2
2
|
import type { Env } from "../shared/env.cjs";
|
|
3
3
|
import type { UserStorageGenericFeatureKey, UserStorageGenericFeatureName, UserStorageGenericPathWithFeatureAndKey } from "../shared/storage-schema.cjs";
|
|
4
|
+
import type { NativeScrypt } from "../shared/types/encryption.cjs";
|
|
4
5
|
export declare const STORAGE_URL: (env: Env, encryptedPath: string) => string;
|
|
5
6
|
export type UserStorageConfig = {
|
|
6
7
|
env: Env;
|
|
@@ -17,17 +18,21 @@ export type GetUserStorageAllFeatureEntriesResponse = {
|
|
|
17
18
|
HashedKey: string;
|
|
18
19
|
Data: string;
|
|
19
20
|
}[];
|
|
21
|
+
export type UserStorageMethodOptions = {
|
|
22
|
+
validateAgainstSchema?: boolean;
|
|
23
|
+
nativeScryptCrypto?: NativeScrypt;
|
|
24
|
+
};
|
|
20
25
|
export declare class UserStorage {
|
|
21
26
|
#private;
|
|
22
27
|
protected config: UserStorageConfig;
|
|
23
|
-
|
|
28
|
+
options: UserStorageOptions;
|
|
24
29
|
protected env: Env;
|
|
25
30
|
constructor(config: UserStorageConfig, options: UserStorageOptions);
|
|
26
|
-
setItem(path: UserStorageGenericPathWithFeatureAndKey, value: string): Promise<void>;
|
|
27
|
-
batchSetItems(path: UserStorageGenericFeatureName, values: [UserStorageGenericFeatureKey, string][]): Promise<void>;
|
|
28
|
-
getItem(path: UserStorageGenericPathWithFeatureAndKey): Promise<string>;
|
|
29
|
-
getAllFeatureItems(path: UserStorageGenericFeatureName): Promise<string[] | null>;
|
|
30
|
-
deleteItem(path: UserStorageGenericPathWithFeatureAndKey): Promise<void>;
|
|
31
|
+
setItem(path: UserStorageGenericPathWithFeatureAndKey, value: string, options?: UserStorageMethodOptions): Promise<void>;
|
|
32
|
+
batchSetItems(path: UserStorageGenericFeatureName, values: [UserStorageGenericFeatureKey, string][], options?: UserStorageMethodOptions): Promise<void>;
|
|
33
|
+
getItem(path: UserStorageGenericPathWithFeatureAndKey, options?: UserStorageMethodOptions): Promise<string | null>;
|
|
34
|
+
getAllFeatureItems(path: UserStorageGenericFeatureName, options?: UserStorageMethodOptions): Promise<string[] | null>;
|
|
35
|
+
deleteItem(path: UserStorageGenericPathWithFeatureAndKey, options?: UserStorageMethodOptions): Promise<void>;
|
|
31
36
|
deleteAllFeatureItems(path: UserStorageGenericFeatureName): Promise<void>;
|
|
32
37
|
batchDeleteItems(path: UserStorageGenericFeatureName, values: UserStorageGenericFeatureKey[]): Promise<void>;
|
|
33
38
|
getStorageKey(): Promise<string>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"user-storage.d.cts","sourceRoot":"","sources":["../../src/sdk/user-storage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,8CAA0C;AAInE,OAAO,KAAK,EAAE,GAAG,EAAE,0BAAsB;AAEzC,OAAO,KAAK,EACV,4BAA4B,EAC5B,6BAA6B,EAC7B,uCAAuC,EAExC,qCAAiC;
|
|
1
|
+
{"version":3,"file":"user-storage.d.cts","sourceRoot":"","sources":["../../src/sdk/user-storage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,8CAA0C;AAInE,OAAO,KAAK,EAAE,GAAG,EAAE,0BAAsB;AAEzC,OAAO,KAAK,EACV,4BAA4B,EAC5B,6BAA6B,EAC7B,uCAAuC,EAExC,qCAAiC;AAElC,OAAO,KAAK,EAAE,YAAY,EAAE,uCAAmC;AAE/D,eAAO,MAAM,WAAW,QAAS,GAAG,iBAAiB,MAAM,WACiB,CAAC;AAE7E,MAAM,MAAM,iBAAiB,GAAG;IAC9B,GAAG,EAAE,GAAG,CAAC;IACT,IAAI,EAAE,IAAI,CAAC,SAAS,EAAE,gBAAgB,GAAG,gBAAgB,GAAG,aAAa,CAAC,CAAC;CAC5E,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,aAAa,EAAE,MAAM,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAC5C,aAAa,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAC/C,CAAC;AA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AA4B,EAAE;IAKlC,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;CAocvC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { IBaseAuth } from "./authentication-jwt-bearer/types.mjs";
|
|
2
2
|
import type { Env } from "../shared/env.mjs";
|
|
3
3
|
import type { UserStorageGenericFeatureKey, UserStorageGenericFeatureName, UserStorageGenericPathWithFeatureAndKey } from "../shared/storage-schema.mjs";
|
|
4
|
+
import type { NativeScrypt } from "../shared/types/encryption.mjs";
|
|
4
5
|
export declare const STORAGE_URL: (env: Env, encryptedPath: string) => string;
|
|
5
6
|
export type UserStorageConfig = {
|
|
6
7
|
env: Env;
|
|
@@ -17,17 +18,21 @@ export type GetUserStorageAllFeatureEntriesResponse = {
|
|
|
17
18
|
HashedKey: string;
|
|
18
19
|
Data: string;
|
|
19
20
|
}[];
|
|
21
|
+
export type UserStorageMethodOptions = {
|
|
22
|
+
validateAgainstSchema?: boolean;
|
|
23
|
+
nativeScryptCrypto?: NativeScrypt;
|
|
24
|
+
};
|
|
20
25
|
export declare class UserStorage {
|
|
21
26
|
#private;
|
|
22
27
|
protected config: UserStorageConfig;
|
|
23
|
-
|
|
28
|
+
options: UserStorageOptions;
|
|
24
29
|
protected env: Env;
|
|
25
30
|
constructor(config: UserStorageConfig, options: UserStorageOptions);
|
|
26
|
-
setItem(path: UserStorageGenericPathWithFeatureAndKey, value: string): Promise<void>;
|
|
27
|
-
batchSetItems(path: UserStorageGenericFeatureName, values: [UserStorageGenericFeatureKey, string][]): Promise<void>;
|
|
28
|
-
getItem(path: UserStorageGenericPathWithFeatureAndKey): Promise<string>;
|
|
29
|
-
getAllFeatureItems(path: UserStorageGenericFeatureName): Promise<string[] | null>;
|
|
30
|
-
deleteItem(path: UserStorageGenericPathWithFeatureAndKey): Promise<void>;
|
|
31
|
+
setItem(path: UserStorageGenericPathWithFeatureAndKey, value: string, options?: UserStorageMethodOptions): Promise<void>;
|
|
32
|
+
batchSetItems(path: UserStorageGenericFeatureName, values: [UserStorageGenericFeatureKey, string][], options?: UserStorageMethodOptions): Promise<void>;
|
|
33
|
+
getItem(path: UserStorageGenericPathWithFeatureAndKey, options?: UserStorageMethodOptions): Promise<string | null>;
|
|
34
|
+
getAllFeatureItems(path: UserStorageGenericFeatureName, options?: UserStorageMethodOptions): Promise<string[] | null>;
|
|
35
|
+
deleteItem(path: UserStorageGenericPathWithFeatureAndKey, options?: UserStorageMethodOptions): Promise<void>;
|
|
31
36
|
deleteAllFeatureItems(path: UserStorageGenericFeatureName): Promise<void>;
|
|
32
37
|
batchDeleteItems(path: UserStorageGenericFeatureName, values: UserStorageGenericFeatureKey[]): Promise<void>;
|
|
33
38
|
getStorageKey(): Promise<string>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"user-storage.d.mts","sourceRoot":"","sources":["../../src/sdk/user-storage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,8CAA0C;AAInE,OAAO,KAAK,EAAE,GAAG,EAAE,0BAAsB;AAEzC,OAAO,KAAK,EACV,4BAA4B,EAC5B,6BAA6B,EAC7B,uCAAuC,EAExC,qCAAiC;
|
|
1
|
+
{"version":3,"file":"user-storage.d.mts","sourceRoot":"","sources":["../../src/sdk/user-storage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,8CAA0C;AAInE,OAAO,KAAK,EAAE,GAAG,EAAE,0BAAsB;AAEzC,OAAO,KAAK,EACV,4BAA4B,EAC5B,6BAA6B,EAC7B,uCAAuC,EAExC,qCAAiC;AAElC,OAAO,KAAK,EAAE,YAAY,EAAE,uCAAmC;AAE/D,eAAO,MAAM,WAAW,QAAS,GAAG,iBAAiB,MAAM,WACiB,CAAC;AAE7E,MAAM,MAAM,iBAAiB,GAAG;IAC9B,GAAG,EAAE,GAAG,CAAC;IACT,IAAI,EAAE,IAAI,CAAC,SAAS,EAAE,gBAAgB,GAAG,gBAAgB,GAAG,aAAa,CAAC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