import {z} from 'zod' export type GetApiSchedulerV1SchedulersSchedulerIdCustomFieldsArgs = {schedulerId: number, limit?: number | undefined, offset?: number | undefined}; export type GetApiSchedulerV1SchedulersSchedulerIdCustomFieldsOptions = {baseUrl?: string | undefined, APIKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const v2FeaturesShiftschedulerExternalApiV1SchedulersSchedulerCustomFieldsModelsShiftCustomFieldSettingsResponseDropdownOptionResponse = z.object({id: z.number().int(), value: z.string(), isDeleted: z.boolean().optional()}); export const dropdownShiftCustomFieldSettingsResponse = z.object({id: z.string(), name: z.string(), type: z.string().optional(), isDefault: z.boolean(), isMultiSelect: z.boolean().optional(), dropdownOptions: z.array(v2FeaturesShiftschedulerExternalApiV1SchedulersSchedulerCustomFieldsModelsShiftCustomFieldSettingsResponseDropdownOptionResponse).optional()}); export const shiftCustomFields = z.enum(["str", "dropdown"]); export const shiftCustomFieldSettingsResponse = z.object({id: z.string(), name: z.string(), type: shiftCustomFields, isDefault: z.boolean()}); export const getShiftCustomFieldsSettingsResponse = z.object({customFields: z.array(z.union([dropdownShiftCustomFieldSettingsResponse, shiftCustomFieldSettingsResponse]))}); export const pagingResponseModelV2 = z.object({offset: z.number().int().gte(0), total: z.number().int().gte(0).nullable().optional()}); export const paginatedBaseResponseV2GetShiftCustomFieldsSettingsResponse = z.object({requestId: z.string().optional(), data: getShiftCustomFieldsSettingsResponse, paging: pagingResponseModelV2}); 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 }; /** * Get shift custom fields * * GET /scheduler/v1/schedulers/{schedulerId}/custom-fields * * Also accepts auth: OAuth2 */ export const getApiSchedulerV1SchedulersSchedulerIdCustomFields = async (args: GetApiSchedulerV1SchedulersSchedulerIdCustomFieldsArgs, options?: GetApiSchedulerV1SchedulersSchedulerIdCustomFieldsOptions) => { const {baseUrl = "https://api.connecteam.com", fetch: fetchFn = fetch, APIKeyHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) if (APIKeyHeader !== undefined) headers.set("X-API-KEY", APIKeyHeader) const url = `${baseUrl.replace(/\/+$/, '')}/scheduler/v1/schedulers/${encodeURIComponent(String(args.schedulerId))}/custom-fields${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(paginatedBaseResponseV2GetShiftCustomFieldsSettingsResponse, await res.json()) };