@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/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @stackframe/stack-shared
2
2
 
3
+ ## 2.8.11
4
+
5
+ ### Patch Changes
6
+
7
+ - Various changes
8
+
9
+ ## 2.8.10
10
+
11
+ ### Patch Changes
12
+
13
+ - Various changes
14
+
15
+ ## 2.8.9
16
+
3
17
  ## 2.8.8
4
18
 
5
19
  ## 2.8.7
@@ -0,0 +1,39 @@
1
+ type ConfigValue = string | number | boolean | null | ConfigValue[] | Config;
2
+ type Config = {
3
+ [keyOrDotNotation: string]: ConfigValue | undefined;
4
+ };
5
+ type NormalizedConfigValue = string | number | boolean | NormalizedConfig | NormalizedConfigValue[];
6
+ type NormalizedConfig = {
7
+ [key: string]: NormalizedConfigValue | undefined;
8
+ };
9
+ type _NormalizesTo<N> = N extends object ? (Config & {
10
+ [K in keyof N]?: _NormalizesTo<N[K]> | null;
11
+ } & {
12
+ [K in `${string}.${string}`]: ConfigValue;
13
+ }) : N;
14
+ type NormalizesTo<N extends NormalizedConfig> = _NormalizesTo<N>;
15
+ /**
16
+ * Note that a config can both be valid and not normalizable.
17
+ */
18
+ declare function isValidConfig(c: unknown): c is Config;
19
+ declare function getInvalidConfigReason(c: unknown, options?: {
20
+ configName?: string;
21
+ }): string | undefined;
22
+ declare function assertValidConfig(c: unknown): void;
23
+ declare function override(c1: Config, ...configs: Config[]): Config;
24
+ type NormalizeOptions = {
25
+ /**
26
+ * What to do if a dot notation is used on null.
27
+ *
28
+ * - "empty" (default): Replace the null with an empty object.
29
+ * - "throw": Throw an error.
30
+ * - "ignore": Ignore the dot notation field.
31
+ */
32
+ onDotIntoNull?: "empty" | "throw" | "ignore";
33
+ };
34
+ declare class NormalizationError extends Error {
35
+ constructor(...args: ConstructorParameters<typeof Error>);
36
+ }
37
+ declare function normalize(c: Config, options?: NormalizeOptions): NormalizedConfig;
38
+
39
+ export { type Config, type ConfigValue, NormalizationError, type NormalizedConfig, type NormalizedConfigValue, type NormalizesTo, type _NormalizesTo, assertValidConfig, getInvalidConfigReason, isValidConfig, normalize, override };
@@ -1,26 +1,26 @@
1
- export type ConfigValue = string | number | boolean | null | ConfigValue[] | Config;
2
- export type Config = {
1
+ type ConfigValue = string | number | boolean | null | ConfigValue[] | Config;
2
+ type Config = {
3
3
  [keyOrDotNotation: string]: ConfigValue | undefined;
4
4
  };
5
- export type NormalizedConfigValue = string | number | boolean | NormalizedConfig | NormalizedConfigValue[];
6
- export type NormalizedConfig = {
5
+ type NormalizedConfigValue = string | number | boolean | NormalizedConfig | NormalizedConfigValue[];
6
+ type NormalizedConfig = {
7
7
  [key: string]: NormalizedConfigValue | undefined;
8
8
  };
9
- export type _NormalizesTo<N> = N extends object ? (Config & {
9
+ type _NormalizesTo<N> = N extends object ? (Config & {
10
10
  [K in keyof N]?: _NormalizesTo<N[K]> | null;
11
11
  } & {
12
12
  [K in `${string}.${string}`]: ConfigValue;
13
13
  }) : N;
14
- export type NormalizesTo<N extends NormalizedConfig> = _NormalizesTo<N>;
14
+ type NormalizesTo<N extends NormalizedConfig> = _NormalizesTo<N>;
15
15
  /**
16
16
  * Note that a config can both be valid and not normalizable.
17
17
  */
18
- export declare function isValidConfig(c: unknown): c is Config;
19
- export declare function getInvalidConfigReason(c: unknown, options?: {
18
+ declare function isValidConfig(c: unknown): c is Config;
19
+ declare function getInvalidConfigReason(c: unknown, options?: {
20
20
  configName?: string;
21
21
  }): string | undefined;
22
- export declare function assertValidConfig(c: unknown): void;
23
- export declare function override(c1: Config, ...configs: Config[]): Config;
22
+ declare function assertValidConfig(c: unknown): void;
23
+ declare function override(c1: Config, ...configs: Config[]): Config;
24
24
  type NormalizeOptions = {
25
25
  /**
26
26
  * What to do if a dot notation is used on null.
@@ -31,8 +31,9 @@ type NormalizeOptions = {
31
31
  */
32
32
  onDotIntoNull?: "empty" | "throw" | "ignore";
33
33
  };
34
- export declare class NormalizationError extends Error {
34
+ declare class NormalizationError extends Error {
35
35
  constructor(...args: ConstructorParameters<typeof Error>);
36
36
  }
37
- export declare function normalize(c: Config, options?: NormalizeOptions): NormalizedConfig;
38
- export {};
37
+ declare function normalize(c: Config, options?: NormalizeOptions): NormalizedConfig;
38
+
39
+ export { type Config, type ConfigValue, NormalizationError, type NormalizedConfig, type NormalizedConfigValue, type NormalizesTo, type _NormalizesTo, assertValidConfig, getInvalidConfigReason, isValidConfig, normalize, override };
@@ -1,224 +1,165 @@
1
- // see https://github.com/stack-auth/info/blob/main/eng-handbook/random-thoughts/config-json-format.md
2
- import { StackAssertionError, throwErr } from "../utils/errors";
3
- import { deleteKey, filterUndefined, get, hasAndNotUndefined, set } from "../utils/objects";
4
- /**
5
- * Note that a config can both be valid and not normalizable.
6
- */
7
- export function isValidConfig(c) {
8
- return getInvalidConfigReason(c) === undefined;
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/config/format.ts
21
+ var format_exports = {};
22
+ __export(format_exports, {
23
+ NormalizationError: () => NormalizationError,
24
+ assertValidConfig: () => assertValidConfig,
25
+ getInvalidConfigReason: () => getInvalidConfigReason,
26
+ isValidConfig: () => isValidConfig,
27
+ normalize: () => normalize,
28
+ override: () => override
29
+ });
30
+ module.exports = __toCommonJS(format_exports);
31
+ var import_errors = require("../utils/errors");
32
+ var import_objects = require("../utils/objects");
33
+ function isValidConfig(c) {
34
+ return getInvalidConfigReason(c) === void 0;
9
35
  }
10
- export function getInvalidConfigReason(c, options = {}) {
11
- const configName = options.configName ?? 'config';
12
- if (c === null || typeof c !== 'object')
13
- return `${configName} must be a non-null object`;
14
- for (const [key, value] of Object.entries(c)) {
15
- if (value === undefined)
16
- continue;
17
- if (typeof key !== 'string')
18
- return `${configName} must have only string keys (found: ${typeof key})`;
19
- if (!key.match(/^[a-zA-Z0-9_:$][a-zA-Z_:$0-9\-]*(?:\.[a-zA-Z0-9_:$][a-zA-Z_:$0-9\-]*)*$/))
20
- return `All keys of ${configName} must consist of only alphanumeric characters, dots, underscores, colons, dollar signs, or hyphens and start with a character other than a hyphen (found: ${key})`;
21
- const entryName = `${configName}.${key}`;
22
- const reason = getInvalidConfigValueReason(value, { valueName: entryName });
23
- if (reason)
24
- return reason;
25
- }
26
- return undefined;
36
+ function getInvalidConfigReason(c, options = {}) {
37
+ const configName = options.configName ?? "config";
38
+ if (c === null || typeof c !== "object") return `${configName} must be a non-null object`;
39
+ for (const [key, value] of Object.entries(c)) {
40
+ if (value === void 0) continue;
41
+ if (typeof key !== "string") return `${configName} must have only string keys (found: ${typeof key})`;
42
+ if (!key.match(/^[a-zA-Z0-9_:$][a-zA-Z_:$0-9\-]*(?:\.[a-zA-Z0-9_:$][a-zA-Z_:$0-9\-]*)*$/)) return `All keys of ${configName} must consist of only alphanumeric characters, dots, underscores, colons, dollar signs, or hyphens and start with a character other than a hyphen (found: ${key})`;
43
+ const entryName = `${configName}.${key}`;
44
+ const reason = getInvalidConfigValueReason(value, { valueName: entryName });
45
+ if (reason) return reason;
46
+ }
47
+ return void 0;
27
48
  }
28
49
  function getInvalidConfigValueReason(value, options = {}) {
29
- const valueName = options.valueName ?? 'value';
30
- switch (typeof value) {
31
- case 'string':
32
- case 'number':
33
- case 'boolean': {
34
- break;
35
- }
36
- case 'object': {
37
- if (value === null) {
38
- break;
39
- }
40
- else if (Array.isArray(value)) {
41
- for (const [index, v] of value.entries()) {
42
- const reason = getInvalidConfigValueReason(v, { valueName: `${valueName}[${index}]` });
43
- if (reason)
44
- return reason;
45
- }
46
- }
47
- else {
48
- const reason = getInvalidConfigReason(value, { configName: valueName });
49
- if (reason)
50
- return reason;
51
- }
52
- break;
53
- }
54
- default: {
55
- return `${valueName} has an invalid value type ${typeof value} (value: ${value})`;
50
+ const valueName = options.valueName ?? "value";
51
+ switch (typeof value) {
52
+ case "string":
53
+ case "number":
54
+ case "boolean": {
55
+ break;
56
+ }
57
+ case "object": {
58
+ if (value === null) {
59
+ break;
60
+ } else if (Array.isArray(value)) {
61
+ for (const [index, v] of value.entries()) {
62
+ const reason = getInvalidConfigValueReason(v, { valueName: `${valueName}[${index}]` });
63
+ if (reason) return reason;
56
64
  }
65
+ } else {
66
+ const reason = getInvalidConfigReason(value, { configName: valueName });
67
+ if (reason) return reason;
68
+ }
69
+ break;
57
70
  }
58
- return undefined;
59
- }
60
- export function assertValidConfig(c) {
61
- const reason = getInvalidConfigReason(c);
62
- if (reason)
63
- throw new StackAssertionError(`Invalid config: ${reason}`, { c });
64
- }
65
- export function override(c1, ...configs) {
66
- if (configs.length === 0)
67
- return c1;
68
- if (configs.length > 1)
69
- return override(override(c1, configs[0]), ...configs.slice(1));
70
- const c2 = configs[0];
71
- assertValidConfig(c1);
72
- assertValidConfig(c2);
73
- let result = c1;
74
- for (const key of Object.keys(filterUndefined(c2))) {
75
- result = Object.fromEntries(Object.entries(result).filter(([k]) => k !== key && !k.startsWith(key + '.')));
71
+ default: {
72
+ return `${valueName} has an invalid value type ${typeof value} (value: ${value})`;
76
73
  }
77
- return {
78
- ...result,
79
- ...filterUndefined(c2),
80
- };
74
+ }
75
+ return void 0;
81
76
  }
82
- import.meta.vitest?.test("override(...)", ({ expect }) => {
83
- expect(override({
84
- a: 1,
85
- b: 2,
86
- "c.d": 3,
87
- "c.e.f": 4,
88
- "c.g": 5,
89
- h: [6, { i: 7 }, 8],
90
- k: 123,
91
- l: undefined,
92
- }, {
93
- a: 9,
94
- "c.d": 10,
95
- "c.e": null,
96
- "h.0": 11,
97
- "h.1": {
98
- j: 12,
99
- },
100
- k: undefined,
101
- })).toEqual({
102
- a: 9,
103
- b: 2,
104
- "c.d": 10,
105
- "c.e": null,
106
- "c.g": 5,
107
- h: [6, { i: 7 }, 8],
108
- "h.0": 11,
109
- "h.1": {
110
- j: 12,
111
- },
112
- k: 123,
113
- l: undefined,
114
- });
115
- });
116
- export class NormalizationError extends Error {
117
- constructor(...args) {
118
- super(...args);
119
- }
77
+ function assertValidConfig(c) {
78
+ const reason = getInvalidConfigReason(c);
79
+ if (reason) throw new import_errors.StackAssertionError(`Invalid config: ${reason}`, { c });
80
+ }
81
+ function override(c1, ...configs) {
82
+ if (configs.length === 0) return c1;
83
+ if (configs.length > 1) return override(override(c1, configs[0]), ...configs.slice(1));
84
+ const c2 = configs[0];
85
+ assertValidConfig(c1);
86
+ assertValidConfig(c2);
87
+ let result = c1;
88
+ for (const key of Object.keys((0, import_objects.filterUndefined)(c2))) {
89
+ result = Object.fromEntries(
90
+ Object.entries(result).filter(([k]) => k !== key && !k.startsWith(key + "."))
91
+ );
92
+ }
93
+ return {
94
+ ...result,
95
+ ...(0, import_objects.filterUndefined)(c2)
96
+ };
120
97
  }
98
+ var NormalizationError = class extends Error {
99
+ constructor(...args) {
100
+ super(...args);
101
+ }
102
+ };
121
103
  NormalizationError.prototype.name = "NormalizationError";
122
- export function normalize(c, options = {}) {
123
- assertValidConfig(c);
124
- const onDotIntoNull = options.onDotIntoNull ?? "empty";
125
- const countDots = (s) => s.match(/\./g)?.length ?? 0;
126
- const result = {};
127
- const keysByDepth = Object.keys(c).sort((a, b) => countDots(a) - countDots(b));
128
- outer: for (const key of keysByDepth) {
129
- const keySegmentsWithoutLast = key.split('.');
130
- const last = keySegmentsWithoutLast.pop() ?? throwErr('split returns empty array?');
131
- const value = get(c, key);
132
- if (value === undefined)
133
- continue;
134
- let current = result;
135
- for (const keySegment of keySegmentsWithoutLast) {
136
- if (!hasAndNotUndefined(current, keySegment)) {
137
- switch (onDotIntoNull) {
138
- case "empty": {
139
- set(current, keySegment, {});
140
- break;
141
- }
142
- case "throw": {
143
- throw new NormalizationError(`Tried to use dot notation to access ${JSON.stringify(key)}, but ${JSON.stringify(keySegment)} doesn't exist on the object (or is null). Maybe this config is not normalizable?`);
144
- }
145
- case "ignore": {
146
- continue outer;
147
- }
148
- }
149
- }
150
- const value = get(current, keySegment);
151
- if (typeof value !== 'object') {
152
- throw new NormalizationError(`Tried to use dot notation to access ${JSON.stringify(key)}, but ${JSON.stringify(keySegment)} is not an object. Maybe this config is not normalizable?`);
153
- }
154
- current = value;
104
+ function normalize(c, options = {}) {
105
+ assertValidConfig(c);
106
+ const onDotIntoNull = options.onDotIntoNull ?? "empty";
107
+ const countDots = (s) => s.match(/\./g)?.length ?? 0;
108
+ const result = {};
109
+ const keysByDepth = Object.keys(c).sort((a, b) => countDots(a) - countDots(b));
110
+ outer: for (const key of keysByDepth) {
111
+ const keySegmentsWithoutLast = key.split(".");
112
+ const last = keySegmentsWithoutLast.pop() ?? (0, import_errors.throwErr)("split returns empty array?");
113
+ const value = (0, import_objects.get)(c, key);
114
+ if (value === void 0) continue;
115
+ let current = result;
116
+ for (const keySegment of keySegmentsWithoutLast) {
117
+ if (!(0, import_objects.hasAndNotUndefined)(current, keySegment)) {
118
+ switch (onDotIntoNull) {
119
+ case "empty": {
120
+ (0, import_objects.set)(current, keySegment, {});
121
+ break;
122
+ }
123
+ case "throw": {
124
+ throw new NormalizationError(`Tried to use dot notation to access ${JSON.stringify(key)}, but ${JSON.stringify(keySegment)} doesn't exist on the object (or is null). Maybe this config is not normalizable?`);
125
+ }
126
+ case "ignore": {
127
+ continue outer;
128
+ }
155
129
  }
156
- setNormalizedValue(current, last, value);
130
+ }
131
+ const value2 = (0, import_objects.get)(current, keySegment);
132
+ if (typeof value2 !== "object") {
133
+ throw new NormalizationError(`Tried to use dot notation to access ${JSON.stringify(key)}, but ${JSON.stringify(keySegment)} is not an object. Maybe this config is not normalizable?`);
134
+ }
135
+ current = value2;
157
136
  }
158
- return result;
137
+ setNormalizedValue(current, last, value);
138
+ }
139
+ return result;
159
140
  }
160
141
  function normalizeValue(value) {
161
- if (value === null)
162
- throw new NormalizationError("Tried to normalize a null value");
163
- if (Array.isArray(value))
164
- return value.map(normalizeValue);
165
- if (typeof value === 'object')
166
- return normalize(value);
167
- return value;
142
+ if (value === null) throw new NormalizationError("Tried to normalize a null value");
143
+ if (Array.isArray(value)) return value.map(normalizeValue);
144
+ if (typeof value === "object") return normalize(value);
145
+ return value;
168
146
  }
169
147
  function setNormalizedValue(result, key, value) {
170
- if (value === null) {
171
- if (hasAndNotUndefined(result, key)) {
172
- deleteKey(result, key);
173
- }
174
- }
175
- else {
176
- set(result, key, normalizeValue(value));
148
+ if (value === null) {
149
+ if ((0, import_objects.hasAndNotUndefined)(result, key)) {
150
+ (0, import_objects.deleteKey)(result, key);
177
151
  }
152
+ } else {
153
+ (0, import_objects.set)(result, key, normalizeValue(value));
154
+ }
178
155
  }
179
- import.meta.vitest?.test("normalize(...)", ({ expect }) => {
180
- expect(normalize({
181
- a: 9,
182
- b: 2,
183
- c: {},
184
- "c.d": 10,
185
- "c.e": null,
186
- "c.g": 5,
187
- h: [6, { i: 7 }, 8],
188
- "h.0": 11,
189
- "h.1": {
190
- j: 12,
191
- },
192
- k: { l: {} },
193
- "k.l.m": 13,
194
- n: undefined,
195
- })).toEqual({
196
- a: 9,
197
- b: 2,
198
- c: {
199
- d: 10,
200
- g: 5,
201
- },
202
- h: [11, { j: 12 }, 8],
203
- k: { l: { m: 13 } },
204
- });
205
- // dotting into null
206
- expect(normalize({
207
- "b.c": 2,
208
- })).toEqual({ b: { c: 2 } });
209
- expect(() => normalize({
210
- "b.c": 2,
211
- }, { onDotIntoNull: "throw" })).toThrow(`Tried to use dot notation to access "b.c", but "b" doesn't exist on the object (or is null). Maybe this config is not normalizable?`);
212
- expect(() => normalize({
213
- b: null,
214
- "b.c": 2,
215
- }, { onDotIntoNull: "throw" })).toThrow(`Tried to use dot notation to access "b.c", but "b" doesn't exist on the object (or is null). Maybe this config is not normalizable?`);
216
- expect(normalize({
217
- "b.c": 2,
218
- }, { onDotIntoNull: "ignore" })).toEqual({});
219
- // dotting into non-object
220
- expect(() => normalize({
221
- b: 1,
222
- "b.c": 2,
223
- })).toThrow(`Tried to use dot notation to access "b.c", but "b" is not an object. Maybe this config is not normalizable?`);
156
+ // Annotate the CommonJS export names for ESM import in node:
157
+ 0 && (module.exports = {
158
+ NormalizationError,
159
+ assertValidConfig,
160
+ getInvalidConfigReason,
161
+ isValidConfig,
162
+ normalize,
163
+ override
224
164
  });
165
+ //# sourceMappingURL=format.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/config/format.ts"],"sourcesContent":["// see https://github.com/stack-auth/info/blob/main/eng-handbook/random-thoughts/config-json-format.md\n\nimport { StackAssertionError, throwErr } from \"../utils/errors\";\nimport { deleteKey, filterUndefined, get, hasAndNotUndefined, set } from \"../utils/objects\";\n\n\nexport type ConfigValue = string | number | boolean | null | ConfigValue[] | Config;\nexport type Config = {\n [keyOrDotNotation: string]: ConfigValue | undefined, // must support undefined for optional values\n};\n\nexport type NormalizedConfigValue = string | number | boolean | NormalizedConfig | NormalizedConfigValue[];\nexport type NormalizedConfig = {\n [key: string]: NormalizedConfigValue | undefined, // must support undefined for optional values\n};\n\nexport type _NormalizesTo<N> = N extends object ? (\n & Config\n & { [K in keyof N]?: _NormalizesTo<N[K]> | null }\n & { [K in `${string}.${string}`]: ConfigValue }\n) : N;\nexport type NormalizesTo<N extends NormalizedConfig> = _NormalizesTo<N>;\n\n/**\n * Note that a config can both be valid and not normalizable.\n */\nexport function isValidConfig(c: unknown): c is Config {\n return getInvalidConfigReason(c) === undefined;\n}\n\nexport function getInvalidConfigReason(c: unknown, options: { configName?: string } = {}): string | undefined {\n const configName = options.configName ?? 'config';\n if (c === null || typeof c !== 'object') return `${configName} must be a non-null object`;\n for (const [key, value] of Object.entries(c)) {\n if (value === undefined) continue;\n if (typeof key !== 'string') return `${configName} must have only string keys (found: ${typeof key})`;\n if (!key.match(/^[a-zA-Z0-9_:$][a-zA-Z_:$0-9\\-]*(?:\\.[a-zA-Z0-9_:$][a-zA-Z_:$0-9\\-]*)*$/)) return `All keys of ${configName} must consist of only alphanumeric characters, dots, underscores, colons, dollar signs, or hyphens and start with a character other than a hyphen (found: ${key})`;\n\n const entryName = `${configName}.${key}`;\n const reason = getInvalidConfigValueReason(value, { valueName: entryName });\n if (reason) return reason;\n }\n return undefined;\n}\n\nfunction getInvalidConfigValueReason(value: unknown, options: { valueName?: string } = {}): string | undefined {\n const valueName = options.valueName ?? 'value';\n switch (typeof value) {\n case 'string':\n case 'number':\n case 'boolean': {\n break;\n }\n case 'object': {\n if (value === null) {\n break;\n } else if (Array.isArray(value)) {\n for (const [index, v] of value.entries()) {\n const reason = getInvalidConfigValueReason(v, { valueName: `${valueName}[${index}]` });\n if (reason) return reason;\n }\n } else {\n const reason = getInvalidConfigReason(value, { configName: valueName });\n if (reason) return reason;\n }\n break;\n }\n default: {\n return `${valueName} has an invalid value type ${typeof value} (value: ${value})`;\n }\n }\n return undefined;\n}\n\nexport function assertValidConfig(c: unknown) {\n const reason = getInvalidConfigReason(c);\n if (reason) throw new StackAssertionError(`Invalid config: ${reason}`, { c });\n}\n\nexport function override(c1: Config, ...configs: Config[]) {\n if (configs.length === 0) return c1;\n if (configs.length > 1) return override(override(c1, configs[0]), ...configs.slice(1));\n const c2 = configs[0];\n\n assertValidConfig(c1);\n assertValidConfig(c2);\n\n let result = c1;\n for (const key of Object.keys(filterUndefined(c2))) {\n result = Object.fromEntries(\n Object.entries(result).filter(([k]) => k !== key && !k.startsWith(key + '.'))\n );\n }\n\n return {\n ...result,\n ...filterUndefined(c2),\n };\n}\n\nundefined?.test(\"override(...)\", ({ expect }) => {\n expect(\n override(\n {\n a: 1,\n b: 2,\n \"c.d\": 3,\n \"c.e.f\": 4,\n \"c.g\": 5,\n h: [6, { i: 7 }, 8],\n k: 123,\n l: undefined,\n },\n {\n a: 9,\n \"c.d\": 10,\n \"c.e\": null,\n \"h.0\": 11,\n \"h.1\": {\n j: 12,\n },\n k: undefined,\n },\n )\n ).toEqual({\n a: 9,\n b: 2,\n \"c.d\": 10,\n \"c.e\": null,\n \"c.g\": 5,\n h: [6, { i: 7 }, 8],\n \"h.0\": 11,\n \"h.1\": {\n j: 12,\n },\n k: 123,\n l: undefined,\n });\n});\n\ntype NormalizeOptions = {\n /**\n * What to do if a dot notation is used on null.\n *\n * - \"empty\" (default): Replace the null with an empty object.\n * - \"throw\": Throw an error.\n * - \"ignore\": Ignore the dot notation field.\n */\n onDotIntoNull?: \"empty\" | \"throw\" | \"ignore\",\n}\n\nexport class NormalizationError extends Error {\n constructor(...args: ConstructorParameters<typeof Error>) {\n super(...args);\n }\n}\nNormalizationError.prototype.name = \"NormalizationError\";\n\nexport function normalize(c: Config, options: NormalizeOptions = {}): NormalizedConfig {\n assertValidConfig(c);\n const onDotIntoNull = options.onDotIntoNull ?? \"empty\";\n\n const countDots = (s: string) => s.match(/\\./g)?.length ?? 0;\n const result: NormalizedConfig = {};\n const keysByDepth = Object.keys(c).sort((a, b) => countDots(a) - countDots(b));\n\n outer: for (const key of keysByDepth) {\n const keySegmentsWithoutLast = key.split('.');\n const last = keySegmentsWithoutLast.pop() ?? throwErr('split returns empty array?');\n const value = get(c, key);\n if (value === undefined) continue;\n\n let current: NormalizedConfig = result;\n for (const keySegment of keySegmentsWithoutLast) {\n if (!hasAndNotUndefined(current, keySegment)) {\n switch (onDotIntoNull) {\n case \"empty\": {\n set(current, keySegment, {});\n break;\n }\n case \"throw\": {\n throw new NormalizationError(`Tried to use dot notation to access ${JSON.stringify(key)}, but ${JSON.stringify(keySegment)} doesn't exist on the object (or is null). Maybe this config is not normalizable?`);\n }\n case \"ignore\": {\n continue outer;\n }\n }\n }\n const value = get(current, keySegment);\n if (typeof value !== 'object') {\n throw new NormalizationError(`Tried to use dot notation to access ${JSON.stringify(key)}, but ${JSON.stringify(keySegment)} is not an object. Maybe this config is not normalizable?`);\n }\n current = value as NormalizedConfig;\n }\n setNormalizedValue(current, last, value);\n }\n return result;\n}\n\nfunction normalizeValue(value: ConfigValue): NormalizedConfigValue {\n if (value === null) throw new NormalizationError(\"Tried to normalize a null value\");\n if (Array.isArray(value)) return value.map(normalizeValue);\n if (typeof value === 'object') return normalize(value);\n return value;\n}\n\nfunction setNormalizedValue(result: NormalizedConfig, key: string, value: ConfigValue) {\n if (value === null) {\n if (hasAndNotUndefined(result, key)) {\n deleteKey(result, key);\n }\n } else {\n set(result, key, normalizeValue(value));\n }\n}\n\nundefined?.test(\"normalize(...)\", ({ expect }) => {\n expect(normalize({\n a: 9,\n b: 2,\n c: {},\n \"c.d\": 10,\n \"c.e\": null,\n \"c.g\": 5,\n h: [6, { i: 7 }, 8],\n \"h.0\": 11,\n \"h.1\": {\n j: 12,\n },\n k: { l: {} },\n \"k.l.m\": 13,\n n: undefined,\n })).toEqual({\n a: 9,\n b: 2,\n c: {\n d: 10,\n g: 5,\n },\n h: [11, { j: 12 }, 8],\n k: { l: { m: 13 } },\n });\n\n // dotting into null\n expect(normalize({\n \"b.c\": 2,\n })).toEqual({ b: { c: 2 } });\n expect(() => normalize({\n \"b.c\": 2,\n }, { onDotIntoNull: \"throw\" })).toThrow(`Tried to use dot notation to access \"b.c\", but \"b\" doesn't exist on the object (or is null). Maybe this config is not normalizable?`);\n expect(() => normalize({\n b: null,\n \"b.c\": 2,\n }, { onDotIntoNull: \"throw\" })).toThrow(`Tried to use dot notation to access \"b.c\", but \"b\" doesn't exist on the object (or is null). Maybe this config is not normalizable?`);\n expect(normalize({\n \"b.c\": 2,\n }, { onDotIntoNull: \"ignore\" })).toEqual({});\n\n // dotting into non-object\n expect(() => normalize({\n b: 1,\n \"b.c\": 2,\n })).toThrow(`Tried to use dot notation to access \"b.c\", but \"b\" is not an object. Maybe this config is not normalizable?`);\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,oBAA8C;AAC9C,qBAAyE;AAuBlE,S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