@inzombieland/nuxt-common 1.18.11 → 1.18.13
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/dist/module.json +1 -1
- package/dist/module.mjs +1 -1
- package/dist/runtime/packages/core/AppProvider.vue +1 -1
- package/dist/runtime/packages/core/api-client.d.ts +2 -0
- package/dist/runtime/packages/core/api-client.mjs +4 -2
- package/dist/runtime/packages/core/comet-client.mjs +3 -4
- package/dist/runtime/packages/core/composables/index.d.ts +0 -1
- package/dist/runtime/packages/core/composables/index.mjs +0 -1
- package/dist/runtime/packages/core/get-user.mjs +4 -3
- package/dist/runtime/packages/core/index.d.ts +5 -0
- package/dist/runtime/packages/core/index.mjs +6 -9
- package/dist/runtime/packages/core/package.json +1 -1
- package/package.json +1 -1
- package/dist/runtime/packages/core/composables/use-api-actions.d.ts +0 -13
- package/dist/runtime/packages/core/composables/use-api-actions.mjs +0 -5
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { fileURLToPath } from 'node:url';
|
|
|
2
2
|
import { defineNuxtModule, createResolver, addServerHandler, addImportsDir, addPlugin, addComponent } from '@nuxt/kit';
|
|
3
3
|
|
|
4
4
|
const name = "@inzombieland/nuxt-common";
|
|
5
|
-
const version = "1.18.
|
|
5
|
+
const version = "1.18.13";
|
|
6
6
|
|
|
7
7
|
const module = defineNuxtModule({
|
|
8
8
|
meta: {
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import bus from "./bus";
|
|
1
2
|
import type { Fetch, FetchConfig, FetchExtraOptions as FetchOptions, User } from "./types";
|
|
3
|
+
export { bus };
|
|
2
4
|
export declare const setUser: (newUser?: User | null) => void;
|
|
3
5
|
export declare const updateUser: (newUser: Partial<User>) => void;
|
|
4
6
|
export declare const getToken: () => string | null | undefined;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import bus from "./bus.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { useUser, useVisitor } from "./composables/index.mjs";
|
|
3
3
|
import { apiHelper, once } from "./helpers/index.mjs";
|
|
4
|
+
import { useApiActions } from "./index.mjs";
|
|
5
|
+
export { bus };
|
|
4
6
|
let token = null;
|
|
5
7
|
export const setUser = (newUser) => {
|
|
6
8
|
const user = useUser();
|
|
@@ -115,7 +117,7 @@ const fetchRequest = (url, options = {}, fetch, config) => {
|
|
|
115
117
|
const { status } = error?.response ?? { status: 500 };
|
|
116
118
|
if (status === 401 && url !== "/account/1/offline") {
|
|
117
119
|
const apiActions = useApiActions();
|
|
118
|
-
await apiActions
|
|
120
|
+
await apiActions?.value?.refreshToken?.();
|
|
119
121
|
return request();
|
|
120
122
|
}
|
|
121
123
|
throw errorHandler(error);
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { Centrifuge } from "centrifuge";
|
|
2
|
-
import { getToken } from "./api-client.mjs";
|
|
3
|
-
import bus from "./bus.mjs";
|
|
4
|
-
import { useApiActions } from "./composables/index.mjs";
|
|
2
|
+
import { bus, getToken } from "./api-client.mjs";
|
|
5
3
|
import { apiHelper } from "./helpers/index.mjs";
|
|
4
|
+
import { useApiActions } from "./index.mjs";
|
|
6
5
|
if (typeof window !== "undefined" && import.meta.env.MODE !== "production") {
|
|
7
6
|
window.wsPublish = (eventName, data) => {
|
|
8
7
|
setTimeout(() => bus.publish(`WS.${eventName}`, data), 0);
|
|
@@ -28,7 +27,7 @@ export function newCometClient(user, cometServerURL) {
|
|
|
28
27
|
debug: import.meta.env.MODE !== "production",
|
|
29
28
|
getToken: async () => {
|
|
30
29
|
const apiActions = useApiActions();
|
|
31
|
-
return await apiActions
|
|
30
|
+
return await apiActions?.value?.refreshToken?.() ?? "";
|
|
32
31
|
}
|
|
33
32
|
});
|
|
34
33
|
const publish = (eventName, data) => () => {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
export * from "../helpers/composables";
|
|
2
2
|
export { useActiveSessions } from "./use-active-sessions";
|
|
3
|
-
export { useApiActions } from "./use-api-actions";
|
|
4
3
|
export { useAppLocale } from "./use-app-locale";
|
|
5
4
|
export { useSubscribe } from "./use-subscribe";
|
|
6
5
|
export { useThemeMode } from "./use-theme-mode";
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
export * from "../helpers/composables.mjs";
|
|
2
2
|
export { useActiveSessions } from "./use-active-sessions.mjs";
|
|
3
|
-
export { useApiActions } from "./use-api-actions.mjs";
|
|
4
3
|
export { useAppLocale } from "./use-app-locale.mjs";
|
|
5
4
|
export { useSubscribe } from "./use-subscribe.mjs";
|
|
6
5
|
export { useThemeMode } from "./use-theme-mode.mjs";
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { useLocalStorage } from "@vueuse/core";
|
|
2
2
|
import { flush, getToken, setUser } from "./api-client.mjs";
|
|
3
|
-
import {
|
|
3
|
+
import { useUser } from "./composables/index.mjs";
|
|
4
4
|
import { createSingletonAsync, once } from "./helpers/index.mjs";
|
|
5
|
+
import { useApiActions } from "./index.mjs";
|
|
5
6
|
async function getUserRequest(fetch, config) {
|
|
6
7
|
const token = getToken();
|
|
7
8
|
const user = useUser();
|
|
@@ -16,8 +17,8 @@ async function getUserRequest(fetch, config) {
|
|
|
16
17
|
}
|
|
17
18
|
try {
|
|
18
19
|
const apiActions = useApiActions();
|
|
19
|
-
await apiActions
|
|
20
|
-
await apiActions
|
|
20
|
+
await apiActions?.value?.getVisitorIdentifier?.();
|
|
21
|
+
await apiActions?.value?.refreshToken?.();
|
|
21
22
|
} catch {
|
|
22
23
|
flush();
|
|
23
24
|
return { token: null, user: null };
|
|
@@ -4,6 +4,10 @@ export { defineVuePlugins } from "./define-vue-plugins";
|
|
|
4
4
|
export { default as AppProvider } from "./AppProvider.vue";
|
|
5
5
|
export * from "./composables";
|
|
6
6
|
export * from "./types";
|
|
7
|
+
type ApiActions = {
|
|
8
|
+
getVisitorIdentifier?: () => Promise<void>;
|
|
9
|
+
refreshToken?: () => Promise<string>;
|
|
10
|
+
};
|
|
7
11
|
export declare function initApiFetch($fetch: Fetch, config: FetchConfig): {
|
|
8
12
|
fetch: Fetch;
|
|
9
13
|
getUser: () => Promise<import("./types").GetUserResponse>;
|
|
@@ -65,3 +69,4 @@ export declare const useUserActions: () => Ref<{
|
|
|
65
69
|
locale: string;
|
|
66
70
|
}) => Promise<void>;
|
|
67
71
|
}> | undefined;
|
|
72
|
+
export declare const useApiActions: () => Ref<ApiActions, ApiActions> | undefined;
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { useLocalStorage } from "@vueuse/core";
|
|
2
2
|
import { ref } from "vue";
|
|
3
|
-
import { createApiFetch } from "./api-client.mjs";
|
|
4
|
-
import bus from "./bus.mjs";
|
|
3
|
+
import { bus, createApiFetch } from "./api-client.mjs";
|
|
5
4
|
import { newCometClient } from "./comet-client.mjs";
|
|
6
|
-
import { useApiActions } from "./composables/index.mjs";
|
|
7
5
|
import { createApiGetUser } from "./get-user.mjs";
|
|
8
6
|
import { createApiGetVisitorIdentifier } from "./get-visitor.mjs";
|
|
9
7
|
import { createInitApplication } from "./init-application.mjs";
|
|
@@ -13,8 +11,8 @@ export { defineVuePlugins } from "./define-vue-plugins.mjs";
|
|
|
13
11
|
export { default as AppProvider } from "./AppProvider.vue";
|
|
14
12
|
export * from "./composables/index.mjs";
|
|
15
13
|
export * from "./types.mjs";
|
|
16
|
-
const apiActions = useApiActions();
|
|
17
14
|
let userActions;
|
|
15
|
+
let apiActions;
|
|
18
16
|
export function initApiFetch($fetch, config) {
|
|
19
17
|
const fetch = createApiFetch($fetch, config);
|
|
20
18
|
const getUser = createApiGetUser(fetch, config);
|
|
@@ -22,11 +20,7 @@ export function initApiFetch($fetch, config) {
|
|
|
22
20
|
const initApplication = createInitApplication();
|
|
23
21
|
const refreshToken = createApiRefreshToken(fetch, config);
|
|
24
22
|
userActions = ref(createApiUserActions(fetch, config, getUser));
|
|
25
|
-
apiActions
|
|
26
|
-
initialized: true,
|
|
27
|
-
getVisitorIdentifier,
|
|
28
|
-
refreshToken
|
|
29
|
-
};
|
|
23
|
+
apiActions = ref({ getVisitorIdentifier, refreshToken });
|
|
30
24
|
if (typeof window !== "undefined") {
|
|
31
25
|
const loggedIn = useLocalStorage("lin", "no");
|
|
32
26
|
const cometServerURL = config.cometServerURL;
|
|
@@ -55,3 +49,6 @@ export function initApiFetch($fetch, config) {
|
|
|
55
49
|
export const useUserActions = () => {
|
|
56
50
|
return userActions;
|
|
57
51
|
};
|
|
52
|
+
export const useApiActions = () => {
|
|
53
|
+
return apiActions;
|
|
54
|
+
};
|
package/package.json
CHANGED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export declare const useApiActions: () => import("vue").Ref<{
|
|
2
|
-
initialized: boolean;
|
|
3
|
-
getVisitorIdentifier?: (() => Promise<void>) | undefined;
|
|
4
|
-
refreshToken?: (() => Promise<string>) | undefined;
|
|
5
|
-
}, {
|
|
6
|
-
initialized: boolean;
|
|
7
|
-
getVisitorIdentifier?: () => Promise<void>;
|
|
8
|
-
refreshToken?: () => Promise<string>;
|
|
9
|
-
} | {
|
|
10
|
-
initialized: boolean;
|
|
11
|
-
getVisitorIdentifier?: (() => Promise<void>) | undefined;
|
|
12
|
-
refreshToken?: (() => Promise<string>) | undefined;
|
|
13
|
-
}>;
|