import {z} from 'zod' export type GetApiV1CardCardIdArgs = {auditUser: string, filter?: string | undefined, fromDate?: string | undefined, toDate?: string | undefined, page?: number | undefined, size?: number | undefined, cardId: unknown}; export type GetApiV1CardCardIdOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const fraudCaseId = z.string(); export const fraudCaseStatus = z.enum(["OPEN", "PENDING", "CLOSED"]); export const fraudCaseCardId = z.string(); export const fraudCaseCreatedTime = z.string(); export const fraudCaseLastUpdatedTime = z.string(); export const fraudCaseComment = z.string().max(512).nullable(); export const fraudCaseResolutionStatus = z.enum(["RISK", "NO_RISK"]); export const fraudCaseTransactionCount = z.number().int(); export const fraudCaseSummary = z.object({id: fraudCaseId, status: fraudCaseStatus, cardId: fraudCaseCardId, createdTime: fraudCaseCreatedTime, lastUpdatedTime: fraudCaseLastUpdatedTime, comment: fraudCaseComment.optional(), resolutionStatus: fraudCaseResolutionStatus.optional(), transactionCount: fraudCaseTransactionCount}); export const fraudCaseSummaryListResponse = z.object({cases: z.array(fraudCaseSummary)}); 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 fraud cases for a card * * GET /v1/card/{cardId} */ export const getApiV1CardCardId = async (args: GetApiV1CardCardIdArgs, options: GetApiV1CardCardIdOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.auditUser != null) query.append("auditUser", String(args.auditUser)) if (args.filter != null) query.append("filter", String(args.filter)) if (args.fromDate != null) query.append("fromDate", String(args.fromDate)) if (args.toDate != null) query.append("toDate", String(args.toDate)) if (args.page != null) query.append("page", String(args.page)) if (args.size != null) query.append("size", String(args.size)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/card/${encodeURIComponent(String(args.cardId))}${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(fraudCaseSummaryListResponse, await res.json()) };