From a0be5e12ec8782379822f7d9872624ca094175de Mon Sep 17 00:00:00 2001 From: Sagar Khole Date: Wed, 22 Jan 2025 19:13:54 +0530 Subject: [PATCH 1/2] feat: Added API to delete connection also added patch for multtenancy oob connection Signed-off-by: Sagar Khole --- ...e+0.5.3+007+outofband-connection-fix.patch | 40 +++++++++++++++++++ .../multi-tenancy/MultiTenancyController.ts | 17 ++++++++ 2 files changed, 57 insertions(+) create mode 100644 patches/@credo-ts+core+0.5.3+007+outofband-connection-fix.patch diff --git a/patches/@credo-ts+core+0.5.3+007+outofband-connection-fix.patch b/patches/@credo-ts+core+0.5.3+007+outofband-connection-fix.patch new file mode 100644 index 00000000..da489746 --- /dev/null +++ b/patches/@credo-ts+core+0.5.3+007+outofband-connection-fix.patch @@ -0,0 +1,40 @@ +diff --git a/node_modules/@credo-ts/core/build/modules/oob/OutOfBandApi.js b/node_modules/@credo-ts/core/build/modules/oob/OutOfBandApi.js +index 141bc8d..e84e210 100644 +--- a/node_modules/@credo-ts/core/build/modules/oob/OutOfBandApi.js ++++ b/node_modules/@credo-ts/core/build/modules/oob/OutOfBandApi.js +@@ -432,17 +432,30 @@ let OutOfBandApi = class OutOfBandApi { + } + else { + // Wait until the connection is ready and then pass the messages to the agent for further processing +- this.connectionsApi +- .returnWhenIsConnected(connectionRecord.id, { timeoutMs }) +- .then((connectionRecord) => this.emitWithConnection(outOfBandRecord, connectionRecord, messages)) +- .catch((error) => { ++ // this.connectionsApi ++ // .returnWhenIsConnected(connectionRecord.id, { timeoutMs }) ++ // .then((connectionRecord) => this.emitWithConnection(outOfBandRecord, connectionRecord, messages)) ++ // .catch((error) => { ++ // if (error instanceof rxjs_1.EmptyError) { ++ // this.logger.warn(`Agent unsubscribed before connection got into ${connections_1.DidExchangeState.Completed} state`, error); ++ // } ++ // else { ++ // this.logger.error('Promise waiting for the connection to be complete failed.', error); ++ // } ++ // }); ++ ++ try{ ++ connectionRecord = await this.connectionsApi.returnWhenIsConnected(connectionRecord.id, { timeoutMs }) ++ await this.emitWithConnection(outOfBandRecord, connectionRecord, messages); ++ ++ }catch(error){ + if (error instanceof rxjs_1.EmptyError) { + this.logger.warn(`Agent unsubscribed before connection got into ${connections_1.DidExchangeState.Completed} state`, error); + } + else { + this.logger.error('Promise waiting for the connection to be complete failed.', error); + } +- }); ++ } + } + } + return { outOfBandRecord, connectionRecord }; diff --git a/src/controllers/multi-tenancy/MultiTenancyController.ts b/src/controllers/multi-tenancy/MultiTenancyController.ts index 9fe90c2f..051a4518 100644 --- a/src/controllers/multi-tenancy/MultiTenancyController.ts +++ b/src/controllers/multi-tenancy/MultiTenancyController.ts @@ -638,6 +638,23 @@ export class MultiTenancyController extends Controller { } } + @Example(ConnectionRecordExample) + @Security('apiKey') + @Delete('/connections/:connectionId/:tenantId') + public async deleteConnectionById(@Path('tenantId') tenantId: string, @Path('connectionId') connectionId: RecordId) { + try { + let connectionRecord + await this.agent.modules.tenants.withTenantAgent({ tenantId }, async (tenantAgent) => { + const connection = await tenantAgent.connections.deleteById(connectionId) + return JsonTransformer.toJSON(connection) + }) + + return connectionRecord + } catch (error) { + throw ErrorHandlingService.handle(error) + } + } + @Security('apiKey') @Post('/create-invitation/:tenantId') public async createInvitation( From 39a53f53ebb8e3c59ebecc8ad805ce1a4264d274 Mon Sep 17 00:00:00 2001 From: Sagar Khole Date: Tue, 28 Jan 2025 16:47:39 +0530 Subject: [PATCH 2/2] Update API of delete connection Signed-off-by: Sagar Khole --- src/controllers/multi-tenancy/MultiTenancyController.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/controllers/multi-tenancy/MultiTenancyController.ts b/src/controllers/multi-tenancy/MultiTenancyController.ts index 051a4518..cb8fc7bc 100644 --- a/src/controllers/multi-tenancy/MultiTenancyController.ts +++ b/src/controllers/multi-tenancy/MultiTenancyController.ts @@ -643,8 +643,7 @@ export class MultiTenancyController extends Controller { @Delete('/connections/:connectionId/:tenantId') public async deleteConnectionById(@Path('tenantId') tenantId: string, @Path('connectionId') connectionId: RecordId) { try { - let connectionRecord - await this.agent.modules.tenants.withTenantAgent({ tenantId }, async (tenantAgent) => { + const connectionRecord = await this.agent.modules.tenants.withTenantAgent({ tenantId }, async (tenantAgent) => { const connection = await tenantAgent.connections.deleteById(connectionId) return JsonTransformer.toJSON(connection) })