Compare commits

..

No commits in common. "master" and "v1.0.8" have entirely different histories.

17 changed files with 685 additions and 19478 deletions

16
.gitignore vendored
View File

@ -1,20 +1,6 @@
.nogit/
# artifacts
node_modules/
coverage/
public/
pages/
# installs
node_modules/
# caches
.yarn/
.cache/
.rpt2_cache
# builds
dist/
dist_*/
# custom

View File

@ -1,122 +1,131 @@
# gitzone ci_default
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
# gitzone standard
image: hosttoday/ht-docker-node:npmci
cache:
paths:
- .npmci_cache/
key: '$CI_BUILD_STAGE'
- .npmci_cache/
key: "$CI_BUILD_STAGE"
stages:
- security
- test
- release
- metadata
before_script:
- npm install -g @shipzone/npmci
- security
- test
- release
- metadata
# ====================
# security stage
# ====================
auditProductionDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
mirror:
stage: security
script:
- npmci npm prepare
- npmci command npm install --production --ignore-scripts
- npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high --only=prod --production
- npmci git mirror
tags:
- docker
allow_failure: true
- docker
- notpriv
auditDevDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
snyk:
stage: security
script:
- npmci npm prepare
- npmci command npm install -g snyk
- npmci command npm install --ignore-scripts
- npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high --only=dev
- npmci command snyk test
tags:
- docker
allow_failure: true
- docker
- notpriv
# ====================
# test stage
# ====================
testStable:
testLEGACY:
stage: test
script:
- npmci npm prepare
- npmci node install stable
- npmci npm install
- npmci npm test
- npmci npm prepare
- npmci node install legacy
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
- docker
- notpriv
allow_failure: true
testBuild:
testLTS:
stage: test
script:
- npmci npm prepare
- npmci node install stable
- npmci npm install
- npmci command npm run build
- npmci npm prepare
- npmci node install lts
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
- docker
- notpriv
testSTABLE:
stage: test
script:
- npmci npm prepare
- npmci node install stable
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
- notpriv
release:
stage: release
script:
- npmci node install stable
- npmci npm publish
- npmci node install stable
- npmci npm publish
only:
- tags
- tags
tags:
- lossless
- docker
- notpriv
- docker
- notpriv
# ====================
# metadata stage
# ====================
codequality:
stage: metadata
image: docker:stable
allow_failure: true
only:
- tags
services:
- docker:stable-dind
script:
- npmci command npm install -g typescript
- npmci npm prepare
- npmci npm install
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
- docker run
--env SOURCE_CODE="$PWD"
--volume "$PWD":/code
--volume /var/run/docker.sock:/var/run/docker.sock
"registry.gitlab.com/gitlab-org/security-products/codequality:$SP_VERSION" /code
artifacts:
paths: [codeclimate.json]
tags:
- lossless
- docker
- priv
- docker
- priv
trigger:
stage: metadata
script:
- npmci trigger
- npmci trigger
only:
- tags
- tags
tags:
- lossless
- docker
- notpriv
- docker
- notpriv
pages:
image: hosttoday/ht-docker-node:npmci
stage: metadata
script:
- npmci node install stable
- npmci command npm install -g typedoc typescript
- npmci npm prepare
- npmci npm install
- npmci command npm run buildDocs
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
tags:
- lossless
- docker
- notpriv
only:
@ -124,5 +133,15 @@ pages:
artifacts:
expire_in: 1 week
paths:
- public
- public
allow_failure: true
windowsCompatibility:
image: stefanscherer/node-windows:10-build-tools
stage: metadata
script:
- npm install & npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- windows
allow_failure: true

11
.vscode/launch.json vendored
View File

@ -1,11 +0,0 @@
{
"version": "0.2.0",
"configurations": [
{
"command": "npm test",
"name": "Run npm test",
"request": "launch",
"type": "node-terminal"
}
]
}

26
.vscode/settings.json vendored
View File

