import {z} from 'zod' export type AssetGroupBindingAdAccountsIdsItems = string; export type AssetGroupBindingCatalogsIdsItems = string; export type BusinessAccessUserSummary = {email?: (string | null) | undefined, id?: (string | null) | undefined, username?: (string | null) | undefined}; export type AssetGroupBindingProfilesIdsItems = string; export type AssetGroupBinding = {ad_accounts_ids: Array, asset_group_description: string | null, asset_group_name: string | null, asset_group_types: Array, catalogs_ids: Array, created_by: BusinessAccessUserSummary, created_time: number | null, id: string, owner: BusinessAccessUserSummary, profiles_ids: Array, updated_time: number | null}; export type AssetGroupType = 'BRAND' | 'LOCATION_OR_LANGUAGE' | 'PRODUCT_LINE' | 'OTHER'; export type AssetGroupTypesCreate = Array; export type AssetGroupInputCreate = {asset_group?: AssetGroupBinding | undefined, asset_group_description: string, asset_group_name: string, asset_group_types: AssetGroupTypesCreate}; export type CreateApiBusinessesBusinessIdAssetGroupsArgs = {business_id: string, body: AssetGroupInputCreate}; export type CreateApiBusinessesBusinessIdAssetGroupsOptions = {baseUrl?: string | undefined, pinterestOauth2?: string | undefined, fetch?: typeof fetch | undefined}; export const assetGroupBindingAdAccountsIdsItems = z.string(); export const assetGroupBindingCatalogsIdsItems = z.string(); export const businessAccessUserSummary = z.object({email: z.string().nullable().optional(), id: z.string().min(1).max(20).nullable().optional(), username: z.string().nullable().optional()}); export const assetGroupBindingProfilesIdsItems = z.string(); export const assetGroupBinding = z.object({ad_accounts_ids: z.array(assetGroupBindingAdAccountsIdsItems), asset_group_description: z.string().nullable(), asset_group_name: z.string().nullable(), asset_group_types: z.array(z.string()), catalogs_ids: z.array(assetGroupBindingCatalogsIdsItems), created_by: businessAccessUserSummary, created_time: z.number().int().nullable(), id: z.string(), owner: businessAccessUserSummary, profiles_ids: z.array(assetGroupBindingProfilesIdsItems), updated_time: z.number().int().nullable()}); export const assetGroupInput = z.object({asset_group: assetGroupBinding.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 }; /** * Create a new asset group. * * POST /businesses/{business_id}/asset_groups */ export const createApiBusinessesBusinessIdAssetGroups = async (args: CreateApiBusinessesBusinessIdAssetGroupsArgs, options?: CreateApiBusinessesBusinessIdAssetGroupsOptions) => { 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))}/asset_groups${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(assetGroupInput, await res.json()) };