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