@ -1,26 +0,0 @@
{
"json.schemas": [
{
"fileMatch": ["/npmextra.json"],
"schema": {
"type": "object",
"properties": {
"npmci": {
"type": "object",
"description": "settings for npmci"
},
"gitzone": {
"type": "object",
"description": "settings for gitzone",
"properties": {
"projectType": {
"type": "string",
"enum": ["website", "element", "service", "npm", "wcc"]
}
}
}
}
}
}
]
}

View File

@ -2,31 +2,5 @@
"npmci": {
"npmGlobalTools": [],
"npmAccessLevel": "public"
},
"gitzone": {
"projectType": "npm",
"module": {
"githost": "code.foss.global",
"gitscope": "push.rocks",
"gitrepo": "smartlog-receiver",
"description": "A package that acts as a receiver for smartlog-destination-receiver, utilizing plugins for functionality.",
"npmPackagename": "@push.rocks/smartlog-receiver",
"license": "MIT",
"keywords": [
"logging",
"receiver",
"smartlog",
"authentication",
"validation",
"typescript",
"plugins",
"smartlog integration",
"log management",
"security"
]
}
},
"tsdoc": {
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
}
}
}

14817
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,59 +1,28 @@
{
"name": "@push.rocks/smartlog-receiver",
"version": "2.0.0",
"name": "@pushrocks/smartlog-receiver",
"version": "1.0.8",
"private": false,
"description": "A package that acts as a receiver for smartlog-destination-receiver, utilizing plugins for functionality.",
"main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts",
"description": "a receiver for smartlog-destination-receiver",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"author": "Lossless GmbH",
"license": "MIT",
"scripts": {
"test": "(tstest test/)",
"build": "(tsbuild --web)",
"buildDocs": "tsdoc"
"build": "(tsbuild)",
"format": "(gitzone format)"
},
"devDependencies": {
"@gitzone/tsbuild": "^2.1.63",
"@gitzone/tstest": "^1.0.72",
"@pushrocks/tapbundle": "^5.0.4",
"@types/node": "^18.6.1"
"@gitzone/tsbuild": "^2.0.22",
"@gitzone/tstest": "^1.0.15",
"@pushrocks/tapbundle": "^3.0.7",
"@types/node": "^10.12.5",
"tslint": "^5.11.0",
"tslint-config-prettier": "^1.15.0"
},
"dependencies": {
"@pushrocks/smarthash": "^3.0.1",
"@pushrocks/smartlog": "^3.0.1",
"@pushrocks/smartlog-interfaces": "^2.0.23"
},
"files": [
"ts/**/*",
"ts_web/**/*",
"dist/**/*",
"dist_*/**/*",
"dist_ts/**/*",
"dist_ts_web/**/*",
"assets/**/*",
"cli.js",
"npmextra.json",
"readme.md"
],
"browserslist": [
"last 1 chrome versions"
],
"type": "module",
"keywords": [
"logging",
"receiver",
"smartlog",
"authentication",
"validation",
"typescript",
"plugins",
"smartlog integration",
"log management",
"security"
],
"homepage": "https://code.foss.global/push.rocks/smartlog-receiver",
"repository": {
"type": "git",
"url": "https://code.foss.global/push.rocks/smartlog-receiver.git"
"@pushrocks/smarthash": "^2.0.0",
"@pushrocks/smartlog": "^2.0.9",
"@pushrocks/smartlog-interfaces": "^2.0.3"
}
}
}

4806
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@ -1 +0,0 @@

128
readme.md
View File

