@ovok/core 0.4.49-dev.495 → 0.4.49-dev.497
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/client/observation/measurement-fields.d.ts +1 -1
- package/dist/client/observation/methods/observationsToMeasurements.d.ts +1 -1
- package/dist/client/observation/methods/observationsToMeasurements.js +59 -59
- package/dist/client/observation/services/base-observation-service.d.ts +1 -1
- package/dist/client/observation/services/blood-oxygen.d.ts +1 -1
- package/dist/client/observation/services/blood-oxygen.js +7 -7
- package/dist/client/observation/services/blood-pressure.d.ts +1 -1
- package/dist/client/observation/services/blood-pressure.js +16 -16
- package/dist/client/observation/services/component-observation-services.d.ts +1 -1
- package/dist/client/observation/services/component-observation-services.js +3 -3
- package/dist/client/observation/services/creator.d.ts +1 -1
- package/dist/client/observation/services/creator.js +10 -10
- package/dist/client/observation/services/ecg-observation-fragments.d.ts +1 -1
- package/dist/client/observation/services/ecg.d.ts +1 -1
- package/dist/client/observation/services/ecg.js +10 -10
- package/dist/client/observation/services/lipid-panel.d.ts +1 -1
- package/dist/client/observation/services/lipid-panel.js +13 -13
- package/dist/client/observation/services/single-value-services.d.ts +1 -1
- package/dist/client/observation/services/single-value-services.js +19 -19
- package/dist/client/observation/services/step-count.d.ts +1 -1
- package/dist/client/observation/services/step-count.js +5 -5
- package/dist/client/observation/services/uric-acid-service.d.ts +1 -1
- package/dist/client/observation/services/uric-acid-service.js +7 -7
- package/dist/client/offline/offline-measurement-queue.d.ts +1 -2
- package/dist/client/wearables/types.d.ts +5 -0
- package/dist/conformance/capability-requirements.js +1 -1
- package/dist/next/auth/access-token.d.ts +9 -0
- package/dist/next/auth/access-token.js +18 -0
- package/dist/next/auth/client-credentials.d.ts +16 -0
- package/dist/next/auth/client-credentials.js +40 -0
- package/dist/next/auth/credentials.d.ts +5 -0
- package/dist/next/auth/credentials.js +7 -0
- package/dist/next/auth/saved-accounts-store.d.ts +26 -0
- package/dist/next/auth/saved-accounts-store.js +93 -0
- package/dist/next/auth/session-store.d.ts +12 -0
- package/dist/next/auth/session-store.js +33 -0
- package/dist/next/auth/session.d.ts +28 -0
- package/dist/next/auth/session.js +27 -0
- package/dist/next/auth/token-endpoint.d.ts +12 -0
- package/dist/next/auth/token-endpoint.js +28 -0
- package/dist/next/auth/user-session.d.ts +39 -0
- package/dist/next/auth/user-session.js +183 -0
- package/dist/next/config/ovok-config.d.ts +42 -0
- package/dist/next/config/ovok-config.js +2 -0
- package/dist/next/config/settings.d.ts +6 -0
- package/dist/next/config/settings.js +74 -0
- package/dist/next/errors/error-from-response.d.ts +2 -0
- package/dist/next/errors/error-from-response.js +35 -0
- package/dist/next/errors/ovok-account-error.d.ts +5 -0
- package/dist/next/errors/ovok-account-error.js +13 -0
- package/dist/next/errors/ovok-errors.d.ts +42 -0
- package/dist/next/errors/ovok-errors.js +74 -0
- package/dist/next/http/http-client.d.ts +36 -0
- package/dist/next/http/http-client.js +116 -0
- package/dist/next/http/retry-after.d.ts +1 -0
- package/dist/next/http/retry-after.js +16 -0
- package/dist/next/http/retry-policy.d.ts +13 -0
- package/dist/next/http/retry-policy.js +27 -0
- package/dist/next/http/transmit.d.ts +14 -0
- package/dist/next/http/transmit.js +57 -0
- package/dist/next/http/url.d.ts +6 -0
- package/dist/next/http/url.js +22 -0
- package/dist/next/index.d.ts +74 -0
- package/dist/next/index.js +35 -0
- package/dist/next/ovok.d.ts +54 -0
- package/dist/next/ovok.js +77 -0
- package/dist/next/paging/bundle-page.d.ts +4 -0
- package/dist/next/paging/bundle-page.js +25 -0
- package/dist/next/paging/cursor-pages.d.ts +7 -0
- package/dist/next/paging/cursor-pages.js +14 -0
- package/dist/next/paging/numbered-pages.d.ts +15 -0
- package/dist/next/paging/numbered-pages.js +20 -0
- package/dist/next/paging/page.d.ts +12 -0
- package/dist/next/paging/page.js +17 -0
- package/dist/next/resources/accounts/accounts-resource.d.ts +8 -0
- package/dist/next/resources/accounts/accounts-resource.js +13 -0
- package/dist/next/resources/ai/ai-chat-resource.d.ts +8 -0
- package/dist/next/resources/ai/ai-chat-resource.js +12 -0
- package/dist/next/resources/ai/ai-resource.d.ts +16 -0
- package/dist/next/resources/ai/ai-resource.js +19 -0
- package/dist/next/resources/ai/chat-messages-resource.d.ts +9 -0
- package/dist/next/resources/ai/chat-messages-resource.js +18 -0
- package/dist/next/resources/ai/chat-sessions-resource.d.ts +14 -0
- package/dist/next/resources/ai/chat-sessions-resource.js +23 -0
- package/dist/next/resources/auth/auth-sessions-resource.d.ts +13 -0
- package/dist/next/resources/auth/auth-sessions-resource.js +25 -0
- package/dist/next/resources/auth/registration.d.ts +35 -0
- package/dist/next/resources/auth/registration.js +24 -0
- package/dist/next/resources/auth/social-login.d.ts +8 -0
- package/dist/next/resources/auth/social-login.js +7 -0
- package/dist/next/resources/auth-resource.d.ts +63 -0
- package/dist/next/resources/auth-resource.js +119 -0
- package/dist/next/resources/bots/bots-resource.d.ts +10 -0
- package/dist/next/resources/bots/bots-resource.js +15 -0
- package/dist/next/resources/cms/cms-delivery.d.ts +22 -0
- package/dist/next/resources/cms/cms-delivery.js +36 -0
- package/dist/next/resources/cms/cms-documents-resource.d.ts +11 -0
- package/dist/next/resources/cms/cms-documents-resource.js +17 -0
- package/dist/next/resources/cms/cms-resource.d.ts +17 -0
- package/dist/next/resources/cms/cms-resource.js +38 -0
- package/dist/next/resources/cms/payload-pages.d.ts +6 -0
- package/dist/next/resources/cms/payload-pages.js +15 -0
- package/dist/next/resources/cms/release-notes-resource.d.ts +10 -0
- package/dist/next/resources/cms/release-notes-resource.js +15 -0
- package/dist/next/resources/cms/translation-tree.d.ts +3 -0
- package/dist/next/resources/cms/translation-tree.js +45 -0
- package/dist/next/resources/consent/consent-resource.d.ts +23 -0
- package/dist/next/resources/consent/consent-resource.js +43 -0
- package/dist/next/resources/content/content-resource.d.ts +19 -0
- package/dist/next/resources/content/content-resource.js +41 -0
- package/dist/next/resources/documents/documents-resource.d.ts +26 -0
- package/dist/next/resources/documents/documents-resource.js +41 -0
- package/dist/next/resources/email/email-resource.d.ts +6 -0
- package/dist/next/resources/email/email-resource.js +10 -0
- package/dist/next/resources/email/email-templates-resource.d.ts +8 -0
- package/dist/next/resources/email/email-templates-resource.js +13 -0
- package/dist/next/resources/fhir-resource.d.ts +28 -0
- package/dist/next/resources/fhir-resource.js +64 -0
- package/dist/next/resources/health-resource.d.ts +17 -0
- package/dist/next/resources/health-resource.js +14 -0
- package/dist/next/resources/invites/invite-flow-resource.d.ts +12 -0
- package/dist/next/resources/invites/invite-flow-resource.js +19 -0
- package/dist/next/resources/invites/invites-resource.d.ts +22 -0
- package/dist/next/resources/invites/invites-resource.js +29 -0
- package/dist/next/resources/localization/i18next-resource.d.ts +10 -0
- package/dist/next/resources/localization/i18next-resource.js +18 -0
- package/dist/next/resources/localization/locales-resource.d.ts +9 -0
- package/dist/next/resources/localization/locales-resource.js +16 -0
- package/dist/next/resources/localization/localizations-resource.d.ts +17 -0
- package/dist/next/resources/localization/localizations-resource.js +27 -0
- package/dist/next/resources/measurements/measurements-resource.d.ts +42 -0
- package/dist/next/resources/measurements/measurements-resource.js +77 -0
- package/dist/next/resources/measurements/observation-builder.d.ts +5 -0
- package/dist/next/resources/measurements/observation-builder.js +57 -0
- package/dist/next/resources/measurements/save-error.d.ts +5 -0
- package/dist/next/resources/measurements/save-error.js +18 -0
- package/dist/next/resources/measurements/signed-in-account.d.ts +11 -0
- package/dist/next/resources/measurements/signed-in-account.js +26 -0
- package/dist/next/resources/patient/fhir-records.d.ts +19 -0
- package/dist/next/resources/patient/fhir-records.js +33 -0
- package/dist/next/resources/patient/patient-resource.d.ts +21 -0
- package/dist/next/resources/patient/patient-resource.js +38 -0
- package/dist/next/resources/projects/project-features-resource.d.ts +9 -0
- package/dist/next/resources/projects/project-features-resource.js +17 -0
- package/dist/next/resources/projects/project-members-resource.d.ts +19 -0
- package/dist/next/resources/projects/project-members-resource.js +25 -0
- package/dist/next/resources/projects/project-settings-resource.d.ts +10 -0
- package/dist/next/resources/projects/project-settings-resource.js +21 -0
- package/dist/next/resources/projects/projects-resource.d.ts +20 -0
- package/dist/next/resources/projects/projects-resource.js +21 -0
- package/dist/next/resources/questionnaires/questionnaires-resource.d.ts +18 -0
- package/dist/next/resources/questionnaires/questionnaires-resource.js +36 -0
- package/dist/next/resources/session/saved-accounts-resource.d.ts +13 -0
- package/dist/next/resources/session/saved-accounts-resource.js +44 -0
- package/dist/next/resources/session/session-resource.d.ts +11 -0
- package/dist/next/resources/session/session-resource.js +15 -0
- package/dist/next/resources/sharing/sharing-invites-resource.d.ts +9 -0
- package/dist/next/resources/sharing/sharing-invites-resource.js +17 -0
- package/dist/next/resources/sharing/sharing-resource.d.ts +10 -0
- package/dist/next/resources/sharing/sharing-resource.js +14 -0
- package/dist/next/resources/sharing/sharing-settings-resource.d.ts +9 -0
- package/dist/next/resources/sharing/sharing-settings-resource.js +16 -0
- package/dist/next/resources/sharing/sharing-shares-resource.d.ts +9 -0
- package/dist/next/resources/sharing/sharing-shares-resource.js +27 -0
- package/dist/next/resources/signals/signals-gateway-resource.d.ts +14 -0
- package/dist/next/resources/signals/signals-gateway-resource.js +44 -0
- package/dist/next/resources/signals/signals-resource.d.ts +13 -0
- package/dist/next/resources/signals/signals-resource.js +19 -0
- package/dist/next/resources/signals/undeliverable-resource.d.ts +26 -0
- package/dist/next/resources/signals/undeliverable-resource.js +18 -0
- package/dist/next/resources/slim/live-reads.d.ts +13 -0
- package/dist/next/resources/slim/live-reads.js +87 -0
- package/dist/next/resources/slim/slim-alarms-resource.d.ts +13 -0
- package/dist/next/resources/slim/slim-alarms-resource.js +25 -0
- package/dist/next/resources/slim/slim-change-history-resource.d.ts +9 -0
- package/dist/next/resources/slim/slim-change-history-resource.js +19 -0
- package/dist/next/resources/slim/slim-child-projects-resource.d.ts +17 -0
- package/dist/next/resources/slim/slim-child-projects-resource.js +22 -0
- package/dist/next/resources/slim/slim-devices-resource.d.ts +29 -0
- package/dist/next/resources/slim/slim-devices-resource.js +81 -0
- package/dist/next/resources/slim/slim-exports-resource.d.ts +8 -0
- package/dist/next/resources/slim/slim-exports-resource.js +14 -0
- package/dist/next/resources/slim/slim-locations-resource.d.ts +14 -0
- package/dist/next/resources/slim/slim-locations-resource.js +30 -0
- package/dist/next/resources/slim/slim-medical-notifications-resource.d.ts +18 -0
- package/dist/next/resources/slim/slim-medical-notifications-resource.js +46 -0
- package/dist/next/resources/slim/slim-notification-notes-resource.d.ts +12 -0
- package/dist/next/resources/slim/slim-notification-notes-resource.js +34 -0
- package/dist/next/resources/slim/slim-notifications-resource.d.ts +19 -0
- package/dist/next/resources/slim/slim-notifications-resource.js +26 -0
- package/dist/next/resources/slim/slim-organizations-resource.d.ts +11 -0
- package/dist/next/resources/slim/slim-organizations-resource.js +25 -0
- package/dist/next/resources/slim/slim-out-of-bed-resource.d.ts +13 -0
- package/dist/next/resources/slim/slim-out-of-bed-resource.js +20 -0
- package/dist/next/resources/slim/slim-paths.d.ts +6 -0
- package/dist/next/resources/slim/slim-paths.js +9 -0
- package/dist/next/resources/slim/slim-patient-thresholds-resource.d.ts +10 -0
- package/dist/next/resources/slim/slim-patient-thresholds-resource.js +20 -0
- package/dist/next/resources/slim/slim-patients-resource.d.ts +20 -0
- package/dist/next/resources/slim/slim-patients-resource.js +39 -0
- package/dist/next/resources/slim/slim-policies-resource.d.ts +12 -0
- package/dist/next/resources/slim/slim-policies-resource.js +29 -0
- package/dist/next/resources/slim/slim-practitioners-resource.d.ts +8 -0
- package/dist/next/resources/slim/slim-practitioners-resource.js +14 -0
- package/dist/next/resources/slim/slim-projects-resource.d.ts +16 -0
- package/dist/next/resources/slim/slim-projects-resource.js +35 -0
- package/dist/next/resources/slim/slim-queries.d.ts +34 -0
- package/dist/next/resources/slim/slim-queries.js +2 -0
- package/dist/next/resources/slim/slim-resource.d.ts +39 -0
- package/dist/next/resources/slim/slim-resource.js +44 -0
- package/dist/next/resources/slim/slim-sleep-resource.d.ts +9 -0
- package/dist/next/resources/slim/slim-sleep-resource.js +15 -0
- package/dist/next/resources/slim/slim-thresholds-resource.d.ts +11 -0
- package/dist/next/resources/slim/slim-thresholds-resource.js +18 -0
- package/dist/next/resources/slim/slim-trends-resource.d.ts +11 -0
- package/dist/next/resources/slim/slim-trends-resource.js +19 -0
- package/dist/next/resources/slim/slim-users-resource.d.ts +11 -0
- package/dist/next/resources/slim/slim-users-resource.js +15 -0
- package/dist/next/resources/slim/slim-zones-resource.d.ts +12 -0
- package/dist/next/resources/slim/slim-zones-resource.js +24 -0
- package/dist/next/resources/video-calls/video-call-access-resource.d.ts +11 -0
- package/dist/next/resources/video-calls/video-call-access-resource.js +19 -0
- package/dist/next/resources/video-calls/video-call-appointments-resource.d.ts +10 -0
- package/dist/next/resources/video-calls/video-call-appointments-resource.js +21 -0
- package/dist/next/resources/video-calls/video-call-emails-resource.d.ts +10 -0
- package/dist/next/resources/video-calls/video-call-emails-resource.js +19 -0
- package/dist/next/resources/video-calls/video-calls-resource.d.ts +14 -0
- package/dist/next/resources/video-calls/video-calls-resource.js +20 -0
- package/dist/next/resources/wearables/wearable-connections-resource.d.ts +12 -0
- package/dist/next/resources/wearables/wearable-connections-resource.js +25 -0
- package/dist/next/resources/wearables/wearable-providers-resource.d.ts +12 -0
- package/dist/next/resources/wearables/wearable-providers-resource.js +27 -0
- package/dist/next/resources/wearables/wearables-resource.d.ts +8 -0
- package/dist/next/resources/wearables/wearables-resource.js +14 -0
- package/dist/next/storage/ovok-storage.d.ts +11 -0
- package/dist/next/storage/ovok-storage.js +19 -0
- package/dist/types/MeasurementTypes.d.ts +5 -0
- package/dist/types/MeasurementTypes.js +21 -0
- package/dist/types/index.d.ts +1 -5
- package/dist/types/index.js +1 -5
- package/next/index.d.ts +1 -0
- package/next/index.js +3 -0
- package/package.json +3 -2
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HttpClient = void 0;
|
|
4
|
+
const credentials_1 = require("../auth/credentials");
|
|
5
|
+
const error_from_response_1 = require("../errors/error-from-response");
|
|
6
|
+
const ovok_errors_1 = require("../errors/ovok-errors");
|
|
7
|
+
const retry_after_1 = require("./retry-after");
|
|
8
|
+
const transmit_1 = require("./transmit");
|
|
9
|
+
const url_1 = require("./url");
|
|
10
|
+
const UNAUTHORIZED = 401;
|
|
11
|
+
const JSON_TYPE = "application/json";
|
|
12
|
+
class HttpClient {
|
|
13
|
+
constructor(context, basePath = "") {
|
|
14
|
+
this.context = context;
|
|
15
|
+
this.basePath = basePath;
|
|
16
|
+
}
|
|
17
|
+
under(path) {
|
|
18
|
+
return new HttpClient(this.context, (0, url_1.joinPath)(this.basePath, path));
|
|
19
|
+
}
|
|
20
|
+
anonymous() {
|
|
21
|
+
return new HttpClient({ ...this.context, credentials: credentials_1.noCredentials }, this.basePath);
|
|
22
|
+
}
|
|
23
|
+
withCredentials(credentials) {
|
|
24
|
+
return new HttpClient({ ...this.context, credentials }, this.basePath);
|
|
25
|
+
}
|
|
26
|
+
get(path, options) {
|
|
27
|
+
return this.send({ method: "GET", path }, options);
|
|
28
|
+
}
|
|
29
|
+
post(path, body, options) {
|
|
30
|
+
return this.send({ method: "POST", path, body }, options);
|
|
31
|
+
}
|
|
32
|
+
put(path, body, options) {
|
|
33
|
+
return this.send({ method: "PUT", path, body }, options);
|
|
34
|
+
}
|
|
35
|
+
patch(path, body, options) {
|
|
36
|
+
return this.send({ method: "PATCH", path, body }, options);
|
|
37
|
+
}
|
|
38
|
+
delete(path, options) {
|
|
39
|
+
return this.send({ method: "DELETE", path }, options);
|
|
40
|
+
}
|
|
41
|
+
async send(request, options = {}) {
|
|
42
|
+
const response = await this.sendAuthorized(request, options);
|
|
43
|
+
if (response.ok) {
|
|
44
|
+
return readJson(response);
|
|
45
|
+
}
|
|
46
|
+
throw await (0, error_from_response_1.errorFromResponse)(response);
|
|
47
|
+
}
|
|
48
|
+
async sendAuthorized(request, options) {
|
|
49
|
+
const response = await this.sendWithRetries(request, options);
|
|
50
|
+
const unauthorized = response.status === UNAUTHORIZED;
|
|
51
|
+
if (unauthorized && (await this.context.credentials.refresh())) {
|
|
52
|
+
return this.sendWithRetries(request, options);
|
|
53
|
+
}
|
|
54
|
+
return response;
|
|
55
|
+
}
|
|
56
|
+
async sendWithRetries(request, options) {
|
|
57
|
+
var _a, _b;
|
|
58
|
+
const { retryPolicy } = this.context;
|
|
59
|
+
for (let attempt = 0;; attempt += 1) {
|
|
60
|
+
const outcome = await this.attempt(request, options);
|
|
61
|
+
const retry = retryPolicy.allows(request, attempt) && this.isRetryable(outcome);
|
|
62
|
+
if (retry) {
|
|
63
|
+
await discard(outcome.response);
|
|
64
|
+
await retryPolicy.pause(attempt, (0, retry_after_1.retryAfterMs)((_b = (_a = outcome.response) === null || _a === void 0 ? void 0 : _a.headers.get("retry-after")) !== null && _b !== void 0 ? _b : null));
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
return unwrap(outcome);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
async attempt(request, options) {
|
|
71
|
+
try {
|
|
72
|
+
const response = await (0, transmit_1.transmit)(this.context.settings, await this.toTransmit(request), options);
|
|
73
|
+
return { response };
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
return { error };
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
isRetryable(outcome) {
|
|
80
|
+
return outcome.response
|
|
81
|
+
? this.context.retryPolicy.isRetryableStatus(outcome.response.status)
|
|
82
|
+
: outcome.error instanceof ovok_errors_1.OvokConnectionError;
|
|
83
|
+
}
|
|
84
|
+
async toTransmit(request) {
|
|
85
|
+
const token = await this.context.credentials.accessToken();
|
|
86
|
+
const contentType = request.body === undefined ? {} : { "Content-Type": JSON_TYPE };
|
|
87
|
+
const authorization = token ? { Authorization: `Bearer ${token}` } : {};
|
|
88
|
+
return {
|
|
89
|
+
url: `${this.context.settings.baseUrl}${(0, url_1.joinPath)(this.basePath, request.path)}`,
|
|
90
|
+
method: request.method,
|
|
91
|
+
headers: { Accept: JSON_TYPE, ...contentType, ...request.headers, ...authorization },
|
|
92
|
+
body: encodeBody(request.body),
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
exports.HttpClient = HttpClient;
|
|
97
|
+
const unwrap = (outcome) => {
|
|
98
|
+
if (outcome.response) {
|
|
99
|
+
return outcome.response;
|
|
100
|
+
}
|
|
101
|
+
throw outcome.error;
|
|
102
|
+
};
|
|
103
|
+
const discard = async (response) => {
|
|
104
|
+
var _a;
|
|
105
|
+
await ((_a = response === null || response === void 0 ? void 0 : response.body) === null || _a === void 0 ? void 0 : _a.cancel().catch(() => undefined));
|
|
106
|
+
};
|
|
107
|
+
const encodeBody = (body) => {
|
|
108
|
+
if (body === undefined) {
|
|
109
|
+
return undefined;
|
|
110
|
+
}
|
|
111
|
+
return typeof body === "string" ? body : JSON.stringify(body);
|
|
112
|
+
};
|
|
113
|
+
const readJson = async (response) => {
|
|
114
|
+
const text = await response.text();
|
|
115
|
+
return (text === "" ? undefined : JSON.parse(text));
|
|
116
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const retryAfterMs: (header: string | null) => number | null;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.retryAfterMs = void 0;
|
|
4
|
+
const MS_PER_SECOND = 1000;
|
|
5
|
+
const retryAfterMs = (header) => {
|
|
6
|
+
if (header === null) {
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
const seconds = Number(header);
|
|
10
|
+
if (Number.isFinite(seconds)) {
|
|
11
|
+
return seconds * MS_PER_SECOND;
|
|
12
|
+
}
|
|
13
|
+
const date = Date.parse(header);
|
|
14
|
+
return Number.isNaN(date) ? null : Math.max(0, date - Date.now());
|
|
15
|
+
};
|
|
16
|
+
exports.retryAfterMs = retryAfterMs;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type Sleep = (ms: number) => Promise<void>;
|
|
2
|
+
export type RetryableRequest = {
|
|
3
|
+
method: string;
|
|
4
|
+
idempotent?: boolean;
|
|
5
|
+
};
|
|
6
|
+
export declare class RetryPolicy {
|
|
7
|
+
private readonly maxRetries;
|
|
8
|
+
private readonly wait;
|
|
9
|
+
constructor(maxRetries: number, wait?: Sleep);
|
|
10
|
+
allows(request: RetryableRequest, attempt: number): boolean;
|
|
11
|
+
isRetryableStatus(status: number): boolean;
|
|
12
|
+
pause(attempt: number, retryAfterMs: number | null): Promise<void>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RetryPolicy = void 0;
|
|
4
|
+
const RETRYABLE_STATUSES = new Set([429, 502, 503, 504]);
|
|
5
|
+
const IDEMPOTENT_METHODS = new Set(["GET", "HEAD", "PUT", "DELETE"]);
|
|
6
|
+
const BASE_DELAY_MS = 300;
|
|
7
|
+
const MAX_DELAY_MS = 5000;
|
|
8
|
+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
9
|
+
class RetryPolicy {
|
|
10
|
+
constructor(maxRetries, wait = sleep) {
|
|
11
|
+
this.maxRetries = maxRetries;
|
|
12
|
+
this.wait = wait;
|
|
13
|
+
}
|
|
14
|
+
allows(request, attempt) {
|
|
15
|
+
var _a;
|
|
16
|
+
const repeatable = (_a = request.idempotent) !== null && _a !== void 0 ? _a : IDEMPOTENT_METHODS.has(request.method);
|
|
17
|
+
return repeatable && attempt < this.maxRetries;
|
|
18
|
+
}
|
|
19
|
+
isRetryableStatus(status) {
|
|
20
|
+
return RETRYABLE_STATUSES.has(status);
|
|
21
|
+
}
|
|
22
|
+
pause(attempt, retryAfterMs) {
|
|
23
|
+
const backoffMs = BASE_DELAY_MS * 2 ** attempt;
|
|
24
|
+
return this.wait(Math.min(retryAfterMs !== null && retryAfterMs !== void 0 ? retryAfterMs : backoffMs, MAX_DELAY_MS));
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.RetryPolicy = RetryPolicy;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { OvokSettings } from "../config/ovok-config";
|
|
2
|
+
export type RequestOptions = {
|
|
3
|
+
signal?: AbortSignal;
|
|
4
|
+
timeoutMs?: number;
|
|
5
|
+
};
|
|
6
|
+
export type TransmitRequest = {
|
|
7
|
+
url: string;
|
|
8
|
+
method: string;
|
|
9
|
+
headers: Record<string, string>;
|
|
10
|
+
body: string | undefined;
|
|
11
|
+
};
|
|
12
|
+
type TransmitSettings = Pick<OvokSettings, "fetch" | "timeoutMs">;
|
|
13
|
+
export declare function transmit(settings: TransmitSettings, request: TransmitRequest, options?: RequestOptions): Promise<Response>;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transmit = transmit;
|
|
4
|
+
const ovok_errors_1 = require("../errors/ovok-errors");
|
|
5
|
+
async function transmit(settings, request, options = {}) {
|
|
6
|
+
var _a;
|
|
7
|
+
const deadline = new Deadline((_a = options.timeoutMs) !== null && _a !== void 0 ? _a : settings.timeoutMs, options.signal);
|
|
8
|
+
try {
|
|
9
|
+
return await settings.fetch(request.url, {
|
|
10
|
+
method: request.method,
|
|
11
|
+
headers: request.headers,
|
|
12
|
+
body: request.body,
|
|
13
|
+
signal: deadline.signal,
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
throw deadline.explain(error);
|
|
18
|
+
}
|
|
19
|
+
finally {
|
|
20
|
+
deadline.clear();
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
class Deadline {
|
|
24
|
+
constructor(timeoutMs, callerSignal) {
|
|
25
|
+
this.timeoutMs = timeoutMs;
|
|
26
|
+
this.callerSignal = callerSignal;
|
|
27
|
+
this.controller = new AbortController();
|
|
28
|
+
this.followCaller = () => { var _a; return this.controller.abort((_a = this.callerSignal) === null || _a === void 0 ? void 0 : _a.reason); };
|
|
29
|
+
this.expired = false;
|
|
30
|
+
this.timer = setTimeout(() => this.expire(), timeoutMs);
|
|
31
|
+
callerSignal === null || callerSignal === void 0 ? void 0 : callerSignal.addEventListener("abort", this.followCaller, { once: true });
|
|
32
|
+
if (callerSignal === null || callerSignal === void 0 ? void 0 : callerSignal.aborted) {
|
|
33
|
+
this.followCaller();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
get signal() {
|
|
37
|
+
return this.controller.signal;
|
|
38
|
+
}
|
|
39
|
+
/** A caller's own abort passes through untouched; everything else is a connection failure. */
|
|
40
|
+
explain(error) {
|
|
41
|
+
var _a, _b;
|
|
42
|
+
if ((_a = this.callerSignal) === null || _a === void 0 ? void 0 : _a.aborted) {
|
|
43
|
+
return (_b = this.callerSignal.reason) !== null && _b !== void 0 ? _b : error;
|
|
44
|
+
}
|
|
45
|
+
const message = this.expired ? `The request timed out after ${this.timeoutMs} ms.` : "Could not reach the Ovok API.";
|
|
46
|
+
return new ovok_errors_1.OvokConnectionError((0, ovok_errors_1.detailsFor)(message), error);
|
|
47
|
+
}
|
|
48
|
+
clear() {
|
|
49
|
+
var _a;
|
|
50
|
+
clearTimeout(this.timer);
|
|
51
|
+
(_a = this.callerSignal) === null || _a === void 0 ? void 0 : _a.removeEventListener("abort", this.followCaller);
|
|
52
|
+
}
|
|
53
|
+
expire() {
|
|
54
|
+
this.expired = true;
|
|
55
|
+
this.controller.abort();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type QueryValue = string | number | boolean | readonly string[] | undefined;
|
|
2
|
+
export type QueryParams = Record<string, QueryValue>;
|
|
3
|
+
export declare const joinPath: (...parts: string[]) => string;
|
|
4
|
+
export declare const pathSegment: (value: string) => string;
|
|
5
|
+
/** A list value repeats its key, so `date: ["ge1", "le2"]` is FHIR's AND; write "a,b" for OR. */
|
|
6
|
+
export declare function toSearchQuery(params: QueryParams): string;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.pathSegment = exports.joinPath = void 0;
|
|
4
|
+
exports.toSearchQuery = toSearchQuery;
|
|
5
|
+
const joinPath = (...parts) => parts
|
|
6
|
+
.map((part) => part.replace(/^\/+|\/+$/g, ""))
|
|
7
|
+
.filter((part) => part !== "")
|
|
8
|
+
.join("/");
|
|
9
|
+
exports.joinPath = joinPath;
|
|
10
|
+
const pathSegment = (value) => encodeURIComponent(value);
|
|
11
|
+
exports.pathSegment = pathSegment;
|
|
12
|
+
/** A list value repeats its key, so `date: ["ge1", "le2"]` is FHIR's AND; write "a,b" for OR. */
|
|
13
|
+
function toSearchQuery(params) {
|
|
14
|
+
const pairs = Object.entries(params).flatMap(([key, value]) => valuesOf(value).map((entry) => `${encodeURIComponent(key)}=${encodeURIComponent(entry)}`));
|
|
15
|
+
return pairs.length === 0 ? "" : `?${pairs.join("&")}`;
|
|
16
|
+
}
|
|
17
|
+
const valuesOf = (value) => {
|
|
18
|
+
if (value === undefined) {
|
|
19
|
+
return [];
|
|
20
|
+
}
|
|
21
|
+
return typeof value === "object" ? value.map(String) : [String(value)];
|
|
22
|
+
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
export { Ovok } from "./ovok";
|
|
2
|
+
export type { OvokConfig, OvokFetch, OvokUnauthenticatedReason } from "./config/ovok-config";
|
|
3
|
+
export { MemoryStorage } from "./storage/ovok-storage";
|
|
4
|
+
export type { OvokStorage } from "./storage/ovok-storage";
|
|
5
|
+
export { OvokAuthenticationError, OvokConfigError, OvokConflictError, OvokConnectionError, OvokError, OvokNotFoundError, OvokPermissionError, OvokRateLimitError, OvokServiceError, OvokValidationError, } from "./errors/ovok-errors";
|
|
6
|
+
export { OvokAccountError } from "./errors/ovok-account-error";
|
|
7
|
+
export type { OvokErrorDetails } from "./errors/ovok-errors";
|
|
8
|
+
export type { RequestOptions } from "./http/transmit";
|
|
9
|
+
export type { QueryParams, QueryValue } from "./http/url";
|
|
10
|
+
export type { Page, PagePromise } from "./paging/page";
|
|
11
|
+
export type { OvokReference, Session } from "./auth/session";
|
|
12
|
+
export type { SavedAccount } from "./auth/saved-accounts-store";
|
|
13
|
+
export type { SessionChangeListener } from "./auth/user-session";
|
|
14
|
+
export type { LoginCredentials, LoginResult, MfaChallenge, ProfileType } from "./resources/auth-resource";
|
|
15
|
+
export type { CreateOptions, PatchOperation } from "./resources/fhir-resource";
|
|
16
|
+
export type { HealthCheck } from "./resources/health-resource";
|
|
17
|
+
export type { PatientRegistration, PractitionerRegistration, RegisterResult } from "./resources/auth/registration";
|
|
18
|
+
export type { SocialCredentials, SocialProvider } from "./resources/auth/social-login";
|
|
19
|
+
export type { LastObservationsQuery, LatestObservationsParams, MeasurementCodeTypes, SaveObservationsOptions, SaveObservationsResult, } from "./resources/measurements/measurements-resource";
|
|
20
|
+
export type { BuildObservationsParams } from "./resources/measurements/observation-builder";
|
|
21
|
+
export type { SignalsDeliveryRepair, SignalsDeliveryRepairResult, SignalsUndeliverable, SignalsUndeliverableResident, } from "./resources/signals/undeliverable-resource";
|
|
22
|
+
export type { ProjectListQuery } from "./resources/projects/projects-resource";
|
|
23
|
+
export type { ProjectMemberListQuery } from "./resources/projects/project-members-resource";
|
|
24
|
+
export type { LocalizationList } from "./resources/localization/localizations-resource";
|
|
25
|
+
export type { PersonInviteFlow, RecordShareFlow } from "./resources/invites/invites-resource";
|
|
26
|
+
export type { AiFhirSearchRequest } from "./resources/ai/ai-resource";
|
|
27
|
+
export type { ChatSessionRetrieveParams } from "./resources/ai/chat-sessions-resource";
|
|
28
|
+
export type { VideoCallAccessPermission } from "./resources/video-calls/video-call-access-resource";
|
|
29
|
+
export type { ActiveCallNotification } from "./resources/video-calls/video-calls-resource";
|
|
30
|
+
export type { CmsListParams, CmsReadParams } from "./resources/cms/cms-delivery";
|
|
31
|
+
export type { DeletedDocument, DocumentDownloadParams } from "./resources/documents/documents-resource";
|
|
32
|
+
export type { BotInput, BotOutput } from "./resources/bots/bots-resource";
|
|
33
|
+
export type * from "./resources/slim/slim-queries";
|
|
34
|
+
export type { AccountsResource } from "./resources/accounts/accounts-resource";
|
|
35
|
+
export type { AiResource } from "./resources/ai/ai-resource";
|
|
36
|
+
export type { AuthResource } from "./resources/auth-resource";
|
|
37
|
+
export type { BotsResource } from "./resources/bots/bots-resource";
|
|
38
|
+
export type { CmsResource } from "./resources/cms/cms-resource";
|
|
39
|
+
export type { ConsentResource } from "./resources/consent/consent-resource";
|
|
40
|
+
export type { ContentResource } from "./resources/content/content-resource";
|
|
41
|
+
export type { DocumentsResource } from "./resources/documents/documents-resource";
|
|
42
|
+
export type { EmailResource } from "./resources/email/email-resource";
|
|
43
|
+
export type { FhirResource } from "./resources/fhir-resource";
|
|
44
|
+
export type { HealthResource } from "./resources/health-resource";
|
|
45
|
+
export type { InvitesResource } from "./resources/invites/invites-resource";
|
|
46
|
+
export type { LocalesResource } from "./resources/localization/locales-resource";
|
|
47
|
+
export type { LocalizationsResource } from "./resources/localization/localizations-resource";
|
|
48
|
+
export type { MeasurementsResource } from "./resources/measurements/measurements-resource";
|
|
49
|
+
export type { PatientResource } from "./resources/patient/patient-resource";
|
|
50
|
+
export type { ProjectsResource } from "./resources/projects/projects-resource";
|
|
51
|
+
export type { QuestionnaireResponsesResource, QuestionnairesResource, } from "./resources/questionnaires/questionnaires-resource";
|
|
52
|
+
export type { SharingResource } from "./resources/sharing/sharing-resource";
|
|
53
|
+
export type { SavedAccountsResource } from "./resources/session/saved-accounts-resource";
|
|
54
|
+
export type { SessionResource } from "./resources/session/session-resource";
|
|
55
|
+
export type { SignalsResource } from "./resources/signals/signals-resource";
|
|
56
|
+
export type { SignalsGatewayRequest } from "./resources/signals/signals-gateway-resource";
|
|
57
|
+
export type { SlimResource } from "./resources/slim/slim-resource";
|
|
58
|
+
export type { VideoCallsResource } from "./resources/video-calls/video-calls-resource";
|
|
59
|
+
export type { WearablesResource } from "./resources/wearables/wearables-resource";
|
|
60
|
+
export * from "../types/MeasurementTypes";
|
|
61
|
+
export type * from "../client/slim/types";
|
|
62
|
+
export type * from "../client/notifications/types";
|
|
63
|
+
export type * from "../client/change-history/types";
|
|
64
|
+
export type * from "../client/experience/types";
|
|
65
|
+
export type * from "../client/platform/types";
|
|
66
|
+
export type * from "../client/consent/types";
|
|
67
|
+
export type * from "../client/patient-sharing/types";
|
|
68
|
+
export type * from "../client/invites/types";
|
|
69
|
+
export type * from "../client/wearables/types";
|
|
70
|
+
export type * from "../client/cms/types";
|
|
71
|
+
export type * from "../client/email/types";
|
|
72
|
+
export type * from "../client/patient/types";
|
|
73
|
+
export type * from "../client/ai-fhir/types";
|
|
74
|
+
export type { EnableSignalsResponse } from "../client/signals/types";
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.OvokAccountError = exports.OvokValidationError = exports.OvokServiceError = exports.OvokRateLimitError = exports.OvokPermissionError = exports.OvokNotFoundError = exports.OvokError = exports.OvokConnectionError = exports.OvokConflictError = exports.OvokConfigError = exports.OvokAuthenticationError = exports.MemoryStorage = exports.Ovok = void 0;
|
|
18
|
+
var ovok_1 = require("./ovok");
|
|
19
|
+
Object.defineProperty(exports, "Ovok", { enumerable: true, get: function () { return ovok_1.Ovok; } });
|
|
20
|
+
var ovok_storage_1 = require("./storage/ovok-storage");
|
|
21
|
+
Object.defineProperty(exports, "MemoryStorage", { enumerable: true, get: function () { return ovok_storage_1.MemoryStorage; } });
|
|
22
|
+
var ovok_errors_1 = require("./errors/ovok-errors");
|
|
23
|
+
Object.defineProperty(exports, "OvokAuthenticationError", { enumerable: true, get: function () { return ovok_errors_1.OvokAuthenticationError; } });
|
|
24
|
+
Object.defineProperty(exports, "OvokConfigError", { enumerable: true, get: function () { return ovok_errors_1.OvokConfigError; } });
|
|
25
|
+
Object.defineProperty(exports, "OvokConflictError", { enumerable: true, get: function () { return ovok_errors_1.OvokConflictError; } });
|
|
26
|
+
Object.defineProperty(exports, "OvokConnectionError", { enumerable: true, get: function () { return ovok_errors_1.OvokConnectionError; } });
|
|
27
|
+
Object.defineProperty(exports, "OvokError", { enumerable: true, get: function () { return ovok_errors_1.OvokError; } });
|
|
28
|
+
Object.defineProperty(exports, "OvokNotFoundError", { enumerable: true, get: function () { return ovok_errors_1.OvokNotFoundError; } });
|
|
29
|
+
Object.defineProperty(exports, "OvokPermissionError", { enumerable: true, get: function () { return ovok_errors_1.OvokPermissionError; } });
|
|
30
|
+
Object.defineProperty(exports, "OvokRateLimitError", { enumerable: true, get: function () { return ovok_errors_1.OvokRateLimitError; } });
|
|
31
|
+
Object.defineProperty(exports, "OvokServiceError", { enumerable: true, get: function () { return ovok_errors_1.OvokServiceError; } });
|
|
32
|
+
Object.defineProperty(exports, "OvokValidationError", { enumerable: true, get: function () { return ovok_errors_1.OvokValidationError; } });
|
|
33
|
+
var ovok_account_error_1 = require("./errors/ovok-account-error");
|
|
34
|
+
Object.defineProperty(exports, "OvokAccountError", { enumerable: true, get: function () { return ovok_account_error_1.OvokAccountError; } });
|
|
35
|
+
__exportStar(require("../types/MeasurementTypes"), exports);
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { OvokConfig } from "./config/ovok-config";
|
|
2
|
+
import { AccountsResource } from "./resources/accounts/accounts-resource";
|
|
3
|
+
import { AiResource } from "./resources/ai/ai-resource";
|
|
4
|
+
import { AuthResource } from "./resources/auth-resource";
|
|
5
|
+
import { BotsResource } from "./resources/bots/bots-resource";
|
|
6
|
+
import { CmsResource } from "./resources/cms/cms-resource";
|
|
7
|
+
import { ConsentResource } from "./resources/consent/consent-resource";
|
|
8
|
+
import { ContentResource } from "./resources/content/content-resource";
|
|
9
|
+
import { DocumentsResource } from "./resources/documents/documents-resource";
|
|
10
|
+
import { EmailResource } from "./resources/email/email-resource";
|
|
11
|
+
import { FhirResource } from "./resources/fhir-resource";
|
|
12
|
+
import { HealthResource } from "./resources/health-resource";
|
|
13
|
+
import { InvitesResource } from "./resources/invites/invites-resource";
|
|
14
|
+
import { LocalesResource } from "./resources/localization/locales-resource";
|
|
15
|
+
import { LocalizationsResource } from "./resources/localization/localizations-resource";
|
|
16
|
+
import { MeasurementsResource } from "./resources/measurements/measurements-resource";
|
|
17
|
+
import { PatientResource } from "./resources/patient/patient-resource";
|
|
18
|
+
import { ProjectsResource } from "./resources/projects/projects-resource";
|
|
19
|
+
import { QuestionnaireResponsesResource, QuestionnairesResource } from "./resources/questionnaires/questionnaires-resource";
|
|
20
|
+
import { SessionResource } from "./resources/session/session-resource";
|
|
21
|
+
import { SharingResource } from "./resources/sharing/sharing-resource";
|
|
22
|
+
import { SignalsResource } from "./resources/signals/signals-resource";
|
|
23
|
+
import { SlimResource } from "./resources/slim/slim-resource";
|
|
24
|
+
import { VideoCallsResource } from "./resources/video-calls/video-calls-resource";
|
|
25
|
+
import { WearablesResource } from "./resources/wearables/wearables-resource";
|
|
26
|
+
/** One client per tenant; each namespace mirrors an area of the Ovok API. */
|
|
27
|
+
export declare class Ovok {
|
|
28
|
+
readonly auth: AuthResource;
|
|
29
|
+
readonly session: SessionResource;
|
|
30
|
+
readonly fhir: FhirResource;
|
|
31
|
+
readonly health: HealthResource;
|
|
32
|
+
readonly patient: PatientResource;
|
|
33
|
+
readonly measurements: MeasurementsResource;
|
|
34
|
+
readonly questionnaires: QuestionnairesResource;
|
|
35
|
+
readonly questionnaireResponses: QuestionnaireResponsesResource;
|
|
36
|
+
readonly consent: ConsentResource;
|
|
37
|
+
readonly invites: InvitesResource;
|
|
38
|
+
readonly sharing: SharingResource;
|
|
39
|
+
readonly signals: SignalsResource;
|
|
40
|
+
readonly slim: SlimResource;
|
|
41
|
+
readonly projects: ProjectsResource;
|
|
42
|
+
readonly accounts: AccountsResource;
|
|
43
|
+
readonly locales: LocalesResource;
|
|
44
|
+
readonly localizations: LocalizationsResource;
|
|
45
|
+
readonly cms: CmsResource;
|
|
46
|
+
readonly content: ContentResource;
|
|
47
|
+
readonly documents: DocumentsResource;
|
|
48
|
+
readonly videoCalls: VideoCallsResource;
|
|
49
|
+
readonly ai: AiResource;
|
|
50
|
+
readonly wearables: WearablesResource;
|
|
51
|
+
readonly email: EmailResource;
|
|
52
|
+
readonly bots: BotsResource;
|
|
53
|
+
constructor(config: OvokConfig);
|
|
54
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Ovok = void 0;
|
|
4
|
+
const client_credentials_1 = require("./auth/client-credentials");
|
|
5
|
+
const saved_accounts_store_1 = require("./auth/saved-accounts-store");
|
|
6
|
+
const session_store_1 = require("./auth/session-store");
|
|
7
|
+
const token_endpoint_1 = require("./auth/token-endpoint");
|
|
8
|
+
const user_session_1 = require("./auth/user-session");
|
|
9
|
+
const settings_1 = require("./config/settings");
|
|
10
|
+
const http_client_1 = require("./http/http-client");
|
|
11
|
+
const retry_policy_1 = require("./http/retry-policy");
|
|
12
|
+
const accounts_resource_1 = require("./resources/accounts/accounts-resource");
|
|
13
|
+
const ai_resource_1 = require("./resources/ai/ai-resource");
|
|
14
|
+
const auth_resource_1 = require("./resources/auth-resource");
|
|
15
|
+
const bots_resource_1 = require("./resources/bots/bots-resource");
|
|
16
|
+
const cms_resource_1 = require("./resources/cms/cms-resource");
|
|
17
|
+
const consent_resource_1 = require("./resources/consent/consent-resource");
|
|
18
|
+
const content_resource_1 = require("./resources/content/content-resource");
|
|
19
|
+
const documents_resource_1 = require("./resources/documents/documents-resource");
|
|
20
|
+
const email_resource_1 = require("./resources/email/email-resource");
|
|
21
|
+
const fhir_resource_1 = require("./resources/fhir-resource");
|
|
22
|
+
const health_resource_1 = require("./resources/health-resource");
|
|
23
|
+
const invites_resource_1 = require("./resources/invites/invites-resource");
|
|
24
|
+
const locales_resource_1 = require("./resources/localization/locales-resource");
|
|
25
|
+
const localizations_resource_1 = require("./resources/localization/localizations-resource");
|
|
26
|
+
const measurements_resource_1 = require("./resources/measurements/measurements-resource");
|
|
27
|
+
const patient_resource_1 = require("./resources/patient/patient-resource");
|
|
28
|
+
const projects_resource_1 = require("./resources/projects/projects-resource");
|
|
29
|
+
const questionnaires_resource_1 = require("./resources/questionnaires/questionnaires-resource");
|
|
30
|
+
const session_resource_1 = require("./resources/session/session-resource");
|
|
31
|
+
const sharing_resource_1 = require("./resources/sharing/sharing-resource");
|
|
32
|
+
const signals_resource_1 = require("./resources/signals/signals-resource");
|
|
33
|
+
const slim_resource_1 = require("./resources/slim/slim-resource");
|
|
34
|
+
const video_calls_resource_1 = require("./resources/video-calls/video-calls-resource");
|
|
35
|
+
const wearables_resource_1 = require("./resources/wearables/wearables-resource");
|
|
36
|
+
/** One client per tenant; each namespace mirrors an area of the Ovok API. */
|
|
37
|
+
class Ovok {
|
|
38
|
+
constructor(config) {
|
|
39
|
+
const settings = (0, settings_1.readSettings)(config, (0, settings_1.currentEnvironment)());
|
|
40
|
+
const credentials = credentialsFor(settings);
|
|
41
|
+
const http = new http_client_1.HttpClient({ settings, credentials, retryPolicy: new retry_policy_1.RetryPolicy(settings.maxNetworkRetries) });
|
|
42
|
+
const session = credentials instanceof user_session_1.UserSession ? credentials : null;
|
|
43
|
+
const fhir = new fhir_resource_1.FhirResource(http.under(settings.fhirPath));
|
|
44
|
+
this.auth = new auth_resource_1.AuthResource(http, settings.tenantCode, session, settings.clientId);
|
|
45
|
+
this.session = new session_resource_1.SessionResource(http, session);
|
|
46
|
+
this.fhir = fhir;
|
|
47
|
+
this.health = new health_resource_1.HealthResource(http.anonymous());
|
|
48
|
+
this.patient = new patient_resource_1.PatientResource(http, fhir);
|
|
49
|
+
this.measurements = new measurements_resource_1.MeasurementsResource(http, fhir, session);
|
|
50
|
+
this.questionnaires = new questionnaires_resource_1.QuestionnairesResource(http);
|
|
51
|
+
this.questionnaireResponses = new questionnaires_resource_1.QuestionnaireResponsesResource(http, fhir);
|
|
52
|
+
this.consent = new consent_resource_1.ConsentResource(http);
|
|
53
|
+
this.invites = new invites_resource_1.InvitesResource(http, session);
|
|
54
|
+
this.sharing = new sharing_resource_1.SharingResource(http);
|
|
55
|
+
this.signals = new signals_resource_1.SignalsResource(http);
|
|
56
|
+
this.slim = new slim_resource_1.SlimResource(http, session);
|
|
57
|
+
this.projects = new projects_resource_1.ProjectsResource(http);
|
|
58
|
+
this.accounts = new accounts_resource_1.AccountsResource(http);
|
|
59
|
+
this.locales = new locales_resource_1.LocalesResource(http);
|
|
60
|
+
this.localizations = new localizations_resource_1.LocalizationsResource(http);
|
|
61
|
+
this.cms = new cms_resource_1.CmsResource(http, settings.tenantCode);
|
|
62
|
+
this.content = new content_resource_1.ContentResource(http);
|
|
63
|
+
this.documents = new documents_resource_1.DocumentsResource(http, settings.baseUrl);
|
|
64
|
+
this.videoCalls = new video_calls_resource_1.VideoCallsResource(http);
|
|
65
|
+
this.ai = new ai_resource_1.AiResource(http);
|
|
66
|
+
this.wearables = new wearables_resource_1.WearablesResource(http);
|
|
67
|
+
this.email = new email_resource_1.EmailResource(http);
|
|
68
|
+
this.bots = new bots_resource_1.BotsResource(http);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
exports.Ovok = Ovok;
|
|
72
|
+
const credentialsFor = (settings) => {
|
|
73
|
+
const tokenEndpoint = new token_endpoint_1.TokenEndpoint(settings);
|
|
74
|
+
return settings.machineClient
|
|
75
|
+
? new client_credentials_1.ClientCredentials(tokenEndpoint, settings.machineClient)
|
|
76
|
+
: new user_session_1.UserSession((0, session_store_1.sessionStoreFor)(settings.storage, settings.tenantCode), tokenEndpoint, settings, Date.now, (0, saved_accounts_store_1.savedAccountsStoreFor)(settings.storage, settings.tenantCode));
|
|
77
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Bundle, Resource } from "@medplum/fhirtypes";
|
|
2
|
+
import { LoadedPage } from "./page";
|
|
3
|
+
/** Follows the next link by its query only: Medplum writes its own host into the link, and Ovok is the only door. */
|
|
4
|
+
export declare function bundlePage<T extends Resource>(bundle: Bundle<T>, loadNext: (query: string) => Promise<LoadedPage<T>>): LoadedPage<T>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.bundlePage = bundlePage;
|
|
4
|
+
const NON_MATCH_SEARCH_MODES = new Set(["include", "outcome"]);
|
|
5
|
+
/** Follows the next link by its query only: Medplum writes its own host into the link, and Ovok is the only door. */
|
|
6
|
+
function bundlePage(bundle, loadNext) {
|
|
7
|
+
var _a, _b, _c;
|
|
8
|
+
const nextUrl = (_b = (_a = bundle.link) === null || _a === void 0 ? void 0 : _a.find((link) => link.relation === "next")) === null || _b === void 0 ? void 0 : _b.url;
|
|
9
|
+
return {
|
|
10
|
+
page: { data: matchesOf(bundle), hasMore: nextUrl !== undefined, total: (_c = bundle.total) !== null && _c !== void 0 ? _c : null },
|
|
11
|
+
next: nextUrl === undefined ? null : () => loadNext(queryOf(nextUrl)),
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
const matchesOf = (bundle) => {
|
|
15
|
+
var _a;
|
|
16
|
+
return ((_a = bundle.entry) !== null && _a !== void 0 ? _a : [])
|
|
17
|
+
.filter(isMatch)
|
|
18
|
+
.map((entry) => entry.resource)
|
|
19
|
+
.filter((resource) => resource !== undefined);
|
|
20
|
+
};
|
|
21
|
+
const isMatch = (entry) => { var _a, _b; return !NON_MATCH_SEARCH_MODES.has((_b = (_a = entry.search) === null || _a === void 0 ? void 0 : _a.mode) !== null && _b !== void 0 ? _b : "match"); };
|
|
22
|
+
const queryOf = (url) => {
|
|
23
|
+
const start = url.indexOf("?");
|
|
24
|
+
return start === -1 ? "" : url.slice(start);
|
|
25
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { PagePromise } from "./page";
|
|
2
|
+
/** Ovok's cursor list shape: pass `nextCursor` back unchanged for the next page. */
|
|
3
|
+
export type CursorPage<T> = {
|
|
4
|
+
items: T[];
|
|
5
|
+
nextCursor: string | null;
|
|
6
|
+
};
|
|
7
|
+
export declare function cursorPages<T>(load: (cursor: string | undefined) => Promise<CursorPage<T>>): PagePromise<T>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.cursorPages = cursorPages;
|
|
4
|
+
const page_1 = require("./page");
|
|
5
|
+
function cursorPages(load) {
|
|
6
|
+
return (0, page_1.pagePromise)(() => loadCursor(load, undefined));
|
|
7
|
+
}
|
|
8
|
+
async function loadCursor(load, cursor) {
|
|
9
|
+
const { items, nextCursor } = await load(cursor);
|
|
10
|
+
return {
|
|
11
|
+
page: { data: items, hasMore: nextCursor !== null, total: null },
|
|
12
|
+
next: nextCursor === null ? null : () => loadCursor(load, nextCursor),
|
|
13
|
+
};
|
|
14
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { QueryValue } from "../http/url";
|
|
2
|
+
import { PagePromise } from "./page";
|
|
3
|
+
/** Ovok's page-numbered list shape: `page` is 0-based and `count` is the page size. */
|
|
4
|
+
export type NumberedPage<T> = {
|
|
5
|
+
total: number;
|
|
6
|
+
page: number;
|
|
7
|
+
count: number;
|
|
8
|
+
resources: T[];
|
|
9
|
+
};
|
|
10
|
+
export declare function numberedPages<T>(load: (page: number) => Promise<NumberedPage<T>>, firstPage?: number): PagePromise<T>;
|
|
11
|
+
export type NumberedPageQuery = Record<string, QueryValue> & {
|
|
12
|
+
page?: number;
|
|
13
|
+
};
|
|
14
|
+
/** Lists a page-numbered route with Ovok's query encoding; `query.page` is the first page loaded. */
|
|
15
|
+
export declare const numberedRoutePages: <T>(read: (path: string) => Promise<NumberedPage<T>>, path: string, query: NumberedPageQuery) => PagePromise<T>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.numberedRoutePages = void 0;
|
|
4
|
+
exports.numberedPages = numberedPages;
|
|
5
|
+
const query_string_1 = require("../../client/query-string");
|
|
6
|
+
const page_1 = require("./page");
|
|
7
|
+
function numberedPages(load, firstPage = 0) {
|
|
8
|
+
return (0, page_1.pagePromise)(() => loadNumbered(load, firstPage));
|
|
9
|
+
}
|
|
10
|
+
async function loadNumbered(load, page) {
|
|
11
|
+
const result = await load(page);
|
|
12
|
+
const hasMore = (result.page + 1) * result.count < result.total;
|
|
13
|
+
return {
|
|
14
|
+
page: { data: result.resources, hasMore, total: result.total },
|
|
15
|
+
next: hasMore ? () => loadNumbered(load, result.page + 1) : null,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/** Lists a page-numbered route with Ovok's query encoding; `query.page` is the first page loaded. */
|
|
19
|
+
const numberedRoutePages = (read, path, query) => numberedPages((page) => read(`${path}${(0, query_string_1.toQueryString)({ ...query, page })}`), query.page);
|
|
20
|
+
exports.numberedRoutePages = numberedRoutePages;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type Page<T> = {
|
|
2
|
+
data: T[];
|
|
3
|
+
hasMore: boolean;
|
|
4
|
+
total: number | null;
|
|
5
|
+
};
|
|
6
|
+
/** Await it for the first page, or `for await` over it to walk every page. */
|
|
7
|
+
export type PagePromise<T> = Promise<Page<T>> & AsyncIterable<T>;
|
|
8
|
+
export type LoadedPage<T> = {
|
|
9
|
+
page: Page<T>;
|
|
10
|
+
next: (() => Promise<LoadedPage<T>>) | null;
|
|
11
|
+
};
|
|
12
|
+
export declare function pagePromise<T>(loadFirst: () => Promise<LoadedPage<T>>): PagePromise<T>;
|