@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,199 @@
|
|
|
1
|
+
// src/integrations/entra.ts
|
|
2
|
+
var ESCALATION_OPS = /* @__PURE__ */ new Set(["assignDirectoryRole", "addAppSecret", "grantAppRoleAssignment"]);
|
|
3
|
+
var OPERATION_SCOPE = {
|
|
4
|
+
read: "agent:read",
|
|
5
|
+
createUser: "agent:write",
|
|
6
|
+
disableUser: "agent:write",
|
|
7
|
+
createAppRegistration: "agent:write",
|
|
8
|
+
addAppSecret: "agent:elevate",
|
|
9
|
+
grantAppRoleAssignment: "agent:elevate",
|
|
10
|
+
assignDirectoryRole: "agent:elevate"
|
|
11
|
+
};
|
|
12
|
+
var VorimEntra = class {
|
|
13
|
+
sdk;
|
|
14
|
+
agentId;
|
|
15
|
+
tenantId;
|
|
16
|
+
adminId;
|
|
17
|
+
minTrustScore;
|
|
18
|
+
escalatePrivileged;
|
|
19
|
+
escalationTimeoutMs;
|
|
20
|
+
onError;
|
|
21
|
+
constructor(sdk, config) {
|
|
22
|
+
if (!config?.agentId) throw new Error("[vorim] Entra integration requires an agentId.");
|
|
23
|
+
if (!config?.tenantId) throw new Error("[vorim] Entra integration requires a tenantId.");
|
|
24
|
+
this.sdk = sdk;
|
|
25
|
+
this.agentId = config.agentId;
|
|
26
|
+
this.tenantId = config.tenantId;
|
|
27
|
+
this.adminId = config.adminId;
|
|
28
|
+
this.minTrustScore = config.minTrustScore ?? 0;
|
|
29
|
+
this.escalatePrivileged = config.escalatePrivileged ?? true;
|
|
30
|
+
this.escalationTimeoutMs = config.escalationTimeoutMs ?? 3e5;
|
|
31
|
+
this.onError = config.onError ?? "closed";
|
|
32
|
+
}
|
|
33
|
+
isPrivileged(operation) {
|
|
34
|
+
return ESCALATION_OPS.has(operation);
|
|
35
|
+
}
|
|
36
|
+
scopeFor(operation) {
|
|
37
|
+
return OPERATION_SCOPE[operation] ?? "agent:write";
|
|
38
|
+
}
|
|
39
|
+
async authorize(action) {
|
|
40
|
+
const privileged = this.isPrivileged(action.operation);
|
|
41
|
+
const scope = this.scopeFor(action.operation);
|
|
42
|
+
try {
|
|
43
|
+
if (this.minTrustScore > 0) {
|
|
44
|
+
const trust = await this.sdk.verify(this.agentId);
|
|
45
|
+
if ((trust?.trust_score ?? 0) < this.minTrustScore) {
|
|
46
|
+
return { authorized: false, reason: `trust score below ${this.minTrustScore}`, outcome: privileged ? "privileged-denied" : "ordinary" };
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (privileged) {
|
|
50
|
+
if (!this.escalatePrivileged) {
|
|
51
|
+
return { authorized: false, reason: `${action.operation} requires a human admin and escalatePrivileged is off`, outcome: "privileged-denied" };
|
|
52
|
+
}
|
|
53
|
+
if (!this.adminId) {
|
|
54
|
+
return {
|
|
55
|
+
authorized: false,
|
|
56
|
+
reason: `${action.operation} requires a configured adminId (the approving human admin)`,
|
|
57
|
+
outcome: "privileged-denied"
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
const esc = await this.escalate(action, scope);
|
|
61
|
+
return {
|
|
62
|
+
authorized: esc.approved,
|
|
63
|
+
reason: esc.approved ? void 0 : esc.reason ?? "admin did not approve",
|
|
64
|
+
outcome: esc.approved ? "approved-by-admin" : "privileged-denied",
|
|
65
|
+
adminId: esc.approved ? this.adminId : void 0,
|
|
66
|
+
decisionId: esc.decisionId
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
const perm = await this.sdk.check(this.agentId, scope);
|
|
70
|
+
return perm.allowed ? { authorized: true, outcome: "ordinary", adminId: this.adminId } : { authorized: false, reason: perm.reason ?? `missing scope ${scope}`, outcome: "ordinary" };
|
|
71
|
+
} catch (e) {
|
|
72
|
+
return this.onError === "open" ? { authorized: true, reason: "vorim unreachable, failed open", outcome: privileged ? "approved-by-admin" : "ordinary" } : { authorized: false, reason: `vorim unreachable: ${e?.message ?? "error"}`, outcome: privileged ? "privileged-denied" : "ordinary" };
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
async escalate(action, scope) {
|
|
76
|
+
const decision = await this.sdk.beforeAction(
|
|
77
|
+
{
|
|
78
|
+
agentId: this.agentId,
|
|
79
|
+
actionType: "api_request",
|
|
80
|
+
actionTarget: `entra:${action.operation}`,
|
|
81
|
+
requiredScope: scope,
|
|
82
|
+
payload: { operation: action.operation, target_id: action.targetId, role: action.role },
|
|
83
|
+
context: { integration: "entra", tenant_id: this.tenantId, requires_human_admin: true, admin_hint: this.adminId }
|
|
84
|
+
},
|
|
85
|
+
{ throwOnDeny: false }
|
|
86
|
+
);
|
|
87
|
+
if (decision.decision === "escalate") {
|
|
88
|
+
const resolved = await this.sdk.waitForDecisionResolution(decision.decisionId, { timeoutMs: this.escalationTimeoutMs });
|
|
89
|
+
const approved = resolved.decision === "allow" || resolved.escalationResolution === "approved";
|
|
90
|
+
return { approved, reason: approved ? void 0 : "admin refused", decisionId: decision.decisionId };
|
|
91
|
+
}
|
|
92
|
+
if (decision.decision === "allow") return { approved: true, decisionId: decision.decisionId };
|
|
93
|
+
if (decision.decision === "fallback")
|
|
94
|
+
return { approved: this.onError === "open", reason: "runtime unreachable", decisionId: decision.decisionId };
|
|
95
|
+
return { approved: false, reason: decision.reason ?? "denied", decisionId: decision.decisionId };
|
|
96
|
+
}
|
|
97
|
+
async record(action, result, extra = {}) {
|
|
98
|
+
const scope = this.scopeFor(action.operation);
|
|
99
|
+
try {
|
|
100
|
+
await this.sdk.emit(
|
|
101
|
+
{
|
|
102
|
+
agent_id: this.agentId,
|
|
103
|
+
event_type: "api_request",
|
|
104
|
+
action: `entra:${action.operation}${action.targetId ? " " + action.targetId : ""}`,
|
|
105
|
+
resource: action.targetId || this.tenantId,
|
|
106
|
+
permission: scope,
|
|
107
|
+
result,
|
|
108
|
+
input_hash: action.inputHash,
|
|
109
|
+
metadata: {
|
|
110
|
+
integration: "entra",
|
|
111
|
+
tenant_id: this.tenantId,
|
|
112
|
+
operation: action.operation,
|
|
113
|
+
privileged: this.isPrivileged(action.operation),
|
|
114
|
+
...action.role ? { role: action.role } : {},
|
|
115
|
+
...extra.outcome ? { outcome: extra.outcome } : {},
|
|
116
|
+
...extra.adminId ?? this.adminId ? { approved_by_admin: extra.adminId ?? this.adminId } : {},
|
|
117
|
+
...extra.decisionId ? { decision_id: extra.decisionId } : {},
|
|
118
|
+
...extra.reason ? { reason: extra.reason } : {}
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
{ sign: true }
|
|
122
|
+
);
|
|
123
|
+
return true;
|
|
124
|
+
} catch {
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
async guard(action, run) {
|
|
129
|
+
const auth = await this.authorize(action);
|
|
130
|
+
if (!auth.authorized) {
|
|
131
|
+
const recorded = await this.record(action, "denied", { reason: auth.reason, outcome: auth.outcome, adminId: auth.adminId, decisionId: auth.decisionId });
|
|
132
|
+
return { receipt: this.receipt(action, false, "denied", auth, recorded) };
|
|
133
|
+
}
|
|
134
|
+
try {
|
|
135
|
+
const value = await run();
|
|
136
|
+
const recorded = await this.record(action, "success", { outcome: auth.outcome, adminId: auth.adminId, decisionId: auth.decisionId });
|
|
137
|
+
return { receipt: this.receipt(action, true, "success", auth, recorded), value };
|
|
138
|
+
} catch (e) {
|
|
139
|
+
const recorded = await this.record(action, "error", { reason: e?.message, outcome: auth.outcome, adminId: auth.adminId, decisionId: auth.decisionId });
|
|
140
|
+
throw Object.assign(e ?? new Error("entra operation failed"), {
|
|
141
|
+
vorimReceipt: this.receipt(action, true, "error", { ...auth, reason: e?.message }, recorded)
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
// --- Named helpers ---------------------------------------------------------
|
|
146
|
+
/** Guard creating a user (POST /users). Requires agent:write. */
|
|
147
|
+
guardedCreateUser(meta, run) {
|
|
148
|
+
return this.guard({ operation: "createUser", targetId: meta.targetId, inputHash: meta.inputHash }, run);
|
|
149
|
+
}
|
|
150
|
+
/** Guard disabling a user (PATCH /users/{id} accountEnabled:false). agent:write. */
|
|
151
|
+
guardedDisableUser(meta, run) {
|
|
152
|
+
return this.guard({ operation: "disableUser", targetId: meta.targetId, inputHash: meta.inputHash }, run);
|
|
153
|
+
}
|
|
154
|
+
/** Guard creating an app registration (POST /applications). agent:write. */
|
|
155
|
+
guardedCreateAppRegistration(meta, run) {
|
|
156
|
+
return this.guard({ operation: "createAppRegistration", targetId: meta.targetId, inputHash: meta.inputHash }, run);
|
|
157
|
+
}
|
|
158
|
+
/** Guard adding a client secret to an app (POST /applications/{id}/addPassword).
|
|
159
|
+
* Mints a long-lived credential; always escalates to the named admin. */
|
|
160
|
+
guardedAddAppSecret(meta, run) {
|
|
161
|
+
return this.guard({ operation: "addAppSecret", targetId: meta.targetId, inputHash: meta.inputHash }, run);
|
|
162
|
+
}
|
|
163
|
+
/** Guard granting an app-role assignment. Always escalates to the named admin
|
|
164
|
+
* (an application-permission grant is tenant-wide privilege). */
|
|
165
|
+
guardedGrantAppRoleAssignment(meta, run) {
|
|
166
|
+
return this.guard({ operation: "grantAppRoleAssignment", targetId: meta.targetId, role: meta.role, inputHash: meta.inputHash }, run);
|
|
167
|
+
}
|
|
168
|
+
/** Guard assigning a directory role (POST /roleManagement/directory/roleAssignments).
|
|
169
|
+
* Always escalates to the named admin. Pass the role (e.g. 'Global Administrator'). */
|
|
170
|
+
guardedAssignDirectoryRole(meta, run) {
|
|
171
|
+
return this.guard({ operation: "assignDirectoryRole", targetId: meta.targetId, role: meta.role, inputHash: meta.inputHash }, run);
|
|
172
|
+
}
|
|
173
|
+
receipt(action, authorized, result, auth, recorded) {
|
|
174
|
+
return {
|
|
175
|
+
authorized,
|
|
176
|
+
agentId: this.agentId,
|
|
177
|
+
tenantId: this.tenantId,
|
|
178
|
+
operation: action.operation,
|
|
179
|
+
targetId: action.targetId,
|
|
180
|
+
role: action.role,
|
|
181
|
+
privileged: this.isPrivileged(action.operation),
|
|
182
|
+
outcome: auth.outcome ?? "ordinary",
|
|
183
|
+
adminId: auth.adminId ?? this.adminId,
|
|
184
|
+
result,
|
|
185
|
+
scope: this.scopeFor(action.operation),
|
|
186
|
+
reason: auth.reason,
|
|
187
|
+
decisionId: auth.decisionId,
|
|
188
|
+
recorded
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
function createVorimEntra(sdk, config) {
|
|
193
|
+
return new VorimEntra(sdk, config);
|
|
194
|
+
}
|
|
195
|
+
export {
|
|
196
|
+
VorimEntra,
|
|
197
|
+
createVorimEntra
|
|
198
|
+
};
|
|
199
|
+
//# sourceMappingURL=entra.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/integrations/entra.ts"],"sourcesContent":["// ============================================================================\n// Vorim AI — Microsoft Entra ID (Microsoft Graph) Integration\n//\n// This guards an AI agent that administers Microsoft Entra ID through the\n// Microsoft Graph v1.0 API — creating users, registering apps, assigning app\n// roles, minting app credentials, assigning directory roles. Before each write\n// runs it verifies the agent's Vorim identity and scoped permission, and for the\n// highest-stakes operations (assigning a directory role, adding an app secret,\n// granting a tenant-wide app-role assignment) it escalates to a named human\n// admin and waits. Either way it signs a tamper-evident record.\n//\n// GRAPH v1.0 ONLY — HONEST SCOPE\n// This connector guards the STABLE, GA Microsoft Graph v1.0 admin writes. It is\n// NOT an integration with \"Entra Agent ID\": that product's identity-create API\n// is Microsoft Graph /beta, which Microsoft states is \"not supported in\n// production.\" We do not imply otherwise. When the Agent ID API reaches v1.0\n// GA, a second connector can guard it.\n//\n// THE ESCALATION RULE (the wedge)\n// Three operations grant standing, tenant-wide authority or mint a long-lived\n// credential and must always route to a named human admin: assigning a directory\n// role (e.g. Global Administrator), adding a client secret to an app (the\n// secretText is returned once and never retrievable again), and granting an\n// app-role assignment that is an application permission. An agent may propose\n// these; a human authorizes them.\n//\n// SCOPE MAPPING (uses Vorim's real scopes)\n// read directory -> agent:read\n// create/disable user, register app -> agent:write\n// assign directory role / add app -> agent:elevate (named-admin approval)\n// secret / grant app-role\n//\n// HONEST COMPLIANCE FRAMING\n// A signed, attributable record of each directory change supports SOC 2 (CC6\n// logical access, CC7 change monitoring). No regime mandates cryptographic\n// signatures on audit logs; signing satisfies the tamper-evident + attributable\n// intent. Say \"cryptographic proof of which agent made which change\", never\n// \"required for compliance\".\n//\n// This layer never holds the Graph app credential and never calls Graph itself.\n// You pass the Graph SDK call as a closure; it authorizes, escalates if needed,\n// runs it, and signs the receipt.\n//\n// Usage:\n// import createVorim from '@vorim/sdk';\n// import { createVorimEntra } from '@vorim/sdk/integrations/entra';\n//\n// const vorim = createVorim({ apiKey: 'agid_sk_...' });\n// const entra = createVorimEntra(vorim, {\n// agentId: 'agid_abc123',\n// tenantId: 'contoso.onmicrosoft.com',\n// adminId: 'admin_42',\n// });\n//\n// const { receipt, value } = await entra.guardedAssignDirectoryRole(\n// { targetId: 'user_9', role: 'Global Administrator' },\n// () => graphClient.api('/roleManagement/directory/roleAssignments').post(body),\n// );\n// ============================================================================\n\nimport type { VorimSDK } from '../index.js';\nimport type { PermissionScope } from '../types.js';\n\n/** The Microsoft Graph (Entra) operations this guard classifies. */\nexport type EntraOperation =\n | 'createUser' // POST /users\n | 'disableUser' // PATCH /users/{id} accountEnabled:false\n | 'createAppRegistration' // POST /applications\n | 'addAppSecret' // POST /applications/{id}/addPassword\n | 'grantAppRoleAssignment' // POST /servicePrincipals/{id}/appRoleAssignedTo\n | 'assignDirectoryRole' // POST /roleManagement/directory/roleAssignments\n | 'read';\n\n/** Operations that grant standing tenant-wide authority or mint a long-lived\n * credential — always escalate to a named human admin. */\nconst ESCALATION_OPS = new Set<string>(['assignDirectoryRole', 'addAppSecret', 'grantAppRoleAssignment']);\n\nconst OPERATION_SCOPE: Record<string, PermissionScope> = {\n read: 'agent:read',\n createUser: 'agent:write',\n disableUser: 'agent:write',\n createAppRegistration: 'agent:write',\n addAppSecret: 'agent:elevate',\n grantAppRoleAssignment: 'agent:elevate',\n assignDirectoryRole: 'agent:elevate',\n};\n\nexport interface EntraGuardConfig {\n /** The acting agent's Vorim id (agid_...). */\n agentId: string;\n /** The Entra tenant, e.g. 'contoso.onmicrosoft.com' or a tenant GUID.\n * Recorded on every receipt. */\n tenantId: string;\n /** The human admin who approves privileged operations. Required if any\n * escalation-class op will be run. */\n adminId?: string;\n minTrustScore?: number;\n /** For a privileged op, escalate to the named admin and wait. Default true. */\n escalatePrivileged?: boolean;\n escalationTimeoutMs?: number;\n onError?: 'closed' | 'open';\n}\n\nexport interface EntraAction {\n operation: EntraOperation | string;\n /** The target the action affects (user id, app/service-principal id).\n * Recorded for attribution. */\n targetId?: string;\n /** For assignDirectoryRole: the role, e.g. 'Global Administrator'. Recorded. */\n role?: string;\n inputHash?: string;\n}\n\nexport type EntraOutcome = 'ordinary' | 'approved-by-admin' | 'privileged-denied';\n\nexport interface EntraReceipt {\n authorized: boolean;\n agentId: string;\n tenantId: string;\n operation: string;\n targetId?: string;\n role?: string;\n privileged: boolean;\n outcome: EntraOutcome;\n adminId?: string;\n result: 'success' | 'denied' | 'error';\n scope: PermissionScope;\n reason?: string;\n decisionId?: string;\n recorded: boolean;\n}\n\nexport class VorimEntra {\n private sdk: VorimSDK;\n private agentId: string;\n private tenantId: string;\n private adminId?: string;\n private minTrustScore: number;\n private escalatePrivileged: boolean;\n private escalationTimeoutMs: number;\n private onError: 'closed' | 'open';\n\n constructor(sdk: VorimSDK, config: EntraGuardConfig) {\n if (!config?.agentId) throw new Error('[vorim] Entra integration requires an agentId.');\n if (!config?.tenantId) throw new Error('[vorim] Entra integration requires a tenantId.');\n this.sdk = sdk;\n this.agentId = config.agentId;\n this.tenantId = config.tenantId;\n this.adminId = config.adminId;\n this.minTrustScore = config.minTrustScore ?? 0;\n this.escalatePrivileged = config.escalatePrivileged ?? true;\n this.escalationTimeoutMs = config.escalationTimeoutMs ?? 300_000;\n this.onError = config.onError ?? 'closed';\n }\n\n private isPrivileged(operation: string): boolean {\n return ESCALATION_OPS.has(operation);\n }\n\n private scopeFor(operation: string): PermissionScope {\n return OPERATION_SCOPE[operation] ?? 'agent:write';\n }\n\n async authorize(\n action: EntraAction,\n ): Promise<{ authorized: boolean; reason?: string; outcome: EntraOutcome; adminId?: string; decisionId?: string }> {\n const privileged = this.isPrivileged(action.operation);\n const scope = this.scopeFor(action.operation);\n\n try {\n if (this.minTrustScore > 0) {\n const trust = await this.sdk.verify(this.agentId);\n if ((trust?.trust_score ?? 0) < this.minTrustScore) {\n return { authorized: false, reason: `trust score below ${this.minTrustScore}`, outcome: privileged ? 'privileged-denied' : 'ordinary' };\n }\n }\n\n if (privileged) {\n if (!this.escalatePrivileged) {\n return { authorized: false, reason: `${action.operation} requires a human admin and escalatePrivileged is off`, outcome: 'privileged-denied' };\n }\n if (!this.adminId) {\n return {\n authorized: false,\n reason: `${action.operation} requires a configured adminId (the approving human admin)`,\n outcome: 'privileged-denied',\n };\n }\n const esc = await this.escalate(action, scope);\n return {\n authorized: esc.approved,\n reason: esc.approved ? undefined : (esc.reason ?? 'admin did not approve'),\n outcome: esc.approved ? 'approved-by-admin' : 'privileged-denied',\n adminId: esc.approved ? this.adminId : undefined,\n decisionId: esc.decisionId,\n };\n }\n\n const perm = await this.sdk.check(this.agentId, scope);\n return perm.allowed\n ? { authorized: true, outcome: 'ordinary', adminId: this.adminId }\n : { authorized: false, reason: perm.reason ?? `missing scope ${scope}`, outcome: 'ordinary' };\n } catch (e: any) {\n return this.onError === 'open'\n ? { authorized: true, reason: 'vorim unreachable, failed open', outcome: privileged ? 'approved-by-admin' : 'ordinary' }\n : { authorized: false, reason: `vorim unreachable: ${e?.message ?? 'error'}`, outcome: privileged ? 'privileged-denied' : 'ordinary' };\n }\n }\n\n private async escalate(action: EntraAction, scope: PermissionScope): Promise<{ approved: boolean; reason?: string; decisionId?: string }> {\n const decision = await this.sdk.beforeAction(\n {\n agentId: this.agentId,\n actionType: 'api_request',\n actionTarget: `entra:${action.operation}`,\n requiredScope: scope,\n payload: { operation: action.operation, target_id: action.targetId, role: action.role },\n context: { integration: 'entra', tenant_id: this.tenantId, requires_human_admin: true, admin_hint: this.adminId },\n },\n { throwOnDeny: false },\n );\n if (decision.decision === 'escalate') {\n const resolved = await this.sdk.waitForDecisionResolution(decision.decisionId, { timeoutMs: this.escalationTimeoutMs });\n const approved = resolved.decision === 'allow' || resolved.escalationResolution === 'approved';\n return { approved, reason: approved ? undefined : 'admin refused', decisionId: decision.decisionId };\n }\n if (decision.decision === 'allow') return { approved: true, decisionId: decision.decisionId };\n if (decision.decision === 'fallback')\n return { approved: this.onError === 'open', reason: 'runtime unreachable', decisionId: decision.decisionId };\n return { approved: false, reason: decision.reason ?? 'denied', decisionId: decision.decisionId };\n }\n\n async record(\n action: EntraAction,\n result: 'success' | 'denied' | 'error',\n extra: { reason?: string; outcome?: EntraOutcome; adminId?: string; decisionId?: string } = {},\n ): Promise<boolean> {\n const scope = this.scopeFor(action.operation);\n try {\n await this.sdk.emit(\n {\n agent_id: this.agentId,\n event_type: 'api_request',\n action: `entra:${action.operation}${action.targetId ? ' ' + action.targetId : ''}`,\n resource: action.targetId || this.tenantId,\n permission: scope,\n result,\n input_hash: action.inputHash,\n metadata: {\n integration: 'entra',\n tenant_id: this.tenantId,\n operation: action.operation,\n privileged: this.isPrivileged(action.operation),\n ...(action.role ? { role: action.role } : {}),\n ...(extra.outcome ? { outcome: extra.outcome } : {}),\n ...(extra.adminId ?? this.adminId ? { approved_by_admin: extra.adminId ?? this.adminId } : {}),\n ...(extra.decisionId ? { decision_id: extra.decisionId } : {}),\n ...(extra.reason ? { reason: extra.reason } : {}),\n },\n },\n { sign: true },\n );\n return true;\n } catch {\n return false;\n }\n }\n\n async guard<T>(action: EntraAction, run: () => Promise<T>): Promise<{ receipt: EntraReceipt; value?: T }> {\n const auth = await this.authorize(action);\n if (!auth.authorized) {\n const recorded = await this.record(action, 'denied', { reason: auth.reason, outcome: auth.outcome, adminId: auth.adminId, decisionId: auth.decisionId });\n return { receipt: this.receipt(action, false, 'denied', auth, recorded) };\n }\n try {\n const value = await run();\n const recorded = await this.record(action, 'success', { outcome: auth.outcome, adminId: auth.adminId, decisionId: auth.decisionId });\n return { receipt: this.receipt(action, true, 'success', auth, recorded), value };\n } catch (e: any) {\n const recorded = await this.record(action, 'error', { reason: e?.message, outcome: auth.outcome, adminId: auth.adminId, decisionId: auth.decisionId });\n throw Object.assign(e ?? new Error('entra operation failed'), {\n vorimReceipt: this.receipt(action, true, 'error', { ...auth, reason: e?.message }, recorded),\n });\n }\n }\n\n // --- Named helpers ---------------------------------------------------------\n\n /** Guard creating a user (POST /users). Requires agent:write. */\n guardedCreateUser<T>(meta: { targetId?: string; inputHash?: string }, run: () => Promise<T>) {\n return this.guard({ operation: 'createUser', targetId: meta.targetId, inputHash: meta.inputHash }, run);\n }\n\n /** Guard disabling a user (PATCH /users/{id} accountEnabled:false). agent:write. */\n guardedDisableUser<T>(meta: { targetId?: string; inputHash?: string }, run: () => Promise<T>) {\n return this.guard({ operation: 'disableUser', targetId: meta.targetId, inputHash: meta.inputHash }, run);\n }\n\n /** Guard creating an app registration (POST /applications). agent:write. */\n guardedCreateAppRegistration<T>(meta: { targetId?: string; inputHash?: string }, run: () => Promise<T>) {\n return this.guard({ operation: 'createAppRegistration', targetId: meta.targetId, inputHash: meta.inputHash }, run);\n }\n\n /** Guard adding a client secret to an app (POST /applications/{id}/addPassword).\n * Mints a long-lived credential; always escalates to the named admin. */\n guardedAddAppSecret<T>(meta: { targetId?: string; inputHash?: string }, run: () => Promise<T>) {\n return this.guard({ operation: 'addAppSecret', targetId: meta.targetId, inputHash: meta.inputHash }, run);\n }\n\n /** Guard granting an app-role assignment. Always escalates to the named admin\n * (an application-permission grant is tenant-wide privilege). */\n guardedGrantAppRoleAssignment<T>(meta: { targetId?: string; role?: string; inputHash?: string }, run: () => Promise<T>) {\n return this.guard({ operation: 'grantAppRoleAssignment', targetId: meta.targetId, role: meta.role, inputHash: meta.inputHash }, run);\n }\n\n /** Guard assigning a directory role (POST /roleManagement/directory/roleAssignments).\n * Always escalates to the named admin. Pass the role (e.g. 'Global Administrator'). */\n guardedAssignDirectoryRole<T>(meta: { targetId?: string; role?: string; inputHash?: string }, run: () => Promise<T>) {\n return this.guard({ operation: 'assignDirectoryRole', targetId: meta.targetId, role: meta.role, inputHash: meta.inputHash }, run);\n }\n\n private receipt(\n action: EntraAction,\n authorized: boolean,\n result: 'success' | 'denied' | 'error',\n auth: { reason?: string; outcome?: EntraOutcome; adminId?: string; decisionId?: string },\n recorded: boolean,\n ): EntraReceipt {\n return {\n authorized,\n agentId: this.agentId,\n tenantId: this.tenantId,\n operation: action.operation,\n targetId: action.targetId,\n role: action.role,\n privileged: this.isPrivileged(action.operation),\n outcome: auth.outcome ?? 'ordinary',\n adminId: auth.adminId ?? this.adminId,\n result,\n scope: this.scopeFor(action.operation),\n reason: auth.reason,\n decisionId: auth.decisionId,\n recorded,\n };\n }\n}\n\n/**\n * Create a VorimEntra guard around a Vorim SDK instance.\n *\n * @example\n * ```typescript\n * import createVorim from '@vorim/sdk';\n * import { createVorimEntra } from '@vorim/sdk/integrations/entra';\n *\n * const vorim = createVorim({ apiKey: 'agid_sk_...' });\n * const entra = createVorimEntra(vorim, {\n * agentId: 'agid_abc123',\n * tenantId: 'contoso.onmicrosoft.com',\n * adminId: 'admin_42',\n * });\n *\n * const { receipt } = await entra.guardedAssignDirectoryRole(\n * { targetId: 'user_9', role: 'Global Administrator' },\n * () => graphClient.api('/roleManagement/directory/roleAssignments').post(body),\n * );\n * ```\n */\nexport function createVorimEntra(sdk: VorimSDK, config: EntraGuardConfig): VorimEntra {\n return new VorimEntra(sdk, config);\n}\n"],"mappings":";AA2EA,IAAM,iBAAiB,oBAAI,IAAY,CAAC,uBAAuB,gBAAgB,wBAAwB,CAAC;AAExG,IAAM,kBAAmD;AAAA,EACvD,MAAM;AAA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,OAAO,KAAK,SAAS,OAAO,SAAS;AAAA,MACrC,QAAQ,KAAK;AAAA,MACb,YAAY,KAAK;AAAA,MACjB;AAAA,IACF;AAAA,EACF;AACF;AAuBO,SAAS,iBAAiB,KAAe,QAAsC;AACpF,SAAO,IAAI,WAAW,KAAK,MAAM;AACnC;","names":[]}
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/integrations/fhir.ts
|
|
21
|
+
var fhir_exports = {};
|
|
22
|
+
__export(fhir_exports, {
|
|
23
|
+
VorimFhir: () => VorimFhir,
|
|
24
|
+
createVorimFhir: () => createVorimFhir
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(fhir_exports);
|
|
27
|
+
var DEFAULT_ORDER_RESOURCES = ["MedicationRequest", "ServiceRequest"];
|
|
28
|
+
var VorimFhir = class {
|
|
29
|
+
sdk;
|
|
30
|
+
agentId;
|
|
31
|
+
fhirBaseUrl;
|
|
32
|
+
allowedResources;
|
|
33
|
+
readOnly;
|
|
34
|
+
orderResources;
|
|
35
|
+
clinicianId;
|
|
36
|
+
escalateOrders;
|
|
37
|
+
escalationTimeoutMs;
|
|
38
|
+
minTrustScore;
|
|
39
|
+
onError;
|
|
40
|
+
constructor(sdk, config) {
|
|
41
|
+
if (!config?.agentId) throw new Error("[vorim] FHIR integration requires an agentId.");
|
|
42
|
+
if (!config?.fhirBaseUrl) throw new Error("[vorim] FHIR integration requires a fhirBaseUrl.");
|
|
43
|
+
this.sdk = sdk;
|
|
44
|
+
this.agentId = config.agentId;
|
|
45
|
+
this.fhirBaseUrl = config.fhirBaseUrl;
|
|
46
|
+
this.allowedResources = config.allowedResources ? new Set(config.allowedResources) : void 0;
|
|
47
|
+
this.readOnly = config.readOnly ?? false;
|
|
48
|
+
this.orderResources = new Set(config.orderResources ?? DEFAULT_ORDER_RESOURCES);
|
|
49
|
+
this.clinicianId = config.clinicianId;
|
|
50
|
+
this.escalateOrders = config.escalateOrders ?? true;
|
|
51
|
+
this.escalationTimeoutMs = config.escalationTimeoutMs ?? 3e5;
|
|
52
|
+
this.minTrustScore = config.minTrustScore ?? 0;
|
|
53
|
+
this.onError = config.onError ?? "closed";
|
|
54
|
+
}
|
|
55
|
+
isRead(interaction) {
|
|
56
|
+
return interaction === "read";
|
|
57
|
+
}
|
|
58
|
+
isOrder(action) {
|
|
59
|
+
return !this.isRead(action.interaction) && this.orderResources.has(action.resourceType);
|
|
60
|
+
}
|
|
61
|
+
/** The Vorim scope an action requires. Reads need read; order-resource writes
|
|
62
|
+
* are elevated (draft + clinician sign); other writes need write. */
|
|
63
|
+
scopeFor(action) {
|
|
64
|
+
if (this.isRead(action.interaction)) return "agent:read";
|
|
65
|
+
if (this.isOrder(action)) return "agent:elevate";
|
|
66
|
+
return "agent:write";
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Decide whether the acting agent may run this FHIR interaction, before it
|
|
70
|
+
* runs. Order: trust floor, read-only cap, resource-type cap, order gate
|
|
71
|
+
* (escalate to clinician), then permission scope.
|
|
72
|
+
*/
|
|
73
|
+
async authorize(action) {
|
|
74
|
+
const isRead = this.isRead(action.interaction);
|
|
75
|
+
const isOrder = this.isOrder(action);
|
|
76
|
+
const scope = this.scopeFor(action);
|
|
77
|
+
if (!isRead && this.readOnly) {
|
|
78
|
+
return {
|
|
79
|
+
authorized: false,
|
|
80
|
+
reason: "agent is read-only; writes are not permitted",
|
|
81
|
+
orderOutcome: isOrder ? "blocked-read-only" : "not-an-order"
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
if (!isRead && this.allowedResources && !this.allowedResources.has(action.resourceType)) {
|
|
85
|
+
return {
|
|
86
|
+
authorized: false,
|
|
87
|
+
reason: `resource type ${action.resourceType} is not in this agent's allowed set`,
|
|
88
|
+
orderOutcome: isOrder ? "order-denied" : "not-an-order"
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
try {
|
|
92
|
+
if (this.minTrustScore > 0) {
|
|
93
|
+
const trust = await this.sdk.verify(this.agentId);
|
|
94
|
+
if ((trust?.trust_score ?? 0) < this.minTrustScore) {
|
|
95
|
+
return {
|
|
96
|
+
authorized: false,
|
|
97
|
+
reason: `trust score below ${this.minTrustScore}`,
|
|
98
|
+
orderOutcome: isOrder ? "order-denied" : "not-an-order"
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (isOrder) {
|
|
103
|
+
if (!this.escalateOrders) {
|
|
104
|
+
return {
|
|
105
|
+
authorized: false,
|
|
106
|
+
reason: "order resource requires a clinician signature and escalateOrders is off",
|
|
107
|
+
orderOutcome: "order-denied"
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
if (!this.clinicianId) {
|
|
111
|
+
return {
|
|
112
|
+
authorized: false,
|
|
113
|
+
reason: "order resource requires a configured clinicianId (the signing clinician)",
|
|
114
|
+
orderOutcome: "order-denied"
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
const esc = await this.escalate(action, scope);
|
|
118
|
+
return {
|
|
119
|
+
authorized: esc.approved,
|
|
120
|
+
reason: esc.approved ? void 0 : esc.reason ?? "clinician did not sign the order",
|
|
121
|
+
orderOutcome: esc.approved ? "signed-by-clinician" : "order-denied",
|
|
122
|
+
signerId: esc.approved ? this.clinicianId : void 0,
|
|
123
|
+
decisionId: esc.decisionId
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
const perm = await this.sdk.check(this.agentId, scope);
|
|
127
|
+
return perm.allowed ? { authorized: true, orderOutcome: "not-an-order" } : {
|
|
128
|
+
authorized: false,
|
|
129
|
+
reason: perm.reason ?? `missing scope ${scope}`,
|
|
130
|
+
orderOutcome: "not-an-order"
|
|
131
|
+
};
|
|
132
|
+
} catch (e) {
|
|
133
|
+
return this.onError === "open" ? {
|
|
134
|
+
authorized: true,
|
|
135
|
+
reason: "vorim unreachable, failed open",
|
|
136
|
+
orderOutcome: isOrder ? "signed-by-clinician" : "not-an-order"
|
|
137
|
+
} : {
|
|
138
|
+
authorized: false,
|
|
139
|
+
reason: `vorim unreachable: ${e?.message ?? "error"}`,
|
|
140
|
+
orderOutcome: isOrder ? "order-denied" : "not-an-order"
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Route an order-resource write through the runtime decision plane so a
|
|
146
|
+
* clinician can sign (approve) or refuse the unsigned draft, and wait. The
|
|
147
|
+
* elevate scope marks the segregation-of-duties gate: the agent proposes the
|
|
148
|
+
* order, the clinician signs it.
|
|
149
|
+
*/
|
|
150
|
+
async escalate(action, scope) {
|
|
151
|
+
const decision = await this.sdk.beforeAction(
|
|
152
|
+
{
|
|
153
|
+
agentId: this.agentId,
|
|
154
|
+
actionType: "api_request",
|
|
155
|
+
actionTarget: `fhir:${action.interaction}:${action.resourceType}`,
|
|
156
|
+
requiredScope: scope,
|
|
157
|
+
payload: {
|
|
158
|
+
interaction: action.interaction,
|
|
159
|
+
resource_type: action.resourceType,
|
|
160
|
+
resource_id: action.resourceId,
|
|
161
|
+
order_status: "unsigned-draft"
|
|
162
|
+
},
|
|
163
|
+
context: {
|
|
164
|
+
integration: "fhir-r4",
|
|
165
|
+
fhir_base_url: this.fhirBaseUrl,
|
|
166
|
+
requires_clinician_signature: true,
|
|
167
|
+
clinician_hint: this.clinicianId
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
{ throwOnDeny: false }
|
|
171
|
+
);
|
|
172
|
+
if (decision.decision === "escalate") {
|
|
173
|
+
const resolved = await this.sdk.waitForDecisionResolution(decision.decisionId, {
|
|
174
|
+
timeoutMs: this.escalationTimeoutMs
|
|
175
|
+
});
|
|
176
|
+
const approved = resolved.decision === "allow" || resolved.escalationResolution === "approved";
|
|
177
|
+
return {
|
|
178
|
+
approved,
|
|
179
|
+
reason: approved ? void 0 : "clinician refused to sign the order",
|
|
180
|
+
decisionId: decision.decisionId
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
if (decision.decision === "allow") return { approved: true, decisionId: decision.decisionId };
|
|
184
|
+
if (decision.decision === "fallback")
|
|
185
|
+
return { approved: this.onError === "open", reason: "runtime unreachable", decisionId: decision.decisionId };
|
|
186
|
+
return { approved: false, reason: decision.reason ?? "denied", decisionId: decision.decisionId };
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Emit a source-signed audit event for a FHIR write and return whether it was
|
|
190
|
+
* recorded. The event names the agent, the server, the resource type/id, and
|
|
191
|
+
* any clinician signer — attributable and independently verifiable offline,
|
|
192
|
+
* supporting HIPAA §164.312(b) audit controls. It carries NO PHI.
|
|
193
|
+
*/
|
|
194
|
+
async record(action, result, extra = {}) {
|
|
195
|
+
const scope = this.scopeFor(action);
|
|
196
|
+
try {
|
|
197
|
+
await this.sdk.emit(
|
|
198
|
+
{
|
|
199
|
+
agent_id: this.agentId,
|
|
200
|
+
event_type: "api_request",
|
|
201
|
+
action: `fhir:${action.interaction} ${action.resourceType}${action.resourceId ? "/" + action.resourceId : ""}`,
|
|
202
|
+
resource: `${action.resourceType}${action.resourceId ? "/" + action.resourceId : ""}`,
|
|
203
|
+
permission: scope,
|
|
204
|
+
result,
|
|
205
|
+
input_hash: action.inputHash,
|
|
206
|
+
metadata: {
|
|
207
|
+
integration: "fhir-r4",
|
|
208
|
+
fhir_base_url: this.fhirBaseUrl,
|
|
209
|
+
interaction: action.interaction,
|
|
210
|
+
resource_type: action.resourceType,
|
|
211
|
+
is_order: this.isOrder(action),
|
|
212
|
+
...extra.orderOutcome ? { order_outcome: extra.orderOutcome } : {},
|
|
213
|
+
...extra.signerId ? { signed_by_clinician: extra.signerId, signed_at: (/* @__PURE__ */ new Date()).toISOString() } : {},
|
|
214
|
+
...extra.decisionId ? { decision_id: extra.decisionId } : {},
|
|
215
|
+
...extra.reason ? { reason: extra.reason } : {}
|
|
216
|
+
}
|
|
217
|
+
},
|
|
218
|
+
{ sign: true }
|
|
219
|
+
// source-signed: the agent's key signs the record
|
|
220
|
+
);
|
|
221
|
+
return true;
|
|
222
|
+
} catch {
|
|
223
|
+
return false;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* The full flow for one FHIR interaction: authorize (trust, caps, order gate,
|
|
228
|
+
* scope), run the FHIR call if allowed, sign a receipt either way. If not
|
|
229
|
+
* authorized, `run` is never called. Rethrows a FHIR error from `run` after
|
|
230
|
+
* recording it, with the receipt attached as `vorimReceipt`.
|
|
231
|
+
*/
|
|
232
|
+
async guard(action, run) {
|
|
233
|
+
const auth = await this.authorize(action);
|
|
234
|
+
if (!auth.authorized) {
|
|
235
|
+
const recorded = await this.record(action, "denied", {
|
|
236
|
+
reason: auth.reason,
|
|
237
|
+
orderOutcome: auth.orderOutcome,
|
|
238
|
+
signerId: auth.signerId,
|
|
239
|
+
decisionId: auth.decisionId
|
|
240
|
+
});
|
|
241
|
+
return { receipt: this.receipt(action, false, "denied", auth, recorded) };
|
|
242
|
+
}
|
|
243
|
+
try {
|
|
244
|
+
const value = await run();
|
|
245
|
+
const recorded = await this.record(action, "success", {
|
|
246
|
+
orderOutcome: auth.orderOutcome,
|
|
247
|
+
signerId: auth.signerId,
|
|
248
|
+
decisionId: auth.decisionId
|
|
249
|
+
});
|
|
250
|
+
return { receipt: this.receipt(action, true, "success", auth, recorded), value };
|
|
251
|
+
} catch (e) {
|
|
252
|
+
const recorded = await this.record(action, "error", {
|
|
253
|
+
reason: e?.message,
|
|
254
|
+
orderOutcome: auth.orderOutcome,
|
|
255
|
+
signerId: auth.signerId,
|
|
256
|
+
decisionId: auth.decisionId
|
|
257
|
+
});
|
|
258
|
+
throw Object.assign(e ?? new Error("fhir operation failed"), {
|
|
259
|
+
vorimReceipt: this.receipt(action, true, "error", { ...auth, reason: e?.message }, recorded)
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
// --- Named helpers ---------------------------------------------------------
|
|
264
|
+
/** Guard a FHIR `create` (POST [base]/[type]). Requires agent:write, or
|
|
265
|
+
* agent:elevate + a clinician signature for an order resource. */
|
|
266
|
+
guardedCreate(meta, run) {
|
|
267
|
+
return this.guard({ interaction: "create", resourceType: meta.resourceType, resourceId: meta.resourceId, inputHash: meta.inputHash }, run);
|
|
268
|
+
}
|
|
269
|
+
/** Guard a FHIR `update` (PUT [base]/[type]/[id]). */
|
|
270
|
+
guardedUpdate(meta, run) {
|
|
271
|
+
return this.guard({ interaction: "update", resourceType: meta.resourceType, resourceId: meta.resourceId, inputHash: meta.inputHash }, run);
|
|
272
|
+
}
|
|
273
|
+
/** Guard a FHIR `patch` (PATCH [base]/[type]/[id]). */
|
|
274
|
+
guardedPatch(meta, run) {
|
|
275
|
+
return this.guard({ interaction: "patch", resourceType: meta.resourceType, resourceId: meta.resourceId, inputHash: meta.inputHash }, run);
|
|
276
|
+
}
|
|
277
|
+
receipt(action, authorized, result, auth, recorded) {
|
|
278
|
+
return {
|
|
279
|
+
authorized,
|
|
280
|
+
agentId: this.agentId,
|
|
281
|
+
fhirBaseUrl: this.fhirBaseUrl,
|
|
282
|
+
interaction: action.interaction,
|
|
283
|
+
resourceType: action.resourceType,
|
|
284
|
+
resourceId: action.resourceId,
|
|
285
|
+
isOrder: this.isOrder(action),
|
|
286
|
+
orderOutcome: auth.orderOutcome ?? "not-an-order",
|
|
287
|
+
signerId: auth.signerId,
|
|
288
|
+
result,
|
|
289
|
+
scope: this.scopeFor(action),
|
|
290
|
+
reason: auth.reason,
|
|
291
|
+
decisionId: auth.decisionId,
|
|
292
|
+
recorded
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
};
|
|
296
|
+
function createVorimFhir(sdk, config) {
|
|
297
|
+
return new VorimFhir(sdk, config);
|
|
298
|
+
}
|
|
299
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
300
|
+
0 && (module.exports = {
|
|
301
|
+
VorimFhir,
|
|
302
|
+
createVorimFhir
|
|
303
|
+
});
|
|
304
|
+
//# sourceMappingURL=fhir.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/integrations/fhir.ts"],"sourcesContent":["// ============================================================================\n// Vorim AI — Healthcare (HL7 FHIR R4 / SMART on FHIR) Integration\n//\n// This guards an AI agent that writes to an electronic health record through the\n// vendor-neutral HL7 FHIR R4 REST API (the surface Epic, Oracle Health, and any\n// ONC g(10)-certified server share). Before each write runs it checks the acting\n// agent holds the right permission and that the FHIR resource type is within the\n// agent's allowed set; for the highest-stakes orders (a prescription or a lab/\n// imaging order) it forces the write to remain an UNSIGNED draft and escalates\n// to a clinician to sign. Either way it signs a tamper-evident record of which\n// agent proposed which mutation and under what authority.\n//\n// WHY FHIR R4, NOT A VENDOR API\n// R4 (4.0.1) is the ONC-mandated baseline every certified EHR exposes; SMART on\n// FHIR is the shared auth layer. One connector runs against every server —\n// vendor differences (base URL, token URL, scope version) are configuration.\n//\n// ALIGNS WITH THE EHR'S OWN MODEL\n// On Epic, agent-writable orders (MedicationRequest, ServiceRequest) are created\n// as \"Unsigned\" drafts that a human clinician signs; the API deliberately does\n// not let software finalize an order. Vorim's escalate-to-human step matches\n// that draft-then-sign model rather than fighting it, and adds the attributable,\n// cryptographic record of which agent proposed the order — which the base FHIR\n// API and the EHR audit log do not natively provide for autonomous agents.\n//\n// SCOPE MAPPING (uses Vorim's real scopes; mirrors SMART v2 CRUDS)\n// read / search (.r .s) -> agent:read\n// create / update / patch -> agent:write\n// an order that needs a -> agent:elevate (draft + clinician sign;\n// clinician signature segregation of duties)\n//\n// HONEST COMPLIANCE FRAMING\n// HIPAA §164.312(b) audit controls and (c)(2) integrity, and 21 CFR Part 11\n// §11.10(e) audit trails, require tamper-evident, attributable, time-stamped\n// records — which a signed Vorim record satisfies. NEITHER mandates a\n// cryptographic signature as the mechanism. Say \"supports HIPAA §164.312 audit\n// controls and integrity\", never \"required by HIPAA\". A Vorim record is not a\n// Part 11 electronic signature.\n//\n// This layer never holds a SMART token and never calls the FHIR server itself.\n// You pass the write to run; it authorizes, escalates if needed, runs it, signs\n// the receipt.\n//\n// Usage:\n// import createVorim from '@vorim/sdk';\n// import { createVorimFhir } from '@vorim/sdk/integrations/fhir';\n//\n// const vorim = createVorim({ apiKey: 'agid_sk_...' });\n// const fhir = createVorimFhir(vorim, {\n// agentId: 'agid_abc123',\n// fhirBaseUrl: 'https://fhir.epic.com/.../api/FHIR/R4',\n// allowedResources: ['DocumentReference', 'Observation'], // resource-type cap\n// readOnly: false,\n// clinicianId: 'dr_42', // who signs an escalated order\n// });\n//\n// const { receipt, value } = await fhir.guardedCreate(\n// { resourceType: 'Observation', resourceId: 'obs-1' },\n// () => fhirClient.create('Observation', body),\n// );\n// ============================================================================\n\nimport type { VorimSDK } from '../index.js';\nimport type { PermissionScope } from '../types.js';\n\n/** A FHIR REST write interaction. Reads/searches pass through as 'read'. */\nexport type FhirInteraction = 'create' | 'update' | 'patch' | 'transaction' | 'read';\n\n/** The two order resource types that, on real EHRs, must be signed by a\n * clinician — Vorim forces these to a draft and escalates. Any resource can be\n * added to this behaviour via `orderResources`. */\nconst DEFAULT_ORDER_RESOURCES = ['MedicationRequest', 'ServiceRequest'];\n\nexport interface FhirGuardConfig {\n /** The acting agent's Vorim id (agid_...). */\n agentId: string;\n /** The FHIR R4 base URL, e.g. an Epic/Oracle R4 endpoint. Recorded on every\n * receipt so a write is attributable to one server. */\n fhirBaseUrl: string;\n /** Attenuation: restrict this agent to these FHIR resource types. A write to\n * any other type is denied. Omit to allow any type (subject to readOnly). */\n allowedResources?: string[];\n /** Attenuation: cap this agent to read/search only. Any create/update/patch is\n * denied even if the SMART token was over-scoped. Default false. */\n readOnly?: boolean;\n /** Resource types that must be written as an UNSIGNED draft and signed by a\n * clinician (escalation). Defaults to MedicationRequest + ServiceRequest —\n * the order resources EHRs gate this way. */\n orderResources?: string[];\n /** The clinician who signs an escalated order. Required if any order-resource\n * write will be run. Recorded as the signer on the record. */\n clinicianId?: string;\n /** For an order resource, escalate to the clinician and wait for the signature\n * instead of denying. Requires the runtime decision plane. Default true.\n * Ignored when readOnly. */\n escalateOrders?: boolean;\n /** Max time to wait for a clinician signature, ms. Default 300000 (5 min). */\n escalationTimeoutMs?: number;\n /** Minimum trust score the agent must hold before any write. Default 0 (off). */\n minTrustScore?: number;\n /** Fail closed (deny on any Vorim error) or fail open. Default 'closed'. */\n onError?: 'closed' | 'open';\n}\n\nexport interface FhirAction {\n /** The FHIR interaction, e.g. 'create'. Drives the scope. Reads pass as\n * 'read'. Unknown labels are treated as a write. */\n interaction: FhirInteraction | string;\n /** The FHIR resource type, e.g. 'Observation'. Checked against\n * allowedResources and the order-resource set. */\n resourceType: string;\n /** The resource id, when known (update/patch, or the created id). */\n resourceId?: string;\n /** Optional hash of the resource body so the receipt covers the exact input\n * without the guard storing PHI. */\n inputHash?: string;\n}\n\n/** How an order-resource write resolved. */\nexport type OrderOutcome = 'not-an-order' | 'signed-by-clinician' | 'order-denied' | 'blocked-read-only';\n\n/** An offline-verifiable receipt for one FHIR write. Contains no PHI — only the\n * resource type/id, the agent, and the authorization outcome. */\nexport interface FhirReceipt {\n authorized: boolean;\n agentId: string;\n fhirBaseUrl: string;\n interaction: string;\n resourceType: string;\n resourceId?: string;\n /** True when the resource is an order that requires a clinician signature. */\n isOrder: boolean;\n orderOutcome: OrderOutcome;\n /** The clinician who signed, when an order was escalated and signed. */\n signerId?: string;\n result: 'success' | 'denied' | 'error';\n scope: PermissionScope;\n reason?: string;\n decisionId?: string;\n recorded: boolean;\n}\n\nexport class VorimFhir {\n private sdk: VorimSDK;\n private agentId: string;\n private fhirBaseUrl: string;\n private allowedResources?: Set<string>;\n private readOnly: boolean;\n private orderResources: Set<string>;\n private clinicianId?: string;\n private escalateOrders: boolean;\n private escalationTimeoutMs: number;\n private minTrustScore: number;\n private onError: 'closed' | 'open';\n\n constructor(sdk: VorimSDK, config: FhirGuardConfig) {\n if (!config?.agentId) throw new Error('[vorim] FHIR integration requires an agentId.');\n if (!config?.fhirBaseUrl) throw new Error('[vorim] FHIR integration requires a fhirBaseUrl.');\n this.sdk = sdk;\n this.agentId = config.agentId;\n this.fhirBaseUrl = config.fhirBaseUrl;\n this.allowedResources = config.allowedResources ? new Set(config.allowedResources) : undefined;\n this.readOnly = config.readOnly ?? false;\n this.orderResources = new Set(config.orderResources ?? DEFAULT_ORDER_RESOURCES);\n this.clinicianId = config.clinicianId;\n this.escalateOrders = config.escalateOrders ?? true;\n this.escalationTimeoutMs = config.escalationTimeoutMs ?? 300_000;\n this.minTrustScore = config.minTrustScore ?? 0;\n this.onError = config.onError ?? 'closed';\n }\n\n private isRead(interaction: string): boolean {\n return interaction === 'read';\n }\n\n private isOrder(action: FhirAction): boolean {\n return !this.isRead(action.interaction) && this.orderResources.has(action.resourceType);\n }\n\n /** The Vorim scope an action requires. Reads need read; order-resource writes\n * are elevated (draft + clinician sign); other writes need write. */\n private scopeFor(action: FhirAction): PermissionScope {\n if (this.isRead(action.interaction)) return 'agent:read';\n if (this.isOrder(action)) return 'agent:elevate';\n return 'agent:write';\n }\n\n /**\n * Decide whether the acting agent may run this FHIR interaction, before it\n * runs. Order: trust floor, read-only cap, resource-type cap, order gate\n * (escalate to clinician), then permission scope.\n */\n async authorize(\n action: FhirAction,\n ): Promise<{\n authorized: boolean;\n reason?: string;\n orderOutcome: OrderOutcome;\n signerId?: string;\n decisionId?: string;\n }> {\n const isRead = this.isRead(action.interaction);\n const isOrder = this.isOrder(action);\n const scope = this.scopeFor(action);\n\n // Read-only cap: enforced before any Vorim round-trip. A write cannot happen\n // even if the SMART token was over-scoped.\n if (!isRead && this.readOnly) {\n return {\n authorized: false,\n reason: 'agent is read-only; writes are not permitted',\n orderOutcome: isOrder ? 'blocked-read-only' : 'not-an-order',\n };\n }\n // Resource-type cap: also before any round-trip.\n if (!isRead && this.allowedResources && !this.allowedResources.has(action.resourceType)) {\n return {\n authorized: false,\n reason: `resource type ${action.resourceType} is not in this agent's allowed set`,\n orderOutcome: isOrder ? 'order-denied' : 'not-an-order',\n };\n }\n\n try {\n if (this.minTrustScore > 0) {\n const trust = await this.sdk.verify(this.agentId);\n if ((trust?.trust_score ?? 0) < this.minTrustScore) {\n return {\n authorized: false,\n reason: `trust score below ${this.minTrustScore}`,\n orderOutcome: isOrder ? 'order-denied' : 'not-an-order',\n };\n }\n }\n\n if (isOrder) {\n if (!this.escalateOrders) {\n return {\n authorized: false,\n reason: 'order resource requires a clinician signature and escalateOrders is off',\n orderOutcome: 'order-denied',\n };\n }\n if (!this.clinicianId) {\n return {\n authorized: false,\n reason: 'order resource requires a configured clinicianId (the signing clinician)',\n orderOutcome: 'order-denied',\n };\n }\n const esc = await this.escalate(action, scope);\n return {\n authorized: esc.approved,\n reason: esc.approved ? undefined : (esc.reason ?? 'clinician did not sign the order'),\n orderOutcome: esc.approved ? 'signed-by-clinician' : 'order-denied',\n signerId: esc.approved ? this.clinicianId : undefined,\n decisionId: esc.decisionId,\n };\n }\n\n const perm = await this.sdk.check(this.agentId, scope);\n return perm.allowed\n ? { authorized: true, orderOutcome: 'not-an-order' }\n : {\n authorized: false,\n reason: perm.reason ?? `missing scope ${scope}`,\n orderOutcome: 'not-an-order',\n };\n } catch (e: any) {\n return this.onError === 'open'\n ? {\n authorized: true,\n reason: 'vorim unreachable, failed open',\n orderOutcome: isOrder ? 'signed-by-clinician' : 'not-an-order',\n }\n : {\n authorized: false,\n reason: `vorim unreachable: ${e?.message ?? 'error'}`,\n orderOutcome: isOrder ? 'order-denied' : 'not-an-order',\n };\n }\n }\n\n /**\n * Route an order-resource write through the runtime decision plane so a\n * clinician can sign (approve) or refuse the unsigned draft, and wait. The\n * elevate scope marks the segregation-of-duties gate: the agent proposes the\n * order, the clinician signs it.\n */\n private async escalate(\n action: FhirAction,\n scope: PermissionScope,\n ): Promise<{ approved: boolean; reason?: string; decisionId?: string }> {\n const decision = await this.sdk.beforeAction(\n {\n agentId: this.agentId,\n actionType: 'api_request',\n actionTarget: `fhir:${action.interaction}:${action.resourceType}`,\n requiredScope: scope,\n payload: {\n interaction: action.interaction,\n resource_type: action.resourceType,\n resource_id: action.resourceId,\n order_status: 'unsigned-draft',\n },\n context: {\n integration: 'fhir-r4',\n fhir_base_url: this.fhirBaseUrl,\n requires_clinician_signature: true,\n clinician_hint: this.clinicianId,\n },\n },\n { throwOnDeny: false },\n );\n\n if (decision.decision === 'escalate') {\n const resolved = await this.sdk.waitForDecisionResolution(decision.decisionId, {\n timeoutMs: this.escalationTimeoutMs,\n });\n const approved = resolved.decision === 'allow' || resolved.escalationResolution === 'approved';\n return {\n approved,\n reason: approved ? undefined : 'clinician refused to sign the order',\n decisionId: decision.decisionId,\n };\n }\n if (decision.decision === 'allow') return { approved: true, decisionId: decision.decisionId };\n if (decision.decision === 'fallback')\n return { approved: this.onError === 'open', reason: 'runtime unreachable', decisionId: decision.decisionId };\n return { approved: false, reason: decision.reason ?? 'denied', decisionId: decision.decisionId };\n }\n\n /**\n * Emit a source-signed audit event for a FHIR write and return whether it was\n * recorded. The event names the agent, the server, the resource type/id, and\n * any clinician signer — attributable and independently verifiable offline,\n * supporting HIPAA §164.312(b) audit controls. It carries NO PHI.\n */\n async record(\n action: FhirAction,\n result: 'success' | 'denied' | 'error',\n extra: { reason?: string; orderOutcome?: OrderOutcome; signerId?: string; decisionId?: string } = {},\n ): Promise<boolean> {\n const scope = this.scopeFor(action);\n try {\n await this.sdk.emit(\n {\n agent_id: this.agentId,\n event_type: 'api_request',\n action: `fhir:${action.interaction} ${action.resourceType}${action.resourceId ? '/' + action.resourceId : ''}`,\n resource: `${action.resourceType}${action.resourceId ? '/' + action.resourceId : ''}`,\n permission: scope,\n result,\n input_hash: action.inputHash,\n metadata: {\n integration: 'fhir-r4',\n fhir_base_url: this.fhirBaseUrl,\n interaction: action.interaction,\n resource_type: action.resourceType,\n is_order: this.isOrder(action),\n ...(extra.orderOutcome ? { order_outcome: extra.orderOutcome } : {}),\n ...(extra.signerId ? { signed_by_clinician: extra.signerId, signed_at: new Date().toISOString() } : {}),\n ...(extra.decisionId ? { decision_id: extra.decisionId } : {}),\n ...(extra.reason ? { reason: extra.reason } : {}),\n },\n },\n { sign: true }, // source-signed: the agent's key signs the record\n );\n return true;\n } catch {\n return false;\n }\n }\n\n /**\n * The full flow for one FHIR interaction: authorize (trust, caps, order gate,\n * scope), run the FHIR call if allowed, sign a receipt either way. If not\n * authorized, `run` is never called. Rethrows a FHIR error from `run` after\n * recording it, with the receipt attached as `vorimReceipt`.\n */\n async guard<T>(action: FhirAction, run: () => Promise<T>): Promise<{ receipt: FhirReceipt; value?: T }> {\n const auth = await this.authorize(action);\n if (!auth.authorized) {\n const recorded = await this.record(action, 'denied', {\n reason: auth.reason,\n orderOutcome: auth.orderOutcome,\n signerId: auth.signerId,\n decisionId: auth.decisionId,\n });\n return { receipt: this.receipt(action, false, 'denied', auth, recorded) };\n }\n try {\n const value = await run();\n const recorded = await this.record(action, 'success', {\n orderOutcome: auth.orderOutcome,\n signerId: auth.signerId,\n decisionId: auth.decisionId,\n });\n return { receipt: this.receipt(action, true, 'success', auth, recorded), value };\n } catch (e: any) {\n const recorded = await this.record(action, 'error', {\n reason: e?.message,\n orderOutcome: auth.orderOutcome,\n signerId: auth.signerId,\n decisionId: auth.decisionId,\n });\n throw Object.assign(e ?? new Error('fhir operation failed'), {\n vorimReceipt: this.receipt(action, true, 'error', { ...auth, reason: e?.message }, recorded),\n });\n }\n }\n\n // --- Named helpers ---------------------------------------------------------\n\n /** Guard a FHIR `create` (POST [base]/[type]). Requires agent:write, or\n * agent:elevate + a clinician signature for an order resource. */\n guardedCreate<T>(meta: { resourceType: string; resourceId?: string; inputHash?: string }, run: () => Promise<T>) {\n return this.guard({ interaction: 'create', resourceType: meta.resourceType, resourceId: meta.resourceId, inputHash: meta.inputHash }, run);\n }\n\n /** Guard a FHIR `update` (PUT [base]/[type]/[id]). */\n guardedUpdate<T>(meta: { resourceType: string; resourceId?: string; inputHash?: string }, run: () => Promise<T>) {\n return this.guard({ interaction: 'update', resourceType: meta.resourceType, resourceId: meta.resourceId, inputHash: meta.inputHash }, run);\n }\n\n /** Guard a FHIR `patch` (PATCH [base]/[type]/[id]). */\n guardedPatch<T>(meta: { resourceType: string; resourceId?: string; inputHash?: string }, run: () => Promise<T>) {\n return this.guard({ interaction: 'patch', resourceType: meta.resourceType, resourceId: meta.resourceId, inputHash: meta.inputHash }, run);\n }\n\n private receipt(\n action: FhirAction,\n authorized: boolean,\n result: 'success' | 'denied' | 'error',\n auth: { reason?: string; orderOutcome?: OrderOutcome; signerId?: string; decisionId?: string },\n recorded: boolean,\n ): FhirReceipt {\n return {\n authorized,\n agentId: this.agentId,\n fhirBaseUrl: this.fhirBaseUrl,\n interaction: action.interaction,\n resourceType: action.resourceType,\n resourceId: action.resourceId,\n isOrder: this.isOrder(action),\n orderOutcome: auth.orderOutcome ?? 'not-an-order',\n signerId: auth.signerId,\n result,\n scope: this.scopeFor(action),\n reason: auth.reason,\n decisionId: auth.decisionId,\n recorded,\n };\n }\n}\n\n/**\n * Create a VorimFhir guard around a Vorim SDK instance.\n *\n * @example\n * ```typescript\n * import createVorim from '@vorim/sdk';\n * import { createVorimFhir } from '@vorim/sdk/integrations/fhir';\n *\n * const vorim = createVorim({ apiKey: 'agid_sk_...' });\n * const fhir = createVorimFhir(vorim, {\n * agentId: 'agid_abc123',\n * fhirBaseUrl: 'https://fhir.epic.com/interconnect-fhir-oauth/api/FHIR/R4',\n * allowedResources: ['DocumentReference', 'Observation'],\n * clinicianId: 'dr_42',\n * });\n *\n * // An order resource forces a draft + clinician signature:\n * const { receipt } = await fhir.guardedCreate(\n * { resourceType: 'MedicationRequest' },\n * () => fhirClient.create('MedicationRequest', unsignedDraft),\n * );\n * ```\n */\nexport function createVorimFhir(sdk: VorimSDK, config: FhirGuardConfig): VorimFhir {\n return new VorimFhir(sdk, config);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAuEA,IAAM,0BAA0B,CAAC,qBAAqB,gBAAgB;AAuE/D,IAAM,YAAN,MAAgB;AAAA,EACb;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAER,YAAY,KAAe,QAAyB;AAClD,QAAI,CAAC,QAAQ,QAAS,OAAM,IAAI,MAAM,+CAA+C;AACrF,QAAI,CAAC,QAAQ,YAAa,OAAM,IAAI,MAAM,kDAAkD;AAC5F,SAAK,MAAM;AACX,SAAK,UAAU,OAAO;AACtB,SAAK,cAAc,OAAO;AAC1B,SAAK,mBAAmB,OAAO,mBAAmB,IAAI,IAAI,OAAO,gBAAgB,IAAI;AACrF,SAAK,WAAW,OAAO,YAAY;AACnC,SAAK,iBAAiB,IAAI,IAAI,OAAO,kBAAkB,uBAAuB;AAC9E,SAAK,cAAc,OAAO;AAC1B,SAAK,iBAAiB,OAAO,kBAAkB;AAC/C,SAAK,sBAAsB,OAAO,uBAAuB;AACzD,SAAK,gBAAgB,OAA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