Registry / http-networking / geostyler-wfs-parser

geostyler-wfs-parser

JSON →
library3.0.1jsnpmunverified

GeoStyler WFS Parser is an npm package that provides a robust implementation of a GeoStyler Data Parser specifically designed for interacting with Web Feature Services (WFS). Currently at stable version 3.0.1, the library sees active development with recent releases, including major updates in July 2024. Its primary function is to read and interpret data from WFS endpoints, converting it into a GeoStyler-compatible data structure for further styling and manipulation within the GeoStyler ecosystem. A key differentiator is its tight integration into the GeoStyler project, offering a standardized approach to WFS data consumption. Users should note that for successful operation, the target WFS service must support `application/json` as an output format, and its application server needs to be configured to send CORS headers if the WFS service is hosted on a different origin than the consuming application. The package ships with TypeScript types, facilitating robust development.

npm install geostyler-wfs-parser
INSTALL
IMPORT
SIG · GEOSTYLER-WFS-PARS
G
geostyler-wfs-parser
http-networkingjavascriptv3.0.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

WfsParser
import { WfsParser } from 'geostyler-wfs-parser';
const WfsParser = require('geostyler-wfs-parser');
Since v3.0.0, the package is ESM-only. CommonJS `require()` is no longer supported.
WfsParser
import WfsParser from 'geostyler-wfs-parser/dist/WfsParser';
While named imports are preferred, direct path imports might be used in specific bundler configurations prior to v3.0.0. Since v3.0.0, the main export path is recommended.
Data
import { Data } from 'geostyler';
While not directly from `geostyler-wfs-parser`, the `Data` type from the core `geostyler` package is commonly used when interacting with the parser's output for type safety.

This quickstart demonstrates how to instantiate the WfsParser and use its `read` method to fetch and parse data from a WFS service, logging the resulting GeoStyler-compatible data object. It highlights the use of `requestParams` and the necessity of `application/json` output.

import { WfsParser } from 'geostyler-wfs-parser'; import { Data } from 'geostyler'; // Import GeoStyler Data type for type safety async function parseWfsData(): Promise<void> { const wfsParser = new WfsParser(); // Replace with a valid WFS GetCapabilities URL that supports application/json output const wfsUrl = process.env.WFS_SERVICE_URL ?? 'https://your-wfs-server.com/geoserver/wfs'; try { // The `read` method fetches and parses WFS data. // `requestParams` is required since v2.0.0 to specify WFS parameters. const { data }: { data: Data } = await wfsParser.read(wfsUrl, { requestParams: { version: '1.1.0', // Specify WFS version typeName: 'feature:my_layer', // Replace with your target layer's typeName outputFormat: 'application/json' // Essential for this parser } }); console.log('Successfully parsed WFS Data:'); console.log(JSON.stringify(data, null, 2)); // 'data' now contains GeoStyler-compatible feature data } catch (error) { console.error('Failed to parse WFS data:', error instanceof Error ? error.message : error); } } parseWfsData();
Debug
Known issues
breakingVersion 3.0.0 switched to an ESM-only build. Projects using CommonJS `require()` will need to migrate to `import` statements and may require bundler configuration adjustments (e.g., for Webpack, Vite).
fix
Migrate your project to use ES modules (`import ... from '...'`) instead of CommonJS `require()`. Adjust your bundler configuration to correctly resolve ESM dependencies.
affects: >=3.0.0
breakingVersion 2.0.0 introduced the `requestParams` object. All request-related arguments (like `version`, `typeName`, `maxFeatures`) previously passed directly to the `read` method were moved into this nested object.
fix
Update calls to the `read` method. Instead of `parser.read(url, version, typeName)`, use `parser.read(url, { requestParams: { version, typeName } })`.
affects: >=2.0.0
gotchaThe `geostyler-wfs-parser` library requires the target WFS service to support `application/json` as an output format for its GetFeature or DescribeFeatureType requests.
fix
Ensure your WFS service is configured to provide JSON output. If not, the parser will fail to interpret the response. You might need to adjust the `outputFormat` in `requestParams` if the service supports other JSON variants.
affects: >=1.0.0
gotchaWhen consuming a WFS service from a different origin (domain, protocol, port) than your application, the WFS application server must be configured to send appropriate CORS (Cross-Origin Resource Sharing) headers.
fix
If encountering network errors related to cross-origin access, contact the administrator of the WFS service to ensure it has CORS enabled for your client's origin. Alternatively, consider proxying the WFS requests through your own backend.
affects: >=1.0.0
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module ... not supported.
Attempting to import `geostyler-wfs-parser` using CommonJS `require()` syntax in a Node.js or bundler environment after v3.0.0.
fix
Change `const WfsParser = require('geostyler-wfs-parser');` to `import { WfsParser } from 'geostyler-wfs-parser';`. Ensure your project's `package.json` has `"type": "module"` or that your build system is configured for ESM.
TypeError: Cannot read properties of undefined (reading 'version') at WfsParser.read
Calling the `read` method after v2.0.0 without wrapping request parameters in the `requestParams` object.
fix
Refactor your `read` method call. Instead of `parser.read(url, { version: '1.1.0' })`, use `parser.read(url, { requestParams: { version: '1.1.0' } })`.
Error: Network request failed, status 0
A common browser error indicating a CORS policy block when the WFS service is on a different origin without proper CORS headers.
fix
Verify that the WFS service's server is configured to include `Access-Control-Allow-Origin` headers that permit requests from your application's origin. Alternatively, use a proxy server to forward requests.
Error: Failed to parse WFS data: Unexpected token '<', "<ows:Exception" is not valid JSON
The WFS service returned an XML error message or an unsupported format instead of `application/json` as expected.
fix
Ensure the `outputFormat` in your `requestParams` is correctly set to `application/json` and that the WFS service truly supports this format. Check the network tab in your browser's developer tools for the actual response from the WFS server.
Upgrade
Version history
3.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources