@flatfile/listener 0.2.0 → 0.3.1
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 +6 -6
- package/CHANGELOG.md +12 -0
- package/dist/index.js +89 -6
- package/dist/index.mjs +89 -6
- package/package.json +3 -2
- package/src/events/authenticated.client.ts +9 -6
- package/src/events/cache.ts +0 -3
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @flatfile/listener@0.
|
|
2
|
+
> @flatfile/listener@0.3.1 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
|
-
[
|
|
12
|
-
[
|
|
13
|
-
[
|
|
14
|
-
[
|
|
11
|
+
[32mCJS[39m [1mdist/index.js [22m[32m17.81 KB[39m
|
|
12
|
+
[32mCJS[39m ⚡️ Build success in 142ms
|
|
13
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m15.87 KB[39m
|
|
14
|
+
[32mESM[39m ⚡️ Build success in 144ms
|
|
15
15
|
[34mDTS[39m Build start
|
|
16
|
-
[32mDTS[39m ⚡️ Build success in
|
|
16
|
+
[32mDTS[39m ⚡️ Build success in 2435ms
|
|
17
17
|
[32mDTS[39m [1mdist/index.d.ts [22m[32m7.14 KB[39m
|
package/CHANGELOG.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -41,12 +41,99 @@ __export(src_exports, {
|
|
|
41
41
|
});
|
|
42
42
|
module.exports = __toCommonJS(src_exports);
|
|
43
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
|
+
|
|
44
130
|
// src/events/authenticated.client.ts
|
|
45
131
|
var import_axios = __toESM(require("axios"));
|
|
46
132
|
var AuthenticatedClient = class {
|
|
47
133
|
constructor(accessToken, apiUrl) {
|
|
48
|
-
const FLATFILE_API_URL =
|
|
49
|
-
|
|
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 || "...";
|
|
50
137
|
this._apiUrl = apiUrl || FLATFILE_API_URL;
|
|
51
138
|
}
|
|
52
139
|
fetch(url) {
|
|
@@ -55,7 +142,6 @@ var AuthenticatedClient = class {
|
|
|
55
142
|
"x-disable-hooks": "true"
|
|
56
143
|
};
|
|
57
144
|
const fetchUrl = this._apiUrl + "/" + url;
|
|
58
|
-
console.log({ fetchUrl });
|
|
59
145
|
return import_axios.default.get(fetchUrl, { headers }).then((resp) => resp.data.data).catch((err) => {
|
|
60
146
|
});
|
|
61
147
|
}
|
|
@@ -79,10 +165,8 @@ var EventCache = class {
|
|
|
79
165
|
}
|
|
80
166
|
async init(key, callback) {
|
|
81
167
|
if (this.eventCache.get(key)) {
|
|
82
|
-
console.log(`Cache hit for ${key}`);
|
|
83
168
|
return this.eventCache.get(key);
|
|
84
169
|
} else {
|
|
85
|
-
console.log(`no cache hit for ${key}`);
|
|
86
170
|
const result = await callback();
|
|
87
171
|
this.eventCache.set(key, result);
|
|
88
172
|
return result;
|
|
@@ -90,7 +174,6 @@ var EventCache = class {
|
|
|
90
174
|
}
|
|
91
175
|
async set(key, callback) {
|
|
92
176
|
if (this.eventCache.get(key)) {
|
|
93
|
-
console.log(`cache set for ${key}`);
|
|
94
177
|
const result = await callback();
|
|
95
178
|
this.eventCache.set(key, result);
|
|
96
179
|
return result;
|
package/dist/index.mjs
CHANGED
|
@@ -1,9 +1,96 @@
|
|
|
1
|
+
// ../cross-env-config/dist/index.mjs
|
|
2
|
+
var CrossEnvConfig = class {
|
|
3
|
+
/**
|
|
4
|
+
* Get a config value from either the environment or any registry overrides
|
|
5
|
+
* @param prop
|
|
6
|
+
*/
|
|
7
|
+
static get(prop) {
|
|
8
|
+
return this.safeEnvLookup(prop);
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Set a value explicitly
|
|
12
|
+
*
|
|
13
|
+
* @param key
|
|
14
|
+
* @param value
|
|
15
|
+
*/
|
|
16
|
+
static set(key, value) {
|
|
17
|
+
return this._overrides.set(key, value);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Alias a key to another key if helpful. This is useful if you have different naming
|
|
21
|
+
* constructs for different environments.
|
|
22
|
+
*
|
|
23
|
+
* @param from
|
|
24
|
+
* @param to
|
|
25
|
+
*/
|
|
26
|
+
static alias(from, to) {
|
|
27
|
+
return this._aliases.set(from, to);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Helpful if you've decided to store settings in another object and want to
|
|
31
|
+
* make that available here. For example in client-side implementations you may reserve
|
|
32
|
+
* a window.FLATFILE_CONFIG object to store settings.
|
|
33
|
+
*
|
|
34
|
+
* @param obj
|
|
35
|
+
*/
|
|
36
|
+
static attachConfigRegistry(obj) {
|
|
37
|
+
this._registry = obj;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Use this to provide an override getter for config values. This is useful
|
|
41
|
+
* if you need to dynamically look up values. Overrides will still take precedence.
|
|
42
|
+
*
|
|
43
|
+
* @param cb
|
|
44
|
+
*/
|
|
45
|
+
static attachConfigFactory(cb) {
|
|
46
|
+
this._factory = cb;
|
|
47
|
+
}
|
|
48
|
+
static reset() {
|
|
49
|
+
this._overrides = /* @__PURE__ */ new Map();
|
|
50
|
+
this._registry = void 0;
|
|
51
|
+
this._factory = void 0;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Internal function for traversing the possible environment sources for a value
|
|
55
|
+
*
|
|
56
|
+
* @param prop
|
|
57
|
+
* @private
|
|
58
|
+
*/
|
|
59
|
+
static safeEnvLookup(prop) {
|
|
60
|
+
let values = [];
|
|
61
|
+
if (this._overrides.get(prop)) {
|
|
62
|
+
values.push(this._overrides.get(prop));
|
|
63
|
+
}
|
|
64
|
+
if (typeof this._registry === "object") {
|
|
65
|
+
values.push(this._registry[prop]);
|
|
66
|
+
}
|
|
67
|
+
if (typeof this._factory === "function") {
|
|
68
|
+
values.push(this._factory(prop));
|
|
69
|
+
}
|
|
70
|
+
if (typeof process === "object" && typeof process.env === "object") {
|
|
71
|
+
values.push(process.env[prop]);
|
|
72
|
+
}
|
|
73
|
+
const foundValue = values.find((v) => v !== void 0);
|
|
74
|
+
if (foundValue !== void 0) {
|
|
75
|
+
return foundValue;
|
|
76
|
+
}
|
|
77
|
+
const alias = this._aliases.get(prop);
|
|
78
|
+
if (alias) {
|
|
79
|
+
return this.safeEnvLookup(alias);
|
|
80
|
+
}
|
|
81
|
+
return void 0;
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
CrossEnvConfig._overrides = /* @__PURE__ */ new Map();
|
|
85
|
+
CrossEnvConfig._aliases = /* @__PURE__ */ new Map();
|
|
86
|
+
|
|
1
87
|
// src/events/authenticated.client.ts
|
|
2
88
|
import axios from "axios";
|
|
3
89
|
var AuthenticatedClient = class {
|
|
4
90
|
constructor(accessToken, apiUrl) {
|
|
5
|
-
const FLATFILE_API_URL =
|
|
6
|
-
|
|
91
|
+
const FLATFILE_API_URL = CrossEnvConfig.get("AGENT_INTERNAL_URL") || "http://localhost:3000";
|
|
92
|
+
const bearerToken = CrossEnvConfig.get("FLATFILE_BEARER_TOKEN");
|
|
93
|
+
this._accessToken = accessToken || bearerToken || "...";
|
|
7
94
|
this._apiUrl = apiUrl || FLATFILE_API_URL;
|
|
8
95
|
}
|
|
9
96
|
fetch(url) {
|
|
@@ -12,7 +99,6 @@ var AuthenticatedClient = class {
|
|
|
12
99
|
"x-disable-hooks": "true"
|
|
13
100
|
};
|
|
14
101
|
const fetchUrl = this._apiUrl + "/" + url;
|
|
15
|
-
console.log({ fetchUrl });
|
|
16
102
|
return axios.get(fetchUrl, { headers }).then((resp) => resp.data.data).catch((err) => {
|
|
17
103
|
});
|
|
18
104
|
}
|
|
@@ -36,10 +122,8 @@ var EventCache = class {
|
|
|
36
122
|
}
|
|
37
123
|
async init(key, callback) {
|
|
38
124
|
if (this.eventCache.get(key)) {
|
|
39
|
-
console.log(`Cache hit for ${key}`);
|
|
40
125
|
return this.eventCache.get(key);
|
|
41
126
|
} else {
|
|
42
|
-
console.log(`no cache hit for ${key}`);
|
|
43
127
|
const result = await callback();
|
|
44
128
|
this.eventCache.set(key, result);
|
|
45
129
|
return result;
|
|
@@ -47,7 +131,6 @@ var EventCache = class {
|
|
|
47
131
|
}
|
|
48
132
|
async set(key, callback) {
|
|
49
133
|
if (this.eventCache.get(key)) {
|
|
50
|
-
console.log(`cache set for ${key}`);
|
|
51
134
|
const result = await callback();
|
|
52
135
|
this.eventCache.set(key, result);
|
|
53
136
|
return result;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flatfile/listener",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "A PubSub Listener for configuring and using Flatfile",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
"@flatfile/eslint-config-platform-sdk": "*",
|
|
18
18
|
"@flatfile/jest-preset-platform-sdk": "*",
|
|
19
19
|
"@flatfile/ts-config-platform-sdk": "*",
|
|
20
|
+
"@flatfile/cross-env-config": "*",
|
|
20
21
|
"@types/flat": "^5.0.2",
|
|
21
22
|
"@types/jest": "^29.5.1",
|
|
22
23
|
"eslint": "^8.19.0",
|
|
@@ -31,7 +32,7 @@
|
|
|
31
32
|
"flat": "^5.0.2"
|
|
32
33
|
},
|
|
33
34
|
"peerDependencies": {
|
|
34
|
-
"@flatfile/api": "^1.4.
|
|
35
|
+
"@flatfile/api": "^1.4.9",
|
|
35
36
|
"axios": "^1.4.0"
|
|
36
37
|
}
|
|
37
38
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { CrossEnvConfig } from '@flatfile/cross-env-config'
|
|
1
2
|
import axios from 'axios'
|
|
2
3
|
|
|
3
4
|
export class AuthenticatedClient {
|
|
@@ -6,10 +7,10 @@ export class AuthenticatedClient {
|
|
|
6
7
|
|
|
7
8
|
constructor(accessToken?: string, apiUrl?: string) {
|
|
8
9
|
const FLATFILE_API_URL =
|
|
9
|
-
|
|
10
|
+
CrossEnvConfig.get('AGENT_INTERNAL_URL') || 'http://localhost:3000'
|
|
11
|
+
const bearerToken = CrossEnvConfig.get('FLATFILE_BEARER_TOKEN')
|
|
10
12
|
|
|
11
|
-
this._accessToken =
|
|
12
|
-
accessToken || process.env.FLATFILE_BEARER_TOKEN || '...'
|
|
13
|
+
this._accessToken = accessToken || bearerToken || '...'
|
|
13
14
|
|
|
14
15
|
this._apiUrl = apiUrl || FLATFILE_API_URL
|
|
15
16
|
}
|
|
@@ -20,10 +21,12 @@ export class AuthenticatedClient {
|
|
|
20
21
|
'x-disable-hooks': 'true',
|
|
21
22
|
}
|
|
22
23
|
const fetchUrl = this._apiUrl + '/' + url
|
|
23
|
-
console.log({ fetchUrl })
|
|
24
|
-
return axios.get(fetchUrl, { headers }).then((resp: any) => resp.data.data).catch((err: any) => {})
|
|
25
|
-
}
|
|
26
24
|
|
|
25
|
+
return axios
|
|
26
|
+
.get(fetchUrl, { headers })
|
|
27
|
+
.then((resp: any) => resp.data.data)
|
|
28
|
+
.catch((err: any) => {})
|
|
29
|
+
}
|
|
27
30
|
/**
|
|
28
31
|
*
|
|
29
32
|
* @deprecated use @flatfile/cross-env-config instead
|
package/src/events/cache.ts
CHANGED
|
@@ -3,10 +3,8 @@ export class EventCache {
|
|
|
3
3
|
|
|
4
4
|
async init<T>(key: string, callback: () => Promise<T>): Promise<T> {
|
|
5
5
|
if (this.eventCache.get(key)) {
|
|
6
|
-
console.log(`Cache hit for ${key}`)
|
|
7
6
|
return this.eventCache.get(key)
|
|
8
7
|
} else {
|
|
9
|
-
console.log(`no cache hit for ${key}`)
|
|
10
8
|
const result = await callback()
|
|
11
9
|
this.eventCache.set(key, result)
|
|
12
10
|
return result
|
|
@@ -15,7 +13,6 @@ export class EventCache {
|
|
|
15
13
|
|
|
16
14
|
async set<T>(key: string, callback: () => Promise<T>): Promise<T> {
|
|
17
15
|
if (this.eventCache.get(key)) {
|
|
18
|
-
console.log(`cache set for ${key}`)
|
|
19
16
|
const result = await callback()
|
|
20
17
|
this.eventCache.set(key, result)
|
|
21
18
|
return result
|