@flatfile/listener 0.3.3 → 0.3.4
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 +5 -2
- package/dist/index.js +29 -3
- package/dist/index.mjs +29 -3
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { Event, RecordsWithLinks } from '@flatfile/api/api';
|
|
1
2
|
import { Flatfile } from '@flatfile/api';
|
|
2
3
|
|
|
3
4
|
declare class AuthenticatedClient {
|
|
4
5
|
_accessToken?: string;
|
|
5
6
|
_apiUrl?: string;
|
|
6
7
|
constructor(accessToken?: string, apiUrl?: string);
|
|
7
|
-
fetch(url: string): Promise<any>;
|
|
8
|
+
fetch(url: string, options?: any): Promise<any>;
|
|
8
9
|
/**
|
|
9
10
|
*
|
|
10
11
|
* @deprecated use @flatfile/cross-env-config instead
|
|
@@ -42,11 +43,12 @@ declare class FlatfileEvent extends AuthenticatedClient {
|
|
|
42
43
|
readonly topic: string;
|
|
43
44
|
readonly domain: string;
|
|
44
45
|
readonly target: string;
|
|
46
|
+
readonly origin: object;
|
|
45
47
|
readonly action: string;
|
|
46
48
|
readonly context: any;
|
|
47
49
|
readonly payload: any;
|
|
48
50
|
readonly cache: EventCache;
|
|
49
|
-
constructor(src:
|
|
51
|
+
constructor(src: Event, accessToken?: string, apiUrl?: string);
|
|
50
52
|
/**
|
|
51
53
|
* Should return either event body if expanded already or fetch data from the
|
|
52
54
|
* signed callback URL
|
|
@@ -56,6 +58,7 @@ declare class FlatfileEvent extends AuthenticatedClient {
|
|
|
56
58
|
get data(): Promise<any>;
|
|
57
59
|
private afterAllCallbacks;
|
|
58
60
|
afterAll<T>(callback: () => T, cacheKey?: string): void;
|
|
61
|
+
update(records: RecordsWithLinks): Promise<void>;
|
|
59
62
|
}
|
|
60
63
|
type EventCallback = (evt: FlatfileEvent) => void;
|
|
61
64
|
|
package/dist/index.js
CHANGED
|
@@ -136,14 +136,25 @@ var AuthenticatedClient = class {
|
|
|
136
136
|
this._accessToken = accessToken || bearerToken || "...";
|
|
137
137
|
this._apiUrl = apiUrl || FLATFILE_API_URL;
|
|
138
138
|
}
|
|
139
|
-
fetch(url) {
|
|
139
|
+
async fetch(url, options) {
|
|
140
140
|
const headers = {
|
|
141
141
|
Authorization: `Bearer ${this._accessToken}`,
|
|
142
142
|
"x-disable-hooks": "true"
|
|
143
143
|
};
|
|
144
|
-
const
|
|
145
|
-
|
|
144
|
+
const axiosInstance = import_axios.default.create({
|
|
145
|
+
headers
|
|
146
146
|
});
|
|
147
|
+
const fetchUrl = this._apiUrl + "/" + url;
|
|
148
|
+
const config = {
|
|
149
|
+
url: fetchUrl,
|
|
150
|
+
method: "GET",
|
|
151
|
+
...options
|
|
152
|
+
};
|
|
153
|
+
try {
|
|
154
|
+
const resp = await axiosInstance(config);
|
|
155
|
+
return resp.data.data;
|
|
156
|
+
} catch (err) {
|
|
157
|
+
}
|
|
147
158
|
}
|
|
148
159
|
/**
|
|
149
160
|
*
|
|
@@ -215,6 +226,7 @@ var FlatfileEvent = class extends AuthenticatedClient {
|
|
|
215
226
|
this.context = src.context;
|
|
216
227
|
this.payload = src.payload;
|
|
217
228
|
this.target = src.target || "";
|
|
229
|
+
this.origin = src.origin || {};
|
|
218
230
|
this.action = src.context?.actionName || "";
|
|
219
231
|
}
|
|
220
232
|
/**
|
|
@@ -236,6 +248,20 @@ var FlatfileEvent = class extends AuthenticatedClient {
|
|
|
236
248
|
this.afterAllCallbacks.set(key, callback);
|
|
237
249
|
}
|
|
238
250
|
}
|
|
251
|
+
async update(records) {
|
|
252
|
+
if (!this.src.dataUrl) {
|
|
253
|
+
throw new Error("Cannot set data on an event without a dataUrl");
|
|
254
|
+
}
|
|
255
|
+
const prepRecords = records.map((record) => {
|
|
256
|
+
record.messages?.map((message) => {
|
|
257
|
+
delete message.source;
|
|
258
|
+
});
|
|
259
|
+
});
|
|
260
|
+
await this.fetch(this.src.dataUrl, {
|
|
261
|
+
method: "POST",
|
|
262
|
+
data: JSON.stringify(prepRecords)
|
|
263
|
+
});
|
|
264
|
+
}
|
|
239
265
|
};
|
|
240
266
|
|
|
241
267
|
// ../../node_modules/wildcard-match/build/index.es.mjs
|
package/dist/index.mjs
CHANGED
|
@@ -93,14 +93,25 @@ var AuthenticatedClient = class {
|
|
|
93
93
|
this._accessToken = accessToken || bearerToken || "...";
|
|
94
94
|
this._apiUrl = apiUrl || FLATFILE_API_URL;
|
|
95
95
|
}
|
|
96
|
-
fetch(url) {
|
|
96
|
+
async fetch(url, options) {
|
|
97
97
|
const headers = {
|
|
98
98
|
Authorization: `Bearer ${this._accessToken}`,
|
|
99
99
|
"x-disable-hooks": "true"
|
|
100
100
|
};
|
|
101
|
-
const
|
|
102
|
-
|
|
101
|
+
const axiosInstance = axios.create({
|
|
102
|
+
headers
|
|
103
103
|
});
|
|
104
|
+
const fetchUrl = this._apiUrl + "/" + url;
|
|
105
|
+
const config = {
|
|
106
|
+
url: fetchUrl,
|
|
107
|
+
method: "GET",
|
|
108
|
+
...options
|
|
109
|
+
};
|
|
110
|
+
try {
|
|
111
|
+
const resp = await axiosInstance(config);
|
|
112
|
+
return resp.data.data;
|
|
113
|
+
} catch (err) {
|
|
114
|
+
}
|
|
104
115
|
}
|
|
105
116
|
/**
|
|
106
117
|
*
|
|
@@ -172,6 +183,7 @@ var FlatfileEvent = class extends AuthenticatedClient {
|
|
|
172
183
|
this.context = src.context;
|
|
173
184
|
this.payload = src.payload;
|
|
174
185
|
this.target = src.target || "";
|
|
186
|
+
this.origin = src.origin || {};
|
|
175
187
|
this.action = src.context?.actionName || "";
|
|
176
188
|
}
|
|
177
189
|
/**
|
|
@@ -193,6 +205,20 @@ var FlatfileEvent = class extends AuthenticatedClient {
|
|
|
193
205
|
this.afterAllCallbacks.set(key, callback);
|
|
194
206
|
}
|
|
195
207
|
}
|
|
208
|
+
async update(records) {
|
|
209
|
+
if (!this.src.dataUrl) {
|
|
210
|
+
throw new Error("Cannot set data on an event without a dataUrl");
|
|
211
|
+
}
|
|
212
|
+
const prepRecords = records.map((record) => {
|
|
213
|
+
record.messages?.map((message) => {
|
|
214
|
+
delete message.source;
|
|
215
|
+
});
|
|
216
|
+
});
|
|
217
|
+
await this.fetch(this.src.dataUrl, {
|
|
218
|
+
method: "POST",
|
|
219
|
+
data: JSON.stringify(prepRecords)
|
|
220
|
+
});
|
|
221
|
+
}
|
|
196
222
|
};
|
|
197
223
|
|
|
198
224
|
// ../../node_modules/wildcard-match/build/index.es.mjs
|