foxnfe 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 +236 -0
- package/dist/client.d.ts +34 -0
- package/dist/client.js +136 -0
- package/dist/distribuicao.d.ts +38 -0
- package/dist/distribuicao.js +53 -0
- package/dist/documents.d.ts +28 -0
- package/dist/documents.js +64 -0
- package/dist/errors.d.ts +14 -0
- package/dist/errors.js +30 -0
- package/dist/events.d.ts +64 -0
- package/dist/events.js +109 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.js +45 -0
- package/dist/mcp.d.ts +22 -0
- package/dist/mcp.js +41 -0
- package/dist/nfe.d.ts +39 -0
- package/dist/nfe.js +73 -0
- package/dist/nfse.d.ts +32 -0
- package/dist/nfse.js +50 -0
- package/dist/reference.d.ts +51 -0
- package/dist/reference.js +52 -0
- package/dist/rtc.d.ts +45 -0
- package/dist/rtc.js +45 -0
- package/dist/support.d.ts +19 -0
- package/dist/support.js +31 -0
- package/dist/types.d.ts +139 -0
- package/dist/types.js +3 -0
- package/dist/webhook.d.ts +85 -0
- package/dist/webhook.js +59 -0
- package/package.json +38 -0
package/dist/rtc.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Client } from './client.js';
|
|
2
|
+
export interface RtcResolveRequest {
|
|
3
|
+
sku: string;
|
|
4
|
+
dfe_type: 'NFE' | 'NFCE' | 'NFSE';
|
|
5
|
+
tax_date: string;
|
|
6
|
+
item_number: number;
|
|
7
|
+
calculator_payload: Record<string, unknown>;
|
|
8
|
+
establishment_key?: string;
|
|
9
|
+
operation_code?: string;
|
|
10
|
+
origin_uf?: string;
|
|
11
|
+
destination_uf?: string;
|
|
12
|
+
recipient_indicator?: string;
|
|
13
|
+
purpose?: string;
|
|
14
|
+
document_reference?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface RtcScenarioRequest {
|
|
17
|
+
name: string;
|
|
18
|
+
dfe_type: 'NFE' | 'NFCE' | 'NFSE';
|
|
19
|
+
input: Omit<RtcResolveRequest, 'dfe_type'>;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Reforma tributária (IBS/CBS) — capacidade 26: resolução oficial pela calculadora,
|
|
23
|
+
* explicação/verificação de reprodutibilidade e cenários versionados por tenant.
|
|
24
|
+
* Nenhum valor é estimado localmente; sem parametrização aprovada a API bloqueia com `code`.
|
|
25
|
+
*/
|
|
26
|
+
export declare class Rtc {
|
|
27
|
+
private readonly client;
|
|
28
|
+
constructor(client: Client);
|
|
29
|
+
status(): Promise<Record<string, unknown>>;
|
|
30
|
+
classifications(dfeType: 'NFE' | 'NFCE' | 'NFSE', cst?: string): Promise<Record<string, unknown>>;
|
|
31
|
+
/** Resolve IBS/CBS de um item. 422 com `code` (rule_missing, rule_ambiguous, classification_invalid, catalog_mismatch, payload_invalid) quando bloqueado. */
|
|
32
|
+
resolve(payload: RtcResolveRequest): Promise<Record<string, unknown>>;
|
|
33
|
+
/** Explica uma resolução: regra, perfis, catálogo, versões e conferência do digest. */
|
|
34
|
+
resolution(id: string): Promise<Record<string, unknown>>;
|
|
35
|
+
/** Reexecuta com a mesma entrada: reproducible | output_drift | version_drift | unavailable. */
|
|
36
|
+
verifyResolution(id: string): Promise<Record<string, unknown>>;
|
|
37
|
+
scenarios(): Promise<Record<string, unknown>>;
|
|
38
|
+
/** Cria/versiona um cenário (a linha de base é congelada na criação). */
|
|
39
|
+
createScenario(payload: RtcScenarioRequest): Promise<Record<string, unknown>>;
|
|
40
|
+
runScenarios(): Promise<Record<string, unknown>>;
|
|
41
|
+
runScenario(id: number): Promise<Record<string, unknown>>;
|
|
42
|
+
deleteScenario(id: number): Promise<Record<string, unknown>>;
|
|
43
|
+
private static uuid;
|
|
44
|
+
private static id;
|
|
45
|
+
}
|
package/dist/rtc.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Rtc = void 0;
|
|
4
|
+
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
5
|
+
/**
|
|
6
|
+
* Reforma tributária (IBS/CBS) — capacidade 26: resolução oficial pela calculadora,
|
|
7
|
+
* explicação/verificação de reprodutibilidade e cenários versionados por tenant.
|
|
8
|
+
* Nenhum valor é estimado localmente; sem parametrização aprovada a API bloqueia com `code`.
|
|
9
|
+
*/
|
|
10
|
+
class Rtc {
|
|
11
|
+
constructor(client) {
|
|
12
|
+
this.client = client;
|
|
13
|
+
}
|
|
14
|
+
status() { return this.client.get('fiscal-agent/rtc/status'); }
|
|
15
|
+
classifications(dfeType, cst) {
|
|
16
|
+
if (cst !== undefined && !/^\d{3}$/.test(cst))
|
|
17
|
+
throw new TypeError('cst deve ter 3 dígitos.');
|
|
18
|
+
return this.client.get('fiscal-agent/rtc/classifications', { dfe_type: dfeType, ...(cst ? { cst } : {}) });
|
|
19
|
+
}
|
|
20
|
+
/** Resolve IBS/CBS de um item. 422 com `code` (rule_missing, rule_ambiguous, classification_invalid, catalog_mismatch, payload_invalid) quando bloqueado. */
|
|
21
|
+
resolve(payload) {
|
|
22
|
+
if (!payload.sku || !payload.calculator_payload)
|
|
23
|
+
throw new TypeError('sku e calculator_payload são obrigatórios.');
|
|
24
|
+
return this.client.post('fiscal-agent/rtc/resolve', payload);
|
|
25
|
+
}
|
|
26
|
+
/** Explica uma resolução: regra, perfis, catálogo, versões e conferência do digest. */
|
|
27
|
+
resolution(id) { Rtc.uuid(id); return this.client.get(`fiscal-agent/rtc/resolutions/${id}`); }
|
|
28
|
+
/** Reexecuta com a mesma entrada: reproducible | output_drift | version_drift | unavailable. */
|
|
29
|
+
verifyResolution(id) { Rtc.uuid(id); return this.client.post(`fiscal-agent/rtc/resolutions/${id}/verify`); }
|
|
30
|
+
scenarios() { return this.client.get('rtc-parameterization/scenarios'); }
|
|
31
|
+
/** Cria/versiona um cenário (a linha de base é congelada na criação). */
|
|
32
|
+
createScenario(payload) {
|
|
33
|
+
if (!/^[A-Za-z0-9][A-Za-z0-9._-]{1,79}$/.test(payload.name))
|
|
34
|
+
throw new TypeError('name: 2..80 caracteres [A-Za-z0-9._-].');
|
|
35
|
+
return this.client.post('rtc-parameterization/scenarios', payload);
|
|
36
|
+
}
|
|
37
|
+
runScenarios() { return this.client.post('rtc-parameterization/scenarios/run'); }
|
|
38
|
+
runScenario(id) { Rtc.id(id); return this.client.post(`rtc-parameterization/scenarios/${id}/run`); }
|
|
39
|
+
deleteScenario(id) { Rtc.id(id); return this.client.delete(`rtc-parameterization/scenarios/${id}`); }
|
|
40
|
+
static uuid(id) { if (!UUID.test(id))
|
|
41
|
+
throw new TypeError('id deve ser um UUID.'); }
|
|
42
|
+
static id(id) { if (!Number.isInteger(id) || id < 1)
|
|
43
|
+
throw new TypeError('id deve ser inteiro positivo.'); }
|
|
44
|
+
}
|
|
45
|
+
exports.Rtc = Rtc;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Client } from './client.js';
|
|
2
|
+
export interface SupportCaseRequest {
|
|
3
|
+
subject: string;
|
|
4
|
+
channel?: string;
|
|
5
|
+
priority?: 'urgent' | 'high' | 'normal' | 'low';
|
|
6
|
+
[k: string]: unknown;
|
|
7
|
+
}
|
|
8
|
+
/** Status do serviço (público, cache 30 s) e casos de suporte com SLA por prioridade (capacidade 28). */
|
|
9
|
+
export declare class Support {
|
|
10
|
+
private readonly client;
|
|
11
|
+
constructor(client: Client);
|
|
12
|
+
/** Componentes, latências e incidentes abertos. Não exige token. */
|
|
13
|
+
status(): Promise<Record<string, unknown>>;
|
|
14
|
+
cases(params?: Record<string, string | number>): Promise<Record<string, unknown>>;
|
|
15
|
+
createCase(payload: SupportCaseRequest): Promise<Record<string, unknown>>;
|
|
16
|
+
case(id: number): Promise<Record<string, unknown>>;
|
|
17
|
+
/** Metas de SLA (primeira resposta/resolução, em minutos) por prioridade e aderência. */
|
|
18
|
+
sla(): Promise<Record<string, unknown>>;
|
|
19
|
+
}
|
package/dist/support.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Support = void 0;
|
|
4
|
+
/** Status do serviço (público, cache 30 s) e casos de suporte com SLA por prioridade (capacidade 28). */
|
|
5
|
+
class Support {
|
|
6
|
+
constructor(client) {
|
|
7
|
+
this.client = client;
|
|
8
|
+
}
|
|
9
|
+
/** Componentes, latências e incidentes abertos. Não exige token. */
|
|
10
|
+
status() { return this.client.get('status'); }
|
|
11
|
+
cases(params = {}) {
|
|
12
|
+
const p = {};
|
|
13
|
+
for (const [k, v] of Object.entries(params))
|
|
14
|
+
p[k] = String(v);
|
|
15
|
+
return this.client.get('support/cases', p);
|
|
16
|
+
}
|
|
17
|
+
createCase(payload) {
|
|
18
|
+
const len = [...(payload.subject ?? '').trim()].length;
|
|
19
|
+
if (len < 3 || len > 200)
|
|
20
|
+
throw new TypeError('subject deve ter entre 3 e 200 caracteres.');
|
|
21
|
+
return this.client.post('support/cases', payload);
|
|
22
|
+
}
|
|
23
|
+
case(id) {
|
|
24
|
+
if (!Number.isInteger(id) || id < 1)
|
|
25
|
+
throw new TypeError('id deve ser inteiro positivo.');
|
|
26
|
+
return this.client.get(`support/cases/${id}`);
|
|
27
|
+
}
|
|
28
|
+
/** Metas de SLA (primeira resposta/resolução, em minutos) por prioridade e aderência. */
|
|
29
|
+
sla() { return this.client.get('support/cases/sla'); }
|
|
30
|
+
}
|
|
31
|
+
exports.Support = Support;
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
export interface ClientOptions {
|
|
2
|
+
tenantSlug: string;
|
|
3
|
+
token?: string;
|
|
4
|
+
baseUrl?: string;
|
|
5
|
+
timeoutMs?: number;
|
|
6
|
+
}
|
|
7
|
+
export interface NfeEmitRequest {
|
|
8
|
+
ambiente: 1 | 2;
|
|
9
|
+
certificate_id: number;
|
|
10
|
+
tomador: {
|
|
11
|
+
cnpj?: string;
|
|
12
|
+
cpf?: string;
|
|
13
|
+
razao_social: string;
|
|
14
|
+
endereco: {
|
|
15
|
+
logradouro: string;
|
|
16
|
+
numero: string;
|
|
17
|
+
municipio: string;
|
|
18
|
+
uf: string;
|
|
19
|
+
cep: string;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
itens: Array<{
|
|
23
|
+
codigo: string;
|
|
24
|
+
descricao: string;
|
|
25
|
+
cfop: string;
|
|
26
|
+
quantidade: number;
|
|
27
|
+
valor_unitario: number;
|
|
28
|
+
valor_total: number;
|
|
29
|
+
ncm?: string;
|
|
30
|
+
}>;
|
|
31
|
+
pagamentos: Array<{
|
|
32
|
+
forma: string;
|
|
33
|
+
valor: number;
|
|
34
|
+
}>;
|
|
35
|
+
total: number;
|
|
36
|
+
}
|
|
37
|
+
/** 1.3.0 — rejeição SEFAZ com o xMotivo oficial e a classificação do catálogo (categoria/ação/dica). */
|
|
38
|
+
export interface NfeRejection {
|
|
39
|
+
code: string;
|
|
40
|
+
reason: string | null;
|
|
41
|
+
codigo: number;
|
|
42
|
+
categoria: string;
|
|
43
|
+
acao: 'corrigir_dados' | 'certificado' | 'reenviar' | 'consultar' | 'suporte';
|
|
44
|
+
dica: string;
|
|
45
|
+
catalogado: boolean;
|
|
46
|
+
retomavel: boolean;
|
|
47
|
+
}
|
|
48
|
+
export interface NfeResource {
|
|
49
|
+
id: number;
|
|
50
|
+
/** Valores reais da API (o antigo 'cancelled' nunca existiu; o correto é 'canceled'). */
|
|
51
|
+
status: 'draft' | 'pending' | 'processing' | 'authorized' | 'rejected' | 'denied' | 'canceled' | 'contingency';
|
|
52
|
+
rejection?: NfeRejection | null;
|
|
53
|
+
chave_acesso?: string;
|
|
54
|
+
numero?: string;
|
|
55
|
+
serie?: string;
|
|
56
|
+
data_emissao?: string;
|
|
57
|
+
total: number;
|
|
58
|
+
tomador_nome: string;
|
|
59
|
+
xml_url?: string;
|
|
60
|
+
pdf_url?: string;
|
|
61
|
+
created_at: string;
|
|
62
|
+
updated_at: string;
|
|
63
|
+
}
|
|
64
|
+
export interface NfeCancelRequest {
|
|
65
|
+
justificativa: string;
|
|
66
|
+
}
|
|
67
|
+
export interface NfseEmitRequest {
|
|
68
|
+
ambiente: 1 | 2;
|
|
69
|
+
certificate_id: number;
|
|
70
|
+
prestador: {
|
|
71
|
+
cnpj: string;
|
|
72
|
+
inscricao_municipal: string;
|
|
73
|
+
razao_social: string;
|
|
74
|
+
codigo_municipio: string;
|
|
75
|
+
};
|
|
76
|
+
tomador: {
|
|
77
|
+
cnpj?: string;
|
|
78
|
+
cpf?: string;
|
|
79
|
+
nome: string;
|
|
80
|
+
};
|
|
81
|
+
servico: {
|
|
82
|
+
codigo_tributacao_nacional: string;
|
|
83
|
+
codigo_tributacao_municipal?: string;
|
|
84
|
+
descricao: string;
|
|
85
|
+
data_competencia: string;
|
|
86
|
+
valor: number;
|
|
87
|
+
aliquota_iss?: number;
|
|
88
|
+
codigo_nbs?: string;
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
export interface NfseResource {
|
|
92
|
+
id: number;
|
|
93
|
+
status: 'pending' | 'authorized' | 'rejected' | 'cancelled';
|
|
94
|
+
numero_nfse?: string;
|
|
95
|
+
chave_acesso?: string;
|
|
96
|
+
codigo_verificacao?: string;
|
|
97
|
+
valor_servico: number;
|
|
98
|
+
valor_iss: number;
|
|
99
|
+
aliquota_iss: number;
|
|
100
|
+
xml_nfse?: string;
|
|
101
|
+
danfse_url?: string;
|
|
102
|
+
created_at: string;
|
|
103
|
+
updated_at: string;
|
|
104
|
+
}
|
|
105
|
+
export interface NfseCancelRequest {
|
|
106
|
+
motivo: string;
|
|
107
|
+
}
|
|
108
|
+
export interface NfseSubstituteRequest extends NfseEmitRequest {
|
|
109
|
+
motivo_cancelamento: string;
|
|
110
|
+
}
|
|
111
|
+
export interface McpTool {
|
|
112
|
+
name: string;
|
|
113
|
+
description: string;
|
|
114
|
+
input_schema: Record<string, unknown>;
|
|
115
|
+
}
|
|
116
|
+
export interface McpToolCallRequest {
|
|
117
|
+
tool: string;
|
|
118
|
+
input: Record<string, unknown>;
|
|
119
|
+
}
|
|
120
|
+
export interface McpToolCallResponse {
|
|
121
|
+
content: Array<{
|
|
122
|
+
type: 'text' | 'image' | 'resource';
|
|
123
|
+
text?: string;
|
|
124
|
+
}>;
|
|
125
|
+
is_error: boolean;
|
|
126
|
+
}
|
|
127
|
+
export interface LoginResponse {
|
|
128
|
+
token: string;
|
|
129
|
+
user: {
|
|
130
|
+
id: number;
|
|
131
|
+
name: string;
|
|
132
|
+
email: string;
|
|
133
|
+
tenant_id: number;
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
export interface ApiErrorResponse {
|
|
137
|
+
message: string;
|
|
138
|
+
errors?: Record<string, string[]>;
|
|
139
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { Client } from './client.js';
|
|
2
|
+
export interface WebhookConfig {
|
|
3
|
+
configured: boolean;
|
|
4
|
+
webhook_url?: string;
|
|
5
|
+
secret_preview?: string;
|
|
6
|
+
active?: boolean;
|
|
7
|
+
}
|
|
8
|
+
/** Response returned by updateConfig() — does not include the `configured` field. */
|
|
9
|
+
export interface WebhookUpdateResponse {
|
|
10
|
+
ok: boolean;
|
|
11
|
+
webhook_url: string;
|
|
12
|
+
secret_preview: string;
|
|
13
|
+
active: boolean;
|
|
14
|
+
}
|
|
15
|
+
/** @deprecated Use WebhookUpdateResponse. */
|
|
16
|
+
export type WebhookConfigResponse = WebhookUpdateResponse;
|
|
17
|
+
export interface WebhookDelivery {
|
|
18
|
+
delivery_id: string;
|
|
19
|
+
event: string;
|
|
20
|
+
attempts: number;
|
|
21
|
+
delivered_at: string | null;
|
|
22
|
+
failed_at: string | null;
|
|
23
|
+
response_status: number | null;
|
|
24
|
+
created_at: string;
|
|
25
|
+
}
|
|
26
|
+
export interface WebhookDeliveryPage {
|
|
27
|
+
data: WebhookDelivery[];
|
|
28
|
+
current_page: number;
|
|
29
|
+
per_page: number;
|
|
30
|
+
total: number;
|
|
31
|
+
last_page: number;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Endpoints de webhook outbound CloudEvents v1.0.
|
|
35
|
+
*
|
|
36
|
+
* Cada evento é assinado via HMAC-SHA256 sobre o JSON canônico.
|
|
37
|
+
* Verifique o cabeçalho `X-Webhook-Signature: sha256=<hex>` no receptor.
|
|
38
|
+
*/
|
|
39
|
+
export declare class Webhook {
|
|
40
|
+
private readonly client;
|
|
41
|
+
constructor(client: Client);
|
|
42
|
+
/** Consulta a configuração de webhook do tenant. */
|
|
43
|
+
getConfig(): Promise<WebhookConfig>;
|
|
44
|
+
/**
|
|
45
|
+
* Cria ou atualiza a URL e o segredo do webhook.
|
|
46
|
+
* URL deve ser HTTPS; hosts privados/loopback são rejeitados (anti-SSRF).
|
|
47
|
+
* Se omitido, o segredo existente é preservado; um segredo é gerado apenas no primeiro cadastro.
|
|
48
|
+
*/
|
|
49
|
+
updateConfig(webhookUrl: string, webhookSecret?: string): Promise<WebhookUpdateResponse>;
|
|
50
|
+
/** Desativa o webhook (preserva a configuração para reativação via PUT). */
|
|
51
|
+
deleteConfig(): Promise<{
|
|
52
|
+
ok: boolean;
|
|
53
|
+
active: boolean;
|
|
54
|
+
}>;
|
|
55
|
+
/** Catálogo publicado de eventos (tipo CloudEvents, descrição, campos de `data`). */
|
|
56
|
+
events(): Promise<{
|
|
57
|
+
data: Array<{
|
|
58
|
+
event: string;
|
|
59
|
+
type: string;
|
|
60
|
+
description: string;
|
|
61
|
+
since: string;
|
|
62
|
+
data: string[];
|
|
63
|
+
}>;
|
|
64
|
+
type_prefix: string;
|
|
65
|
+
}>;
|
|
66
|
+
/** Lista o histórico de entregas paginado (15 por página). */
|
|
67
|
+
deliveries(page?: number): Promise<WebhookDeliveryPage>;
|
|
68
|
+
/**
|
|
69
|
+
* Enfileira um evento sintético `nfe.test` para validar URL,
|
|
70
|
+
* assinatura HMAC e parsing CloudEvents sem emitir documento real.
|
|
71
|
+
*/
|
|
72
|
+
test(): Promise<{
|
|
73
|
+
ok: boolean;
|
|
74
|
+
event: string;
|
|
75
|
+
delivery_id: string;
|
|
76
|
+
}>;
|
|
77
|
+
/**
|
|
78
|
+
* Reenvia uma entrega que falhou, zerando o contador de tentativas.
|
|
79
|
+
* Retorna 409 se a entrega já foi realizada com sucesso.
|
|
80
|
+
*/
|
|
81
|
+
resend(deliveryId: string): Promise<{
|
|
82
|
+
ok: boolean;
|
|
83
|
+
delivery_id: string;
|
|
84
|
+
}>;
|
|
85
|
+
}
|
package/dist/webhook.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Webhook = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Endpoints de webhook outbound CloudEvents v1.0.
|
|
6
|
+
*
|
|
7
|
+
* Cada evento é assinado via HMAC-SHA256 sobre o JSON canônico.
|
|
8
|
+
* Verifique o cabeçalho `X-Webhook-Signature: sha256=<hex>` no receptor.
|
|
9
|
+
*/
|
|
10
|
+
class Webhook {
|
|
11
|
+
constructor(client) {
|
|
12
|
+
this.client = client;
|
|
13
|
+
}
|
|
14
|
+
/** Consulta a configuração de webhook do tenant. */
|
|
15
|
+
getConfig() {
|
|
16
|
+
return this.client.get('webhooks/config');
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Cria ou atualiza a URL e o segredo do webhook.
|
|
20
|
+
* URL deve ser HTTPS; hosts privados/loopback são rejeitados (anti-SSRF).
|
|
21
|
+
* Se omitido, o segredo existente é preservado; um segredo é gerado apenas no primeiro cadastro.
|
|
22
|
+
*/
|
|
23
|
+
updateConfig(webhookUrl, webhookSecret) {
|
|
24
|
+
return this.client.put('webhooks/config', {
|
|
25
|
+
webhook_url: webhookUrl,
|
|
26
|
+
...(webhookSecret !== undefined ? { webhook_secret: webhookSecret } : {}),
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
/** Desativa o webhook (preserva a configuração para reativação via PUT). */
|
|
30
|
+
deleteConfig() {
|
|
31
|
+
return this.client.delete('webhooks/config');
|
|
32
|
+
}
|
|
33
|
+
/** Catálogo publicado de eventos (tipo CloudEvents, descrição, campos de `data`). */
|
|
34
|
+
events() {
|
|
35
|
+
return this.client.get('webhooks/events');
|
|
36
|
+
}
|
|
37
|
+
/** Lista o histórico de entregas paginado (15 por página). */
|
|
38
|
+
deliveries(page = 1) {
|
|
39
|
+
return this.client.get('webhooks/deliveries', { page: String(page) });
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Enfileira um evento sintético `nfe.test` para validar URL,
|
|
43
|
+
* assinatura HMAC e parsing CloudEvents sem emitir documento real.
|
|
44
|
+
*/
|
|
45
|
+
test() {
|
|
46
|
+
return this.client.post('webhooks/test');
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Reenvia uma entrega que falhou, zerando o contador de tentativas.
|
|
50
|
+
* Retorna 409 se a entrega já foi realizada com sucesso.
|
|
51
|
+
*/
|
|
52
|
+
resend(deliveryId) {
|
|
53
|
+
if (!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(deliveryId)) {
|
|
54
|
+
throw new TypeError("deliveryId deve ser um UUID válido.");
|
|
55
|
+
}
|
|
56
|
+
return this.client.post(`webhooks/deliveries/${encodeURIComponent(deliveryId)}/resend`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.Webhook = Webhook;
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "foxnfe",
|
|
3
|
+
"version": "1.3.0",
|
|
4
|
+
"description": "SDK oficial FOX NF-e para Node.js — emissão NF-e, NFSe, cancelamento, consulta e MCP",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"require": "./dist/index.js",
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "tsc",
|
|
19
|
+
"test": "node --test tests/"
|
|
20
|
+
},
|
|
21
|
+
"keywords": [
|
|
22
|
+
"nfe",
|
|
23
|
+
"nfse",
|
|
24
|
+
"nota-fiscal",
|
|
25
|
+
"fiscal",
|
|
26
|
+
"brasil"
|
|
27
|
+
],
|
|
28
|
+
"author": "Central Fox Tecnologia <dev@centralfox.online>",
|
|
29
|
+
"license": "MIT",
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": ">=18.0.0"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"typescript": "^5.0.0",
|
|
36
|
+
"@types/node": "^20.0.0"
|
|
37
|
+
}
|
|
38
|
+
}
|