@zauru-sdk/services 1.0.95 → 1.0.98

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.
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getGeneralQuery = void 0;
7
+ const common_1 = require("@zauru-sdk/common");
8
+ const common_js_1 = require("../common.js");
9
+ const httpGraphQL_js_1 = __importDefault(require("../zauru/httpGraphQL.js"));
10
+ /**
11
+ * getGeneralQuery
12
+ * @param headers
13
+ * @param queryKey - clave dinámica para acceder a los datos en la respuesta (ej. 'purchase_orders', 'users')
14
+ * @returns
15
+ */
16
+ const getGeneralQuery = async (session, query, queryKey // Clave dinámica
17
+ ) => {
18
+ return (0, common_1.handlePossibleAxiosErrors)(async () => {
19
+ const headers = await (0, common_js_1.getGraphQLAPIHeaders)(session);
20
+ // Respuesta con clave dinámica basada en queryKey
21
+ const response = await httpGraphQL_js_1.default.post("", {
22
+ query,
23
+ }, { headers });
24
+ if (response.data.errors) {
25
+ throw new Error(response.data.errors.map((x) => x.message).join(";"));
26
+ }
27
+ // Retorna los datos según la clave dinámica proporcionada
28
+ return response.data.data[queryKey];
29
+ });
30
+ };
31
+ exports.getGeneralQuery = getGeneralQuery;
package/dist/cjs/index.js CHANGED
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./common.js"), exports);
18
+ __exportStar(require("./graphql/index.js"), exports);
18
19
  __exportStar(require("./sessions/sessions.js"), exports);
19
20
  __exportStar(require("./sessions/upstash.js"), exports);
20
21
  __exportStar(require("./zauru/httpGraphQL.js"), exports);
