import {z} from 'zod' export type GetApiV1HostedpagesArgs = {'Accept-Encoding'?: string | undefined, 'Content-Encoding'?: string | undefined, 'Zuora-Track-Id'?: string | undefined, 'Zuora-Entity-Ids'?: string | undefined, 'Zuora-Org-Ids'?: string | undefined, versionNumber?: string | undefined, 'Zuora-Version'?: string | undefined}; export type GetApiV1HostedpagesOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getHostedPageType = z.object({pageId: z.string().optional(), pageName: z.string().optional(), pageType: z.string().optional(), pageVersion: z.string().optional()}); export const getHostedPagesType = z.object({hostedpages: z.array(getHostedPageType).optional(), success: z.boolean().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 hosted pages * * GET /v1/hostedpages */ export const getApiV1Hostedpages = async (args: GetApiV1HostedpagesArgs, options?: GetApiV1HostedpagesOptions) => { const {baseUrl = "https://rest.test.zuora.com", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['Accept-Encoding'] != null) headers.set("Accept-Encoding", String(args['Accept-Encoding'])) if (args['Content-Encoding'] != null) headers.set("Content-Encoding", String(args['Content-Encoding'])) if (args['Zuora-Track-Id'] != null) headers.set("Zuora-Track-Id", String(args['Zuora-Track-Id'])) if (args['Zuora-Entity-Ids'] != null) headers.set("Zuora-Entity-Ids", String(args['Zuora-Entity-Ids'])) if (args['Zuora-Org-Ids'] != null) headers.set("Zuora-Org-Ids", String(args['Zuora-Org-Ids'])) if (args.versionNumber != null) query.append("versionNumber", String(args.versionNumber)) if (args['Zuora-Version'] != null) headers.set("Zuora-Version", String(args['Zuora-Version'])) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/hostedpages${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(getHostedPagesType, await res.json()) };