@ibm-aspera/sdk 0.2.6 → 0.2.8

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.
Files changed (51) hide show
  1. package/README.md +3 -0
  2. package/dist/commonjs/app/core.d.ts +2 -1
  3. package/dist/commonjs/app/core.js +10 -3
  4. package/dist/commonjs/constants/messages.d.ts +1 -0
  5. package/dist/commonjs/constants/messages.js +1 -0
  6. package/dist/commonjs/helpers/client/safari-client.d.ts +4 -2
  7. package/dist/commonjs/helpers/client/safari-client.js +22 -10
  8. package/dist/commonjs/index.d.ts +2 -2
  9. package/dist/commonjs/index.js +2 -1
  10. package/dist/commonjs/models/aspera-sdk.model.d.ts +16 -1
  11. package/dist/commonjs/models/aspera-sdk.model.js +32 -2
  12. package/dist/js/aspera-sdk.js +1 -1
  13. package/dist/js/aspera-sdk.js.LICENSE.txt +2 -2
  14. package/dist/js/aspera-sdk.js.map +1 -1
  15. package/package.json +4 -3
  16. package/.editorconfig +0 -13
  17. package/.eslintrc.js +0 -128
  18. package/.github/CODE_OF_CONDUCT.md +0 -128
  19. package/.github/CONTRIBUTING.md +0 -147
  20. package/.github/workflows/ci.yml +0 -36
  21. package/.github/workflows/documentation.yml +0 -43
  22. package/.github/workflows/npm_upload.yml +0 -30
  23. package/.husky/pre-commit +0 -4
  24. package/CHANGELOG.md +0 -152
  25. package/docs/DEVELOPMENT.md +0 -38
  26. package/jest.config.js +0 -15
  27. package/jest.setup.js +0 -0
  28. package/src/app/core.ts +0 -611
  29. package/src/app/installer.ts +0 -53
  30. package/src/constants/constants.ts +0 -19
  31. package/src/constants/messages.ts +0 -29
  32. package/src/helpers/client/client.ts +0 -11
  33. package/src/helpers/client/http-client.ts +0 -92
  34. package/src/helpers/client/safari-client.ts +0 -318
  35. package/src/helpers/helpers.ts +0 -214
  36. package/src/helpers/http.ts +0 -39
  37. package/src/helpers/ws.ts +0 -215
  38. package/src/index.html +0 -404
  39. package/src/index.ts +0 -77
  40. package/src/models/aspera-sdk.model.ts +0 -364
  41. package/src/models/models.ts +0 -676
  42. package/tests/client.spec.ts +0 -52
  43. package/tests/core.spec.ts +0 -13
  44. package/tests/helpers.spec.ts +0 -124
  45. package/tests/http.spec.ts +0 -14
  46. package/tests/installer.spec.ts +0 -135
  47. package/tests/mocks.ts +0 -11
  48. package/tsconfig.json +0 -10
  49. package/tsconfig.module.json +0 -15
  50. package/typedoc.js +0 -17
  51. package/webpack.config.js +0 -53
