@flatfile/listener
Advanced tools
Comparing version 0.3.3 to 0.3.4
@@ -0,1 +1,2 @@ | ||
import { Event, RecordsWithLinks } from '@flatfile/api/api'; | ||
import { Flatfile } from '@flatfile/api'; | ||
@@ -7,3 +8,3 @@ | ||
constructor(accessToken?: string, apiUrl?: string); | ||
fetch(url: string): Promise<any>; | ||
fetch(url: string, options?: any): Promise<any>; | ||
/** | ||
@@ -46,2 +47,3 @@ * | ||
readonly target: string; | ||
readonly origin: object; | ||
readonly action: string; | ||
@@ -51,3 +53,3 @@ readonly context: any; | ||
readonly cache: EventCache; | ||
constructor(src: Flatfile.Event, accessToken?: string, apiUrl?: string); | ||
constructor(src: Event, accessToken?: string, apiUrl?: string); | ||
/** | ||
@@ -62,2 +64,3 @@ * Should return either event body if expanded already or fetch data from the | ||
afterAll<T>(callback: () => T, cacheKey?: string): void; | ||
update(records: RecordsWithLinks): Promise<void>; | ||
} | ||
@@ -64,0 +67,0 @@ type EventCallback = (evt: FlatfileEvent) => void; |
@@ -139,3 +139,3 @@ "use strict"; | ||
} | ||
fetch(url) { | ||
async fetch(url, options) { | ||
const headers = { | ||
@@ -145,5 +145,16 @@ Authorization: `Bearer ${this._accessToken}`, | ||
}; | ||
const axiosInstance = import_axios.default.create({ | ||
headers | ||
}); | ||
const fetchUrl = this._apiUrl + "/" + url; | ||
return import_axios.default.get(fetchUrl, { headers }).then((resp) => resp.data.data).catch((err) => { | ||
}); | ||
const config = { | ||
url: fetchUrl, | ||
method: "GET", | ||
...options | ||
}; | ||
try { | ||
const resp = await axiosInstance(config); | ||
return resp.data.data; | ||
} catch (err) { | ||
} | ||
} | ||
@@ -220,2 +231,3 @@ /** | ||
this.target = src.target || ""; | ||
this.origin = src.origin || {}; | ||
this.action = src.context?.actionName || ""; | ||
@@ -242,2 +254,16 @@ } | ||
} | ||
async update(records) { | ||
if (!this.src.dataUrl) { | ||
throw new Error("Cannot set data on an event without a dataUrl"); | ||
} | ||
const prepRecords = records.map((record) => { | ||
record.messages?.map((message) => { | ||
delete message.source; | ||
}); | ||
}); | ||
await this.fetch(this.src.dataUrl, { | ||
method: "POST", | ||
data: JSON.stringify(prepRecords) | ||
}); | ||
} | ||
}; | ||
@@ -244,0 +270,0 @@ |
{ | ||
"name": "@flatfile/listener", | ||
"version": "0.3.3", | ||
"version": "0.3.4", | ||
"description": "A PubSub Listener for configuring and using Flatfile", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
44934
1541