@enfyra/sdk-nuxt 0.7.2 → 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.d.ts.map +1 -1
- package/dist/module.json +1 -1
- package/dist/runtime/composables/useEnfyraAuth.d.ts.map +1 -1
- package/dist/runtime/composables/useEnfyraAuth.js +3 -2
- package/dist/runtime/server/api/all.d.ts.map +1 -1
- package/dist/runtime/server/api/all.js +32 -1
- package/dist/runtime/server/api/auth/callback.get.d.ts.map +1 -1
- package/dist/runtime/server/middleware/auth.d.ts.map +1 -1
- package/dist/types/index.d.ts +0 -32
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/module.ts +0 -1
- package/src/runtime/composables/useEnfyraAuth.ts +3 -2
- package/src/runtime/server/api/all.ts +34 -1
- package/src/runtime/server/api/auth/callback.get.ts +0 -3
- package/src/runtime/server/middleware/auth.ts +0 -1
- package/src/types/index.ts +6 -38
package/dist/module.d.ts.map
CHANGED
|
@@ -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,
|
|
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
|
@@ -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,
|
|
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
|
-
|
|
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":";
|
|
1
|
+
{"version":3,"file":"all.d.ts","sourceRoot":"","sources":["../../../../src/runtime/server/api/all.ts"],"names":[],"mappings":";AAoBA,wBA+BG"}
|
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
createError,
|
|
3
|
+
defineEventHandler,
|
|
4
|
+
getQuery,
|
|
5
|
+
sendRedirect,
|
|
6
|
+
setResponseHeaders
|
|
7
|
+
} from "h3";
|
|
8
|
+
import { useRuntimeConfig } from "#imports";
|
|
2
9
|
import { proxyToAPI } from "../../utils/server/proxy.js";
|
|
3
10
|
const CORS_HEADERS = {
|
|
4
11
|
"Access-Control-Allow-Origin": "*",
|
|
@@ -6,10 +13,34 @@ const CORS_HEADERS = {
|
|
|
6
13
|
"Access-Control-Allow-Headers": "Content-Type, Authorization",
|
|
7
14
|
"Access-Control-Max-Age": "86400"
|
|
8
15
|
};
|
|
16
|
+
const OAUTH_PROVIDERS = ["google", "facebook", "github"];
|
|
17
|
+
const OAUTH_INIT_PATTERN = new RegExp(`/auth/(${OAUTH_PROVIDERS.join("|")})(?:/|$|\\?)`);
|
|
9
18
|
export default defineEventHandler(async (event) => {
|
|
10
19
|
setResponseHeaders(event, CORS_HEADERS);
|
|
11
20
|
if (event.method === "OPTIONS") {
|
|
12
21
|
return "";
|
|
13
22
|
}
|
|
23
|
+
const path = (event.path || event.node?.req?.url || "").split("?")[0];
|
|
24
|
+
const oauthMatch = path.match(OAUTH_INIT_PATTERN);
|
|
25
|
+
if (event.method === "GET" && oauthMatch) {
|
|
26
|
+
const provider = oauthMatch[1];
|
|
27
|
+
const query = getQuery(event);
|
|
28
|
+
const redirectParam = query.redirect;
|
|
29
|
+
if (!redirectParam) {
|
|
30
|
+
throw createError({ statusCode: 400, message: "Redirect URL is required" });
|
|
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" });
|
|
44
|
+
}
|
|
14
45
|
return proxyToAPI(event);
|
|
15
46
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"callback.get.d.ts","sourceRoot":"","sources":["../../../../../src/runtime/server/api/auth/callback.get.ts"],"names":[],"mappings":";AAaA,
|
|
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,
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../../../src/runtime/server/middleware/auth.ts"],"names":[],"mappings":";AAQA,wBAsCG"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -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,
|
|
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,QA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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
package/src/module.ts
CHANGED
|
@@ -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
|
-
|
|
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,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
createError,
|
|
3
|
+
defineEventHandler,
|
|
4
|
+
getQuery,
|
|
5
|
+
sendRedirect,
|
|
6
|
+
setResponseHeaders,
|
|
7
|
+
} from "h3";
|
|
8
|
+
import { useRuntimeConfig } from "#imports";
|
|
2
9
|
import { proxyToAPI } from "../../utils/server/proxy";
|
|
3
10
|
|
|
4
11
|
const CORS_HEADERS = {
|
|
@@ -8,6 +15,9 @@ const CORS_HEADERS = {
|
|
|
8
15
|
'Access-Control-Max-Age': '86400',
|
|
9
16
|
};
|
|
10
17
|
|
|
18
|
+
const OAUTH_PROVIDERS = ["google", "facebook", "github"];
|
|
19
|
+
const OAUTH_INIT_PATTERN = new RegExp(`/auth/(${OAUTH_PROVIDERS.join("|")})(?:/|$|\\?)`);
|
|
20
|
+
|
|
11
21
|
export default defineEventHandler(async (event) => {
|
|
12
22
|
setResponseHeaders(event, CORS_HEADERS);
|
|
13
23
|
|
|
@@ -15,5 +25,28 @@ export default defineEventHandler(async (event) => {
|
|
|
15
25
|
return '';
|
|
16
26
|
}
|
|
17
27
|
|
|
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) {
|
|
31
|
+
const provider = oauthMatch[1];
|
|
32
|
+
const query = getQuery(event);
|
|
33
|
+
const redirectParam = query.redirect as string;
|
|
34
|
+
if (!redirectParam) {
|
|
35
|
+
throw createError({ statusCode: 400, message: "Redirect URL is required" });
|
|
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" });
|
|
49
|
+
}
|
|
50
|
+
|
|
18
51
|
return proxyToAPI(event);
|
|
19
52
|
});
|
|
@@ -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" ||
|
package/src/types/index.ts
CHANGED
|
@@ -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
|
|
96
|
-
: T extends { method?: undefined }
|
|
97
|
-
? Partial<BatchApiOptions>
|
|
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
|
|
117
|
+
? BatchExecuteOptions
|
|
150
118
|
: T extends { files: any }
|
|
151
|
-
? BatchExecuteOptions
|
|
152
|
-
: BaseExecuteOptions & Partial<BatchExecuteOptions>;
|
|
119
|
+
? BatchExecuteOptions
|
|
120
|
+
: BaseExecuteOptions & Partial<BatchExecuteOptions>;
|
|
153
121
|
|
|
154
122
|
export type ExecuteOptions = BaseExecuteOptions & BatchExecuteOptions;
|
|
155
123
|
|