cardus 0.0.65 → 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 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,21 +199,45 @@ 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
  };
201
- let userConfiguration = null;
202
+ const getRandomContentValue = () => {
203
+ return Math.floor(Math.random() * 5) + 1;
204
+ };
205
+ const integrationShipmentDetails = this.dataToInsert.details;
206
+ let shipmentContent = null;
202
207
  const userSavedData = (yield configurationService.getDefaultProformaConfiguration(idUsuario)) ||
203
208
  [];
204
- if (userSavedData.length > 0) {
205
- userConfiguration = userSavedData;
209
+ if (integrationShipmentDetails) {
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 || '');
212
+ return {
213
+ id_usuario: idUsuario,
214
+ contenido: detail.bulto.nombre_producto,
215
+ valor: detail.bulto.valor || getRandomContentValue(),
216
+ dni: user.dni,
217
+ taric,
218
+ eori_importacion: user.eori_import,
219
+ eori_exportacion: user.eori_export,
220
+ peso_bruto: detail.bulto.peso,
221
+ peso_neto: detail.bulto.peso,
222
+ origen: 1, // Sacar del país de origen de la orden pendiente. Nombre de país en inglés.
223
+ cantidad: detail.cantidad,
224
+ reason_export: '1'
225
+ };
226
+ })));
227
+ shipmentContent = shipmentContentFromDetails;
228
+ }
229
+ else if (userSavedData.length > 0) {
230
+ shipmentContent = userSavedData;
206
231
  }
207
232
  else {
208
233
  const userFakeData = configurationService.getFakeDefaultProformaConfiguration(idUsuario, user.dni);
209
- userConfiguration = userFakeData;
234
+ shipmentContent = userFakeData;
210
235
  }
211
- if (userConfiguration) {
212
- userConfiguration = cleanContentData(userConfiguration);
236
+ if (shipmentContent) {
237
+ shipmentContent = cleanContentData(shipmentContent);
213
238
  tempShimpmentIds.forEach((tempShimpmentId) => {
214
- if (userConfiguration) {
215
- insert(userConfiguration, tempShimpmentId);
239
+ if (shipmentContent) {
240
+ insert(shipmentContent, tempShimpmentId);
216
241
  }
217
242
  });
218
243
  }
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: { id_usuario: number; dni: string };
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,25 +281,58 @@ export class IntegrationManager {
277
281
  return cleanContent;
278
282
  };
279
283
 
280
- let userConfiguration: UserDefaultConfigurationContent[] | null = null;
284
+ const getRandomContentValue = () => {
285
+ return Math.floor(Math.random() * 5) + 1;
286
+ };
287
+
288
+ const integrationShipmentDetails = this.dataToInsert.details;
289
+ let shipmentContent: UserDefaultConfigurationContent[] | null = null;
281
290
  const userSavedData =
282
291
  (await configurationService.getDefaultProformaConfiguration(idUsuario)) ||
283
292
  [];
284
- if (userSavedData.length > 0) {
285
- userConfiguration = userSavedData;
293
+
294
+ if (integrationShipmentDetails) {
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
+
302
+ return {
303
+ id_usuario: idUsuario,
304
+ contenido: detail.bulto.nombre_producto,
305
+ valor: detail.bulto.valor || getRandomContentValue(),
306
+ dni: user.dni,
307
+ taric,
308
+ eori_importacion: user.eori_import,
309
+ eori_exportacion: user.eori_export,
310
+ peso_bruto: detail.bulto.peso,
311
+ peso_neto: detail.bulto.peso,
312
+ origen: 1, // Sacar del país de origen de la orden pendiente. Nombre de país en inglés.
313
+ cantidad: detail.cantidad,
314
+ reason_export: '1'
315
+ } as UserDefaultConfigurationContent;
316
+ })
317
+ );
318
+
319
+ shipmentContent = shipmentContentFromDetails;
320
+ } else if (userSavedData.length > 0) {
321
+ shipmentContent = userSavedData;
286
322
  } else {
287
323
  const userFakeData =
288
324
  configurationService.getFakeDefaultProformaConfiguration(
289
325
  idUsuario,
290
- user.dni
326
+ user.dni as string
291
327
  );
292
- userConfiguration = userFakeData;
328
+ shipmentContent = userFakeData;
293
329
  }
294
- if (userConfiguration) {
295
- userConfiguration = cleanContentData(userConfiguration);
330
+
331
+ if (shipmentContent) {
332
+ shipmentContent = cleanContentData(shipmentContent);
296
333
  tempShimpmentIds.forEach((tempShimpmentId) => {
297
- if (userConfiguration) {
298
- insert(userConfiguration, tempShimpmentId);
334
+ if (shipmentContent) {
335
+ insert(shipmentContent, tempShimpmentId);
299
336
  }
300
337
  });
301
338
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cardus",
3
- "version": "0.0.65",
3
+ "version": "0.0.67",
4
4
  "description": "an integration manager",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
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;