@lightsparkdev/lightspark-sdk 1.7.1 → 1.8.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.
Files changed (51) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/{chunk-DSWMAFFH.js → chunk-4KFNQOMH.js} +99 -41
  3. package/dist/{index-85107c9f.d.ts → index-9a69ef6a.d.ts} +18 -6
  4. package/dist/index.cjs +158 -94
  5. package/dist/index.d.cts +2 -2
  6. package/dist/index.d.ts +2 -2
  7. package/dist/index.js +4 -4
  8. package/dist/objects/index.cjs +112 -54
  9. package/dist/objects/index.d.cts +1 -1
  10. package/dist/objects/index.d.ts +1 -1
  11. package/dist/objects/index.js +1 -1
  12. package/package.json +2 -2
  13. package/src/client.ts +1 -1
  14. package/src/objects/Account.ts +9 -2
  15. package/src/objects/ApiToken.ts +5 -2
  16. package/src/objects/AuditLogActor.ts +5 -2
  17. package/src/objects/Channel.ts +5 -2
  18. package/src/objects/ChannelClosingTransaction.ts +5 -3
  19. package/src/objects/ChannelOpeningTransaction.ts +5 -3
  20. package/src/objects/ChannelSnapshot.ts +5 -2
  21. package/src/objects/CurrencyUnit.ts +1 -1
  22. package/src/objects/Deposit.ts +5 -2
  23. package/src/objects/Entity.ts +2 -0
  24. package/src/objects/GraphNode.ts +5 -2
  25. package/src/objects/Hop.ts +5 -2
  26. package/src/objects/IncomingPayment.ts +5 -2
  27. package/src/objects/IncomingPaymentAttempt.ts +5 -2
  28. package/src/objects/Invoice.ts +23 -2
  29. package/src/objects/LightningTransaction.ts +5 -2
  30. package/src/objects/LightsparkNode.ts +5 -2
  31. package/src/objects/LightsparkNodeOwner.ts +5 -2
  32. package/src/objects/LightsparkNodeWithOSK.ts +5 -3
  33. package/src/objects/LightsparkNodeWithRemoteSigning.ts +5 -3
  34. package/src/objects/Node.ts +5 -2
  35. package/src/objects/OnChainTransaction.ts +5 -2
  36. package/src/objects/OutgoingPayment.ts +5 -2
  37. package/src/objects/OutgoingPaymentAttempt.ts +5 -3
  38. package/src/objects/PaymentRequest.ts +11 -2
  39. package/src/objects/RegionCode.ts +2 -0
  40. package/src/objects/RoutingTransaction.ts +5 -2
  41. package/src/objects/Signable.ts +5 -2
  42. package/src/objects/SignablePayload.ts +5 -2
  43. package/src/objects/Transaction.ts +5 -2
  44. package/src/objects/TransactionStatus.ts +1 -1
  45. package/src/objects/UmaInvitation.ts +5 -2
  46. package/src/objects/Wallet.ts +7 -2
  47. package/src/objects/WalletStatus.ts +2 -2
  48. package/src/objects/Withdrawal.ts +5 -2
  49. package/src/objects/WithdrawalRequest.ts +5 -2
  50. package/src/tests/generated-objects.test.ts +93 -0
  51. package/src/tests/serialization.test.ts +0 -21
@@ -1,6 +1,6 @@
1
1
  // Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
2
2
 
3
- import { LightsparkException, type Query } from "@lightsparkdev/core";
3
+ import { LightsparkException, isObject, type Query } from "@lightsparkdev/core";
4
4
  import {
5
5
  CurrencyAmountFromJson,
6
6
  CurrencyAmountToJson,
@@ -52,6 +52,8 @@ export const PaymentRequestFromJson = (obj: any): PaymentRequest => {
52
52
  amountPaid: !!obj["invoice_amount_paid"]
53
53
  ? CurrencyAmountFromJson(obj["invoice_amount_paid"])
54
54
  : undefined,
55
+ isUma: obj["invoice_is_uma"],
56
+ isLnurl: obj["invoice_is_lnurl"],
55
57
  } as Invoice;
56
58
  }
57
59
  throw new LightsparkException(
@@ -72,6 +74,8 @@ export const PaymentRequestToJson = (obj: PaymentRequest): any => {
72
74
  invoice_amount_paid: invoice.amountPaid
73
75
  ? CurrencyAmountToJson(invoice.amountPaid)
74
76
  : undefined,
77
+ invoice_is_uma: invoice.isUma,
78
+ invoice_is_lnurl: invoice.isLnurl,
75
79
  };
76
80
  }
