import {z} from 'zod' export type CreateApiV2CompanyCompanyIdCreateManyUsersArgs = {'x-api-version'?: string | undefined, 'x-company-guid'?: string | undefined, company_id: number, body: Array<{first_name: string, last_name: string, preferred_first_name?: (string | null) | undefined, preferred_last_name?: (string | null) | undefined, location_ids: Array, department_ids: Array | null, role_ids?: (Array | 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, invite_user?: (boolean | null) | undefined, notes?: (string | null) | undefined, hire_date?: (string | null) | undefined, type: 'employee' | 'asst_manager' | 'manager' | 'employer', employee_id?: (string | null) | undefined, punch_id?: (number | null) | undefined, birth_date?: (string | null) | undefined, language?: ('en' | 'es' | 'fr') | undefined, appear_as_employee?: (boolean | null) | undefined, subscribe_to_updates?: (boolean | null) | undefined, max_weekly_hours?: (number | null) | undefined, skill_level?: (1 | 2 | 3 | null) | undefined, wage_cents?: (number | null) | undefined, wage_type?: ('hourly' | 'weekly_salary' | null) | undefined, wages?: (Array<{role_id?: number | undefined, wage_cents?: number | undefined, effective_date?: (string | null) | undefined}> | null) | undefined, permissions_template_id?: (number | null) | undefined}>}; export type CreateApiV2CompanyCompanyIdCreateManyUsersOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiV2CompanyCompanyIdCreateManyUsersResponse = z.object({object: z.literal("user"), 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()}))}); 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 }; /** * Create Many Users * * POST /v2/company/{company_id}/create_many_users * * Also accepts auth: cookieAuth */ export const createApiV2CompanyCompanyIdCreateManyUsers = async (args: CreateApiV2CompanyCompanyIdCreateManyUsersArgs, options?: CreateApiV2CompanyCompanyIdCreateManyUsersOptions) => { 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))}/create_many_users${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(createApiV2CompanyCompanyIdCreateManyUsersResponse, await res.json()) };