@openeo/js-client 2.5.1 → 2.6.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/src/openeo.js CHANGED
@@ -1,138 +1,137 @@
1
- const axios = require('axios').default;
2
- const { AbortController } = require("node-abort-controller");
3
- const Utils = require('@openeo/js-commons/src/utils');
4
- const Versions = require('@openeo/js-commons/src/versions');
5
-
6
- // API wrapper
7
- const Connection = require('./connection');
8
- const Job = require('./job');
9
- const Logs = require('./logs');
10
- const UserFile = require('./userfile');
11
- const UserProcess = require('./userprocess');
12
- const Service = require('./service');
13
-
14
- // Auth Providers
15
- const AuthProvider = require('./authprovider');
16
- const BasicProvider = require('./basicprovider');
17
- const OidcProvider = require('./oidcprovider');
18
-
19
- // Response wrapper
20
- const Capabilities = require('./capabilities');
21
- const FileTypes = require('./filetypes');
22
-
23
- // Builder
24
- const Builder = require('./builder/builder');
25
- const BuilderNode = require('./builder/node');
26
- const Parameter = require('./builder/parameter');
27
- const Formula = require('./builder/formula');
28
-
29
- const MIN_API_VERSION = '1.0.0-rc.2';
30
- const MAX_API_VERSION = '1.x.x';
31
-
32
- /**
33
- * Main class to start with openEO. Allows to connect to a server.
34
- *
35
- * @hideconstructor
36
- */
37
- class OpenEO {
38
-
39
- /**
40
- * Connect to a back-end with version discovery (recommended).
41
- *
42
- * Includes version discovery (request to `GET /well-known/openeo`) and connects to the most suitable version compatible to this JS client version.
43
- * Requests the capabilities and authenticates where required.
44
- *
45
- * @async
46
- * @param {string} url - The server URL to connect to.
47
- * @param {Options} [options={}] - Additional options for the connection.
48
- * @returns {Promise<Connection>}
49
- * @throws {Error}
50
- * @static
51
- */
52
- static async connect(url, options = {}) {
53
- let wellKnownUrl = Utils.normalizeUrl(url, '/.well-known/openeo');
54
- let versionedUrl = url;
55
- let response = null;
56
- try {
57
- response = await axios.get(wellKnownUrl, {timeout: 5000});
58
-
59
- if (!Utils.isObject(response.data) || !Array.isArray(response.data.versions)) {
60
- throw new Error("Well-Known Document doesn't list any versions.");
61
- }
62
- } catch(error) {
63
- console.warn("Can't read well-known document, connecting directly to the specified URL as fallback mechanism. Reason: " + error.message);
64
- }
65
-
66
- if (Utils.isObject(response)) {
67
- let version = Versions.findLatest(response.data.versions, true, MIN_API_VERSION, MAX_API_VERSION);
68
- if (version !== null) {
69
- versionedUrl = version.url;
70
- }
71
- else {
72
- throw new Error("Server not supported. Client only supports the API versions between " + MIN_API_VERSION + " and " + MAX_API_VERSION);
73
- }
74
- }
75
-
76
- let connection = await OpenEO.connectDirect(versionedUrl, options);
77
- connection.url = url;
78
- return connection;
79
- }
80
-
81
- /**
82
- * Connects directly to a back-end instance, without version discovery (NOT recommended).
83
- *
84
- * Doesn't do version discovery, therefore a URL of a versioned API must be specified. Requests the capabilities and authenticates where required.
85
- *
86
- * @async
87
- * @param {string} versionedUrl - The server URL to connect to.
88
- * @param {Options} [options={}] - Additional options for the connection.
89
- * @returns {Promise<Connection>}
90
- * @throws {Error}
91
- * @static
92
- */
93
- static async connectDirect(versionedUrl, options = {}) {
94
- let connection = new Connection(versionedUrl, options);
95
-
96
- // Check whether back-end is accessible and supports a compatible version.
97
- let capabilities = await connection.init();
98
- if (Versions.compare(capabilities.apiVersion(), MIN_API_VERSION, "<") || Versions.compare(capabilities.apiVersion(), MAX_API_VERSION, ">")) {
99
- throw new Error("Client only supports the API versions between " + MIN_API_VERSION + " and " + MAX_API_VERSION);
100
- }
101
-
102
- return connection;
103
- }
104
-
105
- /**
106
- * Returns the version number of the client.
107
- *
108
- * Not to confuse with the API version(s) supported by the client.
109
- *
110
- * @returns {string} Version number (according to SemVer).
111
- */
112
- static clientVersion() {
113
- return "2.5.1";
114
- }
115
-
116
- }
117
-
118
- OpenEO.Environment = require('./env');
119
-
120
- module.exports = {
121
- AbortController,
122
- AuthProvider,
123
- BasicProvider,
124
- Capabilities,
125
- Connection,
126
- FileTypes,
127
- Job,
128
- Logs,
129
- OidcProvider,
130
- OpenEO,
131
- Service,
132
- UserFile,
133
- UserProcess,
134
- Builder,
135
- BuilderNode,
136
- Parameter,
137
- Formula
138
- };
1
+ const axios = require('axios');
2
+ const Utils = require('@openeo/js-commons/src/utils');
3
+ const Versions = require('@openeo/js-commons/src/versions');
4
+
5
+ // API wrapper
6
+ const Connection = require('./connection');
7
+ const Job = require('./job');
8
+ const Logs = require('./logs');
9
+ const UserFile = require('./userfile');
10
+ const UserProcess = require('./userprocess');
11
+ const Service = require('./service');
12
+
13
+ // Auth Providers
14
+ const AuthProvider = require('./authprovider');
15
+ const BasicProvider = require('./basicprovider');
16
+ const OidcProvider = require('./oidcprovider');
17
+
18
+ // Response wrapper
19
+ const Capabilities = require('./capabilities');
20
+ const FileTypes = require('./filetypes');
21
+
22
+ // Builder
23
+ const Builder = require('./builder/builder');
24
+ const BuilderNode = require('./builder/node');
25
+ const Parameter = require('./builder/parameter');
26
+ const Formula = require('./builder/formula');
27
+
28
+ const MIN_API_VERSION = '1.0.0-rc.2';
29
+ const MAX_API_VERSION = '1.x.x';
30
+
31
+ /**
32
+ * Main class to start with openEO. Allows to connect to a server.
33
+ *
34
+ * @hideconstructor
35
+ */
36
+ class OpenEO {
37
+
38
+ /**
39
+ * Connect to a back-end with version discovery (recommended).
40
+ *
41
+ * Includes version discovery (request to `GET /well-known/openeo`) and connects to the most suitable version compatible to this JS client version.
42
+ * Requests the capabilities and authenticates where required.
43
+ *
44
+ * @async
45
+ * @param {string} url - The server URL to connect to.
46
+ * @param {Options} [options={}] - Additional options for the connection.
47
+ * @returns {Promise<Connection>}
48
+ * @throws {Error}
49
+ * @static
50
+ */
51
+ static async connect(url, options = {}) {
52
+ let wellKnownUrl = Utils.normalizeUrl(url, '/.well-known/openeo');
53
+ let versionedUrl = url;
54
+ let response = null;
55
+ try {
56
+ response = await axios.get(wellKnownUrl, {timeout: 5000});
57
+
58
+ if (!Utils.isObject(response.data) || !Array.isArray(response.data.versions)) {
59
+ throw new Error("Well-Known Document doesn't list any versions.");
60
+ }
61
+ } catch(error) {
62
+ console.warn("Can't read well-known document, connecting directly to the specified URL as fallback mechanism. Reason: " + error.message);
63
+ }
64
+
65
+ if (Utils.isObject(response)) {
66
+ let version = Versions.findLatest(response.data.versions, true, MIN_API_VERSION, MAX_API_VERSION);
67
+ if (version !== null) {
68
+ versionedUrl = version.url;
69
+ }
70
+ else {
71
+ throw new Error("Server not supported. Client only supports the API versions between " + MIN_API_VERSION + " and " + MAX_API_VERSION);
72
+ }
73
+ }
74
+
75
+ let connection = await OpenEO.connectDirect(versionedUrl, options);
76
+ connection.url = url;
77
+ return connection;
78
+ }
79
+
80
+ /**
81
+ * Connects directly to a back-end instance, without version discovery (NOT recommended).
82
+ *
83
+ * Doesn't do version discovery, therefore a URL of a versioned API must be specified. Requests the capabilities and authenticates where required.
84
+ *
85
+ * @async
86
+ * @param {string} versionedUrl - The server URL to connect to.
87
+ * @param {Options} [options={}] - Additional options for the connection.
88
+ * @returns {Promise<Connection>}
89
+ * @throws {Error}
90
+ * @static
91
+ */
92
+ static async connectDirect(versionedUrl, options = {}) {
93
+ let connection = new Connection(versionedUrl, options);
94
+
95
+ // Check whether back-end is accessible and supports a compatible version.
96
+ let capabilities = await connection.init();
97
+ if (Versions.compare(capabilities.apiVersion(), MIN_API_VERSION, "<") || Versions.compare(capabilities.apiVersion(), MAX_API_VERSION, ">")) {
98
+ throw new Error("Client only supports the API versions between " + MIN_API_VERSION + " and " + MAX_API_VERSION);
99
+ }
100
+
101
+ return connection;
102
+ }
103
+
104
+ /**
105
+ * Returns the version number of the client.
106
+ *
107
+ * Not to confuse with the API version(s) supported by the client.
108
+ *
109
+ * @returns {string} Version number (according to SemVer).
110
+ */
111
+ static clientVersion() {
112
+ return "2.6.0";
113
+ }
114
+
115
+ }
116
+
117
+ OpenEO.Environment = require('./env');
118
+
119
+ module.exports = {
120
+ AbortController,
121
+ AuthProvider,
122
+ BasicProvider,
123
+ Capabilities,
124
+ Connection,
125
+ FileTypes,
126
+ Job,
127
+ Logs,
128
+ OidcProvider,
129
+ OpenEO,
130
+ Service,
131
+ UserFile,
132
+ UserProcess,
133
+ Builder,
134
+ BuilderNode,
135
+ Parameter,
136
+ Formula
137
+ };