whio-api-sdk 1.1.29 → 1.1.34

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.
@@ -25,6 +25,30 @@ export declare class AuthModule extends BaseClient {
25
25
  * @returns The login response including access/refresh tokens and the user.
26
26
  */
27
27
  loginWithCode(email: string, code: string): Promise<LoginResponse>;
28
+ /**
29
+ * Authenticate with a Microsoft (Entra ID) token and persist the session.
30
+ *
31
+ * The client runs the Microsoft sign-in itself and passes the resulting Entra
32
+ * ID token here; the backend verifies it and mints the normal app session. The
33
+ * Microsoft identity must already be linked to a local account (see
34
+ * {@link connectEntra}) - an unlinked customer-app token is rejected.
35
+ *
36
+ * @param idToken - The Entra ID token obtained from the Microsoft sign-in.
37
+ * @returns The login response including access/refresh tokens and the user.
38
+ */
39
+ loginWithEntra(idToken: string): Promise<LoginResponse>;
40
+ /**
41
+ * Link the authenticated user's account to their Microsoft (Entra ID) identity
42
+ * so future {@link loginWithEntra} calls resolve them by their Microsoft oid.
43
+ *
44
+ * Requires an active session - the bearer token is attached automatically.
45
+ *
46
+ * @param idToken - The Entra ID token obtained from the Microsoft sign-in.
47
+ * @returns A confirmation message.
48
+ */
49
+ connectEntra(idToken: string): Promise<{
50
+ message: string;
51
+ }>;
28
52
  /**
29
53
  * Clear the current session and any persisted authentication state.
30
54
  *
@@ -60,6 +60,44 @@ export class AuthModule extends BaseClient {
60
60
  }
61
61
  });
62
62
  }
63
+ /**
64
+ * Authenticate with a Microsoft (Entra ID) token and persist the session.
65
+ *
66
+ * The client runs the Microsoft sign-in itself and passes the resulting Entra
67
+ * ID token here; the backend verifies it and mints the normal app session. The
68
+ * Microsoft identity must already be linked to a local account (see
69
+ * {@link connectEntra}) - an unlinked customer-app token is rejected.
70
+ *
71
+ * @param idToken - The Entra ID token obtained from the Microsoft sign-in.
72
+ * @returns The login response including access/refresh tokens and the user.
73
+ */
74
+ loginWithEntra(idToken) {
75
+ return __awaiter(this, void 0, void 0, function* () {
76
+ try {
77
+ const response = yield this.request(urls.entra, 'POST', { idToken }, {}, true);
78
+ yield this.updateAuthState(response);
79
+ return response;
80
+ }
81
+ catch (error) {
82
+ yield this.clearAuth();
83
+ throw error;
84
+ }
85
+ });
86
+ }
87
+ /**
88
+ * Link the authenticated user's account to their Microsoft (Entra ID) identity
89
+ * so future {@link loginWithEntra} calls resolve them by their Microsoft oid.
90
+ *
91
+ * Requires an active session - the bearer token is attached automatically.
92
+ *
93
+ * @param idToken - The Entra ID token obtained from the Microsoft sign-in.
94
+ * @returns A confirmation message.
95
+ */
96
+ connectEntra(idToken) {
97
+ return __awaiter(this, void 0, void 0, function* () {
98
+ return this.request(urls.entraConnect, 'POST', { idToken });
99
+ });
100
+ }
63
101
  /**
64
102
  * Clear the current session and any persisted authentication state.
65
103
  *
@@ -67,6 +67,7 @@ export class BaseClient {
67
67
  });
68
68
  }
69
69
  request(endpoint, method = 'GET', body, headers = {}, noToken = false) {
70
+ var _a;
70
71
  return __awaiter(this, void 0, void 0, function* () {
71
72
  const url = `${this.baseUrl}${endpoint}`;
72
73
  const defaultHeaders = {
@@ -79,14 +80,34 @@ export class BaseClient {
79
80
  defaultHeaders['Authorization'] = `Bearer ${token}`;
80
81
  }
81
82
  }
82
- const response = yield axios({
83
- url,
84
- method,
85
- headers: Object.assign(Object.assign({}, defaultHeaders), headers),
86
- data: body,
87
- timeout: 5000,
88
- });
89
- return response.data;
83
+ try {
84
+ const response = yield axios({
85
+ url,
86
+ method,
87
+ headers: Object.assign(Object.assign({}, defaultHeaders), headers),
88
+ data: body,
89
+ timeout: 5000,
90
+ });
91
+ return response.data;
92
+ }
93
+ catch (error) {
94
+ // Surface the server-provided error message (NestJS sends `{ message }`)
95
+ // instead of axios's generic "Request failed with status code 4xx", so the
96
+ // reason reaches the UI. The AxiosError is kept intact (response/status/
97
+ // isAxiosError) so callers can still branch on the type of failure.
98
+ if (axios.isAxiosError(error)) {
99
+ const data = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data;
100
+ const serverMessage = Array.isArray(data === null || data === void 0 ? void 0 : data.message)
101
+ ? data === null || data === void 0 ? void 0 : data.message.join(', ')
102
+ : typeof (data === null || data === void 0 ? void 0 : data.message) === 'string'
103
+ ? data.message
104
+ : undefined;
105
+ if (serverMessage) {
106
+ error.message = serverMessage;
107
+ }
108
+ }
109
+ throw error;
110
+ }
90
111
  });
91
112
  }
92
113
  fileUploadRequest(endpoint, body, headers = {}, onProgress) {
@@ -102,6 +102,27 @@ export declare class UserModule extends BaseClient {
102
102
  * @returns The updated user.
103
103
  */
104
104
  updateUser(id: string, data: UpdateUserDto): Promise<User>;
105
+ /**
106
+ * Activate (enable) a user by ID.
107
+ *
108
+ * Requires superuser or organization-admin privileges; an organization admin
109
+ * may only activate users within their own organization.
110
+ *
111
+ * @param id - UUID of the user to activate.
112
+ * @returns The updated user with `isActive` set to `true`.
113
+ */
114
+ activateUser(id: string): Promise<User>;
115
+ /**
116
+ * Deactivate (disable) a user by ID.
117
+ *
118
+ * Requires superuser or organization-admin privileges; an organization admin
119
+ * may only deactivate users within their own organization. Deactivation takes
120
+ * effect immediately: the user can no longer authenticate.
121
+ *
122
+ * @param id - UUID of the user to deactivate.
123
+ * @returns The updated user with `isActive` set to `false`.
124
+ */
125
+ deactivateUser(id: string): Promise<User>;
105
126
  /**
106
127
  * Delete a user by ID.
107
128
  *
@@ -192,6 +192,35 @@ export class UserModule extends BaseClient {
192
192
  return this.request(`${urls.users}/${id}`, 'PATCH', data);
193
193
  });
194
194
  }
195
+ /**
196
+ * Activate (enable) a user by ID.
197
+ *
198
+ * Requires superuser or organization-admin privileges; an organization admin
199
+ * may only activate users within their own organization.
200
+ *
201
+ * @param id - UUID of the user to activate.
202
+ * @returns The updated user with `isActive` set to `true`.
203
+ */
204
+ activateUser(id) {
205
+ return __awaiter(this, void 0, void 0, function* () {
206
+ return this.request(`${urls.users}/${id}/activate`, 'PATCH');
207
+ });
208
+ }
209
+ /**
210
+ * Deactivate (disable) a user by ID.
211
+ *
212
+ * Requires superuser or organization-admin privileges; an organization admin
213
+ * may only deactivate users within their own organization. Deactivation takes
214
+ * effect immediately: the user can no longer authenticate.
215
+ *
216
+ * @param id - UUID of the user to deactivate.
217
+ * @returns The updated user with `isActive` set to `false`.
218
+ */
219
+ deactivateUser(id) {
220
+ return __awaiter(this, void 0, void 0, function* () {
221
+ return this.request(`${urls.users}/${id}/deactivate`, 'PATCH');
222
+ });
223
+ }
195
224
  /**
196
225
  * Delete a user by ID.
197
226
  *
@@ -60,6 +60,10 @@ export declare class ApiSDK extends BaseClient {
60
60
  message: string;
61
61
  }>;
62
62
  loginWithCode(...args: Parameters<AuthModule['loginWithCode']>): Promise<import("./types").LoginResponse>;
63
+ loginWithEntra(...args: Parameters<AuthModule['loginWithEntra']>): Promise<import("./types").LoginResponse>;
64
+ connectEntra(...args: Parameters<AuthModule['connectEntra']>): Promise<{
65
+ message: string;
66
+ }>;
63
67
  createUser(...args: Parameters<UserModule['createUser']>): Promise<User>;
64
68
  assignEditorToRoleToUser(...args: Parameters<UserModule['assignEditorToRoleToUser']>): Promise<User>;
65
69
  assignAdminToRoleToUser(...args: Parameters<UserModule['assignAdminToRoleToUser']>): Promise<User>;
@@ -159,6 +159,19 @@ export class ApiSDK extends BaseClient {
159
159
  return result;
160
160
  });
161
161
  }
162
+ loginWithEntra(...args) {
163
+ return __awaiter(this, void 0, void 0, function* () {
164
+ const result = yield this.auth.loginWithEntra(...args);
165
+ // Sync user state across all modules after successful login
166
+ yield this.syncUserState(result.user, result.access_token, result.refresh_token);
167
+ return result;
168
+ });
169
+ }
170
+ connectEntra(...args) {
171
+ return __awaiter(this, void 0, void 0, function* () {
172
+ return this.auth.connectEntra(...args);
173
+ });
174
+ }
162
175
  // User methods
163
176
  createUser(...args) {
164
177
  return __awaiter(this, void 0, void 0, function* () {
@@ -6,6 +6,8 @@ declare const urls: {
6
6
  logout: string;
7
7
  changePassword: string;
8
8
  adminChangePassword: string;
9
+ entra: string;
10
+ entraConnect: string;
9
11
  user: string;
10
12
  users: string;
11
13
  organizations: string;
@@ -7,6 +7,8 @@ const urls = {
7
7
  logout: '/auth/logout',
8
8
  changePassword: '/auth/change-password',
9
9
  adminChangePassword: '/auth/admin/change-password',
10
+ entra: '/auth/entra',
11
+ entraConnect: '/auth/entra/connect',
10
12
  // Users
11
13
  user: '/users',
12
14
  users: '/users',
@@ -58,6 +58,8 @@ export declare class WhioOrgAdminSDK extends BaseClient {
58
58
  getUsersByOrganization(...args: Parameters<UserModule['getUsersByOrganization']>): Promise<User[]>;
59
59
  getUser(...args: Parameters<UserModule['getUser']>): Promise<User>;
60
60
  updateUser(...args: Parameters<UserModule['updateUser']>): Promise<User>;
61
+ activateUser(...args: Parameters<UserModule['activateUser']>): Promise<User>;
62
+ deactivateUser(...args: Parameters<UserModule['deactivateUser']>): Promise<User>;
61
63
  deleteUser(...args: Parameters<UserModule['deleteUser']>): Promise<void>;
62
64
  createEditorUser(...args: Parameters<UserModule['createEditorUser']>): Promise<User>;
63
65
  createAdminUser(...args: Parameters<UserModule['createAdminUser']>): Promise<User>;
@@ -192,6 +192,16 @@ export class WhioOrgAdminSDK extends BaseClient {
192
192
  return this.usersModule.updateUser(...args);
193
193
  });
194
194
  }
195
+ activateUser(...args) {
196
+ return __awaiter(this, void 0, void 0, function* () {
197
+ return this.usersModule.activateUser(...args);
198
+ });
199
+ }
200
+ deactivateUser(...args) {
201
+ return __awaiter(this, void 0, void 0, function* () {
202
+ return this.usersModule.deactivateUser(...args);
203
+ });
204
+ }
195
205
  deleteUser(...args) {
196
206
  return __awaiter(this, void 0, void 0, function* () {
197
207
  return this.usersModule.deleteUser(...args);
@@ -47,6 +47,10 @@ export declare class WhioSDK extends BaseClient {
47
47
  login(...args: Parameters<AuthModule['login']>): Promise<import("./types").LoginResponse>;
48
48
  logout(...args: Parameters<AuthModule['logout']>): Promise<void>;
49
49
  loginWithCode(...args: Parameters<AuthModule['loginWithCode']>): Promise<import("./types").LoginResponse>;
50
+ loginWithEntra(...args: Parameters<AuthModule['loginWithEntra']>): Promise<import("./types").LoginResponse>;
51
+ connectEntra(...args: Parameters<AuthModule['connectEntra']>): Promise<{
52
+ message: string;
53
+ }>;
50
54
  getProfile(...args: Parameters<AuthModule['getProfile']>): Promise<User>;
51
55
  changePassword(...args: Parameters<AuthModule['changePassword']>): Promise<import("./types").PasswordChangeResponse>;
52
56
  requestLoginCode(...args: Parameters<AuthModule['requestLoginCode']>): Promise<{
@@ -129,6 +129,18 @@ export class WhioSDK extends BaseClient {
129
129
  return result;
130
130
  });
131
131
  }
132
+ loginWithEntra(...args) {
133
+ return __awaiter(this, void 0, void 0, function* () {
134
+ const result = yield this.authModule.loginWithEntra(...args);
135
+ yield this.syncUserState(result.user, result.access_token, result.refresh_token);
136
+ return result;
137
+ });
138
+ }
139
+ connectEntra(...args) {
140
+ return __awaiter(this, void 0, void 0, function* () {
141
+ return this.authModule.connectEntra(...args);
142
+ });
143
+ }
132
144
  getProfile(...args) {
133
145
  return __awaiter(this, void 0, void 0, function* () {
134
146
  return this.authModule.getProfile(...args);
@@ -65,6 +65,8 @@ export declare class WhioSuperuserSDK extends BaseClient {
65
65
  getUser(...args: Parameters<UserModule['getUser']>): Promise<User>;
66
66
  getUsersByOrganization(...args: Parameters<UserModule['getUsersByOrganization']>): Promise<User[]>;
67
67
  updateUser(...args: Parameters<UserModule['updateUser']>): Promise<User>;
68
+ activateUser(...args: Parameters<UserModule['activateUser']>): Promise<User>;
69
+ deactivateUser(...args: Parameters<UserModule['deactivateUser']>): Promise<User>;
68
70
  deleteUser(...args: Parameters<UserModule['deleteUser']>): Promise<void>;
69
71
  createEditorUser(...args: Parameters<UserModule['createEditorUser']>): Promise<User>;
70
72
  createAdminUser(...args: Parameters<UserModule['createAdminUser']>): Promise<User>;
@@ -207,6 +207,16 @@ export class WhioSuperuserSDK extends BaseClient {
207
207
  return this.usersModule.updateUser(...args);
208
208
  });
209
209
  }
210
+ activateUser(...args) {
211
+ return __awaiter(this, void 0, void 0, function* () {
212
+ return this.usersModule.activateUser(...args);
213
+ });
214
+ }
215
+ deactivateUser(...args) {
216
+ return __awaiter(this, void 0, void 0, function* () {
217
+ return this.usersModule.deactivateUser(...args);
218
+ });
219
+ }
210
220
  deleteUser(...args) {
211
221
  return __awaiter(this, void 0, void 0, function* () {
212
222
  return this.usersModule.deleteUser(...args);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "whio-api-sdk",
3
- "version": "1.1.29",
3
+ "version": "1.1.34",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",
@@ -66,6 +66,51 @@ export class AuthModule extends BaseClient {
66
66
  }
67
67
  }
68
68
 
69
+ /**
70
+ * Authenticate with a Microsoft (Entra ID) token and persist the session.
71
+ *
72
+ * The client runs the Microsoft sign-in itself and passes the resulting Entra
73
+ * ID token here; the backend verifies it and mints the normal app session. The
74
+ * Microsoft identity must already be linked to a local account (see
75
+ * {@link connectEntra}) - an unlinked customer-app token is rejected.
76
+ *
77
+ * @param idToken - The Entra ID token obtained from the Microsoft sign-in.
78
+ * @returns The login response including access/refresh tokens and the user.
79
+ */
80
+ public async loginWithEntra(idToken: string): Promise<LoginResponse> {
81
+ try {
82
+ const response = await this.request<LoginResponse>(
83
+ urls.entra,
84
+ 'POST',
85
+ { idToken },
86
+ {},
87
+ true
88
+ );
89
+ await this.updateAuthState(response);
90
+ return response;
91
+ } catch (error) {
92
+ await this.clearAuth();
93
+ throw error;
94
+ }
95
+ }
96
+
97
+ /**
98
+ * Link the authenticated user's account to their Microsoft (Entra ID) identity
99
+ * so future {@link loginWithEntra} calls resolve them by their Microsoft oid.
100
+ *
101
+ * Requires an active session - the bearer token is attached automatically.
102
+ *
103
+ * @param idToken - The Entra ID token obtained from the Microsoft sign-in.
104
+ * @returns A confirmation message.
105
+ */
106
+ public async connectEntra(idToken: string): Promise<{ message: string }> {
107
+ return this.request<{ message: string }>(
108
+ urls.entraConnect,
109
+ 'POST',
110
+ { idToken }
111
+ );
112
+ }
113
+
69
114
  /**
70
115
  * Clear the current session and any persisted authentication state.
71
116
  *
@@ -80,15 +80,36 @@ export class BaseClient {
80
80
  }
81
81
  }
82
82
 
83
- const response = await axios({
84
- url,
85
- method,
86
- headers: { ...defaultHeaders, ...headers },
87
- data: body,
88
- timeout: 5000,
89
- });
83
+ try {
84
+ const response = await axios({
85
+ url,
86
+ method,
87
+ headers: { ...defaultHeaders, ...headers },
88
+ data: body,
89
+ timeout: 5000,
90
+ });
90
91
 
91
- return response.data;
92
+ return response.data;
93
+ } catch (error) {
94
+ // Surface the server-provided error message (NestJS sends `{ message }`)
95
+ // instead of axios's generic "Request failed with status code 4xx", so the
96
+ // reason reaches the UI. The AxiosError is kept intact (response/status/
97
+ // isAxiosError) so callers can still branch on the type of failure.
98
+ if (axios.isAxiosError(error)) {
99
+ const data = error.response?.data as
100
+ | { message?: string | string[] }
101
+ | undefined;
102
+ const serverMessage = Array.isArray(data?.message)
103
+ ? data?.message.join(', ')
104
+ : typeof data?.message === 'string'
105
+ ? data.message
106
+ : undefined;
107
+ if (serverMessage) {
108
+ error.message = serverMessage;
109
+ }
110
+ }
111
+ throw error;
112
+ }
92
113
  }
93
114
 
94
115
  protected async fileUploadRequest<T>(
@@ -178,6 +178,33 @@ export class UserModule extends BaseClient {
178
178
  return this.request<User>(`${urls.users}/${id}`, 'PATCH', data);
179
179
  }
180
180
 
181
+ /**
182
+ * Activate (enable) a user by ID.
183
+ *
184
+ * Requires superuser or organization-admin privileges; an organization admin
185
+ * may only activate users within their own organization.
186
+ *
187
+ * @param id - UUID of the user to activate.
188
+ * @returns The updated user with `isActive` set to `true`.
189
+ */
190
+ public async activateUser(id: string): Promise<User> {
191
+ return this.request<User>(`${urls.users}/${id}/activate`, 'PATCH');
192
+ }
193
+
194
+ /**
195
+ * Deactivate (disable) a user by ID.
196
+ *
197
+ * Requires superuser or organization-admin privileges; an organization admin
198
+ * may only deactivate users within their own organization. Deactivation takes
199
+ * effect immediately: the user can no longer authenticate.
200
+ *
201
+ * @param id - UUID of the user to deactivate.
202
+ * @returns The updated user with `isActive` set to `false`.
203
+ */
204
+ public async deactivateUser(id: string): Promise<User> {
205
+ return this.request<User>(`${urls.users}/${id}/deactivate`, 'PATCH');
206
+ }
207
+
181
208
  /**
182
209
  * Delete a user by ID.
183
210
  *
package/src/sdk/sdk.ts CHANGED
@@ -180,6 +180,17 @@ export class ApiSDK extends BaseClient {
180
180
  return result;
181
181
  }
182
182
 
183
+ public async loginWithEntra(...args: Parameters<AuthModule['loginWithEntra']>) {
184
+ const result = await this.auth.loginWithEntra(...args);
185
+ // Sync user state across all modules after successful login
186
+ await this.syncUserState(result.user, result.access_token, result.refresh_token);
187
+ return result;
188
+ }
189
+
190
+ public async connectEntra(...args: Parameters<AuthModule['connectEntra']>) {
191
+ return this.auth.connectEntra(...args);
192
+ }
193
+
183
194
  // User methods
184
195
  public async createUser(...args: Parameters<UserModule['createUser']>) {
185
196
  return this.users.createUser(...args);
package/src/sdk/urls.ts CHANGED
@@ -7,7 +7,9 @@ const urls = {
7
7
  logout: '/auth/logout',
8
8
  changePassword: '/auth/change-password',
9
9
  adminChangePassword: '/auth/admin/change-password',
10
-
10
+ entra: '/auth/entra',
11
+ entraConnect: '/auth/entra/connect',
12
+
11
13
  // Users
12
14
  user: '/users',
13
15
  users: '/users',
@@ -198,6 +198,14 @@ export class WhioOrgAdminSDK extends BaseClient {
198
198
  return this.usersModule.updateUser(...args);
199
199
  }
200
200
 
201
+ public async activateUser(...args: Parameters<UserModule['activateUser']>) {
202
+ return this.usersModule.activateUser(...args);
203
+ }
204
+
205
+ public async deactivateUser(...args: Parameters<UserModule['deactivateUser']>) {
206
+ return this.usersModule.deactivateUser(...args);
207
+ }
208
+
201
209
  public async deleteUser(...args: Parameters<UserModule['deleteUser']>) {
202
210
  return this.usersModule.deleteUser(...args);
203
211
  }
@@ -149,6 +149,16 @@ export class WhioSDK extends BaseClient {
149
149
  return result;
150
150
  }
151
151
 
152
+ public async loginWithEntra(...args: Parameters<AuthModule['loginWithEntra']>) {
153
+ const result = await this.authModule.loginWithEntra(...args);
154
+ await this.syncUserState(result.user, result.access_token, result.refresh_token);
155
+ return result;
156
+ }
157
+
158
+ public async connectEntra(...args: Parameters<AuthModule['connectEntra']>) {
159
+ return this.authModule.connectEntra(...args);
160
+ }
161
+
152
162
  public async getProfile(...args: Parameters<AuthModule['getProfile']>) {
153
163
  return this.authModule.getProfile(...args);
154
164
  }
@@ -213,6 +213,14 @@ export class WhioSuperuserSDK extends BaseClient {
213
213
  return this.usersModule.updateUser(...args);
214
214
  }
215
215
 
216
+ public async activateUser(...args: Parameters<UserModule['activateUser']>) {
217
+ return this.usersModule.activateUser(...args);
218
+ }
219
+
220
+ public async deactivateUser(...args: Parameters<UserModule['deactivateUser']>) {
221
+ return this.usersModule.deactivateUser(...args);
222
+ }
223
+
216
224
  public async deleteUser(...args: Parameters<UserModule['deleteUser']>) {
217
225
  return this.usersModule.deleteUser(...args);
218
226
  }