@vorim/sdk 3.12.0 → 3.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +14 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -2
- package/dist/index.d.ts +14 -2
- package/dist/index.js +14 -1
- package/dist/index.js.map +1 -1
- package/dist/integrations/anthropic.d.cts +1 -1
- package/dist/integrations/anthropic.d.ts +1 -1
- package/dist/integrations/ap2.d.cts +1 -1
- package/dist/integrations/ap2.d.ts +1 -1
- package/dist/integrations/aws-iam.cjs +225 -0
- package/dist/integrations/aws-iam.cjs.map +1 -0
- package/dist/integrations/aws-iam.d.cts +156 -0
- package/dist/integrations/aws-iam.d.ts +156 -0
- package/dist/integrations/aws-iam.js +199 -0
- package/dist/integrations/aws-iam.js.map +1 -0
- package/dist/integrations/bank-rails.d.cts +1 -1
- package/dist/integrations/bank-rails.d.ts +1 -1
- package/dist/integrations/circle.d.cts +1 -1
- package/dist/integrations/circle.d.ts +1 -1
- package/dist/integrations/cloudflare.d.cts +1 -1
- package/dist/integrations/cloudflare.d.ts +1 -1
- package/dist/integrations/coinbase-cdp.cjs +230 -0
- package/dist/integrations/coinbase-cdp.cjs.map +1 -0
- package/dist/integrations/coinbase-cdp.d.cts +169 -0
- package/dist/integrations/coinbase-cdp.d.ts +169 -0
- package/dist/integrations/coinbase-cdp.js +204 -0
- package/dist/integrations/coinbase-cdp.js.map +1 -0
- package/dist/integrations/crewai.d.cts +1 -1
- package/dist/integrations/crewai.d.ts +1 -1
- package/dist/integrations/entra.cjs +225 -0
- package/dist/integrations/entra.cjs.map +1 -0
- package/dist/integrations/entra.d.cts +155 -0
- package/dist/integrations/entra.d.ts +155 -0
- package/dist/integrations/entra.js +199 -0
- package/dist/integrations/entra.js.map +1 -0
- package/dist/integrations/fhir.cjs +304 -0
- package/dist/integrations/fhir.cjs.map +1 -0
- package/dist/integrations/fhir.d.cts +185 -0
- package/dist/integrations/fhir.d.ts +185 -0
- package/dist/integrations/fhir.js +278 -0
- package/dist/integrations/fhir.js.map +1 -0
- package/dist/integrations/guidewire.cjs +363 -0
- package/dist/integrations/guidewire.cjs.map +1 -0
- package/dist/integrations/guidewire.d.cts +258 -0
- package/dist/integrations/guidewire.d.ts +258 -0
- package/dist/integrations/guidewire.js +337 -0
- package/dist/integrations/guidewire.js.map +1 -0
- package/dist/integrations/hermes.d.cts +1 -1
- package/dist/integrations/hermes.d.ts +1 -1
- package/dist/integrations/langchain.d.cts +1 -1
- package/dist/integrations/langchain.d.ts +1 -1
- package/dist/integrations/langgraph.d.cts +1 -1
- package/dist/integrations/langgraph.d.ts +1 -1
- package/dist/integrations/legal.cjs +339 -0
- package/dist/integrations/legal.cjs.map +1 -0
- package/dist/integrations/legal.d.cts +225 -0
- package/dist/integrations/legal.d.ts +225 -0
- package/dist/integrations/legal.js +313 -0
- package/dist/integrations/legal.js.map +1 -0
- package/dist/integrations/life-sciences.cjs +335 -0
- package/dist/integrations/life-sciences.cjs.map +1 -0
- package/dist/integrations/life-sciences.d.cts +214 -0
- package/dist/integrations/life-sciences.d.ts +214 -0
- package/dist/integrations/life-sciences.js +309 -0
- package/dist/integrations/life-sciences.js.map +1 -0
- package/dist/integrations/lithic.cjs +290 -0
- package/dist/integrations/lithic.cjs.map +1 -0
- package/dist/integrations/lithic.d.cts +130 -0
- package/dist/integrations/lithic.d.ts +130 -0
- package/dist/integrations/lithic.js +264 -0
- package/dist/integrations/lithic.js.map +1 -0
- package/dist/integrations/llamaindex.d.cts +1 -1
- package/dist/integrations/llamaindex.d.ts +1 -1
- package/dist/integrations/marqeta.cjs +285 -0
- package/dist/integrations/marqeta.cjs.map +1 -0
- package/dist/integrations/marqeta.d.cts +121 -0
- package/dist/integrations/marqeta.d.ts +121 -0
- package/dist/integrations/marqeta.js +259 -0
- package/dist/integrations/marqeta.js.map +1 -0
- package/dist/integrations/modern-treasury.d.cts +1 -1
- package/dist/integrations/modern-treasury.d.ts +1 -1
- package/dist/integrations/nekuda.d.cts +1 -1
- package/dist/integrations/nekuda.d.ts +1 -1
- package/dist/integrations/okta.cjs +229 -0
- package/dist/integrations/okta.cjs.map +1 -0
- package/dist/integrations/okta.d.cts +172 -0
- package/dist/integrations/okta.d.ts +172 -0
- package/dist/integrations/okta.js +203 -0
- package/dist/integrations/okta.js.map +1 -0
- package/dist/integrations/openai.d.cts +1 -1
- package/dist/integrations/openai.d.ts +1 -1
- package/dist/integrations/paypal-agent.d.cts +1 -1
- package/dist/integrations/paypal-agent.d.ts +1 -1
- package/dist/integrations/plaid.d.cts +1 -1
- package/dist/integrations/plaid.d.ts +1 -1
- package/dist/integrations/ramp.cjs +206 -0
- package/dist/integrations/ramp.cjs.map +1 -0
- package/dist/integrations/ramp.d.cts +139 -0
- package/dist/integrations/ramp.d.ts +139 -0
- package/dist/integrations/ramp.js +180 -0
- package/dist/integrations/ramp.js.map +1 -0
- package/dist/integrations/shopify.d.cts +1 -1
- package/dist/integrations/shopify.d.ts +1 -1
- package/dist/integrations/siem.d.cts +1 -1
- package/dist/integrations/siem.d.ts +1 -1
- package/dist/integrations/skyfire.d.cts +1 -1
- package/dist/integrations/skyfire.d.ts +1 -1
- package/dist/integrations/stripe-acp.d.cts +1 -1
- package/dist/integrations/stripe-acp.d.ts +1 -1
- package/dist/integrations/stripe-issuing.cjs +316 -0
- package/dist/integrations/stripe-issuing.cjs.map +1 -0
- package/dist/integrations/stripe-issuing.d.cts +154 -0
- package/dist/integrations/stripe-issuing.d.ts +154 -0
- package/dist/integrations/stripe-issuing.js +290 -0
- package/dist/integrations/stripe-issuing.js.map +1 -0
- package/dist/integrations/truanon.d.cts +1 -1
- package/dist/integrations/truanon.d.ts +1 -1
- package/dist/integrations/ucp.d.cts +1 -1
- package/dist/integrations/ucp.d.ts +1 -1
- package/dist/integrations/vercel-ai.d.cts +1 -1
- package/dist/integrations/vercel-ai.d.ts +1 -1
- package/dist/integrations/x402.d.cts +1 -1
- package/dist/integrations/x402.d.ts +1 -1
- package/dist/{types-zzK9YOoa.d.cts → types-Lp1iHEDz.d.cts} +21 -1
- package/dist/{types-zzK9YOoa.d.ts → types-Lp1iHEDz.d.ts} +21 -1
- package/package.json +121 -1
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { VorimSDK } from '../index.cjs';
|
|
2
|
+
import { P as PermissionScope } from '../types-Lp1iHEDz.cjs';
|
|
3
|
+
|
|
4
|
+
/** A FHIR REST write interaction. Reads/searches pass through as 'read'. */
|
|
5
|
+
type FhirInteraction = 'create' | 'update' | 'patch' | 'transaction' | 'read';
|
|
6
|
+
interface FhirGuardConfig {
|
|
7
|
+
/** The acting agent's Vorim id (agid_...). */
|
|
8
|
+
agentId: string;
|
|
9
|
+
/** The FHIR R4 base URL, e.g. an Epic/Oracle R4 endpoint. Recorded on every
|
|
10
|
+
* receipt so a write is attributable to one server. */
|
|
11
|
+
fhirBaseUrl: string;
|
|
12
|
+
/** Attenuation: restrict this agent to these FHIR resource types. A write to
|
|
13
|
+
* any other type is denied. Omit to allow any type (subject to readOnly). */
|
|
14
|
+
allowedResources?: string[];
|
|
15
|
+
/** Attenuation: cap this agent to read/search only. Any create/update/patch is
|
|
16
|
+
* denied even if the SMART token was over-scoped. Default false. */
|
|
17
|
+
readOnly?: boolean;
|
|
18
|
+
/** Resource types that must be written as an UNSIGNED draft and signed by a
|
|
19
|
+
* clinician (escalation). Defaults to MedicationRequest + ServiceRequest —
|
|
20
|
+
* the order resources EHRs gate this way. */
|
|
21
|
+
orderResources?: string[];
|
|
22
|
+
/** The clinician who signs an escalated order. Required if any order-resource
|
|
23
|
+
* write will be run. Recorded as the signer on the record. */
|
|
24
|
+
clinicianId?: string;
|
|
25
|
+
/** For an order resource, escalate to the clinician and wait for the signature
|
|
26
|
+
* instead of denying. Requires the runtime decision plane. Default true.
|
|
27
|
+
* Ignored when readOnly. */
|
|
28
|
+
escalateOrders?: boolean;
|
|
29
|
+
/** Max time to wait for a clinician signature, ms. Default 300000 (5 min). */
|
|
30
|
+
escalationTimeoutMs?: number;
|
|
31
|
+
/** Minimum trust score the agent must hold before any write. Default 0 (off). */
|
|
32
|
+
minTrustScore?: number;
|
|
33
|
+
/** Fail closed (deny on any Vorim error) or fail open. Default 'closed'. */
|
|
34
|
+
onError?: 'closed' | 'open';
|
|
35
|
+
}
|
|
36
|
+
interface FhirAction {
|
|
37
|
+
/** The FHIR interaction, e.g. 'create'. Drives the scope. Reads pass as
|
|
38
|
+
* 'read'. Unknown labels are treated as a write. */
|
|
39
|
+
interaction: FhirInteraction | string;
|
|
40
|
+
/** The FHIR resource type, e.g. 'Observation'. Checked against
|
|
41
|
+
* allowedResources and the order-resource set. */
|
|
42
|
+
resourceType: string;
|
|
43
|
+
/** The resource id, when known (update/patch, or the created id). */
|
|
44
|
+
resourceId?: string;
|
|
45
|
+
/** Optional hash of the resource body so the receipt covers the exact input
|
|
46
|
+
* without the guard storing PHI. */
|
|
47
|
+
inputHash?: string;
|
|
48
|
+
}
|
|
49
|
+
/** How an order-resource write resolved. */
|
|
50
|
+
type OrderOutcome = 'not-an-order' | 'signed-by-clinician' | 'order-denied' | 'blocked-read-only';
|
|
51
|
+
/** An offline-verifiable receipt for one FHIR write. Contains no PHI — only the
|
|
52
|
+
* resource type/id, the agent, and the authorization outcome. */
|
|
53
|
+
interface FhirReceipt {
|
|
54
|
+
authorized: boolean;
|
|
55
|
+
agentId: string;
|
|
56
|
+
fhirBaseUrl: string;
|
|
57
|
+
interaction: string;
|
|
58
|
+
resourceType: string;
|
|
59
|
+
resourceId?: string;
|
|
60
|
+
/** True when the resource is an order that requires a clinician signature. */
|
|
61
|
+
isOrder: boolean;
|
|
62
|
+
orderOutcome: OrderOutcome;
|
|
63
|
+
/** The clinician who signed, when an order was escalated and signed. */
|
|
64
|
+
signerId?: string;
|
|
65
|
+
result: 'success' | 'denied' | 'error';
|
|
66
|
+
scope: PermissionScope;
|
|
67
|
+
reason?: string;
|
|
68
|
+
decisionId?: string;
|
|
69
|
+
recorded: boolean;
|
|
70
|
+
}
|
|
71
|
+
declare class VorimFhir {
|
|
72
|
+
private sdk;
|
|
73
|
+
private agentId;
|
|
74
|
+
private fhirBaseUrl;
|
|
75
|
+
private allowedResources?;
|
|
76
|
+
private readOnly;
|
|
77
|
+
private orderResources;
|
|
78
|
+
private clinicianId?;
|
|
79
|
+
private escalateOrders;
|
|
80
|
+
private escalationTimeoutMs;
|
|
81
|
+
private minTrustScore;
|
|
82
|
+
private onError;
|
|
83
|
+
constructor(sdk: VorimSDK, config: FhirGuardConfig);
|
|
84
|
+
private isRead;
|
|
85
|
+
private isOrder;
|
|
86
|
+
/** The Vorim scope an action requires. Reads need read; order-resource writes
|
|
87
|
+
* are elevated (draft + clinician sign); other writes need write. */
|
|
88
|
+
private scopeFor;
|
|
89
|
+
/**
|
|
90
|
+
* Decide whether the acting agent may run this FHIR interaction, before it
|
|
91
|
+
* runs. Order: trust floor, read-only cap, resource-type cap, order gate
|
|
92
|
+
* (escalate to clinician), then permission scope.
|
|
93
|
+
*/
|
|
94
|
+
authorize(action: FhirAction): Promise<{
|
|
95
|
+
authorized: boolean;
|
|
96
|
+
reason?: string;
|
|
97
|
+
orderOutcome: OrderOutcome;
|
|
98
|
+
signerId?: string;
|
|
99
|
+
decisionId?: string;
|
|
100
|
+
}>;
|
|
101
|
+
/**
|
|
102
|
+
* Route an order-resource write through the runtime decision plane so a
|
|
103
|
+
* clinician can sign (approve) or refuse the unsigned draft, and wait. The
|
|
104
|
+
* elevate scope marks the segregation-of-duties gate: the agent proposes the
|
|
105
|
+
* order, the clinician signs it.
|
|
106
|
+
*/
|
|
107
|
+
private escalate;
|
|
108
|
+
/**
|
|
109
|
+
* Emit a source-signed audit event for a FHIR write and return whether it was
|
|
110
|
+
* recorded. The event names the agent, the server, the resource type/id, and
|
|
111
|
+
* any clinician signer — attributable and independently verifiable offline,
|
|
112
|
+
* supporting HIPAA §164.312(b) audit controls. It carries NO PHI.
|
|
113
|
+
*/
|
|
114
|
+
record(action: FhirAction, result: 'success' | 'denied' | 'error', extra?: {
|
|
115
|
+
reason?: string;
|
|
116
|
+
orderOutcome?: OrderOutcome;
|
|
117
|
+
signerId?: string;
|
|
118
|
+
decisionId?: string;
|
|
119
|
+
}): Promise<boolean>;
|
|
120
|
+
/**
|
|
121
|
+
* The full flow for one FHIR interaction: authorize (trust, caps, order gate,
|
|
122
|
+
* scope), run the FHIR call if allowed, sign a receipt either way. If not
|
|
123
|
+
* authorized, `run` is never called. Rethrows a FHIR error from `run` after
|
|
124
|
+
* recording it, with the receipt attached as `vorimReceipt`.
|
|
125
|
+
*/
|
|
126
|
+
guard<T>(action: FhirAction, run: () => Promise<T>): Promise<{
|
|
127
|
+
receipt: FhirReceipt;
|
|
128
|
+
value?: T;
|
|
129
|
+
}>;
|
|
130
|
+
/** Guard a FHIR `create` (POST [base]/[type]). Requires agent:write, or
|
|
131
|
+
* agent:elevate + a clinician signature for an order resource. */
|
|
132
|
+
guardedCreate<T>(meta: {
|
|
133
|
+
resourceType: string;
|
|
134
|
+
resourceId?: string;
|
|
135
|
+
inputHash?: string;
|
|
136
|
+
}, run: () => Promise<T>): Promise<{
|
|
137
|
+
receipt: FhirReceipt;
|
|
138
|
+
value?: T | undefined;
|
|
139
|
+
}>;
|
|
140
|
+
/** Guard a FHIR `update` (PUT [base]/[type]/[id]). */
|
|
141
|
+
guardedUpdate<T>(meta: {
|
|
142
|
+
resourceType: string;
|
|
143
|
+
resourceId?: string;
|
|
144
|
+
inputHash?: string;
|
|
145
|
+
}, run: () => Promise<T>): Promise<{
|
|
146
|
+
receipt: FhirReceipt;
|
|
147
|
+
value?: T | undefined;
|
|
148
|
+
}>;
|
|
149
|
+
/** Guard a FHIR `patch` (PATCH [base]/[type]/[id]). */
|
|
150
|
+
guardedPatch<T>(meta: {
|
|
151
|
+
resourceType: string;
|
|
152
|
+
resourceId?: string;
|
|
153
|
+
inputHash?: string;
|
|
154
|
+
}, run: () => Promise<T>): Promise<{
|
|
155
|
+
receipt: FhirReceipt;
|
|
156
|
+
value?: T | undefined;
|
|
157
|
+
}>;
|
|
158
|
+
private receipt;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Create a VorimFhir guard around a Vorim SDK instance.
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* ```typescript
|
|
165
|
+
* import createVorim from '@vorim/sdk';
|
|
166
|
+
* import { createVorimFhir } from '@vorim/sdk/integrations/fhir';
|
|
167
|
+
*
|
|
168
|
+
* const vorim = createVorim({ apiKey: 'agid_sk_...' });
|
|
169
|
+
* const fhir = createVorimFhir(vorim, {
|
|
170
|
+
* agentId: 'agid_abc123',
|
|
171
|
+
* fhirBaseUrl: 'https://fhir.epic.com/interconnect-fhir-oauth/api/FHIR/R4',
|
|
172
|
+
* allowedResources: ['DocumentReference', 'Observation'],
|
|
173
|
+
* clinicianId: 'dr_42',
|
|
174
|
+
* });
|
|
175
|
+
*
|
|
176
|
+
* // An order resource forces a draft + clinician signature:
|
|
177
|
+
* const { receipt } = await fhir.guardedCreate(
|
|
178
|
+
* { resourceType: 'MedicationRequest' },
|
|
179
|
+
* () => fhirClient.create('MedicationRequest', unsignedDraft),
|
|
180
|
+
* );
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
declare function createVorimFhir(sdk: VorimSDK, config: FhirGuardConfig): VorimFhir;
|
|
184
|
+
|
|
185
|
+
export { type FhirAction, type FhirGuardConfig, type FhirInteraction, type FhirReceipt, type OrderOutcome, VorimFhir, createVorimFhir };
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { VorimSDK } from '../index.js';
|
|
2
|
+
import { P as PermissionScope } from '../types-Lp1iHEDz.js';
|
|
3
|
+
|
|
4
|
+
/** A FHIR REST write interaction. Reads/searches pass through as 'read'. */
|
|
5
|
+
type FhirInteraction = 'create' | 'update' | 'patch' | 'transaction' | 'read';
|
|
6
|
+
interface FhirGuardConfig {
|
|
7
|
+
/** The acting agent's Vorim id (agid_...). */
|
|
8
|
+
agentId: string;
|
|
9
|
+
/** The FHIR R4 base URL, e.g. an Epic/Oracle R4 endpoint. Recorded on every
|
|
10
|
+
* receipt so a write is attributable to one server. */
|
|
11
|
+
fhirBaseUrl: string;
|
|
12
|
+
/** Attenuation: restrict this agent to these FHIR resource types. A write to
|
|
13
|
+
* any other type is denied. Omit to allow any type (subject to readOnly). */
|
|
14
|
+
allowedResources?: string[];
|
|
15
|
+
/** Attenuation: cap this agent to read/search only. Any create/update/patch is
|
|
16
|
+
* denied even if the SMART token was over-scoped. Default false. */
|
|
17
|
+
readOnly?: boolean;
|
|
18
|
+
/** Resource types that must be written as an UNSIGNED draft and signed by a
|
|
19
|
+
* clinician (escalation). Defaults to MedicationRequest + ServiceRequest —
|
|
20
|
+
* the order resources EHRs gate this way. */
|
|
21
|
+
orderResources?: string[];
|
|
22
|
+
/** The clinician who signs an escalated order. Required if any order-resource
|
|
23
|
+
* write will be run. Recorded as the signer on the record. */
|
|
24
|
+
clinicianId?: string;
|
|
25
|
+
/** For an order resource, escalate to the clinician and wait for the signature
|
|
26
|
+
* instead of denying. Requires the runtime decision plane. Default true.
|
|
27
|
+
* Ignored when readOnly. */
|
|
28
|
+
escalateOrders?: boolean;
|
|
29
|
+
/** Max time to wait for a clinician signature, ms. Default 300000 (5 min). */
|
|
30
|
+
escalationTimeoutMs?: number;
|
|
31
|
+
/** Minimum trust score the agent must hold before any write. Default 0 (off). */
|
|
32
|
+
minTrustScore?: number;
|
|
33
|
+
/** Fail closed (deny on any Vorim error) or fail open. Default 'closed'. */
|
|
34
|
+
onError?: 'closed' | 'open';
|
|
35
|
+
}
|
|
36
|
+
interface FhirAction {
|
|
37
|
+
/** The FHIR interaction, e.g. 'create'. Drives the scope. Reads pass as
|
|
38
|
+
* 'read'. Unknown labels are treated as a write. */
|
|
39
|
+
interaction: FhirInteraction | string;
|
|
40
|
+
/** The FHIR resource type, e.g. 'Observation'. Checked against
|
|
41
|
+
* allowedResources and the order-resource set. */
|
|
42
|
+
resourceType: string;
|
|
43
|
+
/** The resource id, when known (update/patch, or the created id). */
|
|
44
|
+
resourceId?: string;
|
|
45
|
+
/** Optional hash of the resource body so the receipt covers the exact input
|
|
46
|
+
* without the guard storing PHI. */
|
|
47
|
+
inputHash?: string;
|
|
48
|
+
}
|
|
49
|
+
/** How an order-resource write resolved. */
|
|
50
|
+
type OrderOutcome = 'not-an-order' | 'signed-by-clinician' | 'order-denied' | 'blocked-read-only';
|
|
51
|
+
/** An offline-verifiable receipt for one FHIR write. Contains no PHI — only the
|
|
52
|
+
* resource type/id, the agent, and the authorization outcome. */
|
|
53
|
+
interface FhirReceipt {
|
|
54
|
+
authorized: boolean;
|
|
55
|
+
agentId: string;
|
|
56
|
+
fhirBaseUrl: string;
|
|
57
|
+
interaction: string;
|
|
58
|
+
resourceType: string;
|
|
59
|
+
resourceId?: string;
|
|
60
|
+
/** True when the resource is an order that requires a clinician signature. */
|
|
61
|
+
isOrder: boolean;
|
|
62
|
+
orderOutcome: OrderOutcome;
|
|
63
|
+
/** The clinician who signed, when an order was escalated and signed. */
|
|
64
|
+
signerId?: string;
|
|
65
|
+
result: 'success' | 'denied' | 'error';
|
|
66
|
+
scope: PermissionScope;
|
|
67
|
+
reason?: string;
|
|
68
|
+
decisionId?: string;
|
|
69
|
+
recorded: boolean;
|
|
70
|
+
}
|
|
71
|
+
declare class VorimFhir {
|
|
72
|
+
private sdk;
|
|
73
|
+
private agentId;
|
|
74
|
+
private fhirBaseUrl;
|
|
75
|
+
private allowedResources?;
|
|
76
|
+
private readOnly;
|
|
77
|
+
private orderResources;
|
|
78
|
+
private clinicianId?;
|
|
79
|
+
private escalateOrders;
|
|
80
|
+
private escalationTimeoutMs;
|
|
81
|
+
private minTrustScore;
|
|
82
|
+
private onError;
|
|
83
|
+
constructor(sdk: VorimSDK, config: FhirGuardConfig);
|
|
84
|
+
private isRead;
|
|
85
|
+
private isOrder;
|
|
86
|
+
/** The Vorim scope an action requires. Reads need read; order-resource writes
|
|
87
|
+
* are elevated (draft + clinician sign); other writes need write. */
|
|
88
|
+
private scopeFor;
|
|
89
|
+
/**
|
|
90
|
+
* Decide whether the acting agent may run this FHIR interaction, before it
|
|
91
|
+
* runs. Order: trust floor, read-only cap, resource-type cap, order gate
|
|
92
|
+
* (escalate to clinician), then permission scope.
|
|
93
|
+
*/
|
|
94
|
+
authorize(action: FhirAction): Promise<{
|
|
95
|
+
authorized: boolean;
|
|
96
|
+
reason?: string;
|
|
97
|
+
orderOutcome: OrderOutcome;
|
|
98
|
+
signerId?: string;
|
|
99
|
+
decisionId?: string;
|
|
100
|
+
}>;
|
|
101
|
+
/**
|
|
102
|
+
* Route an order-resource write through the runtime decision plane so a
|
|
103
|
+
* clinician can sign (approve) or refuse the unsigned draft, and wait. The
|
|
104
|
+
* elevate scope marks the segregation-of-duties gate: the agent proposes the
|
|
105
|
+
* order, the clinician signs it.
|
|
106
|
+
*/
|
|
107
|
+
private escalate;
|
|
108
|
+
/**
|
|
109
|
+
* Emit a source-signed audit event for a FHIR write and return whether it was
|
|
110
|
+
* recorded. The event names the agent, the server, the resource type/id, and
|
|
111
|
+
* any clinician signer — attributable and independently verifiable offline,
|
|
112
|
+
* supporting HIPAA §164.312(b) audit controls. It carries NO PHI.
|
|
113
|
+
*/
|
|
114
|
+
record(action: FhirAction, result: 'success' | 'denied' | 'error', extra?: {
|
|
115
|
+
reason?: string;
|
|
116
|
+
orderOutcome?: OrderOutcome;
|
|
117
|
+
signerId?: string;
|
|
118
|
+
decisionId?: string;
|
|
119
|
+
}): Promise<boolean>;
|
|
120
|
+
/**
|
|
121
|
+
* The full flow for one FHIR interaction: authorize (trust, caps, order gate,
|
|
122
|
+
* scope), run the FHIR call if allowed, sign a receipt either way. If not
|
|
123
|
+
* authorized, `run` is never called. Rethrows a FHIR error from `run` after
|
|
124
|
+
* recording it, with the receipt attached as `vorimReceipt`.
|
|
125
|
+
*/
|
|
126
|
+
guard<T>(action: FhirAction, run: () => Promise<T>): Promise<{
|
|
127
|
+
receipt: FhirReceipt;
|
|
128
|
+
value?: T;
|
|
129
|
+
}>;
|
|
130
|
+
/** Guard a FHIR `create` (POST [base]/[type]). Requires agent:write, or
|
|
131
|
+
* agent:elevate + a clinician signature for an order resource. */
|
|
132
|
+
guardedCreate<T>(meta: {
|
|
133
|
+
resourceType: string;
|
|
134
|
+
resourceId?: string;
|
|
135
|
+
inputHash?: string;
|
|
136
|
+
}, run: () => Promise<T>): Promise<{
|
|
137
|
+
receipt: FhirReceipt;
|
|
138
|
+
value?: T | undefined;
|
|
139
|
+
}>;
|
|
140
|
+
/** Guard a FHIR `update` (PUT [base]/[type]/[id]). */
|
|
141
|
+
guardedUpdate<T>(meta: {
|
|
142
|
+
resourceType: string;
|
|
143
|
+
resourceId?: string;
|
|
144
|
+
inputHash?: string;
|
|
145
|
+
}, run: () => Promise<T>): Promise<{
|
|
146
|
+
receipt: FhirReceipt;
|
|
147
|
+
value?: T | undefined;
|
|
148
|
+
}>;
|
|
149
|
+
/** Guard a FHIR `patch` (PATCH [base]/[type]/[id]). */
|
|
150
|
+
guardedPatch<T>(meta: {
|
|
151
|
+
resourceType: string;
|
|
152
|
+
resourceId?: string;
|
|
153
|
+
inputHash?: string;
|
|
154
|
+
}, run: () => Promise<T>): Promise<{
|
|
155
|
+
receipt: FhirReceipt;
|
|
156
|
+
value?: T | undefined;
|
|
157
|
+
}>;
|
|
158
|
+
private receipt;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Create a VorimFhir guard around a Vorim SDK instance.
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* ```typescript
|
|
165
|
+
* import createVorim from '@vorim/sdk';
|
|
166
|
+
* import { createVorimFhir } from '@vorim/sdk/integrations/fhir';
|
|
167
|
+
*
|
|
168
|
+
* const vorim = createVorim({ apiKey: 'agid_sk_...' });
|
|
169
|
+
* const fhir = createVorimFhir(vorim, {
|
|
170
|
+
* agentId: 'agid_abc123',
|
|
171
|
+
* fhirBaseUrl: 'https://fhir.epic.com/interconnect-fhir-oauth/api/FHIR/R4',
|
|
172
|
+
* allowedResources: ['DocumentReference', 'Observation'],
|
|
173
|
+
* clinicianId: 'dr_42',
|
|
174
|
+
* });
|
|
175
|
+
*
|
|
176
|
+
* // An order resource forces a draft + clinician signature:
|
|
177
|
+
* const { receipt } = await fhir.guardedCreate(
|
|
178
|
+
* { resourceType: 'MedicationRequest' },
|
|
179
|
+
* () => fhirClient.create('MedicationRequest', unsignedDraft),
|
|
180
|
+
* );
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
declare function createVorimFhir(sdk: VorimSDK, config: FhirGuardConfig): VorimFhir;
|
|
184
|
+
|
|
185
|
+
export { type FhirAction, type FhirGuardConfig, type FhirInteraction, type FhirReceipt, type OrderOutcome, VorimFhir, createVorimFhir };
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
// src/integrations/fhir.ts
|
|
2
|
+
var DEFAULT_ORDER_RESOURCES = ["MedicationRequest", "ServiceRequest"];
|
|
3
|
+
var VorimFhir = class {
|
|
4
|
+
sdk;
|
|
5
|
+
agentId;
|
|
6
|
+
fhirBaseUrl;
|
|
7
|
+
allowedResources;
|
|
8
|
+
readOnly;
|
|
9
|
+
orderResources;
|
|
10
|
+
clinicianId;
|
|
11
|
+
escalateOrders;
|
|
12
|
+
escalationTimeoutMs;
|
|
13
|
+
minTrustScore;
|
|
14
|
+
onError;
|
|
15
|
+
constructor(sdk, config) {
|
|
16
|
+
if (!config?.agentId) throw new Error("[vorim] FHIR integration requires an agentId.");
|
|
17
|
+
if (!config?.fhirBaseUrl) throw new Error("[vorim] FHIR integration requires a fhirBaseUrl.");
|
|
18
|
+
this.sdk = sdk;
|
|
19
|
+
this.agentId = config.agentId;
|
|
20
|
+
this.fhirBaseUrl = config.fhirBaseUrl;
|
|
21
|
+
this.allowedResources = config.allowedResources ? new Set(config.allowedResources) : void 0;
|
|
22
|
+
this.readOnly = config.readOnly ?? false;
|
|
23
|
+
this.orderResources = new Set(config.orderResources ?? DEFAULT_ORDER_RESOURCES);
|
|
24
|
+
this.clinicianId = config.clinicianId;
|
|
25
|
+
this.escalateOrders = config.escalateOrders ?? true;
|
|
26
|
+
this.escalationTimeoutMs = config.escalationTimeoutMs ?? 3e5;
|
|
27
|
+
this.minTrustScore = config.minTrustScore ?? 0;
|
|
28
|
+
this.onError = config.onError ?? "closed";
|
|
29
|
+
}
|
|
30
|
+
isRead(interaction) {
|
|
31
|
+
return interaction === "read";
|
|
32
|
+
}
|
|
33
|
+
isOrder(action) {
|
|
34
|
+
return !this.isRead(action.interaction) && this.orderResources.has(action.resourceType);
|
|
35
|
+
}
|
|
36
|
+
/** The Vorim scope an action requires. Reads need read; order-resource writes
|
|
37
|
+
* are elevated (draft + clinician sign); other writes need write. */
|
|
38
|
+
scopeFor(action) {
|
|
39
|
+
if (this.isRead(action.interaction)) return "agent:read";
|
|
40
|
+
if (this.isOrder(action)) return "agent:elevate";
|
|
41
|
+
return "agent:write";
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Decide whether the acting agent may run this FHIR interaction, before it
|
|
45
|
+
* runs. Order: trust floor, read-only cap, resource-type cap, order gate
|
|
46
|
+
* (escalate to clinician), then permission scope.
|
|
47
|
+
*/
|
|
48
|
+
async authorize(action) {
|
|
49
|
+
const isRead = this.isRead(action.interaction);
|
|
50
|
+
const isOrder = this.isOrder(action);
|
|
51
|
+
const scope = this.scopeFor(action);
|
|
52
|
+
if (!isRead && this.readOnly) {
|
|
53
|
+
return {
|
|
54
|
+
authorized: false,
|
|
55
|
+
reason: "agent is read-only; writes are not permitted",
|
|
56
|
+
orderOutcome: isOrder ? "blocked-read-only" : "not-an-order"
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
if (!isRead && this.allowedResources && !this.allowedResources.has(action.resourceType)) {
|
|
60
|
+
return {
|
|
61
|
+
authorized: false,
|
|
62
|
+
reason: `resource type ${action.resourceType} is not in this agent's allowed set`,
|
|
63
|
+
orderOutcome: isOrder ? "order-denied" : "not-an-order"
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
try {
|
|
67
|
+
if (this.minTrustScore > 0) {
|
|
68
|
+
const trust = await this.sdk.verify(this.agentId);
|
|
69
|
+
if ((trust?.trust_score ?? 0) < this.minTrustScore) {
|
|
70
|
+
return {
|
|
71
|
+
authorized: false,
|
|
72
|
+
reason: `trust score below ${this.minTrustScore}`,
|
|
73
|
+
orderOutcome: isOrder ? "order-denied" : "not-an-order"
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (isOrder) {
|
|
78
|
+
if (!this.escalateOrders) {
|
|
79
|
+
return {
|
|
80
|
+
authorized: false,
|
|
81
|
+
reason: "order resource requires a clinician signature and escalateOrders is off",
|
|
82
|
+
orderOutcome: "order-denied"
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
if (!this.clinicianId) {
|
|
86
|
+
return {
|
|
87
|
+
authorized: false,
|
|
88
|
+
reason: "order resource requires a configured clinicianId (the signing clinician)",
|
|
89
|
+
orderOutcome: "order-denied"
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
const esc = await this.escalate(action, scope);
|
|
93
|
+
return {
|
|
94
|
+
authorized: esc.approved,
|
|
95
|
+
reason: esc.approved ? void 0 : esc.reason ?? "clinician did not sign the order",
|
|
96
|
+
orderOutcome: esc.approved ? "signed-by-clinician" : "order-denied",
|
|
97
|
+
signerId: esc.approved ? this.clinicianId : void 0,
|
|
98
|
+
decisionId: esc.decisionId
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
const perm = await this.sdk.check(this.agentId, scope);
|
|
102
|
+
return perm.allowed ? { authorized: true, orderOutcome: "not-an-order" } : {
|
|
103
|
+
authorized: false,
|
|
104
|
+
reason: perm.reason ?? `missing scope ${scope}`,
|
|
105
|
+
orderOutcome: "not-an-order"
|
|
106
|
+
};
|
|
107
|
+
} catch (e) {
|
|
108
|
+
return this.onError === "open" ? {
|
|
109
|
+
authorized: true,
|
|
110
|
+
reason: "vorim unreachable, failed open",
|
|
111
|
+
orderOutcome: isOrder ? "signed-by-clinician" : "not-an-order"
|
|
112
|
+
} : {
|
|
113
|
+
authorized: false,
|
|
114
|
+
reason: `vorim unreachable: ${e?.message ?? "error"}`,
|
|
115
|
+
orderOutcome: isOrder ? "order-denied" : "not-an-order"
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Route an order-resource write through the runtime decision plane so a
|
|
121
|
+
* clinician can sign (approve) or refuse the unsigned draft, and wait. The
|
|
122
|
+
* elevate scope marks the segregation-of-duties gate: the agent proposes the
|
|
123
|
+
* order, the clinician signs it.
|
|
124
|
+
*/
|
|
125
|
+
async escalate(action, scope) {
|
|
126
|
+
const decision = await this.sdk.beforeAction(
|
|
127
|
+
{
|
|
128
|
+
agentId: this.agentId,
|
|
129
|
+
actionType: "api_request",
|
|
130
|
+
actionTarget: `fhir:${action.interaction}:${action.resourceType}`,
|
|
131
|
+
requiredScope: scope,
|
|
132
|
+
payload: {
|
|
133
|
+
interaction: action.interaction,
|
|
134
|
+
resource_type: action.resourceType,
|
|
135
|
+
resource_id: action.resourceId,
|
|
136
|
+
order_status: "unsigned-draft"
|
|
137
|
+
},
|
|
138
|
+
context: {
|
|
139
|
+
integration: "fhir-r4",
|
|
140
|
+
fhir_base_url: this.fhirBaseUrl,
|
|
141
|
+
requires_clinician_signature: true,
|
|
142
|
+
clinician_hint: this.clinicianId
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
{ throwOnDeny: false }
|
|
146
|
+
);
|
|
147
|
+
if (decision.decision === "escalate") {
|
|
148
|
+
const resolved = await this.sdk.waitForDecisionResolution(decision.decisionId, {
|
|
149
|
+
timeoutMs: this.escalationTimeoutMs
|
|
150
|
+
});
|
|
151
|
+
const approved = resolved.decision === "allow" || resolved.escalationResolution === "approved";
|
|
152
|
+
return {
|
|
153
|
+
approved,
|
|
154
|
+
reason: approved ? void 0 : "clinician refused to sign the order",
|
|
155
|
+
decisionId: decision.decisionId
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
if (decision.decision === "allow") return { approved: true, decisionId: decision.decisionId };
|
|
159
|
+
if (decision.decision === "fallback")
|
|
160
|
+
return { approved: this.onError === "open", reason: "runtime unreachable", decisionId: decision.decisionId };
|
|
161
|
+
return { approved: false, reason: decision.reason ?? "denied", decisionId: decision.decisionId };
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Emit a source-signed audit event for a FHIR write and return whether it was
|
|
165
|
+
* recorded. The event names the agent, the server, the resource type/id, and
|
|
166
|
+
* any clinician signer — attributable and independently verifiable offline,
|
|
167
|
+
* supporting HIPAA §164.312(b) audit controls. It carries NO PHI.
|
|
168
|
+
*/
|
|
169
|
+
async record(action, result, extra = {}) {
|
|
170
|
+
const scope = this.scopeFor(action);
|
|
171
|
+
try {
|
|
172
|
+
await this.sdk.emit(
|
|
173
|
+
{
|
|
174
|
+
agent_id: this.agentId,
|
|
175
|
+
event_type: "api_request",
|
|
176
|
+
action: `fhir:${action.interaction} ${action.resourceType}${action.resourceId ? "/" + action.resourceId : ""}`,
|
|
177
|
+
resource: `${action.resourceType}${action.resourceId ? "/" + action.resourceId : ""}`,
|
|
178
|
+
permission: scope,
|
|
179
|
+
result,
|
|
180
|
+
input_hash: action.inputHash,
|
|
181
|
+
metadata: {
|
|
182
|
+
integration: "fhir-r4",
|
|
183
|
+
fhir_base_url: this.fhirBaseUrl,
|
|
184
|
+
interaction: action.interaction,
|
|
185
|
+
resource_type: action.resourceType,
|
|
186
|
+
is_order: this.isOrder(action),
|
|
187
|
+
...extra.orderOutcome ? { order_outcome: extra.orderOutcome } : {},
|
|
188
|
+
...extra.signerId ? { signed_by_clinician: extra.signerId, signed_at: (/* @__PURE__ */ new Date()).toISOString() } : {},
|
|
189
|
+
...extra.decisionId ? { decision_id: extra.decisionId } : {},
|
|
190
|
+
...extra.reason ? { reason: extra.reason } : {}
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
{ sign: true }
|
|
194
|
+
// source-signed: the agent's key signs the record
|
|
195
|
+
);
|
|
196
|
+
return true;
|
|
197
|
+
} catch {
|
|
198
|
+
return false;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* The full flow for one FHIR interaction: authorize (trust, caps, order gate,
|
|
203
|
+
* scope), run the FHIR call if allowed, sign a receipt either way. If not
|
|
204
|
+
* authorized, `run` is never called. Rethrows a FHIR error from `run` after
|
|
205
|
+
* recording it, with the receipt attached as `vorimReceipt`.
|
|
206
|
+
*/
|
|
207
|
+
async guard(action, run) {
|
|
208
|
+
const auth = await this.authorize(action);
|
|
209
|
+
if (!auth.authorized) {
|
|
210
|
+
const recorded = await this.record(action, "denied", {
|
|
211
|
+
reason: auth.reason,
|
|
212
|
+
orderOutcome: auth.orderOutcome,
|
|
213
|
+
signerId: auth.signerId,
|
|
214
|
+
decisionId: auth.decisionId
|
|
215
|
+
});
|
|
216
|
+
return { receipt: this.receipt(action, false, "denied", auth, recorded) };
|
|
217
|
+
}
|
|
218
|
+
try {
|
|
219
|
+
const value = await run();
|
|
220
|
+
const recorded = await this.record(action, "success", {
|
|
221
|
+
orderOutcome: auth.orderOutcome,
|
|
222
|
+
signerId: auth.signerId,
|
|
223
|
+
decisionId: auth.decisionId
|
|
224
|
+
});
|
|
225
|
+
return { receipt: this.receipt(action, true, "success", auth, recorded), value };
|
|
226
|
+
} catch (e) {
|
|
227
|
+
const recorded = await this.record(action, "error", {
|
|
228
|
+
reason: e?.message,
|
|
229
|
+
orderOutcome: auth.orderOutcome,
|
|
230
|
+
signerId: auth.signerId,
|
|
231
|
+
decisionId: auth.decisionId
|
|
232
|
+
});
|
|
233
|
+
throw Object.assign(e ?? new Error("fhir operation failed"), {
|
|
234
|
+
vorimReceipt: this.receipt(action, true, "error", { ...auth, reason: e?.message }, recorded)
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
// --- Named helpers ---------------------------------------------------------
|
|
239
|
+
/** Guard a FHIR `create` (POST [base]/[type]). Requires agent:write, or
|
|
240
|
+
* agent:elevate + a clinician signature for an order resource. */
|
|
241
|
+
guardedCreate(meta, run) {
|
|
242
|
+
return this.guard({ interaction: "create", resourceType: meta.resourceType, resourceId: meta.resourceId, inputHash: meta.inputHash }, run);
|
|
243
|
+
}
|
|
244
|
+
/** Guard a FHIR `update` (PUT [base]/[type]/[id]). */
|
|
245
|
+
guardedUpdate(meta, run) {
|
|
246
|
+
return this.guard({ interaction: "update", resourceType: meta.resourceType, resourceId: meta.resourceId, inputHash: meta.inputHash }, run);
|
|
247
|
+
}
|
|
248
|
+
/** Guard a FHIR `patch` (PATCH [base]/[type]/[id]). */
|
|
249
|
+
guardedPatch(meta, run) {
|
|
250
|
+
return this.guard({ interaction: "patch", resourceType: meta.resourceType, resourceId: meta.resourceId, inputHash: meta.inputHash }, run);
|
|
251
|
+
}
|
|
252
|
+
receipt(action, authorized, result, auth, recorded) {
|
|
253
|
+
return {
|
|
254
|
+
authorized,
|
|
255
|
+
agentId: this.agentId,
|
|
256
|
+
fhirBaseUrl: this.fhirBaseUrl,
|
|
257
|
+
interaction: action.interaction,
|
|
258
|
+
resourceType: action.resourceType,
|
|
259
|
+
resourceId: action.resourceId,
|
|
260
|
+
isOrder: this.isOrder(action),
|
|
261
|
+
orderOutcome: auth.orderOutcome ?? "not-an-order",
|
|
262
|
+
signerId: auth.signerId,
|
|
263
|
+
result,
|
|
264
|
+
scope: this.scopeFor(action),
|
|
265
|
+
reason: auth.reason,
|
|
266
|
+
decisionId: auth.decisionId,
|
|
267
|
+
recorded
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
function createVorimFhir(sdk, config) {
|
|
272
|
+
return new VorimFhir(sdk, config);
|
|
273
|
+
}
|
|
274
|
+
export {
|
|
275
|
+
VorimFhir,
|
|
276
|
+
createVorimFhir
|
|
277
|
+
};
|
|
278
|
+
//# sourceMappingURL=fhir.js.map
|