The CasC SDK made for interacting with your AWS secrets from JavaScript or TypeScript applications.
NPM
npm install @saouas/cascade-js --save
Yarn
yarn add @saouas/cascade-js
Create a casc.config.yml
file in the root of your project, and define the structure and types of your application configuration.
For example:
database:
host:
type: string
port:
type: integer
username:
type: string
password:
type: string
secret: true
regex: ^[a-zA-Z0-9]+$
- You can nest properties to any depth level
- Supported types are
boolean
,string
,integer
andfloat
- Properties can be flagged with
optional: true
, orsecret: true
- For type
string
, you can add a regex expression that the value will have to match
You can add a build configuration command to your package.json:
{
"scripts": {
"build:config": "cascade-js build"
}
}
And then run npm run build:config
or yarn build:config
For example, in main.ts
:
import { Casc } from '@casc-sdk';
async function bootstrap() {
await Casc.init({ secretId: process.env.AWS_SECRET_ID });
const app = await NestFactory.create(ApplicationModule);
await app.listen(9999);
}
bootstrap();
Your configuration is then accessible with the import:
import { Casc } from '@casc-sdk';
Or using require:
const { Casc } = require('@casc-sdk');
For example:
import { Casc } from '@casc-sdk';
import { Client } from "postgres";
export class DatabaseClient {
private client: Client;
constructor() {
this.client = new Client({
host: Casc.config.database.host,
port: Casc.config.database.port,
username: Casc.config.database.username,
password: Casc.config.database.password,
})
}
}
Create a casc.local.yml
file in the root of your project, defining the values matching your configuration contract.
For example:
database:
host: "localhost"
port: 5432
username: "postgres"
password: "XPJc5qAbQcn77GWg"
In your CI or CD pipeline, run:
cascade-js validate --api-key $YOUR_ENVIRONMENT_API_KEY
Which will check if the values filled in the Casc platform comply with your contract.
Build your typescript types from your contract file.
The path to your configuration contract file. Default is casc.config.yml
.
By default, if contract stays identical, configuration won't be rebuilt to save time. Passing this option will force the rebuild of your configuration.
Check that with your configuration values, either read from a local file or fetched from the Casc platform, match your contract.
The path to your configuration contract file. Default is casc.config.yml
.
The path to your local values file. Default is casc.local.yml
.
The AWS secret id that will be used to fetch values. If specified, parameter -f, --values-file
is ignored.