@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,235 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_http = require("./http-B_rTnLW9.cjs");
|
|
3
|
+
const require_validation = require("./validation-DLnzBVJr.cjs");
|
|
4
|
+
//#region src/server/router.ts
|
|
5
|
+
/**
|
|
6
|
+
* Build a router from a route table.
|
|
7
|
+
*
|
|
8
|
+
* Per request: match (collecting the methods a path supports, `HEAD` served
|
|
9
|
+
* by `GET`) → `405` + `Allow` if only the method is wrong → authenticate
|
|
10
|
+
* (routes with an `action`, or `authenticate: true`) → `401` / challenge →
|
|
11
|
+
* resource → authorize (scoped grants via `scoped.allows`, never the host
|
|
12
|
+
* provider) → `403` → readonly (`readonlyStatus`) → handler. Every thrown
|
|
13
|
+
* error goes through `mapError` with `errors`.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* const router = createRouter({
|
|
18
|
+
* routes: ROUTES,
|
|
19
|
+
* context: { core },
|
|
20
|
+
* auth,
|
|
21
|
+
* authorization,
|
|
22
|
+
* isMutatingAction,
|
|
23
|
+
* readonly,
|
|
24
|
+
* readonlyStatus: 423,
|
|
25
|
+
* errors: { NotFoundError: { status: 404, code: "NOT_FOUND" } },
|
|
26
|
+
* });
|
|
27
|
+
* createPanelHandler({ ..., api: router.handle });
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
function createRouter(options) {
|
|
31
|
+
const { routes } = options;
|
|
32
|
+
const scoped = options.scoped;
|
|
33
|
+
const apiPrefix = options.apiPrefix ?? "/api/";
|
|
34
|
+
const readonlyStatus = options.readonlyStatus ?? 403;
|
|
35
|
+
const readonlyMessage = options.readonlyMessage ?? "The panel is readonly";
|
|
36
|
+
const isReadonly = typeof options.readonly === "function" ? options.readonly : () => options.readonly ?? false;
|
|
37
|
+
for (const route of routes) if (route.action !== void 0 && !route.resource) throw new TypeError(`createRouter: route ${route.operationId} has an action but no resource()`);
|
|
38
|
+
async function handle(request, path) {
|
|
39
|
+
const method = request.method.toUpperCase();
|
|
40
|
+
let route;
|
|
41
|
+
let params = {};
|
|
42
|
+
const allowed = /* @__PURE__ */ new Set();
|
|
43
|
+
for (const r of routes) {
|
|
44
|
+
const m = require_http.match(r.path, path);
|
|
45
|
+
if (!m) continue;
|
|
46
|
+
allowed.add(r.method);
|
|
47
|
+
if (r.method === "GET") allowed.add("HEAD");
|
|
48
|
+
if (!route && (r.method === method || method === "HEAD" && r.method === "GET")) {
|
|
49
|
+
route = r;
|
|
50
|
+
params = m;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (!route) {
|
|
54
|
+
if (allowed.size > 0) return require_http.methodNotAllowed(allowed);
|
|
55
|
+
return path.startsWith(apiPrefix) ? require_http.error(404, "Not found") : null;
|
|
56
|
+
}
|
|
57
|
+
try {
|
|
58
|
+
let who = {
|
|
59
|
+
principal: null,
|
|
60
|
+
scoped: null
|
|
61
|
+
};
|
|
62
|
+
if (route.action !== void 0 || route.authenticate) who = await require_http.authenticate(request, {
|
|
63
|
+
auth: options.auth,
|
|
64
|
+
...options.scoped ? { scoped: options.scoped } : {}
|
|
65
|
+
});
|
|
66
|
+
let raw;
|
|
67
|
+
const call = {
|
|
68
|
+
request,
|
|
69
|
+
path,
|
|
70
|
+
params,
|
|
71
|
+
query: new URL(request.url).searchParams,
|
|
72
|
+
ctx: options.context,
|
|
73
|
+
principal: who.principal,
|
|
74
|
+
scoped: who.scoped,
|
|
75
|
+
async body(schema) {
|
|
76
|
+
raw ??= request.text().then((text) => {
|
|
77
|
+
if (text.trim() === "") return {};
|
|
78
|
+
try {
|
|
79
|
+
return JSON.parse(text);
|
|
80
|
+
} catch {
|
|
81
|
+
throw new require_http.HttpError(400, "Invalid JSON body", { code: "VALIDATION" });
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
return require_validation.parseInput(schema, await raw, options.validationError ? { error: options.validationError } : {});
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
if (route.action !== void 0) {
|
|
88
|
+
if (who.principal === null) return options.auth.challenge?.(request) ?? require_http.error(401, "Unauthorized");
|
|
89
|
+
const resource = await route.resource(call);
|
|
90
|
+
if (!await require_http.authorize(who, {
|
|
91
|
+
action: route.action,
|
|
92
|
+
resource,
|
|
93
|
+
request
|
|
94
|
+
}, {
|
|
95
|
+
authorization: options.authorization,
|
|
96
|
+
...options.scoped ? { scope: (g, a, r) => scoped.allows(g, a, r) } : {}
|
|
97
|
+
})) return require_http.error(403, "Forbidden", { action: route.action });
|
|
98
|
+
if (isReadonly() && options.isMutatingAction?.(route.action)) return require_http.error(readonlyStatus, readonlyMessage, { code: "READONLY" });
|
|
99
|
+
}
|
|
100
|
+
return await route.handle(call);
|
|
101
|
+
} catch (err) {
|
|
102
|
+
return require_http.mapError(err, options.errors);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return {
|
|
106
|
+
handle,
|
|
107
|
+
routes
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
//#endregion
|
|
111
|
+
//#region src/server/openapi.ts
|
|
112
|
+
/** `{ $ref: "#/components/schemas/<name>" }`. */
|
|
113
|
+
const ref = (name) => ({ $ref: `#/components/schemas/${name}` });
|
|
114
|
+
/** The `{ error, code? }` body every error response uses. */
|
|
115
|
+
const ERROR_SCHEMA = {
|
|
116
|
+
type: "object",
|
|
117
|
+
properties: {
|
|
118
|
+
error: { type: "string" },
|
|
119
|
+
code: { type: "string" }
|
|
120
|
+
},
|
|
121
|
+
required: ["error"],
|
|
122
|
+
additionalProperties: true
|
|
123
|
+
};
|
|
124
|
+
/** A JSON error response object with `description`. */
|
|
125
|
+
const errorResponse = (description) => ({
|
|
126
|
+
description,
|
|
127
|
+
content: { "application/json": { schema: ref("Error") } }
|
|
128
|
+
});
|
|
129
|
+
/** `/a/:id/b` → `/a/{id}/b`. */
|
|
130
|
+
const toOpenApiPath = (path) => path.replace(/:([A-Za-z_][A-Za-z0-9_]*)/g, "{$1}");
|
|
131
|
+
const PARAM = /:([A-Za-z_][A-Za-z0-9_]*)/g;
|
|
132
|
+
/** The success response object of a route. */
|
|
133
|
+
function responseOf(spec) {
|
|
134
|
+
const { status, schema, description } = spec.response;
|
|
135
|
+
if (status === 204 || schema === void 0) return { description };
|
|
136
|
+
return {
|
|
137
|
+
description,
|
|
138
|
+
content: { "application/json": { schema: typeof schema === "string" ? ref(schema) : schema } }
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
/** The OpenAPI operation object for one route. */
|
|
142
|
+
function openApiOperation(spec, options = {}) {
|
|
143
|
+
const responses = { [String(spec.response.status)]: responseOf(spec) };
|
|
144
|
+
if (spec.body || spec.query?.length) responses["400"] = errorResponse("Invalid input");
|
|
145
|
+
if (spec.action !== void 0) {
|
|
146
|
+
responses["401"] = errorResponse("Not authenticated");
|
|
147
|
+
responses["403"] = errorResponse("Not authorized for this action");
|
|
148
|
+
if (options.isMutatingAction?.(spec.action)) responses[String(options.readonlyStatus ?? 403)] = errorResponse(options.readonlyStatus === 423 ? "The panel is readonly" : "Not authorized for this action, or the panel is readonly");
|
|
149
|
+
}
|
|
150
|
+
if (spec.path.includes(":")) responses["404"] = errorResponse("Not found");
|
|
151
|
+
const parameters = [...[...spec.path.matchAll(PARAM)].map((m) => ({
|
|
152
|
+
name: m[1],
|
|
153
|
+
in: "path",
|
|
154
|
+
required: true,
|
|
155
|
+
schema: { type: "string" }
|
|
156
|
+
})), ...(spec.query ?? []).map((q) => ({
|
|
157
|
+
name: q.name,
|
|
158
|
+
in: "query",
|
|
159
|
+
required: q.required ?? false,
|
|
160
|
+
description: q.description,
|
|
161
|
+
schema: { type: q.type }
|
|
162
|
+
}))];
|
|
163
|
+
return {
|
|
164
|
+
operationId: spec.operationId,
|
|
165
|
+
tags: [spec.tag],
|
|
166
|
+
summary: spec.summary,
|
|
167
|
+
...spec.description ? { description: spec.description } : {},
|
|
168
|
+
...spec.action !== void 0 ? { "x-action": spec.action } : { security: [] },
|
|
169
|
+
...parameters.length ? { parameters } : {},
|
|
170
|
+
...spec.body ? { requestBody: {
|
|
171
|
+
required: spec.bodyRequired ?? true,
|
|
172
|
+
content: { "application/json": { schema: ref(spec.body) } }
|
|
173
|
+
} } : {},
|
|
174
|
+
responses
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Build the OpenAPI 3.1 document for a route table.
|
|
179
|
+
*
|
|
180
|
+
* @example
|
|
181
|
+
* ```ts
|
|
182
|
+
* const openapi = () =>
|
|
183
|
+
* buildOpenApiDocument({ routes: ROUTES, title, version: VERSION, basePath, schemas, tags });
|
|
184
|
+
* ```
|
|
185
|
+
*/
|
|
186
|
+
function buildOpenApiDocument(options) {
|
|
187
|
+
if (!options.version) throw new TypeError("buildOpenApiDocument: a version is required");
|
|
188
|
+
const paths = {};
|
|
189
|
+
for (const spec of options.routes) {
|
|
190
|
+
if (spec.hidden) continue;
|
|
191
|
+
const generated = openApiOperation(spec, options);
|
|
192
|
+
const p = paths[toOpenApiPath(spec.path)] ??= {};
|
|
193
|
+
p[spec.method.toLowerCase()] = options.operation ? options.operation(spec, generated) : generated;
|
|
194
|
+
}
|
|
195
|
+
return {
|
|
196
|
+
openapi: "3.1.0",
|
|
197
|
+
info: {
|
|
198
|
+
title: options.title,
|
|
199
|
+
version: options.version,
|
|
200
|
+
...options.description ? { description: options.description } : {}
|
|
201
|
+
},
|
|
202
|
+
servers: [{ url: options.basePath || "/" }],
|
|
203
|
+
...options.tags?.length ? { tags: options.tags } : {},
|
|
204
|
+
security: [{ basicAuth: [] }, { bearerAuth: [] }],
|
|
205
|
+
paths,
|
|
206
|
+
components: {
|
|
207
|
+
schemas: {
|
|
208
|
+
Error: ERROR_SCHEMA,
|
|
209
|
+
...options.schemas
|
|
210
|
+
},
|
|
211
|
+
securitySchemes: options.securitySchemes ?? {
|
|
212
|
+
basicAuth: {
|
|
213
|
+
type: "http",
|
|
214
|
+
scheme: "basic"
|
|
215
|
+
},
|
|
216
|
+
bearerAuth: {
|
|
217
|
+
type: "http",
|
|
218
|
+
scheme: "bearer",
|
|
219
|
+
...options.bearerDescription ? { description: options.bearerDescription } : {}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
},
|
|
223
|
+
...options.extra
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
//#endregion
|
|
227
|
+
exports.ERROR_SCHEMA = ERROR_SCHEMA;
|
|
228
|
+
exports.buildOpenApiDocument = buildOpenApiDocument;
|
|
229
|
+
exports.createRouter = createRouter;
|
|
230
|
+
exports.errorResponse = errorResponse;
|
|
231
|
+
exports.openApiOperation = openApiOperation;
|
|
232
|
+
exports.ref = ref;
|
|
233
|
+
exports.toOpenApiPath = toOpenApiPath;
|
|
234
|
+
|
|
235
|
+
//# sourceMappingURL=entry-server-router.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entry-server-router.cjs","names":["match","methodNotAllowed","error","authenticate","HttpError","parseInput","authorize","mapError"],"sources":["../src/server/router.ts","../src/server/openapi.ts"],"sourcesContent":["/**\n * A declarative API router (entitlements' design, made generic): one route\n * table drives dispatch, authentication, authorization, the readonly switch,\n * `405` + `Allow`, request-body validation, and the OpenAPI document\n * (`buildOpenApiDocument`), so the router and its docs cannot drift.\n *\n * Adopting it is optional per product (PLAN §1); the plumbing it is built on\n * (`json`, `match`, `mapError`, `authenticate`, `authorize`) is exported from\n * `@xtandard/kit/server` for hand-written routers.\n *\n * @module\n */\n\nimport type { GenericSchema, InferOutput } from \"valibot\";\nimport type { AuthProvider, Principal } from \"../auth/contract.ts\";\nimport type { AuthorizationProvider } from \"../authorization/contract.ts\";\nimport { parseInput, type ValidationIssue } from \"../util/validation.ts\";\nimport {\n authenticate,\n authorize,\n error,\n HttpError,\n mapError,\n match,\n methodNotAllowed,\n type Authenticated,\n type ErrorMap,\n type ScopedAuth,\n} from \"./http.ts\";\n\n/** HTTP methods the router serves (`HEAD` is answered by `GET` routes). */\nexport type RouteMethod = \"GET\" | \"POST\" | \"PUT\" | \"PATCH\" | \"DELETE\";\n\n/** A query parameter a route documents. */\nexport interface RouteQueryParam {\n name: string;\n type: \"string\" | \"integer\";\n description: string;\n required?: boolean;\n}\n\n/** The documented shape of one route (consumed by the OpenAPI builder). */\nexport interface RouteSpec<Action extends string = string, Tag extends string = string> {\n method: RouteMethod;\n /** Pattern with `:name` segments, base-path-relative. */\n path: string;\n operationId: string;\n summary: string;\n description?: string;\n tag: Tag;\n /** Authorization action; absent = public (no authentication). */\n action?: Action;\n query?: RouteQueryParam[];\n /** Component schema name of the JSON request body. */\n body?: string;\n /** Whether the body is required (default `true` when `body` is set). */\n bodyRequired?: boolean;\n /** Success status, component schema name (or inline JSON schema), description. */\n response: { status: number; schema?: string | Record<string, unknown>; description: string };\n /** Leave the route out of the OpenAPI document. */\n hidden?: boolean;\n}\n\n/** Per-request state handed to route handlers. */\nexport interface Call<Ctx, Grant = never> {\n request: Request;\n /** The base-path-stripped path. */\n path: string;\n params: Record<string, string>;\n query: URLSearchParams;\n /** The product's context object (`RouterOptions.context`). */\n ctx: Ctx;\n principal: Principal | null;\n /** The scoped-token grant, or `null` for host principals and anonymous requests. */\n scoped: Grant | null;\n /** Parse + validate the JSON body (an empty body is `{}`). Memoized. */\n body<S extends GenericSchema>(schema: S): Promise<InferOutput<S>>;\n}\n\n/** A route: its spec plus the resource it targets and its handler. */\nexport interface Route<\n Action extends string = string,\n Resource = unknown,\n Ctx = unknown,\n Grant = never,\n Tag extends string = string,\n> extends RouteSpec<Action, Tag> {\n /** The resource the action targets (required when `action` is set). */\n resource?(call: Call<Ctx, Grant>): Resource | Promise<Resource>;\n /**\n * Authenticate a public route anyway (e.g. `/config`, which reports the\n * principal). An authenticated-but-anonymous result is not an error.\n */\n authenticate?: boolean;\n handle(call: Call<Ctx, Grant>): Response | Promise<Response>;\n}\n\n/** Options for {@link createRouter}. */\nexport interface RouterOptions<\n Action extends string,\n Resource,\n Ctx,\n Grant = never,\n Tag extends string = string,\n> {\n routes: readonly Route<Action, Resource, Ctx, Grant, Tag>[];\n /** Passed to every handler as `call.ctx`. */\n context: Ctx;\n auth: AuthProvider;\n authorization: AuthorizationProvider<Action, Resource>;\n /** Scoped tokens: verification plus what a grant may do. */\n scoped?: ScopedAuth<Grant> & {\n /** Decide a scoped principal's access; the host provider is never consulted for them. */\n allows(grant: Grant, action: Action, resource: Resource): boolean | Promise<boolean>;\n };\n /** Readonly panel. A function is read per request. Default `false`. */\n readonly?: boolean | (() => boolean);\n /** Which actions the readonly switch blocks. */\n isMutatingAction?: (action: Action) => boolean;\n /** Status of a readonly denial: 403 (webhooks, flags, links) or 423 (audit, entitlements). Default `403`. */\n readonlyStatus?: number;\n /** Message of a readonly denial. Default `\"The panel is readonly\"`. */\n readonlyMessage?: string;\n /** Domain errors by name (see `mapError`). */\n errors?: ErrorMap;\n /** Unmatched paths under this prefix answer a JSON 404 instead of `null`. Default `\"/api/\"`. */\n apiPrefix?: string;\n /** Build the error a body validation failure throws. Default: a kit `ValidationError`. */\n validationError?: (issues: ValidationIssue[]) => Error;\n}\n\n/** What {@link createRouter} returns. */\nexport interface Router<Action extends string, Resource, Ctx, Grant, Tag extends string> {\n /**\n * Handle an API request (`path` base-path-stripped). Returns `null` for a\n * path that is not an API route, so the panel serves the UI.\n */\n handle(request: Request, path: string): Promise<Response | null>;\n /** The route table (for `buildOpenApiDocument`). */\n readonly routes: readonly Route<Action, Resource, Ctx, Grant, Tag>[];\n}\n\n/**\n * Build a router from a route table.\n *\n * Per request: match (collecting the methods a path supports, `HEAD` served\n * by `GET`) → `405` + `Allow` if only the method is wrong → authenticate\n * (routes with an `action`, or `authenticate: true`) → `401` / challenge →\n * resource → authorize (scoped grants via `scoped.allows`, never the host\n * provider) → `403` → readonly (`readonlyStatus`) → handler. Every thrown\n * error goes through `mapError` with `errors`.\n *\n * @example\n * ```ts\n * const router = createRouter({\n * routes: ROUTES,\n * context: { core },\n * auth,\n * authorization,\n * isMutatingAction,\n * readonly,\n * readonlyStatus: 423,\n * errors: { NotFoundError: { status: 404, code: \"NOT_FOUND\" } },\n * });\n * createPanelHandler({ ..., api: router.handle });\n * ```\n */\nexport function createRouter<\n Action extends string,\n Resource,\n Ctx,\n Grant = never,\n Tag extends string = string,\n>(\n options: RouterOptions<Action, Resource, Ctx, Grant, Tag>,\n): Router<Action, Resource, Ctx, Grant, Tag> {\n const { routes } = options;\n const scoped = options.scoped as NonNullable<typeof options.scoped>;\n const apiPrefix = options.apiPrefix ?? \"/api/\";\n const readonlyStatus = options.readonlyStatus ?? 403;\n const readonlyMessage = options.readonlyMessage ?? \"The panel is readonly\";\n const isReadonly =\n typeof options.readonly === \"function\"\n ? options.readonly\n : () => (options.readonly as boolean | undefined) ?? false;\n for (const route of routes) {\n if (route.action !== undefined && !route.resource) {\n throw new TypeError(\n `createRouter: route ${route.operationId} has an action but no resource()`,\n );\n }\n }\n\n async function handle(request: Request, path: string): Promise<Response | null> {\n const method = request.method.toUpperCase();\n let route: Route<Action, Resource, Ctx, Grant, Tag> | undefined;\n let params: Record<string, string> = {};\n const allowed = new Set<string>();\n for (const r of routes) {\n const m = match(r.path, path);\n if (!m) continue;\n allowed.add(r.method);\n if (r.method === \"GET\") allowed.add(\"HEAD\");\n if (!route && (r.method === method || (method === \"HEAD\" && r.method === \"GET\"))) {\n route = r;\n params = m;\n }\n }\n if (!route) {\n if (allowed.size > 0) return methodNotAllowed(allowed);\n return path.startsWith(apiPrefix) ? error(404, \"Not found\") : null;\n }\n\n try {\n let who: Authenticated<Grant> = { principal: null, scoped: null };\n if (route.action !== undefined || route.authenticate) {\n who = await authenticate(request, {\n auth: options.auth,\n ...(options.scoped ? { scoped: options.scoped } : {}),\n });\n }\n\n let raw: Promise<unknown> | undefined;\n const call: Call<Ctx, Grant> = {\n request,\n path,\n params,\n query: new URL(request.url).searchParams,\n ctx: options.context,\n principal: who.principal,\n scoped: who.scoped,\n async body(schema) {\n raw ??= request.text().then((text) => {\n if (text.trim() === \"\") return {};\n try {\n return JSON.parse(text) as unknown;\n } catch {\n throw new HttpError(400, \"Invalid JSON body\", { code: \"VALIDATION\" });\n }\n });\n return parseInput(\n schema,\n await raw,\n options.validationError ? { error: options.validationError } : {},\n );\n },\n };\n\n if (route.action !== undefined) {\n if (who.principal === null) {\n return options.auth.challenge?.(request) ?? error(401, \"Unauthorized\");\n }\n const resource = await (route.resource as NonNullable<typeof route.resource>)(call);\n const ok = await authorize(\n who,\n { action: route.action, resource, request },\n {\n authorization: options.authorization,\n ...(options.scoped\n ? { scope: (g: Grant, a: Action, r: Resource) => scoped.allows(g, a, r) }\n : {}),\n },\n );\n if (!ok) return error(403, \"Forbidden\", { action: route.action });\n if (isReadonly() && options.isMutatingAction?.(route.action)) {\n return error(readonlyStatus, readonlyMessage, { code: \"READONLY\" });\n }\n }\n\n return await route.handle(call);\n } catch (err) {\n return mapError(err, options.errors);\n }\n }\n\n return { handle, routes };\n}\n","/**\n * OpenAPI 3.1 generation from a route table (entitlements' design): every\n * operation, its parameters, request body, success response and the standard\n * error responses are derived from the {@link RouteSpec}s, so the document\n * cannot drift from the router.\n *\n * The product supplies the component schemas, tags, descriptions and its\n * readonly status; the document `version` is an explicit option (the copies\n * hard-coded `\"0.1.0\"`).\n *\n * @module\n */\n\nimport type { RouteSpec } from \"./router.ts\";\n\ntype Schema = Record<string, unknown>;\n\n/** Options for {@link buildOpenApiDocument}. */\nexport interface OpenApiOptions<Action extends string = string, Tag extends string = string> {\n /** The documented routes (hidden ones are skipped). */\n routes: readonly RouteSpec<Action, Tag>[];\n /** `info.title`. */\n title: string;\n /**\n * `info.version` — the HTTP API version (entitlements: `\"1\"`) or the package\n * version (links). Required: never a hard-coded default.\n */\n version: string;\n /** `info.description`. */\n description?: string;\n /** Mount prefix used in the `servers` url (e.g. `\"/webhooks\"`). */\n basePath?: string;\n /** Tag descriptions, in display order. */\n tags?: readonly { name: Tag; description?: string }[];\n /** `components.schemas`. Route `body`/`response.schema` names refer to these. */\n schemas?: Record<string, Schema>;\n /**\n * `components.securitySchemes`. Default: `basicAuth` and `bearerAuth` (the\n * latter described with `bearerDescription`).\n */\n securitySchemes?: Record<string, Schema>;\n /** Description of the default `bearerAuth` scheme, e.g. \"Portal tokens (whpt_…)\". */\n bearerDescription?: string;\n /** Which actions the readonly switch blocks (documents the readonly status on them). */\n isMutatingAction?: (action: Action) => boolean;\n /** Status of a readonly denial (403 or 423). Default `403`. */\n readonlyStatus?: number;\n /** Adjust one generated operation (extra responses, headers, examples…). */\n operation?: (spec: RouteSpec<Action, Tag>, operation: Schema) => Schema;\n /** Extra top-level fields merged into the document. */\n extra?: Schema;\n}\n\n/** `{ $ref: \"#/components/schemas/<name>\" }`. */\nexport const ref = (name: string): Schema => ({ $ref: `#/components/schemas/${name}` });\n\n/** The `{ error, code? }` body every error response uses. */\nexport const ERROR_SCHEMA: Schema = {\n type: \"object\",\n properties: { error: { type: \"string\" }, code: { type: \"string\" } },\n required: [\"error\"],\n additionalProperties: true,\n};\n\n/** A JSON error response object with `description`. */\nexport const errorResponse = (description: string): Schema => ({\n description,\n content: { \"application/json\": { schema: ref(\"Error\") } },\n});\n\n/** `/a/:id/b` → `/a/{id}/b`. */\nexport const toOpenApiPath = (path: string): string =>\n path.replace(/:([A-Za-z_][A-Za-z0-9_]*)/g, \"{$1}\");\n\nconst PARAM = /:([A-Za-z_][A-Za-z0-9_]*)/g;\n\n/** The success response object of a route. */\nfunction responseOf(spec: RouteSpec): Schema {\n const { status, schema, description } = spec.response;\n if (status === 204 || schema === undefined) return { description };\n return {\n description,\n content: {\n \"application/json\": { schema: typeof schema === \"string\" ? ref(schema) : schema },\n },\n };\n}\n\n/** The OpenAPI operation object for one route. */\nexport function openApiOperation<Action extends string, Tag extends string>(\n spec: RouteSpec<Action, Tag>,\n options: Pick<OpenApiOptions<Action, Tag>, \"isMutatingAction\" | \"readonlyStatus\"> = {},\n): Schema {\n const responses: Record<string, Schema> = { [String(spec.response.status)]: responseOf(spec) };\n if (spec.body || spec.query?.length) responses[\"400\"] = errorResponse(\"Invalid input\");\n if (spec.action !== undefined) {\n responses[\"401\"] = errorResponse(\"Not authenticated\");\n responses[\"403\"] = errorResponse(\"Not authorized for this action\");\n if (options.isMutatingAction?.(spec.action)) {\n responses[String(options.readonlyStatus ?? 403)] = errorResponse(\n options.readonlyStatus === 423\n ? \"The panel is readonly\"\n : \"Not authorized for this action, or the panel is readonly\",\n );\n }\n }\n if (spec.path.includes(\":\")) responses[\"404\"] = errorResponse(\"Not found\");\n const parameters: Schema[] = [\n ...[...spec.path.matchAll(PARAM)].map((m) => ({\n name: m[1],\n in: \"path\",\n required: true,\n schema: { type: \"string\" },\n })),\n ...(spec.query ?? []).map((q) => ({\n name: q.name,\n in: \"query\",\n required: q.required ?? false,\n description: q.description,\n schema: { type: q.type },\n })),\n ];\n return {\n operationId: spec.operationId,\n tags: [spec.tag],\n summary: spec.summary,\n ...(spec.description ? { description: spec.description } : {}),\n ...(spec.action !== undefined ? { \"x-action\": spec.action } : { security: [] }),\n ...(parameters.length ? { parameters } : {}),\n ...(spec.body\n ? {\n requestBody: {\n required: spec.bodyRequired ?? true,\n content: { \"application/json\": { schema: ref(spec.body) } },\n },\n }\n : {}),\n responses,\n };\n}\n\n/**\n * Build the OpenAPI 3.1 document for a route table.\n *\n * @example\n * ```ts\n * const openapi = () =>\n * buildOpenApiDocument({ routes: ROUTES, title, version: VERSION, basePath, schemas, tags });\n * ```\n */\nexport function buildOpenApiDocument<Action extends string, Tag extends string>(\n options: OpenApiOptions<Action, Tag>,\n): Record<string, unknown> {\n if (!options.version) throw new TypeError(\"buildOpenApiDocument: a version is required\");\n const paths: Record<string, Record<string, Schema>> = {};\n for (const spec of options.routes) {\n if (spec.hidden) continue;\n const generated = openApiOperation(spec, options);\n const p = (paths[toOpenApiPath(spec.path)] ??= {});\n p[spec.method.toLowerCase()] = options.operation\n ? options.operation(spec, generated)\n : generated;\n }\n return {\n openapi: \"3.1.0\",\n info: {\n title: options.title,\n version: options.version,\n ...(options.description ? { description: options.description } : {}),\n },\n servers: [{ url: options.basePath || \"/\" }],\n ...(options.tags?.length ? { tags: options.tags } : {}),\n security: [{ basicAuth: [] }, { bearerAuth: [] }],\n paths,\n components: {\n schemas: { Error: ERROR_SCHEMA, ...options.schemas },\n securitySchemes: options.securitySchemes ?? {\n basicAuth: { type: \"http\", scheme: \"basic\" },\n bearerAuth: {\n type: \"http\",\n scheme: \"bearer\",\n ...(options.bearerDescription ? { description: options.bearerDescription } : {}),\n },\n },\n },\n ...options.extra,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuKA,SAAgB,aAOd,SAC2C;CAC3C,MAAM,EAAE,WAAW;CACnB,MAAM,SAAS,QAAQ;CACvB,MAAM,YAAY,QAAQ,aAAa;CACvC,MAAM,iBAAiB,QAAQ,kBAAkB;CACjD,MAAM,kBAAkB,QAAQ,mBAAmB;CACnD,MAAM,aACJ,OAAO,QAAQ,aAAa,aACxB,QAAQ,iBACD,QAAQ,YAAoC;CACzD,KAAK,MAAM,SAAS,QAClB,IAAI,MAAM,WAAW,KAAA,KAAa,CAAC,MAAM,UACvC,MAAM,IAAI,UACR,uBAAuB,MAAM,YAAY,iCAC3C;CAIJ,eAAe,OAAO,SAAkB,MAAwC;EAC9E,MAAM,SAAS,QAAQ,OAAO,YAAY;EAC1C,IAAI;EACJ,IAAI,SAAiC,CAAC;EACtC,MAAM,0BAAU,IAAI,IAAY;EAChC,KAAK,MAAM,KAAK,Q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|
+
import { r as AuthorizationProvider } from "./contract-BIVzAn4f.cjs";
|
|
3
|
+
import { o as ValidationIssue } from "./validation-tfV2qhbD.cjs";
|
|
4
|
+
import { i as ErrorMap, l as ScopedAuth } from "./http-XBVRk8uo.cjs";
|
|
5
|
+
import { GenericSchema, InferOutput } from "valibot";
|
|
6
|
+
|
|
7
|
+
//#region src/server/router.d.ts
|
|
8
|
+
/** HTTP methods the router serves (`HEAD` is answered by `GET` routes). */
|
|
9
|
+
type RouteMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
10
|
+
/** A query parameter a route documents. */
|
|
11
|
+
interface RouteQueryParam {
|
|
12
|
+
name: string;
|
|
13
|
+
type: "string" | "integer";
|
|
14
|
+
description: string;
|
|
15
|
+
required?: boolean;
|
|
16
|
+
}
|
|
17
|
+
/** The documented shape of one route (consumed by the OpenAPI builder). */
|
|
18
|
+
interface RouteSpec<Action extends string = string, Tag extends string = string> {
|
|
19
|
+
method: RouteMethod;
|
|
20
|
+
/** Pattern with `:name` segments, base-path-relative. */
|
|
21
|
+
path: string;
|
|
22
|
+
operationId: string;
|
|
23
|
+
summary: string;
|
|
24
|
+
description?: string;
|
|
25
|
+
tag: Tag;
|
|
26
|
+
/** Authorization action; absent = public (no authentication). */
|
|
27
|
+
action?: Action;
|
|
28
|
+
query?: RouteQueryParam[];
|
|
29
|
+
/** Component schema name of the JSON request body. */
|
|
30
|
+
body?: string;
|
|
31
|
+
/** Whether the body is required (default `true` when `body` is set). */
|
|
32
|
+
bodyRequired?: boolean;
|
|
33
|
+
/** Success status, component schema name (or inline JSON schema), description. */
|
|
34
|
+
response: {
|
|
35
|
+
status: number;
|
|
36
|
+
schema?: string | Record<string, unknown>;
|
|
37
|
+
description: string;
|
|
38
|
+
};
|
|
39
|
+
/** Leave the route out of the OpenAPI document. */
|
|
40
|
+
hidden?: boolean;
|
|
41
|
+
}
|
|
42
|
+
/** Per-request state handed to route handlers. */
|
|
43
|
+
interface Call<Ctx, Grant = never> {
|
|
44
|
+
request: Request;
|
|
45
|
+
/** The base-path-stripped path. */
|
|
46
|
+
path: string;
|
|
47
|
+
params: Record<string, string>;
|
|
48
|
+
query: URLSearchParams;
|
|
49
|
+
/** The product's context object (`RouterOptions.context`). */
|
|
50
|
+
ctx: Ctx;
|
|
51
|
+
principal: Principal | null;
|
|
52
|
+
/** The scoped-token grant, or `null` for host principals and anonymous requests. */
|
|
53
|
+
scoped: Grant | null;
|
|
54
|
+
/** Parse + validate the JSON body (an empty body is `{}`). Memoized. */
|
|
55
|
+
body<S extends GenericSchema>(schema: S): Promise<InferOutput<S>>;
|
|
56
|
+
}
|
|
57
|
+
/** A route: its spec plus the resource it targets and its handler. */
|
|
58
|
+
interface Route<Action extends string = string, Resource = unknown, Ctx = unknown, Grant = never, Tag extends string = string> extends RouteSpec<Action, Tag> {
|
|
59
|
+
/** The resource the action targets (required when `action` is set). */
|
|
60
|
+
resource?(call: Call<Ctx, Grant>): Resource | Promise<Resource>;
|
|
61
|
+
/**
|
|
62
|
+
* Authenticate a public route anyway (e.g. `/config`, which reports the
|
|
63
|
+
* principal). An authenticated-but-anonymous result is not an error.
|
|
64
|
+
*/
|
|
65
|
+
authenticate?: boolean;
|
|
66
|
+
handle(call: Call<Ctx, Grant>): Response | Promise<Response>;
|
|
67
|
+
}
|
|
68
|
+
/** Options for {@link createRouter}. */
|
|
69
|
+
interface RouterOptions<Action extends string, Resource, Ctx, Grant = never, Tag extends string = string> {
|
|
70
|
+
routes: readonly Route<Action, Resource, Ctx, Grant, Tag>[];
|
|
71
|
+
/** Passed to every handler as `call.ctx`. */
|
|
72
|
+
context: Ctx;
|
|
73
|
+
auth: AuthProvider;
|
|
74
|
+
authorization: AuthorizationProvider<Action, Resource>;
|
|
75
|
+
/** Scoped tokens: verification plus what a grant may do. */
|
|
76
|
+
scoped?: ScopedAuth<Grant> & {
|
|
77
|
+
/** Decide a scoped principal's access; the host provider is never consulted for them. */allows(grant: Grant, action: Action, resource: Resource): boolean | Promise<boolean>;
|
|
78
|
+
};
|
|
79
|
+
/** Readonly panel. A function is read per request. Default `false`. */
|
|
80
|
+
readonly?: boolean | (() => boolean);
|
|
81
|
+
/** Which actions the readonly switch blocks. */
|
|
82
|
+
isMutatingAction?: (action: Action) => boolean;
|
|
83
|
+
/** Status of a readonly denial: 403 (webhooks, flags, links) or 423 (audit, entitlements). Default `403`. */
|
|
84
|
+
readonlyStatus?: number;
|
|
85
|
+
/** Message of a readonly denial. Default `"The panel is readonly"`. */
|
|
86
|
+
readonlyMessage?: string;
|
|
87
|
+
/** Domain errors by name (see `mapError`). */
|
|
88
|
+
errors?: ErrorMap;
|
|
89
|
+
/** Unmatched paths under this prefix answer a JSON 404 instead of `null`. Default `"/api/"`. */
|
|
90
|
+
apiPrefix?: string;
|
|
91
|
+
/** Build the error a body validation failure throws. Default: a kit `ValidationError`. */
|
|
92
|
+
validationError?: (issues: ValidationIssue[]) => Error;
|
|
93
|
+
}
|
|
94
|
+
/** What {@link createRouter} returns. */
|
|
95
|
+
interface Router<Action extends string, Resource, Ctx, Grant, Tag extends string> {
|
|
96
|
+
/**
|
|
97
|
+
* Handle an API request (`path` base-path-stripped). Returns `null` for a
|
|
98
|
+
* path that is not an API route, so the panel serves the UI.
|
|
99
|
+
*/
|
|
100
|
+
handle(request: Request, path: string): Promise<Response | null>;
|
|
101
|
+
/** The route table (for `buildOpenApiDocument`). */
|
|
102
|
+
readonly routes: readonly Route<Action, Resource, Ctx, Grant, Tag>[];
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Build a router from a route table.
|
|
106
|
+
*
|
|
107
|
+
* Per request: match (collecting the methods a path supports, `HEAD` served
|
|
108
|
+
* by `GET`) → `405` + `Allow` if only the method is wrong → authenticate
|
|
109
|
+
* (routes with an `action`, or `authenticate: true`) → `401` / challenge →
|
|
110
|
+
* resource → authorize (scoped grants via `scoped.allows`, never the host
|
|
111
|
+
* provider) → `403` → readonly (`readonlyStatus`) → handler. Every thrown
|
|
112
|
+
* error goes through `mapError` with `errors`.
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```ts
|
|
116
|
+
* const router = createRouter({
|
|
117
|
+
* routes: ROUTES,
|
|
118
|
+
* context: { core },
|
|
119
|
+
* auth,
|
|
120
|
+
* authorization,
|
|
121
|
+
* isMutatingAction,
|
|
122
|
+
* readonly,
|
|
123
|
+
* readonlyStatus: 423,
|
|
124
|
+
* errors: { NotFoundError: { status: 404, code: "NOT_FOUND" } },
|
|
125
|
+
* });
|
|
126
|
+
* createPanelHandler({ ..., api: router.handle });
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
declare function createRouter<Action extends string, Resource, Ctx, Grant = never, Tag extends string = string>(options: RouterOptions<Action, Resource, Ctx, Grant, Tag>): Router<Action, Resource, Ctx, Grant, Tag>;
|
|
130
|
+
//#endregion
|
|
131
|
+
//#region src/server/openapi.d.ts
|
|
132
|
+
type Schema = Record<string, unknown>;
|
|
133
|
+
/** Options for {@link buildOpenApiDocument}. */
|
|
134
|
+
interface OpenApiOptions<Action extends string = string, Tag extends string = string> {
|
|
135
|
+
/** The documented routes (hidden ones are skipped). */
|
|
136
|
+
routes: readonly RouteSpec<Action, Tag>[];
|
|
137
|
+
/** `info.title`. */
|
|
138
|
+
title: string;
|
|
139
|
+
/**
|
|
140
|
+
* `info.version` — the HTTP API version (entitlements: `"1"`) or the package
|
|
141
|
+
* version (links). Required: never a hard-coded default.
|
|
142
|
+
*/
|
|
143
|
+
version: string;
|
|
144
|
+
/** `info.description`. */
|
|
145
|
+
description?: string;
|
|
146
|
+
/** Mount prefix used in the `servers` url (e.g. `"/webhooks"`). */
|
|
147
|
+
basePath?: string;
|
|
148
|
+
/** Tag descriptions, in display order. */
|
|
149
|
+
tags?: readonly {
|
|
150
|
+
name: Tag;
|
|
151
|
+
description?: string;
|
|
152
|
+
}[];
|
|
153
|
+
/** `components.schemas`. Route `body`/`response.schema` names refer to these. */
|
|
154
|
+
schemas?: Record<string, Schema>;
|
|
155
|
+
/**
|
|
156
|
+
* `components.securitySchemes`. Default: `basicAuth` and `bearerAuth` (the
|
|
157
|
+
* latter described with `bearerDescription`).
|
|
158
|
+
*/
|
|
159
|
+
securitySchemes?: Record<string, Schema>;
|
|
160
|
+
/** Description of the default `bearerAuth` scheme, e.g. "Portal tokens (whpt_…)". */
|
|
161
|
+
bearerDescription?: string;
|
|
162
|
+
/** Which actions the readonly switch blocks (documents the readonly status on them). */
|
|
163
|
+
isMutatingAction?: (action: Action) => boolean;
|
|
164
|
+
/** Status of a readonly denial (403 or 423). Default `403`. */
|
|
165
|
+
readonlyStatus?: number;
|
|
166
|
+
/** Adjust one generated operation (extra responses, headers, examples…). */
|
|
167
|
+
operation?: (spec: RouteSpec<Action, Tag>, operation: Schema) => Schema;
|
|
168
|
+
/** Extra top-level fields merged into the document. */
|
|
169
|
+
extra?: Schema;
|
|
170
|
+
}
|
|
171
|
+
/** `{ $ref: "#/components/schemas/<name>" }`. */
|
|
172
|
+
declare const ref: (name: string) => Schema;
|
|
173
|
+
/** The `{ error, code? }` body every error response uses. */
|
|
174
|
+
declare const ERROR_SCHEMA: Schema;
|
|
175
|
+
/** A JSON error response object with `description`. */
|
|
176
|
+
declare const errorResponse: (description: string) => Schema;
|
|
177
|
+
/** `/a/:id/b` → `/a/{id}/b`. */
|
|
178
|
+
declare const toOpenApiPath: (path: string) => string;
|
|
179
|
+
/** The OpenAPI operation object for one route. */
|
|
180
|
+
declare function openApiOperation<Action extends string, Tag extends string>(spec: RouteSpec<Action, Tag>, options?: Pick<OpenApiOptions<Action, Tag>, "isMutatingAction" | "readonlyStatus">): Schema;
|
|
181
|
+
/**
|
|
182
|
+
* Build the OpenAPI 3.1 document for a route table.
|
|
183
|
+
*
|
|
184
|
+
* @example
|
|
185
|
+
* ```ts
|
|
186
|
+
* const openapi = () =>
|
|
187
|
+
* buildOpenApiDocument({ routes: ROUTES, title, version: VERSION, basePath, schemas, tags });
|
|
188
|
+
* ```
|
|
189
|
+
*/
|
|
190
|
+
declare function buildOpenApiDocument<Action extends string, Tag extends string>(options: OpenApiOptions<Action, Tag>): Record<string, unknown>;
|
|
191
|
+
//#endregion
|
|
192
|
+
export { type Call, ERROR_SCHEMA, type OpenApiOptions, type Route, type RouteMethod, type RouteQueryParam, type RouteSpec, type Router, type RouterOptions, buildOpenApiDocument, createRouter, errorResponse, openApiOperation, ref, toOpenApiPath };
|
|
193
|
+
//# sourceMappingURL=entry-server-router.d.cts.map
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { n as Principal, t as AuthProvider } from "./contract-B3UPXXLx.mjs";
|
|
2
|
+
import { r as AuthorizationProvider } from "./contract-BDPNvjtp.mjs";
|
|
3
|
+
import { o as ValidationIssue } from "./validation-BJifGoB2.mjs";
|
|
4
|
+
import { i as ErrorMap, l as ScopedAuth } from "./http-CxYM7kPT.mjs";
|
|
5
|
+
import { GenericSchema, InferOutput } from "valibot";
|
|
6
|
+
|
|
7
|
+
//#region src/server/router.d.ts
|
|
8
|
+
/** HTTP methods the router serves (`HEAD` is answered by `GET` routes). */
|
|
9
|
+
type RouteMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
10
|
+
/** A query parameter a route documents. */
|
|
11
|
+
interface RouteQueryParam {
|
|
12
|
+
name: string;
|
|
13
|
+
type: "string" | "integer";
|
|
14
|
+
description: string;
|
|
15
|
+
required?: boolean;
|
|
16
|
+
}
|
|
17
|
+
/** The documented shape of one route (consumed by the OpenAPI builder). */
|
|
18
|
+
interface RouteSpec<Action extends string = string, Tag extends string = string> {
|
|
19
|
+
method: RouteMethod;
|
|
20
|
+
/** Pattern with `:name` segments, base-path-relative. */
|
|
21
|
+
path: string;
|
|
22
|
+
operationId: string;
|
|
23
|
+
summary: string;
|
|
24
|
+
description?: string;
|
|
25
|
+
tag: Tag;
|
|
26
|
+
/** Authorization action; absent = public (no authentication). */
|
|
27
|
+
action?: Action;
|
|
28
|
+
query?: RouteQueryParam[];
|
|
29
|
+
/** Component schema name of the JSON request body. */
|
|
30
|
+
body?: string;
|
|
31
|
+
/** Whether the body is required (default `true` when `body` is set). */
|
|
32
|
+
bodyRequired?: boolean;
|
|
33
|
+
/** Success status, component schema name (or inline JSON schema), description. */
|
|
34
|
+
response: {
|
|
35
|
+
status: number;
|
|
36
|
+
schema?: string | Record<string, unknown>;
|
|
37
|
+
description: string;
|
|
38
|
+
};
|
|
39
|
+
/** Leave the route out of the OpenAPI document. */
|
|
40
|
+
hidden?: boolean;
|
|
41
|
+
}
|
|
42
|
+
/** Per-request state handed to route handlers. */
|
|
43
|
+
interface Call<Ctx, Grant = never> {
|
|
44
|
+
request: Request;
|
|
45
|
+
/** The base-path-stripped path. */
|
|
46
|
+
path: string;
|
|
47
|
+
params: Record<string, string>;
|
|
48
|
+
query: URLSearchParams;
|
|
49
|
+
/** The product's context object (`RouterOptions.context`). */
|
|
50
|
+
ctx: Ctx;
|
|
51
|
+
principal: Principal | null;
|
|
52
|
+
/** The scoped-token grant, or `null` for host principals and anonymous requests. */
|
|
53
|
+
scoped: Grant | null;
|
|
54
|
+
/** Parse + validate the JSON body (an empty body is `{}`). Memoized. */
|
|
55
|
+
body<S extends GenericSchema>(schema: S): Promise<InferOutput<S>>;
|
|
56
|
+
}
|
|
57
|
+
/** A route: its spec plus the resource it targets and its handler. */
|
|
58
|
+
interface Route<Action extends string = string, Resource = unknown, Ctx = unknown, Grant = never, Tag extends string = string> extends RouteSpec<Action, Tag> {
|
|
59
|
+
/** The resource the action targets (required when `action` is set). */
|
|
60
|
+
resource?(call: Call<Ctx, Grant>): Resource | Promise<Resource>;
|
|
61
|
+
/**
|
|
62
|
+
* Authenticate a public route anyway (e.g. `/config`, which reports the
|
|
63
|
+
* principal). An authenticated-but-anonymous result is not an error.
|
|
64
|
+
*/
|
|
65
|
+
authenticate?: boolean;
|
|
66
|
+
handle(call: Call<Ctx, Grant>): Response | Promise<Response>;
|
|
67
|
+
}
|
|
68
|
+
/** Options for {@link createRouter}. */
|
|
69
|
+
interface RouterOptions<Action extends string, Resource, Ctx, Grant = never, Tag extends string = string> {
|
|
70
|
+
routes: readonly Route<Action, Resource, Ctx, Grant, Tag>[];
|
|
71
|
+
/** Passed to every handler as `call.ctx`. */
|
|
72
|
+
context: Ctx;
|
|
73
|
+
auth: AuthProvider;
|
|
74
|
+
authorization: AuthorizationProvider<Action, Resource>;
|
|
75
|
+
/** Scoped tokens: verification plus what a grant may do. */
|
|
76
|
+
scoped?: ScopedAuth<Grant> & {
|
|
77
|
+
/** Decide a scoped principal's access; the host provider is never consulted for them. */allows(grant: Grant, action: Action, resource: Resource): boolean | Promise<boolean>;
|
|
78
|
+
};
|
|
79
|
+
/** Readonly panel. A function is read per request. Default `false`. */
|
|
80
|
+
readonly?: boolean | (() => boolean);
|
|
81
|
+
/** Which actions the readonly switch blocks. */
|
|
82
|
+
isMutatingAction?: (action: Action) => boolean;
|
|
83
|
+
/** Status of a readonly denial: 403 (webhooks, flags, links) or 423 (audit, entitlements). Default `403`. */
|
|
84
|
+
readonlyStatus?: number;
|
|
85
|
+
/** Message of a readonly denial. Default `"The panel is readonly"`. */
|
|
86
|
+
readonlyMessage?: string;
|
|
87
|
+
/** Domain errors by name (see `mapError`). */
|
|
88
|
+
errors?: ErrorMap;
|
|
89
|
+
/** Unmatched paths under this prefix answer a JSON 404 instead of `null`. Default `"/api/"`. */
|
|
90
|
+
apiPrefix?: string;
|
|
91
|
+
/** Build the error a body validation failure throws. Default: a kit `ValidationError`. */
|
|
92
|
+
validationError?: (issues: ValidationIssue[]) => Error;
|
|
93
|
+
}
|
|
94
|
+
/** What {@link createRouter} returns. */
|
|
95
|
+
interface Router<Action extends string, Resource, Ctx, Grant, Tag extends string> {
|
|
96
|
+
/**
|
|
97
|
+
* Handle an API request (`path` base-path-stripped). Returns `null` for a
|
|
98
|
+
* path that is not an API route, so the panel serves the UI.
|
|
99
|
+
*/
|
|
100
|
+
handle(request: Request, path: string): Promise<Response | null>;
|
|
101
|
+
/** The route table (for `buildOpenApiDocument`). */
|
|
102
|
+
readonly routes: readonly Route<Action, Resource, Ctx, Grant, Tag>[];
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Build a router from a route table.
|
|
106
|
+
*
|
|
107
|
+
* Per request: match (collecting the methods a path supports, `HEAD` served
|
|
108
|
+
* by `GET`) → `405` + `Allow` if only the method is wrong → authenticate
|
|
109
|
+
* (routes with an `action`, or `authenticate: true`) → `401` / challenge →
|
|
110
|
+
* resource → authorize (scoped grants via `scoped.allows`, never the host
|
|
111
|
+
* provider) → `403` → readonly (`readonlyStatus`) → handler. Every thrown
|
|
112
|
+
* error goes through `mapError` with `errors`.
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```ts
|
|
116
|
+
* const router = createRouter({
|
|
117
|
+
* routes: ROUTES,
|
|
118
|
+
* context: { core },
|
|
119
|
+
* auth,
|
|
120
|
+
* authorization,
|
|
121
|
+
* isMutatingAction,
|
|
122
|
+
* readonly,
|
|
123
|
+
* readonlyStatus: 423,
|
|
124
|
+
* errors: { NotFoundError: { status: 404, code: "NOT_FOUND" } },
|
|
125
|
+
* });
|
|
126
|
+
* createPanelHandler({ ..., api: router.handle });
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
declare function createRouter<Action extends string, Resource, Ctx, Grant = never, Tag extends string = string>(options: RouterOptions<Action, Resource, Ctx, Grant, Tag>): Router<Action, Resource, Ctx, Grant, Tag>;
|
|
130
|
+
//#endregion
|
|
131
|
+
//#region src/server/openapi.d.ts
|
|
132
|
+
type Schema = Record<string, unknown>;
|
|
133
|
+
/** Options for {@link buildOpenApiDocument}. */
|
|
134
|
+
interface OpenApiOptions<Action extends string = string, Tag extends string = string> {
|
|
135
|
+
/** The documented routes (hidden ones are skipped). */
|
|
136
|
+
routes: readonly RouteSpec<Action, Tag>[];
|
|
137
|
+
/** `info.title`. */
|
|
138
|
+
title: string;
|
|
139
|
+
/**
|
|
140
|
+
* `info.version` — the HTTP API version (entitlements: `"1"`) or the package
|
|
141
|
+
* version (links). Required: never a hard-coded default.
|
|
142
|
+
*/
|
|
143
|
+
version: string;
|
|
144
|
+
/** `info.description`. */
|
|
145
|
+
description?: string;
|
|
146
|
+
/** Mount prefix used in the `servers` url (e.g. `"/webhooks"`). */
|
|
147
|
+
basePath?: string;
|
|
148
|
+
/** Tag descriptions, in display order. */
|
|
149
|
+
tags?: readonly {
|
|
150
|
+
name: Tag;
|
|
151
|
+
description?: string;
|
|
152
|
+
}[];
|
|
153
|
+
/** `components.schemas`. Route `body`/`response.schema` names refer to these. */
|
|
154
|
+
schemas?: Record<string, Schema>;
|
|
155
|
+
/**
|
|
156
|
+
* `components.securitySchemes`. Default: `basicAuth` and `bearerAuth` (the
|
|
157
|
+
* latter described with `bearerDescription`).
|
|
158
|
+
*/
|
|
159
|
+
securitySchemes?: Record<string, Schema>;
|
|
160
|
+
/** Description of the default `bearerAuth` scheme, e.g. "Portal tokens (whpt_…)". */
|
|
161
|
+
bearerDescription?: string;
|
|
162
|
+
/** Which actions the readonly switch blocks (documents the readonly status on them). */
|
|
163
|
+
isMutatingAction?: (action: Action) => boolean;
|
|
164
|
+
/** Status of a readonly denial (403 or 423). Default `403`. */
|
|
165
|
+
readonlyStatus?: number;
|
|
166
|
+
/** Adjust one generated operation (extra responses, headers, examples…). */
|
|
167
|
+
operation?: (spec: RouteSpec<Action, Tag>, operation: Schema) => Schema;
|
|
168
|
+
/** Extra top-level fields merged into the document. */
|
|
169
|
+
extra?: Schema;
|
|
170
|
+
}
|
|
171
|
+
/** `{ $ref: "#/components/schemas/<name>" }`. */
|
|
172
|
+
declare const ref: (name: string) => Schema;
|
|
173
|
+
/** The `{ error, code? }` body every error response uses. */
|
|
174
|
+
declare const ERROR_SCHEMA: Schema;
|
|
175
|
+
/** A JSON error response object with `description`. */
|
|
176
|
+
declare const errorResponse: (description: string) => Schema;
|
|
177
|
+
/** `/a/:id/b` → `/a/{id}/b`. */
|
|
178
|
+
declare const toOpenApiPath: (path: string) => string;
|
|
179
|
+
/** The OpenAPI operation object for one route. */
|
|
180
|
+
declare function openApiOperation<Action extends string, Tag extends string>(spec: RouteSpec<Action, Tag>, options?: Pick<OpenApiOptions<Action, Tag>, "isMutatingAction" | "readonlyStatus">): Schema;
|
|
181
|
+
/**
|
|
182
|
+
* Build the OpenAPI 3.1 document for a route table.
|
|
183
|
+
*
|
|
184
|
+
* @example
|
|
185
|
+
* ```ts
|
|
186
|
+
* const openapi = () =>
|
|
187
|
+
* buildOpenApiDocument({ routes: ROUTES, title, version: VERSION, basePath, schemas, tags });
|
|
188
|
+
* ```
|
|
189
|
+
*/
|
|
190
|
+
declare function buildOpenApiDocument<Action extends string, Tag extends string>(options: OpenApiOptions<Action, Tag>): Record<string, unknown>;
|
|
191
|
+
//#endregion
|
|
192
|
+
export { type Call, ERROR_SCHEMA, type OpenApiOptions, type Route, type RouteMethod, type RouteQueryParam, type RouteSpec, type Router, type RouterOptions, buildOpenApiDocument, createRouter, errorResponse, openApiOperation, ref, toOpenApiPath };
|
|
193
|
+
//# sourceMappingURL=entry-server-router.d.mts.map
|