/** * account-service client for staff single sign-on (KDI-5225). * * The business owner connects their organisation's identity provider (Lark, SAML, * OpenID Connect) here; account-service checks the permission and the IdP settings. * Errors keep the server's `code`, so the page can explain each refusal instead of * showing the raw message. */ export type StaffSsoScopePurpose = "user_id" | "mobile" | "email" | "org" | "directory" | "message"; export interface StaffSsoSetupField { key: string; /** English; the page translates known keys and falls back to this. */ label: string; /** "secret": write-only, read back masked. "pem": certificates. "list": one value per line. */ input: "text" | "url" | "secret" | "pem" | "list"; required: boolean; /** Fixed once the provider exists. */ locked?: boolean; placeholder?: string; } /** A value the owner pastes into their identity provider. */ export interface StaffSsoCopyValue { key: string; label: string; value: string; } export interface StaffSsoTypeSetup { type: string; /** "redirect": FeedMe runs the sign-in (Lark). "firebase": SAML / OIDC through Firebase. */ kind: "redirect" | "firebase"; label: string; iconUrl: string; /** The connect form, beyond the company code. */ fields: StaffSsoSetupField[]; copy: StaffSsoCopyValue[]; consoleUrl?: string; scopes?: { scope: string; required: boolean; purpose: StaffSsoScopePurpose; }[]; /** Lark's redirect URL, from before `copy`. */ redirectUri?: string; } /** The provider's IdP settings; secret fields read back as "set". */ export type StaffSsoIdpView = { type: string; } & Record; export type StaffSsoIdpValue = string | string[]; export interface StaffSsoProviderView { /** The provider slug. */ _id: string; businessId: string; displayName: string; label?: string; enabled: boolean; orgKey: string; inviteMatch: "mobile" | "email" | "none"; /** Work email domains; the login page finds the company from a staff member's email. */ emailDomains?: string[]; idp: StaffSsoIdpView; /** Staff accounts linked to this provider; it can be removed only at 0. */ staffAccounts: number; /** The IdP app's own name and picture, when the IdP shares them (Lark: Bot turned on). */ app?: { name: string; avatarUrl: string; }; createdAt: string; updatedAt: string; updatedBy?: string; } export interface StaffSsoSettings { providers: StaffSsoProviderView[]; /** False when the business may not connect another provider. */ canAdd: boolean; /** False when the business may not turn a provider on. */ canEnable: boolean; types: StaffSsoTypeSetup[]; } export interface StaffSsoProviderCreate { /** The company ID staff type at sign-in; fixed once created. */ slug: string; displayName: string; idp: { type: string; } & Record; } export interface StaffSsoProviderPatch { enabled?: boolean; displayName?: string; idp?: Record; } declare const SERVER_CODES: readonly ["invalid_body", "invalid_credentials", "provider_exists", "org_taken", "app_taken", "not_found", "live_elsewhere", "org_mismatch", "in_use", "domain_taken", "slug_taken", "provider_unavailable"]; export type StaffSsoErrorCode = (typeof SERVER_CODES)[number] | "unauthorized" | "forbidden" | "network" | "unknown"; export declare class StaffSsoApiError extends Error { readonly code: StaffSsoErrorCode; readonly status: number | undefined; constructor(code: StaffSsoErrorCode, status: number | undefined, message: string); } /** Maps an axios failure to the server's code; status alone covers 401 and 403. */ export declare function toStaffSsoError(error: unknown): StaffSsoApiError; export declare const staffSsoApi: { read(businessId: string): Promise; create(businessId: string, body: StaffSsoProviderCreate): Promise; update(businessId: string, slug: string, body: StaffSsoProviderPatch): Promise; remove(businessId: string, slug: string): Promise; }; export {};