@emilia-protocol/sdk 0.9.0 → 0.10.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/README.md +50 -0
- package/dist/client.d.ts +35 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +160 -2
- package/dist/client.js.map +1 -1
- package/dist/index.d.ts +263 -30
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +167 -16
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +202 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +3 -3
- package/src/client.ts +210 -2
- package/src/index.ts +440 -40
- package/src/types.ts +219 -0
package/src/types.ts
CHANGED
|
@@ -425,6 +425,225 @@ export interface InstallPreflightResult {
|
|
|
425
425
|
score: number;
|
|
426
426
|
}
|
|
427
427
|
|
|
428
|
+
// ----------------------------------------------------------------------------
|
|
429
|
+
// v1 Trust Receipt enforcement types
|
|
430
|
+
// ----------------------------------------------------------------------------
|
|
431
|
+
|
|
432
|
+
export type GuardActionType =
|
|
433
|
+
| 'benefit_bank_account_change'
|
|
434
|
+
| 'benefit_address_change'
|
|
435
|
+
| 'caseworker_override'
|
|
436
|
+
| 'vendor_bank_account_change'
|
|
437
|
+
| 'beneficiary_creation'
|
|
438
|
+
| 'large_payment_release'
|
|
439
|
+
| 'ai_agent_payment_action';
|
|
440
|
+
|
|
441
|
+
export type GuardDecision = 'allow' | 'observe' | 'allow_with_signoff' | 'deny';
|
|
442
|
+
export type GuardEnforcementMode = 'observe' | 'warn' | 'enforce';
|
|
443
|
+
export type ReceiptStatus =
|
|
444
|
+
| 'issued'
|
|
445
|
+
| 'pending_signoff'
|
|
446
|
+
| 'approved_pending_consume'
|
|
447
|
+
| 'rejected'
|
|
448
|
+
| 'consumed'
|
|
449
|
+
| 'denied';
|
|
450
|
+
|
|
451
|
+
export interface GuardQuorumApprover {
|
|
452
|
+
role: string;
|
|
453
|
+
approver: string;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
export interface GuardQuorumPolicy {
|
|
457
|
+
mode?: 'threshold' | 'all';
|
|
458
|
+
required: number;
|
|
459
|
+
approvers: GuardQuorumApprover[];
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
export interface CreateTrustReceiptParams {
|
|
463
|
+
/** Optional cross-check; the API derives the authorized organization from the authenticated key. */
|
|
464
|
+
organizationId?: string;
|
|
465
|
+
actionType: GuardActionType | string;
|
|
466
|
+
targetResourceId: string;
|
|
467
|
+
policyId?: string;
|
|
468
|
+
enforcementMode?: GuardEnforcementMode;
|
|
469
|
+
beforeState?: Record<string, unknown>;
|
|
470
|
+
afterState?: Record<string, unknown>;
|
|
471
|
+
targetChangedFields?: string[];
|
|
472
|
+
amount?: number;
|
|
473
|
+
currency?: string;
|
|
474
|
+
riskFlags?: string[];
|
|
475
|
+
actorRole?: string;
|
|
476
|
+
actorDepartment?: string;
|
|
477
|
+
businessHours?: boolean;
|
|
478
|
+
velocitySameActor24h?: number;
|
|
479
|
+
priorDenialsActor30d?: number;
|
|
480
|
+
priorChangesTarget30d?: number;
|
|
481
|
+
destinationAgeDays?: number;
|
|
482
|
+
quorumPolicy?: GuardQuorumPolicy;
|
|
483
|
+
metadata?: Record<string, unknown>;
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
export interface TrustReceipt {
|
|
487
|
+
receipt_id: string;
|
|
488
|
+
decision: GuardDecision;
|
|
489
|
+
observed_decision?: GuardDecision | null;
|
|
490
|
+
policy_id: string;
|
|
491
|
+
policy_hash: string;
|
|
492
|
+
action_hash: string;
|
|
493
|
+
before_state_hash?: string | null;
|
|
494
|
+
after_state_hash?: string | null;
|
|
495
|
+
nonce: string;
|
|
496
|
+
expires_at: string;
|
|
497
|
+
signoff_required: boolean;
|
|
498
|
+
signoff_request_id?: string | null;
|
|
499
|
+
risk_flags?: string[];
|
|
500
|
+
receipt_status: ReceiptStatus | string;
|
|
501
|
+
enforcement_mode: GuardEnforcementMode | string;
|
|
502
|
+
reasons?: string[];
|
|
503
|
+
canonical_action: Record<string, unknown>;
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
export interface TrustReceiptState {
|
|
507
|
+
receipt_id: string;
|
|
508
|
+
organization_id: string;
|
|
509
|
+
action_type: string;
|
|
510
|
+
decision: GuardDecision;
|
|
511
|
+
enforcement_mode: GuardEnforcementMode | string;
|
|
512
|
+
policy_id: string;
|
|
513
|
+
policy_hash: string;
|
|
514
|
+
action_hash: string;
|
|
515
|
+
before_state_hash?: string | null;
|
|
516
|
+
after_state_hash?: string | null;
|
|
517
|
+
expires_at: string;
|
|
518
|
+
signoff_required: boolean;
|
|
519
|
+
receipt_status: ReceiptStatus | string;
|
|
520
|
+
signoff_key_class?: 'A' | 'B' | 'C' | string | null;
|
|
521
|
+
timeline_event_count: number;
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
export interface RequestSignoffParams {
|
|
525
|
+
receiptId: string;
|
|
526
|
+
approverId?: string;
|
|
527
|
+
expiresInMinutes?: number;
|
|
528
|
+
comment?: string;
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
export interface SignoffRequest {
|
|
532
|
+
signoff_id?: string;
|
|
533
|
+
receipt_id: string;
|
|
534
|
+
action_hash: string;
|
|
535
|
+
initiator_id: string;
|
|
536
|
+
approver_id?: string;
|
|
537
|
+
expires_at: string;
|
|
538
|
+
status: 'pending' | string;
|
|
539
|
+
quorum?: { mode: string; required: number; count: number };
|
|
540
|
+
signoffs?: Array<{ signoff_id: string; role?: string; approver_id: string }>;
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
export interface ConsumeTrustReceiptParams {
|
|
544
|
+
actionHash: string;
|
|
545
|
+
executingSystem: string;
|
|
546
|
+
executionReferenceId?: string;
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
export interface ConsumeTrustReceiptResult {
|
|
550
|
+
receipt_id: string;
|
|
551
|
+
status: 'consumed' | string;
|
|
552
|
+
consumed_at: string;
|
|
553
|
+
consumed_by_system: string;
|
|
554
|
+
execution_reference_id?: string | null;
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
export interface AttestExecutionParams {
|
|
558
|
+
executedAction: Record<string, unknown>;
|
|
559
|
+
executingSystem: string;
|
|
560
|
+
executionId?: string;
|
|
561
|
+
executedAt?: string;
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
export interface ExecutionAttestation {
|
|
565
|
+
receipt_id: string;
|
|
566
|
+
status: 'executed' | string;
|
|
567
|
+
binding_status: 'match' | 'drift' | string;
|
|
568
|
+
executed_action_hash: string;
|
|
569
|
+
approved_action_hash: string;
|
|
570
|
+
execution_integrity: Record<string, unknown>;
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
export interface TrustReceiptEvidence {
|
|
574
|
+
document: Record<string, unknown> | null;
|
|
575
|
+
public_key: string | null;
|
|
576
|
+
signed: boolean;
|
|
577
|
+
verify_with: string;
|
|
578
|
+
receipt_id: string;
|
|
579
|
+
organization_id: string;
|
|
580
|
+
action: {
|
|
581
|
+
type: string;
|
|
582
|
+
action_hash: string;
|
|
583
|
+
before_state_hash?: string | null;
|
|
584
|
+
after_state_hash?: string | null;
|
|
585
|
+
};
|
|
586
|
+
policy: {
|
|
587
|
+
id: string;
|
|
588
|
+
hash: string;
|
|
589
|
+
decision: string;
|
|
590
|
+
enforcement_mode: string;
|
|
591
|
+
};
|
|
592
|
+
signoff: {
|
|
593
|
+
required: boolean;
|
|
594
|
+
approver_id?: string | null;
|
|
595
|
+
approved_at?: string | null;
|
|
596
|
+
rejected_at?: string | null;
|
|
597
|
+
events: Array<{ event_type: string; actor_id: string; at: string }>;
|
|
598
|
+
};
|
|
599
|
+
consume: {
|
|
600
|
+
consumed_at?: string | null;
|
|
601
|
+
consumed_by_system?: string | null;
|
|
602
|
+
execution_reference_id?: string | null;
|
|
603
|
+
};
|
|
604
|
+
issued_at: string;
|
|
605
|
+
expires_at: string;
|
|
606
|
+
schema_version: string;
|
|
607
|
+
[key: string]: unknown;
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
export interface SignoffRequiredContext {
|
|
611
|
+
client: unknown;
|
|
612
|
+
receipt: TrustReceipt;
|
|
613
|
+
signoff?: SignoffRequest;
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
export interface RequireReceiptParams extends CreateTrustReceiptParams {
|
|
617
|
+
executingSystem: string;
|
|
618
|
+
executionReferenceId?: string;
|
|
619
|
+
approverId?: string;
|
|
620
|
+
signoffComment?: string;
|
|
621
|
+
signoffExpiresInMinutes?: number;
|
|
622
|
+
/**
|
|
623
|
+
* Called after a signoff request is created. Complete approval externally
|
|
624
|
+
* (for example a passkey/WebAuthn ceremony or operator workflow) before
|
|
625
|
+
* returning. If omitted, the SDK fails closed and does not run the mutation.
|
|
626
|
+
*/
|
|
627
|
+
onSignoffRequired?: (ctx: SignoffRequiredContext) => Promise<void | boolean | { approved?: boolean }>;
|
|
628
|
+
/**
|
|
629
|
+
* Canonical action that actually executed. Defaults to the receipt's
|
|
630
|
+
* canonical_action, which should match when the wrapped mutation followed the
|
|
631
|
+
* approved plan.
|
|
632
|
+
*/
|
|
633
|
+
executedAction?: Record<string, unknown> | ((ctx: { receipt: TrustReceipt; result: unknown }) => Record<string, unknown>);
|
|
634
|
+
executionId?: string | ((result: unknown) => string | undefined);
|
|
635
|
+
fetchEvidence?: boolean;
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
export interface RequireReceiptResult<T> {
|
|
639
|
+
result: T;
|
|
640
|
+
receipt: TrustReceipt;
|
|
641
|
+
signoff?: SignoffRequest;
|
|
642
|
+
consume: ConsumeTrustReceiptResult;
|
|
643
|
+
execution: ExecutionAttestation;
|
|
644
|
+
evidence?: TrustReceiptEvidence;
|
|
645
|
+
}
|
|
646
|
+
|
|
428
647
|
/** A principal — the enduring actor behind one or more entities. */
|
|
429
648
|
export interface Principal {
|
|
430
649
|
principal_id: string;
|