@v3finance/core-sdk 0.6.0 → 0.8.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 (47) hide show
  1. package/CHANGELOG.md +73 -0
  2. package/dist/cjs/generated/operations.d.ts +138 -2
  3. package/dist/cjs/generated/operations.d.ts.map +1 -1
  4. package/dist/cjs/generated/operations.js +140 -4
  5. package/dist/cjs/generated/operations.js.map +1 -1
  6. package/dist/cjs/generated/types.d.ts +318 -7
  7. package/dist/cjs/generated/types.d.ts.map +1 -1
  8. package/dist/cjs/resources/aml.d.ts +102 -10
  9. package/dist/cjs/resources/aml.d.ts.map +1 -1
  10. package/dist/cjs/resources/aml.js +140 -9
  11. package/dist/cjs/resources/aml.js.map +1 -1
  12. package/dist/cjs/resources/approvals.d.ts +6 -0
  13. package/dist/cjs/resources/approvals.d.ts.map +1 -1
  14. package/dist/cjs/resources/approvals.js.map +1 -1
  15. package/dist/cjs/resources/members.d.ts +11 -1
  16. package/dist/cjs/resources/members.d.ts.map +1 -1
  17. package/dist/cjs/resources/members.js +12 -0
  18. package/dist/cjs/resources/members.js.map +1 -1
  19. package/dist/cjs/version.d.ts +1 -1
  20. package/dist/cjs/version.js +1 -1
  21. package/dist/esm/generated/operations.d.ts +138 -2
  22. package/dist/esm/generated/operations.d.ts.map +1 -1
  23. package/dist/esm/generated/operations.js +140 -4
  24. package/dist/esm/generated/operations.js.map +1 -1
  25. package/dist/esm/generated/types.d.ts +318 -7
  26. package/dist/esm/generated/types.d.ts.map +1 -1
  27. package/dist/esm/resources/aml.d.ts +102 -10
  28. package/dist/esm/resources/aml.d.ts.map +1 -1
  29. package/dist/esm/resources/aml.js +140 -9
  30. package/dist/esm/resources/aml.js.map +1 -1
  31. package/dist/esm/resources/approvals.d.ts +6 -0
  32. package/dist/esm/resources/approvals.d.ts.map +1 -1
  33. package/dist/esm/resources/approvals.js.map +1 -1
  34. package/dist/esm/resources/members.d.ts +11 -1
  35. package/dist/esm/resources/members.d.ts.map +1 -1
  36. package/dist/esm/resources/members.js +12 -0
  37. package/dist/esm/resources/members.js.map +1 -1
  38. package/dist/esm/version.d.ts +1 -1
  39. package/dist/esm/version.js +1 -1
  40. package/docs/errors.md +16 -0
  41. package/package.json +1 -1
  42. package/src/generated/operations.ts +140 -4
  43. package/src/generated/types.ts +343 -7
  44. package/src/resources/aml.ts +186 -10
  45. package/src/resources/approvals.ts +6 -0
  46. package/src/resources/members.ts +19 -0
  47. package/src/version.ts +1 -1
@@ -1,14 +1,37 @@
1
1
  import { seg, type HttpClient } from '../core/http.js'
2
- import type { AmlCheck, AmlRecheckBody } from '../generated/types.js'
2
+ import { toGated, type Gated } from '../core/gated.js'
3
+ import type {
4
+ AddAmlStopListBody,
5
+ AmlDepositReview,
6
+ AmlRule,
7
+ AmlRuleEvaluateBody,
8
+ AmlRuleEvaluation,
9
+ AmlRules,
10
+ AmlStopList,
11
+ AmlStopListEntry,
12
+ CreateAmlRuleBody,
13
+ PatchAmlRuleBody,
14
+ AmlCheck,
15
+ AmlOfficers,
16
+ AmlRecheckBody,
17
+ AmlSettings,
18
+ AmlVisibilityGrant,
19
+ AmlVisibilityGrants,
20
+ ApprovalRequestCreated,
21
+ CreateAmlVisibilityGrantBody,
22
+ UpdateAmlSettingsBody,
23
+ } from '../generated/types.js'
3
24
 
