import {z} from 'zod' export type GetApiChecklistsTaskslistArgs = {tradeid?: number | undefined, checklistid?: number | undefined, categoryid?: number | undefined, subscriberId?: number | undefined, tradeName?: string | undefined, checkListName?: string | undefined, categoryName?: string | undefined, locationId?: number | undefined, storeId?: string | undefined, providerId?: number | undefined}; export type GetApiChecklistsTaskslistOptions = {baseUrl?: string | undefined, oauth2?: string | undefined, fetch?: typeof fetch | undefined}; export const serviceChannelServicesWebApiModelsResponseChecklistsChecklistSettingsResponsesChecklistTaskResponse = z.object({Id: z.number().int().optional(), CheckListId: z.number().int().optional(), TypeId: z.number().int().optional(), TaskTypeId: z.literal("AssetTask").optional(), TaskTypeName: z.string().optional(), Name: z.string().optional(), Description: z.string().optional(), IsActive: z.boolean().optional()}); export const serviceChannelServicesWebApiModelsResponseChecklistsChecklistSettingsResponsesCheckListWithTasksResponse = z.object({ChecklistName: z.string().optional(), Id: z.number().int().optional(), IsActive: z.boolean().optional(), CreatedDate: z.string().optional(), UpdatedDate: z.string().optional(), CreatedBy: z.number().int().optional(), UpdatedBy: z.number().int().optional(), Tasks: z.array(serviceChannelServicesWebApiModelsResponseChecklistsChecklistSettingsResponsesChecklistTaskResponse).optional()}); export const serviceChannelServicesWebApiModelsResponseChecklistsChecklistSettingsResponsesCheckListWithTasksExtendedResponse = z.object({ChecklistWithTasks: z.array(serviceChannelServicesWebApiModelsResponseChecklistsChecklistSettingsResponsesCheckListWithTasksResponse).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 }; /** * Get checklists with asset tasks * * GET /checklists/taskslist */ export const getApiChecklistsTaskslist = async (args: GetApiChecklistsTaskslistArgs, options?: GetApiChecklistsTaskslistOptions) => { const {baseUrl = "https://sb2api.servicechannel.com/v3", fetch: fetchFn = fetch, oauth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.tradeid != null) query.append("tradeid", String(args.tradeid)) if (args.checklistid != null) query.append("checklistid", String(args.checklistid)) if (args.categoryid != null) query.append("categoryid", String(args.categoryid)) if (args.subscriberId != null) query.append("subscriberId", String(args.subscriberId)) if (args.tradeName != null) query.append("tradeName", String(args.tradeName)) if (args.checkListName != null) query.append("checkListName", String(args.checkListName)) if (args.categoryName != null) query.append("categoryName", String(args.categoryName)) if (args.locationId != null) query.append("locationId", String(args.locationId)) if (args.storeId != null) query.append("storeId", String(args.storeId)) if (args.providerId != null) query.append("providerId", String(args.providerId)) if (oauth2 !== undefined) headers.set('authorization', `Bearer ${oauth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/checklists/taskslist${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(serviceChannelServicesWebApiModelsResponseChecklistsChecklistSettingsResponsesCheckListWithTasksExtendedResponse, await res.json()) };