better-auth 1.5.5 → 1.5.6

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.
Files changed (90) hide show
  1. package/dist/api/index.d.mts +6 -10
  2. package/dist/api/index.mjs +19 -4
  3. package/dist/api/index.mjs.map +1 -1
  4. package/dist/api/middlewares/origin-check.mjs +17 -8
  5. package/dist/api/middlewares/origin-check.mjs.map +1 -1
  6. package/dist/api/routes/account.d.mts +1 -1
  7. package/dist/api/routes/email-verification.d.mts +0 -1
  8. package/dist/api/routes/session.d.mts +0 -1
  9. package/dist/api/routes/sign-in.d.mts +2 -2
  10. package/dist/api/routes/sign-up.d.mts +0 -1
  11. package/dist/api/routes/update-session.d.mts +0 -1
  12. package/dist/api/routes/update-user.d.mts +0 -1
  13. package/dist/api/to-auth-endpoints.mjs +49 -12
  14. package/dist/api/to-auth-endpoints.mjs.map +1 -1
  15. package/dist/auth/full.d.mts +0 -1
  16. package/dist/auth/minimal.d.mts +0 -1
  17. package/dist/client/index.d.mts +0 -2
  18. package/dist/client/path-to-object.d.mts +3 -1
  19. package/dist/client/session-refresh.d.mts +0 -1
  20. package/dist/client/session-refresh.mjs +12 -4
  21. package/dist/client/session-refresh.mjs.map +1 -1
  22. package/dist/client/types.d.mts +0 -1
  23. package/dist/context/create-context.mjs +4 -1
  24. package/dist/context/create-context.mjs.map +1 -1
  25. package/dist/context/helpers.mjs +10 -4
  26. package/dist/context/helpers.mjs.map +1 -1
  27. package/dist/cookies/index.d.mts +0 -1
  28. package/dist/cookies/session-store.d.mts +0 -2
  29. package/dist/db/index.d.mts +2 -2
  30. package/dist/db/internal-adapter.d.mts +2 -1
  31. package/dist/db/internal-adapter.mjs +1 -1
  32. package/dist/db/internal-adapter.mjs.map +1 -1
  33. package/dist/db/schema.d.mts +0 -1
  34. package/dist/db/with-hooks.d.mts +6 -2
  35. package/dist/db/with-hooks.mjs +72 -31
  36. package/dist/db/with-hooks.mjs.map +1 -1
  37. package/dist/index.d.mts +0 -2
  38. package/dist/integrations/node.d.mts +0 -1
  39. package/dist/oauth2/link-account.d.mts +0 -1
  40. package/dist/plugins/admin/access/statement.d.mts +0 -2
  41. package/dist/plugins/admin/admin.d.mts +0 -1
  42. package/dist/plugins/admin/client.d.mts +0 -2
  43. package/dist/plugins/admin/types.d.mts +0 -2
  44. package/dist/plugins/anonymous/types.d.mts +0 -1
  45. package/dist/plugins/email-otp/index.mjs +2 -1
  46. package/dist/plugins/email-otp/index.mjs.map +1 -1
  47. package/dist/plugins/email-otp/otp-token.mjs +31 -2
  48. package/dist/plugins/email-otp/otp-token.mjs.map +1 -1
  49. package/dist/plugins/email-otp/routes.mjs +60 -59
  50. package/dist/plugins/email-otp/routes.mjs.map +1 -1
  51. package/dist/plugins/email-otp/types.d.mts +12 -0
  52. package/dist/plugins/email-otp/utils.mjs +4 -1
  53. package/dist/plugins/email-otp/utils.mjs.map +1 -1
  54. package/dist/plugins/generic-oauth/client.d.mts +0 -1
  55. package/dist/plugins/generic-oauth/index.d.mts +0 -1
  56. package/dist/plugins/index.d.mts +0 -3
  57. package/dist/plugins/jwt/types.d.mts +0 -1
  58. package/dist/plugins/magic-link/index.d.mts +2 -0
  59. package/dist/plugins/magic-link/index.mjs +5 -3
  60. package/dist/plugins/magic-link/index.mjs.map +1 -1
  61. package/dist/plugins/mcp/index.d.mts +0 -1
  62. package/dist/plugins/oidc-provider/index.d.mts +0 -1
  63. package/dist/plugins/oidc-provider/types.d.mts +0 -1
  64. package/dist/plugins/one-time-token/index.d.mts +0 -1
  65. package/dist/plugins/organization/access/statement.d.mts +0 -2
  66. package/dist/plugins/organization/adapter.d.mts +0 -2
  67. package/dist/plugins/organization/adapter.mjs +2 -2
  68. package/dist/plugins/organization/adapter.mjs.map +1 -1
  69. package/dist/plugins/organization/client.d.mts +0 -5
  70. package/dist/plugins/organization/organization.d.mts +0 -2
  71. package/dist/plugins/organization/permission.d.mts +0 -1
  72. package/dist/plugins/organization/routes/crud-access-control.d.mts +0 -2
  73. package/dist/plugins/organization/routes/crud-invites.d.mts +0 -3
  74. package/dist/plugins/organization/routes/crud-members.d.mts +0 -3
  75. package/dist/plugins/organization/routes/crud-org.d.mts +0 -3
  76. package/dist/plugins/organization/routes/crud-team.d.mts +2 -3
  77. package/dist/plugins/organization/routes/crud-team.mjs +18 -14
  78. package/dist/plugins/organization/routes/crud-team.mjs.map +1 -1
  79. package/dist/plugins/organization/schema.d.mts +0 -1
  80. package/dist/plugins/organization/types.d.mts +0 -2
  81. package/dist/plugins/phone-number/types.d.mts +0 -1
  82. package/dist/plugins/siwe/index.d.mts +0 -1
  83. package/dist/plugins/test-utils/types.d.mts +0 -2
  84. package/dist/plugins/two-factor/client.d.mts +7 -0
  85. package/dist/plugins/two-factor/client.mjs +5 -1
  86. package/dist/plugins/two-factor/client.mjs.map +1 -1
  87. package/dist/plugins/two-factor/types.d.mts +0 -1
  88. package/dist/test-utils/test-instance.d.mts +18 -22
  89. package/dist/types/index.d.mts +0 -1
  90. package/package.json +13 -10
