@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.
Files changed (68) hide show
  1. package/.editorconfig +13 -0
  2. package/.eslintrc.js +128 -0
  3. package/.github/CODE_OF_CONDUCT.md +128 -0
  4. package/.github/CONTRIBUTING.md +147 -0
  5. package/.github/workflows/ci.yml +36 -0
  6. package/.github/workflows/documentation.yml +43 -0
  7. package/.github/workflows/npm_upload.yml +30 -0
  8. package/.husky/pre-commit +4 -0
  9. package/CHANGELOG.md +124 -0
  10. package/LICENSE +201 -0
  11. package/README.md +25 -0
  12. package/dist/commonjs/app/core.d.ts +219 -0
  13. package/dist/commonjs/app/core.js +546 -0
  14. package/dist/commonjs/app/installer.d.ts +9 -0
  15. package/dist/commonjs/app/installer.js +50 -0
  16. package/dist/commonjs/constants/constants.d.ts +6 -0
  17. package/dist/commonjs/constants/constants.js +9 -0
  18. package/dist/commonjs/constants/messages.d.ts +29 -0
  19. package/dist/commonjs/constants/messages.js +32 -0
  20. package/dist/commonjs/helpers/client/client.d.ts +5 -0
  21. package/dist/commonjs/helpers/client/client.js +7 -0
  22. package/dist/commonjs/helpers/client/http-client.d.ts +42 -0
  23. package/dist/commonjs/helpers/client/http-client.js +84 -0
  24. package/dist/commonjs/helpers/client/safari-client.d.ts +99 -0
  25. package/dist/commonjs/helpers/client/safari-client.js +252 -0
  26. package/dist/commonjs/helpers/helpers.d.ts +84 -0
  27. package/dist/commonjs/helpers/helpers.js +197 -0
  28. package/dist/commonjs/helpers/http.d.ts +16 -0
  29. package/dist/commonjs/helpers/http.js +42 -0
  30. package/dist/commonjs/helpers/ws.d.ts +62 -0
  31. package/dist/commonjs/helpers/ws.js +182 -0
  32. package/dist/commonjs/index.d.ts +41 -0
  33. package/dist/commonjs/index.js +99 -0
  34. package/dist/commonjs/models/aspera-sdk.model.d.ts +213 -0
  35. package/dist/commonjs/models/aspera-sdk.model.js +288 -0
  36. package/dist/commonjs/models/models.d.ts +640 -0
  37. package/dist/commonjs/models/models.js +2 -0
  38. package/dist/js/aspera-sdk.js +3 -0
  39. package/dist/js/aspera-sdk.js.LICENSE.txt +7 -0
  40. package/dist/js/aspera-sdk.js.map +1 -0
  41. package/docs/DEVELOPMENT.md +38 -0
  42. package/jest.config.js +15 -0
  43. package/jest.setup.js +0 -0
  44. package/package.json +50 -0
  45. package/src/app/core.ts +610 -0
  46. package/src/app/installer.ts +53 -0
  47. package/src/constants/constants.ts +16 -0
  48. package/src/constants/messages.ts +29 -0
  49. package/src/helpers/client/client.ts +11 -0
  50. package/src/helpers/client/http-client.ts +92 -0
  51. package/src/helpers/client/safari-client.ts +318 -0
  52. package/src/helpers/helpers.ts +200 -0
  53. package/src/helpers/http.ts +39 -0
  54. package/src/helpers/ws.ts +215 -0
  55. package/src/index.html +404 -0
  56. package/src/index.ts +104 -0
  57. package/src/models/aspera-sdk.model.ts +360 -0
  58. package/src/models/models.ts +669 -0
  59. package/tests/client.spec.ts +52 -0
  60. package/tests/core.spec.ts +13 -0
  61. package/tests/helpers.spec.ts +124 -0
  62. package/tests/http.spec.ts +14 -0
  63. package/tests/installer.spec.ts +135 -0
  64. package/tests/mocks.ts +11 -0
  65. package/tsconfig.json +10 -0
  66. package/tsconfig.module.json +15 -0
  67. package/typedoc.js +17 -0
  68. package/webpack.config.js +53 -0
