@xuda.io/runtime-bundle 1.0.280 → 1.0.282

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,29 @@ 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, uid) {
136
+ // const ret = await func.common.db(SESSION_ID, 'get_account_info', {
137
+ // uid_query: $.cookie('uid'),
138
+ // });
139
+
140
+ var _session = SESSION_OBJ[SESSION_ID];
141
+
142
+ const response = await fetch(`https://${_session.domain}/cpi/get_account_info`, {
143
+ method: 'POST',
144
+ headers: {
145
+ Accept: 'application/json',
146
+ 'Content-Type': 'application/json',
147
+ },
148
+ body: JSON.stringify({
149
+ uid,
150
+ uid_query: $.cookie('uid'),
151
+ }),
152
+ });
153
+ const json = await response.json();
154
+
155
+ return json.data;
156
+ };
157
+
147
158
  const get_rt_info = async function (SESSION_ID, app_id, last_changed_ts) {
148
159
  var _session = _this.SESSION_OBJ[SESSION_ID];
149
160
 
@@ -164,14 +175,21 @@ const get_rt_info = async function (SESSION_ID, app_id, last_changed_ts) {
164
175
  ...rt_info_obj.deploy_data.global_variables,
165
176
  };
166
177
  }
178
+
179
+ let account_info = _session.clone(rt_info_obj?.account_info || {});
180
+ if (_session.engine_mode === 'user_group') {
181
+ const user_group_data = await get_user_group_account_info(SESSION_ID, rt_info_obj?.account_info?.uid);
182
+ account_info = user_group_data.account_info;
183
+ }
167
184
  _session.USR_OBJ = {
168
- _id: rt_info_obj?.account_info?.uid,
169
- usr_name: rt_info_obj?.account_info?.username,
170
- usr_first_name: rt_info_obj?.account_info?.first_name,
171
- usr_last_name: rt_info_obj?.account_info?.last_name,
172
- usr_email: rt_info_obj?.account_info?.email,
173
- usr_profile_picture: rt_info_obj?.account_info?.profile_picture,
185
+ _id: account_info?.uid,
186
+ usr_name: account_info?.username,
187
+ usr_first_name: account_info?.first_name,
188
+ usr_last_name: account_info?.last_name,
189
+ usr_email: account_info?.email,
190
+ usr_profile_picture: account_info?.profile_picture,
174
191
  };
192
+
175
193
  _session.login_info = rt_info_obj?.login_info;
176
194
  _session.client_ip = rt_info_obj.client_ip;
177
195
  _session.rpi_http_methods = rt_info_obj.rpi_http_methods;
@@ -219,37 +237,22 @@ const get_rt_info = async function (SESSION_ID, app_id, last_changed_ts) {
219
237
 
220
238
  resolve();
221
239
 
222
- $(".loader_logo")
223
- .css("background-image", `url( ${rt_info_obj.app_pic})`)
224
- .hide()
225
- .fadeIn();
240
+ $('.loader_logo').css('background-image', `url( ${rt_info_obj.app_pic})`).hide().fadeIn();
226
241
  },
227
242
  error: async function (err) {
228
243
  if (err) {
229
- return _this.func.UI.utils.progressScreen.show(
230
- SESSION_ID,
231
- err,
232
- null,
233
- true
234
- );
244
+ return _this.func.UI.utils.progressScreen.show(SESSION_ID, err, null, true);
235
245
  }
236
246
  // location.reload();
237
- console.warn("** reload request");
247
+ console.warn('** reload request');
238
248
  },
239
249
  };
240
250
  const db = await func.utils.connect_pouchdb(SESSION_ID);
