codevdesign 1.0.42 → 1.0.43

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/index.ts CHANGED
@@ -1,75 +1,75 @@
1
- import csqcAlerteErreur from './composants/csqcAlerteErreur.vue'
2
- import csqcDialogue from './composants/csqcDialogue.vue'
3
- import csqcOptionSwitch from './composants/csqcOptionSwitch.vue'
4
- import csqcRecherche from './composants/csqcRecherche.vue'
5
- import csqcSnackbar from './composants/csqcSnackbar.vue'
6
- import csqcTiroir from './composants/csqcTiroir.vue'
7
- import pivEntete from './composants/gabarit/pivEntete.vue'
8
- import pivFooter from './composants/gabarit/pivPiedPage.vue'
9
- import csqcMenu from './composants/gabarit/csqcMenu.vue'
10
- import csqcConfirmation from './composants/csqcConfirmation.vue'
11
- import csqcSaisie from './composants/csqcModaleSaisie.vue'
12
- import csqcDate from './composants/csqcDate.vue'
13
- import csqcTable from './composants/csqcTable/csqcTable.vue'
14
- import csqcCodeBudgetaire from './composants/csqcCodeBudgetaireGenerique.vue'
15
- import csqcChaise from './composants/csqcChaise/chaiseConteneur.vue'
16
- import csqcAide from './composants/csqcAide.vue'
17
- import csqcEntete from './composants/csqcEntete.vue'
18
- import csqcTexteBilingue from './composants/csqcTexteBilingue.vue'
19
-
20
- import csqcEditeurTexteRiche from './composants/csqcEditeurTexteRiche.vue'
21
- import csqcImportCSV from './composants/csqcImportCSV.vue'
22
- import csqcRechercheUtilisateur from './composants/csqcRechercheUtilisateur.vue'
23
- import validateurs from './composants/validateurs'
24
-
25
- // modèles
26
- import NotificationGabaritDefaut from './modeles/notificationGabaritDefaut'
27
- import modeleSnackbar from './modeles/composants/snackbar'
28
- import modeleDatatableColonne from './modeles/composants/datatableColonne'
29
- import apiReponse from './modeles/apiReponse'
30
- import data from './modeles/data'
31
- import response from './modeles/response'
32
-
33
- // outils
34
- import csqcRafraichisseurToken from './outils/rafraichisseurToken'
35
- import csqcOutils from './outils/csqcOutils'
36
-
37
- // i18n
38
- import csqcEn from './locales/en.json'
39
- import csqcFr from './locales/fr.json'
40
-
41
-
42
- export {
43
- csqcFr,
44
- csqcEn,
45
- csqcAlerteErreur,
46
- csqcDialogue,
47
- csqcConfirmation,
48
- csqcSaisie,
49
- csqcDate,
50
- csqcOptionSwitch,
51
- csqcRecherche,
52
- csqcSnackbar,
53
- csqcTable,
54
- csqcTiroir,
55
- csqcMenu,
56
- csqcCodeBudgetaire,
57
- csqcChaise,
58
- pivFooter,
59
- pivEntete,
60
- csqcAide,
61
- csqcEntete,
62
- csqcTexteBilingue,
63
- csqcEditeurTexteRiche,
64
- validateurs,
65
- csqcImportCSV,
66
- csqcRechercheUtilisateur,
67
- csqcRafraichisseurToken,
68
- csqcOutils,
69
- modeleSnackbar,
70
- modeleDatatableColonne as colonne,
71
- apiReponse,
72
- data,
73
- response,
74
- NotificationGabaritDefaut,
75
- }
1
+ import csqcAlerteErreur from './composants/csqcAlerteErreur.vue'
2
+ import csqcDialogue from './composants/csqcDialogue.vue'
3
+ import csqcOptionSwitch from './composants/csqcOptionSwitch.vue'
4
+ import csqcRecherche from './composants/csqcRecherche.vue'
5
+ import csqcSnackbar from './composants/csqcSnackbar.vue'
6
+ import csqcTiroir from './composants/csqcTiroir.vue'
7
+ import pivEntete from './composants/gabarit/pivEntete.vue'
8
+ import pivFooter from './composants/gabarit/pivPiedPage.vue'
9
+ import csqcMenu from './composants/gabarit/csqcMenu.vue'
10
+ import csqcConfirmation from './composants/csqcConfirmation.vue'
11
+ import csqcSaisie from './composants/csqcModaleSaisie.vue'
12
+ import csqcDate from './composants/csqcDate.vue'
13
+ import csqcTable from './composants/csqcTable/csqcTable.vue'
14
+ import csqcCodeBudgetaire from './composants/csqcCodeBudgetaireGenerique.vue'
15
+ import csqcChaise from './composants/csqcChaise/chaiseConteneur.vue'
16
+ import csqcAide from './composants/csqcAide.vue'
17
+ import csqcEntete from './composants/csqcEntete.vue'
18
+ import csqcTexteBilingue from './composants/csqcTexteBilingue.vue'
19
+
20
+ import csqcEditeurTexteRiche from './composants/csqcEditeurTexteRiche.vue'
21
+ import csqcImportCSV from './composants/csqcImportCSV.vue'
22
+ import csqcRechercheUtilisateur from './composants/csqcRechercheUtilisateur.vue'
23
+ import validateurs from './composants/validateurs'
24
+
25
+ // modèles
26
+ import NotificationGabaritDefaut from './modeles/notificationGabaritDefaut'
27
+ import modeleSnackbar from './modeles/composants/snackbar'
28
+ import modeleDatatableColonne from './modeles/composants/datatableColonne'
29
+ import apiReponse from './modeles/apiReponse'
30
+ import data from './modeles/data'
31
+ import response from './modeles/response'
32
+
33
+ // outils
34
+ import csqcRafraichisseurToken from './outils/rafraichisseurToken'
35
+ import csqcOutils from './outils/csqcOutils'
36
+
37
+ // i18n
38
+ import csqcEn from './locales/en.json'
39
+ import csqcFr from './locales/fr.json'
40
+
41
+
42
+ export {
43
+ csqcFr,
44
+ csqcEn,
45
+ csqcAlerteErreur,
46
+ csqcDialogue,
47
+ csqcConfirmation,
48
+ csqcSaisie,
49
+ csqcDate,
50
+ csqcOptionSwitch,
51
+ csqcRecherche,
52
+ csqcSnackbar,
53
+ csqcTable,
54
+ csqcTiroir,
55
+ csqcMenu,
56
+ csqcCodeBudgetaire,
57
+ csqcChaise,
58
+ pivFooter,
59
+ pivEntete,
60
+ csqcAide,
61
+ csqcEntete,
62
+ csqcTexteBilingue,
63
+ csqcEditeurTexteRiche,
64
+ validateurs,
65
+ csqcImportCSV,
66
+ csqcRechercheUtilisateur,
67
+ csqcRafraichisseurToken,
68
+ csqcOutils,
69
+ modeleSnackbar,
70
+ modeleDatatableColonne as colonne,
71
+ apiReponse,
72
+ data,
73
+ response,
74
+ NotificationGabaritDefaut,
75
+ }
@@ -1,187 +1,187 @@
1
- class RafraichisseurToken {
2
- private intervalleEnSecondes = 15
3
- private secondesAvantExpirationTokenPourRafraichir = 20
4
- private skewSeconds = 5 // marge anti-derives d’horloge
5
- private popupAffiche = false
6
- private timerId: number | null = null
7
-
8
- // Lance une seule fois
9
- public async demarrer(nomTemoin: string | null, urlPortail: string): Promise<void> {
10
- urlPortail = urlPortail.replace(/\/+$/, '')
11
- if (nomTemoin == null || nomTemoin === '') nomTemoin = 'csqc_jeton_secure_expiration'
12
- await this.verifierJeton(nomTemoin, urlPortail)
13
- if (this.timerId != null) return
14
- this.timerId = window.setInterval(() => {
15
- this.verifierJeton(nomTemoin, urlPortail)
16
- }, this.intervalleEnSecondes * 1000)
17
- }
18
-
19
- // Permet d’arrêter le timer (ex: au logout / destroy)
20
- public arreter(): void {
21
- if (this.timerId != null) {
22
- clearInterval(this.timerId)
23
- this.timerId = null
24
- }
25
- }
26
-
27
- public existeJeton = (nomTemoin: string) => {
28
- return this.estJetonValide(nomTemoin)
29
- }
30
-
31
- private async verifierJeton(nomTemoin: string, urlPortail: string): Promise<void> {
32
- if (this.popupAffiche) return
33
-
34
- if (!this.estJetonValide(nomTemoin)) {
35
- this.rafraichir(nomTemoin, urlPortail)
36
- return
37
- }
38
- }
39
-
40
- private estJetonValide(nomTemoin: string): boolean {
41
- if (this.popupAffiche || !nomTemoin) return true //On fait semblant que c'est valide pour ne pas provoquer un autre affichage du popup.
42
-
43
- const tokenEncode = this.lireCookie(nomTemoin)
44
- if (!tokenEncode) {
45
- return false
46
- }
47
-
48
- let token: any
49
- try {
50
- token = this.parseJwt(tokenEncode)
51
- } catch {
52
- return false
53
- }
54
-
55
- const exp = Number(token?.exp)
56
- if (!Number.isFinite(exp)) {
57
- // exp manquant/invalide → tente refresh
58
-
59
- return false
60
- }
61
-
62
- const now = Math.floor(Date.now() / 1000)
63
- const refreshAt = exp - this.secondesAvantExpirationTokenPourRafraichir - this.skewSeconds
64
- if (now >= refreshAt) {
65
- return false
66
- }
67
-
68
- return true
69
- }
70
-
71
- private async rafraichir(nomCookie: string, urlPortail: string): Promise<void> {
72
- if (!nomCookie) return
73
- const url = this.getRefreshUrl(urlPortail)
74
- const controller = new AbortController()
75
- const timeout = setTimeout(() => controller.abort(), 10_000)
76
-
77
- try {
78
- //Première tentative sans iframe, pour la majorité des cas.
79
- const resp = await fetch(url, {
80
- method: 'POST',
81
- credentials: 'include',
82
- headers: { Accept: 'application/json' },
83
- redirect: 'manual',
84
- signal: controller.signal,
85
- })
86
-
87
- // redirection (souvent => login) → traiter comme non auth
88
-
89
- if (resp.type === 'opaqueredirect' || resp.status === 302) {
90
- this.rafraichirParIframe(nomCookie, urlPortail)
91
- return
92
- }
93
-
94
- // OK ou No Content: le cookie devrait être réécrit
95
- if (resp.status === 200 || resp.status === 204) {
96
- const jeton = this.lireCookie(nomCookie)
97
- if (!jeton) this.rafraichirParIframe(nomCookie, urlPortail)
98
- return
99
- }
100
-
101
- // non auth / expiré (401, 419) + IIS timeout (440)
102
- if (resp.status === 401 || resp.status === 419 || resp.status === 440) {
103
- this.rafraichirParIframe(nomCookie, urlPortail)
104
- return
105
- }
106
-
107
- console.warn('Rafraichisseur token: statut inattendu', resp.status)
108
- } catch (err: any) {
109
- if (err?.name === 'AbortError') console.warn('RafraichisseurToken timeout')
110
- else console.error('Erreur rafraichisseur de token', err)
111
- // on réessaiera au prochain tick
112
- } finally {
113
- clearTimeout(timeout)
114
- }
115
- }
116
-
117
- private rafraichirParIframe(nomCookie: string, urlPortail: string): void {
118
- // 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é
119
- // ajax vers le refresh
120
- let iframe = document.createElement('iframe')
121
- const url = this.getRefreshUrl(urlPortail)
122
- iframe.src = `${url}?urlRetour=${encodeURI(window.localStorage.href)}`
123
- iframe.id = 'idRafrToken'
124
- iframe.style.display = 'none'
125
- document.body.appendChild(iframe)
126
- iframe.onload = () => {
127
- const jetonCSQC = this.lireCookie(nomCookie)
128
- if (jetonCSQC == null || jetonCSQC === '') {
129
- this.estDeconnecteAzure(urlPortail)
130
- }
131
-
132
- iframe.remove()
133
- }
134
- }
135
-
136
- private estDeconnecteAzure(urlPortail: string): void {
137
- //on envoie au portail, pas le choix
138
-
139
- const retour = encodeURI(window.location.href)
140
- window.open(`${urlPortail}/home/SeConnecter?urlRetour=${retour}`, '_self')
141
- return
142
- }
143
-
144
- public deconnecterPortail(urlPortail: string): void {
145
- window.location.replace(`${urlPortail}/deconnecte?urlRetour=${encodeURIComponent(window.location.href)}`)
146
- }
147
-
148
- private lireCookie(nom: string): string | null {
149
- if (!document.cookie) return null
150
- const cookies = document.cookie.split(';').map(c => c.trim())
151
- for (const cookie of cookies) {
152
- if (cookie.startsWith(`${nom}=`)) {
153
- try {
154
- return decodeURIComponent(cookie.substring(nom.length + 1))
155
- } catch {
156
- return cookie.substring(nom.length + 1)
157
- }
158
- }
159
- }
160
- return null
161
- }
162
-
163
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
164
- private parseJwt(token: string): any {
165
- const parts = token.split('.')
166
- const base64Url = parts[1]
167
- if (!base64Url) throw new Error('Invalid JWT format')
168
- const base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/')
169
- const jsonPayload = decodeURIComponent(
170
- atob(base64)
171
- .split('')
172
- .map(c => `%${`00${c.charCodeAt(0).toString(16)}`.slice(-2)}`)
173
- .join(''),
174
- )
175
- return JSON.parse(jsonPayload)
176
- }
177
-
178
- // URL refresh selon env (dev = proxy Vite ; prod = portail)
179
- private getRefreshUrl(urlPortail: string): string {
180
- if (import.meta.env.MODE === 'development') return '/portail-refresh'
181
- return urlPortail + '/home/Refresh'
182
- }
183
- }
184
-
185
- // Instance
186
- const rafraichisseurToken = new RafraichisseurToken()
187
- export default rafraichisseurToken
1
+ class RafraichisseurToken {
2
+ private intervalleEnSecondes = 15
3
+ private secondesAvantExpirationTokenPourRafraichir = 20
4
+ private skewSeconds = 5 // marge anti-derives d’horloge
5
+ private popupAffiche = false
6
+ private timerId: number | null = null
7
+
8
+ // Lance une seule fois
9
+ public async demarrer(nomTemoin: string | null, urlPortail: string): Promise<void> {
10
+ urlPortail = urlPortail.replace(/\/+$/, '')
11
+ if (nomTemoin == null || nomTemoin === '') nomTemoin = 'csqc_jeton_secure_expiration'
12
+ await this.verifierJeton(nomTemoin, urlPortail)
13
+ if (this.timerId != null) return
14
+ this.timerId = window.setInterval(() => {
15
+ this.verifierJeton(nomTemoin, urlPortail)
16
+ }, this.intervalleEnSecondes * 1000)
17
+ }
18
+
19
+ // Permet d’arrêter le timer (ex: au logout / destroy)
20
+ public arreter(): void {
21
+ if (this.timerId != null) {
22
+ clearInterval(this.timerId)
23
+ this.timerId = null
24
+ }
25
+ }
26
+
27
+ public existeJeton = (nomTemoin: string) => {
28
+ return this.estJetonValide(nomTemoin)
29
+ }
30
+
31
+ private async verifierJeton(nomTemoin: string, urlPortail: string): Promise<void> {
32
+ if (this.popupAffiche) return
33
+
34
+ if (!this.estJetonValide(nomTemoin)) {
35
+ this.rafraichir(nomTemoin, urlPortail)
36
+ return
37
+ }
38
+ }
39
+
40
+ private estJetonValide(nomTemoin: string): boolean {
41
+ if (this.popupAffiche || !nomTemoin) return true //On fait semblant que c'est valide pour ne pas provoquer un autre affichage du popup.
42
+
43
+ const tokenEncode = this.lireCookie(nomTemoin)
44
+ if (!tokenEncode) {
45
+ return false
46
+ }
47
+
48
+ let token: any
49
+ try {
50
+ token = this.parseJwt(tokenEncode)
51
+ } catch {
52
+ return false
53
+ }
54
+
55
+ const exp = Number(token?.exp)
56
+ if (!Number.isFinite(exp)) {
57
+ // exp manquant/invalide → tente refresh
58
+
59
+ return false
60
+ }
61
+
62
+ const now = Math.floor(Date.now() / 1000)
63
+ const refreshAt = exp - this.secondesAvantExpirationTokenPourRafraichir - this.skewSeconds
64
+ if (now >= refreshAt) {
65
+ return false
66
+ }
67
+
68
+ return true
69
+ }
70
+
71
+ private async rafraichir(nomCookie: string, urlPortail: string): Promise<void> {
72
+ if (!nomCookie) return
73
+ const url = this.getRefreshUrl(urlPortail)
74
+ const controller = new AbortController()
75
+ const timeout = setTimeout(() => controller.abort(), 10_000)
76
+
77
+ try {
78
+ //Première tentative sans iframe, pour la majorité des cas.
79
+ const resp = await fetch(url, {
80
+ method: 'POST',
81
+ credentials: 'include',
82
+ headers: { Accept: 'application/json' },
83
+ redirect: 'manual',
84
+ signal: controller.signal,
85
+ })
86
+
87
+ // redirection (souvent => login) → traiter comme non auth
88
+
89
+ if (resp.type === 'opaqueredirect' || resp.status === 302) {
90
+ this.rafraichirParIframe(nomCookie, urlPortail)
91
+ return
92
+ }
93
+
94
+ // OK ou No Content: le cookie devrait être réécrit
95
+ if (resp.status === 200 || resp.status === 204) {
96
+ const jeton = this.lireCookie(nomCookie)
97
+ if (!jeton) this.rafraichirParIframe(nomCookie, urlPortail)
98
+ return
99
+ }
100
+
101
+ // non auth / expiré (401, 419) + IIS timeout (440)
102
+ if (resp.status === 401 || resp.status === 419 || resp.status === 440) {
103
+ this.rafraichirParIframe(nomCookie, urlPortail)
104
+ return
105
+ }
106
+
107
+ console.warn('Rafraichisseur token: statut inattendu', resp.status)
108
+ } catch (err: any) {
109
+ if (err?.name === 'AbortError') console.warn('RafraichisseurToken timeout')
110
+ else console.error('Erreur rafraichisseur de token', err)
111
+ // on réessaiera au prochain tick
112
+ } finally {
113
+ clearTimeout(timeout)
114
+ }
115
+ }
116
+
117
+ private rafraichirParIframe(nomCookie: string, urlPortail: string): void {
118
+ // 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é
119
+ // ajax vers le refresh
120
+ let iframe = document.createElement('iframe')
121
+ const url = this.getRefreshUrl(urlPortail)
122
+ iframe.src = `${url}?urlRetour=${encodeURI(window.localStorage.href)}`
123
+ iframe.id = 'idRafrToken'
124
+ iframe.style.display = 'none'
125
+ document.body.appendChild(iframe)
126
+ iframe.onload = () => {
127
+ const jetonCSQC = this.lireCookie(nomCookie)
128
+ if (jetonCSQC == null || jetonCSQC === '') {
129
+ this.estDeconnecteAzure(urlPortail)
130
+ }
131
+
132
+ iframe.remove()
133
+ }
134
+ }
135
+
136
+ private estDeconnecteAzure(urlPortail: string): void {
137
+ //on envoie au portail, pas le choix
138
+
139
+ const retour = encodeURI(window.location.href)
140
+ window.open(`${urlPortail}/home/SeConnecter?urlRetour=${retour}`, '_self')
141
+ return
142
+ }
143
+
144
+ public deconnecterPortail(urlPortail: string): void {
145
+ window.location.replace(`${urlPortail}/deconnecte?urlRetour=${encodeURIComponent(window.location.href)}`)
146
+ }
147
+
148
+ private lireCookie(nom: string): string | null {
149
+ if (!document.cookie) return null
150
+ const cookies = document.cookie.split(';').map(c => c.trim())
151
+ for (const cookie of cookies) {
152
+ if (cookie.startsWith(`${nom}=`)) {
153
+ try {
154
+ return decodeURIComponent(cookie.substring(nom.length + 1))
155
+ } catch {
156
+ return cookie.substring(nom.length + 1)
157
+ }
158
+ }
159
+ }
160
+ return null
161
+ }
162
+
163
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
164
+ private parseJwt(token: string): any {
165
+ const parts = token.split('.')
166
+ const base64Url = parts[1]
167
+ if (!base64Url) throw new Error('Invalid JWT format')
168
+ const base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/')
169
+ const jsonPayload = decodeURIComponent(
170
+ atob(base64)
171
+ .split('')
172
+ .map(c => `%${`00${c.charCodeAt(0).toString(16)}`.slice(-2)}`)
173
+ .join(''),
174
+ )
175
+ return JSON.parse(jsonPayload)
176
+ }
177
+
178
+ // URL refresh selon env (dev = proxy Vite ; prod = portail)
179
+ private getRefreshUrl(urlPortail: string): string {
180
+ if (import.meta.env.MODE === 'development') return '/portail-refresh'
181
+ return urlPortail + '/home/Refresh'
182
+ }
183
+ }
184
+
185
+ // Instance
186
+ const rafraichisseurToken = new RafraichisseurToken()
187
+ export default rafraichisseurToken
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codevdesign",
3
- "version": "1.0.42",
3
+ "version": "1.0.43",
4
4
  "description": "Composants Vuetify 3 pour les projets Codev",
5
5
  "files": [
6
6
  "./**/*.vue",
@@ -29,4 +29,4 @@
29
29
  "peerDependencies": {
30
30
  "vue": "^3.5.0"
31
31
  }
32
- }
32
+ }