import {z} from 'zod' export type GetApiOrganizationsOrgIdStatementjobsArgs = {orgId: string, pageSize?: number | undefined, nextToken?: string | undefined, active?: string | undefined, status?: string | undefined, billId?: string | undefined}; export type GetApiOrganizationsOrgIdStatementjobsOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const statementJobStatus = z.enum(["PENDING", "RUNNING", "COMPLETE", "CANCELLED", "FAILED"]); export const statementStatus = z.enum(["LATEST", "STALE", "INVALIDATED"]); export const statementJobResponse = z.object({id: z.string(), version: z.number().int().optional(), statementJobStatus: statementJobStatus.optional(), billId: z.string().optional(), orgId: z.string().optional(), includeCsvFormat: z.boolean().optional(), filters: z.object({meterIds: z.array(z.string()).optional()}).optional(), presignedJsonStatementUrl: z.string().optional(), jsonStatementStatus: statementStatus.optional(), presignedCsvStatementUrl: z.string().optional(), csvStatementStatus: statementStatus.optional(), dtCreated: z.string().optional(), dtLastModified: z.string().optional(), createdBy: z.string().optional(), lastModifiedBy: z.string().optional()}); export const paginatedStatementJobResponseData = z.object({data: z.array(statementJobResponse).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 Statement Jobs * * GET /organizations/{orgId}/statementjobs */ export const getApiOrganizationsOrgIdStatementjobs = async (args: GetApiOrganizationsOrgIdStatementjobsArgs, options?: GetApiOrganizationsOrgIdStatementjobsOptions) => { 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.active != null) query.append("active", String(args.active)) if (args.status != null) query.append("status", String(args.status)) if (args.billId != null) query.append("billId", String(args.billId)) if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/organizations/${encodeURIComponent(String(args.orgId))}/statementjobs${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(paginatedStatementJobResponseData, await res.json()) };