@enfyra/sdk-nuxt 0.7.3 → 0.7.4

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.cjs CHANGED
@@ -103,11 +103,6 @@ declare module '#imports' {
103
103
  handler: resolve("./runtime/server/api/auth/callback.get"),
104
104
  method: "get"
105
105
  });
106
- kit.addServerHandler({
107
- route: `${apiPrefix}/auth/[provider]`,
108
- handler: resolve("./runtime/server/api/auth/[provider].get"),
109
- method: "get"
110
- });
111
106
  kit.addServerHandler({
112
107
  route: "/assets/**",
113
108
  handler: resolve("./runtime/server/api/all")
@@ -1 +1 @@
1
- {"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAYA,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;;AAED,wBA2IG"}
1
+ {"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAYA,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;;AAED,wBAmIG"}
package/dist/module.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": ">=3.0.0"
6
6
  },
7
- "version": "0.7.3",
7
+ "version": "0.7.4",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "0.8.4",
10
10
  "unbuild": "2.0.0"
package/dist/module.mjs CHANGED
@@ -100,11 +100,6 @@ declare module '#imports' {
100
100
  handler: resolve("./runtime/server/api/auth/callback.get"),
101
101
  method: "get"
102
102
  });
103
- addServerHandler({
104
- route: `${apiPrefix}/auth/[provider]`,
105
- handler: resolve("./runtime/server/api/auth/[provider].get"),
106
- method: "get"
107
- });
108
103
  addServerHandler({
109
104
  route: "/assets/**",
110
105
  handler: resolve("./runtime/server/api/all")
@@ -1 +1 @@
1
- {"version":3,"file":"useEnfyraAuth.d.ts","sourceRoot":"","sources":["../../../src/runtime/composables/useEnfyraAuth.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAsB,mBAAmB,EAAiB,MAAM,kBAAkB,CAAC;AAO/F,wBAAgB,aAAa,IAAI,mBAAmB,CA4FnD"}
1
+ {"version":3,"file":"useEnfyraAuth.d.ts","sourceRoot":"","sources":["../../../src/runtime/composables/useEnfyraAuth.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAsB,mBAAmB,EAAiB,MAAM,kBAAkB,CAAC;AAO/F,wBAAgB,aAAa,IAAI,mBAAmB,CA6FnD"}
@@ -4,7 +4,7 @@ import { useEnfyra } from "./useEnfyra.js";
4
4
  const me = ref(null);
5
5
  const isLoading = ref(false);
6
6
  export function useEnfyraAuth() {
7
- const { baseUrl } = useEnfyra();
7
+ const { baseUrl, apiPrefix } = useEnfyra();
8
8
  const login = async (payload) => {
9
9
  isLoading.value = true;
10
10
  try {
@@ -70,7 +70,8 @@ export function useEnfyraAuth() {
70
70
  return;
71
71
  }
72
72
  const currentUrl = window.location.href;
73
- window.location.href = `/api/auth/${provider}?redirect=${encodeURIComponent(currentUrl)}`;
73
+ const path = `${apiPrefix.replace(/\/+$/, "")}/auth/${provider}?redirect=${encodeURIComponent(currentUrl)}`;
74
+ window.location.href = path.startsWith("/") ? path : `/${path}`;
74
75
  };
75
76
  return {
76
77
  me,
@@ -1 +1 @@
1
- {"version":3,"file":"all.d.ts","sourceRoot":"","sources":["../../../../src/runtime/server/api/all.ts"],"names":[],"mappings":";AAaA,wBAyBG"}
1
+ {"version":3,"file":"all.d.ts","sourceRoot":"","sources":["../../../../src/runtime/server/api/all.ts"],"names":[],"mappings":";AAoBA,wBA+BG"}
@@ -1,4 +1,10 @@
1
- import { defineEventHandler, getQuery, sendRedirect, setResponseHeaders } from "h3";
1
+ import {
2
+ createError,
3
+ defineEventHandler,
4
+ getQuery,
5
+ sendRedirect,
6
+ setResponseHeaders
7
+ } from "h3";
2
8
  import { useRuntimeConfig } from "#imports";
3
9
  import { proxyToAPI } from "../../utils/server/proxy.js";
4
10
  const CORS_HEADERS = {
@@ -7,26 +13,34 @@ const CORS_HEADERS = {
7
13
  "Access-Control-Allow-Headers": "Content-Type, Authorization",
8
14
  "Access-Control-Max-Age": "86400"
9
15
  };
10
- const OAUTH_INIT_PATTERN = /\/auth\/(google|facebook|github)(?:\/|$|\?)/;
16
+ const OAUTH_PROVIDERS = ["google", "facebook", "github"];
17
+ const OAUTH_INIT_PATTERN = new RegExp(`/auth/(${OAUTH_PROVIDERS.join("|")})(?:/|$|\\?)`);
11
18
  export default defineEventHandler(async (event) => {
12
19
  setResponseHeaders(event, CORS_HEADERS);
13
20
  if (event.method === "OPTIONS") {
14
21
  return "";
15
22
  }
16
- const pathname = event.path?.split("?")[0] || event.path || "";
17
- const oauthMatch = pathname.match(OAUTH_INIT_PATTERN);
23
+ const path = (event.path || event.node?.req?.url || "").split("?")[0];
24
+ const oauthMatch = path.match(OAUTH_INIT_PATTERN);
18
25
  if (event.method === "GET" && oauthMatch) {
19
26
  const provider = oauthMatch[1];
20
27
  const query = getQuery(event);
21
28
  const redirectParam = query.redirect;
22
- if (redirectParam) {
23
- const config = useRuntimeConfig();
24
- const apiUrl = config.public?.enfyraSDK?.apiUrl;
25
- if (apiUrl) {
26
- const backendUrl = `${apiUrl.replace(/\/+$/, "")}/auth/${provider}?redirect=${encodeURIComponent(redirectParam)}`;
27
- return sendRedirect(event, backendUrl, 302);
28
- }
29
+ if (!redirectParam) {
30
+ throw createError({ statusCode: 400, message: "Redirect URL is required" });
29
31
  }
32
+ const config = useRuntimeConfig();
33
+ const apiUrl = config.public?.enfyraSDK?.apiUrl;
34
+ if (!apiUrl) {
35
+ throw createError({ statusCode: 500, message: "API URL not configured" });
36
+ }
37
+ const backendUrl = `${apiUrl.replace(/\/+$/, "")}/auth/${provider}?redirect=${encodeURIComponent(redirectParam)}`;
38
+ const response = await fetch(backendUrl, { redirect: "manual" });
39
+ const location = response.headers.get("location") || response.headers.get("Location");
40
+ if (location && response.status >= 300 && response.status < 400) {
41
+ return sendRedirect(event, location, 302);
42
+ }
43
+ throw createError({ statusCode: 502, message: "Failed to get OAuth URL from backend" });
30
44
  }
31
45
  return proxyToAPI(event);
32
46
  });
@@ -1 +1 @@
1
- {"version":3,"file":"callback.get.d.ts","sourceRoot":"","sources":["../../../../../src/runtime/server/api/auth/callback.get.ts"],"names":[],"mappings":";AAaA,wBAyBG"}
1
+ {"version":3,"file":"callback.get.d.ts","sourceRoot":"","sources":["../../../../../src/runtime/server/api/auth/callback.get.ts"],"names":[],"mappings":";AAaA,wBAsBG"}
@@ -1 +1 @@
1
- {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../../../src/runtime/server/middleware/auth.ts"],"names":[],"mappings":";AAQA,wBAuCG"}
1
+ {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../../../src/runtime/server/middleware/auth.ts"],"names":[],"mappings":";AAQA,wBAsCG"}
@@ -9,27 +9,16 @@ export interface ApiError {
9
9
  response?: any;
10
10
  }
11
11
  export interface BatchProgress {
12
- /** Current progress percentage (0-100) */
13
12
  progress: number;
14
- /** Number of completed operations */
15
13
  completed: number;
16
- /** Total number of operations */
17
14
  total: number;
18
- /** Number of failed operations */
19
15
  failed: number;
20
- /** Number of operations currently in progress */
21
16
  inProgress: number;
22
- /** Estimated time remaining in milliseconds */
23
17
  estimatedTimeRemaining?: number;
24
- /** Average time per operation in milliseconds */
25
18
  averageTime?: number;
26
- /** Current batch being processed */
27
19
  currentBatch: number;
28
- /** Total number of batches */
29
20
  totalBatches: number;
30
- /** Processing speed (operations per second) */
31
21
  operationsPerSecond?: number;
32
- /** Detailed results array for completed operations */
33
22
  results: Array<{
34
23
  index: number;
35
24
  status: 'completed' | 'failed';
@@ -47,41 +36,24 @@ interface BaseApiOptions<T> {
47
36
  onError?: (error: ApiError, context?: string) => void;
48
37
  disableBatch?: boolean;
49
38
  default?: () => T;
50
- /** Enable SSR with useFetch instead of $fetch */
51
39
  ssr?: boolean;
52
- /** Unique key for useFetch caching */
53
40
  key?: string;
54
- /** Whether to fetch on server (default: true) - Only applies when ssr: true */
55
41
  server?: boolean;
56
- /** Don't block navigation (default: false) - Only applies when ssr: true */
57
42
  lazy?: boolean;
58
- /** Execute immediately (default: true) - Only applies when ssr: true */
59
43
  immediate?: boolean;
60
- /** Transform the response data - Only applies when ssr: true */
61
44
  transform?: (data: any) => T;
62
- /** Pick specific fields from response - Only applies when ssr: true */
63
45
  pick?: string[];
64
- /** Watch reactive sources and refetch when they change - Only applies when ssr: true */
65
46
  watch?: any[];
66
- /** Deep watch (default: false) - Only applies when ssr: true */
67
47
  deep?: boolean;
68
- /** Custom cache data retrieval function - Only applies when ssr: true */
69
48
  getCachedData?: (key: string) => T | null;
70
- /** Enable refresh (default: true) - Only applies when ssr: true */
71
49
  refresh?: boolean;
72
- /** Auto refresh interval in milliseconds - Only applies when ssr: true */
73
50
  refreshInterval?: number;
74
- /** Deduplication key - Only applies when ssr: true */
75
51
  dedupe?: string;
76
- /** Cache mode for the fetch request - Only applies when ssr: true */
77
52
  cache?: RequestCache;
78
53
  }
79
54
  interface BatchApiOptions {
80
- /** Batch size for chunking large operations (default: no limit) - Only available for batch operations */
81
55
  batchSize?: number;
82
- /** Maximum concurrent requests (default: no limit) - Only available for batch operations */
83
56
  concurrent?: number;
84
- /** Real-time progress callback for batch operations - Only available for batch operations */
85
57
  onProgress?: (progress: BatchProgress) => void;
86
58
  }
87
59
  type ConditionalBatchOptions<T> = T extends {
@@ -123,13 +95,9 @@ interface BaseExecuteOptions {
123
95
  }
124
96
  interface BatchExecuteOptions {
125
97
  ids?: (string | number)[];
126
- /** Array of FormData objects for batch upload */
127
98
  files?: FormData[];
128
- /** Override batch size for this specific execution */
129
99
  batchSize?: number;
130
- /** Override concurrent limit for this specific execution */
131
100
  concurrent?: number;
132
- /** Override progress callback for this specific execution */
133
101
  onProgress?: (progress: BatchProgress) => void;
134
102
  }
135
103
  export type ExecuteOptions = BaseExecuteOptions & BatchExecuteOptions;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACzC;AAED,MAAM,WAAW,QAAQ;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,QAAQ,CAAC,EAAE,GAAG,CAAC;CAChB;AAED,MAAM,WAAW,aAAa;IAC5B,0CAA0C;IAC1C,QAAQ,EAAE,MAAM,CAAC;IACjB,qCAAqC;IACrC,SAAS,EAAE,MAAM,CAAC;IAClB,iCAAiC;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,kCAAkC;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,iDAAiD;IACjD,UAAU,EAAE,MAAM,CAAC;IACnB,+CAA+C;IAC/C,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,iDAAiD;IACjD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,oCAAoC;IACpC,YAAY,EAAE,MAAM,CAAC;IACrB,8BAA8B;IAC9B,YAAY,EAAE,MAAM,CAAC;IACrB,+CAA+C;IAC/C,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,sDAAsD;IACtD,OAAO,EAAE,KAAK,CAAC;QACb,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,WAAW,GAAG,QAAQ,CAAC;QAC/B,MAAM,CAAC,EAAE,GAAG,CAAC;QACb,KAAK,CAAC,EAAE,QAAQ,CAAC;QACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB,CAAC,CAAC;CACJ;AAED,UAAU,cAAc,CAAC,CAAC;IACxB,MAAM,CAAC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AC;IAC7B,OAAO,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;CACxB;AAED,UAAU,kBAAkB;IAC1B,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC7B;AAED,UAAU,mBAAmB;IAC3B,GAAG,CAAC,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;IAC1B,KAAK,CAAC,EAAE,QAAQ,EAAE,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,aAAa,KAAK,IAAI,CAAC;CAChD;AAQD,MAAM,MAAM,cAAc,GAAG,kBAAkB,GAAG,mBAAmB,CAAC;AAEtE,MAAM,WAAW,wBAAwB,CAAC,CAAC;IACzC,IAAI,EAAE,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;IACpB,KAAK,EAAE,GAAG,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC;IAC5B,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;IACtB,OAAO,EAAE,CAAC,WAAW,CAAC,EAAE,cAAc,KAAK,OAAO,CAAC,CAAC,GAAG,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC;CACpE;AAGD,cAAc,QAAQ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@enfyra/sdk-nuxt",
3
- "version": "0.7.3",
3
+ "version": "0.7.4",
4
4
  "type": "module",
5
5
  "description": "Nuxt SDK for Enfyra CMS",
6
6
  "repository": {
package/src/module.ts CHANGED
@@ -130,20 +130,12 @@ declare module '#imports' {
130
130
  method: "post",
131
131
  });
132
132
 
133
- // OAuth callback - sets cookies and redirects (must be before [provider])
134
133
  addServerHandler({
135
134
  route: `${apiPrefix}/auth/callback`,
136
135
  handler: resolve("./runtime/server/api/auth/callback.get"),
137
136
  method: "get",
138
137
  });
139
138
 
140
- // OAuth initiate - redirect to backend (not proxy)
141
- addServerHandler({
142
- route: `${apiPrefix}/auth/[provider]`,
143
- handler: resolve("./runtime/server/api/auth/[provider].get"),
144
- method: "get",
145
- });
146
-
147
139
  addServerHandler({
148
140
  route: "/assets/**",
149
141
  handler: resolve("./runtime/server/api/all"),
@@ -7,7 +7,7 @@ const me = ref<User | null>(null);
7
7
  const isLoading = ref<boolean>(false);
8
8
 
9
9
  export function useEnfyraAuth(): UseEnfyraAuthReturn {
10
- const { baseUrl } = useEnfyra();
10
+ const { baseUrl, apiPrefix } = useEnfyra();
11
11
 
12
12
  const login = async (payload: LoginPayload) => {
13
13
  isLoading.value = true;
@@ -87,7 +87,8 @@ export function useEnfyraAuth(): UseEnfyraAuthReturn {
87
87
  }
88
88
 
89
89
  const currentUrl = window.location.href;
90
- window.location.href = `/api/auth/${provider}?redirect=${encodeURIComponent(currentUrl)}`;
90
+ const path = `${apiPrefix.replace(/\/+$/, "")}/auth/${provider}?redirect=${encodeURIComponent(currentUrl)}`;
91
+ window.location.href = path.startsWith("/") ? path : `/${path}`;
91
92
  };
92
93
 
93
94
  return {
@@ -1,4 +1,10 @@
1
- import { defineEventHandler, getQuery, sendRedirect, setResponseHeaders } from "h3";
1
+ import {
2
+ createError,
3
+ defineEventHandler,
4
+ getQuery,
5
+ sendRedirect,
6
+ setResponseHeaders,
7
+ } from "h3";
2
8
  import { useRuntimeConfig } from "#imports";
3
9
  import { proxyToAPI } from "../../utils/server/proxy";
4
10
 
@@ -9,7 +15,8 @@ const CORS_HEADERS = {
9
15
  'Access-Control-Max-Age': '86400',
10
16
  };
11
17
 
12
- const OAUTH_INIT_PATTERN = /\/auth\/(google|facebook|github)(?:\/|$|\?)/;
18
+ const OAUTH_PROVIDERS = ["google", "facebook", "github"];
19
+ const OAUTH_INIT_PATTERN = new RegExp(`/auth/(${OAUTH_PROVIDERS.join("|")})(?:/|$|\\?)`);
13
20
 
14
21
  export default defineEventHandler(async (event) => {
15
22
  setResponseHeaders(event, CORS_HEADERS);
@@ -18,21 +25,27 @@ export default defineEventHandler(async (event) => {
18
25
  return '';
19
26
  }
20
27
 
21
- // OAuth initiate: redirect to backend, do NOT proxy
22
- const pathname = event.path?.split('?')[0] || event.path || '';
23
- const oauthMatch = pathname.match(OAUTH_INIT_PATTERN);
24
- if (event.method === 'GET' && oauthMatch) {
28
+ const path = (event.path || event.node?.req?.url || "").split("?")[0];
29
+ const oauthMatch = path.match(OAUTH_INIT_PATTERN);
30
+ if (event.method === "GET" && oauthMatch) {
25
31
  const provider = oauthMatch[1];
26
32
  const query = getQuery(event);
27
33
  const redirectParam = query.redirect as string;
28
- if (redirectParam) {
29
- const config = useRuntimeConfig();
30
- const apiUrl = config.public?.enfyraSDK?.apiUrl;
31
- if (apiUrl) {
32
- const backendUrl = `${apiUrl.replace(/\/+$/, "")}/auth/${provider}?redirect=${encodeURIComponent(redirectParam)}`;
33
- return sendRedirect(event, backendUrl, 302);
34
- }
34
+ if (!redirectParam) {
35
+ throw createError({ statusCode: 400, message: "Redirect URL is required" });
35
36
  }
37
+ const config = useRuntimeConfig();
38
+ const apiUrl = config.public?.enfyraSDK?.apiUrl;
39
+ if (!apiUrl) {
40
+ throw createError({ statusCode: 500, message: "API URL not configured" });
41
+ }
42
+ const backendUrl = `${apiUrl.replace(/\/+$/, "")}/auth/${provider}?redirect=${encodeURIComponent(redirectParam)}`;
43
+ const response = await fetch(backendUrl, { redirect: "manual" });
44
+ const location = response.headers.get("location") || response.headers.get("Location");
45
+ if (location && response.status >= 300 && response.status < 400) {
46
+ return sendRedirect(event, location, 302);
47
+ }
48
+ throw createError({ statusCode: 502, message: "Failed to get OAuth URL from backend" });
36
49
  }
37
50
 
38
51
  return proxyToAPI(event);
@@ -16,12 +16,10 @@ export default defineEventHandler(async (event) => {
16
16
 
17
17
  const { accessToken, refreshToken, expTime, redirect } = query;
18
18
 
19
- // Validate required tokens
20
19
  if (!accessToken || !refreshToken || !expTime) {
21
20
  return sendRedirect(event, "/login?error=oauth_callback_failed");
22
21
  }
23
22
 
24
- // Set cookies (same as login.post.ts)
25
23
  const cookieOptions = {
26
24
  httpOnly: true,
27
25
  secure: true,
@@ -33,7 +31,6 @@ export default defineEventHandler(async (event) => {
33
31
  setCookie(event, REFRESH_TOKEN_KEY, refreshToken as string, cookieOptions);
34
32
  setCookie(event, EXP_TIME_KEY, expTime as string, cookieOptions);
35
33
 
36
- // Redirect to original page or home
37
34
  const redirectUrl = (redirect as string) || "/";
38
35
  return sendRedirect(event, redirectUrl);
39
36
  });
@@ -9,7 +9,6 @@ import { REFRESH_TOKEN_KEY } from "../../constants/auth";
9
9
  export default defineEventHandler(async (event) => {
10
10
  const url = event.node.req.url || "";
11
11
 
12
- // Skip token validation for auth endpoints
13
12
  if (
14
13
  url === "/api/login" ||
15
14
  url === "/api/logout" ||
@@ -11,27 +11,16 @@ export interface ApiError {
11
11
  }
12
12
 
13
13
  export interface BatchProgress {
14
- /** Current progress percentage (0-100) */
15
14
  progress: number;
16
- /** Number of completed operations */
17
15
  completed: number;
18
- /** Total number of operations */
19
16
  total: number;
20
- /** Number of failed operations */
21
17
  failed: number;
22
- /** Number of operations currently in progress */
23
18
  inProgress: number;
24
- /** Estimated time remaining in milliseconds */
25
19
  estimatedTimeRemaining?: number;
26
- /** Average time per operation in milliseconds */
27
20
  averageTime?: number;
28
- /** Current batch being processed */
29
21
  currentBatch: number;
30
- /** Total number of batches */
31
22
  totalBatches: number;
32
- /** Processing speed (operations per second) */
33
23
  operationsPerSecond?: number;
34
- /** Detailed results array for completed operations */
35
24
  results: Array<{
36
25
  index: number;
37
26
  status: 'completed' | 'failed';
@@ -50,51 +39,34 @@ interface BaseApiOptions<T> {
50
39
  onError?: (error: ApiError, context?: string) => void;
51
40
  disableBatch?: boolean;
52
41
  default?: () => T;
53
- /** Enable SSR with useFetch instead of $fetch */
54
42
  ssr?: boolean;
55
- /** Unique key for useFetch caching */
56
43
  key?: string;
57
- /** Whether to fetch on server (default: true) - Only applies when ssr: true */
58
44
  server?: boolean;
59
- /** Don't block navigation (default: false) - Only applies when ssr: true */
60
45
  lazy?: boolean;
61
- /** Execute immediately (default: true) - Only applies when ssr: true */
62
46
  immediate?: boolean;
63
- /** Transform the response data - Only applies when ssr: true */
64
47
  transform?: (data: any) => T;
65
- /** Pick specific fields from response - Only applies when ssr: true */
66
48
  pick?: string[];
67
- /** Watch reactive sources and refetch when they change - Only applies when ssr: true */
68
49
  watch?: any[];
69
- /** Deep watch (default: false) - Only applies when ssr: true */
70
50
  deep?: boolean;
71
- /** Custom cache data retrieval function - Only applies when ssr: true */
72
51
  getCachedData?: (key: string) => T | null;
73
- /** Enable refresh (default: true) - Only applies when ssr: true */
74
52
  refresh?: boolean;
75
- /** Auto refresh interval in milliseconds - Only applies when ssr: true */
76
53
  refreshInterval?: number;
77
- /** Deduplication key - Only applies when ssr: true */
78
54
  dedupe?: string;
79
- /** Cache mode for the fetch request - Only applies when ssr: true */
80
55
  cache?: RequestCache;
81
56
  }
82
57
 
83
58
  interface BatchApiOptions {
84
- /** Batch size for chunking large operations (default: no limit) - Only available for batch operations */
85
59
  batchSize?: number;
86
- /** Maximum concurrent requests (default: no limit) - Only available for batch operations */
87
60
  concurrent?: number;
88
- /** Real-time progress callback for batch operations - Only available for batch operations */
89
61
  onProgress?: (progress: BatchProgress) => void;
90
62
  }
91
63
 
92
64
  type ConditionalBatchOptions<T> = T extends { method?: 'patch' | 'delete' | 'PATCH' | 'DELETE' }
93
65
  ? BatchApiOptions
94
66
  : T extends { method?: 'post' | 'POST' }
95
- ? BatchApiOptions // POST supports file batch uploads
96
- : T extends { method?: undefined } // Default method is 'get', but could be overridden at execution
97
- ? Partial<BatchApiOptions> // Allow batch options but make them optional since method could change
67
+ ? BatchApiOptions
68
+ : T extends { method?: undefined }
69
+ ? Partial<BatchApiOptions>
98
70
  : {};
99
71
 
100
72
  export type ApiOptions<T> = BaseApiOptions<T> & ConditionalBatchOptions<BaseApiOptions<T>>;
@@ -135,21 +107,17 @@ interface BaseExecuteOptions {
135
107
 
136
108
  interface BatchExecuteOptions {
137
109
  ids?: (string | number)[];
138
- /** Array of FormData objects for batch upload */
139
110
  files?: FormData[];
140
- /** Override batch size for this specific execution */
141
111
  batchSize?: number;
142
- /** Override concurrent limit for this specific execution */
143
112
  concurrent?: number;
144
- /** Override progress callback for this specific execution */
145
113
  onProgress?: (progress: BatchProgress) => void;
146
114
  }
147
115
 
148
116
  type ConditionalExecuteOptions<T> = T extends { ids: any }
149
- ? BatchExecuteOptions // If ids provided, enable all batch options
117
+ ? BatchExecuteOptions
150
118
  : T extends { files: any }
151
- ? BatchExecuteOptions // If files provided, enable all batch options
152
- : BaseExecuteOptions & Partial<BatchExecuteOptions>; // Otherwise base options + optional batch options
119
+ ? BatchExecuteOptions
120
+ : BaseExecuteOptions & Partial<BatchExecuteOptions>;
153
121
 
154
122
  export type ExecuteOptions = BaseExecuteOptions & BatchExecuteOptions;
155
123
 
@@ -1,3 +0,0 @@
1
- declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<void>>;
2
- export default _default;
3
- //# sourceMappingURL=%5Bprovider%5D.get.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"[provider].get.d.ts","sourceRoot":"","sources":["../../../../../src/runtime/server/api/auth/[provider].get.ts"],"names":[],"mappings":";AAcA,wBAqBG"}
@@ -1,27 +0,0 @@
1
- import {
2
- createError,
3
- defineEventHandler,
4
- getQuery,
5
- getRouterParam,
6
- sendRedirect
7
- } from "h3";
8
- import { useRuntimeConfig } from "#imports";
9
- const OAUTH_PROVIDERS = ["google", "facebook", "github"];
10
- export default defineEventHandler((event) => {
11
- const provider = getRouterParam(event, "provider");
12
- if (!provider || !OAUTH_PROVIDERS.includes(provider)) {
13
- throw createError({ statusCode: 400, message: "Invalid OAuth provider" });
14
- }
15
- const query = getQuery(event);
16
- const redirectParam = query.redirect;
17
- if (!redirectParam) {
18
- throw createError({ statusCode: 400, message: "Redirect URL is required" });
19
- }
20
- const config = useRuntimeConfig();
21
- const apiUrl = config.public?.enfyraSDK?.apiUrl;
22
- if (!apiUrl) {
23
- throw createError({ statusCode: 500, message: "API URL not configured" });
24
- }
25
- const backendUrl = `${apiUrl.replace(/\/+$/, "")}/auth/${provider}?redirect=${encodeURIComponent(redirectParam)}`;
26
- return sendRedirect(event, backendUrl, 302);
27
- });
@@ -1,36 +0,0 @@
1
- /**
2
- * OAuth initiate - redirect browser to backend, do NOT proxy/fetch
3
- */
4
- import {
5
- createError,
6
- defineEventHandler,
7
- getQuery,
8
- getRouterParam,
9
- sendRedirect,
10
- } from "h3";
11
- import { useRuntimeConfig } from "#imports";
12
-
13
- const OAUTH_PROVIDERS = ["google", "facebook", "github"];
14
-
15
- export default defineEventHandler((event) => {
16
- const provider = getRouterParam(event, "provider");
17
- if (!provider || !OAUTH_PROVIDERS.includes(provider)) {
18
- throw createError({ statusCode: 400, message: "Invalid OAuth provider" });
19
- }
20
-
21
- const query = getQuery(event);
22
- const redirectParam = query.redirect as string;
23
- if (!redirectParam) {
24
- throw createError({ statusCode: 400, message: "Redirect URL is required" });
25
- }
26
-
27
- const config = useRuntimeConfig();
28
- const apiUrl = config.public?.enfyraSDK?.apiUrl;
29
- if (!apiUrl) {
30
- throw createError({ statusCode: 500, message: "API URL not configured" });
31
- }
32
-
33
- const backendUrl = `${apiUrl.replace(/\/+$/, "")}/auth/${provider}?redirect=${encodeURIComponent(redirectParam)}`;
34
-
35
- return sendRedirect(event, backendUrl, 302);
36
- });