@v3finance/core-sdk 0.5.0 → 0.7.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 (74) hide show
  1. package/CHANGELOG.md +77 -0
  2. package/dist/cjs/client.d.ts +3 -0
  3. package/dist/cjs/client.d.ts.map +1 -1
  4. package/dist/cjs/client.js +2 -0
  5. package/dist/cjs/client.js.map +1 -1
  6. package/dist/cjs/generated/operations.d.ts +104 -0
  7. package/dist/cjs/generated/operations.d.ts.map +1 -1
  8. package/dist/cjs/generated/operations.js +106 -2
  9. package/dist/cjs/generated/operations.js.map +1 -1
  10. package/dist/cjs/generated/types.d.ts +283 -3
  11. package/dist/cjs/generated/types.d.ts.map +1 -1
  12. package/dist/cjs/index.d.ts +1 -0
  13. package/dist/cjs/index.d.ts.map +1 -1
  14. package/dist/cjs/index.js +3 -1
  15. package/dist/cjs/index.js.map +1 -1
  16. package/dist/cjs/resources/aml.d.ts +107 -0
  17. package/dist/cjs/resources/aml.d.ts.map +1 -0
  18. package/dist/cjs/resources/aml.js +141 -0
  19. package/dist/cjs/resources/aml.js.map +1 -0
  20. package/dist/cjs/resources/approvals.d.ts +6 -0
  21. package/dist/cjs/resources/approvals.d.ts.map +1 -1
  22. package/dist/cjs/resources/approvals.js.map +1 -1
  23. package/dist/cjs/resources/members.d.ts +11 -1
  24. package/dist/cjs/resources/members.d.ts.map +1 -1
  25. package/dist/cjs/resources/members.js +12 -0
  26. package/dist/cjs/resources/members.js.map +1 -1
  27. package/dist/cjs/resources/registries.d.ts +10 -1
  28. package/dist/cjs/resources/registries.d.ts.map +1 -1
  29. package/dist/cjs/resources/registries.js +11 -0
  30. package/dist/cjs/resources/registries.js.map +1 -1
  31. package/dist/cjs/version.d.ts +1 -1
  32. package/dist/cjs/version.js +1 -1
  33. package/dist/esm/client.d.ts +3 -0
  34. package/dist/esm/client.d.ts.map +1 -1
  35. package/dist/esm/client.js +2 -0
  36. package/dist/esm/client.js.map +1 -1
  37. package/dist/esm/generated/operations.d.ts +104 -0
  38. package/dist/esm/generated/operations.d.ts.map +1 -1
  39. package/dist/esm/generated/operations.js +106 -2
  40. package/dist/esm/generated/operations.js.map +1 -1
  41. package/dist/esm/generated/types.d.ts +283 -3
  42. package/dist/esm/generated/types.d.ts.map +1 -1
  43. package/dist/esm/index.d.ts +1 -0
  44. package/dist/esm/index.d.ts.map +1 -1
  45. package/dist/esm/index.js +1 -0
  46. package/dist/esm/index.js.map +1 -1
  47. package/dist/esm/resources/aml.d.ts +107 -0
  48. package/dist/esm/resources/aml.d.ts.map +1 -0
  49. package/dist/esm/resources/aml.js +137 -0
  50. package/dist/esm/resources/aml.js.map +1 -0
  51. package/dist/esm/resources/approvals.d.ts +6 -0
  52. package/dist/esm/resources/approvals.d.ts.map +1 -1
  53. package/dist/esm/resources/approvals.js.map +1 -1
  54. package/dist/esm/resources/members.d.ts +11 -1
  55. package/dist/esm/resources/members.d.ts.map +1 -1
  56. package/dist/esm/resources/members.js +12 -0
  57. package/dist/esm/resources/members.js.map +1 -1
  58. package/dist/esm/resources/registries.d.ts +10 -1
  59. package/dist/esm/resources/registries.d.ts.map +1 -1
  60. package/dist/esm/resources/registries.js +11 -0
  61. package/dist/esm/resources/registries.js.map +1 -1
  62. package/dist/esm/version.d.ts +1 -1
  63. package/dist/esm/version.js +1 -1
  64. package/docs/errors.md +10 -0
  65. package/package.json +1 -1
  66. package/src/client.ts +4 -0
  67. package/src/generated/operations.ts +106 -2
  68. package/src/generated/types.ts +307 -3
  69. package/src/index.ts +1 -0
  70. package/src/resources/aml.ts +169 -0
  71. package/src/resources/approvals.ts +6 -0
  72. package/src/resources/members.ts +19 -0
  73. package/src/resources/registries.ts +13 -0
  74. package/src/version.ts +1 -1
