anzar 1.2.9 → 1.3.5
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/README.md +15 -21
- package/dist/adapters/index.cjs +70 -0
- package/dist/adapters/index.d.cts +21 -0
- package/dist/adapters/index.d.ts +21 -0
- package/dist/adapters/index.js +27 -0
- package/dist/base_storage-BnHsA4fU.d.cts +30 -0
- package/dist/base_storage-BnHsA4fU.d.ts +30 -0
- package/dist/chunk-5SSEPZKA.js +27 -0
- package/dist/index-BZFSacf5.d.cts +63 -0
- package/dist/index-BZFSacf5.d.ts +63 -0
- package/dist/index.cjs +235 -120
- package/dist/index.d.cts +112 -60
- package/dist/index.d.ts +112 -60
- package/dist/index.js +207 -112
- package/dist/types/index.cjs +18 -0
- package/dist/types/index.d.cts +1 -0
- package/dist/types/index.d.ts +1 -0
- package/package.json +24 -4
- /package/{README.MD → dist/types/index.js} +0 -0
package/dist/index.js
CHANGED
|
@@ -1,5 +1,136 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MemoryStorage
|
|
3
|
+
} from "./chunk-5SSEPZKA.js";
|
|
4
|
+
|
|
1
5
|
// src/index.ts
|
|
6
|
+
import axios2 from "axios";
|
|
7
|
+
|
|
8
|
+
// src/api/auth.ts
|
|
2
9
|
import axios from "axios";
|
|
10
|
+
var AuthModule = class {
|
|
11
|
+
constructor(authApi, userApi, strategy, options) {
|
|
12
|
+
this.authApi = authApi;
|
|
13
|
+
this.userApi = userApi;
|
|
14
|
+
this.strategy = strategy;
|
|
15
|
+
this.options = options;
|
|
16
|
+
}
|
|
17
|
+
async login(body) {
|
|
18
|
+
const response = await this.authApi.login(body);
|
|
19
|
+
const auth_response = response.data;
|
|
20
|
+
if (auth_response.tokens) {
|
|
21
|
+
this.options?.storage.onTokenRefresh?.(auth_response.tokens);
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
user: auth_response.user,
|
|
25
|
+
verification: auth_response.verification
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
async register(body) {
|
|
29
|
+
const response = await this.authApi.register(body);
|
|
30
|
+
const auth_response = response.data;
|
|
31
|
+
if (auth_response.tokens) {
|
|
32
|
+
this.options?.storage.onTokenRefresh?.(auth_response.tokens);
|
|
33
|
+
}
|
|
34
|
+
return {
|
|
35
|
+
user: auth_response.user,
|
|
36
|
+
verification: auth_response.verification
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
async logout() {
|
|
40
|
+
const refreshToken = this.options?.storage.getRefreshToken();
|
|
41
|
+
await this.authApi.logout({ refresh_token: refreshToken ?? "" });
|
|
42
|
+
this.options?.storage.onLogout?.();
|
|
43
|
+
}
|
|
44
|
+
resetPassword(body) {
|
|
45
|
+
this.authApi.requestPasswordReset(body);
|
|
46
|
+
}
|
|
47
|
+
async isAuthenticated() {
|
|
48
|
+
try {
|
|
49
|
+
const response = await this.userApi.findUser();
|
|
50
|
+
return !!response.data.username;
|
|
51
|
+
} catch (error) {
|
|
52
|
+
if (axios.isAxiosError(error) && error.response?.status === 401) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
throw false;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
async session() {
|
|
59
|
+
if (this.strategy !== "Session" /* Session */) {
|
|
60
|
+
throw new Error("session() is only available with Session auth strategy");
|
|
61
|
+
}
|
|
62
|
+
const response = await this.authApi.getSession();
|
|
63
|
+
return response.data;
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
// src/api/interceptor.ts
|
|
68
|
+
var JwtInterceptor = class {
|
|
69
|
+
isRefreshing = false;
|
|
70
|
+
waitingQueue = [];
|
|
71
|
+
drainQueue(token) {
|
|
72
|
+
this.waitingQueue.forEach(({ resolve }) => resolve(token));
|
|
73
|
+
this.waitingQueue = [];
|
|
74
|
+
}
|
|
75
|
+
rejectQueue(error) {
|
|
76
|
+
this.waitingQueue.forEach(({ reject }) => reject(error));
|
|
77
|
+
this.waitingQueue = [];
|
|
78
|
+
}
|
|
79
|
+
apply(axiosInstance, options) {
|
|
80
|
+
const REFRESH_URI = "/auth/refresh-token";
|
|
81
|
+
axiosInstance.interceptors.request.use(
|
|
82
|
+
(config) => {
|
|
83
|
+
const accessToken = options?.storage.getToken();
|
|
84
|
+
if (!config.url?.includes(REFRESH_URI) && accessToken) {
|
|
85
|
+
config.headers.Authorization = `Bearer ${accessToken}`;
|
|
86
|
+
}
|
|
87
|
+
return config;
|
|
88
|
+
},
|
|
89
|
+
(error) => {
|
|
90
|
+
return Promise.reject(error);
|
|
91
|
+
}
|
|
92
|
+
);
|
|
93
|
+
axiosInstance.interceptors.response.use(
|
|
94
|
+
(response) => response,
|
|
95
|
+
async (error) => {
|
|
96
|
+
const originalRequest = error.config;
|
|
97
|
+
if (error.response?.status !== 401 || originalRequest._retry || originalRequest.url?.includes(REFRESH_URI)) {
|
|
98
|
+
return Promise.reject(error);
|
|
99
|
+
}
|
|
100
|
+
if (this.isRefreshing) {
|
|
101
|
+
return new Promise((resolve, reject) => {
|
|
102
|
+
this.waitingQueue.push({ resolve, reject });
|
|
103
|
+
}).then((newToken) => {
|
|
104
|
+
originalRequest.headers.Authorization = `Bearer ${newToken}`;
|
|
105
|
+
return axiosInstance(originalRequest);
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
originalRequest._retry = true;
|
|
109
|
+
this.isRefreshing = true;
|
|
110
|
+
try {
|
|
111
|
+
const refreshToken = options?.storage.getRefreshToken();
|
|
112
|
+
if (!refreshToken) return Promise.reject(error);
|
|
113
|
+
const response = await axiosInstance.post(REFRESH_URI, {
|
|
114
|
+
refresh_token: refreshToken
|
|
115
|
+
});
|
|
116
|
+
const auth_response = response.data;
|
|
117
|
+
if (auth_response.tokens) {
|
|
118
|
+
options?.storage.onTokenRefresh?.(auth_response.tokens);
|
|
119
|
+
}
|
|
120
|
+
this.drainQueue(auth_response.tokens?.access);
|
|
121
|
+
originalRequest.headers.Authorization = `Bearer ${auth_response.tokens?.access}`;
|
|
122
|
+
return axiosInstance(originalRequest);
|
|
123
|
+
} catch (e) {
|
|
124
|
+
this.rejectQueue(e);
|
|
125
|
+
options?.storage.onSessionExpired?.();
|
|
126
|
+
return Promise.reject(e);
|
|
127
|
+
} finally {
|
|
128
|
+
this.isRefreshing = false;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
};
|
|
3
134
|
|
|
4
135
|
// src/generated/api/auth-api.ts
|
|
5
136
|
import globalAxios2 from "axios";
|
|
@@ -8,9 +139,9 @@ import globalAxios2 from "axios";
|
|
|
8
139
|
import globalAxios from "axios";
|
|
9
140
|
var BASE_PATH = "http://localhost".replace(/\/+$/, "");
|
|
10
141
|
var BaseAPI = class {
|
|
11
|
-
constructor(configuration, basePath = BASE_PATH,
|
|
142
|
+
constructor(configuration, basePath = BASE_PATH, axios3 = globalAxios) {
|
|
12
143
|
this.basePath = basePath;
|
|
13
|
-
this.axios =
|
|
144
|
+
this.axios = axios3;
|
|
14
145
|
if (configuration) {
|
|
15
146
|
this.configuration = configuration;
|
|
16
147
|
this.basePath = configuration.basePath ?? basePath;
|
|
@@ -79,9 +210,9 @@ var toPathString = function(url) {
|
|
|
79
210
|
return url.pathname + url.search + url.hash;
|
|
80
211
|
};
|
|
81
212
|
var createRequestFunction = function(axiosArgs, globalAxios5, BASE_PATH2, configuration) {
|
|
82
|
-
return (
|
|
83
|
-
const axiosRequestArgs = { ...axiosArgs.options, url: (
|
|
84
|
-
return
|
|
213
|
+
return (axios3 = globalAxios5, basePath = BASE_PATH2) => {
|
|
214
|
+
const axiosRequestArgs = { ...axiosArgs.options, url: (axios3.defaults.baseURL ? "" : configuration?.basePath ?? basePath) + axiosArgs.url };
|
|
215
|
+
return axios3.request(axiosRequestArgs);
|
|
85
216
|
};
|
|
86
217
|
};
|
|
87
218
|
|
|
@@ -146,10 +277,12 @@ var AuthApiAxiosParamCreator = function(configuration) {
|
|
|
146
277
|
/**
|
|
147
278
|
* Invalidates the current session and refresh token. The client should discard stored tokens.
|
|
148
279
|
* @summary Logout
|
|
280
|
+
* @param {RefreshTokenRequest} refreshTokenRequest
|
|
149
281
|
* @param {*} [options] Override http request option.
|
|
150
282
|
* @throws {RequiredError}
|
|
151
283
|
*/
|
|
152
|
-
logout: async (options = {}) => {
|
|
284
|
+
logout: async (refreshTokenRequest, options = {}) => {
|
|
285
|
+
assertParamExists("logout", "refreshTokenRequest", refreshTokenRequest);
|
|
153
286
|
const localVarPath = `/auth/logout`;
|
|
154
287
|
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
|
|
155
288
|
let baseOptions;
|
|
@@ -160,10 +293,12 @@ var AuthApiAxiosParamCreator = function(configuration) {
|
|
|
160
293
|
const localVarHeaderParameter = {};
|
|
161
294
|
const localVarQueryParameter = {};
|
|
162
295
|
await setBearerAuthToObject(localVarHeaderParameter, configuration);
|
|
296
|
+
localVarHeaderParameter["Content-Type"] = "application/json";
|
|
163
297
|
localVarHeaderParameter["Accept"] = "application/json";
|
|
164
298
|
setSearchParams(localVarUrlObj, localVarQueryParameter);
|
|
165
299
|
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
|
|
166
300
|
localVarRequestOptions.headers = { ...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers };
|
|
301
|
+
localVarRequestOptions.data = serializeDataIfNeeded(refreshTokenRequest, localVarRequestOptions, configuration);
|
|
167
302
|
return {
|
|
168
303
|
url: toPathString(localVarUrlObj),
|
|
169
304
|
options: localVarRequestOptions
|
|
@@ -172,10 +307,12 @@ var AuthApiAxiosParamCreator = function(configuration) {
|
|
|
172
307
|
/**
|
|
173
308
|
* Issues a new access token using a valid refresh token. Rotate refresh tokens on each call.
|
|
174
309
|
* @summary Refresh access token
|
|
310
|
+
* @param {RefreshTokenRequest} refreshTokenRequest
|
|
175
311
|
* @param {*} [options] Override http request option.
|
|
176
312
|
* @throws {RequiredError}
|
|
177
313
|
*/
|
|
178
|
-
refreshToken: async (options = {}) => {
|
|
314
|
+
refreshToken: async (refreshTokenRequest, options = {}) => {
|
|
315
|
+
assertParamExists("refreshToken", "refreshTokenRequest", refreshTokenRequest);
|
|
179
316
|
const localVarPath = `/auth/refresh-token`;
|
|
180
317
|
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
|
|
181
318
|
let baseOptions;
|
|
@@ -186,10 +323,12 @@ var AuthApiAxiosParamCreator = function(configuration) {
|
|
|
186
323
|
const localVarHeaderParameter = {};
|
|
187
324
|
const localVarQueryParameter = {};
|
|
188
325
|
await setBearerAuthToObject(localVarHeaderParameter, configuration);
|
|
326
|
+
localVarHeaderParameter["Content-Type"] = "application/json";
|
|
189
327
|
localVarHeaderParameter["Accept"] = "application/json";
|
|
190
328
|
setSearchParams(localVarUrlObj, localVarQueryParameter);
|
|
191
329
|
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
|
|
192
330
|
localVarRequestOptions.headers = { ...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers };
|
|
331
|
+
localVarRequestOptions.data = serializeDataIfNeeded(refreshTokenRequest, localVarRequestOptions, configuration);
|
|
193
332
|
return {
|
|
194
333
|
url: toPathString(localVarUrlObj),
|
|
195
334
|
options: localVarRequestOptions
|
|
@@ -329,7 +468,7 @@ var AuthApiFp = function(configuration) {
|
|
|
329
468
|
const localVarAxiosArgs = await localVarAxiosParamCreator.getSession(options);
|
|
330
469
|
const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
|
|
331
470
|
const localVarOperationServerBasePath = operationServerMap["AuthApi.getSession"]?.[localVarOperationServerIndex]?.url;
|
|
332
|
-
return (
|
|
471
|
+
return (axios3, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios2, BASE_PATH, configuration)(axios3, localVarOperationServerBasePath || basePath);
|
|
333
472
|
},
|
|
334
473
|
/**
|
|
335
474
|
* Authenticates a user with email and password. Returns an access token and refresh token on success.
|
|
@@ -342,31 +481,33 @@ var AuthApiFp = function(configuration) {
|
|
|
342
481
|
const localVarAxiosArgs = await localVarAxiosParamCreator.login(loginRequest, options);
|
|
343
482
|
const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
|
|
344
483
|
const localVarOperationServerBasePath = operationServerMap["AuthApi.login"]?.[localVarOperationServerIndex]?.url;
|
|
345
|
-
return (
|
|
484
|
+
return (axios3, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios2, BASE_PATH, configuration)(axios3, localVarOperationServerBasePath || basePath);
|
|
346
485
|
},
|
|
347
486
|
/**
|
|
348
487
|
* Invalidates the current session and refresh token. The client should discard stored tokens.
|
|
349
488
|
* @summary Logout
|
|
489
|
+
* @param {RefreshTokenRequest} refreshTokenRequest
|
|
350
490
|
* @param {*} [options] Override http request option.
|
|
351
491
|
* @throws {RequiredError}
|
|
352
492
|
*/
|
|
353
|
-
async logout(options) {
|
|
354
|
-
const localVarAxiosArgs = await localVarAxiosParamCreator.logout(options);
|
|
493
|
+
async logout(refreshTokenRequest, options) {
|
|
494
|
+
const localVarAxiosArgs = await localVarAxiosParamCreator.logout(refreshTokenRequest, options);
|
|
355
495
|
const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
|
|
356
496
|
const localVarOperationServerBasePath = operationServerMap["AuthApi.logout"]?.[localVarOperationServerIndex]?.url;
|
|
357
|
-
return (
|
|
497
|
+
return (axios3, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios2, BASE_PATH, configuration)(axios3, localVarOperationServerBasePath || basePath);
|
|
358
498
|
},
|
|
359
499
|
/**
|
|
360
500
|
* Issues a new access token using a valid refresh token. Rotate refresh tokens on each call.
|
|
361
501
|
* @summary Refresh access token
|
|
502
|
+
* @param {RefreshTokenRequest} refreshTokenRequest
|
|
362
503
|
* @param {*} [options] Override http request option.
|
|
363
504
|
* @throws {RequiredError}
|
|
364
505
|
*/
|
|
365
|
-
async refreshToken(options) {
|
|
366
|
-
const localVarAxiosArgs = await localVarAxiosParamCreator.refreshToken(options);
|
|
506
|
+
async refreshToken(refreshTokenRequest, options) {
|
|
507
|
+
const localVarAxiosArgs = await localVarAxiosParamCreator.refreshToken(refreshTokenRequest, options);
|
|
367
508
|
const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
|
|
368
509
|
const localVarOperationServerBasePath = operationServerMap["AuthApi.refreshToken"]?.[localVarOperationServerIndex]?.url;
|
|
369
|
-
return (
|
|
510
|
+
return (axios3, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios2, BASE_PATH, configuration)(axios3, localVarOperationServerBasePath || basePath);
|
|
370
511
|
},
|
|
371
512
|
/**
|
|
372
513
|
* Creates a new user account. Sends a verification email upon successful registration.
|
|
@@ -379,7 +520,7 @@ var AuthApiFp = function(configuration) {
|
|
|
379
520
|
const localVarAxiosArgs = await localVarAxiosParamCreator.register(registerRequest, options);
|
|
380
521
|
const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
|
|
381
522
|
const localVarOperationServerBasePath = operationServerMap["AuthApi.register"]?.[localVarOperationServerIndex]?.url;
|
|
382
|
-
return (
|
|
523
|
+
return (axios3, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios2, BASE_PATH, configuration)(axios3, localVarOperationServerBasePath || basePath);
|
|
383
524
|
},
|
|
384
525
|
/**
|
|
385
526
|
* Validates the reset token from the email link and renders the password reset form.
|
|
@@ -392,7 +533,7 @@ var AuthApiFp = function(configuration) {
|
|
|
392
533
|
const localVarAxiosArgs = await localVarAxiosParamCreator.renderResetForm(token, options);
|
|
393
534
|
const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
|
|
394
535
|
const localVarOperationServerBasePath = operationServerMap["AuthApi.renderResetForm"]?.[localVarOperationServerIndex]?.url;
|
|
395
|
-
return (
|
|
536
|
+
return (axios3, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios2, BASE_PATH, configuration)(axios3, localVarOperationServerBasePath || basePath);
|
|
396
537
|
},
|
|
397
538
|
/**
|
|
398
539
|
* Sends a password reset link to the provided email address if an account exists.
|
|
@@ -405,7 +546,7 @@ var AuthApiFp = function(configuration) {
|
|
|
405
546
|
const localVarAxiosArgs = await localVarAxiosParamCreator.requestPasswordReset(emailRequest, options);
|
|
406
547
|
const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
|
|
407
548
|
const localVarOperationServerBasePath = operationServerMap["AuthApi.requestPasswordReset"]?.[localVarOperationServerIndex]?.url;
|
|
408
|
-
return (
|
|
549
|
+
return (axios3, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios2, BASE_PATH, configuration)(axios3, localVarOperationServerBasePath || basePath);
|
|
409
550
|
},
|
|
410
551
|
/**
|
|
411
552
|
* Submits a new password using a valid reset token. Invalidates the token after use.
|
|
@@ -418,7 +559,7 @@ var AuthApiFp = function(configuration) {
|
|
|
418
559
|
const localVarAxiosArgs = await localVarAxiosParamCreator.submitNewPassword(resetPasswordRequest, options);
|
|
419
560
|
const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
|
|
420
561
|
const localVarOperationServerBasePath = operationServerMap["AuthApi.submitNewPassword"]?.[localVarOperationServerIndex]?.url;
|
|
421
|
-
return (
|
|
562
|
+
return (axios3, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios2, BASE_PATH, configuration)(axios3, localVarOperationServerBasePath || basePath);
|
|
422
563
|
}
|
|
423
564
|
};
|
|
424
565
|
};
|
|
@@ -445,20 +586,22 @@ var AuthApi = class extends BaseAPI {
|
|
|
445
586
|
/**
|
|
446
587
|
* Invalidates the current session and refresh token. The client should discard stored tokens.
|
|
447
588
|
* @summary Logout
|
|
589
|
+
* @param {RefreshTokenRequest} refreshTokenRequest
|
|
448
590
|
* @param {*} [options] Override http request option.
|
|
449
591
|
* @throws {RequiredError}
|
|
450
592
|
*/
|
|
451
|
-
logout(options) {
|
|
452
|
-
return AuthApiFp(this.configuration).logout(options).then((request) => request(this.axios, this.basePath));
|
|
593
|
+
logout(refreshTokenRequest, options) {
|
|
594
|
+
return AuthApiFp(this.configuration).logout(refreshTokenRequest, options).then((request) => request(this.axios, this.basePath));
|
|
453
595
|
}
|
|
454
596
|
/**
|
|
455
597
|
* Issues a new access token using a valid refresh token. Rotate refresh tokens on each call.
|
|
456
598
|
* @summary Refresh access token
|
|
599
|
+
* @param {RefreshTokenRequest} refreshTokenRequest
|
|
457
600
|
* @param {*} [options] Override http request option.
|
|
458
601
|
* @throws {RequiredError}
|
|
459
602
|
*/
|
|
460
|
-
refreshToken(options) {
|
|
461
|
-
return AuthApiFp(this.configuration).refreshToken(options).then((request) => request(this.axios, this.basePath));
|
|
603
|
+
refreshToken(refreshTokenRequest, options) {
|
|
604
|
+
return AuthApiFp(this.configuration).refreshToken(refreshTokenRequest, options).then((request) => request(this.axios, this.basePath));
|
|
462
605
|
}
|
|
463
606
|
/**
|
|
464
607
|
* Creates a new user account. Sends a verification email upon successful registration.
|
|
@@ -554,7 +697,7 @@ var EmailApiFp = function(configuration) {
|
|
|
554
697
|
const localVarAxiosArgs = await localVarAxiosParamCreator.verifyEmail(token, options);
|
|
555
698
|
const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
|
|
556
699
|
const localVarOperationServerBasePath = operationServerMap["EmailApi.verifyEmail"]?.[localVarOperationServerIndex]?.url;
|
|
557
|
-
return (
|
|
700
|
+
return (axios3, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios3, BASE_PATH, configuration)(axios3, localVarOperationServerBasePath || basePath);
|
|
558
701
|
}
|
|
559
702
|
};
|
|
560
703
|
};
|
|
@@ -616,7 +759,7 @@ var UsersApiFp = function(configuration) {
|
|
|
616
759
|
const localVarAxiosArgs = await localVarAxiosParamCreator.findUser(options);
|
|
617
760
|
const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
|
|
618
761
|
const localVarOperationServerBasePath = operationServerMap["UsersApi.findUser"]?.[localVarOperationServerIndex]?.url;
|
|
619
|
-
return (
|
|
762
|
+
return (axios3, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios4, BASE_PATH, configuration)(axios3, localVarOperationServerBasePath || basePath);
|
|
620
763
|
}
|
|
621
764
|
};
|
|
622
765
|
};
|
|
@@ -716,97 +859,49 @@ var Configuration = class {
|
|
|
716
859
|
}
|
|
717
860
|
};
|
|
718
861
|
|
|
719
|
-
// src/http/jwt_interceptor.ts
|
|
720
|
-
var JwtInterceptor = class {
|
|
721
|
-
apply(axiosInstance, options) {
|
|
722
|
-
const REFRESH_URI = "/auth/refresh-token";
|
|
723
|
-
axiosInstance.interceptors.request.use(
|
|
724
|
-
(config) => {
|
|
725
|
-
const accessToken = options?.getToken();
|
|
726
|
-
if (!config.url?.includes(REFRESH_URI) && accessToken) {
|
|
727
|
-
config.headers.Authorization = `Bearer ${accessToken}`;
|
|
728
|
-
}
|
|
729
|
-
return config;
|
|
730
|
-
},
|
|
731
|
-
(error) => {
|
|
732
|
-
console.error("Request error:", error);
|
|
733
|
-
return Promise.reject(error);
|
|
734
|
-
}
|
|
735
|
-
);
|
|
736
|
-
axiosInstance.interceptors.response.use(
|
|
737
|
-
(response) => response,
|
|
738
|
-
async (error) => {
|
|
739
|
-
const originalRequest = error.config;
|
|
740
|
-
if (error.response?.status === 401 && !originalRequest._retry && !originalRequest.url?.includes(REFRESH_URI)) {
|
|
741
|
-
originalRequest._retry = true;
|
|
742
|
-
try {
|
|
743
|
-
const refreshToken = options?.getRefreshToken();
|
|
744
|
-
const response = await axiosInstance.post(
|
|
745
|
-
REFRESH_URI,
|
|
746
|
-
{},
|
|
747
|
-
{ headers: { "x-refresh-token": `Bearer ${refreshToken}` } }
|
|
748
|
-
);
|
|
749
|
-
const auth_response = response.data;
|
|
750
|
-
if (auth_response.tokens) {
|
|
751
|
-
options?.onTokenRefresh?.(auth_response.tokens);
|
|
752
|
-
}
|
|
753
|
-
originalRequest.headers.Authorization = `Bearer ${auth_response.tokens?.access}`;
|
|
754
|
-
return axiosInstance(originalRequest);
|
|
755
|
-
} catch (e) {
|
|
756
|
-
options?.onSessionExpired?.();
|
|
757
|
-
return Promise.reject(e);
|
|
758
|
-
}
|
|
759
|
-
}
|
|
760
|
-
return Promise.reject(error);
|
|
761
|
-
}
|
|
762
|
-
);
|
|
763
|
-
}
|
|
764
|
-
};
|
|
765
|
-
|
|
766
862
|
// src/index.ts
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
863
|
+
var DEFAULT_OPTIONS = {
|
|
864
|
+
storage: new MemoryStorage()
|
|
865
|
+
};
|
|
866
|
+
var Anzar = class {
|
|
867
|
+
Auth;
|
|
868
|
+
User;
|
|
869
|
+
Email;
|
|
870
|
+
constructor(anzarConfig, options = DEFAULT_OPTIONS) {
|
|
871
|
+
const basePath = anzarConfig.api_url;
|
|
872
|
+
const axiosInstance = this.createAxiosInstance(basePath);
|
|
873
|
+
const configuration = new Configuration({ basePath });
|
|
874
|
+
if (anzarConfig.auth?.strategy === "Jwt" /* Jwt */) {
|
|
875
|
+
new JwtInterceptor().apply(axiosInstance, options);
|
|
776
876
|
}
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
877
|
+
const apis = this.createApis(configuration, basePath, axiosInstance);
|
|
878
|
+
this.Auth = new AuthModule(
|
|
879
|
+
apis.auth,
|
|
880
|
+
apis.user,
|
|
881
|
+
anzarConfig.auth?.strategy ?? "Session" /* Session */,
|
|
882
|
+
options
|
|
883
|
+
);
|
|
884
|
+
this.User = apis.user;
|
|
885
|
+
this.Email = apis.email;
|
|
780
886
|
}
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
await generatedAuthApi.logout();
|
|
789
|
-
options?.onLogout?.();
|
|
790
|
-
},
|
|
791
|
-
resetPassword: (body) => {
|
|
792
|
-
generatedAuthApi.requestPasswordReset(body);
|
|
793
|
-
},
|
|
794
|
-
...anzarConfig.auth?.strategy === "Session" /* Session */ && {
|
|
795
|
-
session: () => generatedAuthApi.getSession()
|
|
796
|
-
},
|
|
797
|
-
isAuthenticated: async () => {
|
|
798
|
-
try {
|
|
799
|
-
const response = await generatedUserApi.findUser();
|
|
800
|
-
return !!response.data;
|
|
801
|
-
} catch {
|
|
802
|
-
return false;
|
|
803
|
-
}
|
|
887
|
+
createAxiosInstance(baseURL) {
|
|
888
|
+
return axios2.create({
|
|
889
|
+
baseURL,
|
|
890
|
+
withCredentials: true,
|
|
891
|
+
headers: {
|
|
892
|
+
"Content-Type": "application/json",
|
|
893
|
+
Accept: "application/json"
|
|
804
894
|
}
|
|
805
|
-
}
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
895
|
+
});
|
|
896
|
+
}
|
|
897
|
+
createApis(configuration, basePath, axiosInstance) {
|
|
898
|
+
return {
|
|
899
|
+
auth: new AuthApi(configuration, basePath, axiosInstance),
|
|
900
|
+
user: new UsersApi(configuration, basePath, axiosInstance),
|
|
901
|
+
email: new EmailApi(configuration, basePath, axiosInstance)
|
|
902
|
+
};
|
|
903
|
+
}
|
|
904
|
+
};
|
|
810
905
|
export {
|
|
811
906
|
Anzar
|
|
812
907
|
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
|
|
16
|
+
// src/types/index.ts
|
|
17
|
+
var types_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(types_exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { A as AuthResult, U as User } from '../index-BZFSacf5.cjs';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { A as AuthResult, U as User } from '../index-BZFSacf5.js';
|
package/package.json
CHANGED
|
@@ -1,19 +1,37 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "anzar",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.5",
|
|
4
4
|
"description": "Anzar SDK",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"main": "./dist/index.cjs",
|
|
7
6
|
"module": "./dist/index.js",
|
|
7
|
+
"main": "./dist/index.cjs",
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
|
+
},
|
|
15
|
+
"./adapters": {
|
|
16
|
+
"types": "./dist/adapters/index.d.ts",
|
|
17
|
+
"import": "./dist/adapters/index.js",
|
|
18
|
+
"require": "./dist/adapters/index.cjs"
|
|
19
|
+
},
|
|
20
|
+
"./types": {
|
|
21
|
+
"types": "./dist/types/index.d.ts",
|
|
22
|
+
"import": "./dist/types/index.js",
|
|
23
|
+
"require": "./dist/types/index.cjs"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
9
26
|
"files": [
|
|
10
27
|
"dist",
|
|
11
28
|
"README.md",
|
|
12
29
|
"LICENSE"
|
|
13
30
|
],
|
|
14
31
|
"scripts": {
|
|
15
|
-
"test": "
|
|
16
|
-
"
|
|
32
|
+
"test": "node --import tsx/esm --test",
|
|
33
|
+
"coverage": "node --import tsx/esm --experimental-test-coverage --test-coverage-lines=80 --test-coverage-branches=80 --test-coverage-functions=70 --test",
|
|
34
|
+
"build": "tsup",
|
|
17
35
|
"prepublishOnly": "npm run build"
|
|
18
36
|
},
|
|
19
37
|
"keywords": [],
|
|
@@ -34,7 +52,9 @@
|
|
|
34
52
|
},
|
|
35
53
|
"devDependencies": {
|
|
36
54
|
"@openapitools/openapi-generator-cli": "^2.29.0",
|
|
55
|
+
"axios-mock-adapter": "^2.1.0",
|
|
37
56
|
"tsup": "^8.5.1",
|
|
57
|
+
"tsx": "^4.21.0",
|
|
38
58
|
"typescript": "^5.9.3"
|
|
39
59
|
}
|
|
40
60
|
}
|
|
File without changes
|