@flatfile/listener 0.1.1 → 0.2.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.
- package/.turbo/turbo-build.log +7 -7
- package/CHANGELOG.md +12 -0
- package/dist/index.d.ts +16 -28
- package/dist/index.js +21 -343
- package/dist/index.mjs +19 -364
- package/package.json +7 -4
- package/src/event-drivers/Browser.ts +4 -6
- package/src/event-drivers/index.ts +1 -1
- package/src/events/authenticated.client.ts +11 -44
- package/src/events/event.handler.ts +3 -3
- package/src/events/flatfile.event.ts +2 -2
- package/src/dev.ts +0 -13
- package/src/event-drivers/Polling.ts +0 -82
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @flatfile/listener@0.
|
|
2
|
+
> @flatfile/listener@0.2.0 build
|
|
3
3
|
> tsup src/index.ts --format esm,cjs --dts
|
|
4
4
|
|
|
5
5
|
[34mCLI[39m Building entry: src/index.ts
|
|
@@ -8,10 +8,10 @@
|
|
|
8
8
|
[34mCLI[39m Target: es2020
|
|
9
9
|
[34mESM[39m Build start
|
|
10
10
|
[34mCJS[39m Build start
|
|
11
|
-
[32mESM[39m [1mdist/index.mjs [22m[
|
|
12
|
-
[32mESM[39m ⚡️ Build success in
|
|
13
|
-
[32mCJS[39m [1mdist/index.js [22m[
|
|
14
|
-
[32mCJS[39m ⚡️ Build success in
|
|
11
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m13.73 KB[39m
|
|
12
|
+
[32mESM[39m ⚡️ Build success in 295ms
|
|
13
|
+
[32mCJS[39m [1mdist/index.js [22m[32m15.67 KB[39m
|
|
14
|
+
[32mCJS[39m ⚡️ Build success in 293ms
|
|
15
15
|
[34mDTS[39m Build start
|
|
16
|
-
[32mDTS[39m ⚡️ Build success in
|
|
17
|
-
[32mDTS[39m [1mdist/index.d.ts [22m[32m7.
|
|
16
|
+
[32mDTS[39m ⚡️ Build success in 9323ms
|
|
17
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m7.14 KB[39m
|
package/CHANGELOG.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
import {
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
224
|
-
constructor({ apiUrl, accessToken, environmentId, fetchApi, }: {
|
|
222
|
+
constructor({ apiUrl, accessToken, environmentId, }: {
|
|
225
223
|
apiUrl: string;
|
|
226
224
|
accessToken: string;
|
|
227
225
|
environmentId?: string;
|
|
228
|
-
|
|
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
|
|
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,48 @@ 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
|
|
|
284
44
|
// src/events/authenticated.client.ts
|
|
285
|
-
var
|
|
286
|
-
var import_node_fetch = __toESM(require("node-fetch"));
|
|
287
|
-
var FLATFILE_API_URL = process.env.AGENT_INTERNAL_URL || "http://localhost:3000";
|
|
45
|
+
var import_axios = __toESM(require("axios"));
|
|
288
46
|
var AuthenticatedClient = class {
|
|
289
47
|
constructor(accessToken, apiUrl) {
|
|
48
|
+
const FLATFILE_API_URL = process.env.AGENT_INTERNAL_URL || "http://localhost:3000";
|
|
290
49
|
this._accessToken = accessToken || process.env.FLATFILE_BEARER_TOKEN || "...";
|
|
291
50
|
this._apiUrl = apiUrl || FLATFILE_API_URL;
|
|
292
51
|
}
|
|
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
52
|
fetch(url) {
|
|
312
|
-
if (this._fetchApi) {
|
|
313
|
-
return this._fetchApi;
|
|
314
|
-
}
|
|
315
53
|
const headers = {
|
|
316
54
|
Authorization: `Bearer ${this._accessToken}`,
|
|
317
55
|
"x-disable-hooks": "true"
|
|
318
56
|
};
|
|
319
57
|
const fetchUrl = this._apiUrl + "/" + url;
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
})
|
|
323
|
-
return this._fetchApi;
|
|
58
|
+
console.log({ fetchUrl });
|
|
59
|
+
return import_axios.default.get(fetchUrl, { headers }).then((resp) => resp.data.data).catch((err) => {
|
|
60
|
+
});
|
|
324
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
*
|
|
64
|
+
* @deprecated use @flatfile/cross-env-config instead
|
|
65
|
+
*/
|
|
325
66
|
setVariables({
|
|
326
67
|
accessToken,
|
|
327
|
-
apiUrl
|
|
328
|
-
fetchApi
|
|
68
|
+
apiUrl
|
|
329
69
|
}) {
|
|
330
70
|
this._accessToken = accessToken;
|
|
331
71
|
this._apiUrl = apiUrl;
|
|
332
|
-
this.fetchApi = fetchApi;
|
|
333
72
|
}
|
|
334
73
|
};
|
|
335
74
|
|
|
@@ -485,12 +224,12 @@ function transform(pattern, separator) {
|
|
|
485
224
|
}
|
|
486
225
|
continue;
|
|
487
226
|
}
|
|
488
|
-
for (var
|
|
489
|
-
var char = segment[
|
|
227
|
+
for (var c = 0; c < segment.length; c++) {
|
|
228
|
+
var char = segment[c];
|
|
490
229
|
if (char === "\\") {
|
|
491
|
-
if (
|
|
492
|
-
result += escapeRegExpChar(segment[
|
|
493
|
-
|
|
230
|
+
if (c < segment.length - 1) {
|
|
231
|
+
result += escapeRegExpChar(segment[c + 1]);
|
|
232
|
+
c++;
|
|
494
233
|
}
|
|
495
234
|
} else if (char === "?") {
|
|
496
235
|
result += wildcard;
|
|
@@ -775,84 +514,23 @@ var Browser = class extends EventDriver {
|
|
|
775
514
|
constructor({
|
|
776
515
|
apiUrl,
|
|
777
516
|
accessToken,
|
|
778
|
-
environmentId
|
|
779
|
-
fetchApi
|
|
517
|
+
environmentId
|
|
780
518
|
}) {
|
|
781
519
|
super();
|
|
782
520
|
this._apiUrl = apiUrl;
|
|
783
521
|
this._accessToken = accessToken;
|
|
784
522
|
this._environmentId = environmentId || "";
|
|
785
|
-
this._fetchApi = fetchApi || void 0;
|
|
786
523
|
}
|
|
787
524
|
mountEventHandler(handler) {
|
|
788
525
|
handler.setVariables({
|
|
789
526
|
accessToken: this._accessToken,
|
|
790
|
-
apiUrl: this._apiUrl
|
|
791
|
-
fetchApi: this._fetchApi
|
|
527
|
+
apiUrl: this._apiUrl
|
|
792
528
|
});
|
|
793
529
|
this._handler = handler;
|
|
794
530
|
return this;
|
|
795
531
|
}
|
|
796
532
|
};
|
|
797
533
|
|
|
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 = /* @__PURE__ */ new Date();
|
|
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 = /* @__PURE__ */ new Date();
|
|
850
|
-
}, 500);
|
|
851
|
-
}
|
|
852
|
-
shutdown() {
|
|
853
|
-
}
|
|
854
|
-
};
|
|
855
|
-
|
|
856
534
|
// src/event-drivers/FlatfileVirtualMachine.ts
|
|
857
535
|
var FlatfileVirtualMachine = class extends EventDriver {
|
|
858
536
|
/**
|
|
@@ -879,9 +557,9 @@ var Client = class extends FlatfileListener {
|
|
|
879
557
|
AuthenticatedClient,
|
|
880
558
|
Browser,
|
|
881
559
|
Client,
|
|
560
|
+
EventDriver,
|
|
882
561
|
EventHandler,
|
|
883
562
|
FlatfileEvent,
|
|
884
563
|
FlatfileListener,
|
|
885
|
-
FlatfileVirtualMachine
|
|
886
|
-
PollingEventDriver
|
|
564
|
+
FlatfileVirtualMachine
|
|
887
565
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -1,315 +1,31 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __commonJS = (cb, mod) => function __require() {
|
|
8
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
19
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
20
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
21
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
22
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
23
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
24
|
-
mod
|
|
25
|
-
));
|
|
26
|
-
|
|
27
|
-
// ../../node_modules/ansi-colors/symbols.js
|
|
28
|
-
var require_symbols = __commonJS({
|
|
29
|
-
"../../node_modules/ansi-colors/symbols.js"(exports, module) {
|
|
30
|
-
"use strict";
|
|
31
|
-
var isHyper = typeof process !== "undefined" && process.env.TERM_PROGRAM === "Hyper";
|
|
32
|
-
var isWindows = typeof process !== "undefined" && process.platform === "win32";
|
|
33
|
-
var isLinux = typeof process !== "undefined" && process.platform === "linux";
|
|
34
|
-
var common = {
|
|
35
|
-
ballotDisabled: "\u2612",
|
|
36
|
-
ballotOff: "\u2610",
|
|
37
|
-
ballotOn: "\u2611",
|
|
38
|
-
bullet: "\u2022",
|
|
39
|
-
bulletWhite: "\u25E6",
|
|
40
|
-
fullBlock: "\u2588",
|
|
41
|
-
heart: "\u2764",
|
|
42
|
-
identicalTo: "\u2261",
|
|
43
|
-
line: "\u2500",
|
|
44
|
-
mark: "\u203B",
|
|
45
|
-
middot: "\xB7",
|
|
46
|
-
minus: "\uFF0D",
|
|
47
|
-
multiplication: "\xD7",
|
|
48
|
-
obelus: "\xF7",
|
|
49
|
-
pencilDownRight: "\u270E",
|
|
50
|
-
pencilRight: "\u270F",
|
|
51
|
-
pencilUpRight: "\u2710",
|
|
52
|
-
percent: "%",
|
|
53
|
-
pilcrow2: "\u2761",
|
|
54
|
-
pilcrow: "\xB6",
|
|
55
|
-
plusMinus: "\xB1",
|
|
56
|
-
question: "?",
|
|
57
|
-
section: "\xA7",
|
|
58
|
-
starsOff: "\u2606",
|
|
59
|
-
starsOn: "\u2605",
|
|
60
|
-
upDownArrow: "\u2195"
|
|
61
|
-
};
|
|
62
|
-
var windows = Object.assign({}, common, {
|
|
63
|
-
check: "\u221A",
|
|
64
|
-
cross: "\xD7",
|
|
65
|
-
ellipsisLarge: "...",
|
|
66
|
-
ellipsis: "...",
|
|
67
|
-
info: "i",
|
|
68
|
-
questionSmall: "?",
|
|
69
|
-
pointer: ">",
|
|
70
|
-
pointerSmall: "\xBB",
|
|
71
|
-
radioOff: "( )",
|
|
72
|
-
radioOn: "(*)",
|
|
73
|
-
warning: "\u203C"
|
|
74
|
-
});
|
|
75
|
-
var other = Object.assign({}, common, {
|
|
76
|
-
ballotCross: "\u2718",
|
|
77
|
-
check: "\u2714",
|
|
78
|
-
cross: "\u2716",
|
|
79
|
-
ellipsisLarge: "\u22EF",
|
|
80
|
-
ellipsis: "\u2026",
|
|
81
|
-
info: "\u2139",
|
|
82
|
-
questionFull: "\uFF1F",
|
|
83
|
-
questionSmall: "\uFE56",
|
|
84
|
-
pointer: isLinux ? "\u25B8" : "\u276F",
|
|
85
|
-
pointerSmall: isLinux ? "\u2023" : "\u203A",
|
|
86
|
-
radioOff: "\u25EF",
|
|
87
|
-
radioOn: "\u25C9",
|
|
88
|
-
warning: "\u26A0"
|
|
89
|
-
});
|
|
90
|
-
module.exports = isWindows && !isHyper ? windows : other;
|
|
91
|
-
Reflect.defineProperty(module.exports, "common", { enumerable: false, value: common });
|
|
92
|
-
Reflect.defineProperty(module.exports, "windows", { enumerable: false, value: windows });
|
|
93
|
-
Reflect.defineProperty(module.exports, "other", { enumerable: false, value: other });
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
// ../../node_modules/ansi-colors/index.js
|
|
98
|
-
var require_ansi_colors = __commonJS({
|
|
99
|
-
"../../node_modules/ansi-colors/index.js"(exports, module) {
|
|
100
|
-
"use strict";
|
|
101
|
-
var isObject = (val) => val !== null && typeof val === "object" && !Array.isArray(val);
|
|
102
|
-
var ANSI_REGEX = /[\u001b\u009b][[\]#;?()]*(?:(?:(?:[^\W_]*;?[^\W_]*)\u0007)|(?:(?:[0-9]{1,4}(;[0-9]{0,4})*)?[~0-9=<>cf-nqrtyA-PRZ]))/g;
|
|
103
|
-
var hasColor = () => {
|
|
104
|
-
if (typeof process !== "undefined") {
|
|
105
|
-
return process.env.FORCE_COLOR !== "0";
|
|
106
|
-
}
|
|
107
|
-
return false;
|
|
108
|
-
};
|
|
109
|
-
var create = () => {
|
|
110
|
-
const colors = {
|
|
111
|
-
enabled: hasColor(),
|
|
112
|
-
visible: true,
|
|
113
|
-
styles: {},
|
|
114
|
-
keys: {}
|
|
115
|
-
};
|
|
116
|
-
const ansi = (style2) => {
|
|
117
|
-
let open = style2.open = `\x1B[${style2.codes[0]}m`;
|
|
118
|
-
let close = style2.close = `\x1B[${style2.codes[1]}m`;
|
|
119
|
-
let regex = style2.regex = new RegExp(`\\u001b\\[${style2.codes[1]}m`, "g");
|
|
120
|
-
style2.wrap = (input, newline) => {
|
|
121
|
-
if (input.includes(close))
|
|
122
|
-
input = input.replace(regex, close + open);
|
|
123
|
-
let output = open + input + close;
|
|
124
|
-
return newline ? output.replace(/\r*\n/g, `${close}$&${open}`) : output;
|
|
125
|
-
};
|
|
126
|
-
return style2;
|
|
127
|
-
};
|
|
128
|
-
const wrap = (style2, input, newline) => {
|
|
129
|
-
return typeof style2 === "function" ? style2(input) : style2.wrap(input, newline);
|
|
130
|
-
};
|
|
131
|
-
const style = (input, stack) => {
|
|
132
|
-
if (input === "" || input == null)
|
|
133
|
-
return "";
|
|
134
|
-
if (colors.enabled === false)
|
|
135
|
-
return input;
|
|
136
|
-
if (colors.visible === false)
|
|
137
|
-
return "";
|
|
138
|
-
let str = "" + input;
|
|
139
|
-
let nl = str.includes("\n");
|
|
140
|
-
let n = stack.length;
|
|
141
|
-
if (n > 0 && stack.includes("unstyle")) {
|
|
142
|
-
stack = [.../* @__PURE__ */ new Set(["unstyle", ...stack])].reverse();
|
|
143
|
-
}
|
|
144
|
-
while (n-- > 0)
|
|
145
|
-
str = wrap(colors.styles[stack[n]], str, nl);
|
|
146
|
-
return str;
|
|
147
|
-
};
|
|
148
|
-
const define = (name, codes, type) => {
|
|
149
|
-
colors.styles[name] = ansi({ name, codes });
|
|
150
|
-
let keys = colors.keys[type] || (colors.keys[type] = []);
|
|
151
|
-
keys.push(name);
|
|
152
|
-
Reflect.defineProperty(colors, name, {
|
|
153
|
-
configurable: true,
|
|
154
|
-
enumerable: true,
|
|
155
|
-
set(value) {
|
|
156
|
-
colors.alias(name, value);
|
|
157
|
-
},
|
|
158
|
-
get() {
|
|
159
|
-
let color = (input) => style(input, color.stack);
|
|
160
|
-
Reflect.setPrototypeOf(color, colors);
|
|
161
|
-
color.stack = this.stack ? this.stack.concat(name) : [name];
|
|
162
|
-
return color;
|
|
163
|
-
}
|
|
164
|
-
});
|
|
165
|
-
};
|
|
166
|
-
define("reset", [0, 0], "modifier");
|
|
167
|
-
define("bold", [1, 22], "modifier");
|
|
168
|
-
define("dim", [2, 22], "modifier");
|
|
169
|
-
define("italic", [3, 23], "modifier");
|
|
170
|
-
define("underline", [4, 24], "modifier");
|
|
171
|
-
define("inverse", [7, 27], "modifier");
|
|
172
|
-
define("hidden", [8, 28], "modifier");
|
|
173
|
-
define("strikethrough", [9, 29], "modifier");
|
|
174
|
-
define("black", [30, 39], "color");
|
|
175
|
-
define("red", [31, 39], "color");
|
|
176
|
-
define("green", [32, 39], "color");
|
|
177
|
-
define("yellow", [33, 39], "color");
|
|
178
|
-
define("blue", [34, 39], "color");
|
|
179
|
-
define("magenta", [35, 39], "color");
|
|
180
|
-
define("cyan", [36, 39], "color");
|
|
181
|
-
define("white", [37, 39], "color");
|
|
182
|
-
define("gray", [90, 39], "color");
|
|
183
|
-
define("grey", [90, 39], "color");
|
|
184
|
-
define("bgBlack", [40, 49], "bg");
|
|
185
|
-
define("bgRed", [41, 49], "bg");
|
|
186
|
-
define("bgGreen", [42, 49], "bg");
|
|
187
|
-
define("bgYellow", [43, 49], "bg");
|
|
188
|
-
define("bgBlue", [44, 49], "bg");
|
|
189
|
-
define("bgMagenta", [45, 49], "bg");
|
|
190
|
-
define("bgCyan", [46, 49], "bg");
|
|
191
|
-
define("bgWhite", [47, 49], "bg");
|
|
192
|
-
define("blackBright", [90, 39], "bright");
|
|
193
|
-
define("redBright", [91, 39], "bright");
|
|
194
|
-
define("greenBright", [92, 39], "bright");
|
|
195
|
-
define("yellowBright", [93, 39], "bright");
|
|
196
|
-
define("blueBright", [94, 39], "bright");
|
|
197
|
-
define("magentaBright", [95, 39], "bright");
|
|
198
|
-
define("cyanBright", [96, 39], "bright");
|
|
199
|
-
define("whiteBright", [97, 39], "bright");
|
|
200
|
-
define("bgBlackBright", [100, 49], "bgBright");
|
|
201
|
-
define("bgRedBright", [101, 49], "bgBright");
|
|
202
|
-
define("bgGreenBright", [102, 49], "bgBright");
|
|
203
|
-
define("bgYellowBright", [103, 49], "bgBright");
|
|
204
|
-
define("bgBlueBright", [104, 49], "bgBright");
|
|
205
|
-
define("bgMagentaBright", [105, 49], "bgBright");
|
|
206
|
-
define("bgCyanBright", [106, 49], "bgBright");
|
|
207
|
-
define("bgWhiteBright", [107, 49], "bgBright");
|
|
208
|
-
colors.ansiRegex = ANSI_REGEX;
|
|
209
|
-
colors.hasColor = colors.hasAnsi = (str) => {
|
|
210
|
-
colors.ansiRegex.lastIndex = 0;
|
|
211
|
-
return typeof str === "string" && str !== "" && colors.ansiRegex.test(str);
|
|
212
|
-
};
|
|
213
|
-
colors.alias = (name, color) => {
|
|
214
|
-
let fn = typeof color === "string" ? colors[color] : color;
|
|
215
|
-
if (typeof fn !== "function") {
|
|
216
|
-
throw new TypeError("Expected alias to be the name of an existing color (string) or a function");
|
|
217
|
-
}
|
|
218
|
-
if (!fn.stack) {
|
|
219
|
-
Reflect.defineProperty(fn, "name", { value: name });
|
|
220
|
-
colors.styles[name] = fn;
|
|
221
|
-
fn.stack = [name];
|
|
222
|
-
}
|
|
223
|
-
Reflect.defineProperty(colors, name, {
|
|
224
|
-
configurable: true,
|
|
225
|
-
enumerable: true,
|
|
226
|
-
set(value) {
|
|
227
|
-
colors.alias(name, value);
|
|
228
|
-
},
|
|
229
|
-
get() {
|
|
230
|
-
let color2 = (input) => style(input, color2.stack);
|
|
231
|
-
Reflect.setPrototypeOf(color2, colors);
|
|
232
|
-
color2.stack = this.stack ? this.stack.concat(fn.stack) : fn.stack;
|
|
233
|
-
return color2;
|
|
234
|
-
}
|
|
235
|
-
});
|
|
236
|
-
};
|
|
237
|
-
colors.theme = (custom) => {
|
|
238
|
-
if (!isObject(custom))
|
|
239
|
-
throw new TypeError("Expected theme to be an object");
|
|
240
|
-
for (let name of Object.keys(custom)) {
|
|
241
|
-
colors.alias(name, custom[name]);
|
|
242
|
-
}
|
|
243
|
-
return colors;
|
|
244
|
-
};
|
|
245
|
-
colors.alias("unstyle", (str) => {
|
|
246
|
-
if (typeof str === "string" && str !== "") {
|
|
247
|
-
colors.ansiRegex.lastIndex = 0;
|
|
248
|
-
return str.replace(colors.ansiRegex, "");
|
|
249
|
-
}
|
|
250
|
-
return "";
|
|
251
|
-
});
|
|
252
|
-
colors.alias("noop", (str) => str);
|
|
253
|
-
colors.none = colors.clear = colors.noop;
|
|
254
|
-
colors.stripColor = colors.unstyle;
|
|
255
|
-
colors.symbols = require_symbols();
|
|
256
|
-
colors.define = define;
|
|
257
|
-
return colors;
|
|
258
|
-
};
|
|
259
|
-
module.exports = create();
|
|
260
|
-
module.exports.create = create;
|
|
261
|
-
}
|
|
262
|
-
});
|
|
263
|
-
|
|
264
1
|
// src/events/authenticated.client.ts
|
|
265
|
-
import
|
|
266
|
-
import fetch from "node-fetch";
|
|
267
|
-
var FLATFILE_API_URL = process.env.AGENT_INTERNAL_URL || "http://localhost:3000";
|
|
2
|
+
import axios from "axios";
|
|
268
3
|
var AuthenticatedClient = class {
|
|
269
4
|
constructor(accessToken, apiUrl) {
|
|
5
|
+
const FLATFILE_API_URL = process.env.AGENT_INTERNAL_URL || "http://localhost:3000";
|
|
270
6
|
this._accessToken = accessToken || process.env.FLATFILE_BEARER_TOKEN || "...";
|
|
271
7
|
this._apiUrl = apiUrl || FLATFILE_API_URL;
|
|
272
8
|
}
|
|
273
|
-
get api() {
|
|
274
|
-
if (this._api) {
|
|
275
|
-
return this._api;
|
|
276
|
-
}
|
|
277
|
-
const accessToken = this._accessToken;
|
|
278
|
-
const apiUrl = this._apiUrl;
|
|
279
|
-
const ClientConfig = new Configuration({
|
|
280
|
-
basePath: `${apiUrl}/v1`,
|
|
281
|
-
fetchApi: fetch,
|
|
282
|
-
accessToken,
|
|
283
|
-
headers: {
|
|
284
|
-
Authorization: `Bearer ${accessToken || "..."}`,
|
|
285
|
-
"x-disable-hooks": "true"
|
|
286
|
-
}
|
|
287
|
-
});
|
|
288
|
-
this._api = new DefaultApi(ClientConfig);
|
|
289
|
-
return this._api;
|
|
290
|
-
}
|
|
291
9
|
fetch(url) {
|
|
292
|
-
if (this._fetchApi) {
|
|
293
|
-
return this._fetchApi;
|
|
294
|
-
}
|
|
295
10
|
const headers = {
|
|
296
11
|
Authorization: `Bearer ${this._accessToken}`,
|
|
297
12
|
"x-disable-hooks": "true"
|
|
298
13
|
};
|
|
299
14
|
const fetchUrl = this._apiUrl + "/" + url;
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
})
|
|
303
|
-
return this._fetchApi;
|
|
15
|
+
console.log({ fetchUrl });
|
|
16
|
+
return axios.get(fetchUrl, { headers }).then((resp) => resp.data.data).catch((err) => {
|
|
17
|
+
});
|
|
304
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
*
|
|
21
|
+
* @deprecated use @flatfile/cross-env-config instead
|
|
22
|
+
*/
|
|
305
23
|
setVariables({
|
|
306
24
|
accessToken,
|
|
307
|
-
apiUrl
|
|
308
|
-
fetchApi
|
|
25
|
+
apiUrl
|
|
309
26
|
}) {
|
|
310
27
|
this._accessToken = accessToken;
|
|
311
28
|
this._apiUrl = apiUrl;
|
|
312
|
-
this.fetchApi = fetchApi;
|
|
313
29
|
}
|
|
314
30
|
};
|
|
315
31
|
|
|
@@ -465,12 +181,12 @@ function transform(pattern, separator) {
|
|
|
465
181
|
}
|
|
466
182
|
continue;
|
|
467
183
|
}
|
|
468
|
-
for (var
|
|
469
|
-
var char = segment[
|
|
184
|
+
for (var c = 0; c < segment.length; c++) {
|
|
185
|
+
var char = segment[c];
|
|
470
186
|
if (char === "\\") {
|
|
471
|
-
if (
|
|
472
|
-
result += escapeRegExpChar(segment[
|
|
473
|
-
|
|
187
|
+
if (c < segment.length - 1) {
|
|
188
|
+
result += escapeRegExpChar(segment[c + 1]);
|
|
189
|
+
c++;
|
|
474
190
|
}
|
|
475
191
|
} else if (char === "?") {
|
|
476
192
|
result += wildcard;
|
|
@@ -755,84 +471,23 @@ var Browser = class extends EventDriver {
|
|
|
755
471
|
constructor({
|
|
756
472
|
apiUrl,
|
|
757
473
|
accessToken,
|
|
758
|
-
environmentId
|
|
759
|
-
fetchApi
|
|
474
|
+
environmentId
|
|
760
475
|
}) {
|
|
761
476
|
super();
|
|
762
477
|
this._apiUrl = apiUrl;
|
|
763
478
|
this._accessToken = accessToken;
|
|
764
479
|
this._environmentId = environmentId || "";
|
|
765
|
-
this._fetchApi = fetchApi || void 0;
|
|
766
480
|
}
|
|
767
481
|
mountEventHandler(handler) {
|
|
768
482
|
handler.setVariables({
|
|
769
483
|
accessToken: this._accessToken,
|
|
770
|
-
apiUrl: this._apiUrl
|
|
771
|
-
fetchApi: this._fetchApi
|
|
484
|
+
apiUrl: this._apiUrl
|
|
772
485
|
});
|
|
773
486
|
this._handler = handler;
|
|
774
487
|
return this;
|
|
775
488
|
}
|
|
776
489
|
};
|
|
777
490
|
|
|
778
|
-
// src/event-drivers/Polling.ts
|
|
779
|
-
var import_ansi_colors = __toESM(require_ansi_colors());
|
|
780
|
-
var events = /* @__PURE__ */ new Map();
|
|
781
|
-
var PollingEventDriver = class extends EventDriver {
|
|
782
|
-
constructor({
|
|
783
|
-
environmentId,
|
|
784
|
-
apiUrl,
|
|
785
|
-
accessToken
|
|
786
|
-
}) {
|
|
787
|
-
super();
|
|
788
|
-
this.apiUrl = apiUrl || process.env.AGENT_INTERNAL_URL || "https://platform.flatfile.com/api/";
|
|
789
|
-
this.accessToken = accessToken || process.env.FLATFILE_API_KEY || process.env.FLATFILE_BEARER_TOKEN || "...";
|
|
790
|
-
this.environmentId = environmentId || process.env.FLATFILE_ENVIRONMENT_ID;
|
|
791
|
-
}
|
|
792
|
-
start() {
|
|
793
|
-
this.handler.setVariables({
|
|
794
|
-
accessToken: this.accessToken,
|
|
795
|
-
apiUrl: this.apiUrl
|
|
796
|
-
});
|
|
797
|
-
let lastTimestamp = /* @__PURE__ */ new Date();
|
|
798
|
-
if (!this.environmentId) {
|
|
799
|
-
throw new Error("environmentId is required");
|
|
800
|
-
}
|
|
801
|
-
setInterval(() => {
|
|
802
|
-
this.handler.api.getEvents({
|
|
803
|
-
since: lastTimestamp,
|
|
804
|
-
includeAcknowledged: false,
|
|
805
|
-
environmentId: this.environmentId
|
|
806
|
-
}).then((res) => {
|
|
807
|
-
process.stdout.cursorTo(0);
|
|
808
|
-
process.stdout.clearLine(1);
|
|
809
|
-
if (!res.data?.length) {
|
|
810
|
-
process.stdout.write(
|
|
811
|
-
`${import_ansi_colors.default.white.bgMagentaBright(
|
|
812
|
-
"listening for events"
|
|
813
|
-
)} at ${lastTimestamp.toLocaleString()}`
|
|
814
|
-
);
|
|
815
|
-
}
|
|
816
|
-
res.data?.forEach((e) => {
|
|
817
|
-
if (!events.get(e.id)) {
|
|
818
|
-
process.stdout.write(
|
|
819
|
-
`${import_ansi_colors.default.white.bgBlue(e.topic)} ${import_ansi_colors.default.white.bgYellow(
|
|
820
|
-
e.id
|
|
821
|
-
)} ${e.createdAt?.toLocaleString()}
|
|
822
|
-
`
|
|
823
|
-
);
|
|
824
|
-
events.set(e.id, true);
|
|
825
|
-
this.dispatchEvent(e);
|
|
826
|
-
}
|
|
827
|
-
});
|
|
828
|
-
}).catch(console.error);
|
|
829
|
-
lastTimestamp = /* @__PURE__ */ new Date();
|
|
830
|
-
}, 500);
|
|
831
|
-
}
|
|
832
|
-
shutdown() {
|
|
833
|
-
}
|
|
834
|
-
};
|
|
835
|
-
|
|
836
491
|
// src/event-drivers/FlatfileVirtualMachine.ts
|
|
837
492
|
var FlatfileVirtualMachine = class extends EventDriver {
|
|
838
493
|
/**
|
|
@@ -858,9 +513,9 @@ export {
|
|
|
858
513
|
AuthenticatedClient,
|
|
859
514
|
Browser,
|
|
860
515
|
Client,
|
|
516
|
+
EventDriver,
|
|
861
517
|
EventHandler,
|
|
862
518
|
FlatfileEvent,
|
|
863
519
|
FlatfileListener,
|
|
864
|
-
FlatfileVirtualMachine
|
|
865
|
-
PollingEventDriver
|
|
520
|
+
FlatfileVirtualMachine
|
|
866
521
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flatfile/listener",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "A PubSub Listener for configuring and using Flatfile",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -27,8 +27,11 @@
|
|
|
27
27
|
"typescript": "^5.0.4"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"
|
|
31
|
-
"flat": "^5.0.2"
|
|
32
|
-
|
|
30
|
+
"ansi-colors": "^4.1.3",
|
|
31
|
+
"flat": "^5.0.2"
|
|
32
|
+
},
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"@flatfile/api": "^1.4.5",
|
|
35
|
+
"axios": "^1.4.0"
|
|
33
36
|
}
|
|
34
37
|
}
|
|
@@ -1,36 +1,34 @@
|
|
|
1
1
|
import { EventDriver } from './_EventDriver'
|
|
2
2
|
import { EventHandler } from '../events'
|
|
3
|
-
import { FetchAPI } from '@flatfile/api'
|
|
4
3
|
|
|
5
4
|
export class Browser extends EventDriver {
|
|
6
5
|
public _accessToken?: string
|
|
7
6
|
public _apiUrl?: string
|
|
8
7
|
public _environmentId?: string
|
|
9
|
-
public _fetchApi: FetchAPI
|
|
10
8
|
|
|
11
9
|
constructor({
|
|
12
10
|
apiUrl,
|
|
13
11
|
accessToken,
|
|
14
12
|
environmentId,
|
|
15
|
-
fetchApi,
|
|
16
13
|
}: {
|
|
17
14
|
apiUrl: string
|
|
18
15
|
accessToken: string
|
|
19
16
|
environmentId?: string
|
|
20
|
-
|
|
17
|
+
/**
|
|
18
|
+
* @deprecated
|
|
19
|
+
*/
|
|
20
|
+
fetchApi: any
|
|
21
21
|
}) {
|
|
22
22
|
super()
|
|
23
23
|
this._apiUrl = apiUrl
|
|
24
24
|
this._accessToken = accessToken
|
|
25
25
|
this._environmentId = environmentId || ''
|
|
26
|
-
this._fetchApi = fetchApi || undefined
|
|
27
26
|
}
|
|
28
27
|
|
|
29
28
|
mountEventHandler(handler: EventHandler): this {
|
|
30
29
|
handler.setVariables({
|
|
31
30
|
accessToken: this._accessToken,
|
|
32
31
|
apiUrl: this._apiUrl,
|
|
33
|
-
fetchApi: this._fetchApi,
|
|
34
32
|
})
|
|
35
33
|
|
|
36
34
|
this._handler = handler
|
|
@@ -1,74 +1,41 @@
|
|
|
1
|
-
import
|
|
2
|
-
import fetch from 'node-fetch'
|
|
3
|
-
|
|
4
|
-
const FLATFILE_API_URL =
|
|
5
|
-
process.env.AGENT_INTERNAL_URL || 'http://localhost:3000'
|
|
1
|
+
import axios from 'axios'
|
|
6
2
|
|
|
7
3
|
export class AuthenticatedClient {
|
|
8
|
-
private _api?: DefaultApi
|
|
9
|
-
private _fetchApi?: FetchAPI
|
|
10
|
-
|
|
11
4
|
public _accessToken?: string
|
|
12
5
|
public _apiUrl?: string
|
|
13
|
-
public fetchApi: FetchAPI
|
|
14
6
|
|
|
15
7
|
constructor(accessToken?: string, apiUrl?: string) {
|
|
8
|
+
const FLATFILE_API_URL =
|
|
9
|
+
process.env.AGENT_INTERNAL_URL || 'http://localhost:3000'
|
|
10
|
+
|
|
16
11
|
this._accessToken =
|
|
17
12
|
accessToken || process.env.FLATFILE_BEARER_TOKEN || '...'
|
|
18
|
-
this._apiUrl = apiUrl || FLATFILE_API_URL
|
|
19
|
-
}
|
|
20
|
-
get api(): DefaultApi {
|
|
21
|
-
if (this._api) {
|
|
22
|
-
return this._api
|
|
23
|
-
}
|
|
24
13
|
|
|
25
|
-
|
|
26
|
-
const apiUrl = this._apiUrl
|
|
27
|
-
|
|
28
|
-
const ClientConfig = new Configuration({
|
|
29
|
-
basePath: `${apiUrl}/v1`,
|
|
30
|
-
fetchApi: fetch,
|
|
31
|
-
accessToken,
|
|
32
|
-
headers: {
|
|
33
|
-
Authorization: `Bearer ${accessToken || '...'}`,
|
|
34
|
-
'x-disable-hooks': 'true',
|
|
35
|
-
},
|
|
36
|
-
})
|
|
37
|
-
this._api = new DefaultApi(ClientConfig)
|
|
38
|
-
return this._api
|
|
14
|
+
this._apiUrl = apiUrl || FLATFILE_API_URL
|
|
39
15
|
}
|
|
40
16
|
|
|
41
17
|
fetch(url: string) {
|
|
42
|
-
if (this._fetchApi) {
|
|
43
|
-
return this._fetchApi
|
|
44
|
-
}
|
|
45
|
-
|
|
46
18
|
const headers = {
|
|
47
19
|
Authorization: `Bearer ${this._accessToken}`,
|
|
48
20
|
'x-disable-hooks': 'true',
|
|
49
21
|
}
|
|
50
22
|
const fetchUrl = this._apiUrl + '/' + url
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
headers,
|
|
54
|
-
})
|
|
55
|
-
.then((resp: any) => resp.json())
|
|
56
|
-
.then((resp: any) => resp.data)
|
|
57
|
-
|
|
58
|
-
return this._fetchApi
|
|
23
|
+
console.log({ fetchUrl })
|
|
24
|
+
return axios.get(fetchUrl, { headers }).then((resp: any) => resp.data.data).catch((err: any) => {})
|
|
59
25
|
}
|
|
60
26
|
|
|
27
|
+
/**
|
|
28
|
+
*
|
|
29
|
+
* @deprecated use @flatfile/cross-env-config instead
|
|
30
|
+
*/
|
|
61
31
|
public setVariables({
|
|
62
32
|
accessToken,
|
|
63
33
|
apiUrl,
|
|
64
|
-
fetchApi,
|
|
65
34
|
}: {
|
|
66
35
|
accessToken?: string
|
|
67
36
|
apiUrl?: string
|
|
68
|
-
fetchApi?: any
|
|
69
37
|
}) {
|
|
70
38
|
this._accessToken = accessToken
|
|
71
39
|
this._apiUrl = apiUrl
|
|
72
|
-
this.fetchApi = fetchApi
|
|
73
40
|
}
|
|
74
41
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AuthenticatedClient } from './authenticated.client'
|
|
2
2
|
import { EventCallback, FlatfileEvent } from './flatfile.event'
|
|
3
3
|
import { glob, objectMatches } from './glob.match'
|
|
4
|
-
import {
|
|
4
|
+
import type { Flatfile } from '@flatfile/api'
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* EventHandler is a Flatfile flavored implementation of EventTarget
|
|
@@ -77,7 +77,7 @@ export class EventHandler extends AuthenticatedClient {
|
|
|
77
77
|
*
|
|
78
78
|
* @param event
|
|
79
79
|
*/
|
|
80
|
-
async dispatchEvent(event: FlatfileEvent |
|
|
80
|
+
async dispatchEvent(event: FlatfileEvent | Flatfile.Event | any): Promise<void> {
|
|
81
81
|
if (!(event instanceof FlatfileEvent)) {
|
|
82
82
|
event = new FlatfileEvent(event, this._accessToken, this._apiUrl)
|
|
83
83
|
if (this._apiUrl && this._accessToken) {
|
|
@@ -107,7 +107,7 @@ export class EventHandler extends AuthenticatedClient {
|
|
|
107
107
|
* @alias dispatchEvent
|
|
108
108
|
* @param event
|
|
109
109
|
*/
|
|
110
|
-
async routeEvent(event:
|
|
110
|
+
async routeEvent(event: Flatfile.Event) {
|
|
111
111
|
return this.dispatchEvent(event)
|
|
112
112
|
}
|
|
113
113
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AuthenticatedClient } from './authenticated.client'
|
|
2
|
-
import {
|
|
2
|
+
import type { Flatfile } from '@flatfile/api'
|
|
3
3
|
import { EventCache } from './cache'
|
|
4
4
|
export class FlatfileEvent extends AuthenticatedClient {
|
|
5
5
|
/**
|
|
@@ -26,7 +26,7 @@ export class FlatfileEvent extends AuthenticatedClient {
|
|
|
26
26
|
public readonly cache: EventCache
|
|
27
27
|
|
|
28
28
|
constructor(
|
|
29
|
-
private readonly src: Event,
|
|
29
|
+
private readonly src: Flatfile.Event,
|
|
30
30
|
accessToken?: string,
|
|
31
31
|
apiUrl?: string
|
|
32
32
|
) {
|
package/src/dev.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { PollingEventDriver } from './event-drivers/Polling'
|
|
2
|
-
import testClient from './examples/Local'
|
|
3
|
-
|
|
4
|
-
const environmentId = process.env.ENVIROMENT_ID || 'dev_env_1234567890'
|
|
5
|
-
|
|
6
|
-
const pollDriver = new PollingEventDriver({
|
|
7
|
-
interval: 1000,
|
|
8
|
-
environmentId,
|
|
9
|
-
})
|
|
10
|
-
|
|
11
|
-
testClient.mount(pollDriver)
|
|
12
|
-
|
|
13
|
-
pollDriver.start()
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import c from 'ansi-colors'
|
|
2
|
-
import { EventDriver } from './_EventDriver'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Todo: this should just be using the version from listener
|
|
6
|
-
*/
|
|
7
|
-
const events = new Map()
|
|
8
|
-
export class PollingEventDriver extends EventDriver {
|
|
9
|
-
environmentId?: string
|
|
10
|
-
apiUrl: string
|
|
11
|
-
accessToken: string
|
|
12
|
-
constructor({
|
|
13
|
-
environmentId,
|
|
14
|
-
apiUrl,
|
|
15
|
-
accessToken,
|
|
16
|
-
}: {
|
|
17
|
-
environmentId?: string
|
|
18
|
-
apiUrl?: string
|
|
19
|
-
accessToken?: string
|
|
20
|
-
}) {
|
|
21
|
-
super()
|
|
22
|
-
this.apiUrl =
|
|
23
|
-
apiUrl ||
|
|
24
|
-
process.env.AGENT_INTERNAL_URL ||
|
|
25
|
-
'https://platform.flatfile.com/api/'
|
|
26
|
-
this.accessToken =
|
|
27
|
-
accessToken ||
|
|
28
|
-
process.env.FLATFILE_API_KEY ||
|
|
29
|
-
process.env.FLATFILE_BEARER_TOKEN ||
|
|
30
|
-
'...'
|
|
31
|
-
this.environmentId = environmentId || process.env.FLATFILE_ENVIRONMENT_ID
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
start() {
|
|
35
|
-
this.handler.setVariables({
|
|
36
|
-
accessToken: this.accessToken,
|
|
37
|
-
apiUrl: this.apiUrl,
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
let lastTimestamp = new Date()
|
|
41
|
-
if (!this.environmentId) {
|
|
42
|
-
throw new Error('environmentId is required')
|
|
43
|
-
}
|
|
44
|
-
setInterval(() => {
|
|
45
|
-
this.handler.api
|
|
46
|
-
.getEvents({
|
|
47
|
-
since: lastTimestamp,
|
|
48
|
-
includeAcknowledged: false,
|
|
49
|
-
environmentId: this.environmentId,
|
|
50
|
-
})
|
|
51
|
-
.then((res) => {
|
|
52
|
-
process.stdout.cursorTo(0)
|
|
53
|
-
process.stdout.clearLine(1)
|
|
54
|
-
|
|
55
|
-
if (!res.data?.length) {
|
|
56
|
-
process.stdout.write(
|
|
57
|
-
`${c.white.bgMagentaBright(
|
|
58
|
-
'listening for events'
|
|
59
|
-
)} at ${lastTimestamp.toLocaleString()}`
|
|
60
|
-
)
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
res.data?.forEach((e) => {
|
|
64
|
-
if (!events.get(e.id)) {
|
|
65
|
-
process.stdout.write(
|
|
66
|
-
`${c.white.bgBlue(e.topic)} ${c.white.bgYellow(
|
|
67
|
-
e.id
|
|
68
|
-
)} ${e.createdAt?.toLocaleString()}\n`
|
|
69
|
-
)
|
|
70
|
-
events.set(e.id, true)
|
|
71
|
-
this.dispatchEvent(e)
|
|
72
|
-
}
|
|
73
|
-
})
|
|
74
|
-
})
|
|
75
|
-
.catch(console.error)
|
|
76
|
-
|
|
77
|
-
lastTimestamp = new Date()
|
|
78
|
-
}, 500)
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
shutdown() {}
|
|
82
|
-
}
|