31 Commits

Author SHA1 Message Date
cb7331e0b8 2.0.1 2023-03-20 14:14:35 +01:00
89bd481ce0 fix(core): update 2023-03-20 14:14:35 +01:00
5ba6a8addb 2.0.0 2023-03-20 12:26:44 +01:00
5a3ccf6f4f BREAKING CHANGE(switch to esm): update 2023-03-20 12:26:43 +01:00
411516befc 1.0.18 2020-10-19 16:52:38 +00:00
41c2aec293 fix(core): update 2020-10-19 16:52:37 +00:00
8adbfd3118 1.0.17 2020-09-26 12:33:48 +00:00
d9e75a6a57 fix(core): update 2020-09-26 12:33:48 +00:00
6ec0d9dc02 1.0.16 2020-09-26 12:33:24 +00:00
d5516f11f7 1.0.15 2020-09-26 12:31:09 +00:00
a9cf2bb4c3 fix(core): update 2020-09-26 12:31:08 +00:00
ee99ddd23c 1.0.14 2020-09-26 11:57:27 +00:00
b99a0548a2 fix(core): update 2020-09-26 11:57:26 +00:00
1c678ced10 1.0.13 2020-09-23 22:34:43 +00:00
df1f6dff2e fix(core): update 2020-09-23 22:34:42 +00:00
961dfc5693 1.0.12 2020-09-23 21:24:32 +00:00
6e761cb2b9 fix(core): update 2020-09-23 21:24:32 +00:00
ef568f2aa2 1.0.11 2020-09-22 23:06:35 +00:00
fced92e1cc fix(core): update 2020-09-22 23:06:34 +00:00
f73334d8fc 1.0.10 2020-09-22 22:54:06 +00:00
d170af1db5 fix(core): update 2020-09-22 22:54:05 +00:00
9e6b92f864 1.0.9 2020-07-05 15:16:51 +00:00
b094c07ef2 fix(core): update 2020-07-05 15:16:50 +00:00
33584785df 1.0.8 2020-07-04 16:42:42 +00:00
580f8dd7f7 fix(core): update 2020-07-04 16:42:41 +00:00
c1d2231a94 1.0.7 2020-07-04 14:50:25 +00:00
d73a144e8f fix(core): update 2020-07-04 14:50:24 +00:00
e91131b7ae 1.0.6 2020-07-04 14:38:26 +00:00
4dd5d12a2e fix(core): update 2020-07-04 14:38:25 +00:00
7fd110d56c 1.0.5 2020-03-26 21:45:03 +00:00
bb7e9e75ba fix(fix(AAgHandler): now has mandatory async start and async stop methods): update 2020-03-26 21:45:03 +00:00
19 changed files with 4540 additions and 1538 deletions

View File

@ -12,30 +12,38 @@ stages:
- release - release
- metadata - metadata
before_script:
- pnpm install -g pnpm
- pnpm install -g @shipzone/npmci
- npmci npm prepare
# ==================== # ====================
# security stage # security stage
# ==================== # ====================
mirror: # ====================
stage: security # security stage
script: # ====================
- npmci git mirror auditProductionDependencies:
tags:
- lossless
- docker
- notpriv
audit:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security stage: security
script: script:
- npmci npm prepare
- npmci command npm install --ignore-scripts
- npmci command npm config set registry https://registry.npmjs.org - 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: tags:
- lossless - lossless
- docker - 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 # test stage
@ -44,28 +52,22 @@ audit:
testStable: testStable:
stage: test stage: test
script: script:
- npmci npm prepare
- npmci node install stable - npmci node install stable
- npmci npm install - npmci npm install
- npmci npm test - npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/ coverage: /\d+.?\d+?\%\s*coverage/
tags: tags:
- lossless
- docker - docker
- priv
testBuild: testBuild:
stage: test stage: test
script: script:
- npmci npm prepare
- npmci node install stable - npmci node install stable
- npmci npm install - npmci npm install
- npmci command npm run build - npmci npm build
coverage: /\d+.?\d+?\%\s*coverage/ coverage: /\d+.?\d+?\%\s*coverage/
tags: tags:
- lossless
- docker - docker
- notpriv
release: release:
stage: release stage: release
@ -85,11 +87,12 @@ 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 prepare
- npmci npm install - npmci npm install
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
tags: tags:
- lossless - lossless
- docker - docker
@ -109,11 +112,9 @@ trigger:
pages: pages:
stage: metadata stage: metadata
script: script:
- npmci node install lts - npmci node install stable
- npmci command npm install -g @gitzone/tsdoc
- npmci npm prepare
- npmci npm install - npmci npm install
- npmci command tsdoc - npmci command npm run buildDocs
tags: tags:
- lossless - lossless
- docker - docker

