geoserver-node-client 1.4.8 → 1.5.1
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 +3 -6
- package/dist/package.json +13 -12
- package/dist/src/about.js +17 -17
- package/dist/src/datastore.js +105 -105
- package/dist/src/imagemosaic.js +32 -32
- package/dist/src/layer.js +472 -201
- package/dist/src/layergroup.js +31 -32
- package/dist/src/namespace.js +44 -44
- package/dist/src/reset-reload.js +14 -14
- package/dist/src/security.js +87 -41
- package/dist/src/settings.js +37 -37
- package/dist/src/style.js +77 -77
- package/dist/src/util/geoserver.js +7 -6
- package/dist/src/workspace.js +49 -49
- package/geoserver-rest-client.js +2 -2
- package/package.json +13 -12
- package/src/about.js +5 -5
- package/src/datastore.js +69 -29
- package/src/imagemosaic.js +38 -11
- package/src/layer.js +361 -79
- package/src/layergroup.js +18 -19
- package/src/namespace.js +11 -10
- package/src/reset-reload.js +3 -3
- package/src/security.js +31 -6
- package/src/settings.js +16 -6
- package/src/style.js +36 -18
- package/src/util/geoserver.js +7 -9
- package/src/workspace.js +13 -9
package/src/layergroup.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import fetch from 'node-fetch';
|
|
2
2
|
import { getGeoServerResponseText, GeoServerResponseError } from './util/geoserver.js';
|
|
3
|
-
import AboutClient from './about.js'
|
|
4
|
-
import LayerClient from './layer.js';
|
|
3
|
+
import AboutClient from './about.js';
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
6
|
* Client for GeoServer layergroups
|
|
@@ -15,7 +14,7 @@ export default class LayerGroupClient {
|
|
|
15
14
|
* @param {String} url The URL of the GeoServer REST API endpoint
|
|
16
15
|
* @param {String} auth The Basic Authentication string
|
|
17
16
|
*/
|
|
18
|
-
constructor
|
|
17
|
+
constructor(url, auth) {
|
|
19
18
|
this.url = url;
|
|
20
19
|
this.auth = auth;
|
|
21
20
|
}
|
|
@@ -42,7 +41,7 @@ export default class LayerGroupClient {
|
|
|
42
41
|
*
|
|
43
42
|
* @returns {string} A string with layer group location or undefined if not found
|
|
44
43
|
*/
|
|
45
|
-
async create
|
|
44
|
+
async create(workspace, layerGroupName, layers, layerGroupOptions) {
|
|
46
45
|
const options = {
|
|
47
46
|
mode: 'SINGLE',
|
|
48
47
|
layerGroupTitle: '',
|
|
@@ -82,17 +81,15 @@ export default class LayerGroupClient {
|
|
|
82
81
|
...options
|
|
83
82
|
}
|
|
84
83
|
};
|
|
85
|
-
const response = await fetch(
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
95
|
-
);
|
|
84
|
+
const response = await fetch(`${this.url}/workspaces/${workspace}/layergroups`, {
|
|
85
|
+
credentials: 'include',
|
|
86
|
+
method: 'POST',
|
|
87
|
+
headers: {
|
|
88
|
+
Authorization: this.auth,
|
|
89
|
+
'Content-Type': 'application/json'
|
|
90
|
+
},
|
|
91
|
+
body: JSON.stringify(body)
|
|
92
|
+
});
|
|
96
93
|
|
|
97
94
|
if (!response.ok) {
|
|
98
95
|
const grc = new AboutClient(this.url, this.auth);
|
|
@@ -123,15 +120,17 @@ export default class LayerGroupClient {
|
|
|
123
120
|
*
|
|
124
121
|
* @returns {Object} An object with layer group information or undefined if it cannot be found
|
|
125
122
|
*/
|
|
126
|
-
async get
|
|
123
|
+
async get(workspace, layerGroupName) {
|
|
127
124
|
const response = await fetch(
|
|
128
|
-
`${this.url}/workspaces/${workspace}/layergroups/${layerGroupName}.json`,
|
|
125
|
+
`${this.url}/workspaces/${workspace}/layergroups/${layerGroupName}.json`,
|
|
126
|
+
{
|
|
129
127
|
credentials: 'include',
|
|
130
128
|
method: 'GET',
|
|
131
129
|
headers: {
|
|
132
130
|
Authorization: this.auth
|
|
133
131
|
}
|
|
134
|
-
}
|
|
132
|
+
}
|
|
133
|
+
);
|
|
135
134
|
|
|
136
135
|
if (!response.ok) {
|
|
137
136
|
const grc = new AboutClient(this.url, this.auth);
|
|
@@ -156,7 +155,7 @@ export default class LayerGroupClient {
|
|
|
156
155
|
*
|
|
157
156
|
* @throws Error if request fails
|
|
158
157
|
*/
|
|
159
|
-
async update
|
|
158
|
+
async update(workspace, layerGroupName, layerGroupDefinition) {
|
|
160
159
|
const url = `${this.url}/workspaces/${workspace}/layergroups/${layerGroupName}.json`;
|
|
161
160
|
const response = await fetch(url, {
|
|
162
161
|
credentials: 'include',
|
package/src/namespace.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import fetch from 'node-fetch';
|
|
2
2
|
import { getGeoServerResponseText, GeoServerResponseError } from './util/geoserver.js';
|
|
3
|
-
import AboutClient from './about.js'
|
|
3
|
+
import AboutClient from './about.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Client for GeoServer namespace
|
|
@@ -14,7 +14,7 @@ export default class NamespaceClient {
|
|
|
14
14
|
* @param {String} url The URL of the GeoServer REST API endpoint
|
|
15
15
|
* @param {String} auth The Basic Authentication string
|
|
16
16
|
*/
|
|
17
|
-
constructor
|
|
17
|
+
constructor(url, auth) {
|
|
18
18
|
this.url = url;
|
|
19
19
|
this.auth = auth;
|
|
20
20
|
}
|
|
@@ -26,7 +26,7 @@ export default class NamespaceClient {
|
|
|
26
26
|
*
|
|
27
27
|
* @returns {Object} An object describing the namespace
|
|
28
28
|
*/
|
|
29
|
-
async getAll
|
|
29
|
+
async getAll() {
|
|
30
30
|
const response = await fetch(this.url + 'namespaces.json', {
|
|
31
31
|
credentials: 'include',
|
|
32
32
|
method: 'GET',
|
|
@@ -51,7 +51,7 @@ export default class NamespaceClient {
|
|
|
51
51
|
*
|
|
52
52
|
* @returns {String} The name of the created namespace
|
|
53
53
|
*/
|
|
54
|
-
async create
|
|
54
|
+
async create(prefix, uri) {
|
|
55
55
|
const body = {
|
|
56
56
|
namespace: {
|
|
57
57
|
prefix: prefix,
|
|
@@ -86,7 +86,7 @@ export default class NamespaceClient {
|
|
|
86
86
|
*
|
|
87
87
|
* @returns {Object} An object describing the namespace or undefined if it cannot be found
|
|
88
88
|
*/
|
|
89
|
-
async get
|
|
89
|
+
async get(name) {
|
|
90
90
|
const response = await fetch(this.url + 'namespaces/' + name + '.json', {
|
|
91
91
|
credentials: 'include',
|
|
92
92
|
method: 'GET',
|
|
@@ -115,7 +115,7 @@ export default class NamespaceClient {
|
|
|
115
115
|
*
|
|
116
116
|
* @throws Error if request fails
|
|
117
117
|
*/
|
|
118
|
-
async delete
|
|
118
|
+
async delete(name) {
|
|
119
119
|
const response = await fetch(this.url + 'namespaces/' + name, {
|
|
120
120
|
credentials: 'include',
|
|
121
121
|
method: 'DELETE',
|
|
@@ -130,13 +130,14 @@ export default class NamespaceClient {
|
|
|
130
130
|
case 403:
|
|
131
131
|
throw new GeoServerResponseError(
|
|
132
132
|
'Namespace or related Workspace is not empty (and recurse not true)',
|
|
133
|
-
geoServerResponse
|
|
133
|
+
geoServerResponse
|
|
134
|
+
);
|
|
134
135
|
case 404:
|
|
135
|
-
throw new GeoServerResponseError(
|
|
136
|
+
throw new GeoServerResponseError("Namespace doesn't exist", geoServerResponse);
|
|
136
137
|
case 405:
|
|
137
|
-
throw new GeoServerResponseError(
|
|
138
|
+
throw new GeoServerResponseError("Can't delete default namespace", geoServerResponse);
|
|
138
139
|
default:
|
|
139
|
-
throw new GeoServerResponseError('Response not recognized', geoServerResponse)
|
|
140
|
+
throw new GeoServerResponseError('Response not recognized', geoServerResponse);
|
|
140
141
|
}
|
|
141
142
|
}
|
|
142
143
|
}
|
package/src/reset-reload.js
CHANGED
|
@@ -14,7 +14,7 @@ export default class ResetReloadClient {
|
|
|
14
14
|
* @param {String} url The URL of the GeoServer REST API endpoint
|
|
15
15
|
* @param {String} auth The Basic Authentication string
|
|
16
16
|
*/
|
|
17
|
-
constructor
|
|
17
|
+
constructor(url, auth) {
|
|
18
18
|
this.url = url;
|
|
19
19
|
this.auth = auth;
|
|
20
20
|
}
|
|
@@ -28,7 +28,7 @@ export default class ResetReloadClient {
|
|
|
28
28
|
*
|
|
29
29
|
* @throws Error if request fails
|
|
30
30
|
*/
|
|
31
|
-
async reset
|
|
31
|
+
async reset() {
|
|
32
32
|
const url = this.url + 'reset';
|
|
33
33
|
const response = await fetch(url, {
|
|
34
34
|
credentials: 'include',
|
|
@@ -52,7 +52,7 @@ export default class ResetReloadClient {
|
|
|
52
52
|
*
|
|
53
53
|
* @throws Error if request fails
|
|
54
54
|
*/
|
|
55
|
-
async reload
|
|
55
|
+
async reload() {
|
|
56
56
|
const url = this.url + 'reload';
|
|
57
57
|
const response = await fetch(url, {
|
|
58
58
|
credentials: 'include',
|
package/src/security.js
CHANGED
|
@@ -13,7 +13,7 @@ export default class SecurityClient {
|
|
|
13
13
|
* @param {String} url The URL of the GeoServer REST API endpoint
|
|
14
14
|
* @param {String} auth The Basic Authentication string
|
|
15
15
|
*/
|
|
16
|
-
constructor
|
|
16
|
+
constructor(url, auth) {
|
|
17
17
|
this.url = url;
|
|
18
18
|
this.auth = auth;
|
|
19
19
|
}
|
|
@@ -25,7 +25,7 @@ export default class SecurityClient {
|
|
|
25
25
|
*
|
|
26
26
|
* @returns {Object} An object with all users
|
|
27
27
|
*/
|
|
28
|
-
async getAllUsers
|
|
28
|
+
async getAllUsers() {
|
|
29
29
|
const response = await fetch(this.url + 'security/usergroup/users.json', {
|
|
30
30
|
credentials: 'include',
|
|
31
31
|
method: 'GET',
|
|
@@ -49,7 +49,7 @@ export default class SecurityClient {
|
|
|
49
49
|
*
|
|
50
50
|
* @throws Error if request fails
|
|
51
51
|
*/
|
|
52
|
-
async createUser
|
|
52
|
+
async createUser(username, password) {
|
|
53
53
|
const body = {
|
|
54
54
|
user: {
|
|
55
55
|
userName: username,
|
|
@@ -72,7 +72,10 @@ export default class SecurityClient {
|
|
|
72
72
|
const geoServerResponse = await getGeoServerResponseText(response);
|
|
73
73
|
switch (response.status) {
|
|
74
74
|
case 404:
|
|
75
|
-
throw new GeoServerResponseError(
|
|
75
|
+
throw new GeoServerResponseError(
|
|
76
|
+
`User ${username} might already exists.`,
|
|
77
|
+
geoServerResponse
|
|
78
|
+
);
|
|
76
79
|
default:
|
|
77
80
|
throw new GeoServerResponseError(null, geoServerResponse);
|
|
78
81
|
}
|
|
@@ -89,7 +92,7 @@ export default class SecurityClient {
|
|
|
89
92
|
*
|
|
90
93
|
* @throws Error if request fails
|
|
91
94
|
*/
|
|
92
|
-
async updateUser
|
|
95
|
+
async updateUser(username, password, enabled) {
|
|
93
96
|
const body = {
|
|
94
97
|
user: {
|
|
95
98
|
password: password,
|
|
@@ -113,6 +116,28 @@ export default class SecurityClient {
|
|
|
113
116
|
}
|
|
114
117
|
}
|
|
115
118
|
|
|
119
|
+
/**
|
|
120
|
+
* Deletes an existing user.
|
|
121
|
+
*
|
|
122
|
+
* @param {String} username The name of the user to be deleted
|
|
123
|
+
*
|
|
124
|
+
* @throws Error if request fails
|
|
125
|
+
*/
|
|
126
|
+
async deleteUser(username) {
|
|
127
|
+
const response = await fetch(this.url + 'security/usergroup/user/' + username, {
|
|
128
|
+
credentials: 'include',
|
|
129
|
+
method: 'DELETE',
|
|
130
|
+
headers: {
|
|
131
|
+
Authorization: this.auth
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
if (!response.ok) {
|
|
136
|
+
const geoServerResponse = await getGeoServerResponseText(response);
|
|
137
|
+
throw new GeoServerResponseError(null, geoServerResponse);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
116
141
|
/**
|
|
117
142
|
* Associates the given role to the user.
|
|
118
143
|
*
|
|
@@ -121,7 +146,7 @@ export default class SecurityClient {
|
|
|
121
146
|
*
|
|
122
147
|
* @throws Error if request fails
|
|
123
148
|
*/
|
|
124
|
-
async associateUserRole
|
|
149
|
+
async associateUserRole(username, role) {
|
|
125
150
|
const response = await fetch(`${this.url}security/roles/role/${role}/user/${username}`, {
|
|
126
151
|
credentials: 'include',
|
|
127
152
|
method: 'POST',
|
package/src/settings.js
CHANGED
|
@@ -13,7 +13,7 @@ export default class SettingsClient {
|
|
|
13
13
|
* @param {String} url The URL of the GeoServer REST API endpoint
|
|
14
14
|
* @param {String} auth The Basic Authentication string
|
|
15
15
|
*/
|
|
16
|
-
constructor
|
|
16
|
+
constructor(url, auth) {
|
|
17
17
|
this.url = url;
|
|
18
18
|
this.auth = auth;
|
|
19
19
|
}
|
|
@@ -25,7 +25,7 @@ export default class SettingsClient {
|
|
|
25
25
|
*
|
|
26
26
|
* @returns {Object} Settings object
|
|
27
27
|
*/
|
|
28
|
-
async getSettings
|
|
28
|
+
async getSettings() {
|
|
29
29
|
const response = await fetch(this.url + 'settings.json', {
|
|
30
30
|
credentials: 'include',
|
|
31
31
|
method: 'GET',
|
|
@@ -45,7 +45,7 @@ export default class SettingsClient {
|
|
|
45
45
|
*
|
|
46
46
|
* @param {Object} settings The adapted GeoServer settings object
|
|
47
47
|
*/
|
|
48
|
-
async updateSettings
|
|
48
|
+
async updateSettings(settings) {
|
|
49
49
|
const response = await fetch(this.url + 'settings', {
|
|
50
50
|
credentials: 'include',
|
|
51
51
|
method: 'PUT',
|
|
@@ -67,7 +67,7 @@ export default class SettingsClient {
|
|
|
67
67
|
*
|
|
68
68
|
* @param {String} proxyBaseUrl The proxy base URL
|
|
69
69
|
*/
|
|
70
|
-
async updateProxyBaseUrl
|
|
70
|
+
async updateProxyBaseUrl(proxyBaseUrl) {
|
|
71
71
|
const settingsJson = await this.getSettings();
|
|
72
72
|
|
|
73
73
|
// check if settings are correctly formatted
|
|
@@ -88,7 +88,7 @@ export default class SettingsClient {
|
|
|
88
88
|
*
|
|
89
89
|
* @returns {Object} An object with contact information
|
|
90
90
|
*/
|
|
91
|
-
async getContactInformation
|
|
91
|
+
async getContactInformation() {
|
|
92
92
|
const response = await fetch(this.url + 'settings/contact', {
|
|
93
93
|
credentials: 'include',
|
|
94
94
|
method: 'GET',
|
|
@@ -120,7 +120,17 @@ export default class SettingsClient {
|
|
|
120
120
|
*
|
|
121
121
|
* @throws Error if request fails
|
|
122
122
|
*/
|
|
123
|
-
async updateContactInformation
|
|
123
|
+
async updateContactInformation(
|
|
124
|
+
address,
|
|
125
|
+
city,
|
|
126
|
+
country,
|
|
127
|
+
postalCode,
|
|
128
|
+
state,
|
|
129
|
+
email,
|
|
130
|
+
organization,
|
|
131
|
+
contactPerson,
|
|
132
|
+
phoneNumber
|
|
133
|
+
) {
|
|
124
134
|
const contact = {
|
|
125
135
|
address: address,
|
|
126
136
|
addressCity: city,
|
package/src/style.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import fetch from 'node-fetch';
|
|
2
2
|
import WorkspaceClient from './workspace.js';
|
|
3
3
|
import { getGeoServerResponseText, GeoServerResponseError } from './util/geoserver.js';
|
|
4
|
-
import AboutClient from './about.js'
|
|
4
|
+
import AboutClient from './about.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Client for GeoServer styles
|
|
@@ -15,7 +15,7 @@ export default class StyleClient {
|
|
|
15
15
|
* @param {String} url The URL of the GeoServer REST API endpoint
|
|
16
16
|
* @param {String} auth The Basic Authentication string
|
|
17
17
|
*/
|
|
18
|
-
constructor
|
|
18
|
+
constructor(url, auth) {
|
|
19
19
|
this.url = url;
|
|
20
20
|
this.auth = auth;
|
|
21
21
|
}
|
|
@@ -27,7 +27,7 @@ export default class StyleClient {
|
|
|
27
27
|
*
|
|
28
28
|
* @returns {Object} An object with the default styles
|
|
29
29
|
*/
|
|
30
|
-
async getDefaults
|
|
30
|
+
async getDefaults() {
|
|
31
31
|
const response = await fetch(this.url + 'styles.json', {
|
|
32
32
|
credentials: 'include',
|
|
33
33
|
method: 'GET',
|
|
@@ -52,7 +52,7 @@ export default class StyleClient {
|
|
|
52
52
|
*
|
|
53
53
|
* @returns {Object} An object with all styles
|
|
54
54
|
*/
|
|
55
|
-
async getInWorkspace
|
|
55
|
+
async getInWorkspace(workspace) {
|
|
56
56
|
const response = await fetch(this.url + 'workspaces/' + workspace + '/styles.json', {
|
|
57
57
|
credentials: 'include',
|
|
58
58
|
method: 'GET',
|
|
@@ -75,15 +75,17 @@ export default class StyleClient {
|
|
|
75
75
|
*
|
|
76
76
|
* @returns {Object[]} An array with all style objects
|
|
77
77
|
*/
|
|
78
|
-
async getAllWorkspaceStyles
|
|
78
|
+
async getAllWorkspaceStyles() {
|
|
79
79
|
const allStyles = [];
|
|
80
80
|
const ws = new WorkspaceClient(this.url, this.auth);
|
|
81
81
|
const allWs = await ws.getAll();
|
|
82
82
|
|
|
83
|
-
if (
|
|
83
|
+
if (
|
|
84
|
+
!allWs ||
|
|
84
85
|
!allWs.workspaces ||
|
|
85
86
|
!allWs.workspaces.workspace ||
|
|
86
|
-
!Array.isArray(allWs.workspaces.workspace)
|
|
87
|
+
!Array.isArray(allWs.workspaces.workspace)
|
|
88
|
+
) {
|
|
87
89
|
throw new GeoServerResponseError('Response of available workspaces is malformed');
|
|
88
90
|
}
|
|
89
91
|
|
|
@@ -93,7 +95,7 @@ export default class StyleClient {
|
|
|
93
95
|
const wsStyles = await this.getInWorkspace(ws.name);
|
|
94
96
|
|
|
95
97
|
if (wsStyles.styles.style) {
|
|
96
|
-
wsStyles.styles.style.forEach(wsStyle => {
|
|
98
|
+
wsStyles.styles.style.forEach((wsStyle) => {
|
|
97
99
|
allStyles.push(wsStyle);
|
|
98
100
|
});
|
|
99
101
|
}
|
|
@@ -108,7 +110,7 @@ export default class StyleClient {
|
|
|
108
110
|
*
|
|
109
111
|
* @returns {Object[]} An array with all style objects
|
|
110
112
|
*/
|
|
111
|
-
async getAll
|
|
113
|
+
async getAll() {
|
|
112
114
|
const defaultStyles = await this.getDefaults();
|
|
113
115
|
const wsStyles = await this.getAllWorkspaceStyles();
|
|
114
116
|
if (
|
|
@@ -117,7 +119,7 @@ export default class StyleClient {
|
|
|
117
119
|
!defaultStyles.styles.style ||
|
|
118
120
|
!Array.isArray(defaultStyles.styles.style)
|
|
119
121
|
) {
|
|
120
|
-
throw new GeoServerResponseError('Response of default styles malformed')
|
|
122
|
+
throw new GeoServerResponseError('Response of default styles malformed');
|
|
121
123
|
}
|
|
122
124
|
const allStyles = defaultStyles.styles.style.concat(wsStyles);
|
|
123
125
|
|
|
@@ -133,7 +135,7 @@ export default class StyleClient {
|
|
|
133
135
|
*
|
|
134
136
|
* @throws Error if request fails
|
|
135
137
|
*/
|
|
136
|
-
async publish
|
|
138
|
+
async publish(workspace, name, sldBody) {
|
|
137
139
|
const response = await fetch(this.url + 'workspaces/' + workspace + '/styles?name=' + name, {
|
|
138
140
|
credentials: 'include',
|
|
139
141
|
method: 'POST',
|
|
@@ -158,7 +160,7 @@ export default class StyleClient {
|
|
|
158
160
|
* @param {Boolean} [recurse=false] If references to the specified style in existing layers should be deleted
|
|
159
161
|
* @param {Boolean} [purge=false] Whether the underlying file containing the style should be deleted on disk
|
|
160
162
|
*/
|
|
161
|
-
async delete
|
|
163
|
+
async delete(workspace, name, recurse, purge) {
|
|
162
164
|
let paramPurge = false;
|
|
163
165
|
let paramRecurse = false;
|
|
164
166
|
|
|
@@ -173,12 +175,22 @@ export default class StyleClient {
|
|
|
173
175
|
|
|
174
176
|
if (workspace) {
|
|
175
177
|
// delete style inside workspace
|
|
176
|
-
endpoint =
|
|
177
|
-
|
|
178
|
+
endpoint =
|
|
179
|
+
this.url +
|
|
180
|
+
'workspaces/' +
|
|
181
|
+
workspace +
|
|
182
|
+
'/styles/' +
|
|
183
|
+
name +
|
|
184
|
+
'?' +
|
|
185
|
+
'purge=' +
|
|
186
|
+
paramPurge +
|
|
187
|
+
'&' +
|
|
188
|
+
'recurse=' +
|
|
189
|
+
paramRecurse;
|
|
178
190
|
} else {
|
|
179
191
|
// delete style without workspace
|
|
180
|
-
endpoint =
|
|
181
|
-
|
|
192
|
+
endpoint =
|
|
193
|
+
this.url + 'styles/' + name + '?' + 'purge=' + paramPurge + '&' + 'recurse=' + paramRecurse;
|
|
182
194
|
}
|
|
183
195
|
|
|
184
196
|
const response = await fetch(endpoint, {
|
|
@@ -214,7 +226,13 @@ export default class StyleClient {
|
|
|
214
226
|
*
|
|
215
227
|
* @throws Error if request fails
|
|
216
228
|
*/
|
|
217
|
-
async assignStyleToLayer
|
|
229
|
+
async assignStyleToLayer(
|
|
230
|
+
workspaceOfLayer,
|
|
231
|
+
layerName,
|
|
232
|
+
workspaceOfStyle,
|
|
233
|
+
styleName,
|
|
234
|
+
isDefaultStyle
|
|
235
|
+
) {
|
|
218
236
|
let qualifiedName;
|
|
219
237
|
if (workspaceOfLayer) {
|
|
220
238
|
qualifiedName = `${workspaceOfLayer}:${layerName}`;
|
|
@@ -257,7 +275,7 @@ export default class StyleClient {
|
|
|
257
275
|
*
|
|
258
276
|
* @returns {Object} An object about the style or undefined if it cannot be found
|
|
259
277
|
*/
|
|
260
|
-
async getStyleInformation
|
|
278
|
+
async getStyleInformation(workspace, styleName) {
|
|
261
279
|
let url;
|
|
262
280
|
if (workspace) {
|
|
263
281
|
url = this.url + 'workspaces/' + workspace + '/styles/' + styleName + '.json';
|
package/src/util/geoserver.js
CHANGED
|
@@ -9,9 +9,10 @@
|
|
|
9
9
|
*
|
|
10
10
|
* @returns {String} The response text if available
|
|
11
11
|
*/
|
|
12
|
-
async function getGeoServerResponseText
|
|
12
|
+
async function getGeoServerResponseText(response) {
|
|
13
13
|
try {
|
|
14
|
-
return response.text()
|
|
14
|
+
return response.text();
|
|
15
|
+
// eslint-disable-next-line
|
|
15
16
|
} catch (e) {
|
|
16
17
|
// return nothing
|
|
17
18
|
}
|
|
@@ -25,17 +26,14 @@ class GeoServerResponseError extends Error {
|
|
|
25
26
|
* @param {String} [message=GeoServer Response Error] The error message
|
|
26
27
|
* @param {String} [geoServerOutput] The error output from GeoServer (useful for debugging)
|
|
27
28
|
*/
|
|
28
|
-
constructor
|
|
29
|
-
super(message)
|
|
29
|
+
constructor(message, geoServerOutput) {
|
|
30
|
+
super(message);
|
|
30
31
|
this.name = 'GeoServerResponseError';
|
|
31
|
-
this.message = message || 'GeoServer Response Error'
|
|
32
|
+
this.message = message || 'GeoServer Response Error';
|
|
32
33
|
|
|
33
34
|
// custom property as explained here: https://xjamundx.medium.com/custom-javascript-errors-in-es6-aa891b173f87
|
|
34
35
|
this.geoServerOutput = geoServerOutput;
|
|
35
36
|
}
|
|
36
37
|
}
|
|
37
38
|
|
|
38
|
-
export {
|
|
39
|
-
getGeoServerResponseText,
|
|
40
|
-
GeoServerResponseError
|
|
41
|
-
}
|
|
39
|
+
export { getGeoServerResponseText, GeoServerResponseError };
|
package/src/workspace.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import fetch from 'node-fetch';
|
|
2
2
|
import { getGeoServerResponseText, GeoServerResponseError } from './util/geoserver.js';
|
|
3
|
-
import AboutClient from './about.js'
|
|
3
|
+
import AboutClient from './about.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Client for GeoServer workspaces
|
|
@@ -16,7 +16,7 @@ export default class WorkspaceClient {
|
|
|
16
16
|
* @param {String} url The URL of the GeoServer REST API endpoint
|
|
17
17
|
* @param {String} auth The Basic Authentication string
|
|
18
18
|
*/
|
|
19
|
-
constructor
|
|
19
|
+
constructor(url, auth) {
|
|
20
20
|
this.url = url;
|
|
21
21
|
this.auth = auth;
|
|
22
22
|
}
|
|
@@ -28,7 +28,7 @@ export default class WorkspaceClient {
|
|
|
28
28
|
*
|
|
29
29
|
* @returns {Object} An Object describing the workspaces
|
|
30
30
|
*/
|
|
31
|
-
async getAll
|
|
31
|
+
async getAll() {
|
|
32
32
|
const response = await fetch(this.url + 'workspaces.json', {
|
|
33
33
|
credentials: 'include',
|
|
34
34
|
method: 'GET',
|
|
@@ -52,7 +52,7 @@ export default class WorkspaceClient {
|
|
|
52
52
|
*
|
|
53
53
|
* @returns {Object} An object describing the workspaces
|
|
54
54
|
*/
|
|
55
|
-
async get
|
|
55
|
+
async get(name) {
|
|
56
56
|
const response = await fetch(this.url + 'workspaces/' + name + '.json', {
|
|
57
57
|
credentials: 'include',
|
|
58
58
|
method: 'GET',
|
|
@@ -83,7 +83,7 @@ export default class WorkspaceClient {
|
|
|
83
83
|
*
|
|
84
84
|
* @returns {String} The name of the created workspace
|
|
85
85
|
*/
|
|
86
|
-
async create
|
|
86
|
+
async create(name) {
|
|
87
87
|
const body = {
|
|
88
88
|
workspace: {
|
|
89
89
|
name
|
|
@@ -104,7 +104,10 @@ export default class WorkspaceClient {
|
|
|
104
104
|
const geoServerResponse = await getGeoServerResponseText(response);
|
|
105
105
|
switch (response.status) {
|
|
106
106
|
case 409:
|
|
107
|
-
throw new GeoServerResponseError(
|
|
107
|
+
throw new GeoServerResponseError(
|
|
108
|
+
'Unable to add workspace as it already exists',
|
|
109
|
+
geoServerResponse
|
|
110
|
+
);
|
|
108
111
|
default:
|
|
109
112
|
throw new GeoServerResponseError(null, geoServerResponse);
|
|
110
113
|
}
|
|
@@ -122,7 +125,7 @@ export default class WorkspaceClient {
|
|
|
122
125
|
*
|
|
123
126
|
* @throws Error if request fails
|
|
124
127
|
*/
|
|
125
|
-
async delete
|
|
128
|
+
async delete(name, recurse) {
|
|
126
129
|
const response = await fetch(this.url + 'workspaces/' + name + '?recurse=' + recurse, {
|
|
127
130
|
credentials: 'include',
|
|
128
131
|
method: 'DELETE',
|
|
@@ -139,9 +142,10 @@ export default class WorkspaceClient {
|
|
|
139
142
|
// https://docs.geoserver.org/latest/en/api/#1.0.0/workspaces.yaml
|
|
140
143
|
throw new GeoServerResponseError(
|
|
141
144
|
'Workspace or related Namespace is not empty (and recurse not true)',
|
|
142
|
-
geoServerResponse
|
|
145
|
+
geoServerResponse
|
|
146
|
+
);
|
|
143
147
|
case 404:
|
|
144
|
-
throw new GeoServerResponseError(
|
|
148
|
+
throw new GeoServerResponseError("Workspace doesn't exist", geoServerResponse);
|
|
145
149
|
default:
|
|
146
150
|
throw new GeoServerResponseError(null, geoServerResponse);
|
|
147
151
|
}
|