@dhyasama/totem-models 12.3.0 → 12.5.0

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.
package/helpers.js CHANGED
@@ -134,16 +134,3 @@ const getPeopleSources = module.exports.getPeopleSources = function getPeopleSou
134
134
 
135
135
  };
136
136
 
137
- const sortPeopleSources = module.exports.sortPeopleSources = function sortPeopleSources(items, customerId) {
138
-
139
- items = _.sortBy(items, function(item) {
140
- return item.interactionsCount(customerId);
141
- });
142
-
143
- items.reverse();
144
-
145
- items = _.sortBy(items, 'name.full');
146
-
147
- return items;
148
-
149
- };
package/lib/Account.js CHANGED
@@ -21,7 +21,7 @@ module.exports = function(mongoose, config) {
21
21
  permissions: { type: Array, default: [] },
22
22
 
23
23
  funds: [ { type: Schema.ObjectId, ref: 'Fund' } ],
24
-
24
+
25
25
  totemLive: {
26
26
  excelUser: { type: Boolean, default: true },
27
27
  sheetsUser: { type: Boolean, default: true },
@@ -95,97 +95,87 @@ module.exports = function(mongoose, config) {
95
95
 
96
96
  Account.statics.findByEmail = function(email, options, cb) {
97
97
 
98
- let self = this;
99
-
100
- if (!cb) { throw new Error('cb is required'); }
101
- if (!email) { return cb(new Error('email is required'), null); }
98
+ const run = async () => {
99
+ if (!email) { throw new Error('email is required'); }
102
100
 
103
- options = helpers.getDefaultOptions(options);
101
+ options = helpers.getDefaultOptions(options);
104
102
 
105
- let query = { email: email.toLowerCase() };
103
+ let query = { email: email.toLowerCase() };
106
104
 
107
- if (options.current !== undefined || options.customerId !== undefined) {
105
+ if (options.current !== undefined || options.customerId !== undefined) {
108
106
 
109
- if (options.current !== undefined) { query.current = options.current; }
110
- if (options.customerId !== undefined) { query.org = options.customerId; }
111
-
112
- self
113
- .findOne(query)
114
- .populate('person')
115
- .exec().then(function(account) {
116
- if (!account) { return cb(null, null); }
107
+ if (options.current !== undefined) { query.current = options.current; }
108
+ if (options.customerId !== undefined) { query.org = options.customerId; }
117
109
 
118
- if (account.populated('person')) {
110
+ const account = await this.findOne(query).populate('person').lean({ virtuals: true });
111
+ if (!account) { return null; }
119
112
 
120
- if (account.org) { helpers.cleanPerson(account.person, account.org); }
121
- else { account.person.sources = []; }
113
+ if (account.populated('person')) {
122
114
 
123
- }
115
+ if (account.org) { helpers.cleanPerson(account.person, account.org); }
116
+ else { account.person.sources = []; }
124
117
 
125
- return cb(null, account);
118
+ }
126
119
 
127
- }).catch(function(err) { cb(err); });
120
+ return account;
128
121
 
129
- }
122
+ }
130
123
 
131
- else {
124
+ else {
132
125
 
133
- self
134
- .find(query)
135
- .populate({
126
+ const result = await this.find(query).populate({
136
127
  path: 'org',
137
128
  select: 'name'
138
- })
139
- .exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
129
+ }).lean({ virtuals: true });
130
+ return result;
140
131
 
141
- }
132
+ }
133
+ };
134
+
135
+ if (typeof cb === 'function') { run().then(result => cb(null, result)).catch(cb); return; }
136
+ else { return run(); }
142
137
 
143
138
  };
144
139
 
145
140
  Account.statics.findByEmails = function(emails, cb) {
146
141
 
147
- let self = this;
148
-
149
- if (!cb) { throw new Error('cb is required'); }
150
- if (!emails) { return cb(new Error('email is required'), null); }
142
+ const run = async () => {
143
+ if (!emails) { throw new Error('email is required'); }
151
144
 
152
- self
153
- .find({ 'email': { $in : emails }})
154
- .populate('person')
155
- .exec().then(function(accounts) {
156
- if (!accounts) { return cb(null, null); }
145
+ const accounts = await this.find({ 'email': { $in : emails }}).populate('person').lean({ virtuals: true });
146
+ if (!accounts) { return null; }
157
147
 
158
- _.each(accounts, function(account) {
148
+ _.each(accounts, function(account) {
159
149
 
160
- if (account.populated('person')) {
150
+ if (account.populated('person')) {
161
151
 
162
- if (account.org) { helpers.cleanPerson(account.person, account.org); }
163
- else { account.person.sources = []; }
152
+ if (account.org) { helpers.cleanPerson(account.person, account.org); }
153
+ else { account.person.sources = []; }
164
154
 
165
- }
155
+ }
166
156
 
167
- });
157
+ });
168
158
 
169
- return cb(null, accounts);
159
+ return accounts;
160
+ };
170
161
 
171
- }).catch(function(err) { cb(err); });
162
+ if (typeof cb === 'function') { run().then(result => cb(null, result)).catch(cb); return; }
163
+ else { return run(); }
172
164
 
173
165
  };
174
166
 
175
167
  Account.statics.getById = function (id, cb) {
176
168
 
177
- const self = this;
178
-
179
- if (!cb) { throw new Error('cb is required'); }
180
- if (!id) { throw new Error('id is required'); }
181
- if (!mongoose.Types.ObjectId.isValid(id)) { return cb(new Error('id is not a valid ObjectId'), null); }
169
+ const run = async () => {
170
+ if (!id) { throw new Error('id is required'); }
171
+ if (!mongoose.Types.ObjectId.isValid(id)) { throw new Error('id is not a valid ObjectId'); }
182
172
 
183
- let query = self.findById(id);
173
+ let query = this.findById(id);
184
174
 
185
- query.populate('person');
186
- query.populate('org');
175
+ query.populate('person');
176
+ query.populate('org');
187
177
 
188
- query.exec().then(function(account) {
178
+ const account = await query.lean({ virtuals: true });
189
179
  if (account && account.populated('person') && account.populated('org')) {
190
180
 
191
181
  // Scrub customer info before returning
@@ -196,23 +186,25 @@ module.exports = function(mongoose, config) {
196
186
 
197
187
  if (account.populated('person')) { helpers.cleanPerson(account.person, customerId); }
198
188
 
199
- return cb(null, account);
189
+ return account;
200
190
 
201
191
  }
202
192
  else if (!account) {
203
- return cb(new Error('No account with id ' + id.toString()), null);
193
+ throw new Error('No account with id ' + id.toString());
204
194
  }
205
195
  else if (account && !account.person) {
206
- return cb(new Error('Missing person reference on account with id ' + id.toString()), null);
196
+ throw new Error('Missing person reference on account with id ' + id.toString());
207
197
  }
208
198
  else if (account && !account.org) {
209
- return cb(new Error('Missing org reference on account with id ' + id.toString()), null);
199
+ throw new Error('Missing org reference on account with id ' + id.toString());
210
200
  }
211
201
  else {
212
- return cb(new Error('Unknown error'), null);
202
+ throw new Error('Unknown error');
213
203
  }
204
+ };
214
205
 
215
- }).catch(function(err) { cb(err); });
206
+ if (typeof cb === 'function') { run().then(result => cb(null, result)).catch(cb); return; }
207
+ else { return run(); }
216
208
 
217
209
  };
218
210
 
@@ -220,75 +212,79 @@ module.exports = function(mongoose, config) {
220
212
 
221
213
  // No population so no need to scrub
222
214
 
223
- const self = this;
215
+ const run = async () => {
216
+ if (!customerId) { throw new Error('customerId is required'); }
217
+ if (!mongoose.Types.ObjectId.isValid(customerId)) { throw new Error('customerId is not a valid ObjectId'); }
224
218
 
225
- if (!cb) { throw new Error('cb is required'); }
226
- if (!customerId) { return cb(new Error('customerId is required'), null); }
227
- if (!mongoose.Types.ObjectId.isValid(customerId)) { return cb(new Error('customerId is not a valid ObjectId'), null); }
219
+ const result = await this.find({ 'org': customerId }).lean({ virtuals: true });
220
+ return result;
221
+ };
228
222
 
229
- self
230
- .find({ 'org': customerId })
231
- .exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
223
+ if (typeof cb === 'function') { run().then(result => cb(null, result)).catch(cb); return; }
224
+ else { return run(); }
232
225
 
233
226
  };
234
227
 
235
228
  Account.statics.updateCurrent = function(email, customerId, cb) {
236
229
 
237
- if (!cb) { throw new Error('cb is required'); }
238
- if (!email) { return cb(new Error('email is required'), null); }
239
- if (!customerId) { return cb(new Error('customerId is required'), null); }
240
- if (!mongoose.Types.ObjectId.isValid(customerId)) { return cb(new Error('customerId is not a valid ObjectId'), null); }
241
-
242
- const self = this;
230
+ const run = async () => {
231
+ if (!email) { throw new Error('email is required'); }
232
+ if (!customerId) { throw new Error('customerId is required'); }
233
+ if (!mongoose.Types.ObjectId.isValid(customerId)) { throw new Error('customerId is not a valid ObjectId'); }
243
234
 
244
- self.updateMany({ email: email }, { $set: { current: false } }).then(function(res) {self.updateOne({ email: email, org: customerId }, { $set: { current: true } }).then(function(res) {cb(null, res);
245
-
246
- }).catch(function(err) { cb(err); });
235
+ await this.updateMany({ email: email }, { $set: { current: false } });
236
+ const res = await this.updateOne({ email: email, org: customerId }, { $set: { current: true } });
237
+ return res;
238
+ };
247
239
 
248
- }).catch(function(err) { cb(err); });
240
+ if (typeof cb === 'function') { run().then(result => cb(null, result)).catch(cb); return; }
241
+ else { return run(); }
249
242
 
250
243
  };
251
244
 
252
245
  Account.statics.updateOrg = function(email, customerId, cb) {
253
246
 
254
- if (!cb) { throw new Error('cb is required'); }
255
- if (!email) { return cb(new Error('email is required'), null); }
256
- if (!customerId) { return cb(new Error('customerId is required'), null); }
257
- if (!mongoose.Types.ObjectId.isValid(customerId)) { return cb(new Error('customerId is not a valid ObjectId'), null); }
247
+ const run = async () => {
248
+ if (!email) { throw new Error('email is required'); }
249
+ if (!customerId) { throw new Error('customerId is required'); }
250
+ if (!mongoose.Types.ObjectId.isValid(customerId)) { throw new Error('customerId is not a valid ObjectId'); }
258
251
 
259
- const self = this;
260
-
261
- self.updateOne({ email: email }, { $set: { org: customerId } }).then(function(res) {cb(null, res);
262
-
263
- }).catch(function(err) { cb(err); });
252
+ const res = await this.updateOne({ email: email }, { $set: { org: customerId } });
253
+ return res;
254
+ };
255
+
256
+ if (typeof cb === 'function') { run().then(result => cb(null, result)).catch(cb); return; }
257
+ else { return run(); }
264
258
 
265
259
  };
266
260
 
267
261
  Account.statics.listAdminAccounts = function (options, cb) {
268
262
 
269
- const self = this;
270
-
271
- if (!cb) { throw new Error('cb is required'); }
263
+ const run = async () => {
264
+ const result = await this.find({ 'active': true, 'role': 'admin' }).lean({ virtuals: true });
265
+ return result;
266
+ };
272
267
 
273
- self
274
- .find({ 'active': true, 'role': 'admin' })
275
- .exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
268
+ if (typeof cb === 'function') { run().then(result => cb(null, result)).catch(cb); return; }
269
+ else { return run(); }
276
270
 
277
271
  };
278
272
 
279
273
  Account.statics.listSummaryAccounts = function (options, cb) {
280
274
 
281
- const self = this;
275
+ const run = async () => {
276
+ let queryObj = { 'active': true, 'summary.active': true };
282
277
 
283
- if (!cb) { throw new Error('cb is required'); }
278
+ if (options.CUSTOMER_ID) {
279
+ queryObj['org'] = options.CUSTOMER_ID;
280
+ }
284
281
 
285
- let queryObj = { 'active': true, 'summary.active': true };
282
+ const result = await this.find(queryObj).lean({ virtuals: true });
283
+ return result;
284
+ };
286
285
 
287
- if (options.CUSTOMER_ID) {
288
- queryObj['org'] = options.CUSTOMER_ID;
289
- }
290
-
291
- self.find(queryObj).exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
286
+ if (typeof cb === 'function') { run().then(result => cb(null, result)).catch(cb); return; }
287
+ else { return run(); }
292
288
 
293
289
  };
294
290
 
@@ -297,36 +293,33 @@ module.exports = function(mongoose, config) {
297
293
  // This is only for worker
298
294
  // Since it's only worker, no need to scrub results
299
295
 
300
- const self = this;
296
+ const run = async () => {
297
+ options = helpers.getDefaultOptions(options);
301
298
 
302
- if (!cb) { throw new Error('cb is required'); }
299
+ if (!options.isWorkerProcess) { return []; }
303
300
 
304
- options = helpers.getDefaultOptions(options);
301
+ const result = await this.find({'active': true}).populate('person').sort({'person.name.last': 1}).lean({ virtuals: true });
302
+ return result;
303
+ };
305
304
 
306
- if (!options.isWorkerProcess) { return cb(null, []); }
307
-
308
- self
309
- .find({'active': true})
310
- .populate('person')
311
- .sort({'person.name.last': 1})
312
- .exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
305
+ if (typeof cb === 'function') { run().then(result => cb(null, result)).catch(cb); return; }
306
+ else { return run(); }
313
307
 
314
308
  };
315
309
 
316
310
  Account.statics.listAllAccountsSkinny = function (options, cb) {
317
311
 
318
- const self = this;
319
-
320
- if (!cb) { throw new Error('cb is required'); }
312
+ const run = async () => {
313
+ options = helpers.getDefaultOptions(options);
321
314
 
322
- options = helpers.getDefaultOptions(options);
315
+ if (!options.isWorkerProcess) { return []; }
323
316
 
324
- if (!options.isWorkerProcess) { return cb(null, []); }
317
+ const result = await this.find({'active': true}).select('active email auth').lean({ virtuals: true });
318
+ return result;
319
+ };
325
320
 
326
- self
327
- .find({'active': true})
328
- .select('active email auth')
329
- .exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
321
+ if (typeof cb === 'function') { run().then(result => cb(null, result)).catch(cb); return; }
322
+ else { return run(); }
330
323
 
331
324
  };
332
325
 
@@ -335,22 +328,22 @@ module.exports = function(mongoose, config) {
335
328
  // This is only for worker
336
329
  // Since it's only worker, no need to scrub results
337
330
 
338
- const self = this;
339
-
340
- if (!cb) { throw new Error('cb is required'); }
341
-
342
- options = helpers.getDefaultOptions(options);
331
+ const run = async () => {
332
+ options = helpers.getDefaultOptions(options);
343
333
 
344
- if (!options.isWorkerProcess) { return cb(null, []); }
334
+ if (!options.isWorkerProcess) { return []; }
345
335
 
346
- self
347
- .find({
336
+ const result = await this.find({
348
337
  'active': true,
349
338
  'calendar.active': true,
350
339
  'auth.strategy': 'google',
351
340
  'auth.google.refreshToken': { $ne: null }
352
- })
353
- .exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
341
+ }).lean({ virtuals: true });
342
+ return result;
343
+ };
344
+
345
+ if (typeof cb === 'function') { run().then(result => cb(null, result)).catch(cb); return; }
346
+ else { return run(); }
354
347
 
355
348
  };
356
349
 
@@ -359,34 +352,37 @@ module.exports = function(mongoose, config) {
359
352
  // This is only for worker
360
353
  // Since it's only worker, no need to scrub results
361
354
 
362
- const self = this;
363
-
364
- if (!cb) { throw new Error('cb is required'); }
355
+ const run = async () => {
356
+ options = helpers.getDefaultOptions(options);
365
357
 
366
- options = helpers.getDefaultOptions(options);
358
+ if (!options.isWorkerProcess) { return []; }
367
359
 
368
- if (!options.isWorkerProcess) { return cb(null, []); }
369
-
370
- self
371
- .find({
360
+ const result = await this.find({
372
361
  'active': true,
373
362
  'calendar.active': true,
374
363
  'auth.strategy': 'microsoft',
375
364
  'auth.microsoft.refreshToken': { $ne: null }
376
- })
377
- .exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
365
+ }).lean({ virtuals: true });
366
+ return result;
367
+ };
368
+
369
+ if (typeof cb === 'function') { run().then(result => cb(null, result)).catch(cb); return; }
370
+ else { return run(); }
378
371
 
379
372
  };
380
373
 
381
374
  Account.statics.delete = function (id, options, cb) {
382
375
 
383
- const self = this;
376
+ const run = async () => {
377
+ if (!id) { throw new Error('id is required'); }
378
+ if (!mongoose.Types.ObjectId.isValid(id)) { throw new Error('id is not a valid ObjectId'); }
384
379
 
385
- if (!cb) { throw new Error('cb is required'); }
386
- if (!id) { return cb(new Error('id is required'), null); }
387
- if (!mongoose.Types.ObjectId.isValid(id)) { return cb(new Error('id is not a valid ObjectId'), null); }
380
+ const result = await this.findByIdAndDelete(id);
381
+ return result;
382
+ };
388
383
 
389
- self.findByIdAndDelete(id).then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
384
+ if (typeof cb === 'function') { run().then(result => cb(null, result)).catch(cb); return; }
385
+ else { return run(); }
390
386
 
391
387
  };
392
388
 
@@ -394,7 +390,13 @@ module.exports = function(mongoose, config) {
394
390
 
395
391
  // No population so no need to scrub
396
392
 
397
- account.save().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
393
+ const run = async () => {
394
+ const result = await account.save();
395
+ return result;
396
+ };
397
+
398
+ if (typeof cb === 'function') { run().then(result => cb(null, result)).catch(cb); return; }
399
+ else { return run(); }
398
400
 
399
401
  };
400
402
  Account.set('autoIndex', false);
package/lib/Activity.js CHANGED
@@ -42,15 +42,14 @@ module.exports = function(mongoose, config) {
42
42
 
43
43
  Activity.statics.add = function(username, type, remoteAddress, url, filename, callback) {
44
44
 
45
- const self = this;
45
+ const run = async () => {
46
+ if (!username) throw new Error('username is required');
47
+ if (!type) throw new Error('type is required');
46
48
 
47
- if (!username) throw new Error('username is required');
48
- if (!type) throw new Error('type is required');
49
- if (!callback) throw new Error('callback is required');
49
+ username = username.toLowerCase();
50
50
 
51
- username = username.toLowerCase();
52
-
53
- self.findOne({ 'username': username }).then(function(activity) {if (!activity) {
51
+ let activity = await this.findOne({ 'username': username });
52
+ if (!activity) {
54
53
  const A = mongoose.model('Activity');
55
54
  activity = new A();
56
55
  activity.username = username;
@@ -71,29 +70,44 @@ module.exports = function(mongoose, config) {
71
70
 
72
71
  if (activity) {
73
72
  activity.items.unshift(item);
74
- activity.save().then(function(result) {
75
- return callback(null, item);
76
- }).catch(function(err) { callback(err); });
73
+ await activity.save();
74
+ return item;
77
75
  }
78
76
  else {
79
- return callback(null, null);
77
+ return null;
80
78
  }
79
+ };
81
80
 
82
- }).catch(function(err) { callback(err); });
81
+ if (typeof callback === 'function') { run().then(result => callback(null, result)).catch(callback); }
82
+ else { return run(); }
83
83
 
84
84
  };
85
85
 
86
86
  Activity.statics.forMessage = function(username, messageId, cb) {
87
- this.find({ 'username': username.toLowerCase(), 'items.document.messageId': messageId }).then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
87
+
88
+ const run = async () => {
89
+ const result = await this.find({ 'username': username.toLowerCase(), 'items.document.messageId': messageId }).lean({ virtuals: true });
90
+ return result;
91
+ };
92
+
93
+ if (typeof cb === 'function') { run().then(result => cb(null, result)).catch(cb); return; }
94
+ else { return run(); }
95
+
88
96
  };
89
97
 
90
98
  Activity.statics.list = function(username, maxItems, cb) {
91
99
 
92
- var query = this.findOne({ 'username': username.toLowerCase() });
100
+ const run = async () => {
101
+ var query = this.findOne({ 'username': username.toLowerCase() });
102
+
103
+ if (maxItems && maxItems >= 1) { query = query.slice('items', maxItems); }
93
104
 
94
- if (maxItems && maxItems >= 1) { query = query.slice('items', maxItems); }
105
+ const result = await query.lean({ virtuals: true });
106
+ return result;
107
+ };
95
108
 
96
- query.exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
109
+ if (typeof cb === 'function') { run().then(result => cb(null, result)).catch(cb); return; }
110
+ else { return run(); }
97
111
 
98
112
  };
99
113
  Activity.set('autoIndex', false);
package/lib/ApiKey.js CHANGED
@@ -20,44 +20,47 @@ module.exports = function(mongoose, config) {
20
20
 
21
21
  ApiKey.statics.getByTokenHash = function(hash, cb) {
22
22
 
23
- var self = this;
23
+ const run = async () => {
24
+ if (!hash) { throw new Error('hash is required'); }
24
25
 
25
- if (!cb) { throw new Error('cb is required'); }
26
- if (!hash) { return cb(new Error('hash is required'), null); }
26
+ const result = await this.findOne({ tokenHash: hash }).lean({ virtuals: true });
27
+ return result;
28
+ };
27
29
 
28
- self
29
- .findOne({ tokenHash: hash })
30
- .exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
30
+ if (typeof cb === 'function') { run().then(result => cb(null, result)).catch(cb); return; }
31
+ else { return run(); }
31
32
 
32
33
  };
33
34
 
34
35
  ApiKey.statics.getByAccount = function(accountId, customerId, cb) {
35
36
 
36
- var self = this;
37
+ const run = async () => {
38
+ if (!accountId) { throw new Error('accountId is required'); }
39
+ if (!customerId) { throw new Error('customerId is required'); }
37
40
 
38
- if (!cb) { throw new Error('cb is required'); }
39
- if (!accountId) { return cb(new Error('accountId is required'), null); }
40
- if (!customerId) { return cb(new Error('customerId is required'), null); }
41
+ const result = await this.find({ account: accountId, customer: customerId, active: true }).sort({ createdOn: -1 }).select('scopes createdOn lastUsedOn').lean({ virtuals: true });
42
+ return result;
43
+ };
41
44
 
42
- self
43
- .find({ account: accountId, customer: customerId, active: true })
44
- .sort({ createdOn: -1 })
45
- .select('scopes createdOn lastUsedOn')
46
- .exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
45
+ if (typeof cb === 'function') { run().then(result => cb(null, result)).catch(cb); return; }
46
+ else { return run(); }
47
47
 
48
48
  };
49
49
 
50
50
  ApiKey.statics.revoke = function(tokenId, accountId, customerId, cb) {
51
51
 
52
- var self = this;
52
+ const run = async () => {
53
+ if (!tokenId) { throw new Error('tokenId is required'); }
53
54
 
54
- if (!cb) { throw new Error('cb is required'); }
55
- if (!tokenId) { return cb(new Error('tokenId is required'), null); }
55
+ const result = await this.findOneAndUpdate(
56
+ { _id: tokenId, account: accountId, customer: customerId },
57
+ { active: false },
58
+ { new: true });
59
+ return result;
60
+ };
56
61
 
57
- self.findOneAndUpdate(
58
- { _id: tokenId, account: accountId, customer: customerId },
59
- { active: false },
60
- { new: true }).then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
62
+ if (typeof cb === 'function') { run().then(result => cb(null, result)).catch(cb); return; }
63
+ else { return run(); }
61
64
 
62
65
  };
63
66
  ApiKey.set('autoIndex', false);