@inzombieland/core 1.19.11 → 1.19.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/api-client.d.ts CHANGED
@@ -3,5 +3,7 @@ export declare const setUser: (newUser?: User | null) => void;
3
3
  export declare const updateUser: (newUser: Partial<User>) => void;
4
4
  export declare const getToken: () => string | null | undefined;
5
5
  export declare const setToken: (newToken?: string | null) => void;
6
+ export declare const getSecretKey: () => string | undefined;
7
+ export declare const setSecretKey: (newSecretKey?: string) => void;
6
8
  export declare const flush: () => void;
7
9
  export declare const createApiFetch: (fetch: Fetch, config: FetchConfig) => (url: string, options?: FetchOptions) => Promise<any>;
package/api-client.mjs CHANGED
@@ -2,6 +2,7 @@ import { useApiActions, useUser, useVisitor } from "./composables/index.mjs";
2
2
  import { apiHelper, once } from "./helpers/index.mjs";
3
3
  import { useBus } from "./index.mjs";
4
4
  let token = null;
5
+ let secretKey;
5
6
  export const setUser = (newUser) => {
6
7
  const user = useUser();
7
8
  user.value = newUser;
@@ -20,6 +21,12 @@ export const getToken = () => {
20
21
  export const setToken = (newToken) => {
21
22
  token = newToken;
22
23
  };
24
+ export const getSecretKey = () => {
25
+ return secretKey;
26
+ };
27
+ export const setSecretKey = (newSecretKey) => {
28
+ secretKey = newSecretKey;
29
+ };
23
30
  export const flush = () => {
24
31
  setToken(null);
25
32
  setUser(null);
package/get-user.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { useLocalStorage } from "@vueuse/core";
2
- import { flush, getToken, setUser } from "./api-client.mjs";
2
+ import { flush, getSecretKey, getToken, setUser } from "./api-client.mjs";
3
3
  import { useApiActions, useUser } from "./composables/index.mjs";
4
4
  import { createSingletonAsync, once } from "./helpers/index.mjs";
5
5
  async function getUserRequest(fetch, config) {
@@ -26,7 +26,8 @@ async function getUserRequest(fetch, config) {
26
26
  const user2 = await fetch("/account", config.useRequestHeaders?.(["cookie", "authorization"]));
27
27
  setUser(user2);
28
28
  const token2 = getToken();
29
- return { token: token2, user: user2 };
29
+ const secretKey = getSecretKey();
30
+ return { token: token2, secretKey, user: user2 };
30
31
  } catch {
31
32
  flush();
32
33
  return { token: null, user: null };
package/index.d.ts CHANGED
@@ -16,6 +16,7 @@ export declare function initApiFetch($fetch: Fetch, config: FetchConfig): {
16
16
  key: string;
17
17
  }>;
18
18
  signInByCodeVerifyCode: (body: Record<string, any>) => Promise<import("./types").GetUserResponse>;
19
+ getToken: (body: Record<string, any>) => Promise<import("./types").GetUserResponse>;
19
20
  signUp: (body: Record<string, any>) => Promise<{
20
21
  key: string;
21
22
  }>;
@@ -114,6 +115,7 @@ export declare const useUserActions: () => Ref<{
114
115
  key: string;
115
116
  }>;
116
117
  signInByCodeVerifyCode: (body: Record<string, any>) => Promise<import("./types").GetUserResponse>;
118
+ getToken: (body: Record<string, any>) => Promise<import("./types").GetUserResponse>;
117
119
  signUp: (body: Record<string, any>) => Promise<{
118
120
  key: string;
119
121
  }>;
@@ -210,6 +212,7 @@ export declare const useUserActions: () => Ref<{
210
212
  key: string;
211
213
  }>;
212
214
  signInByCodeVerifyCode: (body: Record<string, any>) => Promise<import("./types").GetUserResponse>;
215
+ getToken: (body: Record<string, any>) => Promise<import("./types").GetUserResponse>;
213
216
  signUp: (body: Record<string, any>) => Promise<{
214
217
  key: string;
215
218
  }>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inzombieland/core",
3
- "version": "1.19.11",
3
+ "version": "1.19.13",
4
4
  "type": "module",
5
5
  "license": "ISC",
6
6
  "main": "./index.mjs",
package/types.d.ts CHANGED
@@ -38,6 +38,7 @@ export type FetchConfig = {
38
38
  };
39
39
  export type GetUserResponse = {
40
40
  token?: string | null;
41
+ secretKey?: string;
41
42
  user?: User | null;
42
43
  };
43
44
  export type User = {
package/user-actions.d.ts CHANGED
@@ -8,6 +8,7 @@ export declare const createApiUserActions: (fetch: Fetch, config: FetchConfig, g
8
8
  key: string;
9
9
  }>;
10
10
  signInByCodeVerifyCode: (body: Record<string, any>) => Promise<GetUserResponse>;
11
+ getToken: (body: Record<string, any>) => Promise<GetUserResponse>;
11
12
  signUp: (body: Record<string, any>) => Promise<{
12
13
  key: string;
13
14
  }>;
package/user-actions.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { flush, setToken, updateUser } from "./api-client.mjs";
1
+ import { flush, setSecretKey, setToken, updateUser } from "./api-client.mjs";
2
2
  import { useUser } from "./composables/index.mjs";
3
3
  import { once } from "./helpers/index.mjs";
4
4
  export const createApiUserActions = once(
@@ -28,7 +28,24 @@ export const createApiUserActions = once(
28
28
  });
29
29
  },
30
30
  signInByCodeVerifyCode: async (body) => {
31
- const response = await fetch("/account/0/signinbycode/verifycode", {
31
+ const response = await fetch(
32
+ "/account/0/signinbycode/verifycode",
33
+ {
34
+ body,
35
+ method: "POST",
36
+ ...config.useRequestHeaders?.(["cookie"]) ?? {}
37
+ }
38
+ );
39
+ const { accessToken, secretKey, ...rest } = response;
40
+ if (!accessToken) {
41
+ throw rest;
42
+ }
43
+ setToken(accessToken);
44
+ setSecretKey(secretKey);
45
+ return await getUser();
46
+ },
47
+ getToken: async (body) => {
48
+ const response = await fetch("/account/0/token", {
32
49
  body,
33
50
  method: "POST",
34
51
  ...config.useRequestHeaders?.(["cookie"]) ?? {}