NodeSecure runtime configuration.
- Node.js v16 or higher
This package is available in the Node Package Repository and can be easily installed with npm or yarn.
$ npm i @nodesecure/rc
# or
$ yarn add @nodesecure/rc
Read:
import * as RC from "@nodesecure/rc";
const configurationPayload = (
await RC.read(void 0, { createIfDoesNotExist: true })
).unwrap();
console.log(configurationPayload);
Write:
import assert from "node:assert/strict";
import * as RC from "@nodesecure/rc";
const writeOpts: RC.writeOptions = {
payload: { version: "2.0.0" },
partialUpdate: true
};
const result = (
await RC.write(void 0, writeOpts)
).unwrap();
assert.strictEqual(result, void 0);
👀 .read and .write return Rust like Result object. Under the hood we use ts-results to achieve this.
If
undefined
the location will be assigned toprocess.cwd()
.
interface createReadOptions {
/**
* If enabled the file will be created if it does not exist on the disk.
*
* @default false
*/
createIfDoesNotExist?: boolean;
/**
* RC Generation mode. This option allows to generate a more or less complete configuration for some NodeSecure tools.
*
* @default `minimal`
*/
createMode?: RCGenerationMode | RCGenerationMode[];
}
export type readOptions = RequireAtLeastOne<createReadOptions, "createIfDoesNotExist" | "createMode">;
The createIfDoesNotExist
argument can be ignored if createMode
is provided.
import * as RC from "@nodesecure/rc";
const configurationPayload = (
await RC.read(void 0, { createMode: "ci" })
).unwrap();
console.log(configurationPayload);
By default the write API will overwrite the current payload with the provided one. When the partialUpdate
option is enabled it will merge the new properties with the existing one.
/**
* Overwrite the complete payload. partialUpdate property is mandatory.
*/
export interface writeCompletePayload {
payload: RC;
partialUpdate?: false;
}
/**
* Partially update the payload. This implies not to rewrite the content of the file when enabled.
**/
export interface writePartialPayload {
payload: Partial<RC>;
partialUpdate: true;
}
export type writeOptions = writeCompletePayload | writePartialPayload;
import assert from "node:assert/strict";
import * as RC from "@nodesecure/rc";
assert.strictEqual(RC.CONSTANTS.CONFIGURATION_NAME, ".nodesecurerc");
We provide by default a configuration generation that we consider minimal
. On the contrary, a complete
value will indicate the generation with all possible default keys.
export type RCGenerationMode = "minimal" | "ci" | "report" | "complete";
However, depending on the NodeSecure tool you are working on, it can be interesting to generate a configuration with some property sets specific to your needs.
Note that you can combine several modes:
import * as RC from "@nodesecure/rc";
await RC.read(void 0, { createMode: ["ci", "report"] })
The runtime configuration is validated with a JSON Schema: ./src/schema/nodesecurerc.json
.
It can be retrieved by API if required:
import * as RC from "@nodesecure/rc";
console.log(RC.JSONSchema);
Thanks goes to these wonderful people (emoji key):
Gentilhomme 💻 🐛 👀 📖 🛡️ |
Antoine Coulon 💻 🐛 👀 |
MIT