Compare commits
22 Commits
Author | SHA1 | Date | |
---|---|---|---|
ee99ddd23c | |||
b99a0548a2 | |||
1c678ced10 | |||
df1f6dff2e | |||
961dfc5693 | |||
6e761cb2b9 | |||
ef568f2aa2 | |||
fced92e1cc | |||
f73334d8fc | |||
d170af1db5 | |||
9e6b92f864 | |||
b094c07ef2 | |||
33584785df | |||
580f8dd7f7 | |||
c1d2231a94 | |||
d73a144e8f | |||
e91131b7ae | |||
4dd5d12a2e | |||
7fd110d56c | |||
bb7e9e75ba | |||
0b576c3170 | |||
df96f08038 |
@ -19,23 +19,35 @@ mirror:
|
||||
stage: security
|
||||
script:
|
||||
- npmci git mirror
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
audit:
|
||||
auditProductionDependencies:
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
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
|
||||
tags:
|
||||
- docker
|
||||
|
||||
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
|
||||
- npmci command npm audit --audit-level=high --only=dev
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
allow_failure: true
|
||||
|
||||
# ====================
|
||||
# test stage
|
||||
@ -50,9 +62,7 @@ testStable:
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- priv
|
||||
|
||||
testBuild:
|
||||
stage: test
|
||||
@ -63,9 +73,7 @@ testBuild:
|
||||
- npmci command npm run build
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
release:
|
||||
stage: release
|
||||
@ -85,6 +93,8 @@ release:
|
||||
codequality:
|
||||
stage: metadata
|
||||
allow_failure: true
|
||||
only:
|
||||
- tags
|
||||
script:
|
||||
- npmci command npm install -g tslint typescript
|
||||
- npmci npm prepare
|
||||
|
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
@ -15,7 +15,7 @@
|
||||
"properties": {
|
||||
"projectType": {
|
||||
"type": "string",
|
||||
"enum": ["website", "element", "service", "npm"]
|
||||
"enum": ["website", "element", "service", "npm", "wcc"]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
10383
package-lock.json
generated
10383
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
23
package.json
23
package.json
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@apiglobal/sdk",
|
||||
"version": "1.0.3",
|
||||
"version": "1.0.14",
|
||||
"private": false,
|
||||
"description": "an sdk package for api.global",
|
||||
"main": "dist_ts/index.js",
|
||||
@ -8,21 +8,21 @@
|
||||
"author": "Lossless GmbH",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"test": "(tstest test/)",
|
||||
"build": "(tsbuild)",
|
||||
"format": "(gitzone format)"
|
||||
"test": "(tstest test/ --web)",
|
||||
"build": "(tsbuild --web)"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@gitzone/tsbuild": "^2.0.22",
|
||||
"@gitzone/tstest": "^1.0.15",
|
||||
"@gitzone/tsbuild": "^2.1.24",
|
||||
"@gitzone/tstest": "^1.0.33",
|
||||
"@pushrocks/tapbundle": "^3.0.7",
|
||||
"@types/node": "^13.9.3",
|
||||
"tslint": "^6.1.0",
|
||||
"@types/node": "^14.0.14",
|
||||
"tslint": "^6.1.2",
|
||||
"tslint-config-prettier": "^1.15.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@apiglobal/typedrequest": "^1.0.28",
|
||||
"@tsclass/tsclass": "^3.0.16"
|
||||
"@apiglobal/typedrequest": "^1.0.38",
|
||||
"@pushrocks/smartfile": "^8.0.0",
|
||||
"@tsclass/tsclass": "^3.0.18"
|
||||
},
|
||||
"files": [
|
||||
"ts/**/*",
|
||||
@ -35,5 +35,8 @@
|
||||
"cli.js",
|
||||
"npmextra.json",
|
||||
"readme.md"
|
||||
],
|
||||
"browserslist": [
|
||||
"last 1 chrome versions"
|
||||
]
|
||||
}
|
||||
|
21
readme.md
21
readme.md
@ -8,13 +8,20 @@ an sdk package for api.global
|
||||
* [docs (typedoc)](https://apiglobal.gitlab.io/sdk/)
|
||||
|
||||
## Status for master
|
||||
[](https://gitlab.com/apiglobal/sdk/commits/master)
|
||||
[](https://gitlab.com/apiglobal/sdk/commits/master)
|
||||
[](https://www.npmjs.com/package/@apiglobal/sdk)
|
||||
[](https://snyk.io/test/npm/@apiglobal/sdk)
|
||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
[](https://prettier.io/)
|
||||
|
||||
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
|
||||
|
||||
|
36
test/test.ts
36
test/test.ts
@ -1,18 +1,40 @@
|
||||
import { expect, tap } from '@pushrocks/tapbundle';
|
||||
import * as sdk from '../ts/index';
|
||||
import { ISimpleRequest } from '@tsclass/tsclass/dist_ts/network';
|
||||
import { TypedRouter } from '@apiglobal/typedrequest';
|
||||
|
||||
tap.test('should create a valid Handler', async () => {
|
||||
class MyHandler extends sdk.AAgHandler {
|
||||
slug: 'testapi';
|
||||
public async handleRequest(request: ISimpleRequest) {
|
||||
// this.authenticationHandler
|
||||
let response: any;
|
||||
return response;
|
||||
class MyHandler extends sdk.AAgHandler<any> {
|
||||
public slug: 'testapi';
|
||||
public typedrouter = new TypedRouter();
|
||||
|
||||
public async checkReqirements() {
|
||||
return {
|
||||
allOk: true,
|
||||
reason: '',
|
||||
};
|
||||
}
|
||||
|
||||
public async start() {}
|
||||
|
||||
public async stop() {}
|
||||
|
||||
public async checkRequirements(): Promise<sdk.IRequirementResult> {
|
||||
return {
|
||||
allOk: true,
|
||||
reason: '',
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
const myHandlerInstance = new MyHandler();
|
||||
// tslint:disable-next-line: max-classes-per-file
|
||||
class AgEnvironement extends sdk.AgEnvironment {
|
||||
public async getEnvVar(nameArg: string) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
const myHandlerInstance = new MyHandler(new AgEnvironement());
|
||||
|
||||
expect(myHandlerInstance).to.be.instanceOf(sdk.AAgHandler);
|
||||
});
|
||||
|
@ -1 +1,5 @@
|
||||
export * from './sdk.classes.agenvironment';
|
||||
export * from './sdk.classes.aghandler';
|
||||
export * from './sdk.classes.authinfo';
|
||||
|
||||
export * from './interfaces';
|
||||
|
@ -1 +1 @@
|
||||
export {};
|
||||
export * from './projectsettings';
|
||||
|
7
ts/interfaces/projectsettings.ts
Normal file
7
ts/interfaces/projectsettings.ts
Normal file
@ -0,0 +1,7 @@
|
||||
export interface IProjectSettings {
|
||||
registryId: string;
|
||||
registryUrl: string;
|
||||
registryToken: string;
|
||||
packageName: string;
|
||||
environmentVariables: {[key: string]: string};
|
||||
}
|
8
ts/sdk.classes.agenvironment.ts
Normal file
8
ts/sdk.classes.agenvironment.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import * as plugins from './sdk.plugins';
|
||||
|
||||
/**
|
||||
* AgEnvironment handles the provision of environment variables to handlers
|
||||
*/
|
||||
export abstract class AgEnvironment {
|
||||
public abstract async getEnvVar(envVarName: string): Promise<string>;
|
||||
}
|
@ -1,16 +1,49 @@
|
||||
import * as plugins from './sdk.plugins';
|
||||
import { AuthInfo } from './sdk.classes.authinfo';
|
||||
import { AgEnvironment } from './sdk.classes.agenvironment';
|
||||
|
||||
export abstract class AAgHandler {
|
||||
public authenticationHandler: any;
|
||||
export interface IRequirementResult {
|
||||
allOk: boolean;
|
||||
reason: string;
|
||||
}
|
||||
|
||||
export abstract class AAgHandler<TClaim> {
|
||||
public agEnvironment: AgEnvironment;
|
||||
|
||||
/**
|
||||
* a slug that separates the handler from other handlers
|
||||
*/
|
||||
public abstract slug: string;
|
||||
public abstract typedrouter: plugins.typedrequest.TypedRouter;
|
||||
public abstract checkRequirements(): Promise<IRequirementResult>;
|
||||
|
||||
public abstract handleRequest (request: plugins.tsclass.network.ISimpleRequest): Promise<plugins.tsclass.network.ISimpleResponse>;
|
||||
|
||||
public setAuthenticationHandler(authHandler) {
|
||||
this.authenticationHandler = authHandler;
|
||||
public async checkQenvFile(pathToQenvFileArg: string) {
|
||||
if(!(await plugins.smartfile.fs.fileExists(pathToQenvFileArg))) {
|
||||
throw new Error(`AgHandler with slug '${this.slug}': qenv file does not exists at ${pathToQenvFileArg}`);
|
||||
}
|
||||
const qenvFile = plugins.smartfile.fs.toObjectSync(pathToQenvFileArg);
|
||||
const missingEnvironmentVariables: string[] = [];
|
||||
for (const envVar of qenvFile.required as string[]) {
|
||||
const result = this.agEnvironment.getEnvVar(envVar);
|
||||
if (!result) {
|
||||
missingEnvironmentVariables.push(envVar);
|
||||
}
|
||||
}
|
||||
if (missingEnvironmentVariables.length > 0) {
|
||||
console.log(`AgHandler with slug '${this.slug}': There are ${missingEnvironmentVariables.length} missing environment variables`);
|
||||
const errorMessage = `AgHandler with slug '${this.slug}': The missing env Varibles are ${missingEnvironmentVariables}`;
|
||||
console.log(errorMessage);
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
constructor(agEnvironmentArg: AgEnvironment) {
|
||||
this.agEnvironment = agEnvironmentArg;
|
||||
}
|
||||
|
||||
/**
|
||||
* start the ag-handler
|
||||
*/
|
||||
public abstract start(): Promise<any>;
|
||||
public abstract stop(): Promise<any>;
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
import * as plugins from './sdk.plugins';
|
||||
|
||||
export abstract class AAuthenticationHandler {}
|
19
ts/sdk.classes.authinfo.ts
Normal file
19
ts/sdk.classes.authinfo.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import * as plugins from './sdk.plugins';
|
||||
|
||||
/**
|
||||
* AuthInfo is created for every single incoming request
|
||||
*/
|
||||
export abstract class AuthInfo<TClaim> {
|
||||
/**
|
||||
* wether the request is generally authenticated
|
||||
*/
|
||||
public abstract authenticated: boolean;
|
||||
|
||||
/**
|
||||
* A heuristic analysis result wether the request might be fishy.
|
||||
* Note: DDOS attacks should never make it anywhere near your code and are filtered by api.global itself.
|
||||
*/
|
||||
public abstract potentiallyMalicious: boolean;
|
||||
|
||||
public abstract claim: TClaim;
|
||||
}
|
@ -1,6 +1,18 @@
|
||||
// node native scope
|
||||
import * as path from 'path';
|
||||
|
||||
// @apiglobal scope
|
||||
import * as typedrequest from '@apiglobal/typedrequest';
|
||||
|
||||
export { typedrequest };
|
||||
|
||||
// pushrocks scope
|
||||
import * as smartfile from '@pushrocks/smartfile';
|
||||
|
||||
export {
|
||||
smartfile
|
||||
};
|
||||
|
||||
// @tsclass scope
|
||||
import * as tsclass from '@tsclass/tsclass';
|
||||
|
||||
|
Reference in New Issue
Block a user