@agilemotion/oui-react-js 2.0.2 → 2.0.3

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/DynamicJS.js CHANGED
@@ -15,6 +15,7 @@ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object
15
15
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
16
16
  function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
17
17
  const TEMPLATE_REGEX = exports.TEMPLATE_REGEX = new RegExp('[@]{1}([#@]{1}{)(([a-zA-Z0-9_.[\\]]*)+){1}}((\\(([^)]*)\\))*)', 'g');
18
+ const AsyncFunction = Object.getPrototypeOf(async function () {}).constructor;
18
19
  class DynamicJS {
19
20
  constructor() {
20
21
  var _this = this;
@@ -67,6 +68,10 @@ class DynamicJS {
67
68
  * @param scriptConfig
68
69
  * @param printError
69
70
  * @param scriptParam
71
+ * @param isAsync when true, the script body is wrapped in an AsyncFunction
72
+ * so it may use `await`. The call returns a Promise instead
73
+ * of a synchronous value. Defaults to false to preserve the
74
+ * behavior of every existing scriptlet caller.
70
75
  */
71
76
  _defineProperty(this, "executeScript", function (name, scriptCode, componentId) {
72
77
  let isScriplet = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
@@ -74,6 +79,7 @@ class DynamicJS {
74
79
  let scriptConfig = arguments.length > 5 ? arguments[5] : undefined;
75
80
  let printError = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : true;
76
81
  let scriptParam = arguments.length > 7 ? arguments[7] : undefined;
82
+ let isAsync = arguments.length > 8 && arguments[8] !== undefined ? arguments[8] : false;
77
83
  let parsedScript = _this.parseScript(scriptCode, componentId, isScriplet);
78
84
  let eventParam = null;
79
85
  if (!_Utils.default.isNull(event)) {
@@ -83,7 +89,9 @@ class DynamicJS {
83
89
  }
84
90
  try {
85
91
  // NB : The javascript serializer uses UCT for dates and it is 2 hours behind. TODO : use DateUtils.makeDateReplacer
86
- let func = new Function(parsedScript.replace(/\$event/g, JSON.stringify(eventParam)));
92
+ const body = parsedScript.replace(/\$event/g, JSON.stringify(eventParam));
93
+ const FunctionCtor = isAsync ? AsyncFunction : Function;
94
+ let func = new FunctionCtor(body);
87
95
  if (!_Utils.default.isNull(name)) {
88
96
  DynamicJS.prototype[name] = func;
89
97
  let result = instance[name](scriptParam ? scriptParam : {});
@@ -115,7 +123,8 @@ class DynamicJS {
115
123
  let event = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : null;
116
124
  let scriptParam = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : null;
117
125
  let scriptBody = _this.getScriptCode(script, valuesMap);
118
- return _this.executeScript(name, scriptBody, componentId, false, event, script, true, scriptParam);
126
+ const isAsync = !_Utils.default.isNull(script) && script.async === true;
127
+ return _this.executeScript(name, scriptBody, componentId, false, event, script, true, scriptParam, isAsync);
119
128
  });
120
129
  _defineProperty(this, "executeScriptFunction", function (scriptObject) {
121
130
  const fnCode = _this.parseScript(scriptObject, null, false);
@@ -14,9 +14,21 @@ class ScriptActionHandler {
14
14
  }
15
15
  return ScriptActionHandler.instance;
16
16
  }
17
- execute(actionConfig, event, component, currentViewId) {
18
- let componentId = event === null || event === void 0 ? void 0 : event.getSource().api.id;
19
- _DynamicJS.default.executeScriptObject(currentViewId + '_' + (componentId ? componentId : currentViewId) + '_script', actionConfig.script, componentId, {}, event);
17
+ async execute(actionConfig, event, component, currentViewId) {
18
+ const componentId = event === null || event === void 0 ? void 0 : event.getSource().api.id;
19
+ const scriptName = currentViewId + '_' + (componentId ? componentId : currentViewId) + '_script';
20
+ try {
21
+ const result = _DynamicJS.default.executeScriptObject(scriptName, actionConfig.script, componentId, {}, event);
22
+ if (result && typeof result.then === 'function') {
23
+ console.log("[ScriptActionHandler] awaiting async script:", scriptName);
24
+ return await result;
25
+ }
26
+ return result;
27
+ } catch (e) {
28
+ // Event-loop callers do not await execute(); rethrow would surface as
29
+ // an unhandled promise rejection. Log only — error stays visible in DevTools.
30
+ console.error("[ScriptActionHandler] script failed:", scriptName, e);
31
+ }
20
32
  }
21
33
  }
22
34
  const instance = new ScriptActionHandler();
package/dist/js/Docs.js CHANGED
@@ -116,28 +116,34 @@ class Docs {
116
116
  });
117
117
  });
118
118
  _defineProperty(this, "cacheAndPublish", async (file, correlationId, viewId, sourceApiId, orgCode) => {
119
- console.log("[Docs.cacheAndPublish] entry", "file=", file && {
120
- name: file.name,
121
- type: file.type,
122
- size: file.size
123
- }, "correlationId=", correlationId, "viewId=", viewId, "sourceApiId=", sourceApiId, "orgCode=", orgCode);
124
- try {
125
- const cacheFileId = await this.cacheFile(file, correlationId, orgCode);
126
- console.log("[Docs.cacheAndPublish] cacheFileId=", cacheFileId, "(correlationId=", correlationId, ")");
127
- _ApplicationManager.default.api.fireEvent('SERVICE_CALL_SUCCESS', {
128
- source: {
129
- api: {
130
- id: sourceApiId
131
- }
132
- },
133
- viewId: viewId,
134
- data: undefined
135
- });
136
- console.log("[Docs.cacheAndPublish] fired SERVICE_CALL_SUCCESS sourceApiId=", sourceApiId, "viewId=", viewId);
137
- return cacheFileId;
138
- } catch (e) {
139
- console.error("[Docs.cacheAndPublish] failed correlationId=", correlationId, "viewId=", viewId, "sourceApiId=", sourceApiId, "error=", e);
140
- throw e;
119
+ console.log("[Docs.cacheAndPublish] correlationId=", correlationId, "viewId=", viewId, "sourceApiId=", sourceApiId, "orgCode=", orgCode);
120
+ if (file) {
121
+ console.log("[Docs.cacheAndPublish] entry", "file=", file && {
122
+ name: file.name,
123
+ type: file.type,
124
+ size: file.size
125
+ }, "correlationId=", correlationId, "viewId=", viewId, "sourceApiId=", sourceApiId, "orgCode=", orgCode);
126
+ try {
127
+ const cacheFileId = await this.cacheFile(file, correlationId, orgCode);
128
+ console.log("[Docs.cacheAndPublish] cacheFileId=", cacheFileId, "(correlationId=", correlationId, ")");
129
+ _ApplicationManager.default.api.fireEvent('DOCUMENT_CACHED', {
130
+ source: {
131
+ api: {
132
+ id: sourceApiId
133
+ }
134
+ },
135
+ viewId: viewId,
136
+ data: cacheFileId
137
+ });
138
+ console.log("[Docs.cacheAndPublish] fired SERVICE_CALL_SUCCESS sourceApiId=", sourceApiId, "viewId=", viewId);
139
+ return cacheFileId;
140
+ } catch (e) {
141
+ console.error("[Docs.cacheAndPublish] failed correlationId=", correlationId, "viewId=", viewId, "sourceApiId=", sourceApiId, "error=", e);
142
+ throw e;
143
+ }
144
+ } else {
145
+ console.log("[Docs.cacheAndPublish] no file");
146
+ return null;
141
147
  }
142
148
  });
143
149
  _defineProperty(this, "removeAllHtmlBackGroundImages", htmlBase64 => {
@@ -156,4 +162,4 @@ class Docs {
156
162
  }
157
163
  exports.Docs = Docs;
158
164
  const instance = new Docs();
159
- var _default = exports.default = instance;
165
+ var _default = exports.default = instance; //COJ0003-25/26
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agilemotion/oui-react-js",
3
- "version": "2.0.2",
3
+ "version": "2.0.3",
4
4
  "description": "AgileMotion React UI Component Library - A comprehensive collection of dashboard components, forms, media controls, and more",
5
5
  "license": "ISC",
6
6
  "author": "",