@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,228 @@
|
|
|
1
|
+
import { a as error, c as mapError, i as authorize, l as match, r as authenticate, t as HttpError, u as methodNotAllowed } from "./http-DVdVI6kJ.mjs";
|
|
2
|
+
import { c as parseInput } from "./validation-B-atP968.mjs";
|
|
3
|
+
//#region src/server/router.ts
|
|
4
|
+
/**
|
|
5
|
+
* Build a router from a route table.
|
|
6
|
+
*
|
|
7
|
+
* Per request: match (collecting the methods a path supports, `HEAD` served
|
|
8
|
+
* by `GET`) → `405` + `Allow` if only the method is wrong → authenticate
|
|
9
|
+
* (routes with an `action`, or `authenticate: true`) → `401` / challenge →
|
|
10
|
+
* resource → authorize (scoped grants via `scoped.allows`, never the host
|
|
11
|
+
* provider) → `403` → readonly (`readonlyStatus`) → handler. Every thrown
|
|
12
|
+
* error goes through `mapError` with `errors`.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* const router = createRouter({
|
|
17
|
+
* routes: ROUTES,
|
|
18
|
+
* context: { core },
|
|
19
|
+
* auth,
|
|
20
|
+
* authorization,
|
|
21
|
+
* isMutatingAction,
|
|
22
|
+
* readonly,
|
|
23
|
+
* readonlyStatus: 423,
|
|
24
|
+
* errors: { NotFoundError: { status: 404, code: "NOT_FOUND" } },
|
|
25
|
+
* });
|
|
26
|
+
* createPanelHandler({ ..., api: router.handle });
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
function createRouter(options) {
|
|
30
|
+
const { routes } = options;
|
|
31
|
+
const scoped = options.scoped;
|
|
32
|
+
const apiPrefix = options.apiPrefix ?? "/api/";
|
|
33
|
+
const readonlyStatus = options.readonlyStatus ?? 403;
|
|
34
|
+
const readonlyMessage = options.readonlyMessage ?? "The panel is readonly";
|
|
35
|
+
const isReadonly = typeof options.readonly === "function" ? options.readonly : () => options.readonly ?? false;
|
|
36
|
+
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()`);
|
|
37
|
+
async function handle(request, path) {
|
|
38
|
+
const method = request.method.toUpperCase();
|
|
39
|
+
let route;
|
|
40
|
+
let params = {};
|
|
41
|
+
const allowed = /* @__PURE__ */ new Set();
|
|
42
|
+
for (const r of routes) {
|
|
43
|
+
const m = match(r.path, path);
|
|
44
|
+
if (!m) continue;
|
|
45
|
+
allowed.add(r.method);
|
|
46
|
+
if (r.method === "GET") allowed.add("HEAD");
|
|
47
|
+
if (!route && (r.method === method || method === "HEAD" && r.method === "GET")) {
|
|
48
|
+
route = r;
|
|
49
|
+
params = m;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (!route) {
|
|
53
|
+
if (allowed.size > 0) return methodNotAllowed(allowed);
|
|
54
|
+
return path.startsWith(apiPrefix) ? error(404, "Not found") : null;
|
|
55
|
+
}
|
|
56
|
+
try {
|
|
57
|
+
let who = {
|
|
58
|
+
principal: null,
|
|
59
|
+
scoped: null
|
|
60
|
+
};
|
|
61
|
+
if (route.action !== void 0 || route.authenticate) who = await authenticate(request, {
|
|
62
|
+
auth: options.auth,
|
|
63
|
+
...options.scoped ? { scoped: options.scoped } : {}
|
|
64
|
+
});
|
|
65
|
+
let raw;
|
|
66
|
+
const call = {
|
|
67
|
+
request,
|
|
68
|
+
path,
|
|
69
|
+
params,
|
|
70
|
+
query: new URL(request.url).searchParams,
|
|
71
|
+
ctx: options.context,
|
|
72
|
+
principal: who.principal,
|
|
73
|
+
scoped: who.scoped,
|
|
74
|
+
async body(schema) {
|
|
75
|
+
raw ??= request.text().then((text) => {
|
|
76
|
+
if (text.trim() === "") return {};
|
|
77
|
+
try {
|
|
78
|
+
return JSON.parse(text);
|
|
79
|
+
} catch {
|
|
80
|
+
throw new HttpError(400, "Invalid JSON body", { code: "VALIDATION" });
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
return parseInput(schema, await raw, options.validationError ? { error: options.validationError } : {});
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
if (route.action !== void 0) {
|
|
87
|
+
if (who.principal === null) return options.auth.challenge?.(request) ?? error(401, "Unauthorized");
|
|
88
|
+
const resource = await route.resource(call);
|
|
89
|
+
if (!await authorize(who, {
|
|
90
|
+
action: route.action,
|
|
91
|
+
resource,
|
|
92
|
+
request
|
|
93
|
+
}, {
|
|
94
|
+
authorization: options.authorization,
|
|
95
|
+
...options.scoped ? { scope: (g, a, r) => scoped.allows(g, a, r) } : {}
|
|
96
|
+
})) return error(403, "Forbidden", { action: route.action });
|
|
97
|
+
if (isReadonly() && options.isMutatingAction?.(route.action)) return error(readonlyStatus, readonlyMessage, { code: "READONLY" });
|
|
98
|
+
}
|
|
99
|
+
return await route.handle(call);
|
|
100
|
+
} catch (err) {
|
|
101
|
+
return mapError(err, options.errors);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return {
|
|
105
|
+
handle,
|
|
106
|
+
routes
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
//#endregion
|
|
110
|
+
//#region src/server/openapi.ts
|
|
111
|
+
/** `{ $ref: "#/components/schemas/<name>" }`. */
|
|
112
|
+
const ref = (name) => ({ $ref: `#/components/schemas/${name}` });
|
|
113
|
+
/** The `{ error, code? }` body every error response uses. */
|
|
114
|
+
const ERROR_SCHEMA = {
|
|
115
|
+
type: "object",
|
|
116
|
+
properties: {
|
|
117
|
+
error: { type: "string" },
|
|
118
|
+
code: { type: "string" }
|
|
119
|
+
},
|
|
120
|
+
required: ["error"],
|
|
121
|
+
additionalProperties: true
|
|
122
|
+
};
|
|
123
|
+
/** A JSON error response object with `description`. */
|
|
124
|
+
const errorResponse = (description) => ({
|
|
125
|
+
description,
|
|
126
|
+
content: { "application/json": { schema: ref("Error") } }
|
|
127
|
+
});
|
|
128
|
+
/** `/a/:id/b` → `/a/{id}/b`. */
|
|
129
|
+
const toOpenApiPath = (path) => path.replace(/:([A-Za-z_][A-Za-z0-9_]*)/g, "{$1}");
|
|
130
|
+
const PARAM = /:([A-Za-z_][A-Za-z0-9_]*)/g;
|
|
131
|
+
/** The success response object of a route. */
|
|
132
|
+
function responseOf(spec) {
|
|
133
|
+
const { status, schema, description } = spec.response;
|
|
134
|
+
if (status === 204 || schema === void 0) return { description };
|
|
135
|
+
return {
|
|
136
|
+
description,
|
|
137
|
+
content: { "application/json": { schema: typeof schema === "string" ? ref(schema) : schema } }
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
/** The OpenAPI operation object for one route. */
|
|
141
|
+
function openApiOperation(spec, options = {}) {
|
|
142
|
+
const responses = { [String(spec.response.status)]: responseOf(spec) };
|
|
143
|
+
if (spec.body || spec.query?.length) responses["400"] = errorResponse("Invalid input");
|
|
144
|
+
if (spec.action !== void 0) {
|
|
145
|
+
responses["401"] = errorResponse("Not authenticated");
|
|
146
|
+
responses["403"] = errorResponse("Not authorized for this action");
|
|
147
|
+
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");
|
|
148
|
+
}
|
|
149
|
+
if (spec.path.includes(":")) responses["404"] = errorResponse("Not found");
|
|
150
|
+
const parameters = [...[...spec.path.matchAll(PARAM)].map((m) => ({
|
|
151
|
+
name: m[1],
|
|
152
|
+
in: "path",
|
|
153
|
+
required: true,
|
|
154
|
+
schema: { type: "string" }
|
|
155
|
+
})), ...(spec.query ?? []).map((q) => ({
|
|
156
|
+
name: q.name,
|
|
157
|
+
in: "query",
|
|
158
|
+
required: q.required ?? false,
|
|
159
|
+
description: q.description,
|
|
160
|
+
schema: { type: q.type }
|
|
161
|
+
}))];
|
|
162
|
+
return {
|
|
163
|
+
operationId: spec.operationId,
|
|
164
|
+
tags: [spec.tag],
|
|
165
|
+
summary: spec.summary,
|
|
166
|
+
...spec.description ? { description: spec.description } : {},
|
|
167
|
+
...spec.action !== void 0 ? { "x-action": spec.action } : { security: [] },
|
|
168
|
+
...parameters.length ? { parameters } : {},
|
|
169
|
+
...spec.body ? { requestBody: {
|
|
170
|
+
required: spec.bodyRequired ?? true,
|
|
171
|
+
content: { "application/json": { schema: ref(spec.body) } }
|
|
172
|
+
} } : {},
|
|
173
|
+
responses
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Build the OpenAPI 3.1 document for a route table.
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
* ```ts
|
|
181
|
+
* const openapi = () =>
|
|
182
|
+
* buildOpenApiDocument({ routes: ROUTES, title, version: VERSION, basePath, schemas, tags });
|
|
183
|
+
* ```
|
|
184
|
+
*/
|
|
185
|
+
function buildOpenApiDocument(options) {
|
|
186
|
+
if (!options.version) throw new TypeError("buildOpenApiDocument: a version is required");
|
|
187
|
+
const paths = {};
|
|
188
|
+
for (const spec of options.routes) {
|
|
189
|
+
if (spec.hidden) continue;
|
|
190
|
+
const generated = openApiOperation(spec, options);
|
|
191
|
+
const p = paths[toOpenApiPath(spec.path)] ??= {};
|
|
192
|
+
p[spec.method.toLowerCase()] = options.operation ? options.operation(spec, generated) : generated;
|
|
193
|
+
}
|
|
194
|
+
return {
|
|
195
|
+
openapi: "3.1.0",
|
|
196
|
+
info: {
|
|
197
|
+
title: options.title,
|
|
198
|
+
version: options.version,
|
|
199
|
+
...options.description ? { description: options.description } : {}
|
|
200
|
+
},
|
|
201
|
+
servers: [{ url: options.basePath || "/" }],
|
|
202
|
+
...options.tags?.length ? { tags: options.tags } : {},
|
|
203
|
+
security: [{ basicAuth: [] }, { bearerAuth: [] }],
|
|
204
|
+
paths,
|
|
205
|
+
components: {
|
|
206
|
+
schemas: {
|
|
207
|
+
Error: ERROR_SCHEMA,
|
|
208
|
+
...options.schemas
|
|
209
|
+
},
|
|
210
|
+
securitySchemes: options.securitySchemes ?? {
|
|
211
|
+
basicAuth: {
|
|
212
|
+
type: "http",
|
|
213
|
+
scheme: "basic"
|
|
214
|
+
},
|
|
215
|
+
bearerAuth: {
|
|
216
|
+
type: "http",
|
|
217
|
+
scheme: "bearer",
|
|
218
|
+
...options.bearerDescription ? { description: options.bearerDescription } : {}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
},
|
|
222
|
+
...options.extra
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
//#endregion
|
|
226
|
+
export { ERROR_SCHEMA, buildOpenApiDocument, createRouter, errorResponse, openApiOperation, ref, toOpenApiPath };
|
|
227
|
+
|
|
228
|
+
//# sourceMappingURL=entry-server-router.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entry-server-router.mjs","names":[],"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":"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"}
|
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_base_path = require("./base-path-BJugWLNO.cjs");
|
|
3
|
+
const require_duration = require("./duration-DVA0Fzkx.cjs");
|
|
4
|
+
const require_http = require("./http-B_rTnLW9.cjs");
|
|
5
|
+
//#region src/server/cors.ts
|
|
6
|
+
const DEFAULT_METHODS = "GET,HEAD,PUT,POST,DELETE,PATCH,OPTIONS";
|
|
7
|
+
/**
|
|
8
|
+
* Resolve the value for `Access-Control-Allow-Origin` for this request, or
|
|
9
|
+
* `null` when the origin is not allowed (no CORS headers → the browser blocks).
|
|
10
|
+
*/
|
|
11
|
+
function resolveOrigin(cors, requestOrigin) {
|
|
12
|
+
const { origin } = cors;
|
|
13
|
+
if (origin === "*") return cors.credentials ? requestOrigin ?? null : "*";
|
|
14
|
+
if (requestOrigin === null) return null;
|
|
15
|
+
return (typeof origin === "string" ? origin === requestOrigin : Array.isArray(origin) ? origin.includes(requestOrigin) : origin(requestOrigin)) ? requestOrigin : null;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* `response` itself when its headers can be changed, else a copy that shares
|
|
19
|
+
* its body (`Response.redirect()` and `fetch()` responses have immutable
|
|
20
|
+
* headers).
|
|
21
|
+
*/
|
|
22
|
+
function mutable(response) {
|
|
23
|
+
try {
|
|
24
|
+
response.headers.set("x-xtandard-probe", "1");
|
|
25
|
+
response.headers.delete("x-xtandard-probe");
|
|
26
|
+
return response;
|
|
27
|
+
} catch {
|
|
28
|
+
return new Response(response.body, response);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/** Attach `Access-Control-*` headers to `response` for an allowed cross-origin request. */
|
|
32
|
+
function applyCorsHeaders(request, response, cors) {
|
|
33
|
+
const allowOrigin = resolveOrigin(cors, request.headers.get("origin"));
|
|
34
|
+
if (allowOrigin === null) return response;
|
|
35
|
+
response = mutable(response);
|
|
36
|
+
response.headers.set("access-control-allow-origin", allowOrigin);
|
|
37
|
+
if (cors.credentials) response.headers.set("access-control-allow-credentials", "true");
|
|
38
|
+
if (allowOrigin !== "*") response.headers.append("vary", "Origin");
|
|
39
|
+
return response;
|
|
40
|
+
}
|
|
41
|
+
/** Build the `204` response for a CORS preflight (`OPTIONS`). */
|
|
42
|
+
function preflightResponse(request, cors) {
|
|
43
|
+
const response = new Response(null, { status: 204 });
|
|
44
|
+
applyCorsHeaders(request, response, cors);
|
|
45
|
+
response.headers.set("access-control-allow-methods", (cors.methods ?? []).join(",") || DEFAULT_METHODS);
|
|
46
|
+
const requestedHeaders = request.headers.get("access-control-request-headers");
|
|
47
|
+
response.headers.set("access-control-allow-headers", cors.headers?.join(",") || requestedHeaders || "Content-Type, Authorization");
|
|
48
|
+
if (cors.maxAge !== void 0) response.headers.set("access-control-max-age", String(cors.maxAge));
|
|
49
|
+
return response;
|
|
50
|
+
}
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region src/server/render-index-html.ts
|
|
53
|
+
const IDENTIFIER = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
|
|
54
|
+
const escapeJson = (value) => JSON.stringify(value).replace(/</g, "\\u003c").replace(/>/g, "\\u003e").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
|
|
55
|
+
const escapeHtml = (s) => s.replace(/[&<>"']/g, (c) => `&#${c.charCodeAt(0)};`);
|
|
56
|
+
/** Build the `<base href>` value (always ends in `/`). */
|
|
57
|
+
function baseHref(basePath) {
|
|
58
|
+
return basePath === "" ? "/" : `${basePath}/`;
|
|
59
|
+
}
|
|
60
|
+
function headTags(options) {
|
|
61
|
+
return `<base href="${escapeHtml(baseHref(options.config.basePath))}"><script>window.${options.globalName}=${escapeJson(options.config)}<\/script>`;
|
|
62
|
+
}
|
|
63
|
+
function injectInto(html, options) {
|
|
64
|
+
const tags = headTags(options);
|
|
65
|
+
if (html.includes("<head>")) return html.replace("<head>", () => `<head>${tags}`);
|
|
66
|
+
return tags + html;
|
|
67
|
+
}
|
|
68
|
+
/** Minimal page served when no built UI is present. */
|
|
69
|
+
function fallbackHtml(options) {
|
|
70
|
+
const title = escapeHtml(String(options.config.title));
|
|
71
|
+
const code = "background:#1a1a1a;padding:2px 6px;border-radius:4px";
|
|
72
|
+
return `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">${headTags(options)}<title>${title}</title></head><body style="font-family:system-ui;margin:0;padding:3rem;background:#0a0a0a;color:#e5e5e5"><h1 style="margin:0 0 .5rem">${title}</h1><p style="color:#a3a3a3">The admin UI bundle is not built. Run <code style="${code}">bun run build:ui</code>. The JSON API at <code style="${code}">api/</code> is fully available (<a style="color:#2dd4bf" href="api/openapi.json">OpenAPI</a>).</p></body></html>`;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Read, inject into, and return the SPA index HTML from `uiDir`, or the
|
|
76
|
+
* fallback page when `uiDir` is `undefined` or has no `index.html`.
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```ts
|
|
80
|
+
* const html = await renderIndexHtml(uiDir, {
|
|
81
|
+
* globalName: "__WEBHOOKS_CONFIG__",
|
|
82
|
+
* config: { title, basePath, readonly },
|
|
83
|
+
* });
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
async function renderIndexHtml(uiDir, options) {
|
|
87
|
+
if (!IDENTIFIER.test(options.globalName)) throw new TypeError(`renderIndexHtml: globalName must be an identifier, got "${options.globalName}"`);
|
|
88
|
+
if (uiDir === void 0) return fallbackHtml(options);
|
|
89
|
+
try {
|
|
90
|
+
const [{ readFile }, { join }] = await Promise.all([import("node:fs/promises"), import("node:path")]);
|
|
91
|
+
return injectInto(await readFile(join(uiDir, "index.html"), "utf8"), options);
|
|
92
|
+
} catch {
|
|
93
|
+
return fallbackHtml(options);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
//#endregion
|
|
97
|
+
//#region src/server/static-assets.ts
|
|
98
|
+
/**
|
|
99
|
+
* Serves the bundled SPA's static assets from the UI output directory. Maps file
|
|
100
|
+
* extensions to content types and guards against path traversal.
|
|
101
|
+
*
|
|
102
|
+
* `node:fs` / `node:path` are imported lazily, only when an asset is actually
|
|
103
|
+
* served, so a runtime without them (Cloudflare Workers without
|
|
104
|
+
* `nodejs_compat`) can still import the panel and serve the API — it just
|
|
105
|
+
* passes no `uiDir`.
|
|
106
|
+
*
|
|
107
|
+
* @module
|
|
108
|
+
*/
|
|
109
|
+
const CONTENT_TYPES = {
|
|
110
|
+
".html": "text/html; charset=utf-8",
|
|
111
|
+
".js": "text/javascript; charset=utf-8",
|
|
112
|
+
".mjs": "text/javascript; charset=utf-8",
|
|
113
|
+
".css": "text/css; charset=utf-8",
|
|
114
|
+
".json": "application/json; charset=utf-8",
|
|
115
|
+
".svg": "image/svg+xml",
|
|
116
|
+
".png": "image/png",
|
|
117
|
+
".jpg": "image/jpeg",
|
|
118
|
+
".jpeg": "image/jpeg",
|
|
119
|
+
".gif": "image/gif",
|
|
120
|
+
".webp": "image/webp",
|
|
121
|
+
".ico": "image/x-icon",
|
|
122
|
+
".woff": "font/woff",
|
|
123
|
+
".woff2": "font/woff2",
|
|
124
|
+
".ttf": "font/ttf",
|
|
125
|
+
".map": "application/json; charset=utf-8",
|
|
126
|
+
".txt": "text/plain; charset=utf-8"
|
|
127
|
+
};
|
|
128
|
+
function contentType(path) {
|
|
129
|
+
const dot = path.lastIndexOf(".");
|
|
130
|
+
return CONTENT_TYPES[dot >= 0 ? path.slice(dot).toLowerCase() : ""] ?? "application/octet-stream";
|
|
131
|
+
}
|
|
132
|
+
/** True if the path has a file extension (so a miss should 404 rather than fall through to the SPA). */
|
|
133
|
+
function looksLikeAsset(path) {
|
|
134
|
+
return (path.split("/").pop() ?? "").includes(".");
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Try to serve `path` (base-path-stripped, leading `/`) as a static file from
|
|
138
|
+
* `uiDir`. Returns a `Response`, or `null` if the file does not exist or the
|
|
139
|
+
* path escapes `uiDir`. Files under `assets/` (content-hashed by the bundler)
|
|
140
|
+
* are cached for a year; everything else is `no-cache`.
|
|
141
|
+
*/
|
|
142
|
+
async function serveStaticAsset(uiDir, path) {
|
|
143
|
+
const [{ readFile }, { join, normalize, resolve, sep }] = await Promise.all([import("node:fs/promises"), import("node:path")]);
|
|
144
|
+
const rel = normalize(path).replace(/^(\.\.(\/|\\|$))+/, "");
|
|
145
|
+
const root = resolve(uiDir);
|
|
146
|
+
const full = resolve(join(root, rel));
|
|
147
|
+
if (full !== root && !full.startsWith(root + sep)) return null;
|
|
148
|
+
try {
|
|
149
|
+
const data = await readFile(full);
|
|
150
|
+
return new Response(new Uint8Array(data), {
|
|
151
|
+
status: 200,
|
|
152
|
+
headers: {
|
|
153
|
+
"content-type": contentType(full),
|
|
154
|
+
"cache-control": rel.includes("/assets/") ? "public, max-age=31536000, immutable" : "no-cache"
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
} catch {
|
|
158
|
+
return null;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Locate a product's built SPA. Pass the product module's `import.meta.url`:
|
|
163
|
+
* compiled (the npm-consumer case) the bundle is the sibling `./ui` of the
|
|
164
|
+
* module's `dist/` chunk; run from TypeScript source (examples, `file:`
|
|
165
|
+
* links) it is `<repo>/dist/ui`. Falls back to the compiled-layout path so the
|
|
166
|
+
* "build the UI" hint still fires when nothing is built yet.
|
|
167
|
+
*
|
|
168
|
+
* Extra `candidates` (relative to `moduleUrl`) are tried first. Returns
|
|
169
|
+
* `undefined` when the module URL is not a `file:` URL or the runtime has no
|
|
170
|
+
* `node:fs` (Workers): the panel then serves the API and a fallback page.
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* ```ts
|
|
174
|
+
* const uiDir = options.uiDir ?? resolveUiDir(import.meta.url);
|
|
175
|
+
* ```
|
|
176
|
+
*/
|
|
177
|
+
function resolveUiDir(moduleUrl, candidates = []) {
|
|
178
|
+
const fs = getBuiltin("node:fs");
|
|
179
|
+
const url = getBuiltin("node:url");
|
|
180
|
+
if (!fs || !url) return void 0;
|
|
181
|
+
try {
|
|
182
|
+
const paths = [
|
|
183
|
+
...candidates,
|
|
184
|
+
"./ui",
|
|
185
|
+
"../../dist/ui"
|
|
186
|
+
].map((c) => url.fileURLToPath(new URL(c, moduleUrl)));
|
|
187
|
+
return paths.find((p) => fs.existsSync(p)) ?? paths[candidates.length];
|
|
188
|
+
} catch {
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
/** A Node built-in, synchronously, when the runtime has it (Node ≥ 20.16, Bun, Deno). */
|
|
193
|
+
function getBuiltin(name) {
|
|
194
|
+
return globalThis.process?.getBuiltinModule?.(name);
|
|
195
|
+
}
|
|
196
|
+
//#endregion
|
|
197
|
+
//#region src/server/panel.ts
|
|
198
|
+
/**
|
|
199
|
+
* The panel handler skeleton every product wraps in its `createFetchHandler`:
|
|
200
|
+
* one web-standard `(request) => Promise<Response>` that serves the
|
|
201
|
+
* healthcheck, the product's JSON API, the OpenAPI document, the bundled SPA's
|
|
202
|
+
* static assets and the SPA fallback, under any base path, with optional
|
|
203
|
+
* CORS, plus a uniform `close()` that stops background tasks.
|
|
204
|
+
*
|
|
205
|
+
* Request flow:
|
|
206
|
+
*
|
|
207
|
+
* 1. `OPTIONS` with `cors` set → preflight `204`.
|
|
208
|
+
* 2. `GET|HEAD /healthcheck` → `{ ok: true }`.
|
|
209
|
+
* 3. The product's `api(request, path)`; a non-`null` response wins.
|
|
210
|
+
* 4. `GET|HEAD /api/openapi.json` (and `/openapi.json`) when `openapi` is set.
|
|
211
|
+
* 5. Any other method → `405` (`Allow: GET, HEAD`).
|
|
212
|
+
* 6. A static asset from `uiDir`; a miss on an asset-looking path → `404`.
|
|
213
|
+
* 7. The SPA `index.html` with the bootstrap injected, `cache-control: no-cache`.
|
|
214
|
+
*
|
|
215
|
+
* @module
|
|
216
|
+
*/
|
|
217
|
+
const OPENAPI_PATHS = new Set(["/api/openapi.json", "/openapi.json"]);
|
|
218
|
+
/**
|
|
219
|
+
* Build the panel handler.
|
|
220
|
+
*
|
|
221
|
+
* @example
|
|
222
|
+
* ```ts
|
|
223
|
+
* import { createPanelHandler, resolveUiDir } from "@xtandard/kit/server";
|
|
224
|
+
*
|
|
225
|
+
* const panel = createPanelHandler({
|
|
226
|
+
* basePath: options.basePath,
|
|
227
|
+
* title: options.title ?? "@xtandard/webhooks",
|
|
228
|
+
* globalName: "__WEBHOOKS_CONFIG__",
|
|
229
|
+
* uiDir: options.uiDir ?? resolveUiDir(import.meta.url),
|
|
230
|
+
* api: (request, path) => handleApiRequest(request, path, ctx),
|
|
231
|
+
* openapi: () => buildOpenApiDocument({ basePath, title }),
|
|
232
|
+
* tasks: [dispatcherTask],
|
|
233
|
+
* });
|
|
234
|
+
* Bun.serve({ fetch: panel.fetch });
|
|
235
|
+
* ```
|
|
236
|
+
*/
|
|
237
|
+
function createPanelHandler(options) {
|
|
238
|
+
const basePath = require_base_path.normalizeBasePath(options.basePath);
|
|
239
|
+
const { cors, uiDir } = options;
|
|
240
|
+
const healthcheck = options.healthcheck ?? "/healthcheck";
|
|
241
|
+
const tasks = [...options.tasks ?? []];
|
|
242
|
+
for (const task of tasks) task.start?.();
|
|
243
|
+
let closing;
|
|
244
|
+
async function fetch(request) {
|
|
245
|
+
if (cors && request.method === "OPTIONS") return preflightResponse(request, cors);
|
|
246
|
+
const response = await respond(request);
|
|
247
|
+
return cors ? applyCorsHeaders(request, response, cors) : response;
|
|
248
|
+
}
|
|
249
|
+
async function respond(request) {
|
|
250
|
+
const path = require_base_path.stripBasePath(new URL(request.url).pathname, basePath);
|
|
251
|
+
const read = request.method === "GET" || request.method === "HEAD";
|
|
252
|
+
if (read && healthcheck !== false && path === healthcheck) return require_http.json({ ok: true });
|
|
253
|
+
const api = options.api ? await options.api(request, path) : null;
|
|
254
|
+
if (api) return api;
|
|
255
|
+
if (read && options.openapi && OPENAPI_PATHS.has(path)) return require_http.json(options.openapi());
|
|
256
|
+
if (!read) return new Response("Method Not Allowed", {
|
|
257
|
+
status: 405,
|
|
258
|
+
headers: { allow: "GET, HEAD" }
|
|
259
|
+
});
|
|
260
|
+
if (uiDir !== void 0) {
|
|
261
|
+
const asset = await serveStaticAsset(uiDir, path);
|
|
262
|
+
if (asset) return asset;
|
|
263
|
+
}
|
|
264
|
+
if (path !== "/" && looksLikeAsset(path)) return new Response("Not Found", { status: 404 });
|
|
265
|
+
const html = await renderIndexHtml(uiDir, {
|
|
266
|
+
globalName: options.globalName,
|
|
267
|
+
config: {
|
|
268
|
+
title: options.title,
|
|
269
|
+
basePath,
|
|
270
|
+
readonly: options.readonly ?? false,
|
|
271
|
+
...options.logoUrl !== void 0 ? { logoUrl: options.logoUrl } : {},
|
|
272
|
+
...options.bootstrap?.()
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
return new Response(html, {
|
|
276
|
+
status: 200,
|
|
277
|
+
headers: {
|
|
278
|
+
"content-type": "text/html; charset=utf-8",
|
|
279
|
+
"cache-control": "no-cache"
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
return {
|
|
284
|
+
fetch,
|
|
285
|
+
basePath,
|
|
286
|
+
close() {
|
|
287
|
+
closing ??= Promise.all(tasks.map(async (task) => task.stop())).then(() => void 0);
|
|
288
|
+
return closing;
|
|
289
|
+
}
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* A {@link PanelTask} that runs `run` every `every` (a `Duration`). The timer
|
|
294
|
+
* is `unref()`ed so it never keeps the process alive; a run that rejects is
|
|
295
|
+
* reported, never thrown. `every <= 0` makes a task that does nothing.
|
|
296
|
+
*
|
|
297
|
+
* @example
|
|
298
|
+
* ```ts
|
|
299
|
+
* tasks: [intervalTask("1m", () => engine.sweep(), { source: "@xtandard/entitlements" })]
|
|
300
|
+
* ```
|
|
301
|
+
*/
|
|
302
|
+
function intervalTask(every, run, options = {}) {
|
|
303
|
+
const ms = require_duration.durationToMs(every);
|
|
304
|
+
const onError = options.onError ?? ((error) => console.warn(`[${options.source ?? "@xtandard/kit"}] task failed:`, error));
|
|
305
|
+
let timer;
|
|
306
|
+
return {
|
|
307
|
+
start() {
|
|
308
|
+
if (ms <= 0 || timer) return;
|
|
309
|
+
timer = setInterval(() => {
|
|
310
|
+
Promise.resolve().then(run).catch((error) => onError(error));
|
|
311
|
+
}, ms);
|
|
312
|
+
timer.unref?.();
|
|
313
|
+
},
|
|
314
|
+
stop() {
|
|
315
|
+
if (timer) clearInterval(timer);
|
|
316
|
+
timer = void 0;
|
|
317
|
+
}
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
//#endregion
|
|
321
|
+
exports.HttpError = require_http.HttpError;
|
|
322
|
+
exports.JSON_CONTENT_TYPE = require_http.JSON_CONTENT_TYPE;
|
|
323
|
+
exports.applyCorsHeaders = applyCorsHeaders;
|
|
324
|
+
exports.authenticate = require_http.authenticate;
|
|
325
|
+
exports.authorize = require_http.authorize;
|
|
326
|
+
exports.createPanelHandler = createPanelHandler;
|
|
327
|
+
exports.error = require_http.error;
|
|
328
|
+
exports.intParam = require_http.intParam;
|
|
329
|
+
exports.intervalTask = intervalTask;
|
|
330
|
+
exports.json = require_http.json;
|
|
331
|
+
exports.looksLikeAsset = looksLikeAsset;
|
|
332
|
+
exports.mapError = require_http.mapError;
|
|
333
|
+
exports.match = require_http.match;
|
|
334
|
+
exports.methodNotAllowed = require_http.methodNotAllowed;
|
|
335
|
+
exports.noContent = require_http.noContent;
|
|
336
|
+
exports.normalizeBasePath = require_base_path.normalizeBasePath;
|
|
337
|
+
exports.preflightResponse = preflightResponse;
|
|
338
|
+
exports.renderIndexHtml = renderIndexHtml;
|
|
339
|
+
exports.requireOneOf = require_http.requireOneOf;
|
|
340
|
+
exports.resolveUiDir = resolveUiDir;
|
|
341
|
+
exports.serveStaticAsset = serveStaticAsset;
|
|
342
|
+
exports.stripBasePath = require_base_path.stripBasePath;
|
|
343
|
+
|
|
344
|
+
//# sourceMappingURL=entry-server.cjs.map
|