idea-aws 3.6.2 → 3.7.2
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.
- package/.eslintrc.js +14 -138
- package/dist/index.d.ts +11 -10
- package/dist/index.js +14 -2018
- package/dist/{attachments.d.ts → src/attachments.d.ts} +0 -0
- package/dist/src/attachments.js +45 -0
- package/dist/{cognito.d.ts → src/cognito.d.ts} +16 -11
- package/dist/src/cognito.js +251 -0
- package/dist/{comprehend.d.ts → src/comprehend.d.ts} +0 -0
- package/dist/src/comprehend.js +28 -0
- package/dist/{dynamoDB.d.ts → src/dynamoDB.d.ts} +16 -19
- package/dist/src/dynamoDB.js +308 -0
- package/dist/{genericController.d.ts → src/genericController.d.ts} +0 -0
- package/dist/src/genericController.js +112 -0
- package/dist/{resourceController.d.ts → src/resourceController.d.ts} +8 -4
- package/dist/src/resourceController.js +369 -0
- package/dist/{s3.d.ts → src/s3.d.ts} +1 -1
- package/dist/src/s3.js +144 -0
- package/dist/{ses.d.ts → src/ses.d.ts} +2 -1
- package/dist/src/ses.js +89 -0
- package/dist/{sns.d.ts → src/sns.d.ts} +1 -1
- package/dist/src/sns.js +70 -0
- package/dist/{streamController.d.ts → src/streamController.d.ts} +0 -0
- package/dist/src/streamController.js +16 -0
- package/dist/{translate.d.ts → src/translate.d.ts} +3 -0
- package/dist/src/translate.js +128 -0
- package/index.ts +12 -0
- package/package.json +19 -25
- package/webpack.config.js +0 -18
|
File without changes
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Attachments = void 0;
|
|
4
|
+
const dynamoDB_1 = require("./dynamoDB");
|
|
5
|
+
const s3_1 = require("./s3");
|
|
6
|
+
// declare libs as global vars to be reused in warm starts by the Lambda function
|
|
7
|
+
let ideaWarmStart_ddb = null;
|
|
8
|
+
let ideaWarmStart_s3 = null;
|
|
9
|
+
/**
|
|
10
|
+
* A custom class that takes advantage of DynamoDB and S3 to easily manage attachments.
|
|
11
|
+
*/
|
|
12
|
+
class Attachments {
|
|
13
|
+
constructor() {
|
|
14
|
+
/**
|
|
15
|
+
* The bucket where from to retrieve the attachments. Fallback to IDEA's default one.
|
|
16
|
+
*/
|
|
17
|
+
this.S3_ATTACHMENTS_BUCKET = process.env['S3_ATTACHMENTS_BUCKET'] || 'idea-attachments';
|
|
18
|
+
this.IUID_ATTACHMENTS_PREFIX = process.env['IUID_ATTACHMENTS_PREFIX'] || 'ATT';
|
|
19
|
+
if (!ideaWarmStart_ddb)
|
|
20
|
+
ideaWarmStart_ddb = new dynamoDB_1.DynamoDB();
|
|
21
|
+
this.dynamo = ideaWarmStart_ddb;
|
|
22
|
+
if (!ideaWarmStart_s3)
|
|
23
|
+
ideaWarmStart_s3 = new s3_1.S3();
|
|
24
|
+
this.s3 = ideaWarmStart_s3;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Get a signedURL to put an attachment.
|
|
28
|
+
*/
|
|
29
|
+
async put(project, teamId) {
|
|
30
|
+
const attachmentIdPrefix = this.IUID_ATTACHMENTS_PREFIX.concat('_').concat(project).concat('_').concat(teamId);
|
|
31
|
+
const attachmentId = await this.dynamo.IUNID(attachmentIdPrefix);
|
|
32
|
+
const signedURL = this.s3.signedURLPut(this.S3_ATTACHMENTS_BUCKET, attachmentId);
|
|
33
|
+
signedURL.id = attachmentId;
|
|
34
|
+
return signedURL;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Get a signedURL to retrieve an attachment.
|
|
38
|
+
*/
|
|
39
|
+
get(attachmentId) {
|
|
40
|
+
const signedURL = this.s3.signedURLGet(this.S3_ATTACHMENTS_BUCKET, attachmentId);
|
|
41
|
+
signedURL.id = attachmentId;
|
|
42
|
+
return signedURL;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.Attachments = Attachments;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CognitoIdentityServiceProvider } from 'aws-sdk';
|
|
2
|
-
import {
|
|
2
|
+
import { CognitoUser } from 'idea-toolbox';
|
|
3
3
|
/**
|
|
4
4
|
* A wrapper for AWS Cognito.
|
|
5
5
|
*/
|
|
@@ -15,16 +15,21 @@ export declare class Cognito {
|
|
|
15
15
|
* Get the attributes of the user, from the authorizer claims.
|
|
16
16
|
* @param claims authorizer claims
|
|
17
17
|
* @return user's data
|
|
18
|
+
* @deprecated use IdeaX.CognitoUser instead
|
|
18
19
|
*/
|
|
19
|
-
getUserByClaims(claims: any):
|
|
20
|
+
getUserByClaims(claims: any): CognitoUserGeneric;
|
|
21
|
+
/**
|
|
22
|
+
* Map the complex structure returned by Cognito for a user's attributes in a simple key-value object.
|
|
23
|
+
*/
|
|
24
|
+
private mapCognitoUserAsPlainObject;
|
|
20
25
|
/**
|
|
21
26
|
* Identify a user by its email address, returning its attributes.
|
|
22
27
|
*/
|
|
23
|
-
getUserByEmail(email: string, cognitoUserPoolId: string): Promise<
|
|
28
|
+
getUserByEmail(email: string, cognitoUserPoolId: string): Promise<CognitoUserGeneric>;
|
|
24
29
|
/**
|
|
25
30
|
* Identify a user by its userId (sub), returning its attributes.
|
|
26
31
|
*/
|
|
27
|
-
getUserBySub(sub: string, cognitoUserPoolId: string): Promise<
|
|
32
|
+
getUserBySub(sub: string, cognitoUserPoolId: string): Promise<CognitoUserGeneric>;
|
|
28
33
|
/**
|
|
29
34
|
* Create a new user (by its email) in the pool specified.
|
|
30
35
|
* @return userId of the new user
|
|
@@ -65,24 +70,24 @@ export declare class Cognito {
|
|
|
65
70
|
/**
|
|
66
71
|
* List the groups of the user pool.
|
|
67
72
|
*/
|
|
68
|
-
listGroups(cognitoUserPoolId: string): Promise<
|
|
73
|
+
listGroups(cognitoUserPoolId: string): Promise<CognitoGroup[]>;
|
|
69
74
|
/**
|
|
70
75
|
* List the users part of a group in the user pool.
|
|
71
76
|
*/
|
|
72
|
-
listUsersInGroup(group: string, cognitoUserPoolId: string): Promise<
|
|
77
|
+
listUsersInGroup(group: string, cognitoUserPoolId: string): Promise<CognitoUser[]>;
|
|
73
78
|
/**
|
|
74
79
|
* Add a user (by email) to a group in the user pool.
|
|
75
80
|
*/
|
|
76
|
-
addUserToGroup(email: string, group: string, cognitoUserPoolId: string): Promise<
|
|
81
|
+
addUserToGroup(email: string, group: string, cognitoUserPoolId: string): Promise<void>;
|
|
77
82
|
/**
|
|
78
83
|
* Remove a user (by email) from a group in the user pool.
|
|
79
84
|
*/
|
|
80
|
-
removeUserFromGroup(email: string, group: string, cognitoUserPoolId: string): Promise<
|
|
85
|
+
removeUserFromGroup(email: string, group: string, cognitoUserPoolId: string): Promise<void>;
|
|
81
86
|
}
|
|
82
87
|
/**
|
|
83
|
-
* The attributes of a Cognito user.
|
|
88
|
+
* The attributes of a generic Cognito user of which we don't know the custom attributes.
|
|
84
89
|
*/
|
|
85
|
-
export interface
|
|
90
|
+
export interface CognitoUserGeneric {
|
|
86
91
|
/**
|
|
87
92
|
* The user id (sub).
|
|
88
93
|
*/
|
|
@@ -112,7 +117,7 @@ export interface CreateUserOptions {
|
|
|
112
117
|
/**
|
|
113
118
|
* The attributes of a Cognito group.
|
|
114
119
|
*/
|
|
115
|
-
export interface
|
|
120
|
+
export interface CognitoGroup {
|
|
116
121
|
/**
|
|
117
122
|
* The name (and id) of the group.
|
|
118
123
|
*/
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Cognito = void 0;
|
|
4
|
+
const aws_sdk_1 = require("aws-sdk");
|
|
5
|
+
const idea_toolbox_1 = require("idea-toolbox");
|
|
6
|
+
// declare libs as global vars to be reused in warm starts by the Lambda function
|
|
7
|
+
let ideaWarmStart_cognito = null;
|
|
8
|
+
/**
|
|
9
|
+
* A wrapper for AWS Cognito.
|
|
10
|
+
*/
|
|
11
|
+
class Cognito {
|
|
12
|
+
constructor() {
|
|
13
|
+
if (!ideaWarmStart_cognito)
|
|
14
|
+
ideaWarmStart_cognito = new aws_sdk_1.CognitoIdentityServiceProvider({ apiVersion: '2016-04-18' });
|
|
15
|
+
this.cognito = ideaWarmStart_cognito;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Change the region in which to find the user pool.
|
|
19
|
+
* Default: the runner's (e.g. Lambda function) region.
|
|
20
|
+
*/
|
|
21
|
+
setRegion(region) {
|
|
22
|
+
// there is no quick way to change the region without re-creating the object
|
|
23
|
+
ideaWarmStart_cognito = new aws_sdk_1.CognitoIdentityServiceProvider({ apiVersion: this.cognito.config.apiVersion, region });
|
|
24
|
+
this.cognito = ideaWarmStart_cognito;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Get the attributes of the user, from the authorizer claims.
|
|
28
|
+
* @param claims authorizer claims
|
|
29
|
+
* @return user's data
|
|
30
|
+
* @deprecated use IdeaX.CognitoUser instead
|
|
31
|
+
*/
|
|
32
|
+
getUserByClaims(claims) {
|
|
33
|
+
if (!claims)
|
|
34
|
+
return null;
|
|
35
|
+
const user = {};
|
|
36
|
+
// add any additional cognito attribute available in cognito
|
|
37
|
+
for (const p in claims)
|
|
38
|
+
if (p.startsWith('cognito:'))
|
|
39
|
+
user[p.slice(8)] = claims[p];
|
|
40
|
+
// map the important attributes with reserved names
|
|
41
|
+
user.userId = claims.sub;
|
|
42
|
+
user.email = claims.email;
|
|
43
|
+
return user;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Map the complex structure returned by Cognito for a user's attributes in a simple key-value object.
|
|
47
|
+
*/
|
|
48
|
+
mapCognitoUserAsPlainObject(user) {
|
|
49
|
+
const userAttributes = {};
|
|
50
|
+
user.UserAttributes.forEach((a) => (userAttributes[a.Name] = a.Value));
|
|
51
|
+
return userAttributes;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Identify a user by its email address, returning its attributes.
|
|
55
|
+
*/
|
|
56
|
+
async getUserByEmail(email, cognitoUserPoolId) {
|
|
57
|
+
const user = await this.cognito.adminGetUser({ UserPoolId: cognitoUserPoolId, Username: email }).promise();
|
|
58
|
+
if (!user)
|
|
59
|
+
throw new Error('User not found');
|
|
60
|
+
return this.mapCognitoUserAsPlainObject(user);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Identify a user by its userId (sub), returning its attributes.
|
|
64
|
+
*/
|
|
65
|
+
async getUserBySub(sub, cognitoUserPoolId) {
|
|
66
|
+
// 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
|
|
67
|
+
const usersList = await this.cognito
|
|
68
|
+
.listUsers({ UserPoolId: cognitoUserPoolId, Filter: `sub = "${sub}"`, Limit: 1 })
|
|
69
|
+
.promise();
|
|
70
|
+
const user = usersList?.Users[0];
|
|
71
|
+
if (!user)
|
|
72
|
+
throw new Error('User not found');
|
|
73
|
+
return this.mapCognitoUserAsPlainObject(user);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Create a new user (by its email) in the pool specified.
|
|
77
|
+
* @return userId of the new user
|
|
78
|
+
*/
|
|
79
|
+
async createUser(email, cognitoUserPoolId, options = {}) {
|
|
80
|
+
if ((0, idea_toolbox_1.isEmpty)(email, 'email'))
|
|
81
|
+
throw new Error('INVALID_EMAIL');
|
|
82
|
+
const attributes = [
|
|
83
|
+
{ Name: 'email', Value: email },
|
|
84
|
+
{ Name: 'email_verified', Value: 'true' }
|
|
85
|
+
];
|
|
86
|
+
const params = {
|
|
87
|
+
UserPoolId: cognitoUserPoolId,
|
|
88
|
+
Username: email,
|
|
89
|
+
UserAttributes: attributes
|
|
90
|
+
};
|
|
91
|
+
if (options.skipNotification)
|
|
92
|
+
params.MessageAction = 'SUPPRESS';
|
|
93
|
+
if (options.temporaryPassword)
|
|
94
|
+
params.TemporaryPassword = options.temporaryPassword;
|
|
95
|
+
const result = await this.cognito.adminCreateUser(params).promise();
|
|
96
|
+
const user = this.mapCognitoUserAsPlainObject(result.User);
|
|
97
|
+
const userId = user?.sub;
|
|
98
|
+
if (userId)
|
|
99
|
+
return userId;
|
|
100
|
+
else
|
|
101
|
+
throw new Error('Creation failed');
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Resend the password to a user who never logged in.
|
|
105
|
+
*/
|
|
106
|
+
async resendPassword(email, cognitoUserPoolId, options = {}) {
|
|
107
|
+
if ((0, idea_toolbox_1.isEmpty)(email, 'email'))
|
|
108
|
+
throw new Error('Invalid email');
|
|
109
|
+
const params = {
|
|
110
|
+
UserPoolId: cognitoUserPoolId,
|
|
111
|
+
Username: email,
|
|
112
|
+
MessageAction: 'RESEND'
|
|
113
|
+
};
|
|
114
|
+
if (options.temporaryPassword)
|
|
115
|
+
params.TemporaryPassword = options.temporaryPassword;
|
|
116
|
+
await this.cognito.adminCreateUser(params).promise();
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Delete a user by its email (username), in the pool specified.
|
|
120
|
+
*/
|
|
121
|
+
async deleteUser(email, cognitoUserPoolId) {
|
|
122
|
+
if ((0, idea_toolbox_1.isEmpty)(email, 'email'))
|
|
123
|
+
throw new Error('Invalid email');
|
|
124
|
+
await this.cognito.adminDeleteUser({ UserPoolId: cognitoUserPoolId, Username: email }).promise();
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Sign in a user of a specific pool through username and password.
|
|
128
|
+
*/
|
|
129
|
+
async signIn(email, password, cognitoUserPoolId, cognitoUserPoolClientId) {
|
|
130
|
+
const result = await this.cognito
|
|
131
|
+
.adminInitiateAuth({
|
|
132
|
+
UserPoolId: cognitoUserPoolId,
|
|
133
|
+
ClientId: cognitoUserPoolClientId,
|
|
134
|
+
AuthFlow: 'ADMIN_NO_SRP_AUTH',
|
|
135
|
+
AuthParameters: { USERNAME: email, PASSWORD: password }
|
|
136
|
+
})
|
|
137
|
+
.promise();
|
|
138
|
+
if (result?.AuthenticationResult)
|
|
139
|
+
return result.AuthenticationResult;
|
|
140
|
+
else
|
|
141
|
+
throw new Error('Sign-in failed');
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Given a username and a refresh token (and pool data), refresh the session and return the new tokens.
|
|
145
|
+
*/
|
|
146
|
+
async refreshSession(email, refreshToken, cognitoUserPoolId, cognitoUserPoolClientId) {
|
|
147
|
+
const result = await this.cognito
|
|
148
|
+
.adminInitiateAuth({
|
|
149
|
+
UserPoolId: cognitoUserPoolId,
|
|
150
|
+
ClientId: cognitoUserPoolClientId,
|
|
151
|
+
AuthFlow: 'REFRESH_TOKEN_AUTH',
|
|
152
|
+
AuthParameters: { USERNAME: email, REFRESH_TOKEN: refreshToken }
|
|
153
|
+
})
|
|
154
|
+
.promise();
|
|
155
|
+
if (result?.AuthenticationResult)
|
|
156
|
+
return result.AuthenticationResult;
|
|
157
|
+
else
|
|
158
|
+
throw new Error('Refresh failed');
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Change the email address (== username) associated to a user.
|
|
162
|
+
*/
|
|
163
|
+
async updateEmail(email, newEmail, cognitoUserPoolId) {
|
|
164
|
+
if ((0, idea_toolbox_1.isEmpty)(newEmail, 'email'))
|
|
165
|
+
throw new Error('Invalid new email');
|
|
166
|
+
await this.cognito
|
|
167
|
+
.adminUpdateUserAttributes({
|
|
168
|
+
UserPoolId: cognitoUserPoolId,
|
|
169
|
+
Username: email,
|
|
170
|
+
UserAttributes: [
|
|
171
|
+
{ Name: 'email', Value: newEmail },
|
|
172
|
+
{ Name: 'email_verified', Value: 'true' }
|
|
173
|
+
]
|
|
174
|
+
})
|
|
175
|
+
.promise();
|
|
176
|
+
// sign out the user from all its devices and resolve
|
|
177
|
+
await this.globalSignOut(newEmail, cognitoUserPoolId);
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Change the password to sign in for a user.
|
|
181
|
+
*/
|
|
182
|
+
async updatePassword(email, oldPassword, newPassword, cognitoUserPoolId, cognitoUserPoolClientId) {
|
|
183
|
+
if (newPassword.length < 8)
|
|
184
|
+
throw new Error('Invalid new password');
|
|
185
|
+
const tokensForPasswordChange = await this.signIn(email, oldPassword, cognitoUserPoolId, cognitoUserPoolClientId);
|
|
186
|
+
await this.cognito
|
|
187
|
+
.changePassword({
|
|
188
|
+
AccessToken: tokensForPasswordChange.AccessToken,
|
|
189
|
+
PreviousPassword: oldPassword,
|
|
190
|
+
ProposedPassword: newPassword
|
|
191
|
+
})
|
|
192
|
+
.promise();
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Sign out the user from all devices.
|
|
196
|
+
*/
|
|
197
|
+
async globalSignOut(email, cognitoUserPoolId) {
|
|
198
|
+
await this.cognito.adminUserGlobalSignOut({ Username: email, UserPoolId: cognitoUserPoolId }).promise();
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Confirm and conclude a registration, usign a confirmation code.
|
|
202
|
+
*/
|
|
203
|
+
async confirmSignUp(email, confirmationCode, cognitoUserPoolClientId) {
|
|
204
|
+
if (!email)
|
|
205
|
+
throw new Error('Invalid email');
|
|
206
|
+
if (!confirmationCode)
|
|
207
|
+
throw new Error('Invalid confirmation code');
|
|
208
|
+
if (!cognitoUserPoolClientId)
|
|
209
|
+
throw new Error('Invalid client ID');
|
|
210
|
+
await this.cognito
|
|
211
|
+
.confirmSignUp({ Username: email, ConfirmationCode: confirmationCode, ClientId: cognitoUserPoolClientId })
|
|
212
|
+
.promise();
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* List the groups of the user pool.
|
|
216
|
+
*/
|
|
217
|
+
async listGroups(cognitoUserPoolId) {
|
|
218
|
+
const groupsList = await this.cognito.listGroups({ UserPoolId: cognitoUserPoolId }).promise();
|
|
219
|
+
const groups = groupsList.Groups.map(g => ({ name: g.GroupName, description: g.Description }));
|
|
220
|
+
return groups;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* List the users part of a group in the user pool.
|
|
224
|
+
*/
|
|
225
|
+
async listUsersInGroup(group, cognitoUserPoolId) {
|
|
226
|
+
const usersInGroupList = await this.cognito
|
|
227
|
+
.listUsersInGroup({ UserPoolId: cognitoUserPoolId, GroupName: group })
|
|
228
|
+
.promise();
|
|
229
|
+
const users = usersInGroupList.Users.map(u => new idea_toolbox_1.CognitoUser(this.mapCognitoUserAsPlainObject(u)));
|
|
230
|
+
return users;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Add a user (by email) to a group in the user pool.
|
|
234
|
+
*/
|
|
235
|
+
async addUserToGroup(email, group, cognitoUserPoolId) {
|
|
236
|
+
const user = new idea_toolbox_1.CognitoUser(await this.getUserByEmail(email, cognitoUserPoolId));
|
|
237
|
+
await this.cognito
|
|
238
|
+
.adminAddUserToGroup({ UserPoolId: cognitoUserPoolId, GroupName: group, Username: user.userId })
|
|
239
|
+
.promise();
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Remove a user (by email) from a group in the user pool.
|
|
243
|
+
*/
|
|
244
|
+
async removeUserFromGroup(email, group, cognitoUserPoolId) {
|
|
245
|
+
const user = new idea_toolbox_1.CognitoUser(await this.getUserByEmail(email, cognitoUserPoolId));
|
|
246
|
+
await this.cognito
|
|
247
|
+
.adminRemoveUserFromGroup({ UserPoolId: cognitoUserPoolId, GroupName: group, Username: user.userId })
|
|
248
|
+
.promise();
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
exports.Cognito = Cognito;
|
|
File without changes
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Comprehend = void 0;
|
|
4
|
+
const aws_sdk_1 = require("aws-sdk");
|
|
5
|
+
// declare libs as global vars to be reused in warm starts by the Lambda function
|
|
6
|
+
let ideaWarmStart_comprehend = null;
|
|
7
|
+
/**
|
|
8
|
+
* A wrapper for Amazon Comprehend.
|
|
9
|
+
*/
|
|
10
|
+
class Comprehend {
|
|
11
|
+
constructor() {
|
|
12
|
+
if (!ideaWarmStart_comprehend)
|
|
13
|
+
ideaWarmStart_comprehend = new aws_sdk_1.Comprehend({ apiVersion: '2017-11-27' });
|
|
14
|
+
this.comprehend = ideaWarmStart_comprehend;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Inspects text and returns an inference of the prevailing sentiment (POSITIVE, NEUTRAL, MIXED, or NEGATIVE).
|
|
18
|
+
*/
|
|
19
|
+
async detectSentiment(params) {
|
|
20
|
+
if (!params.language || !params.text)
|
|
21
|
+
throw new Error('Missing some parameters');
|
|
22
|
+
const result = await this.comprehend
|
|
23
|
+
.detectSentiment({ LanguageCode: params.language, Text: params.text })
|
|
24
|
+
.promise();
|
|
25
|
+
return result.Sentiment;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.Comprehend = Comprehend;
|
|
@@ -4,9 +4,6 @@ import { DynamoDB as DDB } from 'aws-sdk';
|
|
|
4
4
|
*/
|
|
5
5
|
export declare class DynamoDB {
|
|
6
6
|
protected dynamo: DDB.DocumentClient;
|
|
7
|
-
/**
|
|
8
|
-
* Initialize a new DynamoDB helper object.
|
|
9
|
-
*/
|
|
10
7
|
constructor();
|
|
11
8
|
/**
|
|
12
9
|
* Convert a JSON object from dynamoDB format to simple JSON.
|
|
@@ -23,7 +20,6 @@ export declare class DynamoDB {
|
|
|
23
20
|
* @return the IUID
|
|
24
21
|
*/
|
|
25
22
|
IUID(project: string): Promise<string>;
|
|
26
|
-
protected iuidHelper(project: string, attempt: number, maxAttempts: number, resolve: any, reject: any): void;
|
|
27
23
|
/**
|
|
28
24
|
* Returns an IUNID: IDEA's Unique Nano IDentifier, which is an id unique through all IDEA's projects.
|
|
29
25
|
* Note: no need of an auth check for external uses: the permissions depend from the context in which it's executed.
|
|
@@ -31,7 +27,6 @@ export declare class DynamoDB {
|
|
|
31
27
|
* @return the IUNID
|
|
32
28
|
*/
|
|
33
29
|
IUNID(project: string): Promise<string>;
|
|
34
|
-
protected iunidHelper(project: string, attempt: number, maxAttempts: number, resolve: any, reject: any): void;
|
|
35
30
|
/**
|
|
36
31
|
* Returns an ISID: IDEA's Short IDentifier, which is a short, unique id through a single project.
|
|
37
32
|
* Note: there's no need of an authorization check for extrernal uses: the permissions depend
|
|
@@ -40,7 +35,7 @@ export declare class DynamoDB {
|
|
|
40
35
|
* @return the ISID
|
|
41
36
|
*/
|
|
42
37
|
ISID(project: string): Promise<string>;
|
|
43
|
-
protected
|
|
38
|
+
protected identifiersGeneratorHelper(project: string, type: 'IUNID' | 'IUID' | 'ISID', attempt: number, maxAttempts: number): Promise<string>;
|
|
44
39
|
/**
|
|
45
40
|
* Manage atomic counters (atomic autoincrement values) in IDEA's projects.
|
|
46
41
|
* They key of an atomic counter should be composed as the following: `DynamoDBTableName_uniqueKey`.
|
|
@@ -67,41 +62,43 @@ export declare class DynamoDB {
|
|
|
67
62
|
* Get group of items based on their keys from DynamoDb table, avoiding the limits of DynamoDB's BatchGetItem.
|
|
68
63
|
* @param ignoreErr if set, ignore the errors and continue the bulk op.
|
|
69
64
|
*/
|
|
70
|
-
batchGet(table: string, keys: DDB.DocumentClient.Key[], ignoreErr?: boolean): Promise<
|
|
71
|
-
protected batchGetHelper(
|
|
65
|
+
batchGet(table: string, keys: DDB.DocumentClient.Key[], ignoreErr?: boolean): Promise<DDB.DocumentClient.AttributeMap[]>;
|
|
66
|
+
protected batchGetHelper(table: string, keys: DDB.DocumentClient.Key[], resultElements: DDB.DocumentClient.AttributeMap[], ignoreErr: boolean, currentChunk?: number, chunkSize?: number): Promise<DDB.DocumentClient.AttributeMap[]>;
|
|
72
67
|
/**
|
|
73
68
|
* Put an array of items in a DynamoDb table, avoiding the limits of DynamoDB's BatchWriteItem.
|
|
74
|
-
*
|
|
69
|
+
* In case of errors, it will retry with a random back-off mechanism until the timeout.
|
|
70
|
+
* Therefore, in case of timeout, there may be some elements written and some not.
|
|
75
71
|
*/
|
|
76
|
-
batchPut(table: string, items: DDB.DocumentClient.AttributeMap[]
|
|
72
|
+
batchPut(table: string, items: DDB.DocumentClient.AttributeMap[]): Promise<void>;
|
|
77
73
|
/**
|
|
78
74
|
* Delete an array of items from a DynamoDb table, avoiding the limits of DynamoDB's BatchWriteItem.
|
|
79
|
-
*
|
|
75
|
+
* In case of errors, it will retry with a random back-off mechanism until the timeout.
|
|
76
|
+
* Therefore, in case of timeout, there may be some elements deleted and some not.
|
|
80
77
|
*/
|
|
81
|
-
batchDelete(table: string, keys: DDB.DocumentClient.Key[]
|
|
82
|
-
protected batchWriteHelper(
|
|
78
|
+
batchDelete(table: string, keys: DDB.DocumentClient.Key[]): Promise<void>;
|
|
79
|
+
protected batchWriteHelper(table: string, itemsOrKeys: DDB.DocumentClient.AttributeMap[] | DDB.DocumentClient.Key[], isPut: boolean, currentChunk?: number, chunkSize?: number): Promise<void>;
|
|
80
|
+
protected batchWriteChunkWithRetries(table: string, params: DDB.DocumentClient.BatchWriteItemInput): Promise<void>;
|
|
83
81
|
/**
|
|
84
82
|
* Query a DynamoDb table, avoiding the limits of DynamoDB's Query.
|
|
85
83
|
* @param params the params to apply to DynamoDB's function
|
|
86
84
|
*/
|
|
87
|
-
query(params: DDB.DocumentClient.QueryInput): Promise<
|
|
85
|
+
query(params: DDB.DocumentClient.QueryInput): Promise<DDB.DocumentClient.AttributeMap[]>;
|
|
88
86
|
/**
|
|
89
87
|
* Scan a DynamoDb table, avoiding the limits of DynamoDB's Query.
|
|
90
88
|
* @param params the params to apply to DynamoDB's function
|
|
91
89
|
*/
|
|
92
|
-
scan(params: DDB.DocumentClient.
|
|
93
|
-
protected queryScanHelper(params: DDB.DocumentClient.QueryInput | DDB.DocumentClient.ScanInput, items: DDB.DocumentClient.AttributeMap[], isQuery: boolean
|
|
90
|
+
scan(params: DDB.DocumentClient.QueryInput): Promise<DDB.DocumentClient.AttributeMap[]>;
|
|
91
|
+
protected queryScanHelper(params: DDB.DocumentClient.QueryInput | DDB.DocumentClient.ScanInput, items: DDB.DocumentClient.AttributeMap[], isQuery: boolean): Promise<DDB.DocumentClient.AttributeMap[]>;
|
|
94
92
|
/**
|
|
95
93
|
* Query a DynamoDb table in the traditional way (no pagination or data mapping).
|
|
96
94
|
* @param params the params to apply to DynamoDB's function
|
|
97
95
|
*/
|
|
98
|
-
queryClassic(params: DDB.DocumentClient.QueryInput): Promise<DDB.DocumentClient.QueryOutput
|
|
96
|
+
queryClassic(params: DDB.DocumentClient.QueryInput): Promise<DDB.DocumentClient.QueryOutput>;
|
|
99
97
|
/**
|
|
100
98
|
* Scan a DynamoDb table in the traditional way (no pagination or data mapping).
|
|
101
99
|
* @param params the params to apply to DynamoDB's function
|
|
102
100
|
*/
|
|
103
|
-
scanClassic(params: DDB.DocumentClient.ScanInput): Promise<DDB.DocumentClient.ScanOutput
|
|
104
|
-
protected queryScanClassicHelper(params: DDB.DocumentClient.QueryInput | DDB.DocumentClient.ScanInput, isQuery: boolean, resolve: any, reject: any): void;
|
|
101
|
+
scanClassic(params: DDB.DocumentClient.ScanInput): Promise<DDB.DocumentClient.ScanOutput>;
|
|
105
102
|
/**
|
|
106
103
|
* Execute a series of max 10 write operations in a single transaction.
|
|
107
104
|
* @param ops the operations to execute in the transaction
|