Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
ee99ddd23c | |||
b99a0548a2 | |||
1c678ced10 | |||
df1f6dff2e | |||
961dfc5693 | |||
6e761cb2b9 | |||
ef568f2aa2 | |||
fced92e1cc |
@ -19,23 +19,35 @@ mirror:
|
|||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci git mirror
|
- npmci git mirror
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- lossless
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- 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
|
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 --ignore-scripts
|
- 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 npm audit --audit-level=high --only=dev
|
||||||
tags:
|
tags:
|
||||||
- lossless
|
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
allow_failure: true
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# test stage
|
# test stage
|
||||||
@ -50,9 +62,7 @@ testStable:
|
|||||||
- 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
|
||||||
@ -63,9 +73,7 @@ testBuild:
|
|||||||
- npmci command npm run build
|
- npmci command npm run build
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- lossless
|
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
|
||||||
|
|
||||||
release:
|
release:
|
||||||
stage: release
|
stage: release
|
||||||
@ -85,6 +93,8 @@ 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 tslint typescript
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
|
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
@ -15,7 +15,7 @@
|
|||||||
"properties": {
|
"properties": {
|
||||||
"projectType": {
|
"projectType": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"enum": ["website", "element", "service", "npm"]
|
"enum": ["website", "element", "service", "npm", "wcc"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
8019
package-lock.json
generated
8019
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@apiglobal/sdk",
|
"name": "@apiglobal/sdk",
|
||||||
"version": "1.0.10",
|
"version": "1.0.14",
|
||||||
"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",
|
||||||
@ -21,6 +21,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@apiglobal/typedrequest": "^1.0.38",
|
"@apiglobal/typedrequest": "^1.0.38",
|
||||||
|
"@pushrocks/smartfile": "^8.0.0",
|
||||||
"@tsclass/tsclass": "^3.0.18"
|
"@tsclass/tsclass": "^3.0.18"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
@ -34,5 +35,8 @@
|
|||||||
"cli.js",
|
"cli.js",
|
||||||
"npmextra.json",
|
"npmextra.json",
|
||||||
"readme.md"
|
"readme.md"
|
||||||
|
],
|
||||||
|
"browserslist": [
|
||||||
|
"last 1 chrome versions"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
15
test/test.ts
15
test/test.ts
@ -3,11 +3,11 @@ import * as sdk from '../ts/index';
|
|||||||
import { ISimpleRequest } from '@tsclass/tsclass/dist_ts/network';
|
import { ISimpleRequest } from '@tsclass/tsclass/dist_ts/network';
|
||||||
import { TypedRouter } from '@apiglobal/typedrequest';
|
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> {
|
||||||
public slug: 'testapi';
|
public slug: 'testapi';
|
||||||
public typedrouter = new TypedRouter();
|
public typedrouter = new TypedRouter();
|
||||||
|
|
||||||
public async checkReqirements() {
|
public async checkReqirements() {
|
||||||
return {
|
return {
|
||||||
allOk: true,
|
allOk: true,
|
||||||
@ -22,12 +22,19 @@ tap.test('should create a valid Handler', async () => {
|
|||||||
public async checkRequirements(): Promise<sdk.IRequirementResult> {
|
public async checkRequirements(): Promise<sdk.IRequirementResult> {
|
||||||
return {
|
return {
|
||||||
allOk: true,
|
allOk: true,
|
||||||
reason: ''
|
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);
|
expect(myHandlerInstance).to.be.instanceOf(sdk.AAgHandler);
|
||||||
});
|
});
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
export * from './sdk.classes.agenvironment';
|
export * from './sdk.classes.agenvironment';
|
||||||
export * from './sdk.classes.aghandler';
|
export * from './sdk.classes.aghandler';
|
||||||
export * from './sdk.classes.authinfo';
|
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};
|
||||||
|
}
|
@ -3,6 +3,6 @@ import * as plugins from './sdk.plugins';
|
|||||||
/**
|
/**
|
||||||
* AgEnvironment handles the provision of environment variables to handlers
|
* AgEnvironment handles the provision of environment variables to handlers
|
||||||
*/
|
*/
|
||||||
export class AgEnvironment {
|
export abstract class AgEnvironment {
|
||||||
|
public abstract async getEnvVar(envVarName: string): Promise<string>;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import * as plugins from './sdk.plugins';
|
import * as plugins from './sdk.plugins';
|
||||||
import { AuthInfo } from './sdk.classes.authinfo';
|
import { AuthInfo } from './sdk.classes.authinfo';
|
||||||
|
import { AgEnvironment } from './sdk.classes.agenvironment';
|
||||||
|
|
||||||
export interface IRequirementResult {
|
export interface IRequirementResult {
|
||||||
allOk: boolean;
|
allOk: boolean;
|
||||||
@ -7,13 +8,39 @@ export interface IRequirementResult {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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 typedrouter: plugins.typedrequest.TypedRouter;
|
||||||
public abstract checkRequirements(): Promise<IRequirementResult>;
|
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
|
* start the ag-handler
|
||||||
*/
|
*/
|
||||||
|
@ -4,8 +4,13 @@ import * as path from 'path';
|
|||||||
// @apiglobal scope
|
// @apiglobal scope
|
||||||
import * as typedrequest from '@apiglobal/typedrequest';
|
import * as typedrequest from '@apiglobal/typedrequest';
|
||||||
|
|
||||||
|
export { typedrequest };
|
||||||
|
|
||||||
|
// pushrocks scope
|
||||||
|
import * as smartfile from '@pushrocks/smartfile';
|
||||||
|
|
||||||
export {
|
export {
|
||||||
typedrequest
|
smartfile
|
||||||
};
|
};
|
||||||
|
|
||||||
// @tsclass scope
|
// @tsclass scope
|
||||||
|
Reference in New Issue
Block a user