@zauru-sdk/services 1.0.32 → 1.0.44

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.
Files changed (107) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/common.d.ts +55 -0
  3. package/dist/common.js +222 -0
  4. package/dist/index.d.ts +34 -34
  5. package/dist/index.js +34 -34
  6. package/dist/sessions/sessions.d.ts +2 -0
  7. package/dist/sessions/sessions.js +13 -0
  8. package/dist/sessions/upstash.d.ts +1 -0
  9. package/dist/sessions/upstash.js +52 -0
  10. package/dist/zauru/httpGraphQL.d.ts +2 -0
  11. package/dist/zauru/httpGraphQL.js +37 -0
  12. package/dist/zauru/httpOauth.d.ts +2 -0
  13. package/dist/zauru/httpOauth.js +37 -0
  14. package/dist/zauru/httpZauru.d.ts +2 -0
  15. package/dist/zauru/httpZauru.js +37 -0
  16. package/dist/zauru/zauru-agencies.d.ts +8 -0
  17. package/dist/zauru/zauru-agencies.js +20 -0
  18. package/dist/zauru/zauru-automatic-numbers.d.ts +8 -0
  19. package/dist/zauru/zauru-automatic-numbers.js +21 -0
  20. package/dist/zauru/zauru-bookings.d.ts +28 -0
  21. package/dist/zauru/zauru-bookings.js +80 -0
  22. package/dist/zauru/zauru-bundles.d.ts +28 -0
  23. package/dist/zauru/zauru-bundles.js +93 -0
  24. package/dist/zauru/zauru-cases.d.ts +6 -0
  25. package/dist/zauru/zauru-cases.js +23 -0
  26. package/dist/zauru/zauru-consolidated.d.ts +36 -0
  27. package/dist/zauru/zauru-consolidated.js +71 -0
  28. package/dist/zauru/zauru-currencies.d.ts +6 -0
  29. package/dist/zauru/zauru-currencies.js +20 -0
  30. package/dist/zauru/zauru-deliveries.d.ts +22 -0
  31. package/dist/zauru/zauru-deliveries.js +44 -0
  32. package/dist/zauru/zauru-discharges.d.ts +26 -0
  33. package/dist/zauru/zauru-discharges.js +46 -0
  34. package/dist/zauru/zauru-employees.d.ts +6 -0
  35. package/dist/zauru/zauru-employees.js +23 -0
  36. package/dist/zauru/zauru-forms.d.ts +96 -0
  37. package/dist/zauru/zauru-forms.js +343 -0
  38. package/dist/zauru/zauru-invoices.d.ts +26 -0
  39. package/dist/zauru/zauru-invoices.js +94 -0
  40. package/dist/zauru/zauru-items.d.ts +97 -0
  41. package/dist/zauru/zauru-items.js +272 -0
  42. package/dist/zauru/zauru-lote-record.d.ts +8 -0
  43. package/dist/zauru/zauru-lote-record.js +26 -0
  44. package/dist/zauru/zauru-lotes.d.ts +111 -0
  45. package/dist/zauru/zauru-lotes.js +294 -0
  46. package/dist/zauru/zauru-motivos-rechazo.d.ts +9 -0
  47. package/dist/zauru/zauru-motivos-rechazo.js +49 -0
  48. package/dist/zauru/zauru-payees.d.ts +97 -0
  49. package/dist/zauru/zauru-payees.js +227 -0
  50. package/dist/zauru/zauru-payment-terms.d.ts +20 -0
  51. package/dist/zauru/zauru-payment-terms.js +65 -0
  52. package/dist/zauru/zauru-price-lists.d.ts +22 -0
  53. package/dist/zauru/zauru-price-lists.js +40 -0
  54. package/dist/zauru/zauru-profiles.d.ts +28 -0
  55. package/dist/zauru/zauru-profiles.js +69 -0
  56. package/dist/zauru/zauru-purchase-orders.d.ts +160 -0
  57. package/dist/zauru/zauru-purchase-orders.js +414 -0
  58. package/dist/zauru/zauru-receptions.d.ts +33 -0
  59. package/dist/zauru/zauru-receptions.js +94 -0
  60. package/dist/zauru/zauru-shipments.d.ts +20 -0
  61. package/dist/zauru/zauru-shipments.js +53 -0
  62. package/dist/zauru/zauru-suggested-prices.d.ts +31 -0
  63. package/dist/zauru/zauru-suggested-prices.js +84 -0
  64. package/dist/zauru/zauru-tags.d.ts +7 -0
  65. package/dist/zauru/zauru-tags.js +13 -0
  66. package/dist/zauru/zauru-templates.d.ts +7 -0
  67. package/dist/zauru/zauru-templates.js +15 -0
  68. package/dist/zauru/zauru-variables.d.ts +14 -0
  69. package/dist/zauru/zauru-variables.js +48 -0
  70. package/dist/zauru/zauru-web-app-tables.d.ts +55 -0
  71. package/dist/zauru/zauru-web-app-tables.js +154 -0
  72. package/package.json +5 -5
  73. package/src/{common.server.ts → common.ts} +4 -4
  74. package/src/index.ts +34 -34
  75. package/src/sessions/{sessions.server.ts → sessions.ts} +1 -1
  76. package/src/zauru/{zauru-agencies.server.ts → zauru-agencies.ts} +2 -2
  77. package/src/zauru/{zauru-automatic-numbers.server.ts → zauru-automatic-numbers.ts} +1 -1
  78. package/src/zauru/{zauru-bookings.server.ts → zauru-bookings.ts} +3 -3
  79. package/src/zauru/{zauru-bundles.server.ts → zauru-bundles.ts} +3 -3
  80. package/src/zauru/{zauru-cases.server.ts → zauru-cases.ts} +2 -2
  81. package/src/zauru/{zauru-consolidated.server.ts → zauru-consolidated.ts} +3 -3
  82. package/src/zauru/{zauru-currencies.server.ts → zauru-currencies.ts} +2 -2
  83. package/src/zauru/{zauru-deliveries.server.ts → zauru-deliveries.ts} +1 -1
  84. package/src/zauru/{zauru-discharges.server.ts → zauru-discharges.ts} +2 -2
  85. package/src/zauru/{zauru-employees.server.ts → zauru-employees.ts} +2 -2
  86. package/src/zauru/{zauru-forms.server.ts → zauru-forms.ts} +3 -3
  87. package/src/zauru/{zauru-invoices.server.ts → zauru-invoices.ts} +3 -3
  88. package/src/zauru/{zauru-items.server.ts → zauru-items.ts} +3 -3
  89. package/src/zauru/{zauru-lote-record.server.ts → zauru-lote-record.ts} +2 -2
  90. package/src/zauru/{zauru-lotes.server.ts → zauru-lotes.ts} +5 -5
  91. package/src/zauru/{zauru-motivos-rechazo.server.ts → zauru-motivos-rechazo.ts} +2 -2
  92. package/src/zauru/{zauru-payees.server.ts → zauru-payees.ts} +3 -3
  93. package/src/zauru/{zauru-payment-terms.server.ts → zauru-payment-terms.ts} +3 -3
  94. package/src/zauru/{zauru-price-lists.server.ts → zauru-price-lists.ts} +1 -1
  95. package/src/zauru/{zauru-profiles.server.ts → zauru-profiles.ts} +2 -2
  96. package/src/zauru/{zauru-purchase-orders.server.ts → zauru-purchase-orders.ts} +4 -4
  97. package/src/zauru/{zauru-receptions.server.ts → zauru-receptions.ts} +1 -1
  98. package/src/zauru/{zauru-shipments.server.ts → zauru-shipments.ts} +3 -3
  99. package/src/zauru/{zauru-suggested-prices.server.ts → zauru-suggested-prices.ts} +3 -3
  100. package/src/zauru/{zauru-tags.server.ts → zauru-tags.ts} +1 -1
  101. package/src/zauru/{zauru-templates.server.ts → zauru-templates.ts} +1 -1
  102. package/src/zauru/{zauru-variables.server.ts → zauru-variables.ts} +1 -1
  103. package/src/zauru/{zauru-web-app-tables.server.ts → zauru-web-app-tables.ts} +3 -3
  104. /package/src/sessions/{upstash.server.ts → upstash.ts} +0 -0
  105. /package/src/zauru/{httpGraphQL.server.ts → httpGraphQL.ts} +0 -0
  106. /package/src/zauru/{httpOauth.server.ts → httpOauth.ts} +0 -0
  107. /package/src/zauru/{httpZauru.server.ts → httpZauru.ts} +0 -0