@@ -1 +1 @@
1
- {"version":3,"file":"crud-team.mjs","names":[],"sources":["../../../../src/plugins/organization/routes/crud-team.ts"],"sourcesContent":["import { createAuthEndpoint } from \"@better-auth/core/api\";\nimport { APIError } from \"@better-auth/core/error\";\nimport * as z from \"zod\";\nimport { getSessionFromCtx } from \"../../../api\";\nimport { setSessionCookie } from \"../../../cookies\";\nimport type { InferAdditionalFieldsFromPluginOptions } from \"../../../db\";\nimport { toZodSchema } from \"../../../db\";\nimport type { PrettifyDeep } from \"../../../types/helper\";\nimport { getOrgAdapter } from \"../adapter\";\nimport { orgMiddleware, orgSessionMiddleware } from \"../call\";\nimport { ORGANIZATION_ERROR_CODES } from \"../error-codes\";\nimport { hasPermission } from \"../has-permission\";\nimport { teamSchema } from \"../schema\";\nimport type { OrganizationOptions } from \"../types\";\n\nconst teamBaseSchema = z.object({\n\tname: z.string().meta({\n\t\tdescription: 'The name of the team. Eg: \"my-team\"',\n\t}),\n\torganizationId: z\n\t\t.string()\n\t\t.meta({\n\t\t\tdescription:\n\t\t\t\t'The organization ID which the team will be created in. Defaults to the active organization. Eg: \"organization-id\"',\n\t\t})\n\t\t.optional(),\n});\n\nexport const createTeam = <O extends OrganizationOptions>(options: O) => {\n\tconst additionalFieldsSchema = toZodSchema({\n\t\tfields: options?.schema?.team?.additionalFields ?? {},\n\t\tisClientSide: true,\n\t});\n\treturn createAuthEndpoint(\n\t\t\"/organization/create-team\",\n\t\t{\n\t\t\tmethod: \"POST\",\n\t\t\tbody: z.object({\n\t\t\t\t...teamBaseSchema.shape,\n\t\t\t\t...additionalFieldsSchema.shape,\n\t\t\t}),\n\t\t\tuse: [orgMiddleware],\n\t\t\tmetadata: {\n\t\t\t\t$Infer: {\n\t\t\t\t\tbody: {} as z.infer<typeof teamBaseSchema> &\n\t\t\t\t\t\tInferAdditionalFieldsFromPluginOptions<\"team\", O>,\n\t\t\t\t},\n\t\t\t\topenapi: {\n\t\t\t\t\tdescription: \"Create a new team within an organization\",\n\t\t\t\t\tresponses: {\n\t\t\t\t\t\t\"200\": {\n\t\t\t\t\t\t\tdescription: \"Team created successfully\",\n\t\t\t\t\t\t\tcontent: {\n\t\t\t\t\t\t\t\t\"application/json\": {\n\t\t\t\t\t\t\t\t\tschema: {\n\t\t\t\t\t\t\t\t\t\ttype: \"object\",\n\t\t\t\t\t\t\t\t\t\tproperties: {\n\t\t\t\t\t\t\t\t\t\t\tid: {\n\t\t\t\t\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t\t\t\t\t\tdescription: \"Unique identifier of the created team\",\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\tname: {\n\t\t\t\t\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t\t\t\t\t\tdescription: \"Name of the team\",\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\torganizationId: {\n\t\t\t\t\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\t\t\t\t\t\t\"ID of the organization the team belongs to\",\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\tcreatedAt: {\n\t\t\t\t\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t\t\t\t\t\tformat: \"date-time\",\n\t\t\t\t\t\t\t\t\t\t\t\tdescription: \"Timestamp when the team was created\",\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\tupdatedAt: {\n\t\t\t\t\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t\t\t\t\t\tformat: \"date-time\",\n\t\t\t\t\t\t\t\t\t\t\t\tdescription: \"Timestamp when the team was last updated\",\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\trequired: [\n\t\t\t\t\t\t\t\t\t\t\t\"id\",\n\t\t\t\t\t\t\t\t\t\t\t\"name\",\n\t\t\t\t\t\t\t\t\t\t\t\"organizationId\",\n\t\t\t\t\t\t\t\t\t\t\t\"createdAt\",\n\t\t\t\t\t\t\t\t\t\t\t\"updatedAt\",\n\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\tasync (ctx) => {\n\t\t\tconst session = await getSessionFromCtx(ctx);\n\t\t\tconst organizationId =\n\t\t\t\tctx.body.organizationId || session?.session.activeOrganizationId;\n\t\t\tif (!session && (ctx.request || ctx.headers)) {\n\t\t\t\tthrow APIError.fromStatus(\"UNAUTHORIZED\");\n\t\t\t}\n\n\t\t\tif (!organizationId) {\n\t\t\t\tthrow APIError.from(\n\t\t\t\t\t\"BAD_REQUEST\",\n\t\t\t\t\tORGANIZATION_ERROR_CODES.NO_ACTIVE_ORGANIZATION,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst adapter = getOrgAdapter<O>(ctx.context, options as O);\n\t\t\tif (session) {\n\t\t\t\tconst member = await adapter.findMemberByOrgId({\n\t\t\t\t\tuserId: session.user.id,\n\t\t\t\t\torganizationId,\n\t\t\t\t});\n\t\t\t\tif (!member) {\n\t\t\t\t\tthrow APIError.from(\n\t\t\t\t\t\t\"FORBIDDEN\",\n\t\t\t\t\t\tORGANIZATION_ERROR_CODES.YOU_ARE_NOT_ALLOWED_TO_INVITE_USERS_TO_THIS_ORGANIZATION,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tconst canCreate = await hasPermission(\n\t\t\t\t\t{\n\t\t\t\t\t\trole: member.role,\n\t\t\t\t\t\toptions: ctx.context.orgOptions,\n\t\t\t\t\t\tpermissions: {\n\t\t\t\t\t\t\tteam: [\"create\"],\n\t\t\t\t\t\t},\n\t\t\t\t\t\torganizationId,\n\t\t\t\t\t},\n\t\t\t\t\tctx,\n\t\t\t\t);\n\n\t\t\t\tif (!canCreate) {\n\t\t\t\t\tthrow APIError.from(\n\t\t\t\t\t\t\"FORBIDDEN\",\n\t\t\t\t\t\tORGANIZATION_ERROR_CODES.YOU_ARE_NOT_ALLOWED_TO_CREATE_TEAMS_IN_THIS_ORGANIZATION,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst existingTeams = await adapter.listTeams(organizationId);\n\t\t\tconst maximum =\n\t\t\t\ttypeof ctx.context.orgOptions.teams?.maximumTeams === \"function\"\n\t\t\t\t\t? await ctx.context.orgOptions.teams?.maximumTeams(\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\torganizationId,\n\t\t\t\t\t\t\t\tsession,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tctx,\n\t\t\t\t\t\t)\n\t\t\t\t\t: ctx.context.orgOptions.teams?.maximumTeams;\n\n\t\t\tconst maxTeamsReached = maximum ? existingTeams.length >= maximum : false;\n\t\t\tif (maxTeamsReached) {\n\t\t\t\tthrow APIError.from(\n\t\t\t\t\t\"BAD_REQUEST\",\n\t\t\t\t\tORGANIZATION_ERROR_CODES.YOU_HAVE_REACHED_THE_MAXIMUM_NUMBER_OF_TEAMS,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst { name, organizationId: _, ...additionalFields } = ctx.body;\n\n\t\t\tconst organization = await adapter.findOrganizationById(organizationId);\n\t\t\tif (!organization) {\n\t\t\t\tthrow APIError.from(\n\t\t\t\t\t\"BAD_REQUEST\",\n\t\t\t\t\tORGANIZATION_ERROR_CODES.ORGANIZATION_NOT_FOUND,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tlet teamData = {\n\t\t\t\tname,\n\t\t\t\torganizationId,\n\t\t\t\tcreatedAt: new Date(),\n\t\t\t\tupdatedAt: new Date(),\n\t\t\t\t...additionalFields,\n\t\t\t};\n\n\t\t\t// Run beforeCreateTeam hook\n\t\t\tif (options?.organizationHooks?.beforeCreateTeam) {\n\t\t\t\tconst response = await options?.organizationHooks.beforeCreateTeam({\n\t\t\t\t\tteam: {\n\t\t\t\t\t\tname,\n\t\t\t\t\t\torganizationId,\n\t\t\t\t\t\t...additionalFields,\n\t\t\t\t\t},\n\t\t\t\t\tuser: session?.user,\n\t\t\t\t\torganization,\n\t\t\t\t});\n\t\t\t\tif (response && typeof response === \"object\" && \"data\" in response) {\n\t\t\t\t\tteamData = {\n\t\t\t\t\t\t...teamData,\n\t\t\t\t\t\t...response.data,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst createdTeam = await adapter.createTeam(teamData);\n\n\t\t\t// Run afterCreateTeam hook\n\t\t\tif (options?.organizationHooks?.afterCreateTeam) {\n\t\t\t\tawait options?.organizationHooks.afterCreateTeam({\n\t\t\t\t\tteam: createdTeam,\n\t\t\t\t\tuser: session?.user,\n\t\t\t\t\torganization,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\treturn ctx.json(createdTeam);\n\t\t},\n\t);\n};\n\nconst removeTeamBodySchema = z.object({\n\tteamId: z.string().meta({\n\t\tdescription: `The team ID of the team to remove. Eg: \"team-id\"`,\n\t}),\n\torganizationId: z\n\t\t.string()\n\t\t.meta({\n\t\t\tdescription: `The organization ID which the team falls under. If not provided, it will default to the user's active organization. Eg: \"organization-id\"`,\n\t\t})\n\t\t.optional(),\n});\n\nexport const removeTeam = <O extends OrganizationOptions>(options: O) =>\n\tcreateAuthEndpoint(\n\t\t\"/organization/remove-team\",\n\t\t{\n\t\t\tmethod: \"POST\",\n\t\t\tbody: removeTeamBodySchema,\n\t\t\tuse: [orgMiddleware],\n\t\t\tmetadata: {\n\t\t\t\topenapi: {\n\t\t\t\t\tdescription: \"Remove a team from an organization\",\n\t\t\t\t\tresponses: {\n\t\t\t\t\t\t\"200\": {\n\t\t\t\t\t\t\tdescription: \"Team removed successfully\",\n\t\t\t\t\t\t\tcontent: {\n\t\t\t\t\t\t\t\t\"application/json\": {\n\t\t\t\t\t\t\t\t\tschema: {\n\t\t\t\t\t\t\t\t\t\ttype: \"object\",\n\t\t\t\t\t\t\t\t\t\tproperties: {\n\t\t\t\t\t\t\t\t\t\t\tmessage: {\n\t\t\t\t\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\t\t\t\t\t\t\"Confirmation message indicating successful removal\",\n\t\t\t\t\t\t\t\t\t\t\t\tenum: [\"Team removed successfully.\"],\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\trequired: [\"message\"],\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\tasync (ctx) => {\n\t\t\tconst session = await getSessionFromCtx(ctx);\n\t\t\tconst organizationId =\n\t\t\t\tctx.body.organizationId || session?.session.activeOrganizationId;\n\t\t\tif (!organizationId) {\n\t\t\t\tthrow APIError.from(\n\t\t\t\t\t\"BAD_REQUEST\",\n\t\t\t\t\tORGANIZATION_ERROR_CODES.NO_ACTIVE_ORGANIZATION,\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (!session && (ctx.request || ctx.headers)) {\n\t\t\t\tthrow APIError.fromStatus(\"UNAUTHORIZED\");\n\t\t\t}\n\t\t\tconst adapter = getOrgAdapter<O>(ctx.context, options);\n\t\t\tif (session) {\n\t\t\t\tconst member = await adapter.findMemberByOrgId({\n\t\t\t\t\tuserId: session.user.id,\n\t\t\t\t\torganizationId,\n\t\t\t\t});\n\n\t\t\t\tif (!member || session.session?.activeTeamId === ctx.body.teamId) {\n\t\t\t\t\tthrow APIError.from(\n\t\t\t\t\t\t\"FORBIDDEN\",\n\t\t\t\t\t\tORGANIZATION_ERROR_CODES.YOU_ARE_NOT_ALLOWED_TO_DELETE_THIS_TEAM,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tconst canRemove = await hasPermission(\n\t\t\t\t\t{\n\t\t\t\t\t\trole: member.role,\n\t\t\t\t\t\toptions: ctx.context.orgOptions,\n\t\t\t\t\t\tpermissions: {\n\t\t\t\t\t\t\tteam: [\"delete\"],\n\t\t\t\t\t\t},\n\t\t\t\t\t\torganizationId,\n\t\t\t\t\t},\n\t\t\t\t\tctx,\n\t\t\t\t);\n\n\t\t\t\tif (!canRemove) {\n\t\t\t\t\tthrow APIError.from(\n\t\t\t\t\t\t\"FORBIDDEN\",\n\t\t\t\t\t\tORGANIZATION_ERROR_CODES.YOU_ARE_NOT_ALLOWED_TO_DELETE_TEAMS_IN_THIS_ORGANIZATION,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst team = await adapter.findTeamById({\n\t\t\t\tteamId: ctx.body.teamId,\n\t\t\t\torganizationId,\n\t\t\t});\n\t\t\tif (!team || team.organizationId !== organizationId) {\n\t\t\t\tthrow APIError.from(\n\t\t\t\t\t\"BAD_REQUEST\",\n\t\t\t\t\tORGANIZATION_ERROR_CODES.TEAM_NOT_FOUND,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tif (!ctx.context.orgOptions.teams?.allowRemovingAllTeams) {\n\t\t\t\tconst teams = await adapter.listTeams(organizationId);\n\t\t\t\tif (teams.length <= 1) {\n\t\t\t\t\tthrow APIError.from(\n\t\t\t\t\t\t\"BAD_REQUEST\",\n\t\t\t\t\t\tORGANIZATION_ERROR_CODES.UNABLE_TO_REMOVE_LAST_TEAM,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst organization = await adapter.findOrganizationById(organizationId);\n\t\t\tif (!organization) {\n\t\t\t\tthrow APIError.from(\n\t\t\t\t\t\"BAD_REQUEST\",\n\t\t\t\t\tORGANIZATION_ERROR_CODES.ORGANIZATION_NOT_FOUND,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t// Run beforeDeleteTeam hook\n\t\t\tif (options?.organizationHooks?.beforeDeleteTeam) {\n\t\t\t\tawait options?.organizationHooks.beforeDeleteTeam({\n\t\t\t\t\tteam,\n\t\t\t\t\tuser: session?.user,\n\t\t\t\t\torganization,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tawait adapter.deleteTeam(team.id);\n\n\t\t\t// Run afterDeleteTeam hook\n\t\t\tif (options?.organizationHooks?.afterDeleteTeam) {\n\t\t\t\tawait options?.organizationHooks.afterDeleteTeam({\n\t\t\t\t\tteam,\n\t\t\t\t\tuser: session?.user,\n\t\t\t\t\torganization,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\treturn ctx.json({ message: \"Team removed successfully.\" });\n\t\t},\n\t);\n\nexport const updateTeam = <O extends OrganizationOptions>(options: O) => {\n\tconst additionalFieldsSchema = toZodSchema({\n\t\tfields: options?.schema?.team?.additionalFields ?? {},\n\t\tisClientSide: true,\n\t});\n\n\ttype Body = {\n\t\tteamId: string;\n\t\tdata: Partial<\n\t\t\tPrettifyDeep<\n\t\t\t\tOmit<z.infer<typeof teamSchema>, \"id\" | \"createdAt\" | \"updatedAt\">\n\t\t\t> &\n\t\t\t\tInferAdditionalFieldsFromPluginOptions<\"team\", O>\n\t\t>;\n\t};\n\n\treturn createAuthEndpoint(\n\t\t\"/organization/update-team\",\n\t\t{\n\t\t\tmethod: \"POST\",\n\t\t\tbody: z.object({\n\t\t\t\tteamId: z.string().meta({\n\t\t\t\t\tdescription: `The ID of the team to be updated. Eg: \"team-id\"`,\n\t\t\t\t}),\n\t\t\t\tdata: z\n\t\t\t\t\t.object({\n\t\t\t\t\t\t...teamSchema.shape,\n\t\t\t\t\t\t...additionalFieldsSchema.shape,\n\t\t\t\t\t})\n\t\t\t\t\t.partial(),\n\t\t\t}),\n\t\t\trequireHeaders: true,\n\t\t\tuse: [orgMiddleware, orgSessionMiddleware],\n\t\t\tmetadata: {\n\t\t\t\t$Infer: { body: {} as Body },\n\t\t\t\topenapi: {\n\t\t\t\t\tdescription: \"Update an existing team in an organization\",\n\t\t\t\t\tresponses: {\n\t\t\t\t\t\t\"200\": {\n\t\t\t\t\t\t\tdescription: \"Team updated successfully\",\n\t\t\t\t\t\t\tcontent: {\n\t\t\t\t\t\t\t\t\"application/json\": {\n\t\t\t\t\t\t\t\t\tschema: {\n\t\t\t\t\t\t\t\t\t\ttype: \"object\",\n\t\t\t\t\t\t\t\t\t\tproperties: {\n\t\t\t\t\t\t\t\t\t\t\tid: {\n\t\t\t\t\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t\t\t\t\t\tdescription: \"Unique identifier of the updated team\",\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\tname: {\n\t\t\t\t\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t\t\t\t\t\tdescription: \"Updated name of the team\",\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\torganizationId: {\n\t\t\t\t\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\t\t\t\t\t\t\"ID of the organization the team belongs to\",\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\tcreatedAt: {\n\t\t\t\t\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t\t\t\t\t\tformat: \"date-time\",\n\t\t\t\t\t\t\t\t\t\t\t\tdescription: \"Timestamp when the team was created\",\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\tupdatedAt: {\n\t\t\t\t\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t\t\t\t\t\tformat: \"date-time\",\n\t\t\t\t\t\t\t\t\t\t\t\tdescription: \"Timestamp when the team was last updated\",\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\trequired: [\n\t\t\t\t\t\t\t\t\t\t\t\"id\",\n\t\t\t\t\t\t\t\t\t\t\t\"name\",\n\t\t\t\t\t\t\t\t\t\t\t\"organizationId\",\n\t\t\t\t\t\t\t\t\t\t\t\"createdAt\",\n\t\t\t\t\t\t\t\t\t\t\t\"updatedAt\",\n\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\tasync (ctx) => {\n\t\t\tconst session = ctx.context.session;\n\t\t\tconst organizationId =\n\t\t\t\tctx.body.data.organizationId || session.session.activeOrganizationId;\n\t\t\tif (!organizationId) {\n\t\t\t\tthrow APIError.from(\n\t\t\t\t\t\"BAD_REQUEST\",\n\t\t\t\t\tORGANIZATION_ERROR_CODES.NO_ACTIVE_ORGANIZATION,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst adapter = getOrgAdapter<O>(ctx.context, options);\n\t\t\tconst member = await adapter.findMemberByOrgId({\n\t\t\t\tuserId: session.user.id,\n\t\t\t\torganizationId,\n\t\t\t});\n\n\t\t\tif (!member) {\n\t\t\t\tthrow APIError.from(\n\t\t\t\t\t\"FORBIDDEN\",\n\t\t\t\t\tORGANIZATION_ERROR_CODES.YOU_ARE_NOT_ALLOWED_TO_UPDATE_THIS_TEAM,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst canUpdate = await hasPermission(\n\t\t\t\t{\n\t\t\t\t\trole: member.role,\n\t\t\t\t\toptions: ctx.context.orgOptions,\n\t\t\t\t\tpermissions: {\n\t\t\t\t\t\tteam: [\"update\"],\n\t\t\t\t\t},\n\t\t\t\t\torganizationId,\n\t\t\t\t},\n\t\t\t\tctx,\n\t\t\t);\n\n\t\t\tif (!canUpdate) {\n\t\t\t\tthrow APIError.from(\n\t\t\t\t\t\"FORBIDDEN\",\n\t\t\t\t\tORGANIZATION_ERROR_CODES.YOU_ARE_NOT_ALLOWED_TO_UPDATE_THIS_TEAM,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst team = await adapter.findTeamById({\n\t\t\t\tteamId: ctx.body.teamId,\n\t\t\t\torganizationId,\n\t\t\t});\n\n\t\t\tif (!team || team.organizationId !== organizationId) {\n\t\t\t\tthrow APIError.from(\n\t\t\t\t\t\"BAD_REQUEST\",\n\t\t\t\t\tORGANIZATION_ERROR_CODES.TEAM_NOT_FOUND,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst { name, organizationId: __, ...additionalFields } = ctx.body.data;\n\n\t\t\tconst organization = await adapter.findOrganizationById(organizationId);\n\t\t\tif (!organization) {\n\t\t\t\tthrow APIError.from(\n\t\t\t\t\t\"BAD_REQUEST\",\n\t\t\t\t\tORGANIZATION_ERROR_CODES.ORGANIZATION_NOT_FOUND,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst updates = {\n\t\t\t\tname,\n\t\t\t\t...additionalFields,\n\t\t\t};\n\n\t\t\t// Run beforeUpdateTeam hook\n\t\t\tif (options?.organizationHooks?.beforeUpdateTeam) {\n\t\t\t\tconst response = await options?.organizationHooks.beforeUpdateTeam({\n\t\t\t\t\tteam,\n\t\t\t\t\tupdates,\n\t\t\t\t\tuser: session.user,\n\t\t\t\t\torganization,\n\t\t\t\t});\n\t\t\t\tif (response && typeof response === \"object\" && \"data\" in response) {\n\t\t\t\t\t// Allow the hook to modify the updates\n\t\t\t\t\tconst modifiedUpdates = response.data;\n\t\t\t\t\tconst updatedTeam = await adapter.updateTeam(\n\t\t\t\t\t\tteam.id,\n\t\t\t\t\t\tmodifiedUpdates,\n\t\t\t\t\t);\n\n\t\t\t\t\t// Run afterUpdateTeam hook\n\t\t\t\t\tif (options?.organizationHooks?.afterUpdateTeam) {\n\t\t\t\t\t\tawait options?.organizationHooks.afterUpdateTeam({\n\t\t\t\t\t\t\tteam: updatedTeam,\n\t\t\t\t\t\t\tuser: session.user,\n\t\t\t\t\t\t\torganization,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\treturn ctx.json(updatedTeam);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst updatedTeam = await adapter.updateTeam(team.id, updates);\n\n\t\t\t// Run afterUpdateTeam hook\n\t\t\tif (options?.organizationHooks?.afterUpdateTeam) {\n\t\t\t\tawait options?.organizationHooks.afterUpdateTeam({\n\t\t\t\t\tteam: updatedTeam,\n\t\t\t\t\tuser: session.user,\n\t\t\t\t\torganization,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\treturn ctx.json(updatedTeam);\n\t\t},\n\t);\n};\n\nconst listOrganizationTeamsQuerySchema = z.optional(\n\tz.object({\n\t\torganizationId: z\n\t\t\t.string()\n\t\t\t.meta({\n\t\t\t\tdescription: `The organization ID which the teams are under to list. Defaults to the users active organization. Eg: \"organization-id\"`,\n\t\t\t})\n\t\t\t.optional(),\n\t}),\n);\n\nexport const listOrganizationTeams = <O extends OrganizationOptions>(\n\toptions: O,\n) =>\n\tcreateAuthEndpoint(\n\t\t\"/organization/list-teams\",\n\t\t{\n\t\t\tmethod: \"GET\",\n\t\t\tquery: listOrganizationTeamsQuerySchema,\n\t\t\tmetadata: {\n\t\t\t\topenapi: {\n\t\t\t\t\tdescription: \"List all teams in an organization\",\n\t\t\t\t\tresponses: {\n\t\t\t\t\t\t\"200\": {\n\t\t\t\t\t\t\tdescription: \"Teams retrieved successfully\",\n\t\t\t\t\t\t\tcontent: {\n\t\t\t\t\t\t\t\t\"application/json\": {\n\t\t\t\t\t\t\t\t\tschema: {\n\t\t\t\t\t\t\t\t\t\ttype: \"array\",\n\t\t\t\t\t\t\t\t\t\titems: {\n\t\t\t\t\t\t\t\t\t\t\ttype: \"object\",\n\t\t\t\t\t\t\t\t\t\t\tproperties: {\n\t\t\t\t\t\t\t\t\t\t\t\tid: {\n\t\t\t\t\t\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t\t\t\t\t\t\tdescription: \"Unique identifier of the team\",\n\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\tname: {\n\t\t\t\t\t\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t\t\t\t\t\t\tdescription: \"Name of the team\",\n\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\torganizationId: {\n\t\t\t\t\t\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"ID of the organization the team belongs to\",\n\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\tcreatedAt: {\n\t\t\t\t\t\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t\t\t\t\t\t\tformat: \"date-time\",\n\t\t\t\t\t\t\t\t\t\t\t\t\tdescription: \"Timestamp when the team was created\",\n\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\tupdatedAt: {\n\t\t\t\t\t\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t\t\t\t\t\t\tformat: \"date-time\",\n\t\t\t\t\t\t\t\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"Timestamp when the team was last updated\",\n\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\trequired: [\n\t\t\t\t\t\t\t\t\t\t\t\t\"id\",\n\t\t\t\t\t\t\t\t\t\t\t\t\"name\",\n\t\t\t\t\t\t\t\t\t\t\t\t\"organizationId\",\n\t\t\t\t\t\t\t\t\t\t\t\t\"createdAt\",\n\t\t\t\t\t\t\t\t\t\t\t\t\"updatedAt\",\n\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\t\t\t\t\"Array of team objects within the organization\",\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\trequireHeaders: true,\n\t\t\tuse: [orgMiddleware, orgSessionMiddleware],\n\t\t},\n\t\tasync (ctx) => {\n\t\t\tconst session = ctx.context.session;\n\t\t\tconst organizationId =\n\t\t\t\tctx.query?.organizationId || session?.session.activeOrganizationId;\n\t\t\tif (!organizationId) {\n\t\t\t\tthrow APIError.from(\n\t\t\t\t\t\"BAD_REQUEST\",\n\t\t\t\t\tORGANIZATION_ERROR_CODES.NO_ACTIVE_ORGANIZATION,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst adapter = getOrgAdapter<O>(ctx.context, options);\n\t\t\tconst member = await adapter.findMemberByOrgId({\n\t\t\t\tuserId: session.user.id,\n\t\t\t\torganizationId: organizationId || \"\",\n\t\t\t});\n\t\t\tif (!member) {\n\t\t\t\tthrow APIError.from(\n\t\t\t\t\t\"FORBIDDEN\",\n\t\t\t\t\tORGANIZATION_ERROR_CODES.YOU_ARE_NOT_ALLOWED_TO_ACCESS_THIS_ORGANIZATION,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst teams = await adapter.listTeams(organizationId);\n\t\t\treturn ctx.json(teams);\n\t\t},\n\t);\n\nconst setActiveTeamBodySchema = z.object({\n\tteamId: z\n\t\t.string()\n\t\t.meta({\n\t\t\tdescription:\n\t\t\t\t\"The team id to set as active. It can be null to unset the active team\",\n\t\t})\n\t\t.nullable()\n\t\t.optional(),\n});\n\nexport const setActiveTeam = <O extends OrganizationOptions>(options: O) =>\n\tcreateAuthEndpoint(\n\t\t\"/organization/set-active-team\",\n\t\t{\n\t\t\tmethod: \"POST\",\n\t\t\tbody: setActiveTeamBodySchema,\n\t\t\trequireHeaders: true,\n\t\t\tuse: [orgSessionMiddleware, orgMiddleware],\n\t\t\tmetadata: {\n\t\t\t\topenapi: {\n\t\t\t\t\tdescription: \"Set the active team\",\n\t\t\t\t\tresponses: {\n\t\t\t\t\t\t\"200\": {\n\t\t\t\t\t\t\tdescription: \"Success\",\n\t\t\t\t\t\t\tcontent: {\n\t\t\t\t\t\t\t\t\"application/json\": {\n\t\t\t\t\t\t\t\t\tschema: {\n\t\t\t\t\t\t\t\t\t\ttype: \"object\",\n\t\t\t\t\t\t\t\t\t\tdescription: \"The team\",\n\t\t\t\t\t\t\t\t\t\t$ref: \"#/components/schemas/Team\",\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\tasync (ctx) => {\n\t\t\tconst adapter = getOrgAdapter(ctx.context, ctx.context.orgOptions);\n\t\t\tconst session = ctx.context.session;\n\n\t\t\tif (ctx.body.teamId === null) {\n\t\t\t\tconst sessionTeamId = session.session.activeTeamId;\n\t\t\t\tif (!sessionTeamId) {\n\t\t\t\t\treturn ctx.json(null);\n\t\t\t\t}\n\n\t\t\t\tconst updatedSession = await adapter.setActiveTeam(\n\t\t\t\t\tsession.session.token,\n\t\t\t\t\tnull,\n\t\t\t\t\tctx,\n\t\t\t\t);\n\n\t\t\t\tawait setSessionCookie(ctx, {\n\t\t\t\t\tsession: updatedSession,\n\t\t\t\t\tuser: session.user,\n\t\t\t\t});\n\n\t\t\t\treturn ctx.json(null);\n\t\t\t}\n\n\t\t\tlet teamId: string;\n\n\t\t\tif (!ctx.body.teamId) {\n\t\t\t\tconst sessionTeamId = session.session.activeTeamId;\n\t\t\t\tif (!sessionTeamId) {\n\t\t\t\t\treturn ctx.json(null);\n\t\t\t\t} else {\n\t\t\t\t\tteamId = sessionTeamId;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tteamId = ctx.body.teamId;\n\t\t\t}\n\n\t\t\tconst team = await adapter.findTeamById({ teamId });\n\n\t\t\tif (!team) {\n\t\t\t\tthrow APIError.from(\n\t\t\t\t\t\"BAD_REQUEST\",\n\t\t\t\t\tORGANIZATION_ERROR_CODES.TEAM_NOT_FOUND,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst member = await adapter.findTeamMember({\n\t\t\t\tteamId,\n\t\t\t\tuserId: session.user.id,\n\t\t\t});\n\n\t\t\tif (!member) {\n\t\t\t\tthrow APIError.from(\n\t\t\t\t\t\"FORBIDDEN\",\n\t\t\t\t\tORGANIZATION_ERROR_CODES.USER_IS_NOT_A_MEMBER_OF_THE_TEAM,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst updatedSession = await adapter.setActiveTeam(\n\t\t\t\tsession.session.token,\n\t\t\t\tteam.id,\n\t\t\t\tctx,\n\t\t\t);\n\n\t\t\tawait setSessionCookie(ctx, {\n\t\t\t\tsession: updatedSession,\n\t\t\t\tuser: session.user,\n\t\t\t});\n\n\t\t\treturn ctx.json(team);\n\t\t},\n\t);\n\nexport const listUserTeams = <O extends OrganizationOptions>(options: O) =>\n\tcreateAuthEndpoint(\n\t\t\"/organization/list-user-teams\",\n\t\t{\n\t\t\tmethod: \"GET\",\n\t\t\tmetadata: {\n\t\t\t\topenapi: {\n\t\t\t\t\tdescription: \"List all teams that the current user is a part of.\",\n\t\t\t\t\tresponses: {\n\t\t\t\t\t\t\"200\": {\n\t\t\t\t\t\t\tdescription: \"Teams retrieved successfully\",\n\t\t\t\t\t\t\tcontent: {\n\t\t\t\t\t\t\t\t\"application/json\": {\n\t\t\t\t\t\t\t\t\tschema: {\n\t\t\t\t\t\t\t\t\t\ttype: \"array\",\n\t\t\t\t\t\t\t\t\t\titems: {\n\t\t\t\t\t\t\t\t\t\t\ttype: \"object\",\n\t\t\t\t\t\t\t\t\t\t\tdescription: \"The team\",\n\t\t\t\t\t\t\t\t\t\t\t$ref: \"#/components/schemas/Team\",\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\t\t\t\t\"Array of team objects within the organization\",\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\trequireHeaders: true,\n\t\t\tuse: [orgMiddleware, orgSessionMiddleware],\n\t\t},\n\t\tasync (ctx) => {\n\t\t\tconst session = ctx.context.session;\n\t\t\tconst adapter = getOrgAdapter(ctx.context, ctx.context.orgOptions);\n\t\t\tconst teams = await adapter.listTeamsByUser({\n\t\t\t\tuserId: session.user.id,\n\t\t\t});\n\n\t\t\treturn ctx.json(teams);\n\t\t},\n\t);\n\nconst listTeamMembersQuerySchema = z.optional(\n\tz.object({\n\t\tteamId: z.string().optional().meta({\n\t\t\tdescription:\n\t\t\t\t\"The team whose members we should return. If this is not provided the members of the current active team get returned.\",\n\t\t}),\n\t}),\n);\n\nexport const listTeamMembers = <O extends OrganizationOptions>(options: O) =>\n\tcreateAuthEndpoint(\n\t\t\"/organization/list-team-members\",\n\t\t{\n\t\t\tmethod: \"GET\",\n\t\t\tquery: listTeamMembersQuerySchema,\n\t\t\tmetadata: {\n\t\t\t\topenapi: {\n\t\t\t\t\tdescription: \"List the members of the given team.\",\n\t\t\t\t\tresponses: {\n\t\t\t\t\t\t\"200\": {\n\t\t\t\t\t\t\tdescription: \"Teams retrieved successfully\",\n\t\t\t\t\t\t\tcontent: {\n\t\t\t\t\t\t\t\t\"application/json\": {\n\t\t\t\t\t\t\t\t\tschema: {\n\t\t\t\t\t\t\t\t\t\ttype: \"array\",\n\t\t\t\t\t\t\t\t\t\titems: {\n\t\t\t\t\t\t\t\t\t\t\ttype: \"object\",\n\t\t\t\t\t\t\t\t\t\t\tdescription: \"The team member\",\n\t\t\t\t\t\t\t\t\t\t\tproperties: {\n\t\t\t\t\t\t\t\t\t\t\t\tid: {\n\t\t\t\t\t\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t\t\t\t\t\t\tdescription: \"Unique identifier of the team member\",\n\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\tuserId: {\n\t\t\t\t\t\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t\t\t\t\t\t\tdescription: \"The user ID of the team member\",\n\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\tteamId: {\n\t\t\t\t\t\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"The team ID of the team the team member is in\",\n\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\tcreatedAt: {\n\t\t\t\t\t\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t\t\t\t\t\t\tformat: \"date-time\",\n\t\t\t\t\t\t\t\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"Timestamp when the team member was created\",\n\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\trequired: [\"id\", \"userId\", \"teamId\", \"createdAt\"],\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\tdescription: \"Array of team member objects within the team\",\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\trequireHeaders: true,\n\t\t\tuse: [orgMiddleware, orgSessionMiddleware],\n\t\t},\n\t\tasync (ctx) => {\n\t\t\tconst session = ctx.context.session;\n\t\t\tconst adapter = getOrgAdapter(ctx.context, ctx.context.orgOptions);\n\t\t\tconst teamId = ctx.query?.teamId || session?.session.activeTeamId;\n\t\t\tif (!teamId) {\n\t\t\t\tthrow APIError.from(\n\t\t\t\t\t\"BAD_REQUEST\",\n\t\t\t\t\tORGANIZATION_ERROR_CODES.YOU_DO_NOT_HAVE_AN_ACTIVE_TEAM,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst member = await adapter.findTeamMember({\n\t\t\t\tuserId: session.user.id,\n\t\t\t\tteamId,\n\t\t\t});\n\n\t\t\tif (!member) {\n\t\t\t\tthrow APIError.from(\n\t\t\t\t\t\"BAD_REQUEST\",\n\t\t\t\t\tORGANIZATION_ERROR_CODES.USER_IS_NOT_A_MEMBER_OF_THE_TEAM,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst members = await adapter.listTeamMembers({\n\t\t\t\tteamId,\n\t\t\t});\n\t\t\treturn ctx.json(members);\n\t\t},\n\t);\n\nconst addTeamMemberBodySchema = z.object({\n\tteamId: z.string().meta({\n\t\tdescription: \"The team the user should be a member of.\",\n\t}),\n\n\tuserId: z.coerce.string().meta({\n\t\tdescription:\n\t\t\t\"The user Id which represents the user to be added as a member.\",\n\t}),\n});\n\nexport const addTeamMember = <O extends OrganizationOptions>(options: O) =>\n\tcreateAuthEndpoint(\n\t\t\"/organization/add-team-member\",\n\t\t{\n\t\t\tmethod: \"POST\",\n\t\t\tbody: addTeamMemberBodySchema,\n\t\t\tmetadata: {\n\t\t\t\topenapi: {\n\t\t\t\t\tdescription: \"The newly created member\",\n\t\t\t\t\tresponses: {\n\t\t\t\t\t\t\"200\": {\n\t\t\t\t\t\t\tdescription: \"Team member created successfully\",\n\t\t\t\t\t\t\tcontent: {\n\t\t\t\t\t\t\t\t\"application/json\": {\n\t\t\t\t\t\t\t\t\tschema: {\n\t\t\t\t\t\t\t\t\t\ttype: \"object\",\n\t\t\t\t\t\t\t\t\t\tdescription: \"The team member\",\n\t\t\t\t\t\t\t\t\t\tproperties: {\n\t\t\t\t\t\t\t\t\t\t\tid: {\n\t\t\t\t\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t\t\t\t\t\tdescription: \"Unique identifier of the team member\",\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\tuserId: {\n\t\t\t\t\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t\t\t\t\t\tdescription: \"The user ID of the team member\",\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\tteamId: {\n\t\t\t\t\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\t\t\t\t\t\t\"The team ID of the team the team member is in\",\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\tcreatedAt: {\n\t\t\t\t\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t\t\t\t\t\tformat: \"date-time\",\n\t\t\t\t\t\t\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\t\t\t\t\t\t\"Timestamp when the team member was created\",\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\trequired: [\"id\", \"userId\", \"teamId\", \"createdAt\"],\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\trequireHeaders: true,\n\t\t\tuse: [orgMiddleware, orgSessionMiddleware],\n\t\t},\n\t\tasync (ctx) => {\n\t\t\tconst session = ctx.context.session;\n\t\t\tconst adapter = getOrgAdapter(ctx.context, ctx.context.orgOptions);\n\n\t\t\tif (!session.session.activeOrganizationId) {\n\t\t\t\tthrow APIError.from(\n\t\t\t\t\t\"BAD_REQUEST\",\n\t\t\t\t\tORGANIZATION_ERROR_CODES.NO_ACTIVE_ORGANIZATION,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst currentMember = await adapter.findMemberByOrgId({\n\t\t\t\tuserId: session.user.id,\n\t\t\t\torganizationId: session.session.activeOrganizationId,\n\t\t\t});\n\n\t\t\tif (!currentMember) {\n\t\t\t\tthrow APIError.from(\n\t\t\t\t\t\"BAD_REQUEST\",\n\t\t\t\t\tORGANIZATION_ERROR_CODES.USER_IS_NOT_A_MEMBER_OF_THE_ORGANIZATION,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst canUpdateMember = await hasPermission(\n\t\t\t\t{\n\t\t\t\t\trole: currentMember.role,\n\t\t\t\t\toptions: ctx.context.orgOptions,\n\t\t\t\t\tpermissions: {\n\t\t\t\t\t\tmember: [\"update\"],\n\t\t\t\t\t},\n\t\t\t\t\torganizationId: session.session.activeOrganizationId,\n\t\t\t\t},\n\t\t\t\tctx,\n\t\t\t);\n\n\t\t\tif (!canUpdateMember) {\n\t\t\t\tthrow APIError.from(\n\t\t\t\t\t\"FORBIDDEN\",\n\t\t\t\t\tORGANIZATION_ERROR_CODES.YOU_ARE_NOT_ALLOWED_TO_CREATE_A_NEW_TEAM_MEMBER,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst toBeAddedMember = await adapter.findMemberByOrgId({\n\t\t\t\tuserId: ctx.body.userId,\n\t\t\t\torganizationId: session.session.activeOrganizationId,\n\t\t\t});\n\n\t\t\tif (!toBeAddedMember) {\n\t\t\t\tthrow APIError.from(\n\t\t\t\t\t\"BAD_REQUEST\",\n\t\t\t\t\tORGANIZATION_ERROR_CODES.USER_IS_NOT_A_MEMBER_OF_THE_ORGANIZATION,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst team = await adapter.findTeamById({\n\t\t\t\tteamId: ctx.body.teamId,\n\t\t\t\torganizationId: session.session.activeOrganizationId,\n\t\t\t});\n\n\t\t\tif (!team) {\n\t\t\t\tthrow APIError.from(\n\t\t\t\t\t\"BAD_REQUEST\",\n\t\t\t\t\tORGANIZATION_ERROR_CODES.TEAM_NOT_FOUND,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst organization = await adapter.findOrganizationById(\n\t\t\t\tsession.session.activeOrganizationId,\n\t\t\t);\n\t\t\tif (!organization) {\n\t\t\t\tthrow APIError.from(\n\t\t\t\t\t\"BAD_REQUEST\",\n\t\t\t\t\tORGANIZATION_ERROR_CODES.ORGANIZATION_NOT_FOUND,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst userBeingAdded = await ctx.context.internalAdapter.findUserById(\n\t\t\t\tctx.body.userId,\n\t\t\t);\n\t\t\tif (!userBeingAdded) {\n\t\t\t\tthrow APIError.fromStatus(\"BAD_REQUEST\", {\n\t\t\t\t\tmessage: \"User not found\",\n\t\t\t\t});\n\t\t\t}\n\n\t\t\t// Run beforeAddTeamMember hook\n\t\t\tif (options?.organizationHooks?.beforeAddTeamMember) {\n\t\t\t\tconst response = await options?.organizationHooks.beforeAddTeamMember({\n\t\t\t\t\tteamMember: {\n\t\t\t\t\t\tteamId: ctx.body.teamId,\n\t\t\t\t\t\tuserId: ctx.body.userId,\n\t\t\t\t\t},\n\t\t\t\t\tteam,\n\t\t\t\t\tuser: userBeingAdded,\n\t\t\t\t\torganization,\n\t\t\t\t});\n\t\t\t\tif (response && typeof response === \"object\" && \"data\" in response) {\n\t\t\t\t\t// Allow the hook to modify the data\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst teamMember = await adapter.findOrCreateTeamMember({\n\t\t\t\tteamId: ctx.body.teamId,\n\t\t\t\tuserId: ctx.body.userId,\n\t\t\t});\n\n\t\t\t// Run afterAddTeamMember hook\n\t\t\tif (options?.organizationHooks?.afterAddTeamMember) {\n\t\t\t\tawait options?.organizationHooks.afterAddTeamMember({\n\t\t\t\t\tteamMember,\n\t\t\t\t\tteam,\n\t\t\t\t\tuser: userBeingAdded,\n\t\t\t\t\torganization,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\treturn ctx.json(teamMember);\n\t\t},\n\t);\n\nconst removeTeamMemberBodySchema = z.object({\n\tteamId: z.string().meta({\n\t\tdescription: \"The team the user should be removed from.\",\n\t}),\n\n\tuserId: z.coerce.string().meta({\n\t\tdescription: \"The user which should be removed from the team.\",\n\t}),\n});\n\nexport const removeTeamMember = <O extends OrganizationOptions>(options: O) =>\n\tcreateAuthEndpoint(\n\t\t\"/organization/remove-team-member\",\n\t\t{\n\t\t\tmethod: \"POST\",\n\t\t\tbody: removeTeamMemberBodySchema,\n\t\t\tmetadata: {\n\t\t\t\topenapi: {\n\t\t\t\t\tdescription: \"Remove a member from a team\",\n\t\t\t\t\tresponses: {\n\t\t\t\t\t\t\"200\": {\n\t\t\t\t\t\t\tdescription: \"Team member removed successfully\",\n\t\t\t\t\t\t\tcontent: {\n\t\t\t\t\t\t\t\t\"application/json\": {\n\t\t\t\t\t\t\t\t\tschema: {\n\t\t\t\t\t\t\t\t\t\ttype: \"object\",\n\t\t\t\t\t\t\t\t\t\tproperties: {\n\t\t\t\t\t\t\t\t\t\t\tmessage: {\n\t\t\t\t\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\t\t\t\t\t\t\"Confirmation message indicating successful removal\",\n\t\t\t\t\t\t\t\t\t\t\t\tenum: [\"Team member removed successfully.\"],\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\trequired: [\"message\"],\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\trequireHeaders: true,\n\t\t\tuse: [orgMiddleware, orgSessionMiddleware],\n\t\t},\n\t\tasync (ctx) => {\n\t\t\tconst session = ctx.context.session;\n\t\t\tconst adapter = getOrgAdapter(ctx.context, ctx.context.orgOptions);\n\n\t\t\tif (!session.session.activeOrganizationId) {\n\t\t\t\tthrow APIError.from(\n\t\t\t\t\t\"BAD_REQUEST\",\n\t\t\t\t\tORGANIZATION_ERROR_CODES.NO_ACTIVE_ORGANIZATION,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst currentMember = await adapter.findMemberByOrgId({\n\t\t\t\tuserId: session.user.id,\n\t\t\t\torganizationId: session.session.activeOrganizationId,\n\t\t\t});\n\n\t\t\tif (!currentMember) {\n\t\t\t\tthrow APIError.from(\n\t\t\t\t\t\"BAD_REQUEST\",\n\t\t\t\t\tORGANIZATION_ERROR_CODES.USER_IS_NOT_A_MEMBER_OF_THE_ORGANIZATION,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst canDeleteMember = await hasPermission(\n\t\t\t\t{\n\t\t\t\t\trole: currentMember.role,\n\t\t\t\t\toptions: ctx.context.orgOptions,\n\t\t\t\t\tpermissions: {\n\t\t\t\t\t\tmember: [\"delete\"],\n\t\t\t\t\t},\n\t\t\t\t\torganizationId: session.session.activeOrganizationId,\n\t\t\t\t},\n\t\t\t\tctx,\n\t\t\t);\n\n\t\t\tif (!canDeleteMember) {\n\t\t\t\tthrow APIError.from(\n\t\t\t\t\t\"FORBIDDEN\",\n\t\t\t\t\tORGANIZATION_ERROR_CODES.YOU_ARE_NOT_ALLOWED_TO_REMOVE_A_TEAM_MEMBER,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst toBeAddedMember = await adapter.findMemberByOrgId({\n\t\t\t\tuserId: ctx.body.userId,\n\t\t\t\torganizationId: session.session.activeOrganizationId,\n\t\t\t});\n\n\t\t\tif (!toBeAddedMember) {\n\t\t\t\tthrow APIError.from(\n\t\t\t\t\t\"BAD_REQUEST\",\n\t\t\t\t\tORGANIZATION_ERROR_CODES.USER_IS_NOT_A_MEMBER_OF_THE_ORGANIZATION,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst team = await adapter.findTeamById({\n\t\t\t\tteamId: ctx.body.teamId,\n\t\t\t\torganizationId: session.session.activeOrganizationId,\n\t\t\t});\n\n\t\t\tif (!team) {\n\t\t\t\tthrow APIError.from(\n\t\t\t\t\t\"BAD_REQUEST\",\n\t\t\t\t\tORGANIZATION_ERROR_CODES.TEAM_NOT_FOUND,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst organization = await adapter.findOrganizationById(\n\t\t\t\tsession.session.activeOrganizationId,\n\t\t\t);\n\t\t\tif (!organization) {\n\t\t\t\tthrow APIError.from(\n\t\t\t\t\t\"BAD_REQUEST\",\n\t\t\t\t\tORGANIZATION_ERROR_CODES.ORGANIZATION_NOT_FOUND,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst userBeingRemoved = await ctx.context.internalAdapter.findUserById(\n\t\t\t\tctx.body.userId,\n\t\t\t);\n\t\t\tif (!userBeingRemoved) {\n\t\t\t\tthrow APIError.fromStatus(\"BAD_REQUEST\", {\n\t\t\t\t\tmessage: \"User not found\",\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst teamMember = await adapter.findTeamMember({\n\t\t\t\tteamId: ctx.body.teamId,\n\t\t\t\tuserId: ctx.body.userId,\n\t\t\t});\n\n\t\t\tif (!teamMember) {\n\t\t\t\tthrow APIError.from(\n\t\t\t\t\t\"BAD_REQUEST\",\n\t\t\t\t\tORGANIZATION_ERROR_CODES.USER_IS_NOT_A_MEMBER_OF_THE_TEAM,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t// Run beforeRemoveTeamMember hook\n\t\t\tif (options?.organizationHooks?.beforeRemoveTeamMember) {\n\t\t\t\tawait options?.organizationHooks.beforeRemoveTeamMember({\n\t\t\t\t\tteamMember,\n\t\t\t\t\tteam,\n\t\t\t\t\tuser: userBeingRemoved,\n\t\t\t\t\torganization,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tawait adapter.removeTeamMember({\n\t\t\t\tteamId: ctx.body.teamId,\n\t\t\t\tuserId: ctx.body.userId,\n\t\t\t});\n\n\t\t\t// Run afterRemoveTeamMember hook\n\t\t\tif (options?.organizationHooks?.afterRemoveTeamMember) {\n\t\t\t\tawait options?.organizationHooks.afterRemoveTeamMember({\n\t\t\t\t\tteamMember,\n\t\t\t\t\tteam,\n\t\t\t\t\tuser: userBeingRemoved,\n\t\t\t\t\torganization,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\treturn ctx.json({ message: \"Team member removed successfully.\" });\n\t\t},\n\t);\n"],"mappings":";;;;;;;;;;;;;;;AAeA,MAAM,iBAAiB,EAAE,OAAO;CAC/B,MAAM,EAAE,QAAQ,CAAC,KAAK,EACrB,aAAa,yCACb,CAAC;CACF,gBAAgB,EACd,QAAQ,CACR,KAAK,EACL,aACC,uHACD,CAAC,CACD,UAAU;CACZ,CAAC;AAEF,MAAa,cAA6C,YAAe;CACxE,MAAM,yBAAyB,YAAY;EAC1C,QAAQ,SAAS,QAAQ,MAAM,oBAAoB,EAAE;EACrD,cAAc;EACd,CAAC;AACF,QAAO,mBACN,6BACA;EACC,QAAQ;E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SAAS,mBAAmB,sBAC/B,OAAM,SAAS,kBAAkB,sBAAsB;EACtD;EACA;EACA,MAAM;EACN;EACA,CAAC;AAGH,QAAO,IAAI,KAAK,EAAE,SAAS,qCAAqC,CAAC;EAElE"}
1
+ {"version":3,"file":"crud-team.mjs","names":[],"sources":["../../../../src/plugins/organization/routes/crud-team.ts"],"sourcesContent":["import { createAuthEndpoint } from \"@better-auth/core/api\";\nimport { APIError } from \"@better-auth/core/error\";\nimport * as z from \"zod\";\nimport { getSessionFromCtx } from \"../../../api\";\nimport { setSessionCookie } from \"../../../cookies\";\nimport type { InferAdditionalFieldsFromPluginOptions } from \"../../../db\";\nimport { toZodSchema } from \"../../../db\";\nimport type { PrettifyDeep } from \"../../../types/helper\";\nimport { getOrgAdapter } from \"../adapter\";\nimport { orgMiddleware, orgSessionMiddleware } from \"../call\";\nimport { ORGANIZATION_ERROR_CODES } from \"../error-codes\";\nimport { hasPermission } from \"../has-permission\";\nimport { teamSchema } from \"../schema\";\nimport type { OrganizationOptions } from \"../types\";\n\nconst teamBaseSchema = z.object({\n\tname: z.string().meta({\n\t\tdescription: 'The name of the team. Eg: \"my-team\"',\n\t}),\n\torganizationId: z\n\t\t.string()\n\t\t.meta({\n\t\t\tdescription:\n\t\t\t\t'The organization ID which the team will be created in. Defaults to the active organization. Eg: \"organization-id\"',\n\t\t})\n\t\t.optional(),\n});\n\nexport const createTeam = <O extends OrganizationOptions>(options: O) => {\n\tconst additionalFieldsSchema = toZodSchema({\n\t\tfields: options?.schema?.team?.additionalFields ?? {},\n\t\tisClientSide: true,\n\t});\n\treturn createAuthEndpoint(\n\t\t\"/organization/create-team\",\n\t\t{\n\t\t\tmethod: \"POST\",\n\t\t\tbody: z.object({\n\t\t\t\t...teamBaseSchema.shape,\n\t\t\t\t...additionalFieldsSchema.shape,\n\t\t\t}),\n\t\t\tuse: [orgMiddleware],\n\t\t\tmetadata: {\n\t\t\t\t$Infer: {\n\t\t\t\t\tbody: {} as z.infer<typeof teamBaseSchema> &\n\t\t\t\t\t\tInferAdditionalFieldsFromPluginOptions<\"team\", O>,\n\t\t\t\t},\n\t\t\t\topenapi: {\n\t\t\t\t\tdescription: \"Create a new team within an organization\",\n\t\t\t\t\tresponses: {\n\t\t\t\t\t\t\"200\": {\n\t\t\t\t\t\t\tdescription: \"Team created successfully\",\n\t\t\t\t\t\t\tcontent: {\n\t\t\t\t\t\t\t\t\"application/json\": {\n\t\t\t\t\t\t\t\t\tschema: {\n\t\t\t\t\t\t\t\t\t\ttype: \"object\",\n\t\t\t\t\t\t\t\t\t\tproperties: {\n\t\t\t\t\t\t\t\t\t\t\tid: {\n\t\t\t\t\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t\t\t\t\t\tdescription: \"Unique identifier of the created team\",\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\tname: {\n\t\t\t\t\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t\t\t\t\t\tdescription: \"Name of the team\",\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\torganizationId: {\n\t\t\t\t\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\t\t\t\t\t\t\"ID of the organization the team belongs to\",\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\tcreatedAt: {\n\t\t\t\t\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t\t\t\t\t\tformat: \"date-time\",\n\t\t\t\t\t\t\t\t\t\t\t\tdescription: \"Timestamp when the team was created\",\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\tupdatedAt: {\n\t\t\t\t\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t\t\t\t\t\tformat: \"date-time\",\n\t\t\t\t\t\t\t\t\t\t\t\tdescription: \"Timestamp when the team was last updated\",\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\trequired: [\n\t\t\t\t\t\t\t\t\t\t\t\"id\",\n\t\t\t\t\t\t\t\t\t\t\t\"name\",\n\t\t\t\t\t\t\t\t\t\t\t\"organizationId\",\n\t\t\t\t\t\t\t\t\t\t\t\"createdAt\",\n\t\t\t\t\t\t\t\t\t\t\t\"updatedAt\",\n\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\tasync (ctx) => {\n\t\t\tconst session = await getSessionFromCtx(ctx);\n\t\t\tconst organizationId =\n\t\t\t\tctx.body.organizationId || session?.session.activeOrganizationId;\n\t\t\tif (!session && (ctx.request || ctx.headers)) {\n\t\t\t\tthrow APIError.fromStatus(\"UNAUTHORIZED\");\n\t\t\t}\n\n\t\t\tif (!organizationId) {\n\t\t\t\tthrow APIError.from(\n\t\t\t\t\t\"BAD_REQUEST\",\n\t\t\t\t\tORGANIZATION_ERROR_CODES.NO_ACTIVE_ORGANIZATION,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst adapter = getOrgAdapter<O>(ctx.context, options as O);\n\t\t\tif (session) {\n\t\t\t\tconst member = await adapter.findMemberByOrgId({\n\t\t\t\t\tuserId: session.user.id,\n\t\t\t\t\torganizationId,\n\t\t\t\t});\n\t\t\t\tif (!member) {\n\t\t\t\t\tthrow APIError.from(\n\t\t\t\t\t\t\"FORBIDDEN\",\n\t\t\t\t\t\tORGANIZATION_ERROR_CODES.YOU_ARE_NOT_ALLOWED_TO_INVITE_USERS_TO_THIS_ORGANIZATION,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tconst canCreate = await hasPermission(\n\t\t\t\t\t{\n\t\t\t\t\t\trole: member.role,\n\t\t\t\t\t\toptions: ctx.context.orgOptions,\n\t\t\t\t\t\tpermissions: {\n\t\t\t\t\t\t\tteam: [\"create\"],\n\t\t\t\t\t\t},\n\t\t\t\t\t\torganizationId,\n\t\t\t\t\t},\n\t\t\t\t\tctx,\n\t\t\t\t);\n\n\t\t\t\tif (!canCreate) {\n\t\t\t\t\tthrow APIError.from(\n\t\t\t\t\t\t\"FORBIDDEN\",\n\t\t\t\t\t\tORGANIZATION_ERROR_CODES.YOU_ARE_NOT_ALLOWED_TO_CREATE_TEAMS_IN_THIS_ORGANIZATION,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst existingTeams = await adapter.listTeams(organizationId);\n\t\t\tconst maximum =\n\t\t\t\ttypeof ctx.context.orgOptions.teams?.maximumTeams === \"function\"\n\t\t\t\t\t? await ctx.context.orgOptions.teams?.maximumTeams(\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\torganizationId,\n\t\t\t\t\t\t\t\tsession,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tctx,\n\t\t\t\t\t\t)\n\t\t\t\t\t: ctx.context.orgOptions.teams?.maximumTeams;\n\n\t\t\tconst maxTeamsReached = maximum ? existingTeams.length >= maximum : false;\n\t\t\tif (maxTeamsReached) {\n\t\t\t\tthrow APIError.from(\n\t\t\t\t\t\"BAD_REQUEST\",\n\t\t\t\t\tORGANIZATION_ERROR_CODES.YOU_HAVE_REACHED_THE_MAXIMUM_NUMBER_OF_TEAMS,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst { name, organizationId: _, ...additionalFields } = ctx.body;\n\n\t\t\tconst organization = await adapter.findOrganizationById(organizationId);\n\t\t\tif (!organization) {\n\t\t\t\tthrow APIError.from(\n\t\t\t\t\t\"BAD_REQUEST\",\n\t\t\t\t\tORGANIZATION_ERROR_CODES.ORGANIZATION_NOT_FOUND,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tlet teamData = {\n\t\t\t\tname,\n\t\t\t\torganizationId,\n\t\t\t\tcreatedAt: new Date(),\n\t\t\t\tupdatedAt: new Date(),\n\t\t\t\t...additionalFields,\n\t\t\t};\n\n\t\t\t// Run beforeCreateTeam hook\n\t\t\tif (options?.organizationHooks?.beforeCreateTeam) {\n\t\t\t\tconst response = await options?.organizationHooks.beforeCreateTeam({\n\t\t\t\t\tteam: {\n\t\t\t\t\t\tname,\n\t\t\t\t\t\torganizationId,\n\t\t\t\t\t\t...additionalFields,\n\t\t\t\t\t},\n\t\t\t\t\tuser: session?.user,\n\t\t\t\t\torganization,\n\t\t\t\t});\n\t\t\t\tif (response && typeof response === \"object\" && \"data\" in response) {\n\t\t\t\t\tteamData = {\n\t\t\t\t\t\t...teamData,\n\t\t\t\t\t\t...response.data,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst createdTeam = await adapter.createTeam(teamData);\n\n\t\t\t// Run afterCreateTeam hook\n\t\t\tif (options?.organizationHooks?.afterCreateTeam) {\n\t\t\t\tawait options?.organizationHooks.afterCreateTeam({\n\t\t\t\t\tteam: createdTeam,\n\t\t\t\t\tuser: session?.user,\n\t\t\t\t\torganization,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\treturn ctx.json(createdTeam);\n\t\t},\n\t);\n};\n\nconst removeTeamBodySchema = z.object({\n\tteamId: z.string().meta({\n\t\tdescription: `The team ID of the team to remove. Eg: \"team-id\"`,\n\t}),\n\torganizationId: z\n\t\t.string()\n\t\t.meta({\n\t\t\tdescription: `The organization ID which the team falls under. If not provided, it will default to the user's active organization. Eg: \"organization-id\"`,\n\t\t})\n\t\t.optional(),\n});\n\nexport const removeTeam = <O extends OrganizationOptions>(options: O) =>\n\tcreateAuthEndpoint(\n\t\t\"/organization/remove-team\",\n\t\t{\n\t\t\tmethod: \"POST\",\n\t\t\tbody: removeTeamBodySchema,\n\t\t\tuse: [orgMiddleware],\n\t\t\tmetadata: {\n\t\t\t\topenapi: {\n\t\t\t\t\tdescription: \"Remove a team from an organization\",\n\t\t\t\t\tresponses: {\n\t\t\t\t\t\t\"200\": {\n\t\t\t\t\t\t\tdescription: \"Team removed successfully\",\n\t\t\t\t\t\t\tcontent: {\n\t\t\t\t\t\t\t\t\"application/json\": {\n\t\t\t\t\t\t\t\t\tschema: {\n\t\t\t\t\t\t\t\t\t\ttype: \"object\",\n\t\t\t\t\t\t\t\t\t\tproperties: {\n\t\t\t\t\t\t\t\t\t\t\tmessage: {\n\t\t\t\t\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\t\t\t\t\t\t\"Confirmation message indicating successful removal\",\n\t\t\t\t\t\t\t\t\t\t\t\tenum: [\"Team removed successfully.\"],\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\trequired: [\"message\"],\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\tasync (ctx) => {\n\t\t\tconst session = await getSessionFromCtx(ctx);\n\t\t\tconst organizationId =\n\t\t\t\tctx.body.organizationId || session?.session.activeOrganizationId;\n\t\t\tif (!organizationId) {\n\t\t\t\tthrow APIError.from(\n\t\t\t\t\t\"BAD_REQUEST\",\n\t\t\t\t\tORGANIZATION_ERROR_CODES.NO_ACTIVE_ORGANIZATION,\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (!session && (ctx.request || ctx.headers)) {\n\t\t\t\tthrow APIError.fromStatus(\"UNAUTHORIZED\");\n\t\t\t}\n\t\t\tconst adapter = getOrgAdapter<O>(ctx.context, options);\n\t\t\tif (session) {\n\t\t\t\tconst member = await adapter.findMemberByOrgId({\n\t\t\t\t\tuserId: session.user.id,\n\t\t\t\t\torganizationId,\n\t\t\t\t});\n\n\t\t\t\tif (!member || session.session?.activeTeamId === ctx.body.teamId) {\n\t\t\t\t\tthrow APIError.from(\n\t\t\t\t\t\t\"FORBIDDEN\",\n\t\t\t\t\t\tORGANIZATION_ERROR_CODES.YOU_ARE_NOT_ALLOWED_TO_DELETE_THIS_TEAM,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tconst canRemove = await hasPermission(\n\t\t\t\t\t{\n\t\t\t\t\t\trole: member.role,\n\t\t\t\t\t\toptions: ctx.context.orgOptions,\n\t\t\t\t\t\tpermissions: {\n\t\t\t\t\t\t\tteam: [\"delete\"],\n\t\t\t\t\t\t},\n\t\t\t\t\t\torganizationId,\n\t\t\t\t\t},\n\t\t\t\t\tctx,\n\t\t\t\t);\n\n\t\t\t\tif (!canRemove) {\n\t\t\t\t\tthrow APIError.from(\n\t\t\t\t\t\t\"FORBIDDEN\",\n\t\t\t\t\t\tORGANIZATION_ERROR_CODES.YOU_ARE_NOT_ALLOWED_TO_DELETE_TEAMS_IN_THIS_ORGANIZATION,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst team = await adapter.findTeamById({\n\t\t\t\tteamId: ctx.body.teamId,\n\t\t\t\torganizationId,\n\t\t\t});\n\t\t\tif (!team || team.organizationId !== organizationId) {\n\t\t\t\tthrow APIError.from(\n\t\t\t\t\t\"BAD_REQUEST\",\n\t\t\t\t\tORGANIZATION_ERROR_CODES.TEAM_NOT_FOUND,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tif (!ctx.context.orgOptions.teams?.allowRemovingAllTeams) {\n\t\t\t\tconst teams = await adapter.listTeams(organizationId);\n\t\t\t\tif (teams.length <= 1) {\n\t\t\t\t\tthrow APIError.from(\n\t\t\t\t\t\t\"BAD_REQUEST\",\n\t\t\t\t\t\tORGANIZATION_ERROR_CODES.UNABLE_TO_REMOVE_LAST_TEAM,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst organization = await adapter.findOrganizationById(organizationId);\n\t\t\tif (!organization) {\n\t\t\t\tthrow APIError.from(\n\t\t\t\t\t\"BAD_REQUEST\",\n\t\t\t\t\tORGANIZATION_ERROR_CODES.ORGANIZATION_NOT_FOUND,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t// Run beforeDeleteTeam hook\n\t\t\tif (options?.organizationHooks?.beforeDeleteTeam) {\n\t\t\t\tawait options?.organizationHooks.beforeDeleteTeam({\n\t\t\t\t\tteam,\n\t\t\t\t\tuser: session?.user,\n\t\t\t\t\torganization,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tawait adapter.deleteTeam(team.id);\n\n\t\t\t// Run afterDeleteTeam hook\n\t\t\tif (options?.organizationHooks?.afterDeleteTeam) {\n\t\t\t\tawait options?.organizationHooks.afterDeleteTeam({\n\t\t\t\t\tteam,\n\t\t\t\t\tuser: session?.user,\n\t\t\t\t\torganization,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\treturn ctx.json({ message: \"Team removed successfully.\" });\n\t\t},\n\t);\n\nexport const updateTeam = <O extends OrganizationOptions>(options: O) => {\n\tconst additionalFieldsSchema = toZodSchema({\n\t\tfields: options?.schema?.team?.additionalFields ?? {},\n\t\tisClientSide: true,\n\t});\n\n\ttype Body = {\n\t\tteamId: string;\n\t\tdata: Partial<\n\t\t\tPrettifyDeep<\n\t\t\t\tOmit<z.infer<typeof teamSchema>, \"id\" | \"createdAt\" | \"updatedAt\">\n\t\t\t> &\n\t\t\t\tInferAdditionalFieldsFromPluginOptions<\"team\", O>\n\t\t>;\n\t};\n\n\treturn createAuthEndpoint(\n\t\t\"/organization/update-team\",\n\t\t{\n\t\t\tmethod: \"POST\",\n\t\t\tbody: z.object({\n\t\t\t\tteamId: z.string().meta({\n\t\t\t\t\tdescription: `The ID of the team to be updated. Eg: \"team-id\"`,\n\t\t\t\t}),\n\t\t\t\tdata: z\n\t\t\t\t\t.object({\n\t\t\t\t\t\t...teamSchema.shape,\n\t\t\t\t\t\t...additionalFieldsSchema.shape,\n\t\t\t\t\t})\n\t\t\t\t\t.partial(),\n\t\t\t}),\n\t\t\trequireHeaders: true,\n\t\t\tuse: [orgMiddleware, orgSessionMiddleware],\n\t\t\tmetadata: {\n\t\t\t\t$Infer: { body: {} as Body },\n\t\t\t\topenapi: {\n\t\t\t\t\tdescription: \"Update an existing team in an organization\",\n\t\t\t\t\tresponses: {\n\t\t\t\t\t\t\"200\": {\n\t\t\t\t\t\t\tdescription: \"Team updated successfully\",\n\t\t\t\t\t\t\tcontent: {\n\t\t\t\t\t\t\t\t\"application/json\": {\n\t\t\t\t\t\t\t\t\tschema: {\n\t\t\t\t\t\t\t\t\t\ttype: \"object\",\n\t\t\t\t\t\t\t\t\t\tproperties: {\n\t\t\t\t\t\t\t\t\t\t\tid: {\n\t\t\t\t\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t\t\t\t\t\tdescription: \"Unique identifier of the updated team\",\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\tname: {\n\t\t\t\t\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t\t\t\t\t\tdescription: \"Updated name of the team\",\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\torganizationId: {\n\t\t\t\t\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\t\t\t\t\t\t\"ID of the organization the team belongs to\",\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\tcreatedAt: {\n\t\t\t\t\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t\t\t\t\t\tformat: \"date-time\",\n\t\t\t\t\t\t\t\t\t\t\t\tdescription: \"Timestamp when the team was created\",\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\tupdatedAt: {\n\t\t\t\t\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t\t\t\t\t\tformat: \"date-time\",\n\t\t\t\t\t\t\t\t\t\t\t\tdescription: \"Timestamp when the team was last updated\",\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\trequired: [\n\t\t\t\t\t\t\t\t\t\t\t\"id\",\n\t\t\t\t\t\t\t\t\t\t\t\"name\",\n\t\t\t\t\t\t\t\t\t\t\t\"organizationId\",\n\t\t\t\t\t\t\t\t\t\t\t\"createdAt\",\n\t\t\t\t\t\t\t\t\t\t\t\"updatedAt\",\n\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\tasync (ctx) => {\n\t\t\tconst session = ctx.context.session;\n\t\t\tconst organizationId =\n\t\t\t\tctx.body.data.organizationId || session.session.activeOrganizationId;\n\t\t\tif (!organizationId) {\n\t\t\t\tthrow APIError.from(\n\t\t\t\t\t\"BAD_REQUEST\",\n\t\t\t\t\tORGANIZATION_ERROR_CODES.NO_ACTIVE_ORGANIZATION,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst adapter = getOrgAdapter<O>(ctx.context, options);\n\t\t\tconst member = await adapter.findMemberByOrgId({\n\t\t\t\tuserId: session.user.id,\n\t\t\t\torganizationId,\n\t\t\t});\n\n\t\t\tif (!member) {\n\t\t\t\tthrow APIError.from(\n\t\t\t\t\t\"FORBIDDEN\",\n\t\t\t\t\tORGANIZATION_ERROR_CODES.YOU_ARE_NOT_ALLOWED_TO_UPDATE_THIS_TEAM,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst canUpdate = await hasPermission(\n\t\t\t\t{\n\t\t\t\t\trole: member.role,\n\t\t\t\t\toptions: ctx.context.orgOptions,\n\t\t\t\t\tpermissions: {\n\t\t\t\t\t\tteam: [\"update\"],\n\t\t\t\t\t},\n\t\t\t\t\torganizationId,\n\t\t\t\t},\n\t\t\t\tctx,\n\t\t\t);\n\n\t\t\tif (!canUpdate) {\n\t\t\t\tthrow APIError.from(\n\t\t\t\t\t\"FORBIDDEN\",\n\t\t\t\t\tORGANIZATION_ERROR_CODES.YOU_ARE_NOT_ALLOWED_TO_UPDATE_THIS_TEAM,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst team = await adapter.findTeamById({\n\t\t\t\tteamId: ctx.body.teamId,\n\t\t\t\torganizationId,\n\t\t\t});\n\n\t\t\tif (!team || team.organizationId !== organizationId) {\n\t\t\t\tthrow APIError.from(\n\t\t\t\t\t\"BAD_REQUEST\",\n\t\t\t\t\tORGANIZATION_ERROR_CODES.TEAM_NOT_FOUND,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst { name, organizationId: __, ...additionalFields } = ctx.body.data;\n\n\t\t\tconst organization = await adapter.findOrganizationById(organizationId);\n\t\t\tif (!organization) {\n\t\t\t\tthrow APIError.from(\n\t\t\t\t\t\"BAD_REQUEST\",\n\t\t\t\t\tORGANIZATION_ERROR_CODES.ORGANIZATION_NOT_FOUND,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst updates = {\n\t\t\t\tname,\n\t\t\t\t...additionalFields,\n\t\t\t};\n\n\t\t\t// Run beforeUpdateTeam hook\n\t\t\tif (options?.organizationHooks?.beforeUpdateTeam) {\n\t\t\t\tconst response = await options?.organizationHooks.beforeUpdateTeam({\n\t\t\t\t\tteam,\n\t\t\t\t\tupdates,\n\t\t\t\t\tuser: session.user,\n\t\t\t\t\torganization,\n\t\t\t\t});\n\t\t\t\tif (response && typeof response === \"object\" && \"data\" in response) {\n\t\t\t\t\t// Allow the hook to modify the updates\n\t\t\t\t\tconst modifiedUpdates = response.data;\n\t\t\t\t\tconst updatedTeam = await adapter.updateTeam(\n\t\t\t\t\t\tteam.id,\n\t\t\t\t\t\tmodifiedUpdates,\n\t\t\t\t\t);\n\n\t\t\t\t\t// Run afterUpdateTeam hook\n\t\t\t\t\tif (options?.organizationHooks?.afterUpdateTeam) {\n\t\t\t\t\t\tawait options?.organizationHooks.afterUpdateTeam({\n\t\t\t\t\t\t\tteam: updatedTeam,\n\t\t\t\t\t\t\tuser: session.user,\n\t\t\t\t\t\t\torganization,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\treturn ctx.json(updatedTeam);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst updatedTeam = await adapter.updateTeam(team.id, updates);\n\n\t\t\t// Run afterUpdateTeam hook\n\t\t\tif (options?.organizationHooks?.afterUpdateTeam) {\n\t\t\t\tawait options?.organizationHooks.afterUpdateTeam({\n\t\t\t\t\tteam: updatedTeam,\n\t\t\t\t\tuser: session.user,\n\t\t\t\t\torganization,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\treturn ctx.json(updatedTeam);\n\t\t},\n\t);\n};\n\nconst listOrganizationTeamsQuerySchema = z.optional(\n\tz.object({\n\t\torganizationId: z\n\t\t\t.string()\n\t\t\t.meta({\n\t\t\t\tdescription: `The organization ID which the teams are under to list. Defaults to the users active organization. Eg: \"organization-id\"`,\n\t\t\t})\n\t\t\t.optional(),\n\t}),\n);\n\nexport const listOrganizationTeams = <O extends OrganizationOptions>(\n\toptions: O,\n) =>\n\tcreateAuthEndpoint(\n\t\t\"/organization/list-teams\",\n\t\t{\n\t\t\tmethod: \"GET\",\n\t\t\tquery: listOrganizationTeamsQuerySchema,\n\t\t\tmetadata: {\n\t\t\t\topenapi: {\n\t\t\t\t\tdescription: \"List all teams in an organization\",\n\t\t\t\t\tresponses: {\n\t\t\t\t\t\t\"200\": {\n\t\t\t\t\t\t\tdescription: \"Teams retrieved successfully\",\n\t\t\t\t\t\t\tcontent: {\n\t\t\t\t\t\t\t\t\"application/json\": {\n\t\t\t\t\t\t\t\t\tschema: {\n\t\t\t\t\t\t\t\t\t\ttype: \"array\",\n\t\t\t\t\t\t\t\t\t\titems: {\n\t\t\t\t\t\t\t\t\t\t\ttype: \"object\",\n\t\t\t\t\t\t\t\t\t\t\tproperties: {\n\t\t\t\t\t\t\t\t\t\t\t\tid: {\n\t\t\t\t\t\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t\t\t\t\t\t\tdescription: \"Unique identifier of the team\",\n\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\tname: {\n\t\t\t\t\t\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t\t\t\t\t\t\tdescription: \"Name of the team\",\n\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\torganizationId: {\n\t\t\t\t\t\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"ID of the organization the team belongs to\",\n\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\tcreatedAt: {\n\t\t\t\t\t\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t\t\t\t\t\t\tformat: \"date-time\",\n\t\t\t\t\t\t\t\t\t\t\t\t\tdescription: \"Timestamp when the team was created\",\n\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\tupdatedAt: {\n\t\t\t\t\t\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t\t\t\t\t\t\tformat: \"date-time\",\n\t\t\t\t\t\t\t\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"Timestamp when the team was last updated\",\n\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\trequired: [\n\t\t\t\t\t\t\t\t\t\t\t\t\"id\",\n\t\t\t\t\t\t\t\t\t\t\t\t\"name\",\n\t\t\t\t\t\t\t\t\t\t\t\t\"organizationId\",\n\t\t\t\t\t\t\t\t\t\t\t\t\"createdAt\",\n\t\t\t\t\t\t\t\t\t\t\t\t\"updatedAt\",\n\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\t\t\t\t\"Array of team objects within the organization\",\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\trequireHeaders: true,\n\t\t\tuse: [orgMiddleware, orgSessionMiddleware],\n\t\t},\n\t\tasync (ctx) => {\n\t\t\tconst session = ctx.context.session;\n\t\t\tconst organizationId =\n\t\t\t\tctx.query?.organizationId || session?.session.activeOrganizationId;\n\t\t\tif (!organizationId) {\n\t\t\t\tthrow APIError.from(\n\t\t\t\t\t\"BAD_REQUEST\",\n\t\t\t\t\tORGANIZATION_ERROR_CODES.NO_ACTIVE_ORGANIZATION,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst adapter = getOrgAdapter<O>(ctx.context, options);\n\t\t\tconst member = await adapter.findMemberByOrgId({\n\t\t\t\tuserId: session.user.id,\n\t\t\t\torganizationId: organizationId || \"\",\n\t\t\t});\n\t\t\tif (!member) {\n\t\t\t\tthrow APIError.from(\n\t\t\t\t\t\"FORBIDDEN\",\n\t\t\t\t\tORGANIZATION_ERROR_CODES.YOU_ARE_NOT_ALLOWED_TO_ACCESS_THIS_ORGANIZATION,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst teams = await adapter.listTeams(organizationId);\n\t\t\treturn ctx.json(teams);\n\t\t},\n\t);\n\nconst setActiveTeamBodySchema = z.object({\n\tteamId: z\n\t\t.string()\n\t\t.meta({\n\t\t\tdescription:\n\t\t\t\t\"The team id to set as active. It can be null to unset the active team\",\n\t\t})\n\t\t.nullable()\n\t\t.optional(),\n});\n\nexport const setActiveTeam = <O extends OrganizationOptions>(options: O) =>\n\tcreateAuthEndpoint(\n\t\t\"/organization/set-active-team\",\n\t\t{\n\t\t\tmethod: \"POST\",\n\t\t\tbody: setActiveTeamBodySchema,\n\t\t\trequireHeaders: true,\n\t\t\tuse: [orgSessionMiddleware, orgMiddleware],\n\t\t\tmetadata: {\n\t\t\t\topenapi: {\n\t\t\t\t\tdescription: \"Set the active team\",\n\t\t\t\t\tresponses: {\n\t\t\t\t\t\t\"200\": {\n\t\t\t\t\t\t\tdescription: \"Success\",\n\t\t\t\t\t\t\tcontent: {\n\t\t\t\t\t\t\t\t\"application/json\": {\n\t\t\t\t\t\t\t\t\tschema: {\n\t\t\t\t\t\t\t\t\t\ttype: \"object\",\n\t\t\t\t\t\t\t\t\t\tdescription: \"The team\",\n\t\t\t\t\t\t\t\t\t\t$ref: \"#/components/schemas/Team\",\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\tasync (ctx) => {\n\t\t\tconst adapter = getOrgAdapter(ctx.context, ctx.context.orgOptions);\n\t\t\tconst session = ctx.context.session;\n\n\t\t\tif (ctx.body.teamId === null) {\n\t\t\t\tconst sessionTeamId = session.session.activeTeamId;\n\t\t\t\tif (!sessionTeamId) {\n\t\t\t\t\treturn ctx.json(null);\n\t\t\t\t}\n\n\t\t\t\tconst updatedSession = await adapter.setActiveTeam(\n\t\t\t\t\tsession.session.token,\n\t\t\t\t\tnull,\n\t\t\t\t\tctx,\n\t\t\t\t);\n\n\t\t\t\tawait setSessionCookie(ctx, {\n\t\t\t\t\tsession: updatedSession,\n\t\t\t\t\tuser: session.user,\n\t\t\t\t});\n\n\t\t\t\treturn ctx.json(null);\n\t\t\t}\n\n\t\t\tlet teamId: string;\n\n\t\t\tif (!ctx.body.teamId) {\n\t\t\t\tconst sessionTeamId = session.session.activeTeamId;\n\t\t\t\tif (!sessionTeamId) {\n\t\t\t\t\treturn ctx.json(null);\n\t\t\t\t} else {\n\t\t\t\t\tteamId = sessionTeamId;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tteamId = ctx.body.teamId;\n\t\t\t}\n\n\t\t\tconst team = await adapter.findTeamById({ teamId });\n\n\t\t\tif (!team) {\n\t\t\t\tthrow APIError.from(\n\t\t\t\t\t\"BAD_REQUEST\",\n\t\t\t\t\tORGANIZATION_ERROR_CODES.TEAM_NOT_FOUND,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst member = await adapter.findTeamMember({\n\t\t\t\tteamId,\n\t\t\t\tuserId: session.user.id,\n\t\t\t});\n\n\t\t\tif (!member) {\n\t\t\t\tthrow APIError.from(\n\t\t\t\t\t\"FORBIDDEN\",\n\t\t\t\t\tORGANIZATION_ERROR_CODES.USER_IS_NOT_A_MEMBER_OF_THE_TEAM,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst updatedSession = await adapter.setActiveTeam(\n\t\t\t\tsession.session.token,\n\t\t\t\tteam.id,\n\t\t\t\tctx,\n\t\t\t);\n\n\t\t\tawait setSessionCookie(ctx, {\n\t\t\t\tsession: updatedSession,\n\t\t\t\tuser: session.user,\n\t\t\t});\n\n\t\t\treturn ctx.json(team);\n\t\t},\n\t);\n\nexport const listUserTeams = <O extends OrganizationOptions>(options: O) =>\n\tcreateAuthEndpoint(\n\t\t\"/organization/list-user-teams\",\n\t\t{\n\t\t\tmethod: \"GET\",\n\t\t\tmetadata: {\n\t\t\t\topenapi: {\n\t\t\t\t\tdescription: \"List all teams that the current user is a part of.\",\n\t\t\t\t\tresponses: {\n\t\t\t\t\t\t\"200\": {\n\t\t\t\t\t\t\tdescription: \"Teams retrieved successfully\",\n\t\t\t\t\t\t\tcontent: {\n\t\t\t\t\t\t\t\t\"application/json\": {\n\t\t\t\t\t\t\t\t\tschema: {\n\t\t\t\t\t\t\t\t\t\ttype: \"array\",\n\t\t\t\t\t\t\t\t\t\titems: {\n\t\t\t\t\t\t\t\t\t\t\ttype: \"object\",\n\t\t\t\t\t\t\t\t\t\t\tdescription: \"The team\",\n\t\t\t\t\t\t\t\t\t\t\t$ref: \"#/components/schemas/Team\",\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\t\t\t\t\"Array of team objects within the organization\",\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\trequireHeaders: true,\n\t\t\tuse: [orgMiddleware, orgSessionMiddleware],\n\t\t},\n\t\tasync (ctx) => {\n\t\t\tconst session = ctx.context.session;\n\t\t\tconst adapter = getOrgAdapter(ctx.context, ctx.context.orgOptions);\n\t\t\tconst teams = await adapter.listTeamsByUser({\n\t\t\t\tuserId: session.user.id,\n\t\t\t});\n\n\t\t\treturn ctx.json(teams);\n\t\t},\n\t);\n\nconst listTeamMembersQuerySchema = z.optional(\n\tz.object({\n\t\tteamId: z.string().optional().meta({\n\t\t\tdescription:\n\t\t\t\t\"The team whose members we should return. If this is not provided the members of the current active team get returned.\",\n\t\t}),\n\t}),\n);\n\nexport const listTeamMembers = <O extends OrganizationOptions>(options: O) =>\n\tcreateAuthEndpoint(\n\t\t\"/organization/list-team-members\",\n\t\t{\n\t\t\tmethod: \"GET\",\n\t\t\tquery: listTeamMembersQuerySchema,\n\t\t\tmetadata: {\n\t\t\t\topenapi: {\n\t\t\t\t\tdescription: \"List the members of the given team.\",\n\t\t\t\t\tresponses: {\n\t\t\t\t\t\t\"200\": {\n\t\t\t\t\t\t\tdescription: \"Teams retrieved successfully\",\n\t\t\t\t\t\t\tcontent: {\n\t\t\t\t\t\t\t\t\"application/json\": {\n\t\t\t\t\t\t\t\t\tschema: {\n\t\t\t\t\t\t\t\t\t\ttype: \"array\",\n\t\t\t\t\t\t\t\t\t\titems: {\n\t\t\t\t\t\t\t\t\t\t\ttype: \"object\",\n\t\t\t\t\t\t\t\t\t\t\tdescription: \"The team member\",\n\t\t\t\t\t\t\t\t\t\t\tproperties: {\n\t\t\t\t\t\t\t\t\t\t\t\tid: {\n\t\t\t\t\t\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t\t\t\t\t\t\tdescription: \"Unique identifier of the team member\",\n\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\tuserId: {\n\t\t\t\t\t\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t\t\t\t\t\t\tdescription: \"The user ID of the team member\",\n\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\tteamId: {\n\t\t\t\t\t\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"The team ID of the team the team member is in\",\n\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\tcreatedAt: {\n\t\t\t\t\t\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t\t\t\t\t\t\tformat: \"date-time\",\n\t\t\t\t\t\t\t\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"Timestamp when the team member was created\",\n\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\trequired: [\"id\", \"userId\", \"teamId\", \"createdAt\"],\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\tdescription: \"Array of team member objects within the team\",\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\trequireHeaders: true,\n\t\t\tuse: [orgMiddleware, orgSessionMiddleware],\n\t\t},\n\t\tasync (ctx) => {\n\t\t\tconst session = ctx.context.session;\n\t\t\tconst adapter = getOrgAdapter(ctx.context, ctx.context.orgOptions);\n\t\t\tconst teamId = ctx.query?.teamId || session?.session.activeTeamId;\n\t\t\tif (!teamId) {\n\t\t\t\tthrow APIError.from(\n\t\t\t\t\t\"BAD_REQUEST\",\n\t\t\t\t\tORGANIZATION_ERROR_CODES.YOU_DO_NOT_HAVE_AN_ACTIVE_TEAM,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst member = await adapter.findTeamMember({\n\t\t\t\tuserId: session.user.id,\n\t\t\t\tteamId,\n\t\t\t});\n\n\t\t\tif (!member) {\n\t\t\t\tthrow APIError.from(\n\t\t\t\t\t\"BAD_REQUEST\",\n\t\t\t\t\tORGANIZATION_ERROR_CODES.USER_IS_NOT_A_MEMBER_OF_THE_TEAM,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst members = await adapter.listTeamMembers({\n\t\t\t\tteamId,\n\t\t\t});\n\t\t\treturn ctx.json(members);\n\t\t},\n\t);\n\nconst addTeamMemberBodySchema = z.object({\n\tteamId: z.string().meta({\n\t\tdescription: \"The team the user should be a member of.\",\n\t}),\n\n\tuserId: z.coerce.string().meta({\n\t\tdescription:\n\t\t\t\"The user Id which represents the user to be added as a member.\",\n\t}),\n\n\torganizationId: z\n\t\t.string()\n\t\t.meta({\n\t\t\tdescription:\n\t\t\t\t\"The organization ID which the team falls under. If not provided, it will default to the user's active organization.\",\n\t\t})\n\t\t.optional(),\n});\n\nexport const addTeamMember = <O extends OrganizationOptions>(options: O) =>\n\tcreateAuthEndpoint(\n\t\t\"/organization/add-team-member\",\n\t\t{\n\t\t\tmethod: \"POST\",\n\t\t\tbody: addTeamMemberBodySchema,\n\t\t\tmetadata: {\n\t\t\t\topenapi: {\n\t\t\t\t\tdescription: \"The newly created member\",\n\t\t\t\t\tresponses: {\n\t\t\t\t\t\t\"200\": {\n\t\t\t\t\t\t\tdescription: \"Team member created successfully\",\n\t\t\t\t\t\t\tcontent: {\n\t\t\t\t\t\t\t\t\"application/json\": {\n\t\t\t\t\t\t\t\t\tschema: {\n\t\t\t\t\t\t\t\t\t\ttype: \"object\",\n\t\t\t\t\t\t\t\t\t\tdescription: \"The team member\",\n\t\t\t\t\t\t\t\t\t\tproperties: {\n\t\t\t\t\t\t\t\t\t\t\tid: {\n\t\t\t\t\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t\t\t\t\t\tdescription: \"Unique identifier of the team member\",\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\tuserId: {\n\t\t\t\t\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t\t\t\t\t\tdescription: \"The user ID of the team member\",\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\tteamId: {\n\t\t\t\t\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\t\t\t\t\t\t\"The team ID of the team the team member is in\",\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\tcreatedAt: {\n\t\t\t\t\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t\t\t\t\t\tformat: \"date-time\",\n\t\t\t\t\t\t\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\t\t\t\t\t\t\"Timestamp when the team member was created\",\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\trequired: [\"id\", \"userId\", \"teamId\", \"createdAt\"],\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\trequireHeaders: true,\n\t\t\tuse: [orgMiddleware, orgSessionMiddleware],\n\t\t},\n\t\tasync (ctx) => {\n\t\t\tconst session = ctx.context.session;\n\t\t\tconst adapter = getOrgAdapter(ctx.context, ctx.context.orgOptions);\n\n\t\t\tconst organizationId =\n\t\t\t\tctx.body.organizationId || session.session.activeOrganizationId;\n\n\t\t\tif (!organizationId) {\n\t\t\t\tthrow APIError.from(\n\t\t\t\t\t\"BAD_REQUEST\",\n\t\t\t\t\tORGANIZATION_ERROR_CODES.NO_ACTIVE_ORGANIZATION,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst currentMember = await adapter.findMemberByOrgId({\n\t\t\t\tuserId: session.user.id,\n\t\t\t\torganizationId: organizationId,\n\t\t\t});\n\n\t\t\tif (!currentMember) {\n\t\t\t\tthrow APIError.from(\n\t\t\t\t\t\"BAD_REQUEST\",\n\t\t\t\t\tORGANIZATION_ERROR_CODES.USER_IS_NOT_A_MEMBER_OF_THE_ORGANIZATION,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst canUpdateMember = await hasPermission(\n\t\t\t\t{\n\t\t\t\t\trole: currentMember.role,\n\t\t\t\t\toptions: ctx.context.orgOptions,\n\t\t\t\t\tpermissions: {\n\t\t\t\t\t\tmember: [\"update\"],\n\t\t\t\t\t},\n\t\t\t\t\torganizationId: organizationId,\n\t\t\t\t},\n\t\t\t\tctx,\n\t\t\t);\n\n\t\t\tif (!canUpdateMember) {\n\t\t\t\tthrow APIError.from(\n\t\t\t\t\t\"FORBIDDEN\",\n\t\t\t\t\tORGANIZATION_ERROR_CODES.YOU_ARE_NOT_ALLOWED_TO_CREATE_A_NEW_TEAM_MEMBER,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst toBeAddedMember = await adapter.findMemberByOrgId({\n\t\t\t\tuserId: ctx.body.userId,\n\t\t\t\torganizationId: organizationId,\n\t\t\t});\n\n\t\t\tif (!toBeAddedMember) {\n\t\t\t\tthrow APIError.from(\n\t\t\t\t\t\"BAD_REQUEST\",\n\t\t\t\t\tORGANIZATION_ERROR_CODES.USER_IS_NOT_A_MEMBER_OF_THE_ORGANIZATION,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst team = await adapter.findTeamById({\n\t\t\t\tteamId: ctx.body.teamId,\n\t\t\t\torganizationId: organizationId,\n\t\t\t});\n\n\t\t\tif (!team) {\n\t\t\t\tthrow APIError.from(\n\t\t\t\t\t\"BAD_REQUEST\",\n\t\t\t\t\tORGANIZATION_ERROR_CODES.TEAM_NOT_FOUND,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst organization = await adapter.findOrganizationById(organizationId);\n\t\t\tif (!organization) {\n\t\t\t\tthrow APIError.from(\n\t\t\t\t\t\"BAD_REQUEST\",\n\t\t\t\t\tORGANIZATION_ERROR_CODES.ORGANIZATION_NOT_FOUND,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst userBeingAdded = await ctx.context.internalAdapter.findUserById(\n\t\t\t\tctx.body.userId,\n\t\t\t);\n\t\t\tif (!userBeingAdded) {\n\t\t\t\tthrow APIError.fromStatus(\"BAD_REQUEST\", {\n\t\t\t\t\tmessage: \"User not found\",\n\t\t\t\t});\n\t\t\t}\n\n\t\t\t// Run beforeAddTeamMember hook\n\t\t\tif (options?.organizationHooks?.beforeAddTeamMember) {\n\t\t\t\tconst response = await options?.organizationHooks.beforeAddTeamMember({\n\t\t\t\t\tteamMember: {\n\t\t\t\t\t\tteamId: ctx.body.teamId,\n\t\t\t\t\t\tuserId: ctx.body.userId,\n\t\t\t\t\t},\n\t\t\t\t\tteam,\n\t\t\t\t\tuser: userBeingAdded,\n\t\t\t\t\torganization,\n\t\t\t\t});\n\t\t\t\tif (response && typeof response === \"object\" && \"data\" in response) {\n\t\t\t\t\t// Allow the hook to modify the data\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst teamMember = await adapter.findOrCreateTeamMember({\n\t\t\t\tteamId: ctx.body.teamId,\n\t\t\t\tuserId: ctx.body.userId,\n\t\t\t});\n\n\t\t\t// Run afterAddTeamMember hook\n\t\t\tif (options?.organizationHooks?.afterAddTeamMember) {\n\t\t\t\tawait options?.organizationHooks.afterAddTeamMember({\n\t\t\t\t\tteamMember,\n\t\t\t\t\tteam,\n\t\t\t\t\tuser: userBeingAdded,\n\t\t\t\t\torganization,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\treturn ctx.json(teamMember);\n\t\t},\n\t);\n\nconst removeTeamMemberBodySchema = z.object({\n\tteamId: z.string().meta({\n\t\tdescription: \"The team the user should be removed from.\",\n\t}),\n\n\tuserId: z.coerce.string().meta({\n\t\tdescription: \"The user which should be removed from the team.\",\n\t}),\n\n\torganizationId: z\n\t\t.string()\n\t\t.meta({\n\t\t\tdescription:\n\t\t\t\t\"The organization ID which the team falls under. If not provided, it will default to the user's active organization.\",\n\t\t})\n\t\t.optional(),\n});\n\nexport const removeTeamMember = <O extends OrganizationOptions>(options: O) =>\n\tcreateAuthEndpoint(\n\t\t\"/organization/remove-team-member\",\n\t\t{\n\t\t\tmethod: \"POST\",\n\t\t\tbody: removeTeamMemberBodySchema,\n\t\t\tmetadata: {\n\t\t\t\topenapi: {\n\t\t\t\t\tdescription: \"Remove a member from a team\",\n\t\t\t\t\tresponses: {\n\t\t\t\t\t\t\"200\": {\n\t\t\t\t\t\t\tdescription: \"Team member removed successfully\",\n\t\t\t\t\t\t\tcontent: {\n\t\t\t\t\t\t\t\t\"application/json\": {\n\t\t\t\t\t\t\t\t\tschema: {\n\t\t\t\t\t\t\t\t\t\ttype: \"object\",\n\t\t\t\t\t\t\t\t\t\tproperties: {\n\t\t\t\t\t\t\t\t\t\t\tmessage: {\n\t\t\t\t\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\t\t\t\t\t\t\"Confirmation message indicating successful removal\",\n\t\t\t\t\t\t\t\t\t\t\t\tenum: [\"Team member removed successfully.\"],\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\trequired: [\"message\"],\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\trequireHeaders: true,\n\t\t\tuse: [orgMiddleware, orgSessionMiddleware],\n\t\t},\n\t\tasync (ctx) => {\n\t\t\tconst session = ctx.context.session;\n\t\t\tconst adapter = getOrgAdapter(ctx.context, ctx.context.orgOptions);\n\n\t\t\tconst organizationId =\n\t\t\t\tctx.body.organizationId || session.session.activeOrganizationId;\n\n\t\t\tif (!organizationId) {\n\t\t\t\tthrow APIError.from(\n\t\t\t\t\t\"BAD_REQUEST\",\n\t\t\t\t\tORGANIZATION_ERROR_CODES.NO_ACTIVE_ORGANIZATION,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst currentMember = await adapter.findMemberByOrgId({\n\t\t\t\tuserId: session.user.id,\n\t\t\t\torganizationId: organizationId,\n\t\t\t});\n\n\t\t\tif (!currentMember) {\n\t\t\t\tthrow APIError.from(\n\t\t\t\t\t\"BAD_REQUEST\",\n\t\t\t\t\tORGANIZATION_ERROR_CODES.USER_IS_NOT_A_MEMBER_OF_THE_ORGANIZATION,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst canDeleteMember = await hasPermission(\n\t\t\t\t{\n\t\t\t\t\trole: currentMember.role,\n\t\t\t\t\toptions: ctx.context.orgOptions,\n\t\t\t\t\tpermissions: {\n\t\t\t\t\t\tmember: [\"delete\"],\n\t\t\t\t\t},\n\t\t\t\t\torganizationId: organizationId,\n\t\t\t\t},\n\t\t\t\tctx,\n\t\t\t);\n\n\t\t\tif (!canDeleteMember) {\n\t\t\t\tthrow APIError.from(\n\t\t\t\t\t\"FORBIDDEN\",\n\t\t\t\t\tORGANIZATION_ERROR_CODES.YOU_ARE_NOT_ALLOWED_TO_REMOVE_A_TEAM_MEMBER,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst toBeAddedMember = await adapter.findMemberByOrgId({\n\t\t\t\tuserId: ctx.body.userId,\n\t\t\t\torganizationId: organizationId,\n\t\t\t});\n\n\t\t\tif (!toBeAddedMember) {\n\t\t\t\tthrow APIError.from(\n\t\t\t\t\t\"BAD_REQUEST\",\n\t\t\t\t\tORGANIZATION_ERROR_CODES.USER_IS_NOT_A_MEMBER_OF_THE_ORGANIZATION,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst team = await adapter.findTeamById({\n\t\t\t\tteamId: ctx.body.teamId,\n\t\t\t\torganizationId: organizationId,\n\t\t\t});\n\n\t\t\tif (!team) {\n\t\t\t\tthrow APIError.from(\n\t\t\t\t\t\"BAD_REQUEST\",\n\t\t\t\t\tORGANIZATION_ERROR_CODES.TEAM_NOT_FOUND,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst organization = await adapter.findOrganizationById(organizationId);\n\t\t\tif (!organization) {\n\t\t\t\tthrow APIError.from(\n\t\t\t\t\t\"BAD_REQUEST\",\n\t\t\t\t\tORGANIZATION_ERROR_CODES.ORGANIZATION_NOT_FOUND,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst userBeingRemoved = await ctx.context.internalAdapter.findUserById(\n\t\t\t\tctx.body.userId,\n\t\t\t);\n\t\t\tif (!userBeingRemoved) {\n\t\t\t\tthrow APIError.fromStatus(\"BAD_REQUEST\", {\n\t\t\t\t\tmessage: \"User not found\",\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst teamMember = await adapter.findTeamMember({\n\t\t\t\tteamId: ctx.body.teamId,\n\t\t\t\tuserId: ctx.body.userId,\n\t\t\t});\n\n\t\t\tif (!teamMember) {\n\t\t\t\tthrow APIError.from(\n\t\t\t\t\t\"BAD_REQUEST\",\n\t\t\t\t\tORGANIZATION_ERROR_CODES.USER_IS_NOT_A_MEMBER_OF_THE_TEAM,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t// Run beforeRemoveTeamMember hook\n\t\t\tif (options?.organizationHooks?.beforeRemoveTeamMember) {\n\t\t\t\tawait options?.organizationHooks.beforeRemoveTeamMember({\n\t\t\t\t\tteamMember,\n\t\t\t\t\tteam,\n\t\t\t\t\tuser: userBeingRemoved,\n\t\t\t\t\torganization,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tawait adapter.removeTeamMember({\n\t\t\t\tteamId: ctx.body.teamId,\n\t\t\t\tuserId: ctx.body.userId,\n\t\t\t});\n\n\t\t\t// Run afterRemoveTeamMember hook\n\t\t\tif (options?.organizationHooks?.afterRemoveTeamMember) {\n\t\t\t\tawait options?.organizationHooks.afterRemoveTeamMember({\n\t\t\t\t\tteamMember,\n\t\t\t\t\tteam,\n\t\t\t\t\tuser: userBeingRemoved,\n\t\t\t\t\torganization,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\treturn ctx.json({ message: \"Team member removed successfully.\" });\n\t\t},\n\t);\n"],"mappings":";;;;;;;;;;;;;;;AAeA,MAAM,iBAAiB,EAAE,OAAO;CAC/B,MAAM,EAAE,QAAQ,CAAC,KAAK,EACrB,aAAa,yCACb,CAAC;CACF,gBAAgB,EACd,QAAQ,CACR,KAAK,EACL,aACC,uHACD,CAAC,CACD,UAAU;CACZ,CAAC;AAEF,MAAa,cAA6C,YAAe;CACxE,MAAM,yBAAyB,YAAY;EAC1C,QAAQ,SAAS,QAAQ,MAAM,oBAAoB,EAAE;EACrD,cAAc;EACd,CAAC;AACF,QAAO,mBACN,6BACA;EACC,QAAQ;EACR,MAAM,EAAE,OAAO;GACd,GAAG,eAAe;GAClB,GAAG,uBAAuB;GAC1B,CAAC;EACF,KAAK,CAAC,cAAc;EACpB,UAAU;GACT,QAAQ,EACP,MAAM,EAAE,EAER;GACD,SAAS;IACR,aAAa;IACb,WAAW,EACV,OAAO;KACN,aAAa;KACb,SAAS,EACR,oBAAoB,EACnB,QAAQ;MACP,MAAM;MACN,YAAY;OACX,IAAI;QACH,MAAM;QACN,aAAa;QACb;OACD,MA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EACD,IACA,CAGA,OAAM,SAAS,KACd,aACA,yBAAyB,4CACzB;AAQF,KAAI,CALoB,MAAM,QAAQ,kBAAkB;EACvD,QAAQ,IAAI,KAAK;EACD;EAChB,CAAC,CAGD,OAAM,SAAS,KACd,eACA,yBAAyB,yCACzB;CAGF,MAAM,OAAO,MAAM,QAAQ,aAAa;EACvC,QAAQ,IAAI,KAAK;EACD;EAChB,CAAC;AAEF,KAAI,CAAC,KACJ,OAAM,SAAS,KACd,eACA,yBAAyB,eACzB;CAGF,MAAM,eAAe,MAAM,QAAQ,qBAAqB,eAAe;AACvE,KAAI,CAAC,aACJ,OAAM,SAAS,KACd,eACA,yBAAyB,uBACzB;CAGF,MAAM,mBAAmB,MAAM,IAAI,QAAQ,gBAAgB,aAC1D,IAAI,KAAK,OACT;AACD,KAAI,CAAC,iBACJ,OAAM,SAAS,WAAW,eAAe,EACxC,SAAS,kBACT,CAAC;CAGH,MAAM,aAAa,MAAM,QAAQ,eAAe;EAC/C,QAAQ,IAAI,KAAK;EACjB,QAAQ,IAAI,KAAK;EACjB,CAAC;AAEF,KAAI,CAAC,WACJ,OAAM,SAAS,KACd,eACA,yBAAyB,iCACzB;AAIF,KAAI,SAAS,mBAAmB,uBAC/B,OAAM,SAAS,kBAAkB,uBAAuB;EACvD;EACA;EACA,MAAM;EACN;EACA,CAAC;AAGH,OAAM,QAAQ,iBAAiB;EAC9B,QAAQ,IAAI,KAAK;EACjB,QAAQ,IAAI,KAAK;EACjB,CAAC;AAGF,KAAI,SAAS,mBAAmB,sBAC/B,OAAM,SAAS,kBAAkB,sBAAsB;EACtD;EACA;EACA,MAAM;EACN;EACA,CAAC;AAGH,QAAO,IAAI,KAAK,EAAE,SAAS,qCAAqC,CAAC;EAElE"}
@@ -1,5 +1,4 @@
1
1
  import { FieldAttributeToObject, RemoveFieldsWithReturnedFalse } from "../../db/field.mjs";