77
81
  throw new LightsparkException(
@@ -388,6 +392,8 @@ fragment PaymentRequestFragment on PaymentRequest {
388
392
  currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
389
393
  currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
390
394
  }
395
+ invoice_is_uma: is_uma
396
+ invoice_is_lnurl: is_lnurl
391
397
  }
392
398
  }`;
393
399
 
@@ -405,7 +411,10 @@ query GetPaymentRequest($id: ID!) {
405
411
  ${FRAGMENT}
406
412
  `,
407
413
  variables: { id },
408
- constructObject: (data: any) => PaymentRequestFromJson(data.entity),
414
+ constructObject: (data: unknown) =>
415
+ isObject(data) && "entity" in data && isObject(data.entity)
416
+ ? PaymentRequestFromJson(data.entity)
417
+ : null,
409
418
  };
410
419
  };
411
420
 
@@ -505,6 +505,8 @@ export enum RegionCode {
505
505
  ZM = "ZM",
506
506
  /** The code representing the country of Zimbabwe. **/
507
507
  ZW = "ZW",
508
+ /** The code representing a fake region for testing. **/
509
+ NN = "NN",
508
510
  }
509
511
 
510
512
  export default RegionCode;
@@ -1,6 +1,6 @@
1
1
  // Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
2
2
 
3
- import { type Query } from "@lightsparkdev/core";
3
+ import { isObject, type Query } from "@lightsparkdev/core";
4
4
  import type CurrencyAmount from "./CurrencyAmount.js";
5
5
  import {
6
6
  CurrencyAmountFromJson,
@@ -170,7 +170,10 @@ query GetRoutingTransaction($id: ID!) {
170
170
  ${FRAGMENT}
171
171
  `,
172
172
  variables: { id },
173
- constructObject: (data: any) => RoutingTransactionFromJson(data.entity),
173
+ constructObject: (data: unknown) =>
174
+ isObject(data) && "entity" in data && isObject(data.entity)
175
+ ? RoutingTransactionFromJson(data.entity)
176
+ : null,
174
177
  };
175
178
  };
176
179
 
@@ -1,6 +1,6 @@
1
1
  // Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
2
2
 
3
- import { type Query } from "@lightsparkdev/core";
3
+ import { isObject, type Query } from "@lightsparkdev/core";
4
4
 
5
5
  interface Signable {
6
6
  /**
@@ -58,7 +58,10 @@ query GetSignable($id: ID!) {
58
58
  ${FRAGMENT}
59
59
  `,
60
60
  variables: { id },
61
- constructObject: (data: any) => SignableFromJson(data.entity),
61
+ constructObject: (data: unknown) =>
62
+ isObject(data) && "entity" in data && isObject(data.entity)
63
+ ? SignableFromJson(data.entity)
64
+ : null,
62
65
  };
63
66
  };
64
67
 
@@ -1,6 +1,6 @@
1
1
  // Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
2
2
 
3
- import { type Query } from "@lightsparkdev/core";
3
+ import { isObject, type Query } from "@lightsparkdev/core";
4
4
  import SignablePayloadStatus from "./SignablePayloadStatus.js";
5
5
 
6
6
  interface SignablePayload {
@@ -102,7 +102,10 @@ query GetSignablePayload($id: ID!) {
102
102
  ${FRAGMENT}
103
103
  `,
104
104
  variables: { id },
105
- constructObject: (data: any) => SignablePayloadFromJson(data.entity),
105
+ constructObject: (data: unknown) =>
106
+ isObject(data) && "entity" in data && isObject(data.entity)
107
+ ? SignablePayloadFromJson(data.entity)
108
+ : null,
106
109
  };
107
110
  };
108
111
 
@@ -1,6 +1,6 @@
1
1
  // Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
2
2
 
3
- import { LightsparkException, type Query } from "@lightsparkdev/core";
3
+ import { LightsparkException, isObject, 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";
@@ -1003,7 +1003,10 @@ query GetTransaction($id: ID!) {
1003
1003
  ${FRAGMENT}
1004
1004
  `,
1005
1005
  variables: { id },
1006
- constructObject: (data: any) => TransactionFromJson(data.entity),
1006
+ constructObject: (data: unknown) =>
1007
+ isObject(data) && "entity" in data && isObject(data.entity)
1008
+ ? TransactionFromJson(data.entity)
1009
+ : null,
1007
1010
  };
1008
1011
  };
1009
1012
 
