@v3finance/core-sdk 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (164) hide show
  1. package/CHANGELOG.md +154 -0
  2. package/README.md +18 -14
  3. package/dist/cjs/client.d.ts +27 -34
  4. package/dist/cjs/client.d.ts.map +1 -1
  5. package/dist/cjs/client.js +69 -0
  6. package/dist/cjs/client.js.map +1 -1
  7. package/dist/cjs/core/gated.d.ts +12 -10
  8. package/dist/cjs/core/gated.d.ts.map +1 -1
  9. package/dist/cjs/core/gated.js +12 -10
  10. package/dist/cjs/core/gated.js.map +1 -1
  11. package/dist/cjs/core/http.d.ts +18 -0
  12. package/dist/cjs/core/http.d.ts.map +1 -1
  13. package/dist/cjs/core/http.js +11 -1
  14. package/dist/cjs/core/http.js.map +1 -1
  15. package/dist/cjs/core/pagination.d.ts +11 -9
  16. package/dist/cjs/core/pagination.d.ts.map +1 -1
  17. package/dist/cjs/core/pagination.js +11 -9
  18. package/dist/cjs/core/pagination.js.map +1 -1
  19. package/dist/cjs/generated/operations.d.ts +210 -2
  20. package/dist/cjs/generated/operations.d.ts.map +1 -1
  21. package/dist/cjs/generated/operations.js +212 -4
  22. package/dist/cjs/generated/operations.js.map +1 -1
  23. package/dist/cjs/generated/types.d.ts +935 -93
  24. package/dist/cjs/generated/types.d.ts.map +1 -1
  25. package/dist/cjs/index.d.ts +6 -6
  26. package/dist/cjs/index.d.ts.map +1 -1
  27. package/dist/cjs/index.js.map +1 -1
  28. package/dist/cjs/resources/addresses.d.ts +91 -4
  29. package/dist/cjs/resources/addresses.d.ts.map +1 -1
  30. package/dist/cjs/resources/addresses.js +55 -3
  31. package/dist/cjs/resources/addresses.js.map +1 -1
  32. package/dist/cjs/resources/admin.d.ts +32 -1
  33. package/dist/cjs/resources/admin.d.ts.map +1 -1
  34. package/dist/cjs/resources/admin.js +45 -0
  35. package/dist/cjs/resources/admin.js.map +1 -1
  36. package/dist/cjs/resources/approvals.d.ts +30 -2
  37. package/dist/cjs/resources/approvals.d.ts.map +1 -1
  38. package/dist/cjs/resources/approvals.js.map +1 -1
  39. package/dist/cjs/resources/balances.d.ts +14 -7
  40. package/dist/cjs/resources/balances.d.ts.map +1 -1
  41. package/dist/cjs/resources/balances.js +10 -4
  42. package/dist/cjs/resources/balances.js.map +1 -1
  43. package/dist/cjs/resources/categories.d.ts +20 -6
  44. package/dist/cjs/resources/categories.d.ts.map +1 -1
  45. package/dist/cjs/resources/categories.js +19 -7
  46. package/dist/cjs/resources/categories.js.map +1 -1
  47. package/dist/cjs/resources/counterparties.d.ts +52 -6
  48. package/dist/cjs/resources/counterparties.d.ts.map +1 -1
  49. package/dist/cjs/resources/counterparties.js +24 -0
  50. package/dist/cjs/resources/counterparties.js.map +1 -1
  51. package/dist/cjs/resources/history.d.ts +227 -26
  52. package/dist/cjs/resources/history.d.ts.map +1 -1
  53. package/dist/cjs/resources/history.js +46 -0
  54. package/dist/cjs/resources/history.js.map +1 -1
  55. package/dist/cjs/resources/me.d.ts +17 -1
  56. package/dist/cjs/resources/me.d.ts.map +1 -1
  57. package/dist/cjs/resources/me.js +19 -0
  58. package/dist/cjs/resources/me.js.map +1 -1
  59. package/dist/cjs/resources/members.d.ts +21 -1
  60. package/dist/cjs/resources/members.d.ts.map +1 -1
  61. package/dist/cjs/resources/members.js +15 -0
  62. package/dist/cjs/resources/members.js.map +1 -1
  63. package/dist/cjs/resources/operations.d.ts +179 -4
  64. package/dist/cjs/resources/operations.d.ts.map +1 -1
  65. package/dist/cjs/resources/operations.js +192 -2
  66. package/dist/cjs/resources/operations.js.map +1 -1
  67. package/dist/cjs/resources/registries.d.ts +19 -2
  68. package/dist/cjs/resources/registries.d.ts.map +1 -1
  69. package/dist/cjs/resources/registries.js +16 -0
  70. package/dist/cjs/resources/registries.js.map +1 -1
  71. package/dist/cjs/version.d.ts +1 -1
  72. package/dist/cjs/version.js +1 -1
  73. package/dist/esm/client.d.ts +27 -34
  74. package/dist/esm/client.d.ts.map +1 -1
  75. package/dist/esm/client.js +69 -0
  76. package/dist/esm/client.js.map +1 -1
  77. package/dist/esm/core/gated.d.ts +12 -10
  78. package/dist/esm/core/gated.d.ts.map +1 -1
  79. package/dist/esm/core/gated.js +12 -10
  80. package/dist/esm/core/gated.js.map +1 -1
  81. package/dist/esm/core/http.d.ts +18 -0
  82. package/dist/esm/core/http.d.ts.map +1 -1
  83. package/dist/esm/core/http.js +11 -1
  84. package/dist/esm/core/http.js.map +1 -1
  85. package/dist/esm/core/pagination.d.ts +11 -9
  86. package/dist/esm/core/pagination.d.ts.map +1 -1
  87. package/dist/esm/core/pagination.js +11 -9
  88. package/dist/esm/core/pagination.js.map +1 -1
  89. package/dist/esm/generated/operations.d.ts +210 -2
  90. package/dist/esm/generated/operations.d.ts.map +1 -1
  91. package/dist/esm/generated/operations.js +212 -4
  92. package/dist/esm/generated/operations.js.map +1 -1
  93. package/dist/esm/generated/types.d.ts +935 -93
  94. package/dist/esm/generated/types.d.ts.map +1 -1
  95. package/dist/esm/index.d.ts +6 -6
  96. package/dist/esm/index.d.ts.map +1 -1
  97. package/dist/esm/index.js.map +1 -1
  98. package/dist/esm/resources/addresses.d.ts +91 -4
  99. package/dist/esm/resources/addresses.d.ts.map +1 -1
  100. package/dist/esm/resources/addresses.js +55 -3
  101. package/dist/esm/resources/addresses.js.map +1 -1
  102. package/dist/esm/resources/admin.d.ts +32 -1
  103. package/dist/esm/resources/admin.d.ts.map +1 -1
  104. package/dist/esm/resources/admin.js +45 -0
  105. package/dist/esm/resources/admin.js.map +1 -1
  106. package/dist/esm/resources/approvals.d.ts +30 -2
  107. package/dist/esm/resources/approvals.d.ts.map +1 -1
  108. package/dist/esm/resources/approvals.js.map +1 -1
  109. package/dist/esm/resources/balances.d.ts +14 -7
  110. package/dist/esm/resources/balances.d.ts.map +1 -1
  111. package/dist/esm/resources/balances.js +10 -4
  112. package/dist/esm/resources/balances.js.map +1 -1
  113. package/dist/esm/resources/categories.d.ts +20 -6
  114. package/dist/esm/resources/categories.d.ts.map +1 -1
  115. package/dist/esm/resources/categories.js +19 -7
  116. package/dist/esm/resources/categories.js.map +1 -1
  117. package/dist/esm/resources/counterparties.d.ts +52 -6
  118. package/dist/esm/resources/counterparties.d.ts.map +1 -1
  119. package/dist/esm/resources/counterparties.js +24 -0
  120. package/dist/esm/resources/counterparties.js.map +1 -1
  121. package/dist/esm/resources/history.d.ts +227 -26
  122. package/dist/esm/resources/history.d.ts.map +1 -1
  123. package/dist/esm/resources/history.js +46 -0
  124. package/dist/esm/resources/history.js.map +1 -1
  125. package/dist/esm/resources/me.d.ts +17 -1
  126. package/dist/esm/resources/me.d.ts.map +1 -1
  127. package/dist/esm/resources/me.js +19 -0
  128. package/dist/esm/resources/me.js.map +1 -1
  129. package/dist/esm/resources/members.d.ts +21 -1
  130. package/dist/esm/resources/members.d.ts.map +1 -1
  131. package/dist/esm/resources/members.js +15 -0
  132. package/dist/esm/resources/members.js.map +1 -1
  133. package/dist/esm/resources/operations.d.ts +179 -4
  134. package/dist/esm/resources/operations.d.ts.map +1 -1
  135. package/dist/esm/resources/operations.js +192 -2
  136. package/dist/esm/resources/operations.js.map +1 -1
  137. package/dist/esm/resources/registries.d.ts +19 -2
  138. package/dist/esm/resources/registries.d.ts.map +1 -1
  139. package/dist/esm/resources/registries.js +16 -0
  140. package/dist/esm/resources/registries.js.map +1 -1
  141. package/dist/esm/version.d.ts +1 -1
  142. package/dist/esm/version.js +1 -1
  143. package/docs/concepts.md +13 -11
  144. package/docs/errors.md +73 -5
  145. package/package.json +1 -1
  146. package/src/client.ts +40 -0
  147. package/src/core/gated.ts +12 -10
  148. package/src/core/http.ts +30 -1
  149. package/src/core/pagination.ts +11 -9
  150. package/src/generated/operations.ts +212 -4
  151. package/src/generated/types.ts +979 -95
  152. package/src/index.ts +15 -1
  153. package/src/resources/addresses.ts +102 -4
  154. package/src/resources/admin.ts +59 -0
  155. package/src/resources/approvals.ts +30 -2
  156. package/src/resources/balances.ts +14 -7
  157. package/src/resources/categories.ts +19 -5
  158. package/src/resources/counterparties.ts +59 -5
  159. package/src/resources/history.ts +238 -27
  160. package/src/resources/me.ts +22 -0
  161. package/src/resources/members.ts +30 -0
  162. package/src/resources/operations.ts +264 -5
  163. package/src/resources/registries.ts +26 -3
  164. package/src/version.ts +1 -1
