@v3finance/core-sdk 0.11.0 → 0.13.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.
Files changed (69) hide show
  1. package/CHANGELOG.md +49 -0
  2. package/README.md +1 -0
  3. package/dist/cjs/client.d.ts +4 -0
  4. package/dist/cjs/client.d.ts.map +1 -1
  5. package/dist/cjs/client.js +3 -0
  6. package/dist/cjs/client.js.map +1 -1
  7. package/dist/cjs/generated/operations.d.ts +168 -0
  8. package/dist/cjs/generated/operations.d.ts.map +1 -1
  9. package/dist/cjs/generated/operations.js +170 -2
  10. package/dist/cjs/generated/operations.js.map +1 -1
  11. package/dist/cjs/generated/types.d.ts +931 -35
  12. package/dist/cjs/generated/types.d.ts.map +1 -1
  13. package/dist/cjs/index.d.ts +1 -0
  14. package/dist/cjs/index.d.ts.map +1 -1
  15. package/dist/cjs/index.js +4 -1
  16. package/dist/cjs/index.js.map +1 -1
  17. package/dist/cjs/resources/aml.d.ts +1 -1
  18. package/dist/cjs/resources/aml.d.ts.map +1 -1
  19. package/dist/cjs/resources/balances.d.ts +2 -1
  20. package/dist/cjs/resources/balances.d.ts.map +1 -1
  21. package/dist/cjs/resources/balances.js.map +1 -1
  22. package/dist/cjs/resources/payments.d.ts +101 -0
  23. package/dist/cjs/resources/payments.d.ts.map +1 -0
  24. package/dist/cjs/resources/payments.js +120 -0
  25. package/dist/cjs/resources/payments.js.map +1 -0
  26. package/dist/cjs/resources/reports.d.ts +17 -4
  27. package/dist/cjs/resources/reports.d.ts.map +1 -1
  28. package/dist/cjs/resources/reports.js.map +1 -1
  29. package/dist/cjs/version.d.ts +1 -1
  30. package/dist/cjs/version.js +1 -1
  31. package/dist/esm/client.d.ts +4 -0
  32. package/dist/esm/client.d.ts.map +1 -1
  33. package/dist/esm/client.js +3 -0
  34. package/dist/esm/client.js.map +1 -1
  35. package/dist/esm/generated/operations.d.ts +168 -0
  36. package/dist/esm/generated/operations.d.ts.map +1 -1
  37. package/dist/esm/generated/operations.js +170 -2
  38. package/dist/esm/generated/operations.js.map +1 -1
  39. package/dist/esm/generated/types.d.ts +931 -35
  40. package/dist/esm/generated/types.d.ts.map +1 -1
  41. package/dist/esm/index.d.ts +1 -0
  42. package/dist/esm/index.d.ts.map +1 -1
  43. package/dist/esm/index.js +1 -0
  44. package/dist/esm/index.js.map +1 -1
  45. package/dist/esm/resources/aml.d.ts +1 -1
  46. package/dist/esm/resources/aml.d.ts.map +1 -1
  47. package/dist/esm/resources/balances.d.ts +2 -1
  48. package/dist/esm/resources/balances.d.ts.map +1 -1
  49. package/dist/esm/resources/balances.js.map +1 -1
  50. package/dist/esm/resources/payments.d.ts +101 -0
  51. package/dist/esm/resources/payments.d.ts.map +1 -0
  52. package/dist/esm/resources/payments.js +115 -0
  53. package/dist/esm/resources/payments.js.map +1 -0
  54. package/dist/esm/resources/reports.d.ts +17 -4
  55. package/dist/esm/resources/reports.d.ts.map +1 -1
  56. package/dist/esm/resources/reports.js.map +1 -1
  57. package/dist/esm/version.d.ts +1 -1
  58. package/dist/esm/version.js +1 -1
  59. package/docs/errors.md +30 -2
  60. package/package.json +1 -1
  61. package/src/client.ts +6 -0
  62. package/src/generated/operations.ts +170 -2
  63. package/src/generated/types.ts +956 -35
  64. package/src/index.ts +8 -0
  65. package/src/resources/aml.ts +1 -1
  66. package/src/resources/balances.ts +2 -1
  67. package/src/resources/payments.ts +193 -0
  68. package/src/resources/reports.ts +19 -3
  69. package/src/version.ts +1 -1
package/src/index.ts CHANGED
@@ -98,6 +98,14 @@ export {
98
98
  type ListTransferDraftsParams,
99
99
  type TransferDraftStatus,
100
100
  } from './resources/transferDrafts.js'
