sumba 2.0.0 → 2.0.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.
Files changed (82) hide show
  1. package/.github/FUNDING.yml +13 -0
  2. package/.github/workflows/repo-lockdown.yml +24 -0
  3. package/.jsdoc.conf.json +45 -0
  4. package/LICENSE +1 -1
  5. package/README.md +40 -7
  6. package/docs/Sumba.html +3 -0
  7. package/docs/data/search.json +1 -0
  8. package/docs/fonts/Inconsolata-Regular.ttf +0 -0
  9. package/docs/fonts/OpenSans-Regular.ttf +0 -0
  10. package/docs/fonts/WorkSans-Bold.ttf +0 -0
  11. package/docs/global.html +3 -0
  12. package/docs/index.html +3 -0
  13. package/docs/index.js.html +526 -0
  14. package/docs/scripts/core.js +726 -0
  15. package/docs/scripts/core.min.js +23 -0
  16. package/docs/scripts/resize.js +90 -0
  17. package/docs/scripts/search.js +265 -0
  18. package/docs/scripts/search.min.js +6 -0
  19. package/docs/scripts/third-party/Apache-License-2.0.txt +202 -0
  20. package/docs/scripts/third-party/fuse.js +9 -0
  21. package/docs/scripts/third-party/hljs-line-num-original.js +369 -0
  22. package/docs/scripts/third-party/hljs-line-num.js +1 -0
  23. package/docs/scripts/third-party/hljs-original.js +5171 -0
  24. package/docs/scripts/third-party/hljs.js +1 -0
  25. package/docs/scripts/third-party/popper.js +5 -0
  26. package/docs/scripts/third-party/tippy.js +1 -0
  27. package/docs/scripts/third-party/tocbot.js +672 -0
  28. package/docs/scripts/third-party/tocbot.min.js +1 -0
  29. package/docs/static/bitcoin.jpeg +0 -0
  30. package/docs/static/home.md +25 -0
  31. package/docs/static/logo-ecosystem.png +0 -0
  32. package/docs/static/logo.png +0 -0
  33. package/docs/styles/clean-jsdoc-theme-base.css +1159 -0
  34. package/docs/styles/clean-jsdoc-theme-dark.css +412 -0
  35. package/docs/styles/clean-jsdoc-theme-light.css +482 -0
  36. package/docs/styles/clean-jsdoc-theme-scrollbar.css +30 -0
  37. package/docs/styles/clean-jsdoc-theme-without-scrollbar.min.css +1 -0
  38. package/docs/styles/clean-jsdoc-theme.min.css +1 -0
  39. package/extend/bajo/hook/dobo.sumba-contact-form@after-record-create.js +1 -1
  40. package/extend/bajo/hook/dobo.sumba-contact-form@before-record-create.js +1 -1
  41. package/extend/bajo/hook/dobo.sumba-user@after-record-create.js +1 -1
  42. package/extend/bajo/hook/dobo.sumba-user@after-record-update.js +3 -3
  43. package/extend/bajo/hook/dobo.sumba-user@after-record-validation.js +1 -1
  44. package/extend/bajo/hook/dobo.sumba-user@before-record-validation.js +1 -1
  45. package/extend/bajo/hook/dobo@before-record-create.js +1 -1
  46. package/extend/bajo/hook/dobo@before-record-find.js +1 -1
  47. package/extend/bajo/hook/waibu@after-app-boot.js +2 -2
  48. package/extend/dobo/feature/lat-lng.js +1 -1
  49. package/extend/dobo/feature/slug.js +2 -2
  50. package/extend/dobo/feature/status.js +1 -1
  51. package/extend/dobo/feature/url.js +1 -1
  52. package/extend/masohiSocketIo/middleware/server/auth.js +1 -1
  53. package/extend/waibuBootstrap/theme/component/factory/nav-dropdown-user.js +1 -1
  54. package/extend/waibuMpa/extend/waibuAdmin/route/reset-user-password.js +2 -2
  55. package/extend/waibuMpa/route/help/contact-form.js +2 -2
  56. package/extend/waibuMpa/route/help/trouble-tickets/add.js +1 -1
  57. package/extend/waibuMpa/route/help/trouble-tickets/details/@id.js +1 -1
  58. package/extend/waibuMpa/route/signout.js +2 -2
  59. package/extend/waibuMpa/route/user/activation.js +1 -1
  60. package/extend/waibuMpa/route/user/forgot-password/@fpl.js +5 -5
  61. package/extend/waibuMpa/route/user/forgot-password.js +3 -3
  62. package/extend/waibuMpa/route/user/signup.js +1 -1
  63. package/extend/waibuMpa/route/your-stuff/change-password.js +2 -2
  64. package/extend/waibuMpa/route/your-stuff/profile/edit.js +2 -2
  65. package/extend/waibuMpa/route/your-stuff/reset-api-key.js +2 -2
  66. package/extend/waibuRestApi/route/your-stuff/profile/update.js +1 -1
  67. package/extend/waibuSocketIo/middleware/server/auth.js +1 -1
  68. package/index.js +43 -28
  69. package/lib/check-iconset.js +1 -1
  70. package/lib/check-team.js +1 -1
  71. package/lib/check-theme.js +1 -1
  72. package/lib/check-user-id.js +3 -3
  73. package/lib/collect-routes.js +4 -4
  74. package/lib/collect-team.js +3 -3
  75. package/lib/lat-lng-hook.js +2 -2
  76. package/package.json +39 -34
  77. package/wiki/CONFIG.md +2 -0
  78. package/wiki/CONTRIBUTING.md +5 -0
  79. package/wiki/DEV-GUIDE.md +1 -0
  80. package/wiki/ECOSYSTEM.md +28 -0
  81. package/wiki/GETTING-STARTED.md +1 -0
  82. package/wiki/USER-GUIDE.md +1 -0
