From bad3b83049e07ec0683813382a33bd38c2bbb701 Mon Sep 17 00:00:00 2001 From: Eva Killenberg Date: Tue, 18 Jun 2024 06:59:42 -0400 Subject: [PATCH] chore(functions): remove request dependency (#3673) --- functions/package.json | 2 - functions/src/Integrations/firebase-slack.ts | 54 +++++++------------- yarn.lock | 6 +-- 3 files changed, 20 insertions(+), 42 deletions(-) diff --git a/functions/package.json b/functions/package.json index 0fcd472405..c7de6698b7 100644 --- a/functions/package.json +++ b/functions/package.json @@ -31,7 +31,6 @@ "google-auth-library": "^9.10.0", "handlebars": "^4.7.8", "oa-shared": "workspace:*", - "request": "^2.88.2", "sitemap": "^7.1.1", "uuid": "^9.0.1" }, @@ -42,7 +41,6 @@ "@types/fs-extra": "^11.0.4", "@types/jest": "^29.5.12", "@types/node": "^20.8.0", - "@types/request": "^2.48.12", "@types/uuid": "^9.0.0", "@types/webpack": "^5.28.5", "@types/webpack-node-externals": "^3.0.4", diff --git a/functions/src/Integrations/firebase-slack.ts b/functions/src/Integrations/firebase-slack.ts index 8c618a5a48..477d04f627 100644 --- a/functions/src/Integrations/firebase-slack.ts +++ b/functions/src/Integrations/firebase-slack.ts @@ -1,6 +1,6 @@ import { CONFIG } from '../config/config' import * as functions from 'firebase-functions' -import * as request from 'request' +import axios from 'axios' import { IModerationStatus } from 'oa-shared' const SITE_URL = CONFIG.deployment.site_url @@ -11,7 +11,7 @@ const SLACK_WEBHOOK_URL = CONFIG.integrations.slack_webhook export const notifyNewPin = functions .runWith({ memory: '512MB' }) .firestore.document('v3_mappins/{pinId}') - .onCreate((snapshot) => { + .onCreate(async (snapshot) => { const info = snapshot.data() const id = info._id const type = info.type @@ -19,48 +19,30 @@ export const notifyNewPin = functions if (moderation !== IModerationStatus.AWAITING_MODERATION) return - request.post( - SLACK_WEBHOOK_URL, - { - json: { - text: `📍 *New ${type}* pin from _${id}_ awaiting moderation. \n Location here ${SITE_URL}/map/#${id}`, - }, - }, - (err, res) => { - if (err) { - console.error(err) - return - } else { - return res - } - }, - ) + return await axios + .post(SLACK_WEBHOOK_URL, { + text: `📍 *New ${type}* pin from _${id}_ awaiting moderation. \n Location here ${SITE_URL}/map/#${id}`, + }) + .catch((err) => { + console.error(err) + }) }) export const notifyNewHowTo = functions .runWith({ memory: '512MB' }) .firestore.document('v3_howtos/{id}') - .onCreate((snapshot) => { + .onCreate(async (snapshot) => { const info = snapshot.data() const user = info._createdBy const title = info.title const slug = info.slug - // console.log(info); - request.post( - SLACK_WEBHOOK_URL, - { - json: { - text: `📓 Yeah! New How To *${title}* by _${user}_ awaiting moderation, + + return await axios + .post(SLACK_WEBHOOK_URL, { + text: `📓 Yeah! New How To *${title}* by _${user}_ awaiting moderation, check it out: ${SITE_URL}/how-to/${slug}`, - }, - }, - (err, res) => { - if (err) { - console.error(err) - return - } else { - return res - } - }, - ) + }) + .catch((err) => { + console.error(err) + }) }) diff --git a/yarn.lock b/yarn.lock index 2653a33795..7ba9afae3c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9044,7 +9044,7 @@ __metadata: languageName: node linkType: hard -"@types/request@npm:^2.48.12, @types/request@npm:^2.48.8": +"@types/request@npm:^2.48.8": version: 2.48.12 resolution: "@types/request@npm:2.48.12" dependencies: @@ -17327,7 +17327,6 @@ __metadata: "@types/fs-extra": ^11.0.4 "@types/jest": ^29.5.12 "@types/node": ^20.8.0 - "@types/request": ^2.48.12 "@types/uuid": ^9.0.0 "@types/webpack": ^5.28.5 "@types/webpack-node-externals": ^3.0.4 @@ -17349,7 +17348,6 @@ __metadata: jest: 29.7.0 jest-junit: ^16.0.0 oa-shared: "workspace:*" - request: ^2.88.2 sitemap: ^7.1.1 supertest: ^6.3.3 ts-jest: 29.1.4 @@ -27024,7 +27022,7 @@ __metadata: languageName: node linkType: hard -"request@npm:^2.87.0, request@npm:^2.88.2": +"request@npm:^2.87.0": version: 2.88.2 resolution: "request@npm:2.88.2" dependencies: