@hammadj/better-auth 1.5.0-beta.9
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 +33 -0
- package/dist/_virtual/rolldown_runtime.mjs +36 -0
- package/dist/adapters/drizzle-adapter/index.d.mts +1 -0
- package/dist/adapters/drizzle-adapter/index.mjs +3 -0
- package/dist/adapters/index.d.mts +23 -0
- package/dist/adapters/index.mjs +13 -0
- package/dist/adapters/index.mjs.map +1 -0
- package/dist/adapters/kysely-adapter/index.d.mts +1 -0
- package/dist/adapters/kysely-adapter/index.mjs +3 -0
- package/dist/adapters/memory-adapter/index.d.mts +1 -0
- package/dist/adapters/memory-adapter/index.mjs +3 -0
- package/dist/adapters/mongodb-adapter/index.d.mts +1 -0
- package/dist/adapters/mongodb-adapter/index.mjs +3 -0
- package/dist/adapters/prisma-adapter/index.d.mts +1 -0
- package/dist/adapters/prisma-adapter/index.mjs +3 -0
- package/dist/api/index.d.mts +40 -0
- package/dist/api/index.mjs +205 -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 +17 -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 +177 -0
- package/dist/api/rate-limiter/index.mjs.map +1 -0
- package/dist/api/routes/account.d.mts +10 -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 +5 -0
- package/dist/api/routes/callback.mjs +178 -0
- package/dist/api/routes/callback.mjs.map +1 -0
- package/dist/api/routes/email-verification.d.mts +29 -0
- package/dist/api/routes/email-verification.mjs +301 -0
- package/dist/api/routes/email-verification.mjs.map +1 -0
- package/dist/api/routes/error.d.mts +5 -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 +5 -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 +8 -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 +52 -0
- package/dist/api/routes/session.mjs +478 -0
- package/dist/api/routes/session.mjs.map +1 -0
- package/dist/api/routes/sign-in.d.mts +8 -0
- package/dist/api/routes/sign-in.mjs +262 -0
- package/dist/api/routes/sign-in.mjs.map +1 -0
- package/dist/api/routes/sign-out.d.mts +5 -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 +7 -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 +12 -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 +5 -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 +44 -0
- package/dist/auth/base.mjs.map +1 -0
- package/dist/auth/full.d.mts +30 -0
- package/dist/auth/full.mjs +32 -0
- package/dist/auth/full.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 +30 -0
- package/dist/client/index.mjs +21 -0
- package/dist/client/index.mjs.map +1 -0
- package/dist/client/lynx/index.d.mts +62 -0
- package/dist/client/lynx/index.mjs +24 -0
- package/dist/client/lynx/index.mjs.map +1 -0
- package/dist/client/lynx/lynx-store.d.mts +47 -0
- package/dist/client/lynx/lynx-store.mjs +47 -0
- package/dist/client/lynx/lynx-store.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 +57 -0
- package/dist/client/plugins/index.d.mts +58 -0
- package/dist/client/plugins/index.mjs +33 -0
- package/dist/client/plugins/infer-plugin.d.mts +9 -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 +63 -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/solid/index.d.mts +57 -0
- package/dist/client/solid/index.mjs +22 -0
- package/dist/client/solid/index.mjs.map +1 -0
- package/dist/client/solid/solid-store.mjs +24 -0
- package/dist/client/solid/solid-store.mjs.map +1 -0
- package/dist/client/svelte/index.d.mts +63 -0
- package/dist/client/svelte/index.mjs +20 -0
- package/dist/client/svelte/index.mjs.map +1 -0
- package/dist/client/types.d.mts +58 -0
- package/dist/client/vanilla.d.mts +62 -0
- package/dist/client/vanilla.mjs +20 -0
- package/dist/client/vanilla.mjs.map +1 -0
- package/dist/client/vue/index.d.mts +86 -0
- package/dist/client/vue/index.mjs +38 -0
- package/dist/client/vue/index.mjs.map +1 -0
- package/dist/client/vue/vue-store.mjs +26 -0
- package/dist/client/vue/vue-store.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 +62 -0
- package/dist/context/helpers.mjs.map +1 -0
- package/dist/context/init-minimal.mjs +20 -0
- package/dist/context/init-minimal.mjs.map +1 -0
- package/dist/context/init.mjs +22 -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 +67 -0
- package/dist/cookies/index.mjs +264 -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 +28 -0
- package/dist/db/adapter-base.mjs.map +1 -0
- package/dist/db/adapter-kysely.d.mts +8 -0
- package/dist/db/adapter-kysely.mjs +21 -0
- package/dist/db/adapter-kysely.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 +55 -0
- package/dist/db/field.mjs +11 -0
- package/dist/db/field.mjs.map +1 -0
- package/dist/db/get-migration.d.mts +23 -0
- package/dist/db/get-migration.mjs +339 -0
- package/dist/db/get-migration.mjs.map +1 -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 +9 -0
- package/dist/db/index.mjs +36 -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 +26 -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 +52 -0
- package/dist/index.mjs +26 -0
- package/dist/integrations/next-js.d.mts +14 -0
- package/dist/integrations/next-js.mjs +78 -0
- package/dist/integrations/next-js.mjs.map +1 -0
- package/dist/integrations/node.d.mts +13 -0
- package/dist/integrations/node.mjs +16 -0
- package/dist/integrations/node.mjs.map +1 -0
- package/dist/integrations/solid-start.d.mts +23 -0
- package/dist/integrations/solid-start.mjs +17 -0
- package/dist/integrations/solid-start.mjs.map +1 -0
- package/dist/integrations/svelte-kit.d.mts +29 -0
- package/dist/integrations/svelte-kit.mjs +57 -0
- package/dist/integrations/svelte-kit.mjs.map +1 -0
- package/dist/integrations/tanstack-start-solid.d.mts +22 -0
- package/dist/integrations/tanstack-start-solid.mjs +61 -0
- package/dist/integrations/tanstack-start-solid.mjs.map +1 -0
- package/dist/integrations/tanstack-start.d.mts +22 -0
- package/dist/integrations/tanstack-start.mjs +61 -0
- package/dist/integrations/tanstack-start.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 +31 -0
- package/dist/oauth2/link-account.mjs +144 -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 +14 -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 +14 -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 +14 -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 +5 -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 +855 -0
- package/dist/plugins/admin/routes.mjs.map +1 -0
- package/dist/plugins/admin/schema.d.mts +6 -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/anonymous/client.d.mts +9 -0
- package/dist/plugins/anonymous/client.mjs +22 -0
- package/dist/plugins/anonymous/client.mjs.map +1 -0
- package/dist/plugins/anonymous/error-codes.d.mts +5 -0
- package/dist/plugins/anonymous/error-codes.mjs +16 -0
- package/dist/plugins/anonymous/error-codes.mjs.map +1 -0
- package/dist/plugins/anonymous/index.d.mts +14 -0
- package/dist/plugins/anonymous/index.mjs +163 -0
- package/dist/plugins/anonymous/index.mjs.map +1 -0
- package/dist/plugins/anonymous/schema.d.mts +5 -0
- package/dist/plugins/anonymous/schema.mjs +11 -0
- package/dist/plugins/anonymous/schema.mjs.map +1 -0
- package/dist/plugins/anonymous/types.d.mts +68 -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 +9 -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 +5 -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 +17 -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 +223 -0
- package/dist/plugins/api-key/routes/verify-api-key.mjs.map +1 -0
- package/dist/plugins/api-key/schema.d.mts +11 -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 +25 -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 +14 -0
- package/dist/plugins/captcha/index.mjs +60 -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 +27 -0
- package/dist/plugins/captcha/verify-handlers/captchafox.mjs.map +1 -0
- package/dist/plugins/captcha/verify-handlers/cloudflare-turnstile.mjs +25 -0
- package/dist/plugins/captcha/verify-handlers/cloudflare-turnstile.mjs.map +1 -0
- package/dist/plugins/captcha/verify-handlers/google-recaptcha.mjs +29 -0
- package/dist/plugins/captcha/verify-handlers/google-recaptcha.mjs.map +1 -0
- package/dist/plugins/captcha/verify-handlers/h-captcha.mjs +27 -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 +10 -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 +26 -0
- package/dist/plugins/custom-session/index.mjs +70 -0
- package/dist/plugins/custom-session/index.mjs.map +1 -0
- package/dist/plugins/device-authorization/client.d.mts +5 -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 +28 -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 +7 -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 +5 -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 +14 -0
- package/dist/plugins/email-otp/index.mjs +108 -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 +564 -0
- package/dist/plugins/email-otp/routes.mjs.map +1 -0
- package/dist/plugins/email-otp/types.d.mts +74 -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 +19 -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 +5 -0
- package/dist/plugins/generic-oauth/error-codes.mjs +15 -0
- package/dist/plugins/generic-oauth/error-codes.mjs.map +1 -0
- package/dist/plugins/generic-oauth/index.d.mts +34 -0
- package/dist/plugins/generic-oauth/index.mjs +137 -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 +394 -0
- package/dist/plugins/generic-oauth/routes.mjs.map +1 -0
- package/dist/plugins/generic-oauth/types.d.mts +145 -0
- package/dist/plugins/haveibeenpwned/index.d.mts +21 -0
- package/dist/plugins/haveibeenpwned/index.mjs +56 -0
- package/dist/plugins/haveibeenpwned/index.mjs.map +1 -0
- package/dist/plugins/index.d.mts +68 -0
- package/dist/plugins/index.mjs +51 -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 +18 -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 +17 -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 +5 -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 +18 -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 +52 -0
- package/dist/plugins/last-login-method/index.mjs +77 -0
- package/dist/plugins/last-login-method/index.mjs.map +1 -0
- package/dist/plugins/magic-link/client.d.mts +5 -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 +61 -0
- package/dist/plugins/magic-link/index.mjs +167 -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 +46 -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 +8 -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 +5 -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 +22 -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 +39 -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 +44 -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 +8 -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 +32 -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 +26 -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 +159 -0
- package/dist/plugins/one-tap/client.mjs +214 -0
- package/dist/plugins/one-tap/client.mjs.map +1 -0
- package/dist/plugins/one-tap/index.d.mts +27 -0
- package/dist/plugins/one-tap/index.mjs +96 -0
- package/dist/plugins/one-tap/index.mjs.map +1 -0
- package/dist/plugins/one-time-token/client.d.mts +7 -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 +53 -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 +45 -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 +205 -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 +151 -0
- package/dist/plugins/organization/client.mjs +107 -0
- package/dist/plugins/organization/client.mjs.map +1 -0
- package/dist/plugins/organization/error-codes.d.mts +5 -0
- package/dist/plugins/organization/error-codes.mjs +65 -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 +252 -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 +26 -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 +11 -0
- package/dist/plugins/organization/routes/crud-access-control.mjs +656 -0
- package/dist/plugins/organization/routes/crud-access-control.mjs.map +1 -0
- package/dist/plugins/organization/routes/crud-invites.d.mts +16 -0
- package/dist/plugins/organization/routes/crud-invites.mjs +555 -0
- package/dist/plugins/organization/routes/crud-invites.mjs.map +1 -0
- package/dist/plugins/organization/routes/crud-members.d.mts +13 -0
- package/dist/plugins/organization/routes/crud-members.mjs +473 -0
- package/dist/plugins/organization/routes/crud-members.mjs.map +1 -0
- package/dist/plugins/organization/routes/crud-org.d.mts +13 -0
- package/dist/plugins/organization/routes/crud-org.mjs +447 -0
- package/dist/plugins/organization/routes/crud-org.mjs.map +1 -0
- package/dist/plugins/organization/routes/crud-team.d.mts +15 -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 +733 -0
- package/dist/plugins/phone-number/client.d.mts +8 -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 +5 -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 +14 -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 +459 -0
- package/dist/plugins/phone-number/routes.mjs.map +1 -0
- package/dist/plugins/phone-number/schema.d.mts +5 -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/siwe/client.d.mts +5 -0
- package/dist/plugins/siwe/client.mjs +11 -0
- package/dist/plugins/siwe/client.mjs.map +1 -0
- package/dist/plugins/siwe/error-codes.mjs +13 -0
- package/dist/plugins/siwe/error-codes.mjs.map +1 -0
- package/dist/plugins/siwe/index.d.mts +26 -0
- package/dist/plugins/siwe/index.mjs +261 -0
- package/dist/plugins/siwe/index.mjs.map +1 -0
- package/dist/plugins/siwe/schema.d.mts +5 -0
- package/dist/plugins/siwe/schema.mjs +32 -0
- package/dist/plugins/siwe/schema.mjs.map +1 -0
- package/dist/plugins/siwe/types.d.mts +44 -0
- package/dist/plugins/two-factor/backup-codes/index.d.mts +91 -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 +17 -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 +5 -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 +19 -0
- package/dist/plugins/two-factor/index.mjs +207 -0
- package/dist/plugins/two-factor/index.mjs.map +1 -0
- package/dist/plugins/two-factor/otp/index.d.mts +96 -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 +5 -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 +81 -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 +65 -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 +76 -0
- package/dist/plugins/two-factor/verify-two-factor.mjs.map +1 -0
- package/dist/plugins/username/client.d.mts +7 -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 +5 -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 +74 -0
- package/dist/plugins/username/index.mjs +237 -0
- package/dist/plugins/username/index.mjs.map +1 -0
- package/dist/plugins/username/schema.d.mts +9 -0
- package/dist/plugins/username/schema.mjs +26 -0
- package/dist/plugins/username/schema.mjs.map +1 -0
- package/dist/social-providers/index.d.mts +1 -0
- package/dist/social-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/test-utils/headers.d.mts +9 -0
- package/dist/test-utils/headers.mjs +24 -0
- package/dist/test-utils/headers.mjs.map +1 -0
- package/dist/test-utils/index.d.mts +3 -0
- package/dist/test-utils/index.mjs +4 -0
- package/dist/test-utils/test-instance.d.mts +181 -0
- package/dist/test-utils/test-instance.mjs +210 -0
- package/dist/test-utils/test-instance.mjs.map +1 -0
- package/dist/types/adapter.d.mts +24 -0
- package/dist/types/api.d.mts +29 -0
- package/dist/types/auth.d.mts +30 -0
- package/dist/types/helper.d.mts +21 -0
- package/dist/types/index.d.mts +11 -0
- package/dist/types/index.mjs +1 -0
- package/dist/types/models.d.mts +17 -0
- package/dist/types/plugins.d.mts +16 -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/hashing.mjs +21 -0
- package/dist/utils/hashing.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 +3 -0
- package/dist/utils/index.mjs +5 -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 +6 -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.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 +601 -0
|
@@ -0,0 +1,676 @@
|
|
|
1
|
+
import { setSessionCookie } from "../../../cookies/index.mjs";
|
|
2
|
+
import { toZodSchema } from "../../../db/to-zod.mjs";
|
|
3
|
+
import "../../../db/index.mjs";
|
|
4
|
+
import { getSessionFromCtx } from "../../../api/routes/session.mjs";
|
|
5
|
+
import "../../../api/index.mjs";
|
|
6
|
+
import { ORGANIZATION_ERROR_CODES } from "../error-codes.mjs";
|
|
7
|
+
import { getOrgAdapter } from "../adapter.mjs";
|
|
8
|
+
import { orgMiddleware, orgSessionMiddleware } from "../call.mjs";
|
|
9
|
+
import { hasPermission } from "../has-permission.mjs";
|
|
10
|
+
import { teamSchema } from "../schema.mjs";
|
|
11
|
+
import { APIError } from "@better-auth/core/error";
|
|
12
|
+
import { createAuthEndpoint } from "@better-auth/core/api";
|
|
13
|
+
import * as z from "zod";
|
|
14
|
+
|
|
15
|
+
//#region src/plugins/organization/routes/crud-team.ts
|
|
16
|
+
const teamBaseSchema = z.object({
|
|
17
|
+
name: z.string().meta({ description: "The name of the team. Eg: \"my-team\"" }),
|
|
18
|
+
organizationId: z.string().meta({ description: "The organization ID which the team will be created in. Defaults to the active organization. Eg: \"organization-id\"" }).optional()
|
|
19
|
+
});
|
|
20
|
+
const createTeam = (options) => {
|
|
21
|
+
const additionalFieldsSchema = toZodSchema({
|
|
22
|
+
fields: options?.schema?.team?.additionalFields ?? {},
|
|
23
|
+
isClientSide: true
|
|
24
|
+
});
|
|
25
|
+
return createAuthEndpoint("/organization/create-team", {
|
|
26
|
+
method: "POST",
|
|
27
|
+
body: z.object({
|
|
28
|
+
...teamBaseSchema.shape,
|
|
29
|
+
...additionalFieldsSchema.shape
|
|
30
|
+
}),
|
|
31
|
+
use: [orgMiddleware],
|
|
32
|
+
metadata: {
|
|
33
|
+
$Infer: { body: {} },
|
|
34
|
+
openapi: {
|
|
35
|
+
description: "Create a new team within an organization",
|
|
36
|
+
responses: { "200": {
|
|
37
|
+
description: "Team created successfully",
|
|
38
|
+
content: { "application/json": { schema: {
|
|
39
|
+
type: "object",
|
|
40
|
+
properties: {
|
|
41
|
+
id: {
|
|
42
|
+
type: "string",
|
|
43
|
+
description: "Unique identifier of the created team"
|
|
44
|
+
},
|
|
45
|
+
name: {
|
|
46
|
+
type: "string",
|
|
47
|
+
description: "Name of the team"
|
|
48
|
+
},
|
|
49
|
+
organizationId: {
|
|
50
|
+
type: "string",
|
|
51
|
+
description: "ID of the organization the team belongs to"
|
|
52
|
+
},
|
|
53
|
+
createdAt: {
|
|
54
|
+
type: "string",
|
|
55
|
+
format: "date-time",
|
|
56
|
+
description: "Timestamp when the team was created"
|
|
57
|
+
},
|
|
58
|
+
updatedAt: {
|
|
59
|
+
type: "string",
|
|
60
|
+
format: "date-time",
|
|
61
|
+
description: "Timestamp when the team was last updated"
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
required: [
|
|
65
|
+
"id",
|
|
66
|
+
"name",
|
|
67
|
+
"organizationId",
|
|
68
|
+
"createdAt",
|
|
69
|
+
"updatedAt"
|
|
70
|
+
]
|
|
71
|
+
} } }
|
|
72
|
+
} }
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}, async (ctx) => {
|
|
76
|
+
const session = await getSessionFromCtx(ctx);
|
|
77
|
+
const organizationId = ctx.body.organizationId || session?.session.activeOrganizationId;
|
|
78
|
+
if (!session && (ctx.request || ctx.headers)) throw APIError.fromStatus("UNAUTHORIZED");
|
|
79
|
+
if (!organizationId) throw APIError.from("BAD_REQUEST", ORGANIZATION_ERROR_CODES.NO_ACTIVE_ORGANIZATION);
|
|
80
|
+
const adapter = getOrgAdapter(ctx.context, options);
|
|
81
|
+
if (session) {
|
|
82
|
+
const member = await adapter.findMemberByOrgId({
|
|
83
|
+
userId: session.user.id,
|
|
84
|
+
organizationId
|
|
85
|
+
});
|
|
86
|
+
if (!member) throw APIError.from("FORBIDDEN", ORGANIZATION_ERROR_CODES.YOU_ARE_NOT_ALLOWED_TO_INVITE_USERS_TO_THIS_ORGANIZATION);
|
|
87
|
+
if (!await hasPermission({
|
|
88
|
+
role: member.role,
|
|
89
|
+
options: ctx.context.orgOptions,
|
|
90
|
+
permissions: { team: ["create"] },
|
|
91
|
+
organizationId
|
|
92
|
+
}, ctx)) throw APIError.from("FORBIDDEN", ORGANIZATION_ERROR_CODES.YOU_ARE_NOT_ALLOWED_TO_CREATE_TEAMS_IN_THIS_ORGANIZATION);
|
|
93
|
+
}
|
|
94
|
+
const existingTeams = await adapter.listTeams(organizationId);
|
|
95
|
+
const maximum = typeof ctx.context.orgOptions.teams?.maximumTeams === "function" ? await ctx.context.orgOptions.teams?.maximumTeams({
|
|
96
|
+
organizationId,
|
|
97
|
+
session
|
|
98
|
+
}, ctx) : ctx.context.orgOptions.teams?.maximumTeams;
|
|
99
|
+
if (maximum ? existingTeams.length >= maximum : false) throw APIError.from("BAD_REQUEST", ORGANIZATION_ERROR_CODES.YOU_HAVE_REACHED_THE_MAXIMUM_NUMBER_OF_TEAMS);
|
|
100
|
+
const { name, organizationId: _, ...additionalFields } = ctx.body;
|
|
101
|
+
const organization = await adapter.findOrganizationById(organizationId);
|
|
102
|
+
if (!organization) throw APIError.from("BAD_REQUEST", ORGANIZATION_ERROR_CODES.ORGANIZATION_NOT_FOUND);
|
|
103
|
+
let teamData = {
|
|
104
|
+
name,
|
|
105
|
+
organizationId,
|
|
106
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
107
|
+
updatedAt: /* @__PURE__ */ new Date(),
|
|
108
|
+
...additionalFields
|
|
109
|
+
};
|
|
110
|
+
if (options?.organizationHooks?.beforeCreateTeam) {
|
|
111
|
+
const response = await options?.organizationHooks.beforeCreateTeam({
|
|
112
|
+
team: {
|
|
113
|
+
name,
|
|
114
|
+
organizationId,
|
|
115
|
+
...additionalFields
|
|
116
|
+
},
|
|
117
|
+
user: session?.user,
|
|
118
|
+
organization
|
|
119
|
+
});
|
|
120
|
+
if (response && typeof response === "object" && "data" in response) teamData = {
|
|
121
|
+
...teamData,
|
|
122
|
+
...response.data
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
const createdTeam = await adapter.createTeam(teamData);
|
|
126
|
+
if (options?.organizationHooks?.afterCreateTeam) await options?.organizationHooks.afterCreateTeam({
|
|
127
|
+
team: createdTeam,
|
|
128
|
+
user: session?.user,
|
|
129
|
+
organization
|
|
130
|
+
});
|
|
131
|
+
return ctx.json(createdTeam);
|
|
132
|
+
});
|
|
133
|
+
};
|
|
134
|
+
const removeTeamBodySchema = z.object({
|
|
135
|
+
teamId: z.string().meta({ description: `The team ID of the team to remove. Eg: "team-id"` }),
|
|
136
|
+
organizationId: z.string().meta({ description: `The organization ID which the team falls under. If not provided, it will default to the user's active organization. Eg: "organization-id"` }).optional()
|
|
137
|
+
});
|
|
138
|
+
const removeTeam = (options) => createAuthEndpoint("/organization/remove-team", {
|
|
139
|
+
method: "POST",
|
|
140
|
+
body: removeTeamBodySchema,
|
|
141
|
+
use: [orgMiddleware],
|
|
142
|
+
metadata: { openapi: {
|
|
143
|
+
description: "Remove a team from an organization",
|
|
144
|
+
responses: { "200": {
|
|
145
|
+
description: "Team removed successfully",
|
|
146
|
+
content: { "application/json": { schema: {
|
|
147
|
+
type: "object",
|
|
148
|
+
properties: { message: {
|
|
149
|
+
type: "string",
|
|
150
|
+
description: "Confirmation message indicating successful removal",
|
|
151
|
+
enum: ["Team removed successfully."]
|
|
152
|
+
} },
|
|
153
|
+
required: ["message"]
|
|
154
|
+
} } }
|
|
155
|
+
} }
|
|
156
|
+
} }
|
|
157
|
+
}, async (ctx) => {
|
|
158
|
+
const session = await getSessionFromCtx(ctx);
|
|
159
|
+
const organizationId = ctx.body.organizationId || session?.session.activeOrganizationId;
|
|
160
|
+
if (!organizationId) throw APIError.from("BAD_REQUEST", ORGANIZATION_ERROR_CODES.NO_ACTIVE_ORGANIZATION);
|
|
161
|
+
if (!session && (ctx.request || ctx.headers)) throw APIError.fromStatus("UNAUTHORIZED");
|
|
162
|
+
const adapter = getOrgAdapter(ctx.context, options);
|
|
163
|
+
if (session) {
|
|
164
|
+
const member = await adapter.findMemberByOrgId({
|
|
165
|
+
userId: session.user.id,
|
|
166
|
+
organizationId
|
|
167
|
+
});
|
|
168
|
+
if (!member || session.session?.activeTeamId === ctx.body.teamId) throw APIError.from("FORBIDDEN", ORGANIZATION_ERROR_CODES.YOU_ARE_NOT_ALLOWED_TO_DELETE_THIS_TEAM);
|
|
169
|
+
if (!await hasPermission({
|
|
170
|
+
role: member.role,
|
|
171
|
+
options: ctx.context.orgOptions,
|
|
172
|
+
permissions: { team: ["delete"] },
|
|
173
|
+
organizationId
|
|
174
|
+
}, ctx)) throw APIError.from("FORBIDDEN", ORGANIZATION_ERROR_CODES.YOU_ARE_NOT_ALLOWED_TO_DELETE_TEAMS_IN_THIS_ORGANIZATION);
|
|
175
|
+
}
|
|
176
|
+
const team = await adapter.findTeamById({
|
|
177
|
+
teamId: ctx.body.teamId,
|
|
178
|
+
organizationId
|
|
179
|
+
});
|
|
180
|
+
if (!team || team.organizationId !== organizationId) throw APIError.from("BAD_REQUEST", ORGANIZATION_ERROR_CODES.TEAM_NOT_FOUND);
|
|
181
|
+
if (!ctx.context.orgOptions.teams?.allowRemovingAllTeams) {
|
|
182
|
+
if ((await adapter.listTeams(organizationId)).length <= 1) throw APIError.from("BAD_REQUEST", ORGANIZATION_ERROR_CODES.UNABLE_TO_REMOVE_LAST_TEAM);
|
|
183
|
+
}
|
|
184
|
+
const organization = await adapter.findOrganizationById(organizationId);
|
|
185
|
+
if (!organization) throw APIError.from("BAD_REQUEST", ORGANIZATION_ERROR_CODES.ORGANIZATION_NOT_FOUND);
|
|
186
|
+
if (options?.organizationHooks?.beforeDeleteTeam) await options?.organizationHooks.beforeDeleteTeam({
|
|
187
|
+
team,
|
|
188
|
+
user: session?.user,
|
|
189
|
+
organization
|
|
190
|
+
});
|
|
191
|
+
await adapter.deleteTeam(team.id);
|
|
192
|
+
if (options?.organizationHooks?.afterDeleteTeam) await options?.organizationHooks.afterDeleteTeam({
|
|
193
|
+
team,
|
|
194
|
+
user: session?.user,
|
|
195
|
+
organization
|
|
196
|
+
});
|
|
197
|
+
return ctx.json({ message: "Team removed successfully." });
|
|
198
|
+
});
|
|
199
|
+
const updateTeam = (options) => {
|
|
200
|
+
const additionalFieldsSchema = toZodSchema({
|
|
201
|
+
fields: options?.schema?.team?.additionalFields ?? {},
|
|
202
|
+
isClientSide: true
|
|
203
|
+
});
|
|
204
|
+
return createAuthEndpoint("/organization/update-team", {
|
|
205
|
+
method: "POST",
|
|
206
|
+
body: z.object({
|
|
207
|
+
teamId: z.string().meta({ description: `The ID of the team to be updated. Eg: "team-id"` }),
|
|
208
|
+
data: z.object({
|
|
209
|
+
...teamSchema.shape,
|
|
210
|
+
...additionalFieldsSchema.shape
|
|
211
|
+
}).partial()
|
|
212
|
+
}),
|
|
213
|
+
requireHeaders: true,
|
|
214
|
+
use: [orgMiddleware, orgSessionMiddleware],
|
|
215
|
+
metadata: {
|
|
216
|
+
$Infer: { body: {} },
|
|
217
|
+
openapi: {
|
|
218
|
+
description: "Update an existing team in an organization",
|
|
219
|
+
responses: { "200": {
|
|
220
|
+
description: "Team updated successfully",
|
|
221
|
+
content: { "application/json": { schema: {
|
|
222
|
+
type: "object",
|
|
223
|
+
properties: {
|
|
224
|
+
id: {
|
|
225
|
+
type: "string",
|
|
226
|
+
description: "Unique identifier of the updated team"
|
|
227
|
+
},
|
|
228
|
+
name: {
|
|
229
|
+
type: "string",
|
|
230
|
+
description: "Updated name of the team"
|
|
231
|
+
},
|
|
232
|
+
organizationId: {
|
|
233
|
+
type: "string",
|
|
234
|
+
description: "ID of the organization the team belongs to"
|
|
235
|
+
},
|
|
236
|
+
createdAt: {
|
|
237
|
+
type: "string",
|
|
238
|
+
format: "date-time",
|
|
239
|
+
description: "Timestamp when the team was created"
|
|
240
|
+
},
|
|
241
|
+
updatedAt: {
|
|
242
|
+
type: "string",
|
|
243
|
+
format: "date-time",
|
|
244
|
+
description: "Timestamp when the team was last updated"
|
|
245
|
+
}
|
|
246
|
+
},
|
|
247
|
+
required: [
|
|
248
|
+
"id",
|
|
249
|
+
"name",
|
|
250
|
+
"organizationId",
|
|
251
|
+
"createdAt",
|
|
252
|
+
"updatedAt"
|
|
253
|
+
]
|
|
254
|
+
} } }
|
|
255
|
+
} }
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}, async (ctx) => {
|
|
259
|
+
const session = ctx.context.session;
|
|
260
|
+
const organizationId = ctx.body.data.organizationId || session.session.activeOrganizationId;
|
|
261
|
+
if (!organizationId) throw APIError.from("BAD_REQUEST", ORGANIZATION_ERROR_CODES.NO_ACTIVE_ORGANIZATION);
|
|
262
|
+
const adapter = getOrgAdapter(ctx.context, options);
|
|
263
|
+
const member = await adapter.findMemberByOrgId({
|
|
264
|
+
userId: session.user.id,
|
|
265
|
+
organizationId
|
|
266
|
+
});
|
|
267
|
+
if (!member) throw APIError.from("FORBIDDEN", ORGANIZATION_ERROR_CODES.YOU_ARE_NOT_ALLOWED_TO_UPDATE_THIS_TEAM);
|
|
268
|
+
if (!await hasPermission({
|
|
269
|
+
role: member.role,
|
|
270
|
+
options: ctx.context.orgOptions,
|
|
271
|
+
permissions: { team: ["update"] },
|
|
272
|
+
organizationId
|
|
273
|
+
}, ctx)) throw APIError.from("FORBIDDEN", ORGANIZATION_ERROR_CODES.YOU_ARE_NOT_ALLOWED_TO_UPDATE_THIS_TEAM);
|
|
274
|
+
const team = await adapter.findTeamById({
|
|
275
|
+
teamId: ctx.body.teamId,
|
|
276
|
+
organizationId
|
|
277
|
+
});
|
|
278
|
+
if (!team || team.organizationId !== organizationId) throw APIError.from("BAD_REQUEST", ORGANIZATION_ERROR_CODES.TEAM_NOT_FOUND);
|
|
279
|
+
const { name, organizationId: __, ...additionalFields } = ctx.body.data;
|
|
280
|
+
const organization = await adapter.findOrganizationById(organizationId);
|
|
281
|
+
if (!organization) throw APIError.from("BAD_REQUEST", ORGANIZATION_ERROR_CODES.ORGANIZATION_NOT_FOUND);
|
|
282
|
+
const updates = {
|
|
283
|
+
name,
|
|
284
|
+
...additionalFields
|
|
285
|
+
};
|
|
286
|
+
if (options?.organizationHooks?.beforeUpdateTeam) {
|
|
287
|
+
const response = await options?.organizationHooks.beforeUpdateTeam({
|
|
288
|
+
team,
|
|
289
|
+
updates,
|
|
290
|
+
user: session.user,
|
|
291
|
+
organization
|
|
292
|
+
});
|
|
293
|
+
if (response && typeof response === "object" && "data" in response) {
|
|
294
|
+
const modifiedUpdates = response.data;
|
|
295
|
+
const updatedTeam = await adapter.updateTeam(team.id, modifiedUpdates);
|
|
296
|
+
if (options?.organizationHooks?.afterUpdateTeam) await options?.organizationHooks.afterUpdateTeam({
|
|
297
|
+
team: updatedTeam,
|
|
298
|
+
user: session.user,
|
|
299
|
+
organization
|
|
300
|
+
});
|
|
301
|
+
return ctx.json(updatedTeam);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
const updatedTeam = await adapter.updateTeam(team.id, updates);
|
|
305
|
+
if (options?.organizationHooks?.afterUpdateTeam) await options?.organizationHooks.afterUpdateTeam({
|
|
306
|
+
team: updatedTeam,
|
|
307
|
+
user: session.user,
|
|
308
|
+
organization
|
|
309
|
+
});
|
|
310
|
+
return ctx.json(updatedTeam);
|
|
311
|
+
});
|
|
312
|
+
};
|
|
313
|
+
const listOrganizationTeamsQuerySchema = z.optional(z.object({ organizationId: z.string().meta({ description: `The organization ID which the teams are under to list. Defaults to the users active organization. Eg: "organization-id"` }).optional() }));
|
|
314
|
+
const listOrganizationTeams = (options) => createAuthEndpoint("/organization/list-teams", {
|
|
315
|
+
method: "GET",
|
|
316
|
+
query: listOrganizationTeamsQuerySchema,
|
|
317
|
+
metadata: { openapi: {
|
|
318
|
+
description: "List all teams in an organization",
|
|
319
|
+
responses: { "200": {
|
|
320
|
+
description: "Teams retrieved successfully",
|
|
321
|
+
content: { "application/json": { schema: {
|
|
322
|
+
type: "array",
|
|
323
|
+
items: {
|
|
324
|
+
type: "object",
|
|
325
|
+
properties: {
|
|
326
|
+
id: {
|
|
327
|
+
type: "string",
|
|
328
|
+
description: "Unique identifier of the team"
|
|
329
|
+
},
|
|
330
|
+
name: {
|
|
331
|
+
type: "string",
|
|
332
|
+
description: "Name of the team"
|
|
333
|
+
},
|
|
334
|
+
organizationId: {
|
|
335
|
+
type: "string",
|
|
336
|
+
description: "ID of the organization the team belongs to"
|
|
337
|
+
},
|
|
338
|
+
createdAt: {
|
|
339
|
+
type: "string",
|
|
340
|
+
format: "date-time",
|
|
341
|
+
description: "Timestamp when the team was created"
|
|
342
|
+
},
|
|
343
|
+
updatedAt: {
|
|
344
|
+
type: "string",
|
|
345
|
+
format: "date-time",
|
|
346
|
+
description: "Timestamp when the team was last updated"
|
|
347
|
+
}
|
|
348
|
+
},
|
|
349
|
+
required: [
|
|
350
|
+
"id",
|
|
351
|
+
"name",
|
|
352
|
+
"organizationId",
|
|
353
|
+
"createdAt",
|
|
354
|
+
"updatedAt"
|
|
355
|
+
]
|
|
356
|
+
},
|
|
357
|
+
description: "Array of team objects within the organization"
|
|
358
|
+
} } }
|
|
359
|
+
} }
|
|
360
|
+
} },
|
|
361
|
+
requireHeaders: true,
|
|
362
|
+
use: [orgMiddleware, orgSessionMiddleware]
|
|
363
|
+
}, async (ctx) => {
|
|
364
|
+
const session = ctx.context.session;
|
|
365
|
+
const organizationId = ctx.query?.organizationId || session?.session.activeOrganizationId;
|
|
366
|
+
if (!organizationId) throw APIError.from("BAD_REQUEST", ORGANIZATION_ERROR_CODES.NO_ACTIVE_ORGANIZATION);
|
|
367
|
+
const adapter = getOrgAdapter(ctx.context, options);
|
|
368
|
+
if (!await adapter.findMemberByOrgId({
|
|
369
|
+
userId: session.user.id,
|
|
370
|
+
organizationId: organizationId || ""
|
|
371
|
+
})) throw APIError.from("FORBIDDEN", ORGANIZATION_ERROR_CODES.YOU_ARE_NOT_ALLOWED_TO_ACCESS_THIS_ORGANIZATION);
|
|
372
|
+
const teams = await adapter.listTeams(organizationId);
|
|
373
|
+
return ctx.json(teams);
|
|
374
|
+
});
|
|
375
|
+
const setActiveTeamBodySchema = z.object({ teamId: z.string().meta({ description: "The team id to set as active. It can be null to unset the active team" }).nullable().optional() });
|
|
376
|
+
const setActiveTeam = (options) => createAuthEndpoint("/organization/set-active-team", {
|
|
377
|
+
method: "POST",
|
|
378
|
+
body: setActiveTeamBodySchema,
|
|
379
|
+
requireHeaders: true,
|
|
380
|
+
use: [orgSessionMiddleware, orgMiddleware],
|
|
381
|
+
metadata: { openapi: {
|
|
382
|
+
description: "Set the active team",
|
|
383
|
+
responses: { "200": {
|
|
384
|
+
description: "Success",
|
|
385
|
+
content: { "application/json": { schema: {
|
|
386
|
+
type: "object",
|
|
387
|
+
description: "The team",
|
|
388
|
+
$ref: "#/components/schemas/Team"
|
|
389
|
+
} } }
|
|
390
|
+
} }
|
|
391
|
+
} }
|
|
392
|
+
}, async (ctx) => {
|
|
393
|
+
const adapter = getOrgAdapter(ctx.context, ctx.context.orgOptions);
|
|
394
|
+
const session = ctx.context.session;
|
|
395
|
+
if (ctx.body.teamId === null) {
|
|
396
|
+
if (!session.session.activeTeamId) return ctx.json(null);
|
|
397
|
+
await setSessionCookie(ctx, {
|
|
398
|
+
session: await adapter.setActiveTeam(session.session.token, null, ctx),
|
|
399
|
+
user: session.user
|
|
400
|
+
});
|
|
401
|
+
return ctx.json(null);
|
|
402
|
+
}
|
|
403
|
+
let teamId;
|
|
404
|
+
if (!ctx.body.teamId) {
|
|
405
|
+
const sessionTeamId = session.session.activeTeamId;
|
|
406
|
+
if (!sessionTeamId) return ctx.json(null);
|
|
407
|
+
else teamId = sessionTeamId;
|
|
408
|
+
} else teamId = ctx.body.teamId;
|
|
409
|
+
const team = await adapter.findTeamById({ teamId });
|
|
410
|
+
if (!team) throw APIError.from("BAD_REQUEST", ORGANIZATION_ERROR_CODES.TEAM_NOT_FOUND);
|
|
411
|
+
if (!await adapter.findTeamMember({
|
|
412
|
+
teamId,
|
|
413
|
+
userId: session.user.id
|
|
414
|
+
})) throw APIError.from("FORBIDDEN", ORGANIZATION_ERROR_CODES.USER_IS_NOT_A_MEMBER_OF_THE_TEAM);
|
|
415
|
+
await setSessionCookie(ctx, {
|
|
416
|
+
session: await adapter.setActiveTeam(session.session.token, team.id, ctx),
|
|
417
|
+
user: session.user
|
|
418
|
+
});
|
|
419
|
+
return ctx.json(team);
|
|
420
|
+
});
|
|
421
|
+
const listUserTeams = (options) => createAuthEndpoint("/organization/list-user-teams", {
|
|
422
|
+
method: "GET",
|
|
423
|
+
metadata: { openapi: {
|
|
424
|
+
description: "List all teams that the current user is a part of.",
|
|
425
|
+
responses: { "200": {
|
|
426
|
+
description: "Teams retrieved successfully",
|
|
427
|
+
content: { "application/json": { schema: {
|
|
428
|
+
type: "array",
|
|
429
|
+
items: {
|
|
430
|
+
type: "object",
|
|
431
|
+
description: "The team",
|
|
432
|
+
$ref: "#/components/schemas/Team"
|
|
433
|
+
},
|
|
434
|
+
description: "Array of team objects within the organization"
|
|
435
|
+
} } }
|
|
436
|
+
} }
|
|
437
|
+
} },
|
|
438
|
+
requireHeaders: true,
|
|
439
|
+
use: [orgMiddleware, orgSessionMiddleware]
|
|
440
|
+
}, async (ctx) => {
|
|
441
|
+
const session = ctx.context.session;
|
|
442
|
+
const teams = await getOrgAdapter(ctx.context, ctx.context.orgOptions).listTeamsByUser({ userId: session.user.id });
|
|
443
|
+
return ctx.json(teams);
|
|
444
|
+
});
|
|
445
|
+
const listTeamMembersQuerySchema = z.optional(z.object({ teamId: z.string().optional().meta({ description: "The team whose members we should return. If this is not provided the members of the current active team get returned." }) }));
|
|
446
|
+
const listTeamMembers = (options) => createAuthEndpoint("/organization/list-team-members", {
|
|
447
|
+
method: "GET",
|
|
448
|
+
query: listTeamMembersQuerySchema,
|
|
449
|
+
metadata: { openapi: {
|
|
450
|
+
description: "List the members of the given team.",
|
|
451
|
+
responses: { "200": {
|
|
452
|
+
description: "Teams retrieved successfully",
|
|
453
|
+
content: { "application/json": { schema: {
|
|
454
|
+
type: "array",
|
|
455
|
+
items: {
|
|
456
|
+
type: "object",
|
|
457
|
+
description: "The team member",
|
|
458
|
+
properties: {
|
|
459
|
+
id: {
|
|
460
|
+
type: "string",
|
|
461
|
+
description: "Unique identifier of the team member"
|
|
462
|
+
},
|
|
463
|
+
userId: {
|
|
464
|
+
type: "string",
|
|
465
|
+
description: "The user ID of the team member"
|
|
466
|
+
},
|
|
467
|
+
teamId: {
|
|
468
|
+
type: "string",
|
|
469
|
+
description: "The team ID of the team the team member is in"
|
|
470
|
+
},
|
|
471
|
+
createdAt: {
|
|
472
|
+
type: "string",
|
|
473
|
+
format: "date-time",
|
|
474
|
+
description: "Timestamp when the team member was created"
|
|
475
|
+
}
|
|
476
|
+
},
|
|
477
|
+
required: [
|
|
478
|
+
"id",
|
|
479
|
+
"userId",
|
|
480
|
+
"teamId",
|
|
481
|
+
"createdAt"
|
|
482
|
+
]
|
|
483
|
+
},
|
|
484
|
+
description: "Array of team member objects within the team"
|
|
485
|
+
} } }
|
|
486
|
+
} }
|
|
487
|
+
} },
|
|
488
|
+
requireHeaders: true,
|
|
489
|
+
use: [orgMiddleware, orgSessionMiddleware]
|
|
490
|
+
}, async (ctx) => {
|
|
491
|
+
const session = ctx.context.session;
|
|
492
|
+
const adapter = getOrgAdapter(ctx.context, ctx.context.orgOptions);
|
|
493
|
+
const teamId = ctx.query?.teamId || session?.session.activeTeamId;
|
|
494
|
+
if (!teamId) throw APIError.from("BAD_REQUEST", ORGANIZATION_ERROR_CODES.YOU_DO_NOT_HAVE_AN_ACTIVE_TEAM);
|
|
495
|
+
if (!await adapter.findTeamMember({
|
|
496
|
+
userId: session.user.id,
|
|
497
|
+
teamId
|
|
498
|
+
})) throw APIError.from("BAD_REQUEST", ORGANIZATION_ERROR_CODES.USER_IS_NOT_A_MEMBER_OF_THE_TEAM);
|
|
499
|
+
const members = await adapter.listTeamMembers({ teamId });
|
|
500
|
+
return ctx.json(members);
|
|
501
|
+
});
|
|
502
|
+
const addTeamMemberBodySchema = z.object({
|
|
503
|
+
teamId: z.string().meta({ description: "The team the user should be a member of." }),
|
|
504
|
+
userId: z.coerce.string().meta({ description: "The user Id which represents the user to be added as a member." })
|
|
505
|
+
});
|
|
506
|
+
const addTeamMember = (options) => createAuthEndpoint("/organization/add-team-member", {
|
|
507
|
+
method: "POST",
|
|
508
|
+
body: addTeamMemberBodySchema,
|
|
509
|
+
metadata: { openapi: {
|
|
510
|
+
description: "The newly created member",
|
|
511
|
+
responses: { "200": {
|
|
512
|
+
description: "Team member created successfully",
|
|
513
|
+
content: { "application/json": { schema: {
|
|
514
|
+
type: "object",
|
|
515
|
+
description: "The team member",
|
|
516
|
+
properties: {
|
|
517
|
+
id: {
|
|
518
|
+
type: "string",
|
|
519
|
+
description: "Unique identifier of the team member"
|
|
520
|
+
},
|
|
521
|
+
userId: {
|
|
522
|
+
type: "string",
|
|
523
|
+
description: "The user ID of the team member"
|
|
524
|
+
},
|
|
525
|
+
teamId: {
|
|
526
|
+
type: "string",
|
|
527
|
+
description: "The team ID of the team the team member is in"
|
|
528
|
+
},
|
|
529
|
+
createdAt: {
|
|
530
|
+
type: "string",
|
|
531
|
+
format: "date-time",
|
|
532
|
+
description: "Timestamp when the team member was created"
|
|
533
|
+
}
|
|
534
|
+
},
|
|
535
|
+
required: [
|
|
536
|
+
"id",
|
|
537
|
+
"userId",
|
|
538
|
+
"teamId",
|
|
539
|
+
"createdAt"
|
|
540
|
+
]
|
|
541
|
+
} } }
|
|
542
|
+
} }
|
|
543
|
+
} },
|
|
544
|
+
requireHeaders: true,
|
|
545
|
+
use: [orgMiddleware, orgSessionMiddleware]
|
|
546
|
+
}, async (ctx) => {
|
|
547
|
+
const session = ctx.context.session;
|
|
548
|
+
const adapter = getOrgAdapter(ctx.context, ctx.context.orgOptions);
|
|
549
|
+
if (!session.session.activeOrganizationId) throw APIError.from("BAD_REQUEST", ORGANIZATION_ERROR_CODES.NO_ACTIVE_ORGANIZATION);
|
|
550
|
+
const currentMember = await adapter.findMemberByOrgId({
|
|
551
|
+
userId: session.user.id,
|
|
552
|
+
organizationId: session.session.activeOrganizationId
|
|
553
|
+
});
|
|
554
|
+
if (!currentMember) throw APIError.from("BAD_REQUEST", ORGANIZATION_ERROR_CODES.USER_IS_NOT_A_MEMBER_OF_THE_ORGANIZATION);
|
|
555
|
+
if (!await hasPermission({
|
|
556
|
+
role: currentMember.role,
|
|
557
|
+
options: ctx.context.orgOptions,
|
|
558
|
+
permissions: { member: ["update"] },
|
|
559
|
+
organizationId: session.session.activeOrganizationId
|
|
560
|
+
}, ctx)) throw APIError.from("FORBIDDEN", ORGANIZATION_ERROR_CODES.YOU_ARE_NOT_ALLOWED_TO_CREATE_A_NEW_TEAM_MEMBER);
|
|
561
|
+
if (!await adapter.findMemberByOrgId({
|
|
562
|
+
userId: ctx.body.userId,
|
|
563
|
+
organizationId: session.session.activeOrganizationId
|
|
564
|
+
})) throw APIError.from("BAD_REQUEST", ORGANIZATION_ERROR_CODES.USER_IS_NOT_A_MEMBER_OF_THE_ORGANIZATION);
|
|
565
|
+
const team = await adapter.findTeamById({
|
|
566
|
+
teamId: ctx.body.teamId,
|
|
567
|
+
organizationId: session.session.activeOrganizationId
|
|
568
|
+
});
|
|
569
|
+
if (!team) throw APIError.from("BAD_REQUEST", ORGANIZATION_ERROR_CODES.TEAM_NOT_FOUND);
|
|
570
|
+
const organization = await adapter.findOrganizationById(session.session.activeOrganizationId);
|
|
571
|
+
if (!organization) throw APIError.from("BAD_REQUEST", ORGANIZATION_ERROR_CODES.ORGANIZATION_NOT_FOUND);
|
|
572
|
+
const userBeingAdded = await ctx.context.internalAdapter.findUserById(ctx.body.userId);
|
|
573
|
+
if (!userBeingAdded) throw APIError.fromStatus("BAD_REQUEST", { message: "User not found" });
|
|
574
|
+
if (options?.organizationHooks?.beforeAddTeamMember) {
|
|
575
|
+
const response = await options?.organizationHooks.beforeAddTeamMember({
|
|
576
|
+
teamMember: {
|
|
577
|
+
teamId: ctx.body.teamId,
|
|
578
|
+
userId: ctx.body.userId
|
|
579
|
+
},
|
|
580
|
+
team,
|
|
581
|
+
user: userBeingAdded,
|
|
582
|
+
organization
|
|
583
|
+
});
|
|
584
|
+
if (response && typeof response === "object" && "data" in response) {}
|
|
585
|
+
}
|
|
586
|
+
const teamMember = await adapter.findOrCreateTeamMember({
|
|
587
|
+
teamId: ctx.body.teamId,
|
|
588
|
+
userId: ctx.body.userId
|
|
589
|
+
});
|
|
590
|
+
if (options?.organizationHooks?.afterAddTeamMember) await options?.organizationHooks.afterAddTeamMember({
|
|
591
|
+
teamMember,
|
|
592
|
+
team,
|
|
593
|
+
user: userBeingAdded,
|
|
594
|
+
organization
|
|
595
|
+
});
|
|
596
|
+
return ctx.json(teamMember);
|
|
597
|
+
});
|
|
598
|
+
const removeTeamMemberBodySchema = z.object({
|
|
599
|
+
teamId: z.string().meta({ description: "The team the user should be removed from." }),
|
|
600
|
+
userId: z.coerce.string().meta({ description: "The user which should be removed from the team." })
|
|
601
|
+
});
|
|
602
|
+
const removeTeamMember = (options) => createAuthEndpoint("/organization/remove-team-member", {
|
|
603
|
+
method: "POST",
|
|
604
|
+
body: removeTeamMemberBodySchema,
|
|
605
|
+
metadata: { openapi: {
|
|
606
|
+
description: "Remove a member from a team",
|
|
607
|
+
responses: { "200": {
|
|
608
|
+
description: "Team member removed successfully",
|
|
609
|
+
content: { "application/json": { schema: {
|
|
610
|
+
type: "object",
|
|
611
|
+
properties: { message: {
|
|
612
|
+
type: "string",
|
|
613
|
+
description: "Confirmation message indicating successful removal",
|
|
614
|
+
enum: ["Team member removed successfully."]
|
|
615
|
+
} },
|
|
616
|
+
required: ["message"]
|
|
617
|
+
} } }
|
|
618
|
+
} }
|
|
619
|
+
} },
|
|
620
|
+
requireHeaders: true,
|
|
621
|
+
use: [orgMiddleware, orgSessionMiddleware]
|
|
622
|
+
}, async (ctx) => {
|
|
623
|
+
const session = ctx.context.session;
|
|
624
|
+
const adapter = getOrgAdapter(ctx.context, ctx.context.orgOptions);
|
|
625
|
+
if (!session.session.activeOrganizationId) throw APIError.from("BAD_REQUEST", ORGANIZATION_ERROR_CODES.NO_ACTIVE_ORGANIZATION);
|
|
626
|
+
const currentMember = await adapter.findMemberByOrgId({
|
|
627
|
+
userId: session.user.id,
|
|
628
|
+
organizationId: session.session.activeOrganizationId
|
|
629
|
+
});
|
|
630
|
+
if (!currentMember) throw APIError.from("BAD_REQUEST", ORGANIZATION_ERROR_CODES.USER_IS_NOT_A_MEMBER_OF_THE_ORGANIZATION);
|
|
631
|
+
if (!await hasPermission({
|
|
632
|
+
role: currentMember.role,
|
|
633
|
+
options: ctx.context.orgOptions,
|
|
634
|
+
permissions: { member: ["delete"] },
|
|
635
|
+
organizationId: session.session.activeOrganizationId
|
|
636
|
+
}, ctx)) throw APIError.from("FORBIDDEN", ORGANIZATION_ERROR_CODES.YOU_ARE_NOT_ALLOWED_TO_REMOVE_A_TEAM_MEMBER);
|
|
637
|
+
if (!await adapter.findMemberByOrgId({
|
|
638
|
+
userId: ctx.body.userId,
|
|
639
|
+
organizationId: session.session.activeOrganizationId
|
|
640
|
+
})) throw APIError.from("BAD_REQUEST", ORGANIZATION_ERROR_CODES.USER_IS_NOT_A_MEMBER_OF_THE_ORGANIZATION);
|
|
641
|
+
const team = await adapter.findTeamById({
|
|
642
|
+
teamId: ctx.body.teamId,
|
|
643
|
+
organizationId: session.session.activeOrganizationId
|
|
644
|
+
});
|
|
645
|
+
if (!team) throw APIError.from("BAD_REQUEST", ORGANIZATION_ERROR_CODES.TEAM_NOT_FOUND);
|
|
646
|
+
const organization = await adapter.findOrganizationById(session.session.activeOrganizationId);
|
|
647
|
+
if (!organization) throw APIError.from("BAD_REQUEST", ORGANIZATION_ERROR_CODES.ORGANIZATION_NOT_FOUND);
|
|
648
|
+
const userBeingRemoved = await ctx.context.internalAdapter.findUserById(ctx.body.userId);
|
|
649
|
+
if (!userBeingRemoved) throw APIError.fromStatus("BAD_REQUEST", { message: "User not found" });
|
|
650
|
+
const teamMember = await adapter.findTeamMember({
|
|
651
|
+
teamId: ctx.body.teamId,
|
|
652
|
+
userId: ctx.body.userId
|
|
653
|
+
});
|
|
654
|
+
if (!teamMember) throw APIError.from("BAD_REQUEST", ORGANIZATION_ERROR_CODES.USER_IS_NOT_A_MEMBER_OF_THE_TEAM);
|
|
655
|
+
if (options?.organizationHooks?.beforeRemoveTeamMember) await options?.organizationHooks.beforeRemoveTeamMember({
|
|
656
|
+
teamMember,
|
|
657
|
+
team,
|
|
658
|
+
user: userBeingRemoved,
|
|
659
|
+
organization
|
|
660
|
+
});
|
|
661
|
+
await adapter.removeTeamMember({
|
|
662
|
+
teamId: ctx.body.teamId,
|
|
663
|
+
userId: ctx.body.userId
|
|
664
|
+
});
|
|
665
|
+
if (options?.organizationHooks?.afterRemoveTeamMember) await options?.organizationHooks.afterRemoveTeamMember({
|
|
666
|
+
teamMember,
|
|
667
|
+
team,
|
|
668
|
+
user: userBeingRemoved,
|
|
669
|
+
organization
|
|
670
|
+
});
|
|
671
|
+
return ctx.json({ message: "Team member removed successfully." });
|
|
672
|
+
});
|
|
673
|
+
|
|
674
|
+
//#endregion
|
|
675
|
+
export { addTeamMember, createTeam, listOrganizationTeams, listTeamMembers, listUserTeams, removeTeam, removeTeamMember, setActiveTeam, updateTeam };
|
|
676
|
+
//# sourceMappingURL=crud-team.mjs.map
|