import {z} from 'zod' export type GetApiV1PaymentOutcomeIntentsIntentIdArgs = {'X-API-Key'?: string | undefined, intentId: string}; export type GetApiV1PaymentOutcomeIntentsIntentIdOptions = {baseUrl?: string | undefined, bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const paymentOutcomeIntentDraftLinkResponseDto = z.object({id: z.string(), draftKind: z.enum(["PAYEE_DRAFT", "TRANSFER_DRAFT"]), draftId: z.string(), linkedAt: z.string()}); export const sealedPaymentPlanLegDto = z.object({legIndex: z.number(), sourceAmountMinor: z.string(), sourceCurrency: z.string(), sourceAccountId: z.string(), sourceRail: z.string(), destinationAmountMinor: z.string(), destinationCurrency: z.string(), payeeAccountId: z.string(), destinationRail: z.string()}); export const sealedPaymentPlanDto = z.object({v: z.number(), legs: z.array(sealedPaymentPlanLegDto)}); export const paymentOutcomeIntentResponseDto = z.object({id: z.string(), organizationId: z.string(), customerId: z.string(), outcomeText: z.string(), requesterId: z.string(), status: z.enum(["OPEN", "APPROVED", "REJECTED"]), draftLinks: z.array(paymentOutcomeIntentDraftLinkResponseDto), sealedPlan: sealedPaymentPlanDto.nullable(), sealedPlanHash: z.string().nullable(), sealedPlanSignature: z.string().nullable(), sealedAt: z.string().nullable(), sealedBy: z.string().nullable(), createdAt: z.string(), updatedAt: z.string()}); 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 a payment outcome intent * * GET /v1/payment-outcome-intents/{intentId} */ export const getApiV1PaymentOutcomeIntentsIntentId = async (args: GetApiV1PaymentOutcomeIntentsIntentIdArgs, options?: GetApiV1PaymentOutcomeIntentsIntentIdOptions) => { const {baseUrl = "https://sandbox.api.infinite.dev", fetch: fetchFn = fetch, bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['X-API-Key'] != null) headers.set("X-API-Key", String(args['X-API-Key'])) if (bearer !== undefined) headers.set('authorization', `Bearer ${bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/payment-outcome-intents/${encodeURIComponent(String(args.intentId))}${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(paymentOutcomeIntentResponseDto, await res.json()) };