@esushealth/sdk 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +146 -2
- package/dist/app-session.d.ts +225 -0
- package/dist/app-session.js +286 -0
- package/dist/clinical-workflows.d.ts +279 -0
- package/dist/clinical-workflows.js +43 -0
- package/dist/diagnostics.d.ts +24 -0
- package/dist/diagnostics.js +57 -0
- package/dist/fhir-contract.d.ts +12540 -0
- package/dist/fhir-contract.js +95 -0
- package/dist/fhir.d.ts +94 -0
- package/dist/fhir.js +169 -0
- package/dist/files.d.ts +13 -0
- package/dist/files.js +40 -0
- package/dist/integration-contract.d.ts +2327 -0
- package/dist/integration-contract.js +124 -0
- package/dist/integration-request.d.ts +11 -0
- package/dist/integration-request.js +19 -0
- package/dist/organization.d.ts +324 -0
- package/dist/organization.js +43 -0
- package/dist/patient-contract.d.ts +2 -0
- package/dist/patient-contract.js +1 -0
- package/dist/public.d.ts +125 -0
- package/dist/public.js +34 -0
- package/dist/server.d.ts +1310 -0
- package/dist/server.js +85 -0
- package/dist/smart.d.ts +42 -0
- package/dist/smart.js +98 -0
- package/dist/tenant-apps.d.ts +355 -0
- package/dist/tenant-apps.js +50 -0
- package/dist/transport.d.ts +38 -0
- package/dist/transport.js +108 -0
- package/dist/webhook-management.d.ts +53 -0
- package/dist/webhook-management.js +83 -0
- package/dist/webhooks.d.ts +24 -0
- package/dist/webhooks.js +41 -0
- package/package.json +17 -4
package/dist/server.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
export { diagnoseCapabilities, integrationCapabilities } from "./diagnostics.js";
|
|
2
|
+
import { smartFhirOperations } from "./fhir-contract.js";
|
|
3
|
+
import { fhirOperation, isFhirResource, readFhir, supportsFhirLifecycle, writeFhir } from "./fhir.js";
|
|
4
|
+
import { webhookManagement } from "./webhook-management.js";
|
|
5
|
+
import { filesClient } from "./files.js";
|
|
6
|
+
import { clinicalWorkflows } from "./clinical-workflows.js";
|
|
7
|
+
import { tenantAppsClient } from "./tenant-apps.js";
|
|
8
|
+
import { organizationClient } from "./organization.js";
|
|
9
|
+
import { createTransport, EsusError, record, } from "./transport.js";
|
|
10
|
+
export { createAppSessionClient } from "./app-session.js";
|
|
11
|
+
export { EsusError } from "./transport.js";
|
|
12
|
+
export { createSmartAuthorization, exchangeSmartCode } from "./smart.js";
|
|
13
|
+
export { verifyWebhook } from "./webhooks.js";
|
|
14
|
+
export { createPublicClient } from "./public.js";
|
|
15
|
+
export { patientPortalResources, tenantWebhookEvents } from "./integration-contract.js";
|
|
16
|
+
export { supportsFhirLifecycle } from "./fhir.js";
|
|
17
|
+
export { fhirResources } from "./fhir-contract.js";
|
|
18
|
+
export { fhirOperations, smartFhirOperations } from "./fhir-contract.js";
|
|
19
|
+
const resourceActions = ["read", "create", "update", "delete"];
|
|
20
|
+
function invalidResponse(response, message) {
|
|
21
|
+
throw new EsusError(message, response.status, response.headers.get("x-request-id"));
|
|
22
|
+
}
|
|
23
|
+
function validActions(actions) {
|
|
24
|
+
return Array.isArray(actions) && actions.every((action) => resourceActions.includes(action));
|
|
25
|
+
}
|
|
26
|
+
async function verifyConnection(request, expectedOrganization, smartClientId, options) {
|
|
27
|
+
const resources = [...new Set(options.resources)];
|
|
28
|
+
if (!resources.every(isFhirResource))
|
|
29
|
+
throw new TypeError("Only resources in the Esus FHIR catalog can be verified");
|
|
30
|
+
const query = resources.length > 0 ? "?" + new URLSearchParams({ resources: resources.join(",") }) : "";
|
|
31
|
+
const { body, response } = await request("/v1/integration/connection" + query, { signal: options.signal });
|
|
32
|
+
const proof = record(body);
|
|
33
|
+
if (proof?.organizationId !== expectedOrganization || proof.smartClientId !== smartClientId ||
|
|
34
|
+
!validActions(proof.patientActions)) {
|
|
35
|
+
return invalidResponse(response, "Esus did not confirm the expected organization and credential");
|
|
36
|
+
}
|
|
37
|
+
const connection = { organizationId: expectedOrganization, smartClientId, patientActions: proof.patientActions };
|
|
38
|
+
if (resources.length === 0)
|
|
39
|
+
return connection;
|
|
40
|
+
const actions = record(proof.resourceActions);
|
|
41
|
+
const confirmed = {};
|
|
42
|
+
for (const resource of resources) {
|
|
43
|
+
const grant = actions?.[resource];
|
|
44
|
+
if (!validActions(grant))
|
|
45
|
+
return invalidResponse(response, `Esus did not confirm permissions for ${resource}`);
|
|
46
|
+
confirmed[resource] = grant.filter((action) => (action !== "create" && action !== "delete") || supportsFhirLifecycle(resource, action));
|
|
47
|
+
}
|
|
48
|
+
return { ...connection, resourceActions: confirmed };
|
|
49
|
+
}
|
|
50
|
+
function organizationConnection(request, organizationId, smartClientId) {
|
|
51
|
+
let confirmed = false;
|
|
52
|
+
async function validateConnection(options = {}) {
|
|
53
|
+
confirmed = false;
|
|
54
|
+
const proof = await verifyConnection(request, organizationId, smartClientId, options);
|
|
55
|
+
confirmed = true;
|
|
56
|
+
return proof;
|
|
57
|
+
}
|
|
58
|
+
const clinical = async (path, init) => {
|
|
59
|
+
if (!confirmed)
|
|
60
|
+
await validateConnection({ signal: init?.signal ?? undefined });
|
|
61
|
+
return request(path, init);
|
|
62
|
+
};
|
|
63
|
+
return { validateConnection, clinical };
|
|
64
|
+
}
|
|
65
|
+
export function createServiceClient(options) {
|
|
66
|
+
const credential = new Headers({ "x-api-key": options.apiKey });
|
|
67
|
+
if (options.appId)
|
|
68
|
+
credential.set("x-app-id", options.appId);
|
|
69
|
+
const { clinical: request, validateConnection } = organizationConnection(createTransport(options, credential), options.organizationId, null);
|
|
70
|
+
return {
|
|
71
|
+
validateConnection,
|
|
72
|
+
fhir: { ...readFhir(request), ...writeFhir(request), operation: fhirOperation(request) },
|
|
73
|
+
webhooks: (appId) => webhookManagement(request, appId, options.appId),
|
|
74
|
+
files: filesClient(request),
|
|
75
|
+
tenantApps: tenantAppsClient(request),
|
|
76
|
+
organization: organizationClient(request, options.organizationId),
|
|
77
|
+
...clinicalWorkflows(request),
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
export function createSmartClient(options) {
|
|
81
|
+
const request = createTransport(options, { authorization: `Bearer ${options.accessToken}` });
|
|
82
|
+
const { validateConnection, clinical } = organizationConnection(request, options.organizationId, options.clientId);
|
|
83
|
+
const reader = { ...readFhir(clinical), operation: fhirOperation(clinical, smartFhirOperations) };
|
|
84
|
+
return { validateConnection, fhir: options.enableWrites ? { ...reader, ...writeFhir(clinical) } : reader };
|
|
85
|
+
}
|
package/dist/smart.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { type TransportOptions } from "./transport.js";
|
|
2
|
+
type AuthorizationOptions = TransportOptions & Readonly<{
|
|
3
|
+
clientId: string;
|
|
4
|
+
redirectUri: string;
|
|
5
|
+
scopes: readonly string[];
|
|
6
|
+
launch?: string;
|
|
7
|
+
}>;
|
|
8
|
+
export type SmartTransaction = Readonly<{
|
|
9
|
+
issuer: string;
|
|
10
|
+
organizationId: string;
|
|
11
|
+
clientId: string;
|
|
12
|
+
redirectUri: string;
|
|
13
|
+
state: string;
|
|
14
|
+
verifier: string;
|
|
15
|
+
tokenEndpoint: string;
|
|
16
|
+
expiresAt: number;
|
|
17
|
+
}>;
|
|
18
|
+
export declare function createSmartAuthorization(options: AuthorizationOptions): Promise<{
|
|
19
|
+
url: string;
|
|
20
|
+
transaction: Readonly<{
|
|
21
|
+
issuer: string;
|
|
22
|
+
organizationId: string;
|
|
23
|
+
clientId: string;
|
|
24
|
+
redirectUri: string;
|
|
25
|
+
state: string;
|
|
26
|
+
verifier: string;
|
|
27
|
+
tokenEndpoint: string;
|
|
28
|
+
expiresAt: number;
|
|
29
|
+
}>;
|
|
30
|
+
}>;
|
|
31
|
+
type ExchangeOptions = TransportOptions & Readonly<{
|
|
32
|
+
clientId: string;
|
|
33
|
+
redirectUri: string;
|
|
34
|
+
clientSecret?: string;
|
|
35
|
+
}>;
|
|
36
|
+
export declare function exchangeSmartCode(options: ExchangeOptions, transaction: SmartTransaction, callbackUrl: string): Promise<{
|
|
37
|
+
accessToken: string;
|
|
38
|
+
expiresAt: number;
|
|
39
|
+
scopes: string[];
|
|
40
|
+
patientId: string | undefined;
|
|
41
|
+
}>;
|
|
42
|
+
export {};
|
package/dist/smart.js
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { createTransport, EsusError, integrationOrigin, record } from "./transport.js";
|
|
2
|
+
function base64Url(bytes) {
|
|
3
|
+
return btoa(String.fromCharCode(...bytes)).replaceAll("+", "-").replaceAll("/", "_").replace(/=+$/, "");
|
|
4
|
+
}
|
|
5
|
+
function endpoint(value, issuer) {
|
|
6
|
+
if (typeof value !== "string")
|
|
7
|
+
throw new EsusError("Esus SMART discovery returned a missing endpoint", 0);
|
|
8
|
+
const url = new URL(value);
|
|
9
|
+
if (url.origin !== issuer || url.username || url.password || url.hash) {
|
|
10
|
+
throw new EsusError("Esus SMART endpoint is outside the configured issuer", 0);
|
|
11
|
+
}
|
|
12
|
+
return url;
|
|
13
|
+
}
|
|
14
|
+
export async function createSmartAuthorization(options) {
|
|
15
|
+
const issuer = integrationOrigin(options.url);
|
|
16
|
+
const callback = new URL(options.redirectUri);
|
|
17
|
+
integrationOrigin(callback.origin);
|
|
18
|
+
if (callback.username || callback.password || callback.search || callback.hash) {
|
|
19
|
+
throw new TypeError("SMART redirect URI must have no credentials, query or fragment");
|
|
20
|
+
}
|
|
21
|
+
const request = createTransport(options, {});
|
|
22
|
+
const { body } = await request("/.well-known/smart-configuration");
|
|
23
|
+
const discovery = record(body);
|
|
24
|
+
if (discovery?.issuer !== issuer ||
|
|
25
|
+
!Array.isArray(discovery.code_challenge_methods_supported) ||
|
|
26
|
+
!discovery.code_challenge_methods_supported.includes("S256")) {
|
|
27
|
+
throw new EsusError("Esus SMART discovery did not confirm the issuer and PKCE S256", 0);
|
|
28
|
+
}
|
|
29
|
+
const authorization = endpoint(discovery.authorization_endpoint, issuer);
|
|
30
|
+
const tokenEndpoint = endpoint(discovery.token_endpoint, issuer);
|
|
31
|
+
const state = base64Url(crypto.getRandomValues(new Uint8Array(32)));
|
|
32
|
+
const verifier = base64Url(crypto.getRandomValues(new Uint8Array(32)));
|
|
33
|
+
const challenge = base64Url(new Uint8Array(await crypto.subtle.digest("SHA-256", new TextEncoder().encode(verifier))));
|
|
34
|
+
for (const [name, value] of Object.entries({
|
|
35
|
+
response_type: "code",
|
|
36
|
+
client_id: options.clientId,
|
|
37
|
+
redirect_uri: callback.href,
|
|
38
|
+
scope: options.scopes.join(" "),
|
|
39
|
+
aud: issuer,
|
|
40
|
+
state,
|
|
41
|
+
code_challenge: challenge,
|
|
42
|
+
code_challenge_method: "S256",
|
|
43
|
+
}))
|
|
44
|
+
authorization.searchParams.set(name, value);
|
|
45
|
+
if (options.launch)
|
|
46
|
+
authorization.searchParams.set("launch", options.launch);
|
|
47
|
+
const transaction = {
|
|
48
|
+
issuer, organizationId: options.organizationId, clientId: options.clientId,
|
|
49
|
+
redirectUri: callback.href, state, verifier, tokenEndpoint: tokenEndpoint.href,
|
|
50
|
+
expiresAt: Date.now() + 10 * 60_000,
|
|
51
|
+
};
|
|
52
|
+
return { url: authorization.href, transaction };
|
|
53
|
+
}
|
|
54
|
+
// Consume the stored transaction once for this browser session before invoking this function.
|
|
55
|
+
export async function exchangeSmartCode(options, transaction, callbackUrl) {
|
|
56
|
+
const issuer = integrationOrigin(options.url);
|
|
57
|
+
const callback = new URL(callbackUrl);
|
|
58
|
+
const expected = new URL(options.redirectUri);
|
|
59
|
+
const states = callback.searchParams.getAll("state");
|
|
60
|
+
if (transaction.issuer !== issuer || transaction.organizationId !== options.organizationId ||
|
|
61
|
+
transaction.clientId !== options.clientId || transaction.redirectUri !== expected.href ||
|
|
62
|
+
Date.now() >= transaction.expiresAt || callback.origin !== expected.origin ||
|
|
63
|
+
callback.pathname !== expected.pathname || states.length !== 1 || states[0] !== transaction.state) {
|
|
64
|
+
throw new EsusError("Invalid or expired SMART callback", 400);
|
|
65
|
+
}
|
|
66
|
+
if (callback.searchParams.has("error")) {
|
|
67
|
+
throw new EsusError("SMART authorization was declined or failed", 400);
|
|
68
|
+
}
|
|
69
|
+
const codes = callback.searchParams.getAll("code");
|
|
70
|
+
const code = codes[0];
|
|
71
|
+
if (codes.length !== 1 || !code)
|
|
72
|
+
throw new EsusError("The SMART callback is missing its authorization code", 400);
|
|
73
|
+
const form = new URLSearchParams({
|
|
74
|
+
grant_type: "authorization_code", code, client_id: transaction.clientId,
|
|
75
|
+
redirect_uri: transaction.redirectUri, code_verifier: transaction.verifier,
|
|
76
|
+
});
|
|
77
|
+
if (options.clientSecret)
|
|
78
|
+
form.set("client_secret", options.clientSecret);
|
|
79
|
+
const request = createTransport(options, {});
|
|
80
|
+
const { body, response } = await request(endpoint(transaction.tokenEndpoint, issuer).href, {
|
|
81
|
+
method: "POST",
|
|
82
|
+
headers: { "content-type": "application/x-www-form-urlencoded" },
|
|
83
|
+
body: form.toString(),
|
|
84
|
+
});
|
|
85
|
+
const grant = record(body);
|
|
86
|
+
if (typeof grant?.access_token !== "string" || !grant.access_token ||
|
|
87
|
+
typeof grant.token_type !== "string" || grant.token_type.toLowerCase() !== "bearer" ||
|
|
88
|
+
typeof grant.expires_in !== "number" || !Number.isFinite(grant.expires_in) || grant.expires_in <= 0 ||
|
|
89
|
+
typeof grant.scope !== "string" || (grant.patient !== undefined && typeof grant.patient !== "string")) {
|
|
90
|
+
throw new EsusError("Esus returned an invalid SMART token response", response.status, response.headers.get("x-request-id"));
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
accessToken: grant.access_token,
|
|
94
|
+
expiresAt: Date.now() + grant.expires_in * 1000,
|
|
95
|
+
scopes: grant.scope.split(/\s+/).filter(Boolean),
|
|
96
|
+
patientId: grant.patient,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
import { tenantAppStatuses, type IntegrationInputs, type IntegrationQueries, type IntegrationResults } from "./integration-contract.js";
|
|
2
|
+
import type { RequestOptions, Transport } from "./transport.js";
|
|
3
|
+
type Route = keyof typeof tenantAppStatuses;
|
|
4
|
+
type Input<R extends keyof IntegrationInputs> = IntegrationInputs[R];
|
|
5
|
+
type Result<R extends Route> = IntegrationResults[R]["body"];
|
|
6
|
+
export type TenantApp = Result<"GET /tenant-apps/:id">;
|
|
7
|
+
export type TenantAppUser = Result<"GET /tenant-apps/:id/users/:userId">;
|
|
8
|
+
export type TenantAppRole = Result<"POST /tenant-apps/:id/roles">;
|
|
9
|
+
export declare function tenantAppsClient(request: Transport): {
|
|
10
|
+
list: (options?: RequestOptions) => Promise<{
|
|
11
|
+
readonly apps: ReadonlyArray<{
|
|
12
|
+
readonly "id": string;
|
|
13
|
+
readonly "organizationId": string;
|
|
14
|
+
readonly "publicId": string;
|
|
15
|
+
readonly "name": string;
|
|
16
|
+
readonly "active": boolean;
|
|
17
|
+
readonly "settings": {
|
|
18
|
+
readonly "appId": string;
|
|
19
|
+
readonly "appDisplayName": string;
|
|
20
|
+
readonly "logoUri"?: string | null;
|
|
21
|
+
readonly "primaryColor"?: string | null;
|
|
22
|
+
readonly "supportEmail"?: string | null;
|
|
23
|
+
readonly "footerText"?: string | null;
|
|
24
|
+
readonly "fromEmail"?: string | null;
|
|
25
|
+
readonly "fromName"?: string | null;
|
|
26
|
+
readonly "replyTo"?: string | null;
|
|
27
|
+
readonly "siteUrl": string;
|
|
28
|
+
readonly "redirectAllowList": ReadonlyArray<string>;
|
|
29
|
+
readonly "emailActionPaths"?: {
|
|
30
|
+
readonly [key: string]: unknown;
|
|
31
|
+
} | null;
|
|
32
|
+
readonly "googleEnabled": boolean;
|
|
33
|
+
readonly "googleClientId"?: string | null;
|
|
34
|
+
readonly "googleConfigured": boolean;
|
|
35
|
+
readonly "googleRedirectUri"?: string | null;
|
|
36
|
+
readonly "webauthnEnabled": boolean;
|
|
37
|
+
readonly "emailCopy"?: {
|
|
38
|
+
readonly [key: string]: unknown;
|
|
39
|
+
} | null;
|
|
40
|
+
readonly "smtpHost"?: string | null;
|
|
41
|
+
readonly "smtpPort"?: string | number | null;
|
|
42
|
+
readonly "smtpSecure": boolean;
|
|
43
|
+
readonly "smtpUser"?: string | null;
|
|
44
|
+
readonly "smtpConfigured": boolean;
|
|
45
|
+
readonly "turnstileSiteKey"?: string | null;
|
|
46
|
+
readonly "turnstileConfigured": boolean;
|
|
47
|
+
};
|
|
48
|
+
readonly "createdAt": string;
|
|
49
|
+
readonly "updatedAt": string;
|
|
50
|
+
}>;
|
|
51
|
+
}>;
|
|
52
|
+
create: (body: Input<"POST /tenant-apps">, options?: RequestOptions) => Promise<{
|
|
53
|
+
readonly id: string;
|
|
54
|
+
readonly organizationId: string;
|
|
55
|
+
readonly publicId: string;
|
|
56
|
+
readonly name: string;
|
|
57
|
+
readonly active: boolean;
|
|
58
|
+
readonly settings: {
|
|
59
|
+
readonly "appId": string;
|
|
60
|
+
readonly "appDisplayName": string;
|
|
61
|
+
readonly "logoUri"?: string | null;
|
|
62
|
+
readonly "primaryColor"?: string | null;
|
|
63
|
+
readonly "supportEmail"?: string | null;
|
|
64
|
+
readonly "footerText"?: string | null;
|
|
65
|
+
readonly "fromEmail"?: string | null;
|
|
66
|
+
readonly "fromName"?: string | null;
|
|
67
|
+
readonly "replyTo"?: string | null;
|
|
68
|
+
readonly "siteUrl": string;
|
|
69
|
+
readonly "redirectAllowList": ReadonlyArray<string>;
|
|
70
|
+
readonly "emailActionPaths"?: {
|
|
71
|
+
readonly [key: string]: unknown;
|
|
72
|
+
} | null;
|
|
73
|
+
readonly "googleEnabled": boolean;
|
|
74
|
+
readonly "googleClientId"?: string | null;
|
|
75
|
+
readonly "googleConfigured": boolean;
|
|
76
|
+
readonly "googleRedirectUri"?: string | null;
|
|
77
|
+
readonly "webauthnEnabled": boolean;
|
|
78
|
+
readonly "emailCopy"?: {
|
|
79
|
+
readonly [key: string]: unknown;
|
|
80
|
+
} | null;
|
|
81
|
+
readonly "smtpHost"?: string | null;
|
|
82
|
+
readonly "smtpPort"?: string | number | null;
|
|
83
|
+
readonly "smtpSecure": boolean;
|
|
84
|
+
readonly "smtpUser"?: string | null;
|
|
85
|
+
readonly "smtpConfigured": boolean;
|
|
86
|
+
readonly "turnstileSiteKey"?: string | null;
|
|
87
|
+
readonly "turnstileConfigured": boolean;
|
|
88
|
+
};
|
|
89
|
+
readonly createdAt: string;
|
|
90
|
+
readonly updatedAt: string;
|
|
91
|
+
}>;
|
|
92
|
+
linkUser: (userId: string, body: Input<"PATCH /v1/auth/users/:userId">, options?: RequestOptions) => Promise<{
|
|
93
|
+
readonly id: string;
|
|
94
|
+
readonly email: string;
|
|
95
|
+
readonly patientId: string | null;
|
|
96
|
+
readonly practitionerId: string | null;
|
|
97
|
+
}>;
|
|
98
|
+
forApp: (id: string) => {
|
|
99
|
+
get: (options?: RequestOptions) => Promise<{
|
|
100
|
+
readonly id: string;
|
|
101
|
+
readonly organizationId: string;
|
|
102
|
+
readonly publicId: string;
|
|
103
|
+
readonly name: string;
|
|
104
|
+
readonly active: boolean;
|
|
105
|
+
readonly settings: {
|
|
106
|
+
readonly "appId": string;
|
|
107
|
+
readonly "appDisplayName": string;
|
|
108
|
+
readonly "logoUri"?: string | null;
|
|
109
|
+
readonly "primaryColor"?: string | null;
|
|
110
|
+
readonly "supportEmail"?: string | null;
|
|
111
|
+
readonly "footerText"?: string | null;
|
|
112
|
+
readonly "fromEmail"?: string | null;
|
|
113
|
+
readonly "fromName"?: string | null;
|
|
114
|
+
readonly "replyTo"?: string | null;
|
|
115
|
+
readonly "siteUrl": string;
|
|
116
|
+
readonly "redirectAllowList": ReadonlyArray<string>;
|
|
117
|
+
readonly "emailActionPaths"?: {
|
|
118
|
+
readonly [key: string]: unknown;
|
|
119
|
+
} | null;
|
|
120
|
+
readonly "googleEnabled": boolean;
|
|
121
|
+
readonly "googleClientId"?: string | null;
|
|
122
|
+
readonly "googleConfigured": boolean;
|
|
123
|
+
readonly "googleRedirectUri"?: string | null;
|
|
124
|
+
readonly "webauthnEnabled": boolean;
|
|
125
|
+
readonly "emailCopy"?: {
|
|
126
|
+
readonly [key: string]: unknown;
|
|
127
|
+
} | null;
|
|
128
|
+
readonly "smtpHost"?: string | null;
|
|
129
|
+
readonly "smtpPort"?: string | number | null;
|
|
130
|
+
readonly "smtpSecure": boolean;
|
|
131
|
+
readonly "smtpUser"?: string | null;
|
|
132
|
+
readonly "smtpConfigured": boolean;
|
|
133
|
+
readonly "turnstileSiteKey"?: string | null;
|
|
134
|
+
readonly "turnstileConfigured": boolean;
|
|
135
|
+
};
|
|
136
|
+
readonly createdAt: string;
|
|
137
|
+
readonly updatedAt: string;
|
|
138
|
+
}>;
|
|
139
|
+
update: (body: Input<"PATCH /tenant-apps/:id">, options?: RequestOptions) => Promise<{
|
|
140
|
+
readonly id: string;
|
|
141
|
+
readonly organizationId: string;
|
|
142
|
+
readonly publicId: string;
|
|
143
|
+
readonly name: string;
|
|
144
|
+
readonly active: boolean;
|
|
145
|
+
readonly settings: {
|
|
146
|
+
readonly "appId": string;
|
|
147
|
+
readonly "appDisplayName": string;
|
|
148
|
+
readonly "logoUri"?: string | null;
|
|
149
|
+
readonly "primaryColor"?: string | null;
|
|
150
|
+
readonly "supportEmail"?: string | null;
|
|
151
|
+
readonly "footerText"?: string | null;
|
|
152
|
+
readonly "fromEmail"?: string | null;
|
|
153
|
+
readonly "fromName"?: string | null;
|
|
154
|
+
readonly "replyTo"?: string | null;
|
|
155
|
+
readonly "siteUrl": string;
|
|
156
|
+
readonly "redirectAllowList": ReadonlyArray<string>;
|
|
157
|
+
readonly "emailActionPaths"?: {
|
|
158
|
+
readonly [key: string]: unknown;
|
|
159
|
+
} | null;
|
|
160
|
+
readonly "googleEnabled": boolean;
|
|
161
|
+
readonly "googleClientId"?: string | null;
|
|
162
|
+
readonly "googleConfigured": boolean;
|
|
163
|
+
readonly "googleRedirectUri"?: string | null;
|
|
164
|
+
readonly "webauthnEnabled": boolean;
|
|
165
|
+
readonly "emailCopy"?: {
|
|
166
|
+
readonly [key: string]: unknown;
|
|
167
|
+
} | null;
|
|
168
|
+
readonly "smtpHost"?: string | null;
|
|
169
|
+
readonly "smtpPort"?: string | number | null;
|
|
170
|
+
readonly "smtpSecure": boolean;
|
|
171
|
+
readonly "smtpUser"?: string | null;
|
|
172
|
+
readonly "smtpConfigured": boolean;
|
|
173
|
+
readonly "turnstileSiteKey"?: string | null;
|
|
174
|
+
readonly "turnstileConfigured": boolean;
|
|
175
|
+
};
|
|
176
|
+
readonly createdAt: string;
|
|
177
|
+
readonly updatedAt: string;
|
|
178
|
+
}>;
|
|
179
|
+
delete: (options?: RequestOptions) => Promise<undefined>;
|
|
180
|
+
stats: (options?: RequestOptions) => Promise<{
|
|
181
|
+
readonly userCount: number;
|
|
182
|
+
readonly activeSessionsLast24h: number;
|
|
183
|
+
readonly signupsLast7d: number;
|
|
184
|
+
readonly lastActivityAt: string | null;
|
|
185
|
+
}>;
|
|
186
|
+
sendTestEmail: (body: Input<"POST /tenant-apps/:id/email/test">, options?: RequestOptions) => Promise<{
|
|
187
|
+
readonly delivered: true;
|
|
188
|
+
}>;
|
|
189
|
+
backfillPatientConsents: (options?: RequestOptions) => Promise<{
|
|
190
|
+
readonly created: number;
|
|
191
|
+
readonly skipped: number;
|
|
192
|
+
readonly total: number;
|
|
193
|
+
}>;
|
|
194
|
+
users: {
|
|
195
|
+
list: (query?: IntegrationQueries["GET /tenant-apps/:id/users"], options?: RequestOptions) => Promise<{
|
|
196
|
+
readonly users: ReadonlyArray<{
|
|
197
|
+
readonly "id": string;
|
|
198
|
+
readonly "appId": string;
|
|
199
|
+
readonly "email": string;
|
|
200
|
+
readonly "firstName": string | null;
|
|
201
|
+
readonly "lastName": string | null;
|
|
202
|
+
readonly "isActive": boolean;
|
|
203
|
+
readonly "emailVerified": boolean;
|
|
204
|
+
readonly "mfaEnabled": boolean;
|
|
205
|
+
readonly "lastLoginAt": string | null;
|
|
206
|
+
readonly "patientId": string | null;
|
|
207
|
+
readonly "practitionerId": string | null;
|
|
208
|
+
readonly "createdAt": string;
|
|
209
|
+
readonly "lockedUntil": string | null;
|
|
210
|
+
readonly "failedLoginAttempts": string | number;
|
|
211
|
+
readonly "roles": ReadonlyArray<{
|
|
212
|
+
readonly "id": string;
|
|
213
|
+
readonly "name": string;
|
|
214
|
+
readonly "isStaff": boolean;
|
|
215
|
+
}>;
|
|
216
|
+
}>;
|
|
217
|
+
readonly nextCursor: string | null;
|
|
218
|
+
}>;
|
|
219
|
+
get: (userId: string, options?: RequestOptions) => Promise<{
|
|
220
|
+
readonly id: string;
|
|
221
|
+
readonly appId: string;
|
|
222
|
+
readonly email: string;
|
|
223
|
+
readonly firstName: string | null;
|
|
224
|
+
readonly lastName: string | null;
|
|
225
|
+
readonly isActive: boolean;
|
|
226
|
+
readonly emailVerified: boolean;
|
|
227
|
+
readonly mfaEnabled: boolean;
|
|
228
|
+
readonly lastLoginAt: string | null;
|
|
229
|
+
readonly patientId: string | null;
|
|
230
|
+
readonly practitionerId: string | null;
|
|
231
|
+
readonly createdAt: string;
|
|
232
|
+
readonly lockedUntil: string | null;
|
|
233
|
+
readonly failedLoginAttempts: string | number;
|
|
234
|
+
readonly roles: ReadonlyArray<{
|
|
235
|
+
readonly "id": string;
|
|
236
|
+
readonly "name": string;
|
|
237
|
+
readonly "isStaff": boolean;
|
|
238
|
+
}>;
|
|
239
|
+
}>;
|
|
240
|
+
update: (userId: string, body: Input<"PATCH /tenant-apps/:id/users/:userId">, options?: RequestOptions) => Promise<undefined>;
|
|
241
|
+
delete: (userId: string, options?: RequestOptions) => Promise<undefined>;
|
|
242
|
+
markEmailVerified: (userId: string, options?: RequestOptions) => Promise<undefined>;
|
|
243
|
+
sendPasswordReset: (userId: string, options?: RequestOptions) => Promise<undefined>;
|
|
244
|
+
roles: (userId: string, options?: RequestOptions) => Promise<{
|
|
245
|
+
readonly items: ReadonlyArray<{
|
|
246
|
+
readonly "id": string;
|
|
247
|
+
readonly "name": string;
|
|
248
|
+
readonly "isStaff": boolean;
|
|
249
|
+
readonly "permissions": ReadonlyArray<{
|
|
250
|
+
readonly "resource": string;
|
|
251
|
+
readonly "action": string;
|
|
252
|
+
}>;
|
|
253
|
+
}>;
|
|
254
|
+
readonly total: number;
|
|
255
|
+
}>;
|
|
256
|
+
assignRole: (userId: string, roleId: string, options?: RequestOptions) => Promise<undefined>;
|
|
257
|
+
removeRole: (userId: string, roleId: string, options?: RequestOptions) => Promise<undefined>;
|
|
258
|
+
};
|
|
259
|
+
roles: {
|
|
260
|
+
list: (options?: RequestOptions) => Promise<{
|
|
261
|
+
readonly items: ReadonlyArray<{
|
|
262
|
+
readonly "id": string;
|
|
263
|
+
readonly "name": string;
|
|
264
|
+
readonly "isStaff": boolean;
|
|
265
|
+
readonly "permissions": ReadonlyArray<{
|
|
266
|
+
readonly "resource": string;
|
|
267
|
+
readonly "action": string;
|
|
268
|
+
}>;
|
|
269
|
+
readonly "organizationId": string;
|
|
270
|
+
readonly "displayName": string | null;
|
|
271
|
+
readonly "description": string | null;
|
|
272
|
+
readonly "isSystem": boolean;
|
|
273
|
+
readonly "createdAt": string;
|
|
274
|
+
readonly "updatedAt": string;
|
|
275
|
+
readonly "userCount": number;
|
|
276
|
+
}>;
|
|
277
|
+
readonly total: number;
|
|
278
|
+
}>;
|
|
279
|
+
create: (body: Input<"POST /tenant-apps/:id/roles">, options?: RequestOptions) => Promise<{
|
|
280
|
+
readonly id: string;
|
|
281
|
+
readonly name: string;
|
|
282
|
+
readonly isStaff: boolean;
|
|
283
|
+
readonly permissions: ReadonlyArray<{
|
|
284
|
+
readonly "resource": string;
|
|
285
|
+
readonly "action": string;
|
|
286
|
+
}>;
|
|
287
|
+
readonly organizationId: string;
|
|
288
|
+
readonly displayName: string | null;
|
|
289
|
+
readonly description: string | null;
|
|
290
|
+
readonly isSystem: boolean;
|
|
291
|
+
readonly createdAt: string;
|
|
292
|
+
readonly updatedAt: string;
|
|
293
|
+
}>;
|
|
294
|
+
update: (roleId: string, body: Input<"PATCH /tenant-apps/:id/roles/:roleId">, options?: RequestOptions) => Promise<{
|
|
295
|
+
readonly id: string;
|
|
296
|
+
readonly name: string;
|
|
297
|
+
readonly isStaff: boolean;
|
|
298
|
+
readonly permissions: ReadonlyArray<{
|
|
299
|
+
readonly "resource": string;
|
|
300
|
+
readonly "action": string;
|
|
301
|
+
}>;
|
|
302
|
+
readonly organizationId: string;
|
|
303
|
+
readonly displayName: string | null;
|
|
304
|
+
readonly description: string | null;
|
|
305
|
+
readonly isSystem: boolean;
|
|
306
|
+
readonly createdAt: string;
|
|
307
|
+
readonly updatedAt: string;
|
|
308
|
+
}>;
|
|
309
|
+
delete: (roleId: string, options?: RequestOptions) => Promise<undefined>;
|
|
310
|
+
users: (roleId: string, options?: RequestOptions) => Promise<{
|
|
311
|
+
readonly items: ReadonlyArray<{
|
|
312
|
+
readonly "id": string;
|
|
313
|
+
readonly "email": string;
|
|
314
|
+
}>;
|
|
315
|
+
readonly total: number;
|
|
316
|
+
}>;
|
|
317
|
+
};
|
|
318
|
+
invitations: {
|
|
319
|
+
list: (options?: RequestOptions) => Promise<{
|
|
320
|
+
readonly items: ReadonlyArray<{
|
|
321
|
+
readonly "id": string;
|
|
322
|
+
readonly "email": string;
|
|
323
|
+
readonly "hasLinkedPatient": boolean;
|
|
324
|
+
readonly "hasLinkedPractitioner": boolean;
|
|
325
|
+
readonly "hasLinkedRole": boolean;
|
|
326
|
+
readonly "expiresAt": string;
|
|
327
|
+
readonly "createdAt": string;
|
|
328
|
+
}>;
|
|
329
|
+
readonly total: number;
|
|
330
|
+
}>;
|
|
331
|
+
invite: (body: Input<"POST /tenant-apps/:id/user-invitations">, options?: RequestOptions) => Promise<{
|
|
332
|
+
readonly invitationId: string;
|
|
333
|
+
}>;
|
|
334
|
+
inviteMany: (body: Input<"POST /tenant-apps/:id/user-invitations/bulk">, options?: RequestOptions) => Promise<{
|
|
335
|
+
readonly created: ReadonlyArray<{
|
|
336
|
+
readonly "email": string;
|
|
337
|
+
readonly "invitationId": string;
|
|
338
|
+
}>;
|
|
339
|
+
readonly failed: ReadonlyArray<{
|
|
340
|
+
readonly "email": string;
|
|
341
|
+
readonly "error": string;
|
|
342
|
+
}>;
|
|
343
|
+
}>;
|
|
344
|
+
inviteStaff: (body: Input<"POST /tenant-apps/:id/staff-invitations">, options?: RequestOptions) => Promise<{
|
|
345
|
+
readonly invitationId: string;
|
|
346
|
+
readonly practitionerId: string;
|
|
347
|
+
}>;
|
|
348
|
+
resend: (invId: string, options?: RequestOptions) => Promise<{
|
|
349
|
+
readonly message: string;
|
|
350
|
+
}>;
|
|
351
|
+
revoke: (invId: string, options?: RequestOptions) => Promise<undefined>;
|
|
352
|
+
};
|
|
353
|
+
};
|
|
354
|
+
};
|
|
355
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { tenantAppStatuses } from "./integration-contract.js";
|
|
2
|
+
import { integrationRequest, uuidPattern } from "./integration-request.js";
|
|
3
|
+
function uuid(id, parameter) {
|
|
4
|
+
if (id === undefined || !uuidPattern.test(id)) {
|
|
5
|
+
throw new TypeError(`Invalid tenant app path parameter: ${parameter}`);
|
|
6
|
+
}
|
|
7
|
+
return id.toLowerCase();
|
|
8
|
+
}
|
|
9
|
+
export function tenantAppsClient(request) {
|
|
10
|
+
const call = integrationRequest(request, tenantAppStatuses, uuid, "Esus returned an invalid tenant app response");
|
|
11
|
+
return {
|
|
12
|
+
list: (options) => call("GET /tenant-apps", {}, options),
|
|
13
|
+
create: (body, options) => call("POST /tenant-apps", {}, { ...options, body }),
|
|
14
|
+
linkUser: (userId, body, options) => call("PATCH /v1/auth/users/:userId", { userId }, { ...options, body }),
|
|
15
|
+
forApp: (id) => ({
|
|
16
|
+
get: (options) => call("GET /tenant-apps/:id", { id }, options),
|
|
17
|
+
update: (body, options) => call("PATCH /tenant-apps/:id", { id }, { ...options, body }),
|
|
18
|
+
delete: (options) => call("DELETE /tenant-apps/:id", { id }, options),
|
|
19
|
+
stats: (options) => call("GET /tenant-apps/:id/stats", { id }, options),
|
|
20
|
+
sendTestEmail: (body, options) => call("POST /tenant-apps/:id/email/test", { id }, { ...options, body }),
|
|
21
|
+
backfillPatientConsents: (options) => call("POST /tenant-apps/:id/backfill-patient-consents", { id }, options),
|
|
22
|
+
users: {
|
|
23
|
+
list: (query, options) => call("GET /tenant-apps/:id/users", { id }, { ...options, query }),
|
|
24
|
+
get: (userId, options) => call("GET /tenant-apps/:id/users/:userId", { id, userId }, options),
|
|
25
|
+
update: (userId, body, options) => call("PATCH /tenant-apps/:id/users/:userId", { id, userId }, { ...options, body }),
|
|
26
|
+
delete: (userId, options) => call("DELETE /tenant-apps/:id/users/:userId", { id, userId }, options),
|
|
27
|
+
markEmailVerified: (userId, options) => call("POST /tenant-apps/:id/users/:userId/verify-email", { id, userId }, options),
|
|
28
|
+
sendPasswordReset: (userId, options) => call("POST /tenant-apps/:id/users/:userId/send-password-reset", { id, userId }, options),
|
|
29
|
+
roles: (userId, options) => call("GET /tenant-apps/:id/users/:userId/roles", { id, userId }, options),
|
|
30
|
+
assignRole: (userId, roleId, options) => call("POST /tenant-apps/:id/users/:userId/roles/:roleId", { id, userId, roleId }, options),
|
|
31
|
+
removeRole: (userId, roleId, options) => call("DELETE /tenant-apps/:id/users/:userId/roles/:roleId", { id, userId, roleId }, options),
|
|
32
|
+
},
|
|
33
|
+
roles: {
|
|
34
|
+
list: (options) => call("GET /tenant-apps/:id/roles", { id }, options),
|
|
35
|
+
create: (body, options) => call("POST /tenant-apps/:id/roles", { id }, { ...options, body }),
|
|
36
|
+
update: (roleId, body, options) => call("PATCH /tenant-apps/:id/roles/:roleId", { id, roleId }, { ...options, body }),
|
|
37
|
+
delete: (roleId, options) => call("DELETE /tenant-apps/:id/roles/:roleId", { id, roleId }, options),
|
|
38
|
+
users: (roleId, options) => call("GET /tenant-apps/:id/roles/:roleId/users", { id, roleId }, options),
|
|
39
|
+
},
|
|
40
|
+
invitations: {
|
|
41
|
+
list: (options) => call("GET /tenant-apps/:id/user-invitations", { id }, options),
|
|
42
|
+
invite: (body, options) => call("POST /tenant-apps/:id/user-invitations", { id }, { ...options, body }),
|
|
43
|
+
inviteMany: (body, options) => call("POST /tenant-apps/:id/user-invitations/bulk", { id }, { ...options, body }),
|
|
44
|
+
inviteStaff: (body, options) => call("POST /tenant-apps/:id/staff-invitations", { id }, { ...options, body }),
|
|
45
|
+
resend: (invId, options) => call("POST /tenant-apps/:id/user-invitations/:invId/resend", { id, invId }, options),
|
|
46
|
+
revoke: (invId, options) => call("DELETE /tenant-apps/:id/user-invitations/:invId", { id, invId }, options),
|
|
47
|
+
},
|
|
48
|
+
}),
|
|
49
|
+
};
|
|
50
|
+
}
|