@atproto/oauth-provider 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- package/.postcssrc.yml +3 -0
- package/CHANGELOG.md +19 -0
- package/LICENSE.txt +7 -0
- package/dist/access-token/access-token-type.d.ts +6 -0
- package/dist/access-token/access-token-type.d.ts.map +1 -0
- package/dist/access-token/access-token-type.js +10 -0
- package/dist/access-token/access-token-type.js.map +1 -0
- package/dist/account/account-manager.d.ts +14 -0
- package/dist/account/account-manager.d.ts.map +1 -0
- package/dist/account/account-manager.js +39 -0
- package/dist/account/account-manager.js.map +1 -0
- package/dist/account/account-store.d.ts +39 -0
- package/dist/account/account-store.d.ts.map +1 -0
- package/dist/account/account-store.js +19 -0
- package/dist/account/account-store.js.map +1 -0
- package/dist/account/account.d.ts +8 -0
- package/dist/account/account.d.ts.map +1 -0
- package/dist/account/account.js +3 -0
- package/dist/account/account.js.map +1 -0
- package/dist/assets/app/bundle-manifest.json +22 -0
- package/dist/assets/app/main.css +3 -0
- package/dist/assets/app/main.js +20 -0
- package/dist/assets/app/main.js.map +1 -0
- package/dist/assets/asset.d.ts +9 -0
- package/dist/assets/asset.d.ts.map +1 -0
- package/dist/assets/asset.js +3 -0
- package/dist/assets/asset.js.map +1 -0
- package/dist/assets/assets-middleware.d.ts +2 -0
- package/dist/assets/assets-middleware.d.ts.map +1 -0
- package/dist/assets/assets-middleware.js +30 -0
- package/dist/assets/assets-middleware.js.map +1 -0
- package/dist/assets/index.d.ts +4 -0
- package/dist/assets/index.d.ts.map +1 -0
- package/dist/assets/index.js +65 -0
- package/dist/assets/index.js.map +1 -0
- package/dist/client/client-auth.d.ts +13 -0
- package/dist/client/client-auth.d.ts.map +1 -0
- package/dist/client/client-auth.js +35 -0
- package/dist/client/client-auth.js.map +1 -0
- package/dist/client/client-data.d.ts +8 -0
- package/dist/client/client-data.d.ts.map +1 -0
- package/dist/client/client-data.js +3 -0
- package/dist/client/client-data.js.map +1 -0
- package/dist/client/client-id.d.ts +4 -0
- package/dist/client/client-id.d.ts.map +1 -0
- package/dist/client/client-id.js +6 -0
- package/dist/client/client-id.js.map +1 -0
- package/dist/client/client-info.d.ts +13 -0
- package/dist/client/client-info.d.ts.map +1 -0
- package/dist/client/client-info.js +3 -0
- package/dist/client/client-info.js.map +1 -0
- package/dist/client/client-manager.d.ts +38 -0
- package/dist/client/client-manager.d.ts.map +1 -0
- package/dist/client/client-manager.js +534 -0
- package/dist/client/client-manager.js.map +1 -0
- package/dist/client/client-store.d.ts +13 -0
- package/dist/client/client-store.d.ts.map +1 -0
- package/dist/client/client-store.js +39 -0
- package/dist/client/client-store.js.map +1 -0
- package/dist/client/client-utils.d.ts +6 -0
- package/dist/client/client-utils.d.ts.map +1 -0
- package/dist/client/client-utils.js +40 -0
- package/dist/client/client-utils.js.map +1 -0
- package/dist/client/client.d.ts +41 -0
- package/dist/client/client.d.ts.map +1 -0
- package/dist/client/client.js +163 -0
- package/dist/client/client.js.map +1 -0
- package/dist/constants.d.ts +42 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +53 -0
- package/dist/constants.js.map +1 -0
- package/dist/device/device-data.d.ts +20 -0
- package/dist/device/device-data.d.ts.map +1 -0
- package/dist/device/device-data.js +11 -0
- package/dist/device/device-data.js.map +1 -0
- package/dist/device/device-details.d.ts +17 -0
- package/dist/device/device-details.d.ts.map +1 -0
- package/dist/device/device-details.js +34 -0
- package/dist/device/device-details.js.map +1 -0
- package/dist/device/device-id.d.ts +6 -0
- package/dist/device/device-id.d.ts.map +1 -0
- package/dist/device/device-id.js +18 -0
- package/dist/device/device-id.js.map +1 -0
- package/dist/device/device-manager.d.ts +88 -0
- package/dist/device/device-manager.d.ts.map +1 -0
- package/dist/device/device-manager.js +206 -0
- package/dist/device/device-manager.js.map +1 -0
- package/dist/device/device-store.d.ts +15 -0
- package/dist/device/device-store.d.ts.map +1 -0
- package/dist/device/device-store.js +36 -0
- package/dist/device/device-store.js.map +1 -0
- package/dist/device/session-id.d.ts +6 -0
- package/dist/device/session-id.d.ts.map +1 -0
- package/dist/device/session-id.js +18 -0
- package/dist/device/session-id.js.map +1 -0
- package/dist/dpop/dpop-manager.d.ts +33 -0
- package/dist/dpop/dpop-manager.d.ts.map +1 -0
- package/dist/dpop/dpop-manager.js +115 -0
- package/dist/dpop/dpop-manager.js.map +1 -0
- package/dist/dpop/dpop-nonce.d.ts +13 -0
- package/dist/dpop/dpop-nonce.d.ts.map +1 -0
- package/dist/dpop/dpop-nonce.js +94 -0
- package/dist/dpop/dpop-nonce.js.map +1 -0
- package/dist/errors/access-denied-error.d.ts +8 -0
- package/dist/errors/access-denied-error.d.ts.map +1 -0
- package/dist/errors/access-denied-error.js +21 -0
- package/dist/errors/access-denied-error.js.map +1 -0
- package/dist/errors/account-selection-required-error.d.ts +6 -0
- package/dist/errors/account-selection-required-error.d.ts.map +1 -0
- package/dist/errors/account-selection-required-error.js +11 -0
- package/dist/errors/account-selection-required-error.js.map +1 -0
- package/dist/errors/consent-required-error.d.ts +6 -0
- package/dist/errors/consent-required-error.d.ts.map +1 -0
- package/dist/errors/consent-required-error.js +11 -0
- package/dist/errors/consent-required-error.js.map +1 -0
- package/dist/errors/invalid-authorization-details-error.d.ts +20 -0
- package/dist/errors/invalid-authorization-details-error.d.ts.map +1 -0
- package/dist/errors/invalid-authorization-details-error.js +26 -0
- package/dist/errors/invalid-authorization-details-error.js.map +1 -0
- package/dist/errors/invalid-client-error.d.ts +18 -0
- package/dist/errors/invalid-client-error.d.ts.map +1 -0
- package/dist/errors/invalid-client-error.js +24 -0
- package/dist/errors/invalid-client-error.js.map +1 -0
- package/dist/errors/invalid-client-id-error.d.ts +13 -0
- package/dist/errors/invalid-client-id-error.d.ts.map +1 -0
- package/dist/errors/invalid-client-id-error.js +25 -0
- package/dist/errors/invalid-client-id-error.js.map +1 -0
- package/dist/errors/invalid-client-metadata-error.d.ts +13 -0
- package/dist/errors/invalid-client-metadata-error.d.ts.map +1 -0
- package/dist/errors/invalid-client-metadata-error.js +23 -0
- package/dist/errors/invalid-client-metadata-error.js.map +1 -0
- package/dist/errors/invalid-dpop-key-binding-error.d.ts +12 -0
- package/dist/errors/invalid-dpop-key-binding-error.d.ts.map +1 -0
- package/dist/errors/invalid-dpop-key-binding-error.js +20 -0
- package/dist/errors/invalid-dpop-key-binding-error.js.map +1 -0
- package/dist/errors/invalid-dpop-proof-error.d.ts +5 -0
- package/dist/errors/invalid-dpop-proof-error.d.ts.map +1 -0
- package/dist/errors/invalid-dpop-proof-error.js +12 -0
- package/dist/errors/invalid-dpop-proof-error.js.map +1 -0
- package/dist/errors/invalid-grant-error.d.ts +14 -0
- package/dist/errors/invalid-grant-error.d.ts.map +1 -0
- package/dist/errors/invalid-grant-error.js +20 -0
- package/dist/errors/invalid-grant-error.js.map +1 -0
- package/dist/errors/invalid-parameters-error.d.ts +6 -0
- package/dist/errors/invalid-parameters-error.d.ts.map +1 -0
- package/dist/errors/invalid-parameters-error.js +11 -0
- package/dist/errors/invalid-parameters-error.js.map +1 -0
- package/dist/errors/invalid-redirect-uri-error.d.ts +11 -0
- package/dist/errors/invalid-redirect-uri-error.d.ts.map +1 -0
- package/dist/errors/invalid-redirect-uri-error.js +21 -0
- package/dist/errors/invalid-redirect-uri-error.js.map +1 -0
- package/dist/errors/invalid-request-error.d.ts +28 -0
- package/dist/errors/invalid-request-error.d.ts.map +1 -0
- package/dist/errors/invalid-request-error.js +34 -0
- package/dist/errors/invalid-request-error.js.map +1 -0
- package/dist/errors/invalid-token-error.d.ts +16 -0
- package/dist/errors/invalid-token-error.d.ts.map +1 -0
- package/dist/errors/invalid-token-error.js +45 -0
- package/dist/errors/invalid-token-error.js.map +1 -0
- package/dist/errors/login-required-error.d.ts +6 -0
- package/dist/errors/login-required-error.d.ts.map +1 -0
- package/dist/errors/login-required-error.js +11 -0
- package/dist/errors/login-required-error.js.map +1 -0
- package/dist/errors/oauth-error.d.ts +13 -0
- package/dist/errors/oauth-error.d.ts.map +1 -0
- package/dist/errors/oauth-error.js +29 -0
- package/dist/errors/oauth-error.js.map +1 -0
- package/dist/errors/unauthorized-client-error.d.ts +18 -0
- package/dist/errors/unauthorized-client-error.d.ts.map +1 -0
- package/dist/errors/unauthorized-client-error.js +24 -0
- package/dist/errors/unauthorized-client-error.js.map +1 -0
- package/dist/errors/use-dpop-nonce-error.d.ts +18 -0
- package/dist/errors/use-dpop-nonce-error.d.ts.map +1 -0
- package/dist/errors/use-dpop-nonce-error.js +27 -0
- package/dist/errors/use-dpop-nonce-error.js.map +1 -0
- package/dist/errors/www-authenticate-error.d.ts +9 -0
- package/dist/errors/www-authenticate-error.d.ts.map +1 -0
- package/dist/errors/www-authenticate-error.js +46 -0
- package/dist/errors/www-authenticate-error.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +31 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/html/build-document.d.ts +32 -0
- package/dist/lib/html/build-document.d.ts.map +1 -0
- package/dist/lib/html/build-document.js +61 -0
- package/dist/lib/html/build-document.js.map +1 -0
- package/dist/lib/html/escapers.d.ts +9 -0
- package/dist/lib/html/escapers.d.ts.map +1 -0
- package/dist/lib/html/escapers.js +66 -0
- package/dist/lib/html/escapers.js.map +1 -0
- package/dist/lib/html/html.d.ts +13 -0
- package/dist/lib/html/html.d.ts.map +1 -0
- package/dist/lib/html/html.js +53 -0
- package/dist/lib/html/html.js.map +1 -0
- package/dist/lib/html/index.d.ts +4 -0
- package/dist/lib/html/index.d.ts.map +1 -0
- package/dist/lib/html/index.js +21 -0
- package/dist/lib/html/index.js.map +1 -0
- package/dist/lib/html/tags.d.ts +34 -0
- package/dist/lib/html/tags.d.ts.map +1 -0
- package/dist/lib/html/tags.js +47 -0
- package/dist/lib/html/tags.js.map +1 -0
- package/dist/lib/html/util.d.ts +4 -0
- package/dist/lib/html/util.d.ts.map +1 -0
- package/dist/lib/html/util.js +20 -0
- package/dist/lib/html/util.js.map +1 -0
- package/dist/lib/http/accept.d.ts +29 -0
- package/dist/lib/http/accept.d.ts.map +1 -0
- package/dist/lib/http/accept.js +67 -0
- package/dist/lib/http/accept.js.map +1 -0
- package/dist/lib/http/context.d.ts +5 -0
- package/dist/lib/http/context.d.ts.map +1 -0
- package/dist/lib/http/context.js +10 -0
- package/dist/lib/http/context.js.map +1 -0
- package/dist/lib/http/index.d.ts +10 -0
- package/dist/lib/http/index.d.ts.map +1 -0
- package/dist/lib/http/index.js +26 -0
- package/dist/lib/http/index.js.map +1 -0
- package/dist/lib/http/method.d.ts +6 -0
- package/dist/lib/http/method.d.ts.map +1 -0
- package/dist/lib/http/method.js +19 -0
- package/dist/lib/http/method.js.map +1 -0
- package/dist/lib/http/middleware.d.ts +18 -0
- package/dist/lib/http/middleware.d.ts.map +1 -0
- package/dist/lib/http/middleware.js +118 -0
- package/dist/lib/http/middleware.js.map +1 -0
- package/dist/lib/http/parser.d.ts +33 -0
- package/dist/lib/http/parser.d.ts.map +1 -0
- package/dist/lib/http/parser.js +48 -0
- package/dist/lib/http/parser.js.map +1 -0
- package/dist/lib/http/path.d.ts +9 -0
- package/dist/lib/http/path.d.ts.map +1 -0
- package/dist/lib/http/path.js +54 -0
- package/dist/lib/http/path.js.map +1 -0
- package/dist/lib/http/request.d.ts +33 -0
- package/dist/lib/http/request.d.ts.map +1 -0
- package/dist/lib/http/request.js +86 -0
- package/dist/lib/http/request.js.map +1 -0
- package/dist/lib/http/response.d.ts +13 -0
- package/dist/lib/http/response.d.ts.map +1 -0
- package/dist/lib/http/response.js +98 -0
- package/dist/lib/http/response.js.map +1 -0
- package/dist/lib/http/route.d.ts +25 -0
- package/dist/lib/http/route.d.ts.map +1 -0
- package/dist/lib/http/route.js +39 -0
- package/dist/lib/http/route.js.map +1 -0
- package/dist/lib/http/router.d.ts +32 -0
- package/dist/lib/http/router.d.ts.map +1 -0
- package/dist/lib/http/router.js +74 -0
- package/dist/lib/http/router.js.map +1 -0
- package/dist/lib/http/stream.d.ts +13 -0
- package/dist/lib/http/stream.d.ts.map +1 -0
- package/dist/lib/http/stream.js +46 -0
- package/dist/lib/http/stream.js.map +1 -0
- package/dist/lib/http/types.d.ts +7 -0
- package/dist/lib/http/types.d.ts.map +1 -0
- package/dist/lib/http/types.js +3 -0
- package/dist/lib/http/types.js.map +1 -0
- package/dist/lib/http/url.d.ts +8 -0
- package/dist/lib/http/url.d.ts.map +1 -0
- package/dist/lib/http/url.js +22 -0
- package/dist/lib/http/url.js.map +1 -0
- package/dist/lib/redis.d.ts +5 -0
- package/dist/lib/redis.d.ts.map +1 -0
- package/dist/lib/redis.js +22 -0
- package/dist/lib/redis.js.map +1 -0
- package/dist/lib/util/authorization-header.d.ts +4 -0
- package/dist/lib/util/authorization-header.d.ts.map +1 -0
- package/dist/lib/util/authorization-header.js +23 -0
- package/dist/lib/util/authorization-header.js.map +1 -0
- package/dist/lib/util/cast.d.ts +2 -0
- package/dist/lib/util/cast.d.ts.map +1 -0
- package/dist/lib/util/cast.js +10 -0
- package/dist/lib/util/cast.js.map +1 -0
- package/dist/lib/util/crypto.d.ts +3 -0
- package/dist/lib/util/crypto.d.ts.map +1 -0
- package/dist/lib/util/crypto.js +29 -0
- package/dist/lib/util/crypto.js.map +1 -0
- package/dist/lib/util/date.d.ts +3 -0
- package/dist/lib/util/date.d.ts.map +1 -0
- package/dist/lib/util/date.js +12 -0
- package/dist/lib/util/date.js.map +1 -0
- package/dist/lib/util/hostname.d.ts +6 -0
- package/dist/lib/util/hostname.d.ts.map +1 -0
- package/dist/lib/util/hostname.js +24 -0
- package/dist/lib/util/hostname.js.map +1 -0
- package/dist/lib/util/redirect-uri.d.ts +7 -0
- package/dist/lib/util/redirect-uri.d.ts.map +1 -0
- package/dist/lib/util/redirect-uri.js +44 -0
- package/dist/lib/util/redirect-uri.js.map +1 -0
- package/dist/lib/util/time.d.ts +6 -0
- package/dist/lib/util/time.d.ts.map +1 -0
- package/dist/lib/util/time.js +28 -0
- package/dist/lib/util/time.js.map +1 -0
- package/dist/lib/util/type.d.ts +6 -0
- package/dist/lib/util/type.d.ts.map +1 -0
- package/dist/lib/util/type.js +3 -0
- package/dist/lib/util/type.js.map +1 -0
- package/dist/lib/util/well-known.d.ts +3 -0
- package/dist/lib/util/well-known.d.ts.map +1 -0
- package/dist/lib/util/well-known.js +11 -0
- package/dist/lib/util/well-known.js.map +1 -0
- package/dist/metadata/build-metadata.d.ts +14 -0
- package/dist/metadata/build-metadata.d.ts.map +1 -0
- package/dist/metadata/build-metadata.js +132 -0
- package/dist/metadata/build-metadata.js.map +1 -0
- package/dist/oauth-client.d.ts +4 -0
- package/dist/oauth-client.d.ts.map +1 -0
- package/dist/oauth-client.js +19 -0
- package/dist/oauth-client.js.map +1 -0
- package/dist/oauth-dpop.d.ts +3 -0
- package/dist/oauth-dpop.d.ts.map +1 -0
- package/dist/oauth-dpop.js +19 -0
- package/dist/oauth-dpop.js.map +1 -0
- package/dist/oauth-errors.d.ts +20 -0
- package/dist/oauth-errors.d.ts.map +1 -0
- package/dist/oauth-errors.js +43 -0
- package/dist/oauth-errors.js.map +1 -0
- package/dist/oauth-hooks.d.ts +42 -0
- package/dist/oauth-hooks.d.ts.map +1 -0
- package/dist/oauth-hooks.js +3 -0
- package/dist/oauth-hooks.js.map +1 -0
- package/dist/oauth-provider.d.ts +179 -0
- package/dist/oauth-provider.d.ts.map +1 -0
- package/dist/oauth-provider.js +748 -0
- package/dist/oauth-provider.js.map +1 -0
- package/dist/oauth-store.d.ts +11 -0
- package/dist/oauth-store.d.ts.map +1 -0
- package/dist/oauth-store.js +27 -0
- package/dist/oauth-store.js.map +1 -0
- package/dist/oauth-verifier.d.ts +66 -0
- package/dist/oauth-verifier.d.ts.map +1 -0
- package/dist/oauth-verifier.js +94 -0
- package/dist/oauth-verifier.js.map +1 -0
- package/dist/oidc/claims.d.ts +16 -0
- package/dist/oidc/claims.d.ts.map +1 -0
- package/dist/oidc/claims.js +29 -0
- package/dist/oidc/claims.js.map +1 -0
- package/dist/oidc/sub.d.ts +4 -0
- package/dist/oidc/sub.d.ts.map +1 -0
- package/dist/oidc/sub.js +6 -0
- package/dist/oidc/sub.js.map +1 -0
- package/dist/oidc/userinfo.d.ts +7 -0
- package/dist/oidc/userinfo.d.ts.map +1 -0
- package/dist/oidc/userinfo.js +3 -0
- package/dist/oidc/userinfo.js.map +1 -0
- package/dist/output/build-error-payload.d.ts +6 -0
- package/dist/output/build-error-payload.d.ts.map +1 -0
- package/dist/output/build-error-payload.js +108 -0
- package/dist/output/build-error-payload.js.map +1 -0
- package/dist/output/customization.d.ts +37 -0
- package/dist/output/customization.d.ts.map +1 -0
- package/dist/output/customization.js +62 -0
- package/dist/output/customization.js.map +1 -0
- package/dist/output/send-authorize-page.d.ts +43 -0
- package/dist/output/send-authorize-page.d.ts.map +1 -0
- package/dist/output/send-authorize-page.js +49 -0
- package/dist/output/send-authorize-page.js.map +1 -0
- package/dist/output/send-authorize-redirect.d.ts +25 -0
- package/dist/output/send-authorize-redirect.d.ts.map +1 -0
- package/dist/output/send-authorize-redirect.js +72 -0
- package/dist/output/send-authorize-redirect.js.map +1 -0
- package/dist/output/send-error-page.d.ts +5 -0
- package/dist/output/send-error-page.d.ts.map +1 -0
- package/dist/output/send-error-page.js +31 -0
- package/dist/output/send-error-page.js.map +1 -0
- package/dist/output/send-web-page.d.ts +8 -0
- package/dist/output/send-web-page.d.ts.map +1 -0
- package/dist/output/send-web-page.js +48 -0
- package/dist/output/send-web-page.js.map +1 -0
- package/dist/parameters/claims-requested.d.ts +3 -0
- package/dist/parameters/claims-requested.d.ts.map +1 -0
- package/dist/parameters/claims-requested.js +77 -0
- package/dist/parameters/claims-requested.js.map +1 -0
- package/dist/parameters/oidc-payload.d.ts +31 -0
- package/dist/parameters/oidc-payload.d.ts.map +1 -0
- package/dist/parameters/oidc-payload.js +25 -0
- package/dist/parameters/oidc-payload.js.map +1 -0
- package/dist/replay/replay-manager.d.ts +10 -0
- package/dist/replay/replay-manager.d.ts.map +1 -0
- package/dist/replay/replay-manager.js +23 -0
- package/dist/replay/replay-manager.js.map +1 -0
- package/dist/replay/replay-store-memory.d.ts +11 -0
- package/dist/replay/replay-store-memory.d.ts.map +1 -0
- package/dist/replay/replay-store-memory.js +30 -0
- package/dist/replay/replay-store-memory.js.map +1 -0
- package/dist/replay/replay-store-redis.d.ts +16 -0
- package/dist/replay/replay-store-redis.d.ts.map +1 -0
- package/dist/replay/replay-store-redis.js +20 -0
- package/dist/replay/replay-store-redis.js.map +1 -0
- package/dist/replay/replay-store.d.ts +16 -0
- package/dist/replay/replay-store.d.ts.map +1 -0
- package/dist/replay/replay-store.js +22 -0
- package/dist/replay/replay-store.js.map +1 -0
- package/dist/request/code.d.ts +7 -0
- package/dist/request/code.d.ts.map +1 -0
- package/dist/request/code.js +20 -0
- package/dist/request/code.js.map +1 -0
- package/dist/request/request-data.d.ts +21 -0
- package/dist/request/request-data.d.ts.map +1 -0
- package/dist/request/request-data.js +6 -0
- package/dist/request/request-data.js.map +1 -0
- package/dist/request/request-id.d.ts +6 -0
- package/dist/request/request-id.d.ts.map +1 -0
- package/dist/request/request-id.js +18 -0
- package/dist/request/request-id.js.map +1 -0
- package/dist/request/request-info.d.ts +12 -0
- package/dist/request/request-info.d.ts.map +1 -0
- package/dist/request/request-info.js +3 -0
- package/dist/request/request-info.js.map +1 -0
- package/dist/request/request-manager.d.ts +40 -0
- package/dist/request/request-manager.d.ts.map +1 -0
- package/dist/request/request-manager.js +310 -0
- package/dist/request/request-manager.js.map +1 -0
- package/dist/request/request-store-memory.d.ts +16 -0
- package/dist/request/request-store-memory.d.ts.map +1 -0
- package/dist/request/request-store-memory.js +31 -0
- package/dist/request/request-store-memory.js.map +1 -0
- package/dist/request/request-store-redis.d.ts +24 -0
- package/dist/request/request-store-redis.d.ts.map +1 -0
- package/dist/request/request-store-redis.js +58 -0
- package/dist/request/request-store-redis.js.map +1 -0
- package/dist/request/request-store.d.ts +27 -0
- package/dist/request/request-store.d.ts.map +1 -0
- package/dist/request/request-store.js +37 -0
- package/dist/request/request-store.js.map +1 -0
- package/dist/request/request-uri.d.ts +8 -0
- package/dist/request/request-uri.d.ts.map +1 -0
- package/dist/request/request-uri.js +24 -0
- package/dist/request/request-uri.js.map +1 -0
- package/dist/request/types.d.ts +328 -0
- package/dist/request/types.d.ts.map +1 -0
- package/dist/request/types.js +27 -0
- package/dist/request/types.js.map +1 -0
- package/dist/signer/signed-token-payload.d.ts +1694 -0
- package/dist/signer/signed-token-payload.d.ts.map +1 -0
- package/dist/signer/signed-token-payload.js +32 -0
- package/dist/signer/signed-token-payload.js.map +1 -0
- package/dist/signer/signer.d.ts +193 -0
- package/dist/signer/signer.d.ts.map +1 -0
- package/dist/signer/signer.js +101 -0
- package/dist/signer/signer.js.map +1 -0
- package/dist/token/refresh-token.d.ts +7 -0
- package/dist/token/refresh-token.d.ts.map +1 -0
- package/dist/token/refresh-token.js +20 -0
- package/dist/token/refresh-token.js.map +1 -0
- package/dist/token/token-claims.d.ts +1687 -0
- package/dist/token/token-claims.d.ts.map +1 -0
- package/dist/token/token-claims.js +30 -0
- package/dist/token/token-claims.js.map +1 -0
- package/dist/token/token-data.d.ts +20 -0
- package/dist/token/token-data.d.ts.map +1 -0
- package/dist/token/token-data.js +3 -0
- package/dist/token/token-data.js.map +1 -0
- package/dist/token/token-id.d.ts +7 -0
- package/dist/token/token-id.d.ts.map +1 -0
- package/dist/token/token-id.js +20 -0
- package/dist/token/token-id.js.map +1 -0
- package/dist/token/token-manager.d.ts +48 -0
- package/dist/token/token-manager.d.ts.map +1 -0
- package/dist/token/token-manager.js +421 -0
- package/dist/token/token-manager.js.map +1 -0
- package/dist/token/token-store.d.ts +35 -0
- package/dist/token/token-store.d.ts.map +1 -0
- package/dist/token/token-store.js +38 -0
- package/dist/token/token-store.js.map +1 -0
- package/dist/token/types.d.ts +250 -0
- package/dist/token/types.d.ts.map +1 -0
- package/dist/token/types.js +36 -0
- package/dist/token/types.js.map +1 -0
- package/dist/token/verify-token-claims.d.ts +17 -0
- package/dist/token/verify-token-claims.d.ts.map +1 -0
- package/dist/token/verify-token-claims.js +39 -0
- package/dist/token/verify-token-claims.js.map +1 -0
- package/package.json +83 -0
- package/rollup.config.js +55 -0
- package/src/access-token/access-token-type.ts +5 -0
- package/src/account/account-manager.ts +55 -0
- package/src/account/account-store.ts +74 -0
- package/src/account/account.ts +10 -0
- package/src/assets/app/app.tsx +28 -0
- package/src/assets/app/backend-data.ts +65 -0
- package/src/assets/app/components/accept-form.tsx +112 -0
- package/src/assets/app/components/account-identifier.tsx +18 -0
- package/src/assets/app/components/account-picker.tsx +108 -0
- package/src/assets/app/components/client-identifier.tsx +32 -0
- package/src/assets/app/components/client-name.tsx +30 -0
- package/src/assets/app/components/error-card.tsx +41 -0
- package/src/assets/app/components/help-card.tsx +42 -0
- package/src/assets/app/components/layout-title-page.tsx +43 -0
- package/src/assets/app/components/layout-welcome.tsx +58 -0
- package/src/assets/app/components/sign-in-form.tsx +290 -0
- package/src/assets/app/components/sign-up-account-form.tsx +210 -0
- package/src/assets/app/components/sign-up-disclaimer.tsx +44 -0
- package/src/assets/app/components/url-viewer.tsx +70 -0
- package/src/assets/app/cookies.ts +11 -0
- package/src/assets/app/hooks/use-api.ts +104 -0
- package/src/assets/app/hooks/use-bound-dispatch.ts +5 -0
- package/src/assets/app/hooks/use-csrf-token.ts +5 -0
- package/src/assets/app/lib/api.ts +64 -0
- package/src/assets/app/lib/clsx.ts +4 -0
- package/src/assets/app/lib/util.ts +10 -0
- package/src/assets/app/main.css +11 -0
- package/src/assets/app/main.tsx +28 -0
- package/src/assets/app/views/accept-view.tsx +51 -0
- package/src/assets/app/views/authorize-view.tsx +101 -0
- package/src/assets/app/views/error-view.tsx +27 -0
- package/src/assets/app/views/sign-in-view.tsx +121 -0
- package/src/assets/app/views/sign-up-view.tsx +93 -0
- package/src/assets/app/views/welcome-view.tsx +61 -0
- package/src/assets/asset.ts +8 -0
- package/src/assets/assets-middleware.ts +32 -0
- package/src/assets/index.ts +74 -0
- package/src/client/client-auth.ts +45 -0
- package/src/client/client-data.ts +9 -0
- package/src/client/client-id.ts +4 -0
- package/src/client/client-info.ts +13 -0
- package/src/client/client-manager.ts +818 -0
- package/src/client/client-store.ts +38 -0
- package/src/client/client-utils.ts +43 -0
- package/src/client/client.ts +231 -0
- package/src/constants.ts +69 -0
- package/src/device/device-data.ts +11 -0
- package/src/device/device-details.ts +43 -0
- package/src/device/device-id.ts +23 -0
- package/src/device/device-manager.ts +287 -0
- package/src/device/device-store.ts +35 -0
- package/src/device/session-id.ts +22 -0
- package/src/dpop/dpop-manager.ts +147 -0
- package/src/dpop/dpop-nonce.ts +104 -0
- package/src/errors/access-denied-error.ts +26 -0
- package/src/errors/account-selection-required-error.ts +12 -0
- package/src/errors/consent-required-error.ts +12 -0
- package/src/errors/invalid-authorization-details-error.ts +22 -0
- package/src/errors/invalid-client-error.ts +20 -0
- package/src/errors/invalid-client-id-error.ts +20 -0
- package/src/errors/invalid-client-metadata-error.ts +19 -0
- package/src/errors/invalid-dpop-key-binding-error.ts +21 -0
- package/src/errors/invalid-dpop-proof-error.ts +13 -0
- package/src/errors/invalid-grant-error.ts +16 -0
- package/src/errors/invalid-parameters-error.ts +12 -0
- package/src/errors/invalid-redirect-uri-error.ts +17 -0
- package/src/errors/invalid-request-error.ts +30 -0
- package/src/errors/invalid-token-error.ts +59 -0
- package/src/errors/login-required-error.ts +12 -0
- package/src/errors/oauth-error.ts +28 -0
- package/src/errors/unauthorized-client-error.ts +20 -0
- package/src/errors/use-dpop-nonce-error.ts +32 -0
- package/src/errors/www-authenticate-error.ts +65 -0
- package/src/index.ts +15 -0
- package/src/lib/html/README.md +9 -0
- package/src/lib/html/build-document.ts +98 -0
- package/src/lib/html/escapers.ts +66 -0
- package/src/lib/html/html.ts +61 -0
- package/src/lib/html/index.ts +5 -0
- package/src/lib/html/tags.ts +58 -0
- package/src/lib/html/util.ts +21 -0
- package/src/lib/http/README.md +11 -0
- package/src/lib/http/accept.ts +91 -0
- package/src/lib/http/context.ts +11 -0
- package/src/lib/http/index.ts +9 -0
- package/src/lib/http/method.ts +18 -0
- package/src/lib/http/middleware.ts +183 -0
- package/src/lib/http/parser.ts +64 -0
- package/src/lib/http/path.ts +82 -0
- package/src/lib/http/request.ts +141 -0
- package/src/lib/http/response.ts +133 -0
- package/src/lib/http/route.ts +56 -0
- package/src/lib/http/router.ts +118 -0
- package/src/lib/http/stream.ts +78 -0
- package/src/lib/http/types.ts +22 -0
- package/src/lib/http/url.ts +23 -0
- package/src/lib/redis.ts +23 -0
- package/src/lib/util/authorization-header.ts +26 -0
- package/src/lib/util/cast.ts +4 -0
- package/src/lib/util/crypto.ts +27 -0
- package/src/lib/util/date.ts +7 -0
- package/src/lib/util/hostname.ts +19 -0
- package/src/lib/util/redirect-uri.ts +46 -0
- package/src/lib/util/time.ts +33 -0
- package/src/lib/util/type.ts +4 -0
- package/src/lib/util/well-known.ts +8 -0
- package/src/metadata/build-metadata.ts +165 -0
- package/src/oauth-client.ts +3 -0
- package/src/oauth-dpop.ts +2 -0
- package/src/oauth-errors.ts +21 -0
- package/src/oauth-hooks.ts +66 -0
- package/src/oauth-provider.ts +1409 -0
- package/src/oauth-store.ts +11 -0
- package/src/oauth-verifier.ts +219 -0
- package/src/oidc/claims.ts +35 -0
- package/src/oidc/sub.ts +4 -0
- package/src/oidc/userinfo.ts +11 -0
- package/src/output/build-error-payload.ts +143 -0
- package/src/output/customization.ts +96 -0
- package/src/output/send-authorize-page.ts +111 -0
- package/src/output/send-authorize-redirect.ts +130 -0
- package/src/output/send-error-page.ts +41 -0
- package/src/output/send-web-page.ts +66 -0
- package/src/parameters/claims-requested.ts +106 -0
- package/src/parameters/oidc-payload.ts +28 -0
- package/src/replay/replay-manager.ts +38 -0
- package/src/replay/replay-store-memory.ts +36 -0
- package/src/replay/replay-store-redis.ts +31 -0
- package/src/replay/replay-store.ts +44 -0
- package/src/request/code.ts +24 -0
- package/src/request/request-data.ts +26 -0
- package/src/request/request-id.ts +23 -0
- package/src/request/request-info.ts +12 -0
- package/src/request/request-manager.ts +479 -0
- package/src/request/request-store-memory.ts +39 -0
- package/src/request/request-store-redis.ts +71 -0
- package/src/request/request-store.ts +54 -0
- package/src/request/request-uri.ts +29 -0
- package/src/request/types.ts +48 -0
- package/src/signer/signed-token-payload.ts +35 -0
- package/src/signer/signer.ts +165 -0
- package/src/token/refresh-token.ts +31 -0
- package/src/token/token-claims.ts +31 -0
- package/src/token/token-data.ts +33 -0
- package/src/token/token-id.ts +26 -0
- package/src/token/token-manager.ts +591 -0
- package/src/token/token-store.ts +78 -0
- package/src/token/types.ts +86 -0
- package/src/token/verify-token-claims.ts +65 -0
- package/tailwind.config.js +13 -0
- package/tsconfig.backend.json +9 -0
- package/tsconfig.frontend.json +11 -0
- package/tsconfig.json +8 -0
- package/tsconfig.tools.json +8 -0
@@ -0,0 +1,33 @@
|
|
1
|
+
/// <reference types="node" />
|
2
|
+
/// <reference types="node" />
|
3
|
+
import { z } from 'zod';
|
4
|
+
import { KnownNames } from './parser.js';
|
5
|
+
import { IncomingMessage, ServerResponse } from './types.js';
|
6
|
+
import { UrlReference } from './url.js';
|
7
|
+
export declare function parseRequestPayload<A extends readonly KnownNames[] = readonly KnownNames[]>(req: IncomingMessage, allow?: A): Promise<ReturnType<(Extract<{
|
8
|
+
readonly name: "json";
|
9
|
+
readonly test: (type: string) => type is "application/json" | `application/${string}+json`;
|
10
|
+
readonly parse: (buffer: Buffer) => import("./parser.js").Json;
|
11
|
+
}, {
|
12
|
+
name: A[number];
|
13
|
+
}> | Extract<{
|
14
|
+
readonly name: "urlencoded";
|
15
|
+
readonly test: (type: string) => type is "application/x-www-form-urlencoded";
|
16
|
+
readonly parse: (buffer: Buffer) => Partial<Record<string, string>>;
|
17
|
+
}, {
|
18
|
+
name: A[number];
|
19
|
+
}> | Extract<{
|
20
|
+
readonly name: "bytes";
|
21
|
+
readonly test: (type: string) => type is "application/octet-stream";
|
22
|
+
readonly parse: (buffer: Buffer) => Buffer;
|
23
|
+
}, {
|
24
|
+
name: A[number];
|
25
|
+
}>)["parse"]>>;
|
26
|
+
export declare function validateRequestPayload<S extends z.ZodTypeAny>(req: IncomingMessage, schema: S, allow?: readonly KnownNames[]): Promise<z.infer<S>>;
|
27
|
+
export declare function validateFetchMode(req: IncomingMessage, res: ServerResponse, expectedMode: readonly (null | 'navigate' | 'same-origin' | 'no-cors' | 'cors')[]): void;
|
28
|
+
export declare function validateReferer(req: IncomingMessage, res: ServerResponse, reference: UrlReference, allowNull?: boolean): void;
|
29
|
+
export declare function setupCsrfToken(req: IncomingMessage, res: ServerResponse, cookieName?: string): Promise<void>;
|
30
|
+
export declare function validateSameOrigin(req: IncomingMessage, res: ServerResponse, origin: string, allowNull?: boolean): void;
|
31
|
+
export declare function validateCsrfToken(req: IncomingMessage, res: ServerResponse, csrfToken: string, cookieName?: string, clearCookie?: boolean): void;
|
32
|
+
export declare function parseHttpCookies(req: IncomingMessage): null | Record<string, undefined | string>;
|
33
|
+
//# sourceMappingURL=request.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../../src/lib/http/request.ts"],"names":[],"mappings":";;AAGA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAGxC,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAC5D,OAAO,EAAE,YAAY,EAAY,MAAM,UAAU,CAAA;AAEjD,wBAAgB,mBAAmB,CACjC,CAAC,SAAS,SAAS,UAAU,EAAE,GAAG,SAAS,UAAU,EAAE,EACvD,GAAG,EAAE,eAAe,EAAE,KAAK,CAAC,EAAE,CAAC;;;;;;;;;;;;;;;;;;eAMhC;AAED,wBAAsB,sBAAsB,CAAC,CAAC,SAAS,CAAC,CAAC,UAAU,EACjE,GAAG,EAAE,eAAe,EACpB,MAAM,EAAE,CAAC,EACT,KAAK,GAAE,SAAS,UAAU,EAA2B,GACpD,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAGrB;AAED,wBAAgB,iBAAiB,CAC/B,GAAG,EAAE,eAAe,EACpB,GAAG,EAAE,cAAc,EACnB,YAAY,EAAE,SAAS,CACnB,IAAI,GACJ,UAAU,GACV,aAAa,GACb,SAAS,GACT,MAAM,CACT,EAAE,QAgBJ;AAED,wBAAgB,eAAe,CAC7B,GAAG,EAAE,eAAe,EACpB,GAAG,EAAE,cAAc,EACnB,SAAS,EAAE,YAAY,EACvB,SAAS,UAAQ,QAOlB;AAED,wBAAsB,cAAc,CAClC,GAAG,EAAE,eAAe,EACpB,GAAG,EAAE,cAAc,EACnB,UAAU,SAAe,iBAa1B;AAGD,wBAAgB,kBAAkB,CAChC,GAAG,EAAE,eAAe,EACpB,GAAG,EAAE,cAAc,EACnB,MAAM,EAAE,MAAM,EACd,SAAS,UAAO,QAMjB;AAED,wBAAgB,iBAAiB,CAC/B,GAAG,EAAE,eAAe,EACpB,GAAG,EAAE,cAAc,EACnB,SAAS,EAAE,MAAM,EACjB,UAAU,SAAe,EACzB,WAAW,UAAQ,QAwBpB;AAED,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,eAAe,GACnB,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,SAAS,GAAG,MAAM,CAAC,CAM3C"}
|
@@ -0,0 +1,86 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
exports.parseHttpCookies = exports.validateCsrfToken = exports.validateSameOrigin = exports.setupCsrfToken = exports.validateReferer = exports.validateFetchMode = exports.validateRequestPayload = exports.parseRequestPayload = void 0;
|
7
|
+
const cookie_1 = require("cookie");
|
8
|
+
const crypto_1 = require("crypto");
|
9
|
+
const http_errors_1 = __importDefault(require("http-errors"));
|
10
|
+
const response_js_1 = require("./response.js");
|
11
|
+
const stream_js_1 = require("./stream.js");
|
12
|
+
const url_js_1 = require("./url.js");
|
13
|
+
function parseRequestPayload(req, allow) {
|
14
|
+
return (0, stream_js_1.parseStream)((0, stream_js_1.decodeStream)(req, req.headers['content-encoding']), req.headers['content-type'], allow);
|
15
|
+
}
|
16
|
+
exports.parseRequestPayload = parseRequestPayload;
|
17
|
+
async function validateRequestPayload(req, schema, allow = ['json', 'urlencoded']) {
|
18
|
+
const payload = await parseRequestPayload(req, allow);
|
19
|
+
return schema.parseAsync(payload, { path: ['body'] });
|
20
|
+
}
|
21
|
+
exports.validateRequestPayload = validateRequestPayload;
|
22
|
+
function validateFetchMode(req, res, expectedMode) {
|
23
|
+
const reqMode = req.headers['sec-fetch-mode'] ?? null;
|
24
|
+
if (Array.isArray(reqMode)) {
|
25
|
+
throw (0, http_errors_1.default)(400, `Invalid sec-fetch-mode header`);
|
26
|
+
}
|
27
|
+
if (!expectedMode.includes(reqMode)) {
|
28
|
+
throw (0, http_errors_1.default)(403, reqMode
|
29
|
+
? `Forbidden sec-fetch-mode "${reqMode}" (expected ${expectedMode})`
|
30
|
+
: `Missing sec-fetch-mode (expected ${expectedMode})`);
|
31
|
+
}
|
32
|
+
}
|
33
|
+
exports.validateFetchMode = validateFetchMode;
|
34
|
+
function validateReferer(req, res, reference, allowNull = false) {
|
35
|
+
const referer = req.headers['referer'];
|
36
|
+
const refererUrl = referer ? new URL(referer) : null;
|
37
|
+
if (refererUrl ? !(0, url_js_1.urlMatch)(refererUrl, reference) : !allowNull) {
|
38
|
+
throw (0, http_errors_1.default)(403, `Invalid referer ${referer}`);
|
39
|
+
}
|
40
|
+
}
|
41
|
+
exports.validateReferer = validateReferer;
|
42
|
+
async function setupCsrfToken(req, res, cookieName = 'csrf_token') {
|
43
|
+
const csrfToken = (0, crypto_1.randomBytes)(8).toString('hex');
|
44
|
+
(0, response_js_1.appendHeader)(res, 'Set-Cookie', (0, cookie_1.serialize)(cookieName, csrfToken, {
|
45
|
+
secure: true,
|
46
|
+
httpOnly: false,
|
47
|
+
sameSite: 'lax',
|
48
|
+
path: req.url?.split('?', 1)[0] || '/',
|
49
|
+
}));
|
50
|
+
}
|
51
|
+
exports.setupCsrfToken = setupCsrfToken;
|
52
|
+
// CORS ensure not cross origin
|
53
|
+
function validateSameOrigin(req, res, origin, allowNull = true) {
|
54
|
+
const reqOrigin = req.headers['origin'];
|
55
|
+
if (reqOrigin ? reqOrigin !== origin : !allowNull) {
|
56
|
+
throw (0, http_errors_1.default)(403, `Invalid origin ${reqOrigin}`);
|
57
|
+
}
|
58
|
+
}
|
59
|
+
exports.validateSameOrigin = validateSameOrigin;
|
60
|
+
function validateCsrfToken(req, res, csrfToken, cookieName = 'csrf_token', clearCookie = false) {
|
61
|
+
const cookies = parseHttpCookies(req);
|
62
|
+
if (!csrfToken ||
|
63
|
+
!cookies ||
|
64
|
+
!cookieName ||
|
65
|
+
cookies[cookieName] !== csrfToken) {
|
66
|
+
throw (0, http_errors_1.default)(403, `Invalid CSRF token`);
|
67
|
+
}
|
68
|
+
if (clearCookie) {
|
69
|
+
(0, response_js_1.appendHeader)(res, 'Set-Cookie', (0, cookie_1.serialize)(cookieName, '', {
|
70
|
+
secure: true,
|
71
|
+
httpOnly: false,
|
72
|
+
sameSite: 'lax',
|
73
|
+
maxAge: 0,
|
74
|
+
}));
|
75
|
+
}
|
76
|
+
}
|
77
|
+
exports.validateCsrfToken = validateCsrfToken;
|
78
|
+
function parseHttpCookies(req) {
|
79
|
+
return 'cookies' in req && req.cookies // Already parsed by another middleware
|
80
|
+
? req.cookies
|
81
|
+
: req.headers['cookie']
|
82
|
+
? (req.cookies = (0, cookie_1.parse)(req.headers['cookie']))
|
83
|
+
: null;
|
84
|
+
}
|
85
|
+
exports.parseHttpCookies = parseHttpCookies;
|
86
|
+
//# sourceMappingURL=request.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"request.js","sourceRoot":"","sources":["../../../src/lib/http/request.ts"],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,EAAC,GAAG,EAAE,kBAAkB,SAAS,EAAE,CAAC,CAAA;IAC3D,CAAC;AACH,CAAC;AAVD,gDAUC;AAED,SAAgB,iBAAiB,CAC/B,GAAoB,EACpB,GAAmB,EACnB,SAAiB,EACjB,UAAU,GAAG,YAAY,EACzB,WAAW,GAAG,KAAK;IAEnB,MAAM,OAAO,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAA;IACrC,IACE,CAAC,SAAS;QACV,CAAC,OAAO;QACR,CAAC,UAAU;QACX,OAAO,CAAC,UAAU,CAAC,KAAK,SAAS,EACjC,CAAC;QACD,MAAM,IAAA,qBAAe,EAAC,GAAG,EAAE,oBAAoB,CAAC,CAAA;IAClD,CAAC;IAED,IAAI,WAAW,EAAE,CAAC;QAChB,IAAA,0BAAY,EACV,GAAG,EACH,YAAY,EACZ,IAAA,kBAAe,EAAC,UAAU,EAAE,EAAE,EAAE;YAC9B,MAAM,EAAE,IAAI;YACZ,QAAQ,EAAE,KAAK;YACf,QAAQ,EAAE,KAAK;YACf,MAAM,EAAE,CAAC;SACV,CAAC,CACH,CAAA;IACH,CAAC;AACH,CAAC;AA7BD,8CA6BC;AAED,SAAgB,gBAAgB,CAC9B,GAAoB;IAEpB,OAAO,SAAS,IAAI,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,uCAAuC;QAC5E,CAAC,CAAE,GAAG,CAAC,OAAe;QACtB,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC;YACrB,CAAC,CAAC,CAAE,GAAW,CAAC,OAAO,GAAG,IAAA,cAAW,EAAC,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;YAC7D,CAAC,CAAC,IAAI,CAAA;AACZ,CAAC;AARD,4CAQC"}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
/// <reference types="node" />
|
2
|
+
/// <reference types="node" />
|
3
|
+
/// <reference types="node" />
|
4
|
+
import { Readable } from 'node:stream';
|
5
|
+
import { Handler, ServerResponse } from './types.js';
|
6
|
+
export declare function appendHeader(res: ServerResponse, header: string, value: string | readonly string[]): void;
|
7
|
+
export declare function writeRedirect(res: ServerResponse, url: string, status?: number): void;
|
8
|
+
export declare function writeStream(res: ServerResponse, stream: Readable, contentType?: string, status?: number): Promise<void>;
|
9
|
+
export declare function writeBuffer(res: ServerResponse, buffer: Buffer, contentType?: string, status?: number): Promise<void>;
|
10
|
+
export declare function writeJson(res: ServerResponse, payload: unknown, status?: number, contentType?: string): Promise<void>;
|
11
|
+
export declare function staticJsonHandler(value: unknown, contentType?: string, status?: number): Handler<unknown>;
|
12
|
+
export declare function writeHtml(res: ServerResponse, html: Buffer | string, status?: number, contentType?: string): Promise<void>;
|
13
|
+
//# sourceMappingURL=response.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"response.d.ts","sourceRoot":"","sources":["../../../src/lib/http/response.ts"],"names":[],"mappings":";;;AAAA,OAAO,EAAe,QAAQ,EAAa,MAAM,aAAa,CAAA;AAI9D,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAEpD,wBAAgB,YAAY,CAC1B,GAAG,EAAE,cAAc,EACnB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,GAChC,IAAI,CAQN;AAED,wBAAgB,aAAa,CAC3B,GAAG,EAAE,cAAc,EACnB,GAAG,EAAE,MAAM,EACX,MAAM,SAAM,GACX,IAAI,CAEN;AA2BD,wBAAsB,WAAW,CAC/B,GAAG,EAAE,cAAc,EACnB,MAAM,EAAE,QAAQ,EAChB,WAAW,SACiB,EAC5B,MAAM,SAAM,GACX,OAAO,CAAC,IAAI,CAAC,CAgCf;AAED,wBAAsB,WAAW,CAC/B,GAAG,EAAE,cAAc,EACnB,MAAM,EAAE,MAAM,EACd,WAAW,CAAC,EAAE,MAAM,EACpB,MAAM,SAAM,GACX,OAAO,CAAC,IAAI,CAAC,CAGf;AAED,wBAAsB,SAAS,CAC7B,GAAG,EAAE,cAAc,EACnB,OAAO,EAAE,OAAO,EAChB,MAAM,SAAM,EACZ,WAAW,SAAqB,GAC/B,OAAO,CAAC,IAAI,CAAC,CAGf;AAED,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,OAAO,EACd,WAAW,SAAqB,EAChC,MAAM,SAAM,GACX,OAAO,CAAC,OAAO,CAAC,CAKlB;AAED,wBAAsB,SAAS,CAC7B,GAAG,EAAE,cAAc,EACnB,IAAI,EAAE,MAAM,GAAG,MAAM,EACrB,MAAM,SAAM,EACZ,WAAW,SAAc,GACxB,OAAO,CAAC,IAAI,CAAC,CAGf"}
|
@@ -0,0 +1,98 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.writeHtml = exports.staticJsonHandler = exports.writeJson = exports.writeBuffer = exports.writeStream = exports.writeRedirect = exports.appendHeader = void 0;
|
4
|
+
const node_stream_1 = require("node:stream");
|
5
|
+
const promises_1 = require("node:stream/promises");
|
6
|
+
const node_zlib_1 = require("node:zlib");
|
7
|
+
function appendHeader(res, header, value) {
|
8
|
+
const existing = res.getHeader(header);
|
9
|
+
if (existing == null) {
|
10
|
+
res.setHeader(header, value);
|
11
|
+
}
|
12
|
+
else {
|
13
|
+
const arr = Array.isArray(existing) ? existing : [String(existing)];
|
14
|
+
res.setHeader(header, arr.concat(value));
|
15
|
+
}
|
16
|
+
}
|
17
|
+
exports.appendHeader = appendHeader;
|
18
|
+
function writeRedirect(res, url, status = 302) {
|
19
|
+
res.writeHead(status, { Location: url }).end();
|
20
|
+
}
|
21
|
+
exports.writeRedirect = writeRedirect;
|
22
|
+
function negotiateEncoding(accept) {
|
23
|
+
if (accept?.includes('br'))
|
24
|
+
return 'br';
|
25
|
+
if (accept?.includes('gzip'))
|
26
|
+
return 'gzip';
|
27
|
+
return 'identity';
|
28
|
+
}
|
29
|
+
function getEncoder(encoding) {
|
30
|
+
switch (encoding) {
|
31
|
+
case 'br':
|
32
|
+
return (0, node_zlib_1.createBrotliCompress)({
|
33
|
+
// Default quality is too slow
|
34
|
+
params: { [node_zlib_1.constants.BROTLI_PARAM_QUALITY]: 5 },
|
35
|
+
});
|
36
|
+
case 'gzip':
|
37
|
+
return (0, node_zlib_1.createGzip)();
|
38
|
+
case 'identity':
|
39
|
+
return new node_stream_1.PassThrough();
|
40
|
+
default:
|
41
|
+
throw new Error(`Unsupported encoding: ${encoding}`);
|
42
|
+
}
|
43
|
+
}
|
44
|
+
const ifString = (value) => typeof value === 'string' ? value : undefined;
|
45
|
+
async function writeStream(res, stream, contentType = ifString(stream.headers?.['content-type']) ||
|
46
|
+
'application/octet-stream', status = 200) {
|
47
|
+
res.statusCode = status;
|
48
|
+
res.setHeader('content-type', contentType);
|
49
|
+
appendHeader(res, 'vary', 'accept-encoding');
|
50
|
+
const encoding = negotiateEncoding(res.req.headers['accept-encoding']);
|
51
|
+
res.setHeader('content-encoding', encoding);
|
52
|
+
res.setHeader('transfer-encoding', 'chunked');
|
53
|
+
if (res.req.method === 'HEAD') {
|
54
|
+
res.end();
|
55
|
+
stream.destroy();
|
56
|
+
return;
|
57
|
+
}
|
58
|
+
try {
|
59
|
+
await (0, promises_1.pipeline)(stream, getEncoder(encoding), res);
|
60
|
+
}
|
61
|
+
catch (err) {
|
62
|
+
// Prevent the socket from being left open in a bad state
|
63
|
+
res.socket?.destroy();
|
64
|
+
if (err != null && typeof err === 'object') {
|
65
|
+
// If an abort signal is used, we can consider this function's job successful
|
66
|
+
if ('name' in err && err.name === 'AbortError')
|
67
|
+
return;
|
68
|
+
// If the client closes the connection, we don't care about the error
|
69
|
+
if ('code' in err && err.code === 'ERR_STREAM_PREMATURE_CLOSE')
|
70
|
+
return;
|
71
|
+
}
|
72
|
+
throw err;
|
73
|
+
}
|
74
|
+
}
|
75
|
+
exports.writeStream = writeStream;
|
76
|
+
async function writeBuffer(res, buffer, contentType, status = 200) {
|
77
|
+
const stream = node_stream_1.Readable.from([buffer]);
|
78
|
+
return writeStream(res, stream, contentType, status);
|
79
|
+
}
|
80
|
+
exports.writeBuffer = writeBuffer;
|
81
|
+
async function writeJson(res, payload, status = 200, contentType = 'application/json') {
|
82
|
+
const buffer = Buffer.from(JSON.stringify(payload));
|
83
|
+
return writeBuffer(res, buffer, contentType, status);
|
84
|
+
}
|
85
|
+
exports.writeJson = writeJson;
|
86
|
+
function staticJsonHandler(value, contentType = 'application/json', status = 200) {
|
87
|
+
const buffer = Buffer.from(JSON.stringify(value));
|
88
|
+
return function (req, res, next) {
|
89
|
+
void writeBuffer(res, buffer, contentType, status).catch(next);
|
90
|
+
};
|
91
|
+
}
|
92
|
+
exports.staticJsonHandler = staticJsonHandler;
|
93
|
+
async function writeHtml(res, html, status = 200, contentType = 'text/html') {
|
94
|
+
const buffer = Buffer.isBuffer(html) ? html : Buffer.from(html);
|
95
|
+
return writeBuffer(res, buffer, contentType, status);
|
96
|
+
}
|
97
|
+
exports.writeHtml = writeHtml;
|
98
|
+
//# sourceMappingURL=response.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"response.js","sourceRoot":"","sources":["../../../src/lib/http/response.ts"],"names":[],"mappings":";;;AAAA,6CAA8D;AAC9D,mDAA+C;AAC/C,yCAAuE;AAIvE,SAAgB,YAAY,CAC1B,GAAmB,EACnB,MAAc,EACd,KAAiC;IAEjC,MAAM,QAAQ,GAAG,GAAG,CAAC,SAAS,CAAC,MAAM,CAAC,CAAA;IACtC,IAAI,QAAQ,IAAI,IAAI,EAAE,CAAC;QACrB,GAAG,CAAC,SAAS,CAAC,MAAM,EAAE,KAAK,CAAC,CAAA;IAC9B,CAAC;SAAM,CAAC;QACN,MAAM,GAAG,GAAG,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAA;QACnE,GAAG,CAAC,SAAS,CAAC,MAAM,EAAE,GAAG,C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Ctx } from './context.js';
|
3
|
+
import { MethodMatcherInput } from './method.js';
|
4
|
+
import { Params, Path } from './path.js';
|
5
|
+
import { IncomingMessage, Middleware, ServerResponse } from './types.js';
|
6
|
+
export type RouteCtx<T, P extends Params> = SubCtx<T, {
|
7
|
+
params: Readonly<P>;
|
8
|
+
}>;
|
9
|
+
export type RouteMiddleware<T, P extends Params, Req = IncomingMessage, Res = ServerResponse> = Middleware<RouteCtx<T, P>, Req, Res>;
|
10
|
+
/**
|
11
|
+
* @example
|
12
|
+
* ```ts
|
13
|
+
* createRoute<{ foo: string }>('GET', '/foo/:foo', function (req, res) {
|
14
|
+
* console.log(this.params.foo) // OK
|
15
|
+
* console.log(this.params.bar) // Error
|
16
|
+
* })
|
17
|
+
*
|
18
|
+
* createRoute<{ foo: string }>(['POST', 'PUT'], '/foo/:foo', function (req, res) {
|
19
|
+
* console.log(this.params.foo) // OK
|
20
|
+
* console.log(this.params.bar) // Error
|
21
|
+
* })
|
22
|
+
* ```
|
23
|
+
*/
|
24
|
+
export declare function createRoute<P extends Params, T = void, Req extends IncomingMessage = IncomingMessage, Res extends ServerResponse = ServerResponse>(method: MethodMatcherInput, path: Path<P>, ...mw: RouteMiddleware<T, P, Req, Res>[]): Middleware<T, Req, Res>;
|
25
|
+
//# sourceMappingURL=route.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../src/lib/http/route.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAU,MAAM,cAAc,CAAA;AAC7C,OAAO,EAAE,kBAAkB,EAAuB,MAAM,aAAa,CAAA;AAErE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAqB,MAAM,WAAW,CAAA;AAC3D,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAExE,MAAM,MAAM,QAAQ,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,IAAI,MAAM,CAAC,CAAC,EAAE;IAAE,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAA;CAAE,CAAC,CAAA;AAC9E,MAAM,MAAM,eAAe,CACzB,CAAC,EACD,CAAC,SAAS,MAAM,EAChB,GAAG,GAAG,eAAe,EACrB,GAAG,GAAG,cAAc,IAClB,UAAU,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,CAAA;AAExC;;;;;;;;;;;;;GAaG;AACH,wBAAgB,WAAW,CACzB,CAAC,SAAS,MAAM,EAChB,CAAC,GAAG,IAAI,EACR,GAAG,SAAS,eAAe,GAAG,eAAe,EAC7C,GAAG,SAAS,cAAc,GAAG,cAAc,EAE3C,MAAM,EAAE,kBAAkB,EAC1B,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,EACb,GAAG,EAAE,EAAE,eAAe,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,GACvC,UAAU,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,CAkBzB"}
|
@@ -0,0 +1,39 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.createRoute = void 0;
|
4
|
+
const context_js_1 = require("./context.js");
|
5
|
+
const method_js_1 = require("./method.js");
|
6
|
+
const middleware_js_1 = require("./middleware.js");
|
7
|
+
const path_js_1 = require("./path.js");
|
8
|
+
/**
|
9
|
+
* @example
|
10
|
+
* ```ts
|
11
|
+
* createRoute<{ foo: string }>('GET', '/foo/:foo', function (req, res) {
|
12
|
+
* console.log(this.params.foo) // OK
|
13
|
+
* console.log(this.params.bar) // Error
|
14
|
+
* })
|
15
|
+
*
|
16
|
+
* createRoute<{ foo: string }>(['POST', 'PUT'], '/foo/:foo', function (req, res) {
|
17
|
+
* console.log(this.params.foo) // OK
|
18
|
+
* console.log(this.params.bar) // Error
|
19
|
+
* })
|
20
|
+
* ```
|
21
|
+
*/
|
22
|
+
function createRoute(method, path, ...mw) {
|
23
|
+
const paramsMatcher = (0, path_js_1.createPathMatcher)(path);
|
24
|
+
const methodMatcher = (0, method_js_1.createMethodMatcher)(method);
|
25
|
+
const middleware = (0, middleware_js_1.combineMiddlewares)(mw, { skipKeyword: 'route' });
|
26
|
+
return function (req, res, next) {
|
27
|
+
if (methodMatcher(req)) {
|
28
|
+
const pathname = req.url?.split('?')[0] ?? '/';
|
29
|
+
const params = paramsMatcher(pathname);
|
30
|
+
if (params) {
|
31
|
+
const context = (0, context_js_1.subCtx)(this, 'params', params);
|
32
|
+
return middleware.call(context, req, res, next);
|
33
|
+
}
|
34
|
+
}
|
35
|
+
return next();
|
36
|
+
};
|
37
|
+
}
|
38
|
+
exports.createRoute = createRoute;
|
39
|
+
//# sourceMappingURL=route.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"route.js","sourceRoot":"","sources":["../../../src/lib/http/route.ts"],"names":[],"mappings":";;;AAAA,6CAA6C;AAC7C,2CAAqE;AACrE,mDAAoD;AACpD,uCAA2D;AAW3D;;;;;;;;;;;;;GAaG;AACH,SAAgB,WAAW,CAMzB,MAA0B,EAC1B,IAAa,EACb,GAAG,EAAqC;IAExC,MAAM,aAAa,GAAG,IAAA,2BAAiB,EAAI,IAAI,CAAC,CAAA;IAChD,MAAM,aAAa,GAAG,IAAA,+BAAmB,EAAC,MAAM,CAAC,CAAA;IAEjD,MAAM,UAAU,GAAG,IAAA,kCAAkB,EAAC,EAAE,EAAE,EAAE,WAAW,EAAE,OAAO,EAAE,CAAC,CAAA;IAEnE,OAAO,UAAU,GAAG,EAAE,GAAG,EAAE,IAAI;QAC7B,IAAI,aAAa,CAAC,GAAG,CAAC,EAAE,CAAC;YACvB,MAAM,QAAQ,GAAG,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,CAAA;YAC9C,MAAM,MAAM,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAA;YACtC,IAAI,MAAM,EAAE,CAAC;gBACX,MAAM,OAAO,GAAG,IAAA,mBAAM,EAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAA;gBAC9C,OAAO,UAAU,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,CAAA;YACjD,CAAC;QACH,CAAC;QAED,OAAO,IAAI,EAAE,CAAA;IACf,CAAC,CAAA;AACH,CAAC;AA3BD,kCA2BC"}
|
@@ -0,0 +1,32 @@
|
|
1
|
+
/// <reference types="node" />
|
2
|
+
/// <reference types="node" />
|
3
|
+
import { SubCtx } from './context.js';
|
4
|
+
import { MethodMatcherInput } from './method.js';
|
5
|
+
import { Params, Path } from './path.js';
|
6
|
+
import { RouteMiddleware } from './route.js';
|
7
|
+
import { IncomingMessage, Middleware, ServerResponse } from './types.js';
|
8
|
+
export type RouterCtx<T> = SubCtx<T, {
|
9
|
+
url: Readonly<URL>;
|
10
|
+
}>;
|
11
|
+
export type RouterMiddleware<T = void, Req = IncomingMessage, Res = ServerResponse> = Middleware<RouterCtx<T>, Req, Res>;
|
12
|
+
export declare class Router<T = void, Req extends IncomingMessage = IncomingMessage, Res extends ServerResponse = ServerResponse> {
|
13
|
+
private readonly url?;
|
14
|
+
private readonly middlewares;
|
15
|
+
constructor(url?: {
|
16
|
+
/** Used to build the origin of the {@link RouterCtx['url']} context property */
|
17
|
+
protocol?: string | undefined;
|
18
|
+
/** Used to build the origin of the {@link RouterCtx['url']} context property */
|
19
|
+
host?: string | undefined;
|
20
|
+
} | undefined);
|
21
|
+
use(...middlewares: RouterMiddleware<T, Req, Res>[]): this;
|
22
|
+
all<P extends Params = Params>(path: Path<P>, ...mw: RouteMiddleware<RouterCtx<T>, P, Req, Res>[]): this;
|
23
|
+
get<P extends Params = Params>(path: Path<P>, ...mw: RouteMiddleware<RouterCtx<T>, P, Req, Res>[]): this;
|
24
|
+
post<P extends Params = Params>(path: Path<P>, ...mw: RouteMiddleware<RouterCtx<T>, P, Req, Res>[]): this;
|
25
|
+
options<P extends Params = Params>(path: Path<P>, ...mw: RouteMiddleware<RouterCtx<T>, P, Req, Res>[]): this;
|
26
|
+
addRoute<P extends Params>(method: MethodMatcherInput, path: Path<P>, ...mw: RouteMiddleware<RouterCtx<T>, P, Req, Res>[]): this;
|
27
|
+
/**
|
28
|
+
* @returns router middleware which dispatches a route matching the request.
|
29
|
+
*/
|
30
|
+
buildHandler(): import("./types.js").Handler<T, Req, Res>;
|
31
|
+
}
|
32
|
+
//# sourceMappingURL=router.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../../src/lib/http/router.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAE,MAAM,EAAU,MAAM,cAAc,CAAA;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAEhD,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AACxC,OAAO,EAAE,eAAe,EAAe,MAAM,YAAY,CAAA;AACzD,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAExE,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC,EAAE;IAAE,GAAG,EAAE,QAAQ,CAAC,GAAG,CAAC,CAAA;CAAE,CAAC,CAAA;AAC5D,MAAM,MAAM,gBAAgB,CAC1B,CAAC,GAAG,IAAI,EACR,GAAG,GAAG,eAAe,EACrB,GAAG,GAAG,cAAc,IAClB,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,CAAA;AAEtC,qBAAa,MAAM,CACjB,CAAC,GAAG,IAAI,EACR,GAAG,SAAS,eAAe,GAAG,eAAe,EAC7C,GAAG,SAAS,cAAc,GAAG,cAAc;IAKzC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC;IAHvB,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CA2Cb"}
|
@@ -0,0 +1,74 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.Router = void 0;
|
4
|
+
const context_js_1 = require("./context.js");
|
5
|
+
const middleware_js_1 = require("./middleware.js");
|
6
|
+
const route_js_1 = require("./route.js");
|
7
|
+
class Router {
|
8
|
+
url;
|
9
|
+
middlewares = [];
|
10
|
+
constructor(url) {
|
11
|
+
this.url = url;
|
12
|
+
}
|
13
|
+
use(...middlewares) {
|
14
|
+
this.middlewares.push(...middlewares);
|
15
|
+
return this;
|
16
|
+
}
|
17
|
+
all(path, ...mw) {
|
18
|
+
return this.addRoute('*', path, ...mw);
|
19
|
+
}
|
20
|
+
get(path, ...mw) {
|
21
|
+
return this.addRoute('GET', path, ...mw);
|
22
|
+
}
|
23
|
+
post(path, ...mw) {
|
24
|
+
return this.addRoute('POST', path, ...mw);
|
25
|
+
}
|
26
|
+
options(path, ...mw) {
|
27
|
+
return this.addRoute('OPTIONS', path, ...mw);
|
28
|
+
}
|
29
|
+
addRoute(method, path, ...mw) {
|
30
|
+
return this.use((0, route_js_1.createRoute)(method, path, ...mw));
|
31
|
+
}
|
32
|
+
/**
|
33
|
+
* @returns router middleware which dispatches a route matching the request.
|
34
|
+
*/
|
35
|
+
buildHandler() {
|
36
|
+
const routerUrl = this.url;
|
37
|
+
// Calling next('router') from a middleware will skip all the remaining
|
38
|
+
// middlewares in the stack.
|
39
|
+
const middleware = (0, middleware_js_1.combineMiddlewares)(this.middlewares, {
|
40
|
+
skipKeyword: 'router',
|
41
|
+
});
|
42
|
+
return (0, middleware_js_1.asHandler)(function (req, res, next) {
|
43
|
+
// Make sure that the context contains a "url". This will allow the add()
|
44
|
+
// method to match routes based on the pathname and will allow routes to
|
45
|
+
// access the query params (through this.url.searchParams).
|
46
|
+
let url;
|
47
|
+
if (!routerUrl &&
|
48
|
+
this != null &&
|
49
|
+
typeof this === 'object' &&
|
50
|
+
'url' in this &&
|
51
|
+
this.url instanceof URL) {
|
52
|
+
// If the context already contains a "url" (router inside router), let's
|
53
|
+
// use it.
|
54
|
+
url = this.url;
|
55
|
+
}
|
56
|
+
else {
|
57
|
+
// Parse the URL using node's URL parser.
|
58
|
+
try {
|
59
|
+
const protocol = routerUrl?.protocol || 'https:';
|
60
|
+
const host = req.headers.host || routerUrl?.host || 'localhost';
|
61
|
+
const pathname = req.url || '/';
|
62
|
+
url = new URL(pathname, `${protocol}//${host}`);
|
63
|
+
}
|
64
|
+
catch (err) {
|
65
|
+
return next(Object.assign(err, { status: 400, statusCode: 400 }));
|
66
|
+
}
|
67
|
+
}
|
68
|
+
const context = (0, context_js_1.subCtx)(this, 'url', url);
|
69
|
+
middleware.call(context, req, res, next);
|
70
|
+
});
|
71
|
+
}
|
72
|
+
}
|
73
|
+
exports.Router = Router;
|
74
|
+
//# sourceMappingURL=router.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"router.js","sourceRoot":"","sources":["../../../src/lib/http/router.ts"],"names":[],"mappings":";;;AAAA,6CAA6C;AAE7C,mDAA+D;AAE/D,yCAAyD;AAUzD,MAAa,MAAM;IAQE;IAHF,WAAW,GAAoC,EAAE,CAAA;IAElE,YACmB,GAKhB;QALgB,QAAG,GAAH,GAAG,CAKnB;IACA,CAAC;IAEJ,GAAG,CAAC,GAAG,WAA4C;QACjD,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,WAAW,CAAC,CAAA;QACrC,OAAO,IAAI,CAAA;IACb,CAAC;IAED,GAAG,CACD,IAAa,EACb,GAAG,EAAgD;QAEnD,OAAO,IAAI,CAAC,QAAQ,CAAI,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,CAAA;IAC3C,CAAC;IAED,GAAG,CACD,IAAa,EACb,GAAG,EAAgD;QAEnD,OAAO,IAAI,CAAC,QAAQ,CAAI,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,CAAA;IAC7C,CAAC;IAED,I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I,WAAW,CAAA;oBAC/D,MAAM,QAAQ,GAAG,GAAG,CAAC,GAAG,IAAI,GAAG,CAAA;oBAC/B,GAAG,GAAG,IAAI,GAAG,CAAC,QAAQ,EAAE,GAAG,QAAQ,KAAK,IAAI,EAAE,CAAC,CAAA;gBACjD,CAAC;gBAAC,OAAO,GAAG,EAAE,CAAC;oBACb,OAAO,IAAI,CACT,MAAM,CAAC,MAAM,CAAC,GAAY,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,UAAU,EAAE,GAAG,EAAE,CAAC,CAC9D,CAAA;gBACH,CAAC;YACH,CAAC;YAED,MAAM,OAAO,GAAG,IAAA,mBAAM,EAAC,IAAI,EAAE,KAAK,EAAE,GAAG,CAAC,CAAA;YACxC,UAAU,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,CAAA;QAC1C,CAAC,CAAC,CAAA;IACJ,CAAC;CACF;AAvGD,wBAuGC"}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
/// <reference types="node" />
|
2
|
+
/// <reference types="node" />
|
3
|
+
import { Readable } from 'node:stream';
|
4
|
+
import { KnownNames, KnownParser, KnownTypes, ParserForType, ParserResult } from './parser.js';
|
5
|
+
export declare function readStream(req: Readable): Promise<Buffer>;
|
6
|
+
export declare function decodeStream(req: Readable, encoding?: string): Readable;
|
7
|
+
export declare function parseStream<T extends KnownTypes, A extends readonly KnownNames[] = readonly KnownNames[]>(req: Readable, contentType: T, allow?: A): Promise<ParserResult<ParserForType<Extract<KnownParser, {
|
8
|
+
name: A[number];
|
9
|
+
}>, T>>>;
|
10
|
+
export declare function parseStream<A extends readonly KnownNames[] = readonly KnownNames[]>(req: Readable, contentType: unknown, allow?: A): Promise<ParserResult<Extract<KnownParser, {
|
11
|
+
name: A[number];
|
12
|
+
}>>>;
|
13
|
+
//# sourceMappingURL=stream.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../../src/lib/http/stream.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAe,QAAQ,EAAE,MAAM,aAAa,CAAA;AAKnD,OAAO,EACL,UAAU,EACV,WAAW,EACX,UAAU,EACV,aAAa,EACb,YAAY,EAEb,MAAM,aAAa,CAAA;AAEpB,wBAAsB,UAAU,CAAC,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,CAQ/D;AAED,wBAAgB,YAAY,CAC1B,GAAG,EAAE,QAAQ,EACb,QAAQ,GAAE,MAAmB,GAC5B,QAAQ,CAWV;AAED,wBAAsB,WAAW,CAC/B,CAAC,SAAS,UAAU,EACpB,CAAC,SAAS,SAAS,UAAU,EAAE,GAAG,SAAS,UAAU,EAAE,EAEvD,GAAG,EAAE,QAAQ,EACb,WAAW,EAAE,CAAC,EACd,KAAK,CAAC,EAAE,CAAC,GACR,OAAO,CACR,YAAY,CAAC,aAAa,CAAC,OAAO,CAAC,WAAW,EAAE;IAAE,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAA;CAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAC1E,CAAA;AACD,wBAAsB,WAAW,CAC/B,CAAC,SAAS,SAAS,UAAU,EAAE,GAAG,SAAS,UAAU,EAAE,EAEvD,GAAG,EAAE,QAAQ,EACb,WAAW,EAAE,OAAO,EACpB,KAAK,CAAC,EAAE,CAAC,GACR,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC,WAAW,EAAE;IAAE,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAA;CAAE,CAAC,CAAC,CAAC,CAAA"}
|
@@ -0,0 +1,46 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
exports.parseStream = exports.decodeStream = exports.readStream = void 0;
|
7
|
+
const node_stream_1 = require("node:stream");
|
8
|
+
const node_zlib_1 = require("node:zlib");
|
9
|
+
const http_errors_1 = __importDefault(require("http-errors"));
|
10
|
+
const parser_js_1 = require("./parser.js");
|
11
|
+
async function readStream(req) {
|
12
|
+
const chunks = [];
|
13
|
+
let totalLength = 0;
|
14
|
+
for await (const chunk of req) {
|
15
|
+
chunks.push(chunk);
|
16
|
+
totalLength += chunk.length;
|
17
|
+
}
|
18
|
+
return Buffer.concat(chunks, totalLength);
|
19
|
+
}
|
20
|
+
exports.readStream = readStream;
|
21
|
+
function decodeStream(req, encoding = 'identity') {
|
22
|
+
switch (encoding) {
|
23
|
+
case 'deflate':
|
24
|
+
return req.compose((0, node_zlib_1.createInflate)());
|
25
|
+
case 'gzip':
|
26
|
+
return req.compose((0, node_zlib_1.createGunzip)());
|
27
|
+
case 'identity':
|
28
|
+
return req.compose(new node_stream_1.PassThrough());
|
29
|
+
default:
|
30
|
+
throw (0, http_errors_1.default)(415, 'Unsupported content-encoding');
|
31
|
+
}
|
32
|
+
}
|
33
|
+
exports.decodeStream = decodeStream;
|
34
|
+
async function parseStream(req, contentType = 'application/octet-stream', allow) {
|
35
|
+
if (typeof contentType !== 'string') {
|
36
|
+
throw (0, http_errors_1.default)(400, 'Invalid content-type');
|
37
|
+
}
|
38
|
+
const parser = parser_js_1.parsers.find((parser) => allow?.includes(parser.name) !== false && parser.test(contentType));
|
39
|
+
if (!parser) {
|
40
|
+
throw (0, http_errors_1.default)(400, 'Unsupported content-type');
|
41
|
+
}
|
42
|
+
const buffer = await readStream(req);
|
43
|
+
return parser.parse(buffer);
|
44
|
+
}
|
45
|
+
exports.parseStream = parseStream;
|
46
|
+
//# sourceMappingURL=stream.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"stream.js","sourceRoot":"","sources":["../../../src/lib/http/stream.ts"],"names":[],"mappings":";;;;;;AAAA,6CAAmD;AACnD,yCAAuD;AAEvD,8DAAyC;AAEzC,2CAOoB;AAEb,KAAK,UA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IAAA,qBAAe,EAAC,GAAG,EAAE,0BAA0B,CAAC,CAAA;IACxD,CAAC;IAED,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,GAAG,CAAC,CAAA;IACpC,OAAO,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;AAC7B,CAAC;AApBD,kCAoBC"}
|
@@ -0,0 +1,7 @@
|
|
1
|
+
/// <reference types="node" />
|
2
|
+
import type { IncomingMessage, ServerResponse } from 'node:http';
|
3
|
+
export { IncomingMessage, ServerResponse };
|
4
|
+
export type NextFunction = (err?: unknown) => void;
|
5
|
+
export type Middleware<T = void, Req = IncomingMessage, Res = ServerResponse> = (this: T, req: Req, res: Res, next: NextFunction) => void | PromiseLike<void>;
|
6
|
+
export type Handler<T = void, Req = IncomingMessage, Res = ServerResponse> = (this: T, req: Req, res: Res, next?: NextFunction) => void;
|
7
|
+
//# sourceMappingURL=types.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/lib/http/types.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAChE,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,CAAA;AAE1C,MAAM,MAAM,YAAY,GAAG,CAAC,GAAG,CAAC,EAAE,OAAO,KAAK,IAAI,CAAA;AAElD,MAAM,MAAM,UAAU,CACpB,CAAC,GAAG,IAAI,EACR,GAAG,GAAG,eAAe,EACrB,GAAG,GAAG,cAAc,IAClB,CACF,IAAI,EAAE,CAAC,EACP,GAAG,EAAE,GAAG,EACR,GAAG,EAAE,GAAG,EACR,IAAI,EAAE,YAAY,KACf,IAAI,GAAG,WAAW,CAAC,IAAI,CAAC,CAAA;AAE7B,MAAM,MAAM,OAAO,CAAC,CAAC,GAAG,IAAI,EAAE,GAAG,GAAG,eAAe,EAAE,GAAG,GAAG,cAAc,IAAI,CAC3E,IAAI,EAAE,CAAC,EACP,GAAG,EAAE,GAAG,EACR,GAAG,EAAE,GAAG,EACR,IAAI,CAAC,EAAE,YAAY,KAChB,IAAI,CAAA"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/lib/http/types.ts"],"names":[],"mappings":""}
|
@@ -0,0 +1,8 @@
|
|
1
|
+
/// <reference types="node" />
|
2
|
+
export type UrlReference = {
|
3
|
+
origin?: string;
|
4
|
+
pathname?: string;
|
5
|
+
searchParams?: Iterable<readonly [string, string]>;
|
6
|
+
};
|
7
|
+
export declare function urlMatch(url: URL, reference: UrlReference): boolean;
|
8
|
+
//# sourceMappingURL=url.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"url.d.ts","sourceRoot":"","sources":["../../../src/lib/http/url.ts"],"names":[],"mappings":";AAAA,MAAM,MAAM,YAAY,GAAG;IACzB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,YAAY,CAAC,EAAE,QAAQ,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;CACnD,CAAA;AAED,wBAAgB,QAAQ,CAAC,GAAG,EAAE,GAAG,EAAE,SAAS,EAAE,YAAY,WAgBzD"}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.urlMatch = void 0;
|
4
|
+
function urlMatch(url, reference) {
|
5
|
+
if (reference.origin !== undefined) {
|
6
|
+
if (url.origin !== reference.origin)
|
7
|
+
return false;
|
8
|
+
}
|
9
|
+
if (reference.pathname !== undefined) {
|
10
|
+
if (url.pathname !== reference.pathname)
|
11
|
+
return false;
|
12
|
+
}
|
13
|
+
if (reference.searchParams !== undefined) {
|
14
|
+
for (const [key, value] of reference.searchParams) {
|
15
|
+
if (url.searchParams.get(key) !== value)
|
16
|
+
return false;
|
17
|
+
}
|
18
|
+
}
|
19
|
+
return true;
|
20
|
+
}
|
21
|
+
exports.urlMatch = urlMatch;
|
22
|
+
//# sourceMappingURL=url.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"url.js","sourceRoot":"","sources":["../../../src/lib/http/url.ts"],"names":[],"mappings":";;;AAMA,SAAgB,QAAQ,CAAC,GAAQ,EAAE,SAAuB;IACxD,IAAI,SAAS,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;QACnC,IAAI,GAAG,CAAC,MAAM,KAAK,SAAS,CAAC,MAAM;YAAE,OAAO,KAAK,CAAA;IACnD,CAAC;IAED,IAAI,SAAS,CAAC,QAAQ,KAAK,SAAS,EAAE,CAAC;QACrC,IAAI,GAAG,CAAC,QAAQ,KAAK,SAAS,CAAC,QAAQ;YAAE,OAAO,KAAK,CAAA;IACvD,CAAC;IAED,IAAI,SAAS,CAAC,YAAY,KAAK,SAAS,EAAE,CAAC;QACzC,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,SAAS,CAAC,YAAY,EAAE,CAAC;YAClD,IAAI,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,KAAK;gBAAE,OAAO,KAAK,CAAA;QACvD,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAA;AACb,CAAC;AAhBD,4BAgBC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"redis.d.ts","sourceRoot":"","sources":["../../src/lib/redis.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,YAAY,EAAE,MAAM,SAAS,CAAA;AAElD,YAAY,EAAE,KAAK,EAAE,YAAY,EAAE,CAAA;AAEnC,MAAM,MAAM,kBAAkB,GAAG,KAAK,GAAG,YAAY,GAAG,MAAM,CAAA;AAE9D,wBAAgB,WAAW,CAAC,OAAO,EAAE,kBAAkB,GAAG,KAAK,CAgB9D"}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.createRedis = void 0;
|
4
|
+
const ioredis_1 = require("ioredis");
|
5
|
+
function createRedis(options) {
|
6
|
+
if (options instanceof ioredis_1.Redis) {
|
7
|
+
return options;
|
8
|
+
}
|
9
|
+
else if (typeof options === 'string') {
|
10
|
+
const url = new URL(options.startsWith('redis://') ? options : `redis://${options}`);
|
11
|
+
return new ioredis_1.Redis({
|
12
|
+
host: url.hostname,
|
13
|
+
port: parseInt(url.port, 10),
|
14
|
+
password: url.password,
|
15
|
+
});
|
16
|
+
}
|
17
|
+
else {
|
18
|
+
return new ioredis_1.Redis(options);
|
19
|
+
}
|
20
|
+
}
|
21
|
+
exports.createRedis = createRedis;
|
22
|
+
//# sourceMappingURL=redis.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"redis.js","sourceRoot":"","sources":["../../src/lib/redis.ts"],"names":[],"mappings":";;;AAAA,qCAAkD;AAMlD,SAAgB,WAAW,CAAC,OAA2B;IACrD,IAAI,OAAO,YAAY,eAAK,EAAE,CAAC;QAC7B,OAAO,OAAO,CAAA;IAChB,CAAC;SAAM,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QACvC,MAAM,GAAG,GAAG,IAAI,GAAG,CACjB,OAAO,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,WAAW,OAAO,EAAE,CAChE,CAAA;QAED,OAAO,IAAI,eAAK,CAAC;YACf,IAAI,EAAE,GAAG,CAAC,QAAQ;YAClB,IAAI,EAAE,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC;YAC5B,QAAQ,EAAE,GAAG,CAAC,QAAQ;SACvB,CAAC,CAAA;IACJ,CAAC;SAAM,CAAC;QACN,OAAO,IAAI,eAAK,CAAC,OAAO,CAAC,CAAA;IAC3B,CAAC;AACH,CAAC;AAhBD,kCAgBC"}
|