Compare commits
35 Commits
Author | SHA1 | Date | |
---|---|---|---|
cb7331e0b8 | |||
89bd481ce0 | |||
5ba6a8addb | |||
5a3ccf6f4f | |||
411516befc | |||
41c2aec293 | |||
8adbfd3118 | |||
d9e75a6a57 | |||
6ec0d9dc02 | |||
d5516f11f7 | |||
a9cf2bb4c3 | |||
ee99ddd23c | |||
b99a0548a2 | |||
1c678ced10 | |||
df1f6dff2e | |||
961dfc5693 | |||
6e761cb2b9 | |||
ef568f2aa2 | |||
fced92e1cc | |||
f73334d8fc | |||
d170af1db5 | |||
9e6b92f864 | |||
b094c07ef2 | |||
33584785df | |||
580f8dd7f7 | |||
c1d2231a94 | |||
d73a144e8f | |||
e91131b7ae | |||
4dd5d12a2e | |||
7fd110d56c | |||
bb7e9e75ba | |||
0b576c3170 | |||
df96f08038 | |||
e4ebd99c8f | |||
b42c700a28 |
@ -12,30 +12,38 @@ stages:
|
||||
- release
|
||||
- metadata
|
||||
|
||||
before_script:
|
||||
- pnpm install -g pnpm
|
||||
- pnpm install -g @shipzone/npmci
|
||||
- npmci npm prepare
|
||||
|
||||
# ====================
|
||||
# security stage
|
||||
# ====================
|
||||
mirror:
|
||||
stage: security
|
||||
script:
|
||||
- npmci git mirror
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
audit:
|
||||
# ====================
|
||||
# security stage
|
||||
# ====================
|
||||
auditProductionDependencies:
|
||||
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 pnpm audit --audit-level=high --prod
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
allow_failure: true
|
||||
|
||||
auditDevDependencies:
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
stage: security
|
||||
script:
|
||||
- npmci command npm config set registry https://registry.npmjs.org
|
||||
- npmci command pnpm audit --audit-level=high --dev
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
allow_failure: true
|
||||
|
||||
# ====================
|
||||
# test stage
|
||||
@ -44,28 +52,22 @@ audit:
|
||||
testStable:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- priv
|
||||
|
||||
testBuild:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci command npm run build
|
||||
- npmci npm build
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
release:
|
||||
stage: release
|
||||
@ -85,11 +87,12 @@ release:
|
||||
codequality:
|
||||
stage: metadata
|
||||
allow_failure: true
|
||||
only:
|
||||
- tags
|
||||
script:
|
||||
- npmci command npm install -g tslint typescript
|
||||
- npmci command npm install -g typescript
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
@ -109,11 +112,9 @@ trigger:
|
||||
pages:
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci node install lts
|
||||
- npmci command npm install -g @gitzone/tsdoc
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci command tsdoc
|
||||
- npmci command npm run buildDocs
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
|
24
.vscode/launch.json
vendored
24
.vscode/launch.json
vendored
@ -2,28 +2,10 @@
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "current file",
|
||||
"type": "node",
|
||||
"command": "npm test",
|
||||
"name": "Run npm test",
|
||||
"request": "launch",
|
||||
"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"
|
||||
"type": "node-terminal"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
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"]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@
|
||||
"githost": "gitlab.com",
|
||||
"gitscope": "apiglobal",
|
||||
"gitrepo": "sdk",
|
||||
"shortDescription": "an sdk package for api.global",
|
||||
"description": "an sdk package for api.global",
|
||||
"npmPackagename": "@apiglobal/sdk",
|
||||
"license": "MIT",
|
||||
"projectDomain": "api.global"
|
||||
|
1439
package-lock.json
generated
1439
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
29
package.json
29
package.json
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@apiglobal/sdk",
|
||||
"version": "1.0.2",
|
||||
"version": "2.0.1",
|
||||
"private": false,
|
||||
"description": "an sdk package for api.global",
|
||||
"main": "dist_ts/index.js",
|
||||
@ -8,20 +8,21 @@
|
||||
"author": "Lossless GmbH",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"test": "(tstest test/)",
|
||||
"build": "(tsbuild)",
|
||||
"format": "(gitzone format)"
|
||||
"test": "(tstest test/ --web)",
|
||||
"build": "(tsbuild --web)",
|
||||
"buildDocs": "tsdoc"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@gitzone/tsbuild": "^2.0.22",
|
||||
"@gitzone/tstest": "^1.0.15",
|
||||
"@pushrocks/tapbundle": "^3.0.7",
|
||||
"@types/node": "^10.11.7",
|
||||
"tslint": "^5.11.0",
|
||||
"tslint-config-prettier": "^1.15.0"
|
||||
"@gitzone/tsbuild": "^2.1.24",
|
||||
"@gitzone/tsrun": "^1.2.39",
|
||||
"@gitzone/tstest": "^1.0.33",
|
||||
"@pushrocks/tapbundle": "^5.0.4",
|
||||
"@types/node": "^18.15.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@tsclass/tsclass": "^3.0.13"
|
||||
"@apiglobal/typedrequest": "^2.0.12",
|
||||
"@pushrocks/smartfile": "^10.0.7",
|
||||
"@tsclass/tsclass": "^4.0.34"
|
||||
},
|
||||
"files": [
|
||||
"ts/**/*",
|
||||
@ -34,5 +35,9 @@
|
||||
"cli.js",
|
||||
"npmextra.json",
|
||||
"readme.md"
|
||||
]
|
||||
],
|
||||
"browserslist": [
|
||||
"last 1 chrome versions"
|
||||
],
|
||||
"type": "module"
|
||||
}
|
||||
|
4334
pnpm-lock.yaml
generated
Normal file
4334
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
25
readme.md
25
readme.md
@ -8,13 +8,19 @@ 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)
|
||||
|
||||
## Usage
|
||||
|
||||
@ -26,7 +32,6 @@ We are always happy for code contributions. If you are not the code contributing
|
||||
|
||||
For further information read the linked docs at the top of this readme.
|
||||
|
||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||
## Legal
|
||||
> MIT licensed | **©** [Task Venture Capital GmbH](https://task.vc)
|
||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
||||
|
||||
[](https://maintainedby.lossless.com)
|
||||
|
39
test/test.ts
39
test/test.ts
@ -1,8 +1,41 @@
|
||||
import { expect, tap } from '@pushrocks/tapbundle';
|
||||
import * as sdk from '../ts/index';
|
||||
import * as sdk from '../ts/index.js';
|
||||
import { TypedRouter } from '@apiglobal/typedrequest';
|
||||
|
||||
tap.test('first test', async () => {
|
||||
console.log(sdk.standardExport);
|
||||
tap.test('should create a valid Handler', async () => {
|
||||
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: '',
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// 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).toBeInstanceOf(sdk.AAgHandler);
|
||||
});
|
||||
|
||||
tap.start();
|
||||
|
8
ts/00_commitinfo_data.ts
Normal file
8
ts/00_commitinfo_data.ts
Normal file
@ -0,0 +1,8 @@
|
||||
/**
|
||||
* autocreated commitinfo by @pushrocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@apiglobal/sdk',
|
||||
version: '2.0.1',
|
||||
description: 'an sdk package for api.global'
|
||||
}
|
@ -1,3 +1,5 @@
|
||||
import * as plugins from './sdk.plugins';
|
||||
export * from './sdk.classes.agenvironment.js';
|
||||
export * from './sdk.classes.aghandler.js';
|
||||
export * from './sdk.classes.authinfo.js';
|
||||
|
||||
export let standardExport = 'Hi there! :) This is an exported string';
|
||||
export * from './interfaces/index.js';
|
||||
|
1
ts/interfaces/index.ts
Normal file
1
ts/interfaces/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './projectsettings.js';
|
21
ts/interfaces/projectsettings.ts
Normal file
21
ts/interfaces/projectsettings.ts
Normal file
@ -0,0 +1,21 @@
|
||||
export interface IHandlerSettings {
|
||||
/**
|
||||
* the slug is a globally unique slug that the package will be answer under
|
||||
*/
|
||||
slug: string;
|
||||
/**
|
||||
* the packagename points to the package to use in the supplied registry
|
||||
*/
|
||||
packageName: string;
|
||||
/**
|
||||
* environment variables are supplied to the service at runtime
|
||||
*/
|
||||
environmentVariables: { [key: string]: string };
|
||||
/**
|
||||
* this is needed to know where to get the package to run
|
||||
*/
|
||||
registryDescriptor: {
|
||||
registryUrl: string;
|
||||
registryToken: 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.js';
|
||||
|
||||
/**
|
||||
* AgEnvironment handles the provision of environment variables to handlers
|
||||
*/
|
||||
export abstract class AgEnvironment {
|
||||
public abstract getEnvVar(envVarName: string): Promise<string>;
|
||||
}
|
53
ts/sdk.classes.aghandler.ts
Normal file
53
ts/sdk.classes.aghandler.ts
Normal file
@ -0,0 +1,53 @@
|
||||
import * as plugins from './sdk.plugins.js';
|
||||
import { AuthInfo } from './sdk.classes.authinfo.js';
|
||||
import { AgEnvironment } from './sdk.classes.agenvironment.js';
|
||||
|
||||
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 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>;
|
||||
}
|
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.js';
|
||||
|
||||
/**
|
||||
* 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,16 @@
|
||||
// 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';
|
||||
|
||||
|
10
tsconfig.json
Normal file
10
tsconfig.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"experimentalDecorators": true,
|
||||
"useDefineForClassFields": false,
|
||||
"target": "ES2022",
|
||||
"module": "ES2022",
|
||||
"moduleResolution": "nodenext",
|
||||
"esModuleInterop": true
|
||||
}
|
||||
}
|
17
tslint.json
17
tslint.json
@ -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