@masheev/better-auth 0.0.0-stage → 1.7.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +20 -0
- package/README.md +31 -2
- package/TYPE-PATCH-NOTICE.md +9 -0
- package/TYPE-PATCH-PROVENANCE.json +267 -0
- package/dist/_virtual/_rolldown/runtime.mjs +27 -0
- package/dist/adapters/drizzle-adapter/index.d.mts +1 -0
- package/dist/adapters/drizzle-adapter/index.mjs +2 -0
- package/dist/adapters/index.d.mts +26 -0
- package/dist/adapters/index.mjs +9 -0
- package/dist/adapters/kysely-adapter/index.d.mts +1 -0
- package/dist/adapters/kysely-adapter/index.mjs +2 -0
- package/dist/adapters/memory-adapter/index.d.mts +1 -0
- package/dist/adapters/memory-adapter/index.mjs +2 -0
- package/dist/adapters/mongodb-adapter/index.d.mts +1 -0
- package/dist/adapters/mongodb-adapter/index.mjs +2 -0
- package/dist/adapters/prisma-adapter/index.d.mts +1 -0
- package/dist/adapters/prisma-adapter/index.mjs +2 -0
- package/dist/api/dispatch.d.mts +34 -0
- package/dist/api/dispatch.mjs +275 -0
- package/dist/api/index.d.mts +4053 -0
- package/dist/api/index.mjs +220 -0
- package/dist/api/middlewares/authorization.d.mts +69 -0
- package/dist/api/middlewares/authorization.mjs +78 -0
- package/dist/api/middlewares/index.d.mts +2 -0
- package/dist/api/middlewares/origin-check.d.mts +17 -0
- package/dist/api/middlewares/origin-check.mjs +155 -0
- package/dist/api/rate-limiter/index.mjs +318 -0
- package/dist/api/routes/account.d.mts +413 -0
- package/dist/api/routes/account.mjs +619 -0
- package/dist/api/routes/callback.d.mts +32 -0
- package/dist/api/routes/callback.mjs +261 -0
- package/dist/api/routes/email-verification.d.mts +160 -0
- package/dist/api/routes/email-verification.mjs +324 -0
- package/dist/api/routes/error.d.mts +27 -0
- package/dist/api/routes/error.mjs +387 -0
- package/dist/api/routes/index.d.mts +12 -0
- package/dist/api/routes/ok.d.mts +35 -0
- package/dist/api/routes/ok.mjs +27 -0
- package/dist/api/routes/password.d.mts +182 -0
- package/dist/api/routes/password.mjs +206 -0
- package/dist/api/routes/session.d.mts +450 -0
- package/dist/api/routes/session.mjs +481 -0
- package/dist/api/routes/sign-in.d.mts +186 -0
- package/dist/api/routes/sign-in.mjs +368 -0
- package/dist/api/routes/sign-out.d.mts +51 -0
- package/dist/api/routes/sign-out.mjs +96 -0
- package/dist/api/routes/sign-up.d.mts +159 -0
- package/dist/api/routes/sign-up.mjs +275 -0
- package/dist/api/routes/update-session.d.mts +74 -0
- package/dist/api/routes/update-session.mjs +57 -0
- package/dist/api/routes/update-user.d.mts +428 -0
- package/dist/api/routes/update-user.mjs +522 -0
- package/dist/api/state/oauth.d.mts +53 -0
- package/dist/api/state/oauth.mjs +38 -0
- package/dist/api/state/should-session-refresh.d.mts +12 -0
- package/dist/api/state/should-session-refresh.mjs +13 -0
- package/dist/api/to-auth-endpoints.mjs +60 -0
- package/dist/auth/base.mjs +66 -0
- package/dist/auth/full.d.mts +28 -0
- package/dist/auth/full.mjs +29 -0
- package/dist/auth/minimal.d.mts +10 -0
- package/dist/auth/minimal.mjs +11 -0
- package/dist/auth/trusted-origins.mjs +106 -0
- package/dist/client/broadcast-channel.d.mts +19 -0
- package/dist/client/broadcast-channel.mjs +44 -0
- package/dist/client/config.d.mts +90 -0
- package/dist/client/config.mjs +113 -0
- package/dist/client/equality.d.mts +19 -0
- package/dist/client/equality.mjs +42 -0
- package/dist/client/fetch-plugins.mjs +17 -0
- package/dist/client/focus-manager.d.mts +10 -0
- package/dist/client/focus-manager.mjs +30 -0
- package/dist/client/index.d.mts +35 -0
- package/dist/client/index.mjs +22 -0
- package/dist/client/lynx/index.d.mts +43 -0
- package/dist/client/lynx/index.mjs +22 -0
- package/dist/client/lynx/lynx-store.d.mts +46 -0
- package/dist/client/lynx/lynx-store.mjs +44 -0
- package/dist/client/online-manager.d.mts +11 -0
- package/dist/client/online-manager.mjs +33 -0
- package/dist/client/parser.d.mts +10 -0
- package/dist/client/parser.mjs +70 -0
- package/dist/client/path-to-object.d.mts +113 -0
- package/dist/client/plugins/index.d.mts +44 -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/proxy.mjs +78 -0
- package/dist/client/query.d.mts +23 -0
- package/dist/client/query.mjs +124 -0
- package/dist/client/react/index.d.mts +44 -0
- package/dist/client/react/index.mjs +22 -0
- package/dist/client/react/react-store.d.mts +46 -0
- package/dist/client/react/react-store.mjs +44 -0
- package/dist/client/session-atom.d.mts +11 -0
- package/dist/client/session-atom.mjs +178 -0
- package/dist/client/session-refresh.d.mts +20 -0
- package/dist/client/session-refresh.mjs +131 -0
- package/dist/client/solid/index.d.mts +44 -0
- package/dist/client/solid/index.mjs +22 -0
- package/dist/client/solid/solid-store.mjs +21 -0
- package/dist/client/svelte/index.d.mts +44 -0
- package/dist/client/svelte/index.mjs +18 -0
- package/dist/client/types.d.mts +51 -0
- package/dist/client/vanilla.d.mts +42 -0
- package/dist/client/vanilla.mjs +18 -0
- package/dist/client/vue/index.d.mts +67 -0
- package/dist/client/vue/index.mjs +54 -0
- package/dist/client/vue/vue-store.mjs +23 -0
- package/dist/context/create-context.mjs +235 -0
- package/dist/context/helpers.mjs +158 -0
- package/dist/context/init-minimal.mjs +17 -0
- package/dist/context/init.mjs +19 -0
- package/dist/context/secret-utils.mjs +53 -0
- package/dist/context/store-capabilities.mjs +12 -0
- package/dist/cookies/cache.mjs +33 -0
- package/dist/cookies/cookie-utils.d.mts +72 -0
- package/dist/cookies/cookie-utils.mjs +203 -0
- package/dist/cookies/index.d.mts +124 -0
- package/dist/cookies/index.mjs +350 -0
- package/dist/cookies/jwt.mjs +44 -0
- package/dist/cookies/session-store.d.mts +32 -0
- package/dist/cookies/session-store.mjs +183 -0
- package/dist/crypto/buffer.d.mts +7 -0
- package/dist/crypto/buffer.mjs +16 -0
- package/dist/crypto/index.d.mts +32 -0
- package/dist/crypto/index.mjs +69 -0
- package/dist/crypto/jwt.d.mts +9 -0
- package/dist/crypto/jwt.mjs +141 -0
- package/dist/crypto/password.d.mts +13 -0
- package/dist/crypto/password.mjs +14 -0
- package/dist/crypto/random.d.mts +4 -0
- package/dist/crypto/random.mjs +5 -0
- package/dist/db/adapter-base.d.mts +7 -0
- package/dist/db/adapter-base.mjs +25 -0
- package/dist/db/adapter-kysely.d.mts +7 -0
- package/dist/db/adapter-kysely.mjs +17 -0
- package/dist/db/field-converter.d.mts +7 -0
- package/dist/db/field-converter.mjs +19 -0
- package/dist/db/field.d.mts +41 -0
- package/dist/db/get-migration.d.mts +56 -0
- package/dist/db/get-migration.mjs +685 -0
- package/dist/db/get-schema.d.mts +13 -0
- package/dist/db/get-schema.mjs +39 -0
- package/dist/db/index.d.mts +10 -0
- package/dist/db/index.mjs +35 -0
- package/dist/db/internal-adapter.d.mts +14 -0
- package/dist/db/internal-adapter.mjs +951 -0
- package/dist/db/revoke-unproven-account-access.d.mts +21 -0
- package/dist/db/revoke-unproven-account-access.mjs +58 -0
- package/dist/db/schema.d.mts +62 -0
- package/dist/db/schema.mjs +161 -0
- package/dist/db/to-zod.d.mts +35 -0
- package/dist/db/to-zod.mjs +23 -0
- package/dist/db/verification-token-storage.mjs +25 -0
- package/dist/db/with-hooks.d.mts +37 -0
- package/dist/db/with-hooks.mjs +255 -0
- package/dist/index.d.mts +30 -0
- package/dist/index.mjs +17 -0
- package/dist/integrations/cookie-plugin-guard.mjs +18 -0
- package/dist/integrations/next-js.d.mts +29 -0
- package/dist/integrations/next-js.mjs +105 -0
- package/dist/integrations/node.d.mts +11 -0
- package/dist/integrations/node.mjs +13 -0
- package/dist/integrations/solid-start.d.mts +22 -0
- package/dist/integrations/solid-start.mjs +15 -0
- package/dist/integrations/svelte-kit.d.mts +38 -0
- package/dist/integrations/svelte-kit.mjs +57 -0
- package/dist/integrations/tanstack-start-solid.d.mts +33 -0
- package/dist/integrations/tanstack-start-solid.mjs +57 -0
- package/dist/integrations/tanstack-start.d.mts +33 -0
- package/dist/integrations/tanstack-start.mjs +57 -0
- package/dist/oauth2/account-key.mjs +43 -0
- package/dist/oauth2/errors.mjs +49 -0
- package/dist/oauth2/index.d.mts +5 -0
- package/dist/oauth2/index.mjs +5 -0
- package/dist/oauth2/link-account.d.mts +96 -0
- package/dist/oauth2/link-account.mjs +329 -0
- package/dist/oauth2/state.d.mts +54 -0
- package/dist/oauth2/state.mjs +67 -0
- package/dist/oauth2/utils.d.mts +11 -0
- package/dist/oauth2/utils.mjs +33 -0
- package/dist/package.mjs +4 -0
- package/dist/plugins/access/access.d.mts +17 -0
- package/dist/plugins/access/access.mjs +78 -0
- package/dist/plugins/access/index.d.mts +3 -0
- package/dist/plugins/access/index.mjs +2 -0
- package/dist/plugins/access/types.d.mts +24 -0
- package/dist/plugins/additional-fields/client.d.mts +100 -0
- package/dist/plugins/additional-fields/client.mjs +11 -0
- package/dist/plugins/admin/access/index.d.mts +2 -0
- package/dist/plugins/admin/access/index.mjs +2 -0
- package/dist/plugins/admin/access/statement.d.mts +51 -0
- package/dist/plugins/admin/access/statement.mjs +52 -0
- package/dist/plugins/admin/admin.d.mts +911 -0
- package/dist/plugins/admin/admin.mjs +89 -0
- package/dist/plugins/admin/client.d.mts +81 -0
- package/dist/plugins/admin/client.mjs +39 -0
- package/dist/plugins/admin/error-codes.d.mts +30 -0
- package/dist/plugins/admin/error-codes.mjs +29 -0
- package/dist/plugins/admin/has-permission.mjs +12 -0
- package/dist/plugins/admin/index.d.mts +3 -0
- package/dist/plugins/admin/index.mjs +2 -0
- package/dist/plugins/admin/routes.mjs +919 -0
- package/dist/plugins/admin/schema.d.mts +40 -0
- package/dist/plugins/admin/schema.mjs +33 -0
- package/dist/plugins/admin/types.d.mts +88 -0
- package/dist/plugins/anonymous/client.d.mts +32 -0
- package/dist/plugins/anonymous/client.mjs +21 -0
- package/dist/plugins/anonymous/error-codes.d.mts +15 -0
- package/dist/plugins/anonymous/error-codes.mjs +14 -0
- package/dist/plugins/anonymous/index.d.mts +175 -0
- package/dist/plugins/anonymous/index.mjs +219 -0
- package/dist/plugins/anonymous/schema.d.mts +15 -0
- package/dist/plugins/anonymous/schema.mjs +9 -0
- package/dist/plugins/anonymous/types.d.mts +65 -0
- package/dist/plugins/bearer/index.d.mts +45 -0
- package/dist/plugins/bearer/index.mjs +74 -0
- package/dist/plugins/captcha/constants.d.mts +9 -0
- package/dist/plugins/captcha/constants.mjs +27 -0
- package/dist/plugins/captcha/error-codes.mjs +13 -0
- package/dist/plugins/captcha/index.d.mts +27 -0
- package/dist/plugins/captcha/index.mjs +79 -0
- package/dist/plugins/captcha/types.d.mts +52 -0
- package/dist/plugins/captcha/utils.mjs +9 -0
- package/dist/plugins/captcha/verify-handlers/captchafox.mjs +27 -0
- package/dist/plugins/captcha/verify-handlers/cloudflare-turnstile.mjs +47 -0
- package/dist/plugins/captcha/verify-handlers/google-recaptcha.mjs +32 -0
- package/dist/plugins/captcha/verify-handlers/h-captcha.mjs +27 -0
- package/dist/plugins/custom-session/client.d.mts +17 -0
- package/dist/plugins/custom-session/client.mjs +7 -0
- package/dist/plugins/custom-session/index.d.mts +73 -0
- package/dist/plugins/custom-session/index.mjs +65 -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/error-codes.mjs +19 -0
- package/dist/plugins/device-authorization/index.d.mts +558 -0
- package/dist/plugins/device-authorization/index.mjs +87 -0
- package/dist/plugins/device-authorization/routes.d.mts +32 -0
- package/dist/plugins/device-authorization/routes.mjs +725 -0
- package/dist/plugins/device-authorization/schema.d.mts +18 -0
- package/dist/plugins/device-authorization/schema.mjs +63 -0
- package/dist/plugins/email-otp/client.d.mts +21 -0
- package/dist/plugins/email-otp/client.mjs +17 -0
- package/dist/plugins/email-otp/error-codes.d.mts +10 -0
- package/dist/plugins/email-otp/error-codes.mjs +9 -0
- package/dist/plugins/email-otp/index.d.mts +551 -0
- package/dist/plugins/email-otp/index.mjs +145 -0
- package/dist/plugins/email-otp/otp-token.mjs +55 -0
- package/dist/plugins/email-otp/routes.mjs +784 -0
- package/dist/plugins/email-otp/types.d.mts +109 -0
- package/dist/plugins/email-otp/utils.mjs +17 -0
- package/dist/plugins/generic-oauth/error-codes.mjs +8 -0
- package/dist/plugins/generic-oauth/index.d.mts +52 -0
- package/dist/plugins/generic-oauth/index.mjs +279 -0
- package/dist/plugins/generic-oauth/providers/auth0.d.mts +36 -0
- package/dist/plugins/generic-oauth/providers/auth0.mjs +49 -0
- package/dist/plugins/generic-oauth/providers/gumroad.d.mts +31 -0
- package/dist/plugins/generic-oauth/providers/gumroad.mjs +62 -0
- package/dist/plugins/generic-oauth/providers/hubspot.d.mts +36 -0
- package/dist/plugins/generic-oauth/providers/hubspot.mjs +62 -0
- package/dist/plugins/generic-oauth/providers/index.d.mts +10 -0
- package/dist/plugins/generic-oauth/providers/keycloak.d.mts +36 -0
- package/dist/plugins/generic-oauth/providers/keycloak.mjs +47 -0
- package/dist/plugins/generic-oauth/providers/line.d.mts +54 -0
- package/dist/plugins/generic-oauth/providers/line.mjs +93 -0
- package/dist/plugins/generic-oauth/providers/microsoft-entra-id.d.mts +39 -0
- package/dist/plugins/generic-oauth/providers/microsoft-entra-id.mjs +104 -0
- package/dist/plugins/generic-oauth/providers/okta.d.mts +36 -0
- package/dist/plugins/generic-oauth/providers/okta.mjs +47 -0
- package/dist/plugins/generic-oauth/providers/patreon.d.mts +29 -0
- package/dist/plugins/generic-oauth/providers/patreon.mjs +61 -0
- package/dist/plugins/generic-oauth/providers/slack.d.mts +29 -0
- package/dist/plugins/generic-oauth/providers/slack.mjs +63 -0
- package/dist/plugins/generic-oauth/providers/yandex.d.mts +29 -0
- package/dist/plugins/generic-oauth/providers/yandex.mjs +67 -0
- package/dist/plugins/generic-oauth/types.d.mts +268 -0
- package/dist/plugins/haveibeenpwned/index.d.mts +63 -0
- package/dist/plugins/haveibeenpwned/index.mjs +81 -0
- package/dist/plugins/index.d.mts +69 -0
- package/dist/plugins/index.mjs +49 -0
- package/dist/plugins/jwt/adapter.mjs +68 -0
- package/dist/plugins/jwt/client.d.mts +41 -0
- package/dist/plugins/jwt/client.mjs +19 -0
- package/dist/plugins/jwt/cookie-cache.mjs +77 -0
- package/dist/plugins/jwt/index.d.mts +246 -0
- package/dist/plugins/jwt/index.mjs +214 -0
- package/dist/plugins/jwt/schema.d.mts +33 -0
- package/dist/plugins/jwt/schema.mjs +29 -0
- package/dist/plugins/jwt/sign.d.mts +128 -0
- package/dist/plugins/jwt/sign.mjs +130 -0
- package/dist/plugins/jwt/types.d.mts +256 -0
- package/dist/plugins/jwt/utils.d.mts +41 -0
- package/dist/plugins/jwt/utils.mjs +64 -0
- package/dist/plugins/jwt/verify.d.mts +11 -0
- package/dist/plugins/jwt/verify.mjs +45 -0
- package/dist/plugins/last-login-method/client.d.mts +48 -0
- package/dist/plugins/last-login-method/client.mjs +48 -0
- package/dist/plugins/last-login-method/index.d.mts +127 -0
- package/dist/plugins/last-login-method/index.mjs +98 -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/index.d.mts +213 -0
- package/dist/plugins/magic-link/index.mjs +208 -0
- package/dist/plugins/magic-link/utils.mjs +9 -0
- package/dist/plugins/multi-session/client.d.mts +19 -0
- package/dist/plugins/multi-session/client.mjs +19 -0
- package/dist/plugins/multi-session/error-codes.d.mts +8 -0
- package/dist/plugins/multi-session/error-codes.mjs +5 -0
- package/dist/plugins/multi-session/index.d.mts +212 -0
- package/dist/plugins/multi-session/index.mjs +217 -0
- package/dist/plugins/oauth-popup/client.d.mts +82 -0
- package/dist/plugins/oauth-popup/client.mjs +203 -0
- package/dist/plugins/oauth-popup/constants.d.mts +11 -0
- package/dist/plugins/oauth-popup/constants.mjs +11 -0
- package/dist/plugins/oauth-popup/error-codes.d.mts +11 -0
- package/dist/plugins/oauth-popup/error-codes.mjs +10 -0
- package/dist/plugins/oauth-popup/index.d.mts +67 -0
- package/dist/plugins/oauth-popup/index.mjs +232 -0
- package/dist/plugins/oauth-popup/types.d.mts +30 -0
- package/dist/plugins/oauth-proxy/index.d.mts +130 -0
- package/dist/plugins/oauth-proxy/index.mjs +407 -0
- package/dist/plugins/oauth-proxy/utils.mjs +55 -0
- package/dist/plugins/one-tap/client.d.mts +174 -0
- package/dist/plugins/one-tap/client.mjs +208 -0
- package/dist/plugins/one-tap/index.d.mts +82 -0
- package/dist/plugins/one-tap/index.mjs +100 -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/index.d.mts +132 -0
- package/dist/plugins/one-time-token/index.mjs +107 -0
- package/dist/plugins/one-time-token/utils.mjs +9 -0
- package/dist/plugins/open-api/generator.d.mts +126 -0
- package/dist/plugins/open-api/generator.mjs +557 -0
- package/dist/plugins/open-api/index.d.mts +97 -0
- package/dist/plugins/open-api/index.mjs +65 -0
- package/dist/plugins/open-api/logo.mjs +13 -0
- package/dist/plugins/organization/access/index.d.mts +2 -0
- package/dist/plugins/organization/access/index.mjs +2 -0
- package/dist/plugins/organization/access/statement.d.mts +113 -0
- package/dist/plugins/organization/access/statement.mjs +77 -0
- package/dist/plugins/organization/adapter.d.mts +815 -0
- package/dist/plugins/organization/adapter.mjs +813 -0
- package/dist/plugins/organization/call.mjs +15 -0
- package/dist/plugins/organization/client.d.mts +375 -0
- package/dist/plugins/organization/client.mjs +104 -0
- package/dist/plugins/organization/error-codes.d.mts +66 -0
- package/dist/plugins/organization/error-codes.mjs +65 -0
- package/dist/plugins/organization/has-permission.d.mts +17 -0
- package/dist/plugins/organization/has-permission.mjs +34 -0
- package/dist/plugins/organization/index.d.mts +6 -0
- package/dist/plugins/organization/index.mjs +4 -0
- package/dist/plugins/organization/organization.d.mts +420 -0
- package/dist/plugins/organization/organization.mjs +886 -0
- package/dist/plugins/organization/permission.d.mts +15 -0
- package/dist/plugins/organization/permission.mjs +14 -0
- package/dist/plugins/organization/routes/crud-access-control.d.mts +511 -0
- package/dist/plugins/organization/routes/crud-access-control.mjs +674 -0
- package/dist/plugins/organization/routes/crud-invites.d.mts +1154 -0
- package/dist/plugins/organization/routes/crud-invites.mjs +602 -0
- package/dist/plugins/organization/routes/crud-members.d.mts +1057 -0
- package/dist/plugins/organization/routes/crud-members.mjs +518 -0
- package/dist/plugins/organization/routes/crud-org.d.mts +918 -0
- package/dist/plugins/organization/routes/crud-org.mjs +455 -0
- package/dist/plugins/organization/routes/crud-team.d.mts +1238 -0
- package/dist/plugins/organization/routes/crud-team.mjs +766 -0
- package/dist/plugins/organization/schema.d.mts +390 -0
- package/dist/plugins/organization/schema.mjs +65 -0
- package/dist/plugins/organization/types.d.mts +691 -0
- package/dist/plugins/phone-number/client.d.mts +31 -0
- package/dist/plugins/phone-number/client.mjs +19 -0
- package/dist/plugins/phone-number/error-codes.d.mts +19 -0
- package/dist/plugins/phone-number/error-codes.mjs +18 -0
- package/dist/plugins/phone-number/index.d.mts +360 -0
- package/dist/plugins/phone-number/index.mjs +57 -0
- package/dist/plugins/phone-number/routes.mjs +529 -0
- package/dist/plugins/phone-number/schema.d.mts +22 -0
- package/dist/plugins/phone-number/schema.mjs +18 -0
- package/dist/plugins/phone-number/types.d.mts +116 -0
- package/dist/plugins/siwe/client.d.mts +14 -0
- package/dist/plugins/siwe/client.mjs +15 -0
- package/dist/plugins/siwe/index.d.mts +62 -0
- package/dist/plugins/siwe/index.mjs +272 -0
- package/dist/plugins/siwe/parse-message.mjs +60 -0
- package/dist/plugins/siwe/schema.d.mts +35 -0
- package/dist/plugins/siwe/schema.mjs +30 -0
- package/dist/plugins/siwe/types.d.mts +43 -0
- package/dist/plugins/test-utils/auth-helpers.mjs +33 -0
- package/dist/plugins/test-utils/cookie-builder.mjs +55 -0
- package/dist/plugins/test-utils/db-helpers.mjs +65 -0
- package/dist/plugins/test-utils/factories.mjs +38 -0
- package/dist/plugins/test-utils/index.d.mts +73 -0
- package/dist/plugins/test-utils/index.mjs +97 -0
- package/dist/plugins/test-utils/otp-sink.mjs +21 -0
- package/dist/plugins/test-utils/types.d.mts +51 -0
- package/dist/plugins/two-factor/backup-codes/index.d.mts +291 -0
- package/dist/plugins/two-factor/backup-codes/index.mjs +341 -0
- package/dist/plugins/two-factor/client.d.mts +76 -0
- package/dist/plugins/two-factor/client.mjs +41 -0
- package/dist/plugins/two-factor/constant.mjs +6 -0
- package/dist/plugins/two-factor/error-code.d.mts +20 -0
- package/dist/plugins/two-factor/error-code.mjs +19 -0
- package/dist/plugins/two-factor/index.d.mts +720 -0
- package/dist/plugins/two-factor/index.mjs +349 -0
- package/dist/plugins/two-factor/otp/index.d.mts +216 -0
- package/dist/plugins/two-factor/otp/index.mjs +252 -0
- package/dist/plugins/two-factor/schema.d.mts +59 -0
- package/dist/plugins/two-factor/schema.mjs +53 -0
- package/dist/plugins/two-factor/totp/index.d.mts +219 -0
- package/dist/plugins/two-factor/totp/index.mjs +230 -0
- package/dist/plugins/two-factor/types.d.mts +111 -0
- package/dist/plugins/two-factor/utils.mjs +9 -0
- package/dist/plugins/two-factor/verify-two-factor.mjs +205 -0
- package/dist/plugins/username/client.d.mts +38 -0
- package/dist/plugins/username/client.mjs +17 -0
- package/dist/plugins/username/error-codes.d.mts +16 -0
- package/dist/plugins/username/error-codes.mjs +15 -0
- package/dist/plugins/username/index.d.mts +326 -0
- package/dist/plugins/username/index.mjs +312 -0
- package/dist/plugins/username/schema.d.mts +50 -0
- package/dist/plugins/username/schema.mjs +25 -0
- package/dist/social-providers/index.d.mts +1 -0
- package/dist/social-providers/index.mjs +2 -0
- package/dist/state.d.mts +48 -0
- package/dist/state.mjs +149 -0
- package/dist/test-utils/headers.d.mts +8 -0
- package/dist/test-utils/headers.mjs +17 -0
- package/dist/test-utils/http-test-instance.d.mts +413 -0
- package/dist/test-utils/http-test-instance.mjs +107 -0
- package/dist/test-utils/index.d.mts +4 -0
- package/dist/test-utils/index.mjs +4 -0
- package/dist/test-utils/test-instance.d.mts +56 -0
- package/dist/test-utils/test-instance.mjs +242 -0
- package/dist/types/adapter.d.mts +2 -0
- package/dist/types/api.d.mts +28 -0
- package/dist/types/auth.d.mts +32 -0
- package/dist/types/helper.d.mts +26 -0
- package/dist/types/index.d.mts +10 -0
- package/dist/types/index.mjs +1 -0
- package/dist/types/models.d.mts +10 -0
- package/dist/types/plugins.d.mts +19 -0
- package/dist/utils/boolean.mjs +6 -0
- package/dist/utils/constants.mjs +4 -0
- package/dist/utils/date.mjs +6 -0
- package/dist/utils/hashing.mjs +18 -0
- package/dist/utils/hide-metadata.d.mts +6 -0
- package/dist/utils/hide-metadata.mjs +4 -0
- package/dist/utils/index.d.mts +4 -0
- package/dist/utils/is-api-error.d.mts +2 -0
- package/dist/utils/is-api-error.mjs +2 -0
- package/dist/utils/is-atom.mjs +6 -0
- package/dist/utils/is-promise.mjs +6 -0
- package/dist/utils/middleware-response.mjs +7 -0
- package/dist/utils/password.mjs +32 -0
- package/dist/utils/plugin-helper.mjs +14 -0
- package/dist/utils/request.mjs +23 -0
- package/dist/utils/shim.mjs +22 -0
- package/dist/utils/time.d.mts +48 -0
- package/dist/utils/time.mjs +98 -0
- package/dist/utils/url.d.mts +78 -0
- package/dist/utils/url.mjs +238 -0
- package/dist/utils/validate-user-info.mjs +44 -0
- package/dist/utils/wildcard.mjs +106 -0
- package/dist/version.mjs +5 -0
- package/package.json +595 -3
|
@@ -0,0 +1,886 @@
|
|
|
1
|
+
import { getSessionFromCtx } from "../../api/routes/session.mjs";
|
|
2
|
+
import { PACKAGE_VERSION } from "../../version.mjs";
|
|
3
|
+
import { defaultRoles } from "./access/statement.mjs";
|
|
4
|
+
import { ORGANIZATION_ERROR_CODES } from "./error-codes.mjs";
|
|
5
|
+
import { getOrgAdapter } from "./adapter.mjs";
|
|
6
|
+
import { shimContext } from "../../utils/shim.mjs";
|
|
7
|
+
import { orgSessionMiddleware } from "./call.mjs";
|
|
8
|
+
import { hasPermission } from "./has-permission.mjs";
|
|
9
|
+
import { createOrgRole, deleteOrgRole, getOrgRole, listOrgRoles, updateOrgRole } from "./routes/crud-access-control.mjs";
|
|
10
|
+
import { acceptInvitation, cancelInvitation, createInvitation, getInvitation, listInvitations, listUserInvitations, rejectInvitation } from "./routes/crud-invites.mjs";
|
|
11
|
+
import { addMember, getActiveMember, getActiveMemberRole, leaveOrganization, listMembers, removeMember, updateMemberRole } from "./routes/crud-members.mjs";
|
|
12
|
+
import { checkOrganizationSlug, createOrganization, deleteOrganization, getFullOrganization, getOrganization, listOrganizations, setActiveOrganization, updateOrganization } from "./routes/crud-org.mjs";
|
|
13
|
+
import { addTeamMember, createTeam, listOrganizationTeams, listTeamMembers, listUserTeams, removeTeam, removeTeamMember, setActiveTeam, updateTeam } from "./routes/crud-team.mjs";
|
|
14
|
+
import { APIError } from "@better-auth/core/error";
|
|
15
|
+
import { createAuthEndpoint } from "@better-auth/core/api";
|
|
16
|
+
import * as z from "zod";
|
|
17
|
+
//#region src/plugins/organization/organization.ts
|
|
18
|
+
function parseRoles(roles) {
|
|
19
|
+
return Array.isArray(roles) ? roles.join(",") : roles;
|
|
20
|
+
}
|
|
21
|
+
const createHasPermissionBodySchema = z.object({ organizationId: z.string().optional() }).and(z.xor([z.object({ permission: z.record(z.string(), z.array(z.string())) }), z.object({ permissions: z.record(z.string(), z.array(z.string())) })]));
|
|
22
|
+
const createHasPermission = (options) => {
|
|
23
|
+
return createAuthEndpoint("/organization/has-permission", {
|
|
24
|
+
method: "POST",
|
|
25
|
+
requireHeaders: true,
|
|
26
|
+
body: createHasPermissionBodySchema,
|
|
27
|
+
use: [orgSessionMiddleware],
|
|
28
|
+
metadata: {
|
|
29
|
+
$Infer: { body: {} },
|
|
30
|
+
openapi: {
|
|
31
|
+
description: "Check if the user has permission",
|
|
32
|
+
requestBody: { content: { "application/json": { schema: {
|
|
33
|
+
type: "object",
|
|
34
|
+
properties: {
|
|
35
|
+
permission: {
|
|
36
|
+
type: "object",
|
|
37
|
+
description: "The permission to check",
|
|
38
|
+
deprecated: true
|
|
39
|
+
},
|
|
40
|
+
permissions: {
|
|
41
|
+
type: "object",
|
|
42
|
+
description: "The permission to check"
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
required: ["permissions"]
|
|
46
|
+
} } } },
|
|
47
|
+
responses: { "200": {
|
|
48
|
+
description: "Success",
|
|
49
|
+
content: { "application/json": { schema: {
|
|
50
|
+
type: "object",
|
|
51
|
+
properties: {
|
|
52
|
+
error: { type: "string" },
|
|
53
|
+
success: { type: "boolean" }
|
|
54
|
+
},
|
|
55
|
+
required: ["success"]
|
|
56
|
+
} } }
|
|
57
|
+
} }
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}, async (ctx) => {
|
|
61
|
+
const activeOrganizationId = ctx.body.organizationId || ctx.context.session.session.activeOrganizationId;
|
|
62
|
+
if (!activeOrganizationId) throw APIError.from("BAD_REQUEST", ORGANIZATION_ERROR_CODES.NO_ACTIVE_ORGANIZATION);
|
|
63
|
+
const member = await getOrgAdapter(ctx.context, options).findMemberByOrgId({
|
|
64
|
+
userId: ctx.context.session.user.id,
|
|
65
|
+
organizationId: activeOrganizationId
|
|
66
|
+
});
|
|
67
|
+
if (!member) throw APIError.from("UNAUTHORIZED", ORGANIZATION_ERROR_CODES.USER_IS_NOT_A_MEMBER_OF_THE_ORGANIZATION);
|
|
68
|
+
const result = await hasPermission({
|
|
69
|
+
role: member.role,
|
|
70
|
+
options,
|
|
71
|
+
permissions: ctx.body.permissions,
|
|
72
|
+
organizationId: activeOrganizationId
|
|
73
|
+
}, ctx);
|
|
74
|
+
return ctx.json({
|
|
75
|
+
error: null,
|
|
76
|
+
success: result
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
function organization(options) {
|
|
81
|
+
const opts = options || {};
|
|
82
|
+
let endpoints = {
|
|
83
|
+
/**
|
|
84
|
+
* ### Endpoint
|
|
85
|
+
*
|
|
86
|
+
* POST `/organization/create`
|
|
87
|
+
*
|
|
88
|
+
* ### API Methods
|
|
89
|
+
*
|
|
90
|
+
* **server:**
|
|
91
|
+
* `auth.api.createOrganization`
|
|
92
|
+
*
|
|
93
|
+
* **client:**
|
|
94
|
+
* `authClient.organization.create`
|
|
95
|
+
*
|
|
96
|
+
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/organization#api-method-organization-create)
|
|
97
|
+
*/
|
|
98
|
+
createOrganization: createOrganization(opts),
|
|
99
|
+
/**
|
|
100
|
+
* ### Endpoint
|
|
101
|
+
*
|
|
102
|
+
* POST `/organization/update`
|
|
103
|
+
*
|
|
104
|
+
* ### API Methods
|
|
105
|
+
*
|
|
106
|
+
* **server:**
|
|
107
|
+
* `auth.api.updateOrganization`
|
|
108
|
+
*
|
|
109
|
+
* **client:**
|
|
110
|
+
* `authClient.organization.update`
|
|
111
|
+
*
|
|
112
|
+
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/organization#api-method-organization-update)
|
|
113
|
+
*/
|
|
114
|
+
updateOrganization: updateOrganization(opts),
|
|
115
|
+
/**
|
|
116
|
+
* ### Endpoint
|
|
117
|
+
*
|
|
118
|
+
* POST `/organization/delete`
|
|
119
|
+
*
|
|
120
|
+
* ### API Methods
|
|
121
|
+
*
|
|
122
|
+
* **server:**
|
|
123
|
+
* `auth.api.deleteOrganization`
|
|
124
|
+
*
|
|
125
|
+
* **client:**
|
|
126
|
+
* `authClient.organization.delete`
|
|
127
|
+
*
|
|
128
|
+
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/organization#api-method-organization-delete)
|
|
129
|
+
*/
|
|
130
|
+
deleteOrganization: deleteOrganization(opts),
|
|
131
|
+
/**
|
|
132
|
+
* ### Endpoint
|
|
133
|
+
*
|
|
134
|
+
* POST `/organization/set-active`
|
|
135
|
+
*
|
|
136
|
+
* ### API Methods
|
|
137
|
+
*
|
|
138
|
+
* **server:**
|
|
139
|
+
* `auth.api.setActiveOrganization`
|
|
140
|
+
*
|
|
141
|
+
* **client:**
|
|
142
|
+
* `authClient.organization.setActive`
|
|
143
|
+
*
|
|
144
|
+
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/organization#api-method-organization-set-active)
|
|
145
|
+
*/
|
|
146
|
+
setActiveOrganization: setActiveOrganization(opts),
|
|
147
|
+
/**
|
|
148
|
+
* ### Endpoint
|
|
149
|
+
*
|
|
150
|
+
* GET `/organization/get-organization`
|
|
151
|
+
*
|
|
152
|
+
* ### API Methods
|
|
153
|
+
*
|
|
154
|
+
* **server:**
|
|
155
|
+
* `auth.api.getOrganization`
|
|
156
|
+
*
|
|
157
|
+
* **client:**
|
|
158
|
+
* `authClient.organization.getOrganization`
|
|
159
|
+
*
|
|
160
|
+
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/organization#api-method-organization-get-organization)
|
|
161
|
+
*/
|
|
162
|
+
getOrganization: getOrganization(opts),
|
|
163
|
+
/**
|
|
164
|
+
* ### Endpoint
|
|
165
|
+
*
|
|
166
|
+
* GET `/organization/get-full-organization`
|
|
167
|
+
*
|
|
168
|
+
* ### API Methods
|
|
169
|
+
*
|
|
170
|
+
* **server:**
|
|
171
|
+
* `auth.api.getFullOrganization`
|
|
172
|
+
*
|
|
173
|
+
* **client:**
|
|
174
|
+
* `authClient.organization.getFullOrganization`
|
|
175
|
+
*
|
|
176
|
+
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/organization#api-method-organization-get-full-organization)
|
|
177
|
+
*/
|
|
178
|
+
getFullOrganization: getFullOrganization(opts),
|
|
179
|
+
/**
|
|
180
|
+
* ### Endpoint
|
|
181
|
+
*
|
|
182
|
+
* GET `/organization/list`
|
|
183
|
+
*
|
|
184
|
+
* ### API Methods
|
|
185
|
+
*
|
|
186
|
+
* **server:**
|
|
187
|
+
* `auth.api.listOrganizations`
|
|
188
|
+
*
|
|
189
|
+
* **client:**
|
|
190
|
+
* `authClient.organization.list`
|
|
191
|
+
*
|
|
192
|
+
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/organization#api-method-organization-list)
|
|
193
|
+
*/
|
|
194
|
+
listOrganizations: listOrganizations(opts),
|
|
195
|
+
/**
|
|
196
|
+
* ### Endpoint
|
|
197
|
+
*
|
|
198
|
+
* POST `/organization/invite-member`
|
|
199
|
+
*
|
|
200
|
+
* ### API Methods
|
|
201
|
+
*
|
|
202
|
+
* **server:**
|
|
203
|
+
* `auth.api.createInvitation`
|
|
204
|
+
*
|
|
205
|
+
* **client:**
|
|
206
|
+
* `authClient.organization.inviteMember`
|
|
207
|
+
*
|
|
208
|
+
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/organization#api-method-organization-invite-member)
|
|
209
|
+
*/
|
|
210
|
+
createInvitation: createInvitation(opts),
|
|
211
|
+
/**
|
|
212
|
+
* ### Endpoint
|
|
213
|
+
*
|
|
214
|
+
* POST `/organization/cancel-invitation`
|
|
215
|
+
*
|
|
216
|
+
* ### API Methods
|
|
217
|
+
*
|
|
218
|
+
* **server:**
|
|
219
|
+
* `auth.api.cancelInvitation`
|
|
220
|
+
*
|
|
221
|
+
* **client:**
|
|
222
|
+
* `authClient.organization.cancelInvitation`
|
|
223
|
+
*
|
|
224
|
+
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/organization#api-method-organization-cancel-invitation)
|
|
225
|
+
*/
|
|
226
|
+
cancelInvitation: cancelInvitation(opts),
|
|
227
|
+
/**
|
|
228
|
+
* ### Endpoint
|
|
229
|
+
*
|
|
230
|
+
* POST `/organization/accept-invitation`
|
|
231
|
+
*
|
|
232
|
+
* ### API Methods
|
|
233
|
+
*
|
|
234
|
+
* **server:**
|
|
235
|
+
* `auth.api.acceptInvitation`
|
|
236
|
+
*
|
|
237
|
+
* **client:**
|
|
238
|
+
* `authClient.organization.acceptInvitation`
|
|
239
|
+
*
|
|
240
|
+
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/organization#api-method-organization-accept-invitation)
|
|
241
|
+
*/
|
|
242
|
+
acceptInvitation: acceptInvitation(opts),
|
|
243
|
+
/**
|
|
244
|
+
* ### Endpoint
|
|
245
|
+
*
|
|
246
|
+
* GET `/organization/get-invitation`
|
|
247
|
+
*
|
|
248
|
+
* ### API Methods
|
|
249
|
+
*
|
|
250
|
+
* **server:**
|
|
251
|
+
* `auth.api.getInvitation`
|
|
252
|
+
*
|
|
253
|
+
* **client:**
|
|
254
|
+
* `authClient.organization.getInvitation`
|
|
255
|
+
*
|
|
256
|
+
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/organization#api-method-organization-get-invitation)
|
|
257
|
+
*/
|
|
258
|
+
getInvitation: getInvitation(opts),
|
|
259
|
+
/**
|
|
260
|
+
* ### Endpoint
|
|
261
|
+
*
|
|
262
|
+
* POST `/organization/reject-invitation`
|
|
263
|
+
*
|
|
264
|
+
* ### API Methods
|
|
265
|
+
*
|
|
266
|
+
* **server:**
|
|
267
|
+
* `auth.api.rejectInvitation`
|
|
268
|
+
*
|
|
269
|
+
* **client:**
|
|
270
|
+
* `authClient.organization.rejectInvitation`
|
|
271
|
+
*
|
|
272
|
+
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/organization#api-method-organization-reject-invitation)
|
|
273
|
+
*/
|
|
274
|
+
rejectInvitation: rejectInvitation(opts),
|
|
275
|
+
/**
|
|
276
|
+
* ### Endpoint
|
|
277
|
+
*
|
|
278
|
+
* GET `/organization/list-invitations`
|
|
279
|
+
*
|
|
280
|
+
* ### API Methods
|
|
281
|
+
*
|
|
282
|
+
* **server:**
|
|
283
|
+
* `auth.api.listInvitations`
|
|
284
|
+
*
|
|
285
|
+
* **client:**
|
|
286
|
+
* `authClient.organization.listInvitations`
|
|
287
|
+
*
|
|
288
|
+
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/organization#api-method-organization-list-invitations)
|
|
289
|
+
*/
|
|
290
|
+
listInvitations: listInvitations(opts),
|
|
291
|
+
/**
|
|
292
|
+
* ### Endpoint
|
|
293
|
+
*
|
|
294
|
+
* GET `/organization/get-active-member`
|
|
295
|
+
*
|
|
296
|
+
* ### API Methods
|
|
297
|
+
*
|
|
298
|
+
* **server:**
|
|
299
|
+
* `auth.api.getActiveMember`
|
|
300
|
+
*
|
|
301
|
+
* **client:**
|
|
302
|
+
* `authClient.organization.getActiveMember`
|
|
303
|
+
*
|
|
304
|
+
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/organization#api-method-organization-get-active-member)
|
|
305
|
+
*/
|
|
306
|
+
getActiveMember: getActiveMember(opts),
|
|
307
|
+
/**
|
|
308
|
+
* ### Endpoint
|
|
309
|
+
*
|
|
310
|
+
* POST `/organization/check-slug`
|
|
311
|
+
*
|
|
312
|
+
* ### API Methods
|
|
313
|
+
*
|
|
314
|
+
* **server:**
|
|
315
|
+
* `auth.api.checkOrganizationSlug`
|
|
316
|
+
*
|
|
317
|
+
* **client:**
|
|
318
|
+
* `authClient.organization.checkSlug`
|
|
319
|
+
*
|
|
320
|
+
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/organization#api-method-organization-check-slug)
|
|
321
|
+
*/
|
|
322
|
+
checkOrganizationSlug: checkOrganizationSlug(opts),
|
|
323
|
+
/**
|
|
324
|
+
* Add a member to an organization directly, bypassing the invitation flow.
|
|
325
|
+
*
|
|
326
|
+
* **Server-only:** callable as `auth.api.addMember` from trusted server
|
|
327
|
+
* code. It is not registered as an HTTP route and has no client method, so
|
|
328
|
+
* it runs no session or permission check of its own; the caller is
|
|
329
|
+
* responsible for authorizing the request.
|
|
330
|
+
*
|
|
331
|
+
* ### API Methods
|
|
332
|
+
*
|
|
333
|
+
* **server:**
|
|
334
|
+
* `auth.api.addMember`
|
|
335
|
+
*
|
|
336
|
+
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/organization#api-method-organization-add-member)
|
|
337
|
+
*/
|
|
338
|
+
addMember: addMember(opts),
|
|
339
|
+
/**
|
|
340
|
+
* ### Endpoint
|
|
341
|
+
*
|
|
342
|
+
* POST `/organization/remove-member`
|
|
343
|
+
*
|
|
344
|
+
* ### API Methods
|
|
345
|
+
*
|
|
346
|
+
* **server:**
|
|
347
|
+
* `auth.api.removeMember`
|
|
348
|
+
*
|
|
349
|
+
* **client:**
|
|
350
|
+
* `authClient.organization.removeMember`
|
|
351
|
+
*
|
|
352
|
+
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/organization#api-method-organization-remove-member)
|
|
353
|
+
*/
|
|
354
|
+
removeMember: removeMember(opts),
|
|
355
|
+
/**
|
|
356
|
+
* ### Endpoint
|
|
357
|
+
*
|
|
358
|
+
* POST `/organization/update-member-role`
|
|
359
|
+
*
|
|
360
|
+
* ### API Methods
|
|
361
|
+
*
|
|
362
|
+
* **server:**
|
|
363
|
+
* `auth.api.updateMemberRole`
|
|
364
|
+
*
|
|
365
|
+
* **client:**
|
|
366
|
+
* `authClient.organization.updateMemberRole`
|
|
367
|
+
*
|
|
368
|
+
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/organization#api-method-organization-update-member-role)
|
|
369
|
+
*/
|
|
370
|
+
updateMemberRole: updateMemberRole(opts),
|
|
371
|
+
/**
|
|
372
|
+
* ### Endpoint
|
|
373
|
+
*
|
|
374
|
+
* POST `/organization/leave`
|
|
375
|
+
*
|
|
376
|
+
* ### API Methods
|
|
377
|
+
*
|
|
378
|
+
* **server:**
|
|
379
|
+
* `auth.api.leaveOrganization`
|
|
380
|
+
*
|
|
381
|
+
* **client:**
|
|
382
|
+
* `authClient.organization.leave`
|
|
383
|
+
*
|
|
384
|
+
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/organization#api-method-organization-leave)
|
|
385
|
+
*/
|
|
386
|
+
leaveOrganization: leaveOrganization(opts),
|
|
387
|
+
listUserInvitations: listUserInvitations(opts),
|
|
388
|
+
/**
|
|
389
|
+
* ### Endpoint
|
|
390
|
+
*
|
|
391
|
+
* GET `/organization/list-members`
|
|
392
|
+
*
|
|
393
|
+
* ### API Methods
|
|
394
|
+
*
|
|
395
|
+
* **server:**
|
|
396
|
+
* `auth.api.listMembers`
|
|
397
|
+
*
|
|
398
|
+
* **client:**
|
|
399
|
+
* `authClient.organization.listMembers`
|
|
400
|
+
*/
|
|
401
|
+
listMembers: listMembers(opts),
|
|
402
|
+
/**
|
|
403
|
+
* ### Endpoint
|
|
404
|
+
*
|
|
405
|
+
* GET `/organization/get-active-member-role`
|
|
406
|
+
*
|
|
407
|
+
* ### API Methods
|
|
408
|
+
*
|
|
409
|
+
* **server:**
|
|
410
|
+
* `auth.api.getActiveMemberRole`
|
|
411
|
+
*
|
|
412
|
+
* **client:**
|
|
413
|
+
* `authClient.organization.getActiveMemberRole`
|
|
414
|
+
*
|
|
415
|
+
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/organization#api-method-organization-get-active-member-role)
|
|
416
|
+
*/
|
|
417
|
+
getActiveMemberRole: getActiveMemberRole(opts)
|
|
418
|
+
};
|
|
419
|
+
const teamSupport = opts.teams?.enabled;
|
|
420
|
+
const teamEndpoints = {
|
|
421
|
+
/**
|
|
422
|
+
* ### Endpoint
|
|
423
|
+
*
|
|
424
|
+
* POST `/organization/create-team`
|
|
425
|
+
*
|
|
426
|
+
* ### API Methods
|
|
427
|
+
*
|
|
428
|
+
* **server:**
|
|
429
|
+
* `auth.api.createTeam`
|
|
430
|
+
*
|
|
431
|
+
* **client:**
|
|
432
|
+
* `authClient.organization.createTeam`
|
|
433
|
+
*
|
|
434
|
+
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/organization#api-method-organization-create-team)
|
|
435
|
+
*/
|
|
436
|
+
createTeam: createTeam(opts),
|
|
437
|
+
/**
|
|
438
|
+
* ### Endpoint
|
|
439
|
+
*
|
|
440
|
+
* GET `/organization/list-teams`
|
|
441
|
+
*
|
|
442
|
+
* ### API Methods
|
|
443
|
+
*
|
|
444
|
+
* **server:**
|
|
445
|
+
* `auth.api.listOrganizationTeams`
|
|
446
|
+
*
|
|
447
|
+
* **client:**
|
|
448
|
+
* `authClient.organization.listTeams`
|
|
449
|
+
*
|
|
450
|
+
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/organization#api-method-organization-list-teams)
|
|
451
|
+
*/
|
|
452
|
+
listOrganizationTeams: listOrganizationTeams(opts),
|
|
453
|
+
/**
|
|
454
|
+
* ### Endpoint
|
|
455
|
+
*
|
|
456
|
+
* POST `/organization/remove-team`
|
|
457
|
+
*
|
|
458
|
+
* ### API Methods
|
|
459
|
+
*
|
|
460
|
+
* **server:**
|
|
461
|
+
* `auth.api.removeTeam`
|
|
462
|
+
*
|
|
463
|
+
* **client:**
|
|
464
|
+
* `authClient.organization.removeTeam`
|
|
465
|
+
*
|
|
466
|
+
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/organization#api-method-organization-remove-team)
|
|
467
|
+
*/
|
|
468
|
+
removeTeam: removeTeam(opts),
|
|
469
|
+
/**
|
|
470
|
+
* ### Endpoint
|
|
471
|
+
*
|
|
472
|
+
* POST `/organization/update-team`
|
|
473
|
+
*
|
|
474
|
+
* ### API Methods
|
|
475
|
+
*
|
|
476
|
+
* **server:**
|
|
477
|
+
* `auth.api.updateTeam`
|
|
478
|
+
*
|
|
479
|
+
* **client:**
|
|
480
|
+
* `authClient.organization.updateTeam`
|
|
481
|
+
*
|
|
482
|
+
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/organization#api-method-organization-update-team)
|
|
483
|
+
*/
|
|
484
|
+
updateTeam: updateTeam(opts),
|
|
485
|
+
/**
|
|
486
|
+
* ### Endpoint
|
|
487
|
+
*
|
|
488
|
+
* POST `/organization/set-active-team`
|
|
489
|
+
*
|
|
490
|
+
* ### API Methods
|
|
491
|
+
*
|
|
492
|
+
* **server:**
|
|
493
|
+
* `auth.api.setActiveTeam`
|
|
494
|
+
*
|
|
495
|
+
* **client:**
|
|
496
|
+
* `authClient.organization.setActiveTeam`
|
|
497
|
+
*
|
|
498
|
+
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/organization#api-set-active-team)
|
|
499
|
+
*/
|
|
500
|
+
setActiveTeam: setActiveTeam(opts),
|
|
501
|
+
/**
|
|
502
|
+
* ### Endpoint
|
|
503
|
+
*
|
|
504
|
+
* GET `/organization/list-user-teams`
|
|
505
|
+
*
|
|
506
|
+
* ### API Methods
|
|
507
|
+
*
|
|
508
|
+
* **server:**
|
|
509
|
+
* `auth.api.listUserTeams`
|
|
510
|
+
*
|
|
511
|
+
* **client:**
|
|
512
|
+
* `authClient.organization.listUserTeams`
|
|
513
|
+
*
|
|
514
|
+
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/organization#api-set-active-team)
|
|
515
|
+
*/
|
|
516
|
+
listUserTeams: listUserTeams(opts),
|
|
517
|
+
/**
|
|
518
|
+
* ### Endpoint
|
|
519
|
+
*
|
|
520
|
+
* POST `/organization/list-team-members`
|
|
521
|
+
*
|
|
522
|
+
* ### API Methods
|
|
523
|
+
*
|
|
524
|
+
* **server:**
|
|
525
|
+
* `auth.api.listTeamMembers`
|
|
526
|
+
*
|
|
527
|
+
* **client:**
|
|
528
|
+
* `authClient.organization.listTeamMembers`
|
|
529
|
+
*
|
|
530
|
+
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/organization#api-set-active-team)
|
|
531
|
+
*/
|
|
532
|
+
listTeamMembers: listTeamMembers(opts),
|
|
533
|
+
/**
|
|
534
|
+
* ### Endpoint
|
|
535
|
+
*
|
|
536
|
+
* POST `/organization/add-team-member`
|
|
537
|
+
*
|
|
538
|
+
* ### API Methods
|
|
539
|
+
*
|
|
540
|
+
* **server:**
|
|
541
|
+
* `auth.api.addTeamMember`
|
|
542
|
+
*
|
|
543
|
+
* **client:**
|
|
544
|
+
* `authClient.organization.addTeamMember`
|
|
545
|
+
*
|
|
546
|
+
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/organization#api-add-team-member)
|
|
547
|
+
*/
|
|
548
|
+
addTeamMember: addTeamMember(opts),
|
|
549
|
+
/**
|
|
550
|
+
* ### Endpoint
|
|
551
|
+
*
|
|
552
|
+
* POST `/organization/remove-team-member`
|
|
553
|
+
*
|
|
554
|
+
* ### API Methods
|
|
555
|
+
*
|
|
556
|
+
* **server:**
|
|
557
|
+
* `auth.api.removeTeamMember`
|
|
558
|
+
*
|
|
559
|
+
* **client:**
|
|
560
|
+
* `authClient.organization.removeTeamMember`
|
|
561
|
+
*
|
|
562
|
+
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/organization#api-remove-team-member)
|
|
563
|
+
*/
|
|
564
|
+
removeTeamMember: removeTeamMember(opts)
|
|
565
|
+
};
|
|
566
|
+
if (teamSupport) endpoints = {
|
|
567
|
+
...endpoints,
|
|
568
|
+
...teamEndpoints
|
|
569
|
+
};
|
|
570
|
+
const dynamicAccessControlEndpoints = {
|
|
571
|
+
createOrgRole: createOrgRole(opts),
|
|
572
|
+
deleteOrgRole: deleteOrgRole(opts),
|
|
573
|
+
listOrgRoles: listOrgRoles(opts),
|
|
574
|
+
getOrgRole: getOrgRole(opts),
|
|
575
|
+
updateOrgRole: updateOrgRole(opts)
|
|
576
|
+
};
|
|
577
|
+
if (opts.dynamicAccessControl?.enabled) endpoints = {
|
|
578
|
+
...endpoints,
|
|
579
|
+
...dynamicAccessControlEndpoints
|
|
580
|
+
};
|
|
581
|
+
const roles = {
|
|
582
|
+
...defaultRoles,
|
|
583
|
+
...opts.roles
|
|
584
|
+
};
|
|
585
|
+
const teamSchema = teamSupport ? {
|
|
586
|
+
team: {
|
|
587
|
+
modelName: opts.schema?.team?.modelName,
|
|
588
|
+
fields: {
|
|
589
|
+
name: {
|
|
590
|
+
type: "string",
|
|
591
|
+
required: true,
|
|
592
|
+
fieldName: opts.schema?.team?.fields?.name
|
|
593
|
+
},
|
|
594
|
+
memberCount: {
|
|
595
|
+
type: "number",
|
|
596
|
+
required: true,
|
|
597
|
+
defaultValue: 0,
|
|
598
|
+
input: false,
|
|
599
|
+
returned: false,
|
|
600
|
+
fieldName: opts.schema?.team?.fields?.memberCount
|
|
601
|
+
},
|
|
602
|
+
organizationId: {
|
|
603
|
+
type: "string",
|
|
604
|
+
required: true,
|
|
605
|
+
references: {
|
|
606
|
+
model: "organization",
|
|
607
|
+
field: "id"
|
|
608
|
+
},
|
|
609
|
+
fieldName: opts.schema?.team?.fields?.organizationId,
|
|
610
|
+
index: true
|
|
611
|
+
},
|
|
612
|
+
createdAt: {
|
|
613
|
+
type: "date",
|
|
614
|
+
required: true,
|
|
615
|
+
fieldName: opts.schema?.team?.fields?.createdAt
|
|
616
|
+
},
|
|
617
|
+
updatedAt: {
|
|
618
|
+
type: "date",
|
|
619
|
+
required: false,
|
|
620
|
+
fieldName: opts.schema?.team?.fields?.updatedAt,
|
|
621
|
+
onUpdate: () => /* @__PURE__ */ new Date()
|
|
622
|
+
},
|
|
623
|
+
...opts.schema?.team?.additionalFields || {}
|
|
624
|
+
}
|
|
625
|
+
},
|
|
626
|
+
teamMember: {
|
|
627
|
+
modelName: opts.schema?.teamMember?.modelName,
|
|
628
|
+
fields: {
|
|
629
|
+
teamId: {
|
|
630
|
+
type: "string",
|
|
631
|
+
required: true,
|
|
632
|
+
references: {
|
|
633
|
+
model: "team",
|
|
634
|
+
field: "id"
|
|
635
|
+
},
|
|
636
|
+
fieldName: opts.schema?.teamMember?.fields?.teamId,
|
|
637
|
+
index: true
|
|
638
|
+
},
|
|
639
|
+
userId: {
|
|
640
|
+
type: "string",
|
|
641
|
+
required: true,
|
|
642
|
+
references: {
|
|
643
|
+
model: "user",
|
|
644
|
+
field: "id"
|
|
645
|
+
},
|
|
646
|
+
fieldName: opts.schema?.teamMember?.fields?.userId,
|
|
647
|
+
index: true
|
|
648
|
+
},
|
|
649
|
+
membershipKey: {
|
|
650
|
+
type: "string",
|
|
651
|
+
required: false,
|
|
652
|
+
unique: true,
|
|
653
|
+
input: false,
|
|
654
|
+
returned: false,
|
|
655
|
+
fieldName: opts.schema?.teamMember?.fields?.membershipKey
|
|
656
|
+
},
|
|
657
|
+
createdAt: {
|
|
658
|
+
type: "date",
|
|
659
|
+
required: false,
|
|
660
|
+
fieldName: opts.schema?.teamMember?.fields?.createdAt
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
} : {};
|
|
665
|
+
const organizationRoleSchema = opts.dynamicAccessControl?.enabled ? { organizationRole: {
|
|
666
|
+
fields: {
|
|
667
|
+
organizationId: {
|
|
668
|
+
type: "string",
|
|
669
|
+
required: true,
|
|
670
|
+
references: {
|
|
671
|
+
model: "organization",
|
|
672
|
+
field: "id"
|
|
673
|
+
},
|
|
674
|
+
fieldName: opts.schema?.organizationRole?.fields?.organizationId,
|
|
675
|
+
index: true
|
|
676
|
+
},
|
|
677
|
+
role: {
|
|
678
|
+
type: "string",
|
|
679
|
+
required: true,
|
|
680
|
+
fieldName: opts.schema?.organizationRole?.fields?.role,
|
|
681
|
+
index: true
|
|
682
|
+
},
|
|
683
|
+
permission: {
|
|
684
|
+
type: "string",
|
|
685
|
+
required: true,
|
|
686
|
+
fieldName: opts.schema?.organizationRole?.fields?.permission
|
|
687
|
+
},
|
|
688
|
+
createdAt: {
|
|
689
|
+
type: "date",
|
|
690
|
+
required: true,
|
|
691
|
+
defaultValue: () => /* @__PURE__ */ new Date(),
|
|
692
|
+
fieldName: opts.schema?.organizationRole?.fields?.createdAt
|
|
693
|
+
},
|
|
694
|
+
updatedAt: {
|
|
695
|
+
type: "date",
|
|
696
|
+
required: false,
|
|
697
|
+
fieldName: opts.schema?.organizationRole?.fields?.updatedAt,
|
|
698
|
+
onUpdate: () => /* @__PURE__ */ new Date()
|
|
699
|
+
},
|
|
700
|
+
...opts.schema?.organizationRole?.additionalFields || {}
|
|
701
|
+
},
|
|
702
|
+
modelName: opts.schema?.organizationRole?.modelName
|
|
703
|
+
} } : {};
|
|
704
|
+
const schema = {
|
|
705
|
+
organization: {
|
|
706
|
+
modelName: opts.schema?.organization?.modelName,
|
|
707
|
+
fields: {
|
|
708
|
+
name: {
|
|
709
|
+
type: "string",
|
|
710
|
+
required: true,
|
|
711
|
+
sortable: true,
|
|
712
|
+
fieldName: opts.schema?.organization?.fields?.name
|
|
713
|
+
},
|
|
714
|
+
slug: {
|
|
715
|
+
type: "string",
|
|
716
|
+
required: true,
|
|
717
|
+
unique: true,
|
|
718
|
+
sortable: true,
|
|
719
|
+
fieldName: opts.schema?.organization?.fields?.slug,
|
|
720
|
+
index: true
|
|
721
|
+
},
|
|
722
|
+
logo: {
|
|
723
|
+
type: "string",
|
|
724
|
+
required: false,
|
|
725
|
+
fieldName: opts.schema?.organization?.fields?.logo
|
|
726
|
+
},
|
|
727
|
+
createdAt: {
|
|
728
|
+
type: "date",
|
|
729
|
+
required: true,
|
|
730
|
+
fieldName: opts.schema?.organization?.fields?.createdAt
|
|
731
|
+
},
|
|
732
|
+
metadata: {
|
|
733
|
+
type: "string",
|
|
734
|
+
required: false,
|
|
735
|
+
fieldName: opts.schema?.organization?.fields?.metadata
|
|
736
|
+
},
|
|
737
|
+
...opts.schema?.organization?.additionalFields || {}
|
|
738
|
+
}
|
|
739
|
+
},
|
|
740
|
+
...organizationRoleSchema,
|
|
741
|
+
...teamSchema,
|
|
742
|
+
member: {
|
|
743
|
+
modelName: opts.schema?.member?.modelName,
|
|
744
|
+
fields: {
|
|
745
|
+
organizationId: {
|
|
746
|
+
type: "string",
|
|
747
|
+
required: true,
|
|
748
|
+
references: {
|
|
749
|
+
model: "organization",
|
|
750
|
+
field: "id"
|
|
751
|
+
},
|
|
752
|
+
fieldName: opts.schema?.member?.fields?.organizationId,
|
|
753
|
+
index: true
|
|
754
|
+
},
|
|
755
|
+
userId: {
|
|
756
|
+
type: "string",
|
|
757
|
+
required: true,
|
|
758
|
+
fieldName: opts.schema?.member?.fields?.userId,
|
|
759
|
+
references: {
|
|
760
|
+
model: "user",
|
|
761
|
+
field: "id"
|
|
762
|
+
},
|
|
763
|
+
index: true
|
|
764
|
+
},
|
|
765
|
+
role: {
|
|
766
|
+
type: "string",
|
|
767
|
+
required: true,
|
|
768
|
+
sortable: true,
|
|
769
|
+
defaultValue: "member",
|
|
770
|
+
fieldName: opts.schema?.member?.fields?.role
|
|
771
|
+
},
|
|
772
|
+
createdAt: {
|
|
773
|
+
type: "date",
|
|
774
|
+
required: true,
|
|
775
|
+
fieldName: opts.schema?.member?.fields?.createdAt
|
|
776
|
+
},
|
|
777
|
+
...opts.schema?.member?.additionalFields || {}
|
|
778
|
+
}
|
|
779
|
+
},
|
|
780
|
+
invitation: {
|
|
781
|
+
modelName: opts.schema?.invitation?.modelName,
|
|
782
|
+
fields: {
|
|
783
|
+
organizationId: {
|
|
784
|
+
type: "string",
|
|
785
|
+
required: true,
|
|
786
|
+
references: {
|
|
787
|
+
model: "organization",
|
|
788
|
+
field: "id"
|
|
789
|
+
},
|
|
790
|
+
fieldName: opts.schema?.invitation?.fields?.organizationId,
|
|
791
|
+
index: true
|
|
792
|
+
},
|
|
793
|
+
email: {
|
|
794
|
+
type: "string",
|
|
795
|
+
required: true,
|
|
796
|
+
sortable: true,
|
|
797
|
+
fieldName: opts.schema?.invitation?.fields?.email,
|
|
798
|
+
index: true
|
|
799
|
+
},
|
|
800
|
+
role: {
|
|
801
|
+
type: "string",
|
|
802
|
+
required: false,
|
|
803
|
+
sortable: true,
|
|
804
|
+
fieldName: opts.schema?.invitation?.fields?.role
|
|
805
|
+
},
|
|
806
|
+
...teamSupport ? { teamId: {
|
|
807
|
+
type: "string",
|
|
808
|
+
required: false,
|
|
809
|
+
sortable: true,
|
|
810
|
+
fieldName: opts.schema?.invitation?.fields?.teamId
|
|
811
|
+
} } : {},
|
|
812
|
+
status: {
|
|
813
|
+
type: "string",
|
|
814
|
+
required: true,
|
|
815
|
+
sortable: true,
|
|
816
|
+
defaultValue: "pending",
|
|
817
|
+
fieldName: opts.schema?.invitation?.fields?.status
|
|
818
|
+
},
|
|
819
|
+
expiresAt: {
|
|
820
|
+
type: "date",
|
|
821
|
+
required: true,
|
|
822
|
+
fieldName: opts.schema?.invitation?.fields?.expiresAt
|
|
823
|
+
},
|
|
824
|
+
createdAt: {
|
|
825
|
+
type: "date",
|
|
826
|
+
required: true,
|
|
827
|
+
fieldName: opts.schema?.invitation?.fields?.createdAt,
|
|
828
|
+
defaultValue: () => /* @__PURE__ */ new Date()
|
|
829
|
+
},
|
|
830
|
+
inviterId: {
|
|
831
|
+
type: "string",
|
|
832
|
+
references: {
|
|
833
|
+
model: "user",
|
|
834
|
+
field: "id"
|
|
835
|
+
},
|
|
836
|
+
fieldName: opts.schema?.invitation?.fields?.inviterId,
|
|
837
|
+
required: true
|
|
838
|
+
},
|
|
839
|
+
...opts.schema?.invitation?.additionalFields || {}
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
};
|
|
843
|
+
return {
|
|
844
|
+
id: "organization",
|
|
845
|
+
version: PACKAGE_VERSION,
|
|
846
|
+
endpoints: {
|
|
847
|
+
...shimContext(endpoints, {
|
|
848
|
+
orgOptions: opts,
|
|
849
|
+
roles,
|
|
850
|
+
getSession: async (context) => {
|
|
851
|
+
return await getSessionFromCtx(context);
|
|
852
|
+
}
|
|
853
|
+
}),
|
|
854
|
+
hasPermission: createHasPermission(opts)
|
|
855
|
+
},
|
|
856
|
+
schema: {
|
|
857
|
+
...schema,
|
|
858
|
+
session: { fields: {
|
|
859
|
+
activeOrganizationId: {
|
|
860
|
+
type: "string",
|
|
861
|
+
required: false,
|
|
862
|
+
input: false,
|
|
863
|
+
fieldName: opts.schema?.session?.fields?.activeOrganizationId
|
|
864
|
+
},
|
|
865
|
+
...teamSupport ? { activeTeamId: {
|
|
866
|
+
type: "string",
|
|
867
|
+
required: false,
|
|
868
|
+
input: false,
|
|
869
|
+
fieldName: opts.schema?.session?.fields?.activeTeamId
|
|
870
|
+
} } : {}
|
|
871
|
+
} }
|
|
872
|
+
},
|
|
873
|
+
$Infer: {
|
|
874
|
+
Organization: {},
|
|
875
|
+
Invitation: {},
|
|
876
|
+
Member: {},
|
|
877
|
+
Team: teamSupport ? {} : {},
|
|
878
|
+
TeamMember: teamSupport ? {} : {},
|
|
879
|
+
ActiveOrganization: {}
|
|
880
|
+
},
|
|
881
|
+
$ERROR_CODES: ORGANIZATION_ERROR_CODES,
|
|
882
|
+
options: opts
|
|
883
|
+
};
|
|
884
|
+
}
|
|
885
|
+
//#endregion
|
|
886
|
+
export { organization, parseRoles };
|