sumba 2.37.0 → 2.38.1

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.
@@ -29,20 +29,58 @@ async function factory (pkgName) {
29
29
  */
30
30
  constructor () {
31
31
  super(pkgName, me.app)
32
+
33
+ /**
34
+ * Configuration object
35
+ * @type {Sumba.TConfig}
36
+ */
32
37
  this.config = config
38
+
39
+ /**
40
+ * Secure guards containers
41
+ * @type {Array}
42
+ */
33
43
  this.secureGuards = []
44
+
45
+ /**
46
+ * Action guards container
47
+ * @type {Array}
48
+ */
34
49
  this.actionGuards = []
50
+
51
+ /**
52
+ * Query guards container
53
+ * @type {Array}
54
+ */
35
55
  this.queryGuards = []
56
+
57
+ /**
58
+ * Attribute guards container
59
+ * @type {Array}
60
+ */
36
61
  this.attribGuards = []
37
- this.secureGuards = []
62
+
63
+ /**
64
+ * Anonymous guards container
65
+ * @type {Array}
66
+ */
38
67
  this.anonymousGuards = []
39
68
 
69
+ /**
70
+ * Download directory path for storing exported files.
71
+ * @type {string}
72
+ */
73
+ this.downloadDir = null
74
+
75
+ /**
76
+ * Unsafe user fields that should not be exposed or returned in API responses.
77
+ * @type {string[]}
78
+ */
40
79
  this.unsafeUserFields = ['password']
41
80
  }
42
81
 
43
82
  /**
44
- * Plugin initialization method. This method is called by the {@link https://ardhi.github.io/bajo|Bajo framework} during plugin initialization.
45
- *
83
+ * Plugin initialization method
46
84
  * @async
47
85
  * @method
48
86
  */
@@ -56,8 +94,7 @@ async function factory (pkgName) {
56
94
  }
57
95
 
58
96
  /**
59
- * Plugin start method. This method is called by the {@link https://ardhi.github.io/bajo|Bajo framework} during plugin start.
60
- *
97
+ * Plugin start method
61
98
  * @async
62
99
  * @method
63
100
  */
@@ -76,10 +113,9 @@ async function factory (pkgName) {
76
113
 
77
114
  /**
78
115
  * Populate route guards at start
79
- *
80
116
  * @async
81
117
  * @method
82
- * @param {array} [sites] - List of sites to populate route guards for. If not provided, it will fetch all active sites.
118
+ * @param {array} [sites] - List of sites to populate route guards for. If not provided, it will fetch all active sites
83
119
  */
84
120
  populateRouteGuards = async (sites) => {
85
121
  const { isString, get, difference } = this.app.lib._
@@ -161,12 +197,11 @@ async function factory (pkgName) {
161
197
 
162
198
  /**
163
199
  * Get authentication setting based on type and source
164
- *
165
200
  * @method
166
- * @private
167
- * @param {string} type - The type of authentication setting to retrieve. If not provided, it will use parent setting.
168
- * @param {string} [source] - The source of the authentication setting. If not provided, it will use the default setting.
169
- * @returns {object} - The authentication setting object.
201
+ * @internal
202
+ * @param {string} [type] - The type of authentication setting to retrieve. If not provided, it will use parent setting
203
+ * @param {string} [source] - The source of the authentication setting. If not provided, it will use the default setting
204
+ * @returns {object} - The authentication setting object
170
205
  */
171
206
  _getAuthSetting = (type, source) => {
172
207
  const { defaultsDeep } = this.app.lib.aneka
@@ -182,13 +217,12 @@ async function factory (pkgName) {
182
217
 
183
218
  /**
184
219
  * Get authentication token based on type, request, and source
185
- *
186
220
  * @method
187
- * @private
188
- * @param {string} type - The type of authentication setting.
189
- * @param {object} req - The request object.
190
- * @param {string} [source] - The source of the authentication setting. If not provided, it will use the default setting.
191
- * @returns {string|boolean} - The token if found, otherwise false.
221
+ * @internal
222
+ * @param {string} type - The type of authentication setting
223
+ * @param {object} req - The request object
224
+ * @param {string} [source] - The source of the authentication setting. If not provided, it will use the default setting
225
+ * @returns {string|boolean} - The token if found, otherwise false
192
226
  */
193
227
  _getAuthToken = (type, req, source) => {
194
228
  const { isEmpty } = this.app.lib._
@@ -206,16 +240,14 @@ async function factory (pkgName) {
206
240
 
207
241
  /**
208
242
  * Build admin menu based on locals and request.
209
- *
210
- * - If multi-site is enabled, it will include the cross-site menu with options to manage all sites and site settings.
211
- * - If caching is enabled, it will include the cache storage menu in the appropriate section.
243
+ * - If multi-site is enabled, it will include the cross-site menu with options to manage all sites and site settings
244
+ * - If caching is enabled, it will include the cache storage menu in the appropriate section
212
245
  * - Session management menu is also included in the appropriate section.
213
- *
214
246
  * @async
215
247
  * @method
216
- * @param {object} locals - The locals object.
217
- * @param {object} req - The request object.
218
- * @returns {array} - The admin menu items.
248
+ * @param {object} locals - The locals object
249
+ * @param {object} req - The request object
250
+ * @returns {array} - The admin menu items
219
251
  */
220
252
  adminMenu = async (locals, req) => {
221
253
  if (!this.app.waibuAdmin) return
@@ -286,11 +318,10 @@ async function factory (pkgName) {
286
318
 
287
319
  /**
288
320
  * Create JWT from user record
289
- *
290
321
  * @async
291
322
  * @method
292
- * @param {object} rec - The user record object.
293
- * @returns {Promise<object>} - The JWT token and its expiration date.
323
+ * @param {object} rec - The user record object
324
+ * @returns {Promise<object>} The JWT token and its expiration date
294
325
  */
295
326
  createJwtFromUserRecord = async (rec) => {
296
327
  const { importPkg } = this.app.bajo
@@ -313,14 +344,13 @@ async function factory (pkgName) {
313
344
 
314
345
  /**
315
346
  * Verify user session
316
- *
317
347
  * @async
318
348
  * @method
319
- * @param {object} req - The request object.
320
- * @param {object} reply - The reply object.
321
- * @param {string} source - The source of the authentication setting.
322
- * @param {object} payload - The payload object.
323
- * @returns {boolean} - True if the session is valid, otherwise false.
349
+ * @param {object} req - The request object
350
+ * @param {object} reply - The reply object
351
+ * @param {string} source - The source of the authentication setting
352
+ * @param {object} payload - The payload object
353
+ * @returns {boolean} - True if the session is valid, otherwise false
324
354
  */
325
355
  verifySession = async (req, reply, source, payload) => {
326
356
  const { routePath } = this.app.waibu
@@ -338,14 +368,13 @@ async function factory (pkgName) {
338
368
 
339
369
  /**
340
370
  * Verify API key
341
- *
342
371
  * @async
343
372
  * @method
344
- * @param {object} req - The request object.
345
- * @param {object} reply - The reply object.
346
- * @param {string} source - The source of the authentication setting.
347
- * @param {object} payload - The payload object.
348
- * @returns {boolean} - True if the API key is valid, otherwise false.
373
+ * @param {object} req - The request object
374
+ * @param {object} reply - The reply object
375
+ * @param {string} source - The source of the authentication setting
376
+ * @param {object} payload - The payload object
377
+ * @returns {boolean} - True if the API key is valid, otherwise false
349
378
  */
350
379
  verifyApiKey = async (req, reply, source, payload) => {
351
380
  const { merge, camelCase } = this.app.lib._
@@ -364,14 +393,13 @@ async function factory (pkgName) {
364
393
 
365
394
  /**
366
395
  * Verify basic authentication
367
- *
368
396
  * @async
369
397
  * @method
370
- * @param {object} req - The request object.
371
- * @param {object} reply - The reply object.
372
- * @param {string} source - The source of the authentication setting.
373
- * @param {object} payload - The payload object.
374
- * @returns {boolean|string} - True if the basic authentication is valid, otherwise false or an error message.
398
+ * @param {object} req - The request object
399
+ * @param {object} reply - The reply object
400
+ * @param {string} source - The source of the authentication setting
401
+ * @param {object} payload - The payload object
402
+ * @returns {boolean|string} - True if the basic authentication is valid, otherwise false or an error message
375
403
  */
376
404
  verifyBasic = async (req, reply, source, payload) => {
377
405
  const { isEmpty, merge } = this.app.lib._
@@ -412,14 +440,13 @@ async function factory (pkgName) {
412
440
 
413
441
  /**
414
442
  * Verify JWT authentication
415
- *
416
443
  * @async
417
444
  * @method
418
- * @param {object} req - The request object.
419
- * @param {object} reply - The reply object.
420
- * @param {string} source - The source of the authentication setting.
421
- * @param {object} payload - The payload object.
422
- * @returns {boolean} - True if the JWT authentication is valid, otherwise false.
445
+ * @param {object} req - The request object
446
+ * @param {object} reply - The reply object
447
+ * @param {string} source - The source of the authentication setting
448
+ * @param {object} payload - The payload object
449
+ * @returns {boolean} - True if the JWT authentication is valid, otherwise false
423
450
  */
424
451
  verifyJwt = async (req, reply, source, payload) => {
425
452
  const { importPkg } = this.app.bajo
@@ -450,11 +477,10 @@ async function factory (pkgName) {
450
477
 
451
478
  /**
452
479
  * Check route guard
453
- *
454
480
  * @method
455
- * @param {Array} guards - The array of guard objects.
456
- * @param {Array} paths - The array of paths to check.
457
- * @returns {string|undefined} - The matched path or undefined if no match is found.
481
+ * @param {Array} guards - The array of guard object
482
+ * @param {Array} paths - The array of paths to check
483
+ * @returns {string|undefined} - The matched path or undefined if no match is found
458
484
  */
459
485
  checkRouteGuard = (guards, paths) => {
460
486
  const { outmatch } = this.app.lib
@@ -465,13 +491,12 @@ async function factory (pkgName) {
465
491
 
466
492
  /**
467
493
  * Sign out user and redirect to the specified URL
468
- *
469
494
  * @async
470
495
  * @method
471
- * @param {object} options - The options object.
472
- * @param {object} options.req - The request object.
473
- * @param {object} options.reply - The reply object.
474
- * @param {string} [options.reason] - The reason for signing out.
496
+ * @param {object} options - The options object
497
+ * @param {object} options.req - The request object
498
+ * @param {object} options.reply - The reply object
499
+ * @param {string} [options.reason] - The reason for signing out
475
500
  */
476
501
  signout = async (options = {}) => {
477
502
  const { req, reply, reason } = options
@@ -489,13 +514,12 @@ async function factory (pkgName) {
489
514
 
490
515
  /**
491
516
  * Sign in user and redirect to the specified URL
492
- *
493
517
  * @async
494
518
  * @method
495
- * @param {object} options - The options object.
496
- * @param {object} options.req - The request object.
497
- * @param {object} options.reply - The reply object.
498
- * @param {object} options.user - The user object.
519
+ * @param {object} options - The options object
520
+ * @param {object} options.req - The request object
521
+ * @param {object} options.reply - The reply object
522
+ * @param {object} options.user - The user object
499
523
  */
500
524
  signin = async (options = {}) => {
501
525
  const { req, reply, user } = options
@@ -519,8 +543,8 @@ async function factory (pkgName) {
519
543
  * Generate a random password based on the configuration settings
520
544
  *
521
545
  * @method
522
- * @param {object} req - The request object.
523
- * @returns {string} - The generated password.
546
+ * @param {object} req - The request object
547
+ * @returns {string} - The generated password
524
548
  */
525
549
  generatePassword = (req = {}) => {
526
550
  const { get } = this.app.lib._
@@ -559,8 +583,8 @@ async function factory (pkgName) {
559
583
  *
560
584
  * @async
561
585
  * @method
562
- * @param {string|number} id - The user ID.
563
- * @returns {Promise<string>} - A promise that resolves to the API key.
586
+ * @param {string|number} id - The user ID
587
+ * @returns {Promise<string>} - A promise that resolves to the API key
564
588
  */
565
589
  getApiKeyFromUserId = async id => {
566
590
  const options = { forceNoHidden: true, noHook: true, noCache: true, attachment: true, mimeType: true }
@@ -573,7 +597,7 @@ async function factory (pkgName) {
573
597
  *
574
598
  * @async
575
599
  * @method
576
- * @returns {Promise<Array<{ value: string|number, text: string }>>} - A promise that resolves to an array of country values and names.
600
+ * @returns {Promise<Array<{ value: string|number, text: string }>>} - A promise that resolves to an array of country values and names
577
601
  */
578
602
  getCountriesValues = async () => {
579
603
  const { getModel } = this.app.dobo
@@ -584,14 +608,13 @@ async function factory (pkgName) {
584
608
 
585
609
  /**
586
610
  * Method to send mail through Masohi Messaging System. It is a thin wrapper
587
- * for {@link https://github.com/ardhi/masohi-mail|masohi-mail} send method.
588
- *
589
- * If both masohiMail and waibu are not loaded, nothing is delivered.
611
+ * for {@link https://github.com/ardhi/masohi-mail|masohi-mail} send method
590
612
  *
613
+ * If both masohiMail and waibu are not loaded, nothing is delivered
591
614
  * @method
592
615
  * @async
593
616
  * @param {(string|Array)} tpl - Mail's template to use. If a string is given, the same template will be used for html & plaintext versions. Otherwise, the first template will be used for html mail, and the second one is for it's plaintext version
594
- * @param {Object} [params={}] - {@link https://github.com/ardhi/masohi-mail|masohi-mail}'s params object.
617
+ * @param {Object} [params={}] - {@link https://github.com/ardhi/masohi-mail|masohi-mail}'s params object
595
618
  */
596
619
  sendMail = async (tpl, { payload = {}, conn, source, options = {} } = {}) => {
597
620
  if (!this.app.masohiMail || !this.app.waibu) return
@@ -616,12 +639,11 @@ async function factory (pkgName) {
616
639
  }
617
640
 
618
641
  /**
619
- * Reset token by generating a new salt and hashing it twice to create a new token.
620
- *
642
+ * Reset token by generating a new salt and hashing it twice to create a new token
621
643
  * @async
622
644
  * @method
623
- * @param {string} [text] - Optional text to use as the salt. If not provided, a new salt will be generated.
624
- * @returns {Promise<{ salt: string, token: string }>} - A promise that resolves to an object containing the salt and token.
645
+ * @param {string} [text] - Optional text to use as the salt. If not provided, a new salt will be generated
646
+ * @returns {Promise<{ salt: string, token: string }>} - A promise that resolves to an object containing the salt and token
625
647
  */
626
648
  resetToken = async (text) => {
627
649
  const { generateId } = this.app.lib.aneka
@@ -631,12 +653,11 @@ async function factory (pkgName) {
631
653
  }
632
654
 
633
655
  /**
634
- * Generate a password validation rule based on the configuration settings.
635
- *
656
+ * Generate a password validation rule based on the configuration settings
636
657
  * @async
637
658
  * @method
638
- * @param {object} req - The request object.
639
- * @returns {object} - The Joi password validation rule.
659
+ * @param {object} req - The request object
660
+ * @returns {object} - The Joi password validation rule
640
661
  */
641
662
  passwordRule = async (req = {}) => {
642
663
  const { get } = this.app.lib._
@@ -659,12 +680,11 @@ async function factory (pkgName) {
659
680
  }
660
681
 
661
682
  /**
662
- * Hash the given item using the specified algorithm from the configuration.
663
- *
683
+ * Hash the given item using the specified algorithm from the configuration
664
684
  * @async
665
685
  * @method
666
- * @param {*} item - The item to be hashed.
667
- * @returns {Promise<string>} - A promise that resolves to the hashed value.
686
+ * @param {*} item - The item to be hashed
687
+ * @returns {Promise<string>} - A promise that resolves to the hashed value
668
688
  */
669
689
  hash = async (item) => {
670
690
  const { hash } = this.app.bajoExtra
@@ -673,17 +693,16 @@ async function factory (pkgName) {
673
693
  }
674
694
 
675
695
  /**
676
- * Fetch guards of the specified type from the database.
677
- *
696
+ * Fetch guards of the specified type from the database
678
697
  * @async
679
698
  * @method
680
699
  * @private
681
- * @param {string} type - The type of guards to fetch. Available types are 'Action', 'Attrib', 'Query', 'Secure', and 'Anonymous'.
682
- * @returns {Promise<Array>} - A promise that resolves to an array of guards.
700
+ * @param {string} type - The type of guards to fetch. Available types are 'Action', 'Attrib', 'Query', 'Secure', and 'Anonymous'
701
+ * @returns {Promise<Array>} - A promise that resolves to an array of guards
683
702
  */
684
703
  _fetchGuards = async (type) => {
685
704
  const { getModel } = this.app.dobo
686
- const options = { noMagic: true, noCache: true, noDriverHook: true, dataOnly: true }
705
+ const options = { noMagic: true, noCache: true, noAdapterHook: true, dataOnly: true }
687
706
  const filter = { query: { status: 'ACTIVE' } }
688
707
  const results = await getModel(`Sumba${type}Guard`).findAllRecord(filter, options)
689
708
  return results.map(result => {
@@ -693,12 +712,11 @@ async function factory (pkgName) {
693
712
  }
694
713
 
695
714
  /**
696
- * Process and order the guards based on their path and weight.
697
- *
715
+ * Process and order the guards based on their path and weight
698
716
  * @method
699
717
  * @private
700
- * @param {Array} inputs - The array of guard inputs.
701
- * @returns {Array} - The processed and ordered array of guards.
718
+ * @param {Array} inputs - The array of guard inputs
719
+ * @returns {Array} - The processed and ordered array of guards
702
720
  */
703
721
  _getGuards = (inputs = []) => {
704
722
  const { routePath } = this.app.waibu
@@ -723,12 +741,11 @@ async function factory (pkgName) {
723
741
  }
724
742
 
725
743
  /**
726
- * Get anonymous guards, optionally reloading them from the database.
727
- *
744
+ * Get anonymous guards, optionally reloading them from the database
728
745
  * @async
729
746
  * @method
730
- * @param {boolean} [reread] - Whether to reload the guards from the database.
731
- * @returns {Promise<Array>} - A promise that resolves to an array of anonymous guards.
747
+ * @param {boolean} [reread] - Whether to reload the guards from the database
748
+ * @returns {Promise<Array>} - A promise that resolves to an array of anonymous guards
732
749
  */
733
750
  getAnonymousGuards = async (reread) => {
734
751
  if (!reread) return this.anonymousGuards
@@ -738,12 +755,11 @@ async function factory (pkgName) {
738
755
  }
739
756
 
740
757
  /**
741
- * Get secure guards, optionally reloading them from the database.
742
- *
758
+ * Get secure guards, optionally reloading them from the database
743
759
  * @async
744
760
  * @method
745
- * @param {boolean} [reread] - Whether to reload the guards from the database.
746
- * @returns {Promise<Array>} - A promise that resolves to an array of secure guards.
761
+ * @param {boolean} [reread] - Whether to reload the guards from the database
762
+ * @returns {Promise<Array>} - A promise that resolves to an array of secure guards
747
763
  */
748
764
  getSecureGuards = async (reread) => {
749
765
  if (!reread) return this.secureGuards
@@ -753,12 +769,11 @@ async function factory (pkgName) {
753
769
  }
754
770
 
755
771
  /**
756
- * Get query guards, optionally reloading them from the database.
757
- *
772
+ * Get query guards, optionally reloading them from the database
758
773
  * @async
759
774
  * @method
760
- * @param {boolean} [reread] - Whether to reload the guards from the database.
761
- * @returns {Promise<Array>} - A promise that resolves to an array of query guards.
775
+ * @param {boolean} [reread] - Whether to reload the guards from the database
776
+ * @returns {Promise<Array>} - A promise that resolves to an array of query guards
762
777
  */
763
778
  getQueryGuards = async (reread) => {
764
779
  if (!reread) return this.queryGuards
@@ -768,12 +783,11 @@ async function factory (pkgName) {
768
783
  }
769
784
 
770
785
  /**
771
- * Get action guards, optionally reloading them from the database.
772
- *
786
+ * Get action guards, optionally reloading them from the database
773
787
  * @async
774
788
  * @method
775
- * @param {boolean} [reread] - Whether to reload the guards from the database.
776
- * @returns {Promise<Array>} - A promise that resolves to an array of action guards.
789
+ * @param {boolean} [reread] - Whether to reload the guards from the database
790
+ * @returns {Promise<Array>} - A promise that resolves to an array of action guards
777
791
  */
778
792
  getActionGuards = async (reread) => {
779
793
  if (!reread) return this.actionGuards
@@ -783,12 +797,11 @@ async function factory (pkgName) {
783
797
  }
784
798
 
785
799
  /**
786
- * Get attribute guards, optionally reloading them from the database.
787
- *
800
+ * Get attribute guards, optionally reloading them from the database
788
801
  * @async
789
802
  * @method
790
- * @param {boolean} [reread] - Whether to reload the guards from the database.
791
- * @returns {Promise<Array>} - A promise that resolves to an array of attribute guards.
803
+ * @param {boolean} [reread] - Whether to reload the guards from the database
804
+ * @returns {Promise<Array>} - A promise that resolves to an array of attribute guards
792
805
  */
793
806
  getAttribGuards = async (reread) => {
794
807
  if (!reread) return this.attribGuards
@@ -798,11 +811,10 @@ async function factory (pkgName) {
798
811
  }
799
812
 
800
813
  /**
801
- * Get all loaded model names, optionally returning them as value-text pairs.
802
- *
814
+ * Get all loaded model names, optionally returning them as value-text pairs
803
815
  * @method
804
- * @param {boolean} [asValue] - Whether to return the model names as value-text pairs.
805
- * @returns {Array} - An array of model names or value-text pairs.
816
+ * @param {boolean} [asValue] - Whether to return the model names as value-text pairs
817
+ * @returns {Array} - An array of model names or value-text pairs
806
818
  */
807
819
  getModelNames = (asValue) => {
808
820
  const values = this.app.dobo.models.map(item => item.name).sort()
@@ -810,11 +822,10 @@ async function factory (pkgName) {
810
822
  }
811
823
 
812
824
  /**
813
- * Gather all paths to check for a request.
814
- *
825
+ * Gather all paths to check for a request
815
826
  * @method
816
- * @param {Object} req - The request object.
817
- * @returns {Array} - An array of paths to check.
827
+ * @param {Object} req - The request object
828
+ * @returns {Array} - An array of paths to check
818
829
  */
819
830
  pathsToCheck = (req) => {
820
831
  const { isSet } = this.app.lib.aneka
@@ -824,13 +835,12 @@ async function factory (pkgName) {
824
835
  }
825
836
 
826
837
  /**
827
- * Check and set the iconset for a request.
828
- *
838
+ * Check and set the iconset for a request
829
839
  * @async
830
840
  * @method
831
- * @param {Object} req - The request object.
832
- * @param {Object} reply - The reply object.
833
- * @returns {Promise<void>} - A promise that resolves when the iconset is checked and set.
841
+ * @param {Object} req - The request object
842
+ * @param {Object} reply - The reply object
843
+ * @returns {Promise<void>} A promise that resolves when the iconset is checked and set
834
844
  */
835
845
  checkIconset = async (req, reply) => {
836
846
  const { get, isString } = this.app.lib._
@@ -845,13 +855,12 @@ async function factory (pkgName) {
845
855
  }
846
856
 
847
857
  /**
848
- * Check and set the theme for a request.
849
- *
858
+ * Check and set the theme for a request
850
859
  * @async
851
860
  * @method
852
- * @param {Object} req - The request object.
853
- * @param {Object} reply - The reply object.
854
- * @returns {Promise<void>} - A promise that resolves when the theme is checked and set.
861
+ * @param {Object} req - The request object
862
+ * @param {Object} reply - The reply object
863
+ * @returns {Promise<void>} A promise that resolves when the theme is checked and set
855
864
  */
856
865
  checkTheme = async (req, reply) => {
857
866
  const { get, isString } = this.app.lib._
@@ -866,13 +875,12 @@ async function factory (pkgName) {
866
875
  }
867
876
 
868
877
  /**
869
- * Check and set the team for a request.
870
- *
878
+ * Check and set the team for a request
871
879
  * @async
872
880
  * @method
873
- * @param {Object} req - The request object.
874
- * @param {Object} reply - The reply object.
875
- * @returns {Promise<void>} - A promise that resolves when the team is checked and set.
881
+ * @param {Object} req - The request object
882
+ * @param {Object} reply - The reply object
883
+ * @returns {Promise<void>} A promise that resolves when the team is checked and set
876
884
  */
877
885
  checkTeam = async (req, reply) => {
878
886
  const { includes } = this.app.lib.aneka
@@ -897,14 +905,13 @@ async function factory (pkgName) {
897
905
  }
898
906
 
899
907
  /**
900
- * Check and set the user for a request.
901
- *
908
+ * Check and set the user for a request
902
909
  * @async
903
910
  * @method
904
- * @param {Object} req - The request object.
905
- * @param {Object} reply - The reply object.
906
- * @param {Object} source - The source object.
907
- * @returns {Promise<boolean|void>} - A promise that resolves to a boolean indicating the result of the check or void.
911
+ * @param {Object} req - The request object
912
+ * @param {Object} reply - The reply object
913
+ * @param {Object} source - The source object
914
+ * @returns {Promise<boolean|void>} A promise that resolves to a boolean indicating the result of the check or void
908
915
  */
909
916
  checkUser = async (req, reply, source) => {
910
917
  const { merge, isEmpty, camelCase, get } = this.app.lib._
@@ -967,13 +974,12 @@ async function factory (pkgName) {
967
974
  }
968
975
 
969
976
  /**
970
- * Check and set the Cross-site settings for a request.
971
- *
977
+ * Check and set the Cross-site settings for a request
972
978
  * @async
973
979
  * @method
974
- * @param {Object} req - The request object.
975
- * @param {Object} reply - The reply object.
976
- * @returns {Promise<void>} - A promise that resolves when the XSite is checked and set.
980
+ * @param {Object} req - The request object
981
+ * @param {Object} reply - The reply object
982
+ * @returns {Promise<void>} A promise that resolves when the XSite is checked and set
977
983
  */
978
984
  checkXSite = async (req, reply) => {
979
985
  const { get } = this.app.lib._
@@ -984,12 +990,11 @@ async function factory (pkgName) {
984
990
  }
985
991
 
986
992
  /**
987
- * Check the route for a request.
988
- *
993
+ * Check the route for a request
989
994
  * @async
990
995
  * @method
991
- * @param {Object} req - The request object.
992
- * @returns {Promise<void>} - A promise that resolves when the route is checked.
996
+ * @param {Object} req - The request object
997
+ * @returns {Promise<void>} A promise that resolves when the route is checked
993
998
  */
994
999
  checkRoute = async (req) => {
995
1000
  const { routePath } = this.app.waibu
@@ -1002,12 +1007,11 @@ async function factory (pkgName) {
1002
1007
  }
1003
1008
 
1004
1009
  /**
1005
- * Parse namespace settings for a request.
1006
- *
1010
+ * Parse namespace settings for a request
1007
1011
  * @method
1008
- * @param {string} ns - The namespace.
1009
- * @param {Object} setting - The setting object.
1010
- * @param {Array} items - The items to parse.
1012
+ * @param {string} ns - The namespace
1013
+ * @param {Object} setting - The setting object
1014
+ * @param {Array} items - The items to parse
1011
1015
  */
1012
1016
  parseNsSettings = (ns, setting, items) => {
1013
1017
  const { trim, set, isPlainObject, isArray, isEmpty, find } = this.app.lib._
@@ -1037,12 +1041,11 @@ async function factory (pkgName) {
1037
1041
  }
1038
1042
 
1039
1043
  /**
1040
- * Get all fixtures for the specified alias, replacing any occurrences of '{alias}' in the fixture data with the provided alias.
1041
- *
1044
+ * Get all fixtures for the specified alias, replacing any occurrences of '{alias}' in the fixture data with the provided alias
1042
1045
  * @async
1043
1046
  * @method
1044
- * @param {string} [alias] - The alias for the fixtures.
1045
- * @returns {Promise<object>} - A promise that resolves to the fixtures data.
1047
+ * @param {string} [alias] - The alias for the fixtures
1048
+ * @returns {Promise<object>} A promise that resolves to the fixtures data
1046
1049
  */
1047
1050
  getAllFixtures = async (alias) => {
1048
1051
  const { readConfig } = this.app.bajo
@@ -1098,13 +1101,12 @@ async function factory (pkgName) {
1098
1101
 
1099
1102
  /**
1100
1103
  * Create references for the specified site using the provided data, options, and verbosity settings.
1101
- *
1102
1104
  * @async
1103
1105
  * @method
1104
- * @param {object} site - The site object for which to create references.
1105
- * @param {object} data - The data object containing fixtures for the site.
1106
- * @param {object} options - Options to pass to the createRecord method.
1107
- * @param {boolean} verbose - Whether to log verbose output.
1106
+ * @param {object} site - The site object for which to create references
1107
+ * @param {object} data - The data object containing fixtures for the site
1108
+ * @param {object} options - Options to pass to the createRecord method
1109
+ * @param {boolean} verbose - Whether to log verbose output
1108
1110
  */
1109
1111
  createRefs = async (site, data, options, verbose) => {
1110
1112
  const { isString } = this.app.lib._
@@ -1130,12 +1132,11 @@ async function factory (pkgName) {
1130
1132
 
1131
1133
  /**
1132
1134
  * Create a new site with the specified alias and optional hostname, using fixtures for initial data.
1133
- *
1134
1135
  * @async
1135
1136
  * @method
1136
- * @param {string} alias - The alias for the new site.
1137
- * @param {string} [hostname] - The hostname for the new site.
1138
- * @param {boolean} [verbose=false] - Whether to log verbose output.
1137
+ * @param {string} alias - The alias for the new site
1138
+ * @param {string} [hostname] - The hostname for the new site
1139
+ * @param {boolean} [verbose=false] - Whether to log verbose output
1139
1140
  */
1140
1141
  createNewSite = async (alias, hostname, verbose) => {
1141
1142
  const { isEmpty } = this.app.lib._
@@ -1168,12 +1169,11 @@ async function factory (pkgName) {
1168
1169
 
1169
1170
  /**
1170
1171
  * Remove references for the specified site using the provided options and verbosity settings.
1171
- *
1172
1172
  * @async
1173
1173
  * @method
1174
- * @param {object} site - The site object for which to remove references.
1175
- * @param {object} options - Options to pass to the removeRecord method.
1176
- * @param {boolean} verbose - Whether to log verbose output.
1174
+ * @param {object} site - The site object for which to remove references
1175
+ * @param {object} options - Options to pass to the removeRecord method
1176
+ * @param {boolean} verbose - Whether to log verbose output
1177
1177
  */
1178
1178
  removeRefs = async (site, options, verbose) => {
1179
1179
  const { orderBy } = this.app.lib._
@@ -1197,11 +1197,10 @@ async function factory (pkgName) {
1197
1197
 
1198
1198
  /**
1199
1199
  * Remove a site with the specified alias, along with its references, using the provided verbosity settings.
1200
- *
1201
1200
  * @async
1202
1201
  * @method
1203
- * @param {string} alias - The alias of the site to remove.
1204
- * @param {boolean} [verbose=false] - Whether to log verbose output.
1202
+ * @param {string} alias - The alias of the site to remove
1203
+ * @param {boolean} [verbose=false] - Whether to log verbose output
1205
1204
  */
1206
1205
  removeSite = async (alias, verbose) => {
1207
1206
  const { isEmpty } = this.app.lib._
@@ -1223,12 +1222,11 @@ async function factory (pkgName) {
1223
1222
 
1224
1223
  /**
1225
1224
  * Get site information based on the provided input, which can be either a hostname or an ID. If multi-site is enabled, it will fetch the site based on the hostname or ID; otherwise, it will return the default site.
1226
- *
1227
1225
  * @async
1228
1226
  * @method
1229
- * @param {string|number} input - The input value, which can be either a hostname or an ID.
1230
- * @param {boolean} [byId=false] - Whether to fetch the site by ID.
1231
- * @returns {object} The site information.
1227
+ * @param {string|number} input - The input value, which can be either a hostname or an ID
1228
+ * @param {boolean} [byId=false] - Whether to fetch the site by ID
1229
+ * @returns {object} The site information
1232
1230
  */
1233
1231
  getSite = async (input, byId = false) => {
1234
1232
  const { omit } = this.app.lib._
@@ -1300,12 +1298,12 @@ async function factory (pkgName) {
1300
1298
  }
1301
1299
 
1302
1300
  /**
1303
- * Merge team information into the user object.
1301
+ * Merge team information into the user object
1304
1302
  *
1305
1303
  * @async
1306
1304
  * @method
1307
- * @param {object} user - The user object to merge team information into.
1308
- * @param {object} req - The request object.
1305
+ * @param {object} user - The user object to merge team information into
1306
+ * @param {object} req - The request object
1309
1307
  */
1310
1308
  mergeTeam = async (user, req) => {
1311
1309
  const { map, pick } = this.app.lib._
@@ -1346,12 +1344,11 @@ async function factory (pkgName) {
1346
1344
 
1347
1345
  /**
1348
1346
  * Get a user by their ID.
1349
- *
1350
1347
  * @async
1351
1348
  * @method
1352
- * @param {string|number} id - The ID of the user to retrieve.
1353
- * @param {object} req - The request object.
1354
- * @returns {object|null} The user object if found, otherwise null.
1349
+ * @param {string|number} id - The ID of the user to retrieve
1350
+ * @param {object} req - The request object
1351
+ * @returns {object|null} The user object if found, otherwise null
1355
1352
  */
1356
1353
  getUserById = async (id, req) => {
1357
1354
  const { getModel } = this.app.dobo
@@ -1362,7 +1359,7 @@ async function factory (pkgName) {
1362
1359
  user = await getCache({ key })
1363
1360
  if (user) return JSON.parse(user)
1364
1361
  }
1365
- user = await getModel('SumbaUser').getRecord(id, { noHook: true, noDriverHook: true, throwNotFound: false, req })
1362
+ user = await getModel('SumbaUser').getRecord(id, { noHook: true, noAdapterHook: true, throwNotFound: false, req })
1366
1363
  if (!user) return
1367
1364
  await this.mergeTeam(user, req)
1368
1365
  if (setCache) {
@@ -1373,12 +1370,11 @@ async function factory (pkgName) {
1373
1370
 
1374
1371
  /**
1375
1372
  * Get a user by their token.
1376
- *
1377
1373
  * @async
1378
1374
  * @method
1379
- * @param {string} token - The token of the user to retrieve.
1380
- * @param {object} req - The request object.
1381
- * @returns {object|null} The user object if found, otherwise null.
1375
+ * @param {string} token - The token of the user to retrieve
1376
+ * @param {object} req - The request object
1377
+ * @returns {object|null} The user object if found, otherwise null
1382
1378
  */
1383
1379
  getUserByToken = async (token, req) => {
1384
1380
  const { getModel } = this.app.dobo
@@ -1389,7 +1385,7 @@ async function factory (pkgName) {
1389
1385
  user = await getCache({ key })
1390
1386
  if (user) return JSON.parse(user)
1391
1387
  }
1392
- user = await getModel('SumbaUser').findOneRecord({ query: { token } }, { noHook: true, noDriverHook: true, throwNotFound: false, req })
1388
+ user = await getModel('SumbaUser').findOneRecord({ query: { token } }, { noHook: true, noAdapterHook: true, throwNotFound: false, req })
1393
1389
  if (!user) return
1394
1390
  await this.mergeTeam(user, req)
1395
1391
  if (setCache) {
@@ -1406,7 +1402,7 @@ async function factory (pkgName) {
1406
1402
  const bcrypt = await importPkg('bajoExtra:bcrypt')
1407
1403
 
1408
1404
  const query = { username, provider: 'local', siteId: req.site.id + '' }
1409
- const user = await model.findOneRecord({ query }, { req, forceNoHidden: true, noHook: true, noDriverHook: true })
1405
+ const user = await model.findOneRecord({ query }, { req, forceNoHidden: true, noHook: true, noAdapterHook: true })
1410
1406
  if (!user) throw this.error('validationError', { details: [{ field: 'username', error: 'Unknown username' }], statusCode: 401 })
1411
1407
  if (user.status !== 'ACTIVE') throw this.error('validationError', { details: ['User is inactive or temporarily disabled'], statusCode: 401 })
1412
1408
  const verified = await bcrypt.compare(password, user.password)
@@ -1417,11 +1413,10 @@ async function factory (pkgName) {
1417
1413
 
1418
1414
  /**
1419
1415
  * Clear the cache for a specific site.
1420
- *
1421
1416
  * @async
1422
1417
  * @method
1423
- * @param {string|number} id - The ID of the site.
1424
- * @param {object} result - The result object containing site data.
1418
+ * @param {string|number} id - The ID of the site
1419
+ * @param {object} result - The result object containing site data
1425
1420
  */
1426
1421
  clearCacheSite = async (id, result) => {
1427
1422
  if (!this.app.bajoCache) return
@@ -1434,11 +1429,10 @@ async function factory (pkgName) {
1434
1429
 
1435
1430
  /**
1436
1431
  * Clear the cache for a specific user.
1437
- *
1438
1432
  * @async
1439
1433
  * @method
1440
- * @param {string|number} id - The ID of the user.
1441
- * @param {object} result - The result object containing user data.
1434
+ * @param {string|number} id - The ID of the user
1435
+ * @param {object} result - The result object containing user data
1442
1436
  */
1443
1437
  clearCacheUser = async (id, result) => {
1444
1438
  if (!this.app.bajoCache) return
@@ -1451,13 +1445,12 @@ async function factory (pkgName) {
1451
1445
 
1452
1446
  /**
1453
1447
  * Filter model data based on settings.
1454
- *
1455
1448
  * @method
1456
- * @param {object} opts - The options object.
1457
- * @param {object} opts.model - The model object.
1458
- * @param {string} opts.field - The field to filter.
1459
- * @param {object} [opts.options={}] - Additional options.
1460
- * @returns {object} The filtered results and operation values.
1449
+ * @param {object} opts - The options object
1450
+ * @param {object} opts.model - The model object
1451
+ * @param {string} opts.field - The field to filter
1452
+ * @param {object} [opts.options={}] - Additional options
1453
+ * @returns {object} The filtered results and operation values
1461
1454
  */
1462
1455
  filterModelFromSetting = (opts = {}) => {
1463
1456
  const { model, field, options = {} } = opts
@@ -1488,14 +1481,13 @@ async function factory (pkgName) {
1488
1481
 
1489
1482
  /**
1490
1483
  * Apply query guards to the provided query.
1491
- *
1492
1484
  * @async
1493
1485
  * @method
1494
- * @param {object} [opts={}] - The options object.
1495
- * @param {object} opts.model - The model object.
1496
- * @param {object} [opts.q={}] - The query object.
1497
- * @param {array} [opts.teamIds=[]] - The team IDs.
1498
- * @param {object} [opts.options={}] - Additional options.
1486
+ * @param {object} [opts={}] - The options object
1487
+ * @param {object} opts.model - The model object
1488
+ * @param {object} [opts.q={}] - The query object
1489
+ * @param {array} [opts.teamIds=[]] - The team IDs
1490
+ * @param {object} [opts.options={}] - Additional options
1499
1491
  */
1500
1492
  runQueryGuard = async (opts = {}) => {
1501
1493
  const { model, q = {}, teamIds = [], options = {} } = opts
@@ -1541,13 +1533,12 @@ async function factory (pkgName) {
1541
1533
 
1542
1534
  /**
1543
1535
  * Apply attribute guards to the provided model.
1544
- *
1545
1536
  * @async
1546
1537
  * @method
1547
- * @param {object} [opts={}] - The options object.
1548
- * @param {object} opts.model - The model object.
1549
- * @param {array} [opts.teamIds=[]] - The team IDs.
1550
- * @param {object} [opts.options={}] - Additional options.
1538
+ * @param {object} [opts={}] - The options object
1539
+ * @param {object} opts.model - The model object
1540
+ * @param {array} [opts.teamIds=[]] - The team IDs
1541
+ * @param {object} [opts.options={}] - Additional options
1551
1542
  */
1552
1543
  runAttribGuard = async (opts = {}) => {
1553
1544
  const { model, teamIds = [], options = {} } = opts
@@ -1571,10 +1562,9 @@ async function factory (pkgName) {
1571
1562
 
1572
1563
  /**
1573
1564
  * Get the team IDs and aliases for the user in the request.
1574
- *
1575
1565
  * @method
1576
- * @param {object} req - The request object.
1577
- * @returns {object} An object containing the team IDs and aliases.
1566
+ * @param {object} req - The request object
1567
+ * @returns {object} An object containing the team IDs and aliases
1578
1568
  */
1579
1569
  getTeamIdsAndAliases = (req) => {
1580
1570
  const { get } = this.app.lib._
@@ -1586,13 +1576,12 @@ async function factory (pkgName) {
1586
1576
 
1587
1577
  /**
1588
1578
  * Rebuild the filter for the provided model.
1589
- *
1590
1579
  * @async
1591
1580
  * @method
1592
- * @param {object} model - The model object.
1593
- * @param {object} [filter={}] - The filter object.
1594
- * @param {object} [options={}] - Additional options.
1595
- * @returns {Promise<object>} The rebuilt filter.
1581
+ * @param {object} model - The model object
1582
+ * @param {object} [filter={}] - The filter object
1583
+ * @param {object} [options={}] - Additional options
1584
+ * @returns {Promise<object>} The rebuilt filter
1596
1585
  */
1597
1586
  rebuildFilter = async (model, filter = {}, options = {}) => {
1598
1587
  const { isEmpty, get, keys } = this.app.lib._
@@ -1663,13 +1652,12 @@ async function factory (pkgName) {
1663
1652
 
1664
1653
  /**
1665
1654
  * Apply query hook to the provided model.
1666
- *
1667
1655
  * @async
1668
1656
  * @method
1669
- * @param {object} model - The model object.
1670
- * @param {string|number} id - The ID of the model.
1671
- * @param {object} options - Additional options.
1672
- * @returns {object} The result of the model hook.
1657
+ * @param {object} model - The model object
1658
+ * @param {string|number} id - The ID of the model
1659
+ * @param {object} options - Additional options
1660
+ * @returns {object} The result of the model hook
1673
1661
  */
1674
1662
  applyQueryHook = async (model, id, options = {}) => {
1675
1663
  const { isEmpty } = this.app.lib._
@@ -1686,13 +1674,12 @@ async function factory (pkgName) {
1686
1674
 
1687
1675
  /**
1688
1676
  * Apply action hook to the provided model.
1689
- *
1690
1677
  * @async
1691
1678
  * @method
1692
- * @param {object} [opts={}] - The options object.
1693
- * @param {object} opts.model - The model object.
1694
- * @param {array} [opts.teamIds=[]] - The team IDs.
1695
- * @param {object} [opts.options={}] - Additional options.
1679
+ * @param {object} [opts={}] - The options object
1680
+ * @param {object} opts.model - The model object
1681
+ * @param {array} [opts.teamIds=[]] - The team IDs
1682
+ * @param {object} [opts.options={}] - Additional options
1696
1683
  */
1697
1684
  applyActionHook = async (opts = {}) => {
1698
1685
  const { model, options = {} } = opts
@@ -1714,13 +1701,12 @@ async function factory (pkgName) {
1714
1701
 
1715
1702
  /**
1716
1703
  * Check if the specified action is allowed for the given model and request. It retrieves the action guards, filters them based on the site ID, model name, and team IDs, and checks if the action is included in the allowed values. If any guard denies the action, it returns false; otherwise, it returns true.
1717
- *
1718
1704
  * @async
1719
1705
  * @method
1720
- * @param {string} action - The action to check. Available actions are: 'READ', 'CREATE', 'UPDATE', 'REMOVE' and 'EXPORT'.
1721
- * @param {object} model - The model object.
1722
- * @param {object} req - The request object.
1723
- * @returns {Promise<boolean>} - Returns true if the action is allowed, otherwise false.
1706
+ * @param {string} action - The action to check. Available actions are: 'READ', 'CREATE', 'UPDATE', 'REMOVE' and 'EXPORT'
1707
+ * @param {object} model - The model object
1708
+ * @param {object} req - The request object
1709
+ * @returns {Promise<boolean>} - Returns true if the action is allowed, otherwise false
1724
1710
  */
1725
1711
  isActionAllowed = async (action, model, req) => {
1726
1712
  const { includes } = this.app.lib.aneka