@ -1,128 +0,0 @@
# @push.rocks/smartlog-receiver
a receiver for smartlog-destination-receiver
## Install
To install `@push.rocks/smartlog-receiver`, use the following command with npm:
```bash
npm install @push.rocks/smartlog-receiver --save
```
or with yarn:
```bash
yarn add @push.rocks/smartlog-receiver
```
Ensure that you have TypeScript and Node.js installed in your development environment as this module leverages TypeScript for type definitions.
## Usage
The `@push.rocks/smartlog-receiver` module is designed to receive log messages sent from applications using the `smartlog` logging system. It allows for centralized logging by receiving, validating, and processing log messages in a secure and controlled manner. Below, we'll go through how to set up and use `smartlog-receiver` in your project.
### Setting up SmartlogReceiver
First, make sure to import `SmartlogReceiver` from the package, along with the types it depends on if necessary.
```typescript
import { SmartlogReceiver, ISmartlogReceiverOptions } from '@push.rocks/smartlog-receiver';
import { Smartlog } from '@pushrocks/smartlog';
```
`SmartlogReceiver` requires an instance of `Smartlog` for logging internal messages and potentially logging the received log messages. Ensure you initialize `Smartlog` first:
```typescript
const smartlogInstance = new Smartlog({
logContext: {
company: 'YourCompany',
companyunit: 'YourUnit',
environment: 'production',
runtime: 'node',
version: '1.0.0'
},
minimumLogLevel: 'info',
});
smartlogInstance.enableConsole(); // Enabling console output for demonstration purposes
```
Now, instantiate the `SmartlogReceiver` with the necessary options. You need to provide a passphrase for authentication and a validator function that decides whether to accept or reject incoming messages based on your criteria.
```typescript
const smartlogReceiver = new SmartlogReceiver({
smartlogInstance: smartlogInstance,
passphrase: 'yourSecretPassphrase',
validatorFunction: async (logPackage) => {
// Example validation: accept only if message contains 'accepted'
return logPackage.message.includes('accepted');
},
});
```
### Handling Log Messages
To handle authenticated log messages, you'd typically have an endpoint in your application that receives log packages. Here, we'll simulate receiving a log package.
```typescript
import { ILogPackageAuthenticated } from '@pushrocks/smartlog-interfaces';
import * as smarthash from '@pushrocks/smarthash';
// Simulated received log message
const receivedLogPackage: ILogPackageAuthenticated = {
auth: smarthash.sha256FromStringSync('yourSecretPassphrase'), // Generate hash of your passphrase for authentication
logPackage: {
timestamp: Date.now(),
context: {
company: 'YourCompany',
companyunit: 'YourUnit',
environment: 'production',
runtime: 'node',
version: '1.0.0'
},
level: 'info',
type: 'log',
message: 'This is an accepted log message',
correlation: {
id: 'unique-correlation-id',
type: 'transaction'
}
}
};
// Handler function to process received log packages
async function handleReceivedLog(logPackage: ILogPackageAuthenticated) {
const result = await smartlogReceiver.handleAuthenticatedLog(logPackage);
console.log(result); // Should output { status: 'ok' } for successfully processed messages
}
handleReceivedLog(receivedLogPackage);
```
Ensure your validation and handling logic fits the security and architectural needs of your application.
### Advanced Usage
- **Batch Processing:** `SmartlogReceiver` also supports processing batches of logs efficiently through the method `handleManyAuthenticatedLogs`, facilitating bulk log management.
- **Customizing Smartlog:** Since `SmartlogReceiver` uses `Smartlog` for its operations, you can harness the full power of `Smartlog` for detailed customization, such as setting up different log destinations, filtering log levels, and more.
By setting up `@push.rocks/smartlog-receiver`, you're enabling a robust and flexible system to manage your application's logging infrastructure, making it easier to monitor and debug with centralized logs.
## License and Legal Information
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
### Trademarks
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.
### Company Information
Task Venture Capital GmbH
Registered at District court Bremen HRB 35230 HB, Germany
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.

View File

@ -1,25 +1,22 @@
import { expect, expectAsync, tap } from '@pushrocks/tapbundle';
import { expect, tap } from '@pushrocks/tapbundle';
import * as smartlog from '@pushrocks/smartlog';
import * as smarthash from '@pushrocks/smarthash';
import * as smartlogReceiver from '../ts/index.js';
import * as smartlogReceiver from '../ts/index';
let testReceiver: smartlogReceiver.SmartlogReceiver;
let testSmartlog = new smartlog.Smartlog({
logContext: null,
minimumLogLevel: 'debug',
});
let testSmartlog = smartlog.defaultLogger;
testSmartlog.enableConsole();
tap.test('should create a valid SmartlogReceiver', async () => {
testReceiver = new smartlogReceiver.SmartlogReceiver({
passphrase: 'hi',
smartlogInstance: testSmartlog,
validatorFunction: async () => {
validatorFunction: () => {
return true;
},
}
});
expect(testReceiver).toBeInstanceOf(smartlogReceiver.SmartlogReceiver);
expect(testReceiver).to.be.instanceof(smartlogReceiver.SmartlogReceiver);
});
tap.test('should receive a message', async () => {
@ -33,17 +30,13 @@ tap.test('should receive a message', async () => {
containerName: null,
environment: 'staging',
runtime: 'node',
zone: 'gitzone',
zone: 'gitzone'
},
level: 'info',
type: 'log',
correlation: {
id: '123',
type: 'none',
},
message: 'hi there',
},
message: 'hi there'
}
});
});
})
tap.start();

