Skip to content

Commit

Permalink
fix(grpc-sdk): modulename injection to modules
Browse files Browse the repository at this point in the history
fix(grpc-sdk): module name add on metadata
  • Loading branch information
kkopanidis authored and kon14 committed Dec 14, 2021
1 parent 6c4116c commit a937344
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
12 changes: 9 additions & 3 deletions libraries/grpc-sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
Router,
SMS,
Storage,
Forms
Forms,
} from './modules';
import { Authentication } from './modules/authentication';
import Crypto from 'crypto';
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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';
Expand Down
17 changes: 10 additions & 7 deletions libraries/grpc-sdk/src/interceptors/moduleName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
});
};
Expand Down

0 comments on commit a937344

Please sign in to comment.