@koopjs/output-geoservices
Advanced tools
Comparing version 7.1.9 to 8.0.0
{ | ||
"name": "@koopjs/output-geoservices", | ||
"version": "7.1.9", | ||
"version": "8.0.0", | ||
"description": "Wraps FeatureServer as a Koop output plugin", | ||
@@ -35,3 +35,3 @@ "main": "src/index.js", | ||
"dependencies": { | ||
"@koopjs/featureserver": "8.1.9", | ||
"@koopjs/featureserver": "8.2.0", | ||
"@koopjs/logger": "5.0.0" | ||
@@ -41,2 +41,3 @@ }, | ||
"coverageReporters": [ | ||
"json-summary", | ||
"json", | ||
@@ -43,0 +44,0 @@ "text", |
105
README.md
@@ -23,55 +23,66 @@ # Koop Geoservices Output Plugin | ||
## Routes | ||
## Options | ||
### `defaults (Object)` | ||
The `defaults` options allows the setting of some FeatureServer metadata properties. The `defaults` option should be an object with some of the following properties: | ||
```js | ||
Geoservices.routes = [ | ||
{ | ||
path: '$namespace/rest/info', | ||
methods: ['get', 'post'], | ||
handler: 'featureServerRestInfo' | ||
}, | ||
{ | ||
path: '$namespace/tokens/:method', | ||
methods: ['get', 'post'], | ||
handler: 'generateToken' | ||
}, | ||
{ | ||
path: '$namespace/tokens/', | ||
methods: ['get', 'post'], | ||
handler: 'generateToken' | ||
}, | ||
{ | ||
path: '$namespace/rest/services/$providerParams/FeatureServer/:layer/:method', | ||
methods: ['get', 'post'], | ||
handler: 'featureServer' | ||
}, | ||
{ | ||
path: '$namespace/rest/services/$providerParams/FeatureServer/layers', | ||
methods: ['get', 'post'], | ||
handler: 'featureServer' | ||
}, | ||
{ | ||
path: '$namespace/rest/services/$providerParams/FeatureServer/:layer', | ||
methods: ['get', 'post'], | ||
handler: 'featureServer' | ||
}, | ||
{ | ||
path: '$namespace/rest/services/$providerParams/FeatureServer', | ||
methods: ['get', 'post'], | ||
handler: 'featureServer' | ||
}, | ||
{ | ||
path: '$namespace/rest/services/$providerParams/FeatureServer*', | ||
methods: ['get', 'post'], | ||
handler: 'featureServer' | ||
}, | ||
{ | ||
path: '$namespace/rest/services/$providerParams/MapServer*', | ||
methods: ['get', 'post'], | ||
handler: 'featureServer' | ||
{ | ||
defaults: { | ||
currentVersion, // number (11.2) | ||
fullVersion, // string ('11.2.0') | ||
maxRecordCount, // number (500) | ||
server: { | ||
serviceDescription, // string ('Default text for serviceDescription') | ||
description, // string ('Default text for description') | ||
copyrightText, // string ('Default text for copyright') | ||
hasStaticData, // boolean (true) | ||
spatialReference, // object (Esri spatial reference) | ||
initialExtent, // object (Esri spatial envelope) | ||
fullExtent, // object (Esri spatial envelope) | ||
}, | ||
layer: { | ||
description, // string ('Default text for layer description') | ||
copyrightText, // string ('Default text for layer copyright') | ||
extent, // object (Esri spatial envelope) | ||
}, | ||
} | ||
] | ||
} | ||
``` | ||
Note that the `defaults` option only overrides FeatureServer's defaults. Providers that set metadata may override values set by the above `defaults` properties. | ||
### `useHttpForTokenUrl (boolean)` | ||
The `rest/info` route generates a property `tokenServicesUrl` with value for the URL to use when requesting a token. By default the protocol for this URL is `https`, but if you require it to be `http` set the value of this option to `true`. | ||
```js | ||
{ | ||
useHttpForTokenUrl: true | ||
} | ||
``` | ||
### `logger (Logger)` | ||
You can leverage your own custom logger instance, but it must adhere to the Winston logger specification. | ||
```js | ||
{ | ||
logger // some custom Logger instance | ||
} | ||
``` | ||
## Routes | ||
```js | ||
<provider-namespace>/rest/info | ||
<provider-namespace>/rest/generateToken | ||
<provider-namespace>/rest/services/<provider-path-params>/FeatureServer/:layer/:method | ||
<provider-namespace>/rest/services/<provider-path-params>/FeatureServer/layers | ||
<provider-namespace>/rest/services/<provider-path-params>/FeatureServer/:layer | ||
<provider-namespace>/rest/services/<provider-path-params>/FeatureServer | ||
<provider-namespace>/rest/services/<provider-path-params>/FeatureServer* | ||
<provider-namespace>/rest/services/<provider-path-params>/MapServer* | ||
``` | ||
[npm-img]: https://img.shields.io/npm/v/@koopjs/output-geoservices.svg?style=flat-square | ||
[npm-url]: https://www.npmjs.com/package/@koopjs/output-geoservices |
@@ -20,3 +20,4 @@ const { promisify } = require('util'); | ||
message: 'Token Required', | ||
details: [], | ||
messageCode: 'GWM_0003', | ||
details: ['Token Required'], | ||
}, | ||
@@ -43,4 +44,6 @@ }; | ||
class GeoServices { | ||
#useHttp = false; | ||
#useHttpForTokenUrl = false; | ||
#authInfo; | ||
#pullData; | ||
#logger; | ||
@@ -56,3 +59,3 @@ static type = 'output'; | ||
{ | ||
path: '$namespace/tokens/:method', | ||
path: '$namespace/rest/generateToken', | ||
methods: ['get', 'post'], | ||
@@ -62,7 +65,2 @@ handler: 'generateToken', | ||
{ | ||
path: '$namespace/tokens/', | ||
methods: ['get', 'post'], | ||
handler: 'generateToken', | ||
}, | ||
{ | ||
path: '$namespace/rest/services/$providerParams/FeatureServer/:layer/:method', | ||
@@ -102,10 +100,11 @@ methods: ['get', 'post'], | ||
this.#pullData = promisify(this.model.pull).bind(this.model); | ||
this.options = options; | ||
this.logger = options.logger || logger; | ||
this.authInfo = options.authInfo || {}; | ||
this.#useHttp = | ||
this.model.authenticationSpecification?.useHttp === true || | ||
process.env.KOOP_AUTH_HTTP === 'true'; | ||
FeatureServer.setLogger({ logger: this.logger }); | ||
this.#logger = options.logger || logger; | ||
this.#authInfo = options.authInfo || { | ||
isTokenBasedSecurity: true, | ||
}; | ||
this.#useHttpForTokenUrl = this.#getHttpSetting(options, model); | ||
FeatureServer.setLogger({ logger: this.#logger }); | ||
// Set overrides | ||
@@ -115,14 +114,31 @@ FeatureServer.setDefaults(options.defaults); | ||
#getHttpSetting(options, model) { | ||
if (options.useHttpForTokenUrl || process.env.GEOSERVICES_HTTP === 'true') { | ||
return ( | ||
options.useHttpForTokenUrl || process.env.GEOSERVICES_HTTP === 'true' | ||
); | ||
} | ||
if (typeof model.authenticationSpecification === 'function') { | ||
return model.authenticationSpecification()?.useHttp === true; | ||
} | ||
if (typeof process.env.KOOP_AUTH_HTTP !== 'undefined') { | ||
this.#logger.warn( | ||
'Use of "KOOP_AUTH_HTTP" environment variable is deprecated. It will be removed in a future release. Use the "useHttpForTokenUrl" option or "GEOSERVICES_HTTP" environment variable.', | ||
); | ||
return process.env.KOOP_AUTH_HTTP === 'true'; | ||
} | ||
return false; | ||
} | ||
async generalHandler(req, res) { | ||
try { | ||
if (this.#shouldAuthorize()) { | ||
await this.model.authorize(req); | ||
} | ||
const data = await this.#pullData(req); | ||
return FeatureServer.route(req, res, data); | ||
} catch (error) { | ||
this.logger.error(error); | ||
this.#logger.error(error); | ||
const token = this.#getToken(req); | ||
const token = this.#extractTokenFromRequest(req); | ||
const { code, message, details = [] } = normalizeError(error); | ||
@@ -154,7 +170,3 @@ | ||
#shouldAuthorize() { | ||
return typeof this.model.authorize === 'function'; | ||
} | ||
#getToken(req) { | ||
#extractTokenFromRequest(req) { | ||
const { | ||
@@ -174,7 +186,5 @@ headers: { authorization }, | ||
restInfoHandler(req, res) { | ||
const authInfo = { ...this.authInfo }; | ||
const authInfo = { ...this.#authInfo }; | ||
if (this.model.authenticationSpecification) { | ||
authInfo.isTokenBasedSecurity = true; | ||
if (this.#authInfo.isTokenBasedSecurity) { | ||
authInfo.tokenServicesUrl = this.#buildTokensUrl( | ||
@@ -186,22 +196,21 @@ req.headers.host, | ||
FeatureServer.route(req, res, { authInfo }); | ||
FeatureServer.route(req, res, { owningSystemUrl: this.#buildOwningSystemUrl(req.headers.host, | ||
req.baseUrl), authInfo }); | ||
} | ||
#buildTokensUrl(host, baseUrl) { | ||
const protocol = this.#useHttp ? 'http' : 'https'; | ||
return `${protocol}://${host}${baseUrl}/${this.model.namespace}/tokens/`; | ||
const protocol = this.#useHttpForTokenUrl ? 'http' : 'https'; | ||
return `${protocol}://${host}${baseUrl}/${this.model.namespace}/rest/generateToken`; | ||
} | ||
#buildOwningSystemUrl(host, baseUrl) { | ||
const protocol = this.#useHttpForTokenUrl ? 'http' : 'https'; | ||
return `${protocol}://${host}${baseUrl}/${this.model.namespace}`; | ||
} | ||
async generateToken(req, res) { | ||
if (typeof this.model.authenticate !== 'function') { | ||
return res | ||
.status(500) | ||
.json({ error: '"authenticate" not implemented for this provider' }); | ||
} | ||
try { | ||
//const decodedToken = await this.model.authorize(req); | ||
const tokenResponse = await this.model.authenticate(req); | ||
res | ||
.status(200) | ||
.json({ ...tokenResponse, ssl: tokenResponse.ssl || false }); | ||
res.status(200).json(tokenResponse); | ||
} catch (error) { | ||
@@ -208,0 +217,0 @@ const { code, message, details = [] } = normalizeError(error); |
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
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
10988
211
87
4
+ Added@koopjs/featureserver@8.2.0(transitive)
- Removed@koopjs/featureserver@8.1.9(transitive)
Updated@koopjs/featureserver@8.2.0