@emilia-protocol/sdk 0.9.0 → 0.11.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/src/types.ts CHANGED
@@ -425,6 +425,234 @@ 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
+ | 'gov.vendor_payment_destination_change'
437
+ | 'gov.disbursement_release'
438
+ | 'gov.grant_disbursement'
439
+ | 'gov.provider_enrollment_change'
440
+ | 'gov.eligibility_override'
441
+ | 'vendor_bank_account_change'
442
+ | 'beneficiary_creation'
443
+ | 'large_payment_release'
444
+ | 'ai_agent_payment_action'
445
+ | 'policy_rollout';
446
+
447
+ export type GuardDecision = 'allow' | 'observe' | 'allow_with_signoff' | 'deny';
448
+ export type GuardEnforcementMode = 'observe' | 'warn' | 'enforce';
449
+ export type ReceiptStatus =
450
+ | 'issued'
451
+ | 'pending_signoff'
452
+ | 'approved_pending_consume'
453
+ | 'rejected'
454
+ | 'consumed'
455
+ | 'denied';
456
+
457
+ export interface GuardQuorumApprover {
458
+ role: string;
459
+ approver: string;
460
+ }
461
+
462
+ export interface GuardQuorumPolicy {
463
+ mode?: 'threshold' | 'ordered';
464
+ required: number;
465
+ approvers: GuardQuorumApprover[];
466
+ }
467
+
468
+ export interface CreateTrustReceiptParams {
469
+ /** Optional cross-check; the API derives the authorized organization from the authenticated key. */
470
+ organizationId?: string;
471
+ actionType: GuardActionType;
472
+ targetResourceId: string;
473
+ policyId?: string;
474
+ enforcementMode?: GuardEnforcementMode;
475
+ beforeState?: Record<string, unknown>;
476
+ afterState?: Record<string, unknown>;
477
+ targetChangedFields?: string[];
478
+ amount?: number;
479
+ currency?: string;
480
+ riskFlags?: string[];
481
+ actorRole?: string;
482
+ actorDepartment?: string;
483
+ businessHours?: boolean;
484
+ velocitySameActor24h?: number;
485
+ priorDenialsActor30d?: number;
486
+ priorChangesTarget30d?: number;
487
+ destinationAgeDays?: number;
488
+ quorumPolicy?: GuardQuorumPolicy;
489
+ metadata?: Record<string, unknown>;
490
+ }
491
+
492
+ export interface TrustReceipt {
493
+ receipt_id: string;
494
+ decision: GuardDecision;
495
+ observed_decision?: GuardDecision | null;
496
+ policy_id: string;
497
+ policy_hash: string;
498
+ action_hash: string;
499
+ before_state_hash?: string | null;
500
+ after_state_hash?: string | null;
501
+ nonce: string;
502
+ expires_at: string;
503
+ signoff_required: boolean;
504
+ signoff_request_id?: string | null;
505
+ risk_flags?: string[];
506
+ receipt_status: ReceiptStatus | string;
507
+ enforcement_mode: GuardEnforcementMode | string;
508
+ reasons?: string[];
509
+ canonical_action: Record<string, unknown>;
510
+ }
511
+
512
+ export interface TrustReceiptState {
513
+ receipt_id: string;
514
+ organization_id: string;
515
+ action_type: string;
516
+ decision: GuardDecision;
517
+ enforcement_mode: GuardEnforcementMode | string;
518
+ policy_id: string;
519
+ policy_hash: string;
520
+ action_hash: string;
521
+ before_state_hash?: string | null;
522
+ after_state_hash?: string | null;
523
+ expires_at: string;
524
+ signoff_required: boolean;
525
+ receipt_status: ReceiptStatus | string;
526
+ signoff_key_class?: 'A' | 'B' | 'C' | string | null;
527
+ timeline_event_count: number;
528
+ }
529
+
530
+ export interface RequestSignoffParams {
531
+ receiptId: string;
532
+ approverId?: string;
533
+ expiresInMinutes?: number;
534
+ comment?: string;
535
+ }
536
+
537
+ export interface SignoffRequest {
538
+ signoff_id?: string;
539
+ receipt_id: string;
540
+ action_hash: string;
541
+ initiator_id: string;
542
+ approver_id?: string;
543
+ expires_at: string;
544
+ status: 'pending' | string;
545
+ quorum?: { mode: string; required: number; count: number };
546
+ signoffs?: Array<{ signoff_id: string; role?: string; approver_id: string }>;
547
+ }
548
+
549
+ export interface ConsumeTrustReceiptParams {
550
+ actionHash: string;
551
+ executingSystem: string;
552
+ executionReferenceId?: string;
553
+ }
554
+
555
+ export interface ConsumeTrustReceiptResult {
556
+ receipt_id: string;
557
+ status: 'consumed' | string;
558
+ consumed_at: string;
559
+ consumed_by_system: string;
560
+ execution_reference_id?: string | null;
561
+ }
562
+
563
+ export interface AttestExecutionParams {
564
+ executedAction: Record<string, unknown>;
565
+ observedAction: Record<string, unknown>;
566
+ executingSystem: string;
567
+ executionId?: string;
568
+ executedAt?: string;
569
+ }
570
+
571
+ export interface ExecutionAttestation {
572
+ receipt_id: string;
573
+ status: 'executed' | string;
574
+ binding_status: 'match' | 'drift' | string;
575
+ executed_action_hash: string;
576
+ approved_action_hash: string;
577
+ execution_integrity: Record<string, unknown>;
578
+ }
579
+
580
+ export interface TrustReceiptEvidence {
581
+ document: Record<string, unknown> | null;
582
+ public_key: string | null;
583
+ signed: boolean;
584
+ verify_with: string;
585
+ receipt_id: string;
586
+ organization_id: string;
587
+ action: {
588
+ type: string;
589
+ action_hash: string;
590
+ before_state_hash?: string | null;
591
+ after_state_hash?: string | null;
592
+ };
593
+ policy: {
594
+ id: string;
595
+ hash: string;
596
+ decision: string;
597
+ enforcement_mode: string;
598
+ };
599
+ signoff: {
600
+ required: boolean;
601
+ approver_id?: string | null;
602
+ approved_at?: string | null;
603
+ rejected_at?: string | null;
604
+ events: Array<{ event_type: string; actor_id: string; at: string }>;
605
+ };
606
+ consume: {
607
+ consumed_at?: string | null;
608
+ consumed_by_system?: string | null;
609
+ execution_reference_id?: string | null;
610
+ };
611
+ issued_at: string;
612
+ expires_at: string;
613
+ schema_version: string;
614
+ [key: string]: unknown;
615
+ }
616
+
617
+ export interface SignoffRequiredContext {
618
+ client: unknown;
619
+ receipt: TrustReceipt;
620
+ signoff?: SignoffRequest;
621
+ }
622
+
623
+ export interface RequireReceiptParams extends CreateTrustReceiptParams {
624
+ executingSystem: string;
625
+ executionReferenceId?: string;
626
+ approverId?: string;
627
+ signoffComment?: string;
628
+ signoffExpiresInMinutes?: number;
629
+ /**
630
+ * Called after a signoff request is created. Complete approval externally
631
+ * (for example a passkey/WebAuthn ceremony or operator workflow) before
632
+ * returning. If omitted, the SDK fails closed and does not run the mutation.
633
+ */
634
+ onSignoffRequired?: (ctx: SignoffRequiredContext) => Promise<void | boolean | { approved?: boolean }>;
635
+ /** Legacy explicit execution report. Prefer observedAction for new integrations. */
636
+ executedAction?: Record<string, unknown> | ((ctx: { receipt: TrustReceipt; result: unknown }) => Record<string, unknown>);
637
+ /**
638
+ * Action fields independently observed by the executor after mutation. If
639
+ * omitted, no execution attestation is emitted.
640
+ */
641
+ observedAction?: Record<string, unknown> | ((ctx: { receipt: TrustReceipt; result: unknown }) => Record<string, unknown>);
642
+ executionId?: string | ((result: unknown) => string | undefined);
643
+ fetchEvidence?: boolean;
644
+ }
645
+
646
+ export interface RequireReceiptResult<T> {
647
+ result: T;
648
+ receipt: TrustReceipt;
649
+ signoff?: SignoffRequest;
650
+ consume: ConsumeTrustReceiptResult;
651
+ execution?: ExecutionAttestation;
652
+ executionStatus: 'attested' | 'unobserved';
653
+ evidence?: TrustReceiptEvidence;
654
+ }
655
+
428
656
  /** A principal — the enduring actor behind one or more entities. */
429
657
  export interface Principal {
430
658
  principal_id: string;
@@ -472,16 +700,6 @@ export interface LineageResult {
472
700
  }>;
473
701
  }
474
702
 
475
- /** Result of a batch receipt submission. */
476
- export interface BatchReceiptResult {
477
- results: Array<{
478
- entity_id: string;
479
- success: boolean;
480
- receipt_id?: string;
481
- error?: string;
482
- }>;
483
- }
484
-
485
703
  /** Result of a bilateral receipt confirmation. */
486
704
  export interface ConfirmReceiptResult {
487
705
  receipt_id: string;
@@ -497,7 +715,7 @@ export interface TrustPolicyDefinition {
497
715
  min_confidence?: ConfidenceTier;
498
716
  }
499
717
 
500
- /** Public proof metrics from /api/stats. */
718
+ /** Authenticated operator metrics from /api/stats. */
501
719
  export interface EPStats {
502
720
  total_entities: number;
503
721
  trust_surfaces: number;