@strivacity/sdk-core 3.0.3 → 4.0.0-beta.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 (327) hide show
  1. package/README.md +1873 -340
  2. package/dist/assets/oidc.cjs +2 -0
  3. package/dist/assets/oidc.cjs.map +1 -0
  4. package/dist/assets/oidc.mjs +2 -0
  5. package/dist/assets/oidc.mjs.map +1 -0
  6. package/dist/assets/server.cjs +2 -0
  7. package/dist/assets/server.cjs.map +1 -0
  8. package/dist/assets/server.mjs +2 -0
  9. package/dist/assets/server.mjs.map +1 -0
  10. package/dist/flows/base.cjs +2 -0
  11. package/dist/flows/base.cjs.map +1 -0
  12. package/dist/flows/base.d.ts +26 -0
  13. package/dist/flows/base.mjs +2 -0
  14. package/dist/flows/base.mjs.map +1 -0
  15. package/dist/flows/embedded.cjs +2 -0
  16. package/dist/flows/embedded.cjs.map +1 -0
  17. package/dist/flows/embedded.d.ts +9 -0
  18. package/dist/flows/embedded.mjs +2 -0
  19. package/dist/flows/embedded.mjs.map +1 -0
  20. package/dist/flows/index.cjs +1 -0
  21. package/dist/flows/index.d.ts +5 -0
  22. package/dist/flows/index.mjs +1 -0
  23. package/dist/flows/native.cjs +2 -0
  24. package/dist/flows/native.cjs.map +1 -0
  25. package/dist/flows/native.d.ts +9 -0
  26. package/dist/flows/native.mjs +2 -0
  27. package/dist/flows/native.mjs.map +1 -0
  28. package/dist/flows/popup.cjs +2 -0
  29. package/dist/flows/popup.cjs.map +1 -0
  30. package/dist/flows/popup.d.ts +9 -0
  31. package/dist/flows/popup.mjs +2 -0
  32. package/dist/flows/popup.mjs.map +1 -0
  33. package/dist/flows/redirect.cjs +2 -0
  34. package/dist/flows/redirect.cjs.map +1 -0
  35. package/dist/flows/redirect.d.ts +9 -0
  36. package/dist/flows/redirect.mjs +2 -0
  37. package/dist/flows/redirect.mjs.map +1 -0
  38. package/dist/handlers/embedded.cjs +2 -0
  39. package/dist/handlers/embedded.cjs.map +1 -0
  40. package/dist/handlers/embedded.d.ts +37 -0
  41. package/dist/handlers/embedded.mjs +2 -0
  42. package/dist/handlers/embedded.mjs.map +1 -0
  43. package/dist/handlers/index.cjs +1 -0
  44. package/dist/handlers/index.d.ts +2 -0
  45. package/dist/handlers/index.mjs +1 -0
  46. package/dist/handlers/native.cjs +2 -0
  47. package/dist/handlers/native.cjs.map +1 -0
  48. package/dist/handlers/native.d.ts +56 -0
  49. package/dist/handlers/native.mjs +2 -0
  50. package/dist/handlers/native.mjs.map +1 -0
  51. package/dist/handlers/popup.cjs +2 -0
  52. package/dist/handlers/popup.cjs.map +1 -0
  53. package/dist/handlers/popup.d.ts +21 -0
  54. package/dist/handlers/popup.mjs +2 -0
  55. package/dist/handlers/popup.mjs.map +1 -0
  56. package/dist/handlers/redirect.cjs +2 -0
  57. package/dist/handlers/redirect.cjs.map +1 -0
  58. package/dist/handlers/redirect.d.ts +18 -0
  59. package/dist/handlers/redirect.mjs +2 -0
  60. package/dist/handlers/redirect.mjs.map +1 -0
  61. package/dist/index.cjs +2 -2
  62. package/dist/index.cjs.map +1 -1
  63. package/dist/index.d.ts +16 -21
  64. package/dist/index.mjs +2 -2
  65. package/dist/index.mjs.map +1 -1
  66. package/dist/server/base.cjs +2 -0
  67. package/dist/server/base.cjs.map +1 -0
  68. package/dist/server/base.d.ts +15 -0
  69. package/dist/server/base.mjs +2 -0
  70. package/dist/server/base.mjs.map +1 -0
  71. package/dist/server/index.cjs +1 -0
  72. package/dist/server/index.d.ts +1 -0
  73. package/dist/server/index.mjs +1 -0
  74. package/dist/storages/cache.cjs +2 -0
  75. package/dist/storages/cache.cjs.map +1 -0
  76. package/dist/storages/cache.d.ts +11 -0
  77. package/dist/storages/cache.mjs +2 -0
  78. package/dist/storages/cache.mjs.map +1 -0
  79. package/dist/storages/index.cjs +1 -0
  80. package/dist/storages/index.d.ts +7 -0
  81. package/dist/storages/index.mjs +1 -0
  82. package/dist/storages/indexeddb.cjs +2 -0
  83. package/dist/storages/indexeddb.cjs.map +1 -0
  84. package/dist/storages/indexeddb.d.ts +10 -0
  85. package/dist/storages/indexeddb.mjs +2 -0
  86. package/dist/storages/indexeddb.mjs.map +1 -0
  87. package/dist/storages/local.cjs +2 -0
  88. package/dist/storages/local.cjs.map +1 -0
  89. package/dist/storages/local.d.ts +7 -0
  90. package/dist/storages/local.mjs +2 -0
  91. package/dist/storages/local.mjs.map +1 -0
  92. package/dist/storages/memory.cjs +2 -0
  93. package/dist/storages/memory.cjs.map +1 -0
  94. package/dist/storages/memory.d.ts +8 -0
  95. package/dist/storages/memory.mjs +2 -0
  96. package/dist/storages/memory.mjs.map +1 -0
  97. package/dist/storages/server.cjs +1 -0
  98. package/dist/storages/server.d.ts +39 -0
  99. package/dist/storages/server.mjs +1 -0
  100. package/dist/storages/session.cjs +2 -0
  101. package/dist/storages/session.cjs.map +1 -0
  102. package/dist/storages/session.d.ts +7 -0
  103. package/dist/storages/session.mjs +2 -0
  104. package/dist/storages/session.mjs.map +1 -0
  105. package/dist/storages/worker.cjs +2 -0
  106. package/dist/storages/worker.cjs.map +1 -0
  107. package/dist/storages/worker.d.ts +46 -0
  108. package/dist/storages/worker.mjs +2 -0
  109. package/dist/storages/worker.mjs.map +1 -0
  110. package/dist/types/common.cjs +0 -0
  111. package/dist/types/common.d.ts +145 -0
  112. package/dist/types/common.mjs +0 -0
  113. package/dist/types/embedded.cjs +0 -0
  114. package/dist/types/embedded.d.ts +103 -0
  115. package/dist/types/embedded.mjs +0 -0
  116. package/dist/types/index.cjs +1 -0
  117. package/dist/types/index.d.ts +7 -0
  118. package/dist/types/index.mjs +1 -0
  119. package/dist/types/native.cjs +0 -0
  120. package/dist/types/native.d.ts +385 -0
  121. package/dist/types/native.mjs +0 -0
  122. package/dist/types/oidc.cjs +2 -0
  123. package/dist/types/oidc.cjs.map +1 -0
  124. package/dist/types/oidc.d.ts +768 -0
  125. package/dist/types/oidc.mjs +2 -0
  126. package/dist/types/oidc.mjs.map +1 -0
  127. package/dist/types/popup.cjs +0 -0
  128. package/dist/types/popup.d.ts +69 -0
  129. package/dist/types/popup.mjs +0 -0
  130. package/dist/types/redirect.cjs +0 -0
  131. package/dist/types/redirect.d.ts +21 -0
  132. package/dist/types/redirect.mjs +0 -0
  133. package/dist/types/server.cjs +0 -0
  134. package/dist/types/server.d.ts +200 -0
  135. package/dist/types/server.mjs +0 -0
  136. package/dist/utils/base64url.cjs +2 -0
  137. package/dist/utils/base64url.cjs.map +1 -0
  138. package/dist/utils/base64url.d.ts +14 -0
  139. package/dist/utils/base64url.mjs +2 -0
  140. package/dist/utils/base64url.mjs.map +1 -0
  141. package/dist/utils/common.cjs +2 -0
  142. package/dist/utils/common.cjs.map +1 -0
  143. package/dist/utils/common.d.ts +23 -0
  144. package/dist/utils/common.mjs +2 -0
  145. package/dist/utils/common.mjs.map +1 -0
  146. package/dist/utils/credentials.cjs +2 -2
  147. package/dist/utils/credentials.cjs.map +1 -1
  148. package/dist/utils/credentials.d.ts +19 -3
  149. package/dist/utils/credentials.mjs +2 -2
  150. package/dist/utils/credentials.mjs.map +1 -1
  151. package/dist/utils/crypto.cjs +2 -2
  152. package/dist/utils/crypto.cjs.map +1 -1
  153. package/dist/utils/crypto.d.ts +16 -26
  154. package/dist/utils/crypto.mjs +2 -2
  155. package/dist/utils/crypto.mjs.map +1 -1
  156. package/dist/utils/dom.cjs +2 -0
  157. package/dist/utils/dom.cjs.map +1 -0
  158. package/dist/utils/dom.d.ts +7 -0
  159. package/dist/utils/dom.mjs +2 -0
  160. package/dist/utils/dom.mjs.map +1 -0
  161. package/dist/utils/errors.cjs +2 -2
  162. package/dist/utils/errors.cjs.map +1 -1
  163. package/dist/utils/errors.d.ts +62 -1
  164. package/dist/utils/errors.mjs +2 -2
  165. package/dist/utils/errors.mjs.map +1 -1
  166. package/dist/utils/httpClient.cjs +2 -0
  167. package/dist/utils/httpClient.cjs.map +1 -0
  168. package/dist/utils/httpClient.d.ts +2 -0
  169. package/dist/utils/httpClient.mjs +2 -0
  170. package/dist/utils/httpClient.mjs.map +1 -0
  171. package/dist/utils/index.cjs +1 -0
  172. package/dist/utils/index.d.ts +12 -0
  173. package/dist/utils/index.mjs +1 -0
  174. package/dist/utils/logging.cjs +2 -0
  175. package/dist/utils/logging.cjs.map +1 -0
  176. package/dist/utils/logging.d.ts +2 -0
  177. package/dist/utils/logging.mjs +2 -0
  178. package/dist/utils/logging.mjs.map +1 -0
  179. package/dist/utils/oidc.cjs +1 -0
  180. package/dist/utils/oidc.d.ts +264 -0
  181. package/dist/utils/oidc.mjs +1 -0
  182. package/dist/utils/server.cjs +1 -0
  183. package/dist/utils/server.d.ts +72 -0
  184. package/dist/utils/server.mjs +1 -0
  185. package/dist/utils/session.cjs +2 -0
  186. package/dist/utils/session.cjs.map +1 -0
  187. package/dist/utils/session.d.ts +29 -0
  188. package/dist/utils/session.mjs +2 -0
  189. package/dist/utils/session.mjs.map +1 -0
  190. package/dist/utils/state.cjs +1 -0
  191. package/dist/utils/state.d.ts +23 -0
  192. package/dist/utils/state.mjs +1 -0
  193. package/package.json +53 -1
  194. package/testing/tests/flows/base.spec.ts +1030 -0
  195. package/testing/tests/flows/embedded.spec.ts +443 -0
  196. package/testing/tests/flows/index.spec.ts +8 -0
  197. package/testing/tests/flows/native.spec.ts +487 -0
  198. package/testing/tests/flows/popup.spec.ts +400 -0
  199. package/testing/tests/flows/redirect.spec.ts +369 -0
  200. package/testing/tests/handlers/embedded.spec.ts +199 -0
  201. package/testing/tests/handlers/index.spec.ts +8 -0
  202. package/testing/tests/handlers/native.spec.ts +283 -0
  203. package/testing/tests/handlers/popup.spec.ts +206 -0
  204. package/testing/tests/handlers/redirect.spec.ts +70 -0
  205. package/testing/tests/index.spec.ts +78 -0
  206. package/testing/tests/server/base.spec.ts +846 -0
  207. package/testing/tests/server/index.spec.ts +15 -0
  208. package/testing/tests/storages/cache.spec.ts +107 -0
  209. package/testing/tests/storages/index.spec.ts +22 -0
  210. package/testing/tests/storages/indexeddb.spec.ts +113 -0
  211. package/testing/tests/storages/local.spec.ts +46 -0
  212. package/testing/tests/storages/memory.spec.ts +51 -0
  213. package/testing/tests/storages/server.spec.ts +435 -0
  214. package/testing/tests/storages/session.spec.ts +46 -0
  215. package/testing/tests/storages/worker.spec.ts +106 -0
  216. package/testing/tests/utils/common.spec.ts +77 -0
  217. package/testing/tests/utils/credentials.spec.ts +195 -0
  218. package/testing/tests/utils/dom.spec.ts +37 -0
  219. package/testing/tests/utils/index.spec.ts +71 -0
  220. package/testing/tests/utils/logging.spec.ts +82 -0
  221. package/testing/tests/utils/oidc.spec.ts +744 -0
  222. package/testing/tests/utils/server.spec.ts +235 -0
  223. package/dist/flows/BaseFlow.cjs +0 -2
  224. package/dist/flows/BaseFlow.cjs.map +0 -1
  225. package/dist/flows/BaseFlow.d.ts +0 -191
  226. package/dist/flows/BaseFlow.mjs +0 -2
  227. package/dist/flows/BaseFlow.mjs.map +0 -1
  228. package/dist/flows/EmbeddedFlow.cjs +0 -2
  229. package/dist/flows/EmbeddedFlow.cjs.map +0 -1
  230. package/dist/flows/EmbeddedFlow.d.ts +0 -26
  231. package/dist/flows/EmbeddedFlow.mjs +0 -2
  232. package/dist/flows/EmbeddedFlow.mjs.map +0 -1
  233. package/dist/flows/NativeFlow.cjs +0 -2
  234. package/dist/flows/NativeFlow.cjs.map +0 -1
  235. package/dist/flows/NativeFlow.d.ts +0 -34
  236. package/dist/flows/NativeFlow.mjs +0 -2
  237. package/dist/flows/NativeFlow.mjs.map +0 -1
  238. package/dist/flows/PopupFlow.cjs +0 -2
  239. package/dist/flows/PopupFlow.cjs.map +0 -1
  240. package/dist/flows/PopupFlow.d.ts +0 -36
  241. package/dist/flows/PopupFlow.mjs +0 -2
  242. package/dist/flows/PopupFlow.mjs.map +0 -1
  243. package/dist/flows/RedirectFlow.cjs +0 -2
  244. package/dist/flows/RedirectFlow.cjs.map +0 -1
  245. package/dist/flows/RedirectFlow.d.ts +0 -38
  246. package/dist/flows/RedirectFlow.mjs +0 -2
  247. package/dist/flows/RedirectFlow.mjs.map +0 -1
  248. package/dist/handlers/BaseFlowHandler.cjs +0 -2
  249. package/dist/handlers/BaseFlowHandler.cjs.map +0 -1
  250. package/dist/handlers/BaseFlowHandler.d.ts +0 -61
  251. package/dist/handlers/BaseFlowHandler.mjs +0 -2
  252. package/dist/handlers/BaseFlowHandler.mjs.map +0 -1
  253. package/dist/handlers/EmbeddedFlowHandler.cjs +0 -2
  254. package/dist/handlers/EmbeddedFlowHandler.cjs.map +0 -1
  255. package/dist/handlers/EmbeddedFlowHandler.d.ts +0 -28
  256. package/dist/handlers/EmbeddedFlowHandler.mjs +0 -2
  257. package/dist/handlers/EmbeddedFlowHandler.mjs.map +0 -1
  258. package/dist/handlers/NativeFlowHandler.cjs +0 -2
  259. package/dist/handlers/NativeFlowHandler.cjs.map +0 -1
  260. package/dist/handlers/NativeFlowHandler.d.ts +0 -31
  261. package/dist/handlers/NativeFlowHandler.mjs +0 -2
  262. package/dist/handlers/NativeFlowHandler.mjs.map +0 -1
  263. package/dist/storages/LocalStorage.cjs +0 -2
  264. package/dist/storages/LocalStorage.cjs.map +0 -1
  265. package/dist/storages/LocalStorage.d.ts +0 -23
  266. package/dist/storages/LocalStorage.mjs +0 -2
  267. package/dist/storages/LocalStorage.mjs.map +0 -1
  268. package/dist/storages/SessionStorage.cjs +0 -2
  269. package/dist/storages/SessionStorage.cjs.map +0 -1
  270. package/dist/storages/SessionStorage.d.ts +0 -23
  271. package/dist/storages/SessionStorage.mjs +0 -2
  272. package/dist/storages/SessionStorage.mjs.map +0 -1
  273. package/dist/types.cjs +0 -2
  274. package/dist/types.cjs.map +0 -1
  275. package/dist/types.d.ts +0 -1263
  276. package/dist/types.mjs +0 -2
  277. package/dist/types.mjs.map +0 -1
  278. package/dist/utils/HttpClient.cjs +0 -2
  279. package/dist/utils/HttpClient.cjs.map +0 -1
  280. package/dist/utils/HttpClient.d.ts +0 -4
  281. package/dist/utils/HttpClient.mjs +0 -2
  282. package/dist/utils/HttpClient.mjs.map +0 -1
  283. package/dist/utils/Logging.cjs +0 -2
  284. package/dist/utils/Logging.cjs.map +0 -1
  285. package/dist/utils/Logging.d.ts +0 -8
  286. package/dist/utils/Logging.mjs +0 -2
  287. package/dist/utils/Logging.mjs.map +0 -1
  288. package/dist/utils/Metadata.cjs +0 -2
  289. package/dist/utils/Metadata.cjs.map +0 -1
  290. package/dist/utils/Metadata.d.ts +0 -98
  291. package/dist/utils/Metadata.mjs +0 -2
  292. package/dist/utils/Metadata.mjs.map +0 -1
  293. package/dist/utils/Session.cjs +0 -2
  294. package/dist/utils/Session.cjs.map +0 -1
  295. package/dist/utils/Session.d.ts +0 -82
  296. package/dist/utils/Session.mjs +0 -2
  297. package/dist/utils/Session.mjs.map +0 -1
  298. package/dist/utils/State.cjs +0 -2
  299. package/dist/utils/State.cjs.map +0 -1
  300. package/dist/utils/State.d.ts +0 -43
  301. package/dist/utils/State.mjs +0 -2
  302. package/dist/utils/State.mjs.map +0 -1
  303. package/dist/utils/base64Url.cjs +0 -2
  304. package/dist/utils/base64Url.cjs.map +0 -1
  305. package/dist/utils/base64Url.d.ts +0 -27
  306. package/dist/utils/base64Url.mjs +0 -2
  307. package/dist/utils/base64Url.mjs.map +0 -1
  308. package/dist/utils/date.cjs +0 -2
  309. package/dist/utils/date.cjs.map +0 -1
  310. package/dist/utils/date.d.ts +0 -6
  311. package/dist/utils/date.mjs +0 -2
  312. package/dist/utils/date.mjs.map +0 -1
  313. package/dist/utils/handlers.cjs +0 -2
  314. package/dist/utils/handlers.cjs.map +0 -1
  315. package/dist/utils/handlers.d.ts +0 -35
  316. package/dist/utils/handlers.mjs +0 -2
  317. package/dist/utils/handlers.mjs.map +0 -1
  318. package/dist/utils/jwt.cjs +0 -2
  319. package/dist/utils/jwt.cjs.map +0 -1
  320. package/dist/utils/jwt.d.ts +0 -34
  321. package/dist/utils/jwt.mjs +0 -2
  322. package/dist/utils/jwt.mjs.map +0 -1
  323. package/dist/utils/object.cjs +0 -2
  324. package/dist/utils/object.cjs.map +0 -1
  325. package/dist/utils/object.d.ts +0 -1
  326. package/dist/utils/object.mjs +0 -2
  327. package/dist/utils/object.mjs.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"file":"handlers.cjs","sources":["../../src/utils/handlers.ts"],"sourcesContent":["import type { RedirectParams, ResponseMode, PopupParams, PopupWindowFeatures } from '../types';\nimport { PopupBlockedError, PopupClosedError } from './errors';\n\nlet popupWindow: WindowProxy | null = null;\n\n/**\n * Handles URL redirection to a target window using a specified location method.\n *\n * @param {string} url The URL to redirect to.\n * @param {RedirectParams} [params] Optional parameters for the redirection, including the target window and location method.\n * @returns {Promise<void>} A promise that resolves when the redirection occurs.\n */\nasync function redirectUrlHandler(url: string, params?: RedirectParams): Promise<void> {\n\tconst targetWindow = params?.targetWindow === 'top' ? window.top : window.self;\n\tconst method = params?.locationMethod || 'assign';\n\n\tif (targetWindow) {\n\t\ttargetWindow.location[method](url);\n\t}\n\n\t// NOTE: Wait for the previous action\n\treturn new Promise((resolve) => resolve());\n}\n\n/**\n * Handles the callback after a redirect and parses the response from the URL.\n *\n * @param {string} [url=globalThis.window?.location.href] The URL to parse, defaults to the current window location.\n * @param {ResponseMode} responseMode The response mode, either 'query' or 'fragment'.\n * @returns {Promise<Record<string, string>>} A promise that resolves to the parsed response data.\n */\nfunction redirectCallbackHandler(url: string = globalThis.window?.location.href, responseMode?: ResponseMode): Promise<Record<string, string>> {\n\tconst data = new URL(url)[responseMode === 'query' ? 'search' : 'hash'].slice(1);\n\n\treturn Promise.resolve(Object.fromEntries(new URLSearchParams(data)));\n}\n\n/**\n * Opens a popup window to handle URL redirection and resolves with the data received from the popup.\n *\n * @param {string} url The URL to redirect to in the popup.\n * @param {PopupParams} [params] Optional parameters for the popup, including window features and target.\n * @param {{ checkOrigin: boolean }} [options] Optional settings for the popup handler.\n * @returns {Promise<Record<string, string>>} A promise that resolves to the data received from the popup window.\n * @throws {Error} If the popup window is blocked or closed by the user.\n */\nasync function popupUrlHandler(\n\tpopupHandlerOrUrl: string | ((popupWindow: Window) => void | Promise<void>),\n\tparams?: PopupParams,\n): Promise<Record<string, string>> {\n\tconst disposables = new Set<() => void>();\n\tconst closeWindow = (): void => {\n\t\tif (popupWindow) {\n\t\t\tif (!popupWindow.closed) {\n\t\t\t\tpopupWindow.close();\n\t\t\t}\n\n\t\t\tpopupWindow = null;\n\t\t}\n\n\t\tfor (const dispose of disposables) {\n\t\t\tdispose();\n\t\t}\n\n\t\tdisposables.clear();\n\t};\n\n\tif (popupWindow) {\n\t\tcloseWindow();\n\t}\n\n\tconst popupWindowFeatures: PopupWindowFeatures = {\n\t\tlocation: false,\n\t\ttoolbar: false,\n\t\theight: 640,\n\t\t...params?.popupWindowFeatures,\n\t};\n\n\tif (popupWindowFeatures.width === undefined) {\n\t\tpopupWindowFeatures.width = [800, 720, 600, 480].find((width) => width <= window.outerWidth / 1.618) ?? 360;\n\t}\n\n\tpopupWindowFeatures.left = Math.max(0, Math.round(window.screenX + (window.outerWidth - popupWindowFeatures.width) / 2));\n\n\tif (popupWindowFeatures.height !== undefined) {\n\t\tpopupWindowFeatures.top = Math.max(0, Math.round(window.screenY + (window.outerHeight - popupWindowFeatures.height) / 2));\n\t}\n\n\tpopupWindow = window.open(\n\t\tundefined,\n\t\tparams?.popupWindowTarget || '_blank',\n\t\tObject.entries(popupWindowFeatures)\n\t\t\t.filter(([, value]) => value !== null)\n\t\t\t.map(([key, value]) => `${key}=${typeof value !== 'boolean' ? (value as string) : value ? 'yes' : 'no'}`)\n\t\t\t.join(','),\n\t);\n\n\tif (!popupWindow) {\n\t\tthrow new PopupBlockedError();\n\t}\n\n\tpopupWindow.focus();\n\n\tif (typeof popupHandlerOrUrl === 'function') {\n\t\tawait popupHandlerOrUrl(popupWindow);\n\t} else {\n\t\tpopupWindow.location.replace(popupHandlerOrUrl);\n\t}\n\n\tconst data = await new Promise<Record<string, string>>((resolve, reject) => {\n\t\tconst listener = (event: MessageEvent<Record<string, string>>) => {\n\t\t\tif ((!params?.checkOrigin || event.origin === window.location.origin) && event.source === popupWindow && event.data) {\n\t\t\t\tresolve(event.data);\n\t\t\t}\n\t\t};\n\n\t\tconst timer = setInterval(() => {\n\t\t\tif (popupWindow?.closed) {\n\t\t\t\tclearInterval(timer);\n\t\t\t\treject(new PopupClosedError());\n\t\t\t}\n\t\t}, 500);\n\n\t\twindow.addEventListener('message', listener);\n\t\tdisposables.add(() => window.removeEventListener('message', listener));\n\t\tdisposables.add(() => clearInterval(timer));\n\t});\n\n\tcloseWindow();\n\n\treturn data;\n}\n\n/**\n * Handles the callback from a popup window, parsing the response parameters from the URL and posting them to the opener window.\n *\n * @param {string} [_url] the URL is not used in this function, but it is kept for type compatibility.\n * @param {ResponseMode} responseMode The response mode, either 'query' or 'fragment'.\n */\nfunction popupCallbackHandler(_url?: string, responseMode?: ResponseMode): Promise<void> {\n\tconst args: Record<string, string> = {};\n\n\tif (responseMode === 'fragment') {\n\t\tnew URLSearchParams(globalThis.window?.location.hash.replace('#', '?')).forEach((value, key) => (args[key] = value));\n\t} else {\n\t\tnew URLSearchParams(globalThis.window?.location.search).forEach((value, key) => (args[key] = value));\n\t}\n\n\tglobalThis.window?.opener?.postMessage(args, '*');\n\n\t// NOTE: Wait for the previous action\n\treturn new Promise(() => undefined);\n}\n\nexport { redirectUrlHandler, redirectCallbackHandler, popupUrlHandler, popupCallbackHandler };\n"],"names":["popupWindow","redirectUrlHandler","url","params","targetWindow","method","resolve","redirectCallbackHandler","responseMode","data","popupUrlHandler","popupHandlerOrUrl","disposables","closeWindow","dispose","popupWindowFeatures","width","value","key","PopupBlockedError","reject","listener","event","timer","PopupClosedError","popupCallbackHandler","_url","args"],"mappings":"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"}
