@stackframe/stack-shared 2.8.8 → 2.8.11

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 (476) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/config/format.d.cts +39 -0
  3. package/dist/config/format.d.ts +14 -13
  4. package/dist/config/format.js +147 -206
  5. package/dist/config/format.js.map +1 -0
  6. package/dist/config/schema.d.cts +729 -0
  7. package/dist/config/schema.d.ts +59 -51
  8. package/dist/config/schema.js +232 -172
  9. package/dist/config/schema.js.map +1 -0
  10. package/dist/crud.d.cts +102 -0
  11. package/dist/crud.d.ts +15 -13
  12. package/dist/crud.js +83 -128
  13. package/dist/crud.js.map +1 -0
  14. package/dist/esm/config/format.js +135 -0
  15. package/dist/esm/config/format.js.map +1 -0
  16. package/dist/esm/config/schema.js +201 -0
  17. package/dist/esm/config/schema.js.map +1 -0
  18. package/dist/esm/crud.js +60 -0
  19. package/dist/esm/crud.js.map +1 -0
  20. package/dist/esm/global.d.js +1 -0
  21. package/dist/esm/global.d.js.map +1 -0
  22. package/dist/esm/helpers/password.js +17 -0
  23. package/dist/esm/helpers/password.js.map +1 -0
  24. package/dist/esm/helpers/production-mode.js +50 -0
  25. package/dist/esm/helpers/production-mode.js.map +1 -0
  26. package/dist/esm/hooks/use-async-callback.js +38 -0
  27. package/dist/esm/hooks/use-async-callback.js.map +1 -0
  28. package/dist/esm/hooks/use-async-external-store.js +23 -0
  29. package/dist/esm/hooks/use-async-external-store.js.map +1 -0
  30. package/dist/esm/hooks/use-hash.js +17 -0
  31. package/dist/esm/hooks/use-hash.js.map +1 -0
  32. package/dist/esm/hooks/use-strict-memo.js +61 -0
  33. package/dist/esm/hooks/use-strict-memo.js.map +1 -0
  34. package/dist/esm/index.js +22 -0
  35. package/dist/esm/index.js.map +1 -0
  36. package/dist/esm/interface/adminInterface.js +244 -0
  37. package/dist/esm/interface/adminInterface.js.map +1 -0
  38. package/dist/esm/interface/clientInterface.js +2041 -0
  39. package/dist/esm/interface/clientInterface.js.map +1 -0
  40. package/dist/esm/interface/crud/contact-channels.js +77 -0
  41. package/dist/esm/interface/crud/contact-channels.js.map +1 -0
  42. package/dist/esm/interface/crud/current-user.js +65 -0
  43. package/dist/esm/interface/crud/current-user.js.map +1 -0
  44. package/dist/esm/interface/crud/email-templates.js +52 -0
  45. package/dist/esm/interface/crud/email-templates.js.map +1 -0
  46. package/dist/esm/interface/crud/emails.js +20 -0
  47. package/dist/esm/interface/crud/emails.js.map +1 -0
  48. package/dist/esm/interface/crud/internal-api-keys.js +69 -0
  49. package/dist/esm/interface/crud/internal-api-keys.js.map +1 -0
  50. package/dist/esm/interface/crud/oauth.js +24 -0
  51. package/dist/esm/interface/crud/oauth.js.map +1 -0
  52. package/dist/esm/interface/crud/project-api-keys.js +93 -0
  53. package/dist/esm/interface/crud/project-api-keys.js.map +1 -0
  54. package/dist/esm/interface/crud/project-permissions.js +113 -0
  55. package/dist/esm/interface/crud/project-permissions.js.map +1 -0
  56. package/dist/esm/interface/crud/projects.js +180 -0
  57. package/dist/esm/interface/crud/projects.js.map +1 -0
  58. package/dist/esm/interface/crud/sessions.js +62 -0
  59. package/dist/esm/interface/crud/sessions.js.map +1 -0
  60. package/dist/esm/interface/crud/svix-token.js +22 -0
  61. package/dist/esm/interface/crud/svix-token.js.map +1 -0
  62. package/dist/esm/interface/crud/team-invitation-details.js +23 -0
  63. package/dist/esm/interface/crud/team-invitation-details.js.map +1 -0
  64. package/dist/esm/interface/crud/team-invitation.js +36 -0
  65. package/dist/esm/interface/crud/team-invitation.js.map +1 -0
  66. package/dist/esm/interface/crud/team-member-profiles.js +62 -0
  67. package/dist/esm/interface/crud/team-member-profiles.js.map +1 -0
  68. package/dist/esm/interface/crud/team-memberships.js +60 -0
  69. package/dist/esm/interface/crud/team-memberships.js.map +1 -0
  70. package/dist/esm/interface/crud/team-permissions.js +114 -0
  71. package/dist/esm/interface/crud/team-permissions.js.map +1 -0
  72. package/dist/esm/interface/crud/teams.js +143 -0
  73. package/dist/esm/interface/crud/teams.js.map +1 -0
  74. package/dist/esm/interface/crud/users.js +139 -0
  75. package/dist/esm/interface/crud/users.js.map +1 -0
  76. package/dist/esm/interface/serverInterface.js +485 -0
  77. package/dist/esm/interface/serverInterface.js.map +1 -0
  78. package/dist/esm/interface/webhooks.js +21 -0
  79. package/dist/esm/interface/webhooks.js.map +1 -0
  80. package/dist/esm/known-errors.js +1238 -0
  81. package/dist/esm/known-errors.js.map +1 -0
  82. package/dist/esm/schema-fields.js +484 -0
  83. package/dist/esm/schema-fields.js.map +1 -0
  84. package/dist/esm/sessions.js +168 -0
  85. package/dist/esm/sessions.js.map +1 -0
  86. package/dist/esm/utils/api-keys.js +79 -0
  87. package/dist/esm/utils/api-keys.js.map +1 -0
  88. package/dist/esm/utils/arrays.js +78 -0
  89. package/dist/esm/utils/arrays.js.map +1 -0
  90. package/dist/esm/utils/base64.js +18 -0
  91. package/dist/esm/utils/base64.js.map +1 -0
  92. package/dist/esm/utils/booleans.js +12 -0
  93. package/dist/esm/utils/booleans.js.map +1 -0
  94. package/dist/esm/utils/browser-compat.js +21 -0
  95. package/dist/esm/utils/browser-compat.js.map +1 -0
  96. package/dist/esm/utils/bytes.js +160 -0
  97. package/dist/esm/utils/bytes.js.map +1 -0
  98. package/dist/esm/utils/caches.js +167 -0
  99. package/dist/esm/utils/caches.js.map +1 -0
  100. package/dist/esm/utils/compile-time.js +11 -0
  101. package/dist/esm/utils/compile-time.js.map +1 -0
  102. package/dist/esm/utils/crypto.js +25 -0
  103. package/dist/esm/utils/crypto.js.map +1 -0
  104. package/dist/esm/utils/dates.js +64 -0
  105. package/dist/esm/utils/dates.js.map +1 -0
  106. package/dist/esm/utils/dom.js +11 -0
  107. package/dist/esm/utils/dom.js.map +1 -0
  108. package/dist/esm/utils/env.js +58 -0
  109. package/dist/esm/utils/env.js.map +1 -0
  110. package/dist/esm/utils/errors.js +174 -0
  111. package/dist/esm/utils/errors.js.map +1 -0
  112. package/dist/esm/utils/fs.js +37 -0
  113. package/dist/esm/utils/fs.js.map +1 -0
  114. package/dist/esm/utils/functions.js +12 -0
  115. package/dist/esm/utils/functions.js.map +1 -0
  116. package/dist/esm/utils/geo.js +15 -0
  117. package/dist/esm/utils/geo.js.map +1 -0
  118. package/dist/esm/utils/globals.js +18 -0
  119. package/dist/esm/utils/globals.js.map +1 -0
  120. package/dist/esm/utils/hashes.js +55 -0
  121. package/dist/esm/utils/hashes.js.map +1 -0
  122. package/dist/esm/utils/html.js +13 -0
  123. package/dist/esm/utils/html.js.map +1 -0
  124. package/dist/esm/utils/http.js +60 -0
  125. package/dist/esm/utils/http.js.map +1 -0
  126. package/dist/esm/utils/ips.js +15 -0
  127. package/dist/esm/utils/ips.js.map +1 -0
  128. package/dist/esm/utils/json.js +31 -0
  129. package/dist/esm/utils/json.js.map +1 -0
  130. package/dist/esm/utils/jwt.js +87 -0
  131. package/dist/esm/utils/jwt.js.map +1 -0
  132. package/dist/esm/utils/locks.js +57 -0
  133. package/dist/esm/utils/locks.js.map +1 -0
  134. package/dist/esm/utils/maps.js +181 -0
  135. package/dist/esm/utils/maps.js.map +1 -0
  136. package/dist/esm/utils/math.js +8 -0
  137. package/dist/esm/utils/math.js.map +1 -0
  138. package/dist/esm/utils/node-http.js +42 -0
  139. package/dist/esm/utils/node-http.js.map +1 -0
  140. package/dist/esm/utils/numbers.js +32 -0
  141. package/dist/esm/utils/numbers.js.map +1 -0
  142. package/dist/esm/utils/oauth.js +10 -0
  143. package/dist/esm/utils/oauth.js.map +1 -0
  144. package/dist/esm/utils/objects.js +177 -0
  145. package/dist/esm/utils/objects.js.map +1 -0
  146. package/dist/esm/utils/passkey.js +1 -0
  147. package/dist/esm/utils/passkey.js.map +1 -0
  148. package/dist/esm/utils/promises.js +233 -0
  149. package/dist/esm/utils/promises.js.map +1 -0
  150. package/dist/esm/utils/proxies.js +128 -0
  151. package/dist/esm/utils/proxies.js.map +1 -0
  152. package/dist/esm/utils/react.js +78 -0
  153. package/dist/esm/utils/react.js.map +1 -0
  154. package/dist/esm/utils/results.js +141 -0
  155. package/dist/esm/utils/results.js.map +1 -0
  156. package/dist/esm/utils/sentry.js +20 -0
  157. package/dist/esm/utils/sentry.js.map +1 -0
  158. package/dist/esm/utils/stores.js +195 -0
  159. package/dist/esm/utils/stores.js.map +1 -0
  160. package/dist/esm/utils/strings.js +295 -0
  161. package/dist/esm/utils/strings.js.map +1 -0
  162. package/dist/esm/utils/strings.nicify.test.js +222 -0
  163. package/dist/esm/utils/strings.nicify.test.js.map +1 -0
  164. package/dist/esm/utils/types.js +1 -0
  165. package/dist/esm/utils/types.js.map +1 -0
  166. package/dist/esm/utils/unicode.js +11 -0
  167. package/dist/esm/utils/unicode.js.map +1 -0
  168. package/dist/esm/utils/urls.js +53 -0
  169. package/dist/esm/utils/urls.js.map +1 -0
  170. package/dist/esm/utils/uuids.js +16 -0
  171. package/dist/esm/utils/uuids.js.map +1 -0
  172. package/dist/global.d.d.cts +1 -0
  173. package/dist/global.d.d.ts +1 -0
  174. package/dist/global.d.js +2 -0
  175. package/dist/global.d.js.map +1 -0
  176. package/dist/helpers/password.d.cts +11 -0
  177. package/dist/helpers/password.d.ts +11 -2
  178. package/dist/helpers/password.js +41 -11
  179. package/dist/helpers/password.js.map +1 -0
  180. package/dist/helpers/production-mode.d.cts +12 -0
  181. package/dist/helpers/production-mode.d.ts +9 -3
  182. package/dist/helpers/production-mode.js +72 -45
  183. package/dist/helpers/production-mode.js.map +1 -0
  184. package/dist/hooks/use-async-callback.d.cts +6 -0
  185. package/dist/hooks/use-async-callback.d.ts +6 -3
  186. package/dist/hooks/use-async-callback.js +72 -30
  187. package/dist/hooks/use-async-callback.js.map +1 -0
  188. package/dist/hooks/use-async-external-store.d.cts +7 -0
  189. package/dist/hooks/use-async-external-store.d.ts +5 -2
  190. package/dist/hooks/use-async-external-store.js +47 -19
  191. package/dist/hooks/use-async-external-store.js.map +1 -0
  192. package/dist/hooks/use-hash.d.cts +3 -0
  193. package/dist/hooks/use-hash.d.ts +3 -1
  194. package/dist/hooks/use-hash.js +41 -8
  195. package/dist/hooks/use-hash.js.map +1 -0
  196. package/dist/hooks/use-strict-memo.d.cts +8 -0
  197. package/dist/hooks/use-strict-memo.d.ts +3 -1
  198. package/dist/hooks/use-strict-memo.js +78 -131
  199. package/dist/hooks/use-strict-memo.js.map +1 -0
  200. package/dist/index.d.cts +30 -0
  201. package/dist/index.d.ts +30 -4
  202. package/dist/index.js +42 -4
  203. package/dist/index.js.map +1 -0
  204. package/dist/interface/adminInterface.d.cts +94 -0
  205. package/dist/interface/adminInterface.d.ts +38 -15
  206. package/dist/interface/adminInterface.js +269 -174
  207. package/dist/interface/adminInterface.js.map +1 -0
  208. package/dist/interface/clientInterface.d.cts +260 -0
  209. package/dist/interface/clientInterface.d.ts +25 -18
  210. package/dist/interface/clientInterface.js +2054 -995
  211. package/dist/interface/clientInterface.js.map +1 -0
  212. package/dist/interface/crud/contact-channels.d.cts +180 -0
  213. package/dist/interface/crud/contact-channels.d.ts +30 -25
  214. package/dist/interface/crud/contact-channels.js +101 -59
  215. package/dist/interface/crud/contact-channels.js.map +1 -0
  216. package/dist/interface/crud/current-user.d.cts +205 -0
  217. package/dist/interface/crud/current-user.d.ts +17 -12
  218. package/dist/interface/crud/current-user.js +86 -56
  219. package/dist/interface/crud/current-user.js.map +1 -0
  220. package/dist/interface/crud/email-templates.d.cts +84 -0
  221. package/dist/interface/crud/email-templates.d.ts +24 -19
  222. package/dist/interface/crud/email-templates.js +77 -37
  223. package/dist/interface/crud/email-templates.js.map +1 -0
  224. package/dist/interface/crud/emails.d.cts +69 -0
  225. package/dist/interface/crud/emails.d.ts +12 -7
  226. package/dist/interface/crud/emails.js +54 -12
  227. package/dist/interface/crud/emails.js.map +1 -0
  228. package/dist/interface/crud/internal-api-keys.d.cts +139 -0
  229. package/dist/interface/crud/internal-api-keys.d.ts +22 -17
  230. package/dist/interface/crud/internal-api-keys.js +92 -54
  231. package/dist/interface/crud/internal-api-keys.js.map +1 -0
  232. package/dist/interface/crud/oauth.d.cts +34 -0
  233. package/dist/interface/crud/oauth.d.ts +16 -11
  234. package/dist/interface/crud/oauth.js +48 -14
  235. package/dist/interface/crud/oauth.js.map +1 -0
  236. package/dist/interface/crud/project-api-keys.d.cts +196 -0
  237. package/dist/interface/crud/project-api-keys.d.ts +20 -12
  238. package/dist/interface/crud/project-api-keys.js +121 -74
  239. package/dist/interface/crud/project-api-keys.js.map +1 -0
  240. package/dist/interface/crud/project-permissions.d.cts +160 -0
  241. package/dist/interface/crud/project-permissions.d.ts +38 -33
  242. package/dist/interface/crud/project-permissions.js +148 -90
  243. package/dist/interface/crud/project-permissions.js.map +1 -0
  244. package/dist/interface/crud/projects.d.cts +627 -0
  245. package/dist/interface/crud/projects.d.ts +43 -51
  246. package/dist/interface/crud/projects.js +210 -156
  247. package/dist/interface/crud/projects.js.map +1 -0
  248. package/dist/interface/crud/sessions.d.cts +149 -0
  249. package/dist/interface/crud/sessions.d.ts +21 -16
  250. package/dist/interface/crud/sessions.js +86 -50
  251. package/dist/interface/crud/sessions.js.map +1 -0
  252. package/dist/interface/crud/svix-token.d.cts +26 -0
  253. package/dist/interface/crud/svix-token.d.ts +14 -9
  254. package/dist/interface/crud/svix-token.js +46 -12
  255. package/dist/interface/crud/svix-token.js.map +1 -0
  256. package/dist/interface/crud/team-invitation-details.d.cts +30 -0
  257. package/dist/interface/crud/team-invitation-details.d.ts +12 -7
  258. package/dist/interface/crud/team-invitation-details.js +57 -15
  259. package/dist/interface/crud/team-invitation-details.js.map +1 -0
  260. package/dist/interface/crud/team-invitation.d.cts +49 -0
  261. package/dist/interface/crud/team-invitation.d.ts +13 -8
  262. package/dist/interface/crud/team-invitation.js +69 -27
  263. package/dist/interface/crud/team-invitation.js.map +1 -0
  264. package/dist/interface/crud/team-member-profiles.d.cts +229 -0
  265. package/dist/interface/crud/team-member-profiles.d.ts +20 -15
  266. package/dist/interface/crud/team-member-profiles.js +95 -49
  267. package/dist/interface/crud/team-member-profiles.js.map +1 -0
  268. package/dist/interface/crud/team-memberships.d.cts +74 -0
  269. package/dist/interface/crud/team-memberships.d.ts +22 -17
  270. package/dist/interface/crud/team-memberships.js +85 -45
  271. package/dist/interface/crud/team-memberships.js.map +1 -0
  272. package/dist/interface/crud/team-permissions.d.cts +168 -0
  273. package/dist/interface/crud/team-permissions.d.ts +38 -33
  274. package/dist/interface/crud/team-permissions.js +149 -91
  275. package/dist/interface/crud/team-permissions.js.map +1 -0
  276. package/dist/interface/crud/teams.d.cts +298 -0
  277. package/dist/interface/crud/teams.d.ts +45 -40
  278. package/dist/interface/crud/teams.js +177 -119
  279. package/dist/interface/crud/teams.js.map +1 -0
  280. package/dist/interface/crud/users.d.cts +469 -0
  281. package/dist/interface/crud/users.d.ts +31 -26
  282. package/dist/interface/crud/users.js +172 -118
  283. package/dist/interface/crud/users.js.map +1 -0
  284. package/dist/interface/serverInterface.d.cts +128 -0
  285. package/dist/interface/serverInterface.d.ts +29 -17
  286. package/dist/interface/serverInterface.js +506 -339
  287. package/dist/interface/serverInterface.js.map +1 -0
  288. package/dist/interface/webhooks.d.cts +292 -0
  289. package/dist/interface/webhooks.d.ts +6 -3
  290. package/dist/interface/webhooks.js +45 -15
  291. package/dist/interface/webhooks.js.map +1 -0
  292. package/dist/known-errors.d.cts +447 -0
  293. package/dist/known-errors.d.ts +15 -9
  294. package/dist/known-errors.js +1104 -562
  295. package/dist/known-errors.js.map +1 -0
  296. package/dist/schema-fields.d.cts +163 -0
  297. package/dist/schema-fields.d.ts +116 -114
  298. package/dist/schema-fields.js +593 -427
  299. package/dist/schema-fields.js.map +1 -0
  300. package/dist/sessions.d.cts +109 -0
  301. package/dist/sessions.d.ts +6 -3
  302. package/dist/sessions.js +201 -172
  303. package/dist/sessions.js.map +1 -0
  304. package/dist/utils/api-keys.d.cts +24 -0
  305. package/dist/utils/api-keys.d.ts +5 -4
  306. package/dist/utils/api-keys.js +106 -66
  307. package/dist/utils/api-keys.js.map +1 -0
  308. package/dist/utils/arrays.d.cts +18 -0
  309. package/dist/utils/arrays.d.ts +15 -13
  310. package/dist/utils/arrays.js +101 -168
  311. package/dist/utils/arrays.js.map +1 -0
  312. package/dist/utils/base64.d.cts +4 -0
  313. package/dist/utils/base64.d.ts +4 -2
  314. package/dist/utils/base64.js +41 -20
  315. package/dist/utils/base64.js.map +1 -0
  316. package/dist/utils/booleans.d.cts +6 -0
  317. package/dist/utils/booleans.d.ts +6 -4
  318. package/dist/utils/booleans.js +35 -27
  319. package/dist/utils/booleans.js.map +1 -0
  320. package/dist/utils/browser-compat.d.cts +8 -0
  321. package/dist/utils/browser-compat.d.ts +3 -1
  322. package/dist/utils/browser-compat.js +45 -16
  323. package/dist/utils/browser-compat.js.map +1 -0
  324. package/dist/utils/bytes.d.cts +15 -0
  325. package/dist/utils/bytes.d.ts +15 -13
  326. package/dist/utils/bytes.js +182 -270
  327. package/dist/utils/bytes.js.map +1 -0
  328. package/dist/utils/caches.d.cts +98 -0
  329. package/dist/utils/caches.d.ts +17 -14
  330. package/dist/utils/caches.js +188 -193
  331. package/dist/utils/caches.js.map +1 -0
  332. package/dist/utils/compile-time.d.cts +8 -0
  333. package/dist/utils/compile-time.d.ts +3 -1
  334. package/dist/utils/compile-time.js +35 -10
  335. package/dist/utils/compile-time.js.map +1 -0
  336. package/dist/utils/crypto.d.cts +8 -0
  337. package/dist/utils/crypto.d.ts +4 -2
  338. package/dist/utils/crypto.js +49 -21
  339. package/dist/utils/crypto.js.map +1 -0
  340. package/dist/utils/dates.d.cts +15 -0
  341. package/dist/utils/dates.d.ts +6 -4
  342. package/dist/utils/dates.js +83 -105
  343. package/dist/utils/dates.js.map +1 -0
  344. package/dist/utils/dom.d.cts +3 -0
  345. package/dist/utils/dom.d.ts +3 -1
  346. package/dist/utils/dom.js +35 -7
  347. package/dist/utils/dom.js.map +1 -0
  348. package/dist/utils/env.d.cts +9 -0
  349. package/dist/utils/env.d.ts +6 -4
  350. package/dist/utils/env.js +70 -43
  351. package/dist/utils/env.js.map +1 -0
  352. package/dist/utils/errors.d.cts +223 -0
  353. package/dist/utils/errors.d.ts +14 -11
  354. package/dist/utils/errors.js +148 -126
  355. package/dist/utils/errors.js.map +1 -0
  356. package/dist/utils/fs.d.cts +7 -0
  357. package/dist/utils/fs.d.ts +5 -3
  358. package/dist/utils/fs.js +70 -27
  359. package/dist/utils/fs.js.map +1 -0
  360. package/dist/utils/functions.d.cts +4 -0
  361. package/dist/utils/functions.d.ts +4 -2
  362. package/dist/utils/functions.js +35 -18
  363. package/dist/utils/functions.js.map +1 -0
  364. package/dist/utils/geo.d.cts +22 -0
  365. package/dist/utils/geo.d.ts +6 -3
  366. package/dist/utils/geo.js +39 -9
  367. package/dist/utils/geo.js.map +1 -0
  368. package/dist/utils/globals.d.cts +5 -0
  369. package/dist/utils/globals.d.ts +4 -2
  370. package/dist/utils/globals.js +41 -14
  371. package/dist/utils/globals.js.map +1 -0
  372. package/dist/utils/hashes.d.cts +7 -0
  373. package/dist/utils/hashes.d.ts +7 -5
  374. package/dist/utils/hashes.js +87 -41
  375. package/dist/utils/hashes.js.map +1 -0
  376. package/dist/utils/html.d.cts +4 -0
  377. package/dist/utils/html.d.ts +4 -2
  378. package/dist/utils/html.js +36 -37
  379. package/dist/utils/html.js.map +1 -0
  380. package/dist/utils/http.d.cts +43 -0
  381. package/dist/utils/http.d.ts +6 -4
  382. package/dist/utils/http.js +83 -83
  383. package/dist/utils/http.js.map +1 -0
  384. package/dist/utils/ips.d.cts +6 -0
  385. package/dist/utils/ips.d.ts +6 -4
  386. package/dist/utils/ips.js +48 -35
  387. package/dist/utils/ips.js.map +1 -0
  388. package/dist/utils/json.d.cts +13 -0
  389. package/dist/utils/json.d.ts +9 -6
  390. package/dist/utils/json.js +54 -157
  391. package/dist/utils/json.js.map +1 -0
  392. package/dist/utils/jwt.d.cts +44 -0
  393. package/dist/utils/jwt.d.ts +14 -11
  394. package/dist/utils/jwt.js +119 -84
  395. package/dist/utils/jwt.js.map +1 -0
  396. package/dist/utils/locks.d.cts +15 -0
  397. package/dist/utils/locks.d.ts +3 -2
  398. package/dist/utils/locks.js +76 -56
  399. package/dist/utils/locks.js.map +1 -0
  400. package/dist/utils/maps.d.cts +59 -0
  401. package/dist/utils/maps.d.ts +6 -4
  402. package/dist/utils/maps.js +207 -343
  403. package/dist/utils/maps.js.map +1 -0
  404. package/dist/utils/math.d.cts +6 -0
  405. package/dist/utils/math.d.ts +3 -1
  406. package/dist/utils/math.js +31 -16
  407. package/dist/utils/math.js.map +1 -0
  408. package/dist/utils/node-http.d.cts +15 -0
  409. package/dist/utils/node-http.d.ts +5 -5
  410. package/dist/utils/node-http.js +65 -36
  411. package/dist/utils/node-http.js.map +1 -0
  412. package/dist/utils/numbers.d.cts +5 -0
  413. package/dist/utils/numbers.d.ts +5 -3
  414. package/dist/utils/numbers.js +53 -66
  415. package/dist/utils/numbers.js.map +1 -0
  416. package/dist/utils/oauth.d.cts +8 -0
  417. package/dist/utils/oauth.d.ts +8 -6
  418. package/dist/utils/oauth.js +37 -4
  419. package/dist/utils/oauth.js.map +1 -0
  420. package/dist/utils/objects.d.cts +69 -0
  421. package/dist/utils/objects.d.ts +37 -32
  422. package/dist/utils/objects.js +224 -374
  423. package/dist/utils/objects.js.map +1 -0
  424. package/dist/utils/passkey.d.cts +1 -0
  425. package/dist/utils/passkey.d.ts +1 -1
  426. package/dist/utils/passkey.js +19 -1
  427. package/dist/utils/passkey.js.map +1 -0
  428. package/dist/utils/promises.d.cts +74 -0
  429. package/dist/utils/promises.d.ts +20 -18
  430. package/dist/utils/promises.js +252 -393
  431. package/dist/utils/promises.js.map +1 -0
  432. package/dist/utils/proxies.d.cts +4 -0
  433. package/dist/utils/proxies.d.ts +4 -2
  434. package/dist/utils/proxies.js +150 -161
  435. package/dist/utils/proxies.js.map +1 -0
  436. package/dist/utils/react.d.cts +25 -0
  437. package/dist/utils/react.d.ts +9 -6
  438. package/dist/utils/react.js +88 -134
  439. package/dist/utils/react.js.map +1 -0
  440. package/dist/utils/results.d.cts +78 -0
  441. package/dist/utils/results.d.ts +10 -9
  442. package/dist/utils/results.js +143 -324
  443. package/dist/utils/results.js.map +1 -0
  444. package/dist/utils/sentry.d.cts +5 -0
  445. package/dist/utils/sentry.d.ts +5 -2
  446. package/dist/utils/sentry.js +44 -14
  447. package/dist/utils/sentry.js.map +1 -0
  448. package/dist/utils/stores.d.cts +102 -0
  449. package/dist/utils/stores.d.ts +12 -9
  450. package/dist/utils/stores.js +219 -189
  451. package/dist/utils/stores.js.map +1 -0
  452. package/dist/utils/strings.d.cts +72 -0
  453. package/dist/utils/strings.d.ts +22 -20
  454. package/dist/utils/strings.js +300 -580
  455. package/dist/utils/strings.js.map +1 -0
  456. package/dist/utils/strings.nicify.test.d.cts +2 -0
  457. package/dist/utils/strings.nicify.test.d.ts +2 -1
  458. package/dist/utils/strings.nicify.test.js +168 -158
  459. package/dist/utils/strings.nicify.test.js.map +1 -0
  460. package/dist/utils/types.d.cts +23 -0
  461. package/dist/utils/types.d.ts +8 -6
  462. package/dist/utils/types.js +19 -1
  463. package/dist/utils/types.js.map +1 -0
  464. package/dist/utils/unicode.d.cts +3 -0
  465. package/dist/utils/unicode.d.ts +3 -1
  466. package/dist/utils/unicode.js +34 -21
  467. package/dist/utils/unicode.js.map +1 -0
  468. package/dist/utils/urls.d.cts +20 -0
  469. package/dist/utils/urls.d.ts +10 -8
  470. package/dist/utils/urls.js +76 -165
  471. package/dist/utils/urls.js.map +1 -0
  472. package/dist/utils/uuids.d.cts +4 -0
  473. package/dist/utils/uuids.d.ts +4 -2
  474. package/dist/utils/uuids.js +39 -35
  475. package/dist/utils/uuids.js.map +1 -0
  476. package/package.json +5 -5
