@flatfile/listener 0.1.2 → 0.3.0

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.
@@ -1,5 +1,5 @@
1
1
 
2
- > @flatfile/listener@0.1.2 build
2
+ > @flatfile/listener@0.3.0 build
3
3
  > tsup src/index.ts --format esm,cjs --dts
4
4
 
5
5
  CLI Building entry: src/index.ts
@@ -8,10 +8,10 @@
8
8
  CLI Target: es2020
9
9
  ESM Build start
10
10
  CJS Build start
11
- CJS dist/index.js 26.77 KB
12
- CJS ⚡️ Build success in 164ms
13
- ESM dist/index.mjs 25.91 KB
14
- ESM ⚡️ Build success in 179ms
11
+ ESM dist/index.mjs 16.00 KB
12
+ ESM ⚡️ Build success in 103ms
13
+ CJS dist/index.js 17.94 KB
14
+ CJS ⚡️ Build success in 106ms
15
15
  DTS Build start
16
- DTS ⚡️ Build success in 5925ms
17
- DTS dist/index.d.ts 7.48 KB
16
+ DTS ⚡️ Build success in 1679ms
17
+ DTS dist/index.d.ts 7.14 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @flatfile/listener
2
2
 
3
+ ## 0.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 2a30e13: Add cross-env library for accessing environment variables
8
+
9
+ ## 0.2.0
10
+
11
+ ### Minor Changes
12
+
13
+ - 637342b: Remove @flatfile/api from listener
14
+
3
15
  ## 0.1.2
4
16
 
5
17
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -1,18 +1,17 @@
1
- import { FetchAPI, DefaultApi, Event } from '@flatfile/api';
1
+ import { Flatfile } from '@flatfile/api';
2
2
 
3
3
  declare class AuthenticatedClient {
4
- private _api?;
5
- private _fetchApi?;
6
4
  _accessToken?: string;
7
5
  _apiUrl?: string;
8
- fetchApi: FetchAPI;
9
6
  constructor(accessToken?: string, apiUrl?: string);
10
- get api(): DefaultApi;
11
- fetch(url: string): any;
12
- setVariables({ accessToken, apiUrl, fetchApi, }: {
7
+ fetch(url: string): Promise<any>;
8
+ /**
9
+ *
10
+ * @deprecated use @flatfile/cross-env-config instead
11
+ */
12
+ setVariables({ accessToken, apiUrl, }: {
13
13
  accessToken?: string;
14
14
  apiUrl?: string;
15
- fetchApi?: any;
16
15
  }): void;
17
16
  }
18
17
 
@@ -47,7 +46,7 @@ declare class FlatfileEvent extends AuthenticatedClient {
47
46
  readonly context: any;
48
47
  readonly payload: any;
49
48
  readonly cache: EventCache;
50
- constructor(src: Event, accessToken?: string, apiUrl?: string);
49
+ constructor(src: Flatfile.Event, accessToken?: string, apiUrl?: string);
51
50
  /**
52
51
  * Should return either event body if expanded already or fetch data from the
53
52
  * signed callback URL
@@ -101,13 +100,13 @@ declare class EventHandler extends AuthenticatedClient {
101
100
  *
102
101
  * @param event
103
102
  */
104
- dispatchEvent(event: FlatfileEvent | Event | any): Promise<void>;
103
+ dispatchEvent(event: FlatfileEvent | Flatfile.Event | any): Promise<void>;
105
104
  /**
106
105
  * @deprecated legacy shim for receiving events from the VM layer
107
106
  * @alias dispatchEvent
108
107
  * @param event
109
108
  */
110
- routeEvent(event: Event): Promise<void>;
109
+ routeEvent(event: Flatfile.Event): Promise<void>;
111
110
  /**
112
111
  * Actually trigger the event listeners on this particular target
113
112
  *
@@ -220,29 +219,18 @@ declare class Browser extends EventDriver {
220
219
  _accessToken?: string;
221
220
  _apiUrl?: string;
222
221
  _environmentId?: string;
223
- _fetchApi: FetchAPI;
224
- constructor({ apiUrl, accessToken, environmentId, fetchApi, }: {
222
+ constructor({ apiUrl, accessToken, environmentId, }: {
225
223
  apiUrl: string;
226
224
  accessToken: string;
227
225
  environmentId?: string;
228
- fetchApi: FetchAPI;
226
+ /**
227
+ * @deprecated
228
+ */
229
+ fetchApi: any;
229
230
  });
230
231
  mountEventHandler(handler: EventHandler): this;
231
232
  }