2
- import "../../db/index.mjs";
3
2
  import { OrganizationOptions } from "./types.mjs";
4
3
  import { BetterAuthPluginDBSchema, DBFieldAttribute } from "@better-auth/core/db";
5
4
  import { Prettify } from "better-call";
@@ -1,7 +1,5 @@
1
1
  import { Session as Session$1, User as User$1 } from "../../types/models.mjs";
2
- import "../../types/index.mjs";
3
2
  import { AccessControl, Role } from "../access/types.mjs";
4
- import "../access/index.mjs";
5
3
  import { Invitation, Member, Organization, OrganizationRole, Team, TeamMember } from "./schema.mjs";
6
4
  import { AuthContext, Awaitable, GenericEndpointContext } from "@better-auth/core";
7
5
  import { DBFieldAttribute } from "@better-auth/core/db";
@@ -1,6 +1,5 @@
1
1
  import { User } from "../../types/models.mjs";
2
2
  import { InferOptionSchema } from "../../types/plugins.mjs";
3
- import "../../types/index.mjs";
4
3
  import { schema } from "./schema.mjs";
5
4
  import { Awaitable, GenericEndpointContext } from "@better-auth/core";
6
5
 
@@ -1,5 +1,4 @@
1
1
  import { InferOptionSchema } from "../../types/plugins.mjs";