@@ -1,11 +0,0 @@
1
- import {httpClient} from './http-client';
2
- import {safariClient} from './safari-client';
3
- import {isSafari} from '../helpers';
4
-
5
- interface Client {
6
- request(method: String, payload?: any): Promise<any>;
7
- }
8
-
9
- export const client: Client = isSafari() ? safariClient : httpClient;
10
-
11
- export default Client;
@@ -1,92 +0,0 @@
1
- import {JSONRPCClient, JSONRPCRequest} from 'json-rpc-2.0';
2
- import Client from './client';
3
- import {generatePromiseObjects} from '../helpers';
4
- import {asperaSdk} from '../../index';
5
-
6
- export const getRpcServerUrl = (): string => {
7
- return `${asperaSdk.globals.asperaAppUrl}:${asperaSdk.globals.rpcPort}`;
8
- };
9
-
10
- /**
11
- * Wraps a promise like object and returns a promise that supports catch.
12
- *
13
- * @param promise the HTTP promise like to wrap
14
- *
15
- * @returns promise for the HTTP connection with catch supporting error
16
- */
17
- export const handlePromiseLikeErrors = (promise: PromiseLike<any>): Promise<any> => {
18
- const promiseInfo = generatePromiseObjects();
19
-
20
- promise.then(response => {
21
- promiseInfo.resolver(response);
22
- }, error => {
23
- promiseInfo.rejecter(error);
24
- });
25
-
26
- return promiseInfo.promise;
27
- };
28
-
29
- /**
30
- * JSON RPC client using HTTP (fetch) as transport.
31
- */
32
- class JSONRPCHttpClient {
33
- /** JSON-RPC client used to make requests */
34
- client: JSONRPCClient;
35
-
36
- constructor() {
37
- this.client = new JSONRPCClient(this.handleRequest);
38
- }
39
-
40
- /**
41
- * Request handler for the JSON-RPC client. This function is called by the JSON-RPC library
42
- * after forming the RPC request.
43
- *
44
- * @param request JSON-RPC request to send to the server
45
- */
46
- private handleRequest = (request: JSONRPCRequest) => {
47
- const options = {
48
- method: 'POST',
49
- headers: {
50
- 'content-type': 'application/json',
51
- },
52
- body: JSON.stringify(request),
53
- };
54
-
55
- const rpcServerURL = getRpcServerUrl();
56
-
57
- return fetch(rpcServerURL, options).then(response => {
58
- if (response.ok) {
59
- return response.json().then(rpcResponse => this.client.receive(rpcResponse));
60
- } else if (request.id !== undefined) {
61
- throw Promise.reject(response.statusText);
62
- }
63
- });
64
- };
65
-
66
- request = (method: string, data: any): PromiseLike<any> => {
67
- return this.client.request(method, data);
68
- };
69
- }
70
-
71
- /**
72
- * Client used for making requests to Aspera.
73
- */
74
- class HttpClient implements Client {
75
- /** HTTP client used to make requests */
76
- httpClient: JSONRPCHttpClient;
77
-
78
- constructor() {
79
- this.httpClient = new JSONRPCHttpClient();
80
- };
81
-
82
- request = (method: string, payload: any = {}): Promise<any> => {
83
- return handlePromiseLikeErrors(this.httpClient.request(method, payload));
84
- };
85
- }
86
-
87
- export const httpClient = new HttpClient();
88
-
89
- export default {
90
- httpClient,
91
- handlePromiseLikeErrors,
92
- };
@@ -1,318 +0,0 @@
1
- import Client from './client';
2
- import {randomUUID} from '../helpers';
3
- import {asperaSdk} from '../../index';
4
-
5
- /**
6
- * Enum defining different types of Safari extension events.
7
- */
8
- enum SafariExtensionEventType {
9
- Monitor = 'Monitor',
10
- Ping = 'Ping',
11
- Request = 'Request'
12
- }
13
-
14
- /**
15
- * Interface representing a JSON-RPC request object.
16
- */
17
- interface JSONRPCRequest {
18
- id: string;
19
- jsonrpc: string;
20
- method: string;
21
- params: any;
22
- }
23
-
24
- /**
25
- * Interface representing a JSON-RPC response object.
26
- */
27
- interface JSONRPCResponse {
28
- id: string;
29
- jsonrpc: string;
30
- result?: any;
31
- error?: any;
32
- }
33
-
34
- /**
35
- * Interface representing a promise executor used in a promise.
36
- */
37
- export interface PromiseExecutor {
38
- resolve: (value: any) => void;
39
- reject: (error: any) => void;
40
- }
41
-
42
- /**
43
- * Global keep alive timeout to prevent recursion.
44
- */
45
- let keepAliveTimeout: ReturnType<typeof setTimeout>;
46
-
47
- /**
48
- * Handles communication with the Safari extension using JSON-RPC over custom events.
49
- */
50
- export class SafariClient implements Client {
51
- private statusInterval = 100;
52
- private keepAliveInterval = 1000;
53
- private promiseExecutors: Map<string, PromiseExecutor>;
54
-
55
- private isFirstPing = true;
56
- private lastPing: number|null = null;
57
- private lastPong: number|null = null;
58
- private safariExtensionEnabled = false;
59
- private subscribedTransferActivity = false;
60
-
61
- /**
62
- * Initializes the SafariExtensionHandler instance.
63
- * Sets up the promise executor map and starts listening to extension events.
64
- */
65
- constructor() {
66
- this.promiseExecutors = new Map();
67
- this.listenResponseEvents();
68
- this.listenTransferActivityEvents();
69
- this.listenStatusEvents();
70
- this.listenPongEvents();
71
-
72
- if (keepAliveTimeout) {
73
- clearTimeout(keepAliveTimeout);
74
- }
75
-
76
- this.keepAlive();
77
- }
78
-
79
- /**
80
- * Sends a JSON-RPC request to the Safari extension.
81
- * @param method The method name to invoke on the extension.
82
- * @param payload Optional payload for the request.
83
- * @returns A Promise that resolves with the response from the extension.
84
- */
85
- request = (method: string, payload: any = {}): Promise<any> => {
86
- return this.dispatchPromiseEvent(
87
- SafariExtensionEventType.Request,
88
- method,
89
- payload
90
- );
91
- };
92
-
93
- /**
94
- * Monitors transfer activity.
95
- * @returns A Promise that resolves with the response from the extension.
96
- */
97
- public monitorTransferActivity(): Promise<unknown> {
98
- const dispatchMonitorEvent = (): Promise<unknown> => {
99
- const promise = this.dispatchPromiseEvent(
100
- SafariExtensionEventType.Monitor,
101
- 'subscribe_transfer_activity',
102
- [asperaSdk.globals.appId]
103
- );
104
-
105
- return promise.then(() => {
106
- this.subscribedTransferActivity = true;
107
- });
108
- };
109
-
110
- if (this.safariExtensionEnabled) {
111
- return dispatchMonitorEvent();
112
- }
113
-
114
- return new Promise((resolve, reject) => {
115
- const extensionInterval = setInterval(() => {
116
- if (!this.safariExtensionEnabled) {
117
- return;
118
- }
119
-
120
- dispatchMonitorEvent()
121
- .then(resolve)
122
- .catch(reject);
123
-
124
- clearInterval(extensionInterval);
125
- }, 1000);
126
- });
127
- }
128
-
129
- /**
130
- * Builds a JSON-RPC request object with a unique identifier.
131
- * @param method The method name to invoke on the extension.
132
- * @param payload Optional parameters for the method.
133
- * @returns The constructed JSON-RPC request object.
134
- */
135
- private buildRPCRequest(method: string, payload?: unknown): JSONRPCRequest {
136
- return {
137
- jsonrpc: '2.0',
138
- method,
139
- params: payload,
140
- id: randomUUID()
141
- };
142
- }
143
-
144
- /**
145
- * Dispatches a custom event to the document to communicate with the Safari extension.
146
- * @param type The type of Safari extension event to dispatch.
147
- * @param request Optional JSON-RPC request payload to send with the event.
148
- */
149
- private dispatchEvent(type: SafariExtensionEventType, request?: JSONRPCRequest) {
150
- const payload = {
151
- detail: request ?? {}
152
- };
153
-
154
- document.dispatchEvent(new CustomEvent(`AsperaDesktop.${type}`, payload));
155
- }
156
-
157
- /**
158
- * Dispatches a custom event to the document to communicate with the Safari extension.
159
- * @param type The type of Safari extension event to dispatch.
160
- * @param method The method name to invoke on the extension.
161
- * @param payload Optional parameters for the method.
162
- */
163
- private dispatchPromiseEvent(type: SafariExtensionEventType, method: string, payload?: unknown): Promise<any> {
164
- const request = this.buildRPCRequest(method, payload);
165
-
166
- return new Promise<any>((resolve, reject) => {
167
- if (this.safariExtensionEnabled) {
168
- this.promiseExecutors.set(request.id, {resolve, reject});
169
-
170
- this.dispatchEvent(type, request);
171
- } else {
172
- console.warn('The Safari extension is disabled or unresponsive (dispatch event)');
173
- console.warn(`Failed event: ${JSON.stringify(request)}`);
174
-
175
- reject('The Safari extension is disabled or unresponsive (dispatch event)');
176
- }
177
- });
178
- }
179
-
180
- /**
181
- * Handles incoming JSON-RPC responses from the Safari extension.
182
- * Resolves or rejects promises based on the response.
183
- * @param response The JSON-RPC response object received from the extension.
184
- */
185
- private handleResponse(response: JSONRPCResponse) {
186
- const requestId = response.id;
187
- const executor = this.promiseExecutors.get(requestId);
188
-
189
- if (!executor) {
190
- console.warn(`Unable to find a promise executor for ${requestId}`);
191
- console.warn(`Response: ${response}`);
192
- return;
193
- }
194
-
195
- this.promiseExecutors.delete(requestId);
196
-
197
- if (response.error) {
198
- executor.reject(response.error);
199
- return;
200
- }
201
-
202
- executor.resolve(response.result);
203
- }
204
-
205
- /**
206
- * Listens for 'AsperaDesktop.Response' events.
207
- */
208
- private listenResponseEvents() {
209
- document.addEventListener('AsperaDesktop.Response', (event: CustomEvent<JSONRPCResponse>) => {
210
- this.handleResponse(event.detail);
211
- });
212
- }
213
-
214
- /**
215
- * Listens for 'AsperaDesktop.TransferActivity' events.
216
- */
217
- private listenTransferActivityEvents() {
218
- document.addEventListener('AsperaDesktop.TransferActivity', (event: any) => {
219
- asperaSdk.activityTracking.handleTransferActivity(event.detail);
220
- });
221
- }
222
-
223
- /**
224
- * Listens for 'AsperaDesktop.Status' events.
225
- */
226
- private listenStatusEvents() {
227
- document.addEventListener('AsperaDesktop.Status', (event: any) => {
228
- asperaSdk.activityTracking.handleWebSocketEvents(event.detail);
229
- });
230
- }
231
-
232
- /**
233
- * Listens for 'AsperaDesktop.Pong' events.
234
- */
235
- private listenPongEvents() {
236
- document.addEventListener('AsperaDesktop.Pong', () => {
237
- this.lastPong = Date.now();
238
- this.safariExtensionStatusChanged(true);
239
- });
240
- }
241
-
242
- /**
243
- * Sends a keep alive ping according to the defined interval.
244
- */
245
- private keepAlive() {
246
- this.lastPing = Date.now();
247
- this.dispatchEvent(SafariExtensionEventType.Ping);
248
-
249
- if (this.isFirstPing) {
250
- this.isFirstPing = false;
251
- } else {
252
- setTimeout(() => {
253
- this.checkSafariExtensionStatus();
254
- }, this.statusInterval);
255
- }
256
-
257
- keepAliveTimeout = setTimeout(() => {
258
- this.keepAlive();
259
- }, this.keepAliveInterval);
260
- }
261
-
262
- /**
263
- * Listens for Safari extension status changes.
264
- * If the extension was disabled and enabled again after initializing the SDK, it
265
- * will call 'monitorTransferActivity' to resume transfer activities.
266
- */
267
- private safariExtensionStatusChanged(isEnabled: boolean) {
268
- if (isEnabled === this.safariExtensionEnabled) {
269
- return;
270
- }
271
-
272
- this.safariExtensionEnabled = isEnabled;
273
-
274
- if (isEnabled) {
275
- if (this.subscribedTransferActivity) {
276
- const resumeTransferActivity = () => {
277
- this.monitorTransferActivity()
278
- .catch(() => {
279
- console.error('Failed to resume transfer activity, will try again in 1s');
280
-
281
- setTimeout(() => {
282
- resumeTransferActivity();
283
- }, 1000);
284
- });
285
- };
286
-
287
- resumeTransferActivity();
288
- }
289
- } else {
290
- asperaSdk.activityTracking.handleWebSocketEvents('CLOSED');
291
-
292
- this.promiseExecutors.forEach((promiseExecutor) => {
293
- promiseExecutor.reject('The Safari extension is disabled or unresponsive (extension status)');
294
- });
295
-
296
- this.promiseExecutors.clear();
297
- }
298
-
299
- asperaSdk.activityTracking.handleSafariExtensionEvents(this.safariExtensionEnabled ? 'ENABLED' : 'DISABLED');
300
- }
301
-
302
- /**
303
- * Checks if the last pong received was longer than the max interval.
304
- */
305
- private checkSafariExtensionStatus() {
306
- const pingPongDiff = this.lastPong - this.lastPing;
307
-
308
- if (this.lastPong == null || pingPongDiff < 0 || pingPongDiff > 500) {
309
- this.safariExtensionStatusChanged(false);
310
- }
311
- }
312
- }
313
-
314
- export const safariClient = new SafariClient();
315
-
316
- export default {
317
- safariClient
318
- };
@@ -1,214 +0,0 @@
1
- import {baseInstallerUrl, installerUrl} from '../constants/constants';
2
- import {ErrorResponse, InstallerUrlInfo, PromiseObject, TransferSpec} from '../models/models';
3
-
4
- /**
5
- * Generates promise object that can be resolved or rejected via functions
6
- *
7
- * @returns an object containing the promise, the resolver and rejecter
8
- */
9
- export const generatePromiseObjects = (): PromiseObject => {
10
- let resolver: (response: any) => void;
11
- let rejecter: (response: any) => void;
12
- const promise = new Promise((resolve, reject) => {
13
- resolver = resolve;
14
- rejecter = reject;
15
- });
16
- return {
17
- promise,
18
- resolver,
19
- rejecter
20
- };
21
- };
22
-
23
- /**
24
- * Log errors from Aspera SDK
25
- *
26
- * @param message the message indicating the error encountered
27
- * @param debugData the data with useful debugging information
28
- */
29
- export const errorLog = (message: string, debugData?: any): void => {
30
- if (debugData && debugData.code && debugData.message) {
31
- debugData = {
32
- code: debugData.code,
33
- message: debugData.message,
34
- data: debugData.data
35
- };
36
- }
37
-
38
- if (typeof (<any>window) === 'object') {
39
- if (!Array.isArray((<any>window).asperaSdkLogs)) {
40
- (<any>window).asperaSdkLogs = [];
41
- }
42
- (<any>window).asperaSdkLogs.push({message, debugData});
43
- }
44
-
45
- console.warn(`Aspera SDK: ${message}`, debugData);
46
- };
47
-
48
- /**
49
- * Generate error object for rejecter responses
50
- *
51
- * @param message the message indicating the error encountered
52
- * @param debugData the data with useful debugging information
53
- *
54
- * @returns object containing standardized error response
55
- */
56
- export const generateErrorBody = (message: string, debugData?: any): ErrorResponse => {
57
- const errorResponse: ErrorResponse = {
58
- error: true,
59
- message
60
- };
61
-
62
- if (debugData && debugData.code && debugData.message) {
63
- errorResponse.debugData = {
64
- code: debugData.code,
65
- message: debugData.message,
66
- data: debugData.data
67
- };
68
- }
69
-
70
- return errorResponse;
71
- };
72
-
73
- /**
74
- * Validate if transferSpec is valid for server communication
75
- *
76
- * @param transferSpec the transferSpec to test
77
- *
78
- * @returns boolean indicating whether supplied transferSpec is valid
79
- */
80
- export const isValidTransferSpec = (transferSpec: TransferSpec): boolean => {
81
- if (
82
- transferSpec &&
83
- typeof transferSpec === 'object' &&
84
- typeof transferSpec.direction === 'string' &&
85
- typeof transferSpec.remote_host === 'string' &&
86
- Array.isArray(transferSpec.paths)
87
- ) {
88
- return true;
89
- }
90
-
91
- return false;
92
- };
93
-
94
- /**
95
- * Returns a string indicating the websocket URL to use for talking to the server
96
- *
97
- * @returns a string of the full Websocket URL
98
- */
99
- export const getWebsocketUrl = (serverUrl: string): string => {
100
- let wsProtocol;
101
- if (serverUrl.indexOf('http:') === 0) {
102
- wsProtocol = 'ws';
103
- } else if (serverUrl.indexOf('https:') === 0) {
104
- wsProtocol = 'wss';
105
- }
106
- const url = serverUrl.replace('http://', '//').replace('https://', '//');
107
-
108
- return `${wsProtocol}:${url}`;
109
- };
110
-
111
- /**
112
- * Simple function to get the current platform.
113
- *
114
- * @returns a string indicating the current platform
115
- */
116
- export const getCurrentPlatform = (): 'macos'|'windows'|'linux'|'unknown' => {
117
- const ua = navigator.userAgent;
118
-
119
- if (/Mac/.test(ua)) {
120
- return 'macos';
121
- } else if (/Win/.test(ua)) {
122
- return 'windows';
123
- } else if (/Linux/.test(ua)) {
124
- return 'linux';
125
- } else {
126
- return 'unknown';
127
- }
128
- };
129
-
130
- /**
131
- * Function used to create a random UUID
132
- *
133
- * @returns string
134
- */
135
- export const randomUUID = (): string => {
136
- const fallback = (): string => {
137
- return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
138
- let r = Number(((new Date().getTime() + 16) * Math.random()).toFixed()) % 16;
139
- if (c !== 'x') {
140
- // eslint-disable-next-line no-bitwise
141
- r = r & 0x3 | 0x8;
142
- }
143
- return r.toString(16);
144
- });
145
- };
146
-
147
- return window.crypto?.randomUUID ? window.crypto.randomUUID() : fallback();
148
- };
149
-
150
- /**
151
- * Return a rejected promise
152
- *
153
- * @param message the message indicating the error encountered
154
- * @param debugData the data with useful debugging information
155
- *
156
- * @returns a rejected promise
157
- */
158
- export const throwError = (message: string, debugData?: any): Promise<any> => {
159
- errorLog(message, debugData);
160
- return new Promise((resolve, reject) => {
161
- reject(generateErrorBody(message, debugData));
162
- });
163
- };
164
-
165
- /**
166
- * Check if the given string is a valid URL
167
- *
168
- * @param url string to check if valid URL
169
- *
170
- * @returns boolean
171
- */
172
- export const isValidURL = (url: string): boolean => {
173
- try {
174
- new URL(url);
175
- return true;
176
- } catch(error) {
177
- return false;
178
- }
179
- };
180
-
181
- /**
182
- * Checks if the current browser is Safari.
183
- * @returns {boolean} Whether the browser is Safari.
184
- */
185
- export const isSafari = (): boolean => {
186
- // eslint-disable-next-line
187
- return /^((?!chrome|android).)*safari/i.test(navigator.userAgent) && !(window as any).MSStream;
188
- };
189
-
190
- /**
191
- * Get the URLs for installer management.
192
- *
193
- * @returns Info on URLs where installers live
194
- */
195
- export const getInstallerUrls = (): InstallerUrlInfo => {
196
- return {
197
- base: baseInstallerUrl,
198
- latest: installerUrl,
199
- };
200
- };
201
-
202
- export default {
203
- errorLog,
204
- generateErrorBody,
205
- generatePromiseObjects,
206
- getCurrentPlatform,
207
- getWebsocketUrl,
208
- isSafari,
209
- isValidURL,
210
- isValidTransferSpec,
211
- randomUUID,
212
- throwError,
213
- getInstallerUrls,
214
- };
@@ -1,39 +0,0 @@
1
- import {generatePromiseObjects} from './helpers';
2
-
3
- /**
4
- * Check HTTP promise response for server error response (non 2XX status) and reject promise is error
5
- *
6
- * @param promise the HTTP promise to check for HTTP status code of 2XX for success
7
- *
8
- * @returns promise for the HTTP connection with catch supporting error
9
- */
10
- export const handlePromiseErrors = (promise: Promise<any>): Promise<any> => {
11
- const promiseInfo = generatePromiseObjects();
12
- promise.then(response => {
13
- if (response.ok) {
14
- promiseInfo.resolver(response);
15
- } else {
16
- promiseInfo.rejecter(response);
17
- }
18
- return response;
19
- }).catch(error => {
20
- promiseInfo.rejecter(error);
21
- });
22
- return promiseInfo.promise;
23
- };
24
-
25
-
26
- /**
27
- * Make a GET for retrieving data from a server
28
- *
29
- * @param url the url string of the resource on the server
30
- *
31
- * @returns a promise that will resolve with the response from the server or reject if network/server error
32
- */
33
- export const apiGet = (url: string): Promise<any> => {
34
- return handlePromiseErrors(fetch(url, {
35
- headers: {
36
- 'Content-Type': 'application/json',
37
- },
38
- }));
39
- };