@sirketio/auth 0.0.1
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/dist/_virtual/_rolldown/runtime.mjs +36 -0
- package/dist/adapter/index.d.mts +4 -0
- package/dist/adapter/index.mjs +7 -0
- package/dist/api/index.d.mts +3872 -0
- package/dist/api/index.mjs +206 -0
- package/dist/api/index.mjs.map +1 -0
- package/dist/api/middlewares/index.d.mts +1 -0
- package/dist/api/middlewares/index.mjs +3 -0
- package/dist/api/middlewares/origin-check.d.mts +18 -0
- package/dist/api/middlewares/origin-check.mjs +140 -0
- package/dist/api/middlewares/origin-check.mjs.map +1 -0
- package/dist/api/rate-limiter/index.mjs +204 -0
- package/dist/api/rate-limiter/index.mjs.map +1 -0
- package/dist/api/routes/account.d.mts +410 -0
- package/dist/api/routes/account.mjs +493 -0
- package/dist/api/routes/account.mjs.map +1 -0
- package/dist/api/routes/callback.d.mts +31 -0
- package/dist/api/routes/callback.mjs +179 -0
- package/dist/api/routes/callback.mjs.map +1 -0
- package/dist/api/routes/email-verification.d.mts +161 -0
- package/dist/api/routes/email-verification.mjs +299 -0
- package/dist/api/routes/email-verification.mjs.map +1 -0
- package/dist/api/routes/error.d.mts +28 -0
- package/dist/api/routes/error.mjs +386 -0
- package/dist/api/routes/error.mjs.map +1 -0
- package/dist/api/routes/index.d.mts +11 -0
- package/dist/api/routes/index.mjs +13 -0
- package/dist/api/routes/ok.d.mts +36 -0
- package/dist/api/routes/ok.mjs +30 -0
- package/dist/api/routes/ok.mjs.map +1 -0
- package/dist/api/routes/password.d.mts +182 -0
- package/dist/api/routes/password.mjs +198 -0
- package/dist/api/routes/password.mjs.map +1 -0
- package/dist/api/routes/session.d.mts +415 -0
- package/dist/api/routes/session.mjs +483 -0
- package/dist/api/routes/session.mjs.map +1 -0
- package/dist/api/routes/sign-in.d.mts +171 -0
- package/dist/api/routes/sign-in.mjs +263 -0
- package/dist/api/routes/sign-in.mjs.map +1 -0
- package/dist/api/routes/sign-out.d.mts +36 -0
- package/dist/api/routes/sign-out.mjs +33 -0
- package/dist/api/routes/sign-out.mjs.map +1 -0
- package/dist/api/routes/sign-up.d.mts +160 -0
- package/dist/api/routes/sign-up.mjs +227 -0
- package/dist/api/routes/sign-up.mjs.map +1 -0
- package/dist/api/routes/update-user.d.mts +445 -0
- package/dist/api/routes/update-user.mjs +493 -0
- package/dist/api/routes/update-user.mjs.map +1 -0
- package/dist/api/state/oauth.d.mts +18 -0
- package/dist/api/state/oauth.mjs +8 -0
- package/dist/api/state/oauth.mjs.map +1 -0
- package/dist/api/state/should-session-refresh.d.mts +13 -0
- package/dist/api/state/should-session-refresh.mjs +16 -0
- package/dist/api/state/should-session-refresh.mjs.map +1 -0
- package/dist/api/to-auth-endpoints.mjs +197 -0
- package/dist/api/to-auth-endpoints.mjs.map +1 -0
- package/dist/auth/base.mjs +45 -0
- package/dist/auth/base.mjs.map +1 -0
- package/dist/auth/minimal.d.mts +12 -0
- package/dist/auth/minimal.mjs +14 -0
- package/dist/auth/minimal.mjs.map +1 -0
- package/dist/auth/trusted-origins.mjs +31 -0
- package/dist/auth/trusted-origins.mjs.map +1 -0
- package/dist/client/broadcast-channel.d.mts +20 -0
- package/dist/client/broadcast-channel.mjs +46 -0
- package/dist/client/broadcast-channel.mjs.map +1 -0
- package/dist/client/config.mjs +90 -0
- package/dist/client/config.mjs.map +1 -0
- package/dist/client/fetch-plugins.mjs +18 -0
- package/dist/client/fetch-plugins.mjs.map +1 -0
- package/dist/client/focus-manager.d.mts +11 -0
- package/dist/client/focus-manager.mjs +32 -0
- package/dist/client/focus-manager.mjs.map +1 -0
- package/dist/client/index.d.mts +33 -0
- package/dist/client/index.mjs +21 -0
- package/dist/client/index.mjs.map +1 -0
- package/dist/client/online-manager.d.mts +12 -0
- package/dist/client/online-manager.mjs +35 -0
- package/dist/client/online-manager.mjs.map +1 -0
- package/dist/client/parser.mjs +73 -0
- package/dist/client/parser.mjs.map +1 -0
- package/dist/client/path-to-object.d.mts +65 -0
- package/dist/client/plugins/index.d.mts +53 -0
- package/dist/client/plugins/index.mjs +30 -0
- package/dist/client/plugins/infer-plugin.d.mts +16 -0
- package/dist/client/plugins/infer-plugin.mjs +11 -0
- package/dist/client/plugins/infer-plugin.mjs.map +1 -0
- package/dist/client/proxy.mjs +79 -0
- package/dist/client/proxy.mjs.map +1 -0
- package/dist/client/query.d.mts +23 -0
- package/dist/client/query.mjs +98 -0
- package/dist/client/query.mjs.map +1 -0
- package/dist/client/react/index.d.mts +128 -0
- package/dist/client/react/index.mjs +24 -0
- package/dist/client/react/index.mjs.map +1 -0
- package/dist/client/react/react-store.d.mts +47 -0
- package/dist/client/react/react-store.mjs +47 -0
- package/dist/client/react/react-store.mjs.map +1 -0
- package/dist/client/session-atom.mjs +29 -0
- package/dist/client/session-atom.mjs.map +1 -0
- package/dist/client/session-refresh.d.mts +28 -0
- package/dist/client/session-refresh.mjs +140 -0
- package/dist/client/session-refresh.mjs.map +1 -0
- package/dist/client/types.d.mts +41 -0
- package/dist/client/vanilla.d.mts +127 -0
- package/dist/client/vanilla.mjs +20 -0
- package/dist/client/vanilla.mjs.map +1 -0
- package/dist/context/create-context.mjs +211 -0
- package/dist/context/create-context.mjs.map +1 -0
- package/dist/context/helpers.mjs +83 -0
- package/dist/context/helpers.mjs.map +1 -0
- package/dist/context/init.mjs +20 -0
- package/dist/context/init.mjs.map +1 -0
- package/dist/cookies/cookie-utils.d.mts +29 -0
- package/dist/cookies/cookie-utils.mjs +105 -0
- package/dist/cookies/cookie-utils.mjs.map +1 -0
- package/dist/cookies/index.d.mts +121 -0
- package/dist/cookies/index.mjs +261 -0
- package/dist/cookies/index.mjs.map +1 -0
- package/dist/cookies/session-store.d.mts +36 -0
- package/dist/cookies/session-store.mjs +200 -0
- package/dist/cookies/session-store.mjs.map +1 -0
- package/dist/crypto/buffer.d.mts +8 -0
- package/dist/crypto/buffer.mjs +18 -0
- package/dist/crypto/buffer.mjs.map +1 -0
- package/dist/crypto/index.d.mts +27 -0
- package/dist/crypto/index.mjs +38 -0
- package/dist/crypto/index.mjs.map +1 -0
- package/dist/crypto/jwt.d.mts +8 -0
- package/dist/crypto/jwt.mjs +95 -0
- package/dist/crypto/jwt.mjs.map +1 -0
- package/dist/crypto/password.d.mts +12 -0
- package/dist/crypto/password.mjs +36 -0
- package/dist/crypto/password.mjs.map +1 -0
- package/dist/crypto/random.d.mts +5 -0
- package/dist/crypto/random.mjs +8 -0
- package/dist/crypto/random.mjs.map +1 -0
- package/dist/db/adapter-base.d.mts +8 -0
- package/dist/db/adapter-base.mjs +19 -0
- package/dist/db/adapter-base.mjs.map +1 -0
- package/dist/db/field-converter.d.mts +8 -0
- package/dist/db/field-converter.mjs +21 -0
- package/dist/db/field-converter.mjs.map +1 -0
- package/dist/db/field.d.mts +42 -0
- package/dist/db/get-schema.d.mts +11 -0
- package/dist/db/get-schema.mjs +39 -0
- package/dist/db/get-schema.mjs.map +1 -0
- package/dist/db/index.d.mts +18 -0
- package/dist/db/index.mjs +34 -0
- package/dist/db/index.mjs.map +1 -0
- package/dist/db/internal-adapter.d.mts +14 -0
- package/dist/db/internal-adapter.mjs +616 -0
- package/dist/db/internal-adapter.mjs.map +1 -0
- package/dist/db/schema.d.mts +49 -0
- package/dist/db/schema.mjs +118 -0
- package/dist/db/schema.mjs.map +1 -0
- package/dist/db/to-zod.d.mts +36 -0
- package/dist/db/to-zod.mjs +26 -0
- package/dist/db/to-zod.mjs.map +1 -0
- package/dist/db/verification-token-storage.mjs +28 -0
- package/dist/db/verification-token-storage.mjs.map +1 -0
- package/dist/db/with-hooks.d.mts +33 -0
- package/dist/db/with-hooks.mjs +159 -0
- package/dist/db/with-hooks.mjs.map +1 -0
- package/dist/index.d.mts +53 -0
- package/dist/index.mjs +27 -0
- package/dist/integrations/next-js.d.mts +29 -0
- package/dist/integrations/next-js.mjs +85 -0
- package/dist/integrations/next-js.mjs.map +1 -0
- package/dist/oauth2/index.d.mts +5 -0
- package/dist/oauth2/index.mjs +7 -0
- package/dist/oauth2/link-account.d.mts +48 -0
- package/dist/oauth2/link-account.mjs +143 -0
- package/dist/oauth2/link-account.mjs.map +1 -0
- package/dist/oauth2/state.d.mts +26 -0
- package/dist/oauth2/state.mjs +51 -0
- package/dist/oauth2/state.mjs.map +1 -0
- package/dist/oauth2/utils.d.mts +8 -0
- package/dist/oauth2/utils.mjs +31 -0
- package/dist/oauth2/utils.mjs.map +1 -0
- package/dist/plugins/access/access.d.mts +30 -0
- package/dist/plugins/access/access.mjs +46 -0
- package/dist/plugins/access/access.mjs.map +1 -0
- package/dist/plugins/access/index.d.mts +3 -0
- package/dist/plugins/access/index.mjs +3 -0
- package/dist/plugins/access/types.d.mts +17 -0
- package/dist/plugins/additional-fields/client.d.mts +96 -0
- package/dist/plugins/additional-fields/client.mjs +11 -0
- package/dist/plugins/additional-fields/client.mjs.map +1 -0
- package/dist/plugins/admin/access/index.d.mts +2 -0
- package/dist/plugins/admin/access/index.mjs +3 -0
- package/dist/plugins/admin/access/statement.d.mts +118 -0
- package/dist/plugins/admin/access/statement.mjs +53 -0
- package/dist/plugins/admin/access/statement.mjs.map +1 -0
- package/dist/plugins/admin/admin.d.mts +911 -0
- package/dist/plugins/admin/admin.mjs +95 -0
- package/dist/plugins/admin/admin.mjs.map +1 -0
- package/dist/plugins/admin/client.d.mts +76 -0
- package/dist/plugins/admin/client.mjs +36 -0
- package/dist/plugins/admin/client.mjs.map +1 -0
- package/dist/plugins/admin/error-codes.d.mts +29 -0
- package/dist/plugins/admin/error-codes.mjs +30 -0
- package/dist/plugins/admin/error-codes.mjs.map +1 -0
- package/dist/plugins/admin/has-permission.mjs +16 -0
- package/dist/plugins/admin/has-permission.mjs.map +1 -0
- package/dist/plugins/admin/index.d.mts +3 -0
- package/dist/plugins/admin/index.mjs +3 -0
- package/dist/plugins/admin/routes.mjs +841 -0
- package/dist/plugins/admin/routes.mjs.map +1 -0
- package/dist/plugins/admin/schema.d.mts +40 -0
- package/dist/plugins/admin/schema.mjs +34 -0
- package/dist/plugins/admin/schema.mjs.map +1 -0
- package/dist/plugins/admin/types.d.mts +89 -0
- package/dist/plugins/api-key/adapter.mjs +468 -0
- package/dist/plugins/api-key/adapter.mjs.map +1 -0
- package/dist/plugins/api-key/client.d.mts +46 -0
- package/dist/plugins/api-key/client.mjs +19 -0
- package/dist/plugins/api-key/client.mjs.map +1 -0
- package/dist/plugins/api-key/error-codes.d.mts +33 -0
- package/dist/plugins/api-key/error-codes.mjs +34 -0
- package/dist/plugins/api-key/error-codes.mjs.map +1 -0
- package/dist/plugins/api-key/index.d.mts +1251 -0
- package/dist/plugins/api-key/index.mjs +134 -0
- package/dist/plugins/api-key/index.mjs.map +1 -0
- package/dist/plugins/api-key/rate-limit.mjs +74 -0
- package/dist/plugins/api-key/rate-limit.mjs.map +1 -0
- package/dist/plugins/api-key/routes/create-api-key.mjs +252 -0
- package/dist/plugins/api-key/routes/create-api-key.mjs.map +1 -0
- package/dist/plugins/api-key/routes/delete-all-expired-api-keys.mjs +24 -0
- package/dist/plugins/api-key/routes/delete-all-expired-api-keys.mjs.map +1 -0
- package/dist/plugins/api-key/routes/delete-api-key.mjs +74 -0
- package/dist/plugins/api-key/routes/delete-api-key.mjs.map +1 -0
- package/dist/plugins/api-key/routes/get-api-key.mjs +158 -0
- package/dist/plugins/api-key/routes/get-api-key.mjs.map +1 -0
- package/dist/plugins/api-key/routes/index.mjs +71 -0
- package/dist/plugins/api-key/routes/index.mjs.map +1 -0
- package/dist/plugins/api-key/routes/list-api-keys.mjs +194 -0
- package/dist/plugins/api-key/routes/list-api-keys.mjs.map +1 -0
- package/dist/plugins/api-key/routes/update-api-key.mjs +248 -0
- package/dist/plugins/api-key/routes/update-api-key.mjs.map +1 -0
- package/dist/plugins/api-key/routes/verify-api-key.mjs +224 -0
- package/dist/plugins/api-key/routes/verify-api-key.mjs.map +1 -0
- package/dist/plugins/api-key/schema.d.mts +199 -0
- package/dist/plugins/api-key/schema.mjs +130 -0
- package/dist/plugins/api-key/schema.mjs.map +1 -0
- package/dist/plugins/api-key/types.d.mts +346 -0
- package/dist/plugins/bearer/index.d.mts +45 -0
- package/dist/plugins/bearer/index.mjs +66 -0
- package/dist/plugins/bearer/index.mjs.map +1 -0
- package/dist/plugins/captcha/constants.d.mts +10 -0
- package/dist/plugins/captcha/constants.mjs +22 -0
- package/dist/plugins/captcha/constants.mjs.map +1 -0
- package/dist/plugins/captcha/error-codes.mjs +16 -0
- package/dist/plugins/captcha/error-codes.mjs.map +1 -0
- package/dist/plugins/captcha/index.d.mts +21 -0
- package/dist/plugins/captcha/index.mjs +62 -0
- package/dist/plugins/captcha/index.mjs.map +1 -0
- package/dist/plugins/captcha/types.d.mts +28 -0
- package/dist/plugins/captcha/utils.mjs +11 -0
- package/dist/plugins/captcha/utils.mjs.map +1 -0
- package/dist/plugins/captcha/verify-handlers/captchafox.mjs +28 -0
- package/dist/plugins/captcha/verify-handlers/captchafox.mjs.map +1 -0
- package/dist/plugins/captcha/verify-handlers/cloudflare-turnstile.mjs +26 -0
- package/dist/plugins/captcha/verify-handlers/cloudflare-turnstile.mjs.map +1 -0
- package/dist/plugins/captcha/verify-handlers/google-recaptcha.mjs +30 -0
- package/dist/plugins/captcha/verify-handlers/google-recaptcha.mjs.map +1 -0
- package/dist/plugins/captcha/verify-handlers/h-captcha.mjs +28 -0
- package/dist/plugins/captcha/verify-handlers/h-captcha.mjs.map +1 -0
- package/dist/plugins/captcha/verify-handlers/index.mjs +6 -0
- package/dist/plugins/custom-session/client.d.mts +17 -0
- package/dist/plugins/custom-session/client.mjs +11 -0
- package/dist/plugins/custom-session/client.mjs.map +1 -0
- package/dist/plugins/custom-session/index.d.mts +72 -0
- package/dist/plugins/custom-session/index.mjs +78 -0
- package/dist/plugins/custom-session/index.mjs.map +1 -0
- package/dist/plugins/device-authorization/client.d.mts +17 -0
- package/dist/plugins/device-authorization/client.mjs +18 -0
- package/dist/plugins/device-authorization/client.mjs.map +1 -0
- package/dist/plugins/device-authorization/error-codes.mjs +21 -0
- package/dist/plugins/device-authorization/error-codes.mjs.map +1 -0
- package/dist/plugins/device-authorization/index.d.mts +424 -0
- package/dist/plugins/device-authorization/index.mjs +50 -0
- package/dist/plugins/device-authorization/index.mjs.map +1 -0
- package/dist/plugins/device-authorization/routes.mjs +510 -0
- package/dist/plugins/device-authorization/routes.mjs.map +1 -0
- package/dist/plugins/device-authorization/schema.mjs +57 -0
- package/dist/plugins/device-authorization/schema.mjs.map +1 -0
- package/dist/plugins/email-otp/client.d.mts +21 -0
- package/dist/plugins/email-otp/client.mjs +18 -0
- package/dist/plugins/email-otp/client.mjs.map +1 -0
- package/dist/plugins/email-otp/error-codes.d.mts +11 -0
- package/dist/plugins/email-otp/error-codes.mjs +12 -0
- package/dist/plugins/email-otp/error-codes.mjs.map +1 -0
- package/dist/plugins/email-otp/index.d.mts +428 -0
- package/dist/plugins/email-otp/index.mjs +130 -0
- package/dist/plugins/email-otp/index.mjs.map +1 -0
- package/dist/plugins/email-otp/otp-token.mjs +29 -0
- package/dist/plugins/email-otp/otp-token.mjs.map +1 -0
- package/dist/plugins/email-otp/routes.mjs +631 -0
- package/dist/plugins/email-otp/routes.mjs.map +1 -0
- package/dist/plugins/email-otp/types.d.mts +86 -0
- package/dist/plugins/email-otp/utils.mjs +17 -0
- package/dist/plugins/email-otp/utils.mjs.map +1 -0
- package/dist/plugins/generic-oauth/client.d.mts +33 -0
- package/dist/plugins/generic-oauth/client.mjs +14 -0
- package/dist/plugins/generic-oauth/client.mjs.map +1 -0
- package/dist/plugins/generic-oauth/error-codes.d.mts +16 -0
- package/dist/plugins/generic-oauth/error-codes.mjs +17 -0
- package/dist/plugins/generic-oauth/error-codes.mjs.map +1 -0
- package/dist/plugins/generic-oauth/index.d.mts +201 -0
- package/dist/plugins/generic-oauth/index.mjs +145 -0
- package/dist/plugins/generic-oauth/index.mjs.map +1 -0
- package/dist/plugins/generic-oauth/providers/auth0.d.mts +37 -0
- package/dist/plugins/generic-oauth/providers/auth0.mjs +62 -0
- package/dist/plugins/generic-oauth/providers/auth0.mjs.map +1 -0
- package/dist/plugins/generic-oauth/providers/gumroad.d.mts +32 -0
- package/dist/plugins/generic-oauth/providers/gumroad.mjs +60 -0
- package/dist/plugins/generic-oauth/providers/gumroad.mjs.map +1 -0
- package/dist/plugins/generic-oauth/providers/hubspot.d.mts +37 -0
- package/dist/plugins/generic-oauth/providers/hubspot.mjs +60 -0
- package/dist/plugins/generic-oauth/providers/hubspot.mjs.map +1 -0
- package/dist/plugins/generic-oauth/providers/index.d.mts +9 -0
- package/dist/plugins/generic-oauth/providers/index.mjs +11 -0
- package/dist/plugins/generic-oauth/providers/keycloak.d.mts +37 -0
- package/dist/plugins/generic-oauth/providers/keycloak.mjs +62 -0
- package/dist/plugins/generic-oauth/providers/keycloak.mjs.map +1 -0
- package/dist/plugins/generic-oauth/providers/line.d.mts +55 -0
- package/dist/plugins/generic-oauth/providers/line.mjs +91 -0
- package/dist/plugins/generic-oauth/providers/line.mjs.map +1 -0
- package/dist/plugins/generic-oauth/providers/microsoft-entra-id.d.mts +37 -0
- package/dist/plugins/generic-oauth/providers/microsoft-entra-id.mjs +66 -0
- package/dist/plugins/generic-oauth/providers/microsoft-entra-id.mjs.map +1 -0
- package/dist/plugins/generic-oauth/providers/okta.d.mts +37 -0
- package/dist/plugins/generic-oauth/providers/okta.mjs +62 -0
- package/dist/plugins/generic-oauth/providers/okta.mjs.map +1 -0
- package/dist/plugins/generic-oauth/providers/patreon.d.mts +30 -0
- package/dist/plugins/generic-oauth/providers/patreon.mjs +59 -0
- package/dist/plugins/generic-oauth/providers/patreon.mjs.map +1 -0
- package/dist/plugins/generic-oauth/providers/slack.d.mts +30 -0
- package/dist/plugins/generic-oauth/providers/slack.mjs +61 -0
- package/dist/plugins/generic-oauth/providers/slack.mjs.map +1 -0
- package/dist/plugins/generic-oauth/routes.mjs +411 -0
- package/dist/plugins/generic-oauth/routes.mjs.map +1 -0
- package/dist/plugins/generic-oauth/types.d.mts +159 -0
- package/dist/plugins/haveibeenpwned/index.d.mts +46 -0
- package/dist/plugins/haveibeenpwned/index.mjs +57 -0
- package/dist/plugins/haveibeenpwned/index.mjs.map +1 -0
- package/dist/plugins/index.d.mts +65 -0
- package/dist/plugins/index.mjs +48 -0
- package/dist/plugins/jwt/adapter.mjs +27 -0
- package/dist/plugins/jwt/adapter.mjs.map +1 -0
- package/dist/plugins/jwt/client.d.mts +40 -0
- package/dist/plugins/jwt/client.mjs +19 -0
- package/dist/plugins/jwt/client.mjs.map +1 -0
- package/dist/plugins/jwt/index.d.mts +224 -0
- package/dist/plugins/jwt/index.mjs +202 -0
- package/dist/plugins/jwt/index.mjs.map +1 -0
- package/dist/plugins/jwt/schema.d.mts +26 -0
- package/dist/plugins/jwt/schema.mjs +23 -0
- package/dist/plugins/jwt/schema.mjs.map +1 -0
- package/dist/plugins/jwt/sign.d.mts +57 -0
- package/dist/plugins/jwt/sign.mjs +66 -0
- package/dist/plugins/jwt/sign.mjs.map +1 -0
- package/dist/plugins/jwt/types.d.mts +194 -0
- package/dist/plugins/jwt/utils.d.mts +42 -0
- package/dist/plugins/jwt/utils.mjs +64 -0
- package/dist/plugins/jwt/utils.mjs.map +1 -0
- package/dist/plugins/jwt/verify.d.mts +12 -0
- package/dist/plugins/jwt/verify.mjs +46 -0
- package/dist/plugins/jwt/verify.mjs.map +1 -0
- package/dist/plugins/last-login-method/client.d.mts +38 -0
- package/dist/plugins/last-login-method/client.mjs +32 -0
- package/dist/plugins/last-login-method/client.mjs.map +1 -0
- package/dist/plugins/last-login-method/index.d.mts +118 -0
- package/dist/plugins/last-login-method/index.mjs +76 -0
- package/dist/plugins/last-login-method/index.mjs.map +1 -0
- package/dist/plugins/magic-link/client.d.mts +10 -0
- package/dist/plugins/magic-link/client.mjs +11 -0
- package/dist/plugins/magic-link/client.mjs.map +1 -0
- package/dist/plugins/magic-link/index.d.mts +193 -0
- package/dist/plugins/magic-link/index.mjs +177 -0
- package/dist/plugins/magic-link/index.mjs.map +1 -0
- package/dist/plugins/magic-link/utils.mjs +12 -0
- package/dist/plugins/magic-link/utils.mjs.map +1 -0
- package/dist/plugins/mcp/authorize.mjs +133 -0
- package/dist/plugins/mcp/authorize.mjs.map +1 -0
- package/dist/plugins/mcp/index.d.mts +458 -0
- package/dist/plugins/mcp/index.mjs +717 -0
- package/dist/plugins/mcp/index.mjs.map +1 -0
- package/dist/plugins/multi-session/client.d.mts +19 -0
- package/dist/plugins/multi-session/client.mjs +20 -0
- package/dist/plugins/multi-session/client.mjs.map +1 -0
- package/dist/plugins/multi-session/error-codes.d.mts +9 -0
- package/dist/plugins/multi-session/error-codes.mjs +8 -0
- package/dist/plugins/multi-session/error-codes.mjs.map +1 -0
- package/dist/plugins/multi-session/index.d.mts +235 -0
- package/dist/plugins/multi-session/index.mjs +172 -0
- package/dist/plugins/multi-session/index.mjs.map +1 -0
- package/dist/plugins/oauth-proxy/index.d.mts +97 -0
- package/dist/plugins/oauth-proxy/index.mjs +305 -0
- package/dist/plugins/oauth-proxy/index.mjs.map +1 -0
- package/dist/plugins/oauth-proxy/utils.mjs +51 -0
- package/dist/plugins/oauth-proxy/utils.mjs.map +1 -0
- package/dist/plugins/oidc-provider/authorize.mjs +194 -0
- package/dist/plugins/oidc-provider/authorize.mjs.map +1 -0
- package/dist/plugins/oidc-provider/client.d.mts +12 -0
- package/dist/plugins/oidc-provider/client.mjs +11 -0
- package/dist/plugins/oidc-provider/client.mjs.map +1 -0
- package/dist/plugins/oidc-provider/error.mjs +17 -0
- package/dist/plugins/oidc-provider/error.mjs.map +1 -0
- package/dist/plugins/oidc-provider/index.d.mts +702 -0
- package/dist/plugins/oidc-provider/index.mjs +1093 -0
- package/dist/plugins/oidc-provider/index.mjs.map +1 -0
- package/dist/plugins/oidc-provider/schema.d.mts +160 -0
- package/dist/plugins/oidc-provider/schema.mjs +132 -0
- package/dist/plugins/oidc-provider/schema.mjs.map +1 -0
- package/dist/plugins/oidc-provider/types.d.mts +517 -0
- package/dist/plugins/oidc-provider/utils/prompt.mjs +19 -0
- package/dist/plugins/oidc-provider/utils/prompt.mjs.map +1 -0
- package/dist/plugins/oidc-provider/utils.mjs +15 -0
- package/dist/plugins/oidc-provider/utils.mjs.map +1 -0
- package/dist/plugins/one-tap/client.d.mts +174 -0
- package/dist/plugins/one-tap/client.mjs +188 -0
- package/dist/plugins/one-tap/client.mjs.map +1 -0
- package/dist/plugins/one-tap/index.d.mts +83 -0
- package/dist/plugins/one-tap/index.mjs +95 -0
- package/dist/plugins/one-tap/index.mjs.map +1 -0
- package/dist/plugins/one-time-token/client.d.mts +10 -0
- package/dist/plugins/one-time-token/client.mjs +11 -0
- package/dist/plugins/one-time-token/client.mjs.map +1 -0
- package/dist/plugins/one-time-token/index.d.mts +133 -0
- package/dist/plugins/one-time-token/index.mjs +82 -0
- package/dist/plugins/one-time-token/index.mjs.map +1 -0
- package/dist/plugins/one-time-token/utils.mjs +12 -0
- package/dist/plugins/one-time-token/utils.mjs.map +1 -0
- package/dist/plugins/open-api/generator.d.mts +115 -0
- package/dist/plugins/open-api/generator.mjs +315 -0
- package/dist/plugins/open-api/generator.mjs.map +1 -0
- package/dist/plugins/open-api/index.d.mts +97 -0
- package/dist/plugins/open-api/index.mjs +67 -0
- package/dist/plugins/open-api/index.mjs.map +1 -0
- package/dist/plugins/open-api/logo.mjs +15 -0
- package/dist/plugins/open-api/logo.mjs.map +1 -0
- package/dist/plugins/organization/access/index.d.mts +2 -0
- package/dist/plugins/organization/access/index.mjs +3 -0
- package/dist/plugins/organization/access/statement.d.mts +249 -0
- package/dist/plugins/organization/access/statement.mjs +81 -0
- package/dist/plugins/organization/access/statement.mjs.map +1 -0
- package/dist/plugins/organization/adapter.d.mts +792 -0
- package/dist/plugins/organization/adapter.mjs +624 -0
- package/dist/plugins/organization/adapter.mjs.map +1 -0
- package/dist/plugins/organization/call.mjs +19 -0
- package/dist/plugins/organization/call.mjs.map +1 -0
- package/dist/plugins/organization/client.d.mts +372 -0
- package/dist/plugins/organization/client.mjs +95 -0
- package/dist/plugins/organization/client.mjs.map +1 -0
- package/dist/plugins/organization/error-codes.d.mts +65 -0
- package/dist/plugins/organization/error-codes.mjs +66 -0
- package/dist/plugins/organization/error-codes.mjs.map +1 -0
- package/dist/plugins/organization/has-permission.mjs +35 -0
- package/dist/plugins/organization/has-permission.mjs.map +1 -0
- package/dist/plugins/organization/index.d.mts +5 -0
- package/dist/plugins/organization/index.mjs +4 -0
- package/dist/plugins/organization/organization.d.mts +394 -0
- package/dist/plugins/organization/organization.mjs +428 -0
- package/dist/plugins/organization/organization.mjs.map +1 -0
- package/dist/plugins/organization/permission.d.mts +17 -0
- package/dist/plugins/organization/permission.mjs +16 -0
- package/dist/plugins/organization/permission.mjs.map +1 -0
- package/dist/plugins/organization/routes/crud-access-control.d.mts +394 -0
- package/dist/plugins/organization/routes/crud-access-control.mjs +678 -0
- package/dist/plugins/organization/routes/crud-access-control.mjs.map +1 -0
- package/dist/plugins/organization/routes/crud-invites.d.mts +1031 -0
- package/dist/plugins/organization/routes/crud-invites.mjs +551 -0
- package/dist/plugins/organization/routes/crud-invites.mjs.map +1 -0
- package/dist/plugins/organization/routes/crud-members.d.mts +940 -0
- package/dist/plugins/organization/routes/crud-members.mjs +466 -0
- package/dist/plugins/organization/routes/crud-members.mjs.map +1 -0
- package/dist/plugins/organization/routes/crud-org.d.mts +708 -0
- package/dist/plugins/organization/routes/crud-org.mjs +423 -0
- package/dist/plugins/organization/routes/crud-org.mjs.map +1 -0
- package/dist/plugins/organization/routes/crud-team.d.mts +1071 -0
- package/dist/plugins/organization/routes/crud-team.mjs +676 -0
- package/dist/plugins/organization/routes/crud-team.mjs.map +1 -0
- package/dist/plugins/organization/schema.d.mts +376 -0
- package/dist/plugins/organization/schema.mjs +68 -0
- package/dist/plugins/organization/schema.mjs.map +1 -0
- package/dist/plugins/organization/types.d.mts +677 -0
- package/dist/plugins/phone-number/client.d.mts +31 -0
- package/dist/plugins/phone-number/client.mjs +20 -0
- package/dist/plugins/phone-number/client.mjs.map +1 -0
- package/dist/plugins/phone-number/error-codes.d.mts +20 -0
- package/dist/plugins/phone-number/error-codes.mjs +21 -0
- package/dist/plugins/phone-number/error-codes.mjs.map +1 -0
- package/dist/plugins/phone-number/index.d.mts +318 -0
- package/dist/plugins/phone-number/index.mjs +49 -0
- package/dist/plugins/phone-number/index.mjs.map +1 -0
- package/dist/plugins/phone-number/routes.mjs +472 -0
- package/dist/plugins/phone-number/routes.mjs.map +1 -0
- package/dist/plugins/phone-number/schema.d.mts +23 -0
- package/dist/plugins/phone-number/schema.mjs +20 -0
- package/dist/plugins/phone-number/schema.mjs.map +1 -0
- package/dist/plugins/phone-number/types.d.mts +118 -0
- package/dist/plugins/two-factor/backup-codes/index.d.mts +279 -0
- package/dist/plugins/two-factor/backup-codes/index.mjs +277 -0
- package/dist/plugins/two-factor/backup-codes/index.mjs.map +1 -0
- package/dist/plugins/two-factor/client.d.mts +55 -0
- package/dist/plugins/two-factor/client.mjs +37 -0
- package/dist/plugins/two-factor/client.mjs.map +1 -0
- package/dist/plugins/two-factor/constant.mjs +8 -0
- package/dist/plugins/two-factor/constant.mjs.map +1 -0
- package/dist/plugins/two-factor/error-code.d.mts +17 -0
- package/dist/plugins/two-factor/error-code.mjs +18 -0
- package/dist/plugins/two-factor/error-code.mjs.map +1 -0
- package/dist/plugins/two-factor/index.d.mts +670 -0
- package/dist/plugins/two-factor/index.mjs +228 -0
- package/dist/plugins/two-factor/index.mjs.map +1 -0
- package/dist/plugins/two-factor/otp/index.d.mts +216 -0
- package/dist/plugins/two-factor/otp/index.mjs +199 -0
- package/dist/plugins/two-factor/otp/index.mjs.map +1 -0
- package/dist/plugins/two-factor/schema.d.mts +41 -0
- package/dist/plugins/two-factor/schema.mjs +36 -0
- package/dist/plugins/two-factor/schema.mjs.map +1 -0
- package/dist/plugins/two-factor/totp/index.d.mts +210 -0
- package/dist/plugins/two-factor/totp/index.mjs +157 -0
- package/dist/plugins/two-factor/totp/index.mjs.map +1 -0
- package/dist/plugins/two-factor/types.d.mts +73 -0
- package/dist/plugins/two-factor/utils.mjs +12 -0
- package/dist/plugins/two-factor/utils.mjs.map +1 -0
- package/dist/plugins/two-factor/verify-two-factor.mjs +85 -0
- package/dist/plugins/two-factor/verify-two-factor.mjs.map +1 -0
- package/dist/plugins/username/client.d.mts +26 -0
- package/dist/plugins/username/client.mjs +18 -0
- package/dist/plugins/username/client.mjs.map +1 -0
- package/dist/plugins/username/error-codes.d.mts +16 -0
- package/dist/plugins/username/error-codes.mjs +17 -0
- package/dist/plugins/username/error-codes.mjs.map +1 -0
- package/dist/plugins/username/index.d.mts +251 -0
- package/dist/plugins/username/index.mjs +234 -0
- package/dist/plugins/username/index.mjs.map +1 -0
- package/dist/plugins/username/schema.d.mts +33 -0
- package/dist/plugins/username/schema.mjs +26 -0
- package/dist/plugins/username/schema.mjs.map +1 -0
- package/dist/providers/index.d.mts +1 -0
- package/dist/providers/index.mjs +3 -0
- package/dist/state.d.mts +42 -0
- package/dist/state.mjs +107 -0
- package/dist/state.mjs.map +1 -0
- package/dist/types/adapter.d.mts +2 -0
- package/dist/types/api.d.mts +29 -0
- package/dist/types/auth.d.mts +29 -0
- package/dist/types/helper.d.mts +10 -0
- package/dist/types/index.d.mts +11 -0
- package/dist/types/index.mjs +1 -0
- package/dist/types/models.d.mts +11 -0
- package/dist/types/plugins.d.mts +20 -0
- package/dist/utils/boolean.mjs +8 -0
- package/dist/utils/boolean.mjs.map +1 -0
- package/dist/utils/constants.mjs +6 -0
- package/dist/utils/constants.mjs.map +1 -0
- package/dist/utils/date.mjs +8 -0
- package/dist/utils/date.mjs.map +1 -0
- package/dist/utils/get-request-ip.d.mts +7 -0
- package/dist/utils/get-request-ip.mjs +23 -0
- package/dist/utils/get-request-ip.mjs.map +1 -0
- package/dist/utils/hide-metadata.d.mts +7 -0
- package/dist/utils/hide-metadata.mjs +6 -0
- package/dist/utils/hide-metadata.mjs.map +1 -0
- package/dist/utils/index.d.mts +4 -0
- package/dist/utils/index.mjs +6 -0
- package/dist/utils/is-api-error.d.mts +7 -0
- package/dist/utils/is-api-error.mjs +11 -0
- package/dist/utils/is-api-error.mjs.map +1 -0
- package/dist/utils/is-atom.mjs +8 -0
- package/dist/utils/is-atom.mjs.map +1 -0
- package/dist/utils/is-promise.mjs +8 -0
- package/dist/utils/is-promise.mjs.map +1 -0
- package/dist/utils/middleware-response.mjs +9 -0
- package/dist/utils/middleware-response.mjs.map +1 -0
- package/dist/utils/password.mjs +26 -0
- package/dist/utils/password.mjs.map +1 -0
- package/dist/utils/plugin-helper.mjs +17 -0
- package/dist/utils/plugin-helper.mjs.map +1 -0
- package/dist/utils/shim.mjs +24 -0
- package/dist/utils/shim.mjs.map +1 -0
- package/dist/utils/time.d.mts +49 -0
- package/dist/utils/time.mjs +100 -0
- package/dist/utils/time.mjs.map +1 -0
- package/dist/utils/url.d.mts +8 -0
- package/dist/utils/url.mjs +92 -0
- package/dist/utils/url.mjs.map +1 -0
- package/dist/utils/wildcard.mjs +108 -0
- package/dist/utils/wildcard.mjs.map +1 -0
- package/package.json +428 -0
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { Session, User } from "../../types/models.mjs";
|
|
2
|
+
import "../../types/index.mjs";
|
|
3
|
+
import { GenericEndpointContext } from "@better-auth/core";
|
|
4
|
+
import * as better_call0 from "better-call";
|
|
5
|
+
import * as z from "zod";
|
|
6
|
+
|
|
7
|
+
//#region src/plugins/one-time-token/index.d.ts
|
|
8
|
+
declare module "@better-auth/core" {
|
|
9
|
+
interface BetterAuthPluginRegistry<AuthOptions, Options> {
|
|
10
|
+
"one-time-token": {
|
|
11
|
+
creator: typeof oneTimeToken;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
interface OneTimeTokenOptions {
|
|
16
|
+
/**
|
|
17
|
+
* Expires in minutes
|
|
18
|
+
*
|
|
19
|
+
* @default 3
|
|
20
|
+
*/
|
|
21
|
+
expiresIn?: number | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* Only allow server initiated requests
|
|
24
|
+
*/
|
|
25
|
+
disableClientRequest?: boolean | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* Generate a custom token
|
|
28
|
+
*/
|
|
29
|
+
generateToken?: ((session: {
|
|
30
|
+
user: User & Record<string, any>;
|
|
31
|
+
session: Session & Record<string, any>;
|
|
32
|
+
}, ctx: GenericEndpointContext) => Promise<string>) | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* Disable setting the session cookie when the token is verified
|
|
35
|
+
*/
|
|
36
|
+
disableSetSessionCookie?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* This option allows you to configure how the token is stored in your database.
|
|
39
|
+
* Note: This will not affect the token that's sent, it will only affect the token stored in your database.
|
|
40
|
+
*
|
|
41
|
+
* @default "plain"
|
|
42
|
+
*/
|
|
43
|
+
storeToken?: ("plain" | "hashed" | {
|
|
44
|
+
type: "custom-hasher";
|
|
45
|
+
hash: (token: string) => Promise<string>;
|
|
46
|
+
}) | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* Set the OTT header on new sessions
|
|
49
|
+
*/
|
|
50
|
+
setOttHeaderOnNewSession?: boolean;
|
|
51
|
+
}
|
|
52
|
+
declare const oneTimeToken: (options?: OneTimeTokenOptions | undefined) => {
|
|
53
|
+
id: "one-time-token";
|
|
54
|
+
endpoints: {
|
|
55
|
+
/**
|
|
56
|
+
* ### Endpoint
|
|
57
|
+
*
|
|
58
|
+
* GET `/one-time-token/generate`
|
|
59
|
+
*
|
|
60
|
+
* ### API Methods
|
|
61
|
+
*
|
|
62
|
+
* **server:**
|
|
63
|
+
* `auth.api.generateOneTimeToken`
|
|
64
|
+
*
|
|
65
|
+
* **client:**
|
|
66
|
+
* `authClient.oneTimeToken.generate`
|
|
67
|
+
*
|
|
68
|
+
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/one-time-token#api-method-one-time-token-generate)
|
|
69
|
+
*/
|
|
70
|
+
generateOneTimeToken: better_call0.StrictEndpoint<"/one-time-token/generate", {
|
|
71
|
+
method: "GET";
|
|
72
|
+
use: ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<{
|
|
73
|
+
session: {
|
|
74
|
+
session: Record<string, any> & {
|
|
75
|
+
id: string;
|
|
76
|
+
createdAt: Date;
|
|
77
|
+
updatedAt: Date;
|
|
78
|
+
userId: string;
|
|
79
|
+
expiresAt: Date;
|
|
80
|
+
token: string;
|
|
81
|
+
ipAddress?: string | null | undefined;
|
|
82
|
+
userAgent?: string | null | undefined;
|
|
83
|
+
};
|
|
84
|
+
user: Record<string, any> & {
|
|
85
|
+
id: string;
|
|
86
|
+
createdAt: Date;
|
|
87
|
+
updatedAt: Date;
|
|
88
|
+
email: string;
|
|
89
|
+
emailVerified: boolean;
|
|
90
|
+
name: string;
|
|
91
|
+
image?: string | null | undefined;
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
}>)[];
|
|
95
|
+
}, {
|
|
96
|
+
token: string;
|
|
97
|
+
}>;
|
|
98
|
+
/**
|
|
99
|
+
* ### Endpoint
|
|
100
|
+
*
|
|
101
|
+
* POST `/one-time-token/verify`
|
|
102
|
+
*
|
|
103
|
+
* ### API Methods
|
|
104
|
+
*
|
|
105
|
+
* **server:**
|
|
106
|
+
* `auth.api.verifyOneTimeToken`
|
|
107
|
+
*
|
|
108
|
+
* **client:**
|
|
109
|
+
* `authClient.oneTimeToken.verify`
|
|
110
|
+
*
|
|
111
|
+
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/one-time-token#api-method-one-time-token-verify)
|
|
112
|
+
*/
|
|
113
|
+
verifyOneTimeToken: better_call0.StrictEndpoint<"/one-time-token/verify", {
|
|
114
|
+
method: "POST";
|
|
115
|
+
body: z.ZodObject<{
|
|
116
|
+
token: z.ZodString;
|
|
117
|
+
}, z.core.$strip>;
|
|
118
|
+
}, {
|
|
119
|
+
session: Session & Record<string, any>;
|
|
120
|
+
user: User & Record<string, any>;
|
|
121
|
+
}>;
|
|
122
|
+
};
|
|
123
|
+
hooks: {
|
|
124
|
+
after: {
|
|
125
|
+
matcher: () => true;
|
|
126
|
+
handler: (inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<void>;
|
|
127
|
+
}[];
|
|
128
|
+
};
|
|
129
|
+
options: OneTimeTokenOptions | undefined;
|
|
130
|
+
};
|
|
131
|
+
//#endregion
|
|
132
|
+
export { OneTimeTokenOptions, oneTimeToken };
|
|
133
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { generateRandomString } from "../../crypto/random.mjs";
|
|
2
|
+
import "../../crypto/index.mjs";
|
|
3
|
+
import { setSessionCookie } from "../../cookies/index.mjs";
|
|
4
|
+
import { sessionMiddleware } from "../../api/routes/session.mjs";
|
|
5
|
+
import "../../api/index.mjs";
|
|
6
|
+
import { defaultKeyHasher } from "./utils.mjs";
|
|
7
|
+
import { createAuthEndpoint, createAuthMiddleware } from "@better-auth/core/api";
|
|
8
|
+
import * as z from "zod";
|
|
9
|
+
|
|
10
|
+
//#region src/plugins/one-time-token/index.ts
|
|
11
|
+
const verifyOneTimeTokenBodySchema = z.object({ token: z.string().meta({ description: "The token to verify. Eg: \"some-token\"" }) });
|
|
12
|
+
const oneTimeToken = (options) => {
|
|
13
|
+
const opts = {
|
|
14
|
+
storeToken: "plain",
|
|
15
|
+
...options
|
|
16
|
+
};
|
|
17
|
+
async function storeToken(ctx, token) {
|
|
18
|
+
if (opts.storeToken === "hashed") return await defaultKeyHasher(token);
|
|
19
|
+
if (typeof opts.storeToken === "object" && "type" in opts.storeToken && opts.storeToken.type === "custom-hasher") return await opts.storeToken.hash(token);
|
|
20
|
+
return token;
|
|
21
|
+
}
|
|
22
|
+
async function generateToken(c, session) {
|
|
23
|
+
const token = opts?.generateToken ? await opts.generateToken(session, c) : generateRandomString(32);
|
|
24
|
+
const expiresAt = new Date(Date.now() + (opts?.expiresIn ?? 3) * 60 * 1e3);
|
|
25
|
+
const storedToken = await storeToken(c, token);
|
|
26
|
+
await c.context.internalAdapter.createVerificationValue({
|
|
27
|
+
value: session.session.token,
|
|
28
|
+
identifier: `one-time-token:${storedToken}`,
|
|
29
|
+
expiresAt
|
|
30
|
+
});
|
|
31
|
+
return token;
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
id: "one-time-token",
|
|
35
|
+
endpoints: {
|
|
36
|
+
generateOneTimeToken: createAuthEndpoint("/one-time-token/generate", {
|
|
37
|
+
method: "GET",
|
|
38
|
+
use: [sessionMiddleware]
|
|
39
|
+
}, async (c) => {
|
|
40
|
+
if (opts?.disableClientRequest && c.request) throw c.error("BAD_REQUEST", { message: "Client requests are disabled" });
|
|
41
|
+
const session = c.context.session;
|
|
42
|
+
const token = await generateToken(c, session);
|
|
43
|
+
return c.json({ token });
|
|
44
|
+
}),
|
|
45
|
+
verifyOneTimeToken: createAuthEndpoint("/one-time-token/verify", {
|
|
46
|
+
method: "POST",
|
|
47
|
+
body: verifyOneTimeTokenBodySchema
|
|
48
|
+
}, async (c) => {
|
|
49
|
+
const { token } = c.body;
|
|
50
|
+
const storedToken = await storeToken(c, token);
|
|
51
|
+
const verificationValue = await c.context.internalAdapter.findVerificationValue(`one-time-token:${storedToken}`);
|
|
52
|
+
if (!verificationValue) throw c.error("BAD_REQUEST", { message: "Invalid token" });
|
|
53
|
+
await c.context.internalAdapter.deleteVerificationValue(verificationValue.id);
|
|
54
|
+
if (verificationValue.expiresAt < /* @__PURE__ */ new Date()) throw c.error("BAD_REQUEST", { message: "Token expired" });
|
|
55
|
+
const session = await c.context.internalAdapter.findSession(verificationValue.value);
|
|
56
|
+
if (!session) throw c.error("BAD_REQUEST", { message: "Session not found" });
|
|
57
|
+
if (!opts?.disableSetSessionCookie) await setSessionCookie(c, session);
|
|
58
|
+
if (session.session.expiresAt < /* @__PURE__ */ new Date()) throw c.error("BAD_REQUEST", { message: "Session expired" });
|
|
59
|
+
return c.json(session);
|
|
60
|
+
})
|
|
61
|
+
},
|
|
62
|
+
hooks: { after: [{
|
|
63
|
+
matcher: () => true,
|
|
64
|
+
handler: createAuthMiddleware(async (ctx) => {
|
|
65
|
+
if (ctx.context.newSession) {
|
|
66
|
+
if (!opts?.setOttHeaderOnNewSession) return;
|
|
67
|
+
const exposedHeaders = ctx.context.responseHeaders?.get("access-control-expose-headers") || "";
|
|
68
|
+
const headersSet = new Set(exposedHeaders.split(",").map((header) => header.trim()).filter(Boolean));
|
|
69
|
+
headersSet.add("set-ott");
|
|
70
|
+
const token = await generateToken(ctx, ctx.context.newSession);
|
|
71
|
+
ctx.setHeader("set-ott", token);
|
|
72
|
+
ctx.setHeader("Access-Control-Expose-Headers", Array.from(headersSet).join(", "));
|
|
73
|
+
}
|
|
74
|
+
})
|
|
75
|
+
}] },
|
|
76
|
+
options
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
//#endregion
|
|
81
|
+
export { oneTimeToken };
|
|
82
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/plugins/one-time-token/index.ts"],"sourcesContent":["import type {\n\tBetterAuthPlugin,\n\tGenericEndpointContext,\n} from \"@better-auth/core\";\nimport {\n\tcreateAuthEndpoint,\n\tcreateAuthMiddleware,\n} from \"@better-auth/core/api\";\nimport * as z from \"zod\";\nimport { sessionMiddleware } from \"../../api\";\nimport { setSessionCookie } from \"../../cookies\";\nimport { generateRandomString } from \"../../crypto\";\nimport type { Session, User } from \"../../types\";\nimport { defaultKeyHasher } from \"./utils\";\n\ndeclare module \"@better-auth/core\" {\n\tinterface BetterAuthPluginRegistry<AuthOptions, Options> {\n\t\t\"one-time-token\": {\n\t\t\tcreator: typeof oneTimeToken;\n\t\t};\n\t}\n}\n\nexport interface OneTimeTokenOptions {\n\t/**\n\t * Expires in minutes\n\t *\n\t * @default 3\n\t */\n\texpiresIn?: number | undefined;\n\t/**\n\t * Only allow server initiated requests\n\t */\n\tdisableClientRequest?: boolean | undefined;\n\t/**\n\t * Generate a custom token\n\t */\n\tgenerateToken?:\n\t\t| ((\n\t\t\t\tsession: {\n\t\t\t\t\tuser: User & Record<string, any>;\n\t\t\t\t\tsession: Session & Record<string, any>;\n\t\t\t\t},\n\t\t\t\tctx: GenericEndpointContext,\n\t\t ) => Promise<string>)\n\t\t| undefined;\n\t/**\n\t * Disable setting the session cookie when the token is verified\n\t */\n\tdisableSetSessionCookie?: boolean;\n\t/**\n\t * This option allows you to configure how the token is stored in your database.\n\t * Note: This will not affect the token that's sent, it will only affect the token stored in your database.\n\t *\n\t * @default \"plain\"\n\t */\n\tstoreToken?:\n\t\t| (\n\t\t\t\t| \"plain\"\n\t\t\t\t| \"hashed\"\n\t\t\t\t| { type: \"custom-hasher\"; hash: (token: string) => Promise<string> }\n\t\t )\n\t\t| undefined;\n\t/**\n\t * Set the OTT header on new sessions\n\t */\n\tsetOttHeaderOnNewSession?: boolean;\n}\n\nconst verifyOneTimeTokenBodySchema = z.object({\n\ttoken: z.string().meta({\n\t\tdescription: 'The token to verify. Eg: \"some-token\"',\n\t}),\n});\n\nexport const oneTimeToken = (options?: OneTimeTokenOptions | undefined) => {\n\tconst opts = {\n\t\tstoreToken: \"plain\",\n\t\t...options,\n\t} satisfies OneTimeTokenOptions;\n\n\tasync function storeToken(ctx: GenericEndpointContext, token: string) {\n\t\tif (opts.storeToken === \"hashed\") {\n\t\t\treturn await defaultKeyHasher(token);\n\t\t}\n\t\tif (\n\t\t\ttypeof opts.storeToken === \"object\" &&\n\t\t\t\"type\" in opts.storeToken &&\n\t\t\topts.storeToken.type === \"custom-hasher\"\n\t\t) {\n\t\t\treturn await opts.storeToken.hash(token);\n\t\t}\n\n\t\treturn token;\n\t}\n\n\tasync function generateToken(\n\t\tc: GenericEndpointContext,\n\t\tsession: {\n\t\t\tsession: Session;\n\t\t\tuser: User;\n\t\t},\n\t) {\n\t\tconst token = opts?.generateToken\n\t\t\t? await opts.generateToken(session, c)\n\t\t\t: generateRandomString(32);\n\t\tconst expiresAt = new Date(Date.now() + (opts?.expiresIn ?? 3) * 60 * 1000);\n\t\tconst storedToken = await storeToken(c, token);\n\t\tawait c.context.internalAdapter.createVerificationValue({\n\t\t\tvalue: session.session.token,\n\t\t\tidentifier: `one-time-token:${storedToken}`,\n\t\t\texpiresAt,\n\t\t});\n\t\treturn token;\n\t}\n\n\treturn {\n\t\tid: \"one-time-token\",\n\t\tendpoints: {\n\t\t\t/**\n\t\t\t * ### Endpoint\n\t\t\t *\n\t\t\t * GET `/one-time-token/generate`\n\t\t\t *\n\t\t\t * ### API Methods\n\t\t\t *\n\t\t\t * **server:**\n\t\t\t * `auth.api.generateOneTimeToken`\n\t\t\t *\n\t\t\t * **client:**\n\t\t\t * `authClient.oneTimeToken.generate`\n\t\t\t *\n\t\t\t * @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/one-time-token#api-method-one-time-token-generate)\n\t\t\t */\n\t\t\tgenerateOneTimeToken: createAuthEndpoint(\n\t\t\t\t\"/one-time-token/generate\",\n\t\t\t\t{\n\t\t\t\t\tmethod: \"GET\",\n\t\t\t\t\tuse: [sessionMiddleware],\n\t\t\t\t},\n\t\t\t\tasync (c) => {\n\t\t\t\t\t//if request exist, it means it's a client request\n\t\t\t\t\tif (opts?.disableClientRequest && c.request) {\n\t\t\t\t\t\tthrow c.error(\"BAD_REQUEST\", {\n\t\t\t\t\t\t\tmessage: \"Client requests are disabled\",\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t\tconst session = c.context.session;\n\t\t\t\t\tconst token = await generateToken(c, session);\n\t\t\t\t\treturn c.json({ token });\n\t\t\t\t},\n\t\t\t),\n\t\t\t/**\n\t\t\t * ### Endpoint\n\t\t\t *\n\t\t\t * POST `/one-time-token/verify`\n\t\t\t *\n\t\t\t * ### API Methods\n\t\t\t *\n\t\t\t * **server:**\n\t\t\t * `auth.api.verifyOneTimeToken`\n\t\t\t *\n\t\t\t * **client:**\n\t\t\t * `authClient.oneTimeToken.verify`\n\t\t\t *\n\t\t\t * @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/one-time-token#api-method-one-time-token-verify)\n\t\t\t */\n\t\t\tverifyOneTimeToken: createAuthEndpoint(\n\t\t\t\t\"/one-time-token/verify\",\n\t\t\t\t{\n\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\tbody: verifyOneTimeTokenBodySchema,\n\t\t\t\t},\n\t\t\t\tasync (c) => {\n\t\t\t\t\tconst { token } = c.body;\n\t\t\t\t\tconst storedToken = await storeToken(c, token);\n\t\t\t\t\tconst verificationValue =\n\t\t\t\t\t\tawait c.context.internalAdapter.findVerificationValue(\n\t\t\t\t\t\t\t`one-time-token:${storedToken}`,\n\t\t\t\t\t\t);\n\t\t\t\t\tif (!verificationValue) {\n\t\t\t\t\t\tthrow c.error(\"BAD_REQUEST\", {\n\t\t\t\t\t\t\tmessage: \"Invalid token\",\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t\tawait c.context.internalAdapter.deleteVerificationValue(\n\t\t\t\t\t\tverificationValue.id,\n\t\t\t\t\t);\n\t\t\t\t\tif (verificationValue.expiresAt < new Date()) {\n\t\t\t\t\t\tthrow c.error(\"BAD_REQUEST\", {\n\t\t\t\t\t\t\tmessage: \"Token expired\",\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t\tconst session = await c.context.internalAdapter.findSession(\n\t\t\t\t\t\tverificationValue.value,\n\t\t\t\t\t);\n\t\t\t\t\tif (!session) {\n\t\t\t\t\t\tthrow c.error(\"BAD_REQUEST\", {\n\t\t\t\t\t\t\tmessage: \"Session not found\",\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t\tif (!opts?.disableSetSessionCookie) {\n\t\t\t\t\t\tawait setSessionCookie(c, session);\n\t\t\t\t\t}\n\n\t\t\t\t\tif (session.session.expiresAt < new Date()) {\n\t\t\t\t\t\tthrow c.error(\"BAD_REQUEST\", {\n\t\t\t\t\t\t\tmessage: \"Session expired\",\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\treturn c.json(session);\n\t\t\t\t},\n\t\t\t),\n\t\t},\n\t\thooks: {\n\t\t\tafter: [\n\t\t\t\t{\n\t\t\t\t\tmatcher: () => true,\n\t\t\t\t\thandler: createAuthMiddleware(async (ctx) => {\n\t\t\t\t\t\tif (ctx.context.newSession) {\n\t\t\t\t\t\t\tif (!opts?.setOttHeaderOnNewSession) {\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tconst exposedHeaders =\n\t\t\t\t\t\t\t\tctx.context.responseHeaders?.get(\n\t\t\t\t\t\t\t\t\t\"access-control-expose-headers\",\n\t\t\t\t\t\t\t\t) || \"\";\n\t\t\t\t\t\t\tconst headersSet = new Set(\n\t\t\t\t\t\t\t\texposedHeaders\n\t\t\t\t\t\t\t\t\t.split(\",\")\n\t\t\t\t\t\t\t\t\t.map((header) => header.trim())\n\t\t\t\t\t\t\t\t\t.filter(Boolean),\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\theadersSet.add(\"set-ott\");\n\t\t\t\t\t\t\tconst token = await generateToken(ctx, ctx.context.newSession);\n\t\t\t\t\t\t\tctx.setHeader(\"set-ott\", token);\n\t\t\t\t\t\t\tctx.setHeader(\n\t\t\t\t\t\t\t\t\"Access-Control-Expose-Headers\",\n\t\t\t\t\t\t\t\tArray.from(headersSet).join(\", \"),\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t}),\n\t\t\t\t},\n\t\t\t],\n\t\t},\n\t\toptions,\n\t} satisfies BetterAuthPlugin;\n};\n"],"mappings":";;;;;;;;;;AAqEA,MAAM,+BAA+B,EAAE,OAAO,EAC7C,OAAO,EAAE,QAAQ,CAAC,KAAK,EACtB,aAAa,2CACb,CAAC,EACF,CAAC;AAEF,MAAa,gBAAgB,YAA8C;CAC1E,MAAM,OAAO;EACZ,YAAY;EACZ,GAAG;EACH;CAED,eAAe,WAAW,KAA6B,OAAe;AACrE,MAAI,KAAK,eAAe,SACvB,QAAO,MAAM,iBAAiB,MAAM;AAErC,MACC,OAAO,KAAK,eAAe,YAC3B,UAAU,KAAK,cACf,KAAK,WAAW,SAAS,gBAEzB,QAAO,MAAM,KAAK,WAAW,KAAK,MAAM;AAGzC,SAAO;;CAGR,eAAe,cACd,GACA,SAIC;EACD,MAAM,QAAQ,MAAM,gBACjB,MAAM,KAAK,cAAc,SAAS,EAAE,GACpC,qBAAqB,GAAG;EAC3B,MAAM,YAAY,IAAI,KAAK,KAAK,KAAK,IAAI,MAAM,aAAa,KAAK,KAAK,IAAK;EAC3E,MAAM,cAAc,MAAM,WAAW,GAAG,MAAM;AAC9C,QAAM,EAAE,QAAQ,gBAAgB,wBAAwB;GACvD,OAAO,QAAQ,QAAQ;GACvB,YAAY,kBAAkB;GAC9B;GACA,CAAC;AACF,SAAO;;AAGR,QAAO;EACN,IAAI;EACJ,WAAW;GAgBV,sBAAsB,mBACrB,4BACA;IACC,QAAQ;IACR,KAAK,CAAC,kBAAkB;IACxB,EACD,OAAO,MAAM;AAEZ,QAAI,MAAM,wBAAwB,EAAE,QACnC,OAAM,EAAE,MAAM,eAAe,EAC5B,SAAS,gCACT,CAAC;IAEH,MAAM,UAAU,EAAE,QAAQ;IAC1B,MAAM,QAAQ,MAAM,cAAc,GAAG,QAAQ;AAC7C,WAAO,EAAE,KAAK,EAAE,OAAO,CAAC;KAEzB;GAgBD,oBAAoB,mBACnB,0BACA;IACC,QAAQ;IACR,MAAM;IACN,EACD,OAAO,MAAM;IACZ,MAAM,EAAE,UAAU,EAAE;IACpB,MAAM,cAAc,MAAM,WAAW,GAAG,MAAM;IAC9C,MAAM,oBACL,MAAM,EAAE,QAAQ,gBAAgB,sBAC/B,kBAAkB,cAClB;AACF,QAAI,CAAC,kBACJ,OAAM,EAAE,MAAM,eAAe,EAC5B,SAAS,iBACT,CAAC;AAEH,UAAM,EAAE,QAAQ,gBAAgB,wBAC/B,kBAAkB,GAClB;AACD,QAAI,kBAAkB,4BAAY,IAAI,MAAM,CAC3C,OAAM,EAAE,MAAM,eAAe,EAC5B,SAAS,iBACT,CAAC;IAEH,MAAM,UAAU,MAAM,EAAE,QAAQ,gBAAgB,YAC/C,kBAAkB,MAClB;AACD,QAAI,CAAC,QACJ,OAAM,EAAE,MAAM,eAAe,EAC5B,SAAS,qBACT,CAAC;AAEH,QAAI,CAAC,MAAM,wBACV,OAAM,iBAAiB,GAAG,QAAQ;AAGnC,QAAI,QAAQ,QAAQ,4BAAY,IAAI,MAAM,CACzC,OAAM,EAAE,MAAM,eAAe,EAC5B,SAAS,mBACT,CAAC;AAGH,WAAO,EAAE,KAAK,QAAQ;KAEvB;GACD;EACD,OAAO,EACN,OAAO,CACN;GACC,eAAe;GACf,SAAS,qBAAqB,OAAO,QAAQ;AAC5C,QAAI,IAAI,QAAQ,YAAY;AAC3B,SAAI,CAAC,MAAM,yBACV;KAED,MAAM,iBACL,IAAI,QAAQ,iBAAiB,IAC5B,gCACA,IAAI;KACN,MAAM,aAAa,IAAI,IACtB,eACE,MAAM,IAAI,CACV,KAAK,WAAW,OAAO,MAAM,CAAC,CAC9B,OAAO,QAAQ,CACjB;AACD,gBAAW,IAAI,UAAU;KACzB,MAAM,QAAQ,MAAM,cAAc,KAAK,IAAI,QAAQ,WAAW;AAC9D,SAAI,UAAU,WAAW,MAAM;AAC/B,SAAI,UACH,iCACA,MAAM,KAAK,WAAW,CAAC,KAAK,KAAK,CACjC;;KAED;GACF,CACD,EACD;EACD;EACA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { base64Url } from "@better-auth/utils/base64";
|
|
2
|
+
import { createHash } from "@better-auth/utils/hash";
|
|
3
|
+
|
|
4
|
+
//#region src/plugins/one-time-token/utils.ts
|
|
5
|
+
const defaultKeyHasher = async (token) => {
|
|
6
|
+
const hash = await createHash("SHA-256").digest(new TextEncoder().encode(token));
|
|
7
|
+
return base64Url.encode(new Uint8Array(hash), { padding: false });
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
//#endregion
|
|
11
|
+
export { defaultKeyHasher };
|
|
12
|
+
//# sourceMappingURL=utils.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.mjs","names":[],"sources":["../../../src/plugins/one-time-token/utils.ts"],"sourcesContent":["import { base64Url } from \"@better-auth/utils/base64\";\nimport { createHash } from \"@better-auth/utils/hash\";\nexport const defaultKeyHasher = async (token: string) => {\n\tconst hash = await createHash(\"SHA-256\").digest(\n\t\tnew TextEncoder().encode(token),\n\t);\n\tconst hashed = base64Url.encode(new Uint8Array(hash), {\n\t\tpadding: false,\n\t});\n\treturn hashed;\n};\n"],"mappings":";;;;AAEA,MAAa,mBAAmB,OAAO,UAAkB;CACxD,MAAM,OAAO,MAAM,WAAW,UAAU,CAAC,OACxC,IAAI,aAAa,CAAC,OAAO,MAAM,CAC/B;AAID,QAHe,UAAU,OAAO,IAAI,WAAW,KAAK,EAAE,EACrD,SAAS,OACT,CAAC"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { AuthContext, BetterAuthOptions } from "@better-auth/core";
|
|
2
|
+
import { DBFieldAttributeConfig, DBFieldType } from "@better-auth/core/db";
|
|
3
|
+
import { OpenAPIParameter, OpenAPISchemaType } from "better-call";
|
|
4
|
+
|
|
5
|
+
//#region src/plugins/open-api/generator.d.ts
|
|
6
|
+
interface Path {
|
|
7
|
+
get?: {
|
|
8
|
+
tags?: string[];
|
|
9
|
+
operationId?: string;
|
|
10
|
+
description?: string;
|
|
11
|
+
security?: [{
|
|
12
|
+
bearerAuth: string[];
|
|
13
|
+
}];
|
|
14
|
+
parameters?: OpenAPIParameter[];
|
|
15
|
+
responses?: { [key in string]: {
|
|
16
|
+
description?: string;
|
|
17
|
+
content: {
|
|
18
|
+
"application/json": {
|
|
19
|
+
schema: {
|
|
20
|
+
type?: OpenAPISchemaType;
|
|
21
|
+
properties?: Record<string, any>;
|
|
22
|
+
required?: string[];
|
|
23
|
+
$ref?: string;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
} };
|
|
28
|
+
} | undefined;
|
|
29
|
+
post?: {
|
|
30
|
+
tags?: string[];
|
|
31
|
+
operationId?: string;
|
|
32
|
+
description?: string;
|
|
33
|
+
security?: [{
|
|
34
|
+
bearerAuth: string[];
|
|
35
|
+
}];
|
|
36
|
+
parameters?: OpenAPIParameter[];
|
|
37
|
+
requestBody?: {
|
|
38
|
+
content: {
|
|
39
|
+
"application/json": {
|
|
40
|
+
schema: {
|
|
41
|
+
type?: OpenAPISchemaType;
|
|
42
|
+
properties?: Record<string, any>;
|
|
43
|
+
required?: string[];
|
|
44
|
+
$ref?: string;
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
responses?: { [key in string]: {
|
|
50
|
+
description?: string;
|
|
51
|
+
content: {
|
|
52
|
+
"application/json": {
|
|
53
|
+
schema: {
|
|
54
|
+
type?: OpenAPISchemaType;
|
|
55
|
+
properties?: Record<string, any>;
|
|
56
|
+
required?: string[];
|
|
57
|
+
$ref?: string;
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
} };
|
|
62
|
+
} | undefined;
|
|
63
|
+
}
|
|
64
|
+
type FieldSchema = {
|
|
65
|
+
type: DBFieldType;
|
|
66
|
+
default?: (DBFieldAttributeConfig["defaultValue"] | "Generated at runtime") | undefined;
|
|
67
|
+
readOnly?: boolean | undefined;
|
|
68
|
+
format?: string;
|
|
69
|
+
};
|
|
70
|
+
type OpenAPIModelSchema = {
|
|
71
|
+
type: "object";
|
|
72
|
+
properties: Record<string, FieldSchema>;
|
|
73
|
+
required?: string[] | undefined;
|
|
74
|
+
};
|
|
75
|
+
declare function generator(ctx: AuthContext, options: BetterAuthOptions): Promise<{
|
|
76
|
+
openapi: string;
|
|
77
|
+
info: {
|
|
78
|
+
title: string;
|
|
79
|
+
description: string;
|
|
80
|
+
version: string;
|
|
81
|
+
};
|
|
82
|
+
components: {
|
|
83
|
+
securitySchemes: {
|
|
84
|
+
apiKeyCookie: {
|
|
85
|
+
type: string;
|
|
86
|
+
in: string;
|
|
87
|
+
name: string;
|
|
88
|
+
description: string;
|
|
89
|
+
};
|
|
90
|
+
bearerAuth: {
|
|
91
|
+
type: string;
|
|
92
|
+
scheme: string;
|
|
93
|
+
description: string;
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
schemas: {
|
|
97
|
+
[x: string]: OpenAPIModelSchema;
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
security: {
|
|
101
|
+
apiKeyCookie: never[];
|
|
102
|
+
bearerAuth: never[];
|
|
103
|
+
}[];
|
|
104
|
+
servers: {
|
|
105
|
+
url: string;
|
|
106
|
+
}[];
|
|
107
|
+
tags: {
|
|
108
|
+
name: string;
|
|
109
|
+
description: string;
|
|
110
|
+
}[];
|
|
111
|
+
paths: Record<string, Path>;
|
|
112
|
+
}>;
|
|
113
|
+
//#endregion
|
|
114
|
+
export { FieldSchema, OpenAPIModelSchema, Path, generator };
|
|
115
|
+
//# sourceMappingURL=generator.d.mts.map
|
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
import { db_exports } from "../../db/index.mjs";
|
|
2
|
+
import { getEndpoints } from "../../api/index.mjs";
|
|
3
|
+
import * as z from "zod";
|
|
4
|
+
|
|
5
|
+
//#region src/plugins/open-api/generator.ts
|
|
6
|
+
const allowedType = new Set([
|
|
7
|
+
"string",
|
|
8
|
+
"number",
|
|
9
|
+
"boolean",
|
|
10
|
+
"array",
|
|
11
|
+
"object"
|
|
12
|
+
]);
|
|
13
|
+
function getTypeFromZodType(zodType) {
|
|
14
|
+
if (zodType instanceof z.ZodDefault) return getTypeFromZodType(zodType.unwrap());
|
|
15
|
+
const type = zodType.type;
|
|
16
|
+
return allowedType.has(type) ? type : "string";
|
|
17
|
+
}
|
|
18
|
+
function getFieldSchema(field) {
|
|
19
|
+
const schema = {
|
|
20
|
+
type: field.type === "date" ? "string" : field.type,
|
|
21
|
+
...field.type === "date" && { format: "date-time" }
|
|
22
|
+
};
|
|
23
|
+
if (field.defaultValue !== void 0) schema.default = typeof field.defaultValue === "function" ? "Generated at runtime" : field.defaultValue;
|
|
24
|
+
if (field.input === false) schema.readOnly = true;
|
|
25
|
+
return schema;
|
|
26
|
+
}
|
|
27
|
+
function getParameters(options) {
|
|
28
|
+
const parameters = [];
|
|
29
|
+
if (options.metadata?.openapi?.parameters) {
|
|
30
|
+
parameters.push(...options.metadata.openapi.parameters);
|
|
31
|
+
return parameters;
|
|
32
|
+
}
|
|
33
|
+
if (options.query instanceof z.ZodObject) Object.entries(options.query.shape).forEach(([key, value]) => {
|
|
34
|
+
if (value instanceof z.ZodType) parameters.push({
|
|
35
|
+
name: key,
|
|
36
|
+
in: "query",
|
|
37
|
+
schema: {
|
|
38
|
+
...processZodType(value),
|
|
39
|
+
..."minLength" in value && value.minLength ? { minLength: value.minLength } : {}
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
return parameters;
|
|
44
|
+
}
|
|
45
|
+
function getRequestBody(options) {
|
|
46
|
+
if (options.metadata?.openapi?.requestBody) return options.metadata.openapi.requestBody;
|
|
47
|
+
if (!options.body) return void 0;
|
|
48
|
+
if (options.body instanceof z.ZodObject || options.body instanceof z.ZodOptional) {
|
|
49
|
+
const shape = options.body.shape;
|
|
50
|
+
if (!shape) return void 0;
|
|
51
|
+
const properties = {};
|
|
52
|
+
const required = [];
|
|
53
|
+
Object.entries(shape).forEach(([key, value]) => {
|
|
54
|
+
if (value instanceof z.ZodType) {
|
|
55
|
+
properties[key] = processZodType(value);
|
|
56
|
+
if (!(value instanceof z.ZodOptional)) required.push(key);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
return {
|
|
60
|
+
required: options.body instanceof z.ZodOptional ? false : options.body ? true : false,
|
|
61
|
+
content: { "application/json": { schema: {
|
|
62
|
+
type: "object",
|
|
63
|
+
properties,
|
|
64
|
+
required
|
|
65
|
+
} } }
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function processZodType(zodType) {
|
|
70
|
+
if (zodType instanceof z.ZodOptional) {
|
|
71
|
+
const innerSchema = processZodType(zodType.unwrap());
|
|
72
|
+
if (innerSchema.type) {
|
|
73
|
+
const type = Array.isArray(innerSchema.type) ? innerSchema.type : [innerSchema.type];
|
|
74
|
+
return {
|
|
75
|
+
...innerSchema,
|
|
76
|
+
type: Array.from(new Set([...type, "null"]))
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
return { anyOf: [innerSchema, { type: "null" }] };
|
|
80
|
+
}
|
|
81
|
+
if (zodType instanceof z.ZodDefault) {
|
|
82
|
+
const innerSchema = processZodType(zodType.unwrap());
|
|
83
|
+
const defaultValueDef = zodType._def.defaultValue;
|
|
84
|
+
const defaultValue = typeof defaultValueDef === "function" ? defaultValueDef() : defaultValueDef;
|
|
85
|
+
return {
|
|
86
|
+
...innerSchema,
|
|
87
|
+
default: defaultValue
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
if (zodType instanceof z.ZodObject) {
|
|
91
|
+
const shape = zodType.shape;
|
|
92
|
+
if (shape) {
|
|
93
|
+
const properties = {};
|
|
94
|
+
const required = [];
|
|
95
|
+
Object.entries(shape).forEach(([key, value]) => {
|
|
96
|
+
if (value instanceof z.ZodType) {
|
|
97
|
+
properties[key] = processZodType(value);
|
|
98
|
+
if (!(value instanceof z.ZodOptional)) required.push(key);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
return {
|
|
102
|
+
type: "object",
|
|
103
|
+
properties,
|
|
104
|
+
...required.length > 0 ? { required } : {},
|
|
105
|
+
description: zodType.description
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
type: getTypeFromZodType(zodType),
|
|
111
|
+
description: zodType.description
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
function getResponse(responses) {
|
|
115
|
+
return {
|
|
116
|
+
"400": {
|
|
117
|
+
content: { "application/json": { schema: {
|
|
118
|
+
type: "object",
|
|
119
|
+
properties: { message: { type: "string" } },
|
|
120
|
+
required: ["message"]
|
|
121
|
+
} } },
|
|
122
|
+
description: "Bad Request. Usually due to missing parameters, or invalid parameters."
|
|
123
|
+
},
|
|
124
|
+
"401": {
|
|
125
|
+
content: { "application/json": { schema: {
|
|
126
|
+
type: "object",
|
|
127
|
+
properties: { message: { type: "string" } },
|
|
128
|
+
required: ["message"]
|
|
129
|
+
} } },
|
|
130
|
+
description: "Unauthorized. Due to missing or invalid authentication."
|
|
131
|
+
},
|
|
132
|
+
"403": {
|
|
133
|
+
content: { "application/json": { schema: {
|
|
134
|
+
type: "object",
|
|
135
|
+
properties: { message: { type: "string" } }
|
|
136
|
+
} } },
|
|
137
|
+
description: "Forbidden. You do not have permission to access this resource or to perform this action."
|
|
138
|
+
},
|
|
139
|
+
"404": {
|
|
140
|
+
content: { "application/json": { schema: {
|
|
141
|
+
type: "object",
|
|
142
|
+
properties: { message: { type: "string" } }
|
|
143
|
+
} } },
|
|
144
|
+
description: "Not Found. The requested resource was not found."
|
|
145
|
+
},
|
|
146
|
+
"429": {
|
|
147
|
+
content: { "application/json": { schema: {
|
|
148
|
+
type: "object",
|
|
149
|
+
properties: { message: { type: "string" } }
|
|
150
|
+
} } },
|
|
151
|
+
description: "Too Many Requests. You have exceeded the rate limit. Try again later."
|
|
152
|
+
},
|
|
153
|
+
"500": {
|
|
154
|
+
content: { "application/json": { schema: {
|
|
155
|
+
type: "object",
|
|
156
|
+
properties: { message: { type: "string" } }
|
|
157
|
+
} } },
|
|
158
|
+
description: "Internal Server Error. This is a problem with the server that you cannot fix."
|
|
159
|
+
},
|
|
160
|
+
...responses
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
function toOpenApiPath(path) {
|
|
164
|
+
return path.split("/").map((part) => part.startsWith(":") ? `{${part.slice(1)}}` : part).join("/");
|
|
165
|
+
}
|
|
166
|
+
async function generator(ctx, options) {
|
|
167
|
+
const baseEndpoints = getEndpoints(ctx, {
|
|
168
|
+
...options,
|
|
169
|
+
plugins: []
|
|
170
|
+
});
|
|
171
|
+
const tables = (0, db_exports.getAuthTables)({
|
|
172
|
+
...options,
|
|
173
|
+
session: {
|
|
174
|
+
...options.session,
|
|
175
|
+
storeSessionInDatabase: true
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
const components = { schemas: { ...Object.entries(tables).reduce((acc, [key, value]) => {
|
|
179
|
+
const modelName = key.charAt(0).toUpperCase() + key.slice(1);
|
|
180
|
+
const fields = value.fields;
|
|
181
|
+
const required = [];
|
|
182
|
+
const properties = { id: { type: "string" } };
|
|
183
|
+
Object.entries(fields).forEach(([fieldKey, fieldValue]) => {
|
|
184
|
+
if (!fieldValue) return;
|
|
185
|
+
properties[fieldKey] = getFieldSchema(fieldValue);
|
|
186
|
+
if (fieldValue.required && fieldValue.input !== false) required.push(fieldKey);
|
|
187
|
+
});
|
|
188
|
+
Object.entries(properties).forEach(([key, prop]) => {
|
|
189
|
+
const field = value.fields[key];
|
|
190
|
+
if (field && field.type === "date" && prop.type === "string") prop.format = "date-time";
|
|
191
|
+
});
|
|
192
|
+
acc[modelName] = {
|
|
193
|
+
type: "object",
|
|
194
|
+
properties,
|
|
195
|
+
required
|
|
196
|
+
};
|
|
197
|
+
return acc;
|
|
198
|
+
}, {}) } };
|
|
199
|
+
const paths = {};
|
|
200
|
+
Object.entries(baseEndpoints.api).forEach(([_, value]) => {
|
|
201
|
+
if (!value.path || ctx.options.disabledPaths?.includes(value.path)) return;
|
|
202
|
+
const options = value.options;
|
|
203
|
+
if (options.metadata?.SERVER_ONLY) return;
|
|
204
|
+
const path = toOpenApiPath(value.path);
|
|
205
|
+
const methods = Array.isArray(options.method) ? options.method : [options.method];
|
|
206
|
+
for (const method of methods.filter((m) => m === "GET" || m === "DELETE")) paths[path] = {
|
|
207
|
+
...paths[path],
|
|
208
|
+
[method.toLowerCase()]: {
|
|
209
|
+
tags: ["Default", ...options.metadata?.openapi?.tags || []],
|
|
210
|
+
description: options.metadata?.openapi?.description,
|
|
211
|
+
operationId: options.metadata?.openapi?.operationId,
|
|
212
|
+
security: [{ bearerAuth: [] }],
|
|
213
|
+
parameters: getParameters(options),
|
|
214
|
+
responses: getResponse(options.metadata?.openapi?.responses)
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
for (const method of methods.filter((m) => m === "POST" || m === "PATCH" || m === "PUT")) {
|
|
218
|
+
const body = getRequestBody(options);
|
|
219
|
+
paths[path] = {
|
|
220
|
+
...paths[path],
|
|
221
|
+
[method.toLowerCase()]: {
|
|
222
|
+
tags: ["Default", ...options.metadata?.openapi?.tags || []],
|
|
223
|
+
description: options.metadata?.openapi?.description,
|
|
224
|
+
operationId: options.metadata?.openapi?.operationId,
|
|
225
|
+
security: [{ bearerAuth: [] }],
|
|
226
|
+
parameters: getParameters(options),
|
|
227
|
+
...body ? { requestBody: body } : { requestBody: { content: { "application/json": { schema: {
|
|
228
|
+
type: "object",
|
|
229
|
+
properties: {}
|
|
230
|
+
} } } } },
|
|
231
|
+
responses: getResponse(options.metadata?.openapi?.responses)
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
for (const plugin of options.plugins || []) {
|
|
237
|
+
if (plugin.id === "open-api") continue;
|
|
238
|
+
const pluginEndpoints = getEndpoints(ctx, {
|
|
239
|
+
...options,
|
|
240
|
+
plugins: [plugin]
|
|
241
|
+
});
|
|
242
|
+
const api = Object.keys(pluginEndpoints.api).map((key) => {
|
|
243
|
+
if (baseEndpoints.api[key] === void 0) return pluginEndpoints.api[key];
|
|
244
|
+
return null;
|
|
245
|
+
}).filter((x) => x !== null);
|
|
246
|
+
Object.entries(api).forEach(([key, value]) => {
|
|
247
|
+
if (!value.path || ctx.options.disabledPaths?.includes(value.path)) return;
|
|
248
|
+
const options = value.options;
|
|
249
|
+
if (options.metadata?.SERVER_ONLY) return;
|
|
250
|
+
const path = toOpenApiPath(value.path);
|
|
251
|
+
const methods = Array.isArray(options.method) ? options.method : [options.method];
|
|
252
|
+
for (const method of methods.filter((m) => m === "GET" || m === "DELETE")) paths[path] = {
|
|
253
|
+
...paths[path],
|
|
254
|
+
[method.toLowerCase()]: {
|
|
255
|
+
tags: options.metadata?.openapi?.tags || [plugin.id.charAt(0).toUpperCase() + plugin.id.slice(1)],
|
|
256
|
+
description: options.metadata?.openapi?.description,
|
|
257
|
+
operationId: options.metadata?.openapi?.operationId,
|
|
258
|
+
security: [{ bearerAuth: [] }],
|
|
259
|
+
parameters: getParameters(options),
|
|
260
|
+
responses: getResponse(options.metadata?.openapi?.responses)
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
for (const method of methods.filter((m) => m === "POST" || m === "PATCH" || m === "PUT")) paths[path] = {
|
|
264
|
+
...paths[path],
|
|
265
|
+
[method.toLowerCase()]: {
|
|
266
|
+
tags: options.metadata?.openapi?.tags || [plugin.id.charAt(0).toUpperCase() + plugin.id.slice(1)],
|
|
267
|
+
description: options.metadata?.openapi?.description,
|
|
268
|
+
operationId: options.metadata?.openapi?.operationId,
|
|
269
|
+
security: [{ bearerAuth: [] }],
|
|
270
|
+
parameters: getParameters(options),
|
|
271
|
+
requestBody: getRequestBody(options),
|
|
272
|
+
responses: getResponse(options.metadata?.openapi?.responses)
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
return {
|
|
278
|
+
openapi: "3.1.1",
|
|
279
|
+
info: {
|
|
280
|
+
title: "Better Auth",
|
|
281
|
+
description: "API Reference for your Better Auth Instance",
|
|
282
|
+
version: "1.1.0"
|
|
283
|
+
},
|
|
284
|
+
components: {
|
|
285
|
+
...components,
|
|
286
|
+
securitySchemes: {
|
|
287
|
+
apiKeyCookie: {
|
|
288
|
+
type: "apiKey",
|
|
289
|
+
in: "cookie",
|
|
290
|
+
name: "apiKeyCookie",
|
|
291
|
+
description: "API Key authentication via cookie"
|
|
292
|
+
},
|
|
293
|
+
bearerAuth: {
|
|
294
|
+
type: "http",
|
|
295
|
+
scheme: "bearer",
|
|
296
|
+
description: "Bearer token authentication"
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
},
|
|
300
|
+
security: [{
|
|
301
|
+
apiKeyCookie: [],
|
|
302
|
+
bearerAuth: []
|
|
303
|
+
}],
|
|
304
|
+
servers: [{ url: ctx.baseURL }],
|
|
305
|
+
tags: [{
|
|
306
|
+
name: "Default",
|
|
307
|
+
description: "Default endpoints that are included with Better Auth by default. These endpoints are not part of any plugin."
|
|
308
|
+
}],
|
|
309
|
+
paths
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
//#endregion
|
|
314
|
+
export { generator };
|
|
315
|
+
//# sourceMappingURL=generator.mjs.map
|