import {z} from 'zod' export type UsersUpdateUserProfile = {custom_attributes?: {[key: string]: string} | undefined, family_name?: string | undefined, first_name?: string | undefined, gender?: string | undefined, given_name?: string | undefined, groups?: Array | undefined, last_name?: string | undefined, locale?: string | undefined, metadata?: {[key: string]: string} | undefined, name?: string | undefined, phone_number?: string | undefined, picture?: string | undefined, preferred_username?: string | undefined}; export type V1usersUpdateUser = {external_id?: string | undefined, metadata?: {[key: string]: string} | undefined, user_profile?: UsersUpdateUserProfile | undefined}; export type PatchApiApiV1UsersIdArgs = {id: string, body: V1usersUpdateUser}; export type PatchApiApiV1UsersIdOptions = {baseUrl?: string | undefined, oauth2?: string | undefined, fetch?: typeof fetch | undefined}; export const commonsMembershipStatus = z.enum(["ACTIVE", "INACTIVE", "PENDING_INVITE", "INVITE_EXPIRED"]); export const commonsRole = z.object({display_name: z.string().optional(), id: z.string().optional(), name: z.string().optional()}); export const commonsOrganizationMembership = z.object({accepted_at: z.string().optional(), created_at: z.string().optional(), display_name: z.string().optional(), expires_at: z.string().optional(), inviter_email: z.string().optional(), join_time: z.string().optional(), membership_status: commonsMembershipStatus.optional(), metadata: z.record(z.string(), z.string()).optional(), name: z.string().optional(), organization_id: z.string().optional(), permissions: z.array(z.string()).optional(), provisioning_method: z.string().optional(), roles: z.array(commonsRole).optional()}); export const commonsIdentityProviderType = z.enum(["OKTA", "GOOGLE", "MICROSOFT_AD", "AUTH0", "ONELOGIN", "PING_IDENTITY", "JUMPCLOUD", "CUSTOM", "GITHUB", "GITLAB", "LINKEDIN", "SALESFORCE", "MICROSOFT", "IDP_SIMULATOR", "SCALEKIT", "ADFS"]); export const commonsExternalIdentity = z.object({connection_id: z.string().optional(), connection_provider: commonsIdentityProviderType.optional(), connection_type: z.string().optional(), connection_user_id: z.string().optional(), created_time: z.string().optional(), is_social: z.boolean().optional(), last_login_time: z.string().optional(), last_synced_time: z.string().optional()}); export const commonsUserProfile = z.object({custom_attributes: z.record(z.string(), z.string()).optional(), email_verified: z.boolean().optional(), external_identities: z.array(commonsExternalIdentity).optional(), family_name: z.string().optional(), gender: z.string().optional(), given_name: z.string().optional(), groups: z.array(z.string()).optional(), id: z.string().optional(), locale: z.string().optional(), metadata: z.record(z.string(), z.string()).optional(), name: z.string().optional(), phone_number: z.string().optional(), phone_number_verified: z.boolean().optional(), picture: z.string().optional(), preferred_username: z.string().optional()}); export const usersUser = z.object({create_time: z.string().optional(), email: z.string().optional(), external_id: z.string().optional(), id: z.string().optional(), last_login_time: z.string().optional(), memberships: z.array(commonsOrganizationMembership).optional(), metadata: z.record(z.string(), z.string()).optional(), update_time: z.string().optional(), user_profile: commonsUserProfile.optional()}); export const usersUpdateUserResponse = z.object({user: usersUser.optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Update user information * * PATCH /api/v1/users/{id} */ export const patchApiApiV1UsersId = async (args: PatchApiApiV1UsersIdArgs, options?: PatchApiApiV1UsersIdOptions) => { const {baseUrl = "https://$SCALEKIT_ENVIRONMENT_URL", fetch: fetchFn = fetch, oauth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (oauth2 !== undefined) headers.set('authorization', `Bearer ${oauth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/users/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(usersUpdateUserResponse, await res.json()) };