quidproquo-actionprocessor-awslambda 0.0.94 → 0.0.96

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 (33) hide show
  1. package/lib/getActionProcessor/core/event/getAPIGatewayEventActionProcessor.js +2 -0
  2. package/lib/getActionProcessor/core/event/getSQSEventRecordActionProcessor.d.ts +2 -2
  3. package/lib/getActionProcessor/core/event/getSQSEventRecordActionProcessor.js +2 -3
  4. package/lib/getActionProcessor/core/event/getServiceFunctionExecuteEventActionProcessor.js +0 -5
  5. package/lib/getActionProcessor/core/eventBus/getQueueSendMessageActionProcessor.js +5 -2
  6. package/lib/getActionProcessor/core/queue/getQueueSendMessageActionProcessor.js +6 -2
  7. package/lib/getActionProcessor/core/system/getExecuteStoryActionProcessor.js +5 -2
  8. package/lib/getActionProcessor/core/userDirectory/getUserDirectoryRefreshTokenActionProcessor.js +7 -2
  9. package/lib/getActionProcessor/webserver/admin/getAdminActionProcessor.d.ts +2 -1
  10. package/lib/getActionProcessor/webserver/admin/getAdminActionProcessor.js +10 -0
  11. package/lib/getActionProcessor/webserver/admin/index.d.ts +1 -0
  12. package/lib/getActionProcessor/webserver/serviceFunction/getServiceFunctionActionProcessor.js +2 -1
  13. package/lib/logic/cognito/authenticateUser.js +3 -1
  14. package/lib/logic/cognito/decodeValidJwt.d.ts +5 -0
  15. package/lib/logic/cognito/decodeValidJwt.js +36 -0
  16. package/lib/logic/cognito/refreshToken.js +3 -1
  17. package/lib/logic/cognito/utils/transformCognitoResponse.d.ts +2 -2
  18. package/lib/logic/cognito/utils/transformCognitoResponse.js +16 -9
  19. package/lib/logic/cognito/verifyJwt.js +4 -15
  20. package/lib/logic/dynamo/getLogByCorrelation.d.ts +2 -0
  21. package/lib/logic/dynamo/getLogByCorrelation.js +53 -0
  22. package/lib/logic/dynamo/getLogChildrenByFromCorrelation.d.ts +2 -0
  23. package/lib/logic/dynamo/getLogChildrenByFromCorrelation.js +60 -0
  24. package/lib/logic/dynamo/getPagedItemsOverRange.js +3 -8
  25. package/lib/logic/dynamo/logs/index.d.ts +1 -0
  26. package/lib/logic/dynamo/logs/index.js +17 -0
  27. package/lib/logic/dynamo/logs/utils/index.d.ts +2 -0
  28. package/lib/logic/dynamo/logs/utils/index.js +18 -0
  29. package/lib/logic/dynamo/logs/utils/lastEvaluatedKeyToString.d.ts +1 -0
  30. package/lib/logic/dynamo/logs/utils/lastEvaluatedKeyToString.js +7 -0
  31. package/lib/logic/dynamo/logs/utils/stringToLastEvaluatedKey.d.ts +1 -0
  32. package/lib/logic/dynamo/logs/utils/stringToLastEvaluatedKey.js +7 -0
  33. package/package.json +1 -1
@@ -59,6 +59,8 @@ const getProcessAutoRespond = (qpqConfig) => {
59
59
  headers: quidproquo_webserver_1.qpqWebServerUtils.getCorsHeaders(qpqConfig, payload.matchResult.config || {}, payload.transformedEventParams.headers),
60
60
  });
61
61
  }
62
+ // TODO: We can pull out the jwt from the session if thats a better way?
63
+ // Think about that when you dont have covid.
62
64
  const authValid = yield (0, isAuthValid_1.isAuthValid)(qpqConfig, quidproquo_webserver_1.qpqWebServerUtils.getHeaderValue('Authorization', payload.transformedEventParams.headers), quidproquo_webserver_1.qpqWebServerUtils.getHeaderValue('x-api-key', payload.transformedEventParams.headers), (_a = payload.matchResult.config) === null || _a === void 0 ? void 0 : _a.routeAuthSettings);
