@lightsparkdev/lightspark-sdk 1.1.7 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/{chunk-7UT6YX37.js → chunk-VTPDR6P4.js} +393 -275
  3. package/dist/{index-d31f4469.d.ts → index-f040db9f.d.ts} +678 -386
  4. package/dist/index.cjs +396 -278
  5. package/dist/index.d.ts +2 -2
  6. package/dist/index.js +7 -7
  7. package/dist/objects/index.cjs +395 -277
  8. package/dist/objects/index.d.ts +1 -1
  9. package/dist/objects/index.js +5 -5
  10. package/package.json +2 -2
  11. package/src/objects/Account.ts +13 -2
  12. package/src/objects/AccountToApiTokensConnection.ts +16 -5
  13. package/src/objects/AccountToChannelsConnection.ts +9 -0
  14. package/src/objects/AccountToNodesConnection.ts +19 -5
  15. package/src/objects/AccountToPaymentRequestsConnection.ts +21 -5
  16. package/src/objects/AccountToTransactionsConnection.ts +33 -9
  17. package/src/objects/AccountToWalletsConnection.ts +13 -4
  18. package/src/objects/ApiToken.ts +13 -3
  19. package/src/objects/Balances.ts +17 -3
  20. package/src/objects/BlockchainBalance.ts +34 -9
  21. package/src/objects/Channel.ts +61 -16
  22. package/src/objects/ChannelClosingTransaction.ts +81 -61
  23. package/src/objects/ChannelFees.ts +16 -5
  24. package/src/objects/ChannelOpeningTransaction.ts +81 -61
  25. package/src/objects/ChannelSnapshot.ts +32 -8
  26. package/src/objects/ChannelToTransactionsConnection.ts +26 -6
  27. package/src/objects/Connection.ts +205 -10
  28. package/src/objects/CreateApiTokenInput.ts +8 -2
  29. package/src/objects/CreateApiTokenOutput.ts +9 -3
  30. package/src/objects/CreateInvoiceInput.ts +14 -5
  31. package/src/objects/CreateInvoiceOutput.ts +7 -2
  32. package/src/objects/CreateLnurlInvoiceInput.ts +13 -3
  33. package/src/objects/CreateNodeWalletAddressInput.ts +9 -2
  34. package/src/objects/CreateNodeWalletAddressOutput.ts +10 -2
  35. package/src/objects/CreateTestModeInvoiceInput.ts +14 -4
  36. package/src/objects/CreateTestModeInvoiceOutput.ts +10 -2
  37. package/src/objects/CreateTestModePaymentInput.ts +12 -3
  38. package/src/objects/CreateTestModePaymentoutput.ts +12 -2
  39. package/src/objects/CreateUmaInvoiceInput.ts +13 -3
  40. package/src/objects/CurrencyAmount.ts +13 -2
  41. package/src/objects/DeclineToSignMessagesInput.ts +9 -2
  42. package/src/objects/DeclineToSignMessagesOutput.ts +15 -3
  43. package/src/objects/DeleteApiTokenInput.ts +7 -2
  44. package/src/objects/DeleteApiTokenOutput.ts +7 -2
  45. package/src/objects/Deposit.ts +77 -61
  46. package/src/objects/Entity.ts +2 -2
  47. package/src/objects/FeeEstimate.ts +12 -3
  48. package/src/objects/FundNodeInput.ts +9 -3
  49. package/src/objects/FundNodeOutput.ts +11 -3
  50. package/src/objects/GraphNode.ts +21 -5
  51. package/src/objects/Hop.ts +27 -9
  52. package/src/objects/IdAndSignature.ts +8 -2
  53. package/src/objects/IncomingPayment.ts +33 -7
  54. package/src/objects/IncomingPaymentAttempt.ts +21 -5
  55. package/src/objects/IncomingPaymentToAttemptsConnection.ts +21 -5
  56. package/src/objects/Invoice.ts +37 -24
  57. package/src/objects/InvoiceData.ts +21 -6
  58. package/src/objects/LightningFeeEstimateForInvoiceInput.ts +13 -3
  59. package/src/objects/LightningFeeEstimateForNodeInput.ts +12 -2
  60. package/src/objects/LightningFeeEstimateOutput.ts +15 -3
  61. package/src/objects/LightningTransaction.ts +117 -28
  62. package/src/objects/LightsparkNode.ts +250 -210
  63. package/src/objects/LightsparkNodeOwner.ts +35 -4
  64. package/src/objects/LightsparkNodeToChannelsConnection.ts +17 -4
  65. package/src/objects/LightsparkNodeWithOSK.ts +66 -17
  66. package/src/objects/LightsparkNodeWithRemoteSigning.ts +62 -15
  67. package/src/objects/Node.ts +209 -68
  68. package/src/objects/NodeAddress.ts +8 -2
  69. package/src/objects/NodeToAddressesConnection.ts +13 -3
  70. package/src/objects/OnChainTransaction.ts +156 -44
  71. package/src/objects/OutgoingPayment.ts +53 -14
  72. package/src/objects/OutgoingPaymentAttempt.ts +37 -8
  73. package/src/objects/OutgoingPaymentAttemptToHopsConnection.ts +18 -5
  74. package/src/objects/OutgoingPaymentToAttemptsConnection.ts +17 -4
  75. package/src/objects/OutgoingPaymentsForInvoiceQueryInput.ts +12 -3
  76. package/src/objects/OutgoingPaymentsForInvoiceQueryOutput.ts +11 -2
  77. package/src/objects/PageInfo.ts +14 -6
  78. package/src/objects/PayInvoiceInput.ts +12 -3
  79. package/src/objects/PayInvoiceOutput.ts +7 -2
  80. package/src/objects/PayUmaInvoiceInput.ts +12 -3
  81. package/src/objects/PaymentRequest.ts +27 -5
  82. package/src/objects/PaymentRequestData.ts +27 -4
  83. package/src/objects/PostTransactionData.ts +12 -3
  84. package/src/objects/RegisterPaymentInput.ts +10 -2
  85. package/src/objects/RegisterPaymentOutput.ts +9 -2
  86. package/src/objects/ReleaseChannelPerCommitmentSecretInput.ts +13 -2
  87. package/src/objects/ReleaseChannelPerCommitmentSecretOutput.ts +9 -2
  88. package/src/objects/ReleasePaymentPreimageInput.ts +10 -2
  89. package/src/objects/ReleasePaymentPreimageOutput.ts +9 -2
  90. package/src/objects/RequestWithdrawalInput.ts +12 -2
  91. package/src/objects/RequestWithdrawalOutput.ts +9 -2
  92. package/src/objects/RichText.ts +7 -2
  93. package/src/objects/RoutingTransaction.ts +62 -41
  94. package/src/objects/ScreenNodeInput.ts +8 -2
  95. package/src/objects/ScreenNodeOutput.ts +7 -2
  96. package/src/objects/Secret.ts +8 -2
  97. package/src/objects/SendPaymentInput.ts +11 -2
  98. package/src/objects/SendPaymentOutput.ts +7 -2
  99. package/src/objects/SetInvoicePaymentHashInput.ts +12 -3
  100. package/src/objects/SetInvoicePaymentHashOutput.ts +9 -2
  101. package/src/objects/SignInvoiceInput.ts +9 -2
  102. package/src/objects/SignInvoiceOutput.ts +7 -2
  103. package/src/objects/SignMessagesInput.ts +13 -3
  104. package/src/objects/SignMessagesOutput.ts +13 -3
  105. package/src/objects/Signable.ts +10 -3
  106. package/src/objects/SignablePayload.ts +18 -5
  107. package/src/objects/Transaction.ts +206 -9
  108. package/src/objects/TransactionFailures.ts +11 -4
  109. package/src/objects/UpdateChannelPerCommitmentPointInput.ts +13 -2
  110. package/src/objects/UpdateChannelPerCommitmentPointOutput.ts +9 -2
  111. package/src/objects/UpdateNodeSharedSecretInput.ts +10 -2
  112. package/src/objects/UpdateNodeSharedSecretOutput.ts +9 -2
  113. package/src/objects/Wallet.ts +22 -5
  114. package/src/objects/WalletToPaymentRequestsConnection.ts +21 -5
  115. package/src/objects/WalletToTransactionsConnection.ts +16 -5
  116. package/src/objects/Withdrawal.ts +77 -61
  117. package/src/objects/WithdrawalRequest.ts +25 -4
  118. package/src/objects/WithdrawalRequestToChannelClosingTransactionsConnection.ts +19 -4
  119. package/src/objects/WithdrawalRequestToChannelOpeningTransactionsConnection.ts +19 -4
  120. package/src/objects/index.ts +5 -2
  121. package/src/tests/serialization.test.ts +18 -0
@@ -4,67 +4,67 @@ import { LightsparkException, type Query } from "@lightsparkdev/core";
4
4
  import type ChannelClosingTransaction from "./ChannelClosingTransaction.js";
5
5
  import type ChannelOpeningTransaction from "./ChannelOpeningTransaction.js";
6
6
  import type CurrencyAmount from "./CurrencyAmount.js";
7
- import { CurrencyAmountFromJson } from "./CurrencyAmount.js";
7
+ import {
8
+ CurrencyAmountFromJson,
9
+ CurrencyAmountToJson,
10
+ } from "./CurrencyAmount.js";
8
11
  import type Deposit from "./Deposit.js";
9
- import type Entity from "./Entity.js";
10
- import type Transaction from "./Transaction.js";
11
12
  import TransactionStatus from "./TransactionStatus.js";
12
13
  import type Withdrawal from "./Withdrawal.js";
13
14
 
14
15
  /** This object represents an L1 transaction that occurred on the Bitcoin Network. You can retrieve this object to receive information about a specific on-chain transaction made on the Lightning Network associated with your Lightspark Node. **/
15
- type OnChainTransaction = Transaction &
16
- Entity & {
17
- /**
18
- * The unique identifier of this entity across all Lightspark systems. Should be treated as an opaque
19
- * string.
20
- **/
21
- id: string;
16
+ interface OnChainTransaction {
17
+ /**
18
+ * The unique identifier of this entity across all Lightspark systems. Should be treated as an opaque
19
+ * string.
20
+ **/
21
+ id: string;
22
22
 
23
- /** The date and time when this transaction was initiated. **/
24
- createdAt: string;
23
+ /** The date and time when this transaction was initiated. **/
24
+ createdAt: string;
25
25
 
26
- /** The date and time when the entity was last updated. **/
27
- updatedAt: string;
26
+ /** The date and time when the entity was last updated. **/
27
+ updatedAt: string;
28
28
 
29
- /** The current status of this transaction. **/
30
- status: TransactionStatus;
29
+ /** The current status of this transaction. **/
30
+ status: TransactionStatus;
31
31
 
32
- /** The amount of money involved in this transaction. **/
33
- amount: CurrencyAmount;
32
+ /** The amount of money involved in this transaction. **/
33
+ amount: CurrencyAmount;
34
34
 
35
- /**
36
- * The height of the block that included this transaction. This will be zero for unconfirmed
37
- * transactions.
38
- **/
39
- blockHeight: number;
35
+ /**
36
+ * The height of the block that included this transaction. This will be zero for unconfirmed
37
+ * transactions.
38
+ **/
39
+ blockHeight: number;
40
40
 
41
- /** The Bitcoin blockchain addresses this transaction was sent to. **/
42
- destinationAddresses: string[];
41
+ /** The Bitcoin blockchain addresses this transaction was sent to. **/
42
+ destinationAddresses: string[];
43
43
 
44
- /** The typename of the object **/
45
- typename: string;
44
+ /** The typename of the object **/
45
+ typename: string;
46
46
 
47
- /** The date and time when this transaction was completed or failed. **/
48
- resolvedAt?: string;
47
+ /** The date and time when this transaction was completed or failed. **/
48
+ resolvedAt?: string | undefined;
49
49
 
50
- /** The hash of this transaction, so it can be uniquely identified on the Lightning Network. **/
51
- transactionHash?: string;
50
+ /** The hash of this transaction, so it can be uniquely identified on the Lightning Network. **/
51
+ transactionHash?: string | undefined;
52
52
 
53
- /**
54
- * The fees that were paid by the wallet sending the transaction to commit it to the Bitcoin
55
- * blockchain.
56
- **/
57
- fees?: CurrencyAmount;
53
+ /**
54
+ * The fees that were paid by the wallet sending the transaction to commit it to the Bitcoin
55
+ * blockchain.
56
+ **/
57
+ fees?: CurrencyAmount | undefined;
58
58
 
59
- /**
60
- * The hash of the block that included this transaction. This will be null for unconfirmed
61
- * transactions.
62
- **/
63
- blockHash?: string;
59
+ /**
60
+ * The hash of the block that included this transaction. This will be null for unconfirmed
61
+ * transactions.
62
+ **/
63
+ blockHash?: string | undefined;
64
64
 
65
- /** The number of blockchain confirmations for this transaction in real time. **/
66
- numConfirmations?: number;
67
- };
65
+ /** The number of blockchain confirmations for this transaction in real time. **/
66
+ numConfirmations?: number | undefined;
67
+ }
68
68
 
