import {z} from 'zod' export type GetApiMerchantActionsActionIdArgs = {actionId: string, includeEvents?: boolean | undefined}; export type GetApiMerchantActionsActionIdOptions = {baseUrl?: string | undefined, BearerToken?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiMerchantActionsActionIdResponse = z.object({id: z.string().optional(), workflowExecutionId: z.string(), workflowCode: z.string(), workspaceId: z.string(), type: z.enum(["authorize", "capture", "cancel", "confirm", "crateInstrument", "fraudScore", "fraudUpdate", "lookup", "payout", "refund", "startPaymentSession"]), status: z.enum(["created", "failed", "success"]), createdAt: z.string().optional(), updatedAt: z.string().optional(), errorCode: 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 }; /** * Get an action by ID * * GET /merchant/actions/{actionId} */ export const getApiMerchantActionsActionId = async (args: GetApiMerchantActionsActionIdArgs, options?: GetApiMerchantActionsActionIdOptions) => { const {baseUrl = "https://api.staging.payrails.io", fetch: fetchFn = fetch, BearerToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.includeEvents != null) query.append("includeEvents", String(args.includeEvents)) if (BearerToken !== undefined) headers.set('authorization', `Bearer ${BearerToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/merchant/actions/${encodeURIComponent(String(args.actionId))}${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(getApiMerchantActionsActionIdResponse, await res.json()) };