From a52b11df5e23d1de816ffe451c9cbbe3e7fbeb8a Mon Sep 17 00:00:00 2001 From: Jim Ezesinachi Date: Thu, 9 Feb 2023 14:50:49 +0100 Subject: [PATCH 1/4] feat: added endpoint setter to Agent InitConfig Signed-off-by: Jim Ezesinachi --- packages/core/src/agent/AgentConfig.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/core/src/agent/AgentConfig.ts b/packages/core/src/agent/AgentConfig.ts index 28ad67488a..c5da474c03 100644 --- a/packages/core/src/agent/AgentConfig.ts +++ b/packages/core/src/agent/AgentConfig.ts @@ -141,6 +141,11 @@ export class AgentConfig { return this.initConfig.endpoints as [string, ...string[]] } + public set endpoints(endpoints: string[]) { + // if endpoints is not set, return queue endpoint + this.initConfig.endpoints = endpoints + } + /** * @deprecated use mediatorInvitationUrl from the `RecipientModuleConfig` class */ From 723714eb52bfe50eccaeceb7ec2679d1ce5b3a58 Mon Sep 17 00:00:00 2001 From: Jim Ezesinachi Date: Thu, 9 Feb 2023 15:44:53 +0100 Subject: [PATCH 2/4] feat: added tests for endpoint setter Signed-off-by: Jim Ezesinachi --- packages/core/src/agent/AgentConfig.ts | 8 +++++--- .../core/src/agent/__tests__/AgentConfig.test.ts | 12 ++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/packages/core/src/agent/AgentConfig.ts b/packages/core/src/agent/AgentConfig.ts index c5da474c03..0700b8b2c2 100644 --- a/packages/core/src/agent/AgentConfig.ts +++ b/packages/core/src/agent/AgentConfig.ts @@ -11,12 +11,14 @@ import { DidCommMimeType } from '../types' export class AgentConfig { private initConfig: InitConfig + private initConfigEndpoints: string[] | undefined public label: string public logger: Logger public readonly agentDependencies: AgentDependencies public constructor(initConfig: InitConfig, agentDependencies: AgentDependencies) { this.initConfig = initConfig + this.initConfigEndpoints = initConfig.endpoints this.label = initConfig.label this.logger = initConfig.logger ?? new ConsoleLogger(LogLevel.off) this.agentDependencies = agentDependencies @@ -134,16 +136,16 @@ export class AgentConfig { public get endpoints(): [string, ...string[]] { // if endpoints is not set, return queue endpoint // https://github.com/hyperledger/aries-rfcs/issues/405#issuecomment-582612875 - if (!this.initConfig.endpoints || this.initConfig.endpoints.length === 0) { + if (!this.initConfigEndpoints || this.initConfigEndpoints.length === 0) { return [DID_COMM_TRANSPORT_QUEUE] } - return this.initConfig.endpoints as [string, ...string[]] + return this.initConfigEndpoints as [string, ...string[]] } public set endpoints(endpoints: string[]) { // if endpoints is not set, return queue endpoint - this.initConfig.endpoints = endpoints + this.initConfigEndpoints = endpoints } /** diff --git a/packages/core/src/agent/__tests__/AgentConfig.test.ts b/packages/core/src/agent/__tests__/AgentConfig.test.ts index 559a9880a3..43549b1e87 100644 --- a/packages/core/src/agent/__tests__/AgentConfig.test.ts +++ b/packages/core/src/agent/__tests__/AgentConfig.test.ts @@ -18,6 +18,18 @@ describe('AgentConfig', () => { expect(agentConfig.endpoints).toStrictEqual(['didcomm:transport/queue']) }) + + it('should return the new config endpoint after setter is called', () => { + const endpoint = 'https://local-url.com' + const newEndpoint = 'https://new-local-url.com' + + const agentConfig = getAgentConfig('AgentConfig Test', { + endpoints: [endpoint], + }) + + agentConfig.endpoints = [newEndpoint] + expect(agentConfig.endpoints).toEqual([newEndpoint]) + }) }) describe('label', () => { From b3567b7b3c0216dec0c2425768778a7573438284 Mon Sep 17 00:00:00 2001 From: Jim Ezesinachi Date: Thu, 9 Feb 2023 15:48:48 +0100 Subject: [PATCH 3/4] refactor: refactored getter Signed-off-by: Jim Ezesinachi --- packages/core/src/agent/AgentConfig.ts | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/packages/core/src/agent/AgentConfig.ts b/packages/core/src/agent/AgentConfig.ts index 0700b8b2c2..1c60069c8e 100644 --- a/packages/core/src/agent/AgentConfig.ts +++ b/packages/core/src/agent/AgentConfig.ts @@ -11,14 +11,14 @@ import { DidCommMimeType } from '../types' export class AgentConfig { private initConfig: InitConfig - private initConfigEndpoints: string[] | undefined + private initConfigEndpoints: string[] public label: string public logger: Logger public readonly agentDependencies: AgentDependencies public constructor(initConfig: InitConfig, agentDependencies: AgentDependencies) { this.initConfig = initConfig - this.initConfigEndpoints = initConfig.endpoints + this.initConfigEndpoints = initConfig.endpoints ?? [DID_COMM_TRANSPORT_QUEUE] this.label = initConfig.label this.logger = initConfig.logger ?? new ConsoleLogger(LogLevel.off) this.agentDependencies = agentDependencies @@ -134,17 +134,10 @@ export class AgentConfig { } public get endpoints(): [string, ...string[]] { - // if endpoints is not set, return queue endpoint - // https://github.com/hyperledger/aries-rfcs/issues/405#issuecomment-582612875 - if (!this.initConfigEndpoints || this.initConfigEndpoints.length === 0) { - return [DID_COMM_TRANSPORT_QUEUE] - } - return this.initConfigEndpoints as [string, ...string[]] } public set endpoints(endpoints: string[]) { - // if endpoints is not set, return queue endpoint this.initConfigEndpoints = endpoints } From 27e9775b129e4302bf791d090d41b47fee310819 Mon Sep 17 00:00:00 2001 From: Jim Ezesinachi Date: Thu, 9 Feb 2023 16:34:49 +0100 Subject: [PATCH 4/4] refactor: refactored getter back to better state Signed-off-by: Jim Ezesinachi --- packages/core/src/agent/AgentConfig.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/core/src/agent/AgentConfig.ts b/packages/core/src/agent/AgentConfig.ts index 1c60069c8e..a2df97a94c 100644 --- a/packages/core/src/agent/AgentConfig.ts +++ b/packages/core/src/agent/AgentConfig.ts @@ -11,14 +11,14 @@ import { DidCommMimeType } from '../types' export class AgentConfig { private initConfig: InitConfig - private initConfigEndpoints: string[] + private _endpoints: string[] | undefined public label: string public logger: Logger public readonly agentDependencies: AgentDependencies public constructor(initConfig: InitConfig, agentDependencies: AgentDependencies) { this.initConfig = initConfig - this.initConfigEndpoints = initConfig.endpoints ?? [DID_COMM_TRANSPORT_QUEUE] + this._endpoints = initConfig.endpoints this.label = initConfig.label this.logger = initConfig.logger ?? new ConsoleLogger(LogLevel.off) this.agentDependencies = agentDependencies @@ -134,11 +134,17 @@ export class AgentConfig { } public get endpoints(): [string, ...string[]] { - return this.initConfigEndpoints as [string, ...string[]] + // if endpoints is not set, return queue endpoint + // https://github.com/hyperledger/aries-rfcs/issues/405#issuecomment-582612875 + if (!this._endpoints || this._endpoints.length === 0) { + return [DID_COMM_TRANSPORT_QUEUE] + } + + return this._endpoints as [string, ...string[]] } public set endpoints(endpoints: string[]) { - this.initConfigEndpoints = endpoints + this._endpoints = endpoints } /**