@fayz-ai/plugin-fiscal-br 0.8.2 → 0.9.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.
@@ -27,6 +27,7 @@ export declare const MIGRATION_025_A_CONTA_DA_NOTA_FECHA_COM_O_TOTAL = "-- -----
27
27
  export declare const MIGRATION_026_O_RECEBIMENTO_PARADO_DIZ_POR_QUE = "-- ---------------------------------------------------------------------------\n-- When notes stop arriving, the emitter row says why.\n-- ---------------------------------------------------------------------------\n-- The SEFAZ pull fails per CNPJ (expired A1 certificate, provider refusal) and\n-- the V1 records only the last failure (integration_sync_state.last_error). The\n-- V2 kept nothing, so a tenant could go two weeks without a note and no screen\n-- would say so. These two columns hold that last failure; the notes list warns\n-- from them and from a stale dfe_last_sync_at.\n-- ---------------------------------------------------------------------------\n\nALTER TABLE public.plg_fiscalbr_emitter_settings\n ADD COLUMN IF NOT EXISTS dfe_last_error text,\n ADD COLUMN IF NOT EXISTS dfe_last_error_at timestamptz;\n\nCOMMENT ON COLUMN public.plg_fiscalbr_emitter_settings.dfe_last_error IS\n 'V1: integration_sync_state.last_error (source = dfe_inbox) \u2014 last failure pulling notes from SEFAZ; null when the last pull worked.';\nCOMMENT ON COLUMN public.plg_fiscalbr_emitter_settings.dfe_last_error_at IS\n 'V1: integration_sync_state.last_synced_at when last_status = error.';\n\nGRANT SELECT (dfe_last_error, dfe_last_error_at) ON public.plg_fiscalbr_emitter_settings TO authenticated;\n";
