@zauru-sdk/services 1.0.4 → 1.0.6
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 +12 -12
- package/dist/common.server.js +44 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -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 +3 -4
- 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-profiles.server.d.ts +2 -141
- package/dist/zauru/zauru-profiles.server.js +2 -1
- package/dist/zauru/zauru-variables.server.d.ts +14 -0
- package/dist/zauru/zauru-variables.server.js +48 -0
- package/package.json +5 -3
- package/src/common.server.ts +69 -19
- package/src/index.ts +2 -0
- package/src/zauru/httpZauru.server.ts +1 -23
- package/src/zauru/zauru-agencies.server.ts +4 -7
- package/src/zauru/zauru-automatic-numbers.server.ts +35 -0
- package/src/zauru/zauru-profiles.server.ts +11 -148
- package/src/zauru/zauru-variables.server.ts +67 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,22 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [1.0.6](https://github.com/intuitiva/zauru-typescript-sdk/compare/v1.0.5...v1.0.6) (2024-03-16)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @zauru-sdk/services
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [1.0.5](https://github.com/intuitiva/zauru-typescript-sdk/compare/v1.0.4...v1.0.5) (2024-03-16)
|
|
15
|
+
|
|
16
|
+
**Note:** Version bump only for package @zauru-sdk/services
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
6
22
|
## [1.0.4](https://github.com/intuitiva/zauru-typescript-sdk/compare/v1.0.3...v1.0.4) (2024-03-15)
|
|
7
23
|
|
|
8
24
|
**Note:** Version bump only for package @zauru-sdk/services
|
package/dist/common.server.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { Session } from "@remix-run/node";
|
|
2
2
|
import { AxiosRequestHeaders } from "axios";
|
|
3
|
-
import { AxiosUtilsResponse } from "
|
|
4
|
-
import { Agency, OauthProfile, ProfileResponse } from "./zauru/zauru-profiles.server.js";
|
|
5
|
-
import { EmployeeGraphQL } from "@zauru-sdk/graphql";
|
|
3
|
+
import { EmployeeGraphQL, OauthProfile, ProfileResponse, AgencyGraphQL, AxiosUtilsResponse } from "@zauru-sdk/types";
|
|
6
4
|
/**
|
|
7
5
|
* loginWebApp
|
|
8
6
|
* @param session
|
|
@@ -15,16 +13,8 @@ export declare const loginWebApp: (session: Session, codeValue: string, cookie:
|
|
|
15
13
|
oauthProfile: OauthProfile;
|
|
16
14
|
employeeProfile: EmployeeGraphQL;
|
|
17
15
|
userProfile: ProfileResponse;
|
|
18
|
-
agencyProfile:
|
|
16
|
+
agencyProfile: AgencyGraphQL;
|
|
19
17
|
}>>;
|
|
20
|
-
export type GraphQLToken = {
|
|
21
|
-
status: number;
|
|
22
|
-
message: string;
|
|
23
|
-
token: string;
|
|
24
|
-
expires: string;
|
|
25
|
-
expiresMsg: string;
|
|
26
|
-
graphqlUrl: string;
|
|
27
|
-
};
|
|
28
18
|
/**
|
|
29
19
|
* Obtiene los headers que se usan en todos los endpoints de zauru
|
|
30
20
|
* @param cookie
|
|
@@ -53,3 +43,13 @@ export type SessionMessage = {
|
|
|
53
43
|
export declare const saveSessionMessage: (session: Session, info: SessionMessage) => Promise<void>;
|
|
54
44
|
export declare const deleteSessionMessage: (session: Session, id: string) => Promise<boolean>;
|
|
55
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
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { redirect } from "@remix-run/node";
|
|
2
2
|
import { commitSession, getSession } from "./sessions/sessions.server.js";
|
|
3
3
|
import chalk from "chalk";
|
|
4
|
-
import httpZauru
|
|
4
|
+
import httpZauru from "./zauru/httpZauru.server.js";
|
|
5
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";
|
|
6
8
|
/**
|
|
7
9
|
* loginWebApp
|
|
8
10
|
* @param session
|
|
@@ -177,3 +179,44 @@ export function generateDistinctCode(prefix) {
|
|
|
177
179
|
const codigoProducto = `${prefix}-${uuid}`;
|
|
178
180
|
return codigoProducto;
|
|
179
181
|
}
|
|
182
|
+
/**
|
|
183
|
+
*
|
|
184
|
+
* @param headers
|
|
185
|
+
* @param session
|
|
186
|
+
* @param names
|
|
187
|
+
* @returns
|
|
188
|
+
*/
|
|
189
|
+
export async function getVariablesByName(headers, session, names) {
|
|
190
|
+
//variables
|
|
191
|
+
let variables = [];
|
|
192
|
+
//consulto si ya están guardadas en la sesión
|
|
193
|
+
const tempVars = session.get("variables");
|
|
194
|
+
if (Array.isArray(tempVars) && tempVars.length) {
|
|
195
|
+
//si ya están guardadas, uso esas
|
|
196
|
+
variables = tempVars;
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
//si no están en la sesión, las obtengo de zauru y luego las guardo en la sesión
|
|
200
|
+
//Obtengo mis variables, para tener los tags solicitados
|
|
201
|
+
const response = await getVariables(headers);
|
|
202
|
+
if (response.error) {
|
|
203
|
+
throw new Error(`${response.userMsg} - ${response.msg}`);
|
|
204
|
+
}
|
|
205
|
+
session.set("variables", response.data);
|
|
206
|
+
await commitSession(session);
|
|
207
|
+
variables = response.data ?? [];
|
|
208
|
+
}
|
|
209
|
+
const filtrados = variables.filter((value) => names.includes(value.name));
|
|
210
|
+
const returnObject = {};
|
|
211
|
+
filtrados.forEach((variable) => {
|
|
212
|
+
returnObject[`${variable.name}`] = variable.value;
|
|
213
|
+
});
|
|
214
|
+
//Pregunto si todas las variables fueron encontradas o no
|
|
215
|
+
if (!names.every((variable) => Object.keys(returnObject).includes(variable))) {
|
|
216
|
+
const noEncontradas = names
|
|
217
|
+
.filter((variable) => !Object.keys(returnObject).includes(variable))
|
|
218
|
+
.join(",");
|
|
219
|
+
throw new Error(`No se encontraron las variables: ${noEncontradas} pruebe cerrar e iniciar sesión nuevamente para continuar.`);
|
|
220
|
+
}
|
|
221
|
+
return returnObject;
|
|
222
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -5,4 +5,6 @@ export * from "./zauru/httpGraphQL.server.js";
|
|
|
5
5
|
export * from "./zauru/httpOauth.server.js";
|
|
6
6
|
export * from "./zauru/httpZauru.server.js";
|
|
7
7
|
export * from "./zauru/zauru-agencies.server.js";
|
|
8
|
+
export * from "./zauru/zauru-automatic-numbers.server.js";
|
|
8
9
|
export * from "./zauru/zauru-profiles.server.js";
|
|
10
|
+
export * from "./zauru/zauru-variables.server.js";
|
package/dist/index.js
CHANGED
|
@@ -5,4 +5,6 @@ export * from "./zauru/httpGraphQL.server.js";
|
|
|
5
5
|
export * from "./zauru/httpOauth.server.js";
|
|
6
6
|
export * from "./zauru/httpZauru.server.js";
|
|
7
7
|
export * from "./zauru/zauru-agencies.server.js";
|
|
8
|
+
export * from "./zauru/zauru-automatic-numbers.server.js";
|
|
8
9
|
export * from "./zauru/zauru-profiles.server.js";
|
|
10
|
+
export * from "./zauru/zauru-variables.server.js";
|
|
@@ -1,14 +1,2 @@
|
|
|
1
|
-
export type AxiosUtilsResponse<T> = {
|
|
2
|
-
error?: boolean;
|
|
3
|
-
msg?: string;
|
|
4
|
-
userMsg?: string;
|
|
5
|
-
data?: T;
|
|
6
|
-
};
|
|
7
|
-
/**
|
|
8
|
-
* Handle web app table actions and return a response with a consistent format.
|
|
9
|
-
* @param action A function that returns a Promise of type T.
|
|
10
|
-
* @returns A Promise of AxiosUtilsResponse<T>.
|
|
11
|
-
*/
|
|
12
|
-
export declare function handlePossibleAxiosErrors<T>(action: () => Promise<T>): Promise<AxiosUtilsResponse<T>>;
|
|
13
1
|
declare const httpZauru: import("axios").AxiosInstance;
|
|
14
2
|
export default httpZauru;
|
|
@@ -1,20 +1,6 @@
|
|
|
1
1
|
import axios from "axios";
|
|
2
2
|
import chalk from "chalk";
|
|
3
3
|
import { config } from "@zauru-sdk/config";
|
|
4
|
-
/**
|
|
5
|
-
* Handle web app table actions and return a response with a consistent format.
|
|
6
|
-
* @param action A function that returns a Promise of type T.
|
|
7
|
-
* @returns A Promise of AxiosUtilsResponse<T>.
|
|
8
|
-
*/
|
|
9
|
-
export async function handlePossibleAxiosErrors(action) {
|
|
10
|
-
try {
|
|
11
|
-
const result = await action();
|
|
12
|
-
return { error: false, data: result };
|
|
13
|
-
}
|
|
14
|
-
catch (error) {
|
|
15
|
-
return { error: true, userMsg: error?.toString() };
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
4
|
const axiosInstance = axios.create({
|
|
19
5
|
baseURL: `${config.zauruBaseURL}`,
|
|
20
6
|
});
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { Session } from "@remix-run/node";
|
|
2
|
-
import type { AgencyGraphQL } from "@zauru-sdk/
|
|
3
|
-
import type { AxiosUtilsResponse } from "./httpZauru.server.js";
|
|
2
|
+
import type { AgencyGraphQL, AxiosUtilsResponse } from "@zauru-sdk/types";
|
|
4
3
|
/**
|
|
5
4
|
* getAgencies
|
|
6
5
|
* @param headers
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { handlePossibleAxiosErrors } from "
|
|
1
|
+
import { handlePossibleAxiosErrors } from "@zauru-sdk/common";
|
|
2
2
|
import httpGraphQLAPI from "./httpGraphQL.server.js";
|
|
3
3
|
import { getGraphQLAPIHeaders } from "~/common.server.js";
|
|
4
|
-
import
|
|
5
|
-
const { default: queries } = graphql;
|
|
4
|
+
import { getAgenciesStringQuery } from "@zauru-sdk/graphql";
|
|
6
5
|
/**
|
|
7
6
|
* getAgencies
|
|
8
7
|
* @param headers
|
|
@@ -12,7 +11,7 @@ export async function getAgencies(session) {
|
|
|
12
11
|
return handlePossibleAxiosErrors(async () => {
|
|
13
12
|
const headers = await getGraphQLAPIHeaders(session);
|
|
14
13
|
const response = await httpGraphQLAPI.post(``, {
|
|
15
|
-
query:
|
|
14
|
+
query: getAgenciesStringQuery,
|
|
16
15
|
}, {
|
|
17
16
|
headers,
|
|
18
17
|
});
|
|
@@ -0,0 +1,8 @@
|
|
|
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>>;
|
|
@@ -0,0 +1,21 @@
|
|
|
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,143 +1,5 @@
|
|
|
1
1
|
import type { Session } from "@remix-run/node";
|
|
2
|
-
import
|
|
3
|
-
import { EmployeeGraphQL } from "@zauru-sdk/graphql";
|
|
4
|
-
interface Logo {
|
|
5
|
-
url: null | string;
|
|
6
|
-
thumb: {
|
|
7
|
-
url: null | string;
|
|
8
|
-
};
|
|
9
|
-
standard: {
|
|
10
|
-
url: null | string;
|
|
11
|
-
};
|
|
12
|
-
header: {
|
|
13
|
-
url: null | string;
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
export type OauthProfile = {
|
|
17
|
-
id: number;
|
|
18
|
-
uid: number;
|
|
19
|
-
username: string;
|
|
20
|
-
name: string;
|
|
21
|
-
time_zone: string;
|
|
22
|
-
mobile_phone: string;
|
|
23
|
-
admin: boolean;
|
|
24
|
-
selected_entity: number;
|
|
25
|
-
selected_entity_name: string;
|
|
26
|
-
selected_entity_logo: string;
|
|
27
|
-
selected_entity_role: number;
|
|
28
|
-
employee_id: number;
|
|
29
|
-
crm_admin: boolean;
|
|
30
|
-
crm_supervisor: boolean;
|
|
31
|
-
crm_user: boolean;
|
|
32
|
-
currency_id: number;
|
|
33
|
-
currency_name: string;
|
|
34
|
-
currency_prefix: string;
|
|
35
|
-
api_key: string;
|
|
36
|
-
scope: string;
|
|
37
|
-
email: string;
|
|
38
|
-
};
|
|
39
|
-
interface Entity {
|
|
40
|
-
id: number;
|
|
41
|
-
name: string;
|
|
42
|
-
tin: string;
|
|
43
|
-
country: string;
|
|
44
|
-
currency_id: number;
|
|
45
|
-
entity_type_id: number;
|
|
46
|
-
industry: string;
|
|
47
|
-
web: string;
|
|
48
|
-
notes: string;
|
|
49
|
-
vat: number;
|
|
50
|
-
vat_included: boolean;
|
|
51
|
-
logo: Logo;
|
|
52
|
-
logo_2: Logo;
|
|
53
|
-
created_at: string;
|
|
54
|
-
updated_at: string;
|
|
55
|
-
distributor: number;
|
|
56
|
-
costing_method: string;
|
|
57
|
-
address: string;
|
|
58
|
-
state: string;
|
|
59
|
-
city: string;
|
|
60
|
-
income_tax: number;
|
|
61
|
-
report_logo: Logo;
|
|
62
|
-
distributor_contract_id: number | null;
|
|
63
|
-
producer_contract_id: number | null;
|
|
64
|
-
legal_representative_name: string | null;
|
|
65
|
-
legal_representative_identification: string | null;
|
|
66
|
-
legal_representative_birthday: string | null;
|
|
67
|
-
legal_representative_gender: boolean;
|
|
68
|
-
legal_representative_marital_status: string | null;
|
|
69
|
-
legal_representative_occupation: string | null;
|
|
70
|
-
legal_representative_nationality: string | null;
|
|
71
|
-
exporter_code: string | null;
|
|
72
|
-
}
|
|
73
|
-
export type Agency = {
|
|
74
|
-
id: number;
|
|
75
|
-
zid: number;
|
|
76
|
-
active: boolean;
|
|
77
|
-
ean13: string;
|
|
78
|
-
name: string;
|
|
79
|
-
employee_id: number | null;
|
|
80
|
-
updater_id: number;
|
|
81
|
-
entity_id: number;
|
|
82
|
-
virtual: boolean;
|
|
83
|
-
virtual_type: string | null;
|
|
84
|
-
warehouse: boolean;
|
|
85
|
-
point_of_sale: boolean;
|
|
86
|
-
workshop: boolean;
|
|
87
|
-
factory: boolean;
|
|
88
|
-
contact: string;
|
|
89
|
-
city: string;
|
|
90
|
-
address_line_1: string;
|
|
91
|
-
address_line_2: string;
|
|
92
|
-
phone: string;
|
|
93
|
-
notes: string;
|
|
94
|
-
created_at: string;
|
|
95
|
-
updated_at: string;
|
|
96
|
-
price_list_id: number | null;
|
|
97
|
-
quote: boolean;
|
|
98
|
-
ecommerce: boolean;
|
|
99
|
-
external_storage_service_name: string;
|
|
100
|
-
agency_category_id: number | null;
|
|
101
|
-
};
|
|
102
|
-
export type Membership = {
|
|
103
|
-
id: number;
|
|
104
|
-
active: boolean;
|
|
105
|
-
current: boolean;
|
|
106
|
-
reference: string;
|
|
107
|
-
starts: string;
|
|
108
|
-
expires: string;
|
|
109
|
-
eternal: boolean;
|
|
110
|
-
entity_id: number;
|
|
111
|
-
notes: string;
|
|
112
|
-
created_at: string;
|
|
113
|
-
updated_at: string;
|
|
114
|
-
licenses_count: number;
|
|
115
|
-
entity: Entity;
|
|
116
|
-
};
|
|
117
|
-
type Profile = {
|
|
118
|
-
id: number;
|
|
119
|
-
email: string;
|
|
120
|
-
active: boolean;
|
|
121
|
-
admin: boolean;
|
|
122
|
-
name: string;
|
|
123
|
-
address: null | string;
|
|
124
|
-
mobile_phone: string;
|
|
125
|
-
birthday: null | string;
|
|
126
|
-
gender: boolean;
|
|
127
|
-
notes: null | string;
|
|
128
|
-
time_zone: string;
|
|
129
|
-
language: string;
|
|
130
|
-
selected_entity_id: number;
|
|
131
|
-
created_at: string;
|
|
132
|
-
updated_at: string;
|
|
133
|
-
authentication_token: string;
|
|
134
|
-
provider: string;
|
|
135
|
-
provider_token: string;
|
|
136
|
-
};
|
|
137
|
-
export type ProfileResponse = {
|
|
138
|
-
profile: Profile;
|
|
139
|
-
memberships: Membership[];
|
|
140
|
-
};
|
|
2
|
+
import { AgencyGraphQL, EmployeeGraphQL, OauthProfile, ProfileResponse, AxiosUtilsResponse } from "@zauru-sdk/types";
|
|
141
3
|
/**
|
|
142
4
|
* getOauthUserInfo
|
|
143
5
|
* @param codeValue
|
|
@@ -163,5 +25,4 @@ export declare const changeEntity: (headers: any, entityId: string) => Promise<a
|
|
|
163
25
|
* @param headers
|
|
164
26
|
* @returns
|
|
165
27
|
*/
|
|
166
|
-
export declare const getAgencyInfo: (headers: any, session: Session) => Promise<AxiosUtilsResponse<
|
|
167
|
-
export {};
|
|
28
|
+
export declare const getAgencyInfo: (headers: any, session: Session) => Promise<AxiosUtilsResponse<AgencyGraphQL>>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import httpZauru
|
|
1
|
+
import httpZauru from "./httpZauru.server.js";
|
|
2
2
|
import httpOauth from "./httpOauth.server.js";
|
|
3
|
+
import { handlePossibleAxiosErrors } from "@zauru-sdk/common";
|
|
3
4
|
import { config } from "@zauru-sdk/config";
|
|
4
5
|
/**
|
|
5
6
|
* getOauthUserInfo
|
|
@@ -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
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zauru-sdk/services",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "Configuración centralizada para aplicaciones Zauru SDK",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -19,13 +19,15 @@
|
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@remix-run/node": "^2.8.1",
|
|
22
|
+
"@zauru-sdk/common": "^1.0.6",
|
|
22
23
|
"@zauru-sdk/config": "^1.0.4",
|
|
23
|
-
"@zauru-sdk/graphql": "^1.0.
|
|
24
|
+
"@zauru-sdk/graphql": "^1.0.5",
|
|
25
|
+
"@zauru-sdk/types": "^1.0.6",
|
|
24
26
|
"axios": "^1.6.7",
|
|
25
27
|
"chalk": "5.3.0"
|
|
26
28
|
},
|
|
27
29
|
"engines": {
|
|
28
30
|
"node": ">=18.0.0"
|
|
29
31
|
},
|
|
30
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "d49d7b1cec4ab5685b34983c46d97db129115aaf"
|
|
31
33
|
}
|
package/src/common.server.ts
CHANGED
|
@@ -2,20 +2,24 @@ 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
|
-
Agency,
|
|
11
|
-
OauthProfile,
|
|
12
|
-
ProfileResponse,
|
|
13
7
|
getAgencyInfo,
|
|
14
8
|
getEmployeeInfo,
|
|
15
9
|
getOauthUserInfo,
|
|
16
10
|
getProfileInformation,
|
|
17
11
|
} from "./zauru/zauru-profiles.server.js";
|
|
18
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
EmployeeGraphQL,
|
|
14
|
+
OauthProfile,
|
|
15
|
+
ProfileResponse,
|
|
16
|
+
AgencyGraphQL,
|
|
17
|
+
VariableGraphQL,
|
|
18
|
+
GraphQLToken,
|
|
19
|
+
AxiosUtilsResponse,
|
|
20
|
+
} from "@zauru-sdk/types";
|
|
21
|
+
import { handlePossibleAxiosErrors } from "@zauru-sdk/common";
|
|
22
|
+
import { getVariables } from "./zauru/zauru-variables.server.js";
|
|
19
23
|
|
|
20
24
|
/**
|
|
21
25
|
* loginWebApp
|
|
@@ -34,7 +38,7 @@ export const loginWebApp = async (
|
|
|
34
38
|
oauthProfile: OauthProfile;
|
|
35
39
|
employeeProfile: EmployeeGraphQL;
|
|
36
40
|
userProfile: ProfileResponse;
|
|
37
|
-
agencyProfile:
|
|
41
|
+
agencyProfile: AgencyGraphQL;
|
|
38
42
|
}>
|
|
39
43
|
> => {
|
|
40
44
|
return handlePossibleAxiosErrors(async () => {
|
|
@@ -100,20 +104,11 @@ export const loginWebApp = async (
|
|
|
100
104
|
oauthProfile: userInfo as OauthProfile,
|
|
101
105
|
employeeProfile: empInfo as EmployeeGraphQL,
|
|
102
106
|
userProfile: profileInfo as ProfileResponse,
|
|
103
|
-
agencyProfile: agencyInfoResponse.data as
|
|
107
|
+
agencyProfile: agencyInfoResponse.data as AgencyGraphQL,
|
|
104
108
|
};
|
|
105
109
|
});
|
|
106
110
|
};
|
|
107
111
|
|
|
108
|
-
export type GraphQLToken = {
|
|
109
|
-
status: number;
|
|
110
|
-
message: string;
|
|
111
|
-
token: string;
|
|
112
|
-
expires: string;
|
|
113
|
-
expiresMsg: string;
|
|
114
|
-
graphqlUrl: string;
|
|
115
|
-
};
|
|
116
|
-
|
|
117
112
|
/**
|
|
118
113
|
* Obtiene los headers que se usan en todos los endpoints de zauru
|
|
119
114
|
* @param cookie
|
|
@@ -291,3 +286,58 @@ export function generateDistinctCode(prefix: string) {
|
|
|
291
286
|
const codigoProducto = `${prefix}-${uuid}`;
|
|
292
287
|
return codigoProducto;
|
|
293
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,6 @@ 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";
|
|
11
12
|
export * from "./zauru/zauru-profiles.server.js";
|
|
13
|
+
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,12 +1,9 @@
|
|
|
1
1
|
import type { Session } from "@remix-run/node";
|
|
2
|
-
import
|
|
3
|
-
import type { AxiosUtilsResponse } from "./httpZauru.server.js";
|
|
4
|
-
import { handlePossibleAxiosErrors } from "./httpZauru.server.js";
|
|
2
|
+
import { handlePossibleAxiosErrors } from "@zauru-sdk/common";
|
|
5
3
|
import httpGraphQLAPI from "./httpGraphQL.server.js";
|
|
6
4
|
import { getGraphQLAPIHeaders } from "~/common.server.js";
|
|
7
|
-
import
|
|
8
|
-
|
|
9
|
-
const { default: queries } = graphql;
|
|
5
|
+
import { getAgenciesStringQuery } from "@zauru-sdk/graphql";
|
|
6
|
+
import type { AgencyGraphQL, AxiosUtilsResponse } from "@zauru-sdk/types";
|
|
10
7
|
|
|
11
8
|
/**
|
|
12
9
|
* getAgencies
|
|
@@ -23,7 +20,7 @@ export async function getAgencies(
|
|
|
23
20
|
}>(
|
|
24
21
|
``,
|
|
25
22
|
{
|
|
26
|
-
query:
|
|
23
|
+
query: getAgenciesStringQuery,
|
|
27
24
|
},
|
|
28
25
|
{
|
|
29
26
|
headers,
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DocumentAutomaticNumberGraphQL,
|
|
3
|
+
AxiosUtilsResponse,
|
|
4
|
+
} from "@zauru-sdk/types";
|
|
5
|
+
import { handlePossibleAxiosErrors } from "@zauru-sdk/common";
|
|
6
|
+
import httpZauru from "./httpZauru.server.js";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* updateAutomaticNumber
|
|
10
|
+
* @param headers
|
|
11
|
+
* @param body
|
|
12
|
+
* @returns
|
|
13
|
+
*/
|
|
14
|
+
export const updateAutomaticNumber = async (
|
|
15
|
+
headers: any,
|
|
16
|
+
body: Partial<DocumentAutomaticNumberGraphQL>
|
|
17
|
+
): Promise<AxiosUtilsResponse<DocumentAutomaticNumberGraphQL>> => {
|
|
18
|
+
return handlePossibleAxiosErrors(async () => {
|
|
19
|
+
const sendBody: any = {
|
|
20
|
+
document_automatic_number: {
|
|
21
|
+
...body,
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const response = await httpZauru.put<DocumentAutomaticNumberGraphQL>(
|
|
26
|
+
`/settings/templates/document_automatic_numbers/${body.id}.json`,
|
|
27
|
+
sendBody,
|
|
28
|
+
{
|
|
29
|
+
headers,
|
|
30
|
+
}
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
return response.data;
|
|
34
|
+
});
|
|
35
|
+
};
|
|
@@ -1,153 +1,16 @@
|
|
|
1
1
|
import type { Session } from "@remix-run/node";
|
|
2
|
-
import
|
|
3
|
-
import httpZauru, { handlePossibleAxiosErrors } from "./httpZauru.server.js";
|
|
2
|
+
import httpZauru from "./httpZauru.server.js";
|
|
4
3
|
import httpOauth from "./httpOauth.server.js";
|
|
5
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
AgencyGraphQL,
|
|
6
|
+
EmployeeGraphQL,
|
|
7
|
+
OauthProfile,
|
|
8
|
+
ProfileResponse,
|
|
9
|
+
AxiosUtilsResponse,
|
|
10
|
+
} from "@zauru-sdk/types";
|
|
11
|
+
import { handlePossibleAxiosErrors } from "@zauru-sdk/common";
|
|
6
12
|
import { config } from "@zauru-sdk/config";
|
|
7
13
|
|
|
8
|
-
interface Logo {
|
|
9
|
-
url: null | string;
|
|
10
|
-
thumb: {
|
|
11
|
-
url: null | string;
|
|
12
|
-
};
|
|
13
|
-
standard: {
|
|
14
|
-
url: null | string;
|
|
15
|
-
};
|
|
16
|
-
header: {
|
|
17
|
-
url: null | string;
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export type OauthProfile = {
|
|
22
|
-
id: number;
|
|
23
|
-
uid: number;
|
|
24
|
-
username: string;
|
|
25
|
-
name: string;
|
|
26
|
-
time_zone: string;
|
|
27
|
-
mobile_phone: string;
|
|
28
|
-
admin: boolean;
|
|
29
|
-
selected_entity: number;
|
|
30
|
-
selected_entity_name: string;
|
|
31
|
-
selected_entity_logo: string;
|
|
32
|
-
selected_entity_role: number;
|
|
33
|
-
employee_id: number;
|
|
34
|
-
crm_admin: boolean;
|
|
35
|
-
crm_supervisor: boolean;
|
|
36
|
-
crm_user: boolean;
|
|
37
|
-
currency_id: number;
|
|
38
|
-
currency_name: string;
|
|
39
|
-
currency_prefix: string;
|
|
40
|
-
api_key: string;
|
|
41
|
-
scope: string;
|
|
42
|
-
email: string;
|
|
43
|
-
};
|
|
44
|
-
interface Entity {
|
|
45
|
-
id: number;
|
|
46
|
-
name: string;
|
|
47
|
-
tin: string;
|
|
48
|
-
country: string;
|
|
49
|
-
currency_id: number;
|
|
50
|
-
entity_type_id: number;
|
|
51
|
-
industry: string;
|
|
52
|
-
web: string;
|
|
53
|
-
notes: string;
|
|
54
|
-
vat: number;
|
|
55
|
-
vat_included: boolean;
|
|
56
|
-
logo: Logo;
|
|
57
|
-
logo_2: Logo;
|
|
58
|
-
created_at: string;
|
|
59
|
-
updated_at: string;
|
|
60
|
-
distributor: number;
|
|
61
|
-
costing_method: string;
|
|
62
|
-
address: string;
|
|
63
|
-
state: string;
|
|
64
|
-
city: string;
|
|
65
|
-
income_tax: number;
|
|
66
|
-
report_logo: Logo;
|
|
67
|
-
distributor_contract_id: number | null;
|
|
68
|
-
producer_contract_id: number | null;
|
|
69
|
-
legal_representative_name: string | null;
|
|
70
|
-
legal_representative_identification: string | null;
|
|
71
|
-
legal_representative_birthday: string | null;
|
|
72
|
-
legal_representative_gender: boolean;
|
|
73
|
-
legal_representative_marital_status: string | null;
|
|
74
|
-
legal_representative_occupation: string | null;
|
|
75
|
-
legal_representative_nationality: string | null;
|
|
76
|
-
exporter_code: string | null;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export type Agency = {
|
|
80
|
-
id: number;
|
|
81
|
-
zid: number;
|
|
82
|
-
active: boolean;
|
|
83
|
-
ean13: string;
|
|
84
|
-
name: string;
|
|
85
|
-
employee_id: number | null;
|
|
86
|
-
updater_id: number;
|
|
87
|
-
entity_id: number;
|
|
88
|
-
virtual: boolean;
|
|
89
|
-
virtual_type: string | null;
|
|
90
|
-
warehouse: boolean;
|
|
91
|
-
point_of_sale: boolean;
|
|
92
|
-
workshop: boolean;
|
|
93
|
-
factory: boolean;
|
|
94
|
-
contact: string;
|
|
95
|
-
city: string;
|
|
96
|
-
address_line_1: string;
|
|
97
|
-
address_line_2: string;
|
|
98
|
-
phone: string;
|
|
99
|
-
notes: string;
|
|
100
|
-
created_at: string;
|
|
101
|
-
updated_at: string;
|
|
102
|
-
price_list_id: number | null;
|
|
103
|
-
quote: boolean;
|
|
104
|
-
ecommerce: boolean;
|
|
105
|
-
external_storage_service_name: string;
|
|
106
|
-
agency_category_id: number | null;
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
export type Membership = {
|
|
110
|
-
id: number;
|
|
111
|
-
active: boolean;
|
|
112
|
-
current: boolean;
|
|
113
|
-
reference: string;
|
|
114
|
-
starts: string;
|
|
115
|
-
expires: string;
|
|
116
|
-
eternal: boolean;
|
|
117
|
-
entity_id: number;
|
|
118
|
-
notes: string;
|
|
119
|
-
created_at: string;
|
|
120
|
-
updated_at: string;
|
|
121
|
-
licenses_count: number;
|
|
122
|
-
entity: Entity;
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
type Profile = {
|
|
126
|
-
id: number;
|
|
127
|
-
email: string;
|
|
128
|
-
active: boolean;
|
|
129
|
-
admin: boolean;
|
|
130
|
-
name: string;
|
|
131
|
-
address: null | string;
|
|
132
|
-
mobile_phone: string;
|
|
133
|
-
birthday: null | string;
|
|
134
|
-
gender: boolean;
|
|
135
|
-
notes: null | string;
|
|
136
|
-
time_zone: string;
|
|
137
|
-
language: string;
|
|
138
|
-
selected_entity_id: number;
|
|
139
|
-
created_at: string;
|
|
140
|
-
updated_at: string;
|
|
141
|
-
authentication_token: string;
|
|
142
|
-
provider: string;
|
|
143
|
-
provider_token: string;
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
export type ProfileResponse = {
|
|
147
|
-
profile: Profile;
|
|
148
|
-
memberships: Membership[];
|
|
149
|
-
};
|
|
150
|
-
|
|
151
14
|
/**
|
|
152
15
|
* getOauthUserInfo
|
|
153
16
|
* @param codeValue
|
|
@@ -223,7 +86,7 @@ export const changeEntity = async (headers: any, entityId: string) => {
|
|
|
223
86
|
export const getAgencyInfo = async (
|
|
224
87
|
headers: any,
|
|
225
88
|
session: Session
|
|
226
|
-
): Promise<AxiosUtilsResponse<
|
|
89
|
+
): Promise<AxiosUtilsResponse<AgencyGraphQL>> => {
|
|
227
90
|
return handlePossibleAxiosErrors(async () => {
|
|
228
91
|
const agency_id = session.get("agency_id");
|
|
229
92
|
if (!agency_id) {
|
|
@@ -231,7 +94,7 @@ export const getAgencyInfo = async (
|
|
|
231
94
|
"No hay una agencia asignada para este usuario... Contacte con su administrador."
|
|
232
95
|
);
|
|
233
96
|
}
|
|
234
|
-
const response = await httpZauru.get<
|
|
97
|
+
const response = await httpZauru.get<AgencyGraphQL>(
|
|
235
98
|
`/settings/agencies/${agency_id}.json`,
|
|
236
99
|
{
|
|
237
100
|
headers,
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import httpZauru from "./httpZauru.server.js";
|
|
3
|
+
import { VariableGraphQL, AxiosUtilsResponse } from "@zauru-sdk/types";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* getVariables Function for get all zauru variables
|
|
7
|
+
* @param headers
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
export async function getVariables(
|
|
11
|
+
headers: any
|
|
12
|
+
): Promise<AxiosUtilsResponse<VariableGraphQL[]>> {
|
|
13
|
+
try {
|
|
14
|
+
const response = await httpZauru<VariableGraphQL[]>(
|
|
15
|
+
`/apps/webapp_vars.json`,
|
|
16
|
+
{
|
|
17
|
+
method: "GET",
|
|
18
|
+
headers: headers,
|
|
19
|
+
}
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
return { data: response.data, error: false } as AxiosUtilsResponse<
|
|
23
|
+
VariableGraphQL[]
|
|
24
|
+
>;
|
|
25
|
+
} catch (error) {
|
|
26
|
+
console.log(
|
|
27
|
+
chalk.red(`OCURRIÓ UN ERROR AL CARGAR LAS VARIABLES: ${error}`)
|
|
28
|
+
);
|
|
29
|
+
return {
|
|
30
|
+
msg: error,
|
|
31
|
+
error: true,
|
|
32
|
+
userMsg: "Ocurrió un error al intentar obtener las variables",
|
|
33
|
+
} as AxiosUtilsResponse<VariableGraphQL[]>;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
*
|
|
39
|
+
* @param headers
|
|
40
|
+
* @param body
|
|
41
|
+
* @returns
|
|
42
|
+
*/
|
|
43
|
+
export async function createVariable(
|
|
44
|
+
headers: any,
|
|
45
|
+
body: Partial<VariableGraphQL>
|
|
46
|
+
) {
|
|
47
|
+
try {
|
|
48
|
+
const response = await httpZauru.post<VariableGraphQL>(
|
|
49
|
+
`/apps/webapp_vars.json`,
|
|
50
|
+
{ variable: body },
|
|
51
|
+
{
|
|
52
|
+
headers,
|
|
53
|
+
}
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
return {
|
|
57
|
+
data: response.data,
|
|
58
|
+
error: false,
|
|
59
|
+
} as AxiosUtilsResponse<VariableGraphQL>;
|
|
60
|
+
} catch (error) {
|
|
61
|
+
return {
|
|
62
|
+
msg: error,
|
|
63
|
+
error: true,
|
|
64
|
+
userMsg: `Ocurrió un error al intentar crear la variable ${body.name}`,
|
|
65
|
+
} as AxiosUtilsResponse<VariableGraphQL>;
|
|
66
|
+
}
|
|
67
|
+
}
|