@enfyra/sdk-nuxt 0.3.15 → 0.3.17

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.
Files changed (54) hide show
  1. package/index.ts +3 -0
  2. package/module.d.ts +14 -0
  3. package/{src/module.ts → module.ts} +21 -9
  4. package/package.json +32 -21
  5. package/src/composables/useEnfyraAuth.ts +1 -1
  6. package/src/types/nuxt-imports.d.ts +5 -0
  7. package/dist/auth.d.ts +0 -43
  8. package/dist/auth.d.ts.map +0 -1
  9. package/dist/auth.js +0 -1
  10. package/dist/composables/useEnfyraApi.d.ts +0 -12
  11. package/dist/composables/useEnfyraApi.mjs +0 -345
  12. package/dist/composables/useEnfyraAuth.d.ts +0 -9
  13. package/dist/composables/useEnfyraAuth.mjs +0 -81
  14. package/dist/composables.d.ts +0 -21
  15. package/dist/constants/auth.d.ts +0 -0
  16. package/dist/constants/auth.mjs +0 -3
  17. package/dist/constants/config.d.ts +0 -5
  18. package/dist/constants/config.mjs +0 -1
  19. package/dist/index.d.ts +0 -141
  20. package/dist/index.d.ts.map +0 -1
  21. package/dist/index.js +0 -1
  22. package/dist/module.cjs +0 -77
  23. package/dist/module.d.cts +0 -11
  24. package/dist/module.d.mts +0 -11
  25. package/dist/module.d.ts +0 -11
  26. package/dist/module.json +0 -9
  27. package/dist/module.mjs +0 -74
  28. package/dist/runtime/plugin/config-error.client.d.ts +0 -0
  29. package/dist/runtime/plugin/config-error.client.js +0 -107
  30. package/dist/runtime/plugin/config-error.client.mjs +0 -107
  31. package/dist/runtime/server/api/all.d.ts +0 -0
  32. package/dist/runtime/server/api/all.js +0 -5
  33. package/dist/runtime/server/api/all.mjs +0 -5
  34. package/dist/runtime/server/api/login.post.d.ts +0 -0
  35. package/dist/runtime/server/api/login.post.js +0 -62
  36. package/dist/runtime/server/api/login.post.mjs +0 -62
  37. package/dist/runtime/server/api/logout.post.d.ts +0 -0
  38. package/dist/runtime/server/api/logout.post.js +0 -35
  39. package/dist/runtime/server/api/logout.post.mjs +0 -35
  40. package/dist/runtime/server/middleware/auth.d.ts +0 -0
  41. package/dist/runtime/server/middleware/auth.js +0 -36
  42. package/dist/runtime/server/middleware/auth.mjs +0 -36
  43. package/dist/types.d.mts +0 -7
  44. package/dist/types.d.ts +0 -7
  45. package/dist/utils/config.d.ts +0 -0
  46. package/dist/utils/config.mjs +0 -16
  47. package/dist/utils/http.d.ts +0 -0
  48. package/dist/utils/http.mjs +0 -61
  49. package/dist/utils/server/proxy.d.ts +0 -0
  50. package/dist/utils/server/proxy.mjs +0 -14
  51. package/dist/utils/server/refreshToken.d.ts +0 -0
  52. package/dist/utils/server/refreshToken.mjs +0 -69
  53. package/dist/utils/url.d.ts +0 -0
  54. package/dist/utils/url.mjs +0 -56
package/index.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from './module'
2
+ export * from './src/types'
3
+
package/module.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ import type { ModuleOptions } from './module'
2
+
3
+ declare module '@nuxt/schema' {
4
+ interface NuxtConfig {
5
+ enfyraSDK?: ModuleOptions
6
+ }
7
+ interface NuxtOptions {
8
+ enfyraSDK?: ModuleOptions
9
+ }
10
+ }
11
+
12
+ export type { ModuleOptions } from './module'
13
+ export type * from './src/types'
14
+
@@ -5,9 +5,14 @@ import {
5
5
  addImportsDir,
6
6
  addPlugin,
7
7
  } from "@nuxt/kit";
