@appnave/quasar-app-extension-asteroid 3.20.0-beta.26-alpha.9 → 3.20.0-beta.26
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/README.md +1 -0
- package/package.json +2 -2
- package/src/boot/api.js +96 -96
- package/src/boot/before-each.js +11 -11
- package/src/boot/debug.js +10 -10
- package/src/boot/error-pages.js +24 -24
- package/src/boot/font-face.js +36 -36
- package/src/boot/loading.js +12 -12
- package/src/boot/notifications.js +45 -45
- package/src/boot/overlay-navigation.js +261 -261
- package/src/boot/query-cache.js +93 -93
- package/src/boot/register.js +8 -8
- package/src/boot/store-adapter.js +5 -5
- package/src/defaults/default-asteroid-config.js +8 -8
- package/src/helpers/asteroid-config-handler.js +22 -22
- package/src/helpers/laravel-echo.js +55 -55
- package/src/helpers/notifications-channels.js +36 -36
- package/src/helpers/on-leader-election-channel.js +23 -23
- package/src/index.js +162 -161
- package/src/index.scss +1 -1
- package/src/install.js +21 -21
- package/src/prompts.js +3 -3
- package/src/templates/css/quasar.variables.scss +4 -4
- package/src/templates/js/asteroid.config.js +44 -44
- package/src/uninstall.js +3 -3
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
../README.md
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@appnave/quasar-app-extension-asteroid",
|
|
3
3
|
"description": "Asteroid",
|
|
4
|
-
"version": "3.20.0-beta.26
|
|
4
|
+
"version": "3.20.0-beta.26",
|
|
5
5
|
"author": "Bild & Vitta <systemteam@bild.com.br>",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"main": "src/index.js",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@appnave/quasar-app-extension-asteroid": "file:",
|
|
38
|
-
"@appnave/quasar-ui-asteroid": "3.20.0-beta.26
|
|
38
|
+
"@appnave/quasar-ui-asteroid": "3.20.0-beta.26",
|
|
39
39
|
"@bildvitta/store-adapter": "^1.0.0",
|
|
40
40
|
"execa": "^7.1.1",
|
|
41
41
|
"fontfaceobserver": "^2.3.0",
|
package/src/boot/api.js
CHANGED
|
@@ -1,96 +1,96 @@
|
|
|
1
|
-
import { camelizeKeys, decamelizeKeys } from 'humps'
|
|
2
|
-
|
|
3
|
-
import asteroidConfig from 'asteroid-config'
|
|
4
|
-
|
|
5
|
-
function getBaseURL (isProduction) {
|
|
6
|
-
// Permite sobrescrever a URL base da API via query string, útil para ambiente de preview.
|
|
7
|
-
const previewURL = new URLSearchParams(window.location.search).get('$base')
|
|
8
|
-
|
|
9
|
-
// TODO: Validar variavel de ambiente se é produção.
|
|
10
|
-
if (previewURL && !isProduction) {
|
|
11
|
-
try {
|
|
12
|
-
const { hostname, protocol } = new URL(previewURL)
|
|
13
|
-
|
|
14
|
-
// Somente permite URLs seguras (https) e do domínio nave.dev.br para evitar possíveis ataques de SSRF.
|
|
15
|
-
if (protocol === 'https:' && hostname.endsWith('.nave.dev.br')) return previewURL
|
|
16
|
-
} catch {}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
// Caso não haja uma URL de preview válida, utiliza a URL base definida nas variáveis de ambiente ou locahost.
|
|
20
|
-
return process.env.SERVER_BASE_URL || '/'
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export default async ({ app, router }) => {
|
|
24
|
-
const api = app.config.globalProperties.$axios
|
|
25
|
-
const isProduction = process.env.ENVIRONMENT === 'production'
|
|
26
|
-
|
|
27
|
-
// Defaults
|
|
28
|
-
api.defaults.baseURL = getBaseURL(isProduction)
|
|
29
|
-
|
|
30
|
-
if (!isProduction) {
|
|
31
|
-
/**
|
|
32
|
-
* Permite que parâmetros de query string iniciados com $ sejam propagados para todas as rotas,
|
|
33
|
-
* útil para ambiente de preview.
|
|
34
|
-
*/
|
|
35
|
-
router.beforeEach((to, from, next) => {
|
|
36
|
-
// Extrai os parâmetros de query string iniciados com $ da rota de origem (from).
|
|
37
|
-
const dollarParams = Object.fromEntries(Object.entries(from.query).filter(([key]) => key.startsWith('$')))
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Valida se há algum parâmetro de query string iniciado com $ que esteja presente
|
|
41
|
-
* na rota de origem (from) mas ausente na rota de destino (to).
|
|
42
|
-
*/
|
|
43
|
-
const hasMissingDollarParams = Object.keys(dollarParams).some(key => !(key in to.query))
|
|
44
|
-
|
|
45
|
-
if (hasMissingDollarParams) {
|
|
46
|
-
next({ ...to, query: { ...dollarParams, ...to.query } })
|
|
47
|
-
} else {
|
|
48
|
-
next()
|
|
49
|
-
}
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
api.interceptors.request.use(config => {
|
|
53
|
-
if (!config.params) return config
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Remove os parâmetros de query string iniciados com $ antes de enviar a requisição para a API, pois eles
|
|
57
|
-
* são utilizados apenas para controlar a chave do back end por exemplo.
|
|
58
|
-
*/
|
|
59
|
-
config.params = Object.fromEntries(Object.entries(config.params).filter(([key]) => !key.startsWith('$')))
|
|
60
|
-
|
|
61
|
-
return config
|
|
62
|
-
})
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
api.defaults.timeout = asteroidConfig.api.serverTimeout
|
|
66
|
-
|
|
67
|
-
// Transformers
|
|
68
|
-
api.defaults.transformResponse = [
|
|
69
|
-
...api.defaults.transformResponse,
|
|
70
|
-
|
|
71
|
-
data => camelizeKeys(data, (key, convert) =>
|
|
72
|
-
/^\D+$/.test(key) ? convert(key) : key
|
|
73
|
-
)
|
|
74
|
-
]
|
|
75
|
-
|
|
76
|
-
api.defaults.transformRequest = [
|
|
77
|
-
data => {
|
|
78
|
-
if (data instanceof FormData) {
|
|
79
|
-
return data
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return decamelizeKeys(data, (key, convert, options) =>
|
|
83
|
-
/^\D+$/.test(key) ? convert(key, options) : key
|
|
84
|
-
)
|
|
85
|
-
},
|
|
86
|
-
|
|
87
|
-
...api.defaults.transformRequest
|
|
88
|
-
]
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Adicionado para que componentes que utilize o Composition API possam ter acesso a instancia do
|
|
92
|
-
* axios que contém as configurações necessárias da aplicação, uma vez que a utilização de provide
|
|
93
|
-
* é a forma recomendada para trabalhar com variavéis globais.
|
|
94
|
-
*/
|
|
95
|
-
app.provide('axios', api)
|
|
96
|
-
}
|
|
1
|
+
import { camelizeKeys, decamelizeKeys } from 'humps'
|
|
2
|
+
|
|
3
|
+
import asteroidConfig from 'asteroid-config'
|
|
4
|
+
|
|
5
|
+
function getBaseURL (isProduction) {
|
|
6
|
+
// Permite sobrescrever a URL base da API via query string, útil para ambiente de preview.
|
|
7
|
+
const previewURL = new URLSearchParams(window.location.search).get('$base')
|
|
8
|
+
|
|
9
|
+
// TODO: Validar variavel de ambiente se é produção.
|
|
10
|
+
if (previewURL && !isProduction) {
|
|
11
|
+
try {
|
|
12
|
+
const { hostname, protocol } = new URL(previewURL)
|
|
13
|
+
|
|
14
|
+
// Somente permite URLs seguras (https) e do domínio nave.dev.br para evitar possíveis ataques de SSRF.
|
|
15
|
+
if (protocol === 'https:' && hostname.endsWith('.nave.dev.br')) return previewURL
|
|
16
|
+
} catch {}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Caso não haja uma URL de preview válida, utiliza a URL base definida nas variáveis de ambiente ou locahost.
|
|
20
|
+
return process.env.SERVER_BASE_URL || '/'
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export default async ({ app, router }) => {
|
|
24
|
+
const api = app.config.globalProperties.$axios
|
|
25
|
+
const isProduction = process.env.ENVIRONMENT === 'production'
|
|
26
|
+
|
|
27
|
+
// Defaults
|
|
28
|
+
api.defaults.baseURL = getBaseURL(isProduction)
|
|
29
|
+
|
|
30
|
+
if (!isProduction) {
|
|
31
|
+
/**
|
|
32
|
+
* Permite que parâmetros de query string iniciados com $ sejam propagados para todas as rotas,
|
|
33
|
+
* útil para ambiente de preview.
|
|
34
|
+
*/
|
|
35
|
+
router.beforeEach((to, from, next) => {
|
|
36
|
+
// Extrai os parâmetros de query string iniciados com $ da rota de origem (from).
|
|
37
|
+
const dollarParams = Object.fromEntries(Object.entries(from.query).filter(([key]) => key.startsWith('$')))
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Valida se há algum parâmetro de query string iniciado com $ que esteja presente
|
|
41
|
+
* na rota de origem (from) mas ausente na rota de destino (to).
|
|
42
|
+
*/
|
|
43
|
+
const hasMissingDollarParams = Object.keys(dollarParams).some(key => !(key in to.query))
|
|
44
|
+
|
|
45
|
+
if (hasMissingDollarParams) {
|
|
46
|
+
next({ ...to, query: { ...dollarParams, ...to.query } })
|
|
47
|
+
} else {
|
|
48
|
+
next()
|
|
49
|
+
}
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
api.interceptors.request.use(config => {
|
|
53
|
+
if (!config.params) return config
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Remove os parâmetros de query string iniciados com $ antes de enviar a requisição para a API, pois eles
|
|
57
|
+
* são utilizados apenas para controlar a chave do back end por exemplo.
|
|
58
|
+
*/
|
|
59
|
+
config.params = Object.fromEntries(Object.entries(config.params).filter(([key]) => !key.startsWith('$')))
|
|
60
|
+
|
|
61
|
+
return config
|
|
62
|
+
})
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
api.defaults.timeout = asteroidConfig.api.serverTimeout
|
|
66
|
+
|
|
67
|
+
// Transformers
|
|
68
|
+
api.defaults.transformResponse = [
|
|
69
|
+
...api.defaults.transformResponse,
|
|
70
|
+
|
|
71
|
+
data => camelizeKeys(data, (key, convert) =>
|
|
72
|
+
/^\D+$/.test(key) ? convert(key) : key
|
|
73
|
+
)
|
|
74
|
+
]
|
|
75
|
+
|
|
76
|
+
api.defaults.transformRequest = [
|
|
77
|
+
data => {
|
|
78
|
+
if (data instanceof FormData) {
|
|
79
|
+
return data
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return decamelizeKeys(data, (key, convert, options) =>
|
|
83
|
+
/^\D+$/.test(key) ? convert(key, options) : key
|
|
84
|
+
)
|
|
85
|
+
},
|
|
86
|
+
|
|
87
|
+
...api.defaults.transformRequest
|
|
88
|
+
]
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Adicionado para que componentes que utilize o Composition API possam ter acesso a instancia do
|
|
92
|
+
* axios que contém as configurações necessárias da aplicação, uma vez que a utilização de provide
|
|
93
|
+
* é a forma recomendada para trabalhar com variavéis globais.
|
|
94
|
+
*/
|
|
95
|
+
app.provide('axios', api)
|
|
96
|
+
}
|
package/src/boot/before-each.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { useHistory, setDefaultFiltersBeforeEach } from 'asteroid'
|
|
2
|
-
|
|
3
|
-
export default ({ router }) => {
|
|
4
|
-
router.beforeEach((to, from, next) => {
|
|
5
|
-
const { addRoute } = useHistory()
|
|
6
|
-
|
|
7
|
-
addRoute(to)
|
|
8
|
-
|
|
9
|
-
setDefaultFiltersBeforeEach(to, from, next)
|
|
10
|
-
})
|
|
11
|
-
}
|
|
1
|
+
import { useHistory, setDefaultFiltersBeforeEach } from 'asteroid'
|
|
2
|
+
|
|
3
|
+
export default ({ router }) => {
|
|
4
|
+
router.beforeEach((to, from, next) => {
|
|
5
|
+
const { addRoute } = useHistory()
|
|
6
|
+
|
|
7
|
+
addRoute(to)
|
|
8
|
+
|
|
9
|
+
setDefaultFiltersBeforeEach(to, from, next)
|
|
10
|
+
})
|
|
11
|
+
}
|
package/src/boot/debug.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { handleProcess } from 'asteroid'
|
|
2
|
-
|
|
3
|
-
import debug from 'debug'
|
|
4
|
-
|
|
5
|
-
export default async () => {
|
|
6
|
-
const debuggingEnv = handleProcess(() => process.env.DEBUGGING, false)
|
|
7
|
-
const debugEnv = handleProcess(() => process.env.DEBUG, '')
|
|
8
|
-
|
|
9
|
-
debug.enable(debuggingEnv && !debugEnv ? 'asteroid-*:*' : debugEnv)
|
|
10
|
-
}
|
|
1
|
+
import { handleProcess } from 'asteroid'
|
|
2
|
+
|
|
3
|
+
import debug from 'debug'
|
|
4
|
+
|
|
5
|
+
export default async () => {
|
|
6
|
+
const debuggingEnv = handleProcess(() => process.env.DEBUGGING, false)
|
|
7
|
+
const debugEnv = handleProcess(() => process.env.DEBUG, '')
|
|
8
|
+
|
|
9
|
+
debug.enable(debuggingEnv && !debugEnv ? 'asteroid-*:*' : debugEnv)
|
|
10
|
+
}
|
package/src/boot/error-pages.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
export default function ({ router }) {
|
|
2
|
-
const routes = [
|
|
3
|
-
{
|
|
4
|
-
name: 'Forbidden',
|
|
5
|
-
path: '/',
|
|
6
|
-
component: () => import('@appnave/quasar-ui-asteroid/src/pages/Forbidden.vue')
|
|
7
|
-
},
|
|
8
|
-
{
|
|
9
|
-
name: 'ServerError',
|
|
10
|
-
path: '/',
|
|
11
|
-
component: () => import('@appnave/quasar-ui-asteroid/src/pages/ServerError.vue')
|
|
12
|
-
}
|
|
13
|
-
]
|
|
14
|
-
|
|
15
|
-
if (process.env.MODE !== 'ssr') {
|
|
16
|
-
routes.push({
|
|
17
|
-
name: 'NotFound',
|
|
18
|
-
path: '/:catchAll(.*)*',
|
|
19
|
-
component: () => import('@appnave/quasar-ui-asteroid/src/pages/NotFound.vue')
|
|
20
|
-
})
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
routes.forEach(route => router.addRoute(route))
|
|
24
|
-
}
|
|
1
|
+
export default function ({ router }) {
|
|
2
|
+
const routes = [
|
|
3
|
+
{
|
|
4
|
+
name: 'Forbidden',
|
|
5
|
+
path: '/',
|
|
6
|
+
component: () => import('@appnave/quasar-ui-asteroid/src/pages/Forbidden.vue')
|
|
7
|
+
},
|
|
8
|
+
{
|
|
9
|
+
name: 'ServerError',
|
|
10
|
+
path: '/',
|
|
11
|
+
component: () => import('@appnave/quasar-ui-asteroid/src/pages/ServerError.vue')
|
|
12
|
+
}
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
if (process.env.MODE !== 'ssr') {
|
|
16
|
+
routes.push({
|
|
17
|
+
name: 'NotFound',
|
|
18
|
+
path: '/:catchAll(.*)*',
|
|
19
|
+
component: () => import('@appnave/quasar-ui-asteroid/src/pages/NotFound.vue')
|
|
20
|
+
})
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
routes.forEach(route => router.addRoute(route))
|
|
24
|
+
}
|
package/src/boot/font-face.js
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
import FontFaceObserver from 'fontfaceobserver'
|
|
2
|
-
import asteroidConfig from 'asteroid-config'
|
|
3
|
-
|
|
4
|
-
export default async () => {
|
|
5
|
-
function setFontFaceObserver () {
|
|
6
|
-
const font = new FontFaceObserver('Material Symbols Rounded')
|
|
7
|
-
|
|
8
|
-
const bodyClass = 'icons-is-loading'
|
|
9
|
-
|
|
10
|
-
const removeClass = () => document.body.classList.remove(bodyClass)
|
|
11
|
-
|
|
12
|
-
document.body.classList.add(bodyClass)
|
|
13
|
-
|
|
14
|
-
font.load(null, 60000).then(removeClass, removeClass)
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function fontFaceEventHandler (event) {
|
|
18
|
-
if (event.data.type === 'updateUser') {
|
|
19
|
-
setFontFaceObserver()
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* após escutar a primeira vez, já remove o listener para não executar novamente
|
|
23
|
-
* caso o evento "updateUser" seja executado novamente.
|
|
24
|
-
*/
|
|
25
|
-
window.removeEventListener('message', fontFaceEventHandler)
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (asteroidConfig.framework?.fonts?.observer?.waitForUserAuthenticate) {
|
|
30
|
-
window.addEventListener('message', fontFaceEventHandler)
|
|
31
|
-
|
|
32
|
-
return
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
setFontFaceObserver()
|
|
36
|
-
}
|
|
1
|
+
import FontFaceObserver from 'fontfaceobserver'
|
|
2
|
+
import asteroidConfig from 'asteroid-config'
|
|
3
|
+
|
|
4
|
+
export default async () => {
|
|
5
|
+
function setFontFaceObserver () {
|
|
6
|
+
const font = new FontFaceObserver('Material Symbols Rounded')
|
|
7
|
+
|
|
8
|
+
const bodyClass = 'icons-is-loading'
|
|
9
|
+
|
|
10
|
+
const removeClass = () => document.body.classList.remove(bodyClass)
|
|
11
|
+
|
|
12
|
+
document.body.classList.add(bodyClass)
|
|
13
|
+
|
|
14
|
+
font.load(null, 60000).then(removeClass, removeClass)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function fontFaceEventHandler (event) {
|
|
18
|
+
if (event.data.type === 'updateUser') {
|
|
19
|
+
setFontFaceObserver()
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* após escutar a primeira vez, já remove o listener para não executar novamente
|
|
23
|
+
* caso o evento "updateUser" seja executado novamente.
|
|
24
|
+
*/
|
|
25
|
+
window.removeEventListener('message', fontFaceEventHandler)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (asteroidConfig.framework?.fonts?.observer?.waitForUserAuthenticate) {
|
|
30
|
+
window.addEventListener('message', fontFaceEventHandler)
|
|
31
|
+
|
|
32
|
+
return
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
setFontFaceObserver()
|
|
36
|
+
}
|
package/src/boot/loading.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { Loading } from 'quasar'
|
|
2
|
-
|
|
3
|
-
export default () => {
|
|
4
|
-
Loading.setDefaults({
|
|
5
|
-
backgroundColor: 'white',
|
|
6
|
-
boxClass: 'text-body1',
|
|
7
|
-
customClass: 'qas-loading',
|
|
8
|
-
message: 'Carregando...',
|
|
9
|
-
messageColor: 'primary',
|
|
10
|
-
spinnerColor: 'primary'
|
|
11
|
-
})
|
|
12
|
-
}
|
|
1
|
+
import { Loading } from 'quasar'
|
|
2
|
+
|
|
3
|
+
export default () => {
|
|
4
|
+
Loading.setDefaults({
|
|
5
|
+
backgroundColor: 'white',
|
|
6
|
+
boxClass: 'text-body1',
|
|
7
|
+
customClass: 'qas-loading',
|
|
8
|
+
message: 'Carregando...',
|
|
9
|
+
messageColor: 'primary',
|
|
10
|
+
spinnerColor: 'primary'
|
|
11
|
+
})
|
|
12
|
+
}
|
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Este boot só é adicionado dinamicamente na aplicação caso a opção
|
|
3
|
-
* "asteroidConfig.framework.featureToggle.useNotifications" esteja ativada.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { isLocalDevelopment } from 'asteroid'
|
|
7
|
-
|
|
8
|
-
import onLeaderElectionChannel from '../helpers/on-leader-election-channel.js'
|
|
9
|
-
import { setLaravelEcho, setLaravelEchoListener } from '../helpers/laravel-echo.js'
|
|
10
|
-
import { setNotificationsChannelListener, setNotificationsUtilsChannel } from '../helpers/notifications-channels.js'
|
|
11
|
-
|
|
12
|
-
import { LocalStorage } from 'quasar'
|
|
13
|
-
|
|
14
|
-
export default () => {
|
|
15
|
-
/**
|
|
16
|
-
* Se estivermos em desenvolvimento local, não vamos estabelecer conexão com o servidor.
|
|
17
|
-
*/
|
|
18
|
-
if (isLocalDevelopment()) return
|
|
19
|
-
|
|
20
|
-
window.addEventListener('message', ({ data }) => {
|
|
21
|
-
if (data.type !== 'updateUser') return
|
|
22
|
-
|
|
23
|
-
const user = data.user
|
|
24
|
-
const accessToken = LocalStorage.getItem('accessToken')
|
|
25
|
-
|
|
26
|
-
const hasBearerPrefix = accessToken.startsWith('Bearer ')
|
|
27
|
-
const userToken = hasBearerPrefix ? accessToken : `Bearer ${accessToken}`
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Aqui vamos estabelecer a conexão com o servidor apenas na tab (aba) líder.
|
|
31
|
-
* Vamos escutar por novas notificações, sempre que receber uma notificação,
|
|
32
|
-
* iremos enviar via BroadcastChannel.postMessage().
|
|
33
|
-
*/
|
|
34
|
-
onLeaderElectionChannel(channel => {
|
|
35
|
-
setLaravelEcho(userToken)
|
|
36
|
-
setLaravelEchoListener({ user, channel })
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Controle de notificações por comunicação entre abas (BroadcastChannel).
|
|
41
|
-
*/
|
|
42
|
-
setNotificationsChannelListener()
|
|
43
|
-
setNotificationsUtilsChannel()
|
|
44
|
-
})
|
|
45
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Este boot só é adicionado dinamicamente na aplicação caso a opção
|
|
3
|
+
* "asteroidConfig.framework.featureToggle.useNotifications" esteja ativada.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { isLocalDevelopment } from 'asteroid'
|
|
7
|
+
|
|
8
|
+
import onLeaderElectionChannel from '../helpers/on-leader-election-channel.js'
|
|
9
|
+
import { setLaravelEcho, setLaravelEchoListener } from '../helpers/laravel-echo.js'
|
|
10
|
+
import { setNotificationsChannelListener, setNotificationsUtilsChannel } from '../helpers/notifications-channels.js'
|
|
11
|
+
|
|
12
|
+
import { LocalStorage } from 'quasar'
|
|
13
|
+
|
|
14
|
+
export default () => {
|
|
15
|
+
/**
|
|
16
|
+
* Se estivermos em desenvolvimento local, não vamos estabelecer conexão com o servidor.
|
|
17
|
+
*/
|
|
18
|
+
if (isLocalDevelopment()) return
|
|
19
|
+
|
|
20
|
+
window.addEventListener('message', ({ data }) => {
|
|
21
|
+
if (data.type !== 'updateUser') return
|
|
22
|
+
|
|
23
|
+
const user = data.user
|
|
24
|
+
const accessToken = LocalStorage.getItem('accessToken')
|
|
25
|
+
|
|
26
|
+
const hasBearerPrefix = accessToken.startsWith('Bearer ')
|
|
27
|
+
const userToken = hasBearerPrefix ? accessToken : `Bearer ${accessToken}`
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Aqui vamos estabelecer a conexão com o servidor apenas na tab (aba) líder.
|
|
31
|
+
* Vamos escutar por novas notificações, sempre que receber uma notificação,
|
|
32
|
+
* iremos enviar via BroadcastChannel.postMessage().
|
|
33
|
+
*/
|
|
34
|
+
onLeaderElectionChannel(channel => {
|
|
35
|
+
setLaravelEcho(userToken)
|
|
36
|
+
setLaravelEchoListener({ user, channel })
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Controle de notificações por comunicação entre abas (BroadcastChannel).
|
|
41
|
+
*/
|
|
42
|
+
setNotificationsChannelListener()
|
|
43
|
+
setNotificationsUtilsChannel()
|
|
44
|
+
})
|
|
45
|
+
}
|