whio-api-sdk 1.0.174 → 1.0.176

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.
@@ -17,11 +17,7 @@ export class ApiSDK {
17
17
  this.refreshToken = null;
18
18
  this.user = null;
19
19
  this.baseUrl = config.baseUrl || '/api';
20
- this.storage = config.storage || {
21
- getItem: (key) => localStorage.getItem(key),
22
- setItem: (key, value) => localStorage.setItem(key, value),
23
- removeItem: (key) => localStorage.removeItem(key),
24
- };
20
+ this.storage = config.storage;
25
21
  this.initialize();
26
22
  }
27
23
  fetchConfig(url) {
@@ -36,7 +32,8 @@ export class ApiSDK {
36
32
  }
37
33
  getToken() {
38
34
  return __awaiter(this, void 0, void 0, function* () {
39
- this.accessToken = yield this.storage.getItem('access_token');
35
+ const accessToken = yield this.storage.getItem('access_token');
36
+ this.accessToken = accessToken ? JSON.parse(accessToken) : null;
40
37
  if (!this.accessToken) {
41
38
  throw new Error('Access token not found');
42
39
  }
@@ -54,10 +51,12 @@ export class ApiSDK {
54
51
  }
55
52
  initialize() {
56
53
  return __awaiter(this, void 0, void 0, function* () {
57
- this.accessToken = yield this.storage.getItem('access_token');
58
- this.refreshToken = yield this.storage.getItem('refresh_token');
54
+ const accessToken = yield this.storage.getItem('access_token');
55
+ const refreshToken = yield this.storage.getItem('refresh_token');
59
56
  const userString = yield this.storage.getItem('user');
60
57
  this.user = userString ? JSON.parse(userString) : null;
58
+ this.accessToken = accessToken ? JSON.parse(accessToken) : null;
59
+ this.refreshToken = refreshToken ? JSON.parse(refreshToken) : null;
61
60
  });
62
61
  }
63
62
  request(endpoint, method = 'GET', body, headers = {}, noToken = false) {
@@ -119,8 +118,8 @@ export class ApiSDK {
119
118
  this.accessToken = response.access_token;
120
119
  this.refreshToken = response.refresh_token;
121
120
  this.user = response.user;
122
- yield this.storage.setItem('access_token', response.access_token);
123
- yield this.storage.setItem('refresh_token', response.refresh_token);
121
+ yield this.storage.setItem('access_token', JSON.stringify(response.access_token));
122
+ yield this.storage.setItem('refresh_token', JSON.stringify(response.refresh_token));
124
123
  yield this.storage.setItem('user', JSON.stringify(response.user));
125
124
  return response;
126
125
  }
@@ -173,8 +172,8 @@ export class ApiSDK {
173
172
  this.accessToken = response.access_token;
174
173
  this.refreshToken = response.refresh_token;
175
174
  this.user = response.user;
176
- yield this.storage.setItem('access_token', response.access_token);
177
- yield this.storage.setItem('refresh_token', response.refresh_token);
175
+ yield this.storage.setItem('access_token', JSON.stringify(response.access_token));
176
+ yield this.storage.setItem('refresh_token', JSON.stringify(response.refresh_token));
178
177
  yield this.storage.setItem('user', JSON.stringify(response.user));
179
178
  }
180
179
  catch (error) {
@@ -291,7 +291,7 @@ export interface CreateSessionDto {
291
291
  dateTime: string;
292
292
  startDateTime?: string;
293
293
  stopDateTime?: string;
294
- templateId: string;
294
+ templateId?: string;
295
295
  templateName?: string;
296
296
  summary?: string;
297
297
  sessionName?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "whio-api-sdk",
3
- "version": "1.0.174",
3
+ "version": "1.0.176",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",
package/src/sdk/sdk.ts CHANGED
@@ -57,12 +57,7 @@ export class ApiSDK {
57
57
 
58
58
  constructor(config: SDKConfig = {}) {
59
59
  this.baseUrl = config.baseUrl || '/api';
60
- this.storage = config.storage || {
61
- getItem: (key) => localStorage.getItem(key),
62
- setItem: (key, value) => localStorage.setItem(key, value),
63
- removeItem: (key) => localStorage.removeItem(key),
64
- };
65
-
60
+ this.storage = config.storage;
66
61
  this.initialize();
67
62
  }
68
63
 
@@ -76,8 +71,8 @@ export class ApiSDK {
76
71
  }
77
72
 
78
73
  private async getToken() {
79
- this.accessToken = await this.storage!.getItem('access_token');
80
-
74
+ const accessToken = await this.storage!.getItem('access_token');
75
+ this.accessToken = accessToken ? JSON.parse(accessToken) : null;
81
76
  if (!this.accessToken) {
82
77
  throw new Error('Access token not found');
83
78
  }
@@ -94,10 +89,12 @@ export class ApiSDK {
94
89
  }
95
90
 
96
91
  private async initialize() {
97
- this.accessToken = await this.storage!.getItem('access_token');
98
- this.refreshToken = await this.storage!.getItem('refresh_token');
92
+ const accessToken = await this.storage!.getItem('access_token');
93
+ const refreshToken = await this.storage!.getItem('refresh_token');
99
94
  const userString = await this.storage!.getItem('user');
100
95
  this.user = userString ? JSON.parse(userString) : null;
96
+ this.accessToken = accessToken ? JSON.parse(accessToken) : null;
97
+ this.refreshToken = refreshToken ? JSON.parse(refreshToken) : null;
101
98
  }
102
99
 
103
100
  private async request<T>(
@@ -187,8 +184,8 @@ export class ApiSDK {
187
184
 
188
185
  this.user = response.user;
189
186
 
190
- await this.storage!.setItem('access_token', response.access_token);
191
- await this.storage!.setItem('refresh_token', response.refresh_token);
187
+ await this.storage!.setItem('access_token', JSON.stringify(response.access_token));
188
+ await this.storage!.setItem('refresh_token', JSON.stringify(response.refresh_token));
192
189
  await this.storage!.setItem('user', JSON.stringify(response.user));
193
190
 
194
191
  return response;
@@ -246,8 +243,8 @@ export class ApiSDK {
246
243
  this.refreshToken = response.refresh_token;
247
244
  this.user = response.user;
248
245
 
249
- await this.storage!.setItem('access_token', response.access_token);
250
- await this.storage!.setItem('refresh_token', response.refresh_token);
246
+ await this.storage!.setItem('access_token', JSON.stringify(response.access_token));
247
+ await this.storage!.setItem('refresh_token', JSON.stringify(response.refresh_token));
251
248
  await this.storage!.setItem('user', JSON.stringify(response.user));
252
249
  } catch (error) {
253
250
  await this.clearAuth();
package/src/sdk/types.ts CHANGED
@@ -370,7 +370,7 @@ export interface CreateSessionDto {
370
370
  dateTime: string;
371
371
  startDateTime?: string;
372
372
  stopDateTime?: string;
373
- templateId: string;
373
+ templateId?: string;
374
374
  templateName?: string;
375
375
  summary?: string;
376
376
  sessionName?: string;