@nitra/vite-boot 5.0.3 → 5.0.6

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nitra/vite-boot",
3
- "version": "5.0.3",
3
+ "version": "5.0.6",
4
4
  "description": "Vite boot",
5
5
  "type": "module",
6
6
  "exports": {
@@ -25,9 +25,9 @@
25
25
  "src"
26
26
  ],
27
27
  "dependencies": {
28
- "@apollo/client": "^4.0.9",
28
+ "@apollo/client": "^4.0.11",
29
29
  "@nitra/jwt-decode": "^1.2.0",
30
- "@vue3-apollo/core": "^1.4.1",
30
+ "@vue3-apollo/core": "1.3.*",
31
31
  "graphql-ws": "^6.0.6",
32
32
  "pinia": "^3.0.4",
33
33
  "pinia-plugin-persistedstate": "^4.7.1",
package/src/apollo.js CHANGED
@@ -3,18 +3,21 @@ import { GraphQLWsLink } from '@apollo/client/link/subscriptions'
3
3
  import { getMainDefinition } from '@apollo/client/utilities'
4
4
  import { createClient } from 'graphql-ws'
5
5
  import { checkedToken, cleanToken, user } from './user.js'
6
+
6
7
  export { gql } from '@apollo/client/core'
7
8
  export { apolloPlugin, useApolloClient, useMutation, useQuery, useSubscription } from '@vue3-apollo/core'
8
9
 
10
+ /**
11
+ * Формує заголовки авторизації для запиту
12
+ * @returns {Record<string, string>} Заголовки з токеном та роллю або порожній обʼєкт
13
+ */
9
14
  function getAuthHeaders() {
10
15
  // Якщо є токен - додаємо його в заголовки
11
16
  if (checkedToken) {
12
- const headers = {}
13
-
14
- headers.Authorization = `Bearer ${checkedToken}`
15
- headers['x-hasura-role'] = user.role
16
-
17
- return headers
17
+ return {
18
+ Authorization: `Bearer ${checkedToken}`,
19
+ 'x-hasura-role': user.role
20
+ }
18
21
  }
19
22
 
20
23
  return {}
package/src/token.js CHANGED
@@ -11,7 +11,7 @@ const allowedRoles = import.meta.env.VITE_HASURA_ROLE.split(',')
11
11
  * @returns {{result: 'ok'|'expired'|'cleaned'|'broken-role', decoded?: object}} - Результат перевірки
12
12
  */
13
13
  export function checkToken(token) {
14
- /** @type {{ exp?: number, [k: string]: any }} */
14
+ /** @type {{ exp?: number, [k: string]: unknown }} */
15
15
  const decoded = jwtDecode(token)
16
16
  if (!decoded || !decoded['https://hasura.io/jwt/claims']) {
17
17
  cleanToken()
@@ -53,7 +53,7 @@ export function defaultLogin(decoded, raw) {
53
53
 
54
54
  /**
55
55
  * Автоматичний вхід користувача
56
- * @returns {Promise<void>}
56
+ * @returns {void}
57
57
  */
58
58
  export function autoLogin() {
59
59
  const token = getToken()
package/src/user.js CHANGED
@@ -19,7 +19,7 @@ export function unsetUser() {
19
19
  /**
20
20
  * Встановлює дані користувача з розкодованого JWT
21
21
  * @param {object} decoded - Обʼєкт з Hasura claims розкодованого токена
22
- * @param {String} raw - Raw токен
22
+ * @param {string} raw - Raw токен
23
23
  */
24
24
  export function setUser(decoded, raw = null) {
25
25
  user = decoded
@@ -51,6 +51,11 @@ export function cleanToken() {
51
51
  // видаляємо з localStorage
52
52
  localStorage.removeItem('__session')
53
53
 
54
- // @ts-ignore
55
- document.cookie = `__session=; Max-Age=0; path=/; domain=${import.meta.env.VITE_DOMAIN}`
54
+ if (globalThis.cookieStore && typeof globalThis.cookieStore.delete === 'function') {
55
+ globalThis.cookieStore.delete('__session', { path: '/', domain: import.meta.env.VITE_DOMAIN })
56
+ } else {
57
+ // @ts-ignore
58
+ // eslint-disable-next-line unicorn/no-document-cookie
59
+ document.cookie = `__session=; Max-Age=0; path=/; domain=${import.meta.env.VITE_DOMAIN}`
60
+ }
56
61
  }