awing-library 2.1.2-stable.4 → 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.
@@ -2,6 +2,6 @@ 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<unknown>;
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;
@@ -37,40 +37,41 @@ var getValueByPath = function (object, path) {
37
37
  };
38
38
  exports.getValueByPath = getValueByPath;
39
39
  var runScript = function (params, script) {
40
- var sandboxUrl = window.REACT_APP_API_ENDPOINT + '/api/Sandbox';
41
- fetch(sandboxUrl, {
42
- method: 'POST',
43
- headers: {
44
- "Content-Type": "application/json-patch+json",
45
- "Accept": "text/plain"
46
- },
47
- body: JSON.stringify({
48
- 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(),
49
- sandboxType: 0,
50
- }).trim(),
51
- credentials: 'include',
52
- })
53
- .then(function (r) { return r.json(); })
54
- .then(console.log);
55
- return new Promise(function (resolve, reject) {
56
- try {
57
- // eslint-disable-next-line
58
- var scriptFunction = new Function(script)();
59
- }
60
- catch (error) {
61
- scriptFunction = function () {
62
- var params = [];
63
- for (var _i = 0; _i < arguments.length; _i++) {
64
- params[_i] = arguments[_i];
65
- }
66
- return new Promise(function (resolve, reject) { return resolve([]); });
67
- };
68
- }
69
- scriptFunction.apply(void 0, params).then(function (result) {
70
- console.log('Script result:', result);
71
- resolve(result);
72
- });
73
- });
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
+ // })
74
75
  };
75
76
  exports.runScript = runScript;
76
77
  var convertRelativeLink = function (link, pagePath, templateId, configs) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "awing-library",
3
- "version": "2.1.2-stable.4",
3
+ "version": "2.1.2-stable.5",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",