Skip to content

Commit

Permalink
chore: remove redis from site (#1309)
Browse files Browse the repository at this point in the history
* chore: remove redis from site

* feat: remove config and clean packages

* feat: update package-lock

---------

Signed-off-by: Xavier Jp <xavier.jouppe@beta.gouv.fr>
  • Loading branch information
XavierJp authored Nov 6, 2024
1 parent 8d7caca commit a32a95c
Show file tree
Hide file tree
Showing 34 changed files with 55 additions and 562 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,9 @@ Nous utilisons [Commit-lint](https://commitlint.js.org/#/) avec [conventional-co

#### Prérequis

Le projet nécessite node > 18 et redis installé pour être lancé en local.
Le projet nécessite node > 18 installé pour être lancé en local.

- [Installer Node](https://nodejs.org/en/download/package-manager)
- [Installer Redis](https://redis.io/docs/getting-started/installation/)

```bash
# Installation
Expand Down
9 changes: 1 addition & 8 deletions clients/_test/clientAllEtablissementsInsee/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,7 @@ function expectClientToMatchSnapshotWithSiren(siren: string, page = 1) {
await expectClientToMatchSnapshot({
__dirname,
client: clientAllEtablissementsInsee,
args: [
siren,
page,
{
useFallback: false,
useCache: false,
},
],
args: [siren, page, false],
snaphotFile: `siren-${siren}${page !== 1 ? '-page-' + page : ''}.json`,
simplifyParams,
});
Expand Down
9 changes: 1 addition & 8 deletions clients/_test/clientUniteLegaleInsee/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,7 @@ function expectClientToMatchSnapshotWithSiren(siren: Siren) {
await expectClientToMatchSnapshot({
client: clientUniteLegaleInsee,
__dirname,
args: [
siren,
1,
{
useFallback: false,
useCache: false,
},
],
args: [siren, 1, false],
snaphotFile: `siren-${siren}.json`,
postProcessResult: (result) => {
result.dateDerniereMiseAJour = '2023-10-5';
Expand Down
4 changes: 0 additions & 4 deletions clients/api-entreprise/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ export default async function clientAPIEntreprise<T, U>(
throw new HttpUnauthorizedError('Missing API Entreprise credentials');
}

// never cache any API Entreprise request
const useCache = false;

const response = await httpGet<T>(route, {
headers: {
Authorization: `Bearer ${process.env.API_ENTREPRISE_TOKEN}`,
Expand All @@ -57,7 +54,6 @@ export default async function clientAPIEntreprise<T, U>(
context: options?.useCase ? options.useCase : 'annuaire-entreprises',
recipient: callerInfos.siret || '13002526500013',
},
useCache,
});

return mapToDomainObject(response);
Expand Down
5 changes: 2 additions & 3 deletions clients/api-proxy/association/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@ import { IAssociationResponse } from './types';
*/
const clientAssociation = async (
rnaOrSiren: IdRna | Siren,
siretSiege: string,
useCache = true
siretSiege: string
) => {
const response = await clientAPIProxy<IAssociationResponse>(
routes.proxy.association + rnaOrSiren,
{ timeout: constants.timeout.XL, useCache }
{ timeout: constants.timeout.XL }
);

if (response.identite && Object.keys(response.identite).length === 1) {
Expand Down
1 change: 0 additions & 1 deletion clients/api-proxy/eori/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { clientAPIProxy } from '../client';
const clientEORI = async (siret: Siret): Promise<IEORIValidation> => {
return await clientAPIProxy<IEORIValidation>(routes.proxy.eori + siret, {
timeout: constants.timeout.XXL,
useCache: true,
});
};

Expand Down
1 change: 0 additions & 1 deletion clients/api-proxy/greffe/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ type IIGResponse = {
const clientUniteLegaleIG = async (siren: Siren): Promise<IUniteLegale> => {
return mapToDomainObject(
await clientAPIProxy<IIGResponse>(routes.proxy.ig + siren, {
useCache: false,
timeout: constants.timeout.XL,
}),
siren
Expand Down
3 changes: 1 addition & 2 deletions clients/api-proxy/rne/documents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@ import { clientAPIProxy } from '../client';
* RNE through the API proxy
* @param siren
*/
const fetchDocumentsFromRNE = async (siren: Siren, useCache = true) => {
const fetchDocumentsFromRNE = async (siren: Siren) => {
const route = routes.proxy.rne.documents.list + siren;

const callerInfos = await sensitiveRequestCallerInfos();
sensitiveRequestLogger(route, callerInfos);

return await clientAPIProxy<IActesRNE>(route, {
timeout: constants.timeout.XXXXL,
useCache,
});
};

Expand Down
9 changes: 2 additions & 7 deletions clients/api-proxy/rne/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,11 @@ type IRNEProxyResponse = {
* RNE through the API proxy - API RNE
* @param siren
*/
const clientRNEImmatriculation = async (siren: Siren, useCache = true) => {
const clientRNEImmatriculation = async (siren: Siren) => {
const response = await clientAPIProxy<IRNEProxyResponse>(
routes.proxy.rne.immatriculation.default + siren,
{
timeout: constants.timeout.XS,
useCache,
}
);
return mapToDomainObject(response);
Expand All @@ -43,15 +42,11 @@ const clientRNEImmatriculation = async (siren: Siren, useCache = true) => {
* RNE through the API proxy - scrapping site as fallback
* @param siren
*/
const clientRNEImmatriculationFallback = async (
siren: Siren,
useCache = true
) => {
const clientRNEImmatriculationFallback = async (siren: Siren) => {
const response = await clientAPIProxy<IRNEProxyResponse>(
routes.proxy.rne.immatriculation.fallback + siren,
{
timeout: constants.timeout.XXXL,
useCache,
}
);
return mapToDomainObject(response);
Expand Down
6 changes: 1 addition & 5 deletions clients/api-proxy/tva/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,10 @@ export class TVAUserException extends Error {
* @param tva
* @returns TVA number if valid else null
*/
const clientTVA = async (
tva: TVANumber,
useCache = true
): Promise<string | null> => {
const clientTVA = async (tva: TVANumber): Promise<string | null> => {
const url = `${routes.proxy.tva}${tva}`;

const data = await clientAPIProxy<IVIESResponse>(url, {
useCache,
timeout: constants.timeout.XXL,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ function queryAnnuaireServicePublic(whereQuery: string) {
url: routes.annuaireServicePublic.ods.search,
config: {
params: { where: whereQuery },
useCache: true,
timeout: constants.timeout.XXXL,
},
},
Expand Down
14 changes: 4 additions & 10 deletions clients/ping-api-clients.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,36 +27,30 @@ const ping = async (slug: string | string[]) => {
const sirenDanone = verifySiren('552032534');
const sirenInclusion = verifySiren('419437629');

const useCache = false;

switch (slug) {
case 'api-proxy-ig':
return await clientUniteLegaleIG(sirenDanone);
case 'api-proxy-rne':
// fetch IRM and disable cache
return await clientRNEImmatriculation(sirenDanone, useCache);
return await clientRNEImmatriculation(sirenDanone);
case 'api-sirene-insee':
return await clientUniteLegaleInsee(sirenGanymede, 1, {
useCache,
useFallback: false,
});
return await clientUniteLegaleInsee(sirenGanymede, 1, false);
case 'api-sirene-donnees-ouvertes':
return await clientUniteLegaleRechercheEntreprise(sirenGanymede, 1);
case 'api-association':
return await clientAssociation(verifyIdRna('W551000280'), '', useCache);
return await clientAssociation(verifyIdRna('W551000280'), '');
case 'api-marche-inclusion':
return await clientMarcheInclusion(sirenInclusion);
case 'api-tva':
const tva = verifyTVANumber(tvaNumber(sirenDanone));
return await clientTVA(tva, useCache);
return await clientTVA(tva);
case 'api-eori':
return await clientEORI(siretGanymede);
case 'api-recherche':
return await clientSearchRechercheEntreprise({
searchTerms: 'test',
pageResultatsRecherche: 1,
searchFilterParams: undefined,
useCache,
inclureEtablissements: false,
});
default:
Expand Down
1 change: 0 additions & 1 deletion clients/recherche-entreprise/dirigeants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export const clientDirigeantsRechercheEntreprise = async (
inclureEtablissements: false,
inclureImmatriculation: false,
pageEtablissements: 1,
useCache: false,
});

if (!results.length || !results[0]) {
Expand Down
7 changes: 2 additions & 5 deletions clients/recherche-entreprise/idcc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@ import { Siren } from '#utils/helpers';
import { httpGet } from '#utils/network';

export const clientIdccRechercheEntreprise = async (
siren: Siren,
useCache = false
siren: Siren
): Promise<IConventionsCollectives> => {
const url = `${routes.rechercheEntreprise.idcc.siren}/${siren}`;
const data = await httpGet<IConventionsCollectives>(url, {
useCache,
});
const data = await httpGet<IConventionsCollectives>(url, {});

return data;
};
3 changes: 0 additions & 3 deletions clients/recherche-entreprise/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ type ClientSearchRechercheEntreprise = {
searchTerms: string;
pageResultatsRecherche: number;
searchFilterParams?: SearchFilterParams;
useCache?: boolean;
inclureEtablissements?: boolean;
inclureImmatriculation?: boolean;
pageEtablissements?: number;
Expand All @@ -46,7 +45,6 @@ type ClientSearchRechercheEntreprise = {
const clientSearchRechercheEntreprise = async ({
searchTerms,
searchFilterParams,
useCache = false,
inclureEtablissements = false,
inclureImmatriculation = false,
pageResultatsRecherche = 1,
Expand Down Expand Up @@ -90,7 +88,6 @@ const clientSearchRechercheEntreprise = async ({
const results = await httpGet<ISearchResponse>(url, {
timeout,
headers: { referer: 'annuaire-entreprises-site' },
useCache,
});

if (!results.results || results.results.length === 0) {
Expand Down
4 changes: 1 addition & 3 deletions clients/recherche-entreprise/siren.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@ import clientSearchRechercheEntreprise from '.';

export const clientUniteLegaleRechercheEntreprise = async (
siren: Siren,
pageEtablissements: number,
useCache = false
pageEtablissements: number
): Promise<IUniteLegale> => {
const { results } = await clientSearchRechercheEntreprise({
searchTerms: siren,
pageResultatsRecherche: 1,
inclureEtablissements: true,
inclureImmatriculation: true,
pageEtablissements,
useCache,
});

if (!results.length || !results[0]) {
Expand Down
4 changes: 1 addition & 3 deletions clients/recherche-entreprise/siret.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ import { IEtablissement } from '#models/core/types';
import clientSearchRechercheEntreprise from '.';

export const clientEtablissementRechercheEntreprise = async (
siret: string,
useCache = false
siret: string
): Promise<IEtablissement> => {
const { results } = await clientSearchRechercheEntreprise({
searchTerms: siret,
pageResultatsRecherche: 1,
inclureEtablissements: false,
inclureImmatriculation: false,
useCache,
});

if (
Expand Down
5 changes: 0 additions & 5 deletions clients/sirene-insee/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@ import constants from '#models/constants';
import { IDefaultRequestConfig } from '#utils/network';
import { httpClientOAuth } from '#utils/network/backend/0auth';

export type InseeClientOptions = {
useFallback: boolean;
useCache: boolean;
};

/**
* Insee client
*
Expand Down
18 changes: 7 additions & 11 deletions clients/sirene-insee/siren.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
libelleFromCategoriesJuridiques,
libelleFromCodeNAF,
} from '#utils/helpers/formatting/labels';
import { inseeClientGet, InseeClientOptions } from '.';
import { inseeClientGet } from '.';
import {
etatFromEtatAdministratifInsee,
parseDateCreationInsee,
Expand Down Expand Up @@ -84,23 +84,23 @@ type TmpUniteLegale = {
const clientUniteLegaleInsee = async (
siren: Siren,
page = 1,
options: InseeClientOptions
useFallback: boolean
): Promise<IUniteLegale> => {
const { uniteLegale, tmpUniteLegale } = await clientTmpUniteLegale(
siren,
options
useFallback
);

const siretSiege = uniteLegale.siege.siret;

const [realSiege, allEtablissements] = await Promise.all([
clientEtablissementInsee(siretSiege, options).catch((e) => {
clientEtablissementInsee(siretSiege, useFallback).catch((e) => {
if (e instanceof HttpForbiddenError) {
return createNonDiffusibleEtablissement(uniteLegale.siege.siret);
}
return null;
}), // better empty etablissement list than failing UL
clientAllEtablissementsInsee(siren, page, options).catch(() => null),
clientAllEtablissementsInsee(siren, page, useFallback).catch(() => null),
]);

const siege = realSiege || uniteLegale.siege;
Expand Down Expand Up @@ -132,14 +132,10 @@ const clientUniteLegaleInsee = async (
};
};

const clientTmpUniteLegale = async (
siren: Siren,
options: InseeClientOptions
) => {
const { useCache, useFallback } = options;
const clientTmpUniteLegale = async (siren: Siren, useFallback: boolean) => {
const dataUniteLegale = await inseeClientGet<IInseeUniteLegaleResponse>(
routes.sireneInsee.siren + siren,
{ useCache },
{},
useFallback
);

Expand Down
Loading

0 comments on commit a32a95c

Please sign in to comment.