2025-05-12 10:03:22 +00:00
|
|
|
import * as plugins from './smartlog-destination-receiver.plugins.js';
|
|
|
|
|
import {
|
|
|
|
|
type ILogDestination,
|
|
|
|
|
type ILogPackageAuthenticated,
|
|
|
|
|
type ILogPackage,
|
|
|
|
|
} from '../dist_ts_interfaces/index.js';
|
|
|
|
|
|
|
|
|
|
export interface ISmartlogDestinationReceiverConstructorOptions {
|
|
|
|
|
passphrase: string;
|
|
|
|
|
receiverEndpoint: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class SmartlogDestinationReceiver implements ILogDestination {
|
|
|
|
|
private options: ISmartlogDestinationReceiverConstructorOptions;
|
2026-02-14 15:52:57 +00:00
|
|
|
private webrequest = new plugins.webrequest.WebrequestClient();
|
2025-05-12 10:03:22 +00:00
|
|
|
|
|
|
|
|
constructor(optionsArg: ISmartlogDestinationReceiverConstructorOptions) {
|
|
|
|
|
this.options = optionsArg;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private errorCounter = 0;
|
|
|
|
|
public async handleLog(logPackageArg: ILogPackage) {
|
|
|
|
|
const response = await this.webrequest.postJson(this.options.receiverEndpoint, {
|
|
|
|
|
auth: plugins.smarthash.sha256FromStringSync(this.options.passphrase),
|
|
|
|
|
logPackage: logPackageArg,
|
|
|
|
|
}).catch(err => {
|
|
|
|
|
if (this.errorCounter % 100 === 0) {
|
|
|
|
|
console.error(`There seems to be an error with logging.`);
|
|
|
|
|
console.error(`Accumulated ${this.errorCounter} errors so far`)
|
|
|
|
|
}
|
|
|
|
|
this.errorCounter++;
|
|
|
|
|
});
|
2026-02-14 15:52:57 +00:00
|
|
|
return response;
|
2025-05-12 10:03:22 +00:00
|
|
|
}
|
|
|
|
|
}
|