@moneymq/sdk 0.9.2 → 0.9.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +200 -2
- package/dist/index.d.ts +200 -2
- package/dist/index.js +338 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +338 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -430,6 +430,76 @@ declare class ChannelError extends Error {
|
|
|
430
430
|
code: string;
|
|
431
431
|
constructor(message: string, code: string);
|
|
432
432
|
}
|
|
433
|
+
/**
|
|
434
|
+
* Event message from the stream
|
|
435
|
+
*/
|
|
436
|
+
interface EventStreamMessage<T = unknown> {
|
|
437
|
+
type: 'event';
|
|
438
|
+
event: ChannelEvent<T>;
|
|
439
|
+
}
|
|
440
|
+
/**
|
|
441
|
+
* Connection state change message
|
|
442
|
+
*/
|
|
443
|
+
interface StateStreamMessage {
|
|
444
|
+
type: 'state';
|
|
445
|
+
state: ConnectionState;
|
|
446
|
+
}
|
|
447
|
+
/**
|
|
448
|
+
* Error message from the stream
|
|
449
|
+
*/
|
|
450
|
+
interface ErrorStreamMessage {
|
|
451
|
+
type: 'error';
|
|
452
|
+
error: ChannelError;
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* Transaction with actor factory method and convenience methods
|
|
456
|
+
*/
|
|
457
|
+
interface TransactionWithActor extends Transaction {
|
|
458
|
+
/** Create an actor scoped to this transaction's channel */
|
|
459
|
+
actor(options?: Omit<ActorOptions, 'secret'>): EventActor;
|
|
460
|
+
/**
|
|
461
|
+
* Stream events for this transaction
|
|
462
|
+
*
|
|
463
|
+
* Creates an actor internally and yields events from the transaction's channel.
|
|
464
|
+
*/
|
|
465
|
+
events(options?: {
|
|
466
|
+
signal?: AbortSignal;
|
|
467
|
+
}): AsyncGenerator<ChannelEvent>;
|
|
468
|
+
/**
|
|
469
|
+
* Attach data to this transaction's channel
|
|
470
|
+
*
|
|
471
|
+
* Creates an actor internally if not already created.
|
|
472
|
+
* The server will create a signed receipt JWT and emit a transaction:completed event.
|
|
473
|
+
*/
|
|
474
|
+
attach<T = unknown>(data: T): Promise<ChannelEvent<T>>;
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* Transaction message (for receivers)
|
|
478
|
+
* Note: The transaction has an actor() method to create a scoped EventActor
|
|
479
|
+
*/
|
|
480
|
+
interface TransactionStreamMessage {
|
|
481
|
+
type: 'transaction';
|
|
482
|
+
transaction: TransactionWithActor;
|
|
483
|
+
}
|
|
484
|
+
/**
|
|
485
|
+
* Union of all channel stream message types
|
|
486
|
+
*/
|
|
487
|
+
type ChannelStreamMessage<T = unknown> = EventStreamMessage<T> | StateStreamMessage | ErrorStreamMessage;
|
|
488
|
+
/**
|
|
489
|
+
* Union of all receiver stream message types
|
|
490
|
+
*/
|
|
491
|
+
type ReceiverStreamMessage = TransactionStreamMessage | StateStreamMessage | ErrorStreamMessage;
|
|
492
|
+
/**
|
|
493
|
+
* Options for the stream() method
|
|
494
|
+
*/
|
|
495
|
+
interface StreamOptions {
|
|
496
|
+
/** AbortSignal to cancel the stream */
|
|
497
|
+
signal?: AbortSignal;
|
|
498
|
+
/** Include state change messages (default: true) */
|
|
499
|
+
includeState?: boolean;
|
|
500
|
+
/** Include error messages (default: true) */
|
|
501
|
+
includeErrors?: boolean;
|
|
502
|
+
}
|
|
433
503
|
/**
|
|
434
504
|
* Base class for channel connections (shared by Reader and Actor)
|
|
435
505
|
*/
|
|
@@ -480,6 +550,47 @@ declare abstract class BaseChannel {
|
|
|
480
550
|
* Disconnect from the channel
|
|
481
551
|
*/
|
|
482
552
|
disconnect(): void;
|
|
553
|
+
/**
|
|
554
|
+
* Stream events as an async iterable
|
|
555
|
+
*
|
|
556
|
+
* Automatically connects and yields messages until disconnected or aborted.
|
|
557
|
+
*
|
|
558
|
+
* @example
|
|
559
|
+
* ```typescript
|
|
560
|
+
* const reader = moneymq.payment.listener('tx-123');
|
|
561
|
+
*
|
|
562
|
+
* for await (const message of reader.stream()) {
|
|
563
|
+
* if (message.type === 'event') {
|
|
564
|
+
* console.log('Event:', message.event.type, message.event.data);
|
|
565
|
+
* } else if (message.type === 'state') {
|
|
566
|
+
* console.log('State:', message.state);
|
|
567
|
+
* } else if (message.type === 'error') {
|
|
568
|
+
* console.error('Error:', message.error);
|
|
569
|
+
* }
|
|
570
|
+
* }
|
|
571
|
+
* ```
|
|
572
|
+
*/
|
|
573
|
+
stream<T = unknown>(options?: StreamOptions): AsyncGenerator<ChannelStreamMessage<T>>;
|
|
574
|
+
/**
|
|
575
|
+
* Stream events directly as an async iterable
|
|
576
|
+
*
|
|
577
|
+
* Simpler API that only yields events, ignoring state/error messages.
|
|
578
|
+
* Automatically connects and yields until disconnected or aborted.
|
|
579
|
+
*
|
|
580
|
+
* @example
|
|
581
|
+
* ```typescript
|
|
582
|
+
* const listener = moneymq.payment.listener('tx-123');
|
|
583
|
+
*
|
|
584
|
+
* for await (const event of listener.events()) {
|
|
585
|
+
* if (event.type === 'payment:settled') {
|
|
586
|
+
* console.log('Payment settled:', event.data.amount);
|
|
587
|
+
* }
|
|
588
|
+
* }
|
|
589
|
+
* ```
|
|
590
|
+
*/
|
|
591
|
+
events<T = unknown>(options?: {
|
|
592
|
+
signal?: AbortSignal;
|
|
593
|
+
}): AsyncGenerator<ChannelEvent<T>>;
|
|
483
594
|
protected abstract buildUrl(): string;
|
|
484
595
|
protected handleMessage(event: MessageEvent): void;
|
|
485
596
|
protected setState(state: ConnectionState): void;
|
|
@@ -555,7 +666,7 @@ declare class EventActor extends BaseChannel {
|
|
|
555
666
|
/**
|
|
556
667
|
* Transaction wrapper for receiver callbacks
|
|
557
668
|
*/
|
|
558
|
-
declare class TransactionContext implements
|
|
669
|
+
declare class TransactionContext implements TransactionWithActor {
|
|
559
670
|
id: string;
|
|
560
671
|
channelId: string;
|
|
561
672
|
basket: BasketItem$1[];
|
|
@@ -563,7 +674,12 @@ declare class TransactionContext implements Transaction {
|
|
|
563
674
|
metadata?: Record<string, unknown>;
|
|
564
675
|
private endpoint;
|
|
565
676
|
private secret;
|
|
677
|
+
private _actor;
|
|
566
678
|
constructor(data: Transaction, endpoint: string, secret: string);
|
|
679
|
+
/**
|
|
680
|
+
* Get or create the internal actor (lazy initialization)
|
|
681
|
+
*/
|
|
682
|
+
private getOrCreateActor;
|
|
567
683
|
/**
|
|
568
684
|
* Get the payment amount as string (from payment details)
|
|
569
685
|
*/
|
|
@@ -592,8 +708,39 @@ declare class TransactionContext implements Transaction {
|
|
|
592
708
|
* Create an actor scoped to this transaction's channel
|
|
593
709
|
*
|
|
594
710
|
* The actor is automatically connected.
|
|
711
|
+
* Note: If you use events() or send() methods, they share the same internal actor.
|
|
595
712
|
*/
|
|
596
713
|
actor(options?: Omit<ActorOptions, 'secret'>): EventActor;
|
|
714
|
+
/**
|
|
715
|
+
* Stream events for this transaction
|
|
716
|
+
*
|
|
717
|
+
* Creates an actor internally and yields events from the transaction's channel.
|
|
718
|
+
*
|
|
719
|
+
* @example
|
|
720
|
+
* ```typescript
|
|
721
|
+
* for await (const event of tx.events()) {
|
|
722
|
+
* if (event.type === 'payment:settled') {
|
|
723
|
+
* await tx.send('order:completed', { orderId: tx.id });
|
|
724
|
+
* break;
|
|
725
|
+
* }
|
|
726
|
+
* }
|
|
727
|
+
* ```
|
|
728
|
+
*/
|
|
729
|
+
events(options?: {
|
|
730
|
+
signal?: AbortSignal;
|
|
731
|
+
}): AsyncGenerator<ChannelEvent>;
|
|
732
|
+
/**
|
|
733
|
+
* Attach data to this transaction's channel
|
|
734
|
+
*
|
|
735
|
+
* Creates an actor internally if not already created.
|
|
736
|
+
* The server will create a signed receipt JWT and emit a transaction:completed event.
|
|
737
|
+
*
|
|
738
|
+
* @example
|
|
739
|
+
* ```typescript
|
|
740
|
+
* await tx.attach({ orderId: tx.id, trackingNumber: '...' });
|
|
741
|
+
* ```
|
|
742
|
+
*/
|
|
743
|
+
attach<T = unknown>(data: T): Promise<ChannelEvent<T>>;
|
|
597
744
|
}
|
|
598
745
|
/**
|
|
599
746
|
* Transaction handler callback
|
|
@@ -666,6 +813,57 @@ declare class EventReceiver {
|
|
|
666
813
|
* Disconnect from the transaction stream
|
|
667
814
|
*/
|
|
668
815
|
disconnect(): void;
|
|
816
|
+
/**
|
|
817
|
+
* Stream transactions as an async iterable
|
|
818
|
+
*
|
|
819
|
+
* Automatically connects and yields messages until disconnected or aborted.
|
|
820
|
+
*
|
|
821
|
+
* @example
|
|
822
|
+
* ```typescript
|
|
823
|
+
* const receiver = moneymq.payment.processor();
|
|
824
|
+
*
|
|
825
|
+
* for await (const message of receiver.stream()) {
|
|
826
|
+
* if (message.type === 'transaction') {
|
|
827
|
+
* const tx = message.transaction;
|
|
828
|
+
* console.log('New transaction:', tx.id);
|
|
829
|
+
*
|
|
830
|
+
* const actor = tx.actor();
|
|
831
|
+
* // Handle the transaction...
|
|
832
|
+
* } else if (message.type === 'state') {
|
|
833
|
+
* console.log('State:', message.state);
|
|
834
|
+
* } else if (message.type === 'error') {
|
|
835
|
+
* console.error('Error:', message.error);
|
|
836
|
+
* }
|
|
837
|
+
* }
|
|
838
|
+
* ```
|
|
839
|
+
*/
|
|
840
|
+
stream(options?: StreamOptions): AsyncGenerator<ReceiverStreamMessage>;
|
|
841
|
+
/**
|
|
842
|
+
* Stream transactions directly as an async iterable
|
|
843
|
+
*
|
|
844
|
+
* Simpler API that only yields transactions, ignoring state/error messages.
|
|
845
|
+
* Automatically connects and yields until disconnected or aborted.
|
|
846
|
+
*
|
|
847
|
+
* @example
|
|
848
|
+
* ```typescript
|
|
849
|
+
* const processor = moneymq.payment.processor();
|
|
850
|
+
*
|
|
851
|
+
* for await (const tx of processor.transactions()) {
|
|
852
|
+
* console.log('New transaction:', tx.id, tx.payment?.amount);
|
|
853
|
+
*
|
|
854
|
+
* const actor = tx.actor();
|
|
855
|
+
* for await (const event of actor.events()) {
|
|
856
|
+
* if (event.type === 'payment:settled') {
|
|
857
|
+
* await actor.send('order:completed', { orderId: tx.id });
|
|
858
|
+
* break;
|
|
859
|
+
* }
|
|
860
|
+
* }
|
|
861
|
+
* }
|
|
862
|
+
* ```
|
|
863
|
+
*/
|
|
864
|
+
transactions(options?: {
|
|
865
|
+
signal?: AbortSignal;
|
|
866
|
+
}): AsyncGenerator<TransactionWithActor>;
|
|
669
867
|
private setState;
|
|
670
868
|
private shouldReconnect;
|
|
671
869
|
private scheduleReconnect;
|
|
@@ -1887,4 +2085,4 @@ declare class CheckoutReceipt {
|
|
|
1887
2085
|
};
|
|
1888
2086
|
}
|
|
1889
2087
|
|
|
1890
|
-
export { type ActorOptions, type Attachments, type BasketItem, ChannelError, type ChannelErrorHandler, type ChannelEvent, type ChannelEventHandler, type CheckoutCreateParams, type CheckoutLineItem, CheckoutReceipt, type CheckoutSession, type CloudEventEnvelope, type ConnectionHandler, type ConnectionState, type Customer, type CustomerCreateParams, type CustomerUpdateParams, type ErrorHandler, EventActor, type EventHandler, EventReader, EventReceiver, EventStream, type EventStreamOptions, type EventStreamState, type ExperimentConfig, type GetSignerParams, MoneyMQ, type MoneyMQConfig, type MoneyMQEventMap, type MoneyMQEventType, type PayParams, type PayResult, type Payment, type PaymentDetails, type PaymentEvent, type PaymentFlow, type PaymentIntent, type PaymentIntentCreateParams, type PaymentLink, type PaymentLinkCreateParams, type PaymentListParams, PaymentRequiredError, type PaymentRequirements, type PaymentSettlementEvent, type PaymentSettlementFailedData, type PaymentSettlementSucceededData, type PaymentVerificationEvent, type PaymentVerificationFailedData, type PaymentVerificationSucceededData, type Payout, type PayoutCreateParams, type PayoutListParams, type PayoutSettings, type PayoutSettingsUpdateParams, type Price, type PriceCreateParams, type PriceRecurring, type ProcessorData, type Product, type ProductAccessParams, type ProductAccessResponse, type ProductCreateParams, type ProductFeature$1 as ProductFeature, type ProductListParams, type ProductPrice, type ReaderOptions, type ReceiptClaims, type ReceiverOptions, type ServerConfig, type StateHandler, type Transaction, type TransactionHandler, type X402ClientConfig, buildEventStreamUrl, computeChannelId, createEventActor, createEventReader, createEventReceiver, createEventStream, fetchConfig, getRpcUrl, isPaymentSettlementFailed, isPaymentSettlementSucceeded, isPaymentVerificationFailed, isPaymentVerificationSucceeded, parseCloudEvent };
|
|
2088
|
+
export { type ActorOptions, type Attachments, type BasketItem, ChannelError, type ChannelErrorHandler, type ChannelEvent, type ChannelEventHandler, type ChannelStreamMessage, type CheckoutCreateParams, type CheckoutLineItem, CheckoutReceipt, type CheckoutSession, type CloudEventEnvelope, type ConnectionHandler, type ConnectionState, type Customer, type CustomerCreateParams, type CustomerUpdateParams, type ErrorHandler, type ErrorStreamMessage, EventActor, type EventHandler, EventReader, EventReceiver, EventStream, type EventStreamMessage, type EventStreamOptions, type EventStreamState, type ExperimentConfig, type GetSignerParams, MoneyMQ, type MoneyMQConfig, type MoneyMQEventMap, type MoneyMQEventType, type PayParams, type PayResult, type Payment, type PaymentDetails, type PaymentEvent, type PaymentFlow, type PaymentIntent, type PaymentIntentCreateParams, type PaymentLink, type PaymentLinkCreateParams, type PaymentListParams, PaymentRequiredError, type PaymentRequirements, type PaymentSettlementEvent, type PaymentSettlementFailedData, type PaymentSettlementSucceededData, type PaymentVerificationEvent, type PaymentVerificationFailedData, type PaymentVerificationSucceededData, type Payout, type PayoutCreateParams, type PayoutListParams, type PayoutSettings, type PayoutSettingsUpdateParams, type Price, type PriceCreateParams, type PriceRecurring, type ProcessorData, type Product, type ProductAccessParams, type ProductAccessResponse, type ProductCreateParams, type ProductFeature$1 as ProductFeature, type ProductListParams, type ProductPrice, type ReaderOptions, type ReceiptClaims, type ReceiverOptions, type ReceiverStreamMessage, type ServerConfig, type StateHandler, type StateStreamMessage, type StreamOptions, type Transaction, type TransactionHandler, type TransactionStreamMessage, type TransactionWithActor, type X402ClientConfig, buildEventStreamUrl, computeChannelId, createEventActor, createEventReader, createEventReceiver, createEventStream, fetchConfig, getRpcUrl, isPaymentSettlementFailed, isPaymentSettlementSucceeded, isPaymentVerificationFailed, isPaymentVerificationSucceeded, parseCloudEvent };
|
package/dist/index.d.ts
CHANGED
|
@@ -430,6 +430,76 @@ declare class ChannelError extends Error {
|
|
|
430
430
|
code: string;
|
|
431
431
|
constructor(message: string, code: string);
|
|
432
432
|
}
|
|
433
|
+
/**
|
|
434
|
+
* Event message from the stream
|
|
435
|
+
*/
|
|
436
|
+
interface EventStreamMessage<T = unknown> {
|
|
437
|
+
type: 'event';
|
|
438
|
+
event: ChannelEvent<T>;
|
|
439
|
+
}
|
|
440
|
+
/**
|
|
441
|
+
* Connection state change message
|
|
442
|
+
*/
|
|
443
|
+
interface StateStreamMessage {
|
|
444
|
+
type: 'state';
|
|
445
|
+
state: ConnectionState;
|
|
446
|
+
}
|
|
447
|
+
/**
|
|
448
|
+
* Error message from the stream
|
|
449
|
+
*/
|
|
450
|
+
interface ErrorStreamMessage {
|
|
451
|
+
type: 'error';
|
|
452
|
+
error: ChannelError;
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* Transaction with actor factory method and convenience methods
|
|
456
|
+
*/
|
|
457
|
+
interface TransactionWithActor extends Transaction {
|
|
458
|
+
/** Create an actor scoped to this transaction's channel */
|
|
459
|
+
actor(options?: Omit<ActorOptions, 'secret'>): EventActor;
|
|
460
|
+
/**
|
|
461
|
+
* Stream events for this transaction
|
|
462
|
+
*
|
|
463
|
+
* Creates an actor internally and yields events from the transaction's channel.
|
|
464
|
+
*/
|
|
465
|
+
events(options?: {
|
|
466
|
+
signal?: AbortSignal;
|
|
467
|
+
}): AsyncGenerator<ChannelEvent>;
|
|
468
|
+
/**
|
|
469
|
+
* Attach data to this transaction's channel
|
|
470
|
+
*
|
|
471
|
+
* Creates an actor internally if not already created.
|
|
472
|
+
* The server will create a signed receipt JWT and emit a transaction:completed event.
|
|
473
|
+
*/
|
|
474
|
+
attach<T = unknown>(data: T): Promise<ChannelEvent<T>>;
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* Transaction message (for receivers)
|
|
478
|
+
* Note: The transaction has an actor() method to create a scoped EventActor
|
|
479
|
+
*/
|
|
480
|
+
interface TransactionStreamMessage {
|
|
481
|
+
type: 'transaction';
|
|
482
|
+
transaction: TransactionWithActor;
|
|
483
|
+
}
|
|
484
|
+
/**
|
|
485
|
+
* Union of all channel stream message types
|
|
486
|
+
*/
|
|
487
|
+
type ChannelStreamMessage<T = unknown> = EventStreamMessage<T> | StateStreamMessage | ErrorStreamMessage;
|
|
488
|
+
/**
|
|
489
|
+
* Union of all receiver stream message types
|
|
490
|
+
*/
|
|
491
|
+
type ReceiverStreamMessage = TransactionStreamMessage | StateStreamMessage | ErrorStreamMessage;
|
|
492
|
+
/**
|
|
493
|
+
* Options for the stream() method
|
|
494
|
+
*/
|
|
495
|
+
interface StreamOptions {
|
|
496
|
+
/** AbortSignal to cancel the stream */
|
|
497
|
+
signal?: AbortSignal;
|
|
498
|
+
/** Include state change messages (default: true) */
|
|
499
|
+
includeState?: boolean;
|
|
500
|
+
/** Include error messages (default: true) */
|
|
501
|
+
includeErrors?: boolean;
|
|
502
|
+
}
|
|
433
503
|
/**
|
|
434
504
|
* Base class for channel connections (shared by Reader and Actor)
|
|
435
505
|
*/
|
|
@@ -480,6 +550,47 @@ declare abstract class BaseChannel {
|
|
|
480
550
|
* Disconnect from the channel
|
|
481
551
|
*/
|
|
482
552
|
disconnect(): void;
|
|
553
|
+
/**
|
|
554
|
+
* Stream events as an async iterable
|
|
555
|
+
*
|
|
556
|
+
* Automatically connects and yields messages until disconnected or aborted.
|
|
557
|
+
*
|
|
558
|
+
* @example
|
|
559
|
+
* ```typescript
|
|
560
|
+
* const reader = moneymq.payment.listener('tx-123');
|
|
561
|
+
*
|
|
562
|
+
* for await (const message of reader.stream()) {
|
|
563
|
+
* if (message.type === 'event') {
|
|
564
|
+
* console.log('Event:', message.event.type, message.event.data);
|
|
565
|
+
* } else if (message.type === 'state') {
|
|
566
|
+
* console.log('State:', message.state);
|
|
567
|
+
* } else if (message.type === 'error') {
|
|
568
|
+
* console.error('Error:', message.error);
|
|
569
|
+
* }
|
|
570
|
+
* }
|
|
571
|
+
* ```
|
|
572
|
+
*/
|
|
573
|
+
stream<T = unknown>(options?: StreamOptions): AsyncGenerator<ChannelStreamMessage<T>>;
|
|
574
|
+
/**
|
|
575
|
+
* Stream events directly as an async iterable
|
|
576
|
+
*
|
|
577
|
+
* Simpler API that only yields events, ignoring state/error messages.
|
|
578
|
+
* Automatically connects and yields until disconnected or aborted.
|
|
579
|
+
*
|
|
580
|
+
* @example
|
|
581
|
+
* ```typescript
|
|
582
|
+
* const listener = moneymq.payment.listener('tx-123');
|
|
583
|
+
*
|
|
584
|
+
* for await (const event of listener.events()) {
|
|
585
|
+
* if (event.type === 'payment:settled') {
|
|
586
|
+
* console.log('Payment settled:', event.data.amount);
|
|
587
|
+
* }
|
|
588
|
+
* }
|
|
589
|
+
* ```
|
|
590
|
+
*/
|
|
591
|
+
events<T = unknown>(options?: {
|
|
592
|
+
signal?: AbortSignal;
|
|
593
|
+
}): AsyncGenerator<ChannelEvent<T>>;
|
|
483
594
|
protected abstract buildUrl(): string;
|
|
484
595
|
protected handleMessage(event: MessageEvent): void;
|
|
485
596
|
protected setState(state: ConnectionState): void;
|
|
@@ -555,7 +666,7 @@ declare class EventActor extends BaseChannel {
|
|
|
555
666
|
/**
|
|
556
667
|
* Transaction wrapper for receiver callbacks
|
|
557
668
|
*/
|
|
558
|
-
declare class TransactionContext implements
|
|
669
|
+
declare class TransactionContext implements TransactionWithActor {
|
|
559
670
|
id: string;
|
|
560
671
|
channelId: string;
|
|
561
672
|
basket: BasketItem$1[];
|
|
@@ -563,7 +674,12 @@ declare class TransactionContext implements Transaction {
|
|
|
563
674
|
metadata?: Record<string, unknown>;
|
|
564
675
|
private endpoint;
|
|
565
676
|
private secret;
|
|
677
|
+
private _actor;
|
|
566
678
|
constructor(data: Transaction, endpoint: string, secret: string);
|
|
679
|
+
/**
|
|
680
|
+
* Get or create the internal actor (lazy initialization)
|
|
681
|
+
*/
|
|
682
|
+
private getOrCreateActor;
|
|
567
683
|
/**
|
|
568
684
|
* Get the payment amount as string (from payment details)
|
|
569
685
|
*/
|
|
@@ -592,8 +708,39 @@ declare class TransactionContext implements Transaction {
|
|
|
592
708
|
* Create an actor scoped to this transaction's channel
|
|
593
709
|
*
|
|
594
710
|
* The actor is automatically connected.
|
|
711
|
+
* Note: If you use events() or send() methods, they share the same internal actor.
|
|
595
712
|
*/
|
|
596
713
|
actor(options?: Omit<ActorOptions, 'secret'>): EventActor;
|
|
714
|
+
/**
|
|
715
|
+
* Stream events for this transaction
|
|
716
|
+
*
|
|
717
|
+
* Creates an actor internally and yields events from the transaction's channel.
|
|
718
|
+
*
|
|
719
|
+
* @example
|
|
720
|
+
* ```typescript
|
|
721
|
+
* for await (const event of tx.events()) {
|
|
722
|
+
* if (event.type === 'payment:settled') {
|
|
723
|
+
* await tx.send('order:completed', { orderId: tx.id });
|
|
724
|
+
* break;
|
|
725
|
+
* }
|
|
726
|
+
* }
|
|
727
|
+
* ```
|
|
728
|
+
*/
|
|
729
|
+
events(options?: {
|
|
730
|
+
signal?: AbortSignal;
|
|
731
|
+
}): AsyncGenerator<ChannelEvent>;
|
|
732
|
+
/**
|
|
733
|
+
* Attach data to this transaction's channel
|
|
734
|
+
*
|
|
735
|
+
* Creates an actor internally if not already created.
|
|
736
|
+
* The server will create a signed receipt JWT and emit a transaction:completed event.
|
|
737
|
+
*
|
|
738
|
+
* @example
|
|
739
|
+
* ```typescript
|
|
740
|
+
* await tx.attach({ orderId: tx.id, trackingNumber: '...' });
|
|
741
|
+
* ```
|
|
742
|
+
*/
|
|
743
|
+
attach<T = unknown>(data: T): Promise<ChannelEvent<T>>;
|
|
597
744
|
}
|
|
598
745
|
/**
|
|
599
746
|
* Transaction handler callback
|
|
@@ -666,6 +813,57 @@ declare class EventReceiver {
|
|
|
666
813
|
* Disconnect from the transaction stream
|
|
667
814
|
*/
|
|
668
815
|
disconnect(): void;
|
|
816
|
+
/**
|
|
817
|
+
* Stream transactions as an async iterable
|
|
818
|
+
*
|
|
819
|
+
* Automatically connects and yields messages until disconnected or aborted.
|
|
820
|
+
*
|
|
821
|
+
* @example
|
|
822
|
+
* ```typescript
|
|
823
|
+
* const receiver = moneymq.payment.processor();
|
|
824
|
+
*
|
|
825
|
+
* for await (const message of receiver.stream()) {
|
|
826
|
+
* if (message.type === 'transaction') {
|
|
827
|
+
* const tx = message.transaction;
|
|
828
|
+
* console.log('New transaction:', tx.id);
|
|
829
|
+
*
|
|
830
|
+
* const actor = tx.actor();
|
|
831
|
+
* // Handle the transaction...
|
|
832
|
+
* } else if (message.type === 'state') {
|
|
833
|
+
* console.log('State:', message.state);
|
|
834
|
+
* } else if (message.type === 'error') {
|
|
835
|
+
* console.error('Error:', message.error);
|
|
836
|
+
* }
|
|
837
|
+
* }
|
|
838
|
+
* ```
|
|
839
|
+
*/
|
|
840
|
+
stream(options?: StreamOptions): AsyncGenerator<ReceiverStreamMessage>;
|
|
841
|
+
/**
|
|
842
|
+
* Stream transactions directly as an async iterable
|
|
843
|
+
*
|
|
844
|
+
* Simpler API that only yields transactions, ignoring state/error messages.
|
|
845
|
+
* Automatically connects and yields until disconnected or aborted.
|
|
846
|
+
*
|
|
847
|
+
* @example
|
|
848
|
+
* ```typescript
|
|
849
|
+
* const processor = moneymq.payment.processor();
|
|
850
|
+
*
|
|
851
|
+
* for await (const tx of processor.transactions()) {
|
|
852
|
+
* console.log('New transaction:', tx.id, tx.payment?.amount);
|
|
853
|
+
*
|
|
854
|
+
* const actor = tx.actor();
|
|
855
|
+
* for await (const event of actor.events()) {
|
|
856
|
+
* if (event.type === 'payment:settled') {
|
|
857
|
+
* await actor.send('order:completed', { orderId: tx.id });
|
|
858
|
+
* break;
|
|
859
|
+
* }
|
|
860
|
+
* }
|
|
861
|
+
* }
|
|
862
|
+
* ```
|
|
863
|
+
*/
|
|
864
|
+
transactions(options?: {
|
|
865
|
+
signal?: AbortSignal;
|
|
866
|
+
}): AsyncGenerator<TransactionWithActor>;
|
|
669
867
|
private setState;
|
|
670
868
|
private shouldReconnect;
|
|
671
869
|
private scheduleReconnect;
|
|
@@ -1887,4 +2085,4 @@ declare class CheckoutReceipt {
|
|
|
1887
2085
|
};
|
|
1888
2086
|
}
|
|
1889
2087
|
|
|
1890
|
-
export { type ActorOptions, type Attachments, type BasketItem, ChannelError, type ChannelErrorHandler, type ChannelEvent, type ChannelEventHandler, type CheckoutCreateParams, type CheckoutLineItem, CheckoutReceipt, type CheckoutSession, type CloudEventEnvelope, type ConnectionHandler, type ConnectionState, type Customer, type CustomerCreateParams, type CustomerUpdateParams, type ErrorHandler, EventActor, type EventHandler, EventReader, EventReceiver, EventStream, type EventStreamOptions, type EventStreamState, type ExperimentConfig, type GetSignerParams, MoneyMQ, type MoneyMQConfig, type MoneyMQEventMap, type MoneyMQEventType, type PayParams, type PayResult, type Payment, type PaymentDetails, type PaymentEvent, type PaymentFlow, type PaymentIntent, type PaymentIntentCreateParams, type PaymentLink, type PaymentLinkCreateParams, type PaymentListParams, PaymentRequiredError, type PaymentRequirements, type PaymentSettlementEvent, type PaymentSettlementFailedData, type PaymentSettlementSucceededData, type PaymentVerificationEvent, type PaymentVerificationFailedData, type PaymentVerificationSucceededData, type Payout, type PayoutCreateParams, type PayoutListParams, type PayoutSettings, type PayoutSettingsUpdateParams, type Price, type PriceCreateParams, type PriceRecurring, type ProcessorData, type Product, type ProductAccessParams, type ProductAccessResponse, type ProductCreateParams, type ProductFeature$1 as ProductFeature, type ProductListParams, type ProductPrice, type ReaderOptions, type ReceiptClaims, type ReceiverOptions, type ServerConfig, type StateHandler, type Transaction, type TransactionHandler, type X402ClientConfig, buildEventStreamUrl, computeChannelId, createEventActor, createEventReader, createEventReceiver, createEventStream, fetchConfig, getRpcUrl, isPaymentSettlementFailed, isPaymentSettlementSucceeded, isPaymentVerificationFailed, isPaymentVerificationSucceeded, parseCloudEvent };
|
|
2088
|
+
export { type ActorOptions, type Attachments, type BasketItem, ChannelError, type ChannelErrorHandler, type ChannelEvent, type ChannelEventHandler, type ChannelStreamMessage, type CheckoutCreateParams, type CheckoutLineItem, CheckoutReceipt, type CheckoutSession, type CloudEventEnvelope, type ConnectionHandler, type ConnectionState, type Customer, type CustomerCreateParams, type CustomerUpdateParams, type ErrorHandler, type ErrorStreamMessage, EventActor, type EventHandler, EventReader, EventReceiver, EventStream, type EventStreamMessage, type EventStreamOptions, type EventStreamState, type ExperimentConfig, type GetSignerParams, MoneyMQ, type MoneyMQConfig, type MoneyMQEventMap, type MoneyMQEventType, type PayParams, type PayResult, type Payment, type PaymentDetails, type PaymentEvent, type PaymentFlow, type PaymentIntent, type PaymentIntentCreateParams, type PaymentLink, type PaymentLinkCreateParams, type PaymentListParams, PaymentRequiredError, type PaymentRequirements, type PaymentSettlementEvent, type PaymentSettlementFailedData, type PaymentSettlementSucceededData, type PaymentVerificationEvent, type PaymentVerificationFailedData, type PaymentVerificationSucceededData, type Payout, type PayoutCreateParams, type PayoutListParams, type PayoutSettings, type PayoutSettingsUpdateParams, type Price, type PriceCreateParams, type PriceRecurring, type ProcessorData, type Product, type ProductAccessParams, type ProductAccessResponse, type ProductCreateParams, type ProductFeature$1 as ProductFeature, type ProductListParams, type ProductPrice, type ReaderOptions, type ReceiptClaims, type ReceiverOptions, type ReceiverStreamMessage, type ServerConfig, type StateHandler, type StateStreamMessage, type StreamOptions, type Transaction, type TransactionHandler, type TransactionStreamMessage, type TransactionWithActor, type X402ClientConfig, buildEventStreamUrl, computeChannelId, createEventActor, createEventReader, createEventReceiver, createEventStream, fetchConfig, getRpcUrl, isPaymentSettlementFailed, isPaymentSettlementSucceeded, isPaymentVerificationFailed, isPaymentVerificationSucceeded, parseCloudEvent };
|