idea-aws 4.4.3 → 4.4.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.
Files changed (71) hide show
  1. package/package.json +1 -1
  2. package/.eslintrc.js +0 -16
  3. package/.prettierrc +0 -9
  4. package/.vscode/settings.json +0 -26
  5. package/HOW-TO-RELEASE.md +0 -8
  6. package/build.sh +0 -21
  7. package/docs/.nojekyll +0 -1
  8. package/docs/assets/custom.css +0 -4
  9. package/docs/assets/highlight.css +0 -50
  10. package/docs/assets/main.js +0 -58
  11. package/docs/assets/search.js +0 -1
  12. package/docs/assets/style.css +0 -1367
  13. package/docs/classes/Attachments.html +0 -201
  14. package/docs/classes/Cognito.html +0 -713
  15. package/docs/classes/Comprehend.html +0 -176
  16. package/docs/classes/DynamoDB.html +0 -584
  17. package/docs/classes/GenericController.html +0 -262
  18. package/docs/classes/HandledError.html +0 -219
  19. package/docs/classes/LambdaLogger.html +0 -220
  20. package/docs/classes/ResourceController.html +0 -957
  21. package/docs/classes/S3.html +0 -391
  22. package/docs/classes/SES.html +0 -335
  23. package/docs/classes/SNS.html +0 -185
  24. package/docs/classes/SecretsManager.html +0 -159
  25. package/docs/classes/StreamController.html +0 -284
  26. package/docs/classes/SystemsManager.html +0 -184
  27. package/docs/classes/Translate.html +0 -239
  28. package/docs/classes/UnhandledError.html +0 -252
  29. package/docs/functions/cleanFilename.html +0 -93
  30. package/docs/index.html +0 -95
  31. package/docs/interfaces/BasicEmailData.html +0 -145
  32. package/docs/interfaces/CognitoGroup.html +0 -122
  33. package/docs/interfaces/CognitoUserGeneric.html +0 -125
  34. package/docs/interfaces/CopyObjectOptions.html +0 -132
  35. package/docs/interfaces/CreateDownloadURLFromDataOptions.html +0 -163
  36. package/docs/interfaces/CreateUserOptions.html +0 -122
  37. package/docs/interfaces/DeleteObjectOptions.html +0 -122
  38. package/docs/interfaces/DetectSentimentParameters.html +0 -121
  39. package/docs/interfaces/EmailAttachment.html +0 -176
  40. package/docs/interfaces/EmailData.html +0 -188
  41. package/docs/interfaces/GetObjectOptions.html +0 -133
  42. package/docs/interfaces/HeadObjectOptions.html +0 -132
  43. package/docs/interfaces/InternalAPIRequestParams.html +0 -207
  44. package/docs/interfaces/ListObjectsOptions.html +0 -122
  45. package/docs/interfaces/PutObjectOptions.html +0 -173
  46. package/docs/interfaces/ResourceControllerOptions.html +0 -142
  47. package/docs/interfaces/SESParams.html +0 -152
  48. package/docs/interfaces/SNSCreateEndpointParams.html +0 -132
  49. package/docs/interfaces/SNSPublishParams.html +0 -142
  50. package/docs/interfaces/SignedURLOptions.html +0 -123
  51. package/docs/interfaces/TemplatedEmailData.html +0 -186
  52. package/docs/interfaces/TranslateParameters.html +0 -140
  53. package/docs/modules.html +0 -130
  54. package/docs/variables/LOG_LEVELS_PRIORITY.html +0 -81
  55. package/docs.style.css +0 -4
  56. package/src/attachments.ts +0 -41
  57. package/src/cognito.ts +0 -511
  58. package/src/comprehend.ts +0 -52
  59. package/src/dynamoDB.ts +0 -311
  60. package/src/genericController.ts +0 -103
  61. package/src/lambdaLogger.ts +0 -39
  62. package/src/metrics.ts +0 -45
  63. package/src/resourceController.ts +0 -645
  64. package/src/s3.ts +0 -334
  65. package/src/secretsManager.ts +0 -24
  66. package/src/ses.ts +0 -313
  67. package/src/sns.ts +0 -118
  68. package/src/ssm.ts +0 -33
  69. package/src/streamController.ts +0 -25
  70. package/src/translate.ts +0 -174
  71. package/tsconfig.json +0 -10
