@zauru-sdk/services 1.0.5 → 1.0.7
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/dist/common.server.d.ts +11 -10
- package/dist/common.server.js +44 -1
- package/dist/index.d.ts +22 -0
- package/dist/index.js +22 -0
- package/dist/zauru/httpZauru.server.d.ts +0 -12
- package/dist/zauru/httpZauru.server.js +0 -14
- package/dist/zauru/zauru-agencies.server.d.ts +1 -2
- package/dist/zauru/zauru-agencies.server.js +1 -1
- package/dist/zauru/zauru-automatic-numbers.server.d.ts +8 -0
- package/dist/zauru/zauru-automatic-numbers.server.js +21 -0
- package/dist/zauru/zauru-currencies.server.d.ts +6 -0
- package/dist/zauru/zauru-currencies.server.js +20 -0
- package/dist/zauru/zauru-deliveries.server.d.ts +22 -0
- package/dist/zauru/zauru-deliveries.server.js +44 -0
- package/dist/zauru/zauru-discharges.server.d.ts +26 -0
- package/dist/zauru/zauru-discharges.server.js +46 -0
- package/dist/zauru/zauru-employees.server.d.ts +6 -0
- package/dist/zauru/zauru-employees.server.js +23 -0
- package/dist/zauru/zauru-forms.server.d.ts +96 -0
- package/dist/zauru/zauru-forms.server.js +343 -0
- package/dist/zauru/zauru-invoices.server.d.ts +26 -0
- package/dist/zauru/zauru-invoices.server.js +94 -0
- package/dist/zauru/zauru-items.server.d.ts +91 -0
- package/dist/zauru/zauru-items.server.js +238 -0
- package/dist/zauru/zauru-lote-record.server.d.ts +8 -0
- package/dist/zauru/zauru-lote-record.server.js +26 -0
- package/dist/zauru/zauru-lotes.server.d.ts +91 -0
- package/dist/zauru/zauru-lotes.server.js +294 -0
- package/dist/zauru/zauru-motivos-rechazo.server.d.ts +9 -0
- package/dist/zauru/zauru-motivos-rechazo.server.js +49 -0
- package/dist/zauru/zauru-payees.server.d.ts +97 -0
- package/dist/zauru/zauru-payees.server.js +227 -0
- package/dist/zauru/zauru-payment-terms.server.d.ts +20 -0
- package/dist/zauru/zauru-payment-terms.server.js +65 -0
- package/dist/zauru/zauru-price-lists.server.d.ts +22 -0
- package/dist/zauru/zauru-price-lists.server.js +40 -0
- package/dist/zauru/zauru-profiles.server.d.ts +1 -2
- package/dist/zauru/zauru-profiles.server.js +2 -1
- package/dist/zauru/zauru-purchase-orders.server.d.ts +160 -0
- package/dist/zauru/zauru-purchase-orders.server.js +414 -0
- package/dist/zauru/zauru-receptions.server.d.ts +33 -0
- package/dist/zauru/zauru-receptions.server.js +94 -0
- package/dist/zauru/zauru-shipments.server.d.ts +20 -0
- package/dist/zauru/zauru-shipments.server.js +53 -0
- package/dist/zauru/zauru-suggested-prices.server.d.ts +30 -0
- package/dist/zauru/zauru-suggested-prices.server.js +83 -0
- package/dist/zauru/zauru-tags.server.d.ts +7 -0
- package/dist/zauru/zauru-tags.server.js +13 -0
- package/dist/zauru/zauru-templates.server.d.ts +7 -0
- package/dist/zauru/zauru-templates.server.js +15 -0
- package/dist/zauru/zauru-variables.server.d.ts +14 -0
- package/dist/zauru/zauru-variables.server.js +48 -0
- package/dist/zauru/zauru-web-app-tables.server.d.ts +48 -0
- package/dist/zauru/zauru-web-app-tables.server.js +120 -0
- package/package.json +6 -5
- package/src/common.server.ts +61 -13
- package/src/index.ts +22 -0
- package/src/zauru/httpZauru.server.ts +1 -23
- package/src/zauru/zauru-agencies.server.ts +2 -3
- package/src/zauru/zauru-automatic-numbers.server.ts +35 -0
- package/src/zauru/zauru-currencies.server.ts +39 -0
- package/src/zauru/zauru-deliveries.server.ts +70 -0
- package/src/zauru/zauru-discharges.server.ts +90 -0
- package/src/zauru/zauru-employees.server.ts +43 -0
- package/src/zauru/zauru-forms.server.ts +618 -0
- package/src/zauru/zauru-invoices.server.ts +142 -0
- package/src/zauru/zauru-items.server.ts +427 -0
- package/src/zauru/zauru-lote-record.server.ts +77 -0
- package/src/zauru/zauru-lotes.server.ts +484 -0
- package/src/zauru/zauru-motivos-rechazo.server.ts +121 -0
- package/src/zauru/zauru-payees.server.ts +398 -0
- package/src/zauru/zauru-payment-terms.server.ts +126 -0
- package/src/zauru/zauru-price-lists.server.ts +68 -0
- package/src/zauru/zauru-profiles.server.ts +3 -2
- package/src/zauru/zauru-purchase-orders.server.ts +701 -0
- package/src/zauru/zauru-receptions.server.ts +148 -0
- package/src/zauru/zauru-shipments.server.ts +88 -0
- package/src/zauru/zauru-suggested-prices.server.ts +134 -0
- package/src/zauru/zauru-tags.server.ts +22 -0
- package/src/zauru/zauru-templates.server.ts +24 -0
- package/src/zauru/zauru-variables.server.ts +67 -0
- package/src/zauru/zauru-web-app-tables.server.ts +200 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Session } from "@remix-run/node";
|
|
2
|
+
import { AxiosUtilsResponse, ShipmentGraphQL } from "@zauru-sdk/types";
|
|
3
|
+
/**
|
|
4
|
+
* getShipmentsByToAgencyLast100Id_booking
|
|
5
|
+
*/
|
|
6
|
+
export declare function getShipmentsByToAgencyLast100Id_booking(session: Session, agency_to_id: string | number): Promise<AxiosUtilsResponse<ShipmentGraphQL[]>>;
|
|
7
|
+
/**
|
|
8
|
+
* receiveShipment_booking
|
|
9
|
+
* @param headers
|
|
10
|
+
* @param id
|
|
11
|
+
* @returns
|
|
12
|
+
*/
|
|
13
|
+
export declare function receiveShipment_booking(headers: any, id: string | number): Promise<AxiosUtilsResponse<boolean>>;
|
|
14
|
+
/**
|
|
15
|
+
* deleteShipment_booking
|
|
16
|
+
* @param headers
|
|
17
|
+
* @param id
|
|
18
|
+
* @returns
|
|
19
|
+
*/
|
|
20
|
+
export declare function deleteShipment_booking(headers: any, id: string | number): Promise<AxiosUtilsResponse<boolean>>;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { handlePossibleAxiosErrors } from "@zauru-sdk/common";
|
|
2
|
+
import { getGraphQLAPIHeaders } from "~/common.server.js";
|
|
3
|
+
import httpGraphQLAPI from "./httpGraphQL.server.js";
|
|
4
|
+
import { getShipmentsByToAgencyLast100StringQuery } from "@zauru-sdk/graphql";
|
|
5
|
+
import httpZauru from "./httpZauru.server.js";
|
|
6
|
+
/**
|
|
7
|
+
* getShipmentsByToAgencyLast100Id_booking
|
|
8
|
+
*/
|
|
9
|
+
export async function getShipmentsByToAgencyLast100Id_booking(session, agency_to_id) {
|
|
10
|
+
return handlePossibleAxiosErrors(async () => {
|
|
11
|
+
const headers = await getGraphQLAPIHeaders(session);
|
|
12
|
+
const response = await httpGraphQLAPI.post("", {
|
|
13
|
+
query: getShipmentsByToAgencyLast100StringQuery,
|
|
14
|
+
variables: {
|
|
15
|
+
agency_to_id,
|
|
16
|
+
},
|
|
17
|
+
}, { headers });
|
|
18
|
+
if (response.data.errors) {
|
|
19
|
+
throw new Error(response.data.errors.map((x) => x.message).join(";"));
|
|
20
|
+
}
|
|
21
|
+
const registers = response?.data?.data?.shipments;
|
|
22
|
+
return registers;
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* receiveShipment_booking
|
|
27
|
+
* @param headers
|
|
28
|
+
* @param id
|
|
29
|
+
* @returns
|
|
30
|
+
*/
|
|
31
|
+
export async function receiveShipment_booking(headers, id) {
|
|
32
|
+
return handlePossibleAxiosErrors(async () => {
|
|
33
|
+
const response = await httpZauru.get(`/inventories/bookings/${id}/deliver.json`, { headers });
|
|
34
|
+
if (!response.data) {
|
|
35
|
+
throw new Error("Sin respuesta de: /inventories/bookings/id/deliver.json");
|
|
36
|
+
}
|
|
37
|
+
return true;
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* deleteShipment_booking
|
|
42
|
+
* @param headers
|
|
43
|
+
* @param id
|
|
44
|
+
* @returns
|
|
45
|
+
*/
|
|
46
|
+
export async function deleteShipment_booking(headers, id) {
|
|
47
|
+
return handlePossibleAxiosErrors(async () => {
|
|
48
|
+
await httpZauru.delete(`/inventories/bookings/${id}.json`, {
|
|
49
|
+
headers,
|
|
50
|
+
});
|
|
51
|
+
return true;
|
|
52
|
+
});
|
|
53
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { AxiosUtilsResponse, ItemWithPrices, SuggestedPriceGraphQL } from "@zauru-sdk/types";
|
|
2
|
+
import { Session } from "@remix-run/node";
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param headers
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
export declare const getSuggestedPricesExportJSON: (headers: any) => Promise<AxiosUtilsResponse<ItemWithPrices[]>>;
|
|
9
|
+
/**
|
|
10
|
+
* getSuggestedPrices
|
|
11
|
+
* @param session
|
|
12
|
+
* @param id
|
|
13
|
+
*/
|
|
14
|
+
export declare function getSuggestedPrices(session: Session, config: {
|
|
15
|
+
notNullPriceList?: boolean;
|
|
16
|
+
withItems?: boolean;
|
|
17
|
+
withItemCategories?: boolean;
|
|
18
|
+
}): Promise<AxiosUtilsResponse<SuggestedPriceGraphQL[]>>;
|
|
19
|
+
/**
|
|
20
|
+
* createSuggestedPrice
|
|
21
|
+
* @param headers
|
|
22
|
+
* @param body
|
|
23
|
+
*/
|
|
24
|
+
export declare function createSuggestedPrice(headers: any, body: Partial<SuggestedPriceGraphQL>): Promise<AxiosUtilsResponse<SuggestedPriceGraphQL>>;
|
|
25
|
+
/**
|
|
26
|
+
* deleteSuggestedPrice
|
|
27
|
+
* @param headers
|
|
28
|
+
* @param body
|
|
29
|
+
*/
|
|
30
|
+
export declare function deleteSuggestedPrice(headers: any, id: string | number): Promise<AxiosUtilsResponse<boolean>>;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { handlePossibleAxiosErrors } from "@zauru-sdk/common";
|
|
2
|
+
import httpZauru from "./httpZauru.server.js";
|
|
3
|
+
import { getGraphQLAPIHeaders } from "~/common.server.js";
|
|
4
|
+
import httpGraphQLAPI from "./httpGraphQL.server.js";
|
|
5
|
+
import { getSuggestedPricesStringQuery } from "@zauru-sdk/graphql";
|
|
6
|
+
/**
|
|
7
|
+
*
|
|
8
|
+
* @param headers
|
|
9
|
+
* @returns
|
|
10
|
+
*/
|
|
11
|
+
export const getSuggestedPricesExportJSON = async (headers) => {
|
|
12
|
+
return handlePossibleAxiosErrors(async () => {
|
|
13
|
+
const response = await httpZauru.get(`/sales/suggested_prices/export.json`, {
|
|
14
|
+
headers,
|
|
15
|
+
});
|
|
16
|
+
return response.data;
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* getSuggestedPrices
|
|
21
|
+
* @param session
|
|
22
|
+
* @param id
|
|
23
|
+
*/
|
|
24
|
+
export async function getSuggestedPrices(session, config) {
|
|
25
|
+
return handlePossibleAxiosErrors(async () => {
|
|
26
|
+
const { notNullPriceList = false, withItems = false, withItemCategories = false, } = config;
|
|
27
|
+
const headers = await getGraphQLAPIHeaders(session);
|
|
28
|
+
const response = await httpGraphQLAPI.post("", {
|
|
29
|
+
query: getSuggestedPricesStringQuery({
|
|
30
|
+
notNullPriceList,
|
|
31
|
+
withItems,
|
|
32
|
+
withItemCategories,
|
|
33
|
+
}),
|
|
34
|
+
}, { headers });
|
|
35
|
+
if (response.data.errors) {
|
|
36
|
+
throw new Error(response.data.errors.map((x) => x.message).join(";"));
|
|
37
|
+
}
|
|
38
|
+
return response?.data?.data?.suggested_prices ?? [];
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* createSuggestedPrice
|
|
43
|
+
* @param headers
|
|
44
|
+
* @param body
|
|
45
|
+
*/
|
|
46
|
+
export async function createSuggestedPrice(headers, body) {
|
|
47
|
+
return handlePossibleAxiosErrors(async () => {
|
|
48
|
+
const response = await httpZauru.post(`/sales/suggested_prices.json`, { suggested_price: body }, { headers });
|
|
49
|
+
return response.data;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
//No existe actualizar
|
|
53
|
+
// /**
|
|
54
|
+
// * updateSuggestedPrice
|
|
55
|
+
// * @param headers
|
|
56
|
+
// * @param body
|
|
57
|
+
// */
|
|
58
|
+
// export async function updateSuggestedPrice(
|
|
59
|
+
// headers: any,
|
|
60
|
+
// body: Partial<SuggestedPriceGraphQL>
|
|
61
|
+
// ): Promise<AxiosUtilsResponse<SuggestedPriceGraphQL>> {
|
|
62
|
+
// return handlePossibleAxiosErrors(async () => {
|
|
63
|
+
// const response = await httpZauru.patch<SuggestedPriceGraphQL>(
|
|
64
|
+
// `/sales/suggested_prices.json`,
|
|
65
|
+
// { suggested_price: body },
|
|
66
|
+
// { headers }
|
|
67
|
+
// );
|
|
68
|
+
// return response.data;
|
|
69
|
+
// });
|
|
70
|
+
// }
|
|
71
|
+
/**
|
|
72
|
+
* deleteSuggestedPrice
|
|
73
|
+
* @param headers
|
|
74
|
+
* @param body
|
|
75
|
+
*/
|
|
76
|
+
export async function deleteSuggestedPrice(headers, id) {
|
|
77
|
+
return handlePossibleAxiosErrors(async () => {
|
|
78
|
+
await httpZauru.delete(`/sales/suggested_prices/${id}?destroy=true`, {
|
|
79
|
+
headers,
|
|
80
|
+
});
|
|
81
|
+
return true;
|
|
82
|
+
});
|
|
83
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { handlePossibleAxiosErrors } from "@zauru-sdk/common";
|
|
2
|
+
import httpZauru from "./httpZauru.server.js";
|
|
3
|
+
/**
|
|
4
|
+
* createTag
|
|
5
|
+
* @param headers
|
|
6
|
+
* @param body
|
|
7
|
+
*/
|
|
8
|
+
export async function createTag(headers, body) {
|
|
9
|
+
return handlePossibleAxiosErrors(async () => {
|
|
10
|
+
const response = await httpZauru.post(`/settings/tags.json`, { tag: body }, { headers });
|
|
11
|
+
return response.data;
|
|
12
|
+
});
|
|
13
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { handlePossibleAxiosErrors } from "@zauru-sdk/common";
|
|
2
|
+
import httpZauru from "./httpZauru.server.js";
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param headers
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
export const getReceptionTemplate = async (headers, id) => {
|
|
9
|
+
return handlePossibleAxiosErrors(async () => {
|
|
10
|
+
const response = await httpZauru.get(`/settings/templates/print_templates/${id}/preview_with_vars`, {
|
|
11
|
+
headers,
|
|
12
|
+
});
|
|
13
|
+
return response.data;
|
|
14
|
+
});
|
|
15
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { VariableGraphQL, AxiosUtilsResponse } from "@zauru-sdk/types";
|
|
2
|
+
/**
|
|
3
|
+
* getVariables Function for get all zauru variables
|
|
4
|
+
* @param headers
|
|
5
|
+
* @returns
|
|
6
|
+
*/
|
|
7
|
+
export declare function getVariables(headers: any): Promise<AxiosUtilsResponse<VariableGraphQL[]>>;
|
|
8
|
+
/**
|
|
9
|
+
*
|
|
10
|
+
* @param headers
|
|
11
|
+
* @param body
|
|
12
|
+
* @returns
|
|
13
|
+
*/
|
|
14
|
+
export declare function createVariable(headers: any, body: Partial<VariableGraphQL>): Promise<AxiosUtilsResponse<VariableGraphQL>>;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import httpZauru from "./httpZauru.server.js";
|
|
3
|
+
/**
|
|
4
|
+
* getVariables Function for get all zauru variables
|
|
5
|
+
* @param headers
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
export async function getVariables(headers) {
|
|
9
|
+
try {
|
|
10
|
+
const response = await httpZauru(`/apps/webapp_vars.json`, {
|
|
11
|
+
method: "GET",
|
|
12
|
+
headers: headers,
|
|
13
|
+
});
|
|
14
|
+
return { data: response.data, error: false };
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
console.log(chalk.red(`OCURRIÓ UN ERROR AL CARGAR LAS VARIABLES: ${error}`));
|
|
18
|
+
return {
|
|
19
|
+
msg: error,
|
|
20
|
+
error: true,
|
|
21
|
+
userMsg: "Ocurrió un error al intentar obtener las variables",
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
*
|
|
27
|
+
* @param headers
|
|
28
|
+
* @param body
|
|
29
|
+
* @returns
|
|
30
|
+
*/
|
|
31
|
+
export async function createVariable(headers, body) {
|
|
32
|
+
try {
|
|
33
|
+
const response = await httpZauru.post(`/apps/webapp_vars.json`, { variable: body }, {
|
|
34
|
+
headers,
|
|
35
|
+
});
|
|
36
|
+
return {
|
|
37
|
+
data: response.data,
|
|
38
|
+
error: false,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
return {
|
|
43
|
+
msg: error,
|
|
44
|
+
error: true,
|
|
45
|
+
userMsg: `Ocurrió un error al intentar crear la variable ${body.name}`,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { Session } from "@remix-run/node";
|
|
2
|
+
import { AxiosUtilsResponse, WebAppRowGraphQL, WebAppTableCreateBody, WebAppTableGraphQL, WebAppTableUpdateResponse } from "@zauru-sdk/types";
|
|
3
|
+
/**
|
|
4
|
+
* getWebAppRow
|
|
5
|
+
* @param headers
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
export declare function getWebAppRow<T>(session: Session, id: number): Promise<AxiosUtilsResponse<T>>;
|
|
9
|
+
/**
|
|
10
|
+
* getWebAppTableRegisters Function for get all web app table registers
|
|
11
|
+
* @param headers
|
|
12
|
+
* @param webapp_table_id web app table id
|
|
13
|
+
* @returns
|
|
14
|
+
*/
|
|
15
|
+
export declare function getWebAppTableRegisters<T>(session: Session, webapp_table_id: string): Promise<AxiosUtilsResponse<WebAppRowGraphQL<T>[]>>;
|
|
16
|
+
/**
|
|
17
|
+
* deleteWebAppTableRegister Function for delete a web app table register
|
|
18
|
+
* @param headers
|
|
19
|
+
* @param id_web_app_table
|
|
20
|
+
* @param id_register
|
|
21
|
+
* @returns
|
|
22
|
+
*/
|
|
23
|
+
export declare function deleteWebAppTableRegister(headers: any, id_web_app_table: string, id_register: number): Promise<WebAppTableUpdateResponse>;
|
|
24
|
+
/**
|
|
25
|
+
* createWebAppTableRegister function for create a new web app table register
|
|
26
|
+
* @param headers
|
|
27
|
+
* @param body
|
|
28
|
+
* @param id_web_app_table
|
|
29
|
+
* @returns
|
|
30
|
+
*/
|
|
31
|
+
export declare function createWebAppTableRegister<T>(headers: any, id_web_app_table: string, body: T, extraBody?: {
|
|
32
|
+
temp_purchase_order_id: string;
|
|
33
|
+
}): Promise<WebAppTableUpdateResponse>;
|
|
34
|
+
/**
|
|
35
|
+
* updateWebAppTableRegister Function for update a web app table register
|
|
36
|
+
* @param headers
|
|
37
|
+
* @param id_web_app_table
|
|
38
|
+
* @param id_register
|
|
39
|
+
* @returns
|
|
40
|
+
*/
|
|
41
|
+
export declare function updateWebAppTableRegister<T>(headers: any, id_web_app_table: string, id_register: number | string, body: Partial<T>): Promise<WebAppTableUpdateResponse>;
|
|
42
|
+
/**
|
|
43
|
+
*
|
|
44
|
+
* @param headers
|
|
45
|
+
* @param body
|
|
46
|
+
* @returns
|
|
47
|
+
*/
|
|
48
|
+
export declare function createWebAppTable(headers: any, body: WebAppTableCreateBody): Promise<AxiosUtilsResponse<WebAppTableGraphQL>>;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { handlePossibleAxiosErrors } from "@zauru-sdk/common";
|
|
2
|
+
import { getGraphQLAPIHeaders } from "~/common.server.js";
|
|
3
|
+
import httpGraphQLAPI from "./httpGraphQL.server.js";
|
|
4
|
+
import { getWebAppRowStringQuery, getWebAppRowsByWebAppTableIdStringQuery, } from "@zauru-sdk/graphql";
|
|
5
|
+
import httpZauru from "./httpZauru.server.js";
|
|
6
|
+
/**
|
|
7
|
+
* getWebAppRow
|
|
8
|
+
* @param headers
|
|
9
|
+
* @returns
|
|
10
|
+
*/
|
|
11
|
+
export async function getWebAppRow(session, id) {
|
|
12
|
+
return handlePossibleAxiosErrors(async () => {
|
|
13
|
+
const headers = await getGraphQLAPIHeaders(session);
|
|
14
|
+
const response = await httpGraphQLAPI.post("", {
|
|
15
|
+
query: getWebAppRowStringQuery,
|
|
16
|
+
variables: {
|
|
17
|
+
id,
|
|
18
|
+
},
|
|
19
|
+
}, { headers });
|
|
20
|
+
return response.data?.data?.webapp_rows[0]?.data;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* getWebAppTableRegisters Function for get all web app table registers
|
|
25
|
+
* @param headers
|
|
26
|
+
* @param webapp_table_id web app table id
|
|
27
|
+
* @returns
|
|
28
|
+
*/
|
|
29
|
+
export async function getWebAppTableRegisters(session, webapp_table_id) {
|
|
30
|
+
return handlePossibleAxiosErrors(async () => {
|
|
31
|
+
const headers = await getGraphQLAPIHeaders(session);
|
|
32
|
+
const response = await httpGraphQLAPI.post("", {
|
|
33
|
+
query: getWebAppRowsByWebAppTableIdStringQuery,
|
|
34
|
+
variables: {
|
|
35
|
+
webapp_table_id,
|
|
36
|
+
},
|
|
37
|
+
}, { headers });
|
|
38
|
+
if (response.data.errors) {
|
|
39
|
+
throw new Error(response.data.errors.map((x) => x.message).join(";"));
|
|
40
|
+
}
|
|
41
|
+
if (!response?.data?.data.webapp_rows) {
|
|
42
|
+
return [];
|
|
43
|
+
}
|
|
44
|
+
return response.data?.data?.webapp_rows;
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* deleteWebAppTableRegister Function for delete a web app table register
|
|
49
|
+
* @param headers
|
|
50
|
+
* @param id_web_app_table
|
|
51
|
+
* @param id_register
|
|
52
|
+
* @returns
|
|
53
|
+
*/
|
|
54
|
+
export async function deleteWebAppTableRegister(headers, id_web_app_table, id_register) {
|
|
55
|
+
const response = await httpZauru(`/apps/webapp_tables/${id_web_app_table}/webapp_rows/${id_register}.json`, {
|
|
56
|
+
method: "DELETE",
|
|
57
|
+
headers: headers,
|
|
58
|
+
});
|
|
59
|
+
return response.data;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* createWebAppTableRegister function for create a new web app table register
|
|
63
|
+
* @param headers
|
|
64
|
+
* @param body
|
|
65
|
+
* @param id_web_app_table
|
|
66
|
+
* @returns
|
|
67
|
+
*/
|
|
68
|
+
export async function createWebAppTableRegister(headers, id_web_app_table, body, extraBody) {
|
|
69
|
+
const requestBody = {
|
|
70
|
+
webapp_row: { data: body },
|
|
71
|
+
...(extraBody ?? {}),
|
|
72
|
+
};
|
|
73
|
+
const response = await httpZauru(`/apps/webapp_tables/${id_web_app_table}/webapp_rows.json`, {
|
|
74
|
+
method: "POST",
|
|
75
|
+
headers: headers,
|
|
76
|
+
data: requestBody,
|
|
77
|
+
});
|
|
78
|
+
return response.data;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* updateWebAppTableRegister Function for update a web app table register
|
|
82
|
+
* @param headers
|
|
83
|
+
* @param id_web_app_table
|
|
84
|
+
* @param id_register
|
|
85
|
+
* @returns
|
|
86
|
+
*/
|
|
87
|
+
export async function updateWebAppTableRegister(headers, id_web_app_table, id_register, body) {
|
|
88
|
+
const requestBody = { webapp_row: { data: body } };
|
|
89
|
+
const response = await httpZauru(`/apps/webapp_tables/${id_web_app_table}/webapp_rows/${id_register}.json`, {
|
|
90
|
+
method: "PATCH",
|
|
91
|
+
headers: headers,
|
|
92
|
+
data: requestBody,
|
|
93
|
+
});
|
|
94
|
+
return response.data;
|
|
95
|
+
}
|
|
96
|
+
//============================== WEB APP TABLE
|
|
97
|
+
/**
|
|
98
|
+
*
|
|
99
|
+
* @param headers
|
|
100
|
+
* @param body
|
|
101
|
+
* @returns
|
|
102
|
+
*/
|
|
103
|
+
export async function createWebAppTable(headers, body) {
|
|
104
|
+
try {
|
|
105
|
+
const response = await httpZauru.post(`/apps/webapp_tables.json`, { webapp_table: body }, {
|
|
106
|
+
headers,
|
|
107
|
+
});
|
|
108
|
+
return {
|
|
109
|
+
data: response.data,
|
|
110
|
+
error: false,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
return {
|
|
115
|
+
msg: error,
|
|
116
|
+
error: true,
|
|
117
|
+
userMsg: `Ocurrió un error al intentar crear la web app table ${body.name}`,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zauru-sdk/services",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.0.7",
|
|
4
|
+
"description": "Servicios de consulta a Zauru",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"type": "module",
|
|
@@ -19,14 +19,15 @@
|
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@remix-run/node": "^2.8.1",
|
|
22
|
+
"@zauru-sdk/common": "^1.0.7",
|
|
22
23
|
"@zauru-sdk/config": "^1.0.4",
|
|
23
|
-
"@zauru-sdk/graphql": "^1.0.
|
|
24
|
-
"@zauru-sdk/types": "^1.0.
|
|
24
|
+
"@zauru-sdk/graphql": "^1.0.7",
|
|
25
|
+
"@zauru-sdk/types": "^1.0.7",
|
|
25
26
|
"axios": "^1.6.7",
|
|
26
27
|
"chalk": "5.3.0"
|
|
27
28
|
},
|
|
28
29
|
"engines": {
|
|
29
30
|
"node": ">=18.0.0"
|
|
30
31
|
},
|
|
31
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "8078893206a171382f3783914ceec8959cdda945"
|
|
32
33
|
}
|
package/src/common.server.ts
CHANGED
|
@@ -2,10 +2,7 @@ import { Session, redirect } from "@remix-run/node";
|
|
|
2
2
|
import { commitSession, getSession } from "./sessions/sessions.server.js";
|
|
3
3
|
import { AxiosRequestHeaders } from "axios";
|
|
4
4
|
import chalk from "chalk";
|
|
5
|
-
import httpZauru
|
|
6
|
-
AxiosUtilsResponse,
|
|
7
|
-
handlePossibleAxiosErrors,
|
|
8
|
-
} from "./zauru/httpZauru.server.js";
|
|
5
|
+
import httpZauru from "./zauru/httpZauru.server.js";
|
|
9
6
|
import {
|
|
10
7
|
getAgencyInfo,
|
|
11
8
|
getEmployeeInfo,
|
|
@@ -17,7 +14,12 @@ import {
|
|
|
17
14
|
OauthProfile,
|
|
18
15
|
ProfileResponse,
|
|
19
16
|
AgencyGraphQL,
|
|
17
|
+
VariableGraphQL,
|
|
18
|
+
GraphQLToken,
|
|
19
|
+
AxiosUtilsResponse,
|
|
20
20
|
} from "@zauru-sdk/types";
|
|
21
|
+
import { handlePossibleAxiosErrors } from "@zauru-sdk/common";
|
|
22
|
+
import { getVariables } from "./zauru/zauru-variables.server.js";
|
|
21
23
|
|
|
22
24
|
/**
|
|
23
25
|
* loginWebApp
|
|
@@ -107,15 +109,6 @@ export const loginWebApp = async (
|
|
|
107
109
|
});
|
|
108
110
|
};
|
|
109
111
|
|
|
110
|
-
export type GraphQLToken = {
|
|
111
|
-
status: number;
|
|
112
|
-
message: string;
|
|
113
|
-
token: string;
|
|
114
|
-
expires: string;
|
|
115
|
-
expiresMsg: string;
|
|
116
|
-
graphqlUrl: string;
|
|
117
|
-
};
|
|
118
|
-
|
|
119
112
|
/**
|
|
120
113
|
* Obtiene los headers que se usan en todos los endpoints de zauru
|
|
121
114
|
* @param cookie
|
|
@@ -293,3 +286,58 @@ export function generateDistinctCode(prefix: string) {
|
|
|
293
286
|
const codigoProducto = `${prefix}-${uuid}`;
|
|
294
287
|
return codigoProducto;
|
|
295
288
|
}
|
|
289
|
+
/**
|
|
290
|
+
*
|
|
291
|
+
* @param headers
|
|
292
|
+
* @param session
|
|
293
|
+
* @param names
|
|
294
|
+
* @returns
|
|
295
|
+
*/
|
|
296
|
+
export async function getVariablesByName(
|
|
297
|
+
headers: any,
|
|
298
|
+
session: Session,
|
|
299
|
+
names: Array<string>
|
|
300
|
+
): Promise<{ [key: string]: string }> {
|
|
301
|
+
//variables
|
|
302
|
+
let variables: VariableGraphQL[] = [];
|
|
303
|
+
|
|
304
|
+
//consulto si ya están guardadas en la sesión
|
|
305
|
+
const tempVars: VariableGraphQL[] = session.get("variables");
|
|
306
|
+
if (Array.isArray(tempVars) && tempVars.length) {
|
|
307
|
+
//si ya están guardadas, uso esas
|
|
308
|
+
variables = tempVars;
|
|
309
|
+
} else {
|
|
310
|
+
//si no están en la sesión, las obtengo de zauru y luego las guardo en la sesión
|
|
311
|
+
//Obtengo mis variables, para tener los tags solicitados
|
|
312
|
+
const response = await getVariables(headers);
|
|
313
|
+
if (response.error) {
|
|
314
|
+
throw new Error(`${response.userMsg} - ${response.msg}`);
|
|
315
|
+
}
|
|
316
|
+
session.set("variables", response.data);
|
|
317
|
+
await commitSession(session);
|
|
318
|
+
variables = response.data ?? [];
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
const filtrados = variables.filter((value: VariableGraphQL) =>
|
|
322
|
+
names.includes(value.name)
|
|
323
|
+
);
|
|
324
|
+
|
|
325
|
+
const returnObject: { [key: string]: string } = {};
|
|
326
|
+
filtrados.forEach((variable) => {
|
|
327
|
+
returnObject[`${variable.name}`] = variable.value;
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
//Pregunto si todas las variables fueron encontradas o no
|
|
331
|
+
if (
|
|
332
|
+
!names.every((variable) => Object.keys(returnObject).includes(variable))
|
|
333
|
+
) {
|
|
334
|
+
const noEncontradas = names
|
|
335
|
+
.filter((variable) => !Object.keys(returnObject).includes(variable))
|
|
336
|
+
.join(",");
|
|
337
|
+
throw new Error(
|
|
338
|
+
`No se encontraron las variables: ${noEncontradas} pruebe cerrar e iniciar sesión nuevamente para continuar.`
|
|
339
|
+
);
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
return returnObject;
|
|
343
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -8,4 +8,26 @@ export * from "./zauru/httpOauth.server.js";
|
|
|
8
8
|
export * from "./zauru/httpZauru.server.js";
|
|
9
9
|
|
|
10
10
|
export * from "./zauru/zauru-agencies.server.js";
|
|
11
|
+
export * from "./zauru/zauru-automatic-numbers.server.js";
|
|
12
|
+
export * from "./zauru/zauru-currencies.server.js";
|
|
13
|
+
export * from "./zauru/zauru-deliveries.server.js";
|
|
14
|
+
export * from "./zauru/zauru-discharges.server.js";
|
|
15
|
+
export * from "./zauru/zauru-employees.server.js";
|
|
16
|
+
export * from "./zauru/zauru-forms.server.js";
|
|
17
|
+
export * from "./zauru/zauru-invoices.server.js";
|
|
18
|
+
export * from "./zauru/zauru-items.server.js";
|
|
19
|
+
export * from "./zauru/zauru-lote-record.server.js";
|
|
20
|
+
export * from "./zauru/zauru-lotes.server.js";
|
|
21
|
+
export * from "./zauru/zauru-motivos-rechazo.server.js";
|
|
22
|
+
export * from "./zauru/zauru-payees.server.js";
|
|
23
|
+
export * from "./zauru/zauru-payment-terms.server.js";
|
|
24
|
+
export * from "./zauru/zauru-price-lists.server.js";
|
|
25
|
+
export * from "./zauru/zauru-purchase-orders.server.js";
|
|
11
26
|
export * from "./zauru/zauru-profiles.server.js";
|
|
27
|
+
export * from "./zauru/zauru-receptions.server.js";
|
|
28
|
+
export * from "./zauru/zauru-shipments.server.js";
|
|
29
|
+
export * from "./zauru/zauru-suggested-prices.server.js";
|
|
30
|
+
export * from "./zauru/zauru-tags.server.js";
|
|
31
|
+
export * from "./zauru/zauru-templates.server.js";
|
|
32
|
+
export * from "./zauru/zauru-web-app-tables.server.js";
|
|
33
|
+
export * from "./zauru/zauru-variables.server.js";
|
|
@@ -1,29 +1,7 @@
|
|
|
1
1
|
import axios from "axios";
|
|
2
2
|
import chalk from "chalk";
|
|
3
3
|
import { config } from "@zauru-sdk/config";
|
|
4
|
-
|
|
5
|
-
export type AxiosUtilsResponse<T> = {
|
|
6
|
-
error?: boolean;
|
|
7
|
-
msg?: string;
|
|
8
|
-
userMsg?: string;
|
|
9
|
-
data?: T;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Handle web app table actions and return a response with a consistent format.
|
|
14
|
-
* @param action A function that returns a Promise of type T.
|
|
15
|
-
* @returns A Promise of AxiosUtilsResponse<T>.
|
|
16
|
-
*/
|
|
17
|
-
export async function handlePossibleAxiosErrors<T>(
|
|
18
|
-
action: () => Promise<T>
|
|
19
|
-
): Promise<AxiosUtilsResponse<T>> {
|
|
20
|
-
try {
|
|
21
|
-
const result = await action();
|
|
22
|
-
return { error: false, data: result } as AxiosUtilsResponse<T>;
|
|
23
|
-
} catch (error) {
|
|
24
|
-
return { error: true, userMsg: error?.toString() } as AxiosUtilsResponse<T>;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
4
|
+
import { AxiosUtilsResponse } from "@zauru-sdk/types";
|
|
27
5
|
|
|
28
6
|
const axiosInstance = axios.create({
|
|
29
7
|
baseURL: `${config.zauruBaseURL}`,
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import type { Session } from "@remix-run/node";
|
|
2
|
-
import
|
|
3
|
-
import { handlePossibleAxiosErrors } from "./httpZauru.server.js";
|
|
2
|
+
import { handlePossibleAxiosErrors } from "@zauru-sdk/common";
|
|
4
3
|
import httpGraphQLAPI from "./httpGraphQL.server.js";
|
|
5
4
|
import { getGraphQLAPIHeaders } from "~/common.server.js";
|
|
6
5
|
import { getAgenciesStringQuery } from "@zauru-sdk/graphql";
|
|
7
|
-
import type { AgencyGraphQL } from "@zauru-sdk/types";
|
|
6
|
+
import type { AgencyGraphQL, AxiosUtilsResponse } from "@zauru-sdk/types";
|
|
8
7
|
|
|
9
8
|
/**
|
|
10
9
|
* getAgencies
|