From 345f7e6e80fc841a36fb42f5fc6a3f0a1b4cf3a2 Mon Sep 17 00:00:00 2001 From: BramJanssen Date: Mon, 20 Dec 2021 14:23:05 +0100 Subject: [PATCH] fix: added a function to normalize the namespace in case of UDP (#57) Co-authored-by: janssenb Co-authored-by: Matthias Mohr --- CHANGELOG.md | 4 ++++ openeo.d.ts | 14 ++++++++++++++ src/connection.js | 23 +++++++++++++++++++++-- 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f5faf31..71d9467a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed + +- The `namespace` parameter in `listProcesses` and `describeProcess` parses URLs to extract the namespace (experimental). + ## [2.3.1] - 2021-12-10 ### Fixed diff --git a/openeo.d.ts b/openeo.d.ts index e1ae14d9..4ea2972e 100644 --- a/openeo.d.ts +++ b/openeo.d.ts @@ -1955,6 +1955,20 @@ declare module OpenEO { * @throws {Error} */ listCollectionItems(collectionId: string, spatialExtent?: Array | null, temporalExtent?: Array | null, limit?: number | null): AsyncGenerator; + /** + * Normalisation of the namespace to a value that is compatible with the OpenEO specs - EXPERIMENTAL. + * + * This is required to support UDP that are shared as public. These can only be executed with providing the full URL + * (e.g. https:///processes//) as the namespace value in the processing graph. For other + * parts of the API (such as the listing of the processes, only the name of the namespace is required. + * + * This function will extract the short name of the namespace from a shareable URL. + * + * @protected + * @param {?string} namespace - Namespace of the process + * @returns {?string} + */ + protected normalizeNamespace(namespace: string | null): string | null; /** * List processes available on the back-end. * diff --git a/src/connection.js b/src/connection.js index 091ce2ee..3c01029d 100644 --- a/src/connection.js +++ b/src/connection.js @@ -290,6 +290,25 @@ class Connection { } } + /** + * Normalisation of the namespace to a value that is compatible with the OpenEO specs - EXPERIMENTAL. + * + * This is required to support UDP that are shared as public. These can only be executed with providing the full URL + * (e.g. https:///processes//) as the namespace value in the processing graph. For other + * parts of the API (such as the listing of the processes, only the name of the namespace is required. + * + * This function will extract the short name of the namespace from a shareable URL. + * + * @protected + * @param {?string} namespace - Namespace of the process + * @returns {?string} + */ + normalizeNamespace(namespace) { + // The pattern in https://github.com/Open-EO/openeo-api/pull/348 doesn't include the double colon yet - the regexp may change in the future + const matches = namespace.match( /^https?:\/\/.*\/processes\/(@?[\w\-.~:]+)\/?/i); + return matches && matches.length > 1 ? matches[1] : namespace; + } + /** * List processes available on the back-end. * @@ -308,7 +327,7 @@ class Connection { if (!namespace) { namespace = 'backend'; } - let path = (namespace === 'backend') ? '/processes' : `/processes/${namespace}`; + let path = (namespace === 'backend') ? '/processes' : `/processes/${this.normalizeNamespace(namespace)}`; let response = await this._get(path); if (!Utils.isObject(response.data) || !Array.isArray(response.data.processes)) { @@ -340,7 +359,7 @@ class Connection { await this.listProcesses(); } else { - let response = await this._get(`/processes/${namespace}/${processId}`); + let response = await this._get(`/processes/${this.normalizeNamespace(namespace)}/${processId}`); if (!Utils.isObject(response.data) || typeof response.data.id !== 'string') { throw new Error('Invalid response received for process'); }