@xuda.io/account_module 1.2.100 → 1.2.101

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.js +221 -398
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1,19 +1,10 @@
1
- const path = require("path");
2
- global._conf = require(path.join(
3
- process.env.XUDA_HOME,
4
- process.env.XUDA_CONFIG
5
- ));
6
-
7
- const _common = require(path.join(
8
- process.env.XUDA_HOME,
9
- "common",
10
- "xuda_node_common.js"
11
- ));
12
-
13
- const _ = require("lodash");
14
- const module_path =
15
- path.join(process.env.XUDA_HOME, "cpi") +
16
- (!_conf.is_debug ? "/node_modules/@xuda.io" : "");
1
+ const path = require('path');
2
+ global._conf = require(path.join(process.env.XUDA_HOME, process.env.XUDA_CONFIG));
3
+
4
+ const _common = require(path.join(process.env.XUDA_HOME, 'common', 'xuda_node_common.js'));
5
+
6
+ const _ = require('lodash');
7
+ const module_path = path.join(process.env.XUDA_HOME, 'cpi') + (!_conf.is_debug ? '/node_modules/@xuda.io' : '');
17
8
  const db_module = require(`${module_path}/db_module`);
18
9
 
19
10
  exports.update_account_info = async function (req) {
@@ -36,64 +27,55 @@ exports.update_account_info = async function (req) {
36
27
  }
37
28
  }
38
29
 
39
- const ret = await db_module.get_couch_doc("xuda_accounts", uid);
30
+ const ret = await db_module.get_couch_doc('xuda_accounts', uid);
40
31
  var account_obj = ret.data;
41
32
  account_obj.ts = Date.now();
42
- var change = "";
33
+ var change = '';
43
34
  var error = {};
44
35
 
45
36
  await marketplace_module.marketplace_save_user({ uid });
46
37
 
