idea-aws 3.13.3 → 3.13.6
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.
|
@@ -9,6 +9,7 @@ import { GenericController, GenericControllerOptions } from './genericController
|
|
|
9
9
|
export declare abstract class ResourceController extends GenericController {
|
|
10
10
|
protected event: APIGatewayProxyEventV2 | APIGatewayProxyEvent;
|
|
11
11
|
protected callback: Callback;
|
|
12
|
+
protected initError: boolean;
|
|
12
13
|
protected authorization: string;
|
|
13
14
|
protected claims: any;
|
|
14
15
|
protected principalId: string;
|
|
@@ -13,12 +13,15 @@ const genericController_1 = require("./genericController");
|
|
|
13
13
|
class ResourceController extends genericController_1.GenericController {
|
|
14
14
|
constructor(event, callback, options = {}) {
|
|
15
15
|
super(event, callback, options);
|
|
16
|
+
this.initError = false;
|
|
16
17
|
this.logger = new logger_1.Logger();
|
|
17
18
|
this.templateMatcher = /{{\s?([^{}\s]*)\s?}}/g;
|
|
18
19
|
///
|
|
19
20
|
/// REQUEST HANDLERS
|
|
20
21
|
///
|
|
21
22
|
this.handleRequest = async () => {
|
|
23
|
+
if (this.initError)
|
|
24
|
+
return;
|
|
22
25
|
try {
|
|
23
26
|
await this.checkAuthBeforeRequest();
|
|
24
27
|
try {
|
|
@@ -85,24 +88,30 @@ class ResourceController extends genericController_1.GenericController {
|
|
|
85
88
|
};
|
|
86
89
|
this.event = event;
|
|
87
90
|
this.callback = callback;
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
91
|
+
try {
|
|
92
|
+
if (event.version === '2.0')
|
|
93
|
+
this.initFromEventV2(event, options);
|
|
94
|
+
else
|
|
95
|
+
this.initFromEventV1(event, options);
|
|
96
|
+
this.logRequestsWithKey = options.logRequestsWithKey;
|
|
97
|
+
// acquire some info about the client, if available
|
|
98
|
+
let version = '?', platform = '?';
|
|
99
|
+
if (this.queryParams['_v']) {
|
|
100
|
+
version = this.queryParams['_v'];
|
|
101
|
+
delete this.queryParams['_v'];
|
|
102
|
+
}
|
|
103
|
+
if (this.queryParams['_p']) {
|
|
104
|
+
platform = this.queryParams['_p'];
|
|
105
|
+
delete this.queryParams['_p'];
|
|
106
|
+
}
|
|
107
|
+
// print the initial log
|
|
108
|
+
const info = { principalId: this.principalId, queryParams: this.queryParams, body: this.body, version, platform };
|
|
109
|
+
this.logger.info(`START: ${this.httpMethod} ${this.path}`, info);
|
|
98
110
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
111
|
+
catch (err) {
|
|
112
|
+
this.initError = true;
|
|
113
|
+
this.done(this.controlHandlerError(err, 'INIT-ERROR', 'Malformed request'));
|
|
102
114
|
}
|
|
103
|
-
// print the initial log
|
|
104
|
-
const info = { principalId: this.principalId, queryParams: this.queryParams, body: this.body, version, platform };
|
|
105
|
-
this.logger.info(`START: ${this.httpMethod} ${this.path}`, info);
|
|
106
115
|
}
|
|
107
116
|
initFromEventV2(event, options) {
|
|
108
117
|
this.authorization = event.headers.authorization;
|
|
@@ -119,7 +128,12 @@ class ResourceController extends genericController_1.GenericController {
|
|
|
119
128
|
this.pathParameters[param] = event.pathParameters[param] ? decodeURIComponent(event.pathParameters[param]) : null;
|
|
120
129
|
this.resourceId = this.pathParameters[options.resourceId || 'proxy'];
|
|
121
130
|
this.queryParams = event.queryStringParameters || {};
|
|
122
|
-
|
|
131
|
+
try {
|
|
132
|
+
this.body = (event.body ? JSON.parse(event.body) : {}) || {};
|
|
133
|
+
}
|
|
134
|
+
catch (error) {
|
|
135
|
+
throw new RCError('Malformed body');
|
|
136
|
+
}
|
|
123
137
|
}
|
|
124
138
|
initFromEventV1(event, options) {
|
|
125
139
|
this.authorization = event.headers.Authorization;
|
|
@@ -135,7 +149,12 @@ class ResourceController extends genericController_1.GenericController {
|
|
|
135
149
|
this.pathParameters[param] = event.pathParameters[param] ? decodeURIComponent(event.pathParameters[param]) : null;
|
|
136
150
|
this.resourceId = this.pathParameters[options.resourceId || 'proxy'];
|
|
137
151
|
this.queryParams = event.queryStringParameters || {};
|
|
138
|
-
|
|
152
|
+
try {
|
|
153
|
+
this.body = (event.body ? JSON.parse(event.body) : {}) || {};
|
|
154
|
+
}
|
|
155
|
+
catch (error) {
|
|
156
|
+
throw new RCError('Malformed body');
|
|
157
|
+
}
|
|
139
158
|
}
|
|
140
159
|
controlHandlerError(err = {}, context, replaceWithErrorMessage) {
|
|
141
160
|
if (err instanceof RCError)
|
package/dist/src/translate.d.ts
CHANGED
|
@@ -23,7 +23,9 @@ export declare class Translate {
|
|
|
23
23
|
/**
|
|
24
24
|
* Initialize a new Translate helper object.
|
|
25
25
|
*/
|
|
26
|
-
constructor(
|
|
26
|
+
constructor(params?: {
|
|
27
|
+
region?: string;
|
|
28
|
+
});
|
|
27
29
|
/**
|
|
28
30
|
* Translates input text from the source language to the target language.
|
|
29
31
|
* @param params the parameters for translateText
|
package/dist/src/translate.js
CHANGED
|
@@ -10,8 +10,8 @@ class Translate {
|
|
|
10
10
|
/**
|
|
11
11
|
* Initialize a new Translate helper object.
|
|
12
12
|
*/
|
|
13
|
-
constructor() {
|
|
14
|
-
this.translate = new aws_sdk_1.Translate({ apiVersion: '2017-07-01' });
|
|
13
|
+
constructor(params = {}) {
|
|
14
|
+
this.translate = new aws_sdk_1.Translate({ apiVersion: '2017-07-01', region: params.region });
|
|
15
15
|
this.sourceLanguageCode = 'en';
|
|
16
16
|
this.targetLanguageCode = 'en';
|
|
17
17
|
this.terminologyNames = new Array();
|