@xtandard/kit 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.
- package/LICENSE +21 -0
- package/README.md +71 -2
- package/bin/xtandard-kit.mjs +3 -0
- package/dist/base-path-BJugWLNO.cjs +42 -0
- package/dist/base-path-BJugWLNO.cjs.map +1 -0
- package/dist/base-path-CDb4In5E.mjs +31 -0
- package/dist/base-path-CDb4In5E.mjs.map +1 -0
- package/dist/basic-Qtriv0xS.mjs +176 -0
- package/dist/basic-Qtriv0xS.mjs.map +1 -0
- package/dist/basic-ZaO92-lB.cjs +199 -0
- package/dist/basic-ZaO92-lB.cjs.map +1 -0
- package/dist/bin.cjs +126 -0
- package/dist/bin.cjs.map +1 -0
- package/dist/bin.d.cts +20 -0
- package/dist/bin.d.mts +20 -0
- package/dist/bin.mjs +125 -0
- package/dist/bin.mjs.map +1 -0
- package/dist/cas-CuPSaXBV.cjs +23 -0
- package/dist/cas-CuPSaXBV.cjs.map +1 -0
- package/dist/cas-CzA-yECx.mjs +18 -0
- package/dist/cas-CzA-yECx.mjs.map +1 -0
- package/dist/chunk-DakpK96I.cjs +43 -0
- package/dist/contract-B3UPXXLx.d.cts +30 -0
- package/dist/contract-B3UPXXLx.d.mts +30 -0
- package/dist/contract-BDPNvjtp.d.mts +64 -0
- package/dist/contract-BEdfGTPs.mjs +85 -0
- package/dist/contract-BEdfGTPs.mjs.map +1 -0
- package/dist/contract-BIVzAn4f.d.cts +64 -0
- package/dist/contract-BvgtswLX.d.cts +75 -0
- package/dist/contract-BvgtswLX.d.mts +75 -0
- package/dist/contract-DUj9P3Vt.d.cts +72 -0
- package/dist/contract-DUj9P3Vt.d.mts +72 -0
- package/dist/contract-wAEMDmYG.cjs +132 -0
- package/dist/contract-wAEMDmYG.cjs.map +1 -0
- package/dist/drizzle-BElCHWri.d.mts +115 -0
- package/dist/drizzle-BXaQXCr0.cjs +232 -0
- package/dist/drizzle-BXaQXCr0.cjs.map +1 -0
- package/dist/drizzle-CEpahWQB.d.cts +115 -0
- package/dist/drizzle-DxnelsPT.mjs +197 -0
- package/dist/drizzle-DxnelsPT.mjs.map +1 -0
- package/dist/duration-7WpAK-xe.mjs +52 -0
- package/dist/duration-7WpAK-xe.mjs.map +1 -0
- package/dist/duration-DVA0Fzkx.cjs +63 -0
- package/dist/duration-DVA0Fzkx.cjs.map +1 -0
- package/dist/duration-FPwbmWIU.d.cts +35 -0
- package/dist/duration-FPwbmWIU.d.mts +35 -0
- package/dist/entry-adapters-bun.cjs +10 -0
- package/dist/entry-adapters-bun.cjs.map +1 -0
- package/dist/entry-adapters-bun.d.cts +10 -0
- package/dist/entry-adapters-bun.d.mts +10 -0
- package/dist/entry-adapters-bun.mjs +9 -0
- package/dist/entry-adapters-bun.mjs.map +1 -0
- package/dist/entry-adapters-elysia.cjs +54 -0
- package/dist/entry-adapters-elysia.cjs.map +1 -0
- package/dist/entry-adapters-elysia.d.cts +38 -0
- package/dist/entry-adapters-elysia.d.mts +38 -0
- package/dist/entry-adapters-elysia.mjs +53 -0
- package/dist/entry-adapters-elysia.mjs.map +1 -0
- package/dist/entry-adapters-express.cjs +27 -0
- package/dist/entry-adapters-express.cjs.map +1 -0
- package/dist/entry-adapters-express.d.cts +24 -0
- package/dist/entry-adapters-express.d.mts +24 -0
- package/dist/entry-adapters-express.mjs +26 -0
- package/dist/entry-adapters-express.mjs.map +1 -0
- package/dist/entry-adapters-hono.cjs +33 -0
- package/dist/entry-adapters-hono.cjs.map +1 -0
- package/dist/entry-adapters-hono.d.cts +36 -0
- package/dist/entry-adapters-hono.d.mts +36 -0
- package/dist/entry-adapters-hono.mjs +30 -0
- package/dist/entry-adapters-hono.mjs.map +1 -0
- package/dist/entry-adapters-next.cjs +19 -0
- package/dist/entry-adapters-next.cjs.map +1 -0
- package/dist/entry-adapters-next.d.cts +35 -0
- package/dist/entry-adapters-next.d.mts +35 -0
- package/dist/entry-adapters-next.mjs +18 -0
- package/dist/entry-adapters-next.mjs.map +1 -0
- package/dist/entry-adapters-node.cjs +7 -0
- package/dist/entry-adapters-node.d.cts +2 -0
- package/dist/entry-adapters-node.d.mts +2 -0
- package/dist/entry-adapters-node.mjs +2 -0
- package/dist/entry-auth-basic.cjs +5 -0
- package/dist/entry-auth-basic.d.cts +83 -0
- package/dist/entry-auth-basic.d.mts +83 -0
- package/dist/entry-auth-basic.mjs +2 -0
- package/dist/entry-auth-delegated.cjs +28 -0
- package/dist/entry-auth-delegated.cjs.map +1 -0
- package/dist/entry-auth-delegated.d.cts +36 -0
- package/dist/entry-auth-delegated.d.mts +36 -0
- package/dist/entry-auth-delegated.mjs +27 -0
- package/dist/entry-auth-delegated.mjs.map +1 -0
- package/dist/entry-auth-none.cjs +4 -0
- package/dist/entry-auth-none.d.cts +25 -0
- package/dist/entry-auth-none.d.mts +25 -0
- package/dist/entry-auth-none.mjs +2 -0
- package/dist/entry-auth.cjs +0 -0
- package/dist/entry-auth.d.cts +2 -0
- package/dist/entry-auth.d.mts +2 -0
- package/dist/entry-auth.mjs +1 -0
- package/dist/entry-authorization-delegated.cjs +27 -0
- package/dist/entry-authorization-delegated.cjs.map +1 -0
- package/dist/entry-authorization-delegated.d.cts +31 -0
- package/dist/entry-authorization-delegated.d.mts +31 -0
- package/dist/entry-authorization-delegated.mjs +26 -0
- package/dist/entry-authorization-delegated.mjs.map +1 -0
- package/dist/entry-authorization-none.cjs +3 -0
- package/dist/entry-authorization-none.d.cts +18 -0
- package/dist/entry-authorization-none.d.mts +18 -0
- package/dist/entry-authorization-none.mjs +2 -0
- package/dist/entry-authorization-roles.cjs +3 -0
- package/dist/entry-authorization-roles.d.cts +2 -0
- package/dist/entry-authorization-roles.d.mts +2 -0
- package/dist/entry-authorization-roles.mjs +2 -0
- package/dist/entry-authorization.cjs +35 -0
- package/dist/entry-authorization.cjs.map +1 -0
- package/dist/entry-authorization.d.cts +2 -0
- package/dist/entry-authorization.d.mts +2 -0
- package/dist/entry-authorization.mjs +34 -0
- package/dist/entry-authorization.mjs.map +1 -0
- package/dist/entry-build.cjs +481 -0
- package/dist/entry-build.cjs.map +1 -0
- package/dist/entry-build.d.cts +355 -0
- package/dist/entry-build.d.mts +355 -0
- package/dist/entry-build.mjs +460 -0
- package/dist/entry-build.mjs.map +1 -0
- package/dist/entry-cli.cjs +368 -0
- package/dist/entry-cli.cjs.map +1 -0
- package/dist/entry-cli.d.cts +275 -0
- package/dist/entry-cli.d.mts +275 -0
- package/dist/entry-cli.mjs +355 -0
- package/dist/entry-cli.mjs.map +1 -0
- package/dist/entry-drizzle-mysql.cjs +36 -0
- package/dist/entry-drizzle-mysql.cjs.map +1 -0
- package/dist/entry-drizzle-mysql.d.cts +55 -0
- package/dist/entry-drizzle-mysql.d.mts +55 -0
- package/dist/entry-drizzle-mysql.mjs +34 -0
- package/dist/entry-drizzle-mysql.mjs.map +1 -0
- package/dist/entry-drizzle-pg.cjs +38 -0
- package/dist/entry-drizzle-pg.cjs.map +1 -0
- package/dist/entry-drizzle-pg.d.cts +78 -0
- package/dist/entry-drizzle-pg.d.mts +78 -0
- package/dist/entry-drizzle-pg.mjs +36 -0
- package/dist/entry-drizzle-pg.mjs.map +1 -0
- package/dist/entry-drizzle-sqlite.cjs +20 -0
- package/dist/entry-drizzle-sqlite.cjs.map +1 -0
- package/dist/entry-drizzle-sqlite.d.cts +22 -0
- package/dist/entry-drizzle-sqlite.d.mts +22 -0
- package/dist/entry-drizzle-sqlite.mjs +19 -0
- package/dist/entry-drizzle-sqlite.mjs.map +1 -0
- package/dist/entry-hooks-log.cjs +32 -0
- package/dist/entry-hooks-log.cjs.map +1 -0
- package/dist/entry-hooks-log.d.cts +36 -0
- package/dist/entry-hooks-log.d.mts +36 -0
- package/dist/entry-hooks-log.mjs +31 -0
- package/dist/entry-hooks-log.mjs.map +1 -0
- package/dist/entry-hooks.cjs +10 -0
- package/dist/entry-hooks.d.cts +2 -0
- package/dist/entry-hooks.d.mts +2 -0
- package/dist/entry-hooks.mjs +2 -0
- package/dist/entry-server-router.cjs +235 -0
- package/dist/entry-server-router.cjs.map +1 -0
- package/dist/entry-server-router.d.cts +193 -0
- package/dist/entry-server-router.d.mts +193 -0
- package/dist/entry-server-router.mjs +228 -0
- package/dist/entry-server-router.mjs.map +1 -0
- package/dist/entry-server.cjs +344 -0
- package/dist/entry-server.cjs.map +1 -0
- package/dist/entry-server.d.cts +230 -0
- package/dist/entry-server.d.mts +230 -0
- package/dist/entry-server.mjs +322 -0
- package/dist/entry-server.mjs.map +1 -0
- package/dist/entry-site.cjs +1083 -0
- package/dist/entry-site.cjs.map +1 -0
- package/dist/entry-site.d.cts +336 -0
- package/dist/entry-site.d.mts +336 -0
- package/dist/entry-site.mjs +1060 -0
- package/dist/entry-site.mjs.map +1 -0
- package/dist/entry-storage-cloudflare-kv.cjs +51 -0
- package/dist/entry-storage-cloudflare-kv.cjs.map +1 -0
- package/dist/entry-storage-cloudflare-kv.d.cts +52 -0
- package/dist/entry-storage-cloudflare-kv.d.mts +52 -0
- package/dist/entry-storage-cloudflare-kv.mjs +50 -0
- package/dist/entry-storage-cloudflare-kv.mjs.map +1 -0
- package/dist/entry-storage-drizzle-internals.cjs +6 -0
- package/dist/entry-storage-drizzle-internals.d.cts +2 -0
- package/dist/entry-storage-drizzle-internals.d.mts +2 -0
- package/dist/entry-storage-drizzle-internals.mjs +2 -0
- package/dist/entry-storage-drizzle.cjs +4 -0
- package/dist/entry-storage-drizzle.d.cts +3 -0
- package/dist/entry-storage-drizzle.d.mts +3 -0
- package/dist/entry-storage-drizzle.mjs +2 -0
- package/dist/entry-storage-file.cjs +306 -0
- package/dist/entry-storage-file.cjs.map +1 -0
- package/dist/entry-storage-file.d.cts +76 -0
- package/dist/entry-storage-file.d.mts +76 -0
- package/dist/entry-storage-file.mjs +301 -0
- package/dist/entry-storage-file.mjs.map +1 -0
- package/dist/entry-storage-libsql-internals.cjs +7 -0
- package/dist/entry-storage-libsql-internals.d.cts +3 -0
- package/dist/entry-storage-libsql-internals.d.mts +3 -0
- package/dist/entry-storage-libsql-internals.mjs +3 -0
- package/dist/entry-storage-libsql.cjs +3 -0
- package/dist/entry-storage-libsql.d.cts +2 -0
- package/dist/entry-storage-libsql.d.mts +2 -0
- package/dist/entry-storage-libsql.mjs +2 -0
- package/dist/entry-storage-memory.cjs +78 -0
- package/dist/entry-storage-memory.cjs.map +1 -0
- package/dist/entry-storage-memory.d.cts +35 -0
- package/dist/entry-storage-memory.d.mts +35 -0
- package/dist/entry-storage-memory.mjs +77 -0
- package/dist/entry-storage-memory.mjs.map +1 -0
- package/dist/entry-storage-mongodb-internals.cjs +5 -0
- package/dist/entry-storage-mongodb-internals.d.cts +2 -0
- package/dist/entry-storage-mongodb-internals.d.mts +2 -0
- package/dist/entry-storage-mongodb-internals.mjs +2 -0
- package/dist/entry-storage-mongodb.cjs +3 -0
- package/dist/entry-storage-mongodb.d.cts +2 -0
- package/dist/entry-storage-mongodb.d.mts +2 -0
- package/dist/entry-storage-mongodb.mjs +2 -0
- package/dist/entry-storage-postgres-internals.cjs +6 -0
- package/dist/entry-storage-postgres-internals.d.cts +2 -0
- package/dist/entry-storage-postgres-internals.d.mts +2 -0
- package/dist/entry-storage-postgres-internals.mjs +2 -0
- package/dist/entry-storage-postgres.cjs +4 -0
- package/dist/entry-storage-postgres.d.cts +2 -0
- package/dist/entry-storage-postgres.d.mts +2 -0
- package/dist/entry-storage-postgres.mjs +2 -0
- package/dist/entry-storage-redis-internals.cjs +7 -0
- package/dist/entry-storage-redis-internals.d.cts +2 -0
- package/dist/entry-storage-redis-internals.d.mts +2 -0
- package/dist/entry-storage-redis-internals.mjs +2 -0
- package/dist/entry-storage-redis.cjs +4 -0
- package/dist/entry-storage-redis.d.cts +2 -0
- package/dist/entry-storage-redis.d.mts +2 -0
- package/dist/entry-storage-redis.mjs +2 -0
- package/dist/entry-storage-sqlite-internals.cjs +7 -0
- package/dist/entry-storage-sqlite-internals.d.cts +3 -0
- package/dist/entry-storage-sqlite-internals.d.mts +3 -0
- package/dist/entry-storage-sqlite-internals.mjs +3 -0
- package/dist/entry-storage-sqlite.cjs +3 -0
- package/dist/entry-storage-sqlite.d.cts +2 -0
- package/dist/entry-storage-sqlite.d.mts +2 -0
- package/dist/entry-storage-sqlite.mjs +2 -0
- package/dist/entry-storage-testing.cjs +801 -0
- package/dist/entry-storage-testing.cjs.map +1 -0
- package/dist/entry-storage-testing.d.cts +150 -0
- package/dist/entry-storage-testing.d.mts +150 -0
- package/dist/entry-storage-testing.mjs +790 -0
- package/dist/entry-storage-testing.mjs.map +1 -0
- package/dist/entry-storage-unstorage.cjs +78 -0
- package/dist/entry-storage-unstorage.cjs.map +1 -0
- package/dist/entry-storage-unstorage.d.cts +30 -0
- package/dist/entry-storage-unstorage.d.mts +30 -0
- package/dist/entry-storage-unstorage.mjs +77 -0
- package/dist/entry-storage-unstorage.mjs.map +1 -0
- package/dist/entry-storage.cjs +114 -0
- package/dist/entry-storage.cjs.map +1 -0
- package/dist/entry-storage.d.cts +152 -0
- package/dist/entry-storage.d.mts +152 -0
- package/dist/entry-storage.mjs +91 -0
- package/dist/entry-storage.mjs.map +1 -0
- package/dist/entry-testing.cjs +79 -0
- package/dist/entry-testing.cjs.map +1 -0
- package/dist/entry-testing.d.cts +55 -0
- package/dist/entry-testing.d.mts +55 -0
- package/dist/entry-testing.mjs +77 -0
- package/dist/entry-testing.mjs.map +1 -0
- package/dist/entry-tokens.cjs +4 -0
- package/dist/entry-tokens.d.cts +85 -0
- package/dist/entry-tokens.d.mts +85 -0
- package/dist/entry-tokens.mjs +2 -0
- package/dist/entry-ui-embed.cjs +131 -0
- package/dist/entry-ui-embed.cjs.map +1 -0
- package/dist/entry-ui-embed.d.cts +87 -0
- package/dist/entry-ui-embed.d.mts +87 -0
- package/dist/entry-ui-embed.mjs +127 -0
- package/dist/entry-ui-embed.mjs.map +1 -0
- package/dist/entry-ui.cjs +795 -0
- package/dist/entry-ui.cjs.map +1 -0
- package/dist/entry-ui.d.cts +574 -0
- package/dist/entry-ui.d.mts +574 -0
- package/dist/entry-ui.mjs +731 -0
- package/dist/entry-ui.mjs.map +1 -0
- package/dist/entry-util.cjs +145 -0
- package/dist/entry-util.cjs.map +1 -0
- package/dist/entry-util.d.cts +85 -0
- package/dist/entry-util.d.mts +85 -0
- package/dist/entry-util.mjs +130 -0
- package/dist/entry-util.mjs.map +1 -0
- package/dist/http-B_rTnLW9.cjs +235 -0
- package/dist/http-B_rTnLW9.cjs.map +1 -0
- package/dist/http-CxYM7kPT.d.mts +133 -0
- package/dist/http-DVdVI6kJ.mjs +164 -0
- package/dist/http-DVdVI6kJ.mjs.map +1 -0
- package/dist/http-XBVRk8uo.d.cts +133 -0
- package/dist/index.cjs +8 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +6 -0
- package/dist/index.d.mts +6 -0
- package/dist/index.mjs +7 -0
- package/dist/index.mjs.map +1 -0
- package/dist/json-CCyzstIm.d.cts +44 -0
- package/dist/json-CCyzstIm.d.mts +44 -0
- package/dist/json-CM7TwYQ7.cjs +92 -0
- package/dist/json-CM7TwYQ7.cjs.map +1 -0
- package/dist/json-CmM1M5Kz.mjs +63 -0
- package/dist/json-CmM1M5Kz.mjs.map +1 -0
- package/dist/keys-Bwubabk0.mjs +73 -0
- package/dist/keys-Bwubabk0.mjs.map +1 -0
- package/dist/keys-DQrwxDKI.cjs +126 -0
- package/dist/keys-DQrwxDKI.cjs.map +1 -0
- package/dist/kv-sqlite-B6iTLOx2.d.cts +20 -0
- package/dist/kv-sqlite-CHOdIMJ-.cjs +77 -0
- package/dist/kv-sqlite-CHOdIMJ-.cjs.map +1 -0
- package/dist/kv-sqlite-DIIPfflJ.mjs +66 -0
- package/dist/kv-sqlite-DIIPfflJ.mjs.map +1 -0
- package/dist/kv-sqlite-Tx4UedJs.d.mts +20 -0
- package/dist/libsql-0160BubR.d.mts +65 -0
- package/dist/libsql-BZmRZIqt.d.cts +65 -0
- package/dist/libsql-CiBfVtbS.cjs +103 -0
- package/dist/libsql-CiBfVtbS.cjs.map +1 -0
- package/dist/libsql-CkOjQINi.mjs +86 -0
- package/dist/libsql-CkOjQINi.mjs.map +1 -0
- package/dist/mongodb--Cuj7V_9.cjs +150 -0
- package/dist/mongodb--Cuj7V_9.cjs.map +1 -0
- package/dist/mongodb-DGtsolQ2.d.cts +61 -0
- package/dist/mongodb-JMizy4Wg.mjs +127 -0
- package/dist/mongodb-JMizy4Wg.mjs.map +1 -0
- package/dist/mongodb-xGEU5Gwz.d.mts +61 -0
- package/dist/node-B1Djcwfi.d.cts +57 -0
- package/dist/node-B1Djcwfi.d.mts +57 -0
- package/dist/node-BYjocCbU.mjs +167 -0
- package/dist/node-BYjocCbU.mjs.map +1 -0
- package/dist/node-DFFqYRk-.cjs +201 -0
- package/dist/node-DFFqYRk-.cjs.map +1 -0
- package/dist/none-BEY7Kc_-.mjs +33 -0
- package/dist/none-BEY7Kc_-.mjs.map +1 -0
- package/dist/none-BoQ6-30P.cjs +33 -0
- package/dist/none-BoQ6-30P.cjs.map +1 -0
- package/dist/none-CHwVkQL-.cjs +49 -0
- package/dist/none-CHwVkQL-.cjs.map +1 -0
- package/dist/none-yu3qC47E.mjs +23 -0
- package/dist/none-yu3qC47E.mjs.map +1 -0
- package/dist/peer-BIjBFzwQ.cjs +56 -0
- package/dist/peer-BIjBFzwQ.cjs.map +1 -0
- package/dist/peer-CTHMzOdn.mjs +40 -0
- package/dist/peer-CTHMzOdn.mjs.map +1 -0
- package/dist/portal-container-CJIcau3B.mjs +610 -0
- package/dist/portal-container-CJIcau3B.mjs.map +1 -0
- package/dist/portal-container-Ca1NxrLE.cjs +774 -0
- package/dist/portal-container-Ca1NxrLE.cjs.map +1 -0
- package/dist/postgres-BJzxKBk0.d.cts +72 -0
- package/dist/postgres-CA8_XcAE.cjs +164 -0
- package/dist/postgres-CA8_XcAE.cjs.map +1 -0
- package/dist/postgres-RfQMgAsj.d.mts +72 -0
- package/dist/postgres-aDiBmNzr.mjs +135 -0
- package/dist/postgres-aDiBmNzr.mjs.map +1 -0
- package/dist/redis-B2AS4xAQ.cjs +259 -0
- package/dist/redis-B2AS4xAQ.cjs.map +1 -0
- package/dist/redis-B362ofBw.d.cts +159 -0
- package/dist/redis-CahNAVTW.d.mts +159 -0
- package/dist/redis-hdoKymfG.mjs +218 -0
- package/dist/redis-hdoKymfG.mjs.map +1 -0
- package/dist/roles-7JPrQXZa.mjs +46 -0
- package/dist/roles-7JPrQXZa.mjs.map +1 -0
- package/dist/roles-B_8QqJ3j.cjs +56 -0
- package/dist/roles-B_8QqJ3j.cjs.map +1 -0
- package/dist/roles-DLISB4T3.d.mts +41 -0
- package/dist/roles-DQbbtUPW.d.cts +41 -0
- package/dist/rolldown-runtime-D7D4PA-g.mjs +13 -0
- package/dist/scope-css-BN3jf0ly.cjs +315 -0
- package/dist/scope-css-BN3jf0ly.cjs.map +1 -0
- package/dist/scope-css-BuJfRCsE.mjs +256 -0
- package/dist/scope-css-BuJfRCsE.mjs.map +1 -0
- package/dist/scoped-BRoE1W1x.cjs +175 -0
- package/dist/scoped-BRoE1W1x.cjs.map +1 -0
- package/dist/scoped-cFBbotCh.mjs +164 -0
- package/dist/scoped-cFBbotCh.mjs.map +1 -0
- package/dist/sqlite-B2g1JJz1.d.cts +47 -0
- package/dist/sqlite-BIPIlxfj.d.mts +47 -0
- package/dist/sqlite-BntoYaXZ.cjs +79 -0
- package/dist/sqlite-BntoYaXZ.cjs.map +1 -0
- package/dist/sqlite-DYJDcu7p.mjs +62 -0
- package/dist/sqlite-DYJDcu7p.mjs.map +1 -0
- package/dist/table-BrioFSra.d.cts +11 -0
- package/dist/table-BrioFSra.d.mts +11 -0
- package/dist/theme-context-DzZ1otaD.d.cts +270 -0
- package/dist/theme-context-J65pythD.d.mts +270 -0
- package/dist/ui/styles.css +239 -0
- package/dist/util-Dnj5T-yw.mjs +39 -0
- package/dist/util-Dnj5T-yw.mjs.map +1 -0
- package/dist/util-dAnTK9x-.cjs +74 -0
- package/dist/util-dAnTK9x-.cjs.map +1 -0
- package/dist/validation-B-atP968.mjs +191 -0
- package/dist/validation-B-atP968.mjs.map +1 -0
- package/dist/validation-BJifGoB2.d.mts +122 -0
- package/dist/validation-DLnzBVJr.cjs +258 -0
- package/dist/validation-DLnzBVJr.cjs.map +1 -0
- package/dist/validation-tfV2qhbD.d.cts +122 -0
- package/package.json +715 -4
- package/tsconfig/assets.d.ts +21 -0
- package/tsconfig/base.json +21 -0
- package/tsconfig/react.json +9 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entry-util.mjs","names":[],"sources":["../src/util/id.ts"],"sourcesContent":["/**\n * Entity id generation, in the three formats the products persist (ADR 0005:\n * a product keeps the format its stored ids already use).\n *\n * | format | shape | sortable | used by |\n * | ---------------- | ----------------------------------------------------------- | -------- | -------------- |\n * | `\"ulid\"` | `prefix_` + 26 Crockford base32 (10 time + 16 random), A–Z | yes | audit, links |\n * | `\"ulid-lower22\"` | `prefix_` + 22 lowercase Crockford (10 time + 12 random) | yes | entitlements |\n * | `\"base62\"` | `prefix_` + 22 base62 characters (128 random bits) | no | webhooks |\n *\n * The time-sortable formats encode integer milliseconds (fractional clock\n * values are floored) and are **monotonic within a generator**: ids minted in\n * the same millisecond, or under a clock that goes backwards, increment the\n * random part, so lexicographic order equals creation order. Each generator\n * keeps its own state. Zero dependencies (Web Crypto).\n *\n * @module\n */\n\n/** The id formats {@link createIdGenerator} supports. */\nexport type IdFormat = \"ulid\" | \"ulid-lower22\" | \"base62\";\n\n/** Options for {@link createIdGenerator}. */\nexport interface IdGeneratorOptions<Prefix extends string = string> {\n /** The id format. Persisted ids depend on it, so a product never changes it. */\n format: IdFormat;\n /**\n * The allowed prefixes. When given, the prefix union is inferred from it and\n * `newId` rejects any other prefix at runtime.\n */\n prefixes?: readonly Prefix[];\n /** Clock for the time-sortable formats (unix ms). Default `Date.now`. */\n now?: () => number;\n}\n\n/** What {@link createIdGenerator} returns. */\nexport interface IdGenerator<Prefix extends string = string> {\n /** The generator's format. */\n readonly format: IdFormat;\n /** A new id, e.g. `newId(\"evt\")` → `\"evt_01JD…\"`. `ms` overrides the clock for this id. */\n newId(prefix: Prefix, ms?: number): string;\n /** The regex an id of `prefix` must match. */\n idPattern(prefix: Prefix): RegExp;\n /**\n * The unix-ms timestamp embedded in a time-sortable id, or `null` when the\n * id is malformed or the format (`base62`) embeds no time.\n */\n idTime(id: string): number | null;\n}\n\nconst CROCKFORD = \"0123456789ABCDEFGHJKMNPQRSTVWXYZ\";\nconst BASE62 = \"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\";\nconst TIME_LEN = 10;\nconst MAX_TIME = 32 ** TIME_LEN - 1;\n\ninterface SortableSpec {\n alphabet: string;\n randomLen: number;\n charClass: string;\n}\n\nconst SORTABLE: Record<\"ulid\" | \"ulid-lower22\", SortableSpec> = {\n ulid: { alphabet: CROCKFORD, randomLen: 16, charClass: \"[0-9A-HJKMNP-TV-Z]\" },\n \"ulid-lower22\": {\n alphabet: CROCKFORD.toLowerCase(),\n randomLen: 12,\n charClass: \"[0-9a-hjkmnp-tv-z]\",\n },\n};\n\nfunction randomDigits(length: number): number[] {\n const bytes = crypto.getRandomValues(new Uint8Array(length));\n // 256 is a multiple of 32: `b % 32` is unbiased.\n return Array.from(bytes, (b) => b % 32);\n}\n\n/** Increment a base32 digit array by one (carry to the left); `null` on overflow. */\nfunction increment(digits: number[]): number[] | null {\n const next = digits.slice();\n for (let i = next.length - 1; i >= 0; i--) {\n if ((next[i] as number) < 31) {\n next[i] = (next[i] as number) + 1;\n return next;\n }\n next[i] = 0;\n }\n return null;\n}\n\nfunction encodeTime(ms: number, alphabet: string): string {\n let out = \"\";\n let value = ms;\n for (let i = 0; i < TIME_LEN; i++) {\n out = alphabet[value % 32] + out;\n value = Math.floor(value / 32);\n }\n return out;\n}\n\nfunction randomBase62(): string {\n const bytes = crypto.getRandomValues(new Uint8Array(16));\n let value = 0n;\n for (const b of bytes) value = (value << 8n) | BigInt(b);\n let out = \"\";\n while (value > 0n) {\n out = BASE62[Number(value % 62n)] + out;\n value /= 62n;\n }\n return out.padStart(22, \"0\");\n}\n\n/**\n * Create an id generator for one product. The prefix union is a type\n * parameter, so `newId(\"typo\")` fails to compile.\n *\n * @example\n * ```ts\n * import { createIdGenerator } from \"@xtandard/kit/util\";\n *\n * export const { newId, idPattern, idTime } = createIdGenerator({\n * format: \"ulid\",\n * prefixes: [\"evt\", \"chk\"],\n * });\n * newId(\"evt\"); // \"evt_01JD3Z…\" — sorts by creation time\n * ```\n */\nexport function createIdGenerator<const Prefix extends string = string>(\n options: IdGeneratorOptions<Prefix>,\n): IdGenerator<Prefix> {\n const { format } = options;\n const allowed = options.prefixes ? new Set<string>(options.prefixes) : null;\n const checkPrefix = (prefix: string): void => {\n if (allowed && !allowed.has(prefix)) {\n throw new TypeError(`newId: unknown id prefix \"${prefix}\"`);\n }\n };\n if (format === \"base62\") {\n return {\n format,\n newId: (prefix) => {\n checkPrefix(prefix);\n return `${prefix}_${randomBase62()}`;\n },\n idPattern: (prefix) => new RegExp(`^${escapeRegex(prefix)}_[0-9A-Za-z]{22}$`),\n idTime: () => null,\n };\n }\n const spec = SORTABLE[format];\n if (!spec) throw new TypeError(`createIdGenerator: unknown format \"${String(format)}\"`);\n const clock = options.now ?? Date.now;\n let lastTime = -1;\n let lastRandom: number[] = [];\n\n const sortable = (input: number): string => {\n let ms = Math.min(Math.max(0, Math.floor(input)), MAX_TIME);\n let random: number[] | null = null;\n if (ms <= lastTime) {\n random = increment(lastRandom);\n // Random part exhausted within one millisecond: move to the next one.\n if (random) ms = lastTime;\n else ms = lastTime + 1;\n }\n random ??= randomDigits(spec.randomLen);\n lastTime = ms;\n lastRandom = random;\n return encodeTime(ms, spec.alphabet) + random.map((d) => spec.alphabet[d]).join(\"\");\n };\n\n return {\n format,\n newId: (prefix, ms) => {\n checkPrefix(prefix);\n return `${prefix}_${sortable(ms ?? clock())}`;\n },\n idPattern: (prefix) =>\n new RegExp(`^${escapeRegex(prefix)}_${spec.charClass}{${TIME_LEN + spec.randomLen}}$`),\n idTime(id) {\n const start = id.indexOf(\"_\") + 1;\n const raw = id.slice(start, start + TIME_LEN);\n if (raw.length !== TIME_LEN) return null;\n let ms = 0;\n for (const ch of raw) {\n const digit = spec.alphabet.indexOf(ch);\n if (digit === -1) return null;\n ms = ms * 32 + digit;\n }\n return ms;\n },\n };\n}\n\nconst escapeRegex = (value: string): string => value.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n"],"mappings":";;;;AAkDA,MAAM,YAAY;AAClB,MAAM,SAAS;AACf,MAAM,WAAW;AACjB,MAAM,WAAW,MAAM,WAAW;AAQlC,MAAM,WAA0D;CAC9D,MAAM;EAAE,UAAU;EAAW,WAAW;EAAI,WAAW;CAAqB;CAC5E,gBAAgB;EACd,UAAU,UAAU,YAAY;EAChC,WAAW;EACX,WAAW;CACb;AACF;AAEA,SAAS,aAAa,QAA0B;CAC9C,MAAM,QAAQ,OAAO,gBAAgB,IAAI,WAAW,MAAM,CAAC;CAE3D,OAAO,MAAM,KAAK,QAAQ,MAAM,IAAI,EAAE;AACxC;;AAGA,SAAS,UAAU,QAAmC;CACpD,MAAM,OAAO,OAAO,MAAM;CAC1B,KAAK,IAAI,IAAI,KAAK,SAAS,GAAG,KAAK,GAAG,KAAK;EACzC,IAAK,KAAK,KAAgB,IAAI;GAC5B,KAAK,KAAM,KAAK,KAAgB;GAChC,OAAO;EACT;EACA,KAAK,KAAK;CACZ;CACA,OAAO;AACT;AAEA,SAAS,WAAW,IAAY,UAA0B;CACxD,IAAI,MAAM;CACV,IAAI,QAAQ;CACZ,KAAK,IAAI,IAAI,GAAG,IAAI,UAAU,KAAK;EACjC,MAAM,SAAS,QAAQ,MAAM;EAC7B,QAAQ,KAAK,MAAM,QAAQ,EAAE;CAC/B;CACA,OAAO;AACT;AAEA,SAAS,eAAuB;CAC9B,MAAM,QAAQ,OAAO,gBAAgB,IA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,EAAE,KAAK,EAAE;CACpF;CAEA,OAAO;EACL;EACA,QAAQ,QAAQ,OAAO;GACrB,YAAY,MAAM;GAClB,OAAO,GAAG,OAAO,GAAG,SAAS,MAAM,MAAM,CAAC;EAC5C;EACA,YAAY,WACV,IAAI,OAAO,IAAI,YAAY,MAAM,EAAE,GAAG,KAAK,UAAU,GAAG,WAAW,KAAK,UAAU,GAAG;EACvF,OAAO,IAAI;GACT,MAAM,QAAQ,GAAG,QAAQ,GAAG,IAAI;GAChC,MAAM,MAAM,GAAG,MAAM,OAAO,QAAQ,QAAQ;GAC5C,IAAI,IAAI,WAAW,UAAU,OAAO;GACpC,IAAI,KAAK;GACT,KAAK,MAAM,MAAM,KAAK;IACpB,MAAM,QAAQ,KAAK,SAAS,QAAQ,EAAE;IACtC,IAAI,UAAU,IAAI,OAAO;IACzB,KAAK,KAAK,KAAK;GACjB;GACA,OAAO;EACT;CACF;AACF;AAEA,MAAM,eAAe,UAA0B,MAAM,QAAQ,uBAAuB,MAAM"}
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
const require_contract = require("./contract-wAEMDmYG.cjs");
|
|
2
|
+
const require_scoped = require("./scoped-BRoE1W1x.cjs");
|
|
3
|
+
//#region src/server/http.ts
|
|
4
|
+
/** Content type of every JSON response. */
|
|
5
|
+
const JSON_CONTENT_TYPE = "application/json; charset=utf-8";
|
|
6
|
+
/** A JSON response. */
|
|
7
|
+
const json = (data, status = 200, headers) => new Response(JSON.stringify(data), {
|
|
8
|
+
status,
|
|
9
|
+
headers: {
|
|
10
|
+
"content-type": JSON_CONTENT_TYPE,
|
|
11
|
+
...headers
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
/** A JSON error response: `{ error: message, ...extra }`. */
|
|
15
|
+
const error = (status, message, extra, headers) => json({
|
|
16
|
+
error: message,
|
|
17
|
+
...extra
|
|
18
|
+
}, status, headers);
|
|
19
|
+
/** `405` with the `Allow` header listing the methods the path supports. */
|
|
20
|
+
const methodNotAllowed = (allow) => error(405, "Method Not Allowed", void 0, { allow: [...new Set(allow)].join(", ") });
|
|
21
|
+
/** An empty `204`. */
|
|
22
|
+
const noContent = () => new Response(null, { status: 204 });
|
|
23
|
+
/** Throw inside a router to short-circuit with `error(status, message, extra)`. */
|
|
24
|
+
var HttpError = class extends Error {
|
|
25
|
+
status;
|
|
26
|
+
extra;
|
|
27
|
+
constructor(status, message, extra) {
|
|
28
|
+
super(message);
|
|
29
|
+
this.status = status;
|
|
30
|
+
this.extra = extra;
|
|
31
|
+
this.name = "HttpError";
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Match `pattern` (with `:name` segments) against `path`; returns the decoded
|
|
36
|
+
* params, or `null`. A malformed `%` escape is **no match** (404), never a
|
|
37
|
+
* thrown `URIError` (500).
|
|
38
|
+
*/
|
|
39
|
+
function match(pattern, path) {
|
|
40
|
+
const pp = pattern.split("/").filter(Boolean);
|
|
41
|
+
const ap = path.split("/").filter(Boolean);
|
|
42
|
+
if (pp.length !== ap.length) return null;
|
|
43
|
+
const params = {};
|
|
44
|
+
for (let i = 0; i < pp.length; i++) {
|
|
45
|
+
const seg = pp[i];
|
|
46
|
+
const val = ap[i];
|
|
47
|
+
if (seg.startsWith(":")) try {
|
|
48
|
+
params[seg.slice(1)] = decodeURIComponent(val);
|
|
49
|
+
} catch {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
else if (seg !== val) return null;
|
|
53
|
+
}
|
|
54
|
+
return params;
|
|
55
|
+
}
|
|
56
|
+
/** Parse an integer query param; `undefined` when absent or empty. */
|
|
57
|
+
function intParam(value, options = {}) {
|
|
58
|
+
if (value === null || value === "") return void 0;
|
|
59
|
+
const positive = options.positive ?? true;
|
|
60
|
+
const n = Number(value);
|
|
61
|
+
if (positive ? Number.isFinite(n) && n > 0 : Number.isInteger(n)) return positive ? Math.floor(n) : n;
|
|
62
|
+
if (options.invalid === "ignore") return void 0;
|
|
63
|
+
const what = positive ? "a positive integer" : "an integer";
|
|
64
|
+
throw new HttpError(400, `Invalid query parameter${options.name ? ` ${options.name}` : ""}: expected ${what}, got "${value}"`);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Map an error to a response:
|
|
68
|
+
*
|
|
69
|
+
* 1. {@link HttpError} → its status and extras.
|
|
70
|
+
* 2. An entry of `errors` matching the error's `name`.
|
|
71
|
+
* 3. Built-ins (each overridable by an `errors` entry of the same name):
|
|
72
|
+
* `HookDeniedError` (any bundle) → its status, `code: "HOOK_DENIED"`; a
|
|
73
|
+
* kit `TokenError`, or any error named `*TokenError` (`PortalTokenError`,
|
|
74
|
+
* `ViewerTokenError` from another bundle) → 401 `code: "TOKEN"`; `ValidationError` → 400 `code: "VALIDATION"`
|
|
75
|
+
* with `errors`; `SyntaxError` → 400 "Invalid JSON body".
|
|
76
|
+
* 4. Anything else → 500 with the error message.
|
|
77
|
+
*/
|
|
78
|
+
function mapError(err, errors = {}) {
|
|
79
|
+
if (err instanceof HttpError) return error(err.status, err.message, err.extra);
|
|
80
|
+
if (typeof err === "object" && err !== null && typeof err.name === "string") {
|
|
81
|
+
const e = err;
|
|
82
|
+
const mapping = Object.hasOwn(errors, e.name) ? errors[e.name] : void 0;
|
|
83
|
+
if (typeof mapping === "function") return mapping(e);
|
|
84
|
+
if (mapping) return error(mapping.status, e.message, {
|
|
85
|
+
...mapping.code ? { code: mapping.code } : {},
|
|
86
|
+
...mapping.extra?.(e)
|
|
87
|
+
});
|
|
88
|
+
const denied = require_contract.hookDeniedStatus(e);
|
|
89
|
+
if (denied !== null) return error(denied, e.message, { code: "HOOK_DENIED" });
|
|
90
|
+
if (e instanceof require_scoped.TokenError || e.name.endsWith("TokenError")) return error(401, e.message, { code: "TOKEN" });
|
|
91
|
+
if (e.name === "ValidationError") {
|
|
92
|
+
const list = e.errors;
|
|
93
|
+
return error(400, e.message, {
|
|
94
|
+
code: "VALIDATION",
|
|
95
|
+
errors: Array.isArray(list) ? list : []
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
if (e.name === "SyntaxError") return error(400, "Invalid JSON body", { code: "VALIDATION" });
|
|
99
|
+
return error(500, typeof e.message === "string" && e.message ? e.message : "Internal error");
|
|
100
|
+
}
|
|
101
|
+
return error(500, "Internal error");
|
|
102
|
+
}
|
|
103
|
+
const BEARER = /^bearer\s+/i;
|
|
104
|
+
/**
|
|
105
|
+
* Authenticate a request.
|
|
106
|
+
*
|
|
107
|
+
* - A `Bearer <prefix>…` token **short-circuits** the host's provider: a valid
|
|
108
|
+
* token yields the scoped principal; an invalid or expired one throws
|
|
109
|
+
* (→ 401 through {@link mapError}). It never falls back to the host's auth
|
|
110
|
+
* with an explicitly presented, rejected credential.
|
|
111
|
+
* - Otherwise the host's provider runs. **If it throws, the error propagates**
|
|
112
|
+
* (→ 500): a broken identity provider is a server failure, not bad
|
|
113
|
+
* credentials. `null` means "not authenticated".
|
|
114
|
+
*/
|
|
115
|
+
async function authenticate(request, options) {
|
|
116
|
+
const header = request.headers.get("authorization") ?? "";
|
|
117
|
+
if (options.scoped && BEARER.test(header)) {
|
|
118
|
+
const token = header.replace(BEARER, "").trim();
|
|
119
|
+
if (token.startsWith(options.scoped.prefix)) {
|
|
120
|
+
const grant = await options.scoped.verify(token, request);
|
|
121
|
+
return {
|
|
122
|
+
principal: options.scoped.principal(grant),
|
|
123
|
+
scoped: grant
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return {
|
|
128
|
+
principal: await options.auth.authenticate(request),
|
|
129
|
+
scoped: null
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Authorize an authenticated request. A scoped principal is decided by
|
|
134
|
+
* `scope` alone — the host's provider is **not consulted** (defence in depth:
|
|
135
|
+
* a permissive host policy can't widen a token).
|
|
136
|
+
*/
|
|
137
|
+
async function authorize(who, input, options) {
|
|
138
|
+
if (who.scoped !== null) return options.scope ? await options.scope(who.scoped, input.action, input.resource) : false;
|
|
139
|
+
return await options.authorization.authorize({
|
|
140
|
+
principal: who.principal,
|
|
141
|
+
...input
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Throw a clear error when none of `keys` is set on `options` — the "requires
|
|
146
|
+
* `storage` or a prebuilt `core`" guard every product's panel needs.
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* ```ts
|
|
150
|
+
* requireOneOf("createFetchHandler", options, ["storage", "core"]);
|
|
151
|
+
* // Error: createFetchHandler requires either `storage` or `core`.
|
|
152
|
+
* ```
|
|
153
|
+
*/
|
|
154
|
+
function requireOneOf(caller, options, keys) {
|
|
155
|
+
const set = options;
|
|
156
|
+
if (keys.some((k) => set[k] !== void 0 && set[k] !== null)) return;
|
|
157
|
+
const list = keys.map((k) => `\`${k}\``);
|
|
158
|
+
const what = list.length > 1 ? `either ${list.slice(0, -1).join(", ")} or ${list.at(-1)}` : list[0];
|
|
159
|
+
throw new TypeError(`${caller} requires ${what}.`);
|
|
160
|
+
}
|
|
161
|
+
//#endregion
|
|
162
|
+
Object.defineProperty(exports, "HttpError", {
|
|
163
|
+
enumerable: true,
|
|
164
|
+
get: function() {
|
|
165
|
+
return HttpError;
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
Object.defineProperty(exports, "JSON_CONTENT_TYPE", {
|
|
169
|
+
enumerable: true,
|
|
170
|
+
get: function() {
|
|
171
|
+
return JSON_CONTENT_TYPE;
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
Object.defineProperty(exports, "authenticate", {
|
|
175
|
+
enumerable: true,
|
|
176
|
+
get: function() {
|
|
177
|
+
return authenticate;
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
Object.defineProperty(exports, "authorize", {
|
|
181
|
+
enumerable: true,
|
|
182
|
+
get: function() {
|
|
183
|
+
return authorize;
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
Object.defineProperty(exports, "error", {
|
|
187
|
+
enumerable: true,
|
|
188
|
+
get: function() {
|
|
189
|
+
return error;
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
Object.defineProperty(exports, "intParam", {
|
|
193
|
+
enumerable: true,
|
|
194
|
+
get: function() {
|
|
195
|
+
return intParam;
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
Object.defineProperty(exports, "json", {
|
|
199
|
+
enumerable: true,
|
|
200
|
+
get: function() {
|
|
201
|
+
return json;
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
Object.defineProperty(exports, "mapError", {
|
|
205
|
+
enumerable: true,
|
|
206
|
+
get: function() {
|
|
207
|
+
return mapError;
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
Object.defineProperty(exports, "match", {
|
|
211
|
+
enumerable: true,
|
|
212
|
+
get: function() {
|
|
213
|
+
return match;
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
Object.defineProperty(exports, "methodNotAllowed", {
|
|
217
|
+
enumerable: true,
|
|
218
|
+
get: function() {
|
|
219
|
+
return methodNotAllowed;
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
Object.defineProperty(exports, "noContent", {
|
|
223
|
+
enumerable: true,
|
|
224
|
+
get: function() {
|
|
225
|
+
return noContent;
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
Object.defineProperty(exports, "requireOneOf", {
|
|
229
|
+
enumerable: true,
|
|
230
|
+
get: function() {
|
|
231
|
+
return requireOneOf;
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
//# sourceMappingURL=http-B_rTnLW9.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-B_rTnLW9.cjs","names":["hookDeniedStatus","TokenError"],"sources":["../src/server/http.ts"],"sourcesContent":["/**\n * HTTP plumbing shared by the products' API routers: JSON responses, a safe\n * `:param` matcher, integer query params, domain-error mapping by name, the\n * authentication step (with the scoped-token short-circuit) and the\n * authorization step that keeps scoped principals away from the host's\n * provider.\n *\n * @module\n */\n\nimport type { AuthProvider, Principal } from \"../auth/contract.ts\";\nimport type { AuthorizationProvider } from \"../authorization/contract.ts\";\nimport { hookDeniedStatus } from \"../hooks/contract.ts\";\nimport { TokenError } from \"../tokens/scoped.ts\";\n\n/** Content type of every JSON response. */\nexport const JSON_CONTENT_TYPE = \"application/json; charset=utf-8\";\n\n/** A JSON response. */\nexport const json = (data: unknown, status = 200, headers?: Record<string, string>): Response =>\n new Response(JSON.stringify(data), {\n status,\n headers: { \"content-type\": JSON_CONTENT_TYPE, ...headers },\n });\n\n/** A JSON error response: `{ error: message, ...extra }`. */\nexport const error = (\n status: number,\n message: string,\n extra?: Record<string, unknown>,\n headers?: Record<string, string>,\n): Response => json({ error: message, ...extra }, status, headers);\n\n/** `405` with the `Allow` header listing the methods the path supports. */\nexport const methodNotAllowed = (allow: Iterable<string>): Response =>\n error(405, \"Method Not Allowed\", undefined, { allow: [...new Set(allow)].join(\", \") });\n\n/** An empty `204`. */\nexport const noContent = (): Response => new Response(null, { status: 204 });\n\n/** Throw inside a router to short-circuit with `error(status, message, extra)`. */\nexport class HttpError extends Error {\n constructor(\n readonly status: number,\n message: string,\n readonly extra?: Record<string, unknown>,\n ) {\n super(message);\n this.name = \"HttpError\";\n }\n}\n\n/**\n * Match `pattern` (with `:name` segments) against `path`; returns the decoded\n * params, or `null`. A malformed `%` escape is **no match** (404), never a\n * thrown `URIError` (500).\n */\nexport function match(pattern: string, path: string): Record<string, string> | null {\n const pp = pattern.split(\"/\").filter(Boolean);\n const ap = path.split(\"/\").filter(Boolean);\n if (pp.length !== ap.length) return null;\n const params: Record<string, string> = {};\n for (let i = 0; i < pp.length; i++) {\n const seg = pp[i] as string;\n const val = ap[i] as string;\n if (seg.startsWith(\":\")) {\n try {\n params[seg.slice(1)] = decodeURIComponent(val);\n } catch {\n return null;\n }\n } else if (seg !== val) return null;\n }\n return params;\n}\n\n/** Options for {@link intParam}. */\nexport interface IntParamOptions {\n /**\n * What an unparseable value does: `\"throw\"` an {@link HttpError} 400\n * (audit, entitlements) or `\"ignore\"` it as if absent (webhooks, flags,\n * links). Part of a product's HTTP contract (ADR 0010). Default `\"throw\"`.\n */\n invalid?: \"throw\" | \"ignore\";\n /** Require a value > 0 (fractions are floored). With `false`, any integer. Default `true`. */\n positive?: boolean;\n /** The parameter name, for the error message. */\n name?: string;\n}\n\n/** Parse an integer query param; `undefined` when absent or empty. */\nexport function intParam(value: string | null, options: IntParamOptions = {}): number | undefined {\n if (value === null || value === \"\") return undefined;\n const positive = options.positive ?? true;\n const n = Number(value);\n const ok = positive ? Number.isFinite(n) && n > 0 : Number.isInteger(n);\n if (ok) return positive ? Math.floor(n) : n;\n if (options.invalid === \"ignore\") return undefined;\n const what = positive ? \"a positive integer\" : \"an integer\";\n throw new HttpError(\n 400,\n `Invalid query parameter${options.name ? ` ${options.name}` : \"\"}: expected ${what}, got \"${value}\"`,\n );\n}\n\n/** How one named domain error maps to a response. */\nexport type ErrorMapping =\n | { status: number; code?: string; extra?: (error: Error) => Record<string, unknown> }\n | ((error: Error) => Response);\n\n/**\n * Domain errors by `name` → response. Names, not classes, so an error thrown\n * from another bundle's copy of the class still maps (see `isNamed`).\n */\nexport type ErrorMap = Record<string, ErrorMapping>;\n\n/**\n * Map an error to a response:\n *\n * 1. {@link HttpError} → its status and extras.\n * 2. An entry of `errors` matching the error's `name`.\n * 3. Built-ins (each overridable by an `errors` entry of the same name):\n * `HookDeniedError` (any bundle) → its status, `code: \"HOOK_DENIED\"`; a\n * kit `TokenError`, or any error named `*TokenError` (`PortalTokenError`,\n * `ViewerTokenError` from another bundle) → 401 `code: \"TOKEN\"`; `ValidationError` → 400 `code: \"VALIDATION\"`\n * with `errors`; `SyntaxError` → 400 \"Invalid JSON body\".\n * 4. Anything else → 500 with the error message.\n */\nexport function mapError(err: unknown, errors: ErrorMap = {}): Response {\n if (err instanceof HttpError) return error(err.status, err.message, err.extra);\n if (typeof err === \"object\" && err !== null && typeof (err as Error).name === \"string\") {\n const e = err as Error;\n const mapping = Object.hasOwn(errors, e.name) ? errors[e.name] : undefined;\n if (typeof mapping === \"function\") return mapping(e);\n if (mapping) {\n return error(mapping.status, e.message, {\n ...(mapping.code ? { code: mapping.code } : {}),\n ...mapping.extra?.(e),\n });\n }\n const denied = hookDeniedStatus(e);\n if (denied !== null) return error(denied, e.message, { code: \"HOOK_DENIED\" });\n if (e instanceof TokenError || e.name.endsWith(\"TokenError\"))\n return error(401, e.message, { code: \"TOKEN\" });\n if (e.name === \"ValidationError\") {\n const list = (e as { errors?: unknown }).errors;\n return error(400, e.message, { code: \"VALIDATION\", errors: Array.isArray(list) ? list : [] });\n }\n if (e.name === \"SyntaxError\") return error(400, \"Invalid JSON body\", { code: \"VALIDATION\" });\n return error(500, typeof e.message === \"string\" && e.message ? e.message : \"Internal error\");\n }\n return error(500, \"Internal error\");\n}\n\n/** How a product verifies its scoped (portal / viewer) tokens. */\nexport interface ScopedAuth<Grant> {\n /** The token prefix (`\"whpt_\"`…). A `Bearer <prefix>…` header takes the scoped lane. */\n prefix: string;\n /** Verify the token; throw (e.g. a `TokenError`) when it is invalid or expired. */\n verify(token: string, request: Request): Promise<Grant>;\n /** The principal a verified grant acts as (e.g. `{ id: \"portal:acme\" }`). */\n principal(grant: Grant): Principal;\n}\n\n/** The outcome of {@link authenticate}. */\nexport interface Authenticated<Grant> {\n principal: Principal | null;\n /** The verified scoped-token grant, or `null` for host-authenticated (or anonymous) requests. */\n scoped: Grant | null;\n}\n\n/** Options for {@link authenticate}. */\nexport interface AuthenticateOptions<Grant> {\n /** The host's provider. */\n auth: AuthProvider;\n /** The product's scoped tokens, when configured. */\n scoped?: ScopedAuth<Grant>;\n}\n\nconst BEARER = /^bearer\\s+/i;\n\n/**\n * Authenticate a request.\n *\n * - A `Bearer <prefix>…` token **short-circuits** the host's provider: a valid\n * token yields the scoped principal; an invalid or expired one throws\n * (→ 401 through {@link mapError}). It never falls back to the host's auth\n * with an explicitly presented, rejected credential.\n * - Otherwise the host's provider runs. **If it throws, the error propagates**\n * (→ 500): a broken identity provider is a server failure, not bad\n * credentials. `null` means \"not authenticated\".\n */\nexport async function authenticate<Grant>(\n request: Request,\n options: AuthenticateOptions<Grant>,\n): Promise<Authenticated<Grant>> {\n const header = request.headers.get(\"authorization\") ?? \"\";\n if (options.scoped && BEARER.test(header)) {\n const token = header.replace(BEARER, \"\").trim();\n if (token.startsWith(options.scoped.prefix)) {\n const grant = await options.scoped.verify(token, request);\n return { principal: options.scoped.principal(grant), scoped: grant };\n }\n }\n return { principal: await options.auth.authenticate(request), scoped: null };\n}\n\n/** Options for {@link authorize}. */\nexport interface AuthorizeOptions<Action extends string, Resource, Grant> {\n /** The host's provider, consulted for host-authenticated principals only. */\n authorization: AuthorizationProvider<Action, Resource>;\n /**\n * Decide what a scoped grant may do. Without it, scoped principals are denied\n * everything.\n */\n scope?: (grant: Grant, action: Action, resource: Resource) => boolean | Promise<boolean>;\n}\n\n/**\n * Authorize an authenticated request. A scoped principal is decided by\n * `scope` alone — the host's provider is **not consulted** (defence in depth:\n * a permissive host policy can't widen a token).\n */\nexport async function authorize<Action extends string, Resource, Grant>(\n who: Authenticated<Grant>,\n input: { action: Action; resource: Resource; request: Request },\n options: AuthorizeOptions<Action, Resource, Grant>,\n): Promise<boolean> {\n if (who.scoped !== null) {\n return options.scope ? await options.scope(who.scoped, input.action, input.resource) : false;\n }\n return await options.authorization.authorize({ principal: who.principal, ...input });\n}\n\n/**\n * Throw a clear error when none of `keys` is set on `options` — the \"requires\n * `storage` or a prebuilt `core`\" guard every product's panel needs.\n *\n * @example\n * ```ts\n * requireOneOf(\"createFetchHandler\", options, [\"storage\", \"core\"]);\n * // Error: createFetchHandler requires either `storage` or `core`.\n * ```\n */\nexport function requireOneOf(caller: string, options: object, keys: readonly string[]): void {\n const set = options as Record<string, unknown>;\n if (keys.some((k) => set[k] !== undefined && set[k] !== null)) return;\n const list = keys.map((k) => `\\`${k}\\``);\n const what =\n list.length > 1 ? `either ${list.slice(0, -1).join(\", \")} or ${list.at(-1)}` : list[0];\n throw new TypeError(`${caller} requires ${what}.`);\n}\n"],"mappings":";;;;AAgBA,MAAa,oBAAoB;;AAGjC,MAAa,QAAQ,MAAe,SAAS,KAAK,YAChD,IAAI,SAAS,KAAK,UAAU,IAAI,GAAG;CACjC;CACA,SAAS;EAAE,gBAAgB;EAAmB,GAAG;CAAQ;AAC3D,CAAC;;AAGH,MAAa,SACX,QACA,SACA,OACA,YACa,KAAK;CAAE,OAAO;CAAS,GAAG;AAAM,GAAG,QAAQ,OAAO;;AAGjE,MAAa,oBAAoB,UAC/B,MAAM,KAAK,sBAAsB,KAAA,GAAW,EAAE,OAAO,CAAC,GAAG,IAAI,IAAI,KAAK,CAAC,EAAE,KAAK,IAAI,EAAE,CAAC;;AAGvF,MAAa,kBAA4B,IAAI,SAAS,MAAM,EAAE,QAAQ,IAAI,CAAC;;AAG3E,IAAa,YAAb,cAA+B,MAAM;CAExB;CAEA;CAHX,YACE,QACA,SACA,OACA;EACA,MAAM,OAAO;EAJJ,KAAA,SAAA;EAEA,KAAA,QAAA;EAGT,KAAK,OAAO;CACd;AACF;;;;;;AAOA,SAAgB,MAAM,SAAiB,MAA6C;CAClF,MAAM,KAAK,QAAQ,MAAM,GAAG,EAAE,OAAO,OAAO;CAC5C,MAAM,KAAK,KAAK,MAAM,GAAG,EAAE,OAAO,OAAO;CACzC,IAAI,GAAG,WAAW,GAAG,QAAQ,OAAO;CACpC,MAAM,SAAiC,CAAC;CACxC,KAAK,IAAI,IAAI,GAAG,IAAI,GAAG,QAAQ,KAAK;EAClC,MAAM,MAAM,GAAG;EACf,MAAM,MAAM,GAAG;EACf,IAAI,IAAI,WAAW,GAAG,GACpB,IAAI;GACF,OAAO,IAAI,MAAM,CAAC,KAAK,mBAAmB,GAAG;EAC/C,QAAQ;GACN,OAAO;EACT;OACK,IAAI,QAAQ,KAAK,OAAO;CACjC;CACA,OAAO;AACT;;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AAI,OAAO,IAAI,GAAG;CAC/D,MAAM,OAAO,KAAK,KAAK,MAAM,KAAK,EAAE,GAAG;CACvC,MAAM,OACJ,KAAK,SAAS,IAAI,UAAU,KAAK,MAAM,GAAG,EAAE,EAAE,KAAK,IAAI,EAAE,MAAM,KAAK,GAAG,EAAE,MAAM,KAAK;CACtF,MAAM,IAAI,UAAU,GAAG,OAAO,YAAY,KAAK,EAAE;AACnD"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { n as Principal, t as AuthProvider } from "./contract-B3UPXXLx.mjs";
|
|
2
|
+
import { r as AuthorizationProvider } from "./contract-BDPNvjtp.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/server/http.d.ts
|
|
5
|
+
/** Content type of every JSON response. */
|
|
6
|
+
declare const JSON_CONTENT_TYPE = "application/json; charset=utf-8";
|
|
7
|
+
/** A JSON response. */
|
|
8
|
+
declare const json: (data: unknown, status?: number, headers?: Record<string, string>) => Response;
|
|
9
|
+
/** A JSON error response: `{ error: message, ...extra }`. */
|
|
10
|
+
declare const error: (status: number, message: string, extra?: Record<string, unknown>, headers?: Record<string, string>) => Response;
|
|
11
|
+
/** `405` with the `Allow` header listing the methods the path supports. */
|
|
12
|
+
declare const methodNotAllowed: (allow: Iterable<string>) => Response;
|
|
13
|
+
/** An empty `204`. */
|
|
14
|
+
declare const noContent: () => Response;
|
|
15
|
+
/** Throw inside a router to short-circuit with `error(status, message, extra)`. */
|
|
16
|
+
declare class HttpError extends Error {
|
|
17
|
+
readonly status: number;
|
|
18
|
+
readonly extra?: Record<string, unknown> | undefined;
|
|
19
|
+
constructor(status: number, message: string, extra?: Record<string, unknown> | undefined);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Match `pattern` (with `:name` segments) against `path`; returns the decoded
|
|
23
|
+
* params, or `null`. A malformed `%` escape is **no match** (404), never a
|
|
24
|
+
* thrown `URIError` (500).
|
|
25
|
+
*/
|
|
26
|
+
declare function match(pattern: string, path: string): Record<string, string> | null;
|
|
27
|
+
/** Options for {@link intParam}. */
|
|
28
|
+
interface IntParamOptions {
|
|
29
|
+
/**
|
|
30
|
+
* What an unparseable value does: `"throw"` an {@link HttpError} 400
|
|
31
|
+
* (audit, entitlements) or `"ignore"` it as if absent (webhooks, flags,
|
|
32
|
+
* links). Part of a product's HTTP contract (ADR 0010). Default `"throw"`.
|
|
33
|
+
*/
|
|
34
|
+
invalid?: "throw" | "ignore";
|
|
35
|
+
/** Require a value > 0 (fractions are floored). With `false`, any integer. Default `true`. */
|
|
36
|
+
positive?: boolean;
|
|
37
|
+
/** The parameter name, for the error message. */
|
|
38
|
+
name?: string;
|
|
39
|
+
}
|
|
40
|
+
/** Parse an integer query param; `undefined` when absent or empty. */
|
|
41
|
+
declare function intParam(value: string | null, options?: IntParamOptions): number | undefined;
|
|
42
|
+
/** How one named domain error maps to a response. */
|
|
43
|
+
type ErrorMapping = {
|
|
44
|
+
status: number;
|
|
45
|
+
code?: string;
|
|
46
|
+
extra?: (error: Error) => Record<string, unknown>;
|
|
47
|
+
} | ((error: Error) => Response);
|
|
48
|
+
/**
|
|
49
|
+
* Domain errors by `name` → response. Names, not classes, so an error thrown
|
|
50
|
+
* from another bundle's copy of the class still maps (see `isNamed`).
|
|
51
|
+
*/
|
|
52
|
+
type ErrorMap = Record<string, ErrorMapping>;
|
|
53
|
+
/**
|
|
54
|
+
* Map an error to a response:
|
|
55
|
+
*
|
|
56
|
+
* 1. {@link HttpError} → its status and extras.
|
|
57
|
+
* 2. An entry of `errors` matching the error's `name`.
|
|
58
|
+
* 3. Built-ins (each overridable by an `errors` entry of the same name):
|
|
59
|
+
* `HookDeniedError` (any bundle) → its status, `code: "HOOK_DENIED"`; a
|
|
60
|
+
* kit `TokenError`, or any error named `*TokenError` (`PortalTokenError`,
|
|
61
|
+
* `ViewerTokenError` from another bundle) → 401 `code: "TOKEN"`; `ValidationError` → 400 `code: "VALIDATION"`
|
|
62
|
+
* with `errors`; `SyntaxError` → 400 "Invalid JSON body".
|
|
63
|
+
* 4. Anything else → 500 with the error message.
|
|
64
|
+
*/
|
|
65
|
+
declare function mapError(err: unknown, errors?: ErrorMap): Response;
|
|
66
|
+
/** How a product verifies its scoped (portal / viewer) tokens. */
|
|
67
|
+
interface ScopedAuth<Grant> {
|
|
68
|
+
/** The token prefix (`"whpt_"`…). A `Bearer <prefix>…` header takes the scoped lane. */
|
|
69
|
+
prefix: string;
|
|
70
|
+
/** Verify the token; throw (e.g. a `TokenError`) when it is invalid or expired. */
|
|
71
|
+
verify(token: string, request: Request): Promise<Grant>;
|
|
72
|
+
/** The principal a verified grant acts as (e.g. `{ id: "portal:acme" }`). */
|
|
73
|
+
principal(grant: Grant): Principal;
|
|
74
|
+
}
|
|
75
|
+
/** The outcome of {@link authenticate}. */
|
|
76
|
+
interface Authenticated<Grant> {
|
|
77
|
+
principal: Principal | null;
|
|
78
|
+
/** The verified scoped-token grant, or `null` for host-authenticated (or anonymous) requests. */
|
|
79
|
+
scoped: Grant | null;
|
|
80
|
+
}
|
|
81
|
+
/** Options for {@link authenticate}. */
|
|
82
|
+
interface AuthenticateOptions<Grant> {
|
|
83
|
+
/** The host's provider. */
|
|
84
|
+
auth: AuthProvider;
|
|
85
|
+
/** The product's scoped tokens, when configured. */
|
|
86
|
+
scoped?: ScopedAuth<Grant>;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Authenticate a request.
|
|
90
|
+
*
|
|
91
|
+
* - A `Bearer <prefix>…` token **short-circuits** the host's provider: a valid
|
|
92
|
+
* token yields the scoped principal; an invalid or expired one throws
|
|
93
|
+
* (→ 401 through {@link mapError}). It never falls back to the host's auth
|
|
94
|
+
* with an explicitly presented, rejected credential.
|
|
95
|
+
* - Otherwise the host's provider runs. **If it throws, the error propagates**
|
|
96
|
+
* (→ 500): a broken identity provider is a server failure, not bad
|
|
97
|
+
* credentials. `null` means "not authenticated".
|
|
98
|
+
*/
|
|
99
|
+
declare function authenticate<Grant>(request: Request, options: AuthenticateOptions<Grant>): Promise<Authenticated<Grant>>;
|
|
100
|
+
/** Options for {@link authorize}. */
|
|
101
|
+
interface AuthorizeOptions<Action extends string, Resource, Grant> {
|
|
102
|
+
/** The host's provider, consulted for host-authenticated principals only. */
|
|
103
|
+
authorization: AuthorizationProvider<Action, Resource>;
|
|
104
|
+
/**
|
|
105
|
+
* Decide what a scoped grant may do. Without it, scoped principals are denied
|
|
106
|
+
* everything.
|
|
107
|
+
*/
|
|
108
|
+
scope?: (grant: Grant, action: Action, resource: Resource) => boolean | Promise<boolean>;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Authorize an authenticated request. A scoped principal is decided by
|
|
112
|
+
* `scope` alone — the host's provider is **not consulted** (defence in depth:
|
|
113
|
+
* a permissive host policy can't widen a token).
|
|
114
|
+
*/
|
|
115
|
+
declare function authorize<Action extends string, Resource, Grant>(who: Authenticated<Grant>, input: {
|
|
116
|
+
action: Action;
|
|
117
|
+
resource: Resource;
|
|
118
|
+
request: Request;
|
|
119
|
+
}, options: AuthorizeOptions<Action, Resource, Grant>): Promise<boolean>;
|
|
120
|
+
/**
|
|
121
|
+
* Throw a clear error when none of `keys` is set on `options` — the "requires
|
|
122
|
+
* `storage` or a prebuilt `core`" guard every product's panel needs.
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```ts
|
|
126
|
+
* requireOneOf("createFetchHandler", options, ["storage", "core"]);
|
|
127
|
+
* // Error: createFetchHandler requires either `storage` or `core`.
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
declare function requireOneOf(caller: string, options: object, keys: readonly string[]): void;
|
|
131
|
+
//#endregion
|
|
132
|
+
export { methodNotAllowed as _, ErrorMapping as a, JSON_CONTENT_TYPE as c, authorize as d, error as f, match as g, mapError as h, ErrorMap as i, ScopedAuth as l, json as m, Authenticated as n, HttpError as o, intParam as p, AuthorizeOptions as r, IntParamOptions as s, AuthenticateOptions as t, authenticate as u, noContent as v, requireOneOf as y };
|
|
133
|
+
//# sourceMappingURL=http-CxYM7kPT.d.mts.map
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { i as hookDeniedStatus } from "./contract-BEdfGTPs.mjs";
|
|
2
|
+
import { t as TokenError } from "./scoped-cFBbotCh.mjs";
|
|
3
|
+
//#region src/server/http.ts
|
|
4
|
+
/** Content type of every JSON response. */
|
|
5
|
+
const JSON_CONTENT_TYPE = "application/json; charset=utf-8";
|
|
6
|
+
/** A JSON response. */
|
|
7
|
+
const json = (data, status = 200, headers) => new Response(JSON.stringify(data), {
|
|
8
|
+
status,
|
|
9
|
+
headers: {
|
|
10
|
+
"content-type": JSON_CONTENT_TYPE,
|
|
11
|
+
...headers
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
/** A JSON error response: `{ error: message, ...extra }`. */
|
|
15
|
+
const error = (status, message, extra, headers) => json({
|
|
16
|
+
error: message,
|
|
17
|
+
...extra
|
|
18
|
+
}, status, headers);
|
|
19
|
+
/** `405` with the `Allow` header listing the methods the path supports. */
|
|
20
|
+
const methodNotAllowed = (allow) => error(405, "Method Not Allowed", void 0, { allow: [...new Set(allow)].join(", ") });
|
|
21
|
+
/** An empty `204`. */
|
|
22
|
+
const noContent = () => new Response(null, { status: 204 });
|
|
23
|
+
/** Throw inside a router to short-circuit with `error(status, message, extra)`. */
|
|
24
|
+
var HttpError = class extends Error {
|
|
25
|
+
status;
|
|
26
|
+
extra;
|
|
27
|
+
constructor(status, message, extra) {
|
|
28
|
+
super(message);
|
|
29
|
+
this.status = status;
|
|
30
|
+
this.extra = extra;
|
|
31
|
+
this.name = "HttpError";
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Match `pattern` (with `:name` segments) against `path`; returns the decoded
|
|
36
|
+
* params, or `null`. A malformed `%` escape is **no match** (404), never a
|
|
37
|
+
* thrown `URIError` (500).
|
|
38
|
+
*/
|
|
39
|
+
function match(pattern, path) {
|
|
40
|
+
const pp = pattern.split("/").filter(Boolean);
|
|
41
|
+
const ap = path.split("/").filter(Boolean);
|
|
42
|
+
if (pp.length !== ap.length) return null;
|
|
43
|
+
const params = {};
|
|
44
|
+
for (let i = 0; i < pp.length; i++) {
|
|
45
|
+
const seg = pp[i];
|
|
46
|
+
const val = ap[i];
|
|
47
|
+
if (seg.startsWith(":")) try {
|
|
48
|
+
params[seg.slice(1)] = decodeURIComponent(val);
|
|
49
|
+
} catch {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
else if (seg !== val) return null;
|
|
53
|
+
}
|
|
54
|
+
return params;
|
|
55
|
+
}
|
|
56
|
+
/** Parse an integer query param; `undefined` when absent or empty. */
|
|
57
|
+
function intParam(value, options = {}) {
|
|
58
|
+
if (value === null || value === "") return void 0;
|
|
59
|
+
const positive = options.positive ?? true;
|
|
60
|
+
const n = Number(value);
|
|
61
|
+
if (positive ? Number.isFinite(n) && n > 0 : Number.isInteger(n)) return positive ? Math.floor(n) : n;
|
|
62
|
+
if (options.invalid === "ignore") return void 0;
|
|
63
|
+
const what = positive ? "a positive integer" : "an integer";
|
|
64
|
+
throw new HttpError(400, `Invalid query parameter${options.name ? ` ${options.name}` : ""}: expected ${what}, got "${value}"`);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Map an error to a response:
|
|
68
|
+
*
|
|
69
|
+
* 1. {@link HttpError} → its status and extras.
|
|
70
|
+
* 2. An entry of `errors` matching the error's `name`.
|
|
71
|
+
* 3. Built-ins (each overridable by an `errors` entry of the same name):
|
|
72
|
+
* `HookDeniedError` (any bundle) → its status, `code: "HOOK_DENIED"`; a
|
|
73
|
+
* kit `TokenError`, or any error named `*TokenError` (`PortalTokenError`,
|
|
74
|
+
* `ViewerTokenError` from another bundle) → 401 `code: "TOKEN"`; `ValidationError` → 400 `code: "VALIDATION"`
|
|
75
|
+
* with `errors`; `SyntaxError` → 400 "Invalid JSON body".
|
|
76
|
+
* 4. Anything else → 500 with the error message.
|
|
77
|
+
*/
|
|
78
|
+
function mapError(err, errors = {}) {
|
|
79
|
+
if (err instanceof HttpError) return error(err.status, err.message, err.extra);
|
|
80
|
+
if (typeof err === "object" && err !== null && typeof err.name === "string") {
|
|
81
|
+
const e = err;
|
|
82
|
+
const mapping = Object.hasOwn(errors, e.name) ? errors[e.name] : void 0;
|
|
83
|
+
if (typeof mapping === "function") return mapping(e);
|
|
84
|
+
if (mapping) return error(mapping.status, e.message, {
|
|
85
|
+
...mapping.code ? { code: mapping.code } : {},
|
|
86
|
+
...mapping.extra?.(e)
|
|
87
|
+
});
|
|
88
|
+
const denied = hookDeniedStatus(e);
|
|
89
|
+
if (denied !== null) return error(denied, e.message, { code: "HOOK_DENIED" });
|
|
90
|
+
if (e instanceof TokenError || e.name.endsWith("TokenError")) return error(401, e.message, { code: "TOKEN" });
|
|
91
|
+
if (e.name === "ValidationError") {
|
|
92
|
+
const list = e.errors;
|
|
93
|
+
return error(400, e.message, {
|
|
94
|
+
code: "VALIDATION",
|
|
95
|
+
errors: Array.isArray(list) ? list : []
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
if (e.name === "SyntaxError") return error(400, "Invalid JSON body", { code: "VALIDATION" });
|
|
99
|
+
return error(500, typeof e.message === "string" && e.message ? e.message : "Internal error");
|
|
100
|
+
}
|
|
101
|
+
return error(500, "Internal error");
|
|
102
|
+
}
|
|
103
|
+
const BEARER = /^bearer\s+/i;
|
|
104
|
+
/**
|
|
105
|
+
* Authenticate a request.
|
|
106
|
+
*
|
|
107
|
+
* - A `Bearer <prefix>…` token **short-circuits** the host's provider: a valid
|
|
108
|
+
* token yields the scoped principal; an invalid or expired one throws
|
|
109
|
+
* (→ 401 through {@link mapError}). It never falls back to the host's auth
|
|
110
|
+
* with an explicitly presented, rejected credential.
|
|
111
|
+
* - Otherwise the host's provider runs. **If it throws, the error propagates**
|
|
112
|
+
* (→ 500): a broken identity provider is a server failure, not bad
|
|
113
|
+
* credentials. `null` means "not authenticated".
|
|
114
|
+
*/
|
|
115
|
+
async function authenticate(request, options) {
|
|
116
|
+
const header = request.headers.get("authorization") ?? "";
|
|
117
|
+
if (options.scoped && BEARER.test(header)) {
|
|
118
|
+
const token = header.replace(BEARER, "").trim();
|
|
119
|
+
if (token.startsWith(options.scoped.prefix)) {
|
|
120
|
+
const grant = await options.scoped.verify(token, request);
|
|
121
|
+
return {
|
|
122
|
+
principal: options.scoped.principal(grant),
|
|
123
|
+
scoped: grant
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return {
|
|
128
|
+
principal: await options.auth.authenticate(request),
|
|
129
|
+
scoped: null
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Authorize an authenticated request. A scoped principal is decided by
|
|
134
|
+
* `scope` alone — the host's provider is **not consulted** (defence in depth:
|
|
135
|
+
* a permissive host policy can't widen a token).
|
|
136
|
+
*/
|
|
137
|
+
async function authorize(who, input, options) {
|
|
138
|
+
if (who.scoped !== null) return options.scope ? await options.scope(who.scoped, input.action, input.resource) : false;
|
|
139
|
+
return await options.authorization.authorize({
|
|
140
|
+
principal: who.principal,
|
|
141
|
+
...input
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Throw a clear error when none of `keys` is set on `options` — the "requires
|
|
146
|
+
* `storage` or a prebuilt `core`" guard every product's panel needs.
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* ```ts
|
|
150
|
+
* requireOneOf("createFetchHandler", options, ["storage", "core"]);
|
|
151
|
+
* // Error: createFetchHandler requires either `storage` or `core`.
|
|
152
|
+
* ```
|
|
153
|
+
*/
|
|
154
|
+
function requireOneOf(caller, options, keys) {
|
|
155
|
+
const set = options;
|
|
156
|
+
if (keys.some((k) => set[k] !== void 0 && set[k] !== null)) return;
|
|
157
|
+
const list = keys.map((k) => `\`${k}\``);
|
|
158
|
+
const what = list.length > 1 ? `either ${list.slice(0, -1).join(", ")} or ${list.at(-1)}` : list[0];
|
|
159
|
+
throw new TypeError(`${caller} requires ${what}.`);
|
|
160
|
+
}
|
|
161
|
+
//#endregion
|
|
162
|
+
export { error as a, mapError as c, noContent as d, requireOneOf as f, authorize as i, match as l, JSON_CONTENT_TYPE as n, intParam as o, authenticate as r, json as s, HttpError as t, methodNotAllowed as u };
|
|
163
|
+
|
|
164
|
+
//# sourceMappingURL=http-DVdVI6kJ.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-DVdVI6kJ.mjs","names":[],"sources":["../src/server/http.ts"],"sourcesContent":["/**\n * HTTP plumbing shared by the products' API routers: JSON responses, a safe\n * `:param` matcher, integer query params, domain-error mapping by name, the\n * authentication step (with the scoped-token short-circuit) and the\n * authorization step that keeps scoped principals away from the host's\n * provider.\n *\n * @module\n */\n\nimport type { AuthProvider, Principal } from \"../auth/contract.ts\";\nimport type { AuthorizationProvider } from \"../authorization/contract.ts\";\nimport { hookDeniedStatus } from \"../hooks/contract.ts\";\nimport { TokenError } from \"../tokens/scoped.ts\";\n\n/** Content type of every JSON response. */\nexport const JSON_CONTENT_TYPE = \"application/json; charset=utf-8\";\n\n/** A JSON response. */\nexport const json = (data: unknown, status = 200, headers?: Record<string, string>): Response =>\n new Response(JSON.stringify(data), {\n status,\n headers: { \"content-type\": JSON_CONTENT_TYPE, ...headers },\n });\n\n/** A JSON error response: `{ error: message, ...extra }`. */\nexport const error = (\n status: number,\n message: string,\n extra?: Record<string, unknown>,\n headers?: Record<string, string>,\n): Response => json({ error: message, ...extra }, status, headers);\n\n/** `405` with the `Allow` header listing the methods the path supports. */\nexport const methodNotAllowed = (allow: Iterable<string>): Response =>\n error(405, \"Method Not Allowed\", undefined, { allow: [...new Set(allow)].join(\", \") });\n\n/** An empty `204`. */\nexport const noContent = (): Response => new Response(null, { status: 204 });\n\n/** Throw inside a router to short-circuit with `error(status, message, extra)`. */\nexport class HttpError extends Error {\n constructor(\n readonly status: number,\n message: string,\n readonly extra?: Record<string, unknown>,\n ) {\n super(message);\n this.name = \"HttpError\";\n }\n}\n\n/**\n * Match `pattern` (with `:name` segments) against `path`; returns the decoded\n * params, or `null`. A malformed `%` escape is **no match** (404), never a\n * thrown `URIError` (500).\n */\nexport function match(pattern: string, path: string): Record<string, string> | null {\n const pp = pattern.split(\"/\").filter(Boolean);\n const ap = path.split(\"/\").filter(Boolean);\n if (pp.length !== ap.length) return null;\n const params: Record<string, string> = {};\n for (let i = 0; i < pp.length; i++) {\n const seg = pp[i] as string;\n const val = ap[i] as string;\n if (seg.startsWith(\":\")) {\n try {\n params[seg.slice(1)] = decodeURIComponent(val);\n } catch {\n return null;\n }\n } else if (seg !== val) return null;\n }\n return params;\n}\n\n/** Options for {@link intParam}. */\nexport interface IntParamOptions {\n /**\n * What an unparseable value does: `\"throw\"` an {@link HttpError} 400\n * (audit, entitlements) or `\"ignore\"` it as if absent (webhooks, flags,\n * links). Part of a product's HTTP contract (ADR 0010). Default `\"throw\"`.\n */\n invalid?: \"throw\" | \"ignore\";\n /** Require a value > 0 (fractions are floored). With `false`, any integer. Default `true`. */\n positive?: boolean;\n /** The parameter name, for the error message. */\n name?: string;\n}\n\n/** Parse an integer query param; `undefined` when absent or empty. */\nexport function intParam(value: string | null, options: IntParamOptions = {}): number | undefined {\n if (value === null || value === \"\") return undefined;\n const positive = options.positive ?? true;\n const n = Number(value);\n const ok = positive ? Number.isFinite(n) && n > 0 : Number.isInteger(n);\n if (ok) return positive ? Math.floor(n) : n;\n if (options.invalid === \"ignore\") return undefined;\n const what = positive ? \"a positive integer\" : \"an integer\";\n throw new HttpError(\n 400,\n `Invalid query parameter${options.name ? ` ${options.name}` : \"\"}: expected ${what}, got \"${value}\"`,\n );\n}\n\n/** How one named domain error maps to a response. */\nexport type ErrorMapping =\n | { status: number; code?: string; extra?: (error: Error) => Record<string, unknown> }\n | ((error: Error) => Response);\n\n/**\n * Domain errors by `name` → response. Names, not classes, so an error thrown\n * from another bundle's copy of the class still maps (see `isNamed`).\n */\nexport type ErrorMap = Record<string, ErrorMapping>;\n\n/**\n * Map an error to a response:\n *\n * 1. {@link HttpError} → its status and extras.\n * 2. An entry of `errors` matching the error's `name`.\n * 3. Built-ins (each overridable by an `errors` entry of the same name):\n * `HookDeniedError` (any bundle) → its status, `code: \"HOOK_DENIED\"`; a\n * kit `TokenError`, or any error named `*TokenError` (`PortalTokenError`,\n * `ViewerTokenError` from another bundle) → 401 `code: \"TOKEN\"`; `ValidationError` → 400 `code: \"VALIDATION\"`\n * with `errors`; `SyntaxError` → 400 \"Invalid JSON body\".\n * 4. Anything else → 500 with the error message.\n */\nexport function mapError(err: unknown, errors: ErrorMap = {}): Response {\n if (err instanceof HttpError) return error(err.status, err.message, err.extra);\n if (typeof err === \"object\" && err !== null && typeof (err as Error).name === \"string\") {\n const e = err as Error;\n const mapping = Object.hasOwn(errors, e.name) ? errors[e.name] : undefined;\n if (typeof mapping === \"function\") return mapping(e);\n if (mapping) {\n return error(mapping.status, e.message, {\n ...(mapping.code ? { code: mapping.code } : {}),\n ...mapping.extra?.(e),\n });\n }\n const denied = hookDeniedStatus(e);\n if (denied !== null) return error(denied, e.message, { code: \"HOOK_DENIED\" });\n if (e instanceof TokenError || e.name.endsWith(\"TokenError\"))\n return error(401, e.message, { code: \"TOKEN\" });\n if (e.name === \"ValidationError\") {\n const list = (e as { errors?: unknown }).errors;\n return error(400, e.message, { code: \"VALIDATION\", errors: Array.isArray(list) ? list : [] });\n }\n if (e.name === \"SyntaxError\") return error(400, \"Invalid JSON body\", { code: \"VALIDATION\" });\n return error(500, typeof e.message === \"string\" && e.message ? e.message : \"Internal error\");\n }\n return error(500, \"Internal error\");\n}\n\n/** How a product verifies its scoped (portal / viewer) tokens. */\nexport interface ScopedAuth<Grant> {\n /** The token prefix (`\"whpt_\"`…). A `Bearer <prefix>…` header takes the scoped lane. */\n prefix: string;\n /** Verify the token; throw (e.g. a `TokenError`) when it is invalid or expired. */\n verify(token: string, request: Request): Promise<Grant>;\n /** The principal a verified grant acts as (e.g. `{ id: \"portal:acme\" }`). */\n principal(grant: Grant): Principal;\n}\n\n/** The outcome of {@link authenticate}. */\nexport interface Authenticated<Grant> {\n principal: Principal | null;\n /** The verified scoped-token grant, or `null` for host-authenticated (or anonymous) requests. */\n scoped: Grant | null;\n}\n\n/** Options for {@link authenticate}. */\nexport interface AuthenticateOptions<Grant> {\n /** The host's provider. */\n auth: AuthProvider;\n /** The product's scoped tokens, when configured. */\n scoped?: ScopedAuth<Grant>;\n}\n\nconst BEARER = /^bearer\\s+/i;\n\n/**\n * Authenticate a request.\n *\n * - A `Bearer <prefix>…` token **short-circuits** the host's provider: a valid\n * token yields the scoped principal; an invalid or expired one throws\n * (→ 401 through {@link mapError}). It never falls back to the host's auth\n * with an explicitly presented, rejected credential.\n * - Otherwise the host's provider runs. **If it throws, the error propagates**\n * (→ 500): a broken identity provider is a server failure, not bad\n * credentials. `null` means \"not authenticated\".\n */\nexport async function authenticate<Grant>(\n request: Request,\n options: AuthenticateOptions<Grant>,\n): Promise<Authenticated<Grant>> {\n const header = request.headers.get(\"authorization\") ?? \"\";\n if (options.scoped && BEARER.test(header)) {\n const token = header.replace(BEARER, \"\").trim();\n if (token.startsWith(options.scoped.prefix)) {\n const grant = await options.scoped.verify(token, request);\n return { principal: options.scoped.principal(grant), scoped: grant };\n }\n }\n return { principal: await options.auth.authenticate(request), scoped: null };\n}\n\n/** Options for {@link authorize}. */\nexport interface AuthorizeOptions<Action extends string, Resource, Grant> {\n /** The host's provider, consulted for host-authenticated principals only. */\n authorization: AuthorizationProvider<Action, Resource>;\n /**\n * Decide what a scoped grant may do. Without it, scoped principals are denied\n * everything.\n */\n scope?: (grant: Grant, action: Action, resource: Resource) => boolean | Promise<boolean>;\n}\n\n/**\n * Authorize an authenticated request. A scoped principal is decided by\n * `scope` alone — the host's provider is **not consulted** (defence in depth:\n * a permissive host policy can't widen a token).\n */\nexport async function authorize<Action extends string, Resource, Grant>(\n who: Authenticated<Grant>,\n input: { action: Action; resource: Resource; request: Request },\n options: AuthorizeOptions<Action, Resource, Grant>,\n): Promise<boolean> {\n if (who.scoped !== null) {\n return options.scope ? await options.scope(who.scoped, input.action, input.resource) : false;\n }\n return await options.authorization.authorize({ principal: who.principal, ...input });\n}\n\n/**\n * Throw a clear error when none of `keys` is set on `options` — the \"requires\n * `storage` or a prebuilt `core`\" guard every product's panel needs.\n *\n * @example\n * ```ts\n * requireOneOf(\"createFetchHandler\", options, [\"storage\", \"core\"]);\n * // Error: createFetchHandler requires either `storage` or `core`.\n * ```\n */\nexport function requireOneOf(caller: string, options: object, keys: readonly string[]): void {\n const set = options as Record<string, unknown>;\n if (keys.some((k) => set[k] !== undefined && set[k] !== null)) return;\n const list = keys.map((k) => `\\`${k}\\``);\n const what =\n list.length > 1 ? `either ${list.slice(0, -1).join(\", \")} or ${list.at(-1)}` : list[0];\n throw new TypeError(`${caller} requires ${what}.`);\n}\n"],"mappings":";;;;AAgBA,MAAa,oBAAoB;;AAGjC,MAAa,QAAQ,MAAe,SAAS,KAAK,YAChD,IAAI,SAAS,KAAK,UAAU,IAAI,GAAG;CACjC;CACA,SAAS;EAAE,gBAAgB;EAAmB,GAAG;CAAQ;AAC3D,CAAC;;AAGH,MAAa,SACX,QACA,SACA,OACA,YACa,KAAK;CAAE,OAAO;CAAS,GAAG;AAAM,GAAG,QAAQ,OAAO;;AAGjE,MAAa,oBAAoB,UAC/B,MAAM,KAAK,sBAAsB,KAAA,GAAW,EAAE,OAAO,CAAC,GAAG,IAAI,IAAI,KAAK,CAAC,EAAE,KAAK,IAAI,EAAE,CAAC;;AAGvF,MAAa,kBAA4B,IAAI,SAAS,MAAM,EAAE,QAAQ,IAAI,CAAC;;AAG3E,IAAa,YAAb,cAA+B,MAAM;CAExB;CAEA;CAHX,YACE,QACA,SACA,OACA;EACA,MAAM,OAAO;EAJJ,KAAA,SAAA;EAEA,KAAA,QAAA;EAGT,KAAK,OAAO;CACd;AACF;;;;;;AAOA,SAAgB,MAAM,SAAi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