@zauru-sdk/services 1.0.44 → 1.0.46
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/CHANGELOG.md +16 -0
- package/package.json +3 -3
- package/dist/common.server.d.ts +0 -55
- package/dist/common.server.js +0 -222
- package/dist/sessions/sessions.server.d.ts +0 -2
- package/dist/sessions/sessions.server.js +0 -13
- package/dist/sessions/upstash.server.d.ts +0 -1
- package/dist/sessions/upstash.server.js +0 -52
- package/dist/zauru/httpGraphQL.server.d.ts +0 -2
- package/dist/zauru/httpGraphQL.server.js +0 -37
- package/dist/zauru/httpOauth.server.d.ts +0 -2
- package/dist/zauru/httpOauth.server.js +0 -37
- package/dist/zauru/httpZauru.server.d.ts +0 -2
- package/dist/zauru/httpZauru.server.js +0 -37
- package/dist/zauru/zauru-agencies.server.d.ts +0 -8
- package/dist/zauru/zauru-agencies.server.js +0 -20
- package/dist/zauru/zauru-automatic-numbers.server.d.ts +0 -8
- package/dist/zauru/zauru-automatic-numbers.server.js +0 -21
- package/dist/zauru/zauru-bookings.server.d.ts +0 -28
- package/dist/zauru/zauru-bookings.server.js +0 -80
- package/dist/zauru/zauru-bundles.server.d.ts +0 -28
- package/dist/zauru/zauru-bundles.server.js +0 -93
- package/dist/zauru/zauru-cases.server.d.ts +0 -6
- package/dist/zauru/zauru-cases.server.js +0 -23
- package/dist/zauru/zauru-consolidated.server.d.ts +0 -36
- package/dist/zauru/zauru-consolidated.server.js +0 -71
- package/dist/zauru/zauru-currencies.server.d.ts +0 -6
- package/dist/zauru/zauru-currencies.server.js +0 -20
- package/dist/zauru/zauru-deliveries.server.d.ts +0 -22
- package/dist/zauru/zauru-deliveries.server.js +0 -44
- package/dist/zauru/zauru-discharges.server.d.ts +0 -26
- package/dist/zauru/zauru-discharges.server.js +0 -46
- package/dist/zauru/zauru-employees.server.d.ts +0 -6
- package/dist/zauru/zauru-employees.server.js +0 -23
- package/dist/zauru/zauru-forms.server.d.ts +0 -96
- package/dist/zauru/zauru-forms.server.js +0 -343
- package/dist/zauru/zauru-invoices.server.d.ts +0 -26
- package/dist/zauru/zauru-invoices.server.js +0 -94
- package/dist/zauru/zauru-items.server.d.ts +0 -97
- package/dist/zauru/zauru-items.server.js +0 -272
- package/dist/zauru/zauru-lote-record.server.d.ts +0 -8
- package/dist/zauru/zauru-lote-record.server.js +0 -26
- package/dist/zauru/zauru-lotes.server.d.ts +0 -91
- package/dist/zauru/zauru-lotes.server.js +0 -294
- package/dist/zauru/zauru-motivos-rechazo.server.d.ts +0 -9
- package/dist/zauru/zauru-motivos-rechazo.server.js +0 -49
- package/dist/zauru/zauru-payees.server.d.ts +0 -97
- package/dist/zauru/zauru-payees.server.js +0 -227
- package/dist/zauru/zauru-payment-terms.server.d.ts +0 -20
- package/dist/zauru/zauru-payment-terms.server.js +0 -65
- package/dist/zauru/zauru-price-lists.server.d.ts +0 -22
- package/dist/zauru/zauru-price-lists.server.js +0 -40
- package/dist/zauru/zauru-profiles.server.d.ts +0 -28
- package/dist/zauru/zauru-profiles.server.js +0 -69
- package/dist/zauru/zauru-purchase-orders.server.d.ts +0 -160
- package/dist/zauru/zauru-purchase-orders.server.js +0 -414
- package/dist/zauru/zauru-receptions.server.d.ts +0 -33
- package/dist/zauru/zauru-receptions.server.js +0 -94
- package/dist/zauru/zauru-shipments.server.d.ts +0 -20
- package/dist/zauru/zauru-shipments.server.js +0 -53
- package/dist/zauru/zauru-suggested-prices.server.d.ts +0 -31
- package/dist/zauru/zauru-suggested-prices.server.js +0 -84
- package/dist/zauru/zauru-tags.server.d.ts +0 -7
- package/dist/zauru/zauru-tags.server.js +0 -13
- package/dist/zauru/zauru-templates.server.d.ts +0 -7
- package/dist/zauru/zauru-templates.server.js +0 -15
- package/dist/zauru/zauru-variables.server.d.ts +0 -14
- package/dist/zauru/zauru-variables.server.js +0 -48
- package/dist/zauru/zauru-web-app-tables.server.d.ts +0 -55
- package/dist/zauru/zauru-web-app-tables.server.js +0 -154
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.46](https://github.com/intuitiva/zauru-typescript-sdk/compare/v1.0.45...v1.0.46) (2024-04-02)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @zauru-sdk/services
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [1.0.45](https://github.com/intuitiva/zauru-typescript-sdk/compare/v1.0.44...v1.0.45) (2024-04-01)
|
|
15
|
+
|
|
16
|
+
**Note:** Version bump only for package @zauru-sdk/services
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
6
22
|
## [1.0.44](https://github.com/intuitiva/zauru-typescript-sdk/compare/v1.0.43...v1.0.44) (2024-04-01)
|
|
7
23
|
|
|
8
24
|
**Note:** Version bump only for package @zauru-sdk/services
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zauru-sdk/services",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.46",
|
|
4
4
|
"description": "Servicios de consulta a Zauru",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@remix-run/node": "^2.8.1",
|
|
22
22
|
"@zauru-sdk/common": "^1.0.33",
|
|
23
|
-
"@zauru-sdk/config": "^1.0.
|
|
23
|
+
"@zauru-sdk/config": "^1.0.46",
|
|
24
24
|
"@zauru-sdk/graphql": "^1.0.33",
|
|
25
25
|
"@zauru-sdk/types": "^1.0.33",
|
|
26
26
|
"axios": "^1.6.7",
|
|
@@ -29,5 +29,5 @@
|
|
|
29
29
|
"engines": {
|
|
30
30
|
"node": ">=18.0.0"
|
|
31
31
|
},
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "d6835463851b558a0a133085413b9e35f3050c32"
|
|
33
33
|
}
|
package/dist/common.server.d.ts
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
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.server.js
DELETED
|
@@ -1,222 +0,0 @@
|
|
|
1
|
-
import { redirect } from "@remix-run/node";
|
|
2
|
-
import { commitSession, getSession } from "./sessions/sessions.server.js";
|
|
3
|
-
import chalk from "chalk";
|
|
4
|
-
import httpZauru from "./zauru/httpZauru.server.js";
|
|
5
|
-
import { getAgencyInfo, getEmployeeInfo, getOauthUserInfo, getProfileInformation, } from "./zauru/zauru-profiles.server.js";
|
|
6
|
-
import { handlePossibleAxiosErrors } from "@zauru-sdk/common";
|
|
7
|
-
import { getVariables } from "./zauru/zauru-variables.server.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
|
-
}
|
|
@@ -1,2 +0,0 @@
|
|
|
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 };
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { createCookie } from "@remix-run/node";
|
|
2
|
-
import { createUpstashSessionStorage } from "./upstash.server.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 };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function createUpstashSessionStorage({ cookie }: any): import("@remix-run/node").SessionStorage<import("@remix-run/node").SessionData, import("@remix-run/node").SessionData>;
|
|
@@ -1,52 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
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;
|
|
@@ -1,37 +0,0 @@
|
|
|
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;
|
|
@@ -1,37 +0,0 @@
|
|
|
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;
|
|
@@ -1,8 +0,0 @@
|
|
|
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[]>>;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { handlePossibleAxiosErrors } from "@zauru-sdk/common";
|
|
2
|
-
import httpGraphQLAPI from "./httpGraphQL.server.js";
|
|
3
|
-
import { getAgenciesStringQuery } from "@zauru-sdk/graphql";
|
|
4
|
-
import { getGraphQLAPIHeaders } from "../common.server.js";
|
|
5
|
-
/**
|
|
6
|
-
* getAgencies
|
|
7
|
-
* @param headers
|
|
8
|
-
* @returns
|
|
9
|
-
*/
|
|
10
|
-
export async function getAgencies(session) {
|
|
11
|
-
return handlePossibleAxiosErrors(async () => {
|
|
12
|
-
const headers = await getGraphQLAPIHeaders(session);
|
|
13
|
-
const response = await httpGraphQLAPI.post(``, {
|
|
14
|
-
query: getAgenciesStringQuery,
|
|
15
|
-
}, {
|
|
16
|
-
headers,
|
|
17
|
-
});
|
|
18
|
-
return response.data?.data.agencies;
|
|
19
|
-
});
|
|
20
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { DocumentAutomaticNumberGraphQL, AxiosUtilsResponse } from "@zauru-sdk/types";
|
|
2
|
-
/**
|
|
3
|
-
* updateAutomaticNumber
|
|
4
|
-
* @param headers
|
|
5
|
-
* @param body
|
|
6
|
-
* @returns
|
|
7
|
-
*/
|
|
8
|
-
export declare const updateAutomaticNumber: (headers: any, body: Partial<DocumentAutomaticNumberGraphQL>) => Promise<AxiosUtilsResponse<DocumentAutomaticNumberGraphQL>>;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { handlePossibleAxiosErrors } from "@zauru-sdk/common";
|
|
2
|
-
import httpZauru from "./httpZauru.server.js";
|
|
3
|
-
/**
|
|
4
|
-
* updateAutomaticNumber
|
|
5
|
-
* @param headers
|
|
6
|
-
* @param body
|
|
7
|
-
* @returns
|
|
8
|
-
*/
|
|
9
|
-
export const updateAutomaticNumber = async (headers, body) => {
|
|
10
|
-
return handlePossibleAxiosErrors(async () => {
|
|
11
|
-
const sendBody = {
|
|
12
|
-
document_automatic_number: {
|
|
13
|
-
...body,
|
|
14
|
-
},
|
|
15
|
-
};
|
|
16
|
-
const response = await httpZauru.put(`/settings/templates/document_automatic_numbers/${body.id}.json`, sendBody, {
|
|
17
|
-
headers,
|
|
18
|
-
});
|
|
19
|
-
return response.data;
|
|
20
|
-
});
|
|
21
|
-
};
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { AxiosUtilsResponse, InsertBookingBody, ShipmentGraphQL } from "@zauru-sdk/types";
|
|
2
|
-
import { Session } from "@remix-run/node";
|
|
3
|
-
/**
|
|
4
|
-
* insertBookings
|
|
5
|
-
* @param headers
|
|
6
|
-
* @param body
|
|
7
|
-
* @returns
|
|
8
|
-
*/
|
|
9
|
-
export declare const insertBookings: (headers: any, body: Partial<InsertBookingBody>, temp_purchase_order_id?: string) => Promise<AxiosUtilsResponse<ShipmentGraphQL>>;
|
|
10
|
-
/**
|
|
11
|
-
* getDeliveryByBooking
|
|
12
|
-
* @param headers
|
|
13
|
-
* @param shipment_id
|
|
14
|
-
* @returns
|
|
15
|
-
*/
|
|
16
|
-
export declare const getDeliveryByBooking: (headers: any, shipment_id: number) => Promise<AxiosUtilsResponse<any>>;
|
|
17
|
-
/**
|
|
18
|
-
* getBookings
|
|
19
|
-
* @param headers
|
|
20
|
-
* @returns
|
|
21
|
-
*/
|
|
22
|
-
export declare const getBookings: (session: Session, wheres?: string[]) => Promise<AxiosUtilsResponse<ShipmentGraphQL[]>>;
|
|
23
|
-
/**
|
|
24
|
-
* getBookings
|
|
25
|
-
* @param headers
|
|
26
|
-
* @returns
|
|
27
|
-
*/
|
|
28
|
-
export declare const getBooking: (headers: any, booking_id: string) => Promise<AxiosUtilsResponse<ShipmentGraphQL>>;
|