@ibm-aspera/sdk 0.19.0 → 0.20.0
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/dist/commonjs/app/core.d.ts +43 -17
- package/dist/commonjs/app/core.js +144 -28
- package/dist/commonjs/app/status.d.ts +11 -1
- package/dist/commonjs/app/status.js +35 -4
- package/dist/commonjs/connect/core.js +3 -0
- package/dist/commonjs/helpers/connect-extension.d.ts +8 -0
- package/dist/commonjs/helpers/connect-extension.js +58 -0
- package/dist/commonjs/helpers/helpers.d.ts +6 -0
- package/dist/commonjs/helpers/helpers.js +19 -1
- package/dist/commonjs/helpers/ws.d.ts +16 -0
- package/dist/commonjs/helpers/ws.js +49 -2
- package/dist/commonjs/http-gateway/core.js +10 -12
- package/dist/commonjs/http-gateway/download.js +2 -2
- package/dist/commonjs/http-gateway/upload.js +2 -2
- package/dist/commonjs/http-gateway/v2/app/core.d.ts +84 -0
- package/dist/commonjs/http-gateway/v2/app/core.js +170 -0
- package/dist/commonjs/http-gateway/v2/app/download.d.ts +15 -0
- package/dist/commonjs/http-gateway/v2/app/download.js +68 -0
- package/dist/commonjs/http-gateway/v2/app/upload.d.ts +169 -0
- package/dist/commonjs/http-gateway/v2/app/upload.js +601 -0
- package/dist/commonjs/http-gateway/v2/constants/constants.d.ts +6 -0
- package/dist/commonjs/http-gateway/v2/constants/constants.js +9 -0
- package/dist/commonjs/http-gateway/v2/constants/messages.d.ts +35 -0
- package/dist/commonjs/http-gateway/v2/constants/messages.js +38 -0
- package/dist/commonjs/http-gateway/v2/helpers/helpers.d.ts +121 -0
- package/dist/commonjs/http-gateway/v2/helpers/helpers.js +294 -0
- package/dist/commonjs/http-gateway/v2/helpers/http.d.ts +86 -0
- package/dist/commonjs/http-gateway/v2/helpers/http.js +153 -0
- package/dist/commonjs/http-gateway/v2/index.d.ts +35 -0
- package/dist/commonjs/http-gateway/v2/index.js +70 -0
- package/dist/commonjs/http-gateway/v2/models/http-gateway-global.model.d.ts +254 -0
- package/dist/commonjs/http-gateway/v2/models/http-gateway-global.model.js +367 -0
- package/dist/commonjs/http-gateway/v2/models/models.d.ts +127 -0
- package/dist/commonjs/http-gateway/v2/models/models.js +87 -0
- package/dist/commonjs/index.d.ts +3 -3
- package/dist/commonjs/index.js +3 -1
- package/dist/commonjs/models/aspera-sdk.model.d.ts +2 -1
- package/dist/commonjs/models/aspera-sdk.model.js +8 -0
- package/dist/commonjs/models/models.d.ts +10 -1
- package/dist/js/aspera-sdk.js +1 -1
- package/dist/js/aspera-sdk.js.LICENSE.txt +1 -1
- package/dist/js/aspera-sdk.js.map +1 -1
- package/package.json +1 -2
- package/scripts/release.sh +7 -7
- package/scripts/version.sh +24 -15
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.messages = void 0;
|
|
4
|
+
/** @ignore */
|
|
5
|
+
exports.messages = {
|
|
6
|
+
serverUrlNotSet: 'Server URL not set. Call init function',
|
|
7
|
+
serverError: 'Unable to communicate with HTTP Gateway server',
|
|
8
|
+
serverNotVerified: 'The HTTP Gateway server has not been verified. Run test or init first',
|
|
9
|
+
downloadFailed: 'The download failed to initiate',
|
|
10
|
+
streamFailed: 'The stream failed to initiate',
|
|
11
|
+
notValidTransferSpec: 'The supplied transferSpec is not valid',
|
|
12
|
+
invalidServerUrl: 'The supplied server URL is invalid',
|
|
13
|
+
unableToGetFilesForUpload: 'Unable to get files for upload based on transferSpec',
|
|
14
|
+
unableToUpload: 'Unable to upload. Server encountered an error',
|
|
15
|
+
failedToGetDownloadUrl: 'Unable to retrieve HTTP download URL',
|
|
16
|
+
failedToGetStreamUrl: 'Unable to retrieve HTTP stream URL',
|
|
17
|
+
streamInjectDomInvalid: 'Unable to find injection point for video player',
|
|
18
|
+
failedToGenerateIframe: 'Unable to generate IFRAME for download. Using new window',
|
|
19
|
+
callbackIsNotFunction: 'The provided callback is not a function',
|
|
20
|
+
websocketClosedUnexpect: 'The websocket was closed unexpectedly',
|
|
21
|
+
invalidChunkSize: 'The provided chunk size for uploads is invalid',
|
|
22
|
+
invalidConcurrentUploads: 'The provided number for concurrent uploads is invalid',
|
|
23
|
+
unableToParseDataForUpload: 'Unable to parse data for uploading',
|
|
24
|
+
unableToDeepCopyObject: 'Unable to deep copy object or array',
|
|
25
|
+
unableToFindElementOnPage: 'Unable to find the element on the current page',
|
|
26
|
+
unauthorizedFilesForUpload: 'Unauthorized files included in the transferSpec. All files for upload must be picked via getFilesForUpload',
|
|
27
|
+
startDownload: 'Start HTTP download?',
|
|
28
|
+
dropFoldersNotAllowed: 'Dropping folders is not currently allowed',
|
|
29
|
+
yes: 'Yes',
|
|
30
|
+
no: 'No',
|
|
31
|
+
close: 'Close',
|
|
32
|
+
leavingWhileUploading: 'An upload is in progress. If you leave the upload will be cancelled.',
|
|
33
|
+
unableToReadFolder: 'The dropped item could not be parsed. Please try selecting via the select file/folder option',
|
|
34
|
+
streamingTooManyFiles: 'Too many files requested for a stream. Only one video file is allowed in the transferSpec',
|
|
35
|
+
loadingDownload: 'The download will now open in this window.',
|
|
36
|
+
versionNotsupported: 'This SDK only supports v2 and below. For newer IBM Aspera HTTP Gateway you must use @ibm-aspera/sdk package. Learn more: https://github.com/IBM/aspera-sdk-js.',
|
|
37
|
+
deprecationWarning: 'This SDK is deprecated. Move to @ibm-aspera/sdk package to support future IBM Aspera Gateway versions. Learn more: https://github.com/IBM/aspera-sdk-js.',
|
|
38
|
+
};
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { PromiseObject, ErrorResponse, TransferSpec, TransferSpecPath, FeatureFlags } 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 HTTP Gateway 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 URL is valid URL
|
|
26
|
+
*
|
|
27
|
+
* @param serverUrl the url to test
|
|
28
|
+
*
|
|
29
|
+
* @returns boolean indicating whether supplied url is valid
|
|
30
|
+
*/
|
|
31
|
+
export declare const isValidUrl: (url: any) => boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Validate if transferSpec is valid for server communication
|
|
34
|
+
*
|
|
35
|
+
* @param transferSpec the transferSpec to test
|
|
36
|
+
*
|
|
37
|
+
* @returns boolean indicating whether supplied transferSpec is valid
|
|
38
|
+
*/
|
|
39
|
+
export declare const isValidTransferSpec: (transferSpec: TransferSpec) => boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Get files from a form
|
|
42
|
+
*
|
|
43
|
+
* @param children form children list
|
|
44
|
+
*
|
|
45
|
+
* @returns an array of Files pulled from an HTML form
|
|
46
|
+
*/
|
|
47
|
+
export declare const checkChildrenForFiles: (children: NodeList) => File[];
|
|
48
|
+
/**
|
|
49
|
+
* Validate if form has required items
|
|
50
|
+
*
|
|
51
|
+
* @param form HTML form element
|
|
52
|
+
*/
|
|
53
|
+
export declare const isValidForm: (form: HTMLFormElement) => boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Take a list of files and match them to a provided transferSpec to find only files to use
|
|
56
|
+
*
|
|
57
|
+
* @param files list of files in JavaScript memory
|
|
58
|
+
* @param transferSpec the transferSpec to compare to for what files to use
|
|
59
|
+
*/
|
|
60
|
+
export declare const parseFilesFromSpec: (files: File[], transferSpec: TransferSpec) => File[];
|
|
61
|
+
/**
|
|
62
|
+
* Take a transferSpec and find folders being used in the form and explode for uploading and explode transferSpec to know all files in folder
|
|
63
|
+
*
|
|
64
|
+
* @param formId the form item to use for parsing
|
|
65
|
+
* @param transferSpec he transfer spec to test with for file list
|
|
66
|
+
*
|
|
67
|
+
* @returns object with files to add to upload and a new transferSpec Path array to use with exploded files
|
|
68
|
+
*/
|
|
69
|
+
export declare const folderTransferSpecExplode: (formId: string, transferSpec: TransferSpec) => {
|
|
70
|
+
files: File[];
|
|
71
|
+
newPath: TransferSpecPath[];
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* Return array of File items to use for transfer
|
|
75
|
+
*
|
|
76
|
+
* @param formId the form item to use for parsing
|
|
77
|
+
* @param transferSpec the transfer spec to test with for file list
|
|
78
|
+
*
|
|
79
|
+
* @returns the array of Files to use
|
|
80
|
+
*/
|
|
81
|
+
export declare const getFilesForTransfer: (formId: string, transferSpec: TransferSpec) => Array<File>;
|
|
82
|
+
/**
|
|
83
|
+
* Convert an irritable into an array. This is useful for taking Maps and making Arrays (Map.values() Map.keys())
|
|
84
|
+
*
|
|
85
|
+
* @param iterable - an iterable to take and convert to an array
|
|
86
|
+
*
|
|
87
|
+
* @returns an array containing the iterable values
|
|
88
|
+
*/
|
|
89
|
+
export declare const iterableToArray: (iterable: IterableIterator<unknown>) => any[];
|
|
90
|
+
/**
|
|
91
|
+
* Figure out which feature to use based on current version of system.
|
|
92
|
+
*
|
|
93
|
+
* @param featureFlag - name of the feature flag to test
|
|
94
|
+
*
|
|
95
|
+
* @returns indicator if feature should be used
|
|
96
|
+
*/
|
|
97
|
+
export declare const getFeatureFlag: (featureFlag: FeatureFlags) => boolean;
|
|
98
|
+
/**
|
|
99
|
+
* Returns a string indicating the websocket URL to use for talking to the server
|
|
100
|
+
*
|
|
101
|
+
* @returns a string of the full Websocket URL
|
|
102
|
+
*/
|
|
103
|
+
export declare const getWebsocketUrl: (serverUrl: string, protocol: string) => string;
|
|
104
|
+
declare const _default: {
|
|
105
|
+
generatePromiseObjects: () => PromiseObject;
|
|
106
|
+
errorLog: (message: string, debugData?: any) => void;
|
|
107
|
+
generateErrorBody: (message: string, debugData?: any) => ErrorResponse;
|
|
108
|
+
isValidUrl: (url: any) => boolean;
|
|
109
|
+
isValidTransferSpec: (transferSpec: TransferSpec) => boolean;
|
|
110
|
+
checkChildrenForFiles: (children: NodeList) => File[];
|
|
111
|
+
isValidForm: (form: HTMLFormElement) => boolean;
|
|
112
|
+
getFilesForTransfer: (formId: string, transferSpec: TransferSpec) => Array<File>;
|
|
113
|
+
folderTransferSpecExplode: (formId: string, transferSpec: TransferSpec) => {
|
|
114
|
+
files: File[];
|
|
115
|
+
newPath: TransferSpecPath[];
|
|
116
|
+
};
|
|
117
|
+
parseFilesFromSpec: (files: File[], transferSpec: TransferSpec) => File[];
|
|
118
|
+
iterableToArray: (iterable: IterableIterator<unknown>) => any[];
|
|
119
|
+
getFeatureFlag: (featureFlag: FeatureFlags) => boolean;
|
|
120
|
+
};
|
|
121
|
+
export default _default;
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getWebsocketUrl = exports.getFeatureFlag = exports.iterableToArray = exports.getFilesForTransfer = exports.folderTransferSpecExplode = exports.parseFilesFromSpec = exports.isValidForm = exports.checkChildrenForFiles = exports.isValidTransferSpec = exports.isValidUrl = exports.generateErrorBody = exports.errorLog = exports.generatePromiseObjects = void 0;
|
|
4
|
+
var index_1 = require("../index");
|
|
5
|
+
var constants_1 = require("../constants/constants");
|
|
6
|
+
var messages_1 = require("../constants/messages");
|
|
7
|
+
/**
|
|
8
|
+
* Generates promise object that can be resolved or rejected via functions
|
|
9
|
+
*
|
|
10
|
+
* @returns an object containing the promise, the resolver and rejecter
|
|
11
|
+
*/
|
|
12
|
+
var generatePromiseObjects = function () {
|
|
13
|
+
var resolver;
|
|
14
|
+
var rejecter;
|
|
15
|
+
var promise = new Promise(function (resolve, reject) {
|
|
16
|
+
resolver = resolve;
|
|
17
|
+
rejecter = reject;
|
|
18
|
+
});
|
|
19
|
+
return {
|
|
20
|
+
promise: promise,
|
|
21
|
+
resolver: resolver,
|
|
22
|
+
rejecter: rejecter
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
exports.generatePromiseObjects = generatePromiseObjects;
|
|
26
|
+
/**
|
|
27
|
+
* Log errors from HTTP Gateway SDK
|
|
28
|
+
*
|
|
29
|
+
* @param message the message indicating the error encountered
|
|
30
|
+
* @param debugData the data with useful debugging information
|
|
31
|
+
*/
|
|
32
|
+
var errorLog = function (message, debugData) {
|
|
33
|
+
if (typeof window === 'object') {
|
|
34
|
+
if (!Array.isArray(window.httpGatewayLogs)) {
|
|
35
|
+
window.httpGatewayLogs = [];
|
|
36
|
+
}
|
|
37
|
+
window.httpGatewayLogs.push({ message: message, debugData: debugData });
|
|
38
|
+
}
|
|
39
|
+
console.warn("Aspera HTTP Gateway SDK: ".concat(message), debugData);
|
|
40
|
+
};
|
|
41
|
+
exports.errorLog = errorLog;
|
|
42
|
+
/**
|
|
43
|
+
* Generate error object for rejecter responses
|
|
44
|
+
*
|
|
45
|
+
* @param message the message indicating the error encountered
|
|
46
|
+
* @param debugData the data with useful debugging information
|
|
47
|
+
*
|
|
48
|
+
* @returns object containing standardized error response
|
|
49
|
+
*/
|
|
50
|
+
var generateErrorBody = function (message, debugData) {
|
|
51
|
+
var errorResponse = {
|
|
52
|
+
error: true,
|
|
53
|
+
message: message
|
|
54
|
+
};
|
|
55
|
+
if (debugData) {
|
|
56
|
+
errorResponse.debugData = debugData;
|
|
57
|
+
}
|
|
58
|
+
return errorResponse;
|
|
59
|
+
};
|
|
60
|
+
exports.generateErrorBody = generateErrorBody;
|
|
61
|
+
/**
|
|
62
|
+
* Validate if URL is valid URL
|
|
63
|
+
*
|
|
64
|
+
* @param serverUrl the url to test
|
|
65
|
+
*
|
|
66
|
+
* @returns boolean indicating whether supplied url is valid
|
|
67
|
+
*/
|
|
68
|
+
var isValidUrl = function (url) {
|
|
69
|
+
if (url &&
|
|
70
|
+
typeof url === 'string' &&
|
|
71
|
+
url.indexOf('//') > -1) {
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
return false;
|
|
75
|
+
};
|
|
76
|
+
exports.isValidUrl = isValidUrl;
|
|
77
|
+
/**
|
|
78
|
+
* Validate if transferSpec is valid for server communication
|
|
79
|
+
*
|
|
80
|
+
* @param transferSpec the transferSpec to test
|
|
81
|
+
*
|
|
82
|
+
* @returns boolean indicating whether supplied transferSpec is valid
|
|
83
|
+
*/
|
|
84
|
+
var isValidTransferSpec = function (transferSpec) {
|
|
85
|
+
if (transferSpec &&
|
|
86
|
+
typeof transferSpec === 'object' &&
|
|
87
|
+
typeof transferSpec.direction === 'string' &&
|
|
88
|
+
typeof transferSpec.remote_host === 'string' &&
|
|
89
|
+
Array.isArray(transferSpec.paths)) {
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
return false;
|
|
93
|
+
};
|
|
94
|
+
exports.isValidTransferSpec = isValidTransferSpec;
|
|
95
|
+
/**
|
|
96
|
+
* Get files from a form
|
|
97
|
+
*
|
|
98
|
+
* @param children form children list
|
|
99
|
+
*
|
|
100
|
+
* @returns an array of Files pulled from an HTML form
|
|
101
|
+
*/
|
|
102
|
+
var checkChildrenForFiles = function (children) {
|
|
103
|
+
var filesFromForm = [];
|
|
104
|
+
children.forEach(function (child) {
|
|
105
|
+
if (child.files) {
|
|
106
|
+
for (var i = 0; i < child.files.length; i++) {
|
|
107
|
+
filesFromForm.push(child.files[i]);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
return filesFromForm;
|
|
112
|
+
};
|
|
113
|
+
exports.checkChildrenForFiles = checkChildrenForFiles;
|
|
114
|
+
/**
|
|
115
|
+
* Validate if form has required items
|
|
116
|
+
*
|
|
117
|
+
* @param form HTML form element
|
|
118
|
+
*/
|
|
119
|
+
var isValidForm = function (form) {
|
|
120
|
+
if (form &&
|
|
121
|
+
typeof form === 'object' &&
|
|
122
|
+
form.nodeType &&
|
|
123
|
+
form.tagName === 'FORM') {
|
|
124
|
+
return true;
|
|
125
|
+
}
|
|
126
|
+
return false;
|
|
127
|
+
};
|
|
128
|
+
exports.isValidForm = isValidForm;
|
|
129
|
+
/**
|
|
130
|
+
* Take a list of files and match them to a provided transferSpec to find only files to use
|
|
131
|
+
*
|
|
132
|
+
* @param files list of files in JavaScript memory
|
|
133
|
+
* @param transferSpec the transferSpec to compare to for what files to use
|
|
134
|
+
*/
|
|
135
|
+
var parseFilesFromSpec = function (files, transferSpec) {
|
|
136
|
+
var transferSpecFilesMap = new Map();
|
|
137
|
+
var filesAddedList = new Map();
|
|
138
|
+
transferSpec.paths.forEach(function (path) {
|
|
139
|
+
transferSpecFilesMap.set(path.source, path);
|
|
140
|
+
});
|
|
141
|
+
return files.filter(function (file) {
|
|
142
|
+
if (filesAddedList.get(file.name)) {
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
var specPath = transferSpecFilesMap.get(file.name);
|
|
146
|
+
if (specPath) {
|
|
147
|
+
specPath.file_size = file.size;
|
|
148
|
+
filesAddedList.set(file.name, true);
|
|
149
|
+
}
|
|
150
|
+
return !!specPath;
|
|
151
|
+
});
|
|
152
|
+
};
|
|
153
|
+
exports.parseFilesFromSpec = parseFilesFromSpec;
|
|
154
|
+
/**
|
|
155
|
+
* Take a transferSpec and find folders being used in the form and explode for uploading and explode transferSpec to know all files in folder
|
|
156
|
+
*
|
|
157
|
+
* @param formId the form item to use for parsing
|
|
158
|
+
* @param transferSpec he transfer spec to test with for file list
|
|
159
|
+
*
|
|
160
|
+
* @returns object with files to add to upload and a new transferSpec Path array to use with exploded files
|
|
161
|
+
*/
|
|
162
|
+
var folderTransferSpecExplode = function (formId, transferSpec) {
|
|
163
|
+
var _a;
|
|
164
|
+
var folderList = index_1.asperaHttpGateway.globals.getOrCreateFolderDataList(formId);
|
|
165
|
+
var folderDropList = index_1.asperaHttpGateway.globals.getOrCreateFolderDataList(constants_1.dropContainerName);
|
|
166
|
+
var newPaths = [];
|
|
167
|
+
var foundFiles = [];
|
|
168
|
+
var handleFolderData = function (file, path) {
|
|
169
|
+
foundFiles.push(file);
|
|
170
|
+
newPaths.push({
|
|
171
|
+
source: file.asperaDropPath || file.webkitRelativePath || file.name,
|
|
172
|
+
destination: path.destination,
|
|
173
|
+
});
|
|
174
|
+
};
|
|
175
|
+
(_a = transferSpec.paths) === null || _a === void 0 ? void 0 : _a.forEach(function (path) {
|
|
176
|
+
if (folderList.get(path.source)) {
|
|
177
|
+
folderList.get(path.source).files.forEach(function (file) {
|
|
178
|
+
handleFolderData(file, path);
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
else if (folderDropList.get(path.source)) {
|
|
182
|
+
folderDropList.get(path.source).files.forEach(function (file) {
|
|
183
|
+
handleFolderData(file, path);
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
newPaths.push(path);
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
return {
|
|
191
|
+
files: foundFiles,
|
|
192
|
+
newPath: newPaths,
|
|
193
|
+
};
|
|
194
|
+
};
|
|
195
|
+
exports.folderTransferSpecExplode = folderTransferSpecExplode;
|
|
196
|
+
/**
|
|
197
|
+
* Return array of File items to use for transfer
|
|
198
|
+
*
|
|
199
|
+
* @param formId the form item to use for parsing
|
|
200
|
+
* @param transferSpec the transfer spec to test with for file list
|
|
201
|
+
*
|
|
202
|
+
* @returns the array of Files to use
|
|
203
|
+
*/
|
|
204
|
+
var getFilesForTransfer = function (formId, transferSpec) {
|
|
205
|
+
var form = index_1.asperaHttpGateway.globals.createOrUseForm(formId);
|
|
206
|
+
if (!(0, exports.isValidForm)(form)) {
|
|
207
|
+
return [];
|
|
208
|
+
}
|
|
209
|
+
var filesFromForm = (0, exports.checkChildrenForFiles)(form.childNodes);
|
|
210
|
+
var dropFiles = index_1.asperaHttpGateway.globals.getOrCreateFormFileListFromDrop(constants_1.dropContainerName);
|
|
211
|
+
dropFiles.forEach(function (file) {
|
|
212
|
+
filesFromForm.push(file);
|
|
213
|
+
});
|
|
214
|
+
return (0, exports.parseFilesFromSpec)(filesFromForm, transferSpec);
|
|
215
|
+
};
|
|
216
|
+
exports.getFilesForTransfer = getFilesForTransfer;
|
|
217
|
+
/**
|
|
218
|
+
* Convert an irritable into an array. This is useful for taking Maps and making Arrays (Map.values() Map.keys())
|
|
219
|
+
*
|
|
220
|
+
* @param iterable - an iterable to take and convert to an array
|
|
221
|
+
*
|
|
222
|
+
* @returns an array containing the iterable values
|
|
223
|
+
*/
|
|
224
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
225
|
+
var iterableToArray = function (iterable) {
|
|
226
|
+
var newArray = [];
|
|
227
|
+
(function addItem() {
|
|
228
|
+
var value = iterable.next();
|
|
229
|
+
if (!value.done) {
|
|
230
|
+
newArray.push(value.value);
|
|
231
|
+
addItem();
|
|
232
|
+
}
|
|
233
|
+
}());
|
|
234
|
+
return newArray;
|
|
235
|
+
};
|
|
236
|
+
exports.iterableToArray = iterableToArray;
|
|
237
|
+
/**
|
|
238
|
+
* Figure out which feature to use based on current version of system.
|
|
239
|
+
*
|
|
240
|
+
* @param featureFlag - name of the feature flag to test
|
|
241
|
+
*
|
|
242
|
+
* @returns indicator if feature should be used
|
|
243
|
+
*/
|
|
244
|
+
var getFeatureFlag = function (featureFlag) {
|
|
245
|
+
var _a;
|
|
246
|
+
if (!((_a = index_1.asperaHttpGateway.globals.serverInfo) === null || _a === void 0 ? void 0 : _a.version)) {
|
|
247
|
+
(0, exports.errorLog)(messages_1.messages.serverNotVerified);
|
|
248
|
+
return false;
|
|
249
|
+
}
|
|
250
|
+
var versionData = index_1.asperaHttpGateway.globals.serverInfo.version.split('.');
|
|
251
|
+
var major = versionData[0] ? Number(versionData[0]) : 0;
|
|
252
|
+
var minor = versionData[1] ? Number(versionData[1]) : 0;
|
|
253
|
+
var patch = versionData[2] ? Number(versionData[2]) : 0;
|
|
254
|
+
var numberBased = (major * 10000000000) + (minor * 100000) + patch;
|
|
255
|
+
switch (featureFlag) {
|
|
256
|
+
case 'noBase64Encoding':
|
|
257
|
+
return numberBased >= 20000300000;
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
exports.getFeatureFlag = getFeatureFlag;
|
|
261
|
+
/**
|
|
262
|
+
* Returns a string indicating the websocket URL to use for talking to the server
|
|
263
|
+
*
|
|
264
|
+
* @returns a string of the full Websocket URL
|
|
265
|
+
*/
|
|
266
|
+
var getWebsocketUrl = function (serverUrl, protocol) {
|
|
267
|
+
var wsProtocol;
|
|
268
|
+
if (serverUrl.indexOf('http:') === 0) {
|
|
269
|
+
wsProtocol = 'ws';
|
|
270
|
+
}
|
|
271
|
+
else if (serverUrl.indexOf('https:') === 0) {
|
|
272
|
+
wsProtocol = 'wss';
|
|
273
|
+
}
|
|
274
|
+
else {
|
|
275
|
+
wsProtocol = protocol === 'https:' ? 'wss' : 'ws';
|
|
276
|
+
}
|
|
277
|
+
var url = serverUrl.replace('http://', '//').replace('https://', '//');
|
|
278
|
+
return "".concat(wsProtocol, ":").concat(url, "/").concat((0, exports.getFeatureFlag)('noBase64Encoding') ? 'v2' : 'v1', "/upload");
|
|
279
|
+
};
|
|
280
|
+
exports.getWebsocketUrl = getWebsocketUrl;
|
|
281
|
+
exports.default = {
|
|
282
|
+
generatePromiseObjects: exports.generatePromiseObjects,
|
|
283
|
+
errorLog: exports.errorLog,
|
|
284
|
+
generateErrorBody: exports.generateErrorBody,
|
|
285
|
+
isValidUrl: exports.isValidUrl,
|
|
286
|
+
isValidTransferSpec: exports.isValidTransferSpec,
|
|
287
|
+
checkChildrenForFiles: exports.checkChildrenForFiles,
|
|
288
|
+
isValidForm: exports.isValidForm,
|
|
289
|
+
getFilesForTransfer: exports.getFilesForTransfer,
|
|
290
|
+
folderTransferSpecExplode: exports.folderTransferSpecExplode,
|
|
291
|
+
parseFilesFromSpec: exports.parseFilesFromSpec,
|
|
292
|
+
iterableToArray: exports.iterableToArray,
|
|
293
|
+
getFeatureFlag: exports.getFeatureFlag,
|
|
294
|
+
};
|
|
@@ -0,0 +1,86 @@
|
|
|
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 params into string for query params
|
|
11
|
+
*
|
|
12
|
+
* @param params object of key:value pairs
|
|
13
|
+
*
|
|
14
|
+
* @returns a string of query params that is URL safe
|
|
15
|
+
*/
|
|
16
|
+
export declare const getQueryString: (params: any) => string;
|
|
17
|
+
/**
|
|
18
|
+
* Create URL with query params if params are set
|
|
19
|
+
*
|
|
20
|
+
* @param url the url string
|
|
21
|
+
* @param params object of key:value pairs
|
|
22
|
+
*
|
|
23
|
+
* @returns a string of url and query params together
|
|
24
|
+
*/
|
|
25
|
+
export declare const getUrlWithQueryParams: (url: string, params: any) => string;
|
|
26
|
+
/**
|
|
27
|
+
* Add required headers and additional headers together for network requests
|
|
28
|
+
*
|
|
29
|
+
* @param additionalHeaders object of key:value of extra header items
|
|
30
|
+
*
|
|
31
|
+
* @returns an object of key:value of all headers (additional and required)
|
|
32
|
+
*/
|
|
33
|
+
export declare const getHeaders: (additionalHeaders?: any) => any;
|
|
34
|
+
/**
|
|
35
|
+
* Make a GET for retrieving data from a server
|
|
36
|
+
*
|
|
37
|
+
* @param url the url string of the resource on the server
|
|
38
|
+
* @param queryParams an object of key:value to be used for the query params
|
|
39
|
+
* @param additionalHeaders an object of key:value to be used for additional headers
|
|
40
|
+
*
|
|
41
|
+
* @returns a promise that will resolve with the response from the server or reject if network/server error
|
|
42
|
+
*/
|
|
43
|
+
export declare const apiGet: (url: string, queryParams?: any, additionalHeaders?: any) => Promise<any>;
|
|
44
|
+
/**
|
|
45
|
+
* Make a POST for creating data on the server
|
|
46
|
+
*
|
|
47
|
+
* @param url the url string of the resource on the server
|
|
48
|
+
* @param data the data (JSON) to send to the server
|
|
49
|
+
* @param queryParams an object of key:value to be used for the query params
|
|
50
|
+
* @param additionalHeaders an object of key:value to be used for additional headers
|
|
51
|
+
*
|
|
52
|
+
* @returns a promise that will resolve with the response from the server or reject if network/server error
|
|
53
|
+
*/
|
|
54
|
+
export declare const apiPost: (url: string, data: any, queryParams?: any, additionalHeaders?: any) => Promise<any>;
|
|
55
|
+
/**
|
|
56
|
+
* Make a PUT for creating data on the server
|
|
57
|
+
*
|
|
58
|
+
* @param url the url string of the resource on the server
|
|
59
|
+
* @param data the data (JSON) to send to the server
|
|
60
|
+
* @param queryParams an object of key:value to be used for the query params
|
|
61
|
+
* @param additionalHeaders an object of key:value to be used for additional headers
|
|
62
|
+
*
|
|
63
|
+
* @returns a promise that will resolve with the response from the server or reject if network/server error
|
|
64
|
+
*/
|
|
65
|
+
export declare const apiPut: (url: string, data: any, queryParams?: any, additionalHeaders?: any) => Promise<any>;
|
|
66
|
+
/**
|
|
67
|
+
* Make a DELETE on a resource on the server
|
|
68
|
+
*
|
|
69
|
+
* @param url the url string of the resource on the server
|
|
70
|
+
* @param queryParams an object of key:value to be used for the query params
|
|
71
|
+
* @param additionalHeaders an object of key:value to be used for additional headers
|
|
72
|
+
*
|
|
73
|
+
* @returns a promise that will resolve with the response from the server or reject if network/server error
|
|
74
|
+
*/
|
|
75
|
+
export declare const apiDelete: (url: string, queryParams?: any, additionalHeaders?: any) => Promise<any>;
|
|
76
|
+
declare const _default: {
|
|
77
|
+
apiGet: (url: string, queryParams?: any, additionalHeaders?: any) => Promise<any>;
|
|
78
|
+
apiPost: (url: string, data: any, queryParams?: any, additionalHeaders?: any) => Promise<any>;
|
|
79
|
+
apiPut: (url: string, data: any, queryParams?: any, additionalHeaders?: any) => Promise<any>;
|
|
80
|
+
apiDelete: (url: string, queryParams?: any, additionalHeaders?: any) => Promise<any>;
|
|
81
|
+
getHeaders: (additionalHeaders?: any) => any;
|
|
82
|
+
getUrlWithQueryParams: (url: string, params: any) => string;
|
|
83
|
+
getQueryString: (params: any) => string;
|
|
84
|
+
handlePromiseErrors: (promise: Promise<any>) => Promise<any>;
|
|
85
|
+
};
|
|
86
|
+
export default _default;
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.apiDelete = exports.apiPut = exports.apiPost = exports.apiGet = exports.getHeaders = exports.getUrlWithQueryParams = exports.getQueryString = 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 params into string for query params
|
|
30
|
+
*
|
|
31
|
+
* @param params object of key:value pairs
|
|
32
|
+
*
|
|
33
|
+
* @returns a string of query params that is URL safe
|
|
34
|
+
*/
|
|
35
|
+
var getQueryString = function (params) {
|
|
36
|
+
var queryString = '';
|
|
37
|
+
Object.keys(params || {}).forEach(function (key) {
|
|
38
|
+
var value = params[key];
|
|
39
|
+
queryString += "".concat(key, "=").concat(encodeURIComponent(value), "&");
|
|
40
|
+
});
|
|
41
|
+
return queryString.slice(0, -1);
|
|
42
|
+
};
|
|
43
|
+
exports.getQueryString = getQueryString;
|
|
44
|
+
/**
|
|
45
|
+
* Create URL with query params if params are set
|
|
46
|
+
*
|
|
47
|
+
* @param url the url string
|
|
48
|
+
* @param params object of key:value pairs
|
|
49
|
+
*
|
|
50
|
+
* @returns a string of url and query params together
|
|
51
|
+
*/
|
|
52
|
+
var getUrlWithQueryParams = function (url, params) {
|
|
53
|
+
if (params) {
|
|
54
|
+
var queryString = (0, exports.getQueryString)(params);
|
|
55
|
+
url = url + (queryString ? "?".concat(queryString) : '');
|
|
56
|
+
}
|
|
57
|
+
return url;
|
|
58
|
+
};
|
|
59
|
+
exports.getUrlWithQueryParams = getUrlWithQueryParams;
|
|
60
|
+
/**
|
|
61
|
+
* Add required headers and additional headers together for network requests
|
|
62
|
+
*
|
|
63
|
+
* @param additionalHeaders object of key:value of extra header items
|
|
64
|
+
*
|
|
65
|
+
* @returns an object of key:value of all headers (additional and required)
|
|
66
|
+
*/
|
|
67
|
+
var getHeaders = function (additionalHeaders) {
|
|
68
|
+
var requiredHeaders = {
|
|
69
|
+
'Content-Type': 'application/json'
|
|
70
|
+
};
|
|
71
|
+
Object.keys(additionalHeaders || {}).forEach(function (key) {
|
|
72
|
+
requiredHeaders[key] = additionalHeaders[key];
|
|
73
|
+
});
|
|
74
|
+
return requiredHeaders;
|
|
75
|
+
};
|
|
76
|
+
exports.getHeaders = getHeaders;
|
|
77
|
+
/**
|
|
78
|
+
* Make a GET for retrieving data from a server
|
|
79
|
+
*
|
|
80
|
+
* @param url the url string of the resource on the server
|
|
81
|
+
* @param queryParams an object of key:value to be used for the query params
|
|
82
|
+
* @param additionalHeaders an object of key:value to be used for additional headers
|
|
83
|
+
*
|
|
84
|
+
* @returns a promise that will resolve with the response from the server or reject if network/server error
|
|
85
|
+
*/
|
|
86
|
+
var apiGet = function (url, queryParams, additionalHeaders) {
|
|
87
|
+
return (0, exports.handlePromiseErrors)(fetch((0, exports.getUrlWithQueryParams)(url, queryParams), {
|
|
88
|
+
headers: (0, exports.getHeaders)(additionalHeaders)
|
|
89
|
+
}));
|
|
90
|
+
};
|
|
91
|
+
exports.apiGet = apiGet;
|
|
92
|
+
/**
|
|
93
|
+
* Make a POST for creating data on the server
|
|
94
|
+
*
|
|
95
|
+
* @param url the url string of the resource on the server
|
|
96
|
+
* @param data the data (JSON) to send to the server
|
|
97
|
+
* @param queryParams an object of key:value to be used for the query params
|
|
98
|
+
* @param additionalHeaders an object of key:value to be used for additional headers
|
|
99
|
+
*
|
|
100
|
+
* @returns a promise that will resolve with the response from the server or reject if network/server error
|
|
101
|
+
*/
|
|
102
|
+
var apiPost = function (url, data, queryParams, additionalHeaders) {
|
|
103
|
+
return (0, exports.handlePromiseErrors)(fetch((0, exports.getUrlWithQueryParams)(url, queryParams), {
|
|
104
|
+
method: 'POST',
|
|
105
|
+
body: JSON.stringify(data),
|
|
106
|
+
headers: (0, exports.getHeaders)(additionalHeaders)
|
|
107
|
+
}));
|
|
108
|
+
};
|
|
109
|
+
exports.apiPost = apiPost;
|
|
110
|
+
/**
|
|
111
|
+
* Make a PUT for creating data on the server
|
|
112
|
+
*
|
|
113
|
+
* @param url the url string of the resource on the server
|
|
114
|
+
* @param data the data (JSON) to send to the server
|
|
115
|
+
* @param queryParams an object of key:value to be used for the query params
|
|
116
|
+
* @param additionalHeaders an object of key:value to be used for additional headers
|
|
117
|
+
*
|
|
118
|
+
* @returns a promise that will resolve with the response from the server or reject if network/server error
|
|
119
|
+
*/
|
|
120
|
+
var apiPut = function (url, data, queryParams, additionalHeaders) {
|
|
121
|
+
return (0, exports.handlePromiseErrors)(fetch((0, exports.getUrlWithQueryParams)(url, queryParams), {
|
|
122
|
+
method: 'PUT',
|
|
123
|
+
body: JSON.stringify(data),
|
|
124
|
+
headers: (0, exports.getHeaders)(additionalHeaders)
|
|
125
|
+
}));
|
|
126
|
+
};
|
|
127
|
+
exports.apiPut = apiPut;
|
|
128
|
+
/**
|
|
129
|
+
* Make a DELETE on a resource on the server
|
|
130
|
+
*
|
|
131
|
+
* @param url the url string of the resource on the server
|
|
132
|
+
* @param queryParams an object of key:value to be used for the query params
|
|
133
|
+
* @param additionalHeaders an object of key:value to be used for additional headers
|
|
134
|
+
*
|
|
135
|
+
* @returns a promise that will resolve with the response from the server or reject if network/server error
|
|
136
|
+
*/
|
|
137
|
+
var apiDelete = function (url, queryParams, additionalHeaders) {
|
|
138
|
+
return (0, exports.handlePromiseErrors)(fetch((0, exports.getUrlWithQueryParams)(url, queryParams), {
|
|
139
|
+
method: 'DELETE',
|
|
140
|
+
headers: (0, exports.getHeaders)(additionalHeaders)
|
|
141
|
+
}));
|
|
142
|
+
};
|
|
143
|
+
exports.apiDelete = apiDelete;
|
|
144
|
+
exports.default = {
|
|
145
|
+
apiGet: exports.apiGet,
|
|
146
|
+
apiPost: exports.apiPost,
|
|
147
|
+
apiPut: exports.apiPut,
|
|
148
|
+
apiDelete: exports.apiDelete,
|
|
149
|
+
getHeaders: exports.getHeaders,
|
|
150
|
+
getUrlWithQueryParams: exports.getUrlWithQueryParams,
|
|
151
|
+
getQueryString: exports.getQueryString,
|
|
152
|
+
handlePromiseErrors: exports.handlePromiseErrors
|
|
153
|
+
};
|