24
.vscode/launch.json vendored
View File

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

View File

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

View File

@ -5,7 +5,7 @@
"githost": "gitlab.com", "githost": "gitlab.com",
"gitscope": "apiglobal", "gitscope": "apiglobal",
"gitrepo": "sdk", "gitrepo": "sdk",
"shortDescription": "an sdk package for api.global", "description": "an sdk package for api.global",
"npmPackagename": "@apiglobal/sdk", "npmPackagename": "@apiglobal/sdk",
"license": "MIT", "license": "MIT",
"projectDomain": "api.global" "projectDomain": "api.global"

1430
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{ {
"name": "@apiglobal/sdk", "name": "@apiglobal/sdk",
"version": "1.0.4", "version": "2.0.1",
"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,21 +8,21 @@
"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)" "buildDocs": "tsdoc"
}, },
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.0.22", "@gitzone/tsbuild": "^2.1.24",
"@gitzone/tstest": "^1.0.15", "@gitzone/tsrun": "^1.2.39",
"@pushrocks/tapbundle": "^3.0.7", "@gitzone/tstest": "^1.0.33",
"@types/node": "^13.9.3", "@pushrocks/tapbundle": "^5.0.4",
"tslint": "^6.1.0", "@types/node": "^18.15.3"
"tslint-config-prettier": "^1.15.0"
}, },
"dependencies": { "dependencies": {
"@apiglobal/typedrequest": "^1.0.28", "@apiglobal/typedrequest": "^2.0.12",
"@tsclass/tsclass": "^3.0.16" "@pushrocks/smartfile": "^10.0.7",
"@tsclass/tsclass": "^4.0.34"
}, },
"files": [ "files": [
"ts/**/*", "ts/**/*",
@ -35,5 +35,9 @@
"cli.js", "cli.js",
"npmextra.json", "npmextra.json",
"readme.md" "readme.md"
] ],
"browserslist": [
"last 1 chrome versions"
],
"type": "module"
} }

