@inzombieland/core 1.20.4 → 1.20.7

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.js CHANGED
@@ -84,7 +84,7 @@ const optionsHandler = (options = {}, config) => {
84
84
  const visitor = { platform: "web", hostname: getHostname() };
85
85
  if (token) {
86
86
  headers.authorization = `JWT ${token}`;
87
- } else if (typeof window !== "undefined" && appClientID && appClientSecret) {
87
+ } else if (globalThis.window !== void 0 && appClientID && appClientSecret) {
88
88
  const credentials = btoa(`${appClientID}:${appClientSecret}`);
89
89
  headers.authorization = `Basic ${credentials}`;
90
90
  }
@@ -96,7 +96,7 @@ const optionsHandler = (options = {}, config) => {
96
96
  options.baseURL = apiBaseURL;
97
97
  visitor.platform = "desktop";
98
98
  }
99
- if (typeof window !== "undefined") {
99
+ if (globalThis.window !== void 0) {
100
100
  visitor.hostname = location.hostname;
101
101
  }
102
102
  const { platform, hostname } = visitor;
@@ -117,7 +117,7 @@ const optionsHandler = (options = {}, config) => {
117
117
  const fetchRequest = (url, options = {}, fetch, config) => {
118
118
  const request = async () => {
119
119
  const apiActions = useApiActions();
120
- if (typeof window !== "undefined") {
120
+ if (globalThis.window !== void 0) {
121
121
  await apiActions.value?.getVisitorIdentifier?.();
122
122
  }
123
123
  const opts = optionsHandler(options, config);
package/comet-client.d.ts CHANGED
@@ -3,6 +3,7 @@ declare global {
3
3
  interface Window {
4
4
  wsPublish: (eventName: string, data: unknown) => void;
5
5
  }
6
+ var wsPublish: (eventName: string, data: unknown) => void;
6
7
  }
7
8
  export declare function newCometClient(user: User, cometServerURL: string): {
8
9
  isStarted: boolean;
package/comet-client.js CHANGED
@@ -3,8 +3,8 @@ import { getToken } from "./api-client.js";
3
3
  import { useApiActions } from "./composables/index.js";
4
4
  import { apiHelper } from "./helpers/index.js";
5
5
  import { useBus } from "./index.js";
6
- if (typeof window !== "undefined" && import.meta.env.VITE_MODE !== "production") {
7
- window.wsPublish = (eventName, data) => {
6
+ if (globalThis.window !== void 0 && import.meta.env.VITE_MODE !== "production") {
7
+ globalThis.wsPublish = (eventName, data) => {
8
8
  const bus = useBus();
9
9
  setTimeout(() => bus.publish(`WS.${eventName}`, data), 0);
10
10
  };
@@ -1,11 +1,12 @@
1
1
  import { useLocalStorage } from "@vueuse/core";
2
2
  export const useAppLocale = () => {
3
+ const namespace = import.meta.env.VITE_APP_NAMESPACE ?? "app";
3
4
  let value = "en";
4
- if (typeof window !== "undefined" && window.navigator.language) {
5
- value = window.navigator.language.split("-")[0] ?? "en";
5
+ if (globalThis.window !== void 0 && globalThis.navigator.language) {
6
+ value = globalThis.navigator.language.split("-", 1)[0] ?? "en";
6
7
  }
7
8
  return useLocalStorage(
8
- "app-preferences-locale",
9
+ `${namespace}-preferences-locale`,
9
10
  { value },
10
11
  {
11
12
  serializer: {
@@ -9,7 +9,7 @@ const CookieDefaults = {
9
9
  decode: (val) => destr(decodeURIComponent(val)),
10
10
  encode: (val) => encodeURIComponent(typeof val === "string" ? val : JSON.stringify(val))
11
11
  };
12
- const store = typeof window !== "undefined" ? window.cookieStore : void 0;
12
+ const store = globalThis.window === void 0 ? void 0 : globalThis.cookieStore;
13
13
  export function useCookies(name, _opts) {
14
14
  const opts = { ...CookieDefaults, ..._opts };
15
15
  opts.filter ??= (key) => key === name;
@@ -63,11 +63,11 @@ export function useCookies(name, _opts) {
63
63
  if (store) {
64
64
  const changeHandler = (event) => {
65
65
  const changedCookie = event.changed.find((c) => c.name === name);
66
- const removedCookie = event.deleted.find((c) => c.name === name);
66
+ const hasRemovedCookie = event.deleted.some((c) => c.name === name);
67
67
  if (changedCookie) {
68
68
  handleChange({ value: changedCookie.value });
69
69
  }
70
- if (removedCookie) {
70
+ if (hasRemovedCookie) {
71
71
  handleChange({ value: null });
72
72
  }
73
73
  };
@@ -3,8 +3,7 @@ export declare const useSubscribe: <T>(eventName: string, func: (data: T) => voi
3
3
  once?: boolean;
4
4
  unsubscribeOnUnmount?: boolean;
5
5
  }) => Subscription | undefined;
6
- declare const _default: <T>(eventName: string, func: (data: T) => void, options?: {
6
+ export default function subscribe<T>(eventName: string, func: (data: T) => void, options?: {
7
7
  once?: boolean;
8
8
  unsubscribeOnUnmount?: boolean;
9
- }) => Subscription | undefined;
10
- export default _default;
9
+ }): Subscription | undefined;
@@ -1,6 +1,6 @@
1
1
  import { onMounted, onUnmounted } from "vue";
2
2
  import { useBus } from "../index.js";
3
- export const useSubscribe = (eventName, func, options = { once: false, unsubscribeOnUnmount: true }) => {
3
+ export const useSubscribe = (eventName, func, options = {}) => {
4
4
  const bus = useBus();
5
5
  let subscription;
6
6
  onMounted(() => {
@@ -12,12 +12,12 @@ export const useSubscribe = (eventName, func, options = { once: false, unsubscri
12
12
  });
13
13
  });
14
14
  onUnmounted(() => {
15
- if (options.unsubscribeOnUnmount) {
15
+ if (options.unsubscribeOnUnmount ?? true) {
16
16
  subscription?.unsubscribe();
17
17
  }
18
18
  });
19
19
  return subscription;
20
20
  };
21
- export default (eventName, func, options) => {
21
+ export default function subscribe(eventName, func, options) {
22
22
  return useSubscribe(eventName, func, options);
23
- };
23
+ }
@@ -1,8 +1,9 @@
1
1
  import { useLocalStorage, usePreferredDark } from "@vueuse/core";
2
2
  export const useThemeMode = () => {
3
+ const namespace = import.meta.env.VITE_APP_NAMESPACE ?? "app";
3
4
  const isDark = usePreferredDark();
4
5
  return useLocalStorage(
5
- "app-preferences-theme",
6
+ `${namespace}-preferences-theme`,
6
7
  { value: isDark.value ? "dark" : "light" },
7
8
  {
8
9
  serializer: {
package/get-visitor.js CHANGED
@@ -4,7 +4,7 @@ import { createSingletonAsync, once } from "./helpers/index.js";
4
4
  import { getVisitorId } from "./local-storage-utils.js";
5
5
  const setVisitor = (newVisitor) => {
6
6
  const visitor = useVisitor();
7
- visitor.value = !visitor.value ? newVisitor : { ...visitor.value, ...newVisitor };
7
+ visitor.value = visitor.value ? { ...visitor.value, ...newVisitor } : newVisitor;
8
8
  };
9
9
  const getVisitorRequest = async (config) => {
10
10
  const visitor = useVisitor();
@@ -1,7 +1,7 @@
1
1
  const device = {}
2
2
 
3
3
  // https://github.com/matthewhudson/current-device
4
- if (typeof window !== "undefined") {
4
+ if (globalThis.window !== undefined) {
5
5
  // Public functions to get the current value of type, os, or orientation.
6
6
  const findMatch = arr => {
7
7
  for (const name of arr) {
@@ -29,9 +29,8 @@ if (typeof window !== "undefined") {
29
29
 
30
30
  // Add one or more CSS classes to the <html> element.
31
31
  const addClass = className => {
32
- let currentClassNames = null
33
32
  if (!hasClass(className)) {
34
- currentClassNames = documentElement.classList.toString().trim()
33
+ const currentClassNames = documentElement.classList.toString().trim()
35
34
  documentElement.className = `${currentClassNames} ${className}`
36
35
  }
37
36
  }
@@ -68,19 +67,19 @@ if (typeof window !== "undefined") {
68
67
  }
69
68
 
70
69
  // Save the previous value of the device variable.
71
- const previousDevice = window.device
70
+ const previousDevice = globalThis.device
72
71
 
73
72
  const changeOrientationList = []
74
73
 
75
74
  // Add device as a global object.
76
- window.device = device
75
+ globalThis.device = device
77
76
 
78
77
  // The <html> element.
79
- const documentElement = window.document.documentElement
78
+ const documentElement = globalThis.document.documentElement
80
79
 
81
80
  // The client user agent string.
82
81
  // Lowercase, so we can use the more efficient indexOf(), instead of Regex
83
- const userAgent = window.navigator.userAgent.toLowerCase()
82
+ const userAgent = globalThis.navigator.userAgent.toLowerCase()
84
83
 
85
84
  // Detectable television devices.
86
85
  const television = [
@@ -177,7 +176,7 @@ if (typeof window !== "undefined") {
177
176
  }
178
177
 
179
178
  device.cordova = function () {
180
- return window.cordova && location.protocol === "file:"
179
+ return globalThis.cordova && location.protocol === "file:"
181
180
  }
182
181
 
183
182
  device.mobile = function () {
@@ -237,7 +236,7 @@ if (typeof window !== "undefined") {
237
236
  // Run device.js in noConflict mode,
238
237
  // returning the device variable to its previous owner.
239
238
  device.noConflict = function () {
240
- window.device = previousDevice
239
+ globalThis.device = previousDevice
241
240
  return this
242
241
  }
243
242
 
@@ -1,7 +1,7 @@
1
1
  export { apiHelper } from "./api-helper.js";
2
+ export * from "./composables.js";
2
3
  export { deviceHelper, type Device } from "./device-helper.js";
3
4
  export { phoneHelper } from "./phone-helper.js";
4
5
  export { stringHelper } from "./string-helper.js";
5
- export * from "./composables.js";
6
6
  export declare function once<T extends (...args: any[]) => any>(fn: T): T;
7
7
  export declare function createSingletonAsync<T, Args extends unknown[]>(fn: (...args: Args) => Promise<T>): (...args: Args) => Promise<T>;
package/helpers/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  export { apiHelper } from "./api-helper.js";
2
+ export * from "./composables.js";
2
3
  export { deviceHelper } from "./device-helper.js";
3
4
  export { phoneHelper } from "./phone-helper.js";
4
5
  export { stringHelper } from "./string-helper.js";
5
- export * from "./composables.js";
6
6
  export function once(fn) {
7
7
  let executed = false;
8
8
  let result;
package/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { type Ref } from "vue";
2
2
  import type { Fetch, FetchConfig } from "./types.js";
3
- export { defineVuePlugins } from "./define-vue-plugins.js";
4
3
  export { default as AppProvider, useBus } from "./AppProvider.vue.js";
5
4
  export * from "./composables/index.js";
5
+ export { defineVuePlugins } from "./define-vue-plugins.js";
6
6
  export * from "./types.js";
7
7
  export declare function initApiFetch($fetch: Fetch, config: FetchConfig): {
8
8
  fetch: Fetch;
package/index.js CHANGED
@@ -9,9 +9,9 @@ import { createApiGetVisitorIdentifier } from "./get-visitor.js";
9
9
  import { createInitApplication } from "./init-application.js";
10
10
  import { createApiRefreshToken } from "./refresh-token.js";
11
11
  import { createApiUserActions } from "./user-actions.js";
12
- export { defineVuePlugins } from "./define-vue-plugins.js";
13
12
  export { default as AppProvider, useBus } from "./AppProvider.vue";
14
13
  export * from "./composables/index.js";
14
+ export { defineVuePlugins } from "./define-vue-plugins.js";
15
15
  export * from "./types.js";
16
16
  const apiActions = useApiActions();
17
17
  let userActions;
@@ -23,7 +23,7 @@ export function initApiFetch($fetch, config) {
23
23
  const refreshToken = createApiRefreshToken(fetch, config);
24
24
  userActions = ref(createApiUserActions(fetch, config, getUser));
25
25
  apiActions.value = { getVisitorIdentifier, refreshToken };
26
- if (typeof window !== "undefined") {
26
+ if (globalThis.window !== void 0) {
27
27
  const loggedIn = useLocalStorage("lin", "no");
28
28
  const cometServerURL = config.cometServerURL;
29
29
  let cometClient;
@@ -1,22 +1,23 @@
1
+ const namespace = import.meta.env.VITE_APP_NAMESPACE ?? "app";
1
2
  export const getSessionId = () => {
2
- if (typeof window !== "undefined") {
3
- return window.localStorage.getItem("sid");
3
+ if (globalThis.window !== void 0) {
4
+ return globalThis.localStorage.getItem(`${namespace}-sid`);
4
5
  }
5
6
  return null;
6
7
  };
7
8
  export const setSessionId = (sessionId = "") => {
8
- if (typeof window !== "undefined") {
9
- window.localStorage.setItem("sid", sessionId);
9
+ if (globalThis.window !== void 0) {
10
+ globalThis.localStorage.setItem(`${namespace}-sid`, sessionId);
10
11
  }
11
12
  };
12
13
  export const getVisitorId = () => {
13
- if (typeof window !== "undefined") {
14
- return window.localStorage.getItem("vid");
14
+ if (globalThis.window !== void 0) {
15
+ return globalThis.localStorage.getItem(`${namespace}-vid`);
15
16
  }
16
17
  return null;
17
18
  };
18
19
  export const setVisitorId = (visitorId = "") => {
19
- if (typeof window !== "undefined") {
20
- window.localStorage.setItem("vid", visitorId);
20
+ if (globalThis.window !== void 0) {
21
+ globalThis.localStorage.setItem(`${namespace}-vid`, visitorId);
21
22
  }
22
23
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@inzombieland/core",
3
- "version": "1.20.4",
4
3
  "type": "module",
4
+ "version": "1.20.7",
5
5
  "license": "ISC",
6
6
  "main": "./index.js",
7
7
  "types": "./index.d.ts",
package/user-actions.js CHANGED
@@ -9,7 +9,7 @@ export const createApiUserActions = once(
9
9
  const response = await fetch("/account/0/signin", {
10
10
  body,
11
11
  method: "POST",
12
- ...config.useRequestHeaders?.(["cookie"]) ?? {}
12
+ ...config.useRequestHeaders?.(["cookie"])
13
13
  });
14
14
  const { key, ...rest } = response;
15
15
  if (key) {
@@ -21,7 +21,7 @@ export const createApiUserActions = once(
21
21
  const response = await fetch("/account/0/signinbycode/verifycode", {
22
22
  body,
23
23
  method: "POST",
24
- ...config.useRequestHeaders?.(["cookie"]) ?? {}
24
+ ...config.useRequestHeaders?.(["cookie"])
25
25
  });
26
26
  const { accessToken, sessionId, visitorId, secretKey, ...rest } = response;
27
27
  if (!accessToken || !sessionId || !visitorId || !secretKey) {
@@ -37,7 +37,7 @@ export const createApiUserActions = once(
37
37
  const response = await fetch("/account/0/token", {
38
38
  body,
39
39
  method: "POST",
40
- ...config.useRequestHeaders?.(["cookie"]) ?? {}
40
+ ...config.useRequestHeaders?.(["cookie"])
41
41
  });
42
42
  const { accessToken, ...rest } = response;
43
43
  if (!accessToken) {
@@ -50,21 +50,21 @@ export const createApiUserActions = once(
50
50
  return await fetch("/account/0/signup", {
51
51
  body,
52
52
  method: "POST",
53
- ...config.useRequestHeaders?.(["cookie"]) ?? {}
53
+ ...config.useRequestHeaders?.(["cookie"])
54
54
  });
55
55
  },
56
56
  confirmEmail: async (body) => {
57
57
  return await fetch("/account/0/signup", {
58
58
  body,
59
59
  method: "PUT",
60
- ...config.useRequestHeaders?.(["cookie"]) ?? {}
60
+ ...config.useRequestHeaders?.(["cookie"])
61
61
  });
62
62
  },
63
63
  resendActivationEmail: async (body) => {
64
64
  return await fetch("/account/0/signup", {
65
65
  body,
66
66
  method: "PATCH",
67
- ...config.useRequestHeaders?.(["cookie"]) ?? {}
67
+ ...config.useRequestHeaders?.(["cookie"])
68
68
  });
69
69
  },
70
70
  logout: async () => {
@@ -81,21 +81,21 @@ export const createApiUserActions = once(
81
81
  return await fetch("/account/0/recovery", {
82
82
  body,
83
83
  method: "POST",
84
- ...config.useRequestHeaders?.(["cookie"]) ?? {}
84
+ ...config.useRequestHeaders?.(["cookie"])
85
85
  });
86
86
  },
87
87
  confirmRecovery: async (body) => {
88
88
  return await fetch("/account/0/recovery", {
89
89
  body,
90
90
  method: "PATCH",
91
- ...config.useRequestHeaders?.(["cookie"]) ?? {}
91
+ ...config.useRequestHeaders?.(["cookie"])
92
92
  });
93
93
  },
94
94
  resetPassword: async (body) => {
95
95
  return await fetch("/account/0/recovery", {
96
96
  body,
97
97
  method: "PUT",
98
- ...config.useRequestHeaders?.(["cookie"]) ?? {}
98
+ ...config.useRequestHeaders?.(["cookie"])
99
99
  });
100
100
  },
101
101
  changeName: async (body) => {