@nitra/vite-boot 1.0.13 → 1.0.16
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/package.json +3 -3
- package/src/apollo.js +6 -39
- package/src/sentry.js +11 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nitra/vite-boot",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.16",
|
|
4
4
|
"description": "Vite boot",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
"globals": {
|
|
30
30
|
"__HASURA_ROLE__": "readonly",
|
|
31
31
|
"__SENTRY_DSN__": "readonly",
|
|
32
|
+
"__BRANCH__": "readonly",
|
|
32
33
|
"__GITHUB_SHA__": "readonly"
|
|
33
34
|
}
|
|
34
35
|
},
|
|
@@ -40,11 +41,10 @@
|
|
|
40
41
|
"src"
|
|
41
42
|
],
|
|
42
43
|
"dependencies": {
|
|
43
|
-
"@apollo/client": "^3.5.
|
|
44
|
+
"@apollo/client": "^3.5.10",
|
|
44
45
|
"@nitra/consola": "^1.7.0",
|
|
45
46
|
"@sentry/tracing": "^6.16.1",
|
|
46
47
|
"@sentry/vue": "^6.16.1",
|
|
47
|
-
"graphql": "^16.2.0",
|
|
48
48
|
"graphql-ws": "^5.5.5",
|
|
49
49
|
"petite-vue-i18n": "^9.2.0-beta.26",
|
|
50
50
|
"pinia": "^2.0.9",
|
package/src/apollo.js
CHANGED
|
@@ -1,48 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { ApolloLink, ApolloClient, Observable, InMemoryCache, from } from '@apollo/client/core'
|
|
1
|
+
import { ApolloClient, InMemoryCache, from } from '@apollo/client/core'
|
|
4
2
|
import { onError } from '@apollo/client/link/error'
|
|
5
|
-
import { print } from 'graphql'
|
|
6
3
|
import { createClient } from 'graphql-ws'
|
|
7
4
|
import { createLogger } from '@nitra/consola'
|
|
8
5
|
import { refreshToken } from './token.js'
|
|
6
|
+
import { GraphQLWsLink } from '@apollo/client/link/subscriptions'
|
|
9
7
|
|
|
10
8
|
const consola = createLogger(import.meta.url)
|
|
11
9
|
|
|
12
|
-
|
|
13
|
-
constructor(options) {
|
|
14
|
-
super()
|
|
15
|
-
this.client = createClient(options)
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
request(operation) {
|
|
19
|
-
return new Observable(sink => {
|
|
20
|
-
return this.client.subscribe(
|
|
21
|
-
{ ...operation, query: print(operation.query) },
|
|
22
|
-
{
|
|
23
|
-
next: sink.next.bind(sink),
|
|
24
|
-
complete: sink.complete.bind(sink),
|
|
25
|
-
error: err => {
|
|
26
|
-
if (Array.isArray(err)) {
|
|
27
|
-
// GraphQLError[]
|
|
28
|
-
return sink.error(new Error(err.map(({ message }) => message).join(', ')))
|
|
29
|
-
}
|
|
30
|
-
if (err instanceof CloseEvent) {
|
|
31
|
-
return sink.error(
|
|
32
|
-
new Error(
|
|
33
|
-
`Socket closed with event ${err.code} ${err.reason || ''}` // reason will be available on clean closes only
|
|
34
|
-
)
|
|
35
|
-
)
|
|
36
|
-
}
|
|
37
|
-
return sink.error(err)
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
)
|
|
41
|
-
})
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const wsLink = new WebSocketLink({
|
|
10
|
+
const wsClient = createClient({
|
|
46
11
|
url: `${import.meta.env.VITE_HASURA_PROTOCOL}://${import.meta.env.VITE_HASURA_HOST}/v1/graphql`,
|
|
47
12
|
disablePong: true,
|
|
48
13
|
connectionParams: () => {
|
|
@@ -61,6 +26,8 @@ const wsLink = new WebSocketLink({
|
|
|
61
26
|
}
|
|
62
27
|
})
|
|
63
28
|
|
|
29
|
+
const wsLink = new GraphQLWsLink(wsClient)
|
|
30
|
+
|
|
64
31
|
const errorLink = onError(({ graphQLErrors, networkError, _operation, _forward }) => {
|
|
65
32
|
if (graphQLErrors) {
|
|
66
33
|
for (const err of graphQLErrors) {
|
|
@@ -87,7 +54,7 @@ const errorLink = onError(({ graphQLErrors, networkError, _operation, _forward }
|
|
|
87
54
|
// To retry on network errors, we recommend the RetryLink
|
|
88
55
|
// instead of the onError link. This just logs the error.
|
|
89
56
|
if (networkError) {
|
|
90
|
-
if (networkError?.message
|
|
57
|
+
if (networkError?.message?.match('JWTExpired')) {
|
|
91
58
|
// ретрай токен
|
|
92
59
|
// и якщо цей користувач ще валідний в БД
|
|
93
60
|
// то видавати йому новий токен
|
package/src/sentry.js
CHANGED
|
@@ -5,10 +5,11 @@ import { Integrations } from '@sentry/tracing'
|
|
|
5
5
|
* Ініціалізація Sentry
|
|
6
6
|
*/
|
|
7
7
|
export const bootSentry = (app, router) => {
|
|
8
|
-
|
|
8
|
+
const options = {
|
|
9
9
|
app,
|
|
10
10
|
dsn: __SENTRY_DSN__,
|
|
11
11
|
release: __GITHUB_SHA__,
|
|
12
|
+
ignoreErrors: ['ResizeObserver loop limit exceeded'],
|
|
12
13
|
integrations: [
|
|
13
14
|
new Integrations.BrowserTracing({
|
|
14
15
|
routingInstrumentation: Sentry.vueRouterInstrumentation(router)
|
|
@@ -18,5 +19,13 @@ export const bootSentry = (app, router) => {
|
|
|
18
19
|
// of transactions for performance monitoring.
|
|
19
20
|
// We recommend adjusting this value in production
|
|
20
21
|
tracesSampleRate: 0.1
|
|
21
|
-
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Якщо публікація з різних гілок
|
|
25
|
+
// записуємо в різні енв для фільтрації в сентрі
|
|
26
|
+
if (typeof __BRANCH__ !== 'undefined') {
|
|
27
|
+
options.environment = __BRANCH__
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
Sentry.init(options)
|
|
22
31
|
}
|