@inzombieland/core 1.20.1 → 1.20.3

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
@@ -5,6 +5,5 @@ export declare const getToken: () => string | null | undefined;
5
5
  export declare const setToken: (newToken?: string | null) => void;
6
6
  export declare const getSecretKey: () => string | undefined;
7
7
  export declare const setSecretKey: (newSecretKey?: string) => void;
8
- export declare const setVisitorId: (visitorId?: string) => void;
9
8
  export declare const flush: () => void;
10
9
  export declare const createApiFetch: (fetch: Fetch, config: FetchConfig) => (url: string, options?: FetchOptions) => Promise<any>;
package/api-client.js CHANGED
@@ -27,9 +27,6 @@ export const getSecretKey = () => {
27
27
  export const setSecretKey = (newSecretKey) => {
28
28
  secretKey = newSecretKey;
29
29
  };
30
- export const setVisitorId = (visitorId = "") => {
31
- localStorage.setItem("vid", visitorId);
32
- };
33
30
  export const flush = () => {
34
31
  setToken(null);
35
32
  setUser(null);
@@ -105,8 +102,8 @@ const optionsHandler = (options = {}, config) => {
105
102
  const { platform, hostname } = visitor;
106
103
  const visitorIdentifier = useVisitor();
107
104
  if (visitorIdentifier.value) {
108
- const { id, ip, device, appName } = visitorIdentifier.value;
109
- headers.visitor = btoa(`${platform}|:|${hostname}|:|${id}|:|${ip}|:|${device}|:|${appName}`);
105
+ const { id, fid, device, appName } = visitorIdentifier.value;
106
+ headers.visitor = btoa(`${platform}|:|${hostname}|:|${id}|:|${fid}|:|${device}|:|${appName}`);
110
107
  } else {
111
108
  headers.visitor = btoa(`${platform}|:|${hostname}`);
112
109
  }
@@ -1,12 +1,12 @@
1
1
  import type { Visitor } from "../types.js";
2
2
  export declare function useVisitor(): import("vue").Ref<{
3
3
  id?: string | undefined;
4
- ip?: string | undefined;
4
+ fid?: string | undefined;
5
5
  device?: string | undefined;
6
6
  appName?: string | undefined;
7
7
  } | null | undefined, Visitor | {
8
8
  id?: string | undefined;
9
- ip?: string | undefined;
9
+ fid?: string | undefined;
10
10
  device?: string | undefined;
11
11
  appName?: string | undefined;
12
12
  } | null | undefined>;
package/get-visitor.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { hashComponents, load } from "@fingerprintjs/fingerprintjs";
2
2
  import { useVisitor } from "./composables/index.js";
3
3
  import { createSingletonAsync, once } from "./helpers/index.js";
4
+ import { getVisitorId } from "./local-storage-utils.js";
4
5
  const setVisitor = (newVisitor) => {
5
6
  const visitor = useVisitor();
6
7
  visitor.value = !visitor.value ? newVisitor : { ...visitor.value, ...newVisitor };
@@ -13,11 +14,14 @@ const getVisitorRequest = async (config) => {
13
14
  const fp = await load();
14
15
  const result = await fp.get();
15
16
  const { canvas, colorDepth, hdr, languages, screenFrame, screenResolution, ...components } = result.components;
16
- const id = hashComponents(components);
17
- const ip = "unknown";
17
+ const fid = hashComponents(components);
18
+ let id = getVisitorId() ?? "";
19
+ if (!/^[0-9a-f]{32}$/i.test(id)) {
20
+ id = fid;
21
+ }
18
22
  const device = await config.getDevice() || "unknown";
19
23
  const appName = config.appName || "unknown";
20
- setVisitor({ id, ip, device, appName });
24
+ setVisitor({ id, fid, device, appName });
21
25
  };
22
26
  const getVisitorIdentifier = createSingletonAsync(getVisitorRequest);
23
27
  export const createApiGetVisitorIdentifier = once((config) => {
@@ -0,0 +1,4 @@
1
+ export declare const getSessionId: () => string | null;
2
+ export declare const setSessionId: (sessionId?: string) => void;
3
+ export declare const getVisitorId: () => string | null;
4
+ export declare const setVisitorId: (visitorId?: string) => void;
@@ -0,0 +1,22 @@
1
+ export const getSessionId = () => {
2
+ if (typeof window !== "undefined") {
3
+ return window.localStorage.getItem("sid");
4
+ }
5
+ return null;
6
+ };
7
+ export const setSessionId = (sessionId = "") => {
8
+ if (typeof window !== "undefined") {
9
+ window.localStorage.setItem("sid", sessionId);
10
+ }
11
+ };
12
+ export const getVisitorId = () => {
13
+ if (typeof window !== "undefined") {
14
+ return window.localStorage.getItem("vid");
15
+ }
16
+ return null;
17
+ };
18
+ export const setVisitorId = (visitorId = "") => {
19
+ if (typeof window !== "undefined") {
20
+ window.localStorage.setItem("vid", visitorId);
21
+ }
22
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inzombieland/core",
3
- "version": "1.20.1",
3
+ "version": "1.20.3",
4
4
  "type": "module",
5
5
  "license": "ISC",
6
6
  "main": "./index.js",
package/types.d.ts CHANGED
@@ -59,7 +59,7 @@ export type User = {
59
59
  };
60
60
  export type Visitor = {
61
61
  id?: string;
62
- ip?: string;
62
+ fid?: string;
63
63
  device?: string;
64
64
  appName?: string;
65
65
  };
package/user-actions.js CHANGED
@@ -1,6 +1,7 @@
1
- import { flush, setSecretKey, setVisitorId, setToken, updateUser } from "./api-client.js";
1
+ import { flush, setSecretKey, setToken, updateUser } from "./api-client.js";
2
2
  import { useUser } from "./composables/index.js";
3
3
  import { once } from "./helpers/index.js";
4
+ import { setSessionId, setVisitorId } from "./local-storage-utils.js";
4
5
  export const createApiUserActions = once(
5
6
  (fetch, config, getUser) => {
6
7
  return {
@@ -28,21 +29,19 @@ export const createApiUserActions = once(
28
29
  });
29
30
  },
30
31
  signInByCodeVerifyCode: async (body) => {
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, visitorId, ...rest } = response;
40
- if (!accessToken) {
32
+ const response = await fetch("/account/0/signinbycode/verifycode", {
33
+ body,
34
+ method: "POST",
35
+ ...config.useRequestHeaders?.(["cookie"]) ?? {}
36
+ });
37
+ const { accessToken, sessionId, visitorId, secretKey, ...rest } = response;
38
+ if (!accessToken || !sessionId) {
41
39
  throw rest;
42
40
  }
43
41
  setToken(accessToken);
44
- setSecretKey(secretKey);
42
+ setSessionId(sessionId);
45
43
  setVisitorId(visitorId);
44
+ setSecretKey(secretKey);
46
45
  return await getUser();
47
46
  },
48
47
  getToken: async (body) => {