@@ -11,9 +11,15 @@ export class RegistriesResource {
11
11
  constructor(http) {
12
12
  this.#http = http;
13
13
  }
14
+ /**
15
+ * Every registered network. Each carries `logoPath`: load the logo through
16
+ * the API with `CoreClient.logo(logoPath)` rather than from `logoUri`, or
17
+ * the image's host sees the client's IP.
18
+ */
14
19
  networks() {
15
20
  return this.#http.request('GET', '/api/v1/networks');
16
21
  }
22
+ /** Tokens, with `logoPath` — see `networks()` on why to load it, not `logoUri`. */
17
23
  tokens(params = {}) {
18
24
  return this.#http.request('GET', '/api/v1/tokens', { query: { ...params } });
19
25
  }
@@ -28,6 +34,16 @@ export class RegistriesResource {
28
34
  * Rates are fetched live on every call and NOT cached, so this is the
29
35
  * "right now" figure. The rate stored on an operation is a separate thing:
30
36
  * a snapshot taken when it was created.
37
+ *
38
+ * `base` adds rates in a fiat currency: `fx.rate` is how much of `base` one
39
+ * USD costs, and each `rates[].rate` is `base` per token (`usdRate` ×
40
+ * `fx.rate`). The conversion goes THROUGH THE DOLLAR, at the Bank of
41
+ * Russia's official rate for the date (`fx.asOf`; unchanged over weekends) —
42
+ * fit for valuation, not for settlement; the server keeps that table for up
43
+ * to an hour. When the currency source is down, `fx` is `null` and every
44
+ * `rates[].rate` is `null`, still with 200. Without `base` the answer is the
45
+ * old one: `base: 'USD'` and neither `fx` nor `rate` keys at all — so pass
46
+ * `base: 'USD'` explicitly if you want `rate` filled in USD.
31
47
  */
32
48
  rates(params = {}) {
33
49
  return this.#http.request('GET', '/api/v1/rates', { query: { ...params } });
@@ -1 +1 @@
1
- {"version":3,"file":"registries.js","sourceRoot":"","sources":["../../../src/resources/registries.ts"],"names":[],"mappings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EAAE,CAAC,CAAA;IACxF,CAAC;IAED;;;;OAIG;IACH,WAAW,CAAC,OAAe,EAAE,KAAqB;QAChD,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAmB,OAAO,EAAE,kBAAkB,kBAAkB,CAAC,OAAO,CAAC,EAAE,EAAE;YACpG,IAAI,EAAE,KAAK;SACZ,CAAC,CAAA;IACJ,CAAC;CACF"}
@@ -1,5 +1,5 @@
1
1
  /** SDK version, sent in the `user-agent` header. */
2
- export declare const SDK_VERSION = "0.4.0";
2
+ export declare const SDK_VERSION = "0.5.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
@@ -1,5 +1,5 @@
1
1
  /** SDK version, sent in the `user-agent` header. */
2
- export const SDK_VERSION = '0.4.0';
2
+ export const SDK_VERSION = '0.5.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
@@ -48,8 +48,8 @@ Practical consequences you will meet:
48
48
 
49
49
  ## 3. An operation may not happen — it may go for approval
50
50
 
51
- Transfers, address creation, changes to the counterparty directory and gated labelling all pass
52
- through the policy engine, and the engine has three outcomes, not two.
51
+ Transfers, address creation, changes to the counterparty directory and gated labelling (operation
52
+ metadata included) all pass through the policy engine, and the engine has three outcomes, not two.
53
53
 
54
54
  The API expresses this with the HTTP status, because **the response bodies are identical**:
55
55
 
@@ -57,7 +57,7 @@ The API expresses this with the HTTP status, because **the response bodies are i
57
57
  | --- | --- |
58
58
  | 201 | applied — it happened |
59
59
  | 202 | pending — funds are RESERVED, nothing has moved, there is a request to sign |
60
- | 200 | replayed — the same idempotency key; the transfer already existed, in whatever state it is now |
60
+ | 200 | replayed — the same idempotency key; the transfer (or the address) already existed, in whatever state it is now |
61
61
 
62
62
  The SDK turns that into `Gated`:
63
63
 
@@ -76,14 +76,16 @@ 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` 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
82
- every other gated method a 200 is an ordinary success (updating a counterparty, for instance) and
83
- is labelled `applied`; writing a `case 'replayed'` there is harmless but dead. The branch is worth
84
- handling where it is reachable and worth knowing about where it is not, because "the key protects
85
- the retry" is true of transfers and of nothing else: a timed-out counterparty change has to be
86
- verified by reading the object back.
79
+ **Only `transfers.send`, `transferDrafts.send` and `addresses.create` can return it.**
80
+ `idempotencyKey` exists on two request bodies in the whole API — the transfer and the new address
81
+ (where it is optional) — and sending a draft derives the key from the draft, so those are the only
82
+ places where a 200 means "this already happened". A replayed address is the address that attempt
83
+ created, or the same pending request if it is still waiting for signatures. On every other gated
84
+ method a 200 is an ordinary success (updating a counterparty, for instance) and is labelled
85
+ `applied`; writing a `case 'replayed'` there is harmless but dead. The branch is worth handling
86
+ where it is reachable and worth knowing about where it is not, because "the key protects the retry"
87
+ is true of transfers and new addresses and of nothing else: a timed-out counterparty change has to
88
+ be verified by reading the object back.
87
89
 
88
90
  Two further rules about approvals:
89
91
 
package/docs/errors.md CHANGED
@@ -197,10 +197,15 @@ Two sets of uppercase strings travel inside **successful** bodies and will misle
197
197
  |---|---|---|---|
198
198
  | `CONCURRENCY_CONFLICT` | 409 | A unique derivation index could not be allocated after 3 attempts — too many simultaneous creations. | **Retry.** This is the one conflict here where a plain retry is the correct answer. |
199
199
  | `NETWORK_NOT_IN_VAULT` | 400 | The network is not connected to this vault. | Offer only the vault's own networks. Terminal otherwise. |
200
+ | `NETWORK_NOT_MONITORED` | 400 | The network has no deposit monitoring — only TRON has it — so no address is created on it. Checked before the signing service and before any approval request; `details.network` names it. (Until 2026-11-22 such an address was created and registered with TRON's monitoring, which never watched it.) | Offer only monitored networks for new addresses. Terminal otherwise. |
201
+ | `IDEMPOTENCY_KEY_REUSED` | 409 | The `idempotencyKey` was already used for an attempt with another body. | Not a replay. A new address needs a new key; a retry of the same one needs the old key with the same body. |
202
+ | `IDEMPOTENCY_KEY_IN_PROGRESS` | 409 | The attempt with this key went for approval, the request was approved, and the address is being created right now. | Wait and retry with the same key and body: it then answers 200 (`replayed`) with the address. |
203
+ | `IDEMPOTENCY_KEY_CLOSED` | 409 | The attempt with this key went for approval and the request closed without an address — rejected, cancelled, or it failed to apply. `details` has `{approvalRequestId, requestStatus}`. | The outcome is settled. A new attempt needs a new key. |
204
+ | `ADDRESS_DERIVATION_COLLISION` | 409 | The vault's derivation paths keep producing on-chain addresses that already exist in another vault — the signing service is shared, and paths are not unique across vaults. Colliding indexes are skipped, but more than the limit in a row is refused; `details` has `{derivationPath, network}`. | Not a retry. The vault needs a derivation segment of its own — an administrator's configuration change. |
200
205
  | `INVALID_SEGMENT` | 400 | A derivation-path segment is missing, unknown, or disabled. | A client bug or a stale form: re-read the vault's route configuration and rebuild the form. |
201
206
  | `GROUP_CREATE_FORBIDDEN` | 403 | You passed a `groupId` for a folder you may not create addresses in. | Create the address outside the folder, or ask the folder's creator. |
202
207
  | `FORBIDDEN_SCOPE` | 403 | You passed `?userId=` for somebody other than yourself, and you are not an admin. | A client bug. Drop the parameter. |
203
- | `MONITORING_FAILED` | 502 | The address was created and then rolled back because it could not be registered for chain monitoring. | Nothing was kept. Retry; if it persists, an upstream service is down. |
208
+ | `MONITORING_FAILED` | 502 | Registering the address for deposit monitoring failed. `details.rolledBack: true` — the address was rolled back and nothing was kept; `false` — the rollback failed too, and the address exists outside monitoring (`details.addressId`). | `true`: retry. `false`: retry with the SAME `idempotencyKey` and body — the replay completes the registration; without a key the address is left for an administrator to clean up. |
204
209
  | `WALLET_SERVICE_ERROR` | 502 | The signing service did not return an address. | Retry. Nothing was created. |
205
210
  | `VAULT_NOT_FOUND` | 404 | The vault code does not resolve. | A client bug or a deleted vault. |
206
211
  | `VAULT_HAS_NO_WALLET_SERVICE` | 500 | No `walletServiceUrl` on the vault. | Configuration fault. Contact an administrator. |
@@ -210,6 +215,8 @@ Two sets of uppercase strings travel inside **successful** bodies and will misle
210
215
  | `APPROVAL_UNSATISFIABLE` | 409 | `create_address` requires signatures, but fewer people can give them than the threshold asks for (the initiator does not count unless the policy allows approving one's own request). Neither the address nor an approval request was created. Unlike the transfer's, it carries no `details`. | **Do not retry.** An administrator has to change the policy or the approver group. See [Easily confused](#easily-confused). |
211
216
  | `APPROVAL_FAILED` | 409 | The approval request could not be created for a reason other than `APPROVAL_UNSATISFIABLE`. See the note under [Declared but never returned](#declared-but-never-returned). | Retry once. If it repeats, it is a server-side fault — escalate. |
212
217
 
218
+ A retry with the same `idempotencyKey` and body is **not** an error either: the address of that attempt comes back with **200** (`outcome: 'replayed'`), or the same pending request with 202, and nothing is created or evaluated again.
219
+
213
220
  Address creation that requires signatures is **not** an error: the server answers **202** with `{status:"awaiting_approval", approvalRequestId, approvalThreshold}`. Nothing is thrown. (`POLICY_REQUIRES_APPROVAL` exists in the server's type but is never sent — see [Declared but never returned](#declared-but-never-returned).) The exception is signatures that cannot be gathered at all: then there is no request and no 202, but `APPROVAL_UNSATISFIABLE` above.
214
221
 
215
222
  Creating an address **into a folder** (`groupId`) can succeed without the folder, and that is not an error either. The right to the folder is checked before anything is created — a refusal there is `GROUP_CREATE_FORBIDDEN` above — but the address is put into the folder only after the signing service and monitoring, and the right is checked again at that moment. If that fails, the address still exists and the answer is still **201**, with `warnings: [{code, message}]` in the body:
@@ -321,7 +328,10 @@ Category schema management (admin) and value assignment (anyone with the right).
321
328
  | `CATEGORY_APPLIES_TO` | 400 | The category applies to transfers only, or deposits only, and you used it on the other kind. | Filter the picker by operation type. |
322
329
  | `CATEGORY_ALREADY_ASSIGNED` | 409 | This category is already on this operation. | Switch to `PATCH` to edit the existing assignment. |
323
330
  | `CATEGORY_FORBIDDEN` | 403 | You lack `view` / `assign` / `edit` on this category — or lack the matching access on the operation's address. | Show the fields as read-only, or hide them. Terminal; the remedy is a category grant or address access. |
324
- | `ASSIGNMENT_STALE` | 409 | Optimistic lock: the assignment changed since you loaded it. | **Re-read, merge, resubmit.** The canonical refresh-and-retry case. Do not resend the same `expectVersion`. |
331
+ | `ASSIGNMENT_STALE` | 409 | Optimistic lock: the assignment changed since the `baseVersion` you sent (on an edit or a removal), or a concurrent write with the same version got in first; the current version is in `details.currentVersion` when known. Nothing was written, no request was created. Also from `operations.setMetadata()` when the `general` assignment changed concurrently three times in a row. | **Re-read, merge, resubmit.** The canonical refresh-and-retry case. Do not resend the same `baseVersion`. |
332
+ | `CATEGORY_KEY_RESERVED` | 400 | Creating a category with the key `general`: it belongs to the system category that holds the older operation metadata, and the server creates it itself. | Ask for a different key. |
333
+ | `LEGACY_TAGS_INVALID` | — | Never thrown: it appears in `items[].error.code` of the administrator's `admin.legacyMetadata.reconcile()`, for a row of the older table whose tags are not an array of strings. That row is counted in `failed` and the others go on. | An administrator's data fix. |
334
+ | `GENERAL_CATEGORY_CONFLICT` | 409 | Writing operation metadata (`operations.setMetadata()`) in a vault that has a category keyed `general` which is NOT the system one, so the metadata has nowhere to go. | Terminal for the client: an administrator has to deal with the vault's own `general` category. |
325
335
  | `CATEGORY_KEY_CONFLICT` | 409 | A category with that key already exists. Keys are immutable once created. | Ask for a different key. |
326
336
  | `CATEGORY_FIELD_CONFLICT` | 409 | A field with that key already exists on the category. | Ask for a different key. |
327
337
  | `CATEGORY_FIELD_DUPLICATE` | 400 | The request body repeats a field key. | A client bug. |
@@ -364,13 +374,64 @@ Group membership also gates destination whitelists: archiving a counterparty gro
364
374
 
365
375
  ## Operation metadata and relations
366
376
 
367
- One domain code lives here — the metadata, link and status-history endpoints have none of their own and refuse with plain statuses.
377
+ The metadata, relation, counterparty-choice and attachment endpoints of one operation.
368
378
 
369
379
  | Code | Status | When | What to do |
370
380
  |---|---|---|---|
371
- | `OPERATION_RELATION_INVALID` | 422 | The relation itself does not make sense: it points an operation at itself, or it carries a `relatedAmountRaw` without the `tokenId` that amount is denominated in, or that `tokenId` is not in the registry. | Fix client-side; `message` says which of the three. A partial amount is meaningless without its token, so send the pair or neither. |
381
+ | `OPERATION_NOT_FOUND` | 404 | From the relation, counterparty-choice and attachment endpoints: the operation is not in this vault, or you may not do this to it. Reading takes seeing the operation; writing — a relation, a counterparty choice, an upload — takes `transfer` on its address (on BOTH addresses for a relation). The cases are not told apart, so an operation you cannot see is not disclosed. | Refresh. If you can see the operation, the remedy is a `contributor` grant, not a different payload. |
382
+ | `OPERATION_RELATION_INVALID` | 422 | The relation itself does not make sense: it points an operation at itself; `relatedAmountRaw` comes without `tokenId` or the reverse; the token is neither operation's; the amount is not above zero, or is above either side's amount in that token (the limit in `details.maxAmountRaw`). The field is in `details.field`. | Fix client-side. A partial amount is meaningless without its token, so send the pair or neither. |
383
+ | `OPERATION_RELATION_EXISTS` | 409 | The same (type, source, target) already exists with another amount, token or comment; `details.relationId` is that relation. An IDENTICAL repeat is not this — it answers 200 with the existing relation. | Show the existing relation. To change it, delete it and create it again. |
384
+ | `OPERATION_RELATION_NOT_FOUND` | 404 | Deleting a relation that does not exist, was already deleted, or neither side of which you can see. | Refresh the relations. |
385
+ | `NOT_RELATION_CREATOR` | 403 | Deleting a relation someone else created, not being an administrator. | Terminal: its creator or an administrator can. |
386
+ | `OPERATION_RELATION_FORBIDDEN` | 403 | Deleting your own relation without `transfer` on the address of one of its operations — a revoked grant revokes the deletion too. | Terminal; the remedy is the grant. |
387
+ | `COUNTERPARTY_NOT_FOUND` | 404 | `operations.setCounterparty()` with a counterparty that is not in this vault — someone else's and a missing one alike. | Refresh the directory. |
388
+ | `COUNTERPARTY_ARCHIVED` | 409 | `operations.setCounterparty()` with an archived counterparty. | Leave archived ones out of the picker. |
389
+ | `OPERATION_AWAITING_APPROVAL` | 409 | Choosing or resetting the counterparty of a transfer that awaits signatures. Its signers see the counterparty matched by the recipient's address, and a choice made then would let them sign a stranger's address under a trusted name. | Wait until the transfer is decided. |
390
+
391
+ Writing the metadata itself (`operations.setMetadata()`) refuses with the category codes — it is a facade over the system category `general` — and, where you may not write, with a plain 404 (`NOT_FOUND`). Writing a relation needs the `transfer` right on both operations, not `view`, because access to an operation and the right to annotate it are separate rights: a viewer gets the 404 for an operation they can read perfectly well.
392
+
393
+ ### Attachments
372
394
 
373
- What is **not** an invalid relation, though it is easy to read as one: if you may not touch either operation, the answer is a plain 404 (`NOT_FOUND`) naming neither side — deliberately, so the existence of an operation you cannot see is not disclosed. Writing a relation needs the `transfer` right on both, not `view`, because access to an operation and the right to annotate it are separate rights. So a viewer gets that 404 for an operation they can read perfectly well, and the fix is a `contributor` grant, not a different payload.
395
+ `operations.attachments()`, `uploadAttachment()`, `downloadAttachment()` and `deleteAttachment()`.
396
+
397
+ | Code | Status | When | What to do |
398
+ |---|---|---|---|
399
+ | `ATTACHMENTS_DISABLED` | 501 | This server has no attachment storage configured. Every attachment call answers it. | Hide attachments. |
400
+ | `ATTACHMENT_NOT_FOUND` | 404 | No such attachment on this operation, or it was deleted. | Refresh the list. |
401
+ | `ATTACHMENT_EMPTY` | 400 | The file is empty. | Normal validation. |
402
+ | `ATTACHMENT_FILENAME_REQUIRED` | 400 | No name: a raw body without `?filename=`, or a form with neither a `filename` field nor a name on the file part. | Pass `filename` (a `File` carries its own). |
403
+ | `ATTACHMENT_FILE_REQUIRED` | 400 | A `multipart/form-data` body without a `file` field holding a file, or one that cannot be parsed. | A client bug: put the file in the field `file`. |
404
+ | `ATTACHMENT_LENGTH_REQUIRED` | 411 | A raw body without `Content-Length` — a stream, for instance. | Send a `Blob`, `ArrayBuffer` or `Uint8Array`; `fetch` sets the length for those. The SDK accepts nothing else as a raw body. |
405
+ | `ATTACHMENT_LENGTH_MISMATCH` | 400 | The raw body was longer or shorter than its `Content-Length`. | A broken upload — retry. |
406
+ | `ATTACHMENT_TOO_LARGE` | 413 | Over 10 MB as a raw body, over 5 MB as a file in a form — counted by the bytes actually read. | Send large files as a raw body; refuse beyond 10 MB client-side. |
407
+ | `ATTACHMENT_BODY_TYPE_NOT_ALLOWED` | 415 | The `Content-Type` of a raw body is neither `application/octet-stream` nor one of the four file types; `details.accepted` lists them. | A client bug; the SDK always sends `application/octet-stream`. |
408
+ | `ATTACHMENT_TYPE_NOT_ALLOWED` | 415 | By its BYTES the file is not a PDF, PNG, JPEG or WebP (SVG and HTML included); `details.allowed`. The declared type is never read. | Tell the person which formats are accepted. |
409
+ | `ATTACHMENT_LIMIT_REACHED` | 409 | The operation already has 20 live attachments. | Delete one first. |
410
+ | `ATTACHMENT_QUOTA_EXCEEDED` | 409 | The vault's quota of live attachments (1 GB by default) is used up; `details` has `{quotaBytes, usedBytes}`. | Terminal until files are deleted or the quota is raised. |
411
+ | `ATTACHMENT_DELETE_FORBIDDEN` | 403 | Deleting an attachment someone else uploaded, or your own after losing the `transfer` right on the operation's address. | Terminal for this person. |
412
+ | `ATTACHMENT_STORAGE_UNAVAILABLE` | 502 | Storage failed. On upload — it did not take the file, nothing was recorded. On download — storage is unreachable, or the file is missing from it (`details.reason: "missing"`). On delete — the attachment IS hidden, but its bytes were not erased (`details.deleted: true`). | Upload and download: retry later. Delete: repeat the call; it finishes erasing the bytes. |
413
+
414
+ ## Logos
415
+
416
+ `CoreClient.logo(logoPath)` — a network's, a token's or an address's logo, fetched by the API.
417
+
418
+ | Code | Status | When | What to do |
419
+ |---|---|---|---|
420
+ | `LOGO_NOT_FOUND` | 404 | No such network or token, or its `logoUri` is empty or one the server will not fetch (not https, an IP address, a non-standard port, a local name). For an address, a missing or invisible ADDRESS is the status-derived `NOT_FOUND` instead. | Show the placeholder. |
421
+ | `LOGO_UNAVAILABLE` | 502 | The source did not deliver an image: a redirect (never followed), a status other than 200, more than 256 KB, not PNG/JPEG/WebP/GIF (SVG never), a 5 s timeout or a network failure — `details.reason` is `redirect`, `upstream_status`, `too_large`, `unsupported_type`, `timeout` or `network`. | Show the placeholder; a retry helps only for `timeout` and `network`. |
422
+
423
+ ## Lists, filters and summaries
424
+
425
+ `history.list()` and `history.summary()`, the address and counterparty listings with their `summary()`, and `approvals.list()`.
426
+
427
+ | Code | Status | When | What to do |
428
+ |---|---|---|---|
429
+ | `TOO_MANY_VALUES` | 400 | More than 50 values in one multi-value filter; `details.param` names it on the feed. | Narrow the filter. |
430
+ | `INVALID_FILTER_VALUE` | 400 | An unknown value of an enumerated filter (`direction`, `status`, `flowType`, `amlLevel`, `relationType`…), an amount bound that is not a decimal, or an unknown facet. `details` has `{param, invalid, allowed}`. Before the filters took several values, the feed answered an unknown `direction`/`status`/`flowType` with `BAD_REQUEST` — same status, different code. | A client bug or a stale list of values: read `details.allowed`. |
431
+ | `SORT_REQUIRES_SINGLE_ASSET` | 400 | `sort: 'amount'` on the feed without exactly one asset in `asset`/`tokenId` — amounts of different tokens do not compare. | Pick one asset, or sort by `usd`. |
432
+ | `INVALID_CURSOR` | 400 | A feed cursor issued for another `sort`/`order`. A cursor that does not parse at all is a `BAD_REQUEST` (`Invalid cursor`), and so is a cursor of another order on the address listing. | Restart from the first page when the order changes. |
433
+ | `HISTORY_SUMMARY_TOO_BROAD` | 422 | `history.summary()` over more than 25 000 operations after filtering; `details.limit`. A cut-off total would look like a complete one, so none is given. | Narrow the period or the filters. |
434
+ | `VOTE_REQUIRES_APPROVER` | 400 | `approvals.list({ vote })` without `approverId` — the vote is that person's. | Pass `approverId` too. |
374
435
 
375
436
  ## Reports
376
437
 
@@ -433,6 +494,12 @@ A risk threshold in a policy is expressed as a **level**, not a numeric score, a
433
494
 
434
495
  One of the library's codes is named here anyway, because the API itself refers to it: `FAILED_TO_GET_SESSION`. The library raises it when it fails to read or renew a session — a sign-out or a revocation deleting the session in the middle of a renewal is one way to get there. The API retries the session lookup once on it; on the API's own paths a failure that survives the retry arrives as `INTERNAL_ERROR`, and only `/api/auth/*` can hand you `FAILED_TO_GET_SESSION` itself, in the library's flat form. Treat it by `status`, like the rest of that namespace.
435
496
 
497
+ One more is named because the API documents it: `VALIDATION_ERROR`, the library's flat `{code, message}` when a body or query does not fit an endpoint's schema — on the device-code endpoints and `magic-link/verify`, for instance. The device-code endpoints also answer their RFC 8628 errors (`authorization_pending`, `slow_down`, `access_denied`, `expired_token`, `invalid_grant`) as a 400 with the RFC code in `message`, not in `code`. The SDK wraps none of `/api/auth/*`.
498
+
499
+ A changing request (`POST`, `PUT`, `PATCH`, `DELETE`) to `/api/v1/*` from a page of a site the API does not trust is refused before anything else with 403 `CROSS_SITE_REQUEST_REFUSED` — an `Origin` outside the trusted list (`Origin: null` included), or no `Origin` with `Sec-Fetch-Site: cross-site`. The session cookie is `SameSite=None`, so without this a foreign page could act with it. Native clients and servers send no `Origin` and are not affected; a web client gets it only when served from an origin the API was not told about — a configuration fix, not a retry.
500
+
501
+ `/webhooks/wallet` is the signing service's inbound channel, not a client endpoint; its 401 `WEBHOOK_UNAUTHORIZED` (a signature missing or wrong while the secret is configured) is for that service.
502
+
436
503
  Three refusals the API puts **in front of** the library are its own: they arrive in the API's envelope, and their codes can be branched on.
437
504
 
438
505
  | Code | Status | When | What to do |
@@ -524,6 +591,7 @@ These codes exist on the server and never reach a client. Most are simply never
524
591
  | `NOT_FOUND` (counterparty) | Counterparty errors | The handlers return a plain 404, so you still receive `code: "NOT_FOUND"` — derived from the status rather than sent. Behaviour is identical; the declaration is dead. |
525
592
  | `ASSIGNMENT_NOT_FOUND` | Category assignment errors | A plain 404 with the status-derived `NOT_FOUND`. |
526
593
  | `REPORT_VAULT_NOT_FOUND` | Report errors, and one report handler does build it | Every report endpoint sits behind the vault-membership middleware, which resolves the vault first and answers its own 404 — so the handler's check cannot be the one that fires. You get the status-derived `NOT_FOUND`, with the middleware's `Vault "x" not found` as the message. |
594
+ | `INVALID_NOTE` | Transfer creation errors (a `note` over 500 characters) | The request schema refuses such a `note` first, with 400 `BAD_REQUEST`; the service's own check is for calls that bypass the schema, and cleaning a note only ever shortens it. |
527
595
  | `STEP_REF_UNRESOLVED` | Approval-request error codes | It is raised, but only inside the composite-chain runner, when a `$step:N` reference names a step that has no result yet. The runner's `catch` keeps the sentence and drops the code, so what leaves is `CHAIN_FAILED_ROLLED_BACK` or `CHAIN_FAILED_PARTIAL` with that sentence inside `message`. Handle those; `hasCode(e, 'STEP_REF_UNRESOLVED')` is never true. |
528
596
 
529
597
  Two further codes are reachable only through server misconfiguration and are worth knowing so you classify them correctly rather than showing them to a user: `DB_REQUIRED` (500, a money path reached without its database binding — fail-closed, nothing is left locked) and `VAULT_HAS_NO_WALLET_SERVICE` / `NO_DYNAMIC_ROUTE` / `TOKEN_NOT_REGISTERED` (500, vault configuration gaps that make transfers or address creation impossible until an administrator fixes them).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@v3finance/core-sdk",
3
- "version": "0.4.0",
3
+ "version": "0.5.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
@@ -67,6 +67,13 @@ import { DEFAULT_BASE_URL } from './version.js'
67
67
  * ```
68
68
  */
69
69
 
70
+ /**
71
+ * The three shapes of `logoPath`: a network's or a token's under `/logos`, an
72
+ * address's under its vault. The query (`?v=…`) is kept as it came.
73
+ */
74
+ const LOGO_PATH =
75
+ /^\/api\/v1\/(?:logos\/(?:networks|tokens)\/[^/?#]+|vaults\/[^/?#]+\/addresses\/[^/?#]+\/logo)(?:\?[^#]*)?$/
76
+
70
77
  export interface VaultScope {
71
78
  readonly code: string
72
79
  readonly addresses: AddressesResource
@@ -220,6 +227,39 @@ export class CoreClient {
220
227
  return this.http.request<Health>('GET', '/')
221
228
  }
222
229
 
230
+ /**
231
+ * A logo, fetched through the API: the image of a network, a token or an
232
+ * address, read from the `logoPath` its record carries. Returns the
233
+ * untouched `Response` — read it with `.blob()`.
234
+ *
235
+ * Why not `logoUri`: the server fetches the picture, so the image's host
236
+ * sees neither the person's IP nor what they opened. Pass `logoPath` WHOLE,
237
+ * as the API returned it — its `?v=` is the version of the link, and a new
238
+ * `logoUri` gives a new path, so a client's day-long cache of the old one
239
+ * does not get in the way. `null` there means there is nothing to fetch;
240
+ * a path is not a promise of an image either (502 `LOGO_UNAVAILABLE` when
241
+ * the source does not deliver one, 404 `LOGO_NOT_FOUND` when there is none
242
+ * to fetch).
243
+ *
244
+ * An address's logo is seen by whoever sees the address card. Its
245
+ * `logoUri` is chosen by the address's owner and fetched at the moment of
246
+ * VIEWING, so a unique link to their own host tells them that — and
247
+ * roughly from where — someone opened the address (never the viewer's IP).
248
+ * A cautious client loads the logos of other people's addresses only on an
249
+ * explicit action.
250
+ *
251
+ * Throws, without a request, for a path that is not one of the three logo
252
+ * paths: this is not a general-purpose GET.
253
+ */
254
+ logo(logoPath: string, options: { signal?: AbortSignal | undefined } = {}): Promise<Response> {
255
+ if (!LOGO_PATH.test(logoPath)) {
256
+ return Promise.reject(
257
+ new Error(`@v3finance/core-sdk: not a logoPath the API returns: ${logoPath}`),
258
+ )
259
+ }
260
+ return this.http.fetchRaw('GET', logoPath, { signal: options.signal })
261
+ }
262
+
223
263
  /** The caller's own profile, devices and permissions. */
224
264
  readonly me: MeResource
225
265
 
package/src/core/gated.ts CHANGED
@@ -4,10 +4,11 @@
4
4
  *
5
5
  * 201 — applied immediately (policy allowed it without signatures);
6
6
  * 202 — queued for approval, funds are reserved, nothing has moved yet;
7
- * 200 — on a transfer: a replay of the same idempotency key, nothing
8
- * happened now and the existing operation came back (no second
9
- * broadcast). Everywhere else: an ordinary applied success, because
10
- * an edit is not a creation and answers 200 (see `replayOn200`).
7
+ * 200 — on a transfer or an address: a replay of the same idempotency
8
+ * key, nothing happened now and the existing operation came back (no
9
+ * second broadcast, no second address). Everywhere else: an ordinary
10
+ * applied success, because an edit is not a creation and answers 200
11
+ * (see `replayOn200`).
11
12
  *
12
13
  * The body can be identical: a transfer returns `{transaction}` in all three.
13
14
  * A client that reads only the body will say "sent" where the truth is
@@ -48,12 +49,13 @@ export type Gated<TApplied, TPending = TApplied> =
48
49
  * of the two it is instead of the helper guessing.
49
50
  *
50
51
  * Which also means `outcome: 'replayed'` is UNREACHABLE for every gated
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.
52
+ * method other than `transfers.send`, `transferDrafts.send` and
53
+ * `addresses.create`: replay protection needs an idempotency key, and the API
54
+ * has one only on a transfer — taken from the transfer body, or derived from
55
+ * the draft when a draft is sent — and on the creation of an address, where
56
+ * it is optional. The three-way `switch` in `docs/concepts.md` is right for
57
+ * those; beside a counterparty edit its `case 'replayed'` is dead, and it is
58
+ * not evidence that such an edit can come back as a replay.
57
59
  */
58
60
  export function toGated<TApplied, TPending>(
59
61
  status: number,
package/src/core/http.ts CHANGED
@@ -83,9 +83,28 @@ export interface ClientOptions {
83
83
  headers?: Record<string, string>
84
84
  }
85
85
 
86
+ /**
87
+ * A body sent as it is instead of as JSON: a file.
88
+ *
89
+ * `fetch` writes `Content-Length` itself for every one of these — the API
90
+ * requires it on a raw upload (411 without it) — and the multipart boundary for
91
+ * a `FormData`. A stream is deliberately not accepted: its length is unknown
92
+ * up front, so fetch would send it chunked and the upload would be refused.
93
+ */
94
+ export type RawBody = Blob | ArrayBuffer | Uint8Array | FormData
95
+
86
96
  export interface RequestOptions {
87
97
  query?: Query | undefined
98
+ /** Serialised with `JSON.stringify` and sent as `application/json`. */
88
99
  body?: unknown
100
+ /**
101
+ * Sent untouched — for the endpoints that take a FILE. Mutually exclusive
102
+ * with `body`. Set `contentType` for a binary body; leave it unset for a
103
+ * `FormData`, whose `Content-Type` carries a boundary only fetch knows.
104
+ */
105
+ rawBody?: RawBody | undefined
106
+ /** `Content-Type` of `rawBody`. Ignored without one. */
107
+ contentType?: string | undefined
89
108
  signal?: AbortSignal | undefined
90
109
  timeoutMs?: number | undefined
91
110
  /**
@@ -252,6 +271,9 @@ export class HttpClient {
252
271
  readPayload: (response: Response, endpoint: string) => Promise<unknown>,
253
272
  ): Promise<{ response: Response; endpoint: string; payload: unknown }> {
254
273
  const endpoint = `${method.toUpperCase()} ${path}`
274
+ if (options.body !== undefined && options.rawBody !== undefined) {
275
+ throw new Error(`@v3finance/core-sdk: ${endpoint} was given both a JSON body and a raw body.`)
276
+ }
255
277
  const url = `${this.baseUrl}${path}${serializeQuery(options.query)}`
256
278
  const timeoutMs = options.timeoutMs ?? this.#timeoutMs
257
279
 
@@ -263,6 +285,9 @@ export class HttpClient {
263
285
  ...options.headers,
264
286
  }
265
287
  if (options.body !== undefined) headers['content-type'] = 'application/json'
288
+ else if (options.rawBody !== undefined && options.contentType !== undefined) {
289
+ headers['content-type'] = options.contentType
290
+ }
266
291
  // NOTHING ELSE IS ADDED BY DEFAULT, and that is a browser constraint
267
292
  // rather than minimalism: the API's CORS preflight allows exactly
268
293
  // `Content-Type` and `Authorization`, so any further header of ours makes
@@ -297,7 +322,11 @@ export class HttpClient {
297
322
  response = await this.#fetch(url, {
298
323
  method: method.toUpperCase(),
299
324
  headers,
300
- ...(options.body === undefined ? {} : { body: JSON.stringify(options.body) }),
325
+ ...(options.rawBody !== undefined
326
+ ? { body: options.rawBody as BodyInit }
327
+ : options.body === undefined
328
+ ? {}
329
+ : { body: JSON.stringify(options.body) }),
301
330
  ...(this.#options.credentials === undefined
302
331
  ? {}
303
332
  : { credentials: this.#options.credentials }),
@@ -1,21 +1,23 @@
1
1
  /**
2
- * Keyset pagination — for the twelve endpoints that have it.
2
+ * Keyset pagination — for the fourteen 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
- * • 12 GETs take `cursor`/`limit` and answer a `nextCursor` — addresses,
8
+ * • 14 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, transfer drafts. These are what `paginate`
12
- * is for;
13
- * • 18 answer `{items}` with NO cursor parameter at all — folders and their
11
+ * vault's policies, balances, transfer drafts, the policy directory and
12
+ * your own sessions (`me.sessions`). These are what `paginate` is for;
13
+ * • 20 answer `{items}` with NO cursor parameter at all — folders and their
14
14
  * grants, address shares, shared-with-me / shared-by-me, visibility
15
- * grants, category assignments and their versions, report templates and
16
- * snapshots, user groups and their members, status history, the
17
- * admin-level `/policies` list and one policy's versions (18 paths, two
18
- * of them the older `/address-groups` prefix of the folder endpoints).
15
+ * grants, category assignments (and the categories available for one
16
+ * operation) and their versions, report templates and snapshots, user
17
+ * groups and their members, status history, an operation's attachments,
18
+ * the admin-level `/policies` list, one policy's versions and the admin
19
+ * list of shared on-chain addresses (20 paths, two of them the older
20
+ * `/address-groups` prefix of the folder endpoints).
19
21
  * What you get is everything there is; `paginate` over one of them yields
20
22
  * that single page and stops, because an absent `nextCursor` is the
21
23
  * end-of-list signal;