cardus 0.0.66 → 0.0.68
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/dist/index.js +14 -9
- package/index.ts +31 -13
- package/package.json +1 -1
- package/types/index.ts +8 -0
package/dist/index.js
CHANGED
|
@@ -67,7 +67,8 @@ class IntegrationManager {
|
|
|
67
67
|
countriesService: params.countriesService,
|
|
68
68
|
configurationService: params.configurationService,
|
|
69
69
|
usersService: params.usersService,
|
|
70
|
-
customizationService: params.customizationService
|
|
70
|
+
customizationService: params.customizationService,
|
|
71
|
+
llmAPIService: params.llmAPIService
|
|
71
72
|
};
|
|
72
73
|
this.dataToInsert = {
|
|
73
74
|
lines: [],
|
|
@@ -173,7 +174,7 @@ class IntegrationManager {
|
|
|
173
174
|
})));
|
|
174
175
|
yield Promise.allSettled([
|
|
175
176
|
integrationsService.insertTempShipmentMultipleLines(this.dataToInsert.lines),
|
|
176
|
-
integrationsService.insertTempShipmentMultipleDetails(this.dataToInsert.details),
|
|
177
|
+
integrationsService.insertTempShipmentMultipleDetails(this.dataToInsert.details.map((detail) => (Object.assign(Object.assign({}, detail), { url_producto: JSON.stringify(this.dataToInsert.details) })))),
|
|
177
178
|
integrationsService.insertTempShipmentMultipleContents(this.dataToInsert.contents),
|
|
178
179
|
integrationsService.insertTempShipmentMultipleExternals(this.dataToInsert.externals)
|
|
179
180
|
]);
|
|
@@ -187,7 +188,7 @@ class IntegrationManager {
|
|
|
187
188
|
insertUserDefaultConfigurationContent(_a) {
|
|
188
189
|
return __awaiter(this, arguments, void 0, function* ({ user, tempShimpmentIds }) {
|
|
189
190
|
const idUsuario = user.id_usuario;
|
|
190
|
-
const { configurationService } = this.services;
|
|
191
|
+
const { configurationService, llmAPIService } = this.services;
|
|
191
192
|
const insert = (data, tempShimpmentId) => {
|
|
192
193
|
data.forEach((tempContent) => {
|
|
193
194
|
this.dataToInsert.contents.push(Object.assign(Object.assign({}, tempContent), { id_envio: tempShimpmentId }));
|
|
@@ -198,27 +199,31 @@ class IntegrationManager {
|
|
|
198
199
|
const cleanContent = contents.map((content) => (Object.assign(Object.assign({}, content), { peso_bruto: content.peso_bruto < 0.1 ? 1 : content.peso_bruto, peso_neto: content.peso_neto < 0.1 ? 1 : content.peso_neto, valor: content.valor <= 0 ? 1 : content.valor })));
|
|
199
200
|
return cleanContent;
|
|
200
201
|
};
|
|
202
|
+
const getRandomContentValue = () => {
|
|
203
|
+
return Math.floor(Math.random() * 5) + 1;
|
|
204
|
+
};
|
|
201
205
|
const integrationShipmentDetails = this.dataToInsert.details;
|
|
202
206
|
let shipmentContent = null;
|
|
203
207
|
const userSavedData = (yield configurationService.getDefaultProformaConfiguration(idUsuario)) ||
|
|
204
208
|
[];
|
|
205
209
|
if (integrationShipmentDetails) {
|
|
206
|
-
const shipmentContentFromDetails = integrationShipmentDetails.map((detail) => {
|
|
210
|
+
const shipmentContentFromDetails = yield Promise.all(integrationShipmentDetails.map((detail) => __awaiter(this, void 0, void 0, function* () {
|
|
211
|
+
const taric = yield llmAPIService.getTaricCode('chatgpt', detail.bulto.nombre_producto || '');
|
|
207
212
|
return {
|
|
208
213
|
id_usuario: idUsuario,
|
|
209
214
|
contenido: detail.bulto.nombre_producto,
|
|
210
|
-
valor:
|
|
215
|
+
valor: detail.bulto.valor || getRandomContentValue(),
|
|
211
216
|
dni: user.dni,
|
|
212
|
-
taric
|
|
213
|
-
eori_importacion:
|
|
214
|
-
eori_exportacion:
|
|
217
|
+
taric,
|
|
218
|
+
eori_importacion: user.eori_import,
|
|
219
|
+
eori_exportacion: user.eori_export,
|
|
215
220
|
peso_bruto: detail.bulto.peso,
|
|
216
221
|
peso_neto: detail.bulto.peso,
|
|
217
222
|
origen: 1, // Sacar del país de origen de la orden pendiente. Nombre de país en inglés.
|
|
218
223
|
cantidad: detail.cantidad,
|
|
219
224
|
reason_export: '1'
|
|
220
225
|
};
|
|
221
|
-
});
|
|
226
|
+
})));
|
|
222
227
|
shipmentContent = shipmentContentFromDetails;
|
|
223
228
|
}
|
|
224
229
|
else if (userSavedData.length > 0) {
|
package/index.ts
CHANGED
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
ConfigurationService,
|
|
15
15
|
UsersService,
|
|
16
16
|
IntegrationsService,
|
|
17
|
+
LlmAPIService,
|
|
17
18
|
Type,
|
|
18
19
|
SellerAddress,
|
|
19
20
|
OriginalOrder,
|
|
@@ -36,6 +37,7 @@ interface Services {
|
|
|
36
37
|
configurationService: ConfigurationService;
|
|
37
38
|
usersService: UsersService;
|
|
38
39
|
customizationService: CustomizationService;
|
|
40
|
+
llmAPIService: LlmAPIService;
|
|
39
41
|
}
|
|
40
42
|
|
|
41
43
|
export class IntegrationManager {
|
|
@@ -56,6 +58,7 @@ export class IntegrationManager {
|
|
|
56
58
|
configurationService: ConfigurationService;
|
|
57
59
|
usersService: UsersService;
|
|
58
60
|
customizationService: CustomizationService;
|
|
61
|
+
llmAPIService: LlmAPIService;
|
|
59
62
|
type: Type;
|
|
60
63
|
integrationType: IntegrationType;
|
|
61
64
|
shipmentType: ShipmentType;
|
|
@@ -69,7 +72,8 @@ export class IntegrationManager {
|
|
|
69
72
|
countriesService: params.countriesService,
|
|
70
73
|
configurationService: params.configurationService,
|
|
71
74
|
usersService: params.usersService,
|
|
72
|
-
customizationService: params.customizationService
|
|
75
|
+
customizationService: params.customizationService,
|
|
76
|
+
llmAPIService: params.llmAPIService
|
|
73
77
|
};
|
|
74
78
|
|
|
75
79
|
this.dataToInsert = {
|
|
@@ -226,7 +230,10 @@ export class IntegrationManager {
|
|
|
226
230
|
this.dataToInsert.lines
|
|
227
231
|
),
|
|
228
232
|
integrationsService.insertTempShipmentMultipleDetails(
|
|
229
|
-
this.dataToInsert.details
|
|
233
|
+
this.dataToInsert.details.map((detail) => ({
|
|
234
|
+
...detail,
|
|
235
|
+
url_producto: JSON.stringify(this.dataToInsert.details)
|
|
236
|
+
}))
|
|
230
237
|
),
|
|
231
238
|
integrationsService.insertTempShipmentMultipleContents(
|
|
232
239
|
this.dataToInsert.contents
|
|
@@ -247,11 +254,11 @@ export class IntegrationManager {
|
|
|
247
254
|
user,
|
|
248
255
|
tempShimpmentIds
|
|
249
256
|
}: {
|
|
250
|
-
user:
|
|
257
|
+
user: Record<string, string | number>;
|
|
251
258
|
tempShimpmentIds: number[];
|
|
252
259
|
}) {
|
|
253
|
-
const idUsuario = user.id_usuario;
|
|
254
|
-
const { configurationService } = this.services;
|
|
260
|
+
const idUsuario = user.id_usuario as number;
|
|
261
|
+
const { configurationService, llmAPIService } = this.services;
|
|
255
262
|
|
|
256
263
|
const insert = (
|
|
257
264
|
data: UserDefaultConfigurationContent[],
|
|
@@ -277,6 +284,10 @@ export class IntegrationManager {
|
|
|
277
284
|
return cleanContent;
|
|
278
285
|
};
|
|
279
286
|
|
|
287
|
+
const getRandomContentValue = () => {
|
|
288
|
+
return Math.floor(Math.random() * 5) + 1;
|
|
289
|
+
};
|
|
290
|
+
|
|
280
291
|
const integrationShipmentDetails = this.dataToInsert.details;
|
|
281
292
|
let shipmentContent: UserDefaultConfigurationContent[] | null = null;
|
|
282
293
|
const userSavedData =
|
|
@@ -284,23 +295,30 @@ export class IntegrationManager {
|
|
|
284
295
|
[];
|
|
285
296
|
|
|
286
297
|
if (integrationShipmentDetails) {
|
|
287
|
-
const shipmentContentFromDetails
|
|
288
|
-
integrationShipmentDetails.map((detail) => {
|
|
298
|
+
const shipmentContentFromDetails = await Promise.all(
|
|
299
|
+
integrationShipmentDetails.map(async (detail) => {
|
|
300
|
+
const taric = await llmAPIService.getTaricCode(
|
|
301
|
+
'chatgpt',
|
|
302
|
+
detail.bulto.nombre_producto || ''
|
|
303
|
+
);
|
|
304
|
+
|
|
289
305
|
return {
|
|
290
306
|
id_usuario: idUsuario,
|
|
291
307
|
contenido: detail.bulto.nombre_producto,
|
|
292
|
-
valor:
|
|
308
|
+
valor: detail.bulto.valor || getRandomContentValue(),
|
|
293
309
|
dni: user.dni,
|
|
294
|
-
taric
|
|
295
|
-
eori_importacion:
|
|
296
|
-
eori_exportacion:
|
|
310
|
+
taric,
|
|
311
|
+
eori_importacion: user.eori_import,
|
|
312
|
+
eori_exportacion: user.eori_export,
|
|
297
313
|
peso_bruto: detail.bulto.peso,
|
|
298
314
|
peso_neto: detail.bulto.peso,
|
|
299
315
|
origen: 1, // Sacar del país de origen de la orden pendiente. Nombre de país en inglés.
|
|
300
316
|
cantidad: detail.cantidad,
|
|
301
317
|
reason_export: '1'
|
|
302
318
|
} as UserDefaultConfigurationContent;
|
|
303
|
-
})
|
|
319
|
+
})
|
|
320
|
+
);
|
|
321
|
+
|
|
304
322
|
shipmentContent = shipmentContentFromDetails;
|
|
305
323
|
} else if (userSavedData.length > 0) {
|
|
306
324
|
shipmentContent = userSavedData;
|
|
@@ -308,7 +326,7 @@ export class IntegrationManager {
|
|
|
308
326
|
const userFakeData =
|
|
309
327
|
configurationService.getFakeDefaultProformaConfiguration(
|
|
310
328
|
idUsuario,
|
|
311
|
-
user.dni
|
|
329
|
+
user.dni as string
|
|
312
330
|
);
|
|
313
331
|
shipmentContent = userFakeData;
|
|
314
332
|
}
|
package/package.json
CHANGED
package/types/index.ts
CHANGED
|
@@ -91,6 +91,7 @@ export type Bulto = {
|
|
|
91
91
|
id_producto: number | null;
|
|
92
92
|
url_imagen: string | null;
|
|
93
93
|
nombre_producto: string | null;
|
|
94
|
+
valor?: number;
|
|
94
95
|
};
|
|
95
96
|
cantidad: number;
|
|
96
97
|
forzarAgrupamientoDeLinea: boolean;
|
|
@@ -237,6 +238,13 @@ export type IntegrationsService = {
|
|
|
237
238
|
}) => Promise<boolean>;
|
|
238
239
|
};
|
|
239
240
|
|
|
241
|
+
export type LlmAPIService = {
|
|
242
|
+
getTaricCode: (
|
|
243
|
+
provider: string,
|
|
244
|
+
producto: string
|
|
245
|
+
) => Promise<string | undefined>;
|
|
246
|
+
};
|
|
247
|
+
|
|
240
248
|
export type SellerAddress = {
|
|
241
249
|
id_pais: number;
|
|
242
250
|
codigo_postal: string;
|