31 lines
937 B
TypeScript
31 lines
937 B
TypeScript
import * as plugins from './smartlog-destination-receiver.plugins.js';
|
|
import {
|
|
ILogDestination,
|
|
ILogPackageAuthenticated,
|
|
ILogPackage,
|
|
} from '@pushrocks/smartlog-interfaces';
|
|
|
|
export interface ISmartlogDestinationReceiverConstructorOptions {
|
|
passphrase: string;
|
|
receiverEndpoint: string;
|
|
}
|
|
|
|
export class SmartlogDestinationReceiver implements ILogDestination {
|
|
private options: ISmartlogDestinationReceiverConstructorOptions;
|
|
private webrequest = new plugins.webrequest.WebRequest();
|
|
|
|
constructor(optionsArg: ISmartlogDestinationReceiverConstructorOptions) {
|
|
this.options = optionsArg;
|
|
}
|
|
|
|
public async handleLog(logPackageArg: ILogPackage) {
|
|
const response = await this.webrequest.postJson(this.options.receiverEndpoint, {
|
|
requestBody: {
|
|
auth: plugins.smarthash.sha256FromStringSync(this.options.passphrase),
|
|
logPackage: logPackageArg,
|
|
},
|
|
});
|
|
return response.body;
|
|
}
|
|
}
|