import {z} from 'zod' export type GetApiV2CompanyCompanyIdUsersArgs = {'x-api-version'?: string | undefined, 'x-company-guid'?: string | undefined, company_id: number, modified_since?: string | undefined, location_id?: number | undefined, department_id?: number | undefined, role_id?: number | undefined, status?: ('active' | 'inactive') | undefined, name?: string | undefined, sort_by?: string | undefined, cursor?: string | undefined, limit?: number | undefined}; export type GetApiV2CompanyCompanyIdUsersOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiV2CompanyCompanyIdUsersResponse = z.object({object: z.literal("users"), data: z.array(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()})), meta: z.object({cursor: z.object({current: z.string().nullable(), prev: z.string().nullable(), next: z.string().nullable(), count: z.number().int().nullable()})})}); 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 }; /** * List Users * * GET /v2/company/{company_id}/users * * Also accepts auth: cookieAuth */ export const getApiV2CompanyCompanyIdUsers = async (args: GetApiV2CompanyCompanyIdUsersArgs, options?: GetApiV2CompanyCompanyIdUsersOptions) => { const {baseUrl = "https://api.7shifts.com", fetch: fetchFn = fetch, OAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() 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 (args.modified_since != null) query.append("modified_since", String(args.modified_since)) if (args.location_id != null) query.append("location_id", String(args.location_id)) if (args.department_id != null) query.append("department_id", String(args.department_id)) if (args.role_id != null) query.append("role_id", String(args.role_id)) if (args.status != null) query.append("status", String(args.status)) if (args.name != null) query.append("name", String(args.name)) if (args.sort_by != null) query.append("sort_by", String(args.sort_by)) if (args.cursor != null) query.append("cursor", String(args.cursor)) if (args.limit != null) query.append("limit", String(args.limit)) if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/company/${encodeURIComponent(String(args.company_id))}/users${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiV2CompanyCompanyIdUsersResponse, await res.json()) };