2
- import "../../types/index.mjs";
3
2
  import { WalletAddressSchema, schema } from "./schema.mjs";
4
3
  import { ENSLookupArgs, ENSLookupResult, SIWEVerifyMessageArgs } from "./types.mjs";
5
4
  import * as better_call0 from "better-call";
@@ -1,6 +1,4 @@
1
1
  import { Session, User } from "../../types/models.mjs";
2
- import "../../types/index.mjs";
3
-
4
2
  //#region src/plugins/test-utils/types.d.ts
5
3
  interface TestUtilsOptions {
6
4
  /** Capture OTPs in memory when created (doesn't prevent sending) */
@@ -9,6 +9,13 @@ import * as _better_fetch_fetch0 from "@better-fetch/fetch";
9
9
 
10
10
  //#region src/plugins/two-factor/client.d.ts
11
11
  declare const twoFactorClient: (options?: {
12
+ /**
13
+ * the page to redirect if a user needs to verify
14
+ * their two factor
15
+ *
16
+ * @warning This causes a full page reload when used.
17
+ */
18
+ twoFactorPage?: string;
12
19
  /**
13
20
  * a redirect function to call if a user needs to verify
14
21
  * their two factor
@@ -24,7 +24,11 @@ const twoFactorClient = (options) => {
24
24
  name: "two-factor",
25
25
  hooks: { async onSuccess(context) {
26
26
  if (context.data?.twoFactorRedirect) {
27
- if (options?.onTwoFactorRedirect) await options.onTwoFactorRedirect();
27
+ if (options?.onTwoFactorRedirect) {
28
+ await options.onTwoFactorRedirect();
29
+ return;
30
+ }
31
+ if (options?.twoFactorPage && typeof window !== "undefined") window.location.href = options.twoFactorPage;
28
32
  }
29
33
  } }
30
34
  }],
@@ -1 +1 @@
1
- {"version":3,"file":"client.mjs","names":[],"sources":["../../../src/plugins/two-factor/client.ts"],"sourcesContent":["import type { BetterAuthClientPlugin } from \"@better-auth/core\";\nimport type { twoFactor as twoFa } from \".\";\nimport { TWO_FACTOR_ERROR_CODES } from \"./error-code\";\n\nexport * from \"./error-code\";\n\nexport const twoFactorClient = (\n\toptions?:\n\t\t| {\n\t\t\t\t/**\n\t\t\t\t * a redirect function to call if a user needs to verify\n\t\t\t\t * their two factor\n\t\t\t\t */\n\t\t\t\tonTwoFactorRedirect?: () => void | Promise<void>;\n\t\t }\n\t\t| undefined,\n) => {\n\treturn {\n\t\tid: \"two-factor\",\n\t\t$InferServerPlugin: {} as ReturnType<typeof twoFa>,\n\t\tatomListeners: [\n\t\t\t{\n\t\t\t\tmatcher: (path) => path.startsWith(\"/two-factor/\"),\n\t\t\t\tsignal: \"$sessionSignal\",\n\t\t\t},\n\t\t],\n\t\tpathMethods: {\n\t\t\t\"/two-factor/disable\": \"POST\",\n\t\t\t\"/two-factor/enable\": \"POST\",\n\t\t\t\"/two-factor/send-otp\": \"POST\",\n\t\t\t\"/two-factor/generate-backup-codes\": \"POST\",\n\t\t\t\"/two-factor/get-totp-uri\": \"POST\",\n\t\t\t\"/two-factor/verify-totp\": \"POST\",\n\t\t\t\"/two-factor/verify-otp\": \"POST\",\n\t\t\t\"/two-factor/verify-backup-code\": \"POST\",\n\t\t},\n\t\tfetchPlugins: [\n\t\t\t{\n\t\t\t\tid: \"two-factor\",\n\t\t\t\tname: \"two-factor\",\n\t\t\t\thooks: {\n\t\t\t\t\tasync onSuccess(context) {\n\t\t\t\t\t\tif (context.data?.twoFactorRedirect) {\n\t\t\t\t\t\t\tif (options?.onTwoFactorRedirect) {\n\t\t\t\t\t\t\t\tawait options.onTwoFactorRedirect();\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t],\n\t\t$ERROR_CODES: TWO_FACTOR_ERROR_CODES,\n\t} satisfies BetterAuthClientPlugin;\n};\n\nexport type * from \"./backup-codes\";\nexport type * from \"./otp\";\nexport type * from \"./totp\";\nexport type * from \"./types\";\n"],"mappings":";;;AAMA,MAAa,mBACZ,YASI;AACJ,QAAO;EACN,IAAI;EACJ,oBAAoB,EAAE;EACtB,eAAe,CACd;GACC,UAAU,SAAS,KAAK,WAAW,eAAe;GAClD,QAAQ;GACR,CACD;EACD,aAAa;GACZ,uBAAuB;GACvB,sBAAsB;GACtB,wBAAwB;GACxB,qCAAqC;GACrC,4BAA4B;GAC5B,2BAA2B;GAC3B,0BAA0B;GAC1B,kCAAkC;GAClC;EACD,cAAc,CACb;GACC,IAAI;GACJ,MAAM;GACN,OAAO,EACN,MAAM,UAAU,SAAS;AACxB,QAAI,QAAQ,MAAM,mBACjB;SAAI,SAAS,oBACZ,OAAM,QAAQ,qBAAqB;;MAItC;GACD,CACD;EACD,cAAc;EACd"}
1
+ {"version":3,"file":"client.mjs","names":[],"sources":["../../../src/plugins/two-factor/client.ts"],"sourcesContent":["import type { BetterAuthClientPlugin } from \"@better-auth/core\";\nimport type { twoFactor as twoFa } from \".\";\nimport { TWO_FACTOR_ERROR_CODES } from \"./error-code\";\n\nexport * from \"./error-code\";\n\nexport const twoFactorClient = (\n\toptions?:\n\t\t| {\n\t\t\t\t/**\n\t\t\t\t * the page to redirect if a user needs to verify\n\t\t\t\t * their two factor\n\t\t\t\t *\n\t\t\t\t * @warning This causes a full page reload when used.\n\t\t\t\t */\n\t\t\t\ttwoFactorPage?: string;\n\t\t\t\t/**\n\t\t\t\t * a redirect function to call if a user needs to verify\n\t\t\t\t * their two factor\n\t\t\t\t */\n\t\t\t\tonTwoFactorRedirect?: () => void | Promise<void>;\n\t\t }\n\t\t| undefined,\n) => {\n\treturn {\n\t\tid: \"two-factor\",\n\t\t$InferServerPlugin: {} as ReturnType<typeof twoFa>,\n\t\tatomListeners: [\n\t\t\t{\n\t\t\t\tmatcher: (path) => path.startsWith(\"/two-factor/\"),\n\t\t\t\tsignal: \"$sessionSignal\",\n\t\t\t},\n\t\t],\n\t\tpathMethods: {\n\t\t\t\"/two-factor/disable\": \"POST\",\n\t\t\t\"/two-factor/enable\": \"POST\",\n\t\t\t\"/two-factor/send-otp\": \"POST\",\n\t\t\t\"/two-factor/generate-backup-codes\": \"POST\",\n\t\t\t\"/two-factor/get-totp-uri\": \"POST\",\n\t\t\t\"/two-factor/verify-totp\": \"POST\",\n\t\t\t\"/two-factor/verify-otp\": \"POST\",\n\t\t\t\"/two-factor/verify-backup-code\": \"POST\",\n\t\t},\n\t\tfetchPlugins: [\n\t\t\t{\n\t\t\t\tid: \"two-factor\",\n\t\t\t\tname: \"two-factor\",\n\t\t\t\thooks: {\n\t\t\t\t\tasync onSuccess(context) {\n\t\t\t\t\t\tif (context.data?.twoFactorRedirect) {\n\t\t\t\t\t\t\tif (options?.onTwoFactorRedirect) {\n\t\t\t\t\t\t\t\tawait options.onTwoFactorRedirect();\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t// fallback for when `onTwoFactorRedirect` is not used and only `twoFactorPage` is provided\n\t\t\t\t\t\t\tif (options?.twoFactorPage && typeof window !== \"undefined\") {\n\t\t\t\t\t\t\t\twindow.location.href = options.twoFactorPage;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t],\n\t\t$ERROR_CODES: TWO_FACTOR_ERROR_CODES,\n\t} satisfies BetterAuthClientPlugin;\n};\n\nexport type * from \"./backup-codes\";\nexport type * from \"./otp\";\nexport type * from \"./totp\";\nexport type * from \"./types\";\n"],"mappings":";;;AAMA,MAAa,mBACZ,YAgBI;AACJ,QAAO;EACN,IAAI;EACJ,oBAAoB,EAAE;EACtB,eAAe,CACd;GACC,UAAU,SAAS,KAAK,WAAW,eAAe;GAClD,QAAQ;GACR,CACD;EACD,aAAa;GACZ,uBAAuB;GACvB,sBAAsB;GACtB,wBAAwB;GACxB,qCAAqC;GACrC,4BAA4B;GAC5B,2BAA2B;GAC3B,0BAA0B;GAC1B,kCAAkC;GAClC;EACD,cAAc,CACb;GACC,IAAI;GACJ,MAAM;GACN,OAAO,EACN,MAAM,UAAU,SAAS;AACxB,QAAI,QAAQ,MAAM,mBAAmB;AACpC,SAAI,SAAS,qBAAqB;AACjC,YAAM,QAAQ,qBAAqB;AACnC;;AAID,SAAI,SAAS,iBAAiB,OAAO,WAAW,YAC/C,QAAO,SAAS,OAAO,QAAQ;;MAIlC;GACD,CACD;EACD,cAAc;EACd"}
@@ -1,6 +1,5 @@
1
1
  import { User } from "../../types/models.mjs";
2
2
  import { InferOptionSchema } from "../../types/plugins.mjs";
3
- import "../../types/index.mjs";
4
3
  import { BackupCodeOptions } from "./backup-codes/index.mjs";
5
4
  import { OTPOptions } from "./otp/index.mjs";
6
5
  import { schema } from "./schema.mjs";