@profullstack/coinpay 0.6.11 → 0.9.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.
- package/CHANGELOG.md +39 -0
- package/README.md +189 -0
- package/bin/coinpay.js +1869 -93
- package/package.json +41 -9
- package/src/auth.js +2 -1
- package/src/card-payments.js +23 -14
- package/src/client.d.ts +52 -0
- package/src/client.js +93 -9
- package/src/finances-tui.js +1005 -0
- package/src/finances.d.ts +333 -0
- package/src/finances.js +445 -0
- package/src/index.d.ts +37 -1
- package/src/index.js +67 -0
- package/src/invoices.d.ts +78 -0
- package/src/invoices.js +250 -0
- package/src/lightning.js +8 -3
- package/src/swap.js +36 -5
- package/src/taskmarket.js +329 -0
- package/src/tokens.d.ts +14 -0
- package/src/tokens.js +34 -0
- package/src/wallet.d.ts +11 -0
- package/src/wallet.js +283 -25
- package/src/webhooks.js +37 -3
- package/src/x402-browser.js +318 -0
- package/src/x402-pay-server.js +272 -0
- package/src/x402-v2.js +416 -0
- package/src/x402.js +164 -19
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
import type { CoinPayClient } from './client.js';
|
|
2
|
+
|
|
3
|
+
export type AccountKind = 'checking' | 'savings' | 'credit' | 'investment' | 'loan' | 'other' | string;
|
|
4
|
+
|
|
5
|
+
export interface FinanceAccount {
|
|
6
|
+
id: string;
|
|
7
|
+
connection_id: string;
|
|
8
|
+
external_id: string;
|
|
9
|
+
org_name: string | null;
|
|
10
|
+
org_domain: string | null;
|
|
11
|
+
name: string;
|
|
12
|
+
currency: string;
|
|
13
|
+
balance: number | null;
|
|
14
|
+
available_balance: number | null;
|
|
15
|
+
balance_date: string | null;
|
|
16
|
+
kind: AccountKind;
|
|
17
|
+
kind_override: string | null;
|
|
18
|
+
is_hidden: boolean;
|
|
19
|
+
last_seen_at: string;
|
|
20
|
+
effective_kind: AccountKind;
|
|
21
|
+
is_liability: boolean;
|
|
22
|
+
display_balance: number | null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface FinanceTransaction {
|
|
26
|
+
id: string;
|
|
27
|
+
account_id: string;
|
|
28
|
+
posted: string;
|
|
29
|
+
transacted_at: string | null;
|
|
30
|
+
amount: number;
|
|
31
|
+
description: string | null;
|
|
32
|
+
payee: string | null;
|
|
33
|
+
memo: string | null;
|
|
34
|
+
mcc: string | null;
|
|
35
|
+
pending: boolean;
|
|
36
|
+
category: string | null;
|
|
37
|
+
account_name: string;
|
|
38
|
+
org_name: string | null;
|
|
39
|
+
currency: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface FinanceTransactionPage {
|
|
43
|
+
rows: FinanceTransaction[];
|
|
44
|
+
total: number;
|
|
45
|
+
limit: number;
|
|
46
|
+
offset: number;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface FinanceConnection {
|
|
50
|
+
id: string;
|
|
51
|
+
provider: 'simplefin' | 'plaid' | string;
|
|
52
|
+
label: string | null;
|
|
53
|
+
is_active: boolean;
|
|
54
|
+
created_at: string;
|
|
55
|
+
last_synced_at: string | null;
|
|
56
|
+
last_sync_status: 'ok' | 'partial' | 'error' | string | null;
|
|
57
|
+
last_sync_error: string | null;
|
|
58
|
+
last_sync_accounts: number | null;
|
|
59
|
+
last_sync_transactions: number | null;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface FinanceSummary {
|
|
63
|
+
windowDays: number;
|
|
64
|
+
totals: Array<{ currency: string; assets: number; liabilities: number; net: number; accounts: number }>;
|
|
65
|
+
primaryCurrency: string | null;
|
|
66
|
+
byKind: Array<{ kind: AccountKind; currency: string; total: number; accounts: number }>;
|
|
67
|
+
byInstitution: Array<{ org: string; currency: string; assets: number; liabilities: number; accounts: number }>;
|
|
68
|
+
cashflow: { currency: string | null; moneyIn: number; moneyOut: number; net: number; transactions: number };
|
|
69
|
+
topCategories: Array<{ category: string | null; spent: number; received: number; count: number }>;
|
|
70
|
+
accountCount: number;
|
|
71
|
+
hiddenCount: number;
|
|
72
|
+
transactionCount: number;
|
|
73
|
+
oldestTransaction: string | null;
|
|
74
|
+
newestTransaction: string | null;
|
|
75
|
+
/** Debt against income, over a longer window than `windowDays`. */
|
|
76
|
+
position: FinancePosition;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export interface FinanceSeriesPoint {
|
|
80
|
+
label: string;
|
|
81
|
+
volumeUsd: number;
|
|
82
|
+
cryptoUsd: number;
|
|
83
|
+
cardUsd: number;
|
|
84
|
+
commissionUsd: number;
|
|
85
|
+
count: number;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export type AccountScope = 'business' | 'personal';
|
|
89
|
+
export type RecurrenceCadence = 'weekly' | 'biweekly' | 'monthly' | 'quarterly' | 'annual';
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Debt against income for a linked feed. Computed server-side over roughly
|
|
93
|
+
* six months, so it does not move with the dashboard window.
|
|
94
|
+
*
|
|
95
|
+
* Transfers and card payments are excluded from both `income` and `spending`:
|
|
96
|
+
* a feed holding both a checking account and the card it pays would otherwise
|
|
97
|
+
* count every card payment on both sides. The untouched totals are kept as
|
|
98
|
+
* `grossCredits` / `grossDebits` so the netting is auditable.
|
|
99
|
+
*/
|
|
100
|
+
export interface FinancePosition {
|
|
101
|
+
currency: string | null;
|
|
102
|
+
/** Days of history that were asked for. */
|
|
103
|
+
lookbackDays: number;
|
|
104
|
+
/** Days of history that exist, capped at `lookbackDays`. Divides the averages. */
|
|
105
|
+
observedDays: number;
|
|
106
|
+
monthsObserved: number;
|
|
107
|
+
months: Array<{
|
|
108
|
+
month: string;
|
|
109
|
+
income: number;
|
|
110
|
+
spending: number;
|
|
111
|
+
net: number;
|
|
112
|
+
debtService: number;
|
|
113
|
+
transactions: number;
|
|
114
|
+
partial: boolean;
|
|
115
|
+
}>;
|
|
116
|
+
income: { total: number; perMonth: number; grossCredits: number; transactions: number };
|
|
117
|
+
spending: { total: number; perMonth: number; grossDebits: number; refunds: number; transactions: number };
|
|
118
|
+
net: { total: number; perMonth: number; savingsRate: number | null };
|
|
119
|
+
debt: {
|
|
120
|
+
total: number;
|
|
121
|
+
revolving: number;
|
|
122
|
+
instalment: number;
|
|
123
|
+
accounts: Array<{
|
|
124
|
+
id: string;
|
|
125
|
+
name: string;
|
|
126
|
+
org: string | null;
|
|
127
|
+
kind: string;
|
|
128
|
+
scope: AccountScope;
|
|
129
|
+
owed: number;
|
|
130
|
+
share: number;
|
|
131
|
+
paid: number;
|
|
132
|
+
payoffMonths: number | null;
|
|
133
|
+
}>;
|
|
134
|
+
servicePerMonth: number;
|
|
135
|
+
payoffMonths: number | null;
|
|
136
|
+
payoffDate: string | null;
|
|
137
|
+
};
|
|
138
|
+
ratios: {
|
|
139
|
+
debtToIncome: number | null;
|
|
140
|
+
debtServiceRatio: number | null;
|
|
141
|
+
monthsOfCover: number | null;
|
|
142
|
+
creditUtilisation: number | null;
|
|
143
|
+
};
|
|
144
|
+
recurring: {
|
|
145
|
+
charges: Array<{
|
|
146
|
+
payee: string;
|
|
147
|
+
amount: number;
|
|
148
|
+
cadence: RecurrenceCadence;
|
|
149
|
+
occurrences: number;
|
|
150
|
+
lastSeen: string;
|
|
151
|
+
nextExpected: string;
|
|
152
|
+
monthlyEquivalent: number;
|
|
153
|
+
scope: AccountScope;
|
|
154
|
+
isDebtService: boolean;
|
|
155
|
+
}>;
|
|
156
|
+
monthlyTotal: number;
|
|
157
|
+
monthlyDebtService: number;
|
|
158
|
+
};
|
|
159
|
+
scopes: Array<{
|
|
160
|
+
scope: AccountScope;
|
|
161
|
+
accounts: number;
|
|
162
|
+
assets: number;
|
|
163
|
+
debt: number;
|
|
164
|
+
income: number;
|
|
165
|
+
spending: number;
|
|
166
|
+
net: number;
|
|
167
|
+
}>;
|
|
168
|
+
confidence: { uncategorisedShare: number; transactions: number; noLiabilityAccounts: boolean };
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export interface FinanceSnapshot {
|
|
172
|
+
generatedAt: string;
|
|
173
|
+
windowDays: number;
|
|
174
|
+
plan: { id: string; commission_rate: number; commission_percent: string } | null;
|
|
175
|
+
businesses: Array<{ id: string; name: string }>;
|
|
176
|
+
earnings: {
|
|
177
|
+
grossVolumeUsd: number;
|
|
178
|
+
cryptoVolumeUsd: number;
|
|
179
|
+
cardVolumeUsd: number;
|
|
180
|
+
commissionUsd: number;
|
|
181
|
+
stripeFeesUsd: number;
|
|
182
|
+
refundsUsd: number;
|
|
183
|
+
netUsd: number;
|
|
184
|
+
transactions: number;
|
|
185
|
+
failed: number;
|
|
186
|
+
failureRate: number;
|
|
187
|
+
};
|
|
188
|
+
series: FinanceSeriesPoint[];
|
|
189
|
+
crypto: {
|
|
190
|
+
volumeUsd: number;
|
|
191
|
+
feesUsd: number;
|
|
192
|
+
successful: number;
|
|
193
|
+
failed: number;
|
|
194
|
+
pending: number;
|
|
195
|
+
total: number;
|
|
196
|
+
byChain: Record<string, number>;
|
|
197
|
+
partial: boolean;
|
|
198
|
+
};
|
|
199
|
+
card: {
|
|
200
|
+
volumeUsd: number;
|
|
201
|
+
platformFeesUsd: number;
|
|
202
|
+
stripeFeesUsd: number;
|
|
203
|
+
netUsd: number;
|
|
204
|
+
refundedUsd: number;
|
|
205
|
+
successful: number;
|
|
206
|
+
failed: number;
|
|
207
|
+
refunded: number;
|
|
208
|
+
total: number;
|
|
209
|
+
partial: boolean;
|
|
210
|
+
};
|
|
211
|
+
escrow: {
|
|
212
|
+
heldUsd: number;
|
|
213
|
+
held: number;
|
|
214
|
+
releasedUsd: number;
|
|
215
|
+
released: number;
|
|
216
|
+
refundedUsd: number;
|
|
217
|
+
refunded: number;
|
|
218
|
+
feesUsd: number;
|
|
219
|
+
total: number;
|
|
220
|
+
};
|
|
221
|
+
invoices: {
|
|
222
|
+
totals: Record<'draft' | 'outstanding' | 'overdue' | 'paid' | 'cancelled', number>;
|
|
223
|
+
counts: Record<'draft' | 'outstanding' | 'overdue' | 'paid' | 'cancelled', number>;
|
|
224
|
+
rows: Array<Record<string, unknown>>;
|
|
225
|
+
};
|
|
226
|
+
payout: { paidUsd: number; pendingUsd: number; count: number };
|
|
227
|
+
bank: {
|
|
228
|
+
currency: string;
|
|
229
|
+
assets: number;
|
|
230
|
+
liabilities: number;
|
|
231
|
+
net: number;
|
|
232
|
+
accountCount: number;
|
|
233
|
+
hiddenCount: number;
|
|
234
|
+
transactionCount: number;
|
|
235
|
+
cashflow: { moneyIn: number; moneyOut: number; net: number; transactions: number };
|
|
236
|
+
byKind: FinanceSummary['byKind'];
|
|
237
|
+
byInstitution: FinanceSummary['byInstitution'];
|
|
238
|
+
topCategories: FinanceSummary['topCategories'];
|
|
239
|
+
newestTransaction: string | null;
|
|
240
|
+
accounts: FinanceAccount[];
|
|
241
|
+
creditCards: FinanceAccount[];
|
|
242
|
+
connections: FinanceConnection[];
|
|
243
|
+
plaidEnabled: boolean;
|
|
244
|
+
ledger: FinanceTransaction[];
|
|
245
|
+
ledgerTotal: number;
|
|
246
|
+
};
|
|
247
|
+
/** Null when the summary source failed; the screen says so rather than showing zeros. */
|
|
248
|
+
position: FinancePosition | null;
|
|
249
|
+
recent: {
|
|
250
|
+
payments: Array<Record<string, unknown>>;
|
|
251
|
+
cards: Array<Record<string, unknown>>;
|
|
252
|
+
escrows: Array<Record<string, unknown>>;
|
|
253
|
+
};
|
|
254
|
+
errors: Record<string, string>;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
export interface FinanceSnapshotOptions {
|
|
258
|
+
/** Window in days for cashflow, earnings and the daily series. Default 30. */
|
|
259
|
+
days?: number;
|
|
260
|
+
/** Rows per list (payments, card charges, ledger). Default 100. */
|
|
261
|
+
limit?: number;
|
|
262
|
+
/** Narrow payments and analytics to one business. */
|
|
263
|
+
businessId?: string;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
export type PaymentStreamEvent =
|
|
267
|
+
| { type: 'connected' | 'heartbeat'; timestamp: string }
|
|
268
|
+
| {
|
|
269
|
+
type: 'payment_created' | 'payment_updated' | 'payment_completed' | 'payment_expired';
|
|
270
|
+
timestamp: string;
|
|
271
|
+
payment: {
|
|
272
|
+
id: string;
|
|
273
|
+
status: string;
|
|
274
|
+
amount_crypto: string;
|
|
275
|
+
amount_usd: string;
|
|
276
|
+
currency: string;
|
|
277
|
+
payment_address: string;
|
|
278
|
+
confirmations?: number;
|
|
279
|
+
required_confirmations?: number;
|
|
280
|
+
tx_hash?: string;
|
|
281
|
+
created_at: string;
|
|
282
|
+
updated_at: string;
|
|
283
|
+
};
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
export type PaymentStreamStatus = 'connecting' | 'connected' | 'disconnected' | 'error' | 'closed';
|
|
287
|
+
|
|
288
|
+
export function periodForDays(days: number): '7d' | '30d' | '90d' | '1y' | 'all';
|
|
289
|
+
export function cryptoFeeUsd(payment: Record<string, unknown>): number;
|
|
290
|
+
|
|
291
|
+
export function getFinanceSummary(client: CoinPayClient, options?: { days?: number; includeHidden?: boolean }): Promise<FinanceSummary>;
|
|
292
|
+
export function listFinanceAccounts(client: CoinPayClient, options?: { includeHidden?: boolean }): Promise<FinanceAccount[]>;
|
|
293
|
+
export function listFinanceTransactions(
|
|
294
|
+
client: CoinPayClient,
|
|
295
|
+
filters?: {
|
|
296
|
+
accountId?: string;
|
|
297
|
+
search?: string;
|
|
298
|
+
category?: string;
|
|
299
|
+
startDate?: string;
|
|
300
|
+
endDate?: string;
|
|
301
|
+
includePending?: boolean;
|
|
302
|
+
limit?: number;
|
|
303
|
+
offset?: number;
|
|
304
|
+
},
|
|
305
|
+
): Promise<FinanceTransactionPage>;
|
|
306
|
+
export function listFinanceConnections(client: CoinPayClient): Promise<{ connections: FinanceConnection[]; plaidEnabled: boolean }>;
|
|
307
|
+
export function syncFinances(client: CoinPayClient, options?: { days?: number; connectionId?: string }): Promise<{
|
|
308
|
+
results: Array<Record<string, unknown>>;
|
|
309
|
+
totals: { accounts: number; transactionsSeen: number; transactionsNew: number };
|
|
310
|
+
status: 'ok' | 'partial';
|
|
311
|
+
}>;
|
|
312
|
+
export function getDashboardStats(client: CoinPayClient, options?: { businessId?: string }): Promise<Record<string, unknown>>;
|
|
313
|
+
export function getFinanceAnalytics(client: CoinPayClient, options?: { period?: string; businessId?: string }): Promise<Record<string, unknown>>;
|
|
314
|
+
export function listCryptoPayments(
|
|
315
|
+
client: CoinPayClient,
|
|
316
|
+
options?: { limit?: number; offset?: number; status?: string; businessId?: string; dateFrom?: string; dateTo?: string },
|
|
317
|
+
): Promise<Record<string, unknown>>;
|
|
318
|
+
export function listCardTransactions(
|
|
319
|
+
client: CoinPayClient,
|
|
320
|
+
options?: { limit?: number; offset?: number; status?: string; businessId?: string; dateFrom?: string; dateTo?: string },
|
|
321
|
+
): Promise<Record<string, unknown>>;
|
|
322
|
+
export function listCardPayouts(client: CoinPayClient, options?: { limit?: number; offset?: number; status?: string }): Promise<Record<string, unknown>>;
|
|
323
|
+
|
|
324
|
+
export function buildFinanceSnapshot(raw?: Record<string, unknown>, options?: { days?: number; now?: Date }): FinanceSnapshot;
|
|
325
|
+
export function collectFinanceSnapshot(client: CoinPayClient, options?: FinanceSnapshotOptions): Promise<FinanceSnapshot>;
|
|
326
|
+
|
|
327
|
+
export function subscribeToPayments(options: {
|
|
328
|
+
baseUrl: string;
|
|
329
|
+
token: string;
|
|
330
|
+
businessId?: string;
|
|
331
|
+
onEvent?: (event: PaymentStreamEvent) => void;
|
|
332
|
+
onStatus?: (status: PaymentStreamStatus, detail?: string) => void;
|
|
333
|
+
}): () => void;
|