@inzombieland/nuxt-common 1.16.5 → 1.16.6
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 +7 -7
- package/dist/runtime/api/index.mjs +9 -8
- package/dist/runtime/packages/api/api-client.mjs +8 -8
- package/dist/runtime/packages/api/get-visitor.mjs +1 -1
- package/dist/runtime/packages/api/package.json +1 -1
- package/dist/runtime/packages/api/types.d.ts +7 -7
- package/dist/runtime/packages/helpers/package.json +1 -1
- package/dist/runtime/packages/layer-manager/package.json +1 -1
- 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.6";
|
|
6
6
|
|
|
7
7
|
const module = defineNuxtModule({
|
|
8
8
|
meta: {
|
|
@@ -2,13 +2,13 @@ import { type Fetch } from "../packages/api";
|
|
|
2
2
|
export { type ActiveSession, type Fetch, type User, type Visitor } from "../packages/api";
|
|
3
3
|
export { getVisitor, getVisitorId, useUser } from "../packages/api";
|
|
4
4
|
export declare const config: {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
apiBaseURL: string;
|
|
6
|
+
cometServerURL: string;
|
|
7
|
+
appClientID: string;
|
|
8
|
+
appClientSecret: string;
|
|
9
|
+
isMobileApp: boolean;
|
|
10
|
+
isDesktopApp: boolean;
|
|
11
|
+
appName: string;
|
|
12
12
|
getHostname: () => string;
|
|
13
13
|
getDevice: () => Promise<any>;
|
|
14
14
|
useRequestHeaders: (include?: string[]) => {
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import { useNuxtApp, useRequestHeaders, useRequestURL
|
|
1
|
+
import { useNuxtApp, useRequestHeaders, useRequestURL } from "#imports";
|
|
2
2
|
import { initApiFetch } from "../packages/api/index.mjs";
|
|
3
3
|
export { getVisitor, getVisitorId, useUser } from "../packages/api/index.mjs";
|
|
4
|
+
const getBoolean = (value) => value === "true";
|
|
4
5
|
export const config = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
apiBaseURL: String(import.meta.env.VITE_API_BASE_URL),
|
|
7
|
+
cometServerURL: String(import.meta.env.VITE_COMET_SERVER_URL),
|
|
8
|
+
appClientID: String(import.meta.env.VITE_APP_CLIENT_ID),
|
|
9
|
+
appClientSecret: String(import.meta.env.VITE_APP_CLIENT_SECRET),
|
|
10
|
+
isMobileApp: getBoolean(import.meta.env.VITE_IS_MOBILE_APP),
|
|
11
|
+
isDesktopApp: getBoolean(import.meta.env.VITE_IS_DESKTOP_APP),
|
|
12
|
+
appName: String(import.meta.env.VITE_APP_NAME),
|
|
12
13
|
getHostname: () => useRequestURL().hostname,
|
|
13
14
|
getDevice: async () => {
|
|
14
15
|
const { $device } = useNuxtApp();
|
|
@@ -72,22 +72,22 @@ const errorHandler = (error) => {
|
|
|
72
72
|
return new Error(message);
|
|
73
73
|
};
|
|
74
74
|
const optionsHandler = (options = {}, config) => {
|
|
75
|
-
const {
|
|
75
|
+
const { apiBaseURL, appClientID, appClientSecret, isMobileApp, isDesktopApp, getHostname } = config;
|
|
76
76
|
const baseURL = "/api";
|
|
77
77
|
const headers = {};
|
|
78
78
|
const visitor = { platform: "web", hostname: getHostname() };
|
|
79
79
|
if (token) {
|
|
80
80
|
headers.authorization = `JWT ${token}`;
|
|
81
|
-
} else if (typeof window !== "undefined" &&
|
|
82
|
-
const credentials = btoa(`${
|
|
81
|
+
} else if (typeof window !== "undefined" && appClientID && appClientSecret) {
|
|
82
|
+
const credentials = btoa(`${appClientID}:${appClientSecret}`);
|
|
83
83
|
headers.authorization = `Basic ${credentials}`;
|
|
84
84
|
}
|
|
85
|
-
if (
|
|
86
|
-
options.baseURL =
|
|
85
|
+
if (isMobileApp) {
|
|
86
|
+
options.baseURL = apiBaseURL;
|
|
87
87
|
visitor.platform = "mobile";
|
|
88
88
|
}
|
|
89
|
-
if (
|
|
90
|
-
options.baseURL =
|
|
89
|
+
if (isDesktopApp) {
|
|
90
|
+
options.baseURL = apiBaseURL;
|
|
91
91
|
visitor.platform = "desktop";
|
|
92
92
|
}
|
|
93
93
|
if (typeof window !== "undefined") {
|
|
@@ -128,7 +128,7 @@ const fetchRequest = (url, options = {}, fetch, config) => {
|
|
|
128
128
|
};
|
|
129
129
|
export const createApiFetch = once((fetch, config) => {
|
|
130
130
|
if (typeof window !== "undefined") {
|
|
131
|
-
const cometServerURL = config.
|
|
131
|
+
const cometServerURL = config.cometServerURL;
|
|
132
132
|
let cometClient;
|
|
133
133
|
bus.subscribe("user:onUpdated", (user) => {
|
|
134
134
|
if (user) {
|
|
@@ -24,7 +24,7 @@ export const getVisitorIdentifier = async (config) => {
|
|
|
24
24
|
setVisitor({ ip: data?.ip ?? "unknown" });
|
|
25
25
|
});
|
|
26
26
|
const device = await config.getDevice() || "unknown";
|
|
27
|
-
const appName = config.
|
|
27
|
+
const appName = config.appName || "unknown";
|
|
28
28
|
setVisitor({ id, ip, device, appName });
|
|
29
29
|
};
|
|
30
30
|
export const createApiGetVisitorIdentifier = once((config) => {
|
|
@@ -25,13 +25,13 @@ export interface Fetch {
|
|
|
25
25
|
create: (defaults: FetchOptions & FetchExtraOptions) => Fetch;
|
|
26
26
|
}
|
|
27
27
|
export type FetchConfig = {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
28
|
+
apiBaseURL: string;
|
|
29
|
+
cometServerURL: string;
|
|
30
|
+
appClientID: string;
|
|
31
|
+
appClientSecret: string;
|
|
32
|
+
isMobileApp: boolean;
|
|
33
|
+
isDesktopApp: boolean;
|
|
34
|
+
appName: string;
|
|
35
35
|
getHostname: () => string;
|
|
36
36
|
getDevice: () => Promise<string>;
|
|
37
37
|
useRequestHeaders?: (include: string[]) => {};
|