@agledger/sdk 1.1.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 (49) hide show
  1. package/LICENSE +34 -0
  2. package/README.md +209 -0
  3. package/dist/client.d.ts +46 -0
  4. package/dist/client.js +68 -0
  5. package/dist/errors.d.ts +64 -0
  6. package/dist/errors.js +114 -0
  7. package/dist/http.d.ts +47 -0
  8. package/dist/http.js +272 -0
  9. package/dist/index.d.ts +19 -0
  10. package/dist/index.js +12 -0
  11. package/dist/resources/a2a.d.ts +22 -0
  12. package/dist/resources/a2a.js +33 -0
  13. package/dist/resources/admin.d.ts +39 -0
  14. package/dist/resources/admin.js +57 -0
  15. package/dist/resources/capabilities.d.ts +23 -0
  16. package/dist/resources/capabilities.js +21 -0
  17. package/dist/resources/compliance.d.ts +34 -0
  18. package/dist/resources/compliance.js +54 -0
  19. package/dist/resources/dashboard.d.ts +14 -0
  20. package/dist/resources/dashboard.js +20 -0
  21. package/dist/resources/disputes.d.ts +16 -0
  22. package/dist/resources/disputes.js +26 -0
  23. package/dist/resources/events.d.ts +21 -0
  24. package/dist/resources/events.js +22 -0
  25. package/dist/resources/health.d.ts +15 -0
  26. package/dist/resources/health.js +21 -0
  27. package/dist/resources/mandates.d.ts +48 -0
  28. package/dist/resources/mandates.js +89 -0
  29. package/dist/resources/notarize.d.ts +20 -0
  30. package/dist/resources/notarize.js +44 -0
  31. package/dist/resources/proxy.d.ts +74 -0
  32. package/dist/resources/proxy.js +149 -0
  33. package/dist/resources/receipts.d.ts +28 -0
  34. package/dist/resources/receipts.js +27 -0
  35. package/dist/resources/registration.d.ts +30 -0
  36. package/dist/resources/registration.js +39 -0
  37. package/dist/resources/reputation.d.ts +16 -0
  38. package/dist/resources/reputation.js +17 -0
  39. package/dist/resources/schemas.d.ts +20 -0
  40. package/dist/resources/schemas.js +24 -0
  41. package/dist/resources/verification.d.ts +13 -0
  42. package/dist/resources/verification.js +17 -0
  43. package/dist/resources/webhooks.d.ts +25 -0
  44. package/dist/resources/webhooks.js +37 -0
  45. package/dist/types.d.ts +1134 -0
  46. package/dist/types.js +6 -0
  47. package/dist/webhooks/verify.d.ts +37 -0
  48. package/dist/webhooks/verify.js +86 -0
  49. package/package.json +74 -0
