@hipnation-truth/sdk 0.25.3 → 0.26.0
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/index.d.mts +6 -18
- package/dist/index.d.ts +6 -18
- package/dist/index.js +43 -29
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +43 -29
- package/dist/index.mjs.map +1 -1
- package/dist/react.d.ts +6 -18
- package/dist/react.js +43 -29
- package/dist/react.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -239,19 +239,6 @@ declare class AttachmentsResource {
|
|
|
239
239
|
}>;
|
|
240
240
|
}
|
|
241
241
|
|
|
242
|
-
/**
|
|
243
|
-
* ConversationsResource — write methods that hang off a specific
|
|
244
|
-
* conversation: notes, tasks, outbound messages.
|
|
245
|
-
*
|
|
246
|
-
* Replaces CommHub's `truthConversationApi.ts` raw-fetch wrappers so
|
|
247
|
-
* the frontend goes through a typed SDK surface instead of building
|
|
248
|
-
* URLs by hand.
|
|
249
|
-
*
|
|
250
|
-
* All methods proxy the matching oRPC procedures (`/conversations/*`)
|
|
251
|
-
* via Truth's application-key auth. Errors surface as
|
|
252
|
-
* `ConversationsError` with a status code so callers can distinguish
|
|
253
|
-
* transport failures (status=0) from API rejections (status>=400).
|
|
254
|
-
*/
|
|
255
242
|
/** Address a conversation by either Convex `_id` or the phonePair. */
|
|
256
243
|
interface ConversationAddress {
|
|
257
244
|
conversationId?: string;
|
|
@@ -383,8 +370,9 @@ declare class ConversationsResource {
|
|
|
383
370
|
private static readonly REQUEST_TIMEOUT_MS;
|
|
384
371
|
private readonly baseUrl;
|
|
385
372
|
private readonly apiKey;
|
|
373
|
+
private readonly auth;
|
|
386
374
|
private readonly convex;
|
|
387
|
-
constructor(apiBaseUrl: string, apiKey: string, convex?: convex_browser.ConvexHttpClient);
|
|
375
|
+
constructor(apiBaseUrl: string, apiKey: string, convex?: convex_browser.ConvexHttpClient, getAuthToken?: AuthTokenFetcher);
|
|
388
376
|
/**
|
|
389
377
|
* Mark a conversation read for the calling user (zeroes unreadCount,
|
|
390
378
|
* stamps `lastReadAt`). Calls the public Convex `markRead` mutation
|
|
@@ -592,12 +580,12 @@ declare class DialpadProxyError extends Error {
|
|
|
592
580
|
* const hintPatient = await truth.ehr.hint.get('/provider/patients/456');
|
|
593
581
|
* ```
|
|
594
582
|
*/
|
|
583
|
+
|
|
595
584
|
declare class EhrProviderProxy {
|
|
596
585
|
private readonly baseUrl;
|
|
597
586
|
private readonly provider;
|
|
598
|
-
private readonly
|
|
599
|
-
constructor(apiBaseUrl: string, provider: string, apiKey: string);
|
|
600
|
-
private headers;
|
|
587
|
+
private readonly auth;
|
|
588
|
+
constructor(apiBaseUrl: string, provider: string, apiKey: string, getAuthToken?: AuthTokenFetcher);
|
|
601
589
|
private request;
|
|
602
590
|
/**
|
|
603
591
|
* GET request to the EHR proxy.
|
|
@@ -619,7 +607,7 @@ declare class EhrResource {
|
|
|
619
607
|
readonly elation: EhrProviderProxy;
|
|
620
608
|
/** Hint Health proxy */
|
|
621
609
|
readonly hint: EhrProviderProxy;
|
|
622
|
-
constructor(apiBaseUrl: string, apiKey: string);
|
|
610
|
+
constructor(apiBaseUrl: string, apiKey: string, getAuthToken?: AuthTokenFetcher);
|
|
623
611
|
}
|
|
624
612
|
declare class EhrProxyError extends Error {
|
|
625
613
|
readonly provider: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -239,19 +239,6 @@ declare class AttachmentsResource {
|
|
|
239
239
|
}>;
|
|
240
240
|
}
|
|
241
241
|
|
|
242
|
-
/**
|
|
243
|
-
* ConversationsResource — write methods that hang off a specific
|
|
244
|
-
* conversation: notes, tasks, outbound messages.
|
|
245
|
-
*
|
|
246
|
-
* Replaces CommHub's `truthConversationApi.ts` raw-fetch wrappers so
|
|
247
|
-
* the frontend goes through a typed SDK surface instead of building
|
|
248
|
-
* URLs by hand.
|
|
249
|
-
*
|
|
250
|
-
* All methods proxy the matching oRPC procedures (`/conversations/*`)
|
|
251
|
-
* via Truth's application-key auth. Errors surface as
|
|
252
|
-
* `ConversationsError` with a status code so callers can distinguish
|
|
253
|
-
* transport failures (status=0) from API rejections (status>=400).
|
|
254
|
-
*/
|
|
255
242
|
/** Address a conversation by either Convex `_id` or the phonePair. */
|
|
256
243
|
interface ConversationAddress {
|
|
257
244
|
conversationId?: string;
|
|
@@ -383,8 +370,9 @@ declare class ConversationsResource {
|
|
|
383
370
|
private static readonly REQUEST_TIMEOUT_MS;
|
|
384
371
|
private readonly baseUrl;
|
|
385
372
|
private readonly apiKey;
|
|
373
|
+
private readonly auth;
|
|
386
374
|
private readonly convex;
|
|
387
|
-
constructor(apiBaseUrl: string, apiKey: string, convex?: convex_browser.ConvexHttpClient);
|
|
375
|
+
constructor(apiBaseUrl: string, apiKey: string, convex?: convex_browser.ConvexHttpClient, getAuthToken?: AuthTokenFetcher);
|
|
388
376
|
/**
|
|
389
377
|
* Mark a conversation read for the calling user (zeroes unreadCount,
|
|
390
378
|
* stamps `lastReadAt`). Calls the public Convex `markRead` mutation
|
|
@@ -592,12 +580,12 @@ declare class DialpadProxyError extends Error {
|
|
|
592
580
|
* const hintPatient = await truth.ehr.hint.get('/provider/patients/456');
|
|
593
581
|
* ```
|
|
594
582
|
*/
|
|
583
|
+
|
|
595
584
|
declare class EhrProviderProxy {
|
|
596
585
|
private readonly baseUrl;
|
|
597
586
|
private readonly provider;
|
|
598
|
-
private readonly
|
|
599
|
-
constructor(apiBaseUrl: string, provider: string, apiKey: string);
|
|
600
|
-
private headers;
|
|
587
|
+
private readonly auth;
|
|
588
|
+
constructor(apiBaseUrl: string, provider: string, apiKey: string, getAuthToken?: AuthTokenFetcher);
|
|
601
589
|
private request;
|
|
602
590
|
/**
|
|
603
591
|
* GET request to the EHR proxy.
|
|
@@ -619,7 +607,7 @@ declare class EhrResource {
|
|
|
619
607
|
readonly elation: EhrProviderProxy;
|
|
620
608
|
/** Hint Health proxy */
|
|
621
609
|
readonly hint: EhrProviderProxy;
|
|
622
|
-
constructor(apiBaseUrl: string, apiKey: string);
|
|
610
|
+
constructor(apiBaseUrl: string, apiKey: string, getAuthToken?: AuthTokenFetcher);
|
|
623
611
|
}
|
|
624
612
|
declare class EhrProxyError extends Error {
|
|
625
613
|
readonly provider: string;
|
package/dist/index.js
CHANGED
|
@@ -352,6 +352,31 @@ var AttachmentsResource = class {
|
|
|
352
352
|
}
|
|
353
353
|
};
|
|
354
354
|
|
|
355
|
+
// src/resources/rest-auth.ts
|
|
356
|
+
function buildAuthHeaders(auth, options) {
|
|
357
|
+
return __async(this, null, function* () {
|
|
358
|
+
const headers = {
|
|
359
|
+
"X-API-Key": auth.apiKey
|
|
360
|
+
};
|
|
361
|
+
if ((options == null ? void 0 : options.accept) !== false) {
|
|
362
|
+
headers.Accept = "application/json";
|
|
363
|
+
}
|
|
364
|
+
if (options == null ? void 0 : options.json) {
|
|
365
|
+
headers["Content-Type"] = "application/json";
|
|
366
|
+
}
|
|
367
|
+
if (auth.getAuthToken) {
|
|
368
|
+
try {
|
|
369
|
+
const token = yield auth.getAuthToken();
|
|
370
|
+
if (token) {
|
|
371
|
+
headers.Authorization = `Bearer ${token}`;
|
|
372
|
+
}
|
|
373
|
+
} catch (e) {
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
return headers;
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
|
|
355
380
|
// src/resources/conversations.ts
|
|
356
381
|
var ConversationsError = class extends Error {
|
|
357
382
|
constructor(operation, status, message) {
|
|
@@ -464,9 +489,10 @@ var ConversationMessagesSubresource = class {
|
|
|
464
489
|
}
|
|
465
490
|
};
|
|
466
491
|
var _ConversationsResource = class _ConversationsResource {
|
|
467
|
-
constructor(apiBaseUrl, apiKey, convex) {
|
|
492
|
+
constructor(apiBaseUrl, apiKey, convex, getAuthToken) {
|
|
468
493
|
this.baseUrl = apiBaseUrl;
|
|
469
494
|
this.apiKey = apiKey;
|
|
495
|
+
this.auth = { apiKey, getAuthToken };
|
|
470
496
|
this.convex = convex != null ? convex : null;
|
|
471
497
|
const post = (path, body) => this.postRequest(path, body);
|
|
472
498
|
const patch = (path, body) => this.patchRequest(path, body);
|
|
@@ -549,11 +575,7 @@ var _ConversationsResource = class _ConversationsResource {
|
|
|
549
575
|
try {
|
|
550
576
|
res = yield fetch(`${this.baseUrl}/api${path}`, {
|
|
551
577
|
method: "POST",
|
|
552
|
-
headers: {
|
|
553
|
-
"Content-Type": "application/json",
|
|
554
|
-
Accept: "application/json",
|
|
555
|
-
"X-API-Key": this.apiKey
|
|
556
|
-
},
|
|
578
|
+
headers: yield buildAuthHeaders(this.auth, { json: true }),
|
|
557
579
|
body: JSON.stringify(body),
|
|
558
580
|
signal: controller.signal
|
|
559
581
|
});
|
|
@@ -595,11 +617,7 @@ var _ConversationsResource = class _ConversationsResource {
|
|
|
595
617
|
try {
|
|
596
618
|
res = yield fetch(`${this.baseUrl}/api${path}`, {
|
|
597
619
|
method: "PATCH",
|
|
598
|
-
headers: {
|
|
599
|
-
"Content-Type": "application/json",
|
|
600
|
-
Accept: "application/json",
|
|
601
|
-
"X-API-Key": this.apiKey
|
|
602
|
-
},
|
|
620
|
+
headers: yield buildAuthHeaders(this.auth, { json: true }),
|
|
603
621
|
body: JSON.stringify(body),
|
|
604
622
|
signal: controller.signal
|
|
605
623
|
});
|
|
@@ -933,20 +951,10 @@ var DialpadProxyError = class extends Error {
|
|
|
933
951
|
|
|
934
952
|
// src/resources/ehr.ts
|
|
935
953
|
var EhrProviderProxy = class {
|
|
936
|
-
constructor(apiBaseUrl, provider, apiKey) {
|
|
954
|
+
constructor(apiBaseUrl, provider, apiKey, getAuthToken) {
|
|
937
955
|
this.baseUrl = apiBaseUrl;
|
|
938
956
|
this.provider = provider;
|
|
939
|
-
this.
|
|
940
|
-
}
|
|
941
|
-
headers(withBody) {
|
|
942
|
-
const headers = {
|
|
943
|
-
Accept: "application/json",
|
|
944
|
-
"X-API-Key": this.apiKey
|
|
945
|
-
};
|
|
946
|
-
if (withBody) {
|
|
947
|
-
headers["Content-Type"] = "application/json";
|
|
948
|
-
}
|
|
949
|
-
return headers;
|
|
957
|
+
this.auth = { apiKey, getAuthToken };
|
|
950
958
|
}
|
|
951
959
|
request(method, path, body, params) {
|
|
952
960
|
return __async(this, null, function* () {
|
|
@@ -960,7 +968,7 @@ var EhrProviderProxy = class {
|
|
|
960
968
|
}
|
|
961
969
|
const response = yield fetch(url.toString(), {
|
|
962
970
|
method,
|
|
963
|
-
headers: this.
|
|
971
|
+
headers: yield buildAuthHeaders(this.auth, { json: body !== void 0 }),
|
|
964
972
|
body: body !== void 0 ? JSON.stringify(body) : void 0
|
|
965
973
|
});
|
|
966
974
|
if (!response.ok) {
|
|
@@ -1005,9 +1013,14 @@ var EhrProviderProxy = class {
|
|
|
1005
1013
|
}
|
|
1006
1014
|
};
|
|
1007
1015
|
var EhrResource = class {
|
|
1008
|
-
constructor(apiBaseUrl, apiKey) {
|
|
1009
|
-
this.elation = new EhrProviderProxy(
|
|
1010
|
-
|
|
1016
|
+
constructor(apiBaseUrl, apiKey, getAuthToken) {
|
|
1017
|
+
this.elation = new EhrProviderProxy(
|
|
1018
|
+
apiBaseUrl,
|
|
1019
|
+
"elation",
|
|
1020
|
+
apiKey,
|
|
1021
|
+
getAuthToken
|
|
1022
|
+
);
|
|
1023
|
+
this.hint = new EhrProviderProxy(apiBaseUrl, "hint", apiKey, getAuthToken);
|
|
1011
1024
|
}
|
|
1012
1025
|
};
|
|
1013
1026
|
var EhrProxyError = class extends Error {
|
|
@@ -1972,7 +1985,7 @@ var TruthClient = class {
|
|
|
1972
1985
|
const apiUrl = this.tracker.apiUrl;
|
|
1973
1986
|
this.patients = new PatientResource(this.convex);
|
|
1974
1987
|
this.appointments = new AppointmentResource(this.convex);
|
|
1975
|
-
this.ehr = new EhrResource(apiUrl, config.apiKey);
|
|
1988
|
+
this.ehr = new EhrResource(apiUrl, config.apiKey, config.getAuthToken);
|
|
1976
1989
|
this.messages = new MessagesResource(apiUrl, config.apiKey);
|
|
1977
1990
|
this.reminders = new RemindersResource(this.convex);
|
|
1978
1991
|
this.translation = new TranslationResource(apiUrl, config.apiKey);
|
|
@@ -1989,7 +2002,8 @@ var TruthClient = class {
|
|
|
1989
2002
|
this.conversations = new ConversationsResource(
|
|
1990
2003
|
apiUrl,
|
|
1991
2004
|
config.apiKey,
|
|
1992
|
-
this.convex
|
|
2005
|
+
this.convex,
|
|
2006
|
+
config.getAuthToken
|
|
1993
2007
|
);
|
|
1994
2008
|
this.userSettings = new UserSettingsResource(this.convex);
|
|
1995
2009
|
this._serviceWorkerPath = (_h = config.serviceWorkerPath) != null ? _h : "/truth-sw.js";
|