@enfyra/sdk-nuxt 0.3.24 → 0.3.26

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 CHANGED
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": ">=3.0.0"
6
6
  },
7
- "version": "0.3.24",
7
+ "version": "0.3.26",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "0.8.4",
10
10
  "unbuild": "2.0.0"
@@ -1 +1 @@
1
- {"version":3,"file":"useEnfyraAuth.d.ts","sourceRoot":"","sources":["../../../src/runtime/composables/useEnfyraAuth.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAsB,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAOhF,wBAAgB,aAAa,IAAI,mBAAmB,CA8EnD"}
1
+ {"version":3,"file":"useEnfyraAuth.d.ts","sourceRoot":"","sources":["../../../src/runtime/composables/useEnfyraAuth.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAsB,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAOhF,wBAAgB,aAAa,IAAI,mBAAmB,CAiFnD"}
@@ -1,5 +1,5 @@
1
1
  import { ref, computed } from "vue";
2
- import { $fetch } from "../utils/http.js";
2
+ import { $fetch } from "ofetch";
3
3
  import { useEnfyra } from "./useEnfyra.js";
4
4
  const me = ref(null);
5
5
  const isLoading = ref(false);
@@ -8,9 +8,10 @@ export function useEnfyraAuth() {
8
8
  const login = async (payload) => {
9
9
  isLoading.value = true;
10
10
  try {
11
- const response = await $fetch(`${baseUrl}/login`, {
11
+ const response = await $fetch("/login", {
12
12
  method: "POST",
13
- body: payload
13
+ body: payload,
14
+ baseURL: baseUrl
14
15
  });
15
16
  me.value = response?.data?.[0] || null;
16
17
  return response;
@@ -24,8 +25,9 @@ export function useEnfyraAuth() {
24
25
  const logout = async () => {
25
26
  isLoading.value = true;
26
27
  try {
27
- await $fetch(`${baseUrl}/logout`, {
28
- method: "POST"
28
+ await $fetch("/logout", {
29
+ method: "POST",
30
+ baseURL: baseUrl
29
31
  });
30
32
  me.value = null;
31
33
  if (typeof window !== "undefined") {
@@ -48,9 +50,10 @@ export function useEnfyraAuth() {
48
50
  if (options?.fields && options.fields.length > 0) {
49
51
  queryParams.fields = options.fields.join(",");
50
52
  }
51
- const response = await $fetch(`${baseUrl}/me`, {
53
+ const response = await $fetch("/me", {
52
54
  method: "GET",
53
- query: queryParams
55
+ query: queryParams,
56
+ baseURL: baseUrl
54
57
  });
55
58
  me.value = response?.data?.[0] || null;
56
59
  } catch (error) {
@@ -1,3 +1,3 @@
1
1
  import { H3Event } from "h3";
2
- export declare function proxyToAPI(event: H3Event, customPath?: string): Promise<any>;
2
+ export declare function proxyToAPI(event: H3Event, customPath?: string): any;
3
3
  //# sourceMappingURL=proxy.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"proxy.d.ts","sourceRoot":"","sources":["../../../../src/runtime/utils/server/proxy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAgB,MAAM,IAAI,CAAC;AAK3C,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,EAAE,UAAU,CAAC,EAAE,MAAM,gBAY7D"}
1
+ {"version":3,"file":"proxy.d.ts","sourceRoot":"","sources":["../../../../src/runtime/utils/server/proxy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAgB,MAAM,IAAI,CAAC;AAK3C,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,EAAE,UAAU,CAAC,EAAE,MAAM,OAyB7D"}
@@ -8,6 +8,16 @@ export function proxyToAPI(event, customPath) {
8
8
  const rawPath = customPath || event.path.replace(new RegExp(`^${apiPrefix}`), "");
9
9
  const targetUrl = normalizeUrl(config.public?.enfyraSDK?.apiUrl, rawPath);
10
10
  const headers = event.context.proxyHeaders || {};
11
+ const isWebSocket = event.headers.get("upgrade")?.toLowerCase() === "websocket";
12
+ if (isWebSocket) {
13
+ return proxyRequest(event, targetUrl, {
14
+ headers,
15
+ fetchOptions: {
16
+ // @ts-ignore - duplex is required for WebSocket in Node fetch
17
+ duplex: "half"
18
+ }
19
+ });
20
+ }
11
21
  return proxyRequest(event, targetUrl, {
12
22
  headers
13
23
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@enfyra/sdk-nuxt",
3
- "version": "0.3.24",
3
+ "version": "0.3.26",
4
4
  "type": "module",
5
5
  "description": "Nuxt SDK for Enfyra CMS",
6
6
  "repository": {
@@ -72,4 +72,4 @@
72
72
  "vite-plugin-dts": "^4.3.0",
73
73
  "vitest": "^3.2.4"
74
74
  }
75
- }
75
+ }
@@ -1,6 +1,6 @@
1
1
  import { ref, computed } from "vue";
2
2
  import type { LoginPayload, User, UseEnfyraAuthReturn } from "../../types/auth";
3
- import { $fetch } from "../utils/http";
3
+ import { $fetch } from "ofetch";
4
4
  import { useEnfyra } from "./useEnfyra";
5
5
 
6
6
  const me = ref<User | null>(null);
@@ -13,9 +13,10 @@ export function useEnfyraAuth(): UseEnfyraAuthReturn {
13
13
  isLoading.value = true;
14
14
 
15
15
  try {
16
- const response = await $fetch(`${baseUrl}/login`, {
16
+ const response = await $fetch("/login", {
17
17
  method: "POST",
18
18
  body: payload,
19
+ baseURL: baseUrl,
19
20
  });
20
21
 
21
22
  me.value = (response as any)?.data?.[0] || null;
@@ -32,8 +33,9 @@ export function useEnfyraAuth(): UseEnfyraAuthReturn {
32
33
  isLoading.value = true;
33
34
 
34
35
  try {
35
- await $fetch(`${baseUrl}/logout`, {
36
+ await $fetch("/logout", {
36
37
  method: "POST",
38
+ baseURL: baseUrl,
37
39
  });
38
40
  me.value = null;
39
41
 
@@ -61,9 +63,10 @@ export function useEnfyraAuth(): UseEnfyraAuthReturn {
61
63
  queryParams.fields = options.fields.join(",");
62
64
  }
63
65
 
64
- const response = await $fetch(`${baseUrl}/me`, {
66
+ const response = await $fetch("/me", {
65
67
  method: "GET",
66
68
  query: queryParams,
69
+ baseURL: baseUrl,
67
70
  });
68
71
 
69
72
  me.value = (response as any)?.data?.[0] || null;
@@ -12,6 +12,19 @@ export function proxyToAPI(event: H3Event, customPath?: string) {
12
12
 
13
13
  const headers = event.context.proxyHeaders || {};
14
14
 
15
+ // Detect WebSocket upgrade request
16
+ const isWebSocket = event.headers.get('upgrade')?.toLowerCase() === 'websocket';
17
+
18
+ if (isWebSocket) {
19
+ return proxyRequest(event, targetUrl, {
20
+ headers,
21
+ fetchOptions: {
22
+ // @ts-ignore - duplex is required for WebSocket in Node fetch
23
+ duplex: 'half',
24
+ },
25
+ }) as any;
26
+ }
27
+
15
28
  return proxyRequest(event, targetUrl, {
16
29
  headers,
17
30
  });
@@ -1,8 +0,0 @@
1
- export declare function $fetch<T = any>(path: string, options?: {
2
- method?: string;
3
- body?: any;
4
- headers?: Record<string, string>;
5
- query?: Record<string, any>;
6
- baseURL?: string;
7
- }): Promise<T>;
8
- //# sourceMappingURL=http.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../src/runtime/utils/http.ts"],"names":[],"mappings":"AAAA,wBAAsB,MAAM,CAAC,CAAC,GAAG,GAAG,EAClC,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE;IACP,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAC;CACb,GACL,OAAO,CAAC,CAAC,CAAC,CAoEZ"}
@@ -1,61 +0,0 @@
1
- export async function $fetch(path, options = {}) {
2
- const {
3
- method = "GET",
4
- body,
5
- headers: optionHeaders = {},
6
- query = {},
7
- baseURL
8
- } = options;
9
- if (!baseURL) {
10
- throw new Error("baseURL is required for $fetch");
11
- }
12
- const url = new URL(
13
- path.startsWith("/") ? path.slice(1) : path,
14
- baseURL.endsWith("/") ? baseURL : `${baseURL}/`
15
- );
16
- Object.entries(query).forEach(([key, value]) => {
17
- if (value !== void 0 && value !== null) {
18
- if (typeof value === "object") {
19
- url.searchParams.append(key, JSON.stringify(value));
20
- } else {
21
- url.searchParams.append(key, String(value));
22
- }
23
- }
24
- });
25
- const headers = {
26
- "Content-Type": "application/json",
27
- ...optionHeaders
28
- };
29
- const fetchOptions = {
30
- method: method.toUpperCase(),
31
- headers
32
- };
33
- if (body && method.toUpperCase() !== "GET") {
34
- if (body instanceof FormData) {
35
- delete headers["Content-Type"];
36
- fetchOptions.body = body;
37
- } else {
38
- fetchOptions.body = JSON.stringify(body);
39
- }
40
- }
41
- try {
42
- const response = await fetch(url.toString(), fetchOptions);
43
- if (!response.ok) {
44
- let errorData;
45
- try {
46
- errorData = await response.json();
47
- } catch {
48
- errorData = { message: response.statusText };
49
- }
50
- throw { response: { data: errorData } };
51
- }
52
- const contentType = response.headers.get("content-type");
53
- if (contentType?.includes("application/json")) {
54
- return await response.json();
55
- } else {
56
- return await response.text();
57
- }
58
- } catch (error) {
59
- throw error;
60
- }
61
- }
@@ -1,78 +0,0 @@
1
- export async function $fetch<T = any>(
2
- path: string,
3
- options: {
4
- method?: string;
5
- body?: any;
6
- headers?: Record<string, string>;
7
- query?: Record<string, any>;
8
- baseURL?: string;
9
- } = {}
10
- ): Promise<T> {
11
- const {
12
- method = "GET",
13
- body,
14
- headers: optionHeaders = {},
15
- query = {},
16
- baseURL,
17
- } = options;
18
- if (!baseURL) {
19
- throw new Error('baseURL is required for $fetch');
20
- }
21
-
22
- const url = new URL(
23
- path.startsWith("/") ? path.slice(1) : path,
24
- baseURL.endsWith("/") ? baseURL : `${baseURL}/`
25
- );
26
-
27
- Object.entries(query).forEach(([key, value]) => {
28
- if (value !== undefined && value !== null) {
29
- if (typeof value === 'object') {
30
- url.searchParams.append(key, JSON.stringify(value));
31
- } else {
32
- url.searchParams.append(key, String(value));
33
- }
34
- }
35
- });
36
-
37
- const headers: Record<string, string> = {
38
- "Content-Type": "application/json",
39
- ...optionHeaders,
40
- };
41
-
42
- const fetchOptions: RequestInit = {
43
- method: method.toUpperCase(),
44
- headers,
45
- };
46
-
47
- if (body && method.toUpperCase() !== "GET") {
48
- if (body instanceof FormData) {
49
- delete headers["Content-Type"]; // Let browser set boundary for FormData
50
- fetchOptions.body = body;
51
- } else {
52
- fetchOptions.body = JSON.stringify(body);
53
- }
54
- }
55
-
56
- try {
57
- const response = await fetch(url.toString(), fetchOptions);
58
-
59
- if (!response.ok) {
60
- let errorData;
61
- try {
62
- errorData = await response.json();
63
- } catch {
64
- errorData = { message: response.statusText };
65
- }
66
- throw { response: { data: errorData } };
67
- }
68
-
69
- const contentType = response.headers.get("content-type");
70
- if (contentType?.includes("application/json")) {
71
- return await response.json();
72
- } else {
73
- return (await response.text()) as T;
74
- }
75
- } catch (error) {
76
- throw error;
77
- }
78
- }