From 974a7d5a5d4bf0b9628e6ab49aa36868c36ec82a Mon Sep 17 00:00:00 2001 From: Matthew Clarke Date: Thu, 27 Jul 2023 10:23:45 +0100 Subject: [PATCH 1/2] baseURL options Signed-off-by: Matthew Clarke --- lib/http.ts | 5 +++-- lib/interfaces.ts | 2 ++ package-lock.json | 4 ++-- package.json | 4 ++-- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/http.ts b/lib/http.ts index e58ea49..72d0658 100644 --- a/lib/http.ts +++ b/lib/http.ts @@ -57,11 +57,12 @@ export default class HttpBase { this.options = this.setDefaults(options); this.rootHttp = axios.create({ ...options.requestConfig, - baseURL: `${options.host}/api/v1`, + baseURL: options.baseUrl ?? `${options.host}/api/v1`, }); this.http = axios.create({ ...options.requestConfig, - baseURL: `${options.host}/api/v1/namespaces/${this.options.namespace}`, + baseURL: + options.namespaceBaseURL ?? `${options.host}/api/v1/namespaces/${this.options.namespace}`, }); } diff --git a/lib/interfaces.ts b/lib/interfaces.ts index 56f4185..97b195a 100644 --- a/lib/interfaces.ts +++ b/lib/interfaces.ts @@ -42,6 +42,8 @@ export interface FireFlyOptionsInput { namespace?: string; username?: string; password?: string; + baseUrl?: string; + namespaceBaseURL?: string; websocket?: { host?: string; reconnectDelay?: number; diff --git a/package-lock.json b/package-lock.json index dff2b98..8d64618 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@hyperledger/firefly-sdk", - "version": "1.2.9", + "version": "1.2.11", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@hyperledger/firefly-sdk", - "version": "1.2.9", + "version": "1.2.11", "license": "Apache-2.0", "dependencies": { "axios": "^0.26.1", diff --git a/package.json b/package.json index 7ff65b5..e4953ae 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@hyperledger/firefly-sdk", - "version": "1.2.10", + "version": "1.2.11", "description": "Client SDK for Hyperledger FireFly", "main": "dist/index.js", "types": "dist/index.d.ts", @@ -45,4 +45,4 @@ "form-data": "^4.0.0", "ws": "^8.5.0" } -} \ No newline at end of file +} From 2485e0685581a4b50c2d7f718d5e86f326aba1d5 Mon Sep 17 00:00:00 2001 From: Matthew Clarke Date: Thu, 27 Jul 2023 20:06:49 +0100 Subject: [PATCH 2/2] check URLs and host options Signed-off-by: Matthew Clarke --- lib/http.ts | 14 +++++++++++--- lib/interfaces.ts | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/http.ts b/lib/http.ts index 72d0658..672fa61 100644 --- a/lib/http.ts +++ b/lib/http.ts @@ -57,18 +57,26 @@ export default class HttpBase { this.options = this.setDefaults(options); this.rootHttp = axios.create({ ...options.requestConfig, - baseURL: options.baseUrl ?? `${options.host}/api/v1`, + baseURL: options.baseURL, }); this.http = axios.create({ ...options.requestConfig, - baseURL: - options.namespaceBaseURL ?? `${options.host}/api/v1/namespaces/${this.options.namespace}`, + baseURL: options.namespaceBaseURL, }); } private setDefaults(options: FireFlyOptionsInput): FireFlyOptions { + const baseURLSet = (options.baseURL ?? '') !== '' && (options.namespaceBaseURL ?? '' !== ''); + if (!baseURLSet && (options.host ?? '') === '') { + throw new Error('Invalid options. Option host, or baseURL and namespaceBaseURL must be set.'); + } + return { ...options, + baseURL: baseURLSet ? options.baseURL : `${options.host}/api/v1`, + namespaceBaseURL: baseURLSet + ? options.namespaceBaseURL + : `${options.host}/api/v1/namespaces/${options.namespace}`, namespace: options.namespace ?? 'default', websocket: { ...options.websocket, diff --git a/lib/interfaces.ts b/lib/interfaces.ts index 97b195a..1c0a96c 100644 --- a/lib/interfaces.ts +++ b/lib/interfaces.ts @@ -42,7 +42,7 @@ export interface FireFlyOptionsInput { namespace?: string; username?: string; password?: string; - baseUrl?: string; + baseURL?: string; namespaceBaseURL?: string; websocket?: { host?: string;