@enfyra/sdk-nuxt 0.3.16 → 0.3.18
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/index.ts +1 -1
- package/module.d.ts +2 -2
- package/{src/module.ts → module.ts} +10 -9
- package/package.json +24 -24
- package/src/composables/useEnfyraAuth.ts +1 -1
- package/src/utils/url.ts +4 -11
- package/dist/composables/useEnfyraApi.d.ts +0 -8
- package/dist/composables/useEnfyraApi.d.ts.map +0 -1
- package/dist/composables/useEnfyraApi.js +0 -363
- package/dist/composables/useEnfyraApi.mjs +0 -345
- package/dist/composables/useEnfyraAuth.d.ts +0 -89
- package/dist/composables/useEnfyraAuth.d.ts.map +0 -1
- package/dist/composables/useEnfyraAuth.js +0 -77
- package/dist/composables/useEnfyraAuth.mjs +0 -81
- package/dist/constants/auth.d.ts +0 -0
- package/dist/constants/auth.mjs +0 -3
- package/dist/constants/config.d.ts +0 -2
- package/dist/constants/config.d.ts.map +0 -1
- package/dist/constants/config.js +0 -1
- package/dist/constants/config.mjs +0 -1
- package/dist/module.cjs +0 -82
- package/dist/module.d.cts +0 -10
- package/dist/module.d.mts +0 -10
- package/dist/module.json +0 -9
- package/dist/module.mjs +0 -79
- package/dist/types/auth.d.ts +0 -43
- package/dist/types/auth.d.ts.map +0 -1
- package/dist/types/auth.js +0 -1
- package/dist/types/index.d.ts +0 -141
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/index.js +0 -1
- package/dist/types.d.mts +0 -7
- package/dist/types.d.ts +0 -7
- package/dist/utils/config.d.ts +0 -0
- package/dist/utils/config.mjs +0 -16
- package/dist/utils/http.d.ts +0 -8
- package/dist/utils/http.d.ts.map +0 -1
- package/dist/utils/http.js +0 -57
- package/dist/utils/http.mjs +0 -61
- package/dist/utils/server/proxy.d.ts +0 -0
- package/dist/utils/server/proxy.mjs +0 -14
- package/dist/utils/server/refreshToken.d.ts +0 -0
- package/dist/utils/server/refreshToken.mjs +0 -69
- package/dist/utils/url.d.ts +0 -12
- package/dist/utils/url.d.ts.map +0 -1
- package/dist/utils/url.js +0 -77
- package/dist/utils/url.mjs +0 -56
|
@@ -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,89 +0,0 @@
|
|
|
1
|
-
import type { LoginPayload, User } from "../types/auth";
|
|
2
|
-
export declare function useEnfyraAuth(): {
|
|
3
|
-
readonly me: import("vue").Ref<{
|
|
4
|
-
id: string;
|
|
5
|
-
email: string;
|
|
6
|
-
isRootAdmin: boolean;
|
|
7
|
-
isSystem: boolean;
|
|
8
|
-
role?: {
|
|
9
|
-
id: string;
|
|
10
|
-
name: string;
|
|
11
|
-
routePermissions: {
|
|
12
|
-
id: string;
|
|
13
|
-
isEnabled: boolean;
|
|
14
|
-
allowedUsers?: {
|
|
15
|
-
id: string;
|
|
16
|
-
}[] | undefined;
|
|
17
|
-
methods: {
|
|
18
|
-
id: string;
|
|
19
|
-
method: string;
|
|
20
|
-
}[];
|
|
21
|
-
route: {
|
|
22
|
-
id: string;
|
|
23
|
-
path: string;
|
|
24
|
-
};
|
|
25
|
-
}[];
|
|
26
|
-
} | undefined;
|
|
27
|
-
allowedRoutePermissions?: {
|
|
28
|
-
id: string;
|
|
29
|
-
isEnabled: boolean;
|
|
30
|
-
allowedUsers?: {
|
|
31
|
-
id: string;
|
|
32
|
-
}[] | undefined;
|
|
33
|
-
methods: {
|
|
34
|
-
id: string;
|
|
35
|
-
method: string;
|
|
36
|
-
}[];
|
|
37
|
-
route: {
|
|
38
|
-
id: string;
|
|
39
|
-
path: string;
|
|
40
|
-
};
|
|
41
|
-
}[] | undefined;
|
|
42
|
-
} | null, User | {
|
|
43
|
-
id: string;
|
|
44
|
-
email: string;
|
|
45
|
-
isRootAdmin: boolean;
|
|
46
|
-
isSystem: boolean;
|
|
47
|
-
role?: {
|
|
48
|
-
id: string;
|
|
49
|
-
name: string;
|
|
50
|
-
routePermissions: {
|
|
51
|
-
id: string;
|
|
52
|
-
isEnabled: boolean;
|
|
53
|
-
allowedUsers?: {
|
|
54
|
-
id: string;
|
|
55
|
-
}[] | undefined;
|
|
56
|
-
methods: {
|
|
57
|
-
id: string;
|
|
58
|
-
method: string;
|
|
59
|
-
}[];
|
|
60
|
-
route: {
|
|
61
|
-
id: string;
|
|
62
|
-
path: string;
|
|
63
|
-
};
|
|
64
|
-
}[];
|
|
65
|
-
} | undefined;
|
|
66
|
-
allowedRoutePermissions?: {
|
|
67
|
-
id: string;
|
|
68
|
-
isEnabled: boolean;
|
|
69
|
-
allowedUsers?: {
|
|
70
|
-
id: string;
|
|
71
|
-
}[] | undefined;
|
|
72
|
-
methods: {
|
|
73
|
-
id: string;
|
|
74
|
-
method: string;
|
|
75
|
-
}[];
|
|
76
|
-
route: {
|
|
77
|
-
id: string;
|
|
78
|
-
path: string;
|
|
79
|
-
};
|
|
80
|
-
}[] | undefined;
|
|
81
|
-
} | null>;
|
|
82
|
-
readonly login: (payload: LoginPayload) => Promise<any>;
|
|
83
|
-
readonly logout: () => Promise<void>;
|
|
84
|
-
readonly fetchUser: (options?: {
|
|
85
|
-
fields?: string[];
|
|
86
|
-
}) => Promise<void>;
|
|
87
|
-
readonly isLoggedIn: import("vue").ComputedRef<boolean>;
|
|
88
|
-
};
|
|
89
|
-
//# sourceMappingURL=useEnfyraAuth.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useEnfyraAuth.d.ts","sourceRoot":"","sources":["../../src/composables/useEnfyraAuth.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,IAAI,EAAuB,MAAM,eAAe,CAAC;AAM7E,wBAAgB,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;8BAgDG,YAAY;;mCAzBP;QAAE,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;KAAE;;EAqEzD"}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { ref, computed } from "vue";
|
|
2
|
-
import { useEnfyraApi } from "./useEnfyraApi";
|
|
3
|
-
const me = ref(null);
|
|
4
|
-
const isLoading = ref(false);
|
|
5
|
-
export function useEnfyraAuth() {
|
|
6
|
-
const { data: loginData, execute: executeLogin, error: loginError, } = useEnfyraApi("/login", {
|
|
7
|
-
method: "post",
|
|
8
|
-
errorContext: "Login",
|
|
9
|
-
});
|
|
10
|
-
const { execute: executeLogout } = useEnfyraApi("/logout", {
|
|
11
|
-
method: "post",
|
|
12
|
-
errorContext: "Logout",
|
|
13
|
-
});
|
|
14
|
-
const { data: meData, execute: executeFetchUser, error: fetchUserError, } = useEnfyraApi("/me", {
|
|
15
|
-
errorContext: "Fetch User Profile",
|
|
16
|
-
});
|
|
17
|
-
const fetchUser = async (options) => {
|
|
18
|
-
isLoading.value = true;
|
|
19
|
-
try {
|
|
20
|
-
const queryParams = {};
|
|
21
|
-
if (options?.fields && options.fields.length > 0) {
|
|
22
|
-
queryParams.fields = options.fields.join(",");
|
|
23
|
-
}
|
|
24
|
-
await executeFetchUser({
|
|
25
|
-
query: queryParams,
|
|
26
|
-
});
|
|
27
|
-
if (fetchUserError.value) {
|
|
28
|
-
me.value = null;
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
me.value = meData.value?.data?.[0];
|
|
32
|
-
}
|
|
33
|
-
finally {
|
|
34
|
-
isLoading.value = false;
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
const login = async (payload) => {
|
|
38
|
-
isLoading.value = true;
|
|
39
|
-
try {
|
|
40
|
-
await executeLogin({ body: payload });
|
|
41
|
-
if (loginError.value) {
|
|
42
|
-
return null;
|
|
43
|
-
}
|
|
44
|
-
return loginData.value;
|
|
45
|
-
}
|
|
46
|
-
finally {
|
|
47
|
-
isLoading.value = false;
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
const logout = async () => {
|
|
51
|
-
isLoading.value = true;
|
|
52
|
-
try {
|
|
53
|
-
await executeLogout();
|
|
54
|
-
me.value = null;
|
|
55
|
-
if (typeof window !== "undefined") {
|
|
56
|
-
window.location.reload();
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
catch (error) {
|
|
60
|
-
me.value = null;
|
|
61
|
-
if (typeof window !== "undefined") {
|
|
62
|
-
window.location.reload();
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
finally {
|
|
66
|
-
isLoading.value = false;
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
const isLoggedIn = computed(() => !!me.value);
|
|
70
|
-
return {
|
|
71
|
-
me,
|
|
72
|
-
login,
|
|
73
|
-
logout,
|
|
74
|
-
fetchUser,
|
|
75
|
-
isLoggedIn,
|
|
76
|
-
};
|
|
77
|
-
}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { ref, computed } from "vue";
|
|
2
|
-
import { useEnfyraApi } from "./useEnfyraApi.mjs";
|
|
3
|
-
const me = ref(null);
|
|
4
|
-
const isLoading = ref(false);
|
|
5
|
-
export function useEnfyraAuth() {
|
|
6
|
-
const {
|
|
7
|
-
data: loginData,
|
|
8
|
-
execute: executeLogin,
|
|
9
|
-
error: loginError
|
|
10
|
-
} = useEnfyraApi("/login", {
|
|
11
|
-
method: "post",
|
|
12
|
-
errorContext: "Login"
|
|
13
|
-
});
|
|
14
|
-
const { execute: executeLogout } = useEnfyraApi("/logout", {
|
|
15
|
-
method: "post",
|
|
16
|
-
errorContext: "Logout"
|
|
17
|
-
});
|
|
18
|
-
const {
|
|
19
|
-
data: meData,
|
|
20
|
-
execute: executeFetchUser,
|
|
21
|
-
error: fetchUserError
|
|
22
|
-
} = useEnfyraApi("/me", {
|
|
23
|
-
errorContext: "Fetch User Profile"
|
|
24
|
-
});
|
|
25
|
-
const fetchUser = async (options) => {
|
|
26
|
-
isLoading.value = true;
|
|
27
|
-
try {
|
|
28
|
-
const queryParams = {};
|
|
29
|
-
if (options?.fields && options.fields.length > 0) {
|
|
30
|
-
queryParams.fields = options.fields.join(",");
|
|
31
|
-
}
|
|
32
|
-
await executeFetchUser({
|
|
33
|
-
query: queryParams
|
|
34
|
-
});
|
|
35
|
-
if (fetchUserError.value) {
|
|
36
|
-
me.value = null;
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
me.value = meData.value?.data?.[0];
|
|
40
|
-
} finally {
|
|
41
|
-
isLoading.value = false;
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
const login = async (payload) => {
|
|
45
|
-
isLoading.value = true;
|
|
46
|
-
try {
|
|
47
|
-
await executeLogin({ body: payload });
|
|
48
|
-
if (loginError.value) {
|
|
49
|
-
return null;
|
|
50
|
-
}
|
|
51
|
-
return loginData.value;
|
|
52
|
-
} finally {
|
|
53
|
-
isLoading.value = false;
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
const logout = async () => {
|
|
57
|
-
isLoading.value = true;
|
|
58
|
-
try {
|
|
59
|
-
await executeLogout();
|
|
60
|
-
me.value = null;
|
|
61
|
-
if (typeof window !== "undefined") {
|
|
62
|
-
window.location.reload();
|
|
63
|
-
}
|
|
64
|
-
} catch (error) {
|
|
65
|
-
me.value = null;
|
|
66
|
-
if (typeof window !== "undefined") {
|
|
67
|
-
window.location.reload();
|
|
68
|
-
}
|
|
69
|
-
} finally {
|
|
70
|
-
isLoading.value = false;
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
const isLoggedIn = computed(() => !!me.value);
|
|
74
|
-
return {
|
|
75
|
-
me,
|
|
76
|
-
login,
|
|
77
|
-
logout,
|
|
78
|
-
fetchUser,
|
|
79
|
-
isLoggedIn
|
|
80
|
-
};
|
|
81
|
-
}
|
package/dist/constants/auth.d.ts
DELETED
|
File without changes
|
package/dist/constants/auth.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/constants/config.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,iBAAiB,gBAAgB,CAAC"}
|
package/dist/constants/config.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const ENFYRA_API_PREFIX = "/enfyra/api";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const ENFYRA_API_PREFIX = "/enfyra/api";
|
package/dist/module.cjs
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const kit = require('@nuxt/kit');
|
|
4
|
-
const config_mjs = require('../dist/constants/config.mjs');
|
|
5
|
-
|
|
6
|
-
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
7
|
-
const module$1 = kit.defineNuxtModule({
|
|
8
|
-
meta: {
|
|
9
|
-
name: "@enfyra/sdk-nuxt",
|
|
10
|
-
configKey: "enfyraSDK"
|
|
11
|
-
},
|
|
12
|
-
defaults: {
|
|
13
|
-
apiUrl: "",
|
|
14
|
-
apiPrefix: config_mjs.ENFYRA_API_PREFIX
|
|
15
|
-
},
|
|
16
|
-
setup(options, nuxt) {
|
|
17
|
-
const normalizedOptions = {
|
|
18
|
-
...options,
|
|
19
|
-
apiUrl: typeof options.apiUrl === "string" ? options.apiUrl.replace(/\/+$/, "") : options.apiUrl,
|
|
20
|
-
apiPrefix: typeof options.apiPrefix === "string" ? options.apiPrefix.trim() ? "/" + options.apiPrefix.replace(/^\/+|\/+$/g, "").replace(/\/+/g, "/") : config_mjs.ENFYRA_API_PREFIX : config_mjs.ENFYRA_API_PREFIX
|
|
21
|
-
};
|
|
22
|
-
const apiPrefix = normalizedOptions.apiPrefix;
|
|
23
|
-
const { resolve } = kit.createResolver((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('module.cjs', document.baseURI).href)));
|
|
24
|
-
if (!normalizedOptions.apiUrl) {
|
|
25
|
-
console.warn(
|
|
26
|
-
`[Enfyra SDK Nuxt] Missing required configuration:
|
|
27
|
-
- apiUrl is required
|
|
28
|
-
Please configure it in your nuxt.config.ts:
|
|
29
|
-
enfyraSDK: {
|
|
30
|
-
apiUrl: 'https://your-api-url'
|
|
31
|
-
}`
|
|
32
|
-
);
|
|
33
|
-
nuxt.options.runtimeConfig.public.enfyraSDK = {
|
|
34
|
-
...normalizedOptions,
|
|
35
|
-
apiPrefix,
|
|
36
|
-
configError: true,
|
|
37
|
-
configErrorMessage: "Enfyra SDK: apiUrl is required. Please configure it in nuxt.config.ts"
|
|
38
|
-
};
|
|
39
|
-
} else {
|
|
40
|
-
nuxt.options.runtimeConfig.public.enfyraSDK = {
|
|
41
|
-
...normalizedOptions,
|
|
42
|
-
apiPrefix
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
if (!normalizedOptions.apiUrl) {
|
|
46
|
-
kit.addPlugin({
|
|
47
|
-
src: resolve("./runtime/plugin/config-error.client"),
|
|
48
|
-
mode: "client"
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
kit.addImportsDir(resolve("./composables"));
|
|
52
|
-
nuxt.hook("prepare:types", ({ declarations, references }) => {
|
|
53
|
-
references.push({
|
|
54
|
-
path: resolve("./types/nuxt-imports.d.ts")
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
kit.addServerHandler({
|
|
58
|
-
handler: resolve("./runtime/server/middleware/auth"),
|
|
59
|
-
middleware: true
|
|
60
|
-
});
|
|
61
|
-
kit.addServerHandler({
|
|
62
|
-
route: `${apiPrefix}/login`,
|
|
63
|
-
handler: resolve("./runtime/server/api/login.post"),
|
|
64
|
-
method: "post"
|
|
65
|
-
});
|
|
66
|
-
kit.addServerHandler({
|
|
67
|
-
route: `${apiPrefix}/logout`,
|
|
68
|
-
handler: resolve("./runtime/server/api/logout.post"),
|
|
69
|
-
method: "post"
|
|
70
|
-
});
|
|
71
|
-
kit.addServerHandler({
|
|
72
|
-
route: "/assets/**",
|
|
73
|
-
handler: resolve("./runtime/server/api/all")
|
|
74
|
-
});
|
|
75
|
-
kit.addServerHandler({
|
|
76
|
-
route: `${apiPrefix}/**`,
|
|
77
|
-
handler: resolve("./runtime/server/api/all")
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
module.exports = module$1;
|