@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,591 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* TSC (Tarjetas de Servicio y Crédito) Reports Resource
|
|
3
|
-
*
|
|
4
|
-
* Extends MexReportsResource with TSC-specific behavior:
|
|
5
|
-
* - Accepts flattened CreateTSCReportInput (TSC fields at root level)
|
|
6
|
-
* - Returns MexTSCReport models
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import { z } from "zod";
|
|
10
|
-
import type {
|
|
11
|
-
CreateReportInput,
|
|
12
|
-
UpdateReportInput,
|
|
13
|
-
CreateReportItemInput,
|
|
14
|
-
UpdateReportItemInput,
|
|
15
|
-
CreateTSCReportInput,
|
|
16
|
-
UpdateTSCReportInput,
|
|
17
|
-
CreateTSCReportItemInput,
|
|
18
|
-
UpdateTSCReportItemInput,
|
|
19
|
-
ListOptions,
|
|
20
|
-
PaginatedResponse,
|
|
21
|
-
AtomicBatchResult,
|
|
22
|
-
PartialBatchResult,
|
|
23
|
-
TscReportDefaultsInput,
|
|
24
|
-
ValidationResult,
|
|
25
|
-
GenerateResult,
|
|
26
|
-
SubmissionResult,
|
|
27
|
-
SubmitTSCSubmissionInput,
|
|
28
|
-
} from "@artu-ai/shared";
|
|
29
|
-
import {
|
|
30
|
-
CodigoActividad,
|
|
31
|
-
createTSCReportInputSchema,
|
|
32
|
-
updateTSCReportInputSchema,
|
|
33
|
-
createTSCReportItemInputSchema,
|
|
34
|
-
updateTSCReportItemInputSchema,
|
|
35
|
-
tscDefaultsInputSchema,
|
|
36
|
-
submitTSCSubmissionInputSchema,
|
|
37
|
-
transformSort,
|
|
38
|
-
tscReportFieldMapping,
|
|
39
|
-
} from "@artu-ai/shared";
|
|
40
|
-
import type {
|
|
41
|
-
TSCReportFilter,
|
|
42
|
-
TSCReportSort,
|
|
43
|
-
TSCReportItemFilter,
|
|
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
|
-
MexTSCReport,
|
|
52
|
-
MexTSCReportItem,
|
|
53
|
-
type ReportData,
|
|
54
|
-
type ReportItemData,
|
|
55
|
-
} from "../../../../models";
|
|
56
|
-
|
|
57
|
-
// ===========================
|
|
58
|
-
// TSCReportsResource
|
|
59
|
-
// ===========================
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* TSC (Tarjetas de Servicio y Crédito) scoped reports resource.
|
|
63
|
-
*
|
|
64
|
-
* @example
|
|
65
|
-
* ```typescript
|
|
66
|
-
* const tscSdk = new ComplianceSDK({
|
|
67
|
-
* apiKey,
|
|
68
|
-
* jurisdiction: Jurisdiction.Mexico,
|
|
69
|
-
* actividadVulnerable: CodigoActividad.TSC,
|
|
70
|
-
* });
|
|
71
|
-
*
|
|
72
|
-
* // Create with fully flattened input
|
|
73
|
-
* const report = await tscSdk.reports.create({
|
|
74
|
-
* mesReportado: "202401",
|
|
75
|
-
* });
|
|
76
|
-
*
|
|
77
|
-
* // Returns MexTSCReport
|
|
78
|
-
* console.log(report.mesReportado);
|
|
79
|
-
* ```
|
|
80
|
-
*/
|
|
81
|
-
export class TSCReportsResource extends MexReportsResource<TSCReportSort, TscReportDefaultsInput> {
|
|
82
|
-
// ─────────────────────────────────────────────────────────────────
|
|
83
|
-
// Report CRUD
|
|
84
|
-
// ─────────────────────────────────────────────────────────────────
|
|
85
|
-
|
|
86
|
-
async create(data: CreateTSCReportInput): Promise<MexTSCReport> {
|
|
87
|
-
const validated = this.validate(createTSCReportInputSchema, 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<MexTSCReport> {
|
|
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<MexTSCReport> {
|
|
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<MexTSCReport> {
|
|
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: UpdateTSCReportInput): Promise<MexTSCReport> {
|
|
119
|
-
const validated = this.validate(updateTSCReportInputSchema, 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 TSC reports with optional filtering.
|
|
134
|
-
*
|
|
135
|
-
* Accepts flattened TSC filter (future TSC-specific report fields at root level).
|
|
136
|
-
*/
|
|
137
|
-
async list(
|
|
138
|
-
options?: ListOptions<TSCReportFilter, TSCReportSort>
|
|
139
|
-
): Promise<PaginatedResponse<MexTSCReport>> {
|
|
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 TSC reports.
|
|
159
|
-
*
|
|
160
|
-
* Accepts flattened TSC filter (future TSC-specific report fields at root level).
|
|
161
|
-
*/
|
|
162
|
-
iterate(
|
|
163
|
-
filter?: TSCReportFilter
|
|
164
|
-
): AsyncGenerator<MexTSCReport, void, undefined> {
|
|
165
|
-
const scopedFilter = this.applyScopeToFilter(filter);
|
|
166
|
-
return this.createIterator<MexTSCReport>({ filter: scopedFilter });
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
// ─────────────────────────────────────────────────────────────────
|
|
170
|
-
// Batch Operations
|
|
171
|
-
// ─────────────────────────────────────────────────────────────────
|
|
172
|
-
|
|
173
|
-
async createMany(
|
|
174
|
-
reports: CreateTSCReportInput[],
|
|
175
|
-
options?: { atomic?: true }
|
|
176
|
-
): Promise<AtomicBatchResult<MexTSCReport>>;
|
|
177
|
-
async createMany(
|
|
178
|
-
reports: CreateTSCReportInput[],
|
|
179
|
-
options: { atomic: false }
|
|
180
|
-
): Promise<PartialBatchResult<MexTSCReport>>;
|
|
181
|
-
async createMany(
|
|
182
|
-
reports: CreateTSCReportInput[],
|
|
183
|
-
options: BatchOptions = {}
|
|
184
|
-
): Promise<
|
|
185
|
-
AtomicBatchResult<MexTSCReport> | PartialBatchResult<MexTSCReport>
|
|
186
|
-
> {
|
|
187
|
-
const atomic = options.atomic ?? true;
|
|
188
|
-
const validated = this.validate(
|
|
189
|
-
z.array(createTSCReportInputSchema),
|
|
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: UpdateTSCReportInput }[],
|
|
217
|
-
options?: { atomic?: true }
|
|
218
|
-
): Promise<AtomicBatchResult<MexTSCReport>>;
|
|
219
|
-
async updateMany(
|
|
220
|
-
updates: { id: string; data: UpdateTSCReportInput }[],
|
|
221
|
-
options: { atomic: false }
|
|
222
|
-
): Promise<PartialBatchResult<MexTSCReport>>;
|
|
223
|
-
async updateMany(
|
|
224
|
-
updates: { id: string; data: UpdateTSCReportInput }[],
|
|
225
|
-
options: BatchOptions = {}
|
|
226
|
-
): Promise<
|
|
227
|
-
AtomicBatchResult<MexTSCReport> | PartialBatchResult<MexTSCReport>
|
|
228
|
-
> {
|
|
229
|
-
const atomic = options.atomic ?? true;
|
|
230
|
-
const updateItemSchema = z.object({
|
|
231
|
-
id: z.uuid(),
|
|
232
|
-
data: updateTSCReportInputSchema,
|
|
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: CreateTSCReportItemInput
|
|
269
|
-
): Promise<MexTSCReportItem> {
|
|
270
|
-
const validated = this.validate(createTSCReportItemInputSchema, 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<MexTSCReportItem> {
|
|
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: UpdateTSCReportItemInput
|
|
291
|
-
): Promise<MexTSCReportItem> {
|
|
292
|
-
const validated = this.validate(updateTSCReportItemInputSchema, 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<TSCReportItemFilter, ReportItemSort>
|
|
308
|
-
): Promise<PaginatedResponse<MexTSCReportItem>> {
|
|
309
|
-
// Transform flattened TSC 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 TSCReportItemFilter to nested ReportItemFilter format.
|
|
328
|
-
*/
|
|
329
|
-
protected applyScopeToItemFilter(
|
|
330
|
-
filter?: TSCReportItemFilter
|
|
331
|
-
): ReportItemFilter | undefined {
|
|
332
|
-
if (!filter) return undefined;
|
|
333
|
-
|
|
334
|
-
const { alertType, alertDescription, ...baseFields } = filter;
|
|
335
|
-
|
|
336
|
-
// If no TSC-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 tscFilter: Record<string, unknown> = {};
|
|
343
|
-
if (alertType !== undefined) tscFilter.alertType = alertType;
|
|
344
|
-
if (alertDescription !== undefined) tscFilter.alertDescription = alertDescription;
|
|
345
|
-
|
|
346
|
-
return {
|
|
347
|
-
...baseFields,
|
|
348
|
-
jurisdictions: {
|
|
349
|
-
MX: {
|
|
350
|
-
actividadVulnerable: {
|
|
351
|
-
TSC: tscFilter,
|
|
352
|
-
},
|
|
353
|
-
},
|
|
354
|
-
},
|
|
355
|
-
} as ReportItemFilter;
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
async addItems(
|
|
359
|
-
reportId: string,
|
|
360
|
-
items: CreateTSCReportItemInput[]
|
|
361
|
-
): Promise<{ added: number; items: MexTSCReportItem[] }> {
|
|
362
|
-
const validated = this.validate(
|
|
363
|
-
z.array(createTSCReportItemInputSchema),
|
|
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 a TSC report.
|
|
384
|
-
*
|
|
385
|
-
* Uses TSC-scoped validation input (jurisdiction and activity are implicit).
|
|
386
|
-
*
|
|
387
|
-
* @param reportId - The report ID to validate
|
|
388
|
-
* @param defaults - TSC report defaults including rfc, alertType, etc.
|
|
389
|
-
*
|
|
390
|
-
* @example
|
|
391
|
-
* ```typescript
|
|
392
|
-
* const result = await tscSdk.reports.validateReport(report.id, {
|
|
393
|
-
* rfc: "ABC200101XXX",
|
|
394
|
-
* alertType: "100",
|
|
395
|
-
* });
|
|
396
|
-
* ```
|
|
397
|
-
*/
|
|
398
|
-
override async validateReport(
|
|
399
|
-
reportId: string,
|
|
400
|
-
defaults: TscReportDefaultsInput
|
|
401
|
-
): Promise<ValidationResult> {
|
|
402
|
-
const validated = this.validate(tscDefaultsInputSchema, defaults);
|
|
403
|
-
const nestedInput = this.transformTscDefaultsToNested(reportId, validated);
|
|
404
|
-
return this.execute(() =>
|
|
405
|
-
this.trpc.reports.validate.mutate(
|
|
406
|
-
nestedInput as Parameters<typeof this.trpc.reports.validate.mutate>[0]
|
|
407
|
-
)
|
|
408
|
-
);
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
// ─────────────────────────────────────────────────────────────────
|
|
412
|
-
// Generation
|
|
413
|
-
// ─────────────────────────────────────────────────────────────────
|
|
414
|
-
|
|
415
|
-
/**
|
|
416
|
-
* Generates XML for a TSC report.
|
|
417
|
-
*
|
|
418
|
-
* Uses the same input as validateReport.
|
|
419
|
-
*
|
|
420
|
-
* @param reportId - The report ID to generate XML for
|
|
421
|
-
* @param defaults - TSC report defaults including rfc, alertType, etc.
|
|
422
|
-
*/
|
|
423
|
-
override async generateReport(
|
|
424
|
-
reportId: string,
|
|
425
|
-
defaults: TscReportDefaultsInput
|
|
426
|
-
): Promise<GenerateResult> {
|
|
427
|
-
const validated = this.validate(tscDefaultsInputSchema, defaults);
|
|
428
|
-
const nestedInput = this.transformTscDefaultsToNested(reportId, validated);
|
|
429
|
-
return this.execute(() =>
|
|
430
|
-
this.trpc.reports.generate.mutate(
|
|
431
|
-
nestedInput as Parameters<typeof this.trpc.reports.generate.mutate>[0]
|
|
432
|
-
)
|
|
433
|
-
);
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
// ─────────────────────────────────────────────────────────────────
|
|
437
|
-
// Submission
|
|
438
|
-
// ─────────────────────────────────────────────────────────────────
|
|
439
|
-
|
|
440
|
-
/**
|
|
441
|
-
* Submits a validated TSC report.
|
|
442
|
-
*
|
|
443
|
-
* Uses TSC-scoped submission input (activity is implicit).
|
|
444
|
-
*/
|
|
445
|
-
override async submit(
|
|
446
|
-
input: SubmitTSCSubmissionInput
|
|
447
|
-
): Promise<SubmissionResult> {
|
|
448
|
-
const validated = this.validate(submitTSCSubmissionInputSchema, input);
|
|
449
|
-
|
|
450
|
-
const jurisdictions = {
|
|
451
|
-
MX: {
|
|
452
|
-
actividadVulnerable: {
|
|
453
|
-
[CodigoActividad.TSC]: {
|
|
454
|
-
acuseRecibo: validated.acuseRecibo,
|
|
455
|
-
notes: validated.notes,
|
|
456
|
-
},
|
|
457
|
-
},
|
|
458
|
-
},
|
|
459
|
-
};
|
|
460
|
-
|
|
461
|
-
return this.execute(() =>
|
|
462
|
-
this.trpc.reports.submit.mutate({
|
|
463
|
-
reportId: validated.reportId,
|
|
464
|
-
jurisdictions,
|
|
465
|
-
})
|
|
466
|
-
);
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
// ─────────────────────────────────────────────────────────────────
|
|
470
|
-
// Protected Helpers
|
|
471
|
-
// ─────────────────────────────────────────────────────────────────
|
|
472
|
-
|
|
473
|
-
protected override transformToNested(
|
|
474
|
-
data: CreateTSCReportInput
|
|
475
|
-
): CreateReportInput {
|
|
476
|
-
const { mesReportado, ...baseFields } = data;
|
|
477
|
-
|
|
478
|
-
return {
|
|
479
|
-
...baseFields,
|
|
480
|
-
jurisdictions: {
|
|
481
|
-
MX: {
|
|
482
|
-
actividadVulnerable: {
|
|
483
|
-
[CodigoActividad.TSC]: { mesReportado },
|
|
484
|
-
},
|
|
485
|
-
},
|
|
486
|
-
},
|
|
487
|
-
} as CreateReportInput;
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
protected override transformUpdateToNested(
|
|
491
|
-
data: UpdateTSCReportInput
|
|
492
|
-
): UpdateReportInput {
|
|
493
|
-
return data as UpdateReportInput;
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
protected override instantiate(data: ReportData): MexTSCReport {
|
|
497
|
-
return new MexTSCReport(data);
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
protected override instantiateItem(data: ReportItemData): MexTSCReportItem {
|
|
501
|
-
return new MexTSCReportItem(data);
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
protected transformItemToNested(
|
|
505
|
-
data: CreateTSCReportItemInput
|
|
506
|
-
): CreateReportItemInput {
|
|
507
|
-
const { alertType, alertDescription, amendment, ...baseFields } = data;
|
|
508
|
-
|
|
509
|
-
const tscData: Record<string, unknown> = {};
|
|
510
|
-
if (alertType !== undefined) tscData.alertType = alertType;
|
|
511
|
-
if (alertDescription !== undefined)
|
|
512
|
-
tscData.alertDescription = alertDescription;
|
|
513
|
-
if (amendment !== undefined) tscData.amendment = amendment;
|
|
514
|
-
|
|
515
|
-
return {
|
|
516
|
-
...baseFields,
|
|
517
|
-
jurisdictions: {
|
|
518
|
-
MX: {
|
|
519
|
-
actividadVulnerable: {
|
|
520
|
-
[CodigoActividad.TSC]: tscData,
|
|
521
|
-
},
|
|
522
|
-
},
|
|
523
|
-
},
|
|
524
|
-
} as CreateReportItemInput;
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
protected transformItemUpdateToNested(
|
|
528
|
-
data: UpdateTSCReportItemInput
|
|
529
|
-
): UpdateReportItemInput {
|
|
530
|
-
const { alertType, alertDescription, amendment, ...baseFields } = data;
|
|
531
|
-
|
|
532
|
-
const tscData: Record<string, unknown> = {};
|
|
533
|
-
if (alertType !== undefined) tscData.alertType = alertType;
|
|
534
|
-
if (alertDescription !== undefined)
|
|
535
|
-
tscData.alertDescription = alertDescription;
|
|
536
|
-
if (amendment !== undefined) tscData.amendment = amendment;
|
|
537
|
-
|
|
538
|
-
if (Object.keys(tscData).length === 0) {
|
|
539
|
-
return baseFields as UpdateReportItemInput;
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
return {
|
|
543
|
-
...baseFields,
|
|
544
|
-
jurisdictions: {
|
|
545
|
-
MX: {
|
|
546
|
-
actividadVulnerable: {
|
|
547
|
-
[CodigoActividad.TSC]: tscData,
|
|
548
|
-
},
|
|
549
|
-
},
|
|
550
|
-
},
|
|
551
|
-
} as UpdateReportItemInput;
|
|
552
|
-
}
|
|
553
|
-
|
|
554
|
-
/**
|
|
555
|
-
* Transforms a flattened TSCReportSort to nested ReportSort format.
|
|
556
|
-
*
|
|
557
|
-
* Maps flattened field names to their full API paths using TSC-specific field mapping.
|
|
558
|
-
*/
|
|
559
|
-
protected override applyScopeToSort(sort?: TSCReportSort): ReportSort | undefined {
|
|
560
|
-
if (!sort || sort.length === 0) {
|
|
561
|
-
return undefined;
|
|
562
|
-
}
|
|
563
|
-
return transformSort(sort, tscReportFieldMapping);
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
/**
|
|
567
|
-
* Transforms TSC defaults to nested API format for validate/generate.
|
|
568
|
-
*/
|
|
569
|
-
protected transformTscDefaultsToNested(
|
|
570
|
-
reportId: string,
|
|
571
|
-
defaults: TscReportDefaultsInput
|
|
572
|
-
): { reportId: string; jurisdictions: unknown } {
|
|
573
|
-
const { rfc, collegiateEntityCode, exempt, priority, ...tscFields } =
|
|
574
|
-
defaults;
|
|
575
|
-
|
|
576
|
-
return {
|
|
577
|
-
reportId,
|
|
578
|
-
jurisdictions: {
|
|
579
|
-
MX: {
|
|
580
|
-
actividadVulnerable: {
|
|
581
|
-
rfc,
|
|
582
|
-
collegiateEntityCode,
|
|
583
|
-
exempt,
|
|
584
|
-
priority,
|
|
585
|
-
[CodigoActividad.TSC]: tscFields,
|
|
586
|
-
},
|
|
587
|
-
},
|
|
588
|
-
},
|
|
589
|
-
};
|
|
590
|
-
}
|
|
591
|
-
}
|