package/dist/sessions.js CHANGED
@@ -1,176 +1,205 @@
1
- import * as jose from 'jose';
2
- import { StackAssertionError } from "./utils/errors";
3
- import { Store } from "./utils/stores";
4
- export class AccessToken {
5
- constructor(token) {
6
- this.token = token;
7
- if (token === "undefined") {
8
- throw new StackAssertionError("Access token is the string 'undefined'; it's unlikely this is the correct value. They're supposed to be unguessable!");
9
- }
10
- }
11
- get decoded() {
12
- return jose.decodeJwt(this.token);
13
- }
14
- get expiresAt() {
15
- const { exp } = this.decoded;
16
- if (exp === undefined)
17
- return new Date(8640000000000000); // max date value
18
- return new Date(exp * 1000);
19
- }
20
- /**
21
- * @returns The number of milliseconds until the access token expires, or 0 if it has already expired.
22
- */
23
- get expiresInMillis() {
24
- return Math.max(0, this.expiresAt.getTime() - Date.now());
25
- }
26
- isExpired() {
27
- return this.expiresInMillis <= 0;
28
- }
29
- }
30
- export class RefreshToken {
31
- constructor(token) {
32
- this.token = token;
33
- if (token === "undefined") {
34
- throw new StackAssertionError("Refresh token is the string 'undefined'; it's unlikely this is the correct value. They're supposed to be unguessable!");
35
- }
36
- }
37
- }
38
- /**
39
- * An InternalSession represents a user's session, which may or may not be valid. It may contain an access token, a refresh token, or both.
40
- *
41
- * A session never changes which user or session it belongs to, but the tokens in it may change over time.
42
- */
43
- export class InternalSession {
44
- constructor(_options) {
45
- this._options = _options;
46
- /**
47
- * Whether the session as a whole is known to be invalid (ie. both access and refresh tokens are invalid). Used as a cache to avoid making multiple requests to the server (sessions never go back to being valid after being invalidated).
48
- *
49
- * It is possible for the access token to be invalid but the refresh token to be valid, in which case the session is
50
- * still valid (just needs a refresh). It is also possible for the access token to be valid but the refresh token to
51
- * be invalid, in which case the session is also valid (eg. if the refresh token is null because the user only passed
52
- * in an access token, eg. in a server-side request handler).
53
- */
54
- this._knownToBeInvalid = new Store(false);
55
- this._refreshPromise = null;
56
- this._accessToken = new Store(_options.accessToken ? new AccessToken(_options.accessToken) : null);
57
- this._refreshToken = _options.refreshToken ? new RefreshToken(_options.refreshToken) : null;
58
- if (_options.accessToken === null && _options.refreshToken === null) {
59
- // this session is already invalid
60
- this._knownToBeInvalid.set(true);
61
- }
62
- this.sessionKey = InternalSession.calculateSessionKey({ accessToken: _options.accessToken ?? null, refreshToken: _options.refreshToken });
63
- }
64
- static calculateSessionKey(ofTokens) {
65
- if (ofTokens.refreshToken) {
66
- return `refresh-${ofTokens.refreshToken}`;
67
- }
68
- else if (ofTokens.accessToken) {
69
- return `access-${ofTokens.accessToken}`;
70
- }
71
- else {
72
- return "not-logged-in";
73
- }
74
- }
75
- isKnownToBeInvalid() {
76
- return this._knownToBeInvalid.get();
77
- }
78
- /**
79
- * Marks the session object as invalid, meaning that the refresh and access tokens can no longer be used.
80
- */
81
- markInvalid() {
82
- this._accessToken.set(null);
83
- this._knownToBeInvalid.set(true);
84
- }
85
- onInvalidate(callback) {
86
- return this._knownToBeInvalid.onChange(() => callback());
87
- }
88
- /**
89
- * Returns the access token if it is found in the cache, fetching it otherwise.
90
- *
91
- * This is usually the function you want to call to get an access token. Either set `minMillisUntilExpiration` to a reasonable value, or catch errors that occur if it expires, and call `markAccessTokenExpired` to mark the token as expired if so (after which a call to this function will always refetch the token).
92
- *
93
- * @returns null if the session is known to be invalid, cached tokens if they exist in the cache (which may or may not be valid still), or new tokens otherwise.
94
- */
95
- async getOrFetchLikelyValidTokens(minMillisUntilExpiration) {
96
- if (minMillisUntilExpiration >= 60000) {
97
- throw new Error(`Required access token expiry ${minMillisUntilExpiration}ms is too long; access tokens are too short to be used for more than 60s`);
98
- }
99
- const accessToken = this._getPotentiallyInvalidAccessTokenIfAvailable();
100
- if (!accessToken || accessToken.expiresInMillis < minMillisUntilExpiration) {
101
- const newTokens = await this.fetchNewTokens();
102
- const expiresInMillis = newTokens?.accessToken.expiresInMillis;
103
- if (expiresInMillis && expiresInMillis < minMillisUntilExpiration) {
104
- throw new StackAssertionError(`Required access token expiry ${minMillisUntilExpiration}ms is too long; access tokens are too short when they're generated (${expiresInMillis}ms)`);
105
- }
106
- return newTokens;
107
- }
108
- return { accessToken, refreshToken: this._refreshToken };
109
- }
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/sessions.ts
31
+ var sessions_exports = {};
32
+ __export(sessions_exports, {
33
+ AccessToken: () => AccessToken,
34
+ InternalSession: () => InternalSession,
35
+ RefreshToken: () => RefreshToken
36
+ });
37
+ module.exports = __toCommonJS(sessions_exports);
38
+ var jose = __toESM(require("jose"), 1);
39
+ var import_errors = require("./utils/errors");
40
+ var import_stores = require("./utils/stores");
41
+ var AccessToken = class {
42
+ constructor(token) {
43
+ this.token = token;
44
+ if (token === "undefined") {
45
+ throw new import_errors.StackAssertionError("Access token is the string 'undefined'; it's unlikely this is the correct value. They're supposed to be unguessable!");
46
+ }
47
+ }
48
+ get decoded() {
49
+ return jose.decodeJwt(this.token);
50
+ }
51
+ get expiresAt() {
52
+ const { exp } = this.decoded;
53
+ if (exp === void 0) return /* @__PURE__ */ new Date(864e13);
54
+ return new Date(exp * 1e3);
55
+ }
56
+ /**
57
+ * @returns The number of milliseconds until the access token expires, or 0 if it has already expired.
58
+ */
59
+ get expiresInMillis() {
60
+ return Math.max(0, this.expiresAt.getTime() - Date.now());
61
+ }
62
+ isExpired() {
63
+ return this.expiresInMillis <= 0;
64
+ }
65
+ };
66
+ var RefreshToken = class {
67
+ constructor(token) {
68
+ this.token = token;
69
+ if (token === "undefined") {
70
+ throw new import_errors.StackAssertionError("Refresh token is the string 'undefined'; it's unlikely this is the correct value. They're supposed to be unguessable!");
71
+ }
72
+ }
73
+ };
74
+ var InternalSession = class _InternalSession {
75
+ constructor(_options) {
76
+ this._options = _options;
110
77
  /**
111
- * Fetches new tokens that are, at the time of fetching, guaranteed to be valid.
78
+ * Whether the session as a whole is known to be invalid (ie. both access and refresh tokens are invalid). Used as a cache to avoid making multiple requests to the server (sessions never go back to being valid after being invalidated).
112
79
  *
113
- * The newly generated tokens are short-lived, so it's good practice not to rely on their validity (if possible). However, this function is useful in some cases where you only want to pass access tokens to a service, and you want to make sure said access token has the longest possible lifetime.
114
- *
115
- * In most cases, you should prefer `getOrFetchLikelyValidTokens`.
116
- *
117
- * @returns null if the session is known to be invalid, or new tokens otherwise (which, at the time of fetching, are guaranteed to be valid).
80
+ * It is possible for the access token to be invalid but the refresh token to be valid, in which case the session is
81
+ * still valid (just needs a refresh). It is also possible for the access token to be valid but the refresh token to
82
+ * be invalid, in which case the session is also valid (eg. if the refresh token is null because the user only passed
83
+ * in an access token, eg. in a server-side request handler).
118
84
  */
119
- async fetchNewTokens() {
120
- const accessToken = await this._getNewlyFetchedAccessToken();
121
- return accessToken ? { accessToken, refreshToken: this._refreshToken } : null;
122
- }
123
- markAccessTokenExpired(accessToken) {
124
- // TODO we don't need this anymore, since we now check the expiry by ourselves
125
- if (this._accessToken.get() === accessToken) {
126
- this._accessToken.set(null);
127
- }
128
- }
129
- /**
130
- * Note that a callback invocation with `null` does not mean the session has been invalidated; the access token may just have expired. Use `onInvalidate` to detect invalidation.
131
- */
132
- onAccessTokenChange(callback) {
133
- return this._accessToken.onChange(callback);
134
- }
135
- /**
136
- * @returns An access token, which may be expired or expire soon, or null if it is known to be invalid.
137
- */
138
- _getPotentiallyInvalidAccessTokenIfAvailable() {
139
- if (!this._refreshToken)
140
- return null;
141
- if (this.isKnownToBeInvalid())
142
- return null;
143
- const accessToken = this._accessToken.get();
144
- if (accessToken && !accessToken.isExpired())
145
- return accessToken;
146
- return null;
147
- }
148
- /**
149
- * You should prefer `_getOrFetchPotentiallyInvalidAccessToken` in almost all cases.
150
- *
151
- * @returns A newly fetched access token (never read from cache), or null if the session either does not represent a user or the session is invalid.
152
- */
153
- async _getNewlyFetchedAccessToken() {
154
- if (!this._refreshToken)
155
- return null;
156
- if (this._knownToBeInvalid.get())
157
- return null;
158
- if (!this._refreshPromise) {
159
- this._refreshAndSetRefreshPromise(this._refreshToken);
85
+ this._knownToBeInvalid = new import_stores.Store(false);
86
+ this._refreshPromise = null;
87
+ this._accessToken = new import_stores.Store(_options.accessToken ? new AccessToken(_options.accessToken) : null);
88
+ this._refreshToken = _options.refreshToken ? new RefreshToken(_options.refreshToken) : null;
89
+ if (_options.accessToken === null && _options.refreshToken === null) {
90
+ this._knownToBeInvalid.set(true);
91
+ }
92
+ this.sessionKey = _InternalSession.calculateSessionKey({ accessToken: _options.accessToken ?? null, refreshToken: _options.refreshToken });
93
+ }
94
+ static calculateSessionKey(ofTokens) {
95
+ if (ofTokens.refreshToken) {
96
+ return `refresh-${ofTokens.refreshToken}`;
97
+ } else if (ofTokens.accessToken) {
98
+ return `access-${ofTokens.accessToken}`;
99
+ } else {
100
+ return "not-logged-in";
101
+ }
102
+ }
103
+ isKnownToBeInvalid() {
104
+ return this._knownToBeInvalid.get();
105
+ }
106
+ /**
107
+ * Marks the session object as invalid, meaning that the refresh and access tokens can no longer be used.
108
+ */
109
+ markInvalid() {
110
+ this._accessToken.set(null);
111
+ this._knownToBeInvalid.set(true);
112
+ }
113
+ onInvalidate(callback) {
114
+ return this._knownToBeInvalid.onChange(() => callback());
115
+ }
116
+ /**
117
+ * Returns the access token if it is found in the cache, fetching it otherwise.
118
+ *
119
+ * This is usually the function you want to call to get an access token. Either set `minMillisUntilExpiration` to a reasonable value, or catch errors that occur if it expires, and call `markAccessTokenExpired` to mark the token as expired if so (after which a call to this function will always refetch the token).
120
+ *
121
+ * @returns null if the session is known to be invalid, cached tokens if they exist in the cache (which may or may not be valid still), or new tokens otherwise.
122
+ */
123
+ async getOrFetchLikelyValidTokens(minMillisUntilExpiration) {
124
+ if (minMillisUntilExpiration >= 6e4) {
125
+ throw new Error(`Required access token expiry ${minMillisUntilExpiration}ms is too long; access tokens are too short to be used for more than 60s`);
126
+ }
127
+ const accessToken = this._getPotentiallyInvalidAccessTokenIfAvailable();
128
+ if (!accessToken || accessToken.expiresInMillis < minMillisUntilExpiration) {
129
+ const newTokens = await this.fetchNewTokens();
130
+ const expiresInMillis = newTokens?.accessToken.expiresInMillis;
131
+ if (expiresInMillis && expiresInMillis < minMillisUntilExpiration) {
132
+ throw new import_errors.StackAssertionError(`Required access token expiry ${minMillisUntilExpiration}ms is too long; access tokens are too short when they're generated (${expiresInMillis}ms)`);
133
+ }
134
+ return newTokens;
135
+ }
136
+ return { accessToken, refreshToken: this._refreshToken };
137
+ }
138
+ /**
139
+ * Fetches new tokens that are, at the time of fetching, guaranteed to be valid.
140
+ *
141
+ * The newly generated tokens are short-lived, so it's good practice not to rely on their validity (if possible). However, this function is useful in some cases where you only want to pass access tokens to a service, and you want to make sure said access token has the longest possible lifetime.
142
+ *
143
+ * In most cases, you should prefer `getOrFetchLikelyValidTokens`.
144
+ *
145
+ * @returns null if the session is known to be invalid, or new tokens otherwise (which, at the time of fetching, are guaranteed to be valid).
146
+ */
147
+ async fetchNewTokens() {
148
+ const accessToken = await this._getNewlyFetchedAccessToken();
149
+ return accessToken ? { accessToken, refreshToken: this._refreshToken } : null;
150
+ }
151
+ markAccessTokenExpired(accessToken) {
152
+ if (this._accessToken.get() === accessToken) {
153
+ this._accessToken.set(null);
154
+ }
155
+ }
156
+ /**
157
+ * Note that a callback invocation with `null` does not mean the session has been invalidated; the access token may just have expired. Use `onInvalidate` to detect invalidation.
158
+ */
159
+ onAccessTokenChange(callback) {
160
+ return this._accessToken.onChange(callback);
161
+ }
162
+ /**
163
+ * @returns An access token, which may be expired or expire soon, or null if it is known to be invalid.
164
+ */
165
+ _getPotentiallyInvalidAccessTokenIfAvailable() {
166
+ if (!this._refreshToken) return null;
167
+ if (this.isKnownToBeInvalid()) return null;
168
+ const accessToken = this._accessToken.get();
169
+ if (accessToken && !accessToken.isExpired()) return accessToken;
170
+ return null;
171
+ }
172
+ /**
173
+ * You should prefer `_getOrFetchPotentiallyInvalidAccessToken` in almost all cases.
174
+ *
175
+ * @returns A newly fetched access token (never read from cache), or null if the session either does not represent a user or the session is invalid.
176
+ */
177
+ async _getNewlyFetchedAccessToken() {
178
+ if (!this._refreshToken) return null;
179
+ if (this._knownToBeInvalid.get()) return null;
180
+ if (!this._refreshPromise) {
181
+ this._refreshAndSetRefreshPromise(this._refreshToken);
182
+ }
183
+ return await this._refreshPromise;
184
+ }
185
+ _refreshAndSetRefreshPromise(refreshToken) {
186
+ let refreshPromise = this._options.refreshAccessTokenCallback(refreshToken).then((accessToken) => {
187
+ if (refreshPromise === this._refreshPromise) {
188
+ this._refreshPromise = null;
189
+ this._accessToken.set(accessToken);
190
+ if (!accessToken) {
191
+ this.markInvalid();
160
192
  }
161
- return await this._refreshPromise;
162
- }
163
- _refreshAndSetRefreshPromise(refreshToken) {
164
- let refreshPromise = this._options.refreshAccessTokenCallback(refreshToken).then((accessToken) => {
165
- if (refreshPromise === this._refreshPromise) {
166
- this._refreshPromise = null;
167
- this._accessToken.set(accessToken);
168
- if (!accessToken) {
169
- this.markInvalid();
170
- }
171
- }
172
- return accessToken;
173
- });
174
- this._refreshPromise = refreshPromise;
175
- }
176
- }
193
+ }
194
+ return accessToken;
195
+ });
196
+ this._refreshPromise = refreshPromise;
197
+ }
198
+ };
199
+ // Annotate the CommonJS export names for ESM import in node:
200
+ 0 && (module.exports = {
201
+ AccessToken,
202
+ InternalSession,
203
+ RefreshToken
204
+ });
205
+ //# sourceMappingURL=sessions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/sessions.ts"],"sourcesContent":["import * as jose from 'jose';\nimport { StackAssertionError } from \"./utils/errors\";\nimport { Store } from \"./utils/stores\";\n\nexport class AccessToken {\n constructor(\n public readonly token: string,\n ) {\n if (token === \"undefined\") {\n throw new StackAssertionError(\"Access token is the string 'undefined'; it's unlikely this is the correct value. They're supposed to be unguessable!\");\n }\n }\n\n get decoded() {\n return jose.decodeJwt(this.token);\n }\n\n get expiresAt(): Date {\n const { exp } = this.decoded;\n if (exp === undefined) return new Date(8640000000000000); // max date value\n return new Date(exp * 1000);\n }\n\n /**\n * @returns The number of milliseconds until the access token expires, or 0 if it has already expired.\n */\n get expiresInMillis(): number {\n return Math.max(0, this.expiresAt.getTime() - Date.now());\n }\n\n isExpired(): boolean {\n return this.expiresInMillis <= 0;\n }\n}\n\nexport class RefreshToken {\n constructor(\n public readonly token: string,\n ) {\n if (token === \"undefined\") {\n throw new StackAssertionError(\"Refresh token is the string 'undefined'; it's unlikely this is the correct value. They're supposed to be unguessable!\");\n }\n }\n}\n\n/**\n * An InternalSession represents a user's session, which may or may not be valid. It may contain an access token, a refresh token, or both.\n *\n * A session never changes which user or session it belongs to, but the tokens in it may change over time.\n */\nexport class InternalSession {\n /**\n * Each session has a session key that depends on the tokens inside. If the session has a refresh token, the session key depends only on the refresh token. If the session does not have a refresh token, the session key depends only on the access token.\n *\n * Multiple Session objects may have the same session key, which implies that they represent the same session by the same user. Furthermore, a session's key never changes over the lifetime of a session object.\n *\n * This is useful for caching and indexing sessions.\n */\n public readonly sessionKey: string;\n\n /**\n * An access token that is not known to be invalid (ie. may be valid, but may have expired).\n */\n private _accessToken: Store<AccessToken | null>;\n private readonly _refreshToken: RefreshToken | null;\n\n /**\n * Whether the session as a whole is known to be invalid (ie. both access and refresh tokens are invalid). Used as a cache to avoid making multiple requests to the server (sessions never go back to being valid after being invalidated).\n *\n * It is possible for the access token to be invalid but the refresh token to be valid, in which case the session is\n * still valid (just needs a refresh). It is also possible for the access token to be valid but the refresh token to\n * be invalid, in which case the session is also valid (eg. if the refresh token is null because the user only passed\n * in an access token, eg. in a server-side request handler).\n */\n private _knownToBeInvalid = new Store<boolean>(false);\n\n private _refreshPromise: Promise<AccessToken | null> | null = null;\n\n constructor(private readonly _options: {\n refreshAccessTokenCallback(refreshToken: RefreshToken): Promise<AccessToken | null>,\n refreshToken: string | null,\n accessToken?: string | null,\n }) {\n this._accessToken = new Store(_options.accessToken ? new AccessToken(_options.accessToken) : null);\n this._refreshToken = _options.refreshToken ? new RefreshToken(_options.refreshToken) : null;\n if (_options.accessToken === null && _options.refreshToken === null) {\n // this session is already invalid\n this._knownToBeInvalid.set(true);\n }\n this.sessionKey = InternalSession.calculateSessionKey({ accessToken: _options.accessToken ?? null, refreshToken: _options.refreshToken });\n }\n\n static calculateSessionKey(ofTokens: { refreshToken: string | null, accessToken?: string | null }): string {\n if (ofTokens.refreshToken) {\n return `refresh-${ofTokens.refreshToken}`;\n } else if (ofTokens.accessToken) {\n return `access-${ofTokens.accessToken}`;\n } else {\n return \"not-logged-in\";\n }\n }\n\n isKnownToBeInvalid() {\n return this._knownToBeInvalid.get();\n }\n\n /**\n * Marks the session object as invalid, meaning that the refresh and access tokens can no longer be used.\n */\n markInvalid() {\n this._accessToken.set(null);\n this._knownToBeInvalid.set(true);\n }\n\n onInvalidate(callback: () => void): { unsubscribe: () => void } {\n return this._knownToBeInvalid.onChange(() => callback());\n }\n\n /**\n * Returns the access token if it is found in the cache, fetching it otherwise.\n *\n * This is usually the function you want to call to get an access token. Either set `minMillisUntilExpiration` to a reasonable value, or catch errors that occur if it expires, and call `markAccessTokenExpired` to mark the token as expired if so (after which a call to this function will always refetch the token).\n *\n * @returns null if the session is known to be invalid, cached tokens if they exist in the cache (which may or may not be valid still), or new tokens otherwise.\n */\n async getOrFetchLikelyValidTokens(minMillisUntilExpiration: number): Promise<{ accessToken: AccessToken, refreshToken: RefreshToken | null } | null> {\n if (minMillisUntilExpiration >= 60_000) {\n throw new Error(`Required access token expiry ${minMillisUntilExpiration}ms is too long; access tokens are too short to be used for more than 60s`);\n }\n\n const accessToken = this._getPotentiallyInvalidAccessTokenIfAvailable();\n if (!accessToken || accessToken.expiresInMillis < minMillisUntilExpiration) {\n const newTokens = await this.fetchNewTokens();\n const expiresInMillis = newTokens?.accessToken.expiresInMillis;\n if (expiresInMillis && expiresInMillis < minMillisUntilExpiration) {\n throw new StackAssertionError(`Required access token expiry ${minMillisUntilExpiration}ms is too long; access tokens are too short when they're generated (${expiresInMillis}ms)`);\n }\n return newTokens;\n }\n return { accessToken, refreshToken: this._refreshToken };\n }\n\n /**\n * Fetches new tokens that are, at the time of fetching, guaranteed to be valid.\n *\n * The newly generated tokens are short-lived, so it's good practice not to rely on their validity (if possible). However, this function is useful in some cases where you only want to pass access tokens to a service, and you want to make sure said access token has the longest possible lifetime.\n *\n * In most cases, you should prefer `getOrFetchLikelyValidTokens`.\n *\n * @returns null if the session is known to be invalid, or new tokens otherwise (which, at the time of fetching, are guaranteed to be valid).\n */\n async fetchNewTokens(): Promise<{ accessToken: AccessToken, refreshToken: RefreshToken | null } | null> {\n const accessToken = await this._getNewlyFetchedAccessToken();\n return accessToken ? { accessToken, refreshToken: this._refreshToken } : null;\n }\n\n markAccessTokenExpired(accessToken: AccessToken) {\n // TODO we don't need this anymore, since we now check the expiry by ourselves\n if (this._accessToken.get() === accessToken) {\n this._accessToken.set(null);\n }\n }\n\n /**\n * Note that a callback invocation with `null` does not mean the session has been invalidated; the access token may just have expired. Use `onInvalidate` to detect invalidation.\n */\n onAccessTokenChange(callback: (newAccessToken: AccessToken | null) => void): { unsubscribe: () => void } {\n return this._accessToken.onChange(callback);\n }\n\n /**\n * @returns An access token, which may be expired or expire soon, or null if it is known to be invalid.\n */\n private _getPotentiallyInvalidAccessTokenIfAvailable(): AccessToken | null {\n if (!this._refreshToken) return null;\n if (this.isKnownToBeInvalid()) return null;\n\n const accessToken = this._accessToken.get();\n if (accessToken && !accessToken.isExpired()) return accessToken;\n\n return null;\n }\n\n /**\n * You should prefer `_getOrFetchPotentiallyInvalidAccessToken` in almost all cases.\n *\n * @returns A newly fetched access token (never read from cache), or null if the session either does not represent a user or the session is invalid.\n */\n private async _getNewlyFetchedAccessToken(): Promise<AccessToken | null> {\n if (!this._refreshToken) return null;\n if (this._knownToBeInvalid.get()) return null;\n\n if (!this._refreshPromise) {\n this._refreshAndSetRefreshPromise(this._refreshToken);\n }\n return await this._refreshPromise;\n }\n\n private _refreshAndSetRefreshPromise(refreshToken: RefreshToken) {\n let refreshPromise: Promise<AccessToken | null> = this._options.refreshAccessTokenCallback(refreshToken).then((accessToken) => {\n if (refreshPromise === this._refreshPromise) {\n this._refreshPromise = null;\n this._accessToken.set(accessToken);\n if (!accessToken) {\n this.markInvalid();\n }\n }\n return accessToken;\n });\n this._refreshPromise = refreshPromise;\n }\n}\n"],"mappings":"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","names":[]}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * An api key has the following format:
3
+ * <prefix_without_underscores>_<secret_part_45_chars><id_part_32_chars><type_user_or_team_4_chars><scanner_and_marker_10_chars><checksum_8_chars>
4
+ *
5
+ * The scanner and marker is a base32 character that is used to determine if the api key is a public or private key
6
+ * and if it is a cloud or self-hosted key.
7
+ *
8
+ * The checksum is a crc32 checksum of the api key encoded in hex.
9
+ *
10
+ */
11
+ type ProjectApiKey = {
12
+ id: string;
13
+ prefix: string;
14
+ isPublic: boolean;
15
+ isCloudVersion: boolean;
16
+ secret: string;
17
+ checksum: string;
18
+ type: "user" | "team";
19
+ };
20
+ declare function isApiKey(secret: string): boolean;
21
+ declare function createProjectApiKey(options: Pick<ProjectApiKey, "id" | "isPublic" | "isCloudVersion" | "type">): string;
22
+ declare function parseProjectApiKey(secret: string): ProjectApiKey;
23
+
24
+ export { createProjectApiKey, isApiKey, parseProjectApiKey };
@@ -17,7 +17,8 @@ type ProjectApiKey = {
17
17
  checksum: string;
18
18
  type: "user" | "team";
19
19
  };
20
- export declare function isApiKey(secret: string): boolean;
21
- export declare function createProjectApiKey(options: Pick<ProjectApiKey, "id" | "isPublic" | "isCloudVersion" | "type">): string;
22
- export declare function parseProjectApiKey(secret: string): ProjectApiKey;
23
- export {};
20
+ declare function isApiKey(secret: string): boolean;
21
+ declare function createProjectApiKey(options: Pick<ProjectApiKey, "id" | "isPublic" | "isCloudVersion" | "type">): string;
22
+ declare function parseProjectApiKey(secret: string): ProjectApiKey;
23
+
24
+ export { createProjectApiKey, isApiKey, parseProjectApiKey };
@@ -1,76 +1,116 @@
1
- import { getBase32CharacterFromIndex } from "@stackframe/stack-shared/dist/utils/bytes";
2
- import { generateSecureRandomString } from "@stackframe/stack-shared/dist/utils/crypto";
3
- import { StackAssertionError } from "@stackframe/stack-shared/dist/utils/errors";
4
- import crc32 from 'crc/crc32';
5
- const STACK_AUTH_MARKER = "574ck4u7h";
6
- // API key part lengths
7
- const API_KEY_LENGTHS = {
8
- SECRET_PART: 45,
9
- ID_PART: 32,
10
- TYPE_PART: 4,
11
- SCANNER: 1,
12
- MARKER: 9,
13
- CHECKSUM: 8,
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/utils/api-keys.tsx
31
+ var api_keys_exports = {};
32
+ __export(api_keys_exports, {
33
+ createProjectApiKey: () => createProjectApiKey,
34
+ isApiKey: () => isApiKey,
35
+ parseProjectApiKey: () => parseProjectApiKey
36
+ });
37
+ module.exports = __toCommonJS(api_keys_exports);
38
+ var import_crc32 = __toESM(require("crc/crc32"), 1);
39
+ var import_bytes = require("./bytes");
40
+ var import_crypto = require("./crypto");
41
+ var import_errors = require("./errors");
42
+ var STACK_AUTH_MARKER = "574ck4u7h";
43
+ var API_KEY_LENGTHS = {
44
+ SECRET_PART: 45,
45
+ ID_PART: 32,
46
+ TYPE_PART: 4,
47
+ SCANNER: 1,
48
+ MARKER: 9,
49
+ CHECKSUM: 8
14
50
  };
15
51
  function createChecksumSync(checksummablePart) {
16
- const data = new TextEncoder().encode(checksummablePart);
17
- const calculated_checksum = crc32(data);
18
- return calculated_checksum.toString(16).padStart(8, "0");
52
+ const data = new TextEncoder().encode(checksummablePart);
53
+ const calculated_checksum = (0, import_crc32.default)(data);
54
+ return calculated_checksum.toString(16).padStart(8, "0");
19
55
  }
20
56
  function createApiKeyParts(options) {
21
- const { id, isPublic, isCloudVersion, type } = options;
22
- const prefix = isPublic ? "pk" : "sk";
23
- const scannerFlag = (isCloudVersion ? 0 : 1) + (isPublic ? 2 : 0) + ( /* version */0);
24
- const secretPart = generateSecureRandomString();
25
- const idPart = id.replace(/-/g, "");
26
- const scannerAndMarker = getBase32CharacterFromIndex(scannerFlag).toLowerCase() + STACK_AUTH_MARKER;
27
- const checksummablePart = `${prefix}_${secretPart}${idPart}${type}${scannerAndMarker}`;
28
- return { checksummablePart, idPart, prefix, scannerAndMarker, type };
57
+ const { id, isPublic, isCloudVersion, type } = options;
58
+ const prefix = isPublic ? "pk" : "sk";
59
+ const scannerFlag = (isCloudVersion ? 0 : 1) + (isPublic ? 2 : 0) + /* version */
60
+ 0;
61
+ const secretPart = (0, import_crypto.generateSecureRandomString)();
62
+ const idPart = id.replace(/-/g, "");
63
+ const scannerAndMarker = (0, import_bytes.getBase32CharacterFromIndex)(scannerFlag).toLowerCase() + STACK_AUTH_MARKER;
64
+ const checksummablePart = `${prefix}_${secretPart}${idPart}${type}${scannerAndMarker}`;
65
+ return { checksummablePart, idPart, prefix, scannerAndMarker, type };
29
66
  }
30
67
  function parseApiKeyParts(secret) {
31
- const regex = new RegExp(`^([a-zA-Z0-9_]+)_` + // prefix
32
- `([a-zA-Z0-9_]{${API_KEY_LENGTHS.SECRET_PART}})` + // secretPart
33
- `([a-zA-Z0-9_]{${API_KEY_LENGTHS.ID_PART}})` + // idPart
34
- `([a-zA-Z0-9_]{${API_KEY_LENGTHS.TYPE_PART}})` + // type
35
- `([a-zA-Z0-9_]{${API_KEY_LENGTHS.SCANNER}})` + // scanner
36
- `(${STACK_AUTH_MARKER})` + // marker
37
- `([a-zA-Z0-9_]{${API_KEY_LENGTHS.CHECKSUM}})$` // checksum
38
- );
39
- const match = secret.match(regex);
40
- if (!match) {
41
- throw new StackAssertionError("Invalid API key format");
42
- }
43
- const [, prefix, secretPart, idPart, type, scannerFlag, marker, checksum] = match;
44
- const isCloudVersion = parseInt(scannerFlag, 32) % 2 === 0;
45
- const isPublic = (parseInt(scannerFlag, 32) & 2) !== 0;
46
- const checksummablePart = `${prefix}_${secretPart}${idPart}${type}${scannerFlag}${marker}`;
47
- const restored_id = idPart.replace(/(.{8})(.{4})(.{4})(.{4})(.{12})/, "$1-$2-$3-$4-$5");
48
- if (!["user", "team"].includes(type)) {
49
- throw new StackAssertionError("Invalid type");
50
- }
51
- return { checksummablePart, checksum, id: restored_id, isCloudVersion, isPublic, prefix, type: type };
68
+ const regex = new RegExp(
69
+ `^([a-zA-Z0-9_]+)_([a-zA-Z0-9_]{${API_KEY_LENGTHS.SECRET_PART}})([a-zA-Z0-9_]{${API_KEY_LENGTHS.ID_PART}})([a-zA-Z0-9_]{${API_KEY_LENGTHS.TYPE_PART}})([a-zA-Z0-9_]{${API_KEY_LENGTHS.SCANNER}})(${STACK_AUTH_MARKER})([a-zA-Z0-9_]{${API_KEY_LENGTHS.CHECKSUM}})$`
70
+ // checksum
71
+ );
72
+ const match = secret.match(regex);
73
+ if (!match) {
74
+ throw new import_errors.StackAssertionError("Invalid API key format");
75
+ }
76
+ const [, prefix, secretPart, idPart, type, scannerFlag, marker, checksum] = match;
77
+ const isCloudVersion = parseInt(scannerFlag, 32) % 2 === 0;
78
+ const isPublic = (parseInt(scannerFlag, 32) & 2) !== 0;
79
+ const checksummablePart = `${prefix}_${secretPart}${idPart}${type}${scannerFlag}${marker}`;
80
+ const restored_id = idPart.replace(/(.{8})(.{4})(.{4})(.{4})(.{12})/, "$1-$2-$3-$4-$5");
81
+ if (!["user", "team"].includes(type)) {
82
+ throw new import_errors.StackAssertionError("Invalid type");
83
+ }
84
+ return { checksummablePart, checksum, id: restored_id, isCloudVersion, isPublic, prefix, type };
52
85
  }
53
- export function isApiKey(secret) {
54
- return secret.includes("_") && secret.includes(STACK_AUTH_MARKER);
86
+ function isApiKey(secret) {
87
+ return secret.includes("_") && secret.includes(STACK_AUTH_MARKER);
55
88
  }
56
- export function createProjectApiKey(options) {
57
- const { checksummablePart } = createApiKeyParts(options);
58
- const checksum = createChecksumSync(checksummablePart);
59
- return `${checksummablePart}${checksum}`;
89
+ function createProjectApiKey(options) {
90
+ const { checksummablePart } = createApiKeyParts(options);
91
+ const checksum = createChecksumSync(checksummablePart);
92
+ return `${checksummablePart}${checksum}`;
60
93
  }
61
- export function parseProjectApiKey(secret) {
62
- const { checksummablePart, checksum, id, isCloudVersion, isPublic, prefix, type } = parseApiKeyParts(secret);
63
- const calculated_checksum = createChecksumSync(checksummablePart);
64
- if (calculated_checksum !== checksum) {
65
- throw new StackAssertionError("Checksum mismatch");
66
- }
67
- return {
68
- id,
69
- prefix,
70
- isPublic,
71
- isCloudVersion,
72
- secret,
73
- checksum,
74
- type,
75
- };
94
+ function parseProjectApiKey(secret) {
95
+ const { checksummablePart, checksum, id, isCloudVersion, isPublic, prefix, type } = parseApiKeyParts(secret);
96
+ const calculated_checksum = createChecksumSync(checksummablePart);
97
+ if (calculated_checksum !== checksum) {
98
+ throw new import_errors.StackAssertionError("Checksum mismatch");
99
+ }
100
+ return {
101
+ id,
102
+ prefix,
103
+ isPublic,
104
+ isCloudVersion,
105
+ secret,
106
+ checksum,
107
+ type
108
+ };
76
109
  }
110
+ // Annotate the CommonJS export names for ESM import in node:
111
+ 0 && (module.exports = {
112
+ createProjectApiKey,
113
+ isApiKey,
114
+ parseProjectApiKey
115
+ });
116
+ //# sourceMappingURL=api-keys.js.map