From a937344126f9ef416e2ad9132ae4a5db1919ea6e Mon Sep 17 00:00:00 2001 From: kkopanidis Date: Tue, 14 Dec 2021 17:09:30 +0200 Subject: [PATCH] fix(grpc-sdk): modulename injection to modules fix(grpc-sdk): module name add on metadata --- libraries/grpc-sdk/src/index.ts | 12 +++++++++--- .../grpc-sdk/src/interceptors/moduleName.ts | 17 ++++++++++------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/libraries/grpc-sdk/src/index.ts b/libraries/grpc-sdk/src/index.ts index 716f245a5..ec5973b21 100644 --- a/libraries/grpc-sdk/src/index.ts +++ b/libraries/grpc-sdk/src/index.ts @@ -10,7 +10,7 @@ import { Router, SMS, Storage, - Forms + Forms, } from './modules'; import { Authentication } from './modules/authentication'; import Crypto from 'crypto'; @@ -185,7 +185,10 @@ export default class ConduitGrpcSdk { }); modules.forEach((m: any) => { if (!this._modules[m.moduleName] && this._availableModules[m.moduleName]) { - this._modules[m.moduleName] = new this._availableModules[m.moduleName](m.moduleName, m.url); + this._modules[m.moduleName] = new this._availableModules[m.moduleName]( + this.name, + m.url + ); } else if (this._availableModules[m.moduleName]) { this._modules[m.moduleName]?.initializeClient(); } @@ -219,7 +222,10 @@ export default class ConduitGrpcSdk { this.lastSearch = Date.now(); r.forEach((m) => { if (!this._modules[m.moduleName] && this._availableModules[m.moduleName]) { - this._modules[m.moduleName] = new this._availableModules[m.moduleName](m.moduleName, m.url); + this._modules[m.moduleName] = new this._availableModules[m.moduleName]( + this.name, + m.url + ); } }); return 'ok'; diff --git a/libraries/grpc-sdk/src/interceptors/moduleName.ts b/libraries/grpc-sdk/src/interceptors/moduleName.ts index 282eece75..d46e07a9c 100644 --- a/libraries/grpc-sdk/src/interceptors/moduleName.ts +++ b/libraries/grpc-sdk/src/interceptors/moduleName.ts @@ -8,14 +8,17 @@ import { Metadata, InterceptingCall } from '@grpc/grpc-js'; export function getModuleNameInterceptor(moduleName: string) { return (options: any, nextCall: Function) => { return new InterceptingCall(nextCall(options), { - start(metadata, _, next) { - next(metadata, { - onReceiveMetadata(metadata: Metadata, next: Function) { - // metadata.set('moduleName', moduleName); - metadata.add('moduleName', moduleName); + start: (metadata, _, next) => { + // outbound + metadata.set('moduleName', moduleName); + let newListener = { + // inbound + onReceiveMetadata: function (metadata: any, next: any) { + metadata.set('moduleName', moduleName); next(metadata); - } - }); + }, + }; + next(metadata, newListener); }, }); };