@mapomodule/core 1.0.0-alpha.6 → 1.0.0-alpha.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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,19 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [1.0.0-alpha.8](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.7...v1.0.0-alpha.8) (2022-01-23)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **auth:** logout user only on 401 ([818f3d5](https://github.com/lotrekagency/mapo/commit/818f3d5ff315635438ac9bc9566a1b2fd2c5cf03))
12
+ * **permission:** fix bad store initialization on ssr ([f075824](https://github.com/lotrekagency/mapo/commit/f075824561d6a71ce07ecbba70e994102abd623b))
13
+ * **permissions:** add route permissions with routename instead on path ([16ff6ee](https://github.com/lotrekagency/mapo/commit/16ff6eee5e3a8ddbf9e7aea1ba05e8a88fb43932))
14
+
15
+
16
+
17
+
18
+
6
19
  # [1.0.0-alpha.6](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.5...v1.0.0-alpha.6) (2021-12-26)
7
20
 
8
21
 
package/index.js CHANGED
@@ -2,6 +2,13 @@ import createRepository from '@mapomodule/core/api/crud'
2
2
  import transformRequestInMultipart from '@mapomodule/core/api/multipart'
3
3
  import initInterceptors from '@mapomodule/core/interceptor'
4
4
 
5
+ function getRouteMiddlewares(route) {
6
+ const meta = Array.isArray(route?.meta) ? route.meta[0] : route.meta
7
+ const { middleware } = meta
8
+ return (typeof middleware === "string" ? [middleware] : middleware) || []
9
+ }
10
+
11
+
5
12
  export default (ctx, inject) => {
6
13
 
7
14
  initInterceptors(ctx)
@@ -39,9 +46,23 @@ export default (ctx, inject) => {
39
46
  get token() { return ctx.store.getters['mapo/user/token'] },
40
47
  get info() { return ctx.store.getters['mapo/user/info'] },
41
48
  get username() { return ctx.store.getters['mapo/user/username'] },
42
- get permissions() { return ctx.store.getters['mapo/user/pagePermission'](ctx.app.context.route.path) },
49
+ get permissions() { return ctx.store.getters['mapo/user/pagePermission'](ctx.app.context.route.name) },
43
50
  get role() { return ctx.store.getters['mapo/user/role'] }
44
- }
51
+ },
52
+ /**
53
+ *
54
+ * This returns the current route middlewares if routemeta is enabled.
55
+ */
56
+ get routeMiddlewares() {
57
+ return getRouteMiddlewares(ctx.app.context.route)
58
+ },
59
+ /**
60
+ *
61
+ * This returns the middlewares of a given route if routemeta is enabled.
62
+ * @param { Object } route { meta } the route object with meta info.
63
+ * @returns { Array }
64
+ */
65
+ getRouteMiddlewares: getRouteMiddlewares
45
66
  },
46
67
  /**
47
68
  * From here you can manage the default popup messaging system of mapo.
@@ -9,17 +9,15 @@ module.exports = ({ $axios, store }) => {
9
9
  })
10
10
 
11
11
  $axios.onResponse((response) => {
12
- if (response.status !== 200) {
13
- if (response.status === 401 || response.status === 402 || response.status === 403) {
14
- store.dispatch('mapo/user/logout');
15
- }
12
+ if (response.status === 401) {
13
+ store.dispatch('mapo/user/logout');
16
14
  }
17
15
  return response
18
16
  })
19
17
 
20
18
  $axios.onError((error) => {
21
19
  const { status } = error.response || {}
22
- if (status === 401 || status === 402 || status === 403) {
20
+ if (status === 401) {
23
21
  store.dispatch('mapo/user/logout');
24
22
  }
25
23
  return Promise.reject(error)
@@ -5,7 +5,7 @@ Middleware.permissions = Middleware.permissions || async function ({ route, erro
5
5
  if (!route.meta.permissions) return
6
6
  const userInfo = store.getters['mapo/user/info']
7
7
  if (userInfo.is_superuser) {
8
- await store.dispatch('mapo/user/addPagePermission', {key: route.path, value: ["add", "change", "delete", "view"]})
8
+ await store.dispatch('mapo/user/addPagePermission', {key: route.name, value: ["add", "change", "delete", "view"]})
9
9
  return
10
10
  }
11
11
  const { model } = route.meta.permissions
@@ -13,7 +13,7 @@ Middleware.permissions = Middleware.permissions || async function ({ route, erro
13
13
  if (!userPermission.includes('view')) {
14
14
  return error({ statusCode: 404, message: 'This page could not be found' })
15
15
  } else {
16
- await store.dispatch('mapo/user/addPagePermission', {key: route.path, value: userPermission})
16
+ await store.dispatch('mapo/user/addPagePermission', {key: route.name, value: userPermission})
17
17
  return
18
18
  }
19
19
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mapomodule/core",
3
- "version": "1.0.0-alpha.6",
3
+ "version": "1.0.0-alpha.8",
4
4
  "description": "This is part of Mapo nuxt module. Injects the core mapo plugin helpers.",
5
5
  "author": "bnznamco <gabriele.baldi.01@gmail.com>",
6
6
  "keywords": [
@@ -13,10 +13,10 @@
13
13
  "repository": "https://github.com/lotrekagency/mapo",
14
14
  "main": "./module.js",
15
15
  "dependencies": {
16
- "@mapomodule/utils": "^1.0.0-alpha.1"
16
+ "@mapomodule/utils": "^1.0.0-alpha.8"
17
17
  },
18
18
  "publishConfig": {
19
19
  "access": "public"
20
20
  },
21
- "gitHead": "c30717d018606a1393f3a1f680276b1817d1d7a8"
21
+ "gitHead": "4448ce925e9f3af25f78f86c3e28a88145201520"
22
22
  }