@xuda.io/runtime-bundle 1.0.490 → 1.0.492

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.
@@ -7753,7 +7753,7 @@ func.events.invoke = async function (event_id) {
7753
7753
  };
7754
7754
  func.expression = {};
7755
7755
 
7756
- func.expression.get_org = async function (SESSION_ID, valP, dsSessionP, sourceP, rowIdP, sourceActionP, secondPassP, calling_fieldIdP, fieldsP, debug_infoP, iterate_info, js_script_callback, jobNo, api_output_type) {
7756
+ 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) {
7757
7757
  class xu_class {
7758
7758
  async get() {
7759
7759
  var ret;
@@ -8107,7 +8107,7 @@ func.expression.get_org = async function (SESSION_ID, valP, dsSessionP, sourceP,
8107
8107
  return new_class.get();
8108
8108
  };
8109
8109
 
8110
- 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) {
8110
+ 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) {
8111
8111
  const evalJson = (text) => eval(`(${text})`);
8112
8112
  const replaceQuotes = (str) => {
8113
8113
  for (const [key, val] of Object.entries(fields)) {
@@ -8373,64 +8373,6 @@ func.expression.parse_org = function (strP) {
8373
8373
  return res;
8374
8374
  };
8375
8375
 
8376
- func.expression.parse_bad = function (strP) {
8377
- const nonLettersPatt = /\W/;
8378
- const validSymbolsNoArray = /[^.@\[]/;
8379
- const validSymbolsWithArray = /[^.@"'\[\]]/;
8380
-
8381
- function extractStr(str, startPos = 0) {
8382
- const cleanSplit = (arr) => (arr?.length > 1 && arr[0] === '' && arr[1].includes('@') ? arr.slice(1) : arr);
8383
-
8384
- const segments = cleanSplit(str.replace(/@/g, '^^@').split('^^'));
8385
- const result = [];
8386
-
8387
- for (const val of segments || []) {
8388
- if (!val) continue;
8389
- const pos = str.indexOf(val) + startPos;
8390
-
8391
- if (val.startsWith('@')) {
8392
- let tmpStr = '';
8393
- let wordStart = null;
8394
- let wordEnd = null;
8395
- let validSymbols = validSymbolsNoArray;
8396
-
8397
- for (let i = 0; i < val.length; i++) {
8398
- const char = val[i];
8399
-
8400
- if (char === '[') validSymbols = validSymbolsWithArray;
8401
- if (char === '.' && wordStart === null) wordStart = i;
8402
- else if (wordStart !== null && nonLettersPatt.test(char)) wordEnd = i;
8403
-
8404
- if (wordStart !== null && wordEnd !== null) {
8405
- const word = val.slice(wordStart + 1, wordEnd);
8406
- tmpStr = tmpStr.slice(0, wordStart) + '^^' + tmpStr.slice(wordStart, wordEnd);
8407
- wordStart = char === '.' ? wordEnd : null;
8408
- wordEnd = null;
8409
- }
8410
-
8411
- tmpStr += nonLettersPatt.test(char) && validSymbols.test(char) && !tmpStr.includes('^^') ? '^^' + char : char;
8412
- }
8413
-
8414
- if (tmpStr.includes('^^')) {
8415
- result.push(...extractStr(tmpStr, pos));
8416
- } else {
8417
- const fieldIdMatch = val.match(/^@([^.\[]+)/);
8418
- result.push({
8419
- value: val,
8420
- fieldId: fieldIdMatch ? fieldIdMatch[1] : undefined,
8421
- pos,
8422
- });
8423
- }
8424
- } else {
8425
- result.push({ value: val, pos });
8426
- }
8427
- }
8428
- return result;
8429
- }
8430
-
8431
- return extractStr(strP);
8432
- };
8433
-
8434
8376
  func.expression.parse = function (input) {
8435
8377
  if (typeof input !== 'string') return [];
8436
8378
 
@@ -8459,7 +8401,7 @@ func.expression.parse = function (input) {
8459
8401
  return segments;
8460
8402
  };
8461
8403
 
8462
- func.expression.get_property = async function (valP) {
8404
+ func.expression.get_property_org = async function (valP) {
8463
8405
  async function secure_eval(val) {
8464
8406
  if (typeof IS_PROCESS_SERVER === 'undefined') {
8465
8407
  try {
@@ -8497,21 +8439,73 @@ func.expression.get_property = async function (valP) {
8497
8439
  property2: property2,
8498
8440
  };
8499
8441
  };
8500
- func.expression.validate_constant = function (valP) {
8442
+
8443
+ func.expression.get_property = async function (valP) {
8444
+ if (typeof valP !== 'string') return { property1: undefined, property2: undefined };
8445
+
8446
+ const secureEval = async (expr) => {
8447
+ if (typeof IS_PROCESS_SERVER === 'undefined') {
8448
+ try {
8449
+ return eval(expr);
8450
+ } catch (err) {
8451
+ console.error(err);
8452
+ return undefined;
8453
+ }
8454
+ }
8455
+ try {
8456
+ const vm = new VM.VM({
8457
+ sandbox: {
8458
+ func,
8459
+ SESSION_ID,
8460
+ SESSION_OBJ: { [SESSION_ID]: SESSION_OBJ[SESSION_ID] },
8461
+ },
8462
+ timeout: 1000,
8463
+ allowAsync: false,
8464
+ });
8465
+ return await vm.run(expr);
8466
+ } catch {
8467
+ return undefined; // Simplified error handling
8468
+ }
8469
+ };
8470
+
8471
+ let property1, property2;
8472
+ const bracketStart = valP.indexOf('[');
8473
+ const bracketEnd = valP.indexOf(']');
8474
+
8475
+ if (bracketStart > -1 && bracketEnd > bracketStart) {
8476
+ const expr = valP.slice(bracketStart + 1, bracketEnd);
8477
+ property1 = await secureEval(expr);
8478
+ }
8479
+
8480
+ const dotIndex = valP.indexOf('.');
8481
+ if (dotIndex > -1) {
8482
+ property2 = valP.slice(dotIndex + 1);
8483
+ }
8484
+
8485
+ return { property1, property2 };
8486
+ };
8487
+
8488
+ func.expression.validate_constant_org = function (valP) {
8501
8489
  var patt = /["']/;
8502
8490
  if (typeof valP === 'string' && patt.test(valP.substr(0, 1)) && patt.test(valP.substr(0, valP.length - 1))) return true;
8503
8491
  else return false;
8504
8492
  };
8505
- func.expression.validate_variables = function (valP) {
8493
+ func.expression.validate_variables_org = function (valP) {
8506
8494
  if (typeof valP === 'string' && valP.indexOf('@') > -1) return true;
8507
8495
  else return false;
8508
8496
  };
8509
- func.expression.remove_quotes = function (valP) {
8497
+ func.expression.remove_quotes_org = function (valP) {
8510
8498
  if (func.expression.validate_constant(valP)) return valP.substr(1, valP.length - 2);
8511
8499
  else return valP;
8512
8500
  };
8513
8501
 
8514
- func.expression.secure_eval = async function (SESSION_ID, sourceP, val, job_id, dsSessionP, js_script_callback, evt) {
8502
+ func.expression.validate_constant = (valP) => typeof valP === 'string' && /^["'].*["']$/.test(valP);
8503
+
8504
+ func.expression.validate_variables = (valP) => typeof valP === 'string' && valP.includes('@');
8505
+
8506
+ func.expression.remove_quotes = (valP) => (func.expression.validate_constant(valP) && typeof valP === 'string' ? valP.slice(1, -1) : valP);
8507
+
8508
+ func.expression.secure_eval_org = async function (SESSION_ID, sourceP, val, job_id, dsSessionP, js_script_callback, evt) {
8515
8509
  const api_utils = await func.common.get_module(SESSION_ID, 'xuda-api-library.mjs', {
8516
8510
  func,
8517
8511
  glb,
@@ -8612,6 +8606,90 @@ func.expression.secure_eval = async function (SESSION_ID, sourceP, val, job_id,
8612
8606
  }
8613
8607
  }
8614
8608
  };
8609
+
8610
+ func.expression.secure_eval = async function (SESSION_ID, sourceP, val, job_id, dsSessionP, js_script_callback, evt) {
8611
+ if (typeof val !== 'string') return val;
8612
+
8613
+ const xu = await func.common.get_module(SESSION_ID, 'xuda-api-library.mjs', {
8614
+ func,
8615
+ glb,
8616
+ SESSION_OBJ,
8617
+ SESSION_ID,
8618
+ APP_OBJ,
8619
+ dsSession: dsSessionP,
8620
+ job_id,
8621
+ });
8622
+
8623
+ const isServer = typeof IS_PROCESS_SERVER !== 'undefined' || typeof IS_DOCKER !== 'undefined';
8624
+
8625
+ // Client-side execution
8626
+ if (!isServer) {
8627
+ try {
8628
+ return eval(val);
8629
+ } catch {
8630
+ try {
8631
+ return JSON5.parse(val);
8632
+ } catch {
8633
+ return val;
8634
+ }
8635
+ }
8636
+ }
8637
+
8638
+ // Server-side execution
8639
+ const sandbox = {
8640
+ func,
8641
+ xu,
8642
+ SESSION_ID,
8643
+ SESSION_OBJ: { [SESSION_ID]: SESSION_OBJ[SESSION_ID] },
8644
+ callback: js_script_callback,
8645
+ job_id,
8646
+ ...(sourceP === 'javascript' ? { axios, got, FormData } : {}),
8647
+ };
8648
+
8649
+ const handleError = (err) => {
8650
+ console.error('Execution error:', err);
8651
+ func.events.delete_job(SESSION_ID, job_id);
8652
+ if (isServer && !SESSION_OBJ[SESSION_ID].crawler) {
8653
+ if (sourceP === 'javascript') {
8654
+ __.rpi.write_log(SESSION_OBJ[SESSION_ID].app_id, 'error', 'worker', 'vm error', err, null, val, 'func.expression.get.secure_eval');
8655
+ } else {
8656
+ __.db.add_error_log(SESSION_OBJ[SESSION_ID].app_id, 'api', err);
8657
+ }
8658
+ }
8659
+ return val; // Fallback to original value
8660
+ };
8661
+
8662
+ if (sourceP === 'javascript') {
8663
+ process.on('uncaughtException', handleError);
8664
+ try {
8665
+ const dir = path.join(_conf.studio_drive_path, SESSION_OBJ[SESSION_ID].app_id, 'node_modules');
8666
+ 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 });
8667
+ const vm = new VM.NodeVM({
8668
+ require: { external: true },
8669
+ sandbox,
8670
+ timeout: 60000,
8671
+ });
8672
+ return await vm.run(script, { filename: dir, dirname: dir });
8673
+ } catch (err) {
8674
+ return handleError(err);
8675
+ }
8676
+ }
8677
+
8678
+ try {
8679
+ const vm = new VM.VM({
8680
+ sandbox,
8681
+ timeout: 1000,
8682
+ allowAsync: false,
8683
+ });
8684
+ return await vm.run(val);
8685
+ } catch {
8686
+ try {
8687
+ return JSON5.parse(val);
8688
+ } catch {
8689
+ return val;
8690
+ }
8691
+ }
8692
+ };
8615
8693
  export default {
8616
8694
  glb,
8617
8695
  func,
@@ -7753,7 +7753,7 @@ func.events.invoke = async function (event_id) {
7753
7753
  };
7754
7754
  func.expression = {};
7755
7755
 
7756
- func.expression.get_org = async function (SESSION_ID, valP, dsSessionP, sourceP, rowIdP, sourceActionP, secondPassP, calling_fieldIdP, fieldsP, debug_infoP, iterate_info, js_script_callback, jobNo, api_output_type) {
7756
+ 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) {
7757
7757
  class xu_class {
7758
7758
  async get() {
7759
7759
  var ret;
@@ -8107,7 +8107,7 @@ func.expression.get_org = async function (SESSION_ID, valP, dsSessionP, sourceP,
8107
8107
  return new_class.get();
8108
8108
  };
8109
8109
 
8110
- 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) {
8110
+ 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) {
8111
8111
  const evalJson = (text) => eval(`(${text})`);
8112
8112
  const replaceQuotes = (str) => {
8113
8113
  for (const [key, val] of Object.entries(fields)) {
@@ -8373,64 +8373,6 @@ func.expression.parse_org = function (strP) {
8373
8373
  return res;
8374
8374
  };
8375
8375
 
8376
- func.expression.parse_bad = function (strP) {
8377
- const nonLettersPatt = /\W/;
8378
- const validSymbolsNoArray = /[^.@\[]/;
8379
- const validSymbolsWithArray = /[^.@"'\[\]]/;
8380
-
8381
- function extractStr(str, startPos = 0) {
8382
- const cleanSplit = (arr) => (arr?.length > 1 && arr[0] === '' && arr[1].includes('@') ? arr.slice(1) : arr);
8383
-
8384
- const segments = cleanSplit(str.replace(/@/g, '^^@').split('^^'));
8385
- const result = [];
8386
-
8387
- for (const val of segments || []) {
8388
- if (!val) continue;
8389
- const pos = str.indexOf(val) + startPos;
8390
-
8391
- if (val.startsWith('@')) {
8392
- let tmpStr = '';
8393
- let wordStart = null;
8394
- let wordEnd = null;
8395
- let validSymbols = validSymbolsNoArray;
8396
-
8397
- for (let i = 0; i < val.length; i++) {
8398
- const char = val[i];
8399
-
8400
- if (char === '[') validSymbols = validSymbolsWithArray;
8401
- if (char === '.' && wordStart === null) wordStart = i;
8402
- else if (wordStart !== null && nonLettersPatt.test(char)) wordEnd = i;
8403
-
8404
- if (wordStart !== null && wordEnd !== null) {
8405
- const word = val.slice(wordStart + 1, wordEnd);
8406
- tmpStr = tmpStr.slice(0, wordStart) + '^^' + tmpStr.slice(wordStart, wordEnd);
8407
- wordStart = char === '.' ? wordEnd : null;
8408
- wordEnd = null;
8409
- }
8410
-
8411
- tmpStr += nonLettersPatt.test(char) && validSymbols.test(char) && !tmpStr.includes('^^') ? '^^' + char : char;
8412
- }
8413
-
8414
- if (tmpStr.includes('^^')) {
8415
- result.push(...extractStr(tmpStr, pos));
8416
- } else {
8417
- const fieldIdMatch = val.match(/^@([^.\[]+)/);
8418
- result.push({
8419
- value: val,
8420
- fieldId: fieldIdMatch ? fieldIdMatch[1] : undefined,
8421
- pos,
8422
- });
8423
- }
8424
- } else {
8425
- result.push({ value: val, pos });
8426
- }
8427
- }
8428
- return result;
8429
- }
8430
-
8431
- return extractStr(strP);
8432
- };
8433
-
8434
8376
  func.expression.parse = function (input) {
8435
8377
  if (typeof input !== 'string') return [];
8436
8378
 
@@ -8459,7 +8401,7 @@ func.expression.parse = function (input) {
8459
8401
  return segments;
8460
8402
  };
8461
8403
 
8462
- func.expression.get_property = async function (valP) {
8404
+ func.expression.get_property_org = async function (valP) {
8463
8405
  async function secure_eval(val) {
8464
8406
  if (typeof IS_PROCESS_SERVER === 'undefined') {
8465
8407
  try {
@@ -8497,21 +8439,73 @@ func.expression.get_property = async function (valP) {
8497
8439
  property2: property2,
8498
8440
  };
8499
8441
  };
8500
- func.expression.validate_constant = function (valP) {
8442
+
8443
+ func.expression.get_property = async function (valP) {
8444
+ if (typeof valP !== 'string') return { property1: undefined, property2: undefined };
8445
+
8446
+ const secureEval = async (expr) => {
8447
+ if (typeof IS_PROCESS_SERVER === 'undefined') {
8448
+ try {
8449
+ return eval(expr);
8450
+ } catch (err) {
8451
+ console.error(err);
8452
+ return undefined;
8453
+ }
8454
+ }
8455
+ try {
8456
+ const vm = new VM.VM({
8457
+ sandbox: {
8458
+ func,
8459
+ SESSION_ID,
8460
+ SESSION_OBJ: { [SESSION_ID]: SESSION_OBJ[SESSION_ID] },
8461
+ },
8462
+ timeout: 1000,
8463
+ allowAsync: false,
8464
+ });
8465
+ return await vm.run(expr);
8466
+ } catch {
8467
+ return undefined; // Simplified error handling
8468
+ }
8469
+ };
8470
+
8471
+ let property1, property2;
8472
+ const bracketStart = valP.indexOf('[');
8473
+ const bracketEnd = valP.indexOf(']');
8474
+
8475
+ if (bracketStart > -1 && bracketEnd > bracketStart) {
8476
+ const expr = valP.slice(bracketStart + 1, bracketEnd);
8477
+ property1 = await secureEval(expr);
8478
+ }
8479
+
8480
+ const dotIndex = valP.indexOf('.');
8481
+ if (dotIndex > -1) {
8482
+ property2 = valP.slice(dotIndex + 1);
8483
+ }
8484
+
8485
+ return { property1, property2 };
8486
+ };
8487
+
8488
+ func.expression.validate_constant_org = function (valP) {
8501
8489
  var patt = /["']/;
8502
8490
  if (typeof valP === 'string' && patt.test(valP.substr(0, 1)) && patt.test(valP.substr(0, valP.length - 1))) return true;
8503
8491
  else return false;
8504
8492
  };
8505
- func.expression.validate_variables = function (valP) {
8493
+ func.expression.validate_variables_org = function (valP) {
8506
8494
  if (typeof valP === 'string' && valP.indexOf('@') > -1) return true;
8507
8495
  else return false;
8508
8496
  };
8509
- func.expression.remove_quotes = function (valP) {
8497
+ func.expression.remove_quotes_org = function (valP) {
8510
8498
  if (func.expression.validate_constant(valP)) return valP.substr(1, valP.length - 2);
8511
8499
  else return valP;
8512
8500
  };
8513
8501
 
8514
- func.expression.secure_eval = async function (SESSION_ID, sourceP, val, job_id, dsSessionP, js_script_callback, evt) {
8502
+ func.expression.validate_constant = (valP) => typeof valP === 'string' && /^["'].*["']$/.test(valP);
8503
+
8504
+ func.expression.validate_variables = (valP) => typeof valP === 'string' && valP.includes('@');
8505
+
8506
+ func.expression.remove_quotes = (valP) => (func.expression.validate_constant(valP) && typeof valP === 'string' ? valP.slice(1, -1) : valP);
8507
+
8508
+ func.expression.secure_eval_org = async function (SESSION_ID, sourceP, val, job_id, dsSessionP, js_script_callback, evt) {
8515
8509
  const api_utils = await func.common.get_module(SESSION_ID, 'xuda-api-library.mjs', {
8516
8510
  func,
8517
8511
  glb,
@@ -8612,3 +8606,87 @@ func.expression.secure_eval = async function (SESSION_ID, sourceP, val, job_id,
8612
8606
  }
8613
8607
  }
8614
8608
  };
8609
+
8610
+ func.expression.secure_eval = async function (SESSION_ID, sourceP, val, job_id, dsSessionP, js_script_callback, evt) {
8611
+ if (typeof val !== 'string') return val;
8612
+
8613
+ const xu = await func.common.get_module(SESSION_ID, 'xuda-api-library.mjs', {
8614
+ func,
8615
+ glb,
8616
+ SESSION_OBJ,
8617
+ SESSION_ID,
8618
+ APP_OBJ,
8619
+ dsSession: dsSessionP,
8620
+ job_id,
8621
+ });
8622
+
8623
+ const isServer = typeof IS_PROCESS_SERVER !== 'undefined' || typeof IS_DOCKER !== 'undefined';
8624
+
8625
+ // Client-side execution
8626
+ if (!isServer) {
8627
+ try {
8628
+ return eval(val);
8629
+ } catch {
8630
+ try {
8631
+ return JSON5.parse(val);
8632
+ } catch {
8633
+ return val;
8634
+ }
8635
+ }
8636
+ }
8637
+
8638
+ // Server-side execution
8639
+ const sandbox = {
8640
+ func,
8641
+ xu,
8642
+ SESSION_ID,
8643
+ SESSION_OBJ: { [SESSION_ID]: SESSION_OBJ[SESSION_ID] },
8644
+ callback: js_script_callback,
8645
+ job_id,
8646
+ ...(sourceP === 'javascript' ? { axios, got, FormData } : {}),
8647
+ };
8648
+
8649
+ const handleError = (err) => {
8650
+ console.error('Execution error:', err);
8651
+ func.events.delete_job(SESSION_ID, job_id);
8652
+ if (isServer && !SESSION_OBJ[SESSION_ID].crawler) {
8653
+ if (sourceP === 'javascript') {
8654
+ __.rpi.write_log(SESSION_OBJ[SESSION_ID].app_id, 'error', 'worker', 'vm error', err, null, val, 'func.expression.get.secure_eval');
8655
+ } else {
8656
+ __.db.add_error_log(SESSION_OBJ[SESSION_ID].app_id, 'api', err);
8657
+ }
8658
+ }
8659
+ return val; // Fallback to original value
8660
+ };
8661
+
8662
+ if (sourceP === 'javascript') {
8663
+ process.on('uncaughtException', handleError);
8664
+ try {
8665
+ const dir = path.join(_conf.studio_drive_path, SESSION_OBJ[SESSION_ID].app_id, 'node_modules');
8666
+ 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 });
8667
+ const vm = new VM.NodeVM({
8668
+ require: { external: true },
8669
+ sandbox,
8670
+ timeout: 60000,
8671
+ });
8672
+ return await vm.run(script, { filename: dir, dirname: dir });
8673
+ } catch (err) {
8674
+ return handleError(err);
8675
+ }
8676
+ }
8677
+
8678
+ try {
8679
+ const vm = new VM.VM({
8680
+ sandbox,
8681
+ timeout: 1000,
8682
+ allowAsync: false,
8683
+ });
8684
+ return await vm.run(val);
8685
+ } catch {
8686
+ try {
8687
+ return JSON5.parse(val);
8688
+ } catch {
8689
+ return val;
8690
+ }
8691
+ }
8692
+ };