@data-fair/lib-vue 1.8.0 → 1.9.0
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 +1 -1
- package/session.d.ts +14 -3
- package/session.js +5 -4
package/package.json
CHANGED
package/session.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ interface GenericCookies {
|
|
|
12
12
|
export interface SessionOptions {
|
|
13
13
|
sitePath: string;
|
|
14
14
|
directoryUrl: string;
|
|
15
|
+
defaultLang: string;
|
|
15
16
|
route?: RouteLocation;
|
|
16
17
|
logoutRedirectUrl?: string;
|
|
17
18
|
req?: IncomingMessage;
|
|
@@ -19,12 +20,22 @@ export interface SessionOptions {
|
|
|
19
20
|
customFetch?: typeof fetch;
|
|
20
21
|
siteInfo?: boolean;
|
|
21
22
|
}
|
|
22
|
-
export interface
|
|
23
|
-
|
|
23
|
+
export interface Colors {
|
|
24
|
+
background: string;
|
|
25
|
+
surface: string;
|
|
26
|
+
primary: string;
|
|
27
|
+
secondary: string;
|
|
28
|
+
accent: string;
|
|
29
|
+
error: string;
|
|
30
|
+
info: string;
|
|
31
|
+
success: string;
|
|
32
|
+
warning: string;
|
|
33
|
+
admin: string;
|
|
24
34
|
}
|
|
25
35
|
export interface SiteInfo {
|
|
26
|
-
|
|
36
|
+
main?: boolean;
|
|
27
37
|
logo?: string;
|
|
38
|
+
colors: Colors;
|
|
28
39
|
}
|
|
29
40
|
export interface Session {
|
|
30
41
|
state: SessionState;
|
package/session.js
CHANGED
|
@@ -3,6 +3,7 @@ import { ofetch } from 'ofetch'
|
|
|
3
3
|
import { jwtDecode } from 'jwt-decode'
|
|
4
4
|
import cookiesModule from 'universal-cookie'
|
|
5
5
|
import Debug from 'debug'
|
|
6
|
+
import inIframe from '@data-fair/lib-utils/in-iframe.js'
|
|
6
7
|
const Cookies = cookiesModule
|
|
7
8
|
const debug = Debug('session')
|
|
8
9
|
debug.log = console.log.bind(console)
|
|
@@ -36,7 +37,7 @@ const goTo = (url) => {
|
|
|
36
37
|
}
|
|
37
38
|
if (url) { topLocation.href = url } else { topLocation.reload() }
|
|
38
39
|
}
|
|
39
|
-
const defaultOptions = { directoryUrl: '/simple-directory', sitePath: '' }
|
|
40
|
+
const defaultOptions = { directoryUrl: '/simple-directory', sitePath: '', defaultLang: 'fr' }
|
|
40
41
|
export async function getSession (initOptions) {
|
|
41
42
|
const options = { ...defaultOptions, ...initOptions }
|
|
42
43
|
const cookiesPath = options.sitePath + '/'
|
|
@@ -62,7 +63,7 @@ export async function getSession (initOptions) {
|
|
|
62
63
|
const darkCookie = cookies.get('theme_dark')
|
|
63
64
|
state.dark = darkCookie === '1' || darkCookie === 'true'
|
|
64
65
|
const langCookie = cookies.get('i18n_lang')
|
|
65
|
-
|
|
66
|
+
state.lang = langCookie ?? options.defaultLang
|
|
66
67
|
const idToken = cookies.get('id_token')
|
|
67
68
|
const user = jwtDecodeAlive(idToken)
|
|
68
69
|
if (!user) {
|
|
@@ -235,9 +236,9 @@ export async function getSession (initOptions) {
|
|
|
235
236
|
// immediately performs a keepalive, but only on top windows (not iframes or popups)
|
|
236
237
|
// and only if it was not done very recently (maybe from a refreshed page next to this one)
|
|
237
238
|
// also run an auto-refresh loop
|
|
238
|
-
if (!ssr &&
|
|
239
|
+
if (!ssr && !inIframe) {
|
|
239
240
|
const lastKeepalive = window.localStorage.getItem('sd-keepalive' + options.sitePath)
|
|
240
|
-
if (!lastKeepalive || (new Date().getTime() - Number(lastKeepalive)) > 10000) {
|
|
241
|
+
if (state.user && (!lastKeepalive || (new Date().getTime() - Number(lastKeepalive)) > 10000)) {
|
|
241
242
|
await keepalive()
|
|
242
243
|
}
|
|
243
244
|
if (options.siteInfo) {
|