quidproquo-actionprocessor-awslambda 0.0.70 → 0.0.72

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.
Files changed (45) hide show
  1. package/lib/awsNamingUtils.d.ts +6 -2
  2. package/lib/awsNamingUtils.js +36 -8
  3. package/lib/getActionProcessor/core/event/getAPIGatewayEventActionProcessor.d.ts +10 -8
  4. package/lib/getActionProcessor/core/event/getAPIGatewayEventActionProcessor.js +45 -20
  5. package/lib/getActionProcessor/core/event/getCloudFrontOriginRequestEventActionProcessor.d.ts +7 -6
  6. package/lib/getActionProcessor/core/event/getCloudFrontOriginRequestEventActionProcessor.js +2 -1
  7. package/lib/getActionProcessor/core/event/getEventBridgeEventActionProcessor.d.ts +6 -3
  8. package/lib/getActionProcessor/core/event/getEventBridgeEventActionProcessor.js +1 -1
  9. package/lib/getActionProcessor/core/event/getSQSEventRecordActionProcessor.d.ts +13 -0
  10. package/lib/getActionProcessor/core/event/getSQSEventRecordActionProcessor.js +73 -0
  11. package/lib/getActionProcessor/core/event/utils/isAuthValid.d.ts +3 -0
  12. package/lib/getActionProcessor/core/event/utils/isAuthValid.js +41 -0
  13. package/lib/getActionProcessor/core/index.d.ts +3 -0
  14. package/lib/getActionProcessor/core/index.js +7 -1
  15. package/lib/getActionProcessor/core/queue/getQueueSendMessageActionProcessor.d.ts +6 -0
  16. package/lib/getActionProcessor/core/queue/getQueueSendMessageActionProcessor.js +26 -0
  17. package/lib/getActionProcessor/core/queue/index.d.ts +5 -0
  18. package/lib/getActionProcessor/core/queue/index.js +7 -0
  19. package/lib/getActionProcessor/core/userDirectory/getUserDirectoryAuthenticateUserActionProcessor.d.ts +5 -0
  20. package/lib/getActionProcessor/core/userDirectory/getUserDirectoryAuthenticateUserActionProcessor.js +29 -0
  21. package/lib/getActionProcessor/core/userDirectory/getUserDirectoryCreateUserActionProcessor.d.ts +5 -0
  22. package/lib/getActionProcessor/core/userDirectory/getUserDirectoryCreateUserActionProcessor.js +28 -0
  23. package/lib/getActionProcessor/core/userDirectory/index.d.ts +6 -0
  24. package/lib/getActionProcessor/core/userDirectory/index.js +8 -0
  25. package/lib/logic/cloudformation/getExportedValue.d.ts +1 -0
  26. package/lib/logic/cloudformation/getExportedValue.js +29 -0
  27. package/lib/logic/cognito/authenticateUser.d.ts +2 -0
  28. package/lib/logic/cognito/authenticateUser.js +50 -0
  29. package/lib/logic/cognito/createUser.d.ts +2 -0
  30. package/lib/logic/cognito/createUser.js +42 -0
  31. package/lib/logic/cognito/getUser.d.ts +10 -0
  32. package/lib/logic/cognito/getUser.js +37 -0
  33. package/lib/logic/cognito/getUserPoolClientSecret.d.ts +1 -0
  34. package/lib/logic/cognito/getUserPoolClientSecret.js +27 -0
  35. package/lib/logic/cognito/utils/calculateSecretHash.d.ts +1 -0
  36. package/lib/logic/cognito/utils/calculateSecretHash.js +13 -0
  37. package/lib/logic/cognito/verifyJwt.d.ts +1 -0
  38. package/lib/logic/cognito/verifyJwt.js +30 -0
  39. package/lib/logic/s3/deleteFiles.js +1 -2
  40. package/lib/logic/sqs/getQueueUrl.d.ts +2 -0
  41. package/lib/logic/sqs/getQueueUrl.js +20 -0
  42. package/lib/logic/sqs/sendMessages.d.ts +1 -0
  43. package/lib/logic/sqs/sendMessages.js +37 -0
  44. package/lib/runtimeConfig/qpqAwsLambdaRuntimeConfigUtils.js +3 -3
  45. package/package.json +5 -1
@@ -1,3 +1,7 @@
1
1
  import { QPQConfig } from 'quidproquo-core';
