Compare commits
16 Commits
Author | SHA1 | Date | |
---|---|---|---|
7e4f16a4df | |||
cb7331e0b8 | |||
89bd481ce0 | |||
5ba6a8addb | |||
5a3ccf6f4f | |||
411516befc | |||
41c2aec293 | |||
8adbfd3118 | |||
d9e75a6a57 | |||
6ec0d9dc02 | |||
d5516f11f7 | |||
a9cf2bb4c3 | |||
ee99ddd23c | |||
b99a0548a2 | |||
1c678ced10 | |||
df1f6dff2e |
@ -12,40 +12,36 @@ stages:
|
|||||||
- release
|
- release
|
||||||
- metadata
|
- metadata
|
||||||
|
|
||||||
|
before_script:
|
||||||
|
- pnpm install -g pnpm
|
||||||
|
- pnpm install -g @shipzone/npmci
|
||||||
|
- npmci npm prepare
|
||||||
|
|
||||||
|
# ====================
|
||||||
|
# security stage
|
||||||
|
# ====================
|
||||||
# ====================
|
# ====================
|
||||||
# security stage
|
# security stage
|
||||||
# ====================
|
# ====================
|
||||||
mirror:
|
|
||||||
stage: security
|
|
||||||
script:
|
|
||||||
- npmci git mirror
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
tags:
|
|
||||||
- lossless
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
auditProductionDependencies:
|
auditProductionDependencies:
|
||||||
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 config set registry https://registry.npmjs.org
|
||||||
- npmci command npm install --production --ignore-scripts
|
- npmci command pnpm audit --audit-level=high --prod
|
||||||
- npmci command npm config set registry https://registry.npmjs.org
|
|
||||||
- npmci command npm audit --audit-level=high --only=prod --production
|
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
|
allow_failure: true
|
||||||
|
|
||||||
auditDevDependencies:
|
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 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 --only=dev
|
- npmci command pnpm audit --audit-level=high --dev
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
|
|
||||||
@ -56,7 +52,6 @@ auditDevDependencies:
|
|||||||
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
|
||||||
@ -67,10 +62,9 @@ testStable:
|
|||||||
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:
|
||||||
- docker
|
- docker
|
||||||
@ -96,10 +90,9 @@ codequality:
|
|||||||
only:
|
only:
|
||||||
- tags
|
- 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
|
||||||
@ -119,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
24
.vscode/launch.json
vendored
@ -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"
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -2,17 +2,37 @@
|
|||||||
"gitzone": {
|
"gitzone": {
|
||||||
"projectType": "npm",
|
"projectType": "npm",
|
||||||
"module": {
|
"module": {
|
||||||
"githost": "gitlab.com",
|
"githost": "code.foss.global",
|
||||||
"gitscope": "apiglobal",
|
"gitscope": "api.global",
|
||||||
"gitrepo": "sdk",
|
"gitrepo": "sdk",
|
||||||
"shortDescription": "an sdk package for api.global",
|
"description": "A software development kit for interacting with api.global services.",
|
||||||
"npmPackagename": "@apiglobal/sdk",
|
"npmPackagename": "@api.global/sdk",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"projectDomain": "api.global"
|
"projectDomain": "api.global",
|
||||||
|
"keywords": [
|
||||||
|
"SDK",
|
||||||
|
"api.global",
|
||||||
|
"TypeScript",
|
||||||
|
"authentication",
|
||||||
|
"HTTP requests",
|
||||||
|
"environment variables",
|
||||||
|
"typed requests",
|
||||||
|
"open source",
|
||||||
|
"code contributions",
|
||||||
|
"npm package",
|
||||||
|
"API development",
|
||||||
|
"handlers",
|
||||||
|
"modular design",
|
||||||
|
"code quality",
|
||||||
|
"software development kit"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"npmci": {
|
"npmci": {
|
||||||
"npmGlobalTools": [],
|
"npmGlobalTools": [],
|
||||||
"npmAccessLevel": "public"
|
"npmAccessLevel": "public"
|
||||||
|
},
|
||||||
|
"tsdoc": {
|
||||||
|
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
|
||||||
}
|
}
|
||||||
}
|
}
|
11197
package-lock.json
generated
11197
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
41
package.json
41
package.json
@ -1,27 +1,28 @@
|
|||||||
{
|
{
|
||||||
"name": "@apiglobal/sdk",
|
"name": "@api.global/sdk",
|
||||||
"version": "1.0.12",
|
"version": "2.0.1",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "an sdk package for api.global",
|
"description": "A software development kit for interacting with api.global services.",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
"typings": "dist_ts/index.d.ts",
|
"typings": "dist_ts/index.d.ts",
|
||||||
"author": "Lossless GmbH",
|
"author": "Lossless GmbH",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(tstest test/ --web)",
|
"test": "(tstest test/ --web)",
|
||||||
"build": "(tsbuild --web)"
|
"build": "(tsbuild --web)",
|
||||||
|
"buildDocs": "tsdoc"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.24",
|
"@gitzone/tsbuild": "^2.1.24",
|
||||||
|
"@gitzone/tsrun": "^1.2.39",
|
||||||
"@gitzone/tstest": "^1.0.33",
|
"@gitzone/tstest": "^1.0.33",
|
||||||
"@pushrocks/tapbundle": "^3.0.7",
|
"@pushrocks/tapbundle": "^5.0.4",
|
||||||
"@types/node": "^14.0.14",
|
"@types/node": "^18.15.3"
|
||||||
"tslint": "^6.1.2",
|
|
||||||
"tslint-config-prettier": "^1.15.0"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@apiglobal/typedrequest": "^1.0.38",
|
"@apiglobal/typedrequest": "^2.0.12",
|
||||||
"@tsclass/tsclass": "^3.0.18"
|
"@pushrocks/smartfile": "^10.0.7",
|
||||||
|
"@tsclass/tsclass": "^4.0.34"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"ts/**/*",
|
"ts/**/*",
|
||||||
@ -37,5 +38,23 @@
|
|||||||
],
|
],
|
||||||
"browserslist": [
|
"browserslist": [
|
||||||
"last 1 chrome versions"
|
"last 1 chrome versions"
|
||||||
|
],
|
||||||
|
"type": "module",
|
||||||
|
"keywords": [
|
||||||
|
"SDK",
|
||||||
|
"api.global",
|
||||||
|
"TypeScript",
|
||||||
|
"authentication",
|
||||||
|
"HTTP requests",
|
||||||
|
"environment variables",
|
||||||
|
"typed requests",
|
||||||
|
"open source",
|
||||||
|
"code contributions",
|
||||||
|
"npm package",
|
||||||
|
"API development",
|
||||||
|
"handlers",
|
||||||
|
"modular design",
|
||||||
|
"code quality",
|
||||||
|
"software development kit"
|
||||||
]
|
]
|
||||||
}
|
}
|
4334
pnpm-lock.yaml
generated
Normal file
4334
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
1
readme.hints.md
Normal file
1
readme.hints.md
Normal file
@ -0,0 +1 @@
|
|||||||
|
|
178
readme.md
178
readme.md
@ -1,39 +1,163 @@
|
|||||||
# @apiglobal/sdk
|
# @api.global/sdk
|
||||||
|
|
||||||
an sdk package for api.global
|
an sdk package for api.global
|
||||||
|
|
||||||
## Availabililty and Links
|
## Install
|
||||||
* [npmjs.org (npm package)](https://www.npmjs.com/package/@apiglobal/sdk)
|
|
||||||
* [gitlab.com (source)](https://gitlab.com/apiglobal/sdk)
|
|
||||||
* [github.com (source mirror)](https://github.com/apiglobal/sdk)
|
|
||||||
* [docs (typedoc)](https://apiglobal.gitlab.io/sdk/)
|
|
||||||
|
|
||||||
## Status for master
|
To install `@api.global/sdk`, you need to have Node.js installed on your machine. This package is available through the npm registry. Installation can be done using the npm or yarn command line tools.
|
||||||
|
|
||||||
Status Category | Status Badge
|
```bash
|
||||||
-- | --
|
npm install @api.global/sdk --save
|
||||||
GitLab Pipelines | [](https://lossless.cloud)
|
```
|
||||||
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
|
||||||
npm | [](https://lossless.cloud)
|
or
|
||||||
Snyk | [](https://lossless.cloud)
|
|
||||||
TypeScript Support | [](https://lossless.cloud)
|
```bash
|
||||||
node Support | [](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
yarn add @api.global/sdk
|
||||||
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
|
## Usage
|
||||||
|
|
||||||
Use TypeScript for best in class intellisense
|
Using `@api.global/sdk` requires an understanding of TypeScript and asynchronous programming concepts in Node.js. Below, we will outline a series of use cases to demonstrate how to utilize the SDK effectively in your projects.
|
||||||
|
|
||||||
## Contribution
|
### Setting Up Your Project
|
||||||
|
|
||||||
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
|
Before proceeding with the usage examples, ensure your TypeScript configuration (`tsconfig.json`) is correctly set up for an ES Module syntax project.
|
||||||
|
|
||||||
For further information read the linked docs at the top of this readme.
|
### Importing the SDK
|
||||||
|
|
||||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
Once installed, you can import the entire SDK or specific parts of it into your project files:
|
||||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
|
||||||
|
|
||||||
[](https://maintainedby.lossless.com)
|
```typescript
|
||||||
|
import * as ApiGlobalSdk from '@api.global/sdk';
|
||||||
|
```
|
||||||
|
|
||||||
|
Or import specific classes if you're only interested in a subset of functionalities:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import { AAgHandler, AgEnvironment, AuthInfo } from '@api.global/sdk';
|
||||||
|
```
|
||||||
|
|
||||||
|
### Creating an Environment Handler
|
||||||
|
|
||||||
|
`AgEnvironment` is an abstract class that manages the provision of environment variables. A concrete implementation could look like this:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import { AgEnvironment } from '@api.global/sdk';
|
||||||
|
|
||||||
|
class MyEnvironment extends AgEnvironment {
|
||||||
|
private envVariables: Map<string, string> = new Map([
|
||||||
|
['API_KEY', 'your-api-key-here'],
|
||||||
|
// Add other environment variables
|
||||||
|
]);
|
||||||
|
|
||||||
|
public async getEnvVar(envVarName: string): Promise<string> {
|
||||||
|
return this.envVariables.get(envVarName) || '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const myEnvironment = new MyEnvironment();
|
||||||
|
```
|
||||||
|
|
||||||
|
### Implementing an Authorization Handler
|
||||||
|
|
||||||
|
The SDK requires implementing an authorization handler by extending the `AuthInfo` class. This class manages authentication and potential security flags for incoming requests.
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import { AuthInfo } from '@api.global/sdk';
|
||||||
|
|
||||||
|
class MyAuthInfo extends AuthInfo<any> {
|
||||||
|
public authenticated: boolean = false;
|
||||||
|
public potentiallyMalicious: boolean = false;
|
||||||
|
public claim: any;
|
||||||
|
|
||||||
|
constructor(claim: any) {
|
||||||
|
super();
|
||||||
|
this.claim = claim;
|
||||||
|
// Implement logic to set 'authenticated' and 'potentiallyMalicious'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Creating an API Handler
|
||||||
|
|
||||||
|
Create an API handler by extending `AAgHandler`. This handler will manage API requests and connect them to your business logic.
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import { AAgHandler, IRequirementResult } from '@api.global/sdk';
|
||||||
|
import { TypedRouter } from '@apiglobal/typedrequest';
|
||||||
|
|
||||||
|
class MyApiHandler extends AAgHandler<any> {
|
||||||
|
public slug: string = 'myApi';
|
||||||
|
public typedrouter: TypedRouter = new TypedRouter();
|
||||||
|
|
||||||
|
public async checkRequirements(): Promise<IRequirementResult> {
|
||||||
|
// Implement checks for your requirements here
|
||||||
|
return { allOk: true, reason: '' };
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor(agEnvironment: AgEnvironment) {
|
||||||
|
super(agEnvironment);
|
||||||
|
// Additional constructor logic
|
||||||
|
}
|
||||||
|
|
||||||
|
public async start(): Promise<void> {
|
||||||
|
// Implement starting logic here
|
||||||
|
}
|
||||||
|
|
||||||
|
public async stop(): Promise<void> {
|
||||||
|
// Implement stopping logic here
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Usage
|
||||||
|
const myApiHandler = new MyApiHandler(myEnvironment);
|
||||||
|
```
|
||||||
|
|
||||||
|
### Starting Your API Handler
|
||||||
|
|
||||||
|
Finally, start your API handler as part of your application's boot-up sequence.
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
async function startApplication() {
|
||||||
|
try {
|
||||||
|
await myApiHandler.start();
|
||||||
|
console.log('API handler started successfully.');
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to start API handler:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
startApplication();
|
||||||
|
```
|
||||||
|
|
||||||
|
### Advanced Use Cases
|
||||||
|
|
||||||
|
- **Custom AuthInfo Implementations**: Depending on your application's authentication mechanism (e.g., OAuth2, JWT), you may need to create more sophisticated `AuthInfo` implementations.
|
||||||
|
- **Feature Flags and Environment Variables**: Use `AgEnvironment` to manage feature flags or other configuration that might change between different environments.
|
||||||
|
- **TypedRequest Integrations**: Leverage the `TypedRouter` from `@apiglobal/typedrequest` to create strongly typed endpoints and request handlers within your `AAgHandler` implementation.
|
||||||
|
|
||||||
|
### Conclusion
|
||||||
|
|
||||||
|
The `@api.global/sdk` offers powerful abstractions to create well-structured, environment-aware, and secure API handlers for Node.js applications. By extending its base classes and implementing the required methods, you can quickly build scalable and maintainable backend services.
|
||||||
|
|
||||||
|
Remember, the key to effectively using `@api.global/sdk` is understanding its core concepts and how they fit into your application's architecture. With this knowledge, you can extend the SDK to meet your specific needs, ensuring a robust and flexible API layer.
|
||||||
|
|
||||||
|
## License and Legal Information
|
||||||
|
|
||||||
|
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
|
||||||
|
|
||||||
|
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
|
### Trademarks
|
||||||
|
|
||||||
|
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.
|
||||||
|
|
||||||
|
### Company Information
|
||||||
|
|
||||||
|
Task Venture Capital GmbH
|
||||||
|
Registered at District court Bremen HRB 35230 HB, Germany
|
||||||
|
|
||||||
|
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
|
||||||
|
|
||||||
|
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
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';
|
import { TypedRouter } from '@apiglobal/typedrequest';
|
||||||
|
|
||||||
tap.test('should create a valid Handler', async () => {
|
tap.test('should create a valid Handler', async () => {
|
||||||
@ -36,7 +35,7 @@ tap.test('should create a valid Handler', async () => {
|
|||||||
|
|
||||||
const myHandlerInstance = new MyHandler(new AgEnvironement());
|
const myHandlerInstance = new MyHandler(new AgEnvironement());
|
||||||
|
|
||||||
expect(myHandlerInstance).to.be.instanceOf(sdk.AAgHandler);
|
expect(myHandlerInstance).toBeInstanceOf(sdk.AAgHandler);
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.start();
|
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 @@
|
|||||||
export * from './sdk.classes.agenvironment';
|
export * from './sdk.classes.agenvironment.js';
|
||||||
export * from './sdk.classes.aghandler';
|
export * from './sdk.classes.aghandler.js';
|
||||||
export * from './sdk.classes.authinfo';
|
export * from './sdk.classes.authinfo.js';
|
||||||
|
|
||||||
|
export * from './interfaces/index.js';
|
||||||
|
@ -1 +1 @@
|
|||||||
export {};
|
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;
|
||||||
|
};
|
||||||
|
}
|
@ -1,8 +1,8 @@
|
|||||||
import * as plugins from './sdk.plugins';
|
import * as plugins from './sdk.plugins.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AgEnvironment handles the provision of environment variables to handlers
|
* AgEnvironment handles the provision of environment variables to handlers
|
||||||
*/
|
*/
|
||||||
export abstract class AgEnvironment {
|
export abstract class AgEnvironment {
|
||||||
public abstract async getEnvVar(envVarName: string): Promise<string>;
|
public abstract getEnvVar(envVarName: string): Promise<string>;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
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';
|
import { AgEnvironment } from './sdk.classes.agenvironment.js';
|
||||||
|
|
||||||
export interface IRequirementResult {
|
export interface IRequirementResult {
|
||||||
allOk: boolean;
|
allOk: boolean;
|
||||||
@ -17,6 +17,30 @@ export abstract class AAgHandler<TClaim> {
|
|||||||
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) {
|
constructor(agEnvironmentArg: AgEnvironment) {
|
||||||
this.agEnvironment = agEnvironmentArg;
|
this.agEnvironment = agEnvironmentArg;
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
|
@ -6,6 +6,11 @@ import * as typedrequest from '@apiglobal/typedrequest';
|
|||||||
|
|
||||||
export { 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';
|
||||||
|
|
||||||
|
14
tsconfig.json
Normal file
14
tsconfig.json
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"experimentalDecorators": true,
|
||||||
|
"useDefineForClassFields": false,
|
||||||
|
"target": "ES2022",
|
||||||
|
"module": "NodeNext",
|
||||||
|
"moduleResolution": "NodeNext",
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"verbatimModuleSyntax": true
|
||||||
|
},
|
||||||
|
"exclude": [
|
||||||
|
"dist_*/**/*.d.ts"
|
||||||
|
]
|
||||||
|
}
|
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"
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user