@zauru-sdk/services 1.0.69 → 1.0.72

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.
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getVariablesByName = exports.generateDistinctCode = exports.deleteSessionMessage = exports.saveSessionMessage = exports.getGraphQLAPIHeaders = exports.getHeaders = exports.loginWebApp = void 0;
6
+ exports.actualizarVariables = exports.getVariablesSchemaByName = exports.getVariablesByName = exports.generateDistinctCode = exports.deleteSessionMessage = exports.saveSessionMessage = exports.getGraphQLAPIHeaders = exports.getHeaders = exports.loginWebApp = void 0;
7
7
  const node_1 = require("@remix-run/node");
8
8
  const sessions_js_1 = require("./sessions/sessions.js");
9
9
  const chalk_1 = __importDefault(require("chalk"));
@@ -233,3 +233,45 @@ async function getVariablesByName(headers, session, names) {
233
233
  return returnObject;
234
234
  }
235
235
  exports.getVariablesByName = getVariablesByName;
236
+ async function getVariablesSchemaByName(headers, session, names) {
237
+ //variables
238
+ let variables = [];
239
+ //consulto si ya están guardadas en la sesión
240
+ const tempVars = session.get("variables");
241
+ if (Array.isArray(tempVars) && tempVars.length) {
242
+ //si ya están guardadas, uso esas
243
+ variables = tempVars;
244
+ }
245
+ else {
246
+ //si no están en la sesión, las obtengo de zauru y luego las guardo en la sesión
247
+ //Obtengo mis variables, para tener los tags solicitados
248
+ const response = await (0, zauru_variables_js_1.getVariables)(headers);
249
+ if (response.error) {
250
+ throw new Error(`${response.userMsg} - ${response.msg}`);
251
+ }
252
+ session.set("variables", response.data);
253
+ await (0, sessions_js_1.commitSession)(session);
254
+ variables = response.data ?? [];
255
+ }
256
+ const filtrados = variables.filter((value) => names.includes(value.name));
257
+ return filtrados;
258
+ }
259
+ exports.getVariablesSchemaByName = getVariablesSchemaByName;
260
+ /**
261
+ * Actualiza las variables en la sesión.
262
+ * @param {any} headers - Headers necesarios para la consulta.
263
+ * @param {Session} session - La sesión actual.
264
+ * @returns {Promise<void>}
265
+ */
266
+ async function actualizarVariables(headers, session) {
267
+ // Intentamos obtener las variables desde el servidor
268
+ const response = await (0, zauru_variables_js_1.getVariables)(headers);
269
+ if (response.error) {
270
+ throw new Error(`${response.userMsg} - ${response.msg}`);
271
+ }
272
+ // Guardamos las variables en la sesión
273
+ session.set("variables", response.data);
274
+ await (0, sessions_js_1.commitSession)(session);
275
+ console.log("Variables actualizadas y sesión refrescada.");
276
+ }
277
+ exports.actualizarVariables = actualizarVariables;
@@ -161,6 +161,7 @@ async function getInvoiceFormSubmissionsByAgencyId(session, agency_id, filters)
161
161
  item_ids: filters?.item_ids,
162
162
  startDate: filters?.startDate,
163
163
  endDate: filters?.endDate,
164
+ formZid: filters?.formZid,
164
165
  });
