@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.
@@ -10474,7 +10474,7 @@ func.events.invoke = async function (event_id) {
10474
10474
  };
10475
10475
  func.expression = {};
10476
10476
 
10477
- 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) {
10477
+ 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) {
10478
10478
  class xu_class {
10479
10479
  async get() {
10480
10480
  var ret;
@@ -10828,7 +10828,7 @@ func.expression.get_org = async function (SESSION_ID, valP, dsSessionP, sourceP,
10828
10828
  return new_class.get();
10829
10829
  };
10830
10830
 
10831
- 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) {
10831
+ 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) {
10832
10832
  const evalJson = (text) => eval(`(${text})`);
10833
10833
  const replaceQuotes = (str) => {
10834
10834
  for (const [key, val] of Object.entries(fields)) {
@@ -11094,64 +11094,6 @@ func.expression.parse_org = function (strP) {
11094
11094
  return res;
11095
11095
  };
11096
11096
 
11097
- func.expression.parse_bad = function (strP) {
11098
- const nonLettersPatt = /\W/;
11099
- const validSymbolsNoArray = /[^.@\[]/;
11100
- const validSymbolsWithArray = /[^.@"'\[\]]/;
11101
-
11102
- function extractStr(str, startPos = 0) {
11103
- const cleanSplit = (arr) => (arr?.length > 1 && arr[0] === '' && arr[1].includes('@') ? arr.slice(1) : arr);
11104
-
11105
- const segments = cleanSplit(str.replace(/@/g, '^^@').split('^^'));
11106
- const result = [];
11107
-
11108
- for (const val of segments || []) {
11109
- if (!val) continue;
11110
- const pos = str.indexOf(val) + startPos;
11111
-
11112
- if (val.startsWith('@')) {
11113
- let tmpStr = '';
11114
- let wordStart = null;
11115
- let wordEnd = null;
11116
- let validSymbols = validSymbolsNoArray;
11117
-
11118
- for (let i = 0; i < val.length; i++) {
11119
- const char = val[i];
11120
-
11121
- if (char === '[') validSymbols = validSymbolsWithArray;
11122
- if (char === '.' && wordStart === null) wordStart = i;
11123
- else if (wordStart !== null && nonLettersPatt.test(char)) wordEnd = i;
11124
-
11125
- if (wordStart !== null && wordEnd !== null) {
11126
- const word = val.slice(wordStart + 1, wordEnd);
11127
- tmpStr = tmpStr.slice(0, wordStart) + '^^' + tmpStr.slice(wordStart, wordEnd);
11128
- wordStart = char === '.' ? wordEnd : null;
11129
- wordEnd = null;
11130
- }
11131
-
11132
- tmpStr += nonLettersPatt.test(char) && validSymbols.test(char) && !tmpStr.includes('^^') ? '^^' + char : char;
11133
- }
11134
-
11135
- if (tmpStr.includes('^^')) {
11136
- result.push(...extractStr(tmpStr, pos));
11137
- } else {
11138
- const fieldIdMatch = val.match(/^@([^.\[]+)/);
11139
- result.push({
11140
- value: val,
11141
- fieldId: fieldIdMatch ? fieldIdMatch[1] : undefined,
11142
- pos,
11143
- });
11144
- }
11145
- } else {
11146
- result.push({ value: val, pos });
11147
- }
11148
- }
11149
- return result;
11150
- }
11151
-
11152
- return extractStr(strP);
11153
- };
11154
-
11155
11097
  func.expression.parse = function (input) {
11156
11098
  if (typeof input !== 'string') return [];
11157
11099
 
@@ -11180,7 +11122,7 @@ func.expression.parse = function (input) {
11180
11122
  return segments;
11181
11123
  };
11182
11124
 
11183
- func.expression.get_property = async function (valP) {
11125
+ func.expression.get_property_org = async function (valP) {
11184
11126
  async function secure_eval(val) {
11185
11127
  if (typeof IS_PROCESS_SERVER === 'undefined') {
11186
11128
  try {
@@ -11218,21 +11160,73 @@ func.expression.get_property = async function (valP) {
11218
11160
  property2: property2,
11219
11161
  };
11220
11162
  };
11221
- func.expression.validate_constant = function (valP) {
11163
+
11164
+ func.expression.get_property = async function (valP) {
11165
+ if (typeof valP !== 'string') return { property1: undefined, property2: undefined };
11166
+
11167
+ const secureEval = async (expr) => {
11168
+ if (typeof IS_PROCESS_SERVER === 'undefined') {
11169
+ try {
11170
+ return eval(expr);
11171
+ } catch (err) {
11172
+ console.error(err);
11173
+ return undefined;
11174
+ }
11175
+ }
11176
+ try {
11177
+ const vm = new VM.VM({
11178
+ sandbox: {
11179
+ func,
11180
+ SESSION_ID,
11181
+ SESSION_OBJ: { [SESSION_ID]: SESSION_OBJ[SESSION_ID] },
11182
+ },
11183
+ timeout: 1000,
11184
+ allowAsync: false,
11185
+ });
11186
+ return await vm.run(expr);
11187
+ } catch {
11188
+ return undefined; // Simplified error handling
11189
+ }
11190
+ };
11191
+
11192
+ let property1, property2;
11193
+ const bracketStart = valP.indexOf('[');
11194
+ const bracketEnd = valP.indexOf(']');
11195
+
11196
+ if (bracketStart > -1 && bracketEnd > bracketStart) {
11197
+ const expr = valP.slice(bracketStart + 1, bracketEnd);
11198
+ property1 = await secureEval(expr);
11199
+ }
11200
+
11201
+ const dotIndex = valP.indexOf('.');
11202
+ if (dotIndex > -1) {
11203
+ property2 = valP.slice(dotIndex + 1);
11204
+ }
11205
+
11206
+ return { property1, property2 };
11207
+ };
11208
+
11209
+ func.expression.validate_constant_org = function (valP) {
11222
11210
  var patt = /["']/;
11223
11211
  if (typeof valP === 'string' && patt.test(valP.substr(0, 1)) && patt.test(valP.substr(0, valP.length - 1))) return true;
11224
11212
  else return false;
11225
11213
  };
11226
- func.expression.validate_variables = function (valP) {
11214
+ func.expression.validate_variables_org = function (valP) {
11227
11215
  if (typeof valP === 'string' && valP.indexOf('@') > -1) return true;
11228
11216
  else return false;
11229
11217
  };
11230
- func.expression.remove_quotes = function (valP) {
11218
+ func.expression.remove_quotes_org = function (valP) {
11231
11219
  if (func.expression.validate_constant(valP)) return valP.substr(1, valP.length - 2);
11232
11220
  else return valP;
11233
11221
  };
11234
11222
 
11235
- func.expression.secure_eval = async function (SESSION_ID, sourceP, val, job_id, dsSessionP, js_script_callback, evt) {
11223
+ func.expression.validate_constant = (valP) => typeof valP === 'string' && /^["'].*["']$/.test(valP);
11224
+
11225
+ func.expression.validate_variables = (valP) => typeof valP === 'string' && valP.includes('@');
11226
+
11227
+ func.expression.remove_quotes = (valP) => (func.expression.validate_constant(valP) && typeof valP === 'string' ? valP.slice(1, -1) : valP);
11228
+
11229
+ func.expression.secure_eval_org = async function (SESSION_ID, sourceP, val, job_id, dsSessionP, js_script_callback, evt) {
11236
11230
  const api_utils = await func.common.get_module(SESSION_ID, 'xuda-api-library.mjs', {
11237
11231
  func,
11238
11232
  glb,
@@ -11333,6 +11327,90 @@ func.expression.secure_eval = async function (SESSION_ID, sourceP, val, job_id,
11333
11327
  }
11334
11328
  }
11335
11329
  };
11330
+
11331
+ func.expression.secure_eval = async function (SESSION_ID, sourceP, val, job_id, dsSessionP, js_script_callback, evt) {
11332
+ if (typeof val !== 'string') return val;
11333
+
11334
+ const xu = await func.common.get_module(SESSION_ID, 'xuda-api-library.mjs', {
11335
+ func,
11336
+ glb,
11337
+ SESSION_OBJ,
11338
+ SESSION_ID,
11339
+ APP_OBJ,
11340
+ dsSession: dsSessionP,
11341
+ job_id,
11342
+ });
11343
+
11344
+ const isServer = typeof IS_PROCESS_SERVER !== 'undefined' || typeof IS_DOCKER !== 'undefined';
11345
+
11346
+ // Client-side execution
11347
+ if (!isServer) {
11348
+ try {
11349
+ return eval(val);
11350
+ } catch {
11351
+ try {
11352
+ return JSON5.parse(val);
11353
+ } catch {
11354
+ return val;
11355
+ }
11356
+ }
11357
+ }
11358
+
11359
+ // Server-side execution
11360
+ const sandbox = {
11361
+ func,
11362
+ xu,
11363
+ SESSION_ID,
11364
+ SESSION_OBJ: { [SESSION_ID]: SESSION_OBJ[SESSION_ID] },
11365
+ callback: js_script_callback,
11366
+ job_id,
11367
+ ...(sourceP === 'javascript' ? { axios, got, FormData } : {}),
11368
+ };
11369
+
11370
+ const handleError = (err) => {
11371
+ console.error('Execution error:', err);
11372
+ func.events.delete_job(SESSION_ID, job_id);
11373
+ if (isServer && !SESSION_OBJ[SESSION_ID].crawler) {
11374
+ if (sourceP === 'javascript') {
11375
+ __.rpi.write_log(SESSION_OBJ[SESSION_ID].app_id, 'error', 'worker', 'vm error', err, null, val, 'func.expression.get.secure_eval');
11376
+ } else {
11377
+ __.db.add_error_log(SESSION_OBJ[SESSION_ID].app_id, 'api', err);
11378
+ }
11379
+ }
11380
+ return val; // Fallback to original value
11381
+ };
11382
+
11383
+ if (sourceP === 'javascript') {
11384
+ process.on('uncaughtException', handleError);
11385
+ try {
11386
+ const dir = path.join(_conf.studio_drive_path, SESSION_OBJ[SESSION_ID].app_id, 'node_modules');
11387
+ 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 });
11388
+ const vm = new VM.NodeVM({
11389
+ require: { external: true },
11390
+ sandbox,
11391
+ timeout: 60000,
11392
+ });
11393
+ return await vm.run(script, { filename: dir, dirname: dir });
11394
+ } catch (err) {
11395
+ return handleError(err);
11396
+ }
11397
+ }
11398
+
11399
+ try {
11400
+ const vm = new VM.VM({
11401
+ sandbox,
11402
+ timeout: 1000,
11403
+ allowAsync: false,
11404
+ });
11405
+ return await vm.run(val);
11406
+ } catch {
11407
+ try {
11408
+ return JSON5.parse(val);
11409
+ } catch {
11410
+ return val;
11411
+ }
11412
+ }
11413
+ };
11336
11414
  func.UI.screen = {};
11337
11415
  func.UI.screen.init = async function (SESSION_ID, prog_id, sourceScreenP, callingDataSource_objP, $callingContainerP, triggerIdP, rowIdP, jobNoP, is_panelP, parameters_obj_inP, source_functionP, call_screen_propertiesP) {
11338
11416
  if (!prog_id) return console.error('program is empty');
@@ -14287,7 +14287,7 @@ func.events.invoke = async function (event_id) {
14287
14287
  };
14288
14288
  func.expression = {};
14289
14289
 
14290
- 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) {
14290
+ 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) {
14291
14291
  class xu_class {
14292
14292
  async get() {
14293
14293
  var ret;
@@ -14641,7 +14641,7 @@ func.expression.get_org = async function (SESSION_ID, valP, dsSessionP, sourceP,
14641
14641
  return new_class.get();
14642
14642
  };
14643
14643
 
14644
- 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) {
14644
+ 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) {
14645
14645
  const evalJson = (text) => eval(`(${text})`);
14646
14646
  const replaceQuotes = (str) => {
14647
14647
  for (const [key, val] of Object.entries(fields)) {
@@ -14907,64 +14907,6 @@ func.expression.parse_org = function (strP) {
14907
14907
  return res;
14908
14908
  };
14909
14909
 
14910
- func.expression.parse_bad = function (strP) {
14911
- const nonLettersPatt = /\W/;
14912
- const validSymbolsNoArray = /[^.@\[]/;
14913
- const validSymbolsWithArray = /[^.@"'\[\]]/;
14914
-
14915
- function extractStr(str, startPos = 0) {
14916
- const cleanSplit = (arr) => (arr?.length > 1 && arr[0] === '' && arr[1].includes('@') ? arr.slice(1) : arr);
14917
-
14918
- const segments = cleanSplit(str.replace(/@/g, '^^@').split('^^'));
14919
- const result = [];
14920
-
14921
- for (const val of segments || []) {
14922
- if (!val) continue;
14923
- const pos = str.indexOf(val) + startPos;
14924
-
14925
- if (val.startsWith('@')) {
14926
- let tmpStr = '';
14927
- let wordStart = null;
14928
- let wordEnd = null;
14929
- let validSymbols = validSymbolsNoArray;
14930
-
14931
- for (let i = 0; i < val.length; i++) {
14932
- const char = val[i];
14933
-
14934
- if (char === '[') validSymbols = validSymbolsWithArray;
14935
- if (char === '.' && wordStart === null) wordStart = i;
14936
- else if (wordStart !== null && nonLettersPatt.test(char)) wordEnd = i;
14937
-
14938
- if (wordStart !== null && wordEnd !== null) {
14939
- const word = val.slice(wordStart + 1, wordEnd);
14940
- tmpStr = tmpStr.slice(0, wordStart) + '^^' + tmpStr.slice(wordStart, wordEnd);
14941
- wordStart = char === '.' ? wordEnd : null;
14942
- wordEnd = null;
14943
- }
14944
-
14945
- tmpStr += nonLettersPatt.test(char) && validSymbols.test(char) && !tmpStr.includes('^^') ? '^^' + char : char;
14946
- }
14947
-
14948
- if (tmpStr.includes('^^')) {
14949
- result.push(...extractStr(tmpStr, pos));
14950
- } else {
14951
- const fieldIdMatch = val.match(/^@([^.\[]+)/);
14952
- result.push({
14953
- value: val,
14954
- fieldId: fieldIdMatch ? fieldIdMatch[1] : undefined,
14955
- pos,
14956
- });
14957
- }
14958
- } else {
14959
- result.push({ value: val, pos });
14960
- }
14961
- }
14962
- return result;
14963
- }
14964
-
14965
- return extractStr(strP);
14966
- };
14967
-
14968
14910
  func.expression.parse = function (input) {
14969
14911
  if (typeof input !== 'string') return [];
14970
14912
 
@@ -14993,7 +14935,7 @@ func.expression.parse = function (input) {
14993
14935
  return segments;
14994
14936
  };
14995
14937
 
14996
- func.expression.get_property = async function (valP) {
14938
+ func.expression.get_property_org = async function (valP) {
14997
14939
  async function secure_eval(val) {
14998
14940
  if (typeof IS_PROCESS_SERVER === 'undefined') {
14999
14941
  try {
@@ -15031,21 +14973,73 @@ func.expression.get_property = async function (valP) {
15031
14973
  property2: property2,
15032
14974
  };
15033
14975
  };
15034
- func.expression.validate_constant = function (valP) {
14976
+
14977
+ func.expression.get_property = async function (valP) {
14978
+ if (typeof valP !== 'string') return { property1: undefined, property2: undefined };
14979
+
14980
+ const secureEval = async (expr) => {
14981
+ if (typeof IS_PROCESS_SERVER === 'undefined') {
14982
+ try {
14983
+ return eval(expr);
14984
+ } catch (err) {
14985
+ console.error(err);
14986
+ return undefined;
14987
+ }
14988
+ }
14989
+ try {
14990
+ const vm = new VM.VM({
14991
+ sandbox: {
14992
+ func,
14993
+ SESSION_ID,
14994
+ SESSION_OBJ: { [SESSION_ID]: SESSION_OBJ[SESSION_ID] },
14995
+ },
14996
+ timeout: 1000,
14997
+ allowAsync: false,
14998
+ });
14999
+ return await vm.run(expr);
15000
+ } catch {
15001
+ return undefined; // Simplified error handling
15002
+ }
15003
+ };
15004
+
15005
+ let property1, property2;
15006
+ const bracketStart = valP.indexOf('[');
15007
+ const bracketEnd = valP.indexOf(']');
15008
+
15009
+ if (bracketStart > -1 && bracketEnd > bracketStart) {
15010
+ const expr = valP.slice(bracketStart + 1, bracketEnd);
15011
+ property1 = await secureEval(expr);
15012
+ }
15013
+
15014
+ const dotIndex = valP.indexOf('.');
15015
+ if (dotIndex > -1) {
15016
+ property2 = valP.slice(dotIndex + 1);
15017
+ }
15018
+
15019
+ return { property1, property2 };
15020
+ };
15021
+
15022
+ func.expression.validate_constant_org = function (valP) {
15035
15023
  var patt = /["']/;
15036
15024
  if (typeof valP === 'string' && patt.test(valP.substr(0, 1)) && patt.test(valP.substr(0, valP.length - 1))) return true;
15037
15025
  else return false;
15038
15026
  };
15039
- func.expression.validate_variables = function (valP) {
15027
+ func.expression.validate_variables_org = function (valP) {
15040
15028
  if (typeof valP === 'string' && valP.indexOf('@') > -1) return true;
15041
15029
  else return false;
15042
15030
  };
15043
- func.expression.remove_quotes = function (valP) {
15031
+ func.expression.remove_quotes_org = function (valP) {
15044
15032
  if (func.expression.validate_constant(valP)) return valP.substr(1, valP.length - 2);
15045
15033
  else return valP;
15046
15034
  };
15047
15035
 
15048
- func.expression.secure_eval = async function (SESSION_ID, sourceP, val, job_id, dsSessionP, js_script_callback, evt) {
15036
+ func.expression.validate_constant = (valP) => typeof valP === 'string' && /^["'].*["']$/.test(valP);
15037
+
15038
+ func.expression.validate_variables = (valP) => typeof valP === 'string' && valP.includes('@');
15039
+
15040
+ func.expression.remove_quotes = (valP) => (func.expression.validate_constant(valP) && typeof valP === 'string' ? valP.slice(1, -1) : valP);
15041
+
15042
+ func.expression.secure_eval_org = async function (SESSION_ID, sourceP, val, job_id, dsSessionP, js_script_callback, evt) {
15049
15043
  const api_utils = await func.common.get_module(SESSION_ID, 'xuda-api-library.mjs', {
15050
15044
  func,
15051
15045
  glb,
@@ -15146,6 +15140,90 @@ func.expression.secure_eval = async function (SESSION_ID, sourceP, val, job_id,
15146
15140
  }
15147
15141
  }
15148
15142
  };
15143
+
15144
+ func.expression.secure_eval = async function (SESSION_ID, sourceP, val, job_id, dsSessionP, js_script_callback, evt) {
15145
+ if (typeof val !== 'string') return val;
15146
+
15147
+ const xu = await func.common.get_module(SESSION_ID, 'xuda-api-library.mjs', {
15148
+ func,
15149
+ glb,
15150
+ SESSION_OBJ,
15151
+ SESSION_ID,
15152
+ APP_OBJ,
15153
+ dsSession: dsSessionP,
15154
+ job_id,
15155
+ });
15156
+
15157
+ const isServer = typeof IS_PROCESS_SERVER !== 'undefined' || typeof IS_DOCKER !== 'undefined';
15158
+
15159
+ // Client-side execution
15160
+ if (!isServer) {
15161
+ try {
15162
+ return eval(val);
15163
+ } catch {
15164
+ try {
15165
+ return JSON5.parse(val);
15166
+ } catch {
15167
+ return val;
15168
+ }
15169
+ }
15170
+ }
15171
+
15172
+ // Server-side execution
15173
+ const sandbox = {
15174
+ func,
15175
+ xu,
15176
+ SESSION_ID,
15177
+ SESSION_OBJ: { [SESSION_ID]: SESSION_OBJ[SESSION_ID] },
15178
+ callback: js_script_callback,
15179
+ job_id,
15180
+ ...(sourceP === 'javascript' ? { axios, got, FormData } : {}),
15181
+ };
15182
+
15183
+ const handleError = (err) => {
15184
+ console.error('Execution error:', err);
15185
+ func.events.delete_job(SESSION_ID, job_id);
15186
+ if (isServer && !SESSION_OBJ[SESSION_ID].crawler) {
15187
+ if (sourceP === 'javascript') {
15188
+ __.rpi.write_log(SESSION_OBJ[SESSION_ID].app_id, 'error', 'worker', 'vm error', err, null, val, 'func.expression.get.secure_eval');
15189
+ } else {
15190
+ __.db.add_error_log(SESSION_OBJ[SESSION_ID].app_id, 'api', err);
15191
+ }
15192
+ }
15193
+ return val; // Fallback to original value
15194
+ };
15195
+
15196
+ if (sourceP === 'javascript') {
15197
+ process.on('uncaughtException', handleError);
15198
+ try {
15199
+ const dir = path.join(_conf.studio_drive_path, SESSION_OBJ[SESSION_ID].app_id, 'node_modules');
15200
+ 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 });
15201
+ const vm = new VM.NodeVM({
15202
+ require: { external: true },
15203
+ sandbox,
15204
+ timeout: 60000,
15205
+ });
15206
+ return await vm.run(script, { filename: dir, dirname: dir });
15207
+ } catch (err) {
15208
+ return handleError(err);
15209
+ }
15210
+ }
15211
+
15212
+ try {
15213
+ const vm = new VM.VM({
15214
+ sandbox,
15215
+ timeout: 1000,
15216
+ allowAsync: false,
15217
+ });
15218
+ return await vm.run(val);
15219
+ } catch {
15220
+ try {
15221
+ return JSON5.parse(val);
15222
+ } catch {
15223
+ return val;
15224
+ }
15225
+ }
15226
+ };
15149
15227
  func.UI.main = {};
15150
15228
 
15151
15229
  func.UI.main.clear_SYNC_INTERVAL = function () {