@croct/sdk 0.17.7 → 0.17.8

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 (409) hide show
  1. package/activeRecord.cjs.map +1 -0
  2. package/activeRecord.d.ts +8 -4
  3. package/activeRecord.js +115 -106
  4. package/activeRecord.js.map +1 -1
  5. package/apiKey.cjs.map +1 -0
  6. package/apiKey.d.ts +4 -2
  7. package/apiKey.js +152 -141
  8. package/apiKey.js.map +1 -1
  9. package/base64Url.cjs.map +1 -0
  10. package/base64Url.d.ts +4 -2
  11. package/base64Url.js +8 -15
  12. package/base64Url.js.map +1 -1
  13. package/cache/cache.cjs.map +1 -0
  14. package/cache/cache.d.ts +6 -4
  15. package/cache/cache.js +9 -10
  16. package/cache/cache.js.map +1 -1
  17. package/cache/cookieCache.cjs.map +1 -0
  18. package/cache/cookieCache.d.ts +6 -3
  19. package/cache/cookieCache.js +52 -54
  20. package/cache/cookieCache.js.map +1 -1
  21. package/cache/fallbackCache.cjs.map +1 -0
  22. package/cache/fallbackCache.d.ts +5 -2
  23. package/cache/fallbackCache.js +20 -21
  24. package/cache/fallbackCache.js.map +1 -1
  25. package/cache/inMemoryCache.cjs.map +1 -0
  26. package/cache/inMemoryCache.d.ts +5 -2
  27. package/cache/inMemoryCache.js +15 -17
  28. package/cache/inMemoryCache.js.map +1 -1
  29. package/cache/index.cjs.map +1 -0
  30. package/cache/index.d.ts +4 -4
  31. package/cache/index.js +9 -11
  32. package/cache/index.js.map +1 -1
  33. package/cache/localStorageCache.cjs.map +1 -0
  34. package/cache/localStorageCache.d.ts +5 -2
  35. package/cache/localStorageCache.js +55 -63
  36. package/cache/localStorageCache.js.map +1 -1
  37. package/channel/channel.cjs.map +1 -0
  38. package/channel/channel.d.ts +8 -6
  39. package/channel/channel.js +21 -22
  40. package/channel/channel.js.map +1 -1
  41. package/channel/encodedChannel.cjs.map +1 -0
  42. package/channel/encodedChannel.d.ts +6 -3
  43. package/channel/encodedChannel.js +13 -14
  44. package/channel/encodedChannel.js.map +1 -1
  45. package/channel/guaranteedChannel.cjs.map +1 -0
  46. package/channel/guaranteedChannel.d.ts +9 -7
  47. package/channel/guaranteedChannel.js +74 -73
  48. package/channel/guaranteedChannel.js.map +1 -1
  49. package/channel/httpBeaconChannel.cjs.map +1 -0
  50. package/channel/httpBeaconChannel.d.ts +9 -6
  51. package/channel/httpBeaconChannel.js +82 -83
  52. package/channel/httpBeaconChannel.js.map +1 -1
  53. package/channel/index.cjs.map +1 -0
  54. package/channel/index.d.ts +12 -7
  55. package/channel/index.js +15 -17
  56. package/channel/index.js.map +1 -1
  57. package/channel/queuedChannel.cjs.map +1 -0
  58. package/channel/queuedChannel.d.ts +7 -4
  59. package/channel/queuedChannel.js +87 -97
  60. package/channel/queuedChannel.js.map +1 -1
  61. package/channel/retryChannel.cjs.map +1 -0
  62. package/channel/retryChannel.d.ts +7 -5
  63. package/channel/retryChannel.js +58 -57
  64. package/channel/retryChannel.js.map +1 -1
  65. package/channel/sandboxChannel.cjs.map +1 -0
  66. package/channel/sandboxChannel.d.ts +5 -2
  67. package/channel/sandboxChannel.js +34 -35
  68. package/channel/sandboxChannel.js.map +1 -1
  69. package/cid/assigner.cjs.map +1 -0
  70. package/cid/assigner.d.ts +3 -1
  71. package/cid/assigner.js +0 -2
  72. package/cid/assigner.js.map +1 -1
  73. package/cid/cachedAssigner.cjs.map +1 -0
  74. package/cid/cachedAssigner.d.ts +7 -5
  75. package/cid/cachedAssigner.js +37 -43
  76. package/cid/cachedAssigner.js.map +1 -1
  77. package/cid/fixedAssigner.cjs.map +1 -0
  78. package/cid/fixedAssigner.d.ts +5 -2
  79. package/cid/fixedAssigner.js +9 -10
  80. package/cid/fixedAssigner.js.map +1 -1
  81. package/cid/index.cjs.map +1 -0
  82. package/cid/index.d.ts +6 -4
  83. package/cid/index.js +9 -11
  84. package/cid/index.js.map +1 -1
  85. package/cid/remoteAssigner.cjs.map +1 -0
  86. package/cid/remoteAssigner.d.ts +6 -3
  87. package/cid/remoteAssigner.js +36 -37
  88. package/cid/remoteAssigner.js.map +1 -1
  89. package/constants.cjs.map +1 -0
  90. package/constants.d.ts +6 -4
  91. package/constants.js +10 -7
  92. package/constants.js.map +1 -1
  93. package/container.cjs.map +1 -0
  94. package/container.d.ts +28 -15
  95. package/container.js +269 -252
  96. package/container.js.map +1 -1
  97. package/contentFetcher.cjs.map +1 -0
  98. package/contentFetcher.d.ts +17 -14
  99. package/contentFetcher.js +156 -163
  100. package/contentFetcher.js.map +1 -1
  101. package/context.cjs.map +1 -0
  102. package/context.d.ts +13 -9
  103. package/context.js +80 -81
  104. package/context.js.map +1 -1
  105. package/error.cjs.map +1 -0
  106. package/error.d.ts +4 -2
  107. package/error.js +21 -21
  108. package/error.js.map +1 -1
  109. package/evaluator.cjs.map +1 -0
  110. package/evaluator.d.ts +18 -16
  111. package/evaluator.js +179 -179
  112. package/evaluator.js.map +1 -1
  113. package/eventManager.cjs.map +1 -0
  114. package/eventManager.d.ts +8 -6
  115. package/eventManager.js +24 -26
  116. package/eventManager.js.map +1 -1
  117. package/eventSubjectProcessor.cjs.map +1 -0
  118. package/eventSubjectProcessor.d.ts +16 -3
  119. package/eventSubjectProcessor.js +53 -59
  120. package/eventSubjectProcessor.js.map +1 -1
  121. package/facade/contentFetcherFacade.cjs.map +1 -0
  122. package/facade/contentFetcherFacade.d.ts +16 -7
  123. package/facade/contentFetcherFacade.js +32 -35
  124. package/facade/contentFetcherFacade.js.map +1 -1
  125. package/facade/evaluatorFacade.cjs.map +1 -0
  126. package/facade/evaluatorFacade.d.ts +17 -10
  127. package/facade/evaluatorFacade.js +56 -60
  128. package/facade/evaluatorFacade.js.map +1 -1
  129. package/facade/index.cjs.map +1 -0
  130. package/facade/index.d.ts +29 -7
  131. package/facade/index.js +19 -19
  132. package/facade/index.js.map +1 -1
  133. package/facade/sdkFacade.cjs.map +1 -0
  134. package/facade/sdkFacade.d.ts +33 -15
  135. package/facade/sdkFacade.js +201 -214
  136. package/facade/sdkFacade.js.map +1 -1
  137. package/facade/sessionFacade.cjs.map +1 -0
  138. package/facade/sessionFacade.d.ts +18 -3
  139. package/facade/sessionFacade.js +10 -11
  140. package/facade/sessionFacade.js.map +1 -1
  141. package/facade/sessionPatch.cjs.map +1 -0
  142. package/facade/sessionPatch.d.ts +17 -4
  143. package/facade/sessionPatch.js +22 -24
  144. package/facade/sessionPatch.js.map +1 -1
  145. package/facade/trackerFacade.cjs.map +1 -0
  146. package/facade/trackerFacade.d.ts +17 -4
  147. package/facade/trackerFacade.js +67 -57
  148. package/facade/trackerFacade.js.map +1 -1
  149. package/facade/userFacade.cjs.map +1 -0
  150. package/facade/userFacade.d.ts +21 -4
  151. package/facade/userFacade.js +17 -18
  152. package/facade/userFacade.js.map +1 -1
  153. package/facade/userPatch.cjs.map +1 -0
  154. package/facade/userPatch.d.ts +17 -4
  155. package/facade/userPatch.js +22 -24
  156. package/facade/userPatch.js.map +1 -1
  157. package/help.cjs.map +1 -0
  158. package/help.d.ts +3 -1
  159. package/help.js +19 -23
  160. package/help.js.map +1 -1
  161. package/index.cjs.map +1 -0
  162. package/index.d.ts +25 -3
  163. package/index.js +7 -7
  164. package/index.js.map +1 -1
  165. package/logging/consoleLogger.cjs.map +1 -0
  166. package/logging/consoleLogger.d.ts +5 -2
  167. package/logging/consoleLogger.js +23 -24
  168. package/logging/consoleLogger.js.map +1 -1
  169. package/logging/filteredLogger.cjs.map +1 -0
  170. package/logging/filteredLogger.d.ts +8 -5
  171. package/logging/filteredLogger.js +36 -37
  172. package/logging/filteredLogger.js.map +1 -1
  173. package/logging/index.cjs.map +1 -0
  174. package/logging/index.d.ts +5 -5
  175. package/logging/index.js +11 -13
  176. package/logging/index.js.map +1 -1
  177. package/logging/logger.cjs.map +1 -0
  178. package/logging/logger.d.ts +4 -2
  179. package/logging/logger.js +0 -2
  180. package/logging/logger.js.map +1 -1
  181. package/logging/namespacedLogger.cjs.map +1 -0
  182. package/logging/namespacedLogger.d.ts +5 -2
  183. package/logging/namespacedLogger.js +22 -23
  184. package/logging/namespacedLogger.js.map +1 -1
  185. package/logging/nullLogger.cjs.map +1 -0
  186. package/logging/nullLogger.d.ts +5 -2
  187. package/logging/nullLogger.js +11 -16
  188. package/logging/nullLogger.js.map +1 -1
  189. package/namespacedStorage.cjs.map +1 -0
  190. package/namespacedStorage.d.ts +3 -1
  191. package/namespacedStorage.js +51 -52
  192. package/namespacedStorage.js.map +1 -1
  193. package/package.json +60 -6
  194. package/patch.cjs.map +1 -0
  195. package/patch.d.ts +6 -4
  196. package/patch.js +0 -2
  197. package/patch.js.map +1 -1
  198. package/queue/capacityRestrictedQueue.cjs.map +1 -0
  199. package/queue/capacityRestrictedQueue.d.ts +5 -2
  200. package/queue/capacityRestrictedQueue.js +31 -32
  201. package/queue/capacityRestrictedQueue.js.map +1 -1
  202. package/queue/inMemoryQueue.cjs.map +1 -0
  203. package/queue/inMemoryQueue.d.ts +5 -2
  204. package/queue/inMemoryQueue.js +32 -34
  205. package/queue/inMemoryQueue.js.map +1 -1
  206. package/queue/index.cjs.map +1 -0
  207. package/queue/index.d.ts +6 -5
  208. package/queue/index.js +11 -13
  209. package/queue/index.js.map +1 -1
  210. package/queue/monitoredQueue.cjs.map +1 -0
  211. package/queue/monitoredQueue.d.ts +8 -5
  212. package/queue/monitoredQueue.js +104 -110
  213. package/queue/monitoredQueue.js.map +1 -1
  214. package/queue/persistentQueue.cjs.map +1 -0
  215. package/queue/persistentQueue.d.ts +5 -2
  216. package/queue/persistentQueue.js +52 -54
  217. package/queue/persistentQueue.js.map +1 -1
  218. package/queue/queue.cjs.map +1 -0
  219. package/queue/queue.d.ts +3 -1
  220. package/queue/queue.js +0 -2
  221. package/queue/queue.js.map +1 -1
  222. package/retry/arbitraryPolicy.cjs.map +1 -0
  223. package/retry/arbitraryPolicy.d.ts +5 -2
  224. package/retry/arbitraryPolicy.js +14 -15
  225. package/retry/arbitraryPolicy.js.map +1 -1
  226. package/retry/backoffPolicy.cjs.map +1 -0
  227. package/retry/backoffPolicy.d.ts +5 -3
  228. package/retry/backoffPolicy.js +52 -50
  229. package/retry/backoffPolicy.js.map +1 -1
  230. package/retry/index.cjs.map +1 -0
  231. package/retry/index.d.ts +5 -5
  232. package/retry/index.js +11 -13
  233. package/retry/index.js.map +1 -1
  234. package/retry/maxAttemptsPolicy.cjs.map +1 -0
  235. package/retry/maxAttemptsPolicy.d.ts +5 -2
  236. package/retry/maxAttemptsPolicy.js +17 -18
  237. package/retry/maxAttemptsPolicy.js.map +1 -1
  238. package/retry/neverPolicy.cjs.map +1 -0
  239. package/retry/neverPolicy.d.ts +5 -2
  240. package/retry/neverPolicy.js +9 -10
  241. package/retry/neverPolicy.js.map +1 -1
  242. package/retry/policy.cjs.map +1 -0
  243. package/retry/policy.d.ts +3 -1
  244. package/retry/policy.js +0 -2
  245. package/retry/policy.js.map +1 -1
  246. package/schema/attributeSchema.cjs.map +1 -0
  247. package/schema/attributeSchema.d.ts +6 -2
  248. package/schema/attributeSchema.js +7 -7
  249. package/schema/attributeSchema.js.map +1 -1
  250. package/schema/contentFetcherSchemas.cjs.map +1 -0
  251. package/schema/contentFetcherSchemas.d.ts +6 -2
  252. package/schema/contentFetcherSchemas.js +24 -21
  253. package/schema/contentFetcherSchemas.js.map +1 -1
  254. package/schema/contentSchemas.cjs.map +1 -0
  255. package/schema/contentSchemas.d.ts +6 -2
  256. package/schema/contentSchemas.js +45 -45
  257. package/schema/contentSchemas.js.map +1 -1
  258. package/schema/contextSchemas.cjs.map +1 -0
  259. package/schema/contextSchemas.d.ts +6 -2
  260. package/schema/contextSchemas.js +6 -6
  261. package/schema/contextSchemas.js.map +1 -1
  262. package/schema/ecommerceSchemas.cjs.map +1 -0
  263. package/schema/ecommerceSchemas.d.ts +10 -6
  264. package/schema/ecommerceSchemas.js +176 -172
  265. package/schema/ecommerceSchemas.js.map +1 -1
  266. package/schema/evaluatorSchemas.cjs.map +1 -0
  267. package/schema/evaluatorSchemas.d.ts +6 -2
  268. package/schema/evaluatorSchemas.js +46 -30
  269. package/schema/evaluatorSchemas.js.map +1 -1
  270. package/schema/eventSchemas.cjs.map +1 -0
  271. package/schema/eventSchemas.d.ts +16 -12
  272. package/schema/eventSchemas.js +125 -102
  273. package/schema/eventSchemas.js.map +1 -1
  274. package/schema/index.cjs.map +1 -0
  275. package/schema/index.d.ts +14 -11
  276. package/schema/index.js +11 -14
  277. package/schema/index.js.map +1 -1
  278. package/schema/loggerSchema.cjs.map +1 -0
  279. package/schema/loggerSchema.d.ts +6 -2
  280. package/schema/loggerSchema.js +13 -13
  281. package/schema/loggerSchema.js.map +1 -1
  282. package/schema/operationSchemas.cjs.map +1 -0
  283. package/schema/operationSchemas.d.ts +14 -10
  284. package/schema/operationSchemas.js +85 -69
  285. package/schema/operationSchemas.js.map +1 -1
  286. package/schema/sdkFacadeSchemas.cjs.map +1 -0
  287. package/schema/sdkFacadeSchemas.d.ts +6 -2
  288. package/schema/sdkFacadeSchemas.js +65 -51
  289. package/schema/sdkFacadeSchemas.js.map +1 -1
  290. package/schema/sdkSchemas.cjs.map +1 -0
  291. package/schema/sdkSchemas.d.ts +8 -4
  292. package/schema/sdkSchemas.js +80 -78
  293. package/schema/sdkSchemas.js.map +1 -1
  294. package/schema/tokenSchema.cjs.map +1 -0
  295. package/schema/tokenSchema.d.ts +6 -2
  296. package/schema/tokenSchema.js +41 -38
  297. package/schema/tokenSchema.js.map +1 -1
  298. package/schema/userSchema.cjs.map +1 -0
  299. package/schema/userSchema.d.ts +6 -2
  300. package/schema/userSchema.js +183 -134
  301. package/schema/userSchema.js.map +1 -1
  302. package/sdk.cjs.map +1 -0
  303. package/sdk.d.ts +28 -14
  304. package/sdk.js +106 -108
  305. package/sdk.js.map +1 -1
  306. package/sdkEvents.cjs.map +1 -0
  307. package/sdkEvents.d.ts +10 -5
  308. package/sdkEvents.js +0 -2
  309. package/sdkEvents.js.map +1 -1
  310. package/sourceLocation.cjs.map +1 -0
  311. package/sourceLocation.d.ts +7 -5
  312. package/sourceLocation.js +56 -57
  313. package/sourceLocation.js.map +1 -1
  314. package/tab.cjs.map +1 -0
  315. package/tab.d.ts +9 -7
  316. package/tab.js +93 -90
  317. package/tab.js.map +1 -1
  318. package/token/cachedTokenStore.cjs.map +1 -0
  319. package/token/cachedTokenStore.d.ts +8 -3
  320. package/token/cachedTokenStore.js +22 -24
  321. package/token/cachedTokenStore.js.map +1 -1
  322. package/token/inMemoryTokenStore.cjs.map +1 -0
  323. package/token/inMemoryTokenStore.d.ts +7 -2
  324. package/token/inMemoryTokenStore.js +12 -13
  325. package/token/inMemoryTokenStore.js.map +1 -1
  326. package/token/index.cjs.map +1 -0
  327. package/token/index.d.ts +7 -4
  328. package/token/index.js +9 -11
  329. package/token/index.js.map +1 -1
  330. package/token/replicatedTokenStore.cjs.map +1 -0
  331. package/token/replicatedTokenStore.d.ts +7 -2
  332. package/token/replicatedTokenStore.js +14 -15
  333. package/token/replicatedTokenStore.js.map +1 -1
  334. package/token/token.cjs.map +1 -0
  335. package/token/token.d.ts +11 -8
  336. package/token/token.js +212 -195
  337. package/token/token.js.map +1 -1
  338. package/tracker.cjs.map +1 -0
  339. package/tracker.d.ts +20 -13
  340. package/tracker.js +307 -307
  341. package/tracker.js.map +1 -1
  342. package/trackingEvents.cjs.map +1 -0
  343. package/trackingEvents.d.ts +65 -62
  344. package/trackingEvents.js +57 -56
  345. package/trackingEvents.js.map +1 -1
  346. package/transformer.cjs.map +1 -0
  347. package/transformer.d.ts +4 -2
  348. package/transformer.js +5 -6
  349. package/transformer.js.map +1 -1
  350. package/utilityTypes.cjs.map +1 -0
  351. package/utilityTypes.d.ts +4 -2
  352. package/utilityTypes.js +0 -2
  353. package/utilityTypes.js.map +1 -1
  354. package/uuid.cjs.map +1 -0
  355. package/uuid.d.ts +3 -1
  356. package/uuid.js +27 -32
  357. package/uuid.js.map +1 -1
  358. package/validation/arrayType.cjs.map +1 -0
  359. package/validation/arrayType.d.ts +5 -3
  360. package/validation/arrayType.js +45 -41
  361. package/validation/arrayType.js.map +1 -1
  362. package/validation/booleanType.cjs.map +1 -0
  363. package/validation/booleanType.d.ts +5 -2
  364. package/validation/booleanType.js +19 -16
  365. package/validation/booleanType.js.map +1 -1
  366. package/validation/functionType.cjs.map +1 -0
  367. package/validation/functionType.d.ts +5 -2
  368. package/validation/functionType.js +19 -16
  369. package/validation/functionType.js.map +1 -1
  370. package/validation/index.cjs.map +1 -0
  371. package/validation/index.d.ts +12 -12
  372. package/validation/index.js +27 -29
  373. package/validation/index.js.map +1 -1
  374. package/validation/jsonType.cjs.map +1 -0
  375. package/validation/jsonType.d.ts +8 -6
  376. package/validation/jsonType.js +89 -82
  377. package/validation/jsonType.js.map +1 -1
  378. package/validation/mixedSchema.cjs.map +1 -0
  379. package/validation/mixedSchema.d.ts +5 -2
  380. package/validation/mixedSchema.js +5 -7
  381. package/validation/mixedSchema.js.map +1 -1
  382. package/validation/nullType.cjs.map +1 -0
  383. package/validation/nullType.d.ts +5 -2
  384. package/validation/nullType.js +19 -16
  385. package/validation/nullType.js.map +1 -1
  386. package/validation/numberType.cjs.map +1 -0
  387. package/validation/numberType.d.ts +5 -3
  388. package/validation/numberType.js +40 -32
  389. package/validation/numberType.js.map +1 -1
  390. package/validation/objectType.cjs.map +1 -0
  391. package/validation/objectType.d.ts +5 -3
  392. package/validation/objectType.js +84 -85
  393. package/validation/objectType.js.map +1 -1
  394. package/validation/schema.cjs.map +1 -0
  395. package/validation/schema.d.ts +5 -3
  396. package/validation/schema.js +8 -9
  397. package/validation/schema.js.map +1 -1
  398. package/validation/stringType.cjs.map +1 -0
  399. package/validation/stringType.d.ts +5 -3
  400. package/validation/stringType.js +74 -70
  401. package/validation/stringType.js.map +1 -1
  402. package/validation/unionType.cjs.map +1 -0
  403. package/validation/unionType.d.ts +5 -2
  404. package/validation/unionType.js +37 -35
  405. package/validation/unionType.js.map +1 -1
  406. package/validation/violation.cjs.map +1 -0
  407. package/validation/violation.d.ts +4 -2
  408. package/validation/violation.js +18 -18
  409. package/validation/violation.js.map +1 -1
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/activeRecord.ts"],"sourcesContent":["import {JsonStructure, JsonValue} from '@croct/json';\nimport {Operation, Patch} from './patch';\nimport {TrackingEvent} from './trackingEvents';\nimport {\n addOperation,\n clearOperation,\n combineOperation,\n decrementOperation,\n incrementOperation,\n mergeOperation,\n setOperation,\n unsetOperation,\n removeOperation,\n} from './schema';\n\nconst operationSchema = {\n add: addOperation,\n set: setOperation,\n merge: mergeOperation,\n combine: combineOperation,\n increment: incrementOperation,\n decrement: decrementOperation,\n clear: clearOperation,\n unset: unsetOperation,\n remove: removeOperation,\n};\n\nexport abstract class ActiveRecord<T extends TrackingEvent> {\n private readonly operations: Operation[] = [];\n\n public set(value: JsonValue): this;\n\n public set(property: string, value: JsonValue): this;\n\n public set(propertyOrValue: string | JsonValue, value?: JsonValue): this {\n if (typeof propertyOrValue === 'string') {\n return this.pushOperation({\n type: 'set',\n path: propertyOrValue,\n value: value as JsonValue,\n });\n }\n\n return this.pushOperation({\n type: 'set',\n path: '.',\n value: propertyOrValue,\n });\n }\n\n public add(property: string, value: JsonValue): this {\n return this.pushOperation({\n type: 'add',\n path: property,\n value: value,\n });\n }\n\n public combine(property: string, value: JsonValue): this {\n return this.pushOperation({\n type: 'combine',\n path: property,\n value: value,\n });\n }\n\n public merge(value: JsonStructure): this;\n\n public merge(property: string, value: JsonStructure): this;\n\n public merge(propertyOrValue: string | JsonStructure, value?: JsonStructure): this {\n if (typeof propertyOrValue === 'string') {\n return this.pushOperation({\n type: 'merge',\n path: propertyOrValue,\n value: value as JsonStructure,\n });\n }\n\n return this.pushOperation({\n type: 'merge',\n path: '.',\n value: propertyOrValue,\n });\n }\n\n public increment(property: string, amount = 1): this {\n return this.pushOperation({\n type: 'increment',\n path: property,\n value: amount,\n });\n }\n\n public decrement(property: string, amount = 1): this {\n return this.pushOperation({\n type: 'decrement',\n path: property,\n value: amount,\n });\n }\n\n public clear(property: string): this {\n return this.pushOperation({\n type: 'clear',\n path: property,\n });\n }\n\n public unset(property: string): this {\n return this.pushOperation({\n type: 'unset',\n path: property,\n });\n }\n\n public remove(property: string, value: JsonValue): this {\n return this.pushOperation({\n type: 'remove',\n path: property,\n value: value,\n });\n }\n\n private pushOperation(operation: Operation): this {\n const {type, ...data} = operation;\n\n operationSchema[type].validate(data);\n\n this.operations.push(operation);\n\n return this;\n }\n\n protected reset(): this {\n this.operations.splice(0);\n\n return this;\n }\n\n public abstract save(): Promise<T>;\n\n protected isDirty(): boolean {\n return this.operations.length > 0;\n }\n\n protected buildPatch(): Patch {\n return {operations: this.operations.slice()};\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,oBAUO;AAEP,MAAM,kBAAkB;AAAA,EACpB,KAAK;AAAA,EACL,KAAK;AAAA,EACL,OAAO;AAAA,EACP,SAAS;AAAA,EACT,WAAW;AAAA,EACX,WAAW;AAAA,EACX,OAAO;AAAA,EACP,OAAO;AAAA,EACP,QAAQ;AACZ;AAEO,MAAe,aAAsC;AAAA,EAArD;AACH,SAAiB,aAA0B,CAAC;AAAA;AAAA,EAMrC,IAAI,iBAAqC,OAAyB;AACrE,QAAI,OAAO,oBAAoB,UAAU;AACrC,aAAO,KAAK,cAAc;AAAA,QACtB,MAAM;AAAA,QACN,MAAM;AAAA,QACN;AAAA,MACJ,CAAC;AAAA,IACL;AAEA,WAAO,KAAK,cAAc;AAAA,MACtB,MAAM;AAAA,MACN,MAAM;AAAA,MACN,OAAO;AAAA,IACX,CAAC;AAAA,EACL;AAAA,EAEO,IAAI,UAAkB,OAAwB;AACjD,WAAO,KAAK,cAAc;AAAA,MACtB,MAAM;AAAA,MACN,MAAM;AAAA,MACN;AAAA,IACJ,CAAC;AAAA,EACL;AAAA,EAEO,QAAQ,UAAkB,OAAwB;AACrD,WAAO,KAAK,cAAc;AAAA,MACtB,MAAM;AAAA,MACN,MAAM;AAAA,MACN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AAAA,EAEU,aAAoB;AAC1B,WAAO,EAAC,YAAY,KAAK,WAAW,MAAM,EAAC;AAAA,EAC/C;AACJ;","names":[]}
package/activeRecord.d.ts CHANGED
@@ -1,7 +1,9 @@
1
- import { JsonStructure, JsonValue } from '@croct/json';
2
- import { Patch } from './patch';
3
- import { TrackingEvent } from './trackingEvents';
4
- export declare abstract class ActiveRecord<T extends TrackingEvent> {
1
+ import { JsonValue, JsonStructure } from '@croct/json';
2
+ import { Patch } from './patch.js';
3
+ import { TrackingEvent } from './trackingEvents.js';
4
+ import './utilityTypes.js';
5
+
6
+ declare abstract class ActiveRecord<T extends TrackingEvent> {
5
7
  private readonly operations;
6
8
  set(value: JsonValue): this;
7
9
  set(property: string, value: JsonValue): this;
@@ -20,3 +22,5 @@ export declare abstract class ActiveRecord<T extends TrackingEvent> {
20
22
  protected isDirty(): boolean;
21
23
  protected buildPatch(): Patch;
22
24
  }
25
+
26
+ export { ActiveRecord };
package/activeRecord.js CHANGED
@@ -1,113 +1,122 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ActiveRecord = void 0;
4
- const schema_1 = require("./schema");
1
+ import {
2
+ addOperation,
3
+ clearOperation,
4
+ combineOperation,
5
+ decrementOperation,
6
+ incrementOperation,
7
+ mergeOperation,
8
+ setOperation,
9
+ unsetOperation,
10
+ removeOperation
11
+ } from "./schema";
5
12
  const operationSchema = {
6
- add: schema_1.addOperation,
7
- set: schema_1.setOperation,
8
- merge: schema_1.mergeOperation,
9
- combine: schema_1.combineOperation,
10
- increment: schema_1.incrementOperation,
11
- decrement: schema_1.decrementOperation,
12
- clear: schema_1.clearOperation,
13
- unset: schema_1.unsetOperation,
14
- remove: schema_1.removeOperation,
13
+ add: addOperation,
14
+ set: setOperation,
15
+ merge: mergeOperation,
16
+ combine: combineOperation,
17
+ increment: incrementOperation,
18
+ decrement: decrementOperation,
19
+ clear: clearOperation,
20
+ unset: unsetOperation,
21
+ remove: removeOperation
15
22
  };
16
23
  class ActiveRecord {
17
- constructor() {
18
- this.operations = [];
24
+ constructor() {
25
+ this.operations = [];
26
+ }
27
+ set(propertyOrValue, value) {
28
+ if (typeof propertyOrValue === "string") {
29
+ return this.pushOperation({
30
+ type: "set",
31
+ path: propertyOrValue,
32
+ value
33
+ });
19
34
  }
20
- set(propertyOrValue, value) {
21
- if (typeof propertyOrValue === 'string') {
22
- return this.pushOperation({
23
- type: 'set',
24
- path: propertyOrValue,
25
- value: value,
26
- });
27
- }
28
- return this.pushOperation({
29
- type: 'set',
30
- path: '.',
31
- value: propertyOrValue,
32
- });
33
- }
34
- add(property, value) {
35
- return this.pushOperation({
36
- type: 'add',
37
- path: property,
38
- value: value,
39
- });
40
- }
41
- combine(property, value) {
42
- return this.pushOperation({
43
- type: 'combine',
44
- path: property,
45
- value: value,
46
- });
47
- }
48
- merge(propertyOrValue, value) {
49
- if (typeof propertyOrValue === 'string') {
50
- return this.pushOperation({
51
- type: 'merge',
52
- path: propertyOrValue,
53
- value: value,
54
- });
55
- }
56
- return this.pushOperation({
57
- type: 'merge',
58
- path: '.',
59
- value: propertyOrValue,
60
- });
61
- }
62
- increment(property, amount = 1) {
63
- return this.pushOperation({
64
- type: 'increment',
65
- path: property,
66
- value: amount,
67
- });
68
- }
69
- decrement(property, amount = 1) {
70
- return this.pushOperation({
71
- type: 'decrement',
72
- path: property,
73
- value: amount,
74
- });
75
- }
76
- clear(property) {
77
- return this.pushOperation({
78
- type: 'clear',
79
- path: property,
80
- });
81
- }
82
- unset(property) {
83
- return this.pushOperation({
84
- type: 'unset',
85
- path: property,
86
- });
87
- }
88
- remove(property, value) {
89
- return this.pushOperation({
90
- type: 'remove',
91
- path: property,
92
- value: value,
93
- });
94
- }
95
- pushOperation(operation) {
96
- const { type, ...data } = operation;
97
- operationSchema[type].validate(data);
98
- this.operations.push(operation);
99
- return this;
100
- }
101
- reset() {
102
- this.operations.splice(0);
103
- return this;
104
- }
105
- isDirty() {
106
- return this.operations.length > 0;
107
- }
108
- buildPatch() {
109
- return { operations: this.operations.slice() };
35
+ return this.pushOperation({
36
+ type: "set",
37
+ path: ".",
38
+ value: propertyOrValue
39
+ });
40
+ }
41
+ add(property, value) {
42
+ return this.pushOperation({
43
+ type: "add",
44
+ path: property,
45
+ value
46
+ });
47
+ }
48
+ combine(property, value) {
49
+ return this.pushOperation({
50
+ type: "combine",
51
+ path: property,
52
+ value
53
+ });
54
+ }
55
+ merge(propertyOrValue, value) {
56
+ if (typeof propertyOrValue === "string") {
57
+ return this.pushOperation({
58
+ type: "merge",
59
+ path: propertyOrValue,
60
+ value
61
+ });
110
62
  }
63
+ return this.pushOperation({
64
+ type: "merge",
65
+ path: ".",
66
+ value: propertyOrValue
67
+ });
68
+ }
69
+ increment(property, amount = 1) {
70
+ return this.pushOperation({
71
+ type: "increment",
72
+ path: property,
73
+ value: amount
74
+ });
75
+ }
76
+ decrement(property, amount = 1) {
77
+ return this.pushOperation({
78
+ type: "decrement",
79
+ path: property,
80
+ value: amount
81
+ });
82
+ }
83
+ clear(property) {
84
+ return this.pushOperation({
85
+ type: "clear",
86
+ path: property
87
+ });
88
+ }
89
+ unset(property) {
90
+ return this.pushOperation({
91
+ type: "unset",
92
+ path: property
93
+ });
94
+ }
95
+ remove(property, value) {
96
+ return this.pushOperation({
97
+ type: "remove",
98
+ path: property,
99
+ value
100
+ });
101
+ }
102
+ pushOperation(operation) {
103
+ const { type, ...data } = operation;
104
+ operationSchema[type].validate(data);
105
+ this.operations.push(operation);
106
+ return this;
107
+ }
108
+ reset() {
109
+ this.operations.splice(0);
110
+ return this;
111
+ }
112
+ isDirty() {
113
+ return this.operations.length > 0;
114
+ }
115
+ buildPatch() {
116
+ return { operations: this.operations.slice() };
117
+ }
111
118
  }
112
- exports.ActiveRecord = ActiveRecord;
119
+ export {
120
+ ActiveRecord
121
+ };
113
122
  //# sourceMappingURL=activeRecord.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"activeRecord.js","sourceRoot":"","sources":["src/activeRecord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AAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAEhC,OAAO,IAAI,CAAC;IAChB,CAAC;IAES,KAAK;QACX,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QAE1B,OAAO,IAAI,CAAC;IAChB,CAAC;IAIS,OAAO;QACb,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC;IACtC,CAAC;IAES,UAAU;QAChB,OAAO,EAAC,UAAU,EAAE,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,EAAC,CAAC;IACjD,CAAC;CACJ;AA1HD,oCA0HC"}
1
+ {"version":3,"sources":["src/activeRecord.ts"],"sourcesContent":["import {JsonStructure, JsonValue} from '@croct/json';\nimport {Operation, Patch} from './patch';\nimport {TrackingEvent} from './trackingEvents';\nimport {\n addOperation,\n clearOperation,\n combineOperation,\n decrementOperation,\n incrementOperation,\n mergeOperation,\n setOperation,\n unsetOperation,\n removeOperation,\n} from './schema';\n\nconst operationSchema = {\n add: addOperation,\n set: setOperation,\n merge: mergeOperation,\n combine: combineOperation,\n increment: incrementOperation,\n decrement: decrementOperation,\n clear: clearOperation,\n unset: unsetOperation,\n remove: removeOperation,\n};\n\nexport abstract class ActiveRecord<T extends TrackingEvent> {\n private readonly operations: Operation[] = [];\n\n public set(value: JsonValue): this;\n\n public set(property: string, value: JsonValue): this;\n\n public set(propertyOrValue: string | JsonValue, value?: JsonValue): this {\n if (typeof propertyOrValue === 'string') {\n return this.pushOperation({\n type: 'set',\n path: propertyOrValue,\n value: value as JsonValue,\n });\n }\n\n return this.pushOperation({\n type: 'set',\n path: '.',\n value: propertyOrValue,\n });\n }\n\n public add(property: string, value: JsonValue): this {\n return this.pushOperation({\n type: 'add',\n path: property,\n value: value,\n });\n }\n\n public combine(property: string, value: JsonValue): this {\n return this.pushOperation({\n type: 'combine',\n path: property,\n value: value,\n });\n }\n\n public merge(value: JsonStructure): this;\n\n public merge(property: string, value: JsonStructure): this;\n\n public merge(propertyOrValue: string | JsonStructure, value?: JsonStructure): this {\n if (typeof propertyOrValue === 'string') {\n return this.pushOperation({\n type: 'merge',\n path: propertyOrValue,\n value: value as JsonStructure,\n });\n }\n\n return this.pushOperation({\n type: 'merge',\n path: '.',\n value: propertyOrValue,\n });\n }\n\n public increment(property: string, amount = 1): this {\n return this.pushOperation({\n type: 'increment',\n path: property,\n value: amount,\n });\n }\n\n public decrement(property: string, amount = 1): this {\n return this.pushOperation({\n type: 'decrement',\n path: property,\n value: amount,\n });\n }\n\n public clear(property: string): this {\n return this.pushOperation({\n type: 'clear',\n path: property,\n });\n }\n\n public unset(property: string): this {\n return this.pushOperation({\n type: 'unset',\n path: property,\n });\n }\n\n public remove(property: string, value: JsonValue): this {\n return this.pushOperation({\n type: 'remove',\n path: property,\n value: value,\n });\n }\n\n private pushOperation(operation: Operation): this {\n const {type, ...data} = operation;\n\n operationSchema[type].validate(data);\n\n this.operations.push(operation);\n\n return this;\n }\n\n protected reset(): this {\n this.operations.splice(0);\n\n return this;\n }\n\n public abstract save(): Promise<T>;\n\n protected isDirty(): boolean {\n return this.operations.length > 0;\n }\n\n protected buildPatch(): Patch {\n return {operations: this.operations.slice()};\n }\n}\n"],"mappings":"AAGA;AAAA,EACI;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACG;AAEP,MAAM,kBAAkB;AAAA,EACpB,KAAK;AAAA,EACL,KAAK;AAAA,EACL,OAAO;AAAA,EACP,SAAS;AAAA,EACT,WAAW;AAAA,EACX,WAAW;AAAA,EACX,OAAO;AAAA,EACP,OAAO;AAAA,EACP,QAAQ;AACZ;AAEO,MAAe,aAAsC;AAAA,EAArD;AACH,SAAiB,aAA0B,CAAC;AAAA;AAAA,EAMrC,IAAI,iBAAqC,OAAyB;AACrE,QAAI,OAAO,oBAAoB,UAAU;AACrC,aAAO,KAAK,cAAc;AAAA,QACtB,MAAM;AAAA,QAC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O,KAAK,cAAc;AAAA,MACtB,MAAM;AAAA,MACN,MAAM;AAAA,MACN;AAAA,IACJ,CAAC;AAAA,EACL;AAAA,EAEQ,cAAc,WAA4B;AAC9C,UAAM,EAAC,MAAM,GAAG,KAAI,IAAI;AAExB,oBAAgB,IAAI,EAAE,SAAS,IAAI;AAEnC,SAAK,WAAW,KAAK,SAAS;AAE9B,WAAO;AAAA,EACX;AAAA,EAEU,QAAc;AACpB,SAAK,WAAW,OAAO,CAAC;AAExB,WAAO;AAAA,EACX;AAAA,EAIU,UAAmB;AACzB,WAAO,KAAK,WAAW,SAAS;AAAA,EACpC;AAAA,EAEU,aAAoB;AAC1B,WAAO,EAAC,YAAY,KAAK,WAAW,MAAM,EAAC;AAAA,EAC/C;AACJ;","names":[]}
package/apiKey.cjs.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/apiKey.ts"],"sourcesContent":["export type ParsedPrivateKey = {\n algorithm: string,\n encodedKey: string,\n};\n\ntype Algorithm = {\n keyAlgorithm: EcKeyImportParams,\n signatureAlgorithm: EcdsaParams,\n};\n\nexport class ApiKey {\n private static readonly IDENTIFIER_PATTERN = /^[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}$/i;\n\n private static readonly PRIVATE_KEY_PATTERN = /^[a-z0-9]+;[^;]+$/i;\n\n private static readonly ALGORITHMS: Record<string, Algorithm> = {\n ES256: {\n keyAlgorithm: {\n name: 'ECDSA',\n namedCurve: 'P-256',\n },\n signatureAlgorithm: {\n name: 'ECDSA',\n hash: 'SHA-256',\n },\n },\n };\n\n private readonly identifier: string;\n\n private readonly privateKey?: ParsedPrivateKey;\n\n private importedKey: Promise<CryptoKey>;\n\n private constructor(identifier: string, privateKey?: ParsedPrivateKey) {\n this.identifier = identifier;\n this.privateKey = privateKey;\n }\n\n public static from(apiKey: string | ApiKey): ApiKey {\n if (apiKey instanceof ApiKey) {\n return apiKey;\n }\n\n return ApiKey.parse(apiKey);\n }\n\n public static parse(apiKey: string): ApiKey {\n const parts = apiKey.split(':');\n\n if (parts.length > 2) {\n throw new Error('Invalid API key format.');\n }\n\n return ApiKey.of(parts[0], parts[1]);\n }\n\n public static of(identifier: string, privateKey?: string): ApiKey {\n if (!ApiKey.IDENTIFIER_PATTERN.test(identifier)) {\n throw new Error('The identifier must be a UUID.');\n }\n\n if (privateKey === undefined || privateKey === '') {\n return new ApiKey(identifier);\n }\n\n if (!ApiKey.PRIVATE_KEY_PATTERN.test(privateKey)) {\n throw new Error('The private key is malformed.');\n }\n\n const [algorithmName, encodedKey] = privateKey.split(';');\n\n if (!(algorithmName in ApiKey.ALGORITHMS)) {\n throw new Error(`Unsupported signing algorithm \"${algorithmName}\".`);\n }\n\n return new ApiKey(identifier, {\n algorithm: algorithmName,\n encodedKey: encodedKey,\n });\n }\n\n public getIdentifier(): string {\n return this.identifier;\n }\n\n public async getIdentifierHash(): Promise<string> {\n const identifierBytes = ApiKey.createByteArrayFromHexString(this.identifier.replace(/-/g, ''));\n const rawHash = await crypto.subtle.digest('SHA-256', identifierBytes);\n\n return ApiKey.convertBufferToHexString(rawHash);\n }\n\n public hasPrivateKey(): boolean {\n return this.privateKey !== undefined;\n }\n\n public getPrivateKey(): string {\n if (this.privateKey === undefined) {\n throw new Error('The API key does not have a private key.');\n }\n\n return `${this.privateKey.algorithm};${this.privateKey.encodedKey}`;\n }\n\n public async sign(data: string): Promise<string> {\n const key = await this.importKey();\n const algorithm = this.getSigningAlgorithm();\n\n return ApiKey.convertBufferToString(\n await crypto.subtle.sign(\n ApiKey.ALGORITHMS[algorithm].signatureAlgorithm,\n key,\n ApiKey.createByteArrayFromString(data),\n ),\n );\n }\n\n public getSigningAlgorithm(): string {\n const {algorithm} = this.getParsedPrivateKey();\n\n return algorithm;\n }\n\n private importKey(): Promise<CryptoKey> {\n const {algorithm, encodedKey} = this.getParsedPrivateKey();\n\n if (this.importedKey === undefined) {\n this.importedKey = crypto.subtle\n .importKey(\n 'pkcs8',\n ApiKey.createByteArrayFromString(atob(encodedKey)),\n ApiKey.ALGORITHMS[algorithm].keyAlgorithm,\n false,\n ['sign'],\n );\n }\n\n return this.importedKey;\n }\n\n private getParsedPrivateKey(): ParsedPrivateKey {\n if (this.privateKey === undefined) {\n throw new Error('The API key does not have a private key.');\n }\n\n return this.privateKey;\n }\n\n public export(): string {\n return this.identifier + (this.hasPrivateKey() ? `:${this.getPrivateKey()}` : '');\n }\n\n public toString(): string {\n return '[redacted]';\n }\n\n /**\n * Create an array buffer from a string.\n *\n * @see https://developers.google.com/web/updates/2012/06/How-to-convert-ArrayBuffer-to-and-from-String\n *\n * @param data The string to convert.\n * @returns The array buffer.\n */\n private static createByteArrayFromString(data: string): Uint8Array {\n const byteArray = new Uint8Array(data.length);\n\n for (let i = 0; i < byteArray.length; i++) {\n byteArray[i] = data.charCodeAt(i);\n }\n\n return byteArray;\n }\n\n private static createByteArrayFromHexString(data: string): Uint8Array {\n const byteArray = new Uint8Array(data.length / 2);\n\n for (let i = 0; i < byteArray.length; i++) {\n byteArray[i] = parseInt(data.substring(i * 2, i * 2 + 2), 16);\n }\n\n return byteArray;\n }\n\n /**\n * Convert an array buffer to a string.\n *\n * @see https://developers.google.com/web/updates/2012/06/How-to-convert-ArrayBuffer-to-and-from-String\n *\n * @param buffer The buffer to convert.\n * @returns The string.\n */\n private static convertBufferToString(buffer: ArrayLike<number> | ArrayBufferLike): string {\n return String.fromCharCode(...new Uint8Array(buffer));\n }\n\n private static convertBufferToHexString(buffer: ArrayLike<number> | ArrayBufferLike): string {\n const bytes = new Uint8Array(buffer);\n let hexString = '';\n\n for (let i = 0; i < bytes.length; i++) {\n hexString += bytes[i].toString(16).padStart(2, '0');\n }\n\n return hexString;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAUO,MAAM,UAAN,MAAM,QAAO;AAAA,EAwBR,YAAY,YAAoB,YAA+B;AACnE,SAAK,aAAa;A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K,MAAM;AAE5C,aAAS,IAAI,GAAG,IAAI,UAAU,QAAQ,KAAK;AACvC,gBAAU,CAAC,IAAI,KAAK,WAAW,CAAC;AAAA,IACpC;AAEA,WAAO;AAAA,EACX;AAAA,EAEA,OAAe,6BAA6B,MAA0B;AAClE,UAAM,YAAY,IAAI,WAAW,KAAK,SAAS,CAAC;AAEhD,aAAS,IAAI,GAAG,IAAI,UAAU,QAAQ,KAAK;AACvC,gBAAU,CAAC,IAAI,SAAS,KAAK,UAAU,IAAI,GAAG,IAAI,IAAI,CAAC,GAAG,EAAE;AAAA,IAChE;AAEA,WAAO;AAAA,EACX;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,OAAe,sBAAsB,QAAqD;AACtF,WAAO,OAAO,aAAa,GAAG,IAAI,WAAW,MAAM,CAAC;AAAA,EACxD;AAAA,EAEA,OAAe,yBAAyB,QAAqD;AACzF,UAAM,QAAQ,IAAI,WAAW,MAAM;AACnC,QAAI,YAAY;AAEhB,aAAS,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;AACnC,mBAAa,MAAM,CAAC,EAAE,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG;AAAA,IACtD;AAEA,WAAO;AAAA,EACX;AACJ;AArMa,QACe,qBAAqB;AADpC,QAGe,sBAAsB;AAHrC,QAKe,aAAwC;AAAA,EAC5D,OAAO;AAAA,IACH,cAAc;AAAA,MACV,MAAM;AAAA,MACN,YAAY;AAAA,IAChB;AAAA,IACA,oBAAoB;AAAA,MAChB,MAAM;AAAA,MACN,MAAM;AAAA,IACV;AAAA,EACJ;AACJ;AAhBG,IAAM,SAAN;","names":[]}
package/apiKey.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- export type ParsedPrivateKey = {
1
+ type ParsedPrivateKey = {
2
2
  algorithm: string;
3
3
  encodedKey: string;
4
4
  };
5
- export declare class ApiKey {
5
+ declare class ApiKey {
6
6
  private static readonly IDENTIFIER_PATTERN;
7
7
  private static readonly PRIVATE_KEY_PATTERN;
8
8
  private static readonly ALGORITHMS;
@@ -44,3 +44,5 @@ export declare class ApiKey {
44
44
  private static convertBufferToString;
45
45
  private static convertBufferToHexString;
46
46
  }
47
+
48
+ export { ApiKey, type ParsedPrivateKey };
package/apiKey.js CHANGED
@@ -1,144 +1,155 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ApiKey = void 0;
4
- class ApiKey {
5
- constructor(identifier, privateKey) {
6
- this.identifier = identifier;
7
- this.privateKey = privateKey;
8
- }
9
- static from(apiKey) {
10
- if (apiKey instanceof ApiKey) {
11
- return apiKey;
12
- }
13
- return ApiKey.parse(apiKey);
14
- }
15
- static parse(apiKey) {
16
- const parts = apiKey.split(':');
17
- if (parts.length > 2) {
18
- throw new Error('Invalid API key format.');
19
- }
20
- return ApiKey.of(parts[0], parts[1]);
21
- }
22
- static of(identifier, privateKey) {
23
- if (!ApiKey.IDENTIFIER_PATTERN.test(identifier)) {
24
- throw new Error('The identifier must be a UUID.');
25
- }
26
- if (privateKey === undefined || privateKey === '') {
27
- return new ApiKey(identifier);
28
- }
29
- if (!ApiKey.PRIVATE_KEY_PATTERN.test(privateKey)) {
30
- throw new Error('The private key is malformed.');
31
- }
32
- const [algorithmName, encodedKey] = privateKey.split(';');
33
- if (!(algorithmName in ApiKey.ALGORITHMS)) {
34
- throw new Error(`Unsupported signing algorithm "${algorithmName}".`);
35
- }
36
- return new ApiKey(identifier, {
37
- algorithm: algorithmName,
38
- encodedKey: encodedKey,
39
- });
40
- }
41
- getIdentifier() {
42
- return this.identifier;
43
- }
44
- async getIdentifierHash() {
45
- const identifierBytes = ApiKey.createByteArrayFromHexString(this.identifier.replace(/-/g, ''));
46
- const rawHash = await crypto.subtle.digest('SHA-256', identifierBytes);
47
- return ApiKey.convertBufferToHexString(rawHash);
48
- }
49
- hasPrivateKey() {
50
- return this.privateKey !== undefined;
51
- }
52
- getPrivateKey() {
53
- if (this.privateKey === undefined) {
54
- throw new Error('The API key does not have a private key.');
55
- }
56
- return `${this.privateKey.algorithm};${this.privateKey.encodedKey}`;
57
- }
58
- async sign(data) {
59
- const key = await this.importKey();
60
- const algorithm = this.getSigningAlgorithm();
61
- return ApiKey.convertBufferToString(await crypto.subtle.sign(ApiKey.ALGORITHMS[algorithm].signatureAlgorithm, key, ApiKey.createByteArrayFromString(data)));
62
- }
63
- getSigningAlgorithm() {
64
- const { algorithm } = this.getParsedPrivateKey();
65
- return algorithm;
66
- }
67
- importKey() {
68
- const { algorithm, encodedKey } = this.getParsedPrivateKey();
69
- if (this.importedKey === undefined) {
70
- this.importedKey = crypto.subtle
71
- .importKey('pkcs8', ApiKey.createByteArrayFromString(atob(encodedKey)), ApiKey.ALGORITHMS[algorithm].keyAlgorithm, false, ['sign']);
72
- }
73
- return this.importedKey;
74
- }
75
- getParsedPrivateKey() {
76
- if (this.privateKey === undefined) {
77
- throw new Error('The API key does not have a private key.');
78
- }
79
- return this.privateKey;
80
- }
81
- export() {
82
- return this.identifier + (this.hasPrivateKey() ? `:${this.getPrivateKey()}` : '');
83
- }
84
- toString() {
85
- return '[redacted]';
86
- }
87
- /**
88
- * Create an array buffer from a string.
89
- *
90
- * @see https://developers.google.com/web/updates/2012/06/How-to-convert-ArrayBuffer-to-and-from-String
91
- *
92
- * @param data The string to convert.
93
- * @returns The array buffer.
94
- */
95
- static createByteArrayFromString(data) {
96
- const byteArray = new Uint8Array(data.length);
97
- for (let i = 0; i < byteArray.length; i++) {
98
- byteArray[i] = data.charCodeAt(i);
99
- }
100
- return byteArray;
101
- }
102
- static createByteArrayFromHexString(data) {
103
- const byteArray = new Uint8Array(data.length / 2);
104
- for (let i = 0; i < byteArray.length; i++) {
105
- byteArray[i] = parseInt(data.substring(i * 2, i * 2 + 2), 16);
106
- }
107
- return byteArray;
108
- }
109
- /**
110
- * Convert an array buffer to a string.
111
- *
112
- * @see https://developers.google.com/web/updates/2012/06/How-to-convert-ArrayBuffer-to-and-from-String
113
- *
114
- * @param buffer The buffer to convert.
115
- * @returns The string.
116
- */
117
- static convertBufferToString(buffer) {
118
- return String.fromCharCode(...new Uint8Array(buffer));
119
- }
120
- static convertBufferToHexString(buffer) {
121
- const bytes = new Uint8Array(buffer);
122
- let hexString = '';
123
- for (let i = 0; i < bytes.length; i++) {
124
- hexString += bytes[i].toString(16).padStart(2, '0');
125
- }
126
- return hexString;
127
- }
128
- }
129
- exports.ApiKey = ApiKey;
130
- ApiKey.IDENTIFIER_PATTERN = /^[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}$/i;
131
- ApiKey.PRIVATE_KEY_PATTERN = /^[a-z0-9]+;[^;]+$/i;
132
- ApiKey.ALGORITHMS = {
133
- ES256: {
134
- keyAlgorithm: {
135
- name: 'ECDSA',
136
- namedCurve: 'P-256',
137
- },
138
- signatureAlgorithm: {
139
- name: 'ECDSA',
140
- hash: 'SHA-256',
141
- },
1
+ const _ApiKey = class _ApiKey {
2
+ constructor(identifier, privateKey) {
3
+ this.identifier = identifier;
4
+ this.privateKey = privateKey;
5
+ }
6
+ static from(apiKey) {
7
+ if (apiKey instanceof _ApiKey) {
8
+ return apiKey;
9
+ }
10
+ return _ApiKey.parse(apiKey);
11
+ }
12
+ static parse(apiKey) {
13
+ const parts = apiKey.split(":");
14
+ if (parts.length > 2) {
15
+ throw new Error("Invalid API key format.");
16
+ }
17
+ return _ApiKey.of(parts[0], parts[1]);
18
+ }
19
+ static of(identifier, privateKey) {
20
+ if (!_ApiKey.IDENTIFIER_PATTERN.test(identifier)) {
21
+ throw new Error("The identifier must be a UUID.");
22
+ }
23
+ if (privateKey === void 0 || privateKey === "") {
24
+ return new _ApiKey(identifier);
25
+ }
26
+ if (!_ApiKey.PRIVATE_KEY_PATTERN.test(privateKey)) {
27
+ throw new Error("The private key is malformed.");
28
+ }
29
+ const [algorithmName, encodedKey] = privateKey.split(";");
30
+ if (!(algorithmName in _ApiKey.ALGORITHMS)) {
31
+ throw new Error(`Unsupported signing algorithm "${algorithmName}".`);
32
+ }
33
+ return new _ApiKey(identifier, {
34
+ algorithm: algorithmName,
35
+ encodedKey
36
+ });
37
+ }
38
+ getIdentifier() {
39
+ return this.identifier;
40
+ }
41
+ async getIdentifierHash() {
42
+ const identifierBytes = _ApiKey.createByteArrayFromHexString(this.identifier.replace(/-/g, ""));
43
+ const rawHash = await crypto.subtle.digest("SHA-256", identifierBytes);
44
+ return _ApiKey.convertBufferToHexString(rawHash);
45
+ }
46
+ hasPrivateKey() {
47
+ return this.privateKey !== void 0;
48
+ }
49
+ getPrivateKey() {
50
+ if (this.privateKey === void 0) {
51
+ throw new Error("The API key does not have a private key.");
52
+ }
53
+ return `${this.privateKey.algorithm};${this.privateKey.encodedKey}`;
54
+ }
55
+ async sign(data) {
56
+ const key = await this.importKey();
57
+ const algorithm = this.getSigningAlgorithm();
58
+ return _ApiKey.convertBufferToString(
59
+ await crypto.subtle.sign(
60
+ _ApiKey.ALGORITHMS[algorithm].signatureAlgorithm,
61
+ key,
62
+ _ApiKey.createByteArrayFromString(data)
63
+ )
64
+ );
65
+ }
66
+ getSigningAlgorithm() {
67
+ const { algorithm } = this.getParsedPrivateKey();
68
+ return algorithm;
69
+ }
70
+ importKey() {
71
+ const { algorithm, encodedKey } = this.getParsedPrivateKey();
72
+ if (this.importedKey === void 0) {
73
+ this.importedKey = crypto.subtle.importKey(
74
+ "pkcs8",
75
+ _ApiKey.createByteArrayFromString(atob(encodedKey)),
76
+ _ApiKey.ALGORITHMS[algorithm].keyAlgorithm,
77
+ false,
78
+ ["sign"]
79
+ );
80
+ }
81
+ return this.importedKey;
82
+ }
83
+ getParsedPrivateKey() {
84
+ if (this.privateKey === void 0) {
85
+ throw new Error("The API key does not have a private key.");
86
+ }
87
+ return this.privateKey;
88
+ }
89
+ export() {
90
+ return this.identifier + (this.hasPrivateKey() ? `:${this.getPrivateKey()}` : "");
91
+ }
92
+ toString() {
93
+ return "[redacted]";
94
+ }
95
+ /**
96
+ * Create an array buffer from a string.
97
+ *
98
+ * @see https://developers.google.com/web/updates/2012/06/How-to-convert-ArrayBuffer-to-and-from-String
99
+ *
100
+ * @param data The string to convert.
101
+ * @returns The array buffer.
102
+ */
103
+ static createByteArrayFromString(data) {
104
+ const byteArray = new Uint8Array(data.length);
105
+ for (let i = 0; i < byteArray.length; i++) {
106
+ byteArray[i] = data.charCodeAt(i);
107
+ }
108
+ return byteArray;
109
+ }
110
+ static createByteArrayFromHexString(data) {
111
+ const byteArray = new Uint8Array(data.length / 2);
112
+ for (let i = 0; i < byteArray.length; i++) {
113
+ byteArray[i] = parseInt(data.substring(i * 2, i * 2 + 2), 16);
114
+ }
115
+ return byteArray;
116
+ }
117
+ /**
118
+ * Convert an array buffer to a string.
119
+ *
120
+ * @see https://developers.google.com/web/updates/2012/06/How-to-convert-ArrayBuffer-to-and-from-String
121
+ *
122
+ * @param buffer The buffer to convert.
123
+ * @returns The string.
124
+ */
125
+ static convertBufferToString(buffer) {
126
+ return String.fromCharCode(...new Uint8Array(buffer));
127
+ }
128
+ static convertBufferToHexString(buffer) {
129
+ const bytes = new Uint8Array(buffer);
130
+ let hexString = "";
131
+ for (let i = 0; i < bytes.length; i++) {
132
+ hexString += bytes[i].toString(16).padStart(2, "0");
133
+ }
134
+ return hexString;
135
+ }
136
+ };
137
+ _ApiKey.IDENTIFIER_PATTERN = /^[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}$/i;
138
+ _ApiKey.PRIVATE_KEY_PATTERN = /^[a-z0-9]+;[^;]+$/i;
139
+ _ApiKey.ALGORITHMS = {
140
+ ES256: {
141
+ keyAlgorithm: {
142
+ name: "ECDSA",
143
+ namedCurve: "P-256"
142
144
  },
145
+ signatureAlgorithm: {
146
+ name: "ECDSA",
147
+ hash: "SHA-256"
148
+ }
149
+ }
150
+ };
151
+ let ApiKey = _ApiKey;
152
+ export {
153
+ ApiKey
143
154
  };
144
155
  //# sourceMappingURL=apiKey.js.map