smartlog-destination-receiver/ts/index.ts

31 lines
937 B
TypeScript
Raw Normal View History

2022-06-26 07:27:01 +00:00
import * as plugins from './smartlog-destination-receiver.plugins.js';
2018-11-11 13:29:26 +00:00
import {
ILogDestination,
ILogPackageAuthenticated,
2022-06-26 07:27:01 +00:00
ILogPackage,
2018-11-11 13:29:26 +00:00
} from '@pushrocks/smartlog-interfaces';
export interface ISmartlogDestinationReceiverConstructorOptions {
passphrase: string;
receiverEndpoint: string;
}
export class SmartlogDestinationReceiver implements ILogDestination {
private options: ISmartlogDestinationReceiverConstructorOptions;
2022-06-26 07:27:01 +00:00
private webrequest = new plugins.webrequest.WebRequest();
2018-11-11 13:29:26 +00:00
constructor(optionsArg: ISmartlogDestinationReceiverConstructorOptions) {
this.options = optionsArg;
}
2018-11-11 18:40:59 +00:00
public async handleLog(logPackageArg: ILogPackage) {
2022-06-26 07:27:01 +00:00
const response = await this.webrequest.postJson(this.options.receiverEndpoint, {
2018-11-11 18:40:59 +00:00
requestBody: {
auth: plugins.smarthash.sha256FromStringSync(this.options.passphrase),
2022-06-26 07:27:01 +00:00
logPackage: logPackageArg,
},
2018-11-11 13:29:26 +00:00
});
2020-06-10 06:48:16 +00:00
return response.body;
2018-11-11 13:29:26 +00:00
}
}