diff --git a/lib/http.ts b/lib/http.ts index e58ea49..672fa61 100644 --- a/lib/http.ts +++ b/lib/http.ts @@ -57,17 +57,26 @@ export default class HttpBase { this.options = this.setDefaults(options); this.rootHttp = axios.create({ ...options.requestConfig, - baseURL: `${options.host}/api/v1`, + baseURL: options.baseURL, }); this.http = axios.create({ ...options.requestConfig, - baseURL: `${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 56f4185..1c0a96c 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 +}