View File

@ -1,8 +0,0 @@
/**
* autocreated commitinfo by @pushrocks/commitinfo
*/
export const commitinfo = {
name: '@pushrocks/smartlog-receiver',
version: '2.0.0',
description: 'a receiver for smartlog-destination-receiver'
}

View File

@ -1 +1 @@
export * from './sl.classes.smartlogreceiver.js';
export * from './sl.classes.smartlogreceiver';

View File

@ -1,12 +1,8 @@
import * as plugins from './sl.receiver.plugins.js';
import * as plugins from './sl.receiver.plugins';
import {
ILogPackage,
ILogPackageAuthenticated,
ILogDestination,
} from '@pushrocks/smartlog-interfaces';
import { ILogPackage, ILogPackageAuthenticated, ILogDestination } from '@pushrocks/smartlog-interfaces';
export type TValidatorFunction = (logPackage: ILogPackage) => Promise<boolean>;
export type TValidatorFunction = (logPackage: ILogPackage) => boolean;
export interface ISmartlogReceiverOptions {
smartlogInstance: plugins.smartlog.Smartlog;
@ -18,37 +14,26 @@ export interface ISmartlogReceiverOptions {
* a class that receives smartlog packages
*/
export class SmartlogReceiver {
public passphrase: string;
public validatorFunction: TValidatorFunction;
public smartlogInstance: plugins.smartlog.Smartlog;
passphrase: string;
validatorFunction: TValidatorFunction;
smartlogInstance: plugins.smartlog.Smartlog;
constructor(smartlogReceiverOptions: ISmartlogReceiverOptions) {
this.passphrase = smartlogReceiverOptions.passphrase;
this.validatorFunction =
smartlogReceiverOptions.validatorFunction ||
(async (logpackageArg) => {
return true;
});
this.validatorFunction = smartlogReceiverOptions.validatorFunction;
this.smartlogInstance = smartlogReceiverOptions.smartlogInstance;
}
/**
* handles a authenticated log
*/
public async handleAuthenticatedLog(authenticatedLogPackageArg: ILogPackageAuthenticated) {
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);
if(authString === plugins.smarthash.sha256FromStringSync(this.passphrase)) {
// this.smartlogInstance.log('ok', 'Message accepted');
this.smartlogInstance.handleLogPackage(logPackage);
return { status: 'ok' };
} else {
this.smartlogInstance.log('error', 'Message rejected because of bad passphrase');
@ -57,17 +42,5 @@ export class SmartlogReceiver {
}
}
/**
* 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);
}
}

View File

@ -1,4 +1,7 @@
import * as smarthash from '@pushrocks/smarthash';
import * as smartlog from '@pushrocks/smartlog';
export { smartlog, smarthash };
export {
smartlog,
smarthash
};

View File

@ -1,14 +0,0 @@
{
"compilerOptions": {
"experimentalDecorators": true,
"useDefineForClassFields": false,
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"esModuleInterop": true,
"verbatimModuleSyntax": true
},
"exclude": [
"dist_*/**/*.d.ts"
]
}

17
tslint.json Normal file
View File

@ -0,0 +1,17 @@
{
"extends": ["tslint:latest", "tslint-config-prettier"],
"rules": {
"semicolon": [true, "always"],
"no-console": false,
"ordered-imports": false,
"object-literal-sort-keys": false,
"member-ordering": {
"options":{
"order": [
"static-method"
]
}
}
},
"defaultSeverity": "warning"
}