@podium/client
Advanced tools
Comparing version 3.0.5 to 3.0.6
@@ -9,2 +9,9 @@ # Changelog | ||
## [3.0.6] - 2019-03-27 | ||
- Clean up kill switch - [#25](https://github.com/podium-lib/client/pull/25) | ||
- Reworked state to HttpOutgoing - [#22](https://github.com/podium-lib/client/pull/22) | ||
- Updated @podium/utils to version 3.1.2 - [#21](https://github.com/podium-lib/client/pull/21) | ||
- Updated other dependencies | ||
## [3.0.5] - 2019-03-15 | ||
@@ -58,3 +65,4 @@ | ||
[unreleased]: https://github.com/podium-lib/client/compare/v3.0.5...HEAD | ||
[unreleased]: https://github.com/podium-lib/client/compare/v3.0.6...HEAD | ||
[3.0.6]: https://github.com/podium-lib/client/compare/v3.0.5...v3.0.6 | ||
[3.0.5]: https://github.com/podium-lib/client/compare/v3.0.4...v3.0.5 | ||
@@ -61,0 +69,0 @@ [3.0.4]: https://github.com/podium-lib/client/compare/v3.0.3...v3.0.4 |
@@ -30,12 +30,12 @@ /* eslint-disable no-plusplus */ | ||
load(state) { | ||
load(outgoing) { | ||
return new Promise(resolve => { | ||
if (state.status !== 'stale') { | ||
const cached = this.registry.get(state.resourceName); | ||
if (outgoing.status !== 'stale') { | ||
const cached = this.registry.get(outgoing.name); | ||
if (cached) { | ||
state.manifest = clonedeep(cached); | ||
state.status = 'cached'; | ||
outgoing.manifest = clonedeep(cached); | ||
outgoing.status = 'cached'; | ||
this.log.debug( | ||
`loaded manifest from cache - resource: ${ | ||
state.resourceName | ||
outgoing.name | ||
}`, | ||
@@ -45,24 +45,24 @@ ); | ||
} | ||
resolve(state); | ||
resolve(outgoing); | ||
}); | ||
} | ||
save(state) { | ||
save(outgoing) { | ||
return new Promise(resolve => { | ||
if (state.status === 'fresh') { | ||
if (outgoing.status === 'fresh') { | ||
this.registry.set( | ||
state.resourceName, | ||
state.manifest, | ||
state.maxAge, | ||
outgoing.name, | ||
outgoing.manifest, | ||
outgoing.maxAge, | ||
); | ||
this.log.debug( | ||
`saved manifest to cache - resource: ${state.resourceName}`, | ||
`saved manifest to cache - resource: ${outgoing.name}`, | ||
); | ||
} | ||
state.killRecursions++; | ||
outgoing.recursions++; | ||
resolve(state); | ||
resolve(outgoing); | ||
}); | ||
} | ||
}; |
@@ -40,14 +40,11 @@ /* eslint-disable no-param-reassign */ | ||
resolve(state) { | ||
resolve(outgoing) { | ||
return new Promise((resolve, reject) => { | ||
if ( | ||
state.killRecursions === state.killThreshold && | ||
state.throwable | ||
) { | ||
if (outgoing.kill && outgoing.throwable) { | ||
this.log.warn( | ||
`recursion detected - failed to resolve fetching of podlet ${ | ||
state.killRecursions | ||
outgoing.recursions | ||
} times - throwing - resource: ${ | ||
state.resourceName | ||
} - url: ${state.manifestUri}`, | ||
outgoing.name | ||
} - url: ${outgoing.manifestUri}`, | ||
); | ||
@@ -57,3 +54,3 @@ reject( | ||
`Recursion detected - failed to resolve fetching of podlet ${ | ||
state.killRecursions | ||
outgoing.recursions | ||
} times`, | ||
@@ -64,14 +61,15 @@ ), | ||
} | ||
if (state.killRecursions === state.killThreshold) { | ||
if (outgoing.kill) { | ||
this.log.warn( | ||
`recursion detected - failed to resolve fetching of podlet ${ | ||
state.killRecursions | ||
outgoing.recursions | ||
} times - serving fallback - resource: ${ | ||
state.resourceName | ||
} - url: ${state.manifestUri}`, | ||
outgoing.name | ||
} - url: ${outgoing.manifestUri}`, | ||
); | ||
state.success = true; | ||
outgoing.success = true; | ||
pipeline( | ||
state.fallbackStream(), | ||
state.stream, | ||
outgoing.fallbackStream(), | ||
outgoing.stream, | ||
(err) => { | ||
@@ -81,3 +79,3 @@ if (err) { | ||
} | ||
resolve(state); | ||
resolve(outgoing); | ||
} | ||
@@ -88,7 +86,7 @@ ); | ||
if (state.status === 'empty' && state.throwable) { | ||
if (outgoing.status === 'empty' && outgoing.throwable) { | ||
this.log.warn( | ||
`no manifest available - cannot read content - throwing - resource: ${ | ||
state.resourceName | ||
} - url: ${state.manifestUri}`, | ||
outgoing.name | ||
} - url: ${outgoing.manifestUri}`, | ||
); | ||
@@ -102,12 +100,13 @@ reject( | ||
} | ||
if (state.status === 'empty') { | ||
if (outgoing.status === 'empty') { | ||
this.log.warn( | ||
`no manifest available - cannot read content - serving fallback - resource: ${ | ||
state.resourceName | ||
} - url: ${state.manifestUri}`, | ||
outgoing.name | ||
} - url: ${outgoing.manifestUri}`, | ||
); | ||
state.success = true; | ||
outgoing.success = true; | ||
pipeline( | ||
state.fallbackStream(), | ||
state.stream, | ||
outgoing.fallbackStream(), | ||
outgoing.stream, | ||
(err) => { | ||
@@ -117,3 +116,3 @@ if (err) { | ||
} | ||
resolve(state); | ||
resolve(outgoing); | ||
} | ||
@@ -124,3 +123,3 @@ ); | ||
const headers = Object.assign({}, state.reqOptions.headers, { | ||
const headers = Object.assign({}, outgoing.reqOptions.headers, { | ||
'User-Agent': UA_STRING, | ||
@@ -131,12 +130,12 @@ }); | ||
headers, | ||
state.reqOptions.podiumContext, | ||
state.resourceName, | ||
outgoing.reqOptions.podiumContext, | ||
outgoing.name, | ||
); | ||
const reqOptions = { | ||
timeout: state.timeout, | ||
timeout: outgoing.timeout, | ||
method: 'GET', | ||
agent: this.agent, | ||
uri: state.contentUri, | ||
qs: state.reqOptions.query, | ||
uri: outgoing.contentUri, | ||
qs: outgoing.reqOptions.query, | ||
headers, | ||
@@ -157,4 +156,4 @@ }; | ||
`start reading content from remote resource - manifest version is ${ | ||
state.manifest.version | ||
} - resource: ${state.resourceName} - url: ${state.contentUri}`, | ||
outgoing.manifest.version | ||
} - resource: ${outgoing.name} - url: ${outgoing.contentUri}`, | ||
); | ||
@@ -168,3 +167,3 @@ | ||
const resError = response.statusCode !== 200; | ||
if (resError && state.throwable) { | ||
if (resError && outgoing.throwable) { | ||
timer({ | ||
@@ -181,4 +180,4 @@ meta: { | ||
response.statusCode | ||
} - resource: ${state.resourceName} - url: ${ | ||
state.contentUri | ||
} - resource: ${outgoing.name} - url: ${ | ||
outgoing.contentUri | ||
}`, | ||
@@ -192,3 +191,3 @@ ); | ||
response.statusCode | ||
} on ${state.contentUri}`, | ||
} on ${outgoing.contentUri}`, | ||
), | ||
@@ -214,10 +213,10 @@ { | ||
response.statusCode | ||
} - resource: ${state.resourceName} - url: ${ | ||
state.contentUri | ||
} - resource: ${outgoing.name} - url: ${ | ||
outgoing.contentUri | ||
}`, | ||
); | ||
state.success = true; | ||
outgoing.success = true; | ||
pipeline( | ||
state.fallbackStream(), | ||
state.stream, | ||
outgoing.fallbackStream(), | ||
outgoing.stream, | ||
(err) => { | ||
@@ -227,3 +226,3 @@ if (err) { | ||
} | ||
resolve(state); | ||
resolve(outgoing); | ||
} | ||
@@ -244,4 +243,4 @@ ); | ||
response.headers['podlet-version'] | ||
} - resource: ${state.resourceName} - url: ${ | ||
state.contentUri | ||
} - resource: ${outgoing.name} - url: ${ | ||
outgoing.contentUri | ||
}`, | ||
@@ -251,3 +250,3 @@ ); | ||
if ( | ||
contentVersion !== state.manifest.version && | ||
contentVersion !== outgoing.manifest.version && | ||
contentVersion !== undefined | ||
@@ -265,13 +264,13 @@ ) { | ||
`podlet version number in header differs from cached version number - aborting request to remote resource for content - resource: ${ | ||
state.resourceName | ||
} - url: ${state.contentUri}`, | ||
outgoing.name | ||
} - url: ${outgoing.contentUri}`, | ||
); | ||
r.abort(); | ||
state.status = 'stale'; | ||
outgoing.status = 'stale'; | ||
return; | ||
} | ||
state.success = true; | ||
state.stream.emit('headers', response.headers); | ||
pipeline(r, state.stream, | ||
outgoing.success = true; | ||
outgoing.stream.emit('headers', response.headers); | ||
pipeline(r, outgoing.stream, | ||
(err) => { | ||
@@ -291,3 +290,3 @@ if (err) { | ||
// Network error | ||
if (state.throwable) { | ||
if (outgoing.throwable) { | ||
timer({ | ||
@@ -303,8 +302,8 @@ meta: { | ||
`could not create network connection to remote resource when trying to request content - resource: ${ | ||
state.resourceName | ||
} - url: ${state.contentUri}`, | ||
outgoing.name | ||
} - url: ${outgoing.contentUri}`, | ||
); | ||
reject( | ||
boom.badGateway( | ||
`Error reading content at ${state.contentUri}`, | ||
`Error reading content at ${outgoing.contentUri}`, | ||
error, | ||
@@ -326,10 +325,10 @@ ), | ||
`could not create network connection to remote resource when trying to request content - resource: ${ | ||
state.resourceName | ||
} - url: ${state.contentUri}`, | ||
outgoing.name | ||
} - url: ${outgoing.contentUri}`, | ||
); | ||
state.success = true; | ||
outgoing.success = true; | ||
pipeline( | ||
state.fallbackStream(), | ||
state.stream, | ||
outgoing.fallbackStream(), | ||
outgoing.stream, | ||
(err) => { | ||
@@ -339,3 +338,3 @@ if (err) { | ||
} | ||
resolve(state); | ||
resolve(outgoing); | ||
} | ||
@@ -356,7 +355,7 @@ ); | ||
`successfully read content from remote resource - resource: ${ | ||
state.resourceName | ||
} - url: ${state.contentUri}`, | ||
outgoing.name | ||
} - url: ${outgoing.contentUri}`, | ||
); | ||
resolve(state); | ||
resolve(outgoing); | ||
}); | ||
@@ -363,0 +362,0 @@ }); |
@@ -36,3 +36,3 @@ /* eslint-disable no-param-reassign */ | ||
resolve(state) { | ||
resolve(outgoing) { | ||
return new Promise(resolve => { | ||
@@ -45,3 +45,3 @@ const timer = this.metrics.timer({ | ||
if (state.status === 'cached') { | ||
if (outgoing.status === 'cached') { | ||
timer({ | ||
@@ -53,3 +53,3 @@ meta: { | ||
}); | ||
resolve(state); | ||
resolve(outgoing); | ||
return; | ||
@@ -61,3 +61,3 @@ } | ||
// Do not set fallback so we can serve any previous fallback we might have | ||
if (state.manifest.fallback === undefined) { | ||
if (outgoing.manifest.fallback === undefined) { | ||
timer({ | ||
@@ -69,3 +69,3 @@ meta: { | ||
}); | ||
resolve(state); | ||
resolve(outgoing); | ||
return; | ||
@@ -76,9 +76,9 @@ } | ||
// Set fallback to empty string | ||
if (state.manifest.fallback === '') { | ||
if (outgoing.manifest.fallback === '') { | ||
this.log.debug( | ||
`no fallback defined in manifest - resource: ${ | ||
state.resourceName | ||
outgoing.name | ||
}`, | ||
); | ||
state.fallback = ''; | ||
outgoing.fallback = ''; | ||
timer({ | ||
@@ -90,3 +90,3 @@ meta: { | ||
}); | ||
resolve(state); | ||
resolve(outgoing); | ||
return; | ||
@@ -101,6 +101,6 @@ } | ||
const reqOptions = { | ||
timeout: state.timeout, | ||
timeout: outgoing.timeout, | ||
method: 'GET', | ||
agent: this.agent, | ||
uri: state.fallbackUri, | ||
uri: outgoing.fallbackUri, | ||
headers, | ||
@@ -112,4 +112,4 @@ }; | ||
`start reading fallback content from remote resource - resource: ${ | ||
state.resourceName | ||
} - url: ${state.fallbackUri}`, | ||
outgoing.name | ||
} - url: ${outgoing.fallbackUri}`, | ||
); | ||
@@ -128,8 +128,8 @@ | ||
`could not create network connection to remote resource for fallback content - resource: ${ | ||
state.resourceName | ||
} - url: ${state.fallbackUri}`, | ||
outgoing.name | ||
} - url: ${outgoing.fallbackUri}`, | ||
); | ||
state.fallback = ''; | ||
resolve(state); | ||
outgoing.fallback = ''; | ||
resolve(outgoing); | ||
return; | ||
@@ -151,9 +151,9 @@ } | ||
res.statusCode | ||
} - resource: ${state.resourceName} - url: ${ | ||
state.fallbackUri | ||
} - resource: ${outgoing.name} - url: ${ | ||
outgoing.fallbackUri | ||
}`, | ||
); | ||
state.fallback = ''; | ||
resolve(state); | ||
outgoing.fallback = ''; | ||
resolve(outgoing); | ||
return; | ||
@@ -171,10 +171,10 @@ } | ||
// Set fallback to the fetched content | ||
state.fallback = body; | ||
outgoing.fallback = body; | ||
this.log.debug( | ||
`successfully read fallback from remote resource - resource: ${ | ||
state.resourceName | ||
} - url: ${state.fallbackUri}`, | ||
outgoing.name | ||
} - url: ${outgoing.fallbackUri}`, | ||
); | ||
resolve(state); | ||
resolve(outgoing); | ||
}); | ||
@@ -181,0 +181,0 @@ }); |
@@ -56,5 +56,5 @@ 'use strict'; | ||
resolve(state) { | ||
resolve(outgoing) { | ||
return this.cache | ||
.load(state) | ||
.load(outgoing) | ||
.then(obj => this.manifest.resolve(obj)) | ||
@@ -72,5 +72,5 @@ .then(obj => this.fallback.resolve(obj)) | ||
refresh(state) { | ||
refresh(outgoing) { | ||
return this.manifest | ||
.resolve(state) | ||
.resolve(outgoing) | ||
.then(obj => this.fallback.resolve(obj)) | ||
@@ -77,0 +77,0 @@ .then(obj => this.cache.save(obj)) |
@@ -40,6 +40,6 @@ /* eslint-disable no-param-reassign */ | ||
resolve(state) { | ||
resolve(outgoing) { | ||
return new Promise(resolve => { | ||
if (state.status === 'cached') { | ||
resolve(state); | ||
if (outgoing.status === 'cached') { | ||
resolve(outgoing); | ||
return; | ||
@@ -53,7 +53,7 @@ } | ||
const reqOptions = { | ||
timeout: state.timeout, | ||
timeout: outgoing.timeout, | ||
method: 'GET', | ||
agent: this.agent, | ||
json: true, | ||
uri: state.manifestUri, | ||
uri: outgoing.manifestUri, | ||
headers, | ||
@@ -75,4 +75,4 @@ }; | ||
`start reading manifest from remote resource - resource: ${ | ||
state.resourceName | ||
} - url: ${state.manifestUri}`, | ||
outgoing.name | ||
} - url: ${outgoing.manifestUri}`, | ||
); | ||
@@ -92,6 +92,6 @@ | ||
`could not create network connection to remote manifest - resource: ${ | ||
state.resourceName | ||
} - url: ${state.manifestUri}`, | ||
outgoing.name | ||
} - url: ${outgoing.manifestUri}`, | ||
); | ||
resolve(state); | ||
resolve(outgoing); | ||
return; | ||
@@ -114,7 +114,7 @@ } | ||
res.statusCode | ||
} - resource: ${state.resourceName} - url: ${ | ||
state.manifestUri | ||
} - resource: ${outgoing.name} - url: ${ | ||
outgoing.manifestUri | ||
}`, | ||
); | ||
resolve(state); | ||
resolve(outgoing); | ||
return; | ||
@@ -137,6 +137,6 @@ } | ||
`could not parse manifest - resource: ${ | ||
state.resourceName | ||
} - url: ${state.manifestUri}`, | ||
outgoing.name | ||
} - url: ${outgoing.manifestUri}`, | ||
); | ||
resolve(state); | ||
resolve(outgoing); | ||
return; | ||
@@ -166,6 +166,6 @@ } | ||
`remote resource has cache header which yelds a max age of ${maxAge}ms, using this as cache ttl - resource: ${ | ||
state.resourceName | ||
} - url: ${state.manifestUri}`, | ||
outgoing.name | ||
} - url: ${outgoing.manifestUri}`, | ||
); | ||
state.maxAge = maxAge; | ||
outgoing.maxAge = maxAge; | ||
} | ||
@@ -177,3 +177,3 @@ | ||
manifest.value.fallback, | ||
state.manifestUri, | ||
outgoing.manifestUri, | ||
); | ||
@@ -184,18 +184,18 @@ } | ||
manifest.value.content, | ||
state.manifestUri, | ||
state.reqOptions.pathname, | ||
outgoing.manifestUri, | ||
outgoing.reqOptions.pathname, | ||
); | ||
// Build absolute css and js URIs if configured to do so | ||
if (state.resolveCss) { | ||
if (outgoing.resolveCss) { | ||
manifest.value.assets.css = utils.uriRelativeToAbsolute( | ||
manifest.value.assets.css, | ||
state.manifestUri, | ||
outgoing.manifestUri, | ||
); | ||
} | ||
if (state.resolveJs) { | ||
if (outgoing.resolveJs) { | ||
manifest.value.assets.js = utils.uriRelativeToAbsolute( | ||
manifest.value.assets.js, | ||
state.manifestUri, | ||
outgoing.manifestUri, | ||
); | ||
@@ -208,15 +208,15 @@ } | ||
manifest.value.proxy[key], | ||
state.manifestUri, | ||
outgoing.manifestUri, | ||
); | ||
}); | ||
state.manifest = manifest.value; | ||
state.status = 'fresh'; | ||
outgoing.manifest = manifest.value; | ||
outgoing.status = 'fresh'; | ||
this.log.debug( | ||
`successfully read manifest from remote resource - resource: ${ | ||
state.resourceName | ||
} - url: ${state.manifestUri}`, | ||
outgoing.name | ||
} - url: ${outgoing.manifestUri}`, | ||
); | ||
resolve(state); | ||
resolve(outgoing); | ||
}); | ||
@@ -223,0 +223,0 @@ }); |
@@ -9,4 +9,4 @@ /* eslint-disable no-param-reassign */ | ||
const assert = require('assert'); | ||
const HttpOutgoing = require('./http-outgoing'); | ||
const Resolver = require('./resolver'); | ||
const State = require('./state'); | ||
@@ -69,3 +69,3 @@ function decoratePodletName(podletName) { | ||
fetch(podiumContext, options = {}) { | ||
const state = new State( | ||
const outgoing = new HttpOutgoing( | ||
this.options, | ||
@@ -79,7 +79,7 @@ { | ||
return this.resolver.resolve(state).then(obj => obj.content); | ||
return this.resolver.resolve(outgoing).then(obj => obj.content); | ||
} | ||
stream(podiumContext, options = {}) { | ||
const state = new State( | ||
const outgoing = new HttpOutgoing( | ||
this.options, | ||
@@ -93,11 +93,11 @@ { | ||
this.resolver.resolve(state).then(() => { | ||
this.resolver.resolve(outgoing).then(() => { | ||
// console.log('stream success'); | ||
}); | ||
return state.stream; | ||
return outgoing.stream; | ||
} | ||
refresh(podiumContext = {}, options = {}) { | ||
const state = new State( | ||
const outgoing = new HttpOutgoing( | ||
this.options, | ||
@@ -111,4 +111,4 @@ { | ||
return this.resolver.refresh(state).then(obj => obj); | ||
return this.resolver.refresh(outgoing).then(obj => obj); | ||
} | ||
}; |
@@ -36,1 +36,2 @@ 'use strict'; | ||
}; | ||
{ | ||
"name": "@podium/client", | ||
"version": "3.0.5", | ||
"version": "3.0.6", | ||
"main": "lib/client.js", | ||
@@ -38,3 +38,3 @@ "license": "MIT", | ||
"@podium/schemas": "3.0.0", | ||
"@podium/utils": "3.1.1", | ||
"@podium/utils": "3.1.2", | ||
"abslog": "2.4.0", | ||
@@ -41,0 +41,0 @@ "boom": "^7.3.0", |
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
65620
1211
+ Added@podium/utils@3.1.2(transitive)
- Removed@podium/utils@3.1.1(transitive)
Updated@podium/utils@3.1.2