Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node20 update II #2319

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
cd96a8d
Updates Readme with Hackathon information
Arique1104 Nov 18, 2023
19a2b78
Ran npm install and got a yarn.lock file update. Keeping to learning…
Arique1104 Dec 3, 2023
2700601
Adds @babel/cli@7.23.4 to dependencies
Arique1104 Dec 3, 2023
752fecc
Removes web-cli from optional dependencies
Arique1104 Dec 3, 2023
12f7776
Adds babel/traverse version 7.23.2 to package and yarn lock
Arique1104 Dec 3, 2023
7d08d12
Ran npm audit fix
Arique1104 Dec 3, 2023
50dfcb3
Adds react-dnd version 7.7.0 to dependencies
Arique1104 Dec 3, 2023
cfe832a
Updates mobilecommons-signup to remove aws-sdk which is deprecated
Arique1104 Dec 3, 2023
d0b18da
Adds babel/plugin-transform-class-properties to project dependencies
Arique1104 Dec 3, 2023
e4d2323
Adds @babel/plugin-transform-nullish-coalescing-operator to project d…
Arique1104 Dec 3, 2023
dc2523a
Adds @babel/plugin-transform-optional-chaining into project dependencies
Arique1104 Dec 3, 2023
ef9b5dc
Upgrades revere-signup document aws-sdk to version 3 standards
Arique1104 Dec 3, 2023
0adff85
Upgrades csv-s3-upload index file to use version 3 aws
Arique1104 Dec 3, 2023
822b26d
Updates jobs.js to version 3 standards of aws - beginning of breaking…
Arique1104 Dec 3, 2023
c8589ea
Adds @aws-sdk/client-lambda to dependencies
Arique1104 Dec 3, 2023
7abeefb
Adds aws-sdk/s3-request-predesigner to dependencies
Arique1104 Dec 3, 2023
80358d6
Adds @aws-sdk/client-s3 to project dependencies
Arique1104 Dec 3, 2023
caa0531
Adds aws-sdk/client-sqs - end of breaking changes
Arique1104 Dec 3, 2023
8c325fd
Upgrades s3-pull index file to use version 3 of aws
Arique1104 Dec 3, 2023
d715d38
updates lambda-async index.js to use version 3 aws-sdk
Arique1104 Dec 3, 2023
4012b75
Updates telemetry to use cloudwatch events and client cloud watch
Arique1104 Dec 3, 2023
f35d89c
Adds aws-sdk/client-cloudwatch to project dependencies
Arique1104 Dec 3, 2023
840e60d
Adds @aws-sdk/client-cloudwatch-events to project dependencies
Arique1104 Dec 3, 2023
b25e90e
Upgrades lambda.js to version 3 of aws-sdk
Arique1104 Dec 3, 2023
c748ee0
Updates node engine to v 20.0.0 and npm to v 9.6.4
Arique1104 Dec 4, 2023
b647ce2
Ran npm install
Arique1104 Dec 4, 2023
f7cb4c9
Merge branch 'main' into node20-update-II
Arique1104 Dec 4, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-v1.4%20adopted-ff69b4.svg)](CODE_OF_CONDUCT.md)


# StateVoices Hack-a-thon Branches for Development

This github workflow is designed to secure the successful completion of our technical priorities.

