@lightsparkdev/lightspark-sdk 1.8.0 → 1.8.2

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 (48) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/{chunk-J7GJGYME.js → chunk-4KFNQOMH.js} +84 -39
  3. package/dist/{index-9a69ef6a.d.ts → index-27dad75b.d.ts} +22 -1
  4. package/dist/index.cjs +240 -91
  5. package/dist/index.d.cts +2 -2
  6. package/dist/index.d.ts +2 -2
  7. package/dist/index.js +103 -3
  8. package/dist/objects/index.cjs +97 -52
  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 +89 -8
  14. package/src/graphql/IncomingPaymentsForInvoice.ts +21 -0
  15. package/src/graphql/OutgoingPaymentsForInvoice.ts +21 -0
  16. package/src/objects/Account.ts +4 -2
  17. package/src/objects/ApiToken.ts +2 -2
  18. package/src/objects/AuditLogActor.ts +2 -2
  19. package/src/objects/Channel.ts +2 -2
  20. package/src/objects/ChannelClosingTransaction.ts +2 -2
  21. package/src/objects/ChannelOpeningTransaction.ts +2 -2
  22. package/src/objects/ChannelSnapshot.ts +2 -2
  23. package/src/objects/Deposit.ts +2 -2
  24. package/src/objects/GraphNode.ts +2 -2
  25. package/src/objects/Hop.ts +2 -2
  26. package/src/objects/IncomingPayment.ts +2 -2
  27. package/src/objects/IncomingPaymentAttempt.ts +2 -2
  28. package/src/objects/Invoice.ts +2 -2
  29. package/src/objects/LightningTransaction.ts +2 -2
  30. package/src/objects/LightsparkNode.ts +2 -2
  31. package/src/objects/LightsparkNodeOwner.ts +2 -2
  32. package/src/objects/LightsparkNodeWithOSK.ts +2 -2
  33. package/src/objects/LightsparkNodeWithRemoteSigning.ts +2 -2
  34. package/src/objects/Node.ts +2 -2
  35. package/src/objects/OnChainTransaction.ts +2 -2
  36. package/src/objects/OutgoingPayment.ts +2 -2
  37. package/src/objects/OutgoingPaymentAttempt.ts +2 -2
  38. package/src/objects/PaymentRequest.ts +2 -2
  39. package/src/objects/RoutingTransaction.ts +2 -2
  40. package/src/objects/Signable.ts +2 -2
  41. package/src/objects/SignablePayload.ts +2 -2
  42. package/src/objects/Transaction.ts +2 -2
  43. package/src/objects/UmaInvitation.ts +2 -2
  44. package/src/objects/Wallet.ts +2 -2
  45. package/src/objects/Withdrawal.ts +2 -2
  46. package/src/objects/WithdrawalRequest.ts +2 -2
  47. package/src/tests/generated-objects.test.ts +93 -0
  48. 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,
@@ -412,7 +412,7 @@ ${FRAGMENT}
412
412
  `,
413
413
  variables: { id },
414
414
  constructObject: (data: unknown) =>
415
- data && typeof data === "object" && "entity" in data
415
+ isObject(data) && "entity" in data && isObject(data.entity)
416
416
  ? PaymentRequestFromJson(data.entity)
417
417
  : null,
418
418
  };
@@ -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,
@@ -171,7 +171,7 @@ ${FRAGMENT}
171
171
  `,
172
172
  variables: { id },
173
173
  constructObject: (data: unknown) =>
174
- data && typeof data === "object" && "entity" in data
174
+ isObject(data) && "entity" in data && isObject(data.entity)
175
175
  ? RoutingTransactionFromJson(data.entity)
176
176
  : null,
177
177
  };
@@ -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
  /**
@@ -59,7 +59,7 @@ ${FRAGMENT}
59
59
  `,
60
60
  variables: { id },
61
61
  constructObject: (data: unknown) =>
62
- data && typeof data === "object" && "entity" in data
62
+ isObject(data) && "entity" in data && isObject(data.entity)
63
63
  ? SignableFromJson(data.entity)
64
64
  : null,
65
65
  };
@@ -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 {
@@ -103,7 +103,7 @@ ${FRAGMENT}
103
103
  `,
104
104
  variables: { id },
105
105
  constructObject: (data: unknown) =>
106
- data && typeof data === "object" && "entity" in data
106
+ isObject(data) && "entity" in data && isObject(data.entity)
107
107
  ? SignablePayloadFromJson(data.entity)
108
108
  : null,
109
109
  };
@@ -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";
@@ -1004,7 +1004,7 @@ ${FRAGMENT}
1004
1004
  `,
1005
1005
  variables: { id },
1006
1006
  constructObject: (data: unknown) =>
1007
- data && typeof data === "object" && "entity" in data
1007
+ isObject(data) && "entity" in data && isObject(data.entity)
1008
1008
  ? TransactionFromJson(data.entity)
1009
1009
  : null,
1010
1010
  };
@@ -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
 
@@ -107,7 +107,7 @@ ${FRAGMENT}
107
107
  `,
108
108
  variables: { id },
109
109
  constructObject: (data: unknown) =>
110
- data && typeof data === "object" && "entity" in data
110
+ isObject(data) && "entity" in data && isObject(data.entity)
111
111
  ? UmaInvitationFromJson(data.entity)
112
112
  : null,
113
113
  };
@@ -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";
@@ -1182,7 +1182,7 @@ ${FRAGMENT}
1182
1182
  `,
1183
1183
  variables: { id },
1184
1184
  constructObject: (data: unknown) =>
1185
- data && typeof data === "object" && "entity" in data
1185
+ isObject(data) && "entity" in data && isObject(data.entity)
1186
1186
  ? WalletFromJson(data.entity)
1187
1187
  : null,
1188
1188
  };
@@ -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,
@@ -156,7 +156,7 @@ ${FRAGMENT}
156
156
  `,
157
157
  variables: { id },
158
158
  constructObject: (data: unknown) =>
159
- data && typeof data === "object" && "entity" in data
159
+ isObject(data) && "entity" in data && isObject(data.entity)
160
160
  ? WithdrawalFromJson(data.entity)
161
161
  : null,
162
162
  };
@@ -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";
@@ -295,7 +295,7 @@ ${FRAGMENT}
295
295
  `,
296
296
  variables: { id },
297
297
  constructObject: (data: unknown) =>
298
- data && typeof data === "object" && "entity" in data
298
+ isObject(data) && "entity" in data && isObject(data.entity)
299
299
  ? WithdrawalRequestFromJson(data.entity)
300
300
  : null,
301
301
  };
@@ -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
- });