@flatfile/listener 0.3.5 → 0.3.7

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
@@ -74,7 +74,7 @@ declare class EventHandler extends AuthenticatedClient {
74
74
  * Cache of registered listeners on this instance
75
75
  * @private
76
76
  */
77
- private listeners;
77
+ protected listeners: [string | string[], EventFilter, EventCallback][];
78
78
  constructor(filter?: EventFilter, accessToken?: string, apiUrl?: string);
79
79
  /**
80
80
  * Cache of registered child nodes for this listener. These nodes will
@@ -82,7 +82,7 @@ declare class EventHandler extends AuthenticatedClient {
82
82
  *
83
83
  * @private
84
84
  */
85
- private nodes;
85
+ protected nodes: EventHandler[];
86
86
  /**
87
87
  * Register a subscriber for events that match this path
88
88
  */
@@ -167,6 +167,38 @@ declare abstract class EventDriver {
167
167
  dispatchEvent(e: any): this;
168
168
  }
169
169
 
170
+ declare class Browser extends EventDriver {
171
+ _accessToken?: string;
172
+ _apiUrl?: string;
173
+ _environmentId?: string;
174
+ constructor({ apiUrl, accessToken, environmentId, }: {
175
+ apiUrl: string;
176
+ accessToken: string;
177
+ environmentId?: string;
178
+ /**
179
+ * @deprecated
180
+ */
181
+ fetchApi: any;
182
+ });
183
+ mountEventHandler(handler: EventHandler): this;
184
+ }
185
+
186
+ /**
187
+ * Flatfile's Virtual Machine is stateless / serverless. So when a new event
188
+ * is handled, it will just call `handle(event)`.
189
+ */
190
+ declare class FlatfileVirtualMachine extends EventDriver {
191
+ /**
192
+ * This method is triggered from within the Flatfile Core VM Runner. This
193
+ * EventDriver does not have to listen for events because this method will
194
+ * be invoked as necessary.
195
+ *
196
+ * @param event
197
+ */
198
+ handle(event: FlatfileEvent): void;
199
+ mountEventHandler(handler: EventHandler): this;
200
+ }
201
+
170
202
  /**
171
203
  * The Flatfile Listener
172
204
  *
@@ -204,58 +236,29 @@ declare class FlatfileListener extends EventHandler {
204
236
  * @param namespace
205
237
  * @param cb
206
238
  */
207
- namespace(namespace: string | string[], cb?: SubFn): FlatfileListener;
239
+ namespace(namespace: string | string[], cb?: SubFn<this>): this;
208
240
  /**
209
241
  * Filter by namespace
210
242
  *
211
243
  * @param filter
212
244
  * @param cb
213
245
  */
214
- filter(filter: EventFilter, cb?: SubFn): FlatfileListener;
246
+ filter(filter: EventFilter, cb?: SubFn<this>): this;
215
247
  /**
216
248
  * Start subscribing to events
217
249
  *
218
250
  * @param cb
219
251
  */
220
- static create(cb: SubFn): FlatfileListener;
252
+ static create<T extends FlatfileListener>(this: Constructor<T>, cb: SubFn<T>): T;
221
253
  /**
222
254
  * Mount this client using an acceptable Event Driver
223
255
  */
224
256
  mount(driver: EventDriver): this;
225
257
  }
226
- type SubFn = (client: FlatfileListener) => void;
227
-
228
- declare class Browser extends EventDriver {
229
- _accessToken?: string;
230
- _apiUrl?: string;
231
- _environmentId?: string;
232
- constructor({ apiUrl, accessToken, environmentId, }: {
233
- apiUrl: string;
234
- accessToken: string;
235
- environmentId?: string;
236
- /**
237
- * @deprecated
238
- */
239
- fetchApi: any;
240
- });
241
- mountEventHandler(handler: EventHandler): this;
242
- }
243
-
244
- /**
245
- * Flatfile's Virtual Machine is stateless / serverless. So when a new event
246
- * is handled, it will just call `handle(event)`.
247
- */
248
- declare class FlatfileVirtualMachine extends EventDriver {
249
- /**
250
- * This method is triggered from within the Flatfile Core VM Runner. This
251
- * EventDriver does not have to listen for events because this method will
252
- * be invoked as necessary.
253
- *
254
- * @param event
255
- */
256
- handle(event: FlatfileEvent): void;
257
- mountEventHandler(handler: EventHandler): this;
258
- }
258
+ type SubFn<T extends FlatfileListener> = (client: T) => void;
259
+ type Constructor<T> = {
260
+ new (): T;
261
+ };
259
262
 
260
263
  /**
261
264
  * Backwards compatibility
package/dist/index.js CHANGED
@@ -275,14 +275,14 @@ var FlatfileEvent = class extends AuthenticatedClient {
275
275
  if (!this.src.dataUrl) {
276
276
  throw new Error("Cannot set data on an event without a dataUrl");
277
277
  }
278
- const prepRecords = records.map((record) => {
278
+ records.map((record) => {
279
279
  record.messages?.map((message) => {
280
280
  delete message.source;
281
281
  });
282
282
  });
283
283
  await this.fetch(this.src.dataUrl, {
284
- method: "POST",
285
- data: JSON.stringify(prepRecords)
284
+ method: "PUT",
285
+ data: records
286
286
  });
287
287
  }
288
288
  };
@@ -594,7 +594,7 @@ var FlatfileListener = class extends EventHandler {
594
594
  * @param cb
595
595
  */
596
596
  filter(filter, cb) {
597
- const client = new FlatfileListener(filter);
597
+ const client = new this.constructor(filter);
598
598
  this.addNode(client);
599
599
  cb?.(client);
600
600
  return client;
@@ -605,7 +605,7 @@ var FlatfileListener = class extends EventHandler {
605
605
  * @param cb
606
606
  */
607
607
  static create(cb) {
608
- const client = new FlatfileListener();
608
+ const client = new this();
609
609
  cb(client);
610
610
  return client;
611
611
  }
package/dist/index.mjs CHANGED
@@ -232,14 +232,14 @@ var FlatfileEvent = class extends AuthenticatedClient {
232
232
  if (!this.src.dataUrl) {
233
233
  throw new Error("Cannot set data on an event without a dataUrl");
234
234
  }
235
- const prepRecords = records.map((record) => {
235
+ records.map((record) => {
236
236
  record.messages?.map((message) => {
237
237
  delete message.source;
238
238
  });
239
239
  });
240
240
  await this.fetch(this.src.dataUrl, {
241
- method: "POST",
242
- data: JSON.stringify(prepRecords)
241
+ method: "PUT",
242
+ data: records
243
243
  });
244
244
  }
245
245
  };
@@ -551,7 +551,7 @@ var FlatfileListener = class extends EventHandler {
551
551
  * @param cb
552
552
  */
553
553
  filter(filter, cb) {
554
- const client = new FlatfileListener(filter);
554
+ const client = new this.constructor(filter);
555
555
  this.addNode(client);
556
556
  cb?.(client);
557
557
  return client;
@@ -562,7 +562,7 @@ var FlatfileListener = class extends EventHandler {
562
562
  * @param cb
563
563
  */
564
564
  static create(cb) {
565
- const client = new FlatfileListener();
565
+ const client = new this();
566
566
  cb(client);
567
567
  return client;
568
568
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flatfile/listener",
3
- "version": "0.3.5",
3
+ "version": "0.3.7",
4
4
  "description": "A PubSub Listener for configuring and using Flatfile",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",