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/dist/index.cjs CHANGED
@@ -28,23 +28,174 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
 
30
30
  // src/index.ts
31
- var index_exports = {};
32
- __export(index_exports, {
31
+ var src_exports = {};
32
+ __export(src_exports, {
33
33
  Anzar: () => Anzar
34
34
  });
35
- module.exports = __toCommonJS(index_exports);
36
- var import_axios5 = __toESM(require("axios"), 1);
35
+ module.exports = __toCommonJS(src_exports);
36
+ var import_axios6 = __toESM(require("axios"), 1);
37
+
38
+ // src/adapters/memory_storage.ts
39
+ var MemoryStorage = class {
40
+ acessToken = null;
41
+ refreshToken = null;
42
+ getToken() {
43
+ return this.acessToken;
44
+ }
45
+ getRefreshToken() {
46
+ return this.refreshToken;
47
+ }
48
+ onTokenRefresh(tokens) {
49
+ this.acessToken = tokens.access;
50
+ this.refreshToken = tokens.refresh;
51
+ }
52
+ onSessionExpired() {
53
+ this.acessToken = null;
54
+ this.refreshToken = null;
55
+ }
56
+ onLogout() {
57
+ this.acessToken = null;
58
+ this.refreshToken = null;
59
+ }
60
+ };
61
+
62
+ // src/api/auth.ts
63
+ var import_axios = __toESM(require("axios"), 1);
64
+ var AuthModule = class {
65
+ constructor(authApi, userApi, strategy, options) {
66
+ this.authApi = authApi;
67
+ this.userApi = userApi;
68
+ this.strategy = strategy;
69
+ this.options = options;
70
+ }
71
+ async login(body) {
72
+ const response = await this.authApi.login(body);
73
+ const auth_response = response.data;
74
+ if (auth_response.tokens) {
75
+ this.options?.storage.onTokenRefresh?.(auth_response.tokens);
76
+ }
77
+ return {
78
+ user: auth_response.user,
79
+ verification: auth_response.verification
80
+ };
81
+ }
82
+ async register(body) {
83
+ const response = await this.authApi.register(body);
84
+ const auth_response = response.data;
85
+ if (auth_response.tokens) {
86
+ this.options?.storage.onTokenRefresh?.(auth_response.tokens);
87
+ }
88
+ return {
89
+ user: auth_response.user,
90
+ verification: auth_response.verification
91
+ };
92
+ }
93
+ async logout() {
94
+ const refreshToken = this.options?.storage.getRefreshToken();
95
+ await this.authApi.logout({ refresh_token: refreshToken ?? "" });
96
+ this.options?.storage.onLogout?.();
97
+ }
98
+ resetPassword(body) {
99
+ this.authApi.requestPasswordReset(body);
100
+ }
101
+ async isAuthenticated() {
102
+ try {
103
+ const response = await this.userApi.findUser();
104
+ return !!response.data.username;
105
+ } catch (error) {
106
+ if (import_axios.default.isAxiosError(error) && error.response?.status === 401) {
107
+ return false;
108
+ }
109
+ throw false;
110
+ }
111
+ }
112
+ async session() {
113
+ if (this.strategy !== "Session" /* Session */) {
114
+ throw new Error("session() is only available with Session auth strategy");
115
+ }
116
+ const response = await this.authApi.getSession();
117
+ return response.data;
118
+ }
119
+ };
120
+
121
+ // src/api/interceptor.ts
122
+ var JwtInterceptor = class {
123
+ isRefreshing = false;
124
+ waitingQueue = [];
125
+ drainQueue(token) {
126
+ this.waitingQueue.forEach(({ resolve }) => resolve(token));
127
+ this.waitingQueue = [];
128
+ }
129
+ rejectQueue(error) {
130
+ this.waitingQueue.forEach(({ reject }) => reject(error));
131
+ this.waitingQueue = [];
132
+ }
133
+ apply(axiosInstance, options) {
134
+ const REFRESH_URI = "/auth/refresh-token";
135
+ axiosInstance.interceptors.request.use(
136
+ (config) => {
137
+ const accessToken = options?.storage.getToken();
138
+ if (!config.url?.includes(REFRESH_URI) && accessToken) {
139
+ config.headers.Authorization = `Bearer ${accessToken}`;
140
+ }
141
+ return config;
142
+ },
143
+ (error) => {
144
+ return Promise.reject(error);
145
+ }
146
+ );
147
+ axiosInstance.interceptors.response.use(
148
+ (response) => response,
149
+ async (error) => {
150
+ const originalRequest = error.config;
151
+ if (error.response?.status !== 401 || originalRequest._retry || originalRequest.url?.includes(REFRESH_URI)) {
152
+ return Promise.reject(error);
153
+ }
154
+ if (this.isRefreshing) {
155
+ return new Promise((resolve, reject) => {
156
+ this.waitingQueue.push({ resolve, reject });
157
+ }).then((newToken) => {
158
+ originalRequest.headers.Authorization = `Bearer ${newToken}`;
159
+ return axiosInstance(originalRequest);
160
+ });
161
+ }
162
+ originalRequest._retry = true;
163
+ this.isRefreshing = true;
164
+ try {
165
+ const refreshToken = options?.storage.getRefreshToken();
166
+ if (!refreshToken) return Promise.reject(error);
167
+ const response = await axiosInstance.post(REFRESH_URI, {
168
+ refresh_token: refreshToken
169
+ });
170
+ const auth_response = response.data;
171
+ if (auth_response.tokens) {
172
+ options?.storage.onTokenRefresh?.(auth_response.tokens);
173
+ }
174
+ this.drainQueue(auth_response.tokens?.access);
175
+ originalRequest.headers.Authorization = `Bearer ${auth_response.tokens?.access}`;
176
+ return axiosInstance(originalRequest);
177
+ } catch (e) {
178
+ this.rejectQueue(e);
179
+ options?.storage.onSessionExpired?.();
180
+ return Promise.reject(e);
181
+ } finally {
182
+ this.isRefreshing = false;
183
+ }
184
+ }
185
+ );
186
+ }
187
+ };
37
188
 
38
189
  // src/generated/api/auth-api.ts
39
- var import_axios2 = __toESM(require("axios"), 1);
190
+ var import_axios3 = __toESM(require("axios"), 1);
40
191
 
41
192
  // src/generated/base.ts
42
- var import_axios = __toESM(require("axios"), 1);
193
+ var import_axios2 = __toESM(require("axios"), 1);
43
194
  var BASE_PATH = "http://localhost".replace(/\/+$/, "");
44
195
  var BaseAPI = class {
45
- constructor(configuration, basePath = BASE_PATH, axios2 = import_axios.default) {
196
+ constructor(configuration, basePath = BASE_PATH, axios3 = import_axios2.default) {
46
197
  this.basePath = basePath;
47
- this.axios = axios2;
198
+ this.axios = axios3;
48
199
  if (configuration) {
49
200
  this.configuration = configuration;
50
201
  this.basePath = configuration.basePath ?? basePath;
@@ -113,9 +264,9 @@ var toPathString = function(url) {
113
264
  return url.pathname + url.search + url.hash;
114
265
  };
115
266
  var createRequestFunction = function(axiosArgs, globalAxios5, BASE_PATH2, configuration) {
116
- return (axios2 = globalAxios5, basePath = BASE_PATH2) => {
117
- const axiosRequestArgs = { ...axiosArgs.options, url: (axios2.defaults.baseURL ? "" : configuration?.basePath ?? basePath) + axiosArgs.url };
118
- return axios2.request(axiosRequestArgs);
267
+ return (axios3 = globalAxios5, basePath = BASE_PATH2) => {
268
+ const axiosRequestArgs = { ...axiosArgs.options, url: (axios3.defaults.baseURL ? "" : configuration?.basePath ?? basePath) + axiosArgs.url };
269
+ return axios3.request(axiosRequestArgs);
119
270
  };
120
271
  };
121
272
 
@@ -180,10 +331,12 @@ var AuthApiAxiosParamCreator = function(configuration) {
180
331
  /**
181
332
  * Invalidates the current session and refresh token. The client should discard stored tokens.
182
333
  * @summary Logout
334
+ * @param {RefreshTokenRequest} refreshTokenRequest
183
335
  * @param {*} [options] Override http request option.
184
336
  * @throws {RequiredError}
185
337
  */
186
- logout: async (options = {}) => {
338
+ logout: async (refreshTokenRequest, options = {}) => {
339
+ assertParamExists("logout", "refreshTokenRequest", refreshTokenRequest);
187
340
  const localVarPath = `/auth/logout`;
188
341
  const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
189
342
  let baseOptions;
@@ -194,10 +347,12 @@ var AuthApiAxiosParamCreator = function(configuration) {
194
347
  const localVarHeaderParameter = {};
195
348
  const localVarQueryParameter = {};
196
349
  await setBearerAuthToObject(localVarHeaderParameter, configuration);
350
+ localVarHeaderParameter["Content-Type"] = "application/json";
197
351
  localVarHeaderParameter["Accept"] = "application/json";
198
352
  setSearchParams(localVarUrlObj, localVarQueryParameter);
199
353
  let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
200
354
  localVarRequestOptions.headers = { ...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers };
355
+ localVarRequestOptions.data = serializeDataIfNeeded(refreshTokenRequest, localVarRequestOptions, configuration);
201
356
  return {
202
357
  url: toPathString(localVarUrlObj),
203
358
  options: localVarRequestOptions
@@ -206,10 +361,12 @@ var AuthApiAxiosParamCreator = function(configuration) {
206
361
  /**
207
362
  * Issues a new access token using a valid refresh token. Rotate refresh tokens on each call.
208
363
  * @summary Refresh access token
364
+ * @param {RefreshTokenRequest} refreshTokenRequest
209
365
  * @param {*} [options] Override http request option.
210
366
  * @throws {RequiredError}
211
367
  */
212
- refreshToken: async (options = {}) => {
368
+ refreshToken: async (refreshTokenRequest, options = {}) => {
369
+ assertParamExists("refreshToken", "refreshTokenRequest", refreshTokenRequest);
213
370
  const localVarPath = `/auth/refresh-token`;
214
371
  const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
215
372
  let baseOptions;
@@ -220,10 +377,12 @@ var AuthApiAxiosParamCreator = function(configuration) {
220
377
  const localVarHeaderParameter = {};
221
378
  const localVarQueryParameter = {};
222
379
  await setBearerAuthToObject(localVarHeaderParameter, configuration);
380
+ localVarHeaderParameter["Content-Type"] = "application/json";
223
381
  localVarHeaderParameter["Accept"] = "application/json";
224
382
  setSearchParams(localVarUrlObj, localVarQueryParameter);
225
383
  let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
226
384
  localVarRequestOptions.headers = { ...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers };
385
+ localVarRequestOptions.data = serializeDataIfNeeded(refreshTokenRequest, localVarRequestOptions, configuration);
227
386
  return {
228
387
  url: toPathString(localVarUrlObj),
229
388
  options: localVarRequestOptions
@@ -363,7 +522,7 @@ var AuthApiFp = function(configuration) {
363
522
  const localVarAxiosArgs = await localVarAxiosParamCreator.getSession(options);
364
523
  const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
365
524
  const localVarOperationServerBasePath = operationServerMap["AuthApi.getSession"]?.[localVarOperationServerIndex]?.url;
366
- return (axios2, basePath) => createRequestFunction(localVarAxiosArgs, import_axios2.default, BASE_PATH, configuration)(axios2, localVarOperationServerBasePath || basePath);
525
+ return (axios3, basePath) => createRequestFunction(localVarAxiosArgs, import_axios3.default, BASE_PATH, configuration)(axios3, localVarOperationServerBasePath || basePath);
367
526
  },
368
527
  /**
369
528
  * Authenticates a user with email and password. Returns an access token and refresh token on success.
@@ -376,31 +535,33 @@ var AuthApiFp = function(configuration) {
376
535
  const localVarAxiosArgs = await localVarAxiosParamCreator.login(loginRequest, options);
377
536
  const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
378
537
  const localVarOperationServerBasePath = operationServerMap["AuthApi.login"]?.[localVarOperationServerIndex]?.url;
379
- return (axios2, basePath) => createRequestFunction(localVarAxiosArgs, import_axios2.default, BASE_PATH, configuration)(axios2, localVarOperationServerBasePath || basePath);
538
+ return (axios3, basePath) => createRequestFunction(localVarAxiosArgs, import_axios3.default, BASE_PATH, configuration)(axios3, localVarOperationServerBasePath || basePath);
380
539
  },
381
540
  /**
382
541
  * Invalidates the current session and refresh token. The client should discard stored tokens.
383
542
  * @summary Logout
543
+ * @param {RefreshTokenRequest} refreshTokenRequest
384
544
  * @param {*} [options] Override http request option.
385
545
  * @throws {RequiredError}
386
546
  */
387
- async logout(options) {
388
- const localVarAxiosArgs = await localVarAxiosParamCreator.logout(options);
547
+ async logout(refreshTokenRequest, options) {
548
+ const localVarAxiosArgs = await localVarAxiosParamCreator.logout(refreshTokenRequest, options);
389
549
  const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
390
550
  const localVarOperationServerBasePath = operationServerMap["AuthApi.logout"]?.[localVarOperationServerIndex]?.url;
391
- return (axios2, basePath) => createRequestFunction(localVarAxiosArgs, import_axios2.default, BASE_PATH, configuration)(axios2, localVarOperationServerBasePath || basePath);
551
+ return (axios3, basePath) => createRequestFunction(localVarAxiosArgs, import_axios3.default, BASE_PATH, configuration)(axios3, localVarOperationServerBasePath || basePath);
392
552
  },
393
553
  /**
394
554
  * Issues a new access token using a valid refresh token. Rotate refresh tokens on each call.
395
555
  * @summary Refresh access token
556
+ * @param {RefreshTokenRequest} refreshTokenRequest
396
557
  * @param {*} [options] Override http request option.
397
558
  * @throws {RequiredError}
398
559
  */
399
- async refreshToken(options) {
400
- const localVarAxiosArgs = await localVarAxiosParamCreator.refreshToken(options);
560
+ async refreshToken(refreshTokenRequest, options) {
561
+ const localVarAxiosArgs = await localVarAxiosParamCreator.refreshToken(refreshTokenRequest, options);
401
562
  const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
402
563
  const localVarOperationServerBasePath = operationServerMap["AuthApi.refreshToken"]?.[localVarOperationServerIndex]?.url;
403
- return (axios2, basePath) => createRequestFunction(localVarAxiosArgs, import_axios2.default, BASE_PATH, configuration)(axios2, localVarOperationServerBasePath || basePath);
564
+ return (axios3, basePath) => createRequestFunction(localVarAxiosArgs, import_axios3.default, BASE_PATH, configuration)(axios3, localVarOperationServerBasePath || basePath);
404
565
  },
405
566
  /**
406
567
  * Creates a new user account. Sends a verification email upon successful registration.
@@ -413,7 +574,7 @@ var AuthApiFp = function(configuration) {
413
574
  const localVarAxiosArgs = await localVarAxiosParamCreator.register(registerRequest, options);
414
575
  const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
415
576
  const localVarOperationServerBasePath = operationServerMap["AuthApi.register"]?.[localVarOperationServerIndex]?.url;
416
- return (axios2, basePath) => createRequestFunction(localVarAxiosArgs, import_axios2.default, BASE_PATH, configuration)(axios2, localVarOperationServerBasePath || basePath);
577
+ return (axios3, basePath) => createRequestFunction(localVarAxiosArgs, import_axios3.default, BASE_PATH, configuration)(axios3, localVarOperationServerBasePath || basePath);
417
578
  },
418
579
  /**
419
580
  * Validates the reset token from the email link and renders the password reset form.
@@ -426,7 +587,7 @@ var AuthApiFp = function(configuration) {
426
587
  const localVarAxiosArgs = await localVarAxiosParamCreator.renderResetForm(token, options);
427
588
  const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
428
589
  const localVarOperationServerBasePath = operationServerMap["AuthApi.renderResetForm"]?.[localVarOperationServerIndex]?.url;
429
- return (axios2, basePath) => createRequestFunction(localVarAxiosArgs, import_axios2.default, BASE_PATH, configuration)(axios2, localVarOperationServerBasePath || basePath);
590
+ return (axios3, basePath) => createRequestFunction(localVarAxiosArgs, import_axios3.default, BASE_PATH, configuration)(axios3, localVarOperationServerBasePath || basePath);
430
591
  },
431
592
  /**
432
593
  * Sends a password reset link to the provided email address if an account exists.
@@ -439,7 +600,7 @@ var AuthApiFp = function(configuration) {
439
600
  const localVarAxiosArgs = await localVarAxiosParamCreator.requestPasswordReset(emailRequest, options);
440
601
  const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
441
602
  const localVarOperationServerBasePath = operationServerMap["AuthApi.requestPasswordReset"]?.[localVarOperationServerIndex]?.url;
442
- return (axios2, basePath) => createRequestFunction(localVarAxiosArgs, import_axios2.default, BASE_PATH, configuration)(axios2, localVarOperationServerBasePath || basePath);
603
+ return (axios3, basePath) => createRequestFunction(localVarAxiosArgs, import_axios3.default, BASE_PATH, configuration)(axios3, localVarOperationServerBasePath || basePath);
443
604
  },
444
605
  /**
445
606
  * Submits a new password using a valid reset token. Invalidates the token after use.
@@ -452,7 +613,7 @@ var AuthApiFp = function(configuration) {
452
613
  const localVarAxiosArgs = await localVarAxiosParamCreator.submitNewPassword(resetPasswordRequest, options);
453
614
  const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
454
615
  const localVarOperationServerBasePath = operationServerMap["AuthApi.submitNewPassword"]?.[localVarOperationServerIndex]?.url;
455
- return (axios2, basePath) => createRequestFunction(localVarAxiosArgs, import_axios2.default, BASE_PATH, configuration)(axios2, localVarOperationServerBasePath || basePath);
616
+ return (axios3, basePath) => createRequestFunction(localVarAxiosArgs, import_axios3.default, BASE_PATH, configuration)(axios3, localVarOperationServerBasePath || basePath);
456
617
  }
457
618
  };
458
619
  };
@@ -479,20 +640,22 @@ var AuthApi = class extends BaseAPI {
479
640
  /**
480
641
  * Invalidates the current session and refresh token. The client should discard stored tokens.
481
642
  * @summary Logout
643
+ * @param {RefreshTokenRequest} refreshTokenRequest
482
644
  * @param {*} [options] Override http request option.
483
645
  * @throws {RequiredError}
484
646
  */
485
- logout(options) {
486
- return AuthApiFp(this.configuration).logout(options).then((request) => request(this.axios, this.basePath));
647
+ logout(refreshTokenRequest, options) {
648
+ return AuthApiFp(this.configuration).logout(refreshTokenRequest, options).then((request) => request(this.axios, this.basePath));
487
649
  }
488
650
  /**
489
651
  * Issues a new access token using a valid refresh token. Rotate refresh tokens on each call.
490
652
  * @summary Refresh access token
653
+ * @param {RefreshTokenRequest} refreshTokenRequest
491
654
  * @param {*} [options] Override http request option.
492
655
  * @throws {RequiredError}
493
656
  */
494
- refreshToken(options) {
495
- return AuthApiFp(this.configuration).refreshToken(options).then((request) => request(this.axios, this.basePath));
657
+ refreshToken(refreshTokenRequest, options) {
658
+ return AuthApiFp(this.configuration).refreshToken(refreshTokenRequest, options).then((request) => request(this.axios, this.basePath));
496
659
  }
497
660
  /**
498
661
  * Creates a new user account. Sends a verification email upon successful registration.
@@ -537,7 +700,7 @@ var AuthApi = class extends BaseAPI {
537
700
  };
538
701
 
539
702
  // src/generated/api/email-api.ts
540
- var import_axios3 = __toESM(require("axios"), 1);
703
+ var import_axios4 = __toESM(require("axios"), 1);
541
704
  var EmailApiAxiosParamCreator = function(configuration) {
542
705
  return {
543
706
  /**
@@ -588,7 +751,7 @@ var EmailApiFp = function(configuration) {
588
751
  const localVarAxiosArgs = await localVarAxiosParamCreator.verifyEmail(token, options);
589
752
  const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
590
753
  const localVarOperationServerBasePath = operationServerMap["EmailApi.verifyEmail"]?.[localVarOperationServerIndex]?.url;
591
- return (axios2, basePath) => createRequestFunction(localVarAxiosArgs, import_axios3.default, BASE_PATH, configuration)(axios2, localVarOperationServerBasePath || basePath);
754
+ return (axios3, basePath) => createRequestFunction(localVarAxiosArgs, import_axios4.default, BASE_PATH, configuration)(axios3, localVarOperationServerBasePath || basePath);
592
755
  }
593
756
  };
594
757
  };
@@ -606,7 +769,7 @@ var EmailApi = class extends BaseAPI {
606
769
  };
607
770
 
608
771
  // src/generated/api/users-api.ts
609
- var import_axios4 = __toESM(require("axios"), 1);
772
+ var import_axios5 = __toESM(require("axios"), 1);
610
773
  var UsersApiAxiosParamCreator = function(configuration) {
611
774
  return {
612
775
  /**
@@ -650,7 +813,7 @@ var UsersApiFp = function(configuration) {
650
813
  const localVarAxiosArgs = await localVarAxiosParamCreator.findUser(options);
651
814
  const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
652
815
  const localVarOperationServerBasePath = operationServerMap["UsersApi.findUser"]?.[localVarOperationServerIndex]?.url;
653
- return (axios2, basePath) => createRequestFunction(localVarAxiosArgs, import_axios4.default, BASE_PATH, configuration)(axios2, localVarOperationServerBasePath || basePath);
816
+ return (axios3, basePath) => createRequestFunction(localVarAxiosArgs, import_axios5.default, BASE_PATH, configuration)(axios3, localVarOperationServerBasePath || basePath);
654
817
  }
655
818
  };
656
819
  };
@@ -750,94 +913,46 @@ var Configuration = class {
750
913
  }
751
914
  };
752
915
 
753
- // src/http/jwt_interceptor.ts
754
- var JwtInterceptor = class {
755
- apply(axiosInstance, options) {
756
- const REFRESH_URI = "/auth/refresh-token";
757
- axiosInstance.interceptors.request.use(
758
- (config) => {
759
- const accessToken = options?.getToken();
760
- if (!config.url?.includes(REFRESH_URI) && accessToken) {
761
- config.headers.Authorization = `Bearer ${accessToken}`;
762
- }
763
- return config;
764
- },
765
- (error) => {
766
- console.error("Request error:", error);
767
- return Promise.reject(error);
768
- }
769
- );
770
- axiosInstance.interceptors.response.use(
771
- (response) => response,
772
- async (error) => {
773
- const originalRequest = error.config;
774
- if (error.response?.status === 401 && !originalRequest._retry && !originalRequest.url?.includes(REFRESH_URI)) {
775
- originalRequest._retry = true;
776
- try {
777
- const refreshToken = options?.getRefreshToken();
778
- const response = await axiosInstance.post(
779
- REFRESH_URI,
780
- {},
781
- { headers: { "x-refresh-token": `Bearer ${refreshToken}` } }
782
- );
783
- const auth_response = response.data;
784
- if (auth_response.tokens) {
785
- options?.onTokenRefresh?.(auth_response.tokens);
786
- }
787
- originalRequest.headers.Authorization = `Bearer ${auth_response.tokens?.access}`;
788
- return axiosInstance(originalRequest);
789
- } catch (e) {
790
- options?.onSessionExpired?.();
791
- return Promise.reject(e);
792
- }
793
- }
794
- return Promise.reject(error);
795
- }
796
- );
797
- }
798
- };
799
-
800
916
  // src/index.ts
801
- function Anzar(anzarConfig, options) {
802
- const basePath = anzarConfig.api_url;
803
- const configuration = new Configuration({ basePath });
804
- const axiosInstance = import_axios5.default.create({
805
- baseURL: basePath,
806
- withCredentials: true,
807
- headers: {
808
- "Content-Type": "application/json",
809
- Accept: "application/json"
917
+ var DEFAULT_OPTIONS = {
918
+ storage: new MemoryStorage()
919
+ };
920
+ var Anzar = class {
921
+ Auth;
922
+ User;
923
+ Email;
924
+ constructor(anzarConfig, options = DEFAULT_OPTIONS) {
925
+ const basePath = anzarConfig.api_url;
926
+ const axiosInstance = this.createAxiosInstance(basePath);
927
+ const configuration = new Configuration({ basePath });
928
+ if (anzarConfig.auth?.strategy === "Jwt" /* Jwt */) {
929
+ new JwtInterceptor().apply(axiosInstance, options);
810
930
  }
811
- });
812
- if (anzarConfig.auth?.strategy === "Jwt" /* Jwt */) {
813
- new JwtInterceptor().apply(axiosInstance, options);
931
+ const apis = this.createApis(configuration, basePath, axiosInstance);
932
+ this.Auth = new AuthModule(
933
+ apis.auth,
934
+ apis.user,
935
+ anzarConfig.auth?.strategy ?? "Session" /* Session */,
936
+ options
937
+ );
938
+ this.User = apis.user;
939
+ this.Email = apis.email;
814
940
  }
815
- const generatedAuthApi = new AuthApi(configuration, basePath, axiosInstance);
816
- const generatedUserApi = new UsersApi(configuration, basePath, axiosInstance);
817
- return {
818
- Auth: {
819
- login: (body) => generatedAuthApi.login(body),
820
- register: (body) => generatedAuthApi.register(body),
821
- logout: async () => {
822
- await generatedAuthApi.logout();
823
- options?.onLogout?.();
824
- },
825
- resetPassword: (body) => {
826
- generatedAuthApi.requestPasswordReset(body);
827
- },
828
- ...anzarConfig.auth?.strategy === "Session" /* Session */ && {
829
- session: () => generatedAuthApi.getSession()
830
- },
831
- isAuthenticated: async () => {
832
- try {
833
- const response = await generatedUserApi.findUser();
834
- return !!response.data;
835
- } catch {
836
- return false;
837
- }
941
+ createAxiosInstance(baseURL) {
942
+ return import_axios6.default.create({
943
+ baseURL,
944
+ withCredentials: true,
945
+ headers: {
946
+ "Content-Type": "application/json",
947
+ Accept: "application/json"
838
948
  }
839
- },
840
- User: generatedUserApi,
841
- Email: new EmailApi(configuration, basePath, axiosInstance)
842
- };
843
- }
949
+ });
950
+ }
951
+ createApis(configuration, basePath, axiosInstance) {
952
+ return {
953
+ auth: new AuthApi(configuration, basePath, axiosInstance),
954
+ user: new UsersApi(configuration, basePath, axiosInstance),
955
+ email: new EmailApi(configuration, basePath, axiosInstance)
956
+ };
957
+ }
958
+ };