63
65
  if (!authValid) {
64
66
  return (0, quidproquo_core_1.actionResult)({
@@ -1,11 +1,11 @@
1
1
  import { QPQConfig, MatchStoryResult, EventMatchStoryActionProcessor, EventTransformEventParamsActionProcessor, EventTransformResponseResultActionProcessor, EventAutoRespondActionProcessor, QueueMessage, QueueQPQConfigSetting } from 'quidproquo-core';
2
2
  import { QueueEvent, QueueEventTypeParams } from 'quidproquo-webserver';
3
- import { Context, SQSRecord } from 'aws-lambda';
3
+ import { Context } from 'aws-lambda';
4
4
  type AnyQueueEvent = QueueEvent<QueueMessage<any>>;
5
5
  export type SqsEventMatchStoryResult = MatchStoryResult<QueueEventTypeParams, string>;
6
6
  export declare const getQueueConfigSetting: () => QueueQPQConfigSetting;
7
7
  declare const _default: (qpqConfig: QPQConfig) => {
8
- "@quidproquo-core/event/TransformEventParams": EventTransformEventParamsActionProcessor<[SQSRecord, Context], AnyQueueEvent>;
8
+ "@quidproquo-core/event/TransformEventParams": EventTransformEventParamsActionProcessor<[QueueMessage<any>, Context], AnyQueueEvent>;
9
9
  "@quidproquo-core/event/TransformResponseResult": EventTransformResponseResultActionProcessor<boolean, AnyQueueEvent, boolean>;
10
10
  "@quidproquo-core/event/AutoRespond": EventAutoRespondActionProcessor<AnyQueueEvent, SqsEventMatchStoryResult, boolean>;
11
11
  "@quidproquo-core/event/MatchStory": EventMatchStoryActionProcessor<AnyQueueEvent, SqsEventMatchStoryResult>;
@@ -20,11 +20,10 @@ const getQueueConfigSetting = () => {
20
20
  exports.getQueueConfigSetting = getQueueConfigSetting;
21
21
  const getProcessTransformEventParams = (qpqConfig) => {
22
22
  return ({ eventParams: [record, context] }) => __awaiter(void 0, void 0, void 0, function* () {
23
- const parsedRecord = JSON.parse(record.body);
24
23
  return (0, quidproquo_core_1.actionResult)({
25
24
  message: {
26
- type: parsedRecord.type,
27
- payload: parsedRecord.payload,
25
+ type: record.type,
26
+ payload: record.payload,
28
27
  },
29
28
  });
30
29
  });
@@ -11,11 +11,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  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
- const transformHttpEventHeadersToAPIGatewayProxyResultHeaders = (headers) => {
15
- return Object.keys(headers)
16
- .filter((header) => !!headers[header])
17
- .reduce((acc, header) => (Object.assign(Object.assign({}, acc), { [header]: headers[header] })), {});
18
- };
19
14
  const getProcessTransformEventParams = (qpqConfig) => {
20
15
  return ({ eventParams: [executeServiceFunctionEvent, context] }) => __awaiter(void 0, void 0, void 0, function* () {
21
16
  return (0, quidproquo_core_1.actionResult)(executeServiceFunctionEvent);
@@ -15,10 +15,13 @@ const publishMessage_1 = require("../../../logic/sns/publishMessage");
15
15
  const getExportedValue_1 = require("../../../logic/cloudformation/getExportedValue");
16
16
  const awsNamingUtils_1 = require("../../../awsNamingUtils");
17
17
  const getProcessEventBusSendMessage = (qpqConfig) => {
18
- return ({ eventBusName, eventBusMessages }) => __awaiter(void 0, void 0, void 0, function* () {
18
+ return ({ eventBusName, eventBusMessages }, session) => __awaiter(void 0, void 0, void 0, function* () {
19
19
  const region = quidproquo_core_1.qpqCoreUtils.getApplicationModuleDeployRegion(qpqConfig);
20
20
  const topicArn = yield (0, getExportedValue_1.getExportedValue)((0, awsNamingUtils_1.getCFExportNameSnsTopicArnFromConfig)(eventBusName, qpqConfig), region);
21
- yield (0, publishMessage_1.publishMessage)(topicArn, region, eventBusMessages.map((message) => JSON.stringify(message)));
21
+ yield (0, publishMessage_1.publishMessage)(topicArn, region, eventBusMessages.map((message) => {
22
+ const eventBusMessageWithSession = Object.assign(Object.assign({}, message), { storySession: session });
23
+ return JSON.stringify(eventBusMessageWithSession);
24
+ }));
22
25
  return (0, quidproquo_core_2.actionResult)(void 0);
23
26
  });
24
27
  };
@@ -14,10 +14,14 @@ const qpqAwsLambdaRuntimeConfigUtils_1 = require("../../../runtimeConfig/qpqAwsL
14
14
  const quidproquo_core_2 = require("quidproquo-core");
15
15
  const sendMessages_1 = require("../../../logic/sqs/sendMessages");
16
16
  const getProcessQueueSendMessage = (qpqConfig) => {
17
- return ({ queueName, queueMessages }) => __awaiter(void 0, void 0, void 0, function* () {
17
+ return ({ queueName, queueMessages }, session) => __awaiter(void 0, void 0, void 0, function* () {
18
18
  // While we have some uuids
19
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)));
20
+ yield (0, sendMessages_1.sendMessages)(sqsQueueName, quidproquo_core_1.qpqCoreUtils.getApplicationModuleDeployRegion(qpqConfig), queueMessages.map((message) => {
21
+ // Add the session info to the message
22
+ const queueMessageWithSession = Object.assign(Object.assign({}, message), { storySession: session });
23
+ return JSON.stringify(queueMessageWithSession);
24
+ }));
21
25
  return (0, quidproquo_core_2.actionResult)(void 0);
22
26
  });
23
27
  };
@@ -15,6 +15,7 @@ const awsLambdaUtils_1 = require("./../../../awsLambdaUtils");
15
15
  const getDateNow = () => new Date().toISOString();
16
16
  exports.getDateNow = getDateNow;
17
17
  const getProcessExecuteStory = (qpqConfig, dynamicModuleLoader) => {
18
+ const moduleName = quidproquo_core_1.qpqCoreUtils.getApplicationModuleName(qpqConfig);
18
19
  return (payload, session, actionProcessors, logger) => __awaiter(void 0, void 0, void 0, function* () {
19
20
  let module = yield dynamicModuleLoader(payload.src);
20
21
  if (module === null) {
@@ -24,10 +25,12 @@ const getProcessExecuteStory = (qpqConfig, dynamicModuleLoader) => {
24
25
  if (!story) {
25
26
  return (0, quidproquo_core_1.actionResultError)(quidproquo_core_1.ErrorTypeEnum.NotFound, `[${payload.runtime}] not found in module [${payload.src}]`);
26
27
  }
27
- const resolveStory = (0, quidproquo_core_1.createRuntime)(qpqConfig, session, actionProcessors, exports.getDateNow, logger, awsLambdaUtils_1.randomGuid, quidproquo_core_1.QpqRuntimeType.EXECUTE_STORY, [`${payload.src}::${payload.runtime}`]);
28
+ const resolveStory = (0, quidproquo_core_1.createRuntime)(qpqConfig, session, actionProcessors, exports.getDateNow, logger,
29
+ // TODO: Share this logic.
30
+ `${moduleName}-${(0, awsLambdaUtils_1.randomGuid)()}`, quidproquo_core_1.QpqRuntimeType.EXECUTE_STORY, [`${payload.src}::${payload.runtime}`]);
28
31
  const storyResult = yield resolveStory(story, payload.params);
29
32
  if (storyResult.error) {
30
- return (0, quidproquo_core_1.actionResultError)(storyResult.error.errorType, `story error! in ${payload.src}::${payload.runtime} -> [${storyResult.error.errorText}]`, storyResult.error.errorStack);
33
+ return (0, quidproquo_core_1.actionResultError)(storyResult.error.errorType, storyResult.error.errorText, `story error! in ${payload.src}::${payload.runtime} -> [${storyResult.error.errorStack}]`);
31
34
  }
32
35
  return (0, quidproquo_core_1.actionResult)(storyResult.result);
33
36
  });
@@ -13,12 +13,17 @@ const quidproquo_core_1 = require("quidproquo-core");
13
13
  const awsNamingUtils_1 = require("../../../awsNamingUtils");
14
14
  const refreshToken_1 = require("../../../logic/cognito/refreshToken");
15
15
  const getExportedValue_1 = require("../../../logic/cloudformation/getExportedValue");
16
+ const decodeValidJwt_1 = require("../../../logic/cognito/decodeValidJwt");
16
17
  const getUserDirectoryRefreshTokenActionProcessor = (qpqConfig) => {
17
- return ({ userDirectoryName, username, refreshToken }) => __awaiter(void 0, void 0, void 0, function* () {
18
+ return ({ userDirectoryName, refreshToken }, session) => __awaiter(void 0, void 0, void 0, function* () {
18
19
  const region = quidproquo_core_1.qpqCoreUtils.getApplicationModuleDeployRegion(qpqConfig);
19
20
  const userPoolId = yield (0, getExportedValue_1.getExportedValue)((0, awsNamingUtils_1.getCFExportNameUserPoolIdFromConfig)(userDirectoryName, qpqConfig), region);
20
21
  const userPoolClientId = yield (0, getExportedValue_1.getExportedValue)((0, awsNamingUtils_1.getCFExportNameUserPoolClientIdFromConfig)(userDirectoryName, qpqConfig), region);
21
- const authResponse = yield (0, refreshToken_1.refreshToken)(userPoolId, userPoolClientId, quidproquo_core_1.qpqCoreUtils.getApplicationModuleDeployRegion(qpqConfig), username, refreshToken);
22
+ const authInfo = yield (0, decodeValidJwt_1.decodeValidJwt)(userPoolId, userPoolClientId, 'access', session.accessToken);
23
+ if (!authInfo || !(authInfo === null || authInfo === void 0 ? void 0 : authInfo.username)) {
24
+ return (0, quidproquo_core_1.actionResultError)(quidproquo_core_1.ErrorTypeEnum.Unauthorized, 'Invalid accessToken');
25
+ }
26
+ const authResponse = yield (0, refreshToken_1.refreshToken)(userPoolId, userPoolClientId, quidproquo_core_1.qpqCoreUtils.getApplicationModuleDeployRegion(qpqConfig), authInfo === null || authInfo === void 0 ? void 0 : authInfo.username, refreshToken);
22
27
  return (0, quidproquo_core_1.actionResult)(authResponse);
23
28
  });
24
29
  };
@@ -1,7 +1,8 @@
1
1
  import { QPQConfig } from 'quidproquo-core';
2
- import { AdminGetLogsActionProcessor, AdminGetLogActionProcessor } from 'quidproquo-webserver';
2
+ import { AdminGetLogsActionProcessor, AdminGetLogActionProcessor, AdminGetLogMetadataChildrenActionProcessor } from 'quidproquo-webserver';
3
3
  declare const _default: (qpqConfig: QPQConfig) => {
4
4
  "@quidproquo-webserver/Admin/GetLogs": AdminGetLogsActionProcessor;
5
5
  "@quidproquo-webserver/Admin/GetLog": AdminGetLogActionProcessor;
6
+ "@quidproquo-webserver/Admin/GetLogMetadataChildren": AdminGetLogMetadataChildrenActionProcessor;
6
7
  };
7
8
  export default _default;
@@ -13,6 +13,7 @@ const quidproquo_core_1 = require("quidproquo-core");
13
13
  const quidproquo_webserver_1 = require("quidproquo-webserver");
14
14
  const awsNamingUtils_1 = require("../../../awsNamingUtils");
15
15
  const getPagedItemsOverRange_1 = require("../../../logic/dynamo/getPagedItemsOverRange");
16
+ const getLogChildrenByFromCorrelation_1 = require("../../../logic/dynamo/getLogChildrenByFromCorrelation");
16
17
  const readTextFile_1 = require("../../../logic/s3/readTextFile");
17
18
  // TODO: Centralize this
18
19
  const QPQ_LOG_BUCKET_NAME = 'logs';
@@ -24,6 +25,14 @@ const getAdminGetLogsActionProcessor = (qpqConfig) => {
24
25
  return (0, quidproquo_core_1.actionResult)(response);
25
26
  });
26
27
  };
28
+ const getLogMetadataChildrenActionProcessor = (qpqConfig) => {
29
+ return ({ correlationId }) => __awaiter(void 0, void 0, void 0, function* () {
30
+ const tableName = (0, awsNamingUtils_1.getQpqRuntimeResourceNameFromConfig)(QPQ_LOG_BUCKET_NAME, qpqConfig, 'log');
31
+ const region = quidproquo_core_1.qpqCoreUtils.getApplicationModuleDeployRegion(qpqConfig);
32
+ const response = yield (0, getLogChildrenByFromCorrelation_1.getLogChildrenByFromCorrelation)(tableName, region, correlationId);
33
+ return (0, quidproquo_core_1.actionResult)(response);
34
+ });
35
+ };
27
36
  const getAdminGetLogActionProcessor = (qpqConfig) => {
28
37
  return ({ correlationId }) => __awaiter(void 0, void 0, void 0, function* () {
29
38
  const bucketName = (0, awsNamingUtils_1.getQpqRuntimeResourceNameFromConfig)(QPQ_LOG_BUCKET_NAME, qpqConfig, 'log');
@@ -37,5 +46,6 @@ exports.default = (qpqConfig) => {
37
46
  return {
38
47
  [quidproquo_webserver_1.AdminActionType.GetLogs]: getAdminGetLogsActionProcessor(qpqConfig),
39
48
  [quidproquo_webserver_1.AdminActionType.GetLog]: getAdminGetLogActionProcessor(qpqConfig),
49
+ [quidproquo_webserver_1.AdminActionType.GetLogMetadataChildren]: getLogMetadataChildrenActionProcessor(qpqConfig),
40
50
  };
41
51
  };
@@ -2,5 +2,6 @@ import { QPQConfig } from 'quidproquo-core';
2
2
  declare const _default: (qpqConfig: QPQConfig) => {
3
3
  "@quidproquo-webserver/Admin/GetLogs": import("quidproquo-webserver/lib").AdminGetLogsActionProcessor;
4
4
  "@quidproquo-webserver/Admin/GetLog": import("quidproquo-webserver/lib").AdminGetLogActionProcessor;
5
+ "@quidproquo-webserver/Admin/GetLogMetadataChildren": import("quidproquo-webserver/lib").AdminGetLogMetadataChildrenActionProcessor;
5
6
  };
6
7
  export default _default;
@@ -14,7 +14,7 @@ const quidproquo_webserver_1 = require("quidproquo-webserver");
14
14
  const executeLambdaByName_1 = require("../../../logic/lambda/executeLambdaByName");
15
15
  const awsNamingUtils_1 = require("../../../awsNamingUtils");
16
16
  const getServiceFunctionExecuteActionProcessor = (qpqConfig) => {
17
- return ({ functionName, service, payload }) => __awaiter(void 0, void 0, void 0, function* () {
17
+ return ({ functionName, service, payload }, session) => __awaiter(void 0, void 0, void 0, function* () {
18
18
  const region = quidproquo_core_1.qpqCoreUtils.getApplicationModuleDeployRegion(qpqConfig);
19
19
  const appName = quidproquo_core_1.qpqCoreUtils.getApplicationName(qpqConfig);
20
20
  const environment = quidproquo_core_1.qpqCoreUtils.getApplicationModuleEnvironment(qpqConfig);
@@ -23,6 +23,7 @@ const getServiceFunctionExecuteActionProcessor = (qpqConfig) => {
23
23
  const serviceFunctionEvent = {
24
24
  functionName: functionName,
25
25
  payload: payload,
26
+ storySession: session,
26
27
  };
27
28
  const result = yield (0, executeLambdaByName_1.executeLambdaByName)(awsFunctionName, region, serviceFunctionEvent);
28
29
  if (result === null || result === void 0 ? void 0 : result.error) {
@@ -20,6 +20,8 @@ const authenticateUser = (userPoolId, clientId, region, username, password) => _
20
20
  const cognitoClient = new client_cognito_identity_provider_1.CognitoIdentityProviderClient({ region });
21
21
  const clientSecret = yield (0, getUserPoolClientSecret_1.getUserPoolClientSecret)(userPoolId, clientId, region);
22
22
  const secretHash = (0, calculateSecretHash_1.calculateSecretHash)(username, clientId, clientSecret);
23
+ // Time we issued the request
24
+ const issueDateTime = new Date().toISOString();
23
25
  const params = {
24
26
  AuthFlow: client_cognito_identity_provider_1.AuthFlowType.ADMIN_USER_PASSWORD_AUTH,
25
27
  UserPoolId: userPoolId,
@@ -32,7 +34,7 @@ const authenticateUser = (userPoolId, clientId, region, username, password) => _
32
34
  };
33
35
  try {
34
36
  const response = yield cognitoClient.send(new client_cognito_identity_provider_1.AdminInitiateAuthCommand(params));
35
- return (0, transformCognitoResponse_1.cognitoAdminInitiateAuthResponseToQpqAuthenticationInfo)(response);
37
+ return (0, transformCognitoResponse_1.cognitoAdminInitiateAuthResponseToQpqAuthenticationInfo)(response, issueDateTime);
36
38
  }
37
39
  catch (e) {
38
40
  if (e instanceof Error) {
@@ -0,0 +1,5 @@
1
+ export type AuthInfo = {
2
+ userId: string;
3
+ username: string;
4
+ };
5
+ export declare const decodeValidJwt: (userPoolId: string, clientId: string, tokenType: 'id' | 'access', accessToken?: string) => Promise<AuthInfo | null>;
@@ -0,0 +1,36 @@
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.decodeValidJwt = void 0;
13
+ const aws_jwt_verify_1 = require("aws-jwt-verify");
14
+ const decodeValidJwt = (userPoolId, clientId, tokenType, accessToken) => __awaiter(void 0, void 0, void 0, function* () {
15
+ var _a;
16
+ if (!accessToken) {
17
+ return null;
18
+ }
19
+ const verifier = aws_jwt_verify_1.CognitoJwtVerifier.create({
20
+ userPoolId: userPoolId,
21
+ tokenUse: tokenType,
22
+ clientId: clientId,
23
+ });
24
+ try {
25
+ const payload = yield verifier.verify(accessToken);
26
+ return {
27
+ userId: payload.sub,
28
+ username: ((_a = payload.username) === null || _a === void 0 ? void 0 : _a.toString()) || '',
29
+ };
30
+ }
31
+ catch (e) {
32
+ console.log('Invalid jwt token', e);
33
+ return null;
34
+ }
35
+ });
36
+ exports.decodeValidJwt = decodeValidJwt;
@@ -27,7 +27,9 @@ const refreshToken = (userPoolId, clientId, region, username, refreshToken) => _
27
27
  SECRET_HASH: secretHash,
28
28
  },
29
29
  };
30
+ // Time we issued the request
31
+ const issueDateTime = new Date().toISOString();
30
32
  const response = yield cognitoClient.send(new client_cognito_identity_provider_1.AdminInitiateAuthCommand(params));
31
- return (0, transformCognitoResponse_1.cognitoAdminInitiateAuthResponseToQpqAuthenticationInfo)(response);
33
+ return (0, transformCognitoResponse_1.cognitoAdminInitiateAuthResponseToQpqAuthenticationInfo)(response, issueDateTime);
32
34
  });
33
35
  exports.refreshToken = refreshToken;
@@ -1,4 +1,4 @@
1
1
  import { AuthenticateUserResponse, AuthenticationInfo } from 'quidproquo-core';
2
2
  import { AuthenticationResultType, AdminInitiateAuthResponse } from '@aws-sdk/client-cognito-identity-provider';
3
- export declare const cognitoAuthenticationResultTypeToQpqAuthenticationInfo: (authResult: AuthenticationResultType) => AuthenticationInfo;
4
- export declare const cognitoAdminInitiateAuthResponseToQpqAuthenticationInfo: (authResponse: AdminInitiateAuthResponse) => AuthenticateUserResponse;
3
+ export declare const cognitoAuthenticationResultTypeToQpqAuthenticationInfo: (authResult: AuthenticationResultType, issueDateTime: string) => AuthenticationInfo;
4
+ export declare const cognitoAdminInitiateAuthResponseToQpqAuthenticationInfo: (authResponse: AdminInitiateAuthResponse, issueDateTime: string) => AuthenticateUserResponse;
@@ -2,21 +2,28 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.cognitoAdminInitiateAuthResponseToQpqAuthenticationInfo = exports.cognitoAuthenticationResultTypeToQpqAuthenticationInfo = void 0;
4
4
  const quidproquo_core_1 = require("quidproquo-core");
5
- const cognitoAuthenticationResultTypeToQpqAuthenticationInfo = (authResult) => ({
6
- accessToken: authResult.AccessToken,
7
- idToken: authResult.IdToken,
8
- expiresIn: authResult.ExpiresIn,
9
- refreshToken: authResult.RefreshToken,
10
- tokenType: authResult.TokenType,
11
- });
5
+ const cognitoAuthenticationResultTypeToQpqAuthenticationInfo = (authResult, issueDateTime) => {
6
+ // Parse the issueDateTime and add the expiresIn to get the expiration date
7
+ let issueDate = new Date(issueDateTime);
8
+ issueDate.setSeconds(issueDate.getSeconds() + (authResult.ExpiresIn || 0));
9
+ const expiresAt = issueDate.toISOString();
10
+ return {
11
+ accessToken: authResult.AccessToken,
12
+ idToken: authResult.IdToken,
13
+ refreshToken: authResult.RefreshToken,
14
+ tokenType: authResult.TokenType,
15
+ expirationDurationInSeconds: authResult.ExpiresIn,
16
+ expiresAt,
17
+ };
18
+ };
12
19
  exports.cognitoAuthenticationResultTypeToQpqAuthenticationInfo = cognitoAuthenticationResultTypeToQpqAuthenticationInfo;
13
- const cognitoAdminInitiateAuthResponseToQpqAuthenticationInfo = (authResponse) => {
20
+ const cognitoAdminInitiateAuthResponseToQpqAuthenticationInfo = (authResponse, issueDateTime) => {
14
21
  const res = {
15
22
  session: authResponse.Session,
16
23
  challenge: quidproquo_core_1.AuthenticateUserChallenge.NONE,
17
24
  };
18
25
  if (authResponse.AuthenticationResult) {
19
- res.authenticationInfo = (0, exports.cognitoAuthenticationResultTypeToQpqAuthenticationInfo)(authResponse.AuthenticationResult);
26
+ res.authenticationInfo = (0, exports.cognitoAuthenticationResultTypeToQpqAuthenticationInfo)(authResponse.AuthenticationResult, issueDateTime);
20
27
  }
21
28
  return res;
22
29
  };
@@ -10,21 +10,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.verifyJwt = void 0;
13
- const aws_jwt_verify_1 = require("aws-jwt-verify");
13
+ const decodeValidJwt_1 = require("./decodeValidJwt");
14
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
- }
15
+ const info = yield (0, decodeValidJwt_1.decodeValidJwt)(userPoolId, clientId, tokenType, accessToken);
16
+ // if we hav info, its valid
17
+ return !!info;
29
18
  });
30
19
  exports.verifyJwt = verifyJwt;
@@ -0,0 +1,2 @@
1
+ import { StoryResultMetadata } from 'quidproquo-core';
2
+ export declare function getLogByCorrelation(tableName: string, region: string, correlation: string): Promise<StoryResultMetadata>;
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.getLogByCorrelation = void 0;
13
+ const client_dynamodb_1 = require("@aws-sdk/client-dynamodb");
14
+ function getLogByCorrelation(tableName, region, correlation) {
15
+ return __awaiter(this, void 0, void 0, function* () {
16
+ const dynamoDBClient = new client_dynamodb_1.DynamoDBClient({ region });
17
+ const queryParams = {
18
+ TableName: tableName,
19
+ IndexName: 'CorrelationIndex',
20
+ KeyConditionExpression: 'correlation = :correlation',
21
+ ExpressionAttributeValues: {
22
+ ':correlation': { S: correlation },
23
+ },
24
+ };
25
+ try {
26
+ const queryResult = yield dynamoDBClient.send(new client_dynamodb_1.QueryCommand(queryParams));
27
+ const items = (queryResult.Items || []).map((i) => {
28
+ var _a, _b, _c;
29
+ const [startedAt, correlation] = ((_a = i.startedAtWithCorrelation.S) === null || _a === void 0 ? void 0 : _a.split('#')) || [];
30
+ const metaData = {
31
+ generic: i.generic.S || '',
32
+ runtimeType: i.runtimeType.S,
33
+ error: (_b = i.error) === null || _b === void 0 ? void 0 : _b.S,
34
+ startedAt: startedAt,
35
+ correlation,
36
+ moduleName: i.moduleName.S || '',
37
+ fromCorrelation: (_c = i.fromCorrelation) === null || _c === void 0 ? void 0 : _c.S,
38
+ };
39
+ return metaData;
40
+ });
41
+ const [result] = items;
42
+ if (!result) {
43
+ throw new Error(`Failed to find log with correlation: ${correlation}`);
44
+ }
45
+ return result;
46
+ }
47
+ catch (err) {
48
+ console.error(`Failed to find log: ${err}`);
49
+ throw err;
50
+ }
51
+ });
52
+ }
53
+ exports.getLogByCorrelation = getLogByCorrelation;
@@ -0,0 +1,2 @@
1
+ import { QpqLogList } from 'quidproquo-webserver';
2
+ export declare function getLogChildrenByFromCorrelation(tableName: string, region: string, fromCorrelation: string, pageKey?: string): Promise<QpqLogList>;
@@ -0,0 +1,60 @@
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.getLogChildrenByFromCorrelation = void 0;
13
+ const client_dynamodb_1 = require("@aws-sdk/client-dynamodb");
14
+ const logs_1 = require("./logs");
15
+ function getLogChildrenByFromCorrelation(tableName, region, fromCorrelation, pageKey) {
16
+ return __awaiter(this, void 0, void 0, function* () {
17
+ const dynamoDBClient = new client_dynamodb_1.DynamoDBClient({ region });
18
+ const queryParams = {
19
+ TableName: tableName,
20
+ IndexName: 'FromCorrelationIndex',
21
+ KeyConditionExpression: 'fromCorrelation = :fromCorrelation',
22
+ ExpressionAttributeValues: {
23
+ ':fromCorrelation': { S: fromCorrelation },
24
+ },
25
+ };
26
+ if (pageKey) {
27
+ queryParams.ExclusiveStartKey = (0, logs_1.stringToLastEvaluatedKey)(pageKey);
28
+ }
29
+ try {
30
+ const queryResult = yield dynamoDBClient.send(new client_dynamodb_1.QueryCommand(queryParams));
31
+ const items = (queryResult.Items || []).map((i) => {
32
+ var _a, _b, _c;
33
+ const [startedAt, correlation] = ((_a = i.startedAtWithCorrelation.S) === null || _a === void 0 ? void 0 : _a.split('#')) || [];
34
+ const metaData = {
35
+ generic: i.generic.S || '',
36
+ runtimeType: i.runtimeType.S,
37
+ error: (_b = i.error) === null || _b === void 0 ? void 0 : _b.S,
38
+ startedAt: startedAt,
39
+ correlation,
40
+ moduleName: i.moduleName.S || '',
41
+ fromCorrelation: (_c = i.fromCorrelation) === null || _c === void 0 ? void 0 : _c.S,
42
+ };
43
+ return metaData;
44
+ });
45
+ if (queryResult.LastEvaluatedKey) {
46
+ const nextPageKey = (0, logs_1.lastEvaluatedKeyToString)(queryResult.LastEvaluatedKey);
47
+ // You can return the nextPageKey along with the items, so it can be used for the next query.
48
+ return { items, nextPageKey };
49
+ }
50
+ else {
51
+ return { items };
52
+ }
53
+ }
54
+ catch (err) {
55
+ console.error(`Failed to query items with the specified fromCorrelation: ${err}`);
56
+ throw err;
57
+ }
58
+ });
59
+ }
60
+ exports.getLogChildrenByFromCorrelation = getLogChildrenByFromCorrelation;
@@ -11,12 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.getPagedItemsOverRange = void 0;
13
13
  const client_dynamodb_1 = require("@aws-sdk/client-dynamodb");
14
- function lastEvaluatedKeyToString(lastEvaluatedKey) {
15
- return Buffer.from(JSON.stringify(lastEvaluatedKey)).toString('base64');
16
- }
17
- function stringToLastEvaluatedKey(encodedKey) {
18
- return JSON.parse(Buffer.from(encodedKey, 'base64').toString());
19
- }
14
+ const logs_1 = require("./logs");
20
15
  function getPagedItemsOverRange(tableName, region, runtimeType, startIsoDateTime, endIsoDateTime, pageKey) {
21
16
  return __awaiter(this, void 0, void 0, function* () {
22
17
  const dynamoDBClient = new client_dynamodb_1.DynamoDBClient({ region });
@@ -31,7 +26,7 @@ function getPagedItemsOverRange(tableName, region, runtimeType, startIsoDateTime
31
26
  ScanIndexForward: false,
32
27
  };
33
28
  if (pageKey) {
34
- queryParams.ExclusiveStartKey = stringToLastEvaluatedKey(pageKey);
29
+ queryParams.ExclusiveStartKey = (0, logs_1.stringToLastEvaluatedKey)(pageKey);
35
30
  }
36
31
  try {
37
32
  const queryResult = yield dynamoDBClient.send(new client_dynamodb_1.QueryCommand(queryParams));
@@ -50,7 +45,7 @@ function getPagedItemsOverRange(tableName, region, runtimeType, startIsoDateTime
50
45
  return metaData;
51
46
  });
52
47
  if (queryResult.LastEvaluatedKey) {
53
- const nextPageKey = lastEvaluatedKeyToString(queryResult.LastEvaluatedKey);
48
+ const nextPageKey = (0, logs_1.lastEvaluatedKeyToString)(queryResult.LastEvaluatedKey);
54
49
  // You can return the nextPageKey along with the items, so it can be used for the next query.
55
50
  return { items, nextPageKey };
56
51
  }
@@ -0,0 +1 @@
1
+ export * from './utils';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./utils"), exports);
@@ -0,0 +1,2 @@
1
+ export * from './lastEvaluatedKeyToString';
2
+ export * from './stringToLastEvaluatedKey';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./lastEvaluatedKeyToString"), exports);
18
+ __exportStar(require("./stringToLastEvaluatedKey"), exports);
@@ -0,0 +1 @@
1
+ export declare function lastEvaluatedKeyToString(lastEvaluatedKey: any): string;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.lastEvaluatedKeyToString = void 0;
4
+ function lastEvaluatedKeyToString(lastEvaluatedKey) {
5
+ return Buffer.from(JSON.stringify(lastEvaluatedKey)).toString('base64');
6
+ }
7
+ exports.lastEvaluatedKeyToString = lastEvaluatedKeyToString;
@@ -0,0 +1 @@
1
+ export declare function stringToLastEvaluatedKey(encodedKey: string): any;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.stringToLastEvaluatedKey = void 0;
4
+ function stringToLastEvaluatedKey(encodedKey) {
5
+ return JSON.parse(Buffer.from(encodedKey, 'base64').toString());
6
+ }
7
+ exports.stringToLastEvaluatedKey = stringToLastEvaluatedKey;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quidproquo-actionprocessor-awslambda",
3
- "version": "0.0.94",
3
+ "version": "0.0.96",
4
4
  "description": "",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.js",