Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6003625186 | |||
| 3b50e9c8cc | |||
| 2e42011eda | |||
| d9512ae3e8 | |||
| 32e72dc131 | |||
| 5371bd058a | |||
| eb9151e23e | |||
| fa4e54a7ee |
+1
-3
@@ -15,8 +15,6 @@ node_modules/
|
|||||||
|
|
||||||
# builds
|
# builds
|
||||||
dist/
|
dist/
|
||||||
dist_web/
|
dist_*/
|
||||||
dist_serve/
|
|
||||||
dist_ts_web/
|
|
||||||
|
|
||||||
# custom
|
# custom
|
||||||
+51
-28
@@ -1,16 +1,19 @@
|
|||||||
# gitzone ci_default
|
# gitzone ci_default
|
||||||
image: hosttoday/ht-docker-node:npmci
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
|
||||||
cache:
|
cache:
|
||||||
paths:
|
paths:
|
||||||
- .npmci_cache/
|
- .npmci_cache/
|
||||||
key: "$CI_BUILD_STAGE"
|
key: '$CI_BUILD_STAGE'
|
||||||
|
|
||||||
stages:
|
stages:
|
||||||
- security
|
- security
|
||||||
- test
|
- test
|
||||||
- release
|
- release
|
||||||
- metadata
|
- metadata
|
||||||
|
|
||||||
|
before_script:
|
||||||
|
- npm install -g @shipzone/npmci
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# security stage
|
# security stage
|
||||||
@@ -19,38 +22,42 @@ mirror:
|
|||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci git mirror
|
- npmci git mirror
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
|
|
||||||
snyk:
|
auditProductionDependencies:
|
||||||
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci command npm install -g snyk
|
- npmci command npm install --production --ignore-scripts
|
||||||
- npmci command npm install --ignore-scripts
|
- npmci command npm config set registry https://registry.npmjs.org
|
||||||
- npmci command snyk test
|
- npmci command npm audit --audit-level=high --only=prod --production
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
allow_failure: true
|
||||||
|
|
||||||
|
auditDevDependencies:
|
||||||
|
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
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
allow_failure: true
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# test stage
|
# test stage
|
||||||
# ====================
|
# ====================
|
||||||
|
|
||||||
testLTS:
|
testStable:
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- npmci npm prepare
|
|
||||||
- npmci node install lts
|
|
||||||
- npmci npm install
|
|
||||||
- npmci npm test
|
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
testSTABLE:
|
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
@@ -60,7 +67,17 @@ testSTABLE:
|
|||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
|
||||||
|
testBuild:
|
||||||
|
stage: test
|
||||||
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
|
- npmci node install stable
|
||||||
|
- npmci npm install
|
||||||
|
- npmci command npm run build
|
||||||
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
|
||||||
release:
|
release:
|
||||||
stage: release
|
stage: release
|
||||||
@@ -70,6 +87,7 @@ release:
|
|||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
|
|
||||||
@@ -79,11 +97,14 @@ release:
|
|||||||
codequality:
|
codequality:
|
||||||
stage: metadata
|
stage: metadata
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
script:
|
script:
|
||||||
- npmci command npm install -g tslint typescript
|
- npmci command npm install -g typescript
|
||||||
|
- npmci npm prepare
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- priv
|
- priv
|
||||||
|
|
||||||
@@ -94,18 +115,20 @@ trigger:
|
|||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
|
|
||||||
pages:
|
pages:
|
||||||
image: hosttoday/ht-docker-node:npmci
|
|
||||||
stage: metadata
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
|
- npmci node install lts
|
||||||
- npmci command npm install -g @gitzone/tsdoc
|
- npmci command npm install -g @gitzone/tsdoc
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci command tsdoc
|
- npmci command tsdoc
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
only:
|
only:
|
||||||
|
|||||||
Vendored
+3
-21
@@ -2,28 +2,10 @@
|
|||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"configurations": [
|
"configurations": [
|
||||||
{
|
{
|
||||||
"name": "current file",
|
"command": "npm test",
|
||||||
"type": "node",
|
"name": "Run npm test",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"args": [
|
"type": "node-terminal"
|
||||||
"${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"
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+26
@@ -0,0 +1,26 @@
|
|||||||
|
{
|
||||||
|
"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"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
+2
-1
@@ -1,10 +1,11 @@
|
|||||||
{
|
{
|
||||||
"gitzone": {
|
"gitzone": {
|
||||||
|
"projectType": "npm",
|
||||||
"module": {
|
"module": {
|
||||||
"githost": "gitlab.com",
|
"githost": "gitlab.com",
|
||||||
"gitscope": "pushrocks",
|
"gitscope": "pushrocks",
|
||||||
"gitrepo": "smartguard",
|
"gitrepo": "smartguard",
|
||||||
"shortDescription": "smart guards for validations",
|
"description": "smart guards for validations",
|
||||||
"npmPackagename": "@pushrocks/smartguard",
|
"npmPackagename": "@pushrocks/smartguard",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"projectDomain": "push.rocks"
|
"projectDomain": "push.rocks"
|
||||||
|
|||||||
Generated
+18168
-955
File diff suppressed because it is too large
Load Diff
+29
-9
@@ -1,10 +1,11 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartguard",
|
"name": "@pushrocks/smartguard",
|
||||||
"version": "1.0.2",
|
"version": "2.0.0",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "smart guards for validations",
|
"description": "smart guards for validations",
|
||||||
"main": "dist/index.js",
|
"main": "dist_ts/index.js",
|
||||||
"typings": "dist/index.d.ts",
|
"typings": "dist_ts/index.d.ts",
|
||||||
|
"type": "module",
|
||||||
"author": "Lossless GmbH",
|
"author": "Lossless GmbH",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@@ -13,12 +14,31 @@
|
|||||||
"format": "(gitzone format)"
|
"format": "(gitzone format)"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.0.22",
|
"@gitzone/tsbuild": "^2.1.60",
|
||||||
"@gitzone/tstest": "^1.0.15",
|
"@gitzone/tstest": "^1.0.69",
|
||||||
"@pushrocks/tapbundle": "^3.0.7",
|
"@pushrocks/smartexpress": "^3.0.110",
|
||||||
"@types/node": "^10.11.7",
|
"@pushrocks/tapbundle": "^5.0.2",
|
||||||
"tslint": "^5.11.0",
|
"@types/node": "^17.0.22",
|
||||||
|
"tslint": "^6.1.3",
|
||||||
"tslint-config-prettier": "^1.15.0"
|
"tslint-config-prettier": "^1.15.0"
|
||||||
},
|
},
|
||||||
"dependencies": {}
|
"dependencies": {
|
||||||
|
"@pushrocks/smartpromise": "^3.0.2",
|
||||||
|
"@pushrocks/smartrequest": "^1.1.56"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"ts/**/*",
|
||||||
|
"ts_web/**/*",
|
||||||
|
"dist/**/*",
|
||||||
|
"dist_*/**/*",
|
||||||
|
"dist_ts/**/*",
|
||||||
|
"dist_ts_web/**/*",
|
||||||
|
"assets/**/*",
|
||||||
|
"cli.js",
|
||||||
|
"npmextra.json",
|
||||||
|
"readme.md"
|
||||||
|
],
|
||||||
|
"browserslist": [
|
||||||
|
"last 1 chrome versions"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
# @pushrocks/smartguard
|
||||||
|
smart guards for validations
|
||||||
|
|
||||||
|
## Availabililty and Links
|
||||||
|
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartguard)
|
||||||
|
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartguard)
|
||||||
|
* [github.com (source mirror)](https://github.com/pushrocks/smartguard)
|
||||||
|
* [docs (typedoc)](https://pushrocks.gitlab.io/smartguard/)
|
||||||
|
|
||||||
|
## Status for master
|
||||||
|
|
||||||
|
Status Category | Status Badge
|
||||||
|
-- | --
|
||||||
|
GitLab Pipelines | [](https://lossless.cloud)
|
||||||
|
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
||||||
|
npm | [](https://lossless.cloud)
|
||||||
|
Snyk | [](https://lossless.cloud)
|
||||||
|
TypeScript Support | [](https://lossless.cloud)
|
||||||
|
node Support | [](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||||
|
Code Style | [](https://lossless.cloud)
|
||||||
|
PackagePhobia (total standalone install weight) | [](https://lossless.cloud)
|
||||||
|
PackagePhobia (package size on registry) | [](https://lossless.cloud)
|
||||||
|
BundlePhobia (total size when bundled) | [](https://lossless.cloud)
|
||||||
|
Platform support | [](https://lossless.cloud) [](https://lossless.cloud)
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
|
||||||
|
## Contribution
|
||||||
|
|
||||||
|
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). :)
|
||||||
|
|
||||||
|
For further information read the linked docs at the top of this readme.
|
||||||
|
|
||||||
|
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||||
|
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
||||||
|
|
||||||
|
[](https://maintainedby.lossless.com)
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
import { expect, expectAsync, tap } from '@pushrocks/tapbundle';
|
||||||
|
import * as smartguard from '../ts/index.js';
|
||||||
|
import * as smartexpress from '@pushrocks/smartexpress';
|
||||||
|
import * as smartrequest from '@pushrocks/smartrequest';
|
||||||
|
|
||||||
|
let smartexpressInstance: smartexpress.Server;
|
||||||
|
|
||||||
|
tap.test('should create a demo smartexpress instance', async () => {
|
||||||
|
smartexpressInstance = new smartexpress.Server({
|
||||||
|
cors: true,
|
||||||
|
forceSsl: false,
|
||||||
|
defaultAnswer: async () => 'hi there',
|
||||||
|
port: 3211,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should be able to create smartguards for a request', async () => {
|
||||||
|
interface IRequestGuardData {
|
||||||
|
req: smartexpress.Request;
|
||||||
|
res: smartexpress.Response;
|
||||||
|
}
|
||||||
|
const ipGuard = new smartguard.Guard<IRequestGuardData>(async (dataArg) => {
|
||||||
|
console.log('executing ip guard');
|
||||||
|
if (dataArg) {
|
||||||
|
console.log('ip guard succeeded');
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
console.log('ip guard failed!');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
smartexpressInstance.addRoute(
|
||||||
|
'/testroute',
|
||||||
|
new smartexpress.Handler('ALL', async (req, res) => {
|
||||||
|
await smartguard.passGuards(
|
||||||
|
{
|
||||||
|
req,
|
||||||
|
res,
|
||||||
|
},
|
||||||
|
[ipGuard]
|
||||||
|
);
|
||||||
|
console.log('ip guard said ok');
|
||||||
|
res.status(200);
|
||||||
|
res.send('hi');
|
||||||
|
})
|
||||||
|
);
|
||||||
|
console.log('Got here ok');
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should start server with guards in place', async () => {
|
||||||
|
await smartexpressInstance.start();
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should execute a request', async () => {
|
||||||
|
const response = await smartrequest.request('http://localhost:3211/testroute', {
|
||||||
|
method: 'GET',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should end the demo smartexpress instance', async () => {
|
||||||
|
await smartexpressInstance.stop();
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.start();
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
import { expect, tap } from '@pushrocks/tapbundle';
|
|
||||||
import * as smartguard from '../ts/index'
|
|
||||||
|
|
||||||
tap.test('first test', async () => {
|
|
||||||
console.log(smartguard.standardExport)
|
|
||||||
})
|
|
||||||
|
|
||||||
tap.start()
|
|
||||||
+17
-2
@@ -1,3 +1,18 @@
|
|||||||
import * as plugins from './smartguard.plugins';
|
import * as plugins from './smartguard.plugins.js';
|
||||||
|
import { Guard } from './smartguard.classes.guard.js';
|
||||||
|
import { GuardSet } from './smartguard.classes.guardset.js';
|
||||||
|
export * from './smartguard.classes.guard.js';
|
||||||
|
|
||||||
export let standardExport = 'Hi there! :) This is an exported string';
|
export const passGuards = async <T>(dataArg: T, guards: Array<Guard<T>>) => {
|
||||||
|
const done = plugins.smartpromise.defer();
|
||||||
|
const guardSet = new GuardSet<T>(guards);
|
||||||
|
const results = await guardSet.executeGuardsWithData(dataArg);
|
||||||
|
for (const result of results) {
|
||||||
|
if (!result) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
done.resolve();
|
||||||
|
await done.promise;
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
import * as plugins from './smartguard.plugins.js';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* a block handler is used
|
||||||
|
*/
|
||||||
|
export class BlockHandler {}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
import * as plugins from './smartguard.plugins.js';
|
||||||
|
|
||||||
|
export type TGuardFunction<T> = (dataArg: T) => Promise<boolean>;
|
||||||
|
|
||||||
|
export class Guard<T> {
|
||||||
|
private guardFunction: TGuardFunction<T>;
|
||||||
|
constructor(guardFunctionArg: TGuardFunction<T>) {
|
||||||
|
this.guardFunction = guardFunctionArg;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* executes the guard against a data argument;
|
||||||
|
* @param dataArg
|
||||||
|
*/
|
||||||
|
public async executeGuardWithData(dataArg: T) {
|
||||||
|
const result = await this.guardFunction(dataArg);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
import * as plugins from './smartguard.plugins.js';
|
||||||
|
import { Guard } from './smartguard.classes.guard.js';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* a guardSet is a set of guards that need to be fulfilled
|
||||||
|
*/
|
||||||
|
export class GuardSet<T> {
|
||||||
|
public guards: Array<Guard<T>>;
|
||||||
|
public passed: boolean;
|
||||||
|
constructor(guardsArrayArg: Array<Guard<T>>) {
|
||||||
|
this.guards = guardsArrayArg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async executeGuardsWithData(dataArg: T) {
|
||||||
|
const resultPromises: Array<Promise<boolean>> = [];
|
||||||
|
for (const guard of this.guards) {
|
||||||
|
const resultPromise = guard.executeGuardWithData(dataArg);
|
||||||
|
resultPromises.push(resultPromise);
|
||||||
|
}
|
||||||
|
const results = Promise.all(resultPromises);
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
const removeme = {};
|
import * as smartpromise from '@pushrocks/smartpromise';
|
||||||
export {
|
|
||||||
removeme
|
// pushrocks scope
|
||||||
}
|
export { smartpromise };
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"target": "ES2022",
|
||||||
|
"module": "ES2022",
|
||||||
|
"moduleResolution": "nodenext"
|
||||||
|
}
|
||||||
|
}
|
||||||
-17
@@ -1,17 +0,0 @@
|
|||||||
{
|
|
||||||
"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"
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user