28
28
  export declare const MIGRATION_027_A_NOTA_COM_CONTA_E_SEM_ESTOQUE_TERMINA_NO_V2 = "-- ---------------------------------------------------------------------------\n-- A note that has its payable but never reached stock can be finished in V2.\n-- ---------------------------------------------------------------------------\n-- In the V1, saving the payment plan of a DANFE import opened the payable\n-- before anyone reconciled the lines; many imports stopped there. Copied over,\n-- those notes carry invoice_id and no stock, and both RPCs read invoice_id as\n-- \"accepted\": nothing could be reconciled and the goods never entered stock\n-- (Artorius 18, Espa\u00E7o Facial 72, Pertinho 17 on 14/10/2026).\n--\n-- \"Settled\" is now: stocked, or a payable with no stock line left to receive.\n-- Saving decisions is allowed until then, and accepting a note that already has\n-- its payable receives the stock against it instead of opening a second one.\n-- ---------------------------------------------------------------------------\n\nDO $m$\nDECLARE\n v_def text;\n v_old text;\n v_new text;\n v_start integer;\n v_end integer;\n v_pending constant text := $q$NOT EXISTS (SELECT 1 FROM public.plg_fiscalbr_inbox_items x\n WHERE x.tenant_id = v_tenant AND x.inbox_document_id = v_doc.id\n AND x.stock_movement_id IS NULL\n AND (x.entry_type IS NULL OR x.entry_type = '' OR x.entry_type IN ('insumo','revenda','patrimonio','uso_consumo')))$q$;\nBEGIN\n -- 1. Saving decisions.\n SELECT pg_get_functiondef(p.oid) INTO v_def FROM pg_proc p JOIN pg_namespace n ON n.oid = p.pronamespace\n WHERE n.nspname = 'public' AND p.proname = 'fiscalbr_save_inbox_decision';\n v_old := 'IF v_doc.stocked_at IS NOT NULL OR v_doc.invoice_id IS NOT NULL THEN';\n IF v_def IS NULL THEN RAISE EXCEPTION 'fiscalbr/027: fiscalbr_save_inbox_decision does not exist'; END IF;\n IF position(v_old in v_def) > 0 THEN\n v_def := replace(v_def, v_old, 'IF v_doc.stocked_at IS NOT NULL OR (v_doc.invoice_id IS NOT NULL AND ' || v_pending || ') THEN');\n -- v_tenant is that function's own variable name too.\n EXECUTE v_def;\n ELSIF position('x.stock_movement_id IS NULL' in v_def) = 0 THEN\n RAISE EXCEPTION 'fiscalbr/027: unexpected body of fiscalbr_save_inbox_decision \u2014 check by hand';\n END IF;\n\n -- 2. Accepting.\n SELECT pg_get_functiondef(p.oid) INTO v_def FROM pg_proc p JOIN pg_namespace n ON n.oid = p.pronamespace\n WHERE n.nspname = 'public' AND p.proname = 'fiscalbr_accept_inbox_document';\n IF v_def IS NULL THEN RAISE EXCEPTION 'fiscalbr/027: fiscalbr_accept_inbox_document does not exist'; END IF;\n IF position('Half-done in the V1' in v_def) > 0 THEN RETURN; END IF;\n\n IF position(v_old in v_def) = 0 THEN\n RAISE EXCEPTION 'fiscalbr/027: unexpected guard in fiscalbr_accept_inbox_document \u2014 check by hand';\n END IF;\n v_def := replace(v_def, v_old, 'IF v_doc.stocked_at IS NOT NULL OR (v_doc.invoice_id IS NOT NULL AND ' || v_pending || ') THEN');\n\n v_start := position(' SELECT coalesce(sum(value), 0),' in v_def);\n v_new := 'PERFORM public.plg_fiscalbr_note_charge_lines(v_tenant, v_doc.id, v_invoice, v_total);';\n v_end := position(v_new in v_def);\n IF v_start = 0 OR v_end = 0 OR v_end < v_start THEN\n RAISE EXCEPTION 'fiscalbr/027: unexpected payable block in fiscalbr_accept_inbox_document \u2014 check by hand';\n END IF;\n v_end := v_end + length(v_new);\n v_def := substr(v_def, 1, v_start - 1)\n || $q$ IF v_doc.invoice_id IS NOT NULL THEN\n -- Half-done in the V1: the payable exists; only the stock is missing.\n v_invoice := v_doc.invoice_id;\n SELECT total INTO v_total FROM public.plg_financial_invoices WHERE id = v_invoice;\n v_insts := '[]'::jsonb;\n ELSE\n$q$ || substr(v_def, v_start, v_end - v_start) || $q$\n END IF;$q$\n || substr(v_def, v_end);\n EXECUTE v_def;\nEND\n$m$;\n";
29
29
  export declare const MIGRATION_028_A_LINHA_DE_ESTOQUE_TEM_UNIDADE = "-- ---------------------------------------------------------------------------\n-- A stock line enters with its unit.\n-- ---------------------------------------------------------------------------\n-- Accepting let a stock line through with no stock unit; the movement then\n-- carried a bare quantity that every screen reads as \"unidade\" (Artorius, NF-e\n-- 222879: 20 kg of copa lombo entered as 20 units). The screen now suggests the\n-- unit and refuses without one; this is the same rule where it cannot be\n-- skipped.\n-- ---------------------------------------------------------------------------\n\nDO $m$\nDECLARE\n v_def text;\n v_old constant text := $q$ IF v_it.product_id IS NULL THEN$q$;\n v_new constant text := $q$ IF v_it.stock_unit_id IS NULL THEN\n RAISE EXCEPTION 'fiscalbr: item % entra no estoque sem unidade \u2014 escolha a unidade de estoque', v_it.item_number\n USING ERRCODE = '23514';\n END IF;\n IF v_it.product_id IS NULL THEN$q$;\nBEGIN\n SELECT pg_get_functiondef(p.oid) INTO v_def FROM pg_proc p JOIN pg_namespace n ON n.oid = p.pronamespace\n WHERE n.nspname = 'public' AND p.proname = 'fiscalbr_accept_inbox_document';\n IF v_def IS NULL THEN RAISE EXCEPTION 'fiscalbr/028: fiscalbr_accept_inbox_document does not exist'; END IF;\n IF position('entra no estoque sem unidade' in v_def) > 0 THEN RETURN; END IF;\n IF position(v_old in v_def) = 0 THEN\n RAISE EXCEPTION 'fiscalbr/028: unexpected body of fiscalbr_accept_inbox_document \u2014 check by hand';\n END IF;\n EXECUTE replace(v_def, v_old, v_new);\nEND\n$m$;\n";