@@ -309,51 +309,55 @@ const getPurchaseOrder = (session, poId, config = {
309
309
  };
310
310
  exports.getPurchaseOrder = getPurchaseOrder;
311
311
  /**
312
- * getPurchaseOrder
312
+ * getGraphQLPurchaseOrderBetweenDates
313
313
  * @param headers
314
314
  * @returns
315
315
  */
316
- const getGraphQLPurchaseOrderBetweenDates = (session, dates, config = {
317
- agencyFilter: true,
318
- consolidateIdFilter: false,
319
- useProductionAgencyId: false,
320
- withShipmentToMyAgency: false,
321
- withLotStocksToMyAgency: false,
322
- betweenIssueDate: false,
323
- withPODetails: true,
324
- withLots: true,
325
- withShipmentPurchaseOrders: true,
326
- withWebAppRows: true,
327
- payeeCategoryIds: [],
328
- excludePayeeCategoryIds: [],
329
- }) => {
316
+ const getGraphQLPurchaseOrderBetweenDates = (session, dates, config = {}) => {
330
317
  return (0, common_1.handlePossibleAxiosErrors)(async () => {
331
318
  const headers = await (0, common_js_1.getGraphQLAPIHeaders)(session);
332
- let agency_id = config.agencyId;
333
- if (config.useProductionAgencyId) {
334
- const { production_agency_id /**{5693: 5696} */ } = await (0, common_js_1.getVariablesByName)(headers, session, ["production_agency_id"]);
319
+ // Valores por defecto para config
320
+ const defaultConfig = {
321
+ agencyFilter: true,
322
+ consolidateIdFilter: false,
323
+ useProductionAgencyId: false,
324
+ withShipmentToMyAgency: false,
325
+ withLotStocksToMyAgency: false,
326
+ betweenIssueDate: false,
327
+ withPODetails: true,
328
+ withLots: true,
329
+ withShipmentPurchaseOrders: true,
330
+ withWebAppRows: true,
331
+ payeeCategoryIds: [],
332
+ excludePayeeCategoryIds: [],
333
+ };
334
+ // Combinar config con los valores por defecto
335
+ const finalConfig = { ...defaultConfig, ...config };
336
+ let agency_id = finalConfig.agencyId;
337
+ if (finalConfig.useProductionAgencyId) {
338
+ const { production_agency_id } = await (0, common_js_1.getVariablesByName)(headers, session, ["production_agency_id"]);
335
339
  const hashAgencyId = JSON.parse(production_agency_id ?? "{}");
336
340
  agency_id = hashAgencyId[session.get("agency_id")];
337
341
  }
338
342
  const query = (0, graphql_1.getPurchaseOrdersBetweenDatesStringQuery)((0, common_1.formatDateToUTC)(dates.startDate), (0, common_1.formatDateToUTC)(dates.endDate), {
339
- agencyId: config.agencyFilter
343
+ agencyId: finalConfig.agencyFilter
340
344
  ? agency_id ?? session.get("agency_id")
341
345
  : undefined,
342
- consolidateIdFilter: config.consolidateIdFilter,
343
- lotItemIdExclusion: config.lotItemIdExclusion,
344
- poDetailTagId: config.poDetailTagId,
345
- withLotStocks: config.withLotStocksToMyAgency,
346
- itemId: config.itemId,
347
- payeeCategoryId: config.payeeCategoryId,
348
- betweenIssueDate: config.betweenIssueDate,
349
- payeeId: config.payeeId,
350
- id_number: config.id_number,
351
- withPODetails: config.withPODetails,
352
- withLots: config.withLots,
353
- withShipmentPurchaseOrders: config.withShipmentPurchaseOrders,
354
- withWebAppRows: config.withWebAppRows,
355
- payeeCategoryIds: config.payeeCategoryIds,
356
- excludePayeeCategoryIds: config.excludePayeeCategoryIds,
346
+ consolidateIdFilter: finalConfig.consolidateIdFilter,
347
+ lotItemIdExclusion: finalConfig.lotItemIdExclusion,
348
+ poDetailTagId: finalConfig.poDetailTagId,
349
+ withLotStocks: finalConfig.withLotStocksToMyAgency,
350
+ itemId: finalConfig.itemId,
351
+ payeeCategoryId: finalConfig.payeeCategoryId,
352
+ betweenIssueDate: finalConfig.betweenIssueDate,
353
+ payeeId: finalConfig.payeeId,
354
+ id_number: finalConfig.id_number,
355
+ withPODetails: finalConfig.withPODetails,
356
+ withLots: finalConfig.withLots,
357
+ withShipmentPurchaseOrders: finalConfig.withShipmentPurchaseOrders,
358
+ withWebAppRows: finalConfig.withWebAppRows,
359
+ payeeCategoryIds: finalConfig.payeeCategoryIds,
360
+ excludePayeeCategoryIds: finalConfig.excludePayeeCategoryIds,
357
361
  });
358
362
  const graphQLBody = {
359
363
  query,
@@ -364,10 +368,10 @@ const getGraphQLPurchaseOrderBetweenDates = (session, dates, config = {
364
368
  }
365
369
  //============ Aplicación de filtros
366
370
  let responseData = response.data.data.purchase_orders;
367
- if (config.withShipmentToMyAgency) {
371
+ if (finalConfig.withShipmentToMyAgency) {
368
372
  responseData = response.data?.data?.purchase_orders.filter((x) => x.shipment_purchase_orders.some((y) => y.shipment.agency_to_id?.toString() == session.get("agency_id")));
369
373
  }
370
- if (config.withLotStocksToMyAgency) {
374
+ if (finalConfig.withLotStocksToMyAgency && finalConfig.withLots) {
371
375
  responseData = responseData.map((x) => {
372
376
  x.lots = x.lots.map((y) => {
373
377
  y.lot_stocks = y.lot_stocks.filter((z) => z.agency_id == session.get("agency_id"));
@@ -0,0 +1,24 @@
1
+ import { handlePossibleAxiosErrors } from "@zauru-sdk/common";
2
+ import { getGraphQLAPIHeaders } from "../common.js";
3
+ import httpGraphQLAPI from "../zauru/httpGraphQL.js";
4
+ /**
5
+ * getGeneralQuery
6
+ * @param headers
7
+ * @param queryKey - clave dinámica para acceder a los datos en la respuesta (ej. 'purchase_orders', 'users')
8
+ * @returns
9
+ */
10
+ export const getGeneralQuery = async (session, query, queryKey // Clave dinámica
11
+ ) => {
12
+ return handlePossibleAxiosErrors(async () => {
13
+ const headers = await getGraphQLAPIHeaders(session);
14
+ // Respuesta con clave dinámica basada en queryKey
15
+ const response = await httpGraphQLAPI.post("", {
16
+ query,
17
+ }, { headers });
18
+ if (response.data.errors) {
19
+ throw new Error(response.data.errors.map((x) => x.message).join(";"));
20
+ }
21
+ // Retorna los datos según la clave dinámica proporcionada
22
+ return response.data.data[queryKey];
23
+ });
24
+ };
package/dist/esm/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from "./common.js";
2
+ export * from "./graphql/index.js";
2
3
  export * from "./sessions/sessions.js";
3
4
  export * from "./sessions/upstash.js";
4
5
  export * from "./zauru/httpGraphQL.js";
@@ -289,51 +289,55 @@ export const getPurchaseOrder = (session, poId, config = {
289
289
  });
290
290
  };
291
291
  /**
292
- * getPurchaseOrder
292
+ * getGraphQLPurchaseOrderBetweenDates
293
293
  * @param headers
294
294
  * @returns
295
295
  */
296
- export const getGraphQLPurchaseOrderBetweenDates = (session, dates, config = {
297
- agencyFilter: true,
298
- consolidateIdFilter: false,
299
- useProductionAgencyId: false,
300
- withShipmentToMyAgency: false,
301
- withLotStocksToMyAgency: false,
302
- betweenIssueDate: false,
303
- withPODetails: true,
304
- withLots: true,
305
- withShipmentPurchaseOrders: true,
306
- withWebAppRows: true,
307
- payeeCategoryIds: [],
308
- excludePayeeCategoryIds: [],
309
- }) => {
296
+ export const getGraphQLPurchaseOrderBetweenDates = (session, dates, config = {}) => {
310
297
  return handlePossibleAxiosErrors(async () => {
311
298
  const headers = await getGraphQLAPIHeaders(session);
312
- let agency_id = config.agencyId;
313
- if (config.useProductionAgencyId) {
314
- const { production_agency_id /**{5693: 5696} */ } = await getVariablesByName(headers, session, ["production_agency_id"]);
299
+ // Valores por defecto para config
300
+ const defaultConfig = {
301
+ agencyFilter: true,
302
+ consolidateIdFilter: false,
303
+ useProductionAgencyId: false,
304
+ withShipmentToMyAgency: false,
305
+ withLotStocksToMyAgency: false,
306
+ betweenIssueDate: false,
307
+ withPODetails: true,
308
+ withLots: true,
309
+ withShipmentPurchaseOrders: true,
310
+ withWebAppRows: true,
311
+ payeeCategoryIds: [],
312
+ excludePayeeCategoryIds: [],
313
+ };
314
+ // Combinar config con los valores por defecto
315
+ const finalConfig = { ...defaultConfig, ...config };
316
+ let agency_id = finalConfig.agencyId;
317
+ if (finalConfig.useProductionAgencyId) {
318
+ const { production_agency_id } = await getVariablesByName(headers, session, ["production_agency_id"]);
315
319
  const hashAgencyId = JSON.parse(production_agency_id ?? "{}");
316
320
  agency_id = hashAgencyId[session.get("agency_id")];
317
321
  }
318
322
  const query = getPurchaseOrdersBetweenDatesStringQuery(formatDateToUTC(dates.startDate), formatDateToUTC(dates.endDate), {
319
- agencyId: config.agencyFilter
323
+ agencyId: finalConfig.agencyFilter
320
324
  ? agency_id ?? session.get("agency_id")
321
325
  : undefined,
322
- consolidateIdFilter: config.consolidateIdFilter,
323
- lotItemIdExclusion: config.lotItemIdExclusion,
324
- poDetailTagId: config.poDetailTagId,
325
- withLotStocks: config.withLotStocksToMyAgency,
326
- itemId: config.itemId,
327
- payeeCategoryId: config.payeeCategoryId,
328
- betweenIssueDate: config.betweenIssueDate,
329
- payeeId: config.payeeId,
330
- id_number: config.id_number,
331
- withPODetails: config.withPODetails,
332
- withLots: config.withLots,
333
- withShipmentPurchaseOrders: config.withShipmentPurchaseOrders,
334
- withWebAppRows: config.withWebAppRows,
335
- payeeCategoryIds: config.payeeCategoryIds,
336
- excludePayeeCategoryIds: config.excludePayeeCategoryIds,
326
+ consolidateIdFilter: finalConfig.consolidateIdFilter,
327
+ lotItemIdExclusion: finalConfig.lotItemIdExclusion,
328
+ poDetailTagId: finalConfig.poDetailTagId,
329
+ withLotStocks: finalConfig.withLotStocksToMyAgency,
330
+ itemId: finalConfig.itemId,
331
+ payeeCategoryId: finalConfig.payeeCategoryId,
332
+ betweenIssueDate: finalConfig.betweenIssueDate,
333
+ payeeId: finalConfig.payeeId,
334
+ id_number: finalConfig.id_number,
335
+ withPODetails: finalConfig.withPODetails,
336
+ withLots: finalConfig.withLots,
337
+ withShipmentPurchaseOrders: finalConfig.withShipmentPurchaseOrders,
338
+ withWebAppRows: finalConfig.withWebAppRows,
339
+ payeeCategoryIds: finalConfig.payeeCategoryIds,
340
+ excludePayeeCategoryIds: finalConfig.excludePayeeCategoryIds,
337
341
  });
338
342
  const graphQLBody = {
339
343
  query,
@@ -344,10 +348,10 @@ export const getGraphQLPurchaseOrderBetweenDates = (session, dates, config = {
344
348
  }
345
349
  //============ Aplicación de filtros
346
350
  let responseData = response.data.data.purchase_orders;
347
- if (config.withShipmentToMyAgency) {
351
+ if (finalConfig.withShipmentToMyAgency) {
348
352
  responseData = response.data?.data?.purchase_orders.filter((x) => x.shipment_purchase_orders.some((y) => y.shipment.agency_to_id?.toString() == session.get("agency_id")));
349
353
  }
350
- if (config.withLotStocksToMyAgency) {
354
+ if (finalConfig.withLotStocksToMyAgency && finalConfig.withLots) {
351
355
  responseData = responseData.map((x) => {
352
356
  x.lots = x.lots.map((y) => {
353
357
  y.lot_stocks = y.lot_stocks.filter((z) => z.agency_id == session.get("agency_id"));
@@ -0,0 +1,9 @@
1
+ import { Session } from "@remix-run/node";
2
+ import { AxiosUtilsResponse } from "@zauru-sdk/types";
3
+ /**
4
+ * getGeneralQuery
5
+ * @param headers
6
+ * @param queryKey - clave dinámica para acceder a los datos en la respuesta (ej. 'purchase_orders', 'users')
7
+ * @returns
8
+ */
9
+ export declare const getGeneralQuery: <T>(session: Session, query: string, queryKey: string) => Promise<AxiosUtilsResponse<T[]>>;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from "./common.js";
2
+ export * from "./graphql/index.js";
2
3
  export * from "./sessions/sessions.js";
3
4
  export * from "./sessions/upstash.js";
4
5
  export * from "./zauru/httpGraphQL.js";
@@ -116,7 +116,7 @@ export declare const getPurchaseOrder: (session: Session, poId: string | number,
116
116
  withLotStocksToMyAgency: boolean;
117
117
  }) => Promise<AxiosUtilsResponse<PurchaseOrderGraphQL>>;
118
118
  /**
119
- * getPurchaseOrder
119
+ * getGraphQLPurchaseOrderBetweenDates
120
120
  * @param headers
121
121
  * @returns
122
122
  */
@@ -124,7 +124,7 @@ export declare const getGraphQLPurchaseOrderBetweenDates: (session: Session, dat
124
124
  startDate: string;
125
125
  endDate: string;
126
126
  }, config?: {
127
- agencyFilter: boolean;
127
+ agencyFilter?: boolean;
128
128
  agencyId?: number | string;
129
129
  id_number?: string;
130
130
  useProductionAgencyId?: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zauru-sdk/services",
3
- "version": "1.0.95",
3
+ "version": "1.0.98",
4
4
  "description": "Servicios de consulta a Zauru",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.js",
@@ -25,12 +25,12 @@
25
25
  },
26
26
  "dependencies": {
27
27
  "@remix-run/node": "^2.8.1",
28
- "@zauru-sdk/common": "^1.0.95",
28
+ "@zauru-sdk/common": "^1.0.98",
29
29
  "@zauru-sdk/config": "^1.0.60",
30
30
  "@zauru-sdk/graphql": "^1.0.94",
31
- "@zauru-sdk/types": "^1.0.95",
31
+ "@zauru-sdk/types": "^1.0.98",
32
32
  "axios": "^1.6.7",
33
33
  "chalk": "5.3.0"
34
34
  },
35
- "gitHead": "b9bc25c0b055b244f322740a211facdd0aa8b5ba"
35
+ "gitHead": "e3b92fe4d2aea4be988540f6b233f0a27eb72a40"
36
36
  }