export type PropertyRelated = {property?: ({data?: ({type?: 'property' | undefined, id?: string | undefined}) | undefined}) | undefined}; export type PersonRelated = {person?: ({data?: ({type?: 'person' | undefined, id?: string | undefined}) | undefined}) | undefined}; export type CreateApiActivityArgs = {body: {data: {type: 'activity', attributes: {activity_type: 'campaign_sent', title: string, description?: string | undefined, url?: string | undefined, meta?: (Record | null) | undefined, source: 'property_reports' | 'print' | 'social' | 'email_marketing', created_at?: (string | null) | undefined}, relationships: PropertyRelated | PersonRelated}}}; export type CreateApiActivityOptions = {baseUrl?: string | undefined, yourApiToken?: string | undefined, fetch?: typeof fetch | undefined}; /** * Create a activity log * * POST /activity */ export const createApiActivity = async (args: CreateApiActivityArgs, options?: CreateApiActivityOptions) => { const {baseUrl = "https://street.co.uk/open-api/v1", fetch: fetchFn = fetch, yourApiToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/vnd.api+json") if (yourApiToken !== undefined) headers.set('authorization', `Bearer ${yourApiToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/activity${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 undefined };