@fayz-ai/plugin-fiscal-br 0.2.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/LICENSE +21 -0
- package/README.md +99 -0
- package/dist/connectors/plugnotas.d.ts +34 -0
- package/dist/connectors/plugnotas.d.ts.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1136 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/financial-provider.d.ts +9 -0
- package/dist/lib/financial-provider.d.ts.map +1 -0
- package/dist/migrations/index.d.ts +7 -0
- package/dist/migrations/index.d.ts.map +1 -0
- package/dist/types.d.ts +55 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +60 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Faya Labs
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# @fayz-ai/plugin-fiscal-br
|
|
2
|
+
|
|
3
|
+
**Status:** preview. Sandbox and SEFAZ homologation only; production emission is
|
|
4
|
+
intentionally not exposed by this package.
|
|
5
|
+
|
|
6
|
+
`plugin-fiscal-br` is the Brazilian fiscal addon hosted by
|
|
7
|
+
`@fayz-ai/plugin-financial`. Its first provider is TecnoSpeed PlugNotas and its
|
|
8
|
+
first document journey is NFC-e (model 65) for a completed restaurant order.
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install @fayz-ai/plugin-fiscal-br
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Ownership boundary
|
|
15
|
+
|
|
16
|
+
- `plugin-financial` owns `plg_financial_nfe`, the fiscal document shown to the
|
|
17
|
+
operator. There is no second PlugNotas invoice table.
|
|
18
|
+
- `plugin-fiscal-br` owns the provider connection contract, durable command,
|
|
19
|
+
retry/recovery trail, webhook receipt and emitter claim.
|
|
20
|
+
- The app owns the Edge Function implementation and the setup panel, because it
|
|
21
|
+
owns deployment, origins and product-specific composition.
|
|
22
|
+
- `packages/db` owns `connections`, `orders` and `items`. The addon consumes
|
|
23
|
+
those canonical contracts; it does not recreate `plg_connections` or
|
|
24
|
+
`order_items` from the pre-squash implementation.
|
|
25
|
+
|
|
26
|
+
## Why the command is durable
|
|
27
|
+
|
|
28
|
+
Sending an NFC-e and losing the HTTP response is ambiguous: the provider may
|
|
29
|
+
have accepted the document even though the caller timed out. Repeating the POST
|
|
30
|
+
without first consulting the provider can create a duplicate fiscal effect.
|
|
31
|
+
|
|
32
|
+
The migration therefore creates `plg_fiscalbr_nfce_jobs` before any provider
|
|
33
|
+
call. The job keeps a frozen order snapshot and a stable idempotency key. A
|
|
34
|
+
timeout moves it to `waiting`; a recovery worker claims it with `SKIP LOCKED`,
|
|
35
|
+
queries PlugNotas and only retries with the same integration id when the
|
|
36
|
+
provider confirms the first request does not exist. Webhooks and recovery update
|
|
37
|
+
the same job and the same `plg_financial_nfe` row.
|
|
38
|
+
|
|
39
|
+
## Credential and certificate boundary
|
|
40
|
+
|
|
41
|
+
The browser stores no PlugNotas API key, A1 bytes, A1 password, CSC code or CSC
|
|
42
|
+
token. The setup form uploads the A1 and its password to the app-owned server
|
|
43
|
+
boundary over the authenticated request; the boundary forwards them to the
|
|
44
|
+
provider and discards them. `connections.settings` receives only readiness and
|
|
45
|
+
non-secret metadata such as expiry and an optional fingerprint.
|
|
46
|
+
|
|
47
|
+
CSC belongs to the emitter. It must be collected during that tenant's setup and
|
|
48
|
+
sent to the server boundary. It is not a pool-wide `PLUGNOTAS_CSC_CONFIG_JSON`
|
|
49
|
+
secret and cannot be shared between tenants. This package deliberately removed
|
|
50
|
+
that old draft contract.
|
|
51
|
+
|
|
52
|
+
The PlugNotas software-house API key remains a server-only deployment secret.
|
|
53
|
+
No secret value is committed here; the manifest contains names only so deploy
|
|
54
|
+
and diagnostics can report missing configuration.
|
|
55
|
+
|
|
56
|
+
## Runtime contract
|
|
57
|
+
|
|
58
|
+
```tsx
|
|
59
|
+
import { createFinancialPlugin } from '@fayz-ai/plugin-financial'
|
|
60
|
+
import {
|
|
61
|
+
createPlugNotasFinancialProvider,
|
|
62
|
+
createPlugNotasPlugin,
|
|
63
|
+
} from '@fayz-ai/plugin-fiscal-br'
|
|
64
|
+
|
|
65
|
+
const fiscalProvider = createPlugNotasFinancialProvider({
|
|
66
|
+
base: financialProvider,
|
|
67
|
+
gateway: appOwnedPlugNotasGateway,
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
const plugins = [
|
|
71
|
+
createFinancialPlugin({
|
|
72
|
+
dataProvider: fiscalProvider,
|
|
73
|
+
fiscalProvider: {
|
|
74
|
+
label: 'PlugNotas',
|
|
75
|
+
models: ['nfce'],
|
|
76
|
+
requiresOrder: true,
|
|
77
|
+
},
|
|
78
|
+
}),
|
|
79
|
+
createPlugNotasPlugin({ SetupPanel: AppOwnedSetupPanel }),
|
|
80
|
+
]
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
The decorator never trusts a transient provider response as the ledger. Issue,
|
|
84
|
+
refresh and cancel always return the document read back from the database after
|
|
85
|
+
the server operation. XML, DANFCE and cancellation XML use short-lived URLs
|
|
86
|
+
resolved on demand instead of durable signed URLs stored on the fiscal row.
|
|
87
|
+
|
|
88
|
+
## What this draft does not authorize
|
|
89
|
+
|
|
90
|
+
- It does not apply the migration to a Supabase project.
|
|
91
|
+
- It does not deploy the Edge Function.
|
|
92
|
+
- It does not create or rotate any secret.
|
|
93
|
+
- It does not enable production emission.
|
|
94
|
+
- It does not claim homologation passed; that needs a real emitter, A1, CSC and
|
|
95
|
+
an observed issue/status/artifact/cancel journey.
|
|
96
|
+
|
|
97
|
+
The companion NeoChef PR supplies the application Edge Function and composition.
|
|
98
|
+
The full ownership map and rollout gates are documented in
|
|
99
|
+
[`docs/integrations/PLUGNOTAS-NFCE.md`](../../docs/integrations/PLUGNOTAS-NFCE.md).
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import { type ConnectorDefinition } from '@fayz-ai/core';
|
|
3
|
+
import type { PlugNotasConnectorClient, PlugNotasSetupState } from '../types';
|
|
4
|
+
export declare const PLUGNOTAS_CONNECTOR_ID = "plugnotas";
|
|
5
|
+
export declare const PLUGNOTAS_FIELDS: readonly [{
|
|
6
|
+
readonly key: "emitterCnpj";
|
|
7
|
+
readonly label: "CNPJ do emitente";
|
|
8
|
+
readonly type: "text";
|
|
9
|
+
readonly placeholder: "00.000.000/0000-00";
|
|
10
|
+
}];
|
|
11
|
+
export declare const PLUGNOTAS_SETTINGS: readonly [{
|
|
12
|
+
readonly key: "environment";
|
|
13
|
+
readonly label: "Ambiente fiscal";
|
|
14
|
+
readonly description: "Sandbox simula o emissor. Homologação envia para a SEFAZ sem valor fiscal.";
|
|
15
|
+
readonly type: "select";
|
|
16
|
+
readonly options: [{
|
|
17
|
+
readonly value: "sandbox";
|
|
18
|
+
readonly label: "Sandbox simulado";
|
|
19
|
+
}, {
|
|
20
|
+
readonly value: "homologation";
|
|
21
|
+
readonly label: "Homologação SEFAZ";
|
|
22
|
+
}];
|
|
23
|
+
readonly requiredToOperate: true;
|
|
24
|
+
readonly defaultValue: "sandbox";
|
|
25
|
+
}];
|
|
26
|
+
export declare function isValidCnpj(value: string): boolean;
|
|
27
|
+
export interface CreatePlugNotasConnectorOptions {
|
|
28
|
+
client?: PlugNotasConnectorClient;
|
|
29
|
+
SetupPanel?: React.ComponentType;
|
|
30
|
+
}
|
|
31
|
+
export declare function createPlugNotasConnector(options?: CreatePlugNotasConnectorOptions): ConnectorDefinition;
|
|
32
|
+
/** Persist only server-confirmed readiness and non-secret certificate metadata. */
|
|
33
|
+
export declare function markPlugNotasEmitterReady(input: PlugNotasSetupState): Promise<void>;
|
|
34
|
+
//# sourceMappingURL=plugnotas.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugnotas.d.ts","sourceRoot":"","sources":["../../src/connectors/plugnotas.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAML,KAAK,mBAAmB,EAGzB,MAAM,eAAe,CAAA;AACtB,OAAO,KAAK,EAAE,wBAAwB,EAAwB,mBAAmB,EAAE,MAAM,UAAU,CAAA;AAEnG,eAAO,MAAM,sBAAsB,cAAc,CAAA;AAIjD,eAAO,MAAM,gBAAgB;;;;;EAOiB,CAAA;AAE9C,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;EAWkB,CAAA;AA0BjD,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAWlD;AAqDD,MAAM,WAAW,+BAA+B;IAC9C,MAAM,CAAC,EAAE,wBAAwB,CAAA;IACjC,UAAU,CAAC,EAAE,KAAK,CAAC,aAAa,CAAA;CACjC;AAED,wBAAgB,wBAAwB,CAAC,OAAO,GAAE,+BAAoC,GAAG,mBAAmB,CA0E3G;AAED,mFAAmF;AACnF,wBAAsB,yBAAyB,CAAC,KAAK,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC,CAgBzF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type PluginManifest } from '@fayz-ai/core';
|
|
2
|
+
import { type CreatePlugNotasConnectorOptions } from './connectors/plugnotas';
|
|
3
|
+
export * from './connectors/plugnotas';
|
|
4
|
+
export * from './lib/financial-provider';
|
|
5
|
+
export * from './types';
|
|
6
|
+
export interface CreatePlugNotasPluginOptions extends CreatePlugNotasConnectorOptions {
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Fiscal Brasil is an addon: Financial owns the fiscal document, while this
|
|
10
|
+
* package owns the provider connection and its asynchronous delivery trail.
|
|
11
|
+
*/
|
|
12
|
+
export declare function createPlugNotasPlugin(options?: CreatePlugNotasPluginOptions): PluginManifest;
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,cAAc,EAAE,MAAM,eAAe,CAAA;AACjE,OAAO,EAA4B,KAAK,+BAA+B,EAAE,MAAM,wBAAwB,CAAA;AAGvG,cAAc,wBAAwB,CAAA;AACtC,cAAc,0BAA0B,CAAA;AACxC,cAAc,SAAS,CAAA;AAEvB,MAAM,WAAW,4BAA6B,SAAQ,+BAA+B;CAAG;AAExF;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,GAAE,4BAAiC,GAAG,cAAc,CAiFhG"}
|