@gudhub/core 1.1.125 → 1.1.127
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/GUDHUB/Utils/AppsTemplateService/AppsTemplateService.js +351 -406
- package/GUDHUB/Utils/FIleHelper/FileHelper.js +107 -57
- package/GUDHUB/Utils/Utils.js +5 -5
- package/GUDHUB/gudhub-https-service.js +78 -40
- package/GUDHUB/utils.js +2 -2
- package/package.json +1 -1
- package/umd/library.min.js +6 -6
- package/umd/library.min.js.map +1 -1
|
@@ -3,67 +3,117 @@ export class FileHelper {
|
|
|
3
3
|
this.gudhub = gudhub;
|
|
4
4
|
}
|
|
5
5
|
|
|
6
|
-
fileInstallerHelper(
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
destination: {
|
|
24
|
-
app_id: appId,
|
|
25
|
-
item_id: itemId,
|
|
26
|
-
element_id: elementId
|
|
27
|
-
}
|
|
28
|
-
}
|
|
6
|
+
async fileInstallerHelper(
|
|
7
|
+
mapAppIds,
|
|
8
|
+
appId,
|
|
9
|
+
items,
|
|
10
|
+
elementId,
|
|
11
|
+
isInstallFromRemoteServer,
|
|
12
|
+
remoteServerGudHubInstance
|
|
13
|
+
) {
|
|
14
|
+
const files = [[]];
|
|
15
|
+
let results = [];
|
|
16
|
+
|
|
17
|
+
items.forEach(item => {
|
|
18
|
+
const itemId = item.item_id;
|
|
19
|
+
const field = item.fields.find(field => field.element_id === elementId);
|
|
20
|
+
|
|
21
|
+
if (field?.field_value) {
|
|
22
|
+
const fileIds = field.field_value.split('.');
|
|
29
23
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
24
|
+
fileIds.forEach(fileId => {
|
|
25
|
+
const newFile = {
|
|
26
|
+
source: fileId,
|
|
27
|
+
destination: {
|
|
28
|
+
app_id: appId,
|
|
29
|
+
item_id: itemId,
|
|
30
|
+
element_id: elementId
|
|
34
31
|
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
return self.gudhub.duplicateFile(filePack);
|
|
42
|
-
}).then(result => {
|
|
43
|
-
results = [
|
|
44
|
-
...results,
|
|
45
|
-
...result
|
|
46
|
-
]
|
|
47
|
-
})
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
chainPromises.then(() => {
|
|
51
|
-
items.forEach(item => {
|
|
52
|
-
const itemId = item.item_id;
|
|
53
|
-
const field = item.fields.find(field => field.element_id === elementId);
|
|
54
|
-
|
|
55
|
-
if(field && field.field_value) {
|
|
56
|
-
field.field_value = '';
|
|
57
|
-
results.forEach(file => {
|
|
58
|
-
if(file.item_id === itemId) {
|
|
59
|
-
field.field_value = field.field_value.split(',').filter(fileId => fileId).concat(file.file_id).join(',');
|
|
60
|
-
}
|
|
61
|
-
})
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
if (files[files.length - 1].length !== 10) { // 10 - max duplicate files
|
|
35
|
+
files[files.length - 1].push(newFile);
|
|
36
|
+
} else {
|
|
37
|
+
files.push([newFile]);
|
|
62
38
|
}
|
|
63
|
-
})
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
for (const filePack of files) {
|
|
44
|
+
if (!filePack.length) continue;
|
|
45
|
+
|
|
46
|
+
let result;
|
|
47
|
+
|
|
48
|
+
if (isInstallFromRemoteServer) {
|
|
49
|
+
result = await this._copyFilesFromRemoteServer(mapAppIds, filePack, remoteServerGudHubInstance);
|
|
50
|
+
} else {
|
|
51
|
+
result = await this.gudhub.duplicateFile(filePack);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
results = [
|
|
55
|
+
...results,
|
|
56
|
+
...result
|
|
57
|
+
];
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
items.forEach(item => {
|
|
61
|
+
const itemId = item.item_id;
|
|
62
|
+
const field = item.fields.find(field => field.element_id === elementId);
|
|
63
|
+
|
|
64
|
+
if (field?.field_value) {
|
|
65
|
+
field.field_value = '';
|
|
64
66
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
+
results.forEach(file => {
|
|
68
|
+
if (file.item_id === itemId) {
|
|
69
|
+
field.field_value = field.field_value
|
|
70
|
+
.split(',')
|
|
71
|
+
.filter(fileId => fileId)
|
|
72
|
+
.concat(file.file_id)
|
|
73
|
+
.join(',');
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
67
77
|
});
|
|
68
78
|
}
|
|
79
|
+
|
|
80
|
+
async _copyFilesFromRemoteServer(apps, filePack, remoteServerGudHubInstance) {
|
|
81
|
+
const createdFiles = [];
|
|
82
|
+
|
|
83
|
+
for (const file of filePack) {
|
|
84
|
+
const sourceFileIds = String(file.source)
|
|
85
|
+
.split(',')
|
|
86
|
+
.map(fileId => fileId.trim())
|
|
87
|
+
.filter(Boolean);
|
|
88
|
+
|
|
89
|
+
const appMap = apps.find(
|
|
90
|
+
app => app.new_app_id === file.destination.app_id
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
if (!appMap) {
|
|
94
|
+
console.warn('App mapping not found for:', file.destination.app_id);
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const sourceAppId = appMap.old_app_id;
|
|
99
|
+
|
|
100
|
+
for (const sourceFileId of sourceFileIds) {
|
|
101
|
+
const sourceFile = await remoteServerGudHubInstance.getFile(
|
|
102
|
+
sourceAppId,
|
|
103
|
+
sourceFileId
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
const createdFile = await this.gudhub.uploadFileFromString({
|
|
107
|
+
...sourceFile,
|
|
108
|
+
app_id: file.destination.app_id,
|
|
109
|
+
item_id: file.destination.item_id,
|
|
110
|
+
element_id: file.destination.element_id
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
createdFiles.push(createdFile);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return createdFiles;
|
|
118
|
+
}
|
|
69
119
|
}
|
package/GUDHUB/Utils/Utils.js
CHANGED
|
@@ -178,12 +178,12 @@ export class Utils {
|
|
|
178
178
|
return compiler(scheme, item, this, variables, appId)
|
|
179
179
|
}
|
|
180
180
|
|
|
181
|
-
fileInstallerHelper(appId, items, elementId) {
|
|
182
|
-
return this.FileHelper.fileInstallerHelper(appId, items, elementId);
|
|
181
|
+
fileInstallerHelper(mapAppIds, appId, items, elementId, isInstallFromRemoteServer, remoteServerGudHubInstance) {
|
|
182
|
+
return this.FileHelper.fileInstallerHelper(mapAppIds, appId, items, elementId, isInstallFromRemoteServer, remoteServerGudHubInstance);
|
|
183
183
|
}
|
|
184
|
-
|
|
185
|
-
createAppsFromTemplate(pack,
|
|
186
|
-
return this.AppsTemplateService.createAppsFromTemplate(pack,
|
|
184
|
+
|
|
185
|
+
createAppsFromTemplate(pack, remoteServerUrl, remoteServerAuthKey, isInstallFromRemoteServer, maxNumberOfInstalledItems, progressCallback) {
|
|
186
|
+
return this.AppsTemplateService.createAppsFromTemplate(pack, remoteServerUrl, remoteServerAuthKey, isInstallFromRemoteServer, maxNumberOfInstalledItems, progressCallback);
|
|
187
187
|
}
|
|
188
188
|
|
|
189
189
|
createApps(pack) {
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import axios from "axios";
|
|
6
6
|
import { convertObjToUrlParams } from "./utils.js";
|
|
7
7
|
import qs from "qs";
|
|
8
|
+
|
|
8
9
|
export class GudHubHttpsService {
|
|
9
10
|
constructor(server_url) {
|
|
10
11
|
this.root = server_url;
|
|
@@ -34,10 +35,11 @@ export class GudHubHttpsService {
|
|
|
34
35
|
if(request.externalResource) {
|
|
35
36
|
url = request.url;
|
|
36
37
|
} else {
|
|
38
|
+
const baseSeparator = /\?/.test(url) ? "&" : "?";
|
|
39
|
+
const paramsString = convertObjToUrlParams(request.params);
|
|
40
|
+
|
|
37
41
|
url = this.root + request.url;
|
|
38
|
-
url = `${url}${
|
|
39
|
-
/\?/.test(url) ? "&" : "?"
|
|
40
|
-
}token=${accessToken}${convertObjToUrlParams(request.params)}`;
|
|
42
|
+
url = `${url}${baseSeparator}${paramsString}${paramsString ? "&" : ""}token=${accessToken}`;
|
|
41
43
|
}
|
|
42
44
|
axios.get(url, {
|
|
43
45
|
validateStatus: function (status) {
|
|
@@ -107,42 +109,77 @@ export class GudHubHttpsService {
|
|
|
107
109
|
return promise;
|
|
108
110
|
}
|
|
109
111
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
112
|
+
/*************** AXIOS REQUEST ***************/
|
|
113
|
+
// It's using to send simple requests to custom urls without token
|
|
114
|
+
// If you want to send application/x-www-form-urlencoded, pass data in 'form' property of request
|
|
115
|
+
// If you wnt to send any other type of data, just pass it to 'body' property of request
|
|
114
116
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
+
axiosRequest(request) {
|
|
118
|
+
const hesh = this.getHashCodeForAxiosRequest(request);
|
|
117
119
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
120
|
+
if (this.requestPromises[hesh]) {
|
|
121
|
+
return this.requestPromises[hesh].promise;
|
|
122
|
+
}
|
|
121
123
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
if(request.form) {
|
|
126
|
-
headers['Content-Type'] = 'application/x-www-form-urlencoded';
|
|
127
|
-
}
|
|
124
|
+
const method = request.method ? request.method.toLowerCase() : "get";
|
|
125
|
+
const url = request.url;
|
|
126
|
+
const headers = { ...(request.headers || {}) };
|
|
128
127
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
headers
|
|
133
|
-
} : {});
|
|
134
|
-
resolve(data);
|
|
135
|
-
} catch(error) {
|
|
136
|
-
console.log("ERROR -> GUDHUB HTTP SERVICE -> SIMPLE POST :", error.message);
|
|
137
|
-
console.log("Request message: ", request);
|
|
138
|
-
reject(error);
|
|
139
|
-
}
|
|
140
|
-
});
|
|
128
|
+
const promise = new Promise(async (resolve, reject) => {
|
|
129
|
+
try {
|
|
130
|
+
let data = request.body;
|
|
141
131
|
|
|
142
|
-
|
|
132
|
+
if (request.form instanceof URLSearchParams) {
|
|
133
|
+
headers["Content-Type"] = "application/x-www-form-urlencoded";
|
|
134
|
+
data = request.form;
|
|
135
|
+
} else if (
|
|
136
|
+
typeof FormData !== "undefined" &&
|
|
137
|
+
request.form instanceof FormData
|
|
138
|
+
) {
|
|
139
|
+
data = request.form;
|
|
140
|
+
delete headers["Content-Type"];
|
|
141
|
+
} else if (request.form) {
|
|
142
|
+
headers["Content-Type"] = "application/x-www-form-urlencoded";
|
|
143
|
+
data = qs.stringify(request.form);
|
|
144
|
+
}
|
|
143
145
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
+
const config = {
|
|
147
|
+
url,
|
|
148
|
+
method,
|
|
149
|
+
headers,
|
|
150
|
+
maxBodyLength: Infinity,
|
|
151
|
+
validateStatus(status) {
|
|
152
|
+
return status < 400;
|
|
153
|
+
},
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
if (["post", "put", "patch"].includes(method)) {
|
|
157
|
+
config.data = data;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const response = await axios(config);
|
|
161
|
+
|
|
162
|
+
resolve(response.data);
|
|
163
|
+
} catch (error) {
|
|
164
|
+
console.log(
|
|
165
|
+
`ERROR -> GUDHUB HTTP SERVICE -> SIMPLE ${method.toUpperCase()} :`,
|
|
166
|
+
error.message
|
|
167
|
+
);
|
|
168
|
+
|
|
169
|
+
console.log("Request message: ", request);
|
|
170
|
+
|
|
171
|
+
if (error.response) {
|
|
172
|
+
console.log("Error response data:", error.response.data);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
reject(error);
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
this.pushPromise(promise, hesh);
|
|
180
|
+
|
|
181
|
+
return promise;
|
|
182
|
+
}
|
|
146
183
|
|
|
147
184
|
/*************** PUSH PROMISE ***************/
|
|
148
185
|
// It push promise object by hash to this.requestPromises
|
|
@@ -225,13 +262,14 @@ export class GudHubHttpsService {
|
|
|
225
262
|
};
|
|
226
263
|
|
|
227
264
|
const basis = {
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
265
|
+
url: request.url || "",
|
|
266
|
+
method: (request.method || request.request_method || "GET").toUpperCase(),
|
|
267
|
+
headers: request.headers || {},
|
|
268
|
+
params: request.params || {},
|
|
269
|
+
query: request.query || {},
|
|
270
|
+
body: request.body || null,
|
|
271
|
+
form: request.form || null,
|
|
272
|
+
externalResource: !!request.externalResource
|
|
235
273
|
};
|
|
236
274
|
|
|
237
275
|
const str = stableStringify(basis);
|
package/GUDHUB/utils.js
CHANGED
|
@@ -21,5 +21,5 @@ export function filterFields(fieldsToFilter = []) {
|
|
|
21
21
|
export function convertObjToUrlParams(obj = {}) {
|
|
22
22
|
const entries = Object.entries(obj);
|
|
23
23
|
if (!entries.length) return "";
|
|
24
|
-
return
|
|
25
|
-
}
|
|
24
|
+
return entries.map(([key, value]) => `${key}=${value}`).join("&");
|
|
25
|
+
}
|