import {z} from 'zod' export type AccountID = number; export type ProjectID = string; export type CreateApiDemandAccountsAccountIdProjectsProjectIdReconciliationsCompletesArgs = {account_id: AccountID, project_id: ProjectID, name?: string | undefined, 'Idempotency-Key'?: string | undefined, 'Content-Type': 'text/csv' | 'application/csv', body: BodyInit}; export type CreateApiDemandAccountsAccountIdProjectsProjectIdReconciliationsCompletesOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const responsesSubmitReconciliationsResponse = z.object({name: z.string().optional(), request_id: z.string().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 }; /** * Submit a list of RIDs for positive reconciliation * * POST /demand/accounts/{account_id}/projects/{project_id}/reconciliations/completes */ export const createApiDemandAccountsAccountIdProjectsProjectIdReconciliationsCompletes = async (args: CreateApiDemandAccountsAccountIdProjectsProjectIdReconciliationsCompletesArgs, options?: CreateApiDemandAccountsAccountIdProjectsProjectIdReconciliationsCompletesOptions) => { const {baseUrl = "https://api.cint.com/v1", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "text/csv") headers.set('accept', "application/json") if (args.name != null) query.append("name", String(args.name)) if (args['Idempotency-Key'] != null) headers.set("Idempotency-Key", String(args['Idempotency-Key'])) if (args['Content-Type'] != null) headers.set("Content-Type", String(args['Content-Type'])) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/demand/accounts/${encodeURIComponent(String(args.account_id))}/projects/${encodeURIComponent(String(args.project_id))}/reconciliations/completes${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: args.body}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(responsesSubmitReconciliationsResponse, await res.json()) };