@ibm-aspera/sdk 0.2.29 → 0.2.30

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 (112) hide show
  1. package/dist/commonjs/app/core.d.ts +191 -0
  2. package/dist/commonjs/app/core.js +682 -0
  3. package/dist/commonjs/app/installer.d.ts +9 -0
  4. package/dist/commonjs/app/installer.js +50 -0
  5. package/dist/commonjs/connect/core.d.ts +11 -0
  6. package/dist/commonjs/connect/core.js +73 -0
  7. package/dist/commonjs/constants/constants.d.ts +8 -0
  8. package/dist/commonjs/constants/constants.js +11 -0
  9. package/dist/commonjs/constants/messages.d.ts +35 -0
  10. package/dist/commonjs/constants/messages.js +38 -0
  11. package/dist/commonjs/helpers/client/client.d.ts +5 -0
  12. package/dist/commonjs/helpers/client/client.js +7 -0
  13. package/dist/commonjs/helpers/client/http-client.d.ts +42 -0
  14. package/dist/commonjs/helpers/client/http-client.js +84 -0
  15. package/dist/commonjs/helpers/client/safari-client.d.ts +101 -0
  16. package/dist/commonjs/helpers/client/safari-client.js +264 -0
  17. package/dist/commonjs/helpers/helpers.d.ts +109 -0
  18. package/dist/commonjs/helpers/helpers.js +249 -0
  19. package/dist/commonjs/helpers/http.d.ts +16 -0
  20. package/dist/commonjs/helpers/http.js +42 -0
  21. package/dist/commonjs/helpers/ws.d.ts +62 -0
  22. package/dist/commonjs/helpers/ws.js +161 -0
  23. package/dist/commonjs/http-gateway/core.d.ts +76 -0
  24. package/dist/commonjs/http-gateway/core.js +254 -0
  25. package/dist/commonjs/http-gateway/download.d.ts +14 -0
  26. package/dist/commonjs/http-gateway/download.js +187 -0
  27. package/dist/commonjs/http-gateway/index.d.ts +11 -0
  28. package/dist/commonjs/http-gateway/index.js +11 -0
  29. package/dist/commonjs/http-gateway/models.d.ts +16 -0
  30. package/dist/commonjs/http-gateway/models.js +2 -0
  31. package/dist/commonjs/http-gateway/upload.d.ts +14 -0
  32. package/dist/commonjs/http-gateway/upload.js +124 -0
  33. package/dist/commonjs/index.d.ts +8 -0
  34. package/dist/commonjs/index.js +100 -0
  35. package/dist/commonjs/models/aspera-sdk.model.d.ts +245 -0
  36. package/dist/commonjs/models/aspera-sdk.model.js +345 -0
  37. package/dist/commonjs/models/models.d.ts +712 -0
  38. package/dist/commonjs/models/models.js +2 -0
  39. package/dist/js/aspera-sdk.js +3 -0
  40. package/dist/js/aspera-sdk.js.LICENSE.txt +15 -0
  41. package/dist/js/aspera-sdk.js.map +1 -0
  42. package/package.json +5 -1
  43. package/.editorconfig +0 -13
  44. package/.github/CODEOWNERS +0 -1
  45. package/.github/CODE_OF_CONDUCT.md +0 -128
  46. package/.github/CONTRIBUTING.md +0 -147
  47. package/.github/dependabot.yml +0 -10
  48. package/.github/workflows/ci.yml +0 -39
  49. package/.github/workflows/documentation.yml +0 -44
  50. package/.github/workflows/publish.yml +0 -23
  51. package/.github/workflows/version.yml +0 -32
  52. package/.whitesource +0 -3
  53. package/CHANGELOG.md +0 -204
  54. package/docs/DEVELOPMENT.md +0 -38
  55. package/eslint.config.js +0 -104
  56. package/example/README.md +0 -7
  57. package/example/index.html +0 -14
  58. package/example/package-lock.json +0 -2989
  59. package/example/package.json +0 -30
  60. package/example/public/404.html +0 -5
  61. package/example/public/sdk-code.js +0 -326
  62. package/example/src/App/App.scss +0 -40
  63. package/example/src/App/index.tsx +0 -196
  64. package/example/src/Views/AllTogether.tsx +0 -26
  65. package/example/src/Views/DragDrop.tsx +0 -23
  66. package/example/src/Views/Home.tsx +0 -10
  67. package/example/src/Views/Initialize.tsx +0 -31
  68. package/example/src/Views/Installer.tsx +0 -154
  69. package/example/src/Views/MonitorTransfers.tsx +0 -88
  70. package/example/src/Views/Other.tsx +0 -24
  71. package/example/src/Views/SelectItems.tsx +0 -46
  72. package/example/src/Views/StartTransfer.tsx +0 -37
  73. package/example/src/Views/Test.tsx +0 -20
  74. package/example/src/Views/Views.scss +0 -111
  75. package/example/src/helpers/index.ts +0 -19
  76. package/example/src/index.scss +0 -47
  77. package/example/src/main.tsx +0 -17
  78. package/example/src/vite-env.d.ts +0 -2
  79. package/example/tsconfig.json +0 -30
  80. package/example/vite.config.ts +0 -23
  81. package/jest.config.js +0 -19
  82. package/jest.setup.js +0 -0
  83. package/renovate.json +0 -12
  84. package/src/app/core.ts +0 -765
  85. package/src/app/installer.ts +0 -53
  86. package/src/connect/core.ts +0 -83
  87. package/src/constants/constants.ts +0 -19
  88. package/src/constants/messages.ts +0 -35
  89. package/src/helpers/client/client.ts +0 -11
  90. package/src/helpers/client/http-client.ts +0 -92
  91. package/src/helpers/client/safari-client.ts +0 -334
  92. package/src/helpers/helpers.ts +0 -253
  93. package/src/helpers/http.ts +0 -39
  94. package/src/helpers/ws.ts +0 -191
  95. package/src/http-gateway/core.ts +0 -273
  96. package/src/http-gateway/download.ts +0 -217
  97. package/src/http-gateway/index.ts +0 -19
  98. package/src/http-gateway/models.ts +0 -20
  99. package/src/http-gateway/upload.ts +0 -148
  100. package/src/index.ts +0 -72
  101. package/src/models/aspera-sdk.model.ts +0 -446
  102. package/src/models/models.ts +0 -740
  103. package/tests/client.spec.ts +0 -52
  104. package/tests/core.spec.ts +0 -13
  105. package/tests/helpers.spec.ts +0 -127
  106. package/tests/http.spec.ts +0 -14
  107. package/tests/installer.spec.ts +0 -135
  108. package/tests/mocks.ts +0 -11
  109. package/tsconfig.json +0 -14
  110. package/tsconfig.module.json +0 -16
  111. package/typedoc.js +0 -7
  112. package/webpack.config.js +0 -35
