geoserver-node-client 0.0.7 → 1.0.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,11 +5,9 @@
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
 
@@ -20,6 +18,48 @@ Compatible with [GeoServer](https://geoserver.org)
20
18
  - v2.18.x (no more maintained and officially deprecated)
21
19
  - v2.17.x (no more maintained and officially deprecated)
22
20
 
21
+
22
+ ### Usage
23
+
24
+ ```shell
25
+ npm i geoserver-node-client
26
+ ```
27
+
28
+ usage with require (ES5):
29
+ ```js
30
+ const grcImport = require('geoserver-node-client');
31
+ const GeoServerRestClient = grcImport.GeoServerRestClient;
32
+
33
+ const url = 'http://localhost:8080/geoserver/rest/';
34
+ const user = 'admin';
35
+ const pw = 'geoserver';
36
+ const grc = new GeoServerRestClient(url, user, pw);
37
+
38
+ async function main () {
39
+ const result = await grc.about.exists();
40
+ console.log(result);
41
+ };
42
+
43
+ main();
44
+ ```
45
+
46
+ usage as ES module (ES6)
47
+ ```js
48
+ import {GeoServerRestClient} from 'geoserver-node-client';
49
+
50
+ const url = 'http://localhost:8080/geoserver/rest/';
51
+ const user = 'admin';
52
+ const pw = 'geoserver';
53
+ const grc = new GeoServerRestClient(url, user, pw);
54
+
55
+ async function main () {
56
+ const result = await grc.about.exists();
57
+ console.log(result);
58
+ };
59
+
60
+ main();
61
+ ```
62
+
23
63
  ### Setup
24
64
 
25
65
  Run as local checkout (mainly for development purposes)
@@ -34,6 +74,28 @@ npm install
34
74
  npm run demo
35
75
  ```
36
76
 
77
+ ### Error Handling
78
+
79
+ 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:
80
+
81
+ ```javascript
82
+ try {
83
+ // call any function from this library
84
+ await grc.styles.publish(workspace, styleName, sldBody)
85
+ } catch (error) {
86
+ // the standard error message
87
+ console.error(error.message);
88
+
89
+ // the whole error including stack trace and (if available) the property 'geoServerOutput'
90
+ console.error(error);
91
+
92
+ if (error instanceof GeoServerResponseError) {
93
+ // a GeoServer specific error happened
94
+ } else {
95
+ // another error happened
96
+ }
97
+ }
98
+ ```
37
99
 
38
100
  ### Unit Tests
39
101
 
@@ -43,19 +105,23 @@ First start a GeoServer, e.g. by using this Docker container:
43
105
  docker run \
44
106
  -p 8080:8080 \
45
107
  -v /path/to/geoserver_mnt:/opt/geoserver_data \
46
- meggsimum/geoserver:2.20.1
108
+ meggsimum/geoserver:2.20.4
47
109
  ```
48
110
 
49
111
  Then, in an other terminal, run:
50
112
 
51
113
  ```shell
52
114
  # specify the GeoServer version and run the test suite
53
- GEOSERVER_VERSION=2.20.1 npm run test
115
+ GEOSERVER_VERSION=2.20.4 npm run test
54
116
  ```
55
117
 
56
118
  ### Release
57
119
 
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:
120
+ 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).
121
+
122
+ The GitHub release has to be performed manually based on the tag created by `release-it`.
123
+
124
+ This is the workflow for releasing:
59
125
 
60
126
  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
127
 
@@ -87,8 +153,9 @@ npm run release
87
153
 
88
154
  ### Credits
89
155
 
90
- 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/).
156
+ 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/):
91
157
  <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>.
158
+ <p><img src="http://www.klips-projekt.de/wp-content/uploads/2021/02/SAG_KLIPS-Logo_Jan21.png" alt="KLIPS Logo" width="200"/></p>.
92
159
 
93
160
  <img src="https://sauber-projekt.de/wp-content/uploads/2018/12/mfund-logo-download-e1547545420815-300x77.jpg" alt="mFund Logo" width="300"/>
94
161
  <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,55 @@
1
+ {
2
+ "name": "geoserver-node-client",
3
+ "version": "1.0.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
+ "node-fetch": "^2.6.5"
38
+ },
39
+ "devDependencies": {
40
+ "@babel/cli": "^7.17.10",
41
+ "@babel/core": "^7.17.12",
42
+ "@babel/plugin-transform-runtime": "^7.18.0",
43
+ "@babel/preset-env": "^7.17.12",
44
+ "chai": "^4.3.4",
45
+ "eslint": "^7.32.0",
46
+ "eslint-config-standard": "^14.1.1",
47
+ "eslint-plugin-import": "^2.25.2",
48
+ "eslint-plugin-node": "^11.1.0",
49
+ "eslint-plugin-promise": "^4.3.1",
50
+ "eslint-plugin-standard": "^4.1.0",
51
+ "jsdoc": "^3.6.10",
52
+ "mocha": "^9.1.3",
53
+ "release-it": "^14.14.3"
54
+ }
55
+ }
@@ -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;