whio-api-sdk 1.0.195-beta-staging → 1.0.196-beta-staging

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.
@@ -2,6 +2,10 @@ import { BaseClient } from './base-client';
2
2
  import { LoginCredentials, LoginResponse, PasswordChangeResponse, User } from '../types';
3
3
  export declare class AuthModule extends BaseClient {
4
4
  login(credentials: LoginCredentials): Promise<LoginResponse>;
5
+ requestLoginCode(email: string): Promise<{
6
+ message: string;
7
+ }>;
8
+ loginWithCode(email: string, code: string): Promise<LoginResponse>;
5
9
  logout(): Promise<void>;
6
10
  getProfile(): Promise<User>;
7
11
  changePassword(currentPassword: string, newPassword: string): Promise<PasswordChangeResponse>;
@@ -28,6 +28,29 @@ export class AuthModule extends BaseClient {
28
28
  }
29
29
  });
30
30
  }
31
+ requestLoginCode(email) {
32
+ return __awaiter(this, void 0, void 0, function* () {
33
+ return this.request('/auth/request-login-code', 'POST', { email }, {}, true);
34
+ });
35
+ }
36
+ loginWithCode(email, code) {
37
+ return __awaiter(this, void 0, void 0, function* () {
38
+ try {
39
+ const response = yield this.request('/auth/login-with-code', 'POST', { email, code }, {}, true);
40
+ this.accessToken = response.access_token;
41
+ this.refreshToken = response.refresh_token;
42
+ this.user = response.user;
43
+ yield this.storage.setItem('access_token', JSON.stringify(response.access_token));
44
+ yield this.storage.setItem('refresh_token', JSON.stringify(response.refresh_token));
45
+ yield this.storage.setItem('user', JSON.stringify(response.user));
46
+ return response;
47
+ }
48
+ catch (error) {
49
+ yield this.clearAuth();
50
+ throw error;
51
+ }
52
+ });
53
+ }
31
54
  logout() {
32
55
  return __awaiter(this, void 0, void 0, function* () {
33
56
  yield this.clearAuth();
@@ -34,6 +34,10 @@ export declare class ApiSDK extends BaseClient {
34
34
  getProfile(...args: Parameters<AuthModule['getProfile']>): Promise<import("./types").User>;
35
35
  changePassword(...args: Parameters<AuthModule['changePassword']>): Promise<import("./types").PasswordChangeResponse>;
36
36
  adminChangePassword(...args: Parameters<AuthModule['adminChangePassword']>): Promise<import("./types").PasswordChangeResponse>;
37
+ requestLoginCode(...args: Parameters<AuthModule['requestLoginCode']>): Promise<{
38
+ message: string;
39
+ }>;
40
+ loginWithCode(...args: Parameters<AuthModule['loginWithCode']>): Promise<import("./types").LoginResponse>;
37
41
  createUser(...args: Parameters<UserModule['createUser']>): Promise<import("./types").User>;
38
42
  assignEditorToRoleToUser(...args: Parameters<UserModule['assignEditorToRoleToUser']>): Promise<import("./types").User>;
39
43
  assignAdminToRoleToUser(...args: Parameters<UserModule['assignAdminToRoleToUser']>): Promise<import("./types").User>;
@@ -70,6 +70,16 @@ export class ApiSDK extends BaseClient {
70
70
  return this.auth.adminChangePassword(...args);
71
71
  });
72
72
  }
73
+ requestLoginCode(...args) {
74
+ return __awaiter(this, void 0, void 0, function* () {
75
+ return this.auth.requestLoginCode(...args);
76
+ });
77
+ }
78
+ loginWithCode(...args) {
79
+ return __awaiter(this, void 0, void 0, function* () {
80
+ return this.auth.loginWithCode(...args);
81
+ });
82
+ }
73
83
  // User methods
74
84
  createUser(...args) {
75
85
  return __awaiter(this, void 0, void 0, function* () {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "whio-api-sdk",
3
- "version": "1.0.195-beta-staging",
3
+ "version": "1.0.196-beta-staging",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",
@@ -27,6 +27,40 @@ export class AuthModule extends BaseClient {
27
27
  }
28
28
  }
29
29
 
30
+ public async requestLoginCode(email: string): Promise<{ message: string }> {
31
+ return this.request<{ message: string }>(
32
+ '/auth/request-login-code',
33
+ 'POST',
34
+ { email },
35
+ {},
36
+ true
37
+ );
38
+ }
39
+
40
+ public async loginWithCode(email: string, code: string): Promise<LoginResponse> {
41
+ try {
42
+ const response = await this.request<LoginResponse>(
43
+ '/auth/login-with-code',
44
+ 'POST',
45
+ { email, code },
46
+ {},
47
+ true
48
+ );
49
+ this.accessToken = response.access_token;
50
+ this.refreshToken = response.refresh_token;
51
+ this.user = response.user;
52
+
53
+ await this.storage!.setItem('access_token', JSON.stringify(response.access_token));
54
+ await this.storage!.setItem('refresh_token', JSON.stringify(response.refresh_token));
55
+ await this.storage!.setItem('user', JSON.stringify(response.user));
56
+
57
+ return response;
58
+ } catch (error) {
59
+ await this.clearAuth();
60
+ throw error;
61
+ }
62
+ }
63
+
30
64
  public async logout(): Promise<void> {
31
65
  await this.clearAuth();
32
66
  }
package/src/sdk/sdk.ts CHANGED
@@ -75,6 +75,14 @@ export class ApiSDK extends BaseClient {
75
75
  return this.auth.adminChangePassword(...args);
76
76
  }
77
77
 
78
+ public async requestLoginCode(...args: Parameters<AuthModule['requestLoginCode']>) {
79
+ return this.auth.requestLoginCode(...args);
80
+ }
81
+
82
+ public async loginWithCode(...args: Parameters<AuthModule['loginWithCode']>) {
83
+ return this.auth.loginWithCode(...args);
84
+ }
85
+
78
86
  // User methods
79
87
  public async createUser(...args: Parameters<UserModule['createUser']>) {
80
88
  return this.users.createUser(...args);