@inzombieland/nuxt-common 1.16.11 → 1.16.12
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/api/index.d.ts +2 -8
- package/dist/runtime/api/user-actions.d.ts +2 -8
- package/dist/runtime/packages/api/get-user.d.ts +1 -7
- package/dist/runtime/packages/api/index.d.ts +2 -8
- package/dist/runtime/packages/api/index.mjs +4 -31
- package/dist/runtime/packages/api/package.json +1 -1
- package/dist/runtime/packages/api/types.d.ts +5 -0
- package/dist/runtime/packages/api/user-actions.d.ts +11 -0
- package/dist/runtime/packages/api/user-actions.mjs +35 -0
- package/package.json +1 -1
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.16.
|
|
5
|
+
const version = "1.16.12";
|
|
6
6
|
|
|
7
7
|
const module = defineNuxtModule({
|
|
8
8
|
meta: {
|
|
@@ -18,18 +18,12 @@ export declare const config: {
|
|
|
18
18
|
};
|
|
19
19
|
};
|
|
20
20
|
};
|
|
21
|
-
declare const fetch: Fetch, getUser: () => Promise<{
|
|
22
|
-
token?: string | null;
|
|
23
|
-
user?: import("src/runtime/packages/api/use-user").User | null;
|
|
24
|
-
}>, getVisitorIdentifier: () => Promise<void>, useApiFetch: () => Fetch, userActions: {
|
|
21
|
+
declare const fetch: Fetch, getUser: () => Promise<import("src/runtime/packages/api/types").GetUserResponse>, getVisitorIdentifier: () => Promise<void>, useApiFetch: () => Fetch, userActions: {
|
|
25
22
|
signIn: (body: {
|
|
26
23
|
username: string;
|
|
27
24
|
password: string;
|
|
28
25
|
rememberMe: boolean;
|
|
29
|
-
}) => Promise<{
|
|
30
|
-
token?: string | null;
|
|
31
|
-
user?: import("src/runtime/packages/api/use-user").User | null;
|
|
32
|
-
} | {
|
|
26
|
+
}) => Promise<import("src/runtime/packages/api/types").GetUserResponse | {
|
|
33
27
|
key: string;
|
|
34
28
|
}>;
|
|
35
29
|
logout: () => Promise<void>;
|
|
@@ -3,10 +3,7 @@ export declare const signIn: (body: {
|
|
|
3
3
|
username: string;
|
|
4
4
|
password: string;
|
|
5
5
|
rememberMe: boolean;
|
|
6
|
-
}) => Promise<{
|
|
7
|
-
token?: string | null;
|
|
8
|
-
user?: import("src/runtime/packages/api").User | null;
|
|
9
|
-
} | {
|
|
6
|
+
}) => Promise<import("src/runtime/packages/api/types").GetUserResponse | {
|
|
10
7
|
key: string;
|
|
11
8
|
}>;
|
|
12
9
|
export declare const logout: () => Promise<void>;
|
|
@@ -19,10 +16,7 @@ export declare const signInByCodeVerifyCode: (body: {
|
|
|
19
16
|
key: string;
|
|
20
17
|
code: string;
|
|
21
18
|
rememberMe?: boolean;
|
|
22
|
-
}) => Promise<
|
|
23
|
-
token?: string | null;
|
|
24
|
-
user?: import("src/runtime/packages/api").User | null;
|
|
25
|
-
}>;
|
|
19
|
+
}) => Promise<import("src/runtime/packages/api/types").GetUserResponse>;
|
|
26
20
|
export declare const signUp: (body: {
|
|
27
21
|
email: string;
|
|
28
22
|
password: string;
|
|
@@ -1,8 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { Fetch, FetchConfig } from "./types";
|
|
3
|
-
type GetUserResponse = {
|
|
4
|
-
token?: string | null;
|
|
5
|
-
user?: User | null;
|
|
6
|
-
};
|
|
1
|
+
import type { Fetch, FetchConfig, GetUserResponse } from "./types";
|
|
7
2
|
export declare const createApiGetUser: (fetch: Fetch, config: FetchConfig) => () => Promise<GetUserResponse>;
|
|
8
|
-
export {};
|
|
@@ -4,10 +4,7 @@ export { useUser, type User } from "./use-user";
|
|
|
4
4
|
export { getVisitor, getVisitorId, type Visitor } from "./get-visitor";
|
|
5
5
|
export declare function initApiFetch($fetch: Fetch, config: FetchConfig): {
|
|
6
6
|
fetch: Fetch;
|
|
7
|
-
getUser: () => Promise<
|
|
8
|
-
token?: string | null;
|
|
9
|
-
user?: import("src/runtime/api").User | null;
|
|
10
|
-
}>;
|
|
7
|
+
getUser: () => Promise<import("./types").GetUserResponse>;
|
|
11
8
|
getVisitorIdentifier: () => Promise<void>;
|
|
12
9
|
useApiFetch: () => Fetch;
|
|
13
10
|
userActions: {
|
|
@@ -15,10 +12,7 @@ export declare function initApiFetch($fetch: Fetch, config: FetchConfig): {
|
|
|
15
12
|
username: string;
|
|
16
13
|
password: string;
|
|
17
14
|
rememberMe: boolean;
|
|
18
|
-
}) => Promise<{
|
|
19
|
-
token?: string | null;
|
|
20
|
-
user?: import("src/runtime/api").User | null;
|
|
21
|
-
} | {
|
|
15
|
+
}) => Promise<import("./types").GetUserResponse | {
|
|
22
16
|
key: string;
|
|
23
17
|
}>;
|
|
24
18
|
logout: () => Promise<void>;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { createApiFetch
|
|
1
|
+
import { createApiFetch } from "./api-client.mjs";
|
|
2
2
|
import { createApiGetUser } from "./get-user.mjs";
|
|
3
3
|
import { createApiGetVisitorIdentifier } from "./get-visitor.mjs";
|
|
4
4
|
import { createApiRefreshToken } from "./refresh-token.mjs";
|
|
5
5
|
import { useApiActions } from "./use-api-actions.mjs";
|
|
6
|
-
import {
|
|
6
|
+
import { createApiUserActions } from "./user-actions.mjs";
|
|
7
7
|
export { useUser } from "./use-user.mjs";
|
|
8
8
|
export { getVisitor, getVisitorId } from "./get-visitor.mjs";
|
|
9
9
|
const apiActions = useApiActions();
|
|
@@ -12,39 +12,12 @@ export function initApiFetch($fetch, config) {
|
|
|
12
12
|
const getUser = createApiGetUser(fetch, config);
|
|
13
13
|
const getVisitorIdentifier = createApiGetVisitorIdentifier(config);
|
|
14
14
|
const refreshToken = createApiRefreshToken(fetch, config);
|
|
15
|
+
const useApiFetch = () => fetch;
|
|
16
|
+
const userActions = createApiUserActions(fetch, config, getUser);
|
|
15
17
|
apiActions.value = {
|
|
16
18
|
initialized: true,
|
|
17
19
|
getVisitorIdentifier,
|
|
18
20
|
refreshToken
|
|
19
21
|
};
|
|
20
|
-
const useApiFetch = () => fetch;
|
|
21
|
-
const userActions = {
|
|
22
|
-
signIn: async (body) => {
|
|
23
|
-
const response = await fetch("/account/0/signin", {
|
|
24
|
-
body,
|
|
25
|
-
method: "POST",
|
|
26
|
-
...config.useRequestHeaders?.(["cookie"]) ?? {}
|
|
27
|
-
});
|
|
28
|
-
const { accessToken, key, ...rest } = response;
|
|
29
|
-
if (!accessToken) {
|
|
30
|
-
if (key) {
|
|
31
|
-
return { key };
|
|
32
|
-
}
|
|
33
|
-
throw rest;
|
|
34
|
-
}
|
|
35
|
-
setToken(accessToken);
|
|
36
|
-
return await getUser();
|
|
37
|
-
},
|
|
38
|
-
logout: async () => {
|
|
39
|
-
const user = useUser();
|
|
40
|
-
try {
|
|
41
|
-
if (user.value) {
|
|
42
|
-
await fetch("/account/1/logout", { method: "POST" });
|
|
43
|
-
}
|
|
44
|
-
} finally {
|
|
45
|
-
flush();
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
22
|
return { fetch, getUser, getVisitorIdentifier, useApiFetch, userActions };
|
|
50
23
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { User } from "./use-user";
|
|
1
2
|
import type { FetchOptions, FetchRequest, FetchResponse } from "ofetch";
|
|
2
3
|
import type { ZodError } from "zod";
|
|
3
4
|
export type FetchExtraOptions = FetchOptions & {
|
|
@@ -36,6 +37,10 @@ export type FetchConfig = {
|
|
|
36
37
|
getDevice: () => Promise<string> | string;
|
|
37
38
|
useRequestHeaders?: (include: string[]) => {};
|
|
38
39
|
};
|
|
40
|
+
export type GetUserResponse = {
|
|
41
|
+
token?: string | null;
|
|
42
|
+
user?: User | null;
|
|
43
|
+
};
|
|
39
44
|
export type ActiveSession = {
|
|
40
45
|
id: string;
|
|
41
46
|
visitorId: string;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Fetch, FetchConfig, GetUserResponse } from "./types";
|
|
2
|
+
export declare const createApiUserActions: (fetch: Fetch, config: FetchConfig, getUser: () => Promise<GetUserResponse>) => {
|
|
3
|
+
signIn: (body: {
|
|
4
|
+
username: string;
|
|
5
|
+
password: string;
|
|
6
|
+
rememberMe: boolean;
|
|
7
|
+
}) => Promise<GetUserResponse | {
|
|
8
|
+
key: string;
|
|
9
|
+
}>;
|
|
10
|
+
logout: () => Promise<void>;
|
|
11
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { flush, setToken } from "./api-client.mjs";
|
|
2
|
+
import { once } from "./helpers/index.mjs";
|
|
3
|
+
import { useUser } from "./use-user.mjs";
|
|
4
|
+
export const createApiUserActions = once(
|
|
5
|
+
(fetch, config, getUser) => {
|
|
6
|
+
return {
|
|
7
|
+
signIn: async (body) => {
|
|
8
|
+
const response = await fetch("/account/0/signin", {
|
|
9
|
+
body,
|
|
10
|
+
method: "POST",
|
|
11
|
+
...config.useRequestHeaders?.(["cookie"]) ?? {}
|
|
12
|
+
});
|
|
13
|
+
const { accessToken, key, ...rest } = response;
|
|
14
|
+
if (!accessToken) {
|
|
15
|
+
if (key) {
|
|
16
|
+
return { key };
|
|
17
|
+
}
|
|
18
|
+
throw rest;
|
|
19
|
+
}
|
|
20
|
+
setToken(accessToken);
|
|
21
|
+
return await getUser();
|
|
22
|
+
},
|
|
23
|
+
logout: async () => {
|
|
24
|
+
const user = useUser();
|
|
25
|
+
try {
|
|
26
|
+
if (user.value) {
|
|
27
|
+
await fetch("/account/1/logout", { method: "POST" });
|
|
28
|
+
}
|
|
29
|
+
} finally {
|
|
30
|
+
flush();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
);
|