101
+ export {
102
+ PaymentsResource,
103
+ DealsResource,
104
+ type ListDealsParams,
105
+ type ListPaymentsParams,
106
+ type PaymentFilters,
107
+ type PaymentState,
108
+ } from './resources/payments.js'
101
109
  export {
102
110
  HistoryResource,
103
111
  type HistoryFilters,
@@ -33,7 +33,7 @@ export interface AmlOperationsFilter {
33
33
  type?: 'transfer' | 'deposit' | undefined
34
34
  /** CSV; `unchecked` — operations never checked. */
35
35
  amlLevel?: string | undefined
36
- /** CSV: `held,released,blocked,unblocked`. */
36
+ /** CSV: `held,released,blocked,unblocked,missed`; `missed` — nothing was left to hold. */
37
37
  amlHoldStatus?: string | undefined
38
38
  provider?: 'scorechain' | undefined
39
39
  category?: string | undefined
@@ -13,7 +13,8 @@ import type {
13
13
  /**
14
14
  * What a ledger account is FOR. A strict alias of the generated enum.
15
15
  *
16
- * `available` (spendable) and `reserved` (held for a transfer in flight)
16
+ * `available` (spendable), `reserved` (held for a transfer in flight) and
17
+ * `reserved_payment` (held for an expected payment, one account per payment)
17
18
  * belong to an ADDRESS. `external` and `adjustment` are vault-level: they are
18
19
  * the far side of the double entry — the outside world, and manual
19
20
  * corrections — and belong to no address, which is why
@@ -0,0 +1,193 @@
1
+ import { seg, type HttpClient } from '../core/http.js'
2
+ import type { PageParams } from '../core/pagination.js'
3
+ import type {
4
+ AllocatePaymentBody,
5
+ ClosePaymentBody,
6
+ CreateDealBody,
7
+ CreatePaymentBody,
8
+ Deal,
9
+ DealDetail,
10
+ DealsPage,
11
+ OperationPayments,
12
+ OperationType,
13
+ PatchDealBody,
14
+ PatchPaymentBody,
15
+ Payment,
16
+ PaymentDetail,
17
+ PaymentOperationCandidates,
18
+ PaymentsPage,
19
+ PaymentTotals,
20
+ ReservePaymentBody,
21
+ } from '../generated/types.js'
22
+
23
+ /** Computed from what was allocated; `closed` and `cancelled` are a person's decision. */
24
+ export type PaymentState = Payment['state']
25
+
26
+ export interface PaymentFilters {
27
+ /** `in` — to be received, `out` — to be sent. */
28
+ direction?: Payment['direction'] | undefined
29
+ /** What is still awaited: `['expected', 'partial', 'in_progress']`. Sent as a comma-separated list. */
30
+ state?: readonly PaymentState[] | undefined
31
+ overdue?: boolean | undefined
32
+ dealId?: string | undefined
33
+ counterpartyId?: string | undefined
34
+ /** Our address. */
35
+ addressId?: string | undefined
36
+ categoryId?: string | undefined
37
+ /** Token code, e.g. `usdt`. */
38
+ asset?: string | undefined
39
+ /** Only the ones I created. */
40
+ mine?: boolean | undefined
41
+ /** Due date, inclusive / exclusive. */
42
+ dueFrom?: string | undefined
43
+ dueTo?: string | undefined
44
+ }
45
+
46
+ export interface ListPaymentsParams extends PaymentFilters, PageParams {
47
+ /** `createdAt` (default) — newest first; `dueAt` — the nearest first, undated last. */
48
+ sort?: 'createdAt' | 'dueAt' | undefined
49
+ }
50
+
51
+ /**
52
+ * Expected payments: what is agreed, before any money moves.
53
+ *
54
+ * A payment is a PLAN. It does not touch the balance; its figures (`settled`,
55
+ * `inProgress`, `remaining`) are computed from the operations allocated to
56
+ * it. The one thing that touches money is the reserve: your own funds move
57
+ * from `available` to a reserve that only a transfer of this payment spends.
58
+ *
59
+ * To pay, pass `paymentId` to `transfers.send` or `transferDrafts.create`. The
60
+ * plan grants nothing: policies, AML and signatures apply as to any transfer.
61
+ *
62
+ * Everything here works in a web session; sending and signing do not.
63
+ */
64
+ export class PaymentsResource {
65
+ readonly #http: HttpClient
66
+ readonly #vault: string
67
+ readonly #base: string
68
+
69
+ constructor(http: HttpClient, vaultCode: string) {
70
+ this.#http = http
71
+ this.#vault = `/api/v1/vaults/${seg(vaultCode)}`
72
+ this.#base = `${this.#vault}/payments`
73
+ }
74
+
75
+ /** No idempotency key: a retry creates a second payment. `amount` is a decimal string. */
76
+ create(input: CreatePaymentBody): Promise<Payment> {
77
+ return this.#http.request<Payment>('POST', this.#base, { body: input })
78
+ }
79
+
80
+ /** Without filters — all of them, settled and closed included. Keyset-paginated. */
81
+ list(params: ListPaymentsParams = {}): Promise<PaymentsPage> {
82
+ return this.#http.request<PaymentsPage>('GET', this.#base, { query: { ...params } })
83
+ }
84
+
85
+ /** Totals per token and direction over open payments that are not settled. */
86
+ summary(filters: PaymentFilters = {}): Promise<PaymentTotals> {
87
+ return this.#http.request<PaymentTotals>('GET', `${this.#base}/summary`, { query: { ...filters } })
88
+ }
89
+
90
+ /**
91
+ * With allocations and history. An allocation whose operation is on an
92
+ * address you cannot see keeps its amount and has `operation: null`.
93
+ */
94
+ get(paymentId: string): Promise<PaymentDetail> {
95
+ return this.#http.request<PaymentDetail>('GET', `${this.#base}/${seg(paymentId)}`)
96
+ }
97
+
98
+ /**
99
+ * Changes what is sent; `direction` and the token never change. Pass the
100
+ * `version` you showed as `expectedVersion` — 409 `PAYMENT_CHANGED` otherwise.
101
+ */
102
+ update(paymentId: string, patch: PatchPaymentBody): Promise<Payment> {
103
+ return this.#http.request<Payment>('PATCH', `${this.#base}/${seg(paymentId)}`, { body: patch })
104
+ }
105
+
106
+ /** No longer awaited. Allocations stay, the reserve is released. */
107
+ close(paymentId: string, input: ClosePaymentBody = {}): Promise<Payment> {
108
+ return this.#http.request<Payment>('POST', `${this.#base}/${seg(paymentId)}/close`, { body: input })
109
+ }
110
+
111
+ /** There was no agreement. With operations allocated — 409 `PAYMENT_HAS_OPERATIONS`: close it. */
112
+ cancel(paymentId: string, input: ClosePaymentBody = {}): Promise<Payment> {
113
+ return this.#http.request<Payment>('POST', `${this.#base}/${seg(paymentId)}/cancel`, { body: input })
114
+ }
115
+
116
+ reopen(paymentId: string): Promise<Payment> {
117
+ return this.#http.request<Payment>('POST', `${this.#base}/${seg(paymentId)}/reopen`)
118
+ }
119
+
120
+ /**
121
+ * Brings the reserve TO `amount` (default — all that remains), in either
122
+ * direction. Repeating the call changes nothing. An AML hold of a deposit
123
+ * outranks the reserve and may take it back.
124
+ */
125
+ reserve(paymentId: string, input: ReservePaymentBody = {}): Promise<Payment> {
126
+ return this.#http.request<Payment>('PUT', `${this.#base}/${seg(paymentId)}/reserve`, { body: input })
127
+ }
128
+
129
+ /** Releases the whole reserve. Nothing reserved — the same payment. */
130
+ release(paymentId: string): Promise<Payment> {
131
+ return this.#http.request<Payment>('DELETE', `${this.#base}/${seg(paymentId)}/reserve`)
132
+ }
133
+
134
+ /**
135
+ * Allocates an operation: deposits settle `in`, transfers settle `out`.
136
+ * Without `amount` — as much as fits. The same pair again changes nothing.
137
+ */
138
+ allocate(paymentId: string, input: AllocatePaymentBody): Promise<Payment> {
139
+ return this.#http.request<Payment>('POST', `${this.#base}/${seg(paymentId)}/allocations`, { body: input })
140
+ }
141
+
142
+ deallocate(paymentId: string, allocationId: string): Promise<Payment> {
143
+ return this.#http.request<Payment>('DELETE', `${this.#base}/${seg(paymentId)}/allocations/${seg(allocationId)}`)
144
+ }
145
+
146
+ /** Operations that might settle the payment. A hint: nothing is allocated. */
147
+ candidates(paymentId: string): Promise<PaymentOperationCandidates> {
148
+ return this.#http.request<PaymentOperationCandidates>('GET', `${this.#base}/${seg(paymentId)}/candidates`)
149
+ }
150
+
151
+ /** What an operation has settled, how much of it is free, and payments it might fit. */
152
+ ofOperation(operationType: OperationType, operationId: string): Promise<OperationPayments> {
153
+ return this.#http.request<OperationPayments>(
154
+ 'GET',
155
+ `${this.#vault}/operations/${seg(operationType)}/${seg(operationId)}/payments`,
156
+ )
157
+ }
158
+ }
159
+
160
+ export interface ListDealsParams extends PageParams {
161
+ /** `true` — archived ones only; by default the live ones. */
162
+ archived?: boolean | undefined
163
+ counterpartyId?: string | undefined
164
+ }
165
+
166
+ /** A deal groups payments of both sides: USDT in, A7A5 out. It has no money of its own. */
167
+ export class DealsResource {
168
+ readonly #http: HttpClient
169
+ readonly #base: string
170
+
171
+ constructor(http: HttpClient, vaultCode: string) {
172
+ this.#http = http
173
+ this.#base = `/api/v1/vaults/${seg(vaultCode)}/deals`
174
+ }
175
+
176
+ create(input: CreateDealBody): Promise<Deal> {
177
+ return this.#http.request<Deal>('POST', this.#base, { body: input })
178
+ }
179
+
180
+ list(params: ListDealsParams = {}): Promise<DealsPage> {
181
+ return this.#http.request<DealsPage>('GET', this.#base, { query: { ...params } })
182
+ }
183
+
184
+ /** With the payments you can see (up to 100, newest first) and their totals. */
185
+ get(dealId: string): Promise<DealDetail> {
186
+ return this.#http.request<DealDetail>('GET', `${this.#base}/${seg(dealId)}`)
187
+ }
188
+
189
+ /** `archived: true` — no new payments; the existing ones stay. */
190
+ update(dealId: string, patch: PatchDealBody): Promise<Deal> {
191
+ return this.#http.request<Deal>('PATCH', `${this.#base}/${seg(dealId)}`, { body: patch })
192
+ }
193
+ }
@@ -15,6 +15,9 @@ import type {
15
15
  DrilldownResponse,
16
16
  OperationsExceptionsReport,
17
17
  PatchReportTemplateBody,
18
+ PaymentsCalendarReport,
19
+ PaymentsOutstandingReport,
20
+ PaymentsPlanFactReport,
18
21
  ReportDrilldownBody,
19
22
  ReportExport,
20
23
  ReportMeta,
@@ -113,6 +116,12 @@ export interface ReportFilters {
113
116
  approverIds?: readonly string[] | undefined
114
117
  decisionPolicyIds?: readonly string[] | undefined
115
118
  targetTypes?: readonly string[] | undefined
119
+ /** `payments_*` only. */
120
+ direction?: 'in' | 'out' | undefined
121
+ /** `payments_*` only. */
122
+ dealIds?: readonly string[] | undefined
123
+ /** `payments_*` only: ids of custom categories. */
124
+ categoryIds?: readonly string[] | undefined
116
125
  }
117
126
 
118
127
  /**
@@ -140,7 +149,7 @@ export type ReportSnapshotListItem = GeneratedReportSnapshotListItem
140
149
  */
141
150
  export type ReportSnapshotDetail = GeneratedReportSnapshotDetail
142
151
 
143
- /** A period. Required by every report except `balance_position`. */
152
+ /** A period. Required by every report except `balance_position` and `payments_outstanding`. */
144
153
  interface Period {
145
154
  from: string
146
155
  to: string
@@ -182,6 +191,10 @@ export interface ReportParams {
182
191
  counterparty_activity: Period & { counterpartyId: string }
183
192
  counterparty_group_activity: Period & { counterpartyGroupId: string }
184
193
  operations_exceptions: Period
194
+ payments_calendar: Period
195
+ /** Like `balance_position`: the moment is `at` (omitted means now). */
196
+ payments_outstanding: Record<never, never>
197
+ payments_plan_fact: Period
185
198
  transaction_activity: Period
186
199
  }
187
200
 
@@ -289,8 +302,8 @@ export type DrilldownQuery = {
289
302
  /**
290
303
  * What each report type ANSWERS with — one generated schema per type.
291
304
  *
292
- * The ten reports share almost nothing beyond `report` (and, except for
293
- * `category_analytics`, `dataQuality`): a position report has `totalsByAsset`
305
+ * The reports share almost nothing beyond `report` (and, except for
306
+ * `category_analytics` and `payments_*`, `dataQuality`): a position report has `totalsByAsset`
294
307
  * and no `summary`, an approval report counts requests rather than money, an
295
308
  * account statement is opening and closing balances. So `run('x', …)` hands
296
309
  * back the schema of `x`, and a block that report does not have is a compile
@@ -308,6 +321,9 @@ export interface ReportResult {
308
321
  counterparty_activity: CounterpartyActivityReport
309
322
  counterparty_group_activity: CounterpartyGroupActivityReport
310
323
  operations_exceptions: OperationsExceptionsReport
324
+ payments_calendar: PaymentsCalendarReport
325
+ payments_outstanding: PaymentsOutstandingReport
326
+ payments_plan_fact: PaymentsPlanFactReport
311
327
  transaction_activity: TransactionActivityReport
312
328
  }
313
329
 
package/src/version.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /** SDK version, sent in the `user-agent` header. */
2
- export const SDK_VERSION = '0.11.0'
2
+ export const SDK_VERSION = '0.13.0'
3
3
 
4
4
  /** Default API base URL. */
5
5
  export const DEFAULT_BASE_URL = 'https://policy-engine-rest.ezig.workers.dev'