@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.
Files changed (303) hide show
  1. package/CHANGELOG.md +22 -1
  2. package/README.md +32 -0
  3. package/auth/mocks/package.json +2 -2
  4. package/dist/controllers/authentication/AuthenticationController.cjs +53 -86
  5. package/dist/controllers/authentication/AuthenticationController.cjs.map +1 -1
  6. package/dist/controllers/authentication/AuthenticationController.d.cts +11 -23
  7. package/dist/controllers/authentication/AuthenticationController.d.cts.map +1 -1
  8. package/dist/controllers/authentication/AuthenticationController.d.mts +11 -23
  9. package/dist/controllers/authentication/AuthenticationController.d.mts.map +1 -1
  10. package/dist/controllers/authentication/AuthenticationController.mjs +53 -86
  11. package/dist/controllers/authentication/AuthenticationController.mjs.map +1 -1
  12. package/dist/controllers/authentication/index.cjs +1 -1
  13. package/dist/controllers/authentication/index.cjs.map +1 -1
  14. package/dist/controllers/authentication/index.d.cts +1 -1
  15. package/dist/controllers/authentication/index.d.cts.map +1 -1
  16. package/dist/controllers/authentication/index.d.mts +1 -1
  17. package/dist/controllers/authentication/index.d.mts.map +1 -1
  18. package/dist/controllers/authentication/index.mjs +1 -1
  19. package/dist/controllers/authentication/index.mjs.map +1 -1
  20. package/dist/controllers/authentication/mocks/index.cjs.map +1 -0
  21. package/dist/controllers/authentication/mocks/index.d.cts.map +1 -0
  22. package/dist/controllers/authentication/mocks/index.d.mts.map +1 -0
  23. package/dist/controllers/authentication/mocks/index.mjs.map +1 -0
  24. package/dist/controllers/authentication/mocks/mockResponses.cjs +34 -0
  25. package/dist/controllers/authentication/mocks/mockResponses.cjs.map +1 -0
  26. package/dist/controllers/authentication/mocks/mockResponses.d.cts +55 -0
  27. package/dist/controllers/authentication/mocks/mockResponses.d.cts.map +1 -0
  28. package/dist/controllers/authentication/mocks/mockResponses.d.mts +55 -0
  29. package/dist/controllers/authentication/mocks/mockResponses.d.mts.map +1 -0
  30. package/dist/controllers/authentication/mocks/mockResponses.mjs +28 -0
  31. package/dist/controllers/authentication/mocks/mockResponses.mjs.map +1 -0
  32. package/dist/controllers/user-storage/UserStorageController.cjs +71 -127
  33. package/dist/controllers/user-storage/UserStorageController.cjs.map +1 -1
  34. package/dist/controllers/user-storage/UserStorageController.d.cts +5 -4
  35. package/dist/controllers/user-storage/UserStorageController.d.cts.map +1 -1
  36. package/dist/controllers/user-storage/UserStorageController.d.mts +5 -4
  37. package/dist/controllers/user-storage/UserStorageController.d.mts.map +1 -1
  38. package/dist/controllers/user-storage/UserStorageController.mjs +71 -127
  39. package/dist/controllers/user-storage/UserStorageController.mjs.map +1 -1
  40. package/dist/controllers/user-storage/account-syncing/controller-integration.cjs +2 -2
  41. package/dist/controllers/user-storage/account-syncing/controller-integration.cjs.map +1 -1
  42. package/dist/controllers/user-storage/account-syncing/controller-integration.mjs +2 -2
  43. package/dist/controllers/user-storage/account-syncing/controller-integration.mjs.map +1 -1
  44. package/dist/controllers/user-storage/account-syncing/sync-utils.cjs +1 -0
  45. package/dist/controllers/user-storage/account-syncing/sync-utils.cjs.map +1 -1
  46. package/dist/controllers/user-storage/account-syncing/sync-utils.d.cts.map +1 -1
  47. package/dist/controllers/user-storage/account-syncing/sync-utils.d.mts.map +1 -1
  48. package/dist/controllers/user-storage/account-syncing/sync-utils.mjs +1 -0
  49. package/dist/controllers/user-storage/account-syncing/sync-utils.mjs.map +1 -1
  50. package/dist/controllers/user-storage/account-syncing/utils.cjs +2 -2
  51. package/dist/controllers/user-storage/account-syncing/utils.cjs.map +1 -1
  52. package/dist/controllers/user-storage/account-syncing/utils.mjs +2 -2
  53. package/dist/controllers/user-storage/account-syncing/utils.mjs.map +1 -1
  54. package/dist/controllers/user-storage/index.cjs +1 -1
  55. package/dist/controllers/user-storage/index.cjs.map +1 -1
  56. package/dist/controllers/user-storage/index.d.cts +1 -1
  57. package/dist/controllers/user-storage/index.d.cts.map +1 -1
  58. package/dist/controllers/user-storage/index.d.mts +1 -1
  59. package/dist/controllers/user-storage/index.d.mts.map +1 -1
  60. package/dist/controllers/user-storage/index.mjs +1 -1
  61. package/dist/controllers/user-storage/index.mjs.map +1 -1
  62. package/dist/controllers/user-storage/mocks/index.cjs.map +1 -0
  63. package/dist/controllers/user-storage/mocks/index.d.cts.map +1 -0
  64. package/dist/controllers/user-storage/mocks/index.d.mts.map +1 -0
  65. package/dist/controllers/user-storage/mocks/index.mjs.map +1 -0
  66. package/dist/controllers/user-storage/{__fixtures__ → mocks}/mockResponses.cjs +3 -3
  67. package/dist/controllers/user-storage/mocks/mockResponses.cjs.map +1 -0
  68. package/dist/controllers/user-storage/{__fixtures__ → mocks}/mockResponses.d.cts +1 -1
  69. package/dist/controllers/user-storage/mocks/mockResponses.d.cts.map +1 -0
  70. package/dist/controllers/user-storage/{__fixtures__ → mocks}/mockResponses.d.mts +1 -1
  71. package/dist/controllers/user-storage/mocks/mockResponses.d.mts.map +1 -0
  72. package/dist/controllers/user-storage/{__fixtures__ → mocks}/mockResponses.mjs +3 -3
  73. package/dist/controllers/user-storage/mocks/mockResponses.mjs.map +1 -0
  74. package/dist/controllers/user-storage/mocks/mockStorage.cjs.map +1 -0
  75. package/dist/controllers/user-storage/mocks/mockStorage.d.cts.map +1 -0
  76. package/dist/controllers/user-storage/mocks/mockStorage.d.mts.map +1 -0
  77. package/dist/controllers/user-storage/mocks/mockStorage.mjs.map +1 -0
  78. package/dist/controllers/user-storage/network-syncing/controller-integration.cjs +14 -14
  79. package/dist/controllers/user-storage/network-syncing/controller-integration.cjs.map +1 -1
  80. package/dist/controllers/user-storage/network-syncing/controller-integration.d.cts +3 -3
  81. package/dist/controllers/user-storage/network-syncing/controller-integration.d.cts.map +1 -1
  82. package/dist/controllers/user-storage/network-syncing/controller-integration.d.mts +3 -3
  83. package/dist/controllers/user-storage/network-syncing/controller-integration.d.mts.map +1 -1
  84. package/dist/controllers/user-storage/network-syncing/controller-integration.mjs +14 -14
  85. package/dist/controllers/user-storage/network-syncing/controller-integration.mjs.map +1 -1
  86. package/dist/controllers/user-storage/network-syncing/services.cjs +27 -23
  87. package/dist/controllers/user-storage/network-syncing/services.cjs.map +1 -1
  88. package/dist/controllers/user-storage/network-syncing/services.d.cts +16 -7
  89. package/dist/controllers/user-storage/network-syncing/services.d.cts.map +1 -1
  90. package/dist/controllers/user-storage/network-syncing/services.d.mts +16 -7
  91. package/dist/controllers/user-storage/network-syncing/services.d.mts.map +1 -1
  92. package/dist/controllers/user-storage/network-syncing/services.mjs +27 -23
  93. package/dist/controllers/user-storage/network-syncing/services.mjs.map +1 -1
  94. package/dist/controllers/user-storage/network-syncing/sync-mutations.cjs.map +1 -1
  95. package/dist/controllers/user-storage/network-syncing/sync-mutations.d.cts +13 -5
  96. package/dist/controllers/user-storage/network-syncing/sync-mutations.d.cts.map +1 -1
  97. package/dist/controllers/user-storage/network-syncing/sync-mutations.d.mts +13 -5
  98. package/dist/controllers/user-storage/network-syncing/sync-mutations.d.mts.map +1 -1
  99. package/dist/controllers/user-storage/network-syncing/sync-mutations.mjs.map +1 -1
  100. package/dist/controllers/user-storage/types.cjs +3 -0
  101. package/dist/controllers/user-storage/types.cjs.map +1 -0
  102. package/dist/controllers/user-storage/types.d.cts +23 -0
  103. package/dist/controllers/user-storage/types.d.cts.map +1 -0
  104. package/dist/controllers/user-storage/types.d.mts +23 -0
  105. package/dist/controllers/user-storage/types.d.mts.map +1 -0
  106. package/dist/controllers/user-storage/types.mjs +2 -0
  107. package/dist/controllers/user-storage/types.mjs.map +1 -0
  108. package/dist/sdk/authentication-jwt-bearer/flow-srp.cjs +7 -8
  109. package/dist/sdk/authentication-jwt-bearer/flow-srp.cjs.map +1 -1
  110. package/dist/sdk/authentication-jwt-bearer/flow-srp.d.cts +2 -0
  111. package/dist/sdk/authentication-jwt-bearer/flow-srp.d.cts.map +1 -1
  112. package/dist/sdk/authentication-jwt-bearer/flow-srp.d.mts +2 -0
  113. package/dist/sdk/authentication-jwt-bearer/flow-srp.d.mts.map +1 -1
  114. package/dist/sdk/authentication-jwt-bearer/flow-srp.mjs +8 -9
  115. package/dist/sdk/authentication-jwt-bearer/flow-srp.mjs.map +1 -1
  116. package/dist/sdk/authentication-jwt-bearer/services.cjs +10 -2
  117. package/dist/sdk/authentication-jwt-bearer/services.cjs.map +1 -1
  118. package/dist/sdk/authentication-jwt-bearer/services.d.cts +3 -1
  119. package/dist/sdk/authentication-jwt-bearer/services.d.cts.map +1 -1
  120. package/dist/sdk/authentication-jwt-bearer/services.d.mts +3 -1
  121. package/dist/sdk/authentication-jwt-bearer/services.d.mts.map +1 -1
  122. package/dist/sdk/authentication-jwt-bearer/services.mjs +10 -2
  123. package/dist/sdk/authentication-jwt-bearer/services.mjs.map +1 -1
  124. package/dist/sdk/authentication-jwt-bearer/types.cjs.map +1 -1
  125. package/dist/sdk/authentication-jwt-bearer/types.mjs.map +1 -1
  126. package/dist/sdk/authentication.cjs.map +1 -1
  127. package/dist/sdk/authentication.d.cts +1 -1
  128. package/dist/sdk/authentication.d.cts.map +1 -1
  129. package/dist/sdk/authentication.d.mts +1 -1
  130. package/dist/sdk/authentication.d.mts.map +1 -1
  131. package/dist/sdk/authentication.mjs.map +1 -1
  132. package/dist/sdk/mocks/auth.cjs +44 -0
  133. package/dist/sdk/mocks/auth.cjs.map +1 -0
  134. package/dist/sdk/{__fixtures__/mock-auth.d.cts → mocks/auth.d.cts} +22 -25
  135. package/dist/sdk/mocks/auth.d.cts.map +1 -0
  136. package/dist/sdk/{__fixtures__/mock-auth.d.mts → mocks/auth.d.mts} +22 -25
  137. package/dist/sdk/mocks/auth.d.mts.map +1 -0
  138. package/dist/sdk/mocks/auth.mjs +41 -0
  139. package/dist/sdk/mocks/auth.mjs.map +1 -0
  140. package/dist/sdk/mocks/userstorage.cjs +43 -0
  141. package/dist/sdk/mocks/userstorage.cjs.map +1 -0
  142. package/dist/sdk/mocks/userstorage.d.cts +10 -0
  143. package/dist/sdk/mocks/userstorage.d.cts.map +1 -0
  144. package/dist/sdk/mocks/userstorage.d.mts +10 -0
  145. package/dist/sdk/mocks/userstorage.d.mts.map +1 -0
  146. package/dist/sdk/mocks/userstorage.mjs +15 -0
  147. package/dist/sdk/mocks/userstorage.mjs.map +1 -0
  148. package/dist/sdk/user-storage.cjs +34 -39
  149. package/dist/sdk/user-storage.cjs.map +1 -1
  150. package/dist/sdk/user-storage.d.cts +11 -6
  151. package/dist/sdk/user-storage.d.cts.map +1 -1
  152. package/dist/sdk/user-storage.d.mts +11 -6
  153. package/dist/sdk/user-storage.d.mts.map +1 -1
  154. package/dist/sdk/user-storage.mjs +34 -39
  155. package/dist/sdk/user-storage.mjs.map +1 -1
  156. package/dist/sdk/utils/messaging-signing-snap-requests.cjs +12 -1
  157. package/dist/sdk/utils/messaging-signing-snap-requests.cjs.map +1 -1
  158. package/dist/sdk/utils/messaging-signing-snap-requests.d.cts +6 -0
  159. package/dist/sdk/utils/messaging-signing-snap-requests.d.cts.map +1 -1
  160. package/dist/sdk/utils/messaging-signing-snap-requests.d.mts +6 -0
  161. package/dist/sdk/utils/messaging-signing-snap-requests.d.mts.map +1 -1
  162. package/dist/sdk/utils/messaging-signing-snap-requests.mjs +10 -0
  163. package/dist/sdk/utils/messaging-signing-snap-requests.mjs.map +1 -1
  164. package/dist/shared/types/services.cjs +3 -0
  165. package/dist/shared/types/services.cjs.map +1 -0
  166. package/dist/shared/types/services.d.cts +10 -0
  167. package/dist/shared/types/services.d.cts.map +1 -0
  168. package/dist/shared/types/services.d.mts +10 -0
  169. package/dist/shared/types/services.d.mts.map +1 -0
  170. package/dist/shared/types/services.mjs +2 -0
  171. package/dist/shared/types/services.mjs.map +1 -0
  172. package/package.json +14 -14
  173. package/user-storage/mocks/package.json +2 -2
  174. package/dist/controllers/authentication/__fixtures__/index.cjs.map +0 -1
  175. package/dist/controllers/authentication/__fixtures__/index.d.cts.map +0 -1
  176. package/dist/controllers/authentication/__fixtures__/index.d.mts.map +0 -1
  177. package/dist/controllers/authentication/__fixtures__/index.mjs.map +0 -1
  178. package/dist/controllers/authentication/__fixtures__/mockResponses.cjs +0 -47
  179. package/dist/controllers/authentication/__fixtures__/mockResponses.cjs.map +0 -1
  180. package/dist/controllers/authentication/__fixtures__/mockResponses.d.cts +0 -23
  181. package/dist/controllers/authentication/__fixtures__/mockResponses.d.cts.map +0 -1
  182. package/dist/controllers/authentication/__fixtures__/mockResponses.d.mts +0 -23
  183. package/dist/controllers/authentication/__fixtures__/mockResponses.d.mts.map +0 -1
  184. package/dist/controllers/authentication/__fixtures__/mockResponses.mjs +0 -41
  185. package/dist/controllers/authentication/__fixtures__/mockResponses.mjs.map +0 -1
  186. package/dist/controllers/authentication/__fixtures__/mockServices.cjs +0 -37
  187. package/dist/controllers/authentication/__fixtures__/mockServices.cjs.map +0 -1
  188. package/dist/controllers/authentication/__fixtures__/mockServices.d.cts +0 -10
  189. package/dist/controllers/authentication/__fixtures__/mockServices.d.cts.map +0 -1
  190. package/dist/controllers/authentication/__fixtures__/mockServices.d.mts +0 -10
  191. package/dist/controllers/authentication/__fixtures__/mockServices.d.mts.map +0 -1
  192. package/dist/controllers/authentication/__fixtures__/mockServices.mjs +0 -35
  193. package/dist/controllers/authentication/__fixtures__/mockServices.mjs.map +0 -1
  194. package/dist/controllers/authentication/services.cjs +0 -132
  195. package/dist/controllers/authentication/services.cjs.map +0 -1
  196. package/dist/controllers/authentication/services.d.cts +0 -72
  197. package/dist/controllers/authentication/services.d.cts.map +0 -1
  198. package/dist/controllers/authentication/services.d.mts +0 -72
  199. package/dist/controllers/authentication/services.d.mts.map +0 -1
  200. package/dist/controllers/authentication/services.mjs +0 -129
  201. package/dist/controllers/authentication/services.mjs.map +0 -1
  202. package/dist/controllers/user-storage/__fixtures__/index.cjs.map +0 -1
  203. package/dist/controllers/user-storage/__fixtures__/index.d.cts.map +0 -1
  204. package/dist/controllers/user-storage/__fixtures__/index.d.mts.map +0 -1
  205. package/dist/controllers/user-storage/__fixtures__/index.mjs.map +0 -1
  206. package/dist/controllers/user-storage/__fixtures__/mockMessenger.cjs +0 -167
  207. package/dist/controllers/user-storage/__fixtures__/mockMessenger.cjs.map +0 -1
  208. package/dist/controllers/user-storage/__fixtures__/mockMessenger.d.cts +0 -105
  209. package/dist/controllers/user-storage/__fixtures__/mockMessenger.d.cts.map +0 -1
  210. package/dist/controllers/user-storage/__fixtures__/mockMessenger.d.mts +0 -105
  211. package/dist/controllers/user-storage/__fixtures__/mockMessenger.d.mts.map +0 -1
  212. package/dist/controllers/user-storage/__fixtures__/mockMessenger.mjs +0 -162
  213. package/dist/controllers/user-storage/__fixtures__/mockMessenger.mjs.map +0 -1
  214. package/dist/controllers/user-storage/__fixtures__/mockResponses.cjs.map +0 -1
  215. package/dist/controllers/user-storage/__fixtures__/mockResponses.d.cts.map +0 -1
  216. package/dist/controllers/user-storage/__fixtures__/mockResponses.d.mts.map +0 -1
  217. package/dist/controllers/user-storage/__fixtures__/mockResponses.mjs.map +0 -1
  218. package/dist/controllers/user-storage/__fixtures__/mockServices.cjs +0 -82
  219. package/dist/controllers/user-storage/__fixtures__/mockServices.cjs.map +0 -1
  220. package/dist/controllers/user-storage/__fixtures__/mockServices.d.cts +0 -15
  221. package/dist/controllers/user-storage/__fixtures__/mockServices.d.cts.map +0 -1
  222. package/dist/controllers/user-storage/__fixtures__/mockServices.d.mts +0 -15
  223. package/dist/controllers/user-storage/__fixtures__/mockServices.d.mts.map +0 -1
  224. package/dist/controllers/user-storage/__fixtures__/mockServices.mjs +0 -76
  225. package/dist/controllers/user-storage/__fixtures__/mockServices.mjs.map +0 -1
  226. package/dist/controllers/user-storage/__fixtures__/mockStorage.cjs.map +0 -1
  227. package/dist/controllers/user-storage/__fixtures__/mockStorage.d.cts.map +0 -1
  228. package/dist/controllers/user-storage/__fixtures__/mockStorage.d.mts.map +0 -1
  229. package/dist/controllers/user-storage/__fixtures__/mockStorage.mjs.map +0 -1
  230. package/dist/controllers/user-storage/__fixtures__/test-utils.cjs +0 -78
  231. package/dist/controllers/user-storage/__fixtures__/test-utils.cjs.map +0 -1
  232. package/dist/controllers/user-storage/__fixtures__/test-utils.d.cts +0 -38
  233. package/dist/controllers/user-storage/__fixtures__/test-utils.d.cts.map +0 -1
  234. package/dist/controllers/user-storage/__fixtures__/test-utils.d.mts +0 -38
  235. package/dist/controllers/user-storage/__fixtures__/test-utils.d.mts.map +0 -1
  236. package/dist/controllers/user-storage/__fixtures__/test-utils.mjs +0 -68
  237. package/dist/controllers/user-storage/__fixtures__/test-utils.mjs.map +0 -1
  238. package/dist/controllers/user-storage/account-syncing/__fixtures__/mockAccounts.cjs +0 -178
  239. package/dist/controllers/user-storage/account-syncing/__fixtures__/mockAccounts.cjs.map +0 -1
  240. package/dist/controllers/user-storage/account-syncing/__fixtures__/mockAccounts.d.cts +0 -91
  241. package/dist/controllers/user-storage/account-syncing/__fixtures__/mockAccounts.d.cts.map +0 -1
  242. package/dist/controllers/user-storage/account-syncing/__fixtures__/mockAccounts.d.mts +0 -91
  243. package/dist/controllers/user-storage/account-syncing/__fixtures__/mockAccounts.d.mts.map +0 -1
  244. package/dist/controllers/user-storage/account-syncing/__fixtures__/mockAccounts.mjs +0 -174
  245. package/dist/controllers/user-storage/account-syncing/__fixtures__/mockAccounts.mjs.map +0 -1
  246. package/dist/controllers/user-storage/account-syncing/__fixtures__/test-utils.cjs +0 -58
  247. package/dist/controllers/user-storage/account-syncing/__fixtures__/test-utils.cjs.map +0 -1
  248. package/dist/controllers/user-storage/account-syncing/__fixtures__/test-utils.d.cts +0 -87
  249. package/dist/controllers/user-storage/account-syncing/__fixtures__/test-utils.d.cts.map +0 -1
  250. package/dist/controllers/user-storage/account-syncing/__fixtures__/test-utils.d.mts +0 -87
  251. package/dist/controllers/user-storage/account-syncing/__fixtures__/test-utils.d.mts.map +0 -1
  252. package/dist/controllers/user-storage/account-syncing/__fixtures__/test-utils.mjs +0 -52
  253. package/dist/controllers/user-storage/account-syncing/__fixtures__/test-utils.mjs.map +0 -1
  254. package/dist/controllers/user-storage/network-syncing/__fixtures__/mockNetwork.cjs +0 -43
  255. package/dist/controllers/user-storage/network-syncing/__fixtures__/mockNetwork.cjs.map +0 -1
  256. package/dist/controllers/user-storage/network-syncing/__fixtures__/mockNetwork.d.cts +0 -11
  257. package/dist/controllers/user-storage/network-syncing/__fixtures__/mockNetwork.d.cts.map +0 -1
  258. package/dist/controllers/user-storage/network-syncing/__fixtures__/mockNetwork.d.mts +0 -11
  259. package/dist/controllers/user-storage/network-syncing/__fixtures__/mockNetwork.d.mts.map +0 -1
  260. package/dist/controllers/user-storage/network-syncing/__fixtures__/mockNetwork.mjs +0 -36
  261. package/dist/controllers/user-storage/network-syncing/__fixtures__/mockNetwork.mjs.map +0 -1
  262. package/dist/controllers/user-storage/services.cjs +0 -306
  263. package/dist/controllers/user-storage/services.cjs.map +0 -1
  264. package/dist/controllers/user-storage/services.d.cts +0 -85
  265. package/dist/controllers/user-storage/services.d.cts.map +0 -1
  266. package/dist/controllers/user-storage/services.d.mts +0 -85
  267. package/dist/controllers/user-storage/services.d.mts.map +0 -1
  268. package/dist/controllers/user-storage/services.mjs +0 -276
  269. package/dist/controllers/user-storage/services.mjs.map +0 -1
  270. package/dist/sdk/__fixtures__/mock-auth.cjs +0 -124
  271. package/dist/sdk/__fixtures__/mock-auth.cjs.map +0 -1
  272. package/dist/sdk/__fixtures__/mock-auth.d.cts.map +0 -1
  273. package/dist/sdk/__fixtures__/mock-auth.d.mts.map +0 -1
  274. package/dist/sdk/__fixtures__/mock-auth.mjs +0 -119
  275. package/dist/sdk/__fixtures__/mock-auth.mjs.map +0 -1
  276. package/dist/sdk/__fixtures__/mock-userstorage.cjs +0 -111
  277. package/dist/sdk/__fixtures__/mock-userstorage.cjs.map +0 -1
  278. package/dist/sdk/__fixtures__/mock-userstorage.d.cts +0 -20
  279. package/dist/sdk/__fixtures__/mock-userstorage.d.cts.map +0 -1
  280. package/dist/sdk/__fixtures__/mock-userstorage.d.mts +0 -20
  281. package/dist/sdk/__fixtures__/mock-userstorage.d.mts.map +0 -1
  282. package/dist/sdk/__fixtures__/mock-userstorage.mjs +0 -81
  283. package/dist/sdk/__fixtures__/mock-userstorage.mjs.map +0 -1
  284. package/dist/sdk/__fixtures__/test-utils.cjs +0 -90
  285. package/dist/sdk/__fixtures__/test-utils.cjs.map +0 -1
  286. package/dist/sdk/__fixtures__/test-utils.d.cts +0 -37
  287. package/dist/sdk/__fixtures__/test-utils.d.cts.map +0 -1
  288. package/dist/sdk/__fixtures__/test-utils.d.mts +0 -37
  289. package/dist/sdk/__fixtures__/test-utils.d.mts.map +0 -1
  290. package/dist/sdk/__fixtures__/test-utils.mjs +0 -84
  291. package/dist/sdk/__fixtures__/test-utils.mjs.map +0 -1
  292. /package/dist/controllers/authentication/{__fixtures__ → mocks}/index.cjs +0 -0
  293. /package/dist/controllers/authentication/{__fixtures__ → mocks}/index.d.cts +0 -0
  294. /package/dist/controllers/authentication/{__fixtures__ → mocks}/index.d.mts +0 -0
  295. /package/dist/controllers/authentication/{__fixtures__ → mocks}/index.mjs +0 -0
  296. /package/dist/controllers/user-storage/{__fixtures__ → mocks}/index.cjs +0 -0
  297. /package/dist/controllers/user-storage/{__fixtures__ → mocks}/index.d.cts +0 -0
  298. /package/dist/controllers/user-storage/{__fixtures__ → mocks}/index.d.mts +0 -0
  299. /package/dist/controllers/user-storage/{__fixtures__ → mocks}/index.mjs +0 -0
  300. /package/dist/controllers/user-storage/{__fixtures__ → mocks}/mockStorage.cjs +0 -0
  301. /package/dist/controllers/user-storage/{__fixtures__ → mocks}/mockStorage.d.cts +0 -0
  302. /package/dist/controllers/user-storage/{__fixtures__ → mocks}/mockStorage.d.mts +0 -0
  303. /package/dist/controllers/user-storage/{__fixtures__ → mocks}/mockStorage.mjs +0 -0