4
25
  /**
5
26
  * AML checks of a vault, in the typed model (AML v2).
6
27
  *
7
28
  * WHAT YOU GET DEPENDS ON WHO YOU ARE, and `view` on the answer says which:
8
- * `summary` (any member) — level, score, categories; `links` (a vault or
9
- * platform admin) — plus the address's links; `full` (`getCheck` only) —
10
- * plus the provider's own response, typed. The server decides; reading
11
- * `links` from a `summary` answer gets `undefined`, not an error.
29
+ * `summary` — level, score, categories; `links` — plus the address's links;
30
+ * `full` (`getCheck` only) — plus the provider's own response, typed. Admins
31
+ * and AML officers get everything; a member gets the vault's default
32
+ * (`summary` unless changed) widened by their visibility grants. The server
33
+ * decides; reading `links` from a `summary` answer gets `undefined`, not an
34
+ * error.
12
35
  *
13
36
  * `level` is what to branch on. `null` means NOT CHECKED, never "clean" —
14
37
  * draw it as a third, neutral state. `share` and `amountUsd` are `null` for
@@ -53,10 +76,10 @@ export class AmlResource {
53
76
  }
54
77
 
55
78
  /**
56
- * One record, whole (`view: full`). This is how an operation's snapshot is
57
- * opened: pass its `amlCheckId` — what was known at the moment of the
58
- * transfer or deposit. Records never change. `native: null` — the full
59
- * provider response is not in the archive. Admins only.
79
+ * One record. This is how an operation's snapshot is opened: pass its
80
+ * `amlCheckId` — what was known at the moment of the transfer or deposit.
81
+ * Records never change. Any member, in their own `view`; only `full`
82
+ * carries `native` (`null` — the full response is not in the archive).
60
83
  */
61
84
  getCheck(id: string): Promise<AmlCheck> {
62
85
  return this.#http.request<AmlCheck>('GET', `${this.#base}/checks/${seg(id)}`)
@@ -66,11 +89,164 @@ export class AmlResource {
66
89
  * The provider's response byte for byte, for audit (hundreds of kilobytes
67
90
  * for an active address). Returns the untouched `Response`. 404
68
91
  * `AML_RAW_NOT_FOUND` — not archived for this record; 501
69
- * `AML_ARCHIVE_DISABLED` — no archive on the server. Admins only.
92
+ * `AML_ARCHIVE_DISABLED` — no archive on the server. Only with `full`
93
+ * (admins, officers, a `full` visibility grant) — 403 otherwise.
70
94
  */
71
95
  rawCheck(id: string, options: { signal?: AbortSignal | undefined } = {}): Promise<Response> {
72
96
  return this.#http.fetchRaw('GET', `${this.#base}/checks/${seg(id)}/raw`, {
73
97
  signal: options.signal,
74
98
  })
75
99
  }
