@artu-ai/compliance-sdk 0.4.0 → 0.4.2
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.
- package/package.json +4 -5
- package/src/errors/api.ts +0 -305
- package/src/errors/base.ts +0 -127
- package/src/errors/index.ts +0 -63
- package/src/errors/upload.ts +0 -204
- package/src/errors/validation.ts +0 -163
- package/src/exports/base.ts +0 -139
- package/src/exports/index.ts +0 -187
- package/src/exports/mexico/actividad-vulnerable/avi.ts +0 -207
- package/src/exports/mexico/actividad-vulnerable/jys.ts +0 -214
- package/src/exports/mexico/actividad-vulnerable/tsc.ts +0 -202
- package/src/exports/mexico/index.ts +0 -215
- package/src/models/Address.ts +0 -235
- package/src/models/BankAccount.ts +0 -235
- package/src/models/Client.ts +0 -363
- package/src/models/ContactMethod.ts +0 -197
- package/src/models/Document.ts +0 -355
- package/src/models/LinkedClient.ts +0 -84
- package/src/models/Report.ts +0 -193
- package/src/models/ReportItem.ts +0 -211
- package/src/models/Transaction.ts +0 -219
- package/src/models/base.ts +0 -56
- package/src/models/index.ts +0 -148
- package/src/models/mex/MexAddress.ts +0 -184
- package/src/models/mex/MexBankAccount.ts +0 -121
- package/src/models/mex/MexClient.ts +0 -177
- package/src/models/mex/MexDocument.ts +0 -890
- package/src/models/mex/MexReport.ts +0 -99
- package/src/models/mex/MexReportItem.ts +0 -79
- package/src/models/mex/MexTransaction.ts +0 -105
- package/src/models/mex/actividad-vulnerable/MexActividadVulnerableClient.ts +0 -66
- package/src/models/mex/actividad-vulnerable/MexActividadVulnerableReport.ts +0 -73
- package/src/models/mex/actividad-vulnerable/MexActividadVulnerableReportItem.ts +0 -74
- package/src/models/mex/actividad-vulnerable/MexActividadVulnerableTransaction.ts +0 -50
- package/src/models/mex/actividad-vulnerable/avi/MexAVIClient.ts +0 -80
- package/src/models/mex/actividad-vulnerable/avi/MexAVIReport.ts +0 -114
- package/src/models/mex/actividad-vulnerable/avi/MexAVIReportItem.ts +0 -105
- package/src/models/mex/actividad-vulnerable/avi/MexAVITransaction.ts +0 -157
- package/src/models/mex/actividad-vulnerable/index.ts +0 -78
- package/src/models/mex/actividad-vulnerable/jys/MexJYSClient.ts +0 -73
- package/src/models/mex/actividad-vulnerable/jys/MexJYSReport.ts +0 -114
- package/src/models/mex/actividad-vulnerable/jys/MexJYSReportItem.ts +0 -105
- package/src/models/mex/actividad-vulnerable/jys/MexJYSTransaction.ts +0 -178
- package/src/models/mex/actividad-vulnerable/tsc/MexTSCClient.ts +0 -73
- package/src/models/mex/actividad-vulnerable/tsc/MexTSCReport.ts +0 -114
- package/src/models/mex/actividad-vulnerable/tsc/MexTSCReportItem.ts +0 -105
- package/src/models/mex/actividad-vulnerable/tsc/MexTSCTransaction.ts +0 -104
- package/src/models/mex/index.ts +0 -57
- package/src/models/types.ts +0 -196
- package/src/namespaces/index.ts +0 -29
- package/src/namespaces/mexico/actividad-vulnerable/avi/index.ts +0 -62
- package/src/namespaces/mexico/actividad-vulnerable/index.ts +0 -79
- package/src/namespaces/mexico/actividad-vulnerable/jys/index.ts +0 -72
- package/src/namespaces/mexico/actividad-vulnerable/tsc/index.ts +0 -60
- package/src/namespaces/mexico/index.ts +0 -325
- package/src/resources/addresses.ts +0 -391
- package/src/resources/bank-accounts.ts +0 -417
- package/src/resources/base.ts +0 -327
- package/src/resources/clients.ts +0 -808
- package/src/resources/contact-methods.ts +0 -412
- package/src/resources/documents.ts +0 -688
- package/src/resources/index.ts +0 -40
- package/src/resources/mex/actividad-vulnerable/avi/clients.ts +0 -559
- package/src/resources/mex/actividad-vulnerable/avi/index.ts +0 -7
- package/src/resources/mex/actividad-vulnerable/avi/reports.ts +0 -609
- package/src/resources/mex/actividad-vulnerable/avi/transactions.ts +0 -404
- package/src/resources/mex/actividad-vulnerable/index.ts +0 -12
- package/src/resources/mex/actividad-vulnerable/jys/clients.ts +0 -445
- package/src/resources/mex/actividad-vulnerable/jys/index.ts +0 -7
- package/src/resources/mex/actividad-vulnerable/jys/reports.ts +0 -591
- package/src/resources/mex/actividad-vulnerable/jys/transactions.ts +0 -395
- package/src/resources/mex/actividad-vulnerable/tsc/clients.ts +0 -445
- package/src/resources/mex/actividad-vulnerable/tsc/index.ts +0 -7
- package/src/resources/mex/actividad-vulnerable/tsc/reports.ts +0 -591
- package/src/resources/mex/actividad-vulnerable/tsc/transactions.ts +0 -404
- package/src/resources/mex/addresses.ts +0 -493
- package/src/resources/mex/bank-accounts.ts +0 -283
- package/src/resources/mex/clients.ts +0 -758
- package/src/resources/mex/ebr.ts +0 -621
- package/src/resources/mex/index.ts +0 -23
- package/src/resources/mex/reports.ts +0 -643
- package/src/resources/mex/transactions.ts +0 -422
- package/src/resources/reports.ts +0 -515
- package/src/resources/transactions.ts +0 -358
- package/src/sdk/ComplianceSDK.ts +0 -812
- package/src/sdk/base.ts +0 -43
- package/src/sdk/index.ts +0 -98
- package/src/sdk/mex/ComplianceSDK.ts +0 -147
- package/src/sdk/mex/actividad-vulnerable/avi/ComplianceSDK.ts +0 -55
- package/src/sdk/mex/actividad-vulnerable/avi/index.ts +0 -16
- package/src/sdk/mex/actividad-vulnerable/avi/types.ts +0 -86
- package/src/sdk/mex/actividad-vulnerable/index.ts +0 -58
- package/src/sdk/mex/actividad-vulnerable/jys/ComplianceSDK.ts +0 -54
- package/src/sdk/mex/actividad-vulnerable/jys/index.ts +0 -16
- package/src/sdk/mex/actividad-vulnerable/jys/types.ts +0 -86
- package/src/sdk/mex/actividad-vulnerable/tsc/ComplianceSDK.ts +0 -54
- package/src/sdk/mex/actividad-vulnerable/tsc/index.ts +0 -16
- package/src/sdk/mex/actividad-vulnerable/tsc/types.ts +0 -86
- package/src/sdk/mex/index.ts +0 -66
- package/src/sdk/mex/types.ts +0 -88
- package/src/sdk/resource-registry.ts +0 -204
- package/src/sdk/sdk-registry.ts +0 -99
- package/src/sdk/types.ts +0 -304
- package/src/utils/environment.ts +0 -187
- package/src/utils/filters.ts +0 -412
- package/src/utils/index.ts +0 -134
- package/src/utils/pagination.ts +0 -143
- package/src/utils/session.ts +0 -303
- package/src/utils/trpc-client.ts +0 -242
- package/src/utils/upload.ts +0 -388
package/src/resources/index.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Resource Managers
|
|
3
|
-
*
|
|
4
|
-
* This module exports resource classes for interacting with
|
|
5
|
-
* the compliance API. Each resource handles CRUD operations,
|
|
6
|
-
* pagination, and error mapping for a specific entity type.
|
|
7
|
-
*
|
|
8
|
-
* Resource Hierarchy:
|
|
9
|
-
* - Base resources: Unscoped, accept full nested input
|
|
10
|
-
* - Mex resources: Mexico-scoped, accept flattened MX input
|
|
11
|
-
* - Activity resources: Activity-scoped, accept fully flattened input
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
// Base classes
|
|
15
|
-
export { BaseResource, ReadOnlyResource, type ResourceConfig } from "./base";
|
|
16
|
-
|
|
17
|
-
// Base resource implementations (unscoped)
|
|
18
|
-
export { ClientsResource, type BatchOptions } from "./clients";
|
|
19
|
-
export { TransactionsResource } from "./transactions";
|
|
20
|
-
export type { RelatedClient, LinkedClient } from "@artu-ai/shared";
|
|
21
|
-
export {
|
|
22
|
-
ReportsResource,
|
|
23
|
-
type ReportFilter,
|
|
24
|
-
type ReportItemFilter,
|
|
25
|
-
type AddItemsResult,
|
|
26
|
-
} from "./reports";
|
|
27
|
-
|
|
28
|
-
// Supporting resources
|
|
29
|
-
export { AddressesResource } from "./addresses";
|
|
30
|
-
export { ContactMethodsResource } from "./contact-methods";
|
|
31
|
-
export { BankAccountsResource } from "./bank-accounts";
|
|
32
|
-
export {
|
|
33
|
-
DocumentsResource,
|
|
34
|
-
type CreateDocumentResult,
|
|
35
|
-
type UploadDocumentInput,
|
|
36
|
-
type UploadOptions,
|
|
37
|
-
} from "./documents";
|
|
38
|
-
|
|
39
|
-
// Mexico-scoped resources
|
|
40
|
-
export * from "./mex";
|
|
@@ -1,559 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* AVI (Activos Virtuales) Clients Resource
|
|
3
|
-
*
|
|
4
|
-
* Extends MexClientsResource with AVI-specific behavior:
|
|
5
|
-
* - Accepts flattened CreateAVIClientInput (AVI fields at root level)
|
|
6
|
-
* - Returns MexAVIClient models
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import { z } from "zod";
|
|
10
|
-
import type {
|
|
11
|
-
CreateClientInput,
|
|
12
|
-
UpdateClientInput,
|
|
13
|
-
ClientFilter,
|
|
14
|
-
ClientSort,
|
|
15
|
-
ListOptions,
|
|
16
|
-
PaginatedResponse,
|
|
17
|
-
CreateAVIClientInput,
|
|
18
|
-
UpdateAVIClientInput,
|
|
19
|
-
CreateMexClientInput,
|
|
20
|
-
UpdateMexClientInput,
|
|
21
|
-
AtomicBatchResult,
|
|
22
|
-
PartialBatchResult,
|
|
23
|
-
ClientRelationshipType,
|
|
24
|
-
LinkedClient as LinkedClientInput,
|
|
25
|
-
CreateMexAddressInput,
|
|
26
|
-
UpdateMexAddressInput,
|
|
27
|
-
CreateContactMethodInput,
|
|
28
|
-
UpdateContactMethodInput,
|
|
29
|
-
CreateBankAccountInput,
|
|
30
|
-
UpdateBankAccountInput,
|
|
31
|
-
SyncItem,
|
|
32
|
-
SyncResult,
|
|
33
|
-
MexClientFilter,
|
|
34
|
-
AVIClientFilter,
|
|
35
|
-
AVIClientSort,
|
|
36
|
-
} from "@artu-ai/shared";
|
|
37
|
-
import {
|
|
38
|
-
CodigoActividad,
|
|
39
|
-
createAVIClientInputSchema,
|
|
40
|
-
updateAVIClientInputSchema,
|
|
41
|
-
linkedClientSchema,
|
|
42
|
-
transformSort,
|
|
43
|
-
aviClientFieldMapping,
|
|
44
|
-
} from "@artu-ai/shared";
|
|
45
|
-
import { MexClientsResource } from "../../clients";
|
|
46
|
-
import { type BatchOptions, type ClientIncludeMap } from "../../../clients";
|
|
47
|
-
import {
|
|
48
|
-
MexAVIClient,
|
|
49
|
-
MexAddress,
|
|
50
|
-
MexBankAccount,
|
|
51
|
-
ContactMethod,
|
|
52
|
-
LinkedClient,
|
|
53
|
-
type ClientData,
|
|
54
|
-
} from "../../../../models";
|
|
55
|
-
|
|
56
|
-
// ===========================
|
|
57
|
-
// AVIClientsResource
|
|
58
|
-
// ===========================
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* AVI (Activos Virtuales) scoped clients resource.
|
|
62
|
-
*
|
|
63
|
-
* Provides the same operations as MexClientsResource but with:
|
|
64
|
-
* - Flattened input types (AVI fields at root level)
|
|
65
|
-
* - MexAVIClient model return type
|
|
66
|
-
*
|
|
67
|
-
* @example
|
|
68
|
-
* ```typescript
|
|
69
|
-
* const aviSdk = new ComplianceSDK({
|
|
70
|
-
* apiKey,
|
|
71
|
-
* environment: "test",
|
|
72
|
-
* jurisdiction: Jurisdiction.Mexico,
|
|
73
|
-
* actividadVulnerable: CodigoActividad.AVI,
|
|
74
|
-
* });
|
|
75
|
-
*
|
|
76
|
-
* // Create with fully flattened input
|
|
77
|
-
* const client = await aviSdk.clients.create({
|
|
78
|
-
* type: ClientType.Person,
|
|
79
|
-
* name: "Juan García",
|
|
80
|
-
* rfc: "GAJL850101ABC", // MX field
|
|
81
|
-
* username: "JGARCIA", // AVI field at root!
|
|
82
|
-
* });
|
|
83
|
-
*
|
|
84
|
-
* // Returns MexAVIClient
|
|
85
|
-
* console.log(client.username);
|
|
86
|
-
* ```
|
|
87
|
-
*/
|
|
88
|
-
export class AVIClientsResource extends MexClientsResource<AVIClientSort> {
|
|
89
|
-
// ─────────────────────────────────────────────────────────────────
|
|
90
|
-
// CRUD Operations
|
|
91
|
-
// ─────────────────────────────────────────────────────────────────
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Creates a new AVI client with fully flattened input.
|
|
95
|
-
*/
|
|
96
|
-
async create(data: CreateAVIClientInput): Promise<MexAVIClient> {
|
|
97
|
-
const validated = this.validate(createAVIClientInputSchema, data);
|
|
98
|
-
const nestedData = this.transformToNested(validated);
|
|
99
|
-
|
|
100
|
-
const response = await this.execute(() =>
|
|
101
|
-
this.trpc.clients.create.mutate(nestedData)
|
|
102
|
-
);
|
|
103
|
-
|
|
104
|
-
return this.instantiate(response);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Retrieves a client by ID.
|
|
109
|
-
*/
|
|
110
|
-
async retrieve(
|
|
111
|
-
id: string,
|
|
112
|
-
include?: ClientIncludeMap
|
|
113
|
-
): Promise<MexAVIClient> {
|
|
114
|
-
const response = await this.execute(() =>
|
|
115
|
-
this.trpc.clients.retrieve.query({ id, include })
|
|
116
|
-
);
|
|
117
|
-
return this.instantiate(response);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Retrieves an AVI client by externalId.
|
|
122
|
-
*/
|
|
123
|
-
async retrieveByExternalId(externalId: string): Promise<MexAVIClient> {
|
|
124
|
-
const response = await this.execute(() =>
|
|
125
|
-
this.trpc.clients.retrieveByExternalId.query({ externalId })
|
|
126
|
-
);
|
|
127
|
-
return this.instantiate(response);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Updates an AVI client with flattened input.
|
|
132
|
-
*/
|
|
133
|
-
async update(id: string, data: UpdateAVIClientInput): Promise<MexAVIClient> {
|
|
134
|
-
const validated = this.validate(updateAVIClientInputSchema, data);
|
|
135
|
-
const nestedData = this.transformUpdateToNested(validated);
|
|
136
|
-
|
|
137
|
-
const response = await this.execute(() =>
|
|
138
|
-
this.trpc.clients.update.mutate({ id, data: nestedData })
|
|
139
|
-
);
|
|
140
|
-
return this.instantiate(response);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// ─────────────────────────────────────────────────────────────────
|
|
144
|
-
// List & Pagination
|
|
145
|
-
// ─────────────────────────────────────────────────────────────────
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* Lists AVI clients with optional filtering.
|
|
149
|
-
*
|
|
150
|
-
* Accepts fully flattened AVI filter (MX and AVI fields at root level)
|
|
151
|
-
* and automatically transforms to nested format before calling the API.
|
|
152
|
-
*
|
|
153
|
-
* @example
|
|
154
|
-
* ```typescript
|
|
155
|
-
* const { data } = await aviSdk.clients.list({
|
|
156
|
-
* filter: {
|
|
157
|
-
* name: { contains: "García" },
|
|
158
|
-
* rfc: { startsWith: "GAJL" }, // MX field at root
|
|
159
|
-
* username: { contains: "jgarcia" }, // AVI field at root!
|
|
160
|
-
* },
|
|
161
|
-
* });
|
|
162
|
-
* ```
|
|
163
|
-
*/
|
|
164
|
-
async list(
|
|
165
|
-
options?: ListOptions<AVIClientFilter, AVIClientSort>
|
|
166
|
-
): Promise<PaginatedResponse<MexAVIClient>> {
|
|
167
|
-
const scopedFilter = this.applyScopeToFilter(options?.filter);
|
|
168
|
-
const scopedSort = this.applyScopeToSort(options?.sort);
|
|
169
|
-
|
|
170
|
-
const response = await this.execute(() =>
|
|
171
|
-
this.trpc.clients.list.query({
|
|
172
|
-
...options,
|
|
173
|
-
filter: scopedFilter,
|
|
174
|
-
sort: scopedSort,
|
|
175
|
-
})
|
|
176
|
-
);
|
|
177
|
-
|
|
178
|
-
return {
|
|
179
|
-
data: response.data.map((c) => this.instantiate(c)),
|
|
180
|
-
pagination: response.pagination,
|
|
181
|
-
};
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* Iterates over AVI clients.
|
|
186
|
-
*
|
|
187
|
-
* Accepts fully flattened AVI filter (MX and AVI fields at root level)
|
|
188
|
-
* and automatically transforms to nested format before calling the API.
|
|
189
|
-
*/
|
|
190
|
-
iterate(
|
|
191
|
-
filter?: AVIClientFilter
|
|
192
|
-
): AsyncGenerator<MexAVIClient, void, undefined> {
|
|
193
|
-
const scopedFilter = this.applyScopeToFilter(filter);
|
|
194
|
-
return this.createIterator<MexAVIClient>({ filter: scopedFilter });
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
// ─────────────────────────────────────────────────────────────────
|
|
198
|
-
// Batch Operations
|
|
199
|
-
// ─────────────────────────────────────────────────────────────────
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* Creates multiple AVI clients with flattened input.
|
|
203
|
-
*/
|
|
204
|
-
async createMany(
|
|
205
|
-
clients: CreateAVIClientInput[],
|
|
206
|
-
options?: { atomic?: true }
|
|
207
|
-
): Promise<AtomicBatchResult<MexAVIClient>>;
|
|
208
|
-
async createMany(
|
|
209
|
-
clients: CreateAVIClientInput[],
|
|
210
|
-
options: { atomic: false }
|
|
211
|
-
): Promise<PartialBatchResult<MexAVIClient>>;
|
|
212
|
-
async createMany(
|
|
213
|
-
clients: CreateAVIClientInput[],
|
|
214
|
-
options: BatchOptions = {}
|
|
215
|
-
): Promise<
|
|
216
|
-
AtomicBatchResult<MexAVIClient> | PartialBatchResult<MexAVIClient>
|
|
217
|
-
> {
|
|
218
|
-
const atomic = options.atomic ?? true;
|
|
219
|
-
const validated = this.validate(
|
|
220
|
-
z.array(createAVIClientInputSchema),
|
|
221
|
-
clients
|
|
222
|
-
);
|
|
223
|
-
const nestedClients = validated.map((c) => this.transformToNested(c));
|
|
224
|
-
|
|
225
|
-
const response = await this.execute(() =>
|
|
226
|
-
this.trpc.clients.createMany.mutate({ items: nestedClients, atomic })
|
|
227
|
-
);
|
|
228
|
-
|
|
229
|
-
if (response.atomic) {
|
|
230
|
-
return {
|
|
231
|
-
atomic: true,
|
|
232
|
-
data: response.data.map((c) => this.instantiate(c)),
|
|
233
|
-
};
|
|
234
|
-
} else {
|
|
235
|
-
return {
|
|
236
|
-
atomic: false,
|
|
237
|
-
succeeded: response.succeeded.map((item) => ({
|
|
238
|
-
index: item.index,
|
|
239
|
-
data: this.instantiate(item.data),
|
|
240
|
-
})),
|
|
241
|
-
failed: response.failed,
|
|
242
|
-
};
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
/**
|
|
247
|
-
* Updates multiple AVI clients.
|
|
248
|
-
*/
|
|
249
|
-
async updateMany(
|
|
250
|
-
updates: { id: string; data: UpdateAVIClientInput }[],
|
|
251
|
-
options?: { atomic?: true }
|
|
252
|
-
): Promise<AtomicBatchResult<MexAVIClient>>;
|
|
253
|
-
async updateMany(
|
|
254
|
-
updates: { id: string; data: UpdateAVIClientInput }[],
|
|
255
|
-
options: { atomic: false }
|
|
256
|
-
): Promise<PartialBatchResult<MexAVIClient>>;
|
|
257
|
-
async updateMany(
|
|
258
|
-
updates: { id: string; data: UpdateAVIClientInput }[],
|
|
259
|
-
options: BatchOptions = {}
|
|
260
|
-
): Promise<
|
|
261
|
-
AtomicBatchResult<MexAVIClient> | PartialBatchResult<MexAVIClient>
|
|
262
|
-
> {
|
|
263
|
-
const atomic = options.atomic ?? true;
|
|
264
|
-
const updateItemSchema = z.object({
|
|
265
|
-
id: z.uuid(),
|
|
266
|
-
data: updateAVIClientInputSchema,
|
|
267
|
-
});
|
|
268
|
-
|
|
269
|
-
const validated = this.validate(z.array(updateItemSchema), updates);
|
|
270
|
-
const nestedUpdates = validated.map((u) => ({
|
|
271
|
-
id: u.id,
|
|
272
|
-
data: this.transformUpdateToNested(u.data),
|
|
273
|
-
}));
|
|
274
|
-
|
|
275
|
-
const response = await this.execute(() =>
|
|
276
|
-
this.trpc.clients.updateMany.mutate({ items: nestedUpdates, atomic })
|
|
277
|
-
);
|
|
278
|
-
|
|
279
|
-
if (response.atomic) {
|
|
280
|
-
return {
|
|
281
|
-
atomic: true,
|
|
282
|
-
data: response.data.map((c) => this.instantiate(c)),
|
|
283
|
-
};
|
|
284
|
-
} else {
|
|
285
|
-
return {
|
|
286
|
-
atomic: false,
|
|
287
|
-
succeeded: response.succeeded.map((item) => ({
|
|
288
|
-
index: item.index,
|
|
289
|
-
data: this.instantiate(item.data),
|
|
290
|
-
})),
|
|
291
|
-
failed: response.failed,
|
|
292
|
-
};
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
// ─────────────────────────────────────────────────────────────────
|
|
297
|
-
// Client-to-Client Relationship Management (scoped returns)
|
|
298
|
-
// ─────────────────────────────────────────────────────────────────
|
|
299
|
-
|
|
300
|
-
async linkClient(
|
|
301
|
-
parentClientId: string,
|
|
302
|
-
childClientId: string,
|
|
303
|
-
relationshipType: ClientRelationshipType,
|
|
304
|
-
metadata?: Record<string, unknown>
|
|
305
|
-
): Promise<MexAVIClient> {
|
|
306
|
-
const response = await this.execute(() =>
|
|
307
|
-
this.trpc.clients.linkClient.mutate({
|
|
308
|
-
parentClientId,
|
|
309
|
-
childClientId,
|
|
310
|
-
relationshipType,
|
|
311
|
-
metadata,
|
|
312
|
-
})
|
|
313
|
-
);
|
|
314
|
-
return this.instantiate(response);
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
async unlinkClient(
|
|
318
|
-
parentClientId: string,
|
|
319
|
-
childClientId: string,
|
|
320
|
-
relationshipType: ClientRelationshipType
|
|
321
|
-
): Promise<MexAVIClient> {
|
|
322
|
-
const response = await this.execute(() =>
|
|
323
|
-
this.trpc.clients.unlinkClient.mutate({
|
|
324
|
-
parentClientId,
|
|
325
|
-
childClientId,
|
|
326
|
-
relationshipType,
|
|
327
|
-
})
|
|
328
|
-
);
|
|
329
|
-
return this.instantiate(response);
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
async listLinkedClients(
|
|
333
|
-
parentClientId: string,
|
|
334
|
-
relationshipType?: ClientRelationshipType
|
|
335
|
-
): Promise<LinkedClient[]> {
|
|
336
|
-
return super.listLinkedClients(parentClientId, relationshipType);
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
async setLinkedClients(
|
|
340
|
-
parentClientId: string,
|
|
341
|
-
linkedClients: LinkedClientInput[]
|
|
342
|
-
): Promise<MexAVIClient> {
|
|
343
|
-
const validated = this.validate(z.array(linkedClientSchema), linkedClients);
|
|
344
|
-
|
|
345
|
-
const response = await this.execute(() =>
|
|
346
|
-
this.trpc.clients.setLinkedClients.mutate({
|
|
347
|
-
parentClientId,
|
|
348
|
-
linkedClients: validated,
|
|
349
|
-
})
|
|
350
|
-
);
|
|
351
|
-
return this.instantiate(response);
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
// ─────────────────────────────────────────────────────────────────
|
|
355
|
-
// Sync All (Atomic)
|
|
356
|
-
// ─────────────────────────────────────────────────────────────────
|
|
357
|
-
|
|
358
|
-
async syncAll(
|
|
359
|
-
clientId: string,
|
|
360
|
-
data: {
|
|
361
|
-
client?: UpdateAVIClientInput;
|
|
362
|
-
addresses?: SyncItem<CreateMexAddressInput>[];
|
|
363
|
-
contactMethods?: SyncItem<CreateContactMethodInput>[];
|
|
364
|
-
bankAccounts?: SyncItem<CreateBankAccountInput>[];
|
|
365
|
-
linkedClients?: LinkedClientInput[];
|
|
366
|
-
},
|
|
367
|
-
options: { replaceMode: true }
|
|
368
|
-
): Promise<{
|
|
369
|
-
client: MexAVIClient;
|
|
370
|
-
addresses: SyncResult<MexAddress>;
|
|
371
|
-
contactMethods: SyncResult<ContactMethod>;
|
|
372
|
-
bankAccounts: SyncResult<MexBankAccount>;
|
|
373
|
-
}>;
|
|
374
|
-
async syncAll(
|
|
375
|
-
clientId: string,
|
|
376
|
-
data: {
|
|
377
|
-
client?: UpdateAVIClientInput;
|
|
378
|
-
addresses?: SyncItem<UpdateMexAddressInput>[];
|
|
379
|
-
contactMethods?: SyncItem<UpdateContactMethodInput>[];
|
|
380
|
-
bankAccounts?: SyncItem<UpdateBankAccountInput>[];
|
|
381
|
-
linkedClients?: LinkedClientInput[];
|
|
382
|
-
},
|
|
383
|
-
options?: { replaceMode?: boolean }
|
|
384
|
-
): Promise<{
|
|
385
|
-
client: MexAVIClient;
|
|
386
|
-
addresses: SyncResult<MexAddress>;
|
|
387
|
-
contactMethods: SyncResult<ContactMethod>;
|
|
388
|
-
bankAccounts: SyncResult<MexBankAccount>;
|
|
389
|
-
}>;
|
|
390
|
-
async syncAll(
|
|
391
|
-
clientId: string,
|
|
392
|
-
data: {
|
|
393
|
-
client?: UpdateAVIClientInput;
|
|
394
|
-
addresses?: SyncItem<UpdateMexAddressInput | CreateMexAddressInput>[];
|
|
395
|
-
contactMethods?: SyncItem<
|
|
396
|
-
UpdateContactMethodInput | CreateContactMethodInput
|
|
397
|
-
>[];
|
|
398
|
-
bankAccounts?: SyncItem<
|
|
399
|
-
UpdateBankAccountInput | CreateBankAccountInput
|
|
400
|
-
>[];
|
|
401
|
-
linkedClients?: LinkedClientInput[];
|
|
402
|
-
},
|
|
403
|
-
options?: { replaceMode?: boolean }
|
|
404
|
-
): Promise<{
|
|
405
|
-
client: MexAVIClient;
|
|
406
|
-
addresses: SyncResult<MexAddress>;
|
|
407
|
-
contactMethods: SyncResult<ContactMethod>;
|
|
408
|
-
bankAccounts: SyncResult<MexBankAccount>;
|
|
409
|
-
}> {
|
|
410
|
-
// Transform client input using AVI-specific transform
|
|
411
|
-
const transformedClient = data.client
|
|
412
|
-
? this.transformUpdateToNested(data.client)
|
|
413
|
-
: undefined;
|
|
414
|
-
|
|
415
|
-
// Call parent syncAll with transformed client data
|
|
416
|
-
const result = await super.syncAll(
|
|
417
|
-
clientId,
|
|
418
|
-
{
|
|
419
|
-
...data,
|
|
420
|
-
client: transformedClient as UpdateMexClientInput,
|
|
421
|
-
},
|
|
422
|
-
options as { replaceMode?: boolean }
|
|
423
|
-
);
|
|
424
|
-
|
|
425
|
-
// Re-instantiate client with AVI-specific model
|
|
426
|
-
return {
|
|
427
|
-
...result,
|
|
428
|
-
client: this.instantiate(result.client as unknown as ClientData),
|
|
429
|
-
};
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
// ─────────────────────────────────────────────────────────────────
|
|
433
|
-
// Protected Helpers
|
|
434
|
-
// ─────────────────────────────────────────────────────────────────
|
|
435
|
-
|
|
436
|
-
/**
|
|
437
|
-
* Transforms a flattened AVIClientFilter to nested ClientFilter format
|
|
438
|
-
* and applies Mexico jurisdiction scoping.
|
|
439
|
-
*
|
|
440
|
-
* Extracts AVI-specific fields (username) from root level and nests them
|
|
441
|
-
* under jurisdictions.MX.actividadVulnerable.AVI.
|
|
442
|
-
*/
|
|
443
|
-
protected override applyScopeToFilter(
|
|
444
|
-
filter?: AVIClientFilter
|
|
445
|
-
): ClientFilter {
|
|
446
|
-
if (!filter) {
|
|
447
|
-
return super.applyScopeToFilter(undefined);
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
// Extract AVI-specific filter fields
|
|
451
|
-
const { username, ...mexFilter } = filter;
|
|
452
|
-
|
|
453
|
-
// Let parent handle MX fields
|
|
454
|
-
const nestedFilter = super.applyScopeToFilter(mexFilter as MexClientFilter);
|
|
455
|
-
|
|
456
|
-
// Only add AVI activity filter if username is provided
|
|
457
|
-
if (username !== undefined) {
|
|
458
|
-
const mexJurisdiction = (nestedFilter.jurisdictions?.MX ?? {}) as Record<
|
|
459
|
-
string,
|
|
460
|
-
unknown
|
|
461
|
-
>;
|
|
462
|
-
|
|
463
|
-
return {
|
|
464
|
-
...nestedFilter,
|
|
465
|
-
jurisdictions: {
|
|
466
|
-
...nestedFilter.jurisdictions,
|
|
467
|
-
MX: {
|
|
468
|
-
...mexJurisdiction,
|
|
469
|
-
actividadVulnerable: {
|
|
470
|
-
[CodigoActividad.AVI]: { username },
|
|
471
|
-
},
|
|
472
|
-
},
|
|
473
|
-
},
|
|
474
|
-
} as ClientFilter;
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
return nestedFilter;
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
/**
|
|
481
|
-
* Transforms a flattened AVIClientSort to nested ClientSort format.
|
|
482
|
-
*
|
|
483
|
-
* Maps flattened field names (username, rfc, curp) to their full API paths.
|
|
484
|
-
*/
|
|
485
|
-
protected override applyScopeToSort(sort?: AVIClientSort): ClientSort | undefined {
|
|
486
|
-
if (!sort || sort.length === 0) {
|
|
487
|
-
return undefined;
|
|
488
|
-
}
|
|
489
|
-
return transformSort(sort, aviClientFieldMapping);
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
/**
|
|
493
|
-
* Transforms flattened AVI input to nested API format.
|
|
494
|
-
*/
|
|
495
|
-
protected override transformToNested(
|
|
496
|
-
data: CreateAVIClientInput
|
|
497
|
-
): CreateClientInput {
|
|
498
|
-
// Extract AVI-specific field first
|
|
499
|
-
const { username, ...restData } = data as Record<string, unknown>;
|
|
500
|
-
|
|
501
|
-
// Use parent for base + MX fields
|
|
502
|
-
const nested = super.transformToNested(
|
|
503
|
-
restData as unknown as CreateMexClientInput
|
|
504
|
-
);
|
|
505
|
-
|
|
506
|
-
// Add AVI activity data (parent always provides jurisdictions.MX)
|
|
507
|
-
const mexData = nested.jurisdictions?.MX;
|
|
508
|
-
|
|
509
|
-
return {
|
|
510
|
-
...nested,
|
|
511
|
-
jurisdictions: {
|
|
512
|
-
MX: {
|
|
513
|
-
...mexData,
|
|
514
|
-
actividadVulnerable: {
|
|
515
|
-
[CodigoActividad.AVI]: { username },
|
|
516
|
-
},
|
|
517
|
-
},
|
|
518
|
-
},
|
|
519
|
-
} as CreateClientInput;
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
/**
|
|
523
|
-
* Transforms flattened AVI update input to nested API format.
|
|
524
|
-
*/
|
|
525
|
-
protected override transformUpdateToNested(
|
|
526
|
-
data: UpdateAVIClientInput
|
|
527
|
-
): UpdateClientInput {
|
|
528
|
-
// Extract AVI-specific field first
|
|
529
|
-
const { username, ...restData } = data as Record<string, unknown>;
|
|
530
|
-
|
|
531
|
-
// Use parent for base + MX fields
|
|
532
|
-
const nested = super.transformUpdateToNested(
|
|
533
|
-
restData as unknown as UpdateMexClientInput
|
|
534
|
-
);
|
|
535
|
-
|
|
536
|
-
// Only add AVI data if username is provided
|
|
537
|
-
if (username !== undefined) {
|
|
538
|
-
const mexData = ((nested.jurisdictions?.MX as Record<string, unknown>) ??
|
|
539
|
-
{}) as Record<string, unknown>;
|
|
540
|
-
mexData.actividadVulnerable = {
|
|
541
|
-
[CodigoActividad.AVI]: { username },
|
|
542
|
-
};
|
|
543
|
-
|
|
544
|
-
return {
|
|
545
|
-
...nested,
|
|
546
|
-
jurisdictions: { MX: mexData },
|
|
547
|
-
} as UpdateClientInput;
|
|
548
|
-
}
|
|
549
|
-
|
|
550
|
-
return nested;
|
|
551
|
-
}
|
|
552
|
-
|
|
553
|
-
/**
|
|
554
|
-
* Instantiates a MexAVIClient model.
|
|
555
|
-
*/
|
|
556
|
-
protected override instantiate(data: ClientData): MexAVIClient {
|
|
557
|
-
return new MexAVIClient(data);
|
|
558
|
-
}
|
|
559
|
-
}
|