From fd508a5ff9b9a3eff1d9fbdfca62365d74bc5d39 Mon Sep 17 00:00:00 2001 From: Netrifier Date: Sun, 30 Mar 2025 11:34:37 +0530 Subject: [PATCH] chore(organization): rename `InferRolesFromOption` to `InferOrganizationRolesFromOption` (#2053) --- .../organization/routes/crud-invites.ts | 6 ++-- .../organization/routes/crud-members.ts | 10 ++++-- .../src/plugins/organization/schema.ts | 34 ++++++++++--------- 3 files changed, 29 insertions(+), 21 deletions(-) diff --git a/packages/better-auth/src/plugins/organization/routes/crud-invites.ts b/packages/better-auth/src/plugins/organization/routes/crud-invites.ts index c4897d29ff..ce01f966a1 100644 --- a/packages/better-auth/src/plugins/organization/routes/crud-invites.ts +++ b/packages/better-auth/src/plugins/organization/routes/crud-invites.ts @@ -3,7 +3,7 @@ import { createAuthEndpoint } from "../../../api/call"; import { getSessionFromCtx } from "../../../api/routes"; import { getOrgAdapter } from "../adapter"; import { orgMiddleware, orgSessionMiddleware } from "../call"; -import { type InferRolesFromOption } from "../schema"; +import { type InferOrganizationRolesFromOption } from "../schema"; import { APIError } from "better-call"; import { parseRoles, type OrganizationOptions } from "../organization"; import { ORGANIZATION_ERROR_CODES } from "../error-codes"; @@ -59,7 +59,9 @@ export const createInvitation = ( /** * The role to assign to the user */ - role: InferRolesFromOption | InferRolesFromOption[]; + role: + | InferOrganizationRolesFromOption + | InferOrganizationRolesFromOption[]; /** * The organization ID to invite * the user to diff --git a/packages/better-auth/src/plugins/organization/routes/crud-members.ts b/packages/better-auth/src/plugins/organization/routes/crud-members.ts index 892af1dd0b..a7010a5c4b 100644 --- a/packages/better-auth/src/plugins/organization/routes/crud-members.ts +++ b/packages/better-auth/src/plugins/organization/routes/crud-members.ts @@ -2,7 +2,7 @@ import { z } from "zod"; import { createAuthEndpoint } from "../../../api/call"; import { getOrgAdapter } from "../adapter"; import { orgMiddleware, orgSessionMiddleware } from "../call"; -import type { InferRolesFromOption, Member } from "../schema"; +import type { InferOrganizationRolesFromOption, Member } from "../schema"; import { APIError } from "better-call"; import { generateId } from "../../../utils"; import { parseRoles, type OrganizationOptions } from "../organization"; @@ -27,7 +27,9 @@ export const addMember = () => $Infer: { body: {} as { userId: string; - role: InferRolesFromOption | InferRolesFromOption[]; + role: + | InferOrganizationRolesFromOption + | InferOrganizationRolesFromOption[]; organizationId?: string; } & (O extends { teams: { enabled: true } } ? { teamId?: string } @@ -293,7 +295,9 @@ export const updateMemberRole = (option: O) => metadata: { $Infer: { body: {} as { - role: InferRolesFromOption | InferRolesFromOption[]; + role: + | InferOrganizationRolesFromOption + | InferOrganizationRolesFromOption[]; memberId: string; /** * If not provided, the active organization will be used diff --git a/packages/better-auth/src/plugins/organization/schema.ts b/packages/better-auth/src/plugins/organization/schema.ts index d92b594924..8c94c8eea0 100644 --- a/packages/better-auth/src/plugins/organization/schema.ts +++ b/packages/better-auth/src/plugins/organization/schema.ts @@ -55,18 +55,20 @@ export type InvitationInput = z.input; export type MemberInput = z.input; export type OrganizationInput = z.input; export type TeamInput = z.infer; -export type InferZodRolesFromOption = - ZodLiteral< - O extends { - roles: { - [key: string]: any; - }; - } - ? keyof O["roles"] | (keyof O["roles"])[] - : "admin" | "member" | "owner" | ("admin" | "member" | "owner")[] - >; -export type InferRolesFromOption = - O extends { roles: any } ? keyof O["roles"] : "admin" | "member" | "owner"; +export type InferOrganizationZodRolesFromOption< + O extends OrganizationOptions | undefined, +> = ZodLiteral< + O extends { + roles: { + [key: string]: any; + }; + } + ? keyof O["roles"] | (keyof O["roles"])[] + : "admin" | "member" | "owner" | ("admin" | "member" | "owner")[] +>; +export type InferOrganizationRolesFromOption< + O extends OrganizationOptions | undefined, +> = O extends { roles: any } ? keyof O["roles"] : "admin" | "member" | "owner"; export type InvitationStatus = "pending" | "accepted" | "rejected" | "canceled"; @@ -76,7 +78,7 @@ export type InferMember = O["teams"] extends { ? { id: string; organizationId: string; - role: InferRolesFromOption; + role: InferOrganizationRolesFromOption; createdAt: Date; userId: string; user: { @@ -89,7 +91,7 @@ export type InferMember = O["teams"] extends { id: string; organizationId: string; createdAt: Date; - role: InferRolesFromOption; + role: InferOrganizationRolesFromOption; teamId?: string; userId: string; user: { @@ -107,7 +109,7 @@ export type InferInvitation = id: string; organizationId: string; email: string; - role: InferRolesFromOption; + role: InferOrganizationRolesFromOption; status: InvitationStatus; inviterId: string; expiresAt: Date; @@ -116,7 +118,7 @@ export type InferInvitation = id: string; organizationId: string; email: string; - role: InferRolesFromOption; + role: InferOrganizationRolesFromOption; status: InvitationStatus; inviterId: string; expiresAt: Date;