2
- export declare const getConfigRuntimeResourceName: (resourceName: string, qpqConfig: QPQConfig, resourceType?: string) => string;
3
- export declare const getQpqRuntimeResourceName: (resourceName: string, qpqConfig: QPQConfig, resourceType?: string) => string;
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;
@@ -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, qpqConfig, resourceType = '') => {
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 getQpqRuntimeResourceName = (resourceName, qpqConfig, resourceType = '') => {
18
- const name = (0, exports.getConfigRuntimeResourceName)(resourceName, qpqConfig, resourceType);
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 { HTTPEventParams } from 'quidproquo-webserver';
3
- import { Context, APIGatewayProxyResult } from 'aws-lambda';
4
- declare const _default: (config: QPQConfig) => {
5
- "@quidproquo-core/event/TransformEventParams": EventTransformEventParamsActionProcessor<[import("aws-lambda").APIGatewayProxyEvent, Context], HTTPEventParams<any>>;
6
- "@quidproquo-core/event/TransformResponseResult": EventTransformResponseResultActionProcessor<any, any, APIGatewayProxyResult>;
7
- "@quidproquo-core/event/AutoRespond": EventAutoRespondActionProcessor<HTTPEventParams<any>>;
8
- "@quidproquo-core/event/MatchStory": EventMatchStoryActionProcessor<HTTPEventParams<any>>;
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
- return (0, quidproquo_core_1.actionResult)({
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 = (configs) => {
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: Object.assign(Object.assign({}, quidproquo_webserver_1.qpqWebServerUtils.getCorsHeaders(configs, {}, payload.transformedEventParams.headers)), (((_a = payload === null || payload === void 0 ? void 0 : payload.response) === null || _a === void 0 ? void 0 : _a.headers) || {})),
47
+ headers: transformHttpEventHeadersToAPIGatewayProxyResultHeaders(headers),
39
48
  });
40
49
  });
41
50
  };
42
- const getProcessAutoRespond = (configs) => {
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
- result: {
47
- statusCode: 200,
48
- headers: quidproquo_webserver_1.qpqWebServerUtils.getCorsHeaders(configs, {}, payload.transformedEventParams.headers),
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 = (routes) => {
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, 'route not found');
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
- options: matchedRoute.match.params || {},
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 = (config) => {
86
- const routes = quidproquo_webserver_1.qpqWebServerUtils.getAllRoutes(config);
87
- const serviceName = quidproquo_core_1.qpqCoreUtils.getApplicationModuleName(config);
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(config),
91
- [quidproquo_core_1.EventActionType.AutoRespond]: getProcessAutoRespond(config),
92
- [quidproquo_core_1.EventActionType.MatchStory]: getProcessMatchStory(routes),
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
  };
@@ -1,10 +1,11 @@
1
- import { QPQConfig, EventMatchStoryActionProcessor, EventTransformEventParamsActionProcessor, EventTransformResponseResultActionProcessor, EventAutoRespondActionProcessor } from 'quidproquo-core';
2
- import { SeoEventParams, SeoEventResponse } from 'quidproquo-webserver';
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], SeoEventParams<any>>;
6
- "@quidproquo-core/event/TransformResponseResult": EventTransformResponseResultActionProcessor<SeoEventResponse, SeoEventParams<any>, SeoEventResponse>;
7
- "@quidproquo-core/event/AutoRespond": EventAutoRespondActionProcessor<SeoEventParams<any>>;
8
- "@quidproquo-core/event/MatchStory": EventMatchStoryActionProcessor<SeoEventParams<any>>;
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
- options: matchedSeoConfig.match.params || {},
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;
@@ -35,7 +35,7 @@ const getProcessMatchStory = (lambdaRuntimeConfig) => {
35
35
  return (0, quidproquo_core_1.actionResult)({
36
36
  src: lambdaRuntimeConfig.src,
37
37
  runtime: lambdaRuntimeConfig.runtime,
38
- options: {},
38
+ runtimeOptions: {},
39
39
  });
40
40
  });
41
41
  };
