import {z} from 'zod' export type GetApiAdvertisersAccountSIDCompanyInformationArgs = {AccountSID: string}; export type GetApiAdvertisersAccountSIDCompanyInformationOptions = {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 contact = z.object({Id: z.string().optional(), FirstName: z.string().optional(), LastName: z.string().optional(), EmailAddress: z.string().optional(), Title: z.string().optional(), ProfileImage: z.string().optional(), WorkPhoneNumberCountry: z.string().optional(), WorkPhoneNumber: z.string().optional(), CellphoneNumberCountry: z.string().optional(), CellphoneNumber: z.string().optional(), Editable: z.boolean().optional(), Labels: z.array(z.string()).optional(), Accounts: z.array(z.object({Id: z.string().optional(), Name: z.string().optional()})).optional(), Uri: z.string().optional()}); export const account = z.object({CompanyName: z.string().optional(), Industry: z.object({IndustryId: z.string().optional(), IndustryName: z.string().optional()}).optional(), Website: z.string().optional(), PrimaryPhoneNumber: z.string().optional(), PrimaryPhoneNumberCountry: z.string().optional(), SecondaryPhoneNumber: z.string().optional(), SecondaryPhoneNumberCountry: z.string().optional(), MinimumContactRating: z.string().optional(), Timezone: z.string().optional(), Currency: z.string().optional(), RegisteredForIndirectTax: z.string().optional(), IndirectTaxNumber: z.string().optional(), OrganizationType: z.string().optional(), EinSsnForeignTaxId: z.string().optional(), CorporateAddress: address.optional(), BillingAddress: address.optional(), FinancialContact: contact.optional(), TechnicalContact: contact.optional(), SecurityContact: contact.optional(), CommercialContact: contact.optional(), Uri: 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 }; /** * Get Company Information * * GET /Advertisers/{AccountSID}/CompanyInformation */ export const getApiAdvertisersAccountSIDCompanyInformation = async (args: GetApiAdvertisersAccountSIDCompanyInformationArgs, options?: GetApiAdvertisersAccountSIDCompanyInformationOptions) => { 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))}/CompanyInformation${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(account, await res.json()) };