@agledger/sdk 1.1.0 → 2.0.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 (46) hide show
  1. package/dist/client.d.ts +2 -0
  2. package/dist/client.js +3 -0
  3. package/dist/errors.d.ts +14 -0
  4. package/dist/errors.js +26 -0
  5. package/dist/http.d.ts +2 -1
  6. package/dist/http.js +7 -3
  7. package/dist/index.d.ts +5 -1
  8. package/dist/index.js +6 -0
  9. package/dist/mandate-lifecycle.d.ts +23 -0
  10. package/dist/mandate-lifecycle.js +54 -0
  11. package/dist/prompt-context.d.ts +16 -0
  12. package/dist/prompt-context.js +47 -0
  13. package/dist/resources/admin.d.ts +15 -8
  14. package/dist/resources/admin.js +13 -5
  15. package/dist/resources/compliance.d.ts +7 -0
  16. package/dist/resources/compliance.js +7 -3
  17. package/dist/resources/dashboard.d.ts +3 -0
  18. package/dist/resources/dashboard.js +3 -0
  19. package/dist/resources/disputes.d.ts +5 -0
  20. package/dist/resources/disputes.js +5 -0
  21. package/dist/resources/enterprises.d.ts +27 -0
  22. package/dist/resources/enterprises.js +43 -0
  23. package/dist/resources/events.d.ts +6 -1
  24. package/dist/resources/events.js +4 -0
  25. package/dist/resources/health.d.ts +2 -0
  26. package/dist/resources/health.js +2 -0
  27. package/dist/resources/mandates.d.ts +13 -0
  28. package/dist/resources/mandates.js +25 -3
  29. package/dist/resources/notarize.d.ts +8 -0
  30. package/dist/resources/notarize.js +8 -8
  31. package/dist/resources/proxy.d.ts +20 -4
  32. package/dist/resources/proxy.js +20 -4
  33. package/dist/resources/reputation.d.ts +2 -0
  34. package/dist/resources/reputation.js +2 -0
  35. package/dist/resources/schemas.d.ts +3 -0
  36. package/dist/resources/schemas.js +3 -0
  37. package/dist/resources/verification.d.ts +2 -0
  38. package/dist/resources/verification.js +2 -0
  39. package/dist/resources/webhooks.d.ts +6 -0
  40. package/dist/resources/webhooks.js +7 -1
  41. package/dist/scopes.d.ts +41 -0
  42. package/dist/scopes.js +67 -0
  43. package/dist/types.d.ts +186 -3
  44. package/dist/webhooks/verify.d.ts +33 -0
  45. package/dist/webhooks/verify.js +32 -0
  46. package/package.json +5 -3
