@airtop/sdk 0.1.37-beta0 → 0.1.37-beta2
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/api/resources/automations/client/Client.js +4 -4
- package/api/resources/files/client/Client.js +4 -4
- package/api/resources/profiles/client/Client.js +1 -1
- package/api/resources/requests/client/Client.js +1 -1
- package/api/resources/sessions/client/Client.js +6 -6
- package/api/resources/sessions/types/SessionsEventsResponse.d.ts +7 -7
- package/api/resources/sessions/types/index.d.ts +2 -2
- package/api/resources/sessions/types/index.js +2 -2
- package/api/resources/windows/client/Client.js +31 -31
- package/api/types/FileEventMessage.d.ts +2 -0
- package/dist/api/resources/automations/client/Client.js +4 -4
- package/dist/api/resources/files/client/Client.js +4 -4
- package/dist/api/resources/profiles/client/Client.js +1 -1
- package/dist/api/resources/requests/client/Client.js +1 -1
- package/dist/api/resources/sessions/client/Client.js +6 -6
- package/dist/api/resources/sessions/types/SessionsEventsResponse.d.ts +7 -7
- package/dist/api/resources/sessions/types/index.d.ts +2 -2
- package/dist/api/resources/sessions/types/index.js +2 -2
- package/dist/api/resources/windows/client/Client.js +31 -31
- package/dist/api/types/FileEventMessage.d.ts +2 -0
- package/dist/serialization/resources/sessions/types/SessionsEventsResponse.d.ts +9 -9
- package/dist/serialization/resources/sessions/types/SessionsEventsResponse.js +4 -4
- package/dist/serialization/resources/sessions/types/index.d.ts +2 -2
- package/dist/serialization/resources/sessions/types/index.js +2 -2
- package/dist/serialization/types/FileEventMessage.d.ts +1 -0
- package/dist/serialization/types/FileEventMessage.js +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/wrapper/AirtopFiles.d.ts +1 -1
- package/dist/wrapper/AirtopFiles.js +1 -1
- package/dist/wrapper/AirtopSessions.d.ts +34 -15
- package/dist/wrapper/AirtopSessions.js +52 -20
- package/package.json +1 -1
- package/serialization/resources/sessions/types/SessionsEventsResponse.d.ts +9 -9
- package/serialization/resources/sessions/types/SessionsEventsResponse.js +4 -4
- package/serialization/resources/sessions/types/index.d.ts +2 -2
- package/serialization/resources/sessions/types/index.js +2 -2
- package/serialization/types/FileEventMessage.d.ts +1 -0
- package/serialization/types/FileEventMessage.js +1 -0
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/wrapper/AirtopFiles.d.ts +1 -1
- package/wrapper/AirtopFiles.js +1 -1
- package/wrapper/AirtopSessions.d.ts +34 -15
- package/wrapper/AirtopSessions.js +52 -20
@@ -152,23 +152,33 @@ class AirtopSessions extends Client_1.Sessions {
|
|
152
152
|
});
|
153
153
|
}
|
154
154
|
/**
|
155
|
-
* Waits for a file to be downloaded in a session and reach 'available' status
|
155
|
+
* Waits for a file to be downloaded in a session and reach 'available' status.
|
156
|
+
* Defaults to looking back 5 seconds in the event stream for the file to be available.
|
157
|
+
* Use `lookbackSeconds` to control this behavior.
|
156
158
|
*
|
157
|
-
* @param sessionId - The ID of the session to monitor
|
158
|
-
* @param
|
159
|
-
* @
|
159
|
+
* @param {string} sessionId - The ID of the session to monitor
|
160
|
+
* @param {Object} configuration - The optional configuration parameters for the function
|
161
|
+
* @param {number} [configuration.lookbackSeconds=5] - The number of seconds to look back for prior events. Default `5`. 0 means no lookback.
|
162
|
+
* @param {Sessions.RequestOptions} [requestOptions] - Optional request configuration including timeout
|
163
|
+
* @returns {Promise<{ id: string, downloadUrl: string } | null>} Object containing file's id and downloadUrl, or null if timed out
|
160
164
|
*/
|
161
|
-
waitForDownload(sessionId, requestOptions) {
|
165
|
+
waitForDownload(sessionId, configuration, requestOptions) {
|
162
166
|
return __awaiter(this, void 0, void 0, function* () {
|
167
|
+
const { lookbackSeconds = 5 } = configuration || {};
|
168
|
+
this.log(`waiting for file to be available on session: ${sessionId}`);
|
169
|
+
const startTime = new Date();
|
163
170
|
const timeoutSeconds = (requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) || 120;
|
164
171
|
// Create a promise that resolves to null after the timeout
|
165
172
|
const timeoutPromise = new Promise((resolve) => {
|
166
|
-
setTimeout(() =>
|
173
|
+
setTimeout(() => {
|
174
|
+
this.log(`waiting for file timed out after ${timeoutSeconds} seconds`);
|
175
|
+
resolve(null);
|
176
|
+
}, timeoutSeconds * 1000);
|
167
177
|
});
|
168
178
|
// Create a promise for the event processing
|
169
179
|
const processEventsPromise = (() => __awaiter(this, void 0, void 0, function* () {
|
170
180
|
var _a, e_2, _b, _c;
|
171
|
-
const sessionEvents = yield this.events(sessionId, {}, Object.assign({ timeoutInSeconds: timeoutSeconds }, (requestOptions || {})));
|
181
|
+
const sessionEvents = yield this.events(sessionId, { all: lookbackSeconds >= 0 }, Object.assign({ timeoutInSeconds: timeoutSeconds }, (requestOptions || {})));
|
172
182
|
try {
|
173
183
|
for (var _d = true, sessionEvents_2 = __asyncValues(sessionEvents), sessionEvents_2_1; sessionEvents_2_1 = yield sessionEvents_2.next(), _a = sessionEvents_2_1.done, !_a; _d = true) {
|
174
184
|
_c = sessionEvents_2_1.value;
|
@@ -176,8 +186,14 @@ class AirtopSessions extends Client_1.Sessions {
|
|
176
186
|
const event = _c;
|
177
187
|
const e = event;
|
178
188
|
if (e.event === 'file_status') {
|
179
|
-
this.log(`file_status message received:\n${JSON.stringify(event, null, 2)}`);
|
180
189
|
if (e.status === 'available') {
|
190
|
+
const eventTime = Date.parse(e.eventTime);
|
191
|
+
this.log(`file_status message received:\n${JSON.stringify(event, null, 2)}`);
|
192
|
+
const thresholdTime = startTime.getTime() - lookbackSeconds * 1000;
|
193
|
+
if (eventTime < thresholdTime) {
|
194
|
+
this.log(`skipping file available event for ${e.fileId} because its timestamp is earlier than lookbackSeconds`);
|
195
|
+
continue;
|
196
|
+
}
|
181
197
|
return {
|
182
198
|
id: e.fileId,
|
183
199
|
downloadUrl: e.downloadUrl,
|
@@ -200,14 +216,20 @@ class AirtopSessions extends Client_1.Sessions {
|
|
200
216
|
});
|
201
217
|
}
|
202
218
|
/**
|
203
|
-
* Waits for a file download to start in a session
|
219
|
+
* Waits for a file download to start in a session.
|
220
|
+
* Defaults to looking back 5 seconds in the event stream for the file to be available.
|
221
|
+
* Use `lookbackSeconds` to control this behavior.
|
204
222
|
*
|
205
|
-
* @param sessionId - The ID of the session to monitor
|
206
|
-
* @param
|
207
|
-
* @
|
223
|
+
* @param {string} sessionId - The ID of the session to monitor
|
224
|
+
* @param {Object} configuration - The optional configuration parameters for the function
|
225
|
+
* @param {number} [configuration.lookbackSeconds=5] - The number of seconds to look back for prior events. Default `5`. 0 means no lookback.
|
226
|
+
* @param {Sessions.RequestOptions} [requestOptions] - Optional request configuration including timeout
|
227
|
+
* @returns {Promise<{ id: string, downloadUrl: string } | null>} Object containing file's id and downloadUrl, or null if timed out
|
208
228
|
*/
|
209
|
-
waitForDownloadStart(sessionId, requestOptions) {
|
229
|
+
waitForDownloadStart(sessionId, configuration, requestOptions) {
|
210
230
|
return __awaiter(this, void 0, void 0, function* () {
|
231
|
+
const { lookbackSeconds = 5 } = configuration || {};
|
232
|
+
const startTime = new Date();
|
211
233
|
const timeoutSeconds = (requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) || 60;
|
212
234
|
// Create a promise that resolves to null after the timeout
|
213
235
|
const timeoutPromise = new Promise((resolve) => {
|
@@ -216,7 +238,7 @@ class AirtopSessions extends Client_1.Sessions {
|
|
216
238
|
// Create a promise for the event processing
|
217
239
|
const processEventsPromise = (() => __awaiter(this, void 0, void 0, function* () {
|
218
240
|
var _a, e_3, _b, _c;
|
219
|
-
const sessionEvents = yield this.events(sessionId, {}, Object.assign({ timeoutInSeconds: timeoutSeconds }, (requestOptions || {})));
|
241
|
+
const sessionEvents = yield this.events(sessionId, { all: lookbackSeconds >= 0 }, Object.assign({ timeoutInSeconds: timeoutSeconds }, (requestOptions || {})));
|
220
242
|
try {
|
221
243
|
for (var _d = true, sessionEvents_3 = __asyncValues(sessionEvents), sessionEvents_3_1; sessionEvents_3_1 = yield sessionEvents_3.next(), _a = sessionEvents_3_1.done, !_a; _d = true) {
|
222
244
|
_c = sessionEvents_3_1.value;
|
@@ -226,6 +248,12 @@ class AirtopSessions extends Client_1.Sessions {
|
|
226
248
|
if (e.event === 'file_status') {
|
227
249
|
this.log(`file_status message received:\n${JSON.stringify(event, null, 2)}`);
|
228
250
|
if (e.status === 'uploading') {
|
251
|
+
const eventTime = Date.parse(e.eventTime);
|
252
|
+
const thresholdTime = startTime.getTime() - lookbackSeconds * 1000;
|
253
|
+
if (eventTime < thresholdTime) {
|
254
|
+
this.log(`skipping file uploading event for ${e.fileId} because its timestamp is earlier than lookbackSeconds`);
|
255
|
+
continue;
|
256
|
+
}
|
229
257
|
return {
|
230
258
|
id: e.fileId,
|
231
259
|
downloadUrl: e.downloadUrl,
|
@@ -250,16 +278,20 @@ class AirtopSessions extends Client_1.Sessions {
|
|
250
278
|
/**
|
251
279
|
* Downloads the next file from a session as soon as it starts to become available
|
252
280
|
*
|
253
|
-
* @param sessionId - The ID of the session to download from
|
254
|
-
* @param destinationPath - The local path where the file should be saved
|
255
|
-
* @param
|
256
|
-
* @param
|
281
|
+
* @param {string} sessionId - The ID of the session to download from
|
282
|
+
* @param {string} destinationPath - The local path where the file should be saved
|
283
|
+
* @param {Object} configuration - The optional configuration parameters for the function
|
284
|
+
* @param {function} [configuration.onProgress] - Optional callback to track download progress
|
285
|
+
* @param {number} [configuration.lookbackSeconds=5] - Optional number of seconds to look back for prior events. Default `5`. 0 means no lookback.
|
286
|
+
* @param {number} [configuration.timeoutSeconds=120] - Optional timeout in seconds. Default `120`.
|
287
|
+
* @param {Sessions.RequestOptions} [requestOptions] - Optional request configuration including timeout
|
257
288
|
* @throws Error if no file is available to download within the timeout period
|
258
289
|
*/
|
259
|
-
downloadNextFile(sessionId, destinationPath,
|
290
|
+
downloadNextFile(sessionId, destinationPath, configuration, requestOptions) {
|
260
291
|
return __awaiter(this, void 0, void 0, function* () {
|
261
292
|
var _a;
|
262
|
-
const
|
293
|
+
const { onProgress = undefined, lookbackSeconds = 5, timeoutSeconds = 120 } = configuration || {};
|
294
|
+
const nextFile = yield this.waitForDownload(sessionId, { lookbackSeconds }, Object.assign({ timeoutInSeconds: timeoutSeconds }, (requestOptions || {})));
|
263
295
|
if (!nextFile) {
|
264
296
|
throw new Error('No file to download within timeout');
|
265
297
|
}
|