@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,12 @@
|
|
|
1
|
+
import { OvokSettings } from "../config/ovok-config";
|
|
2
|
+
export type OAuthTokenResponse = {
|
|
3
|
+
access_token: string;
|
|
4
|
+
refresh_token?: string;
|
|
5
|
+
expires_in: number;
|
|
6
|
+
token_type: string;
|
|
7
|
+
};
|
|
8
|
+
export declare class TokenEndpoint {
|
|
9
|
+
private readonly settings;
|
|
10
|
+
constructor(settings: OvokSettings);
|
|
11
|
+
request(form: Record<string, string>): Promise<OAuthTokenResponse>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TokenEndpoint = void 0;
|
|
4
|
+
const error_from_response_1 = require("../errors/error-from-response");
|
|
5
|
+
const transmit_1 = require("../http/transmit");
|
|
6
|
+
const TOKEN_PATH = "oauth2/token";
|
|
7
|
+
const FORM_TYPE = "application/x-www-form-urlencoded";
|
|
8
|
+
class TokenEndpoint {
|
|
9
|
+
constructor(settings) {
|
|
10
|
+
this.settings = settings;
|
|
11
|
+
}
|
|
12
|
+
async request(form) {
|
|
13
|
+
const response = await (0, transmit_1.transmit)(this.settings, {
|
|
14
|
+
url: `${this.settings.baseUrl}${TOKEN_PATH}`,
|
|
15
|
+
method: "POST",
|
|
16
|
+
headers: { "Content-Type": FORM_TYPE, Accept: "application/json" },
|
|
17
|
+
body: encodeForm(form),
|
|
18
|
+
});
|
|
19
|
+
if (response.ok) {
|
|
20
|
+
return (await response.json());
|
|
21
|
+
}
|
|
22
|
+
throw await (0, error_from_response_1.errorFromResponse)(response);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.TokenEndpoint = TokenEndpoint;
|
|
26
|
+
const encodeForm = (form) => Object.entries(form)
|
|
27
|
+
.map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`)
|
|
28
|
+
.join("&");
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { OvokSettings } from "../config/ovok-config";
|
|
2
|
+
import { Clock } from "./access-token";
|
|
3
|
+
import { Credentials } from "./credentials";
|
|
4
|
+
import { SavedAccount, SavedAccountsStore, StoredSavedAccount } from "./saved-accounts-store";
|
|
5
|
+
import { LoginTokens, Session } from "./session";
|
|
6
|
+
import { SessionStore } from "./session-store";
|
|
7
|
+
import { TokenEndpoint } from "./token-endpoint";
|
|
8
|
+
type SessionSettings = Pick<OvokSettings, "clientId" | "onUnauthenticated">;
|
|
9
|
+
export type SessionChangeListener = (session: Session | null) => void;
|
|
10
|
+
export declare class UserSession implements Credentials {
|
|
11
|
+
private readonly store;
|
|
12
|
+
private readonly endpoint;
|
|
13
|
+
private readonly settings;
|
|
14
|
+
private readonly now;
|
|
15
|
+
private readonly savedAccounts;
|
|
16
|
+
private loaded;
|
|
17
|
+
private pendingRefresh;
|
|
18
|
+
private readonly changeListeners;
|
|
19
|
+
constructor(store: SessionStore, endpoint: TokenEndpoint, settings: SessionSettings, now?: Clock, savedAccounts?: SavedAccountsStore | null);
|
|
20
|
+
current(): Promise<Session | null>;
|
|
21
|
+
onChange(listener: SessionChangeListener): () => void;
|
|
22
|
+
begin(tokens: LoginTokens): Promise<Session>;
|
|
23
|
+
end(): Promise<void>;
|
|
24
|
+
listSavedAccounts(): Promise<SavedAccount[]>;
|
|
25
|
+
getSavedAccount(accountId: string): Promise<StoredSavedAccount | null>;
|
|
26
|
+
switchSavedAccount(accountId: string): Promise<void>;
|
|
27
|
+
removeSavedAccount(accountId: string): Promise<void>;
|
|
28
|
+
markSavedAccountExpired(accountId: string): Promise<void>;
|
|
29
|
+
forSavedAccount(session: Session): UserSession;
|
|
30
|
+
accessToken(): Promise<string | null>;
|
|
31
|
+
refresh(): Promise<boolean>;
|
|
32
|
+
private exchangeRefreshToken;
|
|
33
|
+
/** Only a refused refresh token signs the user out; an outage keeps the session for a later retry. */
|
|
34
|
+
private signOutIfRejected;
|
|
35
|
+
private refreshForm;
|
|
36
|
+
private save;
|
|
37
|
+
private notifyChange;
|
|
38
|
+
}
|
|
39
|
+
export {};
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UserSession = void 0;
|
|
4
|
+
const ovok_account_error_1 = require("../errors/ovok-account-error");
|
|
5
|
+
const ovok_errors_1 = require("../errors/ovok-errors");
|
|
6
|
+
const ovok_storage_1 = require("../storage/ovok-storage");
|
|
7
|
+
const session_1 = require("./session");
|
|
8
|
+
const session_store_1 = require("./session-store");
|
|
9
|
+
const REJECTED_REFRESH_STATUSES = new Set([400, 401, 403]);
|
|
10
|
+
class UserSession {
|
|
11
|
+
constructor(store, endpoint, settings, now = Date.now, savedAccounts = null) {
|
|
12
|
+
this.store = store;
|
|
13
|
+
this.endpoint = endpoint;
|
|
14
|
+
this.settings = settings;
|
|
15
|
+
this.now = now;
|
|
16
|
+
this.savedAccounts = savedAccounts;
|
|
17
|
+
this.loaded = null;
|
|
18
|
+
this.pendingRefresh = null;
|
|
19
|
+
this.changeListeners = new Set();
|
|
20
|
+
}
|
|
21
|
+
current() {
|
|
22
|
+
if (this.loaded === null) {
|
|
23
|
+
const pending = this.store.load().catch((error) => {
|
|
24
|
+
if (this.loaded === pending) {
|
|
25
|
+
this.loaded = null;
|
|
26
|
+
}
|
|
27
|
+
throw error;
|
|
28
|
+
});
|
|
29
|
+
this.loaded = pending;
|
|
30
|
+
}
|
|
31
|
+
return this.loaded;
|
|
32
|
+
}
|
|
33
|
+
onChange(listener) {
|
|
34
|
+
this.changeListeners.add(listener);
|
|
35
|
+
return () => this.changeListeners.delete(listener);
|
|
36
|
+
}
|
|
37
|
+
async begin(tokens) {
|
|
38
|
+
const session = (0, session_1.sessionFromLogin)(tokens, this.now());
|
|
39
|
+
await this.save(session);
|
|
40
|
+
this.notifyChange(session);
|
|
41
|
+
return session;
|
|
42
|
+
}
|
|
43
|
+
async end() {
|
|
44
|
+
var _a;
|
|
45
|
+
const current = await this.current().catch(() => null);
|
|
46
|
+
this.loaded = Promise.resolve(null);
|
|
47
|
+
await this.store.clear();
|
|
48
|
+
if (current) {
|
|
49
|
+
await ((_a = this.savedAccounts) === null || _a === void 0 ? void 0 : _a.remove(current.profile.reference));
|
|
50
|
+
}
|
|
51
|
+
this.notifyChange(null);
|
|
52
|
+
}
|
|
53
|
+
async listSavedAccounts() {
|
|
54
|
+
var _a;
|
|
55
|
+
const current = await this.current();
|
|
56
|
+
const currentAccountId = (_a = current === null || current === void 0 ? void 0 : current.profile.reference) !== null && _a !== void 0 ? _a : null;
|
|
57
|
+
if (this.savedAccounts === null) {
|
|
58
|
+
return [];
|
|
59
|
+
}
|
|
60
|
+
const accounts = await this.savedAccounts.list(currentAccountId);
|
|
61
|
+
if (current && !accounts.some((account) => account.active)) {
|
|
62
|
+
await this.savedAccounts.save(current);
|
|
63
|
+
return this.savedAccounts.list(currentAccountId);
|
|
64
|
+
}
|
|
65
|
+
return accounts;
|
|
66
|
+
}
|
|
67
|
+
async getSavedAccount(accountId) {
|
|
68
|
+
var _a, _b;
|
|
69
|
+
return (_b = (_a = this.savedAccounts) === null || _a === void 0 ? void 0 : _a.get(accountId)) !== null && _b !== void 0 ? _b : null;
|
|
70
|
+
}
|
|
71
|
+
async switchSavedAccount(accountId) {
|
|
72
|
+
const account = await this.getSavedAccount(accountId);
|
|
73
|
+
if (account === null) {
|
|
74
|
+
throw new ovok_account_error_1.OvokAccountError("account_not_found");
|
|
75
|
+
}
|
|
76
|
+
if (account.expired) {
|
|
77
|
+
throw new ovok_account_error_1.OvokAccountError("account_expired");
|
|
78
|
+
}
|
|
79
|
+
const current = await this.current();
|
|
80
|
+
if ((current === null || current === void 0 ? void 0 : current.profile.reference) === accountId) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
await this.store.save(account.session);
|
|
84
|
+
this.loaded = Promise.resolve(account.session);
|
|
85
|
+
this.notifyChange(account.session);
|
|
86
|
+
}
|
|
87
|
+
async removeSavedAccount(accountId) {
|
|
88
|
+
var _a, _b, _c;
|
|
89
|
+
const account = await this.getSavedAccount(accountId);
|
|
90
|
+
if (account === null) {
|
|
91
|
+
throw new ovok_account_error_1.OvokAccountError("account_not_found");
|
|
92
|
+
}
|
|
93
|
+
const current = await this.current();
|
|
94
|
+
const wasActive = (current === null || current === void 0 ? void 0 : current.profile.reference) === accountId;
|
|
95
|
+
if (wasActive) {
|
|
96
|
+
await this.store.clear();
|
|
97
|
+
this.loaded = Promise.resolve(null);
|
|
98
|
+
}
|
|
99
|
+
await ((_a = this.savedAccounts) === null || _a === void 0 ? void 0 : _a.remove(accountId));
|
|
100
|
+
if (wasActive) {
|
|
101
|
+
const nextAccount = ((_c = await ((_b = this.savedAccounts) === null || _b === void 0 ? void 0 : _b.list(null))) !== null && _c !== void 0 ? _c : []).find((saved) => !saved.expired);
|
|
102
|
+
if (nextAccount) {
|
|
103
|
+
await this.switchSavedAccount(nextAccount.id);
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
this.notifyChange(null);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
async markSavedAccountExpired(accountId) {
|
|
111
|
+
var _a;
|
|
112
|
+
await ((_a = this.savedAccounts) === null || _a === void 0 ? void 0 : _a.markExpired(accountId));
|
|
113
|
+
}
|
|
114
|
+
forSavedAccount(session) {
|
|
115
|
+
const isolated = new UserSession(new session_store_1.SessionStore(new ovok_storage_1.MemoryStorage(), "ovok:isolated-session"), this.endpoint, { ...this.settings, onUnauthenticated: () => undefined }, this.now);
|
|
116
|
+
isolated.loaded = Promise.resolve(session);
|
|
117
|
+
return isolated;
|
|
118
|
+
}
|
|
119
|
+
async accessToken() {
|
|
120
|
+
var _a, _b;
|
|
121
|
+
const session = await this.current();
|
|
122
|
+
const refreshable = session !== null && session.refreshToken !== null;
|
|
123
|
+
if (refreshable && (0, session_1.isSessionStaleAt)(session, this.now())) {
|
|
124
|
+
await this.refresh();
|
|
125
|
+
}
|
|
126
|
+
return (_b = (_a = (await this.current())) === null || _a === void 0 ? void 0 : _a.accessToken) !== null && _b !== void 0 ? _b : null;
|
|
127
|
+
}
|
|
128
|
+
refresh() {
|
|
129
|
+
var _a;
|
|
130
|
+
(_a = this.pendingRefresh) !== null && _a !== void 0 ? _a : (this.pendingRefresh = this.exchangeRefreshToken().finally(() => {
|
|
131
|
+
this.pendingRefresh = null;
|
|
132
|
+
}));
|
|
133
|
+
return this.pendingRefresh;
|
|
134
|
+
}
|
|
135
|
+
async exchangeRefreshToken() {
|
|
136
|
+
var _a;
|
|
137
|
+
const session = await this.current();
|
|
138
|
+
const refreshToken = (_a = session === null || session === void 0 ? void 0 : session.refreshToken) !== null && _a !== void 0 ? _a : null;
|
|
139
|
+
if (session === null || refreshToken === null) {
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
142
|
+
try {
|
|
143
|
+
const response = await this.endpoint.request(this.refreshForm(refreshToken));
|
|
144
|
+
await this.save((0, session_1.sessionAfterRefresh)(session, response, this.now()));
|
|
145
|
+
return true;
|
|
146
|
+
}
|
|
147
|
+
catch (error) {
|
|
148
|
+
return this.signOutIfRejected(error);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
/** Only a refused refresh token signs the user out; an outage keeps the session for a later retry. */
|
|
152
|
+
async signOutIfRejected(error) {
|
|
153
|
+
var _a;
|
|
154
|
+
const status = error instanceof ovok_errors_1.OvokError ? error.status : null;
|
|
155
|
+
const rejected = status !== null && REJECTED_REFRESH_STATUSES.has(status);
|
|
156
|
+
if (rejected) {
|
|
157
|
+
const current = await this.current();
|
|
158
|
+
if (current) {
|
|
159
|
+
await ((_a = this.savedAccounts) === null || _a === void 0 ? void 0 : _a.markExpired(current.profile.reference));
|
|
160
|
+
}
|
|
161
|
+
this.loaded = Promise.resolve(null);
|
|
162
|
+
await this.store.clear();
|
|
163
|
+
this.notifyChange(null);
|
|
164
|
+
this.settings.onUnauthenticated({ type: "refresh-rejected", status });
|
|
165
|
+
return false;
|
|
166
|
+
}
|
|
167
|
+
throw error;
|
|
168
|
+
}
|
|
169
|
+
refreshForm(refreshToken) {
|
|
170
|
+
const client = this.settings.clientId ? { client_id: this.settings.clientId } : {};
|
|
171
|
+
return { grant_type: "refresh_token", refresh_token: refreshToken, ...client };
|
|
172
|
+
}
|
|
173
|
+
async save(session) {
|
|
174
|
+
var _a;
|
|
175
|
+
await this.store.save(session);
|
|
176
|
+
await ((_a = this.savedAccounts) === null || _a === void 0 ? void 0 : _a.save(session));
|
|
177
|
+
this.loaded = Promise.resolve(session);
|
|
178
|
+
}
|
|
179
|
+
notifyChange(session) {
|
|
180
|
+
this.changeListeners.forEach((listener) => listener(session));
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
exports.UserSession = UserSession;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { OvokStorage } from "../storage/ovok-storage";
|
|
2
|
+
export type OvokFetch = (url: string, init: RequestInit) => Promise<Response>;
|
|
3
|
+
export type OvokUnauthenticatedReason = {
|
|
4
|
+
type: "refresh-rejected";
|
|
5
|
+
status: number;
|
|
6
|
+
};
|
|
7
|
+
type OvokBaseConfig = {
|
|
8
|
+
baseUrl: string;
|
|
9
|
+
tenantCode: string;
|
|
10
|
+
fhirPath?: string;
|
|
11
|
+
storage?: OvokStorage;
|
|
12
|
+
fetch?: OvokFetch;
|
|
13
|
+
timeoutMs?: number;
|
|
14
|
+
maxNetworkRetries?: number;
|
|
15
|
+
onUnauthenticated?: (reason: OvokUnauthenticatedReason) => void;
|
|
16
|
+
};
|
|
17
|
+
type OvokUserClientConfig = {
|
|
18
|
+
clientId?: string;
|
|
19
|
+
clientSecret?: undefined;
|
|
20
|
+
};
|
|
21
|
+
type OvokMachineClientConfig = {
|
|
22
|
+
clientId: string;
|
|
23
|
+
clientSecret: string;
|
|
24
|
+
};
|
|
25
|
+
export type OvokConfig = OvokBaseConfig & (OvokUserClientConfig | OvokMachineClientConfig);
|
|
26
|
+
export type MachineClient = {
|
|
27
|
+
clientId: string;
|
|
28
|
+
clientSecret: string;
|
|
29
|
+
};
|
|
30
|
+
export type OvokSettings = {
|
|
31
|
+
baseUrl: string;
|
|
32
|
+
tenantCode: string;
|
|
33
|
+
fhirPath: string;
|
|
34
|
+
storage: OvokStorage;
|
|
35
|
+
fetch: OvokFetch;
|
|
36
|
+
timeoutMs: number;
|
|
37
|
+
maxNetworkRetries: number;
|
|
38
|
+
clientId: string | null;
|
|
39
|
+
machineClient: MachineClient | null;
|
|
40
|
+
onUnauthenticated: (reason: OvokUnauthenticatedReason) => void;
|
|
41
|
+
};
|
|
42
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { OvokConfig, OvokSettings } from "./ovok-config";
|
|
2
|
+
export type RuntimeEnvironment = {
|
|
3
|
+
hasDocument: boolean;
|
|
4
|
+
};
|
|
5
|
+
export declare const currentEnvironment: () => RuntimeEnvironment;
|
|
6
|
+
export declare function readSettings(config: OvokConfig, environment: RuntimeEnvironment): OvokSettings;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.currentEnvironment = void 0;
|
|
4
|
+
exports.readSettings = readSettings;
|
|
5
|
+
const ovok_errors_1 = require("../errors/ovok-errors");
|
|
6
|
+
const ovok_storage_1 = require("../storage/ovok-storage");
|
|
7
|
+
const DEFAULT_FHIR_PATH = "fhir";
|
|
8
|
+
const DEFAULT_TIMEOUT_MS = 30000;
|
|
9
|
+
const DEFAULT_MAX_NETWORK_RETRIES = 2;
|
|
10
|
+
const ABSOLUTE_HTTP_URL = /^https?:\/\/[^/\s]+/i;
|
|
11
|
+
const currentEnvironment = () => ({ hasDocument: typeof document !== "undefined" });
|
|
12
|
+
exports.currentEnvironment = currentEnvironment;
|
|
13
|
+
function readSettings(config, environment) {
|
|
14
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
15
|
+
const machineClient = readMachineClient(config, environment);
|
|
16
|
+
return {
|
|
17
|
+
baseUrl: readBaseUrl(config.baseUrl),
|
|
18
|
+
tenantCode: requireText(config.tenantCode, "tenantCode"),
|
|
19
|
+
fhirPath: trimSlashes((_a = config.fhirPath) !== null && _a !== void 0 ? _a : DEFAULT_FHIR_PATH),
|
|
20
|
+
storage: (_b = config.storage) !== null && _b !== void 0 ? _b : new ovok_storage_1.MemoryStorage(),
|
|
21
|
+
fetch: (_c = config.fetch) !== null && _c !== void 0 ? _c : globalFetch(),
|
|
22
|
+
timeoutMs: requirePositive((_d = config.timeoutMs) !== null && _d !== void 0 ? _d : DEFAULT_TIMEOUT_MS, "timeoutMs"),
|
|
23
|
+
maxNetworkRetries: requireCount((_e = config.maxNetworkRetries) !== null && _e !== void 0 ? _e : DEFAULT_MAX_NETWORK_RETRIES, "maxNetworkRetries"),
|
|
24
|
+
clientId: (_f = config.clientId) !== null && _f !== void 0 ? _f : null,
|
|
25
|
+
machineClient,
|
|
26
|
+
onUnauthenticated: (_g = config.onUnauthenticated) !== null && _g !== void 0 ? _g : (() => undefined),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
const configError = (message) => new ovok_errors_1.OvokConfigError((0, ovok_errors_1.detailsFor)(message));
|
|
30
|
+
const readBaseUrl = (baseUrl) => {
|
|
31
|
+
if (!ABSOLUTE_HTTP_URL.test(baseUrl)) {
|
|
32
|
+
throw configError("baseUrl must be an absolute http(s) URL.");
|
|
33
|
+
}
|
|
34
|
+
return baseUrl.endsWith("/") ? baseUrl : `${baseUrl}/`;
|
|
35
|
+
};
|
|
36
|
+
const readMachineClient = (config, environment) => {
|
|
37
|
+
if (config.clientSecret === undefined) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
if (environment.hasDocument) {
|
|
41
|
+
throw configError("clientSecret is for servers only: a secret shipped to a browser is public.");
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
clientId: requireText(config.clientId, "clientId"),
|
|
45
|
+
clientSecret: requireText(config.clientSecret, "clientSecret"),
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
const requireText = (value, name) => {
|
|
49
|
+
var _a;
|
|
50
|
+
const text = (_a = value === null || value === void 0 ? void 0 : value.trim()) !== null && _a !== void 0 ? _a : "";
|
|
51
|
+
if (text === "") {
|
|
52
|
+
throw configError(`${name} is required.`);
|
|
53
|
+
}
|
|
54
|
+
return text;
|
|
55
|
+
};
|
|
56
|
+
const requirePositive = (value, name) => {
|
|
57
|
+
if (!Number.isFinite(value) || value <= 0) {
|
|
58
|
+
throw configError(`${name} must be a positive number.`);
|
|
59
|
+
}
|
|
60
|
+
return value;
|
|
61
|
+
};
|
|
62
|
+
const requireCount = (value, name) => {
|
|
63
|
+
if (!Number.isInteger(value) || value < 0) {
|
|
64
|
+
throw configError(`${name} must be a whole number of at least 0.`);
|
|
65
|
+
}
|
|
66
|
+
return value;
|
|
67
|
+
};
|
|
68
|
+
const trimSlashes = (path) => path.replace(/^\/+|\/+$/g, "");
|
|
69
|
+
const globalFetch = () => {
|
|
70
|
+
if (typeof globalThis.fetch !== "function") {
|
|
71
|
+
throw configError("No global fetch is available: pass config.fetch.");
|
|
72
|
+
}
|
|
73
|
+
return (url, init) => globalThis.fetch(url, init);
|
|
74
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.errorFromResponse = errorFromResponse;
|
|
4
|
+
const ovok_error_1 = require("../../client/errors/ovok-error");
|
|
5
|
+
const retry_after_1 = require("../http/retry-after");
|
|
6
|
+
const ovok_errors_1 = require("./ovok-errors");
|
|
7
|
+
async function errorFromResponse(response) {
|
|
8
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
9
|
+
const fallback = Object.assign(new Error(`Ovok API answered ${response.status}`), {
|
|
10
|
+
status: response.status,
|
|
11
|
+
body: parseBody(await response.text()),
|
|
12
|
+
});
|
|
13
|
+
const details = (0, ovok_error_1.readOvokError)(fallback);
|
|
14
|
+
return (0, ovok_errors_1.errorForStatus)({
|
|
15
|
+
status: response.status,
|
|
16
|
+
code: (_a = details.code) !== null && _a !== void 0 ? _a : null,
|
|
17
|
+
type: (_b = details.type) !== null && _b !== void 0 ? _b : null,
|
|
18
|
+
message: details.message,
|
|
19
|
+
traceId: (_d = (_c = response.headers.get("x-trace-id")) !== null && _c !== void 0 ? _c : details.traceId) !== null && _d !== void 0 ? _d : null,
|
|
20
|
+
requestId: (_f = (_e = response.headers.get("x-request-id")) !== null && _e !== void 0 ? _e : details.requestId) !== null && _f !== void 0 ? _f : null,
|
|
21
|
+
retryAfterMs: (_h = (_g = (0, retry_after_1.retryAfterMs)(response.headers.get("retry-after"))) !== null && _g !== void 0 ? _g : details.retryAfterMs) !== null && _h !== void 0 ? _h : null,
|
|
22
|
+
fieldErrors: details.fieldErrors,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
const parseBody = (text) => {
|
|
26
|
+
if (text === "") {
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
try {
|
|
30
|
+
return JSON.parse(text);
|
|
31
|
+
}
|
|
32
|
+
catch (_a) {
|
|
33
|
+
return { message: text };
|
|
34
|
+
}
|
|
35
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OvokAccountError = void 0;
|
|
4
|
+
class OvokAccountError extends Error {
|
|
5
|
+
constructor(code) {
|
|
6
|
+
super(code === "account_not_found"
|
|
7
|
+
? "Saved account was not found."
|
|
8
|
+
: "This account's session has expired. Sign in again.");
|
|
9
|
+
this.code = code;
|
|
10
|
+
this.name = "OvokAccountError";
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.OvokAccountError = OvokAccountError;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { ValidationError } from "../../types/ValidationError";
|
|
2
|
+
export type OvokErrorDetails = {
|
|
3
|
+
status: number | null;
|
|
4
|
+
code: string | null;
|
|
5
|
+
type: string | null;
|
|
6
|
+
message: string;
|
|
7
|
+
traceId: string | null;
|
|
8
|
+
requestId: string | null;
|
|
9
|
+
retryAfterMs: number | null;
|
|
10
|
+
fieldErrors: ValidationError[];
|
|
11
|
+
};
|
|
12
|
+
export declare class OvokError extends Error {
|
|
13
|
+
readonly status: number | null;
|
|
14
|
+
readonly code: string | null;
|
|
15
|
+
readonly type: string | null;
|
|
16
|
+
readonly traceId: string | null;
|
|
17
|
+
readonly requestId: string | null;
|
|
18
|
+
readonly retryAfterMs: number | null;
|
|
19
|
+
readonly fieldErrors: ValidationError[];
|
|
20
|
+
readonly cause: unknown;
|
|
21
|
+
constructor(details: OvokErrorDetails, cause?: unknown);
|
|
22
|
+
}
|
|
23
|
+
export declare class OvokValidationError extends OvokError {
|
|
24
|
+
}
|
|
25
|
+
export declare class OvokAuthenticationError extends OvokError {
|
|
26
|
+
}
|
|
27
|
+
export declare class OvokPermissionError extends OvokError {
|
|
28
|
+
}
|
|
29
|
+
export declare class OvokNotFoundError extends OvokError {
|
|
30
|
+
}
|
|
31
|
+
export declare class OvokConflictError extends OvokError {
|
|
32
|
+
}
|
|
33
|
+
export declare class OvokRateLimitError extends OvokError {
|
|
34
|
+
}
|
|
35
|
+
export declare class OvokServiceError extends OvokError {
|
|
36
|
+
}
|
|
37
|
+
export declare class OvokConnectionError extends OvokError {
|
|
38
|
+
}
|
|
39
|
+
export declare class OvokConfigError extends OvokError {
|
|
40
|
+
}
|
|
41
|
+
export declare function errorForStatus(details: OvokErrorDetails): OvokError;
|
|
42
|
+
export declare const detailsFor: (message: string) => OvokErrorDetails;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.detailsFor = exports.OvokConfigError = exports.OvokConnectionError = exports.OvokServiceError = exports.OvokRateLimitError = exports.OvokConflictError = exports.OvokNotFoundError = exports.OvokPermissionError = exports.OvokAuthenticationError = exports.OvokValidationError = exports.OvokError = void 0;
|
|
4
|
+
exports.errorForStatus = errorForStatus;
|
|
5
|
+
class OvokError extends Error {
|
|
6
|
+
constructor(details, cause) {
|
|
7
|
+
super(details.message);
|
|
8
|
+
this.name = new.target.name;
|
|
9
|
+
this.status = details.status;
|
|
10
|
+
this.code = details.code;
|
|
11
|
+
this.type = details.type;
|
|
12
|
+
this.traceId = details.traceId;
|
|
13
|
+
this.requestId = details.requestId;
|
|
14
|
+
this.retryAfterMs = details.retryAfterMs;
|
|
15
|
+
this.fieldErrors = details.fieldErrors;
|
|
16
|
+
Object.defineProperty(this, "cause", { value: cause, enumerable: false });
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.OvokError = OvokError;
|
|
20
|
+
class OvokValidationError extends OvokError {
|
|
21
|
+
}
|
|
22
|
+
exports.OvokValidationError = OvokValidationError;
|
|
23
|
+
class OvokAuthenticationError extends OvokError {
|
|
24
|
+
}
|
|
25
|
+
exports.OvokAuthenticationError = OvokAuthenticationError;
|
|
26
|
+
class OvokPermissionError extends OvokError {
|
|
27
|
+
}
|
|
28
|
+
exports.OvokPermissionError = OvokPermissionError;
|
|
29
|
+
class OvokNotFoundError extends OvokError {
|
|
30
|
+
}
|
|
31
|
+
exports.OvokNotFoundError = OvokNotFoundError;
|
|
32
|
+
class OvokConflictError extends OvokError {
|
|
33
|
+
}
|
|
34
|
+
exports.OvokConflictError = OvokConflictError;
|
|
35
|
+
class OvokRateLimitError extends OvokError {
|
|
36
|
+
}
|
|
37
|
+
exports.OvokRateLimitError = OvokRateLimitError;
|
|
38
|
+
class OvokServiceError extends OvokError {
|
|
39
|
+
}
|
|
40
|
+
exports.OvokServiceError = OvokServiceError;
|
|
41
|
+
class OvokConnectionError extends OvokError {
|
|
42
|
+
}
|
|
43
|
+
exports.OvokConnectionError = OvokConnectionError;
|
|
44
|
+
class OvokConfigError extends OvokError {
|
|
45
|
+
}
|
|
46
|
+
exports.OvokConfigError = OvokConfigError;
|
|
47
|
+
const ERROR_CLASS_BY_STATUS = {
|
|
48
|
+
400: OvokValidationError,
|
|
49
|
+
401: OvokAuthenticationError,
|
|
50
|
+
403: OvokPermissionError,
|
|
51
|
+
404: OvokNotFoundError,
|
|
52
|
+
409: OvokConflictError,
|
|
53
|
+
422: OvokValidationError,
|
|
54
|
+
429: OvokRateLimitError,
|
|
55
|
+
};
|
|
56
|
+
const FIRST_SERVER_ERROR_STATUS = 500;
|
|
57
|
+
function errorForStatus(details) {
|
|
58
|
+
var _a, _b;
|
|
59
|
+
const status = (_a = details.status) !== null && _a !== void 0 ? _a : 0;
|
|
60
|
+
const isServerError = status >= FIRST_SERVER_ERROR_STATUS;
|
|
61
|
+
const errorClass = isServerError ? OvokServiceError : (_b = ERROR_CLASS_BY_STATUS[status]) !== null && _b !== void 0 ? _b : OvokError;
|
|
62
|
+
return new errorClass(details);
|
|
63
|
+
}
|
|
64
|
+
const detailsFor = (message) => ({
|
|
65
|
+
status: null,
|
|
66
|
+
code: null,
|
|
67
|
+
type: null,
|
|
68
|
+
message,
|
|
69
|
+
traceId: null,
|
|
70
|
+
requestId: null,
|
|
71
|
+
retryAfterMs: null,
|
|
72
|
+
fieldErrors: [],
|
|
73
|
+
});
|
|
74
|
+
exports.detailsFor = detailsFor;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Credentials } from "../auth/credentials";
|
|
2
|
+
import { OvokSettings } from "../config/ovok-config";
|
|
3
|
+
import { RetryPolicy } from "./retry-policy";
|
|
4
|
+
import { RequestOptions } from "./transmit";
|
|
5
|
+
export type HttpMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
6
|
+
export type HttpRequest = {
|
|
7
|
+
method: HttpMethod;
|
|
8
|
+
path: string;
|
|
9
|
+
body?: unknown;
|
|
10
|
+
headers?: Record<string, string>;
|
|
11
|
+
idempotent?: boolean;
|
|
12
|
+
};
|
|
13
|
+
export type HttpContext = {
|
|
14
|
+
settings: OvokSettings;
|
|
15
|
+
credentials: Credentials;
|
|
16
|
+
retryPolicy: RetryPolicy;
|
|
17
|
+
};
|
|
18
|
+
export declare class HttpClient {
|
|
19
|
+
private readonly context;
|
|
20
|
+
private readonly basePath;
|
|
21
|
+
constructor(context: HttpContext, basePath?: string);
|
|
22
|
+
under(path: string): HttpClient;
|
|
23
|
+
anonymous(): HttpClient;
|
|
24
|
+
withCredentials(credentials: Credentials): HttpClient;
|
|
25
|
+
get<T>(path: string, options?: RequestOptions): Promise<T>;
|
|
26
|
+
post<T>(path: string, body?: unknown, options?: RequestOptions): Promise<T>;
|
|
27
|
+
put<T>(path: string, body: unknown, options?: RequestOptions): Promise<T>;
|
|
28
|
+
patch<T>(path: string, body: unknown, options?: RequestOptions): Promise<T>;
|
|
29
|
+
delete<T = void>(path: string, options?: RequestOptions): Promise<T>;
|
|
30
|
+
send<T>(request: HttpRequest, options?: RequestOptions): Promise<T>;
|
|
31
|
+
private sendAuthorized;
|
|
32
|
+
private sendWithRetries;
|
|
33
|
+
private attempt;
|
|
34
|
+
private isRetryable;
|
|
35
|
+
private toTransmit;
|
|
36
|
+
}
|