geoserver-node-client 1.6.1 → 1.6.2

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.
@@ -1,14 +1,10 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports["default"] = void 0;
8
- var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
9
- var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
10
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
11
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
7
+ exports.default = void 0;
12
8
  var _nodeFetch = _interopRequireDefault(require("node-fetch"));
13
9
  var _geoserver = require("./util/geoserver.js");
14
10
  /**
@@ -16,15 +12,14 @@ var _geoserver = require("./util/geoserver.js");
16
12
  *
17
13
  * @module SettingsClient
18
14
  */
19
- var SettingsClient = exports["default"] = /*#__PURE__*/function () {
15
+ class SettingsClient {
20
16
  /**
21
17
  * Creates a GeoServer REST SettingsClient instance.
22
18
  *
23
19
  * @param {String} url The URL of the GeoServer REST API endpoint
24
20
  * @param {String} auth The Basic Authentication string
25
21
  */
26
- function SettingsClient(url, auth) {
27
- (0, _classCallCheck2["default"])(this, SettingsClient);
22
+ constructor(url, auth) {
28
23
  this.url = url;
29
24
  this.auth = auth;
30
25
  }
@@ -36,251 +31,128 @@ var SettingsClient = exports["default"] = /*#__PURE__*/function () {
36
31
  *
37
32
  * @returns {Object} Settings object
38
33
  */
39
- return (0, _createClass2["default"])(SettingsClient, [{
40
- key: "getSettings",
41
- value: (function () {
42
- var _getSettings = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee() {
43
- var response, geoServerResponse;
44
- return _regenerator["default"].wrap(function (_context) {
45
- while (1) switch (_context.prev = _context.next) {
46
- case 0:
47
- _context.next = 1;
48
- return (0, _nodeFetch["default"])(this.url + 'settings.json', {
49
- credentials: 'include',
50
- method: 'GET',
51
- headers: {
52
- Authorization: this.auth
53
- }
54
- });
55
- case 1:
56
- response = _context.sent;
57
- if (response.ok) {
58
- _context.next = 3;
59
- break;
60
- }
61
- _context.next = 2;
62
- return (0, _geoserver.getGeoServerResponseText)(response);
63
- case 2:
64
- geoServerResponse = _context.sent;
65
- throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
66
- case 3:
67
- return _context.abrupt("return", response.json());
68
- case 4:
69
- case "end":
70
- return _context.stop();
71
- }
72
- }, _callee, this);
73
- }));
74
- function getSettings() {
75
- return _getSettings.apply(this, arguments);
34
+ async getSettings() {
35
+ const response = await (0, _nodeFetch.default)(this.url + 'settings.json', {
36
+ credentials: 'include',
37
+ method: 'GET',
38
+ headers: {
39
+ Authorization: this.auth
76
40
  }
77
- return getSettings;
78
- }()
79
- /**
80
- * Update the global GeoServer settings.
81
- *
82
- * @param {Object} settings The adapted GeoServer settings object
83
- */
84
- )
85
- }, {
86
- key: "updateSettings",
87
- value: (function () {
88
- var _updateSettings = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee2(settings) {
89
- var response, geoServerResponse;
90
- return _regenerator["default"].wrap(function (_context2) {
91
- while (1) switch (_context2.prev = _context2.next) {
92
- case 0:
93
- _context2.next = 1;
94
- return (0, _nodeFetch["default"])(this.url + 'settings', {
95
- credentials: 'include',
96
- method: 'PUT',
97
- headers: {
98
- Authorization: this.auth,
99
- 'Content-Type': 'application/json'
100
- },
101
- body: JSON.stringify(settings)
102
- });
103
- case 1:
104
- response = _context2.sent;
105
- if (response.ok) {
106
- _context2.next = 3;
107
- break;
108
- }
109
- _context2.next = 2;
110
- return (0, _geoserver.getGeoServerResponseText)(response);
111
- case 2:
112
- geoServerResponse = _context2.sent;
113
- throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
114
- case 3:
115
- case "end":
116
- return _context2.stop();
117
- }
118
- }, _callee2, this);
119
- }));
120
- function updateSettings(_x) {
121
- return _updateSettings.apply(this, arguments);
122
- }
123
- return updateSettings;
124
- }()
125
- /**
126
- * Update the global proxyBaseUrl setting.
127
- *
128
- * @param {String} proxyBaseUrl The proxy base URL
129
- */
130
- )
131
- }, {
132
- key: "updateProxyBaseUrl",
133
- value: (function () {
134
- var _updateProxyBaseUrl = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee3(proxyBaseUrl) {
135
- var settingsJson;
136
- return _regenerator["default"].wrap(function (_context3) {
137
- while (1) switch (_context3.prev = _context3.next) {
138
- case 0:
139
- _context3.next = 1;
140
- return this.getSettings();
141
- case 1:
142
- settingsJson = _context3.sent;
143
- if (!(!settingsJson.global && !settingsJson.global.settings)) {
144
- _context3.next = 2;
145
- break;
146
- }
147
- return _context3.abrupt("return", false);
148
- case 2:
149
- // add proxyBaseUrl to settings
150
- settingsJson.global.settings.proxyBaseUrl = proxyBaseUrl;
151
- _context3.next = 3;
152
- return this.updateSettings(settingsJson);
153
- case 3:
154
- case "end":
155
- return _context3.stop();
156
- }
157
- }, _callee3, this);
158
- }));
159
- function updateProxyBaseUrl(_x2) {
160
- return _updateProxyBaseUrl.apply(this, arguments);
161
- }
162
- return updateProxyBaseUrl;
163
- }()
164
- /**
165
- * Get the contact information of the GeoServer.
166
- *
167
- * @throws Error if request fails
168
- *
169
- * @returns {Object} An object with contact information
170
- */
171
- )
172
- }, {
173
- key: "getContactInformation",
174
- value: (function () {
175
- var _getContactInformation = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee4() {
176
- var response, geoServerResponse;
177
- return _regenerator["default"].wrap(function (_context4) {
178
- while (1) switch (_context4.prev = _context4.next) {
179
- case 0:
180
- _context4.next = 1;
181
- return (0, _nodeFetch["default"])(this.url + 'settings/contact', {
182
- credentials: 'include',
183
- method: 'GET',
184
- headers: {
185
- Authorization: this.auth
186
- }
187
- });
188
- case 1:
189
- response = _context4.sent;
190
- if (response.ok) {
191
- _context4.next = 3;
192
- break;
193
- }
194
- _context4.next = 2;
195
- return (0, _geoserver.getGeoServerResponseText)(response);
196
- case 2:
197
- geoServerResponse = _context4.sent;
198
- throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
199
- case 3:
200
- return _context4.abrupt("return", response.json());
201
- case 4:
202
- case "end":
203
- return _context4.stop();
204
- }
205
- }, _callee4, this);
206
- }));
207
- function getContactInformation() {
208
- return _getContactInformation.apply(this, arguments);
209
- }
210
- return getContactInformation;
211
- }()
212
- /**
213
- * Update the contact information.
214
- *
215
- * Deleting is not supported.
216
- *
217
- * @param {String} [address] The contact's address
218
- * @param {String} [city] The contact's city
219
- * @param {String} [country] The contact's country
220
- * @param {String} [postalCode] The contact's postCode
221
- * @param {String} [state] The contact's state
222
- * @param {String} [email] The contact's email
223
- * @param {String} [organization] The contact's organization
224
- * @param {String} [contactPerson] The contact person
225
- * @param {String} [phoneNumber] The contact's phone number
226
- *
227
- * @throws Error if request fails
228
- */
229
- )
230
- }, {
231
- key: "updateContactInformation",
232
- value: (function () {
233
- var _updateContactInformation = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee5(address, city, country, postalCode, state, email, organization, contactPerson, phoneNumber) {
234
- var contact, body, url, response, geoServerResponse;
235
- return _regenerator["default"].wrap(function (_context5) {
236
- while (1) switch (_context5.prev = _context5.next) {
237
- case 0:
238
- contact = {
239
- address: address,
240
- addressCity: city,
241
- addressCountry: country,
242
- addressPostalCode: postalCode,
243
- addressState: state,
244
- contactEmail: email,
245
- contactOrganization: organization,
246
- contactPerson: contactPerson,
247
- contactVoice: phoneNumber
248
- };
249
- body = {
250
- contact: contact
251
- };
252
- url = this.url + 'settings/contact';
253
- _context5.next = 1;
254
- return (0, _nodeFetch["default"])(url, {
255
- credentials: 'include',
256
- method: 'PUT',
257
- headers: {
258
- Authorization: this.auth,
259
- 'Content-Type': 'application/json'
260
- },
261
- body: JSON.stringify(body)
262
- });
263
- case 1:
264
- response = _context5.sent;
265
- if (response.ok) {
266
- _context5.next = 3;
267
- break;
268
- }
269
- _context5.next = 2;
270
- return (0, _geoserver.getGeoServerResponseText)(response);
271
- case 2:
272
- geoServerResponse = _context5.sent;
273
- throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
274
- case 3:
275
- case "end":
276
- return _context5.stop();
277
- }
278
- }, _callee5, this);
279
- }));
280
- function updateContactInformation(_x3, _x4, _x5, _x6, _x7, _x8, _x9, _x0, _x1) {
281
- return _updateContactInformation.apply(this, arguments);
41
+ });
42
+ if (!response.ok) {
43
+ const geoServerResponse = await (0, _geoserver.getGeoServerResponseText)(response);
44
+ throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
45
+ }
46
+ return response.json();
47
+ }
48
+
49
+ /**
50
+ * Update the global GeoServer settings.
51
+ *
52
+ * @param {Object} settings The adapted GeoServer settings object
53
+ */
54
+ async updateSettings(settings) {
55
+ const response = await (0, _nodeFetch.default)(this.url + 'settings', {
56
+ credentials: 'include',
57
+ method: 'PUT',
58
+ headers: {
59
+ Authorization: this.auth,
60
+ 'Content-Type': 'application/json'
61
+ },
62
+ body: JSON.stringify(settings)
63
+ });
64
+ if (!response.ok) {
65
+ const geoServerResponse = await (0, _geoserver.getGeoServerResponseText)(response);
66
+ throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
67
+ }
68
+ }
69
+
70
+ /**
71
+ * Update the global proxyBaseUrl setting.
72
+ *
73
+ * @param {String} proxyBaseUrl The proxy base URL
74
+ */
75
+ async updateProxyBaseUrl(proxyBaseUrl) {
76
+ const settingsJson = await this.getSettings();
77
+
78
+ // check if settings are correctly formatted
79
+ if (!settingsJson.global && !settingsJson.global.settings) {
80
+ return false;
81
+ }
82
+
83
+ // add proxyBaseUrl to settings
84
+ settingsJson.global.settings.proxyBaseUrl = proxyBaseUrl;
85
+ await this.updateSettings(settingsJson);
86
+ }
87
+
88
+ /**
89
+ * Get the contact information of the GeoServer.
90
+ *
91
+ * @throws Error if request fails
92
+ *
93
+ * @returns {Object} An object with contact information
94
+ */
95
+ async getContactInformation() {
96
+ const response = await (0, _nodeFetch.default)(this.url + 'settings/contact', {
97
+ credentials: 'include',
98
+ method: 'GET',
99
+ headers: {
100
+ Authorization: this.auth
282
101
  }
283
- return updateContactInformation;
284
- }())
285
- }]);
286
- }();
102
+ });
103
+ if (!response.ok) {
104
+ const geoServerResponse = await (0, _geoserver.getGeoServerResponseText)(response);
105
+ throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
106
+ }
107
+ return response.json();
108
+ }
109
+
110
+ /**
111
+ * Update the contact information.
112
+ *
113
+ * Deleting is not supported.
114
+ *
115
+ * @param {String} [address] The contact's address
116
+ * @param {String} [city] The contact's city
117
+ * @param {String} [country] The contact's country
118
+ * @param {String} [postalCode] The contact's postCode
119
+ * @param {String} [state] The contact's state
120
+ * @param {String} [email] The contact's email
121
+ * @param {String} [organization] The contact's organization
122
+ * @param {String} [contactPerson] The contact person
123
+ * @param {String} [phoneNumber] The contact's phone number
124
+ *
125
+ * @throws Error if request fails
126
+ */
127
+ async updateContactInformation(address, city, country, postalCode, state, email, organization, contactPerson, phoneNumber) {
128
+ const contact = {
129
+ address: address,
130
+ addressCity: city,
131
+ addressCountry: country,
132
+ addressPostalCode: postalCode,
133
+ addressState: state,
134
+ contactEmail: email,
135
+ contactOrganization: organization,
136
+ contactPerson: contactPerson,
137
+ contactVoice: phoneNumber
138
+ };
139
+ const body = {
140
+ contact: contact
141
+ };
142
+ const url = this.url + 'settings/contact';
143
+ const response = await (0, _nodeFetch.default)(url, {
144
+ credentials: 'include',
145
+ method: 'PUT',
146
+ headers: {
147
+ Authorization: this.auth,
148
+ 'Content-Type': 'application/json'
149
+ },
150
+ body: JSON.stringify(body)
151
+ });
152
+ if (!response.ok) {
153
+ const geoServerResponse = await (0, _geoserver.getGeoServerResponseText)(response);
154
+ throw new _geoserver.GeoServerResponseError(null, geoServerResponse);
155
+ }
156
+ }
157
+ }
158
+ exports.default = SettingsClient;