codevdesign 1.0.8 → 1.0.9

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,20 +1,18 @@
1
- import { useAppStore } from '@/store/appStore'
2
1
 
3
2
  class RafraichisseurToken {
4
3
  private intervalleEnSecondes = 15
5
4
  private secondesAvantExpirationTokenPourRafraichir = 20
6
5
  private skewSeconds = 5 // marge anti-derives d’horloge
7
6
  private popupAffiche = false
8
- private appStore: ReturnType<typeof useAppStore> | null = null
9
7
  private timerId: number | null = null
10
8
 
11
9
  // Lance une seule fois
12
- public async demarrer(): Promise<void> {
13
- this.appStore = useAppStore()
14
- await this.verifierToken()
10
+ public async demarrer(nomCookie: string | null, urlPortail: string): Promise<void> {
11
+ if (nomCookie == null || nomCookie === '') nomCookie = 'csqc_jeton_secure_expiration'
12
+ await this.verifierToken(nomCookie, urlPortail)
15
13
  if (this.timerId != null) return
16
14
  this.timerId = window.setInterval(() => {
17
- this.verifierToken()
15
+ this.verifierToken(nomCookie, urlPortail)
18
16
  }, this.intervalleEnSecondes * 1000)
19
17
  }
20
18
 
@@ -26,13 +24,12 @@ class RafraichisseurToken {
26
24
  }
27
25
  }
28
26
 
29
- private async verifierToken(): Promise<void> {
30
- if (!this.appStore) this.appStore = useAppStore()
31
- const modele = this.appStore?.appModele
32
- if (this.popupAffiche || !modele) return
33
- const tokenEncode = this.lireCookie(modele.nomCookie)
27
+ private async verifierToken(nomCookie: string, urlPortail: string): Promise<void> {
28
+
29
+ if (this.popupAffiche || !nomCookie) return
30
+ const tokenEncode = this.lireCookie(nomCookie)
34
31
  if (!tokenEncode) {
35
- await this.rafraichir()
32
+ await this.rafraichir(nomCookie, urlPortail)
36
33
  return
37
34
  }
38
35
 
@@ -40,29 +37,27 @@ class RafraichisseurToken {
40
37
  try {
41
38
  token = this.parseJwt(tokenEncode)
42
39
  } catch {
43
- await this.rafraichir()
40
+ await this.rafraichir(nomCookie, urlPortail)
44
41
  return
45
42
  }
46
43
 
47
44
  const exp = Number(token?.exp)
48
45
  if (!Number.isFinite(exp)) {
49
46
  // exp manquant/invalide → tente refresh
50
- await this.rafraichir()
47
+ await this.rafraichir(nomCookie, urlPortail)
51
48
  return
52
49
  }
53
50
 
54
51
  const now = Math.floor(Date.now() / 1000)
55
52
  const refreshAt = exp - this.secondesAvantExpirationTokenPourRafraichir - this.skewSeconds
56
53
  if (now >= refreshAt) {
57
- await this.rafraichir()
54
+ await this.rafraichir(nomCookie, urlPortail)
58
55
  }
59
56
  }
60
57
 
61
- private async rafraichir(): Promise<void> {
62
- if (!this.appStore) this.appStore = useAppStore()
63
- const modele = this.appStore?.appModele
64
- if (!modele) return
65
- const url = this.getRefreshUrl()
58
+ private async rafraichir(nomCookie: string, urlPortail: string): Promise<void> {
59
+ if (!nomCookie) return
60
+ const url = this.getRefreshUrl(urlPortail)
66
61
  const controller = new AbortController()
67
62
  const timeout = setTimeout(() => controller.abort(), 10_000)
68
63
 
@@ -79,20 +74,20 @@ class RafraichisseurToken {
79
74
  // redirection (souvent => login) → traiter comme non auth
80
75
 
81
76
  if (resp.type === 'opaqueredirect' || resp.status === 302) {
82
- this.rafraichirParIframe()
77
+ this.rafraichirParIframe(nomCookie, urlPortail)
83
78
  return
84
79
  }
85
80
 
86
81
  // OK ou No Content: le cookie devrait être réécrit
87
82
  if (resp.status === 200 || resp.status === 204) {
88
- const jeton = this.lireCookie(modele.nomCookie)
89
- if (!jeton) this.rafraichirParIframe()
83
+ const jeton = this.lireCookie(nomCookie)
84
+ if (!jeton) this.rafraichirParIframe(nomCookie, urlPortail)
90
85
  return
91
86
  }
92
87
 
93
88
  // non auth / expiré (401, 419) + IIS timeout (440)
94
89
  if (resp.status === 401 || resp.status === 419 || resp.status === 440) {
95
- this.rafraichirParIframe()
90
+ this.rafraichirParIframe(nomCookie, urlPortail)
96
91
  return
97
92
  }
98
93
 
@@ -106,41 +101,35 @@ class RafraichisseurToken {
106
101
  }
107
102
  }
108
103
 
109
- private rafraichirParIframe() {
110
- if (!this.appStore) this.appStore = useAppStore()
104
+ private rafraichirParIframe(nomCookie: string, urlPortail: string): void {
111
105
  // Pour éviter les cross référence, on créé un iframe qui appel portail et force la MAJ du jeton ou l'invalidation du jeton, si jamais l'utilisateur n'est plus connecté
112
106
  // ajax vers le refresh
113
107
  let iframe = document.createElement('iframe')
114
- const url = this.getRefreshUrl()
108
+ const url = this.getRefreshUrl(urlPortail)
115
109
  iframe.src = `${url}?urlRetour=${encodeURI(window.localStorage.href)}`
116
110
  iframe.id = 'idRafrToken'
117
111
  iframe.style.display = 'none'
118
112
  document.body.appendChild(iframe)
119
113
  iframe.onload = () => {
120
- const jetonCSQC = this.lireCookie(this.appStore!.appModele!.nomCookie)
114
+ const jetonCSQC = this.lireCookie(nomCookie)
121
115
  if (jetonCSQC == null || jetonCSQC === '') {
122
- this.estDeconnecteAzure()
116
+ this.estDeconnecteAzure(urlPortail)
123
117
  }
124
118
 
125
119
  iframe.remove()
126
120
  }
127
121
  }
128
122
 
129
- private estDeconnecteAzure(): void {
123
+ private estDeconnecteAzure(urlPortail: string): void {
130
124
  //on envoie au portail, pas le choix
131
- if (!this.appStore) this.appStore = useAppStore()
132
125
 
133
126
  const retour = encodeURI(window.location.href)
134
- window.open(`${this.appStore.appModele!.urlPortailSeConnecter}?urlRetour=${retour}`, '_self')
127
+ window.open(`${urlPortail}/home/SeConnecter?urlRetour=${retour}`, '_self')
135
128
  return
136
129
  }
137
130
 
138
- public deconnecterPortail(): void {
139
- if (!this.appStore) this.appStore = useAppStore()
140
- const modele = this.appStore?.appModele
141
- if (!modele) return
142
-
143
- window.location.replace(`${modele.urlPortail}deconnecte?urlRetour=${encodeURIComponent(window.location.href)}`)
131
+ public deconnecterPortail(urlPortail: string): void {
132
+ window.location.replace(`${urlPortail}deconnecte?urlRetour=${encodeURIComponent(window.location.href)}`)
144
133
  }
145
134
 
146
135
 
@@ -175,9 +164,9 @@ class RafraichisseurToken {
175
164
  }
176
165
 
177
166
  // URL refresh selon env (dev = proxy Vite ; prod = portail)
178
- private getRefreshUrl(): string {
167
+ private getRefreshUrl(urlPortail: string): string {
179
168
  if (import.meta.env.MODE === 'development') return '/portail-refresh'
180
- return this.appStore!.appModele!.urlPortailRafraichissement
169
+ return urlPortail + '/Home/Refresh'
181
170
  }
182
171
  }
183
172
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codevdesign",
3
- "version": "1.0.8",
3
+ "version": "1.0.9",
4
4
  "description": "Composants Vuetify 3 pour les projets Codev",
5
5
  "files": [
6
6
  "./**/*.vue",