-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): provide a lightweight and simple way to configure SDK (#1)
closes #4
- Loading branch information
1 parent
389af93
commit 5aed5cf
Showing
27 changed files
with
798 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"presets": [["@nrwl/web/babel", { "useBuiltIns": "usage" }]] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"extends": ["../../.eslintrc.json"], | ||
"ignorePatterns": ["!**/*"], | ||
"overrides": [ | ||
{ | ||
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"], | ||
"parserOptions": { | ||
"project": ["packages/core/tsconfig.*?.json"] | ||
}, | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.ts", "*.tsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.js", "*.jsx"], | ||
"rules": {} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
# @secbox/core | ||
|
||
The core package can be used to obtain a config including credentials from different sources, and provide a simplified abstraction to handle events and commands. | ||
|
||
## Setup | ||
|
||
```bash | ||
npm i -s @secbox/core | ||
``` | ||
|
||
## Usage | ||
|
||
### Configuration | ||
|
||
First, you need to generate a new instance of `Configuration`. | ||
|
||
```ts | ||
import { Configuration } from '@secbox/core'; | ||
|
||
const config = new Configuration({ | ||
cluster: 'app.neuralegion.com', | ||
credentials: { | ||
token: 'your API key' | ||
} | ||
}); | ||
``` | ||
|
||
After that, you can resolve the configuration using the IoC container. | ||
|
||
```ts | ||
const config = config.container.resolve(Configuration); | ||
``` | ||
|
||
#### Options | ||
|
||
Configuration can be customized using the following options: | ||
|
||
```ts | ||
export interface ConfigurationOptions { | ||
cluster: string; | ||
credentials?: Credentials; | ||
credentialProviders?: CredentialProvider[]; | ||
} | ||
``` | ||
|
||
The default configuration is as follows: | ||
|
||
```js | ||
{ | ||
credentialProviders: [new EnvCredentialProvider()]; | ||
} | ||
``` | ||
|
||
#### cluster | ||
|
||
- type: `string` | ||
|
||
Set the application name (domain name), that is used to establish connection with. By default, the option is equal to `app.neuralegion.com`. | ||
|
||
```ts | ||
import { Configuration } from '@secbox/core'; | ||
|
||
const config = new Configuration({ | ||
cluster: 'app.neuralegion.com' | ||
}); | ||
``` | ||
|
||
#### credentials | ||
|
||
- type: `Credentials` | ||
|
||
Set credentials to access the application. | ||
|
||
```ts | ||
import { Configuration } from '@secbox/core'; | ||
|
||
const config = new Configuration({ | ||
credentials: { | ||
token: 'your API key' | ||
} | ||
}); | ||
``` | ||
|
||
More info about [setting up an API key](https://docs.neuralegion.com/docs/manage-your-organization#manage-organization-apicli-authentication-tokens) | ||
|
||
#### credentialProviders | ||
|
||
- type: `CredentialProvider[]` | ||
|
||
Allows you to provide credentials and load it in runtime. The configuration will invoke one provider at a time and only continue to the next if no credentials have been located. For example, if the process finds values defined via the `BRIGHT_TOKEN` environment variables, the file at `.secboxrc` will not be read. | ||
|
||
#### EnvCredentialProvider | ||
|
||
Use this provider to read credentials from the following environment variable: `BRIGHT_TOKEN` | ||
|
||
If the `BRIGHT_TOKEN` environment variable is not set or contains a falsy value, it will return undefined. | ||
|
||
```ts | ||
import { Configuration, EnvCredentialProvider } from '@secbox/core'; | ||
|
||
const credentialsProvider = new EnvCredentialProvider(); | ||
const config = new Configuration({ | ||
credentialProviders: [credentialsProvider] | ||
}); | ||
``` | ||
|
||
## License | ||
|
||
Copyright © 2022 [NeuraLegion](https://github.com/NeuraLegion). | ||
|
||
This project is licensed under the MIT License - see the [LICENSE file](LICENSE) for details. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module.exports = { | ||
displayName: 'core', | ||
preset: '../../jest.preset.js', | ||
globals: { | ||
'ts-jest': { | ||
tsconfig: '<rootDir>/tsconfig.spec.json' | ||
} | ||
}, | ||
testEnvironment: 'node', | ||
transform: { | ||
'^.+\\.[tj]sx?$': 'ts-jest' | ||
}, | ||
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'], | ||
coverageDirectory: '../../coverage/packages/core' | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "@secbox/core", | ||
"version": "0.0.1" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{ | ||
"root": "packages/core", | ||
"sourceRoot": "packages/core/src", | ||
"projectType": "library", | ||
"targets": { | ||
"build": { | ||
"executor": "@nrwl/js:tsc", | ||
"outputs": ["{options.outputPath}"], | ||
"options": { | ||
"outputPath": "dist/packages/core", | ||
"tsConfig": "packages/core/tsconfig.lib.json", | ||
"packageJson": "packages/core/package.json", | ||
"main": "packages/core/src/index.ts", | ||
"assets": ["packages/core/*.md"] | ||
} | ||
}, | ||
"lint": { | ||
"executor": "@nrwl/linter:eslint", | ||
"outputs": ["{options.outputFile}"], | ||
"options": { | ||
"lintFilePatterns": ["packages/core/**/*.ts"] | ||
} | ||
}, | ||
"test": { | ||
"executor": "@nrwl/jest:jest", | ||
"outputs": ["coverage/packages/core"], | ||
"options": { | ||
"jestConfig": "packages/core/jest.config.js", | ||
"passWithNoTests": true | ||
} | ||
}, | ||
"publish": { | ||
"executor": "./tools/executors:publish", | ||
"options": { | ||
"dist": "dist/packages/core" | ||
} | ||
} | ||
}, | ||
"tags": [] | ||
} |
Oops, something went wrong.