awing-library 2.1.2-stable.3 → 2.1.2-stable.5
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.
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Configs } from
|
|
1
|
+
import { Configs } from './interface';
|
|
2
2
|
export declare const fillConfigs: (input: any) => any;
|
|
3
3
|
export declare const isJSON: (value: any) => boolean;
|
|
4
4
|
export declare const getValueByPath: (object: any, path: string) => any;
|
|
5
|
-
export declare const runScript: (params: any[], script: string) => Promise<
|
|
5
|
+
export declare const runScript: (params: any[], script: string) => Promise<any>;
|
|
6
6
|
export declare const convertRelativeLink: (link: string, pagePath: string, templateId: string, configs: Configs) => string;
|
|
7
7
|
export declare const generateRandomInteger: (max: number) => number;
|
|
@@ -15,12 +15,12 @@ var fillConfigs = function (input) {
|
|
|
15
15
|
};
|
|
16
16
|
exports.fillConfigs = fillConfigs;
|
|
17
17
|
var isJSON = function (value) {
|
|
18
|
-
if (typeof value !==
|
|
18
|
+
if (typeof value !== 'string')
|
|
19
19
|
return false;
|
|
20
20
|
try {
|
|
21
21
|
var result = JSON.parse(value);
|
|
22
22
|
var type = Object.prototype.toString.call(result);
|
|
23
|
-
return type ===
|
|
23
|
+
return type === '[object Object]' || type === '[object Array]';
|
|
24
24
|
}
|
|
25
25
|
catch (err) {
|
|
26
26
|
return false;
|
|
@@ -28,41 +28,60 @@ var isJSON = function (value) {
|
|
|
28
28
|
};
|
|
29
29
|
exports.isJSON = isJSON;
|
|
30
30
|
var getValueByPath = function (object, path) {
|
|
31
|
-
var keys = path.split(
|
|
31
|
+
var keys = path.split('.');
|
|
32
32
|
var result = object;
|
|
33
33
|
for (var i = 0; i < keys.length; i++) {
|
|
34
|
-
result = (result === null || result === void 0 ? void 0 : result[keys[i]]) ||
|
|
34
|
+
result = (result === null || result === void 0 ? void 0 : result[keys[i]]) || '';
|
|
35
35
|
}
|
|
36
36
|
return result;
|
|
37
37
|
};
|
|
38
38
|
exports.getValueByPath = getValueByPath;
|
|
39
39
|
var runScript = function (params, script) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
40
|
+
try {
|
|
41
|
+
var sandboxUrl = window.REACT_APP_API_ENDPOINT + '/api/Sandbox';
|
|
42
|
+
return fetch(sandboxUrl, {
|
|
43
|
+
method: 'POST',
|
|
44
|
+
headers: {
|
|
45
|
+
'Content-Type': 'application/json-patch+json',
|
|
46
|
+
Accept: 'text/plain',
|
|
47
|
+
},
|
|
48
|
+
body: JSON.stringify({
|
|
49
|
+
jsCode: "\n const fn = (function func() {\n ".concat(script, "\n })();\n return fn(").concat(Array.from(params).map(function (i) { return JSON.stringify(i); }), ");\n ").trim(),
|
|
50
|
+
sandboxType: 0,
|
|
51
|
+
}).trim(),
|
|
52
|
+
credentials: 'include',
|
|
53
|
+
})
|
|
54
|
+
.then(function (r) { return r.json(); })
|
|
55
|
+
.then(function (r) { return JSON.parse(r.jsResult); });
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
console.error('Error running script:', error);
|
|
59
|
+
return Promise.resolve([]);
|
|
60
|
+
}
|
|
61
|
+
// return new Promise((resolve, reject) => {
|
|
62
|
+
// try {
|
|
63
|
+
// // eslint-disable-next-line
|
|
64
|
+
// var scriptFunction = new Function(script)()
|
|
65
|
+
// } catch (error) {
|
|
66
|
+
// scriptFunction = (...params: any[]) => {
|
|
67
|
+
// return new Promise((resolve, reject) => resolve([]))
|
|
68
|
+
// }
|
|
69
|
+
// }
|
|
70
|
+
// scriptFunction(...params).then((result: any[]) => {
|
|
71
|
+
// console.log('Script result:', result)
|
|
72
|
+
// resolve(result)
|
|
73
|
+
// })
|
|
74
|
+
// })
|
|
58
75
|
};
|
|
59
76
|
exports.runScript = runScript;
|
|
60
77
|
var convertRelativeLink = function (link, pagePath, templateId, configs) {
|
|
61
78
|
var isTemplatePath = link === null || link === void 0 ? void 0 : link.includes(constant_1.ACM_TEMPLATE_PATH);
|
|
62
79
|
if (isTemplatePath) {
|
|
63
|
-
return "".concat(configs.TEMPLATE_FILE_PATH, "/").concat(templateId, "/").concat(link.split(
|
|
80
|
+
return "".concat(configs.TEMPLATE_FILE_PATH, "/").concat(templateId, "/").concat(link.split('/')[link.split('/').length - 1]);
|
|
64
81
|
}
|
|
65
|
-
return (link === null || link === void 0 ? void 0 : link.includes(constant_1.ACM_PAGE_PATH))
|
|
82
|
+
return (link === null || link === void 0 ? void 0 : link.includes(constant_1.ACM_PAGE_PATH))
|
|
83
|
+
? "".concat(pagePath, "/").concat(link.split('/')[link.split('/').length - 1]) || ''
|
|
84
|
+
: link;
|
|
66
85
|
};
|
|
67
86
|
exports.convertRelativeLink = convertRelativeLink;
|
|
68
87
|
var generateRandomInteger = function (max) {
|