anzar 1.2.8 → 1.2.10

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,135 @@ 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
+ login(body) {
72
+ return this.authApi.login(body);
73
+ }
74
+ register(body) {
75
+ return this.authApi.register(body);
76
+ }
77
+ async logout() {
78
+ await this.authApi.logout();
79
+ this.options?.storage.onLogout?.();
80
+ }
81
+ resetPassword(body) {
82
+ this.authApi.requestPasswordReset(body);
83
+ }
84
+ async isAuthenticated() {
85
+ try {
86
+ const response = await this.userApi.findUser();
87
+ return !!response.data.username;
88
+ } catch (error) {
89
+ if (import_axios.default.isAxiosError(error) && error.response?.status === 401) {
90
+ return false;
91
+ }
92
+ throw false;
93
+ }
94
+ }
95
+ session() {
96
+ if (this.strategy !== "Session" /* Session */) {
97
+ throw new Error("session() is only available with Session auth strategy");
98
+ }
99
+ return this.authApi.getSession();
100
+ }
101
+ };
102
+
103
+ // src/api/interceptor.ts
104
+ var JwtInterceptor = class {
105
+ apply(axiosInstance, options) {
106
+ const REFRESH_URI = "/auth/refresh-token";
107
+ axiosInstance.interceptors.request.use(
108
+ (config) => {
109
+ const accessToken = options?.storage.getToken();
110
+ if (!config.url?.includes(REFRESH_URI) && accessToken) {
111
+ config.headers.Authorization = `Bearer ${accessToken}`;
112
+ }
113
+ return config;
114
+ },
115
+ (error) => {
116
+ console.error("Request error:", error);
117
+ return Promise.reject(error);
118
+ }
119
+ );
120
+ axiosInstance.interceptors.response.use(
121
+ (response) => response,
122
+ async (error) => {
123
+ const originalRequest = error.config;
124
+ if (error.response?.status === 401 && !originalRequest._retry && !originalRequest.url?.includes(REFRESH_URI)) {
125
+ originalRequest._retry = true;
126
+ try {
127
+ const refreshToken = options?.storage.getRefreshToken();
128
+ const response = await axiosInstance.post(
129
+ REFRESH_URI,
130
+ {},
131
+ { headers: { "x-refresh-token": `Bearer ${refreshToken}` } }
132
+ );
133
+ const auth_response = response.data;
134
+ if (auth_response.tokens) {
135
+ options?.storage.onTokenRefresh?.(auth_response.tokens);
136
+ }
137
+ originalRequest.headers.Authorization = `Bearer ${auth_response.tokens?.access}`;
138
+ return axiosInstance(originalRequest);
139
+ } catch (e) {
140
+ options?.storage.onSessionExpired?.();
141
+ return Promise.reject(e);
142
+ }
143
+ }
144
+ return Promise.reject(error);
145
+ }
146
+ );
147
+ }
148
+ };
37
149
 
38
150
  // src/generated/api/auth-api.ts
39
- var import_axios2 = __toESM(require("axios"), 1);
151
+ var import_axios3 = __toESM(require("axios"), 1);
40
152
 
41
153
  // src/generated/base.ts
42
- var import_axios = __toESM(require("axios"), 1);
154
+ var import_axios2 = __toESM(require("axios"), 1);
43
155
  var BASE_PATH = "http://localhost".replace(/\/+$/, "");
