@v3finance/core-sdk 0.4.0 → 0.6.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 +185 -0
- package/README.md +18 -14
- package/dist/cjs/client.d.ts +30 -34
- package/dist/cjs/client.d.ts.map +1 -1
- package/dist/cjs/client.js +71 -0
- package/dist/cjs/client.js.map +1 -1
- package/dist/cjs/core/gated.d.ts +12 -10
- package/dist/cjs/core/gated.d.ts.map +1 -1
- package/dist/cjs/core/gated.js +12 -10
- package/dist/cjs/core/gated.js.map +1 -1
- package/dist/cjs/core/http.d.ts +18 -0
- package/dist/cjs/core/http.d.ts.map +1 -1
- package/dist/cjs/core/http.js +11 -1
- package/dist/cjs/core/http.js.map +1 -1
- package/dist/cjs/core/pagination.d.ts +11 -9
- package/dist/cjs/core/pagination.d.ts.map +1 -1
- package/dist/cjs/core/pagination.js +11 -9
- package/dist/cjs/core/pagination.js.map +1 -1
- package/dist/cjs/generated/operations.d.ts +250 -2
- package/dist/cjs/generated/operations.d.ts.map +1 -1
- package/dist/cjs/generated/operations.js +252 -4
- package/dist/cjs/generated/operations.js.map +1 -1
- package/dist/cjs/generated/types.d.ts +1137 -113
- package/dist/cjs/generated/types.d.ts.map +1 -1
- package/dist/cjs/index.d.ts +7 -6
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +3 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/resources/addresses.d.ts +91 -4
- package/dist/cjs/resources/addresses.d.ts.map +1 -1
- package/dist/cjs/resources/addresses.js +55 -3
- package/dist/cjs/resources/addresses.js.map +1 -1
- package/dist/cjs/resources/admin.d.ts +32 -1
- package/dist/cjs/resources/admin.d.ts.map +1 -1
- package/dist/cjs/resources/admin.js +45 -0
- package/dist/cjs/resources/admin.js.map +1 -1
- package/dist/cjs/resources/aml.d.ts +56 -0
- package/dist/cjs/resources/aml.d.ts.map +1 -0
- package/dist/cjs/resources/aml.js +71 -0
- package/dist/cjs/resources/aml.js.map +1 -0
- package/dist/cjs/resources/approvals.d.ts +30 -2
- package/dist/cjs/resources/approvals.d.ts.map +1 -1
- package/dist/cjs/resources/approvals.js.map +1 -1
- package/dist/cjs/resources/balances.d.ts +14 -7
- package/dist/cjs/resources/balances.d.ts.map +1 -1
- package/dist/cjs/resources/balances.js +10 -4
- package/dist/cjs/resources/balances.js.map +1 -1
- package/dist/cjs/resources/categories.d.ts +20 -6
- package/dist/cjs/resources/categories.d.ts.map +1 -1
- package/dist/cjs/resources/categories.js +19 -7
- package/dist/cjs/resources/categories.js.map +1 -1
- package/dist/cjs/resources/counterparties.d.ts +52 -6
- package/dist/cjs/resources/counterparties.d.ts.map +1 -1
- package/dist/cjs/resources/counterparties.js +24 -0
- package/dist/cjs/resources/counterparties.js.map +1 -1
- package/dist/cjs/resources/history.d.ts +227 -26
- package/dist/cjs/resources/history.d.ts.map +1 -1
- package/dist/cjs/resources/history.js +46 -0
- package/dist/cjs/resources/history.js.map +1 -1
- package/dist/cjs/resources/me.d.ts +17 -1
- package/dist/cjs/resources/me.d.ts.map +1 -1
- package/dist/cjs/resources/me.js +19 -0
- package/dist/cjs/resources/me.js.map +1 -1
- package/dist/cjs/resources/members.d.ts +21 -1
- package/dist/cjs/resources/members.d.ts.map +1 -1
- package/dist/cjs/resources/members.js +15 -0
- package/dist/cjs/resources/members.js.map +1 -1
- package/dist/cjs/resources/operations.d.ts +179 -4
- package/dist/cjs/resources/operations.d.ts.map +1 -1
- package/dist/cjs/resources/operations.js +192 -2
- package/dist/cjs/resources/operations.js.map +1 -1
- package/dist/cjs/resources/registries.d.ts +28 -2
- package/dist/cjs/resources/registries.d.ts.map +1 -1
- package/dist/cjs/resources/registries.js +27 -0
- package/dist/cjs/resources/registries.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 +30 -34
- package/dist/esm/client.d.ts.map +1 -1
- package/dist/esm/client.js +71 -0
- package/dist/esm/client.js.map +1 -1
- package/dist/esm/core/gated.d.ts +12 -10
- package/dist/esm/core/gated.d.ts.map +1 -1
- package/dist/esm/core/gated.js +12 -10
- package/dist/esm/core/gated.js.map +1 -1
- package/dist/esm/core/http.d.ts +18 -0
- package/dist/esm/core/http.d.ts.map +1 -1
- package/dist/esm/core/http.js +11 -1
- package/dist/esm/core/http.js.map +1 -1
- package/dist/esm/core/pagination.d.ts +11 -9
- package/dist/esm/core/pagination.d.ts.map +1 -1
- package/dist/esm/core/pagination.js +11 -9
- package/dist/esm/core/pagination.js.map +1 -1
- package/dist/esm/generated/operations.d.ts +250 -2
- package/dist/esm/generated/operations.d.ts.map +1 -1
- package/dist/esm/generated/operations.js +252 -4
- package/dist/esm/generated/operations.js.map +1 -1
- package/dist/esm/generated/types.d.ts +1137 -113
- package/dist/esm/generated/types.d.ts.map +1 -1
- package/dist/esm/index.d.ts +7 -6
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/resources/addresses.d.ts +91 -4
- package/dist/esm/resources/addresses.d.ts.map +1 -1
- package/dist/esm/resources/addresses.js +55 -3
- package/dist/esm/resources/addresses.js.map +1 -1
- package/dist/esm/resources/admin.d.ts +32 -1
- package/dist/esm/resources/admin.d.ts.map +1 -1
- package/dist/esm/resources/admin.js +45 -0
- package/dist/esm/resources/admin.js.map +1 -1
- package/dist/esm/resources/aml.d.ts +56 -0
- package/dist/esm/resources/aml.d.ts.map +1 -0
- package/dist/esm/resources/aml.js +67 -0
- package/dist/esm/resources/aml.js.map +1 -0
- package/dist/esm/resources/approvals.d.ts +30 -2
- package/dist/esm/resources/approvals.d.ts.map +1 -1
- package/dist/esm/resources/approvals.js.map +1 -1
- package/dist/esm/resources/balances.d.ts +14 -7
- package/dist/esm/resources/balances.d.ts.map +1 -1
- package/dist/esm/resources/balances.js +10 -4
- package/dist/esm/resources/balances.js.map +1 -1
- package/dist/esm/resources/categories.d.ts +20 -6
- package/dist/esm/resources/categories.d.ts.map +1 -1
- package/dist/esm/resources/categories.js +19 -7
- package/dist/esm/resources/categories.js.map +1 -1
- package/dist/esm/resources/counterparties.d.ts +52 -6
- package/dist/esm/resources/counterparties.d.ts.map +1 -1
- package/dist/esm/resources/counterparties.js +24 -0
- package/dist/esm/resources/counterparties.js.map +1 -1
- package/dist/esm/resources/history.d.ts +227 -26
- package/dist/esm/resources/history.d.ts.map +1 -1
- package/dist/esm/resources/history.js +46 -0
- package/dist/esm/resources/history.js.map +1 -1
- package/dist/esm/resources/me.d.ts +17 -1
- package/dist/esm/resources/me.d.ts.map +1 -1
- package/dist/esm/resources/me.js +19 -0
- package/dist/esm/resources/me.js.map +1 -1
- package/dist/esm/resources/members.d.ts +21 -1
- package/dist/esm/resources/members.d.ts.map +1 -1
- package/dist/esm/resources/members.js +15 -0
- package/dist/esm/resources/members.js.map +1 -1
- package/dist/esm/resources/operations.d.ts +179 -4
- package/dist/esm/resources/operations.d.ts.map +1 -1
- package/dist/esm/resources/operations.js +192 -2
- package/dist/esm/resources/operations.js.map +1 -1
- package/dist/esm/resources/registries.d.ts +28 -2
- package/dist/esm/resources/registries.d.ts.map +1 -1
- package/dist/esm/resources/registries.js +27 -0
- package/dist/esm/resources/registries.js.map +1 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/docs/concepts.md +13 -11
- package/docs/errors.md +76 -5
- package/package.json +1 -1
- package/src/client.ts +44 -0
- package/src/core/gated.ts +12 -10
- package/src/core/http.ts +30 -1
- package/src/core/pagination.ts +11 -9
- package/src/generated/operations.ts +252 -4
- package/src/generated/types.ts +1173 -95
- package/src/index.ts +16 -1
- package/src/resources/addresses.ts +102 -4
- package/src/resources/admin.ts +59 -0
- package/src/resources/aml.ts +76 -0
- package/src/resources/approvals.ts +30 -2
- package/src/resources/balances.ts +14 -7
- package/src/resources/categories.ts +19 -5
- package/src/resources/counterparties.ts +59 -5
- package/src/resources/history.ts +238 -27
- package/src/resources/me.ts +22 -0
- package/src/resources/members.ts +30 -0
- package/src/resources/operations.ts +264 -5
- package/src/resources/registries.ts +39 -3
- package/src/version.ts +1 -1
|
@@ -1,15 +1,22 @@
|
|
|
1
|
-
import { seg, type HttpClient } from '../core/http.js'
|
|
1
|
+
import { seg, type HttpClient, type RawBody } from '../core/http.js'
|
|
2
|
+
import { toGated, type Gated } from '../core/gated.js'
|
|
2
3
|
import type { PageParams } from '../core/pagination.js'
|
|
3
4
|
import type {
|
|
4
5
|
ApprovalRelations,
|
|
6
|
+
ApprovalRequestCreated,
|
|
5
7
|
CreateOperationRelationBody,
|
|
6
8
|
IncomingTransactionDetail,
|
|
9
|
+
OperationAttachment,
|
|
10
|
+
OperationAttachmentDeleted,
|
|
11
|
+
OperationAttachmentsList,
|
|
12
|
+
OperationCounterparty,
|
|
7
13
|
OperationMetadata,
|
|
8
14
|
OperationRelation,
|
|
9
15
|
OperationRelationsPage,
|
|
10
16
|
OperationType,
|
|
11
17
|
PatchOperationMetadataBody,
|
|
12
18
|
} from '../generated/types.js'
|
|
19
|
+
import type { OperationRelationType } from './history.js'
|
|
13
20
|
|
|
14
21
|
/**
|
|
15
22
|
* Operation kind in a path. Exactly two values exist.
|
|
@@ -24,7 +31,7 @@ import type {
|
|
|
24
31
|
export type OperationKind = OperationType
|
|
25
32
|
|
|
26
33
|
export interface ListRelationsParams extends PageParams {
|
|
27
|
-
relationType?:
|
|
34
|
+
relationType?: OperationRelationType | undefined
|
|
28
35
|
sourceOperationId?: string | undefined
|
|
29
36
|
targetOperationId?: string | undefined
|
|
30
37
|
/** Links that carry a partial amount in this token. */
|
|
@@ -38,6 +45,22 @@ export interface ListRelationsParams extends PageParams {
|
|
|
38
45
|
to?: string | undefined
|
|
39
46
|
}
|
|
40
47
|
|
|
48
|
+
/** A file to attach, sent as the raw request body. */
|
|
49
|
+
export type AttachmentFile = Exclude<RawBody, FormData>
|
|
50
|
+
|
|
51
|
+
export interface UploadAttachmentOptions {
|
|
52
|
+
/**
|
|
53
|
+
* The file's name, for a raw body. Taken from a `File` when omitted; an
|
|
54
|
+
* `ArrayBuffer` or `Uint8Array` has none, and a raw upload without a name is
|
|
55
|
+
* 400 `ATTACHMENT_FILENAME_REQUIRED`. Not used with a `FormData`: there the
|
|
56
|
+
* name is the form's `filename` field, or the file part's own name.
|
|
57
|
+
*/
|
|
58
|
+
filename?: string | undefined
|
|
59
|
+
signal?: AbortSignal | undefined
|
|
60
|
+
/** An upload can be large; the client's default timeout applies otherwise. */
|
|
61
|
+
timeoutMs?: number | undefined
|
|
62
|
+
}
|
|
63
|
+
|
|
41
64
|
/**
|
|
42
65
|
* Everything hanging off a single operation: free-form metadata, links to
|
|
43
66
|
* other operations, and how its status changed over time.
|
|
@@ -71,16 +94,34 @@ export class OperationsResource {
|
|
|
71
94
|
)
|
|
72
95
|
}
|
|
73
96
|
|
|
74
|
-
|
|
97
|
+
/**
|
|
98
|
+
* A sent field replaces its value, `null` clears it, an absent one stays.
|
|
99
|
+
*
|
|
100
|
+
* Returns `Gated`. The metadata is a facade over the assignment of the
|
|
101
|
+
* system category `general`, and is written the way `categories` writes:
|
|
102
|
+
* a version per change, an optimistic lock, and the category's approval.
|
|
103
|
+
* By default `general` has none and the answer is `applied` (200), as it
|
|
104
|
+
* always was. If an administrator set its `approvalScope`, nothing is
|
|
105
|
+
* written: a request is created (`category_assign` / `category_edit`) and
|
|
106
|
+
* the answer is `pending` (202) with its card. An edit of ANOTHER field
|
|
107
|
+
* made concurrently is not lost — the patch is laid over the fresh version
|
|
108
|
+
* up to three times before 409 `ASSIGNMENT_STALE`.
|
|
109
|
+
*
|
|
110
|
+
* Writing takes the labelling right of `general`: by default `transfer` on
|
|
111
|
+
* the operation's address. Seeing the operation is not enough — a signer or
|
|
112
|
+
* an initiator without that right gets 404.
|
|
113
|
+
*/
|
|
114
|
+
async setMetadata(
|
|
75
115
|
kind: OperationKind,
|
|
76
116
|
operationId: string,
|
|
77
117
|
input: PatchOperationMetadataBody,
|
|
78
|
-
): Promise<OperationMetadata
|
|
79
|
-
|
|
118
|
+
): Promise<Gated<OperationMetadata, ApprovalRequestCreated>> {
|
|
119
|
+
const res = await this.#http.requestRaw<unknown>(
|
|
80
120
|
'PATCH',
|
|
81
121
|
`${this.#op(kind, operationId)}/metadata`,
|
|
82
122
|
{ body: input },
|
|
83
123
|
)
|
|
124
|
+
return toGated<OperationMetadata, ApprovalRequestCreated>(res.status, res.data)
|
|
84
125
|
}
|
|
85
126
|
|
|
86
127
|
/** Other operations linked to this one. A plain array, not a page. */
|
|
@@ -134,6 +175,27 @@ export class OperationsResource {
|
|
|
134
175
|
)
|
|
135
176
|
}
|
|
136
177
|
|
|
178
|
+
/**
|
|
179
|
+
* Links two operations. DIRECTION: `source` is the DERIVED operation (the
|
|
180
|
+
* refund, reversal, correction or replacement itself), `target` the
|
|
181
|
+
* ORIGINAL it refers to — a deposit refunded by a transfer is source =
|
|
182
|
+
* transfer, target = deposit. Both must be in this vault, with `transfer`
|
|
183
|
+
* on the addresses of BOTH; otherwise 404 `OPERATION_NOT_FOUND`, as if
|
|
184
|
+
* missing.
|
|
185
|
+
*
|
|
186
|
+
* Idempotent, and not wrapped in `Gated`: a relation is unique by (type,
|
|
187
|
+
* source, target), and repeating the same body answers 200 with the
|
|
188
|
+
* existing relation where a new one answers 201 — both mean "this relation
|
|
189
|
+
* now exists, exactly as asked". The same triple with another amount, token
|
|
190
|
+
* or comment is 409 `OPERATION_RELATION_EXISTS`, the existing id in
|
|
191
|
+
* `details.relationId`. To change a relation, delete it and create it
|
|
192
|
+
* again.
|
|
193
|
+
*
|
|
194
|
+
* `relatedAmountRaw` only together with `tokenId`: a token of at least one
|
|
195
|
+
* of the two operations, an amount above zero and no larger than either
|
|
196
|
+
* side's amount in that token — otherwise 422 `OPERATION_RELATION_INVALID`,
|
|
197
|
+
* the field in `details.field`.
|
|
198
|
+
*/
|
|
137
199
|
createRelation(input: CreateOperationRelationBody): Promise<OperationRelation> {
|
|
138
200
|
return this.#http.request<OperationRelation>(
|
|
139
201
|
'POST',
|
|
@@ -142,6 +204,192 @@ export class OperationsResource {
|
|
|
142
204
|
)
|
|
143
205
|
}
|
|
144
206
|
|
|
207
|
+
/**
|
|
208
|
+
* Removes a relation — physically: a relation has no version history, so
|
|
209
|
+
* reports read the current state and report snapshots stay as they were.
|
|
210
|
+
*
|
|
211
|
+
* Its creator or an administrator. The creator needs what creating took —
|
|
212
|
+
* `transfer` on the addresses of BOTH operations, now; otherwise 403
|
|
213
|
+
* `OPERATION_RELATION_FORBIDDEN`. Someone else's relation is 403
|
|
214
|
+
* `NOT_RELATION_CREATOR`. A relation neither side of which you can see,
|
|
215
|
+
* like one already removed, is 404 `OPERATION_RELATION_NOT_FOUND`.
|
|
216
|
+
*/
|
|
217
|
+
deleteRelation(relationId: string): Promise<{ deleted: true }> {
|
|
218
|
+
return this.#http.request<{ deleted: true }>(
|
|
219
|
+
'DELETE',
|
|
220
|
+
`/api/v1/vaults/${this.#vault}/operation-relations/${seg(relationId)}`,
|
|
221
|
+
)
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Picks the counterparty of a transfer or a deposit by hand, correcting a
|
|
226
|
+
* wrong or missing automatic match: `counterpartySource` becomes `manual`.
|
|
227
|
+
* `null` is a choice too — "this operation has no counterparty".
|
|
228
|
+
*
|
|
229
|
+
* The choice is written where the automatic match is, so the feed, the
|
|
230
|
+
* cards, the counterparty's counters and reports see it at once. Neither
|
|
231
|
+
* the automatic match nor the retro-match on adding an address overwrites
|
|
232
|
+
* it; `resetCounterparty()` hands the operation back to them. Repeating the
|
|
233
|
+
* same value writes nothing and answers the current state.
|
|
234
|
+
*
|
|
235
|
+
* Only a counterparty of this vault that is not archived: 404
|
|
236
|
+
* `COUNTERPARTY_NOT_FOUND` (someone else's and a missing one alike), 409
|
|
237
|
+
* `COUNTERPARTY_ARCHIVED`. A transfer awaiting signatures is 409
|
|
238
|
+
* `OPERATION_AWAITING_APPROVAL` — its signers see the counterparty matched
|
|
239
|
+
* by the recipient's address, and a manual choice then would let them sign
|
|
240
|
+
* a stranger's address under a trusted name. The policy decision never
|
|
241
|
+
* depends on this choice; it was taken by address at creation.
|
|
242
|
+
*
|
|
243
|
+
* Takes the right to write the operation's metadata: `transfer` on its
|
|
244
|
+
* address. Seeing it is not enough — anyone else gets 404
|
|
245
|
+
* `OPERATION_NOT_FOUND`.
|
|
246
|
+
*/
|
|
247
|
+
setCounterparty(
|
|
248
|
+
kind: OperationKind,
|
|
249
|
+
operationId: string,
|
|
250
|
+
counterpartyId: string | null,
|
|
251
|
+
): Promise<OperationCounterparty> {
|
|
252
|
+
return this.#http.request<OperationCounterparty>(
|
|
253
|
+
'PUT',
|
|
254
|
+
`${this.#op(kind, operationId)}/counterparty`,
|
|
255
|
+
{ body: { counterpartyId } },
|
|
256
|
+
)
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Drops the manual choice and matches the operation again AT ONCE — by the
|
|
261
|
+
* other side's address (the recipient of a transfer, the sender of a
|
|
262
|
+
* deposit) against the directory as it is NOW, by the rule used at
|
|
263
|
+
* creation (an archived counterparty does not match). The result can
|
|
264
|
+
* differ from what was there before the manual choice if the directory has
|
|
265
|
+
* changed since.
|
|
266
|
+
*
|
|
267
|
+
* On an operation that is already automatic nothing is written and the
|
|
268
|
+
* current state comes back, so a repeat is safe. Afterwards
|
|
269
|
+
* `counterpartySource` is `auto` and `counterpartySetById`/`At` say who
|
|
270
|
+
* reset it and when. Same rights and the same 409
|
|
271
|
+
* `OPERATION_AWAITING_APPROVAL` as `setCounterparty()`.
|
|
272
|
+
*/
|
|
273
|
+
resetCounterparty(kind: OperationKind, operationId: string): Promise<OperationCounterparty> {
|
|
274
|
+
return this.#http.request<OperationCounterparty>(
|
|
275
|
+
'DELETE',
|
|
276
|
+
`${this.#op(kind, operationId)}/counterparty`,
|
|
277
|
+
)
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Files attached to an operation (invoices, acts, screenshots) — metadata,
|
|
282
|
+
* in upload order; the bytes are fetched with `downloadAttachment()`. At
|
|
283
|
+
* most 20 per operation, so there is no cursor. Removed ones are not
|
|
284
|
+
* listed.
|
|
285
|
+
*
|
|
286
|
+
* Seen by whoever sees the operation: for a transfer an administrator, its
|
|
287
|
+
* initiator, a signer from the request's snapshot, or `view` on the sending
|
|
288
|
+
* address; for a deposit `view` on the receiving address. Anyone else gets
|
|
289
|
+
* 404 `OPERATION_NOT_FOUND`. A server without attachment storage answers
|
|
290
|
+
* 501 `ATTACHMENTS_DISABLED` on every attachment call — hide the feature
|
|
291
|
+
* then.
|
|
292
|
+
*/
|
|
293
|
+
attachments(kind: OperationKind, operationId: string): Promise<OperationAttachmentsList> {
|
|
294
|
+
return this.#http.request<OperationAttachmentsList>(
|
|
295
|
+
'GET',
|
|
296
|
+
`${this.#op(kind, operationId)}/attachments`,
|
|
297
|
+
)
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* Attaches a file. Two forms, chosen by what you pass:
|
|
302
|
+
*
|
|
303
|
+
* • a `Blob`/`File`, an `ArrayBuffer` or a `Uint8Array` goes as the raw
|
|
304
|
+
* body (`application/octet-stream`, the name in `?filename=`), streamed
|
|
305
|
+
* to storage, up to 10 MB. `fetch` sets `Content-Length` itself, which
|
|
306
|
+
* the API requires (411 `ATTACHMENT_LENGTH_REQUIRED` without it);
|
|
307
|
+
* • a `FormData` goes as `multipart/form-data` exactly as built: the file
|
|
308
|
+
* in the field `file`, the name in the field `filename` or the part's
|
|
309
|
+
* own. Parsed in memory, so up to 5 MB. This is the form React Native
|
|
310
|
+
* sends a file from a `uri` with.
|
|
311
|
+
*
|
|
312
|
+
* The type is decided by the BYTES, never by a header: PDF, PNG, JPEG and
|
|
313
|
+
* WebP only — anything else (SVG and HTML included) is 415
|
|
314
|
+
* `ATTACHMENT_TYPE_NOT_ALLOWED`. The name is cleaned and its extension made
|
|
315
|
+
* to match the type; read the stored one from the answer. Over the size
|
|
316
|
+
* limit is 413 `ATTACHMENT_TOO_LARGE`; over 20 files on the operation, 409
|
|
317
|
+
* `ATTACHMENT_LIMIT_REACHED`; over the vault's quota (1 GB of live files by
|
|
318
|
+
* default), 409 `ATTACHMENT_QUOTA_EXCEEDED` with `details.quotaBytes` and
|
|
319
|
+
* `details.usedBytes`.
|
|
320
|
+
*
|
|
321
|
+
* Uploading takes `transfer` on the operation's address, as labelling does;
|
|
322
|
+
* a signer, an initiator whose grant was revoked and a view-only grant get
|
|
323
|
+
* 404. From a browser, a page of a site the API does not trust is refused
|
|
324
|
+
* with 403 `CROSS_SITE_REQUEST_REFUSED`, as every changing request is.
|
|
325
|
+
*/
|
|
326
|
+
uploadAttachment(
|
|
327
|
+
kind: OperationKind,
|
|
328
|
+
operationId: string,
|
|
329
|
+
file: AttachmentFile | FormData,
|
|
330
|
+
options: UploadAttachmentOptions = {},
|
|
331
|
+
): Promise<OperationAttachment> {
|
|
332
|
+
const path = `${this.#op(kind, operationId)}/attachments`
|
|
333
|
+
const control = { signal: options.signal, timeoutMs: options.timeoutMs }
|
|
334
|
+
if (isFormData(file)) {
|
|
335
|
+
return this.#http.request<OperationAttachment>('POST', path, { ...control, rawBody: file })
|
|
336
|
+
}
|
|
337
|
+
return this.#http.request<OperationAttachment>('POST', path, {
|
|
338
|
+
...control,
|
|
339
|
+
rawBody: file,
|
|
340
|
+
contentType: 'application/octet-stream',
|
|
341
|
+
query: { filename: options.filename ?? fileName(file) },
|
|
342
|
+
})
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* The file itself, as the untouched `Response`: read it with `.blob()` or
|
|
347
|
+
* `.arrayBuffer()`. `Content-Type` is the type detected at upload, and
|
|
348
|
+
* `Content-Disposition: attachment` carries the cleaned name. The same
|
|
349
|
+
* path is the attachment's `downloadPath`, relative to the API base.
|
|
350
|
+
*
|
|
351
|
+
* Who may read it is checked on every request, so a revoked access closes a
|
|
352
|
+
* cached copy too: the API answers with `ETag` = the file's SHA-256 and
|
|
353
|
+
* `Cache-Control: private, max-age=0, must-revalidate`. Do not send
|
|
354
|
+
* `If-None-Match` yourself — a 304 has no body and the transport reports it
|
|
355
|
+
* as an error; the browser's own revalidation is transparent. A file
|
|
356
|
+
* missing from storage is 502 `ATTACHMENT_STORAGE_UNAVAILABLE`.
|
|
357
|
+
*/
|
|
358
|
+
downloadAttachment(
|
|
359
|
+
kind: OperationKind,
|
|
360
|
+
operationId: string,
|
|
361
|
+
attachmentId: string,
|
|
362
|
+
options: { signal?: AbortSignal | undefined } = {},
|
|
363
|
+
): Promise<Response> {
|
|
364
|
+
return this.#http.fetchRaw(
|
|
365
|
+
'GET',
|
|
366
|
+
`${this.#op(kind, operationId)}/attachments/${seg(attachmentId)}/content`,
|
|
367
|
+
{ signal: options.signal },
|
|
368
|
+
)
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* Removes an attachment: its uploader, while they still hold `transfer` on
|
|
373
|
+
* the operation's address, or an administrator — anyone else who sees the
|
|
374
|
+
* operation gets 403 `ATTACHMENT_DELETE_FORBIDDEN`. Soft: the file leaves
|
|
375
|
+
* the list and is no longer served, its bytes are erased, and the record
|
|
376
|
+
* stays as an audit trail. Repeating it answers the same.
|
|
377
|
+
*
|
|
378
|
+
* 502 `ATTACHMENT_STORAGE_UNAVAILABLE` with `details.deleted: true` means
|
|
379
|
+
* the attachment is already hidden but storage kept the bytes; repeat the
|
|
380
|
+
* call to clean them up.
|
|
381
|
+
*/
|
|
382
|
+
deleteAttachment(
|
|
383
|
+
kind: OperationKind,
|
|
384
|
+
operationId: string,
|
|
385
|
+
attachmentId: string,
|
|
386
|
+
): Promise<OperationAttachmentDeleted> {
|
|
387
|
+
return this.#http.request<OperationAttachmentDeleted>(
|
|
388
|
+
'DELETE',
|
|
389
|
+
`${this.#op(kind, operationId)}/attachments/${seg(attachmentId)}`,
|
|
390
|
+
)
|
|
391
|
+
}
|
|
392
|
+
|
|
145
393
|
/**
|
|
146
394
|
* An incoming payment in detail.
|
|
147
395
|
*
|
|
@@ -177,3 +425,14 @@ export class OperationsResource {
|
|
|
177
425
|
)
|
|
178
426
|
}
|
|
179
427
|
}
|
|
428
|
+
|
|
429
|
+
/** `instanceof` alone fails where the global is missing (older Node) — guard it. */
|
|
430
|
+
function isFormData(value: unknown): value is FormData {
|
|
431
|
+
return typeof FormData !== 'undefined' && value instanceof FormData
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
/** The name a `File` carries; a bare `Blob` or buffer has none. */
|
|
435
|
+
function fileName(file: AttachmentFile): string | undefined {
|
|
436
|
+
const name = (file as { name?: unknown }).name
|
|
437
|
+
return typeof name === 'string' && name !== '' ? name : undefined
|
|
438
|
+
}
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import type { HttpClient } from '../core/http.js'
|
|
2
2
|
import type {
|
|
3
|
+
AmlProviders,
|
|
3
4
|
AmlValue,
|
|
4
5
|
CreateNetworkBody,
|
|
5
6
|
CreateTokenBody,
|
|
6
7
|
EvaluationRequest,
|
|
7
8
|
EvaluationResult,
|
|
9
|
+
FiatCurrency,
|
|
8
10
|
Network,
|
|
9
11
|
PatchNetworkBody,
|
|
10
12
|
PatchTokenBody,
|
|
11
13
|
RatesResponse,
|
|
14
|
+
RegistryNetwork,
|
|
12
15
|
TokenWithNetwork,
|
|
13
16
|
} from '../generated/types.js'
|
|
14
17
|
|
|
@@ -59,10 +62,16 @@ export class RegistriesResource {
|
|
|
59
62
|
this.#http = http
|
|
60
63
|
}
|
|
61
64
|
|
|
62
|
-
|
|
63
|
-
|
|
65
|
+
/**
|
|
66
|
+
* Every registered network. Each carries `logoPath`: load the logo through
|
|
67
|
+
* the API with `CoreClient.logo(logoPath)` rather than from `logoUri`, or
|
|
68
|
+
* the image's host sees the client's IP.
|
|
69
|
+
*/
|
|
70
|
+
networks(): Promise<RegistryNetwork[]> {
|
|
71
|
+
return this.#http.request<RegistryNetwork[]>('GET', '/api/v1/networks')
|
|
64
72
|
}
|
|
65
73
|
|
|
74
|
+
/** Tokens, with `logoPath` — see `networks()` on why to load it, not `logoUri`. */
|
|
66
75
|
tokens(params: { network?: string; enabled?: boolean } = {}): Promise<TokenWithNetwork[]> {
|
|
67
76
|
return this.#http.request<TokenWithNetwork[]>('GET', '/api/v1/tokens', { query: { ...params } })
|
|
68
77
|
}
|
|
@@ -78,8 +87,23 @@ export class RegistriesResource {
|
|
|
78
87
|
* Rates are fetched live on every call and NOT cached, so this is the
|
|
79
88
|
* "right now" figure. The rate stored on an operation is a separate thing:
|
|
80
89
|
* a snapshot taken when it was created.
|
|
90
|
+
*
|
|
91
|
+
* `base` adds rates in a fiat currency: `fx.rate` is how much of `base` one
|
|
92
|
+
* USD costs, and each `rates[].rate` is `base` per token (`usdRate` ×
|
|
93
|
+
* `fx.rate`). The conversion goes THROUGH THE DOLLAR, at the Bank of
|
|
94
|
+
* Russia's official rate for the date (`fx.asOf`; unchanged over weekends) —
|
|
95
|
+
* fit for valuation, not for settlement; the server keeps that table for up
|
|
96
|
+
* to an hour. When the currency source is down, `fx` is `null` and every
|
|
97
|
+
* `rates[].rate` is `null`, still with 200. Without `base` the answer is the
|
|
98
|
+
* old one: `base: 'USD'` and neither `fx` nor `rate` keys at all — so pass
|
|
99
|
+
* `base: 'USD'` explicitly if you want `rate` filled in USD.
|
|
81
100
|
*/
|
|
82
|
-
rates(
|
|
101
|
+
rates(
|
|
102
|
+
params: {
|
|
103
|
+
codes?: string | readonly string[] | undefined
|
|
104
|
+
base?: FiatCurrency | undefined
|
|
105
|
+
} = {},
|
|
106
|
+
): Promise<RatesResponse> {
|
|
83
107
|
return this.#http.request<RatesResponse>('GET', '/api/v1/rates', { query: { ...params } })
|
|
84
108
|
}
|
|
85
109
|
|
|
@@ -146,6 +170,18 @@ export class RegistriesResource {
|
|
|
146
170
|
})
|
|
147
171
|
}
|
|
148
172
|
|
|
173
|
+
/**
|
|
174
|
+
* AML providers and what each can do. `capabilities` decides which rule
|
|
175
|
+
* conditions a provider can serve: Scorechain has no shares of funds, no
|
|
176
|
+
* entity of the address itself and no separate sanction authorities, and
|
|
177
|
+
* the server will refuse a rule that needs them — so do not offer those
|
|
178
|
+
* conditions in a rule builder. The registry is code, the same for every
|
|
179
|
+
* vault.
|
|
180
|
+
*/
|
|
181
|
+
amlProviders(): Promise<AmlProviders> {
|
|
182
|
+
return this.#http.request<AmlProviders>('GET', '/api/v1/aml/providers')
|
|
183
|
+
}
|
|
184
|
+
|
|
149
185
|
/**
|
|
150
186
|
* Registering a network. Administrators only.
|
|
151
187
|
*
|
package/src/version.ts
CHANGED