@@ -0,0 +1,52 @@
1
+ import {mockFetch} from './mocks';
2
+ import {httpClient, getRpcServerUrl} from '../src/helpers/client/http-client';
3
+
4
+ let id = 0;
5
+
6
+ const getHeaders = () => {
7
+ return {
8
+ 'content-type': 'application/json',
9
+ };
10
+ };
11
+
12
+ const getMethod = () => {
13
+ return 'POST';
14
+ };
15
+
16
+ const getBody = (method: string, params: any = {}) => {
17
+ return JSON.stringify({
18
+ jsonrpc: '2.0',
19
+ id,
20
+ method,
21
+ params,
22
+ });
23
+ };
24
+
25
+ const getExpectedRequest = (method: string, params: any = {}) => {
26
+ id++;
27
+
28
+ return {
29
+ method: getMethod(),
30
+ headers: getHeaders(),
31
+ body: getBody(method, params),
32
+ };
33
+ };
34
+
35
+ describe('request', () => {
36
+ beforeEach(() => {
37
+ (<any>global).fetch = mockFetch({});
38
+ });
39
+
40
+ const fakeData = {data: 'testing'};
41
+ const rpcServerURL = getRpcServerUrl();
42
+
43
+ test('POST with no params should call url with no params', () => {
44
+ httpClient.request('fake');
45
+ expect(fetch).toHaveBeenCalledWith(rpcServerURL, getExpectedRequest('fake'));
46
+ });
47
+
48
+ test('POST with params should call url with params', () => {
49
+ httpClient.request('fake', fakeData);
50
+ expect(fetch).toHaveBeenCalledWith(rpcServerURL, getExpectedRequest('fake', fakeData));
51
+ });
52
+ });
@@ -0,0 +1,13 @@
1
+ import {mockFetch} from './mocks';
2
+ import {init} from '../src';
3
+
4
+ describe('initHttpGateway', () => {
5
+ beforeEach(() => {
6
+ (<any>global).fetch = mockFetch({});
7
+ });
8
+
9
+ test('calls default URL', async () => {
10
+ init({appId: 'fake'}).catch(() => {});
11
+ // expect(fetch).toBeCalled();
12
+ });
13
+ });
@@ -0,0 +1,124 @@
1
+ import {JSONRPCErrorException} from 'json-rpc-2.0';
2
+ import {
3
+ errorLog,
4
+ generateErrorBody,
5
+ generatePromiseObjects,
6
+ isValidTransferSpec,
7
+ isValidURL
8
+ } from '../src/helpers/helpers';
9
+ import {TransferSpec} from '../src/models/models';
10
+
11
+ describe('generatePromiseObjects', () => {
12
+
13
+ test('returns object containg promise, rejecter and resolver', () => {
14
+ const promiseItem = generatePromiseObjects();
15
+ expect(typeof promiseItem.promise.then).toBe('function');
16
+ expect(typeof promiseItem.resolver).toBe('function');
17
+ expect(typeof promiseItem.rejecter).toBe('function');
18
+ });
19
+ });
20
+
21
+ describe('errorLog', () => {
22
+
23
+ beforeEach(() => {
24
+ (<any>window).asperaSdkLogs = undefined;
25
+ jest.spyOn(global.console, 'warn');
26
+ });
27
+
28
+ test('with message and no debug data should store in array and console', () => {
29
+ const consoleWarnCall = jest.fn();
30
+ console.warn = consoleWarnCall;
31
+ const testMessage = 'Test message';
32
+ expect((<any>window).asperaSdkLogs).toBe(undefined);
33
+ errorLog(testMessage);
34
+ expect(console.warn).toBeCalled();
35
+ expect((<any>window).asperaSdkLogs[0].message).toBe(testMessage);
36
+ expect((<any>window).asperaSdkLogs[0].debugData).toBe(undefined);
37
+ });
38
+
39
+ test('with message and debug data should store in array and console', () => {
40
+ const testMessage = 'Test message';
41
+ expect((<any>window).asperaSdkLogs).toBe(undefined);
42
+ errorLog(testMessage, {error: true});
43
+ expect(console.warn).toBeCalled();
44
+ expect((<any>window).asperaSdkLogs[0].message).toBe(testMessage);
45
+ expect((<any>window).asperaSdkLogs[0].debugData.error).toBe(true);
46
+ });
47
+ });
48
+
49
+ describe('generateErrorBody', () => {
50
+
51
+ test('should return error object without debugData if nothing is passed', () => {
52
+ const errorResponse = generateErrorBody('testing');
53
+ expect(errorResponse.message).toBe('testing');
54
+ expect(errorResponse.error).toBe(true);
55
+ expect(errorResponse.debugData).toBe(undefined);
56
+ });
57
+
58
+ test('should return error object with debugData if data is passed', () => {
59
+ const errorTest = new JSONRPCErrorException('testing error body', -32002, {foo: 'bar'});
60
+ const errorResponse = generateErrorBody('testing', errorTest);
61
+ expect(errorResponse.message).toBe('testing');
62
+ expect(errorResponse.error).toBe(true);
63
+ expect(errorResponse.debugData.message).toBe('testing error body');
64
+ expect(errorResponse.debugData.code).toBe(-32002);
65
+ expect(errorResponse.debugData.data).toStrictEqual({foo: 'bar'});
66
+ });
67
+ });
68
+
69
+ describe('isValidTransferSpec', () => {
70
+ const transferSpec: TransferSpec = {
71
+ authentication: 'token',
72
+ paths: [
73
+ {
74
+ source: '/foo'
75
+ }
76
+ ],
77
+ direction: 'receive',
78
+ remote_host: 'localhost'
79
+ };
80
+ const invalidTransferSpecs: any[] = [
81
+ null,
82
+ undefined,
83
+ 'transfer',
84
+ 85
85
+ ];
86
+
87
+ test('should return true if valid transferSpec', () => {
88
+ expect(isValidTransferSpec(transferSpec)).toBe(true);
89
+ });
90
+
91
+ test('should return false if invalid transferSpec', () => {
92
+ invalidTransferSpecs.forEach(element => {
93
+ expect(isValidTransferSpec(element)).toBe(false);
94
+ });
95
+ });
96
+ });
97
+
98
+ describe('isValidURL', () => {
99
+ const validUrls = [
100
+ 'http://www.aspera.us',
101
+ 'https://www.aspera.us',
102
+ 'https://aspera.us',
103
+ 'https://aspera.us/aspera/sdk/latest.json',
104
+ 'https://aspera.us///aspera/sdk',
105
+ ];
106
+ const invalidUrls = [
107
+ 'aspera.us',
108
+ '/aspera/sdk',
109
+ 'aspera',
110
+ ];
111
+
112
+ test('should return true if valid url', () => {
113
+ validUrls.forEach(url => {
114
+ expect(isValidURL(url)).toBe(true);
115
+ });
116
+ });
117
+
118
+ test('should return false if invalid url', () => {
119
+ invalidUrls.forEach(url => {
120
+ expect(isValidURL(url)).toBe(false);
121
+ });
122
+ });
123
+ });
124
+
@@ -0,0 +1,14 @@
1
+ import {apiGet} from '../src/helpers/http';
2
+ import {mockFetch} from './mocks';
3
+
4
+ describe('apiGet', () => {
5
+
6
+ beforeEach(() => {
7
+ (<any>global).fetch = mockFetch({});
8
+ });
9
+
10
+ test('GET should call url', () => {
11
+ apiGet('aspera.us');
12
+ expect(fetch).toHaveBeenCalledWith('aspera.us', {headers: {'Content-Type': 'application/json'}});
13
+ });
14
+ });
@@ -0,0 +1,135 @@
1
+ import {getInstallerInfo} from '../src/app/installer';
2
+ import {installerUrl} from '../src/constants/constants';
3
+ import {mockFetch} from './mocks';
4
+
5
+ describe('getInstallerInfo', () => {
6
+ const defaultHeaders = {headers: {'Content-Type': 'application/json'}};
7
+
8
+ beforeEach(() => {
9
+ const response = {
10
+ entries: [
11
+ {
12
+ 'version': '1.2.0',
13
+ 'platform': 'macos',
14
+ 'type': 'dmg',
15
+ 'arch': 'universal',
16
+ 'url': 'https://d3gcli72yxqn2z.cloudfront.net/downloads/desktop/macos/1.2.0/stable/universal/ibm-aspera-sdk_1.2.0_macos.dmg'
17
+ },
18
+ {
19
+ 'version': '1.2.0',
20
+ 'platform': 'windows',
21
+ 'type': 'msi',
22
+ 'arch': 'x64',
23
+ 'url': 'https://d3gcli72yxqn2z.cloudfront.net/downloads/desktop/windows/1.2.0/stable/x64/ibm-aspera-sdk_1.2.0.msi'
24
+ },
25
+ {
26
+ 'version': '1.1.9',
27
+ 'platform': 'linux',
28
+ 'type': 'rpm',
29
+ 'arch': 'x64',
30
+ 'url': 'https://d3gcli72yxqn2z.cloudfront.net/downloads/desktop/linux/1.1.9/stable/x64/ibm-aspera-sdk_1.1.9.rpm'
31
+ },
32
+ {
33
+ 'version': '1.1.9',
34
+ 'platform': 'linux',
35
+ 'type': 'appimage',
36
+ 'arch': 'x64',
37
+ 'url': 'https://d3gcli72yxqn2z.cloudfront.net/downloads/desktop/linux/1.1.9/stable/x64/ibm-aspera-sdk_1.1.9.AppImage'
38
+ }
39
+ ]
40
+ };
41
+ (<any>global).fetch = mockFetch(response);
42
+ console.warn = jest.fn();
43
+ });
44
+
45
+ test('called with no options fetches from Amazon CloudFront by default', () => {
46
+ getInstallerInfo().catch(() => {});
47
+ expect(fetch).toHaveBeenCalledWith(`${installerUrl}/latest.json`, defaultHeaders);
48
+ });
49
+
50
+ test('called with no options returns results for specific platform', async () => {
51
+ Object.defineProperty(window.navigator, 'userAgent', {value : 'Macintosh'});
52
+ const exp = [
53
+ {
54
+ 'version': '1.2.0',
55
+ 'platform': 'macos',
56
+ 'type': 'dmg',
57
+ 'arch': 'universal',
58
+ 'url': 'https://d3gcli72yxqn2z.cloudfront.net/downloads/desktop/macos/1.2.0/stable/universal/ibm-aspera-sdk_1.2.0_macos.dmg'
59
+ }
60
+ ];
61
+ const data = await getInstallerInfo();
62
+ expect(data.entries).toEqual(exp);
63
+ });
64
+
65
+ test('called with all returns results for all platforms', async () => {
66
+ const data = await getInstallerInfo({all: true});
67
+ expect(data.entries.length).toBe(4);
68
+ });
69
+
70
+ test('called with endpoint', () => {
71
+ getInstallerInfo({endpoint: 'https://aspera.us/aspera/sdk'}).catch(() => {});
72
+ expect(fetch).toHaveBeenCalledWith('https://aspera.us/aspera/sdk/latest.json', defaultHeaders);
73
+ });
74
+
75
+ test('called with endpoint with trailing json file', () => {
76
+ getInstallerInfo({endpoint: 'https://aspera.us/aspera/sdk/latest.json'}).catch(() => {});
77
+ expect(fetch).toHaveBeenCalledWith('https://aspera.us/aspera/sdk/latest.json', defaultHeaders);
78
+ });
79
+
80
+ test('called with endpoint returns URLs relative to endpoint', async () => {
81
+ const response = {
82
+ entries: [
83
+ {
84
+ 'version': '1.2.0',
85
+ 'platform': 'macos',
86
+ 'type': 'dmg',
87
+ 'arch': 'universal',
88
+ 'url': 'downloads/ibm-aspera-sdk_1.2.0_macos.dmg'
89
+ },
90
+ {
91
+ 'version': '1.2.0',
92
+ 'platform': 'windows',
93
+ 'type': 'msi',
94
+ 'arch': 'x64',
95
+ 'url': 'downloads/ibm-aspera-sdk_1.2.0.msi'
96
+ },
97
+ {
98
+ 'version': '1.1.9',
99
+ 'platform': 'linux',
100
+ 'type': 'rpm',
101
+ 'arch': 'x64',
102
+ 'url': 'downloads/ibm-aspera-sdk_1.1.9.rpm'
103
+ },
104
+ {
105
+ 'version': '1.1.9',
106
+ 'platform': 'linux',
107
+ 'type': 'appimage',
108
+ 'arch': 'x64',
109
+ 'url': 'downloads/ibm-aspera-sdk_1.1.9.AppImage'
110
+ }
111
+ ]
112
+ };
113
+ (<any>global).fetch = mockFetch(response);
114
+ const data = await getInstallerInfo({endpoint: 'https://aspera.us/aspera/sdk', all: true});
115
+ for (const entry of data.entries) {
116
+ expect(entry.url.startsWith('https://aspera.us/aspera/sdk/downloads/ibm-aspera-sdk')).toBe(true);
117
+ }
118
+ });
119
+
120
+ test('called with invalid endpoint rejects', () => {
121
+ const response = {
122
+ entries: [
123
+ {
124
+ 'version': '1.2.0',
125
+ 'platform': 'macos',
126
+ 'type': 'dmg',
127
+ 'arch': 'universal',
128
+ 'url': 'downloads/ibm-aspera-sdk_1.2.0_macos.dmg'
129
+ }
130
+ ]
131
+ };
132
+ (<any>global).fetch = mockFetch(response);
133
+ return expect(getInstallerInfo({endpoint: 'aspera.us'})).rejects.toMatchObject({error: true});
134
+ });
135
+ });
package/tests/mocks.ts ADDED
@@ -0,0 +1,11 @@
1
+ export const mockFetch = (data: any) => {
2
+ const returnPromise = new Promise(resolver => {
3
+ resolver(data);
4
+ });
5
+ return jest.fn().mockImplementation(() => {
6
+ return Promise.resolve({
7
+ ok: true,
8
+ json:() => returnPromise.catch(() => {}),
9
+ });
10
+ });
11
+ };
package/tsconfig.json ADDED
@@ -0,0 +1,10 @@
1
+ {
2
+ "compilerOptions": {
3
+ "outDir": "./dist/js",
4
+ "noImplicitAny": true,
5
+ "module": "es6",
6
+ "target": "es5",
7
+ "esModuleInterop": true,
8
+ "moduleResolution": "node",
9
+ }
10
+ }
@@ -0,0 +1,15 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "es5",
4
+ "module": "commonjs",
5
+ "lib": ["es2017", "es7", "es6", "dom"],
6
+ "declaration": true,
7
+ "outDir": "dist/commonjs",
8
+ "esModuleInterop": true
9
+ },
10
+ "exclude": [
11
+ "node_modules",
12
+ "dist",
13
+ "tests"
14
+ ]
15
+ }
package/typedoc.js ADDED
@@ -0,0 +1,17 @@
1
+ module.exports = {
2
+ mode: 'file',
3
+ out: 'docs',
4
+ theme: 'default',
5
+ ignoreCompilerErrors: true,
6
+ excludePrivate: false,
7
+ excludeNotExported: true,
8
+ target: 'ES6',
9
+ moduleResolution: 'node',
10
+ preserveConstEnums: 'true',
11
+ stripInternal: 'true',
12
+ suppressExcessPropertyErrors: 'true',
13
+ suppressImplicitAnyIndexErrors: 'true',
14
+ module: 'commonjs',
15
+ name: 'IBM Aspera JavaScript Library',
16
+ hideGenerator: true
17
+ };
@@ -0,0 +1,53 @@
1
+ const path = require('path');
2
+ const webpack = require('webpack');
3
+
4
+ const packageFile = require('./package.json');
5
+ let version = '';
6
+
7
+ if (packageFile.version) {
8
+ version = `v${packageFile.version}`;
9
+ }
10
+
11
+ const banner = `IBM Aspera SDK ${version}\nLicensed Materials – Property of IBM\n© Copyright IBM Corp. 2024\nU.S. Government Users Restricted Rights: Use, duplication or disclosure restricted by\nGSA ADP Schedule Contract with IBM Corp.`;
12
+
13
+ module.exports = {
14
+ entry: './src/index.ts',
15
+ devtool: 'source-map',
16
+ output: {
17
+ path: path.resolve(__dirname, 'dist/js'),
18
+ filename: 'aspera-sdk.js'
19
+ },
20
+ resolve: {
21
+ extensions: ['.tsx', '.ts', '.js', '.json']
22
+ },
23
+ module: {
24
+ rules: [
25
+ {
26
+ test: /\.tsx?$/,
27
+ use: ['ts-loader'],
28
+ exclude: /node_modules/
29
+ }
30
+ ]
31
+ },
32
+ devServer: {
33
+ server: {
34
+ type: 'https',
35
+ },
36
+ open: true,
37
+ static: [
38
+ {
39
+ publicPath: '/',
40
+ directory: './src',
41
+ },
42
+ {
43
+ publicPath: '/aspera-sdk-js/docs',
44
+ directory: './dist/js/docs',
45
+ },
46
+ ],
47
+ host: 'js-sdk.aspera.us',
48
+ port: 4205
49
+ },
50
+ plugins: [
51
+ new webpack.BannerPlugin(banner)
52
+ ]
53
+ };