44
156
  var BaseAPI = class {
45
- constructor(configuration, basePath = BASE_PATH, axios2 = import_axios.default) {
157
+ constructor(configuration, basePath = BASE_PATH, axios3 = import_axios2.default) {
46
158
  this.basePath = basePath;
47
- this.axios = axios2;
159
+ this.axios = axios3;
48
160
  if (configuration) {
49
161
  this.configuration = configuration;
50
162
  this.basePath = configuration.basePath ?? basePath;
@@ -113,9 +225,9 @@ var toPathString = function(url) {
113
225
  return url.pathname + url.search + url.hash;
114
226
  };
115
227
  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);
228
+ return (axios3 = globalAxios5, basePath = BASE_PATH2) => {
229
+ const axiosRequestArgs = { ...axiosArgs.options, url: (axios3.defaults.baseURL ? "" : configuration?.basePath ?? basePath) + axiosArgs.url };
230
+ return axios3.request(axiosRequestArgs);
119
231
  };
120
232
  };
121
233
 
@@ -363,7 +475,7 @@ var AuthApiFp = function(configuration) {
363
475
  const localVarAxiosArgs = await localVarAxiosParamCreator.getSession(options);
364
476
  const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
365
477
  const localVarOperationServerBasePath = operationServerMap["AuthApi.getSession"]?.[localVarOperationServerIndex]?.url;
366
- return (axios2, basePath) => createRequestFunction(localVarAxiosArgs, import_axios2.default, BASE_PATH, configuration)(axios2, localVarOperationServerBasePath || basePath);
478
+ return (axios3, basePath) => createRequestFunction(localVarAxiosArgs, import_axios3.default, BASE_PATH, configuration)(axios3, localVarOperationServerBasePath || basePath);
367
479
  },
368
480
  /**
369
481
  * Authenticates a user with email and password. Returns an access token and refresh token on success.
@@ -376,7 +488,7 @@ var AuthApiFp = function(configuration) {
376
488
  const localVarAxiosArgs = await localVarAxiosParamCreator.login(loginRequest, options);
377
489
  const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
378
490
  const localVarOperationServerBasePath = operationServerMap["AuthApi.login"]?.[localVarOperationServerIndex]?.url;
379
- return (axios2, basePath) => createRequestFunction(localVarAxiosArgs, import_axios2.default, BASE_PATH, configuration)(axios2, localVarOperationServerBasePath || basePath);
491
+ return (axios3, basePath) => createRequestFunction(localVarAxiosArgs, import_axios3.default, BASE_PATH, configuration)(axios3, localVarOperationServerBasePath || basePath);
380
492
  },
381
493
  /**
382
494
  * Invalidates the current session and refresh token. The client should discard stored tokens.
@@ -388,7 +500,7 @@ var AuthApiFp = function(configuration) {
388
500
  const localVarAxiosArgs = await localVarAxiosParamCreator.logout(options);
389
501
  const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
390
502
  const localVarOperationServerBasePath = operationServerMap["AuthApi.logout"]?.[localVarOperationServerIndex]?.url;
391
- return (axios2, basePath) => createRequestFunction(localVarAxiosArgs, import_axios2.default, BASE_PATH, configuration)(axios2, localVarOperationServerBasePath || basePath);
503
+ return (axios3, basePath) => createRequestFunction(localVarAxiosArgs, import_axios3.default, BASE_PATH, configuration)(axios3, localVarOperationServerBasePath || basePath);
392
504
  },
393
505
  /**
394
506
  * Issues a new access token using a valid refresh token. Rotate refresh tokens on each call.
@@ -400,7 +512,7 @@ var AuthApiFp = function(configuration) {
400
512
  const localVarAxiosArgs = await localVarAxiosParamCreator.refreshToken(options);
401
513
  const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
402
514
  const localVarOperationServerBasePath = operationServerMap["AuthApi.refreshToken"]?.[localVarOperationServerIndex]?.url;
403
- return (axios2, basePath) => createRequestFunction(localVarAxiosArgs, import_axios2.default, BASE_PATH, configuration)(axios2, localVarOperationServerBasePath || basePath);
515
+ return (axios3, basePath) => createRequestFunction(localVarAxiosArgs, import_axios3.default, BASE_PATH, configuration)(axios3, localVarOperationServerBasePath || basePath);
404
516
  },
405
517
  /**
406
518
  * Creates a new user account. Sends a verification email upon successful registration.
@@ -413,7 +525,7 @@ var AuthApiFp = function(configuration) {
413
525
  const localVarAxiosArgs = await localVarAxiosParamCreator.register(registerRequest, options);
414
526
  const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
415
527
  const localVarOperationServerBasePath = operationServerMap["AuthApi.register"]?.[localVarOperationServerIndex]?.url;
416
- return (axios2, basePath) => createRequestFunction(localVarAxiosArgs, import_axios2.default, BASE_PATH, configuration)(axios2, localVarOperationServerBasePath || basePath);
528
+ return (axios3, basePath) => createRequestFunction(localVarAxiosArgs, import_axios3.default, BASE_PATH, configuration)(axios3, localVarOperationServerBasePath || basePath);
417
529
  },
418
530
  /**
419
531
  * Validates the reset token from the email link and renders the password reset form.
@@ -426,7 +538,7 @@ var AuthApiFp = function(configuration) {
426
538
  const localVarAxiosArgs = await localVarAxiosParamCreator.renderResetForm(token, options);
427
539
  const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
428
540
  const localVarOperationServerBasePath = operationServerMap["AuthApi.renderResetForm"]?.[localVarOperationServerIndex]?.url;
429
- return (axios2, basePath) => createRequestFunction(localVarAxiosArgs, import_axios2.default, BASE_PATH, configuration)(axios2, localVarOperationServerBasePath || basePath);
541
+ return (axios3, basePath) => createRequestFunction(localVarAxiosArgs, import_axios3.default, BASE_PATH, configuration)(axios3, localVarOperationServerBasePath || basePath);
430
542
  },
431
543
  /**
432
544
  * Sends a password reset link to the provided email address if an account exists.
@@ -439,7 +551,7 @@ var AuthApiFp = function(configuration) {
439
551
  const localVarAxiosArgs = await localVarAxiosParamCreator.requestPasswordReset(emailRequest, options);
440
552
  const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
441
553
  const localVarOperationServerBasePath = operationServerMap["AuthApi.requestPasswordReset"]?.[localVarOperationServerIndex]?.url;
442
- return (axios2, basePath) => createRequestFunction(localVarAxiosArgs, import_axios2.default, BASE_PATH, configuration)(axios2, localVarOperationServerBasePath || basePath);
554
+ return (axios3, basePath) => createRequestFunction(localVarAxiosArgs, import_axios3.default, BASE_PATH, configuration)(axios3, localVarOperationServerBasePath || basePath);
443
555
  },
444
556
  /**
445
557
  * Submits a new password using a valid reset token. Invalidates the token after use.
@@ -452,7 +564,7 @@ var AuthApiFp = function(configuration) {
452
564
  const localVarAxiosArgs = await localVarAxiosParamCreator.submitNewPassword(resetPasswordRequest, options);
453
565
  const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
454
566
  const localVarOperationServerBasePath = operationServerMap["AuthApi.submitNewPassword"]?.[localVarOperationServerIndex]?.url;
455
- return (axios2, basePath) => createRequestFunction(localVarAxiosArgs, import_axios2.default, BASE_PATH, configuration)(axios2, localVarOperationServerBasePath || basePath);
567
+ return (axios3, basePath) => createRequestFunction(localVarAxiosArgs, import_axios3.default, BASE_PATH, configuration)(axios3, localVarOperationServerBasePath || basePath);
456
568
  }
457
569
  };
458
570
  };
@@ -537,7 +649,7 @@ var AuthApi = class extends BaseAPI {
537
649
  };
538
650
 
539
651
  // src/generated/api/email-api.ts
540
- var import_axios3 = __toESM(require("axios"), 1);
652
+ var import_axios4 = __toESM(require("axios"), 1);
541
653
  var EmailApiAxiosParamCreator = function(configuration) {
542
654
  return {
543
655
  /**
@@ -588,7 +700,7 @@ var EmailApiFp = function(configuration) {
588
700
  const localVarAxiosArgs = await localVarAxiosParamCreator.verifyEmail(token, options);
589
701
  const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
590
702
  const localVarOperationServerBasePath = operationServerMap["EmailApi.verifyEmail"]?.[localVarOperationServerIndex]?.url;
591
- return (axios2, basePath) => createRequestFunction(localVarAxiosArgs, import_axios3.default, BASE_PATH, configuration)(axios2, localVarOperationServerBasePath || basePath);
703
+ return (axios3, basePath) => createRequestFunction(localVarAxiosArgs, import_axios4.default, BASE_PATH, configuration)(axios3, localVarOperationServerBasePath || basePath);
592
704
  }
593
705
  };
594
706
  };
@@ -606,7 +718,7 @@ var EmailApi = class extends BaseAPI {
606
718
  };
607
719
 
608
720
  // src/generated/api/users-api.ts
609
- var import_axios4 = __toESM(require("axios"), 1);
721
+ var import_axios5 = __toESM(require("axios"), 1);
610
722
  var UsersApiAxiosParamCreator = function(configuration) {
611
723
  return {
612
724
  /**
@@ -650,7 +762,7 @@ var UsersApiFp = function(configuration) {
650
762
  const localVarAxiosArgs = await localVarAxiosParamCreator.findUser(options);
651
763
  const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
652
764
  const localVarOperationServerBasePath = operationServerMap["UsersApi.findUser"]?.[localVarOperationServerIndex]?.url;
653
- return (axios2, basePath) => createRequestFunction(localVarAxiosArgs, import_axios4.default, BASE_PATH, configuration)(axios2, localVarOperationServerBasePath || basePath);
765
+ return (axios3, basePath) => createRequestFunction(localVarAxiosArgs, import_axios5.default, BASE_PATH, configuration)(axios3, localVarOperationServerBasePath || basePath);
654
766
  }
655
767
  };
656
768
  };
@@ -750,94 +862,46 @@ var Configuration = class {
750
862
  }
751
863
  };
752
864
 
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
865
  // 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"
866
+ var DEFAULT_OPTIONS = {
867
+ storage: new MemoryStorage()
868
+ };
869
+ var Anzar = class {
870
+ Auth;
871
+ User;
872
+ Email;
873
+ constructor(anzarConfig, options = DEFAULT_OPTIONS) {
874
+ const basePath = anzarConfig.api_url;
875
+ const axiosInstance = this.createAxiosInstance(basePath);
876
+ const configuration = new Configuration({ basePath });
877
+ if (anzarConfig.auth?.strategy === "Jwt" /* Jwt */) {
878
+ new JwtInterceptor().apply(axiosInstance, options);
810
879
  }
811
- });
812
- if (anzarConfig.auth?.strategy === "Jwt" /* Jwt */) {
813
- new JwtInterceptor().apply(axiosInstance, options);
880
+ const apis = this.createApis(configuration, basePath, axiosInstance);
881
+ this.Auth = new AuthModule(
882
+ apis.auth,
883
+ apis.user,
884
+ anzarConfig.auth?.strategy ?? "Session" /* Session */,
885
+ options
886
+ );
887
+ this.User = apis.user;
888
+ this.Email = apis.email;
814
889
  }
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
- }
890
+ createAxiosInstance(baseURL) {
891
+ return import_axios6.default.create({
892
+ baseURL,
893
+ withCredentials: true,
894
+ headers: {
895
+ "Content-Type": "application/json",
896
+ Accept: "application/json"
838
897
  }
839
- },
840
- User: generatedUserApi,
841
- Email: new EmailApi(configuration, basePath, axiosInstance)
842
- };
843
- }
898
+ });
899
+ }
900
+ createApis(configuration, basePath, axiosInstance) {
901
+ return {
902
+ auth: new AuthApi(configuration, basePath, axiosInstance),
903
+ user: new UsersApi(configuration, basePath, axiosInstance),
904
+ email: new EmailApi(configuration, basePath, axiosInstance)
905
+ };
906
+ }
907
+ };
package/dist/index.d.cts CHANGED
@@ -1,5 +1,6 @@
1
1
  import * as axios from 'axios';
