sumba 2.26.0 → 2.27.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.
@@ -255,14 +255,6 @@ async function hook () {
255
255
  { payload, options, source: this.ns }
256
256
  )
257
257
  }
258
- }, {
259
- name: 'dobo.sumbaUser:afterRecordValidation',
260
- handler: async function (body, options) {
261
- const { isBcrypt, hash } = this.app.bajoExtra
262
- const { has } = this.app.lib._
263
-
264
- if (has(body, 'password') && !isBcrypt(body.password)) body.password = await hash(body.password, 'bcrypt')
265
- }
266
258
  }, {
267
259
  name: 'dobo.sumbaUser:afterRemoveRecord',
268
260
  handler: async function (id, rec, options = {}) {
@@ -303,30 +295,6 @@ async function hook () {
303
295
  )
304
296
  }
305
297
  }
306
- }, {
307
- name: 'dobo.sumbaUser:beforeCreateRecord',
308
- handler: async function (body, options = {}) {
309
- const { token, salt } = await this.resetToken()
310
- body.token = token
311
- body.salt = salt
312
- }
313
- }, {
314
- name: 'dobo.sumbaUser:beforeRecordValidation',
315
- handler: async function (body, options = {}) {
316
- const { set } = this.app.lib._
317
- const password = await this.passwordRule(options.req)
318
- const rule = { password }
319
- set(options, 'validation.params.rule', rule)
320
- }
321
- }, {
322
- name: 'dobo.sumbaUser:beforeUpdateRecord',
323
- handler: async function (id, body, options = {}) {
324
- if (body.salt) {
325
- const { token, salt } = await this.resetToken(body.salt)
326
- body.token = token
327
- body.salt = salt
328
- }
329
- }
330
298
  }, {
331
299
  level: 1000,
332
300
  name: 'dobo.driver:beforeCreateRecord',
@@ -1,6 +1,6 @@
1
1
  [{
2
2
  "siteId": "?:SumbaSite::alias:default",
3
- "userId": "?:SumbaUser::username:admin+siteId={siteId}",
4
- "teamId": "?:SumbaTeam::alias:administrator+siteId={siteId}",
3
+ "userId": "?:SumbaUser::username:'admin'+siteId:'{siteId}'",
4
+ "teamId": "?:SumbaTeam::alias:'administrator'+siteId:'{siteId}'",
5
5
  "_immutable": true
6
6
  }]
@@ -102,8 +102,11 @@ async function model () {
102
102
  options
103
103
  }, {
104
104
  baseName: 'x-route-guard',
105
- properties: rgProperties.filter(prop => !isString(prop) || (isString(prop) && !prop.startsWith('teamIds'))),
106
- features: rgFeatures.filter(feat => !isString(feat) || (isString(feat) && !['sumba:siteId', 'dobo:updatedAt'].includes(feat))).concat('sumba:siteIds', 'dobo:updatedAt'),
105
+ properties: rgProperties.filter(prop => {
106
+ if (!isString(prop)) return true
107
+ return !(prop.startsWith('teamIds') || prop.startsWith('siteId'))
108
+ }).concat('siteIds,sumba:siteIds'),
109
+ features: rgFeatures,
107
110
  options
108
111
  }, {
109
112
  baseName: 'attrib-guard',
@@ -113,8 +116,11 @@ async function model () {
113
116
  buildEnd
114
117
  }, {
115
118
  baseName: 'x-attrib-guard',
116
- properties: agProperties.filter(prop => !isString(prop) || (isString(prop) && !prop.startsWith('teamIds'))),
117
- features: agFeatures.filter(feat => !isString(feat) || (isString(feat) && !['sumba:siteId', 'dobo:updatedAt'].includes(feat))).concat('sumba:siteIds', 'dobo:updatedAt'),
119
+ properties: agProperties.filter(prop => {
120
+ if (!isString(prop)) return true
121
+ return !(prop.startsWith('teamIds') || prop.startsWith('siteId'))
122
+ }).concat('siteIds,sumba:siteIds'),
123
+ features: agFeatures,
118
124
  options,
119
125
  buildEnd
120
126
  }, {
@@ -125,8 +131,11 @@ async function model () {
125
131
  buildEnd
126
132
  }, {
127
133
  baseName: 'x-model-guard',
128
- properties: mgProperties.filter(prop => !isString(prop) || (isString(prop) && !prop.startsWith('teamIds'))),
129
- features: mgFeatures.filter(feat => !isString(feat) || (isString(feat) && !['sumba:siteId', 'dobo:updatedAt'].includes(feat))).concat('sumba:siteIds', 'dobo:updatedAt'),
134
+ properties: mgProperties.filter(prop => {
135
+ if (!isString(prop)) return true
136
+ return !(prop.startsWith('teamIds') || prop.startsWith('siteId'))
137
+ }).concat('siteIds,sumba:siteIds'),
138
+ features: mgFeatures,
130
139
  options,
131
140
  buildEnd
132
141
  }, {
@@ -208,7 +217,40 @@ async function model () {
208
217
  'dobo:createdAt',
209
218
  'dobo:updatedAt',
210
219
  'dobo:immutable'
211
- ]
220
+ ],
221
+ hooks: [{
222
+ name: 'afterRecordValidation',
223
+ handler: async function (body, options) {
224
+ const { isBcrypt, hash } = this.app.bajoExtra
225
+ const { has } = this.app.lib._
226
+
227
+ if (has(body, 'password') && !isBcrypt(body.password)) body.password = await hash(body.password, 'bcrypt')
228
+ }
229
+ }, {
230
+ name: 'beforeCreateRecord',
231
+ handler: async function (body, options = {}) {
232
+ const { token, salt } = await this.plugin.resetToken()
233
+ body.token = token
234
+ body.salt = salt
235
+ }
236
+ }, {
237
+ name: 'beforeRecordValidation',
238
+ handler: async function (body, options = {}) {
239
+ const { set } = this.app.lib._
240
+ const password = await this.plugin.passwordRule(options.req)
241
+ const rule = { password }
242
+ set(options, 'validation.params.rule', rule)
243
+ }
244
+ }, {
245
+ name: 'beforeUpdateRecord',
246
+ handler: async function (id, body, options = {}) {
247
+ if (body.salt) {
248
+ const { token, salt } = await this.plugin.resetToken(body.salt)
249
+ body.token = token
250
+ body.salt = salt
251
+ }
252
+ }
253
+ }]
212
254
  }]
213
255
  }
