@flatfile/listener 0.2.0 → 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.2.0 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
- ESM dist/index.mjs 13.73 KB
12
- ESM ⚡️ Build success in 295ms
13
- CJS dist/index.js 15.67 KB
14
- CJS ⚡️ Build success in 293ms
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 9323ms
16
+ DTS ⚡️ Build success in 1679ms
17
17
  DTS dist/index.d.ts 7.14 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
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
+
3
9
  ## 0.2.0
4
10
 
5
11
  ### Minor Changes
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 = process.env.AGENT_INTERNAL_URL || "http://localhost:3000";
49
- 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 || "...";
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
  }
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 = process.env.AGENT_INTERNAL_URL || "http://localhost:3000";
6
- this._accessToken = accessToken || process.env.FLATFILE_BEARER_TOKEN || "...";
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flatfile/listener",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
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",
@@ -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
- process.env.AGENT_INTERNAL_URL || 'http://localhost:3000'
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