@v3finance/core-sdk 0.1.0 → 0.2.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 +397 -7
- package/README.md +215 -72
- package/dist/cjs/client.d.ts +67 -22
- package/dist/cjs/client.d.ts.map +1 -1
- package/dist/cjs/client.js +38 -2
- package/dist/cjs/client.js.map +1 -1
- package/dist/cjs/core/errors.d.ts +30 -10
- package/dist/cjs/core/errors.d.ts.map +1 -1
- package/dist/cjs/core/errors.js +47 -15
- package/dist/cjs/core/errors.js.map +1 -1
- package/dist/cjs/core/gated.d.ts +21 -3
- package/dist/cjs/core/gated.d.ts.map +1 -1
- package/dist/cjs/core/gated.js +12 -3
- package/dist/cjs/core/gated.js.map +1 -1
- package/dist/cjs/core/http.d.ts +12 -8
- package/dist/cjs/core/http.d.ts.map +1 -1
- package/dist/cjs/core/http.js +130 -40
- package/dist/cjs/core/http.js.map +1 -1
- package/dist/cjs/core/pagination.d.ts +28 -1
- package/dist/cjs/core/pagination.d.ts.map +1 -1
- package/dist/cjs/core/pagination.js +36 -1
- package/dist/cjs/core/pagination.js.map +1 -1
- package/dist/cjs/generated/operations.js +1 -1
- package/dist/cjs/generated/types.d.ts +948 -172
- package/dist/cjs/generated/types.d.ts.map +1 -1
- package/dist/cjs/index.d.ts +32 -8
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +12 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/resources/addresses.d.ts +22 -8
- package/dist/cjs/resources/addresses.d.ts.map +1 -1
- package/dist/cjs/resources/addresses.js +7 -1
- package/dist/cjs/resources/addresses.js.map +1 -1
- package/dist/cjs/resources/admin.d.ts +150 -25
- package/dist/cjs/resources/admin.d.ts.map +1 -1
- package/dist/cjs/resources/admin.js +94 -23
- package/dist/cjs/resources/admin.js.map +1 -1
- package/dist/cjs/resources/approvals.d.ts +46 -5
- package/dist/cjs/resources/approvals.d.ts.map +1 -1
- package/dist/cjs/resources/approvals.js +27 -4
- package/dist/cjs/resources/approvals.js.map +1 -1
- package/dist/cjs/resources/balances.d.ts +152 -16
- package/dist/cjs/resources/balances.d.ts.map +1 -1
- package/dist/cjs/resources/balances.js +9 -5
- package/dist/cjs/resources/balances.js.map +1 -1
- package/dist/cjs/resources/categories.d.ts +93 -21
- package/dist/cjs/resources/categories.d.ts.map +1 -1
- package/dist/cjs/resources/categories.js +65 -18
- package/dist/cjs/resources/categories.js.map +1 -1
- package/dist/cjs/resources/counterparties.d.ts +26 -3
- package/dist/cjs/resources/counterparties.d.ts.map +1 -1
- package/dist/cjs/resources/counterparties.js +17 -0
- package/dist/cjs/resources/counterparties.js.map +1 -1
- package/dist/cjs/resources/folders.d.ts +51 -10
- package/dist/cjs/resources/folders.d.ts.map +1 -1
- package/dist/cjs/resources/folders.js +36 -5
- package/dist/cjs/resources/folders.js.map +1 -1
- package/dist/cjs/resources/history.d.ts +20 -2
- package/dist/cjs/resources/history.d.ts.map +1 -1
- package/dist/cjs/resources/history.js.map +1 -1
- package/dist/cjs/resources/me.d.ts +27 -4
- package/dist/cjs/resources/me.d.ts.map +1 -1
- package/dist/cjs/resources/me.js +22 -1
- package/dist/cjs/resources/me.js.map +1 -1
- package/dist/cjs/resources/members.d.ts +19 -4
- package/dist/cjs/resources/members.d.ts.map +1 -1
- package/dist/cjs/resources/members.js +15 -6
- package/dist/cjs/resources/members.js.map +1 -1
- package/dist/cjs/resources/operations.d.ts +64 -8
- package/dist/cjs/resources/operations.d.ts.map +1 -1
- package/dist/cjs/resources/operations.js +26 -2
- package/dist/cjs/resources/operations.js.map +1 -1
- package/dist/cjs/resources/registries.d.ts +87 -9
- package/dist/cjs/resources/registries.d.ts.map +1 -1
- package/dist/cjs/resources/registries.js +54 -11
- package/dist/cjs/resources/registries.js.map +1 -1
- package/dist/cjs/resources/reports.d.ts +300 -41
- package/dist/cjs/resources/reports.d.ts.map +1 -1
- package/dist/cjs/resources/reports.js +135 -7
- package/dist/cjs/resources/reports.js.map +1 -1
- package/dist/cjs/resources/sharing.d.ts +61 -10
- package/dist/cjs/resources/sharing.d.ts.map +1 -1
- package/dist/cjs/resources/sharing.js +51 -4
- package/dist/cjs/resources/sharing.js.map +1 -1
- package/dist/cjs/resources/transfers.d.ts +26 -4
- package/dist/cjs/resources/transfers.d.ts.map +1 -1
- package/dist/cjs/resources/transfers.js +23 -1
- package/dist/cjs/resources/transfers.js.map +1 -1
- package/dist/cjs/resources/types.d.ts +20 -0
- package/dist/cjs/resources/types.d.ts.map +1 -1
- package/dist/cjs/units.d.ts.map +1 -1
- package/dist/cjs/units.js +18 -2
- package/dist/cjs/units.js.map +1 -1
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/client.d.ts +67 -22
- package/dist/esm/client.d.ts.map +1 -1
- package/dist/esm/client.js +38 -2
- package/dist/esm/client.js.map +1 -1
- package/dist/esm/core/errors.d.ts +30 -10
- package/dist/esm/core/errors.d.ts.map +1 -1
- package/dist/esm/core/errors.js +47 -15
- package/dist/esm/core/errors.js.map +1 -1
- package/dist/esm/core/gated.d.ts +21 -3
- package/dist/esm/core/gated.d.ts.map +1 -1
- package/dist/esm/core/gated.js +12 -3
- package/dist/esm/core/gated.js.map +1 -1
- package/dist/esm/core/http.d.ts +12 -8
- package/dist/esm/core/http.d.ts.map +1 -1
- package/dist/esm/core/http.js +131 -41
- package/dist/esm/core/http.js.map +1 -1
- package/dist/esm/core/pagination.d.ts +28 -1
- package/dist/esm/core/pagination.d.ts.map +1 -1
- package/dist/esm/core/pagination.js +36 -1
- package/dist/esm/core/pagination.js.map +1 -1
- package/dist/esm/generated/operations.js +1 -1
- package/dist/esm/generated/types.d.ts +948 -172
- package/dist/esm/generated/types.d.ts.map +1 -1
- package/dist/esm/index.d.ts +32 -8
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +17 -5
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/resources/addresses.d.ts +22 -8
- package/dist/esm/resources/addresses.d.ts.map +1 -1
- package/dist/esm/resources/addresses.js +7 -1
- package/dist/esm/resources/addresses.js.map +1 -1
- package/dist/esm/resources/admin.d.ts +150 -25
- package/dist/esm/resources/admin.d.ts.map +1 -1
- package/dist/esm/resources/admin.js +94 -23
- package/dist/esm/resources/admin.js.map +1 -1
- package/dist/esm/resources/approvals.d.ts +46 -5
- package/dist/esm/resources/approvals.d.ts.map +1 -1
- package/dist/esm/resources/approvals.js +27 -4
- package/dist/esm/resources/approvals.js.map +1 -1
- package/dist/esm/resources/balances.d.ts +152 -16
- package/dist/esm/resources/balances.d.ts.map +1 -1
- package/dist/esm/resources/balances.js +9 -5
- package/dist/esm/resources/balances.js.map +1 -1
- package/dist/esm/resources/categories.d.ts +93 -21
- package/dist/esm/resources/categories.d.ts.map +1 -1
- package/dist/esm/resources/categories.js +65 -18
- package/dist/esm/resources/categories.js.map +1 -1
- package/dist/esm/resources/counterparties.d.ts +26 -3
- package/dist/esm/resources/counterparties.d.ts.map +1 -1
- package/dist/esm/resources/counterparties.js +17 -0
- package/dist/esm/resources/counterparties.js.map +1 -1
- package/dist/esm/resources/folders.d.ts +51 -10
- package/dist/esm/resources/folders.d.ts.map +1 -1
- package/dist/esm/resources/folders.js +36 -5
- package/dist/esm/resources/folders.js.map +1 -1
- package/dist/esm/resources/history.d.ts +20 -2
- package/dist/esm/resources/history.d.ts.map +1 -1
- package/dist/esm/resources/history.js.map +1 -1
- package/dist/esm/resources/me.d.ts +27 -4
- package/dist/esm/resources/me.d.ts.map +1 -1
- package/dist/esm/resources/me.js +22 -1
- package/dist/esm/resources/me.js.map +1 -1
- package/dist/esm/resources/members.d.ts +19 -4
- package/dist/esm/resources/members.d.ts.map +1 -1
- package/dist/esm/resources/members.js +15 -6
- package/dist/esm/resources/members.js.map +1 -1
- package/dist/esm/resources/operations.d.ts +64 -8
- package/dist/esm/resources/operations.d.ts.map +1 -1
- package/dist/esm/resources/operations.js +26 -2
- package/dist/esm/resources/operations.js.map +1 -1
- package/dist/esm/resources/registries.d.ts +87 -9
- package/dist/esm/resources/registries.d.ts.map +1 -1
- package/dist/esm/resources/registries.js +54 -11
- package/dist/esm/resources/registries.js.map +1 -1
- package/dist/esm/resources/reports.d.ts +300 -41
- package/dist/esm/resources/reports.d.ts.map +1 -1
- package/dist/esm/resources/reports.js +135 -7
- package/dist/esm/resources/reports.js.map +1 -1
- package/dist/esm/resources/sharing.d.ts +61 -10
- package/dist/esm/resources/sharing.d.ts.map +1 -1
- package/dist/esm/resources/sharing.js +51 -4
- package/dist/esm/resources/sharing.js.map +1 -1
- package/dist/esm/resources/transfers.d.ts +26 -4
- package/dist/esm/resources/transfers.d.ts.map +1 -1
- package/dist/esm/resources/transfers.js +23 -1
- package/dist/esm/resources/transfers.js.map +1 -1
- package/dist/esm/resources/types.d.ts +20 -0
- package/dist/esm/resources/types.d.ts.map +1 -1
- package/dist/esm/units.d.ts.map +1 -1
- package/dist/esm/units.js +18 -2
- package/dist/esm/units.js.map +1 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/docs/concepts.md +191 -0
- package/docs/errors.md +471 -0
- package/package.json +7 -6
- package/src/client.ts +89 -25
- package/src/core/errors.ts +49 -15
- package/src/core/gated.ts +22 -4
- package/src/core/http.ts +156 -46
- package/src/core/pagination.ts +38 -1
- package/src/generated/operations.ts +1 -1
- package/src/generated/types.ts +983 -173
- package/src/index.ts +64 -7
- package/src/resources/addresses.ts +23 -8
- package/src/resources/admin.ts +186 -33
- package/src/resources/approvals.ts +55 -9
- package/src/resources/balances.ts +186 -14
- package/src/resources/categories.ts +125 -30
- package/src/resources/counterparties.ts +23 -6
- package/src/resources/folders.ts +74 -18
- package/src/resources/history.ts +27 -2
- package/src/resources/me.ts +30 -5
- package/src/resources/members.ts +26 -7
- package/src/resources/operations.ts +73 -8
- package/src/resources/registries.ts +90 -11
- package/src/resources/reports.ts +348 -67
- package/src/resources/sharing.ts +71 -18
- package/src/resources/transfers.ts +33 -5
- package/src/resources/types.ts +20 -0
- package/src/units.ts +19 -2
- package/src/version.ts +1 -1
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { seg, type HttpClient } from '../core/http.js'
|
|
2
2
|
import { toGated, type Gated } from '../core/gated.js'
|
|
3
3
|
import type {
|
|
4
|
+
CancelResult,
|
|
4
5
|
CreateTransactionResult,
|
|
5
6
|
CreateTransferBody,
|
|
6
7
|
ReconcileTransferBody,
|
|
7
8
|
ReconcileTransferResult,
|
|
8
9
|
TransactionDetail,
|
|
10
|
+
VoteResult,
|
|
9
11
|
} from '../generated/types.js'
|
|
10
12
|
|
|
11
13
|
export interface VoteInput {
|
|
@@ -66,17 +68,43 @@ export class TransfersResource {
|
|
|
66
68
|
* Only people captured in the approver SNAPSHOT taken when the request was
|
|
67
69
|
* created may vote: editing a policy or a group afterwards does not change
|
|
68
70
|
* an in-flight request.
|
|
71
|
+
*
|
|
72
|
+
* READ `status` FROM THE ANSWER — it is the status of the TRANSFER after
|
|
73
|
+
* the vote, and the vote is where the money moves:
|
|
74
|
+
*
|
|
75
|
+
* awaiting_approval — counted, more signatures still needed;
|
|
76
|
+
* rejected — a `reject` is a veto, and the reserve is released;
|
|
77
|
+
* confirmed/failed — this vote completed the threshold, so execution ran
|
|
78
|
+
* INSIDE this request (gas, then broadcast, ~10s).
|
|
79
|
+
*
|
|
80
|
+
* `failed` means the money is back: execution broke after approval and the
|
|
81
|
+
* reserve was released, with the reason in `executionError`. Treating the
|
|
82
|
+
* call as "approved, done" hides both the success and that failure.
|
|
69
83
|
*/
|
|
70
|
-
vote(transferId: string, input: VoteInput): Promise<
|
|
71
|
-
return this.#http.request(
|
|
84
|
+
vote(transferId: string, input: VoteInput): Promise<VoteResult> {
|
|
85
|
+
return this.#http.request<VoteResult>(
|
|
86
|
+
'POST',
|
|
87
|
+
`${this.#base}/${seg(transferId)}/approvals`,
|
|
88
|
+
{ body: input },
|
|
89
|
+
)
|
|
72
90
|
}
|
|
73
91
|
|
|
74
92
|
/**
|
|
75
93
|
* Cancels your own transfer that is awaiting signatures and releases the
|
|
76
|
-
* reserve. A transfer already broadcast cannot be cancelled
|
|
94
|
+
* reserve. A transfer already broadcast cannot be cancelled; administrators
|
|
95
|
+
* may cancel somebody else's, so a stuck request is not hostage to an
|
|
96
|
+
* absent initiator.
|
|
97
|
+
*
|
|
98
|
+
* The resulting status is its own value, `cancelled` — not the `rejected`
|
|
99
|
+
* of a veto and not `failed`. Worth keeping apart in the interface: "you
|
|
100
|
+
* withdrew this" and "somebody refused it" are different events.
|
|
101
|
+
*
|
|
102
|
+
* Clear a stuck transfer through this endpoint and never by writing the
|
|
103
|
+
* status directly: the reserve is released by a ledger posting, not by the
|
|
104
|
+
* status, so a hand-edited row leaves the funds locked for good.
|
|
77
105
|
*/
|
|
78
|
-
cancel(transferId: string): Promise<
|
|
79
|
-
return this.#http.request('POST', `${this.#base}/${seg(transferId)}/cancel`)
|
|
106
|
+
cancel(transferId: string): Promise<CancelResult> {
|
|
107
|
+
return this.#http.request<CancelResult>('POST', `${this.#base}/${seg(transferId)}/cancel`)
|
|
80
108
|
}
|
|
81
109
|
|
|
82
110
|
/**
|
package/src/resources/types.ts
CHANGED
|
@@ -21,11 +21,31 @@ import type {
|
|
|
21
21
|
/**
|
|
22
22
|
* An address as it appears in listings.
|
|
23
23
|
*
|
|
24
|
+
* Which shape comes from where: `GET /addresses` and `PATCH /addresses/{id}`
|
|
25
|
+
* both answer with `AddressListItem` — that is why this is an alias of it and
|
|
26
|
+
* not of the schema called `Address`. `GET /addresses/{id}` answers with the
|
|
27
|
+
* larger `AddressDetail` (transactions, shares, vault).
|
|
28
|
+
*
|
|
29
|
+
* The document DOES also declare a schema named `Address`, and this export
|
|
30
|
+
* shadows it — `src/index.ts` re-exports this name explicitly, and an
|
|
31
|
+
* explicit re-export beats `export type *`. That is deliberate, and the
|
|
32
|
+
* reason belongs here so nobody "fixes" it the wrong way round: no operation
|
|
33
|
+
* references the `Address` schema (zero `$ref`), and its sixteen properties
|
|
34
|
+
* are a strict subset of `AddressListItem`'s twenty-three, identical in type
|
|
35
|
+
* and in optionality. The alias is therefore narrower than the schema it
|
|
36
|
+
* hides, never wider, and the hidden schema describes no response at all.
|
|
37
|
+
* Pointing this name at `Address` would be the real break: the seven extra
|
|
38
|
+
* fields would vanish from the type while still arriving on the wire.
|
|
39
|
+
*
|
|
24
40
|
* `balance` is `string | null`, and the `null` matters: it means the address
|
|
25
41
|
* has NO ledger account yet — nothing has ever arrived. That is not zero, and
|
|
26
42
|
* the two must not be merged, because "no account" and "empty account"
|
|
27
43
|
* deserve different wording. Amounts are raw smallest units; put them through
|
|
28
44
|
* the helpers in `units.ts` rather than `Number`.
|
|
45
|
+
*
|
|
46
|
+
* One field is thinner than the type admits: `sharing` is optional because
|
|
47
|
+
* `PATCH /addresses/{id}` reuses this schema WITHOUT it (the document says so
|
|
48
|
+
* itself, on the property). Listings and the detail endpoint do send it.
|
|
29
49
|
*/
|
|
30
50
|
export type Address = AddressListItem
|
|
31
51
|
|
package/src/units.ts
CHANGED
|
@@ -35,8 +35,16 @@ export class AmountError extends Error {
|
|
|
35
35
|
const RAW_RE = /^-?\d+$/
|
|
36
36
|
const DECIMAL_RE = /^-?\d+(\.\d+)?$/
|
|
37
37
|
|
|
38
|
+
/**
|
|
39
|
+
* The API's own ceiling: `CreateTokenBody.decimals` is `int().min(0).max(38)`
|
|
40
|
+
* in the policy engine's `src/openapi/models.ts`. A lower bound here would
|
|
41
|
+
* contradict the rest of the package — `registries.createToken` would accept a
|
|
42
|
+
* token this module then refuses to do arithmetic on.
|
|
43
|
+
*/
|
|
44
|
+
const MAX_DECIMALS = 38
|
|
45
|
+
|
|
38
46
|
function assertDecimals(decimals: number): void {
|
|
39
|
-
if (!Number.isInteger(decimals) || decimals < 0 || decimals >
|
|
47
|
+
if (!Number.isInteger(decimals) || decimals < 0 || decimals > MAX_DECIMALS) {
|
|
40
48
|
throw new AmountError(`Invalid decimals: ${decimals}`)
|
|
41
49
|
}
|
|
42
50
|
}
|
|
@@ -96,8 +104,17 @@ export function format(
|
|
|
96
104
|
options: { locale?: string; withAsset?: boolean; minFractionDigits?: number } = {},
|
|
97
105
|
): string {
|
|
98
106
|
const decimal = toDecimalString(a, { trim: false })
|
|
107
|
+
// The padding is clamped to `decimals` because `decimals` is the maximum
|
|
108
|
+
// below, and Intl throws RangeError when a minimum exceeds its maximum. So
|
|
109
|
+
// the default of two digits made `format` unusable — not merely unpadded —
|
|
110
|
+
// for any token with 0 or 1 decimals, and such tokens are reachable: the API
|
|
111
|
+
// allows `decimals: 0` on a token, and a `currency` category field takes
|
|
112
|
+
// `scale: 0` today. Clamping rather than raising the maximum: digits past
|
|
113
|
+
// `decimals` do not exist in the asset, and printing them would claim a
|
|
114
|
+
// divisibility the token does not have.
|
|
115
|
+
const minFraction = Math.min(options.minFractionDigits ?? 2, a.decimals)
|
|
99
116
|
const formatter = new Intl.NumberFormat(options.locale ?? 'en-US', {
|
|
100
|
-
minimumFractionDigits:
|
|
117
|
+
minimumFractionDigits: minFraction,
|
|
101
118
|
maximumFractionDigits: a.decimals,
|
|
102
119
|
})
|
|
103
120
|
// The runtime accepts a string and keeps precision; lib.es5 still types the
|
package/src/version.ts
CHANGED