package/LICENSE ADDED
@@ -0,0 +1,34 @@
1
+ Copyright (c) 2026 AGLedger LLC. All rights reserved.
2
+
3
+ PROPRIETARY SOFTWARE LICENSE
4
+
5
+ This software and associated documentation files (the "Software") are the
6
+ proprietary property of AGLedger LLC. The Software is provided for use
7
+ exclusively with the AGLedger API (https://api.agledger.ai).
8
+
9
+ Permission is hereby granted to use the Software solely for the purpose of
10
+ integrating with AGLedger services via the AGLedger API, subject to the
11
+ following conditions:
12
+
13
+ 1. You may not copy, modify, merge, publish, distribute, sublicense, or sell
14
+ copies of the Software, except as required to use it with the AGLedger API.
15
+
16
+ 2. You may not use the Software to create a competing product or service.
17
+
18
+ 3. You may not reverse engineer, decompile, or disassemble the Software,
19
+ except to the extent permitted by applicable law.
20
+
21
+ Use of this SDK is subject to the AGLedger Terms of Service at
22
+ https://agledger.ai/terms.
23
+
24
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27
+ AGLEDGER LLC BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
28
+ AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30
+
31
+ ---
32
+
33
+ AGLedger™ and the Agentic Contract Specification™ are trademarks of
34
+ AGLedger LLC. Patent pending.
package/README.md ADDED
@@ -0,0 +1,209 @@
1
+ # @agledger/sdk
2
+
3
+ The official TypeScript SDK for the [AGLedger](https://agledger.ai) API -- accountability and audit infrastructure for agentic systems.
4
+
5
+ Zero runtime dependencies. TypeScript strict. 113 tests. Works with Node.js 18+, Deno, and Bun.
6
+
7
+ ## Why AGLedger?
8
+
9
+ Enterprises deploying AI agents need to know what each agent was asked to do, what it actually did, and whether the result met expectations. AGLedger provides the accountability record -- what was agreed to, by whom, when, and the delegation of that agreement through other systems.
10
+
11
+ - Record what was asked and who it was delegated to (mandates)
12
+ - Capture what was reported to be done (task attestations)
13
+ - Check whether the creator accepted the results (verification)
14
+ - Track agent reliability across your organization over time (reputation)
15
+
16
+ ## The Accountability Record
17
+
18
+ The core of AGLedger is the contract. A mandate is a structured, deterministic record of what was agreed to -- the acceptance criteria, tolerance bands, and delegation chain. It works the same way regardless of which AI agent, platform, or framework is executing the work.
19
+
20
+ On top of the contract, AGLedger provides:
21
+
22
+ - **Tamper-evident audit trail** -- every state change is hash-chained and independently verifiable
23
+ - **Encrypted operating mode** -- for sensitive operations where criteria and evidence must be encrypted at rest
24
+ - **Governance sidecar** -- passive detection of agent operations via MCP proxy, with observe/advisory/enforced modes
25
+ - **Compliance exports** -- audit-ready reports for internal review, regulators, and EU AI Act assessments
26
+
27
+ ## Get Started
28
+
29
+ 1. Create an account at [agledger.ai](https://agledger.ai)
30
+ 2. Get your API key from the dashboard
31
+ 3. Install the SDK: `npm install @agledger/sdk`
32
+ 4. Follow the Quick Start below
33
+
34
+ ## Quick Start
35
+
36
+ ```typescript
37
+ import { AgledgerClient } from '@agledger/sdk';
38
+
39
+ const client = new AgledgerClient({
40
+ apiKey: process.env.AGLEDGER_API_KEY!,
41
+ });
42
+
43
+ // Create a mandate (what the agent is being asked to do)
44
+ const mandate = await client.mandates.create({
45
+ enterpriseId: 'ent-123',
46
+ contractType: 'ACH-DATA-v1',
47
+ contractVersion: '1',
48
+ platform: 'internal-etl',
49
+ criteria: {
50
+ source_system: 'warehouse-db',
51
+ target_format: 'parquet',
52
+ max_records: 500_000,
53
+ },
54
+ });
55
+
56
+ // Activate the mandate
57
+ await client.mandates.transition(mandate.id, 'activate');
58
+
59
+ // Submit a receipt (what the agent reported back)
60
+ const receipt = await client.receipts.submit(mandate.id, {
61
+ agentId: 'agent-456',
62
+ evidence: {
63
+ records_processed: 487_231,
64
+ output_path: '/data/exports/2026-03-10.parquet',
65
+ duration_ms: 12_400,
66
+ },
67
+ });
68
+
69
+ // Check whether the results meet the original criteria
70
+ const result = await client.verification.verify(mandate.id);
71
+ ```
72
+
73
+ ## Features
74
+
75
+ - **Stripe-style client** with resource sub-clients (`client.mandates`, `client.receipts`, etc.)
76
+ - **Automatic retries** with exponential backoff + jitter for 429/5xx errors
77
+ - **Idempotency keys** auto-generated for all mutating requests
78
+ - **Auto-pagination** via async iterators
79
+ - **Webhook signature verification** (separate import to keep browser bundles lean)
80
+ - **TypeScript-first** with full type coverage and forward-compatible enums
81
+ - **Sandbox support** via `environment: 'sandbox'` option
82
+
83
+ ## Configuration
84
+
85
+ ```typescript
86
+ const client = new AgledgerClient({
87
+ apiKey: 'your_api_key',
88
+
89
+ // Environment shorthand (sets baseUrl automatically)
90
+ environment: 'sandbox', // or 'production' (default)
91
+
92
+ // Or explicit base URL
93
+ baseUrl: 'https://api.agledger.ai',
94
+
95
+ // Retry configuration
96
+ maxRetries: 3, // default: 3
97
+ timeout: 30_000, // default: 30s
98
+
99
+ // Idempotency key prefix
100
+ idempotencyKeyPrefix: 'my-app-',
101
+ });
102
+ ```
103
+
104
+ ## Resources
105
+
106
+ | Resource | Description |
107
+ |----------|-------------|
108
+ | `client.mandates` | Create, search, transition, and delegate mandates |
109
+ | `client.receipts` | Submit and manage task attestation reports |
110
+ | `client.verification` | Trigger and check verification status |
111
+ | `client.disputes` | File, escalate, and resolve disputes |
112
+ | `client.webhooks` | Manage webhook endpoints and deliveries |
113
+ | `client.reputation` | Query agent health scores and history |
114
+ | `client.events` | List audit events and hash-chained audit trails |
115
+ | `client.schemas` | Browse and validate against contract type schemas |
116
+ | `client.dashboard` | Dashboard summaries, metrics, and agent leaderboards |
117
+ | `client.compliance` | Compliance exports, EU AI Act assessments |
118
+ | `client.registration` | Account registration and API key management |
119
+ | `client.health` | Platform health, status, and conformance |
120
+ | `client.admin` | Platform administration (requires platform API key) |
121
+ | `client.a2a` | A2A Protocol support (AgentCard, JSON-RPC 2.0) |
122
+ | `client.capabilities` | Agent contract type capability management |
123
+ | `client.proxy` | Governance sidecar session sync and analytics |
124
+
125
+ ## Contract Types
126
+
127
+ Contract types are defined by the Agentic Contract Specification™:
128
+
129
+ | Type | Use Case |
130
+ |------|----------|
131
+ | `ACH-PROC-v1` | Resource acquisition and provisioning requests |
132
+ | `ACH-DLVR-v1` | Reports, documents, and generated artifacts |
133
+ | `ACH-DATA-v1` | Data processing, ETL, analysis, and transformation |
134
+ | `ACH-TXN-v1` | Internal transfers, ledger entries, and settlements |
135
+ | `ACH-ORCH-v1` | Task delegation and multi-agent coordination |
136
+ | `ACH-COMM-v1` | Notifications, messages, and alerting |
137
+ | `ACH-AUTH-v1` | Permission changes, credential grants, and access control |
138
+ | `ACH-INFRA-v1` | Infrastructure changes, cloud provisioning, and config updates |
139
+ | `ACH-DEL-v1` | Deletions, cancellations, and reversals |
140
+
141
+ ## Pagination
142
+
143
+ All list methods return `Page<T>`:
144
+
145
+ ```typescript
146
+ // Single page
147
+ const page = await client.mandates.list({ enterpriseId: 'ent-123' });
148
+ console.log(page.data); // Mandate[]
149
+ console.log(page.hasMore); // boolean
150
+ console.log(page.total); // number | undefined
151
+
152
+ // Auto-pagination with async iterator
153
+ for await (const mandate of client.mandates.listAll({ enterpriseId: 'ent-123' })) {
154
+ console.log(mandate.id);
155
+ }
156
+ ```
157
+
158
+ ## Error Handling
159
+
160
+ ```typescript
161
+ import { AgledgerApiError, NotFoundError, RateLimitError } from '@agledger/sdk';
162
+
163
+ try {
164
+ await client.mandates.get('mnd-nonexistent');
165
+ } catch (err) {
166
+ if (err instanceof NotFoundError) {
167
+ console.log('Mandate not found');
168
+ } else if (err instanceof RateLimitError) {
169
+ console.log(`Rate limited. Retry after ${err.retryAfter}ms`);
170
+ } else if (err instanceof AgledgerApiError) {
171
+ console.log(err.status); // HTTP status
172
+ console.log(err.code); // Machine-readable code
173
+ console.log(err.retryable); // Can this be retried?
174
+ console.log(err.validationErrors); // Field-level details
175
+ }
176
+ }
177
+ ```
178
+
179
+ Error classes: `AuthenticationError`, `PermissionError`, `NotFoundError`, `ValidationError`, `UnprocessableError`, `RateLimitError`, `ConnectionError`, `TimeoutError`.
180
+
181
+ ## Webhook Verification
182
+
183
+ ```typescript
184
+ import { verifySignature } from '@agledger/sdk/webhooks';
185
+
186
+ const isValid = verifySignature(
187
+ rawBody, // Raw request body string
188
+ req.headers['x-agledger-signature'], // Signature header
189
+ process.env.WEBHOOK_SECRET!, // Your webhook secret
190
+ );
191
+ ```
192
+
193
+ ## Mandate Lifecycle
194
+
195
+ ```
196
+ DRAFT → REGISTERED → ACTIVE → PENDING_VERIFICATION → FULFILLED / FAILED / DISPUTED
197
+
198
+ REMEDIATED
199
+ ```
200
+
201
+ ## API Documentation
202
+
203
+ Full API documentation is available at [https://api.agledger.ai/docs](https://api.agledger.ai/docs).
204
+
205
+ ## License
206
+
207
+ Proprietary. Copyright (c) 2026 AGLedger LLC. All rights reserved. See [LICENSE](./LICENSE) for details.
208
+
209
+ AGLedger™ and the Agentic Contract Specification™ are trademarks of AGLedger LLC. Patent pending.
@@ -0,0 +1,46 @@
1
+ /**
2
+ * AGLedger™ SDK — Client
3
+ * Patent Pending. Copyright 2026 AGLedger LLC. All rights reserved.
4
+ */
5
+ import type { AgledgerClientOptions, RateLimitInfo } from './types.js';
6
+ import { MandatesResource } from './resources/mandates.js';
7
+ import { ReceiptsResource } from './resources/receipts.js';
8
+ import { VerificationResource } from './resources/verification.js';
9
+ import { DisputesResource } from './resources/disputes.js';
10
+ import { WebhooksResource } from './resources/webhooks.js';
11
+ import { ReputationResource } from './resources/reputation.js';
12
+ import { EventsResource } from './resources/events.js';
13
+ import { SchemasResource } from './resources/schemas.js';
14
+ import { DashboardResource } from './resources/dashboard.js';
15
+ import { ComplianceResource } from './resources/compliance.js';
16
+ import { RegistrationResource } from './resources/registration.js';
17
+ import { HealthResource } from './resources/health.js';
18
+ import { ProxyResource } from './resources/proxy.js';
19
+ import { AdminResource } from './resources/admin.js';
20
+ import { A2aResource } from './resources/a2a.js';
21
+ import { CapabilitiesResource } from './resources/capabilities.js';
22
+ import { NotarizeResource } from './resources/notarize.js';
23
+ export declare class AgledgerClient {
24
+ private readonly http;
25
+ readonly mandates: MandatesResource;
26
+ readonly receipts: ReceiptsResource;
27
+ readonly verification: VerificationResource;
28
+ readonly disputes: DisputesResource;
29
+ readonly webhooks: WebhooksResource;
30
+ readonly reputation: ReputationResource;
31
+ readonly events: EventsResource;
32
+ readonly schemas: SchemasResource;
33
+ readonly dashboard: DashboardResource;
34
+ readonly compliance: ComplianceResource;
35
+ readonly registration: RegistrationResource;
36
+ readonly health: HealthResource;
37
+ readonly proxy: ProxyResource;
38
+ readonly admin: AdminResource;
39
+ readonly a2a: A2aResource;
40
+ readonly capabilities: CapabilitiesResource;
41
+ readonly notarize: NotarizeResource;
42
+ /** Rate limit info from the most recent API response. Null if headers not present. */
43
+ get rateLimitInfo(): RateLimitInfo | null;
44
+ constructor(options: AgledgerClientOptions);
45
+ }
46
+ //# sourceMappingURL=client.d.ts.map
package/dist/client.js ADDED
@@ -0,0 +1,68 @@
1
+ /**
2
+ * AGLedger™ SDK — Client
3
+ * Patent Pending. Copyright 2026 AGLedger LLC. All rights reserved.
4
+ */
5
+ import { HttpClient } from './http.js';
6
+ import { MandatesResource } from './resources/mandates.js';
7
+ import { ReceiptsResource } from './resources/receipts.js';
8
+ import { VerificationResource } from './resources/verification.js';
9
+ import { DisputesResource } from './resources/disputes.js';
10
+ import { WebhooksResource } from './resources/webhooks.js';
11
+ import { ReputationResource } from './resources/reputation.js';
12
+ import { EventsResource } from './resources/events.js';
13
+ import { SchemasResource } from './resources/schemas.js';
14
+ import { DashboardResource } from './resources/dashboard.js';
15
+ import { ComplianceResource } from './resources/compliance.js';
16
+ import { RegistrationResource } from './resources/registration.js';
17
+ import { HealthResource } from './resources/health.js';
18
+ import { ProxyResource } from './resources/proxy.js';
19
+ import { AdminResource } from './resources/admin.js';
20
+ import { A2aResource } from './resources/a2a.js';
21
+ import { CapabilitiesResource } from './resources/capabilities.js';
22
+ import { NotarizeResource } from './resources/notarize.js';
23
+ export class AgledgerClient {
24
+ http;
25
+ mandates;
26
+ receipts;
27
+ verification;
28
+ disputes;
29
+ webhooks;
30
+ reputation;
31
+ events;
32
+ schemas;
33
+ dashboard;
34
+ compliance;
35
+ registration;
36
+ health;
37
+ proxy;
38
+ admin;
39
+ a2a;
40
+ capabilities;
41
+ notarize;
42
+ /** Rate limit info from the most recent API response. Null if headers not present. */
43
+ get rateLimitInfo() {
44
+ return this.http.rateLimitInfo;
45
+ }
46
+ constructor(options) {
47
+ const http = new HttpClient(options);
48
+ this.http = http;
49
+ this.mandates = new MandatesResource(http);
50
+ this.receipts = new ReceiptsResource(http);
51
+ this.verification = new VerificationResource(http);
52
+ this.disputes = new DisputesResource(http);
53
+ this.webhooks = new WebhooksResource(http);
54
+ this.reputation = new ReputationResource(http);
55
+ this.events = new EventsResource(http);
56
+ this.schemas = new SchemasResource(http);
57
+ this.dashboard = new DashboardResource(http);
58
+ this.compliance = new ComplianceResource(http);
59
+ this.registration = new RegistrationResource(http);
60
+ this.health = new HealthResource(http);
61
+ this.proxy = new ProxyResource(http);
62
+ this.admin = new AdminResource(http);
63
+ this.a2a = new A2aResource(http);
64
+ this.capabilities = new CapabilitiesResource(http);
65
+ this.notarize = new NotarizeResource(http);
66
+ }
67
+ }
68
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1,64 @@
1
+ /**
2
+ * AGLedger™ SDK — Error Classes
3
+ * Patent Pending. Copyright 2026 AGLedger LLC. All rights reserved.
4
+ */
5
+ import type { ApiErrorResponse, ValidationErrorDetail } from './types.js';
6
+ /**
7
+ * Base error for all SDK errors (network, timeout, etc.).
8
+ * Not an API error — no status code.
9
+ */
10
+ export declare class AgledgerError extends Error {
11
+ constructor(message: string);
12
+ }
13
+ /**
14
+ * API returned an error response. All HTTP errors extend this.
15
+ *
16
+ * Key properties for agent consumers:
17
+ * - `status` — HTTP status code
18
+ * - `code` — stable machine-readable error code (e.g., 'MANDATE_NOT_ACTIVE')
19
+ * - `retryable` — whether this error can be retried
20
+ * - `requestId` — correlation ID for debugging
21
+ * - `validationErrors` — field-level validation details (for 400/422)
22
+ */
23
+ export declare class AgledgerApiError extends AgledgerError {
24
+ readonly status: number;
25
+ readonly code: string;
26
+ readonly requestId?: string;
27
+ readonly details?: ValidationErrorDetail[] | Record<string, unknown>;
28
+ /**
29
+ * Whether this error is retryable.
30
+ * - Uses the API's `retryable` field if present
31
+ * - Falls back to status-based classification: 429 and 5xx are retryable
32
+ */
33
+ readonly retryable: boolean;
34
+ constructor(status: number, body: ApiErrorResponse);
35
+ /** Field-level validation errors, normalized from various API formats. */
36
+ get validationErrors(): ValidationErrorDetail[];
37
+ }
38
+ export declare class AuthenticationError extends AgledgerApiError {
39
+ constructor(body: ApiErrorResponse);
40
+ }
41
+ export declare class PermissionError extends AgledgerApiError {
42
+ constructor(body: ApiErrorResponse);
43
+ }
44
+ export declare class NotFoundError extends AgledgerApiError {
45
+ constructor(body: ApiErrorResponse);
46
+ }
47
+ export declare class ValidationError extends AgledgerApiError {
48
+ constructor(body: ApiErrorResponse);
49
+ }
50
+ export declare class UnprocessableError extends AgledgerApiError {
51
+ constructor(body: ApiErrorResponse);
52
+ }
53
+ export declare class RateLimitError extends AgledgerApiError {
54
+ readonly retryAfter: number | null;
55
+ constructor(body: ApiErrorResponse, retryAfter: number | null);
56
+ }
57
+ export declare class ConnectionError extends AgledgerError {
58
+ readonly cause?: Error;
59
+ constructor(message: string, cause?: Error);
60
+ }
61
+ export declare class TimeoutError extends ConnectionError {
62
+ constructor(method: string, url: string, timeoutMs: number, cause?: Error);
63
+ }
64
+ //# sourceMappingURL=errors.d.ts.map
package/dist/errors.js ADDED
@@ -0,0 +1,114 @@
1
+ /**
2
+ * AGLedger™ SDK — Error Classes
3
+ * Patent Pending. Copyright 2026 AGLedger LLC. All rights reserved.
4
+ */
5
+ /**
6
+ * Base error for all SDK errors (network, timeout, etc.).
7
+ * Not an API error — no status code.
8
+ */
9
+ export class AgledgerError extends Error {
10
+ constructor(message) {
11
+ super(message);
12
+ this.name = 'AgledgerError';
13
+ }
14
+ }
15
+ /**
16
+ * API returned an error response. All HTTP errors extend this.
17
+ *
18
+ * Key properties for agent consumers:
19
+ * - `status` — HTTP status code
20
+ * - `code` — stable machine-readable error code (e.g., 'MANDATE_NOT_ACTIVE')
21
+ * - `retryable` — whether this error can be retried
22
+ * - `requestId` — correlation ID for debugging
23
+ * - `validationErrors` — field-level validation details (for 400/422)
24
+ */
25
+ export class AgledgerApiError extends AgledgerError {
26
+ status;
27
+ code;
28
+ requestId;
29
+ details;
30
+ /**
31
+ * Whether this error is retryable.
32
+ * - Uses the API's `retryable` field if present
33
+ * - Falls back to status-based classification: 429 and 5xx are retryable
34
+ */
35
+ retryable;
36
+ constructor(status, body) {
37
+ super(body.message || `API error ${status}`);
38
+ this.name = 'AgledgerApiError';
39
+ this.status = status;
40
+ this.code = body.code || body.error || 'unknown';
41
+ this.requestId = body.requestId;
42
+ this.details = body.details;
43
+ this.retryable = body.retryable ?? (status === 429 || status >= 500);
44
+ }
45
+ /** Field-level validation errors, normalized from various API formats. */
46
+ get validationErrors() {
47
+ if (!this.details)
48
+ return [];
49
+ if (Array.isArray(this.details))
50
+ return this.details;
51
+ // Handle Ajv-style errors nested under .errors
52
+ const rec = this.details;
53
+ if (Array.isArray(rec.errors)) {
54
+ return rec.errors.map((e) => ({
55
+ field: e.instancePath || e.dataPath || '',
56
+ message: e.message || '',
57
+ }));
58
+ }
59
+ return [];
60
+ }
61
+ }
62
+ export class AuthenticationError extends AgledgerApiError {
63
+ constructor(body) {
64
+ super(401, body);
65
+ this.name = 'AuthenticationError';
66
+ }
67
+ }
68
+ export class PermissionError extends AgledgerApiError {
69
+ constructor(body) {
70
+ super(403, body);
71
+ this.name = 'PermissionError';
72
+ }
73
+ }
74
+ export class NotFoundError extends AgledgerApiError {
75
+ constructor(body) {
76
+ super(404, body);
77
+ this.name = 'NotFoundError';
78
+ }
79
+ }
80
+ export class ValidationError extends AgledgerApiError {
81
+ constructor(body) {
82
+ super(400, body);
83
+ this.name = 'ValidationError';
84
+ }
85
+ }
86
+ export class UnprocessableError extends AgledgerApiError {
87
+ constructor(body) {
88
+ super(422, body);
89
+ this.name = 'UnprocessableError';
90
+ }
91
+ }
92
+ export class RateLimitError extends AgledgerApiError {
93
+ retryAfter;
94
+ constructor(body, retryAfter) {
95
+ super(429, body);
96
+ this.name = 'RateLimitError';
97
+ this.retryAfter = retryAfter;
98
+ }
99
+ }
100
+ export class ConnectionError extends AgledgerError {
101
+ cause;
102
+ constructor(message, cause) {
103
+ super(message);
104
+ this.name = 'ConnectionError';
105
+ this.cause = cause;
106
+ }
107
+ }
108
+ export class TimeoutError extends ConnectionError {
109
+ constructor(method, url, timeoutMs, cause) {
110
+ super(`Request timed out after ${timeoutMs}ms: ${method} ${url}`, cause);
111
+ this.name = 'TimeoutError';
112
+ }
113
+ }
114
+ //# sourceMappingURL=errors.js.map
package/dist/http.d.ts ADDED
@@ -0,0 +1,47 @@
1
+ /**
2
+ * AGLedger™ SDK — HTTP Client
3
+ * Patent Pending. Copyright 2026 AGLedger LLC. All rights reserved.
4
+ *
5
+ * Zero runtime dependencies. Uses native fetch + crypto.
6
+ */
7
+ import type { AgledgerClientOptions, RequestOptions, RateLimitInfo, Page, AutoPaginateOptions } from './types.js';
8
+ export declare class HttpClient {
9
+ private readonly apiKey;
10
+ private readonly baseUrl;
11
+ private readonly maxRetries;
12
+ private readonly timeout;
13
+ private readonly fetchFn;
14
+ private readonly idempotencyKeyPrefix;
15
+ private _rateLimitInfo;
16
+ /** Rate limit info from the most recent response. Null if headers not present. */
17
+ get rateLimitInfo(): RateLimitInfo | null;
18
+ constructor(options: AgledgerClientOptions);
19
+ get<T>(path: string, params?: Record<string, unknown>, options?: RequestOptions): Promise<T>;
20
+ post<T>(path: string, body?: unknown, options?: RequestOptions): Promise<T>;
21
+ patch<T>(path: string, body?: unknown, options?: RequestOptions): Promise<T>;
22
+ delete<T>(path: string, options?: RequestOptions): Promise<T>;
23
+ /**
24
+ * Fetch a list endpoint and normalize the response into Page<T>.
25
+ * Handles both current inconsistent responses (bare arrays, various envelope shapes)
26
+ * and the target format ({ data, hasMore, nextCursor, total }).
27
+ */
28
+ getPage<T>(path: string, params?: Record<string, unknown>, options?: RequestOptions): Promise<Page<T>>;
29
+ /**
30
+ * Async iterator for auto-paginating through all pages.
31
+ * Yields individual items. Stops after maxPages (default: 100) as a safety ceiling.
32
+ */
33
+ paginate<T>(path: string, params?: Record<string, unknown>, options?: RequestOptions & AutoPaginateOptions): AsyncGenerator<T, void, undefined>;
34
+ private buildUrl;
35
+ private request;
36
+ private mapError;
37
+ private backoff;
38
+ private parseRateLimitHeaders;
39
+ /**
40
+ * Normalize any list response shape into Page<T>.
41
+ * Handles: bare array, { data }, { data, hasMore, nextCursor, total },
42
+ * { data, total, limit, offset }, { data, next_cursor }.
43
+ */
44
+ private normalizePage;
45
+ private sleep;
46
+ }
47
+ //# sourceMappingURL=http.d.ts.map