@v3finance/core-sdk 0.6.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 (47) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/dist/cjs/generated/operations.d.ts +66 -2
  3. package/dist/cjs/generated/operations.d.ts.map +1 -1
  4. package/dist/cjs/generated/operations.js +68 -4
  5. package/dist/cjs/generated/operations.js.map +1 -1
  6. package/dist/cjs/generated/types.d.ts +101 -3
  7. package/dist/cjs/generated/types.d.ts.map +1 -1
  8. package/dist/cjs/resources/aml.d.ts +61 -10
  9. package/dist/cjs/resources/aml.d.ts.map +1 -1
  10. package/dist/cjs/resources/aml.js +79 -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 +66 -2
  22. package/dist/esm/generated/operations.d.ts.map +1 -1
  23. package/dist/esm/generated/operations.js +68 -4
  24. package/dist/esm/generated/operations.js.map +1 -1
  25. package/dist/esm/generated/types.d.ts +101 -3
  26. package/dist/esm/generated/types.d.ts.map +1 -1
  27. package/dist/esm/resources/aml.d.ts +61 -10
  28. package/dist/esm/resources/aml.d.ts.map +1 -1
  29. package/dist/esm/resources/aml.js +79 -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 +7 -0
  41. package/package.json +1 -1
  42. package/src/generated/operations.ts +68 -4
  43. package/src/generated/types.ts +113 -3
  44. package/src/resources/aml.ts +103 -10
  45. package/src/resources/approvals.ts +6 -0
  46. package/src/resources/members.ts +19 -0
  47. package/src/version.ts +1 -1
@@ -46,7 +46,7 @@ export interface InvitationWithToken {
46
46
  }
47
47
 
48
48
  /** Тип действия, к которому применяется политика. Видимость участников СЮДА не входит: это грант (/vaults/:code/visibility-grants), а не политика */
49
- export type ActionType = "transfer" | "create_address" | "counterparty_create" | "counterparty_update" | "counterparty_archive" | "counterparty_group_create" | "counterparty_group_update" | "counterparty_group_archive" | "counterparty_group_add" | "counterparty_group_remove"
49
+ export type ActionType = "transfer" | "create_address" | "counterparty_create" | "counterparty_update" | "counterparty_archive" | "counterparty_group_create" | "counterparty_group_update" | "counterparty_group_archive" | "counterparty_group_add" | "counterparty_group_remove" | "aml_check_internal"
50
50
 
51
51
  /** Членство инициатора в группе (по id или по кодам) */
52
52
  export type ActorRoleValue = {
@@ -644,6 +644,29 @@ export interface AllowedSegmentsResponse {
644
644
  }
645
645
  }
646
646
 
647
+ export interface AmlOfficer {
648
+ id: string
649
+ name: string
650
+ username: string | null
651
+ image: string | null
652
+ color: string | null
653
+ emoji: string | null
654
+ amlOfficerGrantedById: string | null
655
+ amlOfficerGrantedAt: string | null
656
+ }
657
+
658
+ export interface AmlOfficerState {
659
+ userId: string
660
+ isAmlOfficer: boolean
661
+ /** Кто назначил; null — не офицер */
662
+ amlOfficerGrantedById: string | null
663
+ amlOfficerGrantedAt: string | null
664
+ }
665
+
666
+ export interface AmlOfficers {
667
+ items: AmlOfficer[]
668
+ }
669
+
647
670
  /** Риск второй стороны по данным AML-провайдера. ВАЖНО: уровень на операции — СНИМОК на момент решения, а не живая ссылка; текущий риск берётся отдельно через GET /aml/score */
