{"version":3,"file":"idp-G_ojPBB5.mjs","names":[],"sources":["../src/runtime/idp.ts"],"sourcesContent":["/**\n * IDP (Identity Provider) utilities.\n *\n * Thin typed wrapper around the platform-provided `tailor.idp` runtime API.\n * At runtime this delegates to `globalThis.tailor.idp`. Use `mockIdp` from\n * `@tailor-platform/sdk/vitest` to mock these calls in unit tests.\n * @example\n * import { idp } from \"@tailor-platform/sdk/runtime\";\n *\n * const client = new idp.Client({ namespace: \"my-namespace\" });\n * const { users } = await client.users({ first: 10 });\n */\n\n/** Configuration object for `idp.Client`. */\nexport interface ClientConfig {\n  namespace: string;\n}\n\n/** User record returned by IDP operations. */\nexport interface User {\n  id: string;\n  name: string;\n  disabled: boolean;\n  createdAt?: string;\n  /**\n   * True when the user has at least one enrolled MFA second factor. False when\n   * the namespace has MFA disabled or the user has not enrolled a factor.\n   */\n  mfaEnrolled: boolean;\n  /**\n   * Enrolled MFA second factor IDs. Pass an entry into\n   * `idp.Client.unenrollMfa()` to remove that factor.\n   */\n  mfaFactorIds: string[];\n}\n\n/** Filter options for `idp.Client.users()`. */\nexport interface UserQuery {\n  /** Filter by user IDs */\n  ids?: string[];\n  /** Filter by user names */\n  names?: string[];\n}\n\n/** Pagination/filter options for `idp.Client.users()`. */\nexport interface ListUsersOptions {\n  /** Maximum number of users to return */\n  first?: number;\n  /** Page token for pagination */\n  after?: string;\n  /** Query filter for users */\n  query?: UserQuery;\n}\n\n/** Response shape for `idp.Client.users()`. */\nexport interface ListUsersResponse {\n  users: User[];\n  nextPageToken: string | null;\n  totalCount: number;\n}\n\n/** Input for `idp.Client.createUser()`. */\nexport interface CreateUserInput {\n  /** The user's name (typically email) */\n  name: string;\n  /** The user's password. If omitted, the user is created without a password (cannot log in with any password). */\n  password?: string;\n  /** Whether the user is disabled */\n  disabled?: boolean;\n}\n\n/** Input for `idp.Client.updateUser()`. */\nexport interface UpdateUserInput {\n  /** The user's ID */\n  id: string;\n  /** New name for the user */\n  name?: string;\n  /** New password for the user. Cannot be used with clearPassword. */\n  password?: string;\n  /** If true, remove the user's password. Cannot be used with password. */\n  clearPassword?: boolean;\n  /** New disabled status for the user */\n  disabled?: boolean;\n}\n\n/** Input for `idp.Client.sendPasswordResetEmail()`. */\nexport interface SendPasswordResetEmailInput {\n  /** The ID of the user */\n  userId: string;\n  /** The URI to redirect to after password reset */\n  redirectUri: string;\n  /** The sender display name. Defaults to 'Tailor Platform IdP'. */\n  fromName?: string;\n  /** The email subject line. Defaults to the localized default subject. */\n  subject?: string;\n}\n\n/** Input for `idp.Client.unenrollMfa()`. */\nexport interface UnenrollMfaInput {\n  /** The ID of the user whose factor will be unenrolled. */\n  userId: string;\n  /**\n   * The ID of the factor to unenroll. Factor IDs are exposed on the user\n   * record (see {@link User.mfaFactorIds}).\n   */\n  mfaFactorId: string;\n}\n\n/** Instance methods exposed by `tailor.idp.Client`. */\nexport interface IdpClientInstance {\n  users(options?: ListUsersOptions): Promise<ListUsersResponse>;\n  user(userId: string): Promise<User>;\n  userByName(name: string): Promise<User>;\n  createUser(input: CreateUserInput): Promise<User>;\n  updateUser(input: UpdateUserInput): Promise<User>;\n  deleteUser(userId: string): Promise<boolean>;\n  sendPasswordResetEmail(input: SendPasswordResetEmailInput): Promise<boolean>;\n  unenrollMfa(input: UnenrollMfaInput): Promise<boolean>;\n}\n\n/**\n * Constructor shape for `tailor.idp.Client`.\n * @internal\n */\nexport interface IdpClientConstructor {\n  new (config: ClientConfig): IdpClientInstance;\n}\n\n/**\n * Platform API surface for `tailor.idp`. Describes the shape the platform\n * runtime injects on `globalThis.tailor.idp`.\n * @internal\n */\nexport interface TailorIdpAPI {\n  Client: IdpClientConstructor;\n}\n\n/**\n * IDP Client for user management operations.\n *\n * Wraps the platform-provided `tailor.idp.Client` and exposes the same surface.\n */\nclass Client {\n  #impl: IdpClientInstance;\n\n  constructor(config: ClientConfig) {\n    this.#impl = new (globalThis as unknown as { tailor: { idp: TailorIdpAPI } }).tailor.idp.Client(\n      config,\n    );\n  }\n\n  /**\n   * List users in the namespace with optional filtering and pagination.\n   * @param options - Pagination and filter options\n   * @returns Page of users with `nextPageToken` and `totalCount`\n   */\n  users(options?: ListUsersOptions): Promise<ListUsersResponse> {\n    return this.#impl.users(options);\n  }\n\n  /**\n   * Get a user by ID.\n   * @param userId - IDP user ID\n   * @returns The matching user\n   */\n  user(userId: string): Promise<User> {\n    return this.#impl.user(userId);\n  }\n\n  /**\n   * Get a user by name.\n   * @param name - IDP user name\n   * @returns The matching user\n   */\n  userByName(name: string): Promise<User> {\n    return this.#impl.userByName(name);\n  }\n\n  /**\n   * Create a new user.\n   * @param input - User attributes\n   * @returns The newly created user\n   */\n  createUser(input: CreateUserInput): Promise<User> {\n    return this.#impl.createUser(input);\n  }\n\n  /**\n   * Update an existing user.\n   * @param input - User ID plus attributes to update\n   * @returns The updated user\n   */\n  updateUser(input: UpdateUserInput): Promise<User> {\n    return this.#impl.updateUser(input);\n  }\n\n  /**\n   * Delete a user by ID.\n   * @param userId - IDP user ID\n   * @returns `true` when the user was deleted\n   */\n  deleteUser(userId: string): Promise<boolean> {\n    return this.#impl.deleteUser(userId);\n  }\n\n  /**\n   * Send a password reset email to a user.\n   * @param input - Target user ID and redirect URI\n   * @returns `true` when the email was queued\n   */\n  sendPasswordResetEmail(input: SendPasswordResetEmailInput): Promise<boolean> {\n    return this.#impl.sendPasswordResetEmail(input);\n  }\n\n  /**\n   * Unenroll an MFA factor from a user.\n   * @param input - Target user ID and factor ID (see {@link User.mfaFactorIds})\n   * @returns `true` when the factor was removed\n   */\n  unenrollMfa(input: UnenrollMfaInput): Promise<boolean> {\n    return this.#impl.unenrollMfa(input);\n  }\n}\n\n// Keep the object typed to the public API so the private wrapper class does not leak into d.ts.\n/** Runtime API for `tailor.idp`. */\nexport const idp: TailorIdpAPI = { Client };\n"],"mappings":"AAkOA,MAAa,EAAoB,CAAE,YApFtB,CACX,GAEA,YAAY,EAAsB,CAChC,KAAK,GAAQ,IAAK,WAA4D,OAAO,IAAI,OACvF,CACF,CACF,CAOA,MAAM,EAAwD,CAC5D,OAAO,KAAK,GAAM,MAAM,CAAO,CACjC,CAOA,KAAK,EAA+B,CAClC,OAAO,KAAK,GAAM,KAAK,CAAM,CAC/B,CAOA,WAAW,EAA6B,CACtC,OAAO,KAAK,GAAM,WAAW,CAAI,CACnC,CAOA,WAAW,EAAuC,CAChD,OAAO,KAAK,GAAM,WAAW,CAAK,CACpC,CAOA,WAAW,EAAuC,CAChD,OAAO,KAAK,GAAM,WAAW,CAAK,CACpC,CAOA,WAAW,EAAkC,CAC3C,OAAO,KAAK,GAAM,WAAW,CAAM,CACrC,CAOA,uBAAuB,EAAsD,CAC3E,OAAO,KAAK,GAAM,uBAAuB,CAAK,CAChD,CAOA,YAAY,EAA2C,CACrD,OAAO,KAAK,GAAM,YAAY,CAAK,CACrC,CACF,CAI0C"}