better-auth 1.4.18 → 1.4.19

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 (118) hide show
  1. package/dist/adapters/drizzle-adapter/drizzle-adapter.mjs +37 -5
  2. package/dist/adapters/drizzle-adapter/drizzle-adapter.mjs.map +1 -1
  3. package/dist/adapters/kysely-adapter/kysely-adapter.mjs +13 -3
  4. package/dist/adapters/kysely-adapter/kysely-adapter.mjs.map +1 -1
  5. package/dist/adapters/memory-adapter/memory-adapter.mjs +21 -17
  6. package/dist/adapters/memory-adapter/memory-adapter.mjs.map +1 -1
  7. package/dist/adapters/mongodb-adapter/mongodb-adapter.mjs +12 -1
  8. package/dist/adapters/mongodb-adapter/mongodb-adapter.mjs.map +1 -1
  9. package/dist/adapters/prisma-adapter/prisma-adapter.mjs +2 -2
  10. package/dist/adapters/prisma-adapter/prisma-adapter.mjs.map +1 -1
  11. package/dist/api/index.d.mts +407 -407
  12. package/dist/api/routes/account.d.mts +11 -11
  13. package/dist/api/routes/account.mjs +1 -1
  14. package/dist/api/routes/account.mjs.map +1 -1
  15. package/dist/api/routes/callback.d.mts +2 -2
  16. package/dist/api/routes/callback.mjs +1 -1
  17. package/dist/api/routes/callback.mjs.map +1 -1
  18. package/dist/api/routes/email-verification.d.mts +4 -4
  19. package/dist/api/routes/email-verification.mjs +1 -1
  20. package/dist/api/routes/email-verification.mjs.map +1 -1
  21. package/dist/api/routes/error.d.mts +2 -2
  22. package/dist/api/routes/ok.d.mts +2 -2
  23. package/dist/api/routes/password.d.mts +7 -7
  24. package/dist/api/routes/session.d.mts +14 -14
  25. package/dist/api/routes/sign-in.d.mts +4 -4
  26. package/dist/api/routes/sign-out.d.mts +2 -2
  27. package/dist/api/routes/sign-up.d.mts +3 -3
  28. package/dist/api/routes/update-user.d.mts +13 -13
  29. package/dist/api/routes/update-user.mjs +1 -1
  30. package/dist/api/routes/update-user.mjs.map +1 -1
  31. package/dist/client/react/index.d.mts +13 -13
  32. package/dist/client/svelte/index.d.mts +15 -15
  33. package/dist/client/vanilla.d.mts +15 -15
  34. package/dist/client/vue/index.d.mts +15 -15
  35. package/dist/context/create-context.mjs +1 -1
  36. package/dist/context/create-context.mjs.map +1 -1
  37. package/dist/cookies/index.d.mts +6 -6
  38. package/dist/cookies/index.mjs +5 -8
  39. package/dist/cookies/index.mjs.map +1 -1
  40. package/dist/db/field.d.mts +10 -10
  41. package/dist/db/field.mjs.map +1 -1
  42. package/dist/db/internal-adapter.mjs +1 -1
  43. package/dist/db/internal-adapter.mjs.map +1 -1
  44. package/dist/integrations/next-js.d.mts +4 -4
  45. package/dist/integrations/svelte-kit.d.mts +2 -2
  46. package/dist/integrations/tanstack-start-solid.d.mts +4 -4
  47. package/dist/integrations/tanstack-start.d.mts +4 -4
  48. package/dist/plugins/access/types.d.mts +1 -1
  49. package/dist/plugins/admin/admin.d.mts +114 -119
  50. package/dist/plugins/admin/admin.mjs +1 -1
  51. package/dist/plugins/admin/admin.mjs.map +1 -1
  52. package/dist/plugins/admin/routes.mjs +1 -1
  53. package/dist/plugins/admin/routes.mjs.map +1 -1
  54. package/dist/plugins/anonymous/index.d.mts +7 -7
  55. package/dist/plugins/api-key/index.d.mts +95 -80
  56. package/dist/plugins/api-key/routes/verify-api-key.mjs +1 -0
  57. package/dist/plugins/api-key/routes/verify-api-key.mjs.map +1 -1
  58. package/dist/plugins/bearer/index.d.mts +6 -6
  59. package/dist/plugins/captcha/index.d.mts +2 -2
  60. package/dist/plugins/custom-session/index.d.mts +5 -5
  61. package/dist/plugins/custom-session/index.mjs +13 -5
  62. package/dist/plugins/custom-session/index.mjs.map +1 -1
  63. package/dist/plugins/device-authorization/index.d.mts +6 -6
  64. package/dist/plugins/email-otp/index.d.mts +16 -16
  65. package/dist/plugins/email-otp/routes.mjs +1 -1
  66. package/dist/plugins/email-otp/routes.mjs.map +1 -1
  67. package/dist/plugins/generic-oauth/error-codes.mjs +3 -1
  68. package/dist/plugins/generic-oauth/error-codes.mjs.map +1 -1
  69. package/dist/plugins/generic-oauth/index.d.mts +32 -29
  70. package/dist/plugins/generic-oauth/index.mjs +8 -0
  71. package/dist/plugins/generic-oauth/index.mjs.map +1 -1
  72. package/dist/plugins/generic-oauth/routes.mjs +19 -2
  73. package/dist/plugins/generic-oauth/routes.mjs.map +1 -1
  74. package/dist/plugins/generic-oauth/types.d.mts +14 -0
  75. package/dist/plugins/haveibeenpwned/index.d.mts +3 -3
  76. package/dist/plugins/jwt/client.d.mts +2 -2
  77. package/dist/plugins/jwt/index.d.mts +9 -9
  78. package/dist/plugins/last-login-method/index.d.mts +4 -4
  79. package/dist/plugins/magic-link/index.d.mts +4 -4
  80. package/dist/plugins/mcp/authorize.mjs +1 -1
  81. package/dist/plugins/mcp/authorize.mjs.map +1 -1
  82. package/dist/plugins/mcp/index.d.mts +10 -10
  83. package/dist/plugins/multi-session/index.d.mts +9 -9
  84. package/dist/plugins/oauth-proxy/index.d.mts +8 -8
  85. package/dist/plugins/oidc-provider/authorize.mjs +1 -1
  86. package/dist/plugins/oidc-provider/authorize.mjs.map +1 -1
  87. package/dist/plugins/oidc-provider/index.d.mts +15 -15
  88. package/dist/plugins/one-tap/client.d.mts +5 -5
  89. package/dist/plugins/one-tap/index.d.mts +2 -2
  90. package/dist/plugins/one-time-token/index.d.mts +5 -5
  91. package/dist/plugins/open-api/index.d.mts +3 -3
  92. package/dist/plugins/organization/client.d.mts +9 -9
  93. package/dist/plugins/organization/error-codes.d.mts +1 -0
  94. package/dist/plugins/organization/error-codes.mjs +2 -1
  95. package/dist/plugins/organization/error-codes.mjs.map +1 -1
  96. package/dist/plugins/organization/organization.d.mts +4 -4
  97. package/dist/plugins/organization/routes/crud-access-control.d.mts +22 -22
  98. package/dist/plugins/organization/routes/crud-access-control.mjs +22 -0
  99. package/dist/plugins/organization/routes/crud-access-control.mjs.map +1 -1
  100. package/dist/plugins/organization/routes/crud-invites.d.mts +70 -70
  101. package/dist/plugins/organization/routes/crud-invites.mjs +0 -4
  102. package/dist/plugins/organization/routes/crud-invites.mjs.map +1 -1
  103. package/dist/plugins/organization/routes/crud-members.d.mts +67 -67
  104. package/dist/plugins/organization/routes/crud-org.d.mts +59 -59
  105. package/dist/plugins/organization/routes/crud-team.d.mts +79 -79
  106. package/dist/plugins/phone-number/index.d.mts +33 -33
  107. package/dist/plugins/phone-number/routes.mjs +6 -2
  108. package/dist/plugins/phone-number/routes.mjs.map +1 -1
  109. package/dist/plugins/siwe/index.d.mts +3 -3
  110. package/dist/plugins/two-factor/backup-codes/index.d.mts +5 -5
  111. package/dist/plugins/two-factor/client.d.mts +2 -2
  112. package/dist/plugins/two-factor/index.d.mts +18 -18
  113. package/dist/plugins/two-factor/otp/index.d.mts +3 -3
  114. package/dist/plugins/two-factor/totp/index.d.mts +5 -5
  115. package/dist/plugins/username/index.d.mts +12 -12
  116. package/dist/plugins/username/schema.d.mts +3 -3
  117. package/dist/test-utils/test-instance.d.mts +1242 -1242
  118. package/package.json +3 -3
