import {z} from 'zod' export type GetApiAdvertisersAccountSIDLegalEntitiesArgs = {AccountSID: string}; export type GetApiAdvertisersAccountSIDLegalEntitiesOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const address = z.object({AddressLine1: z.string().optional(), AddressLine2: z.string().optional(), City: z.string().optional(), State: z.string().optional(), PostalCode: z.string().optional(), Country: z.string().optional()}); export const legalEntity = z.object({Id: z.string().optional(), Name: z.string().optional(), RegisteredForIndirectTax: z.string().optional(), IndirectTaxNumber: z.string().optional(), OrganizationType: z.enum(["NONP_GOV", "CORP", "SOLE_IND", "LLC_LLP_LLS", "TRUST", "SOLE_TRD", "PARTNERS", "LLC", "LLP", "COMPANY", "GOVERNMENT", "OTHER"]).optional(), EinSsnForeignTaxId: z.string().optional(), BillingAddress: address.optional(), Uri: z.string().optional()}); export const getApiAdvertisersAccountSIDLegalEntitiesResponse = z.object({LegalEntities: z.array(legalEntity).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 Legal Entities * * GET /Advertisers/{AccountSID}/LegalEntities */ export const getApiAdvertisersAccountSIDLegalEntities = async (args: GetApiAdvertisersAccountSIDLegalEntitiesArgs, options?: GetApiAdvertisersAccountSIDLegalEntitiesOptions) => { const {baseUrl = "https://api.impact.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/Advertisers/${encodeURIComponent(String(args.AccountSID))}/LegalEntities${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(getApiAdvertisersAccountSIDLegalEntitiesResponse, await res.json()) };