lightapp-platform-common
Advanced tools
Comparing version
@@ -10,9 +10,3 @@ { | ||
"type": "string" | ||
}, | ||
"AuthToken": { | ||
"type": "string" | ||
} | ||
}, | ||
@@ -19,0 +13,0 @@ "required": [ |
@@ -13,5 +13,2 @@ { | ||
"type": "string" | ||
}, | ||
"authToken": { | ||
"type": "string" | ||
} | ||
@@ -22,5 +19,4 @@ }, | ||
"firstName", | ||
"lastName", | ||
"authToken" | ||
"lastName" | ||
] | ||
} |
@@ -15,17 +15,4 @@ { | ||
}, | ||
"type": {}, | ||
"children": { | ||
"type": "array", | ||
"items": { | ||
"$ref": "file:common/model/schemas/Enumeration.schema.json" | ||
} | ||
}, | ||
"Meters": { | ||
"type": "array", | ||
"items": { | ||
"$ref": "file:common/model/schemas/IMeter.schema.json" | ||
} | ||
}, | ||
"MetaData": { | ||
"type": "string" | ||
"type": { | ||
"$ref": "file:common/model/schemas/SystemType.schema.json" | ||
} | ||
@@ -32,0 +19,0 @@ }, |
{ | ||
"name": "lightapp-platform-common", | ||
"version": "2.0.30", | ||
"version": "2.0.31", | ||
"description": "common utilities for lightapp platform", | ||
@@ -11,3 +11,5 @@ "main": "index.js", | ||
"@types/jsonschema": "^1.1.1", | ||
"@types/jsonwebtoken": "^8.3.0", | ||
"amazon-cognito-identity-js": "^3.0.3", | ||
"jsonwebtoken": "^8.4.0", | ||
"pg": "^7.6.1" | ||
@@ -14,0 +16,0 @@ }, |
@@ -9,7 +9,7 @@ "use strict"; | ||
constructor() { | ||
console.log(`instantiating cognito with poolData: ${JSON.stringify(config.poolData)}...`); | ||
console.debug(`Instantiating Cognito with identify pool: ${JSON.stringify(config.poolData)}...`); | ||
this.cognitoUserPoolData = config.poolData; | ||
} | ||
signOut(username) { | ||
console.log(`sign out username: ${username}...`); | ||
console.log(`Singing out username: ${username}...`); | ||
let cognitoUserPool = new amazon_cognito_identity_js_1.CognitoUserPool(this.cognitoUserPoolData); | ||
@@ -31,3 +31,3 @@ const userData = { | ||
}; | ||
console.log(`start Cognito signUp with userInfo: ${JSON.stringify(userInfo)}`); | ||
console.log(`Signing up user: ${JSON.stringify(userInfo)}`); | ||
let userAttributes = []; | ||
@@ -40,3 +40,3 @@ let validationData = []; | ||
userAttributes.push(cognitoUserAttribute); | ||
console.log(`userAttributes: ${JSON.stringify(userAttributes)}`); | ||
console.debug(`userAttributes: ${JSON.stringify(userAttributes)}`); | ||
cognitoUserPool = new amazon_cognito_identity_js_1.CognitoUserPool(this.cognitoUserPoolData); | ||
@@ -50,3 +50,3 @@ } | ||
const { userName, password } = userInfo; | ||
console.log(`before cognitoUserPool.signUp... username: ${userName}, password: ${password}`); | ||
console.debug(`before cognitoUserPool.signUp... username: ${userName}, password: ${password}`); | ||
cognitoUserPool.signUp(userName, password, userAttributes, validationData, (err, res) => { | ||
@@ -65,5 +65,4 @@ if (err) { | ||
signIn(username, password, callBack) { | ||
console.log(`start Cognito login with username: ${username}, password: ${password}`); | ||
console.log(`Attempting to login with username: ${username}, password: ${password}`); | ||
let _result; | ||
console.log(`trying to instantiate new CognitoUserPool using poolData: : ${JSON.stringify(this.cognitoUserPoolData)}`); | ||
let cognitoUserPool = new amazon_cognito_identity_js_1.CognitoUserPool(this.cognitoUserPoolData); | ||
@@ -79,24 +78,13 @@ const userData = { | ||
}); | ||
try { | ||
cognitoUser.authenticateUser(authenticationDetails, { | ||
onSuccess: (res) => { | ||
const idToken = res.getIdToken().getJwtToken(); | ||
const authData = { | ||
Username: username, | ||
Password: password, | ||
AuthToken: idToken | ||
}; | ||
_result = Result_2.getResult(Result_1.StatusCode.OK, authData); | ||
callBack(null, _result); | ||
console.log('end sign in Cognito user'); | ||
}, | ||
onFailure: (err) => { | ||
_result = Result_2.getResult(Result_1.StatusCode.BAD_REQUEST, err); | ||
callBack(Result_2.getError(err, 'fail in cognitoUser.authenticateUser'), _result); | ||
} | ||
}); | ||
} | ||
catch (ex) { | ||
console.log('could not authenticate user:' + ex); | ||
} | ||
cognitoUser.authenticateUser(authenticationDetails, { | ||
onSuccess: (res) => { | ||
const idToken = res.getIdToken().getJwtToken(); | ||
_result = Result_2.getResult(Result_1.StatusCode.OK, 'login success', { Authorization: idToken }); | ||
callBack(null, _result); | ||
}, | ||
onFailure: (err) => { | ||
_result = Result_2.getResult(Result_1.StatusCode.BAD_REQUEST, err); | ||
callBack(Result_2.getError(err, 'Login in has failed'), _result); | ||
} | ||
}); | ||
} | ||
@@ -106,3 +94,3 @@ confirmRegistration(userName, verificationCode, callBack) { | ||
let _result; | ||
console.log(`start confirmRegistration for userName: ${userName}, verificationCode: ${verificationCode}`); | ||
console.log(`Confirming registration for username: ${userName} with verificationCode: ${verificationCode}`); | ||
const cognitoUserPool = new amazon_cognito_identity_js_1.CognitoUserPool(this.cognitoUserPoolData); | ||
@@ -116,3 +104,3 @@ const userData = { | ||
if (err) { | ||
_error = Result_2.getError(err, 'fail in cognitoUser.confirmRegistration'); | ||
_error = Result_2.getError(err, 'User registration failed'); | ||
_result = Result_2.getResult(Result_1.StatusCode.BAD_REQUEST, err); | ||
@@ -119,0 +107,0 @@ callBack(_error, _result); |
@@ -12,5 +12,6 @@ "use strict"; | ||
exports.getError = (error, details) => { | ||
let result = `${details}: ${JSON.stringify(error)}`; | ||
let internalError = { error: JSON.stringify(error), details: details }; | ||
let result = JSON.stringify(internalError); | ||
console.error(result); | ||
return result; | ||
}; |
27647
31.11%49
25.64%709
22.03%5
66.67%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added