fix(core): update

This commit is contained in:
Philipp Kunz 2020-06-10 09:21:59 +00:00
parent 9f97bacaf5
commit 4b402a097e
3 changed files with 10 additions and 6 deletions

View File

@ -38,7 +38,7 @@ tap.test('should receive a message', async () => {
id: '123', id: '123',
type: 'none' type: 'none'
}, },
message: 'hi there', message: 'hi there'
} }
}); });
}); });

View File

@ -3,7 +3,7 @@ import * as plugins from './sl.receiver.plugins';
import { import {
ILogPackage, ILogPackage,
ILogPackageAuthenticated, ILogPackageAuthenticated,
ILogDestination, ILogDestination
} from '@pushrocks/smartlog-interfaces'; } from '@pushrocks/smartlog-interfaces';
export type TValidatorFunction = (logPackage: ILogPackage) => Promise<boolean>; export type TValidatorFunction = (logPackage: ILogPackage) => Promise<boolean>;
@ -24,7 +24,11 @@ export class SmartlogReceiver {
constructor(smartlogReceiverOptions: ISmartlogReceiverOptions) { constructor(smartlogReceiverOptions: ISmartlogReceiverOptions) {
this.passphrase = smartlogReceiverOptions.passphrase; this.passphrase = smartlogReceiverOptions.passphrase;
this.validatorFunction = smartlogReceiverOptions.validatorFunction || (async (logpackageArg) => {return true}); this.validatorFunction =
smartlogReceiverOptions.validatorFunction ||
(async logpackageArg => {
return true;
});
this.smartlogInstance = smartlogReceiverOptions.smartlogInstance; this.smartlogInstance = smartlogReceiverOptions.smartlogInstance;
} }
@ -36,8 +40,8 @@ export class SmartlogReceiver {
const logPackage = authenticatedLogPackageArg.logPackage; const logPackage = authenticatedLogPackageArg.logPackage;
if ( if (
authString === plugins.smarthash.sha256FromStringSync(this.passphrase) authString === plugins.smarthash.sha256FromStringSync(this.passphrase) &&
&& await this.validatorFunction(logPackage) (await this.validatorFunction(logPackage))
) { ) {
// Message authenticated lets clean up. // Message authenticated lets clean up.
logPackage.correlation ? null : (logPackage.correlation = { id: '123', type: 'none' }); logPackage.correlation ? null : (logPackage.correlation = { id: '123', type: 'none' });