diff --git a/site/.env.template b/site/.env.template index 100c65a98..362828d0f 100644 --- a/site/.env.template +++ b/site/.env.template @@ -14,3 +14,6 @@ MATOMO_TOKEN= ATINTERNET_API_ACCESS_KEY= ATINTERNET_API_SECRET_KEY= ZAMMAD_API_SECRET_KEY= + +# Valeurs optionnelles +COMPANY_SEARCH_HOST=https://search-recherche-entreprises.fabrique.social.gouv.fr diff --git a/site/source/api/fabrique-social.ts b/site/source/api/fabrique-social.ts index 8041573be..cad568f7e 100644 --- a/site/source/api/fabrique-social.ts +++ b/site/source/api/fabrique-social.ts @@ -1,22 +1,13 @@ -const isSIREN = (input: string) => /^[\s]*([\d][\s]*){9}$/.exec(input) -const isSIRET = (input: string) => /^[\s]*([\d][\s]*){14}$/.exec(input) - export { fetchCompanyDetails } from './sirene' export async function searchDenominationOrSiren(value: string) { - if (isSIRET(value)) { - value = value.replace(/[\s]/g, '').slice(0, 9) - } - if (isSIREN(value)) { - return [{ siren: value }] - } return searchFullText(value) } /* * Fields are documented in https://www.sirene.fr/static-resources/doc/Description%20fichier%20StockUniteLegaleHistorique.pdf?version=1.33.1 */ -type FabriqueSocialEntreprise = { +export type FabriqueSocialEntreprise = { activitePrincipale: string caractereEmployeurUniteLegale?: 'N' | 'O' conventions: Array<{ @@ -49,17 +40,18 @@ type FabriqueSocialSearchPayload = { entreprises: Array } -const makeSearchUrl = (query: string) => - `https://search-recherche-entreprises.fabrique.social.gouv.fr/api/v1/search?query=${query}&open=false&convention=false&employer=false&ranked=false&limit=10` +const COMPANY_SEARCH_HOST = + process.env.COMPANY_SEARCH_HOST || + 'https://search-recherche-entreprises.fabrique.social.gouv.fr' -export type Entreprise = { - siren: string - address?: string - denomination?: string -} +const makeSearchUrl = (query: string, limit: number) => + `${COMPANY_SEARCH_HOST}/api/v1/search?query=${query}&open=false&convention=false&employer=false&ranked=false&limit=${limit}` -async function searchFullText(text: string): Promise | null> { - const response = await fetch(makeSearchUrl(text)) +async function searchFullText( + text: string, + limit = 10 +): Promise | null> { + const response = await fetch(makeSearchUrl(text, limit)) if (!response.ok) { return null diff --git a/site/webpack.common.js b/site/webpack.common.js index 256a47770..632b2976c 100644 --- a/site/webpack.common.js +++ b/site/webpack.common.js @@ -129,16 +129,14 @@ module.exports.default = { }, plugins: [ new EnvironmentPlugin({ + COMPANY_SEARCH_HOST: + 'https://search-recherche-entreprises.fabrique.social.gouv.fr', EN_BASE_URL: 'http://localhost:8080/infrance', FR_BASE_URL: 'http://localhost:8080/mon-entreprise', AT_INTERNET_SITE_ID: '', - }), - new EnvironmentPlugin({ ALGOLIA_APP_ID: '', ALGOLIA_SEARCH_KEY: '', ALGOLIA_INDEX_PREFIX: '', - }), - new EnvironmentPlugin({ GITHUB_REF: '', GITHUB_HEAD_REF: '', GITHUB_SHA: '',