@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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Santiago Montoya
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,72 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @xtandard/kit
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The shared building blocks of the xtandard products: one implementation of the infrastructure that
|
|
4
|
+
[`@xtandard/webhooks`](https://github.com/xantiagoma/xtandard-webhooks),
|
|
5
|
+
[`@xtandard/flags`](https://github.com/xantiagoma/xtandard-flags),
|
|
6
|
+
[`@xtandard/audit`](https://github.com/xantiagoma/xtandard-audit),
|
|
7
|
+
[`@xtandard/links`](https://github.com/xantiagoma/xtandard-links) and
|
|
8
|
+
[`@xtandard/entitlements`](https://github.com/xantiagoma/xtandard-entitlements) used to copy from each
|
|
9
|
+
other. Fix a bug here once, and every product gets it.
|
|
10
|
+
|
|
11
|
+
> **Status: in development (0.x).** The products depend on this package directly. You only need it
|
|
12
|
+
> yourself if you are building an xtandard-style product.
|
|
13
|
+
|
|
14
|
+
## Contents
|
|
15
|
+
|
|
16
|
+
- [What's inside](#whats-inside)
|
|
17
|
+
- [Documentation](#documentation)
|
|
18
|
+
- [The xtandard ecosystem](#the-xtandard-ecosystem)
|
|
19
|
+
- [License](#license)
|
|
20
|
+
|
|
21
|
+
## What's inside
|
|
22
|
+
|
|
23
|
+
Each building block has its own subpath, and every database client, framework and build tool is an
|
|
24
|
+
**optional peer**. Importing one subpath never loads another's dependencies.
|
|
25
|
+
|
|
26
|
+
| Subpath | What it is |
|
|
27
|
+
| --------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------- |
|
|
28
|
+
| `@xtandard/kit/storage` (+ `/memory`, `/file`, `/sqlite`, `/libsql`, `/postgres`, `/mongodb`, `/redis`, `/cloudflare-kv`, `/unstorage`, `/drizzle`) | The KV storage contract with watch and compare-and-swap capabilities, plus ten drivers |
|
|
29
|
+
| `@xtandard/kit/storage/testing` | The storage conformance suite, runnable under vitest or `bun test` |
|
|
30
|
+
| `@xtandard/kit/drizzle/{pg,mysql,sqlite}` | Drizzle KV table factories |
|
|
31
|
+
| `@xtandard/kit/auth`, `/authorization` (+ `none`, `basic`, `roles`, `delegated`) | Authentication and authorization providers |
|
|
32
|
+
| `@xtandard/kit/hooks`, `/hooks/log` | The before/after hook runner and the log hook |
|
|
33
|
+
| `@xtandard/kit/server`, `/server/router` | Panel/SPA serving, CORS, base path, the router and the OpenAPI generator |
|
|
34
|
+
| `@xtandard/kit/tokens` | Scoped HMAC tokens for portals and embeds |
|
|
35
|
+
| `@xtandard/kit/adapters/{bun,node,express,hono,elysia,next}` | Framework adapters and the Fetch↔Node bridge |
|
|
36
|
+
| `@xtandard/kit/cli` | CLI plumbing: env parsing, driver selection from env, auth from env, `serve` |
|
|
37
|
+
| `@xtandard/kit/util`, `/testing` | Durations, canonical JSON, ids, validation core, test clock |
|
|
38
|
+
| `@xtandard/kit/ui`, `/ui/embed`, `/ui/styles.css` | The React admin shell, primitives, theme, and the embed factory |
|
|
39
|
+
| `@xtandard/kit/build`, `xtandard-kit` bin | Build tooling: config factories, embed CSS scoping, the API-surface check |
|
|
40
|
+
| `@xtandard/kit/site` | Docs-site tooling (Starlight + TypeDoc) |
|
|
41
|
+
|
|
42
|
+
The products also call reusable GitHub workflows from this repo (`.github/workflows/{ci,pages,docker,release-prepare}.yml`).
|
|
43
|
+
|
|
44
|
+
## Documentation
|
|
45
|
+
|
|
46
|
+
- [`PLAN.md`](PLAN.md): what goes in the kit and how the products consume it
|
|
47
|
+
- [`docs/ADR/`](docs/ADR/): architecture decisions
|
|
48
|
+
- [`docs/research/inventory.md`](docs/research/inventory.md): the inventory of the five copies this
|
|
49
|
+
kit replaces
|
|
50
|
+
- Docs site: https://me.xantiagoma.com/xtandard-kit/
|
|
51
|
+
|
|
52
|
+
## The xtandard ecosystem
|
|
53
|
+
|
|
54
|
+
`@xtandard/kit` is the shared building block behind the xtandard products. The products depend on it
|
|
55
|
+
directly, so you never install it yourself to use one of them. Every project below is open source and
|
|
56
|
+
MIT-licensed.
|
|
57
|
+
|
|
58
|
+
| Project | What it is | Links |
|
|
59
|
+
| ---------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
60
|
+
| **`@xtandard/kit`** (this package) | The shared building blocks of the xtandard products: storage drivers and conformance suite, auth, HTTP plumbing, adapters, admin shell and tooling | [Docs](https://me.xantiagoma.com/xtandard-kit/) · [GitHub](https://github.com/xantiagoma/xtandard-kit) · [npm](https://www.npmjs.com/package/@xtandard/kit) |
|
|
61
|
+
| **`@xtandard/lib`** | Lightweight, type-safe TypeScript utilities with a zero-dependency core | [Docs](https://me.xantiagoma.com/xtandard/) · [GitHub](https://github.com/xantiagoma/xtandard) · [npm](https://www.npmjs.com/package/@xtandard/lib) |
|
|
62
|
+
| **`@xtandard/flags`** | A self-hosted, embeddable, OpenFeature-compatible feature-flag control plane with pluggable storage | [Docs](https://me.xantiagoma.com/xtandard-flags/) · [GitHub](https://github.com/xantiagoma/xtandard-flags) · [npm](https://www.npmjs.com/package/@xtandard/flags) |
|
|
63
|
+
| **`@xtandard/webhooks`** | A self-hosted, embeddable, Standard Webhooks-compliant outbound-webhooks control plane: a Svix alternative as a library | [Docs](https://me.xantiagoma.com/xtandard-webhooks/) · [GitHub](https://github.com/xantiagoma/xtandard-webhooks) · [npm](https://www.npmjs.com/package/@xtandard/webhooks) |
|
|
64
|
+
| **`@xtandard/audit`** | A self-hosted, embeddable, tamper-evident audit-log control plane for B2B SaaS: a WorkOS Audit Logs alternative as a library | [Docs](https://me.xantiagoma.com/xtandard-audit/) · [GitHub](https://github.com/xantiagoma/xtandard-audit) · [npm](https://www.npmjs.com/package/@xtandard/audit) |
|
|
65
|
+
| **`@xtandard/links`** | Self-hosted, embeddable branded short links with click analytics, conversion attribution and deep links: a Dub / Bitly alternative as a library | [Docs](https://me.xantiagoma.com/xtandard-links/) · [GitHub](https://github.com/xantiagoma/xtandard-links) · [npm](https://www.npmjs.com/package/@xtandard/links) |
|
|
66
|
+
| **`@xtandard/xyte`** | A Zyte API-compatible `/v1/extract` client and server that runs on any proxy provider, or none | [Docs](https://me.xantiagoma.com/xyte/) · [GitHub](https://github.com/xantiagoma/xyte) · [npm](https://www.npmjs.com/package/@xtandard/xyte) |
|
|
67
|
+
| **xtandard-image** | A self-hosted image and video processing server in Go and libvips: imgproxy-compatible URLs plus the imgix, Cloudinary, ImageKit, Cloudflare and Thumbor dialects, with a TypeScript client (`@xtandard/image`) | [Docs](https://me.xantiagoma.com/xtandard-image/) · [GitHub](https://github.com/xantiagoma/xtandard-image) · [npm](https://www.npmjs.com/package/@xtandard/image) |
|
|
68
|
+
| **`@xtandard/entitlements`** | An embeddable entitlements, plans and usage-metering engine: typed catalog, atomic metering, any billing provider, admin UI and customer portal | [Docs](https://me.xantiagoma.com/xtandard-entitlements/) · [GitHub](https://github.com/xantiagoma/xtandard-entitlements) · [npm](https://www.npmjs.com/package/@xtandard/entitlements) |
|
|
69
|
+
|
|
70
|
+
## License
|
|
71
|
+
|
|
72
|
+
[MIT](LICENSE)
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
//#region src/server/base-path.ts
|
|
2
|
+
/**
|
|
3
|
+
* Base-path helpers. The panel can be mounted under any prefix (`/webhooks`,
|
|
4
|
+
* `/admin/webhooks`, ...). These normalize the configured base path and strip it
|
|
5
|
+
* from incoming request paths so routing is prefix-agnostic.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
/** Normalize a base path to either `""` (root) or `/segment` with no trailing slash. */
|
|
10
|
+
function normalizeBasePath(basePath) {
|
|
11
|
+
if (!basePath || basePath === "/") return "";
|
|
12
|
+
let p = basePath.trim();
|
|
13
|
+
if (!p.startsWith("/")) p = "/" + p;
|
|
14
|
+
if (p.endsWith("/")) p = p.slice(0, -1);
|
|
15
|
+
return p;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Strip the (normalized) base path from a pathname. Returns a path that always
|
|
19
|
+
* starts with `/`. If the pathname does not start with the base path it is
|
|
20
|
+
* returned unchanged (the host framework may already have stripped the mount).
|
|
21
|
+
*/
|
|
22
|
+
function stripBasePath(pathname, basePath) {
|
|
23
|
+
if (basePath === "") return pathname || "/";
|
|
24
|
+
if (pathname === basePath) return "/";
|
|
25
|
+
if (pathname.startsWith(basePath + "/")) return pathname.slice(basePath.length) || "/";
|
|
26
|
+
return pathname || "/";
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
Object.defineProperty(exports, "normalizeBasePath", {
|
|
30
|
+
enumerable: true,
|
|
31
|
+
get: function() {
|
|
32
|
+
return normalizeBasePath;
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
Object.defineProperty(exports, "stripBasePath", {
|
|
36
|
+
enumerable: true,
|
|
37
|
+
get: function() {
|
|
38
|
+
return stripBasePath;
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
//# sourceMappingURL=base-path-BJugWLNO.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-path-BJugWLNO.cjs","names":[],"sources":["../src/server/base-path.ts"],"sourcesContent":["/**\n * Base-path helpers. The panel can be mounted under any prefix (`/webhooks`,\n * `/admin/webhooks`, ...). These normalize the configured base path and strip it\n * from incoming request paths so routing is prefix-agnostic.\n *\n * @module\n */\n\n/** Normalize a base path to either `\"\"` (root) or `/segment` with no trailing slash. */\nexport function normalizeBasePath(basePath: string | undefined): string {\n if (!basePath || basePath === \"/\") return \"\";\n let p = basePath.trim();\n if (!p.startsWith(\"/\")) p = \"/\" + p;\n if (p.endsWith(\"/\")) p = p.slice(0, -1);\n return p;\n}\n\n/**\n * Strip the (normalized) base path from a pathname. Returns a path that always\n * starts with `/`. If the pathname does not start with the base path it is\n * returned unchanged (the host framework may already have stripped the mount).\n */\nexport function stripBasePath(pathname: string, basePath: string): string {\n if (basePath === \"\") return pathname || \"/\";\n if (pathname === basePath) return \"/\";\n if (pathname.startsWith(basePath + \"/\")) {\n const rest = pathname.slice(basePath.length);\n return rest || \"/\";\n }\n return pathname || \"/\";\n}\n"],"mappings":";;;;;;;;;AASA,SAAgB,kBAAkB,UAAsC;CACtE,IAAI,CAAC,YAAY,aAAa,KAAK,OAAO;CAC1C,IAAI,IAAI,SAAS,KAAK;CACtB,IAAI,CAAC,EAAE,WAAW,GAAG,GAAG,IAAI,MAAM;CAClC,IAAI,EAAE,SAAS,GAAG,GAAG,IAAI,EAAE,MAAM,GAAG,EAAE;CACtC,OAAO;AACT;;;;;;AAOA,SAAgB,cAAc,UAAkB,UAA0B;CACxE,IAAI,aAAa,IAAI,OAAO,YAAY;CACxC,IAAI,aAAa,UAAU,OAAO;CAClC,IAAI,SAAS,WAAW,WAAW,GAAG,GAEpC,OADa,SAAS,MAAM,SAAS,MAC3B,KAAK;CAEjB,OAAO,YAAY;AACrB"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
//#region src/server/base-path.ts
|
|
2
|
+
/**
|
|
3
|
+
* Base-path helpers. The panel can be mounted under any prefix (`/webhooks`,
|
|
4
|
+
* `/admin/webhooks`, ...). These normalize the configured base path and strip it
|
|
5
|
+
* from incoming request paths so routing is prefix-agnostic.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
/** Normalize a base path to either `""` (root) or `/segment` with no trailing slash. */
|
|
10
|
+
function normalizeBasePath(basePath) {
|
|
11
|
+
if (!basePath || basePath === "/") return "";
|
|
12
|
+
let p = basePath.trim();
|
|
13
|
+
if (!p.startsWith("/")) p = "/" + p;
|
|
14
|
+
if (p.endsWith("/")) p = p.slice(0, -1);
|
|
15
|
+
return p;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Strip the (normalized) base path from a pathname. Returns a path that always
|
|
19
|
+
* starts with `/`. If the pathname does not start with the base path it is
|
|
20
|
+
* returned unchanged (the host framework may already have stripped the mount).
|
|
21
|
+
*/
|
|
22
|
+
function stripBasePath(pathname, basePath) {
|
|
23
|
+
if (basePath === "") return pathname || "/";
|
|
24
|
+
if (pathname === basePath) return "/";
|
|
25
|
+
if (pathname.startsWith(basePath + "/")) return pathname.slice(basePath.length) || "/";
|
|
26
|
+
return pathname || "/";
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
export { stripBasePath as n, normalizeBasePath as t };
|
|
30
|
+
|
|
31
|
+
//# sourceMappingURL=base-path-CDb4In5E.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-path-CDb4In5E.mjs","names":[],"sources":["../src/server/base-path.ts"],"sourcesContent":["/**\n * Base-path helpers. The panel can be mounted under any prefix (`/webhooks`,\n * `/admin/webhooks`, ...). These normalize the configured base path and strip it\n * from incoming request paths so routing is prefix-agnostic.\n *\n * @module\n */\n\n/** Normalize a base path to either `\"\"` (root) or `/segment` with no trailing slash. */\nexport function normalizeBasePath(basePath: string | undefined): string {\n if (!basePath || basePath === \"/\") return \"\";\n let p = basePath.trim();\n if (!p.startsWith(\"/\")) p = \"/\" + p;\n if (p.endsWith(\"/\")) p = p.slice(0, -1);\n return p;\n}\n\n/**\n * Strip the (normalized) base path from a pathname. Returns a path that always\n * starts with `/`. If the pathname does not start with the base path it is\n * returned unchanged (the host framework may already have stripped the mount).\n */\nexport function stripBasePath(pathname: string, basePath: string): string {\n if (basePath === \"\") return pathname || \"/\";\n if (pathname === basePath) return \"/\";\n if (pathname.startsWith(basePath + \"/\")) {\n const rest = pathname.slice(basePath.length);\n return rest || \"/\";\n }\n return pathname || \"/\";\n}\n"],"mappings":";;;;;;;;;AASA,SAAgB,kBAAkB,UAAsC;CACtE,IAAI,CAAC,YAAY,aAAa,KAAK,OAAO;CAC1C,IAAI,IAAI,SAAS,KAAK;CACtB,IAAI,CAAC,EAAE,WAAW,GAAG,GAAG,IAAI,MAAM;CAClC,IAAI,EAAE,SAAS,GAAG,GAAG,IAAI,EAAE,MAAM,GAAG,EAAE;CACtC,OAAO;AACT;;;;;;AAOA,SAAgB,cAAc,UAAkB,UAA0B;CACxE,IAAI,aAAa,IAAI,OAAO,YAAY;CACxC,IAAI,aAAa,UAAU,OAAO;CAClC,IAAI,SAAS,WAAW,WAAW,GAAG,GAEpC,OADa,SAAS,MAAM,SAAS,MAC3B,KAAK;CAEjB,OAAO,YAAY;AACrB"}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
|
|
2
|
+
import { randomBytes, scrypt, timingSafeEqual } from "node:crypto";
|
|
3
|
+
//#region src/auth/basic.ts
|
|
4
|
+
/**
|
|
5
|
+
* HTTP Basic authentication {@link AuthProvider}.
|
|
6
|
+
*
|
|
7
|
+
* Parses the `Authorization: Basic <base64>` header, looks the username up in a
|
|
8
|
+
* configured user list, and verifies the supplied password using one of three
|
|
9
|
+
* credential modes (in order of preference):
|
|
10
|
+
*
|
|
11
|
+
* 1. A custom `passwordVerifier(username, password)` callback — for delegating
|
|
12
|
+
* to your own user store.
|
|
13
|
+
* 2. A `passwordHash` produced by {@link hashPassword} — scrypt with a random
|
|
14
|
+
* salt, verified in constant time. **Recommended for production.**
|
|
15
|
+
* 3. A plain `password` field — **development only**. Never ship real
|
|
16
|
+
* credentials as plaintext; they are compared in constant time but stored as
|
|
17
|
+
* cleartext in your config.
|
|
18
|
+
*
|
|
19
|
+
* On success the matched user becomes a {@link Principal}; on any failure
|
|
20
|
+
* (missing/malformed header, unknown user, bad password) `authenticate` returns
|
|
21
|
+
* `null`. {@link AuthProvider.challenge} emits a `401` with a
|
|
22
|
+
* `WWW-Authenticate: Basic realm="…"` header so browsers prompt for credentials.
|
|
23
|
+
*
|
|
24
|
+
* Password hashing uses Node's `node:crypto` `scrypt`, which is available in
|
|
25
|
+
* both Node and Bun — no Bun-only APIs and no extra dependencies.
|
|
26
|
+
*
|
|
27
|
+
* @module
|
|
28
|
+
*/
|
|
29
|
+
var basic_exports = /* @__PURE__ */ __exportAll({
|
|
30
|
+
basicAuth: () => basicAuth,
|
|
31
|
+
hashPassword: () => hashPassword,
|
|
32
|
+
verifyPassword: () => verifyPassword
|
|
33
|
+
});
|
|
34
|
+
/** scrypt key length (bytes) used by {@link hashPassword}. */
|
|
35
|
+
const KEY_LENGTH = 64;
|
|
36
|
+
/** Salt length (bytes) used by {@link hashPassword}. */
|
|
37
|
+
const SALT_LENGTH = 16;
|
|
38
|
+
/** Prefix identifying a {@link hashPassword} digest. */
|
|
39
|
+
const SCRYPT_PREFIX = "scrypt";
|
|
40
|
+
const scryptAsync = (password, salt, keylen) => new Promise((resolve, reject) => {
|
|
41
|
+
scrypt(password, salt, keylen, (err, derivedKey) => {
|
|
42
|
+
if (err) reject(err);
|
|
43
|
+
else resolve(derivedKey);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
/** Lowercase hex encoding of a buffer. */
|
|
47
|
+
const toHex = (buf) => buf.toString("hex");
|
|
48
|
+
/**
|
|
49
|
+
* Hash a password with scrypt and a fresh random salt.
|
|
50
|
+
*
|
|
51
|
+
* The returned string is self-describing and safe to store in config or a
|
|
52
|
+
* database: `scrypt$<saltHex>$<hashHex>`. Pass it back to
|
|
53
|
+
* {@link verifyPassword} (or supply it as a user's `passwordHash`) to check a
|
|
54
|
+
* candidate password.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```ts
|
|
58
|
+
* const stored = await hashPassword("correct horse battery staple");
|
|
59
|
+
* // → "scrypt$<32 hex chars>$<128 hex chars>"
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
async function hashPassword(password) {
|
|
63
|
+
const salt = randomBytes(SALT_LENGTH);
|
|
64
|
+
const derived = await scryptAsync(password, salt, KEY_LENGTH);
|
|
65
|
+
return `${SCRYPT_PREFIX}$${toHex(salt)}$${toHex(derived)}`;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Verify a candidate `password` against a digest produced by
|
|
69
|
+
* {@link hashPassword}.
|
|
70
|
+
*
|
|
71
|
+
* Re-derives the scrypt hash using the stored salt and compares it to the stored
|
|
72
|
+
* hash with `crypto.timingSafeEqual` (constant time). Returns `false` — rather
|
|
73
|
+
* than throwing — for malformed or unrecognized digests.
|
|
74
|
+
*/
|
|
75
|
+
async function verifyPassword(password, stored) {
|
|
76
|
+
const parts = stored.split("$");
|
|
77
|
+
if (parts.length !== 3 || parts[0] !== SCRYPT_PREFIX) return false;
|
|
78
|
+
const saltHex = parts[1];
|
|
79
|
+
const hashHex = parts[2];
|
|
80
|
+
if (!saltHex || !hashHex) return false;
|
|
81
|
+
let salt;
|
|
82
|
+
let expected;
|
|
83
|
+
try {
|
|
84
|
+
salt = Buffer.from(saltHex, "hex");
|
|
85
|
+
expected = Buffer.from(hashHex, "hex");
|
|
86
|
+
} catch {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
if (salt.length === 0 || expected.length === 0) return false;
|
|
90
|
+
const derived = await scryptAsync(password, salt, expected.length);
|
|
91
|
+
if (derived.length !== expected.length) return false;
|
|
92
|
+
return timingSafeEqual(derived, expected);
|
|
93
|
+
}
|
|
94
|
+
/** Constant-time string comparison that does not leak length via early exit. */
|
|
95
|
+
function constantTimeEquals(a, b) {
|
|
96
|
+
const bufA = Buffer.from(a, "utf8");
|
|
97
|
+
const bufB = Buffer.from(b, "utf8");
|
|
98
|
+
if (bufA.length !== bufB.length) {
|
|
99
|
+
timingSafeEqual(bufA, bufA);
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
return timingSafeEqual(bufA, bufB);
|
|
103
|
+
}
|
|
104
|
+
/** Decode the `Authorization: Basic <base64>` header, or `null` if absent/malformed. */
|
|
105
|
+
function parseBasicHeader(request) {
|
|
106
|
+
const header = request.headers.get("authorization");
|
|
107
|
+
if (!header) return null;
|
|
108
|
+
const [scheme, encoded] = header.split(" ", 2);
|
|
109
|
+
if (!scheme || scheme.toLowerCase() !== "basic" || !encoded) return null;
|
|
110
|
+
let decoded;
|
|
111
|
+
try {
|
|
112
|
+
decoded = Buffer.from(encoded, "base64").toString("utf8");
|
|
113
|
+
} catch {
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
const sep = decoded.indexOf(":");
|
|
117
|
+
if (sep < 0) return null;
|
|
118
|
+
return {
|
|
119
|
+
username: decoded.slice(0, sep),
|
|
120
|
+
password: decoded.slice(sep + 1)
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
/** Build the {@link Principal} for a successfully authenticated user. */
|
|
124
|
+
function principalFor(user) {
|
|
125
|
+
return {
|
|
126
|
+
id: user.id ?? user.username,
|
|
127
|
+
name: user.username,
|
|
128
|
+
...user.email !== void 0 ? { email: user.email } : {},
|
|
129
|
+
...user.roles !== void 0 ? { roles: user.roles } : {}
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Create an HTTP Basic {@link AuthProvider}.
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* ```ts
|
|
137
|
+
* import { basicAuth, hashPassword } from "@xtandard/kit/auth/basic";
|
|
138
|
+
*
|
|
139
|
+
* const auth = basicAuth({
|
|
140
|
+
* realm: "xtandard-webhooks",
|
|
141
|
+
* users: [
|
|
142
|
+
* { username: "admin", passwordHash: await hashPassword("s3cret"), roles: ["admin"] },
|
|
143
|
+
* ],
|
|
144
|
+
* });
|
|
145
|
+
* ```
|
|
146
|
+
*/
|
|
147
|
+
function basicAuth(options) {
|
|
148
|
+
const realm = options.realm ?? "xtandard";
|
|
149
|
+
const usersByName = /* @__PURE__ */ new Map();
|
|
150
|
+
for (const user of options.users) usersByName.set(user.username, user);
|
|
151
|
+
return {
|
|
152
|
+
async authenticate(request) {
|
|
153
|
+
const creds = parseBasicHeader(request);
|
|
154
|
+
if (!creds) return null;
|
|
155
|
+
const user = usersByName.get(creds.username);
|
|
156
|
+
if (!user) {
|
|
157
|
+
if (options.passwordVerifier) await options.passwordVerifier(creds.username, creds.password);
|
|
158
|
+
return null;
|
|
159
|
+
}
|
|
160
|
+
if (options.passwordVerifier) return await options.passwordVerifier(creds.username, creds.password) ? principalFor(user) : null;
|
|
161
|
+
if (user.passwordHash !== void 0) return await verifyPassword(creds.password, user.passwordHash) ? principalFor(user) : null;
|
|
162
|
+
if (user.password !== void 0) return constantTimeEquals(creds.password, user.password) ? principalFor(user) : null;
|
|
163
|
+
return null;
|
|
164
|
+
},
|
|
165
|
+
challenge(_request) {
|
|
166
|
+
return new Response("Unauthorized", {
|
|
167
|
+
status: 401,
|
|
168
|
+
headers: { "WWW-Authenticate": `Basic realm="${realm}"` }
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
//#endregion
|
|
174
|
+
export { verifyPassword as i, basic_exports as n, hashPassword as r, basicAuth as t };
|
|
175
|
+
|
|
176
|
+
//# sourceMappingURL=basic-Qtriv0xS.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"basic-Qtriv0xS.mjs","names":[],"sources":["../src/auth/basic.ts"],"sourcesContent":["/**\n * HTTP Basic authentication {@link AuthProvider}.\n *\n * Parses the `Authorization: Basic <base64>` header, looks the username up in a\n * configured user list, and verifies the supplied password using one of three\n * credential modes (in order of preference):\n *\n * 1. A custom `passwordVerifier(username, password)` callback — for delegating\n * to your own user store.\n * 2. A `passwordHash` produced by {@link hashPassword} — scrypt with a random\n * salt, verified in constant time. **Recommended for production.**\n * 3. A plain `password` field — **development only**. Never ship real\n * credentials as plaintext; they are compared in constant time but stored as\n * cleartext in your config.\n *\n * On success the matched user becomes a {@link Principal}; on any failure\n * (missing/malformed header, unknown user, bad password) `authenticate` returns\n * `null`. {@link AuthProvider.challenge} emits a `401` with a\n * `WWW-Authenticate: Basic realm=\"…\"` header so browsers prompt for credentials.\n *\n * Password hashing uses Node's `node:crypto` `scrypt`, which is available in\n * both Node and Bun — no Bun-only APIs and no extra dependencies.\n *\n * @module\n */\n\nimport { randomBytes, scrypt as scryptCb, timingSafeEqual } from \"node:crypto\";\nimport type { AuthProvider, Principal } from \"./contract.ts\";\n\n/** scrypt key length (bytes) used by {@link hashPassword}. */\nconst KEY_LENGTH = 64;\n/** Salt length (bytes) used by {@link hashPassword}. */\nconst SALT_LENGTH = 16;\n/** Prefix identifying a {@link hashPassword} digest. */\nconst SCRYPT_PREFIX = \"scrypt\";\n\nconst scryptAsync = (password: string, salt: Buffer, keylen: number): Promise<Buffer> =>\n new Promise((resolve, reject) => {\n scryptCb(password, salt, keylen, (err, derivedKey) => {\n if (err) reject(err);\n else resolve(derivedKey);\n });\n });\n\n/** Lowercase hex encoding of a buffer. */\nconst toHex = (buf: Buffer): string => buf.toString(\"hex\");\n\n/**\n * Hash a password with scrypt and a fresh random salt.\n *\n * The returned string is self-describing and safe to store in config or a\n * database: `scrypt$<saltHex>$<hashHex>`. Pass it back to\n * {@link verifyPassword} (or supply it as a user's `passwordHash`) to check a\n * candidate password.\n *\n * @example\n * ```ts\n * const stored = await hashPassword(\"correct horse battery staple\");\n * // → \"scrypt$<32 hex chars>$<128 hex chars>\"\n * ```\n */\nexport async function hashPassword(password: string): Promise<string> {\n const salt = randomBytes(SALT_LENGTH);\n const derived = await scryptAsync(password, salt, KEY_LENGTH);\n return `${SCRYPT_PREFIX}$${toHex(salt)}$${toHex(derived)}`;\n}\n\n/**\n * Verify a candidate `password` against a digest produced by\n * {@link hashPassword}.\n *\n * Re-derives the scrypt hash using the stored salt and compares it to the stored\n * hash with `crypto.timingSafeEqual` (constant time). Returns `false` — rather\n * than throwing — for malformed or unrecognized digests.\n */\nexport async function verifyPassword(password: string, stored: string): Promise<boolean> {\n const parts = stored.split(\"$\");\n if (parts.length !== 3 || parts[0] !== SCRYPT_PREFIX) return false;\n const saltHex = parts[1];\n const hashHex = parts[2];\n if (!saltHex || !hashHex) return false;\n\n let salt: Buffer;\n let expected: Buffer;\n try {\n salt = Buffer.from(saltHex, \"hex\");\n expected = Buffer.from(hashHex, \"hex\");\n } catch {\n return false;\n }\n if (salt.length === 0 || expected.length === 0) return false;\n\n const derived = await scryptAsync(password, salt, expected.length);\n if (derived.length !== expected.length) return false;\n return timingSafeEqual(derived, expected);\n}\n\n/** A configured user for {@link basicAuth}. */\nexport interface BasicAuthUser {\n /** The login name, matched against the Basic credentials. */\n username: string;\n /**\n * A digest produced by {@link hashPassword} (`scrypt$<salt>$<hash>`).\n * Preferred for production.\n */\n passwordHash?: string;\n /**\n * A plaintext password. **Development only** — prefer `passwordHash`. Compared\n * in constant time but stored as cleartext in your config.\n */\n password?: string;\n /** Roles attached to the resulting {@link Principal}. */\n roles?: string[];\n /** Email attached to the resulting {@link Principal}. */\n email?: string;\n /** Principal id. Defaults to {@link BasicAuthUser.username} when omitted. */\n id?: string;\n}\n\n/** Options for {@link basicAuth}. */\nexport interface BasicAuthOptions {\n /** The known users. */\n users: BasicAuthUser[];\n /**\n * Realm advertised in the `WWW-Authenticate` header on challenge.\n * @default \"xtandard\" (products pass their own, e.g. `\"xtandard-webhooks\"`)\n */\n realm?: string;\n /**\n * Custom verifier. When supplied it takes precedence over `passwordHash` and\n * `password` for matched users — delegate to your own credential store and\n * return `true` to accept.\n */\n passwordVerifier?: (username: string, password: string) => Promise<boolean> | boolean;\n}\n\n/** Constant-time string comparison that does not leak length via early exit. */\nfunction constantTimeEquals(a: string, b: string): boolean {\n const bufA = Buffer.from(a, \"utf8\");\n const bufB = Buffer.from(b, \"utf8\");\n // timingSafeEqual requires equal lengths; hash to a fixed width first so the\n // comparison time does not depend on the inputs.\n if (bufA.length !== bufB.length) {\n // Still perform a comparison to keep timing uniform, then fail.\n timingSafeEqual(bufA, bufA);\n return false;\n }\n return timingSafeEqual(bufA, bufB);\n}\n\n/** Result of parsing an `Authorization: Basic` header. */\ninterface BasicCredentials {\n username: string;\n password: string;\n}\n\n/** Decode the `Authorization: Basic <base64>` header, or `null` if absent/malformed. */\nfunction parseBasicHeader(request: Request): BasicCredentials | null {\n const header = request.headers.get(\"authorization\");\n if (!header) return null;\n const [scheme, encoded] = header.split(\" \", 2);\n if (!scheme || scheme.toLowerCase() !== \"basic\" || !encoded) return null;\n\n let decoded: string;\n try {\n decoded = Buffer.from(encoded, \"base64\").toString(\"utf8\");\n } catch {\n return null;\n }\n const sep = decoded.indexOf(\":\");\n if (sep < 0) return null;\n return { username: decoded.slice(0, sep), password: decoded.slice(sep + 1) };\n}\n\n/** Build the {@link Principal} for a successfully authenticated user. */\nfunction principalFor(user: BasicAuthUser): Principal {\n return {\n id: user.id ?? user.username,\n name: user.username,\n ...(user.email !== undefined ? { email: user.email } : {}),\n ...(user.roles !== undefined ? { roles: user.roles } : {}),\n };\n}\n\n/**\n * Create an HTTP Basic {@link AuthProvider}.\n *\n * @example\n * ```ts\n * import { basicAuth, hashPassword } from \"@xtandard/kit/auth/basic\";\n *\n * const auth = basicAuth({\n * realm: \"xtandard-webhooks\",\n * users: [\n * { username: \"admin\", passwordHash: await hashPassword(\"s3cret\"), roles: [\"admin\"] },\n * ],\n * });\n * ```\n */\nexport function basicAuth(options: BasicAuthOptions): AuthProvider {\n const realm = options.realm ?? \"xtandard\";\n const usersByName = new Map<string, BasicAuthUser>();\n for (const user of options.users) usersByName.set(user.username, user);\n\n return {\n async authenticate(request: Request): Promise<Principal | null> {\n const creds = parseBasicHeader(request);\n if (!creds) return null;\n\n const user = usersByName.get(creds.username);\n if (!user) {\n // Run a dummy verification to keep timing roughly uniform for unknown\n // users versus known users.\n if (options.passwordVerifier) {\n await options.passwordVerifier(creds.username, creds.password);\n }\n return null;\n }\n\n // (a) custom verifier wins.\n if (options.passwordVerifier) {\n const ok = await options.passwordVerifier(creds.username, creds.password);\n return ok ? principalFor(user) : null;\n }\n\n // (b) scrypt hash.\n if (user.passwordHash !== undefined) {\n const ok = await verifyPassword(creds.password, user.passwordHash);\n return ok ? principalFor(user) : null;\n }\n\n // (c) dev-only plaintext.\n if (user.password !== undefined) {\n const ok = constantTimeEquals(creds.password, user.password);\n return ok ? principalFor(user) : null;\n }\n\n return null;\n },\n\n challenge(_request: Request): Response {\n return new Response(\"Unauthorized\", {\n status: 401,\n headers: { \"WWW-Authenticate\": `Basic realm=\"${realm}\"` },\n });\n },\n };\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
const require_chunk = require("./chunk-DakpK96I.cjs");
|
|
2
|
+
let node_crypto = require("node:crypto");
|
|
3
|
+
//#region src/auth/basic.ts
|
|
4
|
+
/**
|
|
5
|
+
* HTTP Basic authentication {@link AuthProvider}.
|
|
6
|
+
*
|
|
7
|
+
* Parses the `Authorization: Basic <base64>` header, looks the username up in a
|
|
8
|
+
* configured user list, and verifies the supplied password using one of three
|
|
9
|
+
* credential modes (in order of preference):
|
|
10
|
+
*
|
|
11
|
+
* 1. A custom `passwordVerifier(username, password)` callback — for delegating
|
|
12
|
+
* to your own user store.
|
|
13
|
+
* 2. A `passwordHash` produced by {@link hashPassword} — scrypt with a random
|
|
14
|
+
* salt, verified in constant time. **Recommended for production.**
|
|
15
|
+
* 3. A plain `password` field — **development only**. Never ship real
|
|
16
|
+
* credentials as plaintext; they are compared in constant time but stored as
|
|
17
|
+
* cleartext in your config.
|
|
18
|
+
*
|
|
19
|
+
* On success the matched user becomes a {@link Principal}; on any failure
|
|
20
|
+
* (missing/malformed header, unknown user, bad password) `authenticate` returns
|
|
21
|
+
* `null`. {@link AuthProvider.challenge} emits a `401` with a
|
|
22
|
+
* `WWW-Authenticate: Basic realm="…"` header so browsers prompt for credentials.
|
|
23
|
+
*
|
|
24
|
+
* Password hashing uses Node's `node:crypto` `scrypt`, which is available in
|
|
25
|
+
* both Node and Bun — no Bun-only APIs and no extra dependencies.
|
|
26
|
+
*
|
|
27
|
+
* @module
|
|
28
|
+
*/
|
|
29
|
+
var basic_exports = /* @__PURE__ */ require_chunk.__exportAll({
|
|
30
|
+
basicAuth: () => basicAuth,
|
|
31
|
+
hashPassword: () => hashPassword,
|
|
32
|
+
verifyPassword: () => verifyPassword
|
|
33
|
+
});
|
|
34
|
+
/** scrypt key length (bytes) used by {@link hashPassword}. */
|
|
35
|
+
const KEY_LENGTH = 64;
|
|
36
|
+
/** Salt length (bytes) used by {@link hashPassword}. */
|
|
37
|
+
const SALT_LENGTH = 16;
|
|
38
|
+
/** Prefix identifying a {@link hashPassword} digest. */
|
|
39
|
+
const SCRYPT_PREFIX = "scrypt";
|
|
40
|
+
const scryptAsync = (password, salt, keylen) => new Promise((resolve, reject) => {
|
|
41
|
+
(0, node_crypto.scrypt)(password, salt, keylen, (err, derivedKey) => {
|
|
42
|
+
if (err) reject(err);
|
|
43
|
+
else resolve(derivedKey);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
/** Lowercase hex encoding of a buffer. */
|
|
47
|
+
const toHex = (buf) => buf.toString("hex");
|
|
48
|
+
/**
|
|
49
|
+
* Hash a password with scrypt and a fresh random salt.
|
|
50
|
+
*
|
|
51
|
+
* The returned string is self-describing and safe to store in config or a
|
|
52
|
+
* database: `scrypt$<saltHex>$<hashHex>`. Pass it back to
|
|
53
|
+
* {@link verifyPassword} (or supply it as a user's `passwordHash`) to check a
|
|
54
|
+
* candidate password.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```ts
|
|
58
|
+
* const stored = await hashPassword("correct horse battery staple");
|
|
59
|
+
* // → "scrypt$<32 hex chars>$<128 hex chars>"
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
async function hashPassword(password) {
|
|
63
|
+
const salt = (0, node_crypto.randomBytes)(SALT_LENGTH);
|
|
64
|
+
const derived = await scryptAsync(password, salt, KEY_LENGTH);
|
|
65
|
+
return `${SCRYPT_PREFIX}$${toHex(salt)}$${toHex(derived)}`;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Verify a candidate `password` against a digest produced by
|
|
69
|
+
* {@link hashPassword}.
|
|
70
|
+
*
|
|
71
|
+
* Re-derives the scrypt hash using the stored salt and compares it to the stored
|
|
72
|
+
* hash with `crypto.timingSafeEqual` (constant time). Returns `false` — rather
|
|
73
|
+
* than throwing — for malformed or unrecognized digests.
|
|
74
|
+
*/
|
|
75
|
+
async function verifyPassword(password, stored) {
|
|
76
|
+
const parts = stored.split("$");
|
|
77
|
+
if (parts.length !== 3 || parts[0] !== SCRYPT_PREFIX) return false;
|
|
78
|
+
const saltHex = parts[1];
|
|
79
|
+
const hashHex = parts[2];
|
|
80
|
+
if (!saltHex || !hashHex) return false;
|
|
81
|
+
let salt;
|
|
82
|
+
let expected;
|
|
83
|
+
try {
|
|
84
|
+
salt = Buffer.from(saltHex, "hex");
|
|
85
|
+
expected = Buffer.from(hashHex, "hex");
|
|
86
|
+
} catch {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
if (salt.length === 0 || expected.length === 0) return false;
|
|
90
|
+
const derived = await scryptAsync(password, salt, expected.length);
|
|
91
|
+
if (derived.length !== expected.length) return false;
|
|
92
|
+
return (0, node_crypto.timingSafeEqual)(derived, expected);
|
|
93
|
+
}
|
|
94
|
+
/** Constant-time string comparison that does not leak length via early exit. */
|
|
95
|
+
function constantTimeEquals(a, b) {
|
|
96
|
+
const bufA = Buffer.from(a, "utf8");
|
|
97
|
+
const bufB = Buffer.from(b, "utf8");
|
|
98
|
+
if (bufA.length !== bufB.length) {
|
|
99
|
+
(0, node_crypto.timingSafeEqual)(bufA, bufA);
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
return (0, node_crypto.timingSafeEqual)(bufA, bufB);
|
|
103
|
+
}
|
|
104
|
+
/** Decode the `Authorization: Basic <base64>` header, or `null` if absent/malformed. */
|
|
105
|
+
function parseBasicHeader(request) {
|
|
106
|
+
const header = request.headers.get("authorization");
|
|
107
|
+
if (!header) return null;
|
|
108
|
+
const [scheme, encoded] = header.split(" ", 2);
|
|
109
|
+
if (!scheme || scheme.toLowerCase() !== "basic" || !encoded) return null;
|
|
110
|
+
let decoded;
|
|
111
|
+
try {
|
|
112
|
+
decoded = Buffer.from(encoded, "base64").toString("utf8");
|
|
113
|
+
} catch {
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
const sep = decoded.indexOf(":");
|
|
117
|
+
if (sep < 0) return null;
|
|
118
|
+
return {
|
|
119
|
+
username: decoded.slice(0, sep),
|
|
120
|
+
password: decoded.slice(sep + 1)
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
/** Build the {@link Principal} for a successfully authenticated user. */
|
|
124
|
+
function principalFor(user) {
|
|
125
|
+
return {
|
|
126
|
+
id: user.id ?? user.username,
|
|
127
|
+
name: user.username,
|
|
128
|
+
...user.email !== void 0 ? { email: user.email } : {},
|
|
129
|
+
...user.roles !== void 0 ? { roles: user.roles } : {}
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Create an HTTP Basic {@link AuthProvider}.
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* ```ts
|
|
137
|
+
* import { basicAuth, hashPassword } from "@xtandard/kit/auth/basic";
|
|
138
|
+
*
|
|
139
|
+
* const auth = basicAuth({
|
|
140
|
+
* realm: "xtandard-webhooks",
|
|
141
|
+
* users: [
|
|
142
|
+
* { username: "admin", passwordHash: await hashPassword("s3cret"), roles: ["admin"] },
|
|
143
|
+
* ],
|
|
144
|
+
* });
|
|
145
|
+
* ```
|
|
146
|
+
*/
|
|
147
|
+
function basicAuth(options) {
|
|
148
|
+
const realm = options.realm ?? "xtandard";
|
|
149
|
+
const usersByName = /* @__PURE__ */ new Map();
|
|
150
|
+
for (const user of options.users) usersByName.set(user.username, user);
|
|
151
|
+
return {
|
|
152
|
+
async authenticate(request) {
|
|
153
|
+
const creds = parseBasicHeader(request);
|
|
154
|
+
if (!creds) return null;
|
|
155
|
+
const user = usersByName.get(creds.username);
|
|
156
|
+
if (!user) {
|
|
157
|
+
if (options.passwordVerifier) await options.passwordVerifier(creds.username, creds.password);
|
|
158
|
+
return null;
|
|
159
|
+
}
|
|
160
|
+
if (options.passwordVerifier) return await options.passwordVerifier(creds.username, creds.password) ? principalFor(user) : null;
|
|
161
|
+
if (user.passwordHash !== void 0) return await verifyPassword(creds.password, user.passwordHash) ? principalFor(user) : null;
|
|
162
|
+
if (user.password !== void 0) return constantTimeEquals(creds.password, user.password) ? principalFor(user) : null;
|
|
163
|
+
return null;
|
|
164
|
+
},
|
|
165
|
+
challenge(_request) {
|
|
166
|
+
return new Response("Unauthorized", {
|
|
167
|
+
status: 401,
|
|
168
|
+
headers: { "WWW-Authenticate": `Basic realm="${realm}"` }
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
//#endregion
|
|
174
|
+
Object.defineProperty(exports, "basicAuth", {
|
|
175
|
+
enumerable: true,
|
|
176
|
+
get: function() {
|
|
177
|
+
return basicAuth;
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
Object.defineProperty(exports, "basic_exports", {
|
|
181
|
+
enumerable: true,
|
|
182
|
+
get: function() {
|
|
183
|
+
return basic_exports;
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
Object.defineProperty(exports, "hashPassword", {
|
|
187
|
+
enumerable: true,
|
|
188
|
+
get: function() {
|
|
189
|
+
return hashPassword;
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
Object.defineProperty(exports, "verifyPassword", {
|
|
193
|
+
enumerable: true,
|
|
194
|
+
get: function() {
|
|
195
|
+
return verifyPassword;
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
//# sourceMappingURL=basic-ZaO92-lB.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"basic-ZaO92-lB.cjs","names":[],"sources":["../src/auth/basic.ts"],"sourcesContent":["/**\n * HTTP Basic authentication {@link AuthProvider}.\n *\n * Parses the `Authorization: Basic <base64>` header, looks the username up in a\n * configured user list, and verifies the supplied password using one of three\n * credential modes (in order of preference):\n *\n * 1. A custom `passwordVerifier(username, password)` callback — for delegating\n * to your own user store.\n * 2. A `passwordHash` produced by {@link hashPassword} — scrypt with a random\n * salt, verified in constant time. **Recommended for production.**\n * 3. A plain `password` field — **development only**. Never ship real\n * credentials as plaintext; they are compared in constant time but stored as\n * cleartext in your config.\n *\n * On success the matched user becomes a {@link Principal}; on any failure\n * (missing/malformed header, unknown user, bad password) `authenticate` returns\n * `null`. {@link AuthProvider.challenge} emits a `401` with a\n * `WWW-Authenticate: Basic realm=\"…\"` header so browsers prompt for credentials.\n *\n * Password hashing uses Node's `node:crypto` `scrypt`, which is available in\n * both Node and Bun — no Bun-only APIs and no extra dependencies.\n *\n * @module\n */\n\nimport { randomBytes, scrypt as scryptCb, timingSafeEqual } from \"node:crypto\";\nimport type { AuthProvider, Principal } from \"./contract.ts\";\n\n/** scrypt key length (bytes) used by {@link hashPassword}. */\nconst KEY_LENGTH = 64;\n/** Salt length (bytes) used by {@link hashPassword}. */\nconst SALT_LENGTH = 16;\n/** Prefix identifying a {@link hashPassword} digest. */\nconst SCRYPT_PREFIX = \"scrypt\";\n\nconst scryptAsync = (password: string, salt: Buffer, keylen: number): Promise<Buffer> =>\n new Promise((resolve, reject) => {\n scryptCb(password, salt, keylen, (err, derivedKey) => {\n if (err) reject(err);\n else resolve(derivedKey);\n });\n });\n\n/** Lowercase hex encoding of a buffer. */\nconst toHex = (buf: Buffer): string => buf.toString(\"hex\");\n\n/**\n * Hash a password with scrypt and a fresh random salt.\n *\n * The returned string is self-describing and safe to store in config or a\n * database: `scrypt$<saltHex>$<hashHex>`. Pass it back to\n * {@link verifyPassword} (or supply it as a user's `passwordHash`) to check a\n * candidate password.\n *\n * @example\n * ```ts\n * const stored = await hashPassword(\"correct horse battery staple\");\n * // → \"scrypt$<32 hex chars>$<128 hex chars>\"\n * ```\n */\nexport async function hashPassword(password: string): Promise<string> {\n const salt = randomBytes(SALT_LENGTH);\n const derived = await scryptAsync(password, salt, KEY_LENGTH);\n return `${SCRYPT_PREFIX}$${toHex(salt)}$${toHex(derived)}`;\n}\n\n/**\n * Verify a candidate `password` against a digest produced by\n * {@link hashPassword}.\n *\n * Re-derives the scrypt hash using the stored salt and compares it to the stored\n * hash with `crypto.timingSafeEqual` (constant time). Returns `false` — rather\n * than throwing — for malformed or unrecognized digests.\n */\nexport async function verifyPassword(password: string, stored: string): Promise<boolean> {\n const parts = stored.split(\"$\");\n if (parts.length !== 3 || parts[0] !== SCRYPT_PREFIX) return false;\n const saltHex = parts[1];\n const hashHex = parts[2];\n if (!saltHex || !hashHex) return false;\n\n let salt: Buffer;\n let expected: Buffer;\n try {\n salt = Buffer.from(saltHex, \"hex\");\n expected = Buffer.from(hashHex, \"hex\");\n } catch {\n return false;\n }\n if (salt.length === 0 || expected.length === 0) return false;\n\n const derived = await scryptAsync(password, salt, expected.length);\n if (derived.length !== expected.length) return false;\n return timingSafeEqual(derived, expected);\n}\n\n/** A configured user for {@link basicAuth}. */\nexport interface BasicAuthUser {\n /** The login name, matched against the Basic credentials. */\n username: string;\n /**\n * A digest produced by {@link hashPassword} (`scrypt$<salt>$<hash>`).\n * Preferred for production.\n */\n passwordHash?: string;\n /**\n * A plaintext password. **Development only** — prefer `passwordHash`. Compared\n * in constant time but stored as cleartext in your config.\n */\n password?: string;\n /** Roles attached to the resulting {@link Principal}. */\n roles?: string[];\n /** Email attached to the resulting {@link Principal}. */\n email?: string;\n /** Principal id. Defaults to {@link BasicAuthUser.username} when omitted. */\n id?: string;\n}\n\n/** Options for {@link basicAuth}. */\nexport interface BasicAuthOptions {\n /** The known users. */\n users: BasicAuthUser[];\n /**\n * Realm advertised in the `WWW-Authenticate` header on challenge.\n * @default \"xtandard\" (products pass their own, e.g. `\"xtandard-webhooks\"`)\n */\n realm?: string;\n /**\n * Custom verifier. When supplied it takes precedence over `passwordHash` and\n * `password` for matched users — delegate to your own credential store and\n * return `true` to accept.\n */\n passwordVerifier?: (username: string, password: string) => Promise<boolean> | boolean;\n}\n\n/** Constant-time string comparison that does not leak length via early exit. */\nfunction constantTimeEquals(a: string, b: string): boolean {\n const bufA = Buffer.from(a, \"utf8\");\n const bufB = Buffer.from(b, \"utf8\");\n // timingSafeEqual requires equal lengths; hash to a fixed width first so the\n // comparison time does not depend on the inputs.\n if (bufA.length !== bufB.length) {\n // Still perform a comparison to keep timing uniform, then fail.\n timingSafeEqual(bufA, bufA);\n return false;\n }\n return timingSafeEqual(bufA, bufB);\n}\n\n/** Result of parsing an `Authorization: Basic` header. */\ninterface BasicCredentials {\n username: string;\n password: string;\n}\n\n/** Decode the `Authorization: Basic <base64>` header, or `null` if absent/malformed. */\nfunction parseBasicHeader(request: Request): BasicCredentials | null {\n const header = request.headers.get(\"authorization\");\n if (!header) return null;\n const [scheme, encoded] = header.split(\" \", 2);\n if (!scheme || scheme.toLowerCase() !== \"basic\" || !encoded) return null;\n\n let decoded: string;\n try {\n decoded = Buffer.from(encoded, \"base64\").toString(\"utf8\");\n } catch {\n return null;\n }\n const sep = decoded.indexOf(\":\");\n if (sep < 0) return null;\n return { username: decoded.slice(0, sep), password: decoded.slice(sep + 1) };\n}\n\n/** Build the {@link Principal} for a successfully authenticated user. */\nfunction principalFor(user: BasicAuthUser): Principal {\n return {\n id: user.id ?? user.username,\n name: user.username,\n ...(user.email !== undefined ? { email: user.email } : {}),\n ...(user.roles !== undefined ? { roles: user.roles } : {}),\n };\n}\n\n/**\n * Create an HTTP Basic {@link AuthProvider}.\n *\n * @example\n * ```ts\n * import { basicAuth, hashPassword } from \"@xtandard/kit/auth/basic\";\n *\n * const auth = basicAuth({\n * realm: \"xtandard-webhooks\",\n * users: [\n * { username: \"admin\", passwordHash: await hashPassword(\"s3cret\"), roles: [\"admin\"] },\n * ],\n * });\n * ```\n */\nexport function basicAuth(options: BasicAuthOptions): AuthProvider {\n const realm = options.realm ?? \"xtandard\";\n const usersByName = new Map<string, BasicAuthUser>();\n for (const user of options.users) usersByName.set(user.username, user);\n\n return {\n async authenticate(request: Request): Promise<Principal | null> {\n const creds = parseBasicHeader(request);\n if (!creds) return null;\n\n const user = usersByName.get(creds.username);\n if (!user) {\n // Run a dummy verification to keep timing roughly uniform for unknown\n // users versus known users.\n if (options.passwordVerifier) {\n await options.passwordVerifier(creds.username, creds.password);\n }\n return null;\n }\n\n // (a) custom verifier wins.\n if (options.passwordVerifier) {\n const ok = await options.passwordVerifier(creds.username, creds.password);\n return ok ? principalFor(user) : null;\n }\n\n // (b) scrypt hash.\n if (user.passwordHash !== undefined) {\n const ok = await verifyPassword(creds.password, user.passwordHash);\n return ok ? principalFor(user) : null;\n }\n\n // (c) dev-only plaintext.\n if (user.password !== undefined) {\n const ok = constantTimeEquals(creds.password, user.password);\n return ok ? principalFor(user) : null;\n }\n\n return null;\n },\n\n challenge(_request: Request): Response {\n return new Response(\"Unauthorized\", {\n status: 401,\n headers: { \"WWW-Authenticate\": `Basic realm=\"${realm}\"` },\n });\n },\n };\n}\n"],"mappings":"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"}
|