232
233
 
233
- declare class PollingEventDriver extends EventDriver {
234
- environmentId?: string;
235
- apiUrl: string;
236
- accessToken: string;
237
- constructor({ environmentId, apiUrl, accessToken, }: {
238
- environmentId?: string;
239
- apiUrl?: string;
240
- accessToken?: string;
241
- });
242
- start(): void;
243
- shutdown(): void;
244
- }
245
-
246
234
  /**
247
235
  * Flatfile's Virtual Machine is stateless / serverless. So when a new event
248
236
  * is handled, it will just call `handle(event)`.
@@ -265,4 +253,4 @@ declare class FlatfileVirtualMachine extends EventDriver {
265
253
  declare class Client extends FlatfileListener {
266
254
  }
267
255
 
268
- export { Arrayable, AuthenticatedClient, Browser, Client, EventCallback, EventFilter, EventHandler, FlatfileEvent, FlatfileListener, FlatfileVirtualMachine, PollingEventDriver };
256
+ export { Arrayable, AuthenticatedClient, Browser, Client, EventCallback, EventDriver, EventFilter, EventHandler, FlatfileEvent, FlatfileListener, FlatfileVirtualMachine };
package/dist/index.js CHANGED
@@ -5,9 +5,6 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __getProtoOf = Object.getPrototypeOf;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __commonJS = (cb, mod) => function __require() {
9
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
10
- };
11
8
  var __export = (target, all) => {
12
9
  for (var name in all)
13
10
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -30,306 +27,134 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
30
27
  ));
31
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
29
 
33
- // ../../node_modules/ansi-colors/symbols.js
34
- var require_symbols = __commonJS({
35
- "../../node_modules/ansi-colors/symbols.js"(exports, module2) {
36
- "use strict";
37
- var isHyper = typeof process !== "undefined" && process.env.TERM_PROGRAM === "Hyper";
38
- var isWindows = typeof process !== "undefined" && process.platform === "win32";
39
- var isLinux = typeof process !== "undefined" && process.platform === "linux";
40
- var common = {
41
- ballotDisabled: "\u2612",
42
- ballotOff: "\u2610",
43
- ballotOn: "\u2611",
44
- bullet: "\u2022",
45
- bulletWhite: "\u25E6",
46
- fullBlock: "\u2588",
47
- heart: "\u2764",
48
- identicalTo: "\u2261",
49
- line: "\u2500",
50
- mark: "\u203B",
51
- middot: "\xB7",
52
- minus: "\uFF0D",
53
- multiplication: "\xD7",
54
- obelus: "\xF7",
55
- pencilDownRight: "\u270E",
56
- pencilRight: "\u270F",
57
- pencilUpRight: "\u2710",
58
- percent: "%",
59
- pilcrow2: "\u2761",
60
- pilcrow: "\xB6",
61
- plusMinus: "\xB1",
62
- question: "?",
63
- section: "\xA7",
64
- starsOff: "\u2606",
65
- starsOn: "\u2605",
66
- upDownArrow: "\u2195"
67
- };
68
- var windows = Object.assign({}, common, {
69
- check: "\u221A",
70
- cross: "\xD7",
71
- ellipsisLarge: "...",
72
- ellipsis: "...",
73
- info: "i",
74
- questionSmall: "?",
75
- pointer: ">",
76
- pointerSmall: "\xBB",
77
- radioOff: "( )",
78
- radioOn: "(*)",
79
- warning: "\u203C"
80
- });
81
- var other = Object.assign({}, common, {
82
- ballotCross: "\u2718",
83
- check: "\u2714",
84
- cross: "\u2716",
85
- ellipsisLarge: "\u22EF",
86
- ellipsis: "\u2026",
87
- info: "\u2139",
88
- questionFull: "\uFF1F",
89
- questionSmall: "\uFE56",
90
- pointer: isLinux ? "\u25B8" : "\u276F",
91
- pointerSmall: isLinux ? "\u2023" : "\u203A",
92
- radioOff: "\u25EF",
93
- radioOn: "\u25C9",
94
- warning: "\u26A0"
95
- });
96
- module2.exports = isWindows && !isHyper ? windows : other;
97
- Reflect.defineProperty(module2.exports, "common", { enumerable: false, value: common });
98
- Reflect.defineProperty(module2.exports, "windows", { enumerable: false, value: windows });
99
- Reflect.defineProperty(module2.exports, "other", { enumerable: false, value: other });
100
- }
101
- });
102
-
103
- // ../../node_modules/ansi-colors/index.js
104
- var require_ansi_colors = __commonJS({
105
- "../../node_modules/ansi-colors/index.js"(exports, module2) {
106
- "use strict";
107
- var isObject = (val) => val !== null && typeof val === "object" && !Array.isArray(val);
108
- var ANSI_REGEX = /[\u001b\u009b][[\]#;?()]*(?:(?:(?:[^\W_]*;?[^\W_]*)\u0007)|(?:(?:[0-9]{1,4}(;[0-9]{0,4})*)?[~0-9=<>cf-nqrtyA-PRZ]))/g;
109
- var hasColor = () => {
110
- if (typeof process !== "undefined") {
111
- return process.env.FORCE_COLOR !== "0";
112
- }
113
- return false;
114
- };
115
- var create = () => {
116
- const colors = {
117
- enabled: hasColor(),
118
- visible: true,
119
- styles: {},
120
- keys: {}
121
- };
122
- const ansi = (style2) => {
123
- let open = style2.open = `\x1B[${style2.codes[0]}m`;
124
- let close = style2.close = `\x1B[${style2.codes[1]}m`;
125
- let regex = style2.regex = new RegExp(`\\u001b\\[${style2.codes[1]}m`, "g");
126
- style2.wrap = (input, newline) => {
127
- if (input.includes(close))
128
- input = input.replace(regex, close + open);
129
- let output = open + input + close;
130
- return newline ? output.replace(/\r*\n/g, `${close}$&${open}`) : output;
131
- };
132
- return style2;
133
- };
134
- const wrap = (style2, input, newline) => {
135
- return typeof style2 === "function" ? style2(input) : style2.wrap(input, newline);
136
- };
137
- const style = (input, stack) => {
138
- if (input === "" || input == null)
139
- return "";
140
- if (colors.enabled === false)
141
- return input;
142
- if (colors.visible === false)
143
- return "";
144
- let str = "" + input;
145
- let nl = str.includes("\n");
146
- let n = stack.length;
147
- if (n > 0 && stack.includes("unstyle")) {
148
- stack = [.../* @__PURE__ */ new Set(["unstyle", ...stack])].reverse();
149
- }
150
- while (n-- > 0)
151
- str = wrap(colors.styles[stack[n]], str, nl);
152
- return str;
153
- };
154
- const define = (name, codes, type) => {
155
- colors.styles[name] = ansi({ name, codes });
156
- let keys = colors.keys[type] || (colors.keys[type] = []);
157
- keys.push(name);
158
- Reflect.defineProperty(colors, name, {
159
- configurable: true,
160
- enumerable: true,
161
- set(value) {
162
- colors.alias(name, value);
163
- },
164
- get() {
165
- let color = (input) => style(input, color.stack);
166
- Reflect.setPrototypeOf(color, colors);
167
- color.stack = this.stack ? this.stack.concat(name) : [name];
168
- return color;
169
- }
170
- });
171
- };
172
- define("reset", [0, 0], "modifier");
173
- define("bold", [1, 22], "modifier");
174
- define("dim", [2, 22], "modifier");
175
- define("italic", [3, 23], "modifier");
176
- define("underline", [4, 24], "modifier");
177
- define("inverse", [7, 27], "modifier");
178
- define("hidden", [8, 28], "modifier");
179
- define("strikethrough", [9, 29], "modifier");
180
- define("black", [30, 39], "color");
181
- define("red", [31, 39], "color");
182
- define("green", [32, 39], "color");
183
- define("yellow", [33, 39], "color");
184
- define("blue", [34, 39], "color");
185
- define("magenta", [35, 39], "color");
186
- define("cyan", [36, 39], "color");
187
- define("white", [37, 39], "color");
188
- define("gray", [90, 39], "color");
189
- define("grey", [90, 39], "color");
190
- define("bgBlack", [40, 49], "bg");
191
- define("bgRed", [41, 49], "bg");
192
- define("bgGreen", [42, 49], "bg");
193
- define("bgYellow", [43, 49], "bg");
194
- define("bgBlue", [44, 49], "bg");
195
- define("bgMagenta", [45, 49], "bg");
196
- define("bgCyan", [46, 49], "bg");
197
- define("bgWhite", [47, 49], "bg");
198
- define("blackBright", [90, 39], "bright");
199
- define("redBright", [91, 39], "bright");
200
- define("greenBright", [92, 39], "bright");
201
- define("yellowBright", [93, 39], "bright");
202
- define("blueBright", [94, 39], "bright");
203
- define("magentaBright", [95, 39], "bright");
204
- define("cyanBright", [96, 39], "bright");
205
- define("whiteBright", [97, 39], "bright");
206
- define("bgBlackBright", [100, 49], "bgBright");
207
- define("bgRedBright", [101, 49], "bgBright");
208
- define("bgGreenBright", [102, 49], "bgBright");
209
- define("bgYellowBright", [103, 49], "bgBright");
210
- define("bgBlueBright", [104, 49], "bgBright");
211
- define("bgMagentaBright", [105, 49], "bgBright");
212
- define("bgCyanBright", [106, 49], "bgBright");
213
- define("bgWhiteBright", [107, 49], "bgBright");
214
- colors.ansiRegex = ANSI_REGEX;
215
- colors.hasColor = colors.hasAnsi = (str) => {
216
- colors.ansiRegex.lastIndex = 0;
217
- return typeof str === "string" && str !== "" && colors.ansiRegex.test(str);
218
- };
219
- colors.alias = (name, color) => {
220
- let fn = typeof color === "string" ? colors[color] : color;
221
- if (typeof fn !== "function") {
222
- throw new TypeError("Expected alias to be the name of an existing color (string) or a function");
223
- }
224
- if (!fn.stack) {
225
- Reflect.defineProperty(fn, "name", { value: name });
226
- colors.styles[name] = fn;
227
- fn.stack = [name];
228
- }
229
- Reflect.defineProperty(colors, name, {
230
- configurable: true,
231
- enumerable: true,
232
- set(value) {
233
- colors.alias(name, value);
234
- },
235
- get() {
236
- let color2 = (input) => style(input, color2.stack);
237
- Reflect.setPrototypeOf(color2, colors);
238
- color2.stack = this.stack ? this.stack.concat(fn.stack) : fn.stack;
239
- return color2;
240
- }
241
- });
242
- };
243
- colors.theme = (custom) => {
244
- if (!isObject(custom))
245
- throw new TypeError("Expected theme to be an object");
246
- for (let name of Object.keys(custom)) {
247
- colors.alias(name, custom[name]);
248
- }
249
- return colors;
250
- };
251
- colors.alias("unstyle", (str) => {
252
- if (typeof str === "string" && str !== "") {
253
- colors.ansiRegex.lastIndex = 0;
254
- return str.replace(colors.ansiRegex, "");
255
- }
256
- return "";
257
- });
258
- colors.alias("noop", (str) => str);
259
- colors.none = colors.clear = colors.noop;
260
- colors.stripColor = colors.unstyle;
261
- colors.symbols = require_symbols();
262
- colors.define = define;
263
- return colors;
264
- };
265
- module2.exports = create();
266
- module2.exports.create = create;
267
- }
268
- });
269
-
270
30
  // src/index.ts
