diff --git a/targets/alert-cli/package.json b/targets/alert-cli/package.json index d9f3b9301..dd2edf097 100644 --- a/targets/alert-cli/package.json +++ b/targets/alert-cli/package.json @@ -5,6 +5,7 @@ "@shared/graphql-client": "1.0.0", "@socialgouv/cdtn-slugify": "^4.35.0", "@socialgouv/cdtn-sources": "^4.35.0", + "node-fetch": "^2.6.1", "nodegit": "0.27.0", "semver": "^7.3.2", "unist-util-parents": "^1.0.3", @@ -15,11 +16,12 @@ "@babel/preset-env": "^7.12.1", "@shared/types": "1.0.0", "@socialgouv/contributions-data-types": "^3.0.0", + "@socialgouv/datafiller-data-types": "^2.6.0", "@socialgouv/eslint-config-recommended": "^1.46.0", "@socialgouv/fiches-travail-data-types": "^4.6.0", - "@socialgouv/datafiller-data-types": "^2.6.0", "@types/jest": "^26.0.15", "@types/node": "^14.14.6", + "@types/node-fetch": "^2.5.7", "@types/nodegit": "^0.26.12", "@types/semver": "^7.3.4", "@types/unist": "^2.0.3", diff --git a/targets/alert-cli/src/exportContributionAlerts.js b/targets/alert-cli/src/exportContributionAlerts.js index bc5173f21..9a630cfff 100644 --- a/targets/alert-cli/src/exportContributionAlerts.js +++ b/targets/alert-cli/src/exportContributionAlerts.js @@ -1,3 +1,5 @@ +import fetch from "node-fetch"; + const contribApi = "https://contributions-api.codedutravail.fabrique.social.gouv.fr/alerts"; @@ -11,7 +13,7 @@ export async function exportContributionAlerts(changes) { )); const contributions = dilaAlertChanges.flatMap((alert) => { const targetedContribs = alert.documents.filter( - (targetDoc) => targetDoc.document.type == "contributions" + (targetDoc) => targetDoc.document.source == "contributions" ); if (targetedContribs.length === 0) { return []; @@ -27,6 +29,11 @@ export async function exportContributionAlerts(changes) { })); }); }); - console.log(JSON.stringify(contributions, null, 2)); - return contributions; + await fetch(contribApi, { + body: JSON.stringify(contributions), + headers: { + "Content-Type": "application/json", + }, + method: "POST", + }); } diff --git a/targets/alert-cli/src/index.d.ts b/targets/alert-cli/src/index.d.ts index 4d3278264..420e1fa07 100644 --- a/targets/alert-cli/src/index.d.ts +++ b/targets/alert-cli/src/index.d.ts @@ -28,7 +28,7 @@ type AstChanges = { } type Changes = AstChanges & { - documents: { document: DocumentInfo, reference: ParseDilaReference[] }[] + documents: { document: DocumentInfo, references: ParseDilaReference[] }[] } type DilaAlertChanges = { diff --git a/yarn.lock b/yarn.lock index fef2dc78e..18d3542db 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3302,6 +3302,14 @@ resolved "https://registry.yarnpkg.com/@types/minimist/-/minimist-1.2.0.tgz#69a23a3ad29caf0097f06eda59b361ee2f0639f6" integrity sha1-aaI6OtKcrwCX8G7aWbNh7i8GOfY= +"@types/node-fetch@^2.5.7": + version "2.5.7" + resolved "https://registry.yarnpkg.com/@types/node-fetch/-/node-fetch-2.5.7.tgz#20a2afffa882ab04d44ca786449a276f9f6bbf3c" + integrity sha512-o2WVNf5UhWRkxlf6eq+jMZDu7kjgpgJfl4xVNlvryc95O/6F2ld8ztKX+qu+Rjyet93WAWm5LjeX9H5FGkODvw== + dependencies: + "@types/node" "*" + form-data "^3.0.0" + "@types/node@*", "@types/node@>= 8", "@types/node@^14.14.6": version "14.14.6" resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.6.tgz#146d3da57b3c636cc0d1769396ce1cfa8991147f" @@ -5084,7 +5092,7 @@ columnify@^1.5.4: strip-ansi "^3.0.0" wcwidth "^1.0.0" -combined-stream@^1.0.6, combined-stream@~1.0.6: +combined-stream@^1.0.6, combined-stream@^1.0.8, combined-stream@~1.0.6: version "1.0.8" resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.8.tgz#c3d45a8b34fd730631a110a8a2520682b31d5a7f" integrity sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg== @@ -7306,6 +7314,15 @@ forever-agent@~0.6.1: resolved "https://registry.yarnpkg.com/forever-agent/-/forever-agent-0.6.1.tgz#fbc71f0c41adeb37f96c577ad1ed42d8fdacca91" integrity sha1-+8cfDEGt6zf5bFd60e1C2P2sypE= +form-data@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/form-data/-/form-data-3.0.0.tgz#31b7e39c85f1355b7139ee0c647cf0de7f83c682" + integrity sha512-CKMFDglpbMi6PyN+brwB9Q/GOw0eAnsrEZDgcsH5Krhz5Od/haKHAX0NmQfha2zPPz0JpWzA7GJHGSnvCRLWsg== + dependencies: + asynckit "^0.4.0" + combined-stream "^1.0.8" + mime-types "^2.1.12" + form-data@~2.3.2: version "2.3.3" resolved "https://registry.yarnpkg.com/form-data/-/form-data-2.3.3.tgz#dcce52c05f644f298c6a7ab936bd724ceffbf3a6"