@nodesecure/rc 4.1.0 → 5.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,245 +1,232 @@
1
- <p align="center">
2
- <img src="https://user-images.githubusercontent.com/4438263/216045720-779bf16d-1d35-409f-a0e6-4019bda8edde.jpg" alt="@nodesecure/rc">
3
- </p>
4
-
5
- <p align="center">
6
- <a href="https://github.com/NodeSecure/blob/master/workspaces/rc">
7
- <img src="https://img.shields.io/badge/dynamic/json.svg?style=for-the-badge&url=https://raw.githubusercontent.com/NodeSecure/scanner/blob/master/workspaces/rc/package.json&query=$.version&label=Version" alt="npm version">
8
- </a>
9
- <a href="https://github.com/NodeSecure/scanner/blob/master/workspaces/rc/LICENSE">
10
- <img src="https://img.shields.io/github/license/NodeSecure/scanner.svg?style=for-the-badge" alt="license">
11
- </a>
12
- <a href="https://api.securityscorecards.dev/projects/github.com/NodeSecure/blob/master/workspaces/rc">
13
- <img src="https://api.securityscorecards.dev/projects/github.com/NodeSecure/scanner/badge?style=for-the-badge" alt="ossf scorecard">
14
- </a>
15
- <a href="https://github.com/NodeSecure/scanner/actions?query=workflow%3A%22Node.js+CI%22">
16
- <img src="https://img.shields.io/github/actions/workflow/status/NodeSecure/scanner/node.js.yml?style=for-the-badge" alt="github ci workflow">
17
- </a>
18
- </p>
19
-
20
- NodeSecure runtime configuration.
21
-
22
- ## Requirements
23
-
24
- - [Node.js](https://nodejs.org/en/) v20 or higher
25
-
26
- ## Getting Started
27
-
28
- This package is available in the Node Package Repository and can be easily installed with [npm](https://docs.npmjs.com/getting-started/what-is-npm) or [yarn](https://yarnpkg.com).
29
-
30
- ```bash
31
- $ npm i @nodesecure/rc
32
- # or
33
- $ yarn add @nodesecure/rc
34
- ```
35
-
36
- ## Usage example
37
-
38
- read:
39
-
40
- ```ts
41
- import * as RC from "@nodesecure/rc";
42
-
43
- const configurationPayload = (
44
- await RC.read(void 0, { createIfDoesNotExist: true })
45
- ).unwrap();
46
- console.log(configurationPayload);
47
- ```
48
-
49
- write:
50
-
51
- ```ts
52
- import assert from "node:assert/strict";
53
- import * as RC from "@nodesecure/rc";
54
-
55
- const writeOpts: RC.writeOptions = {
56
- payload: { version: "2.0.0" },
57
- partialUpdate: true,
58
- };
59
-
60
- const result = (await RC.write(void 0, writeOpts)).unwrap();
61
- assert.strictEqual(result, void 0);
62
- ```
63
-
64
- memoize/memoized:
65
-
66
- ```ts
67
- import * as RC from "@nodesecure/rc";
68
- import assert from "node:assert";
69
-
70
- const configurationPayload = (
71
- await RC.read(void 0, { createMode: "ci" })
72
- ).unwrap()
73
-
74
- RC.memoize(configurationPayload, { overwrite: true });
75
-
76
- const memoizedPayload = RC.memoized();
77
- assert.deepEqual(configurationPayload, memoizedPayload);
78
- ```
79
-
80
- > 👀 .read and .write return Rust like [Result](https://doc.rust-lang.org/std/result/) object.
81
-
82
- ## API
83
-
84
- > [!NOTE]
85
- > If `undefined`, the location will be assigned to `process.cwd()`.
86
-
87
- ### read(location?: string, options?: readOptions): Promise< Result< RC, NodeJS.ErrnoException > >
88
-
89
- ```ts
90
- interface createReadOptions {
91
- /**
92
- * If enabled, the file will be created if it does not exist on disk.
93
- *
94
- * @default false
95
- */
96
- createIfDoesNotExist?: boolean;
97
- /**
98
- * Generate a more or less complete configuration.
99
- *
100
- * @default `minimal`
101
- */
102
- createMode?: RCGenerationMode | RCGenerationMode[];
103
- /**
104
- * Automatically cache the configuration when enabled.
105
- *
106
- * @default false
107
- */
108
- memoize?: boolean;
109
- }
110
-
111
- export type readOptions = RequireAtLeastOne<
112
- createReadOptions,
113
- "createIfDoesNotExist" | "createMode"
114
- >;
115
- ```
116
-
117
- The `createIfDoesNotExist` argument can be ignored if `createMode` is provided.
118
-
119
- ```ts
120
- import * as RC from "@nodesecure/rc";
121
-
122
- const configurationPayload = (
123
- await RC.read(void 0, { createMode: "ci" })
124
- ).unwrap();
125
- console.log(configurationPayload);
126
- ```
127
-
128
- ### write(location?: string, options: writeOptions): Promise< Result< void, NodeJS.ErrnoException > >
129
-
130
- 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.
131
-
132
- ```ts
133
- /**
134
- * Overwrite the complete payload. partialUpdate property is mandatory.
135
- */
136
- export interface writeCompletePayload {
137
- payload: RC;
138
- partialUpdate?: false;
139
- }
140
-
141
- /**
142
- * Partially update the payload. This implies not to rewrite the content of the file when enabled.
143
- **/
144
- export interface writePartialPayload {
145
- payload: Partial<RC>;
146
- partialUpdate: true;
147
- }
148
-
149
- export type writeOptions = writeCompletePayload | writePartialPayload;
150
- ```
151
- ### memoize(payload: Partial< RC >, options: memoizeOptions = {}): void
152
- By default, the memory API overwrites the previous stored payload. When the `OVERWRITE` option is `false`, it merges new properties with existing properties.
153
-
154
- ```ts
155
- export interface memoizeOptions {
156
- overwrite?: boolean;
157
- }
158
- ```
159
- The `overwrite` option is used to specify whether data should be overwritten or merged.
160
-
161
- ### memoized(options: memoizedOptions): Partial< RC > | null
162
- This method returns null, when the default value is null, otherwise, it returns the current value of `memoizedValue`.
163
-
164
- ```ts
165
- export interface memoizedOptions {
166
- defaultValue: Partial<RC>;
167
- }
168
- ```
169
- If the `defaultValue` property is at null, then this value will be returned when `memoized` is called.
170
-
171
- ### maybeMemoized(): Option< Partial< RC > >
172
-
173
- Same as memoized but return an Option monad.
174
-
175
- ```ts
176
- import * as RC from "@nodesecure/rc";
177
-
178
- const memoized = RC.maybeMemoized()
179
- .unwrapOr({}); // Some default RC here
180
- ```
181
-
182
- ### clearMemoized(): void
183
- Clear/reset memoized RC
184
-
185
- ### homedir(): string
186
-
187
- Dedicated directory for NodeSecure to store the configuration in the os HOME directory.
188
-
189
- ```ts
190
- import * as RC from "@nodesecure/rc";
191
-
192
- const homedir = RC.homedir();
193
- ```
194
-
195
- ### CONSTANTS
196
-
197
- ```ts
198
- import assert from "node:assert/strict";
199
- import * as RC from "@nodesecure/rc";
200
-
201
- assert.strictEqual(RC.CONSTANTS.CONFIGURATION_NAME, ".nodesecurerc");
202
- ```
203
-
204
- ### Generation Mode
205
-
206
- 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.
207
-
208
- ```ts
209
- export type RCGenerationMode = "minimal" | "ci" | "report" | "scanner" | "complete";
210
- ```
211
-
212
- 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.
213
-
214
- Note that you can combine several modes:
215
-
216
- ```ts
217
- import * as RC from "@nodesecure/rc";
218
-
219
- await RC.read(void 0, { createMode: ["ci", "report"] });
220
- ```
221
-
222
- ## JSON Schema
223
-
224
- The runtime configuration is validated using a JSON Schema: `./src/schema/nodesecurerc.json`.
225
-
226
- It can be retrieved via API if needed:
227
-
228
- ```ts
229
- import * as RC from "@nodesecure/rc";
230
-
231
- console.log(RC.JSONSchema);
232
- ```
233
-
234
- The JSON schema is a composition of multiple definitions for each tool:
235
-
236
- - [ci](./src/schema/defs/ci.json)
237
- - [ciWarnings](./src/schema/defs/ciWarnings.json)
238
- - [contact](./src/schema/defs/contact.json)
239
- - [report](./src/schema/defs/report.json)
240
- - [reportChart](./src/schema/defs/reportChart.json)
241
- - [scanner](./src/schema/defs/scanner.json)
242
-
243
- ## License
244
-
245
- MIT
1
+ <p align="center">
2
+ <img src="https://user-images.githubusercontent.com/4438263/216045720-779bf16d-1d35-409f-a0e6-4019bda8edde.jpg" alt="@nodesecure/rc">
3
+ </p>
4
+
5
+ <p align="center">
6
+ NodeSecure runtime configuration.
7
+ </p>
8
+
9
+ ## Requirements
10
+
11
+ - [Node.js](https://nodejs.org/en/) v20 or higher
12
+
13
+ ## Getting Started
14
+
15
+ This package is available in the Node Package Repository and can be easily installed with [npm](https://docs.npmjs.com/getting-started/what-is-npm) or [yarn](https://yarnpkg.com).
16
+
17
+ ```bash
18
+ $ npm i @nodesecure/rc
19
+ # or
20
+ $ yarn add @nodesecure/rc
21
+ ```
22
+
23
+ ## Usage example
24
+
25
+ read:
26
+
27
+ ```ts
28
+ import * as RC from "@nodesecure/rc";
29
+
30
+ const configurationPayload = (
31
+ await RC.read(void 0, { createIfDoesNotExist: true })
32
+ ).unwrap();
33
+ console.log(configurationPayload);
34
+ ```
35
+
36
+ write:
37
+
38
+ ```ts
39
+ import assert from "node:assert/strict";
40
+ import * as RC from "@nodesecure/rc";
41
+
42
+ const writeOpts: RC.writeOptions = {
43
+ payload: { version: "2.0.0" },
44
+ partialUpdate: true,
45
+ };
46
+
47
+ const result = (await RC.write(void 0, writeOpts)).unwrap();
48
+ assert.strictEqual(result, void 0);
49
+ ```
50
+
51
+ memoize/memoized:
52
+
53
+ ```ts
54
+ import * as RC from "@nodesecure/rc";
55
+ import assert from "node:assert";
56
+
57
+ const configurationPayload = (
58
+ await RC.read(void 0, { createMode: "ci" })
59
+ ).unwrap()
60
+
61
+ RC.memoize(configurationPayload, { overwrite: true });
62
+
63
+ const memoizedPayload = RC.memoized();
64
+ assert.deepEqual(configurationPayload, memoizedPayload);
65
+ ```
66
+
67
+ > 👀 .read and .write return Rust like [Result](https://doc.rust-lang.org/std/result/) object.
68
+
69
+ ## API
70
+
71
+ > [!NOTE]
72
+ > If `undefined`, the location will be assigned to `process.cwd()`.
73
+
74
+ ### read(location?: string, options?: readOptions): Promise< Result< RC, NodeJS.ErrnoException > >
75
+
76
+ ```ts
77
+ interface CreateReadOptions {
78
+ /**
79
+ * If enabled, the file will be created if it does not exist on disk.
80
+ *
81
+ * @default false
82
+ */
83
+ createIfDoesNotExist?: boolean;
84
+ /**
85
+ * Generate a more or less complete configuration.
86
+ *
87
+ * @default `minimal`
88
+ */
89
+ createMode?: RCGenerationMode | RCGenerationMode[];
90
+ /**
91
+ * Automatically cache the configuration when enabled.
92
+ *
93
+ * @default false
94
+ */
95
+ memoize?: boolean;
96
+ }
97
+
98
+ export type readOptions = RequireAtLeastOne<
99
+ CreateReadOptions,
100
+ "createIfDoesNotExist" | "createMode"
101
+ >;
102
+ ```
103
+
104
+ The `createIfDoesNotExist` argument can be ignored if `createMode` is provided.
105
+
106
+ ```ts
107
+ import * as RC from "@nodesecure/rc";
108
+
109
+ const configurationPayload = (
110
+ await RC.read(void 0, { createMode: "ci" })
111
+ ).unwrap();
112
+ console.log(configurationPayload);
113
+ ```
114
+
115
+ ### write(location?: string, options: WriteOptions): Promise< Result< void, NodeJS.ErrnoException > >
116
+
117
+ 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.
118
+
119
+ ```ts
120
+ /**
121
+ * Overwrite the complete payload. partialUpdate property is mandatory.
122
+ */
123
+ export interface WriteCompletePayload {
124
+ payload: RC;
125
+ partialUpdate?: false;
126
+ }
127
+
128
+ /**
129
+ * Partially update the payload. This implies not to rewrite the content of the file when enabled.
130
+ **/
131
+ export interface WritePartialPayload {
132
+ payload: Partial<RC>;
133
+ partialUpdate: true;
134
+ }
135
+
136
+ export type WriteOptions = WriteCompletePayload | WritePartialPayload;
137
+ ```
138
+ ### memoize(payload: Partial< RC >, options: MemoizeOptions = {}): void
139
+ By default, the memory API overwrites the previous stored payload. When the `OVERWRITE` option is `false`, it merges new properties with existing properties.
140
+
141
+ ```ts
142
+ export interface MemoizeOptions {
143
+ overwrite?: boolean;
144
+ }
145
+ ```
146
+ The `overwrite` option is used to specify whether data should be overwritten or merged.
147
+
148
+ ### memoized(options: MemoizedOptions): Partial< RC > | null
149
+ This method returns null, when the default value is null, otherwise, it returns the current value of `memoizedValue`.
150
+
151
+ ```ts
152
+ export interface MemoizedOptions {
153
+ defaultValue: Partial<RC>;
154
+ }
155
+ ```
156
+ If the `defaultValue` property is at null, then this value will be returned when `memoized` is called.
157
+
158
+ ### maybeMemoized(): Option< Partial< RC > >
159
+
160
+ Same as memoized but return an Option monad.
161
+
162
+ ```ts
163
+ import * as RC from "@nodesecure/rc";
164
+
165
+ const memoized = RC.maybeMemoized()
166
+ .unwrapOr({}); // Some default RC here
167
+ ```
168
+
169
+ ### clearMemoized(): void
170
+ Clear/reset memoized RC
171
+
172
+ ### homedir(): string
173
+
174
+ Dedicated directory for NodeSecure to store the configuration in the os HOME directory.
175
+
176
+ ```ts
177
+ import * as RC from "@nodesecure/rc";
178
+
179
+ const homedir = RC.homedir();
180
+ ```
181
+
182
+ ### CONSTANTS
183
+
184
+ ```ts
185
+ import assert from "node:assert/strict";
186
+ import * as RC from "@nodesecure/rc";
187
+
188
+ assert.strictEqual(RC.CONSTANTS.CONFIGURATION_NAME, ".nodesecurerc");
189
+ ```
190
+
191
+ ### Generation Mode
192
+
193
+ 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.
194
+
195
+ ```ts
196
+ export type RCGenerationMode = "minimal" | "ci" | "report" | "scanner" | "complete";
197
+ ```
198
+
199
+ 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.
200
+
201
+ Note that you can combine several modes:
202
+
203
+ ```ts
204
+ import * as RC from "@nodesecure/rc";
205
+
206
+ await RC.read(void 0, { createMode: ["ci", "report"] });
207
+ ```
208
+
209
+ ## JSON Schema
210
+
211
+ The runtime configuration is validated using a JSON Schema: `./src/schema/nodesecurerc.json`.
212
+
213
+ It can be retrieved via API if needed:
214
+
215
+ ```ts
216
+ import * as RC from "@nodesecure/rc";
217
+
218
+ console.log(RC.JSONSchema);
219
+ ```
220
+
221
+ The JSON schema is a composition of multiple definitions for each tool:
222
+
223
+ - [ci](./src/schema/defs/ci.json)
224
+ - [ciWarnings](./src/schema/defs/ciWarnings.json)
225
+ - [contact](./src/schema/defs/contact.json)
226
+ - [report](./src/schema/defs/report.json)
227
+ - [reportChart](./src/schema/defs/reportChart.json)
228
+ - [scanner](./src/schema/defs/scanner.json)
229
+
230
+ ## License
231
+
232
+ MIT
@@ -1,17 +1,17 @@
1
1
  import { type Option } from "@openally/result";
2
2
  import type { RC } from "../rc.js";
3
- export interface memoizeOptions {
3
+ export interface MemoizeOptions {
4
4
  /**
5
5
  * If enabled it will overwrite (crush) the previous memoized RC
6
6
  * @default true
7
7
  */
8
8
  overwrite?: boolean;
9
9
  }
10
- export declare function memoize(payload: Partial<RC>, options?: memoizeOptions): void;
11
- export interface memoizedOptions {
10
+ export declare function memoize(payload: Partial<RC>, options?: MemoizeOptions): void;
11
+ export interface MemoizedOptions {
12
12
  defaultValue: Partial<RC>;
13
13
  }
14
- export declare function memoized(options?: memoizedOptions): Partial<RC> | null;
14
+ export declare function memoized(options?: MemoizedOptions): Partial<RC> | null;
15
15
  export declare function maybeMemoized(): Option<Partial<RC>>;
16
16
  export declare function clearMemoized(): void;
17
17
  //# sourceMappingURL=memoize.d.ts.map
@@ -1,7 +1,7 @@
1
1
  import { Result } from "@openally/result";
2
2
  import type { RequireAtLeastOne } from "type-fest";
3
3
  import { type RCGenerationMode, type RC } from "../rc.js";
4
- interface createReadOptions {
4
+ interface CreateReadOptions {
5
5
  /**
6
6
  * If enabled the file will be created if it does not exist on the disk.
7
7
  *
@@ -21,7 +21,7 @@ interface createReadOptions {
21
21
  */
22
22
  memoize?: boolean;
23
23
  }
24
- export type readOptions = RequireAtLeastOne<createReadOptions, "createIfDoesNotExist" | "createMode">;
24
+ export type readOptions = RequireAtLeastOne<CreateReadOptions, "createIfDoesNotExist" | "createMode">;
25
25
  export declare function read(location?: string, options?: readOptions): Promise<Result<RC, NodeJS.ErrnoException>>;
26
26
  export {};
27
27
  //# sourceMappingURL=read.d.ts.map
@@ -3,17 +3,17 @@ import { type RC } from "../rc.js";
3
3
  /**
4
4
  * Overwrite the complete payload. partialUpdate property is mandatory.
5
5
  */
6
- export interface writeCompletePayload {
6
+ export interface WriteCompletePayload {
7
7
  payload: RC;
8
8
  partialUpdate?: false;
9
9
  }
10
10
  /**
11
11
  * Partially update the payload. This implies not to rewrite the content of the file when enabled.
12
12
  **/
13
- export interface writePartialPayload {
13
+ export interface WritePartialPayload {
14
14
  payload: Partial<RC>;
15
15
  partialUpdate: true;
16
16
  }
17
- export type writeOptions = writeCompletePayload | writePartialPayload;
18
- export declare function write(location: string, options: writeOptions): Promise<Result<void, NodeJS.ErrnoException>>;
17
+ export type WriteOptions = WriteCompletePayload | WritePartialPayload;
18
+ export declare function write(location: string, options: WriteOptions): Promise<Result<void, NodeJS.ErrnoException>>;
19
19
  //# sourceMappingURL=write.d.ts.map
package/package.json CHANGED
@@ -1,53 +1,53 @@
1
- {
2
- "name": "@nodesecure/rc",
3
- "version": "4.1.0",
4
- "description": "NodeSecure runtime configuration",
5
- "type": "module",
6
- "main": "./dist/index.js",
7
- "types": "./dist/index.d.ts",
8
- "engines": {
9
- "node": ">=20"
10
- },
11
- "scripts": {
12
- "build": "tsc",
13
- "prepublishOnly": "npm run build",
14
- "test-only": "tsx --test ./test/**/*.spec.ts",
15
- "test:tsd": "npm run build && tsd",
16
- "test": "c8 -r html npm run test-only && npm run test:tsd"
17
- },
18
- "repository": {
19
- "type": "git",
20
- "url": "git+https://github.com/NodeSecure/scanner.git"
21
- },
22
- "files": [
23
- "dist"
24
- ],
25
- "keywords": [
26
- "rc",
27
- "config",
28
- "configuration"
29
- ],
30
- "author": "GENTILHOMME Thomas <gentilhomme.thomas@gmail.com>",
31
- "license": "MIT",
32
- "bugs": {
33
- "url": "https://github.com/NodeSecure/scanner/issues"
34
- },
35
- "homepage": "https://github.com/NodeSecure/tree/master/workspaces/rc#readme",
36
- "devDependencies": {
37
- "@types/lodash.merge": "^4.6.7",
38
- "@types/zen-observable": "^0.8.4",
39
- "ajv": "^8.12.0"
40
- },
41
- "dependencies": {
42
- "@nodesecure/js-x-ray": "^8.1.0",
43
- "@nodesecure/npm-types": "^1.2.0",
44
- "@nodesecure/vulnera": "^2.0.1",
45
- "@openally/config": "^1.0.1",
46
- "@openally/result": "^1.2.1",
47
- "lodash.merge": "^4.6.2",
48
- "type-fest": "^4.41.0"
49
- },
50
- "tsd": {
51
- "directory": "test/types"
52
- }
53
- }
1
+ {
2
+ "name": "@nodesecure/rc",
3
+ "version": "5.0.1",
4
+ "description": "NodeSecure runtime configuration",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "engines": {
9
+ "node": ">=20"
10
+ },
11
+ "scripts": {
12
+ "build": "tsc",
13
+ "prepublishOnly": "npm run build",
14
+ "test-only": "tsx --test ./test/**/*.spec.ts",
15
+ "test:tsd": "npm run build && tsd",
16
+ "test": "c8 -r html npm run test-only && npm run test:tsd"
17
+ },
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/NodeSecure/scanner.git"
21
+ },
22
+ "files": [
23
+ "dist"
24
+ ],
25
+ "keywords": [
26
+ "rc",
27
+ "config",
28
+ "configuration"
29
+ ],
30
+ "author": "GENTILHOMME Thomas <gentilhomme.thomas@gmail.com>",
31
+ "license": "MIT",
32
+ "bugs": {
33
+ "url": "https://github.com/NodeSecure/scanner/issues"
34
+ },
35
+ "homepage": "https://github.com/NodeSecure/tree/master/workspaces/rc#readme",
36
+ "devDependencies": {
37
+ "@types/lodash.merge": "^4.6.7",
38
+ "@types/zen-observable": "^0.8.4",
39
+ "ajv": "^8.12.0"
40
+ },
41
+ "dependencies": {
42
+ "@nodesecure/js-x-ray": "^9.2.0",
43
+ "@nodesecure/npm-types": "^1.2.0",
44
+ "@nodesecure/vulnera": "^2.0.1",
45
+ "@openally/config": "^1.0.1",
46
+ "@openally/result": "^1.2.1",
47
+ "lodash.merge": "^4.6.2",
48
+ "type-fest": "^4.41.0"
49
+ },
50
+ "tsd": {
51
+ "directory": "test/types"
52
+ }
53
+ }