Skip to content

Feat/dgfip tva#125

Open
Samuelfaure wants to merge 5 commits into
developfrom
feat/dgfip_tva
Open

Feat/dgfip tva#125
Samuelfaure wants to merge 5 commits into
developfrom
feat/dgfip_tva

Conversation

@Samuelfaure
Copy link
Copy Markdown
Contributor

@Samuelfaure Samuelfaure commented May 13, 2026

Adds a new top-level 'DGFIP' provider (code 43) for error tracking.
Distinct from 'DGFIP - Adélie' (03) and 'DGFIP - SVAIR' (27) which
identify specific upstream channels; reserved for endpoints that proxy
DGFIP data published through other channels (e.g. data.gouv.fr datasets).
GET /v3/dgfip/numero_tva/:siren returns the French intra-community VAT
numbers associated with a SIREN, sourced from the DGFIP TVA dataset
published on data.gouv.fr.

Architecture is a thin proxy of tabular-api.data.gouv.fr — for each
request we issue a single 'vat_no__contains=<siren>&page_size=200' query
to the data.gouv tabular API and reshape the rows into the API Entreprise
collection response. There is no local mirror: server-side filtering on
the tabular API runs in ~200ms p99, and matches per SIREN are bounded
(an entreprise typically has 1–3 historical VAT numbers).

The endpoint is wired and tested but stays operationally offline until
the resource UUID and base URL credentials are populated:

  Siade.credentials[:dgfip_tva_base_url]  = https://tabular-api.data.gouv.fr
  Siade.credentials[:dgfip_tva_resource_id] = <DGFIP-provided UUID>

When the credentials are missing the endpoint returns 503 via
ProviderUnavailable. Target go-live: 2026-06-10 (DGFIP dataset publication).
@Samuelfaure Samuelfaure requested review from Un3x and skelz0r and removed request for Un3x and skelz0r May 13, 2026 10:51
Adds Resources::Dgfip#numero_tva(siren, version:) — open-data lookup of
the intra-community VAT numbers associated with a SIREN, proxied by
SIADE from tabular-api.data.gouv.fr.

Scaffolded automatically from the OpenAPI spec by
clients/ruby/bin/scaffold_resources. The gem hasn't shipped its initial
release yet, so the new method lands under the [Unreleased] section of
the changelog rather than as its own SemVer entry.
Drift catch-up: the source yamls already contained the corrected error
code (00100, was 0100) and meta.provider blocks, but the generated
README and summary.csv were never re-run. Picked up by running
bin/generate_payload_readme.rb during unrelated work on the numero_tva
mocks. No payload .yaml change.
Three 200 fixtures covering the realistic shape of the endpoint:

- 200-single.yaml   — SIREN with one VAT number (the common case)
- 200-multiple.yaml — SIREN with two historical VAT numbers, sorted by
                      date_emission ASC, exercising the collection ordering
- 200-empty.yaml    — SIREN absent from the DGFIP extraction; collection
                      is empty (not a 404)

No 4xx fixtures: 422 input validation is rejected upstream of the mock
backend; 503 from a misconfigured upstream resource_id is an operational
concern, not a data-shape concern, so it doesn't need a fixture here.

README.md and summary.csv regenerated via bin/generate_payload_readme.rb.
@Samuelfaure Samuelfaure requested review from Un3x and skelz0r May 13, 2026 11:00
@linear
Copy link
Copy Markdown

linear Bot commented May 13, 2026

API-6752

Copy link
Copy Markdown
Member

@skelz0r skelz0r left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Globalement la seule question importante est : on tape sur quoi ? quels sont les quotas ? Tout le MakeRequest/BuildRequest est conditionné par les réponses à ces questions. Si c'est genre 10 appels/minute c'est même pas la peine de faire ça et faut voir comme on gère.

La signature de l'API ne me semble pas correct non plus : y'a des infos useless pour nos usagers + il manque la date de la dernière mise à jour dans les meta. D'ailleurs cette date de dernière mise à jour pourrait être dans les erreurs 404. D'ailleurs, est-ce qu'on peut à travers le système que tu exploites, avoir ces infos ?

A la lumière des 2 grosses interrogations métier et technique j'ai review partiellement.

Comment thread commons/endpoints/_swagger_shared/dgfip.yml
Comment thread commons/endpoints/_swagger_shared/dgfip.yml
Comment on lines +281 to +290
date_emission:
title: "Date d'émission du numéro de TVA"
type: "string"
format: "date"
example: "1993-01-01"
date_derniere_modification:
title: "Date de dernière modification du numéro de TVA"
type: "string"
format: "date"
example: "2024-02-13"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