69
69
  export const OnChainTransactionFromJson = (obj: any): OnChainTransaction => {
70
70
  if (obj["__typename"] == "ChannelClosingTransaction") {
@@ -162,6 +162,118 @@ export const OnChainTransactionFromJson = (obj: any): OnChainTransaction => {
162
162
  `Couldn't find a concrete type for interface OnChainTransaction corresponding to the typename=${obj["__typename"]}`,
163
163
  );
164
164
  };
165
+ export const OnChainTransactionToJson = (obj: OnChainTransaction): any => {
166
+ if (obj.typename == "ChannelClosingTransaction") {
167
+ const channelClosingTransaction = obj as ChannelClosingTransaction;
168
+ return {
169
+ __typename: "ChannelClosingTransaction",
170
+ channel_closing_transaction_id: channelClosingTransaction.id,
171
+ channel_closing_transaction_created_at:
172
+ channelClosingTransaction.createdAt,
173
+ channel_closing_transaction_updated_at:
174
+ channelClosingTransaction.updatedAt,
175
+ channel_closing_transaction_status: channelClosingTransaction.status,
176
+ channel_closing_transaction_resolved_at:
177
+ channelClosingTransaction.resolvedAt,
178
+ channel_closing_transaction_amount: CurrencyAmountToJson(
179
+ channelClosingTransaction.amount,
180
+ ),
181
+ channel_closing_transaction_transaction_hash:
182
+ channelClosingTransaction.transactionHash,
183
+ channel_closing_transaction_fees: channelClosingTransaction.fees
184
+ ? CurrencyAmountToJson(channelClosingTransaction.fees)
185
+ : undefined,
186
+ channel_closing_transaction_block_hash:
187
+ channelClosingTransaction.blockHash,
188
+ channel_closing_transaction_block_height:
189
+ channelClosingTransaction.blockHeight,
190
+ channel_closing_transaction_destination_addresses:
191
+ channelClosingTransaction.destinationAddresses,
192
+ channel_closing_transaction_num_confirmations:
193
+ channelClosingTransaction.numConfirmations,
194
+ channel_closing_transaction_channel:
195
+ { id: channelClosingTransaction.channelId } ?? undefined,
196
+ };
197
+ }
198
+ if (obj.typename == "ChannelOpeningTransaction") {
199
+ const channelOpeningTransaction = obj as ChannelOpeningTransaction;
200
+ return {
201
+ __typename: "ChannelOpeningTransaction",
202
+ channel_opening_transaction_id: channelOpeningTransaction.id,
203
+ channel_opening_transaction_created_at:
204
+ channelOpeningTransaction.createdAt,
205
+ channel_opening_transaction_updated_at:
206
+ channelOpeningTransaction.updatedAt,
207
+ channel_opening_transaction_status: channelOpeningTransaction.status,
208
+ channel_opening_transaction_resolved_at:
209
+ channelOpeningTransaction.resolvedAt,
210
+ channel_opening_transaction_amount: CurrencyAmountToJson(
211
+ channelOpeningTransaction.amount,
212
+ ),
213
+ channel_opening_transaction_transaction_hash:
214
+ channelOpeningTransaction.transactionHash,
215
+ channel_opening_transaction_fees: channelOpeningTransaction.fees
216
+ ? CurrencyAmountToJson(channelOpeningTransaction.fees)
217
+ : undefined,
218
+ channel_opening_transaction_block_hash:
219
+ channelOpeningTransaction.blockHash,
220
+ channel_opening_transaction_block_height:
221
+ channelOpeningTransaction.blockHeight,
222
+ channel_opening_transaction_destination_addresses:
223
+ channelOpeningTransaction.destinationAddresses,
224
+ channel_opening_transaction_num_confirmations:
225
+ channelOpeningTransaction.numConfirmations,
226
+ channel_opening_transaction_channel:
227
+ { id: channelOpeningTransaction.channelId } ?? undefined,
228
+ };
229
+ }
230
+ if (obj.typename == "Deposit") {
231
+ const deposit = obj as Deposit;
232
+ return {
233
+ __typename: "Deposit",
234
+ deposit_id: deposit.id,
235
+ deposit_created_at: deposit.createdAt,
236
+ deposit_updated_at: deposit.updatedAt,
237
+ deposit_status: deposit.status,
238
+ deposit_resolved_at: deposit.resolvedAt,
239
+ deposit_amount: CurrencyAmountToJson(deposit.amount),
240
+ deposit_transaction_hash: deposit.transactionHash,
241
+ deposit_fees: deposit.fees
242
+ ? CurrencyAmountToJson(deposit.fees)
243
+ : undefined,
244
+ deposit_block_hash: deposit.blockHash,
245
+ deposit_block_height: deposit.blockHeight,
246
+ deposit_destination_addresses: deposit.destinationAddresses,
247
+ deposit_num_confirmations: deposit.numConfirmations,
248
+ deposit_destination: { id: deposit.destinationId },
249
+ };
250
+ }
251
+ if (obj.typename == "Withdrawal") {
252
+ const withdrawal = obj as Withdrawal;
253
+ return {
254
+ __typename: "Withdrawal",
255
+ withdrawal_id: withdrawal.id,
256
+ withdrawal_created_at: withdrawal.createdAt,
257
+ withdrawal_updated_at: withdrawal.updatedAt,
258
+ withdrawal_status: withdrawal.status,
259
+ withdrawal_resolved_at: withdrawal.resolvedAt,
260
+ withdrawal_amount: CurrencyAmountToJson(withdrawal.amount),
261
+ withdrawal_transaction_hash: withdrawal.transactionHash,
262
+ withdrawal_fees: withdrawal.fees
263
+ ? CurrencyAmountToJson(withdrawal.fees)
264
+ : undefined,
265
+ withdrawal_block_hash: withdrawal.blockHash,
266
+ withdrawal_block_height: withdrawal.blockHeight,
267
+ withdrawal_destination_addresses: withdrawal.destinationAddresses,
268
+ withdrawal_num_confirmations: withdrawal.numConfirmations,
269
+ withdrawal_origin: { id: withdrawal.originId },
270
+ };
271
+ }
272
+ throw new LightsparkException(
273
+ "DeserializationError",
274
+ `Couldn't find a concrete type for interface OnChainTransaction corresponding to the typename=${obj.typename}`,
275
+ );
276
+ };
165
277
 
166
278
  export const FRAGMENT = `
167
279
  fragment OnChainTransactionFragment on OnChainTransaction {
@@ -4,21 +4,32 @@ import { type Query } from "@lightsparkdev/core";
4
4
  import autoBind from "auto-bind";
5
5
  import type LightsparkClient from "../client.js";
6
6
  import type CurrencyAmount from "./CurrencyAmount.js";
7
- import { CurrencyAmountFromJson } from "./CurrencyAmount.js";
7
+ import {
8
+ CurrencyAmountFromJson,
9
+ CurrencyAmountToJson,
10
+ } from "./CurrencyAmount.js";
11
+ import type Entity from "./Entity.js";
8
12
  import type LightningTransaction from "./LightningTransaction.js";
9
13
  import type OutgoingPaymentToAttemptsConnection from "./OutgoingPaymentToAttemptsConnection.js";
10
14
  import { OutgoingPaymentToAttemptsConnectionFromJson } from "./OutgoingPaymentToAttemptsConnection.js";
11
15
  import PaymentFailureReason from "./PaymentFailureReason.js";
12
16
  import type PaymentRequestData from "./PaymentRequestData.js";
13
- import { PaymentRequestDataFromJson } from "./PaymentRequestData.js";
17
+ import {
18
+ PaymentRequestDataFromJson,
19
+ PaymentRequestDataToJson,
20
+ } from "./PaymentRequestData.js";
14
21
  import type PostTransactionData from "./PostTransactionData.js";
15
- import { PostTransactionDataFromJson } from "./PostTransactionData.js";
22
+ import {
23
+ PostTransactionDataFromJson,
24
+ PostTransactionDataToJson,
25
+ } from "./PostTransactionData.js";
16
26
  import type RichText from "./RichText.js";
17
- import { RichTextFromJson } from "./RichText.js";
27
+ import { RichTextFromJson, RichTextToJson } from "./RichText.js";
28
+ import type Transaction from "./Transaction.js";
18
29
  import TransactionStatus from "./TransactionStatus.js";
19
30
 
20
31
  /** This object represents a Lightning Network payment sent from a Lightspark Node. You can retrieve this object to receive payment related information about any payment sent from your Lightspark Node on the Lightning Network. **/
21
- class OutgoingPayment implements LightningTransaction {
32
+ class OutgoingPayment implements LightningTransaction, Transaction, Entity {
22
33
  constructor(
23
34
  public readonly id: string,
24
35
  public readonly createdAt: string,
@@ -27,15 +38,15 @@ class OutgoingPayment implements LightningTransaction {
27
38
  public readonly amount: CurrencyAmount,
28
39
  public readonly originId: string,
29
40
  public readonly typename: string,
30
- public readonly resolvedAt?: string,
31
- public readonly transactionHash?: string,
32
- public readonly destinationId?: string,
33
- public readonly fees?: CurrencyAmount,
34
- public readonly paymentRequestData?: PaymentRequestData,
35
- public readonly failureReason?: PaymentFailureReason,
36
- public readonly failureMessage?: RichText,
37
- public readonly umaPostTransactionData?: PostTransactionData[],
38
- public readonly paymentPreimage?: string,
41
+ public readonly resolvedAt?: string | undefined,
42
+ public readonly transactionHash?: string | undefined,
43
+ public readonly destinationId?: string | undefined,
44
+ public readonly fees?: CurrencyAmount | undefined,
45
+ public readonly paymentRequestData?: PaymentRequestData | undefined,
46
+ public readonly failureReason?: PaymentFailureReason | undefined,
47
+ public readonly failureMessage?: RichText | undefined,
48
+ public readonly umaPostTransactionData?: PostTransactionData[] | undefined,
49
+ public readonly paymentPreimage?: string | undefined,
39
50
  ) {
40
51
  autoBind(this);
41
52
  }
@@ -166,6 +177,34 @@ ${FRAGMENT}
166
177
  constructObject: (data: any) => OutgoingPaymentFromJson(data.entity),
167
178
  };
168
179
  }
180
+
181
+ public toJson() {
182
+ return {
183
+ __typename: "OutgoingPayment",
184
+ outgoing_payment_id: this.id,
185
+ outgoing_payment_created_at: this.createdAt,
186
+ outgoing_payment_updated_at: this.updatedAt,
187
+ outgoing_payment_status: this.status,
188
+ outgoing_payment_resolved_at: this.resolvedAt,
189
+ outgoing_payment_amount: CurrencyAmountToJson(this.amount),
190
+ outgoing_payment_transaction_hash: this.transactionHash,
191
+ outgoing_payment_origin: { id: this.originId },
192
+ outgoing_payment_destination: { id: this.destinationId } ?? undefined,
193
+ outgoing_payment_fees: this.fees
194
+ ? CurrencyAmountToJson(this.fees)
195
+ : undefined,
196
+ outgoing_payment_payment_request_data: this.paymentRequestData
197
+ ? PaymentRequestDataToJson(this.paymentRequestData)
198
+ : undefined,
199
+ outgoing_payment_failure_reason: this.failureReason,
200
+ outgoing_payment_failure_message: this.failureMessage
201
+ ? RichTextToJson(this.failureMessage)
202
+ : undefined,
203
+ outgoing_payment_uma_post_transaction_data:
204
+ this.umaPostTransactionData?.map((e) => PostTransactionDataToJson(e)),
205
+ outgoing_payment_payment_preimage: this.paymentPreimage,
206
+ };
207
+ }
169
208
  }
170
209
 
171
210
  export const OutgoingPaymentFromJson = (obj: any): OutgoingPayment => {
@@ -4,9 +4,15 @@ import { type Query } from "@lightsparkdev/core";
4
4
  import autoBind from "auto-bind";
5
5
  import type LightsparkClient from "../client.js";
6
6
  import type ChannelSnapshot from "./ChannelSnapshot.js";
7
- import { ChannelSnapshotFromJson } from "./ChannelSnapshot.js";
7
+ import {
8
+ ChannelSnapshotFromJson,
9
+ ChannelSnapshotToJson,
10
+ } from "./ChannelSnapshot.js";
8
11
  import type CurrencyAmount from "./CurrencyAmount.js";
9
- import { CurrencyAmountFromJson } from "./CurrencyAmount.js";
12
+ import {
13
+ CurrencyAmountFromJson,
14
+ CurrencyAmountToJson,
15
+ } from "./CurrencyAmount.js";
10
16
  import type Entity from "./Entity.js";
11
17
  import HtlcAttemptFailureCode from "./HtlcAttemptFailureCode.js";
12
18
  import OutgoingPaymentAttemptStatus from "./OutgoingPaymentAttemptStatus.js";
@@ -22,12 +28,12 @@ class OutgoingPaymentAttempt implements Entity {
22
28
  public readonly status: OutgoingPaymentAttemptStatus,
23
29
  public readonly outgoingPaymentId: string,
24
30
  public readonly typename: string,
25
- public readonly failureCode?: HtlcAttemptFailureCode,
26
- public readonly failureSourceIndex?: number,
27
- public readonly resolvedAt?: string,
28
- public readonly amount?: CurrencyAmount,
29
- public readonly fees?: CurrencyAmount,
30
- public readonly channelSnapshot?: ChannelSnapshot,
31
+ public readonly failureCode?: HtlcAttemptFailureCode | undefined,
32
+ public readonly failureSourceIndex?: number | undefined,
33
+ public readonly resolvedAt?: string | undefined,
34
+ public readonly amount?: CurrencyAmount | undefined,
35
+ public readonly fees?: CurrencyAmount | undefined,
36
+ public readonly channelSnapshot?: ChannelSnapshot | undefined,
31
37
  ) {
32
38
  autoBind(this);
33
39
  }
@@ -113,6 +119,29 @@ ${FRAGMENT}
113
119
  OutgoingPaymentAttemptFromJson(data.entity),
114
120
  };
115
121
  }
122
+
123
+ public toJson() {
124
+ return {
125
+ __typename: "OutgoingPaymentAttempt",
126
+ outgoing_payment_attempt_id: this.id,
127
+ outgoing_payment_attempt_created_at: this.createdAt,
128
+ outgoing_payment_attempt_updated_at: this.updatedAt,
129
+ outgoing_payment_attempt_status: this.status,
130
+ outgoing_payment_attempt_failure_code: this.failureCode,
131
+ outgoing_payment_attempt_failure_source_index: this.failureSourceIndex,
132
+ outgoing_payment_attempt_resolved_at: this.resolvedAt,
133
+ outgoing_payment_attempt_amount: this.amount
134
+ ? CurrencyAmountToJson(this.amount)
135
+ : undefined,
136
+ outgoing_payment_attempt_fees: this.fees
137
+ ? CurrencyAmountToJson(this.fees)
138
+ : undefined,
139
+ outgoing_payment_attempt_outgoing_payment: { id: this.outgoingPaymentId },
140
+ outgoing_payment_attempt_channel_snapshot: this.channelSnapshot
141
+ ? ChannelSnapshotToJson(this.channelSnapshot)
142
+ : undefined,
143
+ };
144
+ }
116
145
  }
117
146
 
118
147
  export const OutgoingPaymentAttemptFromJson = (
@@ -1,13 +1,12 @@
1
1
  // Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
2
2
 
3
- import type Connection from "./Connection.js";
4
3
  import type Hop from "./Hop.js";
5
- import { HopFromJson } from "./Hop.js";
4
+ import { HopFromJson, HopToJson } from "./Hop.js";
6
5
  import type PageInfo from "./PageInfo.js";
7
- import { PageInfoFromJson } from "./PageInfo.js";
6
+ import { PageInfoFromJson, PageInfoToJson } from "./PageInfo.js";
8
7
 
9
8
  /** The connection from an outgoing payment attempt to the list of sequential hops that define the path from sender node to recipient node. **/
10
- type OutgoingPaymentAttemptToHopsConnection = Connection & {
9
+ interface OutgoingPaymentAttemptToHopsConnection {
11
10
  /**
12
11
  * The total count of objects in this connection, using the current filters. It is different from the
13
12
  * number of objects returned in the current page (in the `entities` field).
@@ -22,7 +21,7 @@ type OutgoingPaymentAttemptToHopsConnection = Connection & {
22
21
 
23
22
  /** The typename of the object **/
24
23
  typename: string;
25
- };
24
+ }
26
25
 
27
26
  export const OutgoingPaymentAttemptToHopsConnectionFromJson = (
28
27
  obj: any,
@@ -38,6 +37,20 @@ export const OutgoingPaymentAttemptToHopsConnectionFromJson = (
38
37
  typename: "OutgoingPaymentAttemptToHopsConnection",
39
38
  } as OutgoingPaymentAttemptToHopsConnection;
40
39
  };
40
+ export const OutgoingPaymentAttemptToHopsConnectionToJson = (
41
+ obj: OutgoingPaymentAttemptToHopsConnection,
42
+ ): any => {
43
+ return {
44
+ __typename: "OutgoingPaymentAttemptToHopsConnection",
45
+ outgoing_payment_attempt_to_hops_connection_count: obj.count,
46
+ outgoing_payment_attempt_to_hops_connection_page_info: PageInfoToJson(
47
+ obj.pageInfo,
48
+ ),
49
+ outgoing_payment_attempt_to_hops_connection_entities: obj.entities.map(
50
+ (e) => HopToJson(e),
51
+ ),
52
+ };
53
+ };
41
54
 
42
55
  export const FRAGMENT = `
43
56
  fragment OutgoingPaymentAttemptToHopsConnectionFragment on OutgoingPaymentAttemptToHopsConnection {
@@ -1,13 +1,12 @@
1
1
  // Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
2
2
 
3
- import type Connection from "./Connection.js";
4
3
  import type OutgoingPaymentAttempt from "./OutgoingPaymentAttempt.js";
5
4
  import { OutgoingPaymentAttemptFromJson } from "./OutgoingPaymentAttempt.js";
6
5
  import type PageInfo from "./PageInfo.js";
7
- import { PageInfoFromJson } from "./PageInfo.js";
6
+ import { PageInfoFromJson, PageInfoToJson } from "./PageInfo.js";
8
7
 
9
8
  /** The connection from outgoing payment to all attempts. **/
10
- type OutgoingPaymentToAttemptsConnection = Connection & {
9
+ interface OutgoingPaymentToAttemptsConnection {
11
10
  /**
12
11
  * The total count of objects in this connection, using the current filters. It is different from the
13
12
  * number of objects returned in the current page (in the `entities` field).
@@ -22,7 +21,7 @@ type OutgoingPaymentToAttemptsConnection = Connection & {
22
21
 
23
22
  /** The typename of the object **/
24
23
  typename: string;
25
- };
24
+ }
26
25
 
27
26
  export const OutgoingPaymentToAttemptsConnectionFromJson = (
28
27
  obj: any,
@@ -38,6 +37,20 @@ export const OutgoingPaymentToAttemptsConnectionFromJson = (
38
37
  typename: "OutgoingPaymentToAttemptsConnection",
39
38
  } as OutgoingPaymentToAttemptsConnection;
40
39
  };
40
+ export const OutgoingPaymentToAttemptsConnectionToJson = (
41
+ obj: OutgoingPaymentToAttemptsConnection,
42
+ ): any => {
43
+ return {
44
+ __typename: "OutgoingPaymentToAttemptsConnection",
45
+ outgoing_payment_to_attempts_connection_count: obj.count,
46
+ outgoing_payment_to_attempts_connection_page_info: PageInfoToJson(
47
+ obj.pageInfo,
48
+ ),
49
+ outgoing_payment_to_attempts_connection_entities: obj.entities.map((e) =>
50
+ e.toJson(),
51
+ ),
52
+ };
53
+ };
41
54
 
42
55
  export const FRAGMENT = `
43
56
  fragment OutgoingPaymentToAttemptsConnectionFragment on OutgoingPaymentToAttemptsConnection {
@@ -2,13 +2,13 @@
2
2
 
3
3
  import TransactionStatus from "./TransactionStatus.js";
4
4
 
5
- type OutgoingPaymentsForInvoiceQueryInput = {
5
+ interface OutgoingPaymentsForInvoiceQueryInput {
6
6
  /** The encoded invoice that the outgoing payments paid to. **/
7
7
  encodedInvoice: string;
8
8
 
9
9
  /** An optional filter to only query outgoing payments of given statuses. **/
10
- statuses?: TransactionStatus[];
11
- };
10
+ statuses?: TransactionStatus[] | undefined;
11
+ }
12
12
 
13
13
  export const OutgoingPaymentsForInvoiceQueryInputFromJson = (
14
14
  obj: any,
@@ -21,5 +21,14 @@ export const OutgoingPaymentsForInvoiceQueryInputFromJson = (
21
21
  ),
22
22
  } as OutgoingPaymentsForInvoiceQueryInput;
23
23
  };
24
+ export const OutgoingPaymentsForInvoiceQueryInputToJson = (
25
+ obj: OutgoingPaymentsForInvoiceQueryInput,
26
+ ): any => {
27
+ return {
28
+ outgoing_payments_for_invoice_query_input_encoded_invoice:
29
+ obj.encodedInvoice,
30
+ outgoing_payments_for_invoice_query_input_statuses: obj.statuses,
31
+ };
32
+ };
24
33
 
25
34
  export default OutgoingPaymentsForInvoiceQueryInput;
@@ -3,9 +3,9 @@
3
3
  import type OutgoingPayment from "./OutgoingPayment.js";
4
4
  import { OutgoingPaymentFromJson } from "./OutgoingPayment.js";
5
5
 
6
- type OutgoingPaymentsForInvoiceQueryOutput = {
6
+ interface OutgoingPaymentsForInvoiceQueryOutput {
7
7
  payments: OutgoingPayment[];
8
- };
8
+ }
9
9
 
10
10
  export const OutgoingPaymentsForInvoiceQueryOutputFromJson = (
11
11
  obj: any,
@@ -16,6 +16,15 @@ export const OutgoingPaymentsForInvoiceQueryOutputFromJson = (
16
16
  ),
17
17
  } as OutgoingPaymentsForInvoiceQueryOutput;
18
18
  };
19
+ export const OutgoingPaymentsForInvoiceQueryOutputToJson = (
20
+ obj: OutgoingPaymentsForInvoiceQueryOutput,
21
+ ): any => {
22
+ return {
23
+ outgoing_payments_for_invoice_query_output_payments: obj.payments.map((e) =>
24
+ e.toJson(),
25
+ ),
26
+ };
27
+ };
19
28
 
20
29
  export const FRAGMENT = `
21
30
  fragment OutgoingPaymentsForInvoiceQueryOutputFragment on OutgoingPaymentsForInvoiceQueryOutput {
@@ -1,15 +1,15 @@
1
1
  // Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
2
2
 
3
3
  /** This is an object representing information about a page returned by the Lightspark API. For more information, please see the “Pagination” section of our API docs for more information about its usage. **/
4
- type PageInfo = {
5
- hasNextPage?: boolean;
4
+ interface PageInfo {
5
+ hasNextPage?: boolean | undefined;
6
6
 
7
- hasPreviousPage?: boolean;
7
+ hasPreviousPage?: boolean | undefined;
8
8
 
9
- startCursor?: string;
9
+ startCursor?: string | undefined;
10
10
 
11
- endCursor?: string;
12
- };
11
+ endCursor?: string | undefined;
12
+ }
13
13
 
14
14
  export const PageInfoFromJson = (obj: any): PageInfo => {
15
15
  return {
@@ -19,6 +19,14 @@ export const PageInfoFromJson = (obj: any): PageInfo => {
19
19
  endCursor: obj["page_info_end_cursor"],
20
20
  } as PageInfo;
21
21
  };
22
+ export const PageInfoToJson = (obj: PageInfo): any => {
23
+ return {
24
+ page_info_has_next_page: obj.hasNextPage,
25
+ page_info_has_previous_page: obj.hasPreviousPage,
26
+ page_info_start_cursor: obj.startCursor,
27
+ page_info_end_cursor: obj.endCursor,
28
+ };
29
+ };
22
30
 
23
31
  export const FRAGMENT = `
24
32
  fragment PageInfoFragment on PageInfo {
@@ -1,6 +1,6 @@
1
1
  // Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
2
2
 
3
- type PayInvoiceInput = {
3
+ interface PayInvoiceInput {
4
4
  /** The node from where you want to send the payment. **/
5
5
  nodeId: string;
6
6
 
@@ -17,8 +17,8 @@ type PayInvoiceInput = {
17
17
  * The amount you will pay for this invoice, expressed in msats. It should ONLY be set when the
18
18
  * invoice amount is zero.
19
19
  **/
20
- amountMsats?: number;
21
- };
20
+ amountMsats?: number | undefined;
21
+ }
22
22
 
23
23
  export const PayInvoiceInputFromJson = (obj: any): PayInvoiceInput => {
24
24
  return {
@@ -29,5 +29,14 @@ export const PayInvoiceInputFromJson = (obj: any): PayInvoiceInput => {
29
29
  amountMsats: obj["pay_invoice_input_amount_msats"],
30
30
  } as PayInvoiceInput;
31
31
  };
32
+ export const PayInvoiceInputToJson = (obj: PayInvoiceInput): any => {
33
+ return {
34
+ pay_invoice_input_node_id: obj.nodeId,
35
+ pay_invoice_input_encoded_invoice: obj.encodedInvoice,
36
+ pay_invoice_input_timeout_secs: obj.timeoutSecs,
37
+ pay_invoice_input_maximum_fees_msats: obj.maximumFeesMsats,
38
+ pay_invoice_input_amount_msats: obj.amountMsats,
39
+ };
40
+ };
32
41
 
33
42
  export default PayInvoiceInput;
@@ -1,15 +1,20 @@
1
1
  // Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
2
2
 
3
- type PayInvoiceOutput = {
3
+ interface PayInvoiceOutput {
4
4
  /** The payment that has been sent. **/
5
5
  paymentId: string;
6
- };
6
+ }
7
7
 
8
8
  export const PayInvoiceOutputFromJson = (obj: any): PayInvoiceOutput => {
9
9
  return {
10
10
  paymentId: obj["pay_invoice_output_payment"].id,
11
11
  } as PayInvoiceOutput;
12
12
  };
13
+ export const PayInvoiceOutputToJson = (obj: PayInvoiceOutput): any => {
14
+ return {
15
+ pay_invoice_output_payment: { id: obj.paymentId },
16
+ };
17
+ };
13
18
 
14
19
  export const FRAGMENT = `
15
20
  fragment PayInvoiceOutputFragment on PayInvoiceOutput {