sumba 0.1.11 → 0.3.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/bajo/helper/create-jwt-from-user-record.js +1 -1
- package/bajo/helper/get-user.js +1 -1
- package/bajo/helper/has-column.js +2 -2
- package/bajo/helper/verify/api-key.js +2 -2
- package/bajo/helper/verify/basic.js +2 -2
- package/bajo/helper/verify/jwt.js +1 -1
- package/bajo/hook/bajoDb.SumbaUser@on-before-record-validation.js +1 -1
- package/bajo/hook/bajoDb@on-before-record-create.js +1 -1
- package/bajo/hook/bajoDb@on-before-record-find.js +1 -1
- package/bajo/hook/bajoDb@on-before-record-get.js +1 -1
- package/bajoAdmin/mpa/lib/pre-handler.js +1 -1
- package/bajoDb/feature/lat-lng.js +1 -1
- package/bajoDb/feature/slug.js +2 -2
- package/bajoWebMpa/route/activation.js +1 -1
- package/bajoWebMpa/route/change-password.js +1 -1
- package/bajoWebMpa/route/profile.js +1 -1
- package/bajoWebMpa/route/signin.js +2 -3
- package/bajoWebMpa/route/signout.js +1 -1
- package/bajoWebRestapi/route/access-token/@type/create.js +2 -2
- package/bajoWebRestapi/route/account/api-key/get.js +1 -1
- package/bajoWebRestapi/route/account/change-password/update.js +1 -1
- package/bajoWebRestapi/route/account/profile/update.js +1 -1
- package/bajoWebRestapi/route/account/setting/update.js +1 -1
- package/bajoWebRestapi/route/site/coll-builder.json +3 -0
- package/bajoWebRestapi/route/site-setting/coll-builder.json +3 -0
- package/bajoWebRestapi/route/user/coll-builder.json +4 -0
- package/bajoWebRestapi/route/user-setting/coll-builder.json +3 -0
- package/lib/check-lang.js +1 -1
- package/lib/check-theme.js +1 -1
- package/lib/check-user-id.js +2 -2
- package/lib/collect-routes.js +1 -1
- package/lib/update-password.js +1 -1
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
async function createJwtFromUserRecord (rec) {
|
|
2
2
|
const { importPkg, getConfig, dayjs } = this.bajo.helper
|
|
3
3
|
const { hash } = this.bajoExtra.helper
|
|
4
|
-
const { get, pick } =
|
|
4
|
+
const { get, pick } = this.bajo.helper._
|
|
5
5
|
const fastJwt = await importPkg('bajo-extra:fast-jwt')
|
|
6
6
|
const { createSigner } = fastJwt
|
|
7
7
|
|
package/bajo/helper/get-user.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
async function getUser (rec, safe = true) {
|
|
2
2
|
const { getConfig, importPkg } = this.bajo.helper
|
|
3
3
|
const { recordGet } = this.bajoDb.helper
|
|
4
|
-
const { omit, isString } =
|
|
4
|
+
const { omit, isString } = this.bajo.helper._
|
|
5
5
|
const cfg = getConfig('sumba')
|
|
6
6
|
let user
|
|
7
7
|
if (isString(rec)) user = await recordGet('SumbaUser', rec, { noHook: true })
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
async function hasColumn (name, coll) {
|
|
2
2
|
const { importPkg } = this.bajo.helper
|
|
3
3
|
const { getInfo } = this.bajoDb.helper
|
|
4
|
-
const { find } =
|
|
5
|
-
const { schema } =
|
|
4
|
+
const { find } = this.bajo.helper._
|
|
5
|
+
const { schema } = getInfo(coll)
|
|
6
6
|
const result = find(schema.properties, { name })
|
|
7
7
|
return !!result
|
|
8
8
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export async function getSetting (type, source) {
|
|
2
2
|
const { importPkg, getConfig, defaultsDeep } = this.bajo.helper
|
|
3
|
-
const { get } =
|
|
3
|
+
const { get } = this.bajo.helper._
|
|
4
4
|
const cfg = getConfig('sumba')
|
|
5
5
|
const setting = defaultsDeep(get(cfg, `auth.${source}.${type}`, {}), get(cfg, `auth.common.${type}`, {}))
|
|
6
6
|
if (type === 'basic') setting.type = 'Basic'
|
|
@@ -9,7 +9,7 @@ export async function getSetting (type, source) {
|
|
|
9
9
|
|
|
10
10
|
export async function getToken (type, req, source) {
|
|
11
11
|
const { importPkg } = this.bajo.helper
|
|
12
|
-
const { isEmpty } =
|
|
12
|
+
const { isEmpty } = this.bajo.helper._
|
|
13
13
|
const setting = await getSetting.call(this, type, source)
|
|
14
14
|
let token = req.headers[setting.headerKey.toLowerCase()]
|
|
15
15
|
if (!['basic'].includes(type) && isEmpty(token)) token = req.query[setting.qsKey]
|
|
@@ -2,7 +2,7 @@ import { getSetting } from './api-key.js'
|
|
|
2
2
|
|
|
3
3
|
async function setHeader (setting, reply) {
|
|
4
4
|
const { importPkg } = this.bajo.helper
|
|
5
|
-
const { isString } =
|
|
5
|
+
const { isString } = this.bajo.helper._
|
|
6
6
|
let header = setting.type
|
|
7
7
|
const exts = []
|
|
8
8
|
if (isString(setting.realm)) exts.push(`realm="${setting.realm}"`)
|
|
@@ -16,7 +16,7 @@ async function verifyBasic (ctx, req, reply, source) {
|
|
|
16
16
|
const { importPkg, print, error } = this.bajo.helper
|
|
17
17
|
const { getUserFromUsernamePassword } = this.sumba.helper
|
|
18
18
|
const { getUser } = this.sumba.helper
|
|
19
|
-
const { isEmpty } =
|
|
19
|
+
const { isEmpty } = this.bajo.helper._
|
|
20
20
|
const setting = await getSetting.call(this, 'basic', source)
|
|
21
21
|
let authInfo
|
|
22
22
|
const parts = (req.headers.authorization || '').split(' ')
|
|
@@ -4,7 +4,7 @@ async function verifyJwt (ctx, req, reply, source) {
|
|
|
4
4
|
const { importPkg, error } = this.bajo.helper
|
|
5
5
|
const { recordGet } = this.bajoDb.helper
|
|
6
6
|
const { getUser } = this.sumba.helper
|
|
7
|
-
const { isEmpty } =
|
|
7
|
+
const { isEmpty } = this.bajo.helper._
|
|
8
8
|
const fastJwt = await importPkg('bajo-extra:fast-jwt')
|
|
9
9
|
const { createVerifier } = fastJwt
|
|
10
10
|
const setting = await getSetting.call(this, 'jwt', source)
|
|
@@ -2,7 +2,7 @@ import { joiPasswordExtendCore } from 'joi-password'
|
|
|
2
2
|
|
|
3
3
|
async function bajoDbSiteUserOnBeforeRecordValidation (body, options = {}) {
|
|
4
4
|
const { importPkg, getConfig } = this.bajo.helper
|
|
5
|
-
const { set } =
|
|
5
|
+
const { set } = this.bajo.helper._
|
|
6
6
|
const joi = await importPkg('bajo-db:joi')
|
|
7
7
|
const cfg = getConfig('sumba')
|
|
8
8
|
const joiPassword = joi.extend(joiPasswordExtendCore)
|
|
@@ -2,7 +2,7 @@ const bajoDbOnBeforeRecordCreate = {
|
|
|
2
2
|
level: 1000,
|
|
3
3
|
handler: async function (coll, body, options) {
|
|
4
4
|
const { importPkg } = this.bajo.helper
|
|
5
|
-
const { get } =
|
|
5
|
+
const { get } = this.bajo.helper._
|
|
6
6
|
const { hasColumn } = this.sumba.helper
|
|
7
7
|
const item = { siteId: 'req.site.id', userId: 'req.user.id' }
|
|
8
8
|
for (const i in item) {
|
|
@@ -2,7 +2,7 @@ const bajoDbOnBeforeRecordFind = {
|
|
|
2
2
|
level: 1000,
|
|
3
3
|
handler: async function (coll, filter, options) {
|
|
4
4
|
const { importPkg } = this.bajo.helper
|
|
5
|
-
const { isEmpty, cloneDeep, get, set } =
|
|
5
|
+
const { isEmpty, cloneDeep, get, set } = this.bajo.helper._
|
|
6
6
|
const { hasColumn } = this.sumba.helper
|
|
7
7
|
const item = { siteId: 'req.site.id', userId: 'req.user.id' }
|
|
8
8
|
for (const i in item) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export async function checker (coll, id, req) {
|
|
2
2
|
const { importPkg, error } = this.bajo.helper
|
|
3
3
|
const { recordFind } = this.bajoDb.helper
|
|
4
|
-
const { get } =
|
|
4
|
+
const { get } = this.bajo.helper._
|
|
5
5
|
const { hasColumn } = this.sumba.helper
|
|
6
6
|
const item = { siteId: 'site.id', userId: 'user.id' }
|
|
7
7
|
for (const i in item) {
|
|
@@ -5,7 +5,7 @@ async function preHandler (ctx, req, reply) {
|
|
|
5
5
|
const buildPagesMenu = await importModule(`${cfg.dir.pkg}/lib//build-pages-menu.js`)
|
|
6
6
|
req.menu = req.menu ?? {}
|
|
7
7
|
req.menu.coll = await buildCollMenu.call(this)
|
|
8
|
-
req.menu.pages =
|
|
8
|
+
req.menu.pages = buildPagesMenu.call(this)
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
export default preHandler
|
|
@@ -2,7 +2,7 @@ import latLngHook from '../../lib/lat-lng-hook.js'
|
|
|
2
2
|
|
|
3
3
|
async function latLng (opts = {}) {
|
|
4
4
|
const { importPkg } = this.bajo.helper
|
|
5
|
-
const { merge } =
|
|
5
|
+
const { merge } = this.bajo.helper._
|
|
6
6
|
opts.fieldNameLat = opts.fieldNameLat ?? 'lat'
|
|
7
7
|
opts.fieldNameLng = opts.fieldNameLng ?? 'lng'
|
|
8
8
|
opts.scale = opts.scale ?? 5
|
package/bajoDb/feature/slug.js
CHANGED
|
@@ -3,7 +3,7 @@ import slug from 'slug'
|
|
|
3
3
|
async function autoInc ({ schema, body, opts }) {
|
|
4
4
|
const { importPkg } = this.bajo.helper
|
|
5
5
|
const { recordFind } = this.bajoDb.helper
|
|
6
|
-
const { set, last } =
|
|
6
|
+
const { set, last } = this.bajo.helper._
|
|
7
7
|
const query = set({}, opts.fieldName, { $regex: new RegExp('^' + body[opts.fieldName]) })
|
|
8
8
|
const sort = set({}, opts.fieldName, -1)
|
|
9
9
|
const options = { noHook: true, skipCache: true, thrownNotFound: false }
|
|
@@ -41,7 +41,7 @@ async function mainFn (opts = {}) {
|
|
|
41
41
|
hook: {
|
|
42
42
|
beforeCreate: async function ({ schema, body }) {
|
|
43
43
|
const { importPkg, error } = this.bajo.helper
|
|
44
|
-
const { isEmpty, isString } =
|
|
44
|
+
const { isEmpty, isString } = this.bajo.helper._
|
|
45
45
|
if (isEmpty(body[opts.fieldName])) {
|
|
46
46
|
if (isString(opts.fieldSource)) opts.fieldSource = [opts.fieldSource]
|
|
47
47
|
const source = []
|
|
@@ -2,7 +2,7 @@ async function activation (ctx, req, reply) {
|
|
|
2
2
|
const { getConfig, importPkg, error } = this.bajo.helper
|
|
3
3
|
const { recordFind, recordUpdate } = this.bajoDb.helper
|
|
4
4
|
const { routePath } = this.bajoWeb.helper
|
|
5
|
-
const { isEmpty } =
|
|
5
|
+
const { isEmpty } = this.bajo.helper._
|
|
6
6
|
const cfg = getConfig('sumba')
|
|
7
7
|
const { key } = req.query
|
|
8
8
|
let err
|
|
@@ -4,7 +4,7 @@ const profile = {
|
|
|
4
4
|
const { defaultsDeep, importPkg } = this.bajo.helper
|
|
5
5
|
const { attachmentCopyUploaded } = this.bajoDb.helper
|
|
6
6
|
const { recordUpdate } = this.bajoWeb.helper
|
|
7
|
-
const { has } =
|
|
7
|
+
const { has } = this.bajo.helper._
|
|
8
8
|
let form = defaultsDeep(req.body, req.user)
|
|
9
9
|
if (req.method === 'POST') {
|
|
10
10
|
try {
|
|
@@ -4,7 +4,7 @@ const profile = {
|
|
|
4
4
|
const { defaultsDeep, importPkg } = this.bajo.helper
|
|
5
5
|
const { attachmentCopyUploaded } = this.bajoDb.helper
|
|
6
6
|
const { recordUpdate } = this.bajoWeb.helper
|
|
7
|
-
const { has } =
|
|
7
|
+
const { has } = this.bajo.helper._
|
|
8
8
|
let form = defaultsDeep(req.body, req.user)
|
|
9
9
|
if (req.method === 'POST') {
|
|
10
10
|
try {
|
|
@@ -4,8 +4,7 @@ const signin = {
|
|
|
4
4
|
const { getConfig, importPkg } = this.bajo.helper
|
|
5
5
|
const { routePath } = this.bajoWeb.helper
|
|
6
6
|
const { getUserFromUsernamePassword } = this.sumba.helper
|
|
7
|
-
const {
|
|
8
|
-
const { isEmpty, pick } = await importPkg('lodash-es')
|
|
7
|
+
const { isEmpty, pick } = this.bajo.helper._
|
|
9
8
|
const cfg = getConfig('sumba')
|
|
10
9
|
let { username, password, referer } = req.body || {}
|
|
11
10
|
if (req.session.ref) referer = req.session.ref
|
|
@@ -14,7 +13,7 @@ const signin = {
|
|
|
14
13
|
if (req.method === 'POST') {
|
|
15
14
|
try {
|
|
16
15
|
const user = pick(await getUserFromUsernamePassword(username, password, req), ['id', 'username', 'email', 'siteId'])
|
|
17
|
-
emit('sumba.signin', user)
|
|
16
|
+
if (this.bajoEmitter) this.bajoEmitter.helper.emit('sumba.signin', user)
|
|
18
17
|
req.session.user = user
|
|
19
18
|
const { query, params } = req
|
|
20
19
|
const url = !isEmpty(referer) ? referer : routePath(cfg.redirect.home, { query, params })
|
|
@@ -3,7 +3,7 @@ const signout = {
|
|
|
3
3
|
handler: async function (ctx, req, reply) {
|
|
4
4
|
const { getConfig, importPkg } = this.bajo.helper
|
|
5
5
|
const { routePath } = this.bajoWeb.helper
|
|
6
|
-
const { isEmpty } =
|
|
6
|
+
const { isEmpty } = this.bajo.helper._
|
|
7
7
|
const cfg = getConfig('sumba')
|
|
8
8
|
let { referer } = req.body || {}
|
|
9
9
|
if (req.session.ref) referer = req.session.ref
|
|
@@ -7,12 +7,12 @@ async function create () {
|
|
|
7
7
|
'2xx': {
|
|
8
8
|
description: 'Successfull response',
|
|
9
9
|
type: 'object',
|
|
10
|
-
properties:
|
|
10
|
+
properties: this.bajoWebRestapi.helper.transformResult({ data })
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
const handler = async function
|
|
15
|
+
const handler = async function (ctx, req, reply) {
|
|
16
16
|
const { error } = this.bajo.helper
|
|
17
17
|
const { hash } = this.bajoExtra.helper
|
|
18
18
|
const { getUserFromUsernamePassword, createJwtFromUserRecord } = this.sumba.helper
|
|
@@ -34,7 +34,7 @@ async function update ({ ctx }) {
|
|
|
34
34
|
'2xx': {
|
|
35
35
|
description: 'Successfull response',
|
|
36
36
|
type: 'object',
|
|
37
|
-
properties:
|
|
37
|
+
properties: this.bajoWebRestapi.helper.transformResult({ data })
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
}
|
|
@@ -4,7 +4,7 @@ const hidden = ['password', 'token', 'siteId']
|
|
|
4
4
|
async function get ({ ctx }) {
|
|
5
5
|
const { importPkg } = this.bajo.helper
|
|
6
6
|
const { recordUpdate } = this.bajoWeb.helper
|
|
7
|
-
const { omit } =
|
|
7
|
+
const { omit } = this.bajo.helper._
|
|
8
8
|
const { docSchemaColl } = this.bajoWebRestapi.helper
|
|
9
9
|
const schema = await docSchemaColl({ coll, method: 'update', ctx, options: { hidden, noId: true } })
|
|
10
10
|
const handler = async function get (ctx, req, reply, options) {
|
|
@@ -4,7 +4,7 @@ const hidden = ['userId', 'siteId']
|
|
|
4
4
|
async function get ({ ctx }) {
|
|
5
5
|
const { importPkg } = this.bajo.helper
|
|
6
6
|
const { recordUpdate } = this.bajoWeb.helper
|
|
7
|
-
const { omit } =
|
|
7
|
+
const { omit } = this.bajo.helper._
|
|
8
8
|
const { docSchemaColl } = this.bajoWebRestapi.helper
|
|
9
9
|
const schema = await docSchemaColl({ coll, method: 'update', ctx, options: { hidden, noId: true } })
|
|
10
10
|
const handler = async function get (ctx, req, reply, options) {
|
package/lib/check-lang.js
CHANGED
package/lib/check-theme.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
async function checkTheme (req, reply) {
|
|
2
2
|
const { getConfig, importPkg } = this.bajo.helper
|
|
3
|
-
const { get } =
|
|
3
|
+
const { get } = this.bajo.helper._
|
|
4
4
|
if (!req.site) return
|
|
5
5
|
req.theme = get(req, 'site.setting.theme', getConfig('bajoWeb').theme)
|
|
6
6
|
if (get(req, 'site.setting.allowUserTheme')) req.theme = get(req, 'user.setting.theme', req.theme)
|
package/lib/check-user-id.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
async function checker (req, container) {
|
|
2
2
|
const { importPkg, getConfig } = this.bajo.helper
|
|
3
|
-
const { get } =
|
|
3
|
+
const { get } = this.bajo.helper._
|
|
4
4
|
const outmatch = await importPkg('outmatch')
|
|
5
5
|
let match
|
|
6
6
|
for (const item of container) {
|
|
@@ -52,7 +52,7 @@ async function checkUserId (req, reply, source) {
|
|
|
52
52
|
const { getConfig, error, importPkg } = this.bajo.helper
|
|
53
53
|
const ctx = this[source].instance
|
|
54
54
|
if (!req.routeOptions.url) return
|
|
55
|
-
const { isEmpty, camelCase } =
|
|
55
|
+
const { isEmpty, camelCase } = this.bajo.helper._
|
|
56
56
|
const match = await checker.call(this, req, this.sumba.secureRoutes)
|
|
57
57
|
if (!match) {
|
|
58
58
|
await anonymous.call(this, req)
|
package/lib/collect-routes.js
CHANGED
|
@@ -4,7 +4,7 @@ const invIndexes = []
|
|
|
4
4
|
async function collect (type, { file, plugin, dir }) {
|
|
5
5
|
const { readConfig, importPkg } = this.bajo.helper
|
|
6
6
|
const { routeDir } = this.bajoWeb.helper
|
|
7
|
-
const { trim } =
|
|
7
|
+
const { trim } = this.bajo.helper._
|
|
8
8
|
const { hash } = this.bajoExtra.helper
|
|
9
9
|
const routes = await readConfig(file, { ignoreError: true })
|
|
10
10
|
let source = trim(file.replace(dir, '').split('@')[0], '/')
|
package/lib/update-password.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
async function updatePassword (body) {
|
|
2
2
|
const { importPkg } = this.bajo.helper
|
|
3
3
|
const { isBcrypt, hash } = this.bajoExtra.helper
|
|
4
|
-
const { isEmpty } =
|
|
4
|
+
const { isEmpty } = this.bajo.helper._
|
|
5
5
|
if (isEmpty(body.password)) return
|
|
6
6
|
if (!isBcrypt(body.password)) body.password = await hash(body.password, 'bcrypt')
|
|
7
7
|
body.token = await hash(await hash(body.password))
|