@lightsparkdev/lightspark-sdk 0.2.1 → 0.2.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @lightsparkdev/lightspark-sdk
2
2
 
3
+ ## 0.2.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Add bindings to lightspark-sdk for managing connected wallets.
8
+
3
9
  ## 0.2.1
4
10
 
5
11
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightsparkdev/lightspark-sdk",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "Lightspark JS SDK",
5
5
  "author": "Lightspark Inc.",
6
6
  "keywords": [
@@ -18,6 +18,9 @@ import AccountToPaymentRequestsConnection, {
18
18
  import AccountToTransactionsConnection, {
19
19
  AccountToTransactionsConnectionFromJson,
20
20
  } from "./AccountToTransactionsConnection.js";
21
+ import AccountToWalletsConnection, {
22
+ AccountToWalletsConnectionFromJson,
23
+ } from "./AccountToWalletsConnection.js";
21
24
  import BitcoinNetwork from "./BitcoinNetwork.js";
22
25
  import BlockchainBalance, {
23
26
  BlockchainBalanceFromJson,
@@ -1181,6 +1184,73 @@ query FetchAccountToPaymentRequestsConnection($first: Int, $after: String, $afte
1181
1184
  }))!;
1182
1185
  }
1183
1186
 
1187
+ public async getWallets(
1188
+ client: LightsparkClient,
1189
+ first: number | undefined = undefined
1190
+ ): Promise<AccountToWalletsConnection> {
1191
+ return (await client.executeRawQuery({
1192
+ queryPayload: `
1193
+ query FetchAccountToWalletsConnection($first: Int) {
1194
+ current_account {
1195
+ ... on Account {
1196
+ wallets(, first: $first) {
1197
+ __typename
1198
+ account_to_wallets_connection_page_info: page_info {
1199
+ __typename
1200
+ page_info_has_next_page: has_next_page
1201
+ page_info_has_previous_page: has_previous_page
1202
+ page_info_start_cursor: start_cursor
1203
+ page_info_end_cursor: end_cursor
1204
+ }
1205
+ account_to_wallets_connection_count: count
1206
+ account_to_wallets_connection_entities: entities {
1207
+ __typename
1208
+ wallet_id: id
1209
+ wallet_created_at: created_at
1210
+ wallet_updated_at: updated_at
1211
+ wallet_last_login_at: last_login_at
1212
+ wallet_balances: balances {
1213
+ __typename
1214
+ balances_owned_balance: owned_balance {
1215
+ __typename
1216
+ currency_amount_original_value: original_value
1217
+ currency_amount_original_unit: original_unit
1218
+ currency_amount_preferred_currency_unit: preferred_currency_unit
1219
+ currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1220
+ currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1221
+ }
1222
+ balances_available_to_send_balance: available_to_send_balance {
1223
+ __typename
1224
+ currency_amount_original_value: original_value
1225
+ currency_amount_original_unit: original_unit
1226
+ currency_amount_preferred_currency_unit: preferred_currency_unit
1227
+ currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1228
+ currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1229
+ }
1230
+ balances_available_to_withdraw_balance: available_to_withdraw_balance {
1231
+ __typename
1232
+ currency_amount_original_value: original_value
1233
+ currency_amount_original_unit: original_unit
1234
+ currency_amount_preferred_currency_unit: preferred_currency_unit
1235
+ currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1236
+ currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1237
+ }
1238
+ }
1239
+ wallet_third_party_identifier: third_party_identifier
1240
+ }
1241
+ }
1242
+ }
1243
+ }
1244
+ }
1245
+ `,
1246
+ variables: { first: first },
1247
+ constructObject: (json) => {
1248
+ const connection = json["current_account"]["wallets"];
1249
+ return AccountToWalletsConnectionFromJson(connection);
1250
+ },
1251
+ }))!;
1252
+ }
1253
+
1184
1254
  static getAccountQuery(): Query<Account> {
1185
1255
  return {
1186
1256
  queryPayload: `
@@ -0,0 +1,48 @@
1
+ // Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
2
+
3
+ import PageInfo, { PageInfoFromJson } from "./PageInfo.js";
4
+ import Wallet, { WalletFromJson } from "./Wallet.js";
5
+
6
+ type AccountToWalletsConnection = {
7
+ /** An object that holds pagination information about the objects in this connection. **/
8
+ pageInfo: PageInfo;
9
+
10
+ /**
11
+ * The total count of objects in this connection, using the current filters. It is different from the
12
+ * number of objects returned in the current page (in the `entities` field).
13
+ **/
14
+ count: number;
15
+
16
+ /** The wallets for the current page of this connection. **/
17
+ entities: Wallet[];
18
+ };
19
+
20
+ export const AccountToWalletsConnectionFromJson = (
21
+ obj: any
22
+ ): AccountToWalletsConnection => {
23
+ return {
24
+ pageInfo: PageInfoFromJson(obj["account_to_wallets_connection_page_info"]),
25
+ count: obj["account_to_wallets_connection_count"],
26
+ entities: obj["account_to_wallets_connection_entities"].map((e) =>
27
+ WalletFromJson(e)
28
+ ),
29
+ } as AccountToWalletsConnection;
30
+ };
31
+
32
+ export const FRAGMENT = `
33
+ fragment AccountToWalletsConnectionFragment on AccountToWalletsConnection {
34
+ __typename
35
+ account_to_wallets_connection_page_info: page_info {
36
+ __typename
37
+ page_info_has_next_page: has_next_page
38
+ page_info_has_previous_page: has_previous_page
39
+ page_info_start_cursor: start_cursor
40
+ page_info_end_cursor: end_cursor
41
+ }
42
+ account_to_wallets_connection_count: count
43
+ account_to_wallets_connection_entities: entities {
44
+ id
45
+ }
46
+ }`;
47
+
48
+ export default AccountToWalletsConnection;
@@ -0,0 +1,71 @@
1
+ // Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
2
+
3
+ import CurrencyAmount, { CurrencyAmountFromJson } from "./CurrencyAmount.js";
4
+
5
+ type Balances = {
6
+ /**
7
+ * This represents the balance that should be displayed when asked "how much do I own right now?". It
8
+ * represents the amount currently owned, including things that may not be owned soon (e.g. in-flight
9
+ * outgoing payments, in-flight withdrawals, commit fees, etc.). It really is a snapshot of what is
10
+ * officially owned at this instant.
11
+ **/
12
+ ownedBalance: CurrencyAmount;
13
+
14
+ /**
15
+ * This represents the balance that should be displayed when asked "how much can I send on Lightning
16
+ * right now?". It represents the amount currently available to be sent on the Lightning network. We
17
+ * remove from the balance all the funds that are temporarily locked (e.g. channel reserves).
18
+ **/
19
+ availableToSendBalance: CurrencyAmount;
20
+
21
+ /**
22
+ * This represents the balance that should be displayed when asked "how much money can I withdraw on
23
+ * the Bitcoin network right now?". It represents the amount currently available to withdraw and is
24
+ * usually equal to the `owned_balance` but it does not include in-flight operations (which would
25
+ * likely succeed and therefore likely make your withdrawal fail).
26
+ **/
27
+ availableToWithdrawBalance: CurrencyAmount;
28
+ };
29
+
30
+ export const BalancesFromJson = (obj: any): Balances => {
31
+ return {
32
+ ownedBalance: CurrencyAmountFromJson(obj["balances_owned_balance"]),
33
+ availableToSendBalance: CurrencyAmountFromJson(
34
+ obj["balances_available_to_send_balance"]
35
+ ),
36
+ availableToWithdrawBalance: CurrencyAmountFromJson(
37
+ obj["balances_available_to_withdraw_balance"]
38
+ ),
39
+ } as Balances;
40
+ };
41
+
42
+ export const FRAGMENT = `
43
+ fragment BalancesFragment on Balances {
44
+ __typename
45
+ balances_owned_balance: owned_balance {
46
+ __typename
47
+ currency_amount_original_value: original_value
48
+ currency_amount_original_unit: original_unit
49
+ currency_amount_preferred_currency_unit: preferred_currency_unit
50
+ currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
51
+ currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
52
+ }
53
+ balances_available_to_send_balance: available_to_send_balance {
54
+ __typename
55
+ currency_amount_original_value: original_value
56
+ currency_amount_original_unit: original_unit
57
+ currency_amount_preferred_currency_unit: preferred_currency_unit
58
+ currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
59
+ currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
60
+ }
61
+ balances_available_to_withdraw_balance: available_to_withdraw_balance {
62
+ __typename
63
+ currency_amount_original_value: original_value
64
+ currency_amount_original_unit: original_unit
65
+ currency_amount_preferred_currency_unit: preferred_currency_unit
66
+ currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
67
+ currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
68
+ }
69
+ }`;
70
+
71
+ export default Balances;
@@ -810,6 +810,41 @@ fragment EntityFragment on Entity {
810
810
  }
811
811
  routing_transaction_failure_reason: failure_reason
812
812
  }
813
+ ... on Wallet {
814
+ __typename
815
+ wallet_id: id
816
+ wallet_created_at: created_at
817
+ wallet_updated_at: updated_at
818
+ wallet_last_login_at: last_login_at
819
+ wallet_balances: balances {
820
+ __typename
821
+ balances_owned_balance: owned_balance {
822
+ __typename
823
+ currency_amount_original_value: original_value
824
+ currency_amount_original_unit: original_unit
825
+ currency_amount_preferred_currency_unit: preferred_currency_unit
826
+ currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
827
+ currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
828
+ }
829
+ balances_available_to_send_balance: available_to_send_balance {
830
+ __typename
831
+ currency_amount_original_value: original_value
832
+ currency_amount_original_unit: original_unit
833
+ currency_amount_preferred_currency_unit: preferred_currency_unit
834
+ currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
835
+ currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
836
+ }
837
+ balances_available_to_withdraw_balance: available_to_withdraw_balance {
838
+ __typename
839
+ currency_amount_original_value: original_value
840
+ currency_amount_original_unit: original_unit
841
+ currency_amount_preferred_currency_unit: preferred_currency_unit
842
+ currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
843
+ currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
844
+ }
845
+ }
846
+ wallet_third_party_identifier: third_party_identifier
847
+ }
813
848
  ... on Withdrawal {
814
849
  __typename
815
850
  withdrawal_id: id
@@ -0,0 +1,159 @@
1
+ // Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
2
+
3
+ import { Query } from "@lightsparkdev/core";
4
+ import autoBind from "auto-bind";
5
+ import LightsparkClient from "../client.js";
6
+ import Balances, { BalancesFromJson } from "./Balances.js";
7
+ import CurrencyAmount, { CurrencyAmountFromJson } from "./CurrencyAmount.js";
8
+ import Entity from "./Entity.js";
9
+
10
+ class Wallet implements Entity {
11
+ constructor(
12
+ public readonly id: string,
13
+ public readonly createdAt: string,
14
+ public readonly updatedAt: string,
15
+ public readonly thirdPartyIdentifier: string,
16
+ public readonly typename: string,
17
+ public readonly lastLoginAt?: string,
18
+ public readonly balances?: Balances
19
+ ) {
20
+ autoBind(this);
21
+ }
22
+
23
+ public async getTotalAmountReceived(
24
+ client: LightsparkClient,
25
+ createdAfterDate: string | undefined = undefined,
26
+ createdBeforeDate: string | undefined = undefined
27
+ ): Promise<CurrencyAmount> {
28
+ return (await client.executeRawQuery({
29
+ queryPayload: `
30
+ query FetchWalletTotalAmountReceived($created_after_date: DateTime, $created_before_date: DateTime) {
31
+ current_wallet {
32
+ ... on Wallet {
33
+ total_amount_received(, created_after_date: $created_after_date, created_before_date: $created_before_date) {
34
+ __typename
35
+ currency_amount_original_value: original_value
36
+ currency_amount_original_unit: original_unit
37
+ currency_amount_preferred_currency_unit: preferred_currency_unit
38
+ currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
39
+ currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
40
+ }
41
+ }
42
+ }
43
+ }
44
+ `,
45
+ variables: {
46
+ created_after_date: createdAfterDate,
47
+ created_before_date: createdBeforeDate,
48
+ },
49
+ constructObject: (json) => {
50
+ const connection = json["current_wallet"]["total_amount_received"];
51
+ return CurrencyAmountFromJson(connection);
52
+ },
53
+ }))!;
54
+ }
55
+
56
+ public async getTotalAmountSent(
57
+ client: LightsparkClient,
58
+ createdAfterDate: string | undefined = undefined,
59
+ createdBeforeDate: string | undefined = undefined
60
+ ): Promise<CurrencyAmount> {
61
+ return (await client.executeRawQuery({
62
+ queryPayload: `
63
+ query FetchWalletTotalAmountSent($created_after_date: DateTime, $created_before_date: DateTime) {
64
+ current_wallet {
65
+ ... on Wallet {
66
+ total_amount_sent(, created_after_date: $created_after_date, created_before_date: $created_before_date) {
67
+ __typename
68
+ currency_amount_original_value: original_value
69
+ currency_amount_original_unit: original_unit
70
+ currency_amount_preferred_currency_unit: preferred_currency_unit
71
+ currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
72
+ currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
73
+ }
74
+ }
75
+ }
76
+ }
77
+ `,
78
+ variables: {
79
+ created_after_date: createdAfterDate,
80
+ created_before_date: createdBeforeDate,
81
+ },
82
+ constructObject: (json) => {
83
+ const connection = json["current_wallet"]["total_amount_sent"];
84
+ return CurrencyAmountFromJson(connection);
85
+ },
86
+ }))!;
87
+ }
88
+
89
+ static getWalletQuery(): Query<Wallet> {
90
+ return {
91
+ queryPayload: `
92
+ query GetWallet {
93
+ current_wallet {
94
+ ... on Wallet {
95
+ ...WalletFragment
96
+ }
97
+ }
98
+ }
99
+
100
+ ${FRAGMENT}
101
+ `,
102
+ variables: {},
103
+ constructObject: (data: any) => WalletFromJson(data.current_wallet),
104
+ };
105
+ }
106
+ }
107
+
108
+ export const WalletFromJson = (obj: any): Wallet => {
109
+ return new Wallet(
110
+ obj["wallet_id"],
111
+ obj["wallet_created_at"],
112
+ obj["wallet_updated_at"],
113
+ obj["wallet_third_party_identifier"],
114
+ "Wallet",
115
+ obj["wallet_last_login_at"],
116
+ !!obj["wallet_balances"]
117
+ ? BalancesFromJson(obj["wallet_balances"])
118
+ : undefined
119
+ );
120
+ };
121
+
122
+ export const FRAGMENT = `
123
+ fragment WalletFragment on Wallet {
124
+ __typename
125
+ wallet_id: id
126
+ wallet_created_at: created_at
127
+ wallet_updated_at: updated_at
128
+ wallet_last_login_at: last_login_at
129
+ wallet_balances: balances {
130
+ __typename
131
+ balances_owned_balance: owned_balance {
132
+ __typename
133
+ currency_amount_original_value: original_value
134
+ currency_amount_original_unit: original_unit
135
+ currency_amount_preferred_currency_unit: preferred_currency_unit
136
+ currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
137
+ currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
138
+ }
139
+ balances_available_to_send_balance: available_to_send_balance {
140
+ __typename
141
+ currency_amount_original_value: original_value
142
+ currency_amount_original_unit: original_unit
143
+ currency_amount_preferred_currency_unit: preferred_currency_unit
144
+ currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
145
+ currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
146
+ }
147
+ balances_available_to_withdraw_balance: available_to_withdraw_balance {
148
+ __typename
149
+ currency_amount_original_value: original_value
150
+ currency_amount_original_unit: original_unit
151
+ currency_amount_preferred_currency_unit: preferred_currency_unit
152
+ currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
153
+ currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
154
+ }
155
+ }
156
+ wallet_third_party_identifier: third_party_identifier
157
+ }`;
158
+
159
+ export default Wallet;
@@ -4,7 +4,9 @@ export { default as AccountToChannelsConnection } from "./AccountToChannelsConne
4
4
  export { default as AccountToNodesConnection } from "./AccountToNodesConnection.js";
5
5
  export { default as AccountToPaymentRequestsConnection } from "./AccountToPaymentRequestsConnection.js";
6
6
  export { default as AccountToTransactionsConnection } from "./AccountToTransactionsConnection.js";
7
+ export { default as AccountToWalletsConnection } from "./AccountToWalletsConnection.js";
7
8
  export { default as ApiToken, getApiTokenQuery } from "./ApiToken.js";
9
+ export { default as Balances } from "./Balances.js";
8
10
  export { default as BitcoinNetwork } from "./BitcoinNetwork.js";
9
11
  export { default as BlockchainBalance } from "./BlockchainBalance.js";
10
12
  export { default as Channel } from "./Channel.js";
@@ -98,6 +100,7 @@ export { default as TransactionFailures } from "./TransactionFailures.js";
98
100
  export { default as TransactionStatus } from "./TransactionStatus.js";
99
101
  export { default as TransactionType } from "./TransactionType.js";
100
102
  export { default as TransactionUpdate } from "./TransactionUpdate.js";
103
+ export { default as Wallet } from "./Wallet.js";
101
104
  export { default as WalletDashboard } from "./WalletDashboard.js";
102
105
  export { default as WebhookEventType } from "./WebhookEventType.js";
103
106
  export { default as Withdrawal, getWithdrawalQuery } from "./Withdrawal.js";