47
38
  _.forEach(data, function (val, key) {
48
39
  if (account_obj.account_info[key] !== val) {
49
- change += " from " + account_obj.account_info[key] + " to " + val;
40
+ change += ' from ' + account_obj.account_info[key] + ' to ' + val;
50
41
 
51
42
  account_obj.account_info[key] = val;
52
43
 
53
- if (account_obj.account_info.account_type === "business") {
54
- if (
55
- key === "company_name" &&
56
- validate_input(val, 150, true, false) < 0
57
- ) {
58
- error[key] = "Invalid company";
44
+ if (account_obj.account_info.account_type === 'business') {
45
+ if (key === 'company_name' && validate_input(val, 150, true, false) < 0) {
46
+ error[key] = 'Invalid company';
59
47
  }
60
48
  }
61
- if (key === "first_name" && !validate_input(val, 35, true, false)) {
49
+ if (key === 'first_name' && !validate_input(val, 35, true, false)) {
62
50
  // print_r(validate_input($val, 35, true, false)<0);
63
51
  // exit;
64
- error[key] = "Invalid first name";
52
+ error[key] = 'Invalid first name';
65
53
  }
66
- if (key === "last_name" && !validate_input(val, 35, true, false)) {
67
- error[key] = "Invalid last name";
54
+ if (key === 'last_name' && !validate_input(val, 35, true, false)) {
55
+ error[key] = 'Invalid last name';
68
56
  }
69
- if (
70
- key === "email" &&
71
- (!validator.isEmail(val) || !val || val.length < 2)
72
- ) {
73
- error[key] = "Invalid email";
57
+ if (key === 'email' && (!validator.isEmail(val) || !val || val.length < 2)) {
58
+ error[key] = 'Invalid email';
74
59
  }
75
- if (
76
- key === "tel" &&
77
- (!/^[0-9]{3}-[0-9]{4}-[0-9]{4}$/.test(val) || !val || val.length < 2)
78
- ) {
60
+ if (key === 'tel' && (!/^[0-9]{3}-[0-9]{4}-[0-9]{4}$/.test(val) || !val || val.length < 2)) {
79
61
  // if (key === "tel" && (!preg_match("/^[0-9]{3}-[0-9]{4}-[0-9]{4}$/", $val) || !$val || count($val) < 2)) {
80
- error[key] = "Invalid phone number";
62
+ error[key] = 'Invalid phone number';
81
63
  }
82
- if (key === "address" && !/^[a-z0-9- ]+$/i.test(val)) {
64
+ if (key === 'address' && !/^[a-z0-9- ]+$/i.test(val)) {
83
65
  // if (key === "address" && !preg_match('/^[a-z0-9- ]+$/i', $val)) {
84
- error[key] = "Invalid address";
66
+ error[key] = 'Invalid address';
85
67
  }
86
- if (key === "city" && !validate_input(val, 255, false, false)) {
87
- error[key] = "Invalid city";
68
+ if (key === 'city' && !validate_input(val, 255, false, false)) {
69
+ error[key] = 'Invalid city';
88
70
  }
89
- if (key === "state" && !validate_input(val, 50, false, false)) {
90
- error[key] = "Invalid state";
71
+ if (key === 'state' && !validate_input(val, 50, false, false)) {
72
+ error[key] = 'Invalid state';
91
73
  }
92
- if (key === "zip" && validate_input(val, 9, false, false) < 0) {
93
- error[key] = "Invalid zip";
74
+ if (key === 'zip' && validate_input(val, 9, false, false) < 0) {
75
+ error[key] = 'Invalid zip';
94
76
  }
95
- if (key === "country" && !validate_input(val, 55, false, false)) {
96
- error[key] = "Invalid country";
77
+ if (key === 'country' && !validate_input(val, 55, false, false)) {
78
+ error[key] = 'Invalid country';
97
79
  }
98
80
  }
99
81
  });
@@ -102,14 +84,14 @@ exports.update_account_info = async function (req) {
102
84
  return { code: -1310, data: error };
103
85
  }
104
86
  if (!change) {
105
- return { code: 1300, data: "no change" };
87
+ return { code: 1300, data: 'no change' };
106
88
  }
107
89
  delete account_obj.account_info.gtp_token;
108
90
  delete account_obj.account_info.client_id;
109
91
  delete account_obj.account_info.uid;
110
- const ret2 = await db_module.save_couch_doc("xuda_accounts", account_obj);
92
+ const ret2 = await db_module.save_couch_doc('xuda_accounts', account_obj);
111
93
  if (ret2.code > 0) {
112
- return { code: 1300, data: "ok" };
94
+ return { code: 1300, data: 'ok' };
113
95
  }
114
96
  return ret2;
115
97
  };
@@ -117,13 +99,13 @@ exports.update_account_preferences = async function (req) {
117
99
  const account_id = req.account_id;
118
100
  const data = req;
119
101
 
120
- const ret = await db_module.get_couch_doc("xuda_accounts", account_id);
102
+ const ret = await db_module.get_couch_doc('xuda_accounts', account_id);
121
103
  var account_obj = ret.data;
122
104
  account_obj.ts = Date.now();
123
105
 
124
106
  account_obj.preferences = data;
125
107
 
126
- const ret1 = await db_module.save_couch_doc("xuda_accounts", account_obj);
108
+ const ret1 = await db_module.save_couch_doc('xuda_accounts', account_obj);
127
109
  if (ret1.code < 0) {
128
110
  return ret1;
129
111
  }
@@ -131,7 +113,7 @@ exports.update_account_preferences = async function (req) {
131
113
  };
132
114
 
133
115
  exports.save_admin_presets = async function (req) {
134
- const ret = await db_module.get_couch_doc("xuda_master", req.app_id);
116
+ const ret = await db_module.get_couch_doc('xuda_master', req.app_id);
135
117
  if (ret.code < 0) {
136
118
  return ret;
137
119
  }
@@ -144,7 +126,7 @@ exports.save_admin_presets = async function (req) {
144
126
  if (ret3.code > -1) {
145
127
  obj = {
146
128
  code: 1,
147
- data: "ok",
129
+ data: 'ok',
148
130
  app_obj: _common.get_clean_app_obj(app_obj),
149
131
  };
150
132
  } else {
@@ -161,11 +143,7 @@ exports.increment_account_usage = async function (req) {
161
143
  if (uid) {
162
144
  opt.key = uid;
163
145
  }
164
- const accounts_ret = await db_module.get_couch_view_raw(
165
- "xuda_accounts",
166
- "all_accounts",
167
- opt
168
- );
146
+ const accounts_ret = await db_module.get_couch_view_raw('xuda_accounts', 'all_accounts', opt);
169
147
 
170
148
  const drive_module = require(`${module_path}/drive_module`);
171
149
 
@@ -178,27 +156,20 @@ exports.increment_account_usage = async function (req) {
178
156
 
179
157
  const run_account_drive = async function (account_data) {
180
158
  try {
181
- const usage_id = await _common.xuda_get_uuid("usage");
159
+ const usage_id = await _common.xuda_get_uuid('usage');
182
160
 
183
- const usage_ret = await db_module.get_couch_view_raw(
184
- "xuda_usage",
185
- "open_drive_usage",
186
- {
187
- key: account_data._id,
188
- }
189
- );
161
+ const usage_ret = await db_module.get_couch_view_raw('xuda_usage', 'open_drive_usage', {
162
+ key: account_data._id,
163
+ });
190
164
 
191
165
  var doc = {
192
166
  _id: usage_id,
193
- docType: "user_drive_usage",
167
+ docType: 'user_drive_usage',
194
168
  date_created: new Date(),
195
169
  stat: 1,
196
170
  uid: account_data._id,
197
171
  stripe_customer_id: account_data.stripe_customer_id,
198
- account_name:
199
- account_data.account_info.first_name +
200
- " " +
201
- account_data.account_info.last_name,
172
+ account_name: account_data.account_info.first_name + ' ' + account_data.account_info.last_name,
202
173
  size: 0,
203
174
  price: 0,
204
175
  hours: 0,
@@ -212,23 +183,16 @@ exports.increment_account_usage = async function (req) {
212
183
 
213
184
  if (Date.now() - doc.ts >= interval) {
214
185
  const plan = _conf.PLAN_OBJ[account_data.plan];
215
- const drive_size_total =
216
- account_data.user_drive_size +
217
- account_data.studio_drive_size +
218
- account_data.workspace_drive_size +
219
- account_data.builds_drive_size +
220
- account_data.plugins_drive_size;
186
+ 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;
221
187
  if (bytesToGB(drive_size_total) > plan.features.drive) {
222
- var price_per_hour =
223
- (bytesToGB(drive_size_total) * _conf.PRICE_OBJ.price_per_gb_drive) /
224
- _conf.PRICE_OBJ.avg_hours_in_month;
188
+ var price_per_hour = (bytesToGB(drive_size_total) * _conf.PRICE_OBJ.price_per_gb_drive) / _conf.PRICE_OBJ.avg_hours_in_month;
225
189
 
226
190
  doc.hours++;
227
191
  doc.size = drive_size_total;
228
192
  doc.price += price_per_hour;
229
193
 
230
194
  doc.ts = Date.now();
231
- await db_module.save_couch_doc("xuda_usage", doc);
195
+ await db_module.save_couch_doc('xuda_usage', doc);
232
196
  }
233
197
  }
234
198
  } catch (err) {
@@ -237,77 +201,58 @@ exports.increment_account_usage = async function (req) {
237
201
  };
238
202
 
239
203
  const run_account_apps = async function (account_data) {
240
- const apps_ret = await db_module.get_couch_view(
241
- "xuda_master",
242
- "user_apps",
243
- {
244
- startkey: [account_data._id, ""],
245
- endkey: [account_data._id, "ZZZZZ"],
246
- include_docs: true,
247
- }
248
- );
204
+ const apps_ret = await db_module.get_couch_view('xuda_master', 'user_apps', {
205
+ startkey: [account_data._id, ''],
206
+ endkey: [account_data._id, 'ZZZZZ'],
207
+ include_docs: true,
208
+ });
249
209
 
250
210
  try {
251
211
  for await (let app of apps_ret.data.rows) {
252
- if (app.value.app_type === "master") {
212
+ if (app.value.app_type === 'master') {
253
213
  let size_ret = await drive_module.get_drive_size({
254
- drive_type: "studio",
214
+ drive_type: 'studio',
255
215
  app_id: app.id,
256
216
  });
257
- if (size_ret.code > -1)
258
- account_data.studio_drive_size += size_ret.data;
217
+ if (size_ret.code > -1) account_data.studio_drive_size += size_ret.data;
259
218
 
260
219
  size_ret = await drive_module.get_drive_size({
261
- drive_type: "workspace",
220
+ drive_type: 'workspace',
262
221
  app_id: app.id,
263
222
  });
264
- if (size_ret.code > -1)
265
- account_data.workspace_drive_size += size_ret.data;
223
+ if (size_ret.code > -1) account_data.workspace_drive_size += size_ret.data;
266
224
 
267
225
  size_ret = await drive_module.get_drive_size({
268
- drive_type: "builds",
226
+ drive_type: 'builds',
269
227
  app_id: app.id,
270
228
  });
271
- if (size_ret.code > -1)
272
- account_data.builds_drive_size += size_ret.data;
229
+ if (size_ret.code > -1) account_data.builds_drive_size += size_ret.data;
273
230
 
274
231
  size_ret = await drive_module.get_drive_size({
275
- drive_type: "plugins",
232
+ drive_type: 'plugins',
276
233
  app_id: app.id,
277
234
  });
278
- if (size_ret.code > -1)
279
- account_data.plugins_drive_size += size_ret.data;
235
+ if (size_ret.code > -1) account_data.plugins_drive_size += size_ret.data;
280
236
 
281
237
  // db data
282
238
  const couch_info_ret = await db_module.get_couch_app_info(app.id);
283
- account_data.project_data_size +=
284
- couch_info_ret?.data?.sizes?.active || 0;
239
+ account_data.project_data_size += couch_info_ret?.data?.sizes?.active || 0;
285
240
  }
286
241
 
287
- const usage_id = await _common.xuda_get_uuid("usage");
242
+ const usage_id = await _common.xuda_get_uuid('usage');
288
243
 
289
- const usage_ret = await db_module.get_couch_view_raw(
290
- "xuda_usage",
291
- "open_app_usage",
292
- {
293
- key: [
294
- app.id,
295
- app.doc?.app_hosting?.app_server_type || app.doc.app_type,
296
- ],
297
- }
298
- );
244
+ const usage_ret = await db_module.get_couch_view_raw('xuda_usage', 'open_app_usage', {
245
+ key: [app.id, app.doc?.app_hosting?.app_server_type || app.doc.app_type],
246
+ });
299
247
 
300
248
  var doc = {
301
249
  _id: usage_id,
302
- docType: "app_usage",
250
+ docType: 'app_usage',
303
251
  date_created: new Date(),
304
252
  stat: 1,
305
253
  uid: account_data._id,
306
254
  stripe_customer_id: account_data.stripe_customer_id,
307
- account_name:
308
- account_data.account_info.first_name +
309
- " " +
310
- account_data.account_info.last_name,
255
+ account_name: account_data.account_info.first_name + ' ' + account_data.account_info.last_name,
311
256
  app_id: app.id,
312
257
  price: 0,
313
258
  hours: 0,
@@ -318,7 +263,7 @@ exports.increment_account_usage = async function (req) {
318
263
  subscription_id: account_data.stripe_membership_subscription_id,
319
264
  };
320
265
 
321
- if (doc.app_type === "user_group") {
266
+ if (doc.app_type === 'user_group') {
322
267
  doc = {
323
268
  ...doc,
324
269
  ...{
@@ -342,46 +287,34 @@ exports.increment_account_usage = async function (req) {
342
287
  doc.hours++;
343
288
 
344
289
  switch (doc.app_type) {
345
- case "backup":
290
+ case 'backup':
346
291
  if (app.value.app_hosting) {
347
292
  // backup of deployment
348
- price_per_hour =
349
- (app.value.app_hosting.disk *
350
- _conf.PRICE_OBJ.price_per_gb_backup) /
351
- _conf.PRICE_OBJ.avg_hours_in_month;
293
+ price_per_hour = (app.value.app_hosting.disk * _conf.PRICE_OBJ.price_per_gb_backup) / _conf.PRICE_OBJ.avg_hours_in_month;
352
294
  } else {
353
295
  // backup of project
354
296
 
355
297
  const info_ret = await db_module.get_couch_app_info(doc.app_id);
356
298
  if (info_ret.code > 0) {
357
299
  const size = info_ret.data.sizes.active / 1000 / 1000 / 1000; //gb
358
- price_per_hour =
359
- (size * _conf.PRICE_OBJ.price_per_gb_backup) /
360
- _conf.PRICE_OBJ.avg_hours_in_month;
300
+ price_per_hour = (size * _conf.PRICE_OBJ.price_per_gb_backup) / _conf.PRICE_OBJ.avg_hours_in_month;
361
301
  }
362
302
  }
363
303
  break;
364
304
 
365
- case "user_group": {
366
- const team_ret = await db_module.get_couch_view(
367
- "xuda_team",
368
- "user_group_shares_count",
369
- {
370
- key: app.id,
371
- reduce: true,
372
- group_level: 1,
373
- }
374
- );
305
+ case 'user_group': {
306
+ const team_ret = await db_module.get_couch_view('xuda_team', 'user_group_shares_count', {
307
+ key: app.id,
308
+ reduce: true,
309
+ group_level: 1,
310
+ });
375
311
 
376
312
  const team_members = team_ret.data.rows?.[0]?.value || 0;
377
- const price_per_hour_team =
378
- (team_members * _conf.PRICE_OBJ.price_per_user_group_member) /
379
- _conf.PRICE_OBJ.avg_hours_in_month;
313
+ const price_per_hour_team = (team_members * _conf.PRICE_OBJ.price_per_user_group_member) / _conf.PRICE_OBJ.avg_hours_in_month;
380
314
  doc.price_user_group += price_per_hour_team;
381
315
  doc.user_group_members = team_members;
382
316
  doc.user_group_members_accumulated += team_members;
383
- doc.user_group_members_avg =
384
- doc.user_group_members_accumulated / doc.hours;
317
+ doc.user_group_members_avg = doc.user_group_members_accumulated / doc.hours;
385
318
  }
386
319
 
387
320
  default:
@@ -390,8 +323,7 @@ exports.increment_account_usage = async function (req) {
390
323
 
391
324
  doc.app_hosting = app.doc.app_hosting;
392
325
  doc.server_type = app.doc.app_hosting.app_server_type;
393
- price_per_hour =
394
- app.doc.app_hosting.price / _conf.PRICE_OBJ.avg_hours_in_month;
326
+ price_per_hour = app.doc.app_hosting.price / _conf.PRICE_OBJ.avg_hours_in_month;
395
327
 
396
328
  break;
397
329
  }
@@ -401,7 +333,7 @@ exports.increment_account_usage = async function (req) {
401
333
  }
402
334
 
403
335
  doc.ts = Date.now();
404
- await db_module.save_couch_doc("xuda_usage", doc);
336
+ await db_module.save_couch_doc('xuda_usage', doc);
405
337
  }
406
338
  }
407
339
  } catch (err) {
@@ -415,7 +347,7 @@ exports.increment_account_usage = async function (req) {
415
347
 
416
348
  const size_ret = await drive_module.get_drive_size({
417
349
  uid: account_data._id,
418
- drive_type: "user",
350
+ drive_type: 'user',
419
351
  });
420
352
 
421
353
  account_data.user_drive_size = size_ret.data;
@@ -428,14 +360,8 @@ exports.increment_account_usage = async function (req) {
428
360
  await run_account_apps(account_data);
429
361
  await run_account_drive(account_data);
430
362
 
431
- account_data.total_drive_size =
432
- account_data.user_drive_size +
433
- account_data.studio_drive_size +
434
- account_data.workspace_drive_size +
435
- account_data.plugins_drive_size +
436
- account_data.builds_drive_size +
437
- account_data.project_data_size;
438
- await db_module.save_couch_doc("xuda_accounts", account_data);
363
+ 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;
364
+ await db_module.save_couch_doc('xuda_accounts', account_data);
439
365
  }
440
366
  };
441
367
 
@@ -456,10 +382,7 @@ exports.get_account_data = async function (req) {
456
382
  // };
457
383
 
458
384
  try {
459
- const { data: acc_obj } = await db_module.get_couch_doc(
460
- "xuda_accounts",
461
- uid
462
- );
385
+ const { data: acc_obj } = await db_module.get_couch_doc('xuda_accounts', uid);
463
386
  // const account_obj= account_ret.data
464
387
  var ret = { code: 1 };
465
388
  ret.data = {
@@ -522,30 +445,27 @@ exports.get_account_projects = async function (req) {
522
445
  key: uid,
523
446
  };
524
447
 
525
- if (
526
- _conf.superuser_account_ids.includes(uid) ||
527
- _conf.support.support_team_account_ids.includes(uid)
528
- ) {
448
+ if (_conf.superuser_account_ids.includes(uid) || _conf.support.support_team_account_ids.includes(uid)) {
529
449
  opt = {};
530
450
  }
531
451
 
532
- var ret = await db_module.get_couch_view("xuda_master", "user_projects", opt);
452
+ var ret = await db_module.get_couch_view('xuda_master', 'user_projects', opt);
533
453
 
534
454
  return ret;
535
455
  };
536
456
 
537
457
  exports.get_account_datacenters = async function (req) {
538
- return await db_module.get_couch_view("xuda_master", "user_datacenters", {
458
+ return await db_module.get_couch_view('xuda_master', 'user_datacenters', {
539
459
  key: req.uid,
540
460
  });
541
461
  };
542
462
  exports.get_account_deployments = async function (req) {
543
- return await db_module.get_couch_view("xuda_master", "user_deployments", {
463
+ return await db_module.get_couch_view('xuda_master', 'user_deployments', {
544
464
  key: req.uid,
545
465
  });
546
466
  };
547
467
  exports.get_account_instances = async function (req) {
548
- return await db_module.get_couch_view("xuda_master", "user_all_instances", {
468
+ return await db_module.get_couch_view('xuda_master', 'user_all_instances', {
549
469
  key: req.uid,
550
470
  });
551
471
  };
@@ -558,17 +478,17 @@ exports.get_account_info = async function (req) {
558
478
  };
559
479
 
560
480
  exports.get_account_name = async function (req) {
561
- const data = await db_module.get_couch_doc("xuda_accounts", req.uid_query);
481
+ const data = await db_module.get_couch_doc('xuda_accounts', req.uid_query);
562
482
  if (data.code < 0) {
563
483
  return data;
564
484
  }
565
485
  var obj = {
566
- first_name: "",
567
- last_name: "",
568
- email: "",
569
- phone: "",
570
- profile_picture: "",
571
- username: "",
486
+ first_name: '',
487
+ last_name: '',
488
+ email: '',
489
+ phone: '',
490
+ profile_picture: '',
491
+ username: '',
572
492
  };
573
493
  if (data.data.account_info) {
574
494
  obj = {
@@ -585,17 +505,17 @@ exports.get_account_name = async function (req) {
585
505
 
586
506
  exports.account_validate_username = async function (req) {
587
507
  const opt = {
588
- selector: { "account_info.username": req.username },
589
- fields: ["_id"],
508
+ selector: { 'account_info.username': req.username },
509
+ fields: ['_id'],
590
510
  limit: 1,
591
511
  };
592
512
 
593
- var ret = await db_module.find_couch_query("xuda_accounts", opt);
513
+ var ret = await db_module.find_couch_query('xuda_accounts', opt);
594
514
 
595
515
  if (ret.docs.length) {
596
- return { code: -400, data: "User exist" };
516
+ return { code: -400, data: 'User exist' };
597
517
  } else {
598
- return { code: 1, data: "ok" };
518
+ return { code: 1, data: 'ok' };
599
519
  }
600
520
  };
601
521
 
@@ -612,17 +532,17 @@ exports.account_validate_username = async function (req) {
612
532
  exports.verify_account = async function (req) {
613
533
  const { account_id } = req;
614
534
  if (!account_id) {
615
- return { code: -10, data: "Missing id" };
535
+ return { code: -10, data: 'Missing id' };
616
536
  }
617
537
 
618
- const ret = await db_module.get_couch_doc("xuda_accounts", account_id);
538
+ const ret = await db_module.get_couch_doc('xuda_accounts', account_id);
619
539
 
620
540
  if (ret.code < 0) {
621
- return { code: -1, data: "account not found" };
541
+ return { code: -1, data: 'account not found' };
622
542
  }
623
543
  var obj = ret.data;
624
544
  obj.stat = 3;
625
- const ret_acc = await db_module.save_couch_doc("xuda_accounts", obj);
545
+ const ret_acc = await db_module.save_couch_doc('xuda_accounts', obj);
626
546
  if (ret.code < 0) {
627
547
  return ret_acc;
628
548
  }
@@ -632,16 +552,12 @@ exports.verify_account = async function (req) {
632
552
  exports.validate_user_plan = async function (req) {
633
553
  const { account_id, app_obj } = req;
634
554
 
635
- const apps_ret = await db_module.get_couch_view(
636
- "xuda_master",
637
- "user_apps_count",
638
- {
639
- startkey: [account_id, ""],
640
- endkey: [account_id, "ZZZZZ"],
641
- reduce: true,
642
- group_level: 2,
643
- }
644
- );
555
+ const apps_ret = await db_module.get_couch_view('xuda_master', 'user_apps_count', {
556
+ startkey: [account_id, ''],
557
+ endkey: [account_id, 'ZZZZZ'],
558
+ reduce: true,
559
+ group_level: 2,
560
+ });
645
561
 
646
562
  var ret_obj = _.reduce(
647
563
  apps_ret.data.rows,
@@ -649,10 +565,10 @@ exports.validate_user_plan = async function (req) {
649
565
  ret[value.key[1]] = value.value;
650
566
  return ret;
651
567
  },
652
- {}
568
+ {},
653
569
  );
654
570
 
655
- const ret = await db_module.get_couch_doc("xuda_accounts", account_id);
571
+ const ret = await db_module.get_couch_doc('xuda_accounts', account_id);
656
572
  if (ret.code < 0) {
657
573
  return ret;
658
574
  }
@@ -660,14 +576,11 @@ exports.validate_user_plan = async function (req) {
660
576
  // get plan from user
661
577
 
662
578
  if (!plan) {
663
- return { code: -7, data: "error - no plan defined" };
579
+ return { code: -7, data: 'error - no plan defined' };
664
580
  }
665
581
 
666
582
  // validate number of projects
667
- if (
668
- app_obj.app_type === "master" &&
669
- ret_obj.master >= plan.features.projects
670
- ) {
583
+ if (app_obj.app_type === 'master' && ret_obj.master >= plan.features.projects) {
671
584
  return {
672
585
  code: -8,
673
586
  data: `Number of projects (${ret.data.plan}) exceeds to the ${plan.features.projects} plan limits`,
@@ -676,21 +589,13 @@ exports.validate_user_plan = async function (req) {
676
589
 
677
590
  // validate number of team members
678
591
 
679
- const user_active_app_requests_count_ret = await db_module.get_couch_view(
680
- "xuda_team",
681
- "user_active_app_requests_count",
682
- {
683
- key: account_id,
684
- reduce: true,
685
- // group_level: 2,
686
- }
687
- );
592
+ const user_active_app_requests_count_ret = await db_module.get_couch_view('xuda_team', 'user_active_app_requests_count', {
593
+ key: account_id,
594
+ reduce: true,
595
+ // group_level: 2,
596
+ });
688
597
 
689
- if (
690
- app_obj.app_type === "master" &&
691
- user_active_app_requests_count_ret.data?.rows?.[0]?.value >=
692
- plan.features.team
693
- ) {
598
+ if (app_obj.app_type === 'master' && user_active_app_requests_count_ret.data?.rows?.[0]?.value >= plan.features.team) {
694
599
  return {
695
600
  code: -9,
696
601
  data: `Number of team shares (${user_active_app_requests_count_ret.data.rows[0].value}) exceeds to the ${plan.features.team} plan limits`,
@@ -722,11 +627,7 @@ exports.get_hosting_plan = function (req) {
722
627
  return _conf.PRICE_OBJ.server_slugs[app_obj.app_hosting.app_server_type];
723
628
  }
724
629
  debugger;
725
- console.error(
726
- "error: " +
727
- app_obj.app_hosting.app_server_type +
728
- " not found in PRICE_OBJ.server_slugs"
729
- );
630
+ console.error('error: ' + app_obj.app_hosting.app_server_type + ' not found in PRICE_OBJ.server_slugs');
730
631
  return { cpu: 0, price: 0 };
731
632
  }
732
633
  };
@@ -746,16 +647,7 @@ exports.get_cpu = async function (req) {
746
647
  return cpu;
747
648
  };
748
649
 
749
- const get_account_log_object = function (
750
- body,
751
- status,
752
- service,
753
- source,
754
- response_data,
755
- ip,
756
- headers,
757
- security
758
- ) {
650
+ const get_account_log_object = function (body, status, service, source, response_data, ip, headers, security) {
759
651
  return {
760
652
  uid: body.uid,
761
653
  ip,
@@ -773,15 +665,7 @@ const get_account_log_object = function (
773
665
  };
774
666
  };
775
667
 
776
- exports.add_account_log_util = function (
777
- body,
778
- status,
779
- service,
780
- source,
781
- response_data,
782
- ip,
783
- headers
784
- ) {
668
+ exports.add_account_log_util = function (body, status, service, source, response_data, ip, headers) {
785
669
  // non error log
786
670
  // if (status < 400) {
787
671
  // console.log("error", "add_account_log_util", service);
@@ -790,22 +674,11 @@ exports.add_account_log_util = function (
790
674
  if (_conf.cpi_methods?.[service]?.private) return;
791
675
  const security = _conf.cpi_methods?.[service].security;
792
676
  if (!security) {
793
- if (service.substr(0, 4) === "get_" && !body.api_pk && !body.api_sk) return;
677
+ if (service.substr(0, 4) === 'get_' && !body.api_pk && !body.api_sk) return;
794
678
  }
795
679
  // }
796
680
  const logs_module = require(`${module_path}/logs_module`);
797
- logs_module.add_account_log(
798
- get_account_log_object(
799
- body,
800
- status,
801
- service,
802
- source,
803
- response_data,
804
- ip,
805
- headers,
806
- security
807
- )
808
- );
681
+ logs_module.add_account_log(get_account_log_object(body, status, service, source, response_data, ip, headers, security));
809
682
  };
810
683
 
811
684
  exports.save_ssh_key = async function (req) {
@@ -813,46 +686,45 @@ exports.save_ssh_key = async function (req) {
813
686
 
814
687
  function isValidSSHPublicKey(sshPublicKey) {
815
688
  // Regular expression to match SSH public keys
816
- const sshKeyRegex =
817
- /^ssh-(rsa|ed25519|ecdsa-sha2-nistp[0-9]+) [A-Za-z0-9+/]+[=]{0,3}( [^@]+@[^@]+)?$/;
689
+ const sshKeyRegex = /^ssh-(rsa|ed25519|ecdsa-sha2-nistp[0-9]+) [A-Za-z0-9+/]+[=]{0,3}( [^@]+@[^@]+)?$/;
818
690
 
819
691
  return sshKeyRegex.test(sshPublicKey);
820
692
  }
821
693
 
822
694
  if (!isValidSSHPublicKey(ssh_key_content)) {
823
- return { code: -1, data: "invalid ssh key" };
695
+ return { code: -1, data: 'invalid ssh key' };
824
696
  }
825
697
 
826
698
  var doc = {
827
699
  uid,
828
- docType: "ssh_key",
700
+ docType: 'ssh_key',
829
701
  date_created_ts: Date.now(),
830
702
  date_created: Date.now(),
831
703
  stat: 3,
832
704
  };
833
705
 
834
706
  if (_id) {
835
- const ret = await db_module.get_couch_doc("xuda_ssh_keys", _id);
707
+ const ret = await db_module.get_couch_doc('xuda_ssh_keys', _id);
836
708
  if (ret.code < 0) {
837
709
  return ret;
838
710
  }
839
711
  doc = ret.data;
840
712
  doc.date_updated_ts = Date.now();
841
713
  } else {
842
- doc._id = await _common.xuda_get_uuid("ssh_key");
714
+ doc._id = await _common.xuda_get_uuid('ssh_key');
843
715
  }
844
716
 
845
717
  doc.ssh_key_name = ssh_key_name;
846
718
  doc.ssh_key_content = ssh_key_content;
847
719
 
848
- const save_ret = await db_module.save_couch_doc("xuda_ssh_keys", doc);
720
+ const save_ret = await db_module.save_couch_doc('xuda_ssh_keys', doc);
849
721
 
850
722
  return save_ret;
851
723
  };
852
724
  exports.delete_ssh_key = async function (req) {
853
725
  const { ssh_key_id } = req;
854
726
 
855
- const ret = await db_module.get_couch_doc("xuda_ssh_keys", ssh_key_id);
727
+ const ret = await db_module.get_couch_doc('xuda_ssh_keys', ssh_key_id);
856
728
  if (ret.code < 0) {
857
729
  return ret;
858
730
  }
@@ -860,7 +732,7 @@ exports.delete_ssh_key = async function (req) {
860
732
  doc.date_updated_ts = Date.now();
861
733
  doc.stat = 4;
862
734
 
863
- const save_ret = await db_module.save_couch_doc("xuda_ssh_keys", doc);
735
+ const save_ret = await db_module.save_couch_doc('xuda_ssh_keys', doc);
864
736
 
865
737
  return save_ret;
866
738
  };
@@ -869,14 +741,14 @@ exports.get_ssh_keys = async function (req) {
869
741
  const { uid, _id } = req;
870
742
 
871
743
  let opt = {
872
- selector: { docType: "ssh_key", uid, stat: { $lt: 4 } },
744
+ selector: { docType: 'ssh_key', uid, stat: { $lt: 4 } },
873
745
  };
874
746
 
875
747
  if (_id) {
876
748
  opt._id = _id;
877
749
  }
878
750
 
879
- var ret = await db_module.find_couch_query("xuda_ssh_keys", opt);
751
+ var ret = await db_module.find_couch_query('xuda_ssh_keys', opt);
880
752
  return ret;
881
753
  };
882
754
 
@@ -887,11 +759,11 @@ exports.search_users = async function (req) {
887
759
  // bookmark
888
760
  try {
889
761
  if (!_conf.superuser_account_ids.includes(req.uid)) {
890
- throw new Error("user is not authorized for this method");
762
+ throw new Error('user is not authorized for this method');
891
763
  }
892
764
 
893
765
  let selector = {
894
- docType: "account",
766
+ docType: 'account',
895
767
  stat: 3,
896
768
  };
897
769
 
@@ -900,32 +772,32 @@ exports.search_users = async function (req) {
900
772
  ...selector,
901
773
  $or: [
902
774
  {
903
- "account_info.first_name": {
775
+ 'account_info.first_name': {
904
776
  $regex: `(?i)${req.search}`,
905
777
  },
906
778
  },
907
779
  {
908
- "account_info.last_name": {
780
+ 'account_info.last_name': {
909
781
  $regex: `(?i)${req.search}`,
910
782
  },
911
783
  },
912
784
  {
913
- "account_info.company_name": {
785
+ 'account_info.company_name': {
914
786
  $regex: `(?i)${req.search}`,
915
787
  },
916
788
  },
917
789
  {
918
- "account_info.tel": {
790
+ 'account_info.tel': {
919
791
  $regex: `(?i)${req.search}`,
920
792
  },
921
793
  },
922
794
  {
923
- "account_info.email": {
795
+ 'account_info.email': {
924
796
  $regex: `(?i)${req.search}`,
925
797
  },
926
798
  },
927
799
  {
928
- "account_info.address": {
800
+ 'account_info.address': {
929
801
  $regex: `(?i)${req.search}`,
930
802
  },
931
803
  },
@@ -948,12 +820,12 @@ exports.search_users = async function (req) {
948
820
  opt.skip = req.skip;
949
821
  }
950
822
 
951
- if (req?.bookmark !== "nil") {
823
+ if (req?.bookmark !== 'nil') {
952
824
  opt.bookmark = req.bookmark;
953
825
  }
954
826
 
955
827
  try {
956
- var ret = await db_module.find_couch_query("xuda_accounts", opt);
828
+ var ret = await db_module.find_couch_query('xuda_accounts', opt);
957
829
 
958
830
  return {
959
831
  code: 1,
@@ -971,23 +843,22 @@ exports.search_users = async function (req) {
971
843
  };
972
844
 
973
845
  exports.read_emails = async function (req) {
974
- const { uid, email_account_address, email_account_id, accessToken, vendor } =
975
- req;
846
+ const { uid, email_account_address, email_account_id, accessToken, vendor } = req;
976
847
 
977
848
  const email_module = require(`${module_path}/email_module`);
978
849
 
979
850
  const read_mailbox = async function (mailbox_path, mailbox_name, is_sent) {
980
- var emails_ret = await db_module.find_couch_query("xuda_emails", {
851
+ var emails_ret = await db_module.find_couch_query('xuda_emails', {
981
852
  selector: {
982
- docType: "email",
853
+ docType: 'email',
983
854
  uid,
984
855
  email_account_address,
985
856
  email_account_id,
986
857
  mailbox_path,
987
858
  },
988
- fields: ["message.seq"],
859
+ fields: ['message.seq'],
989
860
  limit: 1,
990
- sort: [{ "message.seq": "desc" }],
861
+ sort: [{ 'message.seq': 'desc' }],
991
862
  });
992
863
 
993
864
  var imap_ret;
@@ -995,7 +866,7 @@ exports.read_emails = async function (req) {
995
866
  const seq = emails_ret?.docs?.[0]?.message?.seq || 1;
996
867
  imap_ret = await email_module.query_imap({
997
868
  email_account_address,
998
- type: "all",
869
+ type: 'all',
999
870
  boxLock: mailbox_path,
1000
871
  seq,
1001
872
  accessToken,
@@ -1009,8 +880,8 @@ exports.read_emails = async function (req) {
1009
880
  delete message.modseq;
1010
881
  if (message.seq > seq) {
1011
882
  docs.push({
1012
- _id: await _common.xuda_get_uuid("email"),
1013
- docType: "email",
883
+ _id: await _common.xuda_get_uuid('email'),
884
+ docType: 'email',
1014
885
  uid,
1015
886
  email_account_address,
1016
887
  email_account_id,
@@ -1019,21 +890,17 @@ exports.read_emails = async function (req) {
1019
890
  mailbox_name,
1020
891
  });
1021
892
  if (is_sent) {
1022
- recipient[message.envelope.to[0].address] =
1023
- message.envelope.to[0].name;
893
+ recipient[message.envelope.to[0].address] = message.envelope.to[0].name;
1024
894
  } else {
1025
- senders[message.envelope.sender[0].address] =
1026
- message.envelope.sender[0].name;
895
+ senders[message.envelope.sender[0].address] = message.envelope.sender[0].name;
1027
896
  }
1028
897
  }
1029
898
  }
1030
899
 
1031
900
  if (docs.length) {
1032
- await db_module.sava_couch_bulk_docs("xuda_emails", docs);
901
+ await db_module.save_couch_bulk_docs('xuda_emails', docs);
1033
902
 
1034
- for await (let [email, name] of Object.entries(
1035
- is_sent ? recipient : senders
1036
- )) {
903
+ for await (let [email, name] of Object.entries(is_sent ? recipient : senders)) {
1037
904
  // const contact_ret = await db_module.get_couch_view_raw(
1038
905
  // "xuda_contacts",
1039
906
  // "contacts_by_email_address",
@@ -1064,29 +931,15 @@ exports.read_emails = async function (req) {
1064
931
 
1065
932
  for await (let mailbox_obj of mailboxes_ret) {
1066
933
  switch (vendor) {
1067
- case "gmail":
1068
- if (
1069
- ![
1070
- "[Gmail]/Starred",
1071
- "[Gmail]/Drafts",
1072
- "[Gmail]/All Mail",
1073
- "[Gmail]/Spam",
1074
- "[Gmail]/Trash",
1075
- "[Gmail]",
1076
- "[Gmail]/Important",
1077
- ].includes(mailbox_obj.path)
1078
- ) {
1079
- await read_mailbox(
1080
- mailbox_obj.path,
1081
- mailbox_obj.name,
1082
- mailbox_obj.path === "[Gmail]/Sent Mail"
1083
- );
934
+ case 'gmail':
935
+ if (!['[Gmail]/Starred', '[Gmail]/Drafts', '[Gmail]/All Mail', '[Gmail]/Spam', '[Gmail]/Trash', '[Gmail]', '[Gmail]/Important'].includes(mailbox_obj.path)) {
936
+ await read_mailbox(mailbox_obj.path, mailbox_obj.name, mailbox_obj.path === '[Gmail]/Sent Mail');
1084
937
  }
1085
938
 
1086
939
  break;
1087
940
 
1088
941
  default:
1089
- if (["INBOX", "Sent Mail"].includes(mailbox_obj.path)) {
942
+ if (['INBOX', 'Sent Mail'].includes(mailbox_obj.path)) {
1090
943
  await read_mailbox(mailbox_obj.path, mailbox_obj.name);
1091
944
  }
1092
945
  break;
@@ -1098,9 +951,9 @@ exports.get_email_accounts = async function (req) {
1098
951
  const { uid, stat } = req;
1099
952
 
1100
953
  const db_module = require(`${module_path}/db_module`);
1101
- var email_account_ret = await db_module.find_couch_query("xuda_emails", {
954
+ var email_account_ret = await db_module.find_couch_query('xuda_emails', {
1102
955
  selector: {
1103
- docType: "email_account",
956
+ docType: 'email_account',
1104
957
  uid,
1105
958
  stat: stat || 3,
1106
959
  },
@@ -1110,14 +963,14 @@ exports.get_email_accounts = async function (req) {
1110
963
 
1111
964
  const generate_gmail_access_token = async function (email_account) {
1112
965
  return new Promise((resolve, reject) => {
1113
- fetch("https://oauth2.googleapis.com/token", {
1114
- method: "POST",
1115
- headers: { "Content-Type": "application/json" },
966
+ fetch('https://oauth2.googleapis.com/token', {
967
+ method: 'POST',
968
+ headers: { 'Content-Type': 'application/json' },
1116
969
  body: JSON.stringify({
1117
970
  refresh_token: email_account.authorization_data.refresh_token,
1118
971
  client_id: _conf.gmail.clientId,
1119
972
  client_secret: _conf.gmail.clientSecret,
1120
- grant_type: "refresh_token",
973
+ grant_type: 'refresh_token',
1121
974
  }),
1122
975
  })
1123
976
  .then((response) => response.json())
@@ -1131,17 +984,17 @@ exports.find_contact_duplicates = async function (req) {
1131
984
  const { uid, name } = req;
1132
985
  var opt = {
1133
986
  selector: {
1134
- docType: "contact",
987
+ docType: 'contact',
1135
988
  stat: { $lt: 4 },
1136
989
  uid,
1137
990
  },
1138
991
  limit: 999999,
1139
992
  };
1140
993
 
1141
- if (typeof name !== "undefined") {
994
+ if (typeof name !== 'undefined') {
1142
995
  opt.selector.name = name;
1143
996
  }
1144
- const contact_ret = await db_module.find_couch_query("xuda_contacts", opt);
997
+ const contact_ret = await db_module.find_couch_query('xuda_contacts', opt);
1145
998
  var duplicates = {};
1146
999
  for (contact of contact_ret.docs) {
1147
1000
  if (!duplicates[contact.name]) {
@@ -1175,7 +1028,7 @@ exports.merge_contact = async function (req) {
1175
1028
 
1176
1029
  var duplicate_arr = duplicate_ret?.data?.[name] || [];
1177
1030
  if (!duplicate_arr.length) {
1178
- return { code: 1, data: "no merge performed" };
1031
+ return { code: 1, data: 'no merge performed' };
1179
1032
  }
1180
1033
  var contact_to_merge;
1181
1034
  var contact_to_delete = [];
@@ -1192,12 +1045,7 @@ exports.merge_contact = async function (req) {
1192
1045
  for (let [i, contact_id] of Object.entries(contact_to_delete)) {
1193
1046
  var contact_obj = duplicate_arr.find((e) => e._id === contact_id);
1194
1047
 
1195
- if (
1196
- contact_obj.name &&
1197
- !["spam", "newsletter", "noreply", "no-reply"].includes(
1198
- contact_obj.email?.[0]?.toLowerCase()
1199
- )
1200
- ) {
1048
+ if (contact_obj.name && !['spam', 'newsletter', 'noreply', 'no-reply'].includes(contact_obj.email?.[0]?.toLowerCase())) {
1201
1049
  contact_to_merge = contact_id;
1202
1050
  contact_to_delete = contact_to_delete.splice(i, 1);
1203
1051
  break;
@@ -1211,35 +1059,25 @@ exports.merge_contact = async function (req) {
1211
1059
  }
1212
1060
 
1213
1061
  // get the primary account
1214
- const primary_contact_ret = await db_module.get_couch_doc(
1215
- "xuda_contacts",
1216
- contact_to_merge
1217
- );
1062
+ const primary_contact_ret = await db_module.get_couch_doc('xuda_contacts', contact_to_merge);
1218
1063
  if (primary_contact_ret.code < 0) {
1219
1064
  return primary_contact_ret;
1220
1065
  }
1221
1066
  var primary_contact_doc = primary_contact_ret.data;
1222
1067
 
1223
1068
  primary_contact_doc.stat_ts = Date.now();
1224
- primary_contact_doc.stat_reason = "merge";
1069
+ primary_contact_doc.stat_reason = 'merge';
1225
1070
 
1226
1071
  for (let contact_id of contact_to_delete) {
1227
- var email_address = duplicate_arr.find((e) => e._id === contact_id)
1228
- .email[0];
1072
+ var email_address = duplicate_arr.find((e) => e._id === contact_id).email[0];
1229
1073
 
1230
1074
  primary_contact_doc.email.push(email_address);
1231
1075
  }
1232
1076
 
1233
- const primary_contact_save_ret = await db_module.save_couch_doc(
1234
- "xuda_contacts",
1235
- primary_contact_doc
1236
- );
1077
+ const primary_contact_save_ret = await db_module.save_couch_doc('xuda_contacts', primary_contact_doc);
1237
1078
 
1238
1079
  for (let contact_id of contact_to_delete) {
1239
- const contact_ret = await db_module.get_couch_doc(
1240
- "xuda_contacts",
1241
- contact_id
1242
- );
1080
+ const contact_ret = await db_module.get_couch_doc('xuda_contacts', contact_id);
1243
1081
  if (contact_ret.code < 0) {
1244
1082
  continue;
1245
1083
  }
@@ -1247,8 +1085,8 @@ exports.merge_contact = async function (req) {
1247
1085
  var contact_doc = contact_ret.data;
1248
1086
  contact_doc.stat = 4;
1249
1087
  contact_doc.stat_ts = Date.now();
1250
- contact_doc.stat_reason = "merge";
1251
- await db_module.save_couch_doc("xuda_contacts", contact_doc);
1088
+ contact_doc.stat_reason = 'merge';
1089
+ await db_module.save_couch_doc('xuda_contacts', contact_doc);
1252
1090
  }
1253
1091
 
1254
1092
  return primary_contact_save_ret; //{ code: 1, data: duplicate_arr };
@@ -1258,14 +1096,14 @@ exports.get_contacts = async function (req) {
1258
1096
  const { uid, name, limit, skip, bookmark } = req;
1259
1097
  var opt = {
1260
1098
  selector: {
1261
- docType: "contact",
1099
+ docType: 'contact',
1262
1100
  uid,
1263
1101
  stat: { $lt: 4 },
1264
1102
  },
1265
1103
  limit: limit ? limit : 99999,
1266
1104
  };
1267
1105
 
1268
- if (typeof name !== "undefined") {
1106
+ if (typeof name !== 'undefined') {
1269
1107
  opt.selector.name = { $regex: `(?i)${name}` };
1270
1108
  }
1271
1109
 
@@ -1273,10 +1111,10 @@ exports.get_contacts = async function (req) {
1273
1111
  opt.skip = skip;
1274
1112
  }
1275
1113
 
1276
- if (bookmark !== "nil") {
1114
+ if (bookmark !== 'nil') {
1277
1115
  opt.bookmark = bookmark;
1278
1116
  }
1279
- const contacts_ret = await db_module.find_couch_query("xuda_contacts", opt);
1117
+ const contacts_ret = await db_module.find_couch_query('xuda_contacts', opt);
1280
1118
 
1281
1119
  return contacts_ret;
1282
1120
  };
@@ -1284,19 +1122,16 @@ exports.get_contacts = async function (req) {
1284
1122
  exports.delete_contact = async function (req) {
1285
1123
  const { _id } = req;
1286
1124
 
1287
- const contact_ret = await db_module.get_couch_doc("xuda_contacts", _id);
1125
+ const contact_ret = await db_module.get_couch_doc('xuda_contacts', _id);
1288
1126
  if (contact_ret.code < 0) {
1289
1127
  return contact_ret;
1290
1128
  }
1291
1129
  var contact_doc = contact_ret.data;
1292
1130
 
1293
1131
  contact_doc.stat_ts = Date.now();
1294
- contact_doc.stat_reason = "deleted";
1132
+ contact_doc.stat_reason = 'deleted';
1295
1133
 
1296
- const contact_save_ret = await db_module.save_couch_doc(
1297
- "xuda_contacts",
1298
- contact_doc
1299
- );
1134
+ const contact_save_ret = await db_module.save_couch_doc('xuda_contacts', contact_doc);
1300
1135
 
1301
1136
  return contact_save_ret;
1302
1137
  };
@@ -1315,43 +1150,31 @@ exports.delete_contact = async function (req) {
1315
1150
 
1316
1151
  exports.add_contact = async function (req) {
1317
1152
  const { uid, email, name, stat, contact_uid, req_id } = req;
1318
- const contact_ret = await db_module.get_couch_view_raw(
1319
- "xuda_contacts",
1320
- "contacts_by_email_address",
1321
- { key: [uid, email] }
1322
- );
1153
+ const contact_ret = await db_module.get_couch_view_raw('xuda_contacts', 'contacts_by_email_address', { key: [uid, email] });
1323
1154
 
1324
1155
  if (!contact_ret.rows.length) {
1325
- const ret = await db_module.save_couch_doc("xuda_contacts", {
1326
- _id: await _common.xuda_get_uuid("contact"),
1156
+ const ret = await db_module.save_couch_doc('xuda_contacts', {
1157
+ _id: await _common.xuda_get_uuid('contact'),
1327
1158
  email: [email],
1328
1159
  name,
1329
1160
  stat: stat || 1,
1330
1161
  date_created: Date.now(),
1331
- docType: "contact",
1162
+ docType: 'contact',
1332
1163
  contact_uid,
1333
1164
  uid,
1334
1165
  req_id,
1335
1166
  });
1336
1167
  return ret;
1337
1168
  }
1338
- return { code: -1, data: "contact already exist active or deleted" };
1169
+ return { code: -1, data: 'contact already exist active or deleted' };
1339
1170
  };
1340
1171
  exports.update_contact = async function (req) {
1341
1172
  const { uid, email, contact_uid, stat, req_id } = req;
1342
1173
  var contact_ret;
1343
1174
  if (email) {
1344
- contact_ret = await db_module.get_couch_view_raw(
1345
- "xuda_contacts",
1346
- "contacts_by_email_address",
1347
- { key: [uid, email] }
1348
- );
1175
+ contact_ret = await db_module.get_couch_view_raw('xuda_contacts', 'contacts_by_email_address', { key: [uid, email] });
1349
1176
  } else if (contact_uid) {
1350
- contact_ret = await db_module.get_couch_view_raw(
1351
- "xuda_contacts",
1352
- "contacts_by_contact_uid",
1353
- { key: [uid, contact_uid] }
1354
- );
1177
+ contact_ret = await db_module.get_couch_view_raw('xuda_contacts', 'contacts_by_contact_uid', { key: [uid, contact_uid] });
1355
1178
  }
1356
1179
  if (contact_ret.rows.length) {
1357
1180
  var doc = contact_ret.rows[0].value;
@@ -1362,9 +1185,9 @@ exports.update_contact = async function (req) {
1362
1185
  if (req_id) {
1363
1186
  doc.req_id = req_id;
1364
1187
  }
1365
- return await db_module.save_couch_doc("xuda_contacts", doc);
1188
+ return await db_module.save_couch_doc('xuda_contacts', doc);
1366
1189
  }
1367
- return { code: -1, data: "contact not found" };
1190
+ return { code: -1, data: 'contact not found' };
1368
1191
  };
1369
1192
  exports.invite_user = async function (req) {
1370
1193
  const { email, name, uid } = req;
@@ -1372,7 +1195,7 @@ exports.invite_user = async function (req) {
1372
1195
  const team_module = require(`${module_path}/team_module`);
1373
1196
  const ret = await team_module.create_team_request({
1374
1197
  email,
1375
- access_type: "contact",
1198
+ access_type: 'contact',
1376
1199
  uid,
1377
1200
  });
1378
1201
 
@@ -1380,9 +1203,9 @@ exports.invite_user = async function (req) {
1380
1203
  };
1381
1204
 
1382
1205
  exports.get_account_rt_info = async function (uid) {
1383
- const doc_ret = await db_module.get_couch_doc("xuda_accounts", uid);
1206
+ const doc_ret = await db_module.get_couch_doc('xuda_accounts', uid);
1384
1207
  if (doc_ret.code < 0) {
1385
- console.error("get_account_rt_info", doc_ret);
1208
+ console.error('get_account_rt_info', doc_ret);
1386
1209
  return {};
1387
1210
  }
1388
1211
  var account_info = doc_ret.data.account_info;
@@ -1451,7 +1274,7 @@ exports.validate_account_topup = async function (uid, items = []) {
1451
1274
  err.code = -90;
1452
1275
  err.billing_problem = true;
1453
1276
 
1454
- throw new Error("no card on file");
1277
+ throw new Error('no card on file');
1455
1278
  }
1456
1279
 
1457
1280
  if (data?.balance?.past_due) {
@@ -1495,49 +1318,49 @@ const get_prices = function (uid, item) {
1495
1318
  let price;
1496
1319
 
1497
1320
  switch (item) {
1498
- case "user_group":
1499
- case "pwa":
1500
- case "preview":
1501
- case "android":
1502
- case "ios":
1503
- case "macos":
1504
- case "emitter":
1321
+ case 'user_group':
1322
+ case 'pwa':
1323
+ case 'preview':
1324
+ case 'android':
1325
+ case 'ios':
1326
+ case 'macos':
1327
+ case 'emitter':
1505
1328
  price = _conf.PRICE_OBJ.deployments[item];
1506
1329
  break;
1507
1330
 
1508
- case "drive_ocr":
1331
+ case 'drive_ocr':
1509
1332
  price = _conf.PRICE_OBJ.drive_addons.ocr.price;
1510
1333
  break;
1511
1334
 
1512
- case "drive_edit_image":
1335
+ case 'drive_edit_image':
1513
1336
  price = _conf.PRICE_OBJ.drive_addons.edit_image.price;
1514
1337
  break;
1515
1338
 
1516
- case "auto_backup":
1339
+ case 'auto_backup':
1517
1340
  price = _conf.PRICE_OBJ.auto_backup_per_month;
1518
1341
  break;
1519
1342
 
1520
- case "deployment_offline":
1343
+ case 'deployment_offline':
1521
1344
  price = _conf.PRICE_OBJ.deployment_offline_per_month;
1522
1345
  break;
1523
1346
 
1524
- case "xuda_subdomain":
1347
+ case 'xuda_subdomain':
1525
1348
  price = _conf.PRICE_OBJ.xuda_subdomain_per_month;
1526
1349
  break;
1527
1350
 
1528
- case "custom_domain":
1351
+ case 'custom_domain':
1529
1352
  price = _conf.PRICE_OBJ.custom_domain_per_month;
1530
1353
  break;
1531
1354
 
1532
- case "user_monitor":
1355
+ case 'user_monitor':
1533
1356
  price = _conf.PRICE_OBJ.user_monitor_per_month;
1534
1357
  break;
1535
1358
 
1536
- case "branding":
1359
+ case 'branding':
1537
1360
  price = _conf.PRICE_OBJ.branding_per_month;
1538
1361
  break;
1539
1362
 
1540
- case "utility_screen":
1363
+ case 'utility_screen':
1541
1364
  price = _conf.PRICE_OBJ.utility_screen_per_month;
1542
1365
  break;
1543
1366
 
@@ -1567,7 +1390,7 @@ const get_prices = function (uid, item) {
1567
1390
  // // val._deleted = true;
1568
1391
  // // contact_docs.push(val);
1569
1392
  // // }
1570
- // // await db_module.sava_couch_bulk_docs("xuda_contacts", contact_docs);
1393
+ // // await db_module.save_couch_bulk_docs("xuda_contacts", contact_docs);
1571
1394
 
1572
1395
  // // const emails_ret = await db_module.find_couch_query("xuda_emails", {
1573
1396
  // // selector: {
@@ -1581,7 +1404,7 @@ const get_prices = function (uid, item) {
1581
1404
  // // email_docs.push(val);
1582
1405
  // // }
1583
1406
 
1584
- // // await db_module.sava_couch_bulk_docs("xuda_emails", email_docs);
1407
+ // // await db_module.save_couch_bulk_docs("xuda_emails", email_docs);
1585
1408
 
1586
1409
  // ///////////////////////////////////
1587
1410
  // return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/account_module",
3
- "version": "1.2.100",
3
+ "version": "1.2.101",
4
4
  "description": "Xuda Account Server Module",
5
5
  "main": "index.js",
6
6
  "dependencies": {