@@ -0,0 +1,41 @@
1
+ /**
2
+ * AGLedger™ SDK — API Key Scopes
3
+ * Patent Pending. Copyright 2026 AGLedger LLC. All rights reserved.
4
+ *
5
+ * Scopes narrow what a key can do within its role's ceiling.
6
+ * null scopes = full access for the role (backward compat).
7
+ */
8
+ export declare const Scopes: {
9
+ readonly MANDATES_READ: "mandates:read";
10
+ readonly MANDATES_WRITE: "mandates:write";
11
+ readonly RECEIPTS_READ: "receipts:read";
12
+ readonly RECEIPTS_WRITE: "receipts:write";
13
+ readonly WEBHOOKS_READ: "webhooks:read";
14
+ readonly WEBHOOKS_MANAGE: "webhooks:manage";
15
+ readonly AUDIT_READ: "audit:read";
16
+ readonly AUDIT_ANALYZE: "audit:analyze";
17
+ readonly COMPLIANCE_READ: "compliance:read";
18
+ readonly COMPLIANCE_WRITE: "compliance:write";
19
+ readonly AGENTS_READ: "agents:read";
20
+ readonly AGENTS_MANAGE: "agents:manage";
21
+ readonly DISPUTES_READ: "disputes:read";
22
+ readonly DISPUTES_MANAGE: "disputes:manage";
23
+ readonly DASHBOARD_READ: "dashboard:read";
24
+ readonly EVENTS_READ: "events:read";
25
+ readonly SIGNALS_READ: "signals:read";
26
+ readonly REPUTATION_READ: "reputation:read";
27
+ readonly ADMIN_KEYS: "admin:keys";
28
+ readonly ADMIN_SYSTEM: "admin:system";
29
+ readonly ADMIN_TRUST: "admin:trust";
30
+ };
31
+ export type Scope = (typeof Scopes)[keyof typeof Scopes];
32
+ /** Scope profile definition. */
33
+ export interface ScopeProfile {
34
+ name: string;
35
+ description: string;
36
+ scopes: readonly Scope[];
37
+ }
38
+ /** Pre-defined scope profiles matching the API. */
39
+ export declare const ScopeProfiles: Record<string, ScopeProfile>;
40
+ export type ScopeProfileName = 'sidecar' | 'dashboard' | 'iac-pipeline' | 'agent-full' | 'agent-readonly' | (string & {});
41
+ //# sourceMappingURL=scopes.d.ts.map
package/dist/scopes.js ADDED
@@ -0,0 +1,67 @@
1
+ /**
2
+ * AGLedger™ SDK — API Key Scopes
3
+ * Patent Pending. Copyright 2026 AGLedger LLC. All rights reserved.
4
+ *
5
+ * Scopes narrow what a key can do within its role's ceiling.
6
+ * null scopes = full access for the role (backward compat).
7
+ */
8
+ export const Scopes = {
9
+ // Mandate lifecycle
10
+ MANDATES_READ: 'mandates:read',
11
+ MANDATES_WRITE: 'mandates:write',
12
+ // Receipts
13
+ RECEIPTS_READ: 'receipts:read',
14
+ RECEIPTS_WRITE: 'receipts:write',
15
+ // Webhooks
16
+ WEBHOOKS_READ: 'webhooks:read',
17
+ WEBHOOKS_MANAGE: 'webhooks:manage',
18
+ // Audit & compliance
19
+ AUDIT_READ: 'audit:read',
20
+ AUDIT_ANALYZE: 'audit:analyze',
21
+ COMPLIANCE_READ: 'compliance:read',
22
+ COMPLIANCE_WRITE: 'compliance:write',
23
+ // Agents
24
+ AGENTS_READ: 'agents:read',
25
+ AGENTS_MANAGE: 'agents:manage',
26
+ // Disputes
27
+ DISPUTES_READ: 'disputes:read',
28
+ DISPUTES_MANAGE: 'disputes:manage',
29
+ // Dashboard & events
30
+ DASHBOARD_READ: 'dashboard:read',
31
+ EVENTS_READ: 'events:read',
32
+ SIGNALS_READ: 'signals:read',
33
+ REPUTATION_READ: 'reputation:read',
34
+ // Administration
35
+ ADMIN_KEYS: 'admin:keys',
36
+ ADMIN_SYSTEM: 'admin:system',
37
+ ADMIN_TRUST: 'admin:trust',
38
+ };
39
+ /** Pre-defined scope profiles matching the API. */
40
+ export const ScopeProfiles = {
41
+ sidecar: {
42
+ name: 'sidecar',
43
+ description: 'Governance sidecar — mandate and receipt operations',
44
+ scopes: [Scopes.MANDATES_READ, Scopes.MANDATES_WRITE, Scopes.RECEIPTS_WRITE, Scopes.WEBHOOKS_MANAGE],
45
+ },
46
+ dashboard: {
47
+ name: 'dashboard',
48
+ description: 'Read-only monitoring and audit',
49
+ scopes: [Scopes.DASHBOARD_READ, Scopes.AUDIT_READ, Scopes.EVENTS_READ, Scopes.SIGNALS_READ, Scopes.DISPUTES_READ, Scopes.REPUTATION_READ],
50
+ },
51
+ 'iac-pipeline': {
52
+ name: 'iac-pipeline',
53
+ description: 'Infrastructure provisioning — agents, webhooks, keys',
54
+ scopes: [Scopes.AGENTS_MANAGE, Scopes.WEBHOOKS_MANAGE, Scopes.ADMIN_KEYS],
55
+ },
56
+ 'agent-full': {
57
+ name: 'agent-full',
58
+ description: 'Standard agent — mandate and receipt operations',
59
+ scopes: [Scopes.MANDATES_READ, Scopes.MANDATES_WRITE, Scopes.RECEIPTS_WRITE],
60
+ },
61
+ 'agent-readonly': {
62
+ name: 'agent-readonly',
63
+ description: 'Read-only agent — view mandate history',
64
+ scopes: [Scopes.MANDATES_READ, Scopes.RECEIPTS_READ],
65
+ },
66
+ };
67
+ //# sourceMappingURL=scopes.js.map
package/dist/types.d.ts CHANGED
@@ -85,6 +85,7 @@ export interface BulkCreateResult {
85
85
  failed: number;
86
86
  };
87
87
  }
