@lightsparkdev/lightspark-sdk 0.2.0 → 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.
@@ -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";