import {z} from 'zod' export type CreateConsumerRiskReportRequest = {account_id: string, iso_currency_code: string, end_user_name?: string | undefined, customization_id: string}; export type CreateApiV1RiskReportConsumerArgs = {'Fuse-Client-Id': string, 'Fuse-Api-Key': string, body: CreateConsumerRiskReportRequest}; export type CreateApiV1RiskReportConsumerOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const createConsumerRiskReportResponse = z.object({id: z.string(), request_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 }; /** * Starts the background process that will calculate the consumer risk report depending on the customization passed in. * * POST /v1/risk_report/consumer */ export const createApiV1RiskReportConsumer = async (args: CreateApiV1RiskReportConsumerArgs, options?: CreateApiV1RiskReportConsumerOptions) => { const {baseUrl = "https://sandbox-api.letsfuse.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['Fuse-Client-Id'] != null) headers.set("Fuse-Client-Id", String(args['Fuse-Client-Id'])) if (args['Fuse-Api-Key'] != null) headers.set("Fuse-Api-Key", String(args['Fuse-Api-Key'])) const url = `${baseUrl.replace(/\/+$/, '')}/v1/risk_report/consumer${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(createConsumerRiskReportResponse, await res.json()) };