@flatfile/listener 0.3.10 → 0.3.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -24,6 +24,13 @@ declare class EventCache {
24
24
  delete(key?: string | string[]): void;
25
25
  }
26
26
 
27
+ type GetDataOptions = {
28
+ [key: string]: any;
29
+ };
30
+ interface GetData extends Function {
31
+ (options?: GetDataOptions): Promise<any>;
32
+ then<TResult1 = any, TResult2 = any>(onfulfilled?: ((value: any) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
33
+ }
27
34
  declare class FlatfileEvent extends AuthenticatedClient {
28
35
  private readonly src;
29
36
  /**
@@ -49,14 +56,20 @@ declare class FlatfileEvent extends AuthenticatedClient {
49
56
  readonly payload: any;
50
57
  readonly cache: EventCache;
51
58
  readonly namespace: string[];
59
+ /**
60
+ * Fetch record data from Flatfile API via the event's dataUrl
61
+ *
62
+ * @async
63
+ * @param {object} options
64
+ * @returns {Promise<any>} JSON
65
+ */
66
+ data: GetData;
52
67
  constructor(src: Event, accessToken?: string, apiUrl?: string);
53
68
  /**
54
69
  * Should return either event body if expanded already or fetch data from the
55
- * signed callback URL
56
- *
57
- * @todo this should work with the included callback URL
70
+ * signed dataURL
58
71
  */
59
- get data(): Promise<any>;
72
+ private fetchData;
60
73
  private afterAllCallbacks;
61
74
  afterAll<T>(callback: () => T, cacheKey?: string): void;
62
75
  update(records: RecordsWithLinks): Promise<void>;
package/dist/index.js CHANGED
@@ -253,16 +253,33 @@ var FlatfileEvent = class extends AuthenticatedClient {
253
253
  this.origin = src.origin || {};
254
254
  this.action = src.context?.actionName || "";
255
255
  this.namespace = src.namespaces || [];
256
+ const data = async (options) => this.fetchData(options);
257
+ data.then = (onfulfilled, onrejected) => {
258
+ return this.data().then(onfulfilled, onrejected);
259
+ };
260
+ this.data = data;
256
261
  }
257
262
  /**
258
263
  * Should return either event body if expanded already or fetch data from the
259
- * signed callback URL
260
- *
261
- * @todo this should work with the included callback URL
264
+ * signed dataURL
262
265
  */
263
- get data() {
264
- if (this.src.dataUrl) {
265
- return this.fetch(this.src.dataUrl);
266
+ async fetchData(options) {
267
+ const dataUrl = new URLSearchParams(this.src.dataUrl);
268
+ if (options) {
269
+ dataUrl.set("includeCounts", "true");
270
+ for (const [key, values] of Object.entries(options)) {
271
+ if (Array.isArray(values)) {
272
+ for (const value of values) {
273
+ dataUrl.append(key, value);
274
+ }
275
+ } else {
276
+ dataUrl.append(key, values);
277
+ }
278
+ }
279
+ }
280
+ const decodedURL = decodeURIComponent(dataUrl.toString());
281
+ if (decodedURL) {
282
+ return this.fetch(decodedURL);
266
283
  } else {
267
284
  return this.payload;
268
285
  }
package/dist/index.mjs CHANGED
@@ -210,16 +210,33 @@ var FlatfileEvent = class extends AuthenticatedClient {
210
210
  this.origin = src.origin || {};
211
211
  this.action = src.context?.actionName || "";
212
212
  this.namespace = src.namespaces || [];
213
+ const data = async (options) => this.fetchData(options);
214
+ data.then = (onfulfilled, onrejected) => {
215
+ return this.data().then(onfulfilled, onrejected);
216
+ };
217
+ this.data = data;
213
218
  }
214
219
  /**
215
220
  * Should return either event body if expanded already or fetch data from the
216
- * signed callback URL
217
- *
218
- * @todo this should work with the included callback URL
221
+ * signed dataURL
219
222
  */
220
- get data() {
221
- if (this.src.dataUrl) {
222
- return this.fetch(this.src.dataUrl);
223
+ async fetchData(options) {
224
+ const dataUrl = new URLSearchParams(this.src.dataUrl);
225
+ if (options) {
226
+ dataUrl.set("includeCounts", "true");
227
+ for (const [key, values] of Object.entries(options)) {
228
+ if (Array.isArray(values)) {
229
+ for (const value of values) {
230
+ dataUrl.append(key, value);
231
+ }
232
+ } else {
233
+ dataUrl.append(key, values);
234
+ }
235
+ }
236
+ }
237
+ const decodedURL = decodeURIComponent(dataUrl.toString());
238
+ if (decodedURL) {
239
+ return this.fetch(decodedURL);
223
240
  } else {
224
241
  return this.payload;
225
242
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flatfile/listener",
3
- "version": "0.3.10",
3
+ "version": "0.3.12",
4
4
  "description": "A PubSub Listener for configuring and using Flatfile",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",