diff --git a/.github/workflows/quality.yml b/.github/workflows/quality.yml index 5b3a27140..b77e09544 100644 --- a/.github/workflows/quality.yml +++ b/.github/workflows/quality.yml @@ -65,6 +65,37 @@ jobs: run: | yarn workspace ${{ matrix.repositories }} lint + Type-check: + name: Type-check + runs-on: ubuntu-latest + needs: [build] + strategy: + fail-fast: false + matrix: + repositories: + [ + "frontend", + "alert-cli", + "ingester", + "export-elasticsearch", + "@socialgouv/cdtn-types", + "@shared/utils", + ] + steps: + - uses: actions/cache@v2 + name: Restore build + with: + path: ./* + key: ${{ github.sha }} + - name: Set up Node + uses: actions/setup-node@v3 + with: + node-version: 20.3.1 + cache: "yarn" + - name: Type-check ${{ matrix.repositories }} + run: | + yarn workspace ${{ matrix.repositories }} type-check + test: name: Test runs-on: ubuntu-latest diff --git a/package-scripts.yml b/package-scripts.yml index faa406eed..84dd2c03d 100644 --- a/package-scripts.yml +++ b/package-scripts.yml @@ -17,6 +17,9 @@ scripts: test: default: lerna run --stream --parallel test + type-check: + default: lerna run --stream --parallel type-check + docker: up: default: docker-compose up --build postgres hasura diff --git a/package.json b/package.json index a8ec5b1fb..77b63498d 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "k8s": "yarn --silent --cwd .k8s", "prepare": "test -n \"$CI\" || husky install", "clean": "lerna clean", + "type-check": "nps type-check", "precommit": "lerna run --exclude-dependents --parallel 1 --since HEAD --stream" }, "workspaces": [ diff --git a/shared/types/export/global.ts b/shared/types/export/global.ts deleted file mode 100644 index ef197c567..000000000 --- a/shared/types/export/global.ts +++ /dev/null @@ -1,43 +0,0 @@ -export type DocumentElasticWithSource = DocumentElastic & T; - -export type DocumentRef = { - breadcrumbs: Breadcrumbs[]; - cdtnId: string; - description: string; - slug: string; - source: string; - title: string; - url: string | undefined; -}; - -export type Breadcrumbs = { - label: string; - position: number; - slug: string; -}; - -export type DocumentElastic = { - id: string; - cdtnId: string; - breadcrumbs: Breadcrumbs[]; - title: string; - slug: string; - source: string; - text: string; - isPublished: boolean; - excludeFromSearch: boolean; - metaDescription: string; - refs: DocumentRef[]; -}; - -export type RelatedDocument = { - id: string; - cdtnId: string; - breadcrumbs: Breadcrumbs[]; - title: string; - slug: string; - source: string; - description: string; - icon?: string; // Pour afficher l'icon du simulateur dans la tuile - action?: string; // Pour afficher le texte du bouton pour le simulateur dans la tuile -}; diff --git a/shared/types/export/prequalified.ts b/shared/types/export/prequalified.ts deleted file mode 100644 index 204d428ab..000000000 --- a/shared/types/export/prequalified.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { DocumentElasticWithSource } from "./global"; - -type Prequalified = { - source: "prequalified"; - variants: string[]; -}; - -export type PrequalifiedElasticDocument = Omit< - DocumentElasticWithSource, - "slug" ->; diff --git a/shared/types/global.ts b/shared/types/global.ts deleted file mode 100644 index 88872a0e0..000000000 --- a/shared/types/global.ts +++ /dev/null @@ -1,32 +0,0 @@ -export type BaseHasuraDocument = { - cdtn_id: string; - initial_id: string; - is_available: boolean; - is_searchable: boolean; - is_published: boolean; - meta_description: string; - slug: string; - title: string; - text: string; - created_at: Date; - updated_at: Date; -}; - -export type ExportSourcesContent = - | "conventions_collectives" - | "code_du_travail" - | "contributions" - | "information" - | "external" - | "glossary" - | "highlights" - | "droit_du_travail" - | "modeles_de_courriers" - | "prequalified" - | "fiches_ministere_travail" - | "page_fiche_ministere_travail" - | "fiches_service_public" - | "dossiers" - | "themes" - | "outils" - | "versions"; diff --git a/shared/types/index.ts b/shared/types/index.ts deleted file mode 100644 index c3283a8df..000000000 --- a/shared/types/index.ts +++ /dev/null @@ -1,495 +0,0 @@ -import type { - CodeArticle, - CodeArticleData, - CodeSection, -} from "@socialgouv/legi-data-types"; -import type { - AgreementArticle, - AgreementSection, - IndexedAgreement, -} from "@socialgouv/kali-data-types"; -import type { BaseHasuraDocument, ExportSourcesContent } from "./global"; -import type { - Prequalified, - Highlight, - EditorialContent, -} from "./EditorialContent"; -import { ContributionHighlight } from "./contributions"; - -export * from "./EditorialContent"; -export * from "./utils"; -export * from "./contributions"; -export * from "./documents"; -export * from "./export"; -export * from "./dila-resolver"; - -export enum DOCUMENT_SOURCE { - fiches_ministere_travail = "fiches_ministere_travail", - contributions = "contributions", - code_du_travail = "code_du_travail", - fiches_service_public = "fiches_service_public", - conventions_collectives = "conventions_collectives", - prequalified = "prequalified", - themes = "themes", - modeles_de_courriers = "modeles_de_courriers", - information = "information", - highlights = "highlights", -} - -export type FicheTravailEmploi = BaseHasuraDocument & { - source: "fiches_ministere_travail"; - document: FicheTravailEmploiDoc; -}; - -export type ContributionComplete = BaseHasuraDocument & { - source: "contributions"; - document: ContributionCompleteDoc; -}; - -export type ContributionFiltered = BaseHasuraDocument & { - source: "contributions"; - document: ContributionFilteredDoc; -}; - -export type LaborCodeArticle = BaseHasuraDocument & { - source: "code_du_travail"; - document: LaborCodeDoc; -}; - -export type FicheServicePublic = BaseHasuraDocument & { - source: "fiches_service_public"; - document: FicheServicePublicDoc; -}; - -export type Agreement = BaseHasuraDocument & { - source: "conventions_collectives"; - document: AgreementDoc; -}; - -export type Theme = BaseHasuraDocument & { - source: "themes"; - document: ThemeDoc; -}; - -export type MailTemplate = BaseHasuraDocument & { - source: "modeles_de_courriers"; - document: MailTemplateDoc; -}; - -export type HasuraDocument = - | Agreement - | ContributionComplete - | ContributionFiltered - | FicheServicePublic - | FicheTravailEmploi - | LaborCodeArticle - | MailTemplate - | Theme - | Prequalified - | Highlight - | EditorialContent; - -/** - * Document Table's document type - */ -export type ThemeDoc = { - icon?: string; - shortTitle?: string; - description?: string; -}; - -export type MailTemplateDoc = { - date: string; - html: string; - author: string; - filename: string; - filesize: number; - description: string; - references?: { - url: string; - title: string; - type: string; - }[]; -}; - -export interface FicheTravailEmploiDoc { - date: string; - description: string; - intro: string; - url: string; - sections: Section[]; -} - -export interface Section { - anchor: string; - html: string; - text: string; - title: string; - description: string; - references: TravailEmploiReference[]; -} - -export interface TravailEmploiReference { - id: string; - cid: string; - slug: string; - title: string; - type: "code_du_travail" | "conventions_collectives"; - url: string; -} - -export interface ContributionCompleteDoc { - index: number; - split: false; - description: string; - answers: CCMultipleAnswers; -} - -export interface ContributionFilteredDoc { - index: number; - split: true; - description: string; - answers: CCSingleAnswer; -} - -export interface CCMultipleAnswers { - generic: GenericAnswer; - conventions: Answer[]; -} - -export interface CCSingleAnswer { - generic: GenericAnswer; - conventionAnswer: Answer; -} - -export type LaborCodeDoc = Pick & { - description: string; - html: string; - url: string; - notaHtml?: string; -}; - -export interface FicheServicePublicDoc { - raw: string; - url: string; - date: string; - description: string; - referencedTexts: ServicePublicReference[]; -} - -export type ServicePublicReference = - | ServicePublicExternalReference - | ServicePublicInternalReference; - -export interface ServicePublicInternalReference { - title: string; - slug: string; - type: "code_du_travail" | "conventions_collectives"; -} - -export interface ServicePublicExternalReference { - title: string; - url: string; - type: "external"; -} - -export type AgreementDoc = Pick< - IndexedAgreement, - | "date_publi" - | "effectif" - | "mtime" - | "num" - | "shortTitle" - | "url" - | "synonymes" -> & { - highlight?: ContributionHighlight; -}; - -export type Question = { - id: string; - index: number; - title: string; - answers: { - generic: GenericAnswer; - conventions: Answer[]; - }; -}; - -export interface AgreementContribAnswer { - slug: string; - index: number; - answer: string; - question: string; - references: ContributionReference[]; -} - -export interface ArticleTheme { - bloc: "string"; - articles: { - id: string; - cid: string; - title: string; - section: string; - }; -} - -/** - * Alerts - */ - -export type HasuraAlert = { - id: string; - info: AlertInfo; - status: string; - repository: string; - ref: string; - changes: AlertChanges; - created_at: Date; - updated_at: Date; -}; - -export type AlertInfo = { id: string }; - -export type AlertChanges = - | DilaAlertChanges - | TravailDataAlertChanges - | VddAlertChanges - | DaresAlertChanges; - -/** Dila alert changes */ -export type DilaAlertChanges = DilaChanges & { - type: "dila"; - ref: string; - title: string; - date: Date; - id: string; - file: string; - num?: number; -}; - -export type DilaChanges = { - modified: DilaModifiedNode[]; - added: DilaAddedNode[]; - removed: DilaRemovedNode[]; - documents: DocumentReferences[]; -}; - -export type DilaAddedNode = { - etat: string; - parents: string[]; - title: string; - id: string; - cid: string; -}; - -export type DilaRemovedNode = { - parents: string[]; - title: string; - id: string; - cid: string; -}; - -export type DilaModifiedNode = { - parents: string[]; - title: string; - id: string; - cid: string; - etat: string; - diffs: DiffInfo[]; -}; - -export type DilaNode = - | AgreementArticle - | AgreementSection - | CodeArticle - | CodeSection; - -export type DilaArticle = AgreementArticle | CodeArticle; -export type DilaSection = AgreementSection | CodeSection; - -export type DiffInfo = { - type: "etat" | "nota" | "texte"; - currentText: string; - previousText: string; -}; - -export type DocumentReferences = { - document: DocumentInfo; - references: DocumentReference[]; -}; - -export type DocumentReference = Pick< - DilaRef, - "dila_cid" | "dila_container_id" | "dila_id" | "title" | "url" ->; - -export type DocumentInfo = Pick & { - id: string; -}; -export type DocumentInfoWithCdtnRef = DocumentInfo & { - ref: Pick; - url?: string; -}; - -/** Fiche travail alert changes */ -export type TravailDataAlertChanges = TravailDataChanges & { - type: "travail-data"; - title: string; - ref: string; - date: Date; -}; - -export type TravailDataChanges = { - added: FicheTravailEmploiInfo[]; - removed: FicheTravailEmploiInfo[]; - modified: FicheTravailEmploiInfoWithDiff[]; - documents: DocumentInfoWithCdtnRef[]; -}; - -export type FicheTravailEmploiInfo = { - pubId: string; - title: string; - url: string; -}; - -export type FicheTravailEmploiInfoWithDiff = FicheTravailEmploiInfo & { - removedSections: SectionTextChange[]; - addedSections: SectionTextChange[]; - modifiedSections: SectionTextChange[]; -}; - -export type SectionTextChange = { - title: string; - currentText: string; - previousText: string; -}; - -/** fiche vdd alert changes*/ -export type VddAlertChanges = VddChanges & { - type: "vdd"; - title: string; - ref: string; - date: Date; -}; - -export type DaresAlertChanges = { - type: "dares"; - title: string; - ref: string; - date: Date; - modified: []; - added: { - name: string; - num: number; - }[]; - removed: { - name: string; - num: number; - }[]; - documents: []; -}; - -export type DaresAlert = { - id: string; - info: { - id: string | number; // idcc number - }; - status: "doing" | "done" | "rejected" | "todo"; - repository: "dares"; - ref: string; - changes: DaresAlertChanges; -}; - -export type VddChanges = { - modified: FicheVddInfoWithDiff[]; - removed: FicheVddInfo[]; - added: FicheVddInfo[]; - documents: DocumentInfoWithCdtnRef[]; -}; - -export type FicheVddInfo = { - id: string; - type: string; - title: string; -}; - -export type FicheVddInfoWithDiff = FicheVddInfo & { - currentText: string; - previousText: string; -}; - -export enum Status { - running = "running", - completed = "completed", - failed = "failed", - timeout = "timeout", -} - -export enum Environment { - production = "production", - preproduction = "preproduction", -} - -export interface User { - id: string; - name: string; - email: string; -} - -export interface ExportEsStatus { - id: string; - environment: Environment; - status: Status; - user_id: string; - created_at: Date; - updated_at: Date; - user?: User; - error?: string; - documentsCount?: Record< - Exclude | "total", - number - >; -} - -export type Answer = { - id: string; - idcc: string; - markdown: string; - references: ContributionReference[]; -}; - -export type GenericAnswer = { - id: string; - markdown: string; - description: string; - text: string; - references: ContributionReference[]; -}; - -export type ContributionReference = BaseRef | DilaRef; - -export type DilaRef = { - category: "agreement" | "labor_code"; - url: string; - title: string; - dila_id: string; - dila_cid: string; - dila_container_id: string; -}; - -export type BaseRef = { - category: null; - title: string; - url: string | null; -}; - -export type State = - | "ABROGE" - | "DENONCE" - | "MODIFIE" - | "PERIME" - | "REMPLACE" - | "VIGUEUR" - | "VIGUEUR_ETEN" - | "VIGUEUR_NON_ETEN"; diff --git a/shared/types/package.json b/shared/types/package.json index 1cb8a6caf..d6b2d0191 100644 --- a/shared/types/package.json +++ b/shared/types/package.json @@ -1,13 +1,21 @@ { - "name": "@shared/types", + "name": "@socialgouv/cdtn-types", + "publishConfig": { + "access": "public", + "registry": "https://registry.npmjs.org/" + }, "version": "2.41.6", "private": true, "main": "build/index.js", "module": "build/index.js", "types": "build/index.d.ts", + "files": [ + "build" + ], "scripts": { "build": "tsc", - "build:watch": "tsc -w" + "build:watch": "tsc -w", + "type-check": "tsc --noEmit" }, "devDependencies": { "@socialgouv/kali-data-types": "^2.127.0", diff --git a/shared/types/export/agreements.ts b/shared/types/src/elastic/agreements.ts similarity index 61% rename from shared/types/export/agreements.ts rename to shared/types/src/elastic/agreements.ts index cae814926..0cc283e47 100644 --- a/shared/types/export/agreements.ts +++ b/shared/types/src/elastic/agreements.ts @@ -1,26 +1,16 @@ -import { - AgreementDoc, - ContributionElasticDocument, - OldContributionElasticDocument, -} from "../index"; -import { DocumentElasticWithSource } from "./global"; +import { AgreementDoc } from "../hasura"; +import { DocumentElasticWithSource } from "./common"; +import { ContributionElasticDocument } from "./contributions"; -export type AgreementGenerated = DocumentElasticWithSource & { +export type ElasticAgreement = DocumentElasticWithSource & { articlesByTheme: ArticleByTheme[]; source: "conventions_collectives"; description: string; - answers: (OldExportAnswer | ExportAnswer)[]; + answers: ExportAnswer[]; contributions: boolean; }; // Type pour les réponses -export type OldExportAnswer = OldContributionElasticDocument & { - theme?: string; - answer: string; - question: string; - references: any[]; -}; - export type ExportAnswer = ContributionElasticDocument & { theme?: string; infoMessage: string; diff --git a/shared/types/src/elastic/common.ts b/shared/types/src/elastic/common.ts new file mode 100644 index 000000000..46e4229f3 --- /dev/null +++ b/shared/types/src/elastic/common.ts @@ -0,0 +1,44 @@ +import { SourceRoute } from "@socialgouv/cdtn-sources"; + +export type DocumentElasticWithSource< + T, + U extends SourceRoute = SourceRoute +> = DocumentElastic & T; + +export type Breadcrumb = { + label: string; + position: number; + slug: string; +}; + +export type DocumentElastic = { + id: string; + cdtnId: string; + breadcrumbs: Breadcrumb[]; + title: string; + slug: string; + source: T; + text: string; + isPublished: boolean; + excludeFromSearch: boolean; + metaDescription: string; + refs: DocumentRef[]; +}; + +export type RelatedDocument = { + id: string; + cdtnId: string; + breadcrumbs: Breadcrumb[]; + title: string; + slug: string; + source: T; + description: string; + icon?: string; // Pour afficher l'icon du simulateur dans la tuile + action?: string; // Pour afficher le texte du bouton pour le simulateur dans la tuile + url?: string; // Pour les outils externes +}; + +export type DocumentRef = Omit< + RelatedDocument, + "action" | "url" | "id" +>; diff --git a/shared/types/export/contributions.ts b/shared/types/src/elastic/contributions.ts similarity index 51% rename from shared/types/export/contributions.ts rename to shared/types/src/elastic/contributions.ts index 868fb9ff6..64f75cd2e 100644 --- a/shared/types/export/contributions.ts +++ b/shared/types/src/elastic/contributions.ts @@ -1,8 +1,5 @@ -import { - ContributionDocumentJson, - ContributionHighlight, -} from "../contributions"; -import { Breadcrumbs, DocumentElasticWithSource } from "./global"; +import { ContributionDocumentJson, ContributionHighlight } from "../hasura"; +import { Breadcrumb, DocumentElasticWithSource } from "./common"; export interface ContributionConventionnelInfos { ccnSlug: string; @@ -39,7 +36,7 @@ export type ContributionContent = | ContributionGenericNoCDTContent; export interface ExportFullLinkedContent { - breadcrumbs: Breadcrumbs[]; + breadcrumbs: Breadcrumb[]; description: string; source: string; slug: string; @@ -51,63 +48,34 @@ export interface ExportContributionFullLinkedContent { } type ExportContributionInfo = { - breadcrumbs: Breadcrumbs[]; + breadcrumbs: Breadcrumb[]; highlight?: ContributionHighlight; messageBlock?: string; }; -export type ContributionElasticDocument = Omit< +type ContributionElasticDocumentBase = Omit< DocumentElasticWithSource>, "breadcrumbs" > & ContributionMetadata & ContributionContent & ExportContributionFullLinkedContent & - ExportContributionInfo & + ExportContributionInfo; + +export type ContributionElasticDocument = ContributionElasticDocumentBase & (ContributionGenericInfos | ContributionConventionnelInfos); -export interface OldContributionReference { - url: string; - title: string; - category: string; - dila_id?: string; - dila_cid: string; - dila_container_id: string; -} +export type ElasticSearchContributionGeneric = ContributionElasticDocumentBase & + ContributionGenericInfos; -export interface OldContributionElasticDocument { - index: number; - split: boolean; - description: string; - cdtnId: string; - excludeFromSearch: boolean; - id: string; - isPublished: boolean; - metaDescription: string; - refs: OldContributionReference[]; - slug: string; - source: string; - text: string; - title: string; - answers: { - generic: { - id: string; - text: string; - markdown: string; - references: OldContributionReference[]; - description: string; - }; - conventionAnswer?: { - id: string; - idcc: string; - markdown: string; - shortName: string; - references: OldContributionReference[]; - }; +export type ElasticSearchContributionConventionnelle = + ContributionElasticDocumentBase & ContributionConventionnelInfos; + +export type ElasticSearchContribution = + | ElasticSearchContributionGeneric + | ElasticSearchContributionConventionnelle; + +export type ElasticSearchContributionWithInfoMessage = + ElasticSearchContribution & { + infoMessage: string; }; - breadcrumbs: { - label: string; - position: number; - slug: string; - }[]; -} diff --git a/shared/types/src/elastic/editorial-content.ts b/shared/types/src/elastic/editorial-content.ts new file mode 100644 index 000000000..54012503a --- /dev/null +++ b/shared/types/src/elastic/editorial-content.ts @@ -0,0 +1,7 @@ +import { EditorialContentDoc } from "../hasura"; +import { KeysToCamelCase } from "../utility"; +import { DocumentElasticWithSource } from "./common"; + +export type EditorialContentElasticDocument = DocumentElasticWithSource< + KeysToCamelCase +>; diff --git a/shared/types/export/index.ts b/shared/types/src/elastic/index.ts similarity index 51% rename from shared/types/export/index.ts rename to shared/types/src/elastic/index.ts index 22c4262e2..0c1224218 100644 --- a/shared/types/export/index.ts +++ b/shared/types/src/elastic/index.ts @@ -1,4 +1,6 @@ export * from "./agreements"; export * from "./contributions"; -export * from "./global"; +export * from "./common"; export * from "./prequalified"; +export * from "./tools"; +export * from "./editorial-content"; diff --git a/shared/types/src/elastic/prequalified.ts b/shared/types/src/elastic/prequalified.ts new file mode 100644 index 000000000..7aa7fe411 --- /dev/null +++ b/shared/types/src/elastic/prequalified.ts @@ -0,0 +1,9 @@ +import { PrequalifiedDoc } from "../hasura"; +import { DocumentElasticWithSource, RelatedDocument } from "./common"; + +export type PrequalifiedElasticDocument = Omit< + DocumentElasticWithSource, + "slug" | "refs" +> & { + refs: RelatedDocument[]; +}; diff --git a/shared/types/src/elastic/tools.ts b/shared/types/src/elastic/tools.ts new file mode 100644 index 000000000..bda29d276 --- /dev/null +++ b/shared/types/src/elastic/tools.ts @@ -0,0 +1,23 @@ +export type Tool = { + date: string; + icon: string; + order: number; + action: string; + metaTitle: string; + questions?: string[]; + description: string; + displayTitle: string; + breadcrumbs: Record[]; + cdtnId: string; + excludeFromSearch: boolean; + id: string; + isPublished: boolean; + metaDescription: string; + slug: string; + source: string; + text: string; + title: string; + title_vector: number[]; + _id: string; + displayTool?: boolean; +}; diff --git a/shared/types/src/hasura/agreement.ts b/shared/types/src/hasura/agreement.ts new file mode 100644 index 000000000..9fcde9543 --- /dev/null +++ b/shared/types/src/hasura/agreement.ts @@ -0,0 +1,18 @@ +import { IndexedAgreement } from "@socialgouv/kali-data-types"; +import { HasuraDocument } from "./common"; +import { ContributionHighlight } from "./contributions"; + +export type Agreement = HasuraDocument; + +export type AgreementDoc = Pick< + IndexedAgreement, + | "date_publi" + | "effectif" + | "mtime" + | "num" + | "shortTitle" + | "url" + | "synonymes" +> & { + highlight?: ContributionHighlight; +}; diff --git a/shared/types/src/hasura/alert.ts b/shared/types/src/hasura/alert.ts new file mode 100644 index 000000000..7bc12193b --- /dev/null +++ b/shared/types/src/hasura/alert.ts @@ -0,0 +1,215 @@ +import type { CodeArticle, CodeSection } from "@socialgouv/legi-data-types"; +import type { + AgreementArticle, + AgreementSection, +} from "@socialgouv/kali-data-types"; +import { HasuraDocument } from "./common"; + +export type HasuraAlert = { + id: string; + info: AlertInfo; + status: string; + repository: string; + ref: string; + changes: AlertChanges; + created_at: Date; + updated_at: Date; +}; + +export type AlertInfo = { id: string }; + +export type AlertChanges = + | DilaAlertChanges + | TravailDataAlertChanges + | VddAlertChanges + | DaresAlertChanges; + +/** Dila alert changes */ +export type DilaAlertChanges = DilaChanges & { + type: "dila"; + ref: string; + title: string; + date: Date; + id: string; + file: string; + num?: number; +}; + +export type DilaChanges = { + modified: DilaModifiedNode[]; + added: DilaAddedNode[]; + removed: DilaRemovedNode[]; + documents: DocumentReferences[]; +}; + +export type DilaAddedNode = { + etat: string; + parents: string[]; + title: string; + id: string; + cid: string; +}; + +export type DilaRemovedNode = { + parents: string[]; + title: string; + id: string; + cid: string; +}; + +export type DilaModifiedNode = { + parents: string[]; + title: string; + id: string; + cid: string; + etat: string; + diffs: DiffInfo[]; +}; + +export type DilaNode = + | AgreementArticle + | AgreementSection + | CodeArticle + | CodeSection; + +export type DilaArticle = AgreementArticle | CodeArticle; +export type DilaSection = AgreementSection | CodeSection; + +export type DiffInfo = { + type: "etat" | "nota" | "texte"; + currentText: string; + previousText: string; +}; + +export type DocumentReferences = { + document: DocumentInfo; + references: DocumentReference[]; +}; + +export type DocumentReference = Pick< + DilaRef, + "dila_cid" | "dila_container_id" | "dila_id" | "title" | "url" +>; + +export type DocumentInfo = Pick, "source" | "title"> & { + id: string; +}; + +export type DocumentInfoWithCdtnRef = DocumentInfo & { + ref: Pick; + url?: string; +}; + +/** Fiche travail alert changes */ +export type TravailDataAlertChanges = TravailDataChanges & { + type: "travail-data"; + title: string; + ref: string; + date: Date; +}; + +export type TravailDataChanges = { + added: FicheTravailEmploiInfo[]; + removed: FicheTravailEmploiInfo[]; + modified: FicheTravailEmploiInfoWithDiff[]; + documents: DocumentInfoWithCdtnRef[]; +}; + +export type FicheTravailEmploiInfo = { + pubId: string; + title: string; + url: string; +}; + +export type FicheTravailEmploiInfoWithDiff = FicheTravailEmploiInfo & { + removedSections: SectionTextChange[]; + addedSections: SectionTextChange[]; + modifiedSections: SectionTextChange[]; +}; + +export type SectionTextChange = { + title: string; + currentText: string; + previousText: string; +}; + +/** fiche vdd alert changes*/ +export type VddAlertChanges = VddChanges & { + type: "vdd"; + title: string; + ref: string; + date: Date; +}; + +export type DaresAlertChanges = { + type: "dares"; + title: string; + ref: string; + date: Date; + modified: []; + added: { + name: string; + num: number; + }[]; + removed: { + name: string; + num: number; + }[]; + documents: []; +}; + +export type DaresAlert = { + id: string; + info: { + id: string | number; // idcc number + }; + status: "doing" | "done" | "rejected" | "todo"; + repository: "dares"; + ref: string; + changes: DaresAlertChanges; +}; + +export type VddChanges = { + modified: FicheVddInfoWithDiff[]; + removed: FicheVddInfo[]; + added: FicheVddInfo[]; + documents: DocumentInfoWithCdtnRef[]; +}; + +export type FicheVddInfo = { + id: string; + type: string; + title: string; +}; + +export type FicheVddInfoWithDiff = FicheVddInfo & { + currentText: string; + previousText: string; +}; + +export type ContributionReference = BaseRef | DilaRef; + +export type DilaRef = { + category: "agreement" | "labor_code"; + url: string; + title: string; + dila_id: string; + dila_cid: string; + dila_container_id: string; +}; + +export type BaseRef = { + category: null; + title: string; + url: string | null; +}; + +export type State = + | "ABROGE" + | "DENONCE" + | "MODIFIE" + | "PERIME" + | "REMPLACE" + | "VIGUEUR" + | "VIGUEUR_ETEN" + | "VIGUEUR_NON_ETEN"; diff --git a/shared/types/src/hasura/code-du-travail.ts b/shared/types/src/hasura/code-du-travail.ts new file mode 100644 index 000000000..7105c6252 --- /dev/null +++ b/shared/types/src/hasura/code-du-travail.ts @@ -0,0 +1,11 @@ +import { CodeArticleData } from "@socialgouv/legi-data-types"; +import { HasuraDocument } from "./common"; + +export type LaborCodeArticle = HasuraDocument; + +export type LaborCodeDoc = Pick & { + description: string; + html: string; + url: string; + notaHtml?: string; +}; diff --git a/shared/types/documents.ts b/shared/types/src/hasura/common.ts similarity index 70% rename from shared/types/documents.ts rename to shared/types/src/hasura/common.ts index e86f66db2..fe3b1f08b 100644 --- a/shared/types/documents.ts +++ b/shared/types/src/hasura/common.ts @@ -1,9 +1,9 @@ import { SourceRoute } from "@socialgouv/cdtn-sources"; -export type Document = { +export type HasuraDocument = { cdtn_id: string; initial_id: string; - source: SourceRoute; + source: U; document: T; slug: string; text: string; @@ -14,7 +14,7 @@ export type Document = { is_published: boolean; }; -export type ShortDocument = Pick< - Document, +export type ShortHasuraDocument = Pick< + HasuraDocument, "source" | "slug" | "title" | "initial_id" | "cdtn_id" > & { isPublished: boolean }; diff --git a/shared/types/contributions.ts b/shared/types/src/hasura/contributions.ts similarity index 95% rename from shared/types/contributions.ts rename to shared/types/src/hasura/contributions.ts index 312ee4fbb..f4e04d202 100644 --- a/shared/types/contributions.ts +++ b/shared/types/src/hasura/contributions.ts @@ -1,5 +1,5 @@ -import { FicheServicePublicDoc } from "./index"; -import { Document } from "./documents"; +import { HasuraDocument } from "./common"; +import { FicheServicePublicDoc } from "./fiche-sp"; export type ContributionsAnswers = { id: string; @@ -49,7 +49,7 @@ export type ContributionCdtnReferences = { cdtn_id: string; answer: ContributionsAnswers; answer_id: string; - document: Partial>; + document: Partial>; }; export type ContributionContentFicheSp = { diff --git a/shared/types/dila-resolver.ts b/shared/types/src/hasura/dila-resolver.ts similarity index 100% rename from shared/types/dila-resolver.ts rename to shared/types/src/hasura/dila-resolver.ts diff --git a/shared/types/EditorialContent.ts b/shared/types/src/hasura/editorial-content.ts similarity index 60% rename from shared/types/EditorialContent.ts rename to shared/types/src/hasura/editorial-content.ts index cc7bb432c..aee4938eb 100644 --- a/shared/types/EditorialContent.ts +++ b/shared/types/src/hasura/editorial-content.ts @@ -1,17 +1,17 @@ -import { BaseHasuraDocument } from "./global"; +import { HasuraDocument } from "./common"; -export enum CONTENT_TYPE { +export enum EditorialContentType { markdown = "markdown", graphic = "graphic", content = "content", } -export declare enum BlockDisplayMode { +export enum EditorialContentBlockDisplayMode { line = "line", square = "square", } -export type BaseContentPart = { +export type EditorialContentBaseContentPart = { name: string; title: string; references?: EditoralContentReferenceBloc[]; @@ -19,7 +19,7 @@ export type BaseContentPart = { }; export type MarkdownContentPart = { - type: CONTENT_TYPE.markdown; + type: EditorialContentType.markdown; markdown: string; }; @@ -31,9 +31,9 @@ export type ContentItem = { export type ContentContentPart = { title?: string; - type: CONTENT_TYPE.content; + type: EditorialContentType.content; contents: ContentItem[]; - blockDisplayMode: BlockDisplayMode; + blockDisplayMode: EditorialContentBlockDisplayMode; }; export type EditorialContentPart = @@ -54,7 +54,7 @@ export type EditoralContentReferenceBloc = { }; export type GraphicContentPart = { - type: CONTENT_TYPE.graphic; + type: EditorialContentType.graphic; size: string; imgUrl: string; altText: string; @@ -62,7 +62,7 @@ export type GraphicContentPart = { markdown: string; }; -export enum SectionDisplayMode { +export enum EditorialSectionDisplayMode { accordion = "accordion", tab = "tab", } @@ -70,27 +70,14 @@ export enum SectionDisplayMode { export type EditorialContentDoc = { date: string; intro: string; - section_display_mode?: SectionDisplayMode; + section_display_mode?: EditorialSectionDisplayMode; dismissalProcess?: boolean; - contents: BaseContentPart[]; + contents: EditorialContentBaseContentPart[]; references?: EditoralContentReferenceBloc[]; description: string; }; -export type PrequalifiedDoc = { - variants: string[]; -}; - -export type Prequalified = BaseHasuraDocument & { - source: "prequalified"; - document: PrequalifiedDoc; -}; - -export type Highlight = BaseHasuraDocument & { - source: "highlights"; -}; - -export type EditorialContent = BaseHasuraDocument & { - source: "information"; - document: EditorialContentDoc; -}; +export type EditorialContent = HasuraDocument< + EditorialContentDoc, + "information" +>; diff --git a/shared/types/src/hasura/export-es.ts b/shared/types/src/hasura/export-es.ts new file mode 100644 index 000000000..0d2f0b3f4 --- /dev/null +++ b/shared/types/src/hasura/export-es.ts @@ -0,0 +1,51 @@ +export enum Status { + running = "running", + completed = "completed", + failed = "failed", + timeout = "timeout", +} + +export enum Environment { + production = "production", + preproduction = "preproduction", +} + +interface User { + id: string; + name: string; + email: string; +} + +type ExportSourcesContent = + | "conventions_collectives" + | "code_du_travail" + | "contributions" + | "information" + | "external" + | "glossary" + | "highlights" + | "droit_du_travail" + | "modeles_de_courriers" + | "prequalified" + | "fiches_ministere_travail" + | "page_fiche_ministere_travail" + | "fiches_service_public" + | "dossiers" + | "themes" + | "outils" + | "versions"; + +export interface ExportEsStatus { + id: string; + environment: Environment; + status: Status; + user_id: string; + created_at: Date; + updated_at: Date; + user?: User; + error?: string; + documentsCount?: Record< + Exclude | "total", + number + >; +} diff --git a/shared/types/src/hasura/fiche-sp.ts b/shared/types/src/hasura/fiche-sp.ts new file mode 100644 index 000000000..fcb01561f --- /dev/null +++ b/shared/types/src/hasura/fiche-sp.ts @@ -0,0 +1,30 @@ +import { HasuraDocument } from "./common"; + +export type FicheServicePublic = HasuraDocument< + FicheServicePublicDoc, + "fiches_service_public" +>; + +export interface FicheServicePublicDoc { + raw: string; + url: string; + date: string; + description: string; + referencedTexts: ServicePublicReference[]; +} + +export type ServicePublicReference = + | ServicePublicExternalReference + | ServicePublicInternalReference; + +export interface ServicePublicInternalReference { + title: string; + slug: string; + type: "code_du_travail" | "conventions_collectives"; +} + +export interface ServicePublicExternalReference { + title: string; + url: string; + type: "external"; +} diff --git a/shared/types/src/hasura/fiche-travail.ts b/shared/types/src/hasura/fiche-travail.ts new file mode 100644 index 000000000..e43fbebcb --- /dev/null +++ b/shared/types/src/hasura/fiche-travail.ts @@ -0,0 +1,32 @@ +import { HasuraDocument } from "./common"; + +export type FicheTravailEmploi = HasuraDocument< + FicheTravailEmploiDoc, + "fiches_ministere_travail" +>; + +export interface FicheTravailEmploiDoc { + date: string; + description: string; + intro: string; + url: string; + sections: Section[]; +} + +export interface Section { + anchor: string; + html: string; + text: string; + title: string; + description: string; + references: TravailEmploiReference[]; +} + +export interface TravailEmploiReference { + id: string; + cid: string; + slug: string; + title: string; + type: "code_du_travail" | "conventions_collectives"; + url: string; +} diff --git a/shared/types/src/hasura/highlights.ts b/shared/types/src/hasura/highlights.ts new file mode 100644 index 000000000..f952d29cc --- /dev/null +++ b/shared/types/src/hasura/highlights.ts @@ -0,0 +1,3 @@ +import { HasuraDocument } from "./common"; + +export type Highlight = HasuraDocument; diff --git a/shared/types/src/hasura/index.ts b/shared/types/src/hasura/index.ts new file mode 100644 index 000000000..f96e7ce83 --- /dev/null +++ b/shared/types/src/hasura/index.ts @@ -0,0 +1,14 @@ +export * from "./agreement"; +export * from "./alert"; +export * from "./code-du-travail"; +export * from "./common"; +export * from "./contributions"; +export * from "./dila-resolver"; +export * from "./editorial-content"; +export * from "./export-es"; +export * from "./fiche-sp"; +export * from "./fiche-travail"; +export * from "./highlights"; +export * from "./modeles-de-courrier"; +export * from "./prequalified"; +export * from "./themes"; diff --git a/shared/types/src/hasura/modeles-de-courrier.ts b/shared/types/src/hasura/modeles-de-courrier.ts new file mode 100644 index 000000000..103d56610 --- /dev/null +++ b/shared/types/src/hasura/modeles-de-courrier.ts @@ -0,0 +1,20 @@ +import { HasuraDocument } from "./common"; + +export type MailTemplate = HasuraDocument< + MailTemplateDoc, + "modeles_de_courriers" +>; + +export type MailTemplateDoc = { + date: string; + html: string; + author: string; + filename: string; + filesize: number; + description: string; + references?: { + url: string; + title: string; + type: string; + }[]; +}; diff --git a/shared/types/src/hasura/prequalified.ts b/shared/types/src/hasura/prequalified.ts new file mode 100644 index 000000000..d81471955 --- /dev/null +++ b/shared/types/src/hasura/prequalified.ts @@ -0,0 +1,7 @@ +import { HasuraDocument } from "./common"; + +export type PrequalifiedDoc = { + variants: string[]; +}; + +export type Prequalified = HasuraDocument; diff --git a/shared/types/src/hasura/themes.ts b/shared/types/src/hasura/themes.ts new file mode 100644 index 000000000..5084773e6 --- /dev/null +++ b/shared/types/src/hasura/themes.ts @@ -0,0 +1,9 @@ +import { HasuraDocument } from "./common"; + +export type Theme = HasuraDocument; + +export type ThemeDoc = { + icon?: string; + shortTitle?: string; + description?: string; +}; diff --git a/shared/types/src/index.ts b/shared/types/src/index.ts new file mode 100644 index 000000000..d492f6080 --- /dev/null +++ b/shared/types/src/index.ts @@ -0,0 +1,3 @@ +export * from "./hasura"; +export * from "./elastic"; +export * from "./utility"; diff --git a/shared/types/utils.ts b/shared/types/src/utility.ts similarity index 100% rename from shared/types/utils.ts rename to shared/types/src/utility.ts diff --git a/shared/types/tsconfig.json b/shared/types/tsconfig.json index a52805fbe..774db91cc 100644 --- a/shared/types/tsconfig.json +++ b/shared/types/tsconfig.json @@ -1,8 +1,8 @@ { "compilerOptions": { - "target": "es6" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */, - "module": "commonjs" /* Specify what module code is generated. */, - "rootDir": "." /* Specify the root folder within your source files. */, + "target": "ESNext" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */, + "module": "NodeNext" /* Specify what module code is generated. */, + "rootDir": "./src" /* Specify the root folder within your source files. */, "declaration": true /* Generate .d.ts files from TypeScript and JavaScript files in your project. */, "outDir": "./build" /* Specify an output folder for all emitted files. */, "strict": true /* Enable all strict type-checking options. */, @@ -10,5 +10,6 @@ "sourceMap": true /* Create source map files for emitted JavaScript files. */, "declarationMap": true /* Create source map files for.d.ts files. */ }, - "include": ["index.ts"] + "include": ["./src/**/*"], + "exclude": ["node_modules", "build"] } diff --git a/shared/utils/package.json b/shared/utils/package.json index 43613cc25..0c54b6b05 100644 --- a/shared/utils/package.json +++ b/shared/utils/package.json @@ -19,10 +19,11 @@ "scripts": { "build": "tsc", "build:watch": "tsc -w", - "test": "jest" + "test": "jest", + "type-check": "tsc --noEmit" }, "devDependencies": { - "@shared/types": "workspace:^", + "@socialgouv/cdtn-types": "workspace:^", "@swc/jest": "^0.2.29", "@types/uuid": "^9.0.5", "@types/xxhashjs": "^0.2.2", diff --git a/shared/utils/src/dila-resolver.ts b/shared/utils/src/dila-resolver.ts index 13cca01c7..54019f47c 100644 --- a/shared/utils/src/dila-resolver.ts +++ b/shared/utils/src/dila-resolver.ts @@ -2,7 +2,7 @@ import type { DocumentReference, ArticlePayload, ArticleVersion, -} from "@shared/types"; +} from "@socialgouv/cdtn-types"; import type DilaApiClient from "@socialgouv/dila-api-client"; function createGetArticleReference(client: DilaApiClient) { diff --git a/targets/alert-cli/Dockerfile b/targets/alert-cli/Dockerfile index 50e44ccf3..177eadd8c 100644 --- a/targets/alert-cli/Dockerfile +++ b/targets/alert-cli/Dockerfile @@ -12,7 +12,7 @@ RUN yarn fetch workspaces focus alert-cli FROM deps AS build-types COPY shared/types ./shared/types/ -RUN yarn workspace @shared/types build +RUN yarn workspace @socialgouv/cdtn-types build FROM deps AS build-utils COPY --from=build-types /app/shared/types /app/shared/types @@ -22,8 +22,8 @@ RUN yarn workspace @shared/utils build FROM deps AS dist COPY --from=build-utils /app/shared/utils /app/shared/utils +COPY --from=build-types /app/shared/types /app/shared/types -COPY shared/types ./shared/types COPY targets/alert-cli ./targets/alert-cli COPY tsconfig.build.json ./ diff --git a/targets/alert-cli/package.json b/targets/alert-cli/package.json index 48ff30715..ce8d00d09 100644 --- a/targets/alert-cli/package.json +++ b/targets/alert-cli/package.json @@ -25,8 +25,8 @@ }, "devDependencies": { "@shared/eslint-config": "workspace:^", - "@shared/types": "workspace:^", "@shared/utils": "workspace:^", + "@socialgouv/cdtn-types": "workspace:^", "@socialgouv/contributions-data-types": "3.27.0", "@socialgouv/fiches-travail-data-types": "4.191.0", "@socialgouv/kali-data-types": "2.127.0", @@ -51,7 +51,7 @@ "start:debug": "rm -rf data/* && ncc build ./src/index.ts -o ./dist -e nodegit -s && HASURA_GRAPHQL_ENDPOINT=http://localhost:8080/v1/graphql HASURA_GRAPHQL_ADMIN_SECRET=admin1 node --enable-source-maps --unhandled-rejections=strict ./dist/index.js", "clean": "rm -rf data/*", "lint": "npx eslint \"./src/**/*.{js,ts}\"", - "types": "tsc", + "type-check": "tsc --noEmit", "test": "jest" }, "lint-staged": { diff --git a/targets/alert-cli/src/dares/types.ts b/targets/alert-cli/src/dares/types.ts index 3ca4af77c..875b0b45b 100644 --- a/targets/alert-cli/src/dares/types.ts +++ b/targets/alert-cli/src/dares/types.ts @@ -1,4 +1,4 @@ -import { DaresAlert } from "@shared/types"; +import { DaresAlert } from "@socialgouv/cdtn-types"; export interface Diff { missingAgreementsFromDares: Agreement[]; diff --git a/targets/alert-cli/src/diff/dila/CompareDilaContent.ts b/targets/alert-cli/src/diff/dila/CompareDilaContent.ts index 8d8da4958..916a9ec00 100644 --- a/targets/alert-cli/src/diff/dila/CompareDilaContent.ts +++ b/targets/alert-cli/src/diff/dila/CompareDilaContent.ts @@ -3,7 +3,7 @@ import type { DilaModifiedNode, DilaNode, DilaRemovedNode, -} from "@shared/types"; +} from "@socialgouv/cdtn-types"; import type { Agreement, AgreementArticle, diff --git a/targets/alert-cli/src/diff/dila/RelevantDocuments.ts b/targets/alert-cli/src/diff/dila/RelevantDocuments.ts index 7f3c6e3ea..f1420af35 100644 --- a/targets/alert-cli/src/diff/dila/RelevantDocuments.ts +++ b/targets/alert-cli/src/diff/dila/RelevantDocuments.ts @@ -3,7 +3,7 @@ import getEditorialContentReferences from "./extractReferences/editorialContents import getTravailEmploiReferences from "./extractReferences/ficheTravailEmploi"; import getMailTemplateReferences from "./extractReferences/mailTemplates"; import { DilaChanges } from "./types"; -import { DocumentReferences } from "@shared/types"; +import { DocumentReferences } from "@socialgouv/cdtn-types"; export interface RelevantDocumentsExtractor { extractReferences({ diff --git a/targets/alert-cli/src/diff/dila/__tests__/RelevantDocumentsExtractorStub.ts b/targets/alert-cli/src/diff/dila/__tests__/RelevantDocumentsExtractorStub.ts index fb145695d..81d6f4b9b 100644 --- a/targets/alert-cli/src/diff/dila/__tests__/RelevantDocumentsExtractorStub.ts +++ b/targets/alert-cli/src/diff/dila/__tests__/RelevantDocumentsExtractorStub.ts @@ -1,5 +1,5 @@ import { RelevantDocumentsExtractor } from "../RelevantDocuments"; -import { DilaChanges, DocumentReferences } from "@shared/types"; +import { DilaChanges, DocumentReferences } from "@socialgouv/cdtn-types"; export class RelevantDocumentsExtractorStub implements RelevantDocumentsExtractor diff --git a/targets/alert-cli/src/diff/dila/__tests__/relevantContent.test.ts b/targets/alert-cli/src/diff/dila/__tests__/relevantContent.test.ts index 659edf07b..b4df34439 100644 --- a/targets/alert-cli/src/diff/dila/__tests__/relevantContent.test.ts +++ b/targets/alert-cli/src/diff/dila/__tests__/relevantContent.test.ts @@ -1,5 +1,5 @@ import { describe, expect, it } from "@jest/globals"; -import type { DilaChanges } from "@shared/types"; +import type { DilaChanges } from "@socialgouv/cdtn-types"; import { RelevantDocumentsExtractorImpl } from "../RelevantDocuments"; jest.mock("../extractReferences/ficheTravailEmploi", () => () => []); diff --git a/targets/alert-cli/src/diff/dila/extractReferences/__tests__/editorialContents.test.ts b/targets/alert-cli/src/diff/dila/extractReferences/__tests__/editorialContents.test.ts index 17e85a486..740e2cce8 100644 --- a/targets/alert-cli/src/diff/dila/extractReferences/__tests__/editorialContents.test.ts +++ b/targets/alert-cli/src/diff/dila/extractReferences/__tests__/editorialContents.test.ts @@ -1,4 +1,4 @@ -import type { DocumentReference } from "@shared/types"; +import type { DocumentReference } from "@socialgouv/cdtn-types"; import type { EditorialContentSubset } from "../editorialContents"; import { extractEditorialContentTemplateRef } from "../editorialContents"; diff --git a/targets/alert-cli/src/diff/dila/extractReferences/__tests__/mailTemplates.test.ts b/targets/alert-cli/src/diff/dila/extractReferences/__tests__/mailTemplates.test.ts index 093bc58e5..1707a8bd8 100644 --- a/targets/alert-cli/src/diff/dila/extractReferences/__tests__/mailTemplates.test.ts +++ b/targets/alert-cli/src/diff/dila/extractReferences/__tests__/mailTemplates.test.ts @@ -1,4 +1,4 @@ -import type { DocumentReference } from "@shared/types"; +import type { DocumentReference } from "@socialgouv/cdtn-types"; import type { MailTemplateSubset } from "../mailTemplates"; import { extractMailTemplateRef } from "../mailTemplates"; diff --git a/targets/alert-cli/src/diff/dila/extractReferences/contribution/getContributionsReferences.ts b/targets/alert-cli/src/diff/dila/extractReferences/contribution/getContributionsReferences.ts index 3066462f8..bc8b89970 100644 --- a/targets/alert-cli/src/diff/dila/extractReferences/contribution/getContributionsReferences.ts +++ b/targets/alert-cli/src/diff/dila/extractReferences/contribution/getContributionsReferences.ts @@ -1,4 +1,4 @@ -import type { DocumentReferences } from "@shared/types"; +import type { DocumentReferences } from "@socialgouv/cdtn-types"; import { SOURCES } from "@socialgouv/cdtn-sources"; import { queryContributionsReferences } from "./queryContributionsReferences"; import { diff --git a/targets/alert-cli/src/diff/dila/extractReferences/contribution/index.ts b/targets/alert-cli/src/diff/dila/extractReferences/contribution/index.ts index dc2fd3867..03e585a2d 100644 --- a/targets/alert-cli/src/diff/dila/extractReferences/contribution/index.ts +++ b/targets/alert-cli/src/diff/dila/extractReferences/contribution/index.ts @@ -1,4 +1,4 @@ -import type { DocumentReferences } from "@shared/types"; +import type { DocumentReferences } from "@socialgouv/cdtn-types"; import memoizee from "memoizee"; import { getContributionsReferences } from "./getContributionsReferences"; diff --git a/targets/alert-cli/src/diff/dila/extractReferences/contribution/queryContributionsReferences.ts b/targets/alert-cli/src/diff/dila/extractReferences/contribution/queryContributionsReferences.ts index 31474c3c6..5e75d0cd6 100644 --- a/targets/alert-cli/src/diff/dila/extractReferences/contribution/queryContributionsReferences.ts +++ b/targets/alert-cli/src/diff/dila/extractReferences/contribution/queryContributionsReferences.ts @@ -1,4 +1,4 @@ -import { ContributionsAnswers } from "@shared/types"; +import { ContributionsAnswers } from "@socialgouv/cdtn-types"; import { gqlClient } from "@shared/utils"; const getContributionsWithRefs = ` diff --git a/targets/alert-cli/src/diff/dila/extractReferences/editorialContents.ts b/targets/alert-cli/src/diff/dila/extractReferences/editorialContents.ts index fef397651..5a24d1db4 100644 --- a/targets/alert-cli/src/diff/dila/extractReferences/editorialContents.ts +++ b/targets/alert-cli/src/diff/dila/extractReferences/editorialContents.ts @@ -3,7 +3,7 @@ import type { DocumentReferences, EditoralContentReferenceBloc, EditorialContent, -} from "@shared/types"; +} from "@socialgouv/cdtn-types"; import { SOURCES } from "@socialgouv/cdtn-sources"; import { DilaApiClient } from "@socialgouv/dila-api-client"; import memoizee from "memoizee"; diff --git a/targets/alert-cli/src/diff/dila/extractReferences/ficheTravailEmploi.ts b/targets/alert-cli/src/diff/dila/extractReferences/ficheTravailEmploi.ts index 6893d7467..af34bfe6b 100644 --- a/targets/alert-cli/src/diff/dila/extractReferences/ficheTravailEmploi.ts +++ b/targets/alert-cli/src/diff/dila/extractReferences/ficheTravailEmploi.ts @@ -1,4 +1,7 @@ -import type { DocumentReferences, FicheTravailEmploi } from "@shared/types"; +import type { + DocumentReferences, + FicheTravailEmploi, +} from "@socialgouv/cdtn-types"; import { SOURCES } from "@socialgouv/cdtn-sources"; import memoizee from "memoizee"; diff --git a/targets/alert-cli/src/diff/dila/extractReferences/mailTemplates.ts b/targets/alert-cli/src/diff/dila/extractReferences/mailTemplates.ts index 13c8bb287..ad9716df0 100644 --- a/targets/alert-cli/src/diff/dila/extractReferences/mailTemplates.ts +++ b/targets/alert-cli/src/diff/dila/extractReferences/mailTemplates.ts @@ -1,5 +1,5 @@ import { createGetArticleReference, extractArticleId } from "@shared/utils"; -import type { DocumentReferences, MailTemplate } from "@shared/types"; +import type { DocumentReferences, MailTemplate } from "@socialgouv/cdtn-types"; import { SOURCES } from "@socialgouv/cdtn-sources"; import { DilaApiClient } from "@socialgouv/dila-api-client"; import memoizee from "memoizee"; diff --git a/targets/alert-cli/src/diff/dila/types.ts b/targets/alert-cli/src/diff/dila/types.ts index 136ad662e..4dfc36f63 100644 --- a/targets/alert-cli/src/diff/dila/types.ts +++ b/targets/alert-cli/src/diff/dila/types.ts @@ -4,7 +4,7 @@ import type { DilaModifiedNode, DilaRemovedNode, DocumentReferences, -} from "@shared/types"; +} from "@socialgouv/cdtn-types"; import type { AgreementArticle, AgreementArticleData, diff --git a/targets/alert-cli/src/diff/index.ts b/targets/alert-cli/src/diff/index.ts index c7400eff4..979ed81d0 100644 --- a/targets/alert-cli/src/diff/index.ts +++ b/targets/alert-cli/src/diff/index.ts @@ -3,7 +3,7 @@ import { processAgreementDataDiff, processCodeDataDiff } from "./dila"; import { processVddDiff } from "./sp"; import { processTravailDataDiff } from "./travail-data"; import { GitTagData } from "../types"; -import { AlertChanges } from "@shared/types"; +import { AlertChanges } from "@socialgouv/cdtn-types"; import { GithubApi } from "../utils/github"; import { getSupportedAgreements } from "./shared/getSupportedAgreements"; diff --git a/targets/alert-cli/src/diff/shared/getContributionsCdtnReferences.ts b/targets/alert-cli/src/diff/shared/getContributionsCdtnReferences.ts index d7c0b84d3..b8bad8d28 100644 --- a/targets/alert-cli/src/diff/shared/getContributionsCdtnReferences.ts +++ b/targets/alert-cli/src/diff/shared/getContributionsCdtnReferences.ts @@ -1,4 +1,4 @@ -import { ContributionsAnswers } from "@shared/types"; +import { ContributionsAnswers } from "@socialgouv/cdtn-types"; import { gqlClient } from "@shared/utils"; const getContribCdtnReferences = ` diff --git a/targets/alert-cli/src/diff/shared/getDocumentQuery.gql.ts b/targets/alert-cli/src/diff/shared/getDocumentQuery.gql.ts index ae4b2a89d..81d0e58a2 100644 --- a/targets/alert-cli/src/diff/shared/getDocumentQuery.gql.ts +++ b/targets/alert-cli/src/diff/shared/getDocumentQuery.gql.ts @@ -1,4 +1,4 @@ -import type { HasuraDocument } from "@shared/types"; +import type { HasuraDocument } from "@socialgouv/cdtn-types"; export const getAllDocumentsBySourceQuery = ` query getAllDocumentsBySource($source: [String!], $limit:Int=10,$offset:Int=0 ) { @@ -17,7 +17,7 @@ query getAllDocumentsBySource($source: [String!], $limit:Int=10,$offset:Int=0 ) `; export type HasuraDocumentForAlert = Pick< - HasuraDocument, + HasuraDocument, "source" | "title" > & { initialId: string; @@ -72,14 +72,14 @@ query($source: [String!], $limit:Int=10,$offset:Int=0 ) { `; export type HasuraDocumentWithRelations = Pick< - HasuraDocument, + HasuraDocument, "source" | "title" > & { cdtnId: string; isPublished: boolean; contentRelations: { position: number; - document: Pick & { + document: Pick, "slug" | "source" | "title"> & { initialId: string; }; }[]; diff --git a/targets/alert-cli/src/diff/shared/getDocumentsWithRelations.ts b/targets/alert-cli/src/diff/shared/getDocumentsWithRelations.ts index f376bd2f5..30404230a 100644 --- a/targets/alert-cli/src/diff/shared/getDocumentsWithRelations.ts +++ b/targets/alert-cli/src/diff/shared/getDocumentsWithRelations.ts @@ -1,4 +1,4 @@ -import type { DocumentInfo } from "@shared/types"; +import type { DocumentInfo } from "@socialgouv/cdtn-types"; import { SourceValues } from "@socialgouv/cdtn-sources"; import { getDocumentsWithRelationsBySource } from "./getAllDocumentsBySource"; diff --git a/targets/alert-cli/src/diff/sp/getContributionsWithFicheSp.ts b/targets/alert-cli/src/diff/sp/getContributionsWithFicheSp.ts index 325254154..d5f171d4a 100644 --- a/targets/alert-cli/src/diff/sp/getContributionsWithFicheSp.ts +++ b/targets/alert-cli/src/diff/sp/getContributionsWithFicheSp.ts @@ -1,4 +1,4 @@ -import { ContributionsAnswers } from "@shared/types"; +import { ContributionsAnswers } from "@socialgouv/cdtn-types"; import { gqlClient } from "@shared/utils"; const queryGetContributionsWithRefs = ` diff --git a/targets/alert-cli/src/diff/sp/getRelevantDocument/contributions.ts b/targets/alert-cli/src/diff/sp/getRelevantDocument/contributions.ts index 38167d4b8..f832fb4ec 100644 --- a/targets/alert-cli/src/diff/sp/getRelevantDocument/contributions.ts +++ b/targets/alert-cli/src/diff/sp/getRelevantDocument/contributions.ts @@ -1,4 +1,7 @@ -import type { DocumentInfoWithCdtnRef, VddChanges } from "@shared/types"; +import type { + DocumentInfoWithCdtnRef, + VddChanges, +} from "@socialgouv/cdtn-types"; import { getContributionsWithFicheSp } from "./../getContributionsWithFicheSp"; import { getContributionsCdtnReferences } from "../../shared/getContributionsCdtnReferences"; diff --git a/targets/alert-cli/src/diff/sp/getRelevantDocument/index.ts b/targets/alert-cli/src/diff/sp/getRelevantDocument/index.ts index 75be1c5b2..019816c87 100644 --- a/targets/alert-cli/src/diff/sp/getRelevantDocument/index.ts +++ b/targets/alert-cli/src/diff/sp/getRelevantDocument/index.ts @@ -1,4 +1,7 @@ -import type { DocumentInfoWithCdtnRef, VddChanges } from "@shared/types"; +import type { + DocumentInfoWithCdtnRef, + VddChanges, +} from "@socialgouv/cdtn-types"; import { getRelevantSpDocumentsThemeAndPrequalified } from "./themesAndPrequalified"; import { getRelevantSpDocumentsContributions } from "./contributions"; diff --git a/targets/alert-cli/src/diff/sp/getRelevantDocument/themesAndPrequalified.ts b/targets/alert-cli/src/diff/sp/getRelevantDocument/themesAndPrequalified.ts index b8ed277c0..cdb37ce17 100644 --- a/targets/alert-cli/src/diff/sp/getRelevantDocument/themesAndPrequalified.ts +++ b/targets/alert-cli/src/diff/sp/getRelevantDocument/themesAndPrequalified.ts @@ -1,4 +1,7 @@ -import type { DocumentInfoWithCdtnRef, VddChanges } from "@shared/types"; +import type { + DocumentInfoWithCdtnRef, + VddChanges, +} from "@socialgouv/cdtn-types"; import { SOURCES } from "@socialgouv/cdtn-sources"; import { getDocumentsWithRelations } from "../../shared/getDocumentsWithRelations"; diff --git a/targets/alert-cli/src/diff/sp/index.ts b/targets/alert-cli/src/diff/sp/index.ts index 3644b36d0..fccca5ef2 100644 --- a/targets/alert-cli/src/diff/sp/index.ts +++ b/targets/alert-cli/src/diff/sp/index.ts @@ -1,4 +1,4 @@ -import type { FicheVddInfo, VddChanges } from "@shared/types"; +import type { FicheVddInfo, VddChanges } from "@socialgouv/cdtn-types"; import { createToJson } from "../../utils/node-git.helpers"; import type { diff --git a/targets/alert-cli/src/diff/travail-data/getRelevantDocument/contributions.ts b/targets/alert-cli/src/diff/travail-data/getRelevantDocument/contributions.ts index afec2a73a..ac03717a6 100644 --- a/targets/alert-cli/src/diff/travail-data/getRelevantDocument/contributions.ts +++ b/targets/alert-cli/src/diff/travail-data/getRelevantDocument/contributions.ts @@ -1,7 +1,7 @@ import type { DocumentInfoWithCdtnRef, TravailDataChanges, -} from "@shared/types"; +} from "@socialgouv/cdtn-types"; import { getContributionsCdtnReferences } from "../../shared/getContributionsCdtnReferences"; diff --git a/targets/alert-cli/src/diff/travail-data/getRelevantDocument/index.ts b/targets/alert-cli/src/diff/travail-data/getRelevantDocument/index.ts index 74b941891..51fd8d598 100644 --- a/targets/alert-cli/src/diff/travail-data/getRelevantDocument/index.ts +++ b/targets/alert-cli/src/diff/travail-data/getRelevantDocument/index.ts @@ -1,7 +1,7 @@ import type { DocumentInfoWithCdtnRef, TravailDataChanges, -} from "@shared/types"; +} from "@socialgouv/cdtn-types"; import { getRelevantMtDocumentsThemeAndPrequalified } from "./themesAndPrequalified"; import { getRelevantMtDocumentsContributions } from "./contributions"; diff --git a/targets/alert-cli/src/diff/travail-data/getRelevantDocument/themesAndPrequalified.ts b/targets/alert-cli/src/diff/travail-data/getRelevantDocument/themesAndPrequalified.ts index 460c8d84c..54193e9d1 100644 --- a/targets/alert-cli/src/diff/travail-data/getRelevantDocument/themesAndPrequalified.ts +++ b/targets/alert-cli/src/diff/travail-data/getRelevantDocument/themesAndPrequalified.ts @@ -1,7 +1,7 @@ import type { DocumentInfoWithCdtnRef, TravailDataChanges, -} from "@shared/types"; +} from "@socialgouv/cdtn-types"; import { SOURCES } from "@socialgouv/cdtn-sources"; import { getDocumentsWithRelations } from "../../shared/getDocumentsWithRelations"; diff --git a/targets/alert-cli/src/diff/travail-data/index.ts b/targets/alert-cli/src/diff/travail-data/index.ts index 6ee4238b1..906fc0f5f 100644 --- a/targets/alert-cli/src/diff/travail-data/index.ts +++ b/targets/alert-cli/src/diff/travail-data/index.ts @@ -1,7 +1,7 @@ import type { FicheTravailEmploiInfoWithDiff, TravailDataChanges, -} from "@shared/types"; +} from "@socialgouv/cdtn-types"; import type { FicheTravailEmploi } from "@socialgouv/fiches-travail-data-types"; import { createToJson } from "../../utils/node-git.helpers"; diff --git a/targets/alert-cli/src/repositories/AlertRepository.ts b/targets/alert-cli/src/repositories/AlertRepository.ts index 68b27f98e..e780f7707 100644 --- a/targets/alert-cli/src/repositories/AlertRepository.ts +++ b/targets/alert-cli/src/repositories/AlertRepository.ts @@ -1,4 +1,4 @@ -import { AlertChanges, AlertInfo, HasuraAlert } from "@shared/types"; +import { AlertChanges, AlertInfo, HasuraAlert } from "@socialgouv/cdtn-types"; import { batchPromises } from "../utils/batch-promises"; import { DaresAlertInsert } from "../dares/types"; import { GqlClient } from "@shared/utils"; diff --git a/targets/alert-cli/src/types.ts b/targets/alert-cli/src/types.ts index 1aa24f65c..875677bc6 100644 --- a/targets/alert-cli/src/types.ts +++ b/targets/alert-cli/src/types.ts @@ -3,7 +3,7 @@ import type { DilaAlertChanges, TravailDataAlertChanges, VddAlertChanges, -} from "@shared/types"; +} from "@socialgouv/cdtn-types"; export interface PublicAgreement { id: string; diff --git a/targets/export-elasticsearch/Dockerfile b/targets/export-elasticsearch/Dockerfile index 68a8fc1eb..14e3bfcbd 100644 --- a/targets/export-elasticsearch/Dockerfile +++ b/targets/export-elasticsearch/Dockerfile @@ -14,7 +14,7 @@ RUN yarn fetch workspaces focus export-elasticsearch FROM deps AS build-types COPY shared/types ./shared/types/ -RUN yarn workspace @shared/types build +RUN yarn workspace @socialgouv/cdtn-types build FROM deps AS build-utils COPY --from=build-types /app/shared/types /app/shared/types diff --git a/targets/export-elasticsearch/package.json b/targets/export-elasticsearch/package.json index 4638a0ed7..ce29dbc6a 100644 --- a/targets/export-elasticsearch/package.json +++ b/targets/export-elasticsearch/package.json @@ -20,16 +20,17 @@ "build:swc": "swc ./src -d build", "build:swc:watch": "swc ./src -d build -w", "run:ingester": "curl -X POST -H \"Content-Type: application/json\" -d '{\"environment\": \"preproduction\", \"userId\": \"3d6dddc4-e117-4772-9288-cd8a608693e4\"}' http://localhost:8787/export", - "lint": "npx eslint ./src --ext .ts" + "lint": "npx eslint ./src --ext .ts", + "type-check": "tsc --noEmit" }, "dependencies": { "@aws-sdk/client-s3": "^3.523.0", "@elastic/elasticsearch": "^7.14.1", - "@shared/types": "workspace:^", "@shared/utils": "workspace:^", "@socialgouv/cdtn-elasticsearch": "workspace:^", "@socialgouv/cdtn-slugify": "^4.52.1", "@socialgouv/cdtn-sources": "^4.52.1", + "@socialgouv/cdtn-types": "workspace:^", "axios": "^0.26.1", "body-parser": "^1.19.2", "cors": "^2.8.5", diff --git a/targets/export-elasticsearch/src/controllers/__test__/export.test.ts b/targets/export-elasticsearch/src/controllers/__test__/export.test.ts index c96aecf8d..b2e306109 100644 --- a/targets/export-elasticsearch/src/controllers/__test__/export.test.ts +++ b/targets/export-elasticsearch/src/controllers/__test__/export.test.ts @@ -1,6 +1,6 @@ import "../export"; -import { Environment, Status } from "@shared/types"; +import { Environment, Status } from "@socialgouv/cdtn-types"; import bodyParser from "body-parser"; import type { NextFunction, Request, Response } from "express"; import { Container } from "inversify"; diff --git a/targets/export-elasticsearch/src/controllers/__test__/fake/export.ts b/targets/export-elasticsearch/src/controllers/__test__/fake/export.ts index 9b93e2b36..6d9ae1922 100644 --- a/targets/export-elasticsearch/src/controllers/__test__/fake/export.ts +++ b/targets/export-elasticsearch/src/controllers/__test__/fake/export.ts @@ -1,5 +1,5 @@ -import type { ExportEsStatus } from "@shared/types"; -import { Environment, Status } from "@shared/types"; +import type { ExportEsStatus } from "@socialgouv/cdtn-types"; +import { Environment, Status } from "@socialgouv/cdtn-types"; import { injectable } from "inversify"; import { wait } from "../../../utils"; diff --git a/targets/export-elasticsearch/src/controllers/export.ts b/targets/export-elasticsearch/src/controllers/export.ts index beafe7709..b26a0f8f8 100644 --- a/targets/export-elasticsearch/src/controllers/export.ts +++ b/targets/export-elasticsearch/src/controllers/export.ts @@ -1,5 +1,5 @@ -import type { ExportEsStatus } from "@shared/types"; -import { Environment } from "@shared/types"; +import type { ExportEsStatus } from "@socialgouv/cdtn-types"; +import { Environment } from "@socialgouv/cdtn-types"; import { Request, Response } from "express"; import { inject } from "inversify"; import type { interfaces } from "inversify-express-utils"; diff --git a/targets/export-elasticsearch/src/controllers/middlewares/export.ts b/targets/export-elasticsearch/src/controllers/middlewares/export.ts index e60e94ec3..3c16a5fef 100644 --- a/targets/export-elasticsearch/src/controllers/middlewares/export.ts +++ b/targets/export-elasticsearch/src/controllers/middlewares/export.ts @@ -1,4 +1,4 @@ -import { Environment } from "@shared/types"; +import { Environment } from "@socialgouv/cdtn-types"; import type { NextFunction, Request, Response } from "express"; import { injectable } from "inversify"; import { BaseMiddleware } from "inversify-express-utils"; diff --git a/targets/export-elasticsearch/src/ingester/__tests__/breadcrumbs.test.ts b/targets/export-elasticsearch/src/ingester/__tests__/breadcrumbs.test.ts index 81510fac5..abd11eec8 100644 --- a/targets/export-elasticsearch/src/ingester/__tests__/breadcrumbs.test.ts +++ b/targets/export-elasticsearch/src/ingester/__tests__/breadcrumbs.test.ts @@ -1,9 +1,9 @@ import { getMainBreadcrumb } from "../breadcrumbs"; -import { Breadcrumbs } from "@shared/types"; +import { Breadcrumb } from "@socialgouv/cdtn-types"; describe("getMainBreadcrumb", () => { test("Vérifier que le breadcrumbs avec la plus petite position remonte", () => { - const breadcrumbs1: Breadcrumbs[] = [ + const breadcrumbs1: Breadcrumb[] = [ { label: "label1", position: 1, @@ -15,7 +15,7 @@ describe("getMainBreadcrumb", () => { slug: "slug2", }, ]; - const breadcrumbs2: Breadcrumbs[] = [ + const breadcrumbs2: Breadcrumb[] = [ { label: "label2", position: 2, @@ -31,7 +31,7 @@ describe("getMainBreadcrumb", () => { expect(result).toEqual(breadcrumbs1); }); test("Vérifier que le breadcrumbs avec le moins de themes remonte en premier", () => { - const breadcrumbs1: Breadcrumbs[] = [ + const breadcrumbs1: Breadcrumb[] = [ { label: "label2", position: 2, @@ -43,7 +43,7 @@ describe("getMainBreadcrumb", () => { slug: "slug3", }, ]; - const breadcrumbs2: Breadcrumbs[] = [ + const breadcrumbs2: Breadcrumb[] = [ { label: "label1", position: 1, diff --git a/targets/export-elasticsearch/src/ingester/agreements/generate.ts b/targets/export-elasticsearch/src/ingester/agreements/generate.ts index f2be8057a..c83d39c2f 100644 --- a/targets/export-elasticsearch/src/ingester/agreements/generate.ts +++ b/targets/export-elasticsearch/src/ingester/agreements/generate.ts @@ -1,10 +1,10 @@ import { AgreementDoc, - AgreementGenerated, + ElasticAgreement, ContributionElasticDocument, ExportAnswer, -} from "@shared/types"; -import { DocumentElasticWithSource } from "../types/Glossary"; + DocumentElasticWithSource, +} from "@socialgouv/cdtn-types"; import { SOURCES } from "@socialgouv/cdtn-sources"; import { getIDCCs } from "./getIdcc"; import getAgreementsArticlesByTheme from "./getAgreementsArticlesByTheme"; @@ -18,7 +18,7 @@ const DESCRIPTION = export const generateAgreements = async ( ccnData: DocumentElasticWithSource[], contributions: ContributionElasticDocument[] -): Promise => { +): Promise => { return await pMap( ccnData, async (cc) => { @@ -41,13 +41,12 @@ export const generateAgreements = async ( .sort( // On ordonne les questions par index (a: ExportAnswer, b: ExportAnswer) => - // @ts-ignore a.questionIndex - b.questionIndex ); const articlesByTheme = await getAgreementsArticlesByTheme(cc.num); - const agreementGenerated: AgreementGenerated = { + const agreementGenerated: ElasticAgreement = { ...cc, answers, articlesByTheme, diff --git a/targets/export-elasticsearch/src/ingester/agreements/getAgreementsArticlesByTheme.ts b/targets/export-elasticsearch/src/ingester/agreements/getAgreementsArticlesByTheme.ts index aeb3ae83c..fc6054650 100644 --- a/targets/export-elasticsearch/src/ingester/agreements/getAgreementsArticlesByTheme.ts +++ b/targets/export-elasticsearch/src/ingester/agreements/getAgreementsArticlesByTheme.ts @@ -2,7 +2,7 @@ import { KaliBlockByIdccResult, KaliArticlesByIdResult, ArticleByTheme, -} from "@shared/types"; +} from "@socialgouv/cdtn-types"; import { gqlClient, logger } from "@shared/utils"; import { context } from "../context"; import { detectNullInObject } from "../utils/detectNullInObject"; @@ -86,8 +86,10 @@ export function generateArticleByTheme( export default async function getAgreementsArticlesByTheme( idccNumber: number ): Promise { - const HASURA_GRAPHQL_ENDPOINT = context.get("cdtnAdminEndpoint") || "http://localhost:8080/v1/graphql"; - const HASURA_GRAPHQL_ENDPOINT_SECRET = context.get("cdtnAdminEndpointSecret") ||"admin1"; + const HASURA_GRAPHQL_ENDPOINT = + context.get("cdtnAdminEndpoint") || "http://localhost:8080/v1/graphql"; + const HASURA_GRAPHQL_ENDPOINT_SECRET = + context.get("cdtnAdminEndpointSecret") || "admin1"; const resultKaliBlocks = await gqlClient({ graphqlEndpoint: HASURA_GRAPHQL_ENDPOINT, adminSecret: HASURA_GRAPHQL_ENDPOINT_SECRET, diff --git a/targets/export-elasticsearch/src/ingester/agreements/getIdcc.ts b/targets/export-elasticsearch/src/ingester/agreements/getIdcc.ts index ea3e7d81c..b0562bfd6 100644 --- a/targets/export-elasticsearch/src/ingester/agreements/getIdcc.ts +++ b/targets/export-elasticsearch/src/ingester/agreements/getIdcc.ts @@ -1,4 +1,4 @@ -import { ContributionElasticDocument } from "@shared/types"; +import { ContributionElasticDocument } from "@socialgouv/cdtn-types"; export function getIDCCs(contributions: ContributionElasticDocument[]) { const contribIDCCs = new Set(); diff --git a/targets/export-elasticsearch/src/ingester/agreements/getInfoMessage.ts b/targets/export-elasticsearch/src/ingester/agreements/getInfoMessage.ts index ee66f5c7f..06e67bdc9 100644 --- a/targets/export-elasticsearch/src/ingester/agreements/getInfoMessage.ts +++ b/targets/export-elasticsearch/src/ingester/agreements/getInfoMessage.ts @@ -1,4 +1,4 @@ -import { ContributionElasticDocument } from "@shared/types"; +import { ContributionElasticDocument } from "@socialgouv/cdtn-types"; const CC_NE_PREVOIT_RIEN = "Les informations ci-dessous sont issues du code du travail car la convention collective ne prévoit rien sur ce sujet."; diff --git a/targets/export-elasticsearch/src/ingester/agreements/getTheme.ts b/targets/export-elasticsearch/src/ingester/agreements/getTheme.ts index 19257fb65..84cd6b5c7 100644 --- a/targets/export-elasticsearch/src/ingester/agreements/getTheme.ts +++ b/targets/export-elasticsearch/src/ingester/agreements/getTheme.ts @@ -1,4 +1,4 @@ -import { ContributionElasticDocument } from "@shared/types"; +import { ContributionElasticDocument } from "@socialgouv/cdtn-types"; export function getTheme( data: ContributionElasticDocument diff --git a/targets/export-elasticsearch/src/ingester/breadcrumbs.ts b/targets/export-elasticsearch/src/ingester/breadcrumbs.ts index e7d66d2e8..39ec54d08 100644 --- a/targets/export-elasticsearch/src/ingester/breadcrumbs.ts +++ b/targets/export-elasticsearch/src/ingester/breadcrumbs.ts @@ -1,11 +1,11 @@ import { getRouteBySource, SOURCES } from "@socialgouv/cdtn-sources"; import type { Theme } from "./types/themes"; -import { Breadcrumbs } from "@shared/types"; +import { Breadcrumb } from "@socialgouv/cdtn-types"; -export type GetBreadcrumbsFn = (cdtnId: string) => Breadcrumbs[]; +export type GetBreadcrumbsFn = (cdtnId: string) => Breadcrumb[]; -function toBreadcrumbs(theme: Theme): Breadcrumbs { +function toBreadcrumbs(theme: Theme): Breadcrumb { return { label: theme.title, position: theme.parentRelations[0].position, @@ -13,7 +13,7 @@ function toBreadcrumbs(theme: Theme): Breadcrumbs { }; } -function minPositionBreadcrumb(breadcrumb: Breadcrumbs[]) { +function minPositionBreadcrumb(breadcrumb: Breadcrumb[]) { return ( breadcrumb.reduce( (result, { position }) => @@ -24,9 +24,9 @@ function minPositionBreadcrumb(breadcrumb: Breadcrumbs[]) { } export function getMainBreadcrumb( - allBreadcrumbs: (Breadcrumbs[] | undefined)[] = [] + allBreadcrumbs: (Breadcrumb[] | undefined)[] = [] ) { - return allBreadcrumbs.reduce( + return allBreadcrumbs.reduce( (topBreadcrumb, breadcrumb, index) => { if (index === 0) { return topBreadcrumb; @@ -48,7 +48,7 @@ export function buildGetBreadcrumbs(themes: Theme[]): GetBreadcrumbsFn { // beware, this one is recursive // we might want to set a depth limit for safety reasons // it picks a relation and returns an array of all possible breadcrumbs - function buildAllBreadcrumbs(theme: Theme): (Breadcrumbs[] | undefined)[] { + function buildAllBreadcrumbs(theme: Theme): (Breadcrumb[] | undefined)[] { const currentBreadcrumb = toBreadcrumbs(theme); const parentTheme = themes.filter( (parentTheme) => diff --git a/targets/export-elasticsearch/src/ingester/cdtnDocuments.ts b/targets/export-elasticsearch/src/ingester/cdtnDocuments.ts index 3f82ecda5..9b6da1fb1 100644 --- a/targets/export-elasticsearch/src/ingester/cdtnDocuments.ts +++ b/targets/export-elasticsearch/src/ingester/cdtnDocuments.ts @@ -5,7 +5,9 @@ import { EditorialContentDoc, ExportEsStatus, FicheTravailEmploiDoc, -} from "@shared/types"; + DocumentElasticWithSource, + DocumentRef, +} from "@socialgouv/cdtn-types"; import { logger } from "@shared/utils"; import { SOURCES } from "@socialgouv/cdtn-sources"; @@ -18,7 +20,6 @@ import { import { splitArticle } from "./fichesTravailSplitter"; import { createGlossaryTransform } from "./glossary"; import { getVersions } from "./versions"; -import { DocumentElasticWithSource } from "./types/Glossary"; import { generateContributions } from "./contributions"; import { generateAgreements } from "./agreements"; import { getGlossary } from "./common/fetchGlossary"; @@ -231,7 +232,7 @@ export async function cdtnDocumentsGen( ); const highlightsWithContrib = highlights.map((highlight) => ({ ...highlight, - refs: highlight.refs.map((ref) => { + refs: highlight.refs.map((ref: DocumentRef) => { if (!ref.description) { const foundContrib = generatedContributions.find( (generatedContribution) => { diff --git a/targets/export-elasticsearch/src/ingester/common/fetchCdtnAdminDocuments.ts b/targets/export-elasticsearch/src/ingester/common/fetchCdtnAdminDocuments.ts index 5ac32f320..d4e540693 100644 --- a/targets/export-elasticsearch/src/ingester/common/fetchCdtnAdminDocuments.ts +++ b/targets/export-elasticsearch/src/ingester/common/fetchCdtnAdminDocuments.ts @@ -5,13 +5,15 @@ import type { GetBreadcrumbsFn } from "../breadcrumbs"; import { context } from "../context"; import type { Document, - DocumentElastic, - DocumentElasticWithSource, - DocumentRef, DocumentWithRelation, Relation, } from "../types/Glossary"; -import { Breadcrumbs } from "@shared/types"; +import { + Breadcrumb, + DocumentElastic, + DocumentElasticWithSource, + DocumentRef, +} from "@socialgouv/cdtn-types"; import { gqlClient } from "@shared/utils"; const PAGE_SIZE = process.env.FETCH_PAGE_SIZE @@ -231,7 +233,7 @@ function toElastic( refs: DocumentRef[], getBreadcrumbs: GetBreadcrumbsFn | undefined = undefined ): DocumentElasticWithSource { - let breadcrumbs: Breadcrumbs[] = []; + let breadcrumbs: Breadcrumb[] = []; if (getBreadcrumbs) { breadcrumbs = getBreadcrumbs(cdtnId); } diff --git a/targets/export-elasticsearch/src/ingester/common/populateRelatedDocuments.ts b/targets/export-elasticsearch/src/ingester/common/populateRelatedDocuments.ts index d89818800..6c583bf38 100644 --- a/targets/export-elasticsearch/src/ingester/common/populateRelatedDocuments.ts +++ b/targets/export-elasticsearch/src/ingester/common/populateRelatedDocuments.ts @@ -1,4 +1,7 @@ -import { DocumentElasticWithSource, RelatedDocument } from "@shared/types"; +import { + DocumentElasticWithSource, + RelatedDocument, +} from "@socialgouv/cdtn-types"; export interface RelatedDocuments { [id: string]: RelatedDocument; diff --git a/targets/export-elasticsearch/src/ingester/contributions/__tests__/generateContent.test.ts b/targets/export-elasticsearch/src/ingester/contributions/__tests__/generateContent.test.ts index b5974e5d3..fc37ac901 100644 --- a/targets/export-elasticsearch/src/ingester/contributions/__tests__/generateContent.test.ts +++ b/targets/export-elasticsearch/src/ingester/contributions/__tests__/generateContent.test.ts @@ -1,4 +1,4 @@ -import { ContributionContent } from "@shared/types"; +import { ContributionContent } from "@socialgouv/cdtn-types"; import { fetchFicheSp } from "../fetchFicheSp"; import { generateContent } from "../generateContent"; diff --git a/targets/export-elasticsearch/src/ingester/contributions/__tests__/generateLinkedContent.test.ts b/targets/export-elasticsearch/src/ingester/contributions/__tests__/generateLinkedContent.test.ts index 42f7319b9..6568746de 100644 --- a/targets/export-elasticsearch/src/ingester/contributions/__tests__/generateLinkedContent.test.ts +++ b/targets/export-elasticsearch/src/ingester/contributions/__tests__/generateLinkedContent.test.ts @@ -1,11 +1,11 @@ import { generateLinkedContent } from "../generateLinkedContent"; import { fetchLinkedContent, LinkedContentLight } from "../fetchLinkedContent"; import { ContributionElasticDocumentLightRelatedContent } from "../generate"; -import { Breadcrumbs } from "@shared/types"; +import { Breadcrumb } from "@socialgouv/cdtn-types"; jest.mock("../fetchLinkedContent"); -const breadcrumbs: Breadcrumbs[] = [ +const breadcrumbs: Breadcrumb[] = [ { label: "Thème 1", position: 0, diff --git a/targets/export-elasticsearch/src/ingester/contributions/__tests__/generateMessageBlock.test.ts b/targets/export-elasticsearch/src/ingester/contributions/__tests__/generateMessageBlock.test.ts index 69e7a5623..0cfeed989 100644 --- a/targets/export-elasticsearch/src/ingester/contributions/__tests__/generateMessageBlock.test.ts +++ b/targets/export-elasticsearch/src/ingester/contributions/__tests__/generateMessageBlock.test.ts @@ -1,4 +1,4 @@ -import { ContributionContentType } from "@shared/types"; +import { ContributionContentType } from "@socialgouv/cdtn-types"; import { fetchMessageBlock } from "../fetchMessageBlock"; import { fetchAgreementMessage } from "../fetchAgreementMessage"; import { generateMessageBlock } from "../generateMessageBlock"; diff --git a/targets/export-elasticsearch/src/ingester/contributions/addGlossaryToContent.ts b/targets/export-elasticsearch/src/ingester/contributions/addGlossaryToContent.ts index aeb2fc687..a0df0cc2f 100644 --- a/targets/export-elasticsearch/src/ingester/contributions/addGlossaryToContent.ts +++ b/targets/export-elasticsearch/src/ingester/contributions/addGlossaryToContent.ts @@ -1,4 +1,4 @@ -import { ContributionContent } from "@shared/types"; +import { ContributionContent } from "@socialgouv/cdtn-types"; export function addGlossaryToContent( content: ContributionContent, diff --git a/targets/export-elasticsearch/src/ingester/contributions/fetchAgreementMessage.ts b/targets/export-elasticsearch/src/ingester/contributions/fetchAgreementMessage.ts index b02f29410..768a3402c 100644 --- a/targets/export-elasticsearch/src/ingester/contributions/fetchAgreementMessage.ts +++ b/targets/export-elasticsearch/src/ingester/contributions/fetchAgreementMessage.ts @@ -1,4 +1,4 @@ -import { ContributionAgreementMessage } from "@shared/types"; +import { ContributionAgreementMessage } from "@socialgouv/cdtn-types"; import { gqlClient } from "@shared/utils"; import { context } from "../context"; diff --git a/targets/export-elasticsearch/src/ingester/contributions/fetchFicheSp.ts b/targets/export-elasticsearch/src/ingester/contributions/fetchFicheSp.ts index a4af063b6..9f6103309 100644 --- a/targets/export-elasticsearch/src/ingester/contributions/fetchFicheSp.ts +++ b/targets/export-elasticsearch/src/ingester/contributions/fetchFicheSp.ts @@ -1,4 +1,4 @@ -import { FicheServicePublicDoc } from "@shared/types"; +import { FicheServicePublicDoc } from "@socialgouv/cdtn-types"; import { gqlClient } from "@shared/utils"; import { context } from "../context"; diff --git a/targets/export-elasticsearch/src/ingester/contributions/fetchMessageBlock.ts b/targets/export-elasticsearch/src/ingester/contributions/fetchMessageBlock.ts index 8ecdeb8c4..56fbebc81 100644 --- a/targets/export-elasticsearch/src/ingester/contributions/fetchMessageBlock.ts +++ b/targets/export-elasticsearch/src/ingester/contributions/fetchMessageBlock.ts @@ -1,4 +1,4 @@ -import { ContributionMessageBlock } from "@shared/types"; +import { ContributionMessageBlock } from "@socialgouv/cdtn-types"; import { gqlClient } from "@shared/utils"; import { context } from "../context"; diff --git a/targets/export-elasticsearch/src/ingester/contributions/generate.ts b/targets/export-elasticsearch/src/ingester/contributions/generate.ts index 2a0469a86..043da3339 100644 --- a/targets/export-elasticsearch/src/ingester/contributions/generate.ts +++ b/targets/export-elasticsearch/src/ingester/contributions/generate.ts @@ -1,6 +1,6 @@ import { AgreementDoc, - Breadcrumbs, + Breadcrumb, ContributionConventionnelInfos, ContributionDocumentJson, ContributionElasticDocument, @@ -8,7 +8,7 @@ import { ContributionHighlight, DocumentElasticWithSource, ContributionLinkedContent, -} from "@shared/types"; +} from "@socialgouv/cdtn-types"; import { generateMetadata } from "./generateMetadata"; import { isGenericContribution, isGenericNotCdtContribution } from "./helpers"; import { getCcSupported } from "./getCcSupported"; @@ -37,7 +37,7 @@ export async function generateContributions( getBreadcrumbs: GetBreadcrumbsFn ): Promise { const breadcrumbsOfRootContributionsPerIndex = contributions.reduce( - (state: Record, contribution) => { + (state: Record, contribution) => { if (contribution.breadcrumbs.length > 0) { state[contribution.questionIndex] = contribution.breadcrumbs; } diff --git a/targets/export-elasticsearch/src/ingester/contributions/generateContent.ts b/targets/export-elasticsearch/src/ingester/contributions/generateContent.ts index d6bf896d1..d60f8495e 100644 --- a/targets/export-elasticsearch/src/ingester/contributions/generateContent.ts +++ b/targets/export-elasticsearch/src/ingester/contributions/generateContent.ts @@ -2,7 +2,7 @@ import { ContributionContent, ContributionDocumentJson, DocumentElasticWithSource, -} from "@shared/types"; +} from "@socialgouv/cdtn-types"; import { fetchFicheSp } from "./fetchFicheSp"; export const generateContent = async ( diff --git a/targets/export-elasticsearch/src/ingester/contributions/generateLinkedContent.ts b/targets/export-elasticsearch/src/ingester/contributions/generateLinkedContent.ts index cf9e589ee..2bf99886f 100644 --- a/targets/export-elasticsearch/src/ingester/contributions/generateLinkedContent.ts +++ b/targets/export-elasticsearch/src/ingester/contributions/generateLinkedContent.ts @@ -1,6 +1,6 @@ import { GetBreadcrumbsFn } from "../breadcrumbs"; import { fetchLinkedContent } from "./fetchLinkedContent"; -import { Breadcrumbs, ExportFullLinkedContent } from "@shared/types"; +import { Breadcrumb, ExportFullLinkedContent } from "@socialgouv/cdtn-types"; import { ContributionElasticDocumentLightRelatedContent } from "./generate"; import { isReferencingGenericContribution } from "./helpers"; @@ -8,7 +8,7 @@ export const generateLinkedContent = async ( allGeneratedContributions: ContributionElasticDocumentLightRelatedContent[], currentContribution: ContributionElasticDocumentLightRelatedContent, getBreadcrumbs: GetBreadcrumbsFn, - breadcrumbsOfRootContributionsPerIndex: Record + breadcrumbsOfRootContributionsPerIndex: Record ): Promise => { const linkedContentPromises = currentContribution.linkedContent.map( async (content) => { diff --git a/targets/export-elasticsearch/src/ingester/contributions/generateMessageBlock.ts b/targets/export-elasticsearch/src/ingester/contributions/generateMessageBlock.ts index 36f1cff7e..836e2ecbd 100644 --- a/targets/export-elasticsearch/src/ingester/contributions/generateMessageBlock.ts +++ b/targets/export-elasticsearch/src/ingester/contributions/generateMessageBlock.ts @@ -1,7 +1,7 @@ import { ContributionDocumentJson, DocumentElasticWithSource, -} from "@shared/types"; +} from "@socialgouv/cdtn-types"; import { fetchMessageBlock } from "./fetchMessageBlock"; import { fetchAgreementMessage } from "./fetchAgreementMessage"; diff --git a/targets/export-elasticsearch/src/ingester/contributions/generateMetadata.ts b/targets/export-elasticsearch/src/ingester/contributions/generateMetadata.ts index 8bac914cc..7abdbb335 100644 --- a/targets/export-elasticsearch/src/ingester/contributions/generateMetadata.ts +++ b/targets/export-elasticsearch/src/ingester/contributions/generateMetadata.ts @@ -2,7 +2,7 @@ import { ContributionDocumentJson, ContributionMetadata, DocumentElasticWithSource, -} from "@shared/types"; +} from "@socialgouv/cdtn-types"; export const generateMetadata = ( contribution: DocumentElasticWithSource diff --git a/targets/export-elasticsearch/src/ingester/contributions/generateReferences.ts b/targets/export-elasticsearch/src/ingester/contributions/generateReferences.ts index 85ed75333..72ffc302c 100644 --- a/targets/export-elasticsearch/src/ingester/contributions/generateReferences.ts +++ b/targets/export-elasticsearch/src/ingester/contributions/generateReferences.ts @@ -2,7 +2,7 @@ import { ContributionRef, ContributionDocumentJson, DocumentElasticWithSource, -} from "@shared/types"; +} from "@socialgouv/cdtn-types"; import { isReferencingGenericContribution } from "./helpers"; export const generateReferences = ( diff --git a/targets/export-elasticsearch/src/ingester/contributions/getCcInfos.ts b/targets/export-elasticsearch/src/ingester/contributions/getCcInfos.ts index cfad40884..bf1d4cca5 100644 --- a/targets/export-elasticsearch/src/ingester/contributions/getCcInfos.ts +++ b/targets/export-elasticsearch/src/ingester/contributions/getCcInfos.ts @@ -3,7 +3,7 @@ import { ContributionConventionnelInfos, ContributionDocumentJson, DocumentElasticWithSource, -} from "@shared/types"; +} from "@socialgouv/cdtn-types"; export const getCcInfos = ( ccns: DocumentElasticWithSource[], diff --git a/targets/export-elasticsearch/src/ingester/contributions/getCcSupported.ts b/targets/export-elasticsearch/src/ingester/contributions/getCcSupported.ts index 84c3ea362..d8940c8c8 100644 --- a/targets/export-elasticsearch/src/ingester/contributions/getCcSupported.ts +++ b/targets/export-elasticsearch/src/ingester/contributions/getCcSupported.ts @@ -1,7 +1,7 @@ import { ContributionDocumentJson, DocumentElasticWithSource, -} from "@shared/types"; +} from "@socialgouv/cdtn-types"; // TODO: à enlever lorsqu'on supporte la nouvelle CC de la métallurgie (3248) const OLD_METALLURGIE_INDEX_4 = [ diff --git a/targets/export-elasticsearch/src/ingester/contributions/helpers.ts b/targets/export-elasticsearch/src/ingester/contributions/helpers.ts index 7cb36b966..481e48dd9 100644 --- a/targets/export-elasticsearch/src/ingester/contributions/helpers.ts +++ b/targets/export-elasticsearch/src/ingester/contributions/helpers.ts @@ -2,7 +2,7 @@ import { ContributionContentType, ContributionDocumentJson, DocumentElasticWithSource, -} from "@shared/types"; +} from "@socialgouv/cdtn-types"; export const isGenericContribution = ( contrib: DocumentElasticWithSource diff --git a/targets/export-elasticsearch/src/ingester/exportStatus/updateExportEsStatusWithDocumentsCount.ts b/targets/export-elasticsearch/src/ingester/exportStatus/updateExportEsStatusWithDocumentsCount.ts index a5e9b2008..a1c7930c9 100644 --- a/targets/export-elasticsearch/src/ingester/exportStatus/updateExportEsStatusWithDocumentsCount.ts +++ b/targets/export-elasticsearch/src/ingester/exportStatus/updateExportEsStatusWithDocumentsCount.ts @@ -1,6 +1,6 @@ import { gqlClient, logger } from "@shared/utils"; import { context } from "../context"; -import { ExportEsStatus } from "@shared/types"; +import { ExportEsStatus } from "@socialgouv/cdtn-types"; const updateExportEsStatusQuery = ` mutation updateOneExportEsStatus($id: uuid!, $documentsCount: jsonb) { diff --git a/targets/export-elasticsearch/src/ingester/informations/__tests__/getContentBlockIds.test.ts b/targets/export-elasticsearch/src/ingester/informations/__tests__/getContentBlockIds.test.ts index ebc22c465..9d87c83ff 100644 --- a/targets/export-elasticsearch/src/ingester/informations/__tests__/getContentBlockIds.test.ts +++ b/targets/export-elasticsearch/src/ingester/informations/__tests__/getContentBlockIds.test.ts @@ -1,33 +1,31 @@ -import { - BlockDisplayMode, - ContentBlockContent, - ContentBlockContentItem, - ContentType, -} from "@socialgouv/cdtn-utils"; import { getContentBlockIds } from "../getContentBlockIds"; -import { BaseContentPart, CONTENT_TYPE } from "@shared/types"; +import { + EditorialContentBaseContentPart, + EditorialContentType, + EditorialContentBlockDisplayMode, + EditorialContentPart, + ContentItem, +} from "@socialgouv/cdtn-types"; describe("function getContentBlockIds", () => { - const mockedContent: BaseContentPart = { + const mockedContent: EditorialContentBaseContentPart = { blocks: [], name: "name", references: [], title: "title", }; - const mockedBlock: ContentBlockContent = { - type: ContentType.content, - blockDisplayMode: BlockDisplayMode.line, + const mockedBlock: EditorialContentPart = { + type: EditorialContentType.content, + blockDisplayMode: EditorialContentBlockDisplayMode.line, contents: [], title: "title", }; - const mockedContentItem: ContentBlockContentItem = { + const mockedContentItem: ContentItem = { cdtnId: "cdtnId", title: "title", - description: "description", - slug: "slug", source: "source", }; - let props: BaseContentPart[]; + let props: EditorialContentBaseContentPart[]; let result: string[]; beforeEach(() => { result = getContentBlockIds(props); @@ -42,7 +40,7 @@ describe("function getContentBlockIds", () => { { ...mockedContentItem, cdtnId: "id1" }, { ...mockedContentItem, cdtnId: "id2" }, ], - type: CONTENT_TYPE.content, + type: EditorialContentType.content, }, ]; }); @@ -61,7 +59,7 @@ describe("function getContentBlockIds", () => { { ...mockedContentItem, cdtnId: "id1" }, { ...mockedContentItem, cdtnId: "id3" }, ], - type: CONTENT_TYPE.content, + type: EditorialContentType.content, }, ]; }); diff --git a/targets/export-elasticsearch/src/ingester/informations/__tests__/mergeRelatedDocumentsToEditorialContents.test.ts b/targets/export-elasticsearch/src/ingester/informations/__tests__/mergeRelatedDocumentsToEditorialContents.test.ts index 861444273..18707e857 100644 --- a/targets/export-elasticsearch/src/ingester/informations/__tests__/mergeRelatedDocumentsToEditorialContents.test.ts +++ b/targets/export-elasticsearch/src/ingester/informations/__tests__/mergeRelatedDocumentsToEditorialContents.test.ts @@ -1,10 +1,10 @@ import { RelatedDocuments } from "../../common/populateRelatedDocuments"; import { mergeRelatedDocumentsToEditorialContents } from "../mergeRelatedDocumentsToEditorialContents"; import { - CONTENT_TYPE, + EditorialContentType, DocumentElasticWithSource, EditorialContentDoc, -} from "@shared/types"; +} from "@socialgouv/cdtn-types"; describe("mergeRelatedDocumentsToEditorialContents", () => { const editorialContents = [ @@ -15,7 +15,7 @@ describe("mergeRelatedDocumentsToEditorialContents", () => { id: "1", blocks: [ { - type: CONTENT_TYPE.content, + type: EditorialContentType.content, contents: [{ cdtnId: "id1" }, { cdtnId: "id2" }], }, ], @@ -28,7 +28,7 @@ describe("mergeRelatedDocumentsToEditorialContents", () => { id: "1", title: "Related Document 1", breadcrumbs: [], - source: "", + source: "code_du_travail", cdtnId: "", slug: "", description: "", @@ -37,7 +37,7 @@ describe("mergeRelatedDocumentsToEditorialContents", () => { id: "2", title: "Related Document 2", breadcrumbs: [], - source: "", + source: "code_du_travail", cdtnId: "", slug: "", description: "", @@ -58,13 +58,13 @@ describe("mergeRelatedDocumentsToEditorialContents", () => { id: "1", blocks: [ { - type: CONTENT_TYPE.content, + type: EditorialContentType.content, contents: [ { id: "1", title: "Related Document 1", breadcrumbs: [], - source: "", + source: "code_du_travail", cdtnId: "", slug: "", description: "", @@ -73,7 +73,7 @@ describe("mergeRelatedDocumentsToEditorialContents", () => { id: "2", title: "Related Document 2", breadcrumbs: [], - source: "", + source: "code_du_travail", cdtnId: "", slug: "", description: "", @@ -88,12 +88,12 @@ describe("mergeRelatedDocumentsToEditorialContents", () => { }); it("should throw an error if no related document is found", () => { - const invalidRelatedDocuments = { + const invalidRelatedDocuments: RelatedDocuments = { id1: { id: "1", title: "Related Document 1", breadcrumbs: [], - source: "", + source: "code_du_travail", cdtnId: "", slug: "", description: "", diff --git a/targets/export-elasticsearch/src/ingester/informations/generate.ts b/targets/export-elasticsearch/src/ingester/informations/generate.ts index f64784238..daf8ae158 100644 --- a/targets/export-elasticsearch/src/ingester/informations/generate.ts +++ b/targets/export-elasticsearch/src/ingester/informations/generate.ts @@ -1,4 +1,7 @@ -import { DocumentElasticWithSource, EditorialContentDoc } from "@shared/types"; +import { + DocumentElasticWithSource, + EditorialContentDoc, +} from "@socialgouv/cdtn-types"; import { markdownTransform } from "./markdown"; import { getRelatedIdsDocuments } from "./getRelatedIdsDocuments"; diff --git a/targets/export-elasticsearch/src/ingester/informations/getContentBlockIds.ts b/targets/export-elasticsearch/src/ingester/informations/getContentBlockIds.ts index 4a46f66b4..e5d761c6a 100644 --- a/targets/export-elasticsearch/src/ingester/informations/getContentBlockIds.ts +++ b/targets/export-elasticsearch/src/ingester/informations/getContentBlockIds.ts @@ -1,11 +1,16 @@ -import { BaseContentPart, CONTENT_TYPE } from "@shared/types"; +import { + EditorialContentBaseContentPart, + EditorialContentType, +} from "@socialgouv/cdtn-types"; -export const getContentBlockIds = (data: BaseContentPart[]): string[] => { +export const getContentBlockIds = ( + data: EditorialContentBaseContentPart[] +): string[] => { return data.reduce((idsAcc: string[], content) => { content.blocks = content.blocks ?? []; return idsAcc.concat( content.blocks.flatMap((block) => { - return block.type === CONTENT_TYPE.content + return block.type === EditorialContentType.content ? block.contents .map(({ cdtnId }) => cdtnId) .filter((cdtnId: string) => idsAcc.indexOf(cdtnId) === -1) ?? [] diff --git a/targets/export-elasticsearch/src/ingester/informations/getRelatedIdsDocuments.ts b/targets/export-elasticsearch/src/ingester/informations/getRelatedIdsDocuments.ts index c1d6f6422..583afba1d 100644 --- a/targets/export-elasticsearch/src/ingester/informations/getRelatedIdsDocuments.ts +++ b/targets/export-elasticsearch/src/ingester/informations/getRelatedIdsDocuments.ts @@ -1,4 +1,7 @@ -import { DocumentElasticWithSource, EditorialContentDoc } from "@shared/types"; +import { + DocumentElasticWithSource, + EditorialContentDoc, +} from "@socialgouv/cdtn-types"; import { getContentBlockIds } from "./getContentBlockIds"; export const getRelatedIdsDocuments = ( diff --git a/targets/export-elasticsearch/src/ingester/informations/markdown.ts b/targets/export-elasticsearch/src/ingester/informations/markdown.ts index 212c8f733..2ecb48574 100644 --- a/targets/export-elasticsearch/src/ingester/informations/markdown.ts +++ b/targets/export-elasticsearch/src/ingester/informations/markdown.ts @@ -1,7 +1,7 @@ import type { DocumentElasticWithSource, EditorialContentDoc, -} from "@shared/types"; +} from "@socialgouv/cdtn-types"; import htmlAstToAnotherHtmlAst from "rehype-raw"; import htmlAstStringify from "rehype-stringify"; import markdownToMardownAst from "remark-parse"; diff --git a/targets/export-elasticsearch/src/ingester/informations/mergeRelatedDocumentsToEditorialContents.ts b/targets/export-elasticsearch/src/ingester/informations/mergeRelatedDocumentsToEditorialContents.ts index ee252c4ab..d1d522b2a 100644 --- a/targets/export-elasticsearch/src/ingester/informations/mergeRelatedDocumentsToEditorialContents.ts +++ b/targets/export-elasticsearch/src/ingester/informations/mergeRelatedDocumentsToEditorialContents.ts @@ -1,8 +1,8 @@ import { - CONTENT_TYPE, + EditorialContentType, DocumentElasticWithSource, EditorialContentDoc, -} from "@shared/types"; +} from "@socialgouv/cdtn-types"; import { RelatedDocuments } from "../common/populateRelatedDocuments"; export const mergeRelatedDocumentsToEditorialContents = ( @@ -12,7 +12,7 @@ export const mergeRelatedDocumentsToEditorialContents = ( const augmentedEditorialContents = editorialContents.map((document) => { const contents = document.contents.map((content) => { const blocks = content.blocks.map((block) => { - if (block.type !== CONTENT_TYPE.content) return block; + if (block.type !== EditorialContentType.content) return block; const contents = block.contents.flatMap((blockContent) => { const contentFound = relatedDocuments[blockContent.cdtnId]; if (!contentFound) { diff --git a/targets/export-elasticsearch/src/ingester/prequalified/generatePrequalified.ts b/targets/export-elasticsearch/src/ingester/prequalified/generatePrequalified.ts index b3e2b091c..a7e7c7ac8 100644 --- a/targets/export-elasticsearch/src/ingester/prequalified/generatePrequalified.ts +++ b/targets/export-elasticsearch/src/ingester/prequalified/generatePrequalified.ts @@ -1,6 +1,9 @@ import { SOURCES } from "@socialgouv/cdtn-sources"; import { fetchPrequalified } from "./fetchPrequalified"; -import { PrequalifiedElasticDocument } from "@shared/types"; +import { + PrequalifiedElasticDocument, + RelatedDocument, +} from "@socialgouv/cdtn-types"; import { removeUndefinedKeys } from "../utils/removeUndefinedKeys"; import { GetBreadcrumbsFn } from "../breadcrumbs"; @@ -33,7 +36,7 @@ export const generatePrequalified = async ( breadcrumbs: getBreadcrumbs(document.cdtnId), url: document.document.url, // pour les outils externes action: document.document.action, // pour les outils (interne/externe) - }) + } as RelatedDocument) ), })); }; diff --git a/targets/export-elasticsearch/src/ingester/types/Glossary.ts b/targets/export-elasticsearch/src/ingester/types/Glossary.ts index 39a16c6a8..ba9c641a0 100644 --- a/targets/export-elasticsearch/src/ingester/types/Glossary.ts +++ b/targets/export-elasticsearch/src/ingester/types/Glossary.ts @@ -1,4 +1,4 @@ -import { Breadcrumbs } from "@shared/types"; +import { SourceRoute } from "@socialgouv/cdtn-sources"; import type { GraphQLResponseRoot } from "./GraphQL"; export type DocumentBySourceResponse = GraphQLResponseRoot; @@ -29,7 +29,7 @@ export interface Document { cdtnId: string; title: string; slug: string; - source: string; + source: SourceRoute; text: string; isPublished: boolean; isSearchable: boolean; @@ -37,22 +37,6 @@ export interface Document { document: unknown; } -export type DocumentElasticWithSource = DocumentElastic & T; - -export interface DocumentElastic { - id: string; - cdtnId: string; - breadcrumbs: Breadcrumbs[]; - title: string; - slug: string; - source: string; - text: string; - isPublished: boolean; - excludeFromSearch: boolean; - metaDescription: string; - refs: DocumentRef[]; -} - export type AggregateDocumentBySource = GraphQLResponseRoot<{ documents_aggregate: { aggregate: { @@ -61,16 +45,6 @@ export type AggregateDocumentBySource = GraphQLResponseRoot<{ }; }>; -export interface DocumentRef { - breadcrumbs: Breadcrumbs[]; - cdtnId: string; - description: string; - slug: string; - source: string; - title: string; - url: string | undefined; -} - export interface RequestBySourceWithRelationsData { documents: DocumentWithRelation[]; } @@ -80,7 +54,7 @@ export interface DocumentWithRelation { cdtnId: string; title: string; slug: string; - source: string; + source: SourceRoute; text: string; isPublished: boolean; isSearchable: boolean; @@ -97,7 +71,7 @@ export interface Relation { export interface RelationContent { cdtnId: string; slug: string; - source: string; + source: SourceRoute; title: string; document: unknown; } diff --git a/targets/export-elasticsearch/src/repositories/s3.ts b/targets/export-elasticsearch/src/repositories/s3.ts index b23347757..cf6db51c6 100644 --- a/targets/export-elasticsearch/src/repositories/s3.ts +++ b/targets/export-elasticsearch/src/repositories/s3.ts @@ -9,7 +9,7 @@ import axios from "axios"; import { inject, injectable } from "inversify"; import { diff, name } from "../utils"; -import { Environment } from "@shared/types"; +import { Environment } from "@socialgouv/cdtn-types"; import { logger } from "@shared/utils"; const mime = require("mime-types"); diff --git a/targets/export-elasticsearch/src/repositories/status.ts b/targets/export-elasticsearch/src/repositories/status.ts index ece8d962c..ff6a4171f 100644 --- a/targets/export-elasticsearch/src/repositories/status.ts +++ b/targets/export-elasticsearch/src/repositories/status.ts @@ -1,5 +1,9 @@ import { gqlClient } from "@shared/utils"; -import type { Environment, ExportEsStatus, Status } from "@shared/types"; +import type { + Environment, + ExportEsStatus, + Status, +} from "@socialgouv/cdtn-types"; import { logger } from "@shared/utils"; import { injectable } from "inversify"; diff --git a/targets/export-elasticsearch/src/services/__test__/export.test.ts b/targets/export-elasticsearch/src/services/__test__/export.test.ts index 89ca78b71..b2f0fc09e 100644 --- a/targets/export-elasticsearch/src/services/__test__/export.test.ts +++ b/targets/export-elasticsearch/src/services/__test__/export.test.ts @@ -1,4 +1,4 @@ -import { Environment, Status } from "@shared/types"; +import { Environment, Status } from "@socialgouv/cdtn-types"; import timekeeper from "timekeeper"; import { ExportRepository } from "../../repositories"; diff --git a/targets/export-elasticsearch/src/services/__test__/fake/export.ts b/targets/export-elasticsearch/src/services/__test__/fake/export.ts index 395c766e0..1705d4f01 100644 --- a/targets/export-elasticsearch/src/services/__test__/fake/export.ts +++ b/targets/export-elasticsearch/src/services/__test__/fake/export.ts @@ -1,5 +1,5 @@ -import type { ExportEsStatus } from "@shared/types"; -import { Environment, Status } from "@shared/types"; +import type { ExportEsStatus } from "@socialgouv/cdtn-types"; +import { Environment, Status } from "@socialgouv/cdtn-types"; import { injectable } from "inversify"; import { wait } from "../../../utils"; diff --git a/targets/export-elasticsearch/src/services/agreements.ts b/targets/export-elasticsearch/src/services/agreements.ts index 037346dc3..9c9dd2ce0 100644 --- a/targets/export-elasticsearch/src/services/agreements.ts +++ b/targets/export-elasticsearch/src/services/agreements.ts @@ -4,7 +4,7 @@ import { S3Repository } from "../repositories"; import { getName, name } from "../utils"; import { AgreementsRepository } from "../repositories/agreements"; import { logger } from "@shared/utils"; -import { Environment } from "@shared/types"; +import { Environment } from "@socialgouv/cdtn-types"; @injectable() @name("AgreementsService") diff --git a/targets/export-elasticsearch/src/services/copy.ts b/targets/export-elasticsearch/src/services/copy.ts index d77e441cd..94e6e1bbf 100644 --- a/targets/export-elasticsearch/src/services/copy.ts +++ b/targets/export-elasticsearch/src/services/copy.ts @@ -2,7 +2,7 @@ import { inject, injectable } from "inversify"; import { S3Repository } from "../repositories"; import { getName, name } from "../utils"; -import { Environment } from "@shared/types"; +import { Environment } from "@socialgouv/cdtn-types"; import { logger } from "@shared/utils"; @injectable() diff --git a/targets/export-elasticsearch/src/services/export.ts b/targets/export-elasticsearch/src/services/export.ts index 31a2b5d14..de6c74d4d 100644 --- a/targets/export-elasticsearch/src/services/export.ts +++ b/targets/export-elasticsearch/src/services/export.ts @@ -1,5 +1,5 @@ -import type { ExportEsStatus } from "@shared/types"; -import { Environment, Status } from "@shared/types"; +import type { ExportEsStatus } from "@socialgouv/cdtn-types"; +import { Environment, Status } from "@socialgouv/cdtn-types"; import { logger } from "@shared/utils"; import { randomUUID } from "crypto"; import { inject, injectable } from "inversify"; diff --git a/targets/export-elasticsearch/src/services/sitemap.ts b/targets/export-elasticsearch/src/services/sitemap.ts index d20dab8bc..0293947e2 100644 --- a/targets/export-elasticsearch/src/services/sitemap.ts +++ b/targets/export-elasticsearch/src/services/sitemap.ts @@ -2,7 +2,7 @@ import { inject, injectable } from "inversify"; import { S3Repository } from "../repositories"; import { getName, name } from "../utils"; -import { Environment } from "@shared/types"; +import { Environment } from "@socialgouv/cdtn-types"; import { logger } from "@shared/utils"; @injectable() diff --git a/targets/frontend/.gitignore b/targets/frontend/.gitignore index 52e5df3f4..f64915803 100644 --- a/targets/frontend/.gitignore +++ b/targets/frontend/.gitignore @@ -6,3 +6,4 @@ data/* node_modules .env .env.development +*.tsbuildinfo diff --git a/targets/frontend/Dockerfile b/targets/frontend/Dockerfile index 53aa25330..0cd95fd16 100644 --- a/targets/frontend/Dockerfile +++ b/targets/frontend/Dockerfile @@ -14,7 +14,7 @@ RUN --mount=type=secret,id=npmTiptapToken,target=/secrets/npmTiptapToken \ FROM deps AS build-types COPY shared/types ./shared/types/ -RUN yarn workspace @shared/types build +RUN yarn workspace @socialgouv/cdtn-types build FROM deps AS build-utils COPY --from=build-types /app/shared/types /app/shared/types diff --git a/targets/frontend/package.json b/targets/frontend/package.json index 6015febf0..848dd73cb 100644 --- a/targets/frontend/package.json +++ b/targets/frontend/package.json @@ -68,7 +68,7 @@ "zod": "3.21.4" }, "devDependencies": { - "@shared/types": "workspace:^", + "@socialgouv/cdtn-types": "workspace:^", "@testing-library/jest-dom": "^5.16.5", "@testing-library/react": "^14.0.0", "@testing-library/user-event": "^14.5.1", @@ -99,6 +99,7 @@ "start": "next start", "predev": "only-include-used-icons", "prebuild": "only-include-used-icons", - "test": "jest --silent" + "test": "jest --silent", + "type-check": "tsc --noEmit" } } diff --git a/targets/frontend/src/components/alerts/AlertTitle.tsx b/targets/frontend/src/components/alerts/AlertTitle.tsx index a319480d7..aaa556045 100644 --- a/targets/frontend/src/components/alerts/AlertTitle.tsx +++ b/targets/frontend/src/components/alerts/AlertTitle.tsx @@ -1,4 +1,4 @@ -import { AlertChanges } from "@shared/types"; +import { AlertChanges } from "@socialgouv/cdtn-types"; import React, { useState } from "react"; import { IoIosLink, IoMdChatbubbles } from "react-icons/io"; import { Box, Stack } from "@mui/material"; diff --git a/targets/frontend/src/components/changes/ChangeGroup.tsx b/targets/frontend/src/components/changes/ChangeGroup.tsx index f815f92cc..cbeec3572 100644 --- a/targets/frontend/src/components/changes/ChangeGroup.tsx +++ b/targets/frontend/src/components/changes/ChangeGroup.tsx @@ -8,7 +8,7 @@ import type { DocumentReferences, FicheTravailEmploiInfo, FicheVddInfo, -} from "@shared/types"; +} from "@socialgouv/cdtn-types"; import slugify from "@socialgouv/cdtn-slugify"; import { getRouteBySource } from "@socialgouv/cdtn-sources"; import { Badge, Box, Card, List, ListItem } from "@mui/material"; diff --git a/targets/frontend/src/components/changes/ChangesFiche.tsx b/targets/frontend/src/components/changes/ChangesFiche.tsx index 750757e8a..e1a5bab79 100644 --- a/targets/frontend/src/components/changes/ChangesFiche.tsx +++ b/targets/frontend/src/components/changes/ChangesFiche.tsx @@ -1,5 +1,5 @@ import { Chip } from "@mui/material"; -import { DocumentInfoWithCdtnRef } from "@shared/types"; +import { DocumentInfoWithCdtnRef } from "@socialgouv/cdtn-types"; import slugify from "@socialgouv/cdtn-slugify"; import { getRouteBySource } from "@socialgouv/cdtn-sources"; import { theme } from "src/theme"; diff --git a/targets/frontend/src/components/contributions/questionList/__mocks__/QuestionList.query.ts b/targets/frontend/src/components/contributions/questionList/__mocks__/QuestionList.query.ts index d089db9fd..28c64d7b5 100644 --- a/targets/frontend/src/components/contributions/questionList/__mocks__/QuestionList.query.ts +++ b/targets/frontend/src/components/contributions/questionList/__mocks__/QuestionList.query.ts @@ -10,7 +10,7 @@ const createAnswerStatus = (status: Status): AnswerStatus => { user: { name: "user1", id: "1", - created_at: new Date(), + created_at: new Date().toString(), email: "user1@user.com", }, }; @@ -19,27 +19,13 @@ const createAnswerStatus = (status: Status): AnswerStatus => { export const mock: QuestionListQueryResult = { rows: [ { - answers: [ - { - status: createAnswerStatus("TODO"), - }, - { - status: createAnswerStatus("REDACTING"), - }, - ], + answers: [createAnswerStatus("TODO"), createAnswerStatus("REDACTING")], content: "question1", id: "questionId1", order: 1, }, { - answers: [ - { - status: createAnswerStatus("TODO"), - }, - { - status: createAnswerStatus("TODO"), - }, - ], + answers: [createAnswerStatus("TODO"), createAnswerStatus("TODO")], content: "question2", id: "questionId2", order: 2, diff --git a/targets/frontend/src/components/editorialContent/EditorialContent.tsx b/targets/frontend/src/components/editorialContent/EditorialContent.tsx index c42d29989..807341154 100644 --- a/targets/frontend/src/components/editorialContent/EditorialContent.tsx +++ b/targets/frontend/src/components/editorialContent/EditorialContent.tsx @@ -7,7 +7,7 @@ import React, { useEffect, useState } from "react"; import { Controller, FormProvider, useForm } from "react-hook-form"; import { IoMdCheckmark } from "react-icons/io"; -import { BaseContentPart, Content, SectionDisplayMode } from "../../types"; +import { Content } from "../../types"; import { Button } from "../button"; import { MarkdownLink } from "../MarkdownLink"; import { ContentSections } from "./ContentSections"; @@ -23,6 +23,10 @@ import { import { FormRadioGroup, FormTextField } from "../forms"; import { SnackBar } from "../utils/SnackBar"; import { theme } from "src/theme"; +import { + EditorialContentBaseContentPart, + EditorialSectionDisplayMode, +} from "@socialgouv/cdtn-types"; const addComputedFields = (onSubmit: (content: Partial) => void) => @@ -33,15 +37,17 @@ const addComputedFields = link.type = SOURCES.EXTERNALS; }); }); - data.document?.contents?.forEach((content: BaseContentPart) => { - content.name = slugify(content.title as string); - content.references?.forEach((block) => { - block.links.forEach((reference) => { - reference.id = slugify(reference.title); - reference.type = SOURCES.EXTERNALS; + data.document?.contents?.forEach( + (content: EditorialContentBaseContentPart) => { + content.name = slugify(content.title as string); + content.references?.forEach((block) => { + block.links.forEach((reference) => { + reference.id = slugify(reference.title); + reference.type = SOURCES.EXTERNALS; + }); }); - }); - }); + } + ); onSubmit(data); }; @@ -176,11 +182,11 @@ const EditorialContentForm = ({ options={[ { label: "Accordéon", - value: SectionDisplayMode.accordion, + value: EditorialSectionDisplayMode.accordion, }, { label: "Onglet", - value: SectionDisplayMode.tab, + value: EditorialSectionDisplayMode.tab, }, ]} /> diff --git a/targets/frontend/src/components/export-es/EnvironmentBadge.tsx b/targets/frontend/src/components/export-es/EnvironmentBadge.tsx index 868e04cfb..af9f3cac4 100644 --- a/targets/frontend/src/components/export-es/EnvironmentBadge.tsx +++ b/targets/frontend/src/components/export-es/EnvironmentBadge.tsx @@ -1,4 +1,4 @@ -import { Environment } from "@shared/types"; +import { Environment } from "@socialgouv/cdtn-types"; import { Chip } from "@mui/material"; type EnvironmentTagProps = { diff --git a/targets/frontend/src/components/export-es/InformationsDialog.tsx b/targets/frontend/src/components/export-es/InformationsDialog.tsx index 424b12c0f..885e208f6 100644 --- a/targets/frontend/src/components/export-es/InformationsDialog.tsx +++ b/targets/frontend/src/components/export-es/InformationsDialog.tsx @@ -13,7 +13,7 @@ import { TableHead, TableCell, } from "@mui/material"; -import { ExportEsStatus } from "@shared/types"; +import { ExportEsStatus } from "@socialgouv/cdtn-types"; import { TableCellDiff } from "./TableCellDiff"; type Props = { diff --git a/targets/frontend/src/components/export-es/Status.tsx b/targets/frontend/src/components/export-es/Status.tsx index e1ff30401..0bb298f79 100644 --- a/targets/frontend/src/components/export-es/Status.tsx +++ b/targets/frontend/src/components/export-es/Status.tsx @@ -1,4 +1,4 @@ -import { Status as StatusType } from "@shared/types"; +import { Status as StatusType } from "@socialgouv/cdtn-types"; import { Box, CircularProgress, diff --git a/targets/frontend/src/components/export-es/TriggerButton.tsx b/targets/frontend/src/components/export-es/TriggerButton.tsx index 61165f919..62b5b2586 100644 --- a/targets/frontend/src/components/export-es/TriggerButton.tsx +++ b/targets/frontend/src/components/export-es/TriggerButton.tsx @@ -1,4 +1,4 @@ -import { Status } from "@shared/types"; +import { Status } from "@socialgouv/cdtn-types"; import React, { ReactNode } from "react"; import { MdSyncProblem, MdTimelapse, MdTimerOff } from "react-icons/md"; import { Chip } from "@mui/material"; diff --git a/targets/frontend/src/components/home/DuplicateItems.tsx b/targets/frontend/src/components/home/DuplicateItems.tsx index b6c478b3c..7464355b7 100644 --- a/targets/frontend/src/components/home/DuplicateItems.tsx +++ b/targets/frontend/src/components/home/DuplicateItems.tsx @@ -1,4 +1,4 @@ -import { HasuraDocument } from "@shared/types"; +import { HasuraDocument } from "@socialgouv/cdtn-types"; import { SOURCES } from "@socialgouv/cdtn-sources"; import Link from "next/link"; import React, { useEffect, useState } from "react"; @@ -40,7 +40,7 @@ export type DuplicateContentResult = { export type DuplicateDocument = { relations: Relation[]; }; -type DocumentRef = Pick; +type DocumentRef = Pick, "source" | "cdtn_id" | "title">; export type Relation = { type: string; data: Data; diff --git a/targets/frontend/src/components/home/InvisibleLinkedDocument.tsx b/targets/frontend/src/components/home/InvisibleLinkedDocument.tsx index e3d6c0b07..841f24717 100644 --- a/targets/frontend/src/components/home/InvisibleLinkedDocument.tsx +++ b/targets/frontend/src/components/home/InvisibleLinkedDocument.tsx @@ -1,4 +1,4 @@ -import { HasuraDocument } from "@shared/types"; +import { HasuraDocument } from "@socialgouv/cdtn-types"; import { gql, useQuery } from "urql"; import Link from "next/link"; import { Card, CardContent, Typography } from "@mui/material"; @@ -44,9 +44,12 @@ export const getGhostDocumentQuery = gql` } `; -export type ParentRef = Pick; +export type ParentRef = Pick< + HasuraDocument, + "cdtn_id" | "title" | "source" +>; export type DocumentRef = Pick< - HasuraDocument, + HasuraDocument, | "cdtn_id" | "initial_id" | "title" diff --git a/targets/frontend/src/hooks/exportEs.ts b/targets/frontend/src/hooks/exportEs.ts index b222b2572..0441cd2e2 100644 --- a/targets/frontend/src/hooks/exportEs.ts +++ b/targets/frontend/src/hooks/exportEs.ts @@ -1,4 +1,4 @@ -import { Environment, ExportEsStatus, Status } from "@shared/types"; +import { Environment, ExportEsStatus, Status } from "@socialgouv/cdtn-types"; import { Session } from "next-auth"; import { useState } from "react"; import { serializeError } from "serialize-error"; diff --git a/targets/frontend/src/lib/references/__mocks__/fetchKaliReferences.ts b/targets/frontend/src/lib/references/__mocks__/fetchKaliReferences.ts index 44680f8ec..86de22006 100644 --- a/targets/frontend/src/lib/references/__mocks__/fetchKaliReferences.ts +++ b/targets/frontend/src/lib/references/__mocks__/fetchKaliReferences.ts @@ -3,7 +3,7 @@ import { KaliReference } from "../../../components/contributions"; export async function fetchKaliReferences( props: Omit -): Promise { +): Promise[]> { return Promise.resolve([ { agreementId: "0001", diff --git a/targets/frontend/src/modules/contribution/__tests__/mapContributionToDocument.test.ts b/targets/frontend/src/modules/contribution/__tests__/mapContributionToDocument.test.ts index daabd31ee..09e019a8f 100644 --- a/targets/frontend/src/modules/contribution/__tests__/mapContributionToDocument.test.ts +++ b/targets/frontend/src/modules/contribution/__tests__/mapContributionToDocument.test.ts @@ -1,12 +1,12 @@ import { ContributionDocumentJson, ContributionsAnswers, - Document, -} from "@shared/types"; + HasuraDocument, +} from "@socialgouv/cdtn-types"; import { mapContributionToDocument } from "../mapContributionToDocument"; describe("mapContributionToDocument", () => { - const inputDoc: Document = { + const inputDoc: HasuraDocument = { cdtn_id: "cdtn_id", initial_id: "effee3b9-84fb-4667-944b-4b1e1fd14eb5", title: @@ -130,7 +130,7 @@ describe("mapContributionToDocument", () => { message_block_generic_no_CDT: null, }; - const outputDoc: Document = { + const outputDoc: HasuraDocument = { cdtn_id: "cdtn_id", document: { content: @@ -381,7 +381,7 @@ describe("mapContributionToDocument", () => { message_block_generic_no_CDT: null, }; - const inputDoc: Document = { + const inputDoc: HasuraDocument = { cdtn_id: "cdtn_id", initial_id: "effee3b9-84fb-4667-944b-4b1e1fd14eb5", title: @@ -464,7 +464,7 @@ describe("mapContributionToDocument", () => { message_block_generic_no_CDT: null, }; - const inputDoc: Document = { + const inputDoc: HasuraDocument = { cdtn_id: "cdtn_id", initial_id: "effee3b9-84fb-4667-944b-4b1e1fd14eb5", title: diff --git a/targets/frontend/src/modules/contribution/api/repository.ts b/targets/frontend/src/modules/contribution/api/repository.ts index e772e1896..b7eec6b28 100644 --- a/targets/frontend/src/modules/contribution/api/repository.ts +++ b/targets/frontend/src/modules/contribution/api/repository.ts @@ -3,7 +3,7 @@ import { getContributionAnswerById, getGenericAnswerByQuestionId, } from "./query"; -import { ContributionsAnswers } from "@shared/types"; +import { ContributionsAnswers } from "@socialgouv/cdtn-types"; interface FetchContribPkData { contribution_answers_by_pk: ContributionsAnswers; diff --git a/targets/frontend/src/modules/contribution/getReferences.ts b/targets/frontend/src/modules/contribution/getReferences.ts index 7d8da3cf7..774ed2ae4 100644 --- a/targets/frontend/src/modules/contribution/getReferences.ts +++ b/targets/frontend/src/modules/contribution/getReferences.ts @@ -1,4 +1,4 @@ -import { ContributionRef, ContributionsAnswers } from "@shared/types"; +import { ContributionRef, ContributionsAnswers } from "@socialgouv/cdtn-types"; import { generateKaliRef, generateLegiRef } from "@shared/utils"; export function getReferences(answer: ContributionsAnswers): ContributionRef[] { diff --git a/targets/frontend/src/modules/contribution/mapContributionToDocument.ts b/targets/frontend/src/modules/contribution/mapContributionToDocument.ts index 2e06c1387..256f82004 100644 --- a/targets/frontend/src/modules/contribution/mapContributionToDocument.ts +++ b/targets/frontend/src/modules/contribution/mapContributionToDocument.ts @@ -1,8 +1,8 @@ import { ContributionDocumentJson, ContributionsAnswers, - Document, -} from "@shared/types"; + HasuraDocument, +} from "@socialgouv/cdtn-types"; import { SOURCES } from "@socialgouv/cdtn-sources"; import { getReferences } from "./getReferences"; import { generateCdtnId } from "@shared/utils"; @@ -62,11 +62,11 @@ async function getBaseDocument( export const mapContributionToDocument = async ( data: ContributionsAnswers, - document: Document | undefined, + document: HasuraDocument | undefined, fetchGenericAnswer: ( questionId: string ) => Promise> -): Promise | undefined> => { +): Promise | undefined> => { const baseDoc = await getBaseDocument(data, fetchGenericAnswer); if (!baseDoc) return; diff --git a/targets/frontend/src/modules/documents/api/documents.query.ts b/targets/frontend/src/modules/documents/api/documents.query.ts index d67c49e32..daad42ec3 100644 --- a/targets/frontend/src/modules/documents/api/documents.query.ts +++ b/targets/frontend/src/modules/documents/api/documents.query.ts @@ -1,4 +1,4 @@ -import { Document } from "@shared/types"; +import { HasuraDocument } from "@socialgouv/cdtn-types"; import { ApiClient } from "src/lib/api"; const query = `query documents($source: String!, $initialId: String) { @@ -34,7 +34,7 @@ const fetchDocumentBySlug = ` } `; -export type QueryDocument = Document; +export type QueryDocument = HasuraDocument; export type QueryDocumentResult = { documents: QueryDocument[]; @@ -53,7 +53,7 @@ export type DocumentsQueryBySlugProps = { export const queryDocument = async ( client: ApiClient, variables: DocumentsQueryProps -): Promise | undefined> => { +): Promise | undefined> => { const { data: result, error } = await client.query( query, variables @@ -70,7 +70,7 @@ export const queryDocument = async ( export const queryDocumentBySlug = async ( client: ApiClient, variables: DocumentsQueryBySlugProps -): Promise | undefined> => { +): Promise | undefined> => { const { data: result, error } = await client.query( fetchDocumentBySlug, variables diff --git a/targets/frontend/src/modules/documents/api/documents.repository.ts b/targets/frontend/src/modules/documents/api/documents.repository.ts index 2fef9ed54..cc2e60cfd 100644 --- a/targets/frontend/src/modules/documents/api/documents.repository.ts +++ b/targets/frontend/src/modules/documents/api/documents.repository.ts @@ -9,7 +9,7 @@ import { queryDocument, queryDocumentBySlug, } from "./documents.query"; -import { Document } from "@shared/types"; +import { HasuraDocument } from "@socialgouv/cdtn-types"; export class DocumentsRepository { client: ApiClient; @@ -26,11 +26,11 @@ export class DocumentsRepository { } } - async update(document: Document): Promise { + async update(document: HasuraDocument): Promise { try { const { data, error } = await this.client.mutation< any, - { upsert: Document } + { upsert: HasuraDocument } >(documentsPublishMutation, { upsert: document }); if (error) { console.log("Error while updating document: ", document.cdtn_id, error); diff --git a/targets/frontend/src/modules/documents/api/documents.service.ts b/targets/frontend/src/modules/documents/api/documents.service.ts index 91cf81bb1..9b9e31cd0 100644 --- a/targets/frontend/src/modules/documents/api/documents.service.ts +++ b/targets/frontend/src/modules/documents/api/documents.service.ts @@ -10,7 +10,7 @@ import { } from "src/modules/contribution"; import { ModelRepository } from "../../models/api"; import { Model } from "../../models"; -import { AgreementDoc, Document } from "@shared/types"; +import { AgreementDoc, HasuraDocument } from "@socialgouv/cdtn-types"; import { generateContributionSlug } from "src/modules/contribution/generateSlug"; import { AgreementRepository } from "../../agreements/api"; import { Agreement } from "../../agreements"; @@ -39,8 +39,8 @@ export class DocumentsService { private mapInformationToDocument( data: Information, - document?: Document - ): Document { + document?: HasuraDocument + ): HasuraDocument { return { cdtn_id: document?.cdtn_id ?? generateCdtnId(data.title), initial_id: data.id ?? generateInitialId(), @@ -122,8 +122,8 @@ export class DocumentsService { private mapModelToDocument( data: Model, - document?: Document - ): Document { + document?: HasuraDocument + ): HasuraDocument { return { cdtn_id: document?.cdtn_id ?? generateCdtnId(data.title), initial_id: data.id, @@ -163,8 +163,8 @@ export class DocumentsService { private mapAgreementToDocument( data: Agreement, - document?: Document - ): Document { + document?: HasuraDocument + ): HasuraDocument { return { cdtn_id: document?.cdtn_id ?? generateCdtnId(data.name), initial_id: data.id, diff --git a/targets/frontend/src/modules/export/components/ShowDocumentsToUpdateModal.tsx b/targets/frontend/src/modules/export/components/ShowDocumentsToUpdateModal.tsx index b30903b6e..5fca5339b 100644 --- a/targets/frontend/src/modules/export/components/ShowDocumentsToUpdateModal.tsx +++ b/targets/frontend/src/modules/export/components/ShowDocumentsToUpdateModal.tsx @@ -2,7 +2,7 @@ import { ConfirmModal } from "../../common/components/modals/ConfirmModal"; import DocumentList from "./document-list"; import React, { useEffect, useState } from "react"; import { useDocumentsQuery } from "../document.query"; -import { ShortDocument } from "@shared/types"; +import { ShortHasuraDocument } from "@socialgouv/cdtn-types"; export type ConfirmModalProps = { open: boolean; @@ -22,7 +22,7 @@ export function ShowDocumentsToUpdateModal({ date, }: ConfirmModalProps): JSX.Element { const [isLoadingDocs, setIsLoadingDocs] = useState(true); - const [docsToUpdate] = useState[]>([]); + const [docsToUpdate] = useState[]>([]); const docs = useDocumentsQuery({ date }); useEffect(() => { diff --git a/targets/frontend/src/modules/export/components/export.tsx b/targets/frontend/src/modules/export/components/export.tsx index e86cb7ed7..2c939038e 100644 --- a/targets/frontend/src/modules/export/components/export.tsx +++ b/targets/frontend/src/modules/export/components/export.tsx @@ -1,4 +1,4 @@ -import { Environment } from "@shared/types"; +import { Environment } from "@socialgouv/cdtn-types"; import React, { useEffect, useState } from "react"; import { EnvironmentBadge, diff --git a/targets/frontend/src/modules/export/document.query.ts b/targets/frontend/src/modules/export/document.query.ts index 66d4fd495..8ceab5810 100644 --- a/targets/frontend/src/modules/export/document.query.ts +++ b/targets/frontend/src/modules/export/document.query.ts @@ -1,6 +1,6 @@ import { useQuery } from "urql"; import { SourceRoute, SOURCES } from "@socialgouv/cdtn-sources"; -import { Document } from "@shared/types"; +import { HasuraDocument } from "@socialgouv/cdtn-types"; import { groupBy } from "graphql/jsutils/groupBy"; export const getDocumentsUpdatedAfterDateQuery = ` @@ -27,7 +27,7 @@ type DocumentWIthContentType = { document?: { contentType?: string; idcc?: string }; }; export type UpdatedDocument = Pick< - Document, + HasuraDocument, "title" | "source" | "slug" | "cdtn_id" | "initial_id" | "is_published" > & DocumentWIthContentType; diff --git a/targets/frontend/src/pages/alerts/[[...params]].tsx b/targets/frontend/src/pages/alerts/[[...params]].tsx index 8868724e8..e5fc72651 100644 --- a/targets/frontend/src/pages/alerts/[[...params]].tsx +++ b/targets/frontend/src/pages/alerts/[[...params]].tsx @@ -1,5 +1,5 @@ import { Accordion } from "@reach/accordion"; -import { HasuraAlert } from "@shared/types"; +import { HasuraAlert } from "@socialgouv/cdtn-types"; import { useRouter } from "next/router"; import React, { useMemo } from "react"; import { IoIosInformationCircleOutline } from "react-icons/io"; diff --git a/targets/frontend/src/pages/ghost-documents.tsx b/targets/frontend/src/pages/ghost-documents.tsx index 55bab40f0..48af0c7ee 100644 --- a/targets/frontend/src/pages/ghost-documents.tsx +++ b/targets/frontend/src/pages/ghost-documents.tsx @@ -62,7 +62,7 @@ export function DuplicateContentPage(): JSX.Element { {data?.relations.map(({ id, parent, document }) => { return ( - {getLabelBySource(parent.source)} + {getLabelBySource(parent.source as any)}