165
166
  const response = await httpGraphQL_js_1.default.post("", {
166
167
  query: queryBuilded,
@@ -0,0 +1,27 @@
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.getPrintTemplates = void 0;
7
+ const common_1 = require("@zauru-sdk/common");
8
+ const httpGraphQL_js_1 = __importDefault(require("./httpGraphQL.js"));
9
+ const common_js_1 = require("../common.js");
10
+ const graphql_1 = require("@zauru-sdk/graphql");
11
+ /**
12
+ * getPayees
13
+ * @param headers
14
+ * @returns
15
+ */
16
+ async function getPrintTemplates(session) {
17
+ return (0, common_1.handlePossibleAxiosErrors)(async () => {
18
+ const headers = await (0, common_js_1.getGraphQLAPIHeaders)(session);
19
+ const response = await httpGraphQL_js_1.default.post(``, {
20
+ query: graphql_1.getPrintTemplatesStringQuery,
21
+ }, {
22
+ headers,
23
+ });
24
+ return response.data?.data.print_templates;
25
+ });
26
+ }
27
+ exports.getPrintTemplates = getPrintTemplates;
@@ -3,9 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.createVariable = exports.getVariables = void 0;
6
+ exports.updateVariable = exports.createVariable = exports.getVariables = void 0;
7
7
  const chalk_1 = __importDefault(require("chalk"));
8
8
  const httpZauru_js_1 = __importDefault(require("./httpZauru.js"));
9
+ const common_1 = require("@zauru-sdk/common");
9
10
  /**
10
11
  * getVariables Function for get all zauru variables
11
12
  * @param headers
@@ -54,3 +55,10 @@ async function createVariable(headers, body) {
54
55
  }
55
56
  }
56
57
  exports.createVariable = createVariable;
58
+ const updateVariable = async (headers, body) => {
59
+ return (0, common_1.handlePossibleAxiosErrors)(async () => {
60
+ await httpZauru_js_1.default.patch(`/apps/webapp_vars/${body.id}.json`, { variable: body }, { headers });
61
+ return true;
62
+ });
63
+ };
64
+ exports.updateVariable = updateVariable;
package/dist/common.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Session } from "@remix-run/node";
2
2
  import { AxiosRequestHeaders } from "axios";
3
- import { EmployeeGraphQL, OauthProfile, ProfileResponse, AgencyGraphQL, AxiosUtilsResponse } from "@zauru-sdk/types";
3
+ import { EmployeeGraphQL, OauthProfile, ProfileResponse, AgencyGraphQL, VariableGraphQL, AxiosUtilsResponse } from "@zauru-sdk/types";
4
4
  /**
5
5
  * loginWebApp
6
6
  * @param session
@@ -53,3 +53,11 @@ export declare function generateDistinctCode(prefix: string): string;
53
53
  export declare function getVariablesByName(headers: any, session: Session, names: Array<string>): Promise<{
54
54
  [key: string]: string;
55
55
  }>;
56
+ export declare function getVariablesSchemaByName(headers: any, session: Session, names: Array<string>): Promise<VariableGraphQL[]>;
57
+ /**
58
+ * Actualiza las variables en la sesión.
59
+ * @param {any} headers - Headers necesarios para la consulta.
60
+ * @param {Session} session - La sesión actual.
61
+ * @returns {Promise<void>}
62
+ */
63
+ export declare function actualizarVariables(headers: any, session: Session): Promise<void>;
@@ -220,3 +220,43 @@ export async function getVariablesByName(headers, session, names) {
220
220
  }
221
221
  return returnObject;
222
222
  }
223
+ export async function getVariablesSchemaByName(headers, session, names) {
224
+ //variables
225
+ let variables = [];
226
+ //consulto si ya están guardadas en la sesión
227
+ const tempVars = session.get("variables");
228
+ if (Array.isArray(tempVars) && tempVars.length) {
229
+ //si ya están guardadas, uso esas
230
+ variables = tempVars;
231
+ }
232
+ else {
233
+ //si no están en la sesión, las obtengo de zauru y luego las guardo en la sesión
234
+ //Obtengo mis variables, para tener los tags solicitados
235
+ const response = await getVariables(headers);
236
+ if (response.error) {
237
+ throw new Error(`${response.userMsg} - ${response.msg}`);
238
+ }
239
+ session.set("variables", response.data);
240
+ await commitSession(session);
241
+ variables = response.data ?? [];
242
+ }
243
+ const filtrados = variables.filter((value) => names.includes(value.name));
244
+ return filtrados;
245
+ }
246
+ /**
247
+ * Actualiza las variables en la sesión.
248
+ * @param {any} headers - Headers necesarios para la consulta.
249
+ * @param {Session} session - La sesión actual.
250
+ * @returns {Promise<void>}
251
+ */
252
+ export async function actualizarVariables(headers, session) {
253
+ // Intentamos obtener las variables desde el servidor
254
+ const response = await getVariables(headers);
255
+ if (response.error) {
256
+ throw new Error(`${response.userMsg} - ${response.msg}`);
257
+ }
258
+ // Guardamos las variables en la sesión
259
+ session.set("variables", response.data);
260
+ await commitSession(session);
261
+ console.log("Variables actualizadas y sesión refrescada.");
262
+ }
@@ -150,6 +150,7 @@ export async function getInvoiceFormSubmissionsByAgencyId(session, agency_id, fi
150
150
  item_ids: filters?.item_ids,
151
151
  startDate: filters?.startDate,
152
152
  endDate: filters?.endDate,
153
+ formZid: filters?.formZid,
153
154
  });
