@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
|
@@ -1,609 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* AVI (Activos Virtuales) Reports Resource
|
|
3
|
-
*
|
|
4
|
-
* Extends MexReportsResource with AVI-specific behavior:
|
|
5
|
-
* - Accepts flattened CreateAVIReportInput (AVI fields at root level)
|
|
6
|
-
* - Returns MexAVIReport models
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import { z } from "zod";
|
|
10
|
-
import type {
|
|
11
|
-
CreateReportInput,
|
|
12
|
-
UpdateReportInput,
|
|
13
|
-
CreateReportItemInput,
|
|
14
|
-
UpdateReportItemInput,
|
|
15
|
-
CreateAVIReportInput,
|
|
16
|
-
UpdateAVIReportInput,
|
|
17
|
-
CreateAVIReportItemInput,
|
|
18
|
-
UpdateAVIReportItemInput,
|
|
19
|
-
ListOptions,
|
|
20
|
-
PaginatedResponse,
|
|
21
|
-
AtomicBatchResult,
|
|
22
|
-
PartialBatchResult,
|
|
23
|
-
ValidationResult,
|
|
24
|
-
GenerateResult,
|
|
25
|
-
SubmissionResult,
|
|
26
|
-
AviReportDefaultsInput,
|
|
27
|
-
SubmitAVIReportInput,
|
|
28
|
-
} from "@artu-ai/shared";
|
|
29
|
-
import {
|
|
30
|
-
CodigoActividad,
|
|
31
|
-
createAVIReportInputSchema,
|
|
32
|
-
updateAVIReportInputSchema,
|
|
33
|
-
createAVIReportItemInputSchema,
|
|
34
|
-
updateAVIReportItemInputSchema,
|
|
35
|
-
aviDefaultsInputSchema,
|
|
36
|
-
submitAVIReportInputSchema,
|
|
37
|
-
transformSort,
|
|
38
|
-
aviReportFieldMapping,
|
|
39
|
-
} from "@artu-ai/shared";
|
|
40
|
-
import type {
|
|
41
|
-
AVIReportFilter,
|
|
42
|
-
AVIReportSort,
|
|
43
|
-
AVIReportItemFilter,
|
|
44
|
-
ReportSort,
|
|
45
|
-
ReportItemFilter,
|
|
46
|
-
ReportItemSort,
|
|
47
|
-
} from "@artu-ai/shared";
|
|
48
|
-
import { MexReportsResource } from "../../reports";
|
|
49
|
-
import { type BatchOptions } from "../../../clients";
|
|
50
|
-
import {
|
|
51
|
-
MexAVIReport,
|
|
52
|
-
MexAVIReportItem,
|
|
53
|
-
type ReportData,
|
|
54
|
-
type ReportItemData,
|
|
55
|
-
} from "../../../../models";
|
|
56
|
-
|
|
57
|
-
// ===========================
|
|
58
|
-
// AVIReportsResource
|
|
59
|
-
// ===========================
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* AVI (Activos Virtuales) scoped reports resource.
|
|
63
|
-
*
|
|
64
|
-
* @example
|
|
65
|
-
* ```typescript
|
|
66
|
-
* const aviSdk = new ComplianceSDK({
|
|
67
|
-
* apiKey,
|
|
68
|
-
* jurisdiction: Jurisdiction.Mexico,
|
|
69
|
-
* actividadVulnerable: CodigoActividad.AVI,
|
|
70
|
-
* });
|
|
71
|
-
*
|
|
72
|
-
* // Create with fully flattened input
|
|
73
|
-
* const report = await aviSdk.reports.create({
|
|
74
|
-
* mesReportado: "202401",
|
|
75
|
-
* });
|
|
76
|
-
*
|
|
77
|
-
* // Returns MexAVIReport
|
|
78
|
-
* console.log(report.mesReportado);
|
|
79
|
-
* ```
|
|
80
|
-
*/
|
|
81
|
-
export class AVIReportsResource extends MexReportsResource<AVIReportSort, AviReportDefaultsInput> {
|
|
82
|
-
// ─────────────────────────────────────────────────────────────────
|
|
83
|
-
// Report CRUD
|
|
84
|
-
// ─────────────────────────────────────────────────────────────────
|
|
85
|
-
|
|
86
|
-
async create(data: CreateAVIReportInput): Promise<MexAVIReport> {
|
|
87
|
-
const validated = this.validate(createAVIReportInputSchema, data);
|
|
88
|
-
const nestedData = this.transformToNested(validated);
|
|
89
|
-
|
|
90
|
-
const response = await this.execute(() =>
|
|
91
|
-
this.trpc.reports.create.mutate(nestedData)
|
|
92
|
-
);
|
|
93
|
-
|
|
94
|
-
return this.instantiate(response);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
async retrieve(id: string): Promise<MexAVIReport> {
|
|
98
|
-
const response = await this.execute(() =>
|
|
99
|
-
this.trpc.reports.retrieve.query({ id })
|
|
100
|
-
);
|
|
101
|
-
return this.instantiate(response);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
async retrieveByMetadata(key: string, value: string): Promise<MexAVIReport> {
|
|
105
|
-
const response = await this.execute(() =>
|
|
106
|
-
this.trpc.reports.retrieveByMetadata.query({ key, value })
|
|
107
|
-
);
|
|
108
|
-
return this.instantiate(response);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
async retrieveByExternalId(externalId: string): Promise<MexAVIReport> {
|
|
112
|
-
const response = await this.execute(() =>
|
|
113
|
-
this.trpc.reports.retrieveByExternalId.query({ externalId })
|
|
114
|
-
);
|
|
115
|
-
return this.instantiate(response);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
async update(id: string, data: UpdateAVIReportInput): Promise<MexAVIReport> {
|
|
119
|
-
const validated = this.validate(updateAVIReportInputSchema, data);
|
|
120
|
-
const nestedData = this.transformUpdateToNested(validated);
|
|
121
|
-
|
|
122
|
-
const response = await this.execute(() =>
|
|
123
|
-
this.trpc.reports.update.mutate({ id, data: nestedData })
|
|
124
|
-
);
|
|
125
|
-
return this.instantiate(response);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
// ─────────────────────────────────────────────────────────────────
|
|
129
|
-
// List & Pagination
|
|
130
|
-
// ─────────────────────────────────────────────────────────────────
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Lists AVI reports with optional filtering.
|
|
134
|
-
*
|
|
135
|
-
* Accepts flattened AVI filter (future AVI-specific report fields at root level).
|
|
136
|
-
*/
|
|
137
|
-
async list(
|
|
138
|
-
options?: ListOptions<AVIReportFilter, AVIReportSort>
|
|
139
|
-
): Promise<PaginatedResponse<MexAVIReport>> {
|
|
140
|
-
const scopedFilter = this.applyScopeToFilter(options?.filter);
|
|
141
|
-
const scopedSort = this.applyScopeToSort(options?.sort);
|
|
142
|
-
|
|
143
|
-
const response = await this.execute(() =>
|
|
144
|
-
this.trpc.reports.list.query({
|
|
145
|
-
...options,
|
|
146
|
-
filter: scopedFilter,
|
|
147
|
-
sort: scopedSort,
|
|
148
|
-
})
|
|
149
|
-
);
|
|
150
|
-
|
|
151
|
-
return {
|
|
152
|
-
data: response.data.map((r) => this.instantiate(r)),
|
|
153
|
-
pagination: response.pagination,
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Iterates over AVI reports.
|
|
159
|
-
*
|
|
160
|
-
* Accepts flattened AVI filter (future AVI-specific report fields at root level).
|
|
161
|
-
*/
|
|
162
|
-
iterate(
|
|
163
|
-
filter?: AVIReportFilter
|
|
164
|
-
): AsyncGenerator<MexAVIReport, void, undefined> {
|
|
165
|
-
const scopedFilter = this.applyScopeToFilter(filter);
|
|
166
|
-
return this.createIterator<MexAVIReport>({ filter: scopedFilter });
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
// ─────────────────────────────────────────────────────────────────
|
|
170
|
-
// Batch Operations
|
|
171
|
-
// ─────────────────────────────────────────────────────────────────
|
|
172
|
-
|
|
173
|
-
async createMany(
|
|
174
|
-
reports: CreateAVIReportInput[],
|
|
175
|
-
options?: { atomic?: true }
|
|
176
|
-
): Promise<AtomicBatchResult<MexAVIReport>>;
|
|
177
|
-
async createMany(
|
|
178
|
-
reports: CreateAVIReportInput[],
|
|
179
|
-
options: { atomic: false }
|
|
180
|
-
): Promise<PartialBatchResult<MexAVIReport>>;
|
|
181
|
-
async createMany(
|
|
182
|
-
reports: CreateAVIReportInput[],
|
|
183
|
-
options: BatchOptions = {}
|
|
184
|
-
): Promise<
|
|
185
|
-
AtomicBatchResult<MexAVIReport> | PartialBatchResult<MexAVIReport>
|
|
186
|
-
> {
|
|
187
|
-
const atomic = options.atomic ?? true;
|
|
188
|
-
const validated = this.validate(
|
|
189
|
-
z.array(createAVIReportInputSchema),
|
|
190
|
-
reports
|
|
191
|
-
);
|
|
192
|
-
const nestedItems = validated.map((r) => this.transformToNested(r));
|
|
193
|
-
|
|
194
|
-
const response = await this.execute(() =>
|
|
195
|
-
this.trpc.reports.createMany.mutate({ items: nestedItems, atomic })
|
|
196
|
-
);
|
|
197
|
-
|
|
198
|
-
if (response.atomic) {
|
|
199
|
-
return {
|
|
200
|
-
atomic: true,
|
|
201
|
-
data: response.data.map((r) => this.instantiate(r)),
|
|
202
|
-
};
|
|
203
|
-
} else {
|
|
204
|
-
return {
|
|
205
|
-
atomic: false,
|
|
206
|
-
succeeded: response.succeeded.map((item) => ({
|
|
207
|
-
index: item.index,
|
|
208
|
-
data: this.instantiate(item.data),
|
|
209
|
-
})),
|
|
210
|
-
failed: response.failed,
|
|
211
|
-
};
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
async updateMany(
|
|
216
|
-
updates: { id: string; data: UpdateAVIReportInput }[],
|
|
217
|
-
options?: { atomic?: true }
|
|
218
|
-
): Promise<AtomicBatchResult<MexAVIReport>>;
|
|
219
|
-
async updateMany(
|
|
220
|
-
updates: { id: string; data: UpdateAVIReportInput }[],
|
|
221
|
-
options: { atomic: false }
|
|
222
|
-
): Promise<PartialBatchResult<MexAVIReport>>;
|
|
223
|
-
async updateMany(
|
|
224
|
-
updates: { id: string; data: UpdateAVIReportInput }[],
|
|
225
|
-
options: BatchOptions = {}
|
|
226
|
-
): Promise<
|
|
227
|
-
AtomicBatchResult<MexAVIReport> | PartialBatchResult<MexAVIReport>
|
|
228
|
-
> {
|
|
229
|
-
const atomic = options.atomic ?? true;
|
|
230
|
-
const updateItemSchema = z.object({
|
|
231
|
-
id: z.uuid(),
|
|
232
|
-
data: updateAVIReportInputSchema,
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
const validated = this.validate(z.array(updateItemSchema), updates);
|
|
236
|
-
const nestedUpdates = validated.map((u) => ({
|
|
237
|
-
id: u.id,
|
|
238
|
-
data: this.transformUpdateToNested(u.data),
|
|
239
|
-
}));
|
|
240
|
-
|
|
241
|
-
const response = await this.execute(() =>
|
|
242
|
-
this.trpc.reports.updateMany.mutate({ items: nestedUpdates, atomic })
|
|
243
|
-
);
|
|
244
|
-
|
|
245
|
-
if (response.atomic) {
|
|
246
|
-
return {
|
|
247
|
-
atomic: true,
|
|
248
|
-
data: response.data.map((r) => this.instantiate(r)),
|
|
249
|
-
};
|
|
250
|
-
} else {
|
|
251
|
-
return {
|
|
252
|
-
atomic: false,
|
|
253
|
-
succeeded: response.succeeded.map((item) => ({
|
|
254
|
-
index: item.index,
|
|
255
|
-
data: this.instantiate(item.data),
|
|
256
|
-
})),
|
|
257
|
-
failed: response.failed,
|
|
258
|
-
};
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
// ─────────────────────────────────────────────────────────────────
|
|
263
|
-
// Report Items
|
|
264
|
-
// ─────────────────────────────────────────────────────────────────
|
|
265
|
-
|
|
266
|
-
async addItem(
|
|
267
|
-
reportId: string,
|
|
268
|
-
data: CreateAVIReportItemInput
|
|
269
|
-
): Promise<MexAVIReportItem> {
|
|
270
|
-
const validated = this.validate(createAVIReportItemInputSchema, data);
|
|
271
|
-
const nestedData = this.transformItemToNested(validated);
|
|
272
|
-
|
|
273
|
-
const response = await this.execute(() =>
|
|
274
|
-
this.trpc.reports.addItem.mutate({ reportId, data: nestedData })
|
|
275
|
-
);
|
|
276
|
-
|
|
277
|
-
return this.instantiateItem(response);
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
async getItem(reportId: string, itemId: string): Promise<MexAVIReportItem> {
|
|
281
|
-
const response = await this.execute(() =>
|
|
282
|
-
this.trpc.reports.getItem.query({ reportId, itemId })
|
|
283
|
-
);
|
|
284
|
-
return this.instantiateItem(response);
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
async updateItem(
|
|
288
|
-
reportId: string,
|
|
289
|
-
itemId: string,
|
|
290
|
-
data: UpdateAVIReportItemInput
|
|
291
|
-
): Promise<MexAVIReportItem> {
|
|
292
|
-
const validated = this.validate(updateAVIReportItemInputSchema, data);
|
|
293
|
-
const nestedData = this.transformItemUpdateToNested(validated);
|
|
294
|
-
|
|
295
|
-
const response = await this.execute(() =>
|
|
296
|
-
this.trpc.reports.updateItem.mutate({
|
|
297
|
-
reportId,
|
|
298
|
-
itemId,
|
|
299
|
-
data: nestedData,
|
|
300
|
-
})
|
|
301
|
-
);
|
|
302
|
-
return this.instantiateItem(response);
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
async listItems(
|
|
306
|
-
reportId: string,
|
|
307
|
-
options?: ListOptions<AVIReportItemFilter, ReportItemSort>
|
|
308
|
-
): Promise<PaginatedResponse<MexAVIReportItem>> {
|
|
309
|
-
// Transform flattened AVI filter to nested format
|
|
310
|
-
const scopedFilter = this.applyScopeToItemFilter(options?.filter);
|
|
311
|
-
|
|
312
|
-
const response = await this.execute(() =>
|
|
313
|
-
this.trpc.reports.listItems.query({
|
|
314
|
-
reportId,
|
|
315
|
-
...options,
|
|
316
|
-
filter: scopedFilter,
|
|
317
|
-
})
|
|
318
|
-
);
|
|
319
|
-
|
|
320
|
-
return {
|
|
321
|
-
data: response.data.map((i) => this.instantiateItem(i)),
|
|
322
|
-
pagination: response.pagination,
|
|
323
|
-
};
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
/**
|
|
327
|
-
* Transforms a flattened AVIReportItemFilter to nested ReportItemFilter format.
|
|
328
|
-
*/
|
|
329
|
-
protected applyScopeToItemFilter(
|
|
330
|
-
filter?: AVIReportItemFilter
|
|
331
|
-
): ReportItemFilter | undefined {
|
|
332
|
-
if (!filter) return undefined;
|
|
333
|
-
|
|
334
|
-
const { alertType, alertDescription, ...baseFields } = filter;
|
|
335
|
-
|
|
336
|
-
// If no AVI-specific fields, return base filter as-is
|
|
337
|
-
if (alertType === undefined && alertDescription === undefined) {
|
|
338
|
-
return baseFields as ReportItemFilter;
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
// Build nested filter structure
|
|
342
|
-
const aviFilter: Record<string, unknown> = {};
|
|
343
|
-
if (alertType !== undefined) aviFilter.alertType = alertType;
|
|
344
|
-
if (alertDescription !== undefined) aviFilter.alertDescription = alertDescription;
|
|
345
|
-
|
|
346
|
-
return {
|
|
347
|
-
...baseFields,
|
|
348
|
-
jurisdictions: {
|
|
349
|
-
MX: {
|
|
350
|
-
actividadVulnerable: {
|
|
351
|
-
AVI: aviFilter,
|
|
352
|
-
},
|
|
353
|
-
},
|
|
354
|
-
},
|
|
355
|
-
} as ReportItemFilter;
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
async addItems(
|
|
359
|
-
reportId: string,
|
|
360
|
-
items: CreateAVIReportItemInput[]
|
|
361
|
-
): Promise<{ added: number; items: MexAVIReportItem[] }> {
|
|
362
|
-
const validated = this.validate(
|
|
363
|
-
z.array(createAVIReportItemInputSchema),
|
|
364
|
-
items
|
|
365
|
-
);
|
|
366
|
-
const nestedItems = validated.map((i) => this.transformItemToNested(i));
|
|
367
|
-
|
|
368
|
-
const response = await this.execute(() =>
|
|
369
|
-
this.trpc.reports.addItems.mutate({ reportId, items: nestedItems })
|
|
370
|
-
);
|
|
371
|
-
|
|
372
|
-
return {
|
|
373
|
-
added: response.added,
|
|
374
|
-
items: response.items.map((i) => this.instantiateItem(i)),
|
|
375
|
-
};
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
// ─────────────────────────────────────────────────────────────────
|
|
379
|
-
// Validation
|
|
380
|
-
// ─────────────────────────────────────────────────────────────────
|
|
381
|
-
|
|
382
|
-
/**
|
|
383
|
-
* Validates an AVI report.
|
|
384
|
-
*
|
|
385
|
-
* Uses AVI-scoped validation input (jurisdiction and activity are implicit).
|
|
386
|
-
*
|
|
387
|
-
* @param reportId - The report ID to validate
|
|
388
|
-
* @param defaults - AVI report defaults including rfc, platformDomain, alertType, etc.
|
|
389
|
-
*
|
|
390
|
-
* @example
|
|
391
|
-
* ```typescript
|
|
392
|
-
* const result = await aviSdk.reports.validateReport(report.id, {
|
|
393
|
-
* rfc: "ABC200101XXX",
|
|
394
|
-
* platformDomain: "https://example.com",
|
|
395
|
-
* alertType: "100",
|
|
396
|
-
* });
|
|
397
|
-
* ```
|
|
398
|
-
*/
|
|
399
|
-
override async validateReport(
|
|
400
|
-
reportId: string,
|
|
401
|
-
defaults: AviReportDefaultsInput
|
|
402
|
-
): Promise<ValidationResult> {
|
|
403
|
-
const validated = this.validate(aviDefaultsInputSchema, defaults);
|
|
404
|
-
const nestedInput = this.transformAviDefaultsToNested(reportId, validated);
|
|
405
|
-
return this.execute(() =>
|
|
406
|
-
this.trpc.reports.validate.mutate(nestedInput as Parameters<typeof this.trpc.reports.validate.mutate>[0])
|
|
407
|
-
);
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
// ─────────────────────────────────────────────────────────────────
|
|
411
|
-
// Generation
|
|
412
|
-
// ─────────────────────────────────────────────────────────────────
|
|
413
|
-
|
|
414
|
-
/**
|
|
415
|
-
* Generates XML for an AVI report.
|
|
416
|
-
*
|
|
417
|
-
* Uses the same input as validateReport.
|
|
418
|
-
*
|
|
419
|
-
* @param reportId - The report ID to generate XML for
|
|
420
|
-
* @param defaults - AVI report defaults including rfc, platformDomain, alertType, etc.
|
|
421
|
-
*
|
|
422
|
-
* @example
|
|
423
|
-
* ```typescript
|
|
424
|
-
* const result = await aviSdk.reports.generateReport(report.id, {
|
|
425
|
-
* rfc: "ABC200101XXX",
|
|
426
|
-
* platformDomain: "https://example.com",
|
|
427
|
-
* alertType: "100",
|
|
428
|
-
* });
|
|
429
|
-
* console.log(result.xml);
|
|
430
|
-
* ```
|
|
431
|
-
*/
|
|
432
|
-
override async generateReport(
|
|
433
|
-
reportId: string,
|
|
434
|
-
defaults: AviReportDefaultsInput
|
|
435
|
-
): Promise<GenerateResult> {
|
|
436
|
-
const validated = this.validate(aviDefaultsInputSchema, defaults);
|
|
437
|
-
const nestedInput = this.transformAviDefaultsToNested(reportId, validated);
|
|
438
|
-
return this.execute(() =>
|
|
439
|
-
this.trpc.reports.generate.mutate(
|
|
440
|
-
nestedInput as Parameters<typeof this.trpc.reports.generate.mutate>[0]
|
|
441
|
-
)
|
|
442
|
-
);
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
// ─────────────────────────────────────────────────────────────────
|
|
446
|
-
// Submission
|
|
447
|
-
// ─────────────────────────────────────────────────────────────────
|
|
448
|
-
|
|
449
|
-
/**
|
|
450
|
-
* Submits a validated AVI report.
|
|
451
|
-
*
|
|
452
|
-
* Uses AVI-scoped submission input (activity is implicit).
|
|
453
|
-
*
|
|
454
|
-
* @example
|
|
455
|
-
* ```typescript
|
|
456
|
-
* const result = await aviSdk.reports.submit({
|
|
457
|
-
* reportId: report.id,
|
|
458
|
-
* acuseRecibo: "SAT-12345",
|
|
459
|
-
* notes: "Submitted via portal",
|
|
460
|
-
* });
|
|
461
|
-
* ```
|
|
462
|
-
*/
|
|
463
|
-
override async submit(
|
|
464
|
-
input: SubmitAVIReportInput
|
|
465
|
-
): Promise<SubmissionResult> {
|
|
466
|
-
const validated = this.validate(submitAVIReportInputSchema, input);
|
|
467
|
-
|
|
468
|
-
const jurisdictions = {
|
|
469
|
-
MX: {
|
|
470
|
-
actividadVulnerable: {
|
|
471
|
-
[CodigoActividad.AVI]: {
|
|
472
|
-
acuseRecibo: validated.acuseRecibo,
|
|
473
|
-
notes: validated.notes,
|
|
474
|
-
},
|
|
475
|
-
},
|
|
476
|
-
},
|
|
477
|
-
};
|
|
478
|
-
|
|
479
|
-
return this.execute(() =>
|
|
480
|
-
this.trpc.reports.submit.mutate({
|
|
481
|
-
reportId: validated.reportId,
|
|
482
|
-
jurisdictions,
|
|
483
|
-
})
|
|
484
|
-
);
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
// ─────────────────────────────────────────────────────────────────
|
|
488
|
-
// Protected Helpers
|
|
489
|
-
// ─────────────────────────────────────────────────────────────────
|
|
490
|
-
|
|
491
|
-
/**
|
|
492
|
-
* Transforms a flattened AVIReportSort to nested ReportSort format.
|
|
493
|
-
*
|
|
494
|
-
* Maps flattened field names to their full API paths.
|
|
495
|
-
*/
|
|
496
|
-
protected override applyScopeToSort(sort?: AVIReportSort): ReportSort | undefined {
|
|
497
|
-
if (!sort || sort.length === 0) {
|
|
498
|
-
return undefined;
|
|
499
|
-
}
|
|
500
|
-
return transformSort(sort, aviReportFieldMapping);
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
protected override transformToNested(
|
|
504
|
-
data: CreateAVIReportInput
|
|
505
|
-
): CreateReportInput {
|
|
506
|
-
const { mesReportado, ...baseFields } = data;
|
|
507
|
-
|
|
508
|
-
return {
|
|
509
|
-
...baseFields,
|
|
510
|
-
jurisdictions: {
|
|
511
|
-
MX: {
|
|
512
|
-
actividadVulnerable: {
|
|
513
|
-
[CodigoActividad.AVI]: { mesReportado },
|
|
514
|
-
},
|
|
515
|
-
},
|
|
516
|
-
},
|
|
517
|
-
} as CreateReportInput;
|
|
518
|
-
}
|
|
519
|
-
|
|
520
|
-
protected override transformUpdateToNested(
|
|
521
|
-
data: UpdateAVIReportInput
|
|
522
|
-
): UpdateReportInput {
|
|
523
|
-
return data as UpdateReportInput;
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
protected override instantiate(data: ReportData): MexAVIReport {
|
|
527
|
-
return new MexAVIReport(data);
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
protected override instantiateItem(data: ReportItemData): MexAVIReportItem {
|
|
531
|
-
return new MexAVIReportItem(data);
|
|
532
|
-
}
|
|
533
|
-
|
|
534
|
-
protected transformItemToNested(
|
|
535
|
-
data: CreateAVIReportItemInput
|
|
536
|
-
): CreateReportItemInput {
|
|
537
|
-
const { alertType, alertDescription, amendment, ...baseFields } = data;
|
|
538
|
-
|
|
539
|
-
const aviData: Record<string, unknown> = {};
|
|
540
|
-
if (alertType !== undefined) aviData.alertType = alertType;
|
|
541
|
-
if (alertDescription !== undefined)
|
|
542
|
-
aviData.alertDescription = alertDescription;
|
|
543
|
-
if (amendment !== undefined) aviData.amendment = amendment;
|
|
544
|
-
|
|
545
|
-
return {
|
|
546
|
-
...baseFields,
|
|
547
|
-
jurisdictions: {
|
|
548
|
-
MX: {
|
|
549
|
-
actividadVulnerable: {
|
|
550
|
-
[CodigoActividad.AVI]: aviData,
|
|
551
|
-
},
|
|
552
|
-
},
|
|
553
|
-
},
|
|
554
|
-
} as CreateReportItemInput;
|
|
555
|
-
}
|
|
556
|
-
|
|
557
|
-
protected transformItemUpdateToNested(
|
|
558
|
-
data: UpdateAVIReportItemInput
|
|
559
|
-
): UpdateReportItemInput {
|
|
560
|
-
const { alertType, alertDescription, amendment, ...baseFields } = data;
|
|
561
|
-
|
|
562
|
-
const aviData: Record<string, unknown> = {};
|
|
563
|
-
if (alertType !== undefined) aviData.alertType = alertType;
|
|
564
|
-
if (alertDescription !== undefined)
|
|
565
|
-
aviData.alertDescription = alertDescription;
|
|
566
|
-
if (amendment !== undefined) aviData.amendment = amendment;
|
|
567
|
-
|
|
568
|
-
if (Object.keys(aviData).length === 0) {
|
|
569
|
-
return baseFields as UpdateReportItemInput;
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
return {
|
|
573
|
-
...baseFields,
|
|
574
|
-
jurisdictions: {
|
|
575
|
-
MX: {
|
|
576
|
-
actividadVulnerable: {
|
|
577
|
-
[CodigoActividad.AVI]: aviData,
|
|
578
|
-
},
|
|
579
|
-
},
|
|
580
|
-
},
|
|
581
|
-
} as UpdateReportItemInput;
|
|
582
|
-
}
|
|
583
|
-
|
|
584
|
-
/**
|
|
585
|
-
* Transforms AVI defaults to nested API format for validate/generate.
|
|
586
|
-
*/
|
|
587
|
-
protected transformAviDefaultsToNested(
|
|
588
|
-
reportId: string,
|
|
589
|
-
defaults: AviReportDefaultsInput
|
|
590
|
-
): { reportId: string; jurisdictions: unknown } {
|
|
591
|
-
const { rfc, collegiateEntityCode, exempt, priority, ...aviFields } =
|
|
592
|
-
defaults;
|
|
593
|
-
|
|
594
|
-
return {
|
|
595
|
-
reportId,
|
|
596
|
-
jurisdictions: {
|
|
597
|
-
MX: {
|
|
598
|
-
actividadVulnerable: {
|
|
599
|
-
rfc,
|
|
600
|
-
collegiateEntityCode,
|
|
601
|
-
exempt,
|
|
602
|
-
priority,
|
|
603
|
-
[CodigoActividad.AVI]: aviFields,
|
|
604
|
-
},
|
|
605
|
-
},
|
|
606
|
-
},
|
|
607
|
-
};
|
|
608
|
-
}
|
|
609
|
-
}
|