88
+ /** Known values: ACH-PROC-v1, ACH-DLVR-v1, ACH-DATA-v1, ACH-TXN-v1, ACH-ORCH-v1, ACH-COMM-v1, ACH-AUTH-v1, ACH-INFRA-v1, ACH-DEL-v1, ACH-ANALYZE-v1, ACH-COORD-v1. Accepts any string for forward compatibility. */
88
89
  export type ContractType = 'ACH-PROC-v1' | 'ACH-DLVR-v1' | 'ACH-DATA-v1' | 'ACH-TXN-v1' | 'ACH-ORCH-v1' | 'ACH-COMM-v1' | 'ACH-AUTH-v1' | 'ACH-INFRA-v1' | 'ACH-DEL-v1' | 'ACH-ANALYZE-v1' | 'ACH-COORD-v1' | (string & {});
89
90
  export interface Denomination {
90
91
  amount: number;
@@ -381,55 +382,131 @@ export interface SchemaValidationResult {
381
382
  schemaPath?: string;
382
383
  }>;
383
384
  }
384
- export type MandateStatus = 'DRAFT' | 'PROPOSED' | 'ACCEPTED' | 'COUNTER_PROPOSED' | 'REJECTED' | 'REGISTERED' | 'ACTIVE' | 'PENDING_VERIFICATION' | 'FULFILLED' | 'FAILED' | 'DISPUTED' | 'CANCELLED' | 'REMEDIATED' | 'EXPIRED' | 'RECEIPT_INVALID' | 'RECEIPT_ACCEPTED' | 'VERIFYING' | 'VERIFIED_PASS' | 'VERIFIED_FAIL' | 'CANCELLED_DRAFT' | 'CANCELLED_PRE_WORK' | 'CANCELLED_IN_PROGRESS' | (string & {});
385
+ /** Known values: DRAFT, PROPOSED, ACCEPTED, COUNTER_PROPOSED, REJECTED, REGISTERED, ACTIVE, PENDING_VERIFICATION, FULFILLED, FAILED, DISPUTED, CANCELLED, REMEDIATED, EXPIRED, RECEIPT_INVALID, RECEIPT_ACCEPTED, VERIFYING, VERIFIED_PASS, VERIFIED_FAIL, CANCELLED_DRAFT, CANCELLED_PRE_WORK, CANCELLED_IN_PROGRESS. Accepts any string for forward compatibility. */
386
+ export type MandateStatus = 'DRAFT' | 'PROPOSED' | 'ACCEPTED' | 'COUNTER_PROPOSED' | 'REJECTED' | 'REGISTERED' | 'ACTIVE' | 'PENDING_VERIFICATION' | 'FULFILLED' | 'FAILED' | 'DISPUTED' | 'CANCELLED' | 'REMEDIATED' | 'EXPIRED' | 'RECEIPT_INVALID' | 'RECEIPT_ACCEPTED' | 'VERIFYING' | 'VERIFIED_PASS' | 'VERIFIED_FAIL' | 'CANCELLED_DRAFT' | 'CANCELLED_PRE_WORK' | 'CANCELLED_IN_PROGRESS' | 'REVISION_REQUESTED' | (string & {});
387
+ /** Known values: register, activate, settle, cancel, refund. Accepts any string for forward compatibility. */
385
388
  export type MandateTransitionAction = 'register' | 'activate' | 'settle' | 'cancel' | 'refund' | (string & {});
386
389
  export type OperatingMode = 'standard' | 'encrypted' | 'cleartext';
390
+ /** Known values: auto, principal, gated. Accepts any string for forward compatibility. */
391
+ export type VerificationMode = 'auto' | 'principal' | 'gated' | (string & {});
387
392
  export type RiskClassification = 'unacceptable' | 'high' | 'limited' | 'minimal' | 'unclassified';