271
31
  var src_exports = {};
272
32
  __export(src_exports, {
273
33
  AuthenticatedClient: () => AuthenticatedClient,
274
34
  Browser: () => Browser,
275
35
  Client: () => Client,
36
+ EventDriver: () => EventDriver,
276
37
  EventHandler: () => EventHandler,
277
38
  FlatfileEvent: () => FlatfileEvent,
278
39
  FlatfileListener: () => FlatfileListener,
279
- FlatfileVirtualMachine: () => FlatfileVirtualMachine,
280
- PollingEventDriver: () => PollingEventDriver
40
+ FlatfileVirtualMachine: () => FlatfileVirtualMachine
281
41
  });
282
42
  module.exports = __toCommonJS(src_exports);
283
43
 
44
+ // ../cross-env-config/dist/index.mjs
45
+ var CrossEnvConfig = class {
46
+ /**
47
+ * Get a config value from either the environment or any registry overrides
48
+ * @param prop
49
+ */
50
+ static get(prop) {
51
+ return this.safeEnvLookup(prop);
52
+ }
53
+ /**
54
+ * Set a value explicitly
55
+ *
56
+ * @param key
57
+ * @param value
58
+ */
59
+ static set(key, value) {
60
+ return this._overrides.set(key, value);
61
+ }
62
+ /**
63
+ * Alias a key to another key if helpful. This is useful if you have different naming
64
+ * constructs for different environments.
65
+ *
66
+ * @param from
67
+ * @param to
68
+ */
69
+ static alias(from, to) {
70
+ return this._aliases.set(from, to);
71
+ }
72
+ /**
73
+ * Helpful if you've decided to store settings in another object and want to
74
+ * make that available here. For example in client-side implementations you may reserve
75
+ * a window.FLATFILE_CONFIG object to store settings.
76
+ *
77
+ * @param obj
78
+ */
79
+ static attachConfigRegistry(obj) {
80
+ this._registry = obj;
81
+ }
82
+ /**
83
+ * Use this to provide an override getter for config values. This is useful
84
+ * if you need to dynamically look up values. Overrides will still take precedence.
85
+ *
86
+ * @param cb
87
+ */
88
+ static attachConfigFactory(cb) {
89
+ this._factory = cb;
90
+ }
91
+ static reset() {
92
+ this._overrides = /* @__PURE__ */ new Map();
93
+ this._registry = void 0;
94
+ this._factory = void 0;
95
+ }
96
+ /**
97
+ * Internal function for traversing the possible environment sources for a value
98
+ *
99
+ * @param prop
100
+ * @private
101
+ */
102
+ static safeEnvLookup(prop) {
103
+ let values = [];
104
+ if (this._overrides.get(prop)) {
105
+ values.push(this._overrides.get(prop));
106
+ }
107
+ if (typeof this._registry === "object") {
108
+ values.push(this._registry[prop]);
109
+ }
110
+ if (typeof this._factory === "function") {
111
+ values.push(this._factory(prop));
112
+ }
113
+ if (typeof process === "object" && typeof process.env === "object") {
114
+ values.push(process.env[prop]);
115
+ }
116
+ const foundValue = values.find((v) => v !== void 0);
117
+ if (foundValue !== void 0) {
118
+ return foundValue;
119
+ }
120
+ const alias = this._aliases.get(prop);
121
+ if (alias) {
122
+ return this.safeEnvLookup(alias);
123
+ }
124
+ return void 0;
125
+ }
126
+ };
127
+ CrossEnvConfig._overrides = /* @__PURE__ */ new Map();
128
+ CrossEnvConfig._aliases = /* @__PURE__ */ new Map();
129
+
284
130
  // src/events/authenticated.client.ts