8
- import { ENFYRA_API_PREFIX } from "./constants/config";
8
+ import { ENFYRA_API_PREFIX } from "./src/constants/config";
9
9
 
10
- export default defineNuxtModule({
10
+ export interface ModuleOptions {
11
+ apiUrl: string;
12
+ apiPrefix?: string;
13
+ }
14
+
15
+ export default defineNuxtModule<ModuleOptions>({
11
16
  meta: {
12
17
  name: "@enfyra/sdk-nuxt",
13
18
  configKey: "enfyraSDK",
@@ -60,39 +65,46 @@ export default defineNuxtModule({
60
65
 
61
66
  if (!normalizedOptions.apiUrl) {
62
67
  addPlugin({
63
- src: resolve("./runtime/plugin/config-error.client"),
68
+ src: resolve("./src/runtime/plugin/config-error.client"),
64
69
  mode: 'client'
65
70
  });
66
71
  }
67
72
 
68
- addImportsDir(resolve("./composables"));
73
+ addImportsDir(resolve("./src/composables"));
74
+
75
+ nuxt.hook('prepare:types', ({ declarations, references }: any) => {
76
+ references.push({
77
+ path: resolve('./src/types/nuxt-imports.d.ts'),
78
+ })
79
+ })
69
80
 
70
81
  addServerHandler({
71
- handler: resolve("./runtime/server/middleware/auth"),
82
+ handler: '@enfyra/sdk-nuxt/src/runtime/server/middleware/auth',
72
83
  middleware: true,
73
84
  });
74
85
 
75
86
  addServerHandler({
76
87
  route: `${apiPrefix}/login`,
77
- handler: resolve("./runtime/server/api/login.post"),
88
+ handler: '@enfyra/sdk-nuxt/src/runtime/server/api/login.post',
78
89
  method: "post",
79
90
  });
80
91
 
81
92
  addServerHandler({
82
93
  route: `${apiPrefix}/logout`,
83
- handler: resolve("./runtime/server/api/logout.post"),
94
+ handler: '@enfyra/sdk-nuxt/src/runtime/server/api/logout.post',
84
95
  method: "post",
85
96
  });
86
97
 
87
98
 
88
99
  addServerHandler({
89
100
  route: "/assets/**",
90
- handler: resolve("./runtime/server/api/all"),
101
+ handler: '@enfyra/sdk-nuxt/src/runtime/server/api/all',
91
102
  });
92
103
 
93
104
  addServerHandler({
94
105
  route: `${apiPrefix}/**`,
95
- handler: resolve("./runtime/server/api/all"),
106
+ handler: '@enfyra/sdk-nuxt/src/runtime/server/api/all',
96
107
  });
97
108
  },
98
109
  });
110
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@enfyra/sdk-nuxt",
3
- "version": "0.3.15",
3
+ "version": "0.3.17",
4
4
  "description": "Nuxt SDK for Enfyra CMS",
5
5
  "repository": {
6
6
  "type": "git",
@@ -10,18 +10,39 @@
10
10
  "url": "https://github.com/dothinh115/enfyra-sdk-nuxt/issues"
11
11
  },
12
12
  "homepage": "https://github.com/dothinh115/enfyra-sdk-nuxt#readme",
13
- "main": "./dist/module.mjs",
14
- "types": "./dist/index.d.ts",
13
+ "main": "./module.ts",
14
+ "types": "./module.d.ts",
15
15
  "exports": {
16
16
  ".": {
17
- "import": "./dist/module.mjs",
18
- "require": "./dist/module.cjs",
19
- "types": "./dist/index.d.ts"
20
- }
17
+ "types": "./module.d.ts",
18
+ "import": "./module.ts"
19
+ },
20
+ "./src/composables/useEnfyraApi": {
21
+ "types": "./src/composables/useEnfyraApi.ts",
22
+ "import": "./src/composables/useEnfyraApi.ts"
23
+ },
24
+ "./src/composables/useEnfyraAuth": {
25
+ "types": "./src/composables/useEnfyraAuth.ts",
26
+ "import": "./src/composables/useEnfyraAuth.ts"
27
+ },
28
+ "./src/types": {
29
+ "types": "./src/types/index.ts",
30
+ "import": "./src/types/index.ts"
31
+ },
32
+ "./src/runtime/server/api/all": "./src/runtime/server/api/all.ts",
33
+ "./src/runtime/server/api/all.ts": "./src/runtime/server/api/all.ts",
34
+ "./src/runtime/server/api/login.post": "./src/runtime/server/api/login.post.ts",
35
+ "./src/runtime/server/api/login.post.ts": "./src/runtime/server/api/login.post.ts",
36
+ "./src/runtime/server/api/logout.post": "./src/runtime/server/api/logout.post.ts",
37
+ "./src/runtime/server/api/logout.post.ts": "./src/runtime/server/api/logout.post.ts",
38
+ "./src/runtime/server/middleware/auth": "./src/runtime/server/middleware/auth.ts",
39
+ "./src/runtime/server/middleware/auth.ts": "./src/runtime/server/middleware/auth.ts"
21
40
  },
22
41
  "files": [
23
- "dist/",
24
- "src/"
42
+ "module.ts",
43
+ "module.d.ts",
44
+ "index.ts",
45
+ "src/**/*"
25
46
  ],
26
47
  "keywords": [
27
48
  "nuxt",
@@ -35,12 +56,7 @@
35
56
  "access": "public"
36
57
  },
37
58
  "scripts": {
38
- "dev": "nuxi dev playground",
39
- "build": "nuxt-module-build build && npx tsc -p tsconfig.build.json && node scripts/copy-composables-types.js",
40
- "prepack": "nuxt-module-build build && npx tsc -p tsconfig.build.json && node scripts/copy-composables-types.js",
41
- "test": "vitest",
42
- "test:ui": "vitest --ui",
43
- "test:run": "vitest run"
59
+ "build": "npx tsc --noEmit --skipLibCheck"
44
60
  },
45
61
  "peerDependencies": {
46
62
  "@nuxt/kit": "^3.18.1",
@@ -51,13 +67,8 @@
51
67
  "ofetch": "^1.3.3"
52
68
  },
53
69
  "devDependencies": {
54
- "@nuxt/module-builder": "^0.8.4",
55
70
  "@types/node": "^24.10.1",
56
- "@vitest/ui": "^3.2.4",
57
71
  "nuxt": "^3.18.1",
58
- "typescript": "^5.0.0",
59
- "vite": "^6.0.7",
60
- "vite-plugin-dts": "^4.3.0",
61
- "vitest": "^3.2.4"
72
+ "typescript": "^5.0.0"
62
73
  }
63
74
  }
@@ -1,5 +1,5 @@
1
1
  import { ref, computed } from "vue";
2
- import type { LoginPayload, User, UseEnfyraAuthReturn } from "../types/auth";
2
+ import type { LoginPayload, User } from "../types/auth";
3
3
  import { useEnfyraApi } from "./useEnfyraApi";
4
4
 
5
5
  const me = ref<User | null>(null);
@@ -3,6 +3,11 @@
3
3
  * These are provided at runtime by Nuxt but need declarations for TypeScript
4
4
  */
5
5
 
6
+ declare global {
7
+ const useEnfyraApi: typeof import('../composables/useEnfyraApi').useEnfyraApi
8
+ const useEnfyraAuth: typeof import('../composables/useEnfyraAuth').useEnfyraAuth
9
+ }
10
+
6
11
  declare module '#imports' {
7
12
  export const useRuntimeConfig: () => {
8
13
  public: {
package/dist/auth.d.ts DELETED
@@ -1,43 +0,0 @@
1
- import type { Ref } from 'vue';
2
- export interface User {
3
- id: string;
4
- email: string;
5
- isRootAdmin: boolean;
6
- isSystem: boolean;
7
- role?: {
8
- id: string;
9
- name: string;
10
- routePermissions: RoutePermission[];
11
- };
12
- allowedRoutePermissions?: RoutePermission[];
13
- }
14
- export interface RoutePermission {
15
- id: string;
16
- isEnabled: boolean;
17
- allowedUsers?: {
18
- id: string;
19
- }[];
20
- methods: {
21
- id: string;
22
- method: string;
23
- }[];
24
- route: {
25
- id: string;
26
- path: string;
27
- };
28
- }
29
- export interface LoginPayload {
30
- email: string;
31
- password: string;
32
- remember?: boolean;
33
- }
34
- export interface UseEnfyraAuthReturn {
35
- me: Ref<User | null>;
36
- login: (payload: LoginPayload) => Promise<any>;
37
- logout: () => Promise<void>;
38
- fetchUser: (options?: {
39
- fields?: string[];
40
- }) => Promise<void>;
41
- isLoggedIn: Ref<boolean>;
42
- }
43
- //# sourceMappingURL=auth.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/types/auth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,KAAK,CAAA;AAE9B,MAAM,WAAW,IAAI;IACnB,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,EAAE,MAAM,CAAA;IACb,WAAW,EAAE,OAAO,CAAA;IACpB,QAAQ,EAAE,OAAO,CAAA;IACjB,IAAI,CAAC,EAAE;QACL,EAAE,EAAE,MAAM,CAAA;QACV,IAAI,EAAE,MAAM,CAAA;QACZ,gBAAgB,EAAE,eAAe,EAAE,CAAA;KACpC,CAAA;IACD,uBAAuB,CAAC,EAAE,eAAe,EAAE,CAAA;CAC5C;AAED,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAA;IACV,SAAS,EAAE,OAAO,CAAA;IAClB,YAAY,CAAC,EAAE;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,EAAE,CAAA;IAC/B,OAAO,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,EAAE,CAAA;IACzC,KAAK,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAA;CACpC;AAED,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB;AAED,MAAM,WAAW,mBAAmB;IAClC,EAAE,EAAE,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC,CAAA;IACpB,KAAK,EAAE,CAAC,OAAO,EAAE,YAAY,KAAK,OAAO,CAAC,GAAG,CAAC,CAAA;IAC9C,MAAM,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;IAC3B,SAAS,EAAE,CAAC,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;KAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IAC7D,UAAU,EAAE,GAAG,CAAC,OAAO,CAAC,CAAA;CACzB"}
package/dist/auth.js DELETED
@@ -1 +0,0 @@
1
- export {};
@@ -1,12 +0,0 @@
1
- import type { ApiOptions, UseEnfyraApiSSRReturn, UseEnfyraApiClientReturn } from "../types";
2
-
3
- // Function overloads for proper TypeScript support
4
- export declare function useEnfyraApi<T = any>(
5
- path: (() => string) | string,
6
- opts: ApiOptions<T> & { ssr: true }
7
- ): UseEnfyraApiSSRReturn<T>;
8
-
9
- export declare function useEnfyraApi<T = any>(
10
- path: (() => string) | string,
11
- opts?: ApiOptions<T> & { ssr?: false | undefined }
12
- ): UseEnfyraApiClientReturn<T>;
@@ -1,345 +0,0 @@
1
- import { ref, unref, toRaw } from "vue";
2
- import { $fetch } from "../utils/http";
3
- import { getAppUrl, normalizeUrl } from "../utils/url";
4
- import { ENFYRA_API_PREFIX } from "../constants/config";
5
- import { useRuntimeConfig, useFetch, useRequestHeaders, useNuxtApp } from "#imports";
6
- function handleError(error, context, customHandler) {
7
- const apiError = {
8
- message: error?.message || error?.data?.message || "Request failed",
9
- status: error?.status || error?.response?.status,
10
- data: error?.data || error?.response?.data,
11
- response: error?.response || error
12
- };
13
- if (customHandler) {
14
- customHandler(apiError, context);
15
- } else {
16
- console.error(`[Enfyra API Error]`, { error: apiError, context });
17
- }
18
- return apiError;
19
- }
20
- export function useEnfyraApi(path, opts = {}) {
21
- const { method = "get", body, query, errorContext, onError, ssr, key } = opts;
22
- const batchOptions = opts;
23
- const { batchSize, concurrent, onProgress } = batchOptions;
24
- if (ssr) {
25
- const config = useRuntimeConfig().public.enfyraSDK;
26
- const basePath = (typeof path === "function" ? path() : path).replace(/^\/?api\/?/, "").replace(/^\/+/, "");
27
- const appUrl = getAppUrl();
28
- const finalUrl = normalizeUrl(
29
- appUrl,
30
- config?.apiPrefix || ENFYRA_API_PREFIX,
31
- basePath
32
- );
33
- const clientHeaders = process.client ? {} : useRequestHeaders([
34
- "authorization",
35
- "cookie",
36
- "user-agent",
37
- "accept",
38
- "accept-language",
39
- "referer"
40
- ]);
41
- const serverHeaders = { ...clientHeaders };
42
- delete serverHeaders.connection;
43
- delete serverHeaders["keep-alive"];
44
- delete serverHeaders.host;
45
- delete serverHeaders["content-length"];
46
- const nuxtApp = useNuxtApp();
47
- const fetchOptions = {
48
- method,
49
- body,
50
- query,
51
- headers: {
52
- ...serverHeaders,
53
- ...opts.headers
54
- }
55
- };
56
- if (key !== void 0) {
57
- fetchOptions.key = key;
58
- }
59
- if (opts.default !== void 0) {
60
- fetchOptions.default = opts.default;
61
- }
62
- if (opts.server !== void 0) {
63
- fetchOptions.server = opts.server;
64
- }
65
- if (opts.lazy !== void 0) {
66
- fetchOptions.lazy = opts.lazy;
67
- }
68
- if (opts.immediate !== void 0) {
69
- fetchOptions.immediate = opts.immediate;
70
- }
71
- if (opts.transform !== void 0) {
72
- fetchOptions.transform = opts.transform;
73
- }
74
- if (opts.pick !== void 0) {
75
- fetchOptions.pick = opts.pick;
76
- }
77
- if (opts.watch !== void 0) {
78
- fetchOptions.watch = opts.watch;
79
- }
80
- if (opts.deep !== void 0) {
81
- fetchOptions.deep = opts.deep;
82
- }
83
- if (opts.getCachedData !== void 0) {
84
- fetchOptions.getCachedData = opts.getCachedData;
85
- } else {
86
- fetchOptions.getCachedData = (cacheKey) => {
87
- return nuxtApp.payload.data[cacheKey] || nuxtApp.static.data[cacheKey];
88
- };
89
- }
90
- if (opts.refresh !== void 0) {
91
- fetchOptions.refresh = opts.refresh;
92
- }
93
- if (opts.refreshInterval !== void 0) {
94
- fetchOptions.refreshInterval = opts.refreshInterval;
95
- }
96
- if (opts.dedupe !== void 0) {
97
- fetchOptions.dedupe = opts.dedupe;
98
- }
99
- const result = useFetch(finalUrl, fetchOptions);
100
- return {
101
- ...result,
102
- loading: result.pending,
103
- pending: result.pending
104
- // Keep for backward compatibility
105
- };
106
- }
107
- const data = ref(null);
108
- const error = ref(null);
109
- const pending = ref(false);
110
- const execute = async (executeOpts) => {
111
- pending.value = true;
112
- error.value = null;
113
- try {
114
- const config = useRuntimeConfig().public.enfyraSDK;
115
- const apiUrl = getAppUrl();
116
- const apiPrefix = config?.apiPrefix;
117
- const basePath = (typeof path === "function" ? path() : path).replace(/^\/?api\/?/, "").replace(/^\/+/, "");
118
- const finalBody = executeOpts?.body || unref(body);
119
- const finalQuery = executeOpts?.query || unref(query);
120
- const isBatchOperation = !opts.disableBatch && (executeOpts?.ids && executeOpts.ids.length > 0 && (method.toLowerCase() === "patch" || method.toLowerCase() === "delete") || method.toLowerCase() === "post" && executeOpts?.files && Array.isArray(executeOpts.files) && executeOpts.files.length > 0);
121
- const effectiveBatchSize = isBatchOperation ? executeOpts?.batchSize ?? batchSize : void 0;
122
- const effectiveConcurrent = isBatchOperation ? executeOpts?.concurrent ?? concurrent : void 0;
123
- const effectiveOnProgress = isBatchOperation ? executeOpts?.onProgress ?? onProgress : void 0;
124
- const buildPath = (...segments) => {
125
- return segments.filter(Boolean).join("/");
126
- };
127
- const fullBaseURL = normalizeUrl(apiUrl, apiPrefix || ENFYRA_API_PREFIX);
128
- async function processBatch(items, processor) {
129
- const results = [];
130
- const progressResults = [];
131
- const startTime = Date.now();
132
- let completed = 0;
133
- let failed = 0;
134
- const chunks = effectiveBatchSize ? Array.from(
135
- { length: Math.ceil(items.length / effectiveBatchSize) },
136
- (_, i) => items.slice(
137
- i * effectiveBatchSize,
138
- i * effectiveBatchSize + effectiveBatchSize
139
- )
140
- ) : [items];
141
- const totalBatches = chunks.length;
142
- let currentBatch = 0;
143
- const updateProgress = (inProgress = 0) => {
144
- if (effectiveOnProgress) {
145
- const elapsed = Date.now() - startTime;
146
- const progress = items.length > 0 ? Math.round(completed / items.length * 100) : 0;
147
- const averageTime = completed > 0 ? elapsed / completed : void 0;
148
- const operationsPerSecond = completed > 0 ? completed / elapsed * 1e3 : void 0;
149
- const estimatedTimeRemaining = averageTime && items.length > completed ? Math.round(averageTime * (items.length - completed)) : void 0;
150
- const progressData = {
151
- progress,
152
- completed,
153
- total: items.length,
154
- failed,
155
- inProgress,
156
- estimatedTimeRemaining,
157
- averageTime,
158
- currentBatch: currentBatch + 1,
159
- totalBatches,
160
- operationsPerSecond,
161
- results: [...progressResults]
162
- };
163
- effectiveOnProgress(progressData);
164
- }
165
- };
166
- updateProgress(0);
167
- if (!effectiveBatchSize && !effectiveConcurrent) {
168
- updateProgress(items.length);
169
- const promises = items.map(async (item, index) => {
170
- const itemStartTime = Date.now();
171
- try {
172
- const result = await processor(item, index);
173
- const duration = Date.now() - itemStartTime;
174
- completed++;
175
- progressResults.push({
176
- index,
177
- status: "completed",
178
- result,
179
- duration
180
- });
181
- updateProgress(items.length - completed);
182
- return result;
183
- } catch (error2) {
184
- const duration = Date.now() - itemStartTime;
185
- failed++;
186
- completed++;
187
- progressResults.push({
188
- index,
189
- status: "failed",
190
- error: error2,
191
- duration
192
- });
193
- updateProgress(items.length - completed);
194
- throw error2;
195
- }
196
- });
197
- const results2 = await Promise.all(promises);
198
- updateProgress(0);
199
- return results2;
200
- }
201
- for (let chunkIndex = 0; chunkIndex < chunks.length; chunkIndex++) {
202
- currentBatch = chunkIndex;
203
- const chunk = chunks[chunkIndex];
204
- if (effectiveConcurrent && chunk.length > effectiveConcurrent) {
205
- for (let i = 0; i < chunk.length; i += effectiveConcurrent) {
206
- const batch = chunk.slice(i, i + effectiveConcurrent);
207
- const baseIndex = chunkIndex * (effectiveBatchSize || items.length) + i;
208
- updateProgress(batch.length);
209
- const batchPromises = batch.map(async (item, batchItemIndex) => {
210
- const globalIndex = baseIndex + batchItemIndex;
211
- const itemStartTime = Date.now();
212
- try {
213
- const result = await processor(item, globalIndex);
214
- const duration = Date.now() - itemStartTime;
215
- completed++;
216
- progressResults.push({
217
- index: globalIndex,
218
- status: "completed",
219
- result,
220
- duration
221
- });
222
- updateProgress(
223
- Math.max(0, batch.length - (batchItemIndex + 1))
224
- );
225
- return result;
226
- } catch (error2) {
227
- const duration = Date.now() - itemStartTime;
228
- failed++;
229
- completed++;
230
- progressResults.push({
231
- index: globalIndex,
232
- status: "failed",
233
- error: error2,
234
- duration
235
- });
236
- updateProgress(
237
- Math.max(0, batch.length - (batchItemIndex + 1))
238
- );
239
- throw error2;
240
- }
241
- });
242
- const batchResults = await Promise.all(batchPromises);
243
- results.push(...batchResults);
244
- }
245
- } else {
246
- const baseIndex = chunkIndex * (effectiveBatchSize || items.length);
247
- updateProgress(chunk.length);
248
- const chunkPromises = chunk.map(async (item, chunkItemIndex) => {
249
- const globalIndex = baseIndex + chunkItemIndex;
250
- const itemStartTime = Date.now();
251
- try {
252
- const result = await processor(item, globalIndex);
253
- const duration = Date.now() - itemStartTime;
254
- completed++;
255
- progressResults.push({
256
- index: globalIndex,
257
- status: "completed",
258
- result,
259
- duration
260
- });
261
- updateProgress(
262
- Math.max(0, chunk.length - (chunkItemIndex + 1))
263
- );
264
- return result;
265
- } catch (error2) {
266
- const duration = Date.now() - itemStartTime;
267
- failed++;
268
- completed++;
269
- progressResults.push({
270
- index: globalIndex,
271
- status: "failed",
272
- error: error2,
273
- duration
274
- });
275
- updateProgress(
276
- Math.max(0, chunk.length - (chunkItemIndex + 1))
277
- );
278
- throw error2;
279
- }
280
- });
281
- const chunkResults = await Promise.all(chunkPromises);
282
- results.push(...chunkResults);
283
- }
284
- }
285
- updateProgress(0);
286
- return results;
287
- }
288
- if (isBatchOperation && executeOpts?.ids && executeOpts.ids.length > 0) {
289
- const responses = await processBatch(
290
- executeOpts.ids,
291
- async (id) => {
292
- const finalPath2 = buildPath(basePath, id);
293
- return $fetch(finalPath2, {
294
- baseURL: fullBaseURL,
295
- method,
296
- body: finalBody ? toRaw(finalBody) : void 0,
297
- headers: opts.headers,
298
- query: finalQuery
299
- });
300
- }
301
- );
302
- data.value = responses;
303
- return responses;
304
- }
305
- if (isBatchOperation && executeOpts?.files && Array.isArray(executeOpts.files) && executeOpts.files.length > 0) {
306
- const responses = await processBatch(
307
- executeOpts.files,
308
- async (fileObj) => {
309
- return $fetch(basePath, {
310
- baseURL: fullBaseURL,
311
- method,
312
- body: fileObj,
313
- headers: opts.headers,
314
- query: finalQuery
315
- });
316
- }
317
- );
318
- data.value = responses;
319
- return responses;
320
- }
321
- const finalPath = executeOpts?.id ? buildPath(basePath, executeOpts.id) : basePath;
322
- const response = await $fetch(finalPath, {
323
- baseURL: fullBaseURL,
324
- method,
325
- body: finalBody ? toRaw(finalBody) : void 0,
326
- headers: opts.headers,
327
- query: finalQuery
328
- });
329
- data.value = response;
330
- return response;
331
- } catch (err) {
332
- const apiError = handleError(err, errorContext, onError);
333
- error.value = apiError;
334
- return null;
335
- } finally {
336
- pending.value = false;
337
- }
338
- };
339
- return {
340
- data,
341
- error,
342
- pending,
343
- execute
344
- };
345
- }
@@ -1,9 +0,0 @@
1
- import type { LoginPayload, User } from "../types/auth";
2
- import type { Ref, ComputedRef } from 'vue';
3
- export declare function useEnfyraAuth(): {
4
- me: Ref<User | null>;
5
- login: (payload: LoginPayload) => Promise<any>;
6
- logout: () => Promise<void>;
7
- fetchUser: (options?: { fields?: string[] }) => Promise<void>;
8
- isLoggedIn: ComputedRef<boolean>;
9
- };