@hexclave/shared 1.0.2 → 1.0.5

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 (353) hide show
  1. package/dist/ai/unified-prompts/reminders.js +4 -3
  2. package/dist/ai/unified-prompts/reminders.js.map +1 -1
  3. package/dist/ai/unified-prompts/skill-site-prompt-parts/ai-setup-prompt.d.ts +3 -1
  4. package/dist/ai/unified-prompts/skill-site-prompt-parts/ai-setup-prompt.d.ts.map +1 -1
  5. package/dist/ai/unified-prompts/skill-site-prompt-parts/ai-setup-prompt.js +217 -30
  6. package/dist/ai/unified-prompts/skill-site-prompt-parts/ai-setup-prompt.js.map +1 -1
  7. package/dist/ai/unified-prompts/skill-site-prompt-parts/docs-index.d.ts.map +1 -1
  8. package/dist/ai/unified-prompts/skill-site-prompt-parts/docs-index.js +1 -0
  9. package/dist/ai/unified-prompts/skill-site-prompt-parts/docs-index.js.map +1 -1
  10. package/dist/ai/unified-prompts/skill-site-prompt-parts/docs-json.generated.d.ts +18 -6
  11. package/dist/ai/unified-prompts/skill-site-prompt-parts/docs-json.generated.js +23 -8
  12. package/dist/ai/unified-prompts/skill-site-prompt-parts/docs-json.generated.js.map +1 -1
  13. package/dist/ai/unified-prompts/skill-site-prompt-parts/openapi-specs.js +1 -1
  14. package/dist/ai/unified-prompts/skill-site-prompt-parts/openapi-specs.js.map +1 -1
  15. package/dist/config/schema.d.ts +63 -63
  16. package/dist/config/schema.d.ts.map +1 -1
  17. package/dist/config/schema.js +5 -5
  18. package/dist/config/schema.js.map +1 -1
  19. package/dist/config-authoring.d.ts +4 -4
  20. package/dist/config-authoring.d.ts.map +1 -1
  21. package/dist/config-authoring.js +2 -2
  22. package/dist/config-authoring.js.map +1 -1
  23. package/dist/config-rendering.d.ts +4 -4
  24. package/dist/config-rendering.d.ts.map +1 -1
  25. package/dist/config-rendering.js +19 -18
  26. package/dist/config-rendering.js.map +1 -1
  27. package/dist/esm/ai/unified-prompts/reminders.js +4 -3
  28. package/dist/esm/ai/unified-prompts/reminders.js.map +1 -1
  29. package/dist/esm/ai/unified-prompts/skill-site-prompt-parts/ai-setup-prompt.d.ts +3 -1
  30. package/dist/esm/ai/unified-prompts/skill-site-prompt-parts/ai-setup-prompt.d.ts.map +1 -1
  31. package/dist/esm/ai/unified-prompts/skill-site-prompt-parts/ai-setup-prompt.js +216 -31
  32. package/dist/esm/ai/unified-prompts/skill-site-prompt-parts/ai-setup-prompt.js.map +1 -1
  33. package/dist/esm/ai/unified-prompts/skill-site-prompt-parts/docs-index.d.ts.map +1 -1
  34. package/dist/esm/ai/unified-prompts/skill-site-prompt-parts/docs-index.js +1 -0
  35. package/dist/esm/ai/unified-prompts/skill-site-prompt-parts/docs-index.js.map +1 -1
  36. package/dist/esm/ai/unified-prompts/skill-site-prompt-parts/docs-json.generated.d.ts +18 -6
  37. package/dist/esm/ai/unified-prompts/skill-site-prompt-parts/docs-json.generated.js +23 -8
  38. package/dist/esm/ai/unified-prompts/skill-site-prompt-parts/docs-json.generated.js.map +1 -1
  39. package/dist/esm/ai/unified-prompts/skill-site-prompt-parts/openapi-specs.js +1 -1
  40. package/dist/esm/ai/unified-prompts/skill-site-prompt-parts/openapi-specs.js.map +1 -1
  41. package/dist/esm/config/schema.d.ts +63 -63
  42. package/dist/esm/config/schema.d.ts.map +1 -1
  43. package/dist/esm/config/schema.js +5 -5
  44. package/dist/esm/config/schema.js.map +1 -1
  45. package/dist/esm/config-authoring.d.ts +4 -4
  46. package/dist/esm/config-authoring.d.ts.map +1 -1
  47. package/dist/esm/config-authoring.js +2 -2
  48. package/dist/esm/config-authoring.js.map +1 -1
  49. package/dist/esm/config-rendering.d.ts +4 -4
  50. package/dist/esm/config-rendering.d.ts.map +1 -1
  51. package/dist/esm/config-rendering.js +15 -14
  52. package/dist/esm/config-rendering.js.map +1 -1
  53. package/dist/esm/helpers/vault/client-side.d.ts.map +1 -1
  54. package/dist/esm/helpers/vault/client-side.js.map +1 -1
  55. package/dist/esm/helpers/vault/server-side.d.ts.map +1 -1
  56. package/dist/esm/helpers/vault/server-side.js.map +1 -1
  57. package/dist/esm/hexclave-config-file.d.ts +15 -0
  58. package/dist/esm/hexclave-config-file.d.ts.map +1 -0
  59. package/dist/esm/{stack-config-file.js → hexclave-config-file.js} +7 -7
  60. package/dist/esm/hexclave-config-file.js.map +1 -0
  61. package/dist/esm/hooks/use-async-callback.js +1 -1
  62. package/dist/esm/hooks/use-async-external-store.js +1 -1
  63. package/dist/esm/hooks/use-strict-memo.js +1 -1
  64. package/dist/esm/interface/admin-metrics.d.ts +8 -8
  65. package/dist/esm/interface/admin-metrics.js.map +1 -1
  66. package/dist/esm/interface/client-interface.js +2 -2
  67. package/dist/esm/interface/client-interface.js.map +1 -1
  68. package/dist/esm/interface/conversations.d.ts +32 -32
  69. package/dist/esm/interface/crud/current-user.d.ts +9 -9
  70. package/dist/esm/interface/crud/email-outbox.d.ts +200 -200
  71. package/dist/esm/interface/crud/products.d.ts +13 -13
  72. package/dist/esm/interface/crud/products.d.ts.map +1 -1
  73. package/dist/esm/interface/crud/project-api-keys.d.ts +4 -4
  74. package/dist/esm/interface/crud/project-permissions.js +5 -5
  75. package/dist/esm/interface/crud/project-permissions.js.map +1 -1
  76. package/dist/esm/interface/crud/projects.d.ts +36 -36
  77. package/dist/esm/interface/crud/team-member-profiles.d.ts +18 -18
  78. package/dist/esm/interface/crud/team-permissions.js +5 -5
  79. package/dist/esm/interface/crud/team-permissions.js.map +1 -1
  80. package/dist/esm/interface/crud/transactions.d.ts +6 -6
  81. package/dist/esm/interface/crud/transactions.d.ts.map +1 -1
  82. package/dist/esm/interface/crud/users.d.ts +12 -12
  83. package/dist/esm/interface/page-component-versions.js +107 -107
  84. package/dist/esm/interface/page-component-versions.js.map +1 -1
  85. package/dist/esm/interface/webhooks.d.ts +2 -2
  86. package/dist/esm/known-errors.d.ts +2 -2
  87. package/dist/esm/known-errors.js +4 -4
  88. package/dist/esm/known-errors.js.map +1 -1
  89. package/dist/esm/schema-fields.d.ts +17 -7
  90. package/dist/esm/schema-fields.d.ts.map +1 -1
  91. package/dist/esm/schema-fields.js +26 -16
  92. package/dist/esm/schema-fields.js.map +1 -1
  93. package/dist/esm/sessions.d.ts +7 -7
  94. package/dist/esm/utils/crypto.d.ts.map +1 -1
  95. package/dist/esm/utils/crypto.js.map +1 -1
  96. package/dist/esm/utils/currency-constants.d.ts +6 -0
  97. package/dist/esm/utils/currency-constants.d.ts.map +1 -1
  98. package/dist/esm/utils/currency-constants.js.map +1 -1
  99. package/dist/esm/utils/dev-env-state-path.d.ts +3 -3
  100. package/dist/esm/utils/dev-env-state-path.d.ts.map +1 -1
  101. package/dist/esm/utils/dev-env-state-path.js +4 -4
  102. package/dist/esm/utils/dev-env-state-path.js.map +1 -1
  103. package/dist/esm/utils/errors.js +2 -2
  104. package/dist/esm/utils/errors.js.map +1 -1
  105. package/dist/esm/utils/esbuild.d.ts.map +1 -1
  106. package/dist/esm/utils/esbuild.js +0 -1
  107. package/dist/esm/utils/esbuild.js.map +1 -1
  108. package/dist/esm/utils/featurebase.d.ts +3 -3
  109. package/dist/esm/utils/featurebase.d.ts.map +1 -1
  110. package/dist/esm/utils/featurebase.js +15 -15
  111. package/dist/esm/utils/featurebase.js.map +1 -1
  112. package/dist/esm/utils/fs.js +6 -6
  113. package/dist/esm/utils/fs.js.map +1 -1
  114. package/dist/esm/utils/globals.d.ts.map +1 -1
  115. package/dist/esm/utils/globals.js +10 -10
  116. package/dist/esm/utils/globals.js.map +1 -1
  117. package/dist/esm/utils/jwt.d.ts.map +1 -1
  118. package/dist/esm/utils/jwt.js +3 -3
  119. package/dist/esm/utils/jwt.js.map +1 -1
  120. package/dist/esm/utils/redirect-urls.d.ts +3 -3
  121. package/dist/esm/utils/redirect-urls.d.ts.map +1 -1
  122. package/dist/esm/utils/redirect-urls.js +5 -5
  123. package/dist/esm/utils/redirect-urls.js.map +1 -1
  124. package/dist/esm/utils/urls.js.map +1 -1
  125. package/dist/helpers/vault/client-side.d.ts.map +1 -1
  126. package/dist/helpers/vault/client-side.js.map +1 -1
  127. package/dist/helpers/vault/server-side.d.ts.map +1 -1
  128. package/dist/helpers/vault/server-side.js.map +1 -1
  129. package/dist/hexclave-config-file.d.ts +15 -0
  130. package/dist/hexclave-config-file.d.ts.map +1 -0
  131. package/dist/{stack-config-file.js → hexclave-config-file.js} +8 -8
  132. package/dist/hexclave-config-file.js.map +1 -0
  133. package/dist/hooks/use-async-callback.js +1 -1
  134. package/dist/hooks/use-async-external-store.js +1 -1
  135. package/dist/hooks/use-strict-memo.js +1 -1
  136. package/dist/interface/admin-metrics.d.ts +8 -8
  137. package/dist/interface/admin-metrics.js.map +1 -1
  138. package/dist/interface/client-interface.js +2 -2
  139. package/dist/interface/client-interface.js.map +1 -1
  140. package/dist/interface/conversations.d.ts +32 -32
  141. package/dist/interface/crud/current-user.d.ts +9 -9
  142. package/dist/interface/crud/email-outbox.d.ts +200 -200
  143. package/dist/interface/crud/products.d.ts +13 -13
  144. package/dist/interface/crud/products.d.ts.map +1 -1
  145. package/dist/interface/crud/project-api-keys.d.ts +4 -4
  146. package/dist/interface/crud/project-permissions.js +5 -5
  147. package/dist/interface/crud/project-permissions.js.map +1 -1
  148. package/dist/interface/crud/projects.d.ts +36 -36
  149. package/dist/interface/crud/team-member-profiles.d.ts +18 -18
  150. package/dist/interface/crud/team-permissions.js +5 -5
  151. package/dist/interface/crud/team-permissions.js.map +1 -1
  152. package/dist/interface/crud/transactions.d.ts +6 -6
  153. package/dist/interface/crud/transactions.d.ts.map +1 -1
  154. package/dist/interface/crud/users.d.ts +12 -12
  155. package/dist/interface/page-component-versions.js +107 -107
  156. package/dist/interface/page-component-versions.js.map +1 -1
  157. package/dist/interface/webhooks.d.ts +2 -2
  158. package/dist/known-errors.d.ts +2 -2
  159. package/dist/known-errors.js +4 -4
  160. package/dist/known-errors.js.map +1 -1
  161. package/dist/schema-fields.d.ts +17 -7
  162. package/dist/schema-fields.d.ts.map +1 -1
  163. package/dist/schema-fields.js +26 -16
  164. package/dist/schema-fields.js.map +1 -1
  165. package/dist/sessions.d.ts +7 -7
  166. package/dist/utils/crypto.d.ts.map +1 -1
  167. package/dist/utils/crypto.js.map +1 -1
  168. package/dist/utils/currency-constants.d.ts +6 -0
  169. package/dist/utils/currency-constants.d.ts.map +1 -1
  170. package/dist/utils/currency-constants.js.map +1 -1
  171. package/dist/utils/dev-env-state-path.d.ts +3 -3
  172. package/dist/utils/dev-env-state-path.d.ts.map +1 -1
  173. package/dist/utils/dev-env-state-path.js +5 -5
  174. package/dist/utils/dev-env-state-path.js.map +1 -1
  175. package/dist/utils/errors.js +2 -2
  176. package/dist/utils/errors.js.map +1 -1
  177. package/dist/utils/esbuild.d.ts.map +1 -1
  178. package/dist/utils/esbuild.js +0 -1
  179. package/dist/utils/esbuild.js.map +1 -1
  180. package/dist/utils/featurebase.d.ts +3 -3
  181. package/dist/utils/featurebase.d.ts.map +1 -1
  182. package/dist/utils/featurebase.js +15 -15
  183. package/dist/utils/featurebase.js.map +1 -1
  184. package/dist/utils/fs.js.map +1 -1
  185. package/dist/utils/globals.d.ts.map +1 -1
  186. package/dist/utils/globals.js +10 -10
  187. package/dist/utils/globals.js.map +1 -1
  188. package/dist/utils/jwt.d.ts.map +1 -1
  189. package/dist/utils/jwt.js +3 -3
  190. package/dist/utils/jwt.js.map +1 -1
  191. package/dist/utils/redirect-urls.d.ts +3 -3
  192. package/dist/utils/redirect-urls.d.ts.map +1 -1
  193. package/dist/utils/redirect-urls.js +5 -5
  194. package/dist/utils/redirect-urls.js.map +1 -1
  195. package/dist/utils/urls.js.map +1 -1
  196. package/package.json +2 -1
  197. package/src/ai/image-limits.ts +62 -0
  198. package/src/ai/llms/llms.ts +36 -0
  199. package/src/ai/unified-prompts/reminders.ts +27 -0
  200. package/src/ai/unified-prompts/skill-site-prompt-parts/ai-setup-prompt.ts +1047 -0
  201. package/src/ai/unified-prompts/skill-site-prompt-parts/brain.ts +5 -0
  202. package/src/ai/unified-prompts/skill-site-prompt-parts/cli-help.ts +5 -0
  203. package/src/ai/unified-prompts/skill-site-prompt-parts/config-docs.ts +5 -0
  204. package/src/ai/unified-prompts/skill-site-prompt-parts/custom-components-instructions.ts +5 -0
  205. package/src/ai/unified-prompts/skill-site-prompt-parts/dashboard-instructions.ts +5 -0
  206. package/src/ai/unified-prompts/skill-site-prompt-parts/docs-index.ts +80 -0
  207. package/src/ai/unified-prompts/skill-site-prompt-parts/docs-json.generated.ts +322 -0
  208. package/src/ai/unified-prompts/skill-site-prompt-parts/openapi-specs.ts +5 -0
  209. package/src/ai/unified-prompts/skill-site-prompt-parts/sdk-interface-source.ts +5 -0
  210. package/src/ai/unified-prompts/skill-site-prompt.ts +72 -0
  211. package/src/apps/apps-config.ts +177 -0
  212. package/src/apps/apps-ui.tsx +112 -0
  213. package/src/config/README.md +154 -0
  214. package/src/config/db-sync-mappings.ts +2293 -0
  215. package/src/config/format.ts +388 -0
  216. package/src/config/migrate-catalogs-to-product-lines.ts +475 -0
  217. package/src/config/schema-fuzzer.test.ts +377 -0
  218. package/src/config/schema.ts +1507 -0
  219. package/src/config-authoring.test.ts +52 -0
  220. package/src/config-authoring.ts +37 -0
  221. package/src/config-rendering.ts +142 -0
  222. package/src/crud.tsx +275 -0
  223. package/src/global.d.ts +1 -0
  224. package/src/helpers/emails.ts +250 -0
  225. package/src/helpers/init-prompt.ts +39 -0
  226. package/src/helpers/password.ts +16 -0
  227. package/src/helpers/production-mode.ts +58 -0
  228. package/src/helpers/support-sla.test.ts +124 -0
  229. package/src/helpers/support-sla.ts +93 -0
  230. package/src/helpers/vault/client-side.ts +92 -0
  231. package/src/helpers/vault/server-side.ts +153 -0
  232. package/src/hexclave-config-file.ts +120 -0
  233. package/src/hooks/use-async-callback.tsx +43 -0
  234. package/src/hooks/use-async-external-store.tsx +24 -0
  235. package/src/hooks/use-hash.tsx +14 -0
  236. package/src/hooks/use-hover.tsx +88 -0
  237. package/src/hooks/use-strict-memo.tsx +157 -0
  238. package/src/index.ts +17 -0
  239. package/src/interface/admin-interface.ts +1043 -0
  240. package/src/interface/admin-metrics.ts +214 -0
  241. package/src/interface/client-interface.test.ts +765 -0
  242. package/src/interface/client-interface.ts +2586 -0
  243. package/src/interface/conversations.ts +109 -0
  244. package/src/interface/crud/analytics.ts +11 -0
  245. package/src/interface/crud/connected-accounts.ts +52 -0
  246. package/src/interface/crud/contact-channels.ts +74 -0
  247. package/src/interface/crud/current-user.ts +72 -0
  248. package/src/interface/crud/email-outbox.ts +263 -0
  249. package/src/interface/crud/email-templates.ts +50 -0
  250. package/src/interface/crud/emails.ts +22 -0
  251. package/src/interface/crud/internal-api-keys.ts +69 -0
  252. package/src/interface/crud/invoices.ts +36 -0
  253. package/src/interface/crud/items.ts +24 -0
  254. package/src/interface/crud/notification-preferences.ts +33 -0
  255. package/src/interface/crud/oauth-providers.ts +91 -0
  256. package/src/interface/crud/products.ts +42 -0
  257. package/src/interface/crud/project-api-keys.ts +100 -0
  258. package/src/interface/crud/project-permissions.ts +118 -0
  259. package/src/interface/crud/projects.ts +229 -0
  260. package/src/interface/crud/session-replays.ts +85 -0
  261. package/src/interface/crud/sessions.ts +66 -0
  262. package/src/interface/crud/sign-up-rules.ts +12 -0
  263. package/src/interface/crud/svix-token.ts +20 -0
  264. package/src/interface/crud/team-invitation-details.ts +22 -0
  265. package/src/interface/crud/team-invitation.ts +35 -0
  266. package/src/interface/crud/team-member-profiles.ts +61 -0
  267. package/src/interface/crud/team-memberships.ts +56 -0
  268. package/src/interface/crud/team-permissions.ts +119 -0
  269. package/src/interface/crud/teams.ts +142 -0
  270. package/src/interface/crud/transactions.ts +131 -0
  271. package/src/interface/crud/users.ts +185 -0
  272. package/src/interface/handler-urls.ts +74 -0
  273. package/src/interface/page-component-versions.ts +1702 -0
  274. package/src/interface/server-interface.ts +1146 -0
  275. package/src/interface/webhooks.ts +28 -0
  276. package/src/known-errors.tsx +2031 -0
  277. package/src/local-emulator.ts +5 -0
  278. package/src/payments/payment-methods.ts +167 -0
  279. package/src/payments/stripe-limits.ts +18 -0
  280. package/src/plans.ts +107 -0
  281. package/src/schema-fields.ts +944 -0
  282. package/src/sessions.ts +310 -0
  283. package/src/utils/api-keys.tsx +122 -0
  284. package/src/utils/arrays.tsx +248 -0
  285. package/src/utils/auth-methods.ts +8 -0
  286. package/src/utils/base64.tsx +24 -0
  287. package/src/utils/booleans.tsx +34 -0
  288. package/src/utils/browser-compat.tsx +17 -0
  289. package/src/utils/bytes.tsx +280 -0
  290. package/src/utils/caches.tsx +280 -0
  291. package/src/utils/cel-fields.ts +92 -0
  292. package/src/utils/cloud-hosts.tsx +92 -0
  293. package/src/utils/compile-time.tsx +11 -0
  294. package/src/utils/country-codes.ts +39 -0
  295. package/src/utils/crypto.tsx +174 -0
  296. package/src/utils/currencies.tsx +53 -0
  297. package/src/utils/currency-constants.tsx +51 -0
  298. package/src/utils/dates.tsx +246 -0
  299. package/src/utils/dev-env-state-path.ts +14 -0
  300. package/src/utils/dom.tsx +7 -0
  301. package/src/utils/env.tsx +117 -0
  302. package/src/utils/errors.tsx +284 -0
  303. package/src/utils/esbuild.tsx +235 -0
  304. package/src/utils/featurebase.tsx +247 -0
  305. package/src/utils/fs.tsx +33 -0
  306. package/src/utils/functions.tsx +22 -0
  307. package/src/utils/geo.tsx +16 -0
  308. package/src/utils/globals.tsx +48 -0
  309. package/src/utils/hashes.tsx +52 -0
  310. package/src/utils/html.tsx +60 -0
  311. package/src/utils/http.tsx +91 -0
  312. package/src/utils/ips.tsx +47 -0
  313. package/src/utils/json.tsx +200 -0
  314. package/src/utils/jsx-editable-transpiler.test.ts +156 -0
  315. package/src/utils/jsx-editable-transpiler.tsx +401 -0
  316. package/src/utils/jwt.tsx +170 -0
  317. package/src/utils/locks.tsx +71 -0
  318. package/src/utils/maps.tsx +407 -0
  319. package/src/utils/math.tsx +18 -0
  320. package/src/utils/monkey-patch.tsx +29 -0
  321. package/src/utils/node-http.tsx +47 -0
  322. package/src/utils/numbers.tsx +82 -0
  323. package/src/utils/oauth.tsx +9 -0
  324. package/src/utils/objects.tsx +581 -0
  325. package/src/utils/paginated-lists.test.ts +1039 -0
  326. package/src/utils/paginated-lists.tsx +479 -0
  327. package/src/utils/passkey.tsx +1 -0
  328. package/src/utils/promises.tsx +540 -0
  329. package/src/utils/proxies.tsx +212 -0
  330. package/src/utils/react.tsx +308 -0
  331. package/src/utils/redirect-urls.tsx +299 -0
  332. package/src/utils/regex.tsx +10 -0
  333. package/src/utils/results.tsx +411 -0
  334. package/src/utils/sentry.tsx +20 -0
  335. package/src/utils/stores.tsx +238 -0
  336. package/src/utils/strings.nicify.test.ts +253 -0
  337. package/src/utils/strings.tsx +723 -0
  338. package/src/utils/telemetry.tsx +37 -0
  339. package/src/utils/turnstile-browser.ts +106 -0
  340. package/src/utils/turnstile-flow.test.ts +101 -0
  341. package/src/utils/turnstile-flow.ts +266 -0
  342. package/src/utils/turnstile.ts +34 -0
  343. package/src/utils/typed-arrays.tsx +17 -0
  344. package/src/utils/types.tsx +208 -0
  345. package/src/utils/unicode.tsx +24 -0
  346. package/src/utils/urls.tsx +411 -0
  347. package/src/utils/uuids.tsx +47 -0
  348. package/dist/esm/stack-config-file.d.ts +0 -15
  349. package/dist/esm/stack-config-file.d.ts.map +0 -1
  350. package/dist/esm/stack-config-file.js.map +0 -1
  351. package/dist/stack-config-file.d.ts +0 -15
  352. package/dist/stack-config-file.d.ts.map +0 -1
  353. package/dist/stack-config-file.js.map +0 -1
