sumba 1.1.7 → 1.1.8

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.
@@ -1,7 +1,7 @@
1
1
  const doboBeforeRecordCreate = {
2
2
  level: 1000,
3
3
  handler: async function (body, options = {}) {
4
- const { get, isEmpty } = this.app.bajo.lib._
4
+ const { get, isEmpty } = this.lib._
5
5
  const user = get(options, 'req.user')
6
6
  if (user) {
7
7
  if (isEmpty(body.firstName)) body.firstName = user.firstName
@@ -1,6 +1,6 @@
1
1
  async function doboSumbaUserAfterRecordValidation (body, options) {
2
2
  const { isBcrypt, hash } = this.app.bajoExtra
3
- const { has } = this.app.bajo.lib._
3
+ const { has } = this.lib._
4
4
 
5
5
  if (has(body, 'password') && !isBcrypt(body.password)) body.password = await hash(body.password, 'bcrypt')
6
6
  // if (has(body, 'token') && !isMd5(body.token)) body.token = await hash(body.token)
@@ -1,7 +1,7 @@
1
1
  import passwordRule from '../../lib/password-rule.js'
2
2
 
3
3
  async function doboSumbaUserBeforeRecordValidation (body, options = {}) {
4
- const { set } = this.app.bajo.lib._
4
+ const { set } = this.lib._
5
5
  const password = await passwordRule.call(this, options.req)
6
6
  const rule = { password }
7
7
  set(options, 'validation.params.rule', rule)
@@ -1,7 +1,7 @@
1
1
  const doboBeforeRecordCreate = {
2
2
  level: 1000,
3
3
  handler: async function (model, body, options = {}) {
4
- const { get } = this.app.bajo.lib._
4
+ const { get } = this.lib._
5
5
  const { hasColumn } = this
6
6
  const { req } = options
7
7
 
@@ -1,7 +1,7 @@
1
1
  const useAdmin = ['waibuAdmin']
2
2
 
3
3
  export async function rebuildFilter (model, filter, req) {
4
- const { isEmpty, map, find, get } = this.app.bajo.lib._
4
+ const { isEmpty, map, find, get } = this.lib._
5
5
  const { hasColumn } = this
6
6
  filter.query = filter.query ?? {}
7
7
  const hasSiteId = await hasColumn('siteId', model)
@@ -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.app.bajo.lib._
4
+ const { merge } = this.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.app.bajo.lib._
5
+ const { set, last } = this.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.app.bajo.lib._
43
+ const { isEmpty, isString } = this.lib._
44
44
  if (isEmpty(body[opts.fieldName])) {
45
45
  if (isString(opts.fieldSource)) opts.fieldSource = [opts.fieldSource]
46
46
  const source = []
@@ -1,5 +1,5 @@
1
1
  async function checkIconset (req, reply) {
2
- const { get } = this.app.bajo.lib._
2
+ const { get } = this.lib._
3
3
 
4
4
  if (!req.site) return
5
5
  const globalIconset = get(this.app, 'waibuMpa.config.iconset.default')
@@ -1,6 +1,6 @@
1
1
  async function mergeSetting (req) {
2
2
  const { defaultsDeep, parseObject } = this.app.bajo
3
- const { trim, get, filter } = this.app.bajo.lib._
3
+ const { trim, get, filter } = this.lib._
4
4
  const { recordFind, recordGet } = this.app.dobo
5
5
  const defSetting = {}
6
6
  const nsSetting = {}
@@ -30,7 +30,7 @@ async function mergeSetting (req) {
30
30
  const omitted = ['status']
31
31
 
32
32
  async function checkSiteId (req, reply) {
33
- const { omit } = this.app.bajo.lib._
33
+ const { omit } = this.lib._
34
34
  const { recordFind } = this.app.dobo
35
35
 
36
36
  if (!this.config.multiSite) {
package/lib/check-team.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { pathsToCheck } from './check-user-id.js'
2
2
 
3
3
  async function mergeTeam (req) {
4
- const { map, pick } = this.app.bajo.lib._
4
+ const { map, pick } = this.lib._
5
5
  const { recordFindAll } = this.app.dobo
6
6
  req.user.teams = []
7
7
  const query = { userId: req.user.id, siteId: req.site.id }
@@ -15,7 +15,7 @@ async function mergeTeam (req) {
15
15
 
16
16
  async function checkTeam (req, reply, source) {
17
17
  if (!req.user) return
18
- const { map } = this.app.bajo.lib._
18
+ const { map } = this.lib._
19
19
  await mergeTeam.call(this, req)
20
20
  const paths = pathsToCheck.call(this, req, true)
21
21
  const teams = map(req.user.teams, 'alias')
@@ -1,5 +1,5 @@
1
1
  async function checkTheme (req, reply) {
2
- const { get } = this.app.bajo.lib._
2
+ const { get } = this.lib._
3
3
 
4
4
  if (!req.site) return
5
5
  const globalTheme = get(this.app, 'waibuMpa.config.theme.default')
@@ -1,5 +1,5 @@
1
1
  export function pathsToCheck (req, withHome) {
2
- const { uniq, without } = this.app.bajo.lib._
2
+ const { uniq, without } = this.lib._
3
3
  const checks = uniq(without([req.routeOptions.url, req.url], undefined, null))
4
4
  /*
5
5
  if (withHome) {
@@ -12,7 +12,7 @@ export function pathsToCheck (req, withHome) {
12
12
  }
13
13
 
14
14
  async function setUser (req) {
15
- const { get } = this.app.bajo.lib._
15
+ const { get } = this.lib._
16
16
  const id = get(req, 'session.user.id')
17
17
  if (!id) return
18
18
  try {
@@ -29,7 +29,7 @@ async function mergeSetting (req) {
29
29
  }
30
30
 
31
31
  async function checkUserId (req, reply, source) {
32
- const { isEmpty, camelCase, get } = this.app.bajo.lib._
32
+ const { isEmpty, camelCase, get } = this.lib._
33
33
  const { routePath } = this.app.waibu
34
34
 
35
35
  const webApp = get(req, 'routeOptions.config.webApp', 'waibu')
@@ -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.app.bajo.lib._
4
+ const { camelCase, find, isString, isEmpty } = this.lib._
5
5
  const items = await readConfig(file, { ignoreError: true })
6
6
 
7
7
  for (let item of items) {
@@ -23,7 +23,7 @@ export async function collect ({ type = '', handler, container, file, ns, dir })
23
23
  }
24
24
 
25
25
  function handler (item) {
26
- const { isString } = this.app.bajo.lib._
26
+ const { isString } = this.lib._
27
27
  for (const k of ['methods']) {
28
28
  item[k] = item[k] ?? []
29
29
  if (isString(item[k])) item[k] = item[k].split(',')
@@ -1,7 +1,7 @@
1
1
  import { collect } from './collect-routes.js'
2
2
 
3
3
  function handler (item) {
4
- const { isString } = this.app.bajo.lib._
4
+ const { isString } = this.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(',')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sumba",
3
- "version": "1.1.7",
3
+ "version": "1.1.8",
4
4
  "description": "Bajo Framework's Biz Suite",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/plugin/factory.js CHANGED
@@ -1,6 +1,6 @@
1
1
  async function getSetting (type, source) {
2
2
  const { defaultsDeep } = this.app.bajo
3
- const { get } = this.app.bajo.lib._
3
+ const { get } = this.lib._
4
4
 
5
5
  const setting = defaultsDeep(get(this.config, `auth.${source}.${type}`, {}), get(this.config, `auth.common.${type}`, {}))
6
6
  if (type === 'basic') setting.type = 'Basic'
@@ -8,7 +8,7 @@ async function getSetting (type, source) {
8
8
  }
9
9
 
10
10
  async function getToken (type, req, source) {
11
- const { isEmpty } = this.app.bajo.lib._
11
+ const { isEmpty } = this.lib._
12
12
 
13
13
  const setting = await getSetting.call(this, type, source)
14
14
  let token = req.headers[setting.headerKey.toLowerCase()]
@@ -113,7 +113,7 @@ async function factory (pkgName) {
113
113
 
114
114
  hasColumn = async (name, model) => {
115
115
  const { getInfo } = this.app.dobo
116
- const { find } = this.app.bajo.lib._
116
+ const { find } = this.lib._
117
117
  const { schema } = getInfo(model)
118
118
 
119
119
  const result = find(schema.properties, { name })
@@ -122,7 +122,7 @@ async function factory (pkgName) {
122
122
 
123
123
  getUser = async (rec, safe = true) => {
124
124
  const { recordGet } = this.app.dobo
125
- const { omit, isPlainObject } = this.app.bajo.lib._
125
+ const { omit, isPlainObject } = this.lib._
126
126
 
127
127
  let user
128
128
  if (isPlainObject(rec)) user = rec
@@ -149,9 +149,9 @@ async function factory (pkgName) {
149
149
 
150
150
  createJwtFromUserRecord = async (rec) => {
151
151
  const { importPkg } = this.app.bajo
152
- const { dayjs } = this.app.bajo.lib
152
+ const { dayjs } = this.lib
153
153
  const { hash } = this.app.bajoExtra
154
- const { get, pick } = this.app.bajo.lib._
154
+ const { get, pick } = this.lib._
155
155
 
156
156
  const fastJwt = await importPkg('bajoExtra:fast-jwt')
157
157
  const { createSigner } = fastJwt
@@ -208,10 +208,10 @@ async function factory (pkgName) {
208
208
  verifyBasic = async (req, reply, source) => {
209
209
  const { getUserFromUsernamePassword } = this
210
210
  const { getUser } = this
211
- const { isEmpty } = this.app.bajo.lib._
211
+ const { isEmpty } = this.lib._
212
212
 
213
213
  const setHeader = async (setting, reply) => {
214
- const { isString } = this.app.bajo.lib._
214
+ const { isString } = this.lib._
215
215
 
216
216
  let header = setting.type
217
217
  const exts = []
@@ -251,7 +251,7 @@ async function factory (pkgName) {
251
251
  const { importPkg } = this.app.bajo
252
252
  const { recordGet } = this.app.dobo
253
253
  const { getUser } = this
254
- const { isEmpty } = this.app.bajo.lib._
254
+ const { isEmpty } = this.lib._
255
255
 
256
256
  const fastJwt = await importPkg('bajoExtra:fast-jwt')
257
257
  const { createVerifier } = fastJwt
@@ -277,7 +277,7 @@ async function factory (pkgName) {
277
277
 
278
278
  checkPathsByTeam = ({ paths = [], method = 'GET', teams = [], guards = [] }) => {
279
279
  const { includes } = this.app.bajo
280
- const { outmatch } = this.app.bajo.lib
280
+ const { outmatch } = this.lib
281
281
 
282
282
  for (const item of guards) {
283
283
  const matchPath = outmatch(item.path)
@@ -294,7 +294,7 @@ async function factory (pkgName) {
294
294
  }
295
295
 
296
296
  checkPathsByRoute = ({ paths = [], method = 'GET', guards = [] }) => {
297
- const { outmatch } = this.app.bajo.lib
297
+ const { outmatch } = this.lib
298
298
 
299
299
  for (const item of guards) {
300
300
  const matchPath = outmatch(item.path)
@@ -308,7 +308,7 @@ async function factory (pkgName) {
308
308
  }
309
309
 
310
310
  checkPathsByGuard = ({ guards, paths }) => {
311
- const { outmatch } = this.app.bajo.lib
311
+ const { outmatch } = this.lib
312
312
  const matcher = outmatch(guards)
313
313
  let guarded
314
314
  for (const path of paths) {
@@ -2,7 +2,7 @@ const contactForm = {
2
2
  method: ['GET', 'POST'],
3
3
  handler: async function (req, reply) {
4
4
  const { defaultsDeep } = this.app.bajo
5
- const { pick } = this.app.bajo.lib._
5
+ const { pick } = this.lib._
6
6
  const { recordCreate, recordFind } = this.app.waibuDb
7
7
 
8
8
  const def = req.user ? pick(req.user, ['firstName', 'lastName', 'email']) : {}
@@ -4,7 +4,7 @@ const add = {
4
4
  method: ['GET', 'POST'],
5
5
  handler: async function (req, reply) {
6
6
  const { recordCreate, recordFind } = this.app.waibuDb
7
- const { defaultsDeep } = this.app.bajo.lib._
7
+ const { defaultsDeep } = this.lib._
8
8
  const options = {}
9
9
  const form = defaultsDeep(req.body, {})
10
10
  let error
@@ -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.app.bajo.lib._
6
+ const { cloneDeep } = this.lib._
7
7
  const { recordCreate, recordFind, getSchemaExt } = this.app.waibuDb
8
8
  const { schema } = await getSchemaExt(model, 'list')
9
9
 
@@ -4,7 +4,7 @@ const profile = {
4
4
  const { defaultsDeep } = this.app.bajo
5
5
  // const { attachmentCopyUploaded } = this.app.dobo
6
6
  const { recordUpdate, recordGet } = this.app.waibuDb
7
- const { omit, pick } = this.app.bajo.lib._
7
+ const { omit, pick } = this.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']))
@@ -6,7 +6,7 @@ const resetApiKey = {
6
6
  const { defaultsDeep, importPkg, generateId } = this.app.bajo
7
7
  const { recordGet, recordUpdate } = this.app.dobo
8
8
  const { hash } = this.app.bajoExtra
9
- const delay = await importPkg('delay')
9
+ const delay = await importPkg('bajo:delay')
10
10
  const bcrypt = await importPkg('bajoExtra:bcrypt')
11
11
  const Joi = await importPkg('dobo:joi')
12
12
  const form = defaultsDeep(req.body, { apiKey: await hash(req.user.salt) })
@@ -3,7 +3,7 @@ const signin = {
3
3
  handler: async function (req, reply) {
4
4
  const { getUserFromUsernamePassword } = this
5
5
  const { runHook } = this.app.bajo
6
- const { isEmpty, omit } = this.app.bajo.lib._
6
+ const { isEmpty, omit } = this.lib._
7
7
  const { getSessionId } = this.app.waibuMpa
8
8
 
9
9
  let { username, password, referer } = req.body || {}
@@ -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.app.bajo.lib._
5
+ // const { isEmpty } = this.lib._
6
6
  const { getSessionId } = this.app.waibuMpa
7
7
 
8
8
  let { referer } = req.body || {}
@@ -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.app.bajo.lib
5
+ const { dayjs } = this.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
@@ -20,7 +20,7 @@ const forgotPasswordLink = {
20
20
  handler: async function (req, reply) {
21
21
  const { sendMail } = this.app.waibu
22
22
  const { defaultsDeep, importPkg } = this.app.bajo
23
- const { isString } = this.app.bajo.lib._
23
+ const { isString } = this.lib._
24
24
  const { recordUpdate } = this.app.dobo
25
25
  const Joi = await importPkg('dobo:joi')
26
26
 
@@ -6,7 +6,7 @@ const profile = {
6
6
  if (!this.app.masohiMail) return reply.view('sumba.template:/user/forgot-password.html')
7
7
  const { sendMail } = this.app.waibu
8
8
  const { defaultsDeep } = this.app.bajo
9
- const { dayjs } = this.app.bajo.lib
9
+ const { dayjs } = this.lib
10
10
  const { recordFind } = this.app.dobo
11
11
  const form = defaultsDeep(req.body, {})
12
12
  let error
@@ -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.app.bajo.lib._
6
+ const { omit } = this.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.app.bajo.lib._
4
+ const { merge } = this.lib._
5
5
  const { recordGet } = this.app.dobo
6
6
  const { getSessionId } = this.app.waibuMpa
7
7