sumba 2.35.0 → 2.37.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/docs/Sumba.html +1 -1
- package/docs/data/search.json +1 -1
- package/docs/global.html +1 -1
- package/docs/index.js.html +77 -195
- package/docs/lib_config.js.html +201 -0
- package/docs/lib_constant.js.html +0 -51
- package/extend/bajo/hook.js +4 -4
- package/extend/bajo/intl/en-US.json +2 -1
- package/extend/bajo/intl/id.json +2 -1
- package/extend/waibuMpa/extend/waibuAdmin/route/x/site-setting/@action.js +1 -1
- package/index.js +38 -169
- package/lib/config.js +198 -0
- package/lib/constant.js +0 -51
- package/package.json +1 -1
- package/wiki/CHANGES.md +11 -1
package/index.js
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
import path from 'path'
|
|
2
|
+
import configFactory, { defMultiSite } from './lib/config.js'
|
|
2
3
|
import { joiPasswordExtendCore } from 'joi-password'
|
|
3
4
|
|
|
4
|
-
const defMultiSite = {
|
|
5
|
-
enabled: false,
|
|
6
|
-
catchAll: 'default'
|
|
7
|
-
}
|
|
8
|
-
|
|
9
5
|
/**
|
|
10
6
|
* Plugin factory.
|
|
11
7
|
*
|
|
@@ -18,6 +14,7 @@ async function factory (pkgName) {
|
|
|
18
14
|
const me = this
|
|
19
15
|
const { getModel } = this.app.dobo
|
|
20
16
|
const { cloneDeep, isEmpty } = this.app.lib._
|
|
17
|
+
const config = await configFactory.call(this)
|
|
21
18
|
|
|
22
19
|
/**
|
|
23
20
|
* Sumba class definition.
|
|
@@ -30,141 +27,7 @@ async function factory (pkgName) {
|
|
|
30
27
|
*/
|
|
31
28
|
constructor () {
|
|
32
29
|
super(pkgName, me.app)
|
|
33
|
-
|
|
34
|
-
* @type {TConfig}
|
|
35
|
-
*/
|
|
36
|
-
this.config = {
|
|
37
|
-
multiSite: cloneDeep(defMultiSite),
|
|
38
|
-
xSiteAdmins: [], // format: "<siteAlias>:<username>"
|
|
39
|
-
waibu: {
|
|
40
|
-
title: 'site',
|
|
41
|
-
prefix: 'site'
|
|
42
|
-
},
|
|
43
|
-
dobo: {
|
|
44
|
-
model: {}
|
|
45
|
-
},
|
|
46
|
-
waibuMpa: {
|
|
47
|
-
icon: 'globe',
|
|
48
|
-
redirect: {
|
|
49
|
-
'/': 'sumba:/your-stuff/profile',
|
|
50
|
-
'/your-stuff': 'sumba:/your-stuff/profile',
|
|
51
|
-
'/info': 'sumba:/info/about-us',
|
|
52
|
-
'/user': 'sumba:/your-stuff/profile',
|
|
53
|
-
'/db/export': 'sumba:/db/export/list',
|
|
54
|
-
'/help': 'sumba:/help/contact-form',
|
|
55
|
-
'/help/trouble-tickets': 'sumba:/help/trouble-tickets/list'
|
|
56
|
-
},
|
|
57
|
-
redirectSubRoute: {
|
|
58
|
-
waibuAdmin: {
|
|
59
|
-
'/': 'waibuAdmin:/site/site',
|
|
60
|
-
'/x': 'waibuAdmin:/site/x/site/list',
|
|
61
|
-
'/x/*': 'waibuAdmin:/site/x/{2}/list',
|
|
62
|
-
'/*': 'waibuAdmin:/site/{1}/list'
|
|
63
|
-
}
|
|
64
|
-
},
|
|
65
|
-
menuHandler: [{
|
|
66
|
-
title: 'account',
|
|
67
|
-
icon: 'person',
|
|
68
|
-
level: 9998,
|
|
69
|
-
children: [
|
|
70
|
-
// anonymous only
|
|
71
|
-
{ title: 'signin', href: 'sumba:/signin', visible: 'anon' },
|
|
72
|
-
{ title: 'forgotPassword', href: 'sumba:/user/forgot-password', visible: 'anon' },
|
|
73
|
-
{ title: 'newUserSignup', href: 'sumba:/user/signup', visible: 'anon' },
|
|
74
|
-
{ title: '-', visible: 'anon' },
|
|
75
|
-
{ title: 'activation', href: 'sumba:/user/activation', visible: 'anon' },
|
|
76
|
-
// authenticated only
|
|
77
|
-
{ title: 'yourProfile', href: 'sumba:/your-stuff/profile', visible: 'auth' },
|
|
78
|
-
{ title: 'changePassword', href: 'sumba:/your-stuff/change-password', visible: 'auth' },
|
|
79
|
-
{ title: 'downloadList', href: 'sumba:/your-stuff/download/list', visible: 'auth' },
|
|
80
|
-
{ title: '-', visible: 'auth' },
|
|
81
|
-
{ title: 'signout', href: 'sumba:/signout', visible: 'auth' }
|
|
82
|
-
]
|
|
83
|
-
}, {
|
|
84
|
-
title: 'help',
|
|
85
|
-
icon: 'signInfo',
|
|
86
|
-
level: 9999,
|
|
87
|
-
children: [
|
|
88
|
-
{ title: 'contactForm', href: 'sumba:/help/contact-form' },
|
|
89
|
-
{ title: 'troubleTickets', href: 'sumba:/help/trouble-tickets', visible: 'auth' },
|
|
90
|
-
{ title: '-' },
|
|
91
|
-
{ title: 'cookiePolicy', href: 'sumba:/info/cookie-policy' },
|
|
92
|
-
{ title: 'privacy', href: 'sumba:/info/privacy' },
|
|
93
|
-
{ title: 'termsConditions', href: 'sumba:/info/terms-conditions' }
|
|
94
|
-
]
|
|
95
|
-
}]
|
|
96
|
-
},
|
|
97
|
-
waibuAdmin: {
|
|
98
|
-
menuHandler: 'sumba:adminMenu',
|
|
99
|
-
menuCollapsible: true,
|
|
100
|
-
modelDisabled: 'all'
|
|
101
|
-
},
|
|
102
|
-
auth: {
|
|
103
|
-
common: {
|
|
104
|
-
apiKey: {
|
|
105
|
-
type: 'Bearer',
|
|
106
|
-
qsKey: 'apiKey',
|
|
107
|
-
headerKey: 'X-Auth-ApiKey',
|
|
108
|
-
algo: 'sha256' // changing this require each and every user to reset their apiKey
|
|
109
|
-
},
|
|
110
|
-
basic: {
|
|
111
|
-
},
|
|
112
|
-
jwt: {
|
|
113
|
-
type: 'Bearer',
|
|
114
|
-
qsKey: 'token',
|
|
115
|
-
headerKey: 'X-Auth-Jwt',
|
|
116
|
-
secret: '668de9cf57316c7dbf52f7ff7611c299',
|
|
117
|
-
expiresInDur: '7d'
|
|
118
|
-
}
|
|
119
|
-
},
|
|
120
|
-
waibuRestApi: {
|
|
121
|
-
methods: ['basic', 'apiKey', 'jwt'],
|
|
122
|
-
silentOnError: false
|
|
123
|
-
},
|
|
124
|
-
waibuMpa: {
|
|
125
|
-
methods: ['session'],
|
|
126
|
-
silentOnError: false
|
|
127
|
-
},
|
|
128
|
-
waibuStatic: {
|
|
129
|
-
methods: ['basic', 'apiKey', 'jwt'],
|
|
130
|
-
basic: {
|
|
131
|
-
useUtf8: true,
|
|
132
|
-
realm: true,
|
|
133
|
-
warningMessage: 'pleaseAuthenticate'
|
|
134
|
-
},
|
|
135
|
-
silentOnError: false
|
|
136
|
-
}
|
|
137
|
-
},
|
|
138
|
-
redirect: {
|
|
139
|
-
signin: 'sumba:/signin',
|
|
140
|
-
afterSignin: '/',
|
|
141
|
-
signout: 'sumba:/signout',
|
|
142
|
-
afterSignout: '/'
|
|
143
|
-
},
|
|
144
|
-
siteSetting: {
|
|
145
|
-
forgotPasswordExpDur: '5m',
|
|
146
|
-
timeZone: 'UTC',
|
|
147
|
-
userPassword: {
|
|
148
|
-
minUpperCase: 1,
|
|
149
|
-
minLowerCase: 1,
|
|
150
|
-
minSpecialChar: 1,
|
|
151
|
-
minNumeric: 1,
|
|
152
|
-
noWhitespace: false,
|
|
153
|
-
latinOnlyChars: false,
|
|
154
|
-
pattern: {
|
|
155
|
-
lowerCase: 'abcdefghijklmnopqrstuvwxyz',
|
|
156
|
-
upperCase: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
|
|
157
|
-
specialChar: '!@#$%*',
|
|
158
|
-
numeric: '0123456789'
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
},
|
|
162
|
-
cacheTtl: {
|
|
163
|
-
getSiteDur: '1m',
|
|
164
|
-
getUserByIdDur: '1m',
|
|
165
|
-
getUserByTokenDur: '1m'
|
|
166
|
-
}
|
|
167
|
-
}
|
|
30
|
+
this.config = config
|
|
168
31
|
this.secureGuards = []
|
|
169
32
|
this.actionGuards = []
|
|
170
33
|
this.queryGuards = []
|
|
@@ -297,18 +160,20 @@ async function factory (pkgName) {
|
|
|
297
160
|
/**
|
|
298
161
|
* Get authentication setting based on type and source
|
|
299
162
|
*
|
|
300
|
-
* @async
|
|
301
163
|
* @method
|
|
302
164
|
* @private
|
|
303
|
-
* @param {string} type - The type of authentication setting to retrieve.
|
|
304
|
-
* @param {string} source - The source of the authentication setting.
|
|
165
|
+
* @param {string} type - The type of authentication setting to retrieve. If not provided, it will use parent setting.
|
|
166
|
+
* @param {string} [source] - The source of the authentication setting. If not provided, it will use the default setting.
|
|
305
167
|
* @returns {object} - The authentication setting object.
|
|
306
168
|
*/
|
|
307
|
-
_getAuthSetting =
|
|
169
|
+
_getAuthSetting = (type, source) => {
|
|
308
170
|
const { defaultsDeep } = this.app.lib.aneka
|
|
309
171
|
const { get } = this.app.lib._
|
|
310
172
|
|
|
311
|
-
|
|
173
|
+
let setting
|
|
174
|
+
const withType = type ? `.${type}` : ''
|
|
175
|
+
if (source) setting = defaultsDeep(get(this.config, `${source}.auth${withType}`, {}), get(this.config, `auth${withType}`, {}))
|
|
176
|
+
else setting = get(this.config, `auth${withType}`, {})
|
|
312
177
|
if (type === 'basic') setting.type = 'Basic'
|
|
313
178
|
return setting
|
|
314
179
|
}
|
|
@@ -316,18 +181,17 @@ async function factory (pkgName) {
|
|
|
316
181
|
/**
|
|
317
182
|
* Get authentication token based on type, request, and source
|
|
318
183
|
*
|
|
319
|
-
* @async
|
|
320
184
|
* @method
|
|
321
185
|
* @private
|
|
322
186
|
* @param {string} type - The type of authentication setting.
|
|
323
187
|
* @param {object} req - The request object.
|
|
324
|
-
* @param {string} source - The source of the authentication setting.
|
|
188
|
+
* @param {string} [source] - The source of the authentication setting. If not provided, it will use the default setting.
|
|
325
189
|
* @returns {string|boolean} - The token if found, otherwise false.
|
|
326
190
|
*/
|
|
327
|
-
_getAuthToken =
|
|
191
|
+
_getAuthToken = (type, req, source) => {
|
|
328
192
|
const { isEmpty } = this.app.lib._
|
|
329
193
|
|
|
330
|
-
const setting =
|
|
194
|
+
const setting = this._getAuthSetting(type, source)
|
|
331
195
|
let token = req.headers[setting.headerKey.toLowerCase()]
|
|
332
196
|
if (!['basic'].includes(type) && isEmpty(token)) token = req.query[setting.qsKey]
|
|
333
197
|
if (isEmpty(token)) {
|
|
@@ -339,7 +203,11 @@ async function factory (pkgName) {
|
|
|
339
203
|
}
|
|
340
204
|
|
|
341
205
|
/**
|
|
342
|
-
* Build admin menu based on locals and request
|
|
206
|
+
* Build admin menu based on locals and request.
|
|
207
|
+
*
|
|
208
|
+
* - If multi-site is enabled, it will include the cross-site menu with options to manage all sites and site settings.
|
|
209
|
+
* - If caching is enabled, it will include the cache storage menu in the appropriate section.
|
|
210
|
+
* - Session management menu is also included in the appropriate section.
|
|
343
211
|
*
|
|
344
212
|
* @async
|
|
345
213
|
* @method
|
|
@@ -398,8 +266,8 @@ async function factory (pkgName) {
|
|
|
398
266
|
items.unshift({
|
|
399
267
|
title: 'xSite',
|
|
400
268
|
children: [
|
|
401
|
-
{ title: '
|
|
402
|
-
{ title: '
|
|
269
|
+
{ title: 'manageAllSites', href: `waibuAdmin:/${prefix}/x/site/:action`, params },
|
|
270
|
+
{ title: 'manageAllSiteSettings', href: `waibuAdmin:/${prefix}/x/site-setting/:action`, params },
|
|
403
271
|
sessionMenu
|
|
404
272
|
]
|
|
405
273
|
})
|
|
@@ -420,7 +288,7 @@ async function factory (pkgName) {
|
|
|
420
288
|
* @async
|
|
421
289
|
* @method
|
|
422
290
|
* @param {object} rec - The user record object.
|
|
423
|
-
* @returns {object} - The JWT token and its expiration date.
|
|
291
|
+
* @returns {Promise<object>} - The JWT token and its expiration date.
|
|
424
292
|
*/
|
|
425
293
|
createJwtFromUserRecord = async (rec) => {
|
|
426
294
|
const { importPkg } = this.app.bajo
|
|
@@ -430,8 +298,9 @@ async function factory (pkgName) {
|
|
|
430
298
|
const fastJwt = await importPkg('bajoExtra:fast-jwt')
|
|
431
299
|
const { createSigner } = fastJwt
|
|
432
300
|
|
|
433
|
-
const
|
|
434
|
-
opts
|
|
301
|
+
const setting = this._getAuthSetting('jwt')
|
|
302
|
+
const opts = pick(setting, ['expiresInDur'])
|
|
303
|
+
opts.key = get(setting, 'secret')
|
|
435
304
|
const sign = createSigner(opts)
|
|
436
305
|
const apiKey = await this.hash(rec.token)
|
|
437
306
|
const payload = { uid: rec.id, apiKey }
|
|
@@ -478,7 +347,8 @@ async function factory (pkgName) {
|
|
|
478
347
|
*/
|
|
479
348
|
verifyApiKey = async (req, reply, source, payload) => {
|
|
480
349
|
const { merge, camelCase } = this.app.lib._
|
|
481
|
-
const
|
|
350
|
+
const setting = this._getAuthSetting(null, source)
|
|
351
|
+
const checker = this.app.bajoExtra[camelCase(`is ${setting.apiKey.algo}`)]
|
|
482
352
|
|
|
483
353
|
let token = await this._getAuthToken('apiKey', req, source)
|
|
484
354
|
if (!checker(token)) return false
|
|
@@ -514,7 +384,7 @@ async function factory (pkgName) {
|
|
|
514
384
|
reply.code(401)
|
|
515
385
|
}
|
|
516
386
|
|
|
517
|
-
const setting =
|
|
387
|
+
const setting = this._getAuthSetting('basic', source)
|
|
518
388
|
let authInfo
|
|
519
389
|
const parts = (req.headers.authorization ?? '').split(' ')
|
|
520
390
|
if (parts[0] === setting.type) authInfo = parts[1]
|
|
@@ -555,8 +425,8 @@ async function factory (pkgName) {
|
|
|
555
425
|
|
|
556
426
|
const fastJwt = await importPkg('bajoExtra:fast-jwt')
|
|
557
427
|
const { createVerifier } = fastJwt
|
|
558
|
-
const setting =
|
|
559
|
-
const token =
|
|
428
|
+
const setting = this._getAuthSetting('jwt', source)
|
|
429
|
+
const token = this._getAuthToken('jwt', req, source)
|
|
560
430
|
if (isEmpty(token)) return false
|
|
561
431
|
const verifier = createVerifier({
|
|
562
432
|
key: setting.secret,
|
|
@@ -796,7 +666,8 @@ async function factory (pkgName) {
|
|
|
796
666
|
*/
|
|
797
667
|
hash = async (item) => {
|
|
798
668
|
const { hash } = this.app.bajoExtra
|
|
799
|
-
|
|
669
|
+
const setting = this._getAuthSetting('apiKey')
|
|
670
|
+
return await hash(item, setting.algo)
|
|
800
671
|
}
|
|
801
672
|
|
|
802
673
|
/**
|
|
@@ -810,7 +681,7 @@ async function factory (pkgName) {
|
|
|
810
681
|
*/
|
|
811
682
|
_fetchGuards = async (type) => {
|
|
812
683
|
const { getModel } = this.app.dobo
|
|
813
|
-
const options = { noMagic: true, noCache: true,
|
|
684
|
+
const options = { noMagic: true, noCache: true, noAdapterHook: true, dataOnly: true }
|
|
814
685
|
const filter = { query: { status: 'ACTIVE' } }
|
|
815
686
|
const results = await getModel(`Sumba${type}Guard`).findAllRecord(filter, options)
|
|
816
687
|
return results.map(result => {
|
|
@@ -1076,12 +947,11 @@ async function factory (pkgName) {
|
|
|
1076
947
|
await setUser()
|
|
1077
948
|
return secure
|
|
1078
949
|
}
|
|
1079
|
-
const silentOnError = this.
|
|
950
|
+
const { silentOnError, methods } = this._getAuthSetting(null, webApp)
|
|
1080
951
|
const payload = silentOnError ? { noContent: true } : undefined
|
|
1081
|
-
|
|
1082
|
-
if (isEmpty(authMethods)) throw this.error('noAuthMethod', merge({ statusCode: 500 }, payload))
|
|
952
|
+
if (isEmpty(methods)) throw this.error('noAuthMethod', merge({ statusCode: 500 }, payload))
|
|
1083
953
|
let success
|
|
1084
|
-
for (const m of
|
|
954
|
+
for (const m of methods) {
|
|
1085
955
|
const handler = this[camelCase(`verify ${m}`)]
|
|
1086
956
|
if (!handler) throw this.error('invalidAuthMethod%s', m, merge({ statusCode: 500 }, payload))
|
|
1087
957
|
const check = await handler(req, reply, source, payload)
|
|
@@ -1490,7 +1360,7 @@ async function factory (pkgName) {
|
|
|
1490
1360
|
user = await getCache({ key })
|
|
1491
1361
|
if (user) return JSON.parse(user)
|
|
1492
1362
|
}
|
|
1493
|
-
user = await getModel('SumbaUser').getRecord(id, { noHook: true,
|
|
1363
|
+
user = await getModel('SumbaUser').getRecord(id, { noHook: true, noAdapterHook: true, throwNotFound: false, req })
|
|
1494
1364
|
if (!user) return
|
|
1495
1365
|
await this.mergeTeam(user, req)
|
|
1496
1366
|
if (setCache) {
|
|
@@ -1517,7 +1387,7 @@ async function factory (pkgName) {
|
|
|
1517
1387
|
user = await getCache({ key })
|
|
1518
1388
|
if (user) return JSON.parse(user)
|
|
1519
1389
|
}
|
|
1520
|
-
user = await getModel('SumbaUser').findOneRecord({ query: { token } }, { noHook: true,
|
|
1390
|
+
user = await getModel('SumbaUser').findOneRecord({ query: { token } }, { noHook: true, noAdapterHook: true, throwNotFound: false, req })
|
|
1521
1391
|
if (!user) return
|
|
1522
1392
|
await this.mergeTeam(user, req)
|
|
1523
1393
|
if (setCache) {
|
|
@@ -1534,7 +1404,7 @@ async function factory (pkgName) {
|
|
|
1534
1404
|
const bcrypt = await importPkg('bajoExtra:bcrypt')
|
|
1535
1405
|
|
|
1536
1406
|
const query = { username, provider: 'local', siteId: req.site.id + '' }
|
|
1537
|
-
const user = await model.findOneRecord({ query }, { req, forceNoHidden: true, noHook: true,
|
|
1407
|
+
const user = await model.findOneRecord({ query }, { req, forceNoHidden: true, noHook: true, noAdapterHook: true })
|
|
1538
1408
|
if (!user) throw this.error('validationError', { details: [{ field: 'username', error: 'Unknown username' }], statusCode: 401 })
|
|
1539
1409
|
if (user.status !== 'ACTIVE') throw this.error('validationError', { details: ['User is inactive or temporarily disabled'], statusCode: 401 })
|
|
1540
1410
|
const verified = await bcrypt.compare(password, user.password)
|
|
@@ -1646,7 +1516,6 @@ async function factory (pkgName) {
|
|
|
1646
1516
|
for (const field of fields) {
|
|
1647
1517
|
if (!model.getNonVirtualProperties(true).includes(field)) continue // or, should it throws exception instead?
|
|
1648
1518
|
const inSetting = this.filterModelFromSetting({ model, field, options })
|
|
1649
|
-
if (inSetting.results.length > 0) inSetting.results.push(...inSetting.results)
|
|
1650
1519
|
const prop = model.getProperty(field)
|
|
1651
1520
|
const items = rules.filter(item => item.field === field)
|
|
1652
1521
|
for (const item of items) {
|
package/lib/config.js
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
export const defMultiSite = {
|
|
2
|
+
enabled: false,
|
|
3
|
+
catchAll: 'default'
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Sumba configuration object
|
|
8
|
+
*
|
|
9
|
+
* @typedef {object} TConfig
|
|
10
|
+
* @type {object}
|
|
11
|
+
* @property {object} [config={}] - Configuration object
|
|
12
|
+
* @property {object} [config.multiSite={}] - Multi-site configuration object
|
|
13
|
+
* @property {boolean} [config.multiSite.enabled=false] - Whether multi-site is enabled or not. Default: false
|
|
14
|
+
* @property {string} [config.multiSite.catchAll='default'] - Which site alias to use as the catch-all. Default: 'default'
|
|
15
|
+
* @property {array} [config.xSiteAdmins=[]] - List of cross-site administrators. Format: "<siteAlias>:<username>"
|
|
16
|
+
* @property {object} [config.waibu={}] - Waibu configuration object
|
|
17
|
+
* @property {string} [config.waibu.prefix='site'] - Waibu prefix
|
|
18
|
+
* @property {string} [config.waibu.title='site'] - Waibu title
|
|
19
|
+
* @property {object} [config.waibuMpa={}] - Waibu MPA configuration object
|
|
20
|
+
* @property {object} [config.waibuMpa.auth={}] - Waibu MPA authentication configuration object
|
|
21
|
+
* @property {array} [config.waibuMpa.auth.methods=['session']] - Waibu MPA authentication methods. Default: ['session']
|
|
22
|
+
* @property {boolean} [config.waibuMpa.auth.silentOnError=false] - Whether to silently ignore authentication errors or not. Default: false
|
|
23
|
+
* @property {string} [config.waibuMpa.icon='globe'] - Waibu MPA icon. Default: 'globe'
|
|
24
|
+
* @property {object} [config.waibuMpa.redirect={}] - Waibu MPA route redirection
|
|
25
|
+
* @property {object} [config.waibuMpa.redirectSubRoute={}] - Waibu MPA sub-route redirection
|
|
26
|
+
* @property {object} [config.waibuRestApi={}] - Waibu REST API configuration object
|
|
27
|
+
* @property {object} [config.waibuRestApi.auth={}] - Waibu REST API authentication configuration object
|
|
28
|
+
* @property {array} [config.waibuRestApi.auth.methods=['basic', 'apiKey', 'jwt']] - Waibu REST API authentication methods. Default: ['basic', 'apiKey', 'jwt']
|
|
29
|
+
* @property {boolean} [config.waibuRestApi.auth.silentOnError=false] - Whether to silently ignore authentication errors or not. Default: false
|
|
30
|
+
* @property {object} [config.waibuStatic={}] - Waibu Static configuration object
|
|
31
|
+
* @property {object} [config.waibuStatic.auth={}] - Waibu Static authentication configuration object
|
|
32
|
+
* @property {array} [config.waibuStatic.auth.methods=['basic', 'apiKey', 'jwt']]
|
|
33
|
+
* @property {object} [config.waibuStatic.auth.basic={}] - Waibu Static Basic authentication configuration object
|
|
34
|
+
* @property {boolean} [config.waibuStatic.auth.basic.useUtf8=true] - Whether to use UTF-8 encoding for Basic authentication or not. Default: true
|
|
35
|
+
* @property {boolean} [config.waibuStatic.auth.basic.realm=true] - Whether to use realm for Basic authentication or not. Default: true
|
|
36
|
+
* @property {string} [config.waibuStatic.auth.basic.warningMessage='pleaseAuthenticate'] - Warning message for Basic authentication. Default: 'pleaseAuthenticate'
|
|
37
|
+
* @property {boolean} [config.waibuStatic.auth.silentOnError=false] - Whether to silently ignore authentication errors or not. Default: false
|
|
38
|
+
* @property {array} [config.waibuMpa.menuHandler=[]] - Waibu MPA menu handler
|
|
39
|
+
* @property {object} [config.waibuAdmin={}] - Waibu Admin configuration object
|
|
40
|
+
* @property {string} [config.waibuAdmin.menuHandler='sumba:adminMenu'] - Waibu Admin menu handler. Default: 'sumba:adminMenu'
|
|
41
|
+
* @property {boolean} [config.waibuAdmin.menuCollapsible=true] - Whether the Waibu Admin menu is collapsible or not. Default: true
|
|
42
|
+
* @property {object} [config.auth={}] - Authentication configuration object
|
|
43
|
+
* @property {object} [config.auth.apiKey={}] - API Key authentication configuration object
|
|
44
|
+
* @property {string} [config.auth.apiKey.type='Bearer'] - API Key authentication type. Default: 'Bearer'
|
|
45
|
+
* @property {string} [config.auth.apiKey.qsKey='apiKey'] - API Key authentication query string key. Default: 'apiKey'
|
|
46
|
+
* @property {string} [config.auth.apiKey.headerKey='X-Auth-ApiKey'] - API Key authentication header key. Default: 'X-Auth-ApiKey'
|
|
47
|
+
* @property {string} [config.auth.apiKey.algo='sha256'] - API Key authentication hashing algorithm. Default: 'sha256'
|
|
48
|
+
* @property {object} [config.auth.basic={}] - Basic authentication configuration object
|
|
49
|
+
* @property {object} [config.auth.jwt={}] - JWT authentication configuration object
|
|
50
|
+
* @property {string} [config.auth.jwt.type='Bearer'] - JWT authentication type. Default: 'Bearer'
|
|
51
|
+
* @property {string} [config.auth.jwt.qsKey='token'] - JWT authentication query string key. Default: 'token'
|
|
52
|
+
* @property {string} [config.auth.jwt.headerKey='X-Auth-Jwt'] - JWT authentication header key. Default: 'X-Auth-Jwt'
|
|
53
|
+
* @property {string} [config.auth.jwt.secret] - JWT authentication secret. Default: hard coded value, should be changed in production
|
|
54
|
+
* @property {string} [config.auth.jwt.expiresInDur='7d'] - JWT authentication token expiration duration. Default: '7d'
|
|
55
|
+
* @property {object} [config.redirect={}] - Redirection configuration object
|
|
56
|
+
*/
|
|
57
|
+
|
|
58
|
+
async function configFactory () {
|
|
59
|
+
const { cloneDeep } = this.app.lib._
|
|
60
|
+
const config = {
|
|
61
|
+
multiSite: cloneDeep(defMultiSite),
|
|
62
|
+
xSiteAdmins: [], // format: "<siteAlias>:<username>"
|
|
63
|
+
waibu: {
|
|
64
|
+
title: 'site',
|
|
65
|
+
prefix: 'site'
|
|
66
|
+
},
|
|
67
|
+
dobo: {
|
|
68
|
+
model: {}
|
|
69
|
+
},
|
|
70
|
+
waibuRestApi: {
|
|
71
|
+
auth: {
|
|
72
|
+
methods: ['basic', 'apiKey', 'jwt'],
|
|
73
|
+
silentOnError: false
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
waibuStatic: {
|
|
77
|
+
auth: {
|
|
78
|
+
methods: ['basic', 'apiKey', 'jwt'],
|
|
79
|
+
basic: {
|
|
80
|
+
useUtf8: true,
|
|
81
|
+
realm: true,
|
|
82
|
+
warningMessage: 'pleaseAuthenticate'
|
|
83
|
+
},
|
|
84
|
+
silentOnError: false
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
waibuMpa: {
|
|
88
|
+
icon: 'globe',
|
|
89
|
+
auth: {
|
|
90
|
+
methods: ['session'],
|
|
91
|
+
silentOnError: false
|
|
92
|
+
},
|
|
93
|
+
redirect: {
|
|
94
|
+
'/': 'sumba:/your-stuff/profile',
|
|
95
|
+
'/your-stuff': 'sumba:/your-stuff/profile',
|
|
96
|
+
'/info': 'sumba:/info/about-us',
|
|
97
|
+
'/user': 'sumba:/your-stuff/profile',
|
|
98
|
+
'/db/export': 'sumba:/db/export/list',
|
|
99
|
+
'/help': 'sumba:/help/contact-form',
|
|
100
|
+
'/help/trouble-tickets': 'sumba:/help/trouble-tickets/list'
|
|
101
|
+
},
|
|
102
|
+
redirectSubRoute: {
|
|
103
|
+
waibuAdmin: {
|
|
104
|
+
'/': 'waibuAdmin:/site/site',
|
|
105
|
+
'/x': 'waibuAdmin:/site/x/site/list',
|
|
106
|
+
'/x/*': 'waibuAdmin:/site/x/{2}/list',
|
|
107
|
+
'/*': 'waibuAdmin:/site/{1}/list'
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
menuHandler: [{
|
|
111
|
+
title: 'account',
|
|
112
|
+
icon: 'person',
|
|
113
|
+
level: 9998,
|
|
114
|
+
children: [
|
|
115
|
+
// anonymous only
|
|
116
|
+
{ title: 'signin', href: 'sumba:/signin', visible: 'anon' },
|
|
117
|
+
{ title: 'forgotPassword', href: 'sumba:/user/forgot-password', visible: 'anon' },
|
|
118
|
+
{ title: 'newUserSignup', href: 'sumba:/user/signup', visible: 'anon' },
|
|
119
|
+
{ title: '-', visible: 'anon' },
|
|
120
|
+
{ title: 'activation', href: 'sumba:/user/activation', visible: 'anon' },
|
|
121
|
+
// authenticated only
|
|
122
|
+
{ title: 'yourProfile', href: 'sumba:/your-stuff/profile', visible: 'auth' },
|
|
123
|
+
{ title: 'changePassword', href: 'sumba:/your-stuff/change-password', visible: 'auth' },
|
|
124
|
+
{ title: 'downloadList', href: 'sumba:/your-stuff/download/list', visible: 'auth' },
|
|
125
|
+
{ title: '-', visible: 'auth' },
|
|
126
|
+
{ title: 'signout', href: 'sumba:/signout', visible: 'auth' }
|
|
127
|
+
]
|
|
128
|
+
}, {
|
|
129
|
+
title: 'help',
|
|
130
|
+
icon: 'signInfo',
|
|
131
|
+
level: 9999,
|
|
132
|
+
children: [
|
|
133
|
+
{ title: 'contactForm', href: 'sumba:/help/contact-form' },
|
|
134
|
+
{ title: 'troubleTickets', href: 'sumba:/help/trouble-tickets', visible: 'auth' },
|
|
135
|
+
{ title: '-' },
|
|
136
|
+
{ title: 'cookiePolicy', href: 'sumba:/info/cookie-policy' },
|
|
137
|
+
{ title: 'privacy', href: 'sumba:/info/privacy' },
|
|
138
|
+
{ title: 'termsConditions', href: 'sumba:/info/terms-conditions' }
|
|
139
|
+
]
|
|
140
|
+
}]
|
|
141
|
+
},
|
|
142
|
+
waibuAdmin: {
|
|
143
|
+
menuHandler: 'sumba:adminMenu',
|
|
144
|
+
menuCollapsible: true,
|
|
145
|
+
modelDisabled: 'all'
|
|
146
|
+
},
|
|
147
|
+
auth: {
|
|
148
|
+
apiKey: {
|
|
149
|
+
type: 'Bearer',
|
|
150
|
+
qsKey: 'apiKey',
|
|
151
|
+
headerKey: 'X-Auth-ApiKey',
|
|
152
|
+
algo: 'sha256' // changing this require each and every user to reset their apiKey
|
|
153
|
+
},
|
|
154
|
+
basic: {
|
|
155
|
+
},
|
|
156
|
+
jwt: {
|
|
157
|
+
type: 'Bearer',
|
|
158
|
+
qsKey: 'token',
|
|
159
|
+
headerKey: 'X-Auth-Jwt',
|
|
160
|
+
secret: '668de9cf57316c7dbf52f7ff7611c299',
|
|
161
|
+
expiresInDur: '7d'
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
redirect: {
|
|
165
|
+
signin: 'sumba:/signin',
|
|
166
|
+
afterSignin: '/',
|
|
167
|
+
signout: 'sumba:/signout',
|
|
168
|
+
afterSignout: '/'
|
|
169
|
+
},
|
|
170
|
+
siteSetting: {
|
|
171
|
+
forgotPasswordExpDur: '5m',
|
|
172
|
+
timeZone: 'UTC',
|
|
173
|
+
userPassword: {
|
|
174
|
+
minUpperCase: 1,
|
|
175
|
+
minLowerCase: 1,
|
|
176
|
+
minSpecialChar: 1,
|
|
177
|
+
minNumeric: 1,
|
|
178
|
+
noWhitespace: false,
|
|
179
|
+
latinOnlyChars: false,
|
|
180
|
+
pattern: {
|
|
181
|
+
lowerCase: 'abcdefghijklmnopqrstuvwxyz',
|
|
182
|
+
upperCase: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
|
|
183
|
+
specialChar: '!@#$%*',
|
|
184
|
+
numeric: '0123456789'
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
},
|
|
188
|
+
cacheTtl: {
|
|
189
|
+
getSiteDur: '1m',
|
|
190
|
+
getUserByIdDur: '1m',
|
|
191
|
+
getUserByTokenDur: '1m'
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
return config
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export default configFactory
|
package/lib/constant.js
CHANGED
|
@@ -1,54 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Sumba configuration object
|
|
3
|
-
*
|
|
4
|
-
* @typedef {object} TConfig
|
|
5
|
-
* @type {object}
|
|
6
|
-
* @property {object} [config={}] - Configuration object
|
|
7
|
-
* @property {object} [config.multiSite={}] - Multi-site configuration object
|
|
8
|
-
* @property {boolean} [config.multiSite.enabled=false] - Whether multi-site is enabled or not. Default: false
|
|
9
|
-
* @property {string} [config.multiSite.catchAll='default'] - Which site alias to use as the catch-all. Default: 'default'
|
|
10
|
-
* @property {array} [config.xSiteAdmins=[]] - List of cross-site administrators. Format: "<siteAlias>:<username>"
|
|
11
|
-
* @property {object} [config.waibu={}] - Waibu configuration object
|
|
12
|
-
* @property {string} [config.waibu.prefix='site'] - Waibu prefix
|
|
13
|
-
* @property {string} [config.waibu.title='site'] - Waibu title
|
|
14
|
-
* @property {object} [config.waibuMpa={}] - Waibu MPA configuration object
|
|
15
|
-
* @property {string} [config.waibuMpa.icon='globe'] - Waibu MPA icon. Default: 'globe'
|
|
16
|
-
* @property {object} [config.waibuMpa.redirect={}] - Waibu MPA route redirection
|
|
17
|
-
* @property {object} [config.waibuMpa.redirectSubRoute={}] - Waibu MPA sub-route redirection
|
|
18
|
-
* @property {array} [config.waibuMpa.menuHandler=[]] - Waibu MPA menu handler
|
|
19
|
-
* @property {object} [config.waibuAdmin={}] - Waibu Admin configuration object
|
|
20
|
-
* @property {string} [config.waibuAdmin.menuHandler='sumba:adminMenu'] - Waibu Admin menu handler. Default: 'sumba:adminMenu'
|
|
21
|
-
* @property {boolean} [config.waibuAdmin.menuCollapsible=true] - Whether the Waibu Admin menu is collapsible or not. Default: true
|
|
22
|
-
* @property {object} [config.auth={}] - Authentication configuration object
|
|
23
|
-
* @property {object} [config.auth.common={}] - Common authentication configuration object
|
|
24
|
-
* @property {object} [config.auth.common.apiKey={}] - API Key authentication configuration object
|
|
25
|
-
* @property {string} [config.auth.common.apiKey.type='Bearer'] - API Key authentication type. Default: 'Bearer'
|
|
26
|
-
* @property {string} [config.auth.common.apiKey.qsKey='apiKey'] - API Key authentication query string key. Default: 'apiKey'
|
|
27
|
-
* @property {string} [config.auth.common.apiKey.headerKey='X-Auth-ApiKey'] - API Key authentication header key. Default: 'X-Auth-ApiKey'
|
|
28
|
-
* @property {string} [config.auth.common.apiKey.algo='sha256'] - API Key authentication hashing algorithm. Default: 'sha256'
|
|
29
|
-
* @property {object} [config.auth.common.basic={}] - Basic authentication configuration object
|
|
30
|
-
* @property {object} [config.auth.common.jwt={}] - JWT authentication configuration object
|
|
31
|
-
* @property {string} [config.auth.common.jwt.type='Bearer'] - JWT authentication type. Default: 'Bearer'
|
|
32
|
-
* @property {string} [config.auth.common.jwt.qsKey='token'] - JWT authentication query string key. Default: 'token'
|
|
33
|
-
* @property {string} [config.auth.common.jwt.headerKey='X-Auth-Jwt'] - JWT authentication header key. Default: 'X-Auth-Jwt'
|
|
34
|
-
* @property {string} [config.auth.common.jwt.secret] - JWT authentication secret. Default: hard coded value, should be changed in production
|
|
35
|
-
* @property {string} [config.auth.common.jwt.expiresInDur='7d'] - JWT authentication token expiration duration. Default: '7d'
|
|
36
|
-
* @property {object} [config.auth.waibuRestApi={}] - Waibu REST API authentication configuration object
|
|
37
|
-
* @property {array} [config.auth.waibuRestApi.methods=['basic', 'apiKey', 'jwt']] - Waibu REST API authentication methods. Default: ['basic', 'apiKey', 'jwt']
|
|
38
|
-
* @property {boolean} [config.auth.waibuRestApi.silentOnError=false] - Whether to silently ignore authentication errors or not. Default: false
|
|
39
|
-
* @property {object} [config.auth.waibuMpa={}] - Waibu MPA authentication configuration object
|
|
40
|
-
* @property {array} [config.auth.waibuMpa.methods=['session']] - Waibu MPA authentication methods. Default: ['session']
|
|
41
|
-
* @property {boolean} [config.auth.waibuMpa.silentOnError=false] - Whether to silently ignore authentication errors or not. Default: false
|
|
42
|
-
* @property {object} [config.auth.waibuStatic={}] - Waibu Static authentication configuration object
|
|
43
|
-
* @property {array} [config.auth.waibuStatic.methods=['basic', 'apiKey', 'jwt']]
|
|
44
|
-
* @property {object} [config.auth.waibuStatic.basic={}] - Waibu Static Basic authentication configuration object
|
|
45
|
-
* @property {boolean} [config.auth.waibuStatic.basic.useUtf8=true] - Whether to use UTF-8 encoding for Basic authentication or not. Default: true
|
|
46
|
-
* @property {boolean} [config.auth.waibuStatic.basic.realm=true] - Whether to use realm for Basic authentication or not. Default: true
|
|
47
|
-
* @property {string} [config.auth.waibuStatic.basic.warningMessage='pleaseAuthenticate'] - Warning message for Basic authentication. Default: 'pleaseAuthenticate'
|
|
48
|
-
* @property {boolean} [config.auth.waibuStatic.silentOnError=false] - Whether to silently ignore authentication errors or not. Default: false
|
|
49
|
-
* @property {object} [config.redirect={}] - Redirection configuration object
|
|
50
|
-
*/
|
|
51
|
-
|
|
52
1
|
/**
|
|
53
2
|
* @typedef {object} TTokenData
|
|
54
3
|
* @type {object}
|
package/package.json
CHANGED
package/wiki/CHANGES.md
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
# Changes
|
|
2
2
|
|
|
3
|
-
## 2026-
|
|
3
|
+
## 2026-07-12
|
|
4
|
+
|
|
5
|
+
- [2.37.0] Update `driver` to `adapter`
|
|
6
|
+
|
|
7
|
+
## 2026-06-29
|
|
8
|
+
|
|
9
|
+
- [2.36.0] Move ```config``` object to dedicated file ```lib/config.js```
|
|
10
|
+
- [2.36.0] Changes in ```_getAuthSetting()```
|
|
11
|
+
- [2.36.0] Bug fix in ```runQueryGuard()```
|
|
12
|
+
|
|
13
|
+
## 2026-06-29
|
|
4
14
|
|
|
5
15
|
- [2.35.0] Add ```SumbaActionGuard``` model & its helpers
|
|
6
16
|
- [2.35.0] Restructure admin menu
|