@@ -1 +0,0 @@
1
- {"version":3,"file":"mockNetwork.mjs","sourceRoot":"","sources":["../../../../../src/controllers/user-storage/network-syncing/__fixtures__/mockNetwork.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,qCAAqC;AAM/D,MAAM,CAAC,MAAM,8BAA8B,GAAG,CAC5C,QAAwC,EAClB,EAAE;IACxB,OAAO;QACL,OAAO,EAAE,QAAQ;QACjB,iBAAiB,EAAE,CAAC,sBAAsB,CAAC;QAC3C,uBAAuB,EAAE,CAAC;QAC1B,IAAI,EAAE,cAAc;QACpB,cAAc,EAAE,YAAY;QAC5B,YAAY,EAAE,EAAE;QAChB,4BAA4B,EAAE,CAAC;QAC/B,GAAG,QAAQ;KACZ,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,oCAAoC,GAAG,CAClD,QAA8C,EAClB,EAAE;IAC9B,OAAO;QACL,CAAC,EAAE,GAAG;QACN,GAAG,8BAA8B,EAAE;QACnC,GAAG,QAAQ;KACZ,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,2BAA2B,GAAG,CACzC,QAAyE,EAC5D,EAAE;IACf,OAAO;QACL,IAAI,EAAE,eAAe,CAAC,MAAM;QAC5B,eAAe,EAAE,gBAAgB;QACjC,GAAG,EAAE,mBAAmB;QACxB,GAAG,QAAQ;KACG,CAAC;AACnB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,2BAA2B,GAAG,GAAgB,EAAE;IAC3D,OAAO;QACL,IAAI,EAAE,eAAe,CAAC,MAAM;QAC5B,eAAe,EAAE,SAAS;QAC1B,GAAG,EAAE,gDAAgD;KACtD,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import type { NetworkConfiguration } from '@metamask/network-controller';\nimport { RpcEndpointType } from '@metamask/network-controller';\n\nimport type { RemoteNetworkConfiguration } from '../types';\n\nexport type RPCEndpoint = NetworkConfiguration['rpcEndpoints'][number];\n\nexport const createMockNetworkConfiguration = (\n override?: Partial<NetworkConfiguration>,\n): NetworkConfiguration => {\n return {\n chainId: '0x1337',\n blockExplorerUrls: ['https://etherscan.io'],\n defaultRpcEndpointIndex: 0,\n name: 'Mock Network',\n nativeCurrency: 'MOCK TOKEN',\n rpcEndpoints: [],\n defaultBlockExplorerUrlIndex: 0,\n ...override,\n };\n};\n\nexport const createMockRemoteNetworkConfiguration = (\n override?: Partial<RemoteNetworkConfiguration>,\n): RemoteNetworkConfiguration => {\n return {\n v: '1',\n ...createMockNetworkConfiguration(),\n ...override,\n };\n};\n\nexport const createMockCustomRpcEndpoint = (\n override: Partial<Extract<RPCEndpoint, { type: RpcEndpointType.Custom }>>,\n): RPCEndpoint => {\n return {\n type: RpcEndpointType.Custom,\n networkClientId: '1111-1111-1111',\n url: `https://FAKE_RPC/`,\n ...override,\n } as RPCEndpoint;\n};\n\nexport const createMockInfuraRpcEndpoint = (): RPCEndpoint => {\n return {\n type: RpcEndpointType.Infura,\n networkClientId: 'mainnet',\n url: `https://mainnet.infura.io/v3/{infuraProjectId}`,\n };\n};\n"]}
@@ -1,306 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __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
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.deleteUserStorageAllFeatureEntries = exports.batchDeleteUserStorage = exports.deleteUserStorage = exports.batchUpsertUserStorageWithAlreadyHashedAndEncryptedEntries = exports.batchUpsertUserStorage = exports.upsertUserStorage = exports.getUserStorageAllFeatureEntries = exports.getUserStorage = exports.USER_STORAGE_ENDPOINT = exports.USER_STORAGE_API = void 0;
30
- const loglevel_1 = __importDefault(require("loglevel"));
31
- const encryption_1 = __importStar(require("../../shared/encryption/index.cjs"));
32
- const constants_1 = require("../../shared/encryption/constants.cjs");
33
- const env_1 = require("../../shared/env.cjs");
34
- const storage_schema_1 = require("../../shared/storage-schema.cjs");
35
- const ENV_URLS = (0, env_1.getEnvUrls)(env_1.Env.PRD);
36
- exports.USER_STORAGE_API = ENV_URLS.userStorageApiUrl;
37
- exports.USER_STORAGE_ENDPOINT = `${exports.USER_STORAGE_API}/api/v1/userstorage`;
38
- /**
39
- * User Storage Service - Get Storage Entry.
40
- *
41
- * @param opts - User Storage Options
42
- * @returns The storage entry, or null if fails to find entry
43
- */
44
- async function getUserStorage(opts) {
45
- try {
46
- const { bearerToken, path, storageKey, nativeScryptCrypto } = opts;
47
- const encryptedPath = (0, storage_schema_1.createEntryPath)(path, storageKey);
48
- const url = new URL(`${exports.USER_STORAGE_ENDPOINT}/${encryptedPath}`);
49
- const userStorageResponse = await fetch(url.toString(), {
50
- headers: {
51
- 'Content-Type': 'application/json',
52
- Authorization: `Bearer ${bearerToken}`,
53
- },
54
- });
55
- // Acceptable error - since indicates entry does not exist.
56
- if (userStorageResponse.status === 404) {
57
- return null;
58
- }
59
- if (userStorageResponse.status !== 200) {
60
- throw new Error(`Unable to get User Storage - HTTP ${userStorageResponse.status}`);
61
- }
62
- const userStorage = await userStorageResponse.json();
63
- const encryptedData = userStorage?.Data ?? null;
64
- /* istanbul ignore if - this is an edge case where our endpoint returns invalid JSON payload */
65
- if (!encryptedData) {
66
- return null;
67
- }
68
- const decryptedData = await encryption_1.default.decryptString(encryptedData, opts.storageKey, nativeScryptCrypto);
69
- // Re-encrypt and re-upload the entry if the salt is random
70
- const salt = encryption_1.default.getSalt(encryptedData);
71
- if (salt.toString() !== constants_1.SHARED_SALT.toString()) {
72
- await upsertUserStorage(decryptedData, opts);
73
- }
74
- return decryptedData;
75
- }
76
- catch (e) {
77
- loglevel_1.default.error('Failed to get user storage', e);
78
- return null;
79
- }
80
- }
81
- exports.getUserStorage = getUserStorage;
82
- /**
83
- * User Storage Service - Get all storage entries for a specific feature.
84
- *
85
- * @param opts - User Storage Options
86
- * @returns The storage entry, or null if fails to find entry
87
- */
88
- async function getUserStorageAllFeatureEntries(opts) {
89
- try {
90
- const { bearerToken, path, nativeScryptCrypto } = opts;
91
- const url = new URL(`${exports.USER_STORAGE_ENDPOINT}/${path}`);
92
- const userStorageResponse = await fetch(url.toString(), {
93
- headers: {
94
- 'Content-Type': 'application/json',
95
- Authorization: `Bearer ${bearerToken}`,
96
- },
97
- });
98
- // Acceptable error - since indicates feature does not exist.
99
- if (userStorageResponse.status === 404) {
100
- return null;
101
- }
102
- if (userStorageResponse.status !== 200) {
103
- throw new Error(`Unable to get User Storage - HTTP ${userStorageResponse.status}`);
104
- }
105
- const userStorage = await userStorageResponse.json();
106
- if (!Array.isArray(userStorage)) {
107
- return null;
108
- }
109
- const decryptedData = [];
110
- const reEncryptedEntries = [];
111
- for (const entry of userStorage) {
112
- /* istanbul ignore if - unreachable if statement, but kept as edge case */
113
- if (!entry.Data) {
114
- continue;
115
- }
116
- try {
117
- const data = await encryption_1.default.decryptString(entry.Data, opts.storageKey, nativeScryptCrypto);
118
- decryptedData.push(data);
119
- // Re-encrypt the entry if the salt is different from the shared one
120
- const salt = encryption_1.default.getSalt(entry.Data);
121
- if (salt.toString() !== constants_1.SHARED_SALT.toString()) {
122
- reEncryptedEntries.push([
123
- entry.HashedKey,
124
- await encryption_1.default.encryptString(data, opts.storageKey, nativeScryptCrypto),
125
- ]);
126
- }
127
- }
128
- catch {
129
- // do nothing
130
- }
131
- }
132
- // Re-upload the re-encrypted entries
133
- if (reEncryptedEntries.length) {
134
- await batchUpsertUserStorageWithAlreadyHashedAndEncryptedEntries(reEncryptedEntries, opts);
135
- }
136
- return decryptedData;
137
- }
138
- catch (e) {
139
- loglevel_1.default.error('Failed to get user storage', e);
140
- return null;
141
- }
142
- }
143
- exports.getUserStorageAllFeatureEntries = getUserStorageAllFeatureEntries;
144
- /**
145
- * User Storage Service - Set Storage Entry.
146
- *
147
- * @param data - data to store
148
- * @param opts - storage options
149
- */
150
- async function upsertUserStorage(data, opts) {
151
- const { bearerToken, path, storageKey, nativeScryptCrypto } = opts;
152
- const encryptedData = await encryption_1.default.encryptString(data, opts.storageKey, nativeScryptCrypto);
153
- const encryptedPath = (0, storage_schema_1.createEntryPath)(path, storageKey);
154
- const url = new URL(`${exports.USER_STORAGE_ENDPOINT}/${encryptedPath}`);
155
- const res = await fetch(url.toString(), {
156
- method: 'PUT',
157
- headers: {
158
- 'Content-Type': 'application/json',
159
- Authorization: `Bearer ${bearerToken}`,
160
- },
161
- body: JSON.stringify({ data: encryptedData }),
162
- });
163
- if (!res.ok) {
164
- throw new Error(`user-storage - unable to upsert data - HTTP ${res.status}`);
165
- }
166
- }
167
- exports.upsertUserStorage = upsertUserStorage;
168
- /**
169
- * User Storage Service - Set multiple storage entries for one specific feature.
170
- * You cannot use this method to set multiple features at once.
171
- *
172
- * @param data - data to store, in the form of an array of [entryKey, entryValue] pairs
173
- * @param opts - storage options
174
- */
175
- async function batchUpsertUserStorage(data, opts) {
176
- if (!data.length) {
177
- return;
178
- }
179
- const { bearerToken, path, storageKey, nativeScryptCrypto } = opts;
180
- const encryptedData = [];
181
- for (const d of data) {
182
- encryptedData.push([
183
- (0, encryption_1.createSHA256Hash)(d[0] + storageKey),
184
- await encryption_1.default.encryptString(d[1], opts.storageKey, nativeScryptCrypto),
185
- ]);
186
- }
187
- const url = new URL(`${exports.USER_STORAGE_ENDPOINT}/${path}`);
188
- const formattedData = Object.fromEntries(encryptedData);
189
- const res = await fetch(url.toString(), {
190
- method: 'PUT',
191
- headers: {
192
- 'Content-Type': 'application/json',
193
- Authorization: `Bearer ${bearerToken}`,
194
- },
195
- body: JSON.stringify({ data: formattedData }),
196
- });
197
- if (!res.ok) {
198
- throw new Error(`user-storage - unable to batch upsert data - HTTP ${res.status}`);
199
- }
200
- }
201
- exports.batchUpsertUserStorage = batchUpsertUserStorage;
202
- /**
203
- * User Storage Service - Set multiple storage entries for one specific feature.
204
- * You cannot use this method to set multiple features at once.
205
- *
206
- * @param encryptedData - data to store, in the form of an array of [hashedKey, encryptedData] pairs
207
- * @param opts - storage options
208
- */
209
- async function batchUpsertUserStorageWithAlreadyHashedAndEncryptedEntries(encryptedData, opts) {
210
- if (!encryptedData.length) {
211
- return;
212
- }
213
- const { bearerToken, path } = opts;
214
- const url = new URL(`${exports.USER_STORAGE_ENDPOINT}/${path}`);
215
- const formattedData = Object.fromEntries(encryptedData);
216
- const res = await fetch(url.toString(), {
217
- method: 'PUT',
218
- headers: {
219
- 'Content-Type': 'application/json',
220
- Authorization: `Bearer ${bearerToken}`,
221
- },
222
- body: JSON.stringify({ data: formattedData }),
223
- });
224
- if (!res.ok) {
225
- throw new Error(`user-storage - unable to batch upsert data - HTTP ${res.status}`);
226
- }
227
- }
228
- exports.batchUpsertUserStorageWithAlreadyHashedAndEncryptedEntries = batchUpsertUserStorageWithAlreadyHashedAndEncryptedEntries;
229
- /**
230
- * User Storage Service - Delete Storage Entry.
231
- *
232
- * @param opts - User Storage Options
233
- */
234
- async function deleteUserStorage(opts) {
235
- const { bearerToken, path, storageKey } = opts;
236
- const encryptedPath = (0, storage_schema_1.createEntryPath)(path, storageKey);
237
- const url = new URL(`${exports.USER_STORAGE_ENDPOINT}/${encryptedPath}`);
238
- const userStorageResponse = await fetch(url.toString(), {
239
- method: 'DELETE',
240
- headers: {
241
- 'Content-Type': 'application/json',
242
- Authorization: `Bearer ${bearerToken}`,
243
- },
244
- });
245
- if (userStorageResponse.status === 404) {
246
- throw new Error(`user-storage - feature/entry not found - HTTP ${userStorageResponse.status}`);
247
- }
248
- if (!userStorageResponse.ok) {
249
- throw new Error(`user-storage - unable to delete data - HTTP ${userStorageResponse.status}`);
250
- }
251
- }
252
- exports.deleteUserStorage = deleteUserStorage;
253
- /**
254
- * User Storage Service - Delete multiple storage entries for one specific feature.
255
- * You cannot use this method to delete multiple features at once.
256
- *
257
- * @param data - data to delete, in the form of an array entryKey[]
258
- * @param opts - storage options
259
- */
260
- async function batchDeleteUserStorage(data, opts) {
261
- if (!data.length) {
262
- return;
263
- }
264
- const { bearerToken, path, storageKey } = opts;
265
- const encryptedData = [];
266
- for (const d of data) {
267
- encryptedData.push((0, encryption_1.createSHA256Hash)(d + storageKey));
268
- }
269
- const url = new URL(`${exports.USER_STORAGE_ENDPOINT}/${path}`);
270
- const res = await fetch(url.toString(), {
271
- method: 'PUT',
272
- headers: {
273
- 'Content-Type': 'application/json',
274
- Authorization: `Bearer ${bearerToken}`,
275
- },
276
- body: JSON.stringify({ batch_delete: encryptedData }),
277
- });
278
- if (!res.ok) {
279
- throw new Error(`user-storage - unable to batch delete data - HTTP ${res.status}`);
280
- }
281
- }
282
- exports.batchDeleteUserStorage = batchDeleteUserStorage;
283
- /**
284
- * User Storage Service - Delete all storage entries for a specific feature.
285
- *
286
- * @param opts - User Storage Options
287
- */
288
- async function deleteUserStorageAllFeatureEntries(opts) {
289
- const { bearerToken, path } = opts;
290
- const url = new URL(`${exports.USER_STORAGE_ENDPOINT}/${path}`);
291
- const userStorageResponse = await fetch(url.toString(), {
292
- method: 'DELETE',
293
- headers: {
294
- 'Content-Type': 'application/json',
295
- Authorization: `Bearer ${bearerToken}`,
296
- },
297
- });
298
- if (userStorageResponse.status === 404) {
299
- throw new Error(`user-storage - feature not found - HTTP ${userStorageResponse.status}`);
300
- }
301
- if (!userStorageResponse.ok) {
302
- throw new Error(`user-storage - unable to delete data - HTTP ${userStorageResponse.status}`);
303
- }
304
- }
305
- exports.deleteUserStorageAllFeatureEntries = deleteUserStorageAllFeatureEntries;
306
- //# sourceMappingURL=services.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"services.cjs","sourceRoot":"","sources":["../../../src/controllers/user-storage/services.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wDAA2B;AAE3B,gFAAuE;AACvE,qEAAgE;AAChE,8CAAmD;AAKnD,oEAA8D;AAG9D,MAAM,QAAQ,GAAG,IAAA,gBAAU,EAAC,SAAG,CAAC,GAAG,CAAC,CAAC;AAExB,QAAA,gBAAgB,GAAW,QAAQ,CAAC,iBAAiB,CAAC;AACtD,QAAA,qBAAqB,GAAG,GAAG,wBAAgB,qBAAqB,CAAC;AA+B9E;;;;;GAKG;AACI,KAAK,UAAU,cAAc,CAClC,IAAwB;IAExB,IAAI;QACF,MAAM,EAAE,WAAW,EAAE,IAAI,EAAE,UAAU,EAAE,kBAAkB,EAAE,GAAG,IAAI,CAAC;QAEnE,MAAM,aAAa,GAAG,IAAA,gCAAe,EAAC,IAAI,EAAE,UAAU,CAAC,CAAC;QACxD,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,GAAG,6BAAqB,IAAI,aAAa,EAAE,CAAC,CAAC;QAEjE,MAAM,mBAAmB,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE;YACtD,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;gBAClC,aAAa,EAAE,UAAU,WAAW,EAAE;aACvC;SACF,CAAC,CAAC;QAEH,2DAA2D;QAC3D,IAAI,mBAAmB,CAAC,MAAM,KAAK,GAAG,EAAE;YACtC,OAAO,IAAI,CAAC;SACb;QAED,IAAI,mBAAmB,CAAC,MAAM,KAAK,GAAG,EAAE;YACtC,MAAM,IAAI,KAAK,CACb,qCAAqC,mBAAmB,CAAC,MAAM,EAAE,CAClE,CAAC;SACH;QAED,MAAM,WAAW,GACf,MAAM,mBAAmB,CAAC,IAAI,EAAE,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AI,CAAC,mBAAmB,CAAC,EAAE,EAAE;QAC3B,MAAM,IAAI,KAAK,CACb,+CAA+C,mBAAmB,CAAC,MAAM,EAAE,CAC5E,CAAC;KACH;AACH,CAAC;AAzBD,gFAyBC","sourcesContent":["import log from 'loglevel';\n\nimport encryption, { createSHA256Hash } from '../../shared/encryption';\nimport { SHARED_SALT } from '../../shared/encryption/constants';\nimport { Env, getEnvUrls } from '../../shared/env';\nimport type {\n UserStoragePathWithFeatureAndKey,\n UserStoragePathWithFeatureOnly,\n} from '../../shared/storage-schema';\nimport { createEntryPath } from '../../shared/storage-schema';\nimport type { NativeScrypt } from '../../shared/types/encryption';\n\nconst ENV_URLS = getEnvUrls(Env.PRD);\n\nexport const USER_STORAGE_API: string = ENV_URLS.userStorageApiUrl;\nexport const USER_STORAGE_ENDPOINT = `${USER_STORAGE_API}/api/v1/userstorage`;\n\n/**\n * This is the Server Response shape for a feature entry.\n */\nexport type GetUserStorageResponse = {\n HashedKey: string;\n Data: string;\n};\n\nexport type GetUserStorageAllFeatureEntriesResponse = {\n HashedKey: string;\n Data: string;\n}[];\n\nexport type UserStorageBaseOptions = {\n bearerToken: string;\n storageKey: string;\n nativeScryptCrypto?: NativeScrypt;\n};\n\nexport type UserStorageOptions = UserStorageBaseOptions & {\n path: UserStoragePathWithFeatureAndKey;\n};\n\nexport type UserStorageAllFeatureEntriesOptions = UserStorageBaseOptions & {\n path: UserStoragePathWithFeatureOnly;\n};\n\nexport type UserStorageBatchUpsertOptions = UserStorageAllFeatureEntriesOptions;\n\n/**\n * User Storage Service - Get Storage Entry.\n *\n * @param opts - User Storage Options\n * @returns The storage entry, or null if fails to find entry\n */\nexport async function getUserStorage(\n opts: UserStorageOptions,\n): Promise<string | null> {\n try {\n const { bearerToken, path, storageKey, nativeScryptCrypto } = opts;\n\n const encryptedPath = createEntryPath(path, storageKey);\n const url = new URL(`${USER_STORAGE_ENDPOINT}/${encryptedPath}`);\n\n const userStorageResponse = await fetch(url.toString(), {\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${bearerToken}`,\n },\n });\n\n // Acceptable error - since indicates entry does not exist.\n if (userStorageResponse.status === 404) {\n return null;\n }\n\n if (userStorageResponse.status !== 200) {\n throw new Error(\n `Unable to get User Storage - HTTP ${userStorageResponse.status}`,\n );\n }\n\n const userStorage: GetUserStorageResponse | null =\n await userStorageResponse.json();\n const encryptedData = userStorage?.Data ?? null;\n\n /* istanbul ignore if - this is an edge case where our endpoint returns invalid JSON payload */\n if (!encryptedData) {\n return null;\n }\n\n const decryptedData = await encryption.decryptString(\n encryptedData,\n opts.storageKey,\n nativeScryptCrypto,\n );\n\n // Re-encrypt and re-upload the entry if the salt is random\n const salt = encryption.getSalt(encryptedData);\n if (salt.toString() !== SHARED_SALT.toString()) {\n await upsertUserStorage(decryptedData, opts);\n }\n\n return decryptedData;\n } catch (e) {\n log.error('Failed to get user storage', e);\n return null;\n }\n}\n\n/**\n * User Storage Service - Get all storage entries for a specific feature.\n *\n * @param opts - User Storage Options\n * @returns The storage entry, or null if fails to find entry\n */\nexport async function getUserStorageAllFeatureEntries(\n opts: UserStorageAllFeatureEntriesOptions,\n): Promise<string[] | null> {\n try {\n const { bearerToken, path, nativeScryptCrypto } = opts;\n const url = new URL(`${USER_STORAGE_ENDPOINT}/${path}`);\n\n const userStorageResponse = await fetch(url.toString(), {\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${bearerToken}`,\n },\n });\n\n // Acceptable error - since indicates feature does not exist.\n if (userStorageResponse.status === 404) {\n return null;\n }\n\n if (userStorageResponse.status !== 200) {\n throw new Error(\n `Unable to get User Storage - HTTP ${userStorageResponse.status}`,\n );\n }\n\n const userStorage: GetUserStorageAllFeatureEntriesResponse | null =\n await userStorageResponse.json();\n\n if (!Array.isArray(userStorage)) {\n return null;\n }\n\n const decryptedData: string[] = [];\n const reEncryptedEntries: [string, string][] = [];\n\n for (const entry of userStorage) {\n /* istanbul ignore if - unreachable if statement, but kept as edge case */\n if (!entry.Data) {\n continue;\n }\n\n try {\n const data = await encryption.decryptString(\n entry.Data,\n opts.storageKey,\n nativeScryptCrypto,\n );\n decryptedData.push(data);\n\n // Re-encrypt the entry if the salt is different from the shared one\n const salt = encryption.getSalt(entry.Data);\n if (salt.toString() !== SHARED_SALT.toString()) {\n reEncryptedEntries.push([\n entry.HashedKey,\n await encryption.encryptString(\n data,\n opts.storageKey,\n nativeScryptCrypto,\n ),\n ]);\n }\n } catch {\n // do nothing\n }\n }\n\n // Re-upload the re-encrypted entries\n if (reEncryptedEntries.length) {\n await batchUpsertUserStorageWithAlreadyHashedAndEncryptedEntries(\n reEncryptedEntries,\n opts,\n );\n }\n\n return decryptedData;\n } catch (e) {\n log.error('Failed to get user storage', e);\n return null;\n }\n}\n\n/**\n * User Storage Service - Set Storage Entry.\n *\n * @param data - data to store\n * @param opts - storage options\n */\nexport async function upsertUserStorage(\n data: string,\n opts: UserStorageOptions,\n): Promise<void> {\n const { bearerToken, path, storageKey, nativeScryptCrypto } = opts;\n\n const encryptedData = await encryption.encryptString(\n data,\n opts.storageKey,\n nativeScryptCrypto,\n );\n const encryptedPath = createEntryPath(path, storageKey);\n const url = new URL(`${USER_STORAGE_ENDPOINT}/${encryptedPath}`);\n\n const res = await fetch(url.toString(), {\n method: 'PUT',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${bearerToken}`,\n },\n body: JSON.stringify({ data: encryptedData }),\n });\n\n if (!res.ok) {\n throw new Error(\n `user-storage - unable to upsert data - HTTP ${res.status}`,\n );\n }\n}\n\n/**\n * User Storage Service - Set multiple storage entries for one specific feature.\n * You cannot use this method to set multiple features at once.\n *\n * @param data - data to store, in the form of an array of [entryKey, entryValue] pairs\n * @param opts - storage options\n */\nexport async function batchUpsertUserStorage(\n data: [string, string][],\n opts: UserStorageBatchUpsertOptions,\n): Promise<void> {\n if (!data.length) {\n return;\n }\n\n const { bearerToken, path, storageKey, nativeScryptCrypto } = opts;\n\n const encryptedData: string[][] = [];\n\n for (const d of data) {\n encryptedData.push([\n createSHA256Hash(d[0] + storageKey),\n await encryption.encryptString(d[1], opts.storageKey, nativeScryptCrypto),\n ]);\n }\n\n const url = new URL(`${USER_STORAGE_ENDPOINT}/${path}`);\n\n const formattedData = Object.fromEntries(encryptedData);\n\n const res = await fetch(url.toString(), {\n method: 'PUT',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${bearerToken}`,\n },\n body: JSON.stringify({ data: formattedData }),\n });\n\n if (!res.ok) {\n throw new Error(\n `user-storage - unable to batch upsert data - HTTP ${res.status}`,\n );\n }\n}\n\n/**\n * User Storage Service - Set multiple storage entries for one specific feature.\n * You cannot use this method to set multiple features at once.\n *\n * @param encryptedData - data to store, in the form of an array of [hashedKey, encryptedData] pairs\n * @param opts - storage options\n */\nexport async function batchUpsertUserStorageWithAlreadyHashedAndEncryptedEntries(\n encryptedData: [string, string][],\n opts: UserStorageBatchUpsertOptions,\n): Promise<void> {\n if (!encryptedData.length) {\n return;\n }\n\n const { bearerToken, path } = opts;\n\n const url = new URL(`${USER_STORAGE_ENDPOINT}/${path}`);\n\n const formattedData = Object.fromEntries(encryptedData);\n\n const res = await fetch(url.toString(), {\n method: 'PUT',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${bearerToken}`,\n },\n body: JSON.stringify({ data: formattedData }),\n });\n\n if (!res.ok) {\n throw new Error(\n `user-storage - unable to batch upsert data - HTTP ${res.status}`,\n );\n }\n}\n\n/**\n * User Storage Service - Delete Storage Entry.\n *\n * @param opts - User Storage Options\n */\nexport async function deleteUserStorage(\n opts: UserStorageOptions,\n): Promise<void> {\n const { bearerToken, path, storageKey } = opts;\n const encryptedPath = createEntryPath(path, storageKey);\n const url = new URL(`${USER_STORAGE_ENDPOINT}/${encryptedPath}`);\n\n const userStorageResponse = await fetch(url.toString(), {\n method: 'DELETE',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${bearerToken}`,\n },\n });\n\n if (userStorageResponse.status === 404) {\n throw new Error(\n `user-storage - feature/entry not found - HTTP ${userStorageResponse.status}`,\n );\n }\n\n if (!userStorageResponse.ok) {\n throw new Error(\n `user-storage - unable to delete data - HTTP ${userStorageResponse.status}`,\n );\n }\n}\n\n/**\n * User Storage Service - Delete multiple storage entries for one specific feature.\n * You cannot use this method to delete multiple features at once.\n *\n * @param data - data to delete, in the form of an array entryKey[]\n * @param opts - storage options\n */\nexport async function batchDeleteUserStorage(\n data: string[],\n opts: UserStorageBatchUpsertOptions,\n): Promise<void> {\n if (!data.length) {\n return;\n }\n\n const { bearerToken, path, storageKey } = opts;\n\n const encryptedData: string[] = [];\n\n for (const d of data) {\n encryptedData.push(createSHA256Hash(d + storageKey));\n }\n\n const url = new URL(`${USER_STORAGE_ENDPOINT}/${path}`);\n\n const res = await fetch(url.toString(), {\n method: 'PUT',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${bearerToken}`,\n },\n\n body: JSON.stringify({ batch_delete: encryptedData }),\n });\n\n if (!res.ok) {\n throw new Error(\n `user-storage - unable to batch delete data - HTTP ${res.status}`,\n );\n }\n}\n\n/**\n * User Storage Service - Delete all storage entries for a specific feature.\n *\n * @param opts - User Storage Options\n */\nexport async function deleteUserStorageAllFeatureEntries(\n opts: UserStorageAllFeatureEntriesOptions,\n): Promise<void> {\n const { bearerToken, path } = opts;\n const url = new URL(`${USER_STORAGE_ENDPOINT}/${path}`);\n\n const userStorageResponse = await fetch(url.toString(), {\n method: 'DELETE',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${bearerToken}`,\n },\n });\n\n if (userStorageResponse.status === 404) {\n throw new Error(\n `user-storage - feature not found - HTTP ${userStorageResponse.status}`,\n );\n }\n\n if (!userStorageResponse.ok) {\n throw new Error(\n `user-storage - unable to delete data - HTTP ${userStorageResponse.status}`,\n );\n }\n}\n"]}
@@ -1,85 +0,0 @@
1
- import type { UserStoragePathWithFeatureAndKey, UserStoragePathWithFeatureOnly } from "../../shared/storage-schema.cjs";
2
- import type { NativeScrypt } from "../../shared/types/encryption.cjs";
3
- export declare const USER_STORAGE_API: string;
4
- export declare const USER_STORAGE_ENDPOINT: string;
5
- /**
6
- * This is the Server Response shape for a feature entry.
7
- */
8
- export type GetUserStorageResponse = {
9
- HashedKey: string;
10
- Data: string;
11
- };
12
- export type GetUserStorageAllFeatureEntriesResponse = {
13
- HashedKey: string;
14
- Data: string;
15
- }[];
16
- export type UserStorageBaseOptions = {
17
- bearerToken: string;
18
- storageKey: string;
19
- nativeScryptCrypto?: NativeScrypt;
20
- };
21
- export type UserStorageOptions = UserStorageBaseOptions & {
22
- path: UserStoragePathWithFeatureAndKey;
23
- };
24
- export type UserStorageAllFeatureEntriesOptions = UserStorageBaseOptions & {
25
- path: UserStoragePathWithFeatureOnly;
26
- };
27
- export type UserStorageBatchUpsertOptions = UserStorageAllFeatureEntriesOptions;
28
- /**
29
- * User Storage Service - Get Storage Entry.
30
- *
31
- * @param opts - User Storage Options
32
- * @returns The storage entry, or null if fails to find entry
33
- */
34
- export declare function getUserStorage(opts: UserStorageOptions): Promise<string | null>;
35
- /**
36
- * User Storage Service - Get all storage entries for a specific feature.
37
- *
38
- * @param opts - User Storage Options
39
- * @returns The storage entry, or null if fails to find entry
40
- */
41
- export declare function getUserStorageAllFeatureEntries(opts: UserStorageAllFeatureEntriesOptions): Promise<string[] | null>;
42
- /**
43
- * User Storage Service - Set Storage Entry.
44
- *
45
- * @param data - data to store
46
- * @param opts - storage options
47
- */
48
- export declare function upsertUserStorage(data: string, opts: UserStorageOptions): Promise<void>;
49
- /**
50
- * User Storage Service - Set multiple storage entries for one specific feature.
51
- * You cannot use this method to set multiple features at once.
52
- *
53
- * @param data - data to store, in the form of an array of [entryKey, entryValue] pairs
54
- * @param opts - storage options
55
- */
56
- export declare function batchUpsertUserStorage(data: [string, string][], opts: UserStorageBatchUpsertOptions): Promise<void>;
57
- /**
58
- * User Storage Service - Set multiple storage entries for one specific feature.
59
- * You cannot use this method to set multiple features at once.
60
- *
61
- * @param encryptedData - data to store, in the form of an array of [hashedKey, encryptedData] pairs
62
- * @param opts - storage options
63
- */
64
- export declare function batchUpsertUserStorageWithAlreadyHashedAndEncryptedEntries(encryptedData: [string, string][], opts: UserStorageBatchUpsertOptions): Promise<void>;
65
- /**
66
- * User Storage Service - Delete Storage Entry.
67
- *
68
- * @param opts - User Storage Options
69
- */
70
- export declare function deleteUserStorage(opts: UserStorageOptions): Promise<void>;
71
- /**
72
- * User Storage Service - Delete multiple storage entries for one specific feature.
73
- * You cannot use this method to delete multiple features at once.
74
- *
75
- * @param data - data to delete, in the form of an array entryKey[]
76
- * @param opts - storage options
77
- */
78
- export declare function batchDeleteUserStorage(data: string[], opts: UserStorageBatchUpsertOptions): Promise<void>;
79
- /**
80
- * User Storage Service - Delete all storage entries for a specific feature.
81
- *
82
- * @param opts - User Storage Options
83
- */
84
- export declare function deleteUserStorageAllFeatureEntries(opts: UserStorageAllFeatureEntriesOptions): Promise<void>;
85
- //# sourceMappingURL=services.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"services.d.cts","sourceRoot":"","sources":["../../../src/controllers/user-storage/services.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,gCAAgC,EAChC,8BAA8B,EAC/B,wCAAoC;AAErC,OAAO,KAAK,EAAE,YAAY,EAAE,0CAAsC;AAIlE,eAAO,MAAM,gBAAgB,EAAE,MAAmC,CAAC;AACnE,eAAO,MAAM,qBAAqB,QAA2C,CAAC;AAE9E;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACnC,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,uCAAuC,GAAG;IACpD,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;CACd,EAAE,CAAC;AAEJ,MAAM,MAAM,sBAAsB,GAAG;IACnC,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAA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CAAkC,CACtD,IAAI,EAAE,mCAAmC,GACxC,OAAO,CAAC,IAAI,CAAC,CAuBf"}
@@ -1,85 +0,0 @@
1
- import type { UserStoragePathWithFeatureAndKey, UserStoragePathWithFeatureOnly } from "../../shared/storage-schema.mjs";
2
- import type { NativeScrypt } from "../../shared/types/encryption.mjs";
3
- export declare const USER_STORAGE_API: string;
4
- export declare const USER_STORAGE_ENDPOINT: string;
5
- /**
6
- * This is the Server Response shape for a feature entry.
7
- */
8
- export type GetUserStorageResponse = {
9
- HashedKey: string;
10
- Data: string;
11
- };
12
- export type GetUserStorageAllFeatureEntriesResponse = {
13
- HashedKey: string;
14
- Data: string;
15
- }[];
16
- export type UserStorageBaseOptions = {
17
- bearerToken: string;
18
- storageKey: string;
19
- nativeScryptCrypto?: NativeScrypt;
20
- };
21
- export type UserStorageOptions = UserStorageBaseOptions & {
22
- path: UserStoragePathWithFeatureAndKey;
23
- };
24
- export type UserStorageAllFeatureEntriesOptions = UserStorageBaseOptions & {
25
- path: UserStoragePathWithFeatureOnly;
26
- };
27
- export type UserStorageBatchUpsertOptions = UserStorageAllFeatureEntriesOptions;
28
- /**
29
- * User Storage Service - Get Storage Entry.
30
- *
31
- * @param opts - User Storage Options
32
- * @returns The storage entry, or null if fails to find entry
33
- */
34
- export declare function getUserStorage(opts: UserStorageOptions): Promise<string | null>;
35
- /**
36
- * User Storage Service - Get all storage entries for a specific feature.
37
- *
38
- * @param opts - User Storage Options
39
- * @returns The storage entry, or null if fails to find entry
40
- */
41
- export declare function getUserStorageAllFeatureEntries(opts: UserStorageAllFeatureEntriesOptions): Promise<string[] | null>;
42
- /**
43
- * User Storage Service - Set Storage Entry.
44
- *
45
- * @param data - data to store
46
- * @param opts - storage options
47
- */
48
- export declare function upsertUserStorage(data: string, opts: UserStorageOptions): Promise<void>;
49
- /**
50
- * User Storage Service - Set multiple storage entries for one specific feature.
51
- * You cannot use this method to set multiple features at once.
52
- *
53
- * @param data - data to store, in the form of an array of [entryKey, entryValue] pairs
54
- * @param opts - storage options
55
- */
56
- export declare function batchUpsertUserStorage(data: [string, string][], opts: UserStorageBatchUpsertOptions): Promise<void>;
57
- /**
58
- * User Storage Service - Set multiple storage entries for one specific feature.
59
- * You cannot use this method to set multiple features at once.
60
- *
61
- * @param encryptedData - data to store, in the form of an array of [hashedKey, encryptedData] pairs
62
- * @param opts - storage options
63
- */
64
- export declare function batchUpsertUserStorageWithAlreadyHashedAndEncryptedEntries(encryptedData: [string, string][], opts: UserStorageBatchUpsertOptions): Promise<void>;
65
- /**
66
- * User Storage Service - Delete Storage Entry.
67
- *
68
- * @param opts - User Storage Options
69
- */
70
- export declare function deleteUserStorage(opts: UserStorageOptions): Promise<void>;
71
- /**
72
- * User Storage Service - Delete multiple storage entries for one specific feature.
73
- * You cannot use this method to delete multiple features at once.
74
- *
75
- * @param data - data to delete, in the form of an array entryKey[]
76
- * @param opts - storage options
77
- */
78
- export declare function batchDeleteUserStorage(data: string[], opts: UserStorageBatchUpsertOptions): Promise<void>;
79
- /**
80
- * User Storage Service - Delete all storage entries for a specific feature.
81
- *
82
- * @param opts - User Storage Options
83
- */
84
- export declare function deleteUserStorageAllFeatureEntries(opts: UserStorageAllFeatureEntriesOptions): Promise<void>;
85
- //# sourceMappingURL=services.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"services.d.mts","sourceRoot":"","sources":["../../../src/controllers/user-storage/services.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,gCAAgC,EAChC,8BAA8B,EAC/B,wCAAoC;AAErC,OAAO,KAAK,EAAE,YAAY,EAAE,0CAAsC;AAIlE,eAAO,MAAM,gBAAgB,EAAE,MAAmC,CAAC;AACnE,eAAO,MAAM,qBAAqB,QAA2C,CAAC;AAE9E;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACnC,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,uCAAuC,GAAG;IACpD,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