@flatfile/listener 0.3.14 → 0.3.15
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 +2 -1
- package/dist/index.js +20 -5
- package/dist/index.mjs +20 -5
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -32,7 +32,7 @@ interface GetData extends Function {
|
|
|
32
32
|
then<TResult1 = any, TResult2 = any>(onfulfilled?: ((value: any) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
|
|
33
33
|
}
|
|
34
34
|
declare class FlatfileEvent extends AuthenticatedClient {
|
|
35
|
-
|
|
35
|
+
readonly src: Event;
|
|
36
36
|
/**
|
|
37
37
|
* Event ID from the API
|
|
38
38
|
*
|
|
@@ -56,6 +56,7 @@ declare class FlatfileEvent extends AuthenticatedClient {
|
|
|
56
56
|
readonly payload: any;
|
|
57
57
|
readonly cache: EventCache;
|
|
58
58
|
readonly namespace: string[];
|
|
59
|
+
readonly createdAt?: Date;
|
|
59
60
|
/**
|
|
60
61
|
* Fetch record data from Flatfile API via the event's dataUrl
|
|
61
62
|
*
|
package/dist/index.js
CHANGED
|
@@ -152,12 +152,22 @@ CrossEnvConfig._aliases = /* @__PURE__ */ new Map();
|
|
|
152
152
|
|
|
153
153
|
// src/events/authenticated.client.ts
|
|
154
154
|
var import_axios = __toESM(require("axios"));
|
|
155
|
+
|
|
156
|
+
// src/utils/helpers.ts
|
|
157
|
+
var ensureSingleTrailingSlash = (url) => {
|
|
158
|
+
while (url.endsWith("/")) {
|
|
159
|
+
url = url.slice(0, -1);
|
|
160
|
+
}
|
|
161
|
+
return url + "/";
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
// src/events/authenticated.client.ts
|
|
155
165
|
var AuthenticatedClient = class {
|
|
156
166
|
constructor(accessToken, apiUrl) {
|
|
157
167
|
const FLATFILE_API_URL = CrossEnvConfig.get("AGENT_INTERNAL_URL") || "http://localhost:3000";
|
|
158
168
|
const bearerToken = CrossEnvConfig.get("FLATFILE_BEARER_TOKEN");
|
|
159
169
|
this._accessToken = accessToken || bearerToken || "...";
|
|
160
|
-
this._apiUrl = apiUrl || FLATFILE_API_URL;
|
|
170
|
+
this._apiUrl = apiUrl || FLATFILE_API_URL ? ensureSingleTrailingSlash(apiUrl || FLATFILE_API_URL) : void 0;
|
|
161
171
|
}
|
|
162
172
|
async fetch(url, options) {
|
|
163
173
|
const headers = {
|
|
@@ -165,9 +175,12 @@ var AuthenticatedClient = class {
|
|
|
165
175
|
"x-disable-hooks": "true"
|
|
166
176
|
};
|
|
167
177
|
const axiosInstance = import_axios.default.create({
|
|
168
|
-
headers
|
|
178
|
+
headers,
|
|
179
|
+
validateStatus: (status) => {
|
|
180
|
+
return status >= 200 && status <= 399;
|
|
181
|
+
}
|
|
169
182
|
});
|
|
170
|
-
const fetchUrl = this._apiUrl +
|
|
183
|
+
const fetchUrl = this._apiUrl + url;
|
|
171
184
|
const config = {
|
|
172
185
|
url: fetchUrl,
|
|
173
186
|
method: "GET",
|
|
@@ -253,6 +266,7 @@ var FlatfileEvent = class extends AuthenticatedClient {
|
|
|
253
266
|
this.origin = src.origin || {};
|
|
254
267
|
this.action = src.context?.actionName || "";
|
|
255
268
|
this.namespace = src.namespaces || [];
|
|
269
|
+
this.createdAt = src.createdAt || void 0;
|
|
256
270
|
const data = async (options) => this.fetchData(options);
|
|
257
271
|
data.then = (onfulfilled, onrejected) => {
|
|
258
272
|
return this.data().then(onfulfilled, onrejected);
|
|
@@ -321,10 +335,11 @@ var FlatfileEvent = class extends AuthenticatedClient {
|
|
|
321
335
|
if (spaceId) {
|
|
322
336
|
getSecrets += `&spaceId=${spaceId}`;
|
|
323
337
|
}
|
|
324
|
-
const
|
|
338
|
+
const secretCacheKey = `secrets:${environmentId}${spaceId && `:${spaceId}`}`;
|
|
339
|
+
const secrets = await this.cache.init(secretCacheKey, async () => {
|
|
325
340
|
const secretsResponse = await this.fetch(getSecrets);
|
|
326
341
|
const SecretMap = /* @__PURE__ */ new Map();
|
|
327
|
-
secretsResponse
|
|
342
|
+
secretsResponse?.forEach((secret) => {
|
|
328
343
|
SecretMap.set(secret.name, secret.value);
|
|
329
344
|
});
|
|
330
345
|
return SecretMap;
|
package/dist/index.mjs
CHANGED
|
@@ -109,12 +109,22 @@ CrossEnvConfig._aliases = /* @__PURE__ */ new Map();
|
|
|
109
109
|
|
|
110
110
|
// src/events/authenticated.client.ts
|
|
111
111
|
import axios from "axios";
|
|
112
|
+
|
|
113
|
+
// src/utils/helpers.ts
|
|
114
|
+
var ensureSingleTrailingSlash = (url) => {
|
|
115
|
+
while (url.endsWith("/")) {
|
|
116
|
+
url = url.slice(0, -1);
|
|
117
|
+
}
|
|
118
|
+
return url + "/";
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
// src/events/authenticated.client.ts
|
|
112
122
|
var AuthenticatedClient = class {
|
|
113
123
|
constructor(accessToken, apiUrl) {
|
|
114
124
|
const FLATFILE_API_URL = CrossEnvConfig.get("AGENT_INTERNAL_URL") || "http://localhost:3000";
|
|
115
125
|
const bearerToken = CrossEnvConfig.get("FLATFILE_BEARER_TOKEN");
|
|
116
126
|
this._accessToken = accessToken || bearerToken || "...";
|
|
117
|
-
this._apiUrl = apiUrl || FLATFILE_API_URL;
|
|
127
|
+
this._apiUrl = apiUrl || FLATFILE_API_URL ? ensureSingleTrailingSlash(apiUrl || FLATFILE_API_URL) : void 0;
|
|
118
128
|
}
|
|
119
129
|
async fetch(url, options) {
|
|
120
130
|
const headers = {
|
|
@@ -122,9 +132,12 @@ var AuthenticatedClient = class {
|
|
|
122
132
|
"x-disable-hooks": "true"
|
|
123
133
|
};
|
|
124
134
|
const axiosInstance = axios.create({
|
|
125
|
-
headers
|
|
135
|
+
headers,
|
|
136
|
+
validateStatus: (status) => {
|
|
137
|
+
return status >= 200 && status <= 399;
|
|
138
|
+
}
|
|
126
139
|
});
|
|
127
|
-
const fetchUrl = this._apiUrl +
|
|
140
|
+
const fetchUrl = this._apiUrl + url;
|
|
128
141
|
const config = {
|
|
129
142
|
url: fetchUrl,
|
|
130
143
|
method: "GET",
|
|
@@ -210,6 +223,7 @@ var FlatfileEvent = class extends AuthenticatedClient {
|
|
|
210
223
|
this.origin = src.origin || {};
|
|
211
224
|
this.action = src.context?.actionName || "";
|
|
212
225
|
this.namespace = src.namespaces || [];
|
|
226
|
+
this.createdAt = src.createdAt || void 0;
|
|
213
227
|
const data = async (options) => this.fetchData(options);
|
|
214
228
|
data.then = (onfulfilled, onrejected) => {
|
|
215
229
|
return this.data().then(onfulfilled, onrejected);
|
|
@@ -278,10 +292,11 @@ var FlatfileEvent = class extends AuthenticatedClient {
|
|
|
278
292
|
if (spaceId) {
|
|
279
293
|
getSecrets += `&spaceId=${spaceId}`;
|
|
280
294
|
}
|
|
281
|
-
const
|
|
295
|
+
const secretCacheKey = `secrets:${environmentId}${spaceId && `:${spaceId}`}`;
|
|
296
|
+
const secrets = await this.cache.init(secretCacheKey, async () => {
|
|
282
297
|
const secretsResponse = await this.fetch(getSecrets);
|
|
283
298
|
const SecretMap = /* @__PURE__ */ new Map();
|
|
284
|
-
secretsResponse
|
|
299
|
+
secretsResponse?.forEach((secret) => {
|
|
285
300
|
SecretMap.set(secret.name, secret.value);
|
|
286
301
|
});
|
|
287
302
|
return SecretMap;
|