@hipnation-truth/sdk 0.26.0 → 0.26.2
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 +27 -7
- package/dist/index.d.ts +27 -7
- package/dist/index.js +101 -100
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +101 -100
- package/dist/index.mjs.map +1 -1
- package/dist/react.d.ts +27 -7
- package/dist/react.js +101 -100
- package/dist/react.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -202,8 +202,9 @@ declare class AttachmentsError extends Error {
|
|
|
202
202
|
declare class AttachmentsResource {
|
|
203
203
|
private readonly baseUrl;
|
|
204
204
|
private readonly apiKey;
|
|
205
|
+
private readonly auth;
|
|
205
206
|
private readonly convex;
|
|
206
|
-
constructor(apiBaseUrl: string, apiKey: string, convexClient: ConvexHttpClient);
|
|
207
|
+
constructor(apiBaseUrl: string, apiKey: string, convexClient: ConvexHttpClient, getAuthToken?: AuthTokenFetcher);
|
|
207
208
|
private post;
|
|
208
209
|
createUploadUrl(input: CreateUploadUrlInput): Promise<CreateUploadUrlResult>;
|
|
209
210
|
getDownloadUrl(s3Key: string, expiresIn?: number): Promise<GetDownloadUrlResult>;
|
|
@@ -424,6 +425,7 @@ declare class ConversationsResource {
|
|
|
424
425
|
* const url = await truth.messages.dialpad.authenticateVoicemail(voicemailLink);
|
|
425
426
|
* ```
|
|
426
427
|
*/
|
|
428
|
+
|
|
427
429
|
interface SendSmsParams {
|
|
428
430
|
from_number: string;
|
|
429
431
|
to_number: string;
|
|
@@ -463,7 +465,8 @@ interface VoicemailAuthResponse {
|
|
|
463
465
|
declare class DialpadResource {
|
|
464
466
|
private readonly baseUrl;
|
|
465
467
|
private readonly apiKey;
|
|
466
|
-
|
|
468
|
+
private readonly auth;
|
|
469
|
+
constructor(apiBaseUrl: string, apiKey: string, getAuthToken?: AuthTokenFetcher);
|
|
467
470
|
/**
|
|
468
471
|
* Send an SMS or MMS message via Dialpad.
|
|
469
472
|
*/
|
|
@@ -528,7 +531,8 @@ declare class MessagesResource {
|
|
|
528
531
|
readonly dialpad: DialpadResource;
|
|
529
532
|
private readonly baseUrl;
|
|
530
533
|
private readonly apiKey;
|
|
531
|
-
|
|
534
|
+
private readonly auth;
|
|
535
|
+
constructor(apiBaseUrl: string, apiKey: string, getAuthToken?: AuthTokenFetcher);
|
|
532
536
|
/**
|
|
533
537
|
* Get an authenticated URL for a Dialpad voicemail recording.
|
|
534
538
|
*
|
|
@@ -624,6 +628,7 @@ declare class EhrProxyError extends Error {
|
|
|
624
628
|
* OAuth token and the HTTP call so applications can drop Elation
|
|
625
629
|
* credentials from their own config.
|
|
626
630
|
*/
|
|
631
|
+
|
|
627
632
|
interface NonVisitNoteBullet {
|
|
628
633
|
text: string;
|
|
629
634
|
category?: string;
|
|
@@ -672,7 +677,8 @@ interface PushConversationToElationResult {
|
|
|
672
677
|
declare class NotesResource {
|
|
673
678
|
private readonly baseUrl;
|
|
674
679
|
private readonly apiKey;
|
|
675
|
-
|
|
680
|
+
private readonly auth;
|
|
681
|
+
constructor(apiBaseUrl: string, apiKey: string, getAuthToken?: AuthTokenFetcher);
|
|
676
682
|
/** 30s upstream timeout — Elation API has occasional slow hops; we
|
|
677
683
|
* don't want a pending mutation to hold the UI thread indefinitely. */
|
|
678
684
|
private static readonly REQUEST_TIMEOUT_MS;
|
|
@@ -702,6 +708,7 @@ declare class NotesResource {
|
|
|
702
708
|
* Client-side React usage lives in `@hipnation-truth/sdk/react` via
|
|
703
709
|
* the `useNotifications` hook which mirrors `expo-notifications`.
|
|
704
710
|
*/
|
|
711
|
+
|
|
705
712
|
type NotificationPlatform = "ios" | "android" | "web";
|
|
706
713
|
interface RegisterDeviceInput {
|
|
707
714
|
userId: string;
|
|
@@ -816,7 +823,8 @@ declare class NotificationsError extends Error {
|
|
|
816
823
|
declare class NotificationsResource {
|
|
817
824
|
private readonly baseUrl;
|
|
818
825
|
private readonly apiKey;
|
|
819
|
-
|
|
826
|
+
private readonly auth;
|
|
827
|
+
constructor(apiBaseUrl: string, apiKey: string, getAuthToken?: AuthTokenFetcher);
|
|
820
828
|
private post;
|
|
821
829
|
private get;
|
|
822
830
|
private delete;
|
|
@@ -874,6 +882,7 @@ declare class NotificationsResource {
|
|
|
874
882
|
* X-API-Key. Replaces CommHub's getPatientDetails / getPatientBasicDetails
|
|
875
883
|
* / getPatientMedicalDetails actions.
|
|
876
884
|
*/
|
|
885
|
+
|
|
877
886
|
interface PatientDetailsInput {
|
|
878
887
|
hintId?: string;
|
|
879
888
|
elationId?: string;
|
|
@@ -900,7 +909,8 @@ declare class PatientDetailsError extends Error {
|
|
|
900
909
|
declare class PatientDetailsResource {
|
|
901
910
|
private readonly baseUrl;
|
|
902
911
|
private readonly apiKey;
|
|
903
|
-
|
|
912
|
+
private readonly auth;
|
|
913
|
+
constructor(apiBaseUrl: string, apiKey: string, getAuthToken?: AuthTokenFetcher);
|
|
904
914
|
private post;
|
|
905
915
|
get(input: PatientDetailsInput): Promise<PatientDetailsResult>;
|
|
906
916
|
getBasic(input: PatientDetailsInput): Promise<PatientBasicDetailsResult>;
|
|
@@ -1201,7 +1211,8 @@ declare class TranslationError extends Error {
|
|
|
1201
1211
|
declare class TranslationResource {
|
|
1202
1212
|
private readonly baseUrl;
|
|
1203
1213
|
private readonly apiKey;
|
|
1204
|
-
|
|
1214
|
+
private readonly auth;
|
|
1215
|
+
constructor(apiBaseUrl: string, apiKey: string, getAuthToken?: AuthTokenFetcher);
|
|
1205
1216
|
private post;
|
|
1206
1217
|
translate(input: TranslateTextInput): Promise<TranslationResult>;
|
|
1207
1218
|
translateBatch(input: TranslateBatchInput): Promise<TranslationResult[]>;
|
|
@@ -1640,12 +1651,21 @@ declare class TruthClient {
|
|
|
1640
1651
|
readonly userSettings: UserSettingsResource;
|
|
1641
1652
|
private readonly convex;
|
|
1642
1653
|
private readonly tracker;
|
|
1654
|
+
private readonly _getAuthToken?;
|
|
1643
1655
|
private _vapidPublicKey;
|
|
1644
1656
|
private _webPushReady;
|
|
1645
1657
|
private readonly _serviceWorkerPath;
|
|
1646
1658
|
constructor(config: TruthClientConfig);
|
|
1647
1659
|
get vapidPublicKey(): string | null;
|
|
1648
1660
|
get webPushReady(): Promise<void> | null;
|
|
1661
|
+
/**
|
|
1662
|
+
* When a Clerk token fetcher is configured (publishable-key clients),
|
|
1663
|
+
* the VAPID endpoint is auth-gated — calling it before the session has
|
|
1664
|
+
* hydrated 401s and strands web-push in the "no key" path. Wait
|
|
1665
|
+
* (briefly, bounded) for a token to become available first. No fetcher
|
|
1666
|
+
* → resolve immediately (secret-key path is unaffected).
|
|
1667
|
+
*/
|
|
1668
|
+
private waitForAuthToken;
|
|
1649
1669
|
private initWebPush;
|
|
1650
1670
|
/**
|
|
1651
1671
|
* The resolved Truth API base URL for this environment.
|
package/dist/index.d.ts
CHANGED
|
@@ -202,8 +202,9 @@ declare class AttachmentsError extends Error {
|
|
|
202
202
|
declare class AttachmentsResource {
|
|
203
203
|
private readonly baseUrl;
|
|
204
204
|
private readonly apiKey;
|
|
205
|
+
private readonly auth;
|
|
205
206
|
private readonly convex;
|
|
206
|
-
constructor(apiBaseUrl: string, apiKey: string, convexClient: ConvexHttpClient);
|
|
207
|
+
constructor(apiBaseUrl: string, apiKey: string, convexClient: ConvexHttpClient, getAuthToken?: AuthTokenFetcher);
|
|
207
208
|
private post;
|
|
208
209
|
createUploadUrl(input: CreateUploadUrlInput): Promise<CreateUploadUrlResult>;
|
|
209
210
|
getDownloadUrl(s3Key: string, expiresIn?: number): Promise<GetDownloadUrlResult>;
|
|
@@ -424,6 +425,7 @@ declare class ConversationsResource {
|
|
|
424
425
|
* const url = await truth.messages.dialpad.authenticateVoicemail(voicemailLink);
|
|
425
426
|
* ```
|
|
426
427
|
*/
|
|
428
|
+
|
|
427
429
|
interface SendSmsParams {
|
|
428
430
|
from_number: string;
|
|
429
431
|
to_number: string;
|
|
@@ -463,7 +465,8 @@ interface VoicemailAuthResponse {
|
|
|
463
465
|
declare class DialpadResource {
|
|
464
466
|
private readonly baseUrl;
|
|
465
467
|
private readonly apiKey;
|
|
466
|
-
|
|
468
|
+
private readonly auth;
|
|
469
|
+
constructor(apiBaseUrl: string, apiKey: string, getAuthToken?: AuthTokenFetcher);
|
|
467
470
|
/**
|
|
468
471
|
* Send an SMS or MMS message via Dialpad.
|
|
469
472
|
*/
|
|
@@ -528,7 +531,8 @@ declare class MessagesResource {
|
|
|
528
531
|
readonly dialpad: DialpadResource;
|
|
529
532
|
private readonly baseUrl;
|
|
530
533
|
private readonly apiKey;
|
|
531
|
-
|
|
534
|
+
private readonly auth;
|
|
535
|
+
constructor(apiBaseUrl: string, apiKey: string, getAuthToken?: AuthTokenFetcher);
|
|
532
536
|
/**
|
|
533
537
|
* Get an authenticated URL for a Dialpad voicemail recording.
|
|
534
538
|
*
|
|
@@ -624,6 +628,7 @@ declare class EhrProxyError extends Error {
|
|
|
624
628
|
* OAuth token and the HTTP call so applications can drop Elation
|
|
625
629
|
* credentials from their own config.
|
|
626
630
|
*/
|
|
631
|
+
|
|
627
632
|
interface NonVisitNoteBullet {
|
|
628
633
|
text: string;
|
|
629
634
|
category?: string;
|
|
@@ -672,7 +677,8 @@ interface PushConversationToElationResult {
|
|
|
672
677
|
declare class NotesResource {
|
|
673
678
|
private readonly baseUrl;
|
|
674
679
|
private readonly apiKey;
|
|
675
|
-
|
|
680
|
+
private readonly auth;
|
|
681
|
+
constructor(apiBaseUrl: string, apiKey: string, getAuthToken?: AuthTokenFetcher);
|
|
676
682
|
/** 30s upstream timeout — Elation API has occasional slow hops; we
|
|
677
683
|
* don't want a pending mutation to hold the UI thread indefinitely. */
|
|
678
684
|
private static readonly REQUEST_TIMEOUT_MS;
|
|
@@ -702,6 +708,7 @@ declare class NotesResource {
|
|
|
702
708
|
* Client-side React usage lives in `@hipnation-truth/sdk/react` via
|
|
703
709
|
* the `useNotifications` hook which mirrors `expo-notifications`.
|
|
704
710
|
*/
|
|
711
|
+
|
|
705
712
|
type NotificationPlatform = "ios" | "android" | "web";
|
|
706
713
|
interface RegisterDeviceInput {
|
|
707
714
|
userId: string;
|
|
@@ -816,7 +823,8 @@ declare class NotificationsError extends Error {
|
|
|
816
823
|
declare class NotificationsResource {
|
|
817
824
|
private readonly baseUrl;
|
|
818
825
|
private readonly apiKey;
|
|
819
|
-
|
|
826
|
+
private readonly auth;
|
|
827
|
+
constructor(apiBaseUrl: string, apiKey: string, getAuthToken?: AuthTokenFetcher);
|
|
820
828
|
private post;
|
|
821
829
|
private get;
|
|
822
830
|
private delete;
|
|
@@ -874,6 +882,7 @@ declare class NotificationsResource {
|
|
|
874
882
|
* X-API-Key. Replaces CommHub's getPatientDetails / getPatientBasicDetails
|
|
875
883
|
* / getPatientMedicalDetails actions.
|
|
876
884
|
*/
|
|
885
|
+
|
|
877
886
|
interface PatientDetailsInput {
|
|
878
887
|
hintId?: string;
|
|
879
888
|
elationId?: string;
|
|
@@ -900,7 +909,8 @@ declare class PatientDetailsError extends Error {
|
|
|
900
909
|
declare class PatientDetailsResource {
|
|
901
910
|
private readonly baseUrl;
|
|
902
911
|
private readonly apiKey;
|
|
903
|
-
|
|
912
|
+
private readonly auth;
|
|
913
|
+
constructor(apiBaseUrl: string, apiKey: string, getAuthToken?: AuthTokenFetcher);
|
|
904
914
|
private post;
|
|
905
915
|
get(input: PatientDetailsInput): Promise<PatientDetailsResult>;
|
|
906
916
|
getBasic(input: PatientDetailsInput): Promise<PatientBasicDetailsResult>;
|
|
@@ -1201,7 +1211,8 @@ declare class TranslationError extends Error {
|
|
|
1201
1211
|
declare class TranslationResource {
|
|
1202
1212
|
private readonly baseUrl;
|
|
1203
1213
|
private readonly apiKey;
|
|
1204
|
-
|
|
1214
|
+
private readonly auth;
|
|
1215
|
+
constructor(apiBaseUrl: string, apiKey: string, getAuthToken?: AuthTokenFetcher);
|
|
1205
1216
|
private post;
|
|
1206
1217
|
translate(input: TranslateTextInput): Promise<TranslationResult>;
|
|
1207
1218
|
translateBatch(input: TranslateBatchInput): Promise<TranslationResult[]>;
|
|
@@ -1640,12 +1651,21 @@ declare class TruthClient {
|
|
|
1640
1651
|
readonly userSettings: UserSettingsResource;
|
|
1641
1652
|
private readonly convex;
|
|
1642
1653
|
private readonly tracker;
|
|
1654
|
+
private readonly _getAuthToken?;
|
|
1643
1655
|
private _vapidPublicKey;
|
|
1644
1656
|
private _webPushReady;
|
|
1645
1657
|
private readonly _serviceWorkerPath;
|
|
1646
1658
|
constructor(config: TruthClientConfig);
|
|
1647
1659
|
get vapidPublicKey(): string | null;
|
|
1648
1660
|
get webPushReady(): Promise<void> | null;
|
|
1661
|
+
/**
|
|
1662
|
+
* When a Clerk token fetcher is configured (publishable-key clients),
|
|
1663
|
+
* the VAPID endpoint is auth-gated — calling it before the session has
|
|
1664
|
+
* hydrated 401s and strands web-push in the "no key" path. Wait
|
|
1665
|
+
* (briefly, bounded) for a token to become available first. No fetcher
|
|
1666
|
+
* → resolve immediately (secret-key path is unaffected).
|
|
1667
|
+
*/
|
|
1668
|
+
private waitForAuthToken;
|
|
1649
1669
|
private initWebPush;
|
|
1650
1670
|
/**
|
|
1651
1671
|
* The resolved Truth API base URL for this environment.
|
package/dist/index.js
CHANGED
|
@@ -199,6 +199,31 @@ var AppointmentResource = class {
|
|
|
199
199
|
}
|
|
200
200
|
};
|
|
201
201
|
|
|
202
|
+
// src/resources/rest-auth.ts
|
|
203
|
+
function buildAuthHeaders(auth, options) {
|
|
204
|
+
return __async(this, null, function* () {
|
|
205
|
+
const headers = {
|
|
206
|
+
"X-API-Key": auth.apiKey
|
|
207
|
+
};
|
|
208
|
+
if ((options == null ? void 0 : options.accept) !== false) {
|
|
209
|
+
headers.Accept = "application/json";
|
|
210
|
+
}
|
|
211
|
+
if (options == null ? void 0 : options.json) {
|
|
212
|
+
headers["Content-Type"] = "application/json";
|
|
213
|
+
}
|
|
214
|
+
if (auth.getAuthToken) {
|
|
215
|
+
try {
|
|
216
|
+
const token = yield auth.getAuthToken();
|
|
217
|
+
if (token) {
|
|
218
|
+
headers.Authorization = `Bearer ${token}`;
|
|
219
|
+
}
|
|
220
|
+
} catch (e) {
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
return headers;
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
|
|
202
227
|
// src/resources/attachments.ts
|
|
203
228
|
var AttachmentsError = class extends Error {
|
|
204
229
|
constructor(operation, status, message) {
|
|
@@ -208,20 +233,17 @@ var AttachmentsError = class extends Error {
|
|
|
208
233
|
}
|
|
209
234
|
};
|
|
210
235
|
var AttachmentsResource = class {
|
|
211
|
-
constructor(apiBaseUrl, apiKey, convexClient) {
|
|
236
|
+
constructor(apiBaseUrl, apiKey, convexClient, getAuthToken) {
|
|
212
237
|
this.baseUrl = apiBaseUrl;
|
|
213
238
|
this.apiKey = apiKey;
|
|
239
|
+
this.auth = { apiKey, getAuthToken };
|
|
214
240
|
this.convex = convexClient;
|
|
215
241
|
}
|
|
216
242
|
post(path, body) {
|
|
217
243
|
return __async(this, null, function* () {
|
|
218
244
|
const res = yield fetch(`${this.baseUrl}/api${path}`, {
|
|
219
245
|
method: "POST",
|
|
220
|
-
headers: {
|
|
221
|
-
"Content-Type": "application/json",
|
|
222
|
-
Accept: "application/json",
|
|
223
|
-
"X-API-Key": this.apiKey
|
|
224
|
-
},
|
|
246
|
+
headers: yield buildAuthHeaders(this.auth, { json: true }),
|
|
225
247
|
body: JSON.stringify(body)
|
|
226
248
|
});
|
|
227
249
|
if (!res.ok) {
|
|
@@ -352,31 +374,6 @@ var AttachmentsResource = class {
|
|
|
352
374
|
}
|
|
353
375
|
};
|
|
354
376
|
|
|
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
|
-
|
|
380
377
|
// src/resources/conversations.ts
|
|
381
378
|
var ConversationsError = class extends Error {
|
|
382
379
|
constructor(operation, status, message) {
|
|
@@ -646,9 +643,10 @@ var ConversationsResource = _ConversationsResource;
|
|
|
646
643
|
|
|
647
644
|
// src/resources/dialpad.ts
|
|
648
645
|
var DialpadResource = class {
|
|
649
|
-
constructor(apiBaseUrl, apiKey) {
|
|
646
|
+
constructor(apiBaseUrl, apiKey, getAuthToken) {
|
|
650
647
|
this.baseUrl = apiBaseUrl;
|
|
651
648
|
this.apiKey = apiKey;
|
|
649
|
+
this.auth = { apiKey, getAuthToken };
|
|
652
650
|
}
|
|
653
651
|
/**
|
|
654
652
|
* Send an SMS or MMS message via Dialpad.
|
|
@@ -789,10 +787,7 @@ var DialpadResource = class {
|
|
|
789
787
|
const url = `${this.baseUrl}/api/messages/dialpad/voicemail/authenticate`;
|
|
790
788
|
const response = yield fetch(url, {
|
|
791
789
|
method: "POST",
|
|
792
|
-
headers: {
|
|
793
|
-
"Content-Type": "application/json",
|
|
794
|
-
"X-API-Key": this.apiKey
|
|
795
|
-
},
|
|
790
|
+
headers: yield buildAuthHeaders(this.auth, { json: true, accept: false }),
|
|
796
791
|
body: JSON.stringify({ voicemail_link: voicemailLink })
|
|
797
792
|
});
|
|
798
793
|
const result = yield response.json();
|
|
@@ -817,10 +812,7 @@ var DialpadResource = class {
|
|
|
817
812
|
}
|
|
818
813
|
const response = yield fetch(url.toString(), {
|
|
819
814
|
method: "GET",
|
|
820
|
-
headers:
|
|
821
|
-
Accept: "application/json",
|
|
822
|
-
"X-API-Key": this.apiKey
|
|
823
|
-
}
|
|
815
|
+
headers: yield buildAuthHeaders(this.auth)
|
|
824
816
|
});
|
|
825
817
|
if (!response.ok) {
|
|
826
818
|
throw new DialpadProxyError("GET", path, response.status);
|
|
@@ -833,11 +825,7 @@ var DialpadResource = class {
|
|
|
833
825
|
const url = `${this.baseUrl}/api/messages/dialpad${path}`;
|
|
834
826
|
const response = yield fetch(url, {
|
|
835
827
|
method: "POST",
|
|
836
|
-
headers: {
|
|
837
|
-
"Content-Type": "application/json",
|
|
838
|
-
Accept: "application/json",
|
|
839
|
-
"X-API-Key": this.apiKey
|
|
840
|
-
},
|
|
828
|
+
headers: yield buildAuthHeaders(this.auth, { json: true }),
|
|
841
829
|
body: body !== void 0 ? JSON.stringify(body) : void 0
|
|
842
830
|
});
|
|
843
831
|
if (!response.ok) {
|
|
@@ -852,11 +840,7 @@ var DialpadResource = class {
|
|
|
852
840
|
const url = `${this.baseUrl}/api/messages/dialpad${path}`;
|
|
853
841
|
const response = yield fetch(url, {
|
|
854
842
|
method: "PUT",
|
|
855
|
-
headers: {
|
|
856
|
-
"Content-Type": "application/json",
|
|
857
|
-
Accept: "application/json",
|
|
858
|
-
"X-API-Key": this.apiKey
|
|
859
|
-
},
|
|
843
|
+
headers: yield buildAuthHeaders(this.auth, { json: true }),
|
|
860
844
|
body: body !== void 0 ? JSON.stringify(body) : void 0
|
|
861
845
|
});
|
|
862
846
|
if (!response.ok) {
|
|
@@ -870,10 +854,11 @@ var DialpadResource = class {
|
|
|
870
854
|
}
|
|
871
855
|
};
|
|
872
856
|
var MessagesResource = class {
|
|
873
|
-
constructor(apiBaseUrl, apiKey) {
|
|
874
|
-
this.dialpad = new DialpadResource(apiBaseUrl, apiKey);
|
|
857
|
+
constructor(apiBaseUrl, apiKey, getAuthToken) {
|
|
858
|
+
this.dialpad = new DialpadResource(apiBaseUrl, apiKey, getAuthToken);
|
|
875
859
|
this.baseUrl = apiBaseUrl;
|
|
876
860
|
this.apiKey = apiKey;
|
|
861
|
+
this.auth = { apiKey, getAuthToken };
|
|
877
862
|
}
|
|
878
863
|
/**
|
|
879
864
|
* Get an authenticated URL for a Dialpad voicemail recording.
|
|
@@ -892,11 +877,7 @@ var MessagesResource = class {
|
|
|
892
877
|
return __async(this, null, function* () {
|
|
893
878
|
const res = yield fetch(`${this.baseUrl}/api/conversations/voicemail/url`, {
|
|
894
879
|
method: "POST",
|
|
895
|
-
headers: {
|
|
896
|
-
"Content-Type": "application/json",
|
|
897
|
-
Accept: "application/json",
|
|
898
|
-
"X-API-Key": this.apiKey
|
|
899
|
-
},
|
|
880
|
+
headers: yield buildAuthHeaders(this.auth, { json: true }),
|
|
900
881
|
body: JSON.stringify({ voicemailLink })
|
|
901
882
|
});
|
|
902
883
|
if (!res.ok) {
|
|
@@ -920,11 +901,7 @@ var MessagesResource = class {
|
|
|
920
901
|
return __async(this, null, function* () {
|
|
921
902
|
const res = yield fetch(`${this.baseUrl}/api/conversations/calls/end`, {
|
|
922
903
|
method: "POST",
|
|
923
|
-
headers: {
|
|
924
|
-
"Content-Type": "application/json",
|
|
925
|
-
Accept: "application/json",
|
|
926
|
-
"X-API-Key": this.apiKey
|
|
927
|
-
},
|
|
904
|
+
headers: yield buildAuthHeaders(this.auth, { json: true }),
|
|
928
905
|
body: JSON.stringify({ callId })
|
|
929
906
|
});
|
|
930
907
|
if (!res.ok) {
|
|
@@ -1045,9 +1022,10 @@ var NotesError = class extends Error {
|
|
|
1045
1022
|
}
|
|
1046
1023
|
};
|
|
1047
1024
|
var _NotesResource = class _NotesResource {
|
|
1048
|
-
constructor(apiBaseUrl, apiKey) {
|
|
1025
|
+
constructor(apiBaseUrl, apiKey, getAuthToken) {
|
|
1049
1026
|
this.baseUrl = apiBaseUrl;
|
|
1050
1027
|
this.apiKey = apiKey;
|
|
1028
|
+
this.auth = { apiKey, getAuthToken };
|
|
1051
1029
|
}
|
|
1052
1030
|
post(path, body) {
|
|
1053
1031
|
return __async(this, null, function* () {
|
|
@@ -1060,11 +1038,7 @@ var _NotesResource = class _NotesResource {
|
|
|
1060
1038
|
try {
|
|
1061
1039
|
res = yield fetch(`${this.baseUrl}/api${path}`, {
|
|
1062
1040
|
method: "POST",
|
|
1063
|
-
headers: {
|
|
1064
|
-
"Content-Type": "application/json",
|
|
1065
|
-
Accept: "application/json",
|
|
1066
|
-
"X-API-Key": this.apiKey
|
|
1067
|
-
},
|
|
1041
|
+
headers: yield buildAuthHeaders(this.auth, { json: true }),
|
|
1068
1042
|
body: JSON.stringify(body),
|
|
1069
1043
|
signal: controller.signal
|
|
1070
1044
|
});
|
|
@@ -1125,19 +1099,16 @@ var NotificationsError = class extends Error {
|
|
|
1125
1099
|
}
|
|
1126
1100
|
};
|
|
1127
1101
|
var NotificationsResource = class {
|
|
1128
|
-
constructor(apiBaseUrl, apiKey) {
|
|
1102
|
+
constructor(apiBaseUrl, apiKey, getAuthToken) {
|
|
1129
1103
|
this.baseUrl = apiBaseUrl;
|
|
1130
1104
|
this.apiKey = apiKey;
|
|
1105
|
+
this.auth = { apiKey, getAuthToken };
|
|
1131
1106
|
}
|
|
1132
1107
|
post(path, body) {
|
|
1133
1108
|
return __async(this, null, function* () {
|
|
1134
1109
|
const res = yield fetch(`${this.baseUrl}/api${path}`, {
|
|
1135
1110
|
method: "POST",
|
|
1136
|
-
headers: {
|
|
1137
|
-
"Content-Type": "application/json",
|
|
1138
|
-
Accept: "application/json",
|
|
1139
|
-
"X-API-Key": this.apiKey
|
|
1140
|
-
},
|
|
1111
|
+
headers: yield buildAuthHeaders(this.auth, { json: true }),
|
|
1141
1112
|
body: JSON.stringify(body)
|
|
1142
1113
|
});
|
|
1143
1114
|
if (!res.ok) {
|
|
@@ -1155,10 +1126,7 @@ var NotificationsResource = class {
|
|
|
1155
1126
|
}
|
|
1156
1127
|
const res = yield fetch(url.toString(), {
|
|
1157
1128
|
method: "GET",
|
|
1158
|
-
headers:
|
|
1159
|
-
Accept: "application/json",
|
|
1160
|
-
"X-API-Key": this.apiKey
|
|
1161
|
-
}
|
|
1129
|
+
headers: yield buildAuthHeaders(this.auth)
|
|
1162
1130
|
});
|
|
1163
1131
|
if (!res.ok) {
|
|
1164
1132
|
const text = yield res.text().catch(() => "");
|
|
@@ -1171,10 +1139,7 @@ var NotificationsResource = class {
|
|
|
1171
1139
|
return __async(this, null, function* () {
|
|
1172
1140
|
const res = yield fetch(`${this.baseUrl}/api${path}`, {
|
|
1173
1141
|
method: "DELETE",
|
|
1174
|
-
headers:
|
|
1175
|
-
Accept: "application/json",
|
|
1176
|
-
"X-API-Key": this.apiKey
|
|
1177
|
-
}
|
|
1142
|
+
headers: yield buildAuthHeaders(this.auth)
|
|
1178
1143
|
});
|
|
1179
1144
|
if (!res.ok) {
|
|
1180
1145
|
const text = yield res.text().catch(() => "");
|
|
@@ -1307,19 +1272,16 @@ var PatientDetailsError = class extends Error {
|
|
|
1307
1272
|
}
|
|
1308
1273
|
};
|
|
1309
1274
|
var PatientDetailsResource = class {
|
|
1310
|
-
constructor(apiBaseUrl, apiKey) {
|
|
1275
|
+
constructor(apiBaseUrl, apiKey, getAuthToken) {
|
|
1311
1276
|
this.baseUrl = apiBaseUrl;
|
|
1312
1277
|
this.apiKey = apiKey;
|
|
1278
|
+
this.auth = { apiKey, getAuthToken };
|
|
1313
1279
|
}
|
|
1314
1280
|
post(path, body) {
|
|
1315
1281
|
return __async(this, null, function* () {
|
|
1316
1282
|
const res = yield fetch(`${this.baseUrl}/api${path}`, {
|
|
1317
1283
|
method: "POST",
|
|
1318
|
-
headers: {
|
|
1319
|
-
"Content-Type": "application/json",
|
|
1320
|
-
Accept: "application/json",
|
|
1321
|
-
"X-API-Key": this.apiKey
|
|
1322
|
-
},
|
|
1284
|
+
headers: yield buildAuthHeaders(this.auth, { json: true }),
|
|
1323
1285
|
body: JSON.stringify(body)
|
|
1324
1286
|
});
|
|
1325
1287
|
if (!res.ok) {
|
|
@@ -1641,20 +1603,17 @@ var TranslationError = class extends Error {
|
|
|
1641
1603
|
}
|
|
1642
1604
|
};
|
|
1643
1605
|
var TranslationResource = class {
|
|
1644
|
-
constructor(apiBaseUrl, apiKey) {
|
|
1606
|
+
constructor(apiBaseUrl, apiKey, getAuthToken) {
|
|
1645
1607
|
this.baseUrl = apiBaseUrl;
|
|
1646
1608
|
this.apiKey = apiKey;
|
|
1609
|
+
this.auth = { apiKey, getAuthToken };
|
|
1647
1610
|
}
|
|
1648
1611
|
post(path, body) {
|
|
1649
1612
|
return __async(this, null, function* () {
|
|
1650
1613
|
const url = `${this.baseUrl}/api${path}`;
|
|
1651
1614
|
const res = yield fetch(url, {
|
|
1652
1615
|
method: "POST",
|
|
1653
|
-
headers: {
|
|
1654
|
-
"Content-Type": "application/json",
|
|
1655
|
-
Accept: "application/json",
|
|
1656
|
-
"X-API-Key": this.apiKey
|
|
1657
|
-
},
|
|
1616
|
+
headers: yield buildAuthHeaders(this.auth, { json: true }),
|
|
1658
1617
|
body: JSON.stringify(body)
|
|
1659
1618
|
});
|
|
1660
1619
|
if (!res.ok) {
|
|
@@ -1986,19 +1945,36 @@ var TruthClient = class {
|
|
|
1986
1945
|
this.patients = new PatientResource(this.convex);
|
|
1987
1946
|
this.appointments = new AppointmentResource(this.convex);
|
|
1988
1947
|
this.ehr = new EhrResource(apiUrl, config.apiKey, config.getAuthToken);
|
|
1989
|
-
this.messages = new MessagesResource(
|
|
1948
|
+
this.messages = new MessagesResource(
|
|
1949
|
+
apiUrl,
|
|
1950
|
+
config.apiKey,
|
|
1951
|
+
config.getAuthToken
|
|
1952
|
+
);
|
|
1990
1953
|
this.reminders = new RemindersResource(this.convex);
|
|
1991
|
-
this.translation = new TranslationResource(
|
|
1954
|
+
this.translation = new TranslationResource(
|
|
1955
|
+
apiUrl,
|
|
1956
|
+
config.apiKey,
|
|
1957
|
+
config.getAuthToken
|
|
1958
|
+
);
|
|
1992
1959
|
this.tasks = new TasksResource(this.convex);
|
|
1993
|
-
this.patientDetails = new PatientDetailsResource(
|
|
1960
|
+
this.patientDetails = new PatientDetailsResource(
|
|
1961
|
+
apiUrl,
|
|
1962
|
+
config.apiKey,
|
|
1963
|
+
config.getAuthToken
|
|
1964
|
+
);
|
|
1994
1965
|
this.attachments = new AttachmentsResource(
|
|
1995
1966
|
apiUrl,
|
|
1996
1967
|
config.apiKey,
|
|
1997
|
-
this.convex
|
|
1968
|
+
this.convex,
|
|
1969
|
+
config.getAuthToken
|
|
1998
1970
|
);
|
|
1999
|
-
this.notes = new NotesResource(apiUrl, config.apiKey);
|
|
1971
|
+
this.notes = new NotesResource(apiUrl, config.apiKey, config.getAuthToken);
|
|
2000
1972
|
this.physicians = new PhysiciansResource(this.convex);
|
|
2001
|
-
this.notifications = new NotificationsResource(
|
|
1973
|
+
this.notifications = new NotificationsResource(
|
|
1974
|
+
apiUrl,
|
|
1975
|
+
config.apiKey,
|
|
1976
|
+
config.getAuthToken
|
|
1977
|
+
);
|
|
2002
1978
|
this.conversations = new ConversationsResource(
|
|
2003
1979
|
apiUrl,
|
|
2004
1980
|
config.apiKey,
|
|
@@ -2006,6 +1982,7 @@ var TruthClient = class {
|
|
|
2006
1982
|
config.getAuthToken
|
|
2007
1983
|
);
|
|
2008
1984
|
this.userSettings = new UserSettingsResource(this.convex);
|
|
1985
|
+
this._getAuthToken = config.getAuthToken;
|
|
2009
1986
|
this._serviceWorkerPath = (_h = config.serviceWorkerPath) != null ? _h : "/truth-sw.js";
|
|
2010
1987
|
if (typeof window !== "undefined" && isWebPushSupported() && config.autoInitServiceWorker !== false) {
|
|
2011
1988
|
this._webPushReady = this.initWebPush();
|
|
@@ -2017,9 +1994,33 @@ var TruthClient = class {
|
|
|
2017
1994
|
get webPushReady() {
|
|
2018
1995
|
return this._webPushReady;
|
|
2019
1996
|
}
|
|
1997
|
+
/**
|
|
1998
|
+
* When a Clerk token fetcher is configured (publishable-key clients),
|
|
1999
|
+
* the VAPID endpoint is auth-gated — calling it before the session has
|
|
2000
|
+
* hydrated 401s and strands web-push in the "no key" path. Wait
|
|
2001
|
+
* (briefly, bounded) for a token to become available first. No fetcher
|
|
2002
|
+
* → resolve immediately (secret-key path is unaffected).
|
|
2003
|
+
*/
|
|
2004
|
+
waitForAuthToken() {
|
|
2005
|
+
return __async(this, null, function* () {
|
|
2006
|
+
if (!this._getAuthToken) {
|
|
2007
|
+
return;
|
|
2008
|
+
}
|
|
2009
|
+
for (let attempt = 0; attempt < 20; attempt++) {
|
|
2010
|
+
try {
|
|
2011
|
+
if (yield this._getAuthToken()) {
|
|
2012
|
+
return;
|
|
2013
|
+
}
|
|
2014
|
+
} catch (e) {
|
|
2015
|
+
}
|
|
2016
|
+
yield new Promise((resolve) => setTimeout(resolve, 500));
|
|
2017
|
+
}
|
|
2018
|
+
});
|
|
2019
|
+
}
|
|
2020
2020
|
initWebPush() {
|
|
2021
2021
|
return __async(this, null, function* () {
|
|
2022
2022
|
try {
|
|
2023
|
+
yield this.waitForAuthToken();
|
|
2023
2024
|
const key = yield this.notifications.getVapidKey();
|
|
2024
2025
|
if (!key) {
|
|
2025
2026
|
return;
|