idea-aws 3.10.1 → 3.10.5

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,7 +5,9 @@ import { CognitoUser } from 'idea-toolbox';
5
5
  */
6
6
  export declare class Cognito {
7
7
  protected cognito: CognitoIdentityServiceProvider;
8
- constructor();
8
+ constructor(params?: {
9
+ region?: string;
10
+ });
9
11
  /**
10
12
  * Change the region in which to find the user pool.
11
13
  * Default: the runner's (e.g. Lambda function) region.
@@ -7,8 +7,8 @@ const idea_toolbox_1 = require("idea-toolbox");
7
7
  * A wrapper for AWS Cognito.
8
8
  */
9
9
  class Cognito {
10
- constructor() {
11
- this.cognito = new aws_sdk_1.CognitoIdentityServiceProvider({ apiVersion: '2016-04-18' });
10
+ constructor(params = {}) {
11
+ this.cognito = new aws_sdk_1.CognitoIdentityServiceProvider({ apiVersion: '2016-04-18', region: params.region });
12
12
  }
13
13
  /**
14
14
  * Change the region in which to find the user pool.
@@ -106,8 +106,10 @@ class ResourceController extends genericController_1.GenericController {
106
106
  }
107
107
  initFromEventV2(event, options) {
108
108
  this.authorization = event.headers.authorization;
109
- const contextFromAuthorizer = event.requestContext?.authorizer?.lambda || {};
110
- this.principalId = contextFromAuthorizer.principalId;
109
+ const authorizer = event.requestContext?.authorizer ?? {};
110
+ const contextFromAuthorizer = authorizer.lambda ?? authorizer.jwt?.claims ?? {};
111
+ this.principalId = contextFromAuthorizer.principalId ?? contextFromAuthorizer.sub ?? null;
112
+ this.cognitoUser = authorizer.jwt?.claims ? new idea_toolbox_1.CognitoUser(authorizer.jwt?.claims) : null;
111
113
  this.stage = event.requestContext.stage;
112
114
  this.httpMethod = event.requestContext.http.method;
113
115
  this.resource = event.routeKey.replace('+', ''); // {proxy+} -> {proxy}
@@ -319,7 +321,9 @@ class ResourceController extends genericController_1.GenericController {
319
321
  if (!event.requestContext)
320
322
  event.requestContext = {};
321
323
  event.requestContext.stage = params.stage || this.stage;
322
- event.requestContext.httpMethod = event.httpMethod = params.httpMethod;
324
+ if (!event.requestContext.http)
325
+ event.requestContext.http = {};
326
+ event.requestContext.http.method = event.httpMethod = params.httpMethod;
323
327
  event.routeKey = event.resource = params.resource;
324
328
  event.pathParameters = params.pathParams || {};
325
329
  event.queryStringParameters = params.queryParams || {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "idea-aws",
3
- "version": "3.10.1",
3
+ "version": "3.10.5",
4
4
  "description": "AWS wrappers to use in IDEA's back-ends",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -35,7 +35,7 @@
35
35
  },
36
36
  "homepage": "https://uatisdeproblem.github.io/IDEA-AWS",
37
37
  "dependencies": {
38
- "idea-toolbox": "^6.5.9",
38
+ "idea-toolbox": "^6.5.11",
39
39
  "nanoid": "^3.2.0",
40
40
  "nodemailer": "^6.7.2",
41
41
  "shortid": "^2.2.16",