From d51d1abf6e1b524daaca906072e2d8891a356c8e Mon Sep 17 00:00:00 2001 From: Florent Gravin Date: Sat, 2 Dec 2023 16:58:09 +0100 Subject: [PATCH 1/4] chore: add semver dependency to compare semantic version of backend API --- package-lock.json | 319 +++++++++++++++++++++++++++++++++++++++++----- package.json | 1 + 2 files changed, 287 insertions(+), 33 deletions(-) diff --git a/package-lock.json b/package-lock.json index 159b377f88..a938a8fa4f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -60,6 +60,7 @@ "pg": "^8.9.0", "reflect-metadata": "^0.1.13", "rxjs": "^7.0.0", + "semver": "^7.5.4", "tippy.js": "^6.3.7", "tslib": "^2.3.0", "typeorm": "^0.3.14", @@ -921,17 +922,6 @@ "@esbuild/win32-x64": "0.18.17" } }, - "node_modules/@angular-devkit/build-angular/node_modules/lru-cache": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", - "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", - "dependencies": { - "yallist": "^4.0.0" - }, - "engines": { - "node": ">=10" - } - }, "node_modules/@angular-devkit/build-angular/node_modules/magic-string": { "version": "0.30.1", "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.1.tgz", @@ -970,25 +960,6 @@ "node": "^10 || ^12 || >=14" } }, - "node_modules/@angular-devkit/build-angular/node_modules/semver": { - "version": "7.5.4", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz", - "integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==", - "dependencies": { - "lru-cache": "^6.0.0" - }, - "bin": { - "semver": "bin/semver.js" - }, - "engines": { - "node": ">=10" - } - }, - "node_modules/@angular-devkit/build-angular/node_modules/yallist": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", - "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" - }, "node_modules/@angular-devkit/build-webpack": { "version": "0.1602.0", "resolved": "https://registry.npmjs.org/@angular-devkit/build-webpack/-/build-webpack-0.1602.0.tgz", @@ -1278,6 +1249,39 @@ "yarn": ">= 1.13.0" } }, + "node_modules/@angular/cli/node_modules/lru-cache": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", + "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "dev": true, + "dependencies": { + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/@angular/cli/node_modules/semver": { + "version": "7.5.3", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.3.tgz", + "integrity": "sha512-QBlUtyVk/5EeHbi7X0fw6liDZc7BBmEaSYn01fMU1OUYbf6GPsbTtd8WmnqbI20SeycoHSeiybkE/q1Q+qlThQ==", + "dev": true, + "dependencies": { + "lru-cache": "^6.0.0" + }, + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/@angular/cli/node_modules/yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", + "dev": true + }, "node_modules/@angular/common": { "version": "16.1.7", "resolved": "https://registry.npmjs.org/@angular/common/-/common-16.1.7.tgz", @@ -6788,6 +6792,17 @@ "node": ">=8" } }, + "node_modules/@nx/angular/node_modules/lru-cache": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", + "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "dependencies": { + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/@nx/angular/node_modules/magic-string": { "version": "0.26.7", "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.26.7.tgz", @@ -6799,6 +6814,20 @@ "node": ">=12" } }, + "node_modules/@nx/angular/node_modules/semver": { + "version": "7.5.3", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.3.tgz", + "integrity": "sha512-QBlUtyVk/5EeHbi7X0fw6liDZc7BBmEaSYn01fMU1OUYbf6GPsbTtd8WmnqbI20SeycoHSeiybkE/q1Q+qlThQ==", + "dependencies": { + "lru-cache": "^6.0.0" + }, + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/@nx/angular/node_modules/supports-color": { "version": "7.2.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", @@ -6810,6 +6839,11 @@ "node": ">=8" } }, + "node_modules/@nx/angular/node_modules/yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" + }, "node_modules/@nx/cypress": { "version": "16.6.0", "resolved": "https://registry.npmjs.org/@nx/cypress/-/cypress-16.6.0.tgz", @@ -6834,6 +6868,36 @@ } } }, + "node_modules/@nx/cypress/node_modules/lru-cache": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", + "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "dependencies": { + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/@nx/cypress/node_modules/semver": { + "version": "7.5.3", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.3.tgz", + "integrity": "sha512-QBlUtyVk/5EeHbi7X0fw6liDZc7BBmEaSYn01fMU1OUYbf6GPsbTtd8WmnqbI20SeycoHSeiybkE/q1Q+qlThQ==", + "dependencies": { + "lru-cache": "^6.0.0" + }, + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/@nx/cypress/node_modules/yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" + }, "node_modules/@nx/devkit": { "version": "16.6.0", "resolved": "https://registry.npmjs.org/@nx/devkit/-/devkit-16.6.0.tgz", @@ -6850,6 +6914,36 @@ "nx": ">= 15 <= 17" } }, + "node_modules/@nx/devkit/node_modules/lru-cache": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", + "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "dependencies": { + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/@nx/devkit/node_modules/semver": { + "version": "7.5.3", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.3.tgz", + "integrity": "sha512-QBlUtyVk/5EeHbi7X0fw6liDZc7BBmEaSYn01fMU1OUYbf6GPsbTtd8WmnqbI20SeycoHSeiybkE/q1Q+qlThQ==", + "dependencies": { + "lru-cache": "^6.0.0" + }, + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/@nx/devkit/node_modules/yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" + }, "node_modules/@nx/eslint-plugin": { "version": "16.6.0", "resolved": "https://registry.npmjs.org/@nx/eslint-plugin/-/eslint-plugin-16.6.0.tgz", @@ -6992,6 +7086,33 @@ "node": ">=8" } }, + "node_modules/@nx/eslint-plugin/node_modules/lru-cache": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", + "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "dev": true, + "dependencies": { + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/@nx/eslint-plugin/node_modules/semver": { + "version": "7.5.3", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.3.tgz", + "integrity": "sha512-QBlUtyVk/5EeHbi7X0fw6liDZc7BBmEaSYn01fMU1OUYbf6GPsbTtd8WmnqbI20SeycoHSeiybkE/q1Q+qlThQ==", + "dev": true, + "dependencies": { + "lru-cache": "^6.0.0" + }, + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/@nx/eslint-plugin/node_modules/supports-color": { "version": "7.2.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", @@ -7004,6 +7125,12 @@ "node": ">=8" } }, + "node_modules/@nx/eslint-plugin/node_modules/yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", + "dev": true + }, "node_modules/@nx/jest": { "version": "16.6.0", "resolved": "https://registry.npmjs.org/@nx/jest/-/jest-16.6.0.tgz", @@ -7166,6 +7293,31 @@ "node": ">=8" } }, + "node_modules/@nx/js/node_modules/lru-cache": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", + "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "dependencies": { + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/@nx/js/node_modules/semver": { + "version": "7.5.3", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.3.tgz", + "integrity": "sha512-QBlUtyVk/5EeHbi7X0fw6liDZc7BBmEaSYn01fMU1OUYbf6GPsbTtd8WmnqbI20SeycoHSeiybkE/q1Q+qlThQ==", + "dependencies": { + "lru-cache": "^6.0.0" + }, + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/@nx/js/node_modules/source-map": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", @@ -7194,6 +7346,11 @@ "node": ">=8" } }, + "node_modules/@nx/js/node_modules/yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" + }, "node_modules/@nx/linter": { "version": "16.6.0", "resolved": "https://registry.npmjs.org/@nx/linter/-/linter-16.6.0.tgz", @@ -7304,6 +7461,39 @@ "node": ">=8.6" } }, + "node_modules/@nx/nest/node_modules/lru-cache": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", + "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "dev": true, + "dependencies": { + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/@nx/nest/node_modules/semver": { + "version": "7.5.3", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.3.tgz", + "integrity": "sha512-QBlUtyVk/5EeHbi7X0fw6liDZc7BBmEaSYn01fMU1OUYbf6GPsbTtd8WmnqbI20SeycoHSeiybkE/q1Q+qlThQ==", + "dev": true, + "dependencies": { + "lru-cache": "^6.0.0" + }, + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/@nx/nest/node_modules/yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", + "dev": true + }, "node_modules/@nx/node": { "version": "16.6.0", "resolved": "https://registry.npmjs.org/@nx/node/-/node-16.6.0.tgz", @@ -7487,6 +7677,39 @@ "tslib": "^2.3.0" } }, + "node_modules/@nx/storybook/node_modules/lru-cache": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", + "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "dev": true, + "dependencies": { + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/@nx/storybook/node_modules/semver": { + "version": "7.5.3", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.3.tgz", + "integrity": "sha512-QBlUtyVk/5EeHbi7X0fw6liDZc7BBmEaSYn01fMU1OUYbf6GPsbTtd8WmnqbI20SeycoHSeiybkE/q1Q+qlThQ==", + "dev": true, + "dependencies": { + "lru-cache": "^6.0.0" + }, + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/@nx/storybook/node_modules/yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", + "dev": true + }, "node_modules/@nx/webpack": { "version": "16.6.0", "resolved": "https://registry.npmjs.org/@nx/webpack/-/webpack-16.6.0.tgz", @@ -25662,6 +25885,31 @@ "node": ">=8" } }, + "node_modules/nx/node_modules/lru-cache": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", + "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "dependencies": { + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/nx/node_modules/semver": { + "version": "7.5.3", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.3.tgz", + "integrity": "sha512-QBlUtyVk/5EeHbi7X0fw6liDZc7BBmEaSYn01fMU1OUYbf6GPsbTtd8WmnqbI20SeycoHSeiybkE/q1Q+qlThQ==", + "dependencies": { + "lru-cache": "^6.0.0" + }, + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/nx/node_modules/string-width": { "version": "4.2.3", "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", @@ -25686,6 +25934,11 @@ "node": ">=8" } }, + "node_modules/nx/node_modules/yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" + }, "node_modules/object-assign": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", @@ -28733,9 +28986,9 @@ } }, "node_modules/semver": { - "version": "7.5.3", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.3.tgz", - "integrity": "sha512-QBlUtyVk/5EeHbi7X0fw6liDZc7BBmEaSYn01fMU1OUYbf6GPsbTtd8WmnqbI20SeycoHSeiybkE/q1Q+qlThQ==", + "version": "7.5.4", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz", + "integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==", "dependencies": { "lru-cache": "^6.0.0" }, diff --git a/package.json b/package.json index 72a8dc2c56..c569b15385 100644 --- a/package.json +++ b/package.json @@ -95,6 +95,7 @@ "pg": "^8.9.0", "reflect-metadata": "^0.1.13", "rxjs": "^7.0.0", + "semver": "^7.5.4", "tippy.js": "^6.3.7", "tslib": "^2.3.0", "typeorm": "^0.3.14", From 17b3c52da6831bede618105844a0c8630d6ff4b1 Mon Sep 17 00:00:00 2001 From: Florent Gravin Date: Sat, 2 Dec 2023 17:00:07 +0100 Subject: [PATCH 2/4] refactor(platform): remove isApiCompatible as the error is thrown from getApiVersion() --- .../lib/gn4/platform/gn4-platform.service.ts | 21 +++++++------------ .../src/lib/platform.service.interface.ts | 1 - 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/libs/api/repository/src/lib/gn4/platform/gn4-platform.service.ts b/libs/api/repository/src/lib/gn4/platform/gn4-platform.service.ts index 5e4807ade3..b87eb9ef0f 100644 --- a/libs/api/repository/src/lib/gn4/platform/gn4-platform.service.ts +++ b/libs/api/repository/src/lib/gn4/platform/gn4-platform.service.ts @@ -17,7 +17,7 @@ export class Gn4PlatformService implements PlatformServiceInterface { private readonly type = 'GeoNetwork' private me$: Observable private users$: Observable - isAnonymous$: Observable + private isAnonymous$: Observable private settings$ = of(true).pipe( switchMap(() => this.siteApiService.getSiteOrPortalDescription()), @@ -26,18 +26,16 @@ export class Gn4PlatformService implements PlatformServiceInterface { private readonly apiVersion$ = this.settings$.pipe( map((info) => info['system/platform/version'] as string), + tap((version) => { + if (ltr(version, minApiVersion)) { + throw new Error( + `Gn4 API version is not compatible.\nMinimum: ${minApiVersion}\nYour version: ${version}` + ) + } + }), shareReplay(1) ) - private readonly isApiCompatible$ = this.apiVersion$.pipe( - tap( - (version) => - version < minApiVersion && - console.warn(`The GeoNetwork Api version is too low ${version}`) - ), - map((version) => version >= minApiVersion) - ) - constructor( private siteApiService: SiteApiService, private meApi: MeApiService, @@ -62,9 +60,6 @@ export class Gn4PlatformService implements PlatformServiceInterface { getApiVersion(): Observable { return this.apiVersion$ } - isApiCompatible(): Observable { - return this.isApiCompatible$ - } getMe(): Observable { return this.me$ diff --git a/libs/common/domain/src/lib/platform.service.interface.ts b/libs/common/domain/src/lib/platform.service.interface.ts index 7872c2d052..4711d1d047 100644 --- a/libs/common/domain/src/lib/platform.service.interface.ts +++ b/libs/common/domain/src/lib/platform.service.interface.ts @@ -5,7 +5,6 @@ import { Organization } from './model/record/organization.model' export abstract class PlatformServiceInterface { abstract getType(): string abstract getApiVersion(): Observable - abstract isApiCompatible(): Observable abstract getMe(): Observable abstract isAnonymous(): Observable From 7bf80eb3f3b132b26ef4d3d371a72b9efd55e299 Mon Sep 17 00:00:00 2001 From: Florent Gravin Date: Sat, 2 Dec 2023 17:04:43 +0100 Subject: [PATCH 3/4] refactor(org): use semver for version comparison --- .../organizations-from-metadata.service.ts | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/libs/api/repository/src/lib/gn4/organizations/organizations-from-metadata.service.ts b/libs/api/repository/src/lib/gn4/organizations/organizations-from-metadata.service.ts index 504412fb37..bea2a42653 100644 --- a/libs/api/repository/src/lib/gn4/organizations/organizations-from-metadata.service.ts +++ b/libs/api/repository/src/lib/gn4/organizations/organizations-from-metadata.service.ts @@ -28,6 +28,7 @@ import { combineLatest, Observable, of, switchMap, takeLast } from 'rxjs' import { filter, map, shareReplay, startWith, tap } from 'rxjs/operators' import { LangService } from '@geonetwork-ui/util/i18n' import { PlatformServiceInterface } from '@geonetwork-ui/common/domain/platform.service.interface' +import { coerce, satisfies, valid } from 'semver' const IMAGE_URL = '/geonetwork/images/harvesting/' @@ -144,6 +145,7 @@ export class OrganizationsFromMetadataService } private getAggregationSearchRequest(gnVersion: string) { + const semVersion = valid(coerce(gnVersion)) return this.esService.getSearchRequestBody({ contact: { nested: { @@ -152,9 +154,10 @@ export class OrganizationsFromMetadataService aggs: { org: { terms: { - field: gnVersion.startsWith('4.2.2') - ? 'contactForResource.organisation' - : 'contactForResource.organisationObject.default.keyword', + field: + semVersion === '4.2.2' + ? 'contactForResource.organisation' + : 'contactForResource.organisationObject.default.keyword', exclude: '', size: 5000, order: { _key: 'asc' }, @@ -164,12 +167,9 @@ export class OrganizationsFromMetadataService terms: { size: 50, exclude: '', - field: - gnVersion.startsWith('4.2.2') || - gnVersion.startsWith('4.2.3') || - gnVersion.startsWith('4.2.4') - ? 'contactForResource.email.keyword' - : 'contactForResource.email', + field: satisfies(semVersion, '4.2.2 - 4.2.4') + ? 'contactForResource.email.keyword' + : 'contactForResource.email', }, }, logoUrl: { @@ -187,9 +187,10 @@ export class OrganizationsFromMetadataService terms: { size: 5000, exclude: '', - field: gnVersion.startsWith('4.2.2') - ? 'OrgForResource' - : 'OrgForResourceObject.default', + field: + semVersion === '4.2.2' + ? 'OrgForResource' + : 'OrgForResourceObject.default', order: { _key: 'asc', }, From 2a23a58762f464c8dcc672c679d1f56c5f47364d Mon Sep 17 00:00:00 2001 From: Florent Gravin Date: Sat, 2 Dec 2023 17:08:27 +0100 Subject: [PATCH 4/4] feat(platform): throw an error is the version is not compatible --- .../lib/gn4/platform/gn4-platform.mapper.ts | 2 +- .../gn4/platform/gn4-platform.service.spec.ts | 33 ++++++++++++++++--- .../lib/gn4/platform/gn4-platform.service.ts | 3 +- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/libs/api/repository/src/lib/gn4/platform/gn4-platform.mapper.ts b/libs/api/repository/src/lib/gn4/platform/gn4-platform.mapper.ts index bb34126673..67da958a92 100644 --- a/libs/api/repository/src/lib/gn4/platform/gn4-platform.mapper.ts +++ b/libs/api/repository/src/lib/gn4/platform/gn4-platform.mapper.ts @@ -37,6 +37,6 @@ export class Gn4PlatformMapper { credentialsNonExpired, ...user } = apiUser - return { ...apiUser, id: id + '' } as UserModel + return { ...apiUser, id: id.toString() } as UserModel } } diff --git a/libs/api/repository/src/lib/gn4/platform/gn4-platform.service.spec.ts b/libs/api/repository/src/lib/gn4/platform/gn4-platform.service.spec.ts index 4d42efc935..7580f52018 100644 --- a/libs/api/repository/src/lib/gn4/platform/gn4-platform.service.spec.ts +++ b/libs/api/repository/src/lib/gn4/platform/gn4-platform.service.spec.ts @@ -5,7 +5,7 @@ import { } from '@geonetwork-ui/data-access/gn4' import { TestBed } from '@angular/core/testing' import { Gn4PlatformService } from './gn4-platform.service' -import { firstValueFrom, lastValueFrom, of, Subject } from 'rxjs' +import { firstValueFrom, of, Subject } from 'rxjs' import { AvatarServiceInterface } from '../auth/avatar.service.interface' import { Gn4PlatformMapper } from './gn4-platform.mapper' @@ -31,6 +31,7 @@ class MeApiMock { getMe() { return this._me$ } + _me$ = new Subject() } @@ -46,6 +47,7 @@ class SiteApiServiceMock { }) ) } + class UsersApiServiceMock { getUsers() { return of([ @@ -98,11 +100,32 @@ describe('Gn4PlatformService', () => { expect(service).toBeTruthy() }) - it('fetches version from settings', async () => { - geonetworkVersion = '4.2.0' - const version = await firstValueFrom(service.getApiVersion()) - expect(version).toEqual('4.2.0') + describe('version', () => { + describe('when version is lower than 4.2.2', () => { + beforeEach(() => { + geonetworkVersion = '4.2.0' + }) + it('throws an error', async () => { + let error + await firstValueFrom(service.getApiVersion()).catch((e) => (error = e)) + expect(error).toEqual( + new Error( + 'Gn4 API version is not compatible.\nMinimum: 4.2.2\nYour version: 4.2.0' + ) + ) + }) + }) + describe('when version is euqal or greater than 4.2.2', () => { + beforeEach(() => { + geonetworkVersion = '4.2.2' + }) + it('fetches version from settings', async () => { + const version = await firstValueFrom(service.getApiVersion()) + expect(version).toEqual('4.2.2') + }) + }) }) + it('fetches users from api', async () => { const users = await firstValueFrom(service.getUsers()) expect(users).toEqual([ diff --git a/libs/api/repository/src/lib/gn4/platform/gn4-platform.service.ts b/libs/api/repository/src/lib/gn4/platform/gn4-platform.service.ts index b87eb9ef0f..0b4cfa1d3e 100644 --- a/libs/api/repository/src/lib/gn4/platform/gn4-platform.service.ts +++ b/libs/api/repository/src/lib/gn4/platform/gn4-platform.service.ts @@ -10,8 +10,9 @@ import { PlatformServiceInterface } from '@geonetwork-ui/common/domain/platform. import { UserModel } from '@geonetwork-ui/common/domain/model/user/user.model' import { Organization } from '@geonetwork-ui/common/domain/model/record' import { Gn4PlatformMapper } from './gn4-platform.mapper' +import { ltr } from 'semver' -const minApiVersion = '4.2.0' +const minApiVersion = '4.2.2' @Injectable() export class Gn4PlatformService implements PlatformServiceInterface { private readonly type = 'GeoNetwork'