smartlog-destination-receiver/ts/index.ts

30 lines
882 B
TypeScript
Raw Normal View History

2018-11-11 13:29:26 +00:00
import * as plugins from './smartlog-destination-receiver.plugins';
import {
ILogDestination,
ILogPackageAuthenticated,
ILogPackage
} from '@pushrocks/smartlog-interfaces';
export interface ISmartlogDestinationReceiverConstructorOptions {
passphrase: string;
receiverEndpoint: string;
}
export class SmartlogDestinationReceiver implements ILogDestination {
private options: ISmartlogDestinationReceiverConstructorOptions;
constructor(optionsArg: ISmartlogDestinationReceiverConstructorOptions) {
this.options = optionsArg;
}
2018-11-11 18:40:59 +00:00
public async handleLog(logPackageArg: ILogPackage) {
const response = await plugins.smartrequest.postJson(this.options.receiverEndpoint, {
requestBody: {
auth: plugins.smarthash.sha256FromStringSync(this.options.passphrase),
logPackage: logPackageArg
}
2018-11-11 13:29:26 +00:00
});
2018-11-11 18:40:59 +00:00
console.log(response.body);
2018-11-11 13:29:26 +00:00
}
}