@ibm-aspera/sdk 0.2.2
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/.editorconfig +13 -0
- package/.eslintrc.js +128 -0
- package/.github/CODE_OF_CONDUCT.md +128 -0
- package/.github/CONTRIBUTING.md +147 -0
- package/.github/workflows/ci.yml +36 -0
- package/.github/workflows/documentation.yml +43 -0
- package/.github/workflows/npm_upload.yml +30 -0
- package/.husky/pre-commit +4 -0
- package/CHANGELOG.md +124 -0
- package/LICENSE +201 -0
- package/README.md +25 -0
- package/dist/commonjs/app/core.d.ts +219 -0
- package/dist/commonjs/app/core.js +546 -0
- package/dist/commonjs/app/installer.d.ts +9 -0
- package/dist/commonjs/app/installer.js +50 -0
- package/dist/commonjs/constants/constants.d.ts +6 -0
- package/dist/commonjs/constants/constants.js +9 -0
- package/dist/commonjs/constants/messages.d.ts +29 -0
- package/dist/commonjs/constants/messages.js +32 -0
- package/dist/commonjs/helpers/client/client.d.ts +5 -0
- package/dist/commonjs/helpers/client/client.js +7 -0
- package/dist/commonjs/helpers/client/http-client.d.ts +42 -0
- package/dist/commonjs/helpers/client/http-client.js +84 -0
- package/dist/commonjs/helpers/client/safari-client.d.ts +99 -0
- package/dist/commonjs/helpers/client/safari-client.js +252 -0
- package/dist/commonjs/helpers/helpers.d.ts +84 -0
- package/dist/commonjs/helpers/helpers.js +197 -0
- package/dist/commonjs/helpers/http.d.ts +16 -0
- package/dist/commonjs/helpers/http.js +42 -0
- package/dist/commonjs/helpers/ws.d.ts +62 -0
- package/dist/commonjs/helpers/ws.js +182 -0
- package/dist/commonjs/index.d.ts +41 -0
- package/dist/commonjs/index.js +99 -0
- package/dist/commonjs/models/aspera-sdk.model.d.ts +213 -0
- package/dist/commonjs/models/aspera-sdk.model.js +288 -0
- package/dist/commonjs/models/models.d.ts +640 -0
- package/dist/commonjs/models/models.js +2 -0
- package/dist/js/aspera-sdk.js +3 -0
- package/dist/js/aspera-sdk.js.LICENSE.txt +7 -0
- package/dist/js/aspera-sdk.js.map +1 -0
- package/docs/DEVELOPMENT.md +38 -0
- package/jest.config.js +15 -0
- package/jest.setup.js +0 -0
- package/package.json +50 -0
- package/src/app/core.ts +610 -0
- package/src/app/installer.ts +53 -0
- package/src/constants/constants.ts +16 -0
- package/src/constants/messages.ts +29 -0
- package/src/helpers/client/client.ts +11 -0
- package/src/helpers/client/http-client.ts +92 -0
- package/src/helpers/client/safari-client.ts +318 -0
- package/src/helpers/helpers.ts +200 -0
- package/src/helpers/http.ts +39 -0
- package/src/helpers/ws.ts +215 -0
- package/src/index.html +404 -0
- package/src/index.ts +104 -0
- package/src/models/aspera-sdk.model.ts +360 -0
- package/src/models/models.ts +669 -0
- package/tests/client.spec.ts +52 -0
- package/tests/core.spec.ts +13 -0
- package/tests/helpers.spec.ts +124 -0
- package/tests/http.spec.ts +14 -0
- package/tests/installer.spec.ts +135 -0
- package/tests/mocks.ts +11 -0
- package/tsconfig.json +10 -0
- package/tsconfig.module.json +15 -0
- package/typedoc.js +17 -0
- package/webpack.config.js +53 -0
package/src/app/core.ts
ADDED
|
@@ -0,0 +1,610 @@
|
|
|
1
|
+
import {messages} from '../constants/messages';
|
|
2
|
+
import {client} from '../helpers/client/client';
|
|
3
|
+
import {errorLog, generateErrorBody, generatePromiseObjects, isValidTransferSpec, randomUUID, throwError} from '../helpers/helpers';
|
|
4
|
+
import {asperaSdk} from '../index';
|
|
5
|
+
import {AsperaSdkInfo, TransferResponse} from '../models/aspera-sdk.model';
|
|
6
|
+
import {CustomBrandingOptions, DataTransferResponse, AsperaSdkSpec, BrowserStyleFile, AsperaSdkTransfer, FileDialogOptions, FolderDialogOptions, InitOptions, ModifyTransferOptions, ResumeTransferOptions, SafariExtensionEvent, TransferSpec, WebsocketEvent} from '../models/models';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Check if IBM Aspera for Desktop connection works. This function is called by init
|
|
10
|
+
* when initializing the SDK. This function can be used at any point for checking.
|
|
11
|
+
*
|
|
12
|
+
* @returns a promise that resolves if server can connect or rejects if not
|
|
13
|
+
*/
|
|
14
|
+
export const testConnection = (): Promise<any> => {
|
|
15
|
+
return client.request('get_info')
|
|
16
|
+
.then((data: AsperaSdkInfo) => {
|
|
17
|
+
asperaSdk.globals.AsperaSdkInfo = data;
|
|
18
|
+
asperaSdk.globals.asperaAppVerified = true;
|
|
19
|
+
return data;
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Initialize drag and drop.
|
|
25
|
+
*
|
|
26
|
+
* @returns a promise that resolves if the initialization was successful or not
|
|
27
|
+
*/
|
|
28
|
+
export const initDragDrop = (): Promise<boolean> => {
|
|
29
|
+
if (!asperaSdk.isReady) {
|
|
30
|
+
return throwError(messages.serverNotVerified);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const promiseInfo = generatePromiseObjects();
|
|
34
|
+
|
|
35
|
+
client.request('init_drag_drop')
|
|
36
|
+
.then((data: boolean) => promiseInfo.resolver(data))
|
|
37
|
+
.catch(error => {
|
|
38
|
+
errorLog(messages.dragDropInitFailed, error);
|
|
39
|
+
promiseInfo.rejecter(generateErrorBody(messages.dragDropInitFailed, error));
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
return promiseInfo.promise;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Initialize IBM Aspera client. If client cannot (reject/catch), then
|
|
47
|
+
* client should attempt fixing server URL or trying again. If still fails disable UI elements.
|
|
48
|
+
*
|
|
49
|
+
* @param options initialization options:
|
|
50
|
+
*
|
|
51
|
+
* - `appId` the unique ID for the website. Transfers initiated during this session
|
|
52
|
+
* will be associated with this ID. It is recommended to use a unique ID to keep transfer
|
|
53
|
+
* information private from other websites.
|
|
54
|
+
*
|
|
55
|
+
* - `supportMultipleUsers` when enabled (defaults to false), the SDK will iterate over a port
|
|
56
|
+
* range and generate a session id to determine the running instance of the desktop app for the
|
|
57
|
+
* current user. This is needed when multiple users may be logged into the same machine
|
|
58
|
+
* simultaneously, for example on a Windows Server.
|
|
59
|
+
*
|
|
60
|
+
* @returns a promise that resolves if IBM Aspera Desktop is running properly or
|
|
61
|
+
* rejects if unable to connect
|
|
62
|
+
*/
|
|
63
|
+
export const init = (options?: InitOptions): Promise<any> => {
|
|
64
|
+
const appId = options?.appId ?? randomUUID();
|
|
65
|
+
const supportMultipleUsers = options?.supportMultipleUsers ?? false;
|
|
66
|
+
|
|
67
|
+
asperaSdk.globals.appId = appId;
|
|
68
|
+
|
|
69
|
+
if (supportMultipleUsers) {
|
|
70
|
+
asperaSdk.globals.sessionId = randomUUID();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return asperaSdk.activityTracking.setup()
|
|
74
|
+
.then(() => testConnection())
|
|
75
|
+
.then(() => initDragDrop())
|
|
76
|
+
.catch(error => {
|
|
77
|
+
errorLog(messages.serverError, error);
|
|
78
|
+
asperaSdk.globals.asperaAppVerified = false;
|
|
79
|
+
throw generateErrorBody(messages.serverError, error);
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Start a transfer
|
|
85
|
+
*
|
|
86
|
+
* @param transferSpec standard transferSpec for transfer
|
|
87
|
+
* @param asperaSdkSpec IBM Aspera settings when starting a transfer
|
|
88
|
+
*
|
|
89
|
+
* @returns a promise that resolves if transfer initiation is successful and rejects if transfer cannot be started
|
|
90
|
+
*/
|
|
91
|
+
export const startTransfer = (transferSpec: TransferSpec, asperaSdkSpec: AsperaSdkSpec): Promise<AsperaSdkTransfer> => {
|
|
92
|
+
if (!asperaSdk.isReady) {
|
|
93
|
+
return throwError(messages.serverNotVerified);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (!isValidTransferSpec(transferSpec)) {
|
|
97
|
+
return throwError(messages.notValidTransferSpec, {transferSpec});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const promiseInfo = generatePromiseObjects();
|
|
101
|
+
|
|
102
|
+
const payload = {
|
|
103
|
+
transfer_spec: transferSpec,
|
|
104
|
+
desktop_spec: asperaSdkSpec,
|
|
105
|
+
app_id: asperaSdk.globals.appId,
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
client.request('start_transfer', payload)
|
|
109
|
+
.then((data: any) => promiseInfo.resolver(data))
|
|
110
|
+
.catch(error => {
|
|
111
|
+
errorLog(messages.transferFailed, error);
|
|
112
|
+
promiseInfo.rejecter(generateErrorBody(messages.transferFailed, error));
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
return promiseInfo.promise;
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Register a callback event for getting transfer updates
|
|
120
|
+
*
|
|
121
|
+
* @param callback callback function to receive transfers
|
|
122
|
+
*
|
|
123
|
+
* @returns ID representing the callback for deregistration purposes
|
|
124
|
+
*/
|
|
125
|
+
export const registerActivityCallback = (callback: (transfers: TransferResponse) => void): string => {
|
|
126
|
+
return asperaSdk.activityTracking.setCallback(callback);
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Remove a callback from the transfer callback
|
|
131
|
+
*
|
|
132
|
+
* @param id the ID returned by `registerActivityCallback`
|
|
133
|
+
*/
|
|
134
|
+
export const deregisterActivityCallback = (id: string): void => {
|
|
135
|
+
asperaSdk.activityTracking.removeCallback(id);
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Register a callback event for when a user removes or cancels a transfer
|
|
140
|
+
* directly from IBM Aspera. This may also be called if IBM Aspera
|
|
141
|
+
* is configured to automatically remove completed transfers.
|
|
142
|
+
*
|
|
143
|
+
* @param callback callback function to receive transfers
|
|
144
|
+
*
|
|
145
|
+
* @returns ID representing the callback for deregistration purposes
|
|
146
|
+
*/
|
|
147
|
+
export const registerRemovedCallback = (callback: (transfer: AsperaSdkTransfer) => void): string => {
|
|
148
|
+
return asperaSdk.activityTracking.setRemovedCallback(callback);
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Remove a callback from the removed transfer callback
|
|
153
|
+
*
|
|
154
|
+
* @param id the ID returned by `registerRemovedCallback`
|
|
155
|
+
*/
|
|
156
|
+
export const deregisterRemovedCallback = (id: string): void => {
|
|
157
|
+
asperaSdk.activityTracking.removeRemovedCallback(id);
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Register a callback for getting updates about the connection status of IBM Aspera SDK.
|
|
162
|
+
*
|
|
163
|
+
* For example, to be notified of when the SDK loses connection with the application or connection
|
|
164
|
+
* is re-established. This can be useful if you want to handle the case where the user quits IBM Aspera
|
|
165
|
+
* after `init` has already been called, and want to prompt the user to relaunch the application.
|
|
166
|
+
*
|
|
167
|
+
* @param callback callback function to receive events
|
|
168
|
+
*
|
|
169
|
+
* @returns ID representing the callback for deregistration purposes
|
|
170
|
+
*/
|
|
171
|
+
export const registerStatusCallback = (callback: (status: WebsocketEvent) => void): string => {
|
|
172
|
+
return asperaSdk.activityTracking.setWebSocketEventCallback(callback);
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Remove a callback from getting connection status events.
|
|
177
|
+
*
|
|
178
|
+
* @param id the ID returned by `registerStatusCallback`
|
|
179
|
+
*/
|
|
180
|
+
export const deregisterStatusCallback = (id: string): void => {
|
|
181
|
+
asperaSdk.activityTracking.removeWebSocketEventCallback(id);
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Register a callback for getting updates about the Safari extension status.
|
|
186
|
+
*
|
|
187
|
+
* This can be useful if you want to handle the case where the user enable or disable the Safari extension.
|
|
188
|
+
*
|
|
189
|
+
* @param callback callback function to receive events
|
|
190
|
+
*
|
|
191
|
+
* @returns ID representing the callback for deregistration purposes
|
|
192
|
+
*/
|
|
193
|
+
export const registerSafariExtensionStatusCallback = (callback: (status: SafariExtensionEvent) => void): string => {
|
|
194
|
+
return asperaSdk.activityTracking.setSafariExtensionEventCallback(callback);
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Remove a callback from getting Safari extension status events.
|
|
199
|
+
*
|
|
200
|
+
* @param id the ID returned by `registerStatusCallback`
|
|
201
|
+
*/
|
|
202
|
+
export const deregisterSafariExtensionStatusCallback = (id: string): void => {
|
|
203
|
+
asperaSdk.activityTracking.removeSafariExtensionEventCallback(id);
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Remove a transfer. This will stop the transfer if it is in progress.
|
|
208
|
+
*
|
|
209
|
+
* @param id transfer uuid
|
|
210
|
+
*
|
|
211
|
+
* @returns a promise that resolves if transfer is removed and rejects if transfer cannot be removed
|
|
212
|
+
*/
|
|
213
|
+
export const removeTransfer = (id: string): Promise<any> => {
|
|
214
|
+
if (!asperaSdk.isReady) {
|
|
215
|
+
return throwError(messages.serverNotVerified);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
const promiseInfo = generatePromiseObjects();
|
|
219
|
+
|
|
220
|
+
const payload = {
|
|
221
|
+
transfer_id: id,
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
client.request('remove_transfer', payload)
|
|
225
|
+
.then((data: any) => promiseInfo.resolver(data))
|
|
226
|
+
.catch(error => {
|
|
227
|
+
errorLog(messages.removeTransferFailed, error);
|
|
228
|
+
promiseInfo.rejecter(generateErrorBody(messages.removeTransferFailed, error));
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
return promiseInfo.promise;
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Stop a transfer.
|
|
236
|
+
*
|
|
237
|
+
* @param id transfer uuid
|
|
238
|
+
*
|
|
239
|
+
* @returns a promise that resolves if transfer is stopped and rejects if transfer cannot be stopped
|
|
240
|
+
*/
|
|
241
|
+
export const stopTransfer = (id: string): Promise<any> => {
|
|
242
|
+
if (!asperaSdk.isReady) {
|
|
243
|
+
return throwError(messages.serverNotVerified);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
const promiseInfo = generatePromiseObjects();
|
|
247
|
+
|
|
248
|
+
const payload = {
|
|
249
|
+
transfer_id: id,
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
client.request('stop_transfer', payload)
|
|
253
|
+
.then((data: any) => promiseInfo.resolver(data))
|
|
254
|
+
.catch(error => {
|
|
255
|
+
errorLog(messages.stopTransferFailed, error);
|
|
256
|
+
promiseInfo.rejecter(generateErrorBody(messages.stopTransferFailed, error));
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
return promiseInfo.promise;
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Resume a paused or failed transfer.
|
|
264
|
+
*
|
|
265
|
+
* @param id transfer uuid
|
|
266
|
+
* @param options resume transfer options
|
|
267
|
+
*
|
|
268
|
+
* @returns a promise that resolves with the new transfer object if transfer is resumed
|
|
269
|
+
*/
|
|
270
|
+
export const resumeTransfer = (id: string, options?: ResumeTransferOptions): Promise<AsperaSdkTransfer> => {
|
|
271
|
+
if (!asperaSdk.isReady) {
|
|
272
|
+
return throwError(messages.serverNotVerified);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
const promiseInfo = generatePromiseObjects();
|
|
276
|
+
|
|
277
|
+
const payload = {
|
|
278
|
+
transfer_id: id,
|
|
279
|
+
transfer_spec: options,
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
client.request('resume_transfer', payload)
|
|
283
|
+
.then((data: AsperaSdkTransfer) => promiseInfo.resolver(data))
|
|
284
|
+
.catch(error => {
|
|
285
|
+
errorLog(messages.resumeTransferFailed, error);
|
|
286
|
+
promiseInfo.rejecter(generateErrorBody(messages.resumeTransferFailed, error));
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
return promiseInfo.promise;
|
|
290
|
+
};
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Displays a file browser dialog for the user to select files.
|
|
294
|
+
*
|
|
295
|
+
* @param options file dialog options
|
|
296
|
+
*
|
|
297
|
+
* @returns a promise that resolves with the selected file(s) and rejects if user cancels dialog
|
|
298
|
+
*/
|
|
299
|
+
export const showSelectFileDialog = (options?: FileDialogOptions): Promise<DataTransferResponse> => {
|
|
300
|
+
if (!asperaSdk.isReady) {
|
|
301
|
+
return throwError(messages.serverNotVerified);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
const promiseInfo = generatePromiseObjects();
|
|
305
|
+
|
|
306
|
+
const payload = {
|
|
307
|
+
options: options || {},
|
|
308
|
+
app_id: asperaSdk.globals.appId,
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
client.request('show_file_dialog', payload)
|
|
312
|
+
.then((data: any) => promiseInfo.resolver(data))
|
|
313
|
+
.catch(error => {
|
|
314
|
+
errorLog(messages.showSelectFileDialogFailed, error);
|
|
315
|
+
promiseInfo.rejecter(generateErrorBody(messages.showSelectFileDialogFailed, error));
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
return promiseInfo.promise;
|
|
319
|
+
};
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Displays a folder browser dialog for the user to select folders.
|
|
323
|
+
*
|
|
324
|
+
* @param options folder dialog options
|
|
325
|
+
*
|
|
326
|
+
* @returns a promise that resolves with the selected folder(s) and rejects if user cancels dialog
|
|
327
|
+
*/
|
|
328
|
+
export const showSelectFolderDialog = (options?: FolderDialogOptions): Promise<DataTransferResponse> => {
|
|
329
|
+
if (!asperaSdk.isReady) {
|
|
330
|
+
return throwError(messages.serverNotVerified);
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
const promiseInfo = generatePromiseObjects();
|
|
334
|
+
|
|
335
|
+
const payload = {
|
|
336
|
+
options: options || {},
|
|
337
|
+
app_id: asperaSdk.globals.appId,
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
client.request('show_folder_dialog', payload)
|
|
341
|
+
.then((data: any) => promiseInfo.resolver(data))
|
|
342
|
+
.catch(error => {
|
|
343
|
+
errorLog(messages.showSelectFolderDialogFailed, error);
|
|
344
|
+
promiseInfo.rejecter(generateErrorBody(messages.showSelectFolderDialogFailed, error));
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
return promiseInfo.promise;
|
|
348
|
+
};
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* Opens the IBM Aspera preferences page.
|
|
352
|
+
*
|
|
353
|
+
* @returns a promise that resolves when the preferences page is opened.
|
|
354
|
+
*/
|
|
355
|
+
export const showPreferences = (): Promise<any> => {
|
|
356
|
+
if (!asperaSdk.isReady) {
|
|
357
|
+
return throwError(messages.serverNotVerified);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
const promiseInfo = generatePromiseObjects();
|
|
361
|
+
|
|
362
|
+
client.request('open_preferences')
|
|
363
|
+
.then((data: any) => promiseInfo.resolver(data))
|
|
364
|
+
.catch(error => {
|
|
365
|
+
errorLog(messages.showPreferencesFailed, error);
|
|
366
|
+
promiseInfo.rejecter(generateErrorBody(messages.showPreferencesFailed, error));
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
return promiseInfo.promise;
|
|
370
|
+
};
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* Get all transfers associated with the current application.
|
|
374
|
+
*
|
|
375
|
+
* @returns a promise that resolves with an array of transfers.
|
|
376
|
+
*/
|
|
377
|
+
export const getAllTransfers = (): Promise<AsperaSdkTransfer[]> => {
|
|
378
|
+
if (!asperaSdk.isReady) {
|
|
379
|
+
return throwError(messages.serverNotVerified);
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
const promiseInfo = generatePromiseObjects();
|
|
383
|
+
|
|
384
|
+
const payload = {
|
|
385
|
+
app_id: asperaSdk.globals.appId,
|
|
386
|
+
};
|
|
387
|
+
|
|
388
|
+
client.request('get_all_transfers', payload)
|
|
389
|
+
.then((data: AsperaSdkTransfer[]) => promiseInfo.resolver(data))
|
|
390
|
+
.catch(error => {
|
|
391
|
+
errorLog(messages.getAllTransfersFailed, error);
|
|
392
|
+
promiseInfo.rejecter(generateErrorBody(messages.getAllTransfersFailed, error));
|
|
393
|
+
});
|
|
394
|
+
|
|
395
|
+
return promiseInfo.promise;
|
|
396
|
+
};
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* Get a specific transfer by ID.
|
|
400
|
+
*
|
|
401
|
+
* @param id transfer uuid
|
|
402
|
+
*
|
|
403
|
+
* @returns a promise that resolves with the transfer.
|
|
404
|
+
*/
|
|
405
|
+
export const getTransfer = (id: string): Promise<AsperaSdkTransfer> => {
|
|
406
|
+
if (!asperaSdk.isReady) {
|
|
407
|
+
return throwError(messages.serverNotVerified);
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
const promiseInfo = generatePromiseObjects();
|
|
411
|
+
|
|
412
|
+
const payload = {
|
|
413
|
+
transfer_id: id,
|
|
414
|
+
};
|
|
415
|
+
|
|
416
|
+
client.request('get_transfer', payload)
|
|
417
|
+
.then((data: AsperaSdkTransfer) => promiseInfo.resolver(data))
|
|
418
|
+
.catch(error => {
|
|
419
|
+
errorLog(messages.getTransferFailed, error);
|
|
420
|
+
promiseInfo.rejecter(generateErrorBody(messages.getTransferFailed, error));
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
return promiseInfo.promise;
|
|
424
|
+
};
|
|
425
|
+
|
|
426
|
+
/**
|
|
427
|
+
* Opens and highlights the downloaded file in Finder or Windows Explorer. If multiple files,
|
|
428
|
+
* then only the first file will be selected.
|
|
429
|
+
*
|
|
430
|
+
* @param id transfer uuid
|
|
431
|
+
*
|
|
432
|
+
* @returns a promise that resolves if the file can be shown and rejects if not
|
|
433
|
+
*/
|
|
434
|
+
export const showDirectory = (id: string): Promise<any> => {
|
|
435
|
+
if (!asperaSdk.isReady) {
|
|
436
|
+
return throwError(messages.serverNotVerified);
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
const promiseInfo = generatePromiseObjects();
|
|
440
|
+
|
|
441
|
+
const payload = {
|
|
442
|
+
transfer_id: id,
|
|
443
|
+
};
|
|
444
|
+
|
|
445
|
+
client.request('show_directory', payload)
|
|
446
|
+
.then((data: any) => promiseInfo.resolver(data))
|
|
447
|
+
.catch(error => {
|
|
448
|
+
errorLog(messages.showDirectoryFailed, error);
|
|
449
|
+
promiseInfo.rejecter(generateErrorBody(messages.showDirectoryFailed, error));
|
|
450
|
+
});
|
|
451
|
+
|
|
452
|
+
return promiseInfo.promise;
|
|
453
|
+
};
|
|
454
|
+
|
|
455
|
+
/**
|
|
456
|
+
* Modify the speed of a running transfer.
|
|
457
|
+
*
|
|
458
|
+
* @param id transfer uuid
|
|
459
|
+
* @param options transfer rate options
|
|
460
|
+
*
|
|
461
|
+
* @returns a promise that resolves if the transfer rate can be modified and rejects if not
|
|
462
|
+
*/
|
|
463
|
+
export const modifyTransfer = (id: string, options: ModifyTransferOptions): Promise<AsperaSdkTransfer> => {
|
|
464
|
+
if (!asperaSdk.isReady) {
|
|
465
|
+
return throwError(messages.serverNotVerified);
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
const promiseInfo = generatePromiseObjects();
|
|
469
|
+
|
|
470
|
+
const payload = {
|
|
471
|
+
transfer_id: id,
|
|
472
|
+
transfer_spec: options,
|
|
473
|
+
};
|
|
474
|
+
|
|
475
|
+
client.request('modify_transfer', payload)
|
|
476
|
+
.then((data: any) => promiseInfo.resolver(data))
|
|
477
|
+
.catch(error => {
|
|
478
|
+
errorLog(messages.modifyTransferFailed, error);
|
|
479
|
+
promiseInfo.rejecter(generateErrorBody(messages.modifyTransferFailed, error));
|
|
480
|
+
});
|
|
481
|
+
|
|
482
|
+
return promiseInfo.promise;
|
|
483
|
+
};
|
|
484
|
+
|
|
485
|
+
/**
|
|
486
|
+
* Set the custom branding template to be used by IBM Aspera. If the app is already
|
|
487
|
+
* configured to use a different branding, then the branding template you specify will be
|
|
488
|
+
* stored by the app, allowing the end user to switch at any point.
|
|
489
|
+
*
|
|
490
|
+
* @param id custom branding template id. This should be consistent across page loads.
|
|
491
|
+
* @param options custom branding options
|
|
492
|
+
*
|
|
493
|
+
* @returns a promise that resolves if the branding was properly set.
|
|
494
|
+
*/
|
|
495
|
+
export const setBranding = (id: string, options: CustomBrandingOptions): Promise<any> => {
|
|
496
|
+
if (!asperaSdk.isReady) {
|
|
497
|
+
return throwError(messages.serverNotVerified);
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
const promiseInfo = generatePromiseObjects();
|
|
501
|
+
|
|
502
|
+
const branding = {
|
|
503
|
+
id,
|
|
504
|
+
name: options.name,
|
|
505
|
+
theme: options.theme,
|
|
506
|
+
};
|
|
507
|
+
|
|
508
|
+
const payload = {
|
|
509
|
+
branding,
|
|
510
|
+
};
|
|
511
|
+
|
|
512
|
+
client.request('update_branding', payload)
|
|
513
|
+
.then((data: any) => promiseInfo.resolver(data))
|
|
514
|
+
.catch(error => {
|
|
515
|
+
errorLog(messages.setBrandingFailed, error);
|
|
516
|
+
promiseInfo.rejecter(generateErrorBody(messages.setBrandingFailed, error));
|
|
517
|
+
});
|
|
518
|
+
|
|
519
|
+
return promiseInfo.promise;
|
|
520
|
+
};
|
|
521
|
+
|
|
522
|
+
/**
|
|
523
|
+
* Create a dropzone for the given element selector.
|
|
524
|
+
*
|
|
525
|
+
* @param callback the function to call once the files are dropped
|
|
526
|
+
* @param elementSelector the selector of the element on the page that should watch for drop events
|
|
527
|
+
*/
|
|
528
|
+
export const createDropzone = (
|
|
529
|
+
callback: (data: {event: any; files: DataTransferResponse}) => void,
|
|
530
|
+
elementSelector: string,
|
|
531
|
+
): void => {
|
|
532
|
+
const elements = document.querySelectorAll(elementSelector);
|
|
533
|
+
if (!elements || !elements.length) {
|
|
534
|
+
errorLog(messages.unableToFindElementOnPage);
|
|
535
|
+
return;
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
const dragEvent = (event: any) => {
|
|
539
|
+
event.preventDefault();
|
|
540
|
+
};
|
|
541
|
+
|
|
542
|
+
const dropEvent = (event: any) => {
|
|
543
|
+
event.preventDefault();
|
|
544
|
+
const files: BrowserStyleFile[] = [];
|
|
545
|
+
if (event.dataTransfer && event.dataTransfer.files && event.dataTransfer.files.length && event.dataTransfer.files[0]) {
|
|
546
|
+
for (let i = 0; i < event.dataTransfer.files.length; i++) {
|
|
547
|
+
const file = event.dataTransfer.files[i];
|
|
548
|
+
files.push({
|
|
549
|
+
lastModified: file.lastModified,
|
|
550
|
+
name: file.name,
|
|
551
|
+
size: file.size,
|
|
552
|
+
type: file.type
|
|
553
|
+
});
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
const payload = {
|
|
557
|
+
files,
|
|
558
|
+
app_id: asperaSdk.globals.appId,
|
|
559
|
+
};
|
|
560
|
+
|
|
561
|
+
client.request('dropped_files', payload)
|
|
562
|
+
.then((data: any) => callback({event, files: data}))
|
|
563
|
+
.catch(error => {
|
|
564
|
+
errorLog(messages.unableToReadDropped, error);
|
|
565
|
+
});
|
|
566
|
+
}
|
|
567
|
+
};
|
|
568
|
+
|
|
569
|
+
elements.forEach(element => {
|
|
570
|
+
element.addEventListener('dragover', dragEvent);
|
|
571
|
+
element.addEventListener('drop', dropEvent);
|
|
572
|
+
asperaSdk.globals.dropZonesCreated.set(elementSelector, [{event: 'dragover', callback: dragEvent}, {event: 'drop', callback: dropEvent}]);
|
|
573
|
+
});
|
|
574
|
+
};
|
|
575
|
+
|
|
576
|
+
/**
|
|
577
|
+
* Remove dropzone.
|
|
578
|
+
*
|
|
579
|
+
* @param elementSelector the selector of the element on the page that should remove
|
|
580
|
+
*/
|
|
581
|
+
export const removeDropzone = (elementSelector: string): void => {
|
|
582
|
+
const foundDropzone = asperaSdk.globals.dropZonesCreated.get(elementSelector);
|
|
583
|
+
|
|
584
|
+
if (foundDropzone) {
|
|
585
|
+
foundDropzone.forEach(data => {
|
|
586
|
+
const elements = document.querySelectorAll(elementSelector);
|
|
587
|
+
|
|
588
|
+
if (elements && elements.length) {
|
|
589
|
+
elements.forEach(element => {
|
|
590
|
+
element.removeEventListener(data.event, data.callback);
|
|
591
|
+
});
|
|
592
|
+
}
|
|
593
|
+
});
|
|
594
|
+
}
|
|
595
|
+
};
|
|
596
|
+
|
|
597
|
+
/**
|
|
598
|
+
* Get metadata about the IBM Aspera installation.
|
|
599
|
+
*
|
|
600
|
+
* @returns a promise that returns information about the user's IBM Aspera installation.
|
|
601
|
+
*/
|
|
602
|
+
export const getInfo = (): Promise<AsperaSdkInfo> => {
|
|
603
|
+
if (!asperaSdk.isReady) {
|
|
604
|
+
return throwError(messages.serverNotVerified);
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
return new Promise((resolve, _) => {
|
|
608
|
+
resolve(asperaSdk.globals.AsperaSdkInfo);
|
|
609
|
+
});
|
|
610
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import {asperaSdk} from '../index';
|
|
2
|
+
import {errorLog, generateErrorBody, generatePromiseObjects, getCurrentPlatform, isValidURL, throwError} from '../helpers/helpers';
|
|
3
|
+
import {apiGet} from '../helpers/http';
|
|
4
|
+
import {messages} from '../constants/messages';
|
|
5
|
+
import {InstallerInfoResponse, InstallerOptions} from '../models/models';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Get the latest Aspera SDK installer information such as download URL and version.
|
|
9
|
+
*
|
|
10
|
+
* @param options Installer info options
|
|
11
|
+
*
|
|
12
|
+
* @returns a promise that resolves with the installer info and rejects if there is an error
|
|
13
|
+
*/
|
|
14
|
+
export const getInstallerInfo = (options: InstallerOptions = {}): Promise<InstallerInfoResponse> => {
|
|
15
|
+
let url = options.endpoint || asperaSdk.globals.installerUrl;
|
|
16
|
+
|
|
17
|
+
if (url.endsWith('/latest.json')) {
|
|
18
|
+
url = url.replace('/latest.json', '');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (!isValidURL(url)) {
|
|
22
|
+
return throwError(messages.invalidEndpoint, {url});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const promiseInfo = generatePromiseObjects();
|
|
26
|
+
|
|
27
|
+
apiGet(`${url}/latest.json`).then(response => {
|
|
28
|
+
response.json().then((data: InstallerInfoResponse) => {
|
|
29
|
+
if (options.endpoint) {
|
|
30
|
+
for (const entry of data.entries) {
|
|
31
|
+
if (!isValidURL(entry.url)) {
|
|
32
|
+
entry.url = `${options.endpoint}/${entry.url}`;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (options.all) {
|
|
38
|
+
promiseInfo.resolver(data);
|
|
39
|
+
} else {
|
|
40
|
+
const platform = getCurrentPlatform();
|
|
41
|
+
data.entries = data.entries.filter(entry => entry.platform === platform);
|
|
42
|
+
|
|
43
|
+
promiseInfo.resolver(data);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}).catch(error => {
|
|
47
|
+
errorLog(messages.getInstallerError, error);
|
|
48
|
+
|
|
49
|
+
promiseInfo.rejecter(generateErrorBody(messages.getInstallerError, error));
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
return promiseInfo.promise;
|
|
53
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** @ignore */
|
|
2
|
+
export const hiddenStyleList = `
|
|
3
|
+
display: none !important;
|
|
4
|
+
width: 1px !important;
|
|
5
|
+
height: 1px !important;
|
|
6
|
+
position: fixed !important;
|
|
7
|
+
z-index: -99 !important;
|
|
8
|
+
bottom: 0px !important;
|
|
9
|
+
right: 0px !important;
|
|
10
|
+
`;
|
|
11
|
+
|
|
12
|
+
/** @ignore */
|
|
13
|
+
export const protocol = 'aspera://';
|
|
14
|
+
|
|
15
|
+
/** @ignore */
|
|
16
|
+
export const installerUrl = 'https://d3gcli72yxqn2z.cloudfront.net/downloads/desktop/latest/stable';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/** @ignore */
|
|
2
|
+
export const messages = {
|
|
3
|
+
callbackIsNotFunction: 'The provided callback is not a function',
|
|
4
|
+
dragDropInitFailed: 'Unable to initialize drag-drop',
|
|
5
|
+
failedToGenerateIframe: 'Unable to generate IFRAME for download. Using new window',
|
|
6
|
+
getInstallerError: 'Unable to get latest installers',
|
|
7
|
+
getAllTransfersFailed: 'Unable to get all transfers',
|
|
8
|
+
getTransferFailed: 'Unable to get transfer',
|
|
9
|
+
invalidEndpoint: 'The specified endpoint is not a valid URL',
|
|
10
|
+
loadingProtocol: 'Launching IBM Aspera for Desktop',
|
|
11
|
+
modifyTransferFailed: 'Unable to modify transfer',
|
|
12
|
+
notValidTransferSpec: 'The supplied transferSpec is not valid',
|
|
13
|
+
removeTransferFailed: 'Unable to remove transfer',
|
|
14
|
+
resumeTransferFailed: 'Unable to resume transfer',
|
|
15
|
+
serverError: 'Unable to connect to IBM Aspera for Desktop server',
|
|
16
|
+
serverNotVerified: 'IBM Aspera SDK has not been verified. Run test or init first',
|
|
17
|
+
setBrandingFailed: 'Unable to set custom branding',
|
|
18
|
+
showDirectoryFailed: 'Unable to show transfer directory',
|
|
19
|
+
showSelectFileDialogFailed: 'Unable to show select file dialog',
|
|
20
|
+
showSelectFolderDialogFailed: 'Unable to show select folder dialog',
|
|
21
|
+
showPreferencesFailed: 'Unable to show preferences',
|
|
22
|
+
stopTransferFailed: 'Unable to stop transfer',
|
|
23
|
+
transferFailed: 'The transfer failed to initiate',
|
|
24
|
+
unableToFindElementOnPage: 'Unable to find the element on the current page',
|
|
25
|
+
unableToReadDropped: 'The dropped item could not be parsed. Please try selecting via the select file/folder option',
|
|
26
|
+
websocketClosedError: 'The websocket was closed due to an error',
|
|
27
|
+
websocketClosedUnexpect: 'The websocket was closed unexpectedly',
|
|
28
|
+
websocketNotReady: 'The websocket is not ready. Run init first',
|
|
29
|
+
};
|