30
+ export declare const MIGRATION_029_THE_SERVICE_WRITES_THE_INTAKE_HEALTH = "-- ============================================================================\n-- 029_the_service_writes_the_intake_health \u2014 the DF-e pull moves to the\n-- integration service (ADR 0003 phase 2).\n--\n-- The pull reads a tenant's emitter rows AS the caller (RLS decides which), and\n-- then records each CNPJ's outcome in three health columns, even for a reader\n-- without settings.manage, so the notes list can say \"intake stopped\". The\n-- edge function did that with service_role; the service gets exactly those\n-- three columns, by row id, and nothing else on the table.\n--\n-- Guarded: the role is an operator step. Replay-safe.\n-- ============================================================================\n\nDO $$\nBEGIN\n IF EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'fayz_integration')\n AND to_regclass('public.plg_fiscalbr_emitter_settings') IS NOT NULL THEN\n GRANT SELECT (id) ON public.plg_fiscalbr_emitter_settings TO fayz_integration;\n GRANT UPDATE (dfe_last_sync_at, dfe_last_error, dfe_last_error_at) ON public.plg_fiscalbr_emitter_settings TO fayz_integration;\n DROP POLICY IF EXISTS plg_fiscalbr_emitter_settings_service_health ON public.plg_fiscalbr_emitter_settings;\n CREATE POLICY plg_fiscalbr_emitter_settings_service_health ON public.plg_fiscalbr_emitter_settings\n FOR UPDATE TO fayz_integration USING (true) WITH CHECK (true);\n DROP POLICY IF EXISTS plg_fiscalbr_emitter_settings_service_read ON public.plg_fiscalbr_emitter_settings;\n CREATE POLICY plg_fiscalbr_emitter_settings_service_read ON public.plg_fiscalbr_emitter_settings\n FOR SELECT TO fayz_integration USING (true);\n END IF;\nEND $$;\n";
30
31
  export declare const MIGRATIONS: Array<{
31
32
  id: string;
32
33
  sql: string;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/migrations/index.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,sBAAsB,2g0BA2jBlC,CAAA;AAED,eAAO,MAAM,0DAA0D,uzRAmMtE,CAAA;AAED,eAAO,MAAM,+CAA+C,m5oBAyW3D,CAAA;AAED,eAAO,MAAM,0CAA0C,o1XAgPtD,CAAA;AAED,eAAO,MAAM,8CAA8C,6qCAsB1D,CAAA;AAED,eAAO,MAAM,2CAA2C,w8dA6MvD,CAAA;AAED,eAAO,MAAM,yCAAyC,42BAkBrD,CAAA;AAED,eAAO,MAAM,oDAAoD,4oDA+BhE,CAAA;AAED,eAAO,MAAM,yDAAyD,otbA0NrE,CAAA;AAED,eAAO,MAAM,gEAAgE,q1+BAoiB5E,CAAA;AAED,eAAO,MAAM,gEAAgE,mqVAgO5E,CAAA;AAED,eAAO,MAAM,8CAA8C,k/HAiF1D,CAAA;AAED,eAAO,MAAM,oDAAoD,w2OA4JhE,CAAA;AAED,eAAO,MAAM,oDAAoD,gvRAwJhE,CAAA;AAED,eAAO,MAAM,kDAAkD,shPAoK9D,CAAA;AAED,eAAO,MAAM,8CAA8C,8/EA0C1D,CAAA;AAED,eAAO,MAAM,yCAAyC,2mJA2ErD,CAAA;AAED,eAAO,MAAM,4CAA4C,68QA0IxD,CAAA;AAED,eAAO,MAAM,0CAA0C,83CAwBtD,CAAA;AAED,eAAO,MAAM,+CAA+C,81JAiG3D,CAAA;AAED,eAAO,MAAM,gDAAgD,y+IAgH5D,CAAA;AAED,eAAO,MAAM,4CAA4C,ylEA4CxD,CAAA;AAED,eAAO,MAAM,qCAAqC,kz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AAM,0CAA0C,83CAwBtD,CAAA;AAED,eAAO,MAAM,+CAA+C,81JAiG3D,CAAA;AAED,eAAO,MAAM,gDAAgD,y+IAgH5D,CAAA;AAED,eAAO,MAAM,4CAA4C,ylEA4CxD,CAAA;AAED,eAAO,MAAM,qCAAqC,kzBAajD,CAAA;AAED,eAAO,MAAM,uDAAuD,u6HAyEnE,CAAA;AAED,eAAO,MAAM,oDAAoD,6/KAoHhE,CAAA;AAED,eAAO,MAAM,+CAA+C,uqPAwJ3D,CAAA;AAED,eAAO,MAAM,8CAA8C,myCAoB1D,CAAA;AAED,eAAO,MAAM,0DAA0D,yyHAsEtE,CAAA;AAED,eAAO,MAAM,4CAA4C,+jDA8BxD,CAAA;AAED,eAAO,MAAM,kDAAkD,0pDA2B9D,CAAA;AAED,eAAO,MAAM,UAAU,EAAE,KAAK,CAAC;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CA+BzD,CAAA"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * The plugin's server-side code, for the integration service (ADR 0003 phase
3
+ * 2): the pure «Sugerir com IA» logic the note-suggestion route runs. Its own
4
+ * entry so the service never pulls React through this package.
5
+ */
6
+ export { MESSAGE_BUDGET, SUGGESTION_PROMPT, SUGGESTION_TOOL, buildSuggestionPayload, enforceFactorEvidence, isCountingUnit, packagingCount, parseNoteSuggestionReply, splitToFit, type NoteItemSuggestion, type SuggestionCandidate, } from '../lib/note-suggestion';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EACL,cAAc,EACd,iBAAiB,EACjB,eAAe,EACf,sBAAsB,EACtB,qBAAqB,EACrB,cAAc,EACd,cAAc,EACd,wBAAwB,EACxB,UAAU,EACV,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,GACzB,MAAM,wBAAwB,CAAA"}
@@ -0,0 +1,3 @@
1
+ export { MESSAGE_BUDGET, SUGGESTION_PROMPT, SUGGESTION_TOOL, buildSuggestionPayload, enforceFactorEvidence, isCountingUnit, packagingCount, parseNoteSuggestionReply, splitToFit } from '../chunk-5LI2FDOM.js';
2
+ //# sourceMappingURL=index.js.map
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fayz-ai/plugin-fiscal-br",
3
- "version": "0.8.2",
3
+ "version": "0.9.0",
4
4
  "description": "[preview] Brazilian fiscal addon for asynchronous NFC-e emission through PlugNotas",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -11,6 +11,10 @@
11
11
  ".": {
12
12
  "types": "./dist/index.d.ts",
13
13
  "import": "./dist/index.js"
14
+ },
15
+ "./server": {
16
+ "types": "./dist/server/index.d.ts",
17
+ "import": "./dist/server/index.js"
14
18
  }
15
19
  },
16
20
  "files": [
@@ -24,10 +28,10 @@
24
28
  },
25
29
  "dependencies": {
26
30
  "@tanstack/react-table": "^8.20.0",
27
- "@fayz-ai/admin": "^0.49.0",
28
- "@fayz-ai/core": "^0.49.0",
29
- "@fayz-ai/financial": "^0.1.1",
30
- "@fayz-ai/ui": "^0.49.0"
31
+ "@fayz-ai/admin": "^0.50.0",
32
+ "@fayz-ai/core": "^0.50.0",
33
+ "@fayz-ai/financial": "^0.1.2",
34
+ "@fayz-ai/ui": "^0.50.0"
31
35
  },
32
36
  "devDependencies": {
33
37
  "@types/node": "^20.0.0",