@ibm-aspera/sdk 0.2.30 → 0.4.14

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/README.md CHANGED
@@ -1,7 +1,12 @@
1
1
  # IBM Aspera JavaScript SDK
2
- This JavaScript SDK allows web applications to integrate with `IBM Aspera for desktop` to perform high-speed Aspera file transfers.
2
+ This JavaScript SDK allows web applications to integrate with Aspera transfer clients to perform high-speed Aspera file transfers.
3
3
 
4
- Documentation is available on [GitHub Pages](https://ibm.github.io/aspera-sdk-js/docs/)
4
+ Supported transfer clients:
5
+ - IBM Aspera for desktop
6
+ - IBM Aspera HTTP Gateway
7
+ - IBM Aspera Connect
8
+
9
+ Example code is available on [GitHub Pages](https://ibm.github.io/aspera-sdk-js) with TypeDoc documentation [here](https://ibm.github.io/aspera-sdk-js/docs/).
5
10
 
6
11
  ## Installation
7
12
  Install via npm:
@@ -10,19 +15,18 @@ Install via npm:
10
15
  $ npm install --save @ibm-aspera/sdk
11
16
  ```
12
17
 
13
- Install from source:
18
+ To include this SDK via `script` tag directly in your web application's HTML, refer to third-party CDNs such as jsDelivr:
14
19
 
15
- ```shell
16
- $ git clone https://github.com/IBM/aspera-sdk-js.git
17
- $ cd aspera-sdk-js
18
- $ npm install
20
+ ```html
21
+ <script src="https://cdn.jsdelivr.net/npm/@ibm-aspera/sdk@0.2.30/dist/js/aspera-sdk.js"></script>
19
22
  ```
20
23
 
21
- When installing from source, the `dist` directory includes a `js` directory that contains the bundled JavaScript SDK that can be included via `script` tag
22
- or copied to a web server for hosting.
24
+ ## Usage
25
+
26
+ The full API of this SDK can be found [here](https://ibm.github.io/aspera-sdk-js/docs/) with many [code examples](https://github.com/IBM/aspera-sdk-js/blob/main/examples).
27
+
28
+ Along with the examples, you can find an example test application [here](https://ibm.github.io/aspera-sdk-js/all).
23
29
 
24
- ## Development
25
- To get started with development, take a look [here](https://github.com/IBM/aspera-sdk-js/blob/main/docs/DEVELOPMENT.md).
30
+ ## Migration from Connect SDK
26
31
 
27
- ## Code Example and test application
28
- You can run the test appp by running `npm run start:example` which will launch the browser to the test app.
32
+ Refer to [MIGRATION](MIGRATION.md) for recommended changes when migrating your web application from the Connect SDK (`@ibm-aspera/connect-sdk-js`).
@@ -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, TransferSpec, WebsocketEvent } from '../models/models';
2
+ import { CustomBrandingOptions, DataTransferResponse, AsperaSdkSpec, AsperaSdkTransfer, FileDialogOptions, FolderDialogOptions, InitOptions, ModifyTransferOptions, ResumeTransferOptions, TransferSpec, WebsocketEvent, ReadChunkAsArrayBufferResponse, ReadAsArrayBufferResponse, SdkCapabilities } from '../models/models';
3
3
  import * as ConnectTypes from '@ibm-aspera/connect-sdk-js/dist/esm/core/types';
4
4
  /**
5
5
  * Check if IBM Aspera for Desktop connection works. This function is called by init
@@ -189,3 +189,46 @@ export declare const removeDropzone: (elementSelector: string) => void;
189
189
  * @returns a promise that returns information about the user's IBM Aspera installation.
190
190
  */
191
191
  export declare const getInfo: () => Promise<AsperaSdkInfo>;
192
+ /**
193
+ * Read an entire file as an array buffer (base64-encoded).
194
+ *
195
+ * Note: The maximum file size allowed is 50 MiB.
196
+ *
197
+ * @param path path to the file to read
198
+ *
199
+ * @returns a promise that resolves with the file data as a base64-encoded string and mime type
200
+ */
201
+ export declare const readAsArrayBuffer: (path: string) => Promise<ReadAsArrayBufferResponse>;
202
+ /**
203
+ * Read a chunk of a file as an array buffer (base64-encoded).
204
+ *
205
+ * Note: The maximum chunk size allowed is 50 MiB.
206
+ *
207
+ * @param path path to the file to read
208
+ * @param offset offset to start reading the file, in bytes
209
+ * @param chunkSize the size of the chunk to read, in bytes
210
+ *
211
+ * @returns a promise that resolves with the file chunk data as a base64-encoded string and mime type
212
+ */
213
+ export declare const readChunkAsArrayBuffer: (path: string, offset: number, chunkSize: number) => Promise<ReadChunkAsArrayBufferResponse>;
214
+ /**
215
+ * Returns an object describing the high-level capabilities supported by the user's
216
+ * transfer client (e.g. IBM Aspera for desktop, Connect, or HTTP Gateway).
217
+ *
218
+ * Use this for feature detection at a semantic level rather than checking individual RPC methods.
219
+ * Capabitilies may depend on multiple underlying RPC methods and also may vary by transfer client.
220
+ *
221
+ * Some capabitilies may depend on newer versions of the transfer client. This function may be useful
222
+ * if you want to conditionally perform certain actions rather than potentially getting an error.
223
+ *
224
+ * @returns an object with boolean flags for each capability.
225
+ *
226
+ * @example
227
+ * // Conditionally render UI based on capabilities
228
+ * const caps = asperaSdk.getCapabilities();
229
+ * // Determine if your web application can render image previews for user selected files
230
+ * if (caps.imagePreview) {
231
+ * asperaSdk.readAsArrayBuffer(path);
232
+ * }
233
+ */
234
+ export declare const getCapabilities: () => SdkCapabilities;
@@ -1,6 +1,6 @@
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.deregisterStatusCallback = exports.registerStatusCallback = exports.deregisterActivityCallback = exports.registerActivityCallback = exports.startTransfer = exports.init = exports.initDragDrop = exports.testConnection = void 0;
3
+ exports.getCapabilities = exports.readChunkAsArrayBuffer = exports.readAsArrayBuffer = 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.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");
@@ -28,6 +28,28 @@ var testConnection = function () {
28
28
  });
29
29
  };
30
30
  exports.testConnection = testConnection;
31
+ /**
32
+ * RPC discovery used internally when initializing the SDK.
33
+ *
34
+ * @returns a promise that resolves if discovery is successful
35
+ */
36
+ var rpcDiscover = function () {
37
+ if (index_1.asperaSdk.useConnect || index_1.asperaSdk.useHttpGateway) {
38
+ return Promise.resolve({ methods: [] });
39
+ }
40
+ if (!index_1.asperaSdk.isReady) {
41
+ return (0, helpers_1.throwError)(messages_1.messages.serverNotVerified);
42
+ }
43
+ return client_1.client.request('rpc.discover')
44
+ .then(function (data) {
45
+ index_1.asperaSdk.globals.rpcMethods = data.methods.map(function (m) { return m.name; });
46
+ return data;
47
+ })
48
+ .catch(function (error) {
49
+ (0, helpers_1.errorLog)(messages_1.messages.rpcDiscoverFailed, error);
50
+ return Promise.reject((0, helpers_1.generateErrorBody)(messages_1.messages.rpcDiscoverFailed, error));
51
+ });
52
+ };
31
53
  /**
32
54
  * Initialize drag and drop. HTTP Gateway and Connect does not need to init.
33
55
  * Ignore if only HTTP Gateway
@@ -116,6 +138,7 @@ var init = function (options) {
116
138
  var getDesktopStartCalls = function () {
117
139
  return index_1.asperaSdk.activityTracking.setup()
118
140
  .then(function () { return (0, exports.testConnection)(); })
141
+ .then(function () { return rpcDiscover(); })
119
142
  .then(function () { return (0, exports.initDragDrop)(true); })
120
143
  .then(function () { return index_1.asperaSdk.globals.sdkResponseData; })
121
144
  .catch(handleErrors);
@@ -680,3 +703,110 @@ var getInfo = function () {
680
703
  });
681
704
  };
682
705
  exports.getInfo = getInfo;
706
+ /**
707
+ * Read an entire file as an array buffer (base64-encoded).
708
+ *
709
+ * Note: The maximum file size allowed is 50 MiB.
710
+ *
711
+ * @param path path to the file to read
712
+ *
713
+ * @returns a promise that resolves with the file data as a base64-encoded string and mime type
714
+ */
715
+ var readAsArrayBuffer = function (path) {
716
+ if (index_1.asperaSdk.useHttpGateway) {
717
+ return (0, core_1.httpGatewayReadAsArrayBuffer)(path);
718
+ }
719
+ else if (index_1.asperaSdk.useConnect) {
720
+ return index_1.asperaSdk.globals.connect.readAsArrayBuffer({ path: path });
721
+ }
722
+ if (!index_1.asperaSdk.isReady) {
723
+ return (0, helpers_1.throwError)(messages_1.messages.serverNotVerified);
724
+ }
725
+ var promiseInfo = (0, helpers_1.generatePromiseObjects)();
726
+ var payload = {
727
+ request: {
728
+ path: path,
729
+ },
730
+ app_id: index_1.asperaSdk.globals.appId,
731
+ };
732
+ client_1.client.request('read_as_array_buffer', payload)
733
+ .then(function (data) { return promiseInfo.resolver(data); })
734
+ .catch(function (error) {
735
+ (0, helpers_1.errorLog)(messages_1.messages.readAsArrayBufferFailed, error);
736
+ promiseInfo.rejecter((0, helpers_1.generateErrorBody)(messages_1.messages.readAsArrayBufferFailed, error));
737
+ });
738
+ return promiseInfo.promise;
739
+ };
740
+ exports.readAsArrayBuffer = readAsArrayBuffer;
741
+ /**
742
+ * Read a chunk of a file as an array buffer (base64-encoded).
743
+ *
744
+ * Note: The maximum chunk size allowed is 50 MiB.
745
+ *
746
+ * @param path path to the file to read
747
+ * @param offset offset to start reading the file, in bytes
748
+ * @param chunkSize the size of the chunk to read, in bytes
749
+ *
750
+ * @returns a promise that resolves with the file chunk data as a base64-encoded string and mime type
751
+ */
752
+ var readChunkAsArrayBuffer = function (path, offset, chunkSize) {
753
+ if (index_1.asperaSdk.useHttpGateway) {
754
+ return (0, core_1.httpGatewayReadChunkAsArrayBuffer)(path, offset, chunkSize);
755
+ }
756
+ else if (index_1.asperaSdk.useConnect) {
757
+ return index_1.asperaSdk.globals.connect.readChunkAsArrayBuffer({ path: path, offset: offset, chunkSize: chunkSize });
758
+ }
759
+ if (!index_1.asperaSdk.isReady) {
760
+ return (0, helpers_1.throwError)(messages_1.messages.serverNotVerified);
761
+ }
762
+ var promiseInfo = (0, helpers_1.generatePromiseObjects)();
763
+ var payload = {
764
+ request: {
765
+ path: path,
766
+ offset: offset,
767
+ chunkSize: chunkSize,
768
+ },
769
+ app_id: index_1.asperaSdk.globals.appId,
770
+ };
771
+ client_1.client.request('read_chunk_as_array_buffer', payload)
772
+ .then(function (data) { return promiseInfo.resolver(data); })
773
+ .catch(function (error) {
774
+ (0, helpers_1.errorLog)(messages_1.messages.readChunkAsArrayBufferFailed, error);
775
+ promiseInfo.rejecter((0, helpers_1.generateErrorBody)(messages_1.messages.readChunkAsArrayBufferFailed, error));
776
+ });
777
+ return promiseInfo.promise;
778
+ };
779
+ exports.readChunkAsArrayBuffer = readChunkAsArrayBuffer;
780
+ var supportsMethod = function (method) {
781
+ // HTTP Gateway and Connect do not have any RPC methods so fallback to true
782
+ if (index_1.asperaSdk.useHttpGateway || index_1.asperaSdk.useConnect) {
783
+ return true;
784
+ }
785
+ return index_1.asperaSdk.globals.rpcMethods.includes(method);
786
+ };
787
+ /**
788
+ * Returns an object describing the high-level capabilities supported by the user's
789
+ * transfer client (e.g. IBM Aspera for desktop, Connect, or HTTP Gateway).
790
+ *
791
+ * Use this for feature detection at a semantic level rather than checking individual RPC methods.
792
+ * Capabitilies may depend on multiple underlying RPC methods and also may vary by transfer client.
793
+ *
794
+ * Some capabitilies may depend on newer versions of the transfer client. This function may be useful
795
+ * if you want to conditionally perform certain actions rather than potentially getting an error.
796
+ *
797
+ * @returns an object with boolean flags for each capability.
798
+ *
799
+ * @example
800
+ * // Conditionally render UI based on capabilities
801
+ * const caps = asperaSdk.getCapabilities();
802
+ * // Determine if your web application can render image previews for user selected files
803
+ * if (caps.imagePreview) {
804
+ * asperaSdk.readAsArrayBuffer(path);
805
+ * }
806
+ */
807
+ var getCapabilities = function () {
808
+ return {
809
+ imagePreview: supportsMethod('read_as_array_buffer') && supportsMethod('read_chunk_as_array_buffer'),
810
+ };
811
+ };
812
+ exports.getCapabilities = getCapabilities;
@@ -32,4 +32,7 @@ export declare const messages: {
32
32
  filePickerCancel: string;
33
33
  fileNotAllowed: string;
34
34
  httpNetworkFail: string;
35
+ readAsArrayBufferFailed: string;
36
+ readChunkAsArrayBufferFailed: string;
37
+ rpcDiscoverFailed: string;
35
38
  };
@@ -33,6 +33,9 @@ exports.messages = {
33
33
  httpNotAvailable: 'IBM Aspera HTTP Gateway is not available',
34
34
  httpInitFail: 'IBM Aspera HTTP Gateway could not be started',
35
35
  filePickerCancel: 'User canceled the select file or folder dialog.',
36
- fileNotAllowed: 'TransferSpec contained file not selected by user.',
36
+ fileNotAllowed: 'The specified path has not been allowed by the user.',
37
37
  httpNetworkFail: 'HTTP network encountered unknown error.',
38
+ readAsArrayBufferFailed: 'Unable to read file as array buffer',
39
+ readChunkAsArrayBufferFailed: 'Unable to read file chunk as array buffer',
40
+ rpcDiscoverFailed: 'Unable to discover RPC endpoints',
38
41
  };
@@ -1,4 +1,4 @@
1
- import { FileDialogOptions, DataTransferResponse, TransferSpec, AsperaSdkTransfer } from '../models/models';
1
+ import { FileDialogOptions, DataTransferResponse, TransferSpec, AsperaSdkTransfer, ReadAsArrayBufferResponse, ReadChunkAsArrayBufferResponse } from '../models/models';
2
2
  /**
3
3
  * HTTP Gateway Core Logic
4
4
  * - File/Folder picking
@@ -74,3 +74,25 @@ export declare const getMessageFromError: (error: any) => {
74
74
  code: number;
75
75
  };
76
76
  export declare const base64Encoding: (jsonString: string) => string;
77
+ /**
78
+ * Returns the specified file's contents as a base64-encoded string.
79
+ *
80
+ * Note: The maximum file size allowed is 50 MiB.
81
+ *
82
+ * @param path path to the file to read
83
+ *
84
+ * @returns a promise that resolves with the file data as a base64-encoded string and mime type
85
+ */
86
+ export declare const httpGatewayReadAsArrayBuffer: (path: string) => Promise<ReadAsArrayBufferResponse>;
87
+ /**
88
+ * Read a chunk of a file as a base64-encoded string.
89
+ *
90
+ * Note: The maximum chunk size allowed is 50 MiB.
91
+ *
92
+ * @param path path to the file to read. For pure JS this will just be the filename.
93
+ * @param offset offset to start reading the file, in bytes
94
+ * @param chunkSize the size of the chunk to read, in bytes
95
+ *
96
+ * @returns a promise that resolves with the file chunk data as a base64-encoded string and mime type
97
+ */
98
+ export declare const httpGatewayReadChunkAsArrayBuffer: (path: string, offset: number, chunkSize: number) => Promise<ReadChunkAsArrayBufferResponse>;
@@ -1,10 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.base64Encoding = exports.getMessageFromError = exports.sendTransferUpdate = exports.getSdkTransfer = exports.httpGatewaySelectFileFolderDialog = exports.handleHttpGatewayDrop = exports.createHtmlInputElement = exports.httpGetTransfer = exports.httpGetAllTransfers = exports.httpRemoveTransfer = void 0;
3
+ exports.httpGatewayReadChunkAsArrayBuffer = exports.httpGatewayReadAsArrayBuffer = exports.base64Encoding = exports.getMessageFromError = exports.sendTransferUpdate = exports.getSdkTransfer = exports.httpGatewaySelectFileFolderDialog = exports.handleHttpGatewayDrop = exports.createHtmlInputElement = exports.httpGetTransfer = exports.httpGetAllTransfers = exports.httpRemoveTransfer = void 0;
4
4
  var messages_1 = require("../constants/messages");
5
5
  var helpers_1 = require("../helpers/helpers");
6
6
  var index_1 = require("../index");
7
7
  var http_gateway_sdk_js_1 = require("@ibm-aspera/http-gateway-sdk-js");
8
+ // 50MiB which matches the limits in Connect and IBM Aspera for desktop
9
+ var MAX_FILE_SIZE = 50 * 1024 * 1024;
8
10
  /**
9
11
  * HTTP Gateway Core Logic
10
12
  * - File/Folder picking
@@ -150,7 +152,7 @@ var httpGatewaySelectFileFolderDialog = function (options, folder) {
150
152
  for (var i = 0; i < element.files.length; i++) {
151
153
  var file = element.files[i];
152
154
  returnFiles.push(file);
153
- index_1.asperaSdk.httpGatewaySelectedFiles.set(file.name, file);
155
+ index_1.asperaSdk.httpGatewaySelectedFiles.set(file.webkitRelativePath || file.name, file);
154
156
  }
155
157
  resolver({
156
158
  dataTransfer: {
@@ -252,3 +254,135 @@ var base64Encoding = function (jsonString) {
252
254
  return btoa(binString);
253
255
  };
254
256
  exports.base64Encoding = base64Encoding;
257
+ /**
258
+ * Attempt to read the specified `File` object contents as a base64-encoded string.
259
+ *
260
+ * @param file - File previously selected by the user
261
+ *
262
+ * @returns an object with base64 data and mime type
263
+ */
264
+ var readFileAsBase64 = function (file) {
265
+ return new Promise(function (resolve, reject) {
266
+ var reader = new FileReader();
267
+ reader.onload = function (event) {
268
+ var _a;
269
+ try {
270
+ var dataUrl = (_a = event.target) === null || _a === void 0 ? void 0 : _a.result;
271
+ if (typeof dataUrl !== 'string') {
272
+ reject((0, helpers_1.generateErrorBody)('FileReader did not return a data URL'));
273
+ return;
274
+ }
275
+ // Remove `data:*/*;base64,` from the start of the data URL (https://developer.mozilla.org/en-US/docs/Web/API/FileReader/readAsDataURL)
276
+ var base64 = dataUrl.split(';base64,')[1];
277
+ if (base64 === undefined) {
278
+ reject((0, helpers_1.generateErrorBody)('Invalid data URL format'));
279
+ return;
280
+ }
281
+ resolve({
282
+ data: base64,
283
+ type: file.type || 'application/octet-stream'
284
+ });
285
+ }
286
+ catch (err) {
287
+ reject((0, helpers_1.generateErrorBody)('Failed to process file data', err));
288
+ }
289
+ };
290
+ reader.onerror = function () {
291
+ reject((0, helpers_1.generateErrorBody)('Failed to read file', reader.error));
292
+ };
293
+ reader.readAsDataURL(file);
294
+ });
295
+ };
296
+ /**
297
+ * Returns the specified file's contents as a base64-encoded string.
298
+ *
299
+ * Note: The maximum file size allowed is 50 MiB.
300
+ *
301
+ * @param path path to the file to read
302
+ *
303
+ * @returns a promise that resolves with the file data as a base64-encoded string and mime type
304
+ */
305
+ var httpGatewayReadAsArrayBuffer = function (path) {
306
+ // Pre-condition: Caller must have previously selected file via `showSelectFileDialog()`
307
+ var file = index_1.asperaSdk.httpGatewaySelectedFiles.get(path);
308
+ if (!file) {
309
+ return (0, helpers_1.throwError)(messages_1.messages.fileNotAllowed);
310
+ }
311
+ if (file.size > MAX_FILE_SIZE) {
312
+ return (0, helpers_1.throwError)('File exceeds allowed maximum');
313
+ }
314
+ return readFileAsBase64(file);
315
+ };
316
+ exports.httpGatewayReadAsArrayBuffer = httpGatewayReadAsArrayBuffer;
317
+ /**
318
+ * Attempt to read the specified `File` object contents as a base64-encoded string.
319
+ *
320
+ * @param file - File previously selected by the user
321
+ * @param offset offset to start reading the file, in bytes
322
+ * @param chunkSize the size of the chunk to read, in bytes
323
+ *
324
+ * @returns an object with base64 data and mime type
325
+ */
326
+ var readFileChunkAsBase64 = function (file, offset, chunkSize) {
327
+ return new Promise(function (resolve, reject) {
328
+ if (offset > file.size) {
329
+ resolve({ data: '', type: file.type || 'application/octet-stream' });
330
+ return;
331
+ }
332
+ var chunk = file.slice(offset, offset + chunkSize);
333
+ var reader = new FileReader();
334
+ reader.onload = function (event) {
335
+ var _a;
336
+ try {
337
+ var dataUrl = (_a = event.target) === null || _a === void 0 ? void 0 : _a.result;
338
+ if (typeof dataUrl !== 'string') {
339
+ reject((0, helpers_1.generateErrorBody)('FileReader did not return a data URL'));
340
+ return;
341
+ }
342
+ // Remove `data:*/*;base64,` from the start of the data URL (https://developer.mozilla.org/en-US/docs/Web/API/FileReader/readAsDataURL)
343
+ var base64 = dataUrl.split(';base64,')[1];
344
+ if (base64 === undefined) {
345
+ reject((0, helpers_1.generateErrorBody)('Invalid data URL format'));
346
+ return;
347
+ }
348
+ resolve({
349
+ data: base64,
350
+ type: file.type || 'application/octet-stream'
351
+ });
352
+ }
353
+ catch (err) {
354
+ reject((0, helpers_1.generateErrorBody)('Failed to process file data', err));
355
+ }
356
+ };
357
+ reader.onerror = function () {
358
+ reject((0, helpers_1.generateErrorBody)('Failed to read file', reader.error));
359
+ };
360
+ reader.readAsDataURL(chunk);
361
+ });
362
+ };
363
+ /**
364
+ * Read a chunk of a file as a base64-encoded string.
365
+ *
366
+ * Note: The maximum chunk size allowed is 50 MiB.
367
+ *
368
+ * @param path path to the file to read. For pure JS this will just be the filename.
369
+ * @param offset offset to start reading the file, in bytes
370
+ * @param chunkSize the size of the chunk to read, in bytes
371
+ *
372
+ * @returns a promise that resolves with the file chunk data as a base64-encoded string and mime type
373
+ */
374
+ var httpGatewayReadChunkAsArrayBuffer = function (path, offset, chunkSize) {
375
+ if (offset < 0 || chunkSize <= 0) {
376
+ return (0, helpers_1.throwError)('Invalid offset or chunk size');
377
+ }
378
+ // Pre-condition: Caller must have previously selected file via `showSelectFileDialog()`
379
+ var file = index_1.asperaSdk.httpGatewaySelectedFiles.get(path);
380
+ if (!file) {
381
+ return (0, helpers_1.throwError)(messages_1.messages.fileNotAllowed);
382
+ }
383
+ if (chunkSize > MAX_FILE_SIZE) {
384
+ return (0, helpers_1.throwError)('Chunk size exceeds allowed maximum');
385
+ }
386
+ return readFileChunkAsBase64(file, offset, chunkSize);
387
+ };
388
+ exports.httpGatewayReadChunkAsArrayBuffer = httpGatewayReadChunkAsArrayBuffer;
@@ -1,8 +1,12 @@
1
1
  import { AsperaSdk } from './models/aspera-sdk.model';
2
- import { createDropzone, deregisterActivityCallback, deregisterStatusCallback, getAllTransfers, getInfo, getTransfer, init, initDragDrop, modifyTransfer, registerActivityCallback, registerStatusCallback, removeDropzone, removeTransfer, resumeTransfer, setBranding, showDirectory, showPreferences, showSelectFileDialog, showSelectFolderDialog, startTransfer, stopTransfer, testConnection } from './app/core';
2
+ import { createDropzone, deregisterActivityCallback, deregisterStatusCallback, getAllTransfers, getCapabilities, getInfo, getTransfer, init, initDragDrop, modifyTransfer, readAsArrayBuffer, readChunkAsArrayBuffer, registerActivityCallback, registerStatusCallback, removeDropzone, removeTransfer, resumeTransfer, setBranding, showDirectory, showPreferences, showSelectFileDialog, showSelectFolderDialog, startTransfer, stopTransfer, testConnection } from './app/core';
3
3
  import { getInstallerInfo } from './app/installer';
4
4
  import { getInstallerUrls, isSafari } from './helpers/helpers';
5
5
  export declare const asperaSdk: AsperaSdk;
6
6
  declare const launch: () => void;
7
- export { isSafari, init, testConnection, startTransfer, launch, registerActivityCallback, deregisterActivityCallback, removeTransfer, showDirectory, stopTransfer, resumeTransfer, getAllTransfers, getTransfer, showSelectFileDialog, showSelectFolderDialog, showPreferences, modifyTransfer, createDropzone, removeDropzone, initDragDrop, getInstallerInfo, registerStatusCallback, deregisterStatusCallback, setBranding, getInfo, getInstallerUrls, };
7
+ export { isSafari, init, testConnection, startTransfer, launch, registerActivityCallback, deregisterActivityCallback, removeTransfer, showDirectory, stopTransfer, resumeTransfer, getAllTransfers, getTransfer, showSelectFileDialog, showSelectFolderDialog, showPreferences, modifyTransfer, createDropzone, removeDropzone, initDragDrop, getInstallerInfo, registerStatusCallback, deregisterStatusCallback, setBranding, getInfo, readAsArrayBuffer, readChunkAsArrayBuffer, getInstallerUrls, getCapabilities, };
8
+ export type { AsperaSdkSpec, AsperaSdkTransfer, BrowserStyleFile, CustomBrandingOptions, CustomTheme, CustomThemeItems, DataTransferResponse, FileDialogOptions, FileFilter, FolderDialogOptions, InitOptions, InstallerInfo, InstallerInfoResponse, InstallerOptions, InstallerUrlInfo, ModifyTransferOptions, OverwritePolicy, Path, ReadAsArrayBufferResponse, ReadChunkAsArrayBufferResponse, ResumePolicy, ResumeTransferOptions, SafariExtensionEvent, SdkCapabilities, TransferSpec, TransferStatus, WebsocketEvent, } from './models/models';
9
+ export type { ActivityMessage, ActivityMessageTypes, AsperaSdkClientInfo, AsperaSdkInfo, TransferResponse, } from './models/aspera-sdk.model';
10
+ export { AsperaSdk, AsperaSdkGlobals } from './models/aspera-sdk.model';
11
+ export type { HttpGatewayInfo } from './http-gateway/models';
8
12
  export default asperaSdk;
@@ -33,18 +33,21 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.getInstallerUrls = exports.getInfo = exports.setBranding = exports.deregisterStatusCallback = exports.registerStatusCallback = exports.getInstallerInfo = exports.initDragDrop = exports.removeDropzone = exports.createDropzone = exports.modifyTransfer = exports.showPreferences = exports.showSelectFolderDialog = exports.showSelectFileDialog = exports.getTransfer = exports.getAllTransfers = exports.resumeTransfer = exports.stopTransfer = exports.showDirectory = exports.removeTransfer = exports.deregisterActivityCallback = exports.registerActivityCallback = exports.launch = exports.startTransfer = exports.testConnection = exports.init = exports.isSafari = exports.asperaSdk = void 0;
36
+ exports.AsperaSdkGlobals = exports.AsperaSdk = exports.getCapabilities = exports.getInstallerUrls = exports.readChunkAsArrayBuffer = exports.readAsArrayBuffer = exports.getInfo = exports.setBranding = exports.deregisterStatusCallback = exports.registerStatusCallback = exports.getInstallerInfo = exports.initDragDrop = exports.removeDropzone = exports.createDropzone = exports.modifyTransfer = exports.showPreferences = exports.showSelectFolderDialog = exports.showSelectFileDialog = exports.getTransfer = exports.getAllTransfers = exports.resumeTransfer = exports.stopTransfer = exports.showDirectory = exports.removeTransfer = exports.deregisterActivityCallback = exports.registerActivityCallback = exports.launch = exports.startTransfer = exports.testConnection = exports.init = exports.isSafari = exports.asperaSdk = void 0;
37
37
  var aspera_sdk_model_1 = require("./models/aspera-sdk.model");
38
38
  var core_1 = require("./app/core");
39
39
  Object.defineProperty(exports, "createDropzone", { enumerable: true, get: function () { return core_1.createDropzone; } });
40
40
  Object.defineProperty(exports, "deregisterActivityCallback", { enumerable: true, get: function () { return core_1.deregisterActivityCallback; } });
41
41
  Object.defineProperty(exports, "deregisterStatusCallback", { enumerable: true, get: function () { return core_1.deregisterStatusCallback; } });
42
42
  Object.defineProperty(exports, "getAllTransfers", { enumerable: true, get: function () { return core_1.getAllTransfers; } });
43
+ Object.defineProperty(exports, "getCapabilities", { enumerable: true, get: function () { return core_1.getCapabilities; } });
43
44
  Object.defineProperty(exports, "getInfo", { enumerable: true, get: function () { return core_1.getInfo; } });
44
45
  Object.defineProperty(exports, "getTransfer", { enumerable: true, get: function () { return core_1.getTransfer; } });
45
46
  Object.defineProperty(exports, "init", { enumerable: true, get: function () { return core_1.init; } });
46
47
  Object.defineProperty(exports, "initDragDrop", { enumerable: true, get: function () { return core_1.initDragDrop; } });
47
48
  Object.defineProperty(exports, "modifyTransfer", { enumerable: true, get: function () { return core_1.modifyTransfer; } });
49
+ Object.defineProperty(exports, "readAsArrayBuffer", { enumerable: true, get: function () { return core_1.readAsArrayBuffer; } });
50
+ Object.defineProperty(exports, "readChunkAsArrayBuffer", { enumerable: true, get: function () { return core_1.readChunkAsArrayBuffer; } });
48
51
  Object.defineProperty(exports, "registerActivityCallback", { enumerable: true, get: function () { return core_1.registerActivityCallback; } });
49
52
  Object.defineProperty(exports, "registerStatusCallback", { enumerable: true, get: function () { return core_1.registerStatusCallback; } });
50
53
  Object.defineProperty(exports, "removeDropzone", { enumerable: true, get: function () { return core_1.removeDropzone; } });
@@ -88,8 +91,11 @@ exports.asperaSdk.deregisterStatusCallback = core_1.deregisterStatusCallback;
88
91
  exports.asperaSdk.initDragDrop = core_1.initDragDrop;
89
92
  exports.asperaSdk.setBranding = core_1.setBranding;
90
93
  exports.asperaSdk.getInfo = core_1.getInfo;
94
+ exports.asperaSdk.readAsArrayBuffer = core_1.readAsArrayBuffer;
95
+ exports.asperaSdk.readChunkAsArrayBuffer = core_1.readChunkAsArrayBuffer;
91
96
  exports.asperaSdk.isSafari = helpers_1.isSafari;
92
97
  exports.asperaSdk.getInstallerUrls = helpers_1.getInstallerUrls;
98
+ exports.asperaSdk.getCapabilities = core_1.getCapabilities;
93
99
  exports.asperaSdk.httpGatewayCalls = httpGatewayCalls;
94
100
  var launch = exports.asperaSdk.globals.launch;
95
101
  exports.launch = launch;
@@ -97,4 +103,7 @@ exports.asperaSdk.launch = launch;
97
103
  if (typeof window === 'object') {
98
104
  window.asperaSdk = exports.asperaSdk;
99
105
  }
106
+ var aspera_sdk_model_2 = require("./models/aspera-sdk.model");
107
+ Object.defineProperty(exports, "AsperaSdk", { enumerable: true, get: function () { return aspera_sdk_model_2.AsperaSdk; } });
108
+ Object.defineProperty(exports, "AsperaSdkGlobals", { enumerable: true, get: function () { return aspera_sdk_model_2.AsperaSdkGlobals; } });
100
109
  exports.default = exports.asperaSdk;
@@ -1,12 +1,14 @@
1
- import { CustomBrandingOptions, DataTransferResponse, AsperaSdkSpec, AsperaSdkTransfer, FileDialogOptions, FolderDialogOptions, InitOptions, InstallerInfoResponse, InstallerOptions, ModifyTransferOptions, ResumeTransferOptions, SafariExtensionEvent, TransferSpec, WebsocketEvent, InstallerUrlInfo } from './models';
1
+ import { CustomBrandingOptions, DataTransferResponse, AsperaSdkSpec, AsperaSdkTransfer, FileDialogOptions, FolderDialogOptions, InitOptions, InstallerInfoResponse, InstallerOptions, ModifyTransferOptions, ResumeTransferOptions, SafariExtensionEvent, TransferSpec, WebsocketEvent, InstallerUrlInfo, SdkCapabilities } from './models';
2
2
  import { HttpGatewayInfo } from '../http-gateway/models';
3
3
  import * as ConnectTypes from '@ibm-aspera/connect-sdk-js/dist/esm/core/types';
4
4
  import { Connect, ConnectInstaller } from '@ibm-aspera/connect-sdk-js';
5
- declare class AsperaSdkGlobals {
5
+ export declare class AsperaSdkGlobals {
6
6
  /** The URL of the IBM Aspera HTTP server to use with the SDK */
7
7
  asperaAppUrl: string;
8
8
  /** The URL of the IBM Aspera Desktop HTTP server to use with the SDK */
9
9
  rpcPort: number;
10
+ /** The list of RPC methods supported by the running IBM Aspera for desktop application */
11
+ rpcMethods: string[];
10
12
  /** The default URL to check for latest Aspera installers */
11
13
  installerUrl: string;
12
14
  /** Aspera SDK info */
@@ -161,6 +163,7 @@ export declare class AsperaSdk {
161
163
  /** Global information about IBM Aspera */
162
164
  globals: AsperaSdkGlobals;
163
165
  /** Activity tracking for watching transfers */
166
+ /** @ignore */
164
167
  activityTracking: ActivityTracking;
165
168
  /** HTTP Gateway file store. Key is the file name. */
166
169
  httpGatewaySelectedFiles: Map<string, File>;
@@ -215,10 +218,22 @@ export declare class AsperaSdk {
215
218
  initDragDrop: () => Promise<any>;
216
219
  /** Function to get information about the IBM Aspera instance */
217
220
  getInfo: () => Promise<AsperaSdkInfo>;
221
+ /** Function to read an entire file as an array buffer (base64-encoded) */
222
+ readAsArrayBuffer: (path: string) => Promise<{
223
+ data: string;
224
+ type: string;
225
+ }>;
226
+ /** Function to read a chunk of a file as an array buffer (base64-encoded) */
227
+ readChunkAsArrayBuffer: (path: string, offset: number, chunkSize: number) => Promise<{
228
+ data: string;
229
+ type: string;
230
+ }>;
218
231
  /** Function to get whether IBM Aspera is running on Safari */
219
232
  isSafari: () => boolean;
220
233
  /** Function to get URLs for installer management. */
221
234
  getInstallerUrls: () => InstallerUrlInfo;
235
+ /** Function to get the SDK capabilities. */
236
+ getCapabilities: () => SdkCapabilities;
222
237
  /** Indicate if Safari Extension is enabled. If the extension is disabled during the lifecycle this will not update to disabled. */
223
238
  SAFARI_EXTENSION_STATUS: SafariExtensionEvent;
224
239
  /** Aspera HTTP Gateway calls. This normally is not needed by clients but expose just in case. */
@@ -242,4 +257,3 @@ export declare class AsperaSdk {
242
257
  /** Indicates if old HTTP Gateway SDK should be used (v2 and lower) */
243
258
  get useOldHttpGateway(): boolean;
244
259
  }
245
- export {};
@@ -11,7 +11,7 @@ var __assign = (this && this.__assign) || function () {
11
11
  return __assign.apply(this, arguments);
12
12
  };
13
13
  Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.AsperaSdk = exports.ActivityTracking = void 0;
14
+ exports.AsperaSdk = exports.ActivityTracking = exports.AsperaSdkGlobals = void 0;
15
15
  var constants_1 = require("../constants/constants");
16
16
  var messages_1 = require("../constants/messages");
17
17
  var safari_client_1 = require("../helpers/client/safari-client");
@@ -25,6 +25,8 @@ var AsperaSdkGlobals = /** @class */ (function () {
25
25
  this.asperaAppUrl = 'http://127.0.0.1';
26
26
  /** The URL of the IBM Aspera Desktop HTTP server to use with the SDK */
27
27
  this.rpcPort = 33024;
28
+ /** The list of RPC methods supported by the running IBM Aspera for desktop application */
29
+ this.rpcMethods = [];
28
30
  /** The default URL to check for latest Aspera installers */
29
31
  this.installerUrl = constants_1.installerUrl;
30
32
  /** Indicate that the server has been verified as working */
@@ -79,6 +81,7 @@ var AsperaSdkGlobals = /** @class */ (function () {
79
81
  });
80
82
  return AsperaSdkGlobals;
81
83
  }());
84
+ exports.AsperaSdkGlobals = AsperaSdkGlobals;
82
85
  var ActivityTracking = /** @class */ (function () {
83
86
  function ActivityTracking() {
84
87
  /** Map of callbacks that receive transfer update events */
@@ -283,6 +286,7 @@ var AsperaSdk = /** @class */ (function () {
283
286
  /** Global information about IBM Aspera */
284
287
  this.globals = new AsperaSdkGlobals();
285
288
  /** Activity tracking for watching transfers */
289
+ /** @ignore */
286
290
  this.activityTracking = new ActivityTracking();
287
291
  /** HTTP Gateway file store. Key is the file name. */
288
292
  this.httpGatewaySelectedFiles = new Map();