@vorim/sdk 3.12.0 → 3.15.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 +1 -1
- package/dist/index.js +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/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/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/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/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/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/package.json +91 -1
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import { VorimSDK } from '../index.js';
|
|
2
|
+
import { P as PermissionScope } from '../types-zzK9YOoa.js';
|
|
3
|
+
|
|
4
|
+
/** Which validated system this guard fronts. Configuration, not separate code
|
|
5
|
+
* paths. */
|
|
6
|
+
type LifeSciencesSystem = 'benchling' | 'veeva';
|
|
7
|
+
/** The mutations this guard classifies. Draft/write operations require write;
|
|
8
|
+
* release/approve/lifecycle-to-effective are escalation-gated to a human of
|
|
9
|
+
* record. Any other label defaults to the 'write' tier. */
|
|
10
|
+
type LifeSciencesOperation = 'register-entity' | 'create-entry' | 'create-result' | 'update-entity' | 'create-document' | 'update-document' | 'lifecycle-change' | 'read';
|
|
11
|
+
/** The §11.50(a)(3) meaning associated with a human signature on a record. */
|
|
12
|
+
type SignatureMeaning = 'authorship' | 'review' | 'approval' | 'responsibility';
|
|
13
|
+
interface LifeSciencesGuardConfig {
|
|
14
|
+
/** The acting agent's Vorim id (agid_...). */
|
|
15
|
+
agentId: string;
|
|
16
|
+
/** Which validated system this guard fronts. */
|
|
17
|
+
system: LifeSciencesSystem;
|
|
18
|
+
/** The tenant / vault, e.g. 'acme.benchling.com' or 'acme.veevavault.com'.
|
|
19
|
+
* Recorded on every receipt so an action is attributable to one instance. */
|
|
20
|
+
tenant: string;
|
|
21
|
+
/** The human of record — the Part 11 signatory for any release/approval. Used
|
|
22
|
+
* as the named approver on escalation and recorded as the signer. Required if
|
|
23
|
+
* any release-class action will be run. */
|
|
24
|
+
humanOfRecordId?: string;
|
|
25
|
+
/** Minimum trust score the acting agent must hold before any mutation runs.
|
|
26
|
+
* Default 0 (off). */
|
|
27
|
+
minTrustScore?: number;
|
|
28
|
+
/** Attenuation: cap this agent to draft/write only. Any release-class action
|
|
29
|
+
* (result release, effective lifecycle transition, approval) is denied
|
|
30
|
+
* outright rather than escalated. Default false. */
|
|
31
|
+
draftOnly?: boolean;
|
|
32
|
+
/** For a release-class action, escalate to the human of record and wait for
|
|
33
|
+
* their signature instead of denying. Requires the runtime decision plane.
|
|
34
|
+
* Default true (a release without a human is the thing we exist to prevent).
|
|
35
|
+
* Ignored when draftOnly is set. */
|
|
36
|
+
escalateOnRelease?: boolean;
|
|
37
|
+
/** Max time to wait for an escalation decision, ms. Default 300000 (5 min —
|
|
38
|
+
* a human sign-off, not a machine call). */
|
|
39
|
+
escalationTimeoutMs?: number;
|
|
40
|
+
/** Fail closed (deny on any Vorim error) or fail open. Default 'closed'. */
|
|
41
|
+
onError?: 'closed' | 'open';
|
|
42
|
+
}
|
|
43
|
+
interface LifeSciencesAction {
|
|
44
|
+
/** The REST operation being run, e.g. 'register-entity'. Drives the scope and
|
|
45
|
+
* whether the action is release-class. Unknown labels default to write. */
|
|
46
|
+
operation: LifeSciencesOperation | string;
|
|
47
|
+
/** The entity / entry / document id the action targets. */
|
|
48
|
+
resourceId?: string;
|
|
49
|
+
/** The §11.50 meaning of the human signature, when this action is approved by
|
|
50
|
+
* the human of record. Defaults to 'authorship' for writes, 'approval' for
|
|
51
|
+
* release-class actions. */
|
|
52
|
+
meaning?: SignatureMeaning;
|
|
53
|
+
/** For a Veeva 'lifecycle-change': the per-Vault action name, discovered at
|
|
54
|
+
* runtime by the caller (never hard-coded here). Recorded for the audit. */
|
|
55
|
+
lifecycleAction?: string;
|
|
56
|
+
/** For a Veeva 'lifecycle-change': set true when the transition makes the
|
|
57
|
+
* record effective/approved (release-class → requires the human of record).
|
|
58
|
+
* A Draft→In Review move leaves this false. */
|
|
59
|
+
isEffectiveTransition?: boolean;
|
|
60
|
+
/** Optional hash of the request body so the receipt covers the exact input
|
|
61
|
+
* without the guard storing it. */
|
|
62
|
+
inputHash?: string;
|
|
63
|
+
}
|
|
64
|
+
/** How a release-class action resolved. */
|
|
65
|
+
type ReleaseOutcome = 'not-release-class' | 'signed-by-human' | 'release-denied' | 'draft-only-blocked';
|
|
66
|
+
/** An offline-verifiable receipt for one life-sciences mutation. Carries the
|
|
67
|
+
* Part 11 §11.50 manifestation when a human of record signed. */
|
|
68
|
+
interface LifeSciencesReceipt {
|
|
69
|
+
authorized: boolean;
|
|
70
|
+
agentId: string;
|
|
71
|
+
system: LifeSciencesSystem;
|
|
72
|
+
tenant: string;
|
|
73
|
+
operation: string;
|
|
74
|
+
resourceId?: string;
|
|
75
|
+
/** True when this operation releases/approves/finalizes a record. */
|
|
76
|
+
releaseClass: boolean;
|
|
77
|
+
releaseOutcome: ReleaseOutcome;
|
|
78
|
+
/** The §11.50 manifestation, present when a human of record signed. */
|
|
79
|
+
signature?: {
|
|
80
|
+
signerId: string;
|
|
81
|
+
meaning: SignatureMeaning;
|
|
82
|
+
};
|
|
83
|
+
result: 'success' | 'denied' | 'error';
|
|
84
|
+
scope: PermissionScope;
|
|
85
|
+
reason?: string;
|
|
86
|
+
decisionId?: string;
|
|
87
|
+
recorded: boolean;
|
|
88
|
+
}
|
|
89
|
+
declare class VorimLifeSciences {
|
|
90
|
+
private sdk;
|
|
91
|
+
private agentId;
|
|
92
|
+
private system;
|
|
93
|
+
private tenant;
|
|
94
|
+
private humanOfRecordId?;
|
|
95
|
+
private minTrustScore;
|
|
96
|
+
private draftOnly;
|
|
97
|
+
private escalateOnRelease;
|
|
98
|
+
private escalationTimeoutMs;
|
|
99
|
+
private onError;
|
|
100
|
+
constructor(sdk: VorimSDK, config: LifeSciencesGuardConfig);
|
|
101
|
+
/** Whether an action releases/approves/finalizes a record (needs the human of
|
|
102
|
+
* record). A lifecycle-change counts only when the caller marks it an
|
|
103
|
+
* effective transition. */
|
|
104
|
+
private isReleaseClass;
|
|
105
|
+
/** The Vorim scope an operation requires. A release-class lifecycle-change is
|
|
106
|
+
* elevated even though the base op maps to write. */
|
|
107
|
+
private scopeFor;
|
|
108
|
+
private meaningFor;
|
|
109
|
+
/**
|
|
110
|
+
* Decide whether the acting agent may run this action, before it runs. Order:
|
|
111
|
+
* trust floor, then the release gate (draft-only block, or escalate to the
|
|
112
|
+
* human of record), then permission scope for plain writes.
|
|
113
|
+
*/
|
|
114
|
+
authorize(action: LifeSciencesAction): Promise<{
|
|
115
|
+
authorized: boolean;
|
|
116
|
+
reason?: string;
|
|
117
|
+
releaseOutcome: ReleaseOutcome;
|
|
118
|
+
signerId?: string;
|
|
119
|
+
decisionId?: string;
|
|
120
|
+
}>;
|
|
121
|
+
/**
|
|
122
|
+
* Route a release-class action through the runtime decision plane so the named
|
|
123
|
+
* human of record can sign (approve) or refuse, and wait for that decision.
|
|
124
|
+
* The elevate scope marks this as the segregation-of-duties gate: the agent
|
|
125
|
+
* that drafted the record cannot also be its Part 11 signatory.
|
|
126
|
+
*/
|
|
127
|
+
private escalate;
|
|
128
|
+
/**
|
|
129
|
+
* Emit a source-signed audit event for a mutation and return whether it was
|
|
130
|
+
* recorded. When a human of record signed a release-class action, the event
|
|
131
|
+
* carries the Part 11 §11.50 manifestation: signer id, timestamp (server), and
|
|
132
|
+
* the meaning of the signature — an independent, offline-verifiable record
|
|
133
|
+
* beside the validated system's own controls.
|
|
134
|
+
*/
|
|
135
|
+
record(action: LifeSciencesAction, result: 'success' | 'denied' | 'error', extra?: {
|
|
136
|
+
reason?: string;
|
|
137
|
+
releaseOutcome?: ReleaseOutcome;
|
|
138
|
+
signerId?: string;
|
|
139
|
+
decisionId?: string;
|
|
140
|
+
}): Promise<boolean>;
|
|
141
|
+
/**
|
|
142
|
+
* The full flow for one mutation: authorize (trust, release gate, scope), run
|
|
143
|
+
* the REST call if allowed, sign a receipt either way. If not authorized, `run`
|
|
144
|
+
* is never called. Rethrows a system error from `run` after recording it, with
|
|
145
|
+
* the receipt attached as `vorimReceipt`.
|
|
146
|
+
*/
|
|
147
|
+
guard<T>(action: LifeSciencesAction, run: () => Promise<T>): Promise<{
|
|
148
|
+
receipt: LifeSciencesReceipt;
|
|
149
|
+
value?: T;
|
|
150
|
+
}>;
|
|
151
|
+
/** Guard a Benchling entity/registry/ELN write, or a result release. Pass the
|
|
152
|
+
* operation ('register-entity' | 'create-entry' | 'create-result' |
|
|
153
|
+
* 'update-entity'). A 'create-result' is release-class (needs the human of
|
|
154
|
+
* record). */
|
|
155
|
+
guardedEntityWrite<T>(meta: {
|
|
156
|
+
operation: LifeSciencesOperation | string;
|
|
157
|
+
resourceId?: string;
|
|
158
|
+
meaning?: SignatureMeaning;
|
|
159
|
+
inputHash?: string;
|
|
160
|
+
}, run: () => Promise<T>): Promise<{
|
|
161
|
+
receipt: LifeSciencesReceipt;
|
|
162
|
+
value?: T | undefined;
|
|
163
|
+
}>;
|
|
164
|
+
/** Guard a Veeva Vault document lifecycle transition. `lifecycleAction` is the
|
|
165
|
+
* per-Vault action name (discover it at runtime). Set `isEffectiveTransition`
|
|
166
|
+
* when the move makes the record effective/approved — that makes it
|
|
167
|
+
* release-class and routes it to the human of record. */
|
|
168
|
+
guardedLifecycleChange<T>(meta: {
|
|
169
|
+
documentId?: string;
|
|
170
|
+
lifecycleAction?: string;
|
|
171
|
+
isEffectiveTransition?: boolean;
|
|
172
|
+
meaning?: SignatureMeaning;
|
|
173
|
+
inputHash?: string;
|
|
174
|
+
}, run: () => Promise<T>): Promise<{
|
|
175
|
+
receipt: LifeSciencesReceipt;
|
|
176
|
+
value?: T | undefined;
|
|
177
|
+
}>;
|
|
178
|
+
/** Guard a Veeva Vault document create/update. Requires agent:write. */
|
|
179
|
+
guardedDocumentWrite<T>(meta: {
|
|
180
|
+
operation?: 'create-document' | 'update-document';
|
|
181
|
+
documentId?: string;
|
|
182
|
+
inputHash?: string;
|
|
183
|
+
}, run: () => Promise<T>): Promise<{
|
|
184
|
+
receipt: LifeSciencesReceipt;
|
|
185
|
+
value?: T | undefined;
|
|
186
|
+
}>;
|
|
187
|
+
private receipt;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Create a VorimLifeSciences guard around a Vorim SDK instance.
|
|
191
|
+
*
|
|
192
|
+
* @example
|
|
193
|
+
* ```typescript
|
|
194
|
+
* import createVorim from '@vorim/sdk';
|
|
195
|
+
* import { createVorimLifeSciences } from '@vorim/sdk/integrations/life-sciences';
|
|
196
|
+
*
|
|
197
|
+
* const vorim = createVorim({ apiKey: 'agid_sk_...' });
|
|
198
|
+
* const ls = createVorimLifeSciences(vorim, {
|
|
199
|
+
* agentId: 'agid_abc123',
|
|
200
|
+
* system: 'veeva',
|
|
201
|
+
* tenant: 'acme.veevavault.com',
|
|
202
|
+
* humanOfRecordId: 'qa_lead_7', // the Part 11 signer for approvals
|
|
203
|
+
* });
|
|
204
|
+
*
|
|
205
|
+
* // An effective lifecycle transition escalates to the human of record:
|
|
206
|
+
* const { receipt, value } = await ls.guardedLifecycleChange(
|
|
207
|
+
* { documentId: 'doc_42', lifecycleAction: 'approve__c', isEffectiveTransition: true, meaning: 'approval' },
|
|
208
|
+
* () => vault.post('/api/v26.1/objects/documents/doc_42/lifecycle_actions/approve__c'),
|
|
209
|
+
* );
|
|
210
|
+
* ```
|
|
211
|
+
*/
|
|
212
|
+
declare function createVorimLifeSciences(sdk: VorimSDK, config: LifeSciencesGuardConfig): VorimLifeSciences;
|
|
213
|
+
|
|
214
|
+
export { type LifeSciencesAction, type LifeSciencesGuardConfig, type LifeSciencesOperation, type LifeSciencesReceipt, type LifeSciencesSystem, type ReleaseOutcome, type SignatureMeaning, VorimLifeSciences, createVorimLifeSciences };
|
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
// src/integrations/life-sciences.ts
|
|
2
|
+
var RELEASE_CLASS = /* @__PURE__ */ new Set(["create-result"]);
|
|
3
|
+
var OPERATION_SCOPE = {
|
|
4
|
+
read: "agent:read",
|
|
5
|
+
"register-entity": "agent:write",
|
|
6
|
+
"create-entry": "agent:write",
|
|
7
|
+
"update-entity": "agent:write",
|
|
8
|
+
"create-document": "agent:write",
|
|
9
|
+
"update-document": "agent:write",
|
|
10
|
+
"create-result": "agent:elevate",
|
|
11
|
+
"lifecycle-change": "agent:write"
|
|
12
|
+
// elevated only for an effective transition
|
|
13
|
+
};
|
|
14
|
+
var VorimLifeSciences = class {
|
|
15
|
+
sdk;
|
|
16
|
+
agentId;
|
|
17
|
+
system;
|
|
18
|
+
tenant;
|
|
19
|
+
humanOfRecordId;
|
|
20
|
+
minTrustScore;
|
|
21
|
+
draftOnly;
|
|
22
|
+
escalateOnRelease;
|
|
23
|
+
escalationTimeoutMs;
|
|
24
|
+
onError;
|
|
25
|
+
constructor(sdk, config) {
|
|
26
|
+
if (!config?.agentId) throw new Error("[vorim] Life sciences integration requires an agentId.");
|
|
27
|
+
if (!config?.system) throw new Error("[vorim] Life sciences integration requires a system.");
|
|
28
|
+
if (!config?.tenant) throw new Error("[vorim] Life sciences integration requires a tenant.");
|
|
29
|
+
this.sdk = sdk;
|
|
30
|
+
this.agentId = config.agentId;
|
|
31
|
+
this.system = config.system;
|
|
32
|
+
this.tenant = config.tenant;
|
|
33
|
+
this.humanOfRecordId = config.humanOfRecordId;
|
|
34
|
+
this.minTrustScore = config.minTrustScore ?? 0;
|
|
35
|
+
this.draftOnly = config.draftOnly ?? false;
|
|
36
|
+
this.escalateOnRelease = config.escalateOnRelease ?? true;
|
|
37
|
+
this.escalationTimeoutMs = config.escalationTimeoutMs ?? 3e5;
|
|
38
|
+
this.onError = config.onError ?? "closed";
|
|
39
|
+
}
|
|
40
|
+
/** Whether an action releases/approves/finalizes a record (needs the human of
|
|
41
|
+
* record). A lifecycle-change counts only when the caller marks it an
|
|
42
|
+
* effective transition. */
|
|
43
|
+
isReleaseClass(action) {
|
|
44
|
+
if (action.operation === "lifecycle-change") return action.isEffectiveTransition === true;
|
|
45
|
+
return RELEASE_CLASS.has(action.operation);
|
|
46
|
+
}
|
|
47
|
+
/** The Vorim scope an operation requires. A release-class lifecycle-change is
|
|
48
|
+
* elevated even though the base op maps to write. */
|
|
49
|
+
scopeFor(action) {
|
|
50
|
+
if (this.isReleaseClass(action)) return "agent:elevate";
|
|
51
|
+
return OPERATION_SCOPE[action.operation] ?? "agent:write";
|
|
52
|
+
}
|
|
53
|
+
meaningFor(action) {
|
|
54
|
+
return action.meaning ?? (this.isReleaseClass(action) ? "approval" : "authorship");
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Decide whether the acting agent may run this action, before it runs. Order:
|
|
58
|
+
* trust floor, then the release gate (draft-only block, or escalate to the
|
|
59
|
+
* human of record), then permission scope for plain writes.
|
|
60
|
+
*/
|
|
61
|
+
async authorize(action) {
|
|
62
|
+
const releaseClass = this.isReleaseClass(action);
|
|
63
|
+
const scope = this.scopeFor(action);
|
|
64
|
+
try {
|
|
65
|
+
if (this.minTrustScore > 0) {
|
|
66
|
+
const trust = await this.sdk.verify(this.agentId);
|
|
67
|
+
if ((trust?.trust_score ?? 0) < this.minTrustScore) {
|
|
68
|
+
return {
|
|
69
|
+
authorized: false,
|
|
70
|
+
reason: `trust score below ${this.minTrustScore}`,
|
|
71
|
+
releaseOutcome: releaseClass ? "release-denied" : "not-release-class"
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (releaseClass) {
|
|
76
|
+
if (this.draftOnly) {
|
|
77
|
+
return {
|
|
78
|
+
authorized: false,
|
|
79
|
+
reason: "agent is draft-only; release/approval requires a human of record",
|
|
80
|
+
releaseOutcome: "draft-only-blocked"
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
if (!this.escalateOnRelease) {
|
|
84
|
+
return {
|
|
85
|
+
authorized: false,
|
|
86
|
+
reason: "release requires a human of record and escalateOnRelease is off",
|
|
87
|
+
releaseOutcome: "release-denied"
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
if (!this.humanOfRecordId) {
|
|
91
|
+
return {
|
|
92
|
+
authorized: false,
|
|
93
|
+
reason: "release-class action requires a configured humanOfRecordId (the Part 11 signer)",
|
|
94
|
+
releaseOutcome: "release-denied"
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
const esc = await this.escalate(action, scope);
|
|
98
|
+
return {
|
|
99
|
+
authorized: esc.approved,
|
|
100
|
+
reason: esc.approved ? void 0 : esc.reason ?? "human of record did not sign",
|
|
101
|
+
releaseOutcome: esc.approved ? "signed-by-human" : "release-denied",
|
|
102
|
+
signerId: esc.approved ? this.humanOfRecordId : void 0,
|
|
103
|
+
decisionId: esc.decisionId
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
const perm = await this.sdk.check(this.agentId, scope);
|
|
107
|
+
return perm.allowed ? { authorized: true, releaseOutcome: "not-release-class" } : {
|
|
108
|
+
authorized: false,
|
|
109
|
+
reason: perm.reason ?? `missing scope ${scope}`,
|
|
110
|
+
releaseOutcome: "not-release-class"
|
|
111
|
+
};
|
|
112
|
+
} catch (e) {
|
|
113
|
+
return this.onError === "open" ? {
|
|
114
|
+
authorized: true,
|
|
115
|
+
reason: "vorim unreachable, failed open",
|
|
116
|
+
releaseOutcome: releaseClass ? "signed-by-human" : "not-release-class"
|
|
117
|
+
} : {
|
|
118
|
+
authorized: false,
|
|
119
|
+
reason: `vorim unreachable: ${e?.message ?? "error"}`,
|
|
120
|
+
releaseOutcome: releaseClass ? "release-denied" : "not-release-class"
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Route a release-class action through the runtime decision plane so the named
|
|
126
|
+
* human of record can sign (approve) or refuse, and wait for that decision.
|
|
127
|
+
* The elevate scope marks this as the segregation-of-duties gate: the agent
|
|
128
|
+
* that drafted the record cannot also be its Part 11 signatory.
|
|
129
|
+
*/
|
|
130
|
+
async escalate(action, scope) {
|
|
131
|
+
const decision = await this.sdk.beforeAction(
|
|
132
|
+
{
|
|
133
|
+
agentId: this.agentId,
|
|
134
|
+
actionType: "api_request",
|
|
135
|
+
actionTarget: `${this.system}:${action.operation}`,
|
|
136
|
+
requiredScope: scope,
|
|
137
|
+
payload: {
|
|
138
|
+
operation: action.operation,
|
|
139
|
+
resource_id: action.resourceId,
|
|
140
|
+
lifecycle_action: action.lifecycleAction,
|
|
141
|
+
meaning: this.meaningFor(action)
|
|
142
|
+
},
|
|
143
|
+
context: {
|
|
144
|
+
integration: `${this.system}-life-sciences`,
|
|
145
|
+
tenant: this.tenant,
|
|
146
|
+
requires_human_of_record: true,
|
|
147
|
+
signer_hint: this.humanOfRecordId,
|
|
148
|
+
part11_manifestation: true
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
{ throwOnDeny: false }
|
|
152
|
+
);
|
|
153
|
+
if (decision.decision === "escalate") {
|
|
154
|
+
const resolved = await this.sdk.waitForDecisionResolution(decision.decisionId, {
|
|
155
|
+
timeoutMs: this.escalationTimeoutMs
|
|
156
|
+
});
|
|
157
|
+
const approved = resolved.decision === "allow" || resolved.escalationResolution === "approved";
|
|
158
|
+
return {
|
|
159
|
+
approved,
|
|
160
|
+
reason: approved ? void 0 : "human of record refused to sign",
|
|
161
|
+
decisionId: decision.decisionId
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
if (decision.decision === "allow") return { approved: true, decisionId: decision.decisionId };
|
|
165
|
+
if (decision.decision === "fallback")
|
|
166
|
+
return { approved: this.onError === "open", reason: "runtime unreachable", decisionId: decision.decisionId };
|
|
167
|
+
return { approved: false, reason: decision.reason ?? "denied", decisionId: decision.decisionId };
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Emit a source-signed audit event for a mutation and return whether it was
|
|
171
|
+
* recorded. When a human of record signed a release-class action, the event
|
|
172
|
+
* carries the Part 11 §11.50 manifestation: signer id, timestamp (server), and
|
|
173
|
+
* the meaning of the signature — an independent, offline-verifiable record
|
|
174
|
+
* beside the validated system's own controls.
|
|
175
|
+
*/
|
|
176
|
+
async record(action, result, extra = {}) {
|
|
177
|
+
const scope = this.scopeFor(action);
|
|
178
|
+
const meaning = this.meaningFor(action);
|
|
179
|
+
try {
|
|
180
|
+
await this.sdk.emit(
|
|
181
|
+
{
|
|
182
|
+
agent_id: this.agentId,
|
|
183
|
+
event_type: "api_request",
|
|
184
|
+
action: `${this.system}:${action.operation}${action.resourceId ? " " + action.resourceId : ""}`,
|
|
185
|
+
resource: action.resourceId || this.tenant,
|
|
186
|
+
permission: scope,
|
|
187
|
+
result,
|
|
188
|
+
input_hash: action.inputHash,
|
|
189
|
+
metadata: {
|
|
190
|
+
integration: `${this.system}-life-sciences`,
|
|
191
|
+
system: this.system,
|
|
192
|
+
tenant: this.tenant,
|
|
193
|
+
operation: action.operation,
|
|
194
|
+
release_class: this.isReleaseClass(action),
|
|
195
|
+
...extra.releaseOutcome ? { release_outcome: extra.releaseOutcome } : {},
|
|
196
|
+
...action.lifecycleAction ? { lifecycle_action: action.lifecycleAction } : {},
|
|
197
|
+
// Part 11 §11.50 manifestation, present when a human signed.
|
|
198
|
+
...extra.signerId ? { signature: { signer_id: extra.signerId, meaning, signed_at: (/* @__PURE__ */ new Date()).toISOString() } } : {},
|
|
199
|
+
...extra.decisionId ? { decision_id: extra.decisionId } : {},
|
|
200
|
+
...extra.reason ? { reason: extra.reason } : {}
|
|
201
|
+
}
|
|
202
|
+
},
|
|
203
|
+
{ sign: true }
|
|
204
|
+
// source-signed: the agent's key signs the record
|
|
205
|
+
);
|
|
206
|
+
return true;
|
|
207
|
+
} catch {
|
|
208
|
+
return false;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* The full flow for one mutation: authorize (trust, release gate, scope), run
|
|
213
|
+
* the REST call if allowed, sign a receipt either way. If not authorized, `run`
|
|
214
|
+
* is never called. Rethrows a system error from `run` after recording it, with
|
|
215
|
+
* the receipt attached as `vorimReceipt`.
|
|
216
|
+
*/
|
|
217
|
+
async guard(action, run) {
|
|
218
|
+
const auth = await this.authorize(action);
|
|
219
|
+
if (!auth.authorized) {
|
|
220
|
+
const recorded = await this.record(action, "denied", {
|
|
221
|
+
reason: auth.reason,
|
|
222
|
+
releaseOutcome: auth.releaseOutcome,
|
|
223
|
+
signerId: auth.signerId,
|
|
224
|
+
decisionId: auth.decisionId
|
|
225
|
+
});
|
|
226
|
+
return { receipt: this.receipt(action, false, "denied", auth, recorded) };
|
|
227
|
+
}
|
|
228
|
+
try {
|
|
229
|
+
const value = await run();
|
|
230
|
+
const recorded = await this.record(action, "success", {
|
|
231
|
+
releaseOutcome: auth.releaseOutcome,
|
|
232
|
+
signerId: auth.signerId,
|
|
233
|
+
decisionId: auth.decisionId
|
|
234
|
+
});
|
|
235
|
+
return { receipt: this.receipt(action, true, "success", auth, recorded), value };
|
|
236
|
+
} catch (e) {
|
|
237
|
+
const recorded = await this.record(action, "error", {
|
|
238
|
+
reason: e?.message,
|
|
239
|
+
releaseOutcome: auth.releaseOutcome,
|
|
240
|
+
signerId: auth.signerId,
|
|
241
|
+
decisionId: auth.decisionId
|
|
242
|
+
});
|
|
243
|
+
throw Object.assign(e ?? new Error("life sciences operation failed"), {
|
|
244
|
+
vorimReceipt: this.receipt(action, true, "error", { ...auth, reason: e?.message }, recorded)
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
// --- Named helpers ---------------------------------------------------------
|
|
249
|
+
/** Guard a Benchling entity/registry/ELN write, or a result release. Pass the
|
|
250
|
+
* operation ('register-entity' | 'create-entry' | 'create-result' |
|
|
251
|
+
* 'update-entity'). A 'create-result' is release-class (needs the human of
|
|
252
|
+
* record). */
|
|
253
|
+
guardedEntityWrite(meta, run) {
|
|
254
|
+
return this.guard(
|
|
255
|
+
{ operation: meta.operation, resourceId: meta.resourceId, meaning: meta.meaning, inputHash: meta.inputHash },
|
|
256
|
+
run
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
/** Guard a Veeva Vault document lifecycle transition. `lifecycleAction` is the
|
|
260
|
+
* per-Vault action name (discover it at runtime). Set `isEffectiveTransition`
|
|
261
|
+
* when the move makes the record effective/approved — that makes it
|
|
262
|
+
* release-class and routes it to the human of record. */
|
|
263
|
+
guardedLifecycleChange(meta, run) {
|
|
264
|
+
return this.guard(
|
|
265
|
+
{
|
|
266
|
+
operation: "lifecycle-change",
|
|
267
|
+
resourceId: meta.documentId,
|
|
268
|
+
lifecycleAction: meta.lifecycleAction,
|
|
269
|
+
isEffectiveTransition: meta.isEffectiveTransition,
|
|
270
|
+
meaning: meta.meaning,
|
|
271
|
+
inputHash: meta.inputHash
|
|
272
|
+
},
|
|
273
|
+
run
|
|
274
|
+
);
|
|
275
|
+
}
|
|
276
|
+
/** Guard a Veeva Vault document create/update. Requires agent:write. */
|
|
277
|
+
guardedDocumentWrite(meta, run) {
|
|
278
|
+
return this.guard(
|
|
279
|
+
{ operation: meta.operation ?? "update-document", resourceId: meta.documentId, inputHash: meta.inputHash },
|
|
280
|
+
run
|
|
281
|
+
);
|
|
282
|
+
}
|
|
283
|
+
receipt(action, authorized, result, auth, recorded) {
|
|
284
|
+
return {
|
|
285
|
+
authorized,
|
|
286
|
+
agentId: this.agentId,
|
|
287
|
+
system: this.system,
|
|
288
|
+
tenant: this.tenant,
|
|
289
|
+
operation: action.operation,
|
|
290
|
+
resourceId: action.resourceId,
|
|
291
|
+
releaseClass: this.isReleaseClass(action),
|
|
292
|
+
releaseOutcome: auth.releaseOutcome ?? "not-release-class",
|
|
293
|
+
signature: auth.signerId ? { signerId: auth.signerId, meaning: this.meaningFor(action) } : void 0,
|
|
294
|
+
result,
|
|
295
|
+
scope: this.scopeFor(action),
|
|
296
|
+
reason: auth.reason,
|
|
297
|
+
decisionId: auth.decisionId,
|
|
298
|
+
recorded
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
function createVorimLifeSciences(sdk, config) {
|
|
303
|
+
return new VorimLifeSciences(sdk, config);
|
|
304
|
+
}
|
|
305
|
+
export {
|
|
306
|
+
VorimLifeSciences,
|
|
307
|
+
createVorimLifeSciences
|
|
308
|
+
};
|
|
309
|
+
//# sourceMappingURL=life-sciences.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/integrations/life-sciences.ts"],"sourcesContent":["// ============================================================================\n// Vorim AI — Life Sciences (Benchling / Veeva Vault) Integration\n//\n// This guards an AI agent that acts on a validated GxP system of record —\n// Benchling (R&D / ELN / registry) or Veeva Vault (regulated content: Quality,\n// RIM, Clinical) — through their REST APIs. Before each mutation runs it checks\n// the acting agent holds the right permission and, for the high-stakes actions\n// (releasing a result, moving a document to an Approved/Effective lifecycle\n// state, signing an ELN entry), it escalates to the named HUMAN OF RECORD and\n// waits. Either way it signs a tamper-evident record that carries the FDA 21 CFR\n// Part 11 §11.50 signature-manifestation elements: the signer's printed name,\n// the timestamp, and the meaning of the action.\n//\n// WHY THIS LAYER, AND THE HONEST COMPLIANCE FRAMING\n// Part 11 (§11.10(e) audit trails, §11.50 signature manifestation, §11.70\n// record linking) and EU Annex 11 require tamper-evident, attributable,\n// time-stamped records with signatures linked to the exact content and meaning.\n// Vorim adds an INDEPENDENT, cryptographically tamper-evident record over each\n// agent-driven mutation that maps to those clauses and is offline-verifiable —\n// BESIDE, not instead of, the validated system's own Part 11 controls. Part 11\n// does NOT mandate cryptographic signatures (§11.200 permits an id-code +\n// password signature), so this is a strengthening/data-integrity control. Never\n// claim \"Vorim makes you Part 11 compliant\" or that it IS the required\n// e-signature. The system (Benchling/Veeva) provides its own Part 11 signature.\n//\n// THE AGENT IS NOT THE SIGNATORY\n// Part 11 §11.100(a) requires signatures unique to one individual. An autonomous\n// agent cannot be the Part 11 signatory of an approval. So attenuation is\n// capability-based, not a dollar ceiling: the agent may DRAFT/WRITE, but\n// release/approve/lifecycle-to-effective is gated to a named human, whose\n// identity + the meaning of their signature go into the record.\n//\n// SCOPE MAPPING (uses Vorim's real scopes)\n// read a record -> agent:read\n// draft / write an entity/entry -> agent:write\n// release a result, approve, or -> agent:elevate (escalation to a human\n// move to an effective state of record; SoD gate)\n//\n// This layer never holds a Benchling/Veeva token and never calls them itself.\n// You pass the REST call to run; it authorizes, escalates if needed, runs it,\n// and signs the receipt. Veeva lifecycle ACTION NAMES are per-Vault and MUST be\n// discovered at runtime by the caller — this layer never hard-codes them.\n//\n// Usage:\n// import createVorim from '@vorim/sdk';\n// import { createVorimLifeSciences } from '@vorim/sdk/integrations/life-sciences';\n//\n// const vorim = createVorim({ apiKey: 'agid_sk_...' });\n// const ls = createVorimLifeSciences(vorim, {\n// agentId: 'agid_abc123',\n// system: 'benchling',\n// tenant: 'acme.benchling.com',\n// humanOfRecordId: 'scientist_42', // the Part 11 signer for approvals\n// });\n//\n// const { receipt, value } = await ls.guardedEntityWrite(\n// { operation: 'register-entity', resourceId: 'seq_9', meaning: 'authorship' },\n// () => benchling.post('/api/v2/dna-sequences', body),\n// );\n// ============================================================================\n\nimport type { VorimSDK } from '../index.js';\nimport type { PermissionScope } from '../types.js';\n\n/** Which validated system this guard fronts. Configuration, not separate code\n * paths. */\nexport type LifeSciencesSystem = 'benchling' | 'veeva';\n\n/** The mutations this guard classifies. Draft/write operations require write;\n * release/approve/lifecycle-to-effective are escalation-gated to a human of\n * record. Any other label defaults to the 'write' tier. */\nexport type LifeSciencesOperation =\n // Benchling\n | 'register-entity' // create + register a sample/entity in the Registry\n | 'create-entry' // write an ELN / Notebook entry (draft)\n | 'create-result' // upload / release an assay result\n | 'update-entity'\n // Veeva Vault\n | 'create-document'\n | 'update-document'\n | 'lifecycle-change' // move a document to a new lifecycle state\n | 'read';\n\n/** The §11.50(a)(3) meaning associated with a human signature on a record. */\nexport type SignatureMeaning = 'authorship' | 'review' | 'approval' | 'responsibility';\n\n/** Operations that release/approve/finalize and therefore require the named\n * human of record (segregation of duties), not just an agent write. Note\n * lifecycle-change is release-class ONLY when the caller marks it effective\n * (isEffectiveTransition), since a Draft→In Review move is a lower-stakes\n * write. create-result defaults to release-class because releasing a result\n * into a schema is a data-integrity-sensitive act. */\nconst RELEASE_CLASS = new Set<string>(['create-result']);\n\nconst OPERATION_SCOPE: Record<string, PermissionScope> = {\n read: 'agent:read',\n 'register-entity': 'agent:write',\n 'create-entry': 'agent:write',\n 'update-entity': 'agent:write',\n 'create-document': 'agent:write',\n 'update-document': 'agent:write',\n 'create-result': 'agent:elevate',\n 'lifecycle-change': 'agent:write', // elevated only for an effective transition\n};\n\nexport interface LifeSciencesGuardConfig {\n /** The acting agent's Vorim id (agid_...). */\n agentId: string;\n /** Which validated system this guard fronts. */\n system: LifeSciencesSystem;\n /** The tenant / vault, e.g. 'acme.benchling.com' or 'acme.veevavault.com'.\n * Recorded on every receipt so an action is attributable to one instance. */\n tenant: string;\n /** The human of record — the Part 11 signatory for any release/approval. Used\n * as the named approver on escalation and recorded as the signer. Required if\n * any release-class action will be run. */\n humanOfRecordId?: string;\n /** Minimum trust score the acting agent must hold before any mutation runs.\n * Default 0 (off). */\n minTrustScore?: number;\n /** Attenuation: cap this agent to draft/write only. Any release-class action\n * (result release, effective lifecycle transition, approval) is denied\n * outright rather than escalated. Default false. */\n draftOnly?: boolean;\n /** For a release-class action, escalate to the human of record and wait for\n * their signature instead of denying. Requires the runtime decision plane.\n * Default true (a release without a human is the thing we exist to prevent).\n * Ignored when draftOnly is set. */\n escalateOnRelease?: boolean;\n /** Max time to wait for an escalation decision, ms. Default 300000 (5 min —\n * a human sign-off, not a machine call). */\n escalationTimeoutMs?: number;\n /** Fail closed (deny on any Vorim error) or fail open. Default 'closed'. */\n onError?: 'closed' | 'open';\n}\n\nexport interface LifeSciencesAction {\n /** The REST operation being run, e.g. 'register-entity'. Drives the scope and\n * whether the action is release-class. Unknown labels default to write. */\n operation: LifeSciencesOperation | string;\n /** The entity / entry / document id the action targets. */\n resourceId?: string;\n /** The §11.50 meaning of the human signature, when this action is approved by\n * the human of record. Defaults to 'authorship' for writes, 'approval' for\n * release-class actions. */\n meaning?: SignatureMeaning;\n /** For a Veeva 'lifecycle-change': the per-Vault action name, discovered at\n * runtime by the caller (never hard-coded here). Recorded for the audit. */\n lifecycleAction?: string;\n /** For a Veeva 'lifecycle-change': set true when the transition makes the\n * record effective/approved (release-class → requires the human of record).\n * A Draft→In Review move leaves this false. */\n isEffectiveTransition?: boolean;\n /** Optional hash of the request body so the receipt covers the exact input\n * without the guard storing it. */\n inputHash?: string;\n}\n\n/** How a release-class action resolved. */\nexport type ReleaseOutcome = 'not-release-class' | 'signed-by-human' | 'release-denied' | 'draft-only-blocked';\n\n/** An offline-verifiable receipt for one life-sciences mutation. Carries the\n * Part 11 §11.50 manifestation when a human of record signed. */\nexport interface LifeSciencesReceipt {\n authorized: boolean;\n agentId: string;\n system: LifeSciencesSystem;\n tenant: string;\n operation: string;\n resourceId?: string;\n /** True when this operation releases/approves/finalizes a record. */\n releaseClass: boolean;\n releaseOutcome: ReleaseOutcome;\n /** The §11.50 manifestation, present when a human of record signed. */\n signature?: { signerId: string; meaning: SignatureMeaning };\n result: 'success' | 'denied' | 'error';\n scope: PermissionScope;\n reason?: string;\n decisionId?: string;\n recorded: boolean;\n}\n\nexport class VorimLifeSciences {\n private sdk: VorimSDK;\n private agentId: string;\n private system: LifeSciencesSystem;\n private tenant: string;\n private humanOfRecordId?: string;\n private minTrustScore: number;\n private draftOnly: boolean;\n private escalateOnRelease: boolean;\n private escalationTimeoutMs: number;\n private onError: 'closed' | 'open';\n\n constructor(sdk: VorimSDK, config: LifeSciencesGuardConfig) {\n if (!config?.agentId) throw new Error('[vorim] Life sciences integration requires an agentId.');\n if (!config?.system) throw new Error('[vorim] Life sciences integration requires a system.');\n if (!config?.tenant) throw new Error('[vorim] Life sciences integration requires a tenant.');\n this.sdk = sdk;\n this.agentId = config.agentId;\n this.system = config.system;\n this.tenant = config.tenant;\n this.humanOfRecordId = config.humanOfRecordId;\n this.minTrustScore = config.minTrustScore ?? 0;\n this.draftOnly = config.draftOnly ?? false;\n this.escalateOnRelease = config.escalateOnRelease ?? true;\n this.escalationTimeoutMs = config.escalationTimeoutMs ?? 300_000;\n this.onError = config.onError ?? 'closed';\n }\n\n /** Whether an action releases/approves/finalizes a record (needs the human of\n * record). A lifecycle-change counts only when the caller marks it an\n * effective transition. */\n private isReleaseClass(action: LifeSciencesAction): boolean {\n if (action.operation === 'lifecycle-change') return action.isEffectiveTransition === true;\n return RELEASE_CLASS.has(action.operation);\n }\n\n /** The Vorim scope an operation requires. A release-class lifecycle-change is\n * elevated even though the base op maps to write. */\n private scopeFor(action: LifeSciencesAction): PermissionScope {\n if (this.isReleaseClass(action)) return 'agent:elevate';\n return OPERATION_SCOPE[action.operation] ?? 'agent:write';\n }\n\n private meaningFor(action: LifeSciencesAction): SignatureMeaning {\n return action.meaning ?? (this.isReleaseClass(action) ? 'approval' : 'authorship');\n }\n\n /**\n * Decide whether the acting agent may run this action, before it runs. Order:\n * trust floor, then the release gate (draft-only block, or escalate to the\n * human of record), then permission scope for plain writes.\n */\n async authorize(\n action: LifeSciencesAction,\n ): Promise<{\n authorized: boolean;\n reason?: string;\n releaseOutcome: ReleaseOutcome;\n signerId?: string;\n decisionId?: string;\n }> {\n const releaseClass = this.isReleaseClass(action);\n const scope = this.scopeFor(action);\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 releaseOutcome: releaseClass ? 'release-denied' : 'not-release-class',\n };\n }\n }\n\n if (releaseClass) {\n // A draft-only agent can never release/approve.\n if (this.draftOnly) {\n return {\n authorized: false,\n reason: 'agent is draft-only; release/approval requires a human of record',\n releaseOutcome: 'draft-only-blocked',\n };\n }\n if (!this.escalateOnRelease) {\n return {\n authorized: false,\n reason: 'release requires a human of record and escalateOnRelease is off',\n releaseOutcome: 'release-denied',\n };\n }\n if (!this.humanOfRecordId) {\n return {\n authorized: false,\n reason: 'release-class action requires a configured humanOfRecordId (the Part 11 signer)',\n releaseOutcome: 'release-denied',\n };\n }\n const esc = await this.escalate(action, scope);\n return {\n authorized: esc.approved,\n reason: esc.approved ? undefined : (esc.reason ?? 'human of record did not sign'),\n releaseOutcome: esc.approved ? 'signed-by-human' : 'release-denied',\n signerId: esc.approved ? this.humanOfRecordId : undefined,\n decisionId: esc.decisionId,\n };\n }\n\n // Plain write: a permission check on the scope.\n const perm = await this.sdk.check(this.agentId, scope);\n return perm.allowed\n ? { authorized: true, releaseOutcome: 'not-release-class' }\n : {\n authorized: false,\n reason: perm.reason ?? `missing scope ${scope}`,\n releaseOutcome: 'not-release-class',\n };\n } catch (e: any) {\n return this.onError === 'open'\n ? {\n authorized: true,\n reason: 'vorim unreachable, failed open',\n releaseOutcome: releaseClass ? 'signed-by-human' : 'not-release-class',\n }\n : {\n authorized: false,\n reason: `vorim unreachable: ${e?.message ?? 'error'}`,\n releaseOutcome: releaseClass ? 'release-denied' : 'not-release-class',\n };\n }\n }\n\n /**\n * Route a release-class action through the runtime decision plane so the named\n * human of record can sign (approve) or refuse, and wait for that decision.\n * The elevate scope marks this as the segregation-of-duties gate: the agent\n * that drafted the record cannot also be its Part 11 signatory.\n */\n private async escalate(\n action: LifeSciencesAction,\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: `${this.system}:${action.operation}`,\n requiredScope: scope,\n payload: {\n operation: action.operation,\n resource_id: action.resourceId,\n lifecycle_action: action.lifecycleAction,\n meaning: this.meaningFor(action),\n },\n context: {\n integration: `${this.system}-life-sciences`,\n tenant: this.tenant,\n requires_human_of_record: true,\n signer_hint: this.humanOfRecordId,\n part11_manifestation: true,\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 : 'human of record refused to sign',\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 mutation and return whether it was\n * recorded. When a human of record signed a release-class action, the event\n * carries the Part 11 §11.50 manifestation: signer id, timestamp (server), and\n * the meaning of the signature — an independent, offline-verifiable record\n * beside the validated system's own controls.\n */\n async record(\n action: LifeSciencesAction,\n result: 'success' | 'denied' | 'error',\n extra: { reason?: string; releaseOutcome?: ReleaseOutcome; signerId?: string; decisionId?: string } = {},\n ): Promise<boolean> {\n const scope = this.scopeFor(action);\n const meaning = this.meaningFor(action);\n try {\n await this.sdk.emit(\n {\n agent_id: this.agentId,\n event_type: 'api_request',\n action: `${this.system}:${action.operation}${action.resourceId ? ' ' + action.resourceId : ''}`,\n resource: action.resourceId || this.tenant,\n permission: scope,\n result,\n input_hash: action.inputHash,\n metadata: {\n integration: `${this.system}-life-sciences`,\n system: this.system,\n tenant: this.tenant,\n operation: action.operation,\n release_class: this.isReleaseClass(action),\n ...(extra.releaseOutcome ? { release_outcome: extra.releaseOutcome } : {}),\n ...(action.lifecycleAction ? { lifecycle_action: action.lifecycleAction } : {}),\n // Part 11 §11.50 manifestation, present when a human signed.\n ...(extra.signerId\n ? { signature: { signer_id: extra.signerId, meaning, signed_at: new Date().toISOString() } }\n : {}),\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 mutation: authorize (trust, release gate, scope), run\n * the REST call if allowed, sign a receipt either way. If not authorized, `run`\n * is never called. Rethrows a system error from `run` after recording it, with\n * the receipt attached as `vorimReceipt`.\n */\n async guard<T>(\n action: LifeSciencesAction,\n run: () => Promise<T>,\n ): Promise<{ receipt: LifeSciencesReceipt; 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 releaseOutcome: auth.releaseOutcome,\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 releaseOutcome: auth.releaseOutcome,\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 releaseOutcome: auth.releaseOutcome,\n signerId: auth.signerId,\n decisionId: auth.decisionId,\n });\n throw Object.assign(e ?? new Error('life sciences 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 Benchling entity/registry/ELN write, or a result release. Pass the\n * operation ('register-entity' | 'create-entry' | 'create-result' |\n * 'update-entity'). A 'create-result' is release-class (needs the human of\n * record). */\n guardedEntityWrite<T>(\n meta: { operation: LifeSciencesOperation | string; resourceId?: string; meaning?: SignatureMeaning; inputHash?: string },\n run: () => Promise<T>,\n ) {\n return this.guard(\n { operation: meta.operation, resourceId: meta.resourceId, meaning: meta.meaning, inputHash: meta.inputHash },\n run,\n );\n }\n\n /** Guard a Veeva Vault document lifecycle transition. `lifecycleAction` is the\n * per-Vault action name (discover it at runtime). Set `isEffectiveTransition`\n * when the move makes the record effective/approved — that makes it\n * release-class and routes it to the human of record. */\n guardedLifecycleChange<T>(\n meta: {\n documentId?: string;\n lifecycleAction?: string;\n isEffectiveTransition?: boolean;\n meaning?: SignatureMeaning;\n inputHash?: string;\n },\n run: () => Promise<T>,\n ) {\n return this.guard(\n {\n operation: 'lifecycle-change',\n resourceId: meta.documentId,\n lifecycleAction: meta.lifecycleAction,\n isEffectiveTransition: meta.isEffectiveTransition,\n meaning: meta.meaning,\n inputHash: meta.inputHash,\n },\n run,\n );\n }\n\n /** Guard a Veeva Vault document create/update. Requires agent:write. */\n guardedDocumentWrite<T>(\n meta: { operation?: 'create-document' | 'update-document'; documentId?: string; inputHash?: string },\n run: () => Promise<T>,\n ) {\n return this.guard(\n { operation: meta.operation ?? 'update-document', resourceId: meta.documentId, inputHash: meta.inputHash },\n run,\n );\n }\n\n private receipt(\n action: LifeSciencesAction,\n authorized: boolean,\n result: 'success' | 'denied' | 'error',\n auth: { reason?: string; releaseOutcome?: ReleaseOutcome; signerId?: string; decisionId?: string },\n recorded: boolean,\n ): LifeSciencesReceipt {\n return {\n authorized,\n agentId: this.agentId,\n system: this.system,\n tenant: this.tenant,\n operation: action.operation,\n resourceId: action.resourceId,\n releaseClass: this.isReleaseClass(action),\n releaseOutcome: auth.releaseOutcome ?? 'not-release-class',\n signature: auth.signerId ? { signerId: auth.signerId, meaning: this.meaningFor(action) } : undefined,\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 VorimLifeSciences guard around a Vorim SDK instance.\n *\n * @example\n * ```typescript\n * import createVorim from '@vorim/sdk';\n * import { createVorimLifeSciences } from '@vorim/sdk/integrations/life-sciences';\n *\n * const vorim = createVorim({ apiKey: 'agid_sk_...' });\n * const ls = createVorimLifeSciences(vorim, {\n * agentId: 'agid_abc123',\n * system: 'veeva',\n * tenant: 'acme.veevavault.com',\n * humanOfRecordId: 'qa_lead_7', // the Part 11 signer for approvals\n * });\n *\n * // An effective lifecycle transition escalates to the human of record:\n * const { receipt, value } = await ls.guardedLifecycleChange(\n * { documentId: 'doc_42', lifecycleAction: 'approve__c', isEffectiveTransition: true, meaning: 'approval' },\n * () => vault.post('/api/v26.1/objects/documents/doc_42/lifecycle_actions/approve__c'),\n * );\n * ```\n */\nexport function createVorimLifeSciences(sdk: VorimSDK, config: LifeSciencesGuardConfig): VorimLifeSciences {\n return new VorimLifeSciences(sdk, config);\n}\n"],"mappings":";AA4FA,IAAM,gBAAgB,oBAAI,IAAY,CAAC,eAAe,CAAC;AAEvD,IAAM,kBAAmD;AAAA,EACvD,MAAM;AAAA,EACN,mBAAmB;AAAA,EACnB,gBAAgB;AAAA,EAChB,iBAAiB;AAAA,EACjB,mBAAmB;AAAA,EACnB,mBAAmB;AAAA,EACnB,iBAAiB;AAAA,EACjB,oBAAoB;AAAA;AACtB;AA+EO,IAAM,oBAAN,MAAwB;AAAA,EACrB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAER,YAAY,KAAe,QAAiC;AAC1D,QAAI,CAAC,QAAQ,QAAS,OAAM,IAAI,MAAM,wDAAwD;AAC9F,QAAI,CAAC,QAAQ,OAAQ,OAAM,IAAI,MAAM,sDAAsD;AAC3F,QAAI,CAAC,QAAQ,OAAQ,OAAM,IAAI,MAAM,sDAAsD;AAC3F,SAAK,MAAM;AACX,SAAK,UAAU,OAAO;AACtB,SAAK,SAAS,OAAO;AACrB,SAAK,SAAS,OAAO;AACrB,SAAK,kBAAkB,OAAO;AAC9B,SAAK,gBAAgB,OAAO,iBAAiB;AAC7C,SAAK,YAAY,OAAO,aAAa;AACrC,SAAK,oBAAoB,OAAO,qBAAqB;AACrD,SAAK,sBAAsB,OAAO,uBAAuB;AAC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