100
+
101
+ /**
102
+ * The vault's AML officers, and who appointed them when. These are the
103
+ * people an approver `{ kind: 'aml_officers' }` resolves to — at the moment
104
+ * a request is created, not later. Admins and officers only (403 for a
105
+ * member). Appointing is `members.setAmlOfficer()`.
106
+ */
107
+ officers(): Promise<AmlOfficers> {
108
+ return this.#http.request<AmlOfficers>('GET', `${this.#base}/officers`)
109
+ }
110
+
111
+
112
+ /**
113
+ * The vault's AML settings: providers (enabled, default — whose check is
114
+ * recorded on every operation — and how fresh a stored check may be) and
115
+ * what any member sees without a grant. Untouched vault — Scorechain,
116
+ * 24 h, `summary`. Admins and officers only.
117
+ */
118
+ settings(): Promise<AmlSettings> {
119
+ return this.#http.request<AmlSettings>('GET', `${this.#base}/settings`)
120
+ }
121
+
122
+ /**
123
+ * Changes the settings; absent fields stay as they are. The RESULTING state
124
+ * is validated: exactly one enabled default provider (400
125
+ * `AML_DEFAULT_PROVIDER_REQUIRED`), `maxAgeSeconds` 0…30 days (0 — every
126
+ * check calls the paid provider). Admins and officers only.
127
+ */
128
+ updateSettings(input: UpdateAmlSettingsBody): Promise<AmlSettings> {
129
+ return this.#http.request<AmlSettings>('PUT', `${this.#base}/settings`, { body: input })
130
+ }
131
+
132
+ /** Who sees more than the vault's default. Admins and officers only. */
133
+ visibilityGrants(params: { includeRevoked?: boolean | undefined } = {}): Promise<AmlVisibilityGrants> {
134
+ return this.#http.request<AmlVisibilityGrants>('GET', `${this.#base}/visibility-grants`, {
135
+ query: { ...params },
136
+ })
137
+ }
138
+
139
+ /**
140
+ * Opens `links` or `full` to a member or a group (its CURRENT members).
141
+ * Idempotent like every grant: the same subject again changes the role or
142
+ * reactivates a revoked grant. You must be able to see the member
143
+ * (`NOT_VISIBLE`); not to yourself (`SELF_SHARE`). Admins and officers only.
144
+ */
145
+ grantVisibility(input: CreateAmlVisibilityGrantBody): Promise<AmlVisibilityGrant> {
146
+ return this.#http.request<AmlVisibilityGrant>('POST', `${this.#base}/visibility-grants`, {
147
+ body: input,
148
+ })
149
+ }
150
+
151
+ /** Soft and immediate; repeating it is not an error. Admins and officers only. */
152
+ revokeVisibility(grantId: string): Promise<AmlVisibilityGrant> {
153
+ return this.#http.request<AmlVisibilityGrant>(
154
+ 'DELETE',
155
+ `${this.#base}/visibility-grants/${seg(grantId)}`,
156
+ )
157
+ }
158
+
159
+
160
+ /**
161
+ * Checks one of OUR addresses with the provider — how the provider sees it
162
+ * (blacklisted or not). Not done by default: only with permission.
163
+ *
164
+ * Admins and officers — at once. A member — by their policy on the action
165
+ * `aml_check_internal`: an allowing one checks at once, one that needs
166
+ * approval (typically from `{ kind: 'aml_officers' }`) returns the created
167
+ * request instead, and the check runs once it is approved — its record id
168
+ * is the request's `resolvedResultId`. No policy — 403. No view of the
169
+ * address — 404. Always a fresh, paid provider call. `outcome: 'applied'`
170
+ * carries the check; `'pending'` — the request awaiting approval.
171
+ */
172
+ async checkInternal(addressId: string): Promise<Gated<AmlCheck, ApprovalRequestCreated>> {
173
+ const res = await this.#http.requestRaw<unknown>('POST', `${this.#base}/internal-checks`, {
174
+ body: { addressId },
175
+ })
176
+ return toGated<AmlCheck, ApprovalRequestCreated>(res.status, res.data)
177
+ }
178
+
179
+
180
+ // ---------- AML rules (A3) ----------
181
+
182
+ /**
183
+ * The vault's AML rules. A rule applies to the WHOLE vault, admins
184
+ * included, after the policies: it only ADDS — a block (`AML_BLOCKED`) or
185
+ * an AML officer's approval. It never allows what policies denied and never
186
+ * drops their approvals. Unknown risk leads to an officer, never to a
187
+ * block or a pass. Admins and officers only.
188
+ */
189
+ rules(): Promise<AmlRules> {
190
+ return this.#http.request<AmlRules>('GET', `${this.#base}/rules`)
191
+ }
192
+
193
+ /**
194
+ * Creates a rule. `scope` — which transfers (transfer selectors plus
195
+ * `destinationPattern`, the derivation path of OUR recipient address);
196
+ * `risk` — on what risk (`null` — always); `subject: 'provenance'` judges
197
+ * where the sender's funds came from instead of the recipient. A condition
198
+ * the provider cannot serve is a 400 `AML_PROVIDER_CAPABILITY`.
199
+ */
200
+ createRule(input: CreateAmlRuleBody): Promise<AmlRule> {
201
+ return this.#http.request<AmlRule>('POST', `${this.#base}/rules`, { body: input })
202
+ }
203
+
204
+ getRule(ruleId: string): Promise<AmlRule> {
205
+ return this.#http.request<AmlRule>('GET', `${this.#base}/rules/${seg(ruleId)}`)
206
+ }
207
+
208
+ /** Absent fields stay; the RESULTING rule is validated. Every change is a new `version`. */
209
+ updateRule(ruleId: string, patch: PatchAmlRuleBody): Promise<AmlRule> {
210
+ return this.#http.request<AmlRule>('PATCH', `${this.#base}/rules/${seg(ruleId)}`, { body: patch })
211
+ }
212
+
213
+ /**
214
+ * Dry run of the AML rules only (not the caller's policies) for a transfer
215
+ * from `fromAddressId` to `address`. `ruleIds` runs exactly those rules,
216
+ * DISABLED ones included — to see a rule before switching it on. `amount`
217
+ * is a decimal string, as in `transfers.create`.
218
+ */
219
+ evaluateRules(input: AmlRuleEvaluateBody): Promise<AmlRuleEvaluation> {
220
+ return this.#http.request<AmlRuleEvaluation>('POST', `${this.#base}/rules/evaluate`, { body: input })
221
+ }
222
+
223
+ // ---------- Stop list (A3) ----------
224
+
225
+ /** Addresses the vault considers unacceptable. Acts only through a rule with a `stopList` leaf. */
226
+ stopList(params: { includeRevoked?: boolean | undefined } = {}): Promise<AmlStopList> {
227
+ return this.#http.request<AmlStopList>('GET', `${this.#base}/stop-list`, { query: { ...params } })
228
+ }
229
+
230
+ /** Idempotent: the same address again updates the reason or brings it back. EVM — stored lowercase. */
231
+ addToStopList(input: AddAmlStopListBody): Promise<AmlStopListEntry> {
232
+ return this.#http.request<AmlStopListEntry>('POST', `${this.#base}/stop-list`, { body: input })
233
+ }
234
+
235
+ /** Soft; repeating it is not an error. */
236
+ removeFromStopList(entryId: string): Promise<AmlStopListEntry> {
237
+ return this.#http.request<AmlStopListEntry>('DELETE', `${this.#base}/stop-list/${seg(entryId)}`)
238
+ }
239
+
240
+ /**
241
+ * An AML officer marks a past deposit as reviewed: it stops being a source
242
+ * of risk for provenance rules (they have no time window). AML officers
243
+ * only, and only from the PHONE — web sessions get 403
244
+ * `WEB_SESSION_CANNOT_SIGN`. One mark per deposit; a repeat returns it.
245
+ */
246
+ markDepositReviewed(depositId: string, comment: string): Promise<AmlDepositReview> {
247
+ return this.#http.request<AmlDepositReview>('POST', `${this.#base}/deposits/${seg(depositId)}/reviewed`, {
248
+ body: { comment },
249
+ })
250
+ }
251
+
76
252
  }
