import {z} from 'zod' export type GetApiV1CreditMemosCreditMemoKeyPartsPartidArgs = {'Accept-Encoding'?: string | undefined, 'Content-Encoding'?: string | undefined, 'Zuora-Track-Id'?: string | undefined, 'Zuora-Entity-Ids'?: string | undefined, 'Zuora-Org-Ids'?: string | undefined, partid: string, creditMemoKey: string, 'Zuora-Version'?: string | undefined}; export type GetApiV1CreditMemosCreditMemoKeyPartsPartidOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const gETCreditMemoPartType = z.object({amount: z.number().optional(), createdById: z.string().optional(), createdDate: z.string().optional(), debitMemoId: z.string().nullable().optional(), id: z.string().optional(), invoiceId: z.string().optional(), organizationLabel: z.string().optional(), success: z.boolean().optional(), updatedById: z.string().optional(), updatedDate: 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 }; /** * Retrieve a credit memo part * * GET /v1/credit-memos/{creditMemoKey}/parts/{partid} */ export const getApiV1CreditMemosCreditMemoKeyPartsPartid = async (args: GetApiV1CreditMemosCreditMemoKeyPartsPartidArgs, options?: GetApiV1CreditMemosCreditMemoKeyPartsPartidOptions) => { 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['Zuora-Version'] != null) headers.set("Zuora-Version", String(args['Zuora-Version'])) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/credit-memos/${encodeURIComponent(String(args.creditMemoKey))}/parts/${encodeURIComponent(String(args.partid))}${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(gETCreditMemoPartType, await res.json()) };