import {z} from 'zod' export type Filter = {highValue?: string | undefined, propertyName: string, values?: Array | undefined, value?: string | undefined, operator: 'EQ' | 'NEQ' | 'LT' | 'LTE' | 'GT' | 'GTE' | 'BETWEEN' | 'IN' | 'NOT_IN' | 'HAS_PROPERTY' | 'NOT_HAS_PROPERTY' | 'CONTAINS_TOKEN' | 'NOT_CONTAINS_TOKEN'}; export type FilterGroup = {filters: Array}; export type PublicObjectSearchRequest = {query?: string | undefined, limit: number, after: string, sorts: Array, properties: Array, filterGroups: Array}; export type CreateApiCrmV3ObjectsBucketTest111sSearchArgs = {body: PublicObjectSearchRequest}; export type CreateApiCrmV3ObjectsBucketTest111sSearchOptions = {baseUrl?: string | undefined, oauth2?: string | undefined, fetch?: typeof fetch | undefined}; export const nextPage = z.object({link: z.string().optional(), after: z.string()}); export const forwardPaging = z.object({next: nextPage.optional()}); export const valueWithTimestamp = z.object({sourceId: z.string().optional(), sourceType: z.string(), sourceLabel: z.string().optional(), updatedByUserId: z.number().int().optional(), value: z.string(), timestamp: z.string()}); export const simplePublicObject = z.object({createdAt: z.string(), archived: z.boolean().optional(), archivedAt: z.string().optional(), propertiesWithHistory: z.record(z.string(), z.array(valueWithTimestamp)).optional(), id: z.string(), properties: z.record(z.string(), z.string().nullable()), updatedAt: z.string()}); export const collectionResponseWithTotalSimplePublicObjectForwardPaging = z.object({total: z.number().int(), paging: forwardPaging.optional(), results: z.array(simplePublicObject)}); 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 }; /** * POST /crm/v3/objects/bucket_test111s/search * * Also accepts auth: private_apps */ export const createApiCrmV3ObjectsBucketTest111sSearch = async (args: CreateApiCrmV3ObjectsBucketTest111sSearchArgs, options?: CreateApiCrmV3ObjectsBucketTest111sSearchOptions) => { const {baseUrl = "https://api.hubapi.com", fetch: fetchFn = fetch, oauth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (oauth2 !== undefined) headers.set('authorization', `Bearer ${oauth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/crm/v3/objects/bucket_test111s/search${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(collectionResponseWithTotalSimplePublicObjectForwardPaging, await res.json()) };