285
- var import_api = require("@flatfile/api");
286
- var import_node_fetch = __toESM(require("node-fetch"));
287
- var FLATFILE_API_URL = process.env.AGENT_INTERNAL_URL || "http://localhost:3000";
131
+ var import_axios = __toESM(require("axios"));
288
132
  var AuthenticatedClient = class {
289
133
  constructor(accessToken, apiUrl) {
290
- this._accessToken = accessToken || process.env.FLATFILE_BEARER_TOKEN || "...";
134
+ const FLATFILE_API_URL = CrossEnvConfig.get("AGENT_INTERNAL_URL") || "http://localhost:3000";
135
+ const bearerToken = CrossEnvConfig.get("FLATFILE_BEARER_TOKEN");
136
+ this._accessToken = accessToken || bearerToken || "...";
291
137
  this._apiUrl = apiUrl || FLATFILE_API_URL;
292
138
  }
293
- get api() {
294
- if (this._api) {
295
- return this._api;
296
- }
297
- const accessToken = this._accessToken;
298
- const apiUrl = this._apiUrl;
299
- const ClientConfig = new import_api.Configuration({
300
- basePath: `${apiUrl}/v1`,
301
- fetchApi: import_node_fetch.default,
302
- accessToken,
303
- headers: {
304
- Authorization: `Bearer ${accessToken || "..."}`,
305
- "x-disable-hooks": "true"
306
- }
307
- });
308
- this._api = new import_api.DefaultApi(ClientConfig);
309
- return this._api;
310
- }
311
139
  fetch(url) {
312
- if (this._fetchApi) {
313
- return this._fetchApi;
314
- }
315
140
  const headers = {
316
141
  Authorization: `Bearer ${this._accessToken}`,
317
142
  "x-disable-hooks": "true"
318
143
  };
319
144
  const fetchUrl = this._apiUrl + "/" + url;
320
- this._fetchApi = (0, import_node_fetch.default)(fetchUrl, {
321
- headers
322
- }).then((resp) => resp.json()).then((resp) => resp.data);
323
- return this._fetchApi;
145
+ return import_axios.default.get(fetchUrl, { headers }).then((resp) => resp.data.data).catch((err) => {
146
+ });
324
147
  }
148
+ /**
149
+ *
150
+ * @deprecated use @flatfile/cross-env-config instead
151
+ */
325
152
  setVariables({
326
153
  accessToken,
327
- apiUrl,
328
- fetchApi
154
+ apiUrl
329
155
  }) {
330
156
  this._accessToken = accessToken;
331
157
  this._apiUrl = apiUrl;
332
- this.fetchApi = fetchApi;
333
158
  }
334
159
  };
