@projetoacbr/acbrlib-base-node 1.0.0 → 1.0.1
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/src/ACBrBuffer/index.d.ts +16 -0
- package/dist/src/ACBrBuffer/index.js +78 -0
- package/dist/src/exception/ACBrLibResultCodes.d.ts +19 -0
- package/dist/src/exception/ACBrLibResultCodes.js +23 -0
- package/dist/src/exception/index.d.ts +43 -0
- package/dist/src/exception/index.js +85 -0
- package/dist/src/index.d.ts +136 -0
- package/dist/src/index.js +470 -0
- package/package.json +4 -4
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare const TAMANHO_PADRAO = 1024;
|
|
2
|
+
/**
|
|
3
|
+
* ACBrBuffer é uma classe que representa um buffer
|
|
4
|
+
* Implementa auto-cleanup com 'using' declaration
|
|
5
|
+
*/
|
|
6
|
+
export default class ACBrBuffer {
|
|
7
|
+
private bufferSize;
|
|
8
|
+
private bufferData;
|
|
9
|
+
private disposed;
|
|
10
|
+
constructor(size: number);
|
|
11
|
+
getRefTamanhoBuffer(): any;
|
|
12
|
+
getBuffer(): Buffer<ArrayBufferLike>;
|
|
13
|
+
toString(): string;
|
|
14
|
+
destroy(): void;
|
|
15
|
+
[Symbol.dispose](): void;
|
|
16
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.TAMANHO_PADRAO = void 0;
|
|
37
|
+
const koffi = __importStar(require("koffi"));
|
|
38
|
+
exports.TAMANHO_PADRAO = 1024;
|
|
39
|
+
function deref(pointer, pointerType) {
|
|
40
|
+
return koffi.decode(pointer, pointerType);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* ACBrBuffer é uma classe que representa um buffer
|
|
44
|
+
* Implementa auto-cleanup com 'using' declaration
|
|
45
|
+
*/
|
|
46
|
+
class ACBrBuffer {
|
|
47
|
+
bufferSize;
|
|
48
|
+
bufferData;
|
|
49
|
+
disposed = false;
|
|
50
|
+
constructor(size) {
|
|
51
|
+
this.bufferSize = koffi.alloc("int", 1);
|
|
52
|
+
this.bufferData = Buffer.alloc(size);
|
|
53
|
+
koffi.encode(this.bufferSize, 'int', size);
|
|
54
|
+
}
|
|
55
|
+
getRefTamanhoBuffer() {
|
|
56
|
+
return this.bufferSize;
|
|
57
|
+
}
|
|
58
|
+
getBuffer() {
|
|
59
|
+
return this.bufferData;
|
|
60
|
+
}
|
|
61
|
+
toString() {
|
|
62
|
+
let size = deref(this.bufferSize, 'int');
|
|
63
|
+
let strBuffer = this.bufferData.toString('utf8', 0, (Math.min(size, this.bufferData.length)));
|
|
64
|
+
return strBuffer;
|
|
65
|
+
}
|
|
66
|
+
destroy() {
|
|
67
|
+
if (!this.disposed) {
|
|
68
|
+
koffi.free(this.bufferSize);
|
|
69
|
+
this.bufferSize = null;
|
|
70
|
+
this.disposed = true;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
// Implementação do auto-cleanup com 'using' declaration
|
|
74
|
+
[Symbol.dispose]() {
|
|
75
|
+
this.destroy();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
exports.default = ACBrBuffer;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export declare enum ACBrLibResultCodes {
|
|
2
|
+
OK = 0,
|
|
3
|
+
ErrLibNaoInicializada = -1,
|
|
4
|
+
ErrLibNaoFinalizada = -2,
|
|
5
|
+
ErrConfigLer = -3,
|
|
6
|
+
ErrConfigGravar = -4,
|
|
7
|
+
ErrArquivoNaoExiste = -5,
|
|
8
|
+
ErrDiretorioNaoExiste = -6,
|
|
9
|
+
ErrHttp = -7,
|
|
10
|
+
ErrParametroInvalido = -8,
|
|
11
|
+
ErrExecutandoMetodo = -10,
|
|
12
|
+
ErrCNPJInvalido = -11,
|
|
13
|
+
ErrCPFInvalido = -12,
|
|
14
|
+
ErrIndex = -13,
|
|
15
|
+
ErrGerarXml = -14,
|
|
16
|
+
ErrNaoDisponivelEmModoConsole = -15,
|
|
17
|
+
ErrTimeOut = -19,
|
|
18
|
+
ErrDemoExpirado = -999
|
|
19
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ACBrLibResultCodes = void 0;
|
|
4
|
+
var ACBrLibResultCodes;
|
|
5
|
+
(function (ACBrLibResultCodes) {
|
|
6
|
+
ACBrLibResultCodes[ACBrLibResultCodes["OK"] = 0] = "OK";
|
|
7
|
+
ACBrLibResultCodes[ACBrLibResultCodes["ErrLibNaoInicializada"] = -1] = "ErrLibNaoInicializada";
|
|
8
|
+
ACBrLibResultCodes[ACBrLibResultCodes["ErrLibNaoFinalizada"] = -2] = "ErrLibNaoFinalizada";
|
|
9
|
+
ACBrLibResultCodes[ACBrLibResultCodes["ErrConfigLer"] = -3] = "ErrConfigLer";
|
|
10
|
+
ACBrLibResultCodes[ACBrLibResultCodes["ErrConfigGravar"] = -4] = "ErrConfigGravar";
|
|
11
|
+
ACBrLibResultCodes[ACBrLibResultCodes["ErrArquivoNaoExiste"] = -5] = "ErrArquivoNaoExiste";
|
|
12
|
+
ACBrLibResultCodes[ACBrLibResultCodes["ErrDiretorioNaoExiste"] = -6] = "ErrDiretorioNaoExiste";
|
|
13
|
+
ACBrLibResultCodes[ACBrLibResultCodes["ErrHttp"] = -7] = "ErrHttp";
|
|
14
|
+
ACBrLibResultCodes[ACBrLibResultCodes["ErrParametroInvalido"] = -8] = "ErrParametroInvalido";
|
|
15
|
+
ACBrLibResultCodes[ACBrLibResultCodes["ErrExecutandoMetodo"] = -10] = "ErrExecutandoMetodo";
|
|
16
|
+
ACBrLibResultCodes[ACBrLibResultCodes["ErrCNPJInvalido"] = -11] = "ErrCNPJInvalido";
|
|
17
|
+
ACBrLibResultCodes[ACBrLibResultCodes["ErrCPFInvalido"] = -12] = "ErrCPFInvalido";
|
|
18
|
+
ACBrLibResultCodes[ACBrLibResultCodes["ErrIndex"] = -13] = "ErrIndex";
|
|
19
|
+
ACBrLibResultCodes[ACBrLibResultCodes["ErrGerarXml"] = -14] = "ErrGerarXml";
|
|
20
|
+
ACBrLibResultCodes[ACBrLibResultCodes["ErrNaoDisponivelEmModoConsole"] = -15] = "ErrNaoDisponivelEmModoConsole";
|
|
21
|
+
ACBrLibResultCodes[ACBrLibResultCodes["ErrTimeOut"] = -19] = "ErrTimeOut";
|
|
22
|
+
ACBrLibResultCodes[ACBrLibResultCodes["ErrDemoExpirado"] = -999] = "ErrDemoExpirado";
|
|
23
|
+
})(ACBrLibResultCodes || (exports.ACBrLibResultCodes = ACBrLibResultCodes = {}));
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ACBrLibError é uma classe de Exception para lançar Exceçoes da ACBr
|
|
3
|
+
*
|
|
4
|
+
*/
|
|
5
|
+
export default class ACBrLibError extends Error {
|
|
6
|
+
constructor(msg: string);
|
|
7
|
+
}
|
|
8
|
+
export declare class ACBrLibLibNaoInicializadaError extends ACBrLibError {
|
|
9
|
+
constructor(msg: string);
|
|
10
|
+
}
|
|
11
|
+
export declare class ACBrLibLibNaoFinalizadaError extends ACBrLibError {
|
|
12
|
+
constructor(msg: string);
|
|
13
|
+
}
|
|
14
|
+
export declare class ACBrLibConfigLerError extends ACBrLibError {
|
|
15
|
+
constructor(msg: string);
|
|
16
|
+
}
|
|
17
|
+
export declare class ACBrLibConfigGravarError extends ACBrLibError {
|
|
18
|
+
constructor(msg: string);
|
|
19
|
+
}
|
|
20
|
+
export declare class ACBrLibArquivoNaoExisteError extends ACBrLibError {
|
|
21
|
+
constructor(msg: string);
|
|
22
|
+
}
|
|
23
|
+
export declare class ACBrLibDiretorioNaoExisteError extends ACBrLibError {
|
|
24
|
+
constructor(msg: string);
|
|
25
|
+
}
|
|
26
|
+
export declare class ACBrLibHttpError extends ACBrLibError {
|
|
27
|
+
constructor(msg: string);
|
|
28
|
+
}
|
|
29
|
+
export declare class ACBrLibParametroInvalidoError extends ACBrLibError {
|
|
30
|
+
constructor(msg: string);
|
|
31
|
+
}
|
|
32
|
+
export declare class ACBrLibExecutandoMetodoError extends ACBrLibError {
|
|
33
|
+
constructor(msg: string);
|
|
34
|
+
}
|
|
35
|
+
export declare class ACBrLibNaoDisponivelEmModoConsoleError extends ACBrLibError {
|
|
36
|
+
constructor(msg: string);
|
|
37
|
+
}
|
|
38
|
+
export declare class ACBrLibTimeOutError extends ACBrLibError {
|
|
39
|
+
constructor(msg: string);
|
|
40
|
+
}
|
|
41
|
+
export declare class ACBrLibDemoExpiradoError extends ACBrLibError {
|
|
42
|
+
constructor(msg: string);
|
|
43
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ACBrLibDemoExpiradoError = exports.ACBrLibTimeOutError = exports.ACBrLibNaoDisponivelEmModoConsoleError = exports.ACBrLibExecutandoMetodoError = exports.ACBrLibParametroInvalidoError = exports.ACBrLibHttpError = exports.ACBrLibDiretorioNaoExisteError = exports.ACBrLibArquivoNaoExisteError = exports.ACBrLibConfigGravarError = exports.ACBrLibConfigLerError = exports.ACBrLibLibNaoFinalizadaError = exports.ACBrLibLibNaoInicializadaError = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* ACBrLibError é uma classe de Exception para lançar Exceçoes da ACBr
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
class ACBrLibError extends Error {
|
|
9
|
+
constructor(msg) {
|
|
10
|
+
super(msg);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.default = ACBrLibError;
|
|
14
|
+
class ACBrLibLibNaoInicializadaError extends ACBrLibError {
|
|
15
|
+
constructor(msg) {
|
|
16
|
+
super(msg);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.ACBrLibLibNaoInicializadaError = ACBrLibLibNaoInicializadaError;
|
|
20
|
+
class ACBrLibLibNaoFinalizadaError extends ACBrLibError {
|
|
21
|
+
constructor(msg) {
|
|
22
|
+
super(msg);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.ACBrLibLibNaoFinalizadaError = ACBrLibLibNaoFinalizadaError;
|
|
26
|
+
class ACBrLibConfigLerError extends ACBrLibError {
|
|
27
|
+
constructor(msg) {
|
|
28
|
+
super(msg);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.ACBrLibConfigLerError = ACBrLibConfigLerError;
|
|
32
|
+
class ACBrLibConfigGravarError extends ACBrLibError {
|
|
33
|
+
constructor(msg) {
|
|
34
|
+
super(msg);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.ACBrLibConfigGravarError = ACBrLibConfigGravarError;
|
|
38
|
+
class ACBrLibArquivoNaoExisteError extends ACBrLibError {
|
|
39
|
+
constructor(msg) {
|
|
40
|
+
super(msg);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.ACBrLibArquivoNaoExisteError = ACBrLibArquivoNaoExisteError;
|
|
44
|
+
class ACBrLibDiretorioNaoExisteError extends ACBrLibError {
|
|
45
|
+
constructor(msg) {
|
|
46
|
+
super(msg);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.ACBrLibDiretorioNaoExisteError = ACBrLibDiretorioNaoExisteError;
|
|
50
|
+
class ACBrLibHttpError extends ACBrLibError {
|
|
51
|
+
constructor(msg) {
|
|
52
|
+
super(msg);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.ACBrLibHttpError = ACBrLibHttpError;
|
|
56
|
+
class ACBrLibParametroInvalidoError extends ACBrLibError {
|
|
57
|
+
constructor(msg) {
|
|
58
|
+
super(msg);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
exports.ACBrLibParametroInvalidoError = ACBrLibParametroInvalidoError;
|
|
62
|
+
class ACBrLibExecutandoMetodoError extends ACBrLibError {
|
|
63
|
+
constructor(msg) {
|
|
64
|
+
super(msg);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.ACBrLibExecutandoMetodoError = ACBrLibExecutandoMetodoError;
|
|
68
|
+
class ACBrLibNaoDisponivelEmModoConsoleError extends ACBrLibError {
|
|
69
|
+
constructor(msg) {
|
|
70
|
+
super(msg);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
exports.ACBrLibNaoDisponivelEmModoConsoleError = ACBrLibNaoDisponivelEmModoConsoleError;
|
|
74
|
+
class ACBrLibTimeOutError extends ACBrLibError {
|
|
75
|
+
constructor(msg) {
|
|
76
|
+
super(msg);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
exports.ACBrLibTimeOutError = ACBrLibTimeOutError;
|
|
80
|
+
class ACBrLibDemoExpiradoError extends ACBrLibError {
|
|
81
|
+
constructor(msg) {
|
|
82
|
+
super(msg);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
exports.ACBrLibDemoExpiradoError = ACBrLibDemoExpiradoError;
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import ACBrBuffer from './ACBrBuffer';
|
|
2
|
+
/**
|
|
3
|
+
* ACBrLibBaseMT é uma classe de alto nível que implementa os métodos da ACBrLibComum Multi-Thread
|
|
4
|
+
* Implementa Disposable para auto-cleanup do handle
|
|
5
|
+
*/
|
|
6
|
+
export default abstract class ACBrLibBaseMT {
|
|
7
|
+
#private;
|
|
8
|
+
private handle;
|
|
9
|
+
private isHandleInitialized;
|
|
10
|
+
private acbrlib;
|
|
11
|
+
private arquivoConfig;
|
|
12
|
+
private chaveCrypt;
|
|
13
|
+
private disposed;
|
|
14
|
+
constructor(acbrlib: any, arquivoConfig: string, chaveCrypt: string);
|
|
15
|
+
getAcbrlib(): any;
|
|
16
|
+
getHandle(): any;
|
|
17
|
+
/**
|
|
18
|
+
* Libera recursos alocados
|
|
19
|
+
*/
|
|
20
|
+
destroy(): void;
|
|
21
|
+
/**
|
|
22
|
+
* Implementação do Disposable interface para using declaration
|
|
23
|
+
*/
|
|
24
|
+
[Symbol.dispose](): void;
|
|
25
|
+
/**
|
|
26
|
+
* Implementação do AsyncDisposable interface para using await
|
|
27
|
+
*/
|
|
28
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* @description Método usado para inicializar o componente para uso da biblioteca
|
|
31
|
+
*/
|
|
32
|
+
inicializar(): number;
|
|
33
|
+
/**
|
|
34
|
+
* @description Método usado para inicializar o componente para uso da biblioteca
|
|
35
|
+
* @param arquivoConfig Localização do arquivo INI, pode ser em branco neste caso o ACBrLib vai criar um novo arquivo INI.
|
|
36
|
+
* @param chaveCrypt Chave de segurança para criptografar as informações confidencias, pode ser em branco neste caso será usado a senha padrão.
|
|
37
|
+
* @returns 0 se sucesso ou o código de erro
|
|
38
|
+
*/
|
|
39
|
+
inicializar(arquivoConfig: string, chaveCrypt: string): number;
|
|
40
|
+
/**
|
|
41
|
+
* Método usado para remover ACBrLib e suas classes da memoria
|
|
42
|
+
* @returns 0 ou código de erro
|
|
43
|
+
*/
|
|
44
|
+
finalizar(): number;
|
|
45
|
+
/**
|
|
46
|
+
* @description Método que retornar o nome da biblioteca.
|
|
47
|
+
* @returns Uma string com o nome da biblioteca
|
|
48
|
+
*/
|
|
49
|
+
nome(): string;
|
|
50
|
+
/**
|
|
51
|
+
* @description Método que retornar a versão da biblioteca.
|
|
52
|
+
* @returns Uma string com o versão da biblioteca
|
|
53
|
+
*/
|
|
54
|
+
versao(): string;
|
|
55
|
+
/**
|
|
56
|
+
* @description Método usado retornar o ultimo retorno processado pela biblioteca
|
|
57
|
+
* @returns Retorna uma string com o último retorno processado pela biblioteca.
|
|
58
|
+
*/
|
|
59
|
+
ultimoRetorno(): string;
|
|
60
|
+
configLer(): number;
|
|
61
|
+
configLer(arquivoConfig: string): number;
|
|
62
|
+
/**
|
|
63
|
+
* @description Método usado para gravar a configuração da biblioteca no arquivo INI informado.
|
|
64
|
+
* @param arquivoConfig Arquivo INI para ler, se informado vazio será usado o valor padrão.
|
|
65
|
+
* @returns 0 ou código de erro
|
|
66
|
+
*/
|
|
67
|
+
/**
|
|
68
|
+
* @description Método usado para gravar a configuração da biblioteca no arquivo INI informado.
|
|
69
|
+
*/
|
|
70
|
+
configGravar(): number;
|
|
71
|
+
/**
|
|
72
|
+
* @description Método usado para gravar a configuração da biblioteca no arquivo INI informado.
|
|
73
|
+
* @param arquivoConfig Arquivo INI para ler, se informado vazio será usado o valor padrão.
|
|
74
|
+
* @returns 0 ou código de erro
|
|
75
|
+
*/
|
|
76
|
+
configGravar(arquivoConfig: string): number;
|
|
77
|
+
/**
|
|
78
|
+
* @description Método usado para ler uma determinado item da configuração.
|
|
79
|
+
* @param sessao Nome da sessão de configuração.
|
|
80
|
+
* @param chave Nome da chave da sessão.
|
|
81
|
+
* @returns 0 ou código de erro
|
|
82
|
+
*/
|
|
83
|
+
configLerValor(sessao: string, chave: string): string;
|
|
84
|
+
/**
|
|
85
|
+
* @description Método usado para gravar um determinado item da configuração.
|
|
86
|
+
* @param sessao Nome da sessão de configuração.
|
|
87
|
+
* @param chave Nome da chave da sessão.
|
|
88
|
+
* @param valor Valor para ser gravado na configuração
|
|
89
|
+
* @returns 0 ou código de erro
|
|
90
|
+
*/
|
|
91
|
+
configGravarValor(sessao: string, chave: string, valor: string): number;
|
|
92
|
+
/**
|
|
93
|
+
* @description Método usado para exportar a configuração da biblioteca do arquivo INI informado.
|
|
94
|
+
* @returns Uma string com a configuração exportada.
|
|
95
|
+
*/
|
|
96
|
+
configExportar(): string;
|
|
97
|
+
/**
|
|
98
|
+
*
|
|
99
|
+
* @description Método usado para importar a configuração da biblioteca do arquivo INI informado
|
|
100
|
+
* @param arquivoConfig Arquivo INI para ler, se informado vazio será usado o valor padrão.
|
|
101
|
+
* @returns 0 ou código de erro
|
|
102
|
+
*/
|
|
103
|
+
configImportar(arquivoConfig: string): number;
|
|
104
|
+
/**
|
|
105
|
+
* @description Método que retorna informações da biblioteca OpenSsl
|
|
106
|
+
* @returns
|
|
107
|
+
*/
|
|
108
|
+
openSslInfo(): string;
|
|
109
|
+
_isRequiredReallocBuffer(requiredLen: number): boolean;
|
|
110
|
+
_processaResult(buffer: ACBrBuffer): string;
|
|
111
|
+
/**
|
|
112
|
+
* Verifica se o resultado é um código de erro
|
|
113
|
+
* @param result
|
|
114
|
+
* @returns
|
|
115
|
+
*/
|
|
116
|
+
_isResultErrorCode(result: number): boolean;
|
|
117
|
+
/**
|
|
118
|
+
* Checa o resultado da operação e propaga a exceção se result < 0
|
|
119
|
+
* @param result
|
|
120
|
+
*/
|
|
121
|
+
_checkResult(result: number): void;
|
|
122
|
+
_ultimoRetorno(size: number): string;
|
|
123
|
+
/** Metodos que devem ser implementados em classes filhas */
|
|
124
|
+
protected abstract LIB_Inicializar(handle: any, configPath: string, chaveCrypt: string): number;
|
|
125
|
+
protected abstract LIB_Finalizar(handle: any): number;
|
|
126
|
+
protected abstract LIB_UltimoRetorno(handle: any, mensagem: Buffer, refTamanho: any): number;
|
|
127
|
+
protected abstract LIB_Nome(handle: any, nome: Buffer, refTamanho: any): number;
|
|
128
|
+
protected abstract LIB_Versao(handle: any, versao: Buffer, refTamanho: any): number;
|
|
129
|
+
protected abstract LIB_ConfigLer(handle: any, arqConfig: string): number;
|
|
130
|
+
protected abstract LIB_ConfigGravar(handle: any, arqConfig: string): number;
|
|
131
|
+
protected abstract LIB_ConfigLerValor(handle: any, sessao: string, chave: string, valor: Buffer, refTamanho: any): number;
|
|
132
|
+
protected abstract LIB_ConfigGravarValor(handle: any, sessao: string, chave: string, valor: string): number;
|
|
133
|
+
protected abstract LIB_ConfigImportar(handle: any, arqConfig: string): number;
|
|
134
|
+
protected abstract LIB_ConfigExportar(handle: any, configuracoes: Buffer, refTamanho: any): number;
|
|
135
|
+
protected abstract LIB_OpenSSLInfo(handle: any, configuracoes: Buffer, refTamanho: any): number;
|
|
136
|
+
}
|
|
@@ -0,0 +1,470 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
|
|
36
|
+
if (value !== null && value !== void 0) {
|
|
37
|
+
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
38
|
+
var dispose, inner;
|
|
39
|
+
if (async) {
|
|
40
|
+
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
41
|
+
dispose = value[Symbol.asyncDispose];
|
|
42
|
+
}
|
|
43
|
+
if (dispose === void 0) {
|
|
44
|
+
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
45
|
+
dispose = value[Symbol.dispose];
|
|
46
|
+
if (async) inner = dispose;
|
|
47
|
+
}
|
|
48
|
+
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
49
|
+
if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
|
|
50
|
+
env.stack.push({ value: value, dispose: dispose, async: async });
|
|
51
|
+
}
|
|
52
|
+
else if (async) {
|
|
53
|
+
env.stack.push({ async: true });
|
|
54
|
+
}
|
|
55
|
+
return value;
|
|
56
|
+
};
|
|
57
|
+
var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
|
|
58
|
+
return function (env) {
|
|
59
|
+
function fail(e) {
|
|
60
|
+
env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
|
|
61
|
+
env.hasError = true;
|
|
62
|
+
}
|
|
63
|
+
var r, s = 0;
|
|
64
|
+
function next() {
|
|
65
|
+
while (r = env.stack.pop()) {
|
|
66
|
+
try {
|
|
67
|
+
if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
|
|
68
|
+
if (r.dispose) {
|
|
69
|
+
var result = r.dispose.call(r.value);
|
|
70
|
+
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
|
|
71
|
+
}
|
|
72
|
+
else s |= 1;
|
|
73
|
+
}
|
|
74
|
+
catch (e) {
|
|
75
|
+
fail(e);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
|
|
79
|
+
if (env.hasError) throw env.error;
|
|
80
|
+
}
|
|
81
|
+
return next();
|
|
82
|
+
};
|
|
83
|
+
})(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
84
|
+
var e = new Error(message);
|
|
85
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
86
|
+
});
|
|
87
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
88
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
89
|
+
};
|
|
90
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
91
|
+
const ACBrBuffer_1 = require("./ACBrBuffer");
|
|
92
|
+
const ACBrBuffer_2 = __importDefault(require("./ACBrBuffer"));
|
|
93
|
+
const exception_1 = require("./exception");
|
|
94
|
+
const ACBrLibResultCodes_1 = require("./exception/ACBrLibResultCodes");
|
|
95
|
+
const koffi = __importStar(require("koffi"));
|
|
96
|
+
/**
|
|
97
|
+
* ACBrLibBaseMT é uma classe de alto nível que implementa os métodos da ACBrLibComum Multi-Thread
|
|
98
|
+
* Implementa Disposable para auto-cleanup do handle
|
|
99
|
+
*/
|
|
100
|
+
class ACBrLibBaseMT {
|
|
101
|
+
handle; // ponteiro para ponteiro (void **)
|
|
102
|
+
isHandleInitialized = false;
|
|
103
|
+
acbrlib;
|
|
104
|
+
arquivoConfig;
|
|
105
|
+
chaveCrypt;
|
|
106
|
+
disposed = false;
|
|
107
|
+
constructor(acbrlib, arquivoConfig, chaveCrypt) {
|
|
108
|
+
this.arquivoConfig = arquivoConfig;
|
|
109
|
+
this.chaveCrypt = chaveCrypt;
|
|
110
|
+
this.acbrlib = acbrlib;
|
|
111
|
+
this.handle = null;
|
|
112
|
+
}
|
|
113
|
+
getAcbrlib() {
|
|
114
|
+
return this.acbrlib;
|
|
115
|
+
}
|
|
116
|
+
getHandle() {
|
|
117
|
+
return koffi.decode(this.handle, 'void *');
|
|
118
|
+
}
|
|
119
|
+
#isInitialized() {
|
|
120
|
+
// diferente do ref-napi que tem o metodo isNull() koffi até a presente versão não tem
|
|
121
|
+
// sendo impossivel saber se o handle é null (do lado nodejs) ou não, usamos o isHandleInitialized
|
|
122
|
+
// para saber se a biblioteca foi inicializada
|
|
123
|
+
// sem esse controle, é possivel liberar a memoria mais de uma vez e corromper o heap.
|
|
124
|
+
return this.isHandleInitialized;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Libera recursos alocados
|
|
128
|
+
*/
|
|
129
|
+
destroy() {
|
|
130
|
+
if (!this.disposed) {
|
|
131
|
+
try {
|
|
132
|
+
// Finaliza a biblioteca se estiver inicializada
|
|
133
|
+
if (this.#isInitialized()) {
|
|
134
|
+
this.finalizar();
|
|
135
|
+
}
|
|
136
|
+
this.disposed = true;
|
|
137
|
+
}
|
|
138
|
+
catch (error) {
|
|
139
|
+
console.error('Erro ao liberar recursos:', error);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Implementação do Disposable interface para using declaration
|
|
145
|
+
*/
|
|
146
|
+
[Symbol.dispose]() {
|
|
147
|
+
this.destroy();
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Implementação do AsyncDisposable interface para using await
|
|
151
|
+
*/
|
|
152
|
+
async [Symbol.asyncDispose]() {
|
|
153
|
+
this.destroy();
|
|
154
|
+
}
|
|
155
|
+
inicializar(arquivoConfig, chaveCrypt) {
|
|
156
|
+
//let status = this.LIB_Inicializar(this.handle, arquivoConfig, chaveCrypt)
|
|
157
|
+
if (typeof arquivoConfig === "undefined" && typeof chaveCrypt === "undefined") {
|
|
158
|
+
return this.#inicializar(this.arquivoConfig, this.chaveCrypt);
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
if (typeof arquivoConfig === "string" && typeof chaveCrypt === "string") {
|
|
162
|
+
return this.#inicializar(arquivoConfig, chaveCrypt);
|
|
163
|
+
}
|
|
164
|
+
throw new Error("inicializar precisa de dois parâmetros: chaveCrypt e arquivoConfig");
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
// metodo auxiliar para destruir o ponteiro do handle
|
|
168
|
+
#releaseHandle() {
|
|
169
|
+
if (!this.handle) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
koffi.encode(this.getHandle(), 'void *', null);
|
|
173
|
+
koffi.free(this.handle);
|
|
174
|
+
this.handle = null;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Método usado para remover ACBrLib e suas classes da memoria
|
|
178
|
+
* @returns 0 ou código de erro
|
|
179
|
+
*/
|
|
180
|
+
finalizar() {
|
|
181
|
+
if (!this.#isInitialized()) {
|
|
182
|
+
return 0;
|
|
183
|
+
}
|
|
184
|
+
let status = this.LIB_Finalizar(this.getHandle());
|
|
185
|
+
if (status == ACBrLibResultCodes_1.ACBrLibResultCodes.OK) {
|
|
186
|
+
this.#releaseHandle();
|
|
187
|
+
this.isHandleInitialized = false;
|
|
188
|
+
}
|
|
189
|
+
this._checkResult(status);
|
|
190
|
+
return status;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* @description Método que retornar o nome da biblioteca.
|
|
194
|
+
* @returns Uma string com o nome da biblioteca
|
|
195
|
+
*/
|
|
196
|
+
nome() {
|
|
197
|
+
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
198
|
+
try {
|
|
199
|
+
const acbrBuffer = __addDisposableResource(env_1, new ACBrBuffer_2.default(ACBrBuffer_1.TAMANHO_PADRAO), false);
|
|
200
|
+
let status = this.LIB_Nome(this.getHandle(), acbrBuffer.getBuffer(), acbrBuffer.getRefTamanhoBuffer());
|
|
201
|
+
this._checkResult(status);
|
|
202
|
+
return this._processaResult(acbrBuffer);
|
|
203
|
+
}
|
|
204
|
+
catch (e_1) {
|
|
205
|
+
env_1.error = e_1;
|
|
206
|
+
env_1.hasError = true;
|
|
207
|
+
}
|
|
208
|
+
finally {
|
|
209
|
+
__disposeResources(env_1);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* @description Método que retornar a versão da biblioteca.
|
|
214
|
+
* @returns Uma string com o versão da biblioteca
|
|
215
|
+
*/
|
|
216
|
+
versao() {
|
|
217
|
+
const env_2 = { stack: [], error: void 0, hasError: false };
|
|
218
|
+
try {
|
|
219
|
+
const acbrBuffer = __addDisposableResource(env_2, new ACBrBuffer_2.default(ACBrBuffer_1.TAMANHO_PADRAO), false);
|
|
220
|
+
let status = this.LIB_Versao(this.getHandle(), acbrBuffer.getBuffer(), acbrBuffer.getRefTamanhoBuffer());
|
|
221
|
+
this._checkResult(status);
|
|
222
|
+
return this._processaResult(acbrBuffer);
|
|
223
|
+
}
|
|
224
|
+
catch (e_2) {
|
|
225
|
+
env_2.error = e_2;
|
|
226
|
+
env_2.hasError = true;
|
|
227
|
+
}
|
|
228
|
+
finally {
|
|
229
|
+
__disposeResources(env_2);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* @description Método usado retornar o ultimo retorno processado pela biblioteca
|
|
234
|
+
* @returns Retorna uma string com o último retorno processado pela biblioteca.
|
|
235
|
+
*/
|
|
236
|
+
ultimoRetorno() {
|
|
237
|
+
const env_3 = { stack: [], error: void 0, hasError: false };
|
|
238
|
+
try {
|
|
239
|
+
const acbrBuffer = __addDisposableResource(env_3, new ACBrBuffer_2.default(ACBrBuffer_1.TAMANHO_PADRAO), false);
|
|
240
|
+
this.LIB_UltimoRetorno(this.getHandle(), acbrBuffer.getBuffer(), acbrBuffer.getRefTamanhoBuffer());
|
|
241
|
+
return this._processaResult(acbrBuffer);
|
|
242
|
+
}
|
|
243
|
+
catch (e_3) {
|
|
244
|
+
env_3.error = e_3;
|
|
245
|
+
env_3.hasError = true;
|
|
246
|
+
}
|
|
247
|
+
finally {
|
|
248
|
+
__disposeResources(env_3);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* @description Método usado para ler a configuração da biblioteca do arquivo INI informado.
|
|
253
|
+
* @param arquivoConfig Arquivo INI para ler, se informado vazio será usado o valor padrão.
|
|
254
|
+
* @returns 0 ou código de erro
|
|
255
|
+
*/
|
|
256
|
+
configLer(arquivoConfig) {
|
|
257
|
+
if (typeof arquivoConfig === "undefined") {
|
|
258
|
+
return this.#configLer(this.arquivoConfig);
|
|
259
|
+
}
|
|
260
|
+
return this.#configLer(arquivoConfig);
|
|
261
|
+
}
|
|
262
|
+
configGravar(arquivoConfig) {
|
|
263
|
+
if (typeof arquivoConfig === "undefined") {
|
|
264
|
+
return this.#configGravar(this.arquivoConfig);
|
|
265
|
+
}
|
|
266
|
+
return this.#configGravar(arquivoConfig);
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* @description Método usado para ler uma determinado item da configuração.
|
|
270
|
+
* @param sessao Nome da sessão de configuração.
|
|
271
|
+
* @param chave Nome da chave da sessão.
|
|
272
|
+
* @returns 0 ou código de erro
|
|
273
|
+
*/
|
|
274
|
+
configLerValor(sessao, chave) {
|
|
275
|
+
const env_4 = { stack: [], error: void 0, hasError: false };
|
|
276
|
+
try {
|
|
277
|
+
const acbrBuffer = __addDisposableResource(env_4, new ACBrBuffer_2.default(ACBrBuffer_1.TAMANHO_PADRAO), false);
|
|
278
|
+
let status = this.LIB_ConfigLerValor(this.getHandle(), sessao, chave, acbrBuffer.getBuffer(), acbrBuffer.getRefTamanhoBuffer());
|
|
279
|
+
this._checkResult(status);
|
|
280
|
+
return this._processaResult(acbrBuffer);
|
|
281
|
+
}
|
|
282
|
+
catch (e_4) {
|
|
283
|
+
env_4.error = e_4;
|
|
284
|
+
env_4.hasError = true;
|
|
285
|
+
}
|
|
286
|
+
finally {
|
|
287
|
+
__disposeResources(env_4);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* @description Método usado para gravar um determinado item da configuração.
|
|
292
|
+
* @param sessao Nome da sessão de configuração.
|
|
293
|
+
* @param chave Nome da chave da sessão.
|
|
294
|
+
* @param valor Valor para ser gravado na configuração
|
|
295
|
+
* @returns 0 ou código de erro
|
|
296
|
+
*/
|
|
297
|
+
configGravarValor(sessao, chave, valor) {
|
|
298
|
+
let status = this.LIB_ConfigGravarValor(this.getHandle(), sessao, chave, valor);
|
|
299
|
+
this._checkResult(status);
|
|
300
|
+
return status;
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* @description Método usado para exportar a configuração da biblioteca do arquivo INI informado.
|
|
304
|
+
* @returns Uma string com a configuração exportada.
|
|
305
|
+
*/
|
|
306
|
+
configExportar() {
|
|
307
|
+
const env_5 = { stack: [], error: void 0, hasError: false };
|
|
308
|
+
try {
|
|
309
|
+
const acbrBuffer = __addDisposableResource(env_5, new ACBrBuffer_2.default(ACBrBuffer_1.TAMANHO_PADRAO), false);
|
|
310
|
+
let status = this.LIB_ConfigExportar(this.getHandle(), acbrBuffer.getBuffer(), acbrBuffer.getRefTamanhoBuffer());
|
|
311
|
+
this._checkResult(status);
|
|
312
|
+
return this._processaResult(acbrBuffer);
|
|
313
|
+
}
|
|
314
|
+
catch (e_5) {
|
|
315
|
+
env_5.error = e_5;
|
|
316
|
+
env_5.hasError = true;
|
|
317
|
+
}
|
|
318
|
+
finally {
|
|
319
|
+
__disposeResources(env_5);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
*
|
|
324
|
+
* @description Método usado para importar a configuração da biblioteca do arquivo INI informado
|
|
325
|
+
* @param arquivoConfig Arquivo INI para ler, se informado vazio será usado o valor padrão.
|
|
326
|
+
* @returns 0 ou código de erro
|
|
327
|
+
*/
|
|
328
|
+
configImportar(arquivoConfig) {
|
|
329
|
+
let status = this.LIB_ConfigImportar(this.getHandle(), arquivoConfig);
|
|
330
|
+
this._checkResult(status);
|
|
331
|
+
return status;
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* @description Método que retorna informações da biblioteca OpenSsl
|
|
335
|
+
* @returns
|
|
336
|
+
*/
|
|
337
|
+
openSslInfo() {
|
|
338
|
+
const env_6 = { stack: [], error: void 0, hasError: false };
|
|
339
|
+
try {
|
|
340
|
+
const acbrBuffer = __addDisposableResource(env_6, new ACBrBuffer_2.default(ACBrBuffer_1.TAMANHO_PADRAO), false);
|
|
341
|
+
let status = this.LIB_OpenSSLInfo(this.getHandle(), acbrBuffer.getBuffer(), acbrBuffer.getRefTamanhoBuffer());
|
|
342
|
+
this._checkResult(status);
|
|
343
|
+
return this._processaResult(acbrBuffer);
|
|
344
|
+
}
|
|
345
|
+
catch (e_6) {
|
|
346
|
+
env_6.error = e_6;
|
|
347
|
+
env_6.hasError = true;
|
|
348
|
+
}
|
|
349
|
+
finally {
|
|
350
|
+
__disposeResources(env_6);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
/* Métodos protegidos */
|
|
354
|
+
_isRequiredReallocBuffer(requiredLen) {
|
|
355
|
+
return requiredLen > ACBrBuffer_1.TAMANHO_PADRAO;
|
|
356
|
+
}
|
|
357
|
+
_processaResult(buffer) {
|
|
358
|
+
let requiredLen = koffi.decode(buffer.getRefTamanhoBuffer(), 'int');
|
|
359
|
+
if (this._isRequiredReallocBuffer(requiredLen)) {
|
|
360
|
+
requiredLen = Math.round(requiredLen * 1.3);
|
|
361
|
+
return this._ultimoRetorno(requiredLen);
|
|
362
|
+
}
|
|
363
|
+
return buffer.toString();
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Verifica se o resultado é um código de erro
|
|
367
|
+
* @param result
|
|
368
|
+
* @returns
|
|
369
|
+
*/
|
|
370
|
+
_isResultErrorCode(result) {
|
|
371
|
+
return result < ACBrLibResultCodes_1.ACBrLibResultCodes.OK;
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Checa o resultado da operação e propaga a exceção se result < 0
|
|
375
|
+
* @param result
|
|
376
|
+
*/
|
|
377
|
+
_checkResult(result) {
|
|
378
|
+
// se o resultado é maior ou igual a OK, não há erro
|
|
379
|
+
if (!this._isResultErrorCode(result)) {
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
let errorMessage = this.ultimoRetorno();
|
|
383
|
+
console.log("Checking result: ", result, " Error message: ", errorMessage);
|
|
384
|
+
switch (result) {
|
|
385
|
+
case ACBrLibResultCodes_1.ACBrLibResultCodes.ErrLibNaoInicializada:
|
|
386
|
+
throw new exception_1.ACBrLibLibNaoInicializadaError("Erro ao inicializar " + this.nome);
|
|
387
|
+
break;
|
|
388
|
+
case ACBrLibResultCodes_1.ACBrLibResultCodes.ErrLibNaoFinalizada:
|
|
389
|
+
throw new exception_1.ACBrLibLibNaoFinalizadaError("Erro ao finalizar a biblioteca");
|
|
390
|
+
break;
|
|
391
|
+
case ACBrLibResultCodes_1.ACBrLibResultCodes.ErrConfigLer:
|
|
392
|
+
throw new exception_1.ACBrLibConfigLerError(errorMessage);
|
|
393
|
+
break;
|
|
394
|
+
case ACBrLibResultCodes_1.ACBrLibResultCodes.ErrConfigGravar:
|
|
395
|
+
throw new exception_1.ACBrLibConfigGravarError(errorMessage);
|
|
396
|
+
break;
|
|
397
|
+
case ACBrLibResultCodes_1.ACBrLibResultCodes.ErrArquivoNaoExiste:
|
|
398
|
+
throw new exception_1.ACBrLibArquivoNaoExisteError(errorMessage);
|
|
399
|
+
break;
|
|
400
|
+
case ACBrLibResultCodes_1.ACBrLibResultCodes.ErrDiretorioNaoExiste:
|
|
401
|
+
throw new exception_1.ACBrLibDiretorioNaoExisteError(errorMessage);
|
|
402
|
+
break;
|
|
403
|
+
case ACBrLibResultCodes_1.ACBrLibResultCodes.ErrHttp:
|
|
404
|
+
throw new exception_1.ACBrLibHttpError(errorMessage);
|
|
405
|
+
break;
|
|
406
|
+
case ACBrLibResultCodes_1.ACBrLibResultCodes.ErrTimeOut:
|
|
407
|
+
throw new exception_1.ACBrLibTimeOutError(errorMessage);
|
|
408
|
+
break;
|
|
409
|
+
case ACBrLibResultCodes_1.ACBrLibResultCodes.ErrDemoExpirado:
|
|
410
|
+
throw new exception_1.ACBrLibDemoExpiradoError(errorMessage);
|
|
411
|
+
break;
|
|
412
|
+
case ACBrLibResultCodes_1.ACBrLibResultCodes.ErrNaoDisponivelEmModoConsole:
|
|
413
|
+
throw new exception_1.ACBrLibNaoDisponivelEmModoConsoleError(errorMessage);
|
|
414
|
+
break;
|
|
415
|
+
case ACBrLibResultCodes_1.ACBrLibResultCodes.ErrParametroInvalido:
|
|
416
|
+
throw new exception_1.ACBrLibParametroInvalidoError(errorMessage);
|
|
417
|
+
break;
|
|
418
|
+
case ACBrLibResultCodes_1.ACBrLibResultCodes.ErrExecutandoMetodo:
|
|
419
|
+
throw new exception_1.ACBrLibParametroInvalidoError(errorMessage);
|
|
420
|
+
break;
|
|
421
|
+
default:
|
|
422
|
+
// se a exceção não é uma exceção comum a todas as bibliotecas, exibe a mensagem de erro
|
|
423
|
+
// as classes filhas devem implementar as exceções específicas
|
|
424
|
+
console.error("O código de erro ", result, " Mensagem: ", errorMessage);
|
|
425
|
+
break;
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
_ultimoRetorno(size) {
|
|
429
|
+
const env_7 = { stack: [], error: void 0, hasError: false };
|
|
430
|
+
try {
|
|
431
|
+
const acbrBuffer = __addDisposableResource(env_7, new ACBrBuffer_2.default(size), false);
|
|
432
|
+
this.LIB_UltimoRetorno(this.getHandle(), acbrBuffer.getBuffer(), acbrBuffer.getRefTamanhoBuffer());
|
|
433
|
+
return acbrBuffer.toString();
|
|
434
|
+
}
|
|
435
|
+
catch (e_7) {
|
|
436
|
+
env_7.error = e_7;
|
|
437
|
+
env_7.hasError = true;
|
|
438
|
+
}
|
|
439
|
+
finally {
|
|
440
|
+
__disposeResources(env_7);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
#configGravar(arquivoConfig) {
|
|
444
|
+
let status = this.LIB_ConfigGravar(this.getHandle(), arquivoConfig);
|
|
445
|
+
this._checkResult(status);
|
|
446
|
+
return status;
|
|
447
|
+
}
|
|
448
|
+
#configLer(arquivoConfig) {
|
|
449
|
+
let status = this.LIB_ConfigLer(this.getHandle(), arquivoConfig);
|
|
450
|
+
this._checkResult(status);
|
|
451
|
+
return status;
|
|
452
|
+
}
|
|
453
|
+
#inicializar(arquivoConfig, chaveCrypt) {
|
|
454
|
+
if (this.handle == null) {
|
|
455
|
+
this.handle = koffi.alloc('void *', 1);
|
|
456
|
+
}
|
|
457
|
+
let status = this.LIB_Inicializar(this.handle, arquivoConfig, chaveCrypt);
|
|
458
|
+
if (status === ACBrLibResultCodes_1.ACBrLibResultCodes.OK) {
|
|
459
|
+
this.isHandleInitialized = true;
|
|
460
|
+
}
|
|
461
|
+
else {
|
|
462
|
+
// por segurança, se a inicialização falhar, libera o handle
|
|
463
|
+
this.#releaseHandle();
|
|
464
|
+
this.isHandleInitialized = false;
|
|
465
|
+
}
|
|
466
|
+
this._checkResult(status);
|
|
467
|
+
return status;
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
exports.default = ACBrLibBaseMT;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@projetoacbr/acbrlib-base-node",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/src/index.js",
|
|
6
6
|
"types": "dist/src/index.d.ts",
|
|
@@ -14,14 +14,14 @@
|
|
|
14
14
|
},
|
|
15
15
|
"repository": {
|
|
16
16
|
"type": "git",
|
|
17
|
-
"url": "git+https://github.com/
|
|
17
|
+
"url": "git+https://github.com/Projeto-ACBr-Oficial/ACBrLib-Nodejs.git"
|
|
18
18
|
},
|
|
19
19
|
"author": "",
|
|
20
20
|
"license": "ISC",
|
|
21
21
|
"bugs": {
|
|
22
|
-
"url": "https://github.com/
|
|
22
|
+
"url": "https://github.com/Projeto-ACBr-Oficial/ACBrLib-Nodejs/issues"
|
|
23
23
|
},
|
|
24
|
-
"homepage": "https://github.com/
|
|
24
|
+
"homepage": "https://github.com/Projeto-ACBr-Oficial/ACBrLib-Nodejs#readme",
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@types/node": "^22.5.4",
|
|
27
27
|
"typescript": "^5.5.4"
|