@lightsparkdev/lightspark-sdk 1.1.3 → 1.1.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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @lightsparkdev/lightspark-sdk
2
2
 
3
+ ## 1.1.4
4
+
5
+ ### Patch Changes
6
+
7
+ - 1372f3a: Move transaction polling into new client method
8
+ - Updated dependencies [24782f5]
9
+ - @lightsparkdev/core@1.0.7
10
+
3
11
  ## 1.1.3
4
12
 
5
13
  ### Patch Changes
@@ -1578,6 +1578,13 @@ declare class LightsparkClient {
1578
1578
  * @returns An `OutgoingPayment` object if the payment was successful, or undefined if the payment failed.
1579
1579
  */
1580
1580
  payUmaInvoice(payerNodeId: string, encodedInvoice: string, maximumFeesMsats: number, timeoutSecs?: number, amountMsats?: number | undefined): Promise<OutgoingPayment | undefined>;
1581
+ /**
1582
+ * Waits for a transaction to have a completed status, and returns the transaction.
1583
+ *
1584
+ * @param transactionId The ID of the transaction to wait for
1585
+ * @param pollTimeoutSecs The timeout in seconds that we will wait before throwing an exception
1586
+ */
1587
+ waitForTransactionComplete(transactionId: string, pollTimeoutSecs?: number): Promise<Transaction>;
1581
1588
  /**
1582
1589
  * Sends a payment directly to a node on the Lightning Network through the public key of the node without an invoice.
1583
1590
  *
package/dist/index.cjs CHANGED
@@ -1938,7 +1938,7 @@ var import_core9 = require("@lightsparkdev/core");
1938
1938
  // package.json
1939
1939
  var package_default = {
1940
1940
  name: "@lightsparkdev/lightspark-sdk",
1941
- version: "1.1.3",
1941
+ version: "1.1.4",
1942
1942
  description: "Lightspark JS SDK",
1943
1943
  author: "Lightspark Inc.",
1944
1944
  keywords: [
@@ -2026,7 +2026,7 @@ var package_default = {
2026
2026
  },
2027
2027
  license: "Apache-2.0",
2028
2028
  dependencies: {
2029
- "@lightsparkdev/core": "1.0.6",
2029
+ "@lightsparkdev/core": "1.0.7",
2030
2030
  "@lightsparkdev/crypto-wasm": "0.1.2",
2031
2031
  "auto-bind": "^5.0.1",
2032
2032
  crypto: "^1.0.1",
@@ -11041,6 +11041,43 @@ var LightsparkClient = class {
11041
11041
  }
11042
11042
  return response.pay_uma_invoice && OutgoingPaymentFromJson(response.pay_invoice.payment);
11043
11043
  }
11044
+ /**
11045
+ * Waits for a transaction to have a completed status, and returns the transaction.
11046
+ *
11047
+ * @param transactionId The ID of the transaction to wait for
11048
+ * @param pollTimeoutSecs The timeout in seconds that we will wait before throwing an exception
11049
+ */
11050
+ async waitForTransactionComplete(transactionId, pollTimeoutSecs = 60) {
11051
+ const pollIntervalMs = 250;
11052
+ const pollMaxTimeouts = pollTimeoutSecs * 1e3 / pollIntervalMs;
11053
+ const pollIgnoreErrors = false;
11054
+ const transaction = await (0, import_core9.pollUntil)(
11055
+ () => {
11056
+ return this.getTransaction(transactionId);
11057
+ },
11058
+ (current, response) => {
11059
+ if (current && [
11060
+ TransactionStatus_default.SUCCESS,
11061
+ TransactionStatus_default.CANCELLED,
11062
+ TransactionStatus_default.FAILED
11063
+ ].includes(current.status)) {
11064
+ return {
11065
+ stopPolling: true,
11066
+ value: current
11067
+ };
11068
+ }
11069
+ return response;
11070
+ },
11071
+ pollIntervalMs,
11072
+ pollMaxTimeouts,
11073
+ pollIgnoreErrors,
11074
+ () => new import_core9.LightsparkException(
11075
+ "Timeout",
11076
+ "Timeout waiting for transaction to complete."
11077
+ )
11078
+ );
11079
+ return transaction;
11080
+ }
11044
11081
  /**
11045
11082
  * Sends a payment directly to a node on the Lightning Network through the public key of the node without an invoice.
11046
11083
  *
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { AuthProvider } from '@lightsparkdev/core';
2
- import { W as WebhookEventType, L as LightsparkClient } from './index-827d336f.js';
3
- export { A as Account, a as AccountToApiTokensConnection, b as AccountToChannelsConnection, c as AccountToNodesConnection, d as AccountToPaymentRequestsConnection, e as AccountToTransactionsConnection, f as AccountToWalletsConnection, g as ApiToken, B as Balances, i as BlockchainBalance, C as Channel, j as ChannelClosingTransaction, l as ChannelFees, m as ChannelOpeningTransaction, o as ChannelStatus, p as ChannelToTransactionsConnection, q as ComplianceProvider, r as Connection, s as CreateApiTokenInput, t as CreateApiTokenOutput, u as CreateInvoiceInput, v as CreateInvoiceOutput, w as CreateLnurlInvoiceInput, x as CreateNodeWalletAddressInput, y as CreateNodeWalletAddressOutput, z as CreateTestModeInvoiceInput, D as CreateTestModeInvoiceOutput, E as CreateTestModePaymentInput, F as CreateTestModePaymentoutput, G as CreateUmaInvoiceInput, H as CurrencyAmount, I as CurrencyUnit, J as DeclineToSignMessagesInput, K as DeclineToSignMessagesOutput, M as DeleteApiTokenInput, N as DeleteApiTokenOutput, O as Deposit, Q as Entity, R as FeeEstimate, S as FundNodeInput, T as FundNodeOutput, U as GraphNode, V as Hop, Y as HtlcAttemptFailureCode, Z as IdAndSignature, _ as IncomingPayment, $ as IncomingPaymentAttempt, a1 as IncomingPaymentAttemptStatus, a2 as IncomingPaymentToAttemptsConnection, a3 as Invoice, a5 as InvoiceData, a6 as InvoiceType, a7 as LightningFeeEstimateForInvoiceInput, a8 as LightningFeeEstimateForNodeInput, a9 as LightningFeeEstimateOutput, aa as LightningTransaction, ac as LightsparkNode, ad as LightsparkNodeOwner, af as LightsparkNodeStatus, ag as LightsparkNodeToChannelsConnection, ah as LightsparkNodeWithOSK, ai as LightsparkNodeWithRemoteSigning, aj as Node, ak as NodeAddress, al as NodeAddressType, am as NodeToAddressesConnection, an as OnChainTransaction, ap as OutgoingPayment, aq as OutgoingPaymentAttempt, ar as OutgoingPaymentAttemptStatus, as as OutgoingPaymentAttemptToHopsConnection, av as OutgoingPaymentToAttemptsConnection, at as OutgoingPaymentsForInvoiceQueryInput, au as OutgoingPaymentsForInvoiceQueryOutput, aw as PageInfo, ax as PayInvoiceInput, ay as PayInvoiceOutput, aF as PayUmaInvoiceInput, az as PaymentDirection, aA as PaymentFailureReason, aB as PaymentRequest, aD as PaymentRequestData, aE as PaymentRequestStatus, aG as Permission, aH as PostTransactionData, aI as RegisterPaymentInput, aJ as RegisterPaymentOutput, aK as ReleaseChannelPerCommitmentSecretInput, aL as ReleaseChannelPerCommitmentSecretOutput, aM as ReleasePaymentPreimageInput, aN as ReleasePaymentPreimageOutput, aO as RemoteSigningSubEventType, aP as RequestWithdrawalInput, aQ as RequestWithdrawalOutput, aR as RichText, aS as RiskRating, aT as RoutingTransaction, aV as RoutingTransactionFailureReason, aW as ScreenNodeInput, aX as ScreenNodeOutput, aY as Secret, aZ as SendPaymentInput, a_ as SendPaymentOutput, a$ as SetInvoicePaymentHashInput, b0 as SetInvoicePaymentHashOutput, b6 as SignInvoiceInput, b7 as SignInvoiceOutput, b8 as SignMessagesInput, b9 as SignMessagesOutput, b1 as Signable, b3 as SignablePayload, b5 as SignablePayloadStatus, ba as SingleNodeDashboard, bb as Transaction, bd as TransactionFailures, be as TransactionStatus, bf as TransactionType, bg as TransactionUpdate, bh as UpdateChannelPerCommitmentPointInput, bi as UpdateChannelPerCommitmentPointOutput, bj as UpdateNodeSharedSecretInput, bk as UpdateNodeSharedSecretOutput, bl as Wallet, bm as WalletStatus, bn as WalletToPaymentRequestsConnection, bo as WalletToTransactionsConnection, bp as Withdrawal, br as WithdrawalMode, bs as WithdrawalRequest, bt as WithdrawalRequestStatus, bu as WithdrawalRequestToChannelClosingTransactionsConnection, bv as WithdrawalRequestToChannelOpeningTransactionsConnection, h as getApiTokenQuery, k as getChannelClosingTransactionQuery, n as getChannelOpeningTransactionQuery, P as getDepositQuery, X as getHopQuery, a0 as getIncomingPaymentAttemptQuery, a4 as getInvoiceQuery, ab as getLightningTransactionQuery, ae as getLightsparkNodeOwnerQuery, ao as getOnChainTransactionQuery, aC as getPaymentRequestQuery, aU as getRoutingTransactionQuery, b4 as getSignablePayloadQuery, b2 as getSignableQuery, bc as getTransactionQuery, bq as getWithdrawalQuery } from './index-827d336f.js';
2
+ import { W as WebhookEventType, L as LightsparkClient } from './index-2ac27fbd.js';
3
+ export { A as Account, a as AccountToApiTokensConnection, b as AccountToChannelsConnection, c as AccountToNodesConnection, d as AccountToPaymentRequestsConnection, e as AccountToTransactionsConnection, f as AccountToWalletsConnection, g as ApiToken, B as Balances, i as BlockchainBalance, C as Channel, j as ChannelClosingTransaction, l as ChannelFees, m as ChannelOpeningTransaction, o as ChannelStatus, p as ChannelToTransactionsConnection, q as ComplianceProvider, r as Connection, s as CreateApiTokenInput, t as CreateApiTokenOutput, u as CreateInvoiceInput, v as CreateInvoiceOutput, w as CreateLnurlInvoiceInput, x as CreateNodeWalletAddressInput, y as CreateNodeWalletAddressOutput, z as CreateTestModeInvoiceInput, D as CreateTestModeInvoiceOutput, E as CreateTestModePaymentInput, F as CreateTestModePaymentoutput, G as CreateUmaInvoiceInput, H as CurrencyAmount, I as CurrencyUnit, J as DeclineToSignMessagesInput, K as DeclineToSignMessagesOutput, M as DeleteApiTokenInput, N as DeleteApiTokenOutput, O as Deposit, Q as Entity, R as FeeEstimate, S as FundNodeInput, T as FundNodeOutput, U as GraphNode, V as Hop, Y as HtlcAttemptFailureCode, Z as IdAndSignature, _ as IncomingPayment, $ as IncomingPaymentAttempt, a1 as IncomingPaymentAttemptStatus, a2 as IncomingPaymentToAttemptsConnection, a3 as Invoice, a5 as InvoiceData, a6 as InvoiceType, a7 as LightningFeeEstimateForInvoiceInput, a8 as LightningFeeEstimateForNodeInput, a9 as LightningFeeEstimateOutput, aa as LightningTransaction, ac as LightsparkNode, ad as LightsparkNodeOwner, af as LightsparkNodeStatus, ag as LightsparkNodeToChannelsConnection, ah as LightsparkNodeWithOSK, ai as LightsparkNodeWithRemoteSigning, aj as Node, ak as NodeAddress, al as NodeAddressType, am as NodeToAddressesConnection, an as OnChainTransaction, ap as OutgoingPayment, aq as OutgoingPaymentAttempt, ar as OutgoingPaymentAttemptStatus, as as OutgoingPaymentAttemptToHopsConnection, av as OutgoingPaymentToAttemptsConnection, at as OutgoingPaymentsForInvoiceQueryInput, au as OutgoingPaymentsForInvoiceQueryOutput, aw as PageInfo, ax as PayInvoiceInput, ay as PayInvoiceOutput, aF as PayUmaInvoiceInput, az as PaymentDirection, aA as PaymentFailureReason, aB as PaymentRequest, aD as PaymentRequestData, aE as PaymentRequestStatus, aG as Permission, aH as PostTransactionData, aI as RegisterPaymentInput, aJ as RegisterPaymentOutput, aK as ReleaseChannelPerCommitmentSecretInput, aL as ReleaseChannelPerCommitmentSecretOutput, aM as ReleasePaymentPreimageInput, aN as ReleasePaymentPreimageOutput, aO as RemoteSigningSubEventType, aP as RequestWithdrawalInput, aQ as RequestWithdrawalOutput, aR as RichText, aS as RiskRating, aT as RoutingTransaction, aV as RoutingTransactionFailureReason, aW as ScreenNodeInput, aX as ScreenNodeOutput, aY as Secret, aZ as SendPaymentInput, a_ as SendPaymentOutput, a$ as SetInvoicePaymentHashInput, b0 as SetInvoicePaymentHashOutput, b6 as SignInvoiceInput, b7 as SignInvoiceOutput, b8 as SignMessagesInput, b9 as SignMessagesOutput, b1 as Signable, b3 as SignablePayload, b5 as SignablePayloadStatus, ba as SingleNodeDashboard, bb as Transaction, bd as TransactionFailures, be as TransactionStatus, bf as TransactionType, bg as TransactionUpdate, bh as UpdateChannelPerCommitmentPointInput, bi as UpdateChannelPerCommitmentPointOutput, bj as UpdateNodeSharedSecretInput, bk as UpdateNodeSharedSecretOutput, bl as Wallet, bm as WalletStatus, bn as WalletToPaymentRequestsConnection, bo as WalletToTransactionsConnection, bp as Withdrawal, br as WithdrawalMode, bs as WithdrawalRequest, bt as WithdrawalRequestStatus, bu as WithdrawalRequestToChannelClosingTransactionsConnection, bv as WithdrawalRequestToChannelOpeningTransactionsConnection, h as getApiTokenQuery, k as getChannelClosingTransactionQuery, n as getChannelOpeningTransactionQuery, P as getDepositQuery, X as getHopQuery, a0 as getIncomingPaymentAttemptQuery, a4 as getInvoiceQuery, ab as getLightningTransactionQuery, ae as getLightsparkNodeOwnerQuery, ao as getOnChainTransactionQuery, aC as getPaymentRequestQuery, aU as getRoutingTransactionQuery, b4 as getSignablePayloadQuery, b2 as getSignableQuery, bc as getTransactionQuery, bq as getWithdrawalQuery } from './index-2ac27fbd.js';
4
4
  import { B as BitcoinNetwork } from './BitcoinNetwork-a816c0be.js';
5
5
  import 'zen-observable';
6
6
 
package/dist/index.js CHANGED
@@ -125,6 +125,7 @@ import {
125
125
  LightsparkException,
126
126
  LightsparkSigningException as LightsparkSigningException3,
127
127
  NodeKeyCache,
128
+ pollUntil,
128
129
  Requester,
129
130
  SigningKeyType as SigningKeyType2,
130
131
  StubAuthProvider
@@ -133,7 +134,7 @@ import {
133
134
  // package.json
134
135
  var package_default = {
135
136
  name: "@lightsparkdev/lightspark-sdk",
136
- version: "1.1.3",
137
+ version: "1.1.4",
137
138
  description: "Lightspark JS SDK",
138
139
  author: "Lightspark Inc.",
139
140
  keywords: [
@@ -221,7 +222,7 @@ var package_default = {
221
222
  },
222
223
  license: "Apache-2.0",
223
224
  dependencies: {
224
- "@lightsparkdev/core": "1.0.6",
225
+ "@lightsparkdev/core": "1.0.7",
225
226
  "@lightsparkdev/crypto-wasm": "0.1.2",
226
227
  "auto-bind": "^5.0.1",
227
228
  crypto: "^1.0.1",
@@ -1595,6 +1596,43 @@ var LightsparkClient = class {
1595
1596
  }
1596
1597
  return response.pay_uma_invoice && OutgoingPaymentFromJson(response.pay_invoice.payment);
1597
1598
  }
1599
+ /**
1600
+ * Waits for a transaction to have a completed status, and returns the transaction.
1601
+ *
1602
+ * @param transactionId The ID of the transaction to wait for
1603
+ * @param pollTimeoutSecs The timeout in seconds that we will wait before throwing an exception
1604
+ */
1605
+ async waitForTransactionComplete(transactionId, pollTimeoutSecs = 60) {
1606
+ const pollIntervalMs = 250;
1607
+ const pollMaxTimeouts = pollTimeoutSecs * 1e3 / pollIntervalMs;
1608
+ const pollIgnoreErrors = false;
1609
+ const transaction = await pollUntil(
1610
+ () => {
1611
+ return this.getTransaction(transactionId);
1612
+ },
1613
+ (current, response) => {
1614
+ if (current && [
1615
+ TransactionStatus_default.SUCCESS,
1616
+ TransactionStatus_default.CANCELLED,
1617
+ TransactionStatus_default.FAILED
1618
+ ].includes(current.status)) {
1619
+ return {
1620
+ stopPolling: true,
1621
+ value: current
1622
+ };
1623
+ }
1624
+ return response;
1625
+ },
1626
+ pollIntervalMs,
1627
+ pollMaxTimeouts,
1628
+ pollIgnoreErrors,
1629
+ () => new LightsparkException(
1630
+ "Timeout",
1631
+ "Timeout waiting for transaction to complete."
1632
+ )
1633
+ );
1634
+ return transaction;
1635
+ }
1598
1636
  /**
1599
1637
  * Sends a payment directly to a node on the Lightning Network through the public key of the node without an invoice.
1600
1638
  *
@@ -1,4 +1,4 @@
1
- export { A as Account, a as AccountToApiTokensConnection, b as AccountToChannelsConnection, c as AccountToNodesConnection, d as AccountToPaymentRequestsConnection, e as AccountToTransactionsConnection, f as AccountToWalletsConnection, g as ApiToken, B as Balances, i as BlockchainBalance, C as Channel, j as ChannelClosingTransaction, l as ChannelFees, m as ChannelOpeningTransaction, o as ChannelStatus, p as ChannelToTransactionsConnection, q as ComplianceProvider, r as Connection, s as CreateApiTokenInput, t as CreateApiTokenOutput, u as CreateInvoiceInput, v as CreateInvoiceOutput, w as CreateLnurlInvoiceInput, x as CreateNodeWalletAddressInput, y as CreateNodeWalletAddressOutput, z as CreateTestModeInvoiceInput, D as CreateTestModeInvoiceOutput, E as CreateTestModePaymentInput, F as CreateTestModePaymentoutput, G as CreateUmaInvoiceInput, H as CurrencyAmount, I as CurrencyUnit, J as DeclineToSignMessagesInput, K as DeclineToSignMessagesOutput, M as DeleteApiTokenInput, N as DeleteApiTokenOutput, O as Deposit, Q as Entity, R as FeeEstimate, S as FundNodeInput, T as FundNodeOutput, U as GraphNode, V as Hop, Y as HtlcAttemptFailureCode, Z as IdAndSignature, _ as IncomingPayment, $ as IncomingPaymentAttempt, a1 as IncomingPaymentAttemptStatus, a2 as IncomingPaymentToAttemptsConnection, a3 as Invoice, a5 as InvoiceData, a6 as InvoiceType, a7 as LightningFeeEstimateForInvoiceInput, a8 as LightningFeeEstimateForNodeInput, a9 as LightningFeeEstimateOutput, aa as LightningTransaction, ac as LightsparkNode, ad as LightsparkNodeOwner, af as LightsparkNodeStatus, ag as LightsparkNodeToChannelsConnection, ah as LightsparkNodeWithOSK, ai as LightsparkNodeWithRemoteSigning, aj as Node, ak as NodeAddress, al as NodeAddressType, am as NodeToAddressesConnection, an as OnChainTransaction, ap as OutgoingPayment, aq as OutgoingPaymentAttempt, ar as OutgoingPaymentAttemptStatus, as as OutgoingPaymentAttemptToHopsConnection, av as OutgoingPaymentToAttemptsConnection, at as OutgoingPaymentsForInvoiceQueryInput, au as OutgoingPaymentsForInvoiceQueryOutput, aw as PageInfo, ax as PayInvoiceInput, ay as PayInvoiceOutput, aF as PayUmaInvoiceInput, az as PaymentDirection, aA as PaymentFailureReason, aB as PaymentRequest, aD as PaymentRequestData, aE as PaymentRequestStatus, aG as Permission, aH as PostTransactionData, aI as RegisterPaymentInput, aJ as RegisterPaymentOutput, aK as ReleaseChannelPerCommitmentSecretInput, aL as ReleaseChannelPerCommitmentSecretOutput, aM as ReleasePaymentPreimageInput, aN as ReleasePaymentPreimageOutput, aO as RemoteSigningSubEventType, aP as RequestWithdrawalInput, aQ as RequestWithdrawalOutput, aR as RichText, aS as RiskRating, aT as RoutingTransaction, aV as RoutingTransactionFailureReason, aW as ScreenNodeInput, aX as ScreenNodeOutput, aY as Secret, aZ as SendPaymentInput, a_ as SendPaymentOutput, a$ as SetInvoicePaymentHashInput, b0 as SetInvoicePaymentHashOutput, b6 as SignInvoiceInput, b7 as SignInvoiceOutput, b8 as SignMessagesInput, b9 as SignMessagesOutput, b1 as Signable, b3 as SignablePayload, b5 as SignablePayloadStatus, ba as SingleNodeDashboard, bb as Transaction, bd as TransactionFailures, be as TransactionStatus, bf as TransactionType, bg as TransactionUpdate, bh as UpdateChannelPerCommitmentPointInput, bi as UpdateChannelPerCommitmentPointOutput, bj as UpdateNodeSharedSecretInput, bk as UpdateNodeSharedSecretOutput, bl as Wallet, bm as WalletStatus, bn as WalletToPaymentRequestsConnection, bo as WalletToTransactionsConnection, W as WebhookEventType, bp as Withdrawal, br as WithdrawalMode, bs as WithdrawalRequest, bt as WithdrawalRequestStatus, bu as WithdrawalRequestToChannelClosingTransactionsConnection, bv as WithdrawalRequestToChannelOpeningTransactionsConnection, h as getApiTokenQuery, k as getChannelClosingTransactionQuery, n as getChannelOpeningTransactionQuery, P as getDepositQuery, X as getHopQuery, a0 as getIncomingPaymentAttemptQuery, a4 as getInvoiceQuery, ab as getLightningTransactionQuery, ae as getLightsparkNodeOwnerQuery, ao as getOnChainTransactionQuery, aC as getPaymentRequestQuery, aU as getRoutingTransactionQuery, b4 as getSignablePayloadQuery, b2 as getSignableQuery, bc as getTransactionQuery, bq as getWithdrawalQuery } from '../index-827d336f.js';
1
+ export { A as Account, a as AccountToApiTokensConnection, b as AccountToChannelsConnection, c as AccountToNodesConnection, d as AccountToPaymentRequestsConnection, e as AccountToTransactionsConnection, f as AccountToWalletsConnection, g as ApiToken, B as Balances, i as BlockchainBalance, C as Channel, j as ChannelClosingTransaction, l as ChannelFees, m as ChannelOpeningTransaction, o as ChannelStatus, p as ChannelToTransactionsConnection, q as ComplianceProvider, r as Connection, s as CreateApiTokenInput, t as CreateApiTokenOutput, u as CreateInvoiceInput, v as CreateInvoiceOutput, w as CreateLnurlInvoiceInput, x as CreateNodeWalletAddressInput, y as CreateNodeWalletAddressOutput, z as CreateTestModeInvoiceInput, D as CreateTestModeInvoiceOutput, E as CreateTestModePaymentInput, F as CreateTestModePaymentoutput, G as CreateUmaInvoiceInput, H as CurrencyAmount, I as CurrencyUnit, J as DeclineToSignMessagesInput, K as DeclineToSignMessagesOutput, M as DeleteApiTokenInput, N as DeleteApiTokenOutput, O as Deposit, Q as Entity, R as FeeEstimate, S as FundNodeInput, T as FundNodeOutput, U as GraphNode, V as Hop, Y as HtlcAttemptFailureCode, Z as IdAndSignature, _ as IncomingPayment, $ as IncomingPaymentAttempt, a1 as IncomingPaymentAttemptStatus, a2 as IncomingPaymentToAttemptsConnection, a3 as Invoice, a5 as InvoiceData, a6 as InvoiceType, a7 as LightningFeeEstimateForInvoiceInput, a8 as LightningFeeEstimateForNodeInput, a9 as LightningFeeEstimateOutput, aa as LightningTransaction, ac as LightsparkNode, ad as LightsparkNodeOwner, af as LightsparkNodeStatus, ag as LightsparkNodeToChannelsConnection, ah as LightsparkNodeWithOSK, ai as LightsparkNodeWithRemoteSigning, aj as Node, ak as NodeAddress, al as NodeAddressType, am as NodeToAddressesConnection, an as OnChainTransaction, ap as OutgoingPayment, aq as OutgoingPaymentAttempt, ar as OutgoingPaymentAttemptStatus, as as OutgoingPaymentAttemptToHopsConnection, av as OutgoingPaymentToAttemptsConnection, at as OutgoingPaymentsForInvoiceQueryInput, au as OutgoingPaymentsForInvoiceQueryOutput, aw as PageInfo, ax as PayInvoiceInput, ay as PayInvoiceOutput, aF as PayUmaInvoiceInput, az as PaymentDirection, aA as PaymentFailureReason, aB as PaymentRequest, aD as PaymentRequestData, aE as PaymentRequestStatus, aG as Permission, aH as PostTransactionData, aI as RegisterPaymentInput, aJ as RegisterPaymentOutput, aK as ReleaseChannelPerCommitmentSecretInput, aL as ReleaseChannelPerCommitmentSecretOutput, aM as ReleasePaymentPreimageInput, aN as ReleasePaymentPreimageOutput, aO as RemoteSigningSubEventType, aP as RequestWithdrawalInput, aQ as RequestWithdrawalOutput, aR as RichText, aS as RiskRating, aT as RoutingTransaction, aV as RoutingTransactionFailureReason, aW as ScreenNodeInput, aX as ScreenNodeOutput, aY as Secret, aZ as SendPaymentInput, a_ as SendPaymentOutput, a$ as SetInvoicePaymentHashInput, b0 as SetInvoicePaymentHashOutput, b6 as SignInvoiceInput, b7 as SignInvoiceOutput, b8 as SignMessagesInput, b9 as SignMessagesOutput, b1 as Signable, b3 as SignablePayload, b5 as SignablePayloadStatus, ba as SingleNodeDashboard, bb as Transaction, bd as TransactionFailures, be as TransactionStatus, bf as TransactionType, bg as TransactionUpdate, bh as UpdateChannelPerCommitmentPointInput, bi as UpdateChannelPerCommitmentPointOutput, bj as UpdateNodeSharedSecretInput, bk as UpdateNodeSharedSecretOutput, bl as Wallet, bm as WalletStatus, bn as WalletToPaymentRequestsConnection, bo as WalletToTransactionsConnection, W as WebhookEventType, bp as Withdrawal, br as WithdrawalMode, bs as WithdrawalRequest, bt as WithdrawalRequestStatus, bu as WithdrawalRequestToChannelClosingTransactionsConnection, bv as WithdrawalRequestToChannelOpeningTransactionsConnection, h as getApiTokenQuery, k as getChannelClosingTransactionQuery, n as getChannelOpeningTransactionQuery, P as getDepositQuery, X as getHopQuery, a0 as getIncomingPaymentAttemptQuery, a4 as getInvoiceQuery, ab as getLightningTransactionQuery, ae as getLightsparkNodeOwnerQuery, ao as getOnChainTransactionQuery, aC as getPaymentRequestQuery, aU as getRoutingTransactionQuery, b4 as getSignablePayloadQuery, b2 as getSignableQuery, bc as getTransactionQuery, bq as getWithdrawalQuery } from '../index-2ac27fbd.js';
2
2
  export { B as BitcoinNetwork } from '../BitcoinNetwork-a816c0be.js';
3
3
  import '@lightsparkdev/core';
4
4
  import 'zen-observable';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightsparkdev/lightspark-sdk",
3
- "version": "1.1.3",
3
+ "version": "1.1.4",
4
4
  "description": "Lightspark JS SDK",
5
5
  "author": "Lightspark Inc.",
6
6
  "keywords": [
@@ -88,7 +88,7 @@
88
88
  },
89
89
  "license": "Apache-2.0",
90
90
  "dependencies": {
91
- "@lightsparkdev/core": "1.0.6",
91
+ "@lightsparkdev/core": "1.0.7",
92
92
  "@lightsparkdev/crypto-wasm": "0.1.2",
93
93
  "auto-bind": "^5.0.1",
94
94
  "crypto": "^1.0.1",
package/src/client.ts CHANGED
@@ -18,6 +18,7 @@ import {
18
18
  LightsparkException,
19
19
  LightsparkSigningException,
20
20
  NodeKeyCache,
21
+ pollUntil,
21
22
  Requester,
22
23
  SigningKeyType,
23
24
  StubAuthProvider,
@@ -46,6 +47,7 @@ import { SendPayment } from "./graphql/SendPayment.js";
46
47
  import { SingleNodeDashboard as SingleNodeDashboardQuery } from "./graphql/SingleNodeDashboard.js";
47
48
  import { TransactionsForNode } from "./graphql/TransactionsForNode.js";
48
49
  import { TransactionSubscription } from "./graphql/TransactionSubscription.js";
50
+ import { TransactionStatus } from "./index.js";
49
51
  import NodeKeyLoaderCache from "./NodeKeyLoaderCache.js";
50
52
  import Account from "./objects/Account.js";
51
53
  import { ApiTokenFromJson } from "./objects/ApiToken.js";
@@ -789,6 +791,53 @@ class LightsparkClient {
789
791
  );
790
792
  }
791
793
 
794
+ /**
795
+ * Waits for a transaction to have a completed status, and returns the transaction.
796
+ *
797
+ * @param transactionId The ID of the transaction to wait for
798
+ * @param pollTimeoutSecs The timeout in seconds that we will wait before throwing an exception
799
+ */
800
+ public async waitForTransactionComplete(
801
+ transactionId: string,
802
+ pollTimeoutSecs = 60,
803
+ ) {
804
+ const pollIntervalMs = 250;
805
+ const pollMaxTimeouts = (pollTimeoutSecs * 1000) / pollIntervalMs;
806
+ const pollIgnoreErrors = false;
807
+
808
+ const transaction = (await pollUntil(
809
+ () => {
810
+ return this.getTransaction(transactionId);
811
+ },
812
+ (current, response) => {
813
+ if (
814
+ current &&
815
+ [
816
+ TransactionStatus.SUCCESS,
817
+ TransactionStatus.CANCELLED,
818
+ TransactionStatus.FAILED,
819
+ ].includes(current.status)
820
+ ) {
821
+ return {
822
+ stopPolling: true,
823
+ value: current,
824
+ };
825
+ }
826
+ return response;
827
+ },
828
+ pollIntervalMs,
829
+ pollMaxTimeouts,
830
+ pollIgnoreErrors,
831
+ () =>
832
+ new LightsparkException(
833
+ "Timeout",
834
+ "Timeout waiting for transaction to complete.",
835
+ ),
836
+ )) as Transaction;
837
+
838
+ return transaction;
839
+ }
840
+
792
841
  /**
793
842
  * Sends a payment directly to a node on the Lightning Network through the public key of the node without an invoice.
794
843
  *
@@ -6,7 +6,6 @@ import {
6
6
  BitcoinNetwork,
7
7
  PaymentRequestStatus,
8
8
  TransactionStatus,
9
- type Transaction,
10
9
  } from "../../index.js";
11
10
  import { logger } from "../../logger.js";
12
11
 
@@ -155,27 +154,14 @@ describe("lightspark-sdk client", () => {
155
154
  const payment = await lightsparkClient.payInvoice(nodeId, invoice, 60);
156
155
  log("payment.id", payment?.id);
157
156
 
158
- const transaction = (await pollUntil(
159
- () => {
160
- if (!payment) {
161
- throw new Error("No payment");
162
- }
163
- return lightsparkClient.getTransaction(payment.id);
164
- },
165
- (current, response) => {
166
- if (current && current.status === TransactionStatus.SUCCESS) {
167
- return {
168
- stopPolling: true,
169
- value: current,
170
- };
171
- }
172
- return response;
173
- },
174
- pollIntervalMs,
175
- pollMaxTimeouts,
176
- pollIgnoreErrors,
177
- () => new Error("Timeout waiting for payment to be received"),
178
- )) as Transaction;
157
+ if (!payment) {
158
+ throw new Error("No payment");
159
+ }
160
+
161
+ const transaction = await lightsparkClient.waitForTransactionComplete(
162
+ payment.id,
163
+ pollTimeoutSecs,
164
+ );
179
165
 
180
166
  expect(transaction.status).toEqual(TransactionStatus.SUCCESS);
181
167
  }, 30_000);