648
671
  export interface AmlValue {
649
672
  /** Порог «не ниже чем» по УРОВНЮ риска второй стороны (у перевода — получателя). Уровень, а не числовой score: score калибруется провайдером и приходит вместе со своими thresholds, поэтому политика, написанная в числах, поехала бы вместе с их калибровкой */
@@ -1027,7 +1050,7 @@ export interface ApprovalRequirement {
1027
1050
  detail: string | null
1028
1051
  }
1029
1052
 
1030
- /** Одобряющий: {kind:"user", userId} или {kind:"group", groupId} (PolicyGroup — все члены на момент создания заявки резолвятся и снапшотятся) */
1053
+ /** Одобряющий: {kind:"user", userId}, {kind:"group", groupId} или {kind:"aml_officers"} — AML-офицеры Vault'а. group и aml_officers резолвятся в людей на момент создания заявки и снапшотятся: назначение или снятие офицера на ждущие заявки не влияет. Политику с aml_officers нельзя сохранить в Vault'е без офицеров (400) */
1031
1054
  export type ApproverSpec = {
1032
1055
  kind: "user"
1033
1056
  /** length: 1..∞ */
@@ -1036,6 +1059,8 @@ export type ApproverSpec = {
1036
1059
  kind: "group"
1037
1060
  /** length: 1..∞ */
1038
1061
  groupId: string
1062
+ } | {
1063
+ kind: "aml_officers"
1039
1064
  }
1040
1065
 
1041
1066
  export interface ArchiveCounterpartyBody {
@@ -2879,6 +2904,8 @@ export interface MemberDetail {
2879
2904
  id: string
2880
2905
  name: string
2881
2906
  }>
2907
+ /** AML-офицер этого Vault'а (AML v2): подтверждает AML-требования */
2908
+ isAmlOfficer: boolean
2882
2909
  }
2883
2910
 
2884
2911
  export interface MembersPage {
@@ -3487,7 +3514,7 @@ export interface PendingApproval {
3487
3514
  export interface PolicyApprover {
3488
3515
  id: string
3489
3516
  policyId: string
3490
- /** "user" | "group" */
3517
+ /** "user" | "group" | "aml_officers" */
3491
3518
  kind: string
3492
3519
  userId: string | null
3493
3520
  /** PolicyGroup при kind=group */
@@ -4016,6 +4043,10 @@ export interface SeatCreated {
4016
4043
  expiresAt: string
4017
4044
  }
4018
4045
 
4046
+ export interface SetAmlOfficerBody {
4047
+ isAmlOfficer: boolean
4048
+ }
4049
+
4019
4050
  /** Ручной выбор контрагента операции */
4020
4051
  export interface SetOperationCounterpartyBody {
4021
4052
  /** Контрагент этого Vault'а, не в архиве. null — «у этой операции контрагента нет»: тоже ручной выбор, ретро-матч его не перезапишет (вернуть к авто-матчу — DELETE) */
@@ -5980,6 +6011,15 @@ export interface ScorechainLinkNative {
5980
6011
  address: string
5981
6012
  }
5982
6013
 
6014
+ export interface AmlInternalCheckBody {
6015
+ /**
6016
+ * Наш адрес Vault'а
6017
+ *
6018
+ * length: 1..∞
6019
+ */
6020
+ addressId: string
6021
+ }
6022
+
5983
6023
  export interface AmlProvider {
5984
6024
  id: "scorechain"
5985
6025
  displayName: string
@@ -6009,3 +6049,73 @@ export interface AmlRecheckBody {
6009
6049
  address: string
6010
6050
  provider?: "scorechain"
6011
6051
  }
6052
+
6053
+ export interface AmlSettings {
6054
+ /** Что видит ЛЮБОЙ участник Vault'а без гранта. Гранты только расширяют */
6055
+ memberDefaultView: AmlView
6056
+ providers: VaultAmlProvider[]
6057
+ defaultProvider: "scorechain"
6058
+ }
6059
+
6060
+ /** Объём проверки: summary — уровень, балл, категории; links — плюс связи; full — плюс родной блок провайдера и полный ответ из архива */
6061
+ export type AmlView = "summary" | "links" | "full"
6062
+
6063
+ export interface VaultAmlProvider {
6064
+ provider: "scorechain"
6065
+ displayName: string
6066
+ enabled: boolean
6067
+ /** Его проверка пишется в amlLevel операции. Ровно один включённый */
6068
+ isDefault: boolean
6069
+ /**
6070
+ * Свежесть сохранённой проверки; 0 — всегда новый вызов провайдера (каждый платный)
6071
+ *
6072
+ * range: -9007199254740991..9007199254740991
6073
+ */
6074
+ maxAgeSeconds: number
6075
+ }
6076
+
6077
+ export interface AmlVisibilityGrant {
6078
+ id: string
6079
+ vaultId: string
6080
+ subjectType: "user" | "group"
6081
+ subjectUserId: string | null
6082
+ /** PolicyGroup — все её члены, по ТЕКУЩЕМУ членству */
6083
+ subjectGroupId: string | null
6084
+ role: "links" | "full"
6085
+ canViewLinks: boolean
6086
+ canViewNative: boolean
6087
+ canViewRaw: boolean
6088
+ grantorId: string
6089
+ status: "active" | "revoked"
6090
+ revokedAt: string | null
6091
+ revokedById: string | null
6092
+ /** format: date-time */
6093
+ createdAt: string
6094
+ /** format: date-time */
6095
+ updatedAt: string
6096
+ }
6097
+
6098
+ export interface AmlVisibilityGrants {
6099
+ items: AmlVisibilityGrant[]
6100
+ }
6101
+
6102
+ export interface CreateAmlVisibilityGrantBody {
6103
+ subjectType: "user" | "group"
6104
+ /** length: 1..∞ */
6105
+ subjectUserId?: string
6106
+ /** length: 1..∞ */
6107
+ subjectGroupId?: string
6108
+ role: "links" | "full"
6109
+ }
6110
+
6111
+ export interface UpdateAmlSettingsBody {
6112
+ memberDefaultView?: AmlView
6113
+ providers?: Array<{
6114
+ /** length: 1..∞ */
6115
+ provider: string
6116
+ enabled?: boolean
6117
+ isDefault?: boolean
6118
+ /** range: -9007199254740991..9007199254740991 */
6119
+ maxAgeSeconds?: number
6120
+ }>
6121
+ }
@@ -1,14 +1,27 @@
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
+ AmlCheck,
5
+ AmlOfficers,
6
+ AmlRecheckBody,
7
+ AmlSettings,
8
+ AmlVisibilityGrant,
9
+ AmlVisibilityGrants,
10
+ ApprovalRequestCreated,
11
+ CreateAmlVisibilityGrantBody,
12
+ UpdateAmlSettingsBody,
13
+ } from '../generated/types.js'
3
14
 
4
15
  /**
5
16
  * AML checks of a vault, in the typed model (AML v2).
6
17
  *
7
18
  * 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.
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.
12
25
  *
13
26
  * `level` is what to branch on. `null` means NOT CHECKED, never "clean" —
14
27
  * draw it as a third, neutral state. `share` and `amountUsd` are `null` for
@@ -53,10 +66,10 @@ export class AmlResource {
53
66
  }
54
67
 
55
68
  /**
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.
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).
60
73
  */
61
74
  getCheck(id: string): Promise<AmlCheck> {
62
75
  return this.#http.request<AmlCheck>('GET', `${this.#base}/checks/${seg(id)}`)
@@ -66,11 +79,91 @@ export class AmlResource {
66
79
  * The provider's response byte for byte, for audit (hundreds of kilobytes
67
80
  * for an active address). Returns the untouched `Response`. 404
68
81
  * `AML_RAW_NOT_FOUND` — not archived for this record; 501
69
- * `AML_ARCHIVE_DISABLED` — no archive on the server. Admins only.
82
+ * `AML_ARCHIVE_DISABLED` — no archive on the server. Only with `full`
83
+ * (admins, officers, a `full` visibility grant) — 403 otherwise.
70
84
  */
71
85
  rawCheck(id: string, options: { signal?: AbortSignal | undefined } = {}): Promise<Response> {
72
86
  return this.#http.fetchRaw('GET', `${this.#base}/checks/${seg(id)}/raw`, {
73
87
  signal: options.signal,
74
88
  })
75
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
+
76
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
  }
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.7.0'
3
3
 
4
4
  /** Default API base URL. */
5
5
  export const DEFAULT_BASE_URL = 'https://policy-engine-rest.ezig.workers.dev'