@xuda.io/runtime-bundle 1.0.490 → 1.0.491

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.
@@ -35628,7 +35628,7 @@ func.expression.parse = function (input) {
35628
35628
  return segments;
35629
35629
  };
35630
35630
 
35631
- func.expression.get_property = async function (valP) {
35631
+ func.expression.get_property_org = async function (valP) {
35632
35632
  async function secure_eval(val) {
35633
35633
  if (typeof IS_PROCESS_SERVER === 'undefined') {
35634
35634
  try {
@@ -35666,21 +35666,73 @@ func.expression.get_property = async function (valP) {
35666
35666
  property2: property2,
35667
35667
  };
35668
35668
  };
35669
- func.expression.validate_constant = function (valP) {
35669
+
35670
+ func.expression.get_property = async function (valP) {
35671
+ if (typeof valP !== 'string') return { property1: undefined, property2: undefined };
35672
+
35673
+ const secureEval = async (expr) => {
35674
+ if (typeof IS_PROCESS_SERVER === 'undefined') {
35675
+ try {
35676
+ return eval(expr);
35677
+ } catch (err) {
35678
+ console.error(err);
35679
+ return undefined;
35680
+ }
35681
+ }
35682
+ try {
35683
+ const vm = new VM.VM({
35684
+ sandbox: {
35685
+ func,
35686
+ SESSION_ID,
35687
+ SESSION_OBJ: { [SESSION_ID]: SESSION_OBJ[SESSION_ID] },
35688
+ },
35689
+ timeout: 1000,
35690
+ allowAsync: false,
35691
+ });
35692
+ return await vm.run(expr);
35693
+ } catch {
35694
+ return undefined; // Simplified error handling
35695
+ }
35696
+ };
35697
+
35698
+ let property1, property2;
35699
+ const bracketStart = valP.indexOf('[');
35700
+ const bracketEnd = valP.indexOf(']');
35701
+
35702
+ if (bracketStart > -1 && bracketEnd > bracketStart) {
35703
+ const expr = valP.slice(bracketStart + 1, bracketEnd);
35704
+ property1 = await secureEval(expr);
35705
+ }
35706
+
35707
+ const dotIndex = valP.indexOf('.');
35708
+ if (dotIndex > -1) {
35709
+ property2 = valP.slice(dotIndex + 1);
35710
+ }
35711
+
35712
+ return { property1, property2 };
35713
+ };
35714
+
35715
+ func.expression.validate_constant_org = function (valP) {
35670
35716
  var patt = /["']/;
35671
35717
  if (typeof valP === 'string' && patt.test(valP.substr(0, 1)) && patt.test(valP.substr(0, valP.length - 1))) return true;
35672
35718
  else return false;
35673
35719
  };
35674
- func.expression.validate_variables = function (valP) {
35720
+ func.expression.validate_variables_org = function (valP) {
35675
35721
  if (typeof valP === 'string' && valP.indexOf('@') > -1) return true;
35676
35722
  else return false;
35677
35723
  };
35678
- func.expression.remove_quotes = function (valP) {
35724
+ func.expression.remove_quotes_org = function (valP) {
35679
35725
  if (func.expression.validate_constant(valP)) return valP.substr(1, valP.length - 2);
35680
35726
  else return valP;
35681
35727
  };
35682
35728
 
35683
- func.expression.secure_eval = async function (SESSION_ID, sourceP, val, job_id, dsSessionP, js_script_callback, evt) {
35729
+ func.expression.validate_constant = (valP) => typeof valP === 'string' && /^["'].*["']$/.test(valP);
35730
+
35731
+ func.expression.validate_variables = (valP) => typeof valP === 'string' && valP.includes('@');
35732
+
35733
+ func.expression.remove_quotes = (valP) => (func.expression.validate_constant(valP) && typeof valP === 'string' ? valP.slice(1, -1) : valP);
35734
+
35735
+ func.expression.secure_eval_org = async function (SESSION_ID, sourceP, val, job_id, dsSessionP, js_script_callback, evt) {
35684
35736
  const api_utils = await func.common.get_module(SESSION_ID, 'xuda-api-library.mjs', {
35685
35737
  func,
35686
35738
  glb,
@@ -35781,6 +35833,90 @@ func.expression.secure_eval = async function (SESSION_ID, sourceP, val, job_id,
35781
35833
  }
35782
35834
  }
35783
35835
  };
35836
+
35837
+ func.expression.secure_eval = async function (SESSION_ID, sourceP, val, job_id, dsSessionP, js_script_callback, evt) {
35838
+ if (typeof val !== 'string') return val;
35839
+
35840
+ const xu = await func.common.get_module(SESSION_ID, 'xuda-api-library.mjs', {
35841
+ func,
35842
+ glb,
35843
+ SESSION_OBJ,
35844
+ SESSION_ID,
35845
+ APP_OBJ,
35846
+ dsSession: dsSessionP,
35847
+ job_id,
35848
+ });
35849
+
35850
+ const isServer = typeof IS_PROCESS_SERVER !== 'undefined' || typeof IS_DOCKER !== 'undefined';
35851
+
35852
+ // Client-side execution
35853
+ if (!isServer) {
35854
+ try {
35855
+ return eval(val);
35856
+ } catch {
35857
+ try {
35858
+ return JSON5.parse(val);
35859
+ } catch {
35860
+ return val;
35861
+ }
35862
+ }
35863
+ }
35864
+
35865
+ // Server-side execution
35866
+ const sandbox = {
35867
+ func,
35868
+ xu,
35869
+ SESSION_ID,
35870
+ SESSION_OBJ: { [SESSION_ID]: SESSION_OBJ[SESSION_ID] },
35871
+ callback: js_script_callback,
35872
+ job_id,
35873
+ ...(sourceP === 'javascript' ? { axios, got, FormData } : {}),
35874
+ };
35875
+
35876
+ const handleError = (err) => {
35877
+ console.error('Execution error:', err);
35878
+ func.events.delete_job(SESSION_ID, job_id);
35879
+ if (isServer && !SESSION_OBJ[SESSION_ID].crawler) {
35880
+ if (sourceP === 'javascript') {
35881
+ __.rpi.write_log(SESSION_OBJ[SESSION_ID].app_id, 'error', 'worker', 'vm error', err, null, val, 'func.expression.get.secure_eval');
35882
+ } else {
35883
+ __.db.add_error_log(SESSION_OBJ[SESSION_ID].app_id, 'api', err);
35884
+ }
35885
+ }
35886
+ return val; // Fallback to original value
35887
+ };
35888
+
35889
+ if (sourceP === 'javascript') {
35890
+ process.on('uncaughtException', handleError);
35891
+ try {
35892
+ const dir = path.join(_conf.studio_drive_path, SESSION_OBJ[SESSION_ID].app_id, 'node_modules');
35893
+ 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 });
35894
+ const vm = new VM.NodeVM({
35895
+ require: { external: true },
35896
+ sandbox,
35897
+ timeout: 60000,
35898
+ });
35899
+ return await vm.run(script, { filename: dir, dirname: dir });
35900
+ } catch (err) {
35901
+ return handleError(err);
35902
+ }
35903
+ }
35904
+
35905
+ try {
35906
+ const vm = new VM.VM({
35907
+ sandbox,
35908
+ timeout: 1000,
35909
+ allowAsync: false,
35910
+ });
35911
+ return await vm.run(val);
35912
+ } catch {
35913
+ try {
35914
+ return JSON5.parse(val);
35915
+ } catch {
35916
+ return val;
35917
+ }
35918
+ }
35919
+ };
35784
35920
  func.events = {};
35785
35921
  func.events.validate = async function (SESSION_ID, triggerP, dsSessionP, eventIdP, sourceP, argumentsP, return_validation_onlyP) {
35786
35922
  var _session = SESSION_OBJ[SESSION_ID];