mix sefaz.endpoints (sefaz_nfe v0.5.0)

Copy Markdown View Source

Audits priv/endpoints/nfe_4.00.json (model 55), priv/endpoints/nfce_4.00.json (model 65), priv/endpoints/cte_4.00.json (models 57 and 67) and priv/endpoints/mdfe_3.00.json (model 58).

mix sefaz.endpoints
mix sefaz.endpoints --max-age 90
mix sefaz.endpoints --file priv/endpoints/nfce_4.00.json

AD-004 makes the endpoint table data owned by the RFB, not by this repository, refreshed from the official portal. The portal blocks automated fetching, so this task deliberately does not scrape it: a scraper that silently returns a login page would replace a stale table with a wrong one. It audits what is vendored and prints the manual procedure instead.

Reports a non-zero exit when the snapshot is older than --max-age days (default 180) or fails a structural check, so CI can fail on a stale table rather than a production call discovering it.

Contingency

uf_contingency (model 55 only) maps each UF to the SVC that serves it, SVCAN or SVCRS. Every UF needs an entry, and the authorizer it names has to exist and carry the six per-UF services.

The CT-e and MDF-e tables

Same shape and same URL rule (https, .gov.br), told apart by "family" ("cte" or "mdfe"). Every UF needs an authorizer carrying the family's services in both environments. The IBGE codes live in the model 55 table only.

cte_4.00.json carries uf_contingency as SVCSP or SVCRS for every UF (SVC-SP and SVC-RS; CT-e has no SVC-AN), and contingency_authorizer, which names the authorizer whose endpoints serve each SVC. Both have to point at authorizers that exist and carry the five CT-e services. MDF-e has no SVC.

The model 65 table

It has the same shape as the model 55 one, so the webservice URLs follow the same rule: https and a .gov.br host. Beyond that, every UF must have an authorizer (its own or SVRS) and, in both environments, a qr_code and a url_chave. The IBGE codes live in the model 55 table only.

The two address maps are held to a looser rule on purpose, because they are published that way and go into the XML as SEFAZ expects to read them back:

  • url_chave is not URL-checked at all. Some entries have no scheme (www.sefaz.ac.gov.br/nfce/consulta) and some are plain http; the only constraint is the XSD's own, 21 to 85 characters.
  • qr_code must be an http or https URL on a .gov.br host, or on a bare IPv4 literal (RR's homologation address is published as one). Several UFs still publish plain http QR addresses (AC, AL, BA, CE, DF among them), and the QR code is a link a consumer opens, not a channel this library sends a certificate over, so https is not demanded; the host rule still catches a hand-edit that points it at something that is not SEFAZ.

Refresh procedure

  1. Open https://www.nfe.fazenda.gov.br/portal/webServices.aspx and read the table for layout 4.00, model 55.
  2. Update priv/endpoints/nfe_4.00.json: authorizers holds one entry per authorizer with homologation and production URLs per service, uf_authorizer maps each UF to its authorizer, uf_code the IBGE code the envelopes carry as cUF. operations holds the SOAP operation per authorizer for nfe_consulta_cadastro, the one service whose authorizers disagree on it (default plus overrides).
  3. Set snapshot_date to the date you read the portal.
  4. Run mix sefaz.endpoints and mix test.

For model 65 read the NFC-e table and update priv/endpoints/nfce_4.00.json the same way, plus qr_code (the NfeConsultaQR address per UF) and url_chave (the consulta-por-chave address per UF), both keyed by environment and then UF.

For CT-e read https://www.cte.fazenda.gov.br/portal/webServices.aspx (production) and https://hom.cte.fazenda.gov.br/portal/webServices.aspx (homologation), which answer automated requests, and update priv/endpoints/cte_4.00.json; for MDF-e read https://dfe-portal.svrs.rs.gov.br/Mdfe/Servicos and update priv/endpoints/mdfe_3.00.json. The portals list ?wsdl on some addresses; the snapshot holds the bare service URL.

The nfephp wsnfe_4.00_mod55.xml, wsnfe_4.00_mod65.xml and uri_consulta_nfce.json mirrors are a useful cross-check, never the source of truth.

Summary

Functions

Every problem found in snapshot, as human-readable strings. Empty means it is usable.

Functions

audit(snapshot, max_age \\ 180)

@spec audit(map(), pos_integer()) :: [String.t()]

Every problem found in snapshot, as human-readable strings. Empty means it is usable.