package/src/cognito.ts DELETED
@@ -1,511 +0,0 @@
1
- import * as CognitoIP from '@aws-sdk/client-cognito-identity-provider';
2
- import { CognitoUser, isEmpty } from 'idea-toolbox';
3
-
4
- /**
5
- * A wrapper for AWS Cognito.
6
- */
7
- export class Cognito {
8
- protected cognito: CognitoIP.CognitoIdentityProviderClient;
9
-
10
- constructor(options: { region?: string } = {}) {
11
- this.cognito = new CognitoIP.CognitoIdentityProviderClient({ region: options.region });
12
- }
13
-
14
- /**
15
- * Change the region in which to find the user pool.
16
- * Default: the runner's (e.g. Lambda function) region.
17
- */
18
- setRegion(region: string): void {
19
- // there is no quick way to change the region without re-creating the object
20
- this.cognito = new CognitoIP.CognitoIdentityProviderClient({ region });
21
- }
22
-
23
- /**
24
- * Get the attributes of the user, from the authorizer claims.
25
- * @param claims authorizer claims
26
- * @return user's data
27
- * @deprecated use idea-toolbox's CognitoUser instead
28
- */
29
- getUserByClaims(claims: Record<string, any>): CognitoUserGeneric {
30
- if (!claims) return null;
31
- const user: Record<string, any> = {};
32
- // add any additional cognito attribute available in cognito
33
- for (const p in claims) if (p.startsWith('cognito:')) user[p.slice(8)] = claims[p];
34
- // map the important attributes with reserved names
35
- user.userId = claims.sub;
36
- user.email = claims.email;
37
- return user as CognitoUserGeneric;
38
- }
39
-
40
- /**
41
- * Map the complex structure returned by Cognito for a user's attributes in a simple key-value object.
42
- */
43
- private mapCognitoUserAttributesAsPlainObject(user: Record<string, any>): CognitoUserGeneric {
44
- const userAttributes: Record<string, any> = {};
45
- (user.Attributes ?? user.UserAttributes ?? []).forEach((a: any): void => (userAttributes[a.Name] = a.Value));
46
-
47
- if (!userAttributes.userId) userAttributes.userId = userAttributes.sub;
48
- return userAttributes as CognitoUserGeneric;
49
- }
50
-
51
- //
52
- // ADMIN
53
- //
54
-
55
- /**
56
- * Identify a user by its email address, returning its attributes.
57
- */
58
- async getUserByEmail(email: string, userPoolId: string): Promise<CognitoUserGeneric> {
59
- const command = new CognitoIP.AdminGetUserCommand({ UserPoolId: userPoolId, Username: email });
60
- try {
61
- const user = await this.cognito.send(command);
62
- return this.mapCognitoUserAttributesAsPlainObject(user);
63
- } catch (error) {
64
- if ((error as Error).name === 'UserNotFoundException') throw new Error('User not found');
65
- throw error;
66
- }
67
- }
68
-
69
- /**
70
- * Identify a user by its userId (sub), returning its attributes.
71
- */
72
- async getUserBySub(sub: string, userPoolId: string): Promise<CognitoUserGeneric> {
73
- // as of today, there is no a direct way to find a user by its sub: we need to run a query against the users base
74
- const command = new CognitoIP.ListUsersCommand({ UserPoolId: userPoolId, Filter: `sub = "${sub}"`, Limit: 1 });
75
- const { Users } = await this.cognito.send(command);
76
- if (Users.length < 1) throw new Error('User not found');
77
- return this.mapCognitoUserAttributesAsPlainObject(Users[0]);
78
- }
79
-
80
- /**
81
- * List all the users of the pool.
82
- */
83
- async listUsers(
84
- userPoolId: string,
85
- options: { pagination?: string; users: CognitoUser[] } = { users: [] }
86
- ): Promise<CognitoUser[]> {
87
- const params: CognitoIP.ListUsersCommandInput = { UserPoolId: userPoolId };
88
- if (options.pagination) params.PaginationToken = options.pagination;
89
-
90
- const { Users, PaginationToken: pagination } = await this.cognito.send(new CognitoIP.ListUsersCommand(params));
91
-
92
- const users = options.users.concat(Users.map(u => new CognitoUser(this.mapCognitoUserAttributesAsPlainObject(u))));
93
-
94
- if (pagination) return await this.listUsers(userPoolId, { pagination, users });
95
- else return users;
96
- }
97
- /**
98
- * List all the users of the pool, including the information about the groups they're in.
99
- * Note: it's slower than the alternative `getAllUsers`: use it only when needed.
100
- */
101
- async listUsersWithGroupsDetail(cognitoUserPoolId: string): Promise<CognitoUser[]> {
102
- const groups = await this.listGroups(cognitoUserPoolId);
103
-
104
- const users: CognitoUser[] = [];
105
- for (const group of groups) {
106
- const usersOfGroup = await this.listUsersInGroup(group.name, cognitoUserPoolId);
107
- usersOfGroup.forEach(userInGroup => {
108
- const userAlreadyInOutputList = users.find(u => u.userId === userInGroup.userId);
109
- if (userAlreadyInOutputList) userAlreadyInOutputList.groups.push(group.name);
110
- else {
111
- userInGroup.groups.push(group.name);
112
- users.push(userInGroup);
113
- }
114
- });
115
- }
116
-
117
- return users;
118
- }
119
-
120
- /**
121
- * Create a new user (by its email) in the pool specified.
122
- * @return userId of the new user
123
- */
124
- async createUser(
125
- cognitoUserOrEmail: CognitoUser | string,
126
- userPoolId: string,
127
- options: CreateUserOptions = {}
128
- ): Promise<string> {
129
- const email =
130
- typeof cognitoUserOrEmail === 'string'
131
- ? (cognitoUserOrEmail as string)
132
- : (cognitoUserOrEmail as CognitoUser).email;
133
-
134
- if (isEmpty(email, 'email')) throw new Error('INVALID_EMAIL');
135
-
136
- const UserAttributes = [
137
- { Name: 'email', Value: email },
138
- { Name: 'email_verified', Value: 'true' }
139
- ];
140
-
141
- if (typeof cognitoUserOrEmail === 'object') {
142
- const user = cognitoUserOrEmail as CognitoUser;
143
-
144
- UserAttributes.push({ Name: 'name', Value: user.name });
145
- UserAttributes.push({ Name: 'picture', Value: user.picture || '' });
146
-
147
- Object.keys(user.attributes).forEach(a =>
148
- UserAttributes.push({ Name: 'custom:'.concat(a), Value: String(user.attributes[a]) })
149
- );
150
- }
151
-
152
- const params: CognitoIP.AdminCreateUserCommandInput = { UserPoolId: userPoolId, Username: email, UserAttributes };
153
- if (options.skipNotification) params.MessageAction = 'SUPPRESS';
154
- if (options.temporaryPassword) params.TemporaryPassword = options.temporaryPassword;
155
-
156
- const { User } = await this.cognito.send(new CognitoIP.AdminCreateUserCommand(params));
157
-
158
- const userId = this.mapCognitoUserAttributesAsPlainObject(User).sub;
159
-
160
- if (!userId) throw new Error('Creation failed');
161
- return userId;
162
- }
163
-
164
- /**
165
- * Resend the password to a user who never logged in.
166
- */
167
- async resendPassword(email: string, userPoolId: string, options: CreateUserOptions = {}): Promise<void> {
168
- if (isEmpty(email, 'email')) throw new Error('Invalid email');
169
-
170
- const params: CognitoIP.AdminCreateUserCommandInput = {
171
- UserPoolId: userPoolId,
172
- Username: email,
173
- MessageAction: 'RESEND'
174
- };
175
- if (options.temporaryPassword) params.TemporaryPassword = options.temporaryPassword;
176
-
177
- await this.cognito.send(new CognitoIP.AdminCreateUserCommand(params));
178
- }
179
-
180
- /**
181
- * Set a new password for a specific user identified by its email (admin-only).
182
- * If not specified, the password is generated randomly, and the user must change it at the first login.
183
- */
184
- async setPassword(
185
- email: string,
186
- userPoolId: string,
187
- options: { password?: string; permanent?: boolean } = {}
188
- ): Promise<void> {
189
- if (isEmpty(email, 'email')) throw new Error('Invalid email');
190
-
191
- const RANDOM_PASSWORD_LENGTH = 8;
192
- const password =
193
- options.password ??
194
- Math.random()
195
- .toString(36)
196
- .slice(2, 2 + RANDOM_PASSWORD_LENGTH);
197
-
198
- const params: CognitoIP.AdminSetUserPasswordCommandInput = {
199
- UserPoolId: userPoolId,
200
- Username: email,
201
- Password: password,
202
- Permanent: options.permanent
203
- };
204
-
205
- await this.cognito.send(new CognitoIP.AdminSetUserPasswordCommand(params));
206
- }
207
-
208
- /**
209
- * Delete a user by its email (username), in the pool specified.
210
- */
211
- async deleteUser(email: string, userPoolId: string): Promise<void> {
212
- if (isEmpty(email, 'email')) throw new Error('Invalid email');
213
-
214
- const command = new CognitoIP.AdminDeleteUserCommand({ UserPoolId: userPoolId, Username: email });
215
- await this.cognito.send(command);
216
- }
217
-
218
- //
219
- // USER
220
- //
221
-
222
- /**
223
- * Sign in a user of a specific pool through username and password.
224
- */
225
- async signIn(
226
- email: string,
227
- password: string,
228
- userPoolId: string,
229
- userPoolClientId: string
230
- ): Promise<CognitoIP.AuthenticationResultType> {
231
- const command = new CognitoIP.AdminInitiateAuthCommand({
232
- UserPoolId: userPoolId,
233
- ClientId: userPoolClientId,
234
- AuthFlow: 'ADMIN_NO_SRP_AUTH',
235
- AuthParameters: { USERNAME: email, PASSWORD: password }
236
- });
237
- const { AuthenticationResult } = await this.cognito.send(command);
238
-
239
- if (!AuthenticationResult) throw new Error('Sign-in failed');
240
- return AuthenticationResult;
241
- }
242
-
243
- /**
244
- * Given a username and a refresh token (and pool data), refresh the session and return the new tokens.
245
- */
246
- async refreshSession(
247
- email: string,
248
- refreshToken: string,
249
- userPoolId: string,
250
- userPoolClientId: string
251
- ): Promise<CognitoIP.AuthenticationResultType> {
252
- const command = new CognitoIP.AdminInitiateAuthCommand({
253
- UserPoolId: userPoolId,
254
- ClientId: userPoolClientId,
255
- AuthFlow: 'REFRESH_TOKEN_AUTH',
256
- AuthParameters: { USERNAME: email, REFRESH_TOKEN: refreshToken }
257
- });
258
- const { AuthenticationResult } = await this.cognito.send(command);
259
-
260
- if (!AuthenticationResult) throw new Error('Refresh failed');
261
- return AuthenticationResult;
262
- }
263
-
264
- /**
265
- * Change the email address (== username) associated to a user.
266
- */
267
- async updateEmail(email: string, newEmail: string, userPoolId: string): Promise<void> {
268
- if (isEmpty(newEmail, 'email')) throw new Error('Invalid new email');
269
-
270
- const command = new CognitoIP.AdminUpdateUserAttributesCommand({
271
- UserPoolId: userPoolId,
272
- Username: email,
273
- UserAttributes: [
274
- { Name: 'email', Value: newEmail },
275
- { Name: 'email_verified', Value: 'true' }
276
- ]
277
- });
278
- await this.cognito.send(command);
279
-
280
- // sign out the user from all its devices and resolve
281
- await this.globalSignOut(newEmail, userPoolId);
282
- }
283
-
284
- /**
285
- * Change the password to sign in for a user.
286
- */
287
- async updatePassword(
288
- email: string,
289
- oldPassword: string,
290
- newPassword: string,
291
- userPoolId: string,
292
- userPoolClientId: string
293
- ): Promise<void> {
294
- if (newPassword.length < 8) throw new Error('Invalid new password');
295
-
296
- const tokensForPasswordChange = await this.signIn(email, oldPassword, userPoolId, userPoolClientId);
297
-
298
- const command = new CognitoIP.ChangePasswordCommand({
299
- AccessToken: tokensForPasswordChange.AccessToken,
300
- PreviousPassword: oldPassword,
301
- ProposedPassword: newPassword
302
- });
303
- await this.cognito.send(command);
304
- }
305
-
306
- /**
307
- * Send to a user the instructions to change the password.
308
- */
309
- async forgotPassword(email: string, userPoolClientId: string): Promise<CognitoIP.CodeDeliveryDetailsType> {
310
- const command = new CognitoIP.ForgotPasswordCommand({ Username: email, ClientId: userPoolClientId });
311
- const { CodeDeliveryDetails } = await this.cognito.send(command);
312
- return CodeDeliveryDetails;
313
- }
314
- /**
315
- * Complete the flow of a password forgot.
316
- */
317
- async confirmForgotPassword(
318
- email: string,
319
- newPassword: string,
320
- confirmationCode: string,
321
- userPoolClientId: string
322
- ): Promise<void> {
323
- const command = new CognitoIP.ConfirmForgotPasswordCommand({
324
- ClientId: userPoolClientId,
325
- Username: email,
326
- ConfirmationCode: confirmationCode,
327
- Password: newPassword
328
- });
329
- await this.cognito.send(command);
330
- }
331
-
332
- /**
333
- * Update a (Cognito)User's attributes, excluding the attributes that require specific methods.
334
- */
335
- async updateUser(user: CognitoUser, userPoolId: string): Promise<void> {
336
- const UserAttributes = [
337
- { Name: 'name', Value: user.name },
338
- { Name: 'picture', Value: user.picture ?? '' }
339
- ];
340
-
341
- Object.keys(user.attributes).forEach(customAttribute =>
342
- UserAttributes.push({
343
- Name: 'custom:'.concat(customAttribute),
344
- Value: String(user.attributes[customAttribute])
345
- })
346
- );
347
-
348
- const command = new CognitoIP.AdminUpdateUserAttributesCommand({
349
- UserPoolId: userPoolId,
350
- Username: user.email,
351
- UserAttributes
352
- });
353
- await this.cognito.send(command);
354
- }
355
-
356
- /**
357
- * Sign out the user from all devices.
358
- */
359
- async globalSignOut(email: string, userPoolId: string): Promise<void> {
360
- const command = new CognitoIP.AdminUserGlobalSignOutCommand({ Username: email, UserPoolId: userPoolId });
361
- await this.cognito.send(command);
362
- }
363
-
364
- /**
365
- * Confirm and conclude a registration, usign a confirmation code.
366
- */
367
- async confirmSignUp(email: string, confirmationCode: string, userPoolClientId: string): Promise<void> {
368
- if (!email) throw new Error('Invalid email');
369
- if (!confirmationCode) throw new Error('Invalid confirmation code');
370
- if (!userPoolClientId) throw new Error('Invalid client ID');
371
-
372
- const command = new CognitoIP.ConfirmSignUpCommand({
373
- Username: email,
374
- ConfirmationCode: confirmationCode,
375
- ClientId: userPoolClientId
376
- });
377
- await this.cognito.send(command);
378
- }
379
-
380
- /**
381
- * List the groups of the user pool.
382
- */
383
- async listGroups(
384
- userPoolId: string,
385
- options: { pagination?: string; groups: CognitoGroup[] } = { groups: [] }
386
- ): Promise<CognitoGroup[]> {
387
- const params: CognitoIP.ListGroupsRequest = { UserPoolId: userPoolId };
388
- if (options.pagination) params.NextToken = options.pagination;
389
-
390
- const res = await this.cognito.send(new CognitoIP.ListGroupsCommand(params));
391
-
392
- const pagination = res.NextToken;
393
- const groups = options.groups.concat(
394
- res.Groups.map(g => ({ name: g.GroupName, description: g.Description } as CognitoGroup))
395
- );
396
-
397
- if (pagination) return await this.listGroups(userPoolId, { pagination, groups });
398
- else return groups;
399
- }
400
- /**
401
- * Create a new group in the user pool.
402
- */
403
- async createGroup(groupName: string, userPoolId: string): Promise<void> {
404
- const command = new CognitoIP.CreateGroupCommand({ GroupName: groupName, UserPoolId: userPoolId });
405
- await this.cognito.send(command);
406
- }
407
- /**
408
- * Delete a group from the user pool.
409
- */
410
- async deleteGroup(groupName: string, userPoolId: string): Promise<void> {
411
- const command = new CognitoIP.DeleteGroupCommand({ GroupName: groupName, UserPoolId: userPoolId });
412
- await this.cognito.send(command);
413
- }
414
-
415
- /**
416
- * List the users part of a group in the user pool.
417
- */
418
- async listUsersInGroup(
419
- group: string,
420
- userPoolId: string,
421
- options: { pagination?: string; users: CognitoUser[] } = { users: [] }
422
- ): Promise<CognitoUser[]> {
423
- const params: CognitoIP.ListUsersInGroupRequest = {
424
- UserPoolId: userPoolId,
425
- GroupName: group
426
- };
427
- if (options.pagination) params.NextToken = options.pagination;
428
-
429
- const res = await this.cognito.send(new CognitoIP.ListUsersInGroupCommand(params));
430
-
431
- const pagination = res.NextToken;
432
- const users = options.users.concat(
433
- res.Users.map(u => new CognitoUser(this.mapCognitoUserAttributesAsPlainObject(u)))
434
- );
435
-
436
- if (pagination) return await this.listUsersInGroup(group, userPoolId, { pagination, users });
437
- else return users;
438
- }
439
- /**
440
- * Add a user (by email) to a group in the user pool.
441
- */
442
- async addUserToGroup(email: string, group: string, userPoolId: string): Promise<void> {
443
- const user = new CognitoUser(await this.getUserByEmail(email, userPoolId));
444
-
445
- const command = new CognitoIP.AdminAddUserToGroupCommand({
446
- UserPoolId: userPoolId,
447
- GroupName: group,
448
- Username: user.userId
449
- });
450
- await this.cognito.send(command);
451
- }
452
- /**
453
- * Remove a user (by email) from a group in the user pool.
454
- */
455
- async removeUserFromGroup(email: string, group: string, userPoolId: string): Promise<void> {
456
- const user = new CognitoUser(await this.getUserByEmail(email, userPoolId));
457
-
458
- const command = new CognitoIP.AdminRemoveUserFromGroupCommand({
459
- UserPoolId: userPoolId,
460
- GroupName: group,
461
- Username: user.userId
462
- });
463
- await this.cognito.send(command);
464
- }
465
- }
466
-
467
- /**
468
- * The attributes of a generic Cognito user of which we don't know the custom attributes.
469
- */
470
- export interface CognitoUserGeneric {
471
- /**
472
- * The user id (sub).
473
- */
474
- userId: string;
475
- /**
476
- * The email (=== username).
477
- */
478
- email: string;
479
- /**
480
- * Cognito can have custom attributes.
481
- */
482
- [attribute: string]: string;
483
- }
484
-
485
- /**
486
- * Options when creating a new user.
487
- */
488
- export interface CreateUserOptions {
489
- /**
490
- * Uf true, don't send the default Cognito email notification
491
- */
492
- skipNotification?: boolean;
493
- /**
494
- * If null, randomly generated
495
- */
496
- temporaryPassword?: string;
497
- }
498
-
499
- /**
500
- * The attributes of a Cognito group.
501
- */
502
- export interface CognitoGroup {
503
- /**
504
- * The name (and id) of the group.
505
- */
506
- name: string;
507
- /**
508
- * The description of the group.
509
- */
510
- description: string;
511
- }
package/src/comprehend.ts DELETED
@@ -1,52 +0,0 @@
1
- import * as AmazonComprehend from '@aws-sdk/client-comprehend';
2
- import { Sentiment } from 'idea-toolbox';
3
-
4
- /**
5
- * A wrapper for Amazon Comprehend.
6
- */
7
- export class Comprehend {
8
- protected comprehend: AmazonComprehend.ComprehendClient;
9
-
10
- constructor(options: { region?: string } = {}) {
11
- this.comprehend = new AmazonComprehend.ComprehendClient({ region: options.region });
12
- }
13
-
14
- /**
15
- * Inspects text and returns an inference of the prevailing sentiment (POSITIVE, NEUTRAL, MIXED, or NEGATIVE).
16
- */
17
- async detectSentiment(params: DetectSentimentParameters): Promise<Sentiment> {
18
- if (!params.language || !params.text) throw new Error('Missing some parameters');
19
-
20
- const command = new AmazonComprehend.DetectSentimentCommand({ LanguageCode: params.language, Text: params.text });
21
- const { Sentiment } = await this.comprehend.send(command);
22
-
23
- return Sentiment as Sentiment;
24
- }
25
-
26
- /**
27
- * Determines the dominant language of the input text.
28
- */
29
- async detectDominantLanguage(params: { text: string }): Promise<string> {
30
- if (!params.text) throw new Error('Missing text');
31
-
32
- const command = new AmazonComprehend.DetectDominantLanguageCommand({ Text: params.text });
33
- const { Languages } = await this.comprehend.send(command);
34
- if (!Languages.length) throw new Error('Not found');
35
-
36
- return Languages[0].LanguageCode;
37
- }
38
- }
39
-
40
- export interface DetectSentimentParameters {
41
- /**
42
- * The language of the input contents. You can specify any of the primary languages supported by Amazon Comprehend.
43
- * All contents must be in the same language. Required.
44
- * Valid Values: en | es | fr | de | it | pt | ar | hi | ja | ko | zh | zh-TW
45
- */
46
- language: string;
47
- /**
48
- * The text to analyze. Required.
49
- * A UTF-8 text string. Each string must contain fewer that 5,000 bytes of UTF-8 encoded characters.
50
- */
51
- text: string;
52
- }