@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.
Files changed (57) hide show
  1. package/dist/index.cjs +1 -1
  2. package/dist/index.js +1 -1
  3. package/dist/integrations/coinbase-cdp.cjs +230 -0
  4. package/dist/integrations/coinbase-cdp.cjs.map +1 -0
  5. package/dist/integrations/coinbase-cdp.d.cts +169 -0
  6. package/dist/integrations/coinbase-cdp.d.ts +169 -0
  7. package/dist/integrations/coinbase-cdp.js +204 -0
  8. package/dist/integrations/coinbase-cdp.js.map +1 -0
  9. package/dist/integrations/fhir.cjs +304 -0
  10. package/dist/integrations/fhir.cjs.map +1 -0
  11. package/dist/integrations/fhir.d.cts +185 -0
  12. package/dist/integrations/fhir.d.ts +185 -0
  13. package/dist/integrations/fhir.js +278 -0
  14. package/dist/integrations/fhir.js.map +1 -0
  15. package/dist/integrations/guidewire.cjs +363 -0
  16. package/dist/integrations/guidewire.cjs.map +1 -0
  17. package/dist/integrations/guidewire.d.cts +258 -0
  18. package/dist/integrations/guidewire.d.ts +258 -0
  19. package/dist/integrations/guidewire.js +337 -0
  20. package/dist/integrations/guidewire.js.map +1 -0
  21. package/dist/integrations/legal.cjs +339 -0
  22. package/dist/integrations/legal.cjs.map +1 -0
  23. package/dist/integrations/legal.d.cts +225 -0
  24. package/dist/integrations/legal.d.ts +225 -0
  25. package/dist/integrations/legal.js +313 -0
  26. package/dist/integrations/legal.js.map +1 -0
  27. package/dist/integrations/life-sciences.cjs +335 -0
  28. package/dist/integrations/life-sciences.cjs.map +1 -0
  29. package/dist/integrations/life-sciences.d.cts +214 -0
  30. package/dist/integrations/life-sciences.d.ts +214 -0
  31. package/dist/integrations/life-sciences.js +309 -0
  32. package/dist/integrations/life-sciences.js.map +1 -0
  33. package/dist/integrations/lithic.cjs +290 -0
  34. package/dist/integrations/lithic.cjs.map +1 -0
  35. package/dist/integrations/lithic.d.cts +130 -0
  36. package/dist/integrations/lithic.d.ts +130 -0
  37. package/dist/integrations/lithic.js +264 -0
  38. package/dist/integrations/lithic.js.map +1 -0
  39. package/dist/integrations/marqeta.cjs +285 -0
  40. package/dist/integrations/marqeta.cjs.map +1 -0
  41. package/dist/integrations/marqeta.d.cts +121 -0
  42. package/dist/integrations/marqeta.d.ts +121 -0
  43. package/dist/integrations/marqeta.js +259 -0
  44. package/dist/integrations/marqeta.js.map +1 -0
  45. package/dist/integrations/ramp.cjs +206 -0
  46. package/dist/integrations/ramp.cjs.map +1 -0
  47. package/dist/integrations/ramp.d.cts +139 -0
  48. package/dist/integrations/ramp.d.ts +139 -0
  49. package/dist/integrations/ramp.js +180 -0
  50. package/dist/integrations/ramp.js.map +1 -0
  51. package/dist/integrations/stripe-issuing.cjs +316 -0
  52. package/dist/integrations/stripe-issuing.cjs.map +1 -0
  53. package/dist/integrations/stripe-issuing.d.cts +154 -0
  54. package/dist/integrations/stripe-issuing.d.ts +154 -0
  55. package/dist/integrations/stripe-issuing.js +290 -0
  56. package/dist/integrations/stripe-issuing.js.map +1 -0
  57. package/package.json +91 -1