241
251
  try {
242
252
  let ret = await db.get(`cache_rt_info`);
243
253
  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
- );
254
+ 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)) {
255
+ _this.func.UI.utils.progressScreen.show(SESSION_ID, 'New application setup detected, refreshing data and reloading in 5 sec');
253
256
  setTimeout(async () => {
254
257
  await func.index.delete_pouch(SESSION_ID);
255
258
  location.reload();
@@ -259,18 +262,17 @@ const get_rt_info = async function (SESSION_ID, app_id, last_changed_ts) {
259
262
 
260
263
  response.success(rt_info_obj);
261
264
  } catch (err) {
262
- fetch(_this.func.common.get_url(SESSION_ID, "rpi", "get_rt_info"), {
263
- method: "POST",
265
+ fetch(_this.func.common.get_url(SESSION_ID, 'rpi', 'get_rt_info'), {
266
+ method: 'POST',
264
267
  headers: {
265
- Accept: "application/json",
266
- "Content-Type": "application/json",
267
- "xu-gtp-token": _session.gtp_token,
268
- "xu-app-token": _session.app_token,
268
+ Accept: 'application/json',
269
+ 'Content-Type': 'application/json',
270
+ 'xu-gtp-token': _session.gtp_token,
271
+ 'xu-app-token': _session.app_token,
269
272
  },
270
273
  body: JSON.stringify({
271
274
  app_id,
272
- prog_id:
273
- _session.engine_mode === "live_preview" ? "" : _session.prog_id,
275
+ prog_id: _session.engine_mode === 'live_preview' ? '' : _session.prog_id,
274
276
  engine_mode: _session.engine_mode,
275
277
  build: _session.build_info.build,
276
278
  session_id: SESSION_ID,
@@ -291,14 +293,14 @@ const get_rt_info = async function (SESSION_ID, app_id, last_changed_ts) {
291
293
  })
292
294
  .then((json) => {
293
295
  if (json.code < 0) {
294
- throw new Error(json.data || "unknown error");
296
+ throw new Error(json.data || 'unknown error');
295
297
  }
296
298
  response.success(json);
297
299
 
298
300
  var doc = {
299
301
  _id: `cache_rt_info`,
300
302
  data: json,
301
- docType: "cache_app",
303
+ docType: 'cache_app',
302
304
  };
303
305
  db.put(doc);
304
306
  })
@@ -322,18 +324,13 @@ const insert_custom_prop = function (SESSION_ID) {
322
324
  try {
323
325
  var app_id = _this.SESSION_OBJ[SESSION_ID].app_id;
324
326
  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;
327
+ var head = document.getElementsByTagName('head')[0];
328
+ const app_custom_header = _this.APP_OBJ[app_id].app_custom_prop.app_custom_header;
328
329
 
329
- $(head).append(
330
- func.utils.replace_studio_drive_url(SESSION_ID, app_custom_header)
331
- );
330
+ $(head).append(func.utils.replace_studio_drive_url(SESSION_ID, app_custom_header));
332
331
  }
333
332
  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
- );
333
+ $(_this.SESSION_OBJ[SESSION_ID].root_element).prepend(_this.APP_OBJ[app_id].app_custom_prop.app_custom_body);
337
334
  }
338
335
  } catch (err) {
339
336
  console.error(err);
@@ -345,7 +342,7 @@ const init_runtime_websocket = function (SESSION_ID, app_id) {
345
342
  const set_connected = async function (stat) {
346
343
  var datasource_changes = {
347
344
  [0]: {
348
- ["data_system"]: { SYS_GLOBAL_BOL_CONNECTED: stat },
345
+ ['data_system']: { SYS_GLOBAL_BOL_CONNECTED: stat },
349
346
  },
350
347
  };
351
348
  await func.datasource.update(SESSION_ID, datasource_changes);
@@ -362,28 +359,23 @@ const init_runtime_websocket = function (SESSION_ID, app_id) {
362
359
  // reconnection: true,
363
360
  // reconnectionDelayMax: 10000,
364
361
  rejectUnauthorized: false,
365
- path: "/ws/socket.io",
362
+ path: '/ws/socket.io',
366
363
 
367
364
  // transports: ['websocket']
368
365
  // query: { session_obj: SESSION_OBJ[SESSION_ID] },
369
366
  });
370
367
 
371
- RUNTIME_SERVER_WEBSOCKET.on("connect", () => {
372
- console.info("RUNTIME_SERVER_WEBSOCKET connected");
368
+ RUNTIME_SERVER_WEBSOCKET.on('connect', () => {
369
+ console.info('RUNTIME_SERVER_WEBSOCKET connected');
373
370
 
374
371
  if (_data_system) {
375
372
  set_connected(1);
376
373
  }
377
374
 
378
375
  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
- );
376
+ if ($(_session.root_element).hasClass('runtime_offline')) {
377
+ $(_session.root_element).removeClass('runtime_offline');
378
+ 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
379
  }
388
380
  } else {
389
381
  // back from temporarily disconnected from the server
@@ -392,12 +384,12 @@ const init_runtime_websocket = function (SESSION_ID, app_id) {
392
384
  if (error) {
393
385
  if (!RUNTIME_SERVER_WEBSOCKET_CONNECTED) {
394
386
  // location.reload();
395
- console.warn("** reload request");
387
+ console.warn('** reload request');
396
388
  }
397
389
  }
398
390
  });
399
391
 
400
- RUNTIME_SERVER_WEBSOCKET.on("message", (e) => {
392
+ RUNTIME_SERVER_WEBSOCKET.on('message', (e) => {
401
393
  if (_this.APP_OBJ[app_id].is_deployment) {
402
394
  _this.func.UI.utils.indicator.server.busy();
403
395
  setTimeout(function () {
@@ -406,45 +398,36 @@ const init_runtime_websocket = function (SESSION_ID, app_id) {
406
398
  }
407
399
  var data = e.data;
408
400
 
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", {
401
+ if (e.source === 'http_call') {
402
+ if (e.service === 'get_doc_obj_from_build') {
403
+ return $('body').trigger('get_doc_obj_from_build_response_' + data._id, {
420
404
  data,
421
405
  });
422
406
  }
423
- return $("body").trigger(
424
- "get_ws_data_response_" + e.websocket_queue_num,
425
- {
407
+ if (e.service === 'heartbeat') {
408
+ return $('body').trigger('heartbeat_response', {
426
409
  data,
427
- e,
428
- }
429
- );
410
+ });
411
+ }
412
+ return $('body').trigger('get_ws_data_response_' + e.websocket_queue_num, {
413
+ data,
414
+ e,
415
+ });
430
416
  }
431
- if (e.source === "deployment_server") {
432
- console.log("document_changed", e);
417
+ if (e.source === 'deployment_server') {
418
+ console.log('document_changed', e);
433
419
 
434
- return func.UI.screen.refresh_document_changes_for_realtime_update(
435
- SESSION_ID,
436
- e.data
437
- );
420
+ return func.UI.screen.refresh_document_changes_for_realtime_update(SESSION_ID, e.data);
438
421
  }
439
422
 
440
- if (data !== "connected") return;
423
+ if (data !== 'connected') return;
441
424
 
442
425
  RUNTIME_SERVER_WEBSOCKET_CONNECTED = true;
443
426
 
444
427
  resolve();
445
428
  });
446
429
  var callback_done = false;
447
- RUNTIME_SERVER_WEBSOCKET.on("connect_error", (error) => {
430
+ RUNTIME_SERVER_WEBSOCKET.on('connect_error', (error) => {
448
431
  if (!callback_done) {
449
432
  resolve();
450
433
  callback_done = true;
@@ -452,63 +435,46 @@ const init_runtime_websocket = function (SESSION_ID, app_id) {
452
435
  }
453
436
  });
454
437
 
455
- RUNTIME_SERVER_WEBSOCKET.on("disconnect", async () => {
438
+ RUNTIME_SERVER_WEBSOCKET.on('disconnect', async () => {
456
439
  RUNTIME_SERVER_WEBSOCKET_CONNECTED = false;
457
440
  if (_data_system) {
458
441
  set_connected(0);
459
442
  }
460
443
  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
- );
444
+ $(_session.root_element).addClass('runtime_offline');
445
+ 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
446
  } else {
469
447
  // await func.index.delete_pouch();
470
448
  // 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
- );
449
+ _this.func.UI.utils.progressScreen.show(SESSION_ID, 'Your browser has temporarily disconnected from the server. Please wait while we attempt to reconnect.');
475
450
  }
476
451
  });
477
452
 
478
- window.addEventListener("beforeunload", function (event) {
453
+ window.addEventListener('beforeunload', function (event) {
479
454
  var obj = {
480
- service: "close_websocket",
455
+ service: 'close_websocket',
481
456
  data: { session_id: SESSION_ID },
482
457
  };
483
- RUNTIME_SERVER_WEBSOCKET.emit("message", obj);
458
+ RUNTIME_SERVER_WEBSOCKET.emit('message', obj);
484
459
  });
485
460
  });
486
461
  };
487
462
 
488
- export const run_plugins_runtime_init = async function (
489
- SESSION_ID,
490
- app_id,
491
- method
492
- ) {
463
+ export const run_plugins_runtime_init = async function (SESSION_ID, app_id, method) {
493
464
  var _session = _this.SESSION_OBJ[SESSION_ID];
494
465
 
495
466
  const get_path = function (plugin_name, resource) {
496
- if (_session.worker_type === "Dev") {
467
+ if (_session.worker_type === 'Dev') {
497
468
  return `../../plugins/${_session.domain}/${plugin_name}/${resource}`;
498
469
  }
499
470
  return `https://${_session.domain}/plugins/${plugin_name}/runtime/${resource}?gtp_token=${_session.gtp_token}&app_id=${_session.app_id}`;
500
471
  };
501
472
 
502
473
  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
- )) {
474
+ for await (const [key, val] of Object.entries(_this.APP_OBJ[app_id].app_plugins_purchased)) {
506
475
  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"));
476
+ if (val.manifest?.[method].mjs?.exist && !val.manifest[method].mjs.is_empty) {
477
+ const module = await import(get_path(key, method + '.mjs'));
512
478
  try {
513
479
  await module.default({ SESSION_ID: SESSION_ID });
514
480
  } 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,uid){var _session=SESSION_OBJ[SESSION_ID];const response=await fetch(`https://${_session.domain}/cpi/get_account_info`,{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify({uid:uid,uid_query:$.cookie("uid")})});const json=await response.json();return json.data};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}}let account_info=_session.clone(rt_info_obj?.account_info||{});if(_session.engine_mode==="user_group"){const user_group_data=await get_user_group_account_info(SESSION_ID,rt_info_obj?.account_info?.uid);account_info=user_group_data.account_info}_session.USR_OBJ={_id:account_info?.uid,usr_name:account_info?.username,usr_first_name:account_info?.first_name,usr_last_name:account_info?.last_name,usr_email:account_info?.email,usr_profile_picture: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)}}}};