quidproquo-deploy-awscdk 0.0.87 → 0.0.89
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/constructs/feature/core/auth/QpqCoreUserDirectoryConstruct.js +24 -1
- package/lib/lambdas/lambdaCognitoTriggerEvent_CustomMessage.d.ts +11 -0
- package/lib/lambdas/lambdaCognitoTriggerEvent_CustomMessage.js +53 -0
- package/package.json +4 -3
- package/src/constructs/feature/core/auth/QpqCoreUserDirectoryConstruct.ts +43 -3
- package/src/lambdas/lambdaCognitoTriggerEvent_CustomMessage.ts +65 -0
|
@@ -24,11 +24,13 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.QpqCoreUserDirectoryConstruct = exports.QpqCoreUserDirectoryConstructBase = void 0;
|
|
27
|
+
const quidproquo_core_1 = require("quidproquo-core");
|
|
27
28
|
const quidproquo_actionprocessor_awslambda_1 = require("quidproquo-actionprocessor-awslambda");
|
|
28
29
|
const QpqConstructBlock_1 = require("../../../base/QpqConstructBlock");
|
|
29
30
|
const aws_cdk_lib_1 = require("aws-cdk-lib");
|
|
30
31
|
const cdk = __importStar(require("aws-cdk-lib"));
|
|
31
32
|
const qpqDeployAwsCdkUtils = __importStar(require("../../../../utils"));
|
|
33
|
+
const Function_1 = require("../../../basic/Function");
|
|
32
34
|
class QpqCoreUserDirectoryConstructBase extends QpqConstructBlock_1.QpqConstructBlock {
|
|
33
35
|
grantRead(grantee) {
|
|
34
36
|
this.userPool.grant(grantee, 'cognito-idp:ListUsers', 'cognito-idp:GetUser', 'cognito-idp:ListGroups', 'cognito-idp:GetGroup', 'cognito-idp:ListUserPools', 'cognito-idp:DescribeUserPool', 'cognito-idp:DescribeUserPoolClient');
|
|
@@ -55,7 +57,7 @@ class QpqCoreUserDirectoryConstruct extends QpqCoreUserDirectoryConstructBase {
|
|
|
55
57
|
}
|
|
56
58
|
constructor(scope, id, props) {
|
|
57
59
|
super(scope, id, props);
|
|
58
|
-
|
|
60
|
+
const userPool = new aws_cdk_lib_1.aws_cognito.UserPool(this, 'user-pool', {
|
|
59
61
|
removalPolicy: cdk.RemovalPolicy.DESTROY,
|
|
60
62
|
userPoolName: this.resourceName(props.userDirectoryConfig.name),
|
|
61
63
|
selfSignUpEnabled: props.userDirectoryConfig.selfSignUpEnabled,
|
|
@@ -74,6 +76,27 @@ class QpqCoreUserDirectoryConstruct extends QpqCoreUserDirectoryConstructBase {
|
|
|
74
76
|
phone: props.userDirectoryConfig.phoneRequired,
|
|
75
77
|
},
|
|
76
78
|
});
|
|
79
|
+
this.userPool = userPool;
|
|
80
|
+
// const lambdaFunction = new aws_lambda.Function(this, 'csm-msg-trigger', {
|
|
81
|
+
// functionName: this.qpqResourceName(`${props.userDirectoryConfig.name}`, 'csm-msg'),
|
|
82
|
+
// timeout: cdk.Duration.seconds(25),
|
|
83
|
+
// runtime: aws_lambda.Runtime.NODEJS_18_X,
|
|
84
|
+
// memorySize: 256,
|
|
85
|
+
// code: aws_lambda.Code.fromAsset(path.join(__dirname, '../../../../lambdas')),
|
|
86
|
+
// handler: `lambdaCognitoTriggerEvent_CustomMessage.executeCognitoTriggerEvent`,
|
|
87
|
+
// });
|
|
88
|
+
const customMessageTrigger = new Function_1.Function(this, 'csm-msg-trigger-func', {
|
|
89
|
+
buildPath: quidproquo_core_1.qpqCoreUtils.getUserDirectoryEntryFullPath(props.qpqConfig, props.userDirectoryConfig),
|
|
90
|
+
functionName: this.qpqResourceName(`${props.userDirectoryConfig.name}`, 'cm-trig'),
|
|
91
|
+
functionType: 'lambdaCognitoTriggerEvent_CustomMessage',
|
|
92
|
+
executorName: 'executeCognitoTriggerEvent',
|
|
93
|
+
qpqConfig: props.qpqConfig,
|
|
94
|
+
environment: {
|
|
95
|
+
userDirectoryName: props.userDirectoryConfig.name,
|
|
96
|
+
},
|
|
97
|
+
awsAccountId: props.awsAccountId,
|
|
98
|
+
});
|
|
99
|
+
userPool.addTrigger(aws_cdk_lib_1.aws_cognito.UserPoolOperation.CUSTOM_MESSAGE, customMessageTrigger.lambdaFunction);
|
|
77
100
|
qpqDeployAwsCdkUtils.exportStackValue(this, quidproquo_actionprocessor_awslambda_1.awsNamingUtils.getCFExportNameUserPoolIdFromConfig(props.userDirectoryConfig.name, props.qpqConfig), this.userPool.userPoolId);
|
|
78
101
|
const userPoolClient = new aws_cdk_lib_1.aws_cognito.UserPoolClient(this, 'user-pool-client', {
|
|
79
102
|
userPoolClientName: this.qpqResourceName(props.userDirectoryConfig.name, 'upc'),
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { CustomMessageTriggerEvent, Context } from 'aws-lambda';
|
|
2
|
+
import { EmailTemplates } from 'quidproquo-core';
|
|
3
|
+
export interface EmailPayload {
|
|
4
|
+
username: string;
|
|
5
|
+
code: string;
|
|
6
|
+
userAttributes: Record<string, string>;
|
|
7
|
+
baseDomain: string;
|
|
8
|
+
}
|
|
9
|
+
export declare const renderTemplate: (template: string, data: EmailPayload) => Promise<any>;
|
|
10
|
+
export declare const getTemplates: () => EmailTemplates;
|
|
11
|
+
export declare const executeCognitoTriggerEvent: (event: CustomMessageTriggerEvent, context: Context) => Promise<CustomMessageTriggerEvent>;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.executeCognitoTriggerEvent = exports.getTemplates = exports.renderTemplate = void 0;
|
|
16
|
+
const liquidjs_1 = require("liquidjs");
|
|
17
|
+
// @ts-ignore - Special webpack loader
|
|
18
|
+
const qpq_user_directory_email_templates_1 = __importDefault(require("qpq-user-directory-email-templates!"));
|
|
19
|
+
const renderTemplate = (template, data) => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
|
+
const engine = new liquidjs_1.Liquid();
|
|
21
|
+
const output = yield engine.parseAndRender(template, data);
|
|
22
|
+
return output;
|
|
23
|
+
});
|
|
24
|
+
exports.renderTemplate = renderTemplate;
|
|
25
|
+
const getTemplates = () => {
|
|
26
|
+
const emailTemplates = qpq_user_directory_email_templates_1.default;
|
|
27
|
+
const templates = emailTemplates[process.env.userDirectoryName];
|
|
28
|
+
return templates;
|
|
29
|
+
};
|
|
30
|
+
exports.getTemplates = getTemplates;
|
|
31
|
+
const executeCognitoTriggerEvent = (event, context) => __awaiter(void 0, void 0, void 0, function* () {
|
|
32
|
+
console.log(`executeCognitoTriggerEvent: Started [${event.triggerSource}]`, JSON.stringify(event, null, 2));
|
|
33
|
+
const params = {
|
|
34
|
+
baseDomain: 'joecoady.development.kitted.app',
|
|
35
|
+
code: event.request.codeParameter,
|
|
36
|
+
userAttributes: event.request.userAttributes,
|
|
37
|
+
username: event.userName,
|
|
38
|
+
};
|
|
39
|
+
const templates = (0, exports.getTemplates)();
|
|
40
|
+
switch (event.triggerSource) {
|
|
41
|
+
case 'CustomMessage_ForgotPassword':
|
|
42
|
+
event.response.emailMessage = yield (0, exports.renderTemplate)(templates.resetPassword.body, params);
|
|
43
|
+
event.response.emailSubject = yield (0, exports.renderTemplate)(templates.resetPassword.subject, params);
|
|
44
|
+
break;
|
|
45
|
+
case 'CustomMessage_VerifyUserAttribute':
|
|
46
|
+
event.response.emailMessage = yield (0, exports.renderTemplate)(templates.verifyEmail.body, params);
|
|
47
|
+
event.response.emailSubject = yield (0, exports.renderTemplate)(templates.verifyEmail.subject, params);
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
console.log('executeCognitoTriggerEvent: Ended');
|
|
51
|
+
return event;
|
|
52
|
+
});
|
|
53
|
+
exports.executeCognitoTriggerEvent = executeCognitoTriggerEvent;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "quidproquo-deploy-awscdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.89",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.js",
|
|
@@ -26,10 +26,11 @@
|
|
|
26
26
|
},
|
|
27
27
|
"homepage": "https://github.com/joe-coady/quidproquo#readme",
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"aws-cdk-lib": "^2.58.1",
|
|
30
29
|
"aws-cdk": "^2.58.1",
|
|
30
|
+
"aws-cdk-lib": "^2.58.1",
|
|
31
31
|
"constructs": "^10.1.208",
|
|
32
32
|
"esbuild": "^0.15.16",
|
|
33
|
+
"liquidjs": "^10.7.0",
|
|
33
34
|
"quidproquo-actionprocessor-awslambda": "*",
|
|
34
35
|
"quidproquo-actionprocessor-node": "*",
|
|
35
36
|
"quidproquo-core": "*",
|
|
@@ -40,8 +41,8 @@
|
|
|
40
41
|
"@types/babel__traverse": "7.18.2",
|
|
41
42
|
"@types/node": "^10.17.60",
|
|
42
43
|
"@types/prettier": "2.6.0",
|
|
43
|
-
"ts-node": "^10.9.1",
|
|
44
44
|
"quidproquo-tsconfig": "*",
|
|
45
|
+
"ts-node": "^10.9.1",
|
|
45
46
|
"typescript": "^4.9.3"
|
|
46
47
|
}
|
|
47
48
|
}
|
|
@@ -1,15 +1,19 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as path from 'path';
|
|
2
|
+
|
|
3
|
+
import { QPQConfig, UserDirectoryQPQConfigSetting, qpqCoreUtils } from 'quidproquo-core';
|
|
2
4
|
import { awsNamingUtils } from 'quidproquo-actionprocessor-awslambda';
|
|
3
5
|
|
|
4
6
|
import { QpqConstructBlock, QpqConstructBlockProps } from '../../../base/QpqConstructBlock';
|
|
5
7
|
import { QpqResource } from '../../../base/QpqResource';
|
|
6
8
|
|
|
7
9
|
import { Construct } from 'constructs';
|
|
8
|
-
import { aws_iam, aws_cognito } from 'aws-cdk-lib';
|
|
10
|
+
import { aws_iam, aws_cognito, aws_lambda } from 'aws-cdk-lib';
|
|
9
11
|
import * as cdk from 'aws-cdk-lib';
|
|
10
12
|
|
|
11
13
|
import * as qpqDeployAwsCdkUtils from '../../../../utils';
|
|
12
14
|
|
|
15
|
+
import { Function } from '../../../basic/Function';
|
|
16
|
+
|
|
13
17
|
export interface QpqCoreUserDirectoryConstructProps extends QpqConstructBlockProps {
|
|
14
18
|
userDirectoryConfig: UserDirectoryQPQConfigSetting;
|
|
15
19
|
}
|
|
@@ -86,7 +90,7 @@ export class QpqCoreUserDirectoryConstruct extends QpqCoreUserDirectoryConstruct
|
|
|
86
90
|
constructor(scope: Construct, id: string, props: QpqCoreUserDirectoryConstructProps) {
|
|
87
91
|
super(scope, id, props);
|
|
88
92
|
|
|
89
|
-
|
|
93
|
+
const userPool = new aws_cognito.UserPool(this, 'user-pool', {
|
|
90
94
|
removalPolicy: cdk.RemovalPolicy.DESTROY,
|
|
91
95
|
userPoolName: this.resourceName(props.userDirectoryConfig.name),
|
|
92
96
|
selfSignUpEnabled: props.userDirectoryConfig.selfSignUpEnabled,
|
|
@@ -106,6 +110,42 @@ export class QpqCoreUserDirectoryConstruct extends QpqCoreUserDirectoryConstruct
|
|
|
106
110
|
},
|
|
107
111
|
});
|
|
108
112
|
|
|
113
|
+
this.userPool = userPool;
|
|
114
|
+
|
|
115
|
+
// const lambdaFunction = new aws_lambda.Function(this, 'csm-msg-trigger', {
|
|
116
|
+
// functionName: this.qpqResourceName(`${props.userDirectoryConfig.name}`, 'csm-msg'),
|
|
117
|
+
// timeout: cdk.Duration.seconds(25),
|
|
118
|
+
|
|
119
|
+
// runtime: aws_lambda.Runtime.NODEJS_18_X,
|
|
120
|
+
// memorySize: 256,
|
|
121
|
+
|
|
122
|
+
// code: aws_lambda.Code.fromAsset(path.join(__dirname, '../../../../lambdas')),
|
|
123
|
+
// handler: `lambdaCognitoTriggerEvent_CustomMessage.executeCognitoTriggerEvent`,
|
|
124
|
+
// });
|
|
125
|
+
|
|
126
|
+
const customMessageTrigger = new Function(this, 'csm-msg-trigger-func', {
|
|
127
|
+
buildPath: qpqCoreUtils.getUserDirectoryEntryFullPath(
|
|
128
|
+
props.qpqConfig,
|
|
129
|
+
props.userDirectoryConfig,
|
|
130
|
+
),
|
|
131
|
+
functionName: this.qpqResourceName(`${props.userDirectoryConfig.name}`, 'cm-trig'),
|
|
132
|
+
functionType: 'lambdaCognitoTriggerEvent_CustomMessage',
|
|
133
|
+
executorName: 'executeCognitoTriggerEvent',
|
|
134
|
+
|
|
135
|
+
qpqConfig: props.qpqConfig,
|
|
136
|
+
|
|
137
|
+
environment: {
|
|
138
|
+
userDirectoryName: props.userDirectoryConfig.name,
|
|
139
|
+
},
|
|
140
|
+
|
|
141
|
+
awsAccountId: props.awsAccountId,
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
userPool.addTrigger(
|
|
145
|
+
aws_cognito.UserPoolOperation.CUSTOM_MESSAGE,
|
|
146
|
+
customMessageTrigger.lambdaFunction,
|
|
147
|
+
);
|
|
148
|
+
|
|
109
149
|
qpqDeployAwsCdkUtils.exportStackValue(
|
|
110
150
|
this,
|
|
111
151
|
awsNamingUtils.getCFExportNameUserPoolIdFromConfig(
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { CustomMessageTriggerEvent, Context } from 'aws-lambda';
|
|
2
|
+
import { Liquid } from 'liquidjs';
|
|
3
|
+
|
|
4
|
+
import { EmailTemplates } from 'quidproquo-core';
|
|
5
|
+
|
|
6
|
+
// @ts-ignore - Special webpack loader
|
|
7
|
+
import qpqEmailTemplates from 'qpq-user-directory-email-templates!';
|
|
8
|
+
|
|
9
|
+
export interface EmailPayload {
|
|
10
|
+
username: string;
|
|
11
|
+
code: string;
|
|
12
|
+
|
|
13
|
+
userAttributes: Record<string, string>;
|
|
14
|
+
baseDomain: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const renderTemplate = async (template: string, data: EmailPayload) => {
|
|
18
|
+
const engine = new Liquid();
|
|
19
|
+
|
|
20
|
+
const output = await engine.parseAndRender(template, data);
|
|
21
|
+
|
|
22
|
+
return output;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const getTemplates = (): EmailTemplates => {
|
|
26
|
+
const emailTemplates: Record<string, EmailTemplates> = qpqEmailTemplates;
|
|
27
|
+
const templates = emailTemplates[process.env.userDirectoryName!];
|
|
28
|
+
|
|
29
|
+
return templates;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export const executeCognitoTriggerEvent = async (
|
|
33
|
+
event: CustomMessageTriggerEvent,
|
|
34
|
+
context: Context,
|
|
35
|
+
) => {
|
|
36
|
+
console.log(
|
|
37
|
+
`executeCognitoTriggerEvent: Started [${event.triggerSource}]`,
|
|
38
|
+
JSON.stringify(event, null, 2),
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
const params = {
|
|
42
|
+
baseDomain: 'joecoady.development.kitted.app',
|
|
43
|
+
code: event.request.codeParameter,
|
|
44
|
+
userAttributes: event.request.userAttributes,
|
|
45
|
+
username: event.userName,
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const templates = getTemplates();
|
|
49
|
+
|
|
50
|
+
switch (event.triggerSource) {
|
|
51
|
+
case 'CustomMessage_ForgotPassword':
|
|
52
|
+
event.response.emailMessage = await renderTemplate(templates.resetPassword!.body, params);
|
|
53
|
+
event.response.emailSubject = await renderTemplate(templates.resetPassword!.subject, params);
|
|
54
|
+
break;
|
|
55
|
+
|
|
56
|
+
case 'CustomMessage_VerifyUserAttribute':
|
|
57
|
+
event.response.emailMessage = await renderTemplate(templates.verifyEmail!.body, params);
|
|
58
|
+
event.response.emailSubject = await renderTemplate(templates.verifyEmail!.subject, params);
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
console.log('executeCognitoTriggerEvent: Ended');
|
|
63
|
+
|
|
64
|
+
return event;
|
|
65
|
+
};
|