@@ -3,7 +3,7 @@ import collectTeam from '../../../lib/collect-team.js'
3
3
 
4
4
  async function afterAppBoot () {
5
5
  const { runHook } = this.app.bajo
6
- await runHook(`${this.name}:beforeBoot`)
6
+ await runHook(`${this.ns}:beforeBoot`)
7
7
  this.log.trace('collectingRouteGuards')
8
8
  await collectRoutes.call(this, 'secure')
9
9
  this.log.trace('secureRoutes%d', this.secureRoutes.length)
@@ -15,7 +15,7 @@ async function afterAppBoot () {
15
15
  await collectTeam.call(this)
16
16
  this.log.trace('teamRoutes%d', this.teamRoutes.length)
17
17
  this.log.trace('teamNegRoutes%d', this.teamNegRoutes.length)
18
- await runHook(`${this.name}:afterBoot`)
18
+ await runHook(`${this.ns}:afterBoot`)
19
19
  }
20
20
 
21
21
  export default afterAppBoot
@@ -1,7 +1,7 @@
1
1
  import latLngHook from '../../../lib/lat-lng-hook.js'
2
2
 
3
3
  async function latLng (opts = {}) {
4
- const { merge } = this.lib._
4
+ const { merge } = this.app.lib._
5
5
  opts.fieldNameLat = opts.fieldNameLat ?? 'lat'
6
6
  opts.fieldNameLng = opts.fieldNameLng ?? 'lng'
7
7
  opts.scale = opts.scale ?? 5
@@ -2,7 +2,7 @@ import slug from 'slug'
2
2
 
3
3
  async function autoInc ({ schema, body, opts }) {
4
4
  const { recordFind } = this.app.dobo
5
- const { set, last } = this.lib._
5
+ const { set, last } = this.app.lib._
6
6
  const query = set({}, opts.fieldName, { $regex: new RegExp('^' + body[opts.fieldName]) })
7
7
  const sort = set({}, opts.fieldName, -1)
8
8
  const options = { noHook: true, skipCache: true, thrownNotFound: false }
@@ -40,7 +40,7 @@ async function mainFn (opts = {}) {
40
40
  hook: {
41
41
  beforeCreate: async function ({ schema, body }) {
42
42
  const { error } = this.app.bajo
43
- const { isEmpty, isString } = this.lib._
43
+ const { isEmpty, isString } = this.app.lib._
44
44
  if (isEmpty(body[opts.fieldName])) {
45
45
  if (isString(opts.fieldSource)) opts.fieldSource = [opts.fieldSource]
46
46
  const source = []
@@ -10,7 +10,7 @@ async function status (opts = {}) {
10
10
  }],
11
11
  hook: {
12
12
  beforeCreate: async function ({ body }) {
13
- const { isSet } = this.lib.aneka
13
+ const { isSet } = this.app.lib.aneka
14
14
  if (!isSet(body[opts.fieldName])) body[opts.fieldName] = opts.default
15
15
  }
16
16
  }
@@ -1,5 +1,5 @@
1
1
  async function hook (schema, body, options) {
2
- const { isSet } = this.lib.aneka
2
+ const { isSet } = this.app.lib.aneka
3
3
  let val = body[options.fieldName]
4
4
  if (!isSet(val)) return
5
5
  const [, ...params] = val.split('://')
@@ -1,7 +1,7 @@
1
1
  const auth = {
2
2
  level: 5,
3
3
  handler: async function (socket) {
4
- const { camelCase } = this.lib._
4
+ const { camelCase } = this.app.lib._
5
5
  const { req } = socket
6
6
  const { session } = req
7
7
  const site = await this.getSite(session.siteId)
@@ -1,7 +1,7 @@
1
1
  async function navDropdownUser () {
2
2
  return class NavDropdownUser extends this.baseFactory {
3
3
  build = async () => {
4
- const { has, omit, find, filter } = this.plugin.lib._
4
+ const { has, omit, find, filter } = this.app.lib._
5
5
  const { routePath } = this.plugin.app.waibu
6
6
  const { req } = this.component
7
7
  const icon = this.component.req.iconset ? await this.component.buildTag({ tag: 'icon', attr: { name: 'person' } }) : ''
@@ -6,7 +6,7 @@ const resetUserPassword = {
6
6
  handler: async function (req, reply) {
7
7
  const { importPkg } = this.app.bajo
8
8
  const { recordFindOne, recordUpdate } = this.app.dobo
9
- const { defaultsDeep } = this.lib.aneka
9
+ const { defaultsDeep } = this.app.lib.aneka
10
10
  const Joi = await importPkg('dobo:joi')
11
11
  const model = 'SumbaUser'
12
12
  const form = defaultsDeep(req.body, { username: req.query.username })
@@ -22,7 +22,7 @@ const resetUserPassword = {
22
22
  try {
23
23
  await schema.validateAsync(req.body, this.app.dobo.config.validationParams)
24
24
  } catch (err) {
25
- throw this.error('validationError', { details: err.details, values: err.values, ns: this.name, statusCode: 422, code: 'DB_VALIDATION' })
25
+ throw this.error('validationError', { details: err.details, values: err.values, ns: this.ns, statusCode: 422, code: 'DB_VALIDATION' })
26
26
  }
27
27
  const rec = await recordFindOne(model, { query: { username: req.body.username } })
28
28
  if (!rec) throw this.error('unknownUser', { details: [{ field: 'username', error: 'unknownUser' }], statusCode: 400 })
@@ -1,8 +1,8 @@
1
1
  const contactForm = {
2
2
  method: ['GET', 'POST'],
3
3
  handler: async function (req, reply) {
4
- const { defaultsDeep } = this.lib.aneka
5
- const { pick } = this.lib._
4
+ const { defaultsDeep } = this.app.lib.aneka
5
+ const { pick } = this.app.lib._
6
6
  const { recordCreate, recordFind } = this.app.waibuDb
7
7
 
8
8
  const def = req.user ? pick(req.user, ['firstName', 'lastName', 'email']) : {}
@@ -3,7 +3,7 @@ const model = 'SumbaTicket'
3
3
  const add = {
4
4
  method: ['GET', 'POST'],
5
5
  handler: async function (req, reply) {
6
- const { defaultsDeep } = this.lib.aneka
6
+ const { defaultsDeep } = this.app.lib.aneka
7
7
  const { recordCreate, recordFind } = this.app.waibuDb
8
8
  const options = {}
9
9
  const form = defaultsDeep(req.body, {})
@@ -3,7 +3,7 @@ const model = 'SumbaTicketDetail'
3
3
  const id = {
4
4
  method: ['GET', 'POST'],
5
5
  handler: async function (req, reply) {
6
- const { cloneDeep } = this.lib._
6
+ const { cloneDeep } = this.app.lib._
7
7
  const { recordCreate, recordFind, getSchemaExt } = this.app.waibuDb
8
8
  const { schema } = await getSchemaExt(model, 'list')
9
9
 
@@ -2,7 +2,7 @@ const signout = {
2
2
  method: ['GET', 'POST'],
3
3
  handler: async function (req, reply) {
4
4
  const { runHook } = this.app.bajo
5
- // const { isEmpty } = this.lib._
5
+ // const { isEmpty } = this.app.lib._
6
6
  const { getSessionId } = this.app.waibuMpa
7
7
 
8
8
  let { referer } = req.body || {}
@@ -11,7 +11,7 @@ const signout = {
11
11
  if (req.method === 'POST') {
12
12
  const sid = await getSessionId(req.headers.cookie)
13
13
  req.session.userId = null
14
- await runHook(`${this.name}:afterSignout`, sid, req)
14
+ await runHook(`${this.ns}:afterSignout`, sid, req)
15
15
  const { query, params } = req
16
16
  // const url = !isEmpty(referer) ? referer : this.config.redirect.home
17
17
  const url = this.config.redirect.afterSignout
@@ -3,7 +3,7 @@ const model = 'SumbaUser'
3
3
  const userActivation = {
4
4
  method: ['GET', 'POST'],
5
5
  handler: async function (req, reply) {
6
- const { defaultsDeep } = this.lib.aneka
6
+ const { defaultsDeep } = this.app.lib.aneka
7
7
  const { recordFind, recordUpdate } = this.app.dobo
8
8
  const form = defaultsDeep(req.body, { key: req.query.key })
9
9
  let error
@@ -2,7 +2,7 @@ import passwordRule from '../../../../../lib/password-rule.js'
2
2
  const model = 'SumbaUser'
3
3
 
4
4
  async function getUser (req, reply) {
5
- const { dayjs } = this.lib
5
+ const { dayjs } = this.app.lib
6
6
  const { recordFind } = this.app.waibuDb
7
7
  const invalidFpl = 'sumba.template:/user/fpl-invalid.html'
8
8
  if (Buffer.from(req.params.fpl, 'base64').toString('base64') !== req.params.fpl) return invalidFpl
@@ -19,9 +19,9 @@ const forgotPasswordLink = {
19
19
  method: ['GET', 'POST'],
20
20
  handler: async function (req, reply) {
21
21
  const { sendMail } = this.app.waibu
22
- const { defaultsDeep } = this.lib.aneka
22
+ const { defaultsDeep } = this.app.lib.aneka
23
23
  const { importPkg } = this.app.bajo
24
- const { isString } = this.lib._
24
+ const { isString } = this.app.lib._
25
25
  const { recordUpdate } = this.app.dobo
26
26
  const Joi = await importPkg('dobo:joi')
27
27
 
@@ -40,7 +40,7 @@ const forgotPasswordLink = {
40
40
  try {
41
41
  await schema.validateAsync(req.body, this.app.dobo.config.validationParams)
42
42
  } catch (err) {
43
- throw this.error('validationError', { details: err.details, values: err.values, ns: this.name, statusCode: 422, code: 'DB_VALIDATION' })
43
+ throw this.error('validationError', { details: err.details, values: err.values, ns: this.ns, statusCode: 422, code: 'DB_VALIDATION' })
44
44
  }
45
45
  await recordUpdate(model, user.id, { password: req.body.newPassword }, { noFlash: true })
46
46
  const to = `${user.firstName} ${user.lastName} <${user.email}>`
@@ -48,7 +48,7 @@ const forgotPasswordLink = {
48
48
  const options = { req, reply, tpl: '' }
49
49
  await sendMail(
50
50
  'sumba.template:/_mail/user-forgot-password-changed.html',
51
- { to, subject, data: user, options, source: this.name }
51
+ { to, subject, data: user, options, source: this.ns }
52
52
  )
53
53
  req.flash('notify', req.t('passwordChangedReSignin'))
54
54
  return reply.redirectTo(this.config.redirect.signin)
@@ -5,8 +5,8 @@ const profile = {
5
5
  handler: async function (req, reply) {
6
6
  if (!this.app.masohiMail) return await reply.view('sumba.template:/user/forgot-password.html')
7
7
  const { sendMail } = this.app.waibu
8
- const { defaultsDeep } = this.lib.aneka
9
- const { dayjs } = this.lib
8
+ const { defaultsDeep } = this.app.lib.aneka
9
+ const { dayjs } = this.app.lib
10
10
  const { recordFind } = this.app.dobo
11
11
  const form = defaultsDeep(req.body, {})
12
12
  let error
@@ -24,7 +24,7 @@ const profile = {
24
24
  data._meta = { hostHeader: req.headers.host }
25
25
  await sendMail(
26
26
  'sumba.template:/_mail/user-forgot-password-link.html',
27
- { to, subject, data, options, source: this.name }
27
+ { to, subject, data, options, source: this.ns }
28
28
  )
29
29
  req.flash('notify', req.t('emailSent'))
30
30
  return reply.redirectTo(this.config.redirect.signin)
@@ -1,7 +1,7 @@
1
1
  const signup = {
2
2
  method: ['GET', 'POST'],
3
3
  handler: async function (req, reply) {
4
- const { defaultsDeep } = this.lib.aneka
4
+ const { defaultsDeep } = this.app.lib.aneka
5
5
  const { generateId } = this.app.bajo
6
6
  const { recordCreate } = this.app.waibuDb
7
7
 
@@ -3,7 +3,7 @@ import passwordRule from '../../../../lib/password-rule.js'
3
3
  const profile = {
4
4
  method: ['GET', 'POST'],
5
5
  handler: async function (req, reply) {
6
- const { defaultsDeep } = this.lib.aneka
6
+ const { defaultsDeep } = this.app.lib.aneka
7
7
  const { importPkg } = this.app.bajo
8
8
  const { recordGet, recordUpdate } = this.app.dobo
9
9
  const bcrypt = await importPkg('bajoExtra:bcrypt')
@@ -22,7 +22,7 @@ const profile = {
22
22
  try {
23
23
  await schema.validateAsync(req.body, this.app.dobo.config.validationParams)
24
24
  } catch (err) {
25
- throw this.error('validationError', { details: err.details, values: err.values, ns: this.name, statusCode: 422, code: 'DB_VALIDATION' })
25
+ throw this.error('validationError', { details: err.details, values: err.values, ns: this.ns, statusCode: 422, code: 'DB_VALIDATION' })
26
26
  }
27
27
  const rec = await recordGet(model, req.user.id, { forceNoHidden: true })
28
28
  const verified = await bcrypt.compare(req.body.currentPassword, rec.password)
@@ -1,10 +1,10 @@
1
1
  const profile = {
2
2
  method: ['GET', 'POST'],
3
3
  handler: async function (req, reply) {
4
- const { defaultsDeep } = this.lib.aneka
4
+ const { defaultsDeep } = this.app.lib.aneka
5
5
  // const { attachmentCopyUploaded } = this.app.dobo
6
6
  const { recordUpdate, recordGet } = this.app.waibuDb
7
- const { omit, pick } = this.lib._
7
+ const { omit, pick } = this.app.lib._
8
8
  const { hash } = this.app.bajoExtra
9
9
  const resp = await recordGet({ model: 'SumbaUser', req, id: req.user.id, options: { forceNoHidden: true, noHook: true, noCache: true } })
10
10
  let form = defaultsDeep(req.body, omit(resp.data, ['password']))
@@ -3,7 +3,7 @@ const model = 'SumbaUser'
3
3
  const resetApiKey = {
4
4
  method: ['GET', 'POST'],
5
5
  handler: async function (req, reply) {
6
- const { defaultsDeep } = this.lib.aneka
6
+ const { defaultsDeep } = this.app.lib.aneka
7
7
  const { importPkg, generateId } = this.app.bajo
8
8
  const { recordGet, recordUpdate } = this.app.dobo
9
9
  const { hash } = this.app.bajoExtra
@@ -20,7 +20,7 @@ const resetApiKey = {
20
20
  try {
21
21
  await schema.validateAsync(req.body, this.app.dobo.config.validationParams)
22
22
  } catch (err) {
23
- throw this.error('validationError', { details: err.details, values: err.values, ns: this.name, statusCode: 422, code: 'DB_VALIDATION' })
23
+ throw this.error('validationError', { details: err.details, values: err.values, ns: this.ns, statusCode: 422, code: 'DB_VALIDATION' })
24
24
  }
25
25
  const rec = await recordGet(model, req.user.id, { forceNoHidden: true })
26
26
  const verified = await bcrypt.compare(req.body.password, rec.password)
@@ -3,7 +3,7 @@ const hidden = ['password', 'token', 'siteId']
3
3
 
4
4
  async function get ({ ctx }) {
5
5
  const { recordUpdate } = this.app.waibuDb
6
- const { omit } = this.lib._
6
+ const { omit } = this.app.lib._
7
7
 
8
8
  const { docSchemaModel } = this.app.waibuRestApi
9
9
  const schema = await docSchemaModel({ model, method: 'update', ctx, options: { hidden, noId: true } })
@@ -1,7 +1,7 @@
1
1
  export default {
2
2
  level: 1,
3
3
  handler: async function (socket) {
4
- const { merge } = this.lib._
4
+ const { merge } = this.app.lib._
5
5
  const { recordGet } = this.app.dobo
6
6
  const { getSessionId } = this.app.waibuMpa
7
7
 
package/index.js CHANGED
@@ -1,13 +1,25 @@
1
1
  import path from 'path'
2
2
 
3
+ /**
4
+ * Plugin factory
5
+ *
6
+ * @param {string} pkgName - NPM package name
7
+ * @returns {class}
8
+ */
3
9
  async function factory (pkgName) {
4
10
  const me = this
5
11
 
6
- return class Sumba extends this.lib.Plugin {
12
+ /**
13
+ * Sumba class
14
+ *
15
+ * @class
16
+ */
17
+ class Sumba extends this.app.pluginClass.base {
18
+ static alias = 'sumba'
19
+ static dependencies = ['bajo-extra', 'bajo-common-db', 'bajo-config']
20
+
7
21
  constructor () {
8
22
  super(pkgName, me.app)
9
- this.alias = 'sumba'
10
- this.dependencies = ['bajo-extra', 'bajo-common-db', 'bajo-config']
11
23
  this.config = {
12
24
  multiSite: false,
13
25
  waibu: {
@@ -119,8 +131,8 @@ async function factory (pkgName) {
119
131
 
120
132
  init = async () => {
121
133
  const { getPluginDataDir } = this.app.bajo
122
- this.downloadDir = `${getPluginDataDir(this.name)}/download`
123
- this.lib.fs.ensureDirSync(this.downloadDir)
134
+ this.downloadDir = `${getPluginDataDir(this.ns)}/download`
135
+ this.app.lib.fs.ensureDirSync(this.downloadDir)
124
136
  for (const type of ['secure', 'anonymous', 'team']) {
125
137
  this[`${type}Routes`] = this[`${type}Routes`] ?? []
126
138
  this[`${type}NegRoutes`] = this[`${type}NegRoutes`] ?? []
@@ -128,8 +140,8 @@ async function factory (pkgName) {
128
140
  }
129
141
 
130
142
  _getSetting = async (type, source) => {
131
- const { defaultsDeep } = this.lib.aneka
132
- const { get } = this.lib._
143
+ const { defaultsDeep } = this.app.lib.aneka
144
+ const { get } = this.app.lib._
133
145
 
134
146
  const setting = defaultsDeep(get(this.config, `auth.${source}.${type}`, {}), get(this.config, `auth.common.${type}`, {}))
135
147
  if (type === 'basic') setting.type = 'Basic'
@@ -137,7 +149,7 @@ async function factory (pkgName) {
137
149
  }
138
150
 
139
151
  _getToken = async (type, req, source) => {
140
- const { isEmpty } = this.lib._
152
+ const { isEmpty } = this.app.lib._
141
153
 
142
154
  const setting = await this._getSetting(type, source)
143
155
  let token = req.headers[setting.headerKey.toLowerCase()]
@@ -153,7 +165,7 @@ async function factory (pkgName) {
153
165
  adminMenu = async (locals, req) => {
154
166
  if (!this.app.waibuAdmin) return
155
167
  const { getPluginPrefix } = this.app.waibu
156
- const prefix = getPluginPrefix(this.name)
168
+ const prefix = getPluginPrefix(this.ns)
157
169
  return [{
158
170
  title: 'supportSystem',
159
171
  children: [
@@ -182,7 +194,7 @@ async function factory (pkgName) {
182
194
 
183
195
  getUser = async (rec, safe = true) => {
184
196
  const { recordGet } = this.app.dobo
185
- const { omit, isPlainObject } = this.lib._
197
+ const { omit, isPlainObject } = this.app.lib._
186
198
  let user
187
199
  if (isPlainObject(rec)) user = rec
188
200
  else user = await recordGet('SumbaUser', rec, { noHook: true })
@@ -191,7 +203,7 @@ async function factory (pkgName) {
191
203
 
192
204
  mergeTeam = async (user, site) => {
193
205
  if (!user) return
194
- const { map, pick } = this.lib._
206
+ const { map, pick } = this.app.lib._
195
207
  const { recordFindAll } = this.app.dobo
196
208
  user.teams = []
197
209
  const query = { userId: user.id, siteId: site.id }
@@ -222,9 +234,9 @@ async function factory (pkgName) {
222
234
 
223
235
  createJwtFromUserRecord = async (rec) => {
224
236
  const { importPkg } = this.app.bajo
225
- const { dayjs } = this.lib
237
+ const { dayjs } = this.app.lib
226
238
  const { hash } = this.app.bajoExtra
227
- const { get, pick } = this.lib._
239
+ const { get, pick } = this.app.lib._
228
240
 
229
241
  const fastJwt = await importPkg('bajoExtra:fast-jwt')
230
242
  const { createSigner } = fastJwt
@@ -254,7 +266,7 @@ async function factory (pkgName) {
254
266
  }
255
267
 
256
268
  verifyApiKey = async (req, reply, source, payload) => {
257
- const { merge } = this.lib._
269
+ const { merge } = this.app.lib._
258
270
  const { isMd5, hash } = this.app.bajoExtra
259
271
  const { getUser } = this
260
272
  const { recordFind } = this.app.dobo
@@ -273,10 +285,10 @@ async function factory (pkgName) {
273
285
  verifyBasic = async (req, reply, source, payload) => {
274
286
  const { getUserFromUsernamePassword } = this
275
287
  const { getUser } = this
276
- const { isEmpty, merge } = this.lib._
288
+ const { isEmpty, merge } = this.app.lib._
277
289
 
278
290
  const setHeader = async (setting, reply) => {
279
- const { isString } = this.lib._
291
+ const { isString } = this.app.lib._
280
292
 
281
293
  let header = setting.type
282
294
  const exts = []
@@ -316,7 +328,7 @@ async function factory (pkgName) {
316
328
  const { importPkg } = this.app.bajo
317
329
  const { recordGet } = this.app.dobo
318
330
  const { getUser } = this
319
- const { isEmpty, merge } = this.lib._
331
+ const { isEmpty, merge } = this.app.lib._
320
332
 
321
333
  const fastJwt = await importPkg('bajoExtra:fast-jwt')
322
334
  const { createVerifier } = fastJwt
@@ -342,8 +354,8 @@ async function factory (pkgName) {
342
354
  }
343
355
 
344
356
  checkPathsByTeam = ({ paths = [], method = 'GET', teams = [], guards = [] }) => {
345
- const { includes } = this.lib.aneka
346
- const { outmatch } = this.lib
357
+ const { includes } = this.app.lib.aneka
358
+ const { outmatch } = this.app.lib
347
359
 
348
360
  for (const item of guards) {
349
361
  const matchPath = outmatch(item.path)
@@ -360,7 +372,7 @@ async function factory (pkgName) {
360
372
  }
361
373
 
362
374
  checkPathsByRoute = ({ paths = [], method = 'GET', guards = [] }) => {
363
- const { outmatch } = this.lib
375
+ const { outmatch } = this.app.lib
364
376
 
365
377
  for (const item of guards) {
366
378
  const matchPath = outmatch(item.path)
@@ -374,7 +386,7 @@ async function factory (pkgName) {
374
386
  }
375
387
 
376
388
  checkPathsByGuard = ({ guards, paths }) => {
377
- const { outmatch } = this.lib
389
+ const { outmatch } = this.app.lib
378
390
  const matcher = outmatch(guards)
379
391
  let guarded
380
392
  for (const path of paths) {
@@ -384,23 +396,24 @@ async function factory (pkgName) {
384
396
  }
385
397
 
386
398
  getSite = async (hostname, useId) => {
387
- const { omit } = this.lib._
399
+ const { omit } = this.app.lib._
388
400
  const { recordFind } = this.app.dobo
389
401
  const omitted = ['status']
390
402
 
391
403
  const mergeSetting = async (site) => {
392
- const { defaultsDeep } = this.lib.aneka
404
+ const { defaultsDeep } = this.app.lib.aneka
393
405
  const { parseObject } = this.app.bajo
394
- const { trim, get, filter } = this.lib._
406
+ const { trim, get, filter } = this.app.lib._
395
407
  const { recordFind, recordGet } = this.app.dobo
396
408
  const defSetting = {}
397
409
  const nsSetting = {}
410
+ const names = this.app.getAllNs()
398
411
  const query = {
399
- ns: { $in: this.app.bajo.pluginNames },
412
+ ns: { $in: names },
400
413
  siteId: site.id
401
414
  }
402
415
  const all = await recordFind('SumbaSiteSetting', { query, limit: -1 })
403
- for (const ns of this.app.bajo.pluginNames) {
416
+ for (const ns of names) {
404
417
  nsSetting[ns] = {}
405
418
  defSetting[ns] = get(this, `app.${ns}.config.siteSetting`, {})
406
419
  const items = filter(all, { ns })
@@ -449,14 +462,14 @@ async function factory (pkgName) {
449
462
  signin = async ({ user, req, reply }) => {
450
463
  const { getSessionId } = this.app.waibuMpa
451
464
  const { runHook } = this.app.bajo
452
- const { isEmpty, omit } = this.lib._
465
+ const { isEmpty, omit } = this.app.lib._
453
466
  let { referer } = req.body || {}
454
467
  if (req.session.ref) referer = req.session.ref
455
468
  req.session.ref = null
456
469
  const _user = omit(user, ['password', 'token'])
457
470
  req.session.userId = _user.id
458
471
  const sid = await getSessionId(req.headers.cookie)
459
- await runHook(`${this.name}:afterSignin`, _user, sid, req)
472
+ await runHook(`${this.ns}:afterSignin`, _user, sid, req)
460
473
  const { query, params } = req
461
474
  const url = !isEmpty(referer) ? referer : this.config.redirect.afterSignin
462
475
  req.flash('notify', req.t('signinSuccessfully'))
@@ -503,6 +516,8 @@ async function factory (pkgName) {
503
516
  return await hash(resp.salt)
504
517
  }
505
518
  }
519
+
520
+ return Sumba
506
521
  }
507
522
 
508
523
  export default factory
@@ -1,5 +1,5 @@
1
1
  async function checkIconset (req, reply) {
2
- const { get } = this.lib._
2
+ const { get } = this.app.lib._
3
3
  const mpa = this.app.waibuMpa
4
4
 
5
5
  if (!req.site) return
package/lib/check-team.js CHANGED
@@ -2,7 +2,7 @@ import { pathsToCheck } from './check-user-id.js'
2
2
 
3
3
  async function checkTeam (req, reply, source) {
4
4
  if (!req.user) return
5
- const { map } = this.lib._
5
+ const { map } = this.app.lib._
6
6
  await this.mergeTeam(req.user, req.site)
7
7
  const paths = pathsToCheck.call(this, req, true)
8
8
  const teams = map(req.user.teams, 'alias')
@@ -1,5 +1,5 @@
1
1
  async function checkTheme (req, reply) {
2
- const { get } = this.lib._
2
+ const { get } = this.app.lib._
3
3
  const mpa = this.app.waibuMpa
4
4
 
5
5
  if (!req.site) return
@@ -1,10 +1,10 @@
1
1
  export function pathsToCheck (req, withHome) {
2
- const { uniq, without } = this.lib._
2
+ const { uniq, without } = this.app.lib._
3
3
  return uniq(without([req.routeOptions.url, req.url], undefined, null))
4
4
  }
5
5
 
6
6
  async function setUser (req) {
7
- const { get } = this.lib._
7
+ const { get } = this.app.lib._
8
8
  const id = get(req, 'session.userId')
9
9
  if (!id) return
10
10
  try {
@@ -17,7 +17,7 @@ async function setUser (req) {
17
17
  }
18
18
 
19
19
  async function checkUserId (req, reply, source) {
20
- const { merge, isEmpty, camelCase, get } = this.lib._
20
+ const { merge, isEmpty, camelCase, get } = this.app.lib._
21
21
  const { routePath } = this.app.waibu
22
22
  const userId = get(req, 'session.userId')
23
23
  if (req.session) req.session.siteId = req.site.id
@@ -1,7 +1,7 @@
1
1
  export async function collect ({ type = '', handler, container, file, ns, dir }) {
2
2
  const { readConfig } = this.app.bajo
3
3
  const { routePath, routePathHandlers } = this.app.waibu
4
- const { camelCase, find, isString, isEmpty } = this.lib._
4
+ const { camelCase, find, isString, isEmpty } = this.app.lib._
5
5
  let items = await readConfig(file, { ignoreError: true })
6
6
  if (isEmpty(items)) items = []
7
7
 
@@ -24,7 +24,7 @@ export async function collect ({ type = '', handler, container, file, ns, dir })
24
24
  }
25
25
 
26
26
  function handler (item) {
27
- const { isString } = this.lib._
27
+ const { isString } = this.app.lib._
28
28
  for (const k of ['methods']) {
29
29
  item[k] = item[k] ?? []
30
30
  if (isString(item[k])) item[k] = item[k].split(',')
@@ -35,9 +35,9 @@ async function collectRoutes (type) {
35
35
  const { eachPlugins } = this.app.bajo
36
36
  const me = this
37
37
  await eachPlugins(async function ({ file, dir }) {
38
- const { name: ns } = this
38
+ const { ns } = this
39
39
  await collect.call(me, { type, container: 'Routes', handler, file, ns, dir })
40
- }, { glob: `route/${type}.*`, prefix: this.name })
40
+ }, { glob: `route/${type}.*`, prefix: this.ns })
41
41
  }
42
42
 
43
43
  export default collectRoutes
@@ -1,7 +1,7 @@
1
1
  import { collect } from './collect-routes.js'
2
2
 
3
3
  function handler (item) {
4
- const { isString } = this.lib._
4
+ const { isString } = this.app.lib._
5
5
  for (const k of ['methods', 'teams', 'features']) {
6
6
  item[k] = item[k] ?? []
7
7
  if (isString(item[k])) item[k] = item[k].split(',')
@@ -12,9 +12,9 @@ async function collectTeam () {
12
12
  const { eachPlugins } = this.app.bajo
13
13
  const me = this
14
14
  await eachPlugins(async function ({ file, dir }) {
15
- const { name: ns } = this
15
+ const { ns } = this
16
16
  await collect.call(me, { type: 'team', container: 'Routes', handler, file, ns, dir })
17
- }, { glob: 'route/team.*', prefix: this.name })
17
+ }, { glob: 'route/team.*', prefix: this.ns })
18
18
  }
19
19
 
20
20
  export default collectTeam
@@ -1,6 +1,6 @@
1
1
  async function hook (body, options) {
2
- const { isSet } = this.lib.aneka
3
- const { round } = this.lib.aneka
2
+ const { isSet } = this.app.lib.aneka
3
+ const { round } = this.app.lib.aneka
4
4
  if (!isSet(body[options.fieldName])) return
5
5
  body[options.fieldName] = round(body[options.fieldName], options.scale)
6
6
  }