214
256
 
package/index.js CHANGED
@@ -377,7 +377,7 @@ async function factory (pkgName) {
377
377
  return true
378
378
  }
379
379
 
380
- checkPathsByRoute = ({ paths = [], teamIds = [], guards = [] }) => {
380
+ checkPathsByRoute = ({ req, paths = [], teamIds = [], guards = [] }) => {
381
381
  const { includes } = this.app.lib.aneka
382
382
  const { outmatch } = this.app.lib
383
383
 
@@ -385,8 +385,10 @@ async function factory (pkgName) {
385
385
  const matchPath = outmatch(item.path)
386
386
  for (const path of paths) {
387
387
  if (matchPath(path)) {
388
- if (includes(teamIds, item.teamIds)) return item
389
- if (teamIds.length === 0) return item
388
+ if (item.methods.includes(req.method)) {
389
+ if (includes(teamIds, item.teamIds)) return item
390
+ if (teamIds.length === 0) return item
391
+ }
390
392
  }
391
393
  }
392
394
  }
@@ -61,9 +61,10 @@ export async function createRefs (site, data, options, verbose) {
61
61
  const fixtures = data[m]
62
62
  for (const f of fixtures) {
63
63
  f.siteId = site.id
64
+ const lv = {}
64
65
  for (const key in f) {
65
66
  const val = f[key]
66
- if (isString(val) && val.slice(0, 2) === '?:') f[key] = await mdl._simpleLookup(val.slice(2), options)
67
+ if (isString(val) && val.slice(0, 2) === '?:') f[key] = await mdl._simpleLookup(val.slice(2), lv, options)
67
68
  }
68
69
  await mdl.createRecord(f, options)
69
70
  }
package/lib/util.js CHANGED
@@ -122,28 +122,28 @@ export async function checkUserId (req, reply, source) {
122
122
  const globalGuards = guards.global.filter(item => item.siteIds.includes(req.site.id + ''))
123
123
  const localGuards = guards.local.filter(item => item.siteIds.includes(req.site.id + ''))
124
124
  // find anonymousPath
125
- anonymousPath = await this.checkPathsByRoute({ paths, guards: localGuards.filter(item => item.anonymous && !item.negation) })
125
+ anonymousPath = await this.checkPathsByRoute({ req, paths, guards: localGuards.filter(item => item.anonymous && !item.negation) })
126
126
  if (anonymousPath) {
127
- const neg = await this.checkPathsByRoute({ paths, guards: localGuards.filter(item => item.anonymous && item.negation) })
127
+ const neg = await this.checkPathsByRoute({ req, paths, guards: localGuards.filter(item => item.anonymous && item.negation) })
128
128
  if (neg) anonymousPath = undefined
129
129
  }
130
130
  if (!anonymousPath) {
131
- anonymousPath = await this.checkPathsByRoute({ paths, guards: globalGuards.filter(item => item.anonymous && !item.negation) })
131
+ anonymousPath = await this.checkPathsByRoute({ req, paths, guards: globalGuards.filter(item => item.anonymous && !item.negation) })
132
132
  if (anonymousPath) {
133
- const neg = await this.checkPathsByRoute({ paths, guards: globalGuards.filter(item => item.anonymous && item.negation) })
133
+ const neg = await this.checkPathsByRoute({ req, paths, guards: globalGuards.filter(item => item.anonymous && item.negation) })
134
134
  if (neg) anonymousPath = undefined
135
135
  }
136
136
  }
137
137
  // find securePath
138
- securePath = await this.checkPathsByRoute({ paths, guards: localGuards.filter(item => !item.anonymous && !item.negation) })
138
+ securePath = await this.checkPathsByRoute({ req, paths, guards: localGuards.filter(item => !item.anonymous && !item.negation) })
139
139
  if (securePath) {
140
- const neg = await this.checkPathsByRoute({ paths, guards: localGuards.filter(item => !item.anonymous && item.negation) })
140
+ const neg = await this.checkPathsByRoute({ req, paths, guards: localGuards.filter(item => !item.anonymous && item.negation) })
141
141
  if (neg) securePath = undefined
142
142
  }
143
143
  if (!securePath) {
144
- securePath = await this.checkPathsByRoute({ paths, guards: globalGuards.filter(item => !item.anonymous && !item.negation) })
144
+ securePath = await this.checkPathsByRoute({ req, paths, guards: globalGuards.filter(item => !item.anonymous && !item.negation) })
145
145
  if (securePath) {
146
- const neg = await this.checkPathsByRoute({ paths, guards: globalGuards.filter(item => !item.anonymous && item.negation) })
146
+ const neg = await this.checkPathsByRoute({ req, paths, guards: globalGuards.filter(item => !item.anonymous && item.negation) })
147
147
  if (neg) securePath = undefined
148
148
  }
149
149
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sumba",
3
- "version": "2.26.0",
3
+ "version": "2.27.0",
4
4
  "description": "Biz Suite for Bajo Framework",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/wiki/CHANGES.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changes
2
2
 
3
+ ## 2026-05-30
4
+
5
+ - [2.27.0] Move all ```sumbaUser``` hooks to model hooks
6
+ - [2.27.0] Bug fix in ```model.js```
7
+ - [2.27.0] Bug fix in ```create-new-site.js```
8
+ - [2.27.0] Bug fix in ```team-user.json``` fixture
9
+
10
+ ## 2026-05-29
11
+
12
+ - [2.26.1] Bug fix in ```util.js```
13
+ - [2.26.1] Bug fix in ```checkPathsByRoute()```
14
+
3
15
  ## 2026-05-28
4
16
 
5
17
  - [2.26.0] Change hooks to be written in one ```hook.js``` file