@ibm-aspera/sdk 0.19.0 → 0.20.0
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/commonjs/app/core.d.ts +43 -17
- package/dist/commonjs/app/core.js +144 -28
- package/dist/commonjs/app/status.d.ts +11 -1
- package/dist/commonjs/app/status.js +35 -4
- package/dist/commonjs/connect/core.js +3 -0
- package/dist/commonjs/helpers/connect-extension.d.ts +8 -0
- package/dist/commonjs/helpers/connect-extension.js +58 -0
- package/dist/commonjs/helpers/helpers.d.ts +6 -0
- package/dist/commonjs/helpers/helpers.js +19 -1
- package/dist/commonjs/helpers/ws.d.ts +16 -0
- package/dist/commonjs/helpers/ws.js +49 -2
- package/dist/commonjs/http-gateway/core.js +10 -12
- package/dist/commonjs/http-gateway/download.js +2 -2
- package/dist/commonjs/http-gateway/upload.js +2 -2
- package/dist/commonjs/http-gateway/v2/app/core.d.ts +84 -0
- package/dist/commonjs/http-gateway/v2/app/core.js +170 -0
- package/dist/commonjs/http-gateway/v2/app/download.d.ts +15 -0
- package/dist/commonjs/http-gateway/v2/app/download.js +68 -0
- package/dist/commonjs/http-gateway/v2/app/upload.d.ts +169 -0
- package/dist/commonjs/http-gateway/v2/app/upload.js +601 -0
- package/dist/commonjs/http-gateway/v2/constants/constants.d.ts +6 -0
- package/dist/commonjs/http-gateway/v2/constants/constants.js +9 -0
- package/dist/commonjs/http-gateway/v2/constants/messages.d.ts +35 -0
- package/dist/commonjs/http-gateway/v2/constants/messages.js +38 -0
- package/dist/commonjs/http-gateway/v2/helpers/helpers.d.ts +121 -0
- package/dist/commonjs/http-gateway/v2/helpers/helpers.js +294 -0
- package/dist/commonjs/http-gateway/v2/helpers/http.d.ts +86 -0
- package/dist/commonjs/http-gateway/v2/helpers/http.js +153 -0
- package/dist/commonjs/http-gateway/v2/index.d.ts +35 -0
- package/dist/commonjs/http-gateway/v2/index.js +70 -0
- package/dist/commonjs/http-gateway/v2/models/http-gateway-global.model.d.ts +254 -0
- package/dist/commonjs/http-gateway/v2/models/http-gateway-global.model.js +367 -0
- package/dist/commonjs/http-gateway/v2/models/models.d.ts +127 -0
- package/dist/commonjs/http-gateway/v2/models/models.js +87 -0
- package/dist/commonjs/index.d.ts +3 -3
- package/dist/commonjs/index.js +3 -1
- package/dist/commonjs/models/aspera-sdk.model.d.ts +2 -1
- package/dist/commonjs/models/aspera-sdk.model.js +8 -0
- package/dist/commonjs/models/models.d.ts +10 -1
- package/dist/js/aspera-sdk.js +1 -1
- package/dist/js/aspera-sdk.js.LICENSE.txt +1 -1
- package/dist/js/aspera-sdk.js.map +1 -1
- package/package.json +1 -2
- package/scripts/release.sh +7 -7
- package/scripts/version.sh +24 -15
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.safeJsonParse = exports.safeJsonString = exports.getInstallerUrls = exports.isSafari = exports.isValidURL = exports.throwError = exports.randomUUID = exports.getCurrentPlatform = exports.getWebsocketUrl = exports.isValidTransferSpec = exports.generateErrorBody = exports.errorLog = exports.generatePromiseObjects = void 0;
|
|
3
|
+
exports.withTimeout = exports.safeJsonParse = exports.safeJsonString = exports.getInstallerUrls = exports.isSafari = exports.isValidURL = exports.throwError = exports.randomUUID = exports.getCurrentPlatform = exports.getWebsocketUrl = exports.isValidTransferSpec = exports.generateErrorBody = exports.errorLog = exports.generatePromiseObjects = void 0;
|
|
4
4
|
var constants_1 = require("../constants/constants");
|
|
5
5
|
/**
|
|
6
6
|
* Generates promise object that can be resolved or rejected via functions
|
|
@@ -232,6 +232,23 @@ var safeJsonParse = function (json) {
|
|
|
232
232
|
}
|
|
233
233
|
};
|
|
234
234
|
exports.safeJsonParse = safeJsonParse;
|
|
235
|
+
/**
|
|
236
|
+
* Race a promise against a timeout. Rejects with an Error('timeout') if the
|
|
237
|
+
* given milliseconds elapse before the promise settles.
|
|
238
|
+
*/
|
|
239
|
+
var withTimeout = function (promise, ms) {
|
|
240
|
+
return new Promise(function (resolve, reject) {
|
|
241
|
+
var timer = setTimeout(function () { return reject(new Error('timeout')); }, ms);
|
|
242
|
+
promise.then(function (val) {
|
|
243
|
+
clearTimeout(timer);
|
|
244
|
+
resolve(val);
|
|
245
|
+
}, function (err) {
|
|
246
|
+
clearTimeout(timer);
|
|
247
|
+
reject(err);
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
};
|
|
251
|
+
exports.withTimeout = withTimeout;
|
|
235
252
|
exports.default = {
|
|
236
253
|
errorLog: exports.errorLog,
|
|
237
254
|
generateErrorBody: exports.generateErrorBody,
|
|
@@ -246,4 +263,5 @@ exports.default = {
|
|
|
246
263
|
getInstallerUrls: exports.getInstallerUrls,
|
|
247
264
|
safeJsonString: exports.safeJsonString,
|
|
248
265
|
safeJsonParse: exports.safeJsonParse,
|
|
266
|
+
withTimeout: exports.withTimeout,
|
|
249
267
|
};
|
|
@@ -8,6 +8,12 @@ export declare class WebsocketService {
|
|
|
8
8
|
private eventListener;
|
|
9
9
|
/** Indicator if the websocket is already connected */
|
|
10
10
|
private isConnected;
|
|
11
|
+
/** When true, the reconnect loop is suppressed */
|
|
12
|
+
private stopped;
|
|
13
|
+
/** When true, the connection/reconnect loop is already running */
|
|
14
|
+
private active;
|
|
15
|
+
/** ID of the pending reconnect timer (so it can be cancelled) */
|
|
16
|
+
private reconnectTimerId;
|
|
11
17
|
/** Global promise object that resolves when init completes */
|
|
12
18
|
private initPromise;
|
|
13
19
|
/** Log call for not being ready */
|
|
@@ -52,7 +58,17 @@ export declare class WebsocketService {
|
|
|
52
58
|
* @returns a promise that resolves when the websocket connection is established
|
|
53
59
|
*/
|
|
54
60
|
init(): Promise<unknown>;
|
|
61
|
+
/**
|
|
62
|
+
* Stop the WebSocket connection and suppress the automatic reconnect loop.
|
|
63
|
+
* Used when falling back to a different transfer client (e.g. Connect).
|
|
64
|
+
*/
|
|
65
|
+
disconnect(): void;
|
|
55
66
|
private connect;
|
|
67
|
+
/**
|
|
68
|
+
* Detach event handlers from the current socket so it cannot fire
|
|
69
|
+
* stale CLOSED/RECONNECT events after being replaced.
|
|
70
|
+
*/
|
|
71
|
+
private detachSocket;
|
|
56
72
|
private reconnect;
|
|
57
73
|
private getWebSocketConnection;
|
|
58
74
|
private notifyEvent;
|
|
@@ -11,6 +11,12 @@ var WebsocketService = /** @class */ (function () {
|
|
|
11
11
|
this.sockets = new Map();
|
|
12
12
|
/** Indicator if the websocket is already connected */
|
|
13
13
|
this.isConnected = false;
|
|
14
|
+
/** When true, the reconnect loop is suppressed */
|
|
15
|
+
this.stopped = false;
|
|
16
|
+
/** When true, the connection/reconnect loop is already running */
|
|
17
|
+
this.active = false;
|
|
18
|
+
/** ID of the pending reconnect timer (so it can be cancelled) */
|
|
19
|
+
this.reconnectTimerId = null;
|
|
14
20
|
/** Global promise object that resolves when init completes */
|
|
15
21
|
this.initPromise = (0, helpers_1.generatePromiseObjects)();
|
|
16
22
|
/**
|
|
@@ -104,11 +110,35 @@ var WebsocketService = /** @class */ (function () {
|
|
|
104
110
|
* @returns a promise that resolves when the websocket connection is established
|
|
105
111
|
*/
|
|
106
112
|
WebsocketService.prototype.init = function () {
|
|
107
|
-
this.
|
|
113
|
+
this.stopped = false;
|
|
114
|
+
if (!this.active) {
|
|
115
|
+
this.active = true;
|
|
116
|
+
this.connect();
|
|
117
|
+
}
|
|
108
118
|
return this.initPromise.promise;
|
|
109
119
|
};
|
|
120
|
+
/**
|
|
121
|
+
* Stop the WebSocket connection and suppress the automatic reconnect loop.
|
|
122
|
+
* Used when falling back to a different transfer client (e.g. Connect).
|
|
123
|
+
*/
|
|
124
|
+
WebsocketService.prototype.disconnect = function () {
|
|
125
|
+
this.stopped = true;
|
|
126
|
+
this.active = false;
|
|
127
|
+
if (this.reconnectTimerId) {
|
|
128
|
+
clearTimeout(this.reconnectTimerId);
|
|
129
|
+
this.reconnectTimerId = null;
|
|
130
|
+
}
|
|
131
|
+
this.detachSocket();
|
|
132
|
+
if (this.globalSocket) {
|
|
133
|
+
this.globalSocket.close();
|
|
134
|
+
this.globalSocket = null;
|
|
135
|
+
}
|
|
136
|
+
this.isConnected = false;
|
|
137
|
+
this.initPromise = (0, helpers_1.generatePromiseObjects)();
|
|
138
|
+
};
|
|
110
139
|
WebsocketService.prototype.connect = function () {
|
|
111
140
|
var _this = this;
|
|
141
|
+
this.detachSocket();
|
|
112
142
|
this.getWebSocketConnection(index_1.asperaSdk.globals.rpcPort)
|
|
113
143
|
.then(function (webSocket) {
|
|
114
144
|
_this.globalSocket = webSocket;
|
|
@@ -121,12 +151,29 @@ var WebsocketService = /** @class */ (function () {
|
|
|
121
151
|
_this.reconnect();
|
|
122
152
|
});
|
|
123
153
|
};
|
|
154
|
+
/**
|
|
155
|
+
* Detach event handlers from the current socket so it cannot fire
|
|
156
|
+
* stale CLOSED/RECONNECT events after being replaced.
|
|
157
|
+
*/
|
|
158
|
+
WebsocketService.prototype.detachSocket = function () {
|
|
159
|
+
if (this.globalSocket) {
|
|
160
|
+
this.globalSocket.onopen = null;
|
|
161
|
+
this.globalSocket.onclose = null;
|
|
162
|
+
this.globalSocket.onerror = null;
|
|
163
|
+
this.globalSocket.onmessage = null;
|
|
164
|
+
}
|
|
165
|
+
};
|
|
124
166
|
WebsocketService.prototype.reconnect = function () {
|
|
125
167
|
var _this = this;
|
|
168
|
+
if (this.stopped) {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
this.detachSocket();
|
|
126
172
|
if (this.globalSocket) {
|
|
127
173
|
this.globalSocket.close();
|
|
128
174
|
}
|
|
129
|
-
setTimeout(function () {
|
|
175
|
+
this.reconnectTimerId = setTimeout(function () {
|
|
176
|
+
_this.reconnectTimerId = null;
|
|
130
177
|
_this.connect();
|
|
131
178
|
}, 1000);
|
|
132
179
|
};
|
|
@@ -4,7 +4,7 @@ exports.httpGatewayReadChunkAsArrayBuffer = exports.httpGatewayReadAsArrayBuffer
|
|
|
4
4
|
var messages_1 = require("../constants/messages");
|
|
5
5
|
var helpers_1 = require("../helpers/helpers");
|
|
6
6
|
var index_1 = require("../index");
|
|
7
|
-
var
|
|
7
|
+
var v2_1 = require("./v2");
|
|
8
8
|
// Maximum file size for generating image previews for files. 50MiB matches the limits in both Connect and IBM Aspera for desktop.
|
|
9
9
|
var MAX_FILE_SIZE = 50 * 1024 * 1024;
|
|
10
10
|
/**
|
|
@@ -45,17 +45,14 @@ var initHttpGateway = function (response) {
|
|
|
45
45
|
index_1.asperaSdk.globals.httpGatewayRoutePrefix = majorVersion >= 3 ? '/v3' : '';
|
|
46
46
|
if (index_1.asperaSdk.useOldHttpGateway) {
|
|
47
47
|
// Watch for old HTTP Gateway transfers in case used.
|
|
48
|
-
(0,
|
|
48
|
+
(0, v2_1.registerActivityCallback)(function (oldHttpTransfers) {
|
|
49
49
|
oldHttpTransfers.transfers.forEach(function (oldHttpTransfer) {
|
|
50
50
|
var transfer = oldHttpTransfer;
|
|
51
|
-
|
|
52
|
-
if (transfer.status === 'canceled') {
|
|
53
|
-
transfer.status = 'cancelled';
|
|
54
|
-
}
|
|
51
|
+
transfer.transfer_client = 'http-gateway';
|
|
55
52
|
(0, exports.sendTransferUpdate)(transfer);
|
|
56
53
|
});
|
|
57
54
|
});
|
|
58
|
-
return (0,
|
|
55
|
+
return (0, v2_1.initHttpGateway)(index_1.asperaSdk.globals.httpGatewayUrl).then(function () { });
|
|
59
56
|
}
|
|
60
57
|
var iframeContainer = document.createElement('div');
|
|
61
58
|
iframeContainer.id = 'aspera-http-gateway-iframes';
|
|
@@ -107,7 +104,7 @@ exports.setupHttpGateway = setupHttpGateway;
|
|
|
107
104
|
*/
|
|
108
105
|
var httpStopTransfer = function (id) {
|
|
109
106
|
if (index_1.asperaSdk.useOldHttpGateway) {
|
|
110
|
-
(0,
|
|
107
|
+
(0, v2_1.cancelTransfer)(id);
|
|
111
108
|
return Promise.resolve();
|
|
112
109
|
}
|
|
113
110
|
var transfer = index_1.asperaSdk.httpGatewayTransferStore.get(id);
|
|
@@ -135,7 +132,7 @@ exports.httpStopTransfer = httpStopTransfer;
|
|
|
135
132
|
*/
|
|
136
133
|
var httpRemoveTransfer = function (id) {
|
|
137
134
|
if (index_1.asperaSdk.useOldHttpGateway) {
|
|
138
|
-
(0,
|
|
135
|
+
(0, v2_1.removeTransfer)(id);
|
|
139
136
|
return Promise.resolve({ removed: true });
|
|
140
137
|
}
|
|
141
138
|
/* Cancel the transfer before removing it.
|
|
@@ -159,7 +156,7 @@ exports.httpRemoveTransfer = httpRemoveTransfer;
|
|
|
159
156
|
*/
|
|
160
157
|
var httpGetAllTransfers = function () {
|
|
161
158
|
if (index_1.asperaSdk.useOldHttpGateway) {
|
|
162
|
-
return (0,
|
|
159
|
+
return (0, v2_1.getAllTransfers)().transfers;
|
|
163
160
|
}
|
|
164
161
|
return Array.from(index_1.asperaSdk.httpGatewayTransferStore.values());
|
|
165
162
|
};
|
|
@@ -171,7 +168,7 @@ exports.httpGetAllTransfers = httpGetAllTransfers;
|
|
|
171
168
|
*/
|
|
172
169
|
var httpGetTransfer = function (id) {
|
|
173
170
|
if (index_1.asperaSdk.useOldHttpGateway) {
|
|
174
|
-
return (0,
|
|
171
|
+
return (0, v2_1.getTransferById)(id);
|
|
175
172
|
}
|
|
176
173
|
return index_1.asperaSdk.httpGatewayTransferStore.get(id);
|
|
177
174
|
};
|
|
@@ -251,7 +248,7 @@ exports.handleHttpGatewayDrop = handleHttpGatewayDrop;
|
|
|
251
248
|
*/
|
|
252
249
|
var httpGatewaySelectFileFolderDialog = function (options, folder) {
|
|
253
250
|
if (index_1.asperaSdk.useOldHttpGateway) {
|
|
254
|
-
return (folder ? (0,
|
|
251
|
+
return (folder ? (0, v2_1.getFoldersForUploadPromise)((options === null || options === void 0 ? void 0 : options.http_gateway_v2_transfer_id) || '') : (0, v2_1.getFilesForUploadPromise)((options === null || options === void 0 ? void 0 : options.http_gateway_v2_transfer_id) || ''));
|
|
255
252
|
}
|
|
256
253
|
var _a = (0, helpers_1.generatePromiseObjects)(), promise = _a.promise, rejecter = _a.rejecter, resolver = _a.resolver;
|
|
257
254
|
var element = (0, exports.createHtmlInputElement)();
|
|
@@ -315,6 +312,7 @@ var getSdkTransfer = function (transferSpec) {
|
|
|
315
312
|
percentage: 0,
|
|
316
313
|
title: '',
|
|
317
314
|
remaining_usec: 0,
|
|
315
|
+
transfer_client: 'http-gateway',
|
|
318
316
|
httpGatewayTransfer: true,
|
|
319
317
|
httpDownloadExternalHandle: false,
|
|
320
318
|
};
|
|
@@ -5,7 +5,7 @@ var index_1 = require("../index");
|
|
|
5
5
|
var helpers_1 = require("../helpers/helpers");
|
|
6
6
|
var messages_1 = require("../constants/messages");
|
|
7
7
|
var core_1 = require("./core");
|
|
8
|
-
var
|
|
8
|
+
var v2_1 = require("./v2");
|
|
9
9
|
/**
|
|
10
10
|
* HTTP Gateway Download Logic for presigned flow
|
|
11
11
|
* Presigned flow is when used files are too large or unknown file size
|
|
@@ -173,7 +173,7 @@ var httpDownload = function (transferSpec, asperaSdkSpec) {
|
|
|
173
173
|
return (0, helpers_1.throwError)(messages_1.messages.serverNotVerified, { type: 'download' });
|
|
174
174
|
}
|
|
175
175
|
if (index_1.asperaSdk.useOldHttpGateway) {
|
|
176
|
-
return (0,
|
|
176
|
+
return (0, v2_1.download)(transferSpec);
|
|
177
177
|
}
|
|
178
178
|
if (transferSpec.tags &&
|
|
179
179
|
transferSpec.tags.aspera &&
|
|
@@ -5,7 +5,7 @@ var index_1 = require("../index");
|
|
|
5
5
|
var helpers_1 = require("../helpers/helpers");
|
|
6
6
|
var messages_1 = require("../constants/messages");
|
|
7
7
|
var core_1 = require("./core");
|
|
8
|
-
var
|
|
8
|
+
var v2_1 = require("./v2");
|
|
9
9
|
/**
|
|
10
10
|
* HTTP Gateway Upload Logic
|
|
11
11
|
*
|
|
@@ -23,7 +23,7 @@ var httpUpload = function (transferSpec, asperaSdkSpec) {
|
|
|
23
23
|
return (0, helpers_1.throwError)(messages_1.messages.serverNotVerified, { type: 'upload' });
|
|
24
24
|
}
|
|
25
25
|
if (index_1.asperaSdk.useOldHttpGateway) {
|
|
26
|
-
return (0,
|
|
26
|
+
return (0, v2_1.upload)(transferSpec, (asperaSdkSpec === null || asperaSdkSpec === void 0 ? void 0 : asperaSdkSpec.http_gateway_v2_transfer_id) || '');
|
|
27
27
|
}
|
|
28
28
|
var promiseInfo = (0, helpers_1.generatePromiseObjects)();
|
|
29
29
|
var request = new XMLHttpRequest();
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { TransferResponse } from '../models/http-gateway-global.model';
|
|
2
|
+
import { HttpTransfer } from '../models/models';
|
|
3
|
+
/**
|
|
4
|
+
* Check if HTTP Gateway server connection works. This function is called by init
|
|
5
|
+
* when initializing the SDK. This function can be used at any point for sanity checking.
|
|
6
|
+
*
|
|
7
|
+
* @returns promise that resolves if server can connect or rejects if server unable to connect
|
|
8
|
+
*/
|
|
9
|
+
export declare const testHttpGatewayConnection: () => Promise<any>;
|
|
10
|
+
export declare const cleanupServerUrl: (serverUrl: string) => string;
|
|
11
|
+
/**
|
|
12
|
+
* Initialize HTTP gateway client. If client cannot (reject/catch)
|
|
13
|
+
* client should attempt fixing server URL or trying again. If still fails disable UI elements.
|
|
14
|
+
* If supportMultipleServers is used the failure of the first test will not lock out the SDK.
|
|
15
|
+
*
|
|
16
|
+
* @param serverUrl URL indicating location of the HTTP server
|
|
17
|
+
* @param softwareMode indicate if the SDK should run in software mode instead of DOM mode
|
|
18
|
+
* @param supportMultipleServers indicates if the SDK should support multiple servers (not restricting to setup server)
|
|
19
|
+
*
|
|
20
|
+
* @returns a promise that resolves if HTTP Gateway is running properly or rejects if unable to load
|
|
21
|
+
*/
|
|
22
|
+
export declare const initHttpGateway: (serverUrl: string, softwareMode?: boolean, supportMultipleServers?: boolean) => Promise<any>;
|
|
23
|
+
/**
|
|
24
|
+
* Register a callback event for getting transfer data
|
|
25
|
+
*
|
|
26
|
+
* @param callback callback function to receive transfers
|
|
27
|
+
*
|
|
28
|
+
* @returns ID representing the callback for deregistration purposes
|
|
29
|
+
*/
|
|
30
|
+
export declare const registerActivityCallback: (callback: (transfers: TransferResponse) => void) => string;
|
|
31
|
+
/**
|
|
32
|
+
* Remove a callback from the transfer callback
|
|
33
|
+
* @param id the ID returned by `registerActivityCallback`
|
|
34
|
+
*/
|
|
35
|
+
export declare const deregisterActivityCallback: (id: string) => void;
|
|
36
|
+
/**
|
|
37
|
+
* Returns the transfer requested based on the uuid of the transfer.
|
|
38
|
+
* NOTE: transferId from Node is not accepted as an ID. It must be the ID used by the HTTP Gateway.
|
|
39
|
+
*
|
|
40
|
+
* @param id gateway based ID of the HTTP part of the transfer
|
|
41
|
+
*
|
|
42
|
+
* @returns an object containing the transfer (or undefined if not found) located at key `transfer_info`
|
|
43
|
+
*/
|
|
44
|
+
export declare const getTransferById: (id: string) => {
|
|
45
|
+
transfer_info: HttpTransfer;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Get transfer response object including all transfers
|
|
49
|
+
*
|
|
50
|
+
* @returns transfer data object with transfers array
|
|
51
|
+
*/
|
|
52
|
+
export declare const getAllTransfers: () => TransferResponse;
|
|
53
|
+
/**
|
|
54
|
+
* Remove all transfers that are not active
|
|
55
|
+
*/
|
|
56
|
+
export declare const clearNonActiveTransfers: () => void;
|
|
57
|
+
/**
|
|
58
|
+
* Removes a transfer from the transfers list in HTTP Gateway
|
|
59
|
+
* If an active transfer is removed it will continue to be uploaded/downloaded but progress will not be tracked
|
|
60
|
+
*
|
|
61
|
+
* @param id HTTP Gateway transfer uuid
|
|
62
|
+
*/
|
|
63
|
+
export declare const removeTransfer: (id: string) => void;
|
|
64
|
+
/**
|
|
65
|
+
* Cancel a transfer from the transfers list in HTTP Gateway
|
|
66
|
+
*
|
|
67
|
+
* @param id HTTP Gateway transfer uuid
|
|
68
|
+
*/
|
|
69
|
+
export declare const cancelTransfer: (id: string) => void;
|
|
70
|
+
declare const _default: {
|
|
71
|
+
initHttpGateway: (serverUrl: string, softwareMode?: boolean, supportMultipleServers?: boolean) => Promise<any>;
|
|
72
|
+
testHttpGatewayConnection: () => Promise<any>;
|
|
73
|
+
registerActivityCallback: (callback: (transfers: TransferResponse) => void) => string;
|
|
74
|
+
cleanupServerUrl: (serverUrl: string) => string;
|
|
75
|
+
deregisterActivityCallback: (id: string) => void;
|
|
76
|
+
getTransferById: (id: string) => {
|
|
77
|
+
transfer_info: HttpTransfer;
|
|
78
|
+
};
|
|
79
|
+
getAllTransfers: () => TransferResponse;
|
|
80
|
+
clearNonActiveTransfers: () => void;
|
|
81
|
+
removeTransfer: (id: string) => void;
|
|
82
|
+
cancelTransfer: (id: string) => void;
|
|
83
|
+
};
|
|
84
|
+
export default _default;
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.cancelTransfer = exports.removeTransfer = exports.clearNonActiveTransfers = exports.getAllTransfers = exports.getTransferById = exports.deregisterActivityCallback = exports.registerActivityCallback = exports.initHttpGateway = exports.cleanupServerUrl = exports.testHttpGatewayConnection = void 0;
|
|
4
|
+
var index_1 = require("../index");
|
|
5
|
+
var helpers_1 = require("../helpers/helpers");
|
|
6
|
+
var messages_1 = require("../constants/messages");
|
|
7
|
+
var http_1 = require("../helpers/http");
|
|
8
|
+
/**
|
|
9
|
+
* Check if HTTP Gateway server connection works. This function is called by init
|
|
10
|
+
* when initializing the SDK. This function can be used at any point for sanity checking.
|
|
11
|
+
*
|
|
12
|
+
* @returns promise that resolves if server can connect or rejects if server unable to connect
|
|
13
|
+
*/
|
|
14
|
+
var testHttpGatewayConnection = function () {
|
|
15
|
+
if (!index_1.asperaHttpGateway.globals.serverUrl && !index_1.asperaHttpGateway.globals.supportMultipleServers) {
|
|
16
|
+
(0, helpers_1.errorLog)(messages_1.messages.serverUrlNotSet);
|
|
17
|
+
return new Promise(function (resolve, reject) {
|
|
18
|
+
reject((0, helpers_1.generateErrorBody)(messages_1.messages.serverUrlNotSet));
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
var promiseInfo = (0, helpers_1.generatePromiseObjects)();
|
|
22
|
+
var backupServerData = {
|
|
23
|
+
endpoints: [
|
|
24
|
+
'/aspera/http-gwy/v1/info',
|
|
25
|
+
'/aspera/http-gwy/v1/upload',
|
|
26
|
+
'/aspera/http-gwy/v2/upload',
|
|
27
|
+
'/aspera/http-gwy/v1/download'
|
|
28
|
+
],
|
|
29
|
+
name: 'IBM Aspera HTTP Gateway',
|
|
30
|
+
version: '2.3.0',
|
|
31
|
+
sdkVerificationFailed: true,
|
|
32
|
+
};
|
|
33
|
+
(0, http_1.apiGet)("".concat(index_1.asperaHttpGateway.globals.serverUrl || '', "/v1/info")).then(function (response) {
|
|
34
|
+
response.json().then(function (data) {
|
|
35
|
+
index_1.asperaHttpGateway.globals.serverInfo = data;
|
|
36
|
+
index_1.asperaHttpGateway.globals.serverVerified = true;
|
|
37
|
+
if (Number(index_1.asperaHttpGateway.globals.serverInfo.version.split('.')[0] || 0) >= 3) {
|
|
38
|
+
promiseInfo.rejecter((0, helpers_1.generateErrorBody)(messages_1.messages.versionNotsupported, data));
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
console.warn(messages_1.messages.deprecationWarning);
|
|
42
|
+
promiseInfo.resolver(data);
|
|
43
|
+
});
|
|
44
|
+
}).catch(function (error) {
|
|
45
|
+
(0, helpers_1.errorLog)(messages_1.messages.serverError, error);
|
|
46
|
+
if (index_1.asperaHttpGateway.globals.supportMultipleServers) {
|
|
47
|
+
index_1.asperaHttpGateway.globals.serverInfo = backupServerData;
|
|
48
|
+
index_1.asperaHttpGateway.globals.serverVerified = true;
|
|
49
|
+
promiseInfo.resolver(backupServerData);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
index_1.asperaHttpGateway.globals.serverVerified = false;
|
|
53
|
+
promiseInfo.rejecter((0, helpers_1.generateErrorBody)(messages_1.messages.serverError, error));
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
return promiseInfo.promise;
|
|
57
|
+
};
|
|
58
|
+
exports.testHttpGatewayConnection = testHttpGatewayConnection;
|
|
59
|
+
var cleanupServerUrl = function (serverUrl) {
|
|
60
|
+
if (typeof serverUrl !== 'string') {
|
|
61
|
+
return '';
|
|
62
|
+
}
|
|
63
|
+
if (serverUrl[serverUrl.length - 1] === '/') {
|
|
64
|
+
serverUrl = serverUrl.slice(0, -1);
|
|
65
|
+
}
|
|
66
|
+
return serverUrl.replace('/v1', '/').replace(/\/$/, '').replace(/\/$/, '');
|
|
67
|
+
};
|
|
68
|
+
exports.cleanupServerUrl = cleanupServerUrl;
|
|
69
|
+
/**
|
|
70
|
+
* Initialize HTTP gateway client. If client cannot (reject/catch)
|
|
71
|
+
* client should attempt fixing server URL or trying again. If still fails disable UI elements.
|
|
72
|
+
* If supportMultipleServers is used the failure of the first test will not lock out the SDK.
|
|
73
|
+
*
|
|
74
|
+
* @param serverUrl URL indicating location of the HTTP server
|
|
75
|
+
* @param softwareMode indicate if the SDK should run in software mode instead of DOM mode
|
|
76
|
+
* @param supportMultipleServers indicates if the SDK should support multiple servers (not restricting to setup server)
|
|
77
|
+
*
|
|
78
|
+
* @returns a promise that resolves if HTTP Gateway is running properly or rejects if unable to load
|
|
79
|
+
*/
|
|
80
|
+
var initHttpGateway = function (serverUrl, softwareMode, supportMultipleServers) {
|
|
81
|
+
if (!(0, helpers_1.isValidUrl)(serverUrl)) {
|
|
82
|
+
return new Promise(function (resolve, reject) {
|
|
83
|
+
reject((0, helpers_1.generateErrorBody)(messages_1.messages.invalidServerUrl));
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
index_1.asperaHttpGateway.globals.setUpServer((0, exports.cleanupServerUrl)(serverUrl), softwareMode, supportMultipleServers);
|
|
87
|
+
return (0, exports.testHttpGatewayConnection)();
|
|
88
|
+
};
|
|
89
|
+
exports.initHttpGateway = initHttpGateway;
|
|
90
|
+
/**
|
|
91
|
+
* Register a callback event for getting transfer data
|
|
92
|
+
*
|
|
93
|
+
* @param callback callback function to receive transfers
|
|
94
|
+
*
|
|
95
|
+
* @returns ID representing the callback for deregistration purposes
|
|
96
|
+
*/
|
|
97
|
+
var registerActivityCallback = function (callback) {
|
|
98
|
+
return index_1.asperaHttpGateway.activityTracking.setCallback(callback);
|
|
99
|
+
};
|
|
100
|
+
exports.registerActivityCallback = registerActivityCallback;
|
|
101
|
+
/**
|
|
102
|
+
* Remove a callback from the transfer callback
|
|
103
|
+
* @param id the ID returned by `registerActivityCallback`
|
|
104
|
+
*/
|
|
105
|
+
var deregisterActivityCallback = function (id) {
|
|
106
|
+
index_1.asperaHttpGateway.activityTracking.removeCallback(id);
|
|
107
|
+
};
|
|
108
|
+
exports.deregisterActivityCallback = deregisterActivityCallback;
|
|
109
|
+
/**
|
|
110
|
+
* Returns the transfer requested based on the uuid of the transfer.
|
|
111
|
+
* NOTE: transferId from Node is not accepted as an ID. It must be the ID used by the HTTP Gateway.
|
|
112
|
+
*
|
|
113
|
+
* @param id gateway based ID of the HTTP part of the transfer
|
|
114
|
+
*
|
|
115
|
+
* @returns an object containing the transfer (or undefined if not found) located at key `transfer_info`
|
|
116
|
+
*/
|
|
117
|
+
var getTransferById = function (id) {
|
|
118
|
+
return { transfer_info: index_1.asperaHttpGateway.activityTracking.getTransferById(id) };
|
|
119
|
+
};
|
|
120
|
+
exports.getTransferById = getTransferById;
|
|
121
|
+
/**
|
|
122
|
+
* Get transfer response object including all transfers
|
|
123
|
+
*
|
|
124
|
+
* @returns transfer data object with transfers array
|
|
125
|
+
*/
|
|
126
|
+
var getAllTransfers = function () {
|
|
127
|
+
return index_1.asperaHttpGateway.activityTracking.getAllTransfersResponse();
|
|
128
|
+
};
|
|
129
|
+
exports.getAllTransfers = getAllTransfers;
|
|
130
|
+
/**
|
|
131
|
+
* Remove all transfers that are not active
|
|
132
|
+
*/
|
|
133
|
+
var clearNonActiveTransfers = function () {
|
|
134
|
+
index_1.asperaHttpGateway.activityTracking.clearNonActiveTransfers();
|
|
135
|
+
};
|
|
136
|
+
exports.clearNonActiveTransfers = clearNonActiveTransfers;
|
|
137
|
+
/**
|
|
138
|
+
* Removes a transfer from the transfers list in HTTP Gateway
|
|
139
|
+
* If an active transfer is removed it will continue to be uploaded/downloaded but progress will not be tracked
|
|
140
|
+
*
|
|
141
|
+
* @param id HTTP Gateway transfer uuid
|
|
142
|
+
*/
|
|
143
|
+
var removeTransfer = function (id) {
|
|
144
|
+
index_1.asperaHttpGateway.activityTracking.removeTransfer(id);
|
|
145
|
+
};
|
|
146
|
+
exports.removeTransfer = removeTransfer;
|
|
147
|
+
/**
|
|
148
|
+
* Cancel a transfer from the transfers list in HTTP Gateway
|
|
149
|
+
*
|
|
150
|
+
* @param id HTTP Gateway transfer uuid
|
|
151
|
+
*/
|
|
152
|
+
var cancelTransfer = function (id) {
|
|
153
|
+
var transfer = index_1.asperaHttpGateway.activityTracking.getTransferById(id);
|
|
154
|
+
if (transfer) {
|
|
155
|
+
transfer.status = 'cancelled';
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
exports.cancelTransfer = cancelTransfer;
|
|
159
|
+
exports.default = {
|
|
160
|
+
initHttpGateway: exports.initHttpGateway,
|
|
161
|
+
testHttpGatewayConnection: exports.testHttpGatewayConnection,
|
|
162
|
+
registerActivityCallback: exports.registerActivityCallback,
|
|
163
|
+
cleanupServerUrl: exports.cleanupServerUrl,
|
|
164
|
+
deregisterActivityCallback: exports.deregisterActivityCallback,
|
|
165
|
+
getTransferById: exports.getTransferById,
|
|
166
|
+
getAllTransfers: exports.getAllTransfers,
|
|
167
|
+
clearNonActiveTransfers: exports.clearNonActiveTransfers,
|
|
168
|
+
removeTransfer: exports.removeTransfer,
|
|
169
|
+
cancelTransfer: exports.cancelTransfer
|
|
170
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { DownloadOptions, TransferSpec } from '../models/models';
|
|
2
|
+
/**
|
|
3
|
+
* Start a HTTP Gateway download. Progress is not provided on downloads, browser handles download directly
|
|
4
|
+
* When in software mode the promise will return transfer_spec_id and the URL. The URL has not been used
|
|
5
|
+
* therefore a client can open it and start the download using software specific methods (like file reader).
|
|
6
|
+
*
|
|
7
|
+
* @param transferSpec standard Connect transferSpec for downloading
|
|
8
|
+
*
|
|
9
|
+
* @returns a promise that resolves if download is started successfully or rejects if error occurs
|
|
10
|
+
*/
|
|
11
|
+
export declare const download: (transferSpec: TransferSpec, options?: DownloadOptions) => Promise<any>;
|
|
12
|
+
declare const _default: {
|
|
13
|
+
download: (transferSpec: TransferSpec, options?: DownloadOptions) => Promise<any>;
|
|
14
|
+
};
|
|
15
|
+
export default _default;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.download = void 0;
|
|
4
|
+
var http_1 = require("../helpers/http");
|
|
5
|
+
var index_1 = require("../index");
|
|
6
|
+
var helpers_1 = require("../helpers/helpers");
|
|
7
|
+
var messages_1 = require("../constants/messages");
|
|
8
|
+
var core_1 = require("./core");
|
|
9
|
+
/**
|
|
10
|
+
* Start a HTTP Gateway download. Progress is not provided on downloads, browser handles download directly
|
|
11
|
+
* When in software mode the promise will return transfer_spec_id and the URL. The URL has not been used
|
|
12
|
+
* therefore a client can open it and start the download using software specific methods (like file reader).
|
|
13
|
+
*
|
|
14
|
+
* @param transferSpec standard Connect transferSpec for downloading
|
|
15
|
+
*
|
|
16
|
+
* @returns a promise that resolves if download is started successfully or rejects if error occurs
|
|
17
|
+
*/
|
|
18
|
+
var download = function (transferSpec, options) {
|
|
19
|
+
if (options === void 0) { options = {}; }
|
|
20
|
+
if (!index_1.asperaHttpGateway.isReady) {
|
|
21
|
+
(0, helpers_1.errorLog)(messages_1.messages.serverNotVerified);
|
|
22
|
+
return new Promise(function (resolve, reject) {
|
|
23
|
+
reject((0, helpers_1.generateErrorBody)(messages_1.messages.serverNotVerified));
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
if (!(0, helpers_1.isValidTransferSpec)(transferSpec)) {
|
|
27
|
+
(0, helpers_1.errorLog)(messages_1.messages.notValidTransferSpec);
|
|
28
|
+
return new Promise(function (resolve, reject) {
|
|
29
|
+
reject((0, helpers_1.generateErrorBody)(messages_1.messages.notValidTransferSpec, { transferSpec: transferSpec }));
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
var promiseInfo = (0, helpers_1.generatePromiseObjects)();
|
|
33
|
+
if (typeof options.zipRequire === 'boolean') {
|
|
34
|
+
transferSpec.zip_required = options.zipRequire;
|
|
35
|
+
}
|
|
36
|
+
var payload = {
|
|
37
|
+
transfer_spec: transferSpec
|
|
38
|
+
};
|
|
39
|
+
var finalServerUrl = options.serverUrlOverride ? (0, core_1.cleanupServerUrl)(options.serverUrlOverride) : index_1.asperaHttpGateway.globals.serverUrl;
|
|
40
|
+
(0, http_1.apiPost)("".concat(finalServerUrl, "/v1/download"), payload).then(function (response) {
|
|
41
|
+
response.json().then(function (data) {
|
|
42
|
+
if (data.transfer_spec_id) {
|
|
43
|
+
var downloadUrl = "".concat(finalServerUrl, "/v1/download/").concat(data.transfer_spec_id);
|
|
44
|
+
if (index_1.asperaHttpGateway.globals.softwareMode || (options === null || options === void 0 ? void 0 : options.disableAutoDownload)) {
|
|
45
|
+
promiseInfo.resolver({
|
|
46
|
+
transfer_spec_id: data.transfer_spec_id,
|
|
47
|
+
url: downloadUrl,
|
|
48
|
+
});
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
index_1.asperaHttpGateway.globals.triggerDownloadFromUrl(downloadUrl);
|
|
52
|
+
promiseInfo.resolver();
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
(0, helpers_1.errorLog)(messages_1.messages.failedToGetDownloadUrl, { response: data });
|
|
56
|
+
promiseInfo.rejecter((0, helpers_1.generateErrorBody)(messages_1.messages.failedToGetDownloadUrl, { response: data }));
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}).catch(function (error) {
|
|
60
|
+
(0, helpers_1.errorLog)(messages_1.messages.downloadFailed, error);
|
|
61
|
+
promiseInfo.rejecter((0, helpers_1.generateErrorBody)(messages_1.messages.downloadFailed, error));
|
|
62
|
+
});
|
|
63
|
+
return promiseInfo.promise;
|
|
64
|
+
};
|
|
65
|
+
exports.download = download;
|
|
66
|
+
exports.default = {
|
|
67
|
+
download: exports.download
|
|
68
|
+
};
|