whio-api-sdk 1.0.243-beta-staging → 1.1.1
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/src/sdk/modules/base-client.d.ts +1 -0
- package/dist/src/sdk/modules/base-client.js +41 -21
- package/dist/src/sdk/sdk.d.ts +2 -1
- package/dist/src/sdk/sdk.js +20 -12
- package/dist/src/sdk/types/common.types.d.ts +1 -0
- package/package.json +1 -1
- package/src/sdk/modules/base-client.ts +45 -28
- package/src/sdk/sdk.ts +21 -13
- package/src/sdk/types/common.types.ts +1 -0
|
@@ -70,20 +70,16 @@ export class BaseClient {
|
|
|
70
70
|
}
|
|
71
71
|
request(endpoint, method = 'GET', body, headers = {}, noToken = false) {
|
|
72
72
|
return __awaiter(this, void 0, void 0, function* () {
|
|
73
|
-
yield this.ensureInitialized();
|
|
74
73
|
const url = `${this.baseUrl}${endpoint}`;
|
|
75
74
|
const defaultHeaders = {
|
|
76
75
|
'Content-Type': 'application/json',
|
|
77
76
|
'ngrok-skip-browser-warning': 'true'
|
|
78
77
|
};
|
|
79
|
-
if (noToken) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
if (this.accessToken) {
|
|
86
|
-
defaultHeaders['Authorization'] = `Bearer ${this.accessToken}`;
|
|
78
|
+
if (!noToken) {
|
|
79
|
+
const token = yield this.getValidToken();
|
|
80
|
+
if (token) {
|
|
81
|
+
defaultHeaders['Authorization'] = `Bearer ${token}`;
|
|
82
|
+
}
|
|
87
83
|
}
|
|
88
84
|
const response = yield fetch(url, {
|
|
89
85
|
method,
|
|
@@ -99,14 +95,13 @@ export class BaseClient {
|
|
|
99
95
|
}
|
|
100
96
|
fileUploadRequest(endpoint, body, headers = {}, onProgress) {
|
|
101
97
|
return __awaiter(this, void 0, void 0, function* () {
|
|
102
|
-
yield this.ensureInitialized();
|
|
103
98
|
const url = `${this.baseUrl}${endpoint}`;
|
|
104
99
|
const defaultHeaders = {
|
|
105
100
|
'ngrok-skip-browser-warning': 'true'
|
|
106
101
|
};
|
|
107
|
-
yield this.
|
|
108
|
-
if (
|
|
109
|
-
defaultHeaders['Authorization'] = `Bearer ${
|
|
102
|
+
const token = yield this.getValidToken();
|
|
103
|
+
if (token) {
|
|
104
|
+
defaultHeaders['Authorization'] = `Bearer ${token}`;
|
|
110
105
|
}
|
|
111
106
|
return new Promise((resolve, reject) => {
|
|
112
107
|
const xhr = new XMLHttpRequest();
|
|
@@ -156,14 +151,13 @@ export class BaseClient {
|
|
|
156
151
|
}
|
|
157
152
|
downloadRequest(endpoint) {
|
|
158
153
|
return __awaiter(this, void 0, void 0, function* () {
|
|
159
|
-
yield this.ensureInitialized();
|
|
160
154
|
const url = `${this.baseUrl}${endpoint}`;
|
|
161
|
-
yield this.getToken();
|
|
162
155
|
const defaultHeaders = {
|
|
163
156
|
'ngrok-skip-browser-warning': 'true'
|
|
164
157
|
};
|
|
165
|
-
|
|
166
|
-
|
|
158
|
+
const token = yield this.getValidToken();
|
|
159
|
+
if (token) {
|
|
160
|
+
defaultHeaders['Authorization'] = `Bearer ${token}`;
|
|
167
161
|
}
|
|
168
162
|
const response = yield fetch(url, {
|
|
169
163
|
method: 'GET',
|
|
@@ -178,14 +172,13 @@ export class BaseClient {
|
|
|
178
172
|
}
|
|
179
173
|
textRequest(endpoint) {
|
|
180
174
|
return __awaiter(this, void 0, void 0, function* () {
|
|
181
|
-
yield this.ensureInitialized();
|
|
182
175
|
const url = `${this.baseUrl}${endpoint}`;
|
|
183
|
-
yield this.getToken();
|
|
184
176
|
const defaultHeaders = {
|
|
185
177
|
'ngrok-skip-browser-warning': 'true'
|
|
186
178
|
};
|
|
187
|
-
|
|
188
|
-
|
|
179
|
+
const token = yield this.getValidToken();
|
|
180
|
+
if (token) {
|
|
181
|
+
defaultHeaders['Authorization'] = `Bearer ${token}`;
|
|
189
182
|
}
|
|
190
183
|
const response = yield fetch(url, {
|
|
191
184
|
method: 'GET',
|
|
@@ -273,4 +266,31 @@ export class BaseClient {
|
|
|
273
266
|
getRefreshToken() {
|
|
274
267
|
return this.refreshToken;
|
|
275
268
|
}
|
|
269
|
+
getValidToken() {
|
|
270
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
271
|
+
if (!this.storage) {
|
|
272
|
+
return null;
|
|
273
|
+
}
|
|
274
|
+
const storedAccessToken = yield this.storage.getItem('access_token');
|
|
275
|
+
this.accessToken = storedAccessToken ? JSON.parse(storedAccessToken) : null;
|
|
276
|
+
if (!this.accessToken) {
|
|
277
|
+
return null;
|
|
278
|
+
}
|
|
279
|
+
if (!this.isTokenExpired(this.accessToken)) {
|
|
280
|
+
return this.accessToken;
|
|
281
|
+
}
|
|
282
|
+
const storedRefreshToken = yield this.storage.getItem('refresh_token');
|
|
283
|
+
this.refreshToken = storedRefreshToken ? JSON.parse(storedRefreshToken) : null;
|
|
284
|
+
if (!this.refreshToken) {
|
|
285
|
+
return null;
|
|
286
|
+
}
|
|
287
|
+
try {
|
|
288
|
+
yield this.refreshAccessToken();
|
|
289
|
+
return this.accessToken;
|
|
290
|
+
}
|
|
291
|
+
catch (error) {
|
|
292
|
+
return null;
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
}
|
|
276
296
|
}
|
package/dist/src/sdk/sdk.d.ts
CHANGED
|
@@ -37,7 +37,7 @@ export declare class ApiSDK extends BaseClient {
|
|
|
37
37
|
readonly logs: LogModule;
|
|
38
38
|
readonly debug: DebugModule;
|
|
39
39
|
readonly externalIntegrations: ExternalIntegrationModule;
|
|
40
|
-
readonly websocket: WebSocketModule;
|
|
40
|
+
readonly websocket: WebSocketModule | null;
|
|
41
41
|
readonly reports: ReportsModule;
|
|
42
42
|
readonly patients: PatientModule;
|
|
43
43
|
readonly dataStrategies: DataStrategyModule;
|
|
@@ -212,6 +212,7 @@ export declare class ApiSDK extends BaseClient {
|
|
|
212
212
|
getExternalIntegration(...args: Parameters<ExternalIntegrationModule['getExternalIntegration']>): Promise<import("./types").ExternalIntegration>;
|
|
213
213
|
updateExternalIntegration(...args: Parameters<ExternalIntegrationModule['updateExternalIntegration']>): Promise<import("./types").ExternalIntegration>;
|
|
214
214
|
deleteExternalIntegration(...args: Parameters<ExternalIntegrationModule['deleteExternalIntegration']>): Promise<void>;
|
|
215
|
+
private assertWebSocket;
|
|
215
216
|
connectWebSocket(): Promise<void>;
|
|
216
217
|
disconnectWebSocket(): void;
|
|
217
218
|
isWebSocketConnected(): boolean;
|
package/dist/src/sdk/sdk.js
CHANGED
|
@@ -49,7 +49,7 @@ export class ApiSDK extends BaseClient {
|
|
|
49
49
|
this.logs = new LogModule(config);
|
|
50
50
|
this.debug = new DebugModule(config);
|
|
51
51
|
this.externalIntegrations = new ExternalIntegrationModule(config);
|
|
52
|
-
this.websocket = new WebSocketModule(config);
|
|
52
|
+
this.websocket = config.skipWebsocket ? null : new WebSocketModule(config);
|
|
53
53
|
this.reports = new ReportsModule(config);
|
|
54
54
|
this.patients = new PatientModule(config);
|
|
55
55
|
this.dataStrategies = new DataStrategyModule(config);
|
|
@@ -59,7 +59,8 @@ export class ApiSDK extends BaseClient {
|
|
|
59
59
|
this.auth, this.users, this.organizations, this.teams, this.templates,
|
|
60
60
|
this.transcriptionSummaries, this.sessions, this.agents, this.audio,
|
|
61
61
|
this.workflows, this.integrationActions, this.logs, this.debug, this.externalIntegrations,
|
|
62
|
-
this.
|
|
62
|
+
this.reports, this.patients, this.dataStrategies, this.systemSnapshots,
|
|
63
|
+
...(this.websocket ? [this.websocket] : [])
|
|
63
64
|
];
|
|
64
65
|
// Auto-initialize the SDK
|
|
65
66
|
this.initialize().catch(error => {
|
|
@@ -872,35 +873,42 @@ export class ApiSDK extends BaseClient {
|
|
|
872
873
|
});
|
|
873
874
|
}
|
|
874
875
|
// WebSocket methods
|
|
876
|
+
assertWebSocket() {
|
|
877
|
+
if (!this.websocket) {
|
|
878
|
+
throw new Error('WebSocket module is not available. SDK was initialized with skipWebsocket: true');
|
|
879
|
+
}
|
|
880
|
+
return this.websocket;
|
|
881
|
+
}
|
|
875
882
|
connectWebSocket() {
|
|
876
|
-
return this.
|
|
883
|
+
return this.assertWebSocket().connect();
|
|
877
884
|
}
|
|
878
885
|
disconnectWebSocket() {
|
|
879
|
-
return this.
|
|
886
|
+
return this.assertWebSocket().disconnect();
|
|
880
887
|
}
|
|
881
888
|
isWebSocketConnected() {
|
|
882
|
-
|
|
889
|
+
var _a, _b;
|
|
890
|
+
return (_b = (_a = this.websocket) === null || _a === void 0 ? void 0 : _a.isConnected()) !== null && _b !== void 0 ? _b : false;
|
|
883
891
|
}
|
|
884
892
|
streamAudioChunk(...args) {
|
|
885
|
-
return this.
|
|
893
|
+
return this.assertWebSocket().streamAudioChunk(...args);
|
|
886
894
|
}
|
|
887
895
|
streamAudioChunks(...args) {
|
|
888
|
-
return this.
|
|
896
|
+
return this.assertWebSocket().streamAudioChunks(...args);
|
|
889
897
|
}
|
|
890
898
|
onWebSocketEvent(...args) {
|
|
891
|
-
return this.
|
|
899
|
+
return this.assertWebSocket().on(...args);
|
|
892
900
|
}
|
|
893
901
|
offWebSocketEvent(...args) {
|
|
894
|
-
return this.
|
|
902
|
+
return this.assertWebSocket().off(...args);
|
|
895
903
|
}
|
|
896
904
|
getWebSocketStats() {
|
|
897
|
-
return this.
|
|
905
|
+
return this.assertWebSocket().getConnectionStats();
|
|
898
906
|
}
|
|
899
907
|
subscribe(...args) {
|
|
900
|
-
return this.
|
|
908
|
+
return this.assertWebSocket().on(...args);
|
|
901
909
|
}
|
|
902
910
|
unsubscribe(...args) {
|
|
903
|
-
return this.
|
|
911
|
+
return this.assertWebSocket().off(...args);
|
|
904
912
|
}
|
|
905
913
|
// Reports methods
|
|
906
914
|
getCompanyDailyReportCsv(...args) {
|
package/package.json
CHANGED
|
@@ -69,22 +69,17 @@ export class BaseClient {
|
|
|
69
69
|
headers: Record<string, string> = {},
|
|
70
70
|
noToken: boolean = false,
|
|
71
71
|
): Promise<T> {
|
|
72
|
-
await this.ensureInitialized();
|
|
73
|
-
|
|
74
72
|
const url = `${this.baseUrl}${endpoint}`;
|
|
75
73
|
const defaultHeaders: Record<string, string> = {
|
|
76
74
|
'Content-Type': 'application/json',
|
|
77
75
|
'ngrok-skip-browser-warning': 'true'
|
|
78
76
|
};
|
|
79
77
|
|
|
80
|
-
if (noToken) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
if (this.accessToken) {
|
|
87
|
-
defaultHeaders['Authorization'] = `Bearer ${this.accessToken}`;
|
|
78
|
+
if (!noToken) {
|
|
79
|
+
const token = await this.getValidToken();
|
|
80
|
+
if (token) {
|
|
81
|
+
defaultHeaders['Authorization'] = `Bearer ${token}`;
|
|
82
|
+
}
|
|
88
83
|
}
|
|
89
84
|
|
|
90
85
|
const response = await fetch(url, {
|
|
@@ -109,17 +104,14 @@ export class BaseClient {
|
|
|
109
104
|
headers: Record<string, string> = {},
|
|
110
105
|
onProgress?: (percentage: number) => void
|
|
111
106
|
): Promise<T> {
|
|
112
|
-
await this.ensureInitialized();
|
|
113
|
-
|
|
114
107
|
const url = `${this.baseUrl}${endpoint}`;
|
|
115
108
|
const defaultHeaders: Record<string, string> = {
|
|
116
109
|
'ngrok-skip-browser-warning': 'true'
|
|
117
110
|
};
|
|
118
111
|
|
|
119
|
-
await this.
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
defaultHeaders['Authorization'] = `Bearer ${this.accessToken}`;
|
|
112
|
+
const token = await this.getValidToken();
|
|
113
|
+
if (token) {
|
|
114
|
+
defaultHeaders['Authorization'] = `Bearer ${token}`;
|
|
123
115
|
}
|
|
124
116
|
|
|
125
117
|
return new Promise((resolve, reject) => {
|
|
@@ -172,18 +164,15 @@ export class BaseClient {
|
|
|
172
164
|
}
|
|
173
165
|
|
|
174
166
|
protected async downloadRequest(endpoint: string): Promise<Blob> {
|
|
175
|
-
await this.ensureInitialized();
|
|
176
|
-
|
|
177
167
|
const url = `${this.baseUrl}${endpoint}`;
|
|
178
168
|
|
|
179
|
-
await this.getToken();
|
|
180
|
-
|
|
181
169
|
const defaultHeaders: Record<string, string> = {
|
|
182
170
|
'ngrok-skip-browser-warning': 'true'
|
|
183
171
|
};
|
|
184
172
|
|
|
185
|
-
|
|
186
|
-
|
|
173
|
+
const token = await this.getValidToken();
|
|
174
|
+
if (token) {
|
|
175
|
+
defaultHeaders['Authorization'] = `Bearer ${token}`;
|
|
187
176
|
}
|
|
188
177
|
|
|
189
178
|
const response = await fetch(url, {
|
|
@@ -202,18 +191,15 @@ export class BaseClient {
|
|
|
202
191
|
}
|
|
203
192
|
|
|
204
193
|
protected async textRequest(endpoint: string): Promise<string> {
|
|
205
|
-
await this.ensureInitialized();
|
|
206
|
-
|
|
207
194
|
const url = `${this.baseUrl}${endpoint}`;
|
|
208
195
|
|
|
209
|
-
await this.getToken();
|
|
210
|
-
|
|
211
196
|
const defaultHeaders: Record<string, string> = {
|
|
212
197
|
'ngrok-skip-browser-warning': 'true'
|
|
213
198
|
};
|
|
214
199
|
|
|
215
|
-
|
|
216
|
-
|
|
200
|
+
const token = await this.getValidToken();
|
|
201
|
+
if (token) {
|
|
202
|
+
defaultHeaders['Authorization'] = `Bearer ${token}`;
|
|
217
203
|
}
|
|
218
204
|
|
|
219
205
|
const response = await fetch(url, {
|
|
@@ -316,4 +302,35 @@ export class BaseClient {
|
|
|
316
302
|
return this.refreshToken;
|
|
317
303
|
}
|
|
318
304
|
|
|
305
|
+
public async getValidToken(): Promise<string | null> {
|
|
306
|
+
if (!this.storage) {
|
|
307
|
+
return null;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
const storedAccessToken = await this.storage.getItem('access_token');
|
|
311
|
+
this.accessToken = storedAccessToken ? JSON.parse(storedAccessToken) : null;
|
|
312
|
+
|
|
313
|
+
if (!this.accessToken) {
|
|
314
|
+
return null;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
if (!this.isTokenExpired(this.accessToken)) {
|
|
318
|
+
return this.accessToken;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
const storedRefreshToken = await this.storage.getItem('refresh_token');
|
|
322
|
+
this.refreshToken = storedRefreshToken ? JSON.parse(storedRefreshToken) : null;
|
|
323
|
+
|
|
324
|
+
if (!this.refreshToken) {
|
|
325
|
+
return null;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
try {
|
|
329
|
+
await this.refreshAccessToken();
|
|
330
|
+
return this.accessToken;
|
|
331
|
+
} catch (error) {
|
|
332
|
+
return null;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
|
|
319
336
|
}
|
package/src/sdk/sdk.ts
CHANGED
|
@@ -39,7 +39,7 @@ export class ApiSDK extends BaseClient {
|
|
|
39
39
|
public readonly logs: LogModule;
|
|
40
40
|
public readonly debug: DebugModule;
|
|
41
41
|
public readonly externalIntegrations: ExternalIntegrationModule;
|
|
42
|
-
public readonly websocket: WebSocketModule;
|
|
42
|
+
public readonly websocket: WebSocketModule | null;
|
|
43
43
|
public readonly reports: ReportsModule;
|
|
44
44
|
public readonly patients: PatientModule;
|
|
45
45
|
public readonly dataStrategies: DataStrategyModule;
|
|
@@ -66,7 +66,7 @@ export class ApiSDK extends BaseClient {
|
|
|
66
66
|
this.logs = new LogModule(config);
|
|
67
67
|
this.debug = new DebugModule(config);
|
|
68
68
|
this.externalIntegrations = new ExternalIntegrationModule(config);
|
|
69
|
-
this.websocket = new WebSocketModule(config);
|
|
69
|
+
this.websocket = config.skipWebsocket ? null : new WebSocketModule(config);
|
|
70
70
|
this.reports = new ReportsModule(config);
|
|
71
71
|
this.patients = new PatientModule(config);
|
|
72
72
|
this.dataStrategies = new DataStrategyModule(config);
|
|
@@ -77,7 +77,8 @@ export class ApiSDK extends BaseClient {
|
|
|
77
77
|
this.auth, this.users, this.organizations, this.teams, this.templates,
|
|
78
78
|
this.transcriptionSummaries, this.sessions, this.agents, this.audio,
|
|
79
79
|
this.workflows, this.integrationActions, this.logs, this.debug, this.externalIntegrations,
|
|
80
|
-
this.
|
|
80
|
+
this.reports, this.patients, this.dataStrategies, this.systemSnapshots,
|
|
81
|
+
...(this.websocket ? [this.websocket] : [])
|
|
81
82
|
];
|
|
82
83
|
|
|
83
84
|
// Auto-initialize the SDK
|
|
@@ -751,44 +752,51 @@ export class ApiSDK extends BaseClient {
|
|
|
751
752
|
}
|
|
752
753
|
|
|
753
754
|
// WebSocket methods
|
|
755
|
+
private assertWebSocket(): WebSocketModule {
|
|
756
|
+
if (!this.websocket) {
|
|
757
|
+
throw new Error('WebSocket module is not available. SDK was initialized with skipWebsocket: true');
|
|
758
|
+
}
|
|
759
|
+
return this.websocket;
|
|
760
|
+
}
|
|
761
|
+
|
|
754
762
|
public connectWebSocket() {
|
|
755
|
-
return this.
|
|
763
|
+
return this.assertWebSocket().connect();
|
|
756
764
|
}
|
|
757
765
|
|
|
758
766
|
public disconnectWebSocket() {
|
|
759
|
-
return this.
|
|
767
|
+
return this.assertWebSocket().disconnect();
|
|
760
768
|
}
|
|
761
769
|
|
|
762
770
|
public isWebSocketConnected() {
|
|
763
|
-
return this.websocket
|
|
771
|
+
return this.websocket?.isConnected() ?? false;
|
|
764
772
|
}
|
|
765
773
|
|
|
766
774
|
public streamAudioChunk(...args: Parameters<WebSocketModule['streamAudioChunk']>) {
|
|
767
|
-
return this.
|
|
775
|
+
return this.assertWebSocket().streamAudioChunk(...args);
|
|
768
776
|
}
|
|
769
777
|
|
|
770
778
|
public streamAudioChunks(...args: Parameters<WebSocketModule['streamAudioChunks']>) {
|
|
771
|
-
return this.
|
|
779
|
+
return this.assertWebSocket().streamAudioChunks(...args);
|
|
772
780
|
}
|
|
773
781
|
|
|
774
782
|
public onWebSocketEvent(...args: Parameters<WebSocketModule['on']>) {
|
|
775
|
-
return this.
|
|
783
|
+
return this.assertWebSocket().on(...args);
|
|
776
784
|
}
|
|
777
785
|
|
|
778
786
|
public offWebSocketEvent(...args: Parameters<WebSocketModule['off']>) {
|
|
779
|
-
return this.
|
|
787
|
+
return this.assertWebSocket().off(...args);
|
|
780
788
|
}
|
|
781
789
|
|
|
782
790
|
public getWebSocketStats() {
|
|
783
|
-
return this.
|
|
791
|
+
return this.assertWebSocket().getConnectionStats();
|
|
784
792
|
}
|
|
785
793
|
|
|
786
794
|
public subscribe(...args: Parameters<WebSocketModule['on']>) {
|
|
787
|
-
return this.
|
|
795
|
+
return this.assertWebSocket().on(...args);
|
|
788
796
|
}
|
|
789
797
|
|
|
790
798
|
public unsubscribe(...args: Parameters<WebSocketModule['off']>) {
|
|
791
|
-
return this.
|
|
799
|
+
return this.assertWebSocket().off(...args);
|
|
792
800
|
}
|
|
793
801
|
|
|
794
802
|
// Reports methods
|