@@ -0,0 +1,388 @@
1
+ // Format spec lives in the eng-handbook (random-thoughts/config-json-format.md).
2
+ // (Previously linked to a public repo that doesn't exist — internal handbook only.)
3
+
4
+ import { HexclaveAssertionError, throwErr } from "../utils/errors";
5
+ import { deleteKey, filterUndefined, get, hasAndNotUndefined, set } from "../utils/objects";
6
+ import { OptionalKeys, RequiredKeys } from "../utils/types";
7
+
8
+
9
+ export type ConfigValue = string | number | boolean | null | ConfigValue[] | Config;
10
+ export type Config = {
11
+ [keyOrDotNotation: string]: ConfigValue | undefined, // must support undefined for optional values
12
+ };
13
+
14
+ export type NormalizedConfigValue = string | number | boolean | NormalizedConfig | NormalizedConfigValue[];
15
+ export type NormalizedConfig = {
16
+ [key: string]: NormalizedConfigValue | undefined, // must support undefined for optional values
17
+ };
18
+
19
+ export type _NormalizesTo<N> = N extends readonly any[]
20
+ ? { [K in keyof N]: _NormalizesTo<N[K]> }
21
+ : N extends object ? (
22
+ & Config
23
+ & { [K in OptionalKeys<N>]?: _NormalizesTo<N[K]> | null }
24
+ & { [K in RequiredKeys<N>]: undefined extends N[K] ? _NormalizesTo<N[K]> | null : _NormalizesTo<N[K]> }
25
+ & { [K in `${string}.${string}`]: ConfigValue }
26
+ ) : N;
27
+ export type NormalizesTo<N extends NormalizedConfig> = _NormalizesTo<N>;
28
+
29
+ /**
30
+ * Note that a config can both be valid and not normalizable.
31
+ */
32
+ export function isValidConfig(c: unknown): c is Config {
33
+ return getInvalidConfigReason(c) === undefined;
34
+ }
35
+
36
+ export function getInvalidConfigReason(c: unknown, options: { configName?: string } = {}): string | undefined {
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 === undefined) 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
+
44
+ const entryName = `${configName}.${key}`;
45
+ const reason = getInvalidConfigValueReason(value, { valueName: entryName });
46
+ if (reason) return reason;
47
+ }
48
+ return undefined;
49
+ }
50
+
51
+ function getInvalidConfigValueReason(value: unknown, options: { valueName?: string } = {}): string | undefined {
52
+ const valueName = options.valueName ?? 'value';
53
+ switch (typeof value) {
54
+ case 'string':
55
+ case 'number':
56
+ case 'boolean': {
57
+ break;
58
+ }
59
+ case 'object': {
60
+ if (value === null) {
61
+ break;
62
+ } else if (Array.isArray(value)) {
63
+ for (const [index, v] of value.entries()) {
64
+ const elementValueName = `${valueName}[${index}]`;
65
+ if (v === null) return `${elementValueName} is null; tuple elements cannot be null`;
66
+ const reason = getInvalidConfigValueReason(v, { valueName: elementValueName });
67
+ if (reason) return reason;
68
+ }
69
+ } else {
70
+ const reason = getInvalidConfigReason(value, { configName: valueName });
71
+ if (reason) return reason;
72
+ }
73
+ break;
74
+ }
75
+ default: {
76
+ return `${valueName} has an invalid value type ${typeof value} (value: ${value})`;
77
+ }
78
+ }
79
+ return undefined;
80
+ }
81
+
82
+ export function assertValidConfig(c: unknown) {
83
+ const reason = getInvalidConfigReason(c);
84
+ if (reason) throw new HexclaveAssertionError(`Invalid config: ${reason}`, { c });
85
+ }
86
+
87
+ export function override(c1: Config, ...configs: Config[]) {
88
+ if (configs.length === 0) return c1;
89
+ if (configs.length > 1) return override(override(c1, configs[0]), ...configs.slice(1));
90
+ const c2 = configs[0];
91
+
92
+ assertValidConfig(c1);
93
+ assertValidConfig(c2);
94
+
95
+ let result = c1;
96
+ for (const key of Object.keys(filterUndefined(c2))) {
97
+ result = Object.fromEntries(
98
+ Object.entries(result).filter(([k]) => k !== key && !k.startsWith(key + '.'))
99
+ );
100
+ }
101
+
102
+ return {
103
+ ...result,
104
+ ...filterUndefined(c2),
105
+ };
106
+ }
107
+
108
+ /**
109
+ * Removes keys from a config override, using the same nested key logic as the `override` function.
110
+ * Resetting key "a.b" also resets "a.b.c" (and any other descendants).
111
+ * Handles both flat dot-notation keys and nested object keys.
112
+ */
113
+ export function removeKeysFromConfig(config: Config, keysToRemove: string[]): Config {
114
+ if (keysToRemove.length === 0) return config;
115
+
116
+ const result: Config = {};
117
+ for (const [key, value] of Object.entries(config)) {
118
+ if (value === undefined) continue;
119
+
120
+ // Check if this flat key matches or is a child of any key to remove (same logic as override)
121
+ const shouldRemove = keysToRemove.some(k => key === k || key.startsWith(k + '.'));
122
+ if (shouldRemove) continue;
123
+
124
+ // Check if any key to remove is a descendant of this key (meaning it's nested inside this value)
125
+ const childKeysToRemove = keysToRemove
126
+ .filter(k => k.startsWith(key + '.'))
127
+ .map(k => k.slice(key.length + 1));
128
+
129
+ if (childKeysToRemove.length > 0 && typeof value === 'object' && value !== null && !Array.isArray(value)) {
130
+ const cleaned = removeKeysFromConfig(value as Config, childKeysToRemove);
131
+ if (Object.keys(cleaned).length > 0) {
132
+ result[key] = cleaned;
133
+ }
134
+ } else {
135
+ result[key] = value;
136
+ }
137
+ }
138
+ return result;
139
+ }
140
+
141
+ import.meta.vitest?.test("removeKeysFromConfig(...)", ({ expect }) => {
142
+ // Basic flat key removal
143
+ expect(removeKeysFromConfig({ a: 1, b: 2 }, ["a"])).toEqual({ b: 2 });
144
+ expect(removeKeysFromConfig({ "a.b": 1, "a.c": 2, d: 3 }, ["a.b"])).toEqual({ "a.c": 2, d: 3 });
145
+
146
+ // Removing a parent removes children (flat keys)
147
+ expect(removeKeysFromConfig({ "a.b": 1, "a.b.c": 2, "a.d": 3 }, ["a.b"])).toEqual({ "a.d": 3 });
148
+ expect(removeKeysFromConfig({ "a.b": 1, "a.c": 2, "a.d": 3 }, ["a"])).toEqual({});
149
+ expect(removeKeysFromConfig({ "teams.allowClientTeamCreation": true, "teams.createPersonalTeamOnSignUp": true }, ["teams"])).toEqual({});
150
+
151
+ // Nested object key removal
152
+ expect(removeKeysFromConfig({ teams: { allowClientTeamCreation: true, createPersonalTeamOnSignUp: true } }, ["teams.allowClientTeamCreation"])).toEqual({ teams: { createPersonalTeamOnSignUp: true } });
153
+ expect(removeKeysFromConfig({ teams: { allowClientTeamCreation: true } }, ["teams.allowClientTeamCreation"])).toEqual({});
154
+ expect(removeKeysFromConfig({ teams: { allowClientTeamCreation: true, createPersonalTeamOnSignUp: true } }, ["teams"])).toEqual({});
155
+ expect(removeKeysFromConfig({ a: { b: { c: 1, d: 2 } } }, ["a.b.c"])).toEqual({ a: { b: { d: 2 } } });
156
+
157
+ // Mixed flat and nested
158
+ expect(removeKeysFromConfig({ "teams.allowClientTeamCreation": true, teams: { createPersonalTeamOnSignUp: true } }, ["teams.allowClientTeamCreation"])).toEqual({ teams: { createPersonalTeamOnSignUp: true } });
159
+ expect(removeKeysFromConfig({ "teams.allowClientTeamCreation": true, teams: { createPersonalTeamOnSignUp: true } }, ["teams"])).toEqual({});
160
+
161
+ // Nested with dot-notation inner keys
162
+ expect(removeKeysFromConfig({ teams: { "a.b": 1 } }, ["teams.a.b"])).toEqual({});
163
+ expect(removeKeysFromConfig({ teams: { "a.b.c": 1 } }, ["teams.a.b"])).toEqual({});
164
+
165
+ // No keys to remove
166
+ expect(removeKeysFromConfig({ a: 1, b: 2 }, [])).toEqual({ a: 1, b: 2 });
167
+
168
+ // Key not present (no-op)
169
+ expect(removeKeysFromConfig({ a: 1, b: 2 }, ["c"])).toEqual({ a: 1, b: 2 });
170
+ expect(removeKeysFromConfig({ a: 1, b: 2 }, ["a.b"])).toEqual({ a: 1, b: 2 });
171
+
172
+ // Multiple keys to remove
173
+ expect(removeKeysFromConfig({ "a.b": 1, "c.d": 2, "e.f": 3 }, ["a.b", "e.f"])).toEqual({ "c.d": 2 });
174
+ expect(removeKeysFromConfig({ a: { b: 1 }, c: { d: 2 } }, ["a.b", "c.d"])).toEqual({});
175
+
176
+ // Removing non-object values with nested key path (no-op for non-objects)
177
+ expect(removeKeysFromConfig({ a: "string" }, ["a.b"])).toEqual({ a: "string" });
178
+ expect(removeKeysFromConfig({ a: 123 }, ["a.b"])).toEqual({ a: 123 });
179
+ expect(removeKeysFromConfig({ a: null }, ["a.b"])).toEqual({ a: null });
180
+
181
+ // Array values are preserved (not recursed into)
182
+ expect(removeKeysFromConfig({ a: [1, 2, 3] }, ["a.0"])).toEqual({ a: [1, 2, 3] });
183
+ });
184
+
185
+ import.meta.vitest?.test("override(...)", ({ expect }) => {
186
+ expect(
187
+ override(
188
+ {
189
+ a: 1,
190
+ b: 2,
191
+ "c.d": 3,
192
+ "c.e.f": 4,
193
+ "c.g": 5,
194
+ h: [6, { i: 7 }, 8],
195
+ k: 123,
196
+ l: undefined,
197
+ },
198
+ {
199
+ a: 9,
200
+ "c.d": 10,
201
+ "c.e": null,
202
+ "h.0": 11,
203
+ "h.1": {
204
+ j: 12,
205
+ },
206
+ k: undefined,
207
+ },
208
+ )
209
+ ).toEqual({
210
+ a: 9,
211
+ b: 2,
212
+ "c.d": 10,
213
+ "c.e": null,
214
+ "c.g": 5,
215
+ h: [6, { i: 7 }, 8],
216
+ "h.0": 11,
217
+ "h.1": {
218
+ j: 12,
219
+ },
220
+ k: 123,
221
+ l: undefined,
222
+ });
223
+ });
224
+
225
+ type NormalizeOptions = {
226
+ /**
227
+ * What to do if a dot notation is used on a value that is not an object.
228
+ *
229
+ * - "throw" (default): Throw an error.
230
+ * - "ignore": Ignore the dot notation field.
231
+ */
232
+ onDotIntoNonObject?: "throw" | "ignore",
233
+ /**
234
+ * What to do if a dot notation is used on a value that is null.
235
+ *
236
+ * - "like-non-object" (default): Treat it like a non-object. See `onDotIntoNonObject`.
237
+ * - "throw": Throw an error.
238
+ * - "ignore": Ignore the dot notation field.
239
+ * - "empty-object": Set the value to an empty object.
240
+ */
241
+ onDotIntoNull?: "like-non-object" | "throw" | "ignore" | "empty-object",
242
+ /**
243
+ * If provided, keys that are silently dropped during normalization (when a dot-notation key
244
+ * references a parent that doesn't exist or is not an object and the behavior is "ignore")
245
+ * will be pushed to this array.
246
+ */
247
+ droppedKeys?: string[],
248
+ }
249
+
250
+ export class NormalizationError extends Error {
251
+ constructor(...args: ConstructorParameters<typeof Error>) {
252
+ super(...args);
253
+ }
254
+ }
255
+ NormalizationError.prototype.name = "NormalizationError";
256
+
257
+ export function isNormalized(c: Config): c is NormalizedConfig {
258
+ assertValidConfig(c);
259
+ for (const [key, value] of Object.entries(c)) {
260
+ if (value === undefined) continue;
261
+ if (key.includes('.')) return false;
262
+ if (value === null) return false;
263
+ }
264
+ return true;
265
+ }
266
+
267
+ export function assertNormalized(c: Config): asserts c is NormalizedConfig {
268
+ assertValidConfig(c);
269
+ if (!isNormalized(c)) throw new HexclaveAssertionError(`Config is not normalized: ${JSON.stringify(c)}`);
270
+ }
271
+
272
+ export function normalize(c: Config, options: NormalizeOptions = {}): NormalizedConfig {
273
+ assertValidConfig(c);
274
+ const onDotIntoNonObject = options.onDotIntoNonObject ?? "throw";
275
+ const onDotIntoNull = options.onDotIntoNull ?? "like-non-object";
276
+
277
+ const countDots = (s: string) => s.match(/\./g)?.length ?? 0;
278
+ const result: NormalizedConfig = {};
279
+ const keysByDepth = Object.keys(c).sort((a, b) => countDots(a) - countDots(b));
280
+
281
+ outer: for (const key of keysByDepth) {
282
+ const keySegmentsWithoutLast = key.split('.');
283
+ const last = keySegmentsWithoutLast.pop() ?? throwErr('split returns empty array?');
284
+ const value = get(c, key);
285
+ if (value === undefined) continue;
286
+
287
+ let current: NormalizedConfig = result;
288
+ for (const keySegment of keySegmentsWithoutLast) {
289
+ if (!hasAndNotUndefined(current, keySegment)) {
290
+ switch (onDotIntoNull === "like-non-object" ? onDotIntoNonObject : onDotIntoNull) {
291
+ case "throw": {
292
+ 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).`);
293
+ }
294
+ case "ignore": {
295
+ options.droppedKeys?.push(key);
296
+ continue outer;
297
+ }
298
+ case "empty-object": {
299
+ set(current, keySegment, {});
300
+ break;
301
+ }
302
+ }
303
+ }
304
+ const value = get(current, keySegment);
305
+ if (typeof value !== 'object') {
306
+ switch (onDotIntoNonObject) {
307
+ case "throw": {
308
+ throw new NormalizationError(`Tried to use dot notation to access ${JSON.stringify(key)}, but ${JSON.stringify(keySegment)} is not an object.`);
309
+ }
310
+ case "ignore": {
311
+ options.droppedKeys?.push(key);
312
+ continue outer;
313
+ }
314
+ }
315
+ }
316
+ current = value as NormalizedConfig;
317
+ }
318
+ setNormalizedValue(current, last, value, options);
319
+ }
320
+ return result;
321
+ }
322
+
323
+ function normalizeValue(value: ConfigValue, options: NormalizeOptions): NormalizedConfigValue {
324
+ if (value === null) throw new NormalizationError("Tried to normalize a null value");
325
+ if (Array.isArray(value)) return value.map(v => normalizeValue(v, options));
326
+ if (typeof value === 'object') return normalize(value, options);
327
+ return value;
328
+ }
329
+
330
+ function setNormalizedValue(result: NormalizedConfig, key: string, value: ConfigValue, options: NormalizeOptions) {
331
+ if (value === null) {
332
+ if (hasAndNotUndefined(result, key)) {
333
+ deleteKey(result, key);
334
+ }
335
+ } else {
336
+ set(result, key, normalizeValue(value, options));
337
+ }
338
+ }
339
+
340
+ import.meta.vitest?.test("normalize(...)", ({ expect }) => {
341
+ expect(normalize({
342
+ a: 9,
343
+ b: 2,
344
+ c: {},
345
+ "c.d": 10,
346
+ "c.e": null,
347
+ "c.g": 5,
348
+ h: [6, { i: 7 }, 8],
349
+ "h.0": 11,
350
+ "h.1": {
351
+ j: 12,
352
+ },
353
+ k: { l: {} },
354
+ "k.l.m": 13,
355
+ n: undefined,
356
+ }, { onDotIntoNonObject: "ignore" })).toEqual({
357
+ a: 9,
358
+ b: 2,
359
+ c: {
360
+ d: 10,
361
+ g: 5,
362
+ },
363
+ h: [11, { j: 12 }, 8],
364
+ k: { l: { m: 13 } },
365
+ });
366
+
367
+ // dotting into null
368
+ expect(() => normalize({
369
+ "b.c": 2,
370
+ }, { onDotIntoNonObject: "throw" })).toThrow(`Tried to use dot notation to access "b.c", but "b" doesn't exist on the object (or is null)`);
371
+ expect(() => normalize({
372
+ b: null,
373
+ "b.c": 2,
374
+ }, { onDotIntoNonObject: "throw" })).toThrow(`Tried to use dot notation to access "b.c", but "b" doesn't exist on the object (or is null)`);
375
+ expect(normalize({
376
+ "b.c": 2,
377
+ }, { onDotIntoNonObject: "ignore" })).toEqual({});
378
+
379
+ // dotting into non-object
380
+ expect(() => normalize({
381
+ b: 1,
382
+ "b.c": 2,
383
+ }, { onDotIntoNonObject: "throw" })).toThrow(`Tried to use dot notation to access "b.c", but "b" is not an object`);
384
+ expect(normalize({
385
+ b: 1,
386
+ "b.c": 2,
387
+ }, { onDotIntoNonObject: "ignore" })).toEqual({ b: 1 });
388
+ });