@xuda.io/runtime-bundle 1.0.279 → 1.0.281

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.
@@ -14,13 +14,13 @@ export const project_loader = async function (SESSION_ID, app_id, prog_id) {
14
14
  try {
15
15
  var _session = _this.SESSION_OBJ[SESSION_ID];
16
16
 
17
- if (_this.func.UI.utils.get_url_attribute(SESSION_ID, "clear_cache")) {
17
+ if (_this.func.UI.utils.get_url_attribute(SESSION_ID, 'clear_cache')) {
18
18
  await func.index.delete_pouch(SESSION_ID);
19
19
  }
20
20
  let last_changed_ts = 0;
21
21
  var ret_build_info = {};
22
22
  // call from xuda real-preview app
23
- if (typeof XUDA_BUILD_INFO !== "undefined") {
23
+ if (typeof XUDA_BUILD_INFO !== 'undefined') {
24
24
  _session.build_info = XUDA_BUILD_INFO;
25
25
  } else {
26
26
  // // in case of deployments
@@ -34,7 +34,7 @@ export const project_loader = async function (SESSION_ID, app_id, prog_id) {
34
34
  // }
35
35
  // }
36
36
 
37
- if (_session.engine_mode === "live_preview") {
37
+ if (_session.engine_mode === 'live_preview') {
38
38
  ret_build_info = await get_app_build_info(SESSION_ID, app_id);
39
39
  if (ret_build_info.code < 0) {
40
40
  return console.error(ret_build_info);
@@ -43,16 +43,13 @@ export const project_loader = async function (SESSION_ID, app_id, prog_id) {
43
43
  }
44
44
  }
45
45
 
46
- if (_session.engine_mode !== "live_preview") {
46
+ if (_session.engine_mode !== 'live_preview') {
47
47
  try {
48
48
  const db = await func.utils.connect_pouchdb(SESSION_ID);
49
49
  // only get indication for fresh installation
50
50
  await db.get(`cache_rt_info`);
51
51
  } catch (err) {
52
- const startup_module = await func.common.get_module(
53
- SESSION_ID,
54
- "xuda-deploy-startup-loader.mjs"
55
- );
52
+ const startup_module = await func.common.get_module(SESSION_ID, 'xuda-deploy-startup-loader.mjs');
56
53
  await startup_module.loader(SESSION_ID);
57
54
  }
58
55
  last_changed_ts = _session.opt.last_changed_ts;
@@ -63,18 +60,12 @@ export const project_loader = async function (SESSION_ID, app_id, prog_id) {
63
60
  insert_custom_prop(SESSION_ID);
64
61
 
65
62
  if (_session?.app_admin_prop?.app_admin_direction) {
66
- $(_session.root_element).attr(
67
- "dir",
68
- _session.app_admin_prop.app_admin_direction
69
- );
63
+ $(_session.root_element).attr('dir', _session.app_admin_prop.app_admin_direction);
70
64
  }
71
65
  // load live preview module
72
66
 
73
- if (_session.engine_mode === "live_preview") {
74
- const module = await _this.func.common.get_module(
75
- SESSION_ID,
76
- "xuda-live-preview-module.esm.js"
77
- );
67
+ if (_session.engine_mode === 'live_preview') {
68
+ const module = await _this.func.common.get_module(SESSION_ID, 'xuda-live-preview-module.esm.js');
78
69
 
79
70
  module.live_preview_loader(SESSION_ID);
80
71
  return;
@@ -87,12 +78,9 @@ export const project_loader = async function (SESSION_ID, app_id, prog_id) {
87
78
  throw error;
88
79
  }
89
80
  }
90
- const module = await _this.func.common.get_module(
91
- SESSION_ID,
92
- `xuda-progs-loader-module.mjs`
93
- );
81
+ const module = await _this.func.common.get_module(SESSION_ID, `xuda-progs-loader-module.mjs`);
94
82
 
95
- if (app_id !== "unknown") {
83
+ if (app_id !== 'unknown') {
96
84
  await module.load_objects_cache(SESSION_ID);
97
85
  }
98
86
  await _this.func.UI.main.embed_loader(SESSION_ID);
@@ -106,13 +94,13 @@ const get_app_build_info = async function (SESSION_ID, app_id) {
106
94
  var _session = _this.SESSION_OBJ[SESSION_ID];
107
95
  let app_id_reference = _this.APP_OBJ[app_id].app_id_reference;
108
96
 
109
- fetch(_this.func.common.get_url(SESSION_ID, "rpi", "get_app_build"), {
110
- method: "POST",
97
+ fetch(_this.func.common.get_url(SESSION_ID, 'rpi', 'get_app_build'), {
98
+ method: 'POST',
111
99
  headers: {
112
- Accept: "application/json",
113
- "Content-Type": "application/json",
114
- "xu-gtp-token": _session.gtp_token,
115
- "xu-app-token": _session.app_token,
100
+ Accept: 'application/json',
101
+ 'Content-Type': 'application/json',
102
+ 'xu-gtp-token': _session.gtp_token,
103
+ 'xu-app-token': _session.app_token,
116
104
  },
117
105
  body: JSON.stringify({
118
106
  app_id: app_id,
@@ -144,6 +132,13 @@ const get_app_build_info = async function (SESSION_ID, app_id) {
144
132
  });
145
133
  };
146
134
 
135
+ const get_user_group_account_info = async function (SESSION_ID) {
136
+ const ret = await func.common.db(SESSION_ID, 'get_account_info', {
137
+ uid_query: $.cookie('uid'),
138
+ });
139
+ debugger;
140
+ };
141
+
147
142
  const get_rt_info = async function (SESSION_ID, app_id, last_changed_ts) {
148
143
  var _session = _this.SESSION_OBJ[SESSION_ID];
149
144
 
@@ -178,6 +173,8 @@ const get_rt_info = async function (SESSION_ID, app_id, last_changed_ts) {
178
173
  _session.app_admin_prop = rt_info_obj.app_admin_prop;
179
174
  _session.is_deployment = rt_info_obj.is_deployment;
180
175
 
176
+ await get_user_group_account_info(SESSION_ID);
177
+
181
178
  // const set_prog_cache = async function () {
182
179
  // if (_session.prog_id) {
183
180
  // if (!rt_info_obj.prog_docs[_session.prog_id]) {
@@ -219,37 +216,22 @@ const get_rt_info = async function (SESSION_ID, app_id, last_changed_ts) {
219
216
 
220
217
  resolve();
221
218
 
222
- $(".loader_logo")
223
- .css("background-image", `url( ${rt_info_obj.app_pic})`)
224
- .hide()
225
- .fadeIn();
219
+ $('.loader_logo').css('background-image', `url( ${rt_info_obj.app_pic})`).hide().fadeIn();
226
220
  },
227
221
  error: async function (err) {
228
222
  if (err) {
229
- return _this.func.UI.utils.progressScreen.show(
230
- SESSION_ID,
231
- err,
232
- null,
233
- true
234
- );
223
+ return _this.func.UI.utils.progressScreen.show(SESSION_ID, err, null, true);
235
224
  }
236
225
  // location.reload();
237
- console.warn("** reload request");
226
+ console.warn('** reload request');
238
227
  },
239
228
  };
240
229
  const db = await func.utils.connect_pouchdb(SESSION_ID);
241
230
  try {
242
231
  let ret = await db.get(`cache_rt_info`);
243
232
  const rt_info_obj = ret.data;
244
- if (
245
- rt_info_obj.data.last_changed_ts !== last_changed_ts ||
246
- (_session.engine_mode !== "live_preview" &&
247
- rt_info_obj.data.app_build_id !== _session.opt.app_build_id)
248
- ) {
249
- _this.func.UI.utils.progressScreen.show(
250
- SESSION_ID,
251
- "New application setup detected, refreshing data and reloading in 5 sec"
252
- );
233
+ if (rt_info_obj.data.last_changed_ts !== last_changed_ts || (_session.engine_mode !== 'live_preview' && rt_info_obj.data.app_build_id !== _session.opt.app_build_id)) {
234
+ _this.func.UI.utils.progressScreen.show(SESSION_ID, 'New application setup detected, refreshing data and reloading in 5 sec');
253
235
  setTimeout(async () => {
254
236
  await func.index.delete_pouch(SESSION_ID);
255
237
  location.reload();
@@ -259,18 +241,17 @@ const get_rt_info = async function (SESSION_ID, app_id, last_changed_ts) {
259
241
 
260
242
  response.success(rt_info_obj);
261
243
  } catch (err) {
262
- fetch(_this.func.common.get_url(SESSION_ID, "rpi", "get_rt_info"), {
263
- method: "POST",
244
+ fetch(_this.func.common.get_url(SESSION_ID, 'rpi', 'get_rt_info'), {
245
+ method: 'POST',
264
246
  headers: {
265
- Accept: "application/json",
266
- "Content-Type": "application/json",
267
- "xu-gtp-token": _session.gtp_token,
268
- "xu-app-token": _session.app_token,
247
+ Accept: 'application/json',
248
+ 'Content-Type': 'application/json',
249
+ 'xu-gtp-token': _session.gtp_token,
250
+ 'xu-app-token': _session.app_token,
269
251
  },
270
252
  body: JSON.stringify({
271
253
  app_id,
272
- prog_id:
273
- _session.engine_mode === "live_preview" ? "" : _session.prog_id,
254
+ prog_id: _session.engine_mode === 'live_preview' ? '' : _session.prog_id,
274
255
  engine_mode: _session.engine_mode,
275
256
  build: _session.build_info.build,
276
257
  session_id: SESSION_ID,
@@ -291,14 +272,14 @@ const get_rt_info = async function (SESSION_ID, app_id, last_changed_ts) {
291
272
  })
292
273
  .then((json) => {
293
274
  if (json.code < 0) {
294
- throw new Error(json.data || "unknown error");
275
+ throw new Error(json.data || 'unknown error');
295
276
  }
296
277
  response.success(json);
297
278
 
298
279
  var doc = {
299
280
  _id: `cache_rt_info`,
300
281
  data: json,
301
- docType: "cache_app",
282
+ docType: 'cache_app',
302
283
  };
303
284
  db.put(doc);
304
285
  })
@@ -322,18 +303,13 @@ const insert_custom_prop = function (SESSION_ID) {
322
303
  try {
323
304
  var app_id = _this.SESSION_OBJ[SESSION_ID].app_id;
324
305
  if (_this.APP_OBJ[app_id]?.app_custom_prop?.app_custom_header) {
325
- var head = document.getElementsByTagName("head")[0];
326
- const app_custom_header =
327
- _this.APP_OBJ[app_id].app_custom_prop.app_custom_header;
306
+ var head = document.getElementsByTagName('head')[0];
307
+ const app_custom_header = _this.APP_OBJ[app_id].app_custom_prop.app_custom_header;
328
308
 
329
- $(head).append(
330
- func.utils.replace_studio_drive_url(SESSION_ID, app_custom_header)
331
- );
309
+ $(head).append(func.utils.replace_studio_drive_url(SESSION_ID, app_custom_header));
332
310
  }
333
311
  if (_this.APP_OBJ[app_id]?.app_custom_prop?.app_custom_body) {
334
- $(_this.SESSION_OBJ[SESSION_ID].root_element).prepend(
335
- _this.APP_OBJ[app_id].app_custom_prop.app_custom_body
336
- );
312
+ $(_this.SESSION_OBJ[SESSION_ID].root_element).prepend(_this.APP_OBJ[app_id].app_custom_prop.app_custom_body);
337
313
  }
338
314
  } catch (err) {
339
315
  console.error(err);
@@ -345,7 +321,7 @@ const init_runtime_websocket = function (SESSION_ID, app_id) {
345
321
  const set_connected = async function (stat) {
346
322
  var datasource_changes = {
347
323
  [0]: {
348
- ["data_system"]: { SYS_GLOBAL_BOL_CONNECTED: stat },
324
+ ['data_system']: { SYS_GLOBAL_BOL_CONNECTED: stat },
349
325
  },
350
326
  };
351
327
  await func.datasource.update(SESSION_ID, datasource_changes);
@@ -362,28 +338,23 @@ const init_runtime_websocket = function (SESSION_ID, app_id) {
362
338
  // reconnection: true,
363
339
  // reconnectionDelayMax: 10000,
364
340
  rejectUnauthorized: false,
365
- path: "/ws/socket.io",
341
+ path: '/ws/socket.io',
366
342
 
367
343
  // transports: ['websocket']
368
344
  // query: { session_obj: SESSION_OBJ[SESSION_ID] },
369
345
  });
370
346
 
371
- RUNTIME_SERVER_WEBSOCKET.on("connect", () => {
372
- console.info("RUNTIME_SERVER_WEBSOCKET connected");
347
+ RUNTIME_SERVER_WEBSOCKET.on('connect', () => {
348
+ console.info('RUNTIME_SERVER_WEBSOCKET connected');
373
349
 
374
350
  if (_data_system) {
375
351
  set_connected(1);
376
352
  }
377
353
 
378
354
  if (_session.opt.enable_offline) {
379
- if ($(_session.root_element).hasClass("runtime_offline")) {
380
- $(_session.root_element).removeClass("runtime_offline");
381
- func.utils.alerts.toast(
382
- SESSION_ID,
383
- "Switched to on-line mode",
384
- "You are now online. All data stored while you were offline will be synchronized to the server.",
385
- "success"
386
- );
355
+ if ($(_session.root_element).hasClass('runtime_offline')) {
356
+ $(_session.root_element).removeClass('runtime_offline');
357
+ func.utils.alerts.toast(SESSION_ID, 'Switched to on-line mode', 'You are now online. All data stored while you were offline will be synchronized to the server.', 'success');
387
358
  }
388
359
  } else {
389
360
  // back from temporarily disconnected from the server
@@ -392,12 +363,12 @@ const init_runtime_websocket = function (SESSION_ID, app_id) {
392
363
  if (error) {
393
364
  if (!RUNTIME_SERVER_WEBSOCKET_CONNECTED) {
394
365
  // location.reload();
395
- console.warn("** reload request");
366
+ console.warn('** reload request');
396
367
  }
397
368
  }
398
369
  });
399
370
 
400
- RUNTIME_SERVER_WEBSOCKET.on("message", (e) => {
371
+ RUNTIME_SERVER_WEBSOCKET.on('message', (e) => {
401
372
  if (_this.APP_OBJ[app_id].is_deployment) {
402
373
  _this.func.UI.utils.indicator.server.busy();
403
374
  setTimeout(function () {
@@ -406,45 +377,36 @@ const init_runtime_websocket = function (SESSION_ID, app_id) {
406
377
  }
407
378
  var data = e.data;
408
379
 
409
- if (e.source === "http_call") {
410
- if (e.service === "get_doc_obj_from_build") {
411
- return $("body").trigger(
412
- "get_doc_obj_from_build_response_" + data._id,
413
- {
414
- data,
415
- }
416
- );
417
- }
418
- if (e.service === "heartbeat") {
419
- return $("body").trigger("heartbeat_response", {
380
+ if (e.source === 'http_call') {
381
+ if (e.service === 'get_doc_obj_from_build') {
382
+ return $('body').trigger('get_doc_obj_from_build_response_' + data._id, {
420
383
  data,
421
384
  });
422
385
  }
423
- return $("body").trigger(
424
- "get_ws_data_response_" + e.websocket_queue_num,
425
- {
386
+ if (e.service === 'heartbeat') {
387
+ return $('body').trigger('heartbeat_response', {
426
388
  data,
427
- e,
428
- }
429
- );
389
+ });
390
+ }
391
+ return $('body').trigger('get_ws_data_response_' + e.websocket_queue_num, {
392
+ data,
393
+ e,
394
+ });
430
395
  }
431
- if (e.source === "deployment_server") {
432
- console.log("document_changed", e);
396
+ if (e.source === 'deployment_server') {
397
+ console.log('document_changed', e);
433
398
 
434
- return func.UI.screen.refresh_document_changes_for_realtime_update(
435
- SESSION_ID,
436
- e.data
437
- );
399
+ return func.UI.screen.refresh_document_changes_for_realtime_update(SESSION_ID, e.data);
438
400
  }
439
401
 
440
- if (data !== "connected") return;
402
+ if (data !== 'connected') return;
441
403
 
442
404
  RUNTIME_SERVER_WEBSOCKET_CONNECTED = true;
443
405
 
444
406
  resolve();
445
407
  });
446
408
  var callback_done = false;
447
- RUNTIME_SERVER_WEBSOCKET.on("connect_error", (error) => {
409
+ RUNTIME_SERVER_WEBSOCKET.on('connect_error', (error) => {
448
410
  if (!callback_done) {
449
411
  resolve();
450
412
  callback_done = true;
@@ -452,63 +414,46 @@ const init_runtime_websocket = function (SESSION_ID, app_id) {
452
414
  }
453
415
  });
454
416
 
455
- RUNTIME_SERVER_WEBSOCKET.on("disconnect", async () => {
417
+ RUNTIME_SERVER_WEBSOCKET.on('disconnect', async () => {
456
418
  RUNTIME_SERVER_WEBSOCKET_CONNECTED = false;
457
419
  if (_data_system) {
458
420
  set_connected(0);
459
421
  }
460
422
  if (_session.opt.enable_offline) {
461
- $(_session.root_element).addClass("runtime_offline");
462
- func.utils.alerts.toast(
463
- SESSION_ID,
464
- "Switched to off-line mode",
465
- "You have lost connection to the server and are now working offline. Once the connection is restored, all data will be synchronized.",
466
- "warning"
467
- );
423
+ $(_session.root_element).addClass('runtime_offline');
424
+ func.utils.alerts.toast(SESSION_ID, 'Switched to off-line mode', 'You have lost connection to the server and are now working offline. Once the connection is restored, all data will be synchronized.', 'warning');
468
425
  } else {
469
426
  // await func.index.delete_pouch();
470
427
  // window.location.href = `https://${_session.domain}/error?error_code=408`;
471
- _this.func.UI.utils.progressScreen.show(
472
- SESSION_ID,
473
- "Your browser has temporarily disconnected from the server. Please wait while we attempt to reconnect."
474
- );
428
+ _this.func.UI.utils.progressScreen.show(SESSION_ID, 'Your browser has temporarily disconnected from the server. Please wait while we attempt to reconnect.');
475
429
  }
476
430
  });
477
431
 
478
- window.addEventListener("beforeunload", function (event) {
432
+ window.addEventListener('beforeunload', function (event) {
479
433
  var obj = {
480
- service: "close_websocket",
434
+ service: 'close_websocket',
481
435
  data: { session_id: SESSION_ID },
482
436
  };
483
- RUNTIME_SERVER_WEBSOCKET.emit("message", obj);
437
+ RUNTIME_SERVER_WEBSOCKET.emit('message', obj);
484
438
  });
485
439
  });
486
440
  };
487
441
 
488
- export const run_plugins_runtime_init = async function (
489
- SESSION_ID,
490
- app_id,
491
- method
492
- ) {
442
+ export const run_plugins_runtime_init = async function (SESSION_ID, app_id, method) {
493
443
  var _session = _this.SESSION_OBJ[SESSION_ID];
494
444
 
495
445
  const get_path = function (plugin_name, resource) {
496
- if (_session.worker_type === "Dev") {
446
+ if (_session.worker_type === 'Dev') {
497
447
  return `../../plugins/${_session.domain}/${plugin_name}/${resource}`;
498
448
  }
499
449
  return `https://${_session.domain}/plugins/${plugin_name}/runtime/${resource}?gtp_token=${_session.gtp_token}&app_id=${_session.app_id}`;
500
450
  };
501
451
 
502
452
  if (!_this.APP_OBJ[app_id].app_plugins_purchased) return;
503
- for await (const [key, val] of Object.entries(
504
- _this.APP_OBJ[app_id].app_plugins_purchased
505
- )) {
453
+ for await (const [key, val] of Object.entries(_this.APP_OBJ[app_id].app_plugins_purchased)) {
506
454
  if (!val.installed) continue;
507
- if (
508
- val.manifest?.[method].mjs?.exist &&
509
- !val.manifest[method].mjs.is_empty
510
- ) {
511
- const module = await import(get_path(key, method + ".mjs"));
455
+ if (val.manifest?.[method].mjs?.exist && !val.manifest[method].mjs.is_empty) {
456
+ const module = await import(get_path(key, method + '.mjs'));
512
457
  try {
513
458
  await module.default({ SESSION_ID: SESSION_ID });
514
459
  } catch (error) {
@@ -1 +1 @@
1
- const _this={};export const init_module=e=>{_this.func=e.func;_this.glb=e.glb;_this.SESSION_OBJ=e.SESSION_OBJ;_this.APP_OBJ=e.APP_OBJ;_this.IS_DOCKER=e.IS_DOCKER;_this.IS_API_SERVER=e.IS_API_SERVER;_this.IS_PROCESS_SERVER=e.IS_PROCESS_SERVER};export const project_loader=async function(SESSION_ID,app_id,prog_id){try{var _session=_this.SESSION_OBJ[SESSION_ID];if(_this.func.UI.utils.get_url_attribute(SESSION_ID,"clear_cache")){await func.index.delete_pouch(SESSION_ID)}let last_changed_ts=0;var ret_build_info={};if(typeof XUDA_BUILD_INFO!=="undefined"){_session.build_info=XUDA_BUILD_INFO}else{if(_session.engine_mode==="live_preview"){ret_build_info=await get_app_build_info(SESSION_ID,app_id);if(ret_build_info.code<0){return console.error(ret_build_info)}last_changed_ts=ret_build_info.data.last_changed_ts}}if(_session.engine_mode!=="live_preview"){try{const db=await func.utils.connect_pouchdb(SESSION_ID);await db.get(`cache_rt_info`)}catch(err){const startup_module=await func.common.get_module(SESSION_ID,"xuda-deploy-startup-loader.mjs");await startup_module.loader(SESSION_ID)}last_changed_ts=_session.opt.last_changed_ts}await get_rt_info(SESSION_ID,app_id,last_changed_ts);insert_custom_prop(SESSION_ID);if(_session?.app_admin_prop?.app_admin_direction){$(_session.root_element).attr("dir",_session.app_admin_prop.app_admin_direction)}if(_session.engine_mode==="live_preview"){const module=await _this.func.common.get_module(SESSION_ID,"xuda-live-preview-module.esm.js");module.live_preview_loader(SESSION_ID);return}if(_this.APP_OBJ[app_id]?.is_deployment){try{await init_runtime_websocket(SESSION_ID,app_id)}catch(error){throw error}}const module=await _this.func.common.get_module(SESSION_ID,`xuda-progs-loader-module.mjs`);if(app_id!=="unknown"){await module.load_objects_cache(SESSION_ID)}await _this.func.UI.main.embed_loader(SESSION_ID)}catch(error){throw error}};const get_app_build_info=async function(SESSION_ID,app_id){return new Promise(function(resolve,reject){var _session=_this.SESSION_OBJ[SESSION_ID];let app_id_reference=_this.APP_OBJ[app_id].app_id_reference;fetch(_this.func.common.get_url(SESSION_ID,"rpi","get_app_build"),{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json","xu-gtp-token":_session.gtp_token,"xu-app-token":_session.app_token},body:JSON.stringify({app_id:app_id,app_id_reference:app_id_reference})}).then(response=>{if(!response.ok){return response.text().then(text=>{throw new Error(text)})}return response.json()}).then(async json=>{_this.SESSION_OBJ[SESSION_ID].build_info=json.data;resolve(json)}).catch(err=>{try{resolve(JSON.parse(err.message))}catch(error){resolve({code:-1,data:err.message})}})})};const get_rt_info=async function(SESSION_ID,app_id,last_changed_ts){var _session=_this.SESSION_OBJ[SESSION_ID];return new Promise(async function(resolve,reject){const response={success:async function(ret,ajaxP){if(ret.code<0){return response.error(ret.data)}const rt_info_obj=ret.data;var app_id=rt_info_obj._id;_this.APP_OBJ[app_id]=rt_info_obj;_session.app_id=app_id;if(rt_info_obj?.deploy_data?.global_variables){_session.url_params={..._session.url_params,...rt_info_obj.deploy_data.global_variables}}_session.USR_OBJ={_id:rt_info_obj?.account_info?.uid,usr_name:rt_info_obj?.account_info?.username,usr_first_name:rt_info_obj?.account_info?.first_name,usr_last_name:rt_info_obj?.account_info?.last_name,usr_email:rt_info_obj?.account_info?.email,usr_profile_picture:rt_info_obj?.account_info?.profile_picture};_session.login_info=rt_info_obj?.login_info;_session.client_ip=rt_info_obj.client_ip;_session.rpi_http_methods=rt_info_obj.rpi_http_methods;_session.app_admin_prop=rt_info_obj.app_admin_prop;_session.is_deployment=rt_info_obj.is_deployment;resolve();$(".loader_logo").css("background-image",`url( ${rt_info_obj.app_pic})`).hide().fadeIn()},error:async function(err){if(err){return _this.func.UI.utils.progressScreen.show(SESSION_ID,err,null,true)}console.warn("** reload request")}};const db=await func.utils.connect_pouchdb(SESSION_ID);try{let ret=await db.get(`cache_rt_info`);const rt_info_obj=ret.data;if(rt_info_obj.data.last_changed_ts!==last_changed_ts||_session.engine_mode!=="live_preview"&&rt_info_obj.data.app_build_id!==_session.opt.app_build_id){_this.func.UI.utils.progressScreen.show(SESSION_ID,"New application setup detected, refreshing data and reloading in 5 sec");setTimeout(async()=>{await func.index.delete_pouch(SESSION_ID);location.reload()},5e3);return}response.success(rt_info_obj)}catch(err){fetch(_this.func.common.get_url(SESSION_ID,"rpi","get_rt_info"),{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json","xu-gtp-token":_session.gtp_token,"xu-app-token":_session.app_token},body:JSON.stringify({app_id:app_id,prog_id:_session.engine_mode==="live_preview"?"":_session.prog_id,engine_mode:_session.engine_mode,build:_session.build_info.build,session_id:SESSION_ID,is_cordova:_this.glb.is_cordova,client_info:_session.SYS_GLOBAL_OBJ_CLIENT_INFO,client_id:_session.SYS_GLOBAL_OBJ_CLIENT_INFO.fingerprint})}).then(response=>{if(!response.ok){return response.text().then(text=>{throw new Error(text)})}return response.json()}).then(json=>{if(json.code<0){throw new Error(json.data||"unknown error")}response.success(json);var doc={_id:`cache_rt_info`,data:json,docType:"cache_app"};db.put(doc)}).catch(err=>{response.error(err.message)})}})};const insert_custom_prop=function(SESSION_ID){try{var app_id=_this.SESSION_OBJ[SESSION_ID].app_id;if(_this.APP_OBJ[app_id]?.app_custom_prop?.app_custom_header){var head=document.getElementsByTagName("head")[0];const app_custom_header=_this.APP_OBJ[app_id].app_custom_prop.app_custom_header;$(head).append(func.utils.replace_studio_drive_url(SESSION_ID,app_custom_header))}if(_this.APP_OBJ[app_id]?.app_custom_prop?.app_custom_body){$(_this.SESSION_OBJ[SESSION_ID].root_element).prepend(_this.APP_OBJ[app_id].app_custom_prop.app_custom_body)}}catch(err){console.error(err)}};const init_runtime_websocket=function(SESSION_ID,app_id){return new Promise(function(resolve,reject){const set_connected=async function(stat){var datasource_changes={[0]:{["data_system"]:{SYS_GLOBAL_BOL_CONNECTED:stat}}};await func.datasource.update(SESSION_ID,datasource_changes)};var _session=_this.SESSION_OBJ[SESSION_ID];var _data_system=_session?.DS_GLB?.[0]?.data_system;const url=`https://${location.hostname}`;var error;RUNTIME_SERVER_WEBSOCKET=io(url,{secure:true,reconnection:true,rejectUnauthorized:false,path:"/ws/socket.io"});RUNTIME_SERVER_WEBSOCKET.on("connect",()=>{console.info("RUNTIME_SERVER_WEBSOCKET connected");if(_data_system){set_connected(1)}if(_session.opt.enable_offline){if($(_session.root_element).hasClass("runtime_offline")){$(_session.root_element).removeClass("runtime_offline");func.utils.alerts.toast(SESSION_ID,"Switched to on-line mode","You are now online. All data stored while you were offline will be synchronized to the server.","success")}}else{_this.func.UI.utils.progressScreen.hide(SESSION_ID)}if(error){if(!RUNTIME_SERVER_WEBSOCKET_CONNECTED){console.warn("** reload request")}}});RUNTIME_SERVER_WEBSOCKET.on("message",e=>{if(_this.APP_OBJ[app_id].is_deployment){_this.func.UI.utils.indicator.server.busy();setTimeout(function(){_this.func.UI.utils.indicator.server.normal()},e?.data?.length*100||100)}var data=e.data;if(e.source==="http_call"){if(e.service==="get_doc_obj_from_build"){return $("body").trigger("get_doc_obj_from_build_response_"+data._id,{data:data})}if(e.service==="heartbeat"){return $("body").trigger("heartbeat_response",{data:data})}return $("body").trigger("get_ws_data_response_"+e.websocket_queue_num,{data:data,e:e})}if(e.source==="deployment_server"){console.log("document_changed",e);return func.UI.screen.refresh_document_changes_for_realtime_update(SESSION_ID,e.data)}if(data!=="connected")return;RUNTIME_SERVER_WEBSOCKET_CONNECTED=true;resolve()});var callback_done=false;RUNTIME_SERVER_WEBSOCKET.on("connect_error",error=>{if(!callback_done){resolve();callback_done=true;error=true}});RUNTIME_SERVER_WEBSOCKET.on("disconnect",async()=>{RUNTIME_SERVER_WEBSOCKET_CONNECTED=false;if(_data_system){set_connected(0)}if(_session.opt.enable_offline){$(_session.root_element).addClass("runtime_offline");func.utils.alerts.toast(SESSION_ID,"Switched to off-line mode","You have lost connection to the server and are now working offline. Once the connection is restored, all data will be synchronized.","warning")}else{_this.func.UI.utils.progressScreen.show(SESSION_ID,"Your browser has temporarily disconnected from the server. Please wait while we attempt to reconnect.")}});window.addEventListener("beforeunload",function(event){var obj={service:"close_websocket",data:{session_id:SESSION_ID}};RUNTIME_SERVER_WEBSOCKET.emit("message",obj)})})};export const run_plugins_runtime_init=async function(SESSION_ID,app_id,method){var _session=_this.SESSION_OBJ[SESSION_ID];const get_path=function(plugin_name,resource){if(_session.worker_type==="Dev"){return`../../plugins/${_session.domain}/${plugin_name}/${resource}`}return`https://${_session.domain}/plugins/${plugin_name}/runtime/${resource}?gtp_token=${_session.gtp_token}&app_id=${_session.app_id}`};if(!_this.APP_OBJ[app_id].app_plugins_purchased)return;for await(const[key,val]of Object.entries(_this.APP_OBJ[app_id].app_plugins_purchased)){if(!val.installed)continue;if(val.manifest?.[method].mjs?.exist&&!val.manifest[method].mjs.is_empty){const module=await import(get_path(key,method+".mjs"));try{await module.default({SESSION_ID:SESSION_ID})}catch(error){console.error(error)}}}};
1
+ const _this={};export const init_module=e=>{_this.func=e.func;_this.glb=e.glb;_this.SESSION_OBJ=e.SESSION_OBJ;_this.APP_OBJ=e.APP_OBJ;_this.IS_DOCKER=e.IS_DOCKER;_this.IS_API_SERVER=e.IS_API_SERVER;_this.IS_PROCESS_SERVER=e.IS_PROCESS_SERVER};export const project_loader=async function(SESSION_ID,app_id,prog_id){try{var _session=_this.SESSION_OBJ[SESSION_ID];if(_this.func.UI.utils.get_url_attribute(SESSION_ID,"clear_cache")){await func.index.delete_pouch(SESSION_ID)}let last_changed_ts=0;var ret_build_info={};if(typeof XUDA_BUILD_INFO!=="undefined"){_session.build_info=XUDA_BUILD_INFO}else{if(_session.engine_mode==="live_preview"){ret_build_info=await get_app_build_info(SESSION_ID,app_id);if(ret_build_info.code<0){return console.error(ret_build_info)}last_changed_ts=ret_build_info.data.last_changed_ts}}if(_session.engine_mode!=="live_preview"){try{const db=await func.utils.connect_pouchdb(SESSION_ID);await db.get(`cache_rt_info`)}catch(err){const startup_module=await func.common.get_module(SESSION_ID,"xuda-deploy-startup-loader.mjs");await startup_module.loader(SESSION_ID)}last_changed_ts=_session.opt.last_changed_ts}await get_rt_info(SESSION_ID,app_id,last_changed_ts);insert_custom_prop(SESSION_ID);if(_session?.app_admin_prop?.app_admin_direction){$(_session.root_element).attr("dir",_session.app_admin_prop.app_admin_direction)}if(_session.engine_mode==="live_preview"){const module=await _this.func.common.get_module(SESSION_ID,"xuda-live-preview-module.esm.js");module.live_preview_loader(SESSION_ID);return}if(_this.APP_OBJ[app_id]?.is_deployment){try{await init_runtime_websocket(SESSION_ID,app_id)}catch(error){throw error}}const module=await _this.func.common.get_module(SESSION_ID,`xuda-progs-loader-module.mjs`);if(app_id!=="unknown"){await module.load_objects_cache(SESSION_ID)}await _this.func.UI.main.embed_loader(SESSION_ID)}catch(error){throw error}};const get_app_build_info=async function(SESSION_ID,app_id){return new Promise(function(resolve,reject){var _session=_this.SESSION_OBJ[SESSION_ID];let app_id_reference=_this.APP_OBJ[app_id].app_id_reference;fetch(_this.func.common.get_url(SESSION_ID,"rpi","get_app_build"),{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json","xu-gtp-token":_session.gtp_token,"xu-app-token":_session.app_token},body:JSON.stringify({app_id:app_id,app_id_reference:app_id_reference})}).then(response=>{if(!response.ok){return response.text().then(text=>{throw new Error(text)})}return response.json()}).then(async json=>{_this.SESSION_OBJ[SESSION_ID].build_info=json.data;resolve(json)}).catch(err=>{try{resolve(JSON.parse(err.message))}catch(error){resolve({code:-1,data:err.message})}})})};const get_user_group_account_info=async function(SESSION_ID){const ret=await func.common.db(SESSION_ID,"get_account_info",{uid_query:$.cookie("uid")});debugger};const get_rt_info=async function(SESSION_ID,app_id,last_changed_ts){var _session=_this.SESSION_OBJ[SESSION_ID];return new Promise(async function(resolve,reject){const response={success:async function(ret,ajaxP){if(ret.code<0){return response.error(ret.data)}const rt_info_obj=ret.data;var app_id=rt_info_obj._id;_this.APP_OBJ[app_id]=rt_info_obj;_session.app_id=app_id;if(rt_info_obj?.deploy_data?.global_variables){_session.url_params={..._session.url_params,...rt_info_obj.deploy_data.global_variables}}_session.USR_OBJ={_id:rt_info_obj?.account_info?.uid,usr_name:rt_info_obj?.account_info?.username,usr_first_name:rt_info_obj?.account_info?.first_name,usr_last_name:rt_info_obj?.account_info?.last_name,usr_email:rt_info_obj?.account_info?.email,usr_profile_picture:rt_info_obj?.account_info?.profile_picture};_session.login_info=rt_info_obj?.login_info;_session.client_ip=rt_info_obj.client_ip;_session.rpi_http_methods=rt_info_obj.rpi_http_methods;_session.app_admin_prop=rt_info_obj.app_admin_prop;_session.is_deployment=rt_info_obj.is_deployment;await get_user_group_account_info(SESSION_ID);resolve();$(".loader_logo").css("background-image",`url( ${rt_info_obj.app_pic})`).hide().fadeIn()},error:async function(err){if(err){return _this.func.UI.utils.progressScreen.show(SESSION_ID,err,null,true)}console.warn("** reload request")}};const db=await func.utils.connect_pouchdb(SESSION_ID);try{let ret=await db.get(`cache_rt_info`);const rt_info_obj=ret.data;if(rt_info_obj.data.last_changed_ts!==last_changed_ts||_session.engine_mode!=="live_preview"&&rt_info_obj.data.app_build_id!==_session.opt.app_build_id){_this.func.UI.utils.progressScreen.show(SESSION_ID,"New application setup detected, refreshing data and reloading in 5 sec");setTimeout(async()=>{await func.index.delete_pouch(SESSION_ID);location.reload()},5e3);return}response.success(rt_info_obj)}catch(err){fetch(_this.func.common.get_url(SESSION_ID,"rpi","get_rt_info"),{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json","xu-gtp-token":_session.gtp_token,"xu-app-token":_session.app_token},body:JSON.stringify({app_id:app_id,prog_id:_session.engine_mode==="live_preview"?"":_session.prog_id,engine_mode:_session.engine_mode,build:_session.build_info.build,session_id:SESSION_ID,is_cordova:_this.glb.is_cordova,client_info:_session.SYS_GLOBAL_OBJ_CLIENT_INFO,client_id:_session.SYS_GLOBAL_OBJ_CLIENT_INFO.fingerprint})}).then(response=>{if(!response.ok){return response.text().then(text=>{throw new Error(text)})}return response.json()}).then(json=>{if(json.code<0){throw new Error(json.data||"unknown error")}response.success(json);var doc={_id:`cache_rt_info`,data:json,docType:"cache_app"};db.put(doc)}).catch(err=>{response.error(err.message)})}})};const insert_custom_prop=function(SESSION_ID){try{var app_id=_this.SESSION_OBJ[SESSION_ID].app_id;if(_this.APP_OBJ[app_id]?.app_custom_prop?.app_custom_header){var head=document.getElementsByTagName("head")[0];const app_custom_header=_this.APP_OBJ[app_id].app_custom_prop.app_custom_header;$(head).append(func.utils.replace_studio_drive_url(SESSION_ID,app_custom_header))}if(_this.APP_OBJ[app_id]?.app_custom_prop?.app_custom_body){$(_this.SESSION_OBJ[SESSION_ID].root_element).prepend(_this.APP_OBJ[app_id].app_custom_prop.app_custom_body)}}catch(err){console.error(err)}};const init_runtime_websocket=function(SESSION_ID,app_id){return new Promise(function(resolve,reject){const set_connected=async function(stat){var datasource_changes={[0]:{["data_system"]:{SYS_GLOBAL_BOL_CONNECTED:stat}}};await func.datasource.update(SESSION_ID,datasource_changes)};var _session=_this.SESSION_OBJ[SESSION_ID];var _data_system=_session?.DS_GLB?.[0]?.data_system;const url=`https://${location.hostname}`;var error;RUNTIME_SERVER_WEBSOCKET=io(url,{secure:true,reconnection:true,rejectUnauthorized:false,path:"/ws/socket.io"});RUNTIME_SERVER_WEBSOCKET.on("connect",()=>{console.info("RUNTIME_SERVER_WEBSOCKET connected");if(_data_system){set_connected(1)}if(_session.opt.enable_offline){if($(_session.root_element).hasClass("runtime_offline")){$(_session.root_element).removeClass("runtime_offline");func.utils.alerts.toast(SESSION_ID,"Switched to on-line mode","You are now online. All data stored while you were offline will be synchronized to the server.","success")}}else{_this.func.UI.utils.progressScreen.hide(SESSION_ID)}if(error){if(!RUNTIME_SERVER_WEBSOCKET_CONNECTED){console.warn("** reload request")}}});RUNTIME_SERVER_WEBSOCKET.on("message",e=>{if(_this.APP_OBJ[app_id].is_deployment){_this.func.UI.utils.indicator.server.busy();setTimeout(function(){_this.func.UI.utils.indicator.server.normal()},e?.data?.length*100||100)}var data=e.data;if(e.source==="http_call"){if(e.service==="get_doc_obj_from_build"){return $("body").trigger("get_doc_obj_from_build_response_"+data._id,{data:data})}if(e.service==="heartbeat"){return $("body").trigger("heartbeat_response",{data:data})}return $("body").trigger("get_ws_data_response_"+e.websocket_queue_num,{data:data,e:e})}if(e.source==="deployment_server"){console.log("document_changed",e);return func.UI.screen.refresh_document_changes_for_realtime_update(SESSION_ID,e.data)}if(data!=="connected")return;RUNTIME_SERVER_WEBSOCKET_CONNECTED=true;resolve()});var callback_done=false;RUNTIME_SERVER_WEBSOCKET.on("connect_error",error=>{if(!callback_done){resolve();callback_done=true;error=true}});RUNTIME_SERVER_WEBSOCKET.on("disconnect",async()=>{RUNTIME_SERVER_WEBSOCKET_CONNECTED=false;if(_data_system){set_connected(0)}if(_session.opt.enable_offline){$(_session.root_element).addClass("runtime_offline");func.utils.alerts.toast(SESSION_ID,"Switched to off-line mode","You have lost connection to the server and are now working offline. Once the connection is restored, all data will be synchronized.","warning")}else{_this.func.UI.utils.progressScreen.show(SESSION_ID,"Your browser has temporarily disconnected from the server. Please wait while we attempt to reconnect.")}});window.addEventListener("beforeunload",function(event){var obj={service:"close_websocket",data:{session_id:SESSION_ID}};RUNTIME_SERVER_WEBSOCKET.emit("message",obj)})})};export const run_plugins_runtime_init=async function(SESSION_ID,app_id,method){var _session=_this.SESSION_OBJ[SESSION_ID];const get_path=function(plugin_name,resource){if(_session.worker_type==="Dev"){return`../../plugins/${_session.domain}/${plugin_name}/${resource}`}return`https://${_session.domain}/plugins/${plugin_name}/runtime/${resource}?gtp_token=${_session.gtp_token}&app_id=${_session.app_id}`};if(!_this.APP_OBJ[app_id].app_plugins_purchased)return;for await(const[key,val]of Object.entries(_this.APP_OBJ[app_id].app_plugins_purchased)){if(!val.installed)continue;if(val.manifest?.[method].mjs?.exist&&!val.manifest[method].mjs.is_empty){const module=await import(get_path(key,method+".mjs"));try{await module.default({SESSION_ID:SESSION_ID})}catch(error){console.error(error)}}}};