import {z} from 'zod' export type GetApiV2CompanyCompanyIdExternalUserMappingsArgs = {'x-api-version'?: string | undefined, 'x-company-guid'?: string | undefined, company_id: number, location_id?: number | undefined, user_id?: number | undefined, external_user_id?: string | undefined, modified_since?: string | undefined, cursor?: string | undefined, limit?: number | undefined}; export type GetApiV2CompanyCompanyIdExternalUserMappingsOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiV2CompanyCompanyIdExternalUserMappingsResponse = z.object({object: z.literal("external_user_mappings"), data: z.array(z.object({id: z.number().int(), user_id: z.number().int().nullable(), external_user_id: z.string().nullable(), company_id: z.number().int().nullable(), location_id: z.number().int().nullable(), application_name: z.string(), created: z.string().nullable(), modified: z.string().nullable(), user_active: z.boolean()})), meta: z.object({cursor: z.object({current: z.string().nullable(), prev: z.string().nullable(), next: z.string().nullable(), count: z.number().int().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 }; /** * List External User Mapping * * GET /v2/company/{company_id}/external_user_mappings * * Also accepts auth: cookieAuth */ export const getApiV2CompanyCompanyIdExternalUserMappings = async (args: GetApiV2CompanyCompanyIdExternalUserMappingsArgs, options?: GetApiV2CompanyCompanyIdExternalUserMappingsOptions) => { 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.location_id != null) query.append("location_id", String(args.location_id)) if (args.user_id != null) query.append("user_id", String(args.user_id)) if (args.external_user_id != null) query.append("external_user_id", String(args.external_user_id)) if (args.modified_since != null) query.append("modified_since", String(args.modified_since)) 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))}/external_user_mappings${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(getApiV2CompanyCompanyIdExternalUserMappingsResponse, await res.json()) };