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