@ntegral/lulu
Advanced tools
Comparing version 1.3.4 to 1.3.5
@@ -50,22 +50,14 @@ "use strict"; | ||
this.clock = moment(); | ||
console.log('clock', this.clock.toLocaleString()); | ||
let now = moment(); | ||
console.log('now', now.toLocaleString()); | ||
console.log('isAuthenticated: decoded', this.isAuthenticated, this.decoded); | ||
if (!this.isAuthenticated) { | ||
let result = yield this.getToken(); | ||
console.log('init...'); | ||
this.token = result; | ||
resolve(result); | ||
} | ||
if (this.isAuthenticated && this.decoded && now.isSameOrBefore(moment.unix(+this.decoded.payload.exp).subtract(55, 'minutes'))) { | ||
if (this.isAuthenticated && this.decoded && now.isSameOrBefore(moment.unix(+this.decoded.payload.exp).subtract(15, 'minutes'))) { | ||
let expiry = moment.unix(+this.decoded.payload.exp).toLocaleString(); | ||
console.log('expiry', expiry); | ||
console.log('refresh...'); | ||
console.log('token reused', this.token); | ||
let result = this.token; | ||
resolve(result); | ||
} | ||
if (this.isAuthenticated && this.decoded && now.isSameOrAfter(moment.unix(+this.decoded.payload.exp).subtract(55, 'minutes'))) { | ||
console.log('getting new token...'); | ||
if (this.isAuthenticated && this.decoded && now.isSameOrAfter(moment.unix(+this.decoded.payload.exp).subtract(15, 'minutes'))) { | ||
let result = yield this.getToken(); | ||
@@ -89,5 +81,2 @@ this.token = result; | ||
this.exp = this.decoded.payload.exp; | ||
console.log('exp', this.exp); | ||
let expiry = moment.unix(+this.exp).toLocaleString(); | ||
console.log('expiry', expiry); | ||
this.isAuthenticated = true; | ||
@@ -94,0 +83,0 @@ if (typeof headers.Authorization === 'undefined') { |
@@ -24,3 +24,2 @@ import * as request from 'request'; | ||
private isAuthenticated:boolean; | ||
// private initialization!: Promise<any>; | ||
private sandbox: string = 'https://api.sandbox.lulu.com'; | ||
@@ -47,31 +46,22 @@ private prod: string = 'https://api.lulu.com'; | ||
} | ||
// this.initialization = this.init(); | ||
} | ||
async init(): Promise<IAuthenticationResponse> { | ||
// console.log('clock', this.clock.to); | ||
return new Promise(async(resolve, reject) => { | ||
try { | ||
this.clock = moment(); | ||
console.log('clock', this.clock.toLocaleString()); | ||
let now = moment(); | ||
console.log('now', now.toLocaleString()); | ||
console.log('isAuthenticated: decoded', this.isAuthenticated, this.decoded); | ||
if (!this.isAuthenticated) { | ||
let result = await this.getToken(); | ||
console.log('init...'); | ||
this.token = result; | ||
// return result; | ||
resolve(result); | ||
} | ||
if (this.isAuthenticated && this.decoded && now.isSameOrBefore(moment.unix(+this.decoded.payload.exp).subtract(55,'minutes'))) { | ||
if (this.isAuthenticated && this.decoded && now.isSameOrBefore(moment.unix(+this.decoded.payload.exp).subtract(15,'minutes'))) { | ||
let expiry = moment.unix(+this.decoded.payload.exp).toLocaleString(); | ||
console.log('expiry',expiry); | ||
console.log('refresh...'); | ||
console.log('token reused', this.token); | ||
let result = this.token;// await this.refreshToken(this.token); | ||
resolve(result); | ||
} | ||
if (this.isAuthenticated && this.decoded && now.isSameOrAfter(moment.unix(+this.decoded.payload.exp).subtract(55,'minutes'))) { | ||
console.log('getting new token...'); | ||
if (this.isAuthenticated && this.decoded && now.isSameOrAfter(moment.unix(+this.decoded.payload.exp).subtract(15,'minutes'))) { | ||
let result = await this.getToken(); | ||
@@ -81,16 +71,2 @@ this.token = result; | ||
} | ||
/* let count = this.clock; | ||
if (this.isAuthenticated && this.decoded && now.isSameOrAfter(count.add(60,'seconds'))) { | ||
let result = await this.refreshToken(this.token); | ||
console.log('refreshing token...'); | ||
// return result; | ||
resolve(result); | ||
} | ||
if (this.isAuthenticated && this.decoded && moment.unix(+this.decoded.payload.exp).isAfter(now)) { // token has expired, get a new token // | ||
let result = await this.getToken(); | ||
this.token = result; | ||
console.log('renewing token...'); | ||
// return result; | ||
resolve(result); | ||
} */ | ||
} catch (error) { | ||
@@ -114,9 +90,5 @@ // throw new TypeError('Unable to initiate due to \n' + error); | ||
try { | ||
// data. | ||
this.decoded = jwt.decode(data.access_token, {json: true , complete:true}) as JwtDecodedResponse; | ||
// console.log('jwt decoded', this.decoded); | ||
this.exp = this.decoded.payload.exp; | ||
console.log('exp',this.exp); | ||
let expiry = moment.unix(+this.exp).toLocaleString(); | ||
console.log('expiry',expiry); | ||
this.isAuthenticated = true; | ||
@@ -135,23 +107,3 @@ | ||
resolve(headers); | ||
}) | ||
// let decoded: any = jwt.decode(data.access_token, { complete: true }); | ||
// try { | ||
// this.decoded = jwt.decode(data.access_token, { complete: true }) as JwtDecodedResponse; | ||
// console.log('jwt decoded', this.decoded); | ||
// this.exp = this.decoded.payload.exp; | ||
// let expiry = moment.unix(this.exp).toDate().toLocaleString(); | ||
// console.log('expiry',expiry); | ||
// this.isAuthenticated = true; | ||
// } catch (err) { | ||
// console.log('signature has expired', err); | ||
// await this.getToken(); | ||
// } | ||
// console.log('expire', moment.unix(this.decoded.payload.exp)); | ||
/* if (typeof headers.Authorization === 'undefined') { | ||
headers.Authorization = 'Bearer ' + data.access_token; | ||
} */ | ||
// add access_token, but don't overwrite if header already set | ||
// return headers; | ||
}); | ||
} | ||
@@ -185,15 +137,3 @@ | ||
}) | ||
}) | ||
/* | ||
return rp(this.url, opts).then(async(result: IAuthenticationResponse) => { | ||
if (result.access_token) { | ||
// console.log('authentication successful', result.token_type); | ||
await this.authorizeHeader(result); | ||
// this.isAuthenticated = true; | ||
} | ||
return result; | ||
}).catch(this.handleError); | ||
*/ | ||
}); | ||
} | ||
@@ -229,14 +169,2 @@ | ||
}); | ||
/* | ||
return rp(this.url, opts).then(async(result:IAuthenticationResponse) => { | ||
if (result.access_token) { | ||
// console.log('authentication successful', result.token_type); | ||
await this.authorizeHeader(result); | ||
// this.isAuthenticated = true; | ||
} | ||
return result; | ||
}).catch(this.handleError); | ||
*/ | ||
} | ||
@@ -250,5 +178,2 @@ | ||
async request(data: rp.OptionsWithUri): Promise<any> { | ||
// await this.initialization; | ||
// let status = await this.init(); | ||
// console.log('status of request', status); | ||
let status = await this.init(); | ||
@@ -273,3 +198,2 @@ return this.createRequest(data); | ||
let request: rp.OptionsWithUri = this.mergeData(this.defaultRequest, data); | ||
// console.log('authenticated', this.isAuthenticated); | ||
// add headers // | ||
@@ -284,4 +208,3 @@ request.headers = this.createHeaders(request.headers); | ||
}) | ||
}) | ||
// return rp(request); | ||
}); | ||
} | ||
@@ -288,0 +211,0 @@ |
@@ -10,3 +10,3 @@ { | ||
"name": "@ntegral/lulu", | ||
"version": "1.3.4", | ||
"version": "1.3.5", | ||
"description": "Lulu Print API Client", | ||
@@ -34,3 +34,2 @@ "main": "./dist/index.js", | ||
"dependencies": { | ||
"axios": "^0.19.2", | ||
"jsonwebtoken": "^8.5.1", | ||
@@ -42,3 +41,2 @@ "moment": "^2.24.0", | ||
"devDependencies": { | ||
"@types/axios": "^0.14.0", | ||
"@types/jest": "^24.9.1", | ||
@@ -45,0 +43,0 @@ "@types/jsonwebtoken": "^8.3.8", |
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
4
11
53892
1448
- Removedaxios@^0.19.2
- Removedaxios@0.19.2(transitive)
- Removedfollow-redirects@1.5.10(transitive)