import {z} from 'zod' export type DeletePartnerAssetAccessItem = {asset_id: string, partner_id: string, partner_type?: ('INTERNAL' | 'EXTERNAL') | undefined}; export type DeletePartnerAssetAccessBody = {accesses: Array}; export type DeleteApiBusinessesBusinessIdPartnersAssetsArgs = {business_id: string, body: DeletePartnerAssetAccessBody}; export type DeleteApiBusinessesBusinessIdPartnersAssetsOptions = {baseUrl?: string | undefined, pinterestOauth2?: string | undefined, fetch?: typeof fetch | undefined}; export const permissionsResponse = z.array(z.string()); export const deletePartnerAssetAccessResult = z.object({asset_id: z.string().optional(), asset_type: z.string().optional(), is_shared_partner: z.boolean().optional(), partner_id: z.string().optional(), permissions: permissionsResponse.optional()}); export const deletePartnerAssetAccessResultsResponseArray = z.object({items: z.array(deletePartnerAssetAccessResult).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 }; /** * Delete partner access to asset * * DELETE /businesses/{business_id}/partners/assets */ export const deleteApiBusinessesBusinessIdPartnersAssets = async (args: DeleteApiBusinessesBusinessIdPartnersAssetsArgs, options?: DeleteApiBusinessesBusinessIdPartnersAssetsOptions) => { const {baseUrl = "https://api.pinterest.com/v5", fetch: fetchFn = fetch, pinterestOauth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (pinterestOauth2 !== undefined) headers.set('authorization', `Bearer ${pinterestOauth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/businesses/${encodeURIComponent(String(args.business_id))}/partners/assets${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "DELETE", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(deletePartnerAssetAccessResultsResponseArray, await res.json()) };