@flatfile/listener 0.3.8 → 0.3.10
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 +7 -2
- package/dist/index.js +26 -11
- package/dist/index.mjs +26 -11
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -48,6 +48,7 @@ declare class FlatfileEvent extends AuthenticatedClient {
|
|
|
48
48
|
readonly context: any;
|
|
49
49
|
readonly payload: any;
|
|
50
50
|
readonly cache: EventCache;
|
|
51
|
+
readonly namespace: string[];
|
|
51
52
|
constructor(src: Event, accessToken?: string, apiUrl?: string);
|
|
52
53
|
/**
|
|
53
54
|
* Should return either event body if expanded already or fetch data from the
|
|
@@ -59,6 +60,10 @@ declare class FlatfileEvent extends AuthenticatedClient {
|
|
|
59
60
|
private afterAllCallbacks;
|
|
60
61
|
afterAll<T>(callback: () => T, cacheKey?: string): void;
|
|
61
62
|
update(records: RecordsWithLinks): Promise<void>;
|
|
63
|
+
secrets(key: string, options?: {
|
|
64
|
+
environmentId?: string;
|
|
65
|
+
spaceId?: string;
|
|
66
|
+
}): Promise<string>;
|
|
62
67
|
}
|
|
63
68
|
type EventCallback = (evt: FlatfileEvent) => void;
|
|
64
69
|
|
|
@@ -142,7 +147,7 @@ declare class EventHandler extends AuthenticatedClient {
|
|
|
142
147
|
*/
|
|
143
148
|
matchEvent(event: FlatfileEvent, filter: EventFilter | undefined): boolean;
|
|
144
149
|
}
|
|
145
|
-
type EventFilter = Record<string,
|
|
150
|
+
type EventFilter = Record<string, any>;
|
|
146
151
|
type Arrayable<T> = T | Array<T>;
|
|
147
152
|
type Listener = {
|
|
148
153
|
query: string | string[];
|
|
@@ -236,7 +241,7 @@ declare class FlatfileListener extends EventHandler {
|
|
|
236
241
|
* @param namespace
|
|
237
242
|
* @param cb
|
|
238
243
|
*/
|
|
239
|
-
namespace(
|
|
244
|
+
namespace(namespaces: string | string[], cb?: SubFn<this>): this;
|
|
240
245
|
/**
|
|
241
246
|
* Filter by namespace
|
|
242
247
|
*
|
package/dist/index.js
CHANGED
|
@@ -177,6 +177,7 @@ var AuthenticatedClient = class {
|
|
|
177
177
|
const resp = await axiosInstance(config);
|
|
178
178
|
return resp.data.data;
|
|
179
179
|
} catch (err) {
|
|
180
|
+
console.log("event.fetch error: ", err);
|
|
180
181
|
}
|
|
181
182
|
}
|
|
182
183
|
/**
|
|
@@ -251,6 +252,7 @@ var FlatfileEvent = class extends AuthenticatedClient {
|
|
|
251
252
|
this.target = src.target || "";
|
|
252
253
|
this.origin = src.origin || {};
|
|
253
254
|
this.action = src.context?.actionName || "";
|
|
255
|
+
this.namespace = src.namespaces || [];
|
|
254
256
|
}
|
|
255
257
|
/**
|
|
256
258
|
* Should return either event body if expanded already or fetch data from the
|
|
@@ -285,6 +287,24 @@ var FlatfileEvent = class extends AuthenticatedClient {
|
|
|
285
287
|
data: records
|
|
286
288
|
});
|
|
287
289
|
}
|
|
290
|
+
async secrets(key, options) {
|
|
291
|
+
const environmentId = options?.environmentId || this.context.environmentId;
|
|
292
|
+
const secrets = await this.cache.init("secrets", async () => {
|
|
293
|
+
const secretsResponse = await this.fetch(
|
|
294
|
+
`v1/secrets?environmentId=${environmentId}${options?.spaceId ? `&spaceId=${options.spaceId}` : ""}`
|
|
295
|
+
);
|
|
296
|
+
const SecretMap = /* @__PURE__ */ new Map();
|
|
297
|
+
secretsResponse.forEach((secret) => {
|
|
298
|
+
SecretMap.set(secret.name, secret.value);
|
|
299
|
+
});
|
|
300
|
+
return SecretMap;
|
|
301
|
+
});
|
|
302
|
+
const value = secrets.get(key);
|
|
303
|
+
if (!value) {
|
|
304
|
+
throw new Error(`Secret ${key} not found`);
|
|
305
|
+
}
|
|
306
|
+
return value;
|
|
307
|
+
}
|
|
288
308
|
};
|
|
289
309
|
|
|
290
310
|
// ../../node_modules/wildcard-match/build/index.es.mjs
|
|
@@ -497,15 +517,10 @@ var EventHandler = class extends AuthenticatedClient {
|
|
|
497
517
|
* @param event
|
|
498
518
|
*/
|
|
499
519
|
async dispatchEvent(event) {
|
|
500
|
-
if (!
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
apiUrl: this._apiUrl,
|
|
505
|
-
accessToken: this._accessToken
|
|
506
|
-
});
|
|
507
|
-
}
|
|
508
|
-
}
|
|
520
|
+
if (!event)
|
|
521
|
+
return;
|
|
522
|
+
const eventPayload = event.src ? event.src : event;
|
|
523
|
+
event = new FlatfileEvent(eventPayload, this._accessToken, this._apiUrl);
|
|
509
524
|
await this.trigger(event, true);
|
|
510
525
|
for (const [_key, cb] of event.afterAllCallbacks) {
|
|
511
526
|
await cb(event);
|
|
@@ -584,8 +599,8 @@ var FlatfileListener = class extends EventHandler {
|
|
|
584
599
|
* @param namespace
|
|
585
600
|
* @param cb
|
|
586
601
|
*/
|
|
587
|
-
namespace(
|
|
588
|
-
return this.filter({
|
|
602
|
+
namespace(namespaces, cb) {
|
|
603
|
+
return this.filter({ namespaces }, cb);
|
|
589
604
|
}
|
|
590
605
|
/**
|
|
591
606
|
* Filter by namespace
|
package/dist/index.mjs
CHANGED
|
@@ -134,6 +134,7 @@ var AuthenticatedClient = class {
|
|
|
134
134
|
const resp = await axiosInstance(config);
|
|
135
135
|
return resp.data.data;
|
|
136
136
|
} catch (err) {
|
|
137
|
+
console.log("event.fetch error: ", err);
|
|
137
138
|
}
|
|
138
139
|
}
|
|
139
140
|
/**
|
|
@@ -208,6 +209,7 @@ var FlatfileEvent = class extends AuthenticatedClient {
|
|
|
208
209
|
this.target = src.target || "";
|
|
209
210
|
this.origin = src.origin || {};
|
|
210
211
|
this.action = src.context?.actionName || "";
|
|
212
|
+
this.namespace = src.namespaces || [];
|
|
211
213
|
}
|
|
212
214
|
/**
|
|
213
215
|
* Should return either event body if expanded already or fetch data from the
|
|
@@ -242,6 +244,24 @@ var FlatfileEvent = class extends AuthenticatedClient {
|
|
|
242
244
|
data: records
|
|
243
245
|
});
|
|
244
246
|
}
|
|
247
|
+
async secrets(key, options) {
|
|
248
|
+
const environmentId = options?.environmentId || this.context.environmentId;
|
|
249
|
+
const secrets = await this.cache.init("secrets", async () => {
|
|
250
|
+
const secretsResponse = await this.fetch(
|
|
251
|
+
`v1/secrets?environmentId=${environmentId}${options?.spaceId ? `&spaceId=${options.spaceId}` : ""}`
|
|
252
|
+
);
|
|
253
|
+
const SecretMap = /* @__PURE__ */ new Map();
|
|
254
|
+
secretsResponse.forEach((secret) => {
|
|
255
|
+
SecretMap.set(secret.name, secret.value);
|
|
256
|
+
});
|
|
257
|
+
return SecretMap;
|
|
258
|
+
});
|
|
259
|
+
const value = secrets.get(key);
|
|
260
|
+
if (!value) {
|
|
261
|
+
throw new Error(`Secret ${key} not found`);
|
|
262
|
+
}
|
|
263
|
+
return value;
|
|
264
|
+
}
|
|
245
265
|
};
|
|
246
266
|
|
|
247
267
|
// ../../node_modules/wildcard-match/build/index.es.mjs
|
|
@@ -454,15 +474,10 @@ var EventHandler = class extends AuthenticatedClient {
|
|
|
454
474
|
* @param event
|
|
455
475
|
*/
|
|
456
476
|
async dispatchEvent(event) {
|
|
457
|
-
if (!
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
apiUrl: this._apiUrl,
|
|
462
|
-
accessToken: this._accessToken
|
|
463
|
-
});
|
|
464
|
-
}
|
|
465
|
-
}
|
|
477
|
+
if (!event)
|
|
478
|
+
return;
|
|
479
|
+
const eventPayload = event.src ? event.src : event;
|
|
480
|
+
event = new FlatfileEvent(eventPayload, this._accessToken, this._apiUrl);
|
|
466
481
|
await this.trigger(event, true);
|
|
467
482
|
for (const [_key, cb] of event.afterAllCallbacks) {
|
|
468
483
|
await cb(event);
|
|
@@ -541,8 +556,8 @@ var FlatfileListener = class extends EventHandler {
|
|
|
541
556
|
* @param namespace
|
|
542
557
|
* @param cb
|
|
543
558
|
*/
|
|
544
|
-
namespace(
|
|
545
|
-
return this.filter({
|
|
559
|
+
namespace(namespaces, cb) {
|
|
560
|
+
return this.filter({ namespaces }, cb);
|
|
546
561
|
}
|
|
547
562
|
/**
|
|
548
563
|
* Filter by namespace
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flatfile/listener",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.10",
|
|
4
4
|
"description": "A PubSub Listener for configuring and using Flatfile",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"flat": "^5.0.2"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
|
-
"@flatfile/api": "^1.
|
|
38
|
+
"@flatfile/api": "^1.5.10",
|
|
39
39
|
"axios": "^1.4.0"
|
|
40
40
|
}
|
|
41
41
|
}
|