package/CHANGELOG.md CHANGED
@@ -3,6 +3,22 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [1.0.44](https://github.com/intuitiva/zauru-typescript-sdk/compare/v1.0.43...v1.0.44) (2024-04-01)
7
+
8
+ **Note:** Version bump only for package @zauru-sdk/services
9
+
10
+
11
+
12
+
13
+
14
+ ## [1.0.33](https://github.com/intuitiva/zauru-typescript-sdk/compare/v1.0.32...v1.0.33) (2024-03-25)
15
+
16
+ **Note:** Version bump only for package @zauru-sdk/services
17
+
18
+
19
+
20
+
21
+
6
22
  ## [1.0.32](https://github.com/intuitiva/zauru-typescript-sdk/compare/v1.0.31...v1.0.32) (2024-03-25)
7
23
 
8
24
  **Note:** Version bump only for package @zauru-sdk/services
@@ -0,0 +1,55 @@
1
+ import { Session } from "@remix-run/node";
2
+ import { AxiosRequestHeaders } from "axios";
3
+ import { EmployeeGraphQL, OauthProfile, ProfileResponse, AgencyGraphQL, AxiosUtilsResponse } from "@zauru-sdk/types";
4
+ /**
5
+ * loginWebApp
6
+ * @param session
7
+ * @param codeValue
8
+ * @param cookie
9
+ * @returns
10
+ */
11
+ export declare const loginWebApp: (session: Session, codeValue: string, cookie: string) => Promise<AxiosUtilsResponse<{
12
+ headers: any;
13
+ oauthProfile: OauthProfile;
14
+ employeeProfile: EmployeeGraphQL;
15
+ userProfile: ProfileResponse;
16
+ agencyProfile: AgencyGraphQL;
17
+ }>>;
18
+ /**
19
+ * Obtiene los headers que se usan en todos los endpoints de zauru
20
+ * @param cookie
21
+ * @param _session La session es opcional, se envía sólo si ya se tiene a la mano, para ya no volverla a consultar.
22
+ * @returns
23
+ */
24
+ export declare const getHeaders: (cookie: string | null, _session?: Session | null, config?: {
25
+ token: string;
26
+ username: string;
27
+ } | null, extraConfig?: {
28
+ withOutContentType: string;
29
+ }) => Promise<{
30
+ [key: string]: string;
31
+ }>;
32
+ /**
33
+ * getGraphQLAPIHeaders
34
+ * @param session
35
+ * @returns
36
+ */
37
+ export declare const getGraphQLAPIHeaders: (session: Session) => Promise<AxiosRequestHeaders>;
38
+ export type SessionMessage = {
39
+ id: string;
40
+ title: string;
41
+ message: string;
42
+ };
43
+ export declare const saveSessionMessage: (session: Session, info: SessionMessage) => Promise<void>;
44
+ export declare const deleteSessionMessage: (session: Session, id: string) => Promise<boolean>;
45
+ export declare function generateDistinctCode(prefix: string): string;
46
+ /**
47
+ *
48
+ * @param headers
49
+ * @param session
50
+ * @param names
51
+ * @returns
52
+ */
53
+ export declare function getVariablesByName(headers: any, session: Session, names: Array<string>): Promise<{
54
+ [key: string]: string;
55
+ }>;
package/dist/common.js ADDED
@@ -0,0 +1,222 @@
1
+ import { redirect } from "@remix-run/node";
2
+ import { commitSession, getSession } from "./sessions/sessions.js";
3
+ import chalk from "chalk";
4
+ import httpZauru from "./zauru/httpZauru.js";
5
+ import { getAgencyInfo, getEmployeeInfo, getOauthUserInfo, getProfileInformation, } from "./zauru/zauru-profiles.js";
6
+ import { handlePossibleAxiosErrors } from "@zauru-sdk/common";
7
+ import { getVariables } from "./zauru/zauru-variables.js";
8
+ /**
9
+ * loginWebApp
10
+ * @param session
11
+ * @param codeValue
12
+ * @param cookie
13
+ * @returns
14
+ */
15
+ export const loginWebApp = async (session, codeValue, cookie) => {
16
+ return handlePossibleAxiosErrors(async () => {
17
+ const userInfoResponse = await getOauthUserInfo(codeValue ?? "");
18
+ if (userInfoResponse.error) {
19
+ throw new Error(userInfoResponse.userMsg);
20
+ }
21
+ const userInfo = userInfoResponse.data;
22
+ session.set("username", userInfo?.username);
23
+ session.set("token", userInfo?.api_key);
24
+ session.set("code", codeValue);
25
+ session.set("name", userInfo?.name);
26
+ session.set("email", userInfo?.email);
27
+ session.set("employee_id", userInfo?.employee_id);
28
+ const headers = await getHeaders(cookie, session, {
29
+ token: userInfo?.api_key ?? "",
30
+ username: userInfo?.username ?? "",
31
+ });
32
+ const res_emp = await getEmployeeInfo(userInfo?.employee_id ?? 0, headers);
33
+ if (res_emp.error) {
34
+ throw new Error(res_emp.userMsg);
35
+ }
36
+ const empInfo = res_emp.data;
37
+ session.set("agency_id", empInfo?.agency_id);
38
+ session.set("email", empInfo?.email);
39
+ session.set("selectedEntity", empInfo?.entity_id);
40
+ const profileInfoResponse = await getProfileInformation(headers);
41
+ if (profileInfoResponse.error) {
42
+ throw new Error(profileInfoResponse.userMsg);
43
+ }
44
+ const profileInfo = profileInfoResponse.data;
45
+ if (!profileInfo?.memberships?.length) {
46
+ throw new Error("El usuario no tiene suscripciones...");
47
+ }
48
+ const membership = profileInfo?.memberships?.filter((member) => member?.entity?.id === empInfo?.entity_id);
49
+ if (!membership) {
50
+ throw new Error("No se encontró una suscripción para este usuario en la entidad asignada.");
51
+ }
52
+ if (membership?.length)
53
+ session.set("entityName", membership[0]?.entity?.name);
54
+ const agencyInfoResponse = await getAgencyInfo(headers, session);
55
+ if (agencyInfoResponse.error) {
56
+ throw new Error(agencyInfoResponse.userMsg);
57
+ }
58
+ session.set("agency_name", agencyInfoResponse.data?.name);
59
+ return {
60
+ headers,
61
+ oauthProfile: userInfo,
62
+ employeeProfile: empInfo,
63
+ userProfile: profileInfo,
64
+ agencyProfile: agencyInfoResponse.data,
65
+ };
66
+ });
67
+ };
68
+ /**
69
+ * Obtiene los headers que se usan en todos los endpoints de zauru
70
+ * @param cookie
71
+ * @param _session La session es opcional, se envía sólo si ya se tiene a la mano, para ya no volverla a consultar.
72
+ * @returns
73
+ */
74
+ export const getHeaders = async (cookie, _session, config, extraConfig) => {
75
+ // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>Session and Header Info<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
76
+ const session = _session ?? (await getSession(cookie));
77
+ if (!session.has("username") && !config) {
78
+ redirect("/");
79
+ return {};
80
+ }
81
+ const headers = {
82
+ "X-User-Email": config?.username ?? session.get("username"),
83
+ "X-User-Token": config?.token ?? session.get("token"),
84
+ "Content-type": "application/json",
85
+ Accept: "application/json",
86
+ };
87
+ if (extraConfig?.withOutContentType) {
88
+ delete headers["Content-type"];
89
+ }
90
+ return headers;
91
+ };
92
+ /**
93
+ * getGraphQLToken
94
+ * @param session
95
+ * @returns
96
+ */
97
+ async function getGraphQLToken(session) {
98
+ return handlePossibleAxiosErrors(async () => {
99
+ const token = (await session.get("graphqlToken"));
100
+ const headers = (await getHeaders(null, session));
101
+ const tokenHasExpired = token &&
102
+ token.expires &&
103
+ new Date(new Date().getTime() - 3 * 60 * 60 * 1000) >=
104
+ new Date(token.expires);
105
+ //Si no hay token, es la primera vez que se recibe, lo voy a traer de zauru
106
+ if (!token || tokenHasExpired) {
107
+ tokenHasExpired
108
+ ? console.log(chalk.yellow(`=============== ⚠️ EL TOKEN GRAPHQL ESTÁ EXPIRADO ⚠️ ====================`))
109
+ : console.log(chalk.yellow(`=============== ⚠️ NO HAY UN TOKEN GRAPHQL GUARDADO ⚠️ ====================`));
110
+ const responseToken = await httpZauru.get("/apps/graphql.json", {
111
+ headers,
112
+ });
113
+ if (responseToken.data) {
114
+ session.set("graphqlToken", responseToken.data);
115
+ await commitSession(session);
116
+ console.log(chalk.green(`=============== ✅ TOKEN GRAPHQL GUARDADO EN SESION Y DEVUELTO ✅ ====================`));
117
+ return responseToken.data;
118
+ }
119
+ console.log(chalk.red(`=============== ❗ NO HAY INFORMACIÓN OBTENIDA DEL REQUEST A ZAURU - GET_TOKEN ❗ ====================`));
120
+ throw new Error("No viene información en la solicitud de getGraphQLToken a Zauru");
121
+ }
122
+ //Si ya está guardado un token en la sesión y aún no a expirado.
123
+ return token;
124
+ });
125
+ }
126
+ /**
127
+ * getGraphQLAPIHeaders
128
+ * @param session
129
+ * @returns
130
+ */
131
+ export const getGraphQLAPIHeaders = async (session) => {
132
+ const { data: token, error, userMsg } = await getGraphQLToken(session);
133
+ if (error) {
134
+ console.log(chalk.red(`=============== ❗ OCURRIÓ UN ERROR DEL REQUEST A ZAURU - GET_TOKEN ❗ ==================== ${userMsg}`));
135
+ return {
136
+ Authorization: `Bearer token_no_existe`,
137
+ "Content-Type": "application/json",
138
+ };
139
+ }
140
+ return {
141
+ Authorization: `Bearer ${token?.token}`,
142
+ "Content-Type": "application/json",
143
+ };
144
+ };
145
+ export const saveSessionMessage = async (session, info) => {
146
+ const updateTasks = (session.get("sessionMessages") ??
147
+ []);
148
+ session.set("updateTasks", [...updateTasks, info]);
149
+ await commitSession(session);
150
+ };
151
+ export const deleteSessionMessage = async (session, id) => {
152
+ let updateTasks = session.get("sessionMessages");
153
+ if (Array.isArray(updateTasks) &&
154
+ updateTasks.some((task) => task.id === id)) {
155
+ //La elimino de la lista
156
+ updateTasks = updateTasks.filter((task) => task.id !== id);
157
+ session.set("sessionMessages", updateTasks);
158
+ await commitSession(session);
159
+ return true;
160
+ }
161
+ return false;
162
+ };
163
+ function generarUUID() {
164
+ // Retorna un arreglo de 9 bytes con valores aleatorios
165
+ const array = new Uint8Array(9);
166
+ crypto.getRandomValues(array);
167
+ // Convertir Uint8Array a array normal
168
+ const normalArray = Array.from(array);
169
+ // Codificación en base 64
170
+ const base64 = btoa(String.fromCharCode.apply(null, normalArray))
171
+ .replace("+", "0") // Reemplaza caracteres no alfanuméricos
172
+ .replace("/", "1")
173
+ .substring(0, 11); // Acorta a 11 caracteres
174
+ return base64;
175
+ }
176
+ // Función para generar un código de producto a partir de un UUID
177
+ export function generateDistinctCode(prefix) {
178
+ const uuid = generarUUID();
179
+ const codigoProducto = `${prefix}-${uuid}`;
180
+ return codigoProducto;
181
+ }
182
+ /**
183
+ *
184
+ * @param headers
185
+ * @param session
186
+ * @param names
187
+ * @returns
188
+ */
189
+ export async function getVariablesByName(headers, session, names) {
190
+ //variables
191
+ let variables = [];
192
+ //consulto si ya están guardadas en la sesión
193
+ const tempVars = session.get("variables");
194
+ if (Array.isArray(tempVars) && tempVars.length) {
195
+ //si ya están guardadas, uso esas
196
+ variables = tempVars;
197
+ }
198
+ else {
199
+ //si no están en la sesión, las obtengo de zauru y luego las guardo en la sesión
200
+ //Obtengo mis variables, para tener los tags solicitados
201
+ const response = await getVariables(headers);
202
+ if (response.error) {
203
+ throw new Error(`${response.userMsg} - ${response.msg}`);
204
+ }
205
+ session.set("variables", response.data);
206
+ await commitSession(session);
207
+ variables = response.data ?? [];
208
+ }
209
+ const filtrados = variables.filter((value) => names.includes(value.name));
210
+ const returnObject = {};
211
+ filtrados.forEach((variable) => {
212
+ returnObject[`${variable.name}`] = variable.value;
213
+ });
214
+ //Pregunto si todas las variables fueron encontradas o no
215
+ if (!names.every((variable) => Object.keys(returnObject).includes(variable))) {
216
+ const noEncontradas = names
217
+ .filter((variable) => !Object.keys(returnObject).includes(variable))
218
+ .join(",");
219
+ throw new Error(`No se encontraron las variables: ${noEncontradas} pruebe cerrar e iniciar sesión nuevamente para continuar.`);
220
+ }
221
+ return returnObject;
222
+ }
package/dist/index.d.ts CHANGED
@@ -1,34 +1,34 @@
1
- export * from "./common.server.js";
2
- export * from "./sessions/sessions.server.js";
3
- export * from "./sessions/upstash.server.js";
4
- export * from "./zauru/httpGraphQL.server.js";
5
- export * from "./zauru/httpOauth.server.js";
6
- export * from "./zauru/httpZauru.server.js";
7
- export * from "./zauru/zauru-agencies.server.js";
8
- export * from "./zauru/zauru-automatic-numbers.server.js";
9
- export * from "./zauru/zauru-bookings.server.js";
10
- export * from "./zauru/zauru-bundles.server.js";
11
- export * from "./zauru/zauru-cases.server.js";
12
- export * from "./zauru/zauru-currencies.server.js";
13
- export * from "./zauru/zauru-consolidated.server.js";
14
- export * from "./zauru/zauru-deliveries.server.js";
15
- export * from "./zauru/zauru-discharges.server.js";
16
- export * from "./zauru/zauru-employees.server.js";
17
- export * from "./zauru/zauru-forms.server.js";
18
- export * from "./zauru/zauru-invoices.server.js";
19
- export * from "./zauru/zauru-items.server.js";
20
- export * from "./zauru/zauru-lote-record.server.js";
21
- export * from "./zauru/zauru-lotes.server.js";
22
- export * from "./zauru/zauru-motivos-rechazo.server.js";
23
- export * from "./zauru/zauru-payees.server.js";
24
- export * from "./zauru/zauru-payment-terms.server.js";
25
- export * from "./zauru/zauru-price-lists.server.js";
26
- export * from "./zauru/zauru-purchase-orders.server.js";
27
- export * from "./zauru/zauru-profiles.server.js";
28
- export * from "./zauru/zauru-receptions.server.js";
29
- export * from "./zauru/zauru-shipments.server.js";
30
- export * from "./zauru/zauru-suggested-prices.server.js";
31
- export * from "./zauru/zauru-tags.server.js";
32
- export * from "./zauru/zauru-templates.server.js";
33
- export * from "./zauru/zauru-web-app-tables.server.js";
34
- export * from "./zauru/zauru-variables.server.js";
1
+ export * from "./common.js";
2
+ export * from "./sessions/sessions.js";
3
+ export * from "./sessions/upstash.js";
4
+ export * from "./zauru/httpGraphQL.js";
5
+ export * from "./zauru/httpOauth.js";
6
+ export * from "./zauru/httpZauru.js";
7
+ export * from "./zauru/zauru-agencies.js";
8
+ export * from "./zauru/zauru-automatic-numbers.js";
9
+ export * from "./zauru/zauru-bookings.js";
10
+ export * from "./zauru/zauru-bundles.js";
11
+ export * from "./zauru/zauru-cases.js";
12
+ export * from "./zauru/zauru-currencies.js";
13
+ export * from "./zauru/zauru-consolidated.js";
14
+ export * from "./zauru/zauru-deliveries.js";
15
+ export * from "./zauru/zauru-discharges.js";
16
+ export * from "./zauru/zauru-employees.js";
17
+ export * from "./zauru/zauru-forms.js";
18
+ export * from "./zauru/zauru-invoices.js";
19
+ export * from "./zauru/zauru-items.js";
20
+ export * from "./zauru/zauru-lote-record.js";
21
+ export * from "./zauru/zauru-lotes.js";
22
+ export * from "./zauru/zauru-motivos-rechazo.js";
23
+ export * from "./zauru/zauru-payees.js";
24
+ export * from "./zauru/zauru-payment-terms.js";
25
+ export * from "./zauru/zauru-price-lists.js";
26
+ export * from "./zauru/zauru-purchase-orders.js";
27
+ export * from "./zauru/zauru-profiles.js";
28
+ export * from "./zauru/zauru-receptions.js";
29
+ export * from "./zauru/zauru-shipments.js";
30
+ export * from "./zauru/zauru-suggested-prices.js";
31
+ export * from "./zauru/zauru-tags.js";
32
+ export * from "./zauru/zauru-templates.js";
33
+ export * from "./zauru/zauru-web-app-tables.js";
34
+ export * from "./zauru/zauru-variables.js";
package/dist/index.js CHANGED
@@ -1,34 +1,34 @@
1
- export * from "./common.server.js";
2
- export * from "./sessions/sessions.server.js";
3
- export * from "./sessions/upstash.server.js";
4
- export * from "./zauru/httpGraphQL.server.js";
5
- export * from "./zauru/httpOauth.server.js";
6
- export * from "./zauru/httpZauru.server.js";
7
- export * from "./zauru/zauru-agencies.server.js";
8
- export * from "./zauru/zauru-automatic-numbers.server.js";
9
- export * from "./zauru/zauru-bookings.server.js";
10
- export * from "./zauru/zauru-bundles.server.js";
11
- export * from "./zauru/zauru-cases.server.js";
12
- export * from "./zauru/zauru-currencies.server.js";
13
- export * from "./zauru/zauru-consolidated.server.js";
14
- export * from "./zauru/zauru-deliveries.server.js";
15
- export * from "./zauru/zauru-discharges.server.js";
16
- export * from "./zauru/zauru-employees.server.js";
17
- export * from "./zauru/zauru-forms.server.js";
18
- export * from "./zauru/zauru-invoices.server.js";
19
- export * from "./zauru/zauru-items.server.js";
20
- export * from "./zauru/zauru-lote-record.server.js";
21
- export * from "./zauru/zauru-lotes.server.js";
22
- export * from "./zauru/zauru-motivos-rechazo.server.js";
23
- export * from "./zauru/zauru-payees.server.js";
24
- export * from "./zauru/zauru-payment-terms.server.js";
25
- export * from "./zauru/zauru-price-lists.server.js";
26
- export * from "./zauru/zauru-purchase-orders.server.js";
27
- export * from "./zauru/zauru-profiles.server.js";
28
- export * from "./zauru/zauru-receptions.server.js";
29
- export * from "./zauru/zauru-shipments.server.js";
30
- export * from "./zauru/zauru-suggested-prices.server.js";
31
- export * from "./zauru/zauru-tags.server.js";
32
- export * from "./zauru/zauru-templates.server.js";
33
- export * from "./zauru/zauru-web-app-tables.server.js";
34
- export * from "./zauru/zauru-variables.server.js";
1
+ export * from "./common.js";
2
+ export * from "./sessions/sessions.js";
3
+ export * from "./sessions/upstash.js";
4
+ export * from "./zauru/httpGraphQL.js";
5
+ export * from "./zauru/httpOauth.js";
6
+ export * from "./zauru/httpZauru.js";
7
+ export * from "./zauru/zauru-agencies.js";
8
+ export * from "./zauru/zauru-automatic-numbers.js";
9
+ export * from "./zauru/zauru-bookings.js";
10
+ export * from "./zauru/zauru-bundles.js";
11
+ export * from "./zauru/zauru-cases.js";
12
+ export * from "./zauru/zauru-currencies.js";
13
+ export * from "./zauru/zauru-consolidated.js";
14
+ export * from "./zauru/zauru-deliveries.js";
15
+ export * from "./zauru/zauru-discharges.js";
16
+ export * from "./zauru/zauru-employees.js";
17
+ export * from "./zauru/zauru-forms.js";
18
+ export * from "./zauru/zauru-invoices.js";
19
+ export * from "./zauru/zauru-items.js";
20
+ export * from "./zauru/zauru-lote-record.js";
21
+ export * from "./zauru/zauru-lotes.js";
22
+ export * from "./zauru/zauru-motivos-rechazo.js";
23
+ export * from "./zauru/zauru-payees.js";
24
+ export * from "./zauru/zauru-payment-terms.js";
25
+ export * from "./zauru/zauru-price-lists.js";
26
+ export * from "./zauru/zauru-purchase-orders.js";
27
+ export * from "./zauru/zauru-profiles.js";
28
+ export * from "./zauru/zauru-receptions.js";
29
+ export * from "./zauru/zauru-shipments.js";
30
+ export * from "./zauru/zauru-suggested-prices.js";
31
+ export * from "./zauru/zauru-tags.js";
32
+ export * from "./zauru/zauru-templates.js";
33
+ export * from "./zauru/zauru-web-app-tables.js";
34
+ export * from "./zauru/zauru-variables.js";
@@ -0,0 +1,2 @@
1
+ declare const getSession: (cookieHeader?: string | null | undefined, options?: import("cookie").CookieParseOptions | undefined) => Promise<import("@remix-run/node").Session<import("@remix-run/node").SessionData, import("@remix-run/node").SessionData>>, commitSession: (session: import("@remix-run/node").Session<import("@remix-run/node").SessionData, import("@remix-run/node").SessionData>, options?: import("cookie").CookieSerializeOptions | undefined) => Promise<string>, destroySession: (session: import("@remix-run/node").Session<import("@remix-run/node").SessionData, import("@remix-run/node").SessionData>, options?: import("cookie").CookieSerializeOptions | undefined) => Promise<string>;
2
+ export { getSession, commitSession, destroySession };
@@ -0,0 +1,13 @@
1
+ import { createCookie } from "@remix-run/node";
2
+ import { createUpstashSessionStorage } from "./upstash.js";
3
+ const sessionCookie = createCookie("_rj_session", {
4
+ secrets: ["r3m1xr0ck1"],
5
+ path: "/",
6
+ sameSite: process.env.NODE_ENV === "production" ? "none" : "lax",
7
+ httpOnly: true,
8
+ maxAge: 60 * 60 * 24,
9
+ //expires,
10
+ secure: process.env.NODE_ENV === "production",
11
+ });
12
+ const { getSession, commitSession, destroySession } = createUpstashSessionStorage({ cookie: sessionCookie });
13
+ export { getSession, commitSession, destroySession };
@@ -0,0 +1 @@
1
+ export declare function createUpstashSessionStorage({ cookie }: any): import("@remix-run/node").SessionStorage<import("@remix-run/node").SessionData, import("@remix-run/node").SessionData>;
@@ -0,0 +1,52 @@
1
+ import { createSessionStorage } from "@remix-run/node";
2
+ import crypto from "crypto";
3
+ import { config } from "@zauru-sdk/config";
4
+ const redisBaseURL = config.redisBaseURL;
5
+ const headers = {
6
+ Authorization: `Bearer ${config.redisToken}`,
7
+ Accept: "application/json",
8
+ "Content-Type": "application/json",
9
+ };
10
+ const expiresToSeconds = (expires) => {
11
+ return 3600 * 8;
12
+ };
13
+ // For more info check https://remix.run/docs/en/v1/api/remix#createsessionstorage
14
+ export function createUpstashSessionStorage({ cookie }) {
15
+ return createSessionStorage({
16
+ cookie,
17
+ async createData(data, expires) {
18
+ const id = crypto.randomUUID();
19
+ await fetch(`${redisBaseURL}/set/${id}?EX=${expiresToSeconds(expires)}`, {
20
+ method: "post",
21
+ body: JSON.stringify({ data }),
22
+ headers,
23
+ });
24
+ return id;
25
+ },
26
+ async readData(id) {
27
+ const response = await fetch(`${redisBaseURL}/get/${id}`, {
28
+ headers,
29
+ });
30
+ try {
31
+ const { result } = (await response.json());
32
+ return JSON.parse(result).data;
33
+ }
34
+ catch (error) {
35
+ return null;
36
+ }
37
+ },
38
+ async updateData(id, data, expires) {
39
+ await fetch(`${redisBaseURL}/set/${id}?EX=${expiresToSeconds(expires)}`, {
40
+ method: "post",
41
+ body: JSON.stringify({ data }),
42
+ headers,
43
+ });
44
+ },
45
+ async deleteData(id) {
46
+ await fetch(`${redisBaseURL}/del/${id}`, {
47
+ method: "post",
48
+ headers,
49
+ });
50
+ },
51
+ });
52
+ }
@@ -0,0 +1,2 @@
1
+ declare const httpGraphQLAPI: import("axios").AxiosInstance;
2
+ export default httpGraphQLAPI;
@@ -0,0 +1,37 @@
1
+ import axios from "axios";
2
+ import chalk from "chalk";
3
+ import { config } from "@zauru-sdk/config";
4
+ const axiosInstance = axios.create({
5
+ baseURL: `${config.graphqlAPIBaseURL}`,
6
+ });
7
+ axiosInstance.interceptors.request.use(function (request) {
8
+ // Do something before request is sent
9
+ console.log("---------------- EJECUTANDO REQUEST GRAPHQL ----------------");
10
+ //console.time(`${request.baseURL}${request.url}`);
11
+ console.log(chalk.green(`${request.baseURL}${request.url}`));
12
+ request.timeout = 120000;
13
+ return request;
14
+ }, function (error) {
15
+ console.log(chalk.red("---------------- ERROR CON REQUEST GRAPHQL ----------------"));
16
+ console.log(`${error}`);
17
+ // Do something with request error
18
+ return Promise.reject(error);
19
+ });
20
+ // Add a response interceptor
21
+ axiosInstance.interceptors.response.use(function (response) {
22
+ // Do something with response data
23
+ //console.timeEnd(`${response.config.baseURL}${response.config.url}`);
24
+ return response;
25
+ }, function (error) {
26
+ console.log(chalk.red("---------------- ERROR CON REQUEST GRAPHQL ----------------"));
27
+ console.log(`${error}`);
28
+ // Do something with response error
29
+ const { response } = error;
30
+ const msgError = response
31
+ ? `HTTP ${response.status} ${response.statusText} - URL: ${response?.config?.baseURL}${response?.config?.url} - ${JSON.stringify(response?.data)}`
32
+ : error;
33
+ console.log(chalk.red(`${msgError}`));
34
+ throw new Error(msgError);
35
+ });
36
+ const httpGraphQLAPI = axiosInstance;
37
+ export default httpGraphQLAPI;
@@ -0,0 +1,2 @@
1
+ declare const httpOauth: import("axios").AxiosInstance;
2
+ export default httpOauth;
@@ -0,0 +1,37 @@
1
+ import axios from "axios";
2
+ import chalk from "chalk";
3
+ import { config } from "@zauru-sdk/config";
4
+ const axiosInstance = axios.create({
5
+ baseURL: `${config.oauthBaseURL}`,
6
+ });
7
+ axiosInstance.interceptors.request.use(function (request) {
8
+ // Do something before request is sent
9
+ console.log("---------------- EJECUTANDO REQUEST ----------------");
10
+ //console.time(`${request.baseURL}${request.url}`);
11
+ console.log(chalk.green(`${request.baseURL}${request.url}`));
12
+ request.timeout = 120000;
13
+ return request;
14
+ }, function (error) {
15
+ console.log(chalk.red("---------------- ERROR CON REQUEST ----------------"));
16
+ console.log(`${error}`);
17
+ // Do something with request error
18
+ return Promise.reject(error);
19
+ });
20
+ // Add a response interceptor
21
+ axiosInstance.interceptors.response.use(function (response) {
22
+ // Do something with response data
23
+ //console.timeEnd(`${response.config.baseURL}${response.config.url}`);
24
+ return response;
25
+ }, function (error) {
26
+ console.log(chalk.red("---------------- ERROR CON REQUEST ----------------"));
27
+ console.log(`${error}`);
28
+ // Do something with response error
29
+ const { response } = error;
30
+ const msgError = response
31
+ ? `HTTP ${response.status} ${response.statusText} - URL: ${response?.config?.baseURL}${response?.config?.url} - ${JSON.stringify(response?.data)}`
32
+ : error;
33
+ console.log(chalk.red(`${msgError}`));
34
+ throw new Error(msgError);
35
+ });
36
+ const httpOauth = axiosInstance;
37
+ export default httpOauth;
@@ -0,0 +1,2 @@
1
+ declare const httpZauru: import("axios").AxiosInstance;
2
+ export default httpZauru;
@@ -0,0 +1,37 @@
1
+ import axios from "axios";
2
+ import chalk from "chalk";
3
+ import { config } from "@zauru-sdk/config";
4
+ const axiosInstance = axios.create({
5
+ baseURL: `${config.zauruBaseURL}`,
6
+ });
7
+ axiosInstance.interceptors.request.use(function (request) {
8
+ // Do something before request is sent
9
+ console.log(`---------------- EJECUTANDO REQUEST ----------------`);
10
+ //console.time(`${request.baseURL}${request.url}`);
11
+ console.log(chalk.green(`${request.baseURL}${request.url}`));
12
+ request.timeout = 120000;
13
+ return request;
14
+ }, function (error) {
15
+ console.log(chalk.red("---------------- ERROR CON REQUEST ----------------"));
16
+ console.log(`${error}`);
17
+ // Do something with request error
18
+ return Promise.reject(error);
19
+ });
20
+ // Add a response interceptor
21
+ axiosInstance.interceptors.response.use(function (response) {
22
+ // Do something with response data
23
+ //console.timeEnd(`${response.config.baseURL}${response.config.url}`);
24
+ return response;
25
+ }, function (error) {
26
+ console.log(chalk.red("---------------- ERROR CON REQUEST ----------------"));
27
+ console.log(`${error}`);
28
+ // Do something with response error
29
+ const { response } = error;
30
+ const msgError = response
31
+ ? `HTTP ${response.status} ${response.statusText} - URL: ${response?.config?.baseURL}${response?.config?.url} - ${JSON.stringify(response?.data)}`
32
+ : error;
33
+ console.log(chalk.red(`${msgError}`));
34
+ throw new Error(msgError);
35
+ });
36
+ const httpZauru = axiosInstance;
37
+ export default httpZauru;
@@ -0,0 +1,8 @@
1
+ import type { Session } from "@remix-run/node";
2
+ import type { AgencyGraphQL, AxiosUtilsResponse } from "@zauru-sdk/types";
3
+ /**
4
+ * getAgencies
5
+ * @param headers
6
+ * @returns
7
+ */
8
+ export declare function getAgencies(session: Session): Promise<AxiosUtilsResponse<AgencyGraphQL[]>>;