geoserver-node-client 0.0.5 → 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/LICENSE +25 -0
- package/README.md +81 -9
- package/dist/geoserver-rest-client.js +87 -0
- package/dist/package.json +55 -0
- package/dist/src/about.js +145 -0
- package/dist/src/datastore.js +1050 -0
- package/dist/src/imagemosaic.js +297 -0
- package/dist/src/layer.js +1040 -0
- package/dist/src/namespace.js +315 -0
- package/dist/src/security.js +297 -0
- package/dist/src/settings.js +345 -0
- package/dist/src/style.js +597 -0
- package/dist/src/util/geoserver.js +97 -0
- package/dist/src/workspace.js +321 -0
- package/geoserver-rest-client.js +15 -52
- package/package.json +28 -10
- package/src/about.js +59 -0
- package/src/datastore.js +161 -200
- package/src/imagemosaic.js +74 -97
- package/src/layer.js +376 -332
- package/src/namespace.js +84 -83
- package/src/security.js +61 -84
- package/src/settings.js +76 -91
- package/src/style.js +200 -147
- package/src/util/geoserver.js +41 -0
- package/src/workspace.js +89 -81
- package/.eslintrc.json +0 -20
- package/.github/workflows/ci-geoserver-node-client.yml +0 -54
- package/.github/workflows/ci-publish-docs.yml +0 -24
- package/.github/workflows/wait-for.sh +0 -145
- package/DOCS_HOME.md +0 -24
- package/demo/index.js +0 -188
- package/release-it.json +0 -8
- package/test/sample_data/iceland.gpkg +0 -0
- package/test/sample_data/world.geotiff +0 -0
- package/test/test.js +0 -491
package/src/namespace.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import fetch from 'node-fetch';
|
|
2
|
+
import { getGeoServerResponseText, GeoServerResponseError } from './util/geoserver.js';
|
|
3
|
+
import AboutClient from './about.js'
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
6
|
* Client for GeoServer namespace
|
|
@@ -10,36 +12,33 @@ export default class NamespaceClient {
|
|
|
10
12
|
* Creates a GeoServer REST NamespaceClient instance.
|
|
11
13
|
*
|
|
12
14
|
* @param {String} url The URL of the GeoServer REST API endpoint
|
|
13
|
-
* @param {String}
|
|
14
|
-
* @param {String} password The password for the GeoServer REST API
|
|
15
|
+
* @param {String} auth The Basic Authentication string
|
|
15
16
|
*/
|
|
16
|
-
constructor (url,
|
|
17
|
-
this.url = url
|
|
18
|
-
this.
|
|
19
|
-
this.password = password;
|
|
17
|
+
constructor (url, auth) {
|
|
18
|
+
this.url = url;
|
|
19
|
+
this.auth = auth;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
23
|
* Returns all namespaces.
|
|
24
24
|
*
|
|
25
|
-
* @
|
|
25
|
+
* @throws Error if request fails
|
|
26
|
+
*
|
|
27
|
+
* @returns {Object} An object describing the namespace
|
|
26
28
|
*/
|
|
27
29
|
async getAll () {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const json = await response.json();
|
|
39
|
-
return json;
|
|
40
|
-
} catch (error) {
|
|
41
|
-
return false;
|
|
30
|
+
const response = await fetch(this.url + 'namespaces.json', {
|
|
31
|
+
credentials: 'include',
|
|
32
|
+
method: 'GET',
|
|
33
|
+
headers: {
|
|
34
|
+
Authorization: this.auth
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
if (!response.ok) {
|
|
38
|
+
const geoServerResponse = await getGeoServerResponseText(response);
|
|
39
|
+
throw new GeoServerResponseError(null, geoServerResponse);
|
|
42
40
|
}
|
|
41
|
+
return response.json();
|
|
43
42
|
}
|
|
44
43
|
|
|
45
44
|
/**
|
|
@@ -48,66 +47,65 @@ export default class NamespaceClient {
|
|
|
48
47
|
* @param {String} prefix Prefix of the new namespace
|
|
49
48
|
* @param {String} uri Uri of the new namespace
|
|
50
49
|
*
|
|
51
|
-
* @
|
|
50
|
+
* @throws Error if request fails
|
|
51
|
+
*
|
|
52
|
+
* @returns {String} The name of the created namespace
|
|
52
53
|
*/
|
|
53
54
|
async create (prefix, uri) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
const auth =
|
|
63
|
-
Buffer.from(this.user + ':' + this.password).toString('base64');
|
|
55
|
+
const body = {
|
|
56
|
+
namespace: {
|
|
57
|
+
prefix: prefix,
|
|
58
|
+
uri: uri
|
|
59
|
+
}
|
|
60
|
+
};
|
|
64
61
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
62
|
+
const response = await fetch(this.url + 'namespaces', {
|
|
63
|
+
credentials: 'include',
|
|
64
|
+
method: 'POST',
|
|
65
|
+
headers: {
|
|
66
|
+
Authorization: this.auth,
|
|
67
|
+
'Content-Type': 'application/json'
|
|
68
|
+
},
|
|
69
|
+
body: JSON.stringify(body)
|
|
70
|
+
});
|
|
74
71
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
} else {
|
|
79
|
-
return false;
|
|
80
|
-
}
|
|
81
|
-
} catch (error) {
|
|
82
|
-
return false;
|
|
72
|
+
if (!response.ok) {
|
|
73
|
+
const geoServerResponse = await getGeoServerResponseText(response);
|
|
74
|
+
throw new GeoServerResponseError(null, geoServerResponse);
|
|
83
75
|
}
|
|
76
|
+
|
|
77
|
+
return response.text();
|
|
84
78
|
}
|
|
85
79
|
|
|
86
80
|
/**
|
|
87
81
|
* Returns a namespace.
|
|
88
82
|
*
|
|
89
83
|
* @param {String} name Name of the namespace
|
|
90
|
-
*
|
|
84
|
+
*
|
|
85
|
+
* @throws Error if request fails
|
|
86
|
+
*
|
|
87
|
+
* @returns {Object} An object describing the namespace or undefined if it cannot be found
|
|
91
88
|
*/
|
|
92
89
|
async get (name) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
return
|
|
90
|
+
const response = await fetch(this.url + 'namespaces/' + name + '.json', {
|
|
91
|
+
credentials: 'include',
|
|
92
|
+
method: 'GET',
|
|
93
|
+
headers: {
|
|
94
|
+
Authorization: this.auth
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
if (!response.ok) {
|
|
98
|
+
const grc = new AboutClient(this.url, this.auth);
|
|
99
|
+
if (await grc.exists()) {
|
|
100
|
+
// GeoServer exists, but requested item does not exist, we return empty
|
|
101
|
+
return;
|
|
105
102
|
} else {
|
|
106
|
-
|
|
103
|
+
// There was a general problem with GeoServer
|
|
104
|
+
const geoServerResponse = await getGeoServerResponseText(response);
|
|
105
|
+
throw new GeoServerResponseError(null, geoServerResponse);
|
|
107
106
|
}
|
|
108
|
-
} catch (error) {
|
|
109
|
-
return false;
|
|
110
107
|
}
|
|
108
|
+
return response.json();
|
|
111
109
|
}
|
|
112
110
|
|
|
113
111
|
/**
|
|
@@ -115,28 +113,31 @@ export default class NamespaceClient {
|
|
|
115
113
|
*
|
|
116
114
|
* @param {String} name Name of the namespace to delete
|
|
117
115
|
*
|
|
118
|
-
* @
|
|
116
|
+
* @throws Error if request fails
|
|
119
117
|
*/
|
|
120
118
|
async delete (name) {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
Authorization: 'Basic ' + auth
|
|
129
|
-
}
|
|
130
|
-
});
|
|
119
|
+
const response = await fetch(this.url + 'namespaces/' + name, {
|
|
120
|
+
credentials: 'include',
|
|
121
|
+
method: 'DELETE',
|
|
122
|
+
headers: {
|
|
123
|
+
Authorization: this.auth
|
|
124
|
+
}
|
|
125
|
+
});
|
|
131
126
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
127
|
+
if (!response.ok) {
|
|
128
|
+
const geoServerResponse = await getGeoServerResponseText(response);
|
|
129
|
+
switch (response.status) {
|
|
130
|
+
case 403:
|
|
131
|
+
throw new GeoServerResponseError(
|
|
132
|
+
'Namespace or related Workspace is not empty (and recurse not true)',
|
|
133
|
+
geoServerResponse);
|
|
134
|
+
case 404:
|
|
135
|
+
throw new GeoServerResponseError('Namespace doesn\'t exist', geoServerResponse);
|
|
136
|
+
case 405:
|
|
137
|
+
throw new GeoServerResponseError('Can\'t delete default namespace', geoServerResponse);
|
|
138
|
+
default:
|
|
139
|
+
throw new GeoServerResponseError('Response not recognized', geoServerResponse)
|
|
137
140
|
}
|
|
138
|
-
} catch (error) {
|
|
139
|
-
return false;
|
|
140
141
|
}
|
|
141
142
|
}
|
|
142
143
|
}
|
package/src/security.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import fetch from 'node-fetch';
|
|
2
|
+
import { getGeoServerResponseText, GeoServerResponseError } from './util/geoserver.js';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Client for GeoServer security.
|
|
@@ -10,39 +11,34 @@ export default class SecurityClient {
|
|
|
10
11
|
* Creates a GeoServer REST SecurityClient instance.
|
|
11
12
|
*
|
|
12
13
|
* @param {String} url The URL of the GeoServer REST API endpoint
|
|
13
|
-
* @param {String}
|
|
14
|
-
* @param {String} password The password for the GeoServer REST API
|
|
14
|
+
* @param {String} auth The Basic Authentication string
|
|
15
15
|
*/
|
|
16
|
-
constructor (url,
|
|
17
|
-
this.url = url
|
|
18
|
-
this.
|
|
19
|
-
this.password = password;
|
|
16
|
+
constructor (url, auth) {
|
|
17
|
+
this.url = url;
|
|
18
|
+
this.auth = auth;
|
|
20
19
|
}
|
|
21
20
|
|
|
22
|
-
// TODO: I could not get it working, got Code '406'
|
|
23
21
|
/**
|
|
24
22
|
* Returns all users registered in GeoServer.
|
|
23
|
+
*
|
|
24
|
+
* @throws Error if request fails
|
|
25
|
+
*
|
|
26
|
+
* @returns {Object} An object with all users
|
|
25
27
|
*/
|
|
26
28
|
async getAllUsers () {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
headers: {
|
|
33
|
-
Authorization: 'Basic ' + auth
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
if (response.status === 200) {
|
|
38
|
-
return await response.json();
|
|
39
|
-
} else {
|
|
40
|
-
console.warn(await response.text());
|
|
41
|
-
return false;
|
|
29
|
+
const response = await fetch(this.url + 'security/usergroup/users.json', {
|
|
30
|
+
credentials: 'include',
|
|
31
|
+
method: 'GET',
|
|
32
|
+
headers: {
|
|
33
|
+
Authorization: this.auth
|
|
42
34
|
}
|
|
43
|
-
}
|
|
44
|
-
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
if (!response.ok) {
|
|
38
|
+
const geoServerResponse = await getGeoServerResponseText(response);
|
|
39
|
+
throw new GeoServerResponseError(null, geoServerResponse);
|
|
45
40
|
}
|
|
41
|
+
return response.json();
|
|
46
42
|
}
|
|
47
43
|
|
|
48
44
|
/**
|
|
@@ -51,7 +47,7 @@ export default class SecurityClient {
|
|
|
51
47
|
* @param {String} username The name of the user to be created
|
|
52
48
|
* @param {String} password The password of the user to be created
|
|
53
49
|
*
|
|
54
|
-
* @
|
|
50
|
+
* @throws Error if request fails
|
|
55
51
|
*/
|
|
56
52
|
async createUser (username, password) {
|
|
57
53
|
const body = {
|
|
@@ -62,28 +58,24 @@ export default class SecurityClient {
|
|
|
62
58
|
}
|
|
63
59
|
};
|
|
64
60
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
body: JSON.stringify(body)
|
|
75
|
-
});
|
|
61
|
+
const response = await fetch(this.url + 'security/usergroup/users.json', {
|
|
62
|
+
credentials: 'include',
|
|
63
|
+
method: 'POST',
|
|
64
|
+
headers: {
|
|
65
|
+
Authorization: this.auth,
|
|
66
|
+
'Content-Type': 'application/json'
|
|
67
|
+
},
|
|
68
|
+
body: JSON.stringify(body)
|
|
69
|
+
});
|
|
76
70
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
71
|
+
if (!response.ok) {
|
|
72
|
+
const geoServerResponse = await getGeoServerResponseText(response);
|
|
73
|
+
switch (response.status) {
|
|
74
|
+
case 404:
|
|
75
|
+
throw new GeoServerResponseError(`User ${username} might already exists.`, geoServerResponse);
|
|
76
|
+
default:
|
|
77
|
+
throw new GeoServerResponseError(null, geoServerResponse);
|
|
84
78
|
}
|
|
85
|
-
} catch (error) {
|
|
86
|
-
return false;
|
|
87
79
|
}
|
|
88
80
|
}
|
|
89
81
|
|
|
@@ -95,7 +87,7 @@ export default class SecurityClient {
|
|
|
95
87
|
* @param {String} password The password of the user to be created
|
|
96
88
|
* @param {Boolean} enabled Enable / disable the user
|
|
97
89
|
*
|
|
98
|
-
* @
|
|
90
|
+
* @throws Error if request fails
|
|
99
91
|
*/
|
|
100
92
|
async updateUser (username, password, enabled) {
|
|
101
93
|
const body = {
|
|
@@ -105,26 +97,19 @@ export default class SecurityClient {
|
|
|
105
97
|
}
|
|
106
98
|
};
|
|
107
99
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
body: JSON.stringify(body)
|
|
118
|
-
});
|
|
100
|
+
const response = await fetch(this.url + 'security/usergroup/user/' + username, {
|
|
101
|
+
credentials: 'include',
|
|
102
|
+
method: 'POST',
|
|
103
|
+
headers: {
|
|
104
|
+
Authorization: this.auth,
|
|
105
|
+
'Content-Type': 'application/json'
|
|
106
|
+
},
|
|
107
|
+
body: JSON.stringify(body)
|
|
108
|
+
});
|
|
119
109
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
console.warn(await response.text());
|
|
124
|
-
return false;
|
|
125
|
-
}
|
|
126
|
-
} catch (error) {
|
|
127
|
-
return false;
|
|
110
|
+
if (!response.ok) {
|
|
111
|
+
const geoServerResponse = await getGeoServerResponseText(response);
|
|
112
|
+
throw new GeoServerResponseError(null, geoServerResponse);
|
|
128
113
|
}
|
|
129
114
|
}
|
|
130
115
|
|
|
@@ -134,28 +119,20 @@ export default class SecurityClient {
|
|
|
134
119
|
* @param {String} username The name of the user to add the role to
|
|
135
120
|
* @param {String} role The role to associate
|
|
136
121
|
*
|
|
137
|
-
* @
|
|
122
|
+
* @throws Error if request fails
|
|
138
123
|
*/
|
|
139
124
|
async associateUserRole (username, role) {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
method: 'POST',
|
|
146
|
-
headers: {
|
|
147
|
-
Authorization: 'Basic ' + auth
|
|
148
|
-
}
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
if (response.status === 200) {
|
|
152
|
-
return true;
|
|
153
|
-
} else {
|
|
154
|
-
console.warn(await response.text());
|
|
155
|
-
return false;
|
|
125
|
+
const response = await fetch(`${this.url}security/roles/role/${role}/user/${username}`, {
|
|
126
|
+
credentials: 'include',
|
|
127
|
+
method: 'POST',
|
|
128
|
+
headers: {
|
|
129
|
+
Authorization: this.auth
|
|
156
130
|
}
|
|
157
|
-
}
|
|
158
|
-
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
if (!response.ok) {
|
|
134
|
+
const geoServerResponse = await getGeoServerResponseText(response);
|
|
135
|
+
throw new GeoServerResponseError(null, geoServerResponse);
|
|
159
136
|
}
|
|
160
137
|
}
|
|
161
138
|
}
|
package/src/settings.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import fetch from 'node-fetch';
|
|
2
|
+
import { getGeoServerResponseText, GeoServerResponseError } from './util/geoserver.js';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Client for GeoServer settings.
|
|
@@ -10,60 +11,54 @@ export default class SettingsClient {
|
|
|
10
11
|
* Creates a GeoServer REST SettingsClient instance.
|
|
11
12
|
*
|
|
12
13
|
* @param {String} url The URL of the GeoServer REST API endpoint
|
|
13
|
-
* @param {String}
|
|
14
|
-
* @param {String} password The password for the GeoServer REST API
|
|
14
|
+
* @param {String} auth The Basic Authentication string
|
|
15
15
|
*/
|
|
16
|
-
constructor (url,
|
|
17
|
-
this.url = url
|
|
18
|
-
this.
|
|
19
|
-
this.password = password;
|
|
16
|
+
constructor (url, auth) {
|
|
17
|
+
this.url = url;
|
|
18
|
+
this.auth = auth;
|
|
20
19
|
}
|
|
21
20
|
|
|
22
21
|
/**
|
|
23
22
|
* Get the complete GeoServer settings object.
|
|
24
23
|
*
|
|
25
|
-
* @
|
|
24
|
+
* @throws Error if request fails
|
|
25
|
+
*
|
|
26
|
+
* @returns {Object} Settings object
|
|
26
27
|
*/
|
|
27
28
|
async getSettings () {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
return await response.json();
|
|
39
|
-
} catch (error) {
|
|
40
|
-
return false;
|
|
29
|
+
const response = await fetch(this.url + 'settings.json', {
|
|
30
|
+
credentials: 'include',
|
|
31
|
+
method: 'GET',
|
|
32
|
+
headers: {
|
|
33
|
+
Authorization: this.auth
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
if (!response.ok) {
|
|
37
|
+
const geoServerResponse = await getGeoServerResponseText(response);
|
|
38
|
+
throw new GeoServerResponseError(null, geoServerResponse);
|
|
41
39
|
}
|
|
40
|
+
return response.json();
|
|
42
41
|
}
|
|
43
42
|
|
|
44
43
|
/**
|
|
45
44
|
* Update the global GeoServer settings.
|
|
46
45
|
*
|
|
47
|
-
* @param {
|
|
48
|
-
* @returns {Boolean} Flag indicating if request was successful
|
|
46
|
+
* @param {Object} settings The adapted GeoServer settings object
|
|
49
47
|
*/
|
|
50
48
|
async updateSettings (settings) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
},
|
|
61
|
-
body: JSON.stringify(settings)
|
|
62
|
-
});
|
|
49
|
+
const response = await fetch(this.url + 'settings', {
|
|
50
|
+
credentials: 'include',
|
|
51
|
+
method: 'PUT',
|
|
52
|
+
headers: {
|
|
53
|
+
Authorization: this.auth,
|
|
54
|
+
'Content-Type': 'application/json'
|
|
55
|
+
},
|
|
56
|
+
body: JSON.stringify(settings)
|
|
57
|
+
});
|
|
63
58
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
59
|
+
if (!response.ok) {
|
|
60
|
+
const geoServerResponse = await getGeoServerResponseText(response);
|
|
61
|
+
throw new GeoServerResponseError(null, geoServerResponse);
|
|
67
62
|
}
|
|
68
63
|
}
|
|
69
64
|
|
|
@@ -71,42 +66,41 @@ export default class SettingsClient {
|
|
|
71
66
|
* Update the global proxyBaseUrl setting.
|
|
72
67
|
*
|
|
73
68
|
* @param {String} proxyBaseUrl The proxy base URL
|
|
74
|
-
* @returns {Boolean} Flag indicating if request was successful
|
|
75
69
|
*/
|
|
76
70
|
async updateProxyBaseUrl (proxyBaseUrl) {
|
|
77
71
|
const settingsJson = await this.getSettings();
|
|
78
72
|
|
|
73
|
+
// check if settings are correctly formatted
|
|
79
74
|
if (!settingsJson.global && !settingsJson.global.settings) {
|
|
80
|
-
// settings seem to be wrongly formated
|
|
81
75
|
return false;
|
|
82
76
|
}
|
|
83
77
|
|
|
84
78
|
// add proxyBaseUrl to settings
|
|
85
79
|
settingsJson.global.settings.proxyBaseUrl = proxyBaseUrl;
|
|
86
80
|
|
|
87
|
-
|
|
81
|
+
await this.updateSettings(settingsJson);
|
|
88
82
|
}
|
|
89
83
|
|
|
90
84
|
/**
|
|
91
85
|
* Get the contact information of the GeoServer.
|
|
92
86
|
*
|
|
93
|
-
* @
|
|
87
|
+
* @throws Error if request fails
|
|
88
|
+
*
|
|
89
|
+
* @returns {Object} An object with contact information
|
|
94
90
|
*/
|
|
95
91
|
async getContactInformation () {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
return await response.json();
|
|
107
|
-
} catch (error) {
|
|
108
|
-
return false;
|
|
92
|
+
const response = await fetch(this.url + 'settings/contact', {
|
|
93
|
+
credentials: 'include',
|
|
94
|
+
method: 'GET',
|
|
95
|
+
headers: {
|
|
96
|
+
Authorization: this.auth
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
if (!response.ok) {
|
|
100
|
+
const geoServerResponse = await getGeoServerResponseText(response);
|
|
101
|
+
throw new GeoServerResponseError(null, geoServerResponse);
|
|
109
102
|
}
|
|
103
|
+
return response.json();
|
|
110
104
|
}
|
|
111
105
|
|
|
112
106
|
/**
|
|
@@ -124,47 +118,38 @@ export default class SettingsClient {
|
|
|
124
118
|
* @param {String} [contactPerson] The contact person
|
|
125
119
|
* @param {String} [phoneNumber] The contact's phone number
|
|
126
120
|
*
|
|
127
|
-
* @
|
|
121
|
+
* @throws Error if request fails
|
|
128
122
|
*/
|
|
129
123
|
async updateContactInformation (address, city, country, postalCode, state, email, organization, contactPerson, phoneNumber) {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
const body = {
|
|
144
|
-
contact: contact
|
|
145
|
-
};
|
|
124
|
+
const contact = {
|
|
125
|
+
address: address,
|
|
126
|
+
addressCity: city,
|
|
127
|
+
addressCountry: country,
|
|
128
|
+
addressPostalCode: postalCode,
|
|
129
|
+
addressState: state,
|
|
130
|
+
contactEmail: email,
|
|
131
|
+
contactOrganization: organization,
|
|
132
|
+
contactPerson: contactPerson,
|
|
133
|
+
contactVoice: phoneNumber
|
|
134
|
+
};
|
|
146
135
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
credentials: 'include',
|
|
151
|
-
method: 'PUT',
|
|
152
|
-
headers: {
|
|
153
|
-
Authorization: 'Basic ' + auth,
|
|
154
|
-
'Content-Type': 'application/json'
|
|
155
|
-
},
|
|
156
|
-
body: JSON.stringify(body)
|
|
157
|
-
});
|
|
136
|
+
const body = {
|
|
137
|
+
contact: contact
|
|
138
|
+
};
|
|
158
139
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
140
|
+
const url = this.url + 'settings/contact';
|
|
141
|
+
const response = await fetch(url, {
|
|
142
|
+
credentials: 'include',
|
|
143
|
+
method: 'PUT',
|
|
144
|
+
headers: {
|
|
145
|
+
Authorization: this.auth,
|
|
146
|
+
'Content-Type': 'application/json'
|
|
147
|
+
},
|
|
148
|
+
body: JSON.stringify(body)
|
|
149
|
+
});
|
|
150
|
+
if (!response.ok) {
|
|
151
|
+
const geoServerResponse = await getGeoServerResponseText(response);
|
|
152
|
+
throw new GeoServerResponseError(null, geoServerResponse);
|
|
168
153
|
}
|
|
169
154
|
}
|
|
170
155
|
}
|