fix(ci): Update CI workflows, build scripts, and export configuration
This commit is contained in:
8
ts_receiver/00_commitinfo_data.ts
Normal file
8
ts_receiver/00_commitinfo_data.ts
Normal file
@ -0,0 +1,8 @@
|
||||
/**
|
||||
* autocreated commitinfo by @push.rocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/smartlog-receiver',
|
||||
version: '2.0.0',
|
||||
description: 'a receiver for smartlog-destination-receiver'
|
||||
}
|
1
ts_receiver/index.ts
Normal file
1
ts_receiver/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './sl.classes.smartlogreceiver.js';
|
73
ts_receiver/sl.classes.smartlogreceiver.ts
Normal file
73
ts_receiver/sl.classes.smartlogreceiver.ts
Normal file
@ -0,0 +1,73 @@
|
||||
import * as plugins from './sl.receiver.plugins.js';
|
||||
|
||||
import type {
|
||||
ILogPackage,
|
||||
ILogPackageAuthenticated,
|
||||
ILogDestination,
|
||||
} from '../dist_ts_interfaces/index.js';
|
||||
|
||||
export type TValidatorFunction = (logPackage: ILogPackage) => Promise<boolean>;
|
||||
|
||||
export interface ISmartlogReceiverOptions {
|
||||
smartlogInstance: plugins.smartlog.Smartlog;
|
||||
passphrase: string;
|
||||
validatorFunction: TValidatorFunction;
|
||||
}
|
||||
|
||||
/**
|
||||
* a class that receives smartlog packages
|
||||
*/
|
||||
export class SmartlogReceiver {
|
||||
public passphrase: string;
|
||||
public validatorFunction: TValidatorFunction;
|
||||
public smartlogInstance: plugins.smartlog.Smartlog;
|
||||
|
||||
constructor(smartlogReceiverOptions: ISmartlogReceiverOptions) {
|
||||
this.passphrase = smartlogReceiverOptions.passphrase;
|
||||
this.validatorFunction =
|
||||
smartlogReceiverOptions.validatorFunction ||
|
||||
(async (logpackageArg) => {
|
||||
return true;
|
||||
});
|
||||
this.smartlogInstance = smartlogReceiverOptions.smartlogInstance;
|
||||
}
|
||||
|
||||
/**
|
||||
* handles a authenticated log
|
||||
*/
|
||||
public async handleAuthenticatedLog(authenticatedLogPackageArg: ILogPackageAuthenticated) {
|
||||
const authString = authenticatedLogPackageArg.auth;
|
||||
const logPackage = authenticatedLogPackageArg.logPackage;
|
||||
|
||||
if (
|
||||
authString === plugins.smarthash.sha256FromStringSync(this.passphrase) &&
|
||||
(await this.validatorFunction(logPackage))
|
||||
) {
|
||||
// Message authenticated lets clean up.
|
||||
logPackage.correlation ? null : (logPackage.correlation = { id: '123', type: 'none' });
|
||||
logPackage.correlation.id ? null : (logPackage.correlation.id = '123');
|
||||
logPackage.correlation.type ? null : (logPackage.correlation.type = 'none');
|
||||
|
||||
this.smartlogInstance.handleLog(logPackage);
|
||||
return { status: 'ok' };
|
||||
} else {
|
||||
this.smartlogInstance.log('error', 'Message rejected because of bad passphrase');
|
||||
return { status: 'error' };
|
||||
// console.log(plugins.smarthash.sha256FromStringSync(this.passphrase));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* handles an array of authenticated logs
|
||||
* @param authenticatedLogsPackageArrayArg
|
||||
*/
|
||||
public async handleManyAuthenticatedLogs(
|
||||
authenticatedLogsPackageArrayArg: ILogPackageAuthenticated[]
|
||||
) {
|
||||
const promiseArray: Array<Promise<any>> = [];
|
||||
for (const logPackage of authenticatedLogsPackageArrayArg) {
|
||||
promiseArray.push(this.handleAuthenticatedLog(logPackage));
|
||||
}
|
||||
await Promise.all(promiseArray);
|
||||
}
|
||||
}
|
4
ts_receiver/sl.receiver.plugins.ts
Normal file
4
ts_receiver/sl.receiver.plugins.ts
Normal file
@ -0,0 +1,4 @@
|
||||
import * as smarthash from '@push.rocks/smarthash';
|
||||
import * as smartlog from '../dist_ts/index.js';
|
||||
|
||||
export { smartlog, smarthash };
|
Reference in New Issue
Block a user