@xuda.io/account_module 1.2.154 → 1.2.155

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 +444 -209
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -17,34 +17,35 @@ const db_module = await import(`${module_path}/db_module/index.mjs`);
17
17
  const jobs_module = await import(`${module_path}/jobs_module/index.mjs`);
18
18
  const logs_module = await import(`${module_path}/logs_module/index.mjs`);
19
19
 
20
- export const update_account_info = async (req) => {
21
- const marketplace_module = await import(`${module_path}/marketplace_module/index.mjs`);
20
+ export const update_account_info = async function (req) {
21
+ const marketplace_module = require(`${module_path}/marketplace_module`);
22
22
 
23
23
  const { uid } = req;
24
24
  const data = req;
25
25
 
26
- const validate_input = (string, max_length, is_mandatory, is_pass) => {
26
+ function validate_input(string, max_length, is_mandatory, is_pass) {
27
27
  if (!/^[a-zA-Z0-9,.@ ]*$/.test(string) && !is_pass) {
28
+ // if (!preg_match('^[a-zA-Z0-9,.@ ]*$', string) && !is_pass) {
29
+
28
30
  return -1;
29
31
  } else if ((is_mandatory && !string) || string.length < 2) {
30
32
  return -2;
31
- } else if (string.length > max_length) {
32
- // Fixed: string.count -> string.length
33
+ } else if (string.count > max_length) {
33
34
  return -3;
34
35
  } else {
35
36
  return 1;
36
37
  }
37
- };
38
+ }
38
39
 
39
40
  const ret = await db_module.get_couch_doc('xuda_accounts', uid);
40
- let account_obj = ret.data;
41
+ var account_obj = ret.data;
41
42
  account_obj.ts = Date.now();
42
- let change = '';
43
- let error = {};
43
+ var change = '';
44
+ var error = {};
44
45
 
45
46
  await marketplace_module.marketplace_save_user({ uid });
46
47
 
47
- _.forEach(data, (val, key) => {
48
+ _.forEach(data, function (val, key) {
48
49
  if (account_obj.account_info[key] !== val) {
49
50
  change += ' from ' + account_obj.account_info[key] + ' to ' + val;
50
51
 
@@ -56,6 +57,8 @@ export const update_account_info = async (req) => {
56
57
  }
57
58
  }
58
59
  if (key === 'first_name' && !validate_input(val, 35, true, false)) {
60
+ // print_r(validate_input($val, 35, true, false)<0);
61
+ // exit;
59
62
  error[key] = 'Invalid first name';
60
63
  }
61
64
  if (key === 'last_name' && !validate_input(val, 35, true, false)) {
@@ -65,9 +68,11 @@ export const update_account_info = async (req) => {
65
68
  error[key] = 'Invalid email';
66
69
  }
67
70
  if (key === 'tel' && (!/^[0-9]{3}-[0-9]{4}-[0-9]{4}$/.test(val) || !val || val.length < 2)) {
71
+ // if (key === "tel" && (!preg_match("/^[0-9]{3}-[0-9]{4}-[0-9]{4}$/", $val) || !$val || count($val) < 2)) {
68
72
  error[key] = 'Invalid phone number';
69
73
  }
70
74
  if (key === 'address' && !/^[a-z0-9- ]+$/i.test(val)) {
75
+ // if (key === "address" && !preg_match('/^[a-z0-9- ]+$/i', $val)) {
71
76
  error[key] = 'Invalid address';
72
77
  }
73
78
  if (key === 'city' && !validate_input(val, 255, false, false)) {
@@ -96,16 +101,8 @@ export const update_account_info = async (req) => {
96
101
  delete account_obj.account_info.uid;
97
102
 
98
103
  if (!account_obj.account_project_id) {
99
- const app_module = await import(`${module_path}/app_module/index.mjs`);
100
- const ret = await app_module.create_project({
101
- token_ret: req.token_ret,
102
- uid,
103
- data: {
104
- app_name: `Account ${uid} main project`,
105
- is_account_project: true,
106
- app_plugins_purchased: ['@xuda.io/xuda-dbs-plugin-xuda', '@xuda.io/xuda-framework-plugin-tailwind'],
107
- },
108
- });
104
+ const app_module = require(`${module_path}/app_module`);
105
+ const ret = await app_module.create_project({ token_ret: req.token_ret, uid, data: { app_name: `Account ${uid} main project`, is_account_project: true, app_plugins_purchased: [' @xuda.io/xuda-dbs-plugin-xuda', '@xuda.io/xuda-framework-plugin-tailwind'] } });
109
106
  if (ret.code > -1) {
110
107
  account_obj.account_project_id = ret.data;
111
108
  }
@@ -117,13 +114,12 @@ export const update_account_info = async (req) => {
117
114
  }
118
115
  return ret2;
119
116
  };
120
-
121
- export const update_account_preferences = async (req) => {
117
+ export const update_account_preferences = async function (req) {
122
118
  const account_id = req.account_id;
123
119
  const data = req;
124
120
 
125
121
  const ret = await db_module.get_couch_doc('xuda_accounts', account_id);
126
- let account_obj = ret.data;
122
+ var account_obj = ret.data;
127
123
  account_obj.ts = Date.now();
128
124
 
129
125
  account_obj.preferences = data;
@@ -135,17 +131,17 @@ export const update_account_preferences = async (req) => {
135
131
  return { code: 1300, data: account_obj.preferences };
136
132
  };
137
133
 
138
- export const save_admin_presets = async (req) => {
134
+ export const save_admin_presets = async function (req) {
139
135
  const ret = await db_module.get_couch_doc('xuda_master', req.app_id);
140
136
  if (ret.code < 0) {
141
137
  return ret;
142
138
  }
143
- let app_obj = ret.data;
139
+ var app_obj = ret.data;
144
140
  app_obj.deploy_data.admin_presets = req.admin_presets;
145
141
  app_obj.deploy_data.preset_id = req.preset_id;
146
142
 
147
143
  const ret3 = await db_module.save_app_obj(app_obj, null, req.app_id);
148
- let obj = {};
144
+ var obj = {};
149
145
  if (ret3.code > -1) {
150
146
  obj = {
151
147
  code: 1,
@@ -159,25 +155,25 @@ export const save_admin_presets = async (req) => {
159
155
  return obj;
160
156
  };
161
157
 
162
- export const increment_account_usage = async (req) => {
158
+ export const increment_account_usage = async function (req) {
163
159
  const { uid } = req;
164
160
 
165
- let opt = {};
161
+ var opt = {};
166
162
  if (uid) {
167
163
  opt.key = uid;
168
164
  }
169
165
  const accounts_ret = await db_module.get_couch_view_raw('xuda_accounts', 'all_accounts', opt);
170
166
 
171
- const drive_module = await import(`${module_path}/drive_module/index.mjs`);
167
+ const drive_module = require(`${module_path}/drive_module`);
172
168
 
173
- const bytesToGB = (bytes) => {
169
+ function bytesToGB(bytes) {
174
170
  return bytes / 1073741824; // or bytes / (1024 ** 3)
175
- };
171
+ }
176
172
 
177
173
  // check if last calculation made at least hour ago
178
- const interval = 3600 * 1000;
174
+ const interval = 3600 * 1000; //6000; // 3600 * 1000;
179
175
 
180
- const run_account_drive = async (account_data) => {
176
+ const run_account_drive = async function (account_data) {
181
177
  try {
182
178
  const usage_id = await _common.xuda_get_uuid('usage');
183
179
 
@@ -185,7 +181,7 @@ export const increment_account_usage = async (req) => {
185
181
  key: account_data._id,
186
182
  });
187
183
 
188
- let doc = {
184
+ var doc = {
189
185
  _id: usage_id,
190
186
  docType: 'user_drive_usage',
191
187
  date_created: new Date(),
@@ -208,7 +204,7 @@ export const increment_account_usage = async (req) => {
208
204
  const plan = _conf.PLAN_OBJ[account_data.membership_plan];
209
205
  const drive_size_total = account_data.user_drive_size + account_data.studio_drive_size + account_data.workspace_drive_size + account_data.builds_drive_size + account_data.plugins_drive_size;
210
206
  if (bytesToGB(drive_size_total) > plan.features.drive) {
211
- let price_per_hour = (bytesToGB(drive_size_total) * _conf.PRICE_OBJ.price_per_gb_drive) / _conf.PRICE_OBJ.avg_hours_in_month;
207
+ var price_per_hour = (bytesToGB(drive_size_total) * _conf.PRICE_OBJ.price_per_gb_drive) / _conf.PRICE_OBJ.avg_hours_in_month;
212
208
 
213
209
  doc.hours++;
214
210
  doc.size = drive_size_total;
@@ -223,7 +219,7 @@ export const increment_account_usage = async (req) => {
223
219
  }
224
220
  };
225
221
 
226
- const run_account_apps = async (account_data) => {
222
+ const run_account_apps = async function (account_data) {
227
223
  const apps_ret = await db_module.get_couch_view('xuda_master', 'user_apps', {
228
224
  startkey: [account_data._id, ''],
229
225
  endkey: [account_data._id, 'ZZZZZ'],
@@ -268,7 +264,7 @@ export const increment_account_usage = async (req) => {
268
264
  key: [app.id, app.doc?.app_hosting?.app_server_type || app.doc.app_type],
269
265
  });
270
266
 
271
- let doc = {
267
+ var doc = {
272
268
  _id: usage_id,
273
269
  docType: 'app_usage',
274
270
  date_created: new Date(),
@@ -282,6 +278,7 @@ export const increment_account_usage = async (req) => {
282
278
  ts: 0,
283
279
  name: app.value.app_name,
284
280
  app_type: app.value.app_type,
281
+
285
282
  subscription_id: account_data.stripe_membership_subscription_id,
286
283
  };
287
284
 
@@ -301,7 +298,7 @@ export const increment_account_usage = async (req) => {
301
298
  doc = usage_ret.rows[0].value;
302
299
  }
303
300
 
304
- let price_per_hour;
301
+ var price_per_hour;
305
302
 
306
303
  // check if last calculation made at least hour ago
307
304
  const interval = 6000; // 3600 * 1000;
@@ -315,6 +312,7 @@ export const increment_account_usage = async (req) => {
315
312
  price_per_hour = (app.value.app_hosting.disk * _conf.PRICE_OBJ.price_per_gb_backup) / _conf.PRICE_OBJ.avg_hours_in_month;
316
313
  } else {
317
314
  // backup of project
315
+
318
316
  const info_ret = await db_module.get_couch_app_info(doc.app_id);
319
317
  if (info_ret.code > 0) {
320
318
  const size = info_ret.data.sizes.active / 1000 / 1000 / 1000; //gb
@@ -323,22 +321,20 @@ export const increment_account_usage = async (req) => {
323
321
  }
324
322
  break;
325
323
 
326
- case 'user_group':
327
- {
328
- const team_ret = await db_module.get_couch_view('xuda_team', 'user_group_shares_count', {
329
- key: app.id,
330
- reduce: true,
331
- group_level: 1,
332
- });
333
-
334
- const team_members = team_ret.data.rows?.[0]?.value || 0;
335
- const price_per_hour_team = (team_members * _conf.PRICE_OBJ.price_per_user_group_member) / _conf.PRICE_OBJ.avg_hours_in_month;
336
- doc.price_user_group += price_per_hour_team;
337
- doc.user_group_members = team_members;
338
- doc.user_group_members_accumulated += team_members;
339
- doc.user_group_members_avg = doc.user_group_members_accumulated / doc.hours;
340
- }
341
- break; // Added break
324
+ case 'user_group': {
325
+ const team_ret = await db_module.get_couch_view('xuda_team', 'user_group_shares_count', {
326
+ key: app.id,
327
+ reduce: true,
328
+ group_level: 1,
329
+ });
330
+
331
+ const team_members = team_ret.data.rows?.[0]?.value || 0;
332
+ const price_per_hour_team = (team_members * _conf.PRICE_OBJ.price_per_user_group_member) / _conf.PRICE_OBJ.avg_hours_in_month;
333
+ doc.price_user_group += price_per_hour_team;
334
+ doc.user_group_members = team_members;
335
+ doc.user_group_members_accumulated += team_members;
336
+ doc.user_group_members_avg = doc.user_group_members_accumulated / doc.hours;
337
+ }
342
338
 
343
339
  default:
344
340
  // deployments,vps,master,instances and datacenters
@@ -347,6 +343,7 @@ export const increment_account_usage = async (req) => {
347
343
  doc.app_hosting = app.doc.app_hosting;
348
344
  doc.server_type = app.doc.app_hosting.app_server_type;
349
345
  price_per_hour = app.doc.app_hosting.price / _conf.PRICE_OBJ.avg_hours_in_month;
346
+
350
347
  break;
351
348
  }
352
349
  doc.price += price_per_hour;
@@ -365,7 +362,7 @@ export const increment_account_usage = async (req) => {
365
362
 
366
363
  // iterate on all status account except deleted accounts
367
364
  for await (let val of accounts_ret.rows) {
368
- let account_data = val.value;
365
+ var account_data = val.value;
369
366
 
370
367
  const size_ret = await drive_module.get_drive_size({
371
368
  uid: account_data._id,
@@ -387,12 +384,26 @@ export const increment_account_usage = async (req) => {
387
384
  }
388
385
  };
389
386
 
390
- export const get_account_data = async (req) => {
391
- let { uid, enforce_usage } = req;
387
+ export const get_account_data = async function (req) {
388
+ var { uid, enforce_usage } = req;
389
+ // const get_info = async function () {
390
+ // const get_stripe_subscription = async function (subscription_id) {
391
+ // if (!subscription_id) {
392
+ // return { code: -1, data: "subscription_id missing" };
393
+ // }
394
+ // try {
395
+ // const ret = await stripe.subscriptions.retrieve(subscription_id);
396
+
397
+ // return { code: 1, data: ret };
398
+ // } catch (err) {
399
+ // return { code: -400, data: err };
400
+ // }
401
+ // };
392
402
 
393
403
  try {
394
404
  const { data: acc_obj } = await db_module.get_couch_doc('xuda_accounts', uid);
395
- let ret = { code: 1 };
405
+ // const account_obj= account_ret.data
406
+ var ret = { code: 1 };
396
407
  ret.data = {
397
408
  _id: acc_obj._id,
398
409
  account_info: acc_obj.account_info,
@@ -432,15 +443,38 @@ export const get_account_data = async (req) => {
432
443
  stripe_connect_account_status: acc_obj?.stripe_connect_account_status,
433
444
  };
434
445
 
446
+ // if (account_ret.data.stripe_membership_subscription_id) {
447
+ // const subscription_ret = await get_stripe_subscription(
448
+ // account_ret.data.stripe_membership_subscription_id
449
+ // );
450
+
451
+ // if (subscription_ret.code > 0) {
452
+ // ret.data.stripe_membership_subscription_id = subscription_ret.data.id;
453
+ // }
454
+ // }
455
+
456
+ // if (!acc_obj.account_project_id && req.token_ret) {
457
+ // let = account_obj = acc_obj;
458
+ // const app_module = require(`${module_path}/app_module`);
459
+ // const ret = await app_module.create_project({ token_ret: req.token_ret, uid, data: { app_name: `Account ${uid} main project`, is_account_project: true } });
460
+ // if (ret.code > -1) {
461
+ // account_obj.account_project_id = ret.data;
462
+ // const ret2 = await db_module.save_couch_doc('xuda_accounts', account_obj);
463
+ // }
464
+ // }
465
+
435
466
  return ret;
436
467
  } catch (error) {
437
468
  return { code: -1, data: error };
438
469
  }
470
+ // };
471
+
472
+ // return get_info();
439
473
  };
440
474
 
441
- export const get_account_projects = async (req) => {
475
+ export const get_account_projects = async function (req) {
442
476
  const { uid } = req;
443
- let opt = {
477
+ var opt = {
444
478
  key: uid,
445
479
  };
446
480
 
@@ -448,42 +482,40 @@ export const get_account_projects = async (req) => {
448
482
  opt = {};
449
483
  }
450
484
 
451
- let ret = await db_module.get_couch_view('xuda_master', 'user_projects', opt);
485
+ var ret = await db_module.get_couch_view('xuda_master', 'user_projects', opt);
452
486
 
453
487
  return ret;
454
488
  };
455
489
 
456
- export const get_account_datacenters = async (req) => {
490
+ export const get_account_datacenters = async function (req) {
457
491
  return await db_module.get_couch_view('xuda_master', 'user_datacenters', {
458
492
  key: req.uid,
459
493
  });
460
494
  };
461
-
462
- export const get_account_deployments = async (req) => {
495
+ export const get_account_deployments = async function (req) {
463
496
  return await db_module.get_couch_view('xuda_master', 'user_deployments', {
464
497
  key: req.uid,
465
498
  });
466
499
  };
467
-
468
- export const get_account_instances = async (req) => {
500
+ export const get_account_instances = async function (req) {
469
501
  return await db_module.get_couch_view('xuda_master', 'user_all_instances', {
470
502
  key: req.uid,
471
503
  });
472
504
  };
473
505
 
474
- export const get_account_info = async (req) => {
475
- return await get_account_data({
506
+ export const get_account_info = async function (req) {
507
+ return await this.get_account_data({
476
508
  uid: req.uid,
477
509
  enforce_usage: req.enforce_usage,
478
510
  });
479
511
  };
480
512
 
481
- export const get_account_name = async (req) => {
513
+ export const get_account_name = async function (req) {
482
514
  const data = await db_module.get_couch_doc('xuda_accounts', req.uid_query);
483
515
  if (data.code < 0) {
484
516
  return data;
485
517
  }
486
- let obj = {
518
+ var obj = {
487
519
  first_name: '',
488
520
  last_name: '',
489
521
  email: '',
@@ -504,14 +536,14 @@ export const get_account_name = async (req) => {
504
536
  return { code: 1, data: obj };
505
537
  };
506
538
 
507
- export const account_validate_username = async (req) => {
539
+ export const account_validate_username = async function (req) {
508
540
  const opt = {
509
541
  selector: { 'account_info.username': req.username },
510
542
  fields: ['_id'],
511
543
  limit: 1,
512
544
  };
513
545
 
514
- let ret = await db_module.find_couch_query('xuda_accounts', opt);
546
+ var ret = await db_module.find_couch_query('xuda_accounts', opt);
515
547
 
516
548
  if (ret.docs.length) {
517
549
  return { code: -400, data: 'User exist' };
@@ -520,7 +552,17 @@ export const account_validate_username = async (req) => {
520
552
  }
521
553
  };
522
554
 
523
- export const verify_account = async (req) => {
555
+ // export const get_account_activity = async function (req) {
556
+ // return await db_module.get_couch_view(
557
+ // "xuda_activity",
558
+ // "activity_per_account",
559
+ // {
560
+ // key: req.uid,
561
+ // }
562
+ // );
563
+ // };
564
+
565
+ export const verify_account = async function (req) {
524
566
  const { account_id } = req;
525
567
  if (!account_id) {
526
568
  return { code: -10, data: 'Missing id' };
@@ -531,7 +573,7 @@ export const verify_account = async (req) => {
531
573
  if (ret.code < 0) {
532
574
  return { code: -1, data: 'account not found' };
533
575
  }
534
- let obj = ret.data;
576
+ var obj = ret.data;
535
577
  obj.stat = 3;
536
578
  const ret_acc = await db_module.save_couch_doc('xuda_accounts', obj);
537
579
  if (ret.code < 0) {
@@ -540,7 +582,7 @@ export const verify_account = async (req) => {
540
582
  return { code: 1, data: ret_acc.data };
541
583
  };
542
584
 
543
- export const validate_user_plan = async (req) => {
585
+ export const validate_user_plan = async function (req) {
544
586
  const { account_id, app_obj } = req;
545
587
 
546
588
  const apps_ret = await db_module.get_couch_view('xuda_master', 'user_apps_count', {
@@ -550,7 +592,7 @@ export const validate_user_plan = async (req) => {
550
592
  group_level: 2,
551
593
  });
552
594
 
553
- let ret_obj = _.reduce(
595
+ var ret_obj = _.reduce(
554
596
  apps_ret.data.rows,
555
597
  (ret, value) => {
556
598
  ret[value.key[1]] = value.value;
@@ -563,7 +605,8 @@ export const validate_user_plan = async (req) => {
563
605
  if (ret.code < 0) {
564
606
  return ret;
565
607
  }
566
- let plan = _conf.PLAN_OBJ[ret.data.membership_plan];
608
+ var plan = _conf.PLAN_OBJ[ret.data.membership_plan];
609
+ // get plan from user
567
610
 
568
611
  if (!plan) {
569
612
  return { code: -7, data: 'error - no plan defined' };
@@ -578,6 +621,7 @@ export const validate_user_plan = async (req) => {
578
621
  }
579
622
 
580
623
  // validate number of team members
624
+
581
625
  const user_active_app_requests_count_ret = await db_module.get_couch_view('xuda_team', 'user_active_app_requests_count', {
582
626
  key: account_id,
583
627
  reduce: true,
@@ -594,23 +638,23 @@ export const validate_user_plan = async (req) => {
594
638
  return { code: 1, data: ret.data };
595
639
  };
596
640
 
597
- export const get_hosting_plan = (req) => {
641
+ export const get_hosting_plan = function (req) {
598
642
  const { app_obj } = req;
599
643
  if (app_obj.app_hosting) {
600
644
  if (_conf.PRICE_OBJ.server_slugs[app_obj.app_hosting.app_server_type]) {
601
645
  return _conf.PRICE_OBJ.server_slugs[app_obj.app_hosting.app_server_type];
602
646
  }
603
- // debugger;
647
+ debugger;
604
648
  console.error('error: ' + app_obj.app_hosting.app_server_type + ' not found in PRICE_OBJ.server_slugs');
605
649
  return { cpu: 0, price: 0 };
606
650
  }
607
651
  };
608
652
 
609
- export const get_cpu = async (req) => {
653
+ export const get_cpu = async function (req) {
610
654
  const { app_obj } = req;
611
- let cpu = 1;
655
+ var cpu = 1;
612
656
  if (app_obj.app_hosting) {
613
- const hosting_plan = get_hosting_plan({
657
+ const hosting_plan = this.get_hosting_plan({
614
658
  app_obj,
615
659
  });
616
660
 
@@ -621,7 +665,7 @@ export const get_cpu = async (req) => {
621
665
  return cpu;
622
666
  };
623
667
 
624
- const get_account_log_object = (body, status, service, source, response_data, ip, headers, security) => {
668
+ const get_account_log_object = function (body, status, service, source, response_data, ip, headers, security) {
625
669
  return {
626
670
  uid: body.uid,
627
671
  ip,
@@ -639,31 +683,37 @@ const get_account_log_object = (body, status, service, source, response_data, ip
639
683
  };
640
684
  };
641
685
 
642
- export const add_account_log_util = (body, status, service, source, response_data, ip, headers) => {
686
+ export const add_account_log_util = function (body, status, service, source, response_data, ip, headers) {
687
+ // non error log
688
+ // if (status < 400) {
689
+ // console.log("error", "add_account_log_util", service);
690
+
643
691
  if (!_conf.cpi_methods?.[service]) return;
644
692
  if (_conf.cpi_methods?.[service]?.private) return;
645
693
  const security = _conf.cpi_methods?.[service].security;
646
694
  if (!security) {
647
695
  if (service.substr(0, 4) === 'get_' && !body.api_pk && !body.api_sk) return;
648
696
  }
649
-
697
+ // }
698
+ const logs_module = require(`${module_path}/logs_module`);
650
699
  logs_module.add_account_log(get_account_log_object(body, status, service, source, response_data, ip, headers, security));
651
700
  };
652
701
 
653
- export const save_ssh_key = async (req) => {
702
+ export const save_ssh_key = async function (req) {
654
703
  const { uid, _id, ssh_key_name, ssh_key_content } = req;
655
704
 
656
- const isValidSSHPublicKey = (sshPublicKey) => {
705
+ function isValidSSHPublicKey(sshPublicKey) {
657
706
  // Regular expression to match SSH public keys
658
707
  const sshKeyRegex = /^ssh-(rsa|ed25519|ecdsa-sha2-nistp[0-9]+) [A-Za-z0-9+/]+[=]{0,3}( [^@]+@[^@]+)?$/;
708
+
659
709
  return sshKeyRegex.test(sshPublicKey);
660
- };
710
+ }
661
711
 
662
712
  if (!isValidSSHPublicKey(ssh_key_content)) {
663
713
  return { code: -1, data: 'invalid ssh key' };
664
714
  }
665
715
 
666
- let doc = {
716
+ var doc = {
667
717
  uid,
668
718
  docType: 'ssh_key',
669
719
  date_created_ts: Date.now(),
@@ -689,15 +739,14 @@ export const save_ssh_key = async (req) => {
689
739
 
690
740
  return save_ret;
691
741
  };
692
-
693
- export const delete_ssh_key = async (req) => {
742
+ export const delete_ssh_key = async function (req) {
694
743
  const { ssh_key_id } = req;
695
744
 
696
745
  const ret = await db_module.get_couch_doc('xuda_ssh_keys', ssh_key_id);
697
746
  if (ret.code < 0) {
698
747
  return ret;
699
748
  }
700
- let doc = ret.data;
749
+ var doc = ret.data;
701
750
  doc.date_updated_ts = Date.now();
702
751
  doc.stat = 4;
703
752
 
@@ -706,7 +755,7 @@ export const delete_ssh_key = async (req) => {
706
755
  return save_ret;
707
756
  };
708
757
 
709
- export const get_ssh_keys = async (req) => {
758
+ export const get_ssh_keys = async function (req) {
710
759
  const { uid, _id } = req;
711
760
 
712
761
  let opt = {
@@ -717,11 +766,15 @@ export const get_ssh_keys = async (req) => {
717
766
  opt._id = _id;
718
767
  }
719
768
 
720
- let ret = await db_module.find_couch_query('xuda_ssh_keys', opt);
769
+ var ret = await db_module.find_couch_query('xuda_ssh_keys', opt);
721
770
  return ret;
722
771
  };
723
772
 
724
- export const search_users = async (req) => {
773
+ export const search_users = async function (req) {
774
+ // search
775
+ // skip
776
+ // limit
777
+ // bookmark
725
778
  try {
726
779
  if (!_conf.superuser_account_ids.includes(req.uid)) {
727
780
  throw new Error('user is not authorized for this method');
@@ -736,19 +789,48 @@ export const search_users = async (req) => {
736
789
  selector = {
737
790
  ...selector,
738
791
  $or: [
739
- { 'account_info.first_name': { $regex: `(?i)${req.search}` } },
740
- { 'account_info.last_name': { $regex: `(?i)${req.search}` } },
741
- { 'account_info.company_name': { $regex: `(?i)${req.search}` } },
742
- { 'account_info.tel': { $regex: `(?i)${req.search}` } },
743
- { 'account_info.email': { $regex: `(?i)${req.search}` } },
744
- { 'account_info.address': { $regex: `(?i)${req.search}` } },
745
- { _id: { $regex: `(?i)${req.search}` } },
792
+ {
793
+ 'account_info.first_name': {
794
+ $regex: `(?i)${req.search}`,
795
+ },
796
+ },
797
+ {
798
+ 'account_info.last_name': {
799
+ $regex: `(?i)${req.search}`,
800
+ },
801
+ },
802
+ {
803
+ 'account_info.company_name': {
804
+ $regex: `(?i)${req.search}`,
805
+ },
806
+ },
807
+ {
808
+ 'account_info.tel': {
809
+ $regex: `(?i)${req.search}`,
810
+ },
811
+ },
812
+ {
813
+ 'account_info.email': {
814
+ $regex: `(?i)${req.search}`,
815
+ },
816
+ },
817
+ {
818
+ 'account_info.address': {
819
+ $regex: `(?i)${req.search}`,
820
+ },
821
+ },
822
+ {
823
+ _id: {
824
+ $regex: `(?i)${req.search}`,
825
+ },
826
+ },
746
827
  ],
747
828
  };
748
829
  }
749
830
 
750
831
  const opt = {
751
832
  selector,
833
+
752
834
  limit: req.limit ? req.limit : 99999,
753
835
  };
754
836
 
@@ -761,23 +843,30 @@ export const search_users = async (req) => {
761
843
  }
762
844
 
763
845
  try {
764
- let ret = await db_module.find_couch_query('xuda_accounts', opt);
765
- return { code: 1, data: ret };
846
+ var ret = await db_module.find_couch_query('xuda_accounts', opt);
847
+
848
+ return {
849
+ code: 1,
850
+ data: ret,
851
+ };
766
852
  } catch (e) {
767
- return { code: -400, data: e };
853
+ return {
854
+ code: -400,
855
+ data: e,
856
+ };
768
857
  }
769
858
  } catch (err) {
770
859
  return { code: -1, data: err.message };
771
860
  }
772
861
  };
773
862
 
774
- export const read_emails = async (req) => {
863
+ export const read_emails = async function (req) {
775
864
  const { uid, email_account_address, email_account_id, accessToken, vendor } = req;
776
865
 
777
- const email_module = await import(`${module_path}/email_module/index.mjs`);
866
+ const email_module = require(`${module_path}/email_module`);
778
867
 
779
- const read_mailbox = async (mailbox_path, mailbox_name, is_sent) => {
780
- let emails_ret = await db_module.find_couch_query('xuda_emails', {
868
+ const read_mailbox = async function (mailbox_path, mailbox_name, is_sent) {
869
+ var emails_ret = await db_module.find_couch_query('xuda_emails', {
781
870
  selector: {
782
871
  docType: 'email',
783
872
  uid,
@@ -790,7 +879,7 @@ export const read_emails = async (req) => {
790
879
  sort: [{ 'message.seq': 'desc' }],
791
880
  });
792
881
 
793
- let imap_ret;
882
+ var imap_ret;
794
883
 
795
884
  const seq = emails_ret?.docs?.[0]?.message?.seq || 1;
796
885
  imap_ret = await email_module.query_imap({
@@ -801,9 +890,9 @@ export const read_emails = async (req) => {
801
890
  accessToken,
802
891
  });
803
892
 
804
- let senders = {};
805
- let recipient = {};
806
- let docs = [];
893
+ var senders = {};
894
+ var recipient = {};
895
+ var docs = [];
807
896
 
808
897
  for await (let message of imap_ret) {
809
898
  delete message.modseq;
@@ -830,6 +919,23 @@ export const read_emails = async (req) => {
830
919
  await db_module.save_couch_bulk_docs('xuda_emails', docs);
831
920
 
832
921
  for await (let [email, name] of Object.entries(is_sent ? recipient : senders)) {
922
+ // const contact_ret = await db_module.get_couch_view_raw(
923
+ // "xuda_contacts",
924
+ // "contacts_by_email_address",
925
+ // { key: [uid, email] }
926
+ // );
927
+
928
+ // if (!contact_ret.rows.length) {
929
+ // await db_module.save_couch_doc("xuda_contacts", {
930
+ // _id: await _common.xuda_get_uuid("contact"),
931
+ // email: [email],
932
+ // name,
933
+ // stat: 1,
934
+ // date_created: Date.now(),
935
+ // docType: "contact",
936
+ // uid,
937
+ // });
938
+ // }
833
939
  await add_contact({ uid, name, email });
834
940
  }
835
941
  }
@@ -847,6 +953,7 @@ export const read_emails = async (req) => {
847
953
  if (!['[Gmail]/Starred', '[Gmail]/Drafts', '[Gmail]/All Mail', '[Gmail]/Spam', '[Gmail]/Trash', '[Gmail]', '[Gmail]/Important'].includes(mailbox_obj.path)) {
848
954
  await read_mailbox(mailbox_obj.path, mailbox_obj.name, mailbox_obj.path === '[Gmail]/Sent Mail');
849
955
  }
956
+
850
957
  break;
851
958
 
852
959
  default:
@@ -858,11 +965,11 @@ export const read_emails = async (req) => {
858
965
  }
859
966
  };
860
967
 
861
- export const get_email_accounts = async (req) => {
968
+ export const get_email_accounts = async function (req) {
862
969
  const { uid, stat } = req;
863
970
 
864
- const db_module = await import(`${module_path}/db_module/index.mjs`);
865
- let email_account_ret = await db_module.find_couch_query('xuda_emails', {
971
+ const db_module = require(`${module_path}/db_module`);
972
+ var email_account_ret = await db_module.find_couch_query('xuda_emails', {
866
973
  selector: {
867
974
  docType: 'email_account',
868
975
  uid,
@@ -872,23 +979,28 @@ export const get_email_accounts = async (req) => {
872
979
  return { code: 1, data: email_account_ret };
873
980
  };
874
981
 
875
- const generate_gmail_access_token = async (email_account) => {
876
- const response = await fetch('https://oauth2.googleapis.com/token', {
877
- method: 'POST',
878
- headers: { 'Content-Type': 'application/json' },
879
- body: JSON.stringify({
880
- refresh_token: email_account.authorization_data.refresh_token,
881
- client_id: _conf.gmail.clientId,
882
- client_secret: _conf.gmail.clientSecret,
883
- grant_type: 'refresh_token',
884
- }),
982
+ const generate_gmail_access_token = async function (email_account) {
983
+ return new Promise((resolve, reject) => {
984
+ fetch('https://oauth2.googleapis.com/token', {
985
+ method: 'POST',
986
+ headers: { 'Content-Type': 'application/json' },
987
+ body: JSON.stringify({
988
+ refresh_token: email_account.authorization_data.refresh_token,
989
+ client_id: _conf.gmail.clientId,
990
+ client_secret: _conf.gmail.clientSecret,
991
+ grant_type: 'refresh_token',
992
+ }),
993
+ })
994
+ .then((response) => response.json())
995
+ .then((data) => {
996
+ resolve(data);
997
+ });
885
998
  });
886
- return await response.json();
887
999
  };
888
1000
 
889
- export const find_contact_duplicates = async (req) => {
1001
+ export const find_contact_duplicates = async function (req) {
890
1002
  const { uid, name } = req;
891
- let opt = {
1003
+ var opt = {
892
1004
  selector: {
893
1005
  docType: 'contact',
894
1006
  stat: { $lt: 4 },
@@ -901,8 +1013,8 @@ export const find_contact_duplicates = async (req) => {
901
1013
  opt.selector.name = name;
902
1014
  }
903
1015
  const contact_ret = await db_module.find_couch_query('xuda_contacts', opt);
904
- let duplicates = {};
905
- for (let contact of contact_ret.docs) {
1016
+ var duplicates = {};
1017
+ for (contact of contact_ret.docs) {
906
1018
  if (!duplicates[contact.name]) {
907
1019
  duplicates[contact.name] = [];
908
1020
  }
@@ -922,9 +1034,9 @@ export const find_contact_duplicates = async (req) => {
922
1034
  return { code: 1, data: duplicates };
923
1035
  };
924
1036
 
925
- export const merge_contact = async (req) => {
1037
+ export const merge_contact = async function (req) {
926
1038
  const { uid, name } = req;
927
- let duplicate_ret = await find_contact_duplicates({
1039
+ var duplicate_ret = await find_contact_duplicates({
928
1040
  uid,
929
1041
  name,
930
1042
  });
@@ -932,13 +1044,13 @@ export const merge_contact = async (req) => {
932
1044
  return duplicate_ret;
933
1045
  }
934
1046
 
935
- let duplicate_arr = duplicate_ret?.data?.[name] || [];
1047
+ var duplicate_arr = duplicate_ret?.data?.[name] || [];
936
1048
  if (!duplicate_arr.length) {
937
1049
  return { code: 1, data: 'no merge performed' };
938
1050
  }
939
- let contact_to_merge;
940
- let contact_to_delete = [];
941
- for (let contact of duplicate_arr) {
1051
+ var contact_to_merge;
1052
+ var contact_to_delete = [];
1053
+ for (contact of duplicate_arr) {
942
1054
  if (contact.primary) {
943
1055
  contact_to_merge = contact._id;
944
1056
  continue;
@@ -949,7 +1061,7 @@ export const merge_contact = async (req) => {
949
1061
  if (!contact_to_merge) {
950
1062
  // find best match for primary
951
1063
  for (let [i, contact_id] of Object.entries(contact_to_delete)) {
952
- let contact_obj = duplicate_arr.find((e) => e._id === contact_id);
1064
+ var contact_obj = duplicate_arr.find((e) => e._id === contact_id);
953
1065
 
954
1066
  if (contact_obj.name && !['spam', 'newsletter', 'noreply', 'no-reply'].includes(contact_obj.email?.[0]?.toLowerCase())) {
955
1067
  contact_to_merge = contact_id;
@@ -969,13 +1081,13 @@ export const merge_contact = async (req) => {
969
1081
  if (primary_contact_ret.code < 0) {
970
1082
  return primary_contact_ret;
971
1083
  }
972
- let primary_contact_doc = primary_contact_ret.data;
1084
+ var primary_contact_doc = primary_contact_ret.data;
973
1085
 
974
1086
  primary_contact_doc.stat_ts = Date.now();
975
1087
  primary_contact_doc.stat_reason = 'merge';
976
1088
 
977
1089
  for (let contact_id of contact_to_delete) {
978
- let email_address = duplicate_arr.find((e) => e._id === contact_id).email[0];
1090
+ var email_address = duplicate_arr.find((e) => e._id === contact_id).email[0];
979
1091
 
980
1092
  primary_contact_doc.email.push(email_address);
981
1093
  }
@@ -988,19 +1100,19 @@ export const merge_contact = async (req) => {
988
1100
  continue;
989
1101
  }
990
1102
 
991
- let contact_doc = contact_ret.data;
1103
+ var contact_doc = contact_ret.data;
992
1104
  contact_doc.stat = 4;
993
1105
  contact_doc.stat_ts = Date.now();
994
1106
  contact_doc.stat_reason = 'merge';
995
1107
  await db_module.save_couch_doc('xuda_contacts', contact_doc);
996
1108
  }
997
1109
 
998
- return primary_contact_save_ret;
1110
+ return primary_contact_save_ret; //{ code: 1, data: duplicate_arr };
999
1111
  };
1000
1112
 
1001
- export const get_contacts = async (req) => {
1113
+ export const get_contacts = async function (req) {
1002
1114
  const { uid, name, limit, skip, bookmark } = req;
1003
- let opt = {
1115
+ var opt = {
1004
1116
  selector: {
1005
1117
  docType: 'contact',
1006
1118
  uid,
@@ -1025,14 +1137,14 @@ export const get_contacts = async (req) => {
1025
1137
  return contacts_ret;
1026
1138
  };
1027
1139
 
1028
- export const delete_contact = async (req) => {
1140
+ export const delete_contact = async function (req) {
1029
1141
  const { _id } = req;
1030
1142
 
1031
1143
  const contact_ret = await db_module.get_couch_doc('xuda_contacts', _id);
1032
1144
  if (contact_ret.code < 0) {
1033
1145
  return contact_ret;
1034
1146
  }
1035
- let contact_doc = contact_ret.data;
1147
+ var contact_doc = contact_ret.data;
1036
1148
 
1037
1149
  contact_doc.stat_ts = Date.now();
1038
1150
  contact_doc.stat_reason = 'deleted';
@@ -1041,8 +1153,20 @@ export const delete_contact = async (req) => {
1041
1153
 
1042
1154
  return contact_save_ret;
1043
1155
  };
1044
-
1045
- export const add_contact = async (req) => {
1156
+ // invite user
1157
+
1158
+ // const contact_ret = await db_module.get_couch_view_raw(
1159
+ // "xuda_contacts",
1160
+ // "contacts_by_name_count",
1161
+ // {
1162
+ // startkey: [uid, ""],
1163
+ // endkey: [uid, "ZZZZZZZZZZ"],
1164
+ // reduce: true,
1165
+ // group_level: 2,
1166
+ // }
1167
+ // );
1168
+
1169
+ export const add_contact = async function (req) {
1046
1170
  const { uid, email, name, stat, contact_uid, req_id } = req;
1047
1171
  const contact_ret = await db_module.get_couch_view_raw('xuda_contacts', 'contacts_by_email_address', { key: [uid, email] });
1048
1172
 
@@ -1062,17 +1186,16 @@ export const add_contact = async (req) => {
1062
1186
  }
1063
1187
  return { code: -1, data: 'contact already exist active or deleted' };
1064
1188
  };
1065
-
1066
- export const update_contact = async (req) => {
1189
+ export const update_contact = async function (req) {
1067
1190
  const { uid, email, contact_uid, stat, req_id } = req;
1068
- let contact_ret;
1191
+ var contact_ret;
1069
1192
  if (email) {
1070
1193
  contact_ret = await db_module.get_couch_view_raw('xuda_contacts', 'contacts_by_email_address', { key: [uid, email] });
1071
1194
  } else if (contact_uid) {
1072
1195
  contact_ret = await db_module.get_couch_view_raw('xuda_contacts', 'contacts_by_contact_uid', { key: [uid, contact_uid] });
1073
1196
  }
1074
1197
  if (contact_ret.rows.length) {
1075
- let doc = contact_ret.rows[0].value;
1198
+ var doc = contact_ret.rows[0].value;
1076
1199
  if (stat) {
1077
1200
  doc.stat = stat;
1078
1201
  doc.stat_ts = Date.now();
@@ -1084,25 +1207,26 @@ export const update_contact = async (req) => {
1084
1207
  }
1085
1208
  return { code: -1, data: 'contact not found' };
1086
1209
  };
1087
-
1088
- export const invite_user = async (req) => {
1210
+ export const invite_user = async function (req) {
1089
1211
  const { email, name, uid } = req;
1090
1212
 
1091
- const team_module = await import(`${module_path}/team_module/index.mjs`);
1213
+ const team_module = require(`${module_path}/team_module`);
1092
1214
  const ret = await team_module.create_team_request({
1093
1215
  email,
1094
1216
  access_type: 'contact',
1095
1217
  uid,
1096
1218
  });
1219
+
1220
+ // return { code: -1, data: "contact already exist active or deleted" };
1097
1221
  };
1098
1222
 
1099
- export const get_account_rt_info = async (uid) => {
1223
+ export const get_account_rt_info = async function (uid) {
1100
1224
  const doc_ret = await db_module.get_couch_doc('xuda_accounts', uid);
1101
1225
  if (doc_ret.code < 0) {
1102
1226
  console.error('get_account_rt_info', doc_ret);
1103
1227
  return {};
1104
1228
  }
1105
- let account_info = doc_ret.data.account_info;
1229
+ var account_info = doc_ret.data.account_info;
1106
1230
 
1107
1231
  delete account_info.user_id;
1108
1232
 
@@ -1110,7 +1234,106 @@ export const get_account_rt_info = async (uid) => {
1110
1234
  return account_info;
1111
1235
  };
1112
1236
 
1113
- const get_prices = (uid, item) => {
1237
+ // export const validate_account_topup = async function (uid, items = []) {
1238
+ // const stripe_module = require(`${module_path}/stripe_module`);
1239
+
1240
+ // const { code, data } = await stripe_module.get_billing_metrics({ uid });
1241
+ // if (code < 0) {
1242
+ // throw new Error(data);
1243
+ // }
1244
+ // let topup = 0;
1245
+ // for (const item of items) {
1246
+ // topup += get_prices(uid, item);
1247
+ // }
1248
+
1249
+ // // if ((!data?.customer_obj?.default_source, { billing_problem: true, topup })) {
1250
+ // // throw new Error("no card on file");
1251
+ // // }
1252
+ // debugger;
1253
+ // if (data?.balance?.past_due) {
1254
+ // throw new Error(`past_due ${data?.balance?.past_due}`, {
1255
+ // billing_problem: true,
1256
+ // topup,
1257
+ // });
1258
+ // }
1259
+
1260
+ // const balance = data?.balance?.account || 0; // minus balance represents positive balance
1261
+
1262
+ // if (balance > 0) {
1263
+ // throw new Error(`negative balance ${-balance}`, {
1264
+ // billing_problem: true,
1265
+ // topup: topup - balance, // ask for whole balance
1266
+ // });
1267
+ // }
1268
+
1269
+ // if (topup + balance > 0) {
1270
+ // throw new Error(`not enough balance ${topup + balance}`, {
1271
+ // billing_problem: true,
1272
+ // topup, //-(topup + balance)
1273
+ // });
1274
+ // }
1275
+
1276
+ // return true;
1277
+ // };
1278
+
1279
+ export const validate_account_topup = async function (uid, items = []) {
1280
+ const stripe_module = require(`${module_path}/stripe_module`);
1281
+
1282
+ const { code, data } = await stripe_module.get_billing_metrics({ uid });
1283
+ if (code < 0) {
1284
+ throw new Error(data);
1285
+ }
1286
+ let topup = 0;
1287
+ for (const item of items) {
1288
+ topup += get_prices(uid, item);
1289
+ }
1290
+
1291
+ if (!data?.customer_obj?.default_source) {
1292
+ let err = new Error('no card on file');
1293
+ err.code = -90;
1294
+ err.billing_problem = true;
1295
+ throw err;
1296
+ // throw new Error('no card on file');
1297
+ }
1298
+
1299
+ if (data?.balance?.past_due) {
1300
+ let err = new Error(`past_due ${data.balance.past_due}`);
1301
+ err.code = -91;
1302
+ err.billing_problem = true;
1303
+ err.topup = topup + data.balance.past_due;
1304
+ err.open_invoices = data?.open_invoices;
1305
+ throw err;
1306
+ }
1307
+ // if (data?.balance?.past_due) {
1308
+ // let err = new Error(`past_due ${data?.balance?.past_due}`);
1309
+ // err.code = -91;
1310
+ // err.billing_problem = true;
1311
+ // err.topup = topup;
1312
+ // throw err;
1313
+ // }
1314
+
1315
+ const balance = data?.balance?.account || 0; // minus balance represents positive balance
1316
+
1317
+ if (balance > 0) {
1318
+ let err = new Error(`negative balance ${-balance}`);
1319
+ err.code = -92;
1320
+ err.billing_problem = true;
1321
+ err.topup = topup - balance; // ask for whole balance
1322
+ throw err;
1323
+ }
1324
+
1325
+ if (topup + balance > 0) {
1326
+ let err = new Error(`not enough balance ${topup + balance}`);
1327
+ err.code = -93;
1328
+ err.billing_problem = true;
1329
+ err.topup = topup;
1330
+ throw err;
1331
+ }
1332
+
1333
+ return true;
1334
+ };
1335
+
1336
+ const get_prices = function (uid, item) {
1114
1337
  let price;
1115
1338
 
1116
1339
  switch (item) {
@@ -1172,56 +1395,7 @@ const get_prices = (uid, item) => {
1172
1395
  return price;
1173
1396
  };
1174
1397
 
1175
- export const validate_account_topup = async (uid, items = []) => {
1176
- const stripe_module = await import(`${module_path}/stripe_module/index.mjs`);
1177
-
1178
- const { code, data } = await stripe_module.get_billing_metrics({ uid });
1179
- if (code < 0) {
1180
- throw new Error(data);
1181
- }
1182
- let topup = 0;
1183
- for (const item of items) {
1184
- topup += get_prices(uid, item);
1185
- }
1186
-
1187
- if (!data?.customer_obj?.default_source) {
1188
- let err = new Error('no card on file');
1189
- err.code = -90;
1190
- err.billing_problem = true;
1191
- throw err;
1192
- }
1193
-
1194
- if (data?.balance?.past_due) {
1195
- let err = new Error(`past_due ${data.balance.past_due}`);
1196
- err.code = -91;
1197
- err.billing_problem = true;
1198
- err.topup = topup + data.balance.past_due;
1199
- err.open_invoices = data?.open_invoices;
1200
- throw err;
1201
- }
1202
-
1203
- const balance = data?.balance?.account || 0; // minus balance represents positive balance
1204
-
1205
- if (balance > 0) {
1206
- let err = new Error(`negative balance ${-balance}`);
1207
- err.code = -92;
1208
- err.billing_problem = true;
1209
- err.topup = topup - balance; // ask for whole balance
1210
- throw err;
1211
- }
1212
-
1213
- if (topup + balance > 0) {
1214
- let err = new Error(`not enough balance ${topup + balance}`);
1215
- err.code = -93;
1216
- err.billing_problem = true;
1217
- err.topup = topup;
1218
- throw err;
1219
- }
1220
-
1221
- return true;
1222
- };
1223
-
1224
- export const create_account_oauth_link = async (req, job_id) => {
1398
+ export const create_account_oauth_link = async function (req, job_id) {
1225
1399
  const link = `https://accounts.google.com/o/oauth2/v2/auth?scope=https://mail.google.com/&access_type=offline&include_granted_scopes=true&response_type=code&state=${req.uid}&redirect_uri=https://${_conf.is_debug ? 'dev.' : ''}xuda.io/oauth&client_id=${_conf.gmail.clientId}`;
1226
1400
  await jobs_module.update_job(
1227
1401
  {
@@ -1232,9 +1406,70 @@ export const create_account_oauth_link = async (req, job_id) => {
1232
1406
  global[`_account_module_ch`],
1233
1407
  );
1234
1408
  await _utils.delay(20000);
1235
- // debugger;
1409
+ debugger;
1236
1410
  return {
1237
1411
  code: 1,
1238
1412
  data: link,
1239
1413
  };
1240
1414
  };
1415
+
1416
+ // setTimeout(async () => {
1417
+ // const uid = "0489f946c213947316647b468f029ed9"; //"aecc740881fd0a35098c738652000fab";
1418
+
1419
+ // // // clear data
1420
+ // // const contact_ret = await db_module.find_couch_query("xuda_contacts", {
1421
+ // // selector: {
1422
+ // // docType: "contact",
1423
+ // // },
1424
+ // // limit: 99999,
1425
+ // // });
1426
+ // // var contact_docs = [];
1427
+ // // for (let val of contact_ret.docs) {
1428
+ // // val._deleted = true;
1429
+ // // contact_docs.push(val);
1430
+ // // }
1431
+ // // await db_module.save_couch_bulk_docs("xuda_contacts", contact_docs);
1432
+
1433
+ // // const emails_ret = await db_module.find_couch_query("xuda_emails", {
1434
+ // // selector: {
1435
+ // // docType: "email",
1436
+ // // },
1437
+ // // limit: 99999,
1438
+ // // });
1439
+ // // var email_docs = [];
1440
+ // // for (let val of emails_ret.docs) {
1441
+ // // val._deleted = true;
1442
+ // // email_docs.push(val);
1443
+ // // }
1444
+
1445
+ // // await db_module.save_couch_bulk_docs("xuda_emails", email_docs);
1446
+
1447
+ // ///////////////////////////////////
1448
+ // return;
1449
+ // const email_account_ret = await get_email_accounts({
1450
+ // uid,
1451
+ // });
1452
+
1453
+ // var accessToken;
1454
+ // for await (let email_account of email_account_ret.data.docs) {
1455
+ // switch (email_account.vendor) {
1456
+ // case "gmail":
1457
+ // const ret = await generate_gmail_access_token(email_account);
1458
+ // accessToken = ret.access_token;
1459
+ // break;
1460
+
1461
+ // default:
1462
+ // break;
1463
+ // }
1464
+
1465
+ // read_emails({
1466
+ // uid,
1467
+ // email_account_address: email_account.email,
1468
+ // accessToken,
1469
+ // email_account_id: email_account._id,
1470
+ // vendor: email_account.vendor,
1471
+ // });
1472
+ // }
1473
+
1474
+ // // console.log(await get_contact({ uid, name: "bo" }));
1475
+ // }, 2000);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/account_module",
3
- "version": "1.2.154",
3
+ "version": "1.2.155",
4
4
  "description": "Xuda Account Server Module",
5
5
  "main": "index.mjs",
6
6
  "dependencies": {