import {z} from 'zod' export type GetApiManagedIntegrationsPublicManagedIntegrationUuidPollArgs = {managed_integration_uuid: string, create_dispatch_records?: string | undefined, event_type_in?: string | undefined, was_dispatched?: string | undefined}; export type GetApiManagedIntegrationsPublicManagedIntegrationUuidPollOptions = {baseUrl?: string | undefined, appId?: string | undefined, fetch?: typeof fetch | undefined}; export const event = z.object({uuid: z.string().optional(), type: z.string().optional(), data: z.object({}).optional(), related_object: z.string().nullable().optional(), related_object_type: z.string().optional(), created: z.string().optional()}); export const getApiManagedIntegrationsPublicManagedIntegrationUuidPollResponse = z.array(event); 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 }; /** * Returns a list of new events * * GET /managed_integrations/public/{managed_integration_uuid}/poll */ export const getApiManagedIntegrationsPublicManagedIntegrationUuidPoll = async (args: GetApiManagedIntegrationsPublicManagedIntegrationUuidPollArgs, options?: GetApiManagedIntegrationsPublicManagedIntegrationUuidPollOptions) => { const {baseUrl = "https://api.paperlessparts.com/v1", fetch: fetchFn = fetch, appId} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.create_dispatch_records != null) query.append("create_dispatch_records", String(args.create_dispatch_records)) if (args.event_type_in != null) query.append("event_type_in", String(args.event_type_in)) if (args.was_dispatched != null) query.append("was_dispatched", String(args.was_dispatched)) if (appId !== undefined) headers.set("Authorization", appId) const url = `${baseUrl.replace(/\/+$/, '')}/managed_integrations/public/${encodeURIComponent(String(args.managed_integration_uuid))}/poll${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(getApiManagedIntegrationsPublicManagedIntegrationUuidPollResponse, await res.json()) };