import {z} from 'zod' export type GetApiApiV1AdminMerchantsIdAgreementRecordsArgs = {id: string}; export type GetApiApiV1AdminMerchantsIdAgreementRecordsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const agreementMerchantAgreementRecordsListResponse = z.object({success: z.boolean(), data: z.array(z.object({id: z.string(), agreement_id: z.string(), agreement_kind: z.union([z.literal("quidkey_privacy"), z.literal("quidkey_tos"), z.literal("merchant_tos"), z.literal("merchant_dpa"), z.literal("merchant_prohibited_use"), z.literal("merchant_pricing_plan"), z.literal("merchant_bank_debit_authorization"), z.literal("merchant_nacha_acknowledgment"), z.literal("third_party_provider_agreements"), z.literal("transfermate_authorization"), z.literal("straddle_psa"), z.literal("ach_authorization")]), agreement_kind_label: z.string(), agreement_url_snapshot: z.string(), accepted_at: z.string(), evidence_record_id: 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 }; /** * List merchant-level AgreementRecords the merchant has accepted, in the order they were signed. Excludes per-transaction records (e.g. customer ACH authorizations). * * GET /api/v1/admin/merchants/{id}/agreement-records */ export const getApiApiV1AdminMerchantsIdAgreementRecords = async (args: GetApiApiV1AdminMerchantsIdAgreementRecordsArgs, options?: GetApiApiV1AdminMerchantsIdAgreementRecordsOptions) => { const {baseUrl = "https://core.quidkey.com", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/admin/merchants/${encodeURIComponent(String(args.id))}/agreement-records${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(agreementMerchantAgreementRecordsListResponse, await res.json()) };