@@ -0,0 +1,264 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.safariClient = exports.SafariClient = void 0;
4
+ var helpers_1 = require("../helpers");
5
+ var index_1 = require("../../index");
6
+ /**
7
+ * Enum defining different types of Safari extension events.
8
+ */
9
+ var SafariExtensionEventType;
10
+ (function (SafariExtensionEventType) {
11
+ SafariExtensionEventType["Monitor"] = "Monitor";
12
+ SafariExtensionEventType["Ping"] = "Ping";
13
+ SafariExtensionEventType["Request"] = "Request";
14
+ })(SafariExtensionEventType || (SafariExtensionEventType = {}));
15
+ /**
16
+ * Global keep alive timeout to prevent recursion.
17
+ */
18
+ var keepAliveTimeout;
19
+ /**
20
+ * Handles communication with the Safari extension using JSON-RPC over custom events.
21
+ */
22
+ var SafariClient = /** @class */ (function () {
23
+ /**
24
+ * Initializes the SafariExtensionHandler instance.
25
+ * Sets up the promise executor map and starts listening to extension events.
26
+ */
27
+ function SafariClient() {
28
+ var _this = this;
29
+ this.keepAliveInterval = 1000;
30
+ this.lastPing = null;
31
+ this.lastPong = null;
32
+ this.safariExtensionEnabled = false;
33
+ this.subscribedTransferActivity = false;
34
+ /**
35
+ * Sends a JSON-RPC request to the Safari extension.
36
+ * @param method The method name to invoke on the extension.
37
+ * @param payload Optional payload for the request.
38
+ * @returns A Promise that resolves with the response from the extension.
39
+ */
40
+ this.request = function (method, payload) {
41
+ if (payload === void 0) { payload = {}; }
42
+ return _this.dispatchPromiseEvent(SafariExtensionEventType.Request, method, payload);
43
+ };
44
+ this.promiseExecutors = new Map();
45
+ this.listenResponseEvents();
46
+ this.listenTransferActivityEvents();
47
+ this.listenStatusEvents();
48
+ this.listenClientStatusEvents();
49
+ this.listenPongEvents();
50
+ if (keepAliveTimeout) {
51
+ clearTimeout(keepAliveTimeout);
52
+ }
53
+ this.keepAlive();
54
+ }
55
+ /**
56
+ * Monitors transfer activity.
57
+ * @returns A Promise that resolves with the response from the extension.
58
+ */
59
+ SafariClient.prototype.monitorTransferActivity = function () {
60
+ var _this = this;
61
+ var dispatchMonitorEvent = function () {
62
+ var promise = _this.dispatchPromiseEvent(SafariExtensionEventType.Monitor, 'subscribe_transfer_activity', [index_1.asperaSdk.globals.appId]);
63
+ return promise.then(function () {
64
+ _this.subscribedTransferActivity = true;
65
+ });
66
+ };
67
+ if (this.safariExtensionEnabled) {
68
+ return dispatchMonitorEvent();
69
+ }
70
+ return new Promise(function (resolve, reject) {
71
+ var extensionInterval = setInterval(function () {
72
+ if (!_this.safariExtensionEnabled) {
73
+ return;
74
+ }
75
+ dispatchMonitorEvent()
76
+ .then(resolve)
77
+ .catch(reject);
78
+ clearInterval(extensionInterval);
79
+ }, 1000);
80
+ });
81
+ };
82
+ /**
83
+ * Builds a JSON-RPC request object with a unique identifier.
84
+ * @param method The method name to invoke on the extension.
85
+ * @param payload Optional parameters for the method.
86
+ * @returns The constructed JSON-RPC request object.
87
+ */
88
+ SafariClient.prototype.buildRPCRequest = function (method, payload) {
89
+ return {
90
+ jsonrpc: '2.0',
91
+ method: method,
92
+ params: payload,
93
+ id: (0, helpers_1.randomUUID)()
94
+ };
95
+ };
96
+ /**
97
+ * Dispatches a custom event to the document to communicate with the Safari extension.
98
+ * @param type The type of Safari extension event to dispatch.
99
+ * @param request Optional JSON-RPC request payload to send with the event.
100
+ */
101
+ SafariClient.prototype.dispatchEvent = function (type, request) {
102
+ var payload = {
103
+ detail: request !== null && request !== void 0 ? request : {}
104
+ };
105
+ document.dispatchEvent(new CustomEvent("AsperaDesktop.".concat(type), payload));
106
+ };
107
+ /**
108
+ * Dispatches a custom event to the document to communicate with the Safari extension.
109
+ * @param type The type of Safari extension event to dispatch.
110
+ * @param method The method name to invoke on the extension.
111
+ * @param payload Optional parameters for the method.
112
+ */
113
+ SafariClient.prototype.dispatchPromiseEvent = function (type, method, payload) {
114
+ var _this = this;
115
+ var request = this.buildRPCRequest(method, payload);
116
+ return new Promise(function (resolve, reject) {
117
+ if (_this.safariExtensionEnabled) {
118
+ _this.promiseExecutors.set(request.id, { resolve: resolve, reject: reject });
119
+ _this.dispatchEvent(type, request);
120
+ }
121
+ else {
122
+ console.warn('The Safari extension is disabled or unresponsive (dispatch event)');
123
+ console.warn("Failed event: ".concat((0, helpers_1.safeJsonString)(request)));
124
+ reject('The Safari extension is disabled or unresponsive (dispatch event)');
125
+ }
126
+ });
127
+ };
128
+ /**
129
+ * Handles incoming JSON-RPC responses from the Safari extension.
130
+ * Resolves or rejects promises based on the response.
131
+ * @param response The JSON-RPC response object received from the extension.
132
+ */
133
+ SafariClient.prototype.handleResponse = function (response) {
134
+ var requestId = response.id;
135
+ var executor = this.promiseExecutors.get(requestId);
136
+ if (!executor) {
137
+ console.warn("Unable to find a promise executor for ".concat(requestId));
138
+ console.warn("Response: ".concat(response));
139
+ return;
140
+ }
141
+ this.promiseExecutors.delete(requestId);
142
+ if (response.error) {
143
+ executor.reject(response.error);
144
+ return;
145
+ }
146
+ executor.resolve(response.result);
147
+ };
148
+ /**
149
+ * Listens for 'AsperaDesktop.Response' events.
150
+ */
151
+ SafariClient.prototype.listenResponseEvents = function () {
152
+ var _this = this;
153
+ document.addEventListener('AsperaDesktop.Response', function (event) {
154
+ if (!event.detail) {
155
+ return;
156
+ }
157
+ _this.handleResponse(event.detail);
158
+ });
159
+ };
160
+ /**
161
+ * Listens for 'AsperaDesktop.TransferActivity' events.
162
+ */
163
+ SafariClient.prototype.listenTransferActivityEvents = function () {
164
+ document.addEventListener('AsperaDesktop.TransferActivity', function (event) {
165
+ if (!event.detail) {
166
+ return;
167
+ }
168
+ index_1.asperaSdk.activityTracking.handleTransferActivity(event.detail);
169
+ });
170
+ };
171
+ /**
172
+ * Listens for 'AsperaDesktop.Status' events.
173
+ */
174
+ SafariClient.prototype.listenStatusEvents = function () {
175
+ document.addEventListener('AsperaDesktop.Status', function (event) {
176
+ if (!event.detail) {
177
+ return;
178
+ }
179
+ index_1.asperaSdk.activityTracking.handleWebSocketEvents(event.detail);
180
+ });
181
+ };
182
+ /**
183
+ * Listens for 'isAppAlive' events. This was introduced in version 1.0.9.
184
+ */
185
+ SafariClient.prototype.listenClientStatusEvents = function () {
186
+ document.addEventListener('isAppAlive', function (event) {
187
+ var _a;
188
+ if (!((_a = event.detail) === null || _a === void 0 ? void 0 : _a.running)) {
189
+ return;
190
+ }
191
+ index_1.asperaSdk.activityTracking.handleClientEvents(event.detail.running);
192
+ });
193
+ };
194
+ /**
195
+ * Listens for 'AsperaDesktop.Pong' events.
196
+ */
197
+ SafariClient.prototype.listenPongEvents = function () {
198
+ var _this = this;
199
+ document.addEventListener('AsperaDesktop.Pong', function () {
200
+ _this.lastPong = Date.now();
201
+ _this.safariExtensionStatusChanged(true);
202
+ });
203
+ };
204
+ /**
205
+ * Sends a keep alive ping according to the defined interval.
206
+ */
207
+ SafariClient.prototype.keepAlive = function () {
208
+ var _this = this;
209
+ this.lastPing = Date.now();
210
+ this.dispatchEvent(SafariExtensionEventType.Ping);
211
+ keepAliveTimeout = setTimeout(function () {
212
+ _this.keepAlive();
213
+ }, this.keepAliveInterval);
214
+ };
215
+ /**
216
+ * Listens for Safari extension status changes.
217
+ * If the extension was disabled and enabled again after initializing the SDK, it
218
+ * will call 'monitorTransferActivity' to resume transfer activities.
219
+ */
220
+ SafariClient.prototype.safariExtensionStatusChanged = function (isEnabled) {
221
+ var _this = this;
222
+ if (isEnabled === this.safariExtensionEnabled) {
223
+ return;
224
+ }
225
+ this.safariExtensionEnabled = isEnabled;
226
+ if (isEnabled) {
227
+ if (this.subscribedTransferActivity) {
228
+ var resumeTransferActivity_1 = function () {
229
+ _this.monitorTransferActivity()
230
+ .catch(function () {
231
+ console.error('Failed to resume transfer activity, will try again in 1s');
232
+ setTimeout(function () {
233
+ resumeTransferActivity_1();
234
+ }, 1000);
235
+ });
236
+ };
237
+ resumeTransferActivity_1();
238
+ }
239
+ }
240
+ else {
241
+ index_1.asperaSdk.activityTracking.handleWebSocketEvents('CLOSED');
242
+ this.promiseExecutors.forEach(function (promiseExecutor) {
243
+ promiseExecutor.reject('The Safari extension is disabled or unresponsive (extension status)');
244
+ });
245
+ this.promiseExecutors.clear();
246
+ }
247
+ index_1.asperaSdk.activityTracking.handleSafariExtensionEvents(this.safariExtensionEnabled ? 'ENABLED' : 'DISABLED');
248
+ };
249
+ /**
250
+ * Checks if the last pong received was longer than the max interval.
251
+ */
252
+ SafariClient.prototype.checkSafariExtensionStatus = function () {
253
+ var pingPongDiff = this.lastPong - this.lastPing;
254
+ if (this.lastPong == null || pingPongDiff < 0 || pingPongDiff > 500) {
255
+ this.safariExtensionStatusChanged(false);
256
+ }
257
+ };
258
+ return SafariClient;
259
+ }());
260
+ exports.SafariClient = SafariClient;
261
+ exports.safariClient = new SafariClient();
262
+ exports.default = {
263
+ safariClient: exports.safariClient
264
+ };
@@ -0,0 +1,109 @@
1
+ import { ErrorResponse, InstallerUrlInfo, PromiseObject, TransferSpec } from '../models/models';
2
+ /**
3
+ * Generates promise object that can be resolved or rejected via functions
4
+ *
5
+ * @returns an object containing the promise, the resolver and rejecter
6
+ */
7
+ export declare const generatePromiseObjects: () => PromiseObject;
8
+ /**
9
+ * Log errors from Aspera SDK
10
+ *
11
+ * @param message the message indicating the error encountered
12
+ * @param debugData the data with useful debugging information
13
+ */
14
+ export declare const errorLog: (message: string, debugData?: any) => void;
15
+ /**
16
+ * Generate error object for rejecter responses
17
+ *
18
+ * @param message the message indicating the error encountered
19
+ * @param debugData the data with useful debugging information
20
+ *
21
+ * @returns object containing standardized error response
22
+ */
23
+ export declare const generateErrorBody: (message: string, debugData?: any) => ErrorResponse;
24
+ /**
25
+ * Validate if transferSpec is valid for server communication
26
+ *
27
+ * @param transferSpec the transferSpec to test
28
+ *
29
+ * @returns boolean indicating whether supplied transferSpec is valid
30
+ */
31
+ export declare const isValidTransferSpec: (transferSpec: TransferSpec) => boolean;
32
+ /**
33
+ * Returns a string indicating the websocket URL to use for talking to the server
34
+ *
35
+ * @returns a string of the full Websocket URL
36
+ */
37
+ export declare const getWebsocketUrl: (serverUrl: string) => string;
38
+ /**
39
+ * Simple function to get the current platform.
40
+ *
41
+ * @returns a string indicating the current platform
42
+ */
43
+ export declare const getCurrentPlatform: () => "macos" | "windows" | "linux" | "unknown";
44
+ /**
45
+ * Function used to create a random UUID
46
+ *
47
+ * @returns string
48
+ */
49
+ export declare const randomUUID: () => string;
50
+ /**
51
+ * Return a rejected promise
52
+ *
53
+ * @param message the message indicating the error encountered
54
+ * @param debugData the data with useful debugging information
55
+ *
56
+ * @returns a rejected promise
57
+ */
58
+ export declare const throwError: (message: string, debugData?: any) => Promise<any>;
59
+ /**
60
+ * Check if the given string is a valid URL
61
+ *
62
+ * @param url string to check if valid URL
63
+ *
64
+ * @returns boolean
65
+ */
66
+ export declare const isValidURL: (url: string) => boolean;
67
+ /**
68
+ * Checks if the current browser is Safari.
69
+ * @returns {boolean} Whether the browser is Safari.
70
+ */
71
+ export declare const isSafari: () => boolean;
72
+ /**
73
+ * Get the URLs for installer management.
74
+ *
75
+ * @returns Info on URLs where installers live
76
+ */
77
+ export declare const getInstallerUrls: () => InstallerUrlInfo;
78
+ /**
79
+ * Try to stringify a JSON string and log failures
80
+ *
81
+ * @param json - Object to make into a string
82
+ *
83
+ * @returns string representing JSON or empty string on error
84
+ */
85
+ export declare const safeJsonString: (json: unknown) => string;
86
+ /**
87
+ * Try to parse a JSON string and log failures
88
+ *
89
+ * @param json - String to make into an object
90
+ *
91
+ * @returns object or array from the JSON string. Or undefined
92
+ */
93
+ export declare const safeJsonParse: (json: string) => any | undefined;
94
+ declare const _default: {
95
+ errorLog: (message: string, debugData?: any) => void;
96
+ generateErrorBody: (message: string, debugData?: any) => ErrorResponse;
97
+ generatePromiseObjects: () => PromiseObject;
98
+ getCurrentPlatform: () => "macos" | "windows" | "linux" | "unknown";
99
+ getWebsocketUrl: (serverUrl: string) => string;
100
+ isSafari: () => boolean;
101
+ isValidURL: (url: string) => boolean;
102
+ isValidTransferSpec: (transferSpec: TransferSpec) => boolean;
103
+ randomUUID: () => string;
104
+ throwError: (message: string, debugData?: any) => Promise<any>;
105
+ getInstallerUrls: () => InstallerUrlInfo;
106
+ safeJsonString: (json: unknown) => string;
107
+ safeJsonParse: (json: string) => any | undefined;
108
+ };
109
+ export default _default;
@@ -0,0 +1,249 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.safeJsonParse = exports.safeJsonString = exports.getInstallerUrls = exports.isSafari = exports.isValidURL = exports.throwError = exports.randomUUID = exports.getCurrentPlatform = exports.getWebsocketUrl = exports.isValidTransferSpec = exports.generateErrorBody = exports.errorLog = exports.generatePromiseObjects = void 0;
4
+ var constants_1 = require("../constants/constants");
5
+ /**
6
+ * Generates promise object that can be resolved or rejected via functions
7
+ *
8
+ * @returns an object containing the promise, the resolver and rejecter
9
+ */
10
+ var generatePromiseObjects = function () {
11
+ var resolver;
12
+ var rejecter;
13
+ var promise = new Promise(function (resolve, reject) {
14
+ resolver = resolve;
15
+ rejecter = reject;
16
+ });
17
+ return {
18
+ promise: promise,
19
+ resolver: resolver,
20
+ rejecter: rejecter
21
+ };
22
+ };
23
+ exports.generatePromiseObjects = generatePromiseObjects;
24
+ /**
25
+ * Log errors from Aspera SDK
26
+ *
27
+ * @param message the message indicating the error encountered
28
+ * @param debugData the data with useful debugging information
29
+ */
30
+ var errorLog = function (message, debugData) {
31
+ if (debugData && debugData.code && debugData.message) {
32
+ debugData = {
33
+ code: debugData.code,
34
+ message: debugData.message,
35
+ data: debugData.data
36
+ };
37
+ }
38
+ if (typeof window === 'object') {
39
+ if (!Array.isArray(window.asperaSdkLogs)) {
40
+ window.asperaSdkLogs = [];
41
+ }
42
+ window.asperaSdkLogs.push({ message: message, debugData: debugData });
43
+ }
44
+ console.warn("Aspera SDK: ".concat(message), debugData);
45
+ };
46
+ exports.errorLog = errorLog;
47
+ /**
48
+ * Generate error object for rejecter responses
49
+ *
50
+ * @param message the message indicating the error encountered
51
+ * @param debugData the data with useful debugging information
52
+ *
53
+ * @returns object containing standardized error response
54
+ */
55
+ var generateErrorBody = function (message, debugData) {
56
+ var errorResponse = {
57
+ error: true,
58
+ message: message
59
+ };
60
+ if (debugData && debugData.code && debugData.message) {
61
+ errorResponse.debugData = {
62
+ code: debugData.code,
63
+ message: debugData.message,
64
+ data: debugData.data
65
+ };
66
+ }
67
+ return errorResponse;
68
+ };
69
+ exports.generateErrorBody = generateErrorBody;
70
+ /**
71
+ * Validate if transferSpec is valid for server communication
72
+ *
73
+ * @param transferSpec the transferSpec to test
74
+ *
75
+ * @returns boolean indicating whether supplied transferSpec is valid
76
+ */
77
+ var isValidTransferSpec = function (transferSpec) {
78
+ if (transferSpec &&
79
+ typeof transferSpec === 'object' &&
80
+ typeof transferSpec.direction === 'string' &&
81
+ typeof transferSpec.remote_host === 'string' &&
82
+ Array.isArray(transferSpec.paths)) {
83
+ return true;
84
+ }
85
+ return false;
86
+ };
87
+ exports.isValidTransferSpec = isValidTransferSpec;
88
+ /**
89
+ * Returns a string indicating the websocket URL to use for talking to the server
90
+ *
91
+ * @returns a string of the full Websocket URL
92
+ */
93
+ var getWebsocketUrl = function (serverUrl) {
94
+ var wsProtocol;
95
+ if (serverUrl.indexOf('http:') === 0) {
96
+ wsProtocol = 'ws';
97
+ }
98
+ else if (serverUrl.indexOf('https:') === 0) {
99
+ wsProtocol = 'wss';
100
+ }
101
+ var url = serverUrl.replace('http://', '//').replace('https://', '//');
102
+ return "".concat(wsProtocol, ":").concat(url);
103
+ };
104
+ exports.getWebsocketUrl = getWebsocketUrl;
105
+ /**
106
+ * Simple function to get the current platform.
107
+ *
108
+ * @returns a string indicating the current platform
109
+ */
110
+ var getCurrentPlatform = function () {
111
+ var ua = navigator.userAgent;
112
+ if (/Mac/.test(ua)) {
113
+ return 'macos';
114
+ }
115
+ else if (/Win/.test(ua)) {
116
+ return 'windows';
117
+ }
118
+ else if (/Linux/.test(ua)) {
119
+ return 'linux';
120
+ }
121
+ else {
122
+ return 'unknown';
123
+ }
124
+ };
125
+ exports.getCurrentPlatform = getCurrentPlatform;
126
+ /**
127
+ * Function used to create a random UUID
128
+ *
129
+ * @returns string
130
+ */
131
+ var randomUUID = function () {
132
+ var _a;
133
+ var fallback = function () {
134
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
135
+ var r = Number(((new Date().getTime() + 16) * Math.random()).toFixed()) % 16;
136
+ if (c !== 'x') {
137
+ // eslint-disable-next-line no-bitwise
138
+ r = r & 0x3 | 0x8;
139
+ }
140
+ return r.toString(16);
141
+ });
142
+ };
143
+ return ((_a = window.crypto) === null || _a === void 0 ? void 0 : _a.randomUUID) ? window.crypto.randomUUID() : fallback();
144
+ };
145
+ exports.randomUUID = randomUUID;
146
+ /**
147
+ * Return a rejected promise
148
+ *
149
+ * @param message the message indicating the error encountered
150
+ * @param debugData the data with useful debugging information
151
+ *
152
+ * @returns a rejected promise
153
+ */
154
+ var throwError = function (message, debugData) {
155
+ (0, exports.errorLog)(message, debugData);
156
+ return new Promise(function (resolve, reject) {
157
+ reject((0, exports.generateErrorBody)(message, debugData));
158
+ });
159
+ };
160
+ exports.throwError = throwError;
161
+ /**
162
+ * Check if the given string is a valid URL
163
+ *
164
+ * @param url string to check if valid URL
165
+ *
166
+ * @returns boolean
167
+ */
168
+ var isValidURL = function (url) {
169
+ try {
170
+ new URL(url);
171
+ return true;
172
+ }
173
+ catch (error) {
174
+ return false;
175
+ }
176
+ };
177
+ exports.isValidURL = isValidURL;
178
+ /**
179
+ * Checks if the current browser is Safari.
180
+ * @returns {boolean} Whether the browser is Safari.
181
+ */
182
+ var isSafari = function () {
183
+ return /^((?!chrome|android).)*safari/i.test(navigator.userAgent) && !window.MSStream;
184
+ };
185
+ exports.isSafari = isSafari;
186
+ /**
187
+ * Get the URLs for installer management.
188
+ *
189
+ * @returns Info on URLs where installers live
190
+ */
191
+ var getInstallerUrls = function () {
192
+ return {
193
+ base: constants_1.baseInstallerUrl,
194
+ latest: constants_1.installerUrl,
195
+ };
196
+ };
197
+ exports.getInstallerUrls = getInstallerUrls;
198
+ /**
199
+ * Try to stringify a JSON string and log failures
200
+ *
201
+ * @param json - Object to make into a string
202
+ *
203
+ * @returns string representing JSON or empty string on error
204
+ */
205
+ var safeJsonString = function (json) {
206
+ try {
207
+ return JSON.stringify(json);
208
+ }
209
+ catch (error) {
210
+ (0, exports.errorLog)('safeJsonString: unable to stringify JSON', { error: error, json: json });
211
+ return '';
212
+ }
213
+ };
214
+ exports.safeJsonString = safeJsonString;
215
+ /**
216
+ * Try to parse a JSON string and log failures
217
+ *
218
+ * @param json - String to make into an object
219
+ *
220
+ * @returns object or array from the JSON string. Or undefined
221
+ */
222
+ var safeJsonParse = function (json) {
223
+ if (json && typeof json === 'object') {
224
+ return json;
225
+ }
226
+ try {
227
+ return JSON.parse(json);
228
+ }
229
+ catch (error) {
230
+ (0, exports.errorLog)('safeJsonParse: unable to parse JSON', { error: error, json: json });
231
+ return undefined;
232
+ }
233
+ };
234
+ exports.safeJsonParse = safeJsonParse;
235
+ exports.default = {
236
+ errorLog: exports.errorLog,
237
+ generateErrorBody: exports.generateErrorBody,
238
+ generatePromiseObjects: exports.generatePromiseObjects,
239
+ getCurrentPlatform: exports.getCurrentPlatform,
240
+ getWebsocketUrl: exports.getWebsocketUrl,
241
+ isSafari: exports.isSafari,
242
+ isValidURL: exports.isValidURL,
243
+ isValidTransferSpec: exports.isValidTransferSpec,
244
+ randomUUID: exports.randomUUID,
245
+ throwError: exports.throwError,
246
+ getInstallerUrls: exports.getInstallerUrls,
247
+ safeJsonString: exports.safeJsonString,
248
+ safeJsonParse: exports.safeJsonParse,
249
+ };
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Check HTTP promise response for server error response (non 2XX status) and reject promise is error
3
+ *
4
+ * @param promise the HTTP promise to check for HTTP status code of 2XX for success
5
+ *
6
+ * @returns promise for the HTTP connection with catch supporting error
7
+ */
8
+ export declare const handlePromiseErrors: (promise: Promise<any>) => Promise<any>;
9
+ /**
10
+ * Make a GET for retrieving data from a server
11
+ *
12
+ * @param url the url string of the resource on the server
13
+ *
14
+ * @returns a promise that will resolve with the response from the server or reject if network/server error
15
+ */
16
+ export declare const apiGet: (url: string) => Promise<any>;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.apiGet = exports.handlePromiseErrors = void 0;
4
+ var helpers_1 = require("./helpers");
5
+ /**
6
+ * Check HTTP promise response for server error response (non 2XX status) and reject promise is error
7
+ *
8
+ * @param promise the HTTP promise to check for HTTP status code of 2XX for success
9
+ *
10
+ * @returns promise for the HTTP connection with catch supporting error
11
+ */
12
+ var handlePromiseErrors = function (promise) {
13
+ var promiseInfo = (0, helpers_1.generatePromiseObjects)();
14
+ promise.then(function (response) {
15
+ if (response.ok) {
16
+ promiseInfo.resolver(response);
17
+ }
18
+ else {
19
+ promiseInfo.rejecter(response);
20
+ }
21
+ return response;
22
+ }).catch(function (error) {
23
+ promiseInfo.rejecter(error);
24
+ });
25
+ return promiseInfo.promise;
26
+ };
27
+ exports.handlePromiseErrors = handlePromiseErrors;
28
+ /**
29
+ * Make a GET for retrieving data from a server
30
+ *
31
+ * @param url the url string of the resource on the server
32
+ *
33
+ * @returns a promise that will resolve with the response from the server or reject if network/server error
34
+ */
35
+ var apiGet = function (url) {
36
+ return (0, exports.handlePromiseErrors)(fetch(url, {
37
+ headers: {
38
+ 'Content-Type': 'application/json',
39
+ },
40
+ }));
41
+ };
42
+ exports.apiGet = apiGet;