393
+ /**
394
+ * A mandate — a registered commitment between a principal and a performer.
395
+ * Records what was asked, by whom, and when. The contract is the product.
396
+ *
397
+ * @example
398
+ * ```ts
399
+ * const mandate = await client.mandates.create({
400
+ * enterpriseId: 'ent_123',
401
+ * contractType: 'ACH-PROC-v1',
402
+ * contractVersion: '1',
403
+ * platform: 'internal',
404
+ * criteria: { item: 'widgets', maxQuantity: 100, maxUnitPrice: { amount: 20, currency: 'USD' } },
405
+ * });
406
+ * ```
407
+ */
388
408
  export interface Mandate {
409
+ /** Unique mandate ID (UUID). */
389
410
  id: string;
411
+ /** Enterprise that owns this mandate. */
390
412
  enterpriseId: string;
413
+ /** Agent assigned to this mandate, or null if unassigned. */
391
414
  agentId: string | null;
415
+ /** Agentic Contract Specification type (e.g., 'ACH-PROC-v1'). */
392
416
  contractType: ContractType;
417
+ /** Version of the contract schema. */
393
418
  contractVersion: string;
419
+ /** Platform where this mandate operates. */
394
420
  platform: string;
421
+ /** External reference ID on the platform. */
395
422
  platformRef?: string;
423
+ /** Current lifecycle status. Use `getValidTransitions()` to see allowed next states. */
396
424
  status: MandateStatus;
425
+ /** Acceptance criteria — what the performer must deliver. Typed per contract type. */
397
426
  criteria: Record<string, unknown>;
427
+ /** Tolerance bands for numeric criteria (e.g., quantity_pct: 5 allows 5% variance). */
398
428
  tolerance?: Record<string, unknown>;
429
+ /** ISO 8601 deadline for completion. */
399
430
  deadline?: string;
431
+ /** Commission percentage for the performing agent. */
400
432
  commissionPct?: number;
433
+ /** Operating mode: standard (default), encrypted, or cleartext. */
401
434
  operatingMode?: OperatingMode;
435
+ /** Verification mode: auto (rules auto-settle), principal (hold for verdict), gated (rules then verdict). */
436
+ verificationMode?: VerificationMode;
437
+ /** EU AI Act risk classification. */
402
438
  riskClassification?: RiskClassification;
439
+ /** EU AI Act domain (e.g., 'healthcare', 'finance'). */
403
440
  euAiActDomain?: string;
441
+ /** Human oversight configuration for EU AI Act compliance. */
404
442
  humanOversight?: Record<string, unknown>;
443
+ /** Performer's response to a proposed mandate. */
405
444
  acceptanceStatus?: 'PENDING' | 'ACCEPTED' | 'REJECTED' | 'COUNTER_PROPOSED';
445
+ /** Project grouping reference for related mandates. */
406
446
  projectRef?: string;
447
+ /** Parent mandate ID in a delegation chain. */
407
448
  parentMandateId?: string;
449
+ /** Root mandate ID at the top of the delegation chain. */
408
450
  rootMandateId?: string;
451
+ /** Depth in the delegation chain (0 = root). */
409
452
  chainDepth?: number;
453
+ /** Reason provided for the last state transition. */
410
454
  lastTransitionReason?: string | null;
455
+ /** Actor who triggered the last state transition. */
411
456
  lastTransitionBy?: string | null;
457
+ /** Number of receipt submissions so far. */
458
+ submissionCount: number;
459
+ /** Maximum allowed submissions, or null for unlimited. */
460
+ maxSubmissions: number | null;
461
+ /** Optimistic concurrency version. */
412
462
  version: number;
463
+ /** ISO 8601 creation timestamp. */
413
464
  createdAt: string;
465
+ /** ISO 8601 last update timestamp. */
414
466
  updatedAt: string;
467
+ /** ISO 8601 timestamp when the mandate was activated. */
415
468
  activatedAt?: string;
469
+ /** ISO 8601 timestamp when the mandate was fulfilled. */
416
470
  fulfilledAt?: string;
417
471
  }
472
+ /**
473
+ * Parameters for creating a new mandate via enterprise auth.
474
+ * For agent-to-agent mandates, use {@link CreateAgentMandateParams} with `mandates.createAgent()`.
475
+ */
418
476
  export interface CreateMandateParams {
477
+ /** Enterprise ID that owns this mandate. */
419
478
  enterpriseId: string;
479
+ /** Contract type (e.g., 'ACH-PROC-v1'). Determines criteria schema. */
420
480
  contractType: ContractType;
481
+ /** Contract schema version. */
421
482
  contractVersion: string;
483
+ /** Platform identifier. */
422
484
  platform: string;
485
+ /** External reference ID on the platform. */
423
486
  platformRef?: string;
487
+ /** Project grouping reference. */
424
488
  projectRef?: string;
489
+ /** Acceptance criteria. Typed per contract type when using generic overload. */
425
490
  criteria: Record<string, unknown>;
491
+ /** Numeric tolerance bands (e.g., `{ quantity_pct: 5 }`). */
426
492
  tolerance?: Record<string, unknown>;
493
+ /** ISO 8601 deadline for completion. */
427
494
  deadline?: string;
495
+ /** Agent ID to assign as performer. */
428
496
  agentId?: string;
497
+ /** Commission percentage for the performing agent. */
429
498
  commissionPct?: number;
499
+ /** Max receipt submissions allowed (1-100). Null/omit for unlimited. */
500
+ maxSubmissions?: number;
501
+ /** Operating mode: standard (default), encrypted, or cleartext. */
430
502
  operatingMode?: OperatingMode;
503
+ /** Verification mode: auto (default, rules auto-settle), principal (hold for verdict), gated (rules then verdict). */
504
+ verificationMode?: VerificationMode;
505
+ /** EU AI Act risk classification. */
431
506
  riskClassification?: RiskClassification;
507
+ /** EU AI Act domain. */
432
508
  euAiActDomain?: string;
509
+ /** Human oversight configuration. */
433
510
  humanOversight?: Record<string, unknown>;
434
511
  }