@@ -0,0 +1,13 @@
1
+ import { QPQConfig, MatchStoryResult, EventMatchStoryActionProcessor, EventTransformEventParamsActionProcessor, EventTransformResponseResultActionProcessor, EventAutoRespondActionProcessor, QueueMessage, QueueQPQConfigSetting } from 'quidproquo-core';
2
+ import { QueueEvent, QueueEventTypeParams } from 'quidproquo-webserver';
3
+ import { Context, SQSRecord } from 'aws-lambda';
4
+ type AnyQueueEvent = QueueEvent<QueueMessage<any>>;
5
+ export type SqsEventMatchStoryResult = MatchStoryResult<QueueEventTypeParams, string>;
6
+ export declare const getQueueConfigSetting: () => QueueQPQConfigSetting;
7
+ declare const _default: (qpqConfig: QPQConfig) => {
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>;
12
+ };
13
+ export default _default;
@@ -0,0 +1,73 @@
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.getQueueConfigSetting = void 0;
13
+ const quidproquo_core_1 = require("quidproquo-core");
14
+ const awsLambdaUtils_1 = require("../../../awsLambdaUtils");
15
+ const getQueueConfigSetting = () => {
16
+ const queueQPQConfigSetting = JSON.parse(process.env.queueQPQConfigSetting);
17
+ // TODO: Validate here
18
+ return queueQPQConfigSetting;
19
+ };
20
+ exports.getQueueConfigSetting = getQueueConfigSetting;
21
+ const getProcessTransformEventParams = (qpqConfig) => {
22
+ return ({ eventParams: [record, context] }) => __awaiter(void 0, void 0, void 0, function* () {
23
+ const parsedRecord = JSON.parse(record.body);
24
+ return (0, quidproquo_core_1.actionResult)({
25
+ message: {
26
+ type: parsedRecord.type,
27
+ payload: parsedRecord.payload,
28
+ },
29
+ });
30
+ });
31
+ };
32
+ const getProcessTransformResponseResult = (configs) => {
33
+ return ({ response }) => __awaiter(void 0, void 0, void 0, function* () {
34
+ return (0, quidproquo_core_1.actionResult)(response);
35
+ });
36
+ };
37
+ const getProcessAutoRespond = () => {
38
+ return (payload) => __awaiter(void 0, void 0, void 0, function* () {
39
+ return (0, quidproquo_core_1.actionResult)(null);
40
+ });
41
+ };
42
+ const getProcessMatchStory = (qpqConfig) => {
43
+ const queueQPQConfigSetting = (0, exports.getQueueConfigSetting)();
44
+ return (payload) => __awaiter(void 0, void 0, void 0, function* () {
45
+ const queueQueueProcessors = quidproquo_core_1.qpqCoreUtils.getQueueQueueProcessors(queueQPQConfigSetting.name, qpqConfig);
46
+ const queueTypes = Object.keys(queueQueueProcessors).sort();
47
+ // Find the most relevant match
48
+ const matchedQueueType = queueTypes
49
+ .map((qt) => ({
50
+ match: (0, awsLambdaUtils_1.matchUrl)(qt, payload.transformedEventParams.message.type),
51
+ queueType: qt,
52
+ }))
53
+ .find((m) => m.match.didMatch);
54
+ if (!matchedQueueType) {
55
+ return (0, quidproquo_core_1.actionResultError)(quidproquo_core_1.ErrorTypeEnum.NotFound, `queue type not found ${payload.transformedEventParams.message.type}`);
56
+ }
57
+ const sourceEntry = queueQueueProcessors[matchedQueueType.queueType];
58
+ return (0, quidproquo_core_1.actionResult)({
59
+ src: sourceEntry.src,
60
+ runtime: sourceEntry.runtime,
61
+ runtimeOptions: matchedQueueType.match.params || {},
62
+ config: matchedQueueType.queueType,
63
+ });
64
+ });
65
+ };
66
+ exports.default = (qpqConfig) => {
67
+ return {
68
+ [quidproquo_core_1.EventActionType.TransformEventParams]: getProcessTransformEventParams(qpqConfig),
69
+ [quidproquo_core_1.EventActionType.TransformResponseResult]: getProcessTransformResponseResult(qpqConfig),
70
+ [quidproquo_core_1.EventActionType.AutoRespond]: getProcessAutoRespond(),
71
+ [quidproquo_core_1.EventActionType.MatchStory]: getProcessMatchStory(qpqConfig),
72
+ };
73
+ };
@@ -0,0 +1,3 @@
1
+ import { QPQConfig } from 'quidproquo-core';
2
+ import { RouteAuthSettings } from 'quidproquo-webserver';
3
+ export declare const isAuthValid: (qpqConfig: QPQConfig, authHeader?: string | null, authSettings?: RouteAuthSettings) => Promise<boolean>;
@@ -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;
@@ -3,6 +3,9 @@ export { default as getConfigGetParameterActionProcessor } from './config/getCon
3
3
  export { default as getConfigGetParametersActionProcessor } from './config/getConfigGetParametersActionProcessor';
