import {z} from 'zod' export type PatchApiV2CompaniesIdArgs = {'x-api-version'?: string | undefined, 'x-company-guid'?: string | undefined, id: number, body: {name?: (string | null) | undefined, country?: (string | null) | undefined, photo?: (string | null) | undefined, pos?: (string | null) | undefined}}; export type PatchApiV2CompaniesIdOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const patchApiV2CompaniesIdResponse = z.object({id: z.number(), name: z.string(), country: z.string(), photo: z.string().nullable(), plan_id: z.string(), created: z.string(), modified: z.string().nullable(), expires: z.string().nullable(), days_to_expire: z.number().nullable(), converted: z.string().nullable(), pos: z.string().nullable(), status: z.enum(["active", "trial", "cancelled", "delinquent", "expired", "unknown"]), start_week_on: z.number().nullable(), meta: z.object({signup_utm_source: z.string().nullable().optional(), utm_source: z.string().nullable().optional(), signup_content_source: z.string().nullable().optional(), buy_now: z.boolean().optional(), trial_checklist_stored_locally: z.boolean().optional(), employee_count_range: z.string().nullable().optional(), api_key: z.string().optional()}).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 Company * * PATCH /v2/companies/{id} * * Also accepts auth: cookieAuth */ export const patchApiV2CompaniesId = async (args: PatchApiV2CompaniesIdArgs, options?: PatchApiV2CompaniesIdOptions) => { 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/companies/${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(patchApiV2CompaniesIdResponse, await res.json()) };