@zauru-sdk/graphql 6.4.0 → 6.6.0

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.
@@ -31,6 +31,13 @@ export declare const getShipmentsStringQuery: ({ agency_to_id, agency_from_id, s
31
31
  endDate: string;
32
32
  };
33
33
  }) => string;
34
+ /**
35
+ * Lightweight lookup of a shipment already linked to a purchase order
36
+ * by reference. Used to reuse an existing booking instead of creating
37
+ * a duplicate when a previous attempt persisted the shipment but not
38
+ * the local apiCall.
39
+ */
40
+ export declare const getBookingByPurchaseOrderAndReferenceStringQuery: (purchaseOrderId: number | string, reference: string) => string;
34
41
  export declare const getLotsByNameStringQuery: (name: string, entity_id: number) => string;
35
42
  export declare const getLotStocksByAgencyIdStringQuery: (agency_id: number) => string;
36
43
  export declare const getSerialsStringQuery: (filters: {
@@ -73,7 +80,18 @@ export declare const getPayeesStringQuery: (filters?: {
73
80
  export declare const getProvidersStringQuery = "\nquery getProviders {\n payees (where: {vendor: {_eq: true}}) {\n id\n id_number\n name\n tin\n address_line_1\n }\n}\n";
74
81
  export declare const getAgenciesStringQuery = "\nquery getAgencies {\n agencies {\n id\n name\n address_line_2\n }\n}\n";
75
82
  export declare const getWebAppRowStringQuery: (id: number) => string;
76
- export declare const getWebAppRowsByWebAppTableIdStringQuery: (webapp_table_id: number, limit?: number) => string;
83
+ export type WebAppRowDataFilterScalar = string | number | boolean | null;
84
+ export type WebAppRowDataFilterValue = WebAppRowDataFilterScalar | WebAppRowDataFilterScalar[];
85
+ export type GetWebAppRowsByTableIdOptions = {
86
+ limit?: number;
87
+ /**
88
+ * JSONB `_contains` filters against `webapp_rows.data`.
89
+ * Multiple keys are AND-ed. An array value becomes an OR of `_contains`.
90
+ */
91
+ data?: Record<string, WebAppRowDataFilterValue>;
92
+ };
93
+ export declare const toGetWebAppRowsByTableIdOptions: (limitOrOptions?: number | GetWebAppRowsByTableIdOptions) => GetWebAppRowsByTableIdOptions;
94
+ export declare const getWebAppRowsByWebAppTableIdStringQuery: (webapp_table_id: number, limitOrOptions?: number | GetWebAppRowsByTableIdOptions) => string;
77
95
  export declare const getPayeeCategoryByIdStringQuery: (id: number) => string;
78
96
  export declare const getPayeeCategoriesByNotesMatchStringQuery: (match: string) => string;
79
97
  export declare const getPayeeCategoriesStringQuery = "\nquery getPayeeCategories {\n payee_categories {\n id\n name\n notes\n payees_count\n price_list_id\n }\n}\n";
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getProductionWorkOrderStringQuery = exports.getPrintTemplatesStringQuery = exports.getCasesStringQuery = exports.getInvoicesByAgencyIdStringQuery = exports.getPaymentTermByIdStringQuery = exports.getPaymentMethodsStringQuery = exports.getPaymentTermsStringQuery = exports.getSuggestedPricesStringQuery = exports.getCurrenciesStringQuery = exports.getInvoiceFormSubmissionsByInvoiceIdStringQuery = exports.getCaseFormSubmissionsByCaseIdStringQuery = exports.getLastInvoiceFormSubmissionStringQuery = exports.getInvoiceFormSubmissionsByAgencyIdStringQuery = exports.getFormSubmissionByIdStringQuery = exports.getMyCaseFormSubmissionsStringQuery = exports.getFormsByDocumentTypeStringQuery = exports.getFormsStringQuery = exports.getFormByNameStringQuery = exports.getAllFormsStringQuery = exports.getItemByNameStringQuery = exports.getBundleByNameStringQuery = exports.getBundlesByItemCategoryIdStringQuery = exports.getEmployeesByAgencyIdStringQuery = exports.getEmployeesStringQuery = exports.getEmployeeProfileStringQuery = exports.getConsolidatesBetweenDatesStringQuery = exports.getItemsBySuperCategoryStringQuery = exports.getItemsStringQuery = exports.getItemsByCategoryStringQuery = exports.getItemCategoryByIdStringQuery = exports.getSuperCategoryByIdStringQuery = exports.getPayeeByIdStringQuery = exports.getClientCategoriesStringQuery = exports.getProviderCategoriesStringQuery = exports.getPayeeCategoriesStringQuery = exports.getPayeeCategoriesByNotesMatchStringQuery = exports.getPayeeCategoryByIdStringQuery = exports.getWebAppRowsByWebAppTableIdStringQuery = exports.getWebAppRowStringQuery = exports.getAgenciesStringQuery = exports.getProvidersStringQuery = exports.getPayeesStringQuery = exports.getPurchaseOrdersBetweenDatesStringQuery = exports.getSerialsStringQuery = exports.getLotStocksByAgencyIdStringQuery = exports.getLotsByNameStringQuery = exports.getShipmentsStringQuery = exports.getPurchaseOrderStringQuery = exports.getPurchaseOrderByIdNumberStringQuery = exports.getLast100ReceptionsStringQuery = void 0;
3
+ exports.getCasesStringQuery = exports.getInvoicesByAgencyIdStringQuery = exports.getPaymentTermByIdStringQuery = exports.getPaymentMethodsStringQuery = exports.getPaymentTermsStringQuery = exports.getSuggestedPricesStringQuery = exports.getCurrenciesStringQuery = exports.getInvoiceFormSubmissionsByInvoiceIdStringQuery = exports.getCaseFormSubmissionsByCaseIdStringQuery = exports.getLastInvoiceFormSubmissionStringQuery = exports.getInvoiceFormSubmissionsByAgencyIdStringQuery = exports.getFormSubmissionByIdStringQuery = exports.getMyCaseFormSubmissionsStringQuery = exports.getFormsByDocumentTypeStringQuery = exports.getFormsStringQuery = exports.getFormByNameStringQuery = exports.getAllFormsStringQuery = exports.getItemByNameStringQuery = exports.getBundleByNameStringQuery = exports.getBundlesByItemCategoryIdStringQuery = exports.getEmployeesByAgencyIdStringQuery = exports.getEmployeesStringQuery = exports.getEmployeeProfileStringQuery = exports.getConsolidatesBetweenDatesStringQuery = exports.getItemsBySuperCategoryStringQuery = exports.getItemsStringQuery = exports.getItemsByCategoryStringQuery = exports.getItemCategoryByIdStringQuery = exports.getSuperCategoryByIdStringQuery = exports.getPayeeByIdStringQuery = exports.getClientCategoriesStringQuery = exports.getProviderCategoriesStringQuery = exports.getPayeeCategoriesStringQuery = exports.getPayeeCategoriesByNotesMatchStringQuery = exports.getPayeeCategoryByIdStringQuery = exports.getWebAppRowsByWebAppTableIdStringQuery = exports.toGetWebAppRowsByTableIdOptions = exports.getWebAppRowStringQuery = exports.getAgenciesStringQuery = exports.getProvidersStringQuery = exports.getPayeesStringQuery = exports.getPurchaseOrdersBetweenDatesStringQuery = exports.getSerialsStringQuery = exports.getLotStocksByAgencyIdStringQuery = exports.getLotsByNameStringQuery = exports.getBookingByPurchaseOrderAndReferenceStringQuery = exports.getShipmentsStringQuery = exports.getPurchaseOrderStringQuery = exports.getPurchaseOrderByIdNumberStringQuery = exports.getLast100ReceptionsStringQuery = void 0;
4
+ exports.getProductionWorkOrderStringQuery = exports.getPrintTemplatesStringQuery = void 0;
4
5
  const getLast100ReceptionsStringQuery = (agency_id) => {
5
6
  const conditions = ["voided: {_eq: false}"];
6
7
  if (agency_id) {
@@ -331,6 +332,42 @@ const getShipmentsStringQuery = ({ agency_to_id, agency_from_id, suffix, voided,
331
332
  }`;
332
333
  };
333
334
  exports.getShipmentsStringQuery = getShipmentsStringQuery;
335
+ /**
336
+ * Lightweight lookup of a shipment already linked to a purchase order
337
+ * by reference. Used to reuse an existing booking instead of creating
338
+ * a duplicate when a previous attempt persisted the shipment but not
339
+ * the local apiCall.
340
+ */
341
+ const getBookingByPurchaseOrderAndReferenceStringQuery = (purchaseOrderId, reference) => {
342
+ const escapedReference = String(reference)
343
+ .replace(/\\/g, "\\\\")
344
+ .replace(/"/g, '\\"');
345
+ return `
346
+ query getBookingByPurchaseOrderAndReference {
347
+ purchase_orders(where: {id: {_eq: ${Number(purchaseOrderId)}}}) {
348
+ shipment_purchase_orders(
349
+ where: {
350
+ shipment: {
351
+ reference: { _eq: "${escapedReference}" }
352
+ voided: { _eq: false }
353
+ returned: { _eq: false }
354
+ }
355
+ }
356
+ limit: 1
357
+ ) {
358
+ shipment {
359
+ id
360
+ reference
361
+ delivered
362
+ voided
363
+ returned
364
+ }
365
+ }
366
+ }
367
+ }
368
+ `;
369
+ };
370
+ exports.getBookingByPurchaseOrderAndReferenceStringQuery = getBookingByPurchaseOrderAndReferenceStringQuery;
334
371
  const getLotsByNameStringQuery = (name, entity_id) => `
335
372
  query getLots {
336
373
  lots (limit: 100, order_by: {id: desc}, where: {entity_id: {_eq: ${entity_id}}, name: {_eq: "${name}"}}) {
@@ -639,15 +676,73 @@ query getWebAppRow {
639
676
  }
640
677
  `;
641
678
  exports.getWebAppRowStringQuery = getWebAppRowStringQuery;
642
- const getWebAppRowsByWebAppTableIdStringQuery = (webapp_table_id, limit) => {
679
+ const GRAPHQL_NAME_RE = /^[A-Za-z_][A-Za-z0-9_]*$/;
680
+ const toGetWebAppRowsByTableIdOptions = (limitOrOptions) => {
681
+ if (typeof limitOrOptions === "number") {
682
+ return { limit: limitOrOptions };
683
+ }
684
+ return limitOrOptions ?? {};
685
+ };
686
+ exports.toGetWebAppRowsByTableIdOptions = toGetWebAppRowsByTableIdOptions;
687
+ const serializeGraphQLLiteral = (value) => {
688
+ if (value === null) {
689
+ return "null";
690
+ }
691
+ if (typeof value === "boolean") {
692
+ return value ? "true" : "false";
693
+ }
694
+ if (typeof value === "number") {
695
+ if (!Number.isFinite(value)) {
696
+ throw new Error("Invalid numeric GraphQL literal");
697
+ }
698
+ return String(value);
699
+ }
700
+ return JSON.stringify(value);
701
+ };
702
+ const buildDataContainsClause = (key, value) => {
703
+ if (!GRAPHQL_NAME_RE.test(key)) {
704
+ throw new Error(`Invalid webapp row data filter key: ${key}`);
705
+ }
706
+ return `{ data: { _contains: { ${key}: ${serializeGraphQLLiteral(value)} } } }`;
707
+ };
708
+ const buildDataFilterAndClauses = (data) => {
709
+ if (!data) {
710
+ return [];
711
+ }
712
+ const andParts = [];
713
+ for (const [key, raw] of Object.entries(data)) {
714
+ if (raw === undefined) {
715
+ continue;
716
+ }
717
+ const values = Array.isArray(raw) ? raw : [raw];
718
+ if (values.length === 0) {
719
+ continue;
720
+ }
721
+ const orParts = values.map((value) => buildDataContainsClause(key, value));
722
+ if (orParts.length === 1) {
723
+ andParts.push(orParts[0]);
724
+ }
725
+ else {
726
+ andParts.push(`{ _or: [${orParts.join(", ")}] }`);
727
+ }
728
+ }
729
+ return andParts;
730
+ };
731
+ const getWebAppRowsByWebAppTableIdStringQuery = (webapp_table_id, limitOrOptions) => {
732
+ const options = (0, exports.toGetWebAppRowsByTableIdOptions)(limitOrOptions);
733
+ const tableId = Number(webapp_table_id);
643
734
  const conditions = [];
644
- if (webapp_table_id) {
645
- conditions.push(`webapp_table_id: {_eq: ${webapp_table_id}}`);
735
+ if (tableId) {
736
+ conditions.push(`webapp_table_id: {_eq: ${tableId}}`);
737
+ }
738
+ const dataAnd = buildDataFilterAndClauses(options.data);
739
+ if (dataAnd.length > 0) {
740
+ conditions.push(`_and: [${dataAnd.join(", ")}]`);
646
741
  }
647
742
  const whereClause = conditions.length
648
743
  ? `where: { ${conditions.join(", ")} }`
649
744
  : "";
650
- const limitClause = limit ? `limit: ${limit}` : "";
745
+ const limitClause = options.limit ? `limit: ${Number(options.limit)}` : "";
651
746
  const orderByClause = `order_by: { id: desc }`;
652
747
  return `
653
748
  query getWebAppRowsByWebAppTableId {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zauru-sdk/graphql",
3
- "version": "6.4.0",
3
+ "version": "6.6.0",
4
4
  "description": "Queries de uso común para las aplicación de Zauru.",
5
5
  "main": "./dist/esm/index.js",
6
6
  "module": "./dist/esm/index.js",
@@ -22,5 +22,5 @@
22
22
  "devDependencies": {
23
23
  "typescript": "^5.1.6"
24
24
  },
25
- "gitHead": "65139162e998fda40e90035321542c4b881d2aed"
25
+ "gitHead": "e32a0a82d185dbd8feb512c2252e458b415edc95"
26
26
  }