Comparing version 2.5.0 to 2.6.0
@@ -1,1 +0,1 @@ | ||
# Contributing | ||
# Contributing |
@@ -42,4 +42,3 @@ "use strict"; | ||
// find the user by the email | ||
new AWS.CognitoIdentityServiceProvider({ apiVersion: '2016-04-18' }) | ||
.listUsers({ UserPoolId: cognitoUserPoolId, Filter: `email = "${email}"`, Limit: 1 }, (err, data) => { | ||
new AWS.CognitoIdentityServiceProvider({ apiVersion: '2016-04-18' }).listUsers({ UserPoolId: cognitoUserPoolId, Filter: `email = "${email}"`, Limit: 1 }, (err, data) => { | ||
if (err || !data || !data.Users || !data.Users[0]) | ||
@@ -50,3 +49,3 @@ reject(); | ||
const userAttributes = {}; | ||
data.Users[0].Attributes.forEach((a) => userAttributes[a.Name] = a.Value); | ||
data.Users[0].Attributes.forEach((a) => (userAttributes[a.Name] = a.Value)); | ||
resolve(userAttributes); | ||
@@ -66,4 +65,3 @@ } | ||
// find the user by the sub | ||
new AWS.CognitoIdentityServiceProvider({ apiVersion: '2016-04-18' }) | ||
.listUsers({ UserPoolId: cognitoUserPoolId, Filter: `sub = "${sub}"`, Limit: 1 }, (err, data) => { | ||
new AWS.CognitoIdentityServiceProvider({ apiVersion: '2016-04-18' }).listUsers({ UserPoolId: cognitoUserPoolId, Filter: `sub = "${sub}"`, Limit: 1 }, (err, data) => { | ||
if (err || !data || !data.Users || !data.Users[0]) | ||
@@ -74,3 +72,3 @@ reject(); | ||
const userAttributes = {}; | ||
data.Users[0].Attributes.forEach((a) => userAttributes[a.Name] = a.Value); | ||
data.Users[0].Attributes.forEach((a) => (userAttributes[a.Name] = a.Value)); | ||
resolve(userAttributes); | ||
@@ -101,3 +99,5 @@ } | ||
const params = { | ||
UserPoolId: cognitoUserPoolId, Username: email, UserAttributes: attributes | ||
UserPoolId: cognitoUserPoolId, | ||
Username: email, | ||
UserAttributes: attributes | ||
}; | ||
@@ -116,3 +116,4 @@ if (options.skipNotification) | ||
return reject(new Error(`E.COGNITO.INVALID_PASSWORD`)); | ||
default: return reject(err); | ||
default: | ||
return reject(err); | ||
} | ||
@@ -145,3 +146,5 @@ const userId = data.User.Attributes.find((attr) => attr.Name === 'sub').Value || null; | ||
const params = { | ||
UserPoolId: cognitoUserPoolId, Username: email, MessageAction: 'RESEND' | ||
UserPoolId: cognitoUserPoolId, | ||
Username: email, | ||
MessageAction: 'RESEND' | ||
}; | ||
@@ -156,3 +159,4 @@ if (options.temporaryPassword) | ||
return reject(new Error(`E.COGNITO.USER_ALREADY_CONFIRMED_PASSWORD`)); | ||
default: return reject(err); | ||
default: | ||
return reject(err); | ||
} | ||
@@ -174,4 +178,3 @@ else | ||
return reject(new Error(`E.COGNITO.INVALID_EMAIL`)); | ||
new AWS.CognitoIdentityServiceProvider() | ||
.adminDeleteUser({ UserPoolId: cognitoUserPoolId, Username: email }, (err) => { | ||
new AWS.CognitoIdentityServiceProvider().adminDeleteUser({ UserPoolId: cognitoUserPoolId, Username: email }, (err) => { | ||
IdeaX.logger('COGNITO DELETE USER', err, `${email} (${cognitoUserPoolId})`); | ||
@@ -196,8 +199,7 @@ if (err) | ||
return new Promise((resolve, reject) => { | ||
new AWS.CognitoIdentityServiceProvider({ apiVersion: '2016-04-18' }) | ||
.adminInitiateAuth({ | ||
new AWS.CognitoIdentityServiceProvider({ apiVersion: '2016-04-18' }).adminInitiateAuth({ | ||
UserPoolId: cognitoUserPoolId, | ||
ClientId: cognitoUserPoolClientId, | ||
AuthFlow: 'ADMIN_NO_SRP_AUTH', | ||
AuthParameters: { 'USERNAME': email, 'PASSWORD': password } | ||
AuthParameters: { USERNAME: email, PASSWORD: password } | ||
}, (err, data) => { | ||
@@ -223,10 +225,6 @@ IdeaX.logger('COGNITO SIGN IN', err, data ? JSON.stringify(data.toString) : null); | ||
return reject(new Error('E.COGNITO.INVALID_NEW_EMAIL')); | ||
new AWS.CognitoIdentityServiceProvider({ apiVersion: '2016-04-18' }) | ||
.adminUpdateUserAttributes({ | ||
new AWS.CognitoIdentityServiceProvider({ apiVersion: '2016-04-18' }).adminUpdateUserAttributes({ | ||
UserPoolId: cognitoUserPoolId, | ||
Username: email, | ||
UserAttributes: [ | ||
{ Name: 'email', Value: newEmail }, | ||
{ Name: 'email_verified', Value: 'true' } | ||
] | ||
UserAttributes: [{ Name: 'email', Value: newEmail }, { Name: 'email_verified', Value: 'true' }] | ||
}, (err, _) => { | ||
@@ -262,4 +260,3 @@ IdeaX.logger('COGNITO UPDATE EMAIL', err, newEmail); | ||
// request the password change | ||
new AWS.CognitoIdentityServiceProvider({ apiVersion: '2016-04-18' }) | ||
.changePassword({ | ||
new AWS.CognitoIdentityServiceProvider({ apiVersion: '2016-04-18' }).changePassword({ | ||
AccessToken: data.AccessToken, | ||
@@ -276,3 +273,3 @@ PreviousPassword: oldPassword, | ||
}) | ||
.catch((err) => reject(err)); | ||
.catch(err => reject(err)); | ||
}); | ||
@@ -288,4 +285,3 @@ } | ||
return new Promise((resolve, reject) => { | ||
new AWS.CognitoIdentityServiceProvider({ apiVersion: '2016-04-18' }) | ||
.adminUserGlobalSignOut({ | ||
new AWS.CognitoIdentityServiceProvider({ apiVersion: '2016-04-18' }).adminUserGlobalSignOut({ | ||
Username: email, | ||
@@ -319,4 +315,3 @@ UserPoolId: cognitoUserPoolId | ||
// conclude the registration (sign-up) flow, using a provided confirmation code | ||
new AWS.CognitoIdentityServiceProvider({ apiVersion: '2016-04-18' }) | ||
.confirmSignUp({ Username: email, ConfirmationCode: confirmationCode, ClientId: cognitoUserPoolClientId }, (err, _) => { | ||
new AWS.CognitoIdentityServiceProvider({ apiVersion: '2016-04-18' }).confirmSignUp({ Username: email, ConfirmationCode: confirmationCode, ClientId: cognitoUserPoolClientId }, (err, _) => { | ||
IdeaX.logger('COGNITO CONFIRM SIGN UP', err, `${email} ${confirmationCode}`); | ||
@@ -323,0 +318,0 @@ if (err) |
@@ -42,3 +42,4 @@ "use strict"; | ||
this.put({ | ||
TableName: 'idea_IUID', Item: { project: project, id: id }, | ||
TableName: 'idea_IUID', | ||
Item: { project: project, id: id }, | ||
ConditionExpression: 'NOT (#p = :project AND #id = :id)', | ||
@@ -49,4 +50,5 @@ ExpressionAttributeNames: { '#p': 'project', '#id': 'id' }, | ||
.then(() => resolve(`${project}_${id}`)) | ||
.catch(() => // ID exists, try again | ||
this.iuidHelper(project, attempt + 1, maxAttempts, resolve, reject)); | ||
.catch(() => | ||
// ID exists, try again | ||
this.iuidHelper(project, attempt + 1, maxAttempts, resolve, reject)); | ||
} | ||
@@ -79,3 +81,4 @@ } | ||
this.put({ | ||
TableName: 'idea_ISID', Item: { project: project, id: id }, | ||
TableName: 'idea_ISID', | ||
Item: { project: project, id: id }, | ||
ConditionExpression: 'NOT (#p = :project AND #id = :id)', | ||
@@ -86,4 +89,5 @@ ExpressionAttributeNames: { '#p': 'project', '#id': 'id' }, | ||
.then(() => resolve(id)) | ||
.catch(() => // ID exists, try again | ||
this.isidHelper(project, attempt + 1, maxAttempts, resolve, reject)); | ||
.catch(() => | ||
// ID exists, try again | ||
this.isidHelper(project, attempt + 1, maxAttempts, resolve, reject)); | ||
} | ||
@@ -101,3 +105,4 @@ } | ||
this.update({ | ||
TableName: 'idea_atomicCounters', Key: { key: key }, | ||
TableName: 'idea_atomicCounters', | ||
Key: { key: key }, | ||
UpdateExpression: 'ADD atomicCounter :increment', | ||
@@ -119,4 +124,3 @@ ExpressionAttributeValues: { ':increment': 1 }, | ||
this.dynamo.get(params, (err, data) => { | ||
IdeaX.logger(`GET ${params.IndexName | ||
? `${params.TableName} (${params.IndexName})` : params.TableName}`, err, data); | ||
IdeaX.logger(`GET ${params.IndexName ? `${params.TableName} (${params.IndexName})` : params.TableName}`, err, data); | ||
if (err || !data.Item) | ||
@@ -260,12 +264,9 @@ reject(err); | ||
if (isPut) { | ||
batch.RequestItems[t] = items | ||
.slice(curr, curr + size) | ||
.map(i => { | ||
batch.RequestItems[t] = items.slice(curr, curr + size).map(i => { | ||
return { PutRequest: { Item: i } }; | ||
}); | ||
} | ||
else { // isDelete | ||
batch.RequestItems[t] = items | ||
.slice(curr, curr + size) | ||
.map(k => { | ||
else { | ||
// isDelete | ||
batch.RequestItems[t] = items.slice(curr, curr + size).map(k => { | ||
return { DeleteRequest: { Key: k } }; | ||
@@ -272,0 +273,0 @@ }); |
@@ -84,5 +84,3 @@ "use strict"; | ||
IdeaX.logger('REQUEST', null, this.httpMethod, true); | ||
request | ||
.then((res) => this.done(null, res)) | ||
.catch((err) => this.done(err)); | ||
request.then((res) => this.done(null, res)).catch((err) => this.done(err)); | ||
} | ||
@@ -100,4 +98,6 @@ }) | ||
this.resource = (event.resource || '').replace('+', ''); // {proxy+} -> {proxy} | ||
this.resourceId = event.pathParameters && event.pathParameters[options.resourceId || 'proxy'] | ||
? decodeURIComponent(event.pathParameters[options.resourceId || 'proxy']) : ''; | ||
this.resourceId = | ||
event.pathParameters && event.pathParameters[options.resourceId || 'proxy'] | ||
? decodeURIComponent(event.pathParameters[options.resourceId || 'proxy']) | ||
: ''; | ||
this.queryParams = event.queryStringParameters || {}; | ||
@@ -134,3 +134,3 @@ this.body = JSON.parse(event.body) || {}; | ||
getResource() { | ||
return new Promise((resolve, reject) => reject(new Error(`E.COMMON.UNSUPPORTED_ACTION`))); | ||
return new Promise((_, reject) => reject(new Error(`E.COMMON.UNSUPPORTED_ACTION`))); | ||
} | ||
@@ -141,3 +141,3 @@ /** | ||
postResource() { | ||
return new Promise((resolve, reject) => reject(new Error(`E.COMMON.UNSUPPORTED_ACTION`))); | ||
return new Promise((_, reject) => reject(new Error(`E.COMMON.UNSUPPORTED_ACTION`))); | ||
} | ||
@@ -148,3 +148,3 @@ /** | ||
putResource() { | ||
return new Promise((resolve, reject) => reject(new Error(`E.COMMON.UNSUPPORTED_ACTION`))); | ||
return new Promise((_, reject) => reject(new Error(`E.COMMON.UNSUPPORTED_ACTION`))); | ||
} | ||
@@ -155,3 +155,3 @@ /** | ||
deleteResource() { | ||
return new Promise((resolve, reject) => reject(new Error(`E.COMMON.UNSUPPORTED_ACTION`))); | ||
return new Promise((_, reject) => reject(new Error(`E.COMMON.UNSUPPORTED_ACTION`))); | ||
} | ||
@@ -162,3 +162,3 @@ /** | ||
headResource() { | ||
return new Promise((resolve, reject) => reject(new Error(`E.COMMON.UNSUPPORTED_ACTION`))); | ||
return new Promise((_, reject) => reject(new Error(`E.COMMON.UNSUPPORTED_ACTION`))); | ||
} | ||
@@ -169,3 +169,3 @@ /** | ||
getResources() { | ||
return new Promise((resolve, reject) => reject(new Error(`E.COMMON.UNSUPPORTED_ACTION`))); | ||
return new Promise((_, reject) => reject(new Error(`E.COMMON.UNSUPPORTED_ACTION`))); | ||
} | ||
@@ -176,3 +176,3 @@ /** | ||
postResources() { | ||
return new Promise((resolve, reject) => reject(new Error(`E.COMMON.UNSUPPORTED_ACTION`))); | ||
return new Promise((_, reject) => reject(new Error(`E.COMMON.UNSUPPORTED_ACTION`))); | ||
} | ||
@@ -183,3 +183,3 @@ /** | ||
putResources() { | ||
return new Promise((resolve, reject) => reject(new Error(`E.COMMON.UNSUPPORTED_ACTION`))); | ||
return new Promise((_, reject) => reject(new Error(`E.COMMON.UNSUPPORTED_ACTION`))); | ||
} | ||
@@ -190,3 +190,3 @@ /** | ||
patchResource() { | ||
return new Promise((resolve, reject) => reject(new Error(`E.COMMON.UNSUPPORTED_ACTION`))); | ||
return new Promise((_, reject) => reject(new Error(`E.COMMON.UNSUPPORTED_ACTION`))); | ||
} | ||
@@ -197,3 +197,3 @@ /** | ||
patchResources() { | ||
return new Promise((resolve, reject) => reject(new Error(`E.COMMON.UNSUPPORTED_ACTION`))); | ||
return new Promise((_, reject) => reject(new Error(`E.COMMON.UNSUPPORTED_ACTION`))); | ||
} | ||
@@ -204,3 +204,3 @@ /** | ||
deleteResources() { | ||
return new Promise((resolve, reject) => reject(new Error(`E.COMMON.UNSUPPORTED_ACTION`))); | ||
return new Promise((_, reject) => reject(new Error(`E.COMMON.UNSUPPORTED_ACTION`))); | ||
} | ||
@@ -211,3 +211,3 @@ /** | ||
headResources() { | ||
return new Promise((resolve, reject) => reject(new Error(`E.COMMON.UNSUPPORTED_ACTION`))); | ||
return new Promise((_, reject) => reject(new Error(`E.COMMON.UNSUPPORTED_ACTION`))); | ||
} | ||
@@ -270,3 +270,6 @@ /// | ||
// insert the log and don't wait for response or errors | ||
this.dynamoDB.put({ TableName: this.tables.requestsLogs, Item: { | ||
this.dynamoDB | ||
.put({ | ||
TableName: this.tables.requestsLogs, | ||
Item: { | ||
key: key, | ||
@@ -281,3 +284,4 @@ at: String(new Date().getTime()).concat('_'.concat(UUIDV4())), | ||
requestSucceeded: success | ||
} }) | ||
} | ||
}) | ||
.then(() => { }) | ||
@@ -284,0 +288,0 @@ .catch(() => { }); |
@@ -0,1 +1,2 @@ | ||
import AWS = require('aws-sdk'); | ||
/** | ||
@@ -5,3 +6,3 @@ * A wrapper for AWS Simple Storage Service. | ||
export declare class S3 { | ||
protected s3: any; | ||
protected s3: AWS.S3; | ||
protected DEFAULT_DOWNLOAD_BUCKET_PREFIX: string; | ||
@@ -58,3 +59,3 @@ protected DEFAULT_DOWNLOAD_BUCKET: string; | ||
/** | ||
* Get an object from an S3 bucket. | ||
* Get an object from a S3 bucket. | ||
* @param {any} options strucuted as follows | ||
@@ -69,2 +70,16 @@ ``` | ||
getObject(options?: any): Promise<any>; | ||
/** | ||
* Put an object in a S3 bucket. | ||
* @param {any} options strucuted as follows | ||
``` | ||
bucket: string; // the bucket in which to copy the file. | ||
key; string; // the complete filepath of the bucket in which to copy the file | ||
body: any; // the content of the file | ||
contentType?: string; // content type (e.g. image/png) | ||
acl?: string; // access-control list (e.g. public-read) | ||
metadata?: any; // a set of metadata as attributes | ||
``` | ||
* @return {Promise<any>} | ||
*/ | ||
putObject(options?: any): Promise<any>; | ||
} | ||
@@ -71,0 +86,0 @@ /** |
@@ -37,3 +37,8 @@ "use strict"; | ||
if (!options.key) | ||
options.key = new Date().getTime().toString().concat(Math.random().toString(36).slice(2)); | ||
options.key = new Date() | ||
.getTime() | ||
.toString() | ||
.concat(Math.random() | ||
.toString(36) | ||
.slice(2)); | ||
// add the prefix to the key | ||
@@ -46,3 +51,6 @@ options.key = `${options.prefix || this.DEFAULT_DOWNLOAD_BUCKET_PREFIX}/${options.key}`; | ||
this.s3.upload({ | ||
Bucket: options.bucket, Key: options.key, Body: data, ContentType: options.contentType | ||
Bucket: options.bucket, | ||
Key: options.key, | ||
Body: data, | ||
ContentType: options.contentType | ||
}, (err, d) => { | ||
@@ -67,3 +75,5 @@ IdeaX.logger('S3 UPLOAD', err, d); | ||
url: this.s3.getSignedUrl('putObject', { | ||
Bucket: bucket, Key: key, Expires: expires || this.DEFAULT_UPLOAD_BUCKET_SEC_TO_EXP | ||
Bucket: bucket, | ||
Key: key, | ||
Expires: expires || this.DEFAULT_UPLOAD_BUCKET_SEC_TO_EXP | ||
}) | ||
@@ -82,3 +92,5 @@ }; | ||
url: this.s3.getSignedUrl('getObject', { | ||
Bucket: bucket, Key: key, Expires: expires || this.DEFAULT_DOWNLOAD_BUCKET_SEC_TO_EXP | ||
Bucket: bucket, | ||
Key: key, | ||
Expires: expires || this.DEFAULT_DOWNLOAD_BUCKET_SEC_TO_EXP | ||
}) | ||
@@ -109,3 +121,3 @@ }; | ||
/** | ||
* Get an object from an S3 bucket. | ||
* Get an object from a S3 bucket. | ||
* @param {any} options strucuted as follows | ||
@@ -130,3 +142,4 @@ ``` | ||
break; | ||
default: resolve(d); | ||
default: | ||
resolve(d); | ||
} | ||
@@ -136,3 +149,34 @@ }); | ||
} | ||
/** | ||
* Put an object in a S3 bucket. | ||
* @param {any} options strucuted as follows | ||
``` | ||
bucket: string; // the bucket in which to copy the file. | ||
key; string; // the complete filepath of the bucket in which to copy the file | ||
body: any; // the content of the file | ||
contentType?: string; // content type (e.g. image/png) | ||
acl?: string; // access-control list (e.g. public-read) | ||
metadata?: any; // a set of metadata as attributes | ||
``` | ||
* @return {Promise<any>} | ||
*/ | ||
putObject(options) { | ||
return new Promise((resolve, reject) => { | ||
const params = { Bucket: options.bucket, Key: options.key, Body: options.body }; | ||
if (options.contentType) | ||
params.ContentType = options.contentType; | ||
if (options.acl) | ||
params.ACL = options.acl; | ||
if (options.metadata) | ||
params.Metadata = options.metadata; | ||
this.s3.putObject(params, (err, d) => { | ||
IdeaX.logger('S3 PUT OBJECT', err, d); | ||
if (err) | ||
reject(err); | ||
else | ||
resolve(d); | ||
}); | ||
}); | ||
} | ||
} | ||
exports.S3 = S3; |
@@ -72,4 +72,3 @@ "use strict"; | ||
// send email | ||
new AWS.SES({ region: sesParams.region }) | ||
.sendEmail(sesData, (err, data) => { | ||
new AWS.SES({ region: sesParams.region }).sendEmail(sesData, (err, data) => { | ||
IdeaX.logger('SES SEND EMAIL', err, JSON.stringify(data)); | ||
@@ -106,5 +105,3 @@ if (err) | ||
// create Nodemailer SES transporter and send the email | ||
Nodemailer | ||
.createTransport({ SES: new AWS.SES({ region: sesParams.region }) }) | ||
.sendMail(mailOptions, (err, data) => { | ||
Nodemailer.createTransport({ SES: new AWS.SES({ region: sesParams.region }) }).sendMail(mailOptions, (err, data) => { | ||
IdeaX.logger('SES SEND EMAIL (NODEMAILER)', err, data); | ||
@@ -111,0 +108,0 @@ if (err) |
@@ -33,3 +33,4 @@ "use strict"; | ||
break; | ||
default: return reject(new Error(`UNSUPPORTED_PLATFORM`)); | ||
default: | ||
return reject(new Error(`UNSUPPORTED_PLATFORM`)); | ||
} | ||
@@ -63,6 +64,9 @@ // create a new endpoint in the platform | ||
break; | ||
default: return reject(new Error(`UNSUPPORTED_PLATFORM`)); | ||
default: | ||
return reject(new Error(`UNSUPPORTED_PLATFORM`)); | ||
} | ||
this.sns.publish({ | ||
MessageStructure: 'json', Message: JSON.stringify(structuredMessage), TargetArn: endpoint | ||
MessageStructure: 'json', | ||
Message: JSON.stringify(structuredMessage), | ||
TargetArn: endpoint | ||
}, (err, data) => { | ||
@@ -69,0 +73,0 @@ IdeaX.logger('SNS PUSH NOTIFICATION', err, data); |
var typedoc = typedoc || {}; | ||
typedoc.search = typedoc.search || {}; | ||
typedoc.search.data = {"kinds":{"128":"Class","256":"Interface","512":"Constructor","1024":"Property","2048":"Method","262144":"Accessor"},"rows":[{"id":0,"kind":128,"name":"Cognito","url":"classes/cognito.html","classes":"tsd-kind-class"},{"id":1,"kind":512,"name":"constructor","url":"classes/cognito.html#constructor","classes":"tsd-kind-constructor tsd-parent-kind-class","parent":"Cognito"},{"id":2,"kind":2048,"name":"getUserByClaims","url":"classes/cognito.html#getuserbyclaims","classes":"tsd-kind-method tsd-parent-kind-class","parent":"Cognito"},{"id":3,"kind":2048,"name":"getUserByEmail","url":"classes/cognito.html#getuserbyemail","classes":"tsd-kind-method tsd-parent-kind-class","parent":"Cognito"},{"id":4,"kind":2048,"name":"getUserBySub","url":"classes/cognito.html#getuserbysub","classes":"tsd-kind-method tsd-parent-kind-class","parent":"Cognito"},{"id":5,"kind":2048,"name":"createUser","url":"classes/cognito.html#createuser","classes":"tsd-kind-method tsd-parent-kind-class","parent":"Cognito"},{"id":6,"kind":2048,"name":"resendPassword","url":"classes/cognito.html#resendpassword","classes":"tsd-kind-method tsd-parent-kind-class","parent":"Cognito"},{"id":7,"kind":2048,"name":"deleteUser","url":"classes/cognito.html#deleteuser","classes":"tsd-kind-method tsd-parent-kind-class","parent":"Cognito"},{"id":8,"kind":2048,"name":"signIn","url":"classes/cognito.html#signin","classes":"tsd-kind-method tsd-parent-kind-class","parent":"Cognito"},{"id":9,"kind":2048,"name":"updateEmail","url":"classes/cognito.html#updateemail","classes":"tsd-kind-method tsd-parent-kind-class","parent":"Cognito"},{"id":10,"kind":2048,"name":"updatePassword","url":"classes/cognito.html#updatepassword","classes":"tsd-kind-method tsd-parent-kind-class","parent":"Cognito"},{"id":11,"kind":2048,"name":"globalSignOut","url":"classes/cognito.html#globalsignout","classes":"tsd-kind-method tsd-parent-kind-class","parent":"Cognito"},{"id":12,"kind":2048,"name":"confirmSignUp","url":"classes/cognito.html#confirmsignup","classes":"tsd-kind-method tsd-parent-kind-class","parent":"Cognito"},{"id":13,"kind":128,"name":"DynamoDB","url":"classes/dynamodb.html","classes":"tsd-kind-class"},{"id":14,"kind":512,"name":"constructor","url":"classes/dynamodb.html#constructor","classes":"tsd-kind-constructor tsd-parent-kind-class","parent":"DynamoDB"},{"id":15,"kind":2048,"name":"IUID","url":"classes/dynamodb.html#iuid","classes":"tsd-kind-method tsd-parent-kind-class","parent":"DynamoDB"},{"id":16,"kind":2048,"name":"ISID","url":"classes/dynamodb.html#isid","classes":"tsd-kind-method tsd-parent-kind-class","parent":"DynamoDB"},{"id":17,"kind":2048,"name":"getAtomicCounterByKey","url":"classes/dynamodb.html#getatomiccounterbykey","classes":"tsd-kind-method tsd-parent-kind-class","parent":"DynamoDB"},{"id":18,"kind":2048,"name":"get","url":"classes/dynamodb.html#get","classes":"tsd-kind-method tsd-parent-kind-class","parent":"DynamoDB"},{"id":19,"kind":2048,"name":"put","url":"classes/dynamodb.html#put","classes":"tsd-kind-method tsd-parent-kind-class","parent":"DynamoDB"},{"id":20,"kind":2048,"name":"update","url":"classes/dynamodb.html#update","classes":"tsd-kind-method tsd-parent-kind-class","parent":"DynamoDB"},{"id":21,"kind":2048,"name":"delete","url":"classes/dynamodb.html#delete","classes":"tsd-kind-method tsd-parent-kind-class","parent":"DynamoDB"},{"id":22,"kind":2048,"name":"batchGet","url":"classes/dynamodb.html#batchget","classes":"tsd-kind-method tsd-parent-kind-class","parent":"DynamoDB"},{"id":23,"kind":2048,"name":"batchPut","url":"classes/dynamodb.html#batchput","classes":"tsd-kind-method tsd-parent-kind-class","parent":"DynamoDB"},{"id":24,"kind":2048,"name":"batchDelete","url":"classes/dynamodb.html#batchdelete","classes":"tsd-kind-method tsd-parent-kind-class","parent":"DynamoDB"},{"id":25,"kind":2048,"name":"query","url":"classes/dynamodb.html#query","classes":"tsd-kind-method tsd-parent-kind-class","parent":"DynamoDB"},{"id":26,"kind":2048,"name":"scan","url":"classes/dynamodb.html#scan","classes":"tsd-kind-method tsd-parent-kind-class","parent":"DynamoDB"},{"id":27,"kind":2048,"name":"queryClassic","url":"classes/dynamodb.html#queryclassic","classes":"tsd-kind-method tsd-parent-kind-class","parent":"DynamoDB"},{"id":28,"kind":2048,"name":"scanClassic","url":"classes/dynamodb.html#scanclassic","classes":"tsd-kind-method tsd-parent-kind-class","parent":"DynamoDB"},{"id":29,"kind":2048,"name":"transactWrites","url":"classes/dynamodb.html#transactwrites","classes":"tsd-kind-method tsd-parent-kind-class","parent":"DynamoDB"},{"id":30,"kind":256,"name":"RequestLog","url":"interfaces/requestlog.html","classes":"tsd-kind-interface"},{"id":31,"kind":1024,"name":"key","url":"interfaces/requestlog.html#key","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"RequestLog"},{"id":32,"kind":1024,"name":"at","url":"interfaces/requestlog.html#at","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"RequestLog"},{"id":33,"kind":1024,"name":"expiresAt","url":"interfaces/requestlog.html#expiresat","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"RequestLog"},{"id":34,"kind":1024,"name":"userId","url":"interfaces/requestlog.html#userid","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"RequestLog"},{"id":35,"kind":1024,"name":"resource","url":"interfaces/requestlog.html#resource","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"RequestLog"},{"id":36,"kind":1024,"name":"resourceId","url":"interfaces/requestlog.html#resourceid","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"RequestLog"},{"id":37,"kind":1024,"name":"method","url":"interfaces/requestlog.html#method","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"RequestLog"},{"id":38,"kind":1024,"name":"action","url":"interfaces/requestlog.html#action","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"RequestLog"},{"id":39,"kind":1024,"name":"requestSucceeded","url":"interfaces/requestlog.html#requestsucceeded","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"RequestLog"},{"id":40,"kind":1024,"name":"description","url":"interfaces/requestlog.html#description","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"RequestLog"},{"id":41,"kind":128,"name":"S3","url":"classes/s3.html","classes":"tsd-kind-class"},{"id":42,"kind":512,"name":"constructor","url":"classes/s3.html#constructor","classes":"tsd-kind-constructor tsd-parent-kind-class","parent":"S3"},{"id":43,"kind":2048,"name":"createDownloadURLFromData","url":"classes/s3.html#createdownloadurlfromdata","classes":"tsd-kind-method tsd-parent-kind-class","parent":"S3"},{"id":44,"kind":2048,"name":"signedURLPut","url":"classes/s3.html#signedurlput","classes":"tsd-kind-method tsd-parent-kind-class","parent":"S3"},{"id":45,"kind":2048,"name":"signedURLGet","url":"classes/s3.html#signedurlget","classes":"tsd-kind-method tsd-parent-kind-class","parent":"S3"},{"id":46,"kind":2048,"name":"copyObject","url":"classes/s3.html#copyobject","classes":"tsd-kind-method tsd-parent-kind-class","parent":"S3"},{"id":47,"kind":2048,"name":"getObject","url":"classes/s3.html#getobject","classes":"tsd-kind-method tsd-parent-kind-class","parent":"S3"},{"id":48,"kind":256,"name":"SignedURL","url":"interfaces/signedurl.html","classes":"tsd-kind-interface"},{"id":49,"kind":1024,"name":"url","url":"interfaces/signedurl.html#url","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"SignedURL"},{"id":50,"kind":128,"name":"SES","url":"classes/ses.html","classes":"tsd-kind-class"},{"id":51,"kind":512,"name":"constructor","url":"classes/ses.html#constructor","classes":"tsd-kind-constructor tsd-parent-kind-class","parent":"SES"},{"id":52,"kind":2048,"name":"sendEmail","url":"classes/ses.html#sendemail","classes":"tsd-kind-method tsd-parent-kind-class","parent":"SES"},{"id":53,"kind":128,"name":"SNS","url":"classes/sns.html","classes":"tsd-kind-class"},{"id":54,"kind":512,"name":"constructor","url":"classes/sns.html#constructor","classes":"tsd-kind-constructor tsd-parent-kind-class","parent":"SNS"},{"id":55,"kind":2048,"name":"createPushPlatormEndpoint","url":"classes/sns.html#createpushplatormendpoint","classes":"tsd-kind-method tsd-parent-kind-class","parent":"SNS"},{"id":56,"kind":2048,"name":"publishSNSPush","url":"classes/sns.html#publishsnspush","classes":"tsd-kind-method tsd-parent-kind-class","parent":"SNS"},{"id":57,"kind":128,"name":"ResourceController","url":"classes/resourcecontroller.html","classes":"tsd-kind-class"},{"id":58,"kind":512,"name":"constructor","url":"classes/resourcecontroller.html#constructor","classes":"tsd-kind-constructor tsd-parent-kind-class","parent":"ResourceController"},{"id":59,"kind":2048,"name":"handleRequest","url":"classes/resourcecontroller.html#handlerequest","classes":"tsd-kind-method tsd-parent-kind-class","parent":"ResourceController"},{"id":60,"kind":262144,"name":"dynamoDB","url":"classes/resourcecontroller.html#dynamodb","classes":"tsd-kind-accessor tsd-parent-kind-class","parent":"ResourceController"},{"id":61,"kind":262144,"name":"cognito","url":"classes/resourcecontroller.html#cognito","classes":"tsd-kind-accessor tsd-parent-kind-class","parent":"ResourceController"},{"id":62,"kind":262144,"name":"s3","url":"classes/resourcecontroller.html#s3","classes":"tsd-kind-accessor tsd-parent-kind-class","parent":"ResourceController"},{"id":63,"kind":262144,"name":"ses","url":"classes/resourcecontroller.html#ses","classes":"tsd-kind-accessor tsd-parent-kind-class","parent":"ResourceController"},{"id":64,"kind":262144,"name":"sns","url":"classes/resourcecontroller.html#sns","classes":"tsd-kind-accessor tsd-parent-kind-class","parent":"ResourceController"},{"id":65,"kind":256,"name":"ResourceControllerOptions","url":"interfaces/resourcecontrolleroptions.html","classes":"tsd-kind-interface"},{"id":66,"kind":1024,"name":"tables","url":"interfaces/resourcecontrolleroptions.html#tables","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"ResourceControllerOptions"},{"id":67,"kind":1024,"name":"resourceId","url":"interfaces/resourcecontrolleroptions.html#resourceid","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"ResourceControllerOptions"},{"id":68,"kind":1024,"name":"logsKeys","url":"interfaces/resourcecontrolleroptions.html#logskeys","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"ResourceControllerOptions"}]}; | ||
typedoc.search.data = {"kinds":{"128":"Class","256":"Interface","512":"Constructor","1024":"Property","2048":"Method","262144":"Accessor"},"rows":[{"id":0,"kind":128,"name":"Cognito","url":"classes/cognito.html","classes":"tsd-kind-class"},{"id":1,"kind":512,"name":"constructor","url":"classes/cognito.html#constructor","classes":"tsd-kind-constructor tsd-parent-kind-class","parent":"Cognito"},{"id":2,"kind":2048,"name":"getUserByClaims","url":"classes/cognito.html#getuserbyclaims","classes":"tsd-kind-method tsd-parent-kind-class","parent":"Cognito"},{"id":3,"kind":2048,"name":"getUserByEmail","url":"classes/cognito.html#getuserbyemail","classes":"tsd-kind-method tsd-parent-kind-class","parent":"Cognito"},{"id":4,"kind":2048,"name":"getUserBySub","url":"classes/cognito.html#getuserbysub","classes":"tsd-kind-method tsd-parent-kind-class","parent":"Cognito"},{"id":5,"kind":2048,"name":"createUser","url":"classes/cognito.html#createuser","classes":"tsd-kind-method tsd-parent-kind-class","parent":"Cognito"},{"id":6,"kind":2048,"name":"resendPassword","url":"classes/cognito.html#resendpassword","classes":"tsd-kind-method tsd-parent-kind-class","parent":"Cognito"},{"id":7,"kind":2048,"name":"deleteUser","url":"classes/cognito.html#deleteuser","classes":"tsd-kind-method tsd-parent-kind-class","parent":"Cognito"},{"id":8,"kind":2048,"name":"signIn","url":"classes/cognito.html#signin","classes":"tsd-kind-method tsd-parent-kind-class","parent":"Cognito"},{"id":9,"kind":2048,"name":"updateEmail","url":"classes/cognito.html#updateemail","classes":"tsd-kind-method tsd-parent-kind-class","parent":"Cognito"},{"id":10,"kind":2048,"name":"updatePassword","url":"classes/cognito.html#updatepassword","classes":"tsd-kind-method tsd-parent-kind-class","parent":"Cognito"},{"id":11,"kind":2048,"name":"globalSignOut","url":"classes/cognito.html#globalsignout","classes":"tsd-kind-method tsd-parent-kind-class","parent":"Cognito"},{"id":12,"kind":2048,"name":"confirmSignUp","url":"classes/cognito.html#confirmsignup","classes":"tsd-kind-method tsd-parent-kind-class","parent":"Cognito"},{"id":13,"kind":128,"name":"DynamoDB","url":"classes/dynamodb.html","classes":"tsd-kind-class"},{"id":14,"kind":512,"name":"constructor","url":"classes/dynamodb.html#constructor","classes":"tsd-kind-constructor tsd-parent-kind-class","parent":"DynamoDB"},{"id":15,"kind":2048,"name":"IUID","url":"classes/dynamodb.html#iuid","classes":"tsd-kind-method tsd-parent-kind-class","parent":"DynamoDB"},{"id":16,"kind":2048,"name":"ISID","url":"classes/dynamodb.html#isid","classes":"tsd-kind-method tsd-parent-kind-class","parent":"DynamoDB"},{"id":17,"kind":2048,"name":"getAtomicCounterByKey","url":"classes/dynamodb.html#getatomiccounterbykey","classes":"tsd-kind-method tsd-parent-kind-class","parent":"DynamoDB"},{"id":18,"kind":2048,"name":"get","url":"classes/dynamodb.html#get","classes":"tsd-kind-method tsd-parent-kind-class","parent":"DynamoDB"},{"id":19,"kind":2048,"name":"put","url":"classes/dynamodb.html#put","classes":"tsd-kind-method tsd-parent-kind-class","parent":"DynamoDB"},{"id":20,"kind":2048,"name":"update","url":"classes/dynamodb.html#update","classes":"tsd-kind-method tsd-parent-kind-class","parent":"DynamoDB"},{"id":21,"kind":2048,"name":"delete","url":"classes/dynamodb.html#delete","classes":"tsd-kind-method tsd-parent-kind-class","parent":"DynamoDB"},{"id":22,"kind":2048,"name":"batchGet","url":"classes/dynamodb.html#batchget","classes":"tsd-kind-method tsd-parent-kind-class","parent":"DynamoDB"},{"id":23,"kind":2048,"name":"batchPut","url":"classes/dynamodb.html#batchput","classes":"tsd-kind-method tsd-parent-kind-class","parent":"DynamoDB"},{"id":24,"kind":2048,"name":"batchDelete","url":"classes/dynamodb.html#batchdelete","classes":"tsd-kind-method tsd-parent-kind-class","parent":"DynamoDB"},{"id":25,"kind":2048,"name":"query","url":"classes/dynamodb.html#query","classes":"tsd-kind-method tsd-parent-kind-class","parent":"DynamoDB"},{"id":26,"kind":2048,"name":"scan","url":"classes/dynamodb.html#scan","classes":"tsd-kind-method tsd-parent-kind-class","parent":"DynamoDB"},{"id":27,"kind":2048,"name":"queryClassic","url":"classes/dynamodb.html#queryclassic","classes":"tsd-kind-method tsd-parent-kind-class","parent":"DynamoDB"},{"id":28,"kind":2048,"name":"scanClassic","url":"classes/dynamodb.html#scanclassic","classes":"tsd-kind-method tsd-parent-kind-class","parent":"DynamoDB"},{"id":29,"kind":2048,"name":"transactWrites","url":"classes/dynamodb.html#transactwrites","classes":"tsd-kind-method tsd-parent-kind-class","parent":"DynamoDB"},{"id":30,"kind":256,"name":"RequestLog","url":"interfaces/requestlog.html","classes":"tsd-kind-interface"},{"id":31,"kind":1024,"name":"key","url":"interfaces/requestlog.html#key","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"RequestLog"},{"id":32,"kind":1024,"name":"at","url":"interfaces/requestlog.html#at","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"RequestLog"},{"id":33,"kind":1024,"name":"expiresAt","url":"interfaces/requestlog.html#expiresat","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"RequestLog"},{"id":34,"kind":1024,"name":"userId","url":"interfaces/requestlog.html#userid","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"RequestLog"},{"id":35,"kind":1024,"name":"resource","url":"interfaces/requestlog.html#resource","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"RequestLog"},{"id":36,"kind":1024,"name":"resourceId","url":"interfaces/requestlog.html#resourceid","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"RequestLog"},{"id":37,"kind":1024,"name":"method","url":"interfaces/requestlog.html#method","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"RequestLog"},{"id":38,"kind":1024,"name":"action","url":"interfaces/requestlog.html#action","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"RequestLog"},{"id":39,"kind":1024,"name":"requestSucceeded","url":"interfaces/requestlog.html#requestsucceeded","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"RequestLog"},{"id":40,"kind":1024,"name":"description","url":"interfaces/requestlog.html#description","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"RequestLog"},{"id":41,"kind":128,"name":"S3","url":"classes/s3.html","classes":"tsd-kind-class"},{"id":42,"kind":512,"name":"constructor","url":"classes/s3.html#constructor","classes":"tsd-kind-constructor tsd-parent-kind-class","parent":"S3"},{"id":43,"kind":2048,"name":"createDownloadURLFromData","url":"classes/s3.html#createdownloadurlfromdata","classes":"tsd-kind-method tsd-parent-kind-class","parent":"S3"},{"id":44,"kind":2048,"name":"signedURLPut","url":"classes/s3.html#signedurlput","classes":"tsd-kind-method tsd-parent-kind-class","parent":"S3"},{"id":45,"kind":2048,"name":"signedURLGet","url":"classes/s3.html#signedurlget","classes":"tsd-kind-method tsd-parent-kind-class","parent":"S3"},{"id":46,"kind":2048,"name":"copyObject","url":"classes/s3.html#copyobject","classes":"tsd-kind-method tsd-parent-kind-class","parent":"S3"},{"id":47,"kind":2048,"name":"getObject","url":"classes/s3.html#getobject","classes":"tsd-kind-method tsd-parent-kind-class","parent":"S3"},{"id":48,"kind":2048,"name":"putObject","url":"classes/s3.html#putobject","classes":"tsd-kind-method tsd-parent-kind-class","parent":"S3"},{"id":49,"kind":256,"name":"SignedURL","url":"interfaces/signedurl.html","classes":"tsd-kind-interface"},{"id":50,"kind":1024,"name":"url","url":"interfaces/signedurl.html#url","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"SignedURL"},{"id":51,"kind":128,"name":"SES","url":"classes/ses.html","classes":"tsd-kind-class"},{"id":52,"kind":512,"name":"constructor","url":"classes/ses.html#constructor","classes":"tsd-kind-constructor tsd-parent-kind-class","parent":"SES"},{"id":53,"kind":2048,"name":"sendEmail","url":"classes/ses.html#sendemail","classes":"tsd-kind-method tsd-parent-kind-class","parent":"SES"},{"id":54,"kind":128,"name":"SNS","url":"classes/sns.html","classes":"tsd-kind-class"},{"id":55,"kind":512,"name":"constructor","url":"classes/sns.html#constructor","classes":"tsd-kind-constructor tsd-parent-kind-class","parent":"SNS"},{"id":56,"kind":2048,"name":"createPushPlatormEndpoint","url":"classes/sns.html#createpushplatormendpoint","classes":"tsd-kind-method tsd-parent-kind-class","parent":"SNS"},{"id":57,"kind":2048,"name":"publishSNSPush","url":"classes/sns.html#publishsnspush","classes":"tsd-kind-method tsd-parent-kind-class","parent":"SNS"},{"id":58,"kind":128,"name":"ResourceController","url":"classes/resourcecontroller.html","classes":"tsd-kind-class"},{"id":59,"kind":512,"name":"constructor","url":"classes/resourcecontroller.html#constructor","classes":"tsd-kind-constructor tsd-parent-kind-class","parent":"ResourceController"},{"id":60,"kind":2048,"name":"handleRequest","url":"classes/resourcecontroller.html#handlerequest","classes":"tsd-kind-method tsd-parent-kind-class","parent":"ResourceController"},{"id":61,"kind":262144,"name":"dynamoDB","url":"classes/resourcecontroller.html#dynamodb","classes":"tsd-kind-accessor tsd-parent-kind-class","parent":"ResourceController"},{"id":62,"kind":262144,"name":"cognito","url":"classes/resourcecontroller.html#cognito","classes":"tsd-kind-accessor tsd-parent-kind-class","parent":"ResourceController"},{"id":63,"kind":262144,"name":"s3","url":"classes/resourcecontroller.html#s3","classes":"tsd-kind-accessor tsd-parent-kind-class","parent":"ResourceController"},{"id":64,"kind":262144,"name":"ses","url":"classes/resourcecontroller.html#ses","classes":"tsd-kind-accessor tsd-parent-kind-class","parent":"ResourceController"},{"id":65,"kind":262144,"name":"sns","url":"classes/resourcecontroller.html#sns","classes":"tsd-kind-accessor tsd-parent-kind-class","parent":"ResourceController"},{"id":66,"kind":256,"name":"ResourceControllerOptions","url":"interfaces/resourcecontrolleroptions.html","classes":"tsd-kind-interface"},{"id":67,"kind":1024,"name":"tables","url":"interfaces/resourcecontrolleroptions.html#tables","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"ResourceControllerOptions"},{"id":68,"kind":1024,"name":"resourceId","url":"interfaces/resourcecontrolleroptions.html#resourceid","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"ResourceControllerOptions"},{"id":69,"kind":1024,"name":"logsKeys","url":"interfaces/resourcecontrolleroptions.html#logskeys","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"ResourceControllerOptions"}]}; |
@@ -7,3 +7,3 @@ # Release a new version on npm | ||
1. Commit the files changed in the previous point and commit them using the name of the version | ||
as commit description (e.g. v0.0.2). | ||
1. Release the new version on npm with `npm run publishPackage`. | ||
as commit description (e.g. v0.0.2). | ||
1. Release the new version on npm with `npm run publishPackage`. |
{ | ||
"name": "idea-aws", | ||
"version": "2.5.0", | ||
"version": "2.6.0", | ||
"description": "AWS wrappers to use in IDEA's back-ends", | ||
@@ -48,2 +48,3 @@ "engines": { | ||
"tslint": "^5.13.0", | ||
"typedoc": "^0.15.0", | ||
"typescript": "^2.9.2", | ||
@@ -50,0 +51,0 @@ "typescript-tslint-plugin": "^0.3.1" |
@@ -22,2 +22,2 @@ # IDEA AWS | ||
- The AWS-SDK is a back-end only package, which is already pre-installed in any Lambda Function; | ||
therefore, we included it only as devDependency. | ||
therefore, we included it only as devDependency. |
@@ -40,13 +40,14 @@ import AWS = require('aws-sdk'); | ||
// find the user by the email | ||
new AWS.CognitoIdentityServiceProvider({ apiVersion: '2016-04-18' }) | ||
.listUsers({ UserPoolId: cognitoUserPoolId, Filter: `email = "${email}"`, Limit: 1}, | ||
(err: Error, data: any) => { | ||
if (err || !data || !data.Users || !data.Users[0]) reject(); | ||
else { | ||
// convert and return the attributes | ||
const userAttributes: any = {}; | ||
data.Users[0].Attributes.forEach((a: any) => userAttributes[a.Name] = a.Value); | ||
resolve(userAttributes); | ||
new AWS.CognitoIdentityServiceProvider({ apiVersion: '2016-04-18' }).listUsers( | ||
{ UserPoolId: cognitoUserPoolId, Filter: `email = "${email}"`, Limit: 1 }, | ||
(err: Error, data: any) => { | ||
if (err || !data || !data.Users || !data.Users[0]) reject(); | ||
else { | ||
// convert and return the attributes | ||
const userAttributes: any = {}; | ||
data.Users[0].Attributes.forEach((a: any) => (userAttributes[a.Name] = a.Value)); | ||
resolve(userAttributes); | ||
} | ||
} | ||
}); | ||
); | ||
}); | ||
@@ -64,13 +65,14 @@ } | ||
// find the user by the sub | ||
new AWS.CognitoIdentityServiceProvider({ apiVersion: '2016-04-18' }) | ||
.listUsers({ UserPoolId: cognitoUserPoolId, Filter: `sub = "${sub}"`, Limit: 1}, | ||
(err: Error, data: any) => { | ||
if (err || !data || !data.Users || !data.Users[0]) reject(); | ||
else { | ||
// convert and return the attributes | ||
const userAttributes: any = {}; | ||
data.Users[0].Attributes.forEach((a: any) => userAttributes[a.Name] = a.Value); | ||
resolve(userAttributes); | ||
new AWS.CognitoIdentityServiceProvider({ apiVersion: '2016-04-18' }).listUsers( | ||
{ UserPoolId: cognitoUserPoolId, Filter: `sub = "${sub}"`, Limit: 1 }, | ||
(err: Error, data: any) => { | ||
if (err || !data || !data.Users || !data.Users[0]) reject(); | ||
else { | ||
// convert and return the attributes | ||
const userAttributes: any = {}; | ||
data.Users[0].Attributes.forEach((a: any) => (userAttributes[a.Name] = a.Value)); | ||
resolve(userAttributes); | ||
} | ||
} | ||
}); | ||
); | ||
}); | ||
@@ -97,4 +99,6 @@ } | ||
const attributes = [{ Name: 'email', Value: email }, { Name: 'email_verified', Value: 'true' }]; | ||
const params = <any> { | ||
UserPoolId: cognitoUserPoolId, Username: email, UserAttributes: attributes | ||
const params = <any>{ | ||
UserPoolId: cognitoUserPoolId, | ||
Username: email, | ||
UserAttributes: attributes | ||
}; | ||
@@ -105,9 +109,11 @@ if (options.skipNotification) params.MessageAction = 'SUPPRESS'; | ||
IdeaX.logger('COGNITO CREATE USER', err, data); | ||
if (err) switch (err.name) { | ||
case 'UsernameExistsException': | ||
return reject(new Error(`E.COGNITO.USERNAME_ALREADY_EXISTS`)); | ||
case 'InvalidPasswordException': | ||
return reject(new Error(`E.COGNITO.INVALID_PASSWORD`)); | ||
default: return reject(err); | ||
} | ||
if (err) | ||
switch (err.name) { | ||
case 'UsernameExistsException': | ||
return reject(new Error(`E.COGNITO.USERNAME_ALREADY_EXISTS`)); | ||
case 'InvalidPasswordException': | ||
return reject(new Error(`E.COGNITO.INVALID_PASSWORD`)); | ||
default: | ||
return reject(err); | ||
} | ||
const userId = data.User.Attributes.find((attr: any) => attr.Name === 'sub').Value || null; | ||
@@ -136,4 +142,6 @@ if (userId) resolve(userId); | ||
if (IdeaX.isEmpty(email, 'email')) return reject(new Error(`E.COGNITO.INVALID_EMAIL`)); | ||
const params = <any> { | ||
UserPoolId: cognitoUserPoolId, Username: email, MessageAction: 'RESEND' | ||
const params = <any>{ | ||
UserPoolId: cognitoUserPoolId, | ||
Username: email, | ||
MessageAction: 'RESEND' | ||
}; | ||
@@ -143,7 +151,10 @@ if (options.temporaryPassword) params.TemporaryPassword = options.temporaryPassword; | ||
IdeaX.logger('COGNITO RESEND PASSWORD', err, data); | ||
if (err) switch (err.name) { | ||
case 'UnsupportedUserStateException': | ||
return reject(new Error(`E.COGNITO.USER_ALREADY_CONFIRMED_PASSWORD`)); | ||
default: return reject(err); | ||
} else resolve(); | ||
if (err) | ||
switch (err.name) { | ||
case 'UnsupportedUserStateException': | ||
return reject(new Error(`E.COGNITO.USER_ALREADY_CONFIRMED_PASSWORD`)); | ||
default: | ||
return reject(err); | ||
} | ||
else resolve(); | ||
}); | ||
@@ -162,8 +173,10 @@ }); | ||
if (IdeaX.isEmpty(email, 'email')) return reject(new Error(`E.COGNITO.INVALID_EMAIL`)); | ||
new AWS.CognitoIdentityServiceProvider() | ||
.adminDeleteUser({ UserPoolId: cognitoUserPoolId, Username: email }, (err: Error) => { | ||
IdeaX.logger('COGNITO DELETE USER', err, `${email} (${cognitoUserPoolId})`); | ||
if (err) reject(new Error(`E.COGNITO.DELETION_FAILED`)); | ||
else resolve(); | ||
}); | ||
new AWS.CognitoIdentityServiceProvider().adminDeleteUser( | ||
{ UserPoolId: cognitoUserPoolId, Username: email }, | ||
(err: Error) => { | ||
IdeaX.logger('COGNITO DELETE USER', err, `${email} (${cognitoUserPoolId})`); | ||
if (err) reject(new Error(`E.COGNITO.DELETION_FAILED`)); | ||
else resolve(); | ||
} | ||
); | ||
}); | ||
@@ -182,16 +195,21 @@ } | ||
public signIn( | ||
email: string, password: string, cognitoUserPoolId: string, cognitoUserPoolClientId: string | ||
email: string, | ||
password: string, | ||
cognitoUserPoolId: string, | ||
cognitoUserPoolClientId: string | ||
): Promise<AWS.CognitoIdentityServiceProvider.AuthenticationResultType> { | ||
return new Promise((resolve, reject) => { | ||
new AWS.CognitoIdentityServiceProvider({ apiVersion: '2016-04-18' }) | ||
.adminInitiateAuth({ | ||
UserPoolId: cognitoUserPoolId, | ||
ClientId: cognitoUserPoolClientId, | ||
AuthFlow: 'ADMIN_NO_SRP_AUTH', | ||
AuthParameters: { 'USERNAME': email, 'PASSWORD': password } | ||
}, (err: Error, data: AWS.CognitoIdentityServiceProvider.AdminInitiateAuthResponse) => { | ||
IdeaX.logger('COGNITO SIGN IN', err, data ? JSON.stringify(data.toString) : null); | ||
if (err || !data.AuthenticationResult) reject(err); | ||
else resolve(data.AuthenticationResult); | ||
}); | ||
new AWS.CognitoIdentityServiceProvider({ apiVersion: '2016-04-18' }).adminInitiateAuth( | ||
{ | ||
UserPoolId: cognitoUserPoolId, | ||
ClientId: cognitoUserPoolClientId, | ||
AuthFlow: 'ADMIN_NO_SRP_AUTH', | ||
AuthParameters: { USERNAME: email, PASSWORD: password } | ||
}, | ||
(err: Error, data: AWS.CognitoIdentityServiceProvider.AdminInitiateAuthResponse) => { | ||
IdeaX.logger('COGNITO SIGN IN', err, data ? JSON.stringify(data.toString) : null); | ||
if (err || !data.AuthenticationResult) reject(err); | ||
else resolve(data.AuthenticationResult); | ||
} | ||
); | ||
}); | ||
@@ -210,18 +228,18 @@ } | ||
if (IdeaX.isEmpty(newEmail, 'email')) return reject(new Error('E.COGNITO.INVALID_NEW_EMAIL')); | ||
new AWS.CognitoIdentityServiceProvider({ apiVersion: '2016-04-18' }) | ||
.adminUpdateUserAttributes({ | ||
UserPoolId: cognitoUserPoolId, | ||
Username: email, | ||
UserAttributes: [ | ||
{ Name: 'email', Value: newEmail }, | ||
{ Name: 'email_verified', Value: 'true' } | ||
] | ||
}, (err: Error, _: any) => { | ||
IdeaX.logger('COGNITO UPDATE EMAIL', err, newEmail); | ||
if (err) reject(err); | ||
// sign out the user from all its devices and resolve | ||
else this.globalSignOut(newEmail, cognitoUserPoolId) | ||
.then(() => resolve()) | ||
.catch(e => reject(e)); | ||
}); | ||
new AWS.CognitoIdentityServiceProvider({ apiVersion: '2016-04-18' }).adminUpdateUserAttributes( | ||
{ | ||
UserPoolId: cognitoUserPoolId, | ||
Username: email, | ||
UserAttributes: [{ Name: 'email', Value: newEmail }, { Name: 'email_verified', Value: 'true' }] | ||
}, | ||
(err: Error, _: any) => { | ||
IdeaX.logger('COGNITO UPDATE EMAIL', err, newEmail); | ||
if (err) reject(err); | ||
// sign out the user from all its devices and resolve | ||
else | ||
this.globalSignOut(newEmail, cognitoUserPoolId) | ||
.then(() => resolve()) | ||
.catch(e => reject(e)); | ||
} | ||
); | ||
}); | ||
@@ -241,4 +259,7 @@ } | ||
public updatePassword( | ||
email: string, oldPassword: string, newPassword: string, | ||
cognitoUserPoolId: string, cognitoUserPoolClientId: string | ||
email: string, | ||
oldPassword: string, | ||
newPassword: string, | ||
cognitoUserPoolId: string, | ||
cognitoUserPoolClientId: string | ||
): Promise<void> { | ||
@@ -249,16 +270,18 @@ return new Promise((resolve, reject) => { | ||
this.signIn(email, oldPassword, cognitoUserPoolId, cognitoUserPoolClientId) | ||
.then((data: AWS.CognitoIdentityServiceProvider.AuthenticationResultType) => { | ||
// request the password change | ||
new AWS.CognitoIdentityServiceProvider({ apiVersion: '2016-04-18' }) | ||
.changePassword({ | ||
AccessToken: data.AccessToken, | ||
PreviousPassword: oldPassword, | ||
ProposedPassword: newPassword | ||
}, (err: Error, _: any) => { | ||
IdeaX.logger('COGNITO UPDATE PASSWORD', err, '*******'); | ||
if (err) reject(err); | ||
else resolve(); | ||
}); | ||
}) | ||
.catch((err) => reject(err)); | ||
.then((data: AWS.CognitoIdentityServiceProvider.AuthenticationResultType) => { | ||
// request the password change | ||
new AWS.CognitoIdentityServiceProvider({ apiVersion: '2016-04-18' }).changePassword( | ||
{ | ||
AccessToken: data.AccessToken, | ||
PreviousPassword: oldPassword, | ||
ProposedPassword: newPassword | ||
}, | ||
(err: Error, _: any) => { | ||
IdeaX.logger('COGNITO UPDATE PASSWORD', err, '*******'); | ||
if (err) reject(err); | ||
else resolve(); | ||
} | ||
); | ||
}) | ||
.catch(err => reject(err)); | ||
}); | ||
@@ -275,11 +298,13 @@ } | ||
return new Promise((resolve, reject) => { | ||
new AWS.CognitoIdentityServiceProvider({ apiVersion: '2016-04-18' }) | ||
.adminUserGlobalSignOut({ | ||
Username: email, | ||
UserPoolId: cognitoUserPoolId | ||
}, (err: Error, _: any) => { | ||
IdeaX.logger('COGNITO GLOBAL SIGN OUT', err, email); | ||
if (err) reject(err); | ||
else resolve(); | ||
}); | ||
new AWS.CognitoIdentityServiceProvider({ apiVersion: '2016-04-18' }).adminUserGlobalSignOut( | ||
{ | ||
Username: email, | ||
UserPoolId: cognitoUserPoolId | ||
}, | ||
(err: Error, _: any) => { | ||
IdeaX.logger('COGNITO GLOBAL SIGN OUT', err, email); | ||
if (err) reject(err); | ||
else resolve(); | ||
} | ||
); | ||
}); | ||
@@ -302,11 +327,12 @@ } | ||
// conclude the registration (sign-up) flow, using a provided confirmation code | ||
new AWS.CognitoIdentityServiceProvider({ apiVersion: '2016-04-18' }) | ||
.confirmSignUp({ Username: email, ConfirmationCode: confirmationCode, ClientId: cognitoUserPoolClientId }, | ||
(err: Error, _: any) => { | ||
IdeaX.logger('COGNITO CONFIRM SIGN UP', err, `${email} ${confirmationCode}`); | ||
if (err) reject(err); | ||
else resolve(); | ||
}); | ||
new AWS.CognitoIdentityServiceProvider({ apiVersion: '2016-04-18' }).confirmSignUp( | ||
{ Username: email, ConfirmationCode: confirmationCode, ClientId: cognitoUserPoolClientId }, | ||
(err: Error, _: any) => { | ||
IdeaX.logger('COGNITO CONFIRM SIGN UP', err, `${email} ${confirmationCode}`); | ||
if (err) reject(err); | ||
else resolve(); | ||
} | ||
); | ||
}); | ||
} | ||
} |
@@ -41,3 +41,4 @@ import AWS = require('aws-sdk'); | ||
this.put({ | ||
TableName: 'idea_IUID', Item: { project: project, id: id }, | ||
TableName: 'idea_IUID', | ||
Item: { project: project, id: id }, | ||
ConditionExpression: 'NOT (#p = :project AND #id = :id)', | ||
@@ -47,5 +48,7 @@ ExpressionAttributeNames: { '#p': 'project', '#id': 'id' }, | ||
}) | ||
.then(() => resolve(`${project}_${id}`)) | ||
.catch(() => // ID exists, try again | ||
this.iuidHelper(project, attempt + 1, maxAttempts, resolve, reject)); | ||
.then(() => resolve(`${project}_${id}`)) | ||
.catch(() => | ||
// ID exists, try again | ||
this.iuidHelper(project, attempt + 1, maxAttempts, resolve, reject) | ||
); | ||
} | ||
@@ -76,3 +79,4 @@ } | ||
this.put({ | ||
TableName: 'idea_ISID', Item: { project: project, id: id }, | ||
TableName: 'idea_ISID', | ||
Item: { project: project, id: id }, | ||
ConditionExpression: 'NOT (#p = :project AND #id = :id)', | ||
@@ -82,5 +86,7 @@ ExpressionAttributeNames: { '#p': 'project', '#id': 'id' }, | ||
}) | ||
.then(() => resolve(id)) | ||
.catch(() => // ID exists, try again | ||
this.isidHelper(project, attempt + 1, maxAttempts, resolve, reject)); | ||
.then(() => resolve(id)) | ||
.catch(() => | ||
// ID exists, try again | ||
this.isidHelper(project, attempt + 1, maxAttempts, resolve, reject) | ||
); | ||
} | ||
@@ -99,3 +105,4 @@ } | ||
this.update({ | ||
TableName: 'idea_atomicCounters', Key: { key: key }, | ||
TableName: 'idea_atomicCounters', | ||
Key: { key: key }, | ||
UpdateExpression: 'ADD atomicCounter :increment', | ||
@@ -105,4 +112,4 @@ ExpressionAttributeValues: { ':increment': 1 }, | ||
}) | ||
.then((data: any) => resolve(data.Attributes.atomicCounter)) | ||
.catch(err => reject(err)); | ||
.then((data: any) => resolve(data.Attributes.atomicCounter)) | ||
.catch(err => reject(err)); | ||
}); | ||
@@ -119,4 +126,7 @@ } | ||
this.dynamo.get(params, (err: Error, data: any) => { | ||
IdeaX.logger(`GET ${params.IndexName | ||
? `${params.TableName} (${params.IndexName})` : params.TableName}`, err, data); | ||
IdeaX.logger( | ||
`GET ${params.IndexName ? `${params.TableName} (${params.IndexName})` : params.TableName}`, | ||
err, | ||
data | ||
); | ||
if (err || !data.Item) reject(err); | ||
@@ -193,4 +203,10 @@ else resolve(data.Item); | ||
protected batchGetHelper( | ||
t: string, keys: Array<any>, elements: Array<any>, iErr: boolean, curr: number, size: number, | ||
resolve: any, reject: any | ||
t: string, | ||
keys: Array<any>, | ||
elements: Array<any>, | ||
iErr: boolean, | ||
curr: number, | ||
size: number, | ||
resolve: any, | ||
reject: any | ||
) { | ||
@@ -208,4 +224,3 @@ // prepare the structure for the bulk operation | ||
// if there are still chunks to manage, go on recursively | ||
if (curr + size < keys.length) | ||
this.batchGetHelper(t, keys, elements, iErr, curr + size, size, resolve, reject); | ||
if (curr + size < keys.length) this.batchGetHelper(t, keys, elements, iErr, curr + size, size, resolve, reject); | ||
// no more chunks to manage: we're done | ||
@@ -251,3 +266,10 @@ else resolve(elements); | ||
protected batchWriteHelper( | ||
t: string, items: Array<any>, isPut: boolean, iErr: boolean, curr: number, size: number, resolve: any, reject: any | ||
t: string, | ||
items: Array<any>, | ||
isPut: boolean, | ||
iErr: boolean, | ||
curr: number, | ||
size: number, | ||
resolve: any, | ||
reject: any | ||
) { | ||
@@ -257,11 +279,8 @@ // prepare the structure for the bulk operation | ||
if (isPut) { | ||
batch.RequestItems[t] = items | ||
.slice(curr, curr + size) | ||
.map(i => { | ||
batch.RequestItems[t] = items.slice(curr, curr + size).map(i => { | ||
return { PutRequest: { Item: i } }; | ||
}); | ||
} else { // isDelete | ||
batch.RequestItems[t] = items | ||
.slice(curr, curr + size) | ||
.map(k => { | ||
} else { | ||
// isDelete | ||
batch.RequestItems[t] = items.slice(curr, curr + size).map(k => { | ||
return { DeleteRequest: { Key: k } }; | ||
@@ -272,4 +291,3 @@ }); | ||
this.dynamo.batchWrite(batch, (err: Error) => { | ||
IdeaX.logger(`BATCH WRITE (${isPut ? 'PUT' : 'DELETE'}) ${t}`, err, | ||
`${curr} of ${items.length}`); | ||
IdeaX.logger(`BATCH WRITE (${isPut ? 'PUT' : 'DELETE'}) ${t}`, err, `${curr} of ${items.length}`); | ||
if (err && !iErr) reject(err); | ||
@@ -367,9 +385,10 @@ // if there are still chunks to manage, go on recursively | ||
resolve(); | ||
} else this.dynamo.transactWrite({ TransactItems: ops.slice(0, 10) }, (err: Error) => { | ||
IdeaX.logger(`TRANSACTION WRITES`, err, null); | ||
if (err) reject(err); | ||
else resolve(); | ||
}); | ||
} else | ||
this.dynamo.transactWrite({ TransactItems: ops.slice(0, 10) }, (err: Error) => { | ||
IdeaX.logger(`TRANSACTION WRITES`, err, null); | ||
if (err) reject(err); | ||
else resolve(); | ||
}); | ||
}); | ||
} | ||
} |
@@ -45,3 +45,3 @@ import UUIDV4 = require('uuid/v4'); | ||
constructor(event: any, callback: any, options?: ResourceControllerOptions) { | ||
options = options || <ResourceControllerOptions> {}; | ||
options = options || <ResourceControllerOptions>{}; | ||
IdeaX.logger('START', null, event, true); | ||
@@ -57,4 +57,6 @@ | ||
this.resource = (event.resource || '').replace('+', ''); // {proxy+} -> {proxy} | ||
this.resourceId = event.pathParameters && event.pathParameters[options.resourceId || 'proxy'] | ||
? decodeURIComponent(event.pathParameters[options.resourceId || 'proxy']) : ''; | ||
this.resourceId = | ||
event.pathParameters && event.pathParameters[options.resourceId || 'proxy'] | ||
? decodeURIComponent(event.pathParameters[options.resourceId || 'proxy']) | ||
: ''; | ||
this.queryParams = event.queryStringParameters || {}; | ||
@@ -68,5 +70,5 @@ this.body = JSON.parse(event.body) || {}; | ||
/// | ||
/// REQUEST HANDLERS | ||
/// | ||
/// | ||
/// REQUEST HANDLERS | ||
/// | ||
@@ -79,33 +81,58 @@ /** | ||
this.checkAuthBeforeRequest() | ||
.then(() => { | ||
let request; | ||
if (this.resourceId) switch (this.httpMethod) { | ||
// resource/{resourceId} | ||
case 'GET': request = this.getResource(); break; | ||
case 'POST': request = this.postResource(); break; | ||
case 'PUT': request = this.putResource(); break; | ||
case 'DELETE': request = this.deleteResource(); break; | ||
case 'PATCH': request = this.patchResource(); break; | ||
case 'HEAD': request = this.headResource(); break; | ||
default: /* nope */ | ||
} else switch (this.httpMethod) { | ||
// resource | ||
case 'GET': request = this.getResources(); break; | ||
case 'POST': request = this.postResources(); break; | ||
case 'PUT': request = this.putResources(); break; | ||
case 'DELETE': request = this.deleteResources(); break; | ||
case 'PATCH': request = this.patchResources(); break; | ||
case 'HEAD': request = this.headResources(); break; | ||
default: /* nope */ | ||
} | ||
// execute the API request | ||
if (!request) this.done(new Error(`E.COMMON.UNSUPPORTED_ACTION`)); | ||
else { | ||
IdeaX.logger('REQUEST', null, this.httpMethod, true); | ||
request | ||
.then((res: any) => this.done(null, res)) | ||
.catch((err: Error) => this.done(err)); | ||
} | ||
}) | ||
.catch(() => this.done(new Error(`E.COMMON.UNAUTHORIZED`))); | ||
.then(() => { | ||
let request; | ||
if (this.resourceId) | ||
switch (this.httpMethod) { | ||
// resource/{resourceId} | ||
case 'GET': | ||
request = this.getResource(); | ||
break; | ||
case 'POST': | ||
request = this.postResource(); | ||
break; | ||
case 'PUT': | ||
request = this.putResource(); | ||
break; | ||
case 'DELETE': | ||
request = this.deleteResource(); | ||
break; | ||
case 'PATCH': | ||
request = this.patchResource(); | ||
break; | ||
case 'HEAD': | ||
request = this.headResource(); | ||
break; | ||
default: /* nope */ | ||
} | ||
else | ||
switch (this.httpMethod) { | ||
// resource | ||
case 'GET': | ||
request = this.getResources(); | ||
break; | ||
case 'POST': | ||
request = this.postResources(); | ||
break; | ||
case 'PUT': | ||
request = this.putResources(); | ||
break; | ||
case 'DELETE': | ||
request = this.deleteResources(); | ||
break; | ||
case 'PATCH': | ||
request = this.patchResources(); | ||
break; | ||
case 'HEAD': | ||
request = this.headResources(); | ||
break; | ||
default: /* nope */ | ||
} | ||
// execute the API request | ||
if (!request) this.done(new Error(`E.COMMON.UNSUPPORTED_ACTION`)); | ||
else { | ||
IdeaX.logger('REQUEST', null, this.httpMethod, true); | ||
request.then((res: any) => this.done(null, res)).catch((err: Error) => this.done(err)); | ||
} | ||
}) | ||
.catch(() => this.done(new Error(`E.COMMON.UNAUTHORIZED`))); | ||
} | ||
@@ -130,3 +157,3 @@ /** | ||
statusCode: err ? '400' : '200', | ||
body: err ? JSON.stringify({ message: err.message }) : JSON.stringify(res || {}), | ||
body: err ? JSON.stringify({ message: err.message }) : JSON.stringify(res || {}), | ||
headers: { 'Content-Type': 'application/json', 'Access-Control-Allow-Origin': '*' } | ||
@@ -139,3 +166,3 @@ }); | ||
protected getResource(): Promise<any> { | ||
return new Promise((resolve, reject) => reject(new Error(`E.COMMON.UNSUPPORTED_ACTION`))); | ||
return new Promise((_, reject) => reject(new Error(`E.COMMON.UNSUPPORTED_ACTION`))); | ||
} | ||
@@ -146,3 +173,3 @@ /** | ||
protected postResource(): Promise<any> { | ||
return new Promise((resolve, reject) => reject(new Error(`E.COMMON.UNSUPPORTED_ACTION`))); | ||
return new Promise((_, reject) => reject(new Error(`E.COMMON.UNSUPPORTED_ACTION`))); | ||
} | ||
@@ -153,3 +180,3 @@ /** | ||
protected putResource(): Promise<any> { | ||
return new Promise((resolve, reject) => reject(new Error(`E.COMMON.UNSUPPORTED_ACTION`))); | ||
return new Promise((_, reject) => reject(new Error(`E.COMMON.UNSUPPORTED_ACTION`))); | ||
} | ||
@@ -160,3 +187,3 @@ /** | ||
protected deleteResource(): Promise<any> { | ||
return new Promise((resolve, reject) => reject(new Error(`E.COMMON.UNSUPPORTED_ACTION`))); | ||
return new Promise((_, reject) => reject(new Error(`E.COMMON.UNSUPPORTED_ACTION`))); | ||
} | ||
@@ -167,3 +194,3 @@ /** | ||
protected headResource(): Promise<any> { | ||
return new Promise((resolve, reject) => reject(new Error(`E.COMMON.UNSUPPORTED_ACTION`))); | ||
return new Promise((_, reject) => reject(new Error(`E.COMMON.UNSUPPORTED_ACTION`))); | ||
} | ||
@@ -174,3 +201,3 @@ /** | ||
protected getResources(): Promise<any> { | ||
return new Promise((resolve, reject) => reject(new Error(`E.COMMON.UNSUPPORTED_ACTION`))); | ||
return new Promise((_, reject) => reject(new Error(`E.COMMON.UNSUPPORTED_ACTION`))); | ||
} | ||
@@ -181,3 +208,3 @@ /** | ||
protected postResources(): Promise<any> { | ||
return new Promise((resolve, reject) => reject(new Error(`E.COMMON.UNSUPPORTED_ACTION`))); | ||
return new Promise((_, reject) => reject(new Error(`E.COMMON.UNSUPPORTED_ACTION`))); | ||
} | ||
@@ -188,3 +215,3 @@ /** | ||
protected putResources(): Promise<any> { | ||
return new Promise((resolve, reject) => reject(new Error(`E.COMMON.UNSUPPORTED_ACTION`))); | ||
return new Promise((_, reject) => reject(new Error(`E.COMMON.UNSUPPORTED_ACTION`))); | ||
} | ||
@@ -195,3 +222,3 @@ /** | ||
protected patchResource(): Promise<any> { | ||
return new Promise((resolve, reject) => reject(new Error(`E.COMMON.UNSUPPORTED_ACTION`))); | ||
return new Promise((_, reject) => reject(new Error(`E.COMMON.UNSUPPORTED_ACTION`))); | ||
} | ||
@@ -202,3 +229,3 @@ /** | ||
protected patchResources(): Promise<any> { | ||
return new Promise((resolve, reject) => reject(new Error(`E.COMMON.UNSUPPORTED_ACTION`))); | ||
return new Promise((_, reject) => reject(new Error(`E.COMMON.UNSUPPORTED_ACTION`))); | ||
} | ||
@@ -209,3 +236,3 @@ /** | ||
protected deleteResources(): Promise<any> { | ||
return new Promise((resolve, reject) => reject(new Error(`E.COMMON.UNSUPPORTED_ACTION`))); | ||
return new Promise((_, reject) => reject(new Error(`E.COMMON.UNSUPPORTED_ACTION`))); | ||
} | ||
@@ -216,8 +243,8 @@ /** | ||
protected headResources(): Promise<any> { | ||
return new Promise((resolve, reject) => reject(new Error(`E.COMMON.UNSUPPORTED_ACTION`))); | ||
return new Promise((_, reject) => reject(new Error(`E.COMMON.UNSUPPORTED_ACTION`))); | ||
} | ||
/// | ||
/// AWS SERVICES | ||
/// | ||
/// | ||
/// AWS SERVICES | ||
/// | ||
get dynamoDB(): DynamoDB { | ||
@@ -259,5 +286,5 @@ if (!this._dynamoDB) this._dynamoDB = new DynamoDB(); | ||
/// | ||
/// HELPERS | ||
/// | ||
/// | ||
/// HELPERS | ||
/// | ||
@@ -273,15 +300,19 @@ /** | ||
// insert the log and don't wait for response or errors | ||
this.dynamoDB.put({ TableName: this.tables.requestsLogs, Item: <RequestLog> { | ||
key: key, | ||
at: String(new Date().getTime()).concat('_'.concat(UUIDV4())), | ||
expiresAt: Math.round(expiresAt.getTime() / 1000), | ||
userId: this.principalId || null, | ||
resource: this.resource, | ||
resourceId: this.resourceId || null, | ||
method: this.httpMethod, | ||
action: this.body && this.body.action ? this.body.action : null, | ||
requestSucceeded: success | ||
}}) | ||
.then(() => {}) | ||
.catch(() => {}); | ||
this.dynamoDB | ||
.put({ | ||
TableName: this.tables.requestsLogs, | ||
Item: <RequestLog>{ | ||
key: key, | ||
at: String(new Date().getTime()).concat('_'.concat(UUIDV4())), | ||
expiresAt: Math.round(expiresAt.getTime() / 1000), | ||
userId: this.principalId || null, | ||
resource: this.resource, | ||
resourceId: this.resourceId || null, | ||
method: this.httpMethod, | ||
action: this.body && this.body.action ? this.body.action : null, | ||
requestSucceeded: success | ||
} | ||
}) | ||
.then(() => {}) | ||
.catch(() => {}); | ||
} | ||
@@ -288,0 +319,0 @@ } |
@@ -8,3 +8,3 @@ import AWS = require('aws-sdk'); | ||
export class S3 { | ||
protected s3: any; | ||
protected s3: AWS.S3; | ||
@@ -40,3 +40,11 @@ protected DEFAULT_DOWNLOAD_BUCKET_PREFIX = 'common'; | ||
// if needed, randomly generates the key | ||
if (!options.key) options.key = new Date().getTime().toString().concat(Math.random().toString(36).slice(2)); | ||
if (!options.key) | ||
options.key = new Date() | ||
.getTime() | ||
.toString() | ||
.concat( | ||
Math.random() | ||
.toString(36) | ||
.slice(2) | ||
); | ||
// add the prefix to the key | ||
@@ -48,10 +56,15 @@ options.key = `${options.prefix || this.DEFAULT_DOWNLOAD_BUCKET_PREFIX}/${options.key}`; | ||
// upload the file to the downloads bucket | ||
this.s3.upload({ | ||
Bucket: options.bucket, Key: options.key, Body: data, ContentType: options.contentType | ||
}, | ||
(err: Error, d: any) => { | ||
IdeaX.logger('S3 UPLOAD', err, d); | ||
if (err) reject(err); | ||
else resolve(this.signedURLGet(options.bucket, options.key, options.secToExp)); | ||
}); | ||
this.s3.upload( | ||
{ | ||
Bucket: options.bucket, | ||
Key: options.key, | ||
Body: data, | ||
ContentType: options.contentType | ||
}, | ||
(err: Error, d: any) => { | ||
IdeaX.logger('S3 UPLOAD', err, d); | ||
if (err) reject(err); | ||
else resolve(this.signedURLGet(options.bucket, options.key, options.secToExp)); | ||
} | ||
); | ||
}); | ||
@@ -70,3 +83,5 @@ } | ||
url: this.s3.getSignedUrl('putObject', { | ||
Bucket: bucket, Key: key, Expires: expires || this.DEFAULT_UPLOAD_BUCKET_SEC_TO_EXP | ||
Bucket: bucket, | ||
Key: key, | ||
Expires: expires || this.DEFAULT_UPLOAD_BUCKET_SEC_TO_EXP | ||
}) | ||
@@ -86,3 +101,5 @@ }; | ||
url: this.s3.getSignedUrl('getObject', { | ||
Bucket: bucket, Key: key, Expires: expires || this.DEFAULT_DOWNLOAD_BUCKET_SEC_TO_EXP | ||
Bucket: bucket, | ||
Key: key, | ||
Expires: expires || this.DEFAULT_DOWNLOAD_BUCKET_SEC_TO_EXP | ||
}) | ||
@@ -104,8 +121,10 @@ }; | ||
return new Promise((resolve, reject) => { | ||
this.s3.copyObject({ CopySource: options.copySource, Bucket: options.bucket, Key: options.key }, | ||
(err: Error, d: any) => { | ||
IdeaX.logger('S3 COPY OBJECT', err, d); | ||
if (err) reject(err); | ||
else resolve(); | ||
}); | ||
this.s3.copyObject( | ||
{ CopySource: options.copySource, Bucket: options.bucket, Key: options.key }, | ||
(err: Error, d: any) => { | ||
IdeaX.logger('S3 COPY OBJECT', err, d); | ||
if (err) reject(err); | ||
else resolve(); | ||
} | ||
); | ||
}); | ||
@@ -115,3 +134,3 @@ } | ||
/** | ||
* Get an object from an S3 bucket. | ||
* Get an object from a S3 bucket. | ||
* @param {any} options strucuted as follows | ||
@@ -127,13 +146,43 @@ ``` | ||
return new Promise((resolve, reject) => { | ||
this.s3.getObject({ Bucket: options.bucket, Key: options.key }, | ||
(err: Error, d: any) => { | ||
this.s3.getObject({ Bucket: options.bucket, Key: options.key }, (err: Error, d: any) => { | ||
IdeaX.logger('S3 GET OBJECT', err, d); | ||
if (err) reject(err); | ||
else switch (options.type) { | ||
case 'JSON': resolve(JSON.parse(d.Body.toString('utf-8'))); break; | ||
default: resolve(d); | ||
} | ||
else | ||
switch (options.type) { | ||
case 'JSON': | ||
resolve(JSON.parse(d.Body.toString('utf-8'))); | ||
break; | ||
default: | ||
resolve(d); | ||
} | ||
}); | ||
}); | ||
} | ||
/** | ||
* Put an object in a S3 bucket. | ||
* @param {any} options strucuted as follows | ||
``` | ||
bucket: string; // the bucket in which to copy the file. | ||
key; string; // the complete filepath of the bucket in which to copy the file | ||
body: any; // the content of the file | ||
contentType?: string; // content type (e.g. image/png) | ||
acl?: string; // access-control list (e.g. public-read) | ||
metadata?: any; // a set of metadata as attributes | ||
``` | ||
* @return {Promise<any>} | ||
*/ | ||
public putObject(options?: any): Promise<any> { | ||
return new Promise((resolve, reject) => { | ||
const params: any = { Bucket: options.bucket, Key: options.key, Body: options.body }; | ||
if (options.contentType) params.ContentType = options.contentType; | ||
if (options.acl) params.ACL = options.acl; | ||
if (options.metadata) params.Metadata = options.metadata; | ||
this.s3.putObject(params, (err: Error, d: any) => { | ||
IdeaX.logger('S3 PUT OBJECT', err, d); | ||
if (err) reject(err); | ||
else resolve(d); | ||
}); | ||
}); | ||
} | ||
} | ||
@@ -140,0 +189,0 @@ |
@@ -37,7 +37,5 @@ import AWS = require('aws-sdk'); | ||
// if the email includes attachments, send through Nodemailer | ||
if (emailData.attachments && emailData.attachments.length) | ||
return this.sendEmailNodemailer(emailData, sesParams); | ||
if (emailData.attachments && emailData.attachments.length) return this.sendEmailNodemailer(emailData, sesParams); | ||
// otherwise via SES (more secure) | ||
else | ||
return this.sendEmailSES(emailData, sesParams); | ||
else return this.sendEmailSES(emailData, sesParams); | ||
} | ||
@@ -60,4 +58,3 @@ /** | ||
if (emailData.text) sesData.Message.Body.Text = { Charset: 'UTF-8', Data: emailData.text }; | ||
if (!emailData.html && !emailData.text) | ||
sesData.Message.Body.Text = { Charset: 'UTF-8', Data: '' }; | ||
if (!emailData.html && !emailData.text) sesData.Message.Body.Text = { Charset: 'UTF-8', Data: '' }; | ||
sesData.ReplyToAddresses = emailData.replyToAddresses; | ||
@@ -68,4 +65,3 @@ sesData.Source = `${sesParams.sourceName} <${sesParams.source}>`; | ||
// send email | ||
new AWS.SES({ region: sesParams.region }) | ||
.sendEmail(sesData, (err: Error, data: any) => { | ||
new AWS.SES({ region: sesParams.region }).sendEmail(sesData, (err: Error, data: any) => { | ||
IdeaX.logger('SES SEND EMAIL', err, JSON.stringify(data)); | ||
@@ -95,11 +91,12 @@ if (err) reject(err); | ||
// create Nodemailer SES transporter and send the email | ||
Nodemailer | ||
.createTransport({ SES: new AWS.SES({ region: sesParams.region }) }) | ||
.sendMail(mailOptions, (err: Error, data: any) => { | ||
IdeaX.logger('SES SEND EMAIL (NODEMAILER)', err, data); | ||
if (err) reject(err); | ||
else resolve(data); | ||
}); | ||
Nodemailer.createTransport({ SES: new AWS.SES({ region: sesParams.region }) }).sendMail( | ||
mailOptions, | ||
(err: Error, data: any) => { | ||
IdeaX.logger('SES SEND EMAIL (NODEMAILER)', err, data); | ||
if (err) reject(err); | ||
else resolve(data); | ||
} | ||
); | ||
}); | ||
} | ||
} |
@@ -24,5 +24,3 @@ import AWS = require('aws-sdk'); | ||
*/ | ||
public createPushPlatormEndpoint( | ||
platform: string, deviceId: string, snsParams: any | ||
): Promise<string> { | ||
public createPushPlatormEndpoint(platform: string, deviceId: string, snsParams: any): Promise<string> { | ||
return new Promise((resolve, reject) => { | ||
@@ -32,13 +30,20 @@ let platformARN; | ||
switch (platform) { | ||
case 'APNS': platformARN = snsParams.pushiOS; break; | ||
case 'FCM': platformARN = snsParams.pushAndroid; break; | ||
default: return reject(new Error(`UNSUPPORTED_PLATFORM`)); | ||
case 'APNS': | ||
platformARN = snsParams.pushiOS; | ||
break; | ||
case 'FCM': | ||
platformARN = snsParams.pushAndroid; | ||
break; | ||
default: | ||
return reject(new Error(`UNSUPPORTED_PLATFORM`)); | ||
} | ||
// create a new endpoint in the platform | ||
this.sns.createPlatformEndpoint({ PlatformApplicationArn: platformARN, Token: deviceId }, | ||
(err: Error, data: any) => { | ||
IdeaX.logger('SNS ADD PLATFORM ENDPOINT', err, data); | ||
if (err || !data.EndpointArn) reject(err); | ||
else resolve(data.EndpointArn); | ||
}); | ||
this.sns.createPlatformEndpoint( | ||
{ PlatformApplicationArn: platformARN, Token: deviceId }, | ||
(err: Error, data: any) => { | ||
IdeaX.logger('SNS ADD PLATFORM ENDPOINT', err, data); | ||
if (err || !data.EndpointArn) reject(err); | ||
else resolve(data.EndpointArn); | ||
} | ||
); | ||
}); | ||
@@ -60,17 +65,23 @@ } | ||
structuredMessage = { APNS: JSON.stringify({ aps: { alert: message } }) }; | ||
break; | ||
break; | ||
case 'FCM': | ||
structuredMessage = { GCM: JSON.stringify({ data: { message: message } }) }; | ||
break; | ||
default: return reject(new Error(`UNSUPPORTED_PLATFORM`)); | ||
break; | ||
default: | ||
return reject(new Error(`UNSUPPORTED_PLATFORM`)); | ||
} | ||
this.sns.publish({ | ||
MessageStructure: 'json', Message: JSON.stringify(structuredMessage), TargetArn: endpoint | ||
}, (err: Error, data: any) => { | ||
IdeaX.logger('SNS PUSH NOTIFICATION', err, data); | ||
if (err) reject(err); | ||
else resolve(data); | ||
}); | ||
this.sns.publish( | ||
{ | ||
MessageStructure: 'json', | ||
Message: JSON.stringify(structuredMessage), | ||
TargetArn: endpoint | ||
}, | ||
(err: Error, data: any) => { | ||
IdeaX.logger('SNS PUSH NOTIFICATION', err, data); | ||
if (err) reject(err); | ||
else resolve(data); | ||
} | ||
); | ||
}); | ||
} | ||
} |
@@ -14,8 +14,10 @@ { | ||
"rootDir": "./src", | ||
"outDir": "./dist", | ||
"outDir": "./dist" | ||
}, | ||
"exclude": [ "node_modules", "dist" ], | ||
"plugins": [{ | ||
"name": "typescript-tslint-plugin" | ||
}] | ||
"exclude": ["node_modules", "dist"], | ||
"plugins": [ | ||
{ | ||
"name": "typescript-tslint-plugin" | ||
} | ||
] | ||
} |
@@ -7,6 +7,3 @@ { | ||
"class-name": true, | ||
"comment-format": [ | ||
true, | ||
"check-space" | ||
], | ||
"comment-format": [true, "check-space"], | ||
"curly": false, | ||
@@ -19,12 +16,6 @@ "deprecation": { | ||
"import-spacing": true, | ||
"indent": [ | ||
true, | ||
"spaces" | ||
], | ||
"indent": [true, "spaces"], | ||
"interface-over-type-literal": true, | ||
"label-position": true, | ||
"max-line-length": [ | ||
true, | ||
120 | ||
], | ||
"max-line-length": [true, 120], | ||
"member-access": true, | ||
@@ -34,8 +25,3 @@ "member-ordering": [ | ||
{ | ||
"order": [ | ||
"static-field", | ||
"instance-field", | ||
"static-method", | ||
"instance-method" | ||
] | ||
"order": ["static-field", "instance-field", "static-method", "instance-method"] | ||
} | ||
@@ -45,10 +31,3 @@ ], | ||
"no-bitwise": true, | ||
"no-console": [ | ||
true, | ||
"debug", | ||
"info", | ||
"time", | ||
"timeEnd", | ||
"trace" | ||
], | ||
"no-console": [true, "debug", "info", "time", "timeEnd", "trace"], | ||
"no-construct": true, | ||
@@ -60,6 +39,3 @@ "no-debugger": true, | ||
"no-eval": true, | ||
"no-inferrable-types": [ | ||
true, | ||
"ignore-params" | ||
], | ||
"no-inferrable-types": [true, "ignore-params"], | ||
"no-misused-new": true, | ||
@@ -77,23 +53,8 @@ "no-non-null-assertion": true, | ||
"object-literal-sort-keys": false, | ||
"one-line": [ | ||
true, | ||
"check-open-brace", | ||
"check-catch", | ||
"check-else", | ||
"check-whitespace" | ||
], | ||
"one-line": [true, "check-open-brace", "check-catch", "check-else", "check-whitespace"], | ||
"prefer-const": true, | ||
"quotemark": [ | ||
true, | ||
"single" | ||
], | ||
"quotemark": [true, "single"], | ||
"radix": true, | ||
"semicolon": [ | ||
true, | ||
"always" | ||
], | ||
"triple-equals": [ | ||
true, | ||
"allow-null-check" | ||
], | ||
"semicolon": [true, "always"], | ||
"triple-equals": [true, "allow-null-check"], | ||
"typedef-whitespace": [ | ||
@@ -111,23 +72,5 @@ true, | ||
"variable-name": false, | ||
"whitespace": [ | ||
true, | ||
"check-branch", | ||
"check-decl", | ||
"check-operator", | ||
"check-separator", | ||
"check-type" | ||
], | ||
"directive-selector": [ | ||
true, | ||
"attribute", | ||
"app", | ||
"camelCase" | ||
], | ||
"component-selector": [ | ||
true, | ||
"element", | ||
"app", | ||
"page", | ||
"kebab-case" | ||
], | ||
"whitespace": [true, "check-branch", "check-decl", "check-operator", "check-separator", "check-type"], | ||
"directive-selector": [true, "attribute", "app", "camelCase"], | ||
"component-selector": [true, "element", "app", "page", "kebab-case"], | ||
"no-output-on-prefix": true, | ||
@@ -134,0 +77,0 @@ "use-input-property-decorator": true, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
4002228
5338
23
2
12