cardus 0.0.66 → 0.0.67
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 +13 -8
- package/index.ts +27 -12
- 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: [],
|
|
@@ -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 = {
|
|
@@ -247,11 +251,11 @@ export class IntegrationManager {
|
|
|
247
251
|
user,
|
|
248
252
|
tempShimpmentIds
|
|
249
253
|
}: {
|
|
250
|
-
user:
|
|
254
|
+
user: Record<string, string | number>;
|
|
251
255
|
tempShimpmentIds: number[];
|
|
252
256
|
}) {
|
|
253
|
-
const idUsuario = user.id_usuario;
|
|
254
|
-
const { configurationService } = this.services;
|
|
257
|
+
const idUsuario = user.id_usuario as number;
|
|
258
|
+
const { configurationService, llmAPIService } = this.services;
|
|
255
259
|
|
|
256
260
|
const insert = (
|
|
257
261
|
data: UserDefaultConfigurationContent[],
|
|
@@ -277,6 +281,10 @@ export class IntegrationManager {
|
|
|
277
281
|
return cleanContent;
|
|
278
282
|
};
|
|
279
283
|
|
|
284
|
+
const getRandomContentValue = () => {
|
|
285
|
+
return Math.floor(Math.random() * 5) + 1;
|
|
286
|
+
};
|
|
287
|
+
|
|
280
288
|
const integrationShipmentDetails = this.dataToInsert.details;
|
|
281
289
|
let shipmentContent: UserDefaultConfigurationContent[] | null = null;
|
|
282
290
|
const userSavedData =
|
|
@@ -284,23 +292,30 @@ export class IntegrationManager {
|
|
|
284
292
|
[];
|
|
285
293
|
|
|
286
294
|
if (integrationShipmentDetails) {
|
|
287
|
-
const shipmentContentFromDetails
|
|
288
|
-
integrationShipmentDetails.map((detail) => {
|
|
295
|
+
const shipmentContentFromDetails = await Promise.all(
|
|
296
|
+
integrationShipmentDetails.map(async (detail) => {
|
|
297
|
+
const taric = await llmAPIService.getTaricCode(
|
|
298
|
+
'chatgpt',
|
|
299
|
+
detail.bulto.nombre_producto || ''
|
|
300
|
+
);
|
|
301
|
+
|
|
289
302
|
return {
|
|
290
303
|
id_usuario: idUsuario,
|
|
291
304
|
contenido: detail.bulto.nombre_producto,
|
|
292
|
-
valor:
|
|
305
|
+
valor: detail.bulto.valor || getRandomContentValue(),
|
|
293
306
|
dni: user.dni,
|
|
294
|
-
taric
|
|
295
|
-
eori_importacion:
|
|
296
|
-
eori_exportacion:
|
|
307
|
+
taric,
|
|
308
|
+
eori_importacion: user.eori_import,
|
|
309
|
+
eori_exportacion: user.eori_export,
|
|
297
310
|
peso_bruto: detail.bulto.peso,
|
|
298
311
|
peso_neto: detail.bulto.peso,
|
|
299
312
|
origen: 1, // Sacar del país de origen de la orden pendiente. Nombre de país en inglés.
|
|
300
313
|
cantidad: detail.cantidad,
|
|
301
314
|
reason_export: '1'
|
|
302
315
|
} as UserDefaultConfigurationContent;
|
|
303
|
-
})
|
|
316
|
+
})
|
|
317
|
+
);
|
|
318
|
+
|
|
304
319
|
shipmentContent = shipmentContentFromDetails;
|
|
305
320
|
} else if (userSavedData.length > 0) {
|
|
306
321
|
shipmentContent = userSavedData;
|
|
@@ -308,7 +323,7 @@ export class IntegrationManager {
|
|
|
308
323
|
const userFakeData =
|
|
309
324
|
configurationService.getFakeDefaultProformaConfiguration(
|
|
310
325
|
idUsuario,
|
|
311
|
-
user.dni
|
|
326
|
+
user.dni as string
|
|
312
327
|
);
|
|
313
328
|
shipmentContent = userFakeData;
|
|
314
329
|
}
|
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;
|