export type ContentEventType = 'ResourceCreated' | 'ResourceUpdated' | 'ResourceDeleted' | 'ResourceContentUpdated'; export type EventMetadata = {id: string, type: ContentEventType, timestamp: string}; export type Key = {source: string, instance: string, resourceId: string, timestamp?: number | undefined}; export type ContentEventActor = {identifier: string, name?: string | undefined}; export type Action = {verb: string, text: string, delete?: boolean | undefined}; export type Display = 'expanded' | 'hidden'; export type ContentEventField = {name: string, value: string, label?: string | undefined, op?: ('replace' | 'remove') | undefined, display?: Display | undefined}; export type ContentEventUser = {identifier: string, name?: string | undefined, delete?: boolean | undefined}; export type Group = {identifier: string, delete?: boolean | undefined}; export type Changes = {fields?: Array | undefined, users?: Array | undefined, groups?: Array | undefined}; export type Content = {url: string, previewUrl?: string | undefined, title?: string | undefined, searchText?: string | undefined, mimeType?: string | undefined, linkedToResource?: boolean | undefined, delete?: boolean | undefined}; export type ContentEvent = {eventMetadata?: EventMetadata | undefined, key: Key, actor?: ContentEventActor | undefined, action?: Action | undefined, changes?: Changes | undefined, contents?: Array | undefined}; export type CreateApiAppwiseV2DataArgs = {body: ContentEvent}; export type CreateApiAppwiseV2DataOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Publish content events * * POST /appwise/v2/data */ export const createApiAppwiseV2Data = async (args: CreateApiAppwiseV2DataArgs, options?: CreateApiAppwiseV2DataOptions) => { const {baseUrl = "https://marketplace.appdirect.com/api", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/appwise/v2/data${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 (await res.json()) as unknown };