@heyo-sh/heyo-cms 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (382) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +44 -2
  3. package/dist/access/index.d.ts +9 -0
  4. package/dist/access/index.d.ts.map +1 -0
  5. package/dist/access/permissions.d.ts +54 -0
  6. package/dist/access/permissions.d.ts.map +1 -0
  7. package/dist/adapters/astro.d.ts +38 -0
  8. package/dist/adapters/astro.d.ts.map +1 -0
  9. package/dist/adapters/astro.js +1 -0
  10. package/dist/adapters/next.d.ts +31 -0
  11. package/dist/adapters/next.d.ts.map +1 -0
  12. package/dist/adapters/next.js +1 -0
  13. package/dist/adapters/nuxt.d.ts +47 -0
  14. package/dist/adapters/nuxt.d.ts.map +1 -0
  15. package/dist/adapters/nuxt.js +1 -0
  16. package/dist/adapters/react-router.d.ts +29 -0
  17. package/dist/adapters/react-router.d.ts.map +1 -0
  18. package/dist/adapters/react-router.js +1 -0
  19. package/dist/adapters/sveltekit.d.ts +37 -0
  20. package/dist/adapters/sveltekit.d.ts.map +1 -0
  21. package/dist/adapters/sveltekit.js +1 -0
  22. package/dist/ai/assistant/context.d.ts +64 -0
  23. package/dist/ai/assistant/context.d.ts.map +1 -0
  24. package/dist/ai/assistant/limits.d.ts +10 -0
  25. package/dist/ai/assistant/limits.d.ts.map +1 -0
  26. package/dist/ai/assistant/plans.d.ts +83 -0
  27. package/dist/ai/assistant/plans.d.ts.map +1 -0
  28. package/dist/ai/assistant/prompt.d.ts +22 -0
  29. package/dist/ai/assistant/prompt.d.ts.map +1 -0
  30. package/dist/ai/assistant/run.d.ts +59 -0
  31. package/dist/ai/assistant/run.d.ts.map +1 -0
  32. package/dist/ai/assistant/runtime.d.ts +35 -0
  33. package/dist/ai/assistant/runtime.d.ts.map +1 -0
  34. package/dist/ai/assistant/schema.d.ts +66 -0
  35. package/dist/ai/assistant/schema.d.ts.map +1 -0
  36. package/dist/ai/assistant/tools.d.ts +41 -0
  37. package/dist/ai/assistant/tools.d.ts.map +1 -0
  38. package/dist/ai/assistant/values.d.ts +33 -0
  39. package/dist/ai/assistant/values.d.ts.map +1 -0
  40. package/dist/ai/crypto.d.ts +12 -0
  41. package/dist/ai/crypto.d.ts.map +1 -0
  42. package/dist/ai/index.d.ts +19 -0
  43. package/dist/ai/index.d.ts.map +1 -0
  44. package/dist/ai/pi.d.ts +89 -0
  45. package/dist/ai/pi.d.ts.map +1 -0
  46. package/dist/ai/registry.d.ts +66 -0
  47. package/dist/ai/registry.d.ts.map +1 -0
  48. package/dist/ai/service.d.ts +31 -0
  49. package/dist/ai/service.d.ts.map +1 -0
  50. package/dist/ai/variant-translation.d.ts +6 -0
  51. package/dist/ai/variant-translation.d.ts.map +1 -0
  52. package/dist/ai.d.ts +12 -0
  53. package/dist/ai.d.ts.map +1 -0
  54. package/dist/ai.js +1 -0
  55. package/dist/auth/config.d.ts +65 -0
  56. package/dist/auth/config.d.ts.map +1 -0
  57. package/dist/auth/crypto.d.ts +44 -0
  58. package/dist/auth/crypto.d.ts.map +1 -0
  59. package/dist/auth/index.d.ts +15 -0
  60. package/dist/auth/index.d.ts.map +1 -0
  61. package/dist/auth/oauth.d.ts +93 -0
  62. package/dist/auth/oauth.d.ts.map +1 -0
  63. package/dist/auth/service.d.ts +38 -0
  64. package/dist/auth/service.d.ts.map +1 -0
  65. package/dist/auth/totp.d.ts +34 -0
  66. package/dist/auth/totp.d.ts.map +1 -0
  67. package/dist/auth.d.ts +9 -0
  68. package/dist/auth.d.ts.map +1 -0
  69. package/dist/auth.js +1 -0
  70. package/dist/cli.d.ts +3 -0
  71. package/dist/cli.d.ts.map +1 -0
  72. package/dist/cli.js +30 -0
  73. package/dist/client/index.d.ts +51 -0
  74. package/dist/client/index.d.ts.map +1 -0
  75. package/dist/client/types.d.ts +340 -0
  76. package/dist/client/types.d.ts.map +1 -0
  77. package/dist/client.d.ts +46 -0
  78. package/dist/client.d.ts.map +1 -0
  79. package/dist/client.js +1 -0
  80. package/dist/config.d.ts +31 -0
  81. package/dist/config.d.ts.map +1 -0
  82. package/dist/config.js +1 -0
  83. package/dist/content/export.d.ts +28 -0
  84. package/dist/content/export.d.ts.map +1 -0
  85. package/dist/content/import.d.ts +65 -0
  86. package/dist/content/import.d.ts.map +1 -0
  87. package/dist/content/records.d.ts +73 -0
  88. package/dist/content/records.d.ts.map +1 -0
  89. package/dist/content.d.ts +12 -0
  90. package/dist/content.d.ts.map +1 -0
  91. package/dist/content.js +1 -0
  92. package/dist/db/d1.d.ts +29 -0
  93. package/dist/db/d1.d.ts.map +1 -0
  94. package/dist/db/d1.js +1 -0
  95. package/dist/db/mongodb.d.ts +128 -0
  96. package/dist/db/mongodb.d.ts.map +1 -0
  97. package/dist/db/mongodb.js +2 -0
  98. package/dist/db/postgres.d.ts +37 -0
  99. package/dist/db/postgres.d.ts.map +1 -0
  100. package/dist/db/postgres.js +1 -0
  101. package/dist/db/sql/adapter.d.ts +57 -0
  102. package/dist/db/sql/adapter.d.ts.map +1 -0
  103. package/dist/db/sql/compile.d.ts +50 -0
  104. package/dist/db/sql/compile.d.ts.map +1 -0
  105. package/dist/db/sql/ddl.d.ts +34 -0
  106. package/dist/db/sql/ddl.d.ts.map +1 -0
  107. package/dist/db/sql/dialect.d.ts +35 -0
  108. package/dist/db/sql/dialect.d.ts.map +1 -0
  109. package/dist/db/sql/driver.d.ts +34 -0
  110. package/dist/db/sql/driver.d.ts.map +1 -0
  111. package/dist/db/sql/introspect.d.ts +15 -0
  112. package/dist/db/sql/introspect.d.ts.map +1 -0
  113. package/dist/db/sqlite.d.ts +39 -0
  114. package/dist/db/sqlite.d.ts.map +1 -0
  115. package/dist/db/sqlite.js +1 -0
  116. package/dist/defaults.d.ts +5 -0
  117. package/dist/defaults.d.ts.map +1 -0
  118. package/dist/duration.d.ts +12 -0
  119. package/dist/duration.d.ts.map +1 -0
  120. package/dist/editor/builtin.d.ts +45 -0
  121. package/dist/editor/builtin.d.ts.map +1 -0
  122. package/dist/editor/index.d.ts +14 -0
  123. package/dist/editor/index.d.ts.map +1 -0
  124. package/dist/editor/markdown.d.ts +19 -0
  125. package/dist/editor/markdown.d.ts.map +1 -0
  126. package/dist/editor/registry.d.ts +30 -0
  127. package/dist/editor/registry.d.ts.map +1 -0
  128. package/dist/editor/serialize.d.ts +41 -0
  129. package/dist/editor/serialize.d.ts.map +1 -0
  130. package/dist/editor.d.ts +10 -0
  131. package/dist/editor.d.ts.map +1 -0
  132. package/dist/editor.js +1 -0
  133. package/dist/engine/access.d.ts +33 -0
  134. package/dist/engine/access.d.ts.map +1 -0
  135. package/dist/engine/activity.d.ts +16 -0
  136. package/dist/engine/activity.d.ts.map +1 -0
  137. package/dist/engine/cursor.d.ts +19 -0
  138. package/dist/engine/cursor.d.ts.map +1 -0
  139. package/dist/engine/documents.d.ts +81 -0
  140. package/dist/engine/documents.d.ts.map +1 -0
  141. package/dist/engine/engine.d.ts +276 -0
  142. package/dist/engine/engine.d.ts.map +1 -0
  143. package/dist/engine/field-access.d.ts +21 -0
  144. package/dist/engine/field-access.d.ts.map +1 -0
  145. package/dist/engine/hooks.d.ts +58 -0
  146. package/dist/engine/hooks.d.ts.map +1 -0
  147. package/dist/engine/index.d.ts +20 -0
  148. package/dist/engine/index.d.ts.map +1 -0
  149. package/dist/engine/jobs.d.ts +63 -0
  150. package/dist/engine/jobs.d.ts.map +1 -0
  151. package/dist/engine/locales.d.ts +40 -0
  152. package/dist/engine/locales.d.ts.map +1 -0
  153. package/dist/engine/outbox.d.ts +81 -0
  154. package/dist/engine/outbox.d.ts.map +1 -0
  155. package/dist/engine/relations.d.ts +60 -0
  156. package/dist/engine/relations.d.ts.map +1 -0
  157. package/dist/engine/scoped-db.d.ts +13 -0
  158. package/dist/engine/scoped-db.d.ts.map +1 -0
  159. package/dist/engine/trash.d.ts +25 -0
  160. package/dist/engine/trash.d.ts.map +1 -0
  161. package/dist/errors.d.ts +42 -0
  162. package/dist/errors.d.ts.map +1 -0
  163. package/dist/fields/builtin.d.ts +142 -0
  164. package/dist/fields/builtin.d.ts.map +1 -0
  165. package/dist/fields/index.d.ts +3 -0
  166. package/dist/fields/index.d.ts.map +1 -0
  167. package/dist/fields/registry.d.ts +35 -0
  168. package/dist/fields/registry.d.ts.map +1 -0
  169. package/dist/fields.d.ts +8 -0
  170. package/dist/fields.d.ts.map +1 -0
  171. package/dist/fields.js +1 -0
  172. package/dist/http/guard.d.ts +45 -0
  173. package/dist/http/guard.d.ts.map +1 -0
  174. package/dist/http/handler.d.ts +31 -0
  175. package/dist/http/handler.d.ts.map +1 -0
  176. package/dist/http/index.d.ts +13 -0
  177. package/dist/http/index.d.ts.map +1 -0
  178. package/dist/http/openapi.d.ts +5 -0
  179. package/dist/http/openapi.d.ts.map +1 -0
  180. package/dist/http/params.d.ts +32 -0
  181. package/dist/http/params.d.ts.map +1 -0
  182. package/dist/http/request-db.d.ts +19 -0
  183. package/dist/http/request-db.d.ts.map +1 -0
  184. package/dist/http/respond.d.ts +48 -0
  185. package/dist/http/respond.d.ts.map +1 -0
  186. package/dist/http/rich-text.d.ts +30 -0
  187. package/dist/http/rich-text.d.ts.map +1 -0
  188. package/dist/http/router.d.ts +55 -0
  189. package/dist/http/router.d.ts.map +1 -0
  190. package/dist/http/routes/access.d.ts +13 -0
  191. package/dist/http/routes/access.d.ts.map +1 -0
  192. package/dist/http/routes/admin.d.ts +28 -0
  193. package/dist/http/routes/admin.d.ts.map +1 -0
  194. package/dist/http/routes/ai.d.ts +26 -0
  195. package/dist/http/routes/ai.d.ts.map +1 -0
  196. package/dist/http/routes/auth.d.ts +13 -0
  197. package/dist/http/routes/auth.d.ts.map +1 -0
  198. package/dist/http/routes/documents.d.ts +24 -0
  199. package/dist/http/routes/documents.d.ts.map +1 -0
  200. package/dist/http/routes/generate.d.ts +5 -0
  201. package/dist/http/routes/generate.d.ts.map +1 -0
  202. package/dist/http/routes/media.d.ts +28 -0
  203. package/dist/http/routes/media.d.ts.map +1 -0
  204. package/dist/http/routes/panel.d.ts +20 -0
  205. package/dist/http/routes/panel.d.ts.map +1 -0
  206. package/dist/http/routes/system.d.ts +25 -0
  207. package/dist/http/routes/system.d.ts.map +1 -0
  208. package/dist/http/routes/webhooks.d.ts +17 -0
  209. package/dist/http/routes/webhooks.d.ts.map +1 -0
  210. package/dist/http/spec.d.ts +28 -0
  211. package/dist/http/spec.d.ts.map +1 -0
  212. package/dist/http.d.ts +17 -0
  213. package/dist/http.d.ts.map +1 -0
  214. package/dist/http.js +1 -0
  215. package/dist/i18n/index.d.ts +12 -0
  216. package/dist/i18n/index.d.ts.map +1 -0
  217. package/dist/i18n/names.d.ts +25 -0
  218. package/dist/i18n/names.d.ts.map +1 -0
  219. package/dist/ids.d.ts +28 -0
  220. package/dist/ids.d.ts.map +1 -0
  221. package/dist/index-2757kej5.js +2 -0
  222. package/dist/index-2kb5nbxx.js +2 -0
  223. package/dist/index-2z1qe5mw.js +2 -0
  224. package/dist/index-34s342fz.js +2 -0
  225. package/dist/index-5ngtc7gy.js +2 -0
  226. package/dist/index-7a231xfp.js +2 -0
  227. package/dist/index-7k091gpe.js +2 -0
  228. package/dist/index-9g2n7xa6.js +2 -0
  229. package/dist/index-9x1z3b85.js +5 -0
  230. package/dist/index-9zqnf6gx.js +23 -0
  231. package/dist/index-b2ecggck.js +26 -0
  232. package/dist/index-cbwwtcm4.js +2 -0
  233. package/dist/index-ebtj6ebd.js +0 -0
  234. package/dist/index-g4crf47y.js +0 -0
  235. package/dist/index-gpwcmmvr.js +2 -0
  236. package/dist/index-hq05mc1n.js +3 -0
  237. package/dist/index-hy1x46nf.js +2 -0
  238. package/dist/index-k8wbg1dw.js +2 -0
  239. package/dist/index-kbsgt44t.js +2 -0
  240. package/dist/index-m82a0shw.js +2 -0
  241. package/dist/index-md79xr6h.js +5 -0
  242. package/dist/index-nvgwyykk.js +40 -0
  243. package/dist/index-ty698y02.js +2 -0
  244. package/dist/index-vq2978e7.js +14 -0
  245. package/dist/index-vxw0a03g.js +2 -0
  246. package/dist/index-wj8y1xcj.js +2 -0
  247. package/dist/index-x72d1hzh.js +2 -0
  248. package/dist/index-y5mwknr9.js +2 -0
  249. package/dist/index-ymq6jsar.js +2 -0
  250. package/dist/index.d.ts +25 -0
  251. package/dist/index.d.ts.map +1 -0
  252. package/dist/index.js +1 -0
  253. package/dist/jobs/runner.d.ts +77 -0
  254. package/dist/jobs/runner.d.ts.map +1 -0
  255. package/dist/jobs.d.ts +11 -0
  256. package/dist/jobs.d.ts.map +1 -0
  257. package/dist/jobs.js +1 -0
  258. package/dist/media/document.d.ts +28 -0
  259. package/dist/media/document.d.ts.map +1 -0
  260. package/dist/media/gc.d.ts +46 -0
  261. package/dist/media/gc.d.ts.map +1 -0
  262. package/dist/media/index.d.ts +20 -0
  263. package/dist/media/index.d.ts.map +1 -0
  264. package/dist/media/pipeline.d.ts +36 -0
  265. package/dist/media/pipeline.d.ts.map +1 -0
  266. package/dist/media/probe.d.ts +6 -0
  267. package/dist/media/probe.d.ts.map +1 -0
  268. package/dist/media/service.d.ts +26 -0
  269. package/dist/media/service.d.ts.map +1 -0
  270. package/dist/media/sharp.d.ts +28 -0
  271. package/dist/media/sharp.d.ts.map +1 -0
  272. package/dist/media/strip.d.ts +16 -0
  273. package/dist/media/strip.d.ts.map +1 -0
  274. package/dist/media/usages.d.ts +69 -0
  275. package/dist/media/usages.d.ts.map +1 -0
  276. package/dist/media/variants.d.ts +50 -0
  277. package/dist/media/variants.d.ts.map +1 -0
  278. package/dist/migrations.d.ts +115 -0
  279. package/dist/migrations.d.ts.map +1 -0
  280. package/dist/migrations.js +1 -0
  281. package/dist/panel.d.ts +31 -0
  282. package/dist/panel.d.ts.map +1 -0
  283. package/dist/query.d.ts +40 -0
  284. package/dist/query.d.ts.map +1 -0
  285. package/dist/query.js +1 -0
  286. package/dist/run-3r72dwhs.js +6 -0
  287. package/dist/schema/describe.d.ts +19 -0
  288. package/dist/schema/describe.d.ts.map +1 -0
  289. package/dist/schema/index.d.ts +5 -0
  290. package/dist/schema/index.d.ts.map +1 -0
  291. package/dist/schema/plan.d.ts +20 -0
  292. package/dist/schema/plan.d.ts.map +1 -0
  293. package/dist/schema/snapshot.d.ts +22 -0
  294. package/dist/schema/snapshot.d.ts.map +1 -0
  295. package/dist/schema/system.d.ts +22 -0
  296. package/dist/schema/system.d.ts.map +1 -0
  297. package/dist/schema.d.ts +7 -0
  298. package/dist/schema.d.ts.map +1 -0
  299. package/dist/schema.js +1 -0
  300. package/dist/storage/bytes.d.ts +17 -0
  301. package/dist/storage/bytes.d.ts.map +1 -0
  302. package/dist/storage/http.d.ts +43 -0
  303. package/dist/storage/http.d.ts.map +1 -0
  304. package/dist/storage/local.d.ts +31 -0
  305. package/dist/storage/local.d.ts.map +1 -0
  306. package/dist/storage/providers.d.ts +95 -0
  307. package/dist/storage/providers.d.ts.map +1 -0
  308. package/dist/storage/sign.d.ts +53 -0
  309. package/dist/storage/sign.d.ts.map +1 -0
  310. package/dist/strings.d.ts +13 -0
  311. package/dist/strings.d.ts.map +1 -0
  312. package/dist/telemetry.d.ts +137 -0
  313. package/dist/telemetry.d.ts.map +1 -0
  314. package/dist/telemetry.js +1 -0
  315. package/dist/types/activity.d.ts +68 -0
  316. package/dist/types/activity.d.ts.map +1 -0
  317. package/dist/types/actor.d.ts +26 -0
  318. package/dist/types/actor.d.ts.map +1 -0
  319. package/dist/types/ai.d.ts +357 -0
  320. package/dist/types/ai.d.ts.map +1 -0
  321. package/dist/types/api.d.ts +212 -0
  322. package/dist/types/api.d.ts.map +1 -0
  323. package/dist/types/auth.d.ts +310 -0
  324. package/dist/types/auth.d.ts.map +1 -0
  325. package/dist/types/config.d.ts +632 -0
  326. package/dist/types/config.d.ts.map +1 -0
  327. package/dist/types/database.d.ts +75 -0
  328. package/dist/types/database.d.ts.map +1 -0
  329. package/dist/types/editor.d.ts +140 -0
  330. package/dist/types/editor.d.ts.map +1 -0
  331. package/dist/types/events.d.ts +72 -0
  332. package/dist/types/events.d.ts.map +1 -0
  333. package/dist/types/fields.d.ts +142 -0
  334. package/dist/types/fields.d.ts.map +1 -0
  335. package/dist/types/hooks.d.ts +142 -0
  336. package/dist/types/hooks.d.ts.map +1 -0
  337. package/dist/types/index.d.ts +25 -0
  338. package/dist/types/index.d.ts.map +1 -0
  339. package/dist/types/instance.d.ts +263 -0
  340. package/dist/types/instance.d.ts.map +1 -0
  341. package/dist/types/jobs.d.ts +78 -0
  342. package/dist/types/jobs.d.ts.map +1 -0
  343. package/dist/types/json.d.ts +24 -0
  344. package/dist/types/json.d.ts.map +1 -0
  345. package/dist/types/locales.d.ts +30 -0
  346. package/dist/types/locales.d.ts.map +1 -0
  347. package/dist/types/media.d.ts +245 -0
  348. package/dist/types/media.d.ts.map +1 -0
  349. package/dist/types/panel.d.ts +249 -0
  350. package/dist/types/panel.d.ts.map +1 -0
  351. package/dist/types/plugin.d.ts +172 -0
  352. package/dist/types/plugin.d.ts.map +1 -0
  353. package/dist/types/query.d.ts +101 -0
  354. package/dist/types/query.d.ts.map +1 -0
  355. package/dist/types/schema.d.ts +203 -0
  356. package/dist/types/schema.d.ts.map +1 -0
  357. package/dist/types/storage.d.ts +61 -0
  358. package/dist/types/storage.d.ts.map +1 -0
  359. package/dist/types/telemetry.d.ts +14 -0
  360. package/dist/types/telemetry.d.ts.map +1 -0
  361. package/dist/types/trash.d.ts +42 -0
  362. package/dist/types/trash.d.ts.map +1 -0
  363. package/dist/types/webhooks.d.ts +133 -0
  364. package/dist/types/webhooks.d.ts.map +1 -0
  365. package/dist/types.d.ts +8 -0
  366. package/dist/types.d.ts.map +1 -0
  367. package/dist/types.js +1 -0
  368. package/dist/uploads.d.ts +21 -0
  369. package/dist/uploads.d.ts.map +1 -0
  370. package/dist/uploads.js +9 -0
  371. package/dist/webhooks/index.d.ts +10 -0
  372. package/dist/webhooks/index.d.ts.map +1 -0
  373. package/dist/webhooks/job.d.ts +17 -0
  374. package/dist/webhooks/job.d.ts.map +1 -0
  375. package/dist/webhooks/service.d.ts +53 -0
  376. package/dist/webhooks/service.d.ts.map +1 -0
  377. package/dist/webhooks/sign.d.ts +26 -0
  378. package/dist/webhooks/sign.d.ts.map +1 -0
  379. package/dist/webhooks.d.ts +10 -0
  380. package/dist/webhooks.d.ts.map +1 -0
  381. package/dist/webhooks.js +1 -0
  382. package/package.json +183 -4