@@ -0,0 +1,335 @@
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/life-sciences.ts
21
+ var life_sciences_exports = {};
22
+ __export(life_sciences_exports, {
23
+ VorimLifeSciences: () => VorimLifeSciences,
24
+ createVorimLifeSciences: () => createVorimLifeSciences
25
+ });
26
+ module.exports = __toCommonJS(life_sciences_exports);
27
+ var RELEASE_CLASS = /* @__PURE__ */ new Set(["create-result"]);
28
+ var OPERATION_SCOPE = {
29
+ read: "agent:read",
30
+ "register-entity": "agent:write",
31
+ "create-entry": "agent:write",
32
+ "update-entity": "agent:write",
33
+ "create-document": "agent:write",
34
+ "update-document": "agent:write",
35
+ "create-result": "agent:elevate",
36
+ "lifecycle-change": "agent:write"
37
+ // elevated only for an effective transition
38
+ };
39
+ var VorimLifeSciences = class {
40
+ sdk;
41
+ agentId;
42
+ system;
43
+ tenant;
44
+ humanOfRecordId;
45
+ minTrustScore;
46
+ draftOnly;
47
+ escalateOnRelease;
48
+ escalationTimeoutMs;
49
+ onError;
50
+ constructor(sdk, config) {
51
+ if (!config?.agentId) throw new Error("[vorim] Life sciences integration requires an agentId.");
52
+ if (!config?.system) throw new Error("[vorim] Life sciences integration requires a system.");
53
+ if (!config?.tenant) throw new Error("[vorim] Life sciences integration requires a tenant.");
54
+ this.sdk = sdk;
55
+ this.agentId = config.agentId;
56
+ this.system = config.system;
57
+ this.tenant = config.tenant;
58
+ this.humanOfRecordId = config.humanOfRecordId;
59
+ this.minTrustScore = config.minTrustScore ?? 0;
60
+ this.draftOnly = config.draftOnly ?? false;
61
+ this.escalateOnRelease = config.escalateOnRelease ?? true;
62
+ this.escalationTimeoutMs = config.escalationTimeoutMs ?? 3e5;
63
+ this.onError = config.onError ?? "closed";
64
+ }
65
+ /** Whether an action releases/approves/finalizes a record (needs the human of
66
+ * record). A lifecycle-change counts only when the caller marks it an
67
+ * effective transition. */
68
+ isReleaseClass(action) {
69
+ if (action.operation === "lifecycle-change") return action.isEffectiveTransition === true;
70
+ return RELEASE_CLASS.has(action.operation);
71
+ }
72
+ /** The Vorim scope an operation requires. A release-class lifecycle-change is
73
+ * elevated even though the base op maps to write. */
74
+ scopeFor(action) {
75
+ if (this.isReleaseClass(action)) return "agent:elevate";
76
+ return OPERATION_SCOPE[action.operation] ?? "agent:write";
77
+ }
78
+ meaningFor(action) {
79
+ return action.meaning ?? (this.isReleaseClass(action) ? "approval" : "authorship");
80
+ }
81
+ /**
82
+ * Decide whether the acting agent may run this action, before it runs. Order:
83
+ * trust floor, then the release gate (draft-only block, or escalate to the
84
+ * human of record), then permission scope for plain writes.
85
+ */
86
+ async authorize(action) {
87
+ const releaseClass = this.isReleaseClass(action);
88
+ const scope = this.scopeFor(action);
89
+ try {
90
+ if (this.minTrustScore > 0) {
91
+ const trust = await this.sdk.verify(this.agentId);
92
+ if ((trust?.trust_score ?? 0) < this.minTrustScore) {
93
+ return {
94
+ authorized: false,
95
+ reason: `trust score below ${this.minTrustScore}`,
96
+ releaseOutcome: releaseClass ? "release-denied" : "not-release-class"
97
+ };
98
+ }
99
+ }
100
+ if (releaseClass) {
101
+ if (this.draftOnly) {
102
+ return {
103
+ authorized: false,
104
+ reason: "agent is draft-only; release/approval requires a human of record",
105
+ releaseOutcome: "draft-only-blocked"
106
+ };
107
+ }
108
+ if (!this.escalateOnRelease) {
109
+ return {
110
+ authorized: false,
111
+ reason: "release requires a human of record and escalateOnRelease is off",
112
+ releaseOutcome: "release-denied"
113
+ };
114
+ }
115
+ if (!this.humanOfRecordId) {
116
+ return {
117
+ authorized: false,
118
+ reason: "release-class action requires a configured humanOfRecordId (the Part 11 signer)",
119
+ releaseOutcome: "release-denied"
120
+ };
121
+ }
122
+ const esc = await this.escalate(action, scope);
123
+ return {
124
+ authorized: esc.approved,
125
+ reason: esc.approved ? void 0 : esc.reason ?? "human of record did not sign",
126
+ releaseOutcome: esc.approved ? "signed-by-human" : "release-denied",
127
+ signerId: esc.approved ? this.humanOfRecordId : void 0,
128
+ decisionId: esc.decisionId
129
+ };
130
+ }
131
+ const perm = await this.sdk.check(this.agentId, scope);
132
+ return perm.allowed ? { authorized: true, releaseOutcome: "not-release-class" } : {
133
+ authorized: false,
134
+ reason: perm.reason ?? `missing scope ${scope}`,
135
+ releaseOutcome: "not-release-class"
136
+ };
137
+ } catch (e) {
138
+ return this.onError === "open" ? {
139
+ authorized: true,
140
+ reason: "vorim unreachable, failed open",
141
+ releaseOutcome: releaseClass ? "signed-by-human" : "not-release-class"
142
+ } : {
143
+ authorized: false,
144
+ reason: `vorim unreachable: ${e?.message ?? "error"}`,
145
+ releaseOutcome: releaseClass ? "release-denied" : "not-release-class"
146
+ };
147
+ }
148
+ }
149
+ /**
150
+ * Route a release-class action through the runtime decision plane so the named
151
+ * human of record can sign (approve) or refuse, and wait for that decision.
152
+ * The elevate scope marks this as the segregation-of-duties gate: the agent
153
+ * that drafted the record cannot also be its Part 11 signatory.
154
+ */
155
+ async escalate(action, scope) {
156
+ const decision = await this.sdk.beforeAction(
157
+ {
158
+ agentId: this.agentId,
159
+ actionType: "api_request",
160
+ actionTarget: `${this.system}:${action.operation}`,
161
+ requiredScope: scope,
162
+ payload: {
163
+ operation: action.operation,
164
+ resource_id: action.resourceId,
165
+ lifecycle_action: action.lifecycleAction,
166
+ meaning: this.meaningFor(action)
167
+ },
168
+ context: {
169
+ integration: `${this.system}-life-sciences`,
170
+ tenant: this.tenant,
171
+ requires_human_of_record: true,
172
+ signer_hint: this.humanOfRecordId,
173
+ part11_manifestation: true
174
+ }
175
+ },
176
+ { throwOnDeny: false }
177
+ );
178
+ if (decision.decision === "escalate") {
179
+ const resolved = await this.sdk.waitForDecisionResolution(decision.decisionId, {
180
+ timeoutMs: this.escalationTimeoutMs
181
+ });
182
+ const approved = resolved.decision === "allow" || resolved.escalationResolution === "approved";
183
+ return {
184
+ approved,
185
+ reason: approved ? void 0 : "human of record refused to sign",
186
+ decisionId: decision.decisionId
187
+ };
188
+ }
189
+ if (decision.decision === "allow") return { approved: true, decisionId: decision.decisionId };
190
+ if (decision.decision === "fallback")
191
+ return { approved: this.onError === "open", reason: "runtime unreachable", decisionId: decision.decisionId };
192
+ return { approved: false, reason: decision.reason ?? "denied", decisionId: decision.decisionId };
193
+ }
194
+ /**
195
+ * Emit a source-signed audit event for a mutation and return whether it was
196
+ * recorded. When a human of record signed a release-class action, the event
197
+ * carries the Part 11 §11.50 manifestation: signer id, timestamp (server), and
198
+ * the meaning of the signature — an independent, offline-verifiable record
199
+ * beside the validated system's own controls.
200
+ */
201
+ async record(action, result, extra = {}) {
202
+ const scope = this.scopeFor(action);
203
+ const meaning = this.meaningFor(action);
204
+ try {
205
+ await this.sdk.emit(
206
+ {
207
+ agent_id: this.agentId,
208
+ event_type: "api_request",
209
+ action: `${this.system}:${action.operation}${action.resourceId ? " " + action.resourceId : ""}`,
210
+ resource: action.resourceId || this.tenant,
211
+ permission: scope,
212
+ result,
213
+ input_hash: action.inputHash,
214
+ metadata: {
215
+ integration: `${this.system}-life-sciences`,
216
+ system: this.system,
217
+ tenant: this.tenant,
218
+ operation: action.operation,
219
+ release_class: this.isReleaseClass(action),
220
+ ...extra.releaseOutcome ? { release_outcome: extra.releaseOutcome } : {},
221
+ ...action.lifecycleAction ? { lifecycle_action: action.lifecycleAction } : {},
222
+ // Part 11 §11.50 manifestation, present when a human signed.
223
+ ...extra.signerId ? { signature: { signer_id: extra.signerId, meaning, signed_at: (/* @__PURE__ */ new Date()).toISOString() } } : {},
224
+ ...extra.decisionId ? { decision_id: extra.decisionId } : {},
225
+ ...extra.reason ? { reason: extra.reason } : {}
226
+ }
227
+ },
228
+ { sign: true }
229
+ // source-signed: the agent's key signs the record
230
+ );
231
+ return true;
232
+ } catch {
233
+ return false;
234
+ }
235
+ }
236
+ /**
237
+ * The full flow for one mutation: authorize (trust, release gate, scope), run
238
+ * the REST call if allowed, sign a receipt either way. If not authorized, `run`
239
+ * is never called. Rethrows a system error from `run` after recording it, with
240
+ * the receipt attached as `vorimReceipt`.
241
+ */
242
+ async guard(action, run) {
243
+ const auth = await this.authorize(action);
244
+ if (!auth.authorized) {
245
+ const recorded = await this.record(action, "denied", {
246
+ reason: auth.reason,
247
+ releaseOutcome: auth.releaseOutcome,
248
+ signerId: auth.signerId,
249
+ decisionId: auth.decisionId
250
+ });
251
+ return { receipt: this.receipt(action, false, "denied", auth, recorded) };
252
+ }
253
+ try {
254
+ const value = await run();
255
+ const recorded = await this.record(action, "success", {
256
+ releaseOutcome: auth.releaseOutcome,
257
+ signerId: auth.signerId,
258
+ decisionId: auth.decisionId
259
+ });
260
+ return { receipt: this.receipt(action, true, "success", auth, recorded), value };
261
+ } catch (e) {
262
+ const recorded = await this.record(action, "error", {
263
+ reason: e?.message,
264
+ releaseOutcome: auth.releaseOutcome,
265
+ signerId: auth.signerId,
266
+ decisionId: auth.decisionId
267
+ });
268
+ throw Object.assign(e ?? new Error("life sciences operation failed"), {
269
+ vorimReceipt: this.receipt(action, true, "error", { ...auth, reason: e?.message }, recorded)
270
+ });
271
+ }
272
+ }
273
+ // --- Named helpers ---------------------------------------------------------
274
+ /** Guard a Benchling entity/registry/ELN write, or a result release. Pass the
275
+ * operation ('register-entity' | 'create-entry' | 'create-result' |
276
+ * 'update-entity'). A 'create-result' is release-class (needs the human of
277
+ * record). */
278
+ guardedEntityWrite(meta, run) {
279
+ return this.guard(
280
+ { operation: meta.operation, resourceId: meta.resourceId, meaning: meta.meaning, inputHash: meta.inputHash },
281
+ run
282
+ );
283
+ }
284
+ /** Guard a Veeva Vault document lifecycle transition. `lifecycleAction` is the
285
+ * per-Vault action name (discover it at runtime). Set `isEffectiveTransition`
286
+ * when the move makes the record effective/approved — that makes it
287
+ * release-class and routes it to the human of record. */
288
+ guardedLifecycleChange(meta, run) {
289
+ return this.guard(
290
+ {
291
+ operation: "lifecycle-change",
292
+ resourceId: meta.documentId,
293
+ lifecycleAction: meta.lifecycleAction,
294
+ isEffectiveTransition: meta.isEffectiveTransition,
295
+ meaning: meta.meaning,
296
+ inputHash: meta.inputHash
297
+ },
298
+ run
299
+ );
300
+ }
301
+ /** Guard a Veeva Vault document create/update. Requires agent:write. */
302
+ guardedDocumentWrite(meta, run) {
303
+ return this.guard(
304
+ { operation: meta.operation ?? "update-document", resourceId: meta.documentId, inputHash: meta.inputHash },
305
+ run
306
+ );
307
+ }
308
+ receipt(action, authorized, result, auth, recorded) {
309
+ return {
310
+ authorized,
311
+ agentId: this.agentId,
312
+ system: this.system,
313
+ tenant: this.tenant,
314
+ operation: action.operation,
315
+ resourceId: action.resourceId,
316
+ releaseClass: this.isReleaseClass(action),
317
+ releaseOutcome: auth.releaseOutcome ?? "not-release-class",
318
+ signature: auth.signerId ? { signerId: auth.signerId, meaning: this.meaningFor(action) } : void 0,
319
+ result,
320
+ scope: this.scopeFor(action),
321
+ reason: auth.reason,
322
+ decisionId: auth.decisionId,
323
+ recorded
324
+ };
325
+ }
326
+ };
327
+ function createVorimLifeSciences(sdk, config) {
328
+ return new VorimLifeSciences(sdk, config);
329
+ }
330
+ // Annotate the CommonJS export names for ESM import in node:
331
+ 0 && (module.exports = {
332
+ VorimLifeSciences,
333
+ createVorimLifeSciences
334
+ });
335
+ //# sourceMappingURL=life-sciences.cjs.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":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;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,MA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B,YAAY,KAAK,YAAY,WAAW,KAAK,UAAU;AAAA,MACzG;AAAA,IACF;AAAA,EACF;AAAA,EAEQ,QACN,QACA,YACA,QACA,MACA,UACqB;AACrB,WAAO;AAAA,MACL;AAAA,MACA,SAAS,KAAK;AAAA,MACd,QAAQ,KAAK;AAAA,MACb,QAAQ,KAAK;AAAA,MACb,WAAW,OAAO;AAAA,MAClB,YAAY,OAAO;AAAA,MACnB,cAAc,KAAK,eAAe,MAAM;AAAA,MACxC,gBAAgB,KAAK,kBAAkB;AAAA,MACvC,WAAW,KAAK,WAAW,EAAE,UAAU,KAAK,UAAU,SAAS,KAAK,WAAW,MAAM,EAAE,IAAI;AAAA,MAC3F;AAAA,MACA,OAAO,KAAK,SAAS,MAAM;AAAA,MAC3B,QAAQ,KAAK;AAAA,MACb,YAAY,KAAK;AAAA,MACjB;AAAA,IACF;AAAA,EACF;AACF;AAyBO,SAAS,wBAAwB,KAAe,QAAoD;AACzG,SAAO,IAAI,kBAAkB,KAAK,MAAM;AAC1C;","names":[]}
@@ -0,0 +1,214 @@
1
+ import { VorimSDK } from '../index.cjs';
2
+ import { P as PermissionScope } from '../types-zzK9YOoa.cjs';
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 };