import {z} from 'zod' export type EntityType = 'BILL' | 'COMMITMENT' | 'USER' | 'SERVICE_USER' | 'SCHEDULER'; export type GetApiOrganizationsOrgIdBalancesBalanceIdTransactionsArgs = {orgId: string, balanceId: string, pageSize?: number | undefined, nextToken?: string | undefined, transactionTypeId?: (string | null) | undefined, entityType?: (EntityType | null) | undefined, entityId?: (string | null) | undefined}; export type GetApiOrganizationsOrgIdBalancesBalanceIdTransactionsOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const entityType = z.enum(["BILL", "COMMITMENT", "USER", "SERVICE_USER", "SCHEDULER"]); export const balanceTransactionResponse = z.object({id: z.string(), version: z.number().int().optional(), description: z.string().optional(), amount: z.number().optional(), paid: z.number().optional(), currencyPaid: z.string().optional(), entityType: entityType.optional(), entityId: z.string().optional(), transactionTypeId: z.string().optional(), appliedDate: z.string().optional(), transactionDate: z.string().optional(), dtCreated: z.string().optional(), dtLastModified: z.string().optional(), createdBy: z.string().optional(), lastModifiedBy: z.string().optional()}); export const paginatedBalanceTransactionResponseData = z.object({data: z.array(balanceTransactionResponse).optional(), nextToken: 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 }; /** * List Transactions * * GET /organizations/{orgId}/balances/{balanceId}/transactions */ export const getApiOrganizationsOrgIdBalancesBalanceIdTransactions = async (args: GetApiOrganizationsOrgIdBalancesBalanceIdTransactionsArgs, options?: GetApiOrganizationsOrgIdBalancesBalanceIdTransactionsOptions) => { const {baseUrl = "https://api.m3ter.com", fetch: fetchFn = fetch, OAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.pageSize != null) query.append("pageSize", String(args.pageSize)) if (args.nextToken != null) query.append("nextToken", String(args.nextToken)) if (args.transactionTypeId != null) query.append("transactionTypeId", String(args.transactionTypeId)) if (args.entityType != null) query.append("entityType", String(args.entityType)) if (args.entityId != null) query.append("entityId", String(args.entityId)) if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/organizations/${encodeURIComponent(String(args.orgId))}/balances/${encodeURIComponent(String(args.balanceId))}/transactions${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(paginatedBalanceTransactionResponseData, await res.json()) };