@airtop/sdk 0.1.37-beta0 → 0.1.37-beta1
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 -14
- package/dist/wrapper/AirtopSessions.js +39 -22
- 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 -14
- package/wrapper/AirtopSessions.js +39 -22
@@ -152,14 +152,21 @@ 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 `includePriorEvents` and `lookbackSeconds` to control this behavior.
|
156
158
|
*
|
157
|
-
* @param
|
158
|
-
* @param
|
159
|
-
* @
|
159
|
+
* @param {Object} params - The parameters for the function
|
160
|
+
* @param {string} params.sessionId - The ID of the session to monitor
|
161
|
+
* @param {boolean} [params.includePriorEvents=true] - Whether to include prior events in the wait. Default `true`.
|
162
|
+
* @param {number} [params.lookbackSeconds=5] - The number of seconds to look back for prior events. Default `5`.
|
163
|
+
* @param {Sessions.RequestOptions} [requestOptions] - Optional request configuration including timeout
|
164
|
+
* @returns {Promise<{ id: string, downloadUrl: string } | null>} Object containing file's id and downloadUrl, or null if timed out
|
160
165
|
*/
|
161
|
-
waitForDownload(sessionId, requestOptions) {
|
166
|
+
waitForDownload(sessionId, configuration, requestOptions) {
|
162
167
|
return __awaiter(this, void 0, void 0, function* () {
|
168
|
+
const { includePriorEvents = true, lookbackSeconds = 5 } = configuration || {};
|
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) => {
|
@@ -168,7 +175,7 @@ class AirtopSessions extends Client_1.Sessions {
|
|
168
175
|
// Create a promise for the event processing
|
169
176
|
const processEventsPromise = (() => __awaiter(this, void 0, void 0, function* () {
|
170
177
|
var _a, e_2, _b, _c;
|
171
|
-
const sessionEvents = yield this.events(sessionId, {}, Object.assign({ timeoutInSeconds: timeoutSeconds }, (requestOptions || {})));
|
178
|
+
const sessionEvents = yield this.events(sessionId, { all: includePriorEvents }, Object.assign({ timeoutInSeconds: timeoutSeconds }, (requestOptions || {})));
|
172
179
|
try {
|
173
180
|
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
181
|
_c = sessionEvents_2_1.value;
|
@@ -176,8 +183,14 @@ class AirtopSessions extends Client_1.Sessions {
|
|
176
183
|
const event = _c;
|
177
184
|
const e = event;
|
178
185
|
if (e.event === 'file_status') {
|
179
|
-
this.log(`file_status message received:\n${JSON.stringify(event, null, 2)}`);
|
180
186
|
if (e.status === 'available') {
|
187
|
+
const eventTime = Date.parse(e.eventTime);
|
188
|
+
this.log(`file_status message received:\n${JSON.stringify(event, null, 2)}`);
|
189
|
+
const thresholdTime = startTime.getTime() - lookbackSeconds * 1000;
|
190
|
+
if (eventTime < thresholdTime) {
|
191
|
+
this.log(`skipping file available event for ${e.fileId} because its timestamp is earlier than lookbackSeconds`);
|
192
|
+
continue;
|
193
|
+
}
|
181
194
|
return {
|
182
195
|
id: e.fileId,
|
183
196
|
downloadUrl: e.downloadUrl,
|
@@ -202,12 +215,14 @@ class AirtopSessions extends Client_1.Sessions {
|
|
202
215
|
/**
|
203
216
|
* Waits for a file download to start in a session
|
204
217
|
*
|
205
|
-
* @param
|
206
|
-
* @param
|
207
|
-
* @
|
218
|
+
* @param {Object} params - The parameters for the function
|
219
|
+
* @param {string} params.sessionId - The ID of the session to monitor
|
220
|
+
* @param {boolean} [params.includePriorEvents=false] - Whether to include prior events in the wait
|
221
|
+
* @param {Sessions.RequestOptions} [requestOptions] - Optional request configuration including timeout
|
222
|
+
* @returns {Promise<{ id: string, downloadUrl: string } | null>} Object containing file's id and downloadUrl, or null if timed out
|
208
223
|
*/
|
209
|
-
waitForDownloadStart(
|
210
|
-
return __awaiter(this,
|
224
|
+
waitForDownloadStart(_a, requestOptions_1) {
|
225
|
+
return __awaiter(this, arguments, void 0, function* ({ sessionId, includePriorEvents = false }, requestOptions) {
|
211
226
|
const timeoutSeconds = (requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) || 60;
|
212
227
|
// Create a promise that resolves to null after the timeout
|
213
228
|
const timeoutPromise = new Promise((resolve) => {
|
@@ -216,7 +231,7 @@ class AirtopSessions extends Client_1.Sessions {
|
|
216
231
|
// Create a promise for the event processing
|
217
232
|
const processEventsPromise = (() => __awaiter(this, void 0, void 0, function* () {
|
218
233
|
var _a, e_3, _b, _c;
|
219
|
-
const sessionEvents = yield this.events(sessionId, {}, Object.assign({ timeoutInSeconds: timeoutSeconds }, (requestOptions || {})));
|
234
|
+
const sessionEvents = yield this.events(sessionId, { all: includePriorEvents }, Object.assign({ timeoutInSeconds: timeoutSeconds }, (requestOptions || {})));
|
220
235
|
try {
|
221
236
|
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
237
|
_c = sessionEvents_3_1.value;
|
@@ -250,16 +265,18 @@ class AirtopSessions extends Client_1.Sessions {
|
|
250
265
|
/**
|
251
266
|
* Downloads the next file from a session as soon as it starts to become available
|
252
267
|
*
|
253
|
-
* @param
|
254
|
-
* @param
|
255
|
-
* @param
|
256
|
-
* @param
|
268
|
+
* @param {Object} params - The parameters for the function
|
269
|
+
* @param {string} params.sessionId - The ID of the session to download from
|
270
|
+
* @param {string} params.destinationPath - The local path where the file should be saved
|
271
|
+
* @param {function} [params.onProgress] - Optional callback to track download progress
|
272
|
+
* @param {boolean} [params.includePriorEvents=false] - Whether to include prior events in the wait
|
273
|
+
* @param {Sessions.RequestOptions} [requestOptions] - Optional request configuration including timeout
|
257
274
|
* @throws Error if no file is available to download within the timeout period
|
258
275
|
*/
|
259
|
-
downloadNextFile(
|
260
|
-
return __awaiter(this,
|
261
|
-
var
|
262
|
-
const nextFile = yield this.waitForDownload(sessionId, requestOptions);
|
276
|
+
downloadNextFile(_a, requestOptions_1) {
|
277
|
+
return __awaiter(this, arguments, void 0, function* ({ sessionId, destinationPath, onProgress, includePriorEvents = false, }, requestOptions) {
|
278
|
+
var _b;
|
279
|
+
const nextFile = yield this.waitForDownload(sessionId, { includePriorEvents }, requestOptions);
|
263
280
|
if (!nextFile) {
|
264
281
|
throw new Error('No file to download within timeout');
|
265
282
|
}
|
@@ -267,7 +284,7 @@ class AirtopSessions extends Client_1.Sessions {
|
|
267
284
|
if (!downloadResponse.ok) {
|
268
285
|
throw new Error(`Failed to download file: ${downloadResponse.statusText}`);
|
269
286
|
}
|
270
|
-
const totalBytes = Number.parseInt((
|
287
|
+
const totalBytes = Number.parseInt((_b = downloadResponse.headers.get('content-length')) !== null && _b !== void 0 ? _b : '0', 10);
|
271
288
|
let downloadedBytes = 0;
|
272
289
|
fs.mkdirSync(path.dirname(destinationPath), { recursive: true });
|
273
290
|
const fileStream = fs.createWriteStream(destinationPath);
|