Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
e91131b7ae | |||
4dd5d12a2e | |||
7fd110d56c | |||
bb7e9e75ba | |||
0b576c3170 | |||
df96f08038 |
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@apiglobal/sdk",
|
"name": "@apiglobal/sdk",
|
||||||
"version": "1.0.3",
|
"version": "1.0.6",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@apiglobal/sdk",
|
"name": "@apiglobal/sdk",
|
||||||
"version": "1.0.3",
|
"version": "1.0.6",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "an sdk package for api.global",
|
"description": "an sdk package for api.global",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
@ -8,9 +8,8 @@
|
|||||||
"author": "Lossless GmbH",
|
"author": "Lossless GmbH",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(tstest test/)",
|
"test": "(tstest test/ --web)",
|
||||||
"build": "(tsbuild)",
|
"build": "(tsbuild --web)"
|
||||||
"format": "(gitzone format)"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.0.22",
|
"@gitzone/tsbuild": "^2.0.22",
|
||||||
|
14
test/test.ts
14
test/test.ts
@ -3,13 +3,23 @@ import * as sdk from '../ts/index';
|
|||||||
import { ISimpleRequest } from '@tsclass/tsclass/dist_ts/network';
|
import { ISimpleRequest } from '@tsclass/tsclass/dist_ts/network';
|
||||||
|
|
||||||
tap.test('should create a valid Handler', async () => {
|
tap.test('should create a valid Handler', async () => {
|
||||||
class MyHandler extends sdk.AAgHandler {
|
class MyHandler extends sdk.AAgHandler<any> {
|
||||||
slug: 'testapi';
|
slug: 'testapi';
|
||||||
public async handleRequest(request: ISimpleRequest) {
|
public async handleRequest(authInfo: sdk.AuthInfo<any>, request: ISimpleRequest) {
|
||||||
// this.authenticationHandler
|
// this.authenticationHandler
|
||||||
let response: any;
|
let response: any;
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
public async checkReqirements() {
|
||||||
|
return {
|
||||||
|
allOk: true,
|
||||||
|
reason: ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async start() {}
|
||||||
|
|
||||||
|
public async stop() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
const myHandlerInstance = new MyHandler();
|
const myHandlerInstance = new MyHandler();
|
||||||
|
@ -1 +1,2 @@
|
|||||||
export * from './sdk.classes.aghandler';
|
export * from './sdk.classes.aghandler';
|
||||||
|
export * from './sdk.classes.authinfo';
|
||||||
|
@ -1,16 +1,24 @@
|
|||||||
import * as plugins from './sdk.plugins';
|
import * as plugins from './sdk.plugins';
|
||||||
|
import { AuthInfo } from './sdk.classes.authinfo';
|
||||||
|
|
||||||
export abstract class AAgHandler {
|
export interface IRequirementResult {
|
||||||
public authenticationHandler: any;
|
allOk: boolean;
|
||||||
|
reason: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export abstract class AAgHandler<TClaim> {
|
||||||
/**
|
/**
|
||||||
* a slug that separates the handler from other handlers
|
* a slug that separates the handler from other handlers
|
||||||
*/
|
*/
|
||||||
public abstract slug: string;
|
public abstract slug: string;
|
||||||
|
|
||||||
public abstract handleRequest (request: plugins.tsclass.network.ISimpleRequest): Promise<plugins.tsclass.network.ISimpleResponse>;
|
|
||||||
|
|
||||||
public setAuthenticationHandler(authHandler) {
|
public abstract handleRequest (authInfoArg: AuthInfo<TClaim>, request: plugins.tsclass.network.ISimpleRequest): Promise<plugins.tsclass.network.ISimpleResponse>;
|
||||||
this.authenticationHandler = authHandler;
|
public abstract checkReqirements (): Promise<IRequirementResult>;
|
||||||
}
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
}
|
Reference in New Issue
Block a user