import {z} from 'zod' export type UpdateApiV2CompanyCompanyIdUsersIdentifierArgs = {'x-api-version'?: string | undefined, 'x-company-guid'?: string | undefined, company_id: number, identifier: number, body: {first_name?: string | undefined, last_name?: string | undefined, preferred_first_name?: (string | null) | undefined, preferred_last_name?: (string | null) | undefined, email?: string | undefined, mobile_number?: (string | null) | undefined, home_number?: (string | null) | undefined, address?: (string | null) | undefined, postal_zip?: (string | null) | undefined, city?: (string | null) | undefined, prov_state?: (string | null) | undefined, notes?: (string | null) | undefined, hire_date?: (string | null) | undefined, type?: ('employee' | 'asst_manager' | 'manager') | undefined, employee_id?: (string | null) | undefined, punch_id?: (string | null) | undefined, birth_date?: (string | null) | undefined, language?: ('en' | 'es' | 'fr') | undefined, appear_as_employee?: boolean | undefined, subscribe_to_updates?: boolean | undefined, max_weekly_hours?: (number | null) | undefined, active?: boolean | undefined, pronouns?: (string | null) | undefined, permissions_template_id?: (number | null) | undefined, skill_level?: (1 | 2 | 3 | null) | undefined, invite?: boolean | undefined, wage_type?: ('hourly' | 'weekly_salary') | undefined, show_copy_previous_dialog?: boolean | undefined, push?: boolean | undefined, sms_notifications?: boolean | undefined}}; export type UpdateApiV2CompanyCompanyIdUsersIdentifierOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const updateApiV2CompanyCompanyIdUsersIdentifierResponse = z.object({object: z.literal("user"), data: z.object({id: z.number().int(), identity_id: z.number().int().nullable().optional(), company_id: z.number().int(), first_name: z.string().max(80), last_name: z.string().max(80), preferred_first_name: z.string().max(150).nullable().optional(), preferred_last_name: z.string().max(150).nullable().optional(), pronouns: z.string().max(80).nullable().optional(), email: z.string().max(155), mobile_number: z.string().nullable(), home_number: z.string().nullable(), birth_date: z.string().nullable(), address: z.string().max(100).nullable(), postal_zip: z.string().max(20).nullable(), city: z.string().max(50).nullable(), prov_state: z.string().max(25).nullable(), invite_status: z.enum(["accepted", "pending", "required", "missing_contact_info"]), active: z.boolean(), photo: z.string().nullable(), notes: z.string().nullable(), timezone: z.string().nullable(), type: z.enum(["employee", "asst_manager", "manager", "employer"]), employee_id: z.string().max(190).nullable(), max_weekly_hours: z.string(), punch_id: z.string().max(40).nullable(), created: z.string().optional(), modified: z.string().optional(), invited: z.string().nullable(), invite_accepted: z.string().nullable(), is_new: z.boolean(), appear_as_employee: z.boolean().optional(), subscribe_to_updates: z.boolean().optional(), language: z.string().optional(), push: z.boolean().optional(), skill_level: z.number().int().nullable().optional(), hourly_wage: z.number().int().nullable().optional(), wage_type: z.string().nullable().optional(), sms_me_schedules: z.boolean().nullable().optional(), notify_ot_risk: z.boolean().nullable().optional(), permissions_template_id: z.number().int().nullable().optional(), reactivation_status: z.enum(["accepted", "pending", "expired"]).nullable().optional(), meta: z.object({readonly_fields: z.array(z.string()).optional(), identity_status: z.enum(["created", "updated", "merging_identities"]).nullable().optional()}).nullable().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 * * PUT /v2/company/{company_id}/users/{identifier} * * Also accepts auth: cookieAuth */ export const updateApiV2CompanyCompanyIdUsersIdentifier = async (args: UpdateApiV2CompanyCompanyIdUsersIdentifierArgs, options?: UpdateApiV2CompanyCompanyIdUsersIdentifierOptions) => { const {baseUrl = "https://api.7shifts.com", 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 (args['x-api-version'] != null) headers.set("x-api-version", String(args['x-api-version'])) if (args['x-company-guid'] != null) headers.set("x-company-guid", String(args['x-company-guid'])) if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/company/${encodeURIComponent(String(args.company_id))}/users/${encodeURIComponent(String(args.identifier))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(updateApiV2CompanyCompanyIdUsersIdentifierResponse, await res.json()) };