quidproquo-actionprocessor-awslambda 0.0.75 → 0.0.76

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.
@@ -5,3 +5,4 @@ export declare const getQpqRuntimeResourceName: (resourceName: string, applicati
5
5
  export declare const getQpqRuntimeResourceNameFromConfig: (resourceName: string, qpqConfig: QPQConfig, resourceType?: string) => string;
6
6
  export declare const getCFExportNameUserPoolIdFromConfig: (userDirectoryName: string, qpqConfig: QPQConfig, serviceOverride?: string, applicationOverride?: string) => string;
7
7
  export declare const getCFExportNameUserPoolClientIdFromConfig: (userDirectoryName: string, qpqConfig: QPQConfig, serviceOverride?: string, applicationOverride?: string) => string;
8
+ export declare const getCFExportNameApiKeyIdFromConfig: (apiKeyName: string, qpqConfig: QPQConfig, serviceOverride?: string, applicationOverride?: string) => string;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getCFExportNameUserPoolClientIdFromConfig = exports.getCFExportNameUserPoolIdFromConfig = exports.getQpqRuntimeResourceNameFromConfig = exports.getQpqRuntimeResourceName = exports.getConfigRuntimeResourceNameFromConfig = exports.getConfigRuntimeResourceName = void 0;
3
+ exports.getCFExportNameApiKeyIdFromConfig = exports.getCFExportNameUserPoolClientIdFromConfig = exports.getCFExportNameUserPoolIdFromConfig = exports.getQpqRuntimeResourceNameFromConfig = exports.getQpqRuntimeResourceName = exports.getConfigRuntimeResourceNameFromConfig = exports.getConfigRuntimeResourceName = void 0;
4
4
  const quidproquo_core_1 = require("quidproquo-core");
5
5
  const getConfigRuntimeResourceName = (resourceName, application, service, environment, feature) => {
6
6
  const baseName = `${resourceName}-${application}-${service}-${environment}`;
@@ -47,3 +47,11 @@ const getCFExportNameUserPoolClientIdFromConfig = (userDirectoryName, qpqConfig,
47
47
  return (0, exports.getQpqRuntimeResourceName)(userDirectoryName, application, service, environment, feature, 'user-pool-client-id-export');
48
48
  };
49
49
  exports.getCFExportNameUserPoolClientIdFromConfig = getCFExportNameUserPoolClientIdFromConfig;
50
+ const getCFExportNameApiKeyIdFromConfig = (apiKeyName, qpqConfig, serviceOverride, applicationOverride) => {
51
+ const application = applicationOverride || quidproquo_core_1.qpqCoreUtils.getApplicationName(qpqConfig);
52
+ const service = serviceOverride || quidproquo_core_1.qpqCoreUtils.getApplicationModuleName(qpqConfig);
53
+ const environment = quidproquo_core_1.qpqCoreUtils.getApplicationModuleEnvironment(qpqConfig);
54
+ const feature = quidproquo_core_1.qpqCoreUtils.getApplicationModuleFeature(qpqConfig);
55
+ return (0, exports.getQpqRuntimeResourceName)(apiKeyName, application, service, environment, feature, 'api-key-id-export');
56
+ };
57
+ exports.getCFExportNameApiKeyIdFromConfig = getCFExportNameApiKeyIdFromConfig;
@@ -13,6 +13,7 @@ exports.isAuthValid = void 0;
13
13
  const quidproquo_core_1 = require("quidproquo-core");
14
14
  const verifyJwt_1 = require("../../../../logic/cognito/verifyJwt");
15
15
  const getExportedValue_1 = require("../../../../logic/cloudformation/getExportedValue");
16
+ const getApiKeys_1 = require("../../../../logic/apiGateway/getApiKeys");
16
17
  const awsNamingUtils_1 = require("../../../../awsNamingUtils");
17
18
  const isAuthValidForCognito = (qpqConfig, authSettings, authHeader) => __awaiter(void 0, void 0, void 0, function* () {
18
19
  // If there are no auth settings ~ Its valid.
@@ -38,12 +39,22 @@ const isAuthValidForCognito = (qpqConfig, authSettings, authHeader) => __awaiter
38
39
  // Verify the token
39
40
  return yield (0, verifyJwt_1.verifyJwt)(accessToken, userPoolId, userPoolClientId, 'access');
40
41
  });
41
- const isAuthValidForApiKeys = (authSettings, apiKeyHeader) => __awaiter(void 0, void 0, void 0, function* () {
42
+ const isAuthValidForApiKeys = (qpqConfig, authSettings, apiKeyHeader) => __awaiter(void 0, void 0, void 0, function* () {
42
43
  const apiKeys = authSettings.apiKeys || [];
43
44
  if (apiKeys.length === 0) {
44
45
  return true;
45
46
  }
46
- const index = apiKeys.findIndex((apiKey) => apiKey.value === apiKeyHeader);
47
+ const region = quidproquo_core_1.qpqCoreUtils.getApplicationModuleDeployRegion(qpqConfig);
48
+ const application = quidproquo_core_1.qpqCoreUtils.getApplicationName(qpqConfig);
49
+ const service = quidproquo_core_1.qpqCoreUtils.getApplicationModuleName(qpqConfig);
50
+ const environment = quidproquo_core_1.qpqCoreUtils.getApplicationModuleEnvironment(qpqConfig);
51
+ const feature = quidproquo_core_1.qpqCoreUtils.getApplicationModuleFeature(qpqConfig);
52
+ const realApiKeys = yield (0, getApiKeys_1.getApiKeys)(region, ...apiKeys.map((apiKey) => {
53
+ const apiKeyApplication = apiKey.applicationName || application;
54
+ const apiKeyService = apiKey.serviceName || service;
55
+ return (0, awsNamingUtils_1.getConfigRuntimeResourceName)(apiKey.name, apiKeyApplication, apiKeyService, environment, feature);
56
+ }));
57
+ const index = realApiKeys.findIndex((apiKey) => apiKey.value === apiKeyHeader);
47
58
  return index >= 0;
48
59
  });
49
60
  const isAuthValid = (qpqConfig, authHeader, apiKeyHeader, authSettings) => __awaiter(void 0, void 0, void 0, function* () {
@@ -52,7 +63,7 @@ const isAuthValid = (qpqConfig, authHeader, apiKeyHeader, authSettings) => __awa
52
63
  return true;
53
64
  }
54
65
  const cognitoValid = yield isAuthValidForCognito(qpqConfig, authSettings, authHeader);
55
- const authKeysValid = yield isAuthValidForApiKeys(authSettings, apiKeyHeader);
66
+ const authKeysValid = yield isAuthValidForApiKeys(qpqConfig, authSettings, apiKeyHeader);
56
67
  return cognitoValid && authKeysValid;
57
68
  });
58
69
  exports.isAuthValid = isAuthValid;
@@ -0,0 +1,2 @@
1
+ import { ApiKey } from 'quidproquo-webserver';
2
+ export declare const getApiKeys: (region: string, ...keyNames: string[]) => Promise<ApiKey[]>;
@@ -0,0 +1,24 @@
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.getApiKeys = void 0;
13
+ const client_api_gateway_1 = require("@aws-sdk/client-api-gateway");
14
+ const getApiKeys = (region, ...keyNames) => __awaiter(void 0, void 0, void 0, function* () {
15
+ var _a;
16
+ const apiGatewayClient = new client_api_gateway_1.APIGatewayClient({ region });
17
+ const input = {
18
+ includeValues: true,
19
+ limit: 500,
20
+ };
21
+ const res = yield apiGatewayClient.send(new client_api_gateway_1.GetApiKeysCommand(input));
22
+ return (((_a = res.items) === null || _a === void 0 ? void 0 : _a.filter((i) => keyNames.indexOf(i.name) >= 0).map((i) => ({ name: i.name, value: i.value, description: i.description }))) || []);
23
+ });
24
+ exports.getApiKeys = getApiKeys;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quidproquo-actionprocessor-awslambda",
3
- "version": "0.0.75",
3
+ "version": "0.0.76",
4
4
  "description": "",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.js",
@@ -25,14 +25,15 @@
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",
30
- "@aws-sdk/client-s3": "^3.266.0",
31
- "@aws-sdk/client-secrets-manager": "^3.266.0",
32
- "@aws-sdk/client-sqs": "^3.266.0",
33
- "@aws-sdk/client-ssm": "^3.266.0",
28
+ "@aws-sdk/client-api-gateway": "^3.278.0",
29
+ "@aws-sdk/client-cloudformation": "^3.278.0",
30
+ "@aws-sdk/client-cognito-identity-provider": "^3.278.0",
31
+ "@aws-sdk/client-s3": "^3.278.0",
32
+ "@aws-sdk/client-secrets-manager": "^3.278.0",
33
+ "@aws-sdk/client-sqs": "^3.278.0",
34
+ "@aws-sdk/client-ssm": "^3.278.0",
34
35
  "aws-jwt-verify": "^3.4.0",
35
- "aws-sdk": "^2.1264.0",
36
+ "aws-sdk": "^2.1322.0",
36
37
  "node-match-path": "^0.6.3",
37
38
  "quidproquo-core": "*",
38
39
  "quidproquo-webserver": "*"