@data-fair/lib-vue 1.9.2 → 1.9.4
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 +11 -1
- package/session.js +1 -21
package/package.json
CHANGED
package/session.d.ts
CHANGED
|
@@ -22,15 +22,25 @@ export interface SessionOptions {
|
|
|
22
22
|
}
|
|
23
23
|
export interface Colors {
|
|
24
24
|
background: string;
|
|
25
|
+
'on-background': string;
|
|
25
26
|
surface: string;
|
|
27
|
+
'on-surface': string;
|
|
26
28
|
primary: string;
|
|
29
|
+
'on-primary': string;
|
|
30
|
+
'text-primary': string;
|
|
27
31
|
secondary: string;
|
|
28
|
-
|
|
32
|
+
'on-secondary': string;
|
|
33
|
+
'text-secondary': string;
|
|
29
34
|
error: string;
|
|
35
|
+
'on-error': string;
|
|
30
36
|
info: string;
|
|
37
|
+
'on-info': string;
|
|
31
38
|
success: string;
|
|
39
|
+
'on-success': string;
|
|
32
40
|
warning: string;
|
|
41
|
+
'on-warning': string;
|
|
33
42
|
admin: string;
|
|
43
|
+
'on-admin': string;
|
|
34
44
|
}
|
|
35
45
|
export interface SiteInfo {
|
|
36
46
|
main?: boolean;
|
package/session.js
CHANGED
|
@@ -37,10 +37,6 @@ const goTo = (url) => {
|
|
|
37
37
|
}
|
|
38
38
|
if (url) { topLocation.href = url } else { topLocation.reload() }
|
|
39
39
|
}
|
|
40
|
-
const getSiteInfoStorage = (sitePath) => {
|
|
41
|
-
const siteInfoStorageStr = window.localStorage.getItem('sd-site-info' + sitePath)
|
|
42
|
-
return siteInfoStorageStr ? JSON.parse(siteInfoStorageStr) : null
|
|
43
|
-
}
|
|
44
40
|
const defaultOptions = { directoryUrl: '/simple-directory', sitePath: '', defaultLang: 'fr' }
|
|
45
41
|
export async function getSession (initOptions) {
|
|
46
42
|
const options = { ...defaultOptions, ...initOptions }
|
|
@@ -113,10 +109,6 @@ export async function getSession (initOptions) {
|
|
|
113
109
|
}
|
|
114
110
|
state.accountRole = 'admin'
|
|
115
111
|
}
|
|
116
|
-
if (!ssr) {
|
|
117
|
-
const siteInfoStorage = getSiteInfoStorage(options.sitePath)
|
|
118
|
-
site.value = siteInfoStorage ? siteInfoStorage.info : null
|
|
119
|
-
}
|
|
120
112
|
}
|
|
121
113
|
readState()
|
|
122
114
|
debug('initial state', state)
|
|
@@ -222,17 +214,11 @@ export async function getSession (initOptions) {
|
|
|
222
214
|
await customFetch(`${options.directoryUrl}/api/auth/keepalive`, { method: 'POST' })
|
|
223
215
|
readState()
|
|
224
216
|
}
|
|
225
|
-
const setSiteInfoStorage = (siteInfo) => {
|
|
226
|
-
const siteInfoStorage = { info: siteInfo, updatedAt: new Date().getTime() }
|
|
227
|
-
window.localStorage.setItem('sd-site-info' + options.sitePath, JSON.stringify(siteInfoStorage))
|
|
228
|
-
}
|
|
229
217
|
const refreshSiteInfo = async () => {
|
|
230
218
|
const siteInfo = await customFetch(`${options.directoryUrl}/api/sites/_public`) ?? null
|
|
231
219
|
site.value = siteInfo
|
|
232
|
-
if (!ssr) {
|
|
233
|
-
setSiteInfoStorage(siteInfo)
|
|
234
|
-
}
|
|
235
220
|
}
|
|
221
|
+
if (options.siteInfo) { await refreshSiteInfo() }
|
|
236
222
|
// immediately performs a keepalive, but only on top windows (not iframes or popups)
|
|
237
223
|
// and only if it was not done very recently (maybe from a refreshed page next to this one)
|
|
238
224
|
// also run an auto-refresh loop
|
|
@@ -241,12 +227,6 @@ export async function getSession (initOptions) {
|
|
|
241
227
|
if (state.user && (!lastKeepalive || (new Date().getTime() - Number(lastKeepalive)) > 10000)) {
|
|
242
228
|
await keepalive()
|
|
243
229
|
}
|
|
244
|
-
if (options.siteInfo) {
|
|
245
|
-
const lastSiteInfoStorage = getSiteInfoStorage(options.sitePath)
|
|
246
|
-
if (!lastSiteInfoStorage || (new Date().getTime() - Number(lastSiteInfoStorage.updatedAt)) > 10000) {
|
|
247
|
-
await refreshSiteInfo()
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
230
|
const refreshLoopDelay = 10 * 60 * 1000 // 10 minutes
|
|
251
231
|
setInterval(() => {
|
|
252
232
|
const lastKeepalive = window.localStorage.getItem('sd-keepalive' + options.sitePath)
|