Compare commits

..

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

15 changed files with 3108 additions and 18078 deletions

View File

@ -12,35 +12,30 @@ stages:
- release
- metadata
before_script:
- npm install -g @shipzone/npmci
# ====================
# 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:
- lossless
- docker
allow_failure: true
- notpriv
auditDevDependencies:
audit:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci npm prepare
- 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 npm audit --audit-level=high
tags:
- lossless
- docker
allow_failure: true
- notpriv
# ====================
# test stage
@ -55,7 +50,9 @@ testStable:
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- lossless
- docker
- priv
testBuild:
stage: test
@ -66,7 +63,9 @@ testBuild:
- npmci command npm run build
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- lossless
- docker
- notpriv
release:
stage: release
@ -86,12 +85,11 @@ release:
codequality:
stage: metadata
allow_failure: true
only:
- tags
script:
- npmci command npm install -g typescript
- npmci command npm install -g tslint typescript
- npmci npm prepare
- npmci npm install
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
tags:
- lossless
- docker
@ -111,10 +109,11 @@ trigger:
pages:
stage: metadata
script:
- npmci node install stable
- npmci node install lts
- npmci command npm install -g @gitzone/tsdoc
- npmci npm prepare
- npmci npm install
- npmci command npm run buildDocs
- npmci command tsdoc
tags:
- lossless
- docker

24
.vscode/launch.json vendored
View File

@ -2,10 +2,28 @@
"version": "0.2.0",
"configurations": [
{
"command": "npm test",
"name": "Run npm test",
"name": "current file",
"type": "node",
"request": "launch",
"type": "node-terminal"
"args": [
"${relativeFile}"
],
"runtimeArgs": ["-r", "@gitzone/tsrun"],
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": "test.ts",
"type": "node",
"request": "launch",
"args": [
"test/test.ts"
],
"runtimeArgs": ["-r", "@gitzone/tsrun"],
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"internalConsoleOptions": "openOnSessionStart"
}
]
}

View File

@ -15,7 +15,7 @@
"properties": {
"projectType": {
"type": "string",
"enum": ["website", "element", "service", "npm", "wcc"]
"enum": ["website", "element", "service", "npm"]
}
}
}

View File

@ -6,27 +6,12 @@
"gitzone": {
"projectType": "npm",
"module": {
"githost": "code.foss.global",
"gitscope": "push.rocks",
"githost": "gitlab.com",
"gitscope": "pushrocks",
"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"
]
"shortDescription": "a receiver for smartlog-destination-receiver",
"npmPackagename": "@pushrocks/smartlog-receiver",
"license": "MIT"
}
},
"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"
}
}

16016
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,8 +1,8 @@
{
"name": "@push.rocks/smartlog-receiver",
"version": "2.0.0",
"name": "@pushrocks/smartlog-receiver",
"version": "1.0.11",
"private": false,
"description": "A package that acts as a receiver for smartlog-destination-receiver, utilizing plugins for functionality.",
"description": "a receiver for smartlog-destination-receiver",
"main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts",
"author": "Lossless GmbH",
@ -10,18 +10,20 @@
"scripts": {
"test": "(tstest test/)",
"build": "(tsbuild --web)",
"buildDocs": "tsdoc"
"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.1.24",
"@gitzone/tstest": "^1.0.33",
"@pushrocks/tapbundle": "^3.2.1",
"@types/node": "^14.0.11",
"tslint": "^6.1.2",
"tslint-config-prettier": "^1.18.0"
},
"dependencies": {
"@pushrocks/smarthash": "^3.0.1",
"@pushrocks/smartlog": "^3.0.1",
"@pushrocks/smartlog-interfaces": "^2.0.23"
"@pushrocks/smarthash": "^2.1.6",
"@pushrocks/smartlog": "^2.0.24",
"@pushrocks/smartlog-interfaces": "^2.0.15"
},
"files": [
"ts/**/*",
@ -34,26 +36,5 @@
"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"
}
}
]
}

4806
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@ -1 +0,0 @@

143
readme.md
View File

@ -1,128 +1,39 @@
# @push.rocks/smartlog-receiver
# @pushrocks/smartlog-receiver
a receiver for smartlog-destination-receiver
## Install
## Availabililty and Links
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartlog-receiver)
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartlog-receiver)
* [github.com (source mirror)](https://github.com/pushrocks/smartlog-receiver)
* [docs (typedoc)](https://pushrocks.gitlab.io/smartlog-receiver/)
To install `@push.rocks/smartlog-receiver`, use the following command with npm:
## Status for master
```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.
Status Category | Status Badge
-- | --
GitLab Pipelines | [![pipeline status](https://gitlab.com/pushrocks/smartlog-receiver/badges/master/pipeline.svg)](https://lossless.cloud)
GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/pushrocks/smartlog-receiver/badges/master/coverage.svg)](https://lossless.cloud)
npm | [![npm downloads per month](https://badgen.net/npm/dy/@pushrocks/smartlog-receiver)](https://lossless.cloud)
Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/pushrocks/smartlog-receiver)](https://lossless.cloud)
TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud)
node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud)
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@pushrocks/smartlog-receiver)](https://lossless.cloud)
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@pushrocks/smartlog-receiver)](https://lossless.cloud)
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@pushrocks/smartlog-receiver)](https://lossless.cloud)
Platform support | [![Supports Windows 10](https://badgen.net/badge/supports%20Windows%2010/yes/green?icon=windows)](https://lossless.cloud) [![Supports Mac OS X](https://badgen.net/badge/supports%20Mac%20OS%20X/yes/green?icon=apple)](https://lossless.cloud)
## 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.
Use TypeScript for best in class intellisense.
### Setting up SmartlogReceiver
## Contribution
First, make sure to import `SmartlogReceiver` from the package, along with the types it depends on if necessary.
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
```typescript
import { SmartlogReceiver, ISmartlogReceiverOptions } from '@push.rocks/smartlog-receiver';
import { Smartlog } from '@pushrocks/smartlog';
```
For further information read the linked docs at the top of this readme.
`SmartlogReceiver` requires an instance of `Smartlog` for logging internal messages and potentially logging the received log messages. Ensure you initialize `Smartlog` first:
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
```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.
[![repo-footer](https://lossless.gitlab.io/publicrelations/repofooter.svg)](https://maintainedby.lossless.com)

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,16 +30,16 @@ 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',
type: 'none'
},
message: 'hi there',
},
}
});
});

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,12 @@
import * as plugins from './sl.receiver.plugins.js';
import * as plugins from './sl.receiver.plugins';
import {
ILogPackage,
ILogPackageAuthenticated,
ILogDestination,
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;
@ -24,11 +24,7 @@ export class SmartlogReceiver {
constructor(smartlogReceiverOptions: ISmartlogReceiverOptions) {
this.passphrase = smartlogReceiverOptions.passphrase;
this.validatorFunction =
smartlogReceiverOptions.validatorFunction ||
(async (logpackageArg) => {
return true;
});
this.validatorFunction = smartlogReceiverOptions.validatorFunction;
this.smartlogInstance = smartlogReceiverOptions.smartlogInstance;
}
@ -39,15 +35,8 @@ export class SmartlogReceiver {
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');
if (authString === plugins.smarthash.sha256FromStringSync(this.passphrase)) {
// this.smartlogInstance.log('ok', 'Message accepted');
this.smartlogInstance.handleLog(logPackage);
return { status: 'ok' };
} else {

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"
}