geoserver-node-client 0.0.6 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -5,21 +5,62 @@
5
5
 
6
6
  Node.js / JavaScript Client for the [GeoServer REST API](https://docs.geoserver.org/stable/en/user/rest/).
7
7
 
8
- **CAUTION: This is highly bleeding edge, heavily under development and therefore breaking changes can be made at every time!**
9
-
10
8
  ### API-Docs ###
11
9
 
12
- Detailed API-Docs can be found [here](https://meggsimum.github.io/geoserver-node-client/index.html).
10
+ Detailed [API-Docs](https://meggsimum.github.io/geoserver-node-client/) are automatically created with JSDoc.
13
11
 
14
12
  ### Meta information
15
13
 
16
14
  Compatible with [GeoServer](https://geoserver.org)
17
15
 
16
+ - v2.21.x
18
17
  - v2.20.x
19
- - v2.19.x
18
+ - v2.19.x (no more maintained and officially deprecated)
20
19
  - v2.18.x (no more maintained and officially deprecated)
21
20
  - v2.17.x (no more maintained and officially deprecated)
22
21
 
22
+
23
+ ### Usage
24
+
25
+ ```shell
26
+ npm i geoserver-node-client
27
+ ```
28
+
29
+ usage with require (ES5):
30
+ ```js
31
+ const grcImport = require('geoserver-node-client');
32
+ const GeoServerRestClient = grcImport.GeoServerRestClient;
33
+
34
+ const url = 'http://localhost:8080/geoserver/rest/';
35
+ const user = 'admin';
36
+ const pw = 'geoserver';
37
+ const grc = new GeoServerRestClient(url, user, pw);
38
+
39
+ async function main () {
40
+ const result = await grc.about.exists();
41
+ console.log(result);
42
+ };
43
+
44
+ main();
45
+ ```
46
+
47
+ usage as ES module (ES6)
48
+ ```js
49
+ import {GeoServerRestClient} from 'geoserver-node-client';
50
+
51
+ const url = 'http://localhost:8080/geoserver/rest/';
52
+ const user = 'admin';
53
+ const pw = 'geoserver';
54
+ const grc = new GeoServerRestClient(url, user, pw);
55
+
56
+ async function main () {
57
+ const result = await grc.about.exists();
58
+ console.log(result);
59
+ };
60
+
61
+ main();
62
+ ```
63
+
23
64
  ### Setup
24
65
 
25
66
  Run as local checkout (mainly for development purposes)
@@ -34,6 +75,28 @@ npm install
34
75
  npm run demo
35
76
  ```
36
77
 
78
+ ### Error Handling
79
+
80
+ A request either succeeds or throws the custom `GeoServerResponseError`. It has the standard `message` property with a "human-readable" text. Additionally the error has the property `geoServerOutput` which contains the direct response from GeoServer. This output is not guaranteed to exist and can either be a simple text or a complete HTML document. The latter is difficult to read, but might still be helpful for debugging. This example shows how these error properties can be used. It also shows how to filter by error type:
81
+
82
+ ```javascript
83
+ try {
84
+ // call any function from this library
85
+ await grc.styles.publish(workspace, styleName, sldBody)
86
+ } catch (error) {
87
+ // the standard error message
88
+ console.error(error.message);
89
+
90
+ // the whole error including stack trace and (if available) the property 'geoServerOutput'
91
+ console.error(error);
92
+
93
+ if (error instanceof GeoServerResponseError) {
94
+ // a GeoServer specific error happened
95
+ } else {
96
+ // another error happened
97
+ }
98
+ }
99
+ ```
37
100
 
38
101
  ### Unit Tests
39
102
 
@@ -43,19 +106,23 @@ First start a GeoServer, e.g. by using this Docker container:
43
106
  docker run \
44
107
  -p 8080:8080 \
45
108
  -v /path/to/geoserver_mnt:/opt/geoserver_data \
46
- meggsimum/geoserver:2.20.1
109
+ meggsimum/geoserver:2.20.4
47
110
  ```
48
111
 
49
112
  Then, in an other terminal, run:
50
113
 
51
114
  ```shell
52
115
  # specify the GeoServer version and run the test suite
53
- GEOSERVER_VERSION=2.20.1 npm run test
116
+ GEOSERVER_VERSION=2.20.4 npm run test
54
117
  ```
55
118
 
56
119
  ### Release
57
120
 
58
- The release to GitHub and npm is done via [release-it](https://github.com/release-it/release-it). This is the workflow for releasing:
121
+ Setting a git tag and increasing the version in the `package.json` as well as releasing to npm is done via [release-it](https://github.com/release-it/release-it).
122
+
123
+ The GitHub release has to be performed manually based on the tag created by `release-it`.
124
+
125
+ This is the workflow for releasing:
59
126
 
60
127
  1. Make sure a `GITHUB_TOKEN` is available as environment variable. See [here](https://github.com/release-it/release-it/blob/master/docs/github-releases.md) for more information.
61
128
 
@@ -77,6 +144,9 @@ npm run release
77
144
  ```
78
145
 
79
146
  4. Follow the questions in the commandline.
147
+ - automatically upgrades the version in `package.json`
148
+ - makes a release commit and pushes it to GitHub
149
+ - publishes the new version to npm
80
150
 
81
151
  ### Who do I talk to? ###
82
152
 
@@ -84,8 +154,9 @@ npm run release
84
154
 
85
155
  ### Credits
86
156
 
87
- This project was initiated by [meggsimum](https://meggsimum.de) within the [mFund](https://www.bmvi.de/EN/Topics/Digital-Matters/mFund/mFund.html) research project [SAUBER](https://sauber-projekt.de/).
157
+ This project was initiated by [meggsimum](https://meggsimum.de) within the [mFund](https://www.bmvi.de/EN/Topics/Digital-Matters/mFund/mFund.html) research project [SAUBER](https://sauber-projekt.de/) and is further developed in the mFund research project [KLIPS](http://www.klips-projekt.de/):
88
158
  <p><img src="https://sauber-projekt.de/wp-content/uploads/2018/12/SAG_SAUBER_Logo_Dez3_transparent-1-e1543843688935.png" alt="SAUBER Logo" width="200"/></p>.
159
+ <p><img src="http://www.klips-projekt.de/wp-content/uploads/2021/02/SAG_KLIPS-Logo_Jan21.png" alt="KLIPS Logo" width="200"/></p>.
89
160
 
90
161
  <img src="https://sauber-projekt.de/wp-content/uploads/2018/12/mfund-logo-download-e1547545420815-300x77.jpg" alt="mFund Logo" width="300"/>
91
162
  <img src="https://sauber-projekt.de/wp-content/uploads/2019/06/BMVI_Fz_2017_Office_Farbe_de_Bundestag-400x402.png" alt="BMVI Logo" height="200"/>
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ Object.defineProperty(exports, "GeoServerResponseError", {
9
+ enumerable: true,
10
+ get: function get() {
11
+ return _geoserver.GeoServerResponseError;
12
+ }
13
+ });
14
+ exports.GeoServerRestClient = void 0;
15
+
16
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
17
+
18
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
19
+
20
+ var _layer = _interopRequireDefault(require("./src/layer.js"));
21
+
22
+ var _style = _interopRequireDefault(require("./src/style.js"));
23
+
24
+ var _workspace = _interopRequireDefault(require("./src/workspace.js"));
25
+
26
+ var _datastore = _interopRequireDefault(require("./src/datastore.js"));
27
+
28
+ var _imagemosaic = _interopRequireDefault(require("./src/imagemosaic.js"));
29
+
30
+ var _security = _interopRequireDefault(require("./src/security.js"));
31
+
32
+ var _settings = _interopRequireDefault(require("./src/settings.js"));
33
+
34
+ var _namespace = _interopRequireDefault(require("./src/namespace.js"));
35
+
36
+ var _about = _interopRequireDefault(require("./src/about.js"));
37
+
38
+ var _geoserver = require("./src/util/geoserver.js");
39
+
40
+ /**
41
+ * Client for GeoServer REST API.
42
+ * Has minimal basic functionality and offers REST client instances for
43
+ * sub-entities, like workspaces or datastores as member variables.
44
+ *
45
+ * @module GeoServerRestClient
46
+ */
47
+ var GeoServerRestClient = /*#__PURE__*/(0, _createClass2["default"])(
48
+ /**
49
+ * Creates a GeoServerRestClient instance.
50
+ *
51
+ * @param {String} url The URL of the GeoServer REST API endpoint
52
+ * @param {String} user The user for the GeoServer REST API
53
+ * @param {String} password The password for the GeoServer REST API
54
+ */
55
+ function GeoServerRestClient(url, user, password) {
56
+ (0, _classCallCheck2["default"])(this, GeoServerRestClient);
57
+ this.url = url.endsWith('/') ? url : url + '/';
58
+ this.auth = 'Basic ' + Buffer.from(user + ':' + password).toString('base64');
59
+ /** @member {LayerClient} layers GeoServer REST client instance for layers */
60
+
61
+ this.layers = new _layer["default"](this.url, this.auth);
62
+ /** @member {StyleClient} styles GeoServer REST client instance for styles */
63
+
64
+ this.styles = new _style["default"](this.url, this.auth);
65
+ /** @member {WorkspaceClient} workspaces GeoServer REST client instance for workspaces */
66
+
67
+ this.workspaces = new _workspace["default"](this.url, this.auth);
68
+ /** @member {NamespaceClient} namespaces GeoServer REST client instance for namespaces */
69
+
70
+ this.namespaces = new _namespace["default"](this.url, this.auth);
71
+ /** @member {DatastoreClient} datastores GeoServer REST client instance for data stores */
72
+
73
+ this.datastores = new _datastore["default"](this.url, this.auth);
74
+ /** @member {ImageMosaicClient} imagemosaics GeoServer REST client instance for image mosaics */
75
+
76
+ this.imagemosaics = new _imagemosaic["default"](this.url, this.auth);
77
+ /** @member {SecurityClient} security GeoServer REST client instance for security related modifications */
78
+
79
+ this.security = new _security["default"](this.url, this.auth);
80
+ /** @member {SettingsClient} settings GeoServer REST client instance for settings */
81
+
82
+ this.settings = new _settings["default"](this.url, this.auth);
83
+ /** @member {AboutClient} about GeoServer REST client instance for about endpoint */
84
+
85
+ this.about = new _about["default"](this.url, this.auth);
86
+ });
87
+ exports.GeoServerRestClient = GeoServerRestClient;
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "geoserver-node-client",
3
+ "version": "1.1.0",
4
+ "description": "Node.js client for GeoServer REST API",
5
+ "type": "commonjs",
6
+ "main": "geoserver-rest-client.js",
7
+ "scripts": {
8
+ "demo": "node demo/index.js",
9
+ "docs": "./node_modules/.bin/jsdoc geoserver-rest-client.js src/*.js DOCS_HOME.md",
10
+ "lint": "eslint src/**/*.js test/**/*.js scripts/**/*.js geoserver-rest-client.js",
11
+ "lint-fix": "eslint --fix src/**/*.js test/**/*.js scripts/**/*.js geoserver-rest-client.js",
12
+ "pretest": "npm run lint",
13
+ "test": "mocha --timeout 10000",
14
+ "release": "release-it",
15
+ "build": "npm run build:clean && npm run build:babel && npm run build:fixup",
16
+ "build:clean": "rm -rf dist",
17
+ "build:babel": "babel geoserver-rest-client.js -d dist && babel src -d dist/src",
18
+ "build:fixup": "node scripts/create-custom-package-json.js"
19
+ },
20
+ "exports": {
21
+ "import": "./geoserver-rest-client.js",
22
+ "require": "./dist/geoserver-rest-client.js"
23
+ },
24
+ "files": [
25
+ "geoserver-rest-client.js",
26
+ "src",
27
+ "dist"
28
+ ],
29
+ "keywords": [
30
+ "GeoServer",
31
+ "REST",
32
+ "Client"
33
+ ],
34
+ "author": "C. Mayer, meggsimum (info_at*meggsimum?dot?de)",
35
+ "license": "BSD-2-Clause",
36
+ "dependencies": {
37
+ "@babel/runtime": "^7.18.3",
38
+ "node-fetch": "^2.6.5"
39
+ },
40
+ "devDependencies": {
41
+ "@babel/cli": "^7.17.10",
42
+ "@babel/core": "^7.17.12",
43
+ "@babel/plugin-transform-runtime": "^7.18.0",
44
+ "@babel/preset-env": "^7.17.12",
45
+ "chai": "^4.3.4",
46
+ "eslint": "^7.32.0",
47
+ "eslint-config-standard": "^14.1.1",
48
+ "eslint-plugin-import": "^2.25.2",
49
+ "eslint-plugin-node": "^11.1.0",
50
+ "eslint-plugin-promise": "^4.3.1",
51
+ "eslint-plugin-standard": "^4.1.0",
52
+ "jsdoc": "^3.6.10",
53
+ "mocha": "^9.1.3",
54
+ "release-it": "^14.14.3"
55
+ }
56
+ }
@@ -0,0 +1,145 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports["default"] = void 0;
9
+
10
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
11
+
12
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
13
+
14
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
15
+
16
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
17
+
18
+ var _nodeFetch = _interopRequireDefault(require("node-fetch"));
19
+
20
+ var _geoserver = require("./util/geoserver.js");
21
+
22
+ /**
23
+ * Client for GeoServer "about" endpoint
24
+ *
25
+ * @module AboutClient
26
+ */
27
+ var AboutClient = /*#__PURE__*/function () {
28
+ /**
29
+ * Creates a GeoServer REST AboutClient instance.
30
+ *
31
+ * @param {String} url The URL of the GeoServer REST API endpoint
32
+ * @param {String} auth The Basic Authentication string
33
+ */
34
+ function AboutClient(url, auth) {
35
+ (0, _classCallCheck2["default"])(this, AboutClient);
36
+ this.url = url;
37
+ this.auth = auth;
38
+ }
39
+ /**
40
+ * Get the GeoServer version.
41
+ *
42
+ * @throws Error if request fails
43
+ *
44
+ * @returns {Object} The version of GeoServer
45
+ */
46
+
47
+
48
+ (0, _createClass2["default"])(AboutClient, [{
49
+ key: "getVersion",
50
+ value: function () {
51
+ var _getVersion = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() {
52
+ var url, response, geoServerResponse;
53
+ return _regenerator["default"].wrap(function _callee$(_context) {
54
+ while (1) {
55
+ switch (_context.prev = _context.next) {
56
+ case 0:
57
+ url = this.url + 'about/version.json';
58
+ _context.next = 3;
59
+ return (0, _nodeFetch["default"])(url, {
60
+ credentials: 'include',
61
+ method: 'GET',
62
+ headers: {
63
+ Authorization: this.auth
64
+ }
65
+ });
66
+
67
+ case 3:
68
+ response = _context.sent;
69
+
70
+ if (response.ok) {
71
+ _context.next = 9;
72
+ break;
73
+ }
74
+
75
+ _context.next = 7;
76
+ return (0, _geoserver.getGeoServerResponseText)(response);
77
+
78
+ case 7:
79
+ geoServerResponse = _context.sent;
80
+ throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
81
+
82
+ case 9:
83
+ return _context.abrupt("return", response.json());
84
+
85
+ case 10:
86
+ case "end":
87
+ return _context.stop();
88
+ }
89
+ }
90
+ }, _callee, this);
91
+ }));
92
+
93
+ function getVersion() {
94
+ return _getVersion.apply(this, arguments);
95
+ }
96
+
97
+ return getVersion;
98
+ }()
99
+ /**
100
+ * Checks if the configured GeoServer REST connection exists.
101
+ *
102
+ * @returns {Boolean} If the connection exists
103
+ */
104
+
105
+ }, {
106
+ key: "exists",
107
+ value: function () {
108
+ var _exists = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2() {
109
+ var versionInfo;
110
+ return _regenerator["default"].wrap(function _callee2$(_context2) {
111
+ while (1) {
112
+ switch (_context2.prev = _context2.next) {
113
+ case 0:
114
+ _context2.prev = 0;
115
+ _context2.next = 3;
116
+ return this.getVersion();
117
+
118
+ case 3:
119
+ versionInfo = _context2.sent;
120
+ return _context2.abrupt("return", !!versionInfo);
121
+
122
+ case 7:
123
+ _context2.prev = 7;
124
+ _context2.t0 = _context2["catch"](0);
125
+ return _context2.abrupt("return", false);
126
+
127
+ case 10:
128
+ case "end":
129
+ return _context2.stop();
130
+ }
131
+ }
132
+ }, _callee2, this, [[0, 7]]);
133
+ }));
134
+
135
+ function exists() {
136
+ return _exists.apply(this, arguments);
137
+ }
138
+
139
+ return exists;
140
+ }()
141
+ }]);
142
+ return AboutClient;
143
+ }();
144
+
145
+ exports["default"] = AboutClient;