@@ -0,0 +1,93 @@
1
+ import type { JsonObject } from "../types/json";
2
+ /**
3
+ * OAuth 2.0 and OpenID Connect, as plain functions.
4
+ *
5
+ * Nothing here touches the database or the configuration: a provider is a
6
+ * record of endpoints plus a function that turns whatever the provider
7
+ * returns into the three things the CMS needs — a stable id, an email and a
8
+ * display name. Adding a provider is therefore a literal, not a subclass.
9
+ */
10
+ export interface OAuthProfile {
11
+ /** Stable at the provider. Never the email: emails get reassigned. */
12
+ id: string;
13
+ email: string | null;
14
+ name: string | null;
15
+ avatarUrl: string | null;
16
+ /** Everything the provider said, for `oidc().mapRoles`. */
17
+ claims: JsonObject;
18
+ }
19
+ export interface OAuthTokens {
20
+ accessToken: string;
21
+ idToken?: string;
22
+ tokenType?: string;
23
+ }
24
+ export interface OAuthEndpoints {
25
+ authorization: string;
26
+ token: string;
27
+ userinfo?: string;
28
+ }
29
+ export interface OAuthProvider {
30
+ id: string;
31
+ endpoints: OAuthEndpoints;
32
+ scope: string;
33
+ /** Proof Key for Code Exchange. Off for GitHub, which does not accept it. */
34
+ pkce: boolean;
35
+ profile(tokens: OAuthTokens, fetchImpl: FetchLike): Promise<OAuthProfile>;
36
+ }
37
+ /**
38
+ * Just the call signature, not `typeof fetch`.
39
+ *
40
+ * Runtimes decorate the global with their own extras — Bun adds `preconnect`
41
+ * — and typing against the global would make a hand-written test double fail
42
+ * to compile for a reason that has nothing to do with HTTP.
43
+ */
44
+ export type FetchLike = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
45
+ /**
46
+ * The three providers the plan names.
47
+ *
48
+ * Google and Microsoft are OpenID Connect, so the profile comes from the
49
+ * id_token and needs no second round trip. GitHub is plain OAuth 2 and hides
50
+ * a verified address behind a separate endpoint when the public profile has
51
+ * none, which is the common case for a work account.
52
+ */
53
+ export declare const builtinProviders: Record<string, OAuthProvider>;
54
+ /** The shape every OIDC provider agrees on, including a custom issuer. */
55
+ export declare function oidcProfile(claims: JsonObject): OAuthProfile;
56
+ /**
57
+ * Reads an id_token without verifying its signature.
58
+ *
59
+ * Allowed, and only allowed, because of how it arrives: the authorization code
60
+ * flow fetches it from the token endpoint over TLS, with the client
61
+ * authenticating itself — OpenID Connect Core 3.1.3.7 explicitly permits
62
+ * skipping signature validation on that path. A token that reached us any
63
+ * other way must never be passed to this function.
64
+ */
65
+ export declare function decodeIdToken(token: string): JsonObject;
66
+ export declare function discoverOidc(issuer: string, fetchImpl: FetchLike): Promise<OAuthEndpoints>;
67
+ export interface AuthorizeUrlOptions {
68
+ endpoints: OAuthEndpoints;
69
+ clientId: string;
70
+ redirectUri: string;
71
+ scope: string;
72
+ state: string;
73
+ /** The S256 challenge; omitted for providers that reject PKCE. */
74
+ codeChallenge?: string;
75
+ extra?: Record<string, string>;
76
+ }
77
+ export declare function buildAuthorizeUrl(options: AuthorizeUrlOptions): string;
78
+ /** The PKCE pair: a verifier to keep, a challenge to publish. */
79
+ export declare function pkcePair(verifier: string): Promise<{
80
+ verifier: string;
81
+ challenge: string;
82
+ }>;
83
+ export interface ExchangeOptions {
84
+ endpoints: OAuthEndpoints;
85
+ clientId: string;
86
+ clientSecret: string;
87
+ code: string;
88
+ redirectUri: string;
89
+ codeVerifier?: string;
90
+ fetchImpl: FetchLike;
91
+ }
92
+ export declare function exchangeCode(options: ExchangeOptions): Promise<OAuthTokens>;
93
+ //# sourceMappingURL=oauth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oauth.d.ts","sourceRoot":"","sources":["../../src/auth/oauth.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAGhD;;;;;;;GAOG;AAEH,MAAM,WAAW,YAAY;IAC3B,sEAAsE;IACtE,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,2DAA2D;IAC3D,MAAM,EAAE,UAAU,CAAC;CACpB;AAED,MAAM,WAAW,WAAW;IAC1B,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,cAAc;IAC7B,aAAa,EAAE,MAAM,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,cAAc,CAAC;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,6EAA6E;IAC7E,IAAI,EAAE,OAAO,CAAC;IACd,OAAO,CAAC,MAAM,EAAE,WAAW,EAAE,SAAS,EAAE,SAAS,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;CAC3E;AAED;;;;;;GAMG;AACH,MAAM,MAAM,SAAS,GAAG,CACtB,KAAK,EAAE,WAAW,GAAG,GAAG,EACxB,IAAI,CAAC,EAAE,WAAW,KACf,OAAO,CAAC,QAAQ,CAAC,CAAC;AAEvB;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAyE1D,CAAC;AAEF,0EAA0E;AAC1E,wBAAgB,WAAW,CAAC,MAAM,EAAE,UAAU,GAAG,YAAY,CAQ5D;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAavD;AAWD,wBAAgB,YAAY,CAC1B,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,SAAS,GACnB,OAAO,CAAC,cAAc,CAAC,CA8BzB;AAED,MAAM,WAAW,mBAAmB;IAClC,SAAS,EAAE,cAAc,CAAC;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,kEAAkE;IAClE,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAChC;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,mBAAmB,GAAG,MAAM,CAetE;AAED,iEAAiE;AACjE,wBAAsB,QAAQ,CAC5B,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC,CAElD;AAED,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,cAAc,CAAC;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,SAAS,CAAC;CACtB;AAED,wBAAsB,YAAY,CAChC,OAAO,EAAE,eAAe,GACvB,OAAO,CAAC,WAAW,CAAC,CAuCtB"}
@@ -0,0 +1,38 @@
1
+ import type { CmsAuth } from "../types/auth";
2
+ import type { ResolvedCmsConfig } from "../types/config";
3
+ import type { DatabaseAdapter } from "../types/database";
4
+ import type { Tx } from "../types/query";
5
+ import type { BufferedEvent, OutboxEntryMeta } from "../engine/outbox";
6
+ import { type FetchLike } from "./oauth";
7
+ /** The cookie the panel uses. Named here so stage 7 cannot invent a second. */
8
+ export declare const sessionCookieName = "heyo_cms_session";
9
+ /**
10
+ * API keys announce themselves.
11
+ *
12
+ * One `Authorization: Bearer` header carries either a session token or a
13
+ * machine key, and the prefix is what tells them apart without a database
14
+ * round trip against both tables.
15
+ */
16
+ export declare const apiKeyPrefix = "hck_";
17
+ export interface AuthServiceOptions {
18
+ config: ResolvedCmsConfig;
19
+ database: () => Promise<DatabaseAdapter>;
20
+ /** Appends events to the outbox inside the caller's transaction. */
21
+ emit: (tx: Tx, events: BufferedEvent[], meta: OutboxEntryMeta) => Promise<void>;
22
+ /** Schedules delivery once the transaction has committed. */
23
+ deliver: () => void;
24
+ /** Injectable for tests and for runtimes with a bound fetch. */
25
+ fetch?: FetchLike;
26
+ }
27
+ /**
28
+ * Editor authentication and RBAC.
29
+ *
30
+ * One implementation, used by the local API today and by the REST routes in
31
+ * stage 7 — the same reason `cms.api` exists. Everything is a method on this
32
+ * object rather than a route handler, so a CLI, a seed script and a panel all
33
+ * get identical behaviour, including the parts that are easy to get wrong:
34
+ * single-use tokens, hashed secrets, and a second factor that cannot be
35
+ * skipped by calling a different function.
36
+ */
37
+ export declare function createAuth(options: AuthServiceOptions): CmsAuth;
38
+ //# sourceMappingURL=service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../src/auth/service.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAEV,OAAO,EAYR,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAGV,iBAAiB,EAClB,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEzD,OAAO,KAAK,EAAO,EAAE,EAAS,MAAM,gBAAgB,CAAC;AACrD,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAGvE,OAAO,EAQL,KAAK,SAAS,EAIf,MAAM,SAAS,CAAC;AAUjB,+EAA+E;AAC/E,eAAO,MAAM,iBAAiB,qBAAqB,CAAC;AAEpD;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,SAAS,CAAC;AAoBnC,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,iBAAiB,CAAC;IAC1B,QAAQ,EAAE,MAAM,OAAO,CAAC,eAAe,CAAC,CAAC;IACzC,oEAAoE;IACpE,IAAI,EAAE,CACJ,EAAE,EAAE,EAAE,EACN,MAAM,EAAE,aAAa,EAAE,EACvB,IAAI,EAAE,eAAe,KAClB,OAAO,CAAC,IAAI,CAAC,CAAC;IACnB,6DAA6D;IAC7D,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,gEAAgE;IAChE,KAAK,CAAC,EAAE,SAAS,CAAC;CACnB;AAED;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CA0qD/D"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * TOTP (RFC 6238), on Web Crypto.
3
+ *
4
+ * Six digits, thirty seconds, HMAC-SHA1 — not because SHA-1 is a good hash in
5
+ * 2026, but because it is what every authenticator app implements, and a
6
+ * second factor nobody can enrol is not a second factor.
7
+ */
8
+ /** 160 bits, the size RFC 4226 recommends for the HMAC-SHA1 key. */
9
+ export declare function generateTotpSecret(): string;
10
+ /**
11
+ * The `otpauth://` URI an authenticator scans.
12
+ *
13
+ * The issuer appears twice — as a label prefix and as a parameter — which is
14
+ * redundant and is also what every app expects.
15
+ */
16
+ export declare function totpUri(options: {
17
+ secret: string;
18
+ account: string;
19
+ issuer: string;
20
+ }): string;
21
+ export declare function totpCode(secret: string, at?: number): Promise<string>;
22
+ /**
23
+ * Verifies a code, allowing one step either side.
24
+ *
25
+ * The window is for clock drift between the phone and the server, not for
26
+ * convenience: widening it multiplies the number of codes that are valid at
27
+ * any moment, which is exactly what the second factor is trying to limit.
28
+ */
29
+ export declare function verifyTotp(secret: string | null | undefined, code: string, options?: {
30
+ at?: number;
31
+ window?: number;
32
+ }): Promise<boolean>;
33
+ export declare function base32Encode(bytes: Uint8Array): string;
34
+ //# sourceMappingURL=totp.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"totp.d.ts","sourceRoot":"","sources":["../../src/auth/totp.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAMH,oEAAoE;AACpE,wBAAgB,kBAAkB,IAAI,MAAM,CAE3C;AAED;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,OAAO,EAAE;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;CAChB,GAAG,MAAM,CAUT;AAED,wBAAsB,QAAQ,CAC5B,MAAM,EAAE,MAAM,EACd,EAAE,SAAa,GACd,OAAO,CAAC,MAAM,CAAC,CAEjB;AAED;;;;;;GAMG;AACH,wBAAsB,UAAU,CAC9B,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EACjC,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE;IAAE,EAAE,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAO,GAC7C,OAAO,CAAC,OAAO,CAAC,CAmBlB;AA+BD,wBAAgB,YAAY,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAetD"}
package/dist/auth.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ /**
2
+ * `@heyo-sh/heyo-cms/auth`.
3
+ *
4
+ * `cmsUsers()` and `oidc()` describe who may sign in; the service behind
5
+ * `cms.auth` does the signing in. Both live here so a configuration file and
6
+ * a route handler import from the same place.
7
+ */
8
+ export * from "./auth/index";
9
+ //# sourceMappingURL=auth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,cAAc,cAAc,CAAC"}
package/dist/auth.js ADDED
@@ -0,0 +1 @@
1
+ import"./index-vxw0a03g.js";import{Re}from"./index-2z1qe5mw.js";import{Dn,kt,Mn,qn,Wo,Xt,fe,en,tn}from"./index-5ngtc7gy.js";import{ke,nn,he,Q,X}from"./index-kbsgt44t.js";import{b}from"./index-cbwwtcm4.js";import{n}from"./index-x72d1hzh.js";function o(e){if(e.methods.length===0)throw new n("admin.auth.methods","at least one sign-in method is required");for(let[s,t]of[["session",e.session?.expiresIn],["invites",e.invites?.expiresIn],["magicLink",e.magicLink?.expiresIn],["passwordReset",e.passwordReset?.expiresIn],["apiKeys",e.apiKeys?.expiresIn]])if(t)b(t,`admin.auth.${s}.expiresIn`);for(let s of e.apiKeys?.scopes??[])if(!Re(s))throw new n("admin.auth.apiKeys.scopes",`"${s}" is not a scope; use "read", "write", "delete", "*" or "collection:action"`);let i=e.firstUser;if(typeof i==="object"){let s=i.roles;if(s!==void 0&&s.length===0)throw new n("admin.auth.firstUser.roles","the first account needs at least one role")}if(i!==void 0&&i!==!1&&!e.methods.includes("password"))throw new n("admin.auth.firstUser",'the first account signs in with a password; add "password" to methods, or set firstUser: false');let r=e.password?.minLength;if(r!==void 0&&r<8)throw new n("admin.auth.password.minLength","must be at least 8");return{kind:"cms-users",...e}}function a(e){if(!/^https?:\/\//.test(e.issuer))throw new n("admin.auth.sso.issuer","must be an HTTP(S) issuer URL");return{kind:"oidc",...e}}export{en as apiKeyPrefix,X as base64url,Dn as builtinProviders,o as cmsUsers,tn as createAuth,kt as decodeIdToken,Mn as generateTotpSecret,ke as hashPassword,Q as hashToken,a as oidc,he as randomToken,fe as sessionCookieName,Wo as totpCode,qn as totpUri,nn as verifyPassword,Xt as verifyTotp};
package/dist/cli.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export declare function main(argv: string[]): Promise<number>;
3
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AA8DA,wBAAsB,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CA+B1D"}
package/dist/cli.js ADDED
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env node
2
+ import"./index-2z1qe5mw.js";import"./index-vxw0a03g.js";import"./index-ty698y02.js";import"./index-9zqnf6gx.js";import"./index-vq2978e7.js";import"./index-nvgwyykk.js";import"./index-wj8y1xcj.js";import{Zt,$n,jn,In}from"./index-9x1z3b85.js";import{St,Ot,an}from"./index-34s342fz.js";import{Pt,$t,jt,It,Et}from"./index-md79xr6h.js";import"./index-hq05mc1n.js";import"./index-5ngtc7gy.js";import{createRequire as C}from"node:module";var m=C(import.meta.url);import{createReadStream as b,createWriteStream as v}from"node:fs";import{readFile as p,stat as k}from"node:fs/promises";import{isAbsolute as I,resolve as l}from"node:path";import{pathToFileURL as M}from"node:url";import{randomBytes as P}from"node:crypto";var g=`
3
+ heyo-cms generate [--name <name>] write a migration for what changed
4
+ heyo-cms migrate apply pending migrations
5
+ heyo-cms status show applied, pending and unplanned changes
6
+
7
+ heyo-cms create-admin create an editor account from a shell
8
+ --email <address> required unless HEYO_CMS_ADMIN_EMAIL is set
9
+ --password <value> default: generated and printed once
10
+ --name <name> display name
11
+ --roles <a,b> default: admin
12
+
13
+ heyo-cms seed [--file <path>] run the project's seed module
14
+
15
+ heyo-cms export [--out <file>] write content as NDJSON (default: stdout)
16
+ --collections <a,b> default: every collection
17
+ --globals <a,b> default: every global
18
+ --include-trashed include documents in the trash
19
+
20
+ heyo-cms import <file> read an export back ("-" is stdin)
21
+ --on-conflict <skip|update|fail> default: skip
22
+ --dry-run parse and report without writing
23
+
24
+ heyo-cms telemetry print exactly what would be reported
25
+
26
+ --config <path> configuration module (default: ./heyo-cms.config.ts)
27
+ --dir <path> migrations directory (default: the one in the config)
28
+ --env <path> environment file (default: ./.env, then ./.env.local)
29
+ `;async function _(e){let{command:n,positionals:o,flags:t}=N(e);if(!n||n==="help"||t.has("--help"))return console.log(g),n&&n!=="help"?1:0;await U(t.get("--env"));let s=await j(t.get("--config"));switch(n){case"generate":case"migrate":case"status":return await A(n,s,t);case"create-admin":return await d(n,s,await x(s,t));case"seed":return await d(n,s,await O(s,t));case"export":return await d(n,s,await R(s,t));case"import":return await d(n,s,await W(s,o[1],t));case"telemetry":return await D(s);default:return console.error(`Unknown command: ${n}`),console.log(g),1}}async function A(e,n,o){let t=l(o.get("--dir")??n._config.migrationsDirectory),s=new Zt(t),a=await n.database();if(e==="generate"){let i=await $n({adapter:a,store:s,target:n.schema,plugins:n._config.plugins.flatMap((c)=>(c.migrations??[]).map((u)=>({plugin:c.id,id:u.id,steps:u.steps}))),...o.get("--name")?{name:o.get("--name")}:{}});if(i.created){console.log(`Wrote ${i.file}`);for(let c of i.summary)console.log(` ${c}`)}for(let c of i.plugins??[])console.log(`Wrote ${c.file} (plugin migration)`);if(!i.created&&(i.plugins??[]).length===0)console.log("No schema changes. Nothing to generate.");return await d(e,n,0)}if(e==="migrate"){let i=await jn({adapter:a,store:s});if(i.applied.length===0)return console.log(`Up to date (${i.alreadyApplied} migration(s) already applied).`),await d(e,n,0);for(let c of i.applied)console.log(`Applied ${c}`);return await d(e,n,0)}let r=await In({adapter:a,store:s,target:n.schema});console.log(`Applied: ${r.applied.length}`);for(let i of r.pending)console.log(` pending ${i}`);for(let i of r.modified)console.log(` MODIFIED ${i} (applied, then edited)`);if(r.unplanned.length>0)console.log(` ${r.unplanned.length} change(s) in the configuration have no migration yet; run "heyo-cms generate".`);return r.pending.length>0||r.modified.length>0||r.unplanned.length>0?1:0}async function x(e,n){let o=n.get("--email")??process.env.HEYO_CMS_ADMIN_EMAIL;if(!o)return console.error("An address is required: heyo-cms create-admin --email you@example.com"),1;let t=n.get("--password")??process.env.HEYO_CMS_ADMIN_PASSWORD,s=t??E(),a=(n.get("--roles")??"admin").split(",").map((c)=>c.trim()).filter((c)=>c.length>0),r=await e.auth.users.byEmail(o);if(r)return console.error(`${o} already has an account (${r.status}). Use the panel, or cms.auth.users.setPassword().`),1;let i=await e.auth.users.create({email:o,password:s,roles:a,status:"active",...n.get("--name")?{name:n.get("--name")}:{}});if(await e.drainEvents(),console.log(`Created ${i.email} with role(s) ${i.roles.join(", ")}.`),!t)console.log(`Password: ${s}`),console.log("This is the only time it is shown.");return console.log(`Sign in at ${e._config.basePath}${e._config.admin.path}.`),0}function E(){return P(24).toString("base64url")}var S=["heyo-cms.seed.ts","heyo-cms.seed.js","seed.ts","src/heyo-cms.seed.ts"];async function O(e,n){let o=n.get("--file")?l(n.get("--file")):await y(S,"seed module"),t=await h(o),s=t.seed??t.default;if(typeof s!=="function")return console.error(`${o} does not export a seed. Add \`export async function seed(cms) { ... }\`.`),1;return await s(e),await e.drainEvents(),console.log(`Seeded from ${o}.`),0}async function R(e,n){let o=n.get("--out"),t=o?F(l(o)):Y(),s=0,a=0;try{for await(let r of It(e,{...f(n,"--collections","collections"),...f(n,"--globals","globals"),...n.has("--include-trashed")?{includeTrashed:!0}:{}})){if(r.kind==="document")s+=1;if(r.kind==="global")a+=1;await t.line(jt(r))}}finally{await t.close()}return console.error(`Exported ${s} document(s) and ${a} global(s).`),0}async function W(e,n,o){if(!n)return console.error('A file is required: heyo-cms import content.ndjson (or "-").'),1;let t=o.get("--on-conflict")??"skip";if(!["skip","update","fail"].includes(t))return console.error(`--on-conflict takes skip, update or fail; got ${t}.`),1;let s={onConflict:t,...o.has("--dry-run")?{dryRun:!0}:{}},a=n==="-"?H():q(l(n)),r=await Et(e,Pt($t(a)),s),i=s.dryRun?"Would import":"Imported";if(console.log(`${i} ${r.documents.created} new and ${r.documents.updated} updated document(s), ${r.globals.updated} global(s).`),r.documents.skipped>0)console.log(`Skipped ${r.documents.skipped} document(s).`);for(let c of r.errors)console.error(` ${c}`);return r.errors.length>0?1:0}async function D(e){let n=St(e._config.telemetry),o=Ot("telemetry",e,await w());return console.log(n.enabled?"Telemetry: on":"Telemetry: off"),console.log(` ${n.reason}`),console.log(""),console.log(" What a command would send, in full:"),console.log(""),console.log(JSON.stringify(o,null,2)),console.log(""),console.log(" Turn it off with any of:"),console.log(" HEYO_TELEMETRY_DISABLED=1"),console.log(" DO_NOT_TRACK=1"),console.log(" telemetry: { enabled: false } in heyo-cms.config.ts"),console.log(""),0}async function d(e,n,o){try{await an({event:e,cms:n,version:await w(),...n._config.telemetry?{config:n._config.telemetry}:{}})}catch{}return o}function N(e){let n=new Map,o=[];for(let t=0;t<e.length;t+=1){let s=e[t];if(!s.startsWith("--")){o.push(s);continue}let a=e[t+1];if(a!==void 0&&!a.startsWith("--"))n.set(s,a),t+=1;else n.set(s,"true")}return{command:o[0],positionals:o,flags:n}}function f(e,n,o){let t=e.get(n);if(!t||t==="true")return{};return{[o]:t.split(",").map((s)=>s.trim()).filter((s)=>s.length>0)}}var T=["heyo-cms.config.ts","heyo-cms.config.js","heyo-cms.config.mjs","src/heyo-cms.config.ts","app/heyo-cms.config.ts"];async function j(e){let n=e?l(e):await y(T,"configuration"),o=await h(n),t=o.cms??o.default;if(!L(t))throw Error(`${n} does not export a CMS. Add \`export const cms = heyoCms({ ... })\`.`);return t}async function h(e){return await(I(e)?import(M(e).href):import(e))}async function y(e,n){for(let o of e){let t=l(o);try{return await k(t),t}catch{}}throw Error(`No ${n} found. Looked for ${e.join(", ")}. Use --config or --file.`)}function L(e){return typeof e==="object"&&e!==null&&"_config"in e&&"schema"in e&&typeof e.database==="function"}async function U(e){let n=e?[l(e)]:[l(".env"),l(".env.local")];for(let o of n){let t;try{t=await p(o,"utf8")}catch{if(e)throw Error(`No environment file at ${o}.`);continue}for(let s of t.split(`
30
+ `)){let a=/^\s*(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.*)$/.exec(s);if(!a)continue;let[,r,i]=a;if(process.env[r]!==void 0)continue;let c=i.trim(),u=/^(["'])([\s\S]*)\1$/.exec(c);process.env[r]=u?u[2]:c.split(" #")[0].trim()}}}async function w(){try{let e=await p(new URL("../package.json",import.meta.url),"utf8");return JSON.parse(e).version??"0.0.0"}catch{return"0.0.0"}}function F(e){let n=v(e,{encoding:"utf8"});return{line:(o)=>new Promise((t,s)=>{n.write(o,(a)=>a?s(a):t())}),close:()=>new Promise((o)=>n.end(()=>o()))}}function Y(){return{line:(e)=>new Promise((n,o)=>{process.stdout.write(e,(t)=>t?o(t):n())}),close:async()=>{}}}async function*q(e){let n=b(e,{encoding:"utf8"});for await(let o of n)yield o}async function*H(){process.stdin.setEncoding("utf8");for await(let e of process.stdin)yield e}if(m.main==m.module)_(process.argv.slice(2)).then((e)=>{process.exitCode=e}).catch((e)=>{console.error(e instanceof Error?e.message:String(e)),process.exitCode=1});export{_ as main};
@@ -0,0 +1,51 @@
1
+ import type { CmsPlugin } from "../types/plugin";
2
+ import type { CmsClient, PluginExtensions } from "./types";
3
+ /**
4
+ * The typed client.
5
+ *
6
+ * The public entry point picks up the project's registered CMS type, so
7
+ * `heyoCmsClient()` is typed without importing server configuration into the
8
+ * browser bundle. `heyoCmsClient<typeof cms>()` remains available for a
9
+ * project with more than one CMS. The methods
10
+ * mirror `cms.api` exactly, because the routes they call are three lines
11
+ * around `cms.api`: code written against the local API moves to the client by
12
+ * changing the object it is called on.
13
+ *
14
+ * What it is not: an ORM, a cache or a state manager. It is `fetch` with the
15
+ * URL building, the error shape and the 204 convention taken care of, and it
16
+ * is tiny on purpose — this ships to browsers.
17
+ */
18
+ export interface CmsClientOptions<TPlugins extends readonly CmsPlugin<unknown>[] = []> {
19
+ /**
20
+ * Where the handler is mounted.
21
+ *
22
+ * Defaults to the same-origin `/api/heyo-cms` mount in a browser. Set this
23
+ * for a custom mount or a CMS on another origin, e.g.
24
+ * `https://cms.acme.dev/api/heyo-cms`.
25
+ */
26
+ baseUrl?: string;
27
+ /**
28
+ * A session token or an API key.
29
+ *
30
+ * A function is resolved per request, which is what makes a rotating key or
31
+ * a token read out of a cookie store work without rebuilding the client.
32
+ * Omit it in a browser: the session cookie is sent automatically.
33
+ */
34
+ token?: string | (() => string | null | undefined | Promise<string | null | undefined>);
35
+ headers?: Record<string, string> | (() => Record<string, string> | Promise<Record<string, string>>);
36
+ /** Injectable so a test, a Worker or a framework's own `fetch` can be used. */
37
+ fetch?: typeof fetch;
38
+ /** Defaults to `same-origin`, which is what a cookie session needs. */
39
+ credentials?: RequestCredentials;
40
+ /**
41
+ * The plugins whose client extensions should be installed.
42
+ *
43
+ * Passed rather than discovered: the configuration lives on the server and
44
+ * the client is a browser bundle, so the only way the extension types can
45
+ * reach it is through this list.
46
+ */
47
+ plugins?: TPlugins;
48
+ }
49
+ export declare function heyoCmsClient<TCms = import("../types/instance").CmsInstance, const TPlugins extends readonly CmsPlugin<unknown>[] = []>(options?: CmsClientOptions<TPlugins>): CmsClient<TCms> & PluginExtensions<TPlugins>;
50
+ export type * from "./types";
51
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEjD,OAAO,KAAK,EASV,SAAS,EACT,gBAAgB,EACjB,MAAM,SAAS,CAAC;AAEjB;;;;;;;;;;;;;;GAcG;AAEH,MAAM,WAAW,gBAAgB,CAC/B,QAAQ,SAAS,SAAS,SAAS,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE;IAEnD;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;;;OAMG;IACH,KAAK,CAAC,EAAE,MAAM,GAAG,CAAC,MAAM,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC,CAAC;IACxF,OAAO,CAAC,EACJ,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACtB,CAAC,MAAM,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;IACrE,+EAA+E;IAC/E,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;IACrB,uEAAuE;IACvE,WAAW,CAAC,EAAE,kBAAkB,CAAC;IACjC;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,QAAQ,CAAC;CACpB;AAED,wBAAgB,aAAa,CAC3B,IAAI,GAAG,OAAO,mBAAmB,EAAE,WAAW,EAC9C,KAAK,CAAC,QAAQ,SAAS,SAAS,SAAS,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,EAEzD,OAAO,GAAE,gBAAgB,CAAC,QAAQ,CAAM,GACvC,SAAS,CAAC,IAAI,CAAC,GAAG,gBAAgB,CAAC,QAAQ,CAAC,CAmO9C;AA+RD,mBAAmB,SAAS,CAAC"}
@@ -0,0 +1,340 @@
1
+ import type { CollectionsConfig, GlobalsConfig, InferDocument } from "../types/config";
2
+ import type { CmsInstance } from "../types/instance";
3
+ import type { ActivityListArgs, ActivityPage } from "../types/activity";
4
+ import type { ApiKeyRecord, CmsUser, IssuedApiKey, RoleRecord, SignInResult } from "../types/auth";
5
+ import type { FindResult } from "../types/api";
6
+ import type { JsonObject } from "../types/json";
7
+ import type { LocaleRecord } from "../types/locales";
8
+ import type { MediaDocument, MediaListResult, MediaUsage } from "../types/media";
9
+ import type { CmsPlugin } from "../types/plugin";
10
+ import type { OrderBy, Where } from "../types/query";
11
+ import type { TrashPage } from "../types/trash";
12
+ import type { JobFailure, JobRunReport } from "../types/jobs";
13
+ /**
14
+ * The typed client's argument types.
15
+ *
16
+ * Shaped after the local API on purpose: `client.posts.find({ where: eq(...) })`
17
+ * and `cms.api.posts.find({ where: eq(...) })` take the same object, because
18
+ * the second is what the first ends up calling (section 10). The filter
19
+ * helpers from `@heyo-sh/heyo-cms/query` therefore work on both sides of the
20
+ * network, and there is one query language in the product rather than one per
21
+ * transport.
22
+ */
23
+ export interface ClientLocaleArgs {
24
+ locale?: string;
25
+ fallbackLocale?: string | false;
26
+ }
27
+ export interface ClientReadArgs extends ClientLocaleArgs {
28
+ depth?: number;
29
+ includeTrashed?: boolean;
30
+ /** Per-call headers, e.g. a one-off `authorization`. */
31
+ headers?: Record<string, string>;
32
+ signal?: AbortSignal;
33
+ }
34
+ export interface ClientFindArgs extends ClientReadArgs {
35
+ where?: Where;
36
+ orderBy?: OrderBy[];
37
+ limit?: number;
38
+ offset?: number;
39
+ cursor?: string;
40
+ count?: boolean;
41
+ }
42
+ export type ClientInput<TDoc> = Partial<Omit<TDoc, "id" | "createdAt" | "updatedAt" | "updatedBy" | "deletedAt" | "purgeAfter" | "scheduledAt" | "scheduledPatch" | "_fallback">>;
43
+ export interface ClientCreateArgs<TDoc> extends ClientReadArgs {
44
+ data: ClientInput<TDoc>;
45
+ }
46
+ export interface ClientUpdateArgs<TDoc> extends ClientReadArgs {
47
+ id: string;
48
+ data: ClientInput<TDoc>;
49
+ }
50
+ export interface ClientDeleteArgs extends ClientReadArgs {
51
+ id: string;
52
+ /** Skips the trash. Governed by the `purge` permission. */
53
+ permanent?: boolean;
54
+ }
55
+ export interface ClientScheduleArgs<TDoc> extends ClientReadArgs {
56
+ id: string;
57
+ at: Date | string;
58
+ data: ClientInput<TDoc>;
59
+ }
60
+ /**
61
+ * One collection, over HTTP.
62
+ *
63
+ * A write answers `null` when a `before` hook stopped it — the 204 the route
64
+ * sends — so the client's return types match the local API's exactly and code
65
+ * can move between them without a change.
66
+ */
67
+ export interface ClientCollection<TDoc> {
68
+ find(args?: ClientFindArgs): Promise<FindResult<TDoc>>;
69
+ findById(id: string, args?: ClientReadArgs): Promise<TDoc | null>;
70
+ create(args: ClientCreateArgs<TDoc>): Promise<TDoc | null>;
71
+ update(args: ClientUpdateArgs<TDoc>): Promise<TDoc | null>;
72
+ delete(args: ClientDeleteArgs): Promise<TDoc | null>;
73
+ restore(args: {
74
+ id: string;
75
+ } & ClientReadArgs): Promise<TDoc | null>;
76
+ schedule(args: ClientScheduleArgs<TDoc>): Promise<TDoc | null>;
77
+ unschedule(args: {
78
+ id: string;
79
+ } & ClientReadArgs): Promise<TDoc | null>;
80
+ }
81
+ export interface ClientGlobal<TDoc> {
82
+ get(args?: ClientReadArgs): Promise<TDoc>;
83
+ update(args: {
84
+ data: ClientInput<TDoc>;
85
+ } & ClientReadArgs): Promise<TDoc | null>;
86
+ schedule(args: {
87
+ at: Date | string;
88
+ data: ClientInput<TDoc>;
89
+ } & ClientReadArgs): Promise<TDoc | null>;
90
+ unschedule(args?: ClientReadArgs): Promise<TDoc | null>;
91
+ }
92
+ export interface ClientUploadArgs {
93
+ file: Blob | Uint8Array | ArrayBuffer;
94
+ filename?: string;
95
+ contentType?: string;
96
+ alt?: string;
97
+ locale?: string;
98
+ metadata?: JsonObject;
99
+ signal?: AbortSignal;
100
+ }
101
+ export interface ClientMedia {
102
+ upload(args: ClientUploadArgs | File): Promise<MediaDocument>;
103
+ list(args?: {
104
+ status?: MediaDocument["status"];
105
+ mimeType?: string;
106
+ search?: string;
107
+ limit?: number;
108
+ cursor?: string;
109
+ }): Promise<MediaListResult>;
110
+ get(id: string): Promise<MediaDocument | null>;
111
+ update(args: {
112
+ id: string;
113
+ filename?: string;
114
+ alt?: string | Record<string, string>;
115
+ locale?: string;
116
+ focalPoint?: {
117
+ x: number;
118
+ y: number;
119
+ } | null;
120
+ crop?: {
121
+ x: number;
122
+ y: number;
123
+ width: number;
124
+ height: number;
125
+ } | null;
126
+ metadata?: JsonObject;
127
+ }): Promise<MediaDocument>;
128
+ delete(args: {
129
+ id: string;
130
+ force?: boolean;
131
+ }): Promise<MediaDocument>;
132
+ keep(args: {
133
+ id: string;
134
+ }): Promise<MediaDocument>;
135
+ usages(id: string): Promise<MediaUsage[]>;
136
+ /**
137
+ * The URL of a size, built rather than fetched.
138
+ *
139
+ * A string, not a request: this is what goes into an `<img src>`, and a
140
+ * client that had to await the bytes to produce a URL would make rendering
141
+ * a list of thumbnails a waterfall.
142
+ */
143
+ url(id: string, variant?: string): string;
144
+ }
145
+ export interface ClientAuth {
146
+ signIn(args: {
147
+ email: string;
148
+ password: string;
149
+ }): Promise<SignInResult>;
150
+ /**
151
+ * Creates the first account on a CMS that has none, and signs it in.
152
+ *
153
+ * Answers 409 once any account exists; `GET /panel` reports whether it is
154
+ * still open as `auth.setupRequired`.
155
+ */
156
+ claimFirstAccount(args: {
157
+ email: string;
158
+ password: string;
159
+ name?: string;
160
+ }): Promise<SignInResult>;
161
+ signOut(): Promise<void>;
162
+ session(): Promise<{
163
+ actor: unknown | null;
164
+ user: CmsUser | null;
165
+ }>;
166
+ magicLink(args: {
167
+ email: string;
168
+ }): Promise<{
169
+ status: string;
170
+ }>;
171
+ verifyMagicLink(args: {
172
+ token: string;
173
+ }): Promise<SignInResult>;
174
+ forgotPassword(args: {
175
+ email: string;
176
+ }): Promise<{
177
+ status: string;
178
+ }>;
179
+ resetPassword(args: {
180
+ token: string;
181
+ password: string;
182
+ }): Promise<{
183
+ user: CmsUser;
184
+ }>;
185
+ acceptInvite(args: {
186
+ token: string;
187
+ password?: string;
188
+ name?: string;
189
+ }): Promise<SignInResult>;
190
+ verifyTwoFactor(args: {
191
+ challenge: string;
192
+ code: string;
193
+ }): Promise<SignInResult>;
194
+ beginTwoFactor(): Promise<{
195
+ secret: string;
196
+ uri: string;
197
+ }>;
198
+ enableTwoFactor(args: {
199
+ code: string;
200
+ }): Promise<{
201
+ user: CmsUser;
202
+ }>;
203
+ disableTwoFactor(): Promise<{
204
+ user: CmsUser;
205
+ }>;
206
+ apiKeys: {
207
+ list(): Promise<ApiKeyRecord[]>;
208
+ create(args: {
209
+ name: string;
210
+ scopes?: string[];
211
+ }): Promise<IssuedApiKey>;
212
+ revoke(id: string): Promise<void>;
213
+ };
214
+ /** The URL to send a browser to for an OAuth or SSO sign-in. */
215
+ oauthUrl(provider: string, redirectTo?: string): string;
216
+ }
217
+ export interface ClientUsers {
218
+ list(args?: {
219
+ status?: CmsUser["status"];
220
+ search?: string;
221
+ limit?: number;
222
+ offset?: number;
223
+ }): Promise<{
224
+ users: CmsUser[];
225
+ totalUsers: number;
226
+ }>;
227
+ get(id: string): Promise<CmsUser | null>;
228
+ update(id: string, args: {
229
+ name?: string | null;
230
+ roles?: string[];
231
+ status?: CmsUser["status"];
232
+ locale?: string | null;
233
+ }): Promise<CmsUser>;
234
+ invite(args: {
235
+ email: string;
236
+ name?: string;
237
+ roles?: string[];
238
+ }): Promise<{
239
+ token: string;
240
+ expiresAt: string;
241
+ user: CmsUser;
242
+ }>;
243
+ remove(id: string): Promise<void>;
244
+ }
245
+ export interface ClientRoles {
246
+ list(): Promise<RoleRecord[]>;
247
+ create(args: {
248
+ name: string;
249
+ permissions: string[];
250
+ label?: string;
251
+ }): Promise<RoleRecord>;
252
+ update(name: string, args: {
253
+ permissions?: string[];
254
+ label?: string | null;
255
+ }): Promise<RoleRecord>;
256
+ remove(name: string): Promise<void>;
257
+ }
258
+ export interface ClientTrash {
259
+ list(args?: {
260
+ collection?: string;
261
+ limit?: number;
262
+ cursor?: string;
263
+ locale?: string;
264
+ }): Promise<TrashPage>;
265
+ restore(args: {
266
+ collection: string;
267
+ id: string;
268
+ }): Promise<JsonObject>;
269
+ purge(args: {
270
+ collection: string;
271
+ id: string;
272
+ }): Promise<JsonObject>;
273
+ }
274
+ /**
275
+ * The configured languages.
276
+ *
277
+ * Read-only, because `i18n.locales` is code: a client that could add one
278
+ * would be editing a file it cannot see.
279
+ */
280
+ export interface ClientLocales {
281
+ list(): Promise<{
282
+ locales: LocaleRecord[];
283
+ defaultLocale: string;
284
+ }>;
285
+ }
286
+ export interface ClientJobs {
287
+ run(args?: {
288
+ limit?: number;
289
+ only?: string[];
290
+ }): Promise<JobRunReport>;
291
+ failures(args?: {
292
+ type?: string;
293
+ limit?: number;
294
+ }): Promise<JobFailure[]>;
295
+ }
296
+ /** The escape hatch, and what a plugin's client extension is built on. */
297
+ export interface ClientRequest {
298
+ (path: string, init?: RequestInit & {
299
+ query?: Record<string, unknown>;
300
+ }): Promise<unknown>;
301
+ }
302
+ export interface ClientCore {
303
+ baseUrl: string;
304
+ request: ClientRequest;
305
+ media: ClientMedia;
306
+ auth: ClientAuth;
307
+ users: ClientUsers;
308
+ roles: ClientRoles;
309
+ trash: ClientTrash;
310
+ locales: ClientLocales;
311
+ activity: {
312
+ list(args?: ActivityListArgs): Promise<ActivityPage>;
313
+ };
314
+ jobs: ClientJobs;
315
+ openapi(): Promise<JsonObject>;
316
+ }
317
+ /** Collections become top-level properties, as in `client.posts.find()`. */
318
+ export type ClientCollections<TCollections extends CollectionsConfig> = {
319
+ [K in keyof TCollections]: ClientCollection<InferDocument<TCollections[K]>>;
320
+ };
321
+ export type ClientGlobals<TGlobals extends GlobalsConfig> = {
322
+ [K in keyof TGlobals]: ClientGlobal<InferDocument<TGlobals[K]>>;
323
+ };
324
+ /**
325
+ * The client for one configuration.
326
+ *
327
+ * `globals` is a property rather than being flattened next to the collections
328
+ * because a global and a collection can share a name in different registries
329
+ * and a flat namespace would make that a silent overwrite.
330
+ */
331
+ export type CmsClient<TCms> = TCms extends CmsInstance<infer TCollections, infer TGlobals> ? ClientCore & ClientCollections<TCollections> & {
332
+ globals: ClientGlobals<TGlobals>;
333
+ } : never;
334
+ /** Turns a plugin tuple into the intersection of what their clients add. */
335
+ export type PluginExtensions<TPlugins extends readonly CmsPlugin<unknown>[]> = UnionToIntersection<{
336
+ [K in keyof TPlugins]: TPlugins[K] extends CmsPlugin<infer Ext> ? Ext : never;
337
+ }[number]>;
338
+ type UnionToIntersection<TUnion> = (TUnion extends unknown ? (value: TUnion) => void : never) extends (value: infer TIntersection) => void ? TIntersection : never;
339
+ export {};
340
+ //# sourceMappingURL=types.d.ts.map