import {z} from 'zod' export type GetApiApiV1WaitpointsTokensArgs = {'page[size]'?: number | undefined, 'page[after]'?: string | undefined, 'page[before]'?: string | undefined, 'filter[status]'?: string | undefined, 'filter[idempotencyKey]'?: string | undefined, 'filter[tags]'?: string | undefined, 'filter[createdAt][period]'?: string | undefined, 'filter[createdAt][from]'?: string | undefined, 'filter[createdAt][to]'?: string | undefined}; export type GetApiApiV1WaitpointsTokensOptions = {baseUrl?: string | undefined, secretKey?: string | undefined, fetch?: typeof fetch | undefined}; export const waitpointTokenObject = z.object({id: z.string(), url: z.string(), status: z.enum(["WAITING", "COMPLETED", "TIMED_OUT"]), idempotencyKey: z.string().nullable().optional(), idempotencyKeyExpiresAt: z.string().nullable().optional(), timeoutAt: z.string().nullable().optional(), completedAt: z.string().nullable().optional(), output: z.string().nullable().optional(), outputType: z.string().nullable().optional(), outputIsError: z.boolean().nullable().optional(), tags: z.array(z.string()), createdAt: z.string()}); export const listWaitpointTokensResult = z.object({data: z.array(waitpointTokenObject), pagination: z.object({next: z.string().nullable().optional(), previous: z.string().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 waitpoint tokens * * GET /api/v1/waitpoints/tokens */ export const getApiApiV1WaitpointsTokens = async (args: GetApiApiV1WaitpointsTokensArgs, options?: GetApiApiV1WaitpointsTokensOptions) => { const {baseUrl = "https://api.trigger.dev", fetch: fetchFn = fetch, secretKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['page[size]'] != null) query.append("page[size]", String(args['page[size]'])) if (args['page[after]'] != null) query.append("page[after]", String(args['page[after]'])) if (args['page[before]'] != null) query.append("page[before]", String(args['page[before]'])) if (args['filter[status]'] != null) query.append("filter[status]", String(args['filter[status]'])) if (args['filter[idempotencyKey]'] != null) query.append("filter[idempotencyKey]", String(args['filter[idempotencyKey]'])) if (args['filter[tags]'] != null) query.append("filter[tags]", String(args['filter[tags]'])) if (args['filter[createdAt][period]'] != null) query.append("filter[createdAt][period]", String(args['filter[createdAt][period]'])) if (args['filter[createdAt][from]'] != null) query.append("filter[createdAt][from]", String(args['filter[createdAt][from]'])) if (args['filter[createdAt][to]'] != null) query.append("filter[createdAt][to]", String(args['filter[createdAt][to]'])) if (secretKey !== undefined) headers.set('authorization', `Bearer ${secretKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/waitpoints/tokens${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(listWaitpointTokensResult, await res.json()) };