diff --git a/.kontinuous/env/dev/templates/www.sealed-secret.yaml b/.kontinuous/env/dev/templates/www.sealed-secret.yaml index a51e1cf56..ef75f7fe9 100644 --- a/.kontinuous/env/dev/templates/www.sealed-secret.yaml +++ b/.kontinuous/env/dev/templates/www.sealed-secret.yaml @@ -6,8 +6,6 @@ metadata: name: www spec: encryptedData: - ELASTICSEARCH_URL: AgCc9hf+VdcDI57o1P/TWmp7HWSwaFZ8hwO5VqRP9WJaMmcWQgMQNlUQg6oZAIAfxT7M2rHccMRD6Mkyu+YWCwQo+P26LWV50aH38bMYnQM5WTieDwEJpjffURZHFLVC44dyExz6S6FlvMGJcHtUK0fBrJLKXcS2mZdEh1MScqhtYIqXjXEEOgqTtxwvio7o31XJi0Op0LEY9WQZJmMP65Pt7zueFTe9/6yPFC5V8c/5eGT+axPFIaa71MKJrM+GZI3T7XiA3Pj8YmHvNF5CvrYnS94NOOZsSujiRkP2pB5XHWb3xGPBaNYiN5CuV+C1An/2MfJLvJjkjikTUEv+XMXChf39AcF4jdZZIzhpS0pnjqhncuergg2+vxq+QEwUk6GZiJ7hT0/yOfHA3gnohFESUbU2yce6/FxG3f6xMxpbyfqU9K/Ju7hWQ65BVXaxtYLNSj1l1YGQ5s+N5o9ISWiXa/oZihZjw0L+MEvH1TUGgiTbs94zG3fTl51OBRpzeTqRv9G83ASI/8baAWeKPA4v0CbT6x2eDf7EdiMY11zPwHzMf/zGJqgxr18dtCqC88ETCNc0c9jTVN0n6hriJ5FS0gJwIrWH8O34KYBaDOibEhUGdDAHBs1NStWoYu68LJ77h/ju5t2EIqzrgzfHXzkzWaNU0mrnLHD6Lpj1IREvTnAKbX8JzwELUXpnMmq3gYrbD94/FvyLxpjZvHJtsVunnyGzdGgEgwBbdzkhRo18BPEFtMJRravjZmmCpIZKMHyCbpQEEV4RK0UiwmfSDUX3TkQL - ELASTICSEARCH_TOKEN_UPDATE: AgCJrfs9bxEtOYDMO19x47ZXT0vsn8FcJ0vYwc/Cm0kLGw7g9n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SQBHm8u/0VHQwAWotNt2uVoAbvVzup3DvqxUBN5LJIRanmFHTw2JNh+s4eUvd+86PBiTpoPXIg9QpGWy4rhG7gJ614HOD70cLL6jik48Ezbi4OfOBQGKbs0rrkPiAg60jCW4wXgQqpdH+6TEj/z7+/ZU0um5pKTUA6DS8EN5xU1xQdHLMo7WVXQHI26lbWRtLMQA8JYmvq/kXfhcH6kYVERDWYK1QiajGSdDbEGkjxDh0Uk8KRHAtBw2xXgT8lV6wpVIuGrrc1B6CbJOGgEBUwdjbD9v7n4mqAEp7N8d6Gsc0Nbsc2rrAl4rVB7/ihoUXEtQthrXA8UFj8p7f/O7AMKXCU8gt29FeTFNEwydXhXw1EPlfUzr4/Gp3uNXiLSpjK9/3F4jQMAOHz64XOipFPMxncZSXounxVGJT8yBhxYEvpUq/9nufFA== template: metadata: diff --git a/.kontinuous/env/preprod/templates/www.sealed-secret.yaml b/.kontinuous/env/preprod/templates/www.sealed-secret.yaml index a51e1cf56..ef75f7fe9 100644 --- a/.kontinuous/env/preprod/templates/www.sealed-secret.yaml +++ b/.kontinuous/env/preprod/templates/www.sealed-secret.yaml @@ -6,8 +6,6 @@ metadata: name: www spec: encryptedData: - ELASTICSEARCH_URL: AgCc9hf+VdcDI57o1P/TWmp7HWSwaFZ8hwO5VqRP9WJaMmcWQgMQNlUQg6oZAIAfxT7M2rHccMRD6Mkyu+YWCwQo+P26LWV50aH38bMYnQM5WTieDwEJpjffURZHFLVC44dyExz6S6FlvMGJcHtUK0fBrJLKXcS2mZdEh1MScqhtYIqXjXEEOgqTtxwvio7o31XJi0Op0LEY9WQZJmMP65Pt7zueFTe9/6yPFC5V8c/5eGT+axPFIaa71MKJrM+GZI3T7XiA3Pj8YmHvNF5CvrYnS94NOOZsSujiRkP2pB5XHWb3xGPBaNYiN5CuV+C1An/2MfJLvJjkjikTUEv+XMXChf39AcF4jdZZIzhpS0pnjqhncuergg2+vxq+QEwUk6GZiJ7hT0/yOfHA3gnohFESUbU2yce6/FxG3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5SHmTLbVPxb7D3Rl6BhBhV/GiALar7sF6a6bD4681UhjR7q2So8s1LyksT5V0GPIv+r4NwoB0W1vmimzQTqNiAw0wnte1530xiR24HxF0d+7Yr8y6WRTOjAht0= NEXTAUTH_SECRET: AgAObcZKrO3zRrVCfoXEAntOXyZlHFJdxUep4iWbQdITqzDw32DhJzynwXmLTlOcJrAf0acuDOK3xMoOH2QZO4EaDOmpL8vJwmvQWIccdO/Gll2cxwCr/Cbu/9RmMixaXtrscoPz7m2geO5u/0dRCFE5IVUGZfaOBY+zHIFaxPFxWu9edjHWS9JJfRqcIoEyCLudmM1N20UGa2fq1tuIbD5ZS9f392l3669wqRB4tNnKxOKIJEQ4GA5PkqYYLoFsGGtAR5Hw9/eweXP0KXZfQjRJUfowdzFsx3wutjd2PVz7t0K5WZc2X4+RsodhEEYZJD013vXSQBHm8u/0VHQwAWotNt2uVoAbvVzup3DvqxUBN5LJIRanmFHTw2JNh+s4eUvd+86PBiTpoPXIg9QpGWy4rhG7gJ614HOD70cLL6jik48Ezbi4OfOBQGKbs0rrkPiAg60jCW4wXgQqpdH+6TEj/z7+/ZU0um5pKTUA6DS8EN5xU1xQdHLMo7WVXQHI26lbWRtLMQA8JYmvq/kXfhcH6kYVERDWYK1QiajGSdDbEGkjxDh0Uk8KRHAtBw2xXgT8lV6wpVIuGrrc1B6CbJOGgEBUwdjbD9v7n4mqAEp7N8d6Gsc0Nbsc2rrAl4rVB7/ihoUXEtQthrXA8UFj8p7f/O7AMKXCU8gt29FeTFNEwydXhXw1EPlfUzr4/Gp3uNXiLSpjK9/3F4jQMAOHz64XOipFPMxncZSXounxVGJT8yBhxYEvpUq/9nufFA== template: metadata: diff --git a/.kontinuous/env/prod/templates/www.sealed-secret.yaml b/.kontinuous/env/prod/templates/www.sealed-secret.yaml index 5cc516018..64fcaaebb 100644 --- a/.kontinuous/env/prod/templates/www.sealed-secret.yaml +++ b/.kontinuous/env/prod/templates/www.sealed-secret.yaml @@ -7,8 +7,6 @@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sUjUOEVVn03yL/zZqNqixWpruL3wFNUyS9GsavGyTAtdscyLEx7M5eIMtJwUPzBxVWElFxg3hYaE7ZFxjwDHpIoIFDAlBBDGqz2lX13zpCMfL8rjfTnztSjE/LiiYeJ3W6S1blk87o9U5MGQE4csC2gcSO95Bd1x6uecfaBx81AI+btW+5smOvblLY8u50dn/F83151bKoPFZSaL0qCPjJMujYDXHM//Z7cqeer3s6bMxvo7s1epc+5xcsLxJTqYeN8dqQYTz5OiE5JusTteCDA== template: metadata: diff --git a/targets/frontend/package.json b/targets/frontend/package.json index 61e5529a7..e18863058 100644 --- a/targets/frontend/package.json +++ b/targets/frontend/package.json @@ -4,7 +4,6 @@ "dependencies": { "@aws-sdk/client-s3": "^3.525.0", "@codegouvfr/react-dsfr": "^0.76.4", - "@elastic/elasticsearch": "^7.14.1", "@emotion/react": "11.10.6", "@emotion/styled": "11.10.6", "@hapi/boom": "^9.1.4", @@ -45,7 +44,6 @@ "http-proxy-middleware": "^3.0.0", "jsonwebtoken": "^9.0.2", "mammoth": "^1.6.0", - "memoizee": "^0.4.15", "micromark": "^2.11.4", "mime-types": "^2.1.35", "next": "14.1.4", @@ -62,16 +60,9 @@ "react-hook-form": "^7.43.9", "react-icons": "^4.2.0", "react-sortable-hoc": "^2.0.0", - "rehype-raw": "^5.1.0", - "rehype-stringify": "^8.0.0", - "remark-parse": "^9.0.0", - "remark-rehype": "^8.1.0", - "remark-stringify": "^9.0.1", "serialize-error": "^9.1.1", "sharp": "^0.32.6", - "strip-markdown": "^4.2.0", "swr": "^1.0.1", - "unified": "^9.2.2", "urql": "^4.0.6", "uuid": "^8.3.2", "zod": "3.21.4" diff --git a/targets/frontend/src/lib/preview/glossary.js b/targets/frontend/src/lib/preview/glossary.js deleted file mode 100644 index fa3c507f6..000000000 --- a/targets/frontend/src/lib/preview/glossary.js +++ /dev/null @@ -1,98 +0,0 @@ -const conventionMatchers = [ - "convention collective", - "conventions collectives", - "accords de branches", - "accord de branche", - "disposition conventionnelle", - "dispositions conventionnelles", -]; - -// we cannot use \b word boundary since \w does not match diacritics -// So we do a kind of \b equivalent. -// the main différence is that matched pattern can include a whitespace as first char -const frDiacritics = "àâäçéèêëïîôöùûüÿœæÀÂÄÇÉÈÊËÎÏÔÖÙÛÜŸŒÆ"; -const wordBoundaryStart = `(?:^|[^_/\\w${frDiacritics}-])`; -const wordBoundaryEnd = `(?![\\w${frDiacritics}])`; - -const startTag = `(?<=>[^><]*)`; -const endTag = `(?=[^<]* { - glossary = glossary.concat( - [term, ...variants].map((term) => ({ - definition, - pattern: new RegExp( - `${startTag}${wordBoundaryStart}(${term})${wordBoundaryEnd}${endTag}`, - "gi" - ), - term, - })) - ); - - if (abbreviations.length) { - for (const word of abbreviations) { - glossary.push({ - definition, - pattern: new RegExp(`${startTag}\\b(${word})\\b${endTag}`, "g"), - term: word, - }); - } - } - }); - - // we make sure that bigger terms are replaced first - glossary.sort((previous, next) => { - return next.term.length - previous.term.length; - }); - - // we also sure that cc matchers are replaced first - conventionMatchers.forEach((matcher) => { - glossary.unshift({ - definition: false, - pattern: new RegExp(`${startTag}(${matcher})${endTag}`, "gi"), - term: matcher, - }); - }); - - const idToWebComponent = new Map(); - - glossary.forEach(({ definition, pattern, term }, index) => { - // while we loop, we replace the matches with an id to prevent nested matches - idHtmlContent = idHtmlContent.replace( - pattern, - function ( - match // contains the matching term with the word boundaries - ) { - const id = "__tt__" + index; - const webComponent = definition - ? `", "") - .replace("

