import {z} from 'zod' export type DID = unknown; export type GetApiEntitiesEntityDIDFlowPayinsPayinIdArgs = {entityDID: DID, payinId: string}; export type GetApiEntitiesEntityDIDFlowPayinsPayinIdOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const transferStatus = z.enum(["OUTGOING", "INCOMING", "AWAITING-YOURS", "AWAITING-COUNTERPARTY", "REJECTED", "AUTHORIZED", "FLAGGED", "SETTLED", "FLAGGED-SETTLEMENT", "REVERTED", "REVERT-AUTHORIZED", "REVERT-REJECTED", "REVERT-FLAGGED", "REVERT-REQUESTED", "FROZEN", "CLEARED"]); export const getApiEntitiesEntityDIDFlowPayinsPayinIdResponse = z.object({transfer: z.object({"@id": z.string().optional(), "@type": z.literal("Payin").optional(), ref: z.string().optional(), asset: z.string().optional(), amount: z.string().optional(), status: transferStatus.optional(), originator: z.string().optional(), beneficiary: z.string().optional(), memo: z.string().optional(), supportedAssets: z.array(z.string()).optional(), flowState: z.string().optional(), invoice: z.object({}).optional(), paymentLink: z.string().optional(), customerDid: z.string().optional(), merchantDid: z.string().optional(), requiresCustomerApproval: z.boolean().optional(), createdAt: z.string().optional(), agents: z.array(z.unknown()).optional(), amounts: z.object({}).optional(), log: z.array(z.unknown()).optional(), policyEvaluations: z.array(z.unknown()).optional()}).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 }; /** * Get a specific payin by ID (entity-level) * * GET /entities/{entityDID}/flow/payins/{payinId} */ export const getApiEntitiesEntityDIDFlowPayinsPayinId = async (args: GetApiEntitiesEntityDIDFlowPayinsPayinIdArgs, options?: GetApiEntitiesEntityDIDFlowPayinsPayinIdOptions) => { const {baseUrl = "https://api.eu1.notabene.id", 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(/\/+$/, '')}/entities/${encodeURIComponent(String(args.entityDID))}/flow/payins/${encodeURIComponent(String(args.payinId))}${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(getApiEntitiesEntityDIDFlowPayinsPayinIdResponse, await res.json()) };