import {z} from 'zod' export type GetApiBusinessesBusinessIdAssetsAssetIdMembersArgs = {business_id: string, asset_id: string, start_index?: number | undefined, fetch_system_users?: boolean | undefined, bookmark?: string | undefined, page_size?: number | undefined}; export type GetApiBusinessesBusinessIdAssetsAssetIdMembersOptions = {baseUrl?: string | undefined, pinterestOauth2?: string | undefined, fetch?: typeof fetch | undefined}; export const permissionsResponse = z.array(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 userSingleAssetBinding = z.object({permissions: permissionsResponse.optional(), user: businessAccessUserSummary.optional()}); export const getApiBusinessesBusinessIdAssetsAssetIdMembersResponse = z.object({bookmark: z.string().nullable().optional(), items: z.array(userSingleAssetBinding)}); 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 members with access to asset * * GET /businesses/{business_id}/assets/{asset_id}/members */ export const getApiBusinessesBusinessIdAssetsAssetIdMembers = async (args: GetApiBusinessesBusinessIdAssetsAssetIdMembersArgs, options?: GetApiBusinessesBusinessIdAssetsAssetIdMembersOptions) => { const {baseUrl = "https://api.pinterest.com/v5", fetch: fetchFn = fetch, pinterestOauth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.start_index != null) query.append("start_index", String(args.start_index)) if (args.fetch_system_users != null) query.append("fetch_system_users", String(args.fetch_system_users)) if (args.bookmark != null) query.append("bookmark", String(args.bookmark)) if (args.page_size != null) query.append("page_size", String(args.page_size)) if (pinterestOauth2 !== undefined) headers.set('authorization', `Bearer ${pinterestOauth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/businesses/${encodeURIComponent(String(args.business_id))}/assets/${encodeURIComponent(String(args.asset_id))}/members${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(getApiBusinessesBusinessIdAssetsAssetIdMembersResponse, await res.json()) };