ixc-orm 1.1.2 → 1.3.0

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/README.md CHANGED
@@ -50,5 +50,5 @@ Para configurar a comunicação da biblioteca com seu servidor IXC, é necessár
50
50
 
51
51
  `IXC_TOKEN`
52
52
 
53
- > **IXC_HOST** deve conter a url do seu servidor IXC, no formato: `https://seudominio.com.br/webservice/v1`\
54
- > **IXC_TOKEN** deve conter um token de API gerado dentro do seu sistema IXCsoft.
53
+ > **IXC_HOST** A url do seu servidor IXC, no formato: `https://seudominio.com.br/webservice/v1`\
54
+ > **IXC_TOKEN** Um token de API gerado dentro do seu sistema IXCsoft.
package/dist/IXCClient.js CHANGED
@@ -48,7 +48,7 @@ class IXCClient {
48
48
  */
49
49
  where(whereClauses) {
50
50
  if (whereClauses.length > 3) {
51
- throw new Error(`> O array de cláusulas não pode conter mais de 3 elementos.`);
51
+ throw new Error(`> As cláusulas não podem conter mais de 3 elementos.`);
52
52
  }
53
53
  const [alwaysColumn, operatorOrValue, valueOrUndefined] = whereClauses;
54
54
  const availableOperators = Object.keys(types_1.IXCOperator);
package/dist/request.js CHANGED
@@ -8,7 +8,7 @@ exports.createRequestPayload = createRequestPayload;
8
8
  const axios_1 = __importDefault(require("axios"));
9
9
  /**
10
10
  *
11
- * @param method GET | POST | PUT
11
+ * @param method GET | POST | PUT | DELETE
12
12
  * @returns A instância de um objeto do tipo AxiosInstance, pré-configurado com os cabeçalhos necessários
13
13
  */
14
14
  function createAxiosInstance(method = 'GET') {
@@ -27,7 +27,7 @@ function createAxiosInstance(method = 'GET') {
27
27
  /**
28
28
  *
29
29
  * @param table Nome da tabela do IXC onde será feita a busca, atualização, inserção ou remoção
30
- * @param params Parâmetros da busca (desconciderado quando a ação é a de inserir novos registros)
30
+ * @param params Parâmetros da busca (desconsiderados quando a ação for a de inserir novos registros)
31
31
  * @param options Parâmetros de formatação dos dados da responsta (página, ítens por página e ordenação)
32
32
  * @returns
33
33
  */
@@ -0,0 +1 @@
1
+ {"root":["../src/ixcclient.ts","../src/index.ts","../src/request.ts","../src/types.ts"],"version":"5.6.2"}
package/package.json CHANGED
@@ -1,40 +1,40 @@
1
- {
2
- "name": "ixc-orm",
3
- "version": "1.1.2",
4
- "main": "dist/index.js",
5
- "types": "dist/index.d.ts",
6
- "license": "MIT",
7
- "description": "ORM para consumo de dados da API oficial do IXCsoft",
8
- "scripts": {
9
- "declare": "tsc --declaration",
10
- "build": "tsc --build",
11
- "dev": "nodemon --watch \"src//\" --exec \"ts-node src/index.ts\" -e ts"
12
- },
13
- "repository": {
14
- "type": "git",
15
- "url": "git+https://github.com/SousaFelipe/ixc-orm.git"
16
- },
17
- "keywords": [
18
- "IXCSoft API",
19
- "IXCsoft",
20
- "IXC API"
21
- ],
22
- "author": {
23
- "name": "Felipe Sousa",
24
- "email": "flpssdocarmo@gmail.com",
25
- "url": "https://github.com/SousaFelipe"
26
- },
27
- "bugs": {
28
- "url": "https://github.com/SousaFelipe/ixc-orm/issues"
29
- },
30
- "dependencies": {
31
- "axios": "^1.7.5",
32
- "dotenv": "^16.4.5"
33
- },
34
- "devDependencies": {
35
- "@types/node": "^22.5.0",
36
- "nodemon": "^3.1.4",
37
- "ts-node": "^10.9.2",
38
- "typescript": "^5.5.4"
39
- }
40
- }
1
+ {
2
+ "name": "ixc-orm",
3
+ "version": "1.3.0",
4
+ "main": "dist/index.js",
5
+ "types": "dist/index.d.ts",
6
+ "license": "MIT",
7
+ "description": "ORM para consumo de dados da API oficial do IXCsoft",
8
+ "scripts": {
9
+ "declare": "tsc --declaration",
10
+ "build": "tsc --build",
11
+ "dev": "nodemon --watch \"src//\" --exec \"ts-node src/index.ts\" -e ts"
12
+ },
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/SousaFelipe/ixc-orm.git"
16
+ },
17
+ "keywords": [
18
+ "IXCSoft API",
19
+ "IXCsoft",
20
+ "IXC API"
21
+ ],
22
+ "author": {
23
+ "name": "Felipe Sousa",
24
+ "email": "flpssdocarmo@gmail.com",
25
+ "url": "https://github.com/SousaFelipe"
26
+ },
27
+ "bugs": {
28
+ "url": "https://github.com/SousaFelipe/ixc-orm/issues"
29
+ },
30
+ "dependencies": {
31
+ "axios": "^1.10.0",
32
+ "dotenv": "^17.1.0"
33
+ },
34
+ "devDependencies": {
35
+ "@types/node": "^24.0.12",
36
+ "nodemon": "^3.1.10",
37
+ "ts-node": "^10.9.2",
38
+ "typescript": "^5.6.2"
39
+ }
40
+ }
@@ -1,53 +0,0 @@
1
- import { AxiosError } from 'axios';
2
- import { IXCOptions, IXCQuery, IXCResponse, IXCSortOrder } from './types';
3
- export default abstract class IXCClient {
4
- protected table: string;
5
- protected params: IXCQuery[];
6
- protected options: IXCOptions;
7
- /**
8
- *
9
- * @param table O nome da tabela correspondente ao banco de dados do seu servidor IXC
10
- * @see {@link https://wikiapiprovedor.ixcsoft.com.br/index.php}
11
- */
12
- constructor(table: string);
13
- /**
14
- *
15
- * @param whereClauses Um array de strings, no formato [coluna, operador, valor]
16
- * Obs: se você passar um array no formato [coluna, valor] o operador será considerado como '='
17
- * Operadores válidos: =, !=, >, <, >=, <=, LIKE
18
- * @returns A própria instância
19
- */
20
- where(whereClauses: string[]): IXCClient;
21
- /**
22
- *
23
- * @param column A coluna que será usada para ordenar a busca
24
- * @param order A ordem da busca ('asc'ou 'desc')
25
- * @returns A própria instância
26
- */
27
- orderBy(column: string, order: keyof typeof IXCSortOrder): IXCClient;
28
- /**
29
- *
30
- * @param pg O número da página que será solicitada ao IXC
31
- * @param rows A quantidade de linhas (registros) por página
32
- * @returns Promise<null | IXCResponse | AxiosError>
33
- */
34
- get(pg?: number, rows?: number): Promise<null | IXCResponse | AxiosError>;
35
- /**
36
- *
37
- * @param body Um objeto no formado "chave: valor" contendo as informações do novo registro
38
- * a ser inserido no banco de dados do seu servidor IXC
39
- * @returns Promise<null | IXCResponse | AxiosError>
40
- */
41
- post(body?: {
42
- [key: string]: any;
43
- }): Promise<null | IXCResponse | AxiosError>;
44
- /**
45
- *
46
- * @param id O id do registro que será alterado
47
- * @param body Um objeto no formado "chave : valor" contendo as colunas que serão alteradas
48
- * @returns Promise<null | IXCResponse | AxiosError>
49
- */
50
- put(id: number, body?: {
51
- [key: string]: any;
52
- }): Promise<null | IXCResponse | AxiosError>;
53
- }
package/dist/index.d.ts DELETED
@@ -1,3 +0,0 @@
1
- import IXCClient from './IXCClient';
2
- import { IXCOperator, IXCOptions, IXCQuery, IXCRequest, IXCRequestMethods, IXCResponse, IXCSortOrder } from './types';
3
- export { IXCClient, IXCOperator, IXCOptions, IXCQuery, IXCRequest, IXCRequestMethods, IXCResponse, IXCSortOrder };
package/dist/request.d.ts DELETED
@@ -1,16 +0,0 @@
1
- import { AxiosInstance, AxiosRequestConfig } from 'axios';
2
- import { IXCOptions, IXCQuery, IXCRequest, IXCRequestMethods } from './types';
3
- /**
4
- *
5
- * @param method GET | POST | PUT
6
- * @returns A instância de um objeto do tipo AxiosInstance, pré-configurado com os cabeçalhos necessários
7
- */
8
- export declare function createAxiosInstance(method?: keyof typeof IXCRequestMethods): AxiosInstance;
9
- /**
10
- *
11
- * @param table Nome da tabela do IXC onde será feita a busca, atualização, inserção ou remoção
12
- * @param params Parâmetros da busca (desconciderado quando a ação é a de inserir novos registros)
13
- * @param options Parâmetros de formatação dos dados da responsta (página, ítens por página e ordenação)
14
- * @returns
15
- */
16
- export declare function createRequestPayload(table: string, params: IXCQuery | IXCQuery[], options?: IXCOptions): AxiosRequestConfig<IXCRequest>;
package/dist/types.d.ts DELETED
@@ -1,50 +0,0 @@
1
- export declare const IXCOperator: {
2
- '=': string;
3
- '>': string;
4
- '<': string;
5
- '>=': string;
6
- '<=': string;
7
- '!=': string;
8
- LIKE: string;
9
- };
10
- export declare const IXCSortOrder: {
11
- asc: string;
12
- desc: string;
13
- };
14
- export declare const IXCRequestMethods: {
15
- GET: string;
16
- POST: string;
17
- PUT: string;
18
- DELETE: string;
19
- };
20
- export interface IXCOptions {
21
- page: number;
22
- rowsPerPage?: number;
23
- sortName?: string;
24
- sortOrder?: keyof typeof IXCSortOrder;
25
- }
26
- export interface IXCQuery {
27
- TB: string;
28
- OP?: string;
29
- P: string;
30
- }
31
- export interface IXCRequest {
32
- qtype: string;
33
- query: string;
34
- oper: string;
35
- page: number;
36
- rp: number;
37
- sortname: string;
38
- sortorder: string;
39
- grid_param?: string;
40
- }
41
- export interface IXCResponse {
42
- error?: boolean | object;
43
- message?: string | null;
44
- id?: string | number;
45
- page: number | string;
46
- total: number;
47
- registros: Array<{
48
- [key: string]: any;
49
- }>;
50
- }
package/src/IXCClient.ts DELETED
@@ -1,184 +0,0 @@
1
- import { AxiosError } from 'axios';
2
- import { createAxiosInstance, createRequestPayload } from './request';
3
- import { IXCOperator, IXCOptions, IXCQuery, IXCResponse, IXCSortOrder } from './types';
4
-
5
-
6
-
7
- export default abstract class IXCClient {
8
-
9
-
10
- protected table: string;
11
- protected params: IXCQuery[];
12
- protected options: IXCOptions;
13
-
14
-
15
- /**
16
- *
17
- * @param table O nome da tabela correspondente ao banco de dados do seu servidor IXC
18
- * @see {@link https://wikiapiprovedor.ixcsoft.com.br/index.php}
19
- */
20
- constructor(table: string) {
21
-
22
- this.table = table;
23
- this.params = [];
24
-
25
- this.options = {
26
- page: 1,
27
- rowsPerPage: 20,
28
- sortName: 'id',
29
- sortOrder: 'asc'
30
- };
31
- }
32
-
33
-
34
- /**
35
- *
36
- * @param whereClauses Um array de strings, no formato [coluna, operador, valor]
37
- * Obs: se você passar um array no formato [coluna, valor] o operador será considerado como '='
38
- * Operadores válidos: =, !=, >, <, >=, <=, LIKE
39
- * @returns A própria instância
40
- */
41
- where(whereClauses: string[]) : IXCClient {
42
-
43
- if (whereClauses.length > 3) {
44
- throw new Error(
45
- `> O array de cláusulas não pode conter mais de 3 elementos.`
46
- );
47
- }
48
-
49
- const [
50
- alwaysColumn,
51
- operatorOrValue,
52
- valueOrUndefined
53
- ] = whereClauses;
54
-
55
- const availableOperators = Object.keys(IXCOperator);
56
-
57
- if (whereClauses.length > 2 && !availableOperators.includes(operatorOrValue)) {
58
- throw new Error(
59
- `> O operador ${ operatorOrValue }, não faz parte dos operadores válidos: ${ availableOperators }.`
60
- );
61
- }
62
-
63
- this.params.push({
64
- TB: alwaysColumn,
65
- OP: valueOrUndefined ? operatorOrValue : '=',
66
- P: valueOrUndefined ? valueOrUndefined : operatorOrValue
67
- });
68
-
69
- return this;
70
- }
71
-
72
-
73
- /**
74
- *
75
- * @param column A coluna que será usada para ordenar a busca
76
- * @param order A ordem da busca ('asc'ou 'desc')
77
- * @returns A própria instância
78
- */
79
- orderBy(column: string, order: keyof typeof IXCSortOrder) : IXCClient {
80
- this.options.sortName = column;
81
- this.options.sortOrder = order;
82
- return this;
83
- }
84
-
85
-
86
- /**
87
- *
88
- * @param pg O número da página que será solicitada ao IXC
89
- * @param rows A quantidade de linhas (registros) por página
90
- * @returns Promise<null | IXCResponse | AxiosError>
91
- */
92
- async get(pg?: number, rows?: number) : Promise<null | IXCResponse | AxiosError> {
93
-
94
- const { page, rowsPerPage, ...rest } = this.options;
95
-
96
- const opts = {
97
- page: pg ?? page,
98
- rowsPerPage: rows ?? rowsPerPage,
99
- ...rest
100
- };
101
-
102
- const axios = createAxiosInstance('GET');
103
- const payload = createRequestPayload(this.table, this.params, opts);
104
-
105
- try {
106
- const response = await axios.get<IXCResponse>(this.table, payload);
107
- return response.data;
108
- }
109
- catch (error: any) {
110
- console.error(error);
111
-
112
- if (error instanceof AxiosError) {
113
- return error;
114
- }
115
-
116
- return null;
117
- }
118
- finally {
119
- this.params = [];
120
- this.options = {
121
- page: 1,
122
- rowsPerPage: 20,
123
- sortName: 'id',
124
- sortOrder: 'asc'
125
- };
126
- }
127
- }
128
-
129
-
130
- /**
131
- *
132
- * @param body Um objeto no formado "chave: valor" contendo as informações do novo registro
133
- * a ser inserido no banco de dados do seu servidor IXC
134
- * @returns Promise<null | IXCResponse | AxiosError>
135
- */
136
- async post(body?: { [key: string]: any }) : Promise<null | IXCResponse | AxiosError> {
137
- const axios = createAxiosInstance('POST');
138
-
139
- try {
140
- const response = await axios.post<IXCResponse>(this.table, { data: body });
141
- return response.data;
142
- }
143
- catch (error: any) {
144
- console.error(error);
145
-
146
- if (error instanceof AxiosError) {
147
- return error;
148
- }
149
-
150
- return null;
151
- }
152
- finally {
153
- this.params = [];
154
- }
155
- }
156
-
157
-
158
- /**
159
- *
160
- * @param id O id do registro que será alterado
161
- * @param body Um objeto no formado "chave : valor" contendo as colunas que serão alteradas
162
- * @returns Promise<null | IXCResponse | AxiosError>
163
- */
164
- async put(id: number, body?: { [key: string]: any }) : Promise<null | IXCResponse | AxiosError> {
165
- const axios = createAxiosInstance('PUT');
166
-
167
- try {
168
- const response = await axios.put<IXCResponse>(`${ this.table }/${ id }`, { data: body });
169
- return response.data;
170
- }
171
- catch (error: any) {
172
- console.error(error);
173
-
174
- if (error instanceof AxiosError) {
175
- return error;
176
- }
177
-
178
- return null;
179
- }
180
- finally {
181
- this.params = [];
182
- }
183
- }
184
- }
package/src/index.ts DELETED
@@ -1,37 +0,0 @@
1
- import path from 'path';
2
- import dotenv from 'dotenv';
3
-
4
- import IXCClient from './IXCClient';
5
-
6
- import {
7
- IXCOperator,
8
- IXCOptions,
9
- IXCQuery,
10
- IXCRequest,
11
- IXCRequestMethods,
12
- IXCResponse,
13
- IXCSortOrder
14
- } from './types';
15
-
16
-
17
-
18
- const env = dotenv.config({
19
- path: path.join(__dirname, `../.env`)
20
- });
21
-
22
- if (env.error) {
23
- console.error(env.error);
24
- process.exit(-1);
25
- }
26
-
27
-
28
- export {
29
- IXCClient,
30
- IXCOperator,
31
- IXCOptions,
32
- IXCQuery,
33
- IXCRequest,
34
- IXCRequestMethods,
35
- IXCResponse,
36
- IXCSortOrder
37
- };
package/src/request.ts DELETED
@@ -1,77 +0,0 @@
1
- import axios, { AxiosInstance, AxiosRequestConfig } from 'axios';
2
- import { IXCOptions, IXCQuery, IXCRequest, IXCRequestMethods } from './types';
3
-
4
-
5
- /**
6
- *
7
- * @param method GET | POST | PUT
8
- * @returns A instância de um objeto do tipo AxiosInstance, pré-configurado com os cabeçalhos necessários
9
- */
10
- export function createAxiosInstance(method: keyof typeof IXCRequestMethods = 'GET') : AxiosInstance {
11
-
12
- const host = process.env.IXC_HOST;
13
- const token = process.env.IXC_TOKEN;
14
-
15
- return axios.create({
16
- method: method,
17
- baseURL: host ?? 'http://127.0.0.1/webservice/v1',
18
- headers: {
19
- 'ixcsoft': (method === 'GET') ? 'listar' : '',
20
- 'Content-Type': 'application/json',
21
- 'Authorization': `Basic ${ Buffer.from(token ?? '').toString('base64') }`
22
- }
23
- });
24
- }
25
-
26
-
27
- /**
28
- *
29
- * @param table Nome da tabela do IXC onde será feita a busca, atualização, inserção ou remoção
30
- * @param params Parâmetros da busca (desconciderado quando a ação é a de inserir novos registros)
31
- * @param options Parâmetros de formatação dos dados da responsta (página, ítens por página e ordenação)
32
- * @returns
33
- */
34
- export function createRequestPayload(
35
- table: string,
36
- params: IXCQuery | IXCQuery[],
37
- options?: IXCOptions
38
- ) : AxiosRequestConfig<IXCRequest> {
39
-
40
- const page = options?.page ?? 1;
41
- const rowsPerPage = options?.rowsPerPage ?? 20;
42
- const sortName = options?.sortName ?? 'id';
43
- const sortOrder = options?.sortOrder ?? 'asc';
44
-
45
- if (Array.isArray(params)) {
46
- let grid_param: object[] = [];
47
-
48
- params.forEach(p => {
49
- grid_param.push({
50
- TB: `${table}.${p.TB}`,
51
- OP: p.OP || '=',
52
- P: p.P
53
- });
54
- });
55
-
56
- return { data: {
57
- qtype: table,
58
- query: '',
59
- oper: '',
60
- page: page,
61
- rp: rowsPerPage,
62
- sortname: `${table}.${sortName}`,
63
- sortorder: sortOrder,
64
- grid_param: JSON.stringify(grid_param)
65
- }};
66
- }
67
-
68
- return { data: {
69
- qtype: `${table}.${params.TB}`,
70
- query: params.P,
71
- oper: params.OP || '=',
72
- page: page,
73
- rp: rowsPerPage,
74
- sortname: `${table}.${sortName}`,
75
- sortorder: sortOrder
76
- }};
77
- }
package/src/types.ts DELETED
@@ -1,61 +0,0 @@
1
-
2
-
3
-
4
- export const IXCOperator = {
5
- '=': '=',
6
- '>': '>',
7
- '<': '<',
8
- '>=': '>=',
9
- '<=': '<=',
10
- '!=': '!=',
11
- 'LIKE': 'L'
12
- }
13
-
14
- export const IXCSortOrder = {
15
- asc: 'asc',
16
- desc: 'desc'
17
- }
18
-
19
- export const IXCRequestMethods = {
20
- GET: 'GET',
21
- POST: 'POST',
22
- PUT: 'PUT',
23
- DELETE: 'DELETE'
24
- }
25
-
26
-
27
- export interface IXCOptions {
28
- page: number,
29
- rowsPerPage?: number,
30
- sortName?: string,
31
- sortOrder?: keyof typeof IXCSortOrder
32
- }
33
-
34
-
35
- export interface IXCQuery {
36
- TB: string,
37
- OP?: string,
38
- P: string
39
- }
40
-
41
-
42
- export interface IXCRequest {
43
- qtype: string,
44
- query: string,
45
- oper: string,
46
- page: number,
47
- rp: number,
48
- sortname: string,
49
- sortorder: string,
50
- grid_param?: string
51
- }
52
-
53
-
54
- export interface IXCResponse {
55
- error?: boolean | object,
56
- message?: string | null,
57
- id?: string | number,
58
- page: number | string,
59
- total: number,
60
- registros: Array<{ [key: string]: any }>
61
- }