154
155
  const response = await httpGraphQLAPI.post("", {
155
156
  query: queryBuilded,
@@ -0,0 +1,20 @@
1
+ import { handlePossibleAxiosErrors } from "@zauru-sdk/common";
2
+ import httpGraphQLAPI from "./httpGraphQL.js";
3
+ import { getGraphQLAPIHeaders } from "../common.js";
4
+ import { getPrintTemplatesStringQuery } from "@zauru-sdk/graphql";
5
+ /**
6
+ * getPayees
7
+ * @param headers
8
+ * @returns
9
+ */
10
+ export async function getPrintTemplates(session) {
11
+ return handlePossibleAxiosErrors(async () => {
12
+ const headers = await getGraphQLAPIHeaders(session);
13
+ const response = await httpGraphQLAPI.post(``, {
14
+ query: getPrintTemplatesStringQuery,
15
+ }, {
16
+ headers,
17
+ });
18
+ return response.data?.data.print_templates;
19
+ });
20
+ }
@@ -1,5 +1,6 @@
1
1
  import chalk from "chalk";
2
2
  import httpZauru from "./httpZauru.js";
3
+ import { handlePossibleAxiosErrors } from "@zauru-sdk/common";
3
4
  /**
4
5
  * getVariables Function for get all zauru variables
5
6
  * @param headers
@@ -46,3 +47,9 @@ export async function createVariable(headers, body) {
46
47
  };
47
48
  }
48
49
  }
50
+ export const updateVariable = async (headers, body) => {
51
+ return handlePossibleAxiosErrors(async () => {
52
+ await httpZauru.patch(`/apps/webapp_vars/${body.id}.json`, { variable: body }, { headers });
53
+ return true;
54
+ });
55
+ };
@@ -37,6 +37,7 @@ export declare function getInvoiceFormSubmissionsByAgencyId(session: Session, ag
37
37
  some_field_value?: string;
38
38
  item_ids?: number[];
39
39
  bundle_ids?: number[];
40
+ formZid?: number | string;
40
41
  }): Promise<AxiosUtilsResponse<SubmissionInvoicesGraphQL[]>>;
41
42
  /**
42
43
  * getMyCaseFormSubmissions
@@ -0,0 +1,8 @@
1
+ import type { Session } from "@remix-run/node";
2
+ import { AxiosUtilsResponse, PrintTemplateGraphQL } from "@zauru-sdk/types";
3
+ /**
4
+ * getPayees
5
+ * @param headers
6
+ * @returns
7
+ */
8
+ export declare function getPrintTemplates(session: Session): Promise<AxiosUtilsResponse<PrintTemplateGraphQL[]>>;
@@ -12,3 +12,4 @@ export declare function getVariables(headers: any): Promise<AxiosUtilsResponse<V
12
12
  * @returns
13
13
  */
14
14
  export declare function createVariable(headers: any, body: Partial<VariableGraphQL>): Promise<AxiosUtilsResponse<VariableGraphQL>>;
15
+ export declare const updateVariable: (headers: any, body: Partial<VariableGraphQL>) => Promise<AxiosUtilsResponse<boolean>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zauru-sdk/services",
3
- "version": "1.0.69",
3
+ "version": "1.0.72",
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.69",
28
+ "@zauru-sdk/common": "^1.0.72",
29
29
  "@zauru-sdk/config": "^1.0.60",
30
- "@zauru-sdk/graphql": "^1.0.69",
31
- "@zauru-sdk/types": "^1.0.69",
30
+ "@zauru-sdk/graphql": "^1.0.72",
31
+ "@zauru-sdk/types": "^1.0.72",
32
32
  "axios": "^1.6.7",
33
33
  "chalk": "5.3.0"
34
34
  },
35
- "gitHead": "46dd382e956e8b34c2a65ef078d8fddb2cdd434c"
35
+ "gitHead": "ac02d7a25f80e844c4c16971fd7c3df76be5c2f3"
36
36
  }