@xuda.io/account_module 1.2.2072 → 1.2.2073

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.
Files changed (2) hide show
  1. package/index.mjs +122 -122
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -77,7 +77,7 @@ export const update_account_info = async function (req, job_id, headers) {
77
77
  }
78
78
  }
79
79
 
80
- const ret = await db_ms.get_couch_doc('xuda_accounts', uid);
80
+ const ret = await db_module.get_couch_doc('xuda_accounts', uid);
81
81
  var account_obj = ret.data;
82
82
  account_obj.ts = Date.now();
83
83
  var change = '';
@@ -170,7 +170,7 @@ export const update_account_info = async function (req, job_id, headers) {
170
170
  delete account_obj.account_info.job_id;
171
171
  delete account_obj.account_info.app_id;
172
172
 
173
- const save_ret = await db_ms.save_couch_doc('xuda_accounts', account_obj);
173
+ const save_ret = await db_module.save_couch_doc('xuda_accounts', account_obj);
174
174
 
175
175
  if (account_obj.account_info?.profile_picture) {
176
176
  if (!account_obj.account_info?.profile_avatar && account_obj.account_info.profile_avatar_stat !== 2) {
@@ -187,12 +187,12 @@ export const update_account_info = async function (req, job_id, headers) {
187
187
  export const update_account_preferences = async function (req) {
188
188
  const { uid, hide_create_button, default_dashboard, sidebar_style } = req;
189
189
  try {
190
- let account_doc = await db_ms.get_couch_doc_native('xuda_accounts', uid);
190
+ let account_doc = await db_module.get_couch_doc_native('xuda_accounts', uid);
191
191
  account_doc.ts = Date.now();
192
192
 
193
193
  account_doc.preferences = { hide_create_button, default_dashboard, sidebar_style };
194
194
 
195
- const save_ret = await db_ms.save_couch_doc('xuda_accounts', account_doc);
195
+ const save_ret = await db_module.save_couch_doc('xuda_accounts', account_doc);
196
196
  if (save_ret.code < 0) {
197
197
  throw new Error(save_ret.data);
198
198
  }
@@ -203,7 +203,7 @@ export const update_account_preferences = async function (req) {
203
203
  };
204
204
 
205
205
  export const save_admin_presets = async function (req) {
206
- const ret = await db_ms.get_couch_doc('xuda_master', req.app_id);
206
+ const ret = await db_module.get_couch_doc('xuda_master', req.app_id);
207
207
  if (ret.code < 0) {
208
208
  return ret;
209
209
  }
@@ -211,7 +211,7 @@ export const save_admin_presets = async function (req) {
211
211
  app_obj.deploy_data.admin_presets = req.admin_presets;
212
212
  app_obj.deploy_data.preset_id = req.preset_id;
213
213
 
214
- const ret3 = await db_ms.save_app_obj(app_obj, null, req.app_id);
214
+ const ret3 = await db_module.save_app_obj(app_obj, null, req.app_id);
215
215
  var obj = {};
216
216
  if (ret3.code > -1) {
217
217
  obj = {
@@ -233,7 +233,7 @@ export const increment_account_usage = async function (req) {
233
233
  if (uid) {
234
234
  opt.key = uid;
235
235
  }
236
- const accounts_ret = await db_ms.get_couch_view_raw('xuda_accounts', 'all_accounts', opt);
236
+ const accounts_ret = await db_module.get_couch_view_raw('xuda_accounts', 'all_accounts', opt);
237
237
 
238
238
  function bytesToGB(bytes) {
239
239
  return bytes / 1073741824; // or bytes / (1024 ** 3)
@@ -246,7 +246,7 @@ export const increment_account_usage = async function (req) {
246
246
  try {
247
247
  const usage_id = await _common.xuda_get_uuid('usage');
248
248
 
249
- const usage_ret = await db_ms.get_couch_view_raw('xuda_usage', 'open_drive_usage', {
249
+ const usage_ret = await db_module.get_couch_view_raw('xuda_usage', 'open_drive_usage', {
250
250
  key: account_data._id,
251
251
  });
252
252
 
@@ -280,7 +280,7 @@ export const increment_account_usage = async function (req) {
280
280
  doc.price += price_per_hour;
281
281
 
282
282
  doc.ts = Date.now();
283
- await db_ms.save_couch_doc('xuda_usage', doc);
283
+ await db_module.save_couch_doc('xuda_usage', doc);
284
284
  }
285
285
  }
286
286
  } catch (err) {
@@ -289,7 +289,7 @@ export const increment_account_usage = async function (req) {
289
289
  };
290
290
 
291
291
  const run_account_apps = async function (account_data) {
292
- const apps_ret = await db_ms.get_couch_view('xuda_master', 'user_apps', {
292
+ const apps_ret = await db_module.get_couch_view('xuda_master', 'user_apps', {
293
293
  startkey: [account_data._id, ''],
294
294
  endkey: [account_data._id, 'ZZZZZ'],
295
295
  include_docs: true,
@@ -323,13 +323,13 @@ export const increment_account_usage = async function (req) {
323
323
  if (size_ret.code > -1) account_data.plugins_drive_size += size_ret.data;
324
324
 
325
325
  // db data
326
- const couch_info_ret = await db_ms.get_couch_app_info(app.id);
326
+ const couch_info_ret = await db_module.get_couch_app_info(app.id);
327
327
  account_data.project_data_size += couch_info_ret?.data?.sizes?.active || 0;
328
328
  }
329
329
 
330
330
  const usage_id = await _common.xuda_get_uuid('usage');
331
331
 
332
- const usage_ret = await db_ms.get_couch_view_raw('xuda_usage', 'open_app_usage', {
332
+ const usage_ret = await db_module.get_couch_view_raw('xuda_usage', 'open_app_usage', {
333
333
  key: [app.id, app.doc?.app_hosting?.app_server_type || app.doc.app_type],
334
334
  });
335
335
 
@@ -382,7 +382,7 @@ export const increment_account_usage = async function (req) {
382
382
  } else {
383
383
  // backup of project
384
384
 
385
- const info_ret = await db_ms.get_couch_app_info(doc.app_id);
385
+ const info_ret = await db_module.get_couch_app_info(doc.app_id);
386
386
  if (info_ret.code > 0) {
387
387
  const size = info_ret.data.sizes.active / 1000 / 1000 / 1000; //gb
388
388
  price_per_hour = (size * _conf.PRICE_OBJ.price_per_gb_backup) / _conf.PRICE_OBJ.avg_hours_in_month;
@@ -391,7 +391,7 @@ export const increment_account_usage = async function (req) {
391
391
  break;
392
392
 
393
393
  case 'user_group': {
394
- const team_ret = await db_ms.get_couch_view('xuda_team', 'user_group_shares_count', {
394
+ const team_ret = await db_module.get_couch_view('xuda_team', 'user_group_shares_count', {
395
395
  key: app.id,
396
396
  reduce: true,
397
397
  group_level: 1,
@@ -421,7 +421,7 @@ export const increment_account_usage = async function (req) {
421
421
  }
422
422
 
423
423
  doc.ts = Date.now();
424
- await db_ms.save_couch_doc('xuda_usage', doc);
424
+ await db_module.save_couch_doc('xuda_usage', doc);
425
425
  }
426
426
  }
427
427
  } catch (err) {
@@ -449,7 +449,7 @@ export const increment_account_usage = async function (req) {
449
449
  await run_account_drive(account_data);
450
450
 
451
451
  account_data.total_drive_size = account_data.user_drive_size + account_data.studio_drive_size + account_data.workspace_drive_size + account_data.plugins_drive_size + account_data.builds_drive_size + account_data.project_data_size;
452
- await db_ms.save_couch_doc('xuda_accounts', account_data);
452
+ await db_module.save_couch_doc('xuda_accounts', account_data);
453
453
  }
454
454
  };
455
455
 
@@ -457,11 +457,11 @@ export const get_account_data = async function (req) {
457
457
  var { uid, enforce_usage } = req;
458
458
 
459
459
  try {
460
- const { data: acc_obj } = await db_ms.get_couch_doc('xuda_accounts', uid);
460
+ const { data: acc_obj } = await db_module.get_couch_doc('xuda_accounts', uid);
461
461
 
462
462
  // let _design;
463
463
  // if (acc_obj.account_project_id) {
464
- // _design = await db_ms.get_app_couch_doc_native(acc_obj.account_project_id, '_design/xuda');
464
+ // _design = await db_module.get_app_couch_doc_native(acc_obj.account_project_id, '_design/xuda');
465
465
  // }
466
466
 
467
467
  var ret = { code: 1 };
@@ -526,23 +526,23 @@ export const get_account_projects = async function (req) {
526
526
  opt = {};
527
527
  }
528
528
 
529
- var ret = await db_ms.get_couch_view('xuda_master', 'user_projects', opt);
529
+ var ret = await db_module.get_couch_view('xuda_master', 'user_projects', opt);
530
530
 
531
531
  return ret;
532
532
  };
533
533
 
534
534
  export const get_account_datacenters = async function (req) {
535
- return await db_ms.get_couch_view('xuda_master', 'user_datacenters', {
535
+ return await db_module.get_couch_view('xuda_master', 'user_datacenters', {
536
536
  key: req.uid,
537
537
  });
538
538
  };
539
539
  export const get_account_deployments = async function (req) {
540
- return await db_ms.get_couch_view('xuda_master', 'user_deployments', {
540
+ return await db_module.get_couch_view('xuda_master', 'user_deployments', {
541
541
  key: req.uid,
542
542
  });
543
543
  };
544
544
  export const get_account_instances = async function (req) {
545
- return await db_ms.get_couch_view('xuda_master', 'user_all_instances', {
545
+ return await db_module.get_couch_view('xuda_master', 'user_all_instances', {
546
546
  key: req.uid,
547
547
  });
548
548
  };
@@ -556,11 +556,11 @@ export const get_account_info = async function (req) {
556
556
 
557
557
  export const get_active_account_profile_info = async function (uid, profile_id) {
558
558
  try {
559
- const acc_obj = await db_ms.get_couch_doc_native('xuda_accounts', uid);
559
+ const acc_obj = await db_module.get_couch_doc_native('xuda_accounts', uid);
560
560
 
561
561
  let active_account_profile_id = profile_id || acc_obj.account_info.active_account_profile_id;
562
562
 
563
- const account_profile_obj = await db_ms.get_app_couch_doc_native(acc_obj.account_project_id, active_account_profile_id);
563
+ const account_profile_obj = await db_module.get_app_couch_doc_native(acc_obj.account_project_id, active_account_profile_id);
564
564
  if (account_profile_obj.share_item_id) {
565
565
  // set the original profile id if shared
566
566
  active_account_profile_id = account_profile_obj.share_item_id;
@@ -575,7 +575,7 @@ export const get_active_account_profile_info = async function (uid, profile_id)
575
575
  };
576
576
 
577
577
  export const get_account_name = async function (req) {
578
- const data = await db_ms.get_couch_doc('xuda_accounts', req.uid_query || req.uid);
578
+ const data = await db_module.get_couch_doc('xuda_accounts', req.uid_query || req.uid);
579
579
  if (data.code < 0) {
580
580
  return data;
581
581
  }
@@ -638,7 +638,7 @@ export const account_validate_username = async function (req) {
638
638
  limit: 1,
639
639
  };
640
640
 
641
- var ret = await db_ms.find_couch_query('xuda_accounts', opt);
641
+ var ret = await db_module.find_couch_query('xuda_accounts', opt);
642
642
 
643
643
  if (ret.docs.length) {
644
644
  return { code: -400, data: 'User exist' };
@@ -648,7 +648,7 @@ export const account_validate_username = async function (req) {
648
648
  };
649
649
 
650
650
  // export const get_account_activity = async function (req) {
651
- // return await db_ms.get_couch_view(
651
+ // return await db_module.get_couch_view(
652
652
  // "xuda_activity",
653
653
  // "activity_per_account",
654
654
  // {
@@ -663,14 +663,14 @@ export const verify_account = async function (req) {
663
663
  return { code: -10, data: 'Missing id' };
664
664
  }
665
665
 
666
- const ret = await db_ms.get_couch_doc('xuda_accounts', account_id);
666
+ const ret = await db_module.get_couch_doc('xuda_accounts', account_id);
667
667
 
668
668
  if (ret.code < 0) {
669
669
  return { code: -1, data: 'account not found' };
670
670
  }
671
671
  var obj = ret.data;
672
672
  obj.stat = 3;
673
- const ret_acc = await db_ms.save_couch_doc('xuda_accounts', obj);
673
+ const ret_acc = await db_module.save_couch_doc('xuda_accounts', obj);
674
674
  if (ret.code < 0) {
675
675
  return ret_acc;
676
676
  }
@@ -680,7 +680,7 @@ export const verify_account = async function (req) {
680
680
  export const validate_user_plan = async function (req) {
681
681
  const { account_id, app_obj } = req;
682
682
 
683
- const apps_ret = await db_ms.get_couch_view('xuda_master', 'user_apps_count', {
683
+ const apps_ret = await db_module.get_couch_view('xuda_master', 'user_apps_count', {
684
684
  startkey: [account_id, ''],
685
685
  endkey: [account_id, 'ZZZZZ'],
686
686
  reduce: true,
@@ -696,7 +696,7 @@ export const validate_user_plan = async function (req) {
696
696
  {},
697
697
  );
698
698
 
699
- const ret = await db_ms.get_couch_doc('xuda_accounts', account_id);
699
+ const ret = await db_module.get_couch_doc('xuda_accounts', account_id);
700
700
  if (ret.code < 0) {
701
701
  return ret;
702
702
  }
@@ -717,7 +717,7 @@ export const validate_user_plan = async function (req) {
717
717
 
718
718
  // validate number of team members
719
719
 
720
- const user_active_app_requests_count_ret = await db_ms.get_couch_view('xuda_team', 'user_active_app_requests_count', {
720
+ const user_active_app_requests_count_ret = await db_module.get_couch_view('xuda_team', 'user_active_app_requests_count', {
721
721
  key: account_id,
722
722
  reduce: true,
723
723
  // group_level: 2,
@@ -816,7 +816,7 @@ export const save_ssh_key = async function (req) {
816
816
  };
817
817
 
818
818
  if (_id) {
819
- const ret = await db_ms.get_couch_doc('xuda_ssh_keys', _id);
819
+ const ret = await db_module.get_couch_doc('xuda_ssh_keys', _id);
820
820
  if (ret.code < 0) {
821
821
  return ret;
822
822
  }
@@ -829,14 +829,14 @@ export const save_ssh_key = async function (req) {
829
829
  doc.ssh_key_name = ssh_key_name;
830
830
  doc.ssh_key_content = ssh_key_content;
831
831
 
832
- const save_ret = await db_ms.save_couch_doc('xuda_ssh_keys', doc);
832
+ const save_ret = await db_module.save_couch_doc('xuda_ssh_keys', doc);
833
833
 
834
834
  return save_ret;
835
835
  };
836
836
  export const delete_ssh_key = async function (req) {
837
837
  const { ssh_key_id } = req;
838
838
 
839
- const ret = await db_ms.get_couch_doc('xuda_ssh_keys', ssh_key_id);
839
+ const ret = await db_module.get_couch_doc('xuda_ssh_keys', ssh_key_id);
840
840
  if (ret.code < 0) {
841
841
  return ret;
842
842
  }
@@ -844,7 +844,7 @@ export const delete_ssh_key = async function (req) {
844
844
  doc.date_updated_ts = Date.now();
845
845
  doc.stat = 4;
846
846
 
847
- const save_ret = await db_ms.save_couch_doc('xuda_ssh_keys', doc);
847
+ const save_ret = await db_module.save_couch_doc('xuda_ssh_keys', doc);
848
848
 
849
849
  return save_ret;
850
850
  };
@@ -860,7 +860,7 @@ export const get_ssh_keys = async function (req) {
860
860
  opt.selector._id = _id;
861
861
  }
862
862
 
863
- var ret = await db_ms.find_couch_query('xuda_ssh_keys', opt);
863
+ var ret = await db_module.find_couch_query('xuda_ssh_keys', opt);
864
864
  return ret;
865
865
  };
866
866
 
@@ -943,7 +943,7 @@ export const search_users = async function (req) {
943
943
  }
944
944
 
945
945
  try {
946
- var ret = await db_ms.find_couch_query('xuda_accounts', opt);
946
+ var ret = await db_module.find_couch_query('xuda_accounts', opt);
947
947
 
948
948
  let docs = [];
949
949
  for await (let e of ret.docs) {
@@ -1273,7 +1273,7 @@ export const get_contact_info = async function (uid, contact_doc, _id) {
1273
1273
  const chat_conversation_count = async function () {
1274
1274
  const account_profile_info = await get_active_account_profile_info(uid);
1275
1275
 
1276
- const counts_ret = await db_ms.get_app_couch_view(account_profile_info.app_id, 'chat_conversation_item_counts', {
1276
+ const counts_ret = await db_module.get_app_couch_view(account_profile_info.app_id, 'chat_conversation_item_counts', {
1277
1277
  reduce: true,
1278
1278
  group_level: 1,
1279
1279
 
@@ -1286,7 +1286,7 @@ export const get_contact_info = async function (uid, contact_doc, _id) {
1286
1286
  const chat_conversation_read = async function () {
1287
1287
  const account_profile_info = await get_active_account_profile_info(uid);
1288
1288
 
1289
- const counts_ret = await db_ms.get_app_couch_view(account_profile_info.app_id, 'chat_conversation_item_read', {
1289
+ const counts_ret = await db_module.get_app_couch_view(account_profile_info.app_id, 'chat_conversation_item_read', {
1290
1290
  reduce: true,
1291
1291
  group_level: 2,
1292
1292
 
@@ -1321,7 +1321,7 @@ export const get_contact_info = async function (uid, contact_doc, _id) {
1321
1321
 
1322
1322
  if (doc.team_req_id) {
1323
1323
  try {
1324
- const req_doc = await db_ms.get_couch_doc_native('xuda_team', doc.team_req_id);
1324
+ const req_doc = await db_module.get_couch_doc_native('xuda_team', doc.team_req_id);
1325
1325
  doc.connection_stat = req_doc.team_req_stat;
1326
1326
  doc.connection_type = req_doc.access_type;
1327
1327
  doc.connection_uid = req_doc.team_req_from_uid === uid ? req_doc.team_req_to_uid : req_doc.team_req_from_uid;
@@ -1332,7 +1332,7 @@ export const get_contact_info = async function (uid, contact_doc, _id) {
1332
1332
  if (doc.connection_type === 'account_profile') {
1333
1333
  try {
1334
1334
  const app_id = await get_account_default_project_id(uid);
1335
- const account_profile_doc = await db_ms.get_app_couch_doc_native(app_id, req_doc.share_item_id);
1335
+ const account_profile_doc = await db_module.get_app_couch_doc_native(app_id, req_doc.share_item_id);
1336
1336
  doc.account_profile = account_profile_doc;
1337
1337
  } catch (error) {}
1338
1338
  }
@@ -1396,7 +1396,7 @@ export const get_pending_contact_out = async function (uid, _id) {
1396
1396
  if (_id) {
1397
1397
  to_opt.selector._id = _id;
1398
1398
  }
1399
- const requests_to_res = await db_ms.find_couch_query('xuda_team', to_opt);
1399
+ const requests_to_res = await db_module.find_couch_query('xuda_team', to_opt);
1400
1400
 
1401
1401
  for await (let e of requests_to_res.docs) {
1402
1402
  let doc = { docType: 'contact', date_created: e.team_req_date, email: [e.team_req_to_email], name: '', pending: true, contact_uid: e.team_req_to_uid, team_req_id: e._id, team_req_from_uid: uid };
@@ -1427,7 +1427,7 @@ export const get_pending_contact_in = async function (uid, _id) {
1427
1427
  to_opt.selector._id = _id;
1428
1428
  }
1429
1429
 
1430
- const requests_from_res = await db_ms.find_couch_query('xuda_team', from_opt);
1430
+ const requests_from_res = await db_module.find_couch_query('xuda_team', from_opt);
1431
1431
 
1432
1432
  for await (let e of requests_from_res.docs) {
1433
1433
  let doc = { docType: 'contact', date_created: e.team_req_date, email: [e.sender_account_info.email], name: '', pending: true, contact_uid: e.team_req_from_uid, team_req_id: e._id };
@@ -1456,7 +1456,7 @@ export const get_pending_share_contact_in = async function (uid, _id) {
1456
1456
  to_opt.selector._id = _id;
1457
1457
  }
1458
1458
 
1459
- const requests_from_res = await db_ms.find_couch_query('xuda_team', from_opt);
1459
+ const requests_from_res = await db_module.find_couch_query('xuda_team', from_opt);
1460
1460
 
1461
1461
  for await (let e of requests_from_res.docs) {
1462
1462
  let doc = await get_contact(uid, e.share_item_id);
@@ -1524,7 +1524,7 @@ export const update_contact = async function (req) {
1524
1524
  }
1525
1525
 
1526
1526
  if (contact_uid) {
1527
- const ret = await db_ms.get_couch_doc('xuda_accounts', contact_uid);
1527
+ const ret = await db_module.get_couch_doc('xuda_accounts', contact_uid);
1528
1528
  const account_obj = ret.data;
1529
1529
  doc.profile_picture = account_obj.account_info.profile_picture;
1530
1530
  doc.profile_avatar = account_obj.account_info.profile_avatar;
@@ -1536,7 +1536,7 @@ export const update_contact = async function (req) {
1536
1536
  };
1537
1537
 
1538
1538
  export const get_account_rt_info = async function (uid) {
1539
- const doc_ret = await db_ms.get_couch_doc('xuda_accounts', uid);
1539
+ const doc_ret = await db_module.get_couch_doc('xuda_accounts', uid);
1540
1540
  if (doc_ret.code < 0) {
1541
1541
  console.error('get_account_rt_info', doc_ret);
1542
1542
  return {};
@@ -1687,7 +1687,7 @@ export const create_account_oauth_link = async function (req, job_id) {
1687
1687
  };
1688
1688
 
1689
1689
  export const get_default_project_account_doc = async function (uid) {
1690
- const ret = await db_ms.get_couch_doc('xuda_accounts', uid);
1690
+ const ret = await db_module.get_couch_doc('xuda_accounts', uid);
1691
1691
  return ret.data;
1692
1692
  };
1693
1693
  export const get_account_default_project_id = async function (uid) {
@@ -1743,7 +1743,7 @@ export const onboarding_completed = async function (req, job_id, headers) {
1743
1743
  try {
1744
1744
  await update_account_info(req, job_id, headers);
1745
1745
 
1746
- let account_doc = await db_ms.get_couch_doc_native('xuda_accounts', uid);
1746
+ let account_doc = await db_module.get_couch_doc_native('xuda_accounts', uid);
1747
1747
 
1748
1748
  if (!account_doc.account_info?.profile_picture) {
1749
1749
  throw new Error(`missing profile_picture`);
@@ -1757,7 +1757,7 @@ export const onboarding_completed = async function (req, job_id, headers) {
1757
1757
 
1758
1758
  account_doc.boarded_info = { headers, date_ts: Date.now() };
1759
1759
  account_doc.isBoarded = true;
1760
- const save_ret = await db_ms.save_couch_doc('xuda_accounts', account_doc);
1760
+ const save_ret = await db_module.save_couch_doc('xuda_accounts', account_doc);
1761
1761
 
1762
1762
  return save_ret;
1763
1763
  } catch (err) {
@@ -1783,7 +1783,7 @@ export const get_account_ai_usage = async function (req, job_id, headers) {
1783
1783
  const curr_month = Number(String(d.getMonth() + 1).padStart(2, '0')); // months are 0-based
1784
1784
  const curr_year = d.getFullYear();
1785
1785
 
1786
- const ai_usage = await db_ms.get_couch_view('xuda_usage', 'ai_usage', {
1786
+ const ai_usage = await db_module.get_couch_view('xuda_usage', 'ai_usage', {
1787
1787
  startkey: [uid, year || curr_year, month || curr_month, day || 0],
1788
1788
  endkey: [uid, year || curr_year, month || curr_month, day || 99],
1789
1789
  reduce: true,
@@ -1822,7 +1822,7 @@ export const get_account_ai_usage = async function (req, job_id, headers) {
1822
1822
  // let contact_connection = 0;
1823
1823
  // let total_credits = membership_plan + ai_workspace_plan + contact_connection;
1824
1824
 
1825
- const ai_credits = await db_ms.get_couch_view('xuda_billing', 'ai_credits', {
1825
+ const ai_credits = await db_module.get_couch_view('xuda_billing', 'ai_credits', {
1826
1826
  startkey: [uid, ''],
1827
1827
  endkey: [uid, 'zzz'],
1828
1828
  reduce: true,
@@ -1858,7 +1858,7 @@ const set_account_profile_picture = async function (uid, account_uid, metadata,
1858
1858
  try {
1859
1859
  let profile_picture;
1860
1860
 
1861
- let { code: account_code, data: account_obj } = await db_ms.get_couch_doc('xuda_accounts', account_uid);
1861
+ let { code: account_code, data: account_obj } = await db_module.get_couch_doc('xuda_accounts', account_uid);
1862
1862
  let account_info = account_obj.account_info;
1863
1863
 
1864
1864
  if (account_code < 0) {
@@ -1871,7 +1871,7 @@ const set_account_profile_picture = async function (uid, account_uid, metadata,
1871
1871
  if (!account_info.profile_picture) {
1872
1872
  const file_ret = await ai_ms.get_profile_picture(uid, account_info.account_type, name, { email: account_info.email, metadata, account_info }, account_profile_info, job_id, headers);
1873
1873
 
1874
- let { code: account_code, data: account_obj2 } = await db_ms.get_couch_doc('xuda_accounts', account_uid);
1874
+ let { code: account_code, data: account_obj2 } = await db_module.get_couch_doc('xuda_accounts', account_uid);
1875
1875
  account_obj = account_obj2;
1876
1876
  account_info = account_obj.account_info;
1877
1877
 
@@ -1880,7 +1880,7 @@ const set_account_profile_picture = async function (uid, account_uid, metadata,
1880
1880
 
1881
1881
  account_info.profile_picture = account_info.profile_picture_obj.file_url;
1882
1882
  account_info.profile_picture_source = file_ret.profile_picture_source;
1883
- const account_save_ret = await db_ms.save_couch_doc('xuda_accounts', account_obj);
1883
+ const account_save_ret = await db_module.save_couch_doc('xuda_accounts', account_obj);
1884
1884
  profile_picture = account_info.profile_picture;
1885
1885
  }
1886
1886
 
@@ -1925,7 +1925,7 @@ const set_account_profile_picture = async function (uid, account_uid, metadata,
1925
1925
  if (file_ret.code < 0) {
1926
1926
  throw new Error(file_ret.data);
1927
1927
  }
1928
- let { code: account_code, data: account_obj3 } = await db_ms.get_couch_doc('xuda_accounts', account_uid);
1928
+ let { code: account_code, data: account_obj3 } = await db_module.get_couch_doc('xuda_accounts', account_uid);
1929
1929
  account_obj = account_obj3;
1930
1930
  account_info = account_obj.account_info;
1931
1931
 
@@ -1933,7 +1933,7 @@ const set_account_profile_picture = async function (uid, account_uid, metadata,
1933
1933
  account_info.profile_avatar_obj = file_ret.data;
1934
1934
  account_info.profile_avatar = account_info.profile_avatar_obj.file_url;
1935
1935
 
1936
- const account_save_ret = await db_ms.save_couch_doc('xuda_accounts', account_obj);
1936
+ const account_save_ret = await db_module.save_couch_doc('xuda_accounts', account_obj);
1937
1937
  await update_account_profile_picture_status(account_uid, 3);
1938
1938
  }
1939
1939
  } catch (err) {
@@ -1954,7 +1954,7 @@ setTimeout(async () => {
1954
1954
  // ret = await create_account_profile({ uid });
1955
1955
  // ret = await get_account_profiles({ uid });
1956
1956
 
1957
- // let _design = await db_ms.get_app_couch_doc_native(app_id, '_design/xuda');
1957
+ // let _design = await db_module.get_app_couch_doc_native(app_id, '_design/xuda');
1958
1958
  // ret = _design.views.ai_chat_usage;
1959
1959
  // console.log(_design.views.ai_chat_usage);
1960
1960
  // ret = await set_contact_profile_picture(uid, 'cnt_2d21d55f8f0cdaf65a7a69f69617f532', {}, null, {});
@@ -2023,7 +2023,7 @@ export const add_contact = async function (req, job_id, headers) {
2023
2023
  let cached_contact;
2024
2024
  let business_has_person;
2025
2025
  if (contact_uid) {
2026
- let { code: account_code, data: account_obj } = await db_ms.get_couch_doc('xuda_accounts', contact_uid);
2026
+ let { code: account_code, data: account_obj } = await db_module.get_couch_doc('xuda_accounts', contact_uid);
2027
2027
  // account_info = account_obj.account_info;
2028
2028
  // account_info_ret = await get_account_name({ uid_query: contact_uid });
2029
2029
  if (account_code < 0) {
@@ -2123,7 +2123,7 @@ const set_contact_profile_picture = async function (uid, contact_id, metadata, j
2123
2123
  try {
2124
2124
  // let profile_picture;
2125
2125
 
2126
- const contact_ret = await db_ms.get_app_couch_doc(account_profile_info.app_id, contact_id);
2126
+ const contact_ret = await db_module.get_app_couch_doc(account_profile_info.app_id, contact_id);
2127
2127
 
2128
2128
  if (contact_ret.code < 0) {
2129
2129
  throw new Error(`contact ${contact_id} not found`);
@@ -2163,13 +2163,13 @@ const set_contact_profile_picture = async function (uid, contact_id, metadata, j
2163
2163
  }
2164
2164
  }
2165
2165
  if (file_ret?.data?.file_url) {
2166
- let { code: contact_code, data: contact_obj2 } = await db_ms.get_app_couch_doc(account_profile_info.app_id, contact_id);
2166
+ let { code: contact_code, data: contact_obj2 } = await db_module.get_app_couch_doc(account_profile_info.app_id, contact_id);
2167
2167
  contact_obj = contact_obj2;
2168
2168
  contact_obj.profile_picture_obj = file_ret.data;
2169
2169
  contact_obj.profile_picture = contact_obj.profile_picture_obj.file_url;
2170
2170
  contact_obj.profile_picture_source = file_ret.profile_picture_source;
2171
2171
 
2172
- const contact_save_ret = await db_ms.save_app_couch_doc(account_profile_info.app_id, contact_obj);
2172
+ const contact_save_ret = await db_module.save_app_couch_doc(account_profile_info.app_id, contact_obj);
2173
2173
  // profile_picture = contact_obj.profile_picture;
2174
2174
  }
2175
2175
  }
@@ -2219,7 +2219,7 @@ const set_contact_profile_picture = async function (uid, contact_id, metadata, j
2219
2219
  if (file_ret.data === 'Input file contains unsupported image format') {
2220
2220
  contact_obj.profile_picture = null;
2221
2221
  contact_obj.profile_picture_obj = null;
2222
- const contact_save_ret = await db_ms.save_app_couch_doc(account_profile_info.app_id, contact_obj);
2222
+ const contact_save_ret = await db_module.save_app_couch_doc(account_profile_info.app_id, contact_obj);
2223
2223
  }
2224
2224
  throw new Error(file_ret.data);
2225
2225
  }
@@ -2248,12 +2248,12 @@ const set_contact_profile_picture = async function (uid, contact_id, metadata, j
2248
2248
  // save_xuda_cache(uid, 'profile_avatar', contact_obj.email, file_ret.data, { account_type: contact_obj.account_type, type: 'contact' });
2249
2249
  }
2250
2250
 
2251
- let { code: contact_code, data: contact_obj3 } = await db_ms.get_app_couch_doc(account_profile_info.app_id, contact_id);
2251
+ let { code: contact_code, data: contact_obj3 } = await db_module.get_app_couch_doc(account_profile_info.app_id, contact_id);
2252
2252
  contact_obj = contact_obj3;
2253
2253
  contact_obj.profile_avatar_obj = file_ret.data;
2254
2254
  contact_obj.profile_avatar = contact_obj?.profile_avatar_obj?.file_url;
2255
2255
  contact_obj.avatar_source = file_ret?.data?.avatar_source;
2256
- const contact_save_ret = await db_ms.save_app_couch_doc(account_profile_info.app_id, contact_obj);
2256
+ const contact_save_ret = await db_module.save_app_couch_doc(account_profile_info.app_id, contact_obj);
2257
2257
  }
2258
2258
  await update_contact_profile_picture_status(uid, contact_id, 3);
2259
2259
  } catch (err) {
@@ -2264,11 +2264,11 @@ const set_contact_profile_picture = async function (uid, contact_id, metadata, j
2264
2264
 
2265
2265
  const update_account_profile_picture_status = async function (uid, stat, error) {
2266
2266
  try {
2267
- let doc = await db_ms.get_couch_doc_native('xuda_accounts', uid);
2267
+ let doc = await db_module.get_couch_doc_native('xuda_accounts', uid);
2268
2268
  doc.account_info.profile_avatar_stat = stat;
2269
2269
  doc.account_info.profile_avatar_error = error;
2270
2270
  doc.account_info.profile_avatar_stat_ts = Date.now();
2271
- const save_ret = await db_ms.save_couch_doc_native('xuda_accounts', doc);
2271
+ const save_ret = await db_module.save_couch_doc_native('xuda_accounts', doc);
2272
2272
  } catch (err) {
2273
2273
  console.error(err);
2274
2274
  }
@@ -2277,12 +2277,12 @@ const update_account_profile_picture_status = async function (uid, stat, error)
2277
2277
  const update_contact_profile_picture_status = async function (uid, contact_id, stat, error) {
2278
2278
  const account_profile_info = await get_active_account_profile_info(uid);
2279
2279
  try {
2280
- let doc = await db_ms.get_app_couch_doc_native(account_profile_info.app_id, contact_id);
2280
+ let doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, contact_id);
2281
2281
  doc.profile_avatar_stat = stat;
2282
2282
  doc.profile_avatar_error = error;
2283
2283
  doc.profile_avatar_stat_ts = Date.now();
2284
2284
 
2285
- const save_ret = await db_ms.save_app_couch_doc_native(account_profile_info.app_id, doc);
2285
+ const save_ret = await db_module.save_app_couch_doc_native(account_profile_info.app_id, doc);
2286
2286
  } catch (err) {
2287
2287
  console.error(err);
2288
2288
  }
@@ -2533,15 +2533,15 @@ export const unfriend_contact = async function (req) {
2533
2533
  if (!contact_doc.team_req_id) {
2534
2534
  throw new Error('no friend relationship found');
2535
2535
  }
2536
- let req_doc = await db_ms.get_couch_doc_native('xuda_team', contact_doc.team_req_id);
2536
+ let req_doc = await db_module.get_couch_doc_native('xuda_team', contact_doc.team_req_id);
2537
2537
  req_doc.team_req_stat = 4;
2538
2538
  req_doc.team_req_stat_desc = 'unfriend by the user';
2539
- await db_ms.get_couch_doc_native('xuda_team', contact_doc.team_req_id);
2539
+ await db_module.get_couch_doc_native('xuda_team', contact_doc.team_req_id);
2540
2540
 
2541
2541
  contact_doc.team_req_id = null;
2542
2542
  const contact_save_ret = await save_contact(uid, contact_doc);
2543
2543
 
2544
- const req_save_ret = await db_ms.save_couch_doc('xuda_team', req_doc);
2544
+ const req_save_ret = await db_module.save_couch_doc('xuda_team', req_doc);
2545
2545
 
2546
2546
  return req_save_ret;
2547
2547
  } catch (err) {
@@ -2625,7 +2625,7 @@ export const not_spam_contact = async function (req, job_id, headers) {
2625
2625
  var contact_doc = await get_contact(uid, contact_id);
2626
2626
 
2627
2627
  if (contact_doc.is_spam) {
2628
- await db_ms.save_couch_doc_native('xuda_accounts', {
2628
+ await db_module.save_couch_doc_native('xuda_accounts', {
2629
2629
  _id: await _common.xuda_get_uuid('spam_whitelist'),
2630
2630
  uid,
2631
2631
  docType: 'spam_whitelist',
@@ -2653,7 +2653,7 @@ export const not_spam_contact = async function (req, job_id, headers) {
2653
2653
  await delete_xuda_cache(contact_doc);
2654
2654
  set_contact_profile_picture(uid, contact_doc._id, {}, job_id, headers, account_profile_info, false);
2655
2655
 
2656
- const emails = await db_ms.find_app_couch_query(account_profile_info.app_id, {
2656
+ const emails = await db_module.find_app_couch_query(account_profile_info.app_id, {
2657
2657
  selector: {
2658
2658
  docType: 'email',
2659
2659
  contact_id,
@@ -2665,14 +2665,14 @@ export const not_spam_contact = async function (req, job_id, headers) {
2665
2665
  for await (let email of emails.docs) {
2666
2666
  const app_id = await get_account_default_project_id(uid);
2667
2667
  if (email.conversation_id) {
2668
- db_ms.delete_app_couch_doc(app_id, email.conversation_id);
2668
+ db_module.delete_app_couch_doc(app_id, email.conversation_id);
2669
2669
  email.conversation_id = null;
2670
2670
  }
2671
2671
  if (email.conversation_item_id) {
2672
- db_ms.delete_app_couch_doc(app_id, email.conversation_item_id);
2672
+ db_module.delete_app_couch_doc(app_id, email.conversation_item_id);
2673
2673
  email.conversation_item_id = null;
2674
2674
  }
2675
- const save_ret = await db_ms.save_app_couch_doc_native(app_id, email);
2675
+ const save_ret = await db_module.save_app_couch_doc_native(app_id, email);
2676
2676
 
2677
2677
  // save attachments
2678
2678
  // summarized_body
@@ -2740,7 +2740,7 @@ export const set_deep_research_contact = async function (req, job_id, headers) {
2740
2740
  const contact_save_ret = await save_contact(uid, contact_doc);
2741
2741
  await delete_xuda_cache(contact_doc);
2742
2742
 
2743
- const conversation_items = await db_ms.find_app_couch_query(account_profile_info.app_id, {
2743
+ const conversation_items = await db_module.find_app_couch_query(account_profile_info.app_id, {
2744
2744
  selector: {
2745
2745
  docType: 'chat_conversation_item',
2746
2746
  reference_id: contact_id,
@@ -2752,7 +2752,7 @@ export const set_deep_research_contact = async function (req, job_id, headers) {
2752
2752
  for await (let conversation_item of conversation_items.docs) {
2753
2753
  try {
2754
2754
  const account_profile_info = await get_active_account_profile_info(conversation_item.uid);
2755
- let conversation_doc = await db_ms.get_app_couch_doc_native(account_profile_info.app_id, conversation_item.conversation_id);
2755
+ let conversation_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, conversation_item.conversation_id);
2756
2756
 
2757
2757
  const transcript = await ai_ms.get_transcript(conversation_item.uid, conversation_item.app_id, conversation_item.conversation_id, account_profile_info, conversation_item.file.filename);
2758
2758
  let items;
@@ -2762,7 +2762,7 @@ export const set_deep_research_contact = async function (req, job_id, headers) {
2762
2762
 
2763
2763
  conversation_item.text = transcript?.data || transcript || '';
2764
2764
  conversation_item.process_stat = 'full';
2765
- const conversation_item_save_ret = await db_ms.save_app_couch_doc(account_profile_info.app_id, conversation_item);
2765
+ const conversation_item_save_ret = await db_module.save_app_couch_doc(account_profile_info.app_id, conversation_item);
2766
2766
  }
2767
2767
  } catch (err) {
2768
2768
  throw err;
@@ -2806,10 +2806,10 @@ export const get_pending_share_profile_in = async function (uid, _id) {
2806
2806
  to_opt.selector._id = _id;
2807
2807
  }
2808
2808
 
2809
- const requests_from_res = await db_ms.find_couch_query('xuda_team', from_opt);
2809
+ const requests_from_res = await db_module.find_couch_query('xuda_team', from_opt);
2810
2810
 
2811
2811
  for await (let e of requests_from_res.docs) {
2812
- let doc = await db_ms.get_couch_doc_native('xuda_accounts', e.share_item_id);
2812
+ let doc = await db_module.get_couch_doc_native('xuda_accounts', e.share_item_id);
2813
2813
 
2814
2814
  doc.shared_from_uid = e.team_req_from_uid;
2815
2815
  doc.pending = true;
@@ -2825,7 +2825,7 @@ export const get_account_profile_info = async function (uid, contact_profile_doc
2825
2825
  const app_id = await get_account_default_project_id(uid);
2826
2826
  let doc = contact_profile_doc;
2827
2827
  if (_id) {
2828
- doc = await db_ms.get_couch_doc_native('xuda_accounts', _id);
2828
+ doc = await db_module.get_couch_doc_native('xuda_accounts', _id);
2829
2829
  }
2830
2830
  doc.notifications = 0;
2831
2831
 
@@ -2850,7 +2850,7 @@ export const get_account_profile_info = async function (uid, contact_profile_doc
2850
2850
  let ret = `default-pattern.png`;
2851
2851
 
2852
2852
  if (doc.shared_from_uid) {
2853
- // const account_profile_doc = await db_ms.get_couch_doc_native('xuda_accounts', doc.share_item_id);
2853
+ // const account_profile_doc = await db_module.get_couch_doc_native('xuda_accounts', doc.share_item_id);
2854
2854
  const shared_from_uid_ret = await get_account_name({ uid_query: doc.shared_from_uid });
2855
2855
  ret = shared_from_uid_ret.data.profile_avatar;
2856
2856
  } else if (doc.is_spam) {
@@ -2883,7 +2883,7 @@ export const get_account_profile_info = async function (uid, contact_profile_doc
2883
2883
  const get_online = async () => {
2884
2884
  let online = false;
2885
2885
  let selector = { docType: 'team_request', team_req_stat: 3, share_item_id: doc._id, access_type: 'account_profile', team_req_from_uid: uid };
2886
- let ret = await db_ms.find_couch_query('xuda_team', { selector });
2886
+ let ret = await db_module.find_couch_query('xuda_team', { selector });
2887
2887
  for (const req_obj of ret.docs) {
2888
2888
  const account_info_ret = await get_account_name({ uid_query: req_obj.team_req_to_uid });
2889
2889
  online = account_info_ret.data.online;
@@ -2909,7 +2909,7 @@ export const get_account_profile_info = async function (uid, contact_profile_doc
2909
2909
  const get_members = async () => {
2910
2910
  let members = [];
2911
2911
  let selector = { docType: 'team_request', team_req_stat: 3, share_item_id: doc._id, access_type: 'account_profile', team_req_from_uid: uid };
2912
- let ret = await db_ms.find_couch_query('xuda_team', { selector });
2912
+ let ret = await db_module.find_couch_query('xuda_team', { selector });
2913
2913
  for (const req_obj of ret.docs) {
2914
2914
  const account_info_ret = await get_account_name({ uid_query: req_obj.team_req_to_uid });
2915
2915
  const info = await await get_contact_info(uid, account_info_ret.data);
@@ -2922,7 +2922,7 @@ export const get_account_profile_info = async function (uid, contact_profile_doc
2922
2922
  // const account_profile_info = await get_active_account_profile_info(uid);
2923
2923
 
2924
2924
  let selector = { docType: 'account_profile', stat: 3 };
2925
- let ret = await db_ms.find_app_couch_query(app_id, { selector });
2925
+ let ret = await db_module.find_app_couch_query(app_id, { selector });
2926
2926
 
2927
2927
  return ret.docs;
2928
2928
  };
@@ -2969,7 +2969,7 @@ export const get_account_profiles = async function (req) {
2969
2969
  const { _id, uid, profile_name, limit, skip, bookmark, search, filter_type = 'all', profile_id, active_tab } = req;
2970
2970
  const app_id = await get_account_default_project_id(uid);
2971
2971
  if (_id) {
2972
- let data = await db_ms.get_app_couch_doc(app_id, _id);
2972
+ let data = await db_module.get_app_couch_doc(app_id, _id);
2973
2973
  return data;
2974
2974
  }
2975
2975
 
@@ -3037,7 +3037,7 @@ export const get_account_profiles = async function (req) {
3037
3037
  let profiles = { docs: [], total_docs: 0 };
3038
3038
 
3039
3039
  if (filter_type !== 'pending') {
3040
- profiles = await db_ms.find_app_couch_query(app_id, opt);
3040
+ profiles = await db_module.find_app_couch_query(app_id, opt);
3041
3041
  if (!limit || profile_id) {
3042
3042
  profiles.total_docs = profiles.docs.length;
3043
3043
  } else {
@@ -3046,7 +3046,7 @@ export const get_account_profiles = async function (req) {
3046
3046
  opt.limit = 9999;
3047
3047
  opt.fields = ['_id'];
3048
3048
 
3049
- const counter = await db_ms.find_app_couch_query(app_id, opt);
3049
+ const counter = await db_module.find_app_couch_query(app_id, opt);
3050
3050
  profiles.total_docs = counter.docs.length;
3051
3051
  }
3052
3052
  }
@@ -3098,7 +3098,7 @@ export const archive_account_profile = async function (req) {
3098
3098
 
3099
3099
  await team_ms.validate_share_exist(uid, 'account_profile', profile_id);
3100
3100
 
3101
- var account_profile_doc = await db_ms.get_app_couch_doc_native(app_id, profile_id);
3101
+ var account_profile_doc = await db_module.get_app_couch_doc_native(app_id, profile_id);
3102
3102
 
3103
3103
  if (account_profile_doc.main) {
3104
3104
  throw new Error('reserve');
@@ -3108,7 +3108,7 @@ export const archive_account_profile = async function (req) {
3108
3108
  account_profile_doc.stat_ts = Date.now();
3109
3109
  account_profile_doc.stat_reason = 'archived by the user';
3110
3110
 
3111
- const account_profile_save_ret = await db_ms.save_app_couch_doc(app_id, account_profile_doc);
3111
+ const account_profile_save_ret = await db_module.save_app_couch_doc(app_id, account_profile_doc);
3112
3112
 
3113
3113
  return account_profile_save_ret;
3114
3114
  } catch (err) {
@@ -3123,7 +3123,7 @@ export const delete_account_profile = async function (req, job_id, headers) {
3123
3123
  const { profile_id, uid } = req;
3124
3124
  try {
3125
3125
  const app_id = await get_account_default_project_id(uid);
3126
- var account_profile_doc = await db_ms.get_app_couch_doc_native(app_id, profile_id);
3126
+ var account_profile_doc = await db_module.get_app_couch_doc_native(app_id, profile_id);
3127
3127
  if (account_profile_doc.stat !== 5) {
3128
3128
  throw new Error('A document can only be deleted after it has been archived');
3129
3129
  }
@@ -3131,7 +3131,7 @@ export const delete_account_profile = async function (req, job_id, headers) {
3131
3131
  account_profile_doc.stat_ts = Date.now();
3132
3132
  account_profile_doc.stat_reason = 'deleted by the user';
3133
3133
 
3134
- const account_profile_save_ret = await db_ms.save_app_couch_doc(app_id, account_profile_doc);
3134
+ const account_profile_save_ret = await db_module.save_app_couch_doc(app_id, account_profile_doc);
3135
3135
 
3136
3136
  ai_ms.delete_depended_chats(uid, profile_id);
3137
3137
  return account_profile_save_ret;
@@ -3148,7 +3148,7 @@ export const unarchive_account_profile = async function (req) {
3148
3148
  try {
3149
3149
  const app_id = await get_account_default_project_id(uid);
3150
3150
 
3151
- var account_profile_doc = await db_ms.get_app_couch_doc_native(app_id, profile_id);
3151
+ var account_profile_doc = await db_module.get_app_couch_doc_native(app_id, profile_id);
3152
3152
 
3153
3153
  if (account_profile_doc.stat !== 5) {
3154
3154
  throw new Error('account profile is not archived');
@@ -3158,7 +3158,7 @@ export const unarchive_account_profile = async function (req) {
3158
3158
  account_profile_doc.stat_ts = Date.now();
3159
3159
  account_profile_doc.stat_reason = 'archived by the user';
3160
3160
 
3161
- const account_profile_save_ret = await db_ms.save_app_couch_doc(app_id, account_profile_doc);
3161
+ const account_profile_save_ret = await db_module.save_app_couch_doc(app_id, account_profile_doc);
3162
3162
 
3163
3163
  return account_profile_save_ret;
3164
3164
  }
@@ -3174,7 +3174,7 @@ export const create_account_profile = async function (req, job_id, headers) {
3174
3174
  const { uid, profile_name, profile_signature, email_account_id, profile_picture, profile_avatar, profile_picture_obj, profile_avatar_obj, main, account_type } = req;
3175
3175
  try {
3176
3176
  const app_id = await get_account_default_project_id(uid);
3177
- // const { data: acc_obj } = await db_ms.get_couch_doc('xuda_accounts', uid);
3177
+ // const { data: acc_obj } = await db_module.get_couch_doc('xuda_accounts', uid);
3178
3178
 
3179
3179
  const d = Date.now();
3180
3180
  const doc = {
@@ -3194,7 +3194,7 @@ export const create_account_profile = async function (req, job_id, headers) {
3194
3194
  profile_avatar_obj,
3195
3195
  main,
3196
3196
  };
3197
- const save_ret = await db_ms.save_app_couch_doc(app_id, doc);
3197
+ const save_ret = await db_module.save_app_couch_doc(app_id, doc);
3198
3198
  // acc_obj.active_profile_id = save_ret.data.id;
3199
3199
 
3200
3200
  // return { code: 55, data: save_ret };
@@ -3209,7 +3209,7 @@ export const update_account_profile = async function (req, job_id, headers) {
3209
3209
  const app_id = await get_account_default_project_id(uid);
3210
3210
  const account_profile_properties = ['profile_name', 'profile_signature', 'email_account_id', 'profile_picture', 'profile_avatar', 'profile_picture_obj', 'profile_avatar_obj', 'auto_respond', 'auto_respond_mode', 'auto_respond_agents', 'account_type', 'active_ai_model'];
3211
3211
  try {
3212
- let { data: account_profile_doc } = await db_ms.get_app_couch_doc(app_id, _id);
3212
+ let { data: account_profile_doc } = await db_module.get_app_couch_doc(app_id, _id);
3213
3213
 
3214
3214
  if (account_profile_doc.docType !== 'account_profile') {
3215
3215
  throw new Error('not account profile doc');
@@ -3233,7 +3233,7 @@ export const update_account_profile = async function (req, job_id, headers) {
3233
3233
 
3234
3234
  account_profile_doc.ts = Date.now();
3235
3235
 
3236
- const save_ret = await db_ms.save_app_couch_doc(app_id, account_profile_doc);
3236
+ const save_ret = await db_module.save_app_couch_doc(app_id, account_profile_doc);
3237
3237
 
3238
3238
  return { code: 56, data: save_ret };
3239
3239
  } catch (err) {
@@ -3250,7 +3250,7 @@ export const update_entity_account_profiles = async function (req, job_id, heade
3250
3250
  throw new Error('account_profiles cannot be empty');
3251
3251
  }
3252
3252
 
3253
- let doc = await db_ms.get_app_couch_doc_native(app_id, _id);
3253
+ let doc = await db_module.get_app_couch_doc_native(app_id, _id);
3254
3254
 
3255
3255
  switch (doc.docType) {
3256
3256
  case 'chat_conversation':
@@ -3270,7 +3270,7 @@ export const update_entity_account_profiles = async function (req, job_id, heade
3270
3270
  break;
3271
3271
  }
3272
3272
 
3273
- const save_ret = await db_ms.save_app_couch_doc(app_id, doc);
3273
+ const save_ret = await db_module.save_app_couch_doc(app_id, doc);
3274
3274
 
3275
3275
  return { code: 57, data: save_ret };
3276
3276
  } catch (err) {
@@ -3280,24 +3280,24 @@ export const update_entity_account_profiles = async function (req, job_id, heade
3280
3280
 
3281
3281
  export const get_contact = async function (uid, contact_id) {
3282
3282
  const account_profile_info = await get_active_account_profile_info(uid);
3283
- const contact_ret = await db_ms.get_app_couch_doc_native(account_profile_info.app_id, contact_id);
3283
+ const contact_ret = await db_module.get_app_couch_doc_native(account_profile_info.app_id, contact_id);
3284
3284
  return contact_ret;
3285
3285
  };
3286
3286
 
3287
3287
  export const save_contact = async function (uid, contact_doc) {
3288
3288
  const account_profile_info = await get_active_account_profile_info(uid);
3289
- const contact_ret = await db_ms.save_app_couch_doc(account_profile_info.app_id, contact_doc);
3289
+ const contact_ret = await db_module.save_app_couch_doc(account_profile_info.app_id, contact_doc);
3290
3290
  return contact_ret;
3291
3291
  };
3292
3292
 
3293
3293
  export const find_contact_query = async function (uid, opt) {
3294
3294
  const app_id = await get_account_default_project_id(uid);
3295
- const ret = await db_ms.find_app_couch_query(app_id, opt);
3295
+ const ret = await db_module.find_app_couch_query(app_id, opt);
3296
3296
  return ret;
3297
3297
  };
3298
3298
 
3299
3299
  export const delete_xuda_cache = async function (contact_obj) {
3300
- const ret = await db_ms.find_couch_query('xuda_cache', {
3300
+ const ret = await db_module.find_couch_query('xuda_cache', {
3301
3301
  selector: {
3302
3302
  $or: [
3303
3303
  {
@@ -3312,7 +3312,7 @@ export const delete_xuda_cache = async function (contact_obj) {
3312
3312
 
3313
3313
  for (let doc of ret.docs) {
3314
3314
  doc._deleted = true;
3315
- const save_ret = await db_ms.save_couch_doc('xuda_cache', doc);
3315
+ const save_ret = await db_module.save_couch_doc('xuda_cache', doc);
3316
3316
  }
3317
3317
  };
3318
3318
 
@@ -3332,12 +3332,12 @@ export const save_xuda_cache = async function (uid, docType, key, file, metadata
3332
3332
  metadata,
3333
3333
  hits: 0,
3334
3334
  };
3335
- const save_ret = await db_ms.save_couch_doc('xuda_cache', doc);
3335
+ const save_ret = await db_module.save_couch_doc('xuda_cache', doc);
3336
3336
  return save_ret;
3337
3337
  };
3338
3338
 
3339
3339
  export const get_xuda_cache = async function (uid, docType, key, return_property) {
3340
- let ret = await db_ms.find_couch_query('xuda_cache', {
3340
+ let ret = await db_module.find_couch_query('xuda_cache', {
3341
3341
  selector: { docType, key: key.toLowerCase().trim() },
3342
3342
  limit: 1,
3343
3343
  });
@@ -3348,7 +3348,7 @@ export const get_xuda_cache = async function (uid, docType, key, return_property
3348
3348
 
3349
3349
  return null;
3350
3350
 
3351
- // ret = await db_ms.find_couch_query('xuda_cache', {
3351
+ // ret = await db_module.find_couch_query('xuda_cache', {
3352
3352
  // selector: { docType, name: name.trim() },
3353
3353
  // limit: 1,
3354
3354
  // });
@@ -3359,10 +3359,10 @@ export const get_xuda_cache = async function (uid, docType, key, return_property
3359
3359
  };
3360
3360
 
3361
3361
  export const save_cache_hit = async function (_id) {
3362
- let doc_ret = await db_ms.get_couch_doc('xuda_cache', _id);
3362
+ let doc_ret = await db_module.get_couch_doc('xuda_cache', _id);
3363
3363
  if (doc_ret.code > -1) {
3364
3364
  doc_ret.data.hits++;
3365
- await db_ms.save_couch_doc('xuda_cache', doc_ret.data);
3365
+ await db_module.save_couch_doc('xuda_cache', doc_ret.data);
3366
3366
  }
3367
3367
  };
3368
3368
 
@@ -3392,7 +3392,7 @@ export const record_ai_usage = async function (uid, input_tokens, output_tokens,
3392
3392
  account_profile_info,
3393
3393
  tools,
3394
3394
  };
3395
- const save_ret = await db_ms.save_couch_doc('xuda_usage', usage_doc);
3395
+ const save_ret = await db_module.save_couch_doc('xuda_usage', usage_doc);
3396
3396
  // console.log(save_ret);
3397
3397
  } catch (err) {
3398
3398
  console.error(err);
@@ -3401,7 +3401,7 @@ export const record_ai_usage = async function (uid, input_tokens, output_tokens,
3401
3401
 
3402
3402
  export const record_ai_credit = async function (uid, credits = 0, source, details, credited_uid) {
3403
3403
  try {
3404
- var dup = await db_ms.find_couch_query('xuda_billing', {
3404
+ var dup = await db_module.find_couch_query('xuda_billing', {
3405
3405
  selector: {
3406
3406
  docType: 'ai_credit',
3407
3407
  credited_uid,
@@ -3427,7 +3427,7 @@ export const record_ai_credit = async function (uid, credits = 0, source, detail
3427
3427
  credited_uid,
3428
3428
  details,
3429
3429
  };
3430
- const save_ret = await db_ms.save_couch_doc('xuda_billing', credit_doc);
3430
+ const save_ret = await db_module.save_couch_doc('xuda_billing', credit_doc);
3431
3431
  // console.log(save_ret);
3432
3432
  return save_ret;
3433
3433
  } catch (err) {
@@ -3446,13 +3446,13 @@ export const add_ai_credits_to_active_accounts = async function () {
3446
3446
  });
3447
3447
 
3448
3448
  const _24_hr_ms = 1000 * 60 * 60 * 24;
3449
- const active_accounts = await db_ms.find_couch_query('xuda_accounts', { selector: { stat: 3, docType: 'account', last_free_daily_ai_credit_ts: { $lt: Date.now() - _24_hr_ms }, ai_workspace_plan: 'free_ai_workspace' }, limit: 99999 });
3449
+ const active_accounts = await db_module.find_couch_query('xuda_accounts', { selector: { stat: 3, docType: 'account', last_free_daily_ai_credit_ts: { $lt: Date.now() - _24_hr_ms }, ai_workspace_plan: 'free_ai_workspace' }, limit: 99999 });
3450
3450
  for await (let account_doc of active_accounts.docs) {
3451
3451
  const ret = await record_ai_credit('system', 1, 'daily credit', 'free daily credit ' + date_str, account_doc._id);
3452
3452
  if (ret.code > -1) {
3453
3453
  account_doc.last_free_daily_ai_credit_ts = Date.now();
3454
3454
  account_doc.last_free_daily_ai_credit_id = ret.data.id;
3455
- const save_ret = await db_ms.save_couch_doc('xuda_accounts', account_doc);
3455
+ const save_ret = await db_module.save_couch_doc('xuda_accounts', account_doc);
3456
3456
  }
3457
3457
  }
3458
3458
  };
@@ -3461,17 +3461,17 @@ export const archive_expire_ai_credits = async function () {
3461
3461
  const _24_hr_ms = 1000 * 60 * 60 * 24;
3462
3462
  const _mo_ms = _24_hr_ms * 30;
3463
3463
 
3464
- const active_ai_credits = await db_ms.find_couch_query('xuda_billing', { selector: { stat: 3, docType: 'ai_credit', date_created_ts: { $lt: Date.now() - _mo_ms } }, limit: 99999 });
3464
+ const active_ai_credits = await db_module.find_couch_query('xuda_billing', { selector: { stat: 3, docType: 'ai_credit', date_created_ts: { $lt: Date.now() - _mo_ms } }, limit: 99999 });
3465
3465
  for await (let ai_credit_doc of active_ai_credits.docs) {
3466
3466
  ai_credit_doc.stat = 5;
3467
3467
  ai_credit_doc.stat_ts = Date.now();
3468
3468
  ai_credit_doc.stat_reason = 'expired';
3469
- const save_ret = await db_ms.save_couch_doc('xuda_billing', ai_credit_doc);
3469
+ const save_ret = await db_module.save_couch_doc('xuda_billing', ai_credit_doc);
3470
3470
  }
3471
3471
  };
3472
3472
 
3473
3473
  export const read_accounts_emails = async function () {
3474
- const active_accounts = await db_ms.find_couch_query('xuda_accounts', { selector: { stat: 3, docType: 'account' }, limit: 99999 });
3474
+ const active_accounts = await db_module.find_couch_query('xuda_accounts', { selector: { stat: 3, docType: 'account' }, limit: 99999 });
3475
3475
  for await (let account_doc of active_accounts.docs) {
3476
3476
  if (!account_doc?.account_info?.active_account_profile_id) continue;
3477
3477
  email_ms.refresh_mailboxes({ uid: account_doc._id });
@@ -3479,7 +3479,7 @@ export const read_accounts_emails = async function () {
3479
3479
  };
3480
3480
 
3481
3481
  export const process_accounts_emails = async function () {
3482
- const active_accounts = await db_ms.find_couch_query('xuda_accounts', { selector: { stat: 3, docType: 'account' }, limit: 99999 });
3482
+ const active_accounts = await db_module.find_couch_query('xuda_accounts', { selector: { stat: 3, docType: 'account' }, limit: 99999 });
3483
3483
  for await (let account_doc of active_accounts.docs) {
3484
3484
  if (!account_doc?.account_info?.active_account_profile_id) continue;
3485
3485
  email_ms.process_emails({ uid: account_doc._id });
@@ -3487,7 +3487,7 @@ export const process_accounts_emails = async function () {
3487
3487
  };
3488
3488
 
3489
3489
  const isLikelySpamEmail = async function (email) {
3490
- const spam_whitelists = await db_ms.find_couch_query('xuda_accounts', {
3490
+ const spam_whitelists = await db_module.find_couch_query('xuda_accounts', {
3491
3491
  selector: {
3492
3492
  docType: 'spam_whitelist',
3493
3493
  email,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/account_module",
3
- "version": "1.2.2072",
3
+ "version": "1.2.2073",
4
4
  "description": "Xuda Account Server Module",
5
5
  "main": "index.mjs",
6
6
  "dependencies": {