@xuda.io/runtime-bundle 1.0.496 → 1.0.498

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.
@@ -10999,7 +10999,7 @@ func.expression.get_bad = async function (SESSION_ID, valP, dsSessionP, sourceP,
10999
10999
  return endResults();
11000
11000
  };
11001
11001
 
11002
- func.expression.parse = function (strP) {
11002
+ func.expression.parse_org = function (strP) {
11003
11003
  var extract_str = function (strP, posP) {
11004
11004
  if (!posP) posP = 0;
11005
11005
  var clean_split_str = function (arrP) {
@@ -11094,7 +11094,7 @@ func.expression.parse = function (strP) {
11094
11094
  return res;
11095
11095
  };
11096
11096
 
11097
- func.expression.parse_bad = function (input) {
11097
+ func.expression.parse = function (input) {
11098
11098
  if (typeof input !== 'string') return [];
11099
11099
 
11100
11100
  const segments = [];
@@ -11122,7 +11122,7 @@ func.expression.parse_bad = function (input) {
11122
11122
  return segments;
11123
11123
  };
11124
11124
 
11125
- func.expression.get_property = async function (valP) {
11125
+ func.expression.get_property_org = async function (valP) {
11126
11126
  async function secure_eval(val) {
11127
11127
  if (typeof IS_PROCESS_SERVER === 'undefined') {
11128
11128
  try {
@@ -11161,7 +11161,7 @@ func.expression.get_property = async function (valP) {
11161
11161
  };
11162
11162
  };
11163
11163
 
11164
- func.expression.get_property_bad = async function (valP) {
11164
+ func.expression.get_property = async function (valP) {
11165
11165
  if (typeof valP !== 'string') return { property1: undefined, property2: undefined };
11166
11166
 
11167
11167
  const secureEval = async (expr) => {
@@ -11206,27 +11206,33 @@ func.expression.get_property_bad = async function (valP) {
11206
11206
  return { property1, property2 };
11207
11207
  };
11208
11208
 
11209
- func.expression.validate_constant = function (valP) {
11209
+ func.expression.validate_constant_org = function (valP) {
11210
11210
  var patt = /["']/;
11211
11211
  if (typeof valP === 'string' && patt.test(valP.substr(0, 1)) && patt.test(valP.substr(0, valP.length - 1))) return true;
11212
11212
  else return false;
11213
11213
  };
11214
- func.expression.validate_variables = function (valP) {
11214
+ func.expression.validate_variables_org = function (valP) {
11215
11215
  if (typeof valP === 'string' && valP.indexOf('@') > -1) return true;
11216
11216
  else return false;
11217
11217
  };
11218
- func.expression.remove_quotes = function (valP) {
11218
+ func.expression.remove_quotes_org = function (valP) {
11219
11219
  if (func.expression.validate_constant(valP)) return valP.substr(1, valP.length - 2);
11220
11220
  else return valP;
11221
11221
  };
11222
11222
 
11223
- func.expression.validate_constant_bad = (valP) => typeof valP === 'string' && /^["'].*["']$/.test(valP);
11223
+ func.expression.validate_constant = function (valP) {
11224
+ typeof valP === 'string' && /^["'].*["']$/.test(valP);
11225
+ };
11224
11226
 
11225
- func.expression.validate_variables_bad = (valP) => typeof valP === 'string' && valP.includes('@');
11227
+ func.expression.validate_variables = function (valP) {
11228
+ typeof valP === 'string' && valP.includes('@');
11229
+ };
11226
11230
 
11227
- func.expression.remove_quotes_bad = (valP) => (func.expression.validate_constant(valP) && typeof valP === 'string' ? valP.slice(1, -1) : valP);
11231
+ func.expression.remove_quotes = function (valP) {
11232
+ func.expression.validate_constant(valP) && typeof valP === 'string' ? valP.slice(1, -1) : valP;
11233
+ };
11228
11234
 
11229
- func.expression.secure_eval = async function (SESSION_ID, sourceP, val, job_id, dsSessionP, js_script_callback, evt) {
11235
+ func.expression.secure_eval_org = async function (SESSION_ID, sourceP, val, job_id, dsSessionP, js_script_callback, evt) {
11230
11236
  const api_utils = await func.common.get_module(SESSION_ID, 'xuda-api-library.mjs', {
11231
11237
  func,
11232
11238
  glb,
@@ -11328,7 +11334,7 @@ func.expression.secure_eval = async function (SESSION_ID, sourceP, val, job_id,
11328
11334
  }
11329
11335
  };
11330
11336
 
11331
- func.expression.secure_eval_bad = async function (SESSION_ID, sourceP, val, job_id, dsSessionP, js_script_callback, evt) {
11337
+ func.expression.secure_eval = async function (SESSION_ID, sourceP, val, job_id, dsSessionP, js_script_callback, evt) {
11332
11338
  if (typeof val !== 'string') return val;
11333
11339
 
11334
11340
  const xu = await func.common.get_module(SESSION_ID, 'xuda-api-library.mjs', {
@@ -14807,7 +14807,7 @@ func.expression.get_bad = async function (SESSION_ID, valP, dsSessionP, sourceP,
14807
14807
  return endResults();
14808
14808
  };
14809
14809
 
14810
- func.expression.parse = function (strP) {
14810
+ func.expression.parse_org = function (strP) {
14811
14811
  var extract_str = function (strP, posP) {
14812
14812
  if (!posP) posP = 0;
14813
14813
  var clean_split_str = function (arrP) {
@@ -14902,7 +14902,7 @@ func.expression.parse = function (strP) {
14902
14902
  return res;
14903
14903
  };
14904
14904
 
14905
- func.expression.parse_bad = function (input) {
14905
+ func.expression.parse = function (input) {
14906
14906
  if (typeof input !== 'string') return [];
14907
14907
 
14908
14908
  const segments = [];
@@ -14930,7 +14930,7 @@ func.expression.parse_bad = function (input) {
14930
14930
  return segments;
14931
14931
  };
14932
14932
 
14933
- func.expression.get_property = async function (valP) {
14933
+ func.expression.get_property_org = async function (valP) {
14934
14934
  async function secure_eval(val) {
14935
14935
  if (typeof IS_PROCESS_SERVER === 'undefined') {
14936
14936
  try {
@@ -14969,7 +14969,7 @@ func.expression.get_property = async function (valP) {
14969
14969
  };
14970
14970
  };
14971
14971
 
14972
- func.expression.get_property_bad = async function (valP) {
14972
+ func.expression.get_property = async function (valP) {
14973
14973
  if (typeof valP !== 'string') return { property1: undefined, property2: undefined };
14974
14974
 
14975
14975
  const secureEval = async (expr) => {
@@ -15014,27 +15014,33 @@ func.expression.get_property_bad = async function (valP) {
15014
15014
  return { property1, property2 };
15015
15015
  };
15016
15016
 
15017
- func.expression.validate_constant = function (valP) {
15017
+ func.expression.validate_constant_org = function (valP) {
15018
15018
  var patt = /["']/;
15019
15019
  if (typeof valP === 'string' && patt.test(valP.substr(0, 1)) && patt.test(valP.substr(0, valP.length - 1))) return true;
15020
15020
  else return false;
15021
15021
  };
15022
- func.expression.validate_variables = function (valP) {
15022
+ func.expression.validate_variables_org = function (valP) {
15023
15023
  if (typeof valP === 'string' && valP.indexOf('@') > -1) return true;
15024
15024
  else return false;
15025
15025
  };
15026
- func.expression.remove_quotes = function (valP) {
15026
+ func.expression.remove_quotes_org = function (valP) {
15027
15027
  if (func.expression.validate_constant(valP)) return valP.substr(1, valP.length - 2);
15028
15028
  else return valP;
15029
15029
  };
15030
15030
 
15031
- func.expression.validate_constant_bad = (valP) => typeof valP === 'string' && /^["'].*["']$/.test(valP);
15031
+ func.expression.validate_constant = function (valP) {
15032
+ typeof valP === 'string' && /^["'].*["']$/.test(valP);
15033
+ };
15032
15034
 
15033
- func.expression.validate_variables_bad = (valP) => typeof valP === 'string' && valP.includes('@');
15035
+ func.expression.validate_variables = function (valP) {
15036
+ typeof valP === 'string' && valP.includes('@');
15037
+ };
15034
15038
 
15035
- func.expression.remove_quotes_bad = (valP) => (func.expression.validate_constant(valP) && typeof valP === 'string' ? valP.slice(1, -1) : valP);
15039
+ func.expression.remove_quotes = function (valP) {
15040
+ func.expression.validate_constant(valP) && typeof valP === 'string' ? valP.slice(1, -1) : valP;
15041
+ };
15036
15042
 
15037
- func.expression.secure_eval = async function (SESSION_ID, sourceP, val, job_id, dsSessionP, js_script_callback, evt) {
15043
+ func.expression.secure_eval_org = async function (SESSION_ID, sourceP, val, job_id, dsSessionP, js_script_callback, evt) {
15038
15044
  const api_utils = await func.common.get_module(SESSION_ID, 'xuda-api-library.mjs', {
15039
15045
  func,
15040
15046
  glb,
@@ -15136,7 +15142,7 @@ func.expression.secure_eval = async function (SESSION_ID, sourceP, val, job_id,
15136
15142
  }
15137
15143
  };
15138
15144
 
15139
- func.expression.secure_eval_bad = async function (SESSION_ID, sourceP, val, job_id, dsSessionP, js_script_callback, evt) {
15145
+ func.expression.secure_eval = async function (SESSION_ID, sourceP, val, job_id, dsSessionP, js_script_callback, evt) {
15140
15146
  if (typeof val !== 'string') return val;
15141
15147
 
15142
15148
  const xu = await func.common.get_module(SESSION_ID, 'xuda-api-library.mjs', {
@@ -2,7 +2,7 @@
2
2
  ${refIdP.value}
3
3
  })(document.querySelector(\`[xu-ui-id=${elementP}]\`),evt)`,null,null,null,evt);await func.datasource.set_outputField(SESSION_ID,dsSessionP,result,args);return result},execute_evaluate_javascript:async function(){const module=await func.common.get_module(SESSION_ID,"xuda-event-javascript-module.mjs");const result=await module.run_javascript(SESSION_ID,jobNoP,dsSession,`(async function(el,evt) {
4
4
  ${refIdP.value}
5
- })(document.querySelector(\`[xu-ui-id=${elementP}]\`),evt)`,true,null,null,evt);await func.datasource.set_outputField(SESSION_ID,dsSessionP,result,args);return result},loader_on:async function(){glb.CURRENT_APP_LOADING=null;LOADER_ACTIVE=true;LOADER_TEXT=descP;func.events.delete_job(SESSION_ID,jobNoP)},loader_off:async function(){LOADER_ACTIVE=false;func.events.delete_job(SESSION_ID,jobNoP)},emit_event:async function(){if(refIdP.value){$(document).trigger(refIdP.value,[_session.DS_GLB[dsSession]])}else{func.utils.debug_report(SESSION_ID,"func.events.execute","Event name missing","E")}func.events.delete_job(SESSION_ID,jobNoP)},invoke_action:async function(){func.utils.debug.watch(SESSION_ID,calling_trigger_prop?.id,functionP,null,null,expCond);await func.action.execute(SESSION_ID,refIdP.value,_ds,null,null,jobNoP,containerP)},raise_event:async function(){var _ds=_session.DS_GLB[dsSession];const _view_obj=await func.utils.VIEWS_OBJ.get(SESSION_ID,_ds.prog_id);if(callingSourceP==="grid"||callingSourceP==="form"){let _field_obj=func.common.find_item_by_key(_view_obj.progFields,"field_id",field_elm);var event_name=_field_obj?.triggers?.[eventIdP].name.event;if(_field_obj?.triggers?.[eventIdP].name?.properties["xu-exp:event"]){event_name=(await func.expression.get(SESSION_ID,props[`xu-exp:event`],dsSession,"event_name expression")).result}if(field_elm&&event_name){const dsP=await func.datasource.find_event_dataSource(SESSION_ID,event_name,dsSession);return await func.datasource.run_events_functions(SESSION_ID,dsP,event_name,jobNoP,null,calling_trigger_prop?.data?.name?.parameters||{})}}if(callingSourceP.includes("event")){let event_name=refIdP.event;if(refIdP?.properties?.["xu-exp:event"]){event_name=(await func.expression.get(SESSION_ID,refIdP.properties["xu-exp:event"],dsSession,"event_name expression")).result}const dsP=await func.datasource.find_event_dataSource(SESSION_ID,event_name,dsSession);await func.datasource.run_events_functions(SESSION_ID,dsP,event_name,jobNoP,calling_trigger_prop?.props?.async,calling_trigger_prop?.data?.name?.parameters||{})}func.events.delete_job(SESSION_ID,jobNoP);func.utils.debug.watch(SESSION_ID,calling_trigger_prop?.id,functionP,"","",expCond)},get_data:async function(){const params_obj=await get_params_obj();if(!await get_prog_id()){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} > ${triggerP} > ${functionP} > program ${prog} is missing`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}var _ds=_session.DS_GLB[dsSession];if(!_ds){func.events.delete_job(SESSION_ID,jobNoP);return}if(_ds){func.utils.debug.watch(SESSION_ID,calling_trigger_prop?.id,functionP,null,calling_trigger_prop,expCond);const ret=await func.datasource.create(SESSION_ID,await get_prog_id(),args.dataSourceNoP,args.parentDataSourceNoP,args.containerIdP,args.rowIdP,args.jobNoP,args.calling_trigger_prop,null,null,args.callingSourceP,args.calling_jobP,args.screen_dsP,args.is_panelP,params_obj);let _ds_new=_session.DS_GLB[ret.dsSessionP];let parameters=args?.calling_trigger_prop?.data?.name?.parameters;if(parameters&&!_.isEmpty(parameters)){await func.datasource.update_changes_for_out_parameter(SESSION_ID,_ds_new.dsSession,_ds.dsSession)}func.events.delete_job(SESSION_ID,jobNoP);return _ds_new}},set_data:async function(){return this.get_data()},batch:async function(){const result=await this.get_data();return result},update:async function(){const obj_values_to_update=func.datasource.get_viewFields_for_update_function(SESSION_ID,calling_trigger_prop,null,dsSessionP);if(!obj_values_to_update||_.isEmpty(obj_values_to_update)){func.utils.debug_report(SESSION_ID,"Update values object is empty","","W");if(jobNoP)func.events.delete_job(SESSION_ID,jobNoP);return}var updates=[];for await(const[key,val]of Object.entries(obj_values_to_update)){var $element;if(elementP){$element=$(`[xu-ui-id="${elementP}"]`).clone(true)}let ret_field_id=await func.expression.get(SESSION_ID,val.id.trim(),dsSessionP,"update",null,null,null,null,null,null,$element?.length?$element?.data()?.xuData?.iterate_info:null);let ret_value=await func.expression.get(SESSION_ID,val.val.trim(),dsSessionP,"update",null,null,null,null,null,null,$element?.length?$element?.data()?.xuData?.iterate_info:null);let _field_id=ret_field_id.result;let _value=ret_value.result;updates.push({_field_id:_field_id,_value:_value})}let datasource_changes={};for await(const change of updates){let ret_get_value=await func.datasource.get_value(SESSION_ID,change._field_id,dsSessionP);if(ret_get_value.found){let _ds=_session.DS_GLB[ret_get_value.dsSessionP];if(!datasource_changes[_ds.dsSession]){datasource_changes[_ds.dsSession]={}}if(!datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]){datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]={}}datasource_changes[_ds.dsSession][ret_get_value.currentRecordId][change._field_id]=change._value}}await func.datasource.update(SESSION_ID,datasource_changes);if(jobNoP)func.events.delete_job(SESSION_ID,jobNoP)},call_alert:async function(){await func.utils.alerts.invoke(SESSION_ID,"call_alert",refIdP,log_source,dsSession);func.events.delete_job(SESSION_ID,jobNoP)},alert:async function(){await func.utils.alerts.invoke(SESSION_ID,"alert",refIdP,log_source,dsSession);func.events.delete_job(SESSION_ID,jobNoP)},delay:async function(){return new Promise(resolve=>{setTimeout(function(){if(jobNoP)func.events.delete_job(SESSION_ID,jobNoP);resolve()},refIdP.value)})},comment:async function(){if(jobNoP)func.events.delete_job(SESSION_ID,jobNoP)},call_project_api:async function(){const params_obj=await get_params_obj();const _prog_id=await get_prog_id();if(!_prog_id){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} > ${triggerP} > ${functionP} > program not defined`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}const api_ret=await func.api.call_project_api(_prog_id,params_obj);await func.datasource.set_outputField(SESSION_ID,dsSessionP,api_ret,args);func.events.delete_job(SESSION_ID,jobNoP)},call_system_api:async function(){const api_method=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"api_method");if(!api_method){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} >${triggerP} >${functionP} > api_method not defined`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}let payload={};const _payload=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"payload");if(_payload){const get_payload_property_value=async function(prop_name){let _prop=_payload;let _value=_prop[prop_name];if(_prop?.[`xu-exp:${prop_name}`]){_value=(await func.expression.get(SESSION_ID,_prop[`xu-exp:${prop_name}`],dsSession,`${prop_name} expression`)).result}return _value};for await(let[key,val]of Object.entries(_payload)){const new_key=key.replaceAll("xu-exp:","");payload[new_key]=await get_payload_property_value(new_key)}}const output_field=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"outputField");const api_ret=await func.api.call_system_api(api_method,payload);if(output_field){let datasource_changes={};let ret_get_value=await func.datasource.get_value(SESSION_ID,output_field,dsSessionP);if(ret_get_value.found){let _ds=_session.DS_GLB[ret_get_value.dsSessionP];if(!datasource_changes[_ds.dsSession]){datasource_changes[_ds.dsSession]={}}if(!datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]){datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]={}}datasource_changes[_ds.dsSession][ret_get_value.currentRecordId][output_field]=api_ret;await func.datasource.update(SESSION_ID,datasource_changes)}}func.events.delete_job(SESSION_ID,jobNoP)},call_external_api:async function(){const method=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"method");if(!method){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} >${triggerP} >${functionP} > method not defined`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}const url=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"url");if(!url){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} >${triggerP} >${functionP} > url not defined`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}const payload_arr=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"payload");const report_conversion_error=function(res,typeP,valP){var msg=`${elementP} >${triggerP} >${functionP} > error converting from ${valP} to ${typeP}`;if(error){return func.utils.debug_report(SESSION_ID,msg,"","W")}func.utils.debug_report(SESSION_ID,msg+" "+_.capitalize(source)+prog_info,"","E")};const report_conversion_warn=function(res){var msg=`${elementP} >${triggerP} >${functionP} > type mismatch auto conversion from value ${valP} to ${typeP}`;func.utils.debug_report(SESSION_ID,msg+" "+_.capitalize(source)+prog_info,"","W")};if(error){return report_conversion_error()}const module=await func.common.get_module(SESSION_ID,"xuda-get-cast-util-module.mjs");var payload=_.reduce(payload_arr,(ret,val,key)=>{ret[val.key]=module.cast(val.type,val.val,report_conversion_error,report_conversion_warn);return ret},{});const output_field=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"outputField");const api_ret=await func.api.call_external_api(method,url,payload);if(output_field){let datasource_changes={};let ret_get_value=await func.datasource.get_value(SESSION_ID,output_field,dsSessionP);if(ret_get_value.found){let _ds=_session.DS_GLB[ret_get_value.dsSessionP];if(!datasource_changes[_ds.dsSession]){datasource_changes[_ds.dsSession]={}}if(!datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]){datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]={}}datasource_changes[_ds.dsSession][ret_get_value.currentRecordId][output_field]=api_ret;await func.datasource.update(SESSION_ID,datasource_changes)}}func.events.delete_job(SESSION_ID,jobNoP)}};return await fx[functionP]()};func.events.delete_job=function(SESSION_ID,jobNoP){var _session=SESSION_OBJ[SESSION_ID];var job_index=func.events.find_job_index(SESSION_ID,jobNoP);if(!_session.WORKER_OBJ.jobs[job_index]){_session.WORKER_OBJ.stat=null;return}var dsSession=_session.WORKER_OBJ.jobs[job_index].dsSessionP;let ds_obj=_session?.DS_GLB[dsSession];if(ds_obj){delete SCREEN_BLOCKER_OBJ[ds_obj.screenId+(ds_obj.callingScreenId?"_"+ds_obj.callingScreenId:"")]}if(dsSession&&ds_obj?.loops_limit&&ds_obj?.loops_count<ds_obj?.loops_limit-1){return}_session.WORKER_OBJ.stat=null;_session.WORKER_OBJ.jobs.splice(job_index,1)};func.events.delete_job_0=function(SESSION_ID){var job_index=0;var _session=SESSION_OBJ[SESSION_ID];if(!_session.WORKER_OBJ.jobs[job_index]){_session.WORKER_OBJ.stat=null;return}var dsSession=_session.WORKER_OBJ.jobs[job_index].dsSession;let ds_obj=_session?.DS_GLB[dsSession];if(ds_obj){delete SCREEN_BLOCKER_OBJ[ds_obj.screenId+(ds_obj.callingScreenId?"_"+ds_obj.callingScreenId:"")]}if(dsSession&&ds_obj&&ds_obj.loops_limit&&ds_obj.loops_count<ds_obj.loops_limit-1){return}_session.WORKER_OBJ.stat=null;_session.WORKER_OBJ.jobs.splice(job_index,1)};func.events.check_jobs_idle=async function(SESSION_ID,jobsP){return new Promise((resolve,reject)=>{var _session=SESSION_OBJ[SESSION_ID];if(!jobsP||jobsP&&jobsP.length===0){resolve();return}var listener=setInterval(function(){var found;for(const[key,val]of Object.entries(jobsP)){_.forEach(_session.WORKER_OBJ.jobs,function(val2,key2){if(key2===val){found=true;return false}})}if(!found){do_callback();return}},100);var do_callback=function(){window.clearInterval(listener);resolve()}})};var loop_detected_obj={};setInterval(function(){loop_detected_obj={}},1e3);func.events.set_browser_changes=function(dsP,fieldsChangedP){if(fieldsChangedP.includes("SYS_GLOBAL_STR_BROWSER_TITLE"))document.title=dsP.dataset_new["SYS_GLOBAL_STR_BROWSER_TITLE"]};func.events.execute_PENDING_OPEN_URL_EVENTS=async function(){for(let[key,url]of Object.entries(PENDING_OPEN_URL_EVENTS)){if(url){glb.WINDOW_LOCATION_SEARCH=url;glb.ROOT_ELEMENT_ATTRIBUTES=func.UI.utils.get_root_element_attributes();const params_obj=func.common.getObjectFromUrl(url,glb.ROOT_ELEMENT_ATTRIBUTES);if(!params_obj.prog){return console.warn("prog empty")}await func.utils.TREE_OBJ.get(SESSION_ID,params_obj.prog);let screen_ret=await func.utils.get_screen_obj(SESSION_ID,params_obj.prog);if(screen_ret){await func.UI.screen.init(SESSION_ID,params_obj.prog,null,null,$("#embed_"+SESSION_ID),null,null,null,null,null,"pendingUrlEvent_embed")}else{console.error("Program not exist",params_obj.prog_id);func.UI.utils.progressScreen.show(SESSION_ID,"Program not exist",null,true)}}else{console.warn("url empty")}}};func.events.invoke=async function(event_id){var _session=SESSION_OBJ[SESSION_ID];if(!event_id){console.warn("event_id Cannot be empty");return false}var ds;for await(const[ds_key,val]of Object.entries(_session.DS_GLB)){const _view_obj=await func.utils.VIEWS_OBJ.get(SESSION_ID,val.prog_id);if(_.isEmpty(_view_obj.progEvents))continue;if(ds)break;for await(const[key,val]of Object.entries(_view_obj.progEvents)){if(val?.data?.type==="user_defined"&&val.data.event_name===event_id){ds=ds_key;break}}}if(!ds){console.warn("event_id not found");return false}func.events.validate(SESSION_ID,"user_defined",ds,event_id)};func.expression={};func.expression.get=async function(SESSION_ID,valP,dsSessionP,sourceP,rowIdP,sourceActionP,secondPassP,calling_fieldIdP,fieldsP,debug_infoP,iterate_info,js_script_callback,jobNo,api_output_type){class xu_class{async get(){var ret;var fields={};var error;var warning;function evalJson(text){return eval("("+text+")")}if(valP===null){ret=""}else{switch(typeof valP){case"string":ret=valP;break;case"undefined":ret="";break;case"boolean":ret=valP?"Y":"N";break;default:ret=valP.toString();break}}ret=ret.replace(/\&amp;/g,"&");ret=func.utils.replace_studio_drive_url(SESSION_ID,ret);const end_results=function(){const replace_quotes=function(ret){for(const[key,val]of Object.entries(fields)){if(typeof val==="string")ret=ret.replace('"'+val+'"',val.replace(/"/gi,""))}return ret};if(["update","javascript"].includes(sourceP)){if(typeof ret==="string")ret=replace_quotes(ret)}const log_error=function(){if(SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP]){func.utils.debug.log(SESSION_ID,SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP].nodeId,{module:"expression",action:sourceP,source:calling_fieldIdP,prop:ret,details:ret,result:ret,error:error,warning:warning,fields:null,type:"exp",prog_id:SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP].prog_id,debug_info:debug_infoP})}};if(error)log_error();return{result:ret,fields:fields,res:res,explain:result,error:error,warning:warning,req:valP,var_error_found:var_error_found}};const variable_not_exist=async function(){try{if(sourceP!=="arguments"){if(ret&&ret.substr(0,6)==="_DATE_"){ret=ret.substr(6)}else if(ret&&ret.length===10&&ret.substr(4,1)==="-"&&ret.substr(7,1)==="-"||ret==="self"){ret=ret}else{ret=await func.expression.secure_eval(SESSION_ID,sourceP,ret,jobNo,dsSessionP,js_script_callback)}return end_results()}else{ret=ret.replace(/_NULL/gi,"");return end_results()}}catch(err){return end_results()}};if(!func.expression.validate_variables(valP)){return await variable_not_exist()}const validate_email=async function(){const ret=await func.expression.secure_eval(SESSION_ID,sourceP,valP,jobNo,dsSessionP,js_script_callback);return glb.emailRegex.test(ret)};if(await validate_email()){return await variable_not_exist()}var var_Arr=[];const split=func.expression.parse(ret)||[];for await(const[arr_key,val]of Object.entries(split)){const key=Number(arr_key);var_Arr[key]={};var_Arr[key].value=val.value;const replace_value_in_string=async function(retP,fieldIdP){if(iterate_info?.iterator_key===fieldIdP||iterate_info?.iterator_val===fieldIdP){if(iterate_info.iterator_key===fieldIdP){retP.value=iterate_info._key}if(iterate_info.iterator_val===fieldIdP){retP.value=iterate_info._val}}const set_value=function(valP){if(typeof valP!=="undefined"){var_Arr[key].value=valP;if(typeof valP==="string")var_Arr[key].type="string"}else{if(retP.type==="object"){var_Arr[key].value="";var_Arr[key].type="string"}}};if(sourceP==="exp"&&retP.type!=="exp"){var_Arr[key].type=retP.type;return}if(typeof retP.value!=="undefined"){var_Arr[key].type=retP.type;var_Arr[key].value=retP.value;if(val.value.indexOf("[")>-1|val.value.indexOf(".")>-1){var data=retP.prop;if(retP.type==="object")data=retP.value;var property1,property2;if(val.value.indexOf("[")===-1&&val.value.indexOf("]")>-1&&val.value.substr(0,1)==="@"){var prevData=var_Arr[key-1].value;var_Arr[key].value=prevData[data];if(val.value.indexOf(".")>-1){property2=await func.expression.get_property(val.value).property2;if(prevData[data])set_value(prevData[data][property2])}delete var_Arr[key-1]}else{property1=await func.expression.get_property(val.value).property1;property2=await func.expression.get_property(val.value).property2;if(property1){var_Arr[key].value=data[property1];if(property2){if(data[property1])set_value(data[property1][property2])}}if(property2&&!property1){if(data){set_value(data[property2])}}}fields[fieldIdP]=var_Arr[key].value;var_Arr[key].fieldId=fieldIdP}else{fields[fieldIdP]=var_Arr[key].value;var_Arr[key].fieldId=fieldIdP}}};if(val.fieldId){if(val.fieldId&&val.fieldId.substr(0,5)==="_THIS"&&calling_fieldIdP&&(val.fieldId.length===5||val.fieldId.length>5&&val.fieldId.substr(5,1)===".")){if(val.fieldId.length===5)val.fieldId=calling_fieldIdP;else val.fieldId=calling_fieldIdP+val.fieldId(5,val.fieldId.length-1)}if(!sourceP==="exp"){var_Arr[key].value='""'}fields[val.fieldId]=var_Arr[key].value;const ret=await func.datasource.get_value(SESSION_ID,val.fieldId,dsSessionP,rowIdP);await replace_value_in_string(ret.ret,ret.fieldIdP)}}try{var res=[];var exp_exist;var var_error_found;_.forEach(var_Arr,function(val,key){if(sourceP==="UI Property EXP"){let ret=func.utils.get_drive_url(SESSION_ID,val.value,true);if(ret.changed){res[key]=ret.value;return true}}if(sourceP==="UI Attr EXP"){let ret=func.utils.get_drive_url(SESSION_ID,val.value,var_Arr.length==1?false:true);if(ret.changed){res[key]=ret.value;return true}}if(val.type==="exp"){exp_exist=true}res[key]=val.value;if(var_Arr.length>1){if(!["DbQuery","alert","exp","api_rendered_output"].includes(sourceP)&&["string","date"].includes(val.type)){res[key]="`"+val.value+"`"}if(["api_rendered_output"].includes(sourceP)&&["json"].includes(api_output_type)&&["string","date"].includes(val.type)){res[key]=`"`+val.value+`"`}}if(val.fieldId&&val.value&&typeof val.value==="string"){if(["query","condition","range","sort","locate"].includes(sourceP)){if(val.value.indexOf("↵")>-1){res[key]=val.value.split("↵").join("")}res[key]=res[key].replace(/(\r\n|\n|\r)/gm,"")}if(["init","update","virtual"].includes(sourceP)){if(val.value.indexOf("↵")>-1)res[key]=val.value.split("↵").join("\n");res[key]=res[key].replace(/(\r\n|\n|\r)/gm,"\\n")}if(typeof IS_PROCESS_SERVER!=="undefined"){res[key]=res[key].replace(/(\r\n|\n|\r)/gm,"<br>")}fields[val.fieldId]=res[key]}if(typeof val.value==="object"&&var_Arr.length>1){if(!Array.isArray(val.value)&&!var_Arr[key+1].value?.includes(".")){res[key]="("+JSON.stringify(val.value)+")"}else{res[key]=JSON.stringify(val.value)}}if(!exp_exist&&sourceP!=="exp"&&val.value&&typeof val.value==="string"&&val.value.substr(0,1)==="@"){warning="Error encoding "+val.value;var_error_found=true;res[key]=0}});const join=function(arrP){return arrP.join("")};var exp=undefined;if(exp_exist&&sourceP!=="exp"){exp=await func.expression.get(SESSION_ID,join(res),dsSessionP,sourceP,rowIdP,sourceActionP,true,calling_fieldIdP,fields,debug_infoP);if(exp.res)res=exp.res;else res=[exp.result];fields=_.assignIn(exp.fields,fieldsP)}var result=join(res);if(res.length===1){result=res[0]}if(secondPassP){ret=result}else if(sourceP!=="exp"){if(res.length===1&&typeof res[0]==="string"&&typeof res[0]!=="object"){ret=join(res);if(ret&&ret.substr(0,1)==="@"){error="Error encoding @ var";var_error_found=true}}else{if(!["arguments","api_rendered_output","DbQuery"].includes(sourceP)){ret=await func.expression.secure_eval(SESSION_ID,sourceP,result,jobNo,dsSessionP,js_script_callback)}else{if(sourceP==="DbQuery"){ret=JSON.stringify(evalJson(result))}else{ret=result}}}}return end_results()}catch(err){ret=result;error=err.message;return end_results()}}}const new_class=new xu_class;return new_class.get()};func.expression.get_bad=async function(SESSION_ID,valP,dsSessionP,sourceP,rowIdP,sourceActionP,secondPassP,calling_fieldIdP,fieldsP={},debug_infoP,iterate_info,js_script_callback,jobNo,api_output_type){const evalJson=text=>eval(`(${text})`);const replaceQuotes=str=>{for(const[key,val]of Object.entries(fields)){if(typeof val==="string")str=str.replace(`"${val}"`,val.replace(/"/g,""))}return str};let ret,error,warning,var_error_found;const fields={...fieldsP};if(valP===null||typeof valP==="undefined")ret="";else if(typeof valP==="boolean")ret=valP?"Y":"N";else ret=valP.toString();ret=ret.replace(/\&/g,"&");ret=func.utils.replace_studio_drive_url(SESSION_ID,ret);const endResults=()=>{if(["update","javascript"].includes(sourceP)&&typeof ret==="string"){ret=replaceQuotes(ret)}if((error||warning)&&SESSION_OBJ[SESSION_ID]?.DS_GLB[dsSessionP]){func.utils.debug.log(SESSION_ID,SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP].nodeId,{module:"expression",action:sourceP,source:calling_fieldIdP,prop:ret,details:ret,result:ret,error:error,warning:warning,fields:null,type:"exp",prog_id:SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP].prog_id,debug_info:debug_infoP})}return{result:ret,fields:fields,error:error,warning:warning,req:valP,var_error_found:var_error_found}};const handleNonVariable=async()=>{try{if(sourceP!=="arguments"){if(ret.startsWith("_DATE_"))ret=ret.slice(6);else if(/^\d{4}-\d{2}-\d{2}$/.test(ret)||ret==="self")return endResults();else ret=await func.expression.secure_eval(SESSION_ID,sourceP,ret,jobNo,dsSessionP,js_script_callback)}else{ret=ret.replace(/_NULL/gi,"")}return endResults()}catch(err){error=err.message;return endResults()}};if(!func.expression.validate_variables(valP))return await handleNonVariable();if(glb.emailRegex.test(await func.expression.secure_eval(SESSION_ID,sourceP,valP,jobNo,dsSessionP,js_script_callback))){return await handleNonVariable()}const split=func.expression.parse(ret)||[];const var_Arr=await Promise.all(split.map(async(val,key)=>{const result={value:val.value,fieldId:val.fieldId};if(!val.fieldId)return result;if(val.fieldId.startsWith("_THIS")&&calling_fieldIdP){result.fieldId=val.fieldId.length===5?calling_fieldIdP:calling_fieldIdP+val.fieldId.slice(5)}const{ret:fetchedValue,fieldIdP}=await func.datasource.get_value(SESSION_ID,result.fieldId,dsSessionP,rowIdP);result.value=fetchedValue?.value??(sourceP==="exp"?fetchedValue?.value:'""');result.type=fetchedValue?.type;if(iterate_info){if(iterate_info.iterator_key===fieldIdP)result.value=iterate_info._key;if(iterate_info.iterator_val===fieldIdP)result.value=iterate_info._val}if(val.value.includes("[")||val.value.includes(".")){const{property1,property2}=await func.expression.get_property(val.value);const data=fetchedValue?.type==="object"?fetchedValue.value:fetchedValue?.prop;if(key>0&&val.value.includes("]")&&!val.value.includes("[")&&split[key-1].value){const prevData=split[key-1].value;result.value=prevData[fieldIdP];if(val.value.includes(".")&&prevData[fieldIdP]){result.value=prevData[fieldIdP][property2]??""}}else if(data){if(property1)result.value=data[property1]??"";if(property2)result.value=(property1?data[property1]?.[property2]:data[property2])??""}}fields[fieldIdP]=result.value;return result}));try{const res=var_Arr.map((val,key)=>{if(sourceP==="UI Property EXP"||sourceP==="UI Attr EXP"){const{changed,value}=func.utils.get_drive_url(SESSION_ID,val.value,sourceP==="UI Attr EXP"&&var_Arr.length>1);if(changed)return value}let value=val.value;if(var_Arr.length>1){if(!["DbQuery","alert","exp","api_rendered_output"].includes(sourceP)&&["string","date"].includes(val.type)){value=`\`${value}\``}else if(sourceP==="api_rendered_output"&&api_output_type==="json"&&["string","date"].includes(val.type)){value=`"${value}"`}}if(val.fieldId&&typeof value==="string"){if(["query","condition","range","sort","locate"].includes(sourceP))value=value.replace(/↵|\r\n|\n|\r/g,"");if(["init","update","virtual"].includes(sourceP))value=value.replace(/↵|\r\n|\n|\r/g,"\\n");if(typeof IS_PROCESS_SERVER!=="undefined")value=value.replace(/↵|\r\n|\n|\r/g,"<br>");fields[val.fieldId]=value}if(typeof value==="object"&&var_Arr.length>1){value=Array.isArray(value)||var_Arr[key+1]?.value?.includes(".")?JSON.stringify(value):`(${JSON.stringify(value)})`}if(!val.type==="exp"&&sourceP!=="exp"&&typeof value==="string"&&value.startsWith("@")){warning=`Error encoding ${value}`;var_error_found=true;return"0"}return value});ret=res.length===1?res[0]:res.join("");if(var_Arr.some(v=>v.type==="exp")&&sourceP!=="exp"&&!secondPassP){const exp=await func.expression.get(SESSION_ID,ret,dsSessionP,sourceP,rowIdP,sourceActionP,true,calling_fieldIdP,fields,debug_infoP);ret=exp.res?.[0]??exp.result;Object.assign(fields,exp.fields)}else if(!secondPassP&&!["arguments","api_rendered_output","DbQuery"].includes(sourceP)){ret=await func.expression.secure_eval(SESSION_ID,sourceP,ret,jobNo,dsSessionP,js_script_callback)}else if(sourceP==="DbQuery"){ret=JSON.stringify(evalJson(ret))}if(typeof ret==="string"&&ret.startsWith("@")){error="Error encoding @ var";var_error_found=true}}catch(err){error=err.message}return endResults()};func.expression.parse=function(strP){var extract_str=function(strP,posP){if(!posP)posP=0;var clean_split_str=function(arrP){var arr=[];if(arrP&&arrP.length>1&&arrP[0]===""&&arrP[1].indexOf("@")>-1){for(var i=1;i<=arrP.length;i++){arr.push(arrP[i])}return arr}else return arrP};var nonLettersPatt=/\W/;var validSymbolsNoArray=/[^.@\[]/;var validSymbolsWithArray=/[^.@"'\[\]]/;var validSymbols=validSymbolsNoArray;var splitTmp=strP.replace(/@/g,"^^@").split("^^");var split=clean_split_str(splitTmp);var obj=[];if(split){for(let val of split){if(val){var pos=strP.indexOf(val);if(val&&val.substr(0,1)==="@"){var tmpStr="";var word_start_pos=undefined;var word_end_pos=undefined;for(var i=0;i<=val.length;i++){var key1=i;var val1=val.substr(i,1);if(val1==="."&&!word_start_pos)word_start_pos=key1;if(word_start_pos&&key1>word_start_pos&&nonLettersPatt.test(val1))word_end_pos=key1;if(word_start_pos&&word_start_pos>=0&&word_end_pos&&word_end_pos>=0){var word=val.substr(word_start_pos+1,word_end_pos-word_start_pos-1);tmpStr=tmpStr.substr(0,word_start_pos)+"^^"+tmpStr.substr(word_start_pos,word_end_pos);if(val.substr(word_end_pos,1)===".")word_start_pos=word_end_pos;else word_start_pos=null;word_end_pos=null}if(val1==="[")validSymbols=validSymbolsWithArray;if(nonLettersPatt.test(val1)&&validSymbols.test(val1)&&tmpStr.indexOf("^^")===-1){tmpStr+="^^"+val1}else tmpStr+=val1}if(tmpStr.indexOf("^^")>-1){var obj1=extract_str(tmpStr,pos);obj=obj.concat(obj1)}else{var fieldId=undefined;if(val){fieldId=val.substr(1,val.length);if(val.indexOf(".")>-1)fieldId=val.substr(1,val.indexOf(".")-1);if(val.indexOf("[")>-1)fieldId=val.substr(1,val.indexOf("[")-1)}obj.push({value:val,fieldId:fieldId,pos:pos+posP})}}else{obj.push({value:val,pos:pos+posP})}}}return obj}};var res=extract_str(strP);return res};func.expression.parse_bad=function(input){if(typeof input!=="string")return[];const segments=[];let pos=0;const parts=input.split(/(@\w+)/).filter(Boolean);for(const part of parts){if(part.startsWith("@")){const fieldId=part.slice(1);segments.push({value:part,fieldId:fieldId,pos:pos})}else{segments.push({value:part,pos:pos})}pos+=part.length}return segments};func.expression.get_property=async function(valP){async function secure_eval(val){if(typeof IS_PROCESS_SERVER==="undefined"){try{return eval(val)}catch(err){console.error(err);return}}try{let vm=new VM.VM({sandbox:{func:func,SESSION_ID:SESSION_ID,SESSION_OBJ:{[`${SESSION_ID}`]:SESSION_OBJ[SESSION_ID]}},timeout:1e3,allowAsync:false});return await vm.run(val)}catch(err){throw""}}var property1,property2;if(valP.indexOf("[")>-1&&valP.indexOf("]")>-1){property1=valP.substr(valP.indexOf("[")+1,valP.indexOf("]")-valP.indexOf("[")-1);property1=await secure_eval(property1)}if(valP.indexOf(".")>-1)property2=valP.substr(valP.indexOf(".")+1,valP.length);return{property1:property1,property2:property2}};func.expression.get_property_bad=async function(valP){if(typeof valP!=="string")return{property1:undefined,property2:undefined};const secureEval=async expr=>{if(typeof IS_PROCESS_SERVER==="undefined"){try{return eval(expr)}catch(err){console.error(err);return undefined}}try{const vm=new VM.VM({sandbox:{func:func,SESSION_ID:SESSION_ID,SESSION_OBJ:{[SESSION_ID]:SESSION_OBJ[SESSION_ID]}},timeout:1e3,allowAsync:false});return await vm.run(expr)}catch{return undefined}};let property1,property2;const bracketStart=valP.indexOf("[");const bracketEnd=valP.indexOf("]");if(bracketStart>-1&&bracketEnd>bracketStart){const expr=valP.slice(bracketStart+1,bracketEnd);property1=await secureEval(expr)}const dotIndex=valP.indexOf(".");if(dotIndex>-1){property2=valP.slice(dotIndex+1)}return{property1:property1,property2:property2}};func.expression.validate_constant=function(valP){var patt=/["']/;if(typeof valP==="string"&&patt.test(valP.substr(0,1))&&patt.test(valP.substr(0,valP.length-1)))return true;else return false};func.expression.validate_variables=function(valP){if(typeof valP==="string"&&valP.indexOf("@")>-1)return true;else return false};func.expression.remove_quotes=function(valP){if(func.expression.validate_constant(valP))return valP.substr(1,valP.length-2);else return valP};func.expression.validate_constant_bad=valP=>typeof valP==="string"&&/^["'].*["']$/.test(valP);func.expression.validate_variables_bad=valP=>typeof valP==="string"&&valP.includes("@");func.expression.remove_quotes_bad=valP=>func.expression.validate_constant(valP)&&typeof valP==="string"?valP.slice(1,-1):valP;func.expression.secure_eval=async function(SESSION_ID,sourceP,val,job_id,dsSessionP,js_script_callback,evt){const api_utils=await func.common.get_module(SESSION_ID,"xuda-api-library.mjs",{func:func,glb:glb,SESSION_OBJ:SESSION_OBJ,SESSION_ID:SESSION_ID,APP_OBJ:APP_OBJ,dsSession:dsSessionP,job_id:job_id});const xu=api_utils;if(typeof IS_PROCESS_SERVER==="undefined"&&typeof IS_DOCKER==="undefined"){try{return eval(val)}catch(err){try{return JSON5.parse(val)}catch(err){return val}}}if(sourceP==="javascript"){process.on("uncaughtException",err=>{console.error("Asynchronous error caught.",err);func.events.delete_job(SESSION_ID,job_id);if(typeof IS_PROCESS_SERVER!=="undefined"||typeof IS_DOCKER!=="undefined"){if(SESSION_OBJ[SESSION_ID].crawler)return;return __.rpi.write_log(SESSION_OBJ[SESSION_ID].app_id,"error","worker","vm error",err,null,val,"func.expression.get.secure_eval")}});try{const dir=path.join(_conf.studio_drive_path,SESSION_OBJ[SESSION_ID].app_id,"node_modules","/");const script=new VM.VMScript(`try{${val}}catch(e){func.api.error(SESSION_ID, "nodejs error", e); console.error(e); func.events.delete_job(SESSION_ID, job_id);}`,{filename:dir,dirname:dir});let vm=new VM.NodeVM({require:{external:true},sandbox:{func:func,xu:xu,SESSION_ID:SESSION_ID,SESSION_OBJ:{[`${SESSION_ID}`]:SESSION_OBJ[SESSION_ID]},callback:js_script_callback,job_id:job_id,axios:axios,got:got,FormData:FormData},timeout:6e4});return await vm.run(script,{filename:dir,dirname:dir})}catch(err){console.error("Failed to execute script.",err);if(typeof IS_PROCESS_SERVER!=="undefined"){func.events.delete_job(SESSION_ID,jobNo);return __.db.add_error_log(SESSION_OBJ[SESSION_ID].app_id,"api",err)}}}else{try{try{let vm=new VM.VM({sandbox:{xu:xu,func:func,SESSION_ID:SESSION_ID,SESSION_OBJ:{[`${SESSION_ID}`]:SESSION_OBJ[SESSION_ID]},callback:js_script_callback,job_id:job_id},timeout:1e3,allowAsync:false});let ret=val;if(typeof val==="string"){ret=await vm.run(val)}return ret}catch(err){throw""}}catch(err){try{return JSON5.parse(val)}catch(err){return val}}}};func.expression.secure_eval_bad=async function(SESSION_ID,sourceP,val,job_id,dsSessionP,js_script_callback,evt){if(typeof val!=="string")return val;const xu=await func.common.get_module(SESSION_ID,"xuda-api-library.mjs",{func:func,glb:glb,SESSION_OBJ:SESSION_OBJ,SESSION_ID:SESSION_ID,APP_OBJ:APP_OBJ,dsSession:dsSessionP,job_id:job_id});const isServer=typeof IS_PROCESS_SERVER!=="undefined"||typeof IS_DOCKER!=="undefined";if(!isServer){try{return eval(val)}catch{try{return JSON5.parse(val)}catch{return val}}}const sandbox={func:func,xu:xu,SESSION_ID:SESSION_ID,SESSION_OBJ:{[SESSION_ID]:SESSION_OBJ[SESSION_ID]},callback:js_script_callback,job_id:job_id,...sourceP==="javascript"?{axios:axios,got:got,FormData:FormData}:{}};const handleError=err=>{console.error("Execution error:",err);func.events.delete_job(SESSION_ID,job_id);if(isServer&&!SESSION_OBJ[SESSION_ID].crawler){if(sourceP==="javascript"){__.rpi.write_log(SESSION_OBJ[SESSION_ID].app_id,"error","worker","vm error",err,null,val,"func.expression.get.secure_eval")}else{__.db.add_error_log(SESSION_OBJ[SESSION_ID].app_id,"api",err)}}return val};if(sourceP==="javascript"){process.on("uncaughtException",handleError);try{const dir=path.join(_conf.studio_drive_path,SESSION_OBJ[SESSION_ID].app_id,"node_modules");const script=new VM.VMScript(`try { ${val} } catch (e) { func.api.error(SESSION_ID, "nodejs error", e); console.error(e); func.events.delete_job(SESSION_ID, "${job_id}"); }`,{filename:dir,dirname:dir});const vm=new VM.NodeVM({require:{external:true},sandbox:sandbox,timeout:6e4});return await vm.run(script,{filename:dir,dirname:dir})}catch(err){return handleError(err)}}try{const vm=new VM.VM({sandbox:sandbox,timeout:1e3,allowAsync:false});return await vm.run(val)}catch{try{return JSON5.parse(val)}catch{return val}}};func.UI.main={};func.UI.main.clear_SYNC_INTERVAL=function(){$("body").unbind("mousemove keypress mousedown")};func.UI.main.embed_prog_execute=async function(SESSION_ID,prog){var _session=SESSION_OBJ[SESSION_ID];const _prog=await func.utils.VIEWS_OBJ.get(SESSION_ID,prog);const get_params_obj=function(){var params_obj={};if(_prog?.properties?.progParams){for(const[key,val]of Object.entries(_prog.properties.progParams)){if(!val.data.dir==="in")continue;if(typeof _session.url_params?.[val.data.parameter]!=="undefined"){params_obj[val.data.parameter]=_session.url_params?.[val.data.parameter];continue}console.warn(`Warning: Program ${_prog.properties.menuName} expected In parameter: ${val.data.parameter} but received null instead`)}}return params_obj};let screen_ret=await func.utils.get_screen_obj(SESSION_ID,prog);if(screen_ret){let ret_init=await func.UI.screen.init(SESSION_ID,prog,null,null,$("#embed_"+SESSION_ID),null,null,null,null,get_params_obj(),"call_embed");document.title=screen_ret.properties.menuTitle;return}console.error("Program not exist",prog);func.UI.utils.progressScreen.show(SESSION_ID,"Program not exist",null,true)};func.UI.main.embed_loader=async function(SESSION_ID){var _session=SESSION_OBJ[SESSION_ID];var hash="";if(window.location.hash)hash=window.location.hash.substr(1);_session.SYS_GLOBAL_STR_BROWSER_HASH_ID=hash;_session.SYS_GLOBAL_STR_BROWSER_TITLE=document.title;const init_system_ds=async function(){if(!["main"].includes(_session.opt.app_computing_mode)){await func.index.new_webworker(SESSION_ID,{menuName:"Main"})}const ret=await func.datasource.create(SESSION_ID,"system");return ret};const set_SYS_GLOBAL_KEYS_STATE=async function(SESSION_ID,e,state){if(!_session?.DS_GLB?.[0])return;if(e.keyCode!==16&&e.keyCode!==17&&e.keyCode!==18&&e.keyCode!==91){return}var data={};if(e.keyCode===17){data.SYS_GLOBAL_BOL_CONTROL_KEY_STATE=state}if(e.keyCode===16){data.SYS_GLOBAL_BOL_SHIFT_KEY_STATE=state}if(e.keyCode===18){data.SYS_GLOBAL_BOL_ALT_KEY_STATE=state}if(e.keyCode===91){data.SYS_GLOBAL_BOL_COMMAND_KEY_STATE=state}var datasource_changes={[0]:{["data_system"]:data}};await func.datasource.update(SESSION_ID,datasource_changes)};const start_workers=async function(){_session.WORKER_OBJ.fx=new func.utils.job_worker(SESSION_ID);_session.WORKER_OBJ.fx.init()};const create_embed_container=async function(){$("<div>").attr("id","embed_"+SESSION_ID).addClass("xu_embed_div").data({xuData:{}}).appendTo($(_session.root_element))};const execute_PENDING_OPEN_URL_EVENTS=async function(){if(typeof func.events.execute_PENDING_OPEN_URL_EVENTS!=="undefined"&&glb.is_cordova){func.events.execute_PENDING_OPEN_URL_EVENTS()}};const remove_loader=async function(){$(".loader").remove();$(_session.root_element).removeClass("loader_background_color")};const perform_callback=async function(){if(_session.api_callback){_session.api_callback("xuda_ready",SESSION_ID,SESSION_OBJ)}};const call_program=async function(){if(_session.route_id){const route_obj=await func.utils.DOCS_OBJ.get(SESSION_ID,_session.route_id);function flattenMenuItems(menu){let flatMenu={};function recurse(items){for(let item of items){flatMenu[item.id]=item;if(item.children&&item.children.length>0){recurse(item.children)}}}recurse(menu);return flatMenu}const flatMenu=flattenMenuItems(route_obj.routeMenu.menu);const menu_obj=flatMenu[_session.menu_id];if(_session.menu_id){if(menu_obj){_session.prog_id=menu_obj.prog_id;if(menu_obj.prog_params){_session.url_params={..._session.url_params,...menu_obj.prog_params}}if(menu_obj.global_params){_session.url_params={..._session.url_params,...menu_obj.global_params}}}}}if(!_session.prog_id)return;await func.utils.TREE_OBJ.get(SESSION_ID,_session.prog_id);let screen_ret=await func.utils.get_screen_obj(SESSION_ID,_session.prog_id);if(screen_ret){func.UI.main.embed_prog_execute(SESSION_ID,_session.prog_id)}else{console.error("Program not exist",_session.prog_id);func.UI.utils.progressScreen.show(SESSION_ID,"Program not exist",null,true)}};const register_run_background_plugins=async function(){if(typeof glb.SLIM_BUNDLE!=="undefined"||glb.SLIM_BUNDLE)return;for await(const[plugin_name,val]of Object.entries(APP_OBJ[_session.app_id].app_plugins_purchased)){if(val.installed&&val.run_in_background&&val.manifest?.["runtime.mjs"]?.exist){try{const plugin_runtime_src=await func.utils.get_plugin_npm_cdn(SESSION_ID,plugin_name,`${val.manifest["runtime.mjs"].dist?"dist/":""}runtime.mjs`);if(val.manifest["runtime.mjs"].dist&&val.manifest?.["runtime.mjs"]?.css){const plugin_runtime_css_url=await func.utils.get_plugin_npm_cdn(SESSION_ID,plugin_name,"dist/runtime.css");func.utils.load_css_on_demand(plugin_runtime_css_url)}const plugin_script=await import(plugin_runtime_src);eval(plugin_script);let plugin_setup_script_ret=null;if(val.manifest?.["index.mjs"]?.exist){const plugin_setup_src=await func.utils.get_plugin_npm_cdn(SESSION_ID,plugin_name,`${val.manifest["index.mjs"].dist?"dist/":""}index.mjs`);let plugin_setup_script=await import(plugin_setup_src);if(plugin_setup_script){plugin_setup_script_ret=await func.utils.get_plugin_setup(SESSION_ID,plugin_name);if(plugin_setup_script_ret.code<0){throw plugin_setup_script_ret}}}glb.lifecycle.plugins[plugin_name]={plugin_script:plugin_script,setup_data:plugin_setup_script_ret?.data}}catch(err){console.error(err)}}}};async function updateOnlineStatus(){if(!_session?.DS_GLB?.[0])return;var data={};if(navigator.onLine){data.SYS_GLOBAL_BOL_ONLINE=1}else{data.SYS_GLOBAL_BOL_ONLINE=0}var datasource_changes={[0]:{["data_system"]:data}};await func.datasource.update(SESSION_ID,datasource_changes)}await register_run_background_plugins();$(_session.root_element).show();func.UI.component.create_app_root_component(SESSION_ID);await glb.lifecycle.execute(SESSION_ID,"beforeInit");await start_workers();await init_system_ds();await glb.lifecycle.execute(SESSION_ID,"initialized");await create_embed_container();await execute_PENDING_OPEN_URL_EVENTS();await remove_loader();await func.UI.worker.init(SESSION_ID);await glb.lifecycle.execute(SESSION_ID,"beforeMounted");await call_program();await glb.lifecycle.execute(SESSION_ID,"mounted");await perform_callback();func.utils.debug.write(SESSION_ID,"Xuda.io started.");await glb.lifecycle.execute(SESSION_ID,"systemReady");$(document).keydown(function(e){set_SYS_GLOBAL_KEYS_STATE(SESSION_ID,e,1)});$(document).keyup(function(e){set_SYS_GLOBAL_KEYS_STATE(SESSION_ID,e,0)});await updateOnlineStatus();window.addEventListener("online",updateOnlineStatus);window.addEventListener("offline",updateOnlineStatus);console.log("xuda.io system ready.");$("body")[0].dispatchEvent(glb.system_ready_event)};func.UI.main.set_custom_css=function(SESSION_ID,callbackP){if(SESSION_OBJ[SESSION_ID].DS_GLB[0].data_system?.["SYS_GLOBAL_STR_SITE_CSS"])$("<style type='text/css'> "+SESSION_OBJ[SESSION_ID].DS_GLB[0].data_system["SYS_GLOBAL_STR_SITE_CSS"]+" </style>").appendTo("head");callbackP()};func.index={};$(document).ready(function(){func.index.init_document_listeners();func.UI.utils.indicator.worker.normal();func.index.init_service_workers()});function xuda(...args){let element=null;let opt={};let callback=null;for(const arg of args){if(arg instanceof HTMLElement){element=arg}else if(typeof arg==="object"&&arg!==null&&!Array.isArray(arg)){opt=arg}else if(typeof arg==="function"){callback=arg}}if(!element){if(typeof glb.SLIM_BUNDLE==="undefined"||!glb.SLIM_BUNDLE){return console.error("Xuda Error - element argument is empty")}element="body";console.warn("root element set to body")}if(!$(element).length){return console.error("Xuda Error - element not found")}if(typeof opt==="undefined"){return console.error("Xuda Error - opt argument is undefined")}if(typeof opt!=="object"){return console.error("Xuda Error - opt argument is not an object")}glb.URL_PARAMS=func.common.getJsonFromUrl(window.location.href);glb.worker_type="Worker";if(opt.debug_js){glb.debug_js=true;if((location.host.includes("localhost")||location.host.includes("127.0.0.1"))&&typeof glb.SLIM_BUNDLE==="undefined"&&typeof glb.CODE_BUNDLE==="undefined"){glb.worker_type="Dev"}else{glb.worker_type="Debug"}}const call_xuda=async function(){const _instance_id=Date.now().toString()+Math.round(Math.random()*1e4).toString();const _api_callback=callback;const create_index_html=function(){const{root_element,domain}=_session;$(root_element).css("position","relative");$(root_element).append(`
5
+ })(document.querySelector(\`[xu-ui-id=${elementP}]\`),evt)`,true,null,null,evt);await func.datasource.set_outputField(SESSION_ID,dsSessionP,result,args);return result},loader_on:async function(){glb.CURRENT_APP_LOADING=null;LOADER_ACTIVE=true;LOADER_TEXT=descP;func.events.delete_job(SESSION_ID,jobNoP)},loader_off:async function(){LOADER_ACTIVE=false;func.events.delete_job(SESSION_ID,jobNoP)},emit_event:async function(){if(refIdP.value){$(document).trigger(refIdP.value,[_session.DS_GLB[dsSession]])}else{func.utils.debug_report(SESSION_ID,"func.events.execute","Event name missing","E")}func.events.delete_job(SESSION_ID,jobNoP)},invoke_action:async function(){func.utils.debug.watch(SESSION_ID,calling_trigger_prop?.id,functionP,null,null,expCond);await func.action.execute(SESSION_ID,refIdP.value,_ds,null,null,jobNoP,containerP)},raise_event:async function(){var _ds=_session.DS_GLB[dsSession];const _view_obj=await func.utils.VIEWS_OBJ.get(SESSION_ID,_ds.prog_id);if(callingSourceP==="grid"||callingSourceP==="form"){let _field_obj=func.common.find_item_by_key(_view_obj.progFields,"field_id",field_elm);var event_name=_field_obj?.triggers?.[eventIdP].name.event;if(_field_obj?.triggers?.[eventIdP].name?.properties["xu-exp:event"]){event_name=(await func.expression.get(SESSION_ID,props[`xu-exp:event`],dsSession,"event_name expression")).result}if(field_elm&&event_name){const dsP=await func.datasource.find_event_dataSource(SESSION_ID,event_name,dsSession);return await func.datasource.run_events_functions(SESSION_ID,dsP,event_name,jobNoP,null,calling_trigger_prop?.data?.name?.parameters||{})}}if(callingSourceP.includes("event")){let event_name=refIdP.event;if(refIdP?.properties?.["xu-exp:event"]){event_name=(await func.expression.get(SESSION_ID,refIdP.properties["xu-exp:event"],dsSession,"event_name expression")).result}const dsP=await func.datasource.find_event_dataSource(SESSION_ID,event_name,dsSession);await func.datasource.run_events_functions(SESSION_ID,dsP,event_name,jobNoP,calling_trigger_prop?.props?.async,calling_trigger_prop?.data?.name?.parameters||{})}func.events.delete_job(SESSION_ID,jobNoP);func.utils.debug.watch(SESSION_ID,calling_trigger_prop?.id,functionP,"","",expCond)},get_data:async function(){const params_obj=await get_params_obj();if(!await get_prog_id()){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} > ${triggerP} > ${functionP} > program ${prog} is missing`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}var _ds=_session.DS_GLB[dsSession];if(!_ds){func.events.delete_job(SESSION_ID,jobNoP);return}if(_ds){func.utils.debug.watch(SESSION_ID,calling_trigger_prop?.id,functionP,null,calling_trigger_prop,expCond);const ret=await func.datasource.create(SESSION_ID,await get_prog_id(),args.dataSourceNoP,args.parentDataSourceNoP,args.containerIdP,args.rowIdP,args.jobNoP,args.calling_trigger_prop,null,null,args.callingSourceP,args.calling_jobP,args.screen_dsP,args.is_panelP,params_obj);let _ds_new=_session.DS_GLB[ret.dsSessionP];let parameters=args?.calling_trigger_prop?.data?.name?.parameters;if(parameters&&!_.isEmpty(parameters)){await func.datasource.update_changes_for_out_parameter(SESSION_ID,_ds_new.dsSession,_ds.dsSession)}func.events.delete_job(SESSION_ID,jobNoP);return _ds_new}},set_data:async function(){return this.get_data()},batch:async function(){const result=await this.get_data();return result},update:async function(){const obj_values_to_update=func.datasource.get_viewFields_for_update_function(SESSION_ID,calling_trigger_prop,null,dsSessionP);if(!obj_values_to_update||_.isEmpty(obj_values_to_update)){func.utils.debug_report(SESSION_ID,"Update values object is empty","","W");if(jobNoP)func.events.delete_job(SESSION_ID,jobNoP);return}var updates=[];for await(const[key,val]of Object.entries(obj_values_to_update)){var $element;if(elementP){$element=$(`[xu-ui-id="${elementP}"]`).clone(true)}let ret_field_id=await func.expression.get(SESSION_ID,val.id.trim(),dsSessionP,"update",null,null,null,null,null,null,$element?.length?$element?.data()?.xuData?.iterate_info:null);let ret_value=await func.expression.get(SESSION_ID,val.val.trim(),dsSessionP,"update",null,null,null,null,null,null,$element?.length?$element?.data()?.xuData?.iterate_info:null);let _field_id=ret_field_id.result;let _value=ret_value.result;updates.push({_field_id:_field_id,_value:_value})}let datasource_changes={};for await(const change of updates){let ret_get_value=await func.datasource.get_value(SESSION_ID,change._field_id,dsSessionP);if(ret_get_value.found){let _ds=_session.DS_GLB[ret_get_value.dsSessionP];if(!datasource_changes[_ds.dsSession]){datasource_changes[_ds.dsSession]={}}if(!datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]){datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]={}}datasource_changes[_ds.dsSession][ret_get_value.currentRecordId][change._field_id]=change._value}}await func.datasource.update(SESSION_ID,datasource_changes);if(jobNoP)func.events.delete_job(SESSION_ID,jobNoP)},call_alert:async function(){await func.utils.alerts.invoke(SESSION_ID,"call_alert",refIdP,log_source,dsSession);func.events.delete_job(SESSION_ID,jobNoP)},alert:async function(){await func.utils.alerts.invoke(SESSION_ID,"alert",refIdP,log_source,dsSession);func.events.delete_job(SESSION_ID,jobNoP)},delay:async function(){return new Promise(resolve=>{setTimeout(function(){if(jobNoP)func.events.delete_job(SESSION_ID,jobNoP);resolve()},refIdP.value)})},comment:async function(){if(jobNoP)func.events.delete_job(SESSION_ID,jobNoP)},call_project_api:async function(){const params_obj=await get_params_obj();const _prog_id=await get_prog_id();if(!_prog_id){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} > ${triggerP} > ${functionP} > program not defined`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}const api_ret=await func.api.call_project_api(_prog_id,params_obj);await func.datasource.set_outputField(SESSION_ID,dsSessionP,api_ret,args);func.events.delete_job(SESSION_ID,jobNoP)},call_system_api:async function(){const api_method=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"api_method");if(!api_method){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} >${triggerP} >${functionP} > api_method not defined`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}let payload={};const _payload=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"payload");if(_payload){const get_payload_property_value=async function(prop_name){let _prop=_payload;let _value=_prop[prop_name];if(_prop?.[`xu-exp:${prop_name}`]){_value=(await func.expression.get(SESSION_ID,_prop[`xu-exp:${prop_name}`],dsSession,`${prop_name} expression`)).result}return _value};for await(let[key,val]of Object.entries(_payload)){const new_key=key.replaceAll("xu-exp:","");payload[new_key]=await get_payload_property_value(new_key)}}const output_field=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"outputField");const api_ret=await func.api.call_system_api(api_method,payload);if(output_field){let datasource_changes={};let ret_get_value=await func.datasource.get_value(SESSION_ID,output_field,dsSessionP);if(ret_get_value.found){let _ds=_session.DS_GLB[ret_get_value.dsSessionP];if(!datasource_changes[_ds.dsSession]){datasource_changes[_ds.dsSession]={}}if(!datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]){datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]={}}datasource_changes[_ds.dsSession][ret_get_value.currentRecordId][output_field]=api_ret;await func.datasource.update(SESSION_ID,datasource_changes)}}func.events.delete_job(SESSION_ID,jobNoP)},call_external_api:async function(){const method=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"method");if(!method){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} >${triggerP} >${functionP} > method not defined`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}const url=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"url");if(!url){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} >${triggerP} >${functionP} > url not defined`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}const payload_arr=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"payload");const report_conversion_error=function(res,typeP,valP){var msg=`${elementP} >${triggerP} >${functionP} > error converting from ${valP} to ${typeP}`;if(error){return func.utils.debug_report(SESSION_ID,msg,"","W")}func.utils.debug_report(SESSION_ID,msg+" "+_.capitalize(source)+prog_info,"","E")};const report_conversion_warn=function(res){var msg=`${elementP} >${triggerP} >${functionP} > type mismatch auto conversion from value ${valP} to ${typeP}`;func.utils.debug_report(SESSION_ID,msg+" "+_.capitalize(source)+prog_info,"","W")};if(error){return report_conversion_error()}const module=await func.common.get_module(SESSION_ID,"xuda-get-cast-util-module.mjs");var payload=_.reduce(payload_arr,(ret,val,key)=>{ret[val.key]=module.cast(val.type,val.val,report_conversion_error,report_conversion_warn);return ret},{});const output_field=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"outputField");const api_ret=await func.api.call_external_api(method,url,payload);if(output_field){let datasource_changes={};let ret_get_value=await func.datasource.get_value(SESSION_ID,output_field,dsSessionP);if(ret_get_value.found){let _ds=_session.DS_GLB[ret_get_value.dsSessionP];if(!datasource_changes[_ds.dsSession]){datasource_changes[_ds.dsSession]={}}if(!datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]){datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]={}}datasource_changes[_ds.dsSession][ret_get_value.currentRecordId][output_field]=api_ret;await func.datasource.update(SESSION_ID,datasource_changes)}}func.events.delete_job(SESSION_ID,jobNoP)}};return await fx[functionP]()};func.events.delete_job=function(SESSION_ID,jobNoP){var _session=SESSION_OBJ[SESSION_ID];var job_index=func.events.find_job_index(SESSION_ID,jobNoP);if(!_session.WORKER_OBJ.jobs[job_index]){_session.WORKER_OBJ.stat=null;return}var dsSession=_session.WORKER_OBJ.jobs[job_index].dsSessionP;let ds_obj=_session?.DS_GLB[dsSession];if(ds_obj){delete SCREEN_BLOCKER_OBJ[ds_obj.screenId+(ds_obj.callingScreenId?"_"+ds_obj.callingScreenId:"")]}if(dsSession&&ds_obj?.loops_limit&&ds_obj?.loops_count<ds_obj?.loops_limit-1){return}_session.WORKER_OBJ.stat=null;_session.WORKER_OBJ.jobs.splice(job_index,1)};func.events.delete_job_0=function(SESSION_ID){var job_index=0;var _session=SESSION_OBJ[SESSION_ID];if(!_session.WORKER_OBJ.jobs[job_index]){_session.WORKER_OBJ.stat=null;return}var dsSession=_session.WORKER_OBJ.jobs[job_index].dsSession;let ds_obj=_session?.DS_GLB[dsSession];if(ds_obj){delete SCREEN_BLOCKER_OBJ[ds_obj.screenId+(ds_obj.callingScreenId?"_"+ds_obj.callingScreenId:"")]}if(dsSession&&ds_obj&&ds_obj.loops_limit&&ds_obj.loops_count<ds_obj.loops_limit-1){return}_session.WORKER_OBJ.stat=null;_session.WORKER_OBJ.jobs.splice(job_index,1)};func.events.check_jobs_idle=async function(SESSION_ID,jobsP){return new Promise((resolve,reject)=>{var _session=SESSION_OBJ[SESSION_ID];if(!jobsP||jobsP&&jobsP.length===0){resolve();return}var listener=setInterval(function(){var found;for(const[key,val]of Object.entries(jobsP)){_.forEach(_session.WORKER_OBJ.jobs,function(val2,key2){if(key2===val){found=true;return false}})}if(!found){do_callback();return}},100);var do_callback=function(){window.clearInterval(listener);resolve()}})};var loop_detected_obj={};setInterval(function(){loop_detected_obj={}},1e3);func.events.set_browser_changes=function(dsP,fieldsChangedP){if(fieldsChangedP.includes("SYS_GLOBAL_STR_BROWSER_TITLE"))document.title=dsP.dataset_new["SYS_GLOBAL_STR_BROWSER_TITLE"]};func.events.execute_PENDING_OPEN_URL_EVENTS=async function(){for(let[key,url]of Object.entries(PENDING_OPEN_URL_EVENTS)){if(url){glb.WINDOW_LOCATION_SEARCH=url;glb.ROOT_ELEMENT_ATTRIBUTES=func.UI.utils.get_root_element_attributes();const params_obj=func.common.getObjectFromUrl(url,glb.ROOT_ELEMENT_ATTRIBUTES);if(!params_obj.prog){return console.warn("prog empty")}await func.utils.TREE_OBJ.get(SESSION_ID,params_obj.prog);let screen_ret=await func.utils.get_screen_obj(SESSION_ID,params_obj.prog);if(screen_ret){await func.UI.screen.init(SESSION_ID,params_obj.prog,null,null,$("#embed_"+SESSION_ID),null,null,null,null,null,"pendingUrlEvent_embed")}else{console.error("Program not exist",params_obj.prog_id);func.UI.utils.progressScreen.show(SESSION_ID,"Program not exist",null,true)}}else{console.warn("url empty")}}};func.events.invoke=async function(event_id){var _session=SESSION_OBJ[SESSION_ID];if(!event_id){console.warn("event_id Cannot be empty");return false}var ds;for await(const[ds_key,val]of Object.entries(_session.DS_GLB)){const _view_obj=await func.utils.VIEWS_OBJ.get(SESSION_ID,val.prog_id);if(_.isEmpty(_view_obj.progEvents))continue;if(ds)break;for await(const[key,val]of Object.entries(_view_obj.progEvents)){if(val?.data?.type==="user_defined"&&val.data.event_name===event_id){ds=ds_key;break}}}if(!ds){console.warn("event_id not found");return false}func.events.validate(SESSION_ID,"user_defined",ds,event_id)};func.expression={};func.expression.get=async function(SESSION_ID,valP,dsSessionP,sourceP,rowIdP,sourceActionP,secondPassP,calling_fieldIdP,fieldsP,debug_infoP,iterate_info,js_script_callback,jobNo,api_output_type){class xu_class{async get(){var ret;var fields={};var error;var warning;function evalJson(text){return eval("("+text+")")}if(valP===null){ret=""}else{switch(typeof valP){case"string":ret=valP;break;case"undefined":ret="";break;case"boolean":ret=valP?"Y":"N";break;default:ret=valP.toString();break}}ret=ret.replace(/\&amp;/g,"&");ret=func.utils.replace_studio_drive_url(SESSION_ID,ret);const end_results=function(){const replace_quotes=function(ret){for(const[key,val]of Object.entries(fields)){if(typeof val==="string")ret=ret.replace('"'+val+'"',val.replace(/"/gi,""))}return ret};if(["update","javascript"].includes(sourceP)){if(typeof ret==="string")ret=replace_quotes(ret)}const log_error=function(){if(SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP]){func.utils.debug.log(SESSION_ID,SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP].nodeId,{module:"expression",action:sourceP,source:calling_fieldIdP,prop:ret,details:ret,result:ret,error:error,warning:warning,fields:null,type:"exp",prog_id:SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP].prog_id,debug_info:debug_infoP})}};if(error)log_error();return{result:ret,fields:fields,res:res,explain:result,error:error,warning:warning,req:valP,var_error_found:var_error_found}};const variable_not_exist=async function(){try{if(sourceP!=="arguments"){if(ret&&ret.substr(0,6)==="_DATE_"){ret=ret.substr(6)}else if(ret&&ret.length===10&&ret.substr(4,1)==="-"&&ret.substr(7,1)==="-"||ret==="self"){ret=ret}else{ret=await func.expression.secure_eval(SESSION_ID,sourceP,ret,jobNo,dsSessionP,js_script_callback)}return end_results()}else{ret=ret.replace(/_NULL/gi,"");return end_results()}}catch(err){return end_results()}};if(!func.expression.validate_variables(valP)){return await variable_not_exist()}const validate_email=async function(){const ret=await func.expression.secure_eval(SESSION_ID,sourceP,valP,jobNo,dsSessionP,js_script_callback);return glb.emailRegex.test(ret)};if(await validate_email()){return await variable_not_exist()}var var_Arr=[];const split=func.expression.parse(ret)||[];for await(const[arr_key,val]of Object.entries(split)){const key=Number(arr_key);var_Arr[key]={};var_Arr[key].value=val.value;const replace_value_in_string=async function(retP,fieldIdP){if(iterate_info?.iterator_key===fieldIdP||iterate_info?.iterator_val===fieldIdP){if(iterate_info.iterator_key===fieldIdP){retP.value=iterate_info._key}if(iterate_info.iterator_val===fieldIdP){retP.value=iterate_info._val}}const set_value=function(valP){if(typeof valP!=="undefined"){var_Arr[key].value=valP;if(typeof valP==="string")var_Arr[key].type="string"}else{if(retP.type==="object"){var_Arr[key].value="";var_Arr[key].type="string"}}};if(sourceP==="exp"&&retP.type!=="exp"){var_Arr[key].type=retP.type;return}if(typeof retP.value!=="undefined"){var_Arr[key].type=retP.type;var_Arr[key].value=retP.value;if(val.value.indexOf("[")>-1|val.value.indexOf(".")>-1){var data=retP.prop;if(retP.type==="object")data=retP.value;var property1,property2;if(val.value.indexOf("[")===-1&&val.value.indexOf("]")>-1&&val.value.substr(0,1)==="@"){var prevData=var_Arr[key-1].value;var_Arr[key].value=prevData[data];if(val.value.indexOf(".")>-1){property2=await func.expression.get_property(val.value).property2;if(prevData[data])set_value(prevData[data][property2])}delete var_Arr[key-1]}else{property1=await func.expression.get_property(val.value).property1;property2=await func.expression.get_property(val.value).property2;if(property1){var_Arr[key].value=data[property1];if(property2){if(data[property1])set_value(data[property1][property2])}}if(property2&&!property1){if(data){set_value(data[property2])}}}fields[fieldIdP]=var_Arr[key].value;var_Arr[key].fieldId=fieldIdP}else{fields[fieldIdP]=var_Arr[key].value;var_Arr[key].fieldId=fieldIdP}}};if(val.fieldId){if(val.fieldId&&val.fieldId.substr(0,5)==="_THIS"&&calling_fieldIdP&&(val.fieldId.length===5||val.fieldId.length>5&&val.fieldId.substr(5,1)===".")){if(val.fieldId.length===5)val.fieldId=calling_fieldIdP;else val.fieldId=calling_fieldIdP+val.fieldId(5,val.fieldId.length-1)}if(!sourceP==="exp"){var_Arr[key].value='""'}fields[val.fieldId]=var_Arr[key].value;const ret=await func.datasource.get_value(SESSION_ID,val.fieldId,dsSessionP,rowIdP);await replace_value_in_string(ret.ret,ret.fieldIdP)}}try{var res=[];var exp_exist;var var_error_found;_.forEach(var_Arr,function(val,key){if(sourceP==="UI Property EXP"){let ret=func.utils.get_drive_url(SESSION_ID,val.value,true);if(ret.changed){res[key]=ret.value;return true}}if(sourceP==="UI Attr EXP"){let ret=func.utils.get_drive_url(SESSION_ID,val.value,var_Arr.length==1?false:true);if(ret.changed){res[key]=ret.value;return true}}if(val.type==="exp"){exp_exist=true}res[key]=val.value;if(var_Arr.length>1){if(!["DbQuery","alert","exp","api_rendered_output"].includes(sourceP)&&["string","date"].includes(val.type)){res[key]="`"+val.value+"`"}if(["api_rendered_output"].includes(sourceP)&&["json"].includes(api_output_type)&&["string","date"].includes(val.type)){res[key]=`"`+val.value+`"`}}if(val.fieldId&&val.value&&typeof val.value==="string"){if(["query","condition","range","sort","locate"].includes(sourceP)){if(val.value.indexOf("↵")>-1){res[key]=val.value.split("↵").join("")}res[key]=res[key].replace(/(\r\n|\n|\r)/gm,"")}if(["init","update","virtual"].includes(sourceP)){if(val.value.indexOf("↵")>-1)res[key]=val.value.split("↵").join("\n");res[key]=res[key].replace(/(\r\n|\n|\r)/gm,"\\n")}if(typeof IS_PROCESS_SERVER!=="undefined"){res[key]=res[key].replace(/(\r\n|\n|\r)/gm,"<br>")}fields[val.fieldId]=res[key]}if(typeof val.value==="object"&&var_Arr.length>1){if(!Array.isArray(val.value)&&!var_Arr[key+1].value?.includes(".")){res[key]="("+JSON.stringify(val.value)+")"}else{res[key]=JSON.stringify(val.value)}}if(!exp_exist&&sourceP!=="exp"&&val.value&&typeof val.value==="string"&&val.value.substr(0,1)==="@"){warning="Error encoding "+val.value;var_error_found=true;res[key]=0}});const join=function(arrP){return arrP.join("")};var exp=undefined;if(exp_exist&&sourceP!=="exp"){exp=await func.expression.get(SESSION_ID,join(res),dsSessionP,sourceP,rowIdP,sourceActionP,true,calling_fieldIdP,fields,debug_infoP);if(exp.res)res=exp.res;else res=[exp.result];fields=_.assignIn(exp.fields,fieldsP)}var result=join(res);if(res.length===1){result=res[0]}if(secondPassP){ret=result}else if(sourceP!=="exp"){if(res.length===1&&typeof res[0]==="string"&&typeof res[0]!=="object"){ret=join(res);if(ret&&ret.substr(0,1)==="@"){error="Error encoding @ var";var_error_found=true}}else{if(!["arguments","api_rendered_output","DbQuery"].includes(sourceP)){ret=await func.expression.secure_eval(SESSION_ID,sourceP,result,jobNo,dsSessionP,js_script_callback)}else{if(sourceP==="DbQuery"){ret=JSON.stringify(evalJson(result))}else{ret=result}}}}return end_results()}catch(err){ret=result;error=err.message;return end_results()}}}const new_class=new xu_class;return new_class.get()};func.expression.get_bad=async function(SESSION_ID,valP,dsSessionP,sourceP,rowIdP,sourceActionP,secondPassP,calling_fieldIdP,fieldsP={},debug_infoP,iterate_info,js_script_callback,jobNo,api_output_type){const evalJson=text=>eval(`(${text})`);const replaceQuotes=str=>{for(const[key,val]of Object.entries(fields)){if(typeof val==="string")str=str.replace(`"${val}"`,val.replace(/"/g,""))}return str};let ret,error,warning,var_error_found;const fields={...fieldsP};if(valP===null||typeof valP==="undefined")ret="";else if(typeof valP==="boolean")ret=valP?"Y":"N";else ret=valP.toString();ret=ret.replace(/\&/g,"&");ret=func.utils.replace_studio_drive_url(SESSION_ID,ret);const endResults=()=>{if(["update","javascript"].includes(sourceP)&&typeof ret==="string"){ret=replaceQuotes(ret)}if((error||warning)&&SESSION_OBJ[SESSION_ID]?.DS_GLB[dsSessionP]){func.utils.debug.log(SESSION_ID,SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP].nodeId,{module:"expression",action:sourceP,source:calling_fieldIdP,prop:ret,details:ret,result:ret,error:error,warning:warning,fields:null,type:"exp",prog_id:SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP].prog_id,debug_info:debug_infoP})}return{result:ret,fields:fields,error:error,warning:warning,req:valP,var_error_found:var_error_found}};const handleNonVariable=async()=>{try{if(sourceP!=="arguments"){if(ret.startsWith("_DATE_"))ret=ret.slice(6);else if(/^\d{4}-\d{2}-\d{2}$/.test(ret)||ret==="self")return endResults();else ret=await func.expression.secure_eval(SESSION_ID,sourceP,ret,jobNo,dsSessionP,js_script_callback)}else{ret=ret.replace(/_NULL/gi,"")}return endResults()}catch(err){error=err.message;return endResults()}};if(!func.expression.validate_variables(valP))return await handleNonVariable();if(glb.emailRegex.test(await func.expression.secure_eval(SESSION_ID,sourceP,valP,jobNo,dsSessionP,js_script_callback))){return await handleNonVariable()}const split=func.expression.parse(ret)||[];const var_Arr=await Promise.all(split.map(async(val,key)=>{const result={value:val.value,fieldId:val.fieldId};if(!val.fieldId)return result;if(val.fieldId.startsWith("_THIS")&&calling_fieldIdP){result.fieldId=val.fieldId.length===5?calling_fieldIdP:calling_fieldIdP+val.fieldId.slice(5)}const{ret:fetchedValue,fieldIdP}=await func.datasource.get_value(SESSION_ID,result.fieldId,dsSessionP,rowIdP);result.value=fetchedValue?.value??(sourceP==="exp"?fetchedValue?.value:'""');result.type=fetchedValue?.type;if(iterate_info){if(iterate_info.iterator_key===fieldIdP)result.value=iterate_info._key;if(iterate_info.iterator_val===fieldIdP)result.value=iterate_info._val}if(val.value.includes("[")||val.value.includes(".")){const{property1,property2}=await func.expression.get_property(val.value);const data=fetchedValue?.type==="object"?fetchedValue.value:fetchedValue?.prop;if(key>0&&val.value.includes("]")&&!val.value.includes("[")&&split[key-1].value){const prevData=split[key-1].value;result.value=prevData[fieldIdP];if(val.value.includes(".")&&prevData[fieldIdP]){result.value=prevData[fieldIdP][property2]??""}}else if(data){if(property1)result.value=data[property1]??"";if(property2)result.value=(property1?data[property1]?.[property2]:data[property2])??""}}fields[fieldIdP]=result.value;return result}));try{const res=var_Arr.map((val,key)=>{if(sourceP==="UI Property EXP"||sourceP==="UI Attr EXP"){const{changed,value}=func.utils.get_drive_url(SESSION_ID,val.value,sourceP==="UI Attr EXP"&&var_Arr.length>1);if(changed)return value}let value=val.value;if(var_Arr.length>1){if(!["DbQuery","alert","exp","api_rendered_output"].includes(sourceP)&&["string","date"].includes(val.type)){value=`\`${value}\``}else if(sourceP==="api_rendered_output"&&api_output_type==="json"&&["string","date"].includes(val.type)){value=`"${value}"`}}if(val.fieldId&&typeof value==="string"){if(["query","condition","range","sort","locate"].includes(sourceP))value=value.replace(/↵|\r\n|\n|\r/g,"");if(["init","update","virtual"].includes(sourceP))value=value.replace(/↵|\r\n|\n|\r/g,"\\n");if(typeof IS_PROCESS_SERVER!=="undefined")value=value.replace(/↵|\r\n|\n|\r/g,"<br>");fields[val.fieldId]=value}if(typeof value==="object"&&var_Arr.length>1){value=Array.isArray(value)||var_Arr[key+1]?.value?.includes(".")?JSON.stringify(value):`(${JSON.stringify(value)})`}if(!val.type==="exp"&&sourceP!=="exp"&&typeof value==="string"&&value.startsWith("@")){warning=`Error encoding ${value}`;var_error_found=true;return"0"}return value});ret=res.length===1?res[0]:res.join("");if(var_Arr.some(v=>v.type==="exp")&&sourceP!=="exp"&&!secondPassP){const exp=await func.expression.get(SESSION_ID,ret,dsSessionP,sourceP,rowIdP,sourceActionP,true,calling_fieldIdP,fields,debug_infoP);ret=exp.res?.[0]??exp.result;Object.assign(fields,exp.fields)}else if(!secondPassP&&!["arguments","api_rendered_output","DbQuery"].includes(sourceP)){ret=await func.expression.secure_eval(SESSION_ID,sourceP,ret,jobNo,dsSessionP,js_script_callback)}else if(sourceP==="DbQuery"){ret=JSON.stringify(evalJson(ret))}if(typeof ret==="string"&&ret.startsWith("@")){error="Error encoding @ var";var_error_found=true}}catch(err){error=err.message}return endResults()};func.expression.parse_org=function(strP){var extract_str=function(strP,posP){if(!posP)posP=0;var clean_split_str=function(arrP){var arr=[];if(arrP&&arrP.length>1&&arrP[0]===""&&arrP[1].indexOf("@")>-1){for(var i=1;i<=arrP.length;i++){arr.push(arrP[i])}return arr}else return arrP};var nonLettersPatt=/\W/;var validSymbolsNoArray=/[^.@\[]/;var validSymbolsWithArray=/[^.@"'\[\]]/;var validSymbols=validSymbolsNoArray;var splitTmp=strP.replace(/@/g,"^^@").split("^^");var split=clean_split_str(splitTmp);var obj=[];if(split){for(let val of split){if(val){var pos=strP.indexOf(val);if(val&&val.substr(0,1)==="@"){var tmpStr="";var word_start_pos=undefined;var word_end_pos=undefined;for(var i=0;i<=val.length;i++){var key1=i;var val1=val.substr(i,1);if(val1==="."&&!word_start_pos)word_start_pos=key1;if(word_start_pos&&key1>word_start_pos&&nonLettersPatt.test(val1))word_end_pos=key1;if(word_start_pos&&word_start_pos>=0&&word_end_pos&&word_end_pos>=0){var word=val.substr(word_start_pos+1,word_end_pos-word_start_pos-1);tmpStr=tmpStr.substr(0,word_start_pos)+"^^"+tmpStr.substr(word_start_pos,word_end_pos);if(val.substr(word_end_pos,1)===".")word_start_pos=word_end_pos;else word_start_pos=null;word_end_pos=null}if(val1==="[")validSymbols=validSymbolsWithArray;if(nonLettersPatt.test(val1)&&validSymbols.test(val1)&&tmpStr.indexOf("^^")===-1){tmpStr+="^^"+val1}else tmpStr+=val1}if(tmpStr.indexOf("^^")>-1){var obj1=extract_str(tmpStr,pos);obj=obj.concat(obj1)}else{var fieldId=undefined;if(val){fieldId=val.substr(1,val.length);if(val.indexOf(".")>-1)fieldId=val.substr(1,val.indexOf(".")-1);if(val.indexOf("[")>-1)fieldId=val.substr(1,val.indexOf("[")-1)}obj.push({value:val,fieldId:fieldId,pos:pos+posP})}}else{obj.push({value:val,pos:pos+posP})}}}return obj}};var res=extract_str(strP);return res};func.expression.parse=function(input){if(typeof input!=="string")return[];const segments=[];let pos=0;const parts=input.split(/(@\w+)/).filter(Boolean);for(const part of parts){if(part.startsWith("@")){const fieldId=part.slice(1);segments.push({value:part,fieldId:fieldId,pos:pos})}else{segments.push({value:part,pos:pos})}pos+=part.length}return segments};func.expression.get_property_org=async function(valP){async function secure_eval(val){if(typeof IS_PROCESS_SERVER==="undefined"){try{return eval(val)}catch(err){console.error(err);return}}try{let vm=new VM.VM({sandbox:{func:func,SESSION_ID:SESSION_ID,SESSION_OBJ:{[`${SESSION_ID}`]:SESSION_OBJ[SESSION_ID]}},timeout:1e3,allowAsync:false});return await vm.run(val)}catch(err){throw""}}var property1,property2;if(valP.indexOf("[")>-1&&valP.indexOf("]")>-1){property1=valP.substr(valP.indexOf("[")+1,valP.indexOf("]")-valP.indexOf("[")-1);property1=await secure_eval(property1)}if(valP.indexOf(".")>-1)property2=valP.substr(valP.indexOf(".")+1,valP.length);return{property1:property1,property2:property2}};func.expression.get_property=async function(valP){if(typeof valP!=="string")return{property1:undefined,property2:undefined};const secureEval=async expr=>{if(typeof IS_PROCESS_SERVER==="undefined"){try{return eval(expr)}catch(err){console.error(err);return undefined}}try{const vm=new VM.VM({sandbox:{func:func,SESSION_ID:SESSION_ID,SESSION_OBJ:{[SESSION_ID]:SESSION_OBJ[SESSION_ID]}},timeout:1e3,allowAsync:false});return await vm.run(expr)}catch{return undefined}};let property1,property2;const bracketStart=valP.indexOf("[");const bracketEnd=valP.indexOf("]");if(bracketStart>-1&&bracketEnd>bracketStart){const expr=valP.slice(bracketStart+1,bracketEnd);property1=await secureEval(expr)}const dotIndex=valP.indexOf(".");if(dotIndex>-1){property2=valP.slice(dotIndex+1)}return{property1:property1,property2:property2}};func.expression.validate_constant_org=function(valP){var patt=/["']/;if(typeof valP==="string"&&patt.test(valP.substr(0,1))&&patt.test(valP.substr(0,valP.length-1)))return true;else return false};func.expression.validate_variables_org=function(valP){if(typeof valP==="string"&&valP.indexOf("@")>-1)return true;else return false};func.expression.remove_quotes_org=function(valP){if(func.expression.validate_constant(valP))return valP.substr(1,valP.length-2);else return valP};func.expression.validate_constant=function(valP){typeof valP==="string"&&/^["'].*["']$/.test(valP)};func.expression.validate_variables=function(valP){typeof valP==="string"&&valP.includes("@")};func.expression.remove_quotes=function(valP){func.expression.validate_constant(valP)&&typeof valP==="string"?valP.slice(1,-1):valP};func.expression.secure_eval_org=async function(SESSION_ID,sourceP,val,job_id,dsSessionP,js_script_callback,evt){const api_utils=await func.common.get_module(SESSION_ID,"xuda-api-library.mjs",{func:func,glb:glb,SESSION_OBJ:SESSION_OBJ,SESSION_ID:SESSION_ID,APP_OBJ:APP_OBJ,dsSession:dsSessionP,job_id:job_id});const xu=api_utils;if(typeof IS_PROCESS_SERVER==="undefined"&&typeof IS_DOCKER==="undefined"){try{return eval(val)}catch(err){try{return JSON5.parse(val)}catch(err){return val}}}if(sourceP==="javascript"){process.on("uncaughtException",err=>{console.error("Asynchronous error caught.",err);func.events.delete_job(SESSION_ID,job_id);if(typeof IS_PROCESS_SERVER!=="undefined"||typeof IS_DOCKER!=="undefined"){if(SESSION_OBJ[SESSION_ID].crawler)return;return __.rpi.write_log(SESSION_OBJ[SESSION_ID].app_id,"error","worker","vm error",err,null,val,"func.expression.get.secure_eval")}});try{const dir=path.join(_conf.studio_drive_path,SESSION_OBJ[SESSION_ID].app_id,"node_modules","/");const script=new VM.VMScript(`try{${val}}catch(e){func.api.error(SESSION_ID, "nodejs error", e); console.error(e); func.events.delete_job(SESSION_ID, job_id);}`,{filename:dir,dirname:dir});let vm=new VM.NodeVM({require:{external:true},sandbox:{func:func,xu:xu,SESSION_ID:SESSION_ID,SESSION_OBJ:{[`${SESSION_ID}`]:SESSION_OBJ[SESSION_ID]},callback:js_script_callback,job_id:job_id,axios:axios,got:got,FormData:FormData},timeout:6e4});return await vm.run(script,{filename:dir,dirname:dir})}catch(err){console.error("Failed to execute script.",err);if(typeof IS_PROCESS_SERVER!=="undefined"){func.events.delete_job(SESSION_ID,jobNo);return __.db.add_error_log(SESSION_OBJ[SESSION_ID].app_id,"api",err)}}}else{try{try{let vm=new VM.VM({sandbox:{xu:xu,func:func,SESSION_ID:SESSION_ID,SESSION_OBJ:{[`${SESSION_ID}`]:SESSION_OBJ[SESSION_ID]},callback:js_script_callback,job_id:job_id},timeout:1e3,allowAsync:false});let ret=val;if(typeof val==="string"){ret=await vm.run(val)}return ret}catch(err){throw""}}catch(err){try{return JSON5.parse(val)}catch(err){return val}}}};func.expression.secure_eval=async function(SESSION_ID,sourceP,val,job_id,dsSessionP,js_script_callback,evt){if(typeof val!=="string")return val;const xu=await func.common.get_module(SESSION_ID,"xuda-api-library.mjs",{func:func,glb:glb,SESSION_OBJ:SESSION_OBJ,SESSION_ID:SESSION_ID,APP_OBJ:APP_OBJ,dsSession:dsSessionP,job_id:job_id});const isServer=typeof IS_PROCESS_SERVER!=="undefined"||typeof IS_DOCKER!=="undefined";if(!isServer){try{return eval(val)}catch{try{return JSON5.parse(val)}catch{return val}}}const sandbox={func:func,xu:xu,SESSION_ID:SESSION_ID,SESSION_OBJ:{[SESSION_ID]:SESSION_OBJ[SESSION_ID]},callback:js_script_callback,job_id:job_id,...sourceP==="javascript"?{axios:axios,got:got,FormData:FormData}:{}};const handleError=err=>{console.error("Execution error:",err);func.events.delete_job(SESSION_ID,job_id);if(isServer&&!SESSION_OBJ[SESSION_ID].crawler){if(sourceP==="javascript"){__.rpi.write_log(SESSION_OBJ[SESSION_ID].app_id,"error","worker","vm error",err,null,val,"func.expression.get.secure_eval")}else{__.db.add_error_log(SESSION_OBJ[SESSION_ID].app_id,"api",err)}}return val};if(sourceP==="javascript"){process.on("uncaughtException",handleError);try{const dir=path.join(_conf.studio_drive_path,SESSION_OBJ[SESSION_ID].app_id,"node_modules");const script=new VM.VMScript(`try { ${val} } catch (e) { func.api.error(SESSION_ID, "nodejs error", e); console.error(e); func.events.delete_job(SESSION_ID, "${job_id}"); }`,{filename:dir,dirname:dir});const vm=new VM.NodeVM({require:{external:true},sandbox:sandbox,timeout:6e4});return await vm.run(script,{filename:dir,dirname:dir})}catch(err){return handleError(err)}}try{const vm=new VM.VM({sandbox:sandbox,timeout:1e3,allowAsync:false});return await vm.run(val)}catch{try{return JSON5.parse(val)}catch{return val}}};func.UI.main={};func.UI.main.clear_SYNC_INTERVAL=function(){$("body").unbind("mousemove keypress mousedown")};func.UI.main.embed_prog_execute=async function(SESSION_ID,prog){var _session=SESSION_OBJ[SESSION_ID];const _prog=await func.utils.VIEWS_OBJ.get(SESSION_ID,prog);const get_params_obj=function(){var params_obj={};if(_prog?.properties?.progParams){for(const[key,val]of Object.entries(_prog.properties.progParams)){if(!val.data.dir==="in")continue;if(typeof _session.url_params?.[val.data.parameter]!=="undefined"){params_obj[val.data.parameter]=_session.url_params?.[val.data.parameter];continue}console.warn(`Warning: Program ${_prog.properties.menuName} expected In parameter: ${val.data.parameter} but received null instead`)}}return params_obj};let screen_ret=await func.utils.get_screen_obj(SESSION_ID,prog);if(screen_ret){let ret_init=await func.UI.screen.init(SESSION_ID,prog,null,null,$("#embed_"+SESSION_ID),null,null,null,null,get_params_obj(),"call_embed");document.title=screen_ret.properties.menuTitle;return}console.error("Program not exist",prog);func.UI.utils.progressScreen.show(SESSION_ID,"Program not exist",null,true)};func.UI.main.embed_loader=async function(SESSION_ID){var _session=SESSION_OBJ[SESSION_ID];var hash="";if(window.location.hash)hash=window.location.hash.substr(1);_session.SYS_GLOBAL_STR_BROWSER_HASH_ID=hash;_session.SYS_GLOBAL_STR_BROWSER_TITLE=document.title;const init_system_ds=async function(){if(!["main"].includes(_session.opt.app_computing_mode)){await func.index.new_webworker(SESSION_ID,{menuName:"Main"})}const ret=await func.datasource.create(SESSION_ID,"system");return ret};const set_SYS_GLOBAL_KEYS_STATE=async function(SESSION_ID,e,state){if(!_session?.DS_GLB?.[0])return;if(e.keyCode!==16&&e.keyCode!==17&&e.keyCode!==18&&e.keyCode!==91){return}var data={};if(e.keyCode===17){data.SYS_GLOBAL_BOL_CONTROL_KEY_STATE=state}if(e.keyCode===16){data.SYS_GLOBAL_BOL_SHIFT_KEY_STATE=state}if(e.keyCode===18){data.SYS_GLOBAL_BOL_ALT_KEY_STATE=state}if(e.keyCode===91){data.SYS_GLOBAL_BOL_COMMAND_KEY_STATE=state}var datasource_changes={[0]:{["data_system"]:data}};await func.datasource.update(SESSION_ID,datasource_changes)};const start_workers=async function(){_session.WORKER_OBJ.fx=new func.utils.job_worker(SESSION_ID);_session.WORKER_OBJ.fx.init()};const create_embed_container=async function(){$("<div>").attr("id","embed_"+SESSION_ID).addClass("xu_embed_div").data({xuData:{}}).appendTo($(_session.root_element))};const execute_PENDING_OPEN_URL_EVENTS=async function(){if(typeof func.events.execute_PENDING_OPEN_URL_EVENTS!=="undefined"&&glb.is_cordova){func.events.execute_PENDING_OPEN_URL_EVENTS()}};const remove_loader=async function(){$(".loader").remove();$(_session.root_element).removeClass("loader_background_color")};const perform_callback=async function(){if(_session.api_callback){_session.api_callback("xuda_ready",SESSION_ID,SESSION_OBJ)}};const call_program=async function(){if(_session.route_id){const route_obj=await func.utils.DOCS_OBJ.get(SESSION_ID,_session.route_id);function flattenMenuItems(menu){let flatMenu={};function recurse(items){for(let item of items){flatMenu[item.id]=item;if(item.children&&item.children.length>0){recurse(item.children)}}}recurse(menu);return flatMenu}const flatMenu=flattenMenuItems(route_obj.routeMenu.menu);const menu_obj=flatMenu[_session.menu_id];if(_session.menu_id){if(menu_obj){_session.prog_id=menu_obj.prog_id;if(menu_obj.prog_params){_session.url_params={..._session.url_params,...menu_obj.prog_params}}if(menu_obj.global_params){_session.url_params={..._session.url_params,...menu_obj.global_params}}}}}if(!_session.prog_id)return;await func.utils.TREE_OBJ.get(SESSION_ID,_session.prog_id);let screen_ret=await func.utils.get_screen_obj(SESSION_ID,_session.prog_id);if(screen_ret){func.UI.main.embed_prog_execute(SESSION_ID,_session.prog_id)}else{console.error("Program not exist",_session.prog_id);func.UI.utils.progressScreen.show(SESSION_ID,"Program not exist",null,true)}};const register_run_background_plugins=async function(){if(typeof glb.SLIM_BUNDLE!=="undefined"||glb.SLIM_BUNDLE)return;for await(const[plugin_name,val]of Object.entries(APP_OBJ[_session.app_id].app_plugins_purchased)){if(val.installed&&val.run_in_background&&val.manifest?.["runtime.mjs"]?.exist){try{const plugin_runtime_src=await func.utils.get_plugin_npm_cdn(SESSION_ID,plugin_name,`${val.manifest["runtime.mjs"].dist?"dist/":""}runtime.mjs`);if(val.manifest["runtime.mjs"].dist&&val.manifest?.["runtime.mjs"]?.css){const plugin_runtime_css_url=await func.utils.get_plugin_npm_cdn(SESSION_ID,plugin_name,"dist/runtime.css");func.utils.load_css_on_demand(plugin_runtime_css_url)}const plugin_script=await import(plugin_runtime_src);eval(plugin_script);let plugin_setup_script_ret=null;if(val.manifest?.["index.mjs"]?.exist){const plugin_setup_src=await func.utils.get_plugin_npm_cdn(SESSION_ID,plugin_name,`${val.manifest["index.mjs"].dist?"dist/":""}index.mjs`);let plugin_setup_script=await import(plugin_setup_src);if(plugin_setup_script){plugin_setup_script_ret=await func.utils.get_plugin_setup(SESSION_ID,plugin_name);if(plugin_setup_script_ret.code<0){throw plugin_setup_script_ret}}}glb.lifecycle.plugins[plugin_name]={plugin_script:plugin_script,setup_data:plugin_setup_script_ret?.data}}catch(err){console.error(err)}}}};async function updateOnlineStatus(){if(!_session?.DS_GLB?.[0])return;var data={};if(navigator.onLine){data.SYS_GLOBAL_BOL_ONLINE=1}else{data.SYS_GLOBAL_BOL_ONLINE=0}var datasource_changes={[0]:{["data_system"]:data}};await func.datasource.update(SESSION_ID,datasource_changes)}await register_run_background_plugins();$(_session.root_element).show();func.UI.component.create_app_root_component(SESSION_ID);await glb.lifecycle.execute(SESSION_ID,"beforeInit");await start_workers();await init_system_ds();await glb.lifecycle.execute(SESSION_ID,"initialized");await create_embed_container();await execute_PENDING_OPEN_URL_EVENTS();await remove_loader();await func.UI.worker.init(SESSION_ID);await glb.lifecycle.execute(SESSION_ID,"beforeMounted");await call_program();await glb.lifecycle.execute(SESSION_ID,"mounted");await perform_callback();func.utils.debug.write(SESSION_ID,"Xuda.io started.");await glb.lifecycle.execute(SESSION_ID,"systemReady");$(document).keydown(function(e){set_SYS_GLOBAL_KEYS_STATE(SESSION_ID,e,1)});$(document).keyup(function(e){set_SYS_GLOBAL_KEYS_STATE(SESSION_ID,e,0)});await updateOnlineStatus();window.addEventListener("online",updateOnlineStatus);window.addEventListener("offline",updateOnlineStatus);console.log("xuda.io system ready.");$("body")[0].dispatchEvent(glb.system_ready_event)};func.UI.main.set_custom_css=function(SESSION_ID,callbackP){if(SESSION_OBJ[SESSION_ID].DS_GLB[0].data_system?.["SYS_GLOBAL_STR_SITE_CSS"])$("<style type='text/css'> "+SESSION_OBJ[SESSION_ID].DS_GLB[0].data_system["SYS_GLOBAL_STR_SITE_CSS"]+" </style>").appendTo("head");callbackP()};func.index={};$(document).ready(function(){func.index.init_document_listeners();func.UI.utils.indicator.worker.normal();func.index.init_service_workers()});function xuda(...args){let element=null;let opt={};let callback=null;for(const arg of args){if(arg instanceof HTMLElement){element=arg}else if(typeof arg==="object"&&arg!==null&&!Array.isArray(arg)){opt=arg}else if(typeof arg==="function"){callback=arg}}if(!element){if(typeof glb.SLIM_BUNDLE==="undefined"||!glb.SLIM_BUNDLE){return console.error("Xuda Error - element argument is empty")}element="body";console.warn("root element set to body")}if(!$(element).length){return console.error("Xuda Error - element not found")}if(typeof opt==="undefined"){return console.error("Xuda Error - opt argument is undefined")}if(typeof opt!=="object"){return console.error("Xuda Error - opt argument is not an object")}glb.URL_PARAMS=func.common.getJsonFromUrl(window.location.href);glb.worker_type="Worker";if(opt.debug_js){glb.debug_js=true;if((location.host.includes("localhost")||location.host.includes("127.0.0.1"))&&typeof glb.SLIM_BUNDLE==="undefined"&&typeof glb.CODE_BUNDLE==="undefined"){glb.worker_type="Dev"}else{glb.worker_type="Debug"}}const call_xuda=async function(){const _instance_id=Date.now().toString()+Math.round(Math.random()*1e4).toString();const _api_callback=callback;const create_index_html=function(){const{root_element,domain}=_session;$(root_element).css("position","relative");$(root_element).append(`
6
6
 
7
7
  <style>
8
8
  .loader {
@@ -2,7 +2,7 @@
2
2
  ${refIdP.value}
3
3
  })(document.querySelector(\`[xu-ui-id=${elementP}]\`),evt)`,null,null,null,evt);await func.datasource.set_outputField(SESSION_ID,dsSessionP,result,args);return result},execute_evaluate_javascript:async function(){const module=await func.common.get_module(SESSION_ID,"xuda-event-javascript-module.mjs");const result=await module.run_javascript(SESSION_ID,jobNoP,dsSession,`(async function(el,evt) {
4
4
  ${refIdP.value}
5
- })(document.querySelector(\`[xu-ui-id=${elementP}]\`),evt)`,true,null,null,evt);await func.datasource.set_outputField(SESSION_ID,dsSessionP,result,args);return result},loader_on:async function(){glb.CURRENT_APP_LOADING=null;LOADER_ACTIVE=true;LOADER_TEXT=descP;func.events.delete_job(SESSION_ID,jobNoP)},loader_off:async function(){LOADER_ACTIVE=false;func.events.delete_job(SESSION_ID,jobNoP)},emit_event:async function(){if(refIdP.value){$(document).trigger(refIdP.value,[_session.DS_GLB[dsSession]])}else{func.utils.debug_report(SESSION_ID,"func.events.execute","Event name missing","E")}func.events.delete_job(SESSION_ID,jobNoP)},invoke_action:async function(){func.utils.debug.watch(SESSION_ID,calling_trigger_prop?.id,functionP,null,null,expCond);await func.action.execute(SESSION_ID,refIdP.value,_ds,null,null,jobNoP,containerP)},raise_event:async function(){var _ds=_session.DS_GLB[dsSession];const _view_obj=await func.utils.VIEWS_OBJ.get(SESSION_ID,_ds.prog_id);if(callingSourceP==="grid"||callingSourceP==="form"){let _field_obj=func.common.find_item_by_key(_view_obj.progFields,"field_id",field_elm);var event_name=_field_obj?.triggers?.[eventIdP].name.event;if(_field_obj?.triggers?.[eventIdP].name?.properties["xu-exp:event"]){event_name=(await func.expression.get(SESSION_ID,props[`xu-exp:event`],dsSession,"event_name expression")).result}if(field_elm&&event_name){const dsP=await func.datasource.find_event_dataSource(SESSION_ID,event_name,dsSession);return await func.datasource.run_events_functions(SESSION_ID,dsP,event_name,jobNoP,null,calling_trigger_prop?.data?.name?.parameters||{})}}if(callingSourceP.includes("event")){let event_name=refIdP.event;if(refIdP?.properties?.["xu-exp:event"]){event_name=(await func.expression.get(SESSION_ID,refIdP.properties["xu-exp:event"],dsSession,"event_name expression")).result}const dsP=await func.datasource.find_event_dataSource(SESSION_ID,event_name,dsSession);await func.datasource.run_events_functions(SESSION_ID,dsP,event_name,jobNoP,calling_trigger_prop?.props?.async,calling_trigger_prop?.data?.name?.parameters||{})}func.events.delete_job(SESSION_ID,jobNoP);func.utils.debug.watch(SESSION_ID,calling_trigger_prop?.id,functionP,"","",expCond)},get_data:async function(){const params_obj=await get_params_obj();if(!await get_prog_id()){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} > ${triggerP} > ${functionP} > program ${prog} is missing`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}var _ds=_session.DS_GLB[dsSession];if(!_ds){func.events.delete_job(SESSION_ID,jobNoP);return}if(_ds){func.utils.debug.watch(SESSION_ID,calling_trigger_prop?.id,functionP,null,calling_trigger_prop,expCond);const ret=await func.datasource.create(SESSION_ID,await get_prog_id(),args.dataSourceNoP,args.parentDataSourceNoP,args.containerIdP,args.rowIdP,args.jobNoP,args.calling_trigger_prop,null,null,args.callingSourceP,args.calling_jobP,args.screen_dsP,args.is_panelP,params_obj);let _ds_new=_session.DS_GLB[ret.dsSessionP];let parameters=args?.calling_trigger_prop?.data?.name?.parameters;if(parameters&&!_.isEmpty(parameters)){await func.datasource.update_changes_for_out_parameter(SESSION_ID,_ds_new.dsSession,_ds.dsSession)}func.events.delete_job(SESSION_ID,jobNoP);return _ds_new}},set_data:async function(){return this.get_data()},batch:async function(){const result=await this.get_data();return result},update:async function(){const obj_values_to_update=func.datasource.get_viewFields_for_update_function(SESSION_ID,calling_trigger_prop,null,dsSessionP);if(!obj_values_to_update||_.isEmpty(obj_values_to_update)){func.utils.debug_report(SESSION_ID,"Update values object is empty","","W");if(jobNoP)func.events.delete_job(SESSION_ID,jobNoP);return}var updates=[];for await(const[key,val]of Object.entries(obj_values_to_update)){var $element;if(elementP){$element=$(`[xu-ui-id="${elementP}"]`).clone(true)}let ret_field_id=await func.expression.get(SESSION_ID,val.id.trim(),dsSessionP,"update",null,null,null,null,null,null,$element?.length?$element?.data()?.xuData?.iterate_info:null);let ret_value=await func.expression.get(SESSION_ID,val.val.trim(),dsSessionP,"update",null,null,null,null,null,null,$element?.length?$element?.data()?.xuData?.iterate_info:null);let _field_id=ret_field_id.result;let _value=ret_value.result;updates.push({_field_id:_field_id,_value:_value})}let datasource_changes={};for await(const change of updates){let ret_get_value=await func.datasource.get_value(SESSION_ID,change._field_id,dsSessionP);if(ret_get_value.found){let _ds=_session.DS_GLB[ret_get_value.dsSessionP];if(!datasource_changes[_ds.dsSession]){datasource_changes[_ds.dsSession]={}}if(!datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]){datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]={}}datasource_changes[_ds.dsSession][ret_get_value.currentRecordId][change._field_id]=change._value}}await func.datasource.update(SESSION_ID,datasource_changes);if(jobNoP)func.events.delete_job(SESSION_ID,jobNoP)},call_alert:async function(){await func.utils.alerts.invoke(SESSION_ID,"call_alert",refIdP,log_source,dsSession);func.events.delete_job(SESSION_ID,jobNoP)},alert:async function(){await func.utils.alerts.invoke(SESSION_ID,"alert",refIdP,log_source,dsSession);func.events.delete_job(SESSION_ID,jobNoP)},delay:async function(){return new Promise(resolve=>{setTimeout(function(){if(jobNoP)func.events.delete_job(SESSION_ID,jobNoP);resolve()},refIdP.value)})},comment:async function(){if(jobNoP)func.events.delete_job(SESSION_ID,jobNoP)},call_project_api:async function(){const params_obj=await get_params_obj();const _prog_id=await get_prog_id();if(!_prog_id){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} > ${triggerP} > ${functionP} > program not defined`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}const api_ret=await func.api.call_project_api(_prog_id,params_obj);await func.datasource.set_outputField(SESSION_ID,dsSessionP,api_ret,args);func.events.delete_job(SESSION_ID,jobNoP)},call_system_api:async function(){const api_method=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"api_method");if(!api_method){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} >${triggerP} >${functionP} > api_method not defined`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}let payload={};const _payload=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"payload");if(_payload){const get_payload_property_value=async function(prop_name){let _prop=_payload;let _value=_prop[prop_name];if(_prop?.[`xu-exp:${prop_name}`]){_value=(await func.expression.get(SESSION_ID,_prop[`xu-exp:${prop_name}`],dsSession,`${prop_name} expression`)).result}return _value};for await(let[key,val]of Object.entries(_payload)){const new_key=key.replaceAll("xu-exp:","");payload[new_key]=await get_payload_property_value(new_key)}}const output_field=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"outputField");const api_ret=await func.api.call_system_api(api_method,payload);if(output_field){let datasource_changes={};let ret_get_value=await func.datasource.get_value(SESSION_ID,output_field,dsSessionP);if(ret_get_value.found){let _ds=_session.DS_GLB[ret_get_value.dsSessionP];if(!datasource_changes[_ds.dsSession]){datasource_changes[_ds.dsSession]={}}if(!datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]){datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]={}}datasource_changes[_ds.dsSession][ret_get_value.currentRecordId][output_field]=api_ret;await func.datasource.update(SESSION_ID,datasource_changes)}}func.events.delete_job(SESSION_ID,jobNoP)},call_external_api:async function(){const method=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"method");if(!method){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} >${triggerP} >${functionP} > method not defined`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}const url=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"url");if(!url){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} >${triggerP} >${functionP} > url not defined`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}const payload_arr=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"payload");const report_conversion_error=function(res,typeP,valP){var msg=`${elementP} >${triggerP} >${functionP} > error converting from ${valP} to ${typeP}`;if(error){return func.utils.debug_report(SESSION_ID,msg,"","W")}func.utils.debug_report(SESSION_ID,msg+" "+_.capitalize(source)+prog_info,"","E")};const report_conversion_warn=function(res){var msg=`${elementP} >${triggerP} >${functionP} > type mismatch auto conversion from value ${valP} to ${typeP}`;func.utils.debug_report(SESSION_ID,msg+" "+_.capitalize(source)+prog_info,"","W")};if(error){return report_conversion_error()}const module=await func.common.get_module(SESSION_ID,"xuda-get-cast-util-module.mjs");var payload=_.reduce(payload_arr,(ret,val,key)=>{ret[val.key]=module.cast(val.type,val.val,report_conversion_error,report_conversion_warn);return ret},{});const output_field=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"outputField");const api_ret=await func.api.call_external_api(method,url,payload);if(output_field){let datasource_changes={};let ret_get_value=await func.datasource.get_value(SESSION_ID,output_field,dsSessionP);if(ret_get_value.found){let _ds=_session.DS_GLB[ret_get_value.dsSessionP];if(!datasource_changes[_ds.dsSession]){datasource_changes[_ds.dsSession]={}}if(!datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]){datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]={}}datasource_changes[_ds.dsSession][ret_get_value.currentRecordId][output_field]=api_ret;await func.datasource.update(SESSION_ID,datasource_changes)}}func.events.delete_job(SESSION_ID,jobNoP)}};return await fx[functionP]()};func.events.delete_job=function(SESSION_ID,jobNoP){var _session=SESSION_OBJ[SESSION_ID];var job_index=func.events.find_job_index(SESSION_ID,jobNoP);if(!_session.WORKER_OBJ.jobs[job_index]){_session.WORKER_OBJ.stat=null;return}var dsSession=_session.WORKER_OBJ.jobs[job_index].dsSessionP;let ds_obj=_session?.DS_GLB[dsSession];if(ds_obj){delete SCREEN_BLOCKER_OBJ[ds_obj.screenId+(ds_obj.callingScreenId?"_"+ds_obj.callingScreenId:"")]}if(dsSession&&ds_obj?.loops_limit&&ds_obj?.loops_count<ds_obj?.loops_limit-1){return}_session.WORKER_OBJ.stat=null;_session.WORKER_OBJ.jobs.splice(job_index,1)};func.events.delete_job_0=function(SESSION_ID){var job_index=0;var _session=SESSION_OBJ[SESSION_ID];if(!_session.WORKER_OBJ.jobs[job_index]){_session.WORKER_OBJ.stat=null;return}var dsSession=_session.WORKER_OBJ.jobs[job_index].dsSession;let ds_obj=_session?.DS_GLB[dsSession];if(ds_obj){delete SCREEN_BLOCKER_OBJ[ds_obj.screenId+(ds_obj.callingScreenId?"_"+ds_obj.callingScreenId:"")]}if(dsSession&&ds_obj&&ds_obj.loops_limit&&ds_obj.loops_count<ds_obj.loops_limit-1){return}_session.WORKER_OBJ.stat=null;_session.WORKER_OBJ.jobs.splice(job_index,1)};func.events.check_jobs_idle=async function(SESSION_ID,jobsP){return new Promise((resolve,reject)=>{var _session=SESSION_OBJ[SESSION_ID];if(!jobsP||jobsP&&jobsP.length===0){resolve();return}var listener=setInterval(function(){var found;for(const[key,val]of Object.entries(jobsP)){_.forEach(_session.WORKER_OBJ.jobs,function(val2,key2){if(key2===val){found=true;return false}})}if(!found){do_callback();return}},100);var do_callback=function(){window.clearInterval(listener);resolve()}})};var loop_detected_obj={};setInterval(function(){loop_detected_obj={}},1e3);func.events.set_browser_changes=function(dsP,fieldsChangedP){if(fieldsChangedP.includes("SYS_GLOBAL_STR_BROWSER_TITLE"))document.title=dsP.dataset_new["SYS_GLOBAL_STR_BROWSER_TITLE"]};func.events.execute_PENDING_OPEN_URL_EVENTS=async function(){for(let[key,url]of Object.entries(PENDING_OPEN_URL_EVENTS)){if(url){glb.WINDOW_LOCATION_SEARCH=url;glb.ROOT_ELEMENT_ATTRIBUTES=func.UI.utils.get_root_element_attributes();const params_obj=func.common.getObjectFromUrl(url,glb.ROOT_ELEMENT_ATTRIBUTES);if(!params_obj.prog){return console.warn("prog empty")}await func.utils.TREE_OBJ.get(SESSION_ID,params_obj.prog);let screen_ret=await func.utils.get_screen_obj(SESSION_ID,params_obj.prog);if(screen_ret){await func.UI.screen.init(SESSION_ID,params_obj.prog,null,null,$("#embed_"+SESSION_ID),null,null,null,null,null,"pendingUrlEvent_embed")}else{console.error("Program not exist",params_obj.prog_id);func.UI.utils.progressScreen.show(SESSION_ID,"Program not exist",null,true)}}else{console.warn("url empty")}}};func.events.invoke=async function(event_id){var _session=SESSION_OBJ[SESSION_ID];if(!event_id){console.warn("event_id Cannot be empty");return false}var ds;for await(const[ds_key,val]of Object.entries(_session.DS_GLB)){const _view_obj=await func.utils.VIEWS_OBJ.get(SESSION_ID,val.prog_id);if(_.isEmpty(_view_obj.progEvents))continue;if(ds)break;for await(const[key,val]of Object.entries(_view_obj.progEvents)){if(val?.data?.type==="user_defined"&&val.data.event_name===event_id){ds=ds_key;break}}}if(!ds){console.warn("event_id not found");return false}func.events.validate(SESSION_ID,"user_defined",ds,event_id)};func.expression={};func.expression.get=async function(SESSION_ID,valP,dsSessionP,sourceP,rowIdP,sourceActionP,secondPassP,calling_fieldIdP,fieldsP,debug_infoP,iterate_info,js_script_callback,jobNo,api_output_type){class xu_class{async get(){var ret;var fields={};var error;var warning;function evalJson(text){return eval("("+text+")")}if(valP===null){ret=""}else{switch(typeof valP){case"string":ret=valP;break;case"undefined":ret="";break;case"boolean":ret=valP?"Y":"N";break;default:ret=valP.toString();break}}ret=ret.replace(/\&amp;/g,"&");ret=func.utils.replace_studio_drive_url(SESSION_ID,ret);const end_results=function(){const replace_quotes=function(ret){for(const[key,val]of Object.entries(fields)){if(typeof val==="string")ret=ret.replace('"'+val+'"',val.replace(/"/gi,""))}return ret};if(["update","javascript"].includes(sourceP)){if(typeof ret==="string")ret=replace_quotes(ret)}const log_error=function(){if(SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP]){func.utils.debug.log(SESSION_ID,SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP].nodeId,{module:"expression",action:sourceP,source:calling_fieldIdP,prop:ret,details:ret,result:ret,error:error,warning:warning,fields:null,type:"exp",prog_id:SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP].prog_id,debug_info:debug_infoP})}};if(error)log_error();return{result:ret,fields:fields,res:res,explain:result,error:error,warning:warning,req:valP,var_error_found:var_error_found}};const variable_not_exist=async function(){try{if(sourceP!=="arguments"){if(ret&&ret.substr(0,6)==="_DATE_"){ret=ret.substr(6)}else if(ret&&ret.length===10&&ret.substr(4,1)==="-"&&ret.substr(7,1)==="-"||ret==="self"){ret=ret}else{ret=await func.expression.secure_eval(SESSION_ID,sourceP,ret,jobNo,dsSessionP,js_script_callback)}return end_results()}else{ret=ret.replace(/_NULL/gi,"");return end_results()}}catch(err){return end_results()}};if(!func.expression.validate_variables(valP)){return await variable_not_exist()}const validate_email=async function(){const ret=await func.expression.secure_eval(SESSION_ID,sourceP,valP,jobNo,dsSessionP,js_script_callback);return glb.emailRegex.test(ret)};if(await validate_email()){return await variable_not_exist()}var var_Arr=[];const split=func.expression.parse(ret)||[];for await(const[arr_key,val]of Object.entries(split)){const key=Number(arr_key);var_Arr[key]={};var_Arr[key].value=val.value;const replace_value_in_string=async function(retP,fieldIdP){if(iterate_info?.iterator_key===fieldIdP||iterate_info?.iterator_val===fieldIdP){if(iterate_info.iterator_key===fieldIdP){retP.value=iterate_info._key}if(iterate_info.iterator_val===fieldIdP){retP.value=iterate_info._val}}const set_value=function(valP){if(typeof valP!=="undefined"){var_Arr[key].value=valP;if(typeof valP==="string")var_Arr[key].type="string"}else{if(retP.type==="object"){var_Arr[key].value="";var_Arr[key].type="string"}}};if(sourceP==="exp"&&retP.type!=="exp"){var_Arr[key].type=retP.type;return}if(typeof retP.value!=="undefined"){var_Arr[key].type=retP.type;var_Arr[key].value=retP.value;if(val.value.indexOf("[")>-1|val.value.indexOf(".")>-1){var data=retP.prop;if(retP.type==="object")data=retP.value;var property1,property2;if(val.value.indexOf("[")===-1&&val.value.indexOf("]")>-1&&val.value.substr(0,1)==="@"){var prevData=var_Arr[key-1].value;var_Arr[key].value=prevData[data];if(val.value.indexOf(".")>-1){property2=await func.expression.get_property(val.value).property2;if(prevData[data])set_value(prevData[data][property2])}delete var_Arr[key-1]}else{property1=await func.expression.get_property(val.value).property1;property2=await func.expression.get_property(val.value).property2;if(property1){var_Arr[key].value=data[property1];if(property2){if(data[property1])set_value(data[property1][property2])}}if(property2&&!property1){if(data){set_value(data[property2])}}}fields[fieldIdP]=var_Arr[key].value;var_Arr[key].fieldId=fieldIdP}else{fields[fieldIdP]=var_Arr[key].value;var_Arr[key].fieldId=fieldIdP}}};if(val.fieldId){if(val.fieldId&&val.fieldId.substr(0,5)==="_THIS"&&calling_fieldIdP&&(val.fieldId.length===5||val.fieldId.length>5&&val.fieldId.substr(5,1)===".")){if(val.fieldId.length===5)val.fieldId=calling_fieldIdP;else val.fieldId=calling_fieldIdP+val.fieldId(5,val.fieldId.length-1)}if(!sourceP==="exp"){var_Arr[key].value='""'}fields[val.fieldId]=var_Arr[key].value;const ret=await func.datasource.get_value(SESSION_ID,val.fieldId,dsSessionP,rowIdP);await replace_value_in_string(ret.ret,ret.fieldIdP)}}try{var res=[];var exp_exist;var var_error_found;_.forEach(var_Arr,function(val,key){if(sourceP==="UI Property EXP"){let ret=func.utils.get_drive_url(SESSION_ID,val.value,true);if(ret.changed){res[key]=ret.value;return true}}if(sourceP==="UI Attr EXP"){let ret=func.utils.get_drive_url(SESSION_ID,val.value,var_Arr.length==1?false:true);if(ret.changed){res[key]=ret.value;return true}}if(val.type==="exp"){exp_exist=true}res[key]=val.value;if(var_Arr.length>1){if(!["DbQuery","alert","exp","api_rendered_output"].includes(sourceP)&&["string","date"].includes(val.type)){res[key]="`"+val.value+"`"}if(["api_rendered_output"].includes(sourceP)&&["json"].includes(api_output_type)&&["string","date"].includes(val.type)){res[key]=`"`+val.value+`"`}}if(val.fieldId&&val.value&&typeof val.value==="string"){if(["query","condition","range","sort","locate"].includes(sourceP)){if(val.value.indexOf("↵")>-1){res[key]=val.value.split("↵").join("")}res[key]=res[key].replace(/(\r\n|\n|\r)/gm,"")}if(["init","update","virtual"].includes(sourceP)){if(val.value.indexOf("↵")>-1)res[key]=val.value.split("↵").join("\n");res[key]=res[key].replace(/(\r\n|\n|\r)/gm,"\\n")}if(typeof IS_PROCESS_SERVER!=="undefined"){res[key]=res[key].replace(/(\r\n|\n|\r)/gm,"<br>")}fields[val.fieldId]=res[key]}if(typeof val.value==="object"&&var_Arr.length>1){if(!Array.isArray(val.value)&&!var_Arr[key+1].value?.includes(".")){res[key]="("+JSON.stringify(val.value)+")"}else{res[key]=JSON.stringify(val.value)}}if(!exp_exist&&sourceP!=="exp"&&val.value&&typeof val.value==="string"&&val.value.substr(0,1)==="@"){warning="Error encoding "+val.value;var_error_found=true;res[key]=0}});const join=function(arrP){return arrP.join("")};var exp=undefined;if(exp_exist&&sourceP!=="exp"){exp=await func.expression.get(SESSION_ID,join(res),dsSessionP,sourceP,rowIdP,sourceActionP,true,calling_fieldIdP,fields,debug_infoP);if(exp.res)res=exp.res;else res=[exp.result];fields=_.assignIn(exp.fields,fieldsP)}var result=join(res);if(res.length===1){result=res[0]}if(secondPassP){ret=result}else if(sourceP!=="exp"){if(res.length===1&&typeof res[0]==="string"&&typeof res[0]!=="object"){ret=join(res);if(ret&&ret.substr(0,1)==="@"){error="Error encoding @ var";var_error_found=true}}else{if(!["arguments","api_rendered_output","DbQuery"].includes(sourceP)){ret=await func.expression.secure_eval(SESSION_ID,sourceP,result,jobNo,dsSessionP,js_script_callback)}else{if(sourceP==="DbQuery"){ret=JSON.stringify(evalJson(result))}else{ret=result}}}}return end_results()}catch(err){ret=result;error=err.message;return end_results()}}}const new_class=new xu_class;return new_class.get()};func.expression.get_bad=async function(SESSION_ID,valP,dsSessionP,sourceP,rowIdP,sourceActionP,secondPassP,calling_fieldIdP,fieldsP={},debug_infoP,iterate_info,js_script_callback,jobNo,api_output_type){const evalJson=text=>eval(`(${text})`);const replaceQuotes=str=>{for(const[key,val]of Object.entries(fields)){if(typeof val==="string")str=str.replace(`"${val}"`,val.replace(/"/g,""))}return str};let ret,error,warning,var_error_found;const fields={...fieldsP};if(valP===null||typeof valP==="undefined")ret="";else if(typeof valP==="boolean")ret=valP?"Y":"N";else ret=valP.toString();ret=ret.replace(/\&/g,"&");ret=func.utils.replace_studio_drive_url(SESSION_ID,ret);const endResults=()=>{if(["update","javascript"].includes(sourceP)&&typeof ret==="string"){ret=replaceQuotes(ret)}if((error||warning)&&SESSION_OBJ[SESSION_ID]?.DS_GLB[dsSessionP]){func.utils.debug.log(SESSION_ID,SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP].nodeId,{module:"expression",action:sourceP,source:calling_fieldIdP,prop:ret,details:ret,result:ret,error:error,warning:warning,fields:null,type:"exp",prog_id:SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP].prog_id,debug_info:debug_infoP})}return{result:ret,fields:fields,error:error,warning:warning,req:valP,var_error_found:var_error_found}};const handleNonVariable=async()=>{try{if(sourceP!=="arguments"){if(ret.startsWith("_DATE_"))ret=ret.slice(6);else if(/^\d{4}-\d{2}-\d{2}$/.test(ret)||ret==="self")return endResults();else ret=await func.expression.secure_eval(SESSION_ID,sourceP,ret,jobNo,dsSessionP,js_script_callback)}else{ret=ret.replace(/_NULL/gi,"")}return endResults()}catch(err){error=err.message;return endResults()}};if(!func.expression.validate_variables(valP))return await handleNonVariable();if(glb.emailRegex.test(await func.expression.secure_eval(SESSION_ID,sourceP,valP,jobNo,dsSessionP,js_script_callback))){return await handleNonVariable()}const split=func.expression.parse(ret)||[];const var_Arr=await Promise.all(split.map(async(val,key)=>{const result={value:val.value,fieldId:val.fieldId};if(!val.fieldId)return result;if(val.fieldId.startsWith("_THIS")&&calling_fieldIdP){result.fieldId=val.fieldId.length===5?calling_fieldIdP:calling_fieldIdP+val.fieldId.slice(5)}const{ret:fetchedValue,fieldIdP}=await func.datasource.get_value(SESSION_ID,result.fieldId,dsSessionP,rowIdP);result.value=fetchedValue?.value??(sourceP==="exp"?fetchedValue?.value:'""');result.type=fetchedValue?.type;if(iterate_info){if(iterate_info.iterator_key===fieldIdP)result.value=iterate_info._key;if(iterate_info.iterator_val===fieldIdP)result.value=iterate_info._val}if(val.value.includes("[")||val.value.includes(".")){const{property1,property2}=await func.expression.get_property(val.value);const data=fetchedValue?.type==="object"?fetchedValue.value:fetchedValue?.prop;if(key>0&&val.value.includes("]")&&!val.value.includes("[")&&split[key-1].value){const prevData=split[key-1].value;result.value=prevData[fieldIdP];if(val.value.includes(".")&&prevData[fieldIdP]){result.value=prevData[fieldIdP][property2]??""}}else if(data){if(property1)result.value=data[property1]??"";if(property2)result.value=(property1?data[property1]?.[property2]:data[property2])??""}}fields[fieldIdP]=result.value;return result}));try{const res=var_Arr.map((val,key)=>{if(sourceP==="UI Property EXP"||sourceP==="UI Attr EXP"){const{changed,value}=func.utils.get_drive_url(SESSION_ID,val.value,sourceP==="UI Attr EXP"&&var_Arr.length>1);if(changed)return value}let value=val.value;if(var_Arr.length>1){if(!["DbQuery","alert","exp","api_rendered_output"].includes(sourceP)&&["string","date"].includes(val.type)){value=`\`${value}\``}else if(sourceP==="api_rendered_output"&&api_output_type==="json"&&["string","date"].includes(val.type)){value=`"${value}"`}}if(val.fieldId&&typeof value==="string"){if(["query","condition","range","sort","locate"].includes(sourceP))value=value.replace(/↵|\r\n|\n|\r/g,"");if(["init","update","virtual"].includes(sourceP))value=value.replace(/↵|\r\n|\n|\r/g,"\\n");if(typeof IS_PROCESS_SERVER!=="undefined")value=value.replace(/↵|\r\n|\n|\r/g,"<br>");fields[val.fieldId]=value}if(typeof value==="object"&&var_Arr.length>1){value=Array.isArray(value)||var_Arr[key+1]?.value?.includes(".")?JSON.stringify(value):`(${JSON.stringify(value)})`}if(!val.type==="exp"&&sourceP!=="exp"&&typeof value==="string"&&value.startsWith("@")){warning=`Error encoding ${value}`;var_error_found=true;return"0"}return value});ret=res.length===1?res[0]:res.join("");if(var_Arr.some(v=>v.type==="exp")&&sourceP!=="exp"&&!secondPassP){const exp=await func.expression.get(SESSION_ID,ret,dsSessionP,sourceP,rowIdP,sourceActionP,true,calling_fieldIdP,fields,debug_infoP);ret=exp.res?.[0]??exp.result;Object.assign(fields,exp.fields)}else if(!secondPassP&&!["arguments","api_rendered_output","DbQuery"].includes(sourceP)){ret=await func.expression.secure_eval(SESSION_ID,sourceP,ret,jobNo,dsSessionP,js_script_callback)}else if(sourceP==="DbQuery"){ret=JSON.stringify(evalJson(ret))}if(typeof ret==="string"&&ret.startsWith("@")){error="Error encoding @ var";var_error_found=true}}catch(err){error=err.message}return endResults()};func.expression.parse=function(strP){var extract_str=function(strP,posP){if(!posP)posP=0;var clean_split_str=function(arrP){var arr=[];if(arrP&&arrP.length>1&&arrP[0]===""&&arrP[1].indexOf("@")>-1){for(var i=1;i<=arrP.length;i++){arr.push(arrP[i])}return arr}else return arrP};var nonLettersPatt=/\W/;var validSymbolsNoArray=/[^.@\[]/;var validSymbolsWithArray=/[^.@"'\[\]]/;var validSymbols=validSymbolsNoArray;var splitTmp=strP.replace(/@/g,"^^@").split("^^");var split=clean_split_str(splitTmp);var obj=[];if(split){for(let val of split){if(val){var pos=strP.indexOf(val);if(val&&val.substr(0,1)==="@"){var tmpStr="";var word_start_pos=undefined;var word_end_pos=undefined;for(var i=0;i<=val.length;i++){var key1=i;var val1=val.substr(i,1);if(val1==="."&&!word_start_pos)word_start_pos=key1;if(word_start_pos&&key1>word_start_pos&&nonLettersPatt.test(val1))word_end_pos=key1;if(word_start_pos&&word_start_pos>=0&&word_end_pos&&word_end_pos>=0){var word=val.substr(word_start_pos+1,word_end_pos-word_start_pos-1);tmpStr=tmpStr.substr(0,word_start_pos)+"^^"+tmpStr.substr(word_start_pos,word_end_pos);if(val.substr(word_end_pos,1)===".")word_start_pos=word_end_pos;else word_start_pos=null;word_end_pos=null}if(val1==="[")validSymbols=validSymbolsWithArray;if(nonLettersPatt.test(val1)&&validSymbols.test(val1)&&tmpStr.indexOf("^^")===-1){tmpStr+="^^"+val1}else tmpStr+=val1}if(tmpStr.indexOf("^^")>-1){var obj1=extract_str(tmpStr,pos);obj=obj.concat(obj1)}else{var fieldId=undefined;if(val){fieldId=val.substr(1,val.length);if(val.indexOf(".")>-1)fieldId=val.substr(1,val.indexOf(".")-1);if(val.indexOf("[")>-1)fieldId=val.substr(1,val.indexOf("[")-1)}obj.push({value:val,fieldId:fieldId,pos:pos+posP})}}else{obj.push({value:val,pos:pos+posP})}}}return obj}};var res=extract_str(strP);return res};func.expression.parse_bad=function(input){if(typeof input!=="string")return[];const segments=[];let pos=0;const parts=input.split(/(@\w+)/).filter(Boolean);for(const part of parts){if(part.startsWith("@")){const fieldId=part.slice(1);segments.push({value:part,fieldId:fieldId,pos:pos})}else{segments.push({value:part,pos:pos})}pos+=part.length}return segments};func.expression.get_property=async function(valP){async function secure_eval(val){if(typeof IS_PROCESS_SERVER==="undefined"){try{return eval(val)}catch(err){console.error(err);return}}try{let vm=new VM.VM({sandbox:{func:func,SESSION_ID:SESSION_ID,SESSION_OBJ:{[`${SESSION_ID}`]:SESSION_OBJ[SESSION_ID]}},timeout:1e3,allowAsync:false});return await vm.run(val)}catch(err){throw""}}var property1,property2;if(valP.indexOf("[")>-1&&valP.indexOf("]")>-1){property1=valP.substr(valP.indexOf("[")+1,valP.indexOf("]")-valP.indexOf("[")-1);property1=await secure_eval(property1)}if(valP.indexOf(".")>-1)property2=valP.substr(valP.indexOf(".")+1,valP.length);return{property1:property1,property2:property2}};func.expression.get_property_bad=async function(valP){if(typeof valP!=="string")return{property1:undefined,property2:undefined};const secureEval=async expr=>{if(typeof IS_PROCESS_SERVER==="undefined"){try{return eval(expr)}catch(err){console.error(err);return undefined}}try{const vm=new VM.VM({sandbox:{func:func,SESSION_ID:SESSION_ID,SESSION_OBJ:{[SESSION_ID]:SESSION_OBJ[SESSION_ID]}},timeout:1e3,allowAsync:false});return await vm.run(expr)}catch{return undefined}};let property1,property2;const bracketStart=valP.indexOf("[");const bracketEnd=valP.indexOf("]");if(bracketStart>-1&&bracketEnd>bracketStart){const expr=valP.slice(bracketStart+1,bracketEnd);property1=await secureEval(expr)}const dotIndex=valP.indexOf(".");if(dotIndex>-1){property2=valP.slice(dotIndex+1)}return{property1:property1,property2:property2}};func.expression.validate_constant=function(valP){var patt=/["']/;if(typeof valP==="string"&&patt.test(valP.substr(0,1))&&patt.test(valP.substr(0,valP.length-1)))return true;else return false};func.expression.validate_variables=function(valP){if(typeof valP==="string"&&valP.indexOf("@")>-1)return true;else return false};func.expression.remove_quotes=function(valP){if(func.expression.validate_constant(valP))return valP.substr(1,valP.length-2);else return valP};func.expression.validate_constant_bad=valP=>typeof valP==="string"&&/^["'].*["']$/.test(valP);func.expression.validate_variables_bad=valP=>typeof valP==="string"&&valP.includes("@");func.expression.remove_quotes_bad=valP=>func.expression.validate_constant(valP)&&typeof valP==="string"?valP.slice(1,-1):valP;func.expression.secure_eval=async function(SESSION_ID,sourceP,val,job_id,dsSessionP,js_script_callback,evt){const api_utils=await func.common.get_module(SESSION_ID,"xuda-api-library.mjs",{func:func,glb:glb,SESSION_OBJ:SESSION_OBJ,SESSION_ID:SESSION_ID,APP_OBJ:APP_OBJ,dsSession:dsSessionP,job_id:job_id});const xu=api_utils;if(typeof IS_PROCESS_SERVER==="undefined"&&typeof IS_DOCKER==="undefined"){try{return eval(val)}catch(err){try{return JSON5.parse(val)}catch(err){return val}}}if(sourceP==="javascript"){process.on("uncaughtException",err=>{console.error("Asynchronous error caught.",err);func.events.delete_job(SESSION_ID,job_id);if(typeof IS_PROCESS_SERVER!=="undefined"||typeof IS_DOCKER!=="undefined"){if(SESSION_OBJ[SESSION_ID].crawler)return;return __.rpi.write_log(SESSION_OBJ[SESSION_ID].app_id,"error","worker","vm error",err,null,val,"func.expression.get.secure_eval")}});try{const dir=path.join(_conf.studio_drive_path,SESSION_OBJ[SESSION_ID].app_id,"node_modules","/");const script=new VM.VMScript(`try{${val}}catch(e){func.api.error(SESSION_ID, "nodejs error", e); console.error(e); func.events.delete_job(SESSION_ID, job_id);}`,{filename:dir,dirname:dir});let vm=new VM.NodeVM({require:{external:true},sandbox:{func:func,xu:xu,SESSION_ID:SESSION_ID,SESSION_OBJ:{[`${SESSION_ID}`]:SESSION_OBJ[SESSION_ID]},callback:js_script_callback,job_id:job_id,axios:axios,got:got,FormData:FormData},timeout:6e4});return await vm.run(script,{filename:dir,dirname:dir})}catch(err){console.error("Failed to execute script.",err);if(typeof IS_PROCESS_SERVER!=="undefined"){func.events.delete_job(SESSION_ID,jobNo);return __.db.add_error_log(SESSION_OBJ[SESSION_ID].app_id,"api",err)}}}else{try{try{let vm=new VM.VM({sandbox:{xu:xu,func:func,SESSION_ID:SESSION_ID,SESSION_OBJ:{[`${SESSION_ID}`]:SESSION_OBJ[SESSION_ID]},callback:js_script_callback,job_id:job_id},timeout:1e3,allowAsync:false});let ret=val;if(typeof val==="string"){ret=await vm.run(val)}return ret}catch(err){throw""}}catch(err){try{return JSON5.parse(val)}catch(err){return val}}}};func.expression.secure_eval_bad=async function(SESSION_ID,sourceP,val,job_id,dsSessionP,js_script_callback,evt){if(typeof val!=="string")return val;const xu=await func.common.get_module(SESSION_ID,"xuda-api-library.mjs",{func:func,glb:glb,SESSION_OBJ:SESSION_OBJ,SESSION_ID:SESSION_ID,APP_OBJ:APP_OBJ,dsSession:dsSessionP,job_id:job_id});const isServer=typeof IS_PROCESS_SERVER!=="undefined"||typeof IS_DOCKER!=="undefined";if(!isServer){try{return eval(val)}catch{try{return JSON5.parse(val)}catch{return val}}}const sandbox={func:func,xu:xu,SESSION_ID:SESSION_ID,SESSION_OBJ:{[SESSION_ID]:SESSION_OBJ[SESSION_ID]},callback:js_script_callback,job_id:job_id,...sourceP==="javascript"?{axios:axios,got:got,FormData:FormData}:{}};const handleError=err=>{console.error("Execution error:",err);func.events.delete_job(SESSION_ID,job_id);if(isServer&&!SESSION_OBJ[SESSION_ID].crawler){if(sourceP==="javascript"){__.rpi.write_log(SESSION_OBJ[SESSION_ID].app_id,"error","worker","vm error",err,null,val,"func.expression.get.secure_eval")}else{__.db.add_error_log(SESSION_OBJ[SESSION_ID].app_id,"api",err)}}return val};if(sourceP==="javascript"){process.on("uncaughtException",handleError);try{const dir=path.join(_conf.studio_drive_path,SESSION_OBJ[SESSION_ID].app_id,"node_modules");const script=new VM.VMScript(`try { ${val} } catch (e) { func.api.error(SESSION_ID, "nodejs error", e); console.error(e); func.events.delete_job(SESSION_ID, "${job_id}"); }`,{filename:dir,dirname:dir});const vm=new VM.NodeVM({require:{external:true},sandbox:sandbox,timeout:6e4});return await vm.run(script,{filename:dir,dirname:dir})}catch(err){return handleError(err)}}try{const vm=new VM.VM({sandbox:sandbox,timeout:1e3,allowAsync:false});return await vm.run(val)}catch{try{return JSON5.parse(val)}catch{return val}}}; export default {
5
+ })(document.querySelector(\`[xu-ui-id=${elementP}]\`),evt)`,true,null,null,evt);await func.datasource.set_outputField(SESSION_ID,dsSessionP,result,args);return result},loader_on:async function(){glb.CURRENT_APP_LOADING=null;LOADER_ACTIVE=true;LOADER_TEXT=descP;func.events.delete_job(SESSION_ID,jobNoP)},loader_off:async function(){LOADER_ACTIVE=false;func.events.delete_job(SESSION_ID,jobNoP)},emit_event:async function(){if(refIdP.value){$(document).trigger(refIdP.value,[_session.DS_GLB[dsSession]])}else{func.utils.debug_report(SESSION_ID,"func.events.execute","Event name missing","E")}func.events.delete_job(SESSION_ID,jobNoP)},invoke_action:async function(){func.utils.debug.watch(SESSION_ID,calling_trigger_prop?.id,functionP,null,null,expCond);await func.action.execute(SESSION_ID,refIdP.value,_ds,null,null,jobNoP,containerP)},raise_event:async function(){var _ds=_session.DS_GLB[dsSession];const _view_obj=await func.utils.VIEWS_OBJ.get(SESSION_ID,_ds.prog_id);if(callingSourceP==="grid"||callingSourceP==="form"){let _field_obj=func.common.find_item_by_key(_view_obj.progFields,"field_id",field_elm);var event_name=_field_obj?.triggers?.[eventIdP].name.event;if(_field_obj?.triggers?.[eventIdP].name?.properties["xu-exp:event"]){event_name=(await func.expression.get(SESSION_ID,props[`xu-exp:event`],dsSession,"event_name expression")).result}if(field_elm&&event_name){const dsP=await func.datasource.find_event_dataSource(SESSION_ID,event_name,dsSession);return await func.datasource.run_events_functions(SESSION_ID,dsP,event_name,jobNoP,null,calling_trigger_prop?.data?.name?.parameters||{})}}if(callingSourceP.includes("event")){let event_name=refIdP.event;if(refIdP?.properties?.["xu-exp:event"]){event_name=(await func.expression.get(SESSION_ID,refIdP.properties["xu-exp:event"],dsSession,"event_name expression")).result}const dsP=await func.datasource.find_event_dataSource(SESSION_ID,event_name,dsSession);await func.datasource.run_events_functions(SESSION_ID,dsP,event_name,jobNoP,calling_trigger_prop?.props?.async,calling_trigger_prop?.data?.name?.parameters||{})}func.events.delete_job(SESSION_ID,jobNoP);func.utils.debug.watch(SESSION_ID,calling_trigger_prop?.id,functionP,"","",expCond)},get_data:async function(){const params_obj=await get_params_obj();if(!await get_prog_id()){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} > ${triggerP} > ${functionP} > program ${prog} is missing`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}var _ds=_session.DS_GLB[dsSession];if(!_ds){func.events.delete_job(SESSION_ID,jobNoP);return}if(_ds){func.utils.debug.watch(SESSION_ID,calling_trigger_prop?.id,functionP,null,calling_trigger_prop,expCond);const ret=await func.datasource.create(SESSION_ID,await get_prog_id(),args.dataSourceNoP,args.parentDataSourceNoP,args.containerIdP,args.rowIdP,args.jobNoP,args.calling_trigger_prop,null,null,args.callingSourceP,args.calling_jobP,args.screen_dsP,args.is_panelP,params_obj);let _ds_new=_session.DS_GLB[ret.dsSessionP];let parameters=args?.calling_trigger_prop?.data?.name?.parameters;if(parameters&&!_.isEmpty(parameters)){await func.datasource.update_changes_for_out_parameter(SESSION_ID,_ds_new.dsSession,_ds.dsSession)}func.events.delete_job(SESSION_ID,jobNoP);return _ds_new}},set_data:async function(){return this.get_data()},batch:async function(){const result=await this.get_data();return result},update:async function(){const obj_values_to_update=func.datasource.get_viewFields_for_update_function(SESSION_ID,calling_trigger_prop,null,dsSessionP);if(!obj_values_to_update||_.isEmpty(obj_values_to_update)){func.utils.debug_report(SESSION_ID,"Update values object is empty","","W");if(jobNoP)func.events.delete_job(SESSION_ID,jobNoP);return}var updates=[];for await(const[key,val]of Object.entries(obj_values_to_update)){var $element;if(elementP){$element=$(`[xu-ui-id="${elementP}"]`).clone(true)}let ret_field_id=await func.expression.get(SESSION_ID,val.id.trim(),dsSessionP,"update",null,null,null,null,null,null,$element?.length?$element?.data()?.xuData?.iterate_info:null);let ret_value=await func.expression.get(SESSION_ID,val.val.trim(),dsSessionP,"update",null,null,null,null,null,null,$element?.length?$element?.data()?.xuData?.iterate_info:null);let _field_id=ret_field_id.result;let _value=ret_value.result;updates.push({_field_id:_field_id,_value:_value})}let datasource_changes={};for await(const change of updates){let ret_get_value=await func.datasource.get_value(SESSION_ID,change._field_id,dsSessionP);if(ret_get_value.found){let _ds=_session.DS_GLB[ret_get_value.dsSessionP];if(!datasource_changes[_ds.dsSession]){datasource_changes[_ds.dsSession]={}}if(!datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]){datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]={}}datasource_changes[_ds.dsSession][ret_get_value.currentRecordId][change._field_id]=change._value}}await func.datasource.update(SESSION_ID,datasource_changes);if(jobNoP)func.events.delete_job(SESSION_ID,jobNoP)},call_alert:async function(){await func.utils.alerts.invoke(SESSION_ID,"call_alert",refIdP,log_source,dsSession);func.events.delete_job(SESSION_ID,jobNoP)},alert:async function(){await func.utils.alerts.invoke(SESSION_ID,"alert",refIdP,log_source,dsSession);func.events.delete_job(SESSION_ID,jobNoP)},delay:async function(){return new Promise(resolve=>{setTimeout(function(){if(jobNoP)func.events.delete_job(SESSION_ID,jobNoP);resolve()},refIdP.value)})},comment:async function(){if(jobNoP)func.events.delete_job(SESSION_ID,jobNoP)},call_project_api:async function(){const params_obj=await get_params_obj();const _prog_id=await get_prog_id();if(!_prog_id){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} > ${triggerP} > ${functionP} > program not defined`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}const api_ret=await func.api.call_project_api(_prog_id,params_obj);await func.datasource.set_outputField(SESSION_ID,dsSessionP,api_ret,args);func.events.delete_job(SESSION_ID,jobNoP)},call_system_api:async function(){const api_method=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"api_method");if(!api_method){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} >${triggerP} >${functionP} > api_method not defined`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}let payload={};const _payload=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"payload");if(_payload){const get_payload_property_value=async function(prop_name){let _prop=_payload;let _value=_prop[prop_name];if(_prop?.[`xu-exp:${prop_name}`]){_value=(await func.expression.get(SESSION_ID,_prop[`xu-exp:${prop_name}`],dsSession,`${prop_name} expression`)).result}return _value};for await(let[key,val]of Object.entries(_payload)){const new_key=key.replaceAll("xu-exp:","");payload[new_key]=await get_payload_property_value(new_key)}}const output_field=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"outputField");const api_ret=await func.api.call_system_api(api_method,payload);if(output_field){let datasource_changes={};let ret_get_value=await func.datasource.get_value(SESSION_ID,output_field,dsSessionP);if(ret_get_value.found){let _ds=_session.DS_GLB[ret_get_value.dsSessionP];if(!datasource_changes[_ds.dsSession]){datasource_changes[_ds.dsSession]={}}if(!datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]){datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]={}}datasource_changes[_ds.dsSession][ret_get_value.currentRecordId][output_field]=api_ret;await func.datasource.update(SESSION_ID,datasource_changes)}}func.events.delete_job(SESSION_ID,jobNoP)},call_external_api:async function(){const method=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"method");if(!method){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} >${triggerP} >${functionP} > method not defined`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}const url=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"url");if(!url){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} >${triggerP} >${functionP} > url not defined`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}const payload_arr=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"payload");const report_conversion_error=function(res,typeP,valP){var msg=`${elementP} >${triggerP} >${functionP} > error converting from ${valP} to ${typeP}`;if(error){return func.utils.debug_report(SESSION_ID,msg,"","W")}func.utils.debug_report(SESSION_ID,msg+" "+_.capitalize(source)+prog_info,"","E")};const report_conversion_warn=function(res){var msg=`${elementP} >${triggerP} >${functionP} > type mismatch auto conversion from value ${valP} to ${typeP}`;func.utils.debug_report(SESSION_ID,msg+" "+_.capitalize(source)+prog_info,"","W")};if(error){return report_conversion_error()}const module=await func.common.get_module(SESSION_ID,"xuda-get-cast-util-module.mjs");var payload=_.reduce(payload_arr,(ret,val,key)=>{ret[val.key]=module.cast(val.type,val.val,report_conversion_error,report_conversion_warn);return ret},{});const output_field=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"outputField");const api_ret=await func.api.call_external_api(method,url,payload);if(output_field){let datasource_changes={};let ret_get_value=await func.datasource.get_value(SESSION_ID,output_field,dsSessionP);if(ret_get_value.found){let _ds=_session.DS_GLB[ret_get_value.dsSessionP];if(!datasource_changes[_ds.dsSession]){datasource_changes[_ds.dsSession]={}}if(!datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]){datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]={}}datasource_changes[_ds.dsSession][ret_get_value.currentRecordId][output_field]=api_ret;await func.datasource.update(SESSION_ID,datasource_changes)}}func.events.delete_job(SESSION_ID,jobNoP)}};return await fx[functionP]()};func.events.delete_job=function(SESSION_ID,jobNoP){var _session=SESSION_OBJ[SESSION_ID];var job_index=func.events.find_job_index(SESSION_ID,jobNoP);if(!_session.WORKER_OBJ.jobs[job_index]){_session.WORKER_OBJ.stat=null;return}var dsSession=_session.WORKER_OBJ.jobs[job_index].dsSessionP;let ds_obj=_session?.DS_GLB[dsSession];if(ds_obj){delete SCREEN_BLOCKER_OBJ[ds_obj.screenId+(ds_obj.callingScreenId?"_"+ds_obj.callingScreenId:"")]}if(dsSession&&ds_obj?.loops_limit&&ds_obj?.loops_count<ds_obj?.loops_limit-1){return}_session.WORKER_OBJ.stat=null;_session.WORKER_OBJ.jobs.splice(job_index,1)};func.events.delete_job_0=function(SESSION_ID){var job_index=0;var _session=SESSION_OBJ[SESSION_ID];if(!_session.WORKER_OBJ.jobs[job_index]){_session.WORKER_OBJ.stat=null;return}var dsSession=_session.WORKER_OBJ.jobs[job_index].dsSession;let ds_obj=_session?.DS_GLB[dsSession];if(ds_obj){delete SCREEN_BLOCKER_OBJ[ds_obj.screenId+(ds_obj.callingScreenId?"_"+ds_obj.callingScreenId:"")]}if(dsSession&&ds_obj&&ds_obj.loops_limit&&ds_obj.loops_count<ds_obj.loops_limit-1){return}_session.WORKER_OBJ.stat=null;_session.WORKER_OBJ.jobs.splice(job_index,1)};func.events.check_jobs_idle=async function(SESSION_ID,jobsP){return new Promise((resolve,reject)=>{var _session=SESSION_OBJ[SESSION_ID];if(!jobsP||jobsP&&jobsP.length===0){resolve();return}var listener=setInterval(function(){var found;for(const[key,val]of Object.entries(jobsP)){_.forEach(_session.WORKER_OBJ.jobs,function(val2,key2){if(key2===val){found=true;return false}})}if(!found){do_callback();return}},100);var do_callback=function(){window.clearInterval(listener);resolve()}})};var loop_detected_obj={};setInterval(function(){loop_detected_obj={}},1e3);func.events.set_browser_changes=function(dsP,fieldsChangedP){if(fieldsChangedP.includes("SYS_GLOBAL_STR_BROWSER_TITLE"))document.title=dsP.dataset_new["SYS_GLOBAL_STR_BROWSER_TITLE"]};func.events.execute_PENDING_OPEN_URL_EVENTS=async function(){for(let[key,url]of Object.entries(PENDING_OPEN_URL_EVENTS)){if(url){glb.WINDOW_LOCATION_SEARCH=url;glb.ROOT_ELEMENT_ATTRIBUTES=func.UI.utils.get_root_element_attributes();const params_obj=func.common.getObjectFromUrl(url,glb.ROOT_ELEMENT_ATTRIBUTES);if(!params_obj.prog){return console.warn("prog empty")}await func.utils.TREE_OBJ.get(SESSION_ID,params_obj.prog);let screen_ret=await func.utils.get_screen_obj(SESSION_ID,params_obj.prog);if(screen_ret){await func.UI.screen.init(SESSION_ID,params_obj.prog,null,null,$("#embed_"+SESSION_ID),null,null,null,null,null,"pendingUrlEvent_embed")}else{console.error("Program not exist",params_obj.prog_id);func.UI.utils.progressScreen.show(SESSION_ID,"Program not exist",null,true)}}else{console.warn("url empty")}}};func.events.invoke=async function(event_id){var _session=SESSION_OBJ[SESSION_ID];if(!event_id){console.warn("event_id Cannot be empty");return false}var ds;for await(const[ds_key,val]of Object.entries(_session.DS_GLB)){const _view_obj=await func.utils.VIEWS_OBJ.get(SESSION_ID,val.prog_id);if(_.isEmpty(_view_obj.progEvents))continue;if(ds)break;for await(const[key,val]of Object.entries(_view_obj.progEvents)){if(val?.data?.type==="user_defined"&&val.data.event_name===event_id){ds=ds_key;break}}}if(!ds){console.warn("event_id not found");return false}func.events.validate(SESSION_ID,"user_defined",ds,event_id)};func.expression={};func.expression.get=async function(SESSION_ID,valP,dsSessionP,sourceP,rowIdP,sourceActionP,secondPassP,calling_fieldIdP,fieldsP,debug_infoP,iterate_info,js_script_callback,jobNo,api_output_type){class xu_class{async get(){var ret;var fields={};var error;var warning;function evalJson(text){return eval("("+text+")")}if(valP===null){ret=""}else{switch(typeof valP){case"string":ret=valP;break;case"undefined":ret="";break;case"boolean":ret=valP?"Y":"N";break;default:ret=valP.toString();break}}ret=ret.replace(/\&amp;/g,"&");ret=func.utils.replace_studio_drive_url(SESSION_ID,ret);const end_results=function(){const replace_quotes=function(ret){for(const[key,val]of Object.entries(fields)){if(typeof val==="string")ret=ret.replace('"'+val+'"',val.replace(/"/gi,""))}return ret};if(["update","javascript"].includes(sourceP)){if(typeof ret==="string")ret=replace_quotes(ret)}const log_error=function(){if(SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP]){func.utils.debug.log(SESSION_ID,SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP].nodeId,{module:"expression",action:sourceP,source:calling_fieldIdP,prop:ret,details:ret,result:ret,error:error,warning:warning,fields:null,type:"exp",prog_id:SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP].prog_id,debug_info:debug_infoP})}};if(error)log_error();return{result:ret,fields:fields,res:res,explain:result,error:error,warning:warning,req:valP,var_error_found:var_error_found}};const variable_not_exist=async function(){try{if(sourceP!=="arguments"){if(ret&&ret.substr(0,6)==="_DATE_"){ret=ret.substr(6)}else if(ret&&ret.length===10&&ret.substr(4,1)==="-"&&ret.substr(7,1)==="-"||ret==="self"){ret=ret}else{ret=await func.expression.secure_eval(SESSION_ID,sourceP,ret,jobNo,dsSessionP,js_script_callback)}return end_results()}else{ret=ret.replace(/_NULL/gi,"");return end_results()}}catch(err){return end_results()}};if(!func.expression.validate_variables(valP)){return await variable_not_exist()}const validate_email=async function(){const ret=await func.expression.secure_eval(SESSION_ID,sourceP,valP,jobNo,dsSessionP,js_script_callback);return glb.emailRegex.test(ret)};if(await validate_email()){return await variable_not_exist()}var var_Arr=[];const split=func.expression.parse(ret)||[];for await(const[arr_key,val]of Object.entries(split)){const key=Number(arr_key);var_Arr[key]={};var_Arr[key].value=val.value;const replace_value_in_string=async function(retP,fieldIdP){if(iterate_info?.iterator_key===fieldIdP||iterate_info?.iterator_val===fieldIdP){if(iterate_info.iterator_key===fieldIdP){retP.value=iterate_info._key}if(iterate_info.iterator_val===fieldIdP){retP.value=iterate_info._val}}const set_value=function(valP){if(typeof valP!=="undefined"){var_Arr[key].value=valP;if(typeof valP==="string")var_Arr[key].type="string"}else{if(retP.type==="object"){var_Arr[key].value="";var_Arr[key].type="string"}}};if(sourceP==="exp"&&retP.type!=="exp"){var_Arr[key].type=retP.type;return}if(typeof retP.value!=="undefined"){var_Arr[key].type=retP.type;var_Arr[key].value=retP.value;if(val.value.indexOf("[")>-1|val.value.indexOf(".")>-1){var data=retP.prop;if(retP.type==="object")data=retP.value;var property1,property2;if(val.value.indexOf("[")===-1&&val.value.indexOf("]")>-1&&val.value.substr(0,1)==="@"){var prevData=var_Arr[key-1].value;var_Arr[key].value=prevData[data];if(val.value.indexOf(".")>-1){property2=await func.expression.get_property(val.value).property2;if(prevData[data])set_value(prevData[data][property2])}delete var_Arr[key-1]}else{property1=await func.expression.get_property(val.value).property1;property2=await func.expression.get_property(val.value).property2;if(property1){var_Arr[key].value=data[property1];if(property2){if(data[property1])set_value(data[property1][property2])}}if(property2&&!property1){if(data){set_value(data[property2])}}}fields[fieldIdP]=var_Arr[key].value;var_Arr[key].fieldId=fieldIdP}else{fields[fieldIdP]=var_Arr[key].value;var_Arr[key].fieldId=fieldIdP}}};if(val.fieldId){if(val.fieldId&&val.fieldId.substr(0,5)==="_THIS"&&calling_fieldIdP&&(val.fieldId.length===5||val.fieldId.length>5&&val.fieldId.substr(5,1)===".")){if(val.fieldId.length===5)val.fieldId=calling_fieldIdP;else val.fieldId=calling_fieldIdP+val.fieldId(5,val.fieldId.length-1)}if(!sourceP==="exp"){var_Arr[key].value='""'}fields[val.fieldId]=var_Arr[key].value;const ret=await func.datasource.get_value(SESSION_ID,val.fieldId,dsSessionP,rowIdP);await replace_value_in_string(ret.ret,ret.fieldIdP)}}try{var res=[];var exp_exist;var var_error_found;_.forEach(var_Arr,function(val,key){if(sourceP==="UI Property EXP"){let ret=func.utils.get_drive_url(SESSION_ID,val.value,true);if(ret.changed){res[key]=ret.value;return true}}if(sourceP==="UI Attr EXP"){let ret=func.utils.get_drive_url(SESSION_ID,val.value,var_Arr.length==1?false:true);if(ret.changed){res[key]=ret.value;return true}}if(val.type==="exp"){exp_exist=true}res[key]=val.value;if(var_Arr.length>1){if(!["DbQuery","alert","exp","api_rendered_output"].includes(sourceP)&&["string","date"].includes(val.type)){res[key]="`"+val.value+"`"}if(["api_rendered_output"].includes(sourceP)&&["json"].includes(api_output_type)&&["string","date"].includes(val.type)){res[key]=`"`+val.value+`"`}}if(val.fieldId&&val.value&&typeof val.value==="string"){if(["query","condition","range","sort","locate"].includes(sourceP)){if(val.value.indexOf("↵")>-1){res[key]=val.value.split("↵").join("")}res[key]=res[key].replace(/(\r\n|\n|\r)/gm,"")}if(["init","update","virtual"].includes(sourceP)){if(val.value.indexOf("↵")>-1)res[key]=val.value.split("↵").join("\n");res[key]=res[key].replace(/(\r\n|\n|\r)/gm,"\\n")}if(typeof IS_PROCESS_SERVER!=="undefined"){res[key]=res[key].replace(/(\r\n|\n|\r)/gm,"<br>")}fields[val.fieldId]=res[key]}if(typeof val.value==="object"&&var_Arr.length>1){if(!Array.isArray(val.value)&&!var_Arr[key+1].value?.includes(".")){res[key]="("+JSON.stringify(val.value)+")"}else{res[key]=JSON.stringify(val.value)}}if(!exp_exist&&sourceP!=="exp"&&val.value&&typeof val.value==="string"&&val.value.substr(0,1)==="@"){warning="Error encoding "+val.value;var_error_found=true;res[key]=0}});const join=function(arrP){return arrP.join("")};var exp=undefined;if(exp_exist&&sourceP!=="exp"){exp=await func.expression.get(SESSION_ID,join(res),dsSessionP,sourceP,rowIdP,sourceActionP,true,calling_fieldIdP,fields,debug_infoP);if(exp.res)res=exp.res;else res=[exp.result];fields=_.assignIn(exp.fields,fieldsP)}var result=join(res);if(res.length===1){result=res[0]}if(secondPassP){ret=result}else if(sourceP!=="exp"){if(res.length===1&&typeof res[0]==="string"&&typeof res[0]!=="object"){ret=join(res);if(ret&&ret.substr(0,1)==="@"){error="Error encoding @ var";var_error_found=true}}else{if(!["arguments","api_rendered_output","DbQuery"].includes(sourceP)){ret=await func.expression.secure_eval(SESSION_ID,sourceP,result,jobNo,dsSessionP,js_script_callback)}else{if(sourceP==="DbQuery"){ret=JSON.stringify(evalJson(result))}else{ret=result}}}}return end_results()}catch(err){ret=result;error=err.message;return end_results()}}}const new_class=new xu_class;return new_class.get()};func.expression.get_bad=async function(SESSION_ID,valP,dsSessionP,sourceP,rowIdP,sourceActionP,secondPassP,calling_fieldIdP,fieldsP={},debug_infoP,iterate_info,js_script_callback,jobNo,api_output_type){const evalJson=text=>eval(`(${text})`);const replaceQuotes=str=>{for(const[key,val]of Object.entries(fields)){if(typeof val==="string")str=str.replace(`"${val}"`,val.replace(/"/g,""))}return str};let ret,error,warning,var_error_found;const fields={...fieldsP};if(valP===null||typeof valP==="undefined")ret="";else if(typeof valP==="boolean")ret=valP?"Y":"N";else ret=valP.toString();ret=ret.replace(/\&/g,"&");ret=func.utils.replace_studio_drive_url(SESSION_ID,ret);const endResults=()=>{if(["update","javascript"].includes(sourceP)&&typeof ret==="string"){ret=replaceQuotes(ret)}if((error||warning)&&SESSION_OBJ[SESSION_ID]?.DS_GLB[dsSessionP]){func.utils.debug.log(SESSION_ID,SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP].nodeId,{module:"expression",action:sourceP,source:calling_fieldIdP,prop:ret,details:ret,result:ret,error:error,warning:warning,fields:null,type:"exp",prog_id:SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP].prog_id,debug_info:debug_infoP})}return{result:ret,fields:fields,error:error,warning:warning,req:valP,var_error_found:var_error_found}};const handleNonVariable=async()=>{try{if(sourceP!=="arguments"){if(ret.startsWith("_DATE_"))ret=ret.slice(6);else if(/^\d{4}-\d{2}-\d{2}$/.test(ret)||ret==="self")return endResults();else ret=await func.expression.secure_eval(SESSION_ID,sourceP,ret,jobNo,dsSessionP,js_script_callback)}else{ret=ret.replace(/_NULL/gi,"")}return endResults()}catch(err){error=err.message;return endResults()}};if(!func.expression.validate_variables(valP))return await handleNonVariable();if(glb.emailRegex.test(await func.expression.secure_eval(SESSION_ID,sourceP,valP,jobNo,dsSessionP,js_script_callback))){return await handleNonVariable()}const split=func.expression.parse(ret)||[];const var_Arr=await Promise.all(split.map(async(val,key)=>{const result={value:val.value,fieldId:val.fieldId};if(!val.fieldId)return result;if(val.fieldId.startsWith("_THIS")&&calling_fieldIdP){result.fieldId=val.fieldId.length===5?calling_fieldIdP:calling_fieldIdP+val.fieldId.slice(5)}const{ret:fetchedValue,fieldIdP}=await func.datasource.get_value(SESSION_ID,result.fieldId,dsSessionP,rowIdP);result.value=fetchedValue?.value??(sourceP==="exp"?fetchedValue?.value:'""');result.type=fetchedValue?.type;if(iterate_info){if(iterate_info.iterator_key===fieldIdP)result.value=iterate_info._key;if(iterate_info.iterator_val===fieldIdP)result.value=iterate_info._val}if(val.value.includes("[")||val.value.includes(".")){const{property1,property2}=await func.expression.get_property(val.value);const data=fetchedValue?.type==="object"?fetchedValue.value:fetchedValue?.prop;if(key>0&&val.value.includes("]")&&!val.value.includes("[")&&split[key-1].value){const prevData=split[key-1].value;result.value=prevData[fieldIdP];if(val.value.includes(".")&&prevData[fieldIdP]){result.value=prevData[fieldIdP][property2]??""}}else if(data){if(property1)result.value=data[property1]??"";if(property2)result.value=(property1?data[property1]?.[property2]:data[property2])??""}}fields[fieldIdP]=result.value;return result}));try{const res=var_Arr.map((val,key)=>{if(sourceP==="UI Property EXP"||sourceP==="UI Attr EXP"){const{changed,value}=func.utils.get_drive_url(SESSION_ID,val.value,sourceP==="UI Attr EXP"&&var_Arr.length>1);if(changed)return value}let value=val.value;if(var_Arr.length>1){if(!["DbQuery","alert","exp","api_rendered_output"].includes(sourceP)&&["string","date"].includes(val.type)){value=`\`${value}\``}else if(sourceP==="api_rendered_output"&&api_output_type==="json"&&["string","date"].includes(val.type)){value=`"${value}"`}}if(val.fieldId&&typeof value==="string"){if(["query","condition","range","sort","locate"].includes(sourceP))value=value.replace(/↵|\r\n|\n|\r/g,"");if(["init","update","virtual"].includes(sourceP))value=value.replace(/↵|\r\n|\n|\r/g,"\\n");if(typeof IS_PROCESS_SERVER!=="undefined")value=value.replace(/↵|\r\n|\n|\r/g,"<br>");fields[val.fieldId]=value}if(typeof value==="object"&&var_Arr.length>1){value=Array.isArray(value)||var_Arr[key+1]?.value?.includes(".")?JSON.stringify(value):`(${JSON.stringify(value)})`}if(!val.type==="exp"&&sourceP!=="exp"&&typeof value==="string"&&value.startsWith("@")){warning=`Error encoding ${value}`;var_error_found=true;return"0"}return value});ret=res.length===1?res[0]:res.join("");if(var_Arr.some(v=>v.type==="exp")&&sourceP!=="exp"&&!secondPassP){const exp=await func.expression.get(SESSION_ID,ret,dsSessionP,sourceP,rowIdP,sourceActionP,true,calling_fieldIdP,fields,debug_infoP);ret=exp.res?.[0]??exp.result;Object.assign(fields,exp.fields)}else if(!secondPassP&&!["arguments","api_rendered_output","DbQuery"].includes(sourceP)){ret=await func.expression.secure_eval(SESSION_ID,sourceP,ret,jobNo,dsSessionP,js_script_callback)}else if(sourceP==="DbQuery"){ret=JSON.stringify(evalJson(ret))}if(typeof ret==="string"&&ret.startsWith("@")){error="Error encoding @ var";var_error_found=true}}catch(err){error=err.message}return endResults()};func.expression.parse_org=function(strP){var extract_str=function(strP,posP){if(!posP)posP=0;var clean_split_str=function(arrP){var arr=[];if(arrP&&arrP.length>1&&arrP[0]===""&&arrP[1].indexOf("@")>-1){for(var i=1;i<=arrP.length;i++){arr.push(arrP[i])}return arr}else return arrP};var nonLettersPatt=/\W/;var validSymbolsNoArray=/[^.@\[]/;var validSymbolsWithArray=/[^.@"'\[\]]/;var validSymbols=validSymbolsNoArray;var splitTmp=strP.replace(/@/g,"^^@").split("^^");var split=clean_split_str(splitTmp);var obj=[];if(split){for(let val of split){if(val){var pos=strP.indexOf(val);if(val&&val.substr(0,1)==="@"){var tmpStr="";var word_start_pos=undefined;var word_end_pos=undefined;for(var i=0;i<=val.length;i++){var key1=i;var val1=val.substr(i,1);if(val1==="."&&!word_start_pos)word_start_pos=key1;if(word_start_pos&&key1>word_start_pos&&nonLettersPatt.test(val1))word_end_pos=key1;if(word_start_pos&&word_start_pos>=0&&word_end_pos&&word_end_pos>=0){var word=val.substr(word_start_pos+1,word_end_pos-word_start_pos-1);tmpStr=tmpStr.substr(0,word_start_pos)+"^^"+tmpStr.substr(word_start_pos,word_end_pos);if(val.substr(word_end_pos,1)===".")word_start_pos=word_end_pos;else word_start_pos=null;word_end_pos=null}if(val1==="[")validSymbols=validSymbolsWithArray;if(nonLettersPatt.test(val1)&&validSymbols.test(val1)&&tmpStr.indexOf("^^")===-1){tmpStr+="^^"+val1}else tmpStr+=val1}if(tmpStr.indexOf("^^")>-1){var obj1=extract_str(tmpStr,pos);obj=obj.concat(obj1)}else{var fieldId=undefined;if(val){fieldId=val.substr(1,val.length);if(val.indexOf(".")>-1)fieldId=val.substr(1,val.indexOf(".")-1);if(val.indexOf("[")>-1)fieldId=val.substr(1,val.indexOf("[")-1)}obj.push({value:val,fieldId:fieldId,pos:pos+posP})}}else{obj.push({value:val,pos:pos+posP})}}}return obj}};var res=extract_str(strP);return res};func.expression.parse=function(input){if(typeof input!=="string")return[];const segments=[];let pos=0;const parts=input.split(/(@\w+)/).filter(Boolean);for(const part of parts){if(part.startsWith("@")){const fieldId=part.slice(1);segments.push({value:part,fieldId:fieldId,pos:pos})}else{segments.push({value:part,pos:pos})}pos+=part.length}return segments};func.expression.get_property_org=async function(valP){async function secure_eval(val){if(typeof IS_PROCESS_SERVER==="undefined"){try{return eval(val)}catch(err){console.error(err);return}}try{let vm=new VM.VM({sandbox:{func:func,SESSION_ID:SESSION_ID,SESSION_OBJ:{[`${SESSION_ID}`]:SESSION_OBJ[SESSION_ID]}},timeout:1e3,allowAsync:false});return await vm.run(val)}catch(err){throw""}}var property1,property2;if(valP.indexOf("[")>-1&&valP.indexOf("]")>-1){property1=valP.substr(valP.indexOf("[")+1,valP.indexOf("]")-valP.indexOf("[")-1);property1=await secure_eval(property1)}if(valP.indexOf(".")>-1)property2=valP.substr(valP.indexOf(".")+1,valP.length);return{property1:property1,property2:property2}};func.expression.get_property=async function(valP){if(typeof valP!=="string")return{property1:undefined,property2:undefined};const secureEval=async expr=>{if(typeof IS_PROCESS_SERVER==="undefined"){try{return eval(expr)}catch(err){console.error(err);return undefined}}try{const vm=new VM.VM({sandbox:{func:func,SESSION_ID:SESSION_ID,SESSION_OBJ:{[SESSION_ID]:SESSION_OBJ[SESSION_ID]}},timeout:1e3,allowAsync:false});return await vm.run(expr)}catch{return undefined}};let property1,property2;const bracketStart=valP.indexOf("[");const bracketEnd=valP.indexOf("]");if(bracketStart>-1&&bracketEnd>bracketStart){const expr=valP.slice(bracketStart+1,bracketEnd);property1=await secureEval(expr)}const dotIndex=valP.indexOf(".");if(dotIndex>-1){property2=valP.slice(dotIndex+1)}return{property1:property1,property2:property2}};func.expression.validate_constant_org=function(valP){var patt=/["']/;if(typeof valP==="string"&&patt.test(valP.substr(0,1))&&patt.test(valP.substr(0,valP.length-1)))return true;else return false};func.expression.validate_variables_org=function(valP){if(typeof valP==="string"&&valP.indexOf("@")>-1)return true;else return false};func.expression.remove_quotes_org=function(valP){if(func.expression.validate_constant(valP))return valP.substr(1,valP.length-2);else return valP};func.expression.validate_constant=function(valP){typeof valP==="string"&&/^["'].*["']$/.test(valP)};func.expression.validate_variables=function(valP){typeof valP==="string"&&valP.includes("@")};func.expression.remove_quotes=function(valP){func.expression.validate_constant(valP)&&typeof valP==="string"?valP.slice(1,-1):valP};func.expression.secure_eval_org=async function(SESSION_ID,sourceP,val,job_id,dsSessionP,js_script_callback,evt){const api_utils=await func.common.get_module(SESSION_ID,"xuda-api-library.mjs",{func:func,glb:glb,SESSION_OBJ:SESSION_OBJ,SESSION_ID:SESSION_ID,APP_OBJ:APP_OBJ,dsSession:dsSessionP,job_id:job_id});const xu=api_utils;if(typeof IS_PROCESS_SERVER==="undefined"&&typeof IS_DOCKER==="undefined"){try{return eval(val)}catch(err){try{return JSON5.parse(val)}catch(err){return val}}}if(sourceP==="javascript"){process.on("uncaughtException",err=>{console.error("Asynchronous error caught.",err);func.events.delete_job(SESSION_ID,job_id);if(typeof IS_PROCESS_SERVER!=="undefined"||typeof IS_DOCKER!=="undefined"){if(SESSION_OBJ[SESSION_ID].crawler)return;return __.rpi.write_log(SESSION_OBJ[SESSION_ID].app_id,"error","worker","vm error",err,null,val,"func.expression.get.secure_eval")}});try{const dir=path.join(_conf.studio_drive_path,SESSION_OBJ[SESSION_ID].app_id,"node_modules","/");const script=new VM.VMScript(`try{${val}}catch(e){func.api.error(SESSION_ID, "nodejs error", e); console.error(e); func.events.delete_job(SESSION_ID, job_id);}`,{filename:dir,dirname:dir});let vm=new VM.NodeVM({require:{external:true},sandbox:{func:func,xu:xu,SESSION_ID:SESSION_ID,SESSION_OBJ:{[`${SESSION_ID}`]:SESSION_OBJ[SESSION_ID]},callback:js_script_callback,job_id:job_id,axios:axios,got:got,FormData:FormData},timeout:6e4});return await vm.run(script,{filename:dir,dirname:dir})}catch(err){console.error("Failed to execute script.",err);if(typeof IS_PROCESS_SERVER!=="undefined"){func.events.delete_job(SESSION_ID,jobNo);return __.db.add_error_log(SESSION_OBJ[SESSION_ID].app_id,"api",err)}}}else{try{try{let vm=new VM.VM({sandbox:{xu:xu,func:func,SESSION_ID:SESSION_ID,SESSION_OBJ:{[`${SESSION_ID}`]:SESSION_OBJ[SESSION_ID]},callback:js_script_callback,job_id:job_id},timeout:1e3,allowAsync:false});let ret=val;if(typeof val==="string"){ret=await vm.run(val)}return ret}catch(err){throw""}}catch(err){try{return JSON5.parse(val)}catch(err){return val}}}};func.expression.secure_eval=async function(SESSION_ID,sourceP,val,job_id,dsSessionP,js_script_callback,evt){if(typeof val!=="string")return val;const xu=await func.common.get_module(SESSION_ID,"xuda-api-library.mjs",{func:func,glb:glb,SESSION_OBJ:SESSION_OBJ,SESSION_ID:SESSION_ID,APP_OBJ:APP_OBJ,dsSession:dsSessionP,job_id:job_id});const isServer=typeof IS_PROCESS_SERVER!=="undefined"||typeof IS_DOCKER!=="undefined";if(!isServer){try{return eval(val)}catch{try{return JSON5.parse(val)}catch{return val}}}const sandbox={func:func,xu:xu,SESSION_ID:SESSION_ID,SESSION_OBJ:{[SESSION_ID]:SESSION_OBJ[SESSION_ID]},callback:js_script_callback,job_id:job_id,...sourceP==="javascript"?{axios:axios,got:got,FormData:FormData}:{}};const handleError=err=>{console.error("Execution error:",err);func.events.delete_job(SESSION_ID,job_id);if(isServer&&!SESSION_OBJ[SESSION_ID].crawler){if(sourceP==="javascript"){__.rpi.write_log(SESSION_OBJ[SESSION_ID].app_id,"error","worker","vm error",err,null,val,"func.expression.get.secure_eval")}else{__.db.add_error_log(SESSION_OBJ[SESSION_ID].app_id,"api",err)}}return val};if(sourceP==="javascript"){process.on("uncaughtException",handleError);try{const dir=path.join(_conf.studio_drive_path,SESSION_OBJ[SESSION_ID].app_id,"node_modules");const script=new VM.VMScript(`try { ${val} } catch (e) { func.api.error(SESSION_ID, "nodejs error", e); console.error(e); func.events.delete_job(SESSION_ID, "${job_id}"); }`,{filename:dir,dirname:dir});const vm=new VM.NodeVM({require:{external:true},sandbox:sandbox,timeout:6e4});return await vm.run(script,{filename:dir,dirname:dir})}catch(err){return handleError(err)}}try{const vm=new VM.VM({sandbox:sandbox,timeout:1e3,allowAsync:false});return await vm.run(val)}catch{try{return JSON5.parse(val)}catch{return val}}}; export default {
6
6
  glb,
7
7
  func,
8
8
  APP_OBJ,