4334
pnpm-lock.yaml generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -8,13 +8,19 @@ an sdk package for api.global
* [docs (typedoc)](https://apiglobal.gitlab.io/sdk/) * [docs (typedoc)](https://apiglobal.gitlab.io/sdk/)
## Status for master ## Status for master
[![pipeline status](https://gitlab.com/apiglobal/sdk/badges/master/pipeline.svg)](https://gitlab.com/apiglobal/sdk/commits/master)
[![coverage report](https://gitlab.com/apiglobal/sdk/badges/master/coverage.svg)](https://gitlab.com/apiglobal/sdk/commits/master) Status Category | Status Badge
[![npm downloads per month](https://img.shields.io/npm/dm/@apiglobal/sdk.svg)](https://www.npmjs.com/package/@apiglobal/sdk) -- | --
[![Known Vulnerabilities](https://snyk.io/test/npm/@apiglobal/sdk/badge.svg)](https://snyk.io/test/npm/@apiglobal/sdk) GitLab Pipelines | [![pipeline status](https://gitlab.com/apiglobal/sdk/badges/master/pipeline.svg)](https://lossless.cloud)
[![TypeScript](https://img.shields.io/badge/TypeScript->=%203.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/) GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/apiglobal/sdk/badges/master/coverage.svg)](https://lossless.cloud)
[![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/) npm | [![npm downloads per month](https://badgen.net/npm/dy/@apiglobal/sdk)](https://lossless.cloud)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-prettier-ff69b4.svg)](https://prettier.io/) Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/apiglobal/sdk)](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/@apiglobal/sdk)](https://lossless.cloud)
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@apiglobal/sdk)](https://lossless.cloud)
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@apiglobal/sdk)](https://lossless.cloud)
## Usage ## 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. 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) | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
[![repo-footer](https://lossless.gitlab.io/publicrelations/repofooter.svg)](https://maintainedby.lossless.com)

View File

@ -1,20 +1,41 @@
import { expect, tap } from '@pushrocks/tapbundle'; import { expect, tap } from '@pushrocks/tapbundle';
import * as sdk from '../ts/index'; import * as sdk from '../ts/index.js';
import { ISimpleRequest } from '@tsclass/tsclass/dist_ts/network'; import { TypedRouter } from '@apiglobal/typedrequest';
tap.test('should create a valid Handler', async () => { tap.test('should create a valid Handler', async () => {
class MyHandler extends sdk.AAgHandler<any> { class MyHandler extends sdk.AAgHandler<any> {
slug: 'testapi'; public slug: 'testapi';
public async handleRequest(authInfo: sdk.AuthInfo<any>, request: ISimpleRequest) { public typedrouter = new TypedRouter();
// this.authenticationHandler
let response: any; public async checkReqirements() {
return response; 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 '';
}
}
expect(myHandlerInstance).to.be.instanceOf(sdk.AAgHandler); const myHandlerInstance = new MyHandler(new AgEnvironement());
expect(myHandlerInstance).toBeInstanceOf(sdk.AAgHandler);
}); });
tap.start(); tap.start();

8
ts/00_commitinfo_data.ts Normal file
View 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'
}

View File

@ -1,2 +1,5 @@
export * from './sdk.classes.aghandler'; export * from './sdk.classes.agenvironment.js';
export * from './sdk.classes.authinfo'; export * from './sdk.classes.aghandler.js';
export * from './sdk.classes.authinfo.js';
export * from './interfaces/index.js';

View File

@ -1 +1 @@
export {}; export * from './projectsettings.js';

View 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;
};
}

View 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>;
}

View File

@ -1,11 +1,53 @@
import * as plugins from './sdk.plugins'; import * as plugins from './sdk.plugins.js';
import { AuthInfo } from './sdk.classes.authinfo'; 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> { export abstract class AAgHandler<TClaim> {
public agEnvironment: AgEnvironment;
/** /**
* 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 typedrouter: plugins.typedrequest.TypedRouter;
public abstract checkRequirements(): Promise<IRequirementResult>;
public abstract handleRequest (authInfoArg: AuthInfo<TClaim>, request: plugins.tsclass.network.ISimpleRequest): Promise<plugins.tsclass.network.ISimpleResponse>; 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>;
} }

View File

@ -1,4 +1,4 @@
import * as plugins from './sdk.plugins'; import * as plugins from './sdk.plugins.js';
/** /**
* AuthInfo is created for every single incoming request * AuthInfo is created for every single incoming request

View File

@ -1,6 +1,16 @@
// node native scope // node native scope
import * as path from 'path'; 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 // @tsclass scope
import * as tsclass from '@tsclass/tsclass'; import * as tsclass from '@tsclass/tsclass';

10
tsconfig.json Normal file
View File

@ -0,0 +1,10 @@
{
"compilerOptions": {
"experimentalDecorators": true,
"useDefineForClassFields": false,
"target": "ES2022",
"module": "ES2022",
"moduleResolution": "nodenext",
"esModuleInterop": true
}
}

View File

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