@@ -17,7 +17,7 @@ export enum TransactionStatus {
17
17
  /** Transaction has been initiated and is currently in-flight. **/
18
18
  PENDING = "PENDING",
19
19
  /**
20
- * For transaction type PAYMENT_REQUEST only. No payments have been made to a payment request.
20
+ * For transaction type PAYMENT_REQUEST only. No payments have been made to a payment request. *
21
21
  */
22
22
  NOT_STARTED = "NOT_STARTED",
23
23
  /** For transaction type PAYMENT_REQUEST only. A payment request has expired. **/
@@ -1,6 +1,6 @@
1
1
  // Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
2
2
 
3
- import { type Query } from "@lightsparkdev/core";
3
+ import { isObject, type Query } from "@lightsparkdev/core";
4
4
  import IncentivesIneligibilityReason from "./IncentivesIneligibilityReason.js";
5
5
  import IncentivesStatus from "./IncentivesStatus.js";
6
6
 
@@ -106,7 +106,10 @@ query GetUmaInvitation($id: ID!) {
106
106
  ${FRAGMENT}
107
107
  `,
108
108
  variables: { id },
109
- constructObject: (data: any) => UmaInvitationFromJson(data.entity),
109
+ constructObject: (data: unknown) =>
110
+ isObject(data) && "entity" in data && isObject(data.entity)
111
+ ? UmaInvitationFromJson(data.entity)
112
+ : null,
110
113
  };
111
114
  };
112
115
 
@@ -1,6 +1,6 @@
1
1
  // Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
2
2
 
3
- import { type Query } from "@lightsparkdev/core";
3
+ import { isObject, type Query } from "@lightsparkdev/core";
4
4
  import autoBind from "auto-bind";
5
5
  import type LightsparkClient from "../client.js";
6
6
  import type Balances from "./Balances.js";
@@ -978,6 +978,8 @@ query FetchWalletToPaymentRequestsConnection($entity_id: ID!, $first: Int, $afte
978
978
  currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
979
979
  currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
980
980
  }
981
+ invoice_is_uma: is_uma
982
+ invoice_is_lnurl: is_lnurl
981
983
  }
982
984
  }
983
985
  }
@@ -1179,7 +1181,10 @@ query GetWallet($id: ID!) {
1179
1181
  ${FRAGMENT}
1180
1182
  `,
1181
1183
  variables: { id },
1182
- constructObject: (data: any) => WalletFromJson(data.entity),
1184
+ constructObject: (data: unknown) =>
1185
+ isObject(data) && "entity" in data && isObject(data.entity)
1186
+ ? WalletFromJson(data.entity)
1187
+ : null,
1183
1188
  };
1184
1189
  }
1185
1190
 
@@ -33,8 +33,8 @@ export enum WalletStatus {
33
33
  TERMINATING = "TERMINATING",
34
34
  /**
35
35
  * The wallet has been terminated and is not available in the Lightspark infrastructure anymore.
36
- * It is not connected to the Lightning network and its funds can only be accessed using the Funds
37
- * Recovery flow. *
36
+ * It is not connected to the Lightning network and its funds can only be accessed using the
37
+ * Funds Recovery flow. *
38
38
  */
39
39
  TERMINATED = "TERMINATED",
40
40
  }
@@ -1,6 +1,6 @@
1
1
  // Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
2
2
 
3
- import { type Query } from "@lightsparkdev/core";
3
+ import { isObject, type Query } from "@lightsparkdev/core";
4
4
  import type CurrencyAmount from "./CurrencyAmount.js";
5
5
  import {
6
6
  CurrencyAmountFromJson,
@@ -155,7 +155,10 @@ query GetWithdrawal($id: ID!) {
155
155
  ${FRAGMENT}
156
156
  `,
157
157
  variables: { id },
158
- constructObject: (data: any) => WithdrawalFromJson(data.entity),
158
+ constructObject: (data: unknown) =>
159
+ isObject(data) && "entity" in data && isObject(data.entity)
160
+ ? WithdrawalFromJson(data.entity)
161
+ : null,
159
162
  };
160
163
  };
161
164
 
@@ -1,6 +1,6 @@
1
1
  // Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
2
2
 
3
- import { type Query } from "@lightsparkdev/core";
3
+ import { isObject, 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";
@@ -294,7 +294,10 @@ query GetWithdrawalRequest($id: ID!) {
294
294
  ${FRAGMENT}
295
295
  `,
296
296
  variables: { id },
297
- constructObject: (data: any) => WithdrawalRequestFromJson(data.entity),
297
+ constructObject: (data: unknown) =>
298
+ isObject(data) && "entity" in data && isObject(data.entity)
299
+ ? WithdrawalRequestFromJson(data.entity)
300
+ : null,
298
301
  };
299
302
  }
300
303
 
