@cosmosapp/pay_sdk 1.1.0 → 1.2.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.
- package/CHANGELOG.md +21 -10
- package/LICENSE +273 -18
- package/README.md +32 -7
- package/dist/{chunk-RCLT7E4Y.js → chunk-KZNJR223.js} +3 -3
- package/dist/{chunk-RCLT7E4Y.js.map → chunk-KZNJR223.js.map} +1 -1
- package/dist/index.cjs +161 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +114 -5
- package/dist/index.d.ts +114 -5
- package/dist/index.js +160 -3
- package/dist/index.js.map +1 -1
- package/dist/{intent-input-Caauq1Vl.d.cts → intent-input-Ch8ogEg-.d.cts} +125 -1
- package/dist/{intent-input-Caauq1Vl.d.ts → intent-input-Ch8ogEg-.d.ts} +125 -1
- package/dist/web/index.cjs +1 -1
- package/dist/web/index.cjs.map +1 -1
- package/dist/web/index.d.cts +2 -2
- package/dist/web/index.d.ts +2 -2
- package/dist/web/index.js +2 -2
- package/llms/00-overview.md +43 -0
- package/llms/01-installation.md +35 -0
- package/llms/02-authentication.md +48 -0
- package/llms/03-quickstart.md +57 -0
- package/llms/04-client.md +54 -0
- package/llms/05-payment-intents.md +83 -0
- package/llms/06-web-client.md +113 -0
- package/llms/07-webhooks.md +109 -0
- package/llms/08-products-customers.md +52 -0
- package/llms/09-analytics-health.md +25 -0
- package/llms/10-assets-wallets-addresses.md +57 -0
- package/llms/11-errors-observability.md +47 -0
- package/llms/12-configuration.md +43 -0
- package/llms/13-types-reference.md +78 -0
- package/llms/14-recipes.md +93 -0
- package/llms/README.md +40 -0
- package/llms/llms-full.txt +987 -0
- package/llms/llms.txt +45 -0
- package/package.json +15 -10
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EventEmitter } from 'node:events';
|
|
2
|
-
import { A as AnalyticsSummaryData, a as AnalyticsBalancesData, b as ApiLogsData, W as WebhookLogsData, C as CustomerData, U as UpdateCustomerOptions, c as CreateCustomerOptions, H as HealthCheckData, P as PaymentIntentData, d as PaymentIntentKind, e as PaymentIntentStatus, f as UpdatePaymentIntentOptions, D as DeletedData, V as ValidationOutcomeData, g as CreateTxPaymentIntentOptions, h as CreatePayPaymentIntentOptions, L as ListPaymentIntentsOptions, i as ValidatePaymentIntentOptions, j as ProductData, k as ProductKind, l as UpdateProductOptions, m as CreateProductOptions, n as
|
|
3
|
-
export {
|
|
2
|
+
import { A as AnalyticsSummaryData, a as AnalyticsBalancesData, b as ApiLogsData, W as WebhookLogsData, C as CustomerData, U as UpdateCustomerOptions, c as CreateCustomerOptions, H as HealthCheckData, P as PaymentIntentData, d as PaymentIntentKind, e as PaymentIntentStatus, f as UpdatePaymentIntentOptions, D as DeletedData, V as ValidationOutcomeData, g as CreateTxPaymentIntentOptions, h as CreatePayPaymentIntentOptions, L as ListPaymentIntentsOptions, i as ValidatePaymentIntentOptions, j as ProductData, k as ProductKind, l as UpdateProductOptions, m as CreateProductOptions, S as SwapData, n as SwapStatus, o as SubmitSwapOptions, Q as QuoteSwapOptions, p as SwapQuoteData, q as CreateSwapOptions, r as ListSwapsOptions, s as WebhookDeliveryData, t as WebhookEventType, u as WebhookDeliveryStatus, v as WebhookEndpointData, w as WebhookEndpointWithSecretData, x as UpdateWebhookEndpointOptions, y as WebhookPingData, z as ListWebhookDeliveriesOptions, B as WebhookEvent, E as CreateWebhookEndpointOptions } from './intent-input-Ch8ogEg-.cjs';
|
|
3
|
+
export { F as AddressBook, G as AddressRef, I as AnalyticsBalanceEntry, J as AnalyticsRecentRow, K as AnalyticsSeriesPoint, M as AnalyticsVolumeEntry, N as ApiLogRow, O as AssetDefinition, R as AssetRef, T as Assets, X as CosmosPayAPIError, Y as CosmosPayRequestError, Z as CustomerListData, _ as PaymentIntentListData, $ as ResolvableIntentInput, a0 as ResolvedAsset, a1 as SwapListData, a2 as SwapSubmitOutcomeData, a3 as TestnetAssets, a4 as WalletId, a5 as Wallets, a6 as WebhookDeliveryListData, a7 as WebhookLogRow, a8 as addresses, a9 as assertAddress, aa as defineAsset, ab as isAddress, ac as isContractAddress, ad as isMuxedAddress, ae as isNativeAsset, af as isStellarAddress, ag as resolveAddress, ah as resolveAsset, ai as resolveIntentBody } from './intent-input-Ch8ogEg-.cjs';
|
|
4
4
|
import { IncomingMessage, ServerResponse } from 'node:http';
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -383,6 +383,113 @@ declare class ProductManager extends BaseManager<Product> {
|
|
|
383
383
|
delete(id: string): Promise<ProductDeletedData>;
|
|
384
384
|
}
|
|
385
385
|
|
|
386
|
+
/**
|
|
387
|
+
* A Stellar path-payment swap.
|
|
388
|
+
*
|
|
389
|
+
* Wraps the raw API payload with typed accessors and atomic action methods so
|
|
390
|
+
* you can operate on it directly: `await swap.fetch()`,
|
|
391
|
+
* `await swap.submit({ signedXdr })`.
|
|
392
|
+
*/
|
|
393
|
+
declare class Swap extends Base<SwapData> {
|
|
394
|
+
status: SwapStatus;
|
|
395
|
+
network: string;
|
|
396
|
+
/** Account performing the swap. */
|
|
397
|
+
source: string;
|
|
398
|
+
/** Account that receives the swapped asset. */
|
|
399
|
+
destination: string;
|
|
400
|
+
/** Asset code being sent, or `native` for XLM. */
|
|
401
|
+
sendAsset: string;
|
|
402
|
+
sendAssetIssuer: string | null;
|
|
403
|
+
sendAmount: string;
|
|
404
|
+
feeAmount: string;
|
|
405
|
+
feeBps: number;
|
|
406
|
+
/** Amount swapped after the fee is deducted. */
|
|
407
|
+
swapAmount: string;
|
|
408
|
+
/** Asset code being received, or `native` for XLM. */
|
|
409
|
+
destAsset: string;
|
|
410
|
+
destAssetIssuer: string | null;
|
|
411
|
+
destEstimated: string;
|
|
412
|
+
destMin: string;
|
|
413
|
+
slippageBps: number;
|
|
414
|
+
path: {
|
|
415
|
+
code: string;
|
|
416
|
+
issuer: string | null;
|
|
417
|
+
}[];
|
|
418
|
+
memo: string | null;
|
|
419
|
+
/** Unsigned transaction envelope (base64 XDR). */
|
|
420
|
+
xdr: string;
|
|
421
|
+
/** SEP-7 deep link. */
|
|
422
|
+
uri: string;
|
|
423
|
+
txHash: string;
|
|
424
|
+
/** QR code of the SEP-7 URI (PNG data URL). */
|
|
425
|
+
qr: string;
|
|
426
|
+
createdAt: Date;
|
|
427
|
+
updatedAt: Date;
|
|
428
|
+
constructor(client: Client, data: SwapData);
|
|
429
|
+
protected _patch(data: SwapData): this;
|
|
430
|
+
/** Whether the swap has settled on-chain. */
|
|
431
|
+
get isSucceeded(): boolean;
|
|
432
|
+
/** Whether the swap is still awaiting submission. */
|
|
433
|
+
get isPending(): boolean;
|
|
434
|
+
/** Human-readable send asset label (`XLM` for native). */
|
|
435
|
+
get sendAssetLabel(): string;
|
|
436
|
+
/** Human-readable destination asset label (`XLM` for native). */
|
|
437
|
+
get destAssetLabel(): string;
|
|
438
|
+
/** Re-fetch this swap from the API, returning a fresh instance. */
|
|
439
|
+
fetch(): Promise<Swap>;
|
|
440
|
+
/**
|
|
441
|
+
* Relay the signed transaction for this swap. Mutates this instance from the
|
|
442
|
+
* refreshed swap in the outcome and returns the outcome.
|
|
443
|
+
*/
|
|
444
|
+
submit(options: SubmitSwapOptions): Promise<SwapSubmitOutcome>;
|
|
445
|
+
toJSON(): SwapData;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
/** A page of swaps plus its pagination metadata. */
|
|
449
|
+
interface SwapPage {
|
|
450
|
+
items: Swap[];
|
|
451
|
+
total: number;
|
|
452
|
+
take: number;
|
|
453
|
+
skip: number;
|
|
454
|
+
}
|
|
455
|
+
/** Submission outcome with the refreshed swap materialized. */
|
|
456
|
+
interface SwapSubmitOutcome {
|
|
457
|
+
submitted: boolean;
|
|
458
|
+
status: SwapStatus;
|
|
459
|
+
txHash: string | null;
|
|
460
|
+
reason: string | null;
|
|
461
|
+
resultCodes: string[] | null;
|
|
462
|
+
swap: Swap;
|
|
463
|
+
}
|
|
464
|
+
/**
|
|
465
|
+
* Manages Stellar swaps — `client.swaps`.
|
|
466
|
+
*
|
|
467
|
+
* @example
|
|
468
|
+
* const quote = await client.swaps.quote({
|
|
469
|
+
* amount: '100', destAssetCode: 'USDC',
|
|
470
|
+
* });
|
|
471
|
+
* const swap = await client.swaps.create({
|
|
472
|
+
* amount: '100', destAssetCode: 'USDC', source: 'G...',
|
|
473
|
+
* });
|
|
474
|
+
* console.log(swap.uri, swap.qr);
|
|
475
|
+
*/
|
|
476
|
+
declare class SwapManager extends BaseManager<Swap> {
|
|
477
|
+
private readonly route;
|
|
478
|
+
/** Price a swap without creating it. Returns a plain quote (not a {@link Swap}). */
|
|
479
|
+
quote(options: QuoteSwapOptions): Promise<SwapQuoteData>;
|
|
480
|
+
/** Create a swap (unsigned XDR + SEP-7 URI + QR). */
|
|
481
|
+
create(options: CreateSwapOptions): Promise<Swap>;
|
|
482
|
+
/** Get a single swap by id. */
|
|
483
|
+
fetch(id: string): Promise<Swap>;
|
|
484
|
+
/** List the consumer's swaps (paginated). */
|
|
485
|
+
list(options?: ListSwapsOptions): Promise<SwapPage>;
|
|
486
|
+
/**
|
|
487
|
+
* Relay a signed swap transaction to the network. Finalizes status
|
|
488
|
+
* server-side and returns the outcome with the refreshed swap materialized.
|
|
489
|
+
*/
|
|
490
|
+
submit(id: string, options: SubmitSwapOptions): Promise<SwapSubmitOutcome>;
|
|
491
|
+
}
|
|
492
|
+
|
|
386
493
|
/** A single attempt to deliver an event to a webhook endpoint (audit record). */
|
|
387
494
|
declare class WebhookDelivery extends Base<WebhookDeliveryData> {
|
|
388
495
|
endpointId: string;
|
|
@@ -707,7 +814,7 @@ interface Client {
|
|
|
707
814
|
*/
|
|
708
815
|
declare class Client extends EventEmitter {
|
|
709
816
|
/** Library version. */
|
|
710
|
-
static readonly version = "1.1
|
|
817
|
+
static readonly version = "1.2.1";
|
|
711
818
|
/**
|
|
712
819
|
* Process-wide shared defaults maintained by Cosmos Pay (gateway URL, version,
|
|
713
820
|
* internal secrets). Mutate once at startup to change them for every client
|
|
@@ -726,6 +833,8 @@ declare class Client extends EventEmitter {
|
|
|
726
833
|
readonly webhooks: WebhookManager;
|
|
727
834
|
/** Products / prices. */
|
|
728
835
|
readonly products: ProductManager;
|
|
836
|
+
/** Stellar swaps — quote/create/fetch/list/submit. */
|
|
837
|
+
readonly swaps: SwapManager;
|
|
729
838
|
/** Customers. */
|
|
730
839
|
readonly customers: CustomerManager;
|
|
731
840
|
/** Read-only analytics (summary, balances, logs). */
|
|
@@ -796,7 +905,7 @@ declare const Webhooks: {
|
|
|
796
905
|
};
|
|
797
906
|
|
|
798
907
|
/** Library version, kept in sync with package.json. */
|
|
799
|
-
declare const version = "1.1
|
|
908
|
+
declare const version = "1.2.1";
|
|
800
909
|
/**
|
|
801
910
|
* Default base URL of the Cosmos Pay gateway. Maintained by Cosmos Pay — users
|
|
802
911
|
* never need to set this; it's part of the {@link shared} configuration. Override
|
|
@@ -828,4 +937,4 @@ declare const Events: {
|
|
|
828
937
|
};
|
|
829
938
|
type ClientEvent = (typeof Events)[keyof typeof Events];
|
|
830
939
|
|
|
831
|
-
export { AnalyticsBalancesData, AnalyticsManager, AnalyticsSummaryData, ApiLogsData, Base, BaseManager, Client, type ClientEvent, type ClientEvents, type ClientOptions, CreateCustomerOptions, CreatePayPaymentIntentOptions, CreateProductOptions, CreateTxPaymentIntentOptions, CreateWebhookEndpointOptions, Customer, CustomerData, CustomerManager, DEFAULT_BASE_URL, DEFAULT_RETRIES, DEFAULT_TIMEOUT, DEFAULT_VERSION, DeletedData, Events, type FetchLike, HealthCheckData, HealthManager, ListPaymentIntentsOptions, ListWebhookDeliveriesOptions, PaymentIntent, PaymentIntentData, PaymentIntentKind, PaymentIntentManager, type PaymentIntentPage, PaymentIntentStatus, Product, ProductData, ProductKind, ProductManager, REST, type RESTOptions, type RequestOptions, SIGNATURE_HEADER, type SharedConfig, UpdateCustomerOptions, UpdatePaymentIntentOptions, UpdateProductOptions, UpdateWebhookEndpointOptions, ValidatePaymentIntentOptions, type ValidationOutcome, ValidationOutcomeData, type VerifyWebhookOptions, WebhookDelivery, WebhookDeliveryData, type WebhookDeliveryPage, WebhookDeliveryStatus, WebhookEndpoint, WebhookEndpointData, WebhookEndpointWithSecretData, WebhookEvent, WebhookEventType, type WebhookHandlerOptions, type WebhookListenerEvents, WebhookLogsData, WebhookManager, WebhookPingData, type WebhookProcessOptions, WebhookSignatureError, Webhooks, resolveShared, shared, version };
|
|
940
|
+
export { AnalyticsBalancesData, AnalyticsManager, AnalyticsSummaryData, ApiLogsData, Base, BaseManager, Client, type ClientEvent, type ClientEvents, type ClientOptions, CreateCustomerOptions, CreatePayPaymentIntentOptions, CreateProductOptions, CreateSwapOptions, CreateTxPaymentIntentOptions, CreateWebhookEndpointOptions, Customer, CustomerData, CustomerManager, DEFAULT_BASE_URL, DEFAULT_RETRIES, DEFAULT_TIMEOUT, DEFAULT_VERSION, DeletedData, Events, type FetchLike, HealthCheckData, HealthManager, ListPaymentIntentsOptions, ListSwapsOptions, ListWebhookDeliveriesOptions, PaymentIntent, PaymentIntentData, PaymentIntentKind, PaymentIntentManager, type PaymentIntentPage, PaymentIntentStatus, Product, ProductData, ProductKind, ProductManager, QuoteSwapOptions, REST, type RESTOptions, type RequestOptions, SIGNATURE_HEADER, type SharedConfig, SubmitSwapOptions, Swap, SwapData, SwapManager, type SwapPage, SwapQuoteData, SwapStatus, type SwapSubmitOutcome, UpdateCustomerOptions, UpdatePaymentIntentOptions, UpdateProductOptions, UpdateWebhookEndpointOptions, ValidatePaymentIntentOptions, type ValidationOutcome, ValidationOutcomeData, type VerifyWebhookOptions, WebhookDelivery, WebhookDeliveryData, type WebhookDeliveryPage, WebhookDeliveryStatus, WebhookEndpoint, WebhookEndpointData, WebhookEndpointWithSecretData, WebhookEvent, WebhookEventType, type WebhookHandlerOptions, type WebhookListenerEvents, WebhookLogsData, WebhookManager, WebhookPingData, type WebhookProcessOptions, WebhookSignatureError, Webhooks, resolveShared, shared, version };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EventEmitter } from 'node:events';
|
|
2
|
-
import { A as AnalyticsSummaryData, a as AnalyticsBalancesData, b as ApiLogsData, W as WebhookLogsData, C as CustomerData, U as UpdateCustomerOptions, c as CreateCustomerOptions, H as HealthCheckData, P as PaymentIntentData, d as PaymentIntentKind, e as PaymentIntentStatus, f as UpdatePaymentIntentOptions, D as DeletedData, V as ValidationOutcomeData, g as CreateTxPaymentIntentOptions, h as CreatePayPaymentIntentOptions, L as ListPaymentIntentsOptions, i as ValidatePaymentIntentOptions, j as ProductData, k as ProductKind, l as UpdateProductOptions, m as CreateProductOptions, n as
|
|
3
|
-
export {
|
|
2
|
+
import { A as AnalyticsSummaryData, a as AnalyticsBalancesData, b as ApiLogsData, W as WebhookLogsData, C as CustomerData, U as UpdateCustomerOptions, c as CreateCustomerOptions, H as HealthCheckData, P as PaymentIntentData, d as PaymentIntentKind, e as PaymentIntentStatus, f as UpdatePaymentIntentOptions, D as DeletedData, V as ValidationOutcomeData, g as CreateTxPaymentIntentOptions, h as CreatePayPaymentIntentOptions, L as ListPaymentIntentsOptions, i as ValidatePaymentIntentOptions, j as ProductData, k as ProductKind, l as UpdateProductOptions, m as CreateProductOptions, S as SwapData, n as SwapStatus, o as SubmitSwapOptions, Q as QuoteSwapOptions, p as SwapQuoteData, q as CreateSwapOptions, r as ListSwapsOptions, s as WebhookDeliveryData, t as WebhookEventType, u as WebhookDeliveryStatus, v as WebhookEndpointData, w as WebhookEndpointWithSecretData, x as UpdateWebhookEndpointOptions, y as WebhookPingData, z as ListWebhookDeliveriesOptions, B as WebhookEvent, E as CreateWebhookEndpointOptions } from './intent-input-Ch8ogEg-.js';
|
|
3
|
+
export { F as AddressBook, G as AddressRef, I as AnalyticsBalanceEntry, J as AnalyticsRecentRow, K as AnalyticsSeriesPoint, M as AnalyticsVolumeEntry, N as ApiLogRow, O as AssetDefinition, R as AssetRef, T as Assets, X as CosmosPayAPIError, Y as CosmosPayRequestError, Z as CustomerListData, _ as PaymentIntentListData, $ as ResolvableIntentInput, a0 as ResolvedAsset, a1 as SwapListData, a2 as SwapSubmitOutcomeData, a3 as TestnetAssets, a4 as WalletId, a5 as Wallets, a6 as WebhookDeliveryListData, a7 as WebhookLogRow, a8 as addresses, a9 as assertAddress, aa as defineAsset, ab as isAddress, ac as isContractAddress, ad as isMuxedAddress, ae as isNativeAsset, af as isStellarAddress, ag as resolveAddress, ah as resolveAsset, ai as resolveIntentBody } from './intent-input-Ch8ogEg-.js';
|
|
4
4
|
import { IncomingMessage, ServerResponse } from 'node:http';
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -383,6 +383,113 @@ declare class ProductManager extends BaseManager<Product> {
|
|
|
383
383
|
delete(id: string): Promise<ProductDeletedData>;
|
|
384
384
|
}
|
|
385
385
|
|
|
386
|
+
/**
|
|
387
|
+
* A Stellar path-payment swap.
|
|
388
|
+
*
|
|
389
|
+
* Wraps the raw API payload with typed accessors and atomic action methods so
|
|
390
|
+
* you can operate on it directly: `await swap.fetch()`,
|
|
391
|
+
* `await swap.submit({ signedXdr })`.
|
|
392
|
+
*/
|
|
393
|
+
declare class Swap extends Base<SwapData> {
|
|
394
|
+
status: SwapStatus;
|
|
395
|
+
network: string;
|
|
396
|
+
/** Account performing the swap. */
|
|
397
|
+
source: string;
|
|
398
|
+
/** Account that receives the swapped asset. */
|
|
399
|
+
destination: string;
|
|
400
|
+
/** Asset code being sent, or `native` for XLM. */
|
|
401
|
+
sendAsset: string;
|
|
402
|
+
sendAssetIssuer: string | null;
|
|
403
|
+
sendAmount: string;
|
|
404
|
+
feeAmount: string;
|
|
405
|
+
feeBps: number;
|
|
406
|
+
/** Amount swapped after the fee is deducted. */
|
|
407
|
+
swapAmount: string;
|
|
408
|
+
/** Asset code being received, or `native` for XLM. */
|
|
409
|
+
destAsset: string;
|
|
410
|
+
destAssetIssuer: string | null;
|
|
411
|
+
destEstimated: string;
|
|
412
|
+
destMin: string;
|
|
413
|
+
slippageBps: number;
|
|
414
|
+
path: {
|
|
415
|
+
code: string;
|
|
416
|
+
issuer: string | null;
|
|
417
|
+
}[];
|
|
418
|
+
memo: string | null;
|
|
419
|
+
/** Unsigned transaction envelope (base64 XDR). */
|
|
420
|
+
xdr: string;
|
|
421
|
+
/** SEP-7 deep link. */
|
|
422
|
+
uri: string;
|
|
423
|
+
txHash: string;
|
|
424
|
+
/** QR code of the SEP-7 URI (PNG data URL). */
|
|
425
|
+
qr: string;
|
|
426
|
+
createdAt: Date;
|
|
427
|
+
updatedAt: Date;
|
|
428
|
+
constructor(client: Client, data: SwapData);
|
|
429
|
+
protected _patch(data: SwapData): this;
|
|
430
|
+
/** Whether the swap has settled on-chain. */
|
|
431
|
+
get isSucceeded(): boolean;
|
|
432
|
+
/** Whether the swap is still awaiting submission. */
|
|
433
|
+
get isPending(): boolean;
|
|
434
|
+
/** Human-readable send asset label (`XLM` for native). */
|
|
435
|
+
get sendAssetLabel(): string;
|
|
436
|
+
/** Human-readable destination asset label (`XLM` for native). */
|
|
437
|
+
get destAssetLabel(): string;
|
|
438
|
+
/** Re-fetch this swap from the API, returning a fresh instance. */
|
|
439
|
+
fetch(): Promise<Swap>;
|
|
440
|
+
/**
|
|
441
|
+
* Relay the signed transaction for this swap. Mutates this instance from the
|
|
442
|
+
* refreshed swap in the outcome and returns the outcome.
|
|
443
|
+
*/
|
|
444
|
+
submit(options: SubmitSwapOptions): Promise<SwapSubmitOutcome>;
|
|
445
|
+
toJSON(): SwapData;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
/** A page of swaps plus its pagination metadata. */
|
|
449
|
+
interface SwapPage {
|
|
450
|
+
items: Swap[];
|
|
451
|
+
total: number;
|
|
452
|
+
take: number;
|
|
453
|
+
skip: number;
|
|
454
|
+
}
|
|
455
|
+
/** Submission outcome with the refreshed swap materialized. */
|
|
456
|
+
interface SwapSubmitOutcome {
|
|
457
|
+
submitted: boolean;
|
|
458
|
+
status: SwapStatus;
|
|
459
|
+
txHash: string | null;
|
|
460
|
+
reason: string | null;
|
|
461
|
+
resultCodes: string[] | null;
|
|
462
|
+
swap: Swap;
|
|
463
|
+
}
|
|
464
|
+
/**
|
|
465
|
+
* Manages Stellar swaps — `client.swaps`.
|
|
466
|
+
*
|
|
467
|
+
* @example
|
|
468
|
+
* const quote = await client.swaps.quote({
|
|
469
|
+
* amount: '100', destAssetCode: 'USDC',
|
|
470
|
+
* });
|
|
471
|
+
* const swap = await client.swaps.create({
|
|
472
|
+
* amount: '100', destAssetCode: 'USDC', source: 'G...',
|
|
473
|
+
* });
|
|
474
|
+
* console.log(swap.uri, swap.qr);
|
|
475
|
+
*/
|
|
476
|
+
declare class SwapManager extends BaseManager<Swap> {
|
|
477
|
+
private readonly route;
|
|
478
|
+
/** Price a swap without creating it. Returns a plain quote (not a {@link Swap}). */
|
|
479
|
+
quote(options: QuoteSwapOptions): Promise<SwapQuoteData>;
|
|
480
|
+
/** Create a swap (unsigned XDR + SEP-7 URI + QR). */
|
|
481
|
+
create(options: CreateSwapOptions): Promise<Swap>;
|
|
482
|
+
/** Get a single swap by id. */
|
|
483
|
+
fetch(id: string): Promise<Swap>;
|
|
484
|
+
/** List the consumer's swaps (paginated). */
|
|
485
|
+
list(options?: ListSwapsOptions): Promise<SwapPage>;
|
|
486
|
+
/**
|
|
487
|
+
* Relay a signed swap transaction to the network. Finalizes status
|
|
488
|
+
* server-side and returns the outcome with the refreshed swap materialized.
|
|
489
|
+
*/
|
|
490
|
+
submit(id: string, options: SubmitSwapOptions): Promise<SwapSubmitOutcome>;
|
|
491
|
+
}
|
|
492
|
+
|
|
386
493
|
/** A single attempt to deliver an event to a webhook endpoint (audit record). */
|
|
387
494
|
declare class WebhookDelivery extends Base<WebhookDeliveryData> {
|
|
388
495
|
endpointId: string;
|
|
@@ -707,7 +814,7 @@ interface Client {
|
|
|
707
814
|
*/
|
|
708
815
|
declare class Client extends EventEmitter {
|
|
709
816
|
/** Library version. */
|
|
710
|
-
static readonly version = "1.1
|
|
817
|
+
static readonly version = "1.2.1";
|
|
711
818
|
/**
|
|
712
819
|
* Process-wide shared defaults maintained by Cosmos Pay (gateway URL, version,
|
|
713
820
|
* internal secrets). Mutate once at startup to change them for every client
|
|
@@ -726,6 +833,8 @@ declare class Client extends EventEmitter {
|
|
|
726
833
|
readonly webhooks: WebhookManager;
|
|
727
834
|
/** Products / prices. */
|
|
728
835
|
readonly products: ProductManager;
|
|
836
|
+
/** Stellar swaps — quote/create/fetch/list/submit. */
|
|
837
|
+
readonly swaps: SwapManager;
|
|
729
838
|
/** Customers. */
|
|
730
839
|
readonly customers: CustomerManager;
|
|
731
840
|
/** Read-only analytics (summary, balances, logs). */
|
|
@@ -796,7 +905,7 @@ declare const Webhooks: {
|
|
|
796
905
|
};
|
|
797
906
|
|
|
798
907
|
/** Library version, kept in sync with package.json. */
|
|
799
|
-
declare const version = "1.1
|
|
908
|
+
declare const version = "1.2.1";
|
|
800
909
|
/**
|
|
801
910
|
* Default base URL of the Cosmos Pay gateway. Maintained by Cosmos Pay — users
|
|
802
911
|
* never need to set this; it's part of the {@link shared} configuration. Override
|
|
@@ -828,4 +937,4 @@ declare const Events: {
|
|
|
828
937
|
};
|
|
829
938
|
type ClientEvent = (typeof Events)[keyof typeof Events];
|
|
830
939
|
|
|
831
|
-
export { AnalyticsBalancesData, AnalyticsManager, AnalyticsSummaryData, ApiLogsData, Base, BaseManager, Client, type ClientEvent, type ClientEvents, type ClientOptions, CreateCustomerOptions, CreatePayPaymentIntentOptions, CreateProductOptions, CreateTxPaymentIntentOptions, CreateWebhookEndpointOptions, Customer, CustomerData, CustomerManager, DEFAULT_BASE_URL, DEFAULT_RETRIES, DEFAULT_TIMEOUT, DEFAULT_VERSION, DeletedData, Events, type FetchLike, HealthCheckData, HealthManager, ListPaymentIntentsOptions, ListWebhookDeliveriesOptions, PaymentIntent, PaymentIntentData, PaymentIntentKind, PaymentIntentManager, type PaymentIntentPage, PaymentIntentStatus, Product, ProductData, ProductKind, ProductManager, REST, type RESTOptions, type RequestOptions, SIGNATURE_HEADER, type SharedConfig, UpdateCustomerOptions, UpdatePaymentIntentOptions, UpdateProductOptions, UpdateWebhookEndpointOptions, ValidatePaymentIntentOptions, type ValidationOutcome, ValidationOutcomeData, type VerifyWebhookOptions, WebhookDelivery, WebhookDeliveryData, type WebhookDeliveryPage, WebhookDeliveryStatus, WebhookEndpoint, WebhookEndpointData, WebhookEndpointWithSecretData, WebhookEvent, WebhookEventType, type WebhookHandlerOptions, type WebhookListenerEvents, WebhookLogsData, WebhookManager, WebhookPingData, type WebhookProcessOptions, WebhookSignatureError, Webhooks, resolveShared, shared, version };
|
|
940
|
+
export { AnalyticsBalancesData, AnalyticsManager, AnalyticsSummaryData, ApiLogsData, Base, BaseManager, Client, type ClientEvent, type ClientEvents, type ClientOptions, CreateCustomerOptions, CreatePayPaymentIntentOptions, CreateProductOptions, CreateSwapOptions, CreateTxPaymentIntentOptions, CreateWebhookEndpointOptions, Customer, CustomerData, CustomerManager, DEFAULT_BASE_URL, DEFAULT_RETRIES, DEFAULT_TIMEOUT, DEFAULT_VERSION, DeletedData, Events, type FetchLike, HealthCheckData, HealthManager, ListPaymentIntentsOptions, ListSwapsOptions, ListWebhookDeliveriesOptions, PaymentIntent, PaymentIntentData, PaymentIntentKind, PaymentIntentManager, type PaymentIntentPage, PaymentIntentStatus, Product, ProductData, ProductKind, ProductManager, QuoteSwapOptions, REST, type RESTOptions, type RequestOptions, SIGNATURE_HEADER, type SharedConfig, SubmitSwapOptions, Swap, SwapData, SwapManager, type SwapPage, SwapQuoteData, SwapStatus, type SwapSubmitOutcome, UpdateCustomerOptions, UpdatePaymentIntentOptions, UpdateProductOptions, UpdateWebhookEndpointOptions, ValidatePaymentIntentOptions, type ValidationOutcome, ValidationOutcomeData, type VerifyWebhookOptions, WebhookDelivery, WebhookDeliveryData, type WebhookDeliveryPage, WebhookDeliveryStatus, WebhookEndpoint, WebhookEndpointData, WebhookEndpointWithSecretData, WebhookEvent, WebhookEventType, type WebhookHandlerOptions, type WebhookListenerEvents, WebhookLogsData, WebhookManager, WebhookPingData, type WebhookProcessOptions, WebhookSignatureError, Webhooks, resolveShared, shared, version };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { version, DEFAULT_VERSION, DEFAULT_BASE_URL, DEFAULT_TIMEOUT, DEFAULT_RETRIES, Events, CosmosPayAPIError, CosmosPayRequestError, resolveIntentBody, SIGNATURE_HEADER } from './chunk-
|
|
2
|
-
export { AddressBook, Assets, CosmosPayAPIError, CosmosPayRequestError, DEFAULT_BASE_URL, DEFAULT_RETRIES, DEFAULT_TIMEOUT, DEFAULT_VERSION, Events, SIGNATURE_HEADER, TestnetAssets, Wallets, addresses, assertAddress, defineAsset, isAddress, isContractAddress, isMuxedAddress, isNativeAsset, isStellarAddress, resolveAddress, resolveAsset, resolveIntentBody, version } from './chunk-
|
|
1
|
+
import { version, DEFAULT_VERSION, DEFAULT_BASE_URL, DEFAULT_TIMEOUT, DEFAULT_RETRIES, Events, CosmosPayAPIError, CosmosPayRequestError, resolveIntentBody, SIGNATURE_HEADER } from './chunk-KZNJR223.js';
|
|
2
|
+
export { AddressBook, Assets, CosmosPayAPIError, CosmosPayRequestError, DEFAULT_BASE_URL, DEFAULT_RETRIES, DEFAULT_TIMEOUT, DEFAULT_VERSION, Events, SIGNATURE_HEADER, TestnetAssets, Wallets, addresses, assertAddress, defineAsset, isAddress, isContractAddress, isMuxedAddress, isNativeAsset, isStellarAddress, resolveAddress, resolveAsset, resolveIntentBody, version } from './chunk-KZNJR223.js';
|
|
3
3
|
import { EventEmitter } from 'events';
|
|
4
4
|
import { createHmac, timingSafeEqual } from 'crypto';
|
|
5
5
|
|
|
@@ -216,6 +216,13 @@ var ProductKind = {
|
|
|
216
216
|
OneTime: "one_time",
|
|
217
217
|
Link: "link"
|
|
218
218
|
};
|
|
219
|
+
var SwapStatus = {
|
|
220
|
+
Pending: "PENDING",
|
|
221
|
+
Submitted: "SUBMITTED",
|
|
222
|
+
Succeeded: "SUCCEEDED",
|
|
223
|
+
Failed: "FAILED",
|
|
224
|
+
Expired: "EXPIRED"
|
|
225
|
+
};
|
|
219
226
|
|
|
220
227
|
// src/structures/PaymentIntent.ts
|
|
221
228
|
var PaymentIntent = class extends Base {
|
|
@@ -483,6 +490,155 @@ var ProductManager = class extends BaseManager {
|
|
|
483
490
|
}
|
|
484
491
|
};
|
|
485
492
|
|
|
493
|
+
// src/structures/Swap.ts
|
|
494
|
+
var Swap = class extends Base {
|
|
495
|
+
constructor(client, data) {
|
|
496
|
+
super(client, data);
|
|
497
|
+
}
|
|
498
|
+
_patch(data) {
|
|
499
|
+
super._patch(data);
|
|
500
|
+
this.status = data.status;
|
|
501
|
+
this.network = data.network;
|
|
502
|
+
this.source = data.source;
|
|
503
|
+
this.destination = data.destination;
|
|
504
|
+
this.sendAsset = data.sendAsset;
|
|
505
|
+
this.sendAssetIssuer = data.sendAssetIssuer;
|
|
506
|
+
this.sendAmount = data.sendAmount;
|
|
507
|
+
this.feeAmount = data.feeAmount;
|
|
508
|
+
this.feeBps = data.feeBps;
|
|
509
|
+
this.swapAmount = data.swapAmount;
|
|
510
|
+
this.destAsset = data.destAsset;
|
|
511
|
+
this.destAssetIssuer = data.destAssetIssuer;
|
|
512
|
+
this.destEstimated = data.destEstimated;
|
|
513
|
+
this.destMin = data.destMin;
|
|
514
|
+
this.slippageBps = data.slippageBps;
|
|
515
|
+
this.path = data.path;
|
|
516
|
+
this.memo = data.memo;
|
|
517
|
+
this.xdr = data.xdr;
|
|
518
|
+
this.uri = data.uri;
|
|
519
|
+
this.txHash = data.txHash;
|
|
520
|
+
this.qr = data.qr;
|
|
521
|
+
this.createdAt = new Date(data.createdAt);
|
|
522
|
+
this.updatedAt = new Date(data.updatedAt);
|
|
523
|
+
return this;
|
|
524
|
+
}
|
|
525
|
+
/** Whether the swap has settled on-chain. */
|
|
526
|
+
get isSucceeded() {
|
|
527
|
+
return this.status === SwapStatus.Succeeded;
|
|
528
|
+
}
|
|
529
|
+
/** Whether the swap is still awaiting submission. */
|
|
530
|
+
get isPending() {
|
|
531
|
+
return this.status === SwapStatus.Pending;
|
|
532
|
+
}
|
|
533
|
+
/** Human-readable send asset label (`XLM` for native). */
|
|
534
|
+
get sendAssetLabel() {
|
|
535
|
+
return !this.sendAsset || this.sendAsset === "native" ? "XLM" : this.sendAsset;
|
|
536
|
+
}
|
|
537
|
+
/** Human-readable destination asset label (`XLM` for native). */
|
|
538
|
+
get destAssetLabel() {
|
|
539
|
+
return !this.destAsset || this.destAsset === "native" ? "XLM" : this.destAsset;
|
|
540
|
+
}
|
|
541
|
+
/** Re-fetch this swap from the API, returning a fresh instance. */
|
|
542
|
+
fetch() {
|
|
543
|
+
return this.client.swaps.fetch(this.id);
|
|
544
|
+
}
|
|
545
|
+
/**
|
|
546
|
+
* Relay the signed transaction for this swap. Mutates this instance from the
|
|
547
|
+
* refreshed swap in the outcome and returns the outcome.
|
|
548
|
+
*/
|
|
549
|
+
async submit(options) {
|
|
550
|
+
const outcome = await this.client.swaps.submit(this.id, options);
|
|
551
|
+
this._patch(outcome.swap.toJSON());
|
|
552
|
+
return outcome;
|
|
553
|
+
}
|
|
554
|
+
toJSON() {
|
|
555
|
+
return {
|
|
556
|
+
id: this.id,
|
|
557
|
+
status: this.status,
|
|
558
|
+
network: this.network,
|
|
559
|
+
source: this.source,
|
|
560
|
+
destination: this.destination,
|
|
561
|
+
sendAsset: this.sendAsset,
|
|
562
|
+
sendAssetIssuer: this.sendAssetIssuer,
|
|
563
|
+
sendAmount: this.sendAmount,
|
|
564
|
+
feeAmount: this.feeAmount,
|
|
565
|
+
feeBps: this.feeBps,
|
|
566
|
+
swapAmount: this.swapAmount,
|
|
567
|
+
destAsset: this.destAsset,
|
|
568
|
+
destAssetIssuer: this.destAssetIssuer,
|
|
569
|
+
destEstimated: this.destEstimated,
|
|
570
|
+
destMin: this.destMin,
|
|
571
|
+
slippageBps: this.slippageBps,
|
|
572
|
+
path: this.path,
|
|
573
|
+
memo: this.memo,
|
|
574
|
+
xdr: this.xdr,
|
|
575
|
+
uri: this.uri,
|
|
576
|
+
txHash: this.txHash,
|
|
577
|
+
qr: this.qr,
|
|
578
|
+
createdAt: this.createdAt.toISOString(),
|
|
579
|
+
updatedAt: this.updatedAt.toISOString()
|
|
580
|
+
};
|
|
581
|
+
}
|
|
582
|
+
};
|
|
583
|
+
|
|
584
|
+
// src/managers/SwapManager.ts
|
|
585
|
+
var SwapManager = class extends BaseManager {
|
|
586
|
+
constructor() {
|
|
587
|
+
super(...arguments);
|
|
588
|
+
this.route = "/swaps";
|
|
589
|
+
}
|
|
590
|
+
/** Price a swap without creating it. Returns a plain quote (not a {@link Swap}). */
|
|
591
|
+
async quote(options) {
|
|
592
|
+
return this.rest.post(`${this.route}/quote`, {
|
|
593
|
+
body: options
|
|
594
|
+
});
|
|
595
|
+
}
|
|
596
|
+
/** Create a swap (unsigned XDR + SEP-7 URI + QR). */
|
|
597
|
+
async create(options) {
|
|
598
|
+
const data = await this.rest.post(this.route, { body: options });
|
|
599
|
+
return this._add(new Swap(this.client, data));
|
|
600
|
+
}
|
|
601
|
+
/** Get a single swap by id. */
|
|
602
|
+
async fetch(id) {
|
|
603
|
+
const data = await this.rest.get(`${this.route}/${id}`);
|
|
604
|
+
return this._add(new Swap(this.client, data));
|
|
605
|
+
}
|
|
606
|
+
/** List the consumer's swaps (paginated). */
|
|
607
|
+
async list(options = {}) {
|
|
608
|
+
const data = await this.rest.get(this.route, {
|
|
609
|
+
query: {
|
|
610
|
+
status: options.status,
|
|
611
|
+
take: options.take,
|
|
612
|
+
skip: options.skip
|
|
613
|
+
}
|
|
614
|
+
});
|
|
615
|
+
return {
|
|
616
|
+
items: data.data.map((d) => this._add(new Swap(this.client, d))),
|
|
617
|
+
total: data.total,
|
|
618
|
+
take: data.take,
|
|
619
|
+
skip: data.skip
|
|
620
|
+
};
|
|
621
|
+
}
|
|
622
|
+
/**
|
|
623
|
+
* Relay a signed swap transaction to the network. Finalizes status
|
|
624
|
+
* server-side and returns the outcome with the refreshed swap materialized.
|
|
625
|
+
*/
|
|
626
|
+
async submit(id, options) {
|
|
627
|
+
const data = await this.rest.post(
|
|
628
|
+
`${this.route}/${id}/submit`,
|
|
629
|
+
{ body: options }
|
|
630
|
+
);
|
|
631
|
+
return {
|
|
632
|
+
submitted: data.submitted,
|
|
633
|
+
status: data.status,
|
|
634
|
+
txHash: data.txHash ?? null,
|
|
635
|
+
reason: data.reason ?? null,
|
|
636
|
+
resultCodes: data.resultCodes ?? null,
|
|
637
|
+
swap: this._add(new Swap(this.client, data.swap))
|
|
638
|
+
};
|
|
639
|
+
}
|
|
640
|
+
};
|
|
641
|
+
|
|
486
642
|
// src/structures/WebhookDelivery.ts
|
|
487
643
|
var WebhookDelivery = class extends Base {
|
|
488
644
|
constructor(client, data) {
|
|
@@ -1083,6 +1239,7 @@ var Client = class extends EventEmitter {
|
|
|
1083
1239
|
this.paymentIntents = new PaymentIntentManager(this);
|
|
1084
1240
|
this.webhooks = new WebhookManager(this);
|
|
1085
1241
|
this.products = new ProductManager(this);
|
|
1242
|
+
this.swaps = new SwapManager(this);
|
|
1086
1243
|
this.customers = new CustomerManager(this);
|
|
1087
1244
|
this.analytics = new AnalyticsManager(this);
|
|
1088
1245
|
this.health = new HealthManager(this);
|
|
@@ -1104,6 +1261,6 @@ var Client = class extends EventEmitter {
|
|
|
1104
1261
|
}
|
|
1105
1262
|
};
|
|
1106
1263
|
|
|
1107
|
-
export { AnalyticsManager, Base, BaseManager, Client, Customer, CustomerManager, HealthManager, PaymentIntent, PaymentIntentKind, PaymentIntentManager, PaymentIntentStatus, Product, ProductKind, ProductManager, REST, WebhookDelivery, WebhookDeliveryStatus, WebhookEndpoint, WebhookEventType, WebhookManager, WebhookSignatureError, Webhooks, resolveShared, shared };
|
|
1264
|
+
export { AnalyticsManager, Base, BaseManager, Client, Customer, CustomerManager, HealthManager, PaymentIntent, PaymentIntentKind, PaymentIntentManager, PaymentIntentStatus, Product, ProductKind, ProductManager, REST, Swap, SwapManager, SwapStatus, WebhookDelivery, WebhookDeliveryStatus, WebhookEndpoint, WebhookEventType, WebhookManager, WebhookSignatureError, Webhooks, resolveShared, shared };
|
|
1108
1265
|
//# sourceMappingURL=index.js.map
|
|
1109
1266
|
//# sourceMappingURL=index.js.map
|