est-ce nécessaire ? @DorineLam thoughts ?

Comment thread mocks/payloads/api_entreprise_v3_dgfip_tva/200-empty.yaml
@@ -0,0 +1,28 @@
class APIEntreprise::V3AndMore::DGFIP::TVAController < APIEntreprise::V3AndMore::BaseController
include APIEntreprise::CommonDGFIPOrganizerParams
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pourquoi ?

Comment thread siade/app/interactors/dgfip/tva/validate_response.rb
@@ -0,0 +1,6 @@
class APIEntreprise::DGFIP::NumeroTVASerializer::V3 < APIEntreprise::V3AndMore::BaseSerializer
attributes :numero_tva_intracommunautaire,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

où est le meta de la dernière mise à jour des données ?

end

def request_uri
URI("#{base_url}/api/resources/#{resource_id}/data/")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on tape sur quoi ici ? ce n'est pas clair.

Comment thread siade/app/services/errors_backend.rb
@Samuelfaure
Copy link
Copy Markdown
Contributor Author

@skelz0r Concernant la limite j'ai pas posté mon analyse, je vais la mettre sur linear ptetre, extract:

  • No rate-limit headers exposed. 50 quick requests didn't trigger throttling. We will still add a sensible Retry-After-aware retry in the client, but not as a hard requirement.

@skelz0r
Copy link
Copy Markdown
Member

skelz0r commented May 13, 2026

@skelz0r Concernant la limite j'ai pas posté mon analyse, je vais la mettre sur linear ptetre, extract:

  • No rate-limit headers exposed. 50 quick requests didn't trigger throttling. We will still add a sensible Retry-After-aware retry in the client, but not as a hard requirement.

Du coup ?

@Samuelfaure
Copy link
Copy Markdown
Contributor Author

Du coup on est large à priori. Je pourrais faire un test pour voir quelle est la limite mais ça serait un peu malvenu de taper le FD comme un bourrin non? (et possiblement me faire bannir)

@skelz0r
Copy link
Copy Markdown
Member

skelz0r commented May 18, 2026

Du coup on est large à priori. Je pourrais faire un test pour voir quelle est la limite mais ça serait un peu malvenu de taper le FD comme un bourrin non? (et possiblement me faire bannir)

Je ne vois pas comment tu peux en déduire qu'on est large avec 50 requêtes 😅
Surtout t'as testé sur quoi ? Le fichier TVA fait 280Mo avec 5 millions de lignes, je doute aussi du caractère scale du call vat_no__contains (ça me semble peu optimisé), c'est quoi l'algo en dessous ? Pourquoi on n'utilise pas __eq (ça existe ?) (d'ailleurs le code est faux aussi 😅)
C'était chez qui ? T'as fait un compte ? Faut checker la doc (si existante), leur écrire sinon.

En bref, 99% de la complexité ici est dans ce travail --^ là j'ai aucun élément pour pouvoir valider ta PR car je n'ai aucune idée de si ça va tenir la charge.

@Samuelfaure
Copy link
Copy Markdown
Contributor Author

@skelz0r Okay j'ai fait un point avec Geoffrey qui a éclaircit certain trucs parce que effectivement j'ai un peu fait cette PR à l'aveugle (sorry j'étais crevé ces dernières temps 😅) - surtout que le fichier et la page ne sont pas encore up

L'API ne serait pas normalement tabularisée sur data.gouv car le fichier dépasse 280 mo mais on va faire une exception car on pense avec Geoffrey que c'est mieux de taper sur data.gouv

Concernant les limites il me confirme qu'on est très largement OK dans notre ordre de grandeur de volume

@skelz0r
Copy link
Copy Markdown
Member

skelz0r commented May 18, 2026

Ok intéressant, donc c'est sûr que ça passera par data.gouv ? Ça sera avec un compte (donc API key ?) ?

@Samuelfaure
Copy link
Copy Markdown
Contributor Author

Samuelfaure commented May 18, 2026

Pas de système de power-user authentifié sur data.gouv

Y'a des avantages clairs a passer par data.gouv, après y'a un seul problème c'est que les données seront J+1, mais je pense que pour la TVA c'est OK

Ça peut se discuter

@skelz0r
Copy link
Copy Markdown
Member

skelz0r commented May 18, 2026

après y'a un seul problème c'est que les données seront J+1

D'où le fait de renvoyer la dernière date de mise à jour (et c'était un pré-requis que le fichier soit transféré chaque jour de la veille).

Une idée du rate limiting ? Faudrait quand même qu'on sache, ça me semble assez étrange, ils vont faire du filtrage IP ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants