@v3finance/core-sdk 0.2.5 → 0.3.1
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 +57 -0
- package/README.md +9 -2
- package/dist/cjs/client.d.ts +2 -0
- package/dist/cjs/client.d.ts.map +1 -1
- package/dist/cjs/client.js +2 -0
- package/dist/cjs/client.js.map +1 -1
- package/dist/cjs/core/gated.d.ts +6 -5
- package/dist/cjs/core/gated.d.ts.map +1 -1
- package/dist/cjs/core/gated.js +6 -5
- package/dist/cjs/core/gated.js.map +1 -1
- package/dist/cjs/core/pagination.d.ts +4 -3
- package/dist/cjs/core/pagination.d.ts.map +1 -1
- package/dist/cjs/core/pagination.js +4 -3
- package/dist/cjs/core/pagination.js.map +1 -1
- package/dist/cjs/generated/operations.d.ts +40 -0
- package/dist/cjs/generated/operations.d.ts.map +1 -1
- package/dist/cjs/generated/operations.js +42 -2
- package/dist/cjs/generated/operations.js.map +1 -1
- package/dist/cjs/generated/types.d.ts +50 -1
- package/dist/cjs/generated/types.d.ts.map +1 -1
- package/dist/cjs/index.d.ts +1 -0
- 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/approvals.d.ts +11 -1
- package/dist/cjs/resources/approvals.d.ts.map +1 -1
- package/dist/cjs/resources/approvals.js +11 -1
- package/dist/cjs/resources/approvals.js.map +1 -1
- package/dist/cjs/resources/transferDrafts.d.ts +119 -0
- package/dist/cjs/resources/transferDrafts.d.ts.map +1 -0
- package/dist/cjs/resources/transferDrafts.js +128 -0
- package/dist/cjs/resources/transferDrafts.js.map +1 -0
- package/dist/cjs/resources/transfers.d.ts +18 -2
- package/dist/cjs/resources/transfers.d.ts.map +1 -1
- package/dist/cjs/resources/transfers.js +18 -2
- package/dist/cjs/resources/transfers.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 +2 -0
- package/dist/esm/client.d.ts.map +1 -1
- package/dist/esm/client.js +2 -0
- package/dist/esm/client.js.map +1 -1
- package/dist/esm/core/gated.d.ts +6 -5
- package/dist/esm/core/gated.d.ts.map +1 -1
- package/dist/esm/core/gated.js +6 -5
- package/dist/esm/core/gated.js.map +1 -1
- package/dist/esm/core/pagination.d.ts +4 -3
- package/dist/esm/core/pagination.d.ts.map +1 -1
- package/dist/esm/core/pagination.js +4 -3
- package/dist/esm/core/pagination.js.map +1 -1
- package/dist/esm/generated/operations.d.ts +40 -0
- package/dist/esm/generated/operations.d.ts.map +1 -1
- package/dist/esm/generated/operations.js +42 -2
- package/dist/esm/generated/operations.js.map +1 -1
- package/dist/esm/generated/types.d.ts +50 -1
- package/dist/esm/generated/types.d.ts.map +1 -1
- package/dist/esm/index.d.ts +1 -0
- 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/approvals.d.ts +11 -1
- package/dist/esm/resources/approvals.d.ts.map +1 -1
- package/dist/esm/resources/approvals.js +11 -1
- package/dist/esm/resources/approvals.js.map +1 -1
- package/dist/esm/resources/transferDrafts.d.ts +119 -0
- package/dist/esm/resources/transferDrafts.d.ts.map +1 -0
- package/dist/esm/resources/transferDrafts.js +124 -0
- package/dist/esm/resources/transferDrafts.js.map +1 -0
- package/dist/esm/resources/transfers.d.ts +18 -2
- package/dist/esm/resources/transfers.d.ts.map +1 -1
- package/dist/esm/resources/transfers.js +18 -2
- package/dist/esm/resources/transfers.js.map +1 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/docs/concepts.md +14 -2
- package/docs/errors.md +22 -5
- package/package.json +1 -1
- package/src/client.ts +3 -0
- package/src/core/gated.ts +6 -5
- package/src/core/pagination.ts +4 -3
- package/src/generated/operations.ts +42 -2
- package/src/generated/types.ts +54 -1
- package/src/index.ts +5 -0
- package/src/resources/approvals.ts +11 -1
- package/src/resources/transferDrafts.ts +157 -0
- package/src/resources/transfers.ts +18 -2
- package/src/version.ts +1 -1
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
// resource method calls an operation that exists, and that a new endpoint in
|
|
9
9
|
// the API does not slip in unclassified.
|
|
10
10
|
//
|
|
11
|
-
// Operations:
|
|
12
|
-
// Spec sha256:
|
|
11
|
+
// Operations: 176 · admin: 40 · both: 1 · member: 132 · service: 3
|
|
12
|
+
// Spec sha256: 3f66bcf8b439b4191942fd7876ba49285175222aa6171727591a5cb0f5f6c5b6
|
|
13
13
|
|
|
14
14
|
export type Audience = 'member' | 'admin' | 'service' | 'both' | 'unknown'
|
|
15
15
|
|
|
@@ -160,6 +160,14 @@ export const OPERATIONS = {
|
|
|
160
160
|
"summary": "Отказаться от доступа, который мне выдали",
|
|
161
161
|
"audience": "member"
|
|
162
162
|
},
|
|
163
|
+
"DELETE /api/v1/vaults/{code}/transfer-drafts/{id}": {
|
|
164
|
+
"method": "delete",
|
|
165
|
+
"path": "/api/v1/vaults/{code}/transfer-drafts/{id}",
|
|
166
|
+
"operationId": "deleteApiV1VaultsByCodeTransferDraftsById",
|
|
167
|
+
"tag": "Transfer drafts",
|
|
168
|
+
"summary": "Удалить черновик",
|
|
169
|
+
"audience": "member"
|
|
170
|
+
},
|
|
163
171
|
"DELETE /api/v1/vaults/{code}/visibility-grants/{id}": {
|
|
164
172
|
"method": "delete",
|
|
165
173
|
"path": "/api/v1/vaults/{code}/visibility-grants/{id}",
|
|
@@ -792,6 +800,22 @@ export const OPERATIONS = {
|
|
|
792
800
|
"summary": "Адреса, расшаренные мне (прямые гранты на адрес)",
|
|
793
801
|
"audience": "member"
|
|
794
802
|
},
|
|
803
|
+
"GET /api/v1/vaults/{code}/transfer-drafts": {
|
|
804
|
+
"method": "get",
|
|
805
|
+
"path": "/api/v1/vaults/{code}/transfer-drafts",
|
|
806
|
+
"operationId": "getApiV1VaultsByCodeTransferDrafts",
|
|
807
|
+
"tag": "Transfer drafts",
|
|
808
|
+
"summary": "Мои черновики переводов",
|
|
809
|
+
"audience": "member"
|
|
810
|
+
},
|
|
811
|
+
"GET /api/v1/vaults/{code}/transfer-drafts/{id}": {
|
|
812
|
+
"method": "get",
|
|
813
|
+
"path": "/api/v1/vaults/{code}/transfer-drafts/{id}",
|
|
814
|
+
"operationId": "getApiV1VaultsByCodeTransferDraftsById",
|
|
815
|
+
"tag": "Transfer drafts",
|
|
816
|
+
"summary": "Черновик перевода",
|
|
817
|
+
"audience": "member"
|
|
818
|
+
},
|
|
795
819
|
"GET /api/v1/vaults/{code}/transfers/{id}": {
|
|
796
820
|
"method": "get",
|
|
797
821
|
"path": "/api/v1/vaults/{code}/transfers/{id}",
|
|
@@ -1344,6 +1368,22 @@ export const OPERATIONS = {
|
|
|
1344
1368
|
"summary": "Создать место (приглашение по ссылке)",
|
|
1345
1369
|
"audience": "admin"
|
|
1346
1370
|
},
|
|
1371
|
+
"POST /api/v1/vaults/{code}/transfer-drafts": {
|
|
1372
|
+
"method": "post",
|
|
1373
|
+
"path": "/api/v1/vaults/{code}/transfer-drafts",
|
|
1374
|
+
"operationId": "postApiV1VaultsByCodeTransferDrafts",
|
|
1375
|
+
"tag": "Transfer drafts",
|
|
1376
|
+
"summary": "Создать черновик перевода",
|
|
1377
|
+
"audience": "member"
|
|
1378
|
+
},
|
|
1379
|
+
"POST /api/v1/vaults/{code}/transfer-drafts/{id}/send": {
|
|
1380
|
+
"method": "post",
|
|
1381
|
+
"path": "/api/v1/vaults/{code}/transfer-drafts/{id}/send",
|
|
1382
|
+
"operationId": "postApiV1VaultsByCodeTransferDraftsByIdSend",
|
|
1383
|
+
"tag": "Transfer drafts",
|
|
1384
|
+
"summary": "Отправить черновик (только из мобильного приложения)",
|
|
1385
|
+
"audience": "member"
|
|
1386
|
+
},
|
|
1347
1387
|
"POST /api/v1/vaults/{code}/transfers": {
|
|
1348
1388
|
"method": "post",
|
|
1349
1389
|
"path": "/api/v1/vaults/{code}/transfers",
|
package/src/generated/types.ts
CHANGED
|
@@ -1750,13 +1750,25 @@ export interface CreateTransferBody {
|
|
|
1750
1750
|
amount: string
|
|
1751
1751
|
asset: string
|
|
1752
1752
|
/**
|
|
1753
|
-
* Уникальный ключ попытки перевода (рекомендуется: uuid). Повторный запрос с тем же ключом и теми же параметрами вернёт 200 с существующим переводом — без второго broadcast, без повторной оценки политик. Тот же ключ с другими параметрами — 409 IDEMPOTENCY_KEY_REUSED. Для новой попытки после failed — новый ключ.
|
|
1753
|
+
* Уникальный ключ попытки перевода (рекомендуется: uuid). Повторный запрос с тем же ключом и теми же параметрами вернёт 200 с существующим переводом — без второго broadcast, без повторной оценки политик. Тот же ключ с другими параметрами — 409 IDEMPOTENCY_KEY_REUSED. Для новой попытки после failed — новый ключ. Префикс `draft:` зарезервирован за отправкой черновиков — такой ключ отвергается (400).
|
|
1754
1754
|
*
|
|
1755
1755
|
* length: 8..128
|
|
1756
1756
|
*/
|
|
1757
1757
|
idempotencyKey?: string
|
|
1758
1758
|
}
|
|
1759
1759
|
|
|
1760
|
+
/** Параметры будущего перевода. Ключа идемпотентности нет: повтор создаёт второй черновик (лишний удаляется). Контрагент не хранится — его подбирают по адресу получателя при отправке, как у обычного перевода */
|
|
1761
|
+
export interface CreateTransferDraftBody {
|
|
1762
|
+
/** Адрес-отправитель: нужен доступ на перевод с него (владелец / admin / грант) */
|
|
1763
|
+
fromAddressId: string
|
|
1764
|
+
/** Адрес получателя. Формат проверяется по типу сети адреса-отправителя, как у POST /transfers: не подошёл — 400 INVALID_DESTINATION_ADDRESS. Строка хранится как есть */
|
|
1765
|
+
toAddress: string
|
|
1766
|
+
/** DECIMAL строка, как у POST /transfers — хранится в минимальных единицах токена */
|
|
1767
|
+
amount: string
|
|
1768
|
+
/** Код токена (Token.code) */
|
|
1769
|
+
asset: string
|
|
1770
|
+
}
|
|
1771
|
+
|
|
1760
1772
|
export interface CreateVaultBody {
|
|
1761
1773
|
vault: {
|
|
1762
1774
|
code: string
|
|
@@ -2276,6 +2288,8 @@ export interface MeVaultResponse {
|
|
|
2276
2288
|
name: string
|
|
2277
2289
|
description: string | null
|
|
2278
2290
|
walletServiceUrl: string | null
|
|
2291
|
+
/** Подключён ли к Vault'у сервис подписи (адрес задан и не пуст). Без него создать адрес и отправить перевод нельзя — сервер откажет. Признак заменяет вывод «есть ли подпись» из `walletServiceUrl`: адрес внутреннего сервиса — сведения для администраторов, клиенту нужен только ответ «можно или нет». */
|
|
2292
|
+
signingConfigured: boolean
|
|
2279
2293
|
lockedAt: string | null
|
|
2280
2294
|
networks: Array<{
|
|
2281
2295
|
/** cuid */
|
|
@@ -3446,6 +3460,45 @@ export interface TransferApprover {
|
|
|
3446
3460
|
user: UserCard | null
|
|
3447
3461
|
}
|
|
3448
3462
|
|
|
3463
|
+
export interface TransferDraftResult {
|
|
3464
|
+
draft: TransferDraft
|
|
3465
|
+
}
|
|
3466
|
+
|
|
3467
|
+
export interface TransferDraft {
|
|
3468
|
+
/** cuid */
|
|
3469
|
+
id: string
|
|
3470
|
+
/** draft — ждёт отправки из приложения; sent — перевод создан (его исход — в transactionId: `sent` НЕ значит «деньги ушли»); discarded — удалён, перевод по нему не создавался */
|
|
3471
|
+
status: "draft" | "sent" | "discarded"
|
|
3472
|
+
fromAddress: {
|
|
3473
|
+
/** cuid */
|
|
3474
|
+
id: string
|
|
3475
|
+
address: string
|
|
3476
|
+
label: string | null
|
|
3477
|
+
/** Network.slug — сеть перевода */
|
|
3478
|
+
network: string
|
|
3479
|
+
}
|
|
3480
|
+
toAddress: string
|
|
3481
|
+
/** raw smallest units */
|
|
3482
|
+
amount: string
|
|
3483
|
+
/** Сумма по decimals токена; null — токена нет в реестре */
|
|
3484
|
+
amountDecimal: string | null
|
|
3485
|
+
/** Token.code */
|
|
3486
|
+
asset: string
|
|
3487
|
+
/** Символ токена; null — токена нет в реестре */
|
|
3488
|
+
assetSymbol: string | null
|
|
3489
|
+
/** Перевод, созданный отправкой (у sent); иначе null */
|
|
3490
|
+
transactionId: string | null
|
|
3491
|
+
/** format: date-time */
|
|
3492
|
+
createdAt: string
|
|
3493
|
+
sentAt: string | null
|
|
3494
|
+
discardedAt: string | null
|
|
3495
|
+
}
|
|
3496
|
+
|
|
3497
|
+
export interface TransferDraftsPage {
|
|
3498
|
+
items: TransferDraft[]
|
|
3499
|
+
nextCursor: string | null
|
|
3500
|
+
}
|
|
3501
|
+
|
|
3449
3502
|
export interface UserGroupDetail {
|
|
3450
3503
|
id: string
|
|
3451
3504
|
name: string
|
package/src/index.ts
CHANGED
|
@@ -89,6 +89,11 @@ export {
|
|
|
89
89
|
} from './resources/addresses.js'
|
|
90
90
|
|
|
91
91
|
export { TransfersResource, type VoteInput } from './resources/transfers.js'
|
|
92
|
+
export {
|
|
93
|
+
TransferDraftsResource,
|
|
94
|
+
type ListTransferDraftsParams,
|
|
95
|
+
type TransferDraftStatus,
|
|
96
|
+
} from './resources/transferDrafts.js'
|
|
92
97
|
export {
|
|
93
98
|
HistoryResource,
|
|
94
99
|
type HistoryParams,
|
|
@@ -101,6 +101,12 @@ export class ApprovalsResource {
|
|
|
101
101
|
* an earlier call left undone (it recorded the vote and broke off) — a veto,
|
|
102
102
|
* or an approval once the threshold is met — instead of 409
|
|
103
103
|
* `ALREADY_VOTED`.
|
|
104
|
+
*
|
|
105
|
+
* Signatures are given from the mobile app; from a browser only by a
|
|
106
|
+
* platform administrator; from a web login by nobody (the table is on
|
|
107
|
+
* `TransferDraftsResource`). Any other session gets 403
|
|
108
|
+
* `WEB_SESSION_CANNOT_SIGN` here, on a request of any kind. `cancel()` of
|
|
109
|
+
* your own request is open to any session.
|
|
104
110
|
*/
|
|
105
111
|
vote(requestId: string, input: VoteBody): Promise<RequestVoteResult> {
|
|
106
112
|
return this.#http.request<RequestVoteResult>(
|
|
@@ -115,7 +121,11 @@ export class ApprovalsResource {
|
|
|
115
121
|
*
|
|
116
122
|
* Only while the request is `PENDING`, and only as its initiator or as an
|
|
117
123
|
* admin — the admin case exists so a request whose initiator is gone can
|
|
118
|
-
* still be cleared instead of holding the reserve forever.
|
|
124
|
+
* still be cleared instead of holding the reserve forever. Cancelling
|
|
125
|
+
* someone else's is a "no" like a veto, so only from a session that may
|
|
126
|
+
* sign: an administrator from the mobile app, a platform administrator also
|
|
127
|
+
* from a browser. Otherwise 403 `NOT_INITIATOR`. Your own is cancelled from
|
|
128
|
+
* any session.
|
|
119
129
|
*
|
|
120
130
|
* @param reason IGNORED BY THE SERVER, and no longer sent. The endpoint
|
|
121
131
|
* declares no request body and the handler never reads one, so the reason
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { seg, type HttpClient } from '../core/http.js'
|
|
2
|
+
import type { PageParams } from '../core/pagination.js'
|
|
3
|
+
import { toGated, type Gated } from '../core/gated.js'
|
|
4
|
+
import type {
|
|
5
|
+
CreateTransactionResult,
|
|
6
|
+
CreateTransferDraftBody,
|
|
7
|
+
TransferDraft,
|
|
8
|
+
TransferDraftResult,
|
|
9
|
+
TransferDraftsPage,
|
|
10
|
+
} from '../generated/types.js'
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* `draft` — waiting to be sent from the mobile app; `sent` — a transfer was
|
|
14
|
+
* created from it, which is NOT the same as "the money left" (read the
|
|
15
|
+
* transfer by `transactionId`); `discarded` — deleted, no transfer was created.
|
|
16
|
+
*/
|
|
17
|
+
export type TransferDraftStatus = TransferDraft['status']
|
|
18
|
+
|
|
19
|
+
export interface ListTransferDraftsParams extends PageParams {
|
|
20
|
+
/** One status. Omitted — every draft of yours, discarded ones included. */
|
|
21
|
+
status?: TransferDraftStatus | undefined
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Transfer drafts: how a transfer is prepared in a web session.
|
|
26
|
+
*
|
|
27
|
+
* Money is sent and signatures are given from the mobile app. Who may depends
|
|
28
|
+
* on how the session was obtained:
|
|
29
|
+
*
|
|
30
|
+
* mobile app — anyone (an older session, issued before the API told
|
|
31
|
+
* sessions apart, counts as one);
|
|
32
|
+
* browser — signed in by the email link, as the admin panel is: a
|
|
33
|
+
* platform administrator only;
|
|
34
|
+
* web login — nobody, a platform administrator included.
|
|
35
|
+
*
|
|
36
|
+
* A session that may not is refused with 403 `WEB_SESSION_CANNOT_SIGN` on
|
|
37
|
+
* `transfers.send`, `transfers.vote`, `transfers.reconcile`, `approvals.vote`
|
|
38
|
+
* and `send` below — the refusal is the server's, so hiding a button in a web
|
|
39
|
+
* client is not what enforces it. What a web session can do is create a
|
|
40
|
+
* draft: the API pushes it to the author's mobile devices, and the author
|
|
41
|
+
* sends it from there. Cancelling your OWN transfer or request is open to any
|
|
42
|
+
* session.
|
|
43
|
+
*
|
|
44
|
+
* A draft is seen and touched ONLY by its author — an administrator included.
|
|
45
|
+
* Anyone else's draft, a missing one and one from another vault all answer
|
|
46
|
+
* the same 404 `TRANSFER_DRAFT_NOT_FOUND`.
|
|
47
|
+
*
|
|
48
|
+
* A draft is immutable: for other parameters create a new one and discard the
|
|
49
|
+
* old.
|
|
50
|
+
*/
|
|
51
|
+
export class TransferDraftsResource {
|
|
52
|
+
readonly #http: HttpClient
|
|
53
|
+
readonly #base: string
|
|
54
|
+
|
|
55
|
+
constructor(http: HttpClient, vaultCode: string) {
|
|
56
|
+
this.#http = http
|
|
57
|
+
this.#base = `/api/v1/vaults/${seg(vaultCode)}/transfer-drafts`
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Creates a draft. Allowed in a web session — that is what it is for.
|
|
62
|
+
*
|
|
63
|
+
* Checked as `transfers.send` checks, with the same codes: the address
|
|
64
|
+
* (404 `ADDRESS_NOT_FOUND`, 400 `ADDRESS_NOT_IN_VAULT`), the right to
|
|
65
|
+
* transfer from it (403 `ADDRESS_TRANSFER_FORBIDDEN`), the token (400
|
|
66
|
+
* `TOKEN_NOT_FOUND`, `TOKEN_NETWORK_MISMATCH`), the amount (400
|
|
67
|
+
* `INVALID_AMOUNT`) and the recipient's format (400
|
|
68
|
+
* `INVALID_DESTINATION_ADDRESS`). AML, policies and the balance are NOT
|
|
69
|
+
* checked here: they are decided when the draft is sent.
|
|
70
|
+
*
|
|
71
|
+
* `amount` is a decimal string, as in `transfers.send`; the draft keeps it
|
|
72
|
+
* in smallest units (`draft.amount`) beside `amountDecimal`.
|
|
73
|
+
*
|
|
74
|
+
* There is no idempotency key: a retry creates a second draft. After
|
|
75
|
+
* creation the author gets a push on their mobile devices (`data.type` is
|
|
76
|
+
* `transfer_draft_created`, with `draftId`); a failed push does not fail
|
|
77
|
+
* the call.
|
|
78
|
+
*/
|
|
79
|
+
create(input: CreateTransferDraftBody): Promise<TransferDraftResult> {
|
|
80
|
+
return this.#http.request<TransferDraftResult>('POST', this.#base, { body: input })
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Your own drafts, newest first. Keyset-paginated: `{items, nextCursor}`. */
|
|
84
|
+
list(params: ListTransferDraftsParams = {}): Promise<TransferDraftsPage> {
|
|
85
|
+
return this.#http.request<TransferDraftsPage>('GET', this.#base, { query: { ...params } })
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
get(draftId: string): Promise<TransferDraftResult> {
|
|
89
|
+
return this.#http.request<TransferDraftResult>('GET', `${this.#base}/${seg(draftId)}`)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Deletes a draft — softly: `draft` becomes `discarded`, and it can no
|
|
94
|
+
* longer be sent. Discarding one already discarded answers 200 with the
|
|
95
|
+
* same draft. Allowed in a web session.
|
|
96
|
+
*
|
|
97
|
+
* A draft a transfer was created from is 409 `TRANSFER_DRAFT_ALREADY_SENT`,
|
|
98
|
+
* with `details.transactionId`: discarding it does not undo the transfer.
|
|
99
|
+
* A transfer still awaiting signatures is withdrawn with
|
|
100
|
+
* `transfers.cancel()`. The same 409 comes back when the transfer exists
|
|
101
|
+
* but the draft is not marked `sent` yet — it is being sent from a phone
|
|
102
|
+
* right now, or that send broke off — and the mark is written then.
|
|
103
|
+
*/
|
|
104
|
+
discard(draftId: string): Promise<TransferDraftResult> {
|
|
105
|
+
return this.#http.request<TransferDraftResult>('DELETE', `${this.#base}/${seg(draftId)}`)
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Sends a draft: creates the transfer the same way `transfers.send` does —
|
|
110
|
+
* address right, token, amount, recipient, AML, policies, limits,
|
|
111
|
+
* signatures, reserve. Only the author can, and only from a session that may
|
|
112
|
+
* send money (see the class): a web login, or a browser of anyone but a
|
|
113
|
+
* platform administrator, gets 403 `WEB_SESSION_CANNOT_SIGN`. There is no
|
|
114
|
+
* body; the parameters come from the draft alone.
|
|
115
|
+
*
|
|
116
|
+
* The answer is exactly that of `transfers.send`, and so are its errors:
|
|
117
|
+
* `applied` (201), `pending` (202 — waiting for signatures, funds
|
|
118
|
+
* reserved) or `replayed` (200). Read the TSDoc of `TransfersResource` on
|
|
119
|
+
* what each means; the timeout caveats of a money path apply here too.
|
|
120
|
+
*
|
|
121
|
+
* A DRAFT IS SENT ONCE. The transfer's idempotency key is derived from the
|
|
122
|
+
* draft, so a repeated send — a double tap, a second phone, a retry after a
|
|
123
|
+
* broken connection — returns the SAME transfer as `replayed`, as it stands
|
|
124
|
+
* now, and never a second one. That holds after `failed` too: a transfer
|
|
125
|
+
* from a draft is not sent again; a new attempt is an ordinary transfer.
|
|
126
|
+
* `replayed` does not mean the money left — read
|
|
127
|
+
* `data.transaction.status`.
|
|
128
|
+
*
|
|
129
|
+
* A refusal before the transfer exists (policy, balance, unsatisfiable
|
|
130
|
+
* approval, token) leaves the draft a `draft`, to send later or discard.
|
|
131
|
+
* Once the transfer exists — `failed` after the gas station and 502
|
|
132
|
+
* `TRANSFER_OUTCOME_UNKNOWN` included — the draft is `sent` with
|
|
133
|
+
* `transactionId`. A discarded draft with no transfer is 409
|
|
134
|
+
* `TRANSFER_DRAFT_DISCARDED`.
|
|
135
|
+
*
|
|
136
|
+
* The token is resolved before the replay: if the draft's token was
|
|
137
|
+
* disabled after it was sent, a repeated send answers 400
|
|
138
|
+
* `TOKEN_NOT_FOUND` instead of the transfer. No new transfer is created
|
|
139
|
+
* either way; read it by the draft's `transactionId`.
|
|
140
|
+
*/
|
|
141
|
+
async send(
|
|
142
|
+
draftId: string,
|
|
143
|
+
options: { signal?: AbortSignal; timeoutMs?: number } = {},
|
|
144
|
+
): Promise<Gated<CreateTransactionResult>> {
|
|
145
|
+
const res = await this.#http.requestRaw<CreateTransactionResult>(
|
|
146
|
+
'POST',
|
|
147
|
+
`${this.#base}/${seg(draftId)}/send`,
|
|
148
|
+
{
|
|
149
|
+
...(options.signal === undefined ? {} : { signal: options.signal }),
|
|
150
|
+
...(options.timeoutMs === undefined ? {} : { timeoutMs: options.timeoutMs }),
|
|
151
|
+
},
|
|
152
|
+
)
|
|
153
|
+
return toGated<CreateTransactionResult, CreateTransactionResult>(res.status, res.data, {
|
|
154
|
+
replayOn200: true,
|
|
155
|
+
})
|
|
156
|
+
}
|
|
157
|
+
}
|
|
@@ -43,6 +43,14 @@ export interface VoteInput {
|
|
|
43
43
|
* administrator reconciles it;
|
|
44
44
|
* failed, rejected,
|
|
45
45
|
* cancelled — it did not leave.
|
|
46
|
+
*
|
|
47
|
+
* `send`, `vote` and `reconcile` move money or give a signature, and they are
|
|
48
|
+
* refused with 403 `WEB_SESSION_CANNOT_SIGN` to a session that may not: money
|
|
49
|
+
* is sent and signatures are given from the mobile app; from a browser only
|
|
50
|
+
* by a platform administrator; from a web login by nobody (the table is on
|
|
51
|
+
* `TransferDraftsResource`). A web client prepares a transfer with
|
|
52
|
+
* `transferDrafts.create()` instead. `cancel` of your own transfer is open to
|
|
53
|
+
* any session.
|
|
46
54
|
*/
|
|
47
55
|
export class TransfersResource {
|
|
48
56
|
readonly #http: HttpClient
|
|
@@ -65,6 +73,9 @@ export class TransfersResource {
|
|
|
65
73
|
* transfer stays `pending` with its funds reserved (`details.transactionId`).
|
|
66
74
|
* Retry it only with the SAME key — that returns the transfer without
|
|
67
75
|
* executing it again; a new key can send the money twice.
|
|
76
|
+
*
|
|
77
|
+
* A key beginning with `draft:` is refused with 400 `BAD_REQUEST`: the
|
|
78
|
+
* prefix is reserved for the transfers `transferDrafts.send()` creates.
|
|
68
79
|
*/
|
|
69
80
|
async send(
|
|
70
81
|
input: CreateTransferBody,
|
|
@@ -142,7 +153,10 @@ export class TransfersResource {
|
|
|
142
153
|
* Cancels your own transfer that is awaiting signatures and releases the
|
|
143
154
|
* reserve. A transfer already broadcast cannot be cancelled; administrators
|
|
144
155
|
* may cancel somebody else's, so a stuck request is not hostage to an
|
|
145
|
-
* absent initiator
|
|
156
|
+
* absent initiator — but cancelling someone else's is a "no" like a veto,
|
|
157
|
+
* so only from a session that may sign: an administrator from the mobile
|
|
158
|
+
* app, a platform administrator also from a browser. Otherwise 403
|
|
159
|
+
* `NOT_INITIATOR`. Your own is cancelled from any session.
|
|
146
160
|
*
|
|
147
161
|
* The resulting status is its own value, `cancelled` — not the `rejected`
|
|
148
162
|
* of a veto and not `failed`. Worth keeping apart in the interface: "you
|
|
@@ -157,7 +171,9 @@ export class TransfersResource {
|
|
|
157
171
|
}
|
|
158
172
|
|
|
159
173
|
/**
|
|
160
|
-
* Settles a transfer nothing else can close.
|
|
174
|
+
* Settles a transfer nothing else can close. Platform administrators only,
|
|
175
|
+
* and not from a web-login session: 403 `WEB_SESSION_CANNOT_SIGN` (a browser
|
|
176
|
+
* or the mobile app is fine).
|
|
161
177
|
*
|
|
162
178
|
* pending — execution died, or its outcome is unknown (the
|
|
163
179
|
* send answered 502 `TRANSFER_OUTCOME_UNKNOWN`);
|
package/src/version.ts
CHANGED