@v3finance/core-sdk 0.2.4 → 0.3.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 +74 -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 +51 -2
- 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 +51 -2
- 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 +55 -2
- 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
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { type HttpClient } from '../core/http.js';
|
|
2
|
+
import type { PageParams } from '../core/pagination.js';
|
|
3
|
+
import { type Gated } from '../core/gated.js';
|
|
4
|
+
import type { CreateTransactionResult, CreateTransferDraftBody, TransferDraft, TransferDraftResult, TransferDraftsPage } from '../generated/types.js';
|
|
5
|
+
/**
|
|
6
|
+
* `draft` — waiting to be sent from the mobile app; `sent` — a transfer was
|
|
7
|
+
* created from it, which is NOT the same as "the money left" (read the
|
|
8
|
+
* transfer by `transactionId`); `discarded` — deleted, no transfer was created.
|
|
9
|
+
*/
|
|
10
|
+
export type TransferDraftStatus = TransferDraft['status'];
|
|
11
|
+
export interface ListTransferDraftsParams extends PageParams {
|
|
12
|
+
/** One status. Omitted — every draft of yours, discarded ones included. */
|
|
13
|
+
status?: TransferDraftStatus | undefined;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Transfer drafts: how a transfer is prepared in a web session.
|
|
17
|
+
*
|
|
18
|
+
* Money is sent and signatures are given from the mobile app. Who may depends
|
|
19
|
+
* on how the session was obtained:
|
|
20
|
+
*
|
|
21
|
+
* mobile app — anyone (an older session, issued before the API told
|
|
22
|
+
* sessions apart, counts as one);
|
|
23
|
+
* browser — signed in by the email link, as the admin panel is: a
|
|
24
|
+
* platform administrator only;
|
|
25
|
+
* web login — nobody, a platform administrator included.
|
|
26
|
+
*
|
|
27
|
+
* A session that may not is refused with 403 `WEB_SESSION_CANNOT_SIGN` on
|
|
28
|
+
* `transfers.send`, `transfers.vote`, `transfers.reconcile`, `approvals.vote`
|
|
29
|
+
* and `send` below — the refusal is the server's, so hiding a button in a web
|
|
30
|
+
* client is not what enforces it. What a web session can do is create a
|
|
31
|
+
* draft: the API pushes it to the author's mobile devices, and the author
|
|
32
|
+
* sends it from there. Cancelling your OWN transfer or request is open to any
|
|
33
|
+
* session.
|
|
34
|
+
*
|
|
35
|
+
* A draft is seen and touched ONLY by its author — an administrator included.
|
|
36
|
+
* Anyone else's draft, a missing one and one from another vault all answer
|
|
37
|
+
* the same 404 `TRANSFER_DRAFT_NOT_FOUND`.
|
|
38
|
+
*
|
|
39
|
+
* A draft is immutable: for other parameters create a new one and discard the
|
|
40
|
+
* old.
|
|
41
|
+
*/
|
|
42
|
+
export declare class TransferDraftsResource {
|
|
43
|
+
#private;
|
|
44
|
+
constructor(http: HttpClient, vaultCode: string);
|
|
45
|
+
/**
|
|
46
|
+
* Creates a draft. Allowed in a web session — that is what it is for.
|
|
47
|
+
*
|
|
48
|
+
* Checked as `transfers.send` checks, with the same codes: the address
|
|
49
|
+
* (404 `ADDRESS_NOT_FOUND`, 400 `ADDRESS_NOT_IN_VAULT`), the right to
|
|
50
|
+
* transfer from it (403 `ADDRESS_TRANSFER_FORBIDDEN`), the token (400
|
|
51
|
+
* `TOKEN_NOT_FOUND`, `TOKEN_NETWORK_MISMATCH`), the amount (400
|
|
52
|
+
* `INVALID_AMOUNT`) and the recipient's format (400
|
|
53
|
+
* `INVALID_DESTINATION_ADDRESS`). AML, policies and the balance are NOT
|
|
54
|
+
* checked here: they are decided when the draft is sent.
|
|
55
|
+
*
|
|
56
|
+
* `amount` is a decimal string, as in `transfers.send`; the draft keeps it
|
|
57
|
+
* in smallest units (`draft.amount`) beside `amountDecimal`.
|
|
58
|
+
*
|
|
59
|
+
* There is no idempotency key: a retry creates a second draft. After
|
|
60
|
+
* creation the author gets a push on their mobile devices (`data.type` is
|
|
61
|
+
* `transfer_draft_created`, with `draftId`); a failed push does not fail
|
|
62
|
+
* the call.
|
|
63
|
+
*/
|
|
64
|
+
create(input: CreateTransferDraftBody): Promise<TransferDraftResult>;
|
|
65
|
+
/** Your own drafts, newest first. Keyset-paginated: `{items, nextCursor}`. */
|
|
66
|
+
list(params?: ListTransferDraftsParams): Promise<TransferDraftsPage>;
|
|
67
|
+
get(draftId: string): Promise<TransferDraftResult>;
|
|
68
|
+
/**
|
|
69
|
+
* Deletes a draft — softly: `draft` becomes `discarded`, and it can no
|
|
70
|
+
* longer be sent. Discarding one already discarded answers 200 with the
|
|
71
|
+
* same draft. Allowed in a web session.
|
|
72
|
+
*
|
|
73
|
+
* A draft a transfer was created from is 409 `TRANSFER_DRAFT_ALREADY_SENT`,
|
|
74
|
+
* with `details.transactionId`: discarding it does not undo the transfer.
|
|
75
|
+
* A transfer still awaiting signatures is withdrawn with
|
|
76
|
+
* `transfers.cancel()`. The same 409 comes back when the transfer exists
|
|
77
|
+
* but the draft is not marked `sent` yet — it is being sent from a phone
|
|
78
|
+
* right now, or that send broke off — and the mark is written then.
|
|
79
|
+
*/
|
|
80
|
+
discard(draftId: string): Promise<TransferDraftResult>;
|
|
81
|
+
/**
|
|
82
|
+
* Sends a draft: creates the transfer the same way `transfers.send` does —
|
|
83
|
+
* address right, token, amount, recipient, AML, policies, limits,
|
|
84
|
+
* signatures, reserve. Only the author can, and only from a session that may
|
|
85
|
+
* send money (see the class): a web login, or a browser of anyone but a
|
|
86
|
+
* platform administrator, gets 403 `WEB_SESSION_CANNOT_SIGN`. There is no
|
|
87
|
+
* body; the parameters come from the draft alone.
|
|
88
|
+
*
|
|
89
|
+
* The answer is exactly that of `transfers.send`, and so are its errors:
|
|
90
|
+
* `applied` (201), `pending` (202 — waiting for signatures, funds
|
|
91
|
+
* reserved) or `replayed` (200). Read the TSDoc of `TransfersResource` on
|
|
92
|
+
* what each means; the timeout caveats of a money path apply here too.
|
|
93
|
+
*
|
|
94
|
+
* A DRAFT IS SENT ONCE. The transfer's idempotency key is derived from the
|
|
95
|
+
* draft, so a repeated send — a double tap, a second phone, a retry after a
|
|
96
|
+
* broken connection — returns the SAME transfer as `replayed`, as it stands
|
|
97
|
+
* now, and never a second one. That holds after `failed` too: a transfer
|
|
98
|
+
* from a draft is not sent again; a new attempt is an ordinary transfer.
|
|
99
|
+
* `replayed` does not mean the money left — read
|
|
100
|
+
* `data.transaction.status`.
|
|
101
|
+
*
|
|
102
|
+
* A refusal before the transfer exists (policy, balance, unsatisfiable
|
|
103
|
+
* approval, token) leaves the draft a `draft`, to send later or discard.
|
|
104
|
+
* Once the transfer exists — `failed` after the gas station and 502
|
|
105
|
+
* `TRANSFER_OUTCOME_UNKNOWN` included — the draft is `sent` with
|
|
106
|
+
* `transactionId`. A discarded draft with no transfer is 409
|
|
107
|
+
* `TRANSFER_DRAFT_DISCARDED`.
|
|
108
|
+
*
|
|
109
|
+
* The token is resolved before the replay: if the draft's token was
|
|
110
|
+
* disabled after it was sent, a repeated send answers 400
|
|
111
|
+
* `TOKEN_NOT_FOUND` instead of the transfer. No new transfer is created
|
|
112
|
+
* either way; read it by the draft's `transactionId`.
|
|
113
|
+
*/
|
|
114
|
+
send(draftId: string, options?: {
|
|
115
|
+
signal?: AbortSignal;
|
|
116
|
+
timeoutMs?: number;
|
|
117
|
+
}): Promise<Gated<CreateTransactionResult>>;
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=transferDrafts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transferDrafts.d.ts","sourceRoot":"","sources":["../../../src/resources/transferDrafts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAA;AACtD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AACvD,OAAO,EAAW,KAAK,KAAK,EAAE,MAAM,kBAAkB,CAAA;AACtD,OAAO,KAAK,EACV,uBAAuB,EACvB,uBAAuB,EACvB,aAAa,EACb,mBAAmB,EACnB,kBAAkB,EACnB,MAAM,uBAAuB,CAAA;AAE9B;;;;GAIG;AACH,MAAM,MAAM,mBAAmB,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAA;AAEzD,MAAM,WAAW,wBAAyB,SAAQ,UAAU;IAC1D,2EAA2E;IAC3E,MAAM,CAAC,EAAE,mBAAmB,GAAG,SAAS,CAAA;CACzC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,qBAAa,sBAAsB;;IAIjC,YAAY,IAAI,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAG9C;IAED;;;;;;;;;;;;;;;;;;OAkBG;IACH,MAAM,CAAC,KAAK,EAAE,uBAAuB,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAEnE;IAED,8EAA8E;IAC9E,IAAI,CAAC,MAAM,GAAE,wBAA6B,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAEvE;IAED,GAAG,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAEjD;IAED;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAErD;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAgCG;IACG,IAAI,CACR,OAAO,EAAE,MAAM,EACf,OAAO,GAAE;QAAE,MAAM,CAAC,EAAE,WAAW,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAO,GACzD,OAAO,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC,CAYzC;CACF"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { seg } from '../core/http.js';
|
|
2
|
+
import { toGated } from '../core/gated.js';
|
|
3
|
+
/**
|
|
4
|
+
* Transfer drafts: how a transfer is prepared in a web session.
|
|
5
|
+
*
|
|
6
|
+
* Money is sent and signatures are given from the mobile app. Who may depends
|
|
7
|
+
* on how the session was obtained:
|
|
8
|
+
*
|
|
9
|
+
* mobile app — anyone (an older session, issued before the API told
|
|
10
|
+
* sessions apart, counts as one);
|
|
11
|
+
* browser — signed in by the email link, as the admin panel is: a
|
|
12
|
+
* platform administrator only;
|
|
13
|
+
* web login — nobody, a platform administrator included.
|
|
14
|
+
*
|
|
15
|
+
* A session that may not is refused with 403 `WEB_SESSION_CANNOT_SIGN` on
|
|
16
|
+
* `transfers.send`, `transfers.vote`, `transfers.reconcile`, `approvals.vote`
|
|
17
|
+
* and `send` below — the refusal is the server's, so hiding a button in a web
|
|
18
|
+
* client is not what enforces it. What a web session can do is create a
|
|
19
|
+
* draft: the API pushes it to the author's mobile devices, and the author
|
|
20
|
+
* sends it from there. Cancelling your OWN transfer or request is open to any
|
|
21
|
+
* session.
|
|
22
|
+
*
|
|
23
|
+
* A draft is seen and touched ONLY by its author — an administrator included.
|
|
24
|
+
* Anyone else's draft, a missing one and one from another vault all answer
|
|
25
|
+
* the same 404 `TRANSFER_DRAFT_NOT_FOUND`.
|
|
26
|
+
*
|
|
27
|
+
* A draft is immutable: for other parameters create a new one and discard the
|
|
28
|
+
* old.
|
|
29
|
+
*/
|
|
30
|
+
export class TransferDraftsResource {
|
|
31
|
+
#http;
|
|
32
|
+
#base;
|
|
33
|
+
constructor(http, vaultCode) {
|
|
34
|
+
this.#http = http;
|
|
35
|
+
this.#base = `/api/v1/vaults/${seg(vaultCode)}/transfer-drafts`;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Creates a draft. Allowed in a web session — that is what it is for.
|
|
39
|
+
*
|
|
40
|
+
* Checked as `transfers.send` checks, with the same codes: the address
|
|
41
|
+
* (404 `ADDRESS_NOT_FOUND`, 400 `ADDRESS_NOT_IN_VAULT`), the right to
|
|
42
|
+
* transfer from it (403 `ADDRESS_TRANSFER_FORBIDDEN`), the token (400
|
|
43
|
+
* `TOKEN_NOT_FOUND`, `TOKEN_NETWORK_MISMATCH`), the amount (400
|
|
44
|
+
* `INVALID_AMOUNT`) and the recipient's format (400
|
|
45
|
+
* `INVALID_DESTINATION_ADDRESS`). AML, policies and the balance are NOT
|
|
46
|
+
* checked here: they are decided when the draft is sent.
|
|
47
|
+
*
|
|
48
|
+
* `amount` is a decimal string, as in `transfers.send`; the draft keeps it
|
|
49
|
+
* in smallest units (`draft.amount`) beside `amountDecimal`.
|
|
50
|
+
*
|
|
51
|
+
* There is no idempotency key: a retry creates a second draft. After
|
|
52
|
+
* creation the author gets a push on their mobile devices (`data.type` is
|
|
53
|
+
* `transfer_draft_created`, with `draftId`); a failed push does not fail
|
|
54
|
+
* the call.
|
|
55
|
+
*/
|
|
56
|
+
create(input) {
|
|
57
|
+
return this.#http.request('POST', this.#base, { body: input });
|
|
58
|
+
}
|
|
59
|
+
/** Your own drafts, newest first. Keyset-paginated: `{items, nextCursor}`. */
|
|
60
|
+
list(params = {}) {
|
|
61
|
+
return this.#http.request('GET', this.#base, { query: { ...params } });
|
|
62
|
+
}
|
|
63
|
+
get(draftId) {
|
|
64
|
+
return this.#http.request('GET', `${this.#base}/${seg(draftId)}`);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Deletes a draft — softly: `draft` becomes `discarded`, and it can no
|
|
68
|
+
* longer be sent. Discarding one already discarded answers 200 with the
|
|
69
|
+
* same draft. Allowed in a web session.
|
|
70
|
+
*
|
|
71
|
+
* A draft a transfer was created from is 409 `TRANSFER_DRAFT_ALREADY_SENT`,
|
|
72
|
+
* with `details.transactionId`: discarding it does not undo the transfer.
|
|
73
|
+
* A transfer still awaiting signatures is withdrawn with
|
|
74
|
+
* `transfers.cancel()`. The same 409 comes back when the transfer exists
|
|
75
|
+
* but the draft is not marked `sent` yet — it is being sent from a phone
|
|
76
|
+
* right now, or that send broke off — and the mark is written then.
|
|
77
|
+
*/
|
|
78
|
+
discard(draftId) {
|
|
79
|
+
return this.#http.request('DELETE', `${this.#base}/${seg(draftId)}`);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Sends a draft: creates the transfer the same way `transfers.send` does —
|
|
83
|
+
* address right, token, amount, recipient, AML, policies, limits,
|
|
84
|
+
* signatures, reserve. Only the author can, and only from a session that may
|
|
85
|
+
* send money (see the class): a web login, or a browser of anyone but a
|
|
86
|
+
* platform administrator, gets 403 `WEB_SESSION_CANNOT_SIGN`. There is no
|
|
87
|
+
* body; the parameters come from the draft alone.
|
|
88
|
+
*
|
|
89
|
+
* The answer is exactly that of `transfers.send`, and so are its errors:
|
|
90
|
+
* `applied` (201), `pending` (202 — waiting for signatures, funds
|
|
91
|
+
* reserved) or `replayed` (200). Read the TSDoc of `TransfersResource` on
|
|
92
|
+
* what each means; the timeout caveats of a money path apply here too.
|
|
93
|
+
*
|
|
94
|
+
* A DRAFT IS SENT ONCE. The transfer's idempotency key is derived from the
|
|
95
|
+
* draft, so a repeated send — a double tap, a second phone, a retry after a
|
|
96
|
+
* broken connection — returns the SAME transfer as `replayed`, as it stands
|
|
97
|
+
* now, and never a second one. That holds after `failed` too: a transfer
|
|
98
|
+
* from a draft is not sent again; a new attempt is an ordinary transfer.
|
|
99
|
+
* `replayed` does not mean the money left — read
|
|
100
|
+
* `data.transaction.status`.
|
|
101
|
+
*
|
|
102
|
+
* A refusal before the transfer exists (policy, balance, unsatisfiable
|
|
103
|
+
* approval, token) leaves the draft a `draft`, to send later or discard.
|
|
104
|
+
* Once the transfer exists — `failed` after the gas station and 502
|
|
105
|
+
* `TRANSFER_OUTCOME_UNKNOWN` included — the draft is `sent` with
|
|
106
|
+
* `transactionId`. A discarded draft with no transfer is 409
|
|
107
|
+
* `TRANSFER_DRAFT_DISCARDED`.
|
|
108
|
+
*
|
|
109
|
+
* The token is resolved before the replay: if the draft's token was
|
|
110
|
+
* disabled after it was sent, a repeated send answers 400
|
|
111
|
+
* `TOKEN_NOT_FOUND` instead of the transfer. No new transfer is created
|
|
112
|
+
* either way; read it by the draft's `transactionId`.
|
|
113
|
+
*/
|
|
114
|
+
async send(draftId, options = {}) {
|
|
115
|
+
const res = await this.#http.requestRaw('POST', `${this.#base}/${seg(draftId)}/send`, {
|
|
116
|
+
...(options.signal === undefined ? {} : { signal: options.signal }),
|
|
117
|
+
...(options.timeoutMs === undefined ? {} : { timeoutMs: options.timeoutMs }),
|
|
118
|
+
});
|
|
119
|
+
return toGated(res.status, res.data, {
|
|
120
|
+
replayOn200: true,
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=transferDrafts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transferDrafts.js","sourceRoot":"","sources":["../../../src/resources/transferDrafts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAmB,MAAM,iBAAiB,CAAA;AAEtD,OAAO,EAAE,OAAO,EAAc,MAAM,kBAAkB,CAAA;AAqBtD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,OAAO,sBAAsB;IACxB,KAAK,CAAY;IACjB,KAAK,CAAQ;IAEtB,YAAY,IAAgB,EAAE,SAAiB;QAC7C,IAAI,CAAC,KAAK,GAAG,IAAI,CAAA;QACjB,IAAI,CAAC,KAAK,GAAG,kBAAkB,GAAG,CAAC,SAAS,CAAC,kBAAkB,CAAA;IACjE,CAAC;IAED;;;;;;;;;;;;;;;;;;OAkBG;IACH,MAAM,CAAC,KAA8B;QACnC,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAsB,MAAM,EAAE,IAAI,CAAC,KAAK,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAA;IACrF,CAAC;IAED,8EAA8E;IAC9E,IAAI,CAAC,MAAM,GAA6B,EAAE;QACxC,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAqB,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,EAAE,GAAG,MAAM,EAAE,EAAE,CAAC,CAAA;IAC5F,CAAC;IAED,GAAG,CAAC,OAAe;QACjB,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAsB,KAAK,EAAE,GAAG,IAAI,CAAC,KAAK,IAAI,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;IACxF,CAAC;IAED;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,OAAe;QACrB,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAsB,QAAQ,EAAE,GAAG,IAAI,CAAC,KAAK,IAAI,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;IAC3F,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAgCG;IACH,KAAK,CAAC,IAAI,CACR,OAAe,EACf,OAAO,GAAiD,EAAE;QAE1D,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,UAAU,CACrC,MAAM,EACN,GAAG,IAAI,CAAC,KAAK,IAAI,GAAG,CAAC,OAAO,CAAC,OAAO,EACpC;YACE,GAAG,CAAC,OAAO,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC;YACnE,GAAG,CAAC,OAAO,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,CAAC;SAC7E,CACF,CAAA;QACD,OAAO,OAAO,CAAmD,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,IAAI,EAAE;YACrF,WAAW,EAAE,IAAI;SAClB,CAAC,CAAA;IACJ,CAAC;CACF"}
|
|
@@ -33,6 +33,14 @@ export interface VoteInput {
|
|
|
33
33
|
* administrator reconciles it;
|
|
34
34
|
* failed, rejected,
|
|
35
35
|
* cancelled — it did not leave.
|
|
36
|
+
*
|
|
37
|
+
* `send`, `vote` and `reconcile` move money or give a signature, and they are
|
|
38
|
+
* refused with 403 `WEB_SESSION_CANNOT_SIGN` to a session that may not: money
|
|
39
|
+
* is sent and signatures are given from the mobile app; from a browser only
|
|
40
|
+
* by a platform administrator; from a web login by nobody (the table is on
|
|
41
|
+
* `TransferDraftsResource`). A web client prepares a transfer with
|
|
42
|
+
* `transferDrafts.create()` instead. `cancel` of your own transfer is open to
|
|
43
|
+
* any session.
|
|
36
44
|
*/
|
|
37
45
|
export declare class TransfersResource {
|
|
38
46
|
#private;
|
|
@@ -49,6 +57,9 @@ export declare class TransfersResource {
|
|
|
49
57
|
* transfer stays `pending` with its funds reserved (`details.transactionId`).
|
|
50
58
|
* Retry it only with the SAME key — that returns the transfer without
|
|
51
59
|
* executing it again; a new key can send the money twice.
|
|
60
|
+
*
|
|
61
|
+
* A key beginning with `draft:` is refused with 400 `BAD_REQUEST`: the
|
|
62
|
+
* prefix is reserved for the transfers `transferDrafts.send()` creates.
|
|
52
63
|
*/
|
|
53
64
|
send(input: CreateTransferBody, options?: {
|
|
54
65
|
signal?: AbortSignal;
|
|
@@ -105,7 +116,10 @@ export declare class TransfersResource {
|
|
|
105
116
|
* Cancels your own transfer that is awaiting signatures and releases the
|
|
106
117
|
* reserve. A transfer already broadcast cannot be cancelled; administrators
|
|
107
118
|
* may cancel somebody else's, so a stuck request is not hostage to an
|
|
108
|
-
* absent initiator
|
|
119
|
+
* absent initiator — but cancelling someone else's is a "no" like a veto,
|
|
120
|
+
* so only from a session that may sign: an administrator from the mobile
|
|
121
|
+
* app, a platform administrator also from a browser. Otherwise 403
|
|
122
|
+
* `NOT_INITIATOR`. Your own is cancelled from any session.
|
|
109
123
|
*
|
|
110
124
|
* The resulting status is its own value, `cancelled` — not the `rejected`
|
|
111
125
|
* of a veto and not `failed`. Worth keeping apart in the interface: "you
|
|
@@ -117,7 +131,9 @@ export declare class TransfersResource {
|
|
|
117
131
|
*/
|
|
118
132
|
cancel(transferId: string): Promise<CancelResult>;
|
|
119
133
|
/**
|
|
120
|
-
* Settles a transfer nothing else can close.
|
|
134
|
+
* Settles a transfer nothing else can close. Platform administrators only,
|
|
135
|
+
* and not from a web-login session: 403 `WEB_SESSION_CANNOT_SIGN` (a browser
|
|
136
|
+
* or the mobile app is fine).
|
|
121
137
|
*
|
|
122
138
|
* pending — execution died, or its outcome is unknown (the
|
|
123
139
|
* send answered 502 `TRANSFER_OUTCOME_UNKNOWN`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transfers.d.ts","sourceRoot":"","sources":["../../../src/resources/transfers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAA;AACtD,OAAO,EAAW,KAAK,KAAK,EAAE,MAAM,kBAAkB,CAAA;AACtD,OAAO,KAAK,EACV,YAAY,EACZ,uBAAuB,EACvB,kBAAkB,EAClB,qBAAqB,EACrB,uBAAuB,EACvB,iBAAiB,EACjB,UAAU,EACX,MAAM,uBAAuB,CAAA;AAE9B,MAAM,WAAW,SAAS;IACxB,QAAQ,EAAE,SAAS,GAAG,QAAQ,CAAA;IAC9B,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAC7B;AAED
|
|
1
|
+
{"version":3,"file":"transfers.d.ts","sourceRoot":"","sources":["../../../src/resources/transfers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAA;AACtD,OAAO,EAAW,KAAK,KAAK,EAAE,MAAM,kBAAkB,CAAA;AACtD,OAAO,KAAK,EACV,YAAY,EACZ,uBAAuB,EACvB,kBAAkB,EAClB,qBAAqB,EACrB,uBAAuB,EACvB,iBAAiB,EACjB,UAAU,EACX,MAAM,uBAAuB,CAAA;AAE9B,MAAM,WAAW,SAAS;IACxB,QAAQ,EAAE,SAAS,GAAG,QAAQ,CAAA;IAC9B,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAC7B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,qBAAa,iBAAiB;;IAI5B,YAAY,IAAI,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAG9C;IAED;;;;;;;;;;;;;;;OAeG;IACG,IAAI,CACR,KAAK,EAAE,kBAAkB,EACzB,OAAO,GAAE;QAAE,MAAM,CAAC,EAAE,WAAW,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAO,GACzD,OAAO,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC,CAUzC;IAED;;;;;;OAMG;IACH,GAAG,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAElD;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAqCG;IACH,IAAI,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,GAAG,OAAO,CAAC,UAAU,CAAC,CAM9D;IAED;;;;;;;;;;;;;;;;OAgBG;IACH,MAAM,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,CAEhD;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA+BG;IACH,SAAS,CACP,UAAU,EAAE,MAAM,EAClB,KAAK,GAAE,qBAA0B,GAChC,OAAO,CAAC,uBAAuB,CAAC,CAMlC;CACF"}
|
|
@@ -28,6 +28,14 @@ import { toGated } from '../core/gated.js';
|
|
|
28
28
|
* administrator reconciles it;
|
|
29
29
|
* failed, rejected,
|
|
30
30
|
* cancelled — it did not leave.
|
|
31
|
+
*
|
|
32
|
+
* `send`, `vote` and `reconcile` move money or give a signature, and they are
|
|
33
|
+
* refused with 403 `WEB_SESSION_CANNOT_SIGN` to a session that may not: money
|
|
34
|
+
* is sent and signatures are given from the mobile app; from a browser only
|
|
35
|
+
* by a platform administrator; from a web login by nobody (the table is on
|
|
36
|
+
* `TransferDraftsResource`). A web client prepares a transfer with
|
|
37
|
+
* `transferDrafts.create()` instead. `cancel` of your own transfer is open to
|
|
38
|
+
* any session.
|
|
31
39
|
*/
|
|
32
40
|
export class TransfersResource {
|
|
33
41
|
#http;
|
|
@@ -48,6 +56,9 @@ export class TransfersResource {
|
|
|
48
56
|
* transfer stays `pending` with its funds reserved (`details.transactionId`).
|
|
49
57
|
* Retry it only with the SAME key — that returns the transfer without
|
|
50
58
|
* executing it again; a new key can send the money twice.
|
|
59
|
+
*
|
|
60
|
+
* A key beginning with `draft:` is refused with 400 `BAD_REQUEST`: the
|
|
61
|
+
* prefix is reserved for the transfers `transferDrafts.send()` creates.
|
|
51
62
|
*/
|
|
52
63
|
async send(input, options = {}) {
|
|
53
64
|
const res = await this.#http.requestRaw('POST', this.#base, {
|
|
@@ -115,7 +126,10 @@ export class TransfersResource {
|
|
|
115
126
|
* Cancels your own transfer that is awaiting signatures and releases the
|
|
116
127
|
* reserve. A transfer already broadcast cannot be cancelled; administrators
|
|
117
128
|
* may cancel somebody else's, so a stuck request is not hostage to an
|
|
118
|
-
* absent initiator
|
|
129
|
+
* absent initiator — but cancelling someone else's is a "no" like a veto,
|
|
130
|
+
* so only from a session that may sign: an administrator from the mobile
|
|
131
|
+
* app, a platform administrator also from a browser. Otherwise 403
|
|
132
|
+
* `NOT_INITIATOR`. Your own is cancelled from any session.
|
|
119
133
|
*
|
|
120
134
|
* The resulting status is its own value, `cancelled` — not the `rejected`
|
|
121
135
|
* of a veto and not `failed`. Worth keeping apart in the interface: "you
|
|
@@ -129,7 +143,9 @@ export class TransfersResource {
|
|
|
129
143
|
return this.#http.request('POST', `${this.#base}/${seg(transferId)}/cancel`);
|
|
130
144
|
}
|
|
131
145
|
/**
|
|
132
|
-
* Settles a transfer nothing else can close.
|
|
146
|
+
* Settles a transfer nothing else can close. Platform administrators only,
|
|
147
|
+
* and not from a web-login session: 403 `WEB_SESSION_CANNOT_SIGN` (a browser
|
|
148
|
+
* or the mobile app is fine).
|
|
133
149
|
*
|
|
134
150
|
* pending — execution died, or its outcome is unknown (the
|
|
135
151
|
* send answered 502 `TRANSFER_OUTCOME_UNKNOWN`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transfers.js","sourceRoot":"","sources":["../../../src/resources/transfers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAmB,MAAM,iBAAiB,CAAA;AACtD,OAAO,EAAE,OAAO,EAAc,MAAM,kBAAkB,CAAA;AAgBtD
|
|
1
|
+
{"version":3,"file":"transfers.js","sourceRoot":"","sources":["../../../src/resources/transfers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAmB,MAAM,iBAAiB,CAAA;AACtD,OAAO,EAAE,OAAO,EAAc,MAAM,kBAAkB,CAAA;AAgBtD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,MAAM,OAAO,iBAAiB;IACnB,KAAK,CAAY;IACjB,KAAK,CAAQ;IAEtB,YAAY,IAAgB,EAAE,SAAiB;QAC7C,IAAI,CAAC,KAAK,GAAG,IAAI,CAAA;QACjB,IAAI,CAAC,KAAK,GAAG,kBAAkB,GAAG,CAAC,SAAS,CAAC,YAAY,CAAA;IAC3D,CAAC;IAED;;;;;;;;;;;;;;;OAeG;IACH,KAAK,CAAC,IAAI,CACR,KAAyB,EACzB,OAAO,GAAiD,EAAE;QAE1D,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,UAAU,CAA0B,MAAM,EAAE,IAAI,CAAC,KAAK,EAAE;YACnF,IAAI,EAAE,KAAK;YACX,GAAG,CAAC,KAAK,CAAC,cAAc,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,cAAc,EAAE,KAAK,CAAC,cAAc,EAAE,CAAC;YACvF,GAAG,CAAC,OAAO,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC;YACnE,GAAG,CAAC,OAAO,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,CAAC;SAC7E,CAAC,CAAA;QACF,OAAO,OAAO,CAAmD,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,IAAI,EAAE;YACrF,WAAW,EAAE,IAAI;SAClB,CAAC,CAAA;IACJ,CAAC;IAED;;;;;;OAMG;IACH,GAAG,CAAC,UAAkB;QACpB,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAoB,KAAK,EAAE,GAAG,IAAI,CAAC,KAAK,IAAI,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC,CAAA;IACzF,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAqCG;IACH,IAAI,CAAC,UAAkB,EAAE,KAAgB;QACvC,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CACvB,MAAM,EACN,GAAG,IAAI,CAAC,KAAK,IAAI,GAAG,CAAC,UAAU,CAAC,YAAY,EAC5C,EAAE,IAAI,EAAE,KAAK,EAAE,CAChB,CAAA;IACH,CAAC;IAED;;;;;;;;;;;;;;;;OAgBG;IACH,MAAM,CAAC,UAAkB;QACvB,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAe,MAAM,EAAE,GAAG,IAAI,CAAC,KAAK,IAAI,GAAG,CAAC,UAAU,CAAC,SAAS,CAAC,CAAA;IAC5F,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA+BG;IACH,SAAS,CACP,UAAkB,EAClB,KAAK,GAA0B,EAAE;QAEjC,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CACvB,MAAM,EACN,GAAG,IAAI,CAAC,KAAK,IAAI,GAAG,CAAC,UAAU,CAAC,YAAY,EAC5C,EAAE,IAAI,EAAE,KAAK,EAAE,CAChB,CAAA;IACH,CAAC;CACF"}
|
package/dist/esm/version.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** SDK version, sent in the `user-agent` header. */
|
|
2
|
-
export declare const SDK_VERSION = "0.
|
|
2
|
+
export declare const SDK_VERSION = "0.3.0";
|
|
3
3
|
/** Default API base URL. */
|
|
4
4
|
export declare const DEFAULT_BASE_URL = "https://policy-engine-rest.ezig.workers.dev";
|
|
5
5
|
//# sourceMappingURL=version.d.ts.map
|
package/dist/esm/version.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** SDK version, sent in the `user-agent` header. */
|
|
2
|
-
export const SDK_VERSION = '0.
|
|
2
|
+
export const SDK_VERSION = '0.3.0';
|
|
3
3
|
/** Default API base URL. */
|
|
4
4
|
export const DEFAULT_BASE_URL = 'https://policy-engine-rest.ezig.workers.dev';
|
|
5
5
|
//# sourceMappingURL=version.js.map
|
package/docs/concepts.md
CHANGED
|
@@ -76,8 +76,9 @@ now, so `replayed` must not be shown as "sent": `data.transaction.status` says w
|
|
|
76
76
|
or waiting for an administrator to reconcile it (`pending`) or did not go out (`failed`, `rejected`,
|
|
77
77
|
`cancelled`).
|
|
78
78
|
|
|
79
|
-
**Only `transfers.send` can return it.** `idempotencyKey` exists on
|
|
80
|
-
whole API — the transfer —
|
|
79
|
+
**Only `transfers.send` and `transferDrafts.send` can return it.** `idempotencyKey` exists on
|
|
80
|
+
exactly one request body in the whole API — the transfer — and sending a draft derives the key from
|
|
81
|
+
the draft, so a transfer is the only place where a 200 means "this already happened". On
|
|
81
82
|
every other gated method a 200 is an ordinary success (updating a counterparty, for instance) and
|
|
82
83
|
is labelled `applied`; writing a `case 'replayed'` there is harmless but dead. The branch is worth
|
|
83
84
|
handling where it is reachable and worth knowing about where it is not, because "the key protects
|
|
@@ -93,6 +94,17 @@ Two further rules about approvals:
|
|
|
93
94
|
That is how "the CFO AND compliance" is expressed, and it means adding a permissive policy beside
|
|
94
95
|
an existing one does not remove its signatures.
|
|
95
96
|
|
|
97
|
+
**Money and signatures go from the mobile app.** A session obtained through a web login cannot
|
|
98
|
+
send a transfer, vote on one, reconcile one or vote on any approval request: the API answers 403
|
|
99
|
+
`WEB_SESSION_CANNOT_SIGN`, whoever the person is. A browser signed in by the email link (the admin
|
|
100
|
+
panel) can only for a platform administrator. What a web session can do is prepare a transfer
|
|
101
|
+
as a **draft** (`transferDrafts`). The draft belongs to its author alone, the author gets a push
|
|
102
|
+
on their mobile devices, and sends it from the app — through the same checks, policies and
|
|
103
|
+
signatures as any transfer. A draft is sent once: sending it again returns the same transfer. Its
|
|
104
|
+
`sent` status means a transfer was created, not that the money left — that is the transfer's own
|
|
105
|
+
status. Withdrawing your own transfer or request is open to any session; someone else's, being a
|
|
106
|
+
"no" like a veto, only to an administrator in a session that may sign.
|
|
107
|
+
|
|
96
108
|
## 4. Money is a string, and zero is not nothing
|
|
97
109
|
|
|
98
110
|
Every amount is raw smallest units in a string: `"96325670000"` is 96 325.67 USDT. `float64` loses
|
package/docs/errors.md
CHANGED
|
@@ -59,7 +59,7 @@ The validation hook inside the API does build a flat `{"error": "amount: Require
|
|
|
59
59
|
|
|
60
60
|
`code` is derived from the status — the hook sets none — which is why it is `BAD_REQUEST` and not something domain-specific. `message` is a readable `path: problem` list joined by `; ` and is the only information available; `details` is absent. Show the message, or map it to your own form state by parsing the paths.
|
|
61
61
|
|
|
62
|
-
This is why `BAD_REQUEST` is not a domain error. It means "the body or query did not match the schema", and it covers, among others: an unknown report type (`type=transaction-activity` instead of `transaction_activity` — the names are snake_case everywhere), an `idempotencyKey` shorter than 8 characters, and an out-of-range `limit`.
|
|
62
|
+
This is why `BAD_REQUEST` is not a domain error. It means "the body or query did not match the schema", and it covers, among others: an unknown report type (`type=transaction-activity` instead of `transaction_activity` — the names are snake_case everywhere), an `idempotencyKey` shorter than 8 characters or beginning with `draft:` (the prefix is reserved for the transfers a draft creates), and an out-of-range `limit`.
|
|
63
63
|
|
|
64
64
|
## Status-derived codes
|
|
65
65
|
|
|
@@ -99,7 +99,7 @@ the authentication middleware with `UNAUTHENTICATED`.
|
|
|
99
99
|
|
|
100
100
|
## Money and transfers
|
|
101
101
|
|
|
102
|
-
`POST /transfers`, and the vote / cancel / reconcile endpoints behind it.
|
|
102
|
+
`POST /transfers`, and the vote / cancel / reconcile endpoints behind it. Sending a draft (`transferDrafts.send`) creates the transfer the same way and answers with the same codes; the draft's own are under [Transfer drafts](#transfer-drafts).
|
|
103
103
|
|
|
104
104
|
| Code | Status | When | What to do |
|
|
105
105
|
|---|---|---|---|
|
|
@@ -111,6 +111,7 @@ the authentication middleware with `UNAUTHENTICATED`.
|
|
|
111
111
|
| `ADDRESS_NOT_FOUND` | 404 | No such address id. | Refresh the address list; the address was deleted or the id is stale. |
|
|
112
112
|
| `ADDRESS_NOT_IN_VAULT` | 400 | The address exists but belongs to another vault. | A client bug: the vault scope and the address id disagree. |
|
|
113
113
|
| `ADDRESS_TRANSFER_FORBIDDEN` | 403 | You are neither the owner nor an admin, and you hold no grant with transfer rights on this address. Checked before the policy engine. | Show the address as view-only. The remedy is a `contributor` grant from the owner — direct the user there, not to a retry. |
|
|
114
|
+
| `WEB_SESSION_CANNOT_SIGN` | 403 | The session may not send money or sign. That depends on how it was obtained: the mobile app may (the email link verified by the app itself, with no http(s) `callbackURL`), and so may an older session, issued before the API told sessions apart; a browser signed in by the email link — the admin panel — only for a platform administrator; a web login — nobody, a platform administrator included. Refused on `transfers.send`, `transfers.vote`, `approvals.vote` and `transferDrafts.send` before anything else is checked, and on `transfers.reconcile` (platform administrators only) in a web-login session. Nothing was created, reserved or recorded. Cancelling your own transfer or request is not refused. | Terminal in that session. In a web client do not offer these actions: create a draft instead (`transferDrafts.create`), which the author sends from the app. |
|
|
114
115
|
| `POLICY_DENIED` | 403 | The policy engine said `block`, or no policy permits the action (default-deny). `details` carries the full decision, including `trace`. | Terminal for this request. Show `message` — it already names the rule that fired. Changing the amount or the destination may make the same request pass; retrying it unchanged will not. |
|
|
115
116
|
| `APPROVAL_UNSATISFIABLE` | 409 | Signatures are required but cannot be gathered: fewer eligible approvers than the threshold. `details` has `{threshold, eligibleApprovers}`. | **Do not retry.** Nobody can approve this. Tell the user to contact an administrator — the policy or the approver group has to change. See [Easily confused](#easily-confused). |
|
|
116
117
|
| `IDEMPOTENCY_KEY_REUSED` | 409 | The `idempotencyKey` already belongs to a different transfer: another sending address, recipient, amount, asset or network — their names are in `details.fields` (the amount is compared by value, `1.5` equals `1.50`); or it was used by another person or in another vault, and then there is no `details`. Nothing was created or moved. | Not a replay — a key reused for a new attempt. A new transfer needs a new key; a retry of the same transfer needs the old key with the same body. |
|
|
@@ -133,7 +134,7 @@ the authentication middleware with `UNAUTHENTICATED`.
|
|
|
133
134
|
| `NOT_AN_APPROVER` | 403 | You are not in the approver snapshot taken when the request was created. Editing the policy or the group afterwards does not add you. | Hide the approve/reject controls for this item. Terminal. |
|
|
134
135
|
| `ALREADY_VOTED` | 409 | You already voted. One vote per person. Repeating the **same** decision is not refused when it can finish what an earlier call left undone (it recorded the vote and broke off): a repeated reject completes the veto, a repeated approve executes the transfer once the threshold is met. A different decision over a recorded vote is always this 409. | Refresh; show your recorded vote. |
|
|
135
136
|
| `REQUEST_INCOMPLETE` | 409 | The approval request behind the transfer was not created completely — signature steps it refers to are missing — so it can never be approved. The `approve` that got this 409 **is recorded**. | Do not offer approve again. The request is closed by its initiator or an admin (cancel; anyone else gets 403 `NOT_INITIATOR`), or by a veto from an approver who has not voted yet; the reserve is returned. Then create the transfer anew. |
|
|
136
|
-
| `NOT_INITIATOR` | 403 | Only the initiator or an admin can cancel. | Hide the cancel control. |
|
|
137
|
+
| `NOT_INITIATOR` | 403 | Only the initiator or an admin can cancel. Someone else's is cancelled only from a session that may sign (see `WEB_SESSION_CANNOT_SIGN`): by an admin from the mobile app, by a platform administrator also from a browser, from a web login by nobody. | Hide the cancel control. |
|
|
137
138
|
|
|
138
139
|
### Reconciling a stuck transfer
|
|
139
140
|
|
|
@@ -153,6 +154,18 @@ A `pending` transfer is decided by the hash: with `txHash` it is driven to `conf
|
|
|
153
154
|
| `RESERVE_MISSING` | 409 | `txHash` sent for a transfer whose funds were never reserved, so it cannot have executed. | Reconcile without `txHash`; it closes as `failed` with no money moved. |
|
|
154
155
|
| `RESERVE_RELEASED` | 409 | `txHash` sent, but the reserve had already been returned: on a `pending` transfer the returned funds are already spent and the send cannot be charged to them; a closed transfer is not confirmed by reconciliation at all. Nothing moved. | An administrator has to post a correcting entry. Escalate. |
|
|
155
156
|
|
|
157
|
+
### Transfer drafts
|
|
158
|
+
|
|
159
|
+
`/transfer-drafts`. A draft is seen only by its author, an administrator included. Creating one is checked like a transfer and fails with the same codes (`ADDRESS_NOT_FOUND`, `ADDRESS_NOT_IN_VAULT`, `ADDRESS_TRANSFER_FORBIDDEN`, `TOKEN_NOT_FOUND`, `TOKEN_NETWORK_MISMATCH`, `INVALID_AMOUNT`, `INVALID_DESTINATION_ADDRESS`); AML, policies and the balance are not checked until it is sent. Sending one answers with every code of `POST /transfers` above, plus `WEB_SESSION_CANNOT_SIGN` and these:
|
|
160
|
+
|
|
161
|
+
| Code | Status | When | What to do |
|
|
162
|
+
|---|---|---|---|
|
|
163
|
+
| `TRANSFER_DRAFT_NOT_FOUND` | 404 | No such draft, someone else's, or one from another vault — the three are not told apart, so the existence of another person's draft is not revealed. Reading, discarding and sending. | Refresh your list of drafts. |
|
|
164
|
+
| `TRANSFER_DRAFT_DISCARDED` | 409 | Sending a discarded draft that no transfer was created from. Nothing was created or reserved. | Terminal. Create a new draft. |
|
|
165
|
+
| `TRANSFER_DRAFT_ALREADY_SENT` | 409 | Discarding a draft a transfer was created from — also when the transfer exists but the draft was not marked `sent` yet (a send from a phone is under way or broke off; the mark is written now). `details.transactionId` is the transfer. Discarding does not undo it. | Show the transfer by `details.transactionId`. If it is still `awaiting_approval`, it is withdrawn with `transfers.cancel`. |
|
|
166
|
+
|
|
167
|
+
A refusal before the transfer exists — `POLICY_DENIED`, `INSUFFICIENT_BALANCE`, `APPROVAL_UNSATISFIABLE`, `TOKEN_NOT_FOUND` and the like — leaves the draft a `draft`: it can be sent later or discarded. Once a transfer exists, even a `failed` one or one behind a 502 `TRANSFER_OUTCOME_UNKNOWN`, the draft is `sent`, and a further send never creates a second transfer: it answers 200 with that one — unless the draft's token has been disabled since, which answers 400 `TOKEN_NOT_FOUND`.
|
|
168
|
+
|
|
156
169
|
### Not error codes, though they look like them
|
|
157
170
|
|
|
158
171
|
Two sets of uppercase strings travel inside **successful** bodies and will mislead anyone grepping for codes:
|
|
@@ -286,9 +299,10 @@ In the single-subject form the per-subject code is returned as a normal error
|
|
|
286
299
|
| `NOT_FOUND` | 404 | No such request in this vault. | Refresh the list. |
|
|
287
300
|
| `NOT_PENDING` | 409 | The request is already `APPROVED` / `REJECTED` / `CANCELLED`. Voting is over. | Refresh and show the final status. Expected under concurrency; not worth an alert. |
|
|
288
301
|
| `NOT_APPROVER` | 403 | You are not in the approver snapshot. The snapshot is frozen at creation — later policy or group edits do not add you. | Hide the controls for this request. Terminal. |
|
|
302
|
+
| `WEB_SESSION_CANNOT_SIGN` | 403 | A vote, on a request of any kind, from a session that may not sign: a web login, or a browser of anyone but a platform administrator (see [Money and transfers](#money-and-transfers)). Nothing was recorded. Cancelling your own request is not refused. | Show the request without approve/reject in such a client; the vote is given from the app. |
|
|
289
303
|
| `ALREADY_VOTED` | 409 | One vote per person, already cast. Repeating the **same** decision on a `PENDING` request is not refused when it can finish what an earlier call left undone: a repeated reject completes the veto, a repeated approve completes the approval once the threshold is met. | Refresh; show your vote. |
|
|
290
304
|
| `REQUEST_INCOMPLETE` | 409 | The request was not created completely — signature steps its approvers refer to are missing — so it can never be approved. The `approve` that got this 409 **is recorded**. | Do not offer approve again. It is closed by its initiator or an admin (cancel; anyone else gets 403 `NOT_INITIATOR`), or by a veto from an approver who has not voted yet. Then create the action anew. |
|
|
291
|
-
| `NOT_INITIATOR` | 403 | Only the initiator or an admin can cancel. | Hide the cancel control. |
|
|
305
|
+
| `NOT_INITIATOR` | 403 | Only the initiator or an admin can cancel. Someone else's is cancelled only from a session that may sign (see `WEB_SESSION_CANNOT_SIGN`): by an admin from the mobile app, by a platform administrator also from a browser, from a web login by nobody. | Hide the cancel control. |
|
|
292
306
|
| `UNSATISFIABLE` | 409 | The request cannot be created: a step has fewer eligible approvers than its threshold, or every step is auto-approved so no request is needed. | **Do not retry.** An administrator has to fix the policy. Same situation as `APPROVAL_UNSATISFIABLE` on a transfer. |
|
|
293
307
|
| `DB_REQUIRED` | 500 | A money-path request was handled without the database binding. Deliberately fail-closed, so no reserve is left locked. | Infrastructure fault. Nothing the user can do; escalate. |
|
|
294
308
|
| `POLICY_DENIED` | 403 | No policy permits one of the steps. `message` is prefixed `Step N (action): …`. | Terminal. The step index is in `details.stepIndex`; the prefix in `message` is for display, not for parsing. |
|
|
@@ -425,7 +439,9 @@ Three refusals the API puts **in front of** the library are its own: they arrive
|
|
|
425
439
|
|---|---|---|---|
|
|
426
440
|
| `ADMIN_CANNOT_APPROVE_WEB_LOGIN` | 403 | `POST /api/auth/device/approve` by a platform administrator. Approving a web login gives the holder of the code a new session of the approving user, and a platform administrator's session is not handed to the web version at all. | Terminal. Approve from an account that is not a platform administrator. |
|
|
427
441
|
| `WEB_SESSION_CANNOT_APPROVE` | 403 | The same approval sent with a session that was itself obtained through a web login. Only a session signed in another way may approve, so one leaked web token cannot keep minting new ones. | Approve from the mobile app. |
|
|
428
|
-
| `WEB_SESSION_CANNOT_MANAGE_SESSIONS` | 403 | A web
|
|
442
|
+
| `WEB_SESSION_CANNOT_MANAGE_SESSIONS` | 403 | A session that may not sign — a web login, or a browser of anyone but a platform administrator — called `list-sessions`, `revoke-session`, `revoke-sessions` or `revoke-other-sessions`. Signing out (`sign-out`) is not affected. | Hide session management in such a client; it is done from the mobile app. |
|
|
443
|
+
|
|
444
|
+
The same sessions are also refused the money and signature endpoints of the API itself, with 403 `WEB_SESSION_CANNOT_SIGN` — see [Money and transfers](#money-and-transfers).
|
|
429
445
|
|
|
430
446
|
Rate limiting outside `/api/auth/*` is not implemented in the API itself. A 429 there comes from the platform in front of it, usually without a JSON body, which means `code: "RATE_LIMITED"` and no `details`. Inside `/api/auth/*` a 429 can also come from the library's own limiter, as a bare `{message}`; and requesting a web-login code (`/api/auth/device/code`) is limited by the API itself, with a 429 in the API's envelope and `code: "RATE_LIMITED"`. Whichever answered, back off — for `X-Retry-After` seconds when the header is there — and retry.
|
|
431
447
|
|
|
@@ -491,6 +507,7 @@ Rules that follow from how the server handles the key:
|
|
|
491
507
|
- **`replayed` does not mean "sent".** It means "a transfer with this key already exists": the earlier attempt did reach the server and only its answer was lost. `data` is that transfer as it stands **now**, and what happened to it is in `data.transaction.status` — `confirmed` (or `submitted`): it left; `awaiting_approval`: it is waiting for signatures, funds reserved; `pending`: it is still executing, or its outcome is unknown and waits for an administrator's reconciliation; `failed`, `rejected` or `cancelled`: it did not leave. Tell the person that, not "sent".
|
|
492
508
|
- **A new key after a `failed` or `rejected` transfer.** The old key is bound to that row, and reusing it returns the dead transfer instead of sending a new one. The same key with any other parameters is not a replay at all: 409 `IDEMPOTENCY_KEY_REUSED`.
|
|
493
509
|
- **No key sent, and a timeout?** Do **not** retry. Fetch the transfer list or the operation history first and establish whether the transfer exists. Make the SDK's own callers always pass a key so this situation cannot arise.
|
|
510
|
+
- **A draft needs no key of yours.** `transferDrafts.send` derives it from the draft, so after a timeout send the SAME draft again: it answers 200 (`replayed`) with the transfer if one was created, and never creates a second.
|
|
494
511
|
- **`network` and `aborted` carry the same uncertainty as `timeout`** on money paths. The request may have been received and executed; only the response was lost. Treat all three identically: same key, or verify first.
|
|
495
512
|
- **A thrown `GAS_STATION_FAILED` or `WALLET_SERVICE_ERROR` is different.** Those are definite: the transfer is `failed` and the reserve has been returned. Retry those with a **new** key.
|
|
496
513
|
- **A thrown `TRANSFER_OUTCOME_UNKNOWN` is not.** It is a 502 that carries the same uncertainty as a timeout: the transaction may have left. Only the same key, which returns the transfer and does not execute it again; the outcome is set by reconciliation. `TRANSFER_BROADCAST_UNRECORDED` means it did leave — no retry at all.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@v3finance/core-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "The official TypeScript SDK for the V3 Finance Core API — custodial addresses, transfers under policy control, approvals, shared access, labelling and reports",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
package/src/client.ts
CHANGED
|
@@ -28,6 +28,7 @@ import { RegistriesResource } from './resources/registries.js'
|
|
|
28
28
|
import { ReportsResource } from './resources/reports.js'
|
|
29
29
|
import { SharingResource } from './resources/sharing.js'
|
|
30
30
|
import { MeResource } from './resources/me.js'
|
|
31
|
+
import { TransferDraftsResource } from './resources/transferDrafts.js'
|
|
31
32
|
import { TransfersResource } from './resources/transfers.js'
|
|
32
33
|
import { DEFAULT_BASE_URL } from './version.js'
|
|
33
34
|
|
|
@@ -70,6 +71,7 @@ export interface VaultScope {
|
|
|
70
71
|
readonly code: string
|
|
71
72
|
readonly addresses: AddressesResource
|
|
72
73
|
readonly transfers: TransfersResource
|
|
74
|
+
readonly transferDrafts: TransferDraftsResource
|
|
73
75
|
readonly history: HistoryResource
|
|
74
76
|
readonly balances: BalancesResource
|
|
75
77
|
readonly approvals: ApprovalsResource
|
|
@@ -128,6 +130,7 @@ export class CoreClient {
|
|
|
128
130
|
code,
|
|
129
131
|
addresses: new AddressesResource(this.http, code),
|
|
130
132
|
transfers: new TransfersResource(this.http, code),
|
|
133
|
+
transferDrafts: new TransferDraftsResource(this.http, code),
|
|
131
134
|
history: new HistoryResource(this.http, code),
|
|
132
135
|
balances: new BalancesResource(this.http, code),
|
|
133
136
|
approvals: new ApprovalsResource(this.http, code),
|
package/src/core/gated.ts
CHANGED
|
@@ -48,11 +48,12 @@ export type Gated<TApplied, TPending = TApplied> =
|
|
|
48
48
|
* of the two it is instead of the helper guessing.
|
|
49
49
|
*
|
|
50
50
|
* Which also means `outcome: 'replayed'` is UNREACHABLE for every gated
|
|
51
|
-
* method other than `transfers.send`: replay
|
|
52
|
-
* key, and the
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
51
|
+
* method other than `transfers.send` and `transferDrafts.send`: replay
|
|
52
|
+
* protection needs an idempotency key, and the API has one only on a
|
|
53
|
+
* transfer — taken from the transfer body, or derived from the draft when a
|
|
54
|
+
* draft is sent. The three-way `switch` in `docs/concepts.md` is right for a
|
|
55
|
+
* transfer; beside a counterparty edit its `case 'replayed'` is dead, and it
|
|
56
|
+
* is not evidence that such an edit can come back as a replay.
|
|
56
57
|
*/
|
|
57
58
|
export function toGated<TApplied, TPending>(
|
|
58
59
|
status: number,
|
package/src/core/pagination.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Keyset pagination — for the
|
|
2
|
+
* Keyset pagination — for the twelve endpoints that have it.
|
|
3
3
|
*
|
|
4
4
|
* "Every list returns `{items, nextCursor}`" is what this file used to claim,
|
|
5
5
|
* and it is not what the API does. Counted over the spec snapshot
|
|
6
6
|
* (`openapi/spec.json`), the reading endpoints fall into three shapes:
|
|
7
7
|
*
|
|
8
|
-
* •
|
|
8
|
+
* • 12 GETs take `cursor`/`limit` and answer a `nextCursor` — addresses,
|
|
9
9
|
* history, approval requests, members, counterparties, counterparty
|
|
10
10
|
* groups, operation categories, operation relations, ledger entries, a
|
|
11
|
-
* vault's policies, balances. These are what `paginate`
|
|
11
|
+
* vault's policies, balances, transfer drafts. These are what `paginate`
|
|
12
|
+
* is for;
|
|
12
13
|
* • 18 answer `{items}` with NO cursor parameter at all — folders and their
|
|
13
14
|
* grants, address shares, shared-with-me / shared-by-me, visibility
|
|
14
15
|
* grants, category assignments and their versions, report templates and
|