", "") - )}">${term}
` - : `${term}`; - idToWebComponent.set(id, webComponent); - return match.replace(new RegExp(term), id); - } - ); - }); - - // In the end, we replace the id with its related component - let finalContent = idHtmlContent; - idToWebComponent.forEach((webComponent, id) => { - // make sure we don't match larger numbers - finalContent = finalContent.replace( - new RegExp(`${id}([^1-9])`, "g"), - `${webComponent}$1` - ); - }); - - return finalContent; -} diff --git a/targets/frontend/src/lib/preview/markdown.js b/targets/frontend/src/lib/preview/markdown.js deleted file mode 100644 index bcc07c8b9..000000000 --- a/targets/frontend/src/lib/preview/markdown.js +++ /dev/null @@ -1,45 +0,0 @@ -import htmlAstToAnotherHtmlAst from "rehype-raw"; -import htmlAstStringify from "rehype-stringify"; -import markdownToMardownAst from "remark-parse"; -import markdownAstToHtmlAst from "remark-rehype"; -import markdownAstStringify from "remark-stringify"; -import markdownAstStrip from "strip-markdown"; -import unified from "unified"; - -import { addGlossary } from "./glossary"; - -const textProcessor = unified() - .use(markdownToMardownAst) - .use(markdownAstStrip) - .use(markdownAstStringify); - -const htmlProcessor = unified() - .use(markdownToMardownAst) - .use(markdownAstToHtmlAst, { allowDangerousHtml: true }) - .use(htmlAstToAnotherHtmlAst) - .use(htmlAstStringify); - -export function markdownTransform(glossary, document) { - document.intro = addGlossary( - glossary, - htmlProcessor.processSync(document.intro).contents - ); - - document.contents.forEach((content) => { - content.html = addGlossary( - glossary, - htmlProcessor.processSync(content.markdown).contents - ); - delete content.markdown; - }); - - document.text = - textProcessor.processSync(document.intro) + - document.contents - .map(({ markdown }) => - textProcessor.processSync(markdown).contents.replace(/\s\s+/g, " ") - ) - .join(""); - - return document; -} diff --git a/targets/frontend/src/lib/preview/preview.gql.js b/targets/frontend/src/lib/preview/preview.gql.js deleted file mode 100644 index c5d21a542..000000000 --- a/targets/frontend/src/lib/preview/preview.gql.js +++ /dev/null @@ -1,7 +0,0 @@ -export const previewContentAction = ` -mutation preview( $cdtnId: String! $document: jsonb! $source: String!) { - preview_document(cdtnId: $cdtnId, document: $document, source: $source) { - message - } -} -`; diff --git a/targets/frontend/src/pages/api/actions/preview.js b/targets/frontend/src/pages/api/actions/preview.js deleted file mode 100644 index 759c4155a..000000000 --- a/targets/frontend/src/pages/api/actions/preview.js +++ /dev/null @@ -1,106 +0,0 @@ -import { Client } from "@elastic/elasticsearch"; -import { Boom } from "@hapi/boom"; -import { gqlClient } from "@shared/utils"; -import { SOURCES } from "@socialgouv/cdtn-sources"; -import memoizee from "memoizee"; -import { createErrorFor } from "src/lib/apiError"; -import { markdownTransform } from "src/lib/preview/markdown"; - -const getGlossary = ` -query getGlossary { - glossary(order_by: {term: asc}) { - abbreviations - definition - id - references - term - variants - } -} -`; - -async function _fetchGlossary() { - const result = await gqlClient().query(getGlossary).toPromise(); - if (result.error) { - console.error("[fetchGlossary]", result.error); - throw result.error; - } - return result.data.glossary; -} -const fetchGlossary = memoizee(_fetchGlossary, { - maxAge: 1000 * 5 * 60, - preFetch: true, - promise: true, -}); - -export const [majorIndexVersion] = - require("../../../../package.json").version.split("."); - -export default async function updateDocument(req, res) { - const apiError = createErrorFor(res); - if (req.method === "GET") { - console.error("[updateDocument] GET method not allowed"); - res.setHeader("Allow", ["POST"]); - return apiError(Boom.methodNotAllowed("GET method not allowed")); - } - - if (req.headers["actions-secret"] !== process.env.ACTIONS_SECRET) { - console.error("[updateDocument] Invalid secret token"); - return apiError(Boom.unauthorized("Invalid secret token")); - } - - if ( - !process.env.ELASTICSEARCH_TOKEN_UPDATE || - !process.env.ELASTICSEARCH_URL - ) { - console.error("[updateDocument] Missing env"); - return apiError(Boom.forbidden("Missing env")); - } - - const { cdtnId, document, source } = req.body.input; - - const glossary = await fetchGlossary(); - - const client = new Client({ - auth: { - apiKey: process.env.ELASTICSEARCH_TOKEN_UPDATE, - }, - node: `${process.env.ELASTICSEARCH_URL}`, - }); - - try { - await client.update({ - body: { - doc: await transform(source, document, glossary), - }, - id: cdtnId, - index: `cdtn-preprod-v${majorIndexVersion}_documents`, - }); - console.log( - `[actions] update document ${cdtnId} in index cdtn-preprod-v${majorIndexVersion}_documents` - ); - res.json({ message: "doc updated!", statusCode: 200 }); - } catch (response) { - if (response.body) { - console.error( - `[actions] update document ${cdtnId} for preview failed`, - response.body.error - ); - } else { - console.error( - `[actions] update ${cdtnId} document for preview failed`, - response - ); - } - apiError(Boom.badGateway(`[actions] update document for preview failed`)); - } -} - -async function transform(source, document, glossary) { - switch (source) { - case SOURCES.EDITORIAL_CONTENT: - return markdownTransform(glossary, document); - default: - return document; - } -} diff --git a/targets/frontend/src/pages/api/webhooks/publication.js b/targets/frontend/src/pages/api/webhooks/publication.js deleted file mode 100644 index 9dc4ff315..000000000 --- a/targets/frontend/src/pages/api/webhooks/publication.js +++ /dev/null @@ -1,78 +0,0 @@ -import { Client } from "@elastic/elasticsearch"; -import Boom from "@hapi/boom"; -import { z } from "zod"; -import { createErrorFor } from "src/lib/apiError"; - -import { majorIndexVersion } from "../actions/preview"; - -export default async function publishDocument(req, res) { - const apiError = createErrorFor(res); - - if (req.headers["publication-secret"] !== process.env.PUBLICATION_SECRET) { - console.error("[publishDocument] Invalid secret token"); - return apiError(Boom.unauthorized("Invalid secret token")); - } - - if ( - !process.env.ELASTICSEARCH_TOKEN_UPDATE || - !process.env.ELASTICSEARCH_URL - ) { - console.error("[publishDocument] Missing env"); - res.status(304).json({ message: "not modified" }); - } - - const schema = z.object({ - event: z.object({ - data: z.object({ - new: z.object({ - cdtn_id: z.string(), - is_published: z.boolean().optional(), - }), - }), - op: z.string().regex(/^(UPDATE)$/, "OP"), - }), - }); - - const { error, data: value } = schema.safeParse(req.body); - - if (error) { - console.error(`[publishDocument] ${error.details[0].message}`); - return apiError(Boom.badRequest(error.details[0].message)); - } - const { data } = value.event; - const { cdtn_id, is_published } = data.new; - - const client = new Client({ - auth: { - apiKey: process.env.ELASTICSEARCH_TOKEN_UPDATE, - }, - node: `${process.env.ELASTICSEARCH_URL}`, - }); - - try { - await client.update({ - body: { - doc: { isPublished: is_published }, - }, - id: cdtn_id, - index: `cdtn-preprod-v${majorIndexVersion}_documents`, - }); - console.log( - `[publishDocument] ${ - is_published ? "published" : "unpublish" - } document ${cdtn_id}` - ); - res.json({ - message: `${ - is_published ? "published" : "unpublish" - } document ${cdtn_id}`, - }); - } catch (response) { - if (response.body) { - console.error("[webhook] update publication status", response.body.error); - } else { - console.error("[webhook] update publication status", response); - } - apiError(Boom.badGateway(`[webhook] can't update publication status`)); - } -} diff --git a/targets/frontend/src/pages/contenus/[id].tsx b/targets/frontend/src/pages/contenus/[id].tsx index 287219f3e..891241fa6 100644 --- a/targets/frontend/src/pages/contenus/[id].tsx +++ b/targets/frontend/src/pages/contenus/[id].tsx @@ -4,7 +4,6 @@ import React, { useEffect, useState } from "react"; import { useForm } from "react-hook-form"; import { Button } from "src/components/button"; import { Layout } from "src/components/layout/auth.layout"; -import { previewContentAction } from "src/lib/preview/preview.gql"; import { useMutation, useQuery } from "urql"; import { Card, Stack } from "@mui/material"; @@ -29,7 +28,6 @@ export function DocumentPage() { const [hasChanged, setHasChanged] = useState(false); const [jsonData, setJsonData] = useState("{}"); const [, executeUpdate] = useMutation(updateDocumentMutation); - const [, previewContent] = useMutation(previewContentAction); const { handleSubmit } = useForm(); useEffect(() => { @@ -54,24 +52,9 @@ export function DocumentPage() { console.error("update impossible"); return; } - const { cdtnId, source, document, metaDescription, text, title } = - data?.document; if (errorUpdate) { console.error("update impossible", errorUpdate.message); } - const response: any = previewContent({ - cdtnId, - document: { - ...document, - metaDescription, - text, - title, - }, - source, - }); - if (response.error) { - console.error("preview impossible", response.error.message); - } } function handleEditorChange(stringifyCode: string) { diff --git a/targets/frontend/src/pages/contenus/edit/[id].tsx b/targets/frontend/src/pages/contenus/edit/[id].tsx index 5193bb325..b9166e818 100644 --- a/targets/frontend/src/pages/contenus/edit/[id].tsx +++ b/targets/frontend/src/pages/contenus/edit/[id].tsx @@ -8,7 +8,6 @@ import { Dialog } from "src/components/dialog"; import { EditorialContentForm } from "src/components/editorialContent"; import { HighlightsForm } from "src/components/highlights"; import { Layout } from "src/components/layout/auth.layout"; -import { previewContentAction } from "src/lib/preview/preview.gql"; import { Content, ContentQuery, @@ -46,7 +45,6 @@ export function EditInformationPage() { const [{ fetching: deleting }, deleteContent] = useMutation( deleteContentMutation ); - const [, previewContent] = useMutation(previewContentAction); const onSubmit = (mapper: (content: T) => object) => @@ -56,23 +54,6 @@ export function EditInformationPage() { if (!result) return; const { slug: computedSlug, metaDescription: computedMetaDescription } = result.data.content; - if (!result.error) { - previewContent({ - cdtnId: content?.cdtnId, - document: { - metaDescription: computedMetaDescription, - slug: computedSlug, - title: content?.title, - }, - source: content?.source, - }).then((response) => { - if (response.error) { - console.error("preview impossible", response.error.message); - } - }); - } else { - console.error("edition impossible", result.error.message); - } }; const onSubmitContent = onSubmit((contentItem: Content) => { @@ -99,7 +80,6 @@ export function EditInformationPage() { router, data?.content, editContent, - previewContent, ]); const onSubmitHightlight = onSubmit( @@ -125,33 +105,6 @@ export function EditInformationPage() { router, data?.content, editContent, - previewContent, - ]); - - const onSubmitPrequalified = onSubmit( - (contentItem: PrequalifiedContent) => { - const relationIds = getContentRelationIds(contentItem.contentRelations); - const relations = mapContentRelations( - contentItem.contentRelations, - router.query.id as string - ); - return { - cdtnId: data?.content?.cdtnId, - document: contentItem.document, - metaDescription: contentItem.title, - relationIds, - relations, - slug: contentItem?.slug || slugify(contentItem?.title as string), - title: contentItem?.title, - }; - } - ); - - const onSubmitPrequalifiedMemo = useCallback(onSubmitPrequalified, [ - router, - data?.content, - editContent, - previewContent, ]); if (!data?.content) { diff --git a/targets/hasura/metadata/actions.graphql b/targets/hasura/metadata/actions.graphql index 081545811..c0af7009a 100644 --- a/targets/hasura/metadata/actions.graphql +++ b/targets/hasura/metadata/actions.graphql @@ -1,11 +1,3 @@ -type Mutation { - preview_document( - cdtnId: String! - document: jsonb! - source: String! - ): Status -} - type Mutation { publish( id: uuid! diff --git a/targets/hasura/metadata/actions.yaml b/targets/hasura/metadata/actions.yaml index e3c8ba4ce..10de0bdd0 100644 --- a/targets/hasura/metadata/actions.yaml +++ b/targets/hasura/metadata/actions.yaml @@ -1,15 +1,4 @@ actions: - - name: preview_document - definition: - kind: synchronous - handler: '{{API_URL}}/actions/preview' - forward_client_headers: true - headers: - - name: actions-secret - value_from_env: ACTIONS_SECRET - permissions: - - role: super - - role: user - name: publish definition: kind: synchronous diff --git a/targets/hasura/metadata/databases/default/tables/public_documents.yaml b/targets/hasura/metadata/databases/default/tables/public_documents.yaml index c5516fe2b..37aa641fa 100644 --- a/targets/hasura/metadata/databases/default/tables/public_documents.yaml +++ b/targets/hasura/metadata/databases/default/tables/public_documents.yaml @@ -136,18 +136,3 @@ delete_permissions: - role: user permission: filter: {} -event_triggers: - - name: publication - definition: - enable_manual: false - update: - columns: - - is_published - retry_conf: - interval_sec: 10 - num_retries: 2 - timeout_sec: 60 - webhook_from_env: PUBLICATION_WEBHOOK_URL - headers: - - name: publication-secret - value_from_env: PUBLICATION_SECRET diff --git a/yarn.lock b/yarn.lock index cfd159dae..bfe1d6847 100644 --- a/yarn.lock +++ b/yarn.lock @@ -11963,7 +11963,6 @@ __metadata: dependencies: "@aws-sdk/client-s3": ^3.525.0 "@codegouvfr/react-dsfr": ^0.76.4 - "@elastic/elasticsearch": ^7.14.1 "@emotion/react": 11.10.6 "@emotion/styled": 11.10.6 "@hapi/boom": ^9.1.4 @@ -12021,7 +12020,6 @@ __metadata: jsonwebtoken: ^9.0.2 lint-staged: ^12.0.0 mammoth: ^1.6.0 - memoizee: ^0.4.15 micromark: ^2.11.4 mime-types: ^2.1.35 next: 14.1.4 @@ -12039,17 +12037,10 @@ __metadata: react-hook-form: ^7.43.9 react-icons: ^4.2.0 react-sortable-hoc: ^2.0.0 - rehype-raw: ^5.1.0 - rehype-stringify: ^8.0.0 - remark-parse: ^9.0.0 - remark-rehype: ^8.1.0 - remark-stringify: ^9.0.1 serialize-error: ^9.1.1 sharp: ^0.32.6 - strip-markdown: ^4.2.0 swr: ^1.0.1 typescript: ^5.4.3 - unified: ^9.2.2 urql: ^4.0.6 uuid: ^8.3.2 zod: 3.21.4 @@ -16807,7 +16798,7 @@ __metadata: languageName: node linkType: hard -"memoizee@npm:0.4.15, memoizee@npm:^0.4.15": +"memoizee@npm:0.4.15": version: 0.4.15 resolution: "memoizee@npm:0.4.15" dependencies: @@ -21403,13 +21394,6 @@ __metadata: languageName: node linkType: hard -"strip-markdown@npm:^4.2.0": - version: 4.2.0 - resolution: "strip-markdown@npm:4.2.0" - checksum: 85bf852685b9353791073774fa91730beb26f8e122307241f812e5731227eb01829a3979e7606b922c3a83a8a69a1e4c0218cb02ab6025e55c37a75a14472ce6 - languageName: node - linkType: hard - "strnum@npm:^1.0.5": version: 1.0.5 resolution: "strnum@npm:1.0.5"