@ntegral/lulu
Advanced tools
Comparing version 1.2.2 to 1.2.3
@@ -19,3 +19,3 @@ import * as request from 'request'; | ||
init: () => Promise<any>; | ||
authorizeHeader(data: IAuthenticationResponse): request.Headers; | ||
authorizeHeader(data: IAuthenticationResponse): Promise<request.Headers>; | ||
getToken(): Promise<any>; | ||
@@ -22,0 +22,0 @@ refreshToken(data: IAuthenticationResponse): Promise<void>; |
@@ -63,8 +63,16 @@ "use strict"; | ||
authorizeHeader(data) { | ||
const headers = this.defaultHeaders; | ||
this.decoded = jwt.decode(data.access_token, { complete: true }); | ||
if (typeof headers.Authorization === 'undefined') { | ||
headers.Authorization = 'Bearer ' + data.access_token; | ||
} | ||
return headers; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const headers = this.defaultHeaders; | ||
try { | ||
this.decoded = jwt.decode(data.access_token, { complete: true }); | ||
} | ||
catch (err) { | ||
console.log('signature has expired', err); | ||
yield this.getToken(); | ||
} | ||
if (typeof headers.Authorization === 'undefined') { | ||
headers.Authorization = 'Bearer ' + data.access_token; | ||
} | ||
return headers; | ||
}); | ||
} | ||
@@ -85,9 +93,9 @@ getToken() { | ||
}; | ||
return yield rp(this.url, opts).then((result) => { | ||
return yield rp(this.url, opts).then((result) => __awaiter(this, void 0, void 0, function* () { | ||
if (result.access_token) { | ||
this.authorizeHeader(result); | ||
yield this.authorizeHeader(result); | ||
this.isAuthenticated = true; | ||
} | ||
return result; | ||
}).catch(this.handleError); | ||
})).catch(this.handleError); | ||
}); | ||
@@ -110,9 +118,9 @@ } | ||
}; | ||
rp(this.url, opts).then((result) => { | ||
rp(this.url, opts).then((result) => __awaiter(this, void 0, void 0, function* () { | ||
if (result.access_token) { | ||
this.authorizeHeader(result); | ||
yield this.authorizeHeader(result); | ||
this.isAuthenticated = true; | ||
} | ||
return result; | ||
}).catch(this.handleError); | ||
})).catch(this.handleError); | ||
}); | ||
@@ -119,0 +127,0 @@ } |
@@ -67,3 +67,3 @@ import * as request from 'request'; | ||
*/ | ||
authorizeHeader(data: IAuthenticationResponse) { | ||
async authorizeHeader(data: IAuthenticationResponse) { | ||
// merge access token with default headers | ||
@@ -73,3 +73,8 @@ const headers = this.defaultHeaders; | ||
// let decoded: any = jwt.decode(data.access_token, { complete: true }); | ||
this.decoded = jwt.decode(data.access_token, { complete: true }); | ||
try { | ||
this.decoded = jwt.decode(data.access_token, { complete: true }); | ||
} catch (err) { | ||
console.log('signature has expired', err); | ||
await this.getToken(); | ||
} | ||
// console.log('expire', moment.unix(this.decoded.payload.exp)); | ||
@@ -104,6 +109,6 @@ | ||
return await rp(this.url, opts).then((result) => { | ||
return await rp(this.url, opts).then(async(result) => { | ||
if (result.access_token) { | ||
// console.log('authentication successful', result.token_type); | ||
this.authorizeHeader(result); | ||
await this.authorizeHeader(result); | ||
this.isAuthenticated = true; | ||
@@ -145,6 +150,6 @@ } | ||
rp(this.url, opts).then((result) => { | ||
rp(this.url, opts).then(async(result) => { | ||
if (result.access_token) { | ||
// console.log('authentication successful', result.token_type); | ||
this.authorizeHeader(result); | ||
await this.authorizeHeader(result); | ||
this.isAuthenticated = true; | ||
@@ -151,0 +156,0 @@ } |
@@ -10,3 +10,3 @@ { | ||
"name": "@ntegral/lulu", | ||
"version": "1.2.2", | ||
"version": "1.2.3", | ||
"description": "Lulu Print API Client", | ||
@@ -13,0 +13,0 @@ "main": "./dist/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
51124
1343