@t402/streaming-payments 1.0.0-beta.1

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,1004 @@
1
+ import { z } from 'zod';
2
+
3
+ /**
4
+ * Stream state
5
+ */
6
+ declare const StreamState: z.ZodEnum<["idle", "active", "paused", "completed", "cancelled"]>;
7
+ type StreamState = z.infer<typeof StreamState>;
8
+ /**
9
+ * Rate type
10
+ */
11
+ declare const RateType: z.ZodEnum<["fixed", "variable", "tiered", "dynamic"]>;
12
+ type RateType = z.infer<typeof RateType>;
13
+ /**
14
+ * Stream rate configuration
15
+ */
16
+ declare const StreamRate: z.ZodObject<{
17
+ type: z.ZodEnum<["fixed", "variable", "tiered", "dynamic"]>;
18
+ baseRate: z.ZodString;
19
+ minRate: z.ZodOptional<z.ZodString>;
20
+ maxRate: z.ZodOptional<z.ZodString>;
21
+ tiers: z.ZodOptional<z.ZodArray<z.ZodObject<{
22
+ threshold: z.ZodString;
23
+ rate: z.ZodString;
24
+ }, "strip", z.ZodTypeAny, {
25
+ threshold: string;
26
+ rate: string;
27
+ }, {
28
+ threshold: string;
29
+ rate: string;
30
+ }>, "many">>;
31
+ adjustmentInterval: z.ZodOptional<z.ZodNumber>;
32
+ adjustmentFactor: z.ZodOptional<z.ZodNumber>;
33
+ }, "strip", z.ZodTypeAny, {
34
+ type: "fixed" | "variable" | "tiered" | "dynamic";
35
+ baseRate: string;
36
+ minRate?: string | undefined;
37
+ maxRate?: string | undefined;
38
+ tiers?: {
39
+ threshold: string;
40
+ rate: string;
41
+ }[] | undefined;
42
+ adjustmentInterval?: number | undefined;
43
+ adjustmentFactor?: number | undefined;
44
+ }, {
45
+ type: "fixed" | "variable" | "tiered" | "dynamic";
46
+ baseRate: string;
47
+ minRate?: string | undefined;
48
+ maxRate?: string | undefined;
49
+ tiers?: {
50
+ threshold: string;
51
+ rate: string;
52
+ }[] | undefined;
53
+ adjustmentInterval?: number | undefined;
54
+ adjustmentFactor?: number | undefined;
55
+ }>;
56
+ type StreamRate = z.infer<typeof StreamRate>;
57
+ /**
58
+ * Usage metrics
59
+ */
60
+ declare const UsageMetrics: z.ZodObject<{
61
+ totalSeconds: z.ZodNumber;
62
+ totalAmount: z.ZodString;
63
+ averageRate: z.ZodString;
64
+ peakRate: z.ZodString;
65
+ startTime: z.ZodNumber;
66
+ endTime: z.ZodOptional<z.ZodNumber>;
67
+ hourly: z.ZodOptional<z.ZodArray<z.ZodObject<{
68
+ hour: z.ZodNumber;
69
+ amount: z.ZodString;
70
+ seconds: z.ZodNumber;
71
+ }, "strip", z.ZodTypeAny, {
72
+ amount: string;
73
+ hour: number;
74
+ seconds: number;
75
+ }, {
76
+ amount: string;
77
+ hour: number;
78
+ seconds: number;
79
+ }>, "many">>;
80
+ }, "strip", z.ZodTypeAny, {
81
+ startTime: number;
82
+ totalSeconds: number;
83
+ totalAmount: string;
84
+ averageRate: string;
85
+ peakRate: string;
86
+ endTime?: number | undefined;
87
+ hourly?: {
88
+ amount: string;
89
+ hour: number;
90
+ seconds: number;
91
+ }[] | undefined;
92
+ }, {
93
+ startTime: number;
94
+ totalSeconds: number;
95
+ totalAmount: string;
96
+ averageRate: string;
97
+ peakRate: string;
98
+ endTime?: number | undefined;
99
+ hourly?: {
100
+ amount: string;
101
+ hour: number;
102
+ seconds: number;
103
+ }[] | undefined;
104
+ }>;
105
+ type UsageMetrics = z.infer<typeof UsageMetrics>;
106
+ /**
107
+ * Metering record
108
+ */
109
+ declare const MeteringRecord: z.ZodObject<{
110
+ timestamp: z.ZodNumber;
111
+ duration: z.ZodNumber;
112
+ amount: z.ZodString;
113
+ rate: z.ZodString;
114
+ cumulative: z.ZodString;
115
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
116
+ }, "strip", z.ZodTypeAny, {
117
+ timestamp: number;
118
+ amount: string;
119
+ rate: string;
120
+ duration: number;
121
+ cumulative: string;
122
+ metadata?: Record<string, unknown> | undefined;
123
+ }, {
124
+ timestamp: number;
125
+ amount: string;
126
+ rate: string;
127
+ duration: number;
128
+ cumulative: string;
129
+ metadata?: Record<string, unknown> | undefined;
130
+ }>;
131
+ type MeteringRecord = z.infer<typeof MeteringRecord>;
132
+ /**
133
+ * Billing period
134
+ */
135
+ declare const BillingPeriod: z.ZodEnum<["realtime", "second", "minute", "hour", "day"]>;
136
+ type BillingPeriod = z.infer<typeof BillingPeriod>;
137
+ /**
138
+ * Billing configuration
139
+ */
140
+ declare const BillingConfig: z.ZodObject<{
141
+ period: z.ZodEnum<["realtime", "second", "minute", "hour", "day"]>;
142
+ minimumCharge: z.ZodDefault<z.ZodString>;
143
+ roundingMode: z.ZodDefault<z.ZodEnum<["floor", "ceil", "round"]>>;
144
+ gracePeriod: z.ZodDefault<z.ZodNumber>;
145
+ invoiceInterval: z.ZodOptional<z.ZodNumber>;
146
+ }, "strip", z.ZodTypeAny, {
147
+ gracePeriod: number;
148
+ period: "hour" | "realtime" | "second" | "minute" | "day";
149
+ minimumCharge: string;
150
+ roundingMode: "floor" | "ceil" | "round";
151
+ invoiceInterval?: number | undefined;
152
+ }, {
153
+ period: "hour" | "realtime" | "second" | "minute" | "day";
154
+ gracePeriod?: number | undefined;
155
+ minimumCharge?: string | undefined;
156
+ roundingMode?: "floor" | "ceil" | "round" | undefined;
157
+ invoiceInterval?: number | undefined;
158
+ }>;
159
+ type BillingConfig = z.infer<typeof BillingConfig>;
160
+ /**
161
+ * Invoice item
162
+ */
163
+ declare const InvoiceItem: z.ZodObject<{
164
+ description: z.ZodString;
165
+ quantity: z.ZodNumber;
166
+ rate: z.ZodString;
167
+ amount: z.ZodString;
168
+ startTime: z.ZodNumber;
169
+ endTime: z.ZodNumber;
170
+ }, "strip", z.ZodTypeAny, {
171
+ startTime: number;
172
+ amount: string;
173
+ rate: string;
174
+ endTime: number;
175
+ description: string;
176
+ quantity: number;
177
+ }, {
178
+ startTime: number;
179
+ amount: string;
180
+ rate: string;
181
+ endTime: number;
182
+ description: string;
183
+ quantity: number;
184
+ }>;
185
+ type InvoiceItem = z.infer<typeof InvoiceItem>;
186
+ /**
187
+ * Invoice
188
+ */
189
+ declare const Invoice: z.ZodObject<{
190
+ id: z.ZodString;
191
+ channelId: z.ZodString;
192
+ payer: z.ZodString;
193
+ payee: z.ZodString;
194
+ items: z.ZodArray<z.ZodObject<{
195
+ description: z.ZodString;
196
+ quantity: z.ZodNumber;
197
+ rate: z.ZodString;
198
+ amount: z.ZodString;
199
+ startTime: z.ZodNumber;
200
+ endTime: z.ZodNumber;
201
+ }, "strip", z.ZodTypeAny, {
202
+ startTime: number;
203
+ amount: string;
204
+ rate: string;
205
+ endTime: number;
206
+ description: string;
207
+ quantity: number;
208
+ }, {
209
+ startTime: number;
210
+ amount: string;
211
+ rate: string;
212
+ endTime: number;
213
+ description: string;
214
+ quantity: number;
215
+ }>, "many">;
216
+ subtotal: z.ZodString;
217
+ fees: z.ZodString;
218
+ total: z.ZodString;
219
+ currency: z.ZodString;
220
+ status: z.ZodEnum<["pending", "paid", "settled", "disputed"]>;
221
+ createdAt: z.ZodNumber;
222
+ dueAt: z.ZodOptional<z.ZodNumber>;
223
+ paidAt: z.ZodOptional<z.ZodNumber>;
224
+ }, "strip", z.ZodTypeAny, {
225
+ status: "pending" | "paid" | "settled" | "disputed";
226
+ payer: string;
227
+ payee: string;
228
+ total: string;
229
+ channelId: string;
230
+ id: string;
231
+ createdAt: number;
232
+ items: {
233
+ startTime: number;
234
+ amount: string;
235
+ rate: string;
236
+ endTime: number;
237
+ description: string;
238
+ quantity: number;
239
+ }[];
240
+ subtotal: string;
241
+ fees: string;
242
+ currency: string;
243
+ dueAt?: number | undefined;
244
+ paidAt?: number | undefined;
245
+ }, {
246
+ status: "pending" | "paid" | "settled" | "disputed";
247
+ payer: string;
248
+ payee: string;
249
+ total: string;
250
+ channelId: string;
251
+ id: string;
252
+ createdAt: number;
253
+ items: {
254
+ startTime: number;
255
+ amount: string;
256
+ rate: string;
257
+ endTime: number;
258
+ description: string;
259
+ quantity: number;
260
+ }[];
261
+ subtotal: string;
262
+ fees: string;
263
+ currency: string;
264
+ dueAt?: number | undefined;
265
+ paidAt?: number | undefined;
266
+ }>;
267
+ type Invoice = z.infer<typeof Invoice>;
268
+ /**
269
+ * Stream session
270
+ */
271
+ declare const StreamSession: z.ZodObject<{
272
+ id: z.ZodString;
273
+ channelId: z.ZodString;
274
+ state: z.ZodEnum<["idle", "active", "paused", "completed", "cancelled"]>;
275
+ rate: z.ZodObject<{
276
+ type: z.ZodEnum<["fixed", "variable", "tiered", "dynamic"]>;
277
+ baseRate: z.ZodString;
278
+ minRate: z.ZodOptional<z.ZodString>;
279
+ maxRate: z.ZodOptional<z.ZodString>;
280
+ tiers: z.ZodOptional<z.ZodArray<z.ZodObject<{
281
+ threshold: z.ZodString;
282
+ rate: z.ZodString;
283
+ }, "strip", z.ZodTypeAny, {
284
+ threshold: string;
285
+ rate: string;
286
+ }, {
287
+ threshold: string;
288
+ rate: string;
289
+ }>, "many">>;
290
+ adjustmentInterval: z.ZodOptional<z.ZodNumber>;
291
+ adjustmentFactor: z.ZodOptional<z.ZodNumber>;
292
+ }, "strip", z.ZodTypeAny, {
293
+ type: "fixed" | "variable" | "tiered" | "dynamic";
294
+ baseRate: string;
295
+ minRate?: string | undefined;
296
+ maxRate?: string | undefined;
297
+ tiers?: {
298
+ threshold: string;
299
+ rate: string;
300
+ }[] | undefined;
301
+ adjustmentInterval?: number | undefined;
302
+ adjustmentFactor?: number | undefined;
303
+ }, {
304
+ type: "fixed" | "variable" | "tiered" | "dynamic";
305
+ baseRate: string;
306
+ minRate?: string | undefined;
307
+ maxRate?: string | undefined;
308
+ tiers?: {
309
+ threshold: string;
310
+ rate: string;
311
+ }[] | undefined;
312
+ adjustmentInterval?: number | undefined;
313
+ adjustmentFactor?: number | undefined;
314
+ }>;
315
+ startedAt: z.ZodOptional<z.ZodNumber>;
316
+ pausedAt: z.ZodOptional<z.ZodNumber>;
317
+ endedAt: z.ZodOptional<z.ZodNumber>;
318
+ totalDuration: z.ZodNumber;
319
+ totalAmount: z.ZodString;
320
+ meteringRecords: z.ZodArray<z.ZodObject<{
321
+ timestamp: z.ZodNumber;
322
+ duration: z.ZodNumber;
323
+ amount: z.ZodString;
324
+ rate: z.ZodString;
325
+ cumulative: z.ZodString;
326
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
327
+ }, "strip", z.ZodTypeAny, {
328
+ timestamp: number;
329
+ amount: string;
330
+ rate: string;
331
+ duration: number;
332
+ cumulative: string;
333
+ metadata?: Record<string, unknown> | undefined;
334
+ }, {
335
+ timestamp: number;
336
+ amount: string;
337
+ rate: string;
338
+ duration: number;
339
+ cumulative: string;
340
+ metadata?: Record<string, unknown> | undefined;
341
+ }>, "many">;
342
+ billingConfig: z.ZodObject<{
343
+ period: z.ZodEnum<["realtime", "second", "minute", "hour", "day"]>;
344
+ minimumCharge: z.ZodDefault<z.ZodString>;
345
+ roundingMode: z.ZodDefault<z.ZodEnum<["floor", "ceil", "round"]>>;
346
+ gracePeriod: z.ZodDefault<z.ZodNumber>;
347
+ invoiceInterval: z.ZodOptional<z.ZodNumber>;
348
+ }, "strip", z.ZodTypeAny, {
349
+ gracePeriod: number;
350
+ period: "hour" | "realtime" | "second" | "minute" | "day";
351
+ minimumCharge: string;
352
+ roundingMode: "floor" | "ceil" | "round";
353
+ invoiceInterval?: number | undefined;
354
+ }, {
355
+ period: "hour" | "realtime" | "second" | "minute" | "day";
356
+ gracePeriod?: number | undefined;
357
+ minimumCharge?: string | undefined;
358
+ roundingMode?: "floor" | "ceil" | "round" | undefined;
359
+ invoiceInterval?: number | undefined;
360
+ }>;
361
+ invoices: z.ZodArray<z.ZodString, "many">;
362
+ }, "strip", z.ZodTypeAny, {
363
+ channelId: string;
364
+ id: string;
365
+ state: "paused" | "idle" | "active" | "completed" | "cancelled";
366
+ rate: {
367
+ type: "fixed" | "variable" | "tiered" | "dynamic";
368
+ baseRate: string;
369
+ minRate?: string | undefined;
370
+ maxRate?: string | undefined;
371
+ tiers?: {
372
+ threshold: string;
373
+ rate: string;
374
+ }[] | undefined;
375
+ adjustmentInterval?: number | undefined;
376
+ adjustmentFactor?: number | undefined;
377
+ };
378
+ totalAmount: string;
379
+ totalDuration: number;
380
+ meteringRecords: {
381
+ timestamp: number;
382
+ amount: string;
383
+ rate: string;
384
+ duration: number;
385
+ cumulative: string;
386
+ metadata?: Record<string, unknown> | undefined;
387
+ }[];
388
+ billingConfig: {
389
+ gracePeriod: number;
390
+ period: "hour" | "realtime" | "second" | "minute" | "day";
391
+ minimumCharge: string;
392
+ roundingMode: "floor" | "ceil" | "round";
393
+ invoiceInterval?: number | undefined;
394
+ };
395
+ invoices: string[];
396
+ pausedAt?: number | undefined;
397
+ startedAt?: number | undefined;
398
+ endedAt?: number | undefined;
399
+ }, {
400
+ channelId: string;
401
+ id: string;
402
+ state: "paused" | "idle" | "active" | "completed" | "cancelled";
403
+ rate: {
404
+ type: "fixed" | "variable" | "tiered" | "dynamic";
405
+ baseRate: string;
406
+ minRate?: string | undefined;
407
+ maxRate?: string | undefined;
408
+ tiers?: {
409
+ threshold: string;
410
+ rate: string;
411
+ }[] | undefined;
412
+ adjustmentInterval?: number | undefined;
413
+ adjustmentFactor?: number | undefined;
414
+ };
415
+ totalAmount: string;
416
+ totalDuration: number;
417
+ meteringRecords: {
418
+ timestamp: number;
419
+ amount: string;
420
+ rate: string;
421
+ duration: number;
422
+ cumulative: string;
423
+ metadata?: Record<string, unknown> | undefined;
424
+ }[];
425
+ billingConfig: {
426
+ period: "hour" | "realtime" | "second" | "minute" | "day";
427
+ gracePeriod?: number | undefined;
428
+ minimumCharge?: string | undefined;
429
+ roundingMode?: "floor" | "ceil" | "round" | undefined;
430
+ invoiceInterval?: number | undefined;
431
+ };
432
+ invoices: string[];
433
+ pausedAt?: number | undefined;
434
+ startedAt?: number | undefined;
435
+ endedAt?: number | undefined;
436
+ }>;
437
+ type StreamSession = z.infer<typeof StreamSession>;
438
+ /**
439
+ * Rate adjustment request
440
+ */
441
+ declare const RateAdjustmentRequest: z.ZodObject<{
442
+ sessionId: z.ZodString;
443
+ newRate: z.ZodString;
444
+ reason: z.ZodString;
445
+ effectiveFrom: z.ZodOptional<z.ZodNumber>;
446
+ signature: z.ZodOptional<z.ZodString>;
447
+ }, "strip", z.ZodTypeAny, {
448
+ reason: string;
449
+ sessionId: string;
450
+ newRate: string;
451
+ signature?: string | undefined;
452
+ effectiveFrom?: number | undefined;
453
+ }, {
454
+ reason: string;
455
+ sessionId: string;
456
+ newRate: string;
457
+ signature?: string | undefined;
458
+ effectiveFrom?: number | undefined;
459
+ }>;
460
+ type RateAdjustmentRequest = z.infer<typeof RateAdjustmentRequest>;
461
+ /**
462
+ * Stream event
463
+ */
464
+ declare const StreamEvent: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
465
+ type: z.ZodLiteral<"started">;
466
+ sessionId: z.ZodString;
467
+ timestamp: z.ZodNumber;
468
+ rate: z.ZodString;
469
+ }, "strip", z.ZodTypeAny, {
470
+ type: "started";
471
+ timestamp: number;
472
+ rate: string;
473
+ sessionId: string;
474
+ }, {
475
+ type: "started";
476
+ timestamp: number;
477
+ rate: string;
478
+ sessionId: string;
479
+ }>, z.ZodObject<{
480
+ type: z.ZodLiteral<"paused">;
481
+ sessionId: z.ZodString;
482
+ timestamp: z.ZodNumber;
483
+ totalStreamed: z.ZodString;
484
+ }, "strip", z.ZodTypeAny, {
485
+ type: "paused";
486
+ timestamp: number;
487
+ sessionId: string;
488
+ totalStreamed: string;
489
+ }, {
490
+ type: "paused";
491
+ timestamp: number;
492
+ sessionId: string;
493
+ totalStreamed: string;
494
+ }>, z.ZodObject<{
495
+ type: z.ZodLiteral<"resumed">;
496
+ sessionId: z.ZodString;
497
+ timestamp: z.ZodNumber;
498
+ }, "strip", z.ZodTypeAny, {
499
+ type: "resumed";
500
+ timestamp: number;
501
+ sessionId: string;
502
+ }, {
503
+ type: "resumed";
504
+ timestamp: number;
505
+ sessionId: string;
506
+ }>, z.ZodObject<{
507
+ type: z.ZodLiteral<"rate_changed">;
508
+ sessionId: z.ZodString;
509
+ timestamp: z.ZodNumber;
510
+ oldRate: z.ZodString;
511
+ newRate: z.ZodString;
512
+ }, "strip", z.ZodTypeAny, {
513
+ type: "rate_changed";
514
+ timestamp: number;
515
+ sessionId: string;
516
+ newRate: string;
517
+ oldRate: string;
518
+ }, {
519
+ type: "rate_changed";
520
+ timestamp: number;
521
+ sessionId: string;
522
+ newRate: string;
523
+ oldRate: string;
524
+ }>, z.ZodObject<{
525
+ type: z.ZodLiteral<"checkpoint">;
526
+ sessionId: z.ZodString;
527
+ timestamp: z.ZodNumber;
528
+ amount: z.ZodString;
529
+ checkpointId: z.ZodString;
530
+ }, "strip", z.ZodTypeAny, {
531
+ type: "checkpoint";
532
+ timestamp: number;
533
+ amount: string;
534
+ sessionId: string;
535
+ checkpointId: string;
536
+ }, {
537
+ type: "checkpoint";
538
+ timestamp: number;
539
+ amount: string;
540
+ sessionId: string;
541
+ checkpointId: string;
542
+ }>, z.ZodObject<{
543
+ type: z.ZodLiteral<"completed">;
544
+ sessionId: z.ZodString;
545
+ timestamp: z.ZodNumber;
546
+ totalAmount: z.ZodString;
547
+ totalDuration: z.ZodNumber;
548
+ }, "strip", z.ZodTypeAny, {
549
+ type: "completed";
550
+ timestamp: number;
551
+ totalAmount: string;
552
+ totalDuration: number;
553
+ sessionId: string;
554
+ }, {
555
+ type: "completed";
556
+ timestamp: number;
557
+ totalAmount: string;
558
+ totalDuration: number;
559
+ sessionId: string;
560
+ }>, z.ZodObject<{
561
+ type: z.ZodLiteral<"cancelled">;
562
+ sessionId: z.ZodString;
563
+ timestamp: z.ZodNumber;
564
+ reason: z.ZodString;
565
+ }, "strip", z.ZodTypeAny, {
566
+ type: "cancelled";
567
+ timestamp: number;
568
+ reason: string;
569
+ sessionId: string;
570
+ }, {
571
+ type: "cancelled";
572
+ timestamp: number;
573
+ reason: string;
574
+ sessionId: string;
575
+ }>]>;
576
+ type StreamEvent = z.infer<typeof StreamEvent>;
577
+
578
+ /**
579
+ * Flow controller configuration
580
+ */
581
+ interface FlowConfig {
582
+ updateInterval?: number;
583
+ bufferTime?: number;
584
+ autoCheckpoint?: boolean;
585
+ checkpointInterval?: number;
586
+ }
587
+ /**
588
+ * Flow controller for managing streaming sessions
589
+ */
590
+ declare class FlowController {
591
+ private session;
592
+ private config;
593
+ private updateTimer?;
594
+ private checkpointTimer?;
595
+ private eventListeners;
596
+ private lastUpdateTime;
597
+ constructor(channelId: string, rate: StreamRate, billingConfig: BillingConfig, config?: FlowConfig);
598
+ /**
599
+ * Get current session state
600
+ */
601
+ getSession(): StreamSession;
602
+ /**
603
+ * Get current state
604
+ */
605
+ getState(): StreamState;
606
+ /**
607
+ * Start streaming
608
+ */
609
+ start(): {
610
+ success: boolean;
611
+ error?: string;
612
+ };
613
+ /**
614
+ * Pause streaming
615
+ */
616
+ pause(): {
617
+ success: boolean;
618
+ error?: string;
619
+ };
620
+ /**
621
+ * Resume streaming (alias for start when paused)
622
+ */
623
+ resume(): {
624
+ success: boolean;
625
+ error?: string;
626
+ };
627
+ /**
628
+ * Stop streaming (complete)
629
+ */
630
+ stop(): {
631
+ success: boolean;
632
+ error?: string;
633
+ finalAmount: string;
634
+ };
635
+ /**
636
+ * Cancel streaming
637
+ */
638
+ cancel(reason: string): {
639
+ success: boolean;
640
+ error?: string;
641
+ };
642
+ /**
643
+ * Get current streamed amount
644
+ */
645
+ getCurrentAmount(): string;
646
+ /**
647
+ * Get current rate
648
+ */
649
+ getCurrentRate(): string;
650
+ /**
651
+ * Get time until exhaustion (returns -1 if infinite)
652
+ */
653
+ getTimeUntilExhaustion(channelCapacity: string): number;
654
+ /**
655
+ * Check if stream is near exhaustion
656
+ */
657
+ isNearExhaustion(channelCapacity: string): boolean;
658
+ /**
659
+ * Create manual checkpoint
660
+ */
661
+ createCheckpoint(): {
662
+ id: string;
663
+ amount: string;
664
+ timestamp: number;
665
+ };
666
+ /**
667
+ * Subscribe to stream events
668
+ */
669
+ onEvent(callback: (event: StreamEvent) => void): () => void;
670
+ /**
671
+ * Clean up resources
672
+ */
673
+ destroy(): void;
674
+ private startUpdateTimer;
675
+ private startCheckpointTimer;
676
+ private stopTimers;
677
+ private updateTotals;
678
+ private calculateAmount;
679
+ private getEffectiveRate;
680
+ private addMeteringRecord;
681
+ private emitEvent;
682
+ private generateSessionId;
683
+ }
684
+ /**
685
+ * Create a simple fixed-rate flow controller
686
+ */
687
+ declare function createFixedRateFlow(channelId: string, ratePerSecond: string, config?: FlowConfig): FlowController;
688
+ /**
689
+ * Create a tiered rate flow controller
690
+ */
691
+ declare function createTieredRateFlow(channelId: string, baseRate: string, tiers: Array<{
692
+ threshold: string;
693
+ rate: string;
694
+ }>, config?: FlowConfig): FlowController;
695
+
696
+ /**
697
+ * Rate controller configuration
698
+ */
699
+ interface RateControllerConfig {
700
+ maxChangePercent?: number;
701
+ minChangeInterval?: number;
702
+ smoothingFactor?: number;
703
+ }
704
+ /**
705
+ * Rate history entry
706
+ */
707
+ interface RateHistoryEntry {
708
+ timestamp: number;
709
+ rate: string;
710
+ reason: string;
711
+ previousRate: string;
712
+ }
713
+ /**
714
+ * Rate controller for managing and adjusting streaming rates
715
+ */
716
+ declare class RateController {
717
+ private currentRate;
718
+ private config;
719
+ private history;
720
+ private lastChangeTime;
721
+ constructor(initialRate: StreamRate, config?: RateControllerConfig);
722
+ /**
723
+ * Get current rate configuration
724
+ */
725
+ getRate(): StreamRate;
726
+ /**
727
+ * Get current effective rate
728
+ */
729
+ getEffectiveRate(totalUsage?: string): string;
730
+ /**
731
+ * Request rate adjustment
732
+ */
733
+ adjustRate(request: RateAdjustmentRequest): {
734
+ success: boolean;
735
+ error?: string;
736
+ newRate?: string;
737
+ adjustedAmount?: string;
738
+ };
739
+ /**
740
+ * Set rate bounds
741
+ */
742
+ setBounds(minRate?: string, maxRate?: string): void;
743
+ /**
744
+ * Add or update a tier
745
+ */
746
+ addTier(threshold: string, rate: string): void;
747
+ /**
748
+ * Remove a tier
749
+ */
750
+ removeTier(threshold: string): boolean;
751
+ /**
752
+ * Get rate history
753
+ */
754
+ getHistory(): RateHistoryEntry[];
755
+ /**
756
+ * Calculate average rate over time period
757
+ */
758
+ getAverageRate(startTime: number, endTime: number): string;
759
+ /**
760
+ * Calculate rate for dynamic pricing based on demand
761
+ */
762
+ calculateDynamicRate(demand: number, // 0-1 representing demand level
763
+ _baseRate?: string): string;
764
+ /**
765
+ * Apply exponential smoothing for rate changes
766
+ */
767
+ smoothRate(targetRate: string): string;
768
+ private calculateTieredRate;
769
+ private calculateChangePercent;
770
+ private applyMaxChange;
771
+ }
772
+ /**
773
+ * Rate limiter for preventing abuse
774
+ */
775
+ declare class RateLimiter {
776
+ private requests;
777
+ private maxRequests;
778
+ private windowMs;
779
+ constructor(maxRequests?: number, windowMs?: number);
780
+ /**
781
+ * Check if request is allowed
782
+ */
783
+ isAllowed(key: string): boolean;
784
+ /**
785
+ * Get remaining requests in window
786
+ */
787
+ getRemainingRequests(key: string): number;
788
+ /**
789
+ * Reset limits for a key
790
+ */
791
+ reset(key: string): void;
792
+ /**
793
+ * Clear all limits
794
+ */
795
+ clear(): void;
796
+ }
797
+ /**
798
+ * Calculate optimal rate based on channel parameters
799
+ */
800
+ declare function calculateOptimalRate(channelCapacity: string, desiredDurationSeconds: number, bufferPercent?: number): string;
801
+ /**
802
+ * Convert rate between time units
803
+ */
804
+ declare function convertRate(rate: string, fromUnit: 'second' | 'minute' | 'hour' | 'day', toUnit: 'second' | 'minute' | 'hour' | 'day'): string;
805
+
806
+ /**
807
+ * Metering configuration
808
+ */
809
+ interface MeteringConfig {
810
+ recordInterval?: number;
811
+ aggregationInterval?: number;
812
+ maxRecords?: number;
813
+ precision?: number;
814
+ }
815
+ /**
816
+ * Aggregated usage data
817
+ */
818
+ interface AggregatedUsage {
819
+ period: string;
820
+ totalAmount: string;
821
+ totalDuration: number;
822
+ averageRate: string;
823
+ recordCount: number;
824
+ }
825
+ /**
826
+ * Metering manager for tracking usage
827
+ */
828
+ declare class MeteringManager {
829
+ private records;
830
+ private config;
831
+ private sessionId;
832
+ private startTime;
833
+ constructor(sessionId: string, config?: MeteringConfig);
834
+ /**
835
+ * Record usage
836
+ */
837
+ record(duration: number, amount: string, rate: string, metadata?: Record<string, unknown>): MeteringRecord;
838
+ /**
839
+ * Get all records
840
+ */
841
+ getRecords(): MeteringRecord[];
842
+ /**
843
+ * Get records in time range
844
+ */
845
+ getRecordsInRange(startTime: number, endTime: number): MeteringRecord[];
846
+ /**
847
+ * Calculate usage metrics
848
+ */
849
+ getMetrics(): UsageMetrics;
850
+ /**
851
+ * Get aggregated usage by period
852
+ */
853
+ aggregate(intervalSeconds?: number): AggregatedUsage[];
854
+ /**
855
+ * Get cumulative amount at a point in time
856
+ */
857
+ getCumulativeAt(timestamp: number): string;
858
+ /**
859
+ * Calculate usage for billing period
860
+ */
861
+ getUsageForBillingPeriod(startTime: number, endTime: number): {
862
+ amount: string;
863
+ duration: number;
864
+ records: number;
865
+ };
866
+ /**
867
+ * Export records for backup/audit
868
+ */
869
+ export(): string;
870
+ /**
871
+ * Import records from backup
872
+ */
873
+ import(data: string): {
874
+ success: boolean;
875
+ recordsImported: number;
876
+ };
877
+ /**
878
+ * Clear all records
879
+ */
880
+ clear(): void;
881
+ private calculateCumulative;
882
+ private pruneRecords;
883
+ private getHourlyBreakdown;
884
+ }
885
+ /**
886
+ * Calculate pro-rated usage for partial periods
887
+ */
888
+ declare function calculateProRatedUsage(fullPeriodAmount: string, fullPeriodSeconds: number, actualSeconds: number): string;
889
+ /**
890
+ * Estimate usage based on historical data
891
+ */
892
+ declare function estimateUsage(metrics: UsageMetrics, futureSeconds: number): string;
893
+ /**
894
+ * Compare usage across periods
895
+ */
896
+ declare function compareUsage(current: UsageMetrics, previous: UsageMetrics): {
897
+ amountChange: string;
898
+ amountChangePercent: number;
899
+ rateChange: string;
900
+ rateChangePercent: number;
901
+ };
902
+
903
+ /**
904
+ * Billing manager configuration
905
+ */
906
+ interface BillingManagerConfig {
907
+ autoInvoice?: boolean;
908
+ invoiceInterval?: number;
909
+ currency?: string;
910
+ taxRate?: number;
911
+ }
912
+ /**
913
+ * Billing manager for generating invoices from metering data
914
+ */
915
+ declare class BillingManager {
916
+ private config;
917
+ private billingConfig;
918
+ private invoices;
919
+ private channelId;
920
+ private payer;
921
+ private payee;
922
+ private lastInvoiceTime;
923
+ constructor(channelId: string, payer: string, payee: string, billingConfig: BillingConfig, config?: BillingManagerConfig);
924
+ /**
925
+ * Generate invoice from metering records
926
+ */
927
+ generateInvoice(records: MeteringRecord[], startTime: number, endTime: number): Invoice;
928
+ /**
929
+ * Get all invoices
930
+ */
931
+ getInvoices(): Invoice[];
932
+ /**
933
+ * Get invoice by ID
934
+ */
935
+ getInvoice(id: string): Invoice | undefined;
936
+ /**
937
+ * Mark invoice as paid
938
+ */
939
+ markPaid(invoiceId: string): boolean;
940
+ /**
941
+ * Mark invoice as settled
942
+ */
943
+ markSettled(invoiceId: string): boolean;
944
+ /**
945
+ * Get pending amount
946
+ */
947
+ getPendingAmount(): string;
948
+ /**
949
+ * Get total billed amount
950
+ */
951
+ getTotalBilled(): string;
952
+ /**
953
+ * Check if new invoice is due
954
+ */
955
+ isInvoiceDue(currentTime: number): boolean;
956
+ /**
957
+ * Calculate amount for billing period
958
+ */
959
+ calculatePeriodAmount(rate: string, durationSeconds: number): string;
960
+ /**
961
+ * Apply minimum charge
962
+ */
963
+ applyMinimumCharge(amount: string): string;
964
+ /**
965
+ * Calculate grace period savings
966
+ */
967
+ calculateGracePeriodSavings(rate: string, totalDuration: number): string;
968
+ /**
969
+ * Get billing summary
970
+ */
971
+ getSummary(): {
972
+ totalInvoices: number;
973
+ totalBilled: string;
974
+ totalPaid: string;
975
+ totalPending: string;
976
+ averageInvoice: string;
977
+ };
978
+ /**
979
+ * Export billing data
980
+ */
981
+ export(): string;
982
+ private createInvoiceItems;
983
+ private calculateSubtotal;
984
+ private calculateFees;
985
+ private applyRounding;
986
+ private getPeriodSeconds;
987
+ private getPeriodName;
988
+ private calculateQuantity;
989
+ private generateInvoiceId;
990
+ }
991
+ /**
992
+ * Format currency amount for display
993
+ */
994
+ declare function formatCurrencyAmount(amount: string, decimals?: number, symbol?: string): string;
995
+ /**
996
+ * Parse currency amount from display format
997
+ */
998
+ declare function parseCurrencyAmount(display: string, decimals?: number): string;
999
+ /**
1000
+ * Calculate estimated bill for future period
1001
+ */
1002
+ declare function estimateFutureBill(currentRate: string, durationSeconds: number, minimumCharge?: string): string;
1003
+
1004
+ export { type AggregatedUsage, BillingConfig, BillingManager, type BillingManagerConfig, BillingPeriod, type FlowConfig, FlowController, Invoice, InvoiceItem, type MeteringConfig, MeteringManager, MeteringRecord, RateAdjustmentRequest, RateController, type RateControllerConfig, type RateHistoryEntry, RateLimiter, RateType, StreamEvent, StreamRate, StreamSession, StreamState, UsageMetrics, calculateOptimalRate, calculateProRatedUsage, compareUsage, convertRate, createFixedRateFlow, createTieredRateFlow, estimateFutureBill, estimateUsage, formatCurrencyAmount, parseCurrencyAmount };