idea-aws 3.13.2 → 3.13.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.
@@ -14,9 +14,15 @@ export declare class Comprehend {
14
14
  /**
15
15
  * Inspects text and returns an inference of the prevailing sentiment (POSITIVE, NEUTRAL, MIXED, or NEGATIVE).
16
16
  */
17
- detectSentiment(params: ComprehendParameters): Promise<Sentiment>;
17
+ detectSentiment(params: DetectSentimentParameters): Promise<Sentiment>;
18
+ /**
19
+ * Determines the dominant language of the input text.
20
+ */
21
+ detectDominantLanguage(params: {
22
+ text: string;
23
+ }): Promise<string>;
18
24
  }
19
- export interface ComprehendParameters {
25
+ export interface DetectSentimentParameters {
20
26
  /**
21
27
  * The language of the input contents. You can specify any of the primary languages supported by Amazon Comprehend.
22
28
  * All contents must be in the same language. Required.
@@ -20,5 +20,16 @@ class Comprehend {
20
20
  .promise();
21
21
  return result.Sentiment;
22
22
  }
23
+ /**
24
+ * Determines the dominant language of the input text.
25
+ */
26
+ async detectDominantLanguage(params) {
27
+ if (!params.text)
28
+ throw new Error('Missing text');
29
+ const result = await this.comprehend.detectDominantLanguage({ Text: params.text }).promise();
30
+ if (!result.Languages.length)
31
+ throw new Error('Not found');
32
+ return result.Languages[0].LanguageCode;
33
+ }
23
34
  }
24
35
  exports.Comprehend = Comprehend;
@@ -119,7 +119,12 @@ class ResourceController extends genericController_1.GenericController {
119
119
  this.pathParameters[param] = event.pathParameters[param] ? decodeURIComponent(event.pathParameters[param]) : null;
120
120
  this.resourceId = this.pathParameters[options.resourceId || 'proxy'];
121
121
  this.queryParams = event.queryStringParameters || {};
122
- this.body = (event.body ? JSON.parse(event.body) : {}) || {};
122
+ try {
123
+ this.body = (event.body ? JSON.parse(event.body) : {}) || {};
124
+ }
125
+ catch (error) {
126
+ throw new RCError('Malformed body');
127
+ }
123
128
  }
124
129
  initFromEventV1(event, options) {
125
130
  this.authorization = event.headers.Authorization;
@@ -135,7 +140,12 @@ class ResourceController extends genericController_1.GenericController {
135
140
  this.pathParameters[param] = event.pathParameters[param] ? decodeURIComponent(event.pathParameters[param]) : null;
136
141
  this.resourceId = this.pathParameters[options.resourceId || 'proxy'];
137
142
  this.queryParams = event.queryStringParameters || {};
138
- this.body = (event.body ? JSON.parse(event.body) : {}) || {};
143
+ try {
144
+ this.body = (event.body ? JSON.parse(event.body) : {}) || {};
145
+ }
146
+ catch (error) {
147
+ throw new RCError('Malformed body');
148
+ }
139
149
  }
140
150
  controlHandlerError(err = {}, context, replaceWithErrorMessage) {
141
151
  if (err instanceof RCError)
@@ -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
@@ -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();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "idea-aws",
3
- "version": "3.13.2",
3
+ "version": "3.13.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",