2
- import { AxiosInstance, RawAxiosRequestConfig } from 'axios';
2
+ import { AxiosInstance, RawAxiosRequestConfig, AxiosResponse } from 'axios';
3
+ import { S as SessionTokens, B as BaseStorage } from './base_storage-CQKHFbrb.cjs';
3
4
 
4
5
  /**
5
6
  * Anzar Software API
@@ -118,22 +119,6 @@ declare class BaseAPI {
118
119
  constructor(configuration?: Configuration, basePath?: string, axios?: AxiosInstance);
119
120
  }
120
121
 
121
- /**
122
- * Anzar Software API
123
- * REST API for the Anzar platform. All protected routes require a Bearer token.
124
- *
125
- * The version of the OpenAPI document: 0.6.2
126
- * Contact: dev@anzar.io
127
- *
128
- * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
129
- * https://openapi-generator.tech
130
- * Do not edit the class manually.
131
- */
132
- interface SessionTokens {
133
- 'access': string;
134
- 'refresh': string;
135
- }
136
-
137
122
  /**
138
123
  * Anzar Software API
139
124
  * REST API for the Anzar platform. All protected routes require a Bearer token.
@@ -257,6 +242,39 @@ interface RegisterRequest {
257
242
  'username': string;
258
243
  }
259
244
 
245
+ /**
246
+ * Anzar Software API
247
+ * REST API for the Anzar platform. All protected routes require a Bearer token.
248
+ *
249
+ * The version of the OpenAPI document: 0.6.2
250
+ * Contact: dev@anzar.io
251
+ *
252
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
253
+ * https://openapi-generator.tech
254
+ * Do not edit the class manually.
255
+ */
256
+ interface ResetLink {
257
+ 'expires_at': string;
258
+ 'link': string;
259
+ }
260
+
261
+ /**
262
+ * Anzar Software API
263
+ * REST API for the Anzar platform. All protected routes require a Bearer token.
264
+ *
265
+ * The version of the OpenAPI document: 0.6.2
266
+ * Contact: dev@anzar.io
267
+ *
268
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
269
+ * https://openapi-generator.tech
270
+ * Do not edit the class manually.
271
+ */
272
+ interface ResetPasswordRequest {
273
+ 'csrf_token': string;
274
+ 'password': string;
275
+ 'token': string;
276
+ }
277
+
260
278
  /**
261
279
  * Anzar Software API
262
280
  * REST API for the Anzar platform. All protected routes require a Bearer token.
@@ -292,6 +310,73 @@ interface TokenQuery {
292
310
  'token': string;
293
311
  }
294
312
 
313
+ /**
314
+ * AuthApi - object-oriented interface
315
+ */
316
+ declare class AuthApi extends BaseAPI {
317
+ /**
318
+ * Returns the currently authenticated user\'s session data. Requires a valid Bearer token.
319
+ * @summary Get current session
320
+ * @param {*} [options] Override http request option.
321
+ * @throws {RequiredError}
322
+ */
323
+ getSession(options?: RawAxiosRequestConfig): Promise<axios.AxiosResponse<Session, any, {}>>;
324
+ /**
325
+ * Authenticates a user with email and password. Returns an access token and refresh token on success.
326
+ * @summary User login
327
+ * @param {LoginRequest} loginRequest User login credentials
328
+ * @param {*} [options] Override http request option.
329
+ * @throws {RequiredError}
330
+ */
331
+ login(loginRequest: LoginRequest, options?: RawAxiosRequestConfig): Promise<axios.AxiosResponse<AuthResponse, any, {}>>;
332
+ /**
333
+ * Invalidates the current session and refresh token. The client should discard stored tokens.
334
+ * @summary Logout
335
+ * @param {*} [options] Override http request option.
336
+ * @throws {RequiredError}
337
+ */
338
+ logout(options?: RawAxiosRequestConfig): Promise<axios.AxiosResponse<void, any, {}>>;
339
+ /**
340
+ * Issues a new access token using a valid refresh token. Rotate refresh tokens on each call.
341
+ * @summary Refresh access token
342
+ * @param {*} [options] Override http request option.
343
+ * @throws {RequiredError}
344
+ */
345
+ refreshToken(options?: RawAxiosRequestConfig): Promise<axios.AxiosResponse<AuthResponse, any, {}>>;
346
+ /**
347
+ * Creates a new user account. Sends a verification email upon successful registration.
348
+ * @summary Register a new user
349
+ * @param {RegisterRequest} registerRequest User register credentials
350
+ * @param {*} [options] Override http request option.
351
+ * @throws {RequiredError}
352
+ */
353
+ register(registerRequest: RegisterRequest, options?: RawAxiosRequestConfig): Promise<axios.AxiosResponse<AuthResponse, any, {}>>;
354
+ /**
355
+ * Validates the reset token from the email link and renders the password reset form.
356
+ * @summary Render password reset form
357
+ * @param {TokenQuery} token Password reset token
358
+ * @param {*} [options] Override http request option.
359
+ * @throws {RequiredError}
360
+ */
361
+ renderResetForm(token: TokenQuery, options?: RawAxiosRequestConfig): Promise<axios.AxiosResponse<string, any, {}>>;
362
+ /**
363
+ * Sends a password reset link to the provided email address if an account exists.
364
+ * @summary Request a password reset
365
+ * @param {EmailRequest} emailRequest Email address to send the reset link to
366
+ * @param {*} [options] Override http request option.
367
+ * @throws {RequiredError}
368
+ */
369
+ requestPasswordReset(emailRequest: EmailRequest, options?: RawAxiosRequestConfig): Promise<axios.AxiosResponse<ResetLink, any, {}>>;
370
+ /**
371
+ * Submits a new password using a valid reset token. Invalidates the token after use.
372
+ * @summary Submit new password
373
+ * @param {ResetPasswordRequest} resetPasswordRequest Reset token and the new password
374
+ * @param {*} [options] Override http request option.
375
+ * @throws {RequiredError}
376
+ */
377
+ submitNewPassword(resetPasswordRequest: ResetPasswordRequest, options?: RawAxiosRequestConfig): Promise<axios.AxiosResponse<void, any, {}>>;
378
+ }
379
+
295
380
  /**
296
381
  * EmailApi - object-oriented interface
297
382
  */
