import {z} from 'zod' export type GetApiApiV4PartnerActivationsArgs = {next?: string | undefined, limit?: number | undefined, stage?: string | undefined, reference?: string | undefined, installer_id?: number | undefined, system_name?: string | undefined, city?: string | undefined, state?: string | undefined, country?: string | undefined, postal_code?: string | undefined, street1?: string | undefined, street2?: string | undefined, host_id?: number | undefined, owner_id?: number | undefined}; export type GetApiApiV4PartnerActivationsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiV4PartnerActivationsResponse = z.object({systems: z.array(z.object({system_id: z.number().int().optional(), system_name: z.string().optional(), system_type: z.string().optional(), status: z.string().optional(), timezone: z.string().optional(), stage: z.number().int().optional(), internet_connection: z.string().optional(), lease: z.boolean().optional(), operational: z.boolean().optional(), owner: z.string().optional(), owner_id: z.number().int().optional(), host: z.string().optional(), host_id: z.number().int().optional(), installer_name: z.string().optional(), installer_id: z.number().int().optional(), maintainer_name: z.string().optional(), maintainer_id: z.number().int().optional(), authorized_subcontractors: z.array(z.object({authorized_subcontractor_id: z.number().int().optional(), authorized_subcontractor_name: z.string().optional(), status: z.string().optional()})).optional(), grid_connection_type: z.object({type: z.number().int().optional(), value: z.string().optional()}).optional(), battery_grid_mode: z.string().optional(), third_party_storage_device_installed: z.boolean().optional(), third_party_storage_device_manufacturer: z.string().optional(), interconnection_application_date: z.number().int().optional(), permission_to_operate: z.boolean().optional(), uri: z.string().optional(), updated_at: z.number().int().optional(), reference: z.string().optional(), other_references: z.array(z.string()).optional(), address: z.object({street1: z.string().optional(), city: z.string().optional(), state: z.string().optional(), postal_code: z.string().optional(), country: z.string().optional(), latitude: z.number().int().optional(), longitude: z.number().int().optional(), street2: z.string().optional()}).optional()})).optional(), next: 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 of Activations * * GET /api/v4/partner/activations */ export const getApiApiV4PartnerActivations = async (args: GetApiApiV4PartnerActivationsArgs, options?: GetApiApiV4PartnerActivationsOptions) => { const {baseUrl = "https://api-qa2.enphaseenergy.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.next != null) query.append("next", String(args.next)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.stage != null) query.append("stage", String(args.stage)) if (args.reference != null) query.append("reference", String(args.reference)) if (args.installer_id != null) query.append("installer_id", String(args.installer_id)) if (args.system_name != null) query.append("system_name", String(args.system_name)) if (args.city != null) query.append("city", String(args.city)) if (args.state != null) query.append("state", String(args.state)) if (args.country != null) query.append("country", String(args.country)) if (args.postal_code != null) query.append("postal_code", String(args.postal_code)) if (args.street1 != null) query.append("street1", String(args.street1)) if (args.street2 != null) query.append("street2", String(args.street2)) if (args.host_id != null) query.append("host_id", String(args.host_id)) if (args.owner_id != null) query.append("owner_id", String(args.owner_id)) const url = `${baseUrl.replace(/\/+$/, '')}/api/v4/partner/activations${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(getApiApiV4PartnerActivationsResponse, await res.json()) };