- See our live updates from our Hackathon here on our [project board](https://github.com/orgs/StateVoicesNational/projects/3).
- Register for the [Merge Party Sunday Nov 19, 2023 3pmPST/6pmEST](https://www.mobilize.us/statevoices/event/592881/)

Github Workflow

- `main` - is our branch where our community depends on us to maintain it free of bugs and deprecations.

- `hackathon2023-staging` - is our branch where all passing code is developed during State Voices Hack-a-thon. This branch will recieve a full QA before being merged to main.

- `hackathon2023-testing` - is our branch where volunteer developers bring together their code for peer-review.

## Spoke

# StateVoices is the new community steward for Spoke!

On November 19th, the repo Spoke was transfered from MoveOn to StateVoices.
Expand All @@ -8,6 +26,7 @@ On November 19th, the repo Spoke was transfered from MoveOn to StateVoices.

## Spoke History


Spoke is an open source text-distribution tool for organizations to mobilize supporters and members into action. Spoke allows you to upload phone numbers, customize scripts and assign volunteers to communicate with supporters while allowing organizations to manage the process.

Spoke was created by Saikat Chakrabarti and Sheena Pakanati, and is now maintained by MoveOn.org.
Expand Down
3 changes: 1 addition & 2 deletions lambda.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"use strict";
const AWS = require("aws-sdk");
"use strict";;
const awsServerlessExpress = require("aws-serverless-express");
let app, server, jobs, dispatcher;

Expand Down
20 changes: 15 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"description": "Spoke",
"main": "src/server",
"engines": {
"node": ">=16.18.0",
"npm": "8.19.2"
"node": ">=20.0.0",
"npm": "9.6.4"
},
"scripts": {
"test": "jest --forceExit --runInBand --detectOpenHandles --verbose=false",
Expand Down Expand Up @@ -81,14 +81,24 @@
"homepage": "https://github.com/MoveOnOrg/Spoke/#readme",
"dependencies": {
"@aoberoi/passport-slack": "^1.0.5",
"@babel/cli": "^7.19.3",
"@aws-sdk/client-cloudwatch": "^3.465.0",
"@aws-sdk/client-cloudwatch-events": "^3.465.0",
"@aws-sdk/client-lambda": "^3.465.0",
"@aws-sdk/client-s3": "^3.465.0",
"@aws-sdk/client-sqs": "^3.465.0",
"@aws-sdk/s3-request-presigner": "^3.465.0",
"@babel/cli": "^7.23.4",
"@babel/core": "^7.19.6",
"@babel/plugin-proposal-export-default-from": "^7.18.10",
"@babel/plugin-transform-class-properties": "^7.23.3",
"@babel/plugin-transform-nullish-coalescing-operator": "^7.23.4",
"@babel/plugin-transform-optional-chaining": "^7.23.4",
"@babel/plugin-transform-runtime": "^7.19.6",
"@babel/preset-env": "^7.20.2",
"@babel/preset-react": "^7.18.6",
"@babel/preset-typescript": "^7.18.6",
"@babel/register": "^7.18.9",
"@babel/traverse": "^7.23.2",
"@bandwidth/messaging": "^3.0.0",
"@bandwidth/numbers": "^1.7.0",
"@date-io/core": "^1.3.13",
Expand Down Expand Up @@ -153,6 +163,7 @@
"prop-types": "^15.6.0",
"query-string": "^4.1.0",
"react": "16.14.0",
"react-dnd": "^7.7.0",
"redis": "3",
"request": "^2.81.0",
"rethink-knex-adapter": "0.4.20",
Expand Down Expand Up @@ -230,7 +241,6 @@
"react-formal": "2.2.2",
"react-router": "^3.2.0",
"react-tooltip": "^4.2.13",
"recompose": "^0.30.0",
"webpack-cli": "^4.7.2"
"recompose": "^0.30.0"
}
}
1 change: 0 additions & 1 deletion src/extensions/action-handlers/mobilecommons-signup.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import request from "request";
import aws from "aws-sdk";
import { r } from "../../server/models";
import { actionKitSignup } from "./helper-ak-sync.js";
import { getConfig } from "../../server/api/lib/config";
Expand Down
4 changes: 2 additions & 2 deletions src/extensions/action-handlers/revere-signup.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import request from "request";
import aws from "aws-sdk";
import { SQS } from "@aws-sdk/client-sqs";
import { r } from "../../server/models";
import { actionKitSignup } from "./helper-ak-sync.js";

const sqs = new aws.SQS();
const sqs = new SQS();

export const name = "revere-signup";

Expand Down
19 changes: 14 additions & 5 deletions src/extensions/contact-loaders/csv-s3-upload/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { unzipPayload } from "../../../workers/jobs";
import { getConfig, hasConfig } from "../../../server/api/lib/config";
import { gunzip } from "../../../lib";

import AWS from "aws-sdk";
import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
import { PutObjectCommand, S3 } from "@aws-sdk/client-s3";

export const name = "csv-s3-upload";

Expand Down Expand Up @@ -67,8 +68,11 @@ export async function getClientChoiceData(
/// The react-component will be sent this data as a property
/// return a json object which will be cached for expiresSeconds long
/// `data` should be a single string -- it can be JSON which you can parse in the client component
const s3 = new AWS.S3({
const s3 = new S3({
// The key signatureVersion is no longer supported in v3, and can be removed.
// @deprecated SDK v3 only supports signature v4.
signatureVersion: "v4",

region: getConfig("AWS_REGION")
});
const key = `contacts-upload/${campaign.id}/contacts.json.gz`;
Expand All @@ -80,7 +84,9 @@ export async function getClientChoiceData(
Expires: 1800 // 30 minutes
};

const result = await s3.getSignedUrl("putObject", params);
const result = await getSignedUrl(s3, new PutObjectCommand(params), {
expiresIn: "/* add value from 'Expires' from v2 call if present, else remove */"
});

return {
data: JSON.stringify({ s3Url: result, s3key: key }),
Expand Down Expand Up @@ -116,16 +122,19 @@ export async function processContactLoad(job, maxContacts, organization) {
/// * Batching
/// * Error handling
/// * "Request of Doom" scenarios -- queries or jobs too big to complete
const s3 = new AWS.S3({
const s3 = new S3({
// The key signatureVersion is no longer supported in v3, and can be removed.
// @deprecated SDK v3 only supports signature v4.
signatureVersion: "v4",

region: getConfig("AWS_REGION")
});
var params = {
Bucket: getConfig("AWS_S3_BUCKET_NAME"),
Key: job.payload
};

const contactsData = (await s3.getObject(params).promise()).Body.toString(
const contactsData = (await s3.getObject(params)).Body.toString(
"utf-8"
);
const parsedData = JSON.parse(
Expand Down
18 changes: 11 additions & 7 deletions src/extensions/contact-loaders/s3-pull/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { log, gunzip } from "../../../lib";

import path from "path";
import Papa from "papaparse";
import AWS from "aws-sdk";
import { S3 } from "@aws-sdk/client-s3";

export const name = "s3-pull";

Expand Down Expand Up @@ -89,8 +89,11 @@ export async function loadContactS3PullProcessFile(jobEvent, contextVars) {
customIndexes,
region
} = jobEvent;
const s3 = new AWS.S3({
const s3 = new S3({
region,

// The key signatureVersion is no longer supported in v3, and can be removed.
// @deprecated SDK v3 only supports signature v4.
signatureVersion: "v4"
});

Expand All @@ -111,8 +114,7 @@ export async function loadContactS3PullProcessFile(jobEvent, contextVars) {
.split("/")
.slice(3)
.join("/")
})
.promise();
});
const fileString = await gunzip(fileData.Body);
const { data, errors } = await new Promise((resolve, reject) => {
Papa.parse(fileString.toString(), {
Expand Down Expand Up @@ -256,8 +258,11 @@ export async function processContactLoad(job, maxContacts, organization) {
const s3Path = JSON.parse(job.payload).s3Path;
const s3Bucket = getConfig("AWS_S3_BUCKET_NAME", organization);
const region = getConfig("AWS_REGION", organization);
const s3 = new AWS.S3({
const s3 = new S3({
region,

// The key signatureVersion is no longer supported in v3, and can be removed.
// @deprecated SDK v3 only supports signature v4.
signatureVersion: "v4"
});

Expand All @@ -271,8 +276,7 @@ export async function processContactLoad(job, maxContacts, organization) {
.getObject({
Bucket: s3Bucket,
Key: manifestPath.replace(/^\//, "")
})
.promise();
});
manifestData = JSON.parse(manifestFile.Body.toString("utf-8"));
} catch (err) {
await failedContactLoad(
Expand Down
10 changes: 4 additions & 6 deletions src/extensions/job-runners/lambda-async/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import AWS from "aws-sdk";
import { Lambda } from "@aws-sdk/client-lambda";
import { saveJob } from "../helpers";

const functionName =
process.env.WORKER_LAMBDA_FUNCTION_NAME ||
process.env.AWS_LAMBDA_FUNCTION_NAME;

const client = new AWS.Lambda();
const client = new Lambda();

export const fullyConfigured = () => !!functionName;

Expand Down Expand Up @@ -33,8 +33,7 @@ export const dispatchJob = async (
FunctionName: functionName,
InvocationType: "Event",
Payload: JSON.stringify({ type: "JOB", jobId: job.id })
})
.promise();
});
return job;
};

Expand All @@ -44,6 +43,5 @@ export const dispatchTask = async (taskName, payload) => {
FunctionName: functionName,
InvocationType: "Event",
Payload: JSON.stringify({ type: "TASK", taskName, payload })
})
.promise();
});
};
17 changes: 9 additions & 8 deletions src/server/telemetry.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import moment from "moment";
import AWS from "aws-sdk";
import { CloudWatch } from "@aws-sdk/client-cloudwatch";
import { CloudWatchEvents } from "@aws-sdk/client-cloudwatch-events";
import { log } from "../lib";
import { getConfig } from "./api/lib/config";
import _ from "lodash";
Expand Down Expand Up @@ -55,13 +56,13 @@ const makeCloudwatchErrorEvent = (err, details) => {

// Specific to the Warren AWS deploy: report a cloudwatch event to "Mission Control"
if (getConfig("ENABLE_CLOUDWATCH_REPORTING", null, { truthy: 1 })) {
const cloudwatchEventsClient = new AWS.CloudWatchEvents();
const cloudwatchMetricsClient = new AWS.CloudWatch();
const cloudwatchEventsClient = new CloudWatchEvents();
const cloudwatchMetricsClient = new CloudWatch();

reportErrorCallbacks.push(async (err, details) => {
const payload = makeCloudwatchErrorEvent(err, details);
try {
await cloudwatchEventsClient.putEvents(payload).promise();
await cloudwatchEventsClient.putEvents(payload);
} catch (e) {
log.error({
msg: "Error posting exception to Cloudwatch:",
Expand All @@ -74,7 +75,7 @@ if (getConfig("ENABLE_CLOUDWATCH_REPORTING", null, { truthy: 1 })) {
reportEventCallbacks.push(async (detailType, details) => {
const payload = makeCloudwatchEvent(detailType, details);
try {
await cloudwatchEventsClient.putEvents(payload).promise();
await cloudwatchEventsClient.putEvents(payload);
if (details.count) {
const metricData = {
MetricData: [
Expand All @@ -87,7 +88,7 @@ if (getConfig("ENABLE_CLOUDWATCH_REPORTING", null, { truthy: 1 })) {
],
Namespace: `Spoke/${stage}/Data`
};
await cloudwatchMetricsClient.putMetricData(metricData).promise();
await cloudwatchMetricsClient.putMetricData(metricData);
}
} catch (e) {
log.error({
Expand Down Expand Up @@ -124,7 +125,7 @@ if (getConfig("ENABLE_CLOUDWATCH_REPORTING", null, { truthy: 1 })) {
awsEvent: req.awsEvent,
path: JSON.stringify(err.path)
});
await cloudwatchEventsClient.putEvents(payload).promise();
await cloudwatchEventsClient.putEvents(payload);
}
const metricData = {
MetricData: [
Expand All @@ -137,7 +138,7 @@ if (getConfig("ENABLE_CLOUDWATCH_REPORTING", null, { truthy: 1 })) {
],
Namespace: `Spoke/${stage}/Error`
};
await cloudwatchMetricsClient.putMetricData(metricData).promise();
await cloudwatchMetricsClient.putMetricData(metricData);
}
} catch (e) {
log.error({
Expand Down
33 changes: 18 additions & 15 deletions src/workers/jobs.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ import {
import importScriptFromDocument from "../server/api/lib/import-script";
import { rawIngestMethod } from "../extensions/contact-loaders";

import AWS from "aws-sdk";
import { Lambda } from "@aws-sdk/client-lambda";
import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
import { GetObjectCommand, S3 } from "@aws-sdk/client-s3";
import { SQS } from "@aws-sdk/client-sqs";
import Papa from "papaparse";
import moment from "moment";
import { sendEmail } from "../server/mail";
Expand Down Expand Up @@ -131,7 +134,7 @@ export async function sendJobToAWSLambda(job) {
console.log("LAMBDA INVOCATION FAILED: JOB NOT INVOKABLE", job);
return Promise.reject("Job type not available in job-processes");
}
const lambda = new AWS.Lambda();
const lambda = new Lambda();
const lambdaPayload = JSON.stringify(job);
if (lambdaPayload.length > 128000) {
console.log("LAMBDA INVOCATION FAILED PAYLOAD TOO LARGE");
Expand Down Expand Up @@ -169,7 +172,7 @@ export async function processSqsMessages(TWILIO_SQS_QUEUE_URL) {
return Promise.reject("TWILIO_SQS_QUEUE_URL not set");
}

const sqs = new AWS.SQS();
const sqs = new SQS();

const params = {
QueueUrl: TWILIO_SQS_QUEUE_URL,
Expand Down Expand Up @@ -206,7 +209,6 @@ export async function processSqsMessages(TWILIO_SQS_QUEUE_URL) {
QueueUrl: TWILIO_SQS_QUEUE_URL,
ReceiptHandle: message.ReceiptHandle
})
.promise()
.catch(reject);
if (process.env.DEBUG) {
console.log("processSqsMessages deleteresult", delMessageData);
Expand Down Expand Up @@ -859,7 +861,10 @@ export async function exportCampaign(job) {
(process.env.AWS_ACCESS_KEY_ID && process.env.AWS_SECRET_ACCESS_KEY)
) {
try {
const s3bucket = new AWS.S3({
const s3bucket = new S3({
// The transformation for params is not implemented.
// Refer to UPGRADING.md on aws-sdk-js-v3 for changes needed.
// Please create/upvote feature request on aws-sdk-js-codemod for params.
params: { Bucket: process.env.AWS_S3_BUCKET_NAME }
});
const campaignTitle = campaign.title
Expand All @@ -870,19 +875,17 @@ export async function exportCampaign(job) {
)}.csv`;
const messageKey = `${key}-messages.csv`;
let params = { Key: key, Body: campaignCsv };
await s3bucket.putObject(params).promise();
await s3bucket.putObject(params);
params = { Key: key, Expires: 86400 };
const campaignExportUrl = await s3bucket.getSignedUrl(
"getObject",
params
);
const campaignExportUrl = await getSignedUrl(s3bucket, new GetObjectCommand(params), {
expiresIn: "/* add value from 'Expires' from v2 call if present, else remove */"
});
params = { Key: messageKey, Body: messageCsv };
await s3bucket.putObject(params).promise();
await s3bucket.putObject(params);
params = { Key: messageKey, Expires: 86400 };
const campaignMessagesExportUrl = await s3bucket.getSignedUrl(
"getObject",
params
);
const campaignMessagesExportUrl = await getSignedUrl(s3bucket, new GetObjectCommand(params), {
expiresIn: "/* add value from 'Expires' from v2 call if present, else remove */"
});
exportResults.campaignExportUrl = campaignExportUrl;
exportResults.campaignMessagesExportUrl = campaignMessagesExportUrl;

Expand Down
Loading
Loading