335
160
 
@@ -485,12 +310,12 @@ function transform(pattern, separator) {
485
310
  }
486
311
  continue;
487
312
  }
488
- for (var c2 = 0; c2 < segment.length; c2++) {
489
- var char = segment[c2];
313
+ for (var c = 0; c < segment.length; c++) {
314
+ var char = segment[c];
490
315
  if (char === "\\") {
491
- if (c2 < segment.length - 1) {
492
- result += escapeRegExpChar(segment[c2 + 1]);
493
- c2++;
316
+ if (c < segment.length - 1) {
317
+ result += escapeRegExpChar(segment[c + 1]);
318
+ c++;
494
319
  }
495
320
  } else if (char === "?") {
496
321
  result += wildcard;
@@ -775,84 +600,23 @@ var Browser = class extends EventDriver {
775
600
  constructor({
776
601
  apiUrl,
777
602
  accessToken,
778
- environmentId,
779
- fetchApi
603
+ environmentId
780
604
  }) {
781
605
  super();
782
606
  this._apiUrl = apiUrl;
783
607
  this._accessToken = accessToken;
784
608
  this._environmentId = environmentId || "";
785
- this._fetchApi = fetchApi || void 0;
786
609
  }
787
610
  mountEventHandler(handler) {
788
611
  handler.setVariables({
789
612
  accessToken: this._accessToken,
790
- apiUrl: this._apiUrl,
791
- fetchApi: this._fetchApi
613
+ apiUrl: this._apiUrl
792
614
  });
793
615
  this._handler = handler;
794
616
  return this;
795
617
  }
796
618
  };
797
619
 
798
- // src/event-drivers/Polling.ts
799
- var import_ansi_colors = __toESM(require_ansi_colors());
800
- var events = /* @__PURE__ */ new Map();
801
- var PollingEventDriver = class extends EventDriver {
802
- constructor({
803
- environmentId,
804
- apiUrl,
805
- accessToken
806
- }) {
807
- super();
808
- this.apiUrl = apiUrl || process.env.AGENT_INTERNAL_URL || "https://platform.flatfile.com/api/";
809
- this.accessToken = accessToken || process.env.FLATFILE_API_KEY || process.env.FLATFILE_BEARER_TOKEN || "...";
810
- this.environmentId = environmentId || process.env.FLATFILE_ENVIRONMENT_ID;
811
- }
812
- start() {
813
- this.handler.setVariables({
814
- accessToken: this.accessToken,
815
- apiUrl: this.apiUrl
816
- });
817
- let lastTimestamp = new Date(Date.now() - 5e3);
818
- if (!this.environmentId) {
819
- throw new Error("environmentId is required");
820
- }
821
- setInterval(() => {
822
- this.handler.api.getEvents({
823
- since: lastTimestamp,
824
- includeAcknowledged: false,
825
- environmentId: this.environmentId
826
- }).then((res) => {
827
- process.stdout.cursorTo(0);
828
- process.stdout.clearLine(1);
829
- if (!res.data?.length) {
830
- process.stdout.write(
831
- `${import_ansi_colors.default.white.bgMagentaBright(
832
- "listening for events"
833
- )} at ${lastTimestamp.toLocaleString()}`
834
- );
835
- }
836
- res.data?.forEach((e) => {
837
- if (!events.get(e.id)) {
838
- process.stdout.write(
839
- `${import_ansi_colors.default.white.bgBlue(e.topic)} ${import_ansi_colors.default.white.bgYellow(
840
- e.id
841
- )} ${e.createdAt?.toLocaleString()}
842
- `
843
- );
844
- events.set(e.id, true);
845
- this.dispatchEvent(e);
846
- }
847
- });
848
- }).catch(console.error);
849
- lastTimestamp = new Date(Date.now() - 5e3);
850
- }, 500);
851
- }
852
- shutdown() {
853
- }
854
- };
855
-
856
620
  // src/event-drivers/FlatfileVirtualMachine.ts
857
621
  var FlatfileVirtualMachine = class extends EventDriver {
858
622
  /**
@@ -879,9 +643,9 @@ var Client = class extends FlatfileListener {
879
643
  AuthenticatedClient,
880
644
  Browser,
881
645
  Client,
646
+ EventDriver,
882
647
  EventHandler,
883
648
  FlatfileEvent,
884
649
  FlatfileListener,
885
- FlatfileVirtualMachine,
886
- PollingEventDriver
650
+ FlatfileVirtualMachine
887
651
  });