@airtop/sdk 0.1.37-beta1 → 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 +4 -4
- package/api/resources/sessions/types/index.d.ts +1 -1
- package/api/resources/sessions/types/index.js +1 -1
- package/api/resources/windows/client/Client.js +31 -31
- 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 +4 -4
- package/dist/api/resources/sessions/types/index.d.ts +1 -1
- package/dist/api/resources/sessions/types/index.js +1 -1
- package/dist/api/resources/windows/client/Client.js +31 -31
- package/dist/serialization/resources/sessions/types/SessionsEventsResponse.d.ts +5 -5
- package/dist/serialization/resources/sessions/types/SessionsEventsResponse.js +2 -2
- package/dist/serialization/resources/sessions/types/index.d.ts +1 -1
- package/dist/serialization/resources/sessions/types/index.js +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/wrapper/AirtopSessions.d.ts +21 -22
- package/dist/wrapper/AirtopSessions.js +40 -25
- package/package.json +1 -1
- package/serialization/resources/sessions/types/SessionsEventsResponse.d.ts +5 -5
- package/serialization/resources/sessions/types/SessionsEventsResponse.js +2 -2
- package/serialization/resources/sessions/types/index.d.ts +1 -1
- package/serialization/resources/sessions/types/index.js +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/wrapper/AirtopSessions.d.ts +21 -22
- package/wrapper/AirtopSessions.js +40 -25
@@ -38,18 +38,18 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
39
39
|
exports.SessionsEventsResponse = void 0;
|
40
40
|
const core = __importStar(require("../../../../core"));
|
41
|
+
const SessionsEventsResponseWindowEvent_1 = require("./SessionsEventsResponseWindowEvent");
|
41
42
|
const SessionsEventsResponseSessionEvent_1 = require("./SessionsEventsResponseSessionEvent");
|
42
43
|
const SessionsEventsResponseFileEvent_1 = require("./SessionsEventsResponseFileEvent");
|
43
44
|
const SessionsEventsResponseStatus_1 = require("./SessionsEventsResponseStatus");
|
44
45
|
const SessionsEventsResponseError_1 = require("./SessionsEventsResponseError");
|
45
|
-
const SessionsEventsResponseWindowEvent_1 = require("./SessionsEventsResponseWindowEvent");
|
46
46
|
exports.SessionsEventsResponse = core.serialization
|
47
47
|
.union("event", {
|
48
|
+
windowEvent: SessionsEventsResponseWindowEvent_1.SessionsEventsResponseWindowEvent,
|
48
49
|
sessionEvent: SessionsEventsResponseSessionEvent_1.SessionsEventsResponseSessionEvent,
|
49
50
|
fileEvent: SessionsEventsResponseFileEvent_1.SessionsEventsResponseFileEvent,
|
50
51
|
status: SessionsEventsResponseStatus_1.SessionsEventsResponseStatus,
|
51
52
|
error: SessionsEventsResponseError_1.SessionsEventsResponseError,
|
52
|
-
windowEvent: SessionsEventsResponseWindowEvent_1.SessionsEventsResponseWindowEvent,
|
53
53
|
})
|
54
54
|
.transform({
|
55
55
|
transform: (value) => value,
|
@@ -1,7 +1,7 @@
|
|
1
1
|
export * from "./SessionsListRequestStatus";
|
2
|
+
export * from "./SessionsEventsResponseWindowEvent";
|
2
3
|
export * from "./SessionsEventsResponseSessionEvent";
|
3
4
|
export * from "./SessionsEventsResponseFileEvent";
|
4
5
|
export * from "./SessionsEventsResponseStatus";
|
5
6
|
export * from "./SessionsEventsResponseError";
|
6
|
-
export * from "./SessionsEventsResponseWindowEvent";
|
7
7
|
export * from "./SessionsEventsResponse";
|
@@ -15,9 +15,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
15
15
|
};
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
17
17
|
__exportStar(require("./SessionsListRequestStatus"), exports);
|
18
|
+
__exportStar(require("./SessionsEventsResponseWindowEvent"), exports);
|
18
19
|
__exportStar(require("./SessionsEventsResponseSessionEvent"), exports);
|
19
20
|
__exportStar(require("./SessionsEventsResponseFileEvent"), exports);
|
20
21
|
__exportStar(require("./SessionsEventsResponseStatus"), exports);
|
21
22
|
__exportStar(require("./SessionsEventsResponseError"), exports);
|
22
|
-
__exportStar(require("./SessionsEventsResponseWindowEvent"), exports);
|
23
23
|
__exportStar(require("./SessionsEventsResponse"), exports);
|
package/dist/version.d.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export declare const SDK_VERSION = "0.1.37-
|
1
|
+
export declare const SDK_VERSION = "0.1.37-beta2";
|
package/dist/version.js
CHANGED
@@ -31,34 +31,33 @@ export declare class AirtopSessions extends SessionsClass {
|
|
31
31
|
/**
|
32
32
|
* Waits for a file to be downloaded in a session and reach 'available' status.
|
33
33
|
* Defaults to looking back 5 seconds in the event stream for the file to be available.
|
34
|
-
* Use `
|
34
|
+
* Use `lookbackSeconds` to control this behavior.
|
35
35
|
*
|
36
|
-
* @param {
|
37
|
-
* @param {
|
38
|
-
* @param {
|
39
|
-
* @param {number} [params.lookbackSeconds=5] - The number of seconds to look back for prior events. Default `5`.
|
36
|
+
* @param {string} sessionId - The ID of the session to monitor
|
37
|
+
* @param {Object} configuration - The optional configuration parameters for the function
|
38
|
+
* @param {number} [configuration.lookbackSeconds=5] - The number of seconds to look back for prior events. Default `5`. 0 means no lookback.
|
40
39
|
* @param {Sessions.RequestOptions} [requestOptions] - Optional request configuration including timeout
|
41
40
|
* @returns {Promise<{ id: string, downloadUrl: string } | null>} Object containing file's id and downloadUrl, or null if timed out
|
42
41
|
*/
|
43
42
|
waitForDownload(sessionId: string, configuration?: {
|
44
|
-
includePriorEvents?: boolean;
|
45
43
|
lookbackSeconds?: number;
|
46
44
|
}, requestOptions?: SessionsNamespace.RequestOptions): Promise<{
|
47
45
|
id: string;
|
48
46
|
downloadUrl: string;
|
49
47
|
} | null>;
|
50
48
|
/**
|
51
|
-
* Waits for a file download to start in a session
|
49
|
+
* Waits for a file download to start in a session.
|
50
|
+
* Defaults to looking back 5 seconds in the event stream for the file to be available.
|
51
|
+
* Use `lookbackSeconds` to control this behavior.
|
52
52
|
*
|
53
|
-
* @param {
|
54
|
-
* @param {
|
55
|
-
* @param {
|
53
|
+
* @param {string} sessionId - The ID of the session to monitor
|
54
|
+
* @param {Object} configuration - The optional configuration parameters for the function
|
55
|
+
* @param {number} [configuration.lookbackSeconds=5] - The number of seconds to look back for prior events. Default `5`. 0 means no lookback.
|
56
56
|
* @param {Sessions.RequestOptions} [requestOptions] - Optional request configuration including timeout
|
57
57
|
* @returns {Promise<{ id: string, downloadUrl: string } | null>} Object containing file's id and downloadUrl, or null if timed out
|
58
58
|
*/
|
59
|
-
waitForDownloadStart(
|
60
|
-
|
61
|
-
includePriorEvents?: boolean;
|
59
|
+
waitForDownloadStart(sessionId: string, configuration?: {
|
60
|
+
lookbackSeconds?: number;
|
62
61
|
}, requestOptions?: SessionsNamespace.RequestOptions): Promise<{
|
63
62
|
id: string;
|
64
63
|
downloadUrl: string;
|
@@ -66,18 +65,18 @@ export declare class AirtopSessions extends SessionsClass {
|
|
66
65
|
/**
|
67
66
|
* Downloads the next file from a session as soon as it starts to become available
|
68
67
|
*
|
69
|
-
* @param {
|
70
|
-
* @param {string}
|
71
|
-
* @param {
|
72
|
-
* @param {function} [
|
73
|
-
* @param {
|
68
|
+
* @param {string} sessionId - The ID of the session to download from
|
69
|
+
* @param {string} destinationPath - The local path where the file should be saved
|
70
|
+
* @param {Object} configuration - The optional configuration parameters for the function
|
71
|
+
* @param {function} [configuration.onProgress] - Optional callback to track download progress
|
72
|
+
* @param {number} [configuration.lookbackSeconds=5] - Optional number of seconds to look back for prior events. Default `5`. 0 means no lookback.
|
73
|
+
* @param {number} [configuration.timeoutSeconds=120] - Optional timeout in seconds. Default `120`.
|
74
74
|
* @param {Sessions.RequestOptions} [requestOptions] - Optional request configuration including timeout
|
75
75
|
* @throws Error if no file is available to download within the timeout period
|
76
76
|
*/
|
77
|
-
downloadNextFile(
|
78
|
-
sessionId: string;
|
79
|
-
destinationPath: string;
|
77
|
+
downloadNextFile(sessionId: string, destinationPath: string, configuration?: {
|
80
78
|
onProgress?: (downloadedBytes: number, totalBytes: number) => void;
|
81
|
-
|
79
|
+
lookbackSeconds?: number;
|
80
|
+
timeoutSeconds?: number;
|
82
81
|
}, requestOptions?: SessionsNamespace.RequestOptions): Promise<void>;
|
83
82
|
}
|
@@ -154,28 +154,31 @@ class AirtopSessions extends Client_1.Sessions {
|
|
154
154
|
/**
|
155
155
|
* Waits for a file to be downloaded in a session and reach 'available' status.
|
156
156
|
* Defaults to looking back 5 seconds in the event stream for the file to be available.
|
157
|
-
* Use `
|
157
|
+
* Use `lookbackSeconds` to control this behavior.
|
158
158
|
*
|
159
|
-
* @param {
|
160
|
-
* @param {
|
161
|
-
* @param {
|
162
|
-
* @param {number} [params.lookbackSeconds=5] - The number of seconds to look back for prior events. Default `5`.
|
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.
|
163
162
|
* @param {Sessions.RequestOptions} [requestOptions] - Optional request configuration including timeout
|
164
163
|
* @returns {Promise<{ id: string, downloadUrl: string } | null>} Object containing file's id and downloadUrl, or null if timed out
|
165
164
|
*/
|
166
165
|
waitForDownload(sessionId, configuration, requestOptions) {
|
167
166
|
return __awaiter(this, void 0, void 0, function* () {
|
168
|
-
const {
|
167
|
+
const { lookbackSeconds = 5 } = configuration || {};
|
168
|
+
this.log(`waiting for file to be available on session: ${sessionId}`);
|
169
169
|
const startTime = new Date();
|
170
170
|
const timeoutSeconds = (requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) || 120;
|
171
171
|
// Create a promise that resolves to null after the timeout
|
172
172
|
const timeoutPromise = new Promise((resolve) => {
|
173
|
-
setTimeout(() =>
|
173
|
+
setTimeout(() => {
|
174
|
+
this.log(`waiting for file timed out after ${timeoutSeconds} seconds`);
|
175
|
+
resolve(null);
|
176
|
+
}, timeoutSeconds * 1000);
|
174
177
|
});
|
175
178
|
// Create a promise for the event processing
|
176
179
|
const processEventsPromise = (() => __awaiter(this, void 0, void 0, function* () {
|
177
180
|
var _a, e_2, _b, _c;
|
178
|
-
const sessionEvents = yield this.events(sessionId, { all:
|
181
|
+
const sessionEvents = yield this.events(sessionId, { all: lookbackSeconds >= 0 }, Object.assign({ timeoutInSeconds: timeoutSeconds }, (requestOptions || {})));
|
179
182
|
try {
|
180
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) {
|
181
184
|
_c = sessionEvents_2_1.value;
|
@@ -213,16 +216,20 @@ class AirtopSessions extends Client_1.Sessions {
|
|
213
216
|
});
|
214
217
|
}
|
215
218
|
/**
|
216
|
-
* 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.
|
217
222
|
*
|
218
|
-
* @param {
|
219
|
-
* @param {
|
220
|
-
* @param {
|
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.
|
221
226
|
* @param {Sessions.RequestOptions} [requestOptions] - Optional request configuration including timeout
|
222
227
|
* @returns {Promise<{ id: string, downloadUrl: string } | null>} Object containing file's id and downloadUrl, or null if timed out
|
223
228
|
*/
|
224
|
-
waitForDownloadStart(
|
225
|
-
return __awaiter(this,
|
229
|
+
waitForDownloadStart(sessionId, configuration, requestOptions) {
|
230
|
+
return __awaiter(this, void 0, void 0, function* () {
|
231
|
+
const { lookbackSeconds = 5 } = configuration || {};
|
232
|
+
const startTime = new Date();
|
226
233
|
const timeoutSeconds = (requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) || 60;
|
227
234
|
// Create a promise that resolves to null after the timeout
|
228
235
|
const timeoutPromise = new Promise((resolve) => {
|
@@ -231,7 +238,7 @@ class AirtopSessions extends Client_1.Sessions {
|
|
231
238
|
// Create a promise for the event processing
|
232
239
|
const processEventsPromise = (() => __awaiter(this, void 0, void 0, function* () {
|
233
240
|
var _a, e_3, _b, _c;
|
234
|
-
const sessionEvents = yield this.events(sessionId, { all:
|
241
|
+
const sessionEvents = yield this.events(sessionId, { all: lookbackSeconds >= 0 }, Object.assign({ timeoutInSeconds: timeoutSeconds }, (requestOptions || {})));
|
235
242
|
try {
|
236
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) {
|
237
244
|
_c = sessionEvents_3_1.value;
|
@@ -241,6 +248,12 @@ class AirtopSessions extends Client_1.Sessions {
|
|
241
248
|
if (e.event === 'file_status') {
|
242
249
|
this.log(`file_status message received:\n${JSON.stringify(event, null, 2)}`);
|
243
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
|
+
}
|
244
257
|
return {
|
245
258
|
id: e.fileId,
|
246
259
|
downloadUrl: e.downloadUrl,
|
@@ -265,18 +278,20 @@ class AirtopSessions extends Client_1.Sessions {
|
|
265
278
|
/**
|
266
279
|
* Downloads the next file from a session as soon as it starts to become available
|
267
280
|
*
|
268
|
-
* @param {
|
269
|
-
* @param {string}
|
270
|
-
* @param {
|
271
|
-
* @param {function} [
|
272
|
-
* @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`.
|
273
287
|
* @param {Sessions.RequestOptions} [requestOptions] - Optional request configuration including timeout
|
274
288
|
* @throws Error if no file is available to download within the timeout period
|
275
289
|
*/
|
276
|
-
downloadNextFile(
|
277
|
-
return __awaiter(this,
|
278
|
-
var
|
279
|
-
const
|
290
|
+
downloadNextFile(sessionId, destinationPath, configuration, requestOptions) {
|
291
|
+
return __awaiter(this, void 0, void 0, function* () {
|
292
|
+
var _a;
|
293
|
+
const { onProgress = undefined, lookbackSeconds = 5, timeoutSeconds = 120 } = configuration || {};
|
294
|
+
const nextFile = yield this.waitForDownload(sessionId, { lookbackSeconds }, Object.assign({ timeoutInSeconds: timeoutSeconds }, (requestOptions || {})));
|
280
295
|
if (!nextFile) {
|
281
296
|
throw new Error('No file to download within timeout');
|
282
297
|
}
|
@@ -284,7 +299,7 @@ class AirtopSessions extends Client_1.Sessions {
|
|
284
299
|
if (!downloadResponse.ok) {
|
285
300
|
throw new Error(`Failed to download file: ${downloadResponse.statusText}`);
|
286
301
|
}
|
287
|
-
const totalBytes = Number.parseInt((
|
302
|
+
const totalBytes = Number.parseInt((_a = downloadResponse.headers.get('content-length')) !== null && _a !== void 0 ? _a : '0', 10);
|
288
303
|
let downloadedBytes = 0;
|
289
304
|
fs.mkdirSync(path.dirname(destinationPath), { recursive: true });
|
290
305
|
const fileStream = fs.createWriteStream(destinationPath);
|
package/package.json
CHANGED
@@ -4,14 +4,17 @@
|
|
4
4
|
import * as serializers from "../../../index";
|
5
5
|
import * as Airtop from "../../../../api/index";
|
6
6
|
import * as core from "../../../../core";
|
7
|
+
import { SessionsEventsResponseWindowEvent } from "./SessionsEventsResponseWindowEvent";
|
7
8
|
import { SessionsEventsResponseSessionEvent } from "./SessionsEventsResponseSessionEvent";
|
8
9
|
import { SessionsEventsResponseFileEvent } from "./SessionsEventsResponseFileEvent";
|
9
10
|
import { SessionsEventsResponseStatus } from "./SessionsEventsResponseStatus";
|
10
11
|
import { SessionsEventsResponseError } from "./SessionsEventsResponseError";
|
11
|
-
import { SessionsEventsResponseWindowEvent } from "./SessionsEventsResponseWindowEvent";
|
12
12
|
export declare const SessionsEventsResponse: core.serialization.Schema<serializers.SessionsEventsResponse.Raw, Airtop.SessionsEventsResponse>;
|
13
13
|
export declare namespace SessionsEventsResponse {
|
14
|
-
type Raw = SessionsEventsResponse.
|
14
|
+
type Raw = SessionsEventsResponse.WindowEvent | SessionsEventsResponse.SessionEvent | SessionsEventsResponse.FileEvent | SessionsEventsResponse.Status | SessionsEventsResponse.Error;
|
15
|
+
interface WindowEvent extends SessionsEventsResponseWindowEvent.Raw {
|
16
|
+
event: "windowEvent";
|
17
|
+
}
|
15
18
|
interface SessionEvent extends SessionsEventsResponseSessionEvent.Raw {
|
16
19
|
event: "sessionEvent";
|
17
20
|
}
|
@@ -24,7 +27,4 @@ export declare namespace SessionsEventsResponse {
|
|
24
27
|
interface Error extends SessionsEventsResponseError.Raw {
|
25
28
|
event: "error";
|
26
29
|
}
|
27
|
-
interface WindowEvent extends SessionsEventsResponseWindowEvent.Raw {
|
28
|
-
event: "windowEvent";
|
29
|
-
}
|
30
30
|
}
|
@@ -38,18 +38,18 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
39
39
|
exports.SessionsEventsResponse = void 0;
|
40
40
|
const core = __importStar(require("../../../../core"));
|
41
|
+
const SessionsEventsResponseWindowEvent_1 = require("./SessionsEventsResponseWindowEvent");
|
41
42
|
const SessionsEventsResponseSessionEvent_1 = require("./SessionsEventsResponseSessionEvent");
|
42
43
|
const SessionsEventsResponseFileEvent_1 = require("./SessionsEventsResponseFileEvent");
|
43
44
|
const SessionsEventsResponseStatus_1 = require("./SessionsEventsResponseStatus");
|
44
45
|
const SessionsEventsResponseError_1 = require("./SessionsEventsResponseError");
|
45
|
-
const SessionsEventsResponseWindowEvent_1 = require("./SessionsEventsResponseWindowEvent");
|
46
46
|
exports.SessionsEventsResponse = core.serialization
|
47
47
|
.union("event", {
|
48
|
+
windowEvent: SessionsEventsResponseWindowEvent_1.SessionsEventsResponseWindowEvent,
|
48
49
|
sessionEvent: SessionsEventsResponseSessionEvent_1.SessionsEventsResponseSessionEvent,
|
49
50
|
fileEvent: SessionsEventsResponseFileEvent_1.SessionsEventsResponseFileEvent,
|
50
51
|
status: SessionsEventsResponseStatus_1.SessionsEventsResponseStatus,
|
51
52
|
error: SessionsEventsResponseError_1.SessionsEventsResponseError,
|
52
|
-
windowEvent: SessionsEventsResponseWindowEvent_1.SessionsEventsResponseWindowEvent,
|
53
53
|
})
|
54
54
|
.transform({
|
55
55
|
transform: (value) => value,
|
@@ -1,7 +1,7 @@
|
|
1
1
|
export * from "./SessionsListRequestStatus";
|
2
|
+
export * from "./SessionsEventsResponseWindowEvent";
|
2
3
|
export * from "./SessionsEventsResponseSessionEvent";
|
3
4
|
export * from "./SessionsEventsResponseFileEvent";
|
4
5
|
export * from "./SessionsEventsResponseStatus";
|
5
6
|
export * from "./SessionsEventsResponseError";
|
6
|
-
export * from "./SessionsEventsResponseWindowEvent";
|
7
7
|
export * from "./SessionsEventsResponse";
|
@@ -15,9 +15,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
15
15
|
};
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
17
17
|
__exportStar(require("./SessionsListRequestStatus"), exports);
|
18
|
+
__exportStar(require("./SessionsEventsResponseWindowEvent"), exports);
|
18
19
|
__exportStar(require("./SessionsEventsResponseSessionEvent"), exports);
|
19
20
|
__exportStar(require("./SessionsEventsResponseFileEvent"), exports);
|
20
21
|
__exportStar(require("./SessionsEventsResponseStatus"), exports);
|
21
22
|
__exportStar(require("./SessionsEventsResponseError"), exports);
|
22
|
-
__exportStar(require("./SessionsEventsResponseWindowEvent"), exports);
|
23
23
|
__exportStar(require("./SessionsEventsResponse"), exports);
|
package/version.d.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export declare const SDK_VERSION = "0.1.37-
|
1
|
+
export declare const SDK_VERSION = "0.1.37-beta2";
|
package/version.js
CHANGED
@@ -31,34 +31,33 @@ export declare class AirtopSessions extends SessionsClass {
|
|
31
31
|
/**
|
32
32
|
* Waits for a file to be downloaded in a session and reach 'available' status.
|
33
33
|
* Defaults to looking back 5 seconds in the event stream for the file to be available.
|
34
|
-
* Use `
|
34
|
+
* Use `lookbackSeconds` to control this behavior.
|
35
35
|
*
|
36
|
-
* @param {
|
37
|
-
* @param {
|
38
|
-
* @param {
|
39
|
-
* @param {number} [params.lookbackSeconds=5] - The number of seconds to look back for prior events. Default `5`.
|
36
|
+
* @param {string} sessionId - The ID of the session to monitor
|
37
|
+
* @param {Object} configuration - The optional configuration parameters for the function
|
38
|
+
* @param {number} [configuration.lookbackSeconds=5] - The number of seconds to look back for prior events. Default `5`. 0 means no lookback.
|
40
39
|
* @param {Sessions.RequestOptions} [requestOptions] - Optional request configuration including timeout
|
41
40
|
* @returns {Promise<{ id: string, downloadUrl: string } | null>} Object containing file's id and downloadUrl, or null if timed out
|
42
41
|
*/
|
43
42
|
waitForDownload(sessionId: string, configuration?: {
|
44
|
-
includePriorEvents?: boolean;
|
45
43
|
lookbackSeconds?: number;
|
46
44
|
}, requestOptions?: SessionsNamespace.RequestOptions): Promise<{
|
47
45
|
id: string;
|
48
46
|
downloadUrl: string;
|
49
47
|
} | null>;
|
50
48
|
/**
|
51
|
-
* Waits for a file download to start in a session
|
49
|
+
* Waits for a file download to start in a session.
|
50
|
+
* Defaults to looking back 5 seconds in the event stream for the file to be available.
|
51
|
+
* Use `lookbackSeconds` to control this behavior.
|
52
52
|
*
|
53
|
-
* @param {
|
54
|
-
* @param {
|
55
|
-
* @param {
|
53
|
+
* @param {string} sessionId - The ID of the session to monitor
|
54
|
+
* @param {Object} configuration - The optional configuration parameters for the function
|
55
|
+
* @param {number} [configuration.lookbackSeconds=5] - The number of seconds to look back for prior events. Default `5`. 0 means no lookback.
|
56
56
|
* @param {Sessions.RequestOptions} [requestOptions] - Optional request configuration including timeout
|
57
57
|
* @returns {Promise<{ id: string, downloadUrl: string } | null>} Object containing file's id and downloadUrl, or null if timed out
|
58
58
|
*/
|
59
|
-
waitForDownloadStart(
|
60
|
-
|
61
|
-
includePriorEvents?: boolean;
|
59
|
+
waitForDownloadStart(sessionId: string, configuration?: {
|
60
|
+
lookbackSeconds?: number;
|
62
61
|
}, requestOptions?: SessionsNamespace.RequestOptions): Promise<{
|
63
62
|
id: string;
|
64
63
|
downloadUrl: string;
|
@@ -66,18 +65,18 @@ export declare class AirtopSessions extends SessionsClass {
|
|
66
65
|
/**
|
67
66
|
* Downloads the next file from a session as soon as it starts to become available
|
68
67
|
*
|
69
|
-
* @param {
|
70
|
-
* @param {string}
|
71
|
-
* @param {
|
72
|
-
* @param {function} [
|
73
|
-
* @param {
|
68
|
+
* @param {string} sessionId - The ID of the session to download from
|
69
|
+
* @param {string} destinationPath - The local path where the file should be saved
|
70
|
+
* @param {Object} configuration - The optional configuration parameters for the function
|
71
|
+
* @param {function} [configuration.onProgress] - Optional callback to track download progress
|
72
|
+
* @param {number} [configuration.lookbackSeconds=5] - Optional number of seconds to look back for prior events. Default `5`. 0 means no lookback.
|
73
|
+
* @param {number} [configuration.timeoutSeconds=120] - Optional timeout in seconds. Default `120`.
|
74
74
|
* @param {Sessions.RequestOptions} [requestOptions] - Optional request configuration including timeout
|
75
75
|
* @throws Error if no file is available to download within the timeout period
|
76
76
|
*/
|
77
|
-
downloadNextFile(
|
78
|
-
sessionId: string;
|
79
|
-
destinationPath: string;
|
77
|
+
downloadNextFile(sessionId: string, destinationPath: string, configuration?: {
|
80
78
|
onProgress?: (downloadedBytes: number, totalBytes: number) => void;
|
81
|
-
|
79
|
+
lookbackSeconds?: number;
|
80
|
+
timeoutSeconds?: number;
|
82
81
|
}, requestOptions?: SessionsNamespace.RequestOptions): Promise<void>;
|
83
82
|
}
|
@@ -154,28 +154,31 @@ class AirtopSessions extends Client_1.Sessions {
|
|
154
154
|
/**
|
155
155
|
* Waits for a file to be downloaded in a session and reach 'available' status.
|
156
156
|
* Defaults to looking back 5 seconds in the event stream for the file to be available.
|
157
|
-
* Use `
|
157
|
+
* Use `lookbackSeconds` to control this behavior.
|
158
158
|
*
|
159
|
-
* @param {
|
160
|
-
* @param {
|
161
|
-
* @param {
|
162
|
-
* @param {number} [params.lookbackSeconds=5] - The number of seconds to look back for prior events. Default `5`.
|
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.
|
163
162
|
* @param {Sessions.RequestOptions} [requestOptions] - Optional request configuration including timeout
|
164
163
|
* @returns {Promise<{ id: string, downloadUrl: string } | null>} Object containing file's id and downloadUrl, or null if timed out
|
165
164
|
*/
|
166
165
|
waitForDownload(sessionId, configuration, requestOptions) {
|
167
166
|
return __awaiter(this, void 0, void 0, function* () {
|
168
|
-
const {
|
167
|
+
const { lookbackSeconds = 5 } = configuration || {};
|
168
|
+
this.log(`waiting for file to be available on session: ${sessionId}`);
|
169
169
|
const startTime = new Date();
|
170
170
|
const timeoutSeconds = (requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) || 120;
|
171
171
|
// Create a promise that resolves to null after the timeout
|
172
172
|
const timeoutPromise = new Promise((resolve) => {
|
173
|
-
setTimeout(() =>
|
173
|
+
setTimeout(() => {
|
174
|
+
this.log(`waiting for file timed out after ${timeoutSeconds} seconds`);
|
175
|
+
resolve(null);
|
176
|
+
}, timeoutSeconds * 1000);
|
174
177
|
});
|
175
178
|
// Create a promise for the event processing
|
176
179
|
const processEventsPromise = (() => __awaiter(this, void 0, void 0, function* () {
|
177
180
|
var _a, e_2, _b, _c;
|
178
|
-
const sessionEvents = yield this.events(sessionId, { all:
|
181
|
+
const sessionEvents = yield this.events(sessionId, { all: lookbackSeconds >= 0 }, Object.assign({ timeoutInSeconds: timeoutSeconds }, (requestOptions || {})));
|
179
182
|
try {
|
180
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) {
|
181
184
|
_c = sessionEvents_2_1.value;
|
@@ -213,16 +216,20 @@ class AirtopSessions extends Client_1.Sessions {
|
|
213
216
|
});
|
214
217
|
}
|
215
218
|
/**
|
216
|
-
* 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.
|
217
222
|
*
|
218
|
-
* @param {
|
219
|
-
* @param {
|
220
|
-
* @param {
|
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.
|
221
226
|
* @param {Sessions.RequestOptions} [requestOptions] - Optional request configuration including timeout
|
222
227
|
* @returns {Promise<{ id: string, downloadUrl: string } | null>} Object containing file's id and downloadUrl, or null if timed out
|
223
228
|
*/
|
224
|
-
waitForDownloadStart(
|
225
|
-
return __awaiter(this,
|
229
|
+
waitForDownloadStart(sessionId, configuration, requestOptions) {
|
230
|
+
return __awaiter(this, void 0, void 0, function* () {
|
231
|
+
const { lookbackSeconds = 5 } = configuration || {};
|
232
|
+
const startTime = new Date();
|
226
233
|
const timeoutSeconds = (requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) || 60;
|
227
234
|
// Create a promise that resolves to null after the timeout
|
228
235
|
const timeoutPromise = new Promise((resolve) => {
|
@@ -231,7 +238,7 @@ class AirtopSessions extends Client_1.Sessions {
|
|
231
238
|
// Create a promise for the event processing
|
232
239
|
const processEventsPromise = (() => __awaiter(this, void 0, void 0, function* () {
|
233
240
|
var _a, e_3, _b, _c;
|
234
|
-
const sessionEvents = yield this.events(sessionId, { all:
|
241
|
+
const sessionEvents = yield this.events(sessionId, { all: lookbackSeconds >= 0 }, Object.assign({ timeoutInSeconds: timeoutSeconds }, (requestOptions || {})));
|
235
242
|
try {
|
236
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) {
|
237
244
|
_c = sessionEvents_3_1.value;
|
@@ -241,6 +248,12 @@ class AirtopSessions extends Client_1.Sessions {
|
|
241
248
|
if (e.event === 'file_status') {
|
242
249
|
this.log(`file_status message received:\n${JSON.stringify(event, null, 2)}`);
|
243
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
|
+
}
|
244
257
|
return {
|
245
258
|
id: e.fileId,
|
246
259
|
downloadUrl: e.downloadUrl,
|
@@ -265,18 +278,20 @@ class AirtopSessions extends Client_1.Sessions {
|
|
265
278
|
/**
|
266
279
|
* Downloads the next file from a session as soon as it starts to become available
|
267
280
|
*
|
268
|
-
* @param {
|
269
|
-
* @param {string}
|
270
|
-
* @param {
|
271
|
-
* @param {function} [
|
272
|
-
* @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`.
|
273
287
|
* @param {Sessions.RequestOptions} [requestOptions] - Optional request configuration including timeout
|
274
288
|
* @throws Error if no file is available to download within the timeout period
|
275
289
|
*/
|
276
|
-
downloadNextFile(
|
277
|
-
return __awaiter(this,
|
278
|
-
var
|
279
|
-
const
|
290
|
+
downloadNextFile(sessionId, destinationPath, configuration, requestOptions) {
|
291
|
+
return __awaiter(this, void 0, void 0, function* () {
|
292
|
+
var _a;
|
293
|
+
const { onProgress = undefined, lookbackSeconds = 5, timeoutSeconds = 120 } = configuration || {};
|
294
|
+
const nextFile = yield this.waitForDownload(sessionId, { lookbackSeconds }, Object.assign({ timeoutInSeconds: timeoutSeconds }, (requestOptions || {})));
|
280
295
|
if (!nextFile) {
|
281
296
|
throw new Error('No file to download within timeout');
|
282
297
|
}
|
@@ -284,7 +299,7 @@ class AirtopSessions extends Client_1.Sessions {
|
|
284
299
|
if (!downloadResponse.ok) {
|
285
300
|
throw new Error(`Failed to download file: ${downloadResponse.statusText}`);
|
286
301
|
}
|
287
|
-
const totalBytes = Number.parseInt((
|
302
|
+
const totalBytes = Number.parseInt((_a = downloadResponse.headers.get('content-length')) !== null && _a !== void 0 ? _a : '0', 10);
|
288
303
|
let downloadedBytes = 0;
|
289
304
|
fs.mkdirSync(path.dirname(destinationPath), { recursive: true });
|
290
305
|
const fileStream = fs.createWriteStream(destinationPath);
|