@@ -1,35 +0,0 @@
1
- import { RedirectParams, ResponseMode, PopupParams } from '../types';
2
- /**
3
- * Handles URL redirection to a target window using a specified location method.
4
- *
5
- * @param {string} url The URL to redirect to.
6
- * @param {RedirectParams} [params] Optional parameters for the redirection, including the target window and location method.
7
- * @returns {Promise<void>} A promise that resolves when the redirection occurs.
8
- */
9
- declare function redirectUrlHandler(url: string, params?: RedirectParams): Promise<void>;
10
- /**
11
- * Handles the callback after a redirect and parses the response from the URL.
12
- *
13
- * @param {string} [url=globalThis.window?.location.href] The URL to parse, defaults to the current window location.
14
- * @param {ResponseMode} responseMode The response mode, either 'query' or 'fragment'.
15
- * @returns {Promise<Record<string, string>>} A promise that resolves to the parsed response data.
16
- */
17
- declare function redirectCallbackHandler(url?: string, responseMode?: ResponseMode): Promise<Record<string, string>>;
18
- /**
19
- * Opens a popup window to handle URL redirection and resolves with the data received from the popup.
20
- *
21
- * @param {string} url The URL to redirect to in the popup.
22
- * @param {PopupParams} [params] Optional parameters for the popup, including window features and target.
23
- * @param {{ checkOrigin: boolean }} [options] Optional settings for the popup handler.
24
- * @returns {Promise<Record<string, string>>} A promise that resolves to the data received from the popup window.
25
- * @throws {Error} If the popup window is blocked or closed by the user.
26
- */
27
- declare function popupUrlHandler(popupHandlerOrUrl: string | ((popupWindow: Window) => void | Promise<void>), params?: PopupParams): Promise<Record<string, string>>;
28
- /**
29
- * Handles the callback from a popup window, parsing the response parameters from the URL and posting them to the opener window.
30
- *
31
- * @param {string} [_url] the URL is not used in this function, but it is kept for type compatibility.
32
- * @param {ResponseMode} responseMode The response mode, either 'query' or 'fragment'.
33
- */
34
- declare function popupCallbackHandler(_url?: string, responseMode?: ResponseMode): Promise<void>;
35
- export { redirectUrlHandler, redirectCallbackHandler, popupUrlHandler, popupCallbackHandler };
@@ -1,2 +0,0 @@
1
- import{PopupBlockedError as h,PopupClosedError as f}from"./errors.mjs";let n=null;async function u(r,i){const e=i?.targetWindow==="top"?window.top:window.self,a=i?.locationMethod||"assign";return e&&e.location[a](r),new Promise(o=>o())}function g(r=globalThis.window?.location.href,i){const e=new URL(r)[i==="query"?"search":"hash"].slice(1);return Promise.resolve(Object.fromEntries(new URLSearchParams(e)))}async function m(r,i){const e=new Set,a=()=>{n&&(n.closed||n.close(),n=null);for(const t of e)t();e.clear()};n&&a();const o={location:!1,toolbar:!1,height:640,...i?.popupWindowFeatures};if(o.width===void 0&&(o.width=[800,720,600,480].find(t=>t<=window.outerWidth/1.618)??360),o.left=Math.max(0,Math.round(window.screenX+(window.outerWidth-o.width)/2)),o.height!==void 0&&(o.top=Math.max(0,Math.round(window.screenY+(window.outerHeight-o.height)/2))),n=window.open(void 0,i?.popupWindowTarget||"_blank",Object.entries(o).filter(([,t])=>t!==null).map(([t,s])=>`${t}=${typeof s!="boolean"?s:s?"yes":"no"}`).join(",")),!n)throw new h;n.focus(),typeof r=="function"?await r(n):n.location.replace(r);const w=await new Promise((t,s)=>{const d=c=>{(!i?.checkOrigin||c.origin===window.location.origin)&&c.source===n&&c.data&&t(c.data)},l=setInterval(()=>{n?.closed&&(clearInterval(l),s(new f))},500);window.addEventListener("message",d),e.add(()=>window.removeEventListener("message",d)),e.add(()=>clearInterval(l))});return a(),w}function b(r,i){const e={};return i==="fragment"?new URLSearchParams(globalThis.window?.location.hash.replace("#","?")).forEach((a,o)=>e[o]=a):new URLSearchParams(globalThis.window?.location.search).forEach((a,o)=>e[o]=a),globalThis.window?.opener?.postMessage(e,"*"),new Promise(()=>{})}export{b as popupCallbackHandler,m as popupUrlHandler,g as redirectCallbackHandler,u as redirectUrlHandler};
2
- //# sourceMappingURL=handlers.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"handlers.mjs","sources":["../../src/utils/handlers.ts"],"sourcesContent":["import type { RedirectParams, ResponseMode, PopupParams, PopupWindowFeatures } from '../types';\nimport { PopupBlockedError, PopupClosedError } from './errors';\n\nlet popupWindow: WindowProxy | null = null;\n\n/**\n * Handles URL redirection to a target window using a specified location method.\n *\n * @param {string} url The URL to redirect to.\n * @param {RedirectParams} [params] Optional parameters for the redirection, including the target window and location method.\n * @returns {Promise<void>} A promise that resolves when the redirection occurs.\n */\nasync function redirectUrlHandler(url: string, params?: RedirectParams): Promise<void> {\n\tconst targetWindow = params?.targetWindow === 'top' ? window.top : window.self;\n\tconst method = params?.locationMethod || 'assign';\n\n\tif (targetWindow) {\n\t\ttargetWindow.location[method](url);\n\t}\n\n\t// NOTE: Wait for the previous action\n\treturn new Promise((resolve) => resolve());\n}\n\n/**\n * Handles the callback after a redirect and parses the response from the URL.\n *\n * @param {string} [url=globalThis.window?.location.href] The URL to parse, defaults to the current window location.\n * @param {ResponseMode} responseMode The response mode, either 'query' or 'fragment'.\n * @returns {Promise<Record<string, string>>} A promise that resolves to the parsed response data.\n */\nfunction redirectCallbackHandler(url: string = globalThis.window?.location.href, responseMode?: ResponseMode): Promise<Record<string, string>> {\n\tconst data = new URL(url)[responseMode === 'query' ? 'search' : 'hash'].slice(1);\n\n\treturn Promise.resolve(Object.fromEntries(new URLSearchParams(data)));\n}\n\n/**\n * Opens a popup window to handle URL redirection and resolves with the data received from the popup.\n *\n * @param {string} url The URL to redirect to in the popup.\n * @param {PopupParams} [params] Optional parameters for the popup, including window features and target.\n * @param {{ checkOrigin: boolean }} [options] Optional settings for the popup handler.\n * @returns {Promise<Record<string, string>>} A promise that resolves to the data received from the popup window.\n * @throws {Error} If the popup window is blocked or closed by the user.\n */\nasync function popupUrlHandler(\n\tpopupHandlerOrUrl: string | ((popupWindow: Window) => void | Promise<void>),\n\tparams?: PopupParams,\n): Promise<Record<string, string>> {\n\tconst disposables = new Set<() => void>();\n\tconst closeWindow = (): void => {\n\t\tif (popupWindow) {\n\t\t\tif (!popupWindow.closed) {\n\t\t\t\tpopupWindow.close();\n\t\t\t}\n\n\t\t\tpopupWindow = null;\n\t\t}\n\n\t\tfor (const dispose of disposables) {\n\t\t\tdispose();\n\t\t}\n\n\t\tdisposables.clear();\n\t};\n\n\tif (popupWindow) {\n\t\tcloseWindow();\n\t}\n\n\tconst popupWindowFeatures: PopupWindowFeatures = {\n\t\tlocation: false,\n\t\ttoolbar: false,\n\t\theight: 640,\n\t\t...params?.popupWindowFeatures,\n\t};\n\n\tif (popupWindowFeatures.width === undefined) {\n\t\tpopupWindowFeatures.width = [800, 720, 600, 480].find((width) => width <= window.outerWidth / 1.618) ?? 360;\n\t}\n\n\tpopupWindowFeatures.left = Math.max(0, Math.round(window.screenX + (window.outerWidth - popupWindowFeatures.width) / 2));\n\n\tif (popupWindowFeatures.height !== undefined) {\n\t\tpopupWindowFeatures.top = Math.max(0, Math.round(window.screenY + (window.outerHeight - popupWindowFeatures.height) / 2));\n\t}\n\n\tpopupWindow = window.open(\n\t\tundefined,\n\t\tparams?.popupWindowTarget || '_blank',\n\t\tObject.entries(popupWindowFeatures)\n\t\t\t.filter(([, value]) => value !== null)\n\t\t\t.map(([key, value]) => `${key}=${typeof value !== 'boolean' ? (value as string) : value ? 'yes' : 'no'}`)\n\t\t\t.join(','),\n\t);\n\n\tif (!popupWindow) {\n\t\tthrow new PopupBlockedError();\n\t}\n\n\tpopupWindow.focus();\n\n\tif (typeof popupHandlerOrUrl === 'function') {\n\t\tawait popupHandlerOrUrl(popupWindow);\n\t} else {\n\t\tpopupWindow.location.replace(popupHandlerOrUrl);\n\t}\n\n\tconst data = await new Promise<Record<string, string>>((resolve, reject) => {\n\t\tconst listener = (event: MessageEvent<Record<string, string>>) => {\n\t\t\tif ((!params?.checkOrigin || event.origin === window.location.origin) && event.source === popupWindow && event.data) {\n\t\t\t\tresolve(event.data);\n\t\t\t}\n\t\t};\n\n\t\tconst timer = setInterval(() => {\n\t\t\tif (popupWindow?.closed) {\n\t\t\t\tclearInterval(timer);\n\t\t\t\treject(new PopupClosedError());\n\t\t\t}\n\t\t}, 500);\n\n\t\twindow.addEventListener('message', listener);\n\t\tdisposables.add(() => window.removeEventListener('message', listener));\n\t\tdisposables.add(() => clearInterval(timer));\n\t});\n\n\tcloseWindow();\n\n\treturn data;\n}\n\n/**\n * Handles the callback from a popup window, parsing the response parameters from the URL and posting them to the opener window.\n *\n * @param {string} [_url] the URL is not used in this function, but it is kept for type compatibility.\n * @param {ResponseMode} responseMode The response mode, either 'query' or 'fragment'.\n */\nfunction popupCallbackHandler(_url?: string, responseMode?: ResponseMode): Promise<void> {\n\tconst args: Record<string, string> = {};\n\n\tif (responseMode === 'fragment') {\n\t\tnew URLSearchParams(globalThis.window?.location.hash.replace('#', '?')).forEach((value, key) => (args[key] = value));\n\t} else {\n\t\tnew URLSearchParams(globalThis.window?.location.search).forEach((value, key) => (args[key] = value));\n\t}\n\n\tglobalThis.window?.opener?.postMessage(args, '*');\n\n\t// NOTE: Wait for the previous action\n\treturn new Promise(() => undefined);\n}\n\nexport { redirectUrlHandler, redirectCallbackHandler, popupUrlHandler, popupCallbackHandler };\n"],"names":["popupWindow","redirectUrlHandler","url","params","targetWindow","method","resolve","redirectCallbackHandler","responseMode","data","popupUrlHandler","popupHandlerOrUrl","disposables","closeWindow","dispose","popupWindowFeatures","width","value","key","PopupBlockedError","reject","listener","event","timer","PopupClosedError","popupCallbackHandler","_url","args"],"mappings":"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"}
@@ -1,2 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("./base64Url.cjs");function i(o){const e=o.split(".");if(e.length!==3)throw new Error("Invalid JWT");return JSON.parse(n.Base64Url.decodeUnicode(e[1]))}async function l(o,e,t){const c=n.Base64Url.encode(new TextEncoder().encode(JSON.stringify(o))),d=n.Base64Url.encode(new TextEncoder().encode(JSON.stringify(e))),r=`${c}.${d}`,s=await window.crypto.subtle.sign({name:"ECDSA",hash:{name:"SHA-256"}},t,new TextEncoder().encode(r)),a=n.Base64Url.encode(new Uint8Array(s));return`${r}.${a}`}function u(o,e){const t=n.Base64Url.encode(new TextEncoder().encode(JSON.stringify(o))),c=n.Base64Url.encode(new TextEncoder().encode(JSON.stringify(e)));return`${`${t}.${c}`}.signature`}const g={decode:i,generate:l,generateUnsigned:u};exports.jwt=g;
2
- //# sourceMappingURL=jwt.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"jwt.cjs","sources":["../../src/utils/jwt.ts"],"sourcesContent":["import type { JwtClaims } from '../types';\nimport { Base64Url } from './base64Url';\n\n/**\n * Decodes a JWT token and returns its claims.\n *\n * @template R The expected structure of the JWT claims.\n * @param {string} token The JWT token to decode.\n * @returns {R} The decoded JWT claims.\n * @throws {Error} If the token is invalid or has the wrong format.\n */\nfunction decode<R = JwtClaims>(token: string): R {\n\tconst sections = token.split('.');\n\n\tif (sections.length !== 3) {\n\t\tthrow new Error('Invalid JWT');\n\t}\n\n\treturn JSON.parse(Base64Url.decodeUnicode(sections[1])) as R;\n}\n\n/**\n * Generates a signed JWT token using the provided header, payload, and private key.\n *\n * @param {object} header The JWT header.\n * @param {object} payload The JWT payload.\n * @param {CryptoKey} privateKey The private key to sign the JWT.\n * @returns {Promise<string>} A promise that resolves to the signed JWT token.\n */\nasync function generate(header: object, payload: object, privateKey: CryptoKey): Promise<string> {\n\tconst encodedHeader = Base64Url.encode(new TextEncoder().encode(JSON.stringify(header)));\n\tconst encodedPayload = Base64Url.encode(new TextEncoder().encode(JSON.stringify(payload)));\n\tconst encodedToken = `${encodedHeader}.${encodedPayload}`;\n\n\tconst signature = await window.crypto.subtle.sign(\n\t\t{\n\t\t\tname: 'ECDSA',\n\t\t\thash: { name: 'SHA-256' },\n\t\t},\n\t\tprivateKey,\n\t\tnew TextEncoder().encode(encodedToken),\n\t);\n\n\tconst encodedSignature = Base64Url.encode(new Uint8Array(signature));\n\treturn `${encodedToken}.${encodedSignature}`;\n}\n\n/**\n * Generates an unsigned JWT token using the provided header and payload.\n * The token will not include a valid signature.\n *\n * @param {object} header The JWT header.\n * @param {object} payload The JWT payload.\n * @returns {string} The unsigned JWT token.\n */\nfunction generateUnsigned(header: object, payload: object): string {\n\tconst encodedHeader = Base64Url.encode(new TextEncoder().encode(JSON.stringify(header)));\n\tconst encodedPayload = Base64Url.encode(new TextEncoder().encode(JSON.stringify(payload)));\n\tconst encodedToken = `${encodedHeader}.${encodedPayload}`;\n\n\treturn `${encodedToken}.signature`;\n}\n\nexport const jwt = {\n\tdecode,\n\tgenerate,\n\tgenerateUnsigned,\n};\n"],"names":["decode","token","sections","Base64Url","generate","header","payload","privateKey","encodedHeader","encodedPayload","encodedToken","signature","encodedSignature","generateUnsigned","jwt"],"mappings":"mHAWA,SAASA,EAAsBC,EAAkB,CAChD,MAAMC,EAAWD,EAAM,MAAM,GAAG,EAEhC,GAAIC,EAAS,SAAW,EACvB,MAAM,IAAI,MAAM,aAAa,EAG9B,OAAO,KAAK,MAAMC,EAAAA,UAAU,cAAcD,EAAS,CAAC,CAAC,CAAC,CACvD,CAUA,eAAeE,EAASC,EAAgBC,EAAiBC,EAAwC,CAChG,MAAMC,EAAgBL,EAAAA,UAAU,OAAO,IAAI,YAAA,EAAc,OAAO,KAAK,UAAUE,CAAM,CAAC,CAAC,EACjFI,EAAiBN,EAAAA,UAAU,OAAO,IAAI,YAAA,EAAc,OAAO,KAAK,UAAUG,CAAO,CAAC,CAAC,EACnFI,EAAe,GAAGF,CAAa,IAAIC,CAAc,GAEjDE,EAAY,MAAM,OAAO,OAAO,OAAO,KAC5C,CACC,KAAM,QACN,KAAM,CAAE,KAAM,SAAA,CAAU,EAEzBJ,EACA,IAAI,YAAA,EAAc,OAAOG,CAAY,CAAA,EAGhCE,EAAmBT,EAAAA,UAAU,OAAO,IAAI,WAAWQ,CAAS,CAAC,EACnE,MAAO,GAAGD,CAAY,IAAIE,CAAgB,EAC3C,CAUA,SAASC,EAAiBR,EAAgBC,EAAyB,CAClE,MAAME,EAAgBL,EAAAA,UAAU,OAAO,IAAI,YAAA,EAAc,OAAO,KAAK,UAAUE,CAAM,CAAC,CAAC,EACjFI,EAAiBN,EAAAA,UAAU,OAAO,IAAI,YAAA,EAAc,OAAO,KAAK,UAAUG,CAAO,CAAC,CAAC,EAGzF,MAAO,GAFc,GAAGE,CAAa,IAAIC,CAAc,EAEjC,YACvB,CAEO,MAAMK,EAAM,CAClB,OAAAd,EACA,SAAAI,EACA,iBAAAS,CACD"}
@@ -1,34 +0,0 @@
1
- import { JwtClaims } from '../types';
2
- /**
3
- * Decodes a JWT token and returns its claims.
4
- *
5
- * @template R The expected structure of the JWT claims.
6
- * @param {string} token The JWT token to decode.
7
- * @returns {R} The decoded JWT claims.
8
- * @throws {Error} If the token is invalid or has the wrong format.
9
- */
10
- declare function decode<R = JwtClaims>(token: string): R;
11
- /**
12
- * Generates a signed JWT token using the provided header, payload, and private key.
13
- *
14
- * @param {object} header The JWT header.
15
- * @param {object} payload The JWT payload.
16
- * @param {CryptoKey} privateKey The private key to sign the JWT.
17
- * @returns {Promise<string>} A promise that resolves to the signed JWT token.
18
- */
19
- declare function generate(header: object, payload: object, privateKey: CryptoKey): Promise<string>;
20
- /**
21
- * Generates an unsigned JWT token using the provided header and payload.
22
- * The token will not include a valid signature.
23
- *
24
- * @param {object} header The JWT header.
25
- * @param {object} payload The JWT payload.
26
- * @returns {string} The unsigned JWT token.
27
- */
28
- declare function generateUnsigned(header: object, payload: object): string;
29
- export declare const jwt: {
30
- decode: typeof decode;
31
- generate: typeof generate;
32
- generateUnsigned: typeof generateUnsigned;
33
- };
34
- export {};
@@ -1,2 +0,0 @@
1
- import{Base64Url as n}from"./base64Url.mjs";function a(o){const e=o.split(".");if(e.length!==3)throw new Error("Invalid JWT");return JSON.parse(n.decodeUnicode(e[1]))}async function g(o,e,d){const c=n.encode(new TextEncoder().encode(JSON.stringify(o))),t=n.encode(new TextEncoder().encode(JSON.stringify(e))),r=`${c}.${t}`,s=await window.crypto.subtle.sign({name:"ECDSA",hash:{name:"SHA-256"}},d,new TextEncoder().encode(r)),i=n.encode(new Uint8Array(s));return`${r}.${i}`}function w(o,e){const d=n.encode(new TextEncoder().encode(JSON.stringify(o))),c=n.encode(new TextEncoder().encode(JSON.stringify(e)));return`${`${d}.${c}`}.signature`}const f={decode:a,generate:g,generateUnsigned:w};export{f as jwt};
2
- //# sourceMappingURL=jwt.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"jwt.mjs","sources":["../../src/utils/jwt.ts"],"sourcesContent":["import type { JwtClaims } from '../types';\nimport { Base64Url } from './base64Url';\n\n/**\n * Decodes a JWT token and returns its claims.\n *\n * @template R The expected structure of the JWT claims.\n * @param {string} token The JWT token to decode.\n * @returns {R} The decoded JWT claims.\n * @throws {Error} If the token is invalid or has the wrong format.\n */\nfunction decode<R = JwtClaims>(token: string): R {\n\tconst sections = token.split('.');\n\n\tif (sections.length !== 3) {\n\t\tthrow new Error('Invalid JWT');\n\t}\n\n\treturn JSON.parse(Base64Url.decodeUnicode(sections[1])) as R;\n}\n\n/**\n * Generates a signed JWT token using the provided header, payload, and private key.\n *\n * @param {object} header The JWT header.\n * @param {object} payload The JWT payload.\n * @param {CryptoKey} privateKey The private key to sign the JWT.\n * @returns {Promise<string>} A promise that resolves to the signed JWT token.\n */\nasync function generate(header: object, payload: object, privateKey: CryptoKey): Promise<string> {\n\tconst encodedHeader = Base64Url.encode(new TextEncoder().encode(JSON.stringify(header)));\n\tconst encodedPayload = Base64Url.encode(new TextEncoder().encode(JSON.stringify(payload)));\n\tconst encodedToken = `${encodedHeader}.${encodedPayload}`;\n\n\tconst signature = await window.crypto.subtle.sign(\n\t\t{\n\t\t\tname: 'ECDSA',\n\t\t\thash: { name: 'SHA-256' },\n\t\t},\n\t\tprivateKey,\n\t\tnew TextEncoder().encode(encodedToken),\n\t);\n\n\tconst encodedSignature = Base64Url.encode(new Uint8Array(signature));\n\treturn `${encodedToken}.${encodedSignature}`;\n}\n\n/**\n * Generates an unsigned JWT token using the provided header and payload.\n * The token will not include a valid signature.\n *\n * @param {object} header The JWT header.\n * @param {object} payload The JWT payload.\n * @returns {string} The unsigned JWT token.\n */\nfunction generateUnsigned(header: object, payload: object): string {\n\tconst encodedHeader = Base64Url.encode(new TextEncoder().encode(JSON.stringify(header)));\n\tconst encodedPayload = Base64Url.encode(new TextEncoder().encode(JSON.stringify(payload)));\n\tconst encodedToken = `${encodedHeader}.${encodedPayload}`;\n\n\treturn `${encodedToken}.signature`;\n}\n\nexport const jwt = {\n\tdecode,\n\tgenerate,\n\tgenerateUnsigned,\n};\n"],"names":["decode","token","sections","Base64Url","generate","header","payload","privateKey","encodedHeader","encodedPayload","encodedToken","signature","encodedSignature","generateUnsigned","jwt"],"mappings":"4CAWA,SAASA,EAAsBC,EAAkB,CAChD,MAAMC,EAAWD,EAAM,MAAM,GAAG,EAEhC,GAAIC,EAAS,SAAW,EACvB,MAAM,IAAI,MAAM,aAAa,EAG9B,OAAO,KAAK,MAAMC,EAAU,cAAcD,EAAS,CAAC,CAAC,CAAC,CACvD,CAUA,eAAeE,EAASC,EAAgBC,EAAiBC,EAAwC,CAChG,MAAMC,EAAgBL,EAAU,OAAO,IAAI,YAAA,EAAc,OAAO,KAAK,UAAUE,CAAM,CAAC,CAAC,EACjFI,EAAiBN,EAAU,OAAO,IAAI,YAAA,EAAc,OAAO,KAAK,UAAUG,CAAO,CAAC,CAAC,EACnFI,EAAe,GAAGF,CAAa,IAAIC,CAAc,GAEjDE,EAAY,MAAM,OAAO,OAAO,OAAO,KAC5C,CACC,KAAM,QACN,KAAM,CAAE,KAAM,SAAA,CAAU,EAEzBJ,EACA,IAAI,YAAA,EAAc,OAAOG,CAAY,CAAA,EAGhCE,EAAmBT,EAAU,OAAO,IAAI,WAAWQ,CAAS,CAAC,EACnE,MAAO,GAAGD,CAAY,IAAIE,CAAgB,EAC3C,CAUA,SAASC,EAAiBR,EAAgBC,EAAyB,CAClE,MAAME,EAAgBL,EAAU,OAAO,IAAI,YAAA,EAAc,OAAO,KAAK,UAAUE,CAAM,CAAC,CAAC,EACjFI,EAAiBN,EAAU,OAAO,IAAI,YAAA,EAAc,OAAO,KAAK,UAAUG,CAAO,CAAC,CAAC,EAGzF,MAAO,GAFc,GAAGE,CAAa,IAAIC,CAAc,EAEjC,YACvB,CAEO,MAAMK,EAAM,CAClB,OAAAd,EACA,SAAAI,EACA,iBAAAS,CACD"}
@@ -1,2 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function l(n){const o={};for(const s in n){const u=s.split(".");u.reduce((e,t,i)=>(i===u.length-1?e[t]=n[s]:e[t]=e[t]||{},e[t]),o)}return o}exports.unflattenObject=l;
2
- //# sourceMappingURL=object.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"object.cjs","sources":["../../src/utils/object.ts"],"sourcesContent":["export function unflattenObject(flatObject: Record<string, unknown>): Record<string, unknown> {\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tconst nestedObject: Record<string, any> = {};\n\n\tfor (const key in flatObject) {\n\t\tconst keys = key.split('.');\n\n\t\tkeys.reduce((acc, part, index) => {\n\t\t\tif (index === keys.length - 1) {\n\t\t\t\tacc[part] = flatObject[key];\n\t\t\t} else {\n\t\t\t\tacc[part] = acc[part] || {};\n\t\t\t}\n\n\t\t\treturn acc[part];\n\t\t}, nestedObject);\n\t}\n\n\treturn nestedObject;\n}\n"],"names":["unflattenObject","flatObject","nestedObject","key","keys","acc","part","index"],"mappings":"gFAAO,SAASA,EAAgBC,EAA8D,CAE7F,MAAMC,EAAoC,CAAA,EAE1C,UAAWC,KAAOF,EAAY,CAC7B,MAAMG,EAAOD,EAAI,MAAM,GAAG,EAE1BC,EAAK,OAAO,CAACC,EAAKC,EAAMC,KACnBA,IAAUH,EAAK,OAAS,EAC3BC,EAAIC,CAAI,EAAIL,EAAWE,CAAG,EAE1BE,EAAIC,CAAI,EAAID,EAAIC,CAAI,GAAK,CAAA,EAGnBD,EAAIC,CAAI,GACbJ,CAAY,CAChB,CAEA,OAAOA,CACR"}
@@ -1 +0,0 @@
1
- export declare function unflattenObject(flatObject: Record<string, unknown>): Record<string, unknown>;
@@ -1,2 +0,0 @@
1
- function r(t){const s={};for(const o in t){const u=o.split(".");u.reduce((e,n,i)=>(i===u.length-1?e[n]=t[o]:e[n]=e[n]||{},e[n]),s)}return s}export{r as unflattenObject};
2
- //# sourceMappingURL=object.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"object.mjs","sources":["../../src/utils/object.ts"],"sourcesContent":["export function unflattenObject(flatObject: Record<string, unknown>): Record<string, unknown> {\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tconst nestedObject: Record<string, any> = {};\n\n\tfor (const key in flatObject) {\n\t\tconst keys = key.split('.');\n\n\t\tkeys.reduce((acc, part, index) => {\n\t\t\tif (index === keys.length - 1) {\n\t\t\t\tacc[part] = flatObject[key];\n\t\t\t} else {\n\t\t\t\tacc[part] = acc[part] || {};\n\t\t\t}\n\n\t\t\treturn acc[part];\n\t\t}, nestedObject);\n\t}\n\n\treturn nestedObject;\n}\n"],"names":["unflattenObject","flatObject","nestedObject","key","keys","acc","part","index"],"mappings":"AAAO,SAASA,EAAgBC,EAA8D,CAE7F,MAAMC,EAAoC,CAAA,EAE1C,UAAWC,KAAOF,EAAY,CAC7B,MAAMG,EAAOD,EAAI,MAAM,GAAG,EAE1BC,EAAK,OAAO,CAACC,EAAKC,EAAMC,KACnBA,IAAUH,EAAK,OAAS,EAC3BC,EAAIC,CAAI,EAAIL,EAAWE,CAAG,EAE1BE,EAAIC,CAAI,EAAID,EAAIC,CAAI,GAAK,CAAA,EAGnBD,EAAIC,CAAI,GACbJ,CAAY,CAChB,CAEA,OAAOA,CACR"}