sumba 2.18.1 → 2.19.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.
@@ -1,7 +1,9 @@
1
1
  import { removeRefs } from '../../../lib/remove-site.js'
2
+ import { clearCache } from './dobo.sumba-site@after-update-record.js'
2
3
 
3
4
  async function afterRemoveRecord (id, result, options) {
4
5
  await removeRefs.call(this, result.oldData, options)
6
+ await clearCache.call(this, id, result)
5
7
  }
6
8
 
7
9
  export default afterRemoveRecord
@@ -0,0 +1,14 @@
1
+ export async function clearCache (id, result) {
2
+ if (!this.app.bajoCache) return
3
+ const { clear } = this.app.bajoCache
4
+ const { get } = this.app.lib._
5
+ await clear({ key: 'dobo|SumbaSite|getSite|default' })
6
+ await clear({ key: `dobo|SumbaSite|getSite|multiSite|${id}` })
7
+ await clear({ key: `dobo|SumbaSite|getSite|multiSite|${get(result, 'data.hostname', get(result, 'oldData.hostname'))}` })
8
+ }
9
+
10
+ async function afterUpdateRecord (id, input, result, opts) {
11
+ await clearCache.call(this, id, result)
12
+ }
13
+
14
+ export default afterUpdateRecord
@@ -0,0 +1,7 @@
1
+ import { clearCache } from './dobo.sumba-user@after-update-record.js'
2
+
3
+ async function afterRemoveRecord (id, rec, options = {}) {
4
+ await clearCache.call(this, id, rec)
5
+ }
6
+
7
+ export default afterRemoveRecord
@@ -1,3 +1,14 @@
1
+ export async function clearCache (id, result) {
2
+ if (!this.app.bajoCache) return
3
+ const { hash } = this.app.bajoExtra
4
+ const { clear } = this.app.bajoCache
5
+ const { get, isEmpty } = this.app.lib._
6
+ let token = get(result, 'data.token', get(result, 'oldData.token', ''))
7
+ if (!isEmpty(token)) token = await hash(token)
8
+ await clear({ key: `dobo|SumbaUser|getUserById|${id}` })
9
+ await clear({ key: `dobo|SumbaUser|getUserByToken|${token}` })
10
+ }
11
+
1
12
  async function afterUpdateRecord (id, body, rec, options = {}) {
2
13
  const { data, oldData } = rec
3
14
  const { req } = options
@@ -5,6 +16,9 @@ async function afterUpdateRecord (id, body, rec, options = {}) {
5
16
  const t = get(req, 't', this.t)
6
17
  const to = `${data.firstName} ${data.lastName} <${data.email}>`
7
18
  const source = this.ns
19
+
20
+ await clearCache.call(this, id, rec)
21
+
8
22
  let subject
9
23
  const payload = { to, subject, data }
10
24
 
@@ -17,7 +17,7 @@
17
17
  <c:form-input name="city" label-floating col="8-lg 7-md"/>
18
18
  <c:form-input name="zipCode" label-floating col="4-lg 5-md"/>
19
19
  <c:form-input name="provinceState" label-floating col="6-lg"/>
20
- <c:form-select-country name="country" label-floating col="6-lg"/>
20
+ <c:form-select-ext name="country" label-floating col="6-lg"/>
21
21
  <c:form-input name="phone" label-floating col="6-lg"/>
22
22
  <c:form-input name="website" label-floating col="6-lg"/>
23
23
  </c:fieldset>
@@ -14,7 +14,8 @@ const manageSite = {
14
14
  const options = {
15
15
  modelOpts: {
16
16
  formatValue: true,
17
- retainOriginalValue: true
17
+ retainOriginalValue: true,
18
+ noCache: true
18
19
  },
19
20
  schema: {
20
21
  view: {
@@ -1,14 +1,21 @@
1
1
  const fields = ['email', 'firstName', 'lastName', 'address1', 'address2', 'city', 'zipCode', 'provinceState', 'country', 'phone', 'website']
2
+ const model = 'SumbaUser'
2
3
 
3
4
  const profile = {
4
5
  method: ['GET', 'POST'],
5
6
  handler: async function (req, reply) {
6
7
  const { defaultsDeep } = this.app.lib.aneka
7
- // const { attachmentCopyUploaded } = this.app.dobo
8
8
  const { updateRecord, getRecord } = this.app.waibuDb
9
+ const { getSchemaExt } = this.app.waibuDb
9
10
  const { omit, pick } = this.app.lib._
10
11
  const { hash } = this.app.bajoExtra
11
- const resp = await getRecord({ model: 'SumbaUser', req, id: req.user.id, options: { forceNoHidden: ['token'], noHook: true, noCache: true } })
12
+
13
+ const options = { forceNoHidden: ['token'], noHook: true, noCache: true, formatValue: true, retainOriginalValue: true }
14
+ const mdl = this.app.dobo.getModel(model)
15
+
16
+ const { schema } = await getSchemaExt(model, 'edit', { ...options, args: [{ req, model: mdl }] })
17
+
18
+ const resp = await getRecord({ model, req, id: req.user.id, options })
12
19
  let form = defaultsDeep(req.body, omit(resp.data, ['password', 'salt']))
13
20
  form.token = await hash(form.token)
14
21
  let error
@@ -16,7 +23,7 @@ const profile = {
16
23
  try {
17
24
  const body = pick(form, fields)
18
25
  const options = { noFlash: true, hidden: [], setField: 'profile', setFile: 'main.png', partial: true, fields }
19
- const resp = await updateRecord({ req, reply, model: 'SumbaUser', id: req.user.id, body, options })
26
+ const resp = await updateRecord({ req, reply, model, id: req.user.id, body, options })
20
27
  form = resp.data
21
28
  req.flash('notify', req.t('profileUpdated'))
22
29
  return reply.redirectTo('sumba:/your-stuff/profile')
@@ -24,7 +31,7 @@ const profile = {
24
31
  error = err
25
32
  }
26
33
  }
27
- return await reply.view('sumba.template:/your-stuff/profile/edit.html', { form, error })
34
+ return await reply.view('sumba.template:/your-stuff/profile/edit.html', { form, error, schema })
28
35
  }
29
36
  }
30
37
 
@@ -3,7 +3,7 @@ const profile = {
3
3
  handler: async function (req, reply) {
4
4
  const { hash } = this.app.bajoExtra
5
5
  const { getRecord } = this.app.waibuDb
6
- const options = { forceNoHidden: ['token'], noHook: true, noCache: true, attachment: true, mimeType: true }
6
+ const options = { forceNoHidden: ['token'], noHook: true, noCache: true, attachment: true, mimeType: true, formatValue: true, retainOriginalValue: true }
7
7
  const resp = await getRecord({ model: 'SumbaUser', req, id: req.user.id, options })
8
8
  const form = resp.data
9
9
  form.token = await hash(form.salt)
package/lib/get-site.js CHANGED
@@ -31,7 +31,7 @@ async function getSite (input, byId = false) {
31
31
 
32
32
  if (!this.config.multiSite.enabled) {
33
33
  const filter = { query: { alias: 'default' } }
34
- const key = 'getSite|default'
34
+ const key = 'dobo|SumbaSite|getSite|default'
35
35
  if (getCache) {
36
36
  site = await getCache({ key })
37
37
  if (site) return site
@@ -47,7 +47,7 @@ async function getSite (input, byId = false) {
47
47
  let query
48
48
  if (byId) query = { id: input }
49
49
  else query = { hostname: input }
50
- const key = `getSite|multiSite|${input}`
50
+ const key = `dobo|SumbaSite|getSite|multiSite|${input}`
51
51
  if (getCache) {
52
52
  site = await getCache({ key })
53
53
  if (site) return JSON.parse(site)
package/lib/get-user.js CHANGED
@@ -39,7 +39,7 @@ export async function mergeTeam (user) {
39
39
  export async function getUserById (id, req) {
40
40
  const { getModel } = this.app.dobo
41
41
  const { set: setCache, get: getCache } = this.app.bajoCache ?? {}
42
- const key = `getUserById|${id}`
42
+ const key = `dobo|SumbaUser|getUserById|${id}`
43
43
  let user
44
44
  if (getCache) {
45
45
  user = await getCache({ key })
@@ -57,7 +57,7 @@ export async function getUserById (id, req) {
57
57
  export async function getUserByToken (token, req) {
58
58
  const { getModel } = this.app.dobo
59
59
  const { set: setCache, get: getCache } = this.app.bajoCache ?? {}
60
- const key = `getUserByToken|${token}`
60
+ const key = `dobo|SumbaUser|getUserByToken|${token}`
61
61
  let user
62
62
  if (getCache) {
63
63
  user = await getCache({ key })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sumba",
3
- "version": "2.18.1",
3
+ "version": "2.19.1",
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-04-17
4
+
5
+ - [2.19.1] Bug fix in profile edit's route
6
+
7
+ ## 2026-04-16
8
+
9
+ - [2.19.0] Add cache clearing if a site is updated/removed
10
+ - [2.19.0] Add cache clearing if a user is updated/removed
11
+ - [2.19.0] Necessary changes to all routes to support ```formatValue``` & ```retainOriginalValue``` options
12
+ - [2.19.0] Change cache key for ```getUser()```
13
+ - [2.19.0] Change cache key for ```getSite()```
14
+
3
15
  ## 2026-04-13
4
16
 
5
17
  - [2.18.1] Bug fix on ```SumbaSite``` model