435
512
  export interface UpdateMandateParams {
@@ -442,6 +519,7 @@ export interface UpdateMandateParams {
442
519
  }
443
520
  export interface ListMandatesParams extends ListParams {
444
521
  enterpriseId: string;
522
+ status?: MandateStatus;
445
523
  }
446
524
  export interface SearchMandatesParams extends ListParams {
447
525
  enterpriseId: string;
@@ -473,30 +551,53 @@ export interface CreateAgentMandateParams {
473
551
  tolerance?: Record<string, unknown>;
474
552
  parentMandateId?: string;
475
553
  commissionPct?: number;
554
+ maxSubmissions?: number;
476
555
  deadline?: string;
556
+ verificationMode?: VerificationMode;
477
557
  }
478
558
  export interface RespondToMandateParams {
479
559
  action: 'accept' | 'reject' | 'counter';
480
560
  reason?: string;
481
561
  counterTerms?: Record<string, unknown>;
482
562
  }
563
+ /** Known values: SUBMITTED, ACCEPTED, REJECTED, INVALID. Accepts any string for forward compatibility. */
483
564
  export type ReceiptStatus = 'SUBMITTED' | 'ACCEPTED' | 'REJECTED' | 'INVALID' | (string & {});
565
+ /**
566
+ * A receipt — structured evidence submitted by a performer claiming completion of a mandate.
567
+ * The principal reviews the receipt and renders a verdict (accept/reject).
568
+ */
484
569
  export interface Receipt {
570
+ /** Unique receipt ID (UUID). */
485
571
  id: string;
572
+ /** Mandate this receipt is for. */
486
573
  mandateId: string;
574
+ /** Agent that submitted the receipt. */
487
575
  agentId: string;
576
+ /** Receipt processing status. */
488
577
  status: ReceiptStatus;
578
+ /** Evidence of completion. Typed per contract type. */
489
579
  evidence: Record<string, unknown>;
580
+ /** SHA-256 hash of the evidence payload. */
490
581
  evidenceHash?: string;
582
+ /** Free-text notes from the performer. */
491
583
  notes?: string;
584
+ /** Current verification phase (e.g., 'phase1', 'phase2'). */
492
585
  verificationPhase?: string;
586
+ /** Detailed verification rule results. */
493
587
  verificationResult?: Record<string, unknown>;
588
+ /** Overall verification outcome: PASS, FAIL, or REVIEW_REQUIRED. */
494
589
  verificationOutcome?: VerificationOutcome;
590
+ /** ISO 8601 timestamp when verification completed. */
495
591
  verificationCompletedAt?: string;
592
+ /** Schema validation errors, if the receipt was invalid. */
496
593
  validationErrors?: string[] | null;
594
+ /** Current status of the parent mandate (denormalized for convenience). */
497
595
  mandateStatus?: MandateStatus;
596
+ /** Idempotency key used when submitting. */
498
597
  idempotencyKey?: string | null;
598
+ /** ISO 8601 creation timestamp. */
499
599
  createdAt: string;
600
+ /** ISO 8601 last update timestamp. */
500
601
  updatedAt?: string;
501
602
  }
502
603
  export interface SubmitReceiptParams {
@@ -509,7 +610,9 @@ export interface UpdateReceiptParams {
509
610
  evidence?: Record<string, unknown>;
510
611
  notes?: string;
511
612
  }
613
+ /** Known values: PASS, FAIL, REVIEW_REQUIRED. Accepts any string for forward compatibility. */
512
614
  export type VerificationOutcome = 'PASS' | 'FAIL' | 'REVIEW_REQUIRED' | (string & {});
615
+ /** Known values: SETTLE, HOLD, RELEASE. Accepts any string for forward compatibility. */
513
616
  export type SettlementSignal = 'SETTLE' | 'HOLD' | 'RELEASE' | (string & {});
514
617
  export interface VerificationResult {
515
618
  mandateId: string;
@@ -527,6 +630,7 @@ export interface VerificationStatus {
527
630
  lastVerifiedAt?: string;
528
631
  pendingRules?: string[];
529
632
  }
633
+ /** Known values: OPEN, TIER_1_REVIEW, EVIDENCE_WINDOW, TIER_2_REVIEW, ESCALATED, TIER_3_ARBITRATION, RESOLVED, WITHDRAWN. Accepts any string for forward compatibility. */
530
634
  export type DisputeStatus = 'OPEN' | 'TIER_1_REVIEW' | 'EVIDENCE_WINDOW' | 'TIER_2_REVIEW' | 'ESCALATED' | 'TIER_3_ARBITRATION' | 'RESOLVED' | 'WITHDRAWN' | (string & {});
531
635
  export interface Dispute {
532
636
  id: string;
@@ -551,7 +655,8 @@ export interface ResolveDisputeParams {
551
655
  resolution: string;
552
656
  amount?: number;
553
657
  }
554
- export type WebhookEventType = 'receipt.submitted' | 'receipt.verified' | 'receipt.accepted' | 'receipt.rejected' | 'mandate.created' | 'mandate.registered' | 'mandate.activated' | 'mandate.fulfilled' | 'mandate.failed' | 'mandate.cancelled' | 'mandate.delegated' | 'mandate.released' | 'dispute.created' | 'dispute.resolved' | 'signal.emitted' | 'verification.complete' | (string & {});
658
+ /** Known values: receipt.submitted, receipt.verified, receipt.accepted, receipt.rejected, mandate.created, mandate.registered, mandate.activated, mandate.fulfilled, mandate.failed, mandate.cancelled, mandate.delegated, mandate.released, dispute.created, dispute.resolved, signal.emitted, verification.complete. Accepts any string for forward compatibility. */
659
+ export type WebhookEventType = 'receipt.submitted' | 'receipt.verified' | 'receipt.accepted' | 'receipt.rejected' | 'mandate.created' | 'mandate.registered' | 'mandate.activated' | 'mandate.fulfilled' | 'mandate.failed' | 'mandate.cancelled' | 'mandate.delegated' | 'mandate.released' | 'mandate.revision_requested' | 'dispute.created' | 'dispute.resolved' | 'signal.emitted' | 'verification.complete' | (string & {});
555
660
  export interface Webhook {
556
661
  id: string;
557
662
  url: string;
@@ -596,6 +701,7 @@ export interface WebhookTestResult {
596
701
  success?: boolean;
597
702
  deliveryId?: string;
598
703
  }
704
+ /** Known values: platinum, gold, silver, bronze. Accepts any string for forward compatibility. */
599
705
  export type ReputationTier = 'platinum' | 'gold' | 'silver' | 'bronze' | (string & {});
600
706
  export interface ReputationScore {
601
707
  agentId: string;
@@ -756,6 +862,10 @@ export interface AccountProfile {
756
862
  enterpriseId?: string;
757
863
  capabilities?: ContractType[];
758
864
  sandboxMode?: boolean;
865
+ /** API key scopes. Null = full access for the role. */
866
+ scopes?: string[] | null;
867
+ /** Scope profile name if key was created with a profile. */
868
+ scopeProfile?: string | null;
759
869
  createdAt: string;
760
870
  }
761
871
  export interface HealthResponse {
@@ -806,8 +916,32 @@ export interface AdminApiKey {
806
916
  ownerId: string;
807
917
  ownerType: AccountType;
808
918
  active: boolean;
919
+ /** API key scopes. Null = full access for the role. */
920
+ scopes?: string[] | null;
921
+ /** Scope profile name if created with a profile. */
922
+ scopeProfile?: string | null;
809
923
  createdAt: string;
810
924
  lastUsedAt?: string;
925
+ expiresAt?: string | null;
926
+ }
927
+ export interface CreateApiKeyParams {
928
+ ownerId: string;
929
+ ownerType: AccountType;
930
+ /** Explicit scopes to set on the key. */
931
+ scopes?: string[];
932
+ /** Convenience profile name — expands to a predefined scope array. Takes precedence over `scopes`. */
933
+ scopeProfile?: string;
934
+ /** Optional expiration date (ISO 8601). */
935
+ expiresAt?: string;
936
+ /** IP allowlist. Null = any IP. */
937
+ allowedIps?: string[];
938
+ }
939
+ /** Result of creating an API key via the admin endpoint. */
940
+ export interface CreateApiKeyResult {
941
+ apiKey: string;
942
+ keyId: string;
943
+ scopes: string[] | null;
944
+ scopeProfile: string | null;
811
945
  }
812
946
  export interface WebhookDlqEntry {
813
947
  id: string;
@@ -860,6 +994,7 @@ export interface JsonRpcResponse {
860
994
  id?: string | number;
861
995
  }
862
996
  export type ProxyMode = 'observe' | 'advisory' | 'enforced';
997
+ /** Known values: ALLOWED, BLOCKED, ANNOTATED. Accepts any string for forward compatibility. */
863
998
  export type InterceptorAction = 'ALLOWED' | 'BLOCKED' | 'ANNOTATED' | (string & {});
864
999
  export type ConfidenceLevel = 'low' | 'medium' | 'high';
865
1000
  export type SidecarMandateStatus = 'SHADOW' | 'FORMALIZED' | 'DISMISSED';
@@ -1040,6 +1175,7 @@ export interface AlignmentAnalysis {
1040
1175
  missingCategories?: string[];
1041
1176
  recommendations?: string[];
1042
1177
  }
1178
+ /** Known values: NOTARIZED, ACCEPTED, COUNTER_PROPOSED, RECEIPT_SUBMITTED, VERDICT_PASS, VERDICT_FAIL. Accepts any string for forward compatibility. */
1043
1179
  export type NotarizeStatus = 'NOTARIZED' | 'ACCEPTED' | 'COUNTER_PROPOSED' | 'RECEIPT_SUBMITTED' | 'VERDICT_PASS' | 'VERDICT_FAIL' | (string & {});
1044
1180
  export interface NotarizedMandate {
1045
1181
  id: string;
@@ -1083,7 +1219,7 @@ export interface NotarizeReceiptResult {
1083
1219
  payload: Record<string, unknown>;
1084
1220
  }
1085
1221
  export interface NotarizeVerdictParams {
1086
- outcome: 'PASS' | 'FAIL';
1222
+ verdict: 'PASS' | 'FAIL';
1087
1223
  reason?: string;
1088
1224
  }
1089
1225
  export interface NotarizeVerifyParams {
@@ -1099,6 +1235,53 @@ export interface NotarizeHistory {
1099
1235
  mandateId: string;
1100
1236
  transitions: NotarizeTransition[];
1101
1237
  }
1238
+ /** Known values: approved, suspended, revoked. Accepts any string for forward compatibility. */
1239
+ export type EnterpriseAgentStatus = 'approved' | 'suspended' | 'revoked' | (string & {});
1240
+ export interface EnterpriseAgentRecord {
1241
+ enterpriseId: string;
1242
+ agentId: string;
1243
+ status: EnterpriseAgentStatus;
1244
+ approvedBy: string | null;
1245
+ approvedAt: string;
1246
+ suspendedAt: string | null;
1247
+ revokedAt: string | null;
1248
+ reason: string | null;
1249
+ }
1250
+ export interface ApprovalConfig {
1251
+ agentApprovalRequired: boolean;
1252
+ allowSelfApproval: boolean;
1253
+ }
1254
+ export interface ApproveAgentParams {
1255
+ reason?: string;
1256
+ }
1257
+ export interface RevokeAgentParams {
1258
+ reason?: string;
1259
+ }
1260
+ export interface UpdateAgentStatusParams {
1261
+ status: 'suspended' | 'approved';
1262
+ reason?: string;
1263
+ }
1264
+ export interface BulkApproveAgentParams {
1265
+ agents: Array<{
1266
+ agentId: string;
1267
+ reason?: string;
1268
+ }>;
1269
+ }
1270
+ export interface BulkApproveResult {
1271
+ results: Array<{
1272
+ agentId: string;
1273
+ status: 'approved' | 'failed';
1274
+ error?: string;
1275
+ }>;
1276
+ summary: {
1277
+ total: number;
1278
+ approved: number;
1279
+ failed: number;
1280
+ };
1281
+ }
1282
+ export interface ListEnterpriseAgentsParams extends ListParams {
1283
+ status?: EnterpriseAgentStatus;
1284
+ }
1102
1285
  export interface ApiErrorResponse {
1103
1286
  error: string;
1104
1287
  message: string;
@@ -5,6 +5,39 @@
5
5
  * Separate export to avoid pulling node:crypto into browser bundles.
6
6
  * Import via: import { verifySignature } from '@agledger/sdk/webhooks'
7
7
  */
8
+ import type { WebhookEventType, Mandate, Receipt, VerificationResult, Dispute } from '../types.js';
9
+ /** A verified webhook event with typed payload. */
10
+ export interface WebhookEvent<T extends WebhookEventType = WebhookEventType> {
11
+ /** Event type (e.g., 'mandate.created', 'receipt.submitted'). */
12
+ type: T;
13
+ /** Event payload — the resource that triggered the event. */
14
+ data: T extends `mandate.${string}` ? Mandate : T extends `receipt.${string}` ? Receipt : T extends `verification.${string}` ? VerificationResult : T extends `dispute.${string}` ? Dispute : Record<string, unknown>;
15
+ /** ISO 8601 timestamp of the event. */
16
+ timestamp: string;
17
+ /** Unique event ID. */
18
+ id?: string;
19
+ }
20
+ /**
21
+ * Verify a webhook signature and parse the payload in one step.
22
+ *
23
+ * @param rawBody - The raw request body string (do NOT parse JSON first)
24
+ * @param header - The x-agledger-signature header value
25
+ * @param secrets - One or more webhook secrets (array for key rotation)
26
+ * @param toleranceSeconds - Max age in seconds (default/max: 300)
27
+ * @returns Parsed and typed webhook event
28
+ * @throws Error if signature is invalid or body cannot be parsed
29
+ *
30
+ * @example
31
+ * ```ts
32
+ * import { constructEvent } from '@agledger/sdk/webhooks';
33
+ *
34
+ * const event = constructEvent(rawBody, req.headers['x-agledger-signature'], secret);
35
+ * if (event.type === 'mandate.created') {
36
+ * console.log(event.data.id); // typed as Mandate
37
+ * }
38
+ * ```
39
+ */
40
+ export declare function constructEvent(rawBody: string, header: string, secrets: string | string[], toleranceSeconds?: number): WebhookEvent;
8
41
  export interface SignResult {
9
42
  header: string;
10
43
  timestamp: number;
@@ -7,6 +7,38 @@
7
7
  */
8
8
  import { createHmac, timingSafeEqual } from 'node:crypto';
9
9
  const MAX_TOLERANCE_SECONDS = 300;
10
+ /**
11
+ * Verify a webhook signature and parse the payload in one step.
12
+ *
13
+ * @param rawBody - The raw request body string (do NOT parse JSON first)
14
+ * @param header - The x-agledger-signature header value
15
+ * @param secrets - One or more webhook secrets (array for key rotation)
16
+ * @param toleranceSeconds - Max age in seconds (default/max: 300)
17
+ * @returns Parsed and typed webhook event
18
+ * @throws Error if signature is invalid or body cannot be parsed
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * import { constructEvent } from '@agledger/sdk/webhooks';
23
+ *
24
+ * const event = constructEvent(rawBody, req.headers['x-agledger-signature'], secret);
25
+ * if (event.type === 'mandate.created') {
26
+ * console.log(event.data.id); // typed as Mandate
27
+ * }
28
+ * ```
29
+ */
30
+ export function constructEvent(rawBody, header, secrets, toleranceSeconds) {
31
+ if (!verifySignature(rawBody, header, secrets, toleranceSeconds)) {
32
+ throw new Error('Webhook signature verification failed');
33
+ }
34
+ const parsed = JSON.parse(rawBody);
35
+ return {
36
+ type: parsed.type ?? parsed.event ?? 'unknown',
37
+ data: parsed.data ?? parsed.payload ?? parsed,
38
+ timestamp: parsed.timestamp ?? parsed.created_at ?? new Date().toISOString(),
39
+ id: parsed.id ?? parsed.event_id,
40
+ };
41
+ }
10
42
  /**
11
43
  * Sign a payload (for testing purposes).
12
44
  * Returns the header string, timestamp, and hex signature.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agledger/sdk",
3
- "version": "1.1.0",
3
+ "version": "2.0.0",
4
4
  "description": "AGLedger™ SDK — Accountability and audit infrastructure for agentic systems.",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "type": "module",
@@ -9,11 +9,13 @@
9
9
  "exports": {
10
10
  ".": {
11
11
  "types": "./dist/index.d.ts",
12
- "import": "./dist/index.js"
12
+ "import": "./dist/index.js",
13
+ "default": "./dist/index.js"
13
14
  },
14
15
  "./webhooks": {
15
16
  "types": "./dist/webhooks/verify.d.ts",
16
- "import": "./dist/webhooks/verify.js"
17
+ "import": "./dist/webhooks/verify.js",
18
+ "default": "./dist/webhooks/verify.js"
17
19
  }
18
20
  },
19
21
  "files": [