@@ -0,0 +1,93 @@
1
+ import { getHopQuery } from "../objects/Hop.js";
2
+ import {
3
+ InvoiceDataFromJson,
4
+ InvoiceDataToJson,
5
+ } from "../objects/InvoiceData.js";
6
+
7
+ describe("Serialization", () => {
8
+ test("should serialize and deserialize InvoiceData to the same object", () => {
9
+ const serialized = `{"__typename": "InvoiceData", "invoice_data_encoded_payment_request":"lnbcrt34170n1pj5vdn4pp56jhw0672v566u4rvl333v8hwwuvavvu9gx4a2mqag4pkrvm0hwkqhp5xaz278y6cejcvpqnndl4wfq3slgthjduwlfksg778aevn23v2pdscqzpgxqyz5vqsp5ee5jezfvjqvvz7hfwta3ekk8hs6dq36szkgp40qh7twa8upquxlq9qyyssqjg2slc95falxf2t67y0wu2w43qwfcvfflwl8tn4ppqw9tumwqxk36qkfct9p2w8c3yy2ld7c6nacy4ssv2gl6qyqfpmhl4jmarnjf8cpvjlxek","invoice_data_bitcoin_network":"REGTEST","invoice_data_payment_hash":"d4aee7ebca6535ae546cfc63161eee7719d6338541abd56c1d454361b36fbbac","invoice_data_amount":{"currency_amount_original_value":3417,"currency_amount_original_unit":"SATOSHI","currency_amount_preferred_currency_unit":"USD","currency_amount_preferred_currency_value_rounded":118,"currency_amount_preferred_currency_value_approx":118.89352818371607},"invoice_data_created_at":"2023-11-04T12:17:57Z","invoice_data_expires_at":"2023-11-05T12:17:57Z","invoice_data_memo":null,"invoice_data_destination":{"graph_node_id":"GraphNode:0189a572-6dba-cf00-0000-ac0908d34ea6","graph_node_created_at":"2023-07-30T06:18:07.162759Z","graph_node_updated_at":"2023-11-04T12:01:04.015414Z","graph_node_alias":"ls_test_vSViIQitob_SE","graph_node_bitcoin_network":"REGTEST","graph_node_color":"#3399ff","graph_node_conductivity":null,"graph_node_display_name":"ls_test_vSViIQitob_SE","graph_node_public_key":"02253935a5703a6f0429081e08d2defce0faa15f4d75305302284751d53a4e0608", "__typename":"GraphNode"}}`;
10
+ const deserialized = InvoiceDataFromJson(JSON.parse(serialized));
11
+ const reserialized = InvoiceDataToJson(deserialized) as Record<
12
+ string,
13
+ unknown
14
+ >;
15
+ expect(reserialized).toEqual(JSON.parse(serialized));
16
+
17
+ const deserializedAgain = InvoiceDataFromJson(reserialized);
18
+ expect(JSON.stringify(deserializedAgain)).toEqual(
19
+ JSON.stringify(deserialized),
20
+ );
21
+ });
22
+ });
23
+
24
+ describe("Get entity query functions", () => {
25
+ test("constructObject should return null when data is not an object", () => {
26
+ const query = getHopQuery("something");
27
+ expect(query.constructObject(null)).toBeNull();
28
+ expect(query.constructObject(undefined)).toBeNull();
29
+ expect(query.constructObject("string")).toBeNull();
30
+ expect(query.constructObject(123)).toBeNull();
31
+ expect(query.constructObject(true)).toBeNull();
32
+ });
33
+ test("constructObject should return null when data.{path} is not an object", () => {
34
+ const query = getHopQuery("something");
35
+ expect(query.constructObject({ entity: null })).toBeNull();
36
+ expect(query.constructObject({ entity: undefined })).toBeNull();
37
+ expect(query.constructObject({ entity: "string" })).toBeNull();
38
+ expect(query.constructObject({ entity: 123 })).toBeNull();
39
+ expect(query.constructObject({ entity: true })).toBeNull();
40
+ });
41
+ test("constructObject should return the object when data.{path} is an object", () => {
42
+ const query = getHopQuery("something");
43
+ const data = {
44
+ entity: {
45
+ hop_id: "123",
46
+ hop_created_at: "2023-11-04T12:17:57Z",
47
+ hop_updated_at: "2023-11-04T12:17:57Z",
48
+ hop_index: 1,
49
+ hop_destination: { id: "destination" },
50
+ hop_public_key: "public_key",
51
+ hop_amount_to_forward: {
52
+ currency_amount_original_value: 3417,
53
+ currency_amount_original_unit: "SATOSHI",
54
+ currency_amount_preferred_currency_unit: "USD",
55
+ currency_amount_preferred_currency_value_rounded: 118,
56
+ currency_amount_preferred_currency_value_approx: 118.89352818371607,
57
+ },
58
+ hop_fee: {
59
+ currency_amount_original_value: 3417,
60
+ currency_amount_original_unit: "SATOSHI",
61
+ currency_amount_preferred_currency_unit: "USD",
62
+ currency_amount_preferred_currency_value_rounded: 118,
63
+ currency_amount_preferred_currency_value_approx: 118.89352818371607,
64
+ },
65
+ hop_expiry_block_height: 123,
66
+ },
67
+ };
68
+ expect(query.constructObject(data)).toEqual({
69
+ id: "123",
70
+ createdAt: "2023-11-04T12:17:57Z",
71
+ updatedAt: "2023-11-04T12:17:57Z",
72
+ index: 1,
73
+ typename: "Hop",
74
+ destinationId: "destination",
75
+ publicKey: "public_key",
76
+ amountToForward: {
77
+ originalValue: 3417,
78
+ originalUnit: "SATOSHI",
79
+ preferredCurrencyUnit: "USD",
80
+ preferredCurrencyValueRounded: 118,
81
+ preferredCurrencyValueApprox: 118.89352818371607,
82
+ },
83
+ fee: {
84
+ originalValue: 3417,
85
+ originalUnit: "SATOSHI",
86
+ preferredCurrencyUnit: "USD",
87
+ preferredCurrencyValueRounded: 118,
88
+ preferredCurrencyValueApprox: 118.89352818371607,
89
+ },
90
+ expiryBlockHeight: 123,
91
+ });
92
+ });
93
+ });
@@ -1,21 +0,0 @@
1
- import {
2
- InvoiceDataFromJson,
3
- InvoiceDataToJson,
4
- } from "../objects/InvoiceData.js";
5
-
6
- describe("Serialization", () => {
7
- test("should serialize and deserialize InvoiceData to the same object", () => {
8
- const serialized = `{"__typename": "InvoiceData", "invoice_data_encoded_payment_request":"lnbcrt34170n1pj5vdn4pp56jhw0672v566u4rvl333v8hwwuvavvu9gx4a2mqag4pkrvm0hwkqhp5xaz278y6cejcvpqnndl4wfq3slgthjduwlfksg778aevn23v2pdscqzpgxqyz5vqsp5ee5jezfvjqvvz7hfwta3ekk8hs6dq36szkgp40qh7twa8upquxlq9qyyssqjg2slc95falxf2t67y0wu2w43qwfcvfflwl8tn4ppqw9tumwqxk36qkfct9p2w8c3yy2ld7c6nacy4ssv2gl6qyqfpmhl4jmarnjf8cpvjlxek","invoice_data_bitcoin_network":"REGTEST","invoice_data_payment_hash":"d4aee7ebca6535ae546cfc63161eee7719d6338541abd56c1d454361b36fbbac","invoice_data_amount":{"currency_amount_original_value":3417,"currency_amount_original_unit":"SATOSHI","currency_amount_preferred_currency_unit":"USD","currency_amount_preferred_currency_value_rounded":118,"currency_amount_preferred_currency_value_approx":118.89352818371607},"invoice_data_created_at":"2023-11-04T12:17:57Z","invoice_data_expires_at":"2023-11-05T12:17:57Z","invoice_data_memo":null,"invoice_data_destination":{"graph_node_id":"GraphNode:0189a572-6dba-cf00-0000-ac0908d34ea6","graph_node_created_at":"2023-07-30T06:18:07.162759Z","graph_node_updated_at":"2023-11-04T12:01:04.015414Z","graph_node_alias":"ls_test_vSViIQitob_SE","graph_node_bitcoin_network":"REGTEST","graph_node_color":"#3399ff","graph_node_conductivity":null,"graph_node_display_name":"ls_test_vSViIQitob_SE","graph_node_public_key":"02253935a5703a6f0429081e08d2defce0faa15f4d75305302284751d53a4e0608", "__typename":"GraphNode"}}`;
9
- const deserialized = InvoiceDataFromJson(JSON.parse(serialized));
10
- const reserialized = InvoiceDataToJson(deserialized) as Record<
11
- string,
12
- unknown
13
- >;
14
- expect(reserialized).toEqual(JSON.parse(serialized));
15
-
16
- const deserializedAgain = InvoiceDataFromJson(reserialized);
17
- expect(JSON.stringify(deserializedAgain)).toEqual(
18
- JSON.stringify(deserialized),
19
- );
20
- });
21
- });