diff --git a/CHANGELOG.md b/CHANGELOG.md index 644728e4..b2829582 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). -## [0.20.3] - 2023-12-27 +## [0.20.5] - 2024-1-19 +- Update Lamdba functions using Node to version 18. This required upgrading the Lambda code to use the JS SDK v3 as well. +- Dependency upgrades to fix critical vulnerabilities. + +## [0.20.4] - 2023-12-27 - Add support for file attachments. See new File Uploads README for full details. - Clean-up & fix issues related to webpack 5 and `npm run` related errors for some build types. diff --git a/lex-web-ui/package-lock.json b/lex-web-ui/package-lock.json index 071fab59..4aa3c9c5 100644 --- a/lex-web-ui/package-lock.json +++ b/lex-web-ui/package-lock.json @@ -6771,9 +6771,9 @@ "dev": true }, "node_modules/follow-redirects": { - "version": "1.15.2", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.2.tgz", - "integrity": "sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==", + "version": "1.15.4", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.4.tgz", + "integrity": "sha512-Cr4D/5wlrb0z9dgERpUL3LrmPKVDsETIJhaCMeDfuFYcqa5bldGV6wBsAN6X/vxlXQtFBMrXdXxdL8CbDTGniw==", "dev": true, "funding": [ { @@ -18572,9 +18572,9 @@ "dev": true }, "follow-redirects": { - "version": "1.15.2", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.2.tgz", - "integrity": "sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==", + "version": "1.15.4", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.4.tgz", + "integrity": "sha512-Cr4D/5wlrb0z9dgERpUL3LrmPKVDsETIJhaCMeDfuFYcqa5bldGV6wBsAN6X/vxlXQtFBMrXdXxdL8CbDTGniw==", "dev": true }, "for-each": { diff --git a/lex-web-ui/package.json b/lex-web-ui/package.json index 717ba03b..67f52751 100644 --- a/lex-web-ui/package.json +++ b/lex-web-ui/package.json @@ -1,6 +1,6 @@ { "name": "lex-web-ui", - "version": "0.20.4", + "version": "0.20.5", "description": "Amazon Lex Web Interface", "author": "AWS", "license": "Amazon Software License", diff --git a/package-lock.json b/package-lock.json index a1d48355..70bdec2d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5547,9 +5547,9 @@ "dev": true }, "node_modules/follow-redirects": { - "version": "1.15.3", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.3.tgz", - "integrity": "sha512-1VzOtuEM8pC9SFU1E+8KfTjZyMztRsgEfwQl44z8A25uy13jSzTj6dyK2Df52iV0vgHCfBwLhDWevLn95w5v6Q==", + "version": "1.15.4", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.4.tgz", + "integrity": "sha512-Cr4D/5wlrb0z9dgERpUL3LrmPKVDsETIJhaCMeDfuFYcqa5bldGV6wBsAN6X/vxlXQtFBMrXdXxdL8CbDTGniw==", "dev": true, "funding": [ { @@ -16075,9 +16075,9 @@ "dev": true }, "follow-redirects": { - "version": "1.15.3", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.3.tgz", - "integrity": "sha512-1VzOtuEM8pC9SFU1E+8KfTjZyMztRsgEfwQl44z8A25uy13jSzTj6dyK2Df52iV0vgHCfBwLhDWevLn95w5v6Q==", + "version": "1.15.4", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.4.tgz", + "integrity": "sha512-Cr4D/5wlrb0z9dgERpUL3LrmPKVDsETIJhaCMeDfuFYcqa5bldGV6wBsAN6X/vxlXQtFBMrXdXxdL8CbDTGniw==", "dev": true }, "for-each": { diff --git a/package.json b/package.json index b9cf68f8..e149f80f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "aws-lex-web-ui", - "version": "0.20.4", + "version": "0.20.5", "description": "Sample Amazon Lex Web Interface", "main": "dist/lex-web-ui.min.js", "repository": { diff --git a/src/initiate-chat-lambda/index.js b/src/initiate-chat-lambda/index.js index 8b934888..d74bada8 100644 --- a/src/initiate-chat-lambda/index.js +++ b/src/initiate-chat-lambda/index.js @@ -1,6 +1,5 @@ -const AWS = require('aws-sdk'); -AWS.config.update({ region: process.env.REGION }); -const connect = new AWS.Connect(); +const { ConnectClient, StartChatContactCommand } = require("@aws-sdk/client-connect"); +const client = new ConnectClient({ region: process.env.REGION }); const parentOrigin = process.env.PARENT_ORIGIN; exports.handler = (event, context, callback) => { @@ -16,7 +15,7 @@ exports.handler = (event, context, callback) => { }); }; -function startChatContact(body) { +async function startChatContact(body) { let contactFlowId = ""; if (body.hasOwnProperty('ContactFlowId')) { contactFlowId = body["ContactFlowId"]; @@ -46,38 +45,33 @@ function startChatContact(body) { attributes = body["Attributes"]; } - return new Promise(function(resolve, reject) { - const startChat = { - "InstanceId": instanceId == "" ? process.env.INSTANCE_ID : instanceId, - "ContactFlowId": contactFlowId == "" ? process.env.CONTACT_FLOW_ID : contactFlowId, - "Attributes": attributes, - "ChatDurationInMinutes": 60, - "ParticipantDetails": { - "DisplayName": body["ParticipantDetails"]["DisplayName"] - } - }; - - if (initialMsgContent && initialMsgContentType != "" ){ - startChat.InitialMessage = { - "Content": initialMsgContent, - "ContentType": initialMsgContentType - }; + const startChat = { + "InstanceId": instanceId == "" ? process.env.INSTANCE_ID : instanceId, + "ContactFlowId": contactFlowId == "" ? process.env.CONTACT_FLOW_ID : contactFlowId, + "Attributes": attributes, + "ChatDurationInMinutes": 60, + "ParticipantDetails": { + "DisplayName": body["ParticipantDetails"]["DisplayName"] + } + }; + + if (initialMsgContent && initialMsgContentType != "" ){ + startChat.InitialMessage = { + "Content": initialMsgContent, + "ContentType": initialMsgContentType }; - - console.log('startChat params', startChat); - connect.startChatContact(startChat, function(err, data) { - if (err) { - console.log("Error starting the chat."); - console.log(err, err.stack); - reject(err); - } - else { - console.log("Start chat succeeded with the response: " + JSON.stringify(data)); - resolve(data); - } - }); - - }); + }; + + console.log('startChat params', startChat); + const command = new StartChatContactCommand(startChat); + try { + const response = await client.send(command); + return response; + } catch (error) { + console.log("Error starting the chat."); + console.log(error, error.stack); + return response; + } } function buildSuccessfulResponse(result) { diff --git a/src/streaming-lambda/index.js b/src/streaming-lambda/index.js index bf357bc9..96c16102 100644 --- a/src/streaming-lambda/index.js +++ b/src/streaming-lambda/index.js @@ -1,24 +1,26 @@ -const AWS = require('aws-sdk'); -const ddb = new AWS.DynamoDB.DocumentClient({ apiVersion: '2012-08-10', region: process.env.AWS_REGION }); +const { PutCommand, DynamoDBDocumentClient } = require('@aws-sdk/lib-dynamodb'); +const { DynamoDBClient } = require('@aws-sdk/client-dynamodb'); + +const client = new DynamoDBClient({ apiVersion: '2012-08-10', region: process.env.AWS_REGION }); +const docClient = DynamoDBDocumentClient.from(client); exports.handler = async event => { console.log("Received event: " + JSON.stringify(event)); const ttlTime = Date.now() / 1000 + 86400; //One day later in epoch time for TTL - const putParams = { + const command = new PutCommand({ TableName: process.env.TABLE_NAME, Item: { connectionId: event.requestContext.connectionId, sessionId: event.queryStringParameters.sessionId, ttl: ttlTime } - }; - + }); + try { - await ddb.put(putParams).promise(); + await docClient.send(command); + return { statusCode: 200, body: 'Connected.' }; } catch (err) { return { statusCode: 500, body: 'Failed to connect: ' + JSON.stringify(err) }; } - - return { statusCode: 200, body: 'Connected.' }; }; \ No newline at end of file diff --git a/templates/cognito.yaml b/templates/cognito.yaml index 9618eddb..284cf735 100644 --- a/templates/cognito.yaml +++ b/templates/cognito.yaml @@ -417,7 +417,7 @@ Resources: Condition: ShouldAllowSignUpEmailDomain Properties: Handler: index.handler - Runtime: nodejs14.x + Runtime: nodejs18.x Timeout: 3 Environment: Variables: diff --git a/templates/restapi.yaml b/templates/restapi.yaml index ec8bdb6a..8d76a50f 100644 --- a/templates/restapi.yaml +++ b/templates/restapi.yaml @@ -45,7 +45,7 @@ Resources: Description: AWS Lambda Function to initiate the chat with the end user Handler: "index.handler" Role: !GetAtt InitiateChatLambdaExecutionRole.Arn - Runtime: "nodejs14.x" + Runtime: "nodejs18.x" MemorySize: 128 Timeout: 30 Environment: diff --git a/templates/streaming-support.yaml b/templates/streaming-support.yaml index ee8b4b8c..b2d32f03 100644 --- a/templates/streaming-support.yaml +++ b/templates/streaming-support.yaml @@ -41,7 +41,7 @@ Resources: Description: AWS Lambda Function to initiate web socket connection for streaming Handler: "index.handler" Role: !GetAtt StreamingLambdaExecutionRole.Arn - Runtime: "nodejs14.x" + Runtime: "nodejs18.x" MemorySize: 128 Timeout: 30 Environment: