@atcn/sdk 1.3.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.
@@ -0,0 +1,670 @@
1
+ import type { z } from "zod";
2
+ import { type AllocationInputSchema, type AllocationRuleInputSchema, type AttestableField, type Correction, type DelegationEventInputSchema, type DelegationInputSchema, type EvidenceRef, type FinancialEventInput, type OperatorKeyRecord, type ProviderInputSchema, type ResponseType, type SignedClosure, type SignedReceipt, type TaskInputSchema } from "@atcn/subledger";
3
+ import { AtcnClient, type ClientOptions } from "./client.js";
4
+ type Json = Record<string, unknown>;
5
+ type Opts = {
6
+ idempotencyKey?: string;
7
+ };
8
+ /** Caller-supplied references address records before their server IDs are known: ext("job-42"). */
9
+ export declare const ext: (externalRef: string) => string;
10
+ /** Idempotency key derived from the caller's stable references; long references are hashed to fit 8-200 chars. */
11
+ export declare function stableKey(kind: string, ...parts: string[]): string;
12
+ /**
13
+ * Small, independent subledger operations (PRD §15). Default idempotency keys derive from the caller's own
14
+ * stable references, so a retry from anywhere in the orchestrator never creates a second record.
15
+ */
16
+ export declare class SubledgerClient {
17
+ readonly http: AtcnClient;
18
+ constructor(options: ClientOptions | AtcnClient);
19
+ createTask(input: z.input<typeof TaskInputSchema>, opts?: Opts): Promise<Json>;
20
+ getTask(taskId: string): Promise<Json>;
21
+ listTasks(query?: {
22
+ status?: "open" | "closed";
23
+ external_ref?: string;
24
+ }): Promise<{
25
+ items: Json[];
26
+ }>;
27
+ /** Admin only. Principals are "user:<id>" or "api_key:<id>". */
28
+ getTaskAccess(taskId: string): Promise<Json>;
29
+ updateTaskAccess(taskId: string, input: {
30
+ restricted?: boolean;
31
+ grant?: string[];
32
+ revoke?: string[];
33
+ }, opts?: Opts): Promise<Json>;
34
+ createDelegation(taskId: string, input: z.input<typeof DelegationInputSchema>, opts?: Opts): Promise<Json>;
35
+ assignProvider(delegationId: string, providerId: string, opts?: Opts): Promise<Json>;
36
+ appendDelegationEvent(delegationId: string, input: z.input<typeof DelegationEventInputSchema>, opts?: Opts): Promise<Json>;
37
+ recordFinancialEvent(input: FinancialEventInput, opts?: Opts): Promise<{
38
+ financial_event: Json;
39
+ deduplicated: boolean;
40
+ attributed?: boolean;
41
+ attribution: Json | null;
42
+ match_id: string | null;
43
+ exception_ids: string[];
44
+ }>;
45
+ importCsv(csv: string, opts?: Opts): Promise<{
46
+ imported: number;
47
+ deduplicated: number;
48
+ rejected: number;
49
+ rows: Json[];
50
+ }>;
51
+ listFinancialEvents(query?: {
52
+ unattributed?: "true" | "false";
53
+ source?: string;
54
+ }): Promise<{
55
+ items: Json[];
56
+ }>;
57
+ allocate(financialEventId: string, input: z.input<typeof AllocationInputSchema>, opts?: Opts): Promise<Json>;
58
+ createAllocationRule(input: z.input<typeof AllocationRuleInputSchema>, opts?: Opts): Promise<Json>;
59
+ listMatches(status?: "pending" | "confirmed" | "dismissed"): Promise<{
60
+ items: Json[];
61
+ }>;
62
+ confirmMatch(matchId: string, node: {
63
+ task_id: string;
64
+ delegation_id?: string | null;
65
+ }, opts?: Opts): Promise<Json>;
66
+ financialSummary(taskId: string, query?: {
67
+ report_currency?: string;
68
+ as_of?: string;
69
+ }): Promise<Json>;
70
+ listExceptions(query?: {
71
+ task_id?: string;
72
+ status?: "open" | "resolved" | "dismissed";
73
+ }): Promise<{
74
+ items: Json[];
75
+ }>;
76
+ resolveException(exceptionId: string, input: {
77
+ status: "resolved" | "dismissed";
78
+ resolution: string;
79
+ }, opts?: Opts): Promise<Json>;
80
+ reportCaptureGap(taskId: string, gap: {
81
+ delegation_id?: string | null;
82
+ kind: "capture_failed" | "queue_overflow" | "provider_undisclosed" | "manual_gap";
83
+ detail: string;
84
+ }, opts?: Opts): Promise<Json>;
85
+ closeTask(taskId: string, opts?: Opts): Promise<{
86
+ closure: SignedClosure;
87
+ digest: string;
88
+ }>;
89
+ getClosure(taskId: string, version?: number): Promise<{
90
+ payload: {
91
+ document_type: "atcn.subledger.closure";
92
+ schema_version: "1.3" | "1.2";
93
+ closure_id: string;
94
+ version: number;
95
+ previous_closure_id: string | null;
96
+ previous_closure_digest: string | null;
97
+ generated_at: string;
98
+ issuer: {
99
+ operator_id: string;
100
+ operator_name: string;
101
+ signed_by: "atcn-hosted-service" | "atcn-local-runner";
102
+ };
103
+ task: {
104
+ task_id: string;
105
+ external_ref: string;
106
+ currency: string;
107
+ budget_minor: number | null;
108
+ customer_ref: string | null;
109
+ project_ref: string | null;
110
+ cost_center: string | null;
111
+ scope_ref: string | null;
112
+ retrospective: boolean;
113
+ created_at: string;
114
+ };
115
+ delegations: {
116
+ delegation_id: string;
117
+ parent_delegation_id: string | null;
118
+ depth: number;
119
+ provider_id: string | null;
120
+ provider_name_stated: string | null;
121
+ provider_own_id: string | null;
122
+ external_ref: string | null;
123
+ provider_job_ref: string | null;
124
+ scope_ref: string | null;
125
+ currency: string;
126
+ quoted_max_minor: number | null;
127
+ quote_basis: string | null;
128
+ quote_valid_until: string | null;
129
+ accepted_amount_minor: number | null;
130
+ terms_digest: string | null;
131
+ expected_delivery: string | null;
132
+ downstream_visibility: "unknown" | "disclosed" | "none";
133
+ delivery_status: string;
134
+ retrospective: boolean;
135
+ created_at: string;
136
+ }[];
137
+ delivery_claims: {
138
+ event_id: string;
139
+ delegation_id: string;
140
+ type: "acceptance" | "completion" | "partial_completion" | "cancellation" | "provider_failure" | "terms_update" | "correction";
141
+ asserted_by: "provider" | "buyer" | "clearing_policy" | "dispute_reviewer" | "clearing_network";
142
+ assurance: ("contested" | "issuer_signed" | "buyer_recorded" | "network_recorded" | "recipient_viewed" | "link_authenticated_response" | "provider_identity_bound" | "provider_key_signed" | "superseded")[];
143
+ note: string | null;
144
+ evidence: {
145
+ uri: string;
146
+ digest: string | null;
147
+ evidence_type: string;
148
+ }[];
149
+ supersedes_event_id: string | null;
150
+ reason: string | null;
151
+ retrospective: boolean;
152
+ occurred_at: string;
153
+ recorded_at: string;
154
+ }[];
155
+ financial_events: {
156
+ record: {
157
+ financial_event_id: string;
158
+ type: "quote" | "invoice" | "charge" | "payment_reported" | "refund" | "reversal" | "fee" | "credit" | "adjustment" | "fx_rate";
159
+ source: string;
160
+ source_event_id: string;
161
+ provider_id: string | null;
162
+ provider_reference: string | null;
163
+ amount_minor: number;
164
+ currency: string;
165
+ event_date: string;
166
+ imported_at: string;
167
+ provider_status: string | null;
168
+ normalized_status: "unknown" | "quoted" | "issued" | "pending" | "reported_paid" | "failed" | "refunded" | "reversed" | "void";
169
+ evidence: {
170
+ uri: string;
171
+ digest: string | null;
172
+ evidence_type: string;
173
+ } | null;
174
+ retrospective: boolean;
175
+ payer: "provider" | "buyer" | "other";
176
+ liability_owner: string | null;
177
+ economic_event_id: string | null;
178
+ included_in_event_id: string | null;
179
+ reverses_event_id: string | null;
180
+ settles_event_id: string | null;
181
+ fx: {
182
+ base_currency: string;
183
+ quote_currency: string;
184
+ rate_numerator: number;
185
+ rate_denominator: number;
186
+ } | null;
187
+ reason: string | null;
188
+ };
189
+ event_digest: string;
190
+ attributed_to: string;
191
+ }[];
192
+ allocations: {
193
+ allocation_id: string;
194
+ financial_event_id: string;
195
+ version: number;
196
+ source_event_digest: string;
197
+ source_amount_minor: number;
198
+ currency: string;
199
+ lines: {
200
+ target: {
201
+ type: "task" | "delegation" | "cost_center" | "unallocated";
202
+ id: string | null;
203
+ };
204
+ amount_minor: number;
205
+ }[];
206
+ rounding: {
207
+ method: "largest_remainder" | "none";
208
+ remainder_units: {
209
+ line_index: number;
210
+ units: number;
211
+ }[];
212
+ };
213
+ rule: {
214
+ rule_id: string;
215
+ version: number;
216
+ } | null;
217
+ reason: string;
218
+ after_close: boolean;
219
+ created_by: string;
220
+ created_at: string;
221
+ }[];
222
+ rollup: {
223
+ root_task_id: string;
224
+ nodes: {
225
+ node_id: string;
226
+ parent_id: string | null;
227
+ direct: Record<string, {
228
+ quoted: number;
229
+ accepted: number;
230
+ invoiced: number;
231
+ charged: number;
232
+ fees: number;
233
+ adjustments: number;
234
+ refunded: number;
235
+ credits: number;
236
+ reported_paid: number;
237
+ net_cost: number;
238
+ unresolved: number;
239
+ downstream_reported: number;
240
+ allocated: number;
241
+ unallocated: number;
242
+ }>;
243
+ descendant: Record<string, {
244
+ quoted: number;
245
+ accepted: number;
246
+ invoiced: number;
247
+ charged: number;
248
+ fees: number;
249
+ adjustments: number;
250
+ refunded: number;
251
+ credits: number;
252
+ reported_paid: number;
253
+ net_cost: number;
254
+ unresolved: number;
255
+ downstream_reported: number;
256
+ allocated: number;
257
+ unallocated: number;
258
+ }>;
259
+ total: Record<string, {
260
+ quoted: number;
261
+ accepted: number;
262
+ invoiced: number;
263
+ charged: number;
264
+ fees: number;
265
+ adjustments: number;
266
+ refunded: number;
267
+ credits: number;
268
+ reported_paid: number;
269
+ net_cost: number;
270
+ unresolved: number;
271
+ downstream_reported: number;
272
+ allocated: number;
273
+ unallocated: number;
274
+ }>;
275
+ event_ids: string[];
276
+ }[];
277
+ root_total: Record<string, {
278
+ quoted: number;
279
+ accepted: number;
280
+ invoiced: number;
281
+ charged: number;
282
+ fees: number;
283
+ adjustments: number;
284
+ refunded: number;
285
+ credits: number;
286
+ reported_paid: number;
287
+ net_cost: number;
288
+ unresolved: number;
289
+ downstream_reported: number;
290
+ allocated: number;
291
+ unallocated: number;
292
+ }>;
293
+ excluded_event_ids: {
294
+ reversed: string[];
295
+ reversals: string[];
296
+ fx_rates: string[];
297
+ };
298
+ };
299
+ open_exceptions: {
300
+ exception_id: string;
301
+ kind: string;
302
+ status: "open" | "dismissed" | "resolved";
303
+ delegation_id: string | null;
304
+ financial_event_id: string | null;
305
+ detail: string;
306
+ created_at: string;
307
+ }[];
308
+ receipts: {
309
+ receipt_id: string;
310
+ delegation_id: string;
311
+ revision: number;
312
+ digest: string;
313
+ }[];
314
+ responses: {
315
+ response_id: string;
316
+ receipt_id: string;
317
+ receipt_revision: number;
318
+ provider_id: string | null;
319
+ statement: {
320
+ document_type: "atcn.subledger.receipt_response";
321
+ receipt_id: string;
322
+ receipt_digest: string;
323
+ receipt_revision: number;
324
+ issuer_operator_id: string;
325
+ response_type: "acknowledge_view" | "acknowledge_delivery" | "submit_evidence" | "propose_correction" | "signed_attestation";
326
+ fields: ("delivery.status" | "delivery.evidence" | "scope.terms_digest" | "financial.amounts" | "financial.status")[];
327
+ note: string | null;
328
+ evidence: {
329
+ uri: string;
330
+ digest: string | null;
331
+ evidence_type: string;
332
+ }[];
333
+ corrections: {
334
+ field: "delivery.status" | "delivery.evidence" | "scope.terms_digest" | "financial.amounts" | "financial.status";
335
+ proposed_value: string;
336
+ reason: string;
337
+ }[];
338
+ };
339
+ statement_digest: string;
340
+ provider_signature: {
341
+ key_id: string;
342
+ binding_id: string;
343
+ value: string;
344
+ } | null;
345
+ assurance: ("contested" | "issuer_signed" | "buyer_recorded" | "network_recorded" | "recipient_viewed" | "link_authenticated_response" | "provider_identity_bound" | "provider_key_signed" | "superseded")[];
346
+ decision: {
347
+ status: "accepted" | "rejected";
348
+ reason: string;
349
+ decided_by: string;
350
+ decided_at: string;
351
+ } | null;
352
+ created_at: string;
353
+ }[];
354
+ key_bindings: {
355
+ binding_id: string;
356
+ provider_id: string;
357
+ key_id: string;
358
+ public_key: string;
359
+ method: "operator_configured" | "domain_challenge";
360
+ created_by: string;
361
+ created_at: string;
362
+ revoked_at: string | null;
363
+ domain?: string | null | undefined;
364
+ }[];
365
+ lineage: {
366
+ complete: boolean;
367
+ capture_gaps: {
368
+ gap_id: string;
369
+ delegation_id: string | null;
370
+ kind: string;
371
+ detail: string;
372
+ reported_at: string;
373
+ }[];
374
+ unknown_downstream: string[];
375
+ };
376
+ disclosure: {
377
+ missing: string[];
378
+ unverified: string[];
379
+ contested: string[];
380
+ provider_reported: string[];
381
+ retrospective: string[];
382
+ };
383
+ obligation_links?: {
384
+ delegation_id: string;
385
+ obligation_id: string;
386
+ decision_id: string | null;
387
+ decision_digest: string | null;
388
+ }[] | undefined;
389
+ };
390
+ signature: {
391
+ key_id: string;
392
+ key_version: number;
393
+ algorithm: "Ed25519";
394
+ value: string;
395
+ };
396
+ operator_signatures?: {
397
+ key_id: string;
398
+ algorithm: "Ed25519";
399
+ value: string;
400
+ signed_at: string;
401
+ }[] | undefined;
402
+ }>;
403
+ createReceipt(taskId: string, delegationId: string, opts?: Opts): Promise<{
404
+ receipt: SignedReceipt;
405
+ digest: string;
406
+ }>;
407
+ getReceipt(receiptId: string): Promise<{
408
+ payload: {
409
+ document_type: "atcn.subledger.receipt";
410
+ schema_version: "1.3" | "1.2";
411
+ receipt_id: string;
412
+ revision: number;
413
+ previous_receipt_id: string | null;
414
+ previous_receipt_digest: string | null;
415
+ issued_at: string;
416
+ expires_at: string | null;
417
+ issuer: {
418
+ operator_id: string;
419
+ operator_name: string;
420
+ signed_by: "atcn-hosted-service" | "atcn-local-runner";
421
+ };
422
+ delegation: {
423
+ delegation_id: string;
424
+ root_task_id: string;
425
+ external_ref: string | null;
426
+ provider_job_ref: string | null;
427
+ shared_description: string | null;
428
+ terms_digest: string | null;
429
+ currency: string;
430
+ quoted_max_minor: number | null;
431
+ quote_basis: string | null;
432
+ accepted_amount_minor: number | null;
433
+ expected_delivery: string | null;
434
+ retrospective: boolean;
435
+ downstream_visibility: "unknown" | "disclosed" | "none";
436
+ };
437
+ provider: {
438
+ provider_id: string | null;
439
+ name_stated: string | null;
440
+ provider_own_id: string | null;
441
+ identity_binding: "key_bound" | "not_bound";
442
+ };
443
+ delivery_claims: {
444
+ type: "acceptance" | "completion" | "partial_completion" | "cancellation" | "provider_failure" | "terms_update" | "correction";
445
+ retrospective: boolean;
446
+ occurred_at: string;
447
+ asserted_by: "provider" | "buyer" | "clearing_policy" | "dispute_reviewer" | "clearing_network";
448
+ note: string | null;
449
+ evidence: {
450
+ uri: string;
451
+ digest: string | null;
452
+ evidence_type: string;
453
+ }[];
454
+ supersedes_event_id: string | null;
455
+ reason: string | null;
456
+ event_id: string;
457
+ assurance: ("contested" | "issuer_signed" | "buyer_recorded" | "network_recorded" | "recipient_viewed" | "link_authenticated_response" | "provider_identity_bound" | "provider_key_signed" | "superseded")[];
458
+ recorded_at: string;
459
+ }[];
460
+ financial_events: {
461
+ type: "quote" | "invoice" | "charge" | "payment_reported" | "refund" | "reversal" | "fee" | "credit" | "adjustment" | "fx_rate";
462
+ currency: string;
463
+ retrospective: boolean;
464
+ provider_id: string | null;
465
+ evidence: {
466
+ uri: string;
467
+ digest: string | null;
468
+ evidence_type: string;
469
+ } | null;
470
+ reason: string | null;
471
+ amount_minor: number;
472
+ event_date: string;
473
+ source: string;
474
+ source_event_id: string;
475
+ provider_reference: string | null;
476
+ provider_status: string | null;
477
+ normalized_status: "unknown" | "quoted" | "issued" | "pending" | "reported_paid" | "failed" | "refunded" | "reversed" | "void";
478
+ payer: "provider" | "buyer" | "other";
479
+ included_in_event_id: string | null;
480
+ reverses_event_id: string | null;
481
+ settles_event_id: string | null;
482
+ imported_at: string;
483
+ financial_event_id: string;
484
+ allocation_version: number;
485
+ }[];
486
+ totals: Record<string, {
487
+ quoted: number;
488
+ reported_paid: number;
489
+ refunded: number;
490
+ accepted: number;
491
+ invoiced: number;
492
+ charged: number;
493
+ fees: number;
494
+ adjustments: number;
495
+ credits: number;
496
+ net_cost: number;
497
+ unresolved: number;
498
+ downstream_reported: number;
499
+ }>;
500
+ field_status: Record<"delivery.status" | "delivery.evidence" | "scope.terms_digest" | "financial.amounts" | "financial.status", "contested" | "missing" | "imported" | "buyer_asserted" | "provider_reported">;
501
+ unverified_fields: ("delivery.status" | "delivery.evidence" | "scope.terms_digest" | "financial.amounts" | "financial.status")[];
502
+ corrections: {
503
+ response_id: string;
504
+ receipt_revision: number;
505
+ fields: ("delivery.status" | "delivery.evidence" | "scope.terms_digest" | "financial.amounts" | "financial.status")[];
506
+ decision: "accepted" | "rejected" | "open";
507
+ }[];
508
+ lineage: {
509
+ complete: boolean;
510
+ capture_gaps: {
511
+ detail: string;
512
+ reported_at: string;
513
+ gap_id: string;
514
+ kind: string;
515
+ }[];
516
+ };
517
+ };
518
+ signature: {
519
+ key_id: string;
520
+ key_version: number;
521
+ algorithm: "Ed25519";
522
+ value: string;
523
+ };
524
+ operator_signatures?: {
525
+ key_id: string;
526
+ algorithm: "Ed25519";
527
+ value: string;
528
+ signed_at: string;
529
+ }[] | undefined;
530
+ }>;
531
+ markReceiptDelivered(receiptId: string, channel: string, reference?: string | null, opts?: Opts): Promise<Json>;
532
+ createReceiptShare(receiptId: string, allowedActions?: string[], ttlHours?: number, opts?: Opts): Promise<{
533
+ share_id: string;
534
+ token: string;
535
+ url: string;
536
+ expires_at: string;
537
+ allowed_actions: string[];
538
+ }>;
539
+ revokeReceiptShare(shareId: string, opts?: Opts): Promise<Json>;
540
+ listResponses(receiptId: string): Promise<{
541
+ items: Json[];
542
+ }>;
543
+ /** Accepting appends the corrected records. A correction of financial fields needs the corrected events in `financialEvents`. */
544
+ decideCorrection(responseId: string, status: "accepted" | "rejected", reason: string, opts?: Opts & {
545
+ financialEvents?: FinancialEventInput[];
546
+ }): Promise<Json>;
547
+ createProvider(input: z.input<typeof ProviderInputSchema>, opts?: Opts): Promise<Json>;
548
+ bindProviderKey(providerId: string, keyId: string, publicKey: string, opts?: Opts): Promise<Json>;
549
+ /** Admin only. The provider publishes the returned txt_value at txt_name; then call verifyDomainChallenge. */
550
+ startDomainChallenge(providerId: string, input: {
551
+ key_id: string;
552
+ public_key: string;
553
+ domain?: string;
554
+ }, opts?: Opts): Promise<Json>;
555
+ verifyDomainChallenge(challengeId: string, opts?: Opts): Promise<Json>;
556
+ /** Admin only. Registers the public half of a key the operator holds; the private key stays with the operator. */
557
+ registerOperatorKey(keyId: string, publicKey: string, opts?: Opts): Promise<Json>;
558
+ revokeOperatorKey(keyId: string, reason: string, opts?: Opts): Promise<Json>;
559
+ operatorKeys(operatorId: string): Promise<{
560
+ items: OperatorKeyRecord[];
561
+ }>;
562
+ /** Signs the document's payload locally with the operator's private key and records the countersignature. */
563
+ countersign(signed: SignedClosure | SignedReceipt, keyId: string, privateKey: string, opts?: Opts): Promise<{
564
+ key_id: string;
565
+ algorithm: "Ed25519";
566
+ value: string;
567
+ signed_at: string;
568
+ }>;
569
+ productMetrics(): Promise<Json>;
570
+ serviceKeys(): Promise<{
571
+ items: Json[];
572
+ }>;
573
+ }
574
+ /** Provider-side access through a receipt link: no account, no API key, only the link's scope. */
575
+ export declare class ReceiptLinkClient {
576
+ private readonly http;
577
+ constructor(options: {
578
+ baseUrl: string;
579
+ shareToken: string;
580
+ fetch?: typeof fetch;
581
+ retries?: number;
582
+ });
583
+ current(): Promise<{
584
+ receipt: SignedReceipt;
585
+ digest: string;
586
+ revisions: Json[];
587
+ allowed_actions: string[];
588
+ expires_at: string;
589
+ responses: Json[];
590
+ notice: string;
591
+ }>;
592
+ verification(receiptId: string): Promise<Json>;
593
+ respond(receipt: {
594
+ receipt_id: string;
595
+ digest: string;
596
+ revision: number;
597
+ }, response: {
598
+ response_type: ResponseType;
599
+ fields?: AttestableField[];
600
+ note?: string | null;
601
+ evidence?: EvidenceRef[];
602
+ corrections?: Correction[];
603
+ }, signing?: {
604
+ bindingId: string;
605
+ keyId: string;
606
+ privateKey: string;
607
+ issuerOperatorId: string;
608
+ }, opts?: Opts): Promise<Json>;
609
+ }
610
+ export interface CaptureOperation {
611
+ id: string;
612
+ method: "POST";
613
+ path: string;
614
+ body: unknown;
615
+ idempotencyKey: string;
616
+ enqueued_at: string;
617
+ attempts: number;
618
+ last_error: string | null;
619
+ }
620
+ export interface CaptureQueueOptions {
621
+ /** Documented maximum. When full, new operations are dropped (never the oldest) and counted. Default 1000. */
622
+ maxSize?: number;
623
+ /** Attempts before an operation moves to the failed list for export and replay. Default 5. */
624
+ maxAttempts?: number;
625
+ }
626
+ export interface FlushResult {
627
+ sent: number;
628
+ failed: number;
629
+ remaining: number;
630
+ }
631
+ /**
632
+ * Bounded local capture queue (PRD §15, acceptance 20-21). enqueue() and flush() never throw, so a capture
633
+ * outage never stops the orchestrator's work. Each operation keeps one idempotency key for its lifetime, so
634
+ * replays and retries create exactly one record. Drops and permanent failures are counted and can be
635
+ * reported as capture gaps, so the chain is never silently shown as complete.
636
+ *
637
+ * Overflow policy: reject the newest operation and increment `dropped`. Older operations keep their order,
638
+ * because later events (completions, charges) depend on earlier ones (tasks, delegations).
639
+ */
640
+ export declare class CaptureQueue {
641
+ private readonly client;
642
+ readonly maxSize: number;
643
+ readonly maxAttempts: number;
644
+ private pending;
645
+ private failed;
646
+ private droppedCount;
647
+ private sequence;
648
+ constructor(client: SubledgerClient, options?: CaptureQueueOptions);
649
+ get dropped(): number;
650
+ get size(): number;
651
+ /** Queues one mutation. Returns false (and counts a drop) when the queue is full; never throws. */
652
+ enqueue(path: string, body: unknown, idempotencyKey?: string): boolean;
653
+ task(input: z.input<typeof TaskInputSchema>): boolean;
654
+ delegation(taskRef: string, input: z.input<typeof DelegationInputSchema>): boolean;
655
+ delegationEvent(delegationRef: string, input: z.input<typeof DelegationEventInputSchema>, idempotencyKey?: string): boolean;
656
+ financialEvent(input: FinancialEventInput): boolean;
657
+ /**
658
+ * Sends queued operations in order. A retryable failure (network, 5xx, 429) stops the flush and keeps the
659
+ * operation for the next flush; a non-retryable rejection moves it to the failed list. Never throws.
660
+ */
661
+ flush(): Promise<FlushResult>;
662
+ failedOperations(): CaptureOperation[];
663
+ /** Failed operations as JSON lines, for replay after the cause is fixed. */
664
+ exportFailed(): string;
665
+ /** Puts exported operations back in the queue with their original idempotency keys. */
666
+ replay(jsonLines: string): number;
667
+ /** Reports drops and permanent failures for a task as capture gaps (marks its lineage incomplete). Never throws. */
668
+ reportGaps(taskRef: string): Promise<boolean>;
669
+ }
670
+ export {};