@@ -390,24 +475,30 @@ type AnzarConfig = {
390
475
  };
391
476
 
392
477
  interface SdkOptions {
393
- getToken: () => string | null;
394
- getRefreshToken: () => string | null;
395
- onTokenRefresh?: (tokens: SessionTokens) => void;
396
- onSessionExpired?: () => void;
397
- onLogout?: () => void;
478
+ storage: BaseStorage;
398
479
  }
399
480
 
400
- declare function Anzar(anzarConfig: AnzarConfig, options?: SdkOptions): {
401
- Auth: {
402
- isAuthenticated: () => Promise<boolean>;
403
- session?: (() => Promise<axios.AxiosResponse<Session, any, {}>>) | undefined;
404
- login: (body: LoginRequest) => Promise<axios.AxiosResponse<AuthResponse, any, {}>>;
405
- register: (body: RegisterRequest) => Promise<axios.AxiosResponse<AuthResponse, any, {}>>;
406
- logout: () => Promise<void>;
407
- resetPassword: (body: EmailRequest) => void;
408
- };
481
+ declare class AuthModule {
482
+ private readonly authApi;
483
+ private readonly userApi;
484
+ private readonly strategy;
485
+ private readonly options?;
486
+ constructor(authApi: AuthApi, userApi: UsersApi, strategy: AuthStrategy, options?: SdkOptions | undefined);
487
+ login(body: LoginRequest): Promise<AxiosResponse<AuthResponse, any, {}>>;
488
+ register(body: RegisterRequest): Promise<AxiosResponse<AuthResponse, any, {}>>;
489
+ logout(): Promise<void>;
490
+ resetPassword(body: EmailRequest): void;
491
+ isAuthenticated(): Promise<boolean>;
492
+ session(): Promise<AxiosResponse<Session, any, {}>>;
493
+ }
494
+
495
+ declare class Anzar {
496
+ Auth: AuthModule;
409
497
  User: UsersApi;
410
498
  Email: EmailApi;
411
- };
499
+ constructor(anzarConfig: AnzarConfig, options?: SdkOptions);
500
+ private createAxiosInstance;
501
+ private createApis;
502
+ }
412
503
 
413
504
  export { Anzar };