@@ -57,6 +57,12 @@ export interface ListApprovalsParams extends PageParams {
57
57
  vote?: 'approve' | 'reject' | 'any' | 'none' | undefined
58
58
  decisionPolicyId?: string | undefined
59
59
  targetType?: string | undefined
60
+ /**
61
+ * The AML officer's queue: pending requests waiting for MY vote that need
62
+ * an AML officer's approval (a policy with an `aml_officers` approver) or
63
+ * are an AML action themselves (`aml_check_internal`).
64
+ */
65
+ forAmlOfficer?: boolean | undefined
60
66
  /**
61
67
  * `newest` (default) or `oldest` — with `status: 'PENDING'`, the ones
62
68
  * waiting longest. A cursor belongs to its order: one from the other is a
@@ -2,6 +2,7 @@ import { seg, type HttpClient } from '../core/http.js'
2
2
  import type { PageParams } from '../core/pagination.js'
3
3
  import type {
4
4
  ActionType,
5
+ AmlOfficerState,
5
6
  MemberCard,
6
7
  MemberDetail,
7
8
  MembersPage,
@@ -123,4 +124,22 @@ export class MembersResource {
123
124
  `/api/v1/vaults/${this.#vault}/user-groups/${seg(groupId)}/members`,
124
125
  )
125
126
  }
127
+
128
+ /**
129
+ * Appoints or removes an AML officer. An officer is a FLAG on a member, not
130
+ * a role: a member or an admin of the vault can also be an officer. Vault
131
+ * or platform administrators only (403 otherwise). Idempotent.
132
+ *
133
+ * 409 `AML_LAST_OFFICER` — the last officer cannot be removed while an
134
+ * enabled policy needs an officer's approval: `details.policies` lists
135
+ * their codes. Change those policies first, or appoint another officer.
136
+ */
137
+ setAmlOfficer(userId: string, isAmlOfficer: boolean): Promise<AmlOfficerState> {
138
+ return this.#http.request<AmlOfficerState>(
139
+ 'PATCH',
140
+ `/api/v1/vaults/${this.#vault}/members/${seg(userId)}`,
141
+ { body: { isAmlOfficer } },
142
+ )
143
+ }
144
+
126
145
  }
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.6.0'
2
+ export const SDK_VERSION = '0.8.0'
3
3
 
4
4
  /** Default API base URL. */
5
5
  export const DEFAULT_BASE_URL = 'https://policy-engine-rest.ezig.workers.dev'