import {z} from 'zod' export type GetApiAdvertisersAccountSIDCampaignsCampaignIdContactsArgs = {AccountSID: string, CampaignId: number, AccountId?: string | undefined, Title?: string | undefined}; export type GetApiAdvertisersAccountSIDCampaignsCampaignIdContactsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; 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 getApiAdvertisersAccountSIDCampaignsCampaignIdContactsResponse = z.object({Contacts: z.array(contact).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 all contacts * * GET /Advertisers/{AccountSID}/Campaigns/{CampaignId}/Contacts */ export const getApiAdvertisersAccountSIDCampaignsCampaignIdContacts = async (args: GetApiAdvertisersAccountSIDCampaignsCampaignIdContactsArgs, options?: GetApiAdvertisersAccountSIDCampaignsCampaignIdContactsOptions) => { const {baseUrl = "https://api.impact.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.AccountId != null) query.append("AccountId", String(args.AccountId)) if (args.Title != null) query.append("Title", String(args.Title)) const url = `${baseUrl.replace(/\/+$/, '')}/Advertisers/${encodeURIComponent(String(args.AccountSID))}/Campaigns/${encodeURIComponent(String(args.CampaignId))}/Contacts${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(getApiAdvertisersAccountSIDCampaignsCampaignIdContactsResponse, await res.json()) };