quidproquo-actionprocessor-awslambda 0.0.71 → 0.0.73
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/awsNamingUtils.d.ts +6 -2
- package/lib/awsNamingUtils.js +36 -8
- package/lib/getActionProcessor/core/event/getAPIGatewayEventActionProcessor.d.ts +10 -8
- package/lib/getActionProcessor/core/event/getAPIGatewayEventActionProcessor.js +45 -20
- package/lib/getActionProcessor/core/event/getCloudFrontOriginRequestEventActionProcessor.d.ts +7 -6
- package/lib/getActionProcessor/core/event/getCloudFrontOriginRequestEventActionProcessor.js +2 -1
- package/lib/getActionProcessor/core/event/getEventBridgeEventActionProcessor.d.ts +6 -3
- package/lib/getActionProcessor/core/event/getEventBridgeEventActionProcessor.js +1 -1
- package/lib/getActionProcessor/core/event/getSQSEventRecordActionProcessor.d.ts +8 -7
- package/lib/getActionProcessor/core/event/getSQSEventRecordActionProcessor.js +2 -1
- package/lib/getActionProcessor/core/event/utils/isAuthValid.d.ts +3 -0
- package/lib/getActionProcessor/core/event/utils/isAuthValid.js +41 -0
- package/lib/getActionProcessor/core/index.d.ts +1 -0
- package/lib/getActionProcessor/core/index.js +3 -1
- package/lib/getActionProcessor/core/userDirectory/getUserDirectoryAuthenticateUserActionProcessor.d.ts +5 -0
- package/lib/getActionProcessor/core/userDirectory/getUserDirectoryAuthenticateUserActionProcessor.js +29 -0
- package/lib/getActionProcessor/core/userDirectory/getUserDirectoryCreateUserActionProcessor.d.ts +5 -0
- package/lib/getActionProcessor/core/userDirectory/getUserDirectoryCreateUserActionProcessor.js +28 -0
- package/lib/getActionProcessor/core/userDirectory/index.d.ts +6 -0
- package/lib/getActionProcessor/core/userDirectory/index.js +8 -0
- package/lib/logic/cloudformation/getExportedValue.d.ts +1 -0
- package/lib/logic/cloudformation/getExportedValue.js +29 -0
- package/lib/logic/cognito/authenticateUser.d.ts +2 -0
- package/lib/logic/cognito/authenticateUser.js +50 -0
- package/lib/logic/cognito/createUser.d.ts +2 -0
- package/lib/logic/cognito/createUser.js +42 -0
- package/lib/logic/cognito/getUser.d.ts +10 -0
- package/lib/logic/cognito/getUser.js +37 -0
- package/lib/logic/cognito/getUserPoolClientSecret.d.ts +1 -0
- package/lib/logic/cognito/getUserPoolClientSecret.js +27 -0
- package/lib/logic/cognito/utils/calculateSecretHash.d.ts +1 -0
- package/lib/logic/cognito/utils/calculateSecretHash.js +13 -0
- package/lib/logic/cognito/verifyJwt.d.ts +1 -0
- package/lib/logic/cognito/verifyJwt.js +30 -0
- package/lib/logic/s3/deleteFiles.js +1 -2
- package/lib/runtimeConfig/qpqAwsLambdaRuntimeConfigUtils.js +3 -3
- package/package.json +5 -2
package/lib/awsNamingUtils.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
import { QPQConfig } from 'quidproquo-core';
|
|
2
|
-
export declare const getConfigRuntimeResourceName: (resourceName: string,
|
|
3
|
-
export declare const
|
|
2
|
+
export declare const getConfigRuntimeResourceName: (resourceName: string, application: string, service: string, environment: string, feature?: string) => string;
|
|
3
|
+
export declare const getConfigRuntimeResourceNameFromConfig: (resourceName: string, qpqConfig: QPQConfig) => string;
|
|
4
|
+
export declare const getQpqRuntimeResourceName: (resourceName: string, application: string, service: string, environment: string, feature?: string, resourceType?: string) => string;
|
|
5
|
+
export declare const getQpqRuntimeResourceNameFromConfig: (resourceName: string, qpqConfig: QPQConfig, resourceType?: string) => string;
|
|
6
|
+
export declare const getCFExportNameUserPoolIdFromConfig: (userDirectoryName: string, qpqConfig: QPQConfig, serviceOverride?: string, applicationOverride?: string) => string;
|
|
7
|
+
export declare const getCFExportNameUserPoolClientIdFromConfig: (userDirectoryName: string, qpqConfig: QPQConfig, serviceOverride?: string, applicationOverride?: string) => string;
|
package/lib/awsNamingUtils.js
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getQpqRuntimeResourceName = exports.getConfigRuntimeResourceName = void 0;
|
|
3
|
+
exports.getCFExportNameUserPoolClientIdFromConfig = exports.getCFExportNameUserPoolIdFromConfig = exports.getQpqRuntimeResourceNameFromConfig = exports.getQpqRuntimeResourceName = exports.getConfigRuntimeResourceNameFromConfig = exports.getConfigRuntimeResourceName = void 0;
|
|
4
4
|
const quidproquo_core_1 = require("quidproquo-core");
|
|
5
|
-
const getConfigRuntimeResourceName = (resourceName,
|
|
6
|
-
const application = quidproquo_core_1.qpqCoreUtils.getApplicationName(qpqConfig);
|
|
7
|
-
const service = quidproquo_core_1.qpqCoreUtils.getApplicationModuleName(qpqConfig);
|
|
8
|
-
const environment = quidproquo_core_1.qpqCoreUtils.getApplicationModuleEnvironment(qpqConfig);
|
|
9
|
-
const feature = quidproquo_core_1.qpqCoreUtils.getApplicationModuleFeature(qpqConfig);
|
|
5
|
+
const getConfigRuntimeResourceName = (resourceName, application, service, environment, feature) => {
|
|
10
6
|
const baseName = `${resourceName}-${application}-${service}-${environment}`;
|
|
11
7
|
if (feature) {
|
|
12
8
|
return `${baseName}-${feature}`;
|
|
@@ -14,8 +10,40 @@ const getConfigRuntimeResourceName = (resourceName, qpqConfig, resourceType = ''
|
|
|
14
10
|
return baseName;
|
|
15
11
|
};
|
|
16
12
|
exports.getConfigRuntimeResourceName = getConfigRuntimeResourceName;
|
|
17
|
-
const
|
|
18
|
-
const
|
|
13
|
+
const getConfigRuntimeResourceNameFromConfig = (resourceName, qpqConfig) => {
|
|
14
|
+
const application = quidproquo_core_1.qpqCoreUtils.getApplicationName(qpqConfig);
|
|
15
|
+
const service = quidproquo_core_1.qpqCoreUtils.getApplicationModuleName(qpqConfig);
|
|
16
|
+
const environment = quidproquo_core_1.qpqCoreUtils.getApplicationModuleEnvironment(qpqConfig);
|
|
17
|
+
const feature = quidproquo_core_1.qpqCoreUtils.getApplicationModuleFeature(qpqConfig);
|
|
18
|
+
return (0, exports.getConfigRuntimeResourceName)(resourceName, application, service, environment, feature);
|
|
19
|
+
};
|
|
20
|
+
exports.getConfigRuntimeResourceNameFromConfig = getConfigRuntimeResourceNameFromConfig;
|
|
21
|
+
const getQpqRuntimeResourceName = (resourceName, application, service, environment, feature, resourceType = '') => {
|
|
22
|
+
const name = (0, exports.getConfigRuntimeResourceName)(resourceName, application, service, environment, feature);
|
|
19
23
|
return `${name}-qpq${resourceType}`;
|
|
20
24
|
};
|
|
21
25
|
exports.getQpqRuntimeResourceName = getQpqRuntimeResourceName;
|
|
26
|
+
const getQpqRuntimeResourceNameFromConfig = (resourceName, qpqConfig, resourceType = '') => {
|
|
27
|
+
const application = quidproquo_core_1.qpqCoreUtils.getApplicationName(qpqConfig);
|
|
28
|
+
const service = quidproquo_core_1.qpqCoreUtils.getApplicationModuleName(qpqConfig);
|
|
29
|
+
const environment = quidproquo_core_1.qpqCoreUtils.getApplicationModuleEnvironment(qpqConfig);
|
|
30
|
+
const feature = quidproquo_core_1.qpqCoreUtils.getApplicationModuleFeature(qpqConfig);
|
|
31
|
+
return (0, exports.getQpqRuntimeResourceName)(resourceName, application, service, environment, feature, resourceType);
|
|
32
|
+
};
|
|
33
|
+
exports.getQpqRuntimeResourceNameFromConfig = getQpqRuntimeResourceNameFromConfig;
|
|
34
|
+
const getCFExportNameUserPoolIdFromConfig = (userDirectoryName, qpqConfig, serviceOverride, applicationOverride) => {
|
|
35
|
+
const application = applicationOverride || quidproquo_core_1.qpqCoreUtils.getApplicationName(qpqConfig);
|
|
36
|
+
const service = serviceOverride || quidproquo_core_1.qpqCoreUtils.getApplicationModuleName(qpqConfig);
|
|
37
|
+
const environment = quidproquo_core_1.qpqCoreUtils.getApplicationModuleEnvironment(qpqConfig);
|
|
38
|
+
const feature = quidproquo_core_1.qpqCoreUtils.getApplicationModuleFeature(qpqConfig);
|
|
39
|
+
return (0, exports.getQpqRuntimeResourceName)(userDirectoryName, application, service, environment, feature, 'user-pool-id-export');
|
|
40
|
+
};
|
|
41
|
+
exports.getCFExportNameUserPoolIdFromConfig = getCFExportNameUserPoolIdFromConfig;
|
|
42
|
+
const getCFExportNameUserPoolClientIdFromConfig = (userDirectoryName, qpqConfig, serviceOverride, applicationOverride) => {
|
|
43
|
+
const application = applicationOverride || quidproquo_core_1.qpqCoreUtils.getApplicationName(qpqConfig);
|
|
44
|
+
const service = serviceOverride || quidproquo_core_1.qpqCoreUtils.getApplicationModuleName(qpqConfig);
|
|
45
|
+
const environment = quidproquo_core_1.qpqCoreUtils.getApplicationModuleEnvironment(qpqConfig);
|
|
46
|
+
const feature = quidproquo_core_1.qpqCoreUtils.getApplicationModuleFeature(qpqConfig);
|
|
47
|
+
return (0, exports.getQpqRuntimeResourceName)(userDirectoryName, application, service, environment, feature, 'user-pool-client-id-export');
|
|
48
|
+
};
|
|
49
|
+
exports.getCFExportNameUserPoolClientIdFromConfig = getCFExportNameUserPoolClientIdFromConfig;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { QPQConfig, EventMatchStoryActionProcessor, EventTransformEventParamsActionProcessor, EventTransformResponseResultActionProcessor, EventAutoRespondActionProcessor } from 'quidproquo-core';
|
|
2
|
-
import {
|
|
3
|
-
import { Context, APIGatewayProxyResult } from 'aws-lambda';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
"@quidproquo-core/event/
|
|
8
|
-
"@quidproquo-core/event/
|
|
1
|
+
import { QPQConfig, MatchStoryResult, EventMatchStoryActionProcessor, EventTransformEventParamsActionProcessor, EventTransformResponseResultActionProcessor, EventAutoRespondActionProcessor } from 'quidproquo-core';
|
|
2
|
+
import { HTTPEvent, HTTPEventResponse, HttpEventRouteParams, RouteOptions } from 'quidproquo-webserver';
|
|
3
|
+
import { APIGatewayEvent, Context, APIGatewayProxyResult } from 'aws-lambda';
|
|
4
|
+
export type HttpRouteMatchStoryResult = MatchStoryResult<HttpEventRouteParams, RouteOptions>;
|
|
5
|
+
export type ApiGatewayEventParams = [APIGatewayEvent, Context];
|
|
6
|
+
declare const _default: (qpqConfig: QPQConfig) => {
|
|
7
|
+
"@quidproquo-core/event/TransformEventParams": EventTransformEventParamsActionProcessor<ApiGatewayEventParams, HTTPEvent<any>>;
|
|
8
|
+
"@quidproquo-core/event/TransformResponseResult": EventTransformResponseResultActionProcessor<HTTPEventResponse<string>, HTTPEvent<string>, APIGatewayProxyResult>;
|
|
9
|
+
"@quidproquo-core/event/AutoRespond": EventAutoRespondActionProcessor<HTTPEvent<any>, HttpRouteMatchStoryResult, HTTPEventResponse<string> | null>;
|
|
10
|
+
"@quidproquo-core/event/MatchStory": EventMatchStoryActionProcessor<HTTPEvent<any>, HttpRouteMatchStoryResult>;
|
|
9
11
|
};
|
|
10
12
|
export default _default;
|
|
@@ -12,10 +12,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
const quidproquo_core_1 = require("quidproquo-core");
|
|
13
13
|
const quidproquo_webserver_1 = require("quidproquo-webserver");
|
|
14
14
|
const awsLambdaUtils_1 = require("../../../awsLambdaUtils");
|
|
15
|
+
const isAuthValid_1 = require("./utils/isAuthValid");
|
|
16
|
+
const transformHttpEventHeadersToAPIGatewayProxyResultHeaders = (headers) => {
|
|
17
|
+
return Object.keys(headers)
|
|
18
|
+
.filter((header) => !!headers[header])
|
|
19
|
+
.reduce((acc, header) => (Object.assign(Object.assign({}, acc), { [header]: headers[header] })), {});
|
|
20
|
+
};
|
|
15
21
|
const getProcessTransformEventParams = (serviceName) => {
|
|
16
22
|
return ({ eventParams: [apiGatewayEvent, context] }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
23
|
const path = (apiGatewayEvent.path || '').replace(new RegExp(`^(\/${serviceName})/`), '/');
|
|
18
|
-
|
|
24
|
+
const transformedEventParams = {
|
|
19
25
|
path,
|
|
20
26
|
query: Object.assign(Object.assign({}, (apiGatewayEvent.multiValueQueryStringParameters || {})), (apiGatewayEvent.queryStringParameters || {})),
|
|
21
27
|
body: apiGatewayEvent.body,
|
|
@@ -24,40 +30,57 @@ const getProcessTransformEventParams = (serviceName) => {
|
|
|
24
30
|
correlation: context.awsRequestId,
|
|
25
31
|
sourceIp: apiGatewayEvent.requestContext.identity.sourceIp,
|
|
26
32
|
isBase64Encoded: apiGatewayEvent.isBase64Encoded,
|
|
27
|
-
}
|
|
33
|
+
};
|
|
34
|
+
console.log(JSON.stringify(transformedEventParams, null, 2));
|
|
35
|
+
return (0, quidproquo_core_1.actionResult)(transformedEventParams);
|
|
28
36
|
});
|
|
29
37
|
};
|
|
30
|
-
const getProcessTransformResponseResult = (
|
|
38
|
+
const getProcessTransformResponseResult = (qpqConfig) => {
|
|
31
39
|
// We might need to JSON.stringify the body.
|
|
32
40
|
return (payload) => __awaiter(void 0, void 0, void 0, function* () {
|
|
33
41
|
var _a;
|
|
42
|
+
const headers = Object.assign(Object.assign({}, quidproquo_webserver_1.qpqWebServerUtils.getCorsHeaders(qpqConfig, {}, payload.transformedEventParams.headers)), (((_a = payload === null || payload === void 0 ? void 0 : payload.response) === null || _a === void 0 ? void 0 : _a.headers) || {}));
|
|
34
43
|
return (0, quidproquo_core_1.actionResult)({
|
|
35
44
|
statusCode: payload.response.status,
|
|
36
|
-
body: payload.response.body,
|
|
45
|
+
body: payload.response.body || '',
|
|
37
46
|
isBase64Encoded: payload.response.isBase64Encoded,
|
|
38
|
-
headers:
|
|
47
|
+
headers: transformHttpEventHeadersToAPIGatewayProxyResultHeaders(headers),
|
|
39
48
|
});
|
|
40
49
|
});
|
|
41
50
|
};
|
|
42
|
-
const getProcessAutoRespond = (
|
|
51
|
+
const getProcessAutoRespond = (qpqConfig) => {
|
|
43
52
|
return (payload) => __awaiter(void 0, void 0, void 0, function* () {
|
|
53
|
+
var _a;
|
|
44
54
|
if (payload.transformedEventParams.method === 'OPTIONS') {
|
|
45
55
|
return (0, quidproquo_core_1.actionResult)({
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
},
|
|
56
|
+
status: 200,
|
|
57
|
+
isBase64Encoded: false,
|
|
58
|
+
body: '',
|
|
59
|
+
headers: quidproquo_webserver_1.qpqWebServerUtils.getCorsHeaders(qpqConfig, payload.matchResult.config || {}, payload.transformedEventParams.headers),
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
const authValid = yield (0, isAuthValid_1.isAuthValid)(qpqConfig, quidproquo_webserver_1.qpqWebServerUtils.getHeaderValue('Authorization', payload.transformedEventParams.headers), (_a = payload.matchResult.config) === null || _a === void 0 ? void 0 : _a.routeAuthSettings);
|
|
63
|
+
if (!authValid) {
|
|
64
|
+
return (0, quidproquo_core_1.actionResult)({
|
|
65
|
+
status: 401,
|
|
66
|
+
isBase64Encoded: false,
|
|
67
|
+
body: JSON.stringify({
|
|
68
|
+
message: 'You are unauthorized to access this resource',
|
|
69
|
+
}),
|
|
70
|
+
headers: quidproquo_webserver_1.qpqWebServerUtils.getCorsHeaders(qpqConfig, payload.matchResult.config || {}, payload.transformedEventParams.headers),
|
|
50
71
|
});
|
|
51
72
|
}
|
|
52
73
|
return (0, quidproquo_core_1.actionResult)(null);
|
|
53
74
|
});
|
|
54
75
|
};
|
|
55
|
-
const getProcessMatchStory = (
|
|
76
|
+
const getProcessMatchStory = (qpqConfig) => {
|
|
77
|
+
const routes = quidproquo_webserver_1.qpqWebServerUtils.getAllRoutes(qpqConfig);
|
|
56
78
|
return (payload) => __awaiter(void 0, void 0, void 0, function* () {
|
|
57
79
|
// Sort the routes by string length
|
|
58
80
|
// Note: We may need to filter variable routes out {} as the variables are length independent
|
|
59
81
|
const sortedRoutes = routes
|
|
60
|
-
.filter((r) => r.method === payload.transformedEventParams.method
|
|
82
|
+
.filter((r) => r.method === payload.transformedEventParams.method ||
|
|
83
|
+
payload.transformedEventParams.method === 'OPTIONS')
|
|
61
84
|
.sort((a, b) => {
|
|
62
85
|
if (a.path.length < b.path.length)
|
|
63
86
|
return -1;
|
|
@@ -73,22 +96,24 @@ const getProcessMatchStory = (routes) => {
|
|
|
73
96
|
}))
|
|
74
97
|
.find((m) => m.match.didMatch);
|
|
75
98
|
if (!matchedRoute) {
|
|
76
|
-
return (0, quidproquo_core_1.actionResultError)(quidproquo_core_1.ErrorTypeEnum.NotFound,
|
|
99
|
+
return (0, quidproquo_core_1.actionResultError)(quidproquo_core_1.ErrorTypeEnum.NotFound, `route not found [${payload.transformedEventParams.path}] - [${quidproquo_webserver_1.qpqWebServerUtils.getHeaderValue('user-agent', payload.transformedEventParams.headers)}]`);
|
|
77
100
|
}
|
|
78
101
|
return (0, quidproquo_core_1.actionResult)({
|
|
79
102
|
src: matchedRoute.route.src,
|
|
80
103
|
runtime: matchedRoute.route.runtime,
|
|
81
|
-
|
|
104
|
+
runtimeOptions: matchedRoute.match.params || {},
|
|
105
|
+
// TODO: Make this aware of the API that we are eventing
|
|
106
|
+
config: quidproquo_webserver_1.qpqWebServerUtils.mergeAllRouteOptions('api', matchedRoute.route, qpqConfig),
|
|
82
107
|
});
|
|
83
108
|
});
|
|
84
109
|
};
|
|
85
|
-
exports.default = (
|
|
86
|
-
|
|
87
|
-
const serviceName = quidproquo_core_1.qpqCoreUtils.getApplicationModuleName(
|
|
110
|
+
exports.default = (qpqConfig) => {
|
|
111
|
+
// TODO: Make this aware of the API that we are eventing
|
|
112
|
+
const serviceName = quidproquo_core_1.qpqCoreUtils.getApplicationModuleName(qpqConfig);
|
|
88
113
|
return {
|
|
89
114
|
[quidproquo_core_1.EventActionType.TransformEventParams]: getProcessTransformEventParams(serviceName),
|
|
90
|
-
[quidproquo_core_1.EventActionType.TransformResponseResult]: getProcessTransformResponseResult(
|
|
91
|
-
[quidproquo_core_1.EventActionType.AutoRespond]: getProcessAutoRespond(
|
|
92
|
-
[quidproquo_core_1.EventActionType.MatchStory]: getProcessMatchStory(
|
|
115
|
+
[quidproquo_core_1.EventActionType.TransformResponseResult]: getProcessTransformResponseResult(qpqConfig),
|
|
116
|
+
[quidproquo_core_1.EventActionType.AutoRespond]: getProcessAutoRespond(qpqConfig),
|
|
117
|
+
[quidproquo_core_1.EventActionType.MatchStory]: getProcessMatchStory(qpqConfig),
|
|
93
118
|
};
|
|
94
119
|
};
|
package/lib/getActionProcessor/core/event/getCloudFrontOriginRequestEventActionProcessor.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { QPQConfig, EventMatchStoryActionProcessor, EventTransformEventParamsActionProcessor, EventTransformResponseResultActionProcessor, EventAutoRespondActionProcessor } from 'quidproquo-core';
|
|
2
|
-
import {
|
|
1
|
+
import { QPQConfig, MatchStoryResult, EventMatchStoryActionProcessor, EventTransformEventParamsActionProcessor, EventTransformResponseResultActionProcessor, EventAutoRespondActionProcessor } from 'quidproquo-core';
|
|
2
|
+
import { SeoQPQWebServerConfigSetting, SeoEvent, SeoEventResponse, SeoEventRouteParams } from 'quidproquo-webserver';
|
|
3
3
|
import { CloudFrontRequestEvent, Context } from 'aws-lambda';
|
|
4
|
+
export type CloudFrontOriginMatchStoryResult = MatchStoryResult<SeoEventRouteParams, SeoQPQWebServerConfigSetting>;
|
|
4
5
|
declare const _default: (config: QPQConfig) => {
|
|
5
|
-
"@quidproquo-core/event/TransformEventParams": EventTransformEventParamsActionProcessor<[CloudFrontRequestEvent, Context],
|
|
6
|
-
"@quidproquo-core/event/TransformResponseResult": EventTransformResponseResultActionProcessor<SeoEventResponse,
|
|
7
|
-
"@quidproquo-core/event/AutoRespond": EventAutoRespondActionProcessor<
|
|
8
|
-
"@quidproquo-core/event/MatchStory": EventMatchStoryActionProcessor<
|
|
6
|
+
"@quidproquo-core/event/TransformEventParams": EventTransformEventParamsActionProcessor<[CloudFrontRequestEvent, Context], SeoEvent<any>>;
|
|
7
|
+
"@quidproquo-core/event/TransformResponseResult": EventTransformResponseResultActionProcessor<SeoEventResponse, SeoEvent<any>, SeoEventResponse>;
|
|
8
|
+
"@quidproquo-core/event/AutoRespond": EventAutoRespondActionProcessor<SeoEvent<any>, CloudFrontOriginMatchStoryResult, null>;
|
|
9
|
+
"@quidproquo-core/event/MatchStory": EventMatchStoryActionProcessor<SeoEvent<any>, CloudFrontOriginMatchStoryResult>;
|
|
9
10
|
};
|
|
10
11
|
export default _default;
|
|
@@ -63,7 +63,8 @@ const getProcessMatchStory = (seoConfigs) => {
|
|
|
63
63
|
return (0, quidproquo_core_1.actionResult)({
|
|
64
64
|
src: matchedSeoConfig.route.src,
|
|
65
65
|
runtime: matchedSeoConfig.route.runtime,
|
|
66
|
-
|
|
66
|
+
runtimeOptions: matchedSeoConfig.match.params || {},
|
|
67
|
+
config: matchedSeoConfig.route,
|
|
67
68
|
});
|
|
68
69
|
});
|
|
69
70
|
};
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import { EventMatchStoryActionProcessor, EventTransformEventParamsActionProcessor, EventTransformResponseResultActionProcessor, EventAutoRespondActionProcessor, ScheduledEventParams } from 'quidproquo-core';
|
|
1
|
+
import { MatchStoryResult, EventMatchStoryActionProcessor, EventTransformEventParamsActionProcessor, EventTransformResponseResultActionProcessor, EventAutoRespondActionProcessor, ScheduledEventParams } from 'quidproquo-core';
|
|
2
2
|
import { LambdaRuntimeConfig } from '../../../runtimeConfig/QPQAWSResourceMap';
|
|
3
3
|
import { EventBridgeEvent, Context } from 'aws-lambda';
|
|
4
|
+
type MatchOptions = {};
|
|
5
|
+
type MatchConfig = any;
|
|
6
|
+
type EventBridgeEventMatchStoryResult = MatchStoryResult<MatchOptions, MatchConfig>;
|
|
4
7
|
declare const _default: (runtimeConfig: LambdaRuntimeConfig) => {
|
|
5
8
|
"@quidproquo-core/event/TransformEventParams": EventTransformEventParamsActionProcessor<[EventBridgeEvent<any, any>, Context], ScheduledEventParams<any>>;
|
|
6
9
|
"@quidproquo-core/event/TransformResponseResult": EventTransformResponseResultActionProcessor<any, any, any>;
|
|
7
|
-
"@quidproquo-core/event/AutoRespond": EventAutoRespondActionProcessor<ScheduledEventParams<any
|
|
8
|
-
"@quidproquo-core/event/MatchStory": EventMatchStoryActionProcessor<ScheduledEventParams<any
|
|
10
|
+
"@quidproquo-core/event/AutoRespond": EventAutoRespondActionProcessor<ScheduledEventParams<any>, EventBridgeEventMatchStoryResult, null>;
|
|
11
|
+
"@quidproquo-core/event/MatchStory": EventMatchStoryActionProcessor<ScheduledEventParams<any>, EventBridgeEventMatchStoryResult>;
|
|
9
12
|
};
|
|
10
13
|
export default _default;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { QPQConfig, EventMatchStoryActionProcessor, EventTransformEventParamsActionProcessor, EventTransformResponseResultActionProcessor, EventAutoRespondActionProcessor, QueueMessage, QueueQPQConfigSetting } from 'quidproquo-core';
|
|
2
|
-
import {
|
|
1
|
+
import { QPQConfig, MatchStoryResult, EventMatchStoryActionProcessor, EventTransformEventParamsActionProcessor, EventTransformResponseResultActionProcessor, EventAutoRespondActionProcessor, QueueMessage, QueueQPQConfigSetting } from 'quidproquo-core';
|
|
2
|
+
import { QueueEvent, QueueEventTypeParams } from 'quidproquo-webserver';
|
|
3
3
|
import { Context, SQSRecord } from 'aws-lambda';
|
|
4
|
-
type
|
|
4
|
+
type AnyQueueEvent = QueueEvent<QueueMessage<any>>;
|
|
5
|
+
export type SqsEventMatchStoryResult = MatchStoryResult<QueueEventTypeParams, string>;
|
|
5
6
|
export declare const getQueueConfigSetting: () => QueueQPQConfigSetting;
|
|
6
7
|
declare const _default: (qpqConfig: QPQConfig) => {
|
|
7
|
-
"@quidproquo-core/event/TransformEventParams": EventTransformEventParamsActionProcessor<[SQSRecord, Context],
|
|
8
|
-
"@quidproquo-core/event/TransformResponseResult": EventTransformResponseResultActionProcessor<boolean,
|
|
9
|
-
"@quidproquo-core/event/AutoRespond": EventAutoRespondActionProcessor<
|
|
10
|
-
"@quidproquo-core/event/MatchStory": EventMatchStoryActionProcessor<
|
|
8
|
+
"@quidproquo-core/event/TransformEventParams": EventTransformEventParamsActionProcessor<[SQSRecord, Context], AnyQueueEvent>;
|
|
9
|
+
"@quidproquo-core/event/TransformResponseResult": EventTransformResponseResultActionProcessor<boolean, AnyQueueEvent, boolean>;
|
|
10
|
+
"@quidproquo-core/event/AutoRespond": EventAutoRespondActionProcessor<AnyQueueEvent, SqsEventMatchStoryResult, null>;
|
|
11
|
+
"@quidproquo-core/event/MatchStory": EventMatchStoryActionProcessor<AnyQueueEvent, SqsEventMatchStoryResult>;
|
|
11
12
|
};
|
|
12
13
|
export default _default;
|
|
@@ -58,7 +58,8 @@ const getProcessMatchStory = (qpqConfig) => {
|
|
|
58
58
|
return (0, quidproquo_core_1.actionResult)({
|
|
59
59
|
src: sourceEntry.src,
|
|
60
60
|
runtime: sourceEntry.runtime,
|
|
61
|
-
|
|
61
|
+
runtimeOptions: matchedQueueType.match.params || {},
|
|
62
|
+
config: matchedQueueType.queueType,
|
|
62
63
|
});
|
|
63
64
|
});
|
|
64
65
|
};
|
|
@@ -0,0 +1,41 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.isAuthValid = void 0;
|
|
13
|
+
const quidproquo_core_1 = require("quidproquo-core");
|
|
14
|
+
const verifyJwt_1 = require("../../../../logic/cognito/verifyJwt");
|
|
15
|
+
const getExportedValue_1 = require("../../../../logic/cloudformation/getExportedValue");
|
|
16
|
+
const awsNamingUtils_1 = require("../../../../awsNamingUtils");
|
|
17
|
+
const isAuthValid = (qpqConfig, authHeader, authSettings) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
|
+
// If there are no auth settings ~ Its valid.
|
|
19
|
+
if (!authSettings || !authSettings.userDirectoryName) {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
// We need a header to be able to auth
|
|
23
|
+
if (!authHeader) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
// Make sure we have a Bearer token
|
|
27
|
+
const [authType, accessToken] = authHeader.split(' ');
|
|
28
|
+
if (authType !== 'Bearer' || !accessToken) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
// Grab the user directory to auth against
|
|
32
|
+
const userDirectoryName = authSettings.userDirectoryName;
|
|
33
|
+
const region = quidproquo_core_1.qpqCoreUtils.getApplicationModuleDeployRegion(qpqConfig);
|
|
34
|
+
// Resolve the user pool id
|
|
35
|
+
const userPoolId = yield (0, getExportedValue_1.getExportedValue)((0, awsNamingUtils_1.getCFExportNameUserPoolIdFromConfig)(userDirectoryName, qpqConfig, authSettings.serviceName, authSettings.applicationName), region);
|
|
36
|
+
// Resolve the user pool client id
|
|
37
|
+
const userPoolClientId = yield (0, getExportedValue_1.getExportedValue)((0, awsNamingUtils_1.getCFExportNameUserPoolClientIdFromConfig)(userDirectoryName, qpqConfig, authSettings.serviceName, authSettings.applicationName), region);
|
|
38
|
+
// Verify the token
|
|
39
|
+
return yield (0, verifyJwt_1.verifyJwt)(accessToken, userPoolId, userPoolClientId, 'access');
|
|
40
|
+
});
|
|
41
|
+
exports.isAuthValid = isAuthValid;
|
|
@@ -8,3 +8,4 @@ export { default as getEventBridgeEventActionProcessor } from './event/getEventB
|
|
|
8
8
|
export { default as getSystemActionProcessor } from './system';
|
|
9
9
|
export { default as getFileActionProcessor } from './file';
|
|
10
10
|
export { default as getQueueActionProcessor } from './queue';
|
|
11
|
+
export { default as getUserDirectoryActionProcessor } from './userDirectory';
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getQueueActionProcessor = exports.getFileActionProcessor = exports.getSystemActionProcessor = exports.getEventBridgeEventActionProcessor = exports.getSQSEventRecordActionProcessor = exports.getCloudFrontOriginRequestEventActionProcessor = exports.getAPIGatewayEventActionProcessor = exports.getConfigGetParametersActionProcessor = exports.getConfigGetParameterActionProcessor = exports.getConfigGetSecretActionProcessor = void 0;
|
|
6
|
+
exports.getUserDirectoryActionProcessor = exports.getQueueActionProcessor = exports.getFileActionProcessor = exports.getSystemActionProcessor = exports.getEventBridgeEventActionProcessor = exports.getSQSEventRecordActionProcessor = exports.getCloudFrontOriginRequestEventActionProcessor = exports.getAPIGatewayEventActionProcessor = exports.getConfigGetParametersActionProcessor = exports.getConfigGetParameterActionProcessor = exports.getConfigGetSecretActionProcessor = void 0;
|
|
7
7
|
var getConfigGetSecretActionProcessor_1 = require("./config/getConfigGetSecretActionProcessor");
|
|
8
8
|
Object.defineProperty(exports, "getConfigGetSecretActionProcessor", { enumerable: true, get: function () { return __importDefault(getConfigGetSecretActionProcessor_1).default; } });
|
|
9
9
|
var getConfigGetParameterActionProcessor_1 = require("./config/getConfigGetParameterActionProcessor");
|
|
@@ -24,3 +24,5 @@ var file_1 = require("./file");
|
|
|
24
24
|
Object.defineProperty(exports, "getFileActionProcessor", { enumerable: true, get: function () { return __importDefault(file_1).default; } });
|
|
25
25
|
var queue_1 = require("./queue");
|
|
26
26
|
Object.defineProperty(exports, "getQueueActionProcessor", { enumerable: true, get: function () { return __importDefault(queue_1).default; } });
|
|
27
|
+
var userDirectory_1 = require("./userDirectory");
|
|
28
|
+
Object.defineProperty(exports, "getUserDirectoryActionProcessor", { enumerable: true, get: function () { return __importDefault(userDirectory_1).default; } });
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { UserDirectoryAuthenticateUserActionProcessor, QPQConfig } from 'quidproquo-core';
|
|
2
|
+
declare const _default: (qpqConfig: QPQConfig) => {
|
|
3
|
+
"@quidproquo-core/UserDirectory/AuthenticateUser": UserDirectoryAuthenticateUserActionProcessor;
|
|
4
|
+
};
|
|
5
|
+
export default _default;
|
package/lib/getActionProcessor/core/userDirectory/getUserDirectoryAuthenticateUserActionProcessor.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const quidproquo_core_1 = require("quidproquo-core");
|
|
13
|
+
const awsNamingUtils_1 = require("../../../awsNamingUtils");
|
|
14
|
+
const authenticateUser_1 = require("../../../logic/cognito/authenticateUser");
|
|
15
|
+
const getExportedValue_1 = require("../../../logic/cloudformation/getExportedValue");
|
|
16
|
+
const getUserDirectoryAuthenticateUserActionProcessor = (qpqConfig) => {
|
|
17
|
+
return (payload) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
|
+
const region = quidproquo_core_1.qpqCoreUtils.getApplicationModuleDeployRegion(qpqConfig);
|
|
19
|
+
const userPoolId = yield (0, getExportedValue_1.getExportedValue)((0, awsNamingUtils_1.getCFExportNameUserPoolIdFromConfig)(payload.userDirectoryName, qpqConfig), region);
|
|
20
|
+
const userPoolClientId = yield (0, getExportedValue_1.getExportedValue)((0, awsNamingUtils_1.getCFExportNameUserPoolClientIdFromConfig)(payload.userDirectoryName, qpqConfig), region);
|
|
21
|
+
const authResponse = yield (0, authenticateUser_1.authenticateUser)(userPoolId, userPoolClientId, quidproquo_core_1.qpqCoreUtils.getApplicationModuleDeployRegion(qpqConfig), payload.authenticateUserRequest);
|
|
22
|
+
return (0, quidproquo_core_1.actionResult)(authResponse);
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
exports.default = (qpqConfig) => {
|
|
26
|
+
return {
|
|
27
|
+
[quidproquo_core_1.UserDirectoryActionType.AuthenticateUser]: getUserDirectoryAuthenticateUserActionProcessor(qpqConfig),
|
|
28
|
+
};
|
|
29
|
+
};
|
package/lib/getActionProcessor/core/userDirectory/getUserDirectoryCreateUserActionProcessor.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const quidproquo_core_1 = require("quidproquo-core");
|
|
13
|
+
const awsNamingUtils_1 = require("../../../awsNamingUtils");
|
|
14
|
+
const createUser_1 = require("../../../logic/cognito/createUser");
|
|
15
|
+
const getExportedValue_1 = require("../../../logic/cloudformation/getExportedValue");
|
|
16
|
+
const getUserDirectoryCreateUserActionProcessor = (qpqConfig) => {
|
|
17
|
+
return (payload) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
|
+
const region = quidproquo_core_1.qpqCoreUtils.getApplicationModuleDeployRegion(qpqConfig);
|
|
19
|
+
const userPoolId = yield (0, getExportedValue_1.getExportedValue)((0, awsNamingUtils_1.getCFExportNameUserPoolIdFromConfig)(payload.userDirectoryName, qpqConfig), region);
|
|
20
|
+
const username = yield (0, createUser_1.createUser)(userPoolId, quidproquo_core_1.qpqCoreUtils.getApplicationModuleDeployRegion(qpqConfig), payload.createUserRequest);
|
|
21
|
+
return (0, quidproquo_core_1.actionResult)(username);
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
exports.default = (qpqConfig) => {
|
|
25
|
+
return {
|
|
26
|
+
[quidproquo_core_1.UserDirectoryActionType.CreateUser]: getUserDirectoryCreateUserActionProcessor(qpqConfig),
|
|
27
|
+
};
|
|
28
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { QPQConfig } from 'quidproquo-core';
|
|
2
|
+
declare const _default: (qpqConfig: QPQConfig) => {
|
|
3
|
+
"@quidproquo-core/UserDirectory/CreateUser": import("quidproquo-core").UserDirectoryCreateUserActionProcessor;
|
|
4
|
+
"@quidproquo-core/UserDirectory/AuthenticateUser": import("quidproquo-core").UserDirectoryAuthenticateUserActionProcessor;
|
|
5
|
+
};
|
|
6
|
+
export default _default;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const getUserDirectoryAuthenticateUserActionProcessor_1 = __importDefault(require("./getUserDirectoryAuthenticateUserActionProcessor"));
|
|
7
|
+
const getUserDirectoryCreateUserActionProcessor_1 = __importDefault(require("./getUserDirectoryCreateUserActionProcessor"));
|
|
8
|
+
exports.default = (qpqConfig) => (Object.assign(Object.assign({}, (0, getUserDirectoryAuthenticateUserActionProcessor_1.default)(qpqConfig)), (0, getUserDirectoryCreateUserActionProcessor_1.default)(qpqConfig)));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getExportedValue: (variableName: string, region: string) => Promise<string>;
|
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.getExportedValue = void 0;
|
|
13
|
+
const client_cloudformation_1 = require("@aws-sdk/client-cloudformation");
|
|
14
|
+
const getExportedValue = (variableName, region) => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
|
+
var _a;
|
|
16
|
+
const cloudformation = new client_cloudformation_1.CloudFormationClient({ region });
|
|
17
|
+
const listCommandParams = {};
|
|
18
|
+
do {
|
|
19
|
+
const result = yield cloudformation.send(new client_cloudformation_1.ListExportsCommand(listCommandParams));
|
|
20
|
+
const value = (_a = (result.Exports || []).find((e) => e.Name === variableName)) === null || _a === void 0 ? void 0 : _a.Value;
|
|
21
|
+
if (value !== undefined) {
|
|
22
|
+
console.log(`CF Found: [${variableName}] = [${value}]`);
|
|
23
|
+
return value;
|
|
24
|
+
}
|
|
25
|
+
listCommandParams.NextToken = result.NextToken;
|
|
26
|
+
} while (!!listCommandParams.NextToken);
|
|
27
|
+
throw new Error(`CF could not find: [${variableName}]`);
|
|
28
|
+
});
|
|
29
|
+
exports.getExportedValue = getExportedValue;
|
|
@@ -0,0 +1,50 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.authenticateUser = void 0;
|
|
13
|
+
const quidproquo_core_1 = require("quidproquo-core");
|
|
14
|
+
const client_cognito_identity_provider_1 = require("@aws-sdk/client-cognito-identity-provider");
|
|
15
|
+
const calculateSecretHash_1 = require("./utils/calculateSecretHash");
|
|
16
|
+
const getUserPoolClientSecret_1 = require("./getUserPoolClientSecret");
|
|
17
|
+
const cognitoAuthenticationResultTypeToQpqAuthenticationInfo = (authResult) => ({
|
|
18
|
+
accessToken: authResult.AccessToken,
|
|
19
|
+
idToken: authResult.IdToken,
|
|
20
|
+
expiresIn: authResult.ExpiresIn,
|
|
21
|
+
refreshToken: authResult.RefreshToken,
|
|
22
|
+
tokenType: authResult.TokenType,
|
|
23
|
+
});
|
|
24
|
+
const authenticateUser = (userPoolId, clientId, region, authenticateUserRequest) => __awaiter(void 0, void 0, void 0, function* () {
|
|
25
|
+
const cognitoClient = new client_cognito_identity_provider_1.CognitoIdentityProviderClient({ region });
|
|
26
|
+
const clientSecret = yield (0, getUserPoolClientSecret_1.getUserPoolClientSecret)(userPoolId, clientId, region);
|
|
27
|
+
const secretHash = (0, calculateSecretHash_1.calculateSecretHash)(authenticateUserRequest.email, clientId, clientSecret);
|
|
28
|
+
const params = {
|
|
29
|
+
AuthFlow: client_cognito_identity_provider_1.AuthFlowType.ADMIN_USER_PASSWORD_AUTH,
|
|
30
|
+
UserPoolId: userPoolId,
|
|
31
|
+
ClientId: clientId,
|
|
32
|
+
AuthParameters: {
|
|
33
|
+
USERNAME: authenticateUserRequest.email,
|
|
34
|
+
PASSWORD: authenticateUserRequest.password,
|
|
35
|
+
SECRET_HASH: secretHash,
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
const response = yield cognitoClient.send(new client_cognito_identity_provider_1.AdminInitiateAuthCommand(params));
|
|
39
|
+
console.log(JSON.stringify(response, null, 2));
|
|
40
|
+
const authenticateUserResponse = {
|
|
41
|
+
session: response.Session,
|
|
42
|
+
challenge: quidproquo_core_1.AuthenticateUserChallenge.NONE,
|
|
43
|
+
};
|
|
44
|
+
if (response.AuthenticationResult) {
|
|
45
|
+
authenticateUserResponse.authenticationInfo =
|
|
46
|
+
cognitoAuthenticationResultTypeToQpqAuthenticationInfo(response.AuthenticationResult);
|
|
47
|
+
}
|
|
48
|
+
return authenticateUserResponse;
|
|
49
|
+
});
|
|
50
|
+
exports.authenticateUser = authenticateUser;
|
|
@@ -0,0 +1,42 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.createUser = void 0;
|
|
13
|
+
const client_cognito_identity_provider_1 = require("@aws-sdk/client-cognito-identity-provider");
|
|
14
|
+
const createUser = (userPoolId, region, createUserRequest) => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
|
+
var _a;
|
|
16
|
+
const cognitoClient = new client_cognito_identity_provider_1.CognitoIdentityProviderClient({ region });
|
|
17
|
+
const params = {
|
|
18
|
+
UserPoolId: userPoolId,
|
|
19
|
+
Username: createUserRequest.email,
|
|
20
|
+
MessageAction: client_cognito_identity_provider_1.MessageActionType.SUPPRESS,
|
|
21
|
+
DesiredDeliveryMediums: [client_cognito_identity_provider_1.DeliveryMediumType.EMAIL],
|
|
22
|
+
UserAttributes: [{ Name: 'email', Value: createUserRequest.email }],
|
|
23
|
+
ForceAliasCreation: false,
|
|
24
|
+
};
|
|
25
|
+
if (createUserRequest.phone) {
|
|
26
|
+
params.DesiredDeliveryMediums.push(client_cognito_identity_provider_1.DeliveryMediumType.SMS);
|
|
27
|
+
params.UserAttributes.push({ Name: 'phone_number', Value: createUserRequest.phone });
|
|
28
|
+
}
|
|
29
|
+
const response = yield cognitoClient.send(new client_cognito_identity_provider_1.AdminCreateUserCommand(params));
|
|
30
|
+
const username = ((_a = response.User) === null || _a === void 0 ? void 0 : _a.Username) || '';
|
|
31
|
+
// There has to be a better way than this?
|
|
32
|
+
const passwordParams = {
|
|
33
|
+
Password: createUserRequest.password,
|
|
34
|
+
Username: username,
|
|
35
|
+
UserPoolId: userPoolId,
|
|
36
|
+
Permanent: true,
|
|
37
|
+
};
|
|
38
|
+
yield cognitoClient.send(new client_cognito_identity_provider_1.AdminSetUserPasswordCommand(passwordParams));
|
|
39
|
+
// ///////////////////////
|
|
40
|
+
return username;
|
|
41
|
+
});
|
|
42
|
+
exports.createUser = createUser;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface UserAttributes {
|
|
2
|
+
[attribute: string]: string;
|
|
3
|
+
}
|
|
4
|
+
export interface User {
|
|
5
|
+
id: string;
|
|
6
|
+
username: string;
|
|
7
|
+
email: string;
|
|
8
|
+
userAttributes: UserAttributes;
|
|
9
|
+
}
|
|
10
|
+
export declare const getUser: (accessToken: string, region: string) => Promise<User>;
|
|
@@ -0,0 +1,37 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.getUser = void 0;
|
|
13
|
+
const client_cognito_identity_provider_1 = require("@aws-sdk/client-cognito-identity-provider");
|
|
14
|
+
const getUserAttribute = (attributeName, userAttributes) => {
|
|
15
|
+
const lowerAttributeName = attributeName.toLowerCase();
|
|
16
|
+
const attribute = userAttributes.find((k) => { var _a; return ((_a = k.Name) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === lowerAttributeName; });
|
|
17
|
+
return attribute === null || attribute === void 0 ? void 0 : attribute.Value;
|
|
18
|
+
};
|
|
19
|
+
const getUser = (accessToken, region) => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
|
+
const cognitoClient = new client_cognito_identity_provider_1.CognitoIdentityProviderClient({ region });
|
|
21
|
+
const params = {
|
|
22
|
+
AccessToken: accessToken,
|
|
23
|
+
};
|
|
24
|
+
const response = yield cognitoClient.send(new client_cognito_identity_provider_1.GetUserCommand(params));
|
|
25
|
+
console.log(JSON.stringify(response, null, 2));
|
|
26
|
+
const attributeTypes = (response.UserAttributes || []).filter((ua) => !!ua.Value);
|
|
27
|
+
const userAttributes = attributeTypes.reduce((acc, ua) => (Object.assign(Object.assign({}, acc), { [ua.Name]: ua.Value })), {});
|
|
28
|
+
const user = {
|
|
29
|
+
username: response.Username,
|
|
30
|
+
id: getUserAttribute('sub', attributeTypes),
|
|
31
|
+
email: getUserAttribute('email', attributeTypes),
|
|
32
|
+
userAttributes,
|
|
33
|
+
};
|
|
34
|
+
console.log(JSON.stringify(user, null, 2));
|
|
35
|
+
return user;
|
|
36
|
+
});
|
|
37
|
+
exports.getUser = getUser;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getUserPoolClientSecret: (userPoolId: string, clientId: string, region: string) => Promise<string>;
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.getUserPoolClientSecret = void 0;
|
|
13
|
+
const client_cognito_identity_provider_1 = require("@aws-sdk/client-cognito-identity-provider");
|
|
14
|
+
const getUserPoolClientSecret = (userPoolId, clientId, region) => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
|
+
var _a, _b;
|
|
16
|
+
const cognitoClient = new client_cognito_identity_provider_1.CognitoIdentityProviderClient({ region });
|
|
17
|
+
const params = {
|
|
18
|
+
ClientId: clientId,
|
|
19
|
+
UserPoolId: userPoolId,
|
|
20
|
+
};
|
|
21
|
+
const response = yield cognitoClient.send(new client_cognito_identity_provider_1.DescribeUserPoolClientCommand(params));
|
|
22
|
+
if (!((_a = response.UserPoolClient) === null || _a === void 0 ? void 0 : _a.ClientSecret)) {
|
|
23
|
+
throw new Error('Can not find client secret for Cognito user pool client');
|
|
24
|
+
}
|
|
25
|
+
return (_b = response.UserPoolClient) === null || _b === void 0 ? void 0 : _b.ClientSecret;
|
|
26
|
+
});
|
|
27
|
+
exports.getUserPoolClientSecret = getUserPoolClientSecret;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const calculateSecretHash: (username: string, clientId: string, clientSecret: string) => string;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.calculateSecretHash = void 0;
|
|
4
|
+
const crypto_1 = require("crypto");
|
|
5
|
+
const calculateSecretHash = (username, clientId, clientSecret) => {
|
|
6
|
+
// create the hmac with the sha256 algorithm and a secret key
|
|
7
|
+
const hasher = (0, crypto_1.createHmac)('sha256', clientSecret);
|
|
8
|
+
// add the value we want to hash
|
|
9
|
+
hasher.update(`${username}${clientId}`);
|
|
10
|
+
// get the hashed value as base64
|
|
11
|
+
return hasher.digest('base64');
|
|
12
|
+
};
|
|
13
|
+
exports.calculateSecretHash = calculateSecretHash;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const verifyJwt: (accessToken: string, userPoolId: string, clientId: string, tokenType: 'id' | 'access') => Promise<boolean>;
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.verifyJwt = void 0;
|
|
13
|
+
const aws_jwt_verify_1 = require("aws-jwt-verify");
|
|
14
|
+
const verifyJwt = (accessToken, userPoolId, clientId, tokenType) => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
|
+
const verifier = aws_jwt_verify_1.CognitoJwtVerifier.create({
|
|
16
|
+
userPoolId: userPoolId,
|
|
17
|
+
tokenUse: tokenType,
|
|
18
|
+
clientId: clientId,
|
|
19
|
+
});
|
|
20
|
+
try {
|
|
21
|
+
const payload = yield verifier.verify(accessToken);
|
|
22
|
+
console.log('verify: ', JSON.stringify(payload, null, 2));
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
catch (e) {
|
|
26
|
+
console.log(e);
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
exports.verifyJwt = verifyJwt;
|
|
@@ -11,7 +11,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.deleteFiles = void 0;
|
|
13
13
|
const client_s3_1 = require("@aws-sdk/client-s3");
|
|
14
|
-
const client_s3_2 = require("@aws-sdk/client-s3");
|
|
15
14
|
const deleteFiles = (drive, filepaths, region) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
15
|
const s3Client = new client_s3_1.S3Client({ region });
|
|
17
16
|
const bucketParams = {
|
|
@@ -21,7 +20,7 @@ const deleteFiles = (drive, filepaths, region) => __awaiter(void 0, void 0, void
|
|
|
21
20
|
Objects: filepaths.map((fp) => ({ Key: fp })),
|
|
22
21
|
},
|
|
23
22
|
};
|
|
24
|
-
const response = yield s3Client.send(new
|
|
23
|
+
const response = yield s3Client.send(new client_s3_1.DeleteObjectsCommand(bucketParams));
|
|
25
24
|
return (response.Errors || []).map((e) => e.Key || '');
|
|
26
25
|
});
|
|
27
26
|
exports.deleteFiles = deleteFiles;
|
|
@@ -3,14 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.resolveParameterKey = exports.resolveSecretKey = exports.resolveResourceName = void 0;
|
|
4
4
|
const awsNamingUtils_1 = require("../awsNamingUtils");
|
|
5
5
|
const resolveResourceName = (resourceName, qpqConfig) => {
|
|
6
|
-
return (0, awsNamingUtils_1.
|
|
6
|
+
return (0, awsNamingUtils_1.getConfigRuntimeResourceNameFromConfig)(resourceName, qpqConfig);
|
|
7
7
|
};
|
|
8
8
|
exports.resolveResourceName = resolveResourceName;
|
|
9
9
|
const resolveSecretKey = (secretName, qpqConfig) => {
|
|
10
|
-
return (0, awsNamingUtils_1.
|
|
10
|
+
return (0, awsNamingUtils_1.getConfigRuntimeResourceNameFromConfig)(secretName, qpqConfig);
|
|
11
11
|
};
|
|
12
12
|
exports.resolveSecretKey = resolveSecretKey;
|
|
13
13
|
const resolveParameterKey = (parameterName, qpqConfig) => {
|
|
14
|
-
return (0, awsNamingUtils_1.
|
|
14
|
+
return (0, awsNamingUtils_1.getConfigRuntimeResourceNameFromConfig)(parameterName, qpqConfig);
|
|
15
15
|
};
|
|
16
16
|
exports.resolveParameterKey = resolveParameterKey;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "quidproquo-actionprocessor-awslambda",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.73",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.js",
|
|
@@ -25,10 +25,13 @@
|
|
|
25
25
|
},
|
|
26
26
|
"homepage": "https://github.com/joe-coady/quidproquo#readme",
|
|
27
27
|
"dependencies": {
|
|
28
|
+
"@aws-sdk/client-cloudformation": "^3.266.0",
|
|
29
|
+
"@aws-sdk/client-cognito-identity-provider": "^3.266.0",
|
|
28
30
|
"@aws-sdk/client-s3": "^3.266.0",
|
|
29
31
|
"@aws-sdk/client-secrets-manager": "^3.266.0",
|
|
30
|
-
"@aws-sdk/client-sqs": "^3.266.
|
|
32
|
+
"@aws-sdk/client-sqs": "^3.266.0",
|
|
31
33
|
"@aws-sdk/client-ssm": "^3.266.0",
|
|
34
|
+
"aws-jwt-verify": "^3.4.0",
|
|
32
35
|
"aws-sdk": "^2.1264.0",
|
|
33
36
|
"node-match-path": "^0.6.3",
|
|
34
37
|
"quidproquo-core": "*",
|