whio-api-sdk 1.0.242-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/modules/system-snapshot.module.d.ts +16 -0
- package/dist/src/sdk/modules/system-snapshot.module.js +54 -0
- package/dist/src/sdk/sdk.d.ts +7 -1
- package/dist/src/sdk/sdk.js +38 -12
- package/dist/src/sdk/types/common.types.d.ts +1 -0
- package/dist/src/sdk/types/index.d.ts +1 -0
- package/dist/src/sdk/types/index.js +1 -0
- package/dist/src/sdk/types/system-snapshot.types.d.ts +31 -0
- package/dist/src/sdk/types/system-snapshot.types.js +1 -0
- package/dist/src/sdk/urls.d.ts +1 -0
- package/dist/src/sdk/urls.js +2 -0
- package/package.json +1 -1
- package/src/sdk/modules/base-client.ts +45 -28
- package/src/sdk/modules/system-snapshot.module.ts +59 -0
- package/src/sdk/sdk.ts +39 -15
- package/src/sdk/types/common.types.ts +1 -0
- package/src/sdk/types/index.ts +1 -0
- package/src/sdk/types/system-snapshot.types.ts +34 -0
- package/src/sdk/urls.ts +3 -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
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { BaseClient } from './base-client';
|
|
2
|
+
import { SystemSnapshot, SystemSnapshotsResponse, QuerySnapshotsParams, CurrentMetrics } from '../types';
|
|
3
|
+
export declare class SystemSnapshotModule extends BaseClient {
|
|
4
|
+
/**
|
|
5
|
+
* Get historical system snapshots with optional filtering
|
|
6
|
+
*/
|
|
7
|
+
getSnapshots(params?: QuerySnapshotsParams): Promise<SystemSnapshotsResponse>;
|
|
8
|
+
/**
|
|
9
|
+
* Get the most recent stored snapshot
|
|
10
|
+
*/
|
|
11
|
+
getLatestSnapshot(): Promise<SystemSnapshot | null>;
|
|
12
|
+
/**
|
|
13
|
+
* Get current live metrics without persisting
|
|
14
|
+
*/
|
|
15
|
+
getCurrentMetrics(): Promise<CurrentMetrics>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { BaseClient } from './base-client';
|
|
11
|
+
import urls from '../urls';
|
|
12
|
+
export class SystemSnapshotModule extends BaseClient {
|
|
13
|
+
/**
|
|
14
|
+
* Get historical system snapshots with optional filtering
|
|
15
|
+
*/
|
|
16
|
+
getSnapshots(params) {
|
|
17
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
const searchParams = new URLSearchParams();
|
|
19
|
+
if (params === null || params === void 0 ? void 0 : params.startDate) {
|
|
20
|
+
searchParams.append('startDate', params.startDate);
|
|
21
|
+
}
|
|
22
|
+
if (params === null || params === void 0 ? void 0 : params.endDate) {
|
|
23
|
+
searchParams.append('endDate', params.endDate);
|
|
24
|
+
}
|
|
25
|
+
if ((params === null || params === void 0 ? void 0 : params.limit) !== undefined) {
|
|
26
|
+
searchParams.append('limit', params.limit.toString());
|
|
27
|
+
}
|
|
28
|
+
if ((params === null || params === void 0 ? void 0 : params.offset) !== undefined) {
|
|
29
|
+
searchParams.append('offset', params.offset.toString());
|
|
30
|
+
}
|
|
31
|
+
const queryString = searchParams.toString();
|
|
32
|
+
const url = queryString
|
|
33
|
+
? `${urls.systemSnapshots}?${queryString}`
|
|
34
|
+
: urls.systemSnapshots;
|
|
35
|
+
return this.request(url, 'GET');
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Get the most recent stored snapshot
|
|
40
|
+
*/
|
|
41
|
+
getLatestSnapshot() {
|
|
42
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
return this.request(`${urls.systemSnapshots}/latest`, 'GET');
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Get current live metrics without persisting
|
|
48
|
+
*/
|
|
49
|
+
getCurrentMetrics() {
|
|
50
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
51
|
+
return this.request(`${urls.systemSnapshots}/current`, 'GET');
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
package/dist/src/sdk/sdk.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ import { WebSocketModule } from './modules/websocket.module';
|
|
|
18
18
|
import { ReportsModule } from './modules/reports.module';
|
|
19
19
|
import { PatientModule } from './modules/patient.module';
|
|
20
20
|
import { DataStrategyModule } from './modules/data-strategy.module';
|
|
21
|
+
import { SystemSnapshotModule } from './modules/system-snapshot.module';
|
|
21
22
|
/**
|
|
22
23
|
* Main SDK class that provides access to all domain-specific modules
|
|
23
24
|
*/
|
|
@@ -36,10 +37,11 @@ export declare class ApiSDK extends BaseClient {
|
|
|
36
37
|
readonly logs: LogModule;
|
|
37
38
|
readonly debug: DebugModule;
|
|
38
39
|
readonly externalIntegrations: ExternalIntegrationModule;
|
|
39
|
-
readonly websocket: WebSocketModule;
|
|
40
|
+
readonly websocket: WebSocketModule | null;
|
|
40
41
|
readonly reports: ReportsModule;
|
|
41
42
|
readonly patients: PatientModule;
|
|
42
43
|
readonly dataStrategies: DataStrategyModule;
|
|
44
|
+
readonly systemSnapshots: SystemSnapshotModule;
|
|
43
45
|
private modules;
|
|
44
46
|
private sdkInitialized;
|
|
45
47
|
constructor(config?: SDKConfig);
|
|
@@ -210,6 +212,7 @@ export declare class ApiSDK extends BaseClient {
|
|
|
210
212
|
getExternalIntegration(...args: Parameters<ExternalIntegrationModule['getExternalIntegration']>): Promise<import("./types").ExternalIntegration>;
|
|
211
213
|
updateExternalIntegration(...args: Parameters<ExternalIntegrationModule['updateExternalIntegration']>): Promise<import("./types").ExternalIntegration>;
|
|
212
214
|
deleteExternalIntegration(...args: Parameters<ExternalIntegrationModule['deleteExternalIntegration']>): Promise<void>;
|
|
215
|
+
private assertWebSocket;
|
|
213
216
|
connectWebSocket(): Promise<void>;
|
|
214
217
|
disconnectWebSocket(): void;
|
|
215
218
|
isWebSocketConnected(): boolean;
|
|
@@ -229,4 +232,7 @@ export declare class ApiSDK extends BaseClient {
|
|
|
229
232
|
getDataStrategyByOrganization(...args: Parameters<DataStrategyModule['getDataStrategyByOrganization']>): Promise<import("./types").DataStrategy>;
|
|
230
233
|
updateDataStrategy(...args: Parameters<DataStrategyModule['updateDataStrategy']>): Promise<import("./types").DataStrategy>;
|
|
231
234
|
deleteDataStrategy(...args: Parameters<DataStrategyModule['deleteDataStrategy']>): Promise<void>;
|
|
235
|
+
getSystemSnapshots(...args: Parameters<SystemSnapshotModule['getSnapshots']>): Promise<import("./types").SystemSnapshotsResponse>;
|
|
236
|
+
getLatestSystemSnapshot(...args: Parameters<SystemSnapshotModule['getLatestSnapshot']>): Promise<import("./types").SystemSnapshot | null>;
|
|
237
|
+
getCurrentSystemMetrics(...args: Parameters<SystemSnapshotModule['getCurrentMetrics']>): Promise<import("./types").CurrentMetrics>;
|
|
232
238
|
}
|
package/dist/src/sdk/sdk.js
CHANGED
|
@@ -26,6 +26,7 @@ import { WebSocketModule } from './modules/websocket.module';
|
|
|
26
26
|
import { ReportsModule } from './modules/reports.module';
|
|
27
27
|
import { PatientModule } from './modules/patient.module';
|
|
28
28
|
import { DataStrategyModule } from './modules/data-strategy.module';
|
|
29
|
+
import { SystemSnapshotModule } from './modules/system-snapshot.module';
|
|
29
30
|
/**
|
|
30
31
|
* Main SDK class that provides access to all domain-specific modules
|
|
31
32
|
*/
|
|
@@ -48,16 +49,18 @@ export class ApiSDK extends BaseClient {
|
|
|
48
49
|
this.logs = new LogModule(config);
|
|
49
50
|
this.debug = new DebugModule(config);
|
|
50
51
|
this.externalIntegrations = new ExternalIntegrationModule(config);
|
|
51
|
-
this.websocket = new WebSocketModule(config);
|
|
52
|
+
this.websocket = config.skipWebsocket ? null : new WebSocketModule(config);
|
|
52
53
|
this.reports = new ReportsModule(config);
|
|
53
54
|
this.patients = new PatientModule(config);
|
|
54
55
|
this.dataStrategies = new DataStrategyModule(config);
|
|
56
|
+
this.systemSnapshots = new SystemSnapshotModule(config);
|
|
55
57
|
// Store all modules for batch operations
|
|
56
58
|
this.modules = [
|
|
57
59
|
this.auth, this.users, this.organizations, this.teams, this.templates,
|
|
58
60
|
this.transcriptionSummaries, this.sessions, this.agents, this.audio,
|
|
59
61
|
this.workflows, this.integrationActions, this.logs, this.debug, this.externalIntegrations,
|
|
60
|
-
this.
|
|
62
|
+
this.reports, this.patients, this.dataStrategies, this.systemSnapshots,
|
|
63
|
+
...(this.websocket ? [this.websocket] : [])
|
|
61
64
|
];
|
|
62
65
|
// Auto-initialize the SDK
|
|
63
66
|
this.initialize().catch(error => {
|
|
@@ -870,35 +873,42 @@ export class ApiSDK extends BaseClient {
|
|
|
870
873
|
});
|
|
871
874
|
}
|
|
872
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
|
+
}
|
|
873
882
|
connectWebSocket() {
|
|
874
|
-
return this.
|
|
883
|
+
return this.assertWebSocket().connect();
|
|
875
884
|
}
|
|
876
885
|
disconnectWebSocket() {
|
|
877
|
-
return this.
|
|
886
|
+
return this.assertWebSocket().disconnect();
|
|
878
887
|
}
|
|
879
888
|
isWebSocketConnected() {
|
|
880
|
-
|
|
889
|
+
var _a, _b;
|
|
890
|
+
return (_b = (_a = this.websocket) === null || _a === void 0 ? void 0 : _a.isConnected()) !== null && _b !== void 0 ? _b : false;
|
|
881
891
|
}
|
|
882
892
|
streamAudioChunk(...args) {
|
|
883
|
-
return this.
|
|
893
|
+
return this.assertWebSocket().streamAudioChunk(...args);
|
|
884
894
|
}
|
|
885
895
|
streamAudioChunks(...args) {
|
|
886
|
-
return this.
|
|
896
|
+
return this.assertWebSocket().streamAudioChunks(...args);
|
|
887
897
|
}
|
|
888
898
|
onWebSocketEvent(...args) {
|
|
889
|
-
return this.
|
|
899
|
+
return this.assertWebSocket().on(...args);
|
|
890
900
|
}
|
|
891
901
|
offWebSocketEvent(...args) {
|
|
892
|
-
return this.
|
|
902
|
+
return this.assertWebSocket().off(...args);
|
|
893
903
|
}
|
|
894
904
|
getWebSocketStats() {
|
|
895
|
-
return this.
|
|
905
|
+
return this.assertWebSocket().getConnectionStats();
|
|
896
906
|
}
|
|
897
907
|
subscribe(...args) {
|
|
898
|
-
return this.
|
|
908
|
+
return this.assertWebSocket().on(...args);
|
|
899
909
|
}
|
|
900
910
|
unsubscribe(...args) {
|
|
901
|
-
return this.
|
|
911
|
+
return this.assertWebSocket().off(...args);
|
|
902
912
|
}
|
|
903
913
|
// Reports methods
|
|
904
914
|
getCompanyDailyReportCsv(...args) {
|
|
@@ -948,4 +958,20 @@ export class ApiSDK extends BaseClient {
|
|
|
948
958
|
return this.dataStrategies.deleteDataStrategy(...args);
|
|
949
959
|
});
|
|
950
960
|
}
|
|
961
|
+
// SystemSnapshot methods
|
|
962
|
+
getSystemSnapshots(...args) {
|
|
963
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
964
|
+
return this.systemSnapshots.getSnapshots(...args);
|
|
965
|
+
});
|
|
966
|
+
}
|
|
967
|
+
getLatestSystemSnapshot(...args) {
|
|
968
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
969
|
+
return this.systemSnapshots.getLatestSnapshot(...args);
|
|
970
|
+
});
|
|
971
|
+
}
|
|
972
|
+
getCurrentSystemMetrics(...args) {
|
|
973
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
974
|
+
return this.systemSnapshots.getCurrentMetrics(...args);
|
|
975
|
+
});
|
|
976
|
+
}
|
|
951
977
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export interface SystemSnapshot {
|
|
2
|
+
id: string;
|
|
3
|
+
websocketConnectionCount: number;
|
|
4
|
+
transcriptionQueueSize: number;
|
|
5
|
+
summaryQueueSize: number;
|
|
6
|
+
systemRamUsageBytes: string;
|
|
7
|
+
systemRamTotalBytes: string;
|
|
8
|
+
systemCpuUsagePercent: number;
|
|
9
|
+
createdAt: string;
|
|
10
|
+
}
|
|
11
|
+
export interface SystemSnapshotsResponse {
|
|
12
|
+
data: SystemSnapshot[];
|
|
13
|
+
total: number;
|
|
14
|
+
limit: number;
|
|
15
|
+
offset: number;
|
|
16
|
+
}
|
|
17
|
+
export interface QuerySnapshotsParams {
|
|
18
|
+
startDate?: string;
|
|
19
|
+
endDate?: string;
|
|
20
|
+
limit?: number;
|
|
21
|
+
offset?: number;
|
|
22
|
+
}
|
|
23
|
+
export interface CurrentMetrics {
|
|
24
|
+
websocketConnectionCount: number;
|
|
25
|
+
transcriptionQueueSize: number;
|
|
26
|
+
summaryQueueSize: number;
|
|
27
|
+
systemRamUsageBytes: string;
|
|
28
|
+
systemRamTotalBytes: string;
|
|
29
|
+
systemCpuUsagePercent: number;
|
|
30
|
+
capturedAt: string;
|
|
31
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/src/sdk/urls.d.ts
CHANGED
package/dist/src/sdk/urls.js
CHANGED
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
|
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { BaseClient } from './base-client';
|
|
2
|
+
import {
|
|
3
|
+
SystemSnapshot,
|
|
4
|
+
SystemSnapshotsResponse,
|
|
5
|
+
QuerySnapshotsParams,
|
|
6
|
+
CurrentMetrics,
|
|
7
|
+
} from '../types';
|
|
8
|
+
import urls from '../urls';
|
|
9
|
+
|
|
10
|
+
export class SystemSnapshotModule extends BaseClient {
|
|
11
|
+
/**
|
|
12
|
+
* Get historical system snapshots with optional filtering
|
|
13
|
+
*/
|
|
14
|
+
public async getSnapshots(
|
|
15
|
+
params?: QuerySnapshotsParams,
|
|
16
|
+
): Promise<SystemSnapshotsResponse> {
|
|
17
|
+
const searchParams = new URLSearchParams();
|
|
18
|
+
|
|
19
|
+
if (params?.startDate) {
|
|
20
|
+
searchParams.append('startDate', params.startDate);
|
|
21
|
+
}
|
|
22
|
+
if (params?.endDate) {
|
|
23
|
+
searchParams.append('endDate', params.endDate);
|
|
24
|
+
}
|
|
25
|
+
if (params?.limit !== undefined) {
|
|
26
|
+
searchParams.append('limit', params.limit.toString());
|
|
27
|
+
}
|
|
28
|
+
if (params?.offset !== undefined) {
|
|
29
|
+
searchParams.append('offset', params.offset.toString());
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const queryString = searchParams.toString();
|
|
33
|
+
const url = queryString
|
|
34
|
+
? `${urls.systemSnapshots}?${queryString}`
|
|
35
|
+
: urls.systemSnapshots;
|
|
36
|
+
|
|
37
|
+
return this.request<SystemSnapshotsResponse>(url, 'GET');
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Get the most recent stored snapshot
|
|
42
|
+
*/
|
|
43
|
+
public async getLatestSnapshot(): Promise<SystemSnapshot | null> {
|
|
44
|
+
return this.request<SystemSnapshot | null>(
|
|
45
|
+
`${urls.systemSnapshots}/latest`,
|
|
46
|
+
'GET',
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Get current live metrics without persisting
|
|
52
|
+
*/
|
|
53
|
+
public async getCurrentMetrics(): Promise<CurrentMetrics> {
|
|
54
|
+
return this.request<CurrentMetrics>(
|
|
55
|
+
`${urls.systemSnapshots}/current`,
|
|
56
|
+
'GET',
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
}
|
package/src/sdk/sdk.ts
CHANGED
|
@@ -19,6 +19,7 @@ import { WebSocketModule } from './modules/websocket.module';
|
|
|
19
19
|
import { ReportsModule } from './modules/reports.module';
|
|
20
20
|
import { PatientModule } from './modules/patient.module';
|
|
21
21
|
import { DataStrategyModule } from './modules/data-strategy.module';
|
|
22
|
+
import { SystemSnapshotModule } from './modules/system-snapshot.module';
|
|
22
23
|
|
|
23
24
|
/**
|
|
24
25
|
* Main SDK class that provides access to all domain-specific modules
|
|
@@ -38,11 +39,12 @@ export class ApiSDK extends BaseClient {
|
|
|
38
39
|
public readonly logs: LogModule;
|
|
39
40
|
public readonly debug: DebugModule;
|
|
40
41
|
public readonly externalIntegrations: ExternalIntegrationModule;
|
|
41
|
-
public readonly websocket: WebSocketModule;
|
|
42
|
+
public readonly websocket: WebSocketModule | null;
|
|
42
43
|
public readonly reports: ReportsModule;
|
|
43
44
|
public readonly patients: PatientModule;
|
|
44
45
|
public readonly dataStrategies: DataStrategyModule;
|
|
45
|
-
|
|
46
|
+
public readonly systemSnapshots: SystemSnapshotModule;
|
|
47
|
+
|
|
46
48
|
private modules: BaseClient[];
|
|
47
49
|
private sdkInitialized: boolean = false;
|
|
48
50
|
|
|
@@ -64,17 +66,19 @@ export class ApiSDK extends BaseClient {
|
|
|
64
66
|
this.logs = new LogModule(config);
|
|
65
67
|
this.debug = new DebugModule(config);
|
|
66
68
|
this.externalIntegrations = new ExternalIntegrationModule(config);
|
|
67
|
-
this.websocket = new WebSocketModule(config);
|
|
69
|
+
this.websocket = config.skipWebsocket ? null : new WebSocketModule(config);
|
|
68
70
|
this.reports = new ReportsModule(config);
|
|
69
71
|
this.patients = new PatientModule(config);
|
|
70
72
|
this.dataStrategies = new DataStrategyModule(config);
|
|
71
|
-
|
|
73
|
+
this.systemSnapshots = new SystemSnapshotModule(config);
|
|
74
|
+
|
|
72
75
|
// Store all modules for batch operations
|
|
73
76
|
this.modules = [
|
|
74
77
|
this.auth, this.users, this.organizations, this.teams, this.templates,
|
|
75
78
|
this.transcriptionSummaries, this.sessions, this.agents, this.audio,
|
|
76
79
|
this.workflows, this.integrationActions, this.logs, this.debug, this.externalIntegrations,
|
|
77
|
-
this.
|
|
80
|
+
this.reports, this.patients, this.dataStrategies, this.systemSnapshots,
|
|
81
|
+
...(this.websocket ? [this.websocket] : [])
|
|
78
82
|
];
|
|
79
83
|
|
|
80
84
|
// Auto-initialize the SDK
|
|
@@ -748,44 +752,51 @@ export class ApiSDK extends BaseClient {
|
|
|
748
752
|
}
|
|
749
753
|
|
|
750
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
|
+
|
|
751
762
|
public connectWebSocket() {
|
|
752
|
-
return this.
|
|
763
|
+
return this.assertWebSocket().connect();
|
|
753
764
|
}
|
|
754
765
|
|
|
755
766
|
public disconnectWebSocket() {
|
|
756
|
-
return this.
|
|
767
|
+
return this.assertWebSocket().disconnect();
|
|
757
768
|
}
|
|
758
769
|
|
|
759
770
|
public isWebSocketConnected() {
|
|
760
|
-
return this.websocket
|
|
771
|
+
return this.websocket?.isConnected() ?? false;
|
|
761
772
|
}
|
|
762
773
|
|
|
763
774
|
public streamAudioChunk(...args: Parameters<WebSocketModule['streamAudioChunk']>) {
|
|
764
|
-
return this.
|
|
775
|
+
return this.assertWebSocket().streamAudioChunk(...args);
|
|
765
776
|
}
|
|
766
777
|
|
|
767
778
|
public streamAudioChunks(...args: Parameters<WebSocketModule['streamAudioChunks']>) {
|
|
768
|
-
return this.
|
|
779
|
+
return this.assertWebSocket().streamAudioChunks(...args);
|
|
769
780
|
}
|
|
770
781
|
|
|
771
782
|
public onWebSocketEvent(...args: Parameters<WebSocketModule['on']>) {
|
|
772
|
-
return this.
|
|
783
|
+
return this.assertWebSocket().on(...args);
|
|
773
784
|
}
|
|
774
785
|
|
|
775
786
|
public offWebSocketEvent(...args: Parameters<WebSocketModule['off']>) {
|
|
776
|
-
return this.
|
|
787
|
+
return this.assertWebSocket().off(...args);
|
|
777
788
|
}
|
|
778
789
|
|
|
779
790
|
public getWebSocketStats() {
|
|
780
|
-
return this.
|
|
791
|
+
return this.assertWebSocket().getConnectionStats();
|
|
781
792
|
}
|
|
782
793
|
|
|
783
794
|
public subscribe(...args: Parameters<WebSocketModule['on']>) {
|
|
784
|
-
return this.
|
|
795
|
+
return this.assertWebSocket().on(...args);
|
|
785
796
|
}
|
|
786
797
|
|
|
787
798
|
public unsubscribe(...args: Parameters<WebSocketModule['off']>) {
|
|
788
|
-
return this.
|
|
799
|
+
return this.assertWebSocket().off(...args);
|
|
789
800
|
}
|
|
790
801
|
|
|
791
802
|
// Reports methods
|
|
@@ -827,4 +838,17 @@ export class ApiSDK extends BaseClient {
|
|
|
827
838
|
return this.dataStrategies.deleteDataStrategy(...args);
|
|
828
839
|
}
|
|
829
840
|
|
|
841
|
+
// SystemSnapshot methods
|
|
842
|
+
public async getSystemSnapshots(...args: Parameters<SystemSnapshotModule['getSnapshots']>) {
|
|
843
|
+
return this.systemSnapshots.getSnapshots(...args);
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
public async getLatestSystemSnapshot(...args: Parameters<SystemSnapshotModule['getLatestSnapshot']>) {
|
|
847
|
+
return this.systemSnapshots.getLatestSnapshot(...args);
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
public async getCurrentSystemMetrics(...args: Parameters<SystemSnapshotModule['getCurrentMetrics']>) {
|
|
851
|
+
return this.systemSnapshots.getCurrentMetrics(...args);
|
|
852
|
+
}
|
|
853
|
+
|
|
830
854
|
}
|
package/src/sdk/types/index.ts
CHANGED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export interface SystemSnapshot {
|
|
2
|
+
id: string;
|
|
3
|
+
websocketConnectionCount: number;
|
|
4
|
+
transcriptionQueueSize: number;
|
|
5
|
+
summaryQueueSize: number;
|
|
6
|
+
systemRamUsageBytes: string;
|
|
7
|
+
systemRamTotalBytes: string;
|
|
8
|
+
systemCpuUsagePercent: number;
|
|
9
|
+
createdAt: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface SystemSnapshotsResponse {
|
|
13
|
+
data: SystemSnapshot[];
|
|
14
|
+
total: number;
|
|
15
|
+
limit: number;
|
|
16
|
+
offset: number;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface QuerySnapshotsParams {
|
|
20
|
+
startDate?: string;
|
|
21
|
+
endDate?: string;
|
|
22
|
+
limit?: number;
|
|
23
|
+
offset?: number;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface CurrentMetrics {
|
|
27
|
+
websocketConnectionCount: number;
|
|
28
|
+
transcriptionQueueSize: number;
|
|
29
|
+
summaryQueueSize: number;
|
|
30
|
+
systemRamUsageBytes: string;
|
|
31
|
+
systemRamTotalBytes: string;
|
|
32
|
+
systemCpuUsagePercent: number;
|
|
33
|
+
capturedAt: string;
|
|
34
|
+
}
|