-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from reapit/feature/cld-664-config-serverless
feature/cld 664 config serverless
- Loading branch information
Showing
7 changed files
with
153 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
dev: | ||
COGNITO_USERPOOL_ID: "<<YOUR KEY>>" | ||
MARKET_PLACE_URL: "<YOUR MARKET_PLACE URL>" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,48 @@ | ||
service: cognito-auth-api-dev-dev-mailer | ||
service: cognito-mailer | ||
custom: ${file(./env.yml)} | ||
provider: | ||
name: aws | ||
runtime: nodejs10.x | ||
stage: dev | ||
stage: ${opt:stage, 'dev'} | ||
region: eu-west-2 | ||
deploymentBucket: | ||
name: cognito.mailer.${self:provider.stage} | ||
blockPublicAccess: false | ||
environment: | ||
COGNITO_USERPOOL_ID: ${self:custom.${self:provider.stage}.COGNITO_USERPOOL_ID} | ||
MARKET_PLACE_URL: ${self:custom.${self:provider.stage}.MARKET_PLACE_URL} | ||
package: | ||
include: | ||
- public/** | ||
exclude: | ||
- .git/** | ||
- .github/** | ||
- .serverless/** | ||
- coverage/** | ||
- node_modules/** | ||
- src/** | ||
- .gitignore | ||
- .env.example.yml | ||
- .env.yml | ||
- package.json | ||
- README.md | ||
- serverless.yml | ||
- tsconfig.json | ||
- tsconfig.legacy.json | ||
- tslint.json | ||
|
||
functions: | ||
mailer: | ||
handler: public/app.mailHandler | ||
forgotPasswordHandler: | ||
handler: public/app.forgotPasswordHandler | ||
events: | ||
- cognitoUserPool: | ||
pool: ${self:custom.${self:provider.stage}.COGNITO_USERPOOL_ID} | ||
trigger: CustomMessage | ||
existing: true | ||
existing: true | ||
confirmRegistrationHandler: | ||
handler: public/app.confirmRegistrationHandler | ||
events: | ||
- cognitoUserPool: | ||
pool: ${self:custom.${self:provider.stage}.COGNITO_USERPOOL_ID} | ||
trigger: CustomMessage | ||
existing: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
import { CognitoUserPoolTriggerHandler } from 'aws-lambda' | ||
import { customMailer } from './mailer/custom-mailer' | ||
import { sendForgotPasswordMail, sendConfirmRegistrationMail } from './mailer/custom-mailer' | ||
|
||
export const mailHandler: CognitoUserPoolTriggerHandler = (event, context, callback) => | ||
customMailer(event, context, callback) | ||
export const forgotPasswordHandler: CognitoUserPoolTriggerHandler = (event, context, callback) => | ||
sendForgotPasswordMail(event, context, callback) | ||
|
||
export const confirmRegistrationHandler: CognitoUserPoolTriggerHandler = (event, context, callback) => | ||
sendConfirmRegistrationMail(event, context, callback) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,27 @@ | ||
import { CognitoUserPoolTriggerHandler } from 'aws-lambda' | ||
import { forgotPasswordTemplate, confirmRegistrationTemplate } from './templates/index' | ||
|
||
export const customMailer: CognitoUserPoolTriggerHandler = async (event, _context, callback) => { | ||
if (event.userPoolId === process.env.COGNITO_USERPOOL_ID) { | ||
switch (event.triggerSource) { | ||
case 'CustomMessage_ForgotPassword': | ||
event.response.emailSubject = 'Reapit Foundations: Forgotten Password' | ||
// TODO will replace by env | ||
const resetPasswordUrl = 'https://dev.marketplace.reapit.com/developer/reset-password' | ||
event.response.emailMessage = await forgotPasswordTemplate({ | ||
verificationCode: event.request.codeParameter as string, | ||
userName: event.request.userAttributes.email, | ||
url: resetPasswordUrl | ||
}) | ||
break | ||
case 'CustomMessage_SignUp': | ||
event.response.emailSubject = 'Welcome to Reapit Foundations' | ||
// TODO will replace by env | ||
const confirmRegistrationUrl = 'https://dev.marketplace.reapit.com/register/confirm' | ||
event.response.emailMessage = await confirmRegistrationTemplate({ | ||
userName: event.request.userAttributes.email, | ||
url: confirmRegistrationUrl | ||
}) | ||
break | ||
} | ||
export const sendForgotPasswordMail: CognitoUserPoolTriggerHandler = async (event, _context, callback) => { | ||
if (event.userPoolId === process.env.COGNITO_USERPOOL_ID && event.triggerSource === 'CustomMessage_ForgotPassword') { | ||
event.response.emailSubject = 'Reapit Foundations: Forgotten Password' | ||
const resetPasswordUrl = `${process.env.MARKET_PLACE_URL}/developer/reset-password` | ||
event.response.emailMessage = await forgotPasswordTemplate({ | ||
verificationCode: event.request.codeParameter as string, | ||
userName: event.request.userAttributes.email, | ||
url: resetPasswordUrl | ||
}) | ||
} | ||
callback(null, event) | ||
} | ||
|
||
export const sendConfirmRegistrationMail: CognitoUserPoolTriggerHandler = async (event, _context, callback) => { | ||
if (event.userPoolId === process.env.COGNITO_USERPOOL_ID && event.triggerSource === 'CustomMessage_SignUp') { | ||
event.response.emailSubject = 'Welcome to Reapit Foundations' | ||
const confirmRegistrationUrl = `${process.env.MARKET_PLACE_URL}/register/confirm` | ||
event.response.emailMessage = await confirmRegistrationTemplate({ | ||
userName: event.request.userAttributes.email, | ||
url: confirmRegistrationUrl | ||
}) | ||
} | ||
callback(null, event) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -979,6 +979,13 @@ cosmiconfig@^5.2.1: | |
js-yaml "^3.13.1" | ||
parse-json "^4.0.0" | ||
|
||
cross-env@^6.0.3: | ||
version "6.0.3" | ||
resolved "https://registry.yarnpkg.com/cross-env/-/cross-env-6.0.3.tgz#4256b71e49b3a40637a0ce70768a6ef5c72ae941" | ||
integrity sha512-+KqxF6LCvfhWvADcDPqo64yVIB31gv/jQulX2NGzKS/g3GEVz6/pt4wjHFtFWsHMddebWD/sDthJemzM4MaAag== | ||
dependencies: | ||
cross-spawn "^7.0.0" | ||
|
||
cross-spawn@^6.0.0, cross-spawn@^6.0.5: | ||
version "6.0.5" | ||
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-6.0.5.tgz#4a5ec7c64dfae22c3a14124dbacdee846d80cbc4" | ||
|
@@ -990,6 +997,15 @@ cross-spawn@^6.0.0, cross-spawn@^6.0.5: | |
shebang-command "^1.2.0" | ||
which "^1.2.9" | ||
|
||
cross-spawn@^7.0.0: | ||
version "7.0.1" | ||
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.1.tgz#0ab56286e0f7c24e153d04cc2aa027e43a9a5d14" | ||
integrity sha512-u7v4o84SwFpD32Z8IIcPZ6z1/ie24O6RU3RbtL5Y316l3KuHVPx9ItBgWQ6VlfAFnRnTtMUrsQ9MUUTuEZjogg== | ||
dependencies: | ||
path-key "^3.1.0" | ||
shebang-command "^2.0.0" | ||
which "^2.0.1" | ||
|
||
[email protected], "cssom@>= 0.3.2 < 0.4.0": | ||
version "0.3.8" | ||
resolved "https://registry.yarnpkg.com/cssom/-/cssom-0.3.8.tgz#9f1276f5b2b463f2114d3f2c75250af8c1a36f4a" | ||
|
@@ -3280,6 +3296,11 @@ path-key@^3.0.0: | |
resolved "https://registry.yarnpkg.com/path-key/-/path-key-3.1.0.tgz#99a10d870a803bdd5ee6f0470e58dfcd2f9a54d3" | ||
integrity sha512-8cChqz0RP6SHJkMt48FW0A7+qUOn+OsnOsVtzI59tZ8m+5bCSk7hzwET0pulwOM2YMn9J1efb07KB9l9f30SGg== | ||
|
||
path-key@^3.1.0: | ||
version "3.1.1" | ||
resolved "https://registry.yarnpkg.com/path-key/-/path-key-3.1.1.tgz#581f6ade658cbba65a0d3380de7753295054f375" | ||
integrity sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q== | ||
|
||
path-parse@^1.0.6: | ||
version "1.0.6" | ||
resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.6.tgz#d62dbb5679405d72c4737ec58600e9ddcf06d24c" | ||
|
@@ -3737,11 +3758,23 @@ shebang-command@^1.2.0: | |
dependencies: | ||
shebang-regex "^1.0.0" | ||
|
||
shebang-command@^2.0.0: | ||
version "2.0.0" | ||
resolved "https://registry.yarnpkg.com/shebang-command/-/shebang-command-2.0.0.tgz#ccd0af4f8835fbdc265b82461aaf0c36663f34ea" | ||
integrity sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA== | ||
dependencies: | ||
shebang-regex "^3.0.0" | ||
|
||
shebang-regex@^1.0.0: | ||
version "1.0.0" | ||
resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-1.0.0.tgz#da42f49740c0b42db2ca9728571cb190c98efea3" | ||
integrity sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM= | ||
|
||
shebang-regex@^3.0.0: | ||
version "3.0.0" | ||
resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-3.0.0.tgz#ae16f1644d873ecad843b0307b143362d4c42172" | ||
integrity sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A== | ||
|
||
shellwords@^0.1.1: | ||
version "0.1.1" | ||
resolved "https://registry.yarnpkg.com/shellwords/-/shellwords-0.1.1.tgz#d6b9181c1a48d397324c84871efbcfc73fc0654b" | ||
|
@@ -4385,6 +4418,13 @@ which@^1.2.9, which@^1.3.0: | |
dependencies: | ||
isexe "^2.0.0" | ||
|
||
which@^2.0.1: | ||
version "2.0.2" | ||
resolved "https://registry.yarnpkg.com/which/-/which-2.0.2.tgz#7c6a8dd0a636a0327e10b59c9286eee93f3f51b1" | ||
integrity sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA== | ||
dependencies: | ||
isexe "^2.0.0" | ||
|
||
wide-align@^1.1.0: | ||
version "1.1.3" | ||
resolved "https://registry.yarnpkg.com/wide-align/-/wide-align-1.1.3.tgz#ae074e6bdc0c14a431e804e624549c633b000457" | ||
|