import {z} from 'zod' export type DeleteApiV1AdsLabelsLabelIdAssignmentsArgs = {labelId: string, accountId: string, adAccountId?: string | undefined, customerId?: string | undefined, campaignIds?: Array | undefined, adSetIds?: Array | undefined, adIds?: Array | undefined, keywordIds?: Array | undefined}; export type DeleteApiV1AdsLabelsLabelIdAssignmentsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const deleteApiV1AdsLabelsLabelIdAssignmentsResponse = z.object({customerId: z.string().optional(), labelId: z.string().optional(), detached: z.number().int().optional(), unchanged: z.number().int().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 }; /** * Detach a Google Ads label * * DELETE /v1/ads/labels/{labelId}/assignments */ export const deleteApiV1AdsLabelsLabelIdAssignments = async (args: DeleteApiV1AdsLabelsLabelIdAssignmentsArgs, options?: DeleteApiV1AdsLabelsLabelIdAssignmentsOptions) => { const {baseUrl = "https://zernio.com/api", fetch: fetchFn = fetch, bearerAuth} = 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.adAccountId != null) query.append("adAccountId", String(args.adAccountId)) if (args.customerId != null) query.append("customerId", String(args.customerId)) for (const item of args.campaignIds ?? []) query.append("campaignIds", String(item)) for (const item of args.adSetIds ?? []) query.append("adSetIds", String(item)) for (const item of args.adIds ?? []) query.append("adIds", String(item)) for (const item of args.keywordIds ?? []) query.append("keywordIds", String(item)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/ads/labels/${encodeURIComponent(String(args.labelId))}/assignments${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "DELETE", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(deleteApiV1AdsLabelsLabelIdAssignmentsResponse, await res.json()) };