@flatfile/listener 0.3.4 → 0.3.6
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 +41 -38
- package/dist/index.js +28 -3
- package/dist/index.mjs +28 -3
- package/package.json +1 -1
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
|
-
|
|
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
|
-
|
|
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):
|
|
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):
|
|
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):
|
|
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:
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
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
|
@@ -113,6 +113,7 @@ var CrossEnvConfig = class {
|
|
|
113
113
|
if (typeof process === "object" && typeof process.env === "object") {
|
|
114
114
|
values.push(process.env[prop]);
|
|
115
115
|
}
|
|
116
|
+
values.push(...this.checkForBrowserVariables(prop));
|
|
116
117
|
const foundValue = values.find((v) => v !== void 0);
|
|
117
118
|
if (foundValue !== void 0) {
|
|
118
119
|
return foundValue;
|
|
@@ -123,6 +124,28 @@ var CrossEnvConfig = class {
|
|
|
123
124
|
}
|
|
124
125
|
return void 0;
|
|
125
126
|
}
|
|
127
|
+
/**
|
|
128
|
+
* Internal function for checking for stored variables in a browser-like environment
|
|
129
|
+
*
|
|
130
|
+
* @param prop
|
|
131
|
+
* @private
|
|
132
|
+
*/
|
|
133
|
+
static checkForBrowserVariables(prop) {
|
|
134
|
+
let values = [];
|
|
135
|
+
if (typeof window === "object") {
|
|
136
|
+
const windowValue = window[`CROSSENV_${prop}`];
|
|
137
|
+
if (windowValue !== void 0) {
|
|
138
|
+
values.push(windowValue);
|
|
139
|
+
}
|
|
140
|
+
if (typeof sessionStorage === "object") {
|
|
141
|
+
const storedValue = sessionStorage.getItem(`CROSSENV_${prop}`);
|
|
142
|
+
if (storedValue !== null) {
|
|
143
|
+
values.push(storedValue);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return values;
|
|
148
|
+
}
|
|
126
149
|
};
|
|
127
150
|
CrossEnvConfig._overrides = /* @__PURE__ */ new Map();
|
|
128
151
|
CrossEnvConfig._aliases = /* @__PURE__ */ new Map();
|
|
@@ -484,7 +507,9 @@ var EventHandler = class extends AuthenticatedClient {
|
|
|
484
507
|
}
|
|
485
508
|
}
|
|
486
509
|
await this.trigger(event, true);
|
|
487
|
-
|
|
510
|
+
for (const [_key, cb] of event.afterAllCallbacks) {
|
|
511
|
+
await cb(event);
|
|
512
|
+
}
|
|
488
513
|
event.cache.delete();
|
|
489
514
|
}
|
|
490
515
|
/**
|
|
@@ -569,7 +594,7 @@ var FlatfileListener = class extends EventHandler {
|
|
|
569
594
|
* @param cb
|
|
570
595
|
*/
|
|
571
596
|
filter(filter, cb) {
|
|
572
|
-
const client = new
|
|
597
|
+
const client = new this.constructor(filter);
|
|
573
598
|
this.addNode(client);
|
|
574
599
|
cb?.(client);
|
|
575
600
|
return client;
|
|
@@ -580,7 +605,7 @@ var FlatfileListener = class extends EventHandler {
|
|
|
580
605
|
* @param cb
|
|
581
606
|
*/
|
|
582
607
|
static create(cb) {
|
|
583
|
-
const client = new
|
|
608
|
+
const client = new this();
|
|
584
609
|
cb(client);
|
|
585
610
|
return client;
|
|
586
611
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -70,6 +70,7 @@ var CrossEnvConfig = class {
|
|
|
70
70
|
if (typeof process === "object" && typeof process.env === "object") {
|
|
71
71
|
values.push(process.env[prop]);
|
|
72
72
|
}
|
|
73
|
+
values.push(...this.checkForBrowserVariables(prop));
|
|
73
74
|
const foundValue = values.find((v) => v !== void 0);
|
|
74
75
|
if (foundValue !== void 0) {
|
|
75
76
|
return foundValue;
|
|
@@ -80,6 +81,28 @@ var CrossEnvConfig = class {
|
|
|
80
81
|
}
|
|
81
82
|
return void 0;
|
|
82
83
|
}
|
|
84
|
+
/**
|
|
85
|
+
* Internal function for checking for stored variables in a browser-like environment
|
|
86
|
+
*
|
|
87
|
+
* @param prop
|
|
88
|
+
* @private
|
|
89
|
+
*/
|
|
90
|
+
static checkForBrowserVariables(prop) {
|
|
91
|
+
let values = [];
|
|
92
|
+
if (typeof window === "object") {
|
|
93
|
+
const windowValue = window[`CROSSENV_${prop}`];
|
|
94
|
+
if (windowValue !== void 0) {
|
|
95
|
+
values.push(windowValue);
|
|
96
|
+
}
|
|
97
|
+
if (typeof sessionStorage === "object") {
|
|
98
|
+
const storedValue = sessionStorage.getItem(`CROSSENV_${prop}`);
|
|
99
|
+
if (storedValue !== null) {
|
|
100
|
+
values.push(storedValue);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return values;
|
|
105
|
+
}
|
|
83
106
|
};
|
|
84
107
|
CrossEnvConfig._overrides = /* @__PURE__ */ new Map();
|
|
85
108
|
CrossEnvConfig._aliases = /* @__PURE__ */ new Map();
|
|
@@ -441,7 +464,9 @@ var EventHandler = class extends AuthenticatedClient {
|
|
|
441
464
|
}
|
|
442
465
|
}
|
|
443
466
|
await this.trigger(event, true);
|
|
444
|
-
|
|
467
|
+
for (const [_key, cb] of event.afterAllCallbacks) {
|
|
468
|
+
await cb(event);
|
|
469
|
+
}
|
|
445
470
|
event.cache.delete();
|
|
446
471
|
}
|
|
447
472
|
/**
|
|
@@ -526,7 +551,7 @@ var FlatfileListener = class extends EventHandler {
|
|
|
526
551
|
* @param cb
|
|
527
552
|
*/
|
|
528
553
|
filter(filter, cb) {
|
|
529
|
-
const client = new
|
|
554
|
+
const client = new this.constructor(filter);
|
|
530
555
|
this.addNode(client);
|
|
531
556
|
cb?.(client);
|
|
532
557
|
return client;
|
|
@@ -537,7 +562,7 @@ var FlatfileListener = class extends EventHandler {
|
|
|
537
562
|
* @param cb
|
|
538
563
|
*/
|
|
539
564
|
static create(cb) {
|
|
540
|
-
const client = new
|
|
565
|
+
const client = new this();
|
|
541
566
|
cb(client);
|
|
542
567
|
return client;
|
|
543
568
|
}
|