4
4
  export { default as getAPIGatewayEventActionProcessor } from './event/getAPIGatewayEventActionProcessor';
5
5
  export { default as getCloudFrontOriginRequestEventActionProcessor } from './event/getCloudFrontOriginRequestEventActionProcessor';
6
+ export { default as getSQSEventRecordActionProcessor } from './event/getSQSEventRecordActionProcessor';
6
7
  export { default as getEventBridgeEventActionProcessor } from './event/getEventBridgeEventActionProcessor';
7
8
  export { default as getSystemActionProcessor } from './system';
8
9
  export { default as getFileActionProcessor } from './file';
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.getFileActionProcessor = exports.getSystemActionProcessor = exports.getEventBridgeEventActionProcessor = 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");
@@ -14,9 +14,15 @@ var getAPIGatewayEventActionProcessor_1 = require("./event/getAPIGatewayEventAct
14
14
  Object.defineProperty(exports, "getAPIGatewayEventActionProcessor", { enumerable: true, get: function () { return __importDefault(getAPIGatewayEventActionProcessor_1).default; } });
15
15
  var getCloudFrontOriginRequestEventActionProcessor_1 = require("./event/getCloudFrontOriginRequestEventActionProcessor");
16
16
  Object.defineProperty(exports, "getCloudFrontOriginRequestEventActionProcessor", { enumerable: true, get: function () { return __importDefault(getCloudFrontOriginRequestEventActionProcessor_1).default; } });
17
+ var getSQSEventRecordActionProcessor_1 = require("./event/getSQSEventRecordActionProcessor");
18
+ Object.defineProperty(exports, "getSQSEventRecordActionProcessor", { enumerable: true, get: function () { return __importDefault(getSQSEventRecordActionProcessor_1).default; } });
17
19
  var getEventBridgeEventActionProcessor_1 = require("./event/getEventBridgeEventActionProcessor");
18
20
  Object.defineProperty(exports, "getEventBridgeEventActionProcessor", { enumerable: true, get: function () { return __importDefault(getEventBridgeEventActionProcessor_1).default; } });
19
21
  var system_1 = require("./system");
20
22
  Object.defineProperty(exports, "getSystemActionProcessor", { enumerable: true, get: function () { return __importDefault(system_1).default; } });
21
23
  var file_1 = require("./file");
22
24
  Object.defineProperty(exports, "getFileActionProcessor", { enumerable: true, get: function () { return __importDefault(file_1).default; } });
25
+ var queue_1 = require("./queue");
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,6 @@
1
+ import { QPQConfig } from 'quidproquo-core';
2
+ import { QueueSendMessageActionProcessor } from 'quidproquo-core';
3
+ declare const _default: (qpqConfig: QPQConfig) => {
4
+ "@quidproquo-core/Queue/SendMessage": QueueSendMessageActionProcessor<any>;
5
+ };
6
+ export default _default;
@@ -0,0 +1,26 @@
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 qpqAwsLambdaRuntimeConfigUtils_1 = require("../../../runtimeConfig/qpqAwsLambdaRuntimeConfigUtils");
14
+ const quidproquo_core_2 = require("quidproquo-core");
15
+ const sendMessages_1 = require("../../../logic/sqs/sendMessages");
16
+ const getProcessQueueSendMessage = (qpqConfig) => {
17
+ return ({ queueName, queueMessages }) => __awaiter(void 0, void 0, void 0, function* () {
18
+ // While we have some uuids
19
+ const sqsQueueName = (0, qpqAwsLambdaRuntimeConfigUtils_1.resolveResourceName)(queueName, qpqConfig);
20
+ yield (0, sendMessages_1.sendMessages)(sqsQueueName, quidproquo_core_1.qpqCoreUtils.getApplicationModuleDeployRegion(qpqConfig), queueMessages.map((message) => JSON.stringify(message)));
21
+ return (0, quidproquo_core_2.actionResult)(void 0);
22
+ });
23
+ };
24
+ exports.default = (qpqConfig) => ({
25
+ [quidproquo_core_2.QueueActionType.SendMessages]: getProcessQueueSendMessage(qpqConfig),
26
+ });
@@ -0,0 +1,5 @@
1
+ import { QPQConfig } from 'quidproquo-core';
2
+ declare const _default: (qpqConfig: QPQConfig) => {
3
+ "@quidproquo-core/Queue/SendMessage": import("quidproquo-core").QueueSendMessageActionProcessor<any>;
4
+ };
5
+ export default _default;
@@ -0,0 +1,7 @@
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 getQueueSendMessageActionProcessor_1 = __importDefault(require("./getQueueSendMessageActionProcessor"));
7
+ exports.default = (qpqConfig) => (Object.assign({}, (0, getQueueSendMessageActionProcessor_1.default)(qpqConfig)));
@@ -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;
@@ -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
+ };
@@ -0,0 +1,5 @@
1
+ import { UserDirectoryCreateUserActionProcessor, QPQConfig } from 'quidproquo-core';
2
+ declare const _default: (qpqConfig: QPQConfig) => {
3
+ "@quidproquo-core/UserDirectory/CreateUser": UserDirectoryCreateUserActionProcessor;
4
+ };
5
+ export default _default;
@@ -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,2 @@
1
+ import { AuthenticateUserRequest, AuthenticateUserResponse } from 'quidproquo-core';
2
+ export declare const authenticateUser: (userPoolId: string, clientId: string, region: string, authenticateUserRequest: AuthenticateUserRequest) => Promise<AuthenticateUserResponse>;
@@ -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,2 @@
1
+ import { CreateUserRequest } from 'quidproquo-core';
2
+ export declare const createUser: (userPoolId: string, region: string, createUserRequest: CreateUserRequest) => Promise<string>;
@@ -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 client_s3_2.DeleteObjectsCommand(bucketParams));
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;
@@ -0,0 +1,2 @@
1
+ import { SQSClient } from '@aws-sdk/client-sqs';
2
+ export declare const getQueueUrl: (queueName: string, sqsClient: SQSClient) => Promise<string>;
@@ -0,0 +1,20 @@
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.getQueueUrl = void 0;
13
+ const client_sqs_1 = require("@aws-sdk/client-sqs");
14
+ const getQueueUrl = (queueName, sqsClient) => __awaiter(void 0, void 0, void 0, function* () {
15
+ const response = yield sqsClient.send(new client_sqs_1.GetQueueUrlCommand({
16
+ QueueName: queueName,
17
+ }));
18
+ return response.QueueUrl || '';
19
+ });
20
+ exports.getQueueUrl = getQueueUrl;
@@ -0,0 +1 @@
1
+ export declare const sendMessages: (queueName: string, region: string, messages: string[]) => Promise<void>;
@@ -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.sendMessages = void 0;
13
+ const client_sqs_1 = require("@aws-sdk/client-sqs");
14
+ const getQueueUrl_1 = require("./getQueueUrl");
15
+ const sendMessages = (queueName, region, messages) => __awaiter(void 0, void 0, void 0, function* () {
16
+ const sqsClient = new client_sqs_1.SQSClient({
17
+ region,
18
+ });
19
+ const url = yield (0, getQueueUrl_1.getQueueUrl)(queueName, sqsClient);
20
+ // Convert them to entries
21
+ const entries = messages.map((message, index) => ({
22
+ MessageBody: message,
23
+ Id: `${index}`,
24
+ }));
25
+ // now send them off in batches of 10
26
+ // We want to await incase of FIFO
27
+ // If you don't care about order, you can split and askParallel outside of this
28
+ while (entries.length > 0) {
29
+ // Max batch size is 10
30
+ const entriesBatch = entries.splice(0, 10);
31
+ yield sqsClient.send(new client_sqs_1.SendMessageBatchCommand({
32
+ Entries: entriesBatch,
33
+ QueueUrl: url,
34
+ }));
35
+ }
36
+ });
37
+ exports.sendMessages = sendMessages;
@@ -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.getConfigRuntimeResourceName)(resourceName, qpqConfig);
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.getConfigRuntimeResourceName)(secretName, qpqConfig);
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.getConfigRuntimeResourceName)(parameterName, qpqConfig);
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.70",
3
+ "version": "0.0.72",
4
4
  "description": "",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.js",
@@ -25,9 +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",
32
+ "@aws-sdk/client-sqs": "^3.266.0",
30
33
  "@aws-sdk/client-ssm": "^3.266.0",
34
+ "aws-jwt-verify": "^3.4.0",
31
35
  "aws-sdk": "^2.1264.0",
32
36
  "node-match-path": "^0.6.3",
33
37
  "quidproquo-core": "*",