@ibm-aspera/sdk 0.2.8 → 0.2.9
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/.whitesource +3 -0
- package/README.md +1 -1
- package/dist/commonjs/app/core.d.ts +5 -20
- package/dist/commonjs/app/core.js +106 -45
- package/dist/commonjs/constants/constants.d.ts +1 -1
- package/dist/commonjs/constants/messages.d.ts +5 -0
- package/dist/commonjs/constants/messages.js +5 -0
- package/dist/commonjs/helpers/client/http-client.js +1 -1
- package/dist/commonjs/helpers/client/safari-client.js +1 -1
- package/dist/commonjs/helpers/helpers.d.ts +20 -2
- package/dist/commonjs/helpers/helpers.js +40 -2
- package/dist/commonjs/helpers/ws.js +2 -8
- package/dist/commonjs/http-gateway/core.d.ts +76 -0
- package/dist/commonjs/http-gateway/core.js +254 -0
- package/dist/commonjs/http-gateway/download.d.ts +14 -0
- package/dist/commonjs/http-gateway/download.js +186 -0
- package/dist/commonjs/http-gateway/index.d.ts +11 -0
- package/dist/commonjs/http-gateway/index.js +11 -0
- package/dist/commonjs/http-gateway/models.d.ts +16 -0
- package/dist/commonjs/http-gateway/models.js +2 -0
- package/dist/commonjs/http-gateway/upload.d.ts +14 -0
- package/dist/commonjs/http-gateway/upload.js +124 -0
- package/dist/commonjs/index.d.ts +2 -2
- package/dist/commonjs/index.js +36 -5
- package/dist/commonjs/models/aspera-sdk.model.d.ts +39 -27
- package/dist/commonjs/models/aspera-sdk.model.js +62 -58
- package/dist/commonjs/models/models.d.ts +49 -3
- package/dist/js/aspera-sdk.js +1 -1
- package/dist/js/aspera-sdk.js.LICENSE.txt +9 -1
- package/dist/js/aspera-sdk.js.map +1 -1
- package/package.json +21 -19
package/.whitesource
ADDED
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# IBM Aspera JavaScript SDK
|
|
2
|
-
This JavaScript SDK allows web applications to integrate with IBM Aspera to perform high-speed Aspera file transfers.
|
|
2
|
+
This JavaScript SDK allows web applications to integrate with `IBM Aspera for desktop` to perform high-speed Aspera file transfers.
|
|
3
3
|
|
|
4
4
|
Documentation is available on [GitHub Pages](https://ibm.github.io/aspera-sdk-js/docs/)
|
|
5
5
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AsperaSdkInfo, TransferResponse } from '../models/aspera-sdk.model';
|
|
2
|
-
import { CustomBrandingOptions, DataTransferResponse, AsperaSdkSpec, AsperaSdkTransfer, FileDialogOptions, FolderDialogOptions, InitOptions, ModifyTransferOptions, ResumeTransferOptions,
|
|
2
|
+
import { CustomBrandingOptions, DataTransferResponse, AsperaSdkSpec, AsperaSdkTransfer, FileDialogOptions, FolderDialogOptions, InitOptions, ModifyTransferOptions, ResumeTransferOptions, TransferSpec, WebsocketEvent } from '../models/models';
|
|
3
3
|
/**
|
|
4
4
|
* Check if IBM Aspera for Desktop connection works. This function is called by init
|
|
5
5
|
* when initializing the SDK. This function can be used at any point for checking.
|
|
@@ -8,7 +8,8 @@ import { CustomBrandingOptions, DataTransferResponse, AsperaSdkSpec, AsperaSdkTr
|
|
|
8
8
|
*/
|
|
9
9
|
export declare const testConnection: () => Promise<any>;
|
|
10
10
|
/**
|
|
11
|
-
* Initialize drag and drop.
|
|
11
|
+
* Initialize drag and drop. HTTP Gateway does not need to init.
|
|
12
|
+
* Ignore if only HTTP Gateway
|
|
12
13
|
* @param initCall - Indicate if called via init flow and should not reject
|
|
13
14
|
*
|
|
14
15
|
* @returns a promise that resolves if the initialization was successful or not
|
|
@@ -37,7 +38,7 @@ export declare const init: (options?: InitOptions) => Promise<any>;
|
|
|
37
38
|
* Start a transfer
|
|
38
39
|
*
|
|
39
40
|
* @param transferSpec standard transferSpec for transfer
|
|
40
|
-
* @param asperaSdkSpec IBM Aspera settings when starting a transfer
|
|
41
|
+
* @param asperaSdkSpec IBM Aspera settings when starting a transfer.
|
|
41
42
|
*
|
|
42
43
|
* @returns a promise that resolves if transfer initiation is successful and rejects if transfer cannot be started
|
|
43
44
|
*/
|
|
@@ -90,22 +91,6 @@ export declare const registerStatusCallback: (callback: (status: WebsocketEvent)
|
|
|
90
91
|
* @param id the ID returned by `registerStatusCallback`
|
|
91
92
|
*/
|
|
92
93
|
export declare const deregisterStatusCallback: (id: string) => void;
|
|
93
|
-
/**
|
|
94
|
-
* Register a callback for getting updates about the Safari extension status.
|
|
95
|
-
*
|
|
96
|
-
* This can be useful if you want to handle the case where the user enable or disable the Safari extension.
|
|
97
|
-
*
|
|
98
|
-
* @param callback callback function to receive events
|
|
99
|
-
*
|
|
100
|
-
* @returns ID representing the callback for deregistration purposes
|
|
101
|
-
*/
|
|
102
|
-
export declare const registerSafariExtensionStatusCallback: (callback: (status: SafariExtensionEvent) => void) => string;
|
|
103
|
-
/**
|
|
104
|
-
* Remove a callback from getting Safari extension status events.
|
|
105
|
-
*
|
|
106
|
-
* @param id the ID returned by `registerStatusCallback`
|
|
107
|
-
*/
|
|
108
|
-
export declare const deregisterSafariExtensionStatusCallback: (id: string) => void;
|
|
109
94
|
/**
|
|
110
95
|
* Remove a transfer. This will stop the transfer if it is in progress.
|
|
111
96
|
*
|
|
@@ -203,7 +188,7 @@ export declare const setBranding: (id: string, options: CustomBrandingOptions) =
|
|
|
203
188
|
* @param elementSelector the selector of the element on the page that should watch for drop events
|
|
204
189
|
*/
|
|
205
190
|
export declare const createDropzone: (callback: (data: {
|
|
206
|
-
event:
|
|
191
|
+
event: DragEvent;
|
|
207
192
|
files: DataTransferResponse;
|
|
208
193
|
}) => void, elementSelector: string) => void;
|
|
209
194
|
/**
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getInfo = exports.removeDropzone = exports.createDropzone = exports.setBranding = exports.modifyTransfer = exports.showDirectory = exports.getTransfer = exports.getAllTransfers = exports.showPreferences = exports.showSelectFolderDialog = exports.showSelectFileDialog = exports.resumeTransfer = exports.stopTransfer = exports.removeTransfer = exports.
|
|
3
|
+
exports.getInfo = exports.removeDropzone = exports.createDropzone = exports.setBranding = exports.modifyTransfer = exports.showDirectory = exports.getTransfer = exports.getAllTransfers = exports.showPreferences = exports.showSelectFolderDialog = exports.showSelectFileDialog = exports.resumeTransfer = exports.stopTransfer = exports.removeTransfer = exports.deregisterStatusCallback = exports.registerStatusCallback = exports.deregisterRemovedCallback = exports.registerRemovedCallback = exports.deregisterActivityCallback = exports.registerActivityCallback = exports.startTransfer = exports.init = exports.initDragDrop = exports.testConnection = void 0;
|
|
4
4
|
var messages_1 = require("../constants/messages");
|
|
5
5
|
var client_1 = require("../helpers/client/client");
|
|
6
6
|
var helpers_1 = require("../helpers/helpers");
|
|
7
|
+
var http_gateway_1 = require("../http-gateway");
|
|
8
|
+
var core_1 = require("../http-gateway/core");
|
|
7
9
|
var index_1 = require("../index");
|
|
10
|
+
var http_gateway_sdk_js_1 = require("@ibm-aspera/http-gateway-sdk-js");
|
|
8
11
|
/**
|
|
9
12
|
* Check if IBM Aspera for Desktop connection works. This function is called by init
|
|
10
13
|
* when initializing the SDK. This function can be used at any point for checking.
|
|
@@ -14,20 +17,24 @@ var index_1 = require("../index");
|
|
|
14
17
|
var testConnection = function () {
|
|
15
18
|
return client_1.client.request('get_info')
|
|
16
19
|
.then(function (data) {
|
|
17
|
-
index_1.asperaSdk.globals.
|
|
20
|
+
index_1.asperaSdk.globals.asperaSdkInfo = data;
|
|
18
21
|
index_1.asperaSdk.globals.asperaAppVerified = true;
|
|
19
|
-
return
|
|
22
|
+
return index_1.asperaSdk.globals.sdkResponseData;
|
|
20
23
|
});
|
|
21
24
|
};
|
|
22
25
|
exports.testConnection = testConnection;
|
|
23
26
|
/**
|
|
24
|
-
* Initialize drag and drop.
|
|
27
|
+
* Initialize drag and drop. HTTP Gateway does not need to init.
|
|
28
|
+
* Ignore if only HTTP Gateway
|
|
25
29
|
* @param initCall - Indicate if called via init flow and should not reject
|
|
26
30
|
*
|
|
27
31
|
* @returns a promise that resolves if the initialization was successful or not
|
|
28
32
|
*/
|
|
29
33
|
var initDragDrop = function (initCall) {
|
|
30
|
-
if (
|
|
34
|
+
if (index_1.asperaSdk.useHttpGateway) {
|
|
35
|
+
return Promise.resolve(true);
|
|
36
|
+
}
|
|
37
|
+
else if (!index_1.asperaSdk.isReady) {
|
|
31
38
|
return (0, helpers_1.throwError)(messages_1.messages.serverNotVerified);
|
|
32
39
|
}
|
|
33
40
|
var promiseInfo = (0, helpers_1.generatePromiseObjects)();
|
|
@@ -69,35 +76,85 @@ var init = function (options) {
|
|
|
69
76
|
var appId = (_a = options === null || options === void 0 ? void 0 : options.appId) !== null && _a !== void 0 ? _a : (0, helpers_1.randomUUID)();
|
|
70
77
|
var supportMultipleUsers = (_b = options === null || options === void 0 ? void 0 : options.supportMultipleUsers) !== null && _b !== void 0 ? _b : false;
|
|
71
78
|
index_1.asperaSdk.globals.appId = appId;
|
|
79
|
+
// Watch for old HTTP Gateway transfers in case used.
|
|
80
|
+
(0, http_gateway_sdk_js_1.registerActivityCallback)(function (oldHttpTransfers) {
|
|
81
|
+
oldHttpTransfers.transfers.forEach(function (oldHttpTransfer) {
|
|
82
|
+
(0, core_1.sendTransferUpdate)(oldHttpTransfer);
|
|
83
|
+
});
|
|
84
|
+
});
|
|
72
85
|
if (supportMultipleUsers) {
|
|
73
86
|
index_1.asperaSdk.globals.supportMultipleUsers = true;
|
|
74
87
|
index_1.asperaSdk.globals.sessionId = (0, helpers_1.randomUUID)();
|
|
75
88
|
}
|
|
76
|
-
|
|
77
|
-
.then(function () { return (0, exports.testConnection)(); })
|
|
78
|
-
.then(function () { return (0, exports.initDragDrop)(true); })
|
|
79
|
-
.catch(function (error) {
|
|
89
|
+
var handleErrors = function (error) {
|
|
80
90
|
(0, helpers_1.errorLog)(messages_1.messages.serverError, error);
|
|
81
91
|
index_1.asperaSdk.globals.asperaAppVerified = false;
|
|
82
92
|
throw (0, helpers_1.generateErrorBody)(messages_1.messages.serverError, error);
|
|
83
|
-
}
|
|
93
|
+
};
|
|
94
|
+
var getDesktopStartCalls = function () {
|
|
95
|
+
return index_1.asperaSdk.activityTracking.setup()
|
|
96
|
+
.then(function () { return (0, exports.testConnection)(); })
|
|
97
|
+
.then(function () { return (0, exports.initDragDrop)(true); })
|
|
98
|
+
.then(function () { return index_1.asperaSdk.globals.sdkResponseData; })
|
|
99
|
+
.catch(handleErrors);
|
|
100
|
+
};
|
|
101
|
+
if (options.httpGatewayUrl && !index_1.asperaSdk.globals.httpGatewayVerified) {
|
|
102
|
+
var finalHttpGatewayUrl = options.httpGatewayUrl.trim();
|
|
103
|
+
if (finalHttpGatewayUrl.indexOf('http') !== 0) {
|
|
104
|
+
finalHttpGatewayUrl = "https://".concat(finalHttpGatewayUrl);
|
|
105
|
+
}
|
|
106
|
+
if (finalHttpGatewayUrl.endsWith('/')) {
|
|
107
|
+
finalHttpGatewayUrl = finalHttpGatewayUrl.slice(0, -1);
|
|
108
|
+
}
|
|
109
|
+
index_1.asperaSdk.globals.httpGatewayUrl = finalHttpGatewayUrl;
|
|
110
|
+
return fetch("".concat(index_1.asperaSdk.globals.httpGatewayUrl, "/info"), { method: 'GET' }).then(function (response) {
|
|
111
|
+
return response.json().then(function (responseData) {
|
|
112
|
+
if (response.status >= 400) {
|
|
113
|
+
throw Error(responseData);
|
|
114
|
+
}
|
|
115
|
+
return responseData;
|
|
116
|
+
});
|
|
117
|
+
}).then(function (response) {
|
|
118
|
+
index_1.asperaSdk.globals.httpGatewayInfo = response;
|
|
119
|
+
index_1.asperaSdk.globals.httpGatewayVerified = true;
|
|
120
|
+
var iframeContainer = document.createElement('div');
|
|
121
|
+
iframeContainer.id = 'aspera-http-gateway-iframes';
|
|
122
|
+
iframeContainer.style = 'display: none;';
|
|
123
|
+
document.body.appendChild(iframeContainer);
|
|
124
|
+
index_1.asperaSdk.globals.httpGatewayIframeContainer = iframeContainer;
|
|
125
|
+
if (options.forceHttpGateway) {
|
|
126
|
+
return Promise.resolve(index_1.asperaSdk.globals.sdkResponseData);
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
return getDesktopStartCalls();
|
|
130
|
+
}
|
|
131
|
+
}).catch(function (error) {
|
|
132
|
+
// If HTTP Gateway fails log and move on to desktop
|
|
133
|
+
(0, helpers_1.errorLog)(messages_1.messages.httpInitFail, error);
|
|
134
|
+
return getDesktopStartCalls();
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
return getDesktopStartCalls();
|
|
84
138
|
};
|
|
85
139
|
exports.init = init;
|
|
86
140
|
/**
|
|
87
141
|
* Start a transfer
|
|
88
142
|
*
|
|
89
143
|
* @param transferSpec standard transferSpec for transfer
|
|
90
|
-
* @param asperaSdkSpec IBM Aspera settings when starting a transfer
|
|
144
|
+
* @param asperaSdkSpec IBM Aspera settings when starting a transfer.
|
|
91
145
|
*
|
|
92
146
|
* @returns a promise that resolves if transfer initiation is successful and rejects if transfer cannot be started
|
|
93
147
|
*/
|
|
94
148
|
var startTransfer = function (transferSpec, asperaSdkSpec) {
|
|
95
|
-
if (!index_1.asperaSdk.isReady) {
|
|
96
|
-
return (0, helpers_1.throwError)(messages_1.messages.serverNotVerified);
|
|
97
|
-
}
|
|
98
149
|
if (!(0, helpers_1.isValidTransferSpec)(transferSpec)) {
|
|
99
150
|
return (0, helpers_1.throwError)(messages_1.messages.notValidTransferSpec, { transferSpec: transferSpec });
|
|
100
151
|
}
|
|
152
|
+
if (index_1.asperaSdk.useHttpGateway) {
|
|
153
|
+
return transferSpec.direction === 'receive' ? (0, http_gateway_1.httpDownload)(transferSpec, asperaSdkSpec) : (0, http_gateway_1.httpUpload)(transferSpec, asperaSdkSpec);
|
|
154
|
+
}
|
|
155
|
+
else if (!index_1.asperaSdk.isReady) {
|
|
156
|
+
return (0, helpers_1.throwError)(messages_1.messages.serverNotVerified);
|
|
157
|
+
}
|
|
101
158
|
var promiseInfo = (0, helpers_1.generatePromiseObjects)();
|
|
102
159
|
var payload = {
|
|
103
160
|
transfer_spec: transferSpec,
|
|
@@ -179,28 +236,6 @@ var deregisterStatusCallback = function (id) {
|
|
|
179
236
|
index_1.asperaSdk.activityTracking.removeWebSocketEventCallback(id);
|
|
180
237
|
};
|
|
181
238
|
exports.deregisterStatusCallback = deregisterStatusCallback;
|
|
182
|
-
/**
|
|
183
|
-
* Register a callback for getting updates about the Safari extension status.
|
|
184
|
-
*
|
|
185
|
-
* This can be useful if you want to handle the case where the user enable or disable the Safari extension.
|
|
186
|
-
*
|
|
187
|
-
* @param callback callback function to receive events
|
|
188
|
-
*
|
|
189
|
-
* @returns ID representing the callback for deregistration purposes
|
|
190
|
-
*/
|
|
191
|
-
var registerSafariExtensionStatusCallback = function (callback) {
|
|
192
|
-
return index_1.asperaSdk.activityTracking.setSafariExtensionEventCallback(callback);
|
|
193
|
-
};
|
|
194
|
-
exports.registerSafariExtensionStatusCallback = registerSafariExtensionStatusCallback;
|
|
195
|
-
/**
|
|
196
|
-
* Remove a callback from getting Safari extension status events.
|
|
197
|
-
*
|
|
198
|
-
* @param id the ID returned by `registerStatusCallback`
|
|
199
|
-
*/
|
|
200
|
-
var deregisterSafariExtensionStatusCallback = function (id) {
|
|
201
|
-
index_1.asperaSdk.activityTracking.removeSafariExtensionEventCallback(id);
|
|
202
|
-
};
|
|
203
|
-
exports.deregisterSafariExtensionStatusCallback = deregisterSafariExtensionStatusCallback;
|
|
204
239
|
/**
|
|
205
240
|
* Remove a transfer. This will stop the transfer if it is in progress.
|
|
206
241
|
*
|
|
@@ -209,6 +244,9 @@ exports.deregisterSafariExtensionStatusCallback = deregisterSafariExtensionStatu
|
|
|
209
244
|
* @returns a promise that resolves if transfer is removed and rejects if transfer cannot be removed
|
|
210
245
|
*/
|
|
211
246
|
var removeTransfer = function (id) {
|
|
247
|
+
if (index_1.asperaSdk.useHttpGateway) {
|
|
248
|
+
return (0, core_1.httpRemoveTransfer)(id);
|
|
249
|
+
}
|
|
212
250
|
if (!index_1.asperaSdk.isReady) {
|
|
213
251
|
return (0, helpers_1.throwError)(messages_1.messages.serverNotVerified);
|
|
214
252
|
}
|
|
@@ -283,7 +321,10 @@ exports.resumeTransfer = resumeTransfer;
|
|
|
283
321
|
* @returns a promise that resolves with the selected file(s) and rejects if user cancels dialog
|
|
284
322
|
*/
|
|
285
323
|
var showSelectFileDialog = function (options) {
|
|
286
|
-
if (
|
|
324
|
+
if (index_1.asperaSdk.useHttpGateway) {
|
|
325
|
+
return (0, core_1.httpGatewaySelectFileFolderDialog)(options, false);
|
|
326
|
+
}
|
|
327
|
+
else if (!index_1.asperaSdk.isReady) {
|
|
287
328
|
return (0, helpers_1.throwError)(messages_1.messages.serverNotVerified);
|
|
288
329
|
}
|
|
289
330
|
var promiseInfo = (0, helpers_1.generatePromiseObjects)();
|
|
@@ -308,7 +349,10 @@ exports.showSelectFileDialog = showSelectFileDialog;
|
|
|
308
349
|
* @returns a promise that resolves with the selected folder(s) and rejects if user cancels dialog
|
|
309
350
|
*/
|
|
310
351
|
var showSelectFolderDialog = function (options) {
|
|
311
|
-
if (
|
|
352
|
+
if (index_1.asperaSdk.useHttpGateway) {
|
|
353
|
+
return (0, core_1.httpGatewaySelectFileFolderDialog)(options, true);
|
|
354
|
+
}
|
|
355
|
+
else if (!index_1.asperaSdk.isReady) {
|
|
312
356
|
return (0, helpers_1.throwError)(messages_1.messages.serverNotVerified);
|
|
313
357
|
}
|
|
314
358
|
var promiseInfo = (0, helpers_1.generatePromiseObjects)();
|
|
@@ -350,6 +394,9 @@ exports.showPreferences = showPreferences;
|
|
|
350
394
|
* @returns a promise that resolves with an array of transfers.
|
|
351
395
|
*/
|
|
352
396
|
var getAllTransfers = function () {
|
|
397
|
+
if (index_1.asperaSdk.useHttpGateway) {
|
|
398
|
+
return Promise.resolve((0, core_1.httpGetAllTransfers)());
|
|
399
|
+
}
|
|
353
400
|
if (!index_1.asperaSdk.isReady) {
|
|
354
401
|
return (0, helpers_1.throwError)(messages_1.messages.serverNotVerified);
|
|
355
402
|
}
|
|
@@ -374,6 +421,15 @@ exports.getAllTransfers = getAllTransfers;
|
|
|
374
421
|
* @returns a promise that resolves with the transfer.
|
|
375
422
|
*/
|
|
376
423
|
var getTransfer = function (id) {
|
|
424
|
+
if (index_1.asperaSdk.useHttpGateway) {
|
|
425
|
+
var transfer = (0, core_1.httpGetTransfer)(id);
|
|
426
|
+
if (transfer) {
|
|
427
|
+
return Promise.resolve(transfer);
|
|
428
|
+
}
|
|
429
|
+
else {
|
|
430
|
+
return Promise.reject((0, helpers_1.generateErrorBody)(messages_1.messages.getTransferFailed, { reason: 'Not found' }));
|
|
431
|
+
}
|
|
432
|
+
}
|
|
377
433
|
if (!index_1.asperaSdk.isReady) {
|
|
378
434
|
return (0, helpers_1.throwError)(messages_1.messages.serverNotVerified);
|
|
379
435
|
}
|
|
@@ -490,8 +546,8 @@ var createDropzone = function (callback, elementSelector) {
|
|
|
490
546
|
};
|
|
491
547
|
var dropEvent = function (event) {
|
|
492
548
|
event.preventDefault();
|
|
493
|
-
var files = [];
|
|
494
549
|
if (event.dataTransfer && event.dataTransfer.files && event.dataTransfer.files.length && event.dataTransfer.files[0]) {
|
|
550
|
+
var files = [];
|
|
495
551
|
for (var i = 0; i < event.dataTransfer.files.length; i++) {
|
|
496
552
|
var file = event.dataTransfer.files[i];
|
|
497
553
|
files.push({
|
|
@@ -505,11 +561,16 @@ var createDropzone = function (callback, elementSelector) {
|
|
|
505
561
|
files: files,
|
|
506
562
|
app_id: index_1.asperaSdk.globals.appId,
|
|
507
563
|
};
|
|
508
|
-
|
|
509
|
-
.
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
564
|
+
if (index_1.asperaSdk.isReady) {
|
|
565
|
+
client_1.client.request('dropped_files', payload)
|
|
566
|
+
.then(function (data) { return callback({ event: event, files: data }); })
|
|
567
|
+
.catch(function (error) {
|
|
568
|
+
(0, helpers_1.errorLog)(messages_1.messages.unableToReadDropped, error);
|
|
569
|
+
});
|
|
570
|
+
}
|
|
571
|
+
else if (index_1.asperaSdk.httpGatewayIsReady) {
|
|
572
|
+
(0, core_1.handleHttpGatewayDrop)(event.dataTransfer.items, callback, event);
|
|
573
|
+
}
|
|
513
574
|
}
|
|
514
575
|
};
|
|
515
576
|
elements.forEach(function (element) {
|
|
@@ -548,7 +609,7 @@ var getInfo = function () {
|
|
|
548
609
|
return (0, helpers_1.throwError)(messages_1.messages.serverNotVerified);
|
|
549
610
|
}
|
|
550
611
|
return new Promise(function (resolve, _) {
|
|
551
|
-
resolve(index_1.asperaSdk.globals.
|
|
612
|
+
resolve(index_1.asperaSdk.globals.sdkResponseData);
|
|
552
613
|
});
|
|
553
614
|
};
|
|
554
615
|
exports.getInfo = getInfo;
|
|
@@ -5,4 +5,4 @@ export declare const protocol = "aspera://";
|
|
|
5
5
|
/** @ignore */
|
|
6
6
|
export declare const baseInstallerUrl = "https://downloads.ibmaspera.com/downloads/desktop";
|
|
7
7
|
/** @ignore */
|
|
8
|
-
export declare const installerUrl
|
|
8
|
+
export declare const installerUrl = "https://downloads.ibmaspera.com/downloads/desktop/latest/stable";
|
|
@@ -27,4 +27,9 @@ export declare const messages: {
|
|
|
27
27
|
websocketClosedError: string;
|
|
28
28
|
websocketClosedUnexpect: string;
|
|
29
29
|
websocketNotReady: string;
|
|
30
|
+
httpNotAvailable: string;
|
|
31
|
+
httpInitFail: string;
|
|
32
|
+
filePickerCancel: string;
|
|
33
|
+
fileNotAllowed: string;
|
|
34
|
+
httpNetworkFail: string;
|
|
30
35
|
};
|
|
@@ -30,4 +30,9 @@ exports.messages = {
|
|
|
30
30
|
websocketClosedError: 'The websocket was closed due to an error',
|
|
31
31
|
websocketClosedUnexpect: 'The websocket was closed unexpectedly',
|
|
32
32
|
websocketNotReady: 'The websocket is not ready. Run init first',
|
|
33
|
+
httpNotAvailable: 'IBM Aspera HTTP Gateway is not available',
|
|
34
|
+
httpInitFail: 'IBM Aspera HTTP Gateway could not be started',
|
|
35
|
+
filePickerCancel: 'User canceled the select file or folder dialog.',
|
|
36
|
+
fileNotAllowed: 'TransferSpec contained file not selected by user.',
|
|
37
|
+
httpNetworkFail: 'HTTP network encountered unknown error.',
|
|
33
38
|
};
|
|
@@ -43,7 +43,7 @@ var JSONRPCHttpClient = /** @class */ (function () {
|
|
|
43
43
|
headers: {
|
|
44
44
|
'content-type': 'application/json',
|
|
45
45
|
},
|
|
46
|
-
body:
|
|
46
|
+
body: (0, helpers_1.safeJsonString)(request),
|
|
47
47
|
};
|
|
48
48
|
var rpcServerURL = (0, exports.getRpcServerUrl)();
|
|
49
49
|
return fetch(rpcServerURL, options).then(function (response) {
|
|
@@ -120,7 +120,7 @@ var SafariClient = /** @class */ (function () {
|
|
|
120
120
|
}
|
|
121
121
|
else {
|
|
122
122
|
console.warn('The Safari extension is disabled or unresponsive (dispatch event)');
|
|
123
|
-
console.warn("Failed event: ".concat(
|
|
123
|
+
console.warn("Failed event: ".concat((0, helpers_1.safeJsonString)(request)));
|
|
124
124
|
reject('The Safari extension is disabled or unresponsive (dispatch event)');
|
|
125
125
|
}
|
|
126
126
|
});
|
|
@@ -40,7 +40,7 @@ export declare const getWebsocketUrl: (serverUrl: string) => string;
|
|
|
40
40
|
*
|
|
41
41
|
* @returns a string indicating the current platform
|
|
42
42
|
*/
|
|
43
|
-
export declare const getCurrentPlatform: () =>
|
|
43
|
+
export declare const getCurrentPlatform: () => "macos" | "windows" | "linux" | "unknown";
|
|
44
44
|
/**
|
|
45
45
|
* Function used to create a random UUID
|
|
46
46
|
*
|
|
@@ -75,11 +75,27 @@ export declare const isSafari: () => boolean;
|
|
|
75
75
|
* @returns Info on URLs where installers live
|
|
76
76
|
*/
|
|
77
77
|
export declare const getInstallerUrls: () => InstallerUrlInfo;
|
|
78
|
+
/**
|
|
79
|
+
* Try to stringify a JSON string and log failures
|
|
80
|
+
*
|
|
81
|
+
* @param json - Object to make into a string
|
|
82
|
+
*
|
|
83
|
+
* @returns string representing JSON or empty string on error
|
|
84
|
+
*/
|
|
85
|
+
export declare const safeJsonString: (json: unknown) => string;
|
|
86
|
+
/**
|
|
87
|
+
* Try to parse a JSON string and log failures
|
|
88
|
+
*
|
|
89
|
+
* @param json - String to make into an object
|
|
90
|
+
*
|
|
91
|
+
* @returns object or array from the JSON string. Or undefined
|
|
92
|
+
*/
|
|
93
|
+
export declare const safeJsonParse: (json: string) => any | undefined;
|
|
78
94
|
declare const _default: {
|
|
79
95
|
errorLog: (message: string, debugData?: any) => void;
|
|
80
96
|
generateErrorBody: (message: string, debugData?: any) => ErrorResponse;
|
|
81
97
|
generatePromiseObjects: () => PromiseObject;
|
|
82
|
-
getCurrentPlatform: () => "
|
|
98
|
+
getCurrentPlatform: () => "macos" | "windows" | "linux" | "unknown";
|
|
83
99
|
getWebsocketUrl: (serverUrl: string) => string;
|
|
84
100
|
isSafari: () => boolean;
|
|
85
101
|
isValidURL: (url: string) => boolean;
|
|
@@ -87,5 +103,7 @@ declare const _default: {
|
|
|
87
103
|
randomUUID: () => string;
|
|
88
104
|
throwError: (message: string, debugData?: any) => Promise<any>;
|
|
89
105
|
getInstallerUrls: () => InstallerUrlInfo;
|
|
106
|
+
safeJsonString: (json: unknown) => string;
|
|
107
|
+
safeJsonParse: (json: string) => any | undefined;
|
|
90
108
|
};
|
|
91
109
|
export default _default;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
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.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
|
|
@@ -180,7 +180,6 @@ exports.isValidURL = isValidURL;
|
|
|
180
180
|
* @returns {boolean} Whether the browser is Safari.
|
|
181
181
|
*/
|
|
182
182
|
var isSafari = function () {
|
|
183
|
-
// eslint-disable-next-line
|
|
184
183
|
return /^((?!chrome|android).)*safari/i.test(navigator.userAgent) && !window.MSStream;
|
|
185
184
|
};
|
|
186
185
|
exports.isSafari = isSafari;
|
|
@@ -196,6 +195,43 @@ var getInstallerUrls = function () {
|
|
|
196
195
|
};
|
|
197
196
|
};
|
|
198
197
|
exports.getInstallerUrls = getInstallerUrls;
|
|
198
|
+
/**
|
|
199
|
+
* Try to stringify a JSON string and log failures
|
|
200
|
+
*
|
|
201
|
+
* @param json - Object to make into a string
|
|
202
|
+
*
|
|
203
|
+
* @returns string representing JSON or empty string on error
|
|
204
|
+
*/
|
|
205
|
+
var safeJsonString = function (json) {
|
|
206
|
+
try {
|
|
207
|
+
return JSON.stringify(json);
|
|
208
|
+
}
|
|
209
|
+
catch (error) {
|
|
210
|
+
(0, exports.errorLog)('safeJsonString: unable to stringify JSON', { error: error, json: json });
|
|
211
|
+
return '';
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
exports.safeJsonString = safeJsonString;
|
|
215
|
+
/**
|
|
216
|
+
* Try to parse a JSON string and log failures
|
|
217
|
+
*
|
|
218
|
+
* @param json - String to make into an object
|
|
219
|
+
*
|
|
220
|
+
* @returns object or array from the JSON string. Or undefined
|
|
221
|
+
*/
|
|
222
|
+
var safeJsonParse = function (json) {
|
|
223
|
+
if (json && typeof json === 'object') {
|
|
224
|
+
return json;
|
|
225
|
+
}
|
|
226
|
+
try {
|
|
227
|
+
return JSON.parse(json);
|
|
228
|
+
}
|
|
229
|
+
catch (error) {
|
|
230
|
+
(0, exports.errorLog)('safeJsonParse: unable to parse JSON', { error: error, json: json });
|
|
231
|
+
return undefined;
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
exports.safeJsonParse = safeJsonParse;
|
|
199
235
|
exports.default = {
|
|
200
236
|
errorLog: exports.errorLog,
|
|
201
237
|
generateErrorBody: exports.generateErrorBody,
|
|
@@ -208,4 +244,6 @@ exports.default = {
|
|
|
208
244
|
randomUUID: exports.randomUUID,
|
|
209
245
|
throwError: exports.throwError,
|
|
210
246
|
getInstallerUrls: exports.getInstallerUrls,
|
|
247
|
+
safeJsonString: exports.safeJsonString,
|
|
248
|
+
safeJsonParse: exports.safeJsonParse,
|
|
211
249
|
};
|
|
@@ -48,13 +48,7 @@ var WebsocketService = /** @class */ (function () {
|
|
|
48
48
|
* This function handles messages received from the websocket
|
|
49
49
|
*/
|
|
50
50
|
this.handleMessage = function (message) {
|
|
51
|
-
var data;
|
|
52
|
-
try {
|
|
53
|
-
data = JSON.parse(message.data);
|
|
54
|
-
}
|
|
55
|
-
catch (error) {
|
|
56
|
-
(0, helpers_1.errorLog)('Unable to parse Websocket message', { error: error, message: message });
|
|
57
|
-
}
|
|
51
|
+
var data = (0, helpers_1.safeJsonParse)(message.data);
|
|
58
52
|
// Message we get on subscription
|
|
59
53
|
if (data && data.id === 1) {
|
|
60
54
|
_this.initPromise.resolver(data);
|
|
@@ -78,7 +72,7 @@ var WebsocketService = /** @class */ (function () {
|
|
|
78
72
|
this.handleNotReady();
|
|
79
73
|
return false;
|
|
80
74
|
}
|
|
81
|
-
this.globalSocket.send(
|
|
75
|
+
this.globalSocket.send((0, helpers_1.safeJsonString)({ jsonrpc: '2.0', method: 'subscribe_transfer_activity', params: [index_1.asperaSdk.globals.appId], id: 1 }));
|
|
82
76
|
return true;
|
|
83
77
|
};
|
|
84
78
|
/**
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { FileDialogOptions, DataTransferResponse, TransferSpec, AsperaSdkTransfer } from '../models/models';
|
|
2
|
+
/**
|
|
3
|
+
* HTTP Gateway Core Logic
|
|
4
|
+
* - File/Folder picking
|
|
5
|
+
* - Starting and testing
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* Most logic is called directly by Desktop SDK functions
|
|
9
|
+
* You may not need to import anything from this file.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Remove a transfer from HTTP Gateway systems
|
|
13
|
+
* @param id - ID of the transfer
|
|
14
|
+
*
|
|
15
|
+
* @returns Promise indicating success
|
|
16
|
+
*/
|
|
17
|
+
export declare const httpRemoveTransfer: (id: string) => Promise<any>;
|
|
18
|
+
/**
|
|
19
|
+
* Get the list of http gateway transfers
|
|
20
|
+
*
|
|
21
|
+
* @returns list of HTTP Gateway
|
|
22
|
+
*/
|
|
23
|
+
export declare const httpGetAllTransfers: () => AsperaSdkTransfer[];
|
|
24
|
+
/**
|
|
25
|
+
* Get a HTTP Gateway transfer by ID
|
|
26
|
+
*
|
|
27
|
+
* @returns a transfer or null
|
|
28
|
+
*/
|
|
29
|
+
export declare const httpGetTransfer: (id: string) => AsperaSdkTransfer | null;
|
|
30
|
+
/**
|
|
31
|
+
* Create HTML input element for file picking
|
|
32
|
+
*/
|
|
33
|
+
export declare const createHtmlInputElement: () => HTMLInputElement;
|
|
34
|
+
/**
|
|
35
|
+
* Handle drop events and store files for HTTP Gateway
|
|
36
|
+
* This works on top of desktop.
|
|
37
|
+
*/
|
|
38
|
+
export declare const handleHttpGatewayDrop: (items: DataTransferItemList, callback: (data: {
|
|
39
|
+
event: DragEvent;
|
|
40
|
+
files: DataTransferResponse;
|
|
41
|
+
}) => void, event: DragEvent) => void;
|
|
42
|
+
/**
|
|
43
|
+
* Open native browser file or folder picker for files
|
|
44
|
+
*
|
|
45
|
+
* @param options - File picker options
|
|
46
|
+
* @param folder - Indicate if choosing folders
|
|
47
|
+
*
|
|
48
|
+
* @returns Promise that resolves with info about the files picked
|
|
49
|
+
*/
|
|
50
|
+
export declare const httpGatewaySelectFileFolderDialog: (options?: FileDialogOptions, folder?: boolean) => Promise<DataTransferResponse>;
|
|
51
|
+
/**
|
|
52
|
+
* Get a generic transfer object for HTTP Gateway transfers.
|
|
53
|
+
*
|
|
54
|
+
* @param transferSpec - TransferSpec being provided for the HTTP Gateway transfer
|
|
55
|
+
*
|
|
56
|
+
* @returns a transfer object to track status and send to consumers
|
|
57
|
+
*/
|
|
58
|
+
export declare const getSdkTransfer: (transferSpec: TransferSpec) => AsperaSdkTransfer;
|
|
59
|
+
/**
|
|
60
|
+
* Send a transfer update through the SDK
|
|
61
|
+
*
|
|
62
|
+
* @param transfer - Transsfer object to send to consumers
|
|
63
|
+
*/
|
|
64
|
+
export declare const sendTransferUpdate: (transfer: AsperaSdkTransfer) => void;
|
|
65
|
+
/**
|
|
66
|
+
* Try to parse and get a useful string from API calls for HTTP Gateway
|
|
67
|
+
*
|
|
68
|
+
* @param error - Error from API call for Gateway
|
|
69
|
+
*
|
|
70
|
+
* @returns a string to use for errors
|
|
71
|
+
*/
|
|
72
|
+
export declare const getMessageFromError: (error: any) => {
|
|
73
|
+
message: string;
|
|
74
|
+
code: number;
|
|
75
|
+
};
|
|
76
|
+
export declare const base64Encoding: (jsonString: string) => string;
|