@@ -0,0 +1,169 @@
1
+ import { seg, type HttpClient } from '../core/http.js'
2
+ import { toGated, type Gated } from '../core/gated.js'
3
+ import type {
4
+ AmlCheck,
5
+ AmlOfficers,
6
+ AmlRecheckBody,
7
+ AmlSettings,
8
+ AmlVisibilityGrant,
9
+ AmlVisibilityGrants,
10
+ ApprovalRequestCreated,
11
+ CreateAmlVisibilityGrantBody,
12
+ UpdateAmlSettingsBody,
13
+ } from '../generated/types.js'
14
+
15
+ /**
16
+ * AML checks of a vault, in the typed model (AML v2).
17
+ *
18
+ * WHAT YOU GET DEPENDS ON WHO YOU ARE, and `view` on the answer says which:
19
+ * `summary` — level, score, categories; `links` — plus the address's links;
20
+ * `full` (`getCheck` only) — plus the provider's own response, typed. Admins
21
+ * and AML officers get everything; a member gets the vault's default
22
+ * (`summary` unless changed) widened by their visibility grants. The server
23
+ * decides; reading `links` from a `summary` answer gets `undefined`, not an
24
+ * error.
25
+ *
26
+ * `level` is what to branch on. `null` means NOT CHECKED, never "clean" —
27
+ * draw it as a third, neutral state. `share` and `amountUsd` are `null` for
28
+ * Scorechain because the provider sends no amounts: show "no data", not
29
+ * "0 %". What a provider can do at all is in `registries.amlProviders()`.
30
+ *
31
+ * Not to be confused with `registries.amlScore()`: that one keeps the
32
+ * earlier shape for the transfer form; this one is the model decisions are
33
+ * made on, with a record id you can come back to.
34
+ */
35
+ export class AmlResource {
36
+ readonly #http: HttpClient
37
+ readonly #base: string
38
+
39
+ constructor(http: HttpClient, vaultCode: string) {
40
+ this.#http = http
41
+ this.#base = `/api/v1/vaults/${seg(vaultCode)}/aml`
42
+ }
43
+
44
+ /**
45
+ * A check of the address. A stored one younger than 24 hours is returned
46
+ * as is (`cached: true`); otherwise the provider is called and a new
47
+ * record is written. 502 `AML_UNAVAILABLE` — the provider is down: show
48
+ * "could not check", not a green badge.
49
+ */
50
+ check(
51
+ address: string,
52
+ options: { provider?: AmlCheck['provider'] | undefined; signal?: AbortSignal | undefined } = {},
53
+ ): Promise<AmlCheck> {
54
+ return this.#http.request<AmlCheck>('GET', `${this.#base}/checks`, {
55
+ query: { address, provider: options.provider },
56
+ signal: options.signal,
57
+ })
58
+ }
59
+
60
+ /**
61
+ * A fresh check, always calling the provider. Paid per call — only on an
62
+ * explicit action of a person. Admins only (403 for a member).
63
+ */
64
+ recheck(input: AmlRecheckBody): Promise<AmlCheck> {
65
+ return this.#http.request<AmlCheck>('POST', `${this.#base}/checks`, { body: input })
66
+ }
67
+
68
+ /**
69
+ * One record. This is how an operation's snapshot is opened: pass its
70
+ * `amlCheckId` — what was known at the moment of the transfer or deposit.
71
+ * Records never change. Any member, in their own `view`; only `full`
72
+ * carries `native` (`null` — the full response is not in the archive).
73
+ */
74
+ getCheck(id: string): Promise<AmlCheck> {
75
+ return this.#http.request<AmlCheck>('GET', `${this.#base}/checks/${seg(id)}`)
76
+ }
77
+
78
+ /**
79
+ * The provider's response byte for byte, for audit (hundreds of kilobytes
80
+ * for an active address). Returns the untouched `Response`. 404
81
+ * `AML_RAW_NOT_FOUND` — not archived for this record; 501
82
+ * `AML_ARCHIVE_DISABLED` — no archive on the server. Only with `full`
83
+ * (admins, officers, a `full` visibility grant) — 403 otherwise.
84
+ */
85
+ rawCheck(id: string, options: { signal?: AbortSignal | undefined } = {}): Promise<Response> {
86
+ return this.#http.fetchRaw('GET', `${this.#base}/checks/${seg(id)}/raw`, {
87
+ signal: options.signal,
88
+ })
89
+ }
90
+
91
+ /**
92
+ * The vault's AML officers, and who appointed them when. These are the
93
+ * people an approver `{ kind: 'aml_officers' }` resolves to — at the moment
94
+ * a request is created, not later. Admins and officers only (403 for a
95
+ * member). Appointing is `members.setAmlOfficer()`.
96
+ */
97
+ officers(): Promise<AmlOfficers> {
98
+ return this.#http.request<AmlOfficers>('GET', `${this.#base}/officers`)
99
+ }
100
+
101
+
102
+ /**
103
+ * The vault's AML settings: providers (enabled, default — whose check is
104
+ * recorded on every operation — and how fresh a stored check may be) and
105
+ * what any member sees without a grant. Untouched vault — Scorechain,
106
+ * 24 h, `summary`. Admins and officers only.
107
+ */
108
+ settings(): Promise<AmlSettings> {
109
+ return this.#http.request<AmlSettings>('GET', `${this.#base}/settings`)
110
+ }
111
+
112
+ /**
113
+ * Changes the settings; absent fields stay as they are. The RESULTING state
114
+ * is validated: exactly one enabled default provider (400
115
+ * `AML_DEFAULT_PROVIDER_REQUIRED`), `maxAgeSeconds` 0…30 days (0 — every
116
+ * check calls the paid provider). Admins and officers only.
117
+ */
118
+ updateSettings(input: UpdateAmlSettingsBody): Promise<AmlSettings> {
119
+ return this.#http.request<AmlSettings>('PUT', `${this.#base}/settings`, { body: input })
120
+ }
121
+
122
+ /** Who sees more than the vault's default. Admins and officers only. */
123
+ visibilityGrants(params: { includeRevoked?: boolean | undefined } = {}): Promise<AmlVisibilityGrants> {
124
+ return this.#http.request<AmlVisibilityGrants>('GET', `${this.#base}/visibility-grants`, {
125
+ query: { ...params },
126
+ })
127
+ }
128
+
129
+ /**
130
+ * Opens `links` or `full` to a member or a group (its CURRENT members).
131
+ * Idempotent like every grant: the same subject again changes the role or
132
+ * reactivates a revoked grant. You must be able to see the member
133
+ * (`NOT_VISIBLE`); not to yourself (`SELF_SHARE`). Admins and officers only.
134
+ */
135
+ grantVisibility(input: CreateAmlVisibilityGrantBody): Promise<AmlVisibilityGrant> {
136
+ return this.#http.request<AmlVisibilityGrant>('POST', `${this.#base}/visibility-grants`, {
137
+ body: input,
138
+ })
139
+ }
140
+
141
+ /** Soft and immediate; repeating it is not an error. Admins and officers only. */
142
+ revokeVisibility(grantId: string): Promise<AmlVisibilityGrant> {
143
+ return this.#http.request<AmlVisibilityGrant>(
144
+ 'DELETE',
145
+ `${this.#base}/visibility-grants/${seg(grantId)}`,
146
+ )
147
+ }
148
+
149
+
150
+ /**
151
+ * Checks one of OUR addresses with the provider — how the provider sees it
152
+ * (blacklisted or not). Not done by default: only with permission.
153
+ *
154
+ * Admins and officers — at once. A member — by their policy on the action
155
+ * `aml_check_internal`: an allowing one checks at once, one that needs
156
+ * approval (typically from `{ kind: 'aml_officers' }`) returns the created
157
+ * request instead, and the check runs once it is approved — its record id
158
+ * is the request's `resolvedResultId`. No policy — 403. No view of the
159
+ * address — 404. Always a fresh, paid provider call. `outcome: 'applied'`
160
+ * carries the check; `'pending'` — the request awaiting approval.
161
+ */
162
+ async checkInternal(addressId: string): Promise<Gated<AmlCheck, ApprovalRequestCreated>> {
163
+ const res = await this.#http.requestRaw<unknown>('POST', `${this.#base}/internal-checks`, {
164
+ body: { addressId },
165
+ })
166
+ return toGated<AmlCheck, ApprovalRequestCreated>(res.status, res.data)
167
+ }
168
+
169
+ }
@@ -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
  }
@@ -1,5 +1,6 @@
1
1
  import type { HttpClient } from '../core/http.js'
2
2
  import type {
3
+ AmlProviders,
3
4
  AmlValue,
4
5
  CreateNetworkBody,
5
6
  CreateTokenBody,
@@ -169,6 +170,18 @@ export class RegistriesResource {
169
170
  })
170
171
  }
171
172
 
173
+ /**
174
+ * AML providers and what each can do. `capabilities` decides which rule
175
+ * conditions a provider can serve: Scorechain has no shares of funds, no
176
+ * entity of the address itself and no separate sanction authorities, and
177
+ * the server will refuse a rule that needs them — so do not offer those
178
+ * conditions in a rule builder. The registry is code, the same for every
179
+ * vault.
180
+ */
181
+ amlProviders(): Promise<AmlProviders> {
182
+ return this.#http.request<AmlProviders>('GET', '/api/v1/aml/providers')
183
+ }
184
+
172
185
  /**
173
186
  * Registering a network. Administrators only.
174
187
  *
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.5.0'
2
+ export const SDK_VERSION = '0.7.0'
3
3
 
4
4
  /** Default API base URL. */
5
5
  export const DEFAULT_BASE_URL = 'https://policy-engine-rest.ezig.workers.dev'