whio-api-sdk 1.0.226-beta-staging → 1.0.228-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.
@@ -26,11 +26,14 @@ export class UserModule extends BaseClient {
26
26
  });
27
27
  }
28
28
  assignRoleToUser(userId, roleName, organizationId) {
29
- var _a;
29
+ var _a, _b;
30
30
  return __awaiter(this, void 0, void 0, function* () {
31
31
  const orgId = organizationId || ((_a = this.user) === null || _a === void 0 ? void 0 : _a.organizationId);
32
32
  const organization = yield this.request(`${urls.organizations}/${orgId}`, 'GET');
33
- const orgRoleEditor = organization.roles.find(r => r.name === roleName);
33
+ const orgRoleEditor = (_b = organization.roles) === null || _b === void 0 ? void 0 : _b.find(r => r.name === roleName);
34
+ if (!orgRoleEditor) {
35
+ throw new Error(`Role ${roleName} not found in organization ${orgId}`);
36
+ }
34
37
  const assignRoleDto = {
35
38
  userId: userId,
36
39
  organizationRoleId: orgRoleEditor.id,
@@ -55,6 +55,10 @@ export class ApiSDK extends BaseClient {
55
55
  this.workflows, this.logs, this.debug, this.externalIntegrations,
56
56
  this.websocket, this.reports, this.patients
57
57
  ];
58
+ // Auto-initialize the SDK
59
+ this.initialize().catch(error => {
60
+ console.error('Failed to initialize SDK:', error);
61
+ });
58
62
  }
59
63
  initialize() {
60
64
  const _super = Object.create(null, {
@@ -105,7 +109,7 @@ export class ApiSDK extends BaseClient {
105
109
  return __awaiter(this, void 0, void 0, function* () {
106
110
  const result = yield this.auth.login(...args);
107
111
  // Sync user state across all modules after successful login
108
- yield this.syncUserStateAcrossModules();
112
+ yield this.syncUserState(result.user, result.access_token, result.refresh_token);
109
113
  return result;
110
114
  });
111
115
  }
@@ -113,7 +117,7 @@ export class ApiSDK extends BaseClient {
113
117
  return __awaiter(this, void 0, void 0, function* () {
114
118
  const result = yield this.auth.logout(...args);
115
119
  // Sync cleared state across all modules after logout
116
- yield this.syncUserStateAcrossModules();
120
+ yield this.syncUserState(null, null, null);
117
121
  return result;
118
122
  });
119
123
  }
@@ -141,7 +145,7 @@ export class ApiSDK extends BaseClient {
141
145
  return __awaiter(this, void 0, void 0, function* () {
142
146
  const result = yield this.auth.loginWithCode(...args);
143
147
  // Sync user state across all modules after successful login
144
- yield this.syncUserStateAcrossModules();
148
+ yield this.syncUserState(result.user, result.access_token, result.refresh_token);
145
149
  return result;
146
150
  });
147
151
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "whio-api-sdk",
3
- "version": "1.0.226-beta-staging",
3
+ "version": "1.0.228-beta-staging",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",
@@ -27,10 +27,13 @@ export class UserModule extends BaseClient {
27
27
  `${urls.organizations}/${orgId}`,
28
28
  'GET'
29
29
  );
30
- const orgRoleEditor = organization.roles!.find(r => r.name === roleName);
30
+ const orgRoleEditor = organization.roles?.find(r => r.name === roleName);
31
+ if (!orgRoleEditor) {
32
+ throw new Error(`Role ${roleName} not found in organization ${orgId}`);
33
+ }
31
34
  const assignRoleDto: AssignOrganizationRoleDto = {
32
35
  userId: userId,
33
- organizationRoleId: orgRoleEditor!.id,
36
+ organizationRoleId: orgRoleEditor.id,
34
37
  };
35
38
  this.request(urls.userOrganizationRoles, 'POST', assignRoleDto);
36
39
  const userWithOrgRole = await this.request<User>(`${urls.user}/${userId}`, 'GET');
package/src/sdk/sdk.ts CHANGED
@@ -70,6 +70,11 @@ export class ApiSDK extends BaseClient {
70
70
  this.workflows, this.logs, this.debug, this.externalIntegrations,
71
71
  this.websocket, this.reports, this.patients
72
72
  ];
73
+
74
+ // Auto-initialize the SDK
75
+ this.initialize().catch(error => {
76
+ console.error('Failed to initialize SDK:', error);
77
+ });
73
78
  }
74
79
 
75
80
  public async initialize(): Promise<void> {
@@ -127,14 +132,14 @@ export class ApiSDK extends BaseClient {
127
132
  public async login(...args: Parameters<AuthModule['login']>) {
128
133
  const result = await this.auth.login(...args);
129
134
  // Sync user state across all modules after successful login
130
- await this.syncUserStateAcrossModules();
135
+ await this.syncUserState(result.user, result.access_token, result.refresh_token);
131
136
  return result;
132
137
  }
133
138
 
134
139
  public async logout(...args: Parameters<AuthModule['logout']>) {
135
140
  const result = await this.auth.logout(...args);
136
141
  // Sync cleared state across all modules after logout
137
- await this.syncUserStateAcrossModules();
142
+ await this.syncUserState(null, null, null);
138
143
  return result;
139
144
  }
140
145
 
@@ -157,7 +162,7 @@ export class ApiSDK extends BaseClient {
157
162
  public async loginWithCode(...args: Parameters<AuthModule['loginWithCode']>) {
158
163
  const result = await this.auth.loginWithCode(...args);
159
164
  // Sync user state across all modules after successful login
160
- await this.syncUserStateAcrossModules();
165
+ await this.syncUserState(result.user, result.access_token, result.refresh_token);
161
166
  return result;
162
167
  }
163
168