@innertia-solutions/innertia-nuxt 0.1.73 → 0.1.75
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/plugins/api-organization.client.ts +25 -17
- package/plugins/vue-query.ts +23 -20
- package/stores/organization.ts +4 -2
package/package.json
CHANGED
|
@@ -11,27 +11,35 @@
|
|
|
11
11
|
* el header por-request sin afectar el toggle global.
|
|
12
12
|
*
|
|
13
13
|
* Solo activo cuando `mode === 'saas'` (orgs viven dentro de un tenant).
|
|
14
|
+
*
|
|
15
|
+
* Depende de `innertia:vue-query`: useOrganization → useAuth → useQueryClient()
|
|
16
|
+
* necesita el QueryClient instalado. Sin `dependsOn`, el orden alfabético de la
|
|
17
|
+
* capa corre este plugin antes y el cliente cae con "No 'queryClient' found".
|
|
14
18
|
*/
|
|
15
|
-
export default defineNuxtPlugin(
|
|
16
|
-
|
|
17
|
-
|
|
19
|
+
export default defineNuxtPlugin({
|
|
20
|
+
name: 'innertia:api-organization',
|
|
21
|
+
dependsOn: ['innertia:vue-query'],
|
|
22
|
+
setup() {
|
|
23
|
+
const { hasTenant } = useInnertiaMode()
|
|
24
|
+
if (!hasTenant()) return
|
|
18
25
|
|
|
19
|
-
|
|
20
|
-
|
|
26
|
+
const appConfig = useAppConfig()
|
|
27
|
+
if (!appConfig.innertia?.organizations?.enabled) return
|
|
21
28
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
29
|
+
const { add } = useRequestInterceptors()
|
|
30
|
+
const organizationStore = useOrganizationStore()
|
|
31
|
+
const { currentContext } = useOrganization()
|
|
25
32
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
33
|
+
add((headers: Record<string, string>) => {
|
|
34
|
+
const ctx = currentContext.value
|
|
35
|
+
if (!ctx) return
|
|
29
36
|
|
|
30
|
-
|
|
31
|
-
|
|
37
|
+
const slug = organizationStore.currentFor(ctx)
|
|
38
|
+
if (slug) headers['X-Organization'] = slug
|
|
32
39
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
40
|
+
if (organizationStore.consolidated) {
|
|
41
|
+
headers['X-Consolidated'] = 'true'
|
|
42
|
+
}
|
|
43
|
+
})
|
|
44
|
+
},
|
|
37
45
|
})
|
package/plugins/vue-query.ts
CHANGED
|
@@ -1,29 +1,32 @@
|
|
|
1
1
|
import type { DehydratedState } from '@tanstack/vue-query'
|
|
2
2
|
import { VueQueryPlugin, QueryClient, dehydrate, hydrate } from '@tanstack/vue-query'
|
|
3
3
|
|
|
4
|
-
export default defineNuxtPlugin(
|
|
5
|
-
|
|
4
|
+
export default defineNuxtPlugin({
|
|
5
|
+
name: 'innertia:vue-query',
|
|
6
|
+
setup(nuxtApp) {
|
|
7
|
+
const vueQueryState = useState<DehydratedState | null>('vue-query')
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
const queryClient = new QueryClient({
|
|
10
|
+
defaultOptions: {
|
|
11
|
+
queries: {
|
|
12
|
+
staleTime: 5 * 60 * 1000, // 5 min — datos frescos sin re-fetch
|
|
13
|
+
gcTime: 10 * 60 * 1000, // 10 min — cache se limpia si no hay subscribers
|
|
14
|
+
retry: 1,
|
|
15
|
+
refetchOnWindowFocus: false,
|
|
16
|
+
},
|
|
14
17
|
},
|
|
15
|
-
}
|
|
16
|
-
})
|
|
18
|
+
})
|
|
17
19
|
|
|
18
|
-
|
|
20
|
+
nuxtApp.vueApp.use(VueQueryPlugin, { queryClient })
|
|
19
21
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
if (import.meta.server) {
|
|
23
|
+
nuxtApp.hooks.hook('app:rendered', () => {
|
|
24
|
+
vueQueryState.value = dehydrate(queryClient)
|
|
25
|
+
})
|
|
26
|
+
}
|
|
25
27
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
if (import.meta.client) {
|
|
29
|
+
hydrate(queryClient, vueQueryState.value)
|
|
30
|
+
}
|
|
31
|
+
},
|
|
29
32
|
})
|
package/stores/organization.ts
CHANGED
|
@@ -29,8 +29,10 @@ export const useOrganizationStore = defineStore('organization', {
|
|
|
29
29
|
{
|
|
30
30
|
key: 'innertia_org_by_ctx',
|
|
31
31
|
pick: ['currentByContext'],
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
// pinia-plugin-persistedstate v4: `cookies(...)` es una fábrica que recibe las
|
|
33
|
+
// opciones. Pasarla sin llamar (API v3 + `cookieOptions`) deja un storage inválido
|
|
34
|
+
// y la sede elegida nunca se guarda: cada recarga vuelve al selector de sede.
|
|
35
|
+
storage: piniaPluginPersistedstate.cookies({ maxAge: 60 * 60 * 24 * 30, sameSite: 'lax' }),
|
|
34
36
|
},
|
|
35
37
|
],
|
|
36
38
|
|