@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.
Files changed (45) hide show
  1. package/api/resources/automations/client/Client.js +4 -4
  2. package/api/resources/files/client/Client.js +4 -4
  3. package/api/resources/profiles/client/Client.js +1 -1
  4. package/api/resources/requests/client/Client.js +1 -1
  5. package/api/resources/sessions/client/Client.js +6 -6
  6. package/api/resources/sessions/types/SessionsEventsResponse.d.ts +7 -7
  7. package/api/resources/sessions/types/index.d.ts +2 -2
  8. package/api/resources/sessions/types/index.js +2 -2
  9. package/api/resources/windows/client/Client.js +31 -31
  10. package/api/types/FileEventMessage.d.ts +2 -0
  11. package/dist/api/resources/automations/client/Client.js +4 -4
  12. package/dist/api/resources/files/client/Client.js +4 -4
  13. package/dist/api/resources/profiles/client/Client.js +1 -1
  14. package/dist/api/resources/requests/client/Client.js +1 -1
  15. package/dist/api/resources/sessions/client/Client.js +6 -6
  16. package/dist/api/resources/sessions/types/SessionsEventsResponse.d.ts +7 -7
  17. package/dist/api/resources/sessions/types/index.d.ts +2 -2
  18. package/dist/api/resources/sessions/types/index.js +2 -2
  19. package/dist/api/resources/windows/client/Client.js +31 -31
  20. package/dist/api/types/FileEventMessage.d.ts +2 -0
  21. package/dist/serialization/resources/sessions/types/SessionsEventsResponse.d.ts +9 -9
  22. package/dist/serialization/resources/sessions/types/SessionsEventsResponse.js +4 -4
  23. package/dist/serialization/resources/sessions/types/index.d.ts +2 -2
  24. package/dist/serialization/resources/sessions/types/index.js +2 -2
  25. package/dist/serialization/types/FileEventMessage.d.ts +1 -0
  26. package/dist/serialization/types/FileEventMessage.js +1 -0
  27. package/dist/version.d.ts +1 -1
  28. package/dist/version.js +1 -1
  29. package/dist/wrapper/AirtopFiles.d.ts +1 -1
  30. package/dist/wrapper/AirtopFiles.js +1 -1
  31. package/dist/wrapper/AirtopSessions.d.ts +34 -15
  32. package/dist/wrapper/AirtopSessions.js +52 -20
  33. package/package.json +1 -1
  34. package/serialization/resources/sessions/types/SessionsEventsResponse.d.ts +9 -9
  35. package/serialization/resources/sessions/types/SessionsEventsResponse.js +4 -4
  36. package/serialization/resources/sessions/types/index.d.ts +2 -2
  37. package/serialization/resources/sessions/types/index.js +2 -2
  38. package/serialization/types/FileEventMessage.d.ts +1 -0
  39. package/serialization/types/FileEventMessage.js +1 -0
  40. package/version.d.ts +1 -1
  41. package/version.js +1 -1
  42. package/wrapper/AirtopFiles.d.ts +1 -1
  43. package/wrapper/AirtopFiles.js +1 -1
  44. package/wrapper/AirtopSessions.d.ts +34 -15
  45. 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 requestOptions - Optional request configuration including timeout
159
- * @returns Object containing file's id and downloadUrl, or null if timed out
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(() => resolve(null), timeoutSeconds * 1000);
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 requestOptions - Optional request configuration including timeout
207
- * @returns Object containing file's id and downloadUrl, or null if timed out
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 onProgress - Optional callback to track download progress
256
- * @param requestOptions - Optional request configuration including timeout
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, onProgress, requestOptions) {
290
+ downloadNextFile(sessionId, destinationPath, configuration, requestOptions) {
260
291
  return __awaiter(this, void 0, void 0, function* () {
261
292
  var _a;
262
- const nextFile = yield this.waitForDownload(sessionId, requestOptions);
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
  }