@@ -1 +1 @@
1
- {"version":3,"file":"crud-access-control.mjs","names":["condition: Where","updateData: Partial<OrganizationRole>","hasNecessaryPermissions: {\n\t\tresource: { [x: string]: string[] };\n\t\thasPermission: boolean;\n\t}[]","errorMessage: string"],"sources":["../../../../src/plugins/organization/routes/crud-access-control.ts"],"sourcesContent":["import type { GenericEndpointContext } from \"@better-auth/core\";\nimport { createAuthEndpoint } from \"@better-auth/core/api\";\nimport type { Where } from \"@better-auth/core/db/adapter\";\nimport * as z from \"zod\";\nimport { APIError } from \"../../../api\";\nimport type { InferAdditionalFieldsFromPluginOptions } from \"../../../db\";\nimport { toZodSchema } from \"../../../db\";\nimport type { User } from \"../../../types\";\nimport type { AccessControl } from \"../../access\";\nimport { orgSessionMiddleware } from \"../call\";\nimport { ORGANIZATION_ERROR_CODES } from \"../error-codes\";\nimport { hasPermission } from \"../has-permission\";\nimport type { Member, OrganizationRole } from \"../schema\";\nimport type { OrganizationOptions } from \"../types\";\n\ntype IsExactlyEmptyObject<T> = keyof T extends never // no keys\n\t? T extends {} // is assignable to {}\n\t\t? {} extends T\n\t\t\t? true\n\t\t\t: false // and {} is assignable to it\n\t\t: false\n\t: false;\n\nconst normalizeRoleName = (role: string) => role.toLowerCase();\nconst DEFAULT_MAXIMUM_ROLES_PER_ORGANIZATION = Number.POSITIVE_INFINITY;\n\nconst getAdditionalFields = <\n\tO extends OrganizationOptions,\n\tAllPartial extends boolean = false,\n>(\n\toptions: O,\n\tshouldBePartial: AllPartial = false as AllPartial,\n) => {\n\tconst additionalFields =\n\t\toptions?.schema?.organizationRole?.additionalFields || {};\n\tif (shouldBePartial) {\n\t\tfor (const key in additionalFields) {\n\t\t\tadditionalFields[key]!.required = false;\n\t\t}\n\t}\n\tconst additionalFieldsSchema = toZodSchema({\n\t\tfields: additionalFields,\n\t\tisClientSide: true,\n\t});\n\ttype AdditionalFields = AllPartial extends true\n\t\t? Partial<InferAdditionalFieldsFromPluginOptions<\"organizationRole\", O>>\n\t\t: InferAdditionalFieldsFromPluginOptions<\"organizationRole\", O>;\n\ttype ReturnAdditionalFields = InferAdditionalFieldsFromPluginOptions<\n\t\t\"organizationRole\",\n\t\tO,\n\t\tfalse\n\t>;\n\n\treturn {\n\t\tadditionalFieldsSchema,\n\t\t$AdditionalFields: {} as AdditionalFields,\n\t\t$ReturnAdditionalFields: {} as ReturnAdditionalFields,\n\t};\n};\n\nconst baseCreateOrgRoleSchema = z.object({\n\torganizationId: z.string().optional().meta({\n\t\tdescription:\n\t\t\t\"The id of the organization to create the role in. If not provided, the user's active organization will be used.\",\n\t}),\n\trole: z.string().meta({\n\t\tdescription: \"The name of the role to create\",\n\t}),\n\tpermission: z.record(z.string(), z.array(z.string())).meta({\n\t\tdescription: \"The permission to assign to the role\",\n\t}),\n});\n\nexport const createOrgRole = <O extends OrganizationOptions>(options: O) => {\n\tconst { additionalFieldsSchema, $AdditionalFields, $ReturnAdditionalFields } =\n\t\tgetAdditionalFields<O>(options, false);\n\ttype AdditionalFields = typeof $AdditionalFields;\n\ttype ReturnAdditionalFields = typeof $ReturnAdditionalFields;\n\n\treturn createAuthEndpoint(\n\t\t\"/organization/create-role\",\n\t\t{\n\t\t\tmethod: \"POST\",\n\t\t\tbody: baseCreateOrgRoleSchema.safeExtend({\n\t\t\t\tadditionalFields: z\n\t\t\t\t\t.object({ ...additionalFieldsSchema.shape })\n\t\t\t\t\t.optional(),\n\t\t\t}),\n\t\t\tmetadata: {\n\t\t\t\t$Infer: {\n\t\t\t\t\tbody: {} as {\n\t\t\t\t\t\torganizationId?: string | undefined;\n\t\t\t\t\t\trole: string;\n\t\t\t\t\t\tpermission: Record<string, string[]>;\n\t\t\t\t\t} & (IsExactlyEmptyObject<AdditionalFields> extends true\n\t\t\t\t\t\t? { additionalFields?: {} | undefined }\n\t\t\t\t\t\t: { additionalFields: AdditionalFields }),\n\t\t\t\t},\n\t\t\t},\n\t\t\trequireHeaders: true,\n\t\t\tuse: [orgSessionMiddleware],\n\t\t},\n\t\tasync (ctx) => {\n\t\t\tconst { session, user } = ctx.context.session;\n\t\t\tlet roleName = ctx.body.role;\n\t\t\tconst permission = ctx.body.permission;\n\t\t\tconst additionalFields = ctx.body.additionalFields;\n\n\t\t\tconst ac = options.ac;\n\t\t\tif (!ac) {\n\t\t\t\tctx.context.logger.error(\n\t\t\t\t\t`[Dynamic Access Control] The organization plugin is missing a pre-defined ac instance.`,\n\t\t\t\t\t`\\nPlease refer to the documentation here: https://better-auth.com/docs/plugins/organization#dynamic-access-control`,\n\t\t\t\t);\n\t\t\t\tthrow new APIError(\"NOT_IMPLEMENTED\", {\n\t\t\t\t\tmessage: ORGANIZATION_ERROR_CODES.MISSING_AC_INSTANCE,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\t// Get the organization id where the role will be created.\n\t\t\t// We can verify if the org id is valid and associated with the user in the next step when we try to find the member.\n\t\t\tconst organizationId =\n\t\t\t\tctx.body.organizationId ?? session.activeOrganizationId;\n\t\t\tif (!organizationId) {\n\t\t\t\tctx.context.logger.error(\n\t\t\t\t\t`[Dynamic Access Control] The session is missing an active organization id to create a role. Either set an active org id, or pass an organizationId in the request body.`,\n\t\t\t\t);\n\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\tmessage:\n\t\t\t\t\t\tORGANIZATION_ERROR_CODES.YOU_MUST_BE_IN_AN_ORGANIZATION_TO_CREATE_A_ROLE,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\troleName = normalizeRoleName(roleName);\n\n\t\t\tawait checkIfRoleNameIsTakenByPreDefinedRole({\n\t\t\t\trole: roleName,\n\t\t\t\torganizationId,\n\t\t\t\toptions,\n\t\t\t\tctx,\n\t\t\t});\n\n\t\t\t// Get the user's role associated with the organization.\n\t\t\t// This also serves as a check to ensure the org id is valid.\n\t\t\tconst member = await ctx.context.adapter.findOne<Member>({\n\t\t\t\tmodel: \"member\",\n\t\t\t\twhere: [\n\t\t\t\t\t{\n\t\t\t\t\t\tfield: \"organizationId\",\n\t\t\t\t\t\tvalue: organizationId,\n\t\t\t\t\t\toperator: \"eq\",\n\t\t\t\t\t\tconnector: \"AND\",\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tfield: \"userId\",\n\t\t\t\t\t\tvalue: user.id,\n\t\t\t\t\t\toperator: \"eq\",\n\t\t\t\t\t\tconnector: \"AND\",\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t});\n\t\t\tif (!member) {\n\t\t\t\tctx.context.logger.error(\n\t\t\t\t\t`[Dynamic Access Control] The user is not a member of the organization to create a role.`,\n\t\t\t\t\t{\n\t\t\t\t\t\tuserId: user.id,\n\t\t\t\t\t\torganizationId,\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t\tthrow new APIError(\"FORBIDDEN\", {\n\t\t\t\t\tmessage:\n\t\t\t\t\t\tORGANIZATION_ERROR_CODES.YOU_ARE_NOT_A_MEMBER_OF_THIS_ORGANIZATION,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst canCreateRole = await hasPermission(\n\t\t\t\t{\n\t\t\t\t\toptions,\n\t\t\t\t\torganizationId,\n\t\t\t\t\tpermissions: {\n\t\t\t\t\t\tac: [\"create\"],\n\t\t\t\t\t},\n\t\t\t\t\trole: member.role,\n\t\t\t\t},\n\t\t\t\tctx,\n\t\t\t);\n\t\t\tif (!canCreateRole) {\n\t\t\t\tctx.context.logger.error(\n\t\t\t\t\t`[Dynamic Access Control] The user is not permitted to create a role. If this is unexpected, please make sure the role associated to that member has the \"ac\" resource with the \"create\" permission.`,\n\t\t\t\t\t{\n\t\t\t\t\t\tuserId: user.id,\n\t\t\t\t\t\torganizationId,\n\t\t\t\t\t\trole: member.role,\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t\tthrow new APIError(\"FORBIDDEN\", {\n\t\t\t\t\tmessage:\n\t\t\t\t\t\tORGANIZATION_ERROR_CODES.YOU_ARE_NOT_ALLOWED_TO_CREATE_A_ROLE,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst maximumRolesPerOrganization =\n\t\t\t\ttypeof options.dynamicAccessControl?.maximumRolesPerOrganization ===\n\t\t\t\t\"function\"\n\t\t\t\t\t? await options.dynamicAccessControl.maximumRolesPerOrganization(\n\t\t\t\t\t\t\torganizationId,\n\t\t\t\t\t\t)\n\t\t\t\t\t: (options.dynamicAccessControl?.maximumRolesPerOrganization ??\n\t\t\t\t\t\tDEFAULT_MAXIMUM_ROLES_PER_ORGANIZATION);\n\t\t\tconst rolesInDB = await ctx.context.adapter.count({\n\t\t\t\tmodel: \"organizationRole\",\n\t\t\t\twhere: [\n\t\t\t\t\t{\n\t\t\t\t\t\tfield: \"organizationId\",\n\t\t\t\t\t\tvalue: organizationId,\n\t\t\t\t\t\toperator: \"eq\",\n\t\t\t\t\t\tconnector: \"AND\",\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t});\n\t\t\tif (rolesInDB >= maximumRolesPerOrganization) {\n\t\t\t\tctx.context.logger.error(\n\t\t\t\t\t`[Dynamic Access Control] Failed to create a new role, the organization has too many roles. Maximum allowed roles is ${maximumRolesPerOrganization}.`,\n\t\t\t\t\t{\n\t\t\t\t\t\torganizationId,\n\t\t\t\t\t\tmaximumRolesPerOrganization,\n\t\t\t\t\t\trolesInDB,\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\tmessage: ORGANIZATION_ERROR_CODES.TOO_MANY_ROLES,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tawait checkForInvalidResources({ ac, ctx, permission });\n\n\t\t\tawait checkIfMemberHasPermission({\n\t\t\t\tctx,\n\t\t\t\tmember,\n\t\t\t\toptions,\n\t\t\t\torganizationId,\n\t\t\t\tpermissionRequired: permission,\n\t\t\t\tuser,\n\t\t\t\taction: \"create\",\n\t\t\t});\n\n\t\t\tawait checkIfRoleNameIsTakenByRoleInDB({\n\t\t\t\tctx,\n\t\t\t\torganizationId,\n\t\t\t\trole: roleName,\n\t\t\t});\n\n\t\t\tconst newRole = ac.newRole(permission);\n\n\t\t\tconst newRoleInDB = await ctx.context.adapter.create<\n\t\t\t\tOmit<OrganizationRole, \"permission\"> & { permission: string }\n\t\t\t>({\n\t\t\t\tmodel: \"organizationRole\",\n\t\t\t\tdata: {\n\t\t\t\t\tcreatedAt: new Date(),\n\t\t\t\t\torganizationId,\n\t\t\t\t\tpermission: JSON.stringify(permission),\n\t\t\t\t\trole: roleName,\n\t\t\t\t\t...additionalFields,\n\t\t\t\t},\n\t\t\t});\n\n\t\t\tconst data = {\n\t\t\t\t...newRoleInDB,\n\t\t\t\tpermission,\n\t\t\t} as OrganizationRole & ReturnAdditionalFields;\n\t\t\treturn ctx.json({\n\t\t\t\tsuccess: true,\n\t\t\t\troleData: data,\n\t\t\t\tstatements: newRole.statements,\n\t\t\t});\n\t\t},\n\t);\n};\n\nconst deleteOrgRoleBodySchema = z\n\t.object({\n\t\torganizationId: z.string().optional().meta({\n\t\t\tdescription:\n\t\t\t\t\"The id of the organization to create the role in. If not provided, the user's active organization will be used.\",\n\t\t}),\n\t})\n\t.and(\n\t\tz.union([\n\t\t\tz.object({\n\t\t\t\troleName: z.string().nonempty().meta({\n\t\t\t\t\tdescription: \"The name of the role to delete\",\n\t\t\t\t}),\n\t\t\t}),\n\t\t\tz.object({\n\t\t\t\troleId: z.string().nonempty().meta({\n\t\t\t\t\tdescription: \"The id of the role to delete\",\n\t\t\t\t}),\n\t\t\t}),\n\t\t]),\n\t);\n\nexport const deleteOrgRole = <O extends OrganizationOptions>(options: O) => {\n\treturn createAuthEndpoint(\n\t\t\"/organization/delete-role\",\n\t\t{\n\t\t\tmethod: \"POST\",\n\t\t\tbody: deleteOrgRoleBodySchema,\n\t\t\trequireHeaders: true,\n\t\t\tuse: [orgSessionMiddleware],\n\t\t\tmetadata: {\n\t\t\t\t$Infer: {\n\t\t\t\t\tbody: {} as {\n\t\t\t\t\t\troleName?: string | undefined;\n\t\t\t\t\t\troleId?: string | undefined;\n\t\t\t\t\t\torganizationId?: string | undefined;\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, user } = ctx.context.session;\n\n\t\t\tconst organizationId =\n\t\t\t\tctx.body.organizationId ?? session.activeOrganizationId;\n\t\t\tif (!organizationId) {\n\t\t\t\tctx.context.logger.error(\n\t\t\t\t\t`[Dynamic Access Control] The session is missing an active organization id to delete a role. Either set an active org id, or pass an organizationId in the request body.`,\n\t\t\t\t);\n\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\tmessage: ORGANIZATION_ERROR_CODES.NO_ACTIVE_ORGANIZATION,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst member = await ctx.context.adapter.findOne<Member>({\n\t\t\t\tmodel: \"member\",\n\t\t\t\twhere: [\n\t\t\t\t\t{\n\t\t\t\t\t\tfield: \"organizationId\",\n\t\t\t\t\t\tvalue: organizationId,\n\t\t\t\t\t\toperator: \"eq\",\n\t\t\t\t\t\tconnector: \"AND\",\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tfield: \"userId\",\n\t\t\t\t\t\tvalue: user.id,\n\t\t\t\t\t\toperator: \"eq\",\n\t\t\t\t\t\tconnector: \"AND\",\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t});\n\t\t\tif (!member) {\n\t\t\t\tctx.context.logger.error(\n\t\t\t\t\t`[Dynamic Access Control] The user is not a member of the organization to delete a role.`,\n\t\t\t\t\t{\n\t\t\t\t\t\tuserId: user.id,\n\t\t\t\t\t\torganizationId,\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t\tthrow new APIError(\"FORBIDDEN\", {\n\t\t\t\t\tmessage:\n\t\t\t\t\t\tORGANIZATION_ERROR_CODES.YOU_ARE_NOT_A_MEMBER_OF_THIS_ORGANIZATION,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst canDeleteRole = await hasPermission(\n\t\t\t\t{\n\t\t\t\t\toptions,\n\t\t\t\t\torganizationId,\n\t\t\t\t\tpermissions: {\n\t\t\t\t\t\tac: [\"delete\"],\n\t\t\t\t\t},\n\t\t\t\t\trole: member.role,\n\t\t\t\t},\n\t\t\t\tctx,\n\t\t\t);\n\t\t\tif (!canDeleteRole) {\n\t\t\t\tctx.context.logger.error(\n\t\t\t\t\t`[Dynamic Access Control] The user is not permitted to delete a role. If this is unexpected, please make sure the role associated to that member has the \"ac\" resource with the \"delete\" permission.`,\n\t\t\t\t\t{\n\t\t\t\t\t\tuserId: user.id,\n\t\t\t\t\t\torganizationId,\n\t\t\t\t\t\trole: member.role,\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t\tthrow new APIError(\"FORBIDDEN\", {\n\t\t\t\t\tmessage:\n\t\t\t\t\t\tORGANIZATION_ERROR_CODES.YOU_ARE_NOT_ALLOWED_TO_DELETE_A_ROLE,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tif (ctx.body.roleName) {\n\t\t\t\tconst roleName = ctx.body.roleName;\n\t\t\t\tconst defaultRoles = options.roles\n\t\t\t\t\t? Object.keys(options.roles)\n\t\t\t\t\t: [\"owner\", \"admin\", \"member\"];\n\t\t\t\tif (defaultRoles.includes(roleName)) {\n\t\t\t\t\tctx.context.logger.error(\n\t\t\t\t\t\t`[Dynamic Access Control] Cannot delete a pre-defined role.`,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\troleName,\n\t\t\t\t\t\t\torganizationId,\n\t\t\t\t\t\t\tdefaultRoles,\n\t\t\t\t\t\t},\n\t\t\t\t\t);\n\t\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\t\tmessage: ORGANIZATION_ERROR_CODES.CANNOT_DELETE_A_PRE_DEFINED_ROLE,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tlet condition: Where;\n\t\t\tif (ctx.body.roleName) {\n\t\t\t\tcondition = {\n\t\t\t\t\tfield: \"role\",\n\t\t\t\t\tvalue: ctx.body.roleName,\n\t\t\t\t\toperator: \"eq\",\n\t\t\t\t\tconnector: \"AND\",\n\t\t\t\t};\n\t\t\t} else if (ctx.body.roleId) {\n\t\t\t\tcondition = {\n\t\t\t\t\tfield: \"id\",\n\t\t\t\t\tvalue: ctx.body.roleId,\n\t\t\t\t\toperator: \"eq\",\n\t\t\t\t\tconnector: \"AND\",\n\t\t\t\t};\n\t\t\t} else {\n\t\t\t\t// shouldn't be able to reach here given the schema validation.\n\t\t\t\t// But just in case, throw an error.\n\t\t\t\tctx.context.logger.error(\n\t\t\t\t\t`[Dynamic Access Control] The role name/id is not provided in the request body.`,\n\t\t\t\t);\n\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\tmessage: ORGANIZATION_ERROR_CODES.ROLE_NOT_FOUND,\n\t\t\t\t});\n\t\t\t}\n\t\t\tconst existingRoleInDB =\n\t\t\t\tawait ctx.context.adapter.findOne<OrganizationRole>({\n\t\t\t\t\tmodel: \"organizationRole\",\n\t\t\t\t\twhere: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tfield: \"organizationId\",\n\t\t\t\t\t\t\tvalue: organizationId,\n\t\t\t\t\t\t\toperator: \"eq\",\n\t\t\t\t\t\t\tconnector: \"AND\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\tcondition,\n\t\t\t\t\t],\n\t\t\t\t});\n\t\t\tif (!existingRoleInDB) {\n\t\t\t\tctx.context.logger.error(\n\t\t\t\t\t`[Dynamic Access Control] The role name/id does not exist in the database.`,\n\t\t\t\t\t{\n\t\t\t\t\t\t...(\"roleName\" in ctx.body\n\t\t\t\t\t\t\t? { roleName: ctx.body.roleName }\n\t\t\t\t\t\t\t: { roleId: ctx.body.roleId }),\n\t\t\t\t\t\torganizationId,\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\tmessage: ORGANIZATION_ERROR_CODES.ROLE_NOT_FOUND,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\texistingRoleInDB.permission = JSON.parse(\n\t\t\t\texistingRoleInDB.permission as never as string,\n\t\t\t);\n\n\t\t\tawait ctx.context.adapter.delete({\n\t\t\t\tmodel: \"organizationRole\",\n\t\t\t\twhere: [\n\t\t\t\t\t{\n\t\t\t\t\t\tfield: \"organizationId\",\n\t\t\t\t\t\tvalue: organizationId,\n\t\t\t\t\t\toperator: \"eq\",\n\t\t\t\t\t\tconnector: \"AND\",\n\t\t\t\t\t},\n\t\t\t\t\tcondition,\n\t\t\t\t],\n\t\t\t});\n\n\t\t\treturn ctx.json({\n\t\t\t\tsuccess: true,\n\t\t\t});\n\t\t},\n\t);\n};\n\nconst listOrgRolesQuerySchema = z\n\t.object({\n\t\torganizationId: z.string().optional().meta({\n\t\t\tdescription:\n\t\t\t\t\"The id of the organization to list roles for. If not provided, the user's active organization will be used.\",\n\t\t}),\n\t})\n\t.optional();\n\nexport const listOrgRoles = <O extends OrganizationOptions>(options: O) => {\n\tconst { $ReturnAdditionalFields } = getAdditionalFields<O>(options, false);\n\ttype ReturnAdditionalFields = typeof $ReturnAdditionalFields;\n\n\treturn createAuthEndpoint(\n\t\t\"/organization/list-roles\",\n\t\t{\n\t\t\tmethod: \"GET\",\n\t\t\trequireHeaders: true,\n\t\t\tuse: [orgSessionMiddleware],\n\t\t\tquery: listOrgRolesQuerySchema,\n\t\t},\n\t\tasync (ctx) => {\n\t\t\tconst { session, user } = ctx.context.session;\n\n\t\t\tconst organizationId =\n\t\t\t\tctx.query?.organizationId ?? session.activeOrganizationId;\n\t\t\tif (!organizationId) {\n\t\t\t\tctx.context.logger.error(\n\t\t\t\t\t`[Dynamic Access Control] The session is missing an active organization id to list roles. Either set an active org id, or pass an organizationId in the request query.`,\n\t\t\t\t);\n\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\tmessage: ORGANIZATION_ERROR_CODES.NO_ACTIVE_ORGANIZATION,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst member = await ctx.context.adapter.findOne<Member>({\n\t\t\t\tmodel: \"member\",\n\t\t\t\twhere: [\n\t\t\t\t\t{\n\t\t\t\t\t\tfield: \"organizationId\",\n\t\t\t\t\t\tvalue: organizationId,\n\t\t\t\t\t\toperator: \"eq\",\n\t\t\t\t\t\tconnector: \"AND\",\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tfield: \"userId\",\n\t\t\t\t\t\tvalue: user.id,\n\t\t\t\t\t\toperator: \"eq\",\n\t\t\t\t\t\tconnector: \"AND\",\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t});\n\t\t\tif (!member) {\n\t\t\t\tctx.context.logger.error(\n\t\t\t\t\t`[Dynamic Access Control] The user is not a member of the organization to list roles.`,\n\t\t\t\t\t{\n\t\t\t\t\t\tuserId: user.id,\n\t\t\t\t\t\torganizationId,\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t\tthrow new APIError(\"FORBIDDEN\", {\n\t\t\t\t\tmessage:\n\t\t\t\t\t\tORGANIZATION_ERROR_CODES.YOU_ARE_NOT_A_MEMBER_OF_THIS_ORGANIZATION,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst canListRoles = await hasPermission(\n\t\t\t\t{\n\t\t\t\t\toptions,\n\t\t\t\t\torganizationId,\n\t\t\t\t\tpermissions: {\n\t\t\t\t\t\tac: [\"read\"],\n\t\t\t\t\t},\n\t\t\t\t\trole: member.role,\n\t\t\t\t},\n\t\t\t\tctx,\n\t\t\t);\n\t\t\tif (!canListRoles) {\n\t\t\t\tctx.context.logger.error(\n\t\t\t\t\t`[Dynamic Access Control] The user is not permitted to list roles.`,\n\t\t\t\t\t{\n\t\t\t\t\t\tuserId: user.id,\n\t\t\t\t\t\torganizationId,\n\t\t\t\t\t\trole: member.role,\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t\tthrow new APIError(\"FORBIDDEN\", {\n\t\t\t\t\tmessage: ORGANIZATION_ERROR_CODES.YOU_ARE_NOT_ALLOWED_TO_LIST_A_ROLE,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tlet roles = await ctx.context.adapter.findMany<\n\t\t\t\tOrganizationRole & ReturnAdditionalFields\n\t\t\t>({\n\t\t\t\tmodel: \"organizationRole\",\n\t\t\t\twhere: [\n\t\t\t\t\t{\n\t\t\t\t\t\tfield: \"organizationId\",\n\t\t\t\t\t\tvalue: organizationId,\n\t\t\t\t\t\toperator: \"eq\",\n\t\t\t\t\t\tconnector: \"AND\",\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t});\n\n\t\t\troles = roles.map((x) => ({\n\t\t\t\t...x,\n\t\t\t\tpermission: JSON.parse(x.permission as never as string),\n\t\t\t}));\n\n\t\t\treturn ctx.json(roles);\n\t\t},\n\t);\n};\n\nconst getOrgRoleQuerySchema = z\n\t.object({\n\t\torganizationId: z.string().optional().meta({\n\t\t\tdescription:\n\t\t\t\t\"The id of the organization to read a role for. If not provided, the user's active organization will be used.\",\n\t\t}),\n\t})\n\t.and(\n\t\tz.union([\n\t\t\tz.object({\n\t\t\t\troleName: z.string().nonempty().meta({\n\t\t\t\t\tdescription: \"The name of the role to read\",\n\t\t\t\t}),\n\t\t\t}),\n\t\t\tz.object({\n\t\t\t\troleId: z.string().nonempty().meta({\n\t\t\t\t\tdescription: \"The id of the role to read\",\n\t\t\t\t}),\n\t\t\t}),\n\t\t]),\n\t)\n\t.optional();\n\nexport const getOrgRole = <O extends OrganizationOptions>(options: O) => {\n\tconst { $ReturnAdditionalFields } = getAdditionalFields<O>(options, false);\n\ttype ReturnAdditionalFields = typeof $ReturnAdditionalFields;\n\treturn createAuthEndpoint(\n\t\t\"/organization/get-role\",\n\t\t{\n\t\t\tmethod: \"GET\",\n\t\t\trequireHeaders: true,\n\t\t\tuse: [orgSessionMiddleware],\n\t\t\tquery: getOrgRoleQuerySchema,\n\t\t\tmetadata: {\n\t\t\t\t$Infer: {\n\t\t\t\t\tquery: {} as {\n\t\t\t\t\t\torganizationId?: string | undefined;\n\t\t\t\t\t\troleName?: string | undefined;\n\t\t\t\t\t\troleId?: string | undefined;\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, user } = ctx.context.session;\n\n\t\t\tconst organizationId =\n\t\t\t\tctx.query?.organizationId ?? session.activeOrganizationId;\n\t\t\tif (!organizationId) {\n\t\t\t\tctx.context.logger.error(\n\t\t\t\t\t`[Dynamic Access Control] The session is missing an active organization id to read a role. Either set an active org id, or pass an organizationId in the request query.`,\n\t\t\t\t);\n\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\tmessage: ORGANIZATION_ERROR_CODES.NO_ACTIVE_ORGANIZATION,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst member = await ctx.context.adapter.findOne<Member>({\n\t\t\t\tmodel: \"member\",\n\t\t\t\twhere: [\n\t\t\t\t\t{\n\t\t\t\t\t\tfield: \"organizationId\",\n\t\t\t\t\t\tvalue: organizationId,\n\t\t\t\t\t\toperator: \"eq\",\n\t\t\t\t\t\tconnector: \"AND\",\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tfield: \"userId\",\n\t\t\t\t\t\tvalue: user.id,\n\t\t\t\t\t\toperator: \"eq\",\n\t\t\t\t\t\tconnector: \"AND\",\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t});\n\t\t\tif (!member) {\n\t\t\t\tctx.context.logger.error(\n\t\t\t\t\t`[Dynamic Access Control] The user is not a member of the organization to read a role.`,\n\t\t\t\t\t{\n\t\t\t\t\t\tuserId: user.id,\n\t\t\t\t\t\torganizationId,\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t\tthrow new APIError(\"FORBIDDEN\", {\n\t\t\t\t\tmessage:\n\t\t\t\t\t\tORGANIZATION_ERROR_CODES.YOU_ARE_NOT_A_MEMBER_OF_THIS_ORGANIZATION,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst canListRoles = await hasPermission(\n\t\t\t\t{\n\t\t\t\t\toptions,\n\t\t\t\t\torganizationId,\n\t\t\t\t\tpermissions: {\n\t\t\t\t\t\tac: [\"read\"],\n\t\t\t\t\t},\n\t\t\t\t\trole: member.role,\n\t\t\t\t},\n\t\t\t\tctx,\n\t\t\t);\n\t\t\tif (!canListRoles) {\n\t\t\t\tctx.context.logger.error(\n\t\t\t\t\t`[Dynamic Access Control] The user is not permitted to read a role.`,\n\t\t\t\t\t{\n\t\t\t\t\t\tuserId: user.id,\n\t\t\t\t\t\torganizationId,\n\t\t\t\t\t\trole: member.role,\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t\tthrow new APIError(\"FORBIDDEN\", {\n\t\t\t\t\tmessage: ORGANIZATION_ERROR_CODES.YOU_ARE_NOT_ALLOWED_TO_READ_A_ROLE,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tlet condition: Where;\n\t\t\tif (ctx.query.roleName) {\n\t\t\t\tcondition = {\n\t\t\t\t\tfield: \"role\",\n\t\t\t\t\tvalue: ctx.query.roleName,\n\t\t\t\t\toperator: \"eq\",\n\t\t\t\t\tconnector: \"AND\",\n\t\t\t\t};\n\t\t\t} else if (ctx.query.roleId) {\n\t\t\t\tcondition = {\n\t\t\t\t\tfield: \"id\",\n\t\t\t\t\tvalue: ctx.query.roleId,\n\t\t\t\t\toperator: \"eq\",\n\t\t\t\t\tconnector: \"AND\",\n\t\t\t\t};\n\t\t\t} else {\n\t\t\t\t// shouldn't be able to reach here given the schema validation.\n\t\t\t\t// But just in case, throw an error.\n\t\t\t\tctx.context.logger.error(\n\t\t\t\t\t`[Dynamic Access Control] The role name/id is not provided in the request query.`,\n\t\t\t\t);\n\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\tmessage: ORGANIZATION_ERROR_CODES.ROLE_NOT_FOUND,\n\t\t\t\t});\n\t\t\t}\n\t\t\tconst role = await ctx.context.adapter.findOne<OrganizationRole>({\n\t\t\t\tmodel: \"organizationRole\",\n\t\t\t\twhere: [\n\t\t\t\t\t{\n\t\t\t\t\t\tfield: \"organizationId\",\n\t\t\t\t\t\tvalue: organizationId,\n\t\t\t\t\t\toperator: \"eq\",\n\t\t\t\t\t\tconnector: \"AND\",\n\t\t\t\t\t},\n\t\t\t\t\tcondition,\n\t\t\t\t],\n\t\t\t});\n\t\t\tif (!role) {\n\t\t\t\tctx.context.logger.error(\n\t\t\t\t\t`[Dynamic Access Control] The role name/id does not exist in the database.`,\n\t\t\t\t\t{\n\t\t\t\t\t\t...(\"roleName\" in ctx.query\n\t\t\t\t\t\t\t? { roleName: ctx.query.roleName }\n\t\t\t\t\t\t\t: { roleId: ctx.query.roleId }),\n\t\t\t\t\t\torganizationId,\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\tmessage: ORGANIZATION_ERROR_CODES.ROLE_NOT_FOUND,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\trole.permission = JSON.parse(role.permission as never as string);\n\n\t\t\treturn ctx.json(role as OrganizationRole & ReturnAdditionalFields);\n\t\t},\n\t);\n};\n\nconst roleNameOrIdSchema = z.union([\n\tz.object({\n\t\troleName: z.string().nonempty().meta({\n\t\t\tdescription: \"The name of the role to update\",\n\t\t}),\n\t}),\n\tz.object({\n\t\troleId: z.string().nonempty().meta({\n\t\t\tdescription: \"The id of the role to update\",\n\t\t}),\n\t}),\n]);\n\nexport const updateOrgRole = <O extends OrganizationOptions>(options: O) => {\n\tconst { additionalFieldsSchema, $AdditionalFields, $ReturnAdditionalFields } =\n\t\tgetAdditionalFields<O, true>(options, true);\n\ttype AdditionalFields = typeof $AdditionalFields;\n\ttype ReturnAdditionalFields = typeof $ReturnAdditionalFields;\n\n\treturn createAuthEndpoint(\n\t\t\"/organization/update-role\",\n\t\t{\n\t\t\tmethod: \"POST\",\n\t\t\tbody: z\n\t\t\t\t.object({\n\t\t\t\t\torganizationId: z.string().optional().meta({\n\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\"The id of the organization to update the role in. If not provided, the user's active organization will be used.\",\n\t\t\t\t\t}),\n\t\t\t\t\tdata: z.object({\n\t\t\t\t\t\tpermission: z\n\t\t\t\t\t\t\t.record(z.string(), z.array(z.string()))\n\t\t\t\t\t\t\t.optional()\n\t\t\t\t\t\t\t.meta({\n\t\t\t\t\t\t\t\tdescription: \"The permission to update the role with\",\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\troleName: z.string().optional().meta({\n\t\t\t\t\t\t\tdescription: \"The name of the role to update\",\n\t\t\t\t\t\t}),\n\t\t\t\t\t\t...additionalFieldsSchema.shape,\n\t\t\t\t\t}),\n\t\t\t\t})\n\t\t\t\t.and(roleNameOrIdSchema),\n\t\t\tmetadata: {\n\t\t\t\t$Infer: {\n\t\t\t\t\tbody: {} as {\n\t\t\t\t\t\torganizationId?: string | undefined;\n\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\tpermission?: Record<string, string[]> | undefined;\n\t\t\t\t\t\t\troleName?: string | undefined;\n\t\t\t\t\t\t} & AdditionalFields;\n\t\t\t\t\t\troleName?: string | undefined;\n\t\t\t\t\t\troleId?: string | undefined;\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\trequireHeaders: true,\n\t\t\tuse: [orgSessionMiddleware],\n\t\t},\n\t\tasync (ctx) => {\n\t\t\tconst { session, user } = ctx.context.session;\n\n\t\t\tconst ac = options.ac;\n\t\t\tif (!ac) {\n\t\t\t\tctx.context.logger.error(\n\t\t\t\t\t`[Dynamic Access Control] The organization plugin is missing a pre-defined ac instance.`,\n\t\t\t\t\t`\\nPlease refer to the documentation here: https://better-auth.com/docs/plugins/organization#dynamic-access-control`,\n\t\t\t\t);\n\t\t\t\tthrow new APIError(\"NOT_IMPLEMENTED\", {\n\t\t\t\t\tmessage: ORGANIZATION_ERROR_CODES.MISSING_AC_INSTANCE,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst organizationId =\n\t\t\t\tctx.body.organizationId ?? session.activeOrganizationId;\n\t\t\tif (!organizationId) {\n\t\t\t\tctx.context.logger.error(\n\t\t\t\t\t`[Dynamic Access Control] The session is missing an active organization id to update a role. Either set an active org id, or pass an organizationId in the request body.`,\n\t\t\t\t);\n\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\tmessage: ORGANIZATION_ERROR_CODES.NO_ACTIVE_ORGANIZATION,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst member = await ctx.context.adapter.findOne<Member>({\n\t\t\t\tmodel: \"member\",\n\t\t\t\twhere: [\n\t\t\t\t\t{\n\t\t\t\t\t\tfield: \"organizationId\",\n\t\t\t\t\t\tvalue: organizationId,\n\t\t\t\t\t\toperator: \"eq\",\n\t\t\t\t\t\tconnector: \"AND\",\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tfield: \"userId\",\n\t\t\t\t\t\tvalue: user.id,\n\t\t\t\t\t\toperator: \"eq\",\n\t\t\t\t\t\tconnector: \"AND\",\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t});\n\t\t\tif (!member) {\n\t\t\t\tctx.context.logger.error(\n\t\t\t\t\t`[Dynamic Access Control] The user is not a member of the organization to update a role.`,\n\t\t\t\t\t{\n\t\t\t\t\t\tuserId: user.id,\n\t\t\t\t\t\torganizationId,\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t\tthrow new APIError(\"FORBIDDEN\", {\n\t\t\t\t\tmessage:\n\t\t\t\t\t\tORGANIZATION_ERROR_CODES.YOU_ARE_NOT_A_MEMBER_OF_THIS_ORGANIZATION,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst canUpdateRole = await hasPermission(\n\t\t\t\t{\n\t\t\t\t\toptions,\n\t\t\t\t\torganizationId,\n\t\t\t\t\trole: member.role,\n\t\t\t\t\tpermissions: {\n\t\t\t\t\t\tac: [\"update\"],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tctx,\n\t\t\t);\n\t\t\tif (!canUpdateRole) {\n\t\t\t\tctx.context.logger.error(\n\t\t\t\t\t`[Dynamic Access Control] The user is not permitted to update a role.`,\n\t\t\t\t);\n\t\t\t\tthrow new APIError(\"FORBIDDEN\", {\n\t\t\t\t\tmessage:\n\t\t\t\t\t\tORGANIZATION_ERROR_CODES.YOU_ARE_NOT_ALLOWED_TO_UPDATE_A_ROLE,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tlet condition: Where;\n\t\t\tif (ctx.body.roleName) {\n\t\t\t\tcondition = {\n\t\t\t\t\tfield: \"role\",\n\t\t\t\t\tvalue: ctx.body.roleName,\n\t\t\t\t\toperator: \"eq\",\n\t\t\t\t\tconnector: \"AND\",\n\t\t\t\t};\n\t\t\t} else if (ctx.body.roleId) {\n\t\t\t\tcondition = {\n\t\t\t\t\tfield: \"id\",\n\t\t\t\t\tvalue: ctx.body.roleId,\n\t\t\t\t\toperator: \"eq\",\n\t\t\t\t\tconnector: \"AND\",\n\t\t\t\t};\n\t\t\t} else {\n\t\t\t\t// shouldn't be able to reach here given the schema validation.\n\t\t\t\t// But just in case, throw an error.\n\t\t\t\tctx.context.logger.error(\n\t\t\t\t\t`[Dynamic Access Control] The role name/id is not provided in the request body.`,\n\t\t\t\t);\n\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\tmessage: ORGANIZATION_ERROR_CODES.ROLE_NOT_FOUND,\n\t\t\t\t});\n\t\t\t}\n\t\t\tconst role = await ctx.context.adapter.findOne<OrganizationRole>({\n\t\t\t\tmodel: \"organizationRole\",\n\t\t\t\twhere: [\n\t\t\t\t\t{\n\t\t\t\t\t\tfield: \"organizationId\",\n\t\t\t\t\t\tvalue: organizationId,\n\t\t\t\t\t\toperator: \"eq\",\n\t\t\t\t\t\tconnector: \"AND\",\n\t\t\t\t\t},\n\t\t\t\t\tcondition,\n\t\t\t\t],\n\t\t\t});\n\t\t\tif (!role) {\n\t\t\t\tctx.context.logger.error(\n\t\t\t\t\t`[Dynamic Access Control] The role name/id does not exist in the database.`,\n\t\t\t\t\t{\n\t\t\t\t\t\t...(\"roleName\" in ctx.body\n\t\t\t\t\t\t\t? { roleName: ctx.body.roleName }\n\t\t\t\t\t\t\t: { roleId: ctx.body.roleId }),\n\t\t\t\t\t\torganizationId,\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\tmessage: ORGANIZATION_ERROR_CODES.ROLE_NOT_FOUND,\n\t\t\t\t});\n\t\t\t}\n\t\t\trole.permission = role.permission\n\t\t\t\t? JSON.parse(role.permission as never as string)\n\t\t\t\t: undefined;\n\n\t\t\tconst {\n\t\t\t\tpermission: _,\n\t\t\t\troleName: __,\n\t\t\t\t...additionalFields\n\t\t\t} = ctx.body.data;\n\n\t\t\tconst updateData: Partial<OrganizationRole> = {\n\t\t\t\t...additionalFields,\n\t\t\t};\n\n\t\t\tif (ctx.body.data.permission) {\n\t\t\t\tconst newPermission = ctx.body.data.permission;\n\n\t\t\t\tawait checkForInvalidResources({ ac, ctx, permission: newPermission });\n\n\t\t\t\tawait checkIfMemberHasPermission({\n\t\t\t\t\tctx,\n\t\t\t\t\tmember,\n\t\t\t\t\toptions,\n\t\t\t\t\torganizationId,\n\t\t\t\t\tpermissionRequired: newPermission,\n\t\t\t\t\tuser,\n\t\t\t\t\taction: \"update\",\n\t\t\t\t});\n\n\t\t\t\tupdateData.permission = newPermission;\n\t\t\t}\n\t\t\tif (ctx.body.data.roleName) {\n\t\t\t\tlet newRoleName = ctx.body.data.roleName;\n\n\t\t\t\tnewRoleName = normalizeRoleName(newRoleName);\n\n\t\t\t\tawait checkIfRoleNameIsTakenByPreDefinedRole({\n\t\t\t\t\trole: newRoleName,\n\t\t\t\t\torganizationId,\n\t\t\t\t\toptions,\n\t\t\t\t\tctx,\n\t\t\t\t});\n\t\t\t\tawait checkIfRoleNameIsTakenByRoleInDB({\n\t\t\t\t\trole: newRoleName,\n\t\t\t\t\torganizationId,\n\t\t\t\t\tctx,\n\t\t\t\t});\n\n\t\t\t\tupdateData.role = newRoleName;\n\t\t\t}\n\n\t\t\t// -----\n\t\t\t// Apply the updates\n\t\t\tconst update = {\n\t\t\t\t...updateData,\n\t\t\t\t...(updateData.permission\n\t\t\t\t\t? { permission: JSON.stringify(updateData.permission) }\n\t\t\t\t\t: {}),\n\t\t\t};\n\t\t\tawait ctx.context.adapter.update<OrganizationRole>({\n\t\t\t\tmodel: \"organizationRole\",\n\t\t\t\twhere: [\n\t\t\t\t\t{\n\t\t\t\t\t\tfield: \"organizationId\",\n\t\t\t\t\t\tvalue: organizationId,\n\t\t\t\t\t\toperator: \"eq\",\n\t\t\t\t\t\tconnector: \"AND\",\n\t\t\t\t\t},\n\t\t\t\t\tcondition,\n\t\t\t\t],\n\t\t\t\tupdate,\n\t\t\t});\n\n\t\t\t// -----\n\t\t\t// Return the updated role\n\t\t\treturn ctx.json({\n\t\t\t\tsuccess: true,\n\t\t\t\troleData: {\n\t\t\t\t\t...role,\n\t\t\t\t\t...update,\n\t\t\t\t\tpermission: updateData.permission || role.permission || null,\n\t\t\t\t} as OrganizationRole & ReturnAdditionalFields,\n\t\t\t});\n\t\t},\n\t);\n};\n\nasync function checkForInvalidResources({\n\tac,\n\tctx,\n\tpermission,\n}: {\n\tac: AccessControl;\n\tctx: GenericEndpointContext;\n\tpermission: Record<string, string[]>;\n}) {\n\tconst validResources = Object.keys(ac.statements);\n\tconst providedResources = Object.keys(permission);\n\tconst hasInvalidResource = providedResources.some(\n\t\t(r) => !validResources.includes(r),\n\t);\n\tif (hasInvalidResource) {\n\t\tctx.context.logger.error(\n\t\t\t`[Dynamic Access Control] The provided permission includes an invalid resource.`,\n\t\t\t{\n\t\t\t\tprovidedResources,\n\t\t\t\tvalidResources,\n\t\t\t},\n\t\t);\n\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\tmessage: ORGANIZATION_ERROR_CODES.INVALID_RESOURCE,\n\t\t});\n\t}\n}\n\nasync function checkIfMemberHasPermission({\n\tctx,\n\tpermissionRequired: permission,\n\toptions,\n\torganizationId,\n\tmember,\n\tuser,\n\taction,\n}: {\n\tctx: GenericEndpointContext;\n\tpermissionRequired: Record<string, string[]>;\n\toptions: OrganizationOptions;\n\torganizationId: string;\n\tmember: Member;\n\tuser: User;\n\taction: \"create\" | \"update\" | \"delete\" | \"read\" | \"list\" | \"get\";\n}) {\n\tconst hasNecessaryPermissions: {\n\t\tresource: { [x: string]: string[] };\n\t\thasPermission: boolean;\n\t}[] = [];\n\tconst permissionEntries = Object.entries(permission);\n\tfor await (const [resource, permissions] of permissionEntries) {\n\t\tfor await (const perm of permissions) {\n\t\t\thasNecessaryPermissions.push({\n\t\t\t\tresource: { [resource]: [perm] },\n\t\t\t\thasPermission: await hasPermission(\n\t\t\t\t\t{\n\t\t\t\t\t\toptions,\n\t\t\t\t\t\torganizationId,\n\t\t\t\t\t\tpermissions: { [resource]: [perm] },\n\t\t\t\t\t\tuseMemoryCache: true,\n\t\t\t\t\t\trole: member.role,\n\t\t\t\t\t},\n\t\t\t\t\tctx,\n\t\t\t\t),\n\t\t\t});\n\t\t}\n\t}\n\tconst missingPermissions = hasNecessaryPermissions\n\t\t.filter((x) => x.hasPermission === false)\n\t\t.map((x) => {\n\t\t\tconst key = Object.keys(x.resource)[0]!;\n\t\t\treturn `${key}:${x.resource[key]![0]}` as const;\n\t\t});\n\tif (missingPermissions.length > 0) {\n\t\tctx.context.logger.error(\n\t\t\t`[Dynamic Access Control] The user is missing permissions necessary to ${action} a role with those set of permissions.\\n`,\n\t\t\t{\n\t\t\t\tuserId: user.id,\n\t\t\t\torganizationId,\n\t\t\t\trole: member.role,\n\t\t\t\tmissingPermissions,\n\t\t\t},\n\t\t);\n\t\tlet errorMessage: string;\n\t\tif (action === \"create\")\n\t\t\terrorMessage =\n\t\t\t\tORGANIZATION_ERROR_CODES.YOU_ARE_NOT_ALLOWED_TO_CREATE_A_ROLE;\n\t\telse if (action === \"update\")\n\t\t\terrorMessage =\n\t\t\t\tORGANIZATION_ERROR_CODES.YOU_ARE_NOT_ALLOWED_TO_UPDATE_A_ROLE;\n\t\telse if (action === \"delete\")\n\t\t\terrorMessage =\n\t\t\t\tORGANIZATION_ERROR_CODES.YOU_ARE_NOT_ALLOWED_TO_DELETE_A_ROLE;\n\t\telse if (action === \"read\")\n\t\t\terrorMessage =\n\t\t\t\tORGANIZATION_ERROR_CODES.YOU_ARE_NOT_ALLOWED_TO_READ_A_ROLE;\n\t\telse if (action === \"list\")\n\t\t\terrorMessage =\n\t\t\t\tORGANIZATION_ERROR_CODES.YOU_ARE_NOT_ALLOWED_TO_LIST_A_ROLE;\n\t\telse\n\t\t\terrorMessage = ORGANIZATION_ERROR_CODES.YOU_ARE_NOT_ALLOWED_TO_GET_A_ROLE;\n\n\t\tthrow new APIError(\"FORBIDDEN\", {\n\t\t\tmessage: errorMessage,\n\t\t\tmissingPermissions,\n\t\t});\n\t}\n}\n\nasync function checkIfRoleNameIsTakenByPreDefinedRole({\n\toptions,\n\torganizationId,\n\trole,\n\tctx,\n}: {\n\toptions: OrganizationOptions;\n\torganizationId: string;\n\trole: string;\n\tctx: GenericEndpointContext;\n}) {\n\tconst defaultRoles = options.roles\n\t\t? Object.keys(options.roles)\n\t\t: [\"owner\", \"admin\", \"member\"];\n\tif (defaultRoles.includes(role)) {\n\t\tctx.context.logger.error(\n\t\t\t`[Dynamic Access Control] The role name \"${role}\" is already taken by a pre-defined role.`,\n\t\t\t{\n\t\t\t\trole,\n\t\t\t\torganizationId,\n\t\t\t\tdefaultRoles,\n\t\t\t},\n\t\t);\n\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\tmessage: ORGANIZATION_ERROR_CODES.ROLE_NAME_IS_ALREADY_TAKEN,\n\t\t});\n\t}\n}\n\nasync function checkIfRoleNameIsTakenByRoleInDB({\n\torganizationId,\n\trole,\n\tctx,\n}: {\n\tctx: GenericEndpointContext;\n\torganizationId: string;\n\trole: string;\n}) {\n\tconst existingRoleInDB = await ctx.context.adapter.findOne<OrganizationRole>({\n\t\tmodel: \"organizationRole\",\n\t\twhere: [\n\t\t\t{\n\t\t\t\tfield: \"organizationId\",\n\t\t\t\tvalue: organizationId,\n\t\t\t\toperator: \"eq\",\n\t\t\t\tconnector: \"AND\",\n\t\t\t},\n\t\t\t{\n\t\t\t\tfield: \"role\",\n\t\t\t\tvalue: role,\n\t\t\t\toperator: \"eq\",\n\t\t\t\tconnector: \"AND\",\n\t\t\t},\n\t\t],\n\t});\n\tif (existingRoleInDB) {\n\t\tctx.context.logger.error(\n\t\t\t`[Dynamic Access Control] The role name \"${role}\" is already taken by a role in the database.`,\n\t\t\t{\n\t\t\t\trole,\n\t\t\t\torganizationId,\n\t\t\t},\n\t\t);\n\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\tmessage: ORGANIZATION_ERROR_CODES.ROLE_NAME_IS_ALREADY_TAKEN,\n\t\t});\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AO;GACP,OAAO;GACP,UAAU;GACV,WAAW;GACX,CACD;EACD,CAAC,EACoB;AACrB,MAAI,QAAQ,OAAO,MAClB,2CAA2C,KAAK,gDAChD;GACC;GACA;GACA,CACD;AACD,QAAM,IAAI,SAAS,eAAe,EACjC,SAAS,yBAAyB,4BAClC,CAAC"}
1
+ {"version":3,"file":"crud-access-control.mjs","names":["condition: Where","member","updateData: Partial<OrganizationRole>","hasNecessaryPermissions: {\n\t\tresource: { [x: string]: string[] };\n\t\thasPermission: boolean;\n\t}[]","errorMessage: string"],"sources":["../../../../src/plugins/organization/routes/crud-access-control.ts"],"sourcesContent":["import type { GenericEndpointContext } from \"@better-auth/core\";\nimport { createAuthEndpoint } from \"@better-auth/core/api\";\nimport type { Where } from \"@better-auth/core/db/adapter\";\nimport * as z from \"zod\";\nimport { APIError } from \"../../../api\";\nimport type { InferAdditionalFieldsFromPluginOptions } from \"../../../db\";\nimport { toZodSchema } from \"../../../db\";\nimport type { User } from \"../../../types\";\nimport type { AccessControl } from \"../../access\";\nimport { orgSessionMiddleware } from \"../call\";\nimport { ORGANIZATION_ERROR_CODES } from \"../error-codes\";\nimport { hasPermission } from \"../has-permission\";\nimport type { Member, OrganizationRole } from \"../schema\";\nimport type { OrganizationOptions } from \"../types\";\n\ntype IsExactlyEmptyObject<T> = keyof T extends never // no keys\n\t? T extends {} // is assignable to {}\n\t\t? {} extends T\n\t\t\t? true\n\t\t\t: false // and {} is assignable to it\n\t\t: false\n\t: false;\n\nconst normalizeRoleName = (role: string) => role.toLowerCase();\nconst DEFAULT_MAXIMUM_ROLES_PER_ORGANIZATION = Number.POSITIVE_INFINITY;\n\nconst getAdditionalFields = <\n\tO extends OrganizationOptions,\n\tAllPartial extends boolean = false,\n>(\n\toptions: O,\n\tshouldBePartial: AllPartial = false as AllPartial,\n) => {\n\tconst additionalFields =\n\t\toptions?.schema?.organizationRole?.additionalFields || {};\n\tif (shouldBePartial) {\n\t\tfor (const key in additionalFields) {\n\t\t\tadditionalFields[key]!.required = false;\n\t\t}\n\t}\n\tconst additionalFieldsSchema = toZodSchema({\n\t\tfields: additionalFields,\n\t\tisClientSide: true,\n\t});\n\ttype AdditionalFields = AllPartial extends true\n\t\t? Partial<InferAdditionalFieldsFromPluginOptions<\"organizationRole\", O>>\n\t\t: InferAdditionalFieldsFromPluginOptions<\"organizationRole\", O>;\n\ttype ReturnAdditionalFields = InferAdditionalFieldsFromPluginOptions<\n\t\t\"organizationRole\",\n\t\tO,\n\t\tfalse\n\t>;\n\n\treturn {\n\t\tadditionalFieldsSchema,\n\t\t$AdditionalFields: {} as AdditionalFields,\n\t\t$ReturnAdditionalFields: {} as ReturnAdditionalFields,\n\t};\n};\n\nconst baseCreateOrgRoleSchema = z.object({\n\torganizationId: z.string().optional().meta({\n\t\tdescription:\n\t\t\t\"The id of the organization to create the role in. If not provided, the user's active organization will be used.\",\n\t}),\n\trole: z.string().meta({\n\t\tdescription: \"The name of the role to create\",\n\t}),\n\tpermission: z.record(z.string(), z.array(z.string())).meta({\n\t\tdescription: \"The permission to assign to the role\",\n\t}),\n});\n\nexport const createOrgRole = <O extends OrganizationOptions>(options: O) => {\n\tconst { additionalFieldsSchema, $AdditionalFields, $ReturnAdditionalFields } =\n\t\tgetAdditionalFields<O>(options, false);\n\ttype AdditionalFields = typeof $AdditionalFields;\n\ttype ReturnAdditionalFields = typeof $ReturnAdditionalFields;\n\n\treturn createAuthEndpoint(\n\t\t\"/organization/create-role\",\n\t\t{\n\t\t\tmethod: \"POST\",\n\t\t\tbody: baseCreateOrgRoleSchema.safeExtend({\n\t\t\t\tadditionalFields: z\n\t\t\t\t\t.object({ ...additionalFieldsSchema.shape })\n\t\t\t\t\t.optional(),\n\t\t\t}),\n\t\t\tmetadata: {\n\t\t\t\t$Infer: {\n\t\t\t\t\tbody: {} as {\n\t\t\t\t\t\torganizationId?: string | undefined;\n\t\t\t\t\t\trole: string;\n\t\t\t\t\t\tpermission: Record<string, string[]>;\n\t\t\t\t\t} & (IsExactlyEmptyObject<AdditionalFields> extends true\n\t\t\t\t\t\t? { additionalFields?: {} | undefined }\n\t\t\t\t\t\t: { additionalFields: AdditionalFields }),\n\t\t\t\t},\n\t\t\t},\n\t\t\trequireHeaders: true,\n\t\t\tuse: [orgSessionMiddleware],\n\t\t},\n\t\tasync (ctx) => {\n\t\t\tconst { session, user } = ctx.context.session;\n\t\t\tlet roleName = ctx.body.role;\n\t\t\tconst permission = ctx.body.permission;\n\t\t\tconst additionalFields = ctx.body.additionalFields;\n\n\t\t\tconst ac = options.ac;\n\t\t\tif (!ac) {\n\t\t\t\tctx.context.logger.error(\n\t\t\t\t\t`[Dynamic Access Control] The organization plugin is missing a pre-defined ac instance.`,\n\t\t\t\t\t`\\nPlease refer to the documentation here: https://better-auth.com/docs/plugins/organization#dynamic-access-control`,\n\t\t\t\t);\n\t\t\t\tthrow new APIError(\"NOT_IMPLEMENTED\", {\n\t\t\t\t\tmessage: ORGANIZATION_ERROR_CODES.MISSING_AC_INSTANCE,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\t// Get the organization id where the role will be created.\n\t\t\t// We can verify if the org id is valid and associated with the user in the next step when we try to find the member.\n\t\t\tconst organizationId =\n\t\t\t\tctx.body.organizationId ?? session.activeOrganizationId;\n\t\t\tif (!organizationId) {\n\t\t\t\tctx.context.logger.error(\n\t\t\t\t\t`[Dynamic Access Control] The session is missing an active organization id to create a role. Either set an active org id, or pass an organizationId in the request body.`,\n\t\t\t\t);\n\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\tmessage:\n\t\t\t\t\t\tORGANIZATION_ERROR_CODES.YOU_MUST_BE_IN_AN_ORGANIZATION_TO_CREATE_A_ROLE,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\troleName = normalizeRoleName(roleName);\n\n\t\t\tawait checkIfRoleNameIsTakenByPreDefinedRole({\n\t\t\t\trole: roleName,\n\t\t\t\torganizationId,\n\t\t\t\toptions,\n\t\t\t\tctx,\n\t\t\t});\n\n\t\t\t// Get the user's role associated with the organization.\n\t\t\t// This also serves as a check to ensure the org id is valid.\n\t\t\tconst member = await ctx.context.adapter.findOne<Member>({\n\t\t\t\tmodel: \"member\",\n\t\t\t\twhere: [\n\t\t\t\t\t{\n\t\t\t\t\t\tfield: \"organizationId\",\n\t\t\t\t\t\tvalue: organizationId,\n\t\t\t\t\t\toperator: \"eq\",\n\t\t\t\t\t\tconnector: \"AND\",\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tfield: \"userId\",\n\t\t\t\t\t\tvalue: user.id,\n\t\t\t\t\t\toperator: \"eq\",\n\t\t\t\t\t\tconnector: \"AND\",\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t});\n\t\t\tif (!member) {\n\t\t\t\tctx.context.logger.error(\n\t\t\t\t\t`[Dynamic Access Control] The user is not a member of the organization to create a role.`,\n\t\t\t\t\t{\n\t\t\t\t\t\tuserId: user.id,\n\t\t\t\t\t\torganizationId,\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t\tthrow new APIError(\"FORBIDDEN\", {\n\t\t\t\t\tmessage:\n\t\t\t\t\t\tORGANIZATION_ERROR_CODES.YOU_ARE_NOT_A_MEMBER_OF_THIS_ORGANIZATION,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst canCreateRole = await hasPermission(\n\t\t\t\t{\n\t\t\t\t\toptions,\n\t\t\t\t\torganizationId,\n\t\t\t\t\tpermissions: {\n\t\t\t\t\t\tac: [\"create\"],\n\t\t\t\t\t},\n\t\t\t\t\trole: member.role,\n\t\t\t\t},\n\t\t\t\tctx,\n\t\t\t);\n\t\t\tif (!canCreateRole) {\n\t\t\t\tctx.context.logger.error(\n\t\t\t\t\t`[Dynamic Access Control] The user is not permitted to create a role. If this is unexpected, please make sure the role associated to that member has the \"ac\" resource with the \"create\" permission.`,\n\t\t\t\t\t{\n\t\t\t\t\t\tuserId: user.id,\n\t\t\t\t\t\torganizationId,\n\t\t\t\t\t\trole: member.role,\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t\tthrow new APIError(\"FORBIDDEN\", {\n\t\t\t\t\tmessage:\n\t\t\t\t\t\tORGANIZATION_ERROR_CODES.YOU_ARE_NOT_ALLOWED_TO_CREATE_A_ROLE,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst maximumRolesPerOrganization =\n\t\t\t\ttypeof options.dynamicAccessControl?.maximumRolesPerOrganization ===\n\t\t\t\t\"function\"\n\t\t\t\t\t? await options.dynamicAccessControl.maximumRolesPerOrganization(\n\t\t\t\t\t\t\torganizationId,\n\t\t\t\t\t\t)\n\t\t\t\t\t: (options.dynamicAccessControl?.maximumRolesPerOrganization ??\n\t\t\t\t\t\tDEFAULT_MAXIMUM_ROLES_PER_ORGANIZATION);\n\t\t\tconst rolesInDB = await ctx.context.adapter.count({\n\t\t\t\tmodel: \"organizationRole\",\n\t\t\t\twhere: [\n\t\t\t\t\t{\n\t\t\t\t\t\tfield: \"organizationId\",\n\t\t\t\t\t\tvalue: organizationId,\n\t\t\t\t\t\toperator: \"eq\",\n\t\t\t\t\t\tconnector: \"AND\",\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t});\n\t\t\tif (rolesInDB >= maximumRolesPerOrganization) {\n\t\t\t\tctx.context.logger.error(\n\t\t\t\t\t`[Dynamic Access Control] Failed to create a new role, the organization has too many roles. Maximum allowed roles is ${maximumRolesPerOrganization}.`,\n\t\t\t\t\t{\n\t\t\t\t\t\torganizationId,\n\t\t\t\t\t\tmaximumRolesPerOrganization,\n\t\t\t\t\t\trolesInDB,\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\tmessage: ORGANIZATION_ERROR_CODES.TOO_MANY_ROLES,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tawait checkForInvalidResources({ ac, ctx, permission });\n\n\t\t\tawait checkIfMemberHasPermission({\n\t\t\t\tctx,\n\t\t\t\tmember,\n\t\t\t\toptions,\n\t\t\t\torganizationId,\n\t\t\t\tpermissionRequired: permission,\n\t\t\t\tuser,\n\t\t\t\taction: \"create\",\n\t\t\t});\n\n\t\t\tawait checkIfRoleNameIsTakenByRoleInDB({\n\t\t\t\tctx,\n\t\t\t\torganizationId,\n\t\t\t\trole: roleName,\n\t\t\t});\n\n\t\t\tconst newRole = ac.newRole(permission);\n\n\t\t\tconst newRoleInDB = await ctx.context.adapter.create<\n\t\t\t\tOmit<OrganizationRole, \"permission\"> & { permission: string }\n\t\t\t>({\n\t\t\t\tmodel: \"organizationRole\",\n\t\t\t\tdata: {\n\t\t\t\t\tcreatedAt: new Date(),\n\t\t\t\t\torganizationId,\n\t\t\t\t\tpermission: JSON.stringify(permission),\n\t\t\t\t\trole: roleName,\n\t\t\t\t\t...additionalFields,\n\t\t\t\t},\n\t\t\t});\n\n\t\t\tconst data = {\n\t\t\t\t...newRoleInDB,\n\t\t\t\tpermission,\n\t\t\t} as OrganizationRole & ReturnAdditionalFields;\n\t\t\treturn ctx.json({\n\t\t\t\tsuccess: true,\n\t\t\t\troleData: data,\n\t\t\t\tstatements: newRole.statements,\n\t\t\t});\n\t\t},\n\t);\n};\n\nconst deleteOrgRoleBodySchema = z\n\t.object({\n\t\torganizationId: z.string().optional().meta({\n\t\t\tdescription:\n\t\t\t\t\"The id of the organization to create the role in. If not provided, the user's active organization will be used.\",\n\t\t}),\n\t})\n\t.and(\n\t\tz.union([\n\t\t\tz.object({\n\t\t\t\troleName: z.string().nonempty().meta({\n\t\t\t\t\tdescription: \"The name of the role to delete\",\n\t\t\t\t}),\n\t\t\t}),\n\t\t\tz.object({\n\t\t\t\troleId: z.string().nonempty().meta({\n\t\t\t\t\tdescription: \"The id of the role to delete\",\n\t\t\t\t}),\n\t\t\t}),\n\t\t]),\n\t);\n\nexport const deleteOrgRole = <O extends OrganizationOptions>(options: O) => {\n\treturn createAuthEndpoint(\n\t\t\"/organization/delete-role\",\n\t\t{\n\t\t\tmethod: \"POST\",\n\t\t\tbody: deleteOrgRoleBodySchema,\n\t\t\trequireHeaders: true,\n\t\t\tuse: [orgSessionMiddleware],\n\t\t\tmetadata: {\n\t\t\t\t$Infer: {\n\t\t\t\t\tbody: {} as {\n\t\t\t\t\t\troleName?: string | undefined;\n\t\t\t\t\t\troleId?: string | undefined;\n\t\t\t\t\t\torganizationId?: string | undefined;\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, user } = ctx.context.session;\n\n\t\t\tconst organizationId =\n\t\t\t\tctx.body.organizationId ?? session.activeOrganizationId;\n\t\t\tif (!organizationId) {\n\t\t\t\tctx.context.logger.error(\n\t\t\t\t\t`[Dynamic Access Control] The session is missing an active organization id to delete a role. Either set an active org id, or pass an organizationId in the request body.`,\n\t\t\t\t);\n\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\tmessage: ORGANIZATION_ERROR_CODES.NO_ACTIVE_ORGANIZATION,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst member = await ctx.context.adapter.findOne<Member>({\n\t\t\t\tmodel: \"member\",\n\t\t\t\twhere: [\n\t\t\t\t\t{\n\t\t\t\t\t\tfield: \"organizationId\",\n\t\t\t\t\t\tvalue: organizationId,\n\t\t\t\t\t\toperator: \"eq\",\n\t\t\t\t\t\tconnector: \"AND\",\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tfield: \"userId\",\n\t\t\t\t\t\tvalue: user.id,\n\t\t\t\t\t\toperator: \"eq\",\n\t\t\t\t\t\tconnector: \"AND\",\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t});\n\t\t\tif (!member) {\n\t\t\t\tctx.context.logger.error(\n\t\t\t\t\t`[Dynamic Access Control] The user is not a member of the organization to delete a role.`,\n\t\t\t\t\t{\n\t\t\t\t\t\tuserId: user.id,\n\t\t\t\t\t\torganizationId,\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t\tthrow new APIError(\"FORBIDDEN\", {\n\t\t\t\t\tmessage:\n\t\t\t\t\t\tORGANIZATION_ERROR_CODES.YOU_ARE_NOT_A_MEMBER_OF_THIS_ORGANIZATION,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst canDeleteRole = await hasPermission(\n\t\t\t\t{\n\t\t\t\t\toptions,\n\t\t\t\t\torganizationId,\n\t\t\t\t\tpermissions: {\n\t\t\t\t\t\tac: [\"delete\"],\n\t\t\t\t\t},\n\t\t\t\t\trole: member.role,\n\t\t\t\t},\n\t\t\t\tctx,\n\t\t\t);\n\t\t\tif (!canDeleteRole) {\n\t\t\t\tctx.context.logger.error(\n\t\t\t\t\t`[Dynamic Access Control] The user is not permitted to delete a role. If this is unexpected, please make sure the role associated to that member has the \"ac\" resource with the \"delete\" permission.`,\n\t\t\t\t\t{\n\t\t\t\t\t\tuserId: user.id,\n\t\t\t\t\t\torganizationId,\n\t\t\t\t\t\trole: member.role,\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t\tthrow new APIError(\"FORBIDDEN\", {\n\t\t\t\t\tmessage:\n\t\t\t\t\t\tORGANIZATION_ERROR_CODES.YOU_ARE_NOT_ALLOWED_TO_DELETE_A_ROLE,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tif (ctx.body.roleName) {\n\t\t\t\tconst roleName = ctx.body.roleName;\n\t\t\t\tconst defaultRoles = options.roles\n\t\t\t\t\t? Object.keys(options.roles)\n\t\t\t\t\t: [\"owner\", \"admin\", \"member\"];\n\t\t\t\tif (defaultRoles.includes(roleName)) {\n\t\t\t\t\tctx.context.logger.error(\n\t\t\t\t\t\t`[Dynamic Access Control] Cannot delete a pre-defined role.`,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\troleName,\n\t\t\t\t\t\t\torganizationId,\n\t\t\t\t\t\t\tdefaultRoles,\n\t\t\t\t\t\t},\n\t\t\t\t\t);\n\t\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\t\tmessage: ORGANIZATION_ERROR_CODES.CANNOT_DELETE_A_PRE_DEFINED_ROLE,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tlet condition: Where;\n\t\t\tif (ctx.body.roleName) {\n\t\t\t\tcondition = {\n\t\t\t\t\tfield: \"role\",\n\t\t\t\t\tvalue: ctx.body.roleName,\n\t\t\t\t\toperator: \"eq\",\n\t\t\t\t\tconnector: \"AND\",\n\t\t\t\t};\n\t\t\t} else if (ctx.body.roleId) {\n\t\t\t\tcondition = {\n\t\t\t\t\tfield: \"id\",\n\t\t\t\t\tvalue: ctx.body.roleId,\n\t\t\t\t\toperator: \"eq\",\n\t\t\t\t\tconnector: \"AND\",\n\t\t\t\t};\n\t\t\t} else {\n\t\t\t\t// shouldn't be able to reach here given the schema validation.\n\t\t\t\t// But just in case, throw an error.\n\t\t\t\tctx.context.logger.error(\n\t\t\t\t\t`[Dynamic Access Control] The role name/id is not provided in the request body.`,\n\t\t\t\t);\n\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\tmessage: ORGANIZATION_ERROR_CODES.ROLE_NOT_FOUND,\n\t\t\t\t});\n\t\t\t}\n\t\t\tconst existingRoleInDB =\n\t\t\t\tawait ctx.context.adapter.findOne<OrganizationRole>({\n\t\t\t\t\tmodel: \"organizationRole\",\n\t\t\t\t\twhere: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tfield: \"organizationId\",\n\t\t\t\t\t\t\tvalue: organizationId,\n\t\t\t\t\t\t\toperator: \"eq\",\n\t\t\t\t\t\t\tconnector: \"AND\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\tcondition,\n\t\t\t\t\t],\n\t\t\t\t});\n\t\t\tif (!existingRoleInDB) {\n\t\t\t\tctx.context.logger.error(\n\t\t\t\t\t`[Dynamic Access Control] The role name/id does not exist in the database.`,\n\t\t\t\t\t{\n\t\t\t\t\t\t...(\"roleName\" in ctx.body\n\t\t\t\t\t\t\t? { roleName: ctx.body.roleName }\n\t\t\t\t\t\t\t: { roleId: ctx.body.roleId }),\n\t\t\t\t\t\torganizationId,\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\tmessage: ORGANIZATION_ERROR_CODES.ROLE_NOT_FOUND,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\texistingRoleInDB.permission = JSON.parse(\n\t\t\t\texistingRoleInDB.permission as never as string,\n\t\t\t);\n\n\t\t\t// Check if any members are assigned to this role\n\t\t\tconst roleToDelete = existingRoleInDB.role;\n\t\t\tconst members = await ctx.context.adapter.findMany<Member>({\n\t\t\t\tmodel: \"member\",\n\t\t\t\twhere: [\n\t\t\t\t\t{\n\t\t\t\t\t\tfield: \"organizationId\",\n\t\t\t\t\t\tvalue: organizationId,\n\t\t\t\t\t\toperator: \"eq\",\n\t\t\t\t\t\tconnector: \"AND\",\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tfield: \"role\",\n\t\t\t\t\t\tvalue: roleToDelete,\n\t\t\t\t\t\toperator: \"contains\",\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t});\n\t\t\tconst memberWithRole = members.find((member) => {\n\t\t\t\tconst memberRoles = member.role.split(\",\").map((r) => r.trim());\n\t\t\t\treturn memberRoles.includes(roleToDelete);\n\t\t\t});\n\t\t\tif (memberWithRole) {\n\t\t\t\tctx.context.logger.error(\n\t\t\t\t\t`[Dynamic Access Control] Cannot delete a role that is assigned to members.`,\n\t\t\t\t\t{\n\t\t\t\t\t\trole: existingRoleInDB.role,\n\t\t\t\t\t\torganizationId,\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\tmessage: ORGANIZATION_ERROR_CODES.ROLE_IS_ASSIGNED_TO_MEMBERS,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tawait ctx.context.adapter.delete({\n\t\t\t\tmodel: \"organizationRole\",\n\t\t\t\twhere: [\n\t\t\t\t\t{\n\t\t\t\t\t\tfield: \"organizationId\",\n\t\t\t\t\t\tvalue: organizationId,\n\t\t\t\t\t\toperator: \"eq\",\n\t\t\t\t\t\tconnector: \"AND\",\n\t\t\t\t\t},\n\t\t\t\t\tcondition,\n\t\t\t\t],\n\t\t\t});\n\n\t\t\treturn ctx.json({\n\t\t\t\tsuccess: true,\n\t\t\t});\n\t\t},\n\t);\n};\n\nconst listOrgRolesQuerySchema = z\n\t.object({\n\t\torganizationId: z.string().optional().meta({\n\t\t\tdescription:\n\t\t\t\t\"The id of the organization to list roles for. If not provided, the user's active organization will be used.\",\n\t\t}),\n\t})\n\t.optional();\n\nexport const listOrgRoles = <O extends OrganizationOptions>(options: O) => {\n\tconst { $ReturnAdditionalFields } = getAdditionalFields<O>(options, false);\n\ttype ReturnAdditionalFields = typeof $ReturnAdditionalFields;\n\n\treturn createAuthEndpoint(\n\t\t\"/organization/list-roles\",\n\t\t{\n\t\t\tmethod: \"GET\",\n\t\t\trequireHeaders: true,\n\t\t\tuse: [orgSessionMiddleware],\n\t\t\tquery: listOrgRolesQuerySchema,\n\t\t},\n\t\tasync (ctx) => {\n\t\t\tconst { session, user } = ctx.context.session;\n\n\t\t\tconst organizationId =\n\t\t\t\tctx.query?.organizationId ?? session.activeOrganizationId;\n\t\t\tif (!organizationId) {\n\t\t\t\tctx.context.logger.error(\n\t\t\t\t\t`[Dynamic Access Control] The session is missing an active organization id to list roles. Either set an active org id, or pass an organizationId in the request query.`,\n\t\t\t\t);\n\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\tmessage: ORGANIZATION_ERROR_CODES.NO_ACTIVE_ORGANIZATION,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst member = await ctx.context.adapter.findOne<Member>({\n\t\t\t\tmodel: \"member\",\n\t\t\t\twhere: [\n\t\t\t\t\t{\n\t\t\t\t\t\tfield: \"organizationId\",\n\t\t\t\t\t\tvalue: organizationId,\n\t\t\t\t\t\toperator: \"eq\",\n\t\t\t\t\t\tconnector: \"AND\",\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tfield: \"userId\",\n\t\t\t\t\t\tvalue: user.id,\n\t\t\t\t\t\toperator: \"eq\",\n\t\t\t\t\t\tconnector: \"AND\",\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t});\n\t\t\tif (!member) {\n\t\t\t\tctx.context.logger.error(\n\t\t\t\t\t`[Dynamic Access Control] The user is not a member of the organization to list roles.`,\n\t\t\t\t\t{\n\t\t\t\t\t\tuserId: user.id,\n\t\t\t\t\t\torganizationId,\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t\tthrow new APIError(\"FORBIDDEN\", {\n\t\t\t\t\tmessage:\n\t\t\t\t\t\tORGANIZATION_ERROR_CODES.YOU_ARE_NOT_A_MEMBER_OF_THIS_ORGANIZATION,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst canListRoles = await hasPermission(\n\t\t\t\t{\n\t\t\t\t\toptions,\n\t\t\t\t\torganizationId,\n\t\t\t\t\tpermissions: {\n\t\t\t\t\t\tac: [\"read\"],\n\t\t\t\t\t},\n\t\t\t\t\trole: member.role,\n\t\t\t\t},\n\t\t\t\tctx,\n\t\t\t);\n\t\t\tif (!canListRoles) {\n\t\t\t\tctx.context.logger.error(\n\t\t\t\t\t`[Dynamic Access Control] The user is not permitted to list roles.`,\n\t\t\t\t\t{\n\t\t\t\t\t\tuserId: user.id,\n\t\t\t\t\t\torganizationId,\n\t\t\t\t\t\trole: member.role,\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t\tthrow new APIError(\"FORBIDDEN\", {\n\t\t\t\t\tmessage: ORGANIZATION_ERROR_CODES.YOU_ARE_NOT_ALLOWED_TO_LIST_A_ROLE,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tlet roles = await ctx.context.adapter.findMany<\n\t\t\t\tOrganizationRole & ReturnAdditionalFields\n\t\t\t>({\n\t\t\t\tmodel: \"organizationRole\",\n\t\t\t\twhere: [\n\t\t\t\t\t{\n\t\t\t\t\t\tfield: \"organizationId\",\n\t\t\t\t\t\tvalue: organizationId,\n\t\t\t\t\t\toperator: \"eq\",\n\t\t\t\t\t\tconnector: \"AND\",\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t});\n\n\t\t\troles = roles.map((x) => ({\n\t\t\t\t...x,\n\t\t\t\tpermission: JSON.parse(x.permission as never as string),\n\t\t\t}));\n\n\t\t\treturn ctx.json(roles);\n\t\t},\n\t);\n};\n\nconst getOrgRoleQuerySchema = z\n\t.object({\n\t\torganizationId: z.string().optional().meta({\n\t\t\tdescription:\n\t\t\t\t\"The id of the organization to read a role for. If not provided, the user's active organization will be used.\",\n\t\t}),\n\t})\n\t.and(\n\t\tz.union([\n\t\t\tz.object({\n\t\t\t\troleName: z.string().nonempty().meta({\n\t\t\t\t\tdescription: \"The name of the role to read\",\n\t\t\t\t}),\n\t\t\t}),\n\t\t\tz.object({\n\t\t\t\troleId: z.string().nonempty().meta({\n\t\t\t\t\tdescription: \"The id of the role to read\",\n\t\t\t\t}),\n\t\t\t}),\n\t\t]),\n\t)\n\t.optional();\n\nexport const getOrgRole = <O extends OrganizationOptions>(options: O) => {\n\tconst { $ReturnAdditionalFields } = getAdditionalFields<O>(options, false);\n\ttype ReturnAdditionalFields = typeof $ReturnAdditionalFields;\n\treturn createAuthEndpoint(\n\t\t\"/organization/get-role\",\n\t\t{\n\t\t\tmethod: \"GET\",\n\t\t\trequireHeaders: true,\n\t\t\tuse: [orgSessionMiddleware],\n\t\t\tquery: getOrgRoleQuerySchema,\n\t\t\tmetadata: {\n\t\t\t\t$Infer: {\n\t\t\t\t\tquery: {} as {\n\t\t\t\t\t\torganizationId?: string | undefined;\n\t\t\t\t\t\troleName?: string | undefined;\n\t\t\t\t\t\troleId?: string | undefined;\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, user } = ctx.context.session;\n\n\t\t\tconst organizationId =\n\t\t\t\tctx.query?.organizationId ?? session.activeOrganizationId;\n\t\t\tif (!organizationId) {\n\t\t\t\tctx.context.logger.error(\n\t\t\t\t\t`[Dynamic Access Control] The session is missing an active organization id to read a role. Either set an active org id, or pass an organizationId in the request query.`,\n\t\t\t\t);\n\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\tmessage: ORGANIZATION_ERROR_CODES.NO_ACTIVE_ORGANIZATION,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst member = await ctx.context.adapter.findOne<Member>({\n\t\t\t\tmodel: \"member\",\n\t\t\t\twhere: [\n\t\t\t\t\t{\n\t\t\t\t\t\tfield: \"organizationId\",\n\t\t\t\t\t\tvalue: organizationId,\n\t\t\t\t\t\toperator: \"eq\",\n\t\t\t\t\t\tconnector: \"AND\",\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tfield: \"userId\",\n\t\t\t\t\t\tvalue: user.id,\n\t\t\t\t\t\toperator: \"eq\",\n\t\t\t\t\t\tconnector: \"AND\",\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t});\n\t\t\tif (!member) {\n\t\t\t\tctx.context.logger.error(\n\t\t\t\t\t`[Dynamic Access Control] The user is not a member of the organization to read a role.`,\n\t\t\t\t\t{\n\t\t\t\t\t\tuserId: user.id,\n\t\t\t\t\t\torganizationId,\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t\tthrow new APIError(\"FORBIDDEN\", {\n\t\t\t\t\tmessage:\n\t\t\t\t\t\tORGANIZATION_ERROR_CODES.YOU_ARE_NOT_A_MEMBER_OF_THIS_ORGANIZATION,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst canListRoles = await hasPermission(\n\t\t\t\t{\n\t\t\t\t\toptions,\n\t\t\t\t\torganizationId,\n\t\t\t\t\tpermissions: {\n\t\t\t\t\t\tac: [\"read\"],\n\t\t\t\t\t},\n\t\t\t\t\trole: member.role,\n\t\t\t\t},\n\t\t\t\tctx,\n\t\t\t);\n\t\t\tif (!canListRoles) {\n\t\t\t\tctx.context.logger.error(\n\t\t\t\t\t`[Dynamic Access Control] The user is not permitted to read a role.`,\n\t\t\t\t\t{\n\t\t\t\t\t\tuserId: user.id,\n\t\t\t\t\t\torganizationId,\n\t\t\t\t\t\trole: member.role,\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t\tthrow new APIError(\"FORBIDDEN\", {\n\t\t\t\t\tmessage: ORGANIZATION_ERROR_CODES.YOU_ARE_NOT_ALLOWED_TO_READ_A_ROLE,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tlet condition: Where;\n\t\t\tif (ctx.query.roleName) {\n\t\t\t\tcondition = {\n\t\t\t\t\tfield: \"role\",\n\t\t\t\t\tvalue: ctx.query.roleName,\n\t\t\t\t\toperator: \"eq\",\n\t\t\t\t\tconnector: \"AND\",\n\t\t\t\t};\n\t\t\t} else if (ctx.query.roleId) {\n\t\t\t\tcondition = {\n\t\t\t\t\tfield: \"id\",\n\t\t\t\t\tvalue: ctx.query.roleId,\n\t\t\t\t\toperator: \"eq\",\n\t\t\t\t\tconnector: \"AND\",\n\t\t\t\t};\n\t\t\t} else {\n\t\t\t\t// shouldn't be able to reach here given the schema validation.\n\t\t\t\t// But just in case, throw an error.\n\t\t\t\tctx.context.logger.error(\n\t\t\t\t\t`[Dynamic Access Control] The role name/id is not provided in the request query.`,\n\t\t\t\t);\n\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\tmessage: ORGANIZATION_ERROR_CODES.ROLE_NOT_FOUND,\n\t\t\t\t});\n\t\t\t}\n\t\t\tconst role = await ctx.context.adapter.findOne<OrganizationRole>({\n\t\t\t\tmodel: \"organizationRole\",\n\t\t\t\twhere: [\n\t\t\t\t\t{\n\t\t\t\t\t\tfield: \"organizationId\",\n\t\t\t\t\t\tvalue: organizationId,\n\t\t\t\t\t\toperator: \"eq\",\n\t\t\t\t\t\tconnector: \"AND\",\n\t\t\t\t\t},\n\t\t\t\t\tcondition,\n\t\t\t\t],\n\t\t\t});\n\t\t\tif (!role) {\n\t\t\t\tctx.context.logger.error(\n\t\t\t\t\t`[Dynamic Access Control] The role name/id does not exist in the database.`,\n\t\t\t\t\t{\n\t\t\t\t\t\t...(\"roleName\" in ctx.query\n\t\t\t\t\t\t\t? { roleName: ctx.query.roleName }\n\t\t\t\t\t\t\t: { roleId: ctx.query.roleId }),\n\t\t\t\t\t\torganizationId,\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\tmessage: ORGANIZATION_ERROR_CODES.ROLE_NOT_FOUND,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\trole.permission = JSON.parse(role.permission as never as string);\n\n\t\t\treturn ctx.json(role as OrganizationRole & ReturnAdditionalFields);\n\t\t},\n\t);\n};\n\nconst roleNameOrIdSchema = z.union([\n\tz.object({\n\t\troleName: z.string().nonempty().meta({\n\t\t\tdescription: \"The name of the role to update\",\n\t\t}),\n\t}),\n\tz.object({\n\t\troleId: z.string().nonempty().meta({\n\t\t\tdescription: \"The id of the role to update\",\n\t\t}),\n\t}),\n]);\n\nexport const updateOrgRole = <O extends OrganizationOptions>(options: O) => {\n\tconst { additionalFieldsSchema, $AdditionalFields, $ReturnAdditionalFields } =\n\t\tgetAdditionalFields<O, true>(options, true);\n\ttype AdditionalFields = typeof $AdditionalFields;\n\ttype ReturnAdditionalFields = typeof $ReturnAdditionalFields;\n\n\treturn createAuthEndpoint(\n\t\t\"/organization/update-role\",\n\t\t{\n\t\t\tmethod: \"POST\",\n\t\t\tbody: z\n\t\t\t\t.object({\n\t\t\t\t\torganizationId: z.string().optional().meta({\n\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\"The id of the organization to update the role in. If not provided, the user's active organization will be used.\",\n\t\t\t\t\t}),\n\t\t\t\t\tdata: z.object({\n\t\t\t\t\t\tpermission: z\n\t\t\t\t\t\t\t.record(z.string(), z.array(z.string()))\n\t\t\t\t\t\t\t.optional()\n\t\t\t\t\t\t\t.meta({\n\t\t\t\t\t\t\t\tdescription: \"The permission to update the role with\",\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\troleName: z.string().optional().meta({\n\t\t\t\t\t\t\tdescription: \"The name of the role to update\",\n\t\t\t\t\t\t}),\n\t\t\t\t\t\t...additionalFieldsSchema.shape,\n\t\t\t\t\t}),\n\t\t\t\t})\n\t\t\t\t.and(roleNameOrIdSchema),\n\t\t\tmetadata: {\n\t\t\t\t$Infer: {\n\t\t\t\t\tbody: {} as {\n\t\t\t\t\t\torganizationId?: string | undefined;\n\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\tpermission?: Record<string, string[]> | undefined;\n\t\t\t\t\t\t\troleName?: string | undefined;\n\t\t\t\t\t\t} & AdditionalFields;\n\t\t\t\t\t\troleName?: string | undefined;\n\t\t\t\t\t\troleId?: string | undefined;\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\trequireHeaders: true,\n\t\t\tuse: [orgSessionMiddleware],\n\t\t},\n\t\tasync (ctx) => {\n\t\t\tconst { session, user } = ctx.context.session;\n\n\t\t\tconst ac = options.ac;\n\t\t\tif (!ac) {\n\t\t\t\tctx.context.logger.error(\n\t\t\t\t\t`[Dynamic Access Control] The organization plugin is missing a pre-defined ac instance.`,\n\t\t\t\t\t`\\nPlease refer to the documentation here: https://better-auth.com/docs/plugins/organization#dynamic-access-control`,\n\t\t\t\t);\n\t\t\t\tthrow new APIError(\"NOT_IMPLEMENTED\", {\n\t\t\t\t\tmessage: ORGANIZATION_ERROR_CODES.MISSING_AC_INSTANCE,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst organizationId =\n\t\t\t\tctx.body.organizationId ?? session.activeOrganizationId;\n\t\t\tif (!organizationId) {\n\t\t\t\tctx.context.logger.error(\n\t\t\t\t\t`[Dynamic Access Control] The session is missing an active organization id to update a role. Either set an active org id, or pass an organizationId in the request body.`,\n\t\t\t\t);\n\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\tmessage: ORGANIZATION_ERROR_CODES.NO_ACTIVE_ORGANIZATION,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst member = await ctx.context.adapter.findOne<Member>({\n\t\t\t\tmodel: \"member\",\n\t\t\t\twhere: [\n\t\t\t\t\t{\n\t\t\t\t\t\tfield: \"organizationId\",\n\t\t\t\t\t\tvalue: organizationId,\n\t\t\t\t\t\toperator: \"eq\",\n\t\t\t\t\t\tconnector: \"AND\",\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tfield: \"userId\",\n\t\t\t\t\t\tvalue: user.id,\n\t\t\t\t\t\toperator: \"eq\",\n\t\t\t\t\t\tconnector: \"AND\",\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t});\n\t\t\tif (!member) {\n\t\t\t\tctx.context.logger.error(\n\t\t\t\t\t`[Dynamic Access Control] The user is not a member of the organization to update a role.`,\n\t\t\t\t\t{\n\t\t\t\t\t\tuserId: user.id,\n\t\t\t\t\t\torganizationId,\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t\tthrow new APIError(\"FORBIDDEN\", {\n\t\t\t\t\tmessage:\n\t\t\t\t\t\tORGANIZATION_ERROR_CODES.YOU_ARE_NOT_A_MEMBER_OF_THIS_ORGANIZATION,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst canUpdateRole = await hasPermission(\n\t\t\t\t{\n\t\t\t\t\toptions,\n\t\t\t\t\torganizationId,\n\t\t\t\t\trole: member.role,\n\t\t\t\t\tpermissions: {\n\t\t\t\t\t\tac: [\"update\"],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tctx,\n\t\t\t);\n\t\t\tif (!canUpdateRole) {\n\t\t\t\tctx.context.logger.error(\n\t\t\t\t\t`[Dynamic Access Control] The user is not permitted to update a role.`,\n\t\t\t\t);\n\t\t\t\tthrow new APIError(\"FORBIDDEN\", {\n\t\t\t\t\tmessage:\n\t\t\t\t\t\tORGANIZATION_ERROR_CODES.YOU_ARE_NOT_ALLOWED_TO_UPDATE_A_ROLE,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tlet condition: Where;\n\t\t\tif (ctx.body.roleName) {\n\t\t\t\tcondition = {\n\t\t\t\t\tfield: \"role\",\n\t\t\t\t\tvalue: ctx.body.roleName,\n\t\t\t\t\toperator: \"eq\",\n\t\t\t\t\tconnector: \"AND\",\n\t\t\t\t};\n\t\t\t} else if (ctx.body.roleId) {\n\t\t\t\tcondition = {\n\t\t\t\t\tfield: \"id\",\n\t\t\t\t\tvalue: ctx.body.roleId,\n\t\t\t\t\toperator: \"eq\",\n\t\t\t\t\tconnector: \"AND\",\n\t\t\t\t};\n\t\t\t} else {\n\t\t\t\t// shouldn't be able to reach here given the schema validation.\n\t\t\t\t// But just in case, throw an error.\n\t\t\t\tctx.context.logger.error(\n\t\t\t\t\t`[Dynamic Access Control] The role name/id is not provided in the request body.`,\n\t\t\t\t);\n\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\tmessage: ORGANIZATION_ERROR_CODES.ROLE_NOT_FOUND,\n\t\t\t\t});\n\t\t\t}\n\t\t\tconst role = await ctx.context.adapter.findOne<OrganizationRole>({\n\t\t\t\tmodel: \"organizationRole\",\n\t\t\t\twhere: [\n\t\t\t\t\t{\n\t\t\t\t\t\tfield: \"organizationId\",\n\t\t\t\t\t\tvalue: organizationId,\n\t\t\t\t\t\toperator: \"eq\",\n\t\t\t\t\t\tconnector: \"AND\",\n\t\t\t\t\t},\n\t\t\t\t\tcondition,\n\t\t\t\t],\n\t\t\t});\n\t\t\tif (!role) {\n\t\t\t\tctx.context.logger.error(\n\t\t\t\t\t`[Dynamic Access Control] The role name/id does not exist in the database.`,\n\t\t\t\t\t{\n\t\t\t\t\t\t...(\"roleName\" in ctx.body\n\t\t\t\t\t\t\t? { roleName: ctx.body.roleName }\n\t\t\t\t\t\t\t: { roleId: ctx.body.roleId }),\n\t\t\t\t\t\torganizationId,\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\tmessage: ORGANIZATION_ERROR_CODES.ROLE_NOT_FOUND,\n\t\t\t\t});\n\t\t\t}\n\t\t\trole.permission = role.permission\n\t\t\t\t? JSON.parse(role.permission as never as string)\n\t\t\t\t: undefined;\n\n\t\t\tconst {\n\t\t\t\tpermission: _,\n\t\t\t\troleName: __,\n\t\t\t\t...additionalFields\n\t\t\t} = ctx.body.data;\n\n\t\t\tconst updateData: Partial<OrganizationRole> = {\n\t\t\t\t...additionalFields,\n\t\t\t};\n\n\t\t\tif (ctx.body.data.permission) {\n\t\t\t\tconst newPermission = ctx.body.data.permission;\n\n\t\t\t\tawait checkForInvalidResources({ ac, ctx, permission: newPermission });\n\n\t\t\t\tawait checkIfMemberHasPermission({\n\t\t\t\t\tctx,\n\t\t\t\t\tmember,\n\t\t\t\t\toptions,\n\t\t\t\t\torganizationId,\n\t\t\t\t\tpermissionRequired: newPermission,\n\t\t\t\t\tuser,\n\t\t\t\t\taction: \"update\",\n\t\t\t\t});\n\n\t\t\t\tupdateData.permission = newPermission;\n\t\t\t}\n\t\t\tif (ctx.body.data.roleName) {\n\t\t\t\tlet newRoleName = ctx.body.data.roleName;\n\n\t\t\t\tnewRoleName = normalizeRoleName(newRoleName);\n\n\t\t\t\tawait checkIfRoleNameIsTakenByPreDefinedRole({\n\t\t\t\t\trole: newRoleName,\n\t\t\t\t\torganizationId,\n\t\t\t\t\toptions,\n\t\t\t\t\tctx,\n\t\t\t\t});\n\t\t\t\tawait checkIfRoleNameIsTakenByRoleInDB({\n\t\t\t\t\trole: newRoleName,\n\t\t\t\t\torganizationId,\n\t\t\t\t\tctx,\n\t\t\t\t});\n\n\t\t\t\tupdateData.role = newRoleName;\n\t\t\t}\n\n\t\t\t// -----\n\t\t\t// Apply the updates\n\t\t\tconst update = {\n\t\t\t\t...updateData,\n\t\t\t\t...(updateData.permission\n\t\t\t\t\t? { permission: JSON.stringify(updateData.permission) }\n\t\t\t\t\t: {}),\n\t\t\t};\n\t\t\tawait ctx.context.adapter.update<OrganizationRole>({\n\t\t\t\tmodel: \"organizationRole\",\n\t\t\t\twhere: [\n\t\t\t\t\t{\n\t\t\t\t\t\tfield: \"organizationId\",\n\t\t\t\t\t\tvalue: organizationId,\n\t\t\t\t\t\toperator: \"eq\",\n\t\t\t\t\t\tconnector: \"AND\",\n\t\t\t\t\t},\n\t\t\t\t\tcondition,\n\t\t\t\t],\n\t\t\t\tupdate,\n\t\t\t});\n\n\t\t\t// -----\n\t\t\t// Return the updated role\n\t\t\treturn ctx.json({\n\t\t\t\tsuccess: true,\n\t\t\t\troleData: {\n\t\t\t\t\t...role,\n\t\t\t\t\t...update,\n\t\t\t\t\tpermission: updateData.permission || role.permission || null,\n\t\t\t\t} as OrganizationRole & ReturnAdditionalFields,\n\t\t\t});\n\t\t},\n\t);\n};\n\nasync function checkForInvalidResources({\n\tac,\n\tctx,\n\tpermission,\n}: {\n\tac: AccessControl;\n\tctx: GenericEndpointContext;\n\tpermission: Record<string, string[]>;\n}) {\n\tconst validResources = Object.keys(ac.statements);\n\tconst providedResources = Object.keys(permission);\n\tconst hasInvalidResource = providedResources.some(\n\t\t(r) => !validResources.includes(r),\n\t);\n\tif (hasInvalidResource) {\n\t\tctx.context.logger.error(\n\t\t\t`[Dynamic Access Control] The provided permission includes an invalid resource.`,\n\t\t\t{\n\t\t\t\tprovidedResources,\n\t\t\t\tvalidResources,\n\t\t\t},\n\t\t);\n\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\tmessage: ORGANIZATION_ERROR_CODES.INVALID_RESOURCE,\n\t\t});\n\t}\n}\n\nasync function checkIfMemberHasPermission({\n\tctx,\n\tpermissionRequired: permission,\n\toptions,\n\torganizationId,\n\tmember,\n\tuser,\n\taction,\n}: {\n\tctx: GenericEndpointContext;\n\tpermissionRequired: Record<string, string[]>;\n\toptions: OrganizationOptions;\n\torganizationId: string;\n\tmember: Member;\n\tuser: User;\n\taction: \"create\" | \"update\" | \"delete\" | \"read\" | \"list\" | \"get\";\n}) {\n\tconst hasNecessaryPermissions: {\n\t\tresource: { [x: string]: string[] };\n\t\thasPermission: boolean;\n\t}[] = [];\n\tconst permissionEntries = Object.entries(permission);\n\tfor await (const [resource, permissions] of permissionEntries) {\n\t\tfor await (const perm of permissions) {\n\t\t\thasNecessaryPermissions.push({\n\t\t\t\tresource: { [resource]: [perm] },\n\t\t\t\thasPermission: await hasPermission(\n\t\t\t\t\t{\n\t\t\t\t\t\toptions,\n\t\t\t\t\t\torganizationId,\n\t\t\t\t\t\tpermissions: { [resource]: [perm] },\n\t\t\t\t\t\tuseMemoryCache: true,\n\t\t\t\t\t\trole: member.role,\n\t\t\t\t\t},\n\t\t\t\t\tctx,\n\t\t\t\t),\n\t\t\t});\n\t\t}\n\t}\n\tconst missingPermissions = hasNecessaryPermissions\n\t\t.filter((x) => x.hasPermission === false)\n\t\t.map((x) => {\n\t\t\tconst key = Object.keys(x.resource)[0]!;\n\t\t\treturn `${key}:${x.resource[key]![0]}` as const;\n\t\t});\n\tif (missingPermissions.length > 0) {\n\t\tctx.context.logger.error(\n\t\t\t`[Dynamic Access Control] The user is missing permissions necessary to ${action} a role with those set of permissions.\\n`,\n\t\t\t{\n\t\t\t\tuserId: user.id,\n\t\t\t\torganizationId,\n\t\t\t\trole: member.role,\n\t\t\t\tmissingPermissions,\n\t\t\t},\n\t\t);\n\t\tlet errorMessage: string;\n\t\tif (action === \"create\")\n\t\t\terrorMessage =\n\t\t\t\tORGANIZATION_ERROR_CODES.YOU_ARE_NOT_ALLOWED_TO_CREATE_A_ROLE;\n\t\telse if (action === \"update\")\n\t\t\terrorMessage =\n\t\t\t\tORGANIZATION_ERROR_CODES.YOU_ARE_NOT_ALLOWED_TO_UPDATE_A_ROLE;\n\t\telse if (action === \"delete\")\n\t\t\terrorMessage =\n\t\t\t\tORGANIZATION_ERROR_CODES.YOU_ARE_NOT_ALLOWED_TO_DELETE_A_ROLE;\n\t\telse if (action === \"read\")\n\t\t\terrorMessage =\n\t\t\t\tORGANIZATION_ERROR_CODES.YOU_ARE_NOT_ALLOWED_TO_READ_A_ROLE;\n\t\telse if (action === \"list\")\n\t\t\terrorMessage =\n\t\t\t\tORGANIZATION_ERROR_CODES.YOU_ARE_NOT_ALLOWED_TO_LIST_A_ROLE;\n\t\telse\n\t\t\terrorMessage = ORGANIZATION_ERROR_CODES.YOU_ARE_NOT_ALLOWED_TO_GET_A_ROLE;\n\n\t\tthrow new APIError(\"FORBIDDEN\", {\n\t\t\tmessage: errorMessage,\n\t\t\tmissingPermissions,\n\t\t});\n\t}\n}\n\nasync function checkIfRoleNameIsTakenByPreDefinedRole({\n\toptions,\n\torganizationId,\n\trole,\n\tctx,\n}: {\n\toptions: OrganizationOptions;\n\torganizationId: string;\n\trole: string;\n\tctx: GenericEndpointContext;\n}) {\n\tconst defaultRoles = options.roles\n\t\t? Object.keys(options.roles)\n\t\t: [\"owner\", \"admin\", \"member\"];\n\tif (defaultRoles.includes(role)) {\n\t\tctx.context.logger.error(\n\t\t\t`[Dynamic Access Control] The role name \"${role}\" is already taken by a pre-defined role.`,\n\t\t\t{\n\t\t\t\trole,\n\t\t\t\torganizationId,\n\t\t\t\tdefaultRoles,\n\t\t\t},\n\t\t);\n\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\tmessage: ORGANIZATION_ERROR_CODES.ROLE_NAME_IS_ALREADY_TAKEN,\n\t\t});\n\t}\n}\n\nasync function checkIfRoleNameIsTakenByRoleInDB({\n\torganizationId,\n\trole,\n\tctx,\n}: {\n\tctx: GenericEndpointContext;\n\torganizationId: string;\n\trole: string;\n}) {\n\tconst existingRoleInDB = await ctx.context.adapter.findOne<OrganizationRole>({\n\t\tmodel: \"organizationRole\",\n\t\twhere: [\n\t\t\t{\n\t\t\t\tfield: \"organizationId\",\n\t\t\t\tvalue: organizationId,\n\t\t\t\toperator: \"eq\",\n\t\t\t\tconnector: \"AND\",\n\t\t\t},\n\t\t\t{\n\t\t\t\tfield: \"role\",\n\t\t\t\tvalue: role,\n\t\t\t\toperator: \"eq\",\n\t\t\t\tconnector: \"AND\",\n\t\t\t},\n\t\t],\n\t});\n\tif (existingRoleInDB) {\n\t\tctx.context.logger.error(\n\t\t\t`[Dynamic Access Control] The role name \"${role}\" is already taken by a role in the database.`,\n\t\t\t{\n\t\t\t\trole,\n\t\t\t\torganizationId,\n\t\t\t},\n\t\t);\n\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\tmessage: ORGANIZATION_ERROR_CODES.ROLE_NAME_IS_ALREADY_TAKEN,\n\t\t});\n\t}\n}\n"],"mappings":";;;;;;;;;;AAuBA,MAAM,qBAAqB,SAAiB,KAAK,aAAa;AAC9D,MAAM,yCAAyC,OAAO;AAEtD,MAAM,uBAIL,SACA,kBAA8B,UAC1B;CACJ,MAAM,mBACL,SAAS,QAAQ,kBAAkB,oBAAoB,EAAE;AAC1D,KAAI,gBACH,MAAK,MAAM,OAAO,iBACjB,kBAAiB,KAAM,WAAW;AAgBpC,QAAO;EACN,wBAd8B,YAAY;GAC1C,QAAQ;GACR,cAAc;GACd,CAAC;EAYD,mBAAmB,EAAE;EACrB,yBAAyB,EAAE;EAC3B;;AAGF,MAAM,0BAA0B,EAAE,OAAO;CACxC,gBAAgB,EAAE,QAAQ,CAAC,UAAU,CAAC,KAAK,EAC1C,aACC,mHACD,CAAC;CACF,MAAM,EAAE,QAAQ,CAAC,KAAK,EACrB,aAAa,kCACb,CAAC;CACF,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,KAAK,EAC1D,aAAa,wCACb,CAAC;CACF,CAAC;AAEF,MAAa,iBAAgD,YAAe;CAC3E,MAAM,EAAE,wBAAwB,mBAAmB,4BAClD,oBAAuB,SAAS,MAAM;AAIvC,QAAO,mBACN,6BACA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KAAM;GACjC;AACH,KAAI,mBAAmB,SAAS,GAAG;AAClC,MAAI,QAAQ,OAAO,MAClB,yEAAyE,OAAO,2CAChF;GACC,QAAQ,KAAK;GACb;GACA,MAAM,OAAO;GACb;GACA,CACD;EACD,IAAIC;AACJ,MAAI,WAAW,SACd,gBACC,yBAAyB;WAClB,WAAW,SACnB,gBACC,yBAAyB;WAClB,WAAW,SACnB,gBACC,yBAAyB;WAClB,WAAW,OACnB,gBACC,yBAAyB;WAClB,WAAW,OACnB,gBACC,yBAAyB;MAE1B,gBAAe,yBAAyB;AAEzC,QAAM,IAAI,SAAS,aAAa;GAC/B,SAAS;GACT;GACA,CAAC;;;AAIJ,eAAe,uCAAuC,EACrD,SACA,gBACA,MACA,OAME;CACF,MAAM,eAAe,QAAQ,QAC1B,OAAO,KAAK,QAAQ,MAAM,GAC1B;EAAC;EAAS;EAAS;EAAS;AAC/B,KAAI,aAAa,SAAS,KAAK,EAAE;AAChC,MAAI,QAAQ,OAAO,MAClB,2CAA2C,KAAK,4CAChD;GACC;GACA;GACA;GACA,CACD;AACD,QAAM,IAAI,SAAS,eAAe,EACjC,SAAS,yBAAyB,4BAClC,CAAC;;;AAIJ,eAAe,iCAAiC,EAC/C,gBACA,MACA,OAKE;AAkBF,KAjByB,MAAM,IAAI,QAAQ,QAAQ,QAA0B;EAC5E,OAAO;EACP,OAAO,CACN;GACC,OAAO;GACP,OAAO;GACP,UAAU;GACV,WAAW;GACX,EACD;GACC,OAAO;GACP,OAAO;GACP,UAAU;GACV,WAAW;GACX,CACD;EACD,CAAC,EACoB;AACrB,MAAI,QAAQ,OAAO,MAClB,2CAA2C,KAAK,gDAChD;GACC;GACA;GACA,CACD;AACD,QAAM,IAAI,SAAS,eAAe,EACjC,SAAS,yBAAyB,4BAClC,CAAC"}
@@ -6,29 +6,29 @@ import { InferOrganizationRolesFromOption, InvitationStatus } from "../schema.mj
6
6
  import "../../index.mjs";
7
7
  import { defaultRoles } from "../access/statement.mjs";
8
8
  import "../index.mjs";
9
- import * as _better_auth_core54 from "@better-auth/core";
10
- import * as _better_auth_core_db95 from "@better-auth/core/db";
11
- import * as better_call893 from "better-call";
9
+ import * as _better_auth_core45 from "@better-auth/core";
10
+ import * as _better_auth_core_db60 from "@better-auth/core/db";
11
+ import * as better_call845 from "better-call";
12
12
  import * as z from "zod";
13
13
 
14
14
  //#region src/plugins/organization/routes/crud-invites.d.ts
15
- declare const createInvitation: <O extends OrganizationOptions>(option: O) => better_call893.StrictEndpoint<"/organization/invite-member", {
15
+ declare const createInvitation: <O extends OrganizationOptions>(option: O) => better_call845.StrictEndpoint<"/organization/invite-member", {
16
16
  method: "POST";
17
17
  requireHeaders: true;
18
- use: (((inputContext: better_call893.MiddlewareInputContext<better_call893.MiddlewareOptions>) => Promise<{
18
+ use: (((inputContext: better_call845.MiddlewareInputContext<better_call845.MiddlewareOptions>) => Promise<{
19
19
  orgOptions: OrganizationOptions;
20
20
  roles: typeof defaultRoles & {
21
21
  [key: string]: Role<{}>;
22
22
  };
23
- getSession: (context: _better_auth_core54.GenericEndpointContext) => Promise<{
24
- session: _better_auth_core_db95.Session & {
23
+ getSession: (context: _better_auth_core45.GenericEndpointContext) => Promise<{
24
+ session: _better_auth_core_db60.Session & {
25
25
  activeTeamId?: string | undefined;
26
26
  activeOrganizationId?: string | undefined;
27
27
  };
28
- user: _better_auth_core_db95.User;
28
+ user: _better_auth_core_db60.User;
29
29
  }>;
30
- }>) | ((inputContext: better_call893.MiddlewareInputContext<{
31
- use: ((inputContext: better_call893.MiddlewareInputContext<better_call893.MiddlewareOptions>) => Promise<{
30
+ }>) | ((inputContext: better_call845.MiddlewareInputContext<{
31
+ use: ((inputContext: better_call845.MiddlewareInputContext<better_call845.MiddlewareOptions>) => Promise<{
32
32
  session: {
33
33
  session: Record<string, any> & {
34
34
  id: string;
@@ -53,11 +53,11 @@ declare const createInvitation: <O extends OrganizationOptions>(option: O) => be
53
53
  }>)[];
54
54
  }>) => Promise<{
55
55
  session: {
56
- session: _better_auth_core_db95.Session & {
56
+ session: _better_auth_core_db60.Session & {
57
57
  activeTeamId?: string | undefined;
58
58
  activeOrganizationId?: string | undefined;
59
59
  };
60
- user: _better_auth_core_db95.User;
60
+ user: _better_auth_core_db60.User;
61
61
  };
62
62
  }>))[];
63
63
  body: z.ZodObject<{
@@ -168,7 +168,7 @@ declare const createInvitation: <O extends OrganizationOptions>(option: O) => be
168
168
  createdAt: Date;
169
169
  }) & (O["schema"] extends {
170
170
  invitation?: {
171
- additionalFields: infer Field extends Record<string, _better_auth_core_db95.DBFieldAttribute>;
171
+ additionalFields: infer Field extends Record<string, _better_auth_core_db60.DBFieldAttribute>;
172
172
  } | undefined;
173
173
  } ? FieldAttributeToObject<Field> : {}) extends infer T ? { [K in keyof T]: T[K] } : never) | ((O["teams"] extends {
174
174
  enabled: true;
@@ -193,29 +193,29 @@ declare const createInvitation: <O extends OrganizationOptions>(option: O) => be
193
193
  createdAt: Date;
194
194
  }) & (O["schema"] extends {
195
195
  invitation?: {
196
- additionalFields: infer Field extends Record<string, _better_auth_core_db95.DBFieldAttribute>;
196
+ additionalFields: infer Field extends Record<string, _better_auth_core_db60.DBFieldAttribute>;
197
197
  } | undefined;
198
198
  } ? FieldAttributeToObject<RemoveFieldsWithReturnedFalse<Field>> : {}) extends infer T_1 ? { [K_1 in keyof T_1]: T_1[K_1] } : never)>;
199
- declare const acceptInvitation: <O extends OrganizationOptions>(options: O) => better_call893.StrictEndpoint<"/organization/accept-invitation", {
199
+ declare const acceptInvitation: <O extends OrganizationOptions>(options: O) => better_call845.StrictEndpoint<"/organization/accept-invitation", {
200
200
  method: "POST";
201
201
  body: z.ZodObject<{
202
202
  invitationId: z.ZodString;
203
203
  }, z.core.$strip>;
204
204
  requireHeaders: true;
205
- use: (((inputContext: better_call893.MiddlewareInputContext<better_call893.MiddlewareOptions>) => Promise<{
205
+ use: (((inputContext: better_call845.MiddlewareInputContext<better_call845.MiddlewareOptions>) => Promise<{
206
206
  orgOptions: OrganizationOptions;
207
207
  roles: typeof defaultRoles & {
208
208
  [key: string]: Role<{}>;
209
209
  };
210
- getSession: (context: _better_auth_core54.GenericEndpointContext) => Promise<{
211
- session: _better_auth_core_db95.Session & {
210
+ getSession: (context: _better_auth_core45.GenericEndpointContext) => Promise<{
211
+ session: _better_auth_core_db60.Session & {
212
212
  activeTeamId?: string | undefined;
213
213
  activeOrganizationId?: string | undefined;
214
214
  };
215
- user: _better_auth_core_db95.User;
215
+ user: _better_auth_core_db60.User;
216
216
  }>;
217
- }>) | ((inputContext: better_call893.MiddlewareInputContext<{
218
- use: ((inputContext: better_call893.MiddlewareInputContext<better_call893.MiddlewareOptions>) => Promise<{
217
+ }>) | ((inputContext: better_call845.MiddlewareInputContext<{
218
+ use: ((inputContext: better_call845.MiddlewareInputContext<better_call845.MiddlewareOptions>) => Promise<{
219
219
  session: {
220
220
  session: Record<string, any> & {
221
221
  id: string;
@@ -240,11 +240,11 @@ declare const acceptInvitation: <O extends OrganizationOptions>(options: O) => b
240
240
  }>)[];
241
241
  }>) => Promise<{
242
242
  session: {
243
- session: _better_auth_core_db95.Session & {
243
+ session: _better_auth_core_db60.Session & {
244
244
  activeTeamId?: string | undefined;
245
245
  activeOrganizationId?: string | undefined;
246
246
  };
247
- user: _better_auth_core_db95.User;
247
+ user: _better_auth_core_db60.User;
248
248
  };
249
249
  }>))[];
250
250
  metadata: {
@@ -296,7 +296,7 @@ declare const acceptInvitation: <O extends OrganizationOptions>(options: O) => b
296
296
  createdAt: Date;
297
297
  }) & (O["schema"] extends {
298
298
  invitation?: {
299
- additionalFields: infer Field extends Record<string, _better_auth_core_db95.DBFieldAttribute>;
299
+ additionalFields: infer Field extends Record<string, _better_auth_core_db60.DBFieldAttribute>;
300
300
  } | undefined;
301
301
  } ? FieldAttributeToObject<Field> : {}) extends infer T ? { [K in keyof T]: T[K] } : never;
302
302
  member: {
@@ -306,27 +306,27 @@ declare const acceptInvitation: <O extends OrganizationOptions>(options: O) => b
306
306
  role: string;
307
307
  createdAt: Date;
308
308
  } & InferAdditionalFieldsFromPluginOptions<"member", O, false>;
309
- } | null>;
310
- declare const rejectInvitation: <O extends OrganizationOptions>(options: O) => better_call893.StrictEndpoint<"/organization/reject-invitation", {
309
+ }>;
310
+ declare const rejectInvitation: <O extends OrganizationOptions>(options: O) => better_call845.StrictEndpoint<"/organization/reject-invitation", {
311
311
  method: "POST";
312
312
  body: z.ZodObject<{
313
313
  invitationId: z.ZodString;
314
314
  }, z.core.$strip>;
315
315
  requireHeaders: true;
316
- use: (((inputContext: better_call893.MiddlewareInputContext<better_call893.MiddlewareOptions>) => Promise<{
316
+ use: (((inputContext: better_call845.MiddlewareInputContext<better_call845.MiddlewareOptions>) => Promise<{
317
317
  orgOptions: OrganizationOptions;
318
318
  roles: typeof defaultRoles & {
319
319
  [key: string]: Role<{}>;
320
320
  };
321
- getSession: (context: _better_auth_core54.GenericEndpointContext) => Promise<{
322
- session: _better_auth_core_db95.Session & {
321
+ getSession: (context: _better_auth_core45.GenericEndpointContext) => Promise<{
322
+ session: _better_auth_core_db60.Session & {
323
323
  activeTeamId?: string | undefined;
324
324
  activeOrganizationId?: string | undefined;
325
325
  };
326
- user: _better_auth_core_db95.User;
326
+ user: _better_auth_core_db60.User;
327
327
  }>;
328
- }>) | ((inputContext: better_call893.MiddlewareInputContext<{
329
- use: ((inputContext: better_call893.MiddlewareInputContext<better_call893.MiddlewareOptions>) => Promise<{
328
+ }>) | ((inputContext: better_call845.MiddlewareInputContext<{
329
+ use: ((inputContext: better_call845.MiddlewareInputContext<better_call845.MiddlewareOptions>) => Promise<{
330
330
  session: {
331
331
  session: Record<string, any> & {
332
332
  id: string;
@@ -351,11 +351,11 @@ declare const rejectInvitation: <O extends OrganizationOptions>(options: O) => b
351
351
  }>)[];
352
352
  }>) => Promise<{
353
353
  session: {
354
- session: _better_auth_core_db95.Session & {
354
+ session: _better_auth_core_db60.Session & {
355
355
  activeTeamId?: string | undefined;
356
356
  activeOrganizationId?: string | undefined;
357
357
  };
358
- user: _better_auth_core_db95.User;
358
+ user: _better_auth_core_db60.User;
359
359
  };
360
360
  }>))[];
361
361
  metadata: {
@@ -397,26 +397,26 @@ declare const rejectInvitation: <O extends OrganizationOptions>(options: O) => b
397
397
  } | null;
398
398
  member: null;
399
399
  }>;
400
- declare const cancelInvitation: <O extends OrganizationOptions>(options: O) => better_call893.StrictEndpoint<"/organization/cancel-invitation", {
400
+ declare const cancelInvitation: <O extends OrganizationOptions>(options: O) => better_call845.StrictEndpoint<"/organization/cancel-invitation", {
401
401
  method: "POST";
402
402
  body: z.ZodObject<{
403
403
  invitationId: z.ZodString;
404
404
  }, z.core.$strip>;
405
405
  requireHeaders: true;
406
- use: (((inputContext: better_call893.MiddlewareInputContext<better_call893.MiddlewareOptions>) => Promise<{
406
+ use: (((inputContext: better_call845.MiddlewareInputContext<better_call845.MiddlewareOptions>) => Promise<{
407
407
  orgOptions: OrganizationOptions;
408
408
  roles: typeof defaultRoles & {
409
409
  [key: string]: Role<{}>;
410
410
  };
411
- getSession: (context: _better_auth_core54.GenericEndpointContext) => Promise<{
412
- session: _better_auth_core_db95.Session & {
411
+ getSession: (context: _better_auth_core45.GenericEndpointContext) => Promise<{
412
+ session: _better_auth_core_db60.Session & {
413
413
  activeTeamId?: string | undefined;
414
414
  activeOrganizationId?: string | undefined;
415
415
  };
416
- user: _better_auth_core_db95.User;
416
+ user: _better_auth_core_db60.User;
417
417
  }>;
418
- }>) | ((inputContext: better_call893.MiddlewareInputContext<{
419
- use: ((inputContext: better_call893.MiddlewareInputContext<better_call893.MiddlewareOptions>) => Promise<{
418
+ }>) | ((inputContext: better_call845.MiddlewareInputContext<{
419
+ use: ((inputContext: better_call845.MiddlewareInputContext<better_call845.MiddlewareOptions>) => Promise<{
420
420
  session: {
421
421
  session: Record<string, any> & {
422
422
  id: string;
@@ -441,11 +441,11 @@ declare const cancelInvitation: <O extends OrganizationOptions>(options: O) => b
441
441
  }>)[];
442
442
  }>) => Promise<{
443
443
  session: {
444
- session: _better_auth_core_db95.Session & {
444
+ session: _better_auth_core_db60.Session & {
445
445
  activeTeamId?: string | undefined;
446
446
  activeOrganizationId?: string | undefined;
447
447
  };
448
- user: _better_auth_core_db95.User;
448
+ user: _better_auth_core_db60.User;
449
449
  };
450
450
  }>))[];
451
451
  openapi: {
@@ -492,22 +492,22 @@ declare const cancelInvitation: <O extends OrganizationOptions>(options: O) => b
492
492
  createdAt: Date;
493
493
  }) & (O["schema"] extends {
494
494
  invitation?: {
495
- additionalFields: infer Field extends Record<string, _better_auth_core_db95.DBFieldAttribute>;
495
+ additionalFields: infer Field extends Record<string, _better_auth_core_db60.DBFieldAttribute>;
496
496
  } | undefined;
497
497
  } ? FieldAttributeToObject<Field> : {}) extends infer T ? { [K in keyof T]: T[K] } : never) | null>;
498
- declare const getInvitation: <O extends OrganizationOptions>(options: O) => better_call893.StrictEndpoint<"/organization/get-invitation", {
498
+ declare const getInvitation: <O extends OrganizationOptions>(options: O) => better_call845.StrictEndpoint<"/organization/get-invitation", {
499
499
  method: "GET";
500
- use: ((inputContext: better_call893.MiddlewareInputContext<better_call893.MiddlewareOptions>) => Promise<{
500
+ use: ((inputContext: better_call845.MiddlewareInputContext<better_call845.MiddlewareOptions>) => Promise<{
501
501
  orgOptions: OrganizationOptions;
502
502
  roles: typeof defaultRoles & {
503
503
  [key: string]: Role<{}>;
504
504
  };
505
- getSession: (context: _better_auth_core54.GenericEndpointContext) => Promise<{
506
- session: _better_auth_core_db95.Session & {
505
+ getSession: (context: _better_auth_core45.GenericEndpointContext) => Promise<{
506
+ session: _better_auth_core_db60.Session & {
507
507
  activeTeamId?: string | undefined;
508
508
  activeOrganizationId?: string | undefined;
509
509
  };
510
- user: _better_auth_core_db95.User;
510
+ user: _better_auth_core_db60.User;
511
511
  }>;
512
512
  }>)[];
513
513
  requireHeaders: true;
@@ -587,7 +587,7 @@ declare const getInvitation: <O extends OrganizationOptions>(options: O) => bett
587
587
  createdAt: Date;
588
588
  }) & (O["schema"] extends {
589
589
  invitation?: {
590
- additionalFields: infer Field extends Record<string, _better_auth_core_db95.DBFieldAttribute>;
590
+ additionalFields: infer Field extends Record<string, _better_auth_core_db60.DBFieldAttribute>;
591
591
  } | undefined;
592
592
  } ? FieldAttributeToObject<Field> : {}) extends infer T ? { [K in keyof T]: T[K] } : never) & {
593
593
  organizationName: ({
@@ -599,7 +599,7 @@ declare const getInvitation: <O extends OrganizationOptions>(options: O) => bett
599
599
  metadata?: any;
600
600
  } & (O["schema"] extends {
601
601
  organization?: {
602
- additionalFields: infer Field extends Record<string, _better_auth_core_db95.DBFieldAttribute>;
602
+ additionalFields: infer Field extends Record<string, _better_auth_core_db60.DBFieldAttribute>;
603
603
  } | undefined;
604
604
  } ? FieldAttributeToObject<RemoveFieldsWithReturnedFalse<Field>> : {}))["name"];
605
605
  organizationSlug: ({
@@ -611,28 +611,28 @@ declare const getInvitation: <O extends OrganizationOptions>(options: O) => bett
611
611
  metadata?: any;
612
612
  } & (O["schema"] extends {
613
613
  organization?: {
614
- additionalFields: infer Field extends Record<string, _better_auth_core_db95.DBFieldAttribute>;
614
+ additionalFields: infer Field extends Record<string, _better_auth_core_db60.DBFieldAttribute>;
615
615
  } | undefined;
616
616
  } ? FieldAttributeToObject<RemoveFieldsWithReturnedFalse<Field>> : {}))["slug"];
617
617
  inviterEmail: string;
618
618
  }>;
619
- declare const listInvitations: <O extends OrganizationOptions>(options: O) => better_call893.StrictEndpoint<"/organization/list-invitations", {
619
+ declare const listInvitations: <O extends OrganizationOptions>(options: O) => better_call845.StrictEndpoint<"/organization/list-invitations", {
620
620
  method: "GET";
621
621
  requireHeaders: true;
622
- use: (((inputContext: better_call893.MiddlewareInputContext<better_call893.MiddlewareOptions>) => Promise<{
622
+ use: (((inputContext: better_call845.MiddlewareInputContext<better_call845.MiddlewareOptions>) => Promise<{
623
623
  orgOptions: OrganizationOptions;
624
624
  roles: typeof defaultRoles & {
625
625
  [key: string]: Role<{}>;
626
626
  };
627
- getSession: (context: _better_auth_core54.GenericEndpointContext) => Promise<{
628
- session: _better_auth_core_db95.Session & {
627
+ getSession: (context: _better_auth_core45.GenericEndpointContext) => Promise<{
628
+ session: _better_auth_core_db60.Session & {
629
629
  activeTeamId?: string | undefined;
630
630
  activeOrganizationId?: string | undefined;
631
631
  };
632
- user: _better_auth_core_db95.User;
632
+ user: _better_auth_core_db60.User;
633
633
  }>;
634
- }>) | ((inputContext: better_call893.MiddlewareInputContext<{
635
- use: ((inputContext: better_call893.MiddlewareInputContext<better_call893.MiddlewareOptions>) => Promise<{
634
+ }>) | ((inputContext: better_call845.MiddlewareInputContext<{
635
+ use: ((inputContext: better_call845.MiddlewareInputContext<better_call845.MiddlewareOptions>) => Promise<{
636
636
  session: {
637
637
  session: Record<string, any> & {
638
638
  id: string;
@@ -657,11 +657,11 @@ declare const listInvitations: <O extends OrganizationOptions>(options: O) => be
657
657
  }>)[];
658
658
  }>) => Promise<{
659
659
  session: {
660
- session: _better_auth_core_db95.Session & {
660
+ session: _better_auth_core_db60.Session & {
661
661
  activeTeamId?: string | undefined;
662
662
  activeOrganizationId?: string | undefined;
663
663
  };
664
- user: _better_auth_core_db95.User;
664
+ user: _better_auth_core_db60.User;
665
665
  };
666
666
  }>))[];
667
667
  query: z.ZodOptional<z.ZodObject<{
@@ -690,25 +690,25 @@ declare const listInvitations: <O extends OrganizationOptions>(options: O) => be
690
690
  createdAt: Date;
691
691
  }) & (O["schema"] extends {
692
692
  invitation?: {
693
- additionalFields: infer Field extends Record<string, _better_auth_core_db95.DBFieldAttribute>;
693
+ additionalFields: infer Field extends Record<string, _better_auth_core_db60.DBFieldAttribute>;
694
694
  } | undefined;
695
695
  } ? FieldAttributeToObject<Field> : {}) extends infer T ? { [K in keyof T]: T[K] } : never)[]>;
696
696
  /**
697
697
  * List all invitations a user has received
698
698
  */
699
- declare const listUserInvitations: <O extends OrganizationOptions>(options: O) => better_call893.StrictEndpoint<"/organization/list-user-invitations", {
699
+ declare const listUserInvitations: <O extends OrganizationOptions>(options: O) => better_call845.StrictEndpoint<"/organization/list-user-invitations", {
700
700
  method: "GET";
701
- use: ((inputContext: better_call893.MiddlewareInputContext<better_call893.MiddlewareOptions>) => Promise<{
701
+ use: ((inputContext: better_call845.MiddlewareInputContext<better_call845.MiddlewareOptions>) => Promise<{
702
702
  orgOptions: OrganizationOptions;
703
703
  roles: typeof defaultRoles & {
704
704
  [key: string]: Role<{}>;
705
705
  };
706
- getSession: (context: _better_auth_core54.GenericEndpointContext) => Promise<{
707
- session: _better_auth_core_db95.Session & {
706
+ getSession: (context: _better_auth_core45.GenericEndpointContext) => Promise<{
707
+ session: _better_auth_core_db60.Session & {
708
708
  activeTeamId?: string | undefined;
709
709
  activeOrganizationId?: string | undefined;
710
710
  };
711
- user: _better_auth_core_db95.User;
711
+ user: _better_auth_core_db60.User;
712
712
  }>;
713
713
  }>)[];
714
714
  query: z.ZodOptional<z.ZodObject<{
@@ -793,7 +793,7 @@ declare const listUserInvitations: <O extends OrganizationOptions>(options: O) =
793
793
  createdAt: Date;
794
794
  }) & (O["schema"] extends {
795
795
  invitation?: {
796
- additionalFields: infer Field extends Record<string, _better_auth_core_db95.DBFieldAttribute>;
796
+ additionalFields: infer Field extends Record<string, _better_auth_core_db60.DBFieldAttribute>;
797
797
  } | undefined;
798
798
  } ? FieldAttributeToObject<Field> : {}) extends infer T ? { [K in keyof T]: T[K] } : never) & {
799
799
  organization: {
@@ -805,7 +805,7 @@ declare const listUserInvitations: <O extends OrganizationOptions>(options: O) =
805
805
  metadata?: any;
806
806
  } & (O["schema"] extends {
807
807
  organization?: {
808
- additionalFields: infer Field extends Record<string, _better_auth_core_db95.DBFieldAttribute>;
808
+ additionalFields: infer Field extends Record<string, _better_auth_core_db60.DBFieldAttribute>;
809
809
  } | undefined;
810
810
  } ? FieldAttributeToObject<Field> : {}) extends infer T_1 ? { [K_1 in keyof T_1]: T_1[K_1] } : never;
811
811
  }, "organization"> & {
@@ -818,7 +818,7 @@ declare const listUserInvitations: <O extends OrganizationOptions>(options: O) =
818
818
  metadata?: any;
819
819
  } & (O["schema"] extends {
820
820
  organization?: {
821
- additionalFields: infer Field extends Record<string, _better_auth_core_db95.DBFieldAttribute>;
821
+ additionalFields: infer Field extends Record<string, _better_auth_core_db60.DBFieldAttribute>;
822
822
  } | undefined;
823
823
  } ? FieldAttributeToObject<Field> : {}))["name"];
824
824
  })[]>;