@nodesecure/rc 1.4.0 → 2.0.0

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.
Files changed (40) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +15 -4
  3. package/dist/constants.d.ts +2 -2
  4. package/dist/constants.js +2 -2
  5. package/dist/functions/memoize.d.ts +16 -14
  6. package/dist/functions/memoize.js +25 -19
  7. package/dist/functions/memoize.js.map +1 -1
  8. package/dist/functions/read.d.ts +27 -27
  9. package/dist/functions/read.js +33 -35
  10. package/dist/functions/read.js.map +1 -1
  11. package/dist/functions/write.d.ts +19 -19
  12. package/dist/functions/write.js +25 -27
  13. package/dist/functions/write.js.map +1 -1
  14. package/dist/index.d.ts +5 -5
  15. package/dist/index.js +5 -5
  16. package/dist/index.js.map +1 -1
  17. package/dist/projects/ci.d.ts +25 -25
  18. package/dist/projects/ci.js +10 -10
  19. package/dist/projects/report.d.ts +69 -69
  20. package/dist/projects/report.js +32 -32
  21. package/dist/projects/scanner.d.ts +18 -0
  22. package/dist/projects/scanner.js +7 -0
  23. package/dist/projects/scanner.js.map +1 -0
  24. package/dist/rc.d.ts +48 -40
  25. package/dist/rc.js +34 -32
  26. package/dist/rc.js.map +1 -1
  27. package/dist/schema/defs/author.json +13 -0
  28. package/dist/schema/defs/ci.json +58 -58
  29. package/dist/schema/defs/ciWarnings.json +8 -8
  30. package/dist/schema/defs/report.json +97 -98
  31. package/dist/schema/defs/reportChart.json +27 -27
  32. package/dist/schema/defs/scanner.json +12 -0
  33. package/dist/schema/loader.d.ts +1 -1
  34. package/dist/schema/loader.js +19 -19
  35. package/dist/schema/nodesecurerc.json +48 -39
  36. package/dist/utils/index.d.ts +1 -1
  37. package/dist/utils/index.js +1 -1
  38. package/dist/utils/readJSON.d.ts +1 -1
  39. package/dist/utils/readJSON.js +6 -6
  40. package/package.json +17 -21
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2021 NodeSecure
3
+ Copyright (c) 2021-2024 NodeSecure
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  <img src="https://img.shields.io/badge/dynamic/json.svg?style=for-the-badge&url=https://raw.githubusercontent.com/NodeSecure/rc/master/package.json&query=$.version&label=Version" alt="npm version">
8
8
  </a>
9
9
  <a href="https://github.com/NodeSecure/rc/blob/master/LICENSE">
10
- <img src="https://img.shields.io/github/license/Naereen/StrapDown.js.svg?style=for-the-badge" alt="license">
10
+ <img src="https://img.shields.io/github/license/NodeSecure/rc.svg?style=for-the-badge" alt="license">
11
11
  </a>
12
12
  <a href="https://api.securityscorecards.dev/projects/github.com/NodeSecure/rc">
13
13
  <img src="https://api.securityscorecards.dev/projects/github.com/NodeSecure/rc/badge?style=for-the-badge" alt="ossf scorecard">
@@ -21,7 +21,7 @@ NodeSecure runtime configuration.
21
21
 
22
22
  ## Requirements
23
23
 
24
- - [Node.js](https://nodejs.org/en/) v16 or higher
24
+ - [Node.js](https://nodejs.org/en/) v18 or higher
25
25
 
26
26
  ## Getting Started
27
27
 
@@ -77,7 +77,7 @@ const memoizedPayload = RC.memoized();
77
77
  assert.deepEqual(configurationPayload, memoizedPayload);
78
78
  ```
79
79
 
80
- > 👀 .read and .write return Rust like [Result](https://doc.rust-lang.org/std/result/) object. Under the hood we use [ts-results](https://github.com/vultix/ts-results) to achieve this.
80
+ > 👀 .read and .write return Rust like [Result](https://doc.rust-lang.org/std/result/) object.
81
81
 
82
82
  ## API
83
83
 
@@ -167,6 +167,17 @@ export interface memoizedOptions {
167
167
  ```
168
168
  If the `defaultValue` property is at null, then this value will be returned when `memoized` is called.
169
169
 
170
+ ### maybeMemoized(): Option< Partial< RC > >
171
+
172
+ Same as memoized but return an Option monad.
173
+
174
+ ```ts
175
+ import * as RC from "@nodesecure/rc";
176
+
177
+ const memoized = RC.maybeMemoized()
178
+ .unwrapOr({}); // Some default RC here
179
+ ```
180
+
170
181
  ### clearMemoized(): void
171
182
  Clear/reset memoized RC
172
183
 
@@ -194,7 +205,7 @@ assert.strictEqual(RC.CONSTANTS.CONFIGURATION_NAME, ".nodesecurerc");
194
205
  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.
195
206
 
196
207
  ```ts
197
- export type RCGenerationMode = "minimal" | "ci" | "report" | "complete";
208
+ export type RCGenerationMode = "minimal" | "ci" | "report" | "scanner" | "complete";
198
209
  ```
199
210
 
200
211
  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.
@@ -1,2 +1,2 @@
1
- export declare const CONFIGURATION_NAME = ".nodesecurerc";
2
- export declare const GLOBAL_CONFIGURATION_DIRECTORY = "nodesecure";
1
+ export declare const CONFIGURATION_NAME = ".nodesecurerc";
2
+ export declare const GLOBAL_CONFIGURATION_DIRECTORY = "nodesecure";
package/dist/constants.js CHANGED
@@ -1,3 +1,3 @@
1
- export const CONFIGURATION_NAME = ".nodesecurerc";
2
- export const GLOBAL_CONFIGURATION_DIRECTORY = "nodesecure";
1
+ export const CONFIGURATION_NAME = ".nodesecurerc";
2
+ export const GLOBAL_CONFIGURATION_DIRECTORY = "nodesecure";
3
3
  //# sourceMappingURL=constants.js.map
@@ -1,14 +1,16 @@
1
- import { RC } from "../rc.js";
2
- export interface memoizeOptions {
3
- /**
4
- * If enabled it will overwrite (crush) the previous memoized RC
5
- * @default true
6
- */
7
- overwrite?: boolean;
8
- }
9
- export declare function memoize(payload: Partial<RC>, options?: memoizeOptions): void;
10
- export interface memoizedOptions {
11
- defaultValue: Partial<RC>;
12
- }
13
- export declare function memoized(options?: memoizedOptions): Partial<RC> | null;
14
- export declare function clearMemoized(): void;
1
+ import { Option } from "@openally/result";
2
+ import { RC } from "../rc.js";
3
+ export interface memoizeOptions {
4
+ /**
5
+ * If enabled it will overwrite (crush) the previous memoized RC
6
+ * @default true
7
+ */
8
+ overwrite?: boolean;
9
+ }
10
+ export declare function memoize(payload: Partial<RC>, options?: memoizeOptions): void;
11
+ export interface memoizedOptions {
12
+ defaultValue: Partial<RC>;
13
+ }
14
+ export declare function memoized(options?: memoizedOptions): Partial<RC> | null;
15
+ export declare function maybeMemoized(): Option<Partial<RC>>;
16
+ export declare function clearMemoized(): void;
@@ -1,20 +1,26 @@
1
- // Import Third-party Dependencies
2
- import merge from "lodash.merge";
3
- let memoizedValue = null;
4
- export function memoize(payload, options = {}) {
5
- const { overwrite = true } = options;
6
- if (memoizedValue === null || overwrite) {
7
- memoizedValue = payload;
8
- }
9
- else {
10
- memoizedValue = merge({}, memoizedValue, payload);
11
- }
12
- }
13
- export function memoized(options) {
14
- const { defaultValue = null } = options ?? {};
15
- return memoizedValue ?? defaultValue;
16
- }
17
- export function clearMemoized() {
18
- memoizedValue = null;
19
- }
1
+ // Import Third-party Dependencies
2
+ import merge from "lodash.merge";
3
+ import { Some, None } from "@openally/result";
4
+ let memoizedValue = null;
5
+ export function memoize(payload, options = {}) {
6
+ const { overwrite = true } = options;
7
+ if (memoizedValue === null || overwrite) {
8
+ memoizedValue = payload;
9
+ }
10
+ else {
11
+ memoizedValue = merge({}, memoizedValue, payload);
12
+ }
13
+ }
14
+ export function memoized(options) {
15
+ const { defaultValue = null } = options ?? {};
16
+ return memoizedValue ?? defaultValue;
17
+ }
18
+ export function maybeMemoized() {
19
+ return memoizedValue === null ?
20
+ None :
21
+ Some(memoizedValue);
22
+ }
23
+ export function clearMemoized() {
24
+ memoizedValue = null;
25
+ }
20
26
  //# sourceMappingURL=memoize.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"memoize.js","sourceRoot":"","sources":["../../src/functions/memoize.ts"],"names":[],"mappings":"AAAA,kCAAkC;AAClC,OAAO,KAAK,MAAM,cAAc,CAAC;AAKjC,IAAI,aAAa,GAAuB,IAAI,CAAC;AAU7C,MAAM,UAAU,OAAO,CACrB,OAAoB,EACpB,UAA0B,E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,CAAC,CAAC;QAC7B,IAAI,CAAC,CAAC;QACN,IAAI,CAAC,aAAa,CAAC,CAAC;AACxB,CAAC;AAED,MAAM,UAAU,aAAa;IAC3B,aAAa,GAAG,IAAI,CAAC;AACvB,CAAC"}
@@ -1,27 +1,27 @@
1
- /// <reference types="node" />
2
- import { Result } from "ts-results";
3
- import { RequireAtLeastOne } from "type-fest";
4
- import { RC, RCGenerationMode } from "../rc.js";
5
- interface createReadOptions {
6
- /**
7
- * If enabled the file will be created if it does not exist on the disk.
8
- *
9
- * @default false
10
- */
11
- createIfDoesNotExist?: boolean;
12
- /**
13
- * RC Generation mode. This option allows to generate a more or less complete configuration for some NodeSecure tools.
14
- *
15
- * @default `minimal`
16
- */
17
- createMode?: RCGenerationMode | RCGenerationMode[];
18
- /**
19
- * RC automatic caching option. This option allows to cache a configuration passed in parameter.
20
- *
21
- * @default false
22
- */
23
- memoize?: boolean;
24
- }
25
- export type readOptions = RequireAtLeastOne<createReadOptions, "createIfDoesNotExist" | "createMode">;
26
- export declare function read(location?: string, options?: readOptions): Promise<Result<RC, NodeJS.ErrnoException>>;
27
- export {};
1
+ /// <reference types="node" />
2
+ import { Result } from "@openally/result";
3
+ import { RequireAtLeastOne } from "type-fest";
4
+ import { RC, RCGenerationMode } from "../rc.js";
5
+ interface createReadOptions {
6
+ /**
7
+ * If enabled the file will be created if it does not exist on the disk.
8
+ *
9
+ * @default false
10
+ */
11
+ createIfDoesNotExist?: boolean;
12
+ /**
13
+ * RC Generation mode. This option allows to generate a more or less complete configuration for some NodeSecure tools.
14
+ *
15
+ * @default `minimal`
16
+ */
17
+ createMode?: RCGenerationMode | RCGenerationMode[];
18
+ /**
19
+ * RC automatic caching option. This option allows to cache a configuration passed in parameter.
20
+ *
21
+ * @default false
22
+ */
23
+ memoize?: boolean;
24
+ }
25
+ export type readOptions = RequireAtLeastOne<createReadOptions, "createIfDoesNotExist" | "createMode">;
26
+ export declare function read(location?: string, options?: readOptions): Promise<Result<RC, NodeJS.ErrnoException>>;
27
+ export {};
@@ -1,36 +1,34 @@
1
- // Import Node.js Dependencies
2
- import path from "node:path";
3
- import { once } from "node:events";
4
- // Import Third-party Dependencies
5
- import Config from "@slimio/config";
6
- import TR from "ts-results";
7
- // Import Internal Dependencies
8
- import { JSONSchema, generateDefaultRC } from "../rc.js";
9
- import * as CONSTANTS from "../constants.js";
10
- import { memoize } from "./memoize.js";
11
- // CONSTANTS
12
- const { Ok, Err } = TR;
13
- export async function read(location = process.cwd(), options = Object.create(null)) {
14
- try {
15
- const { createIfDoesNotExist = Boolean(options.createMode), createMode, memoize: memoizeRc = false } = options;
16
- const cfgPath = path.join(location, CONSTANTS.CONFIGURATION_NAME);
17
- const cfg = new Config(cfgPath, {
18
- defaultSchema: JSONSchema,
19
- createOnNoEntry: createIfDoesNotExist
20
- });
21
- await cfg.read(createIfDoesNotExist ? generateDefaultRC(createMode) : void 0);
22
- if (createIfDoesNotExist) {
23
- await once(cfg, "configWritten");
24
- }
25
- const result = cfg.payload;
26
- if (memoizeRc) {
27
- memoize(result);
28
- }
29
- await cfg.close();
30
- return new Ok(result);
31
- }
32
- catch (error) {
33
- return new Err(error);
34
- }
35
- }
1
+ // Import Node.js Dependencies
2
+ import path from "node:path";
3
+ import { once } from "node:events";
4
+ // Import Third-party Dependencies
5
+ import Config from "@slimio/config";
6
+ import { Ok, Err } from "@openally/result";
7
+ // Import Internal Dependencies
8
+ import { JSONSchema, generateDefaultRC } from "../rc.js";
9
+ import * as CONSTANTS from "../constants.js";
10
+ import { memoize } from "./memoize.js";
11
+ export async function read(location = process.cwd(), options = Object.create(null)) {
12
+ try {
13
+ const { createIfDoesNotExist = Boolean(options.createMode), createMode, memoize: memoizeRc = false } = options;
14
+ const cfgPath = path.join(location, CONSTANTS.CONFIGURATION_NAME);
15
+ const cfg = new Config(cfgPath, {
16
+ defaultSchema: JSONSchema,
17
+ createOnNoEntry: createIfDoesNotExist
18
+ });
19
+ await cfg.read(createIfDoesNotExist ? generateDefaultRC(createMode) : void 0);
20
+ if (createIfDoesNotExist) {
21
+ await once(cfg, "configWritten");
22
+ }
23
+ const result = cfg.payload;
24
+ if (memoizeRc) {
25
+ memoize(result);
26
+ }
27
+ await cfg.close();
28
+ return Ok(result);
29
+ }
30
+ catch (error) {
31
+ return Err(error);
32
+ }
33
+ }
36
34
  //# sourceMappingURL=read.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"read.js","sourceRoot":"","sources":["../../src/functions/read.ts"],"names":[],"mappings":"AAAA,8BAA8B;AAC9B,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAEnC,kCAAkC;AAClC,OAAO,MAAM,MAAM,gBAAgB,CAAC;AACpC,OAAO,EAAc,MAAM,YAAY,CAAC;AAGxC,+BAA+B;AAC/B,OAAO,EAAM,UAAU,EAAE,iBAAiB,EAAoB,MAAM,UAAU,CAAC;AAC/E,OAAO,KAAK,SAAS,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,YAAY;AACZ,MAAM,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;AA0BvB,MAAM,CAAC,KAAK,UAAU,IAAI,CACxB,QAAQ,GAAG,OAAO,CAAC,GAAG,EAAE,EACxB,UAAuB,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC;IAE1C,IAAI;QACF,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,UAAU,EAAE,OAAO,EAAE,SAAS,GAAG,KAAK,EAAE,GAAG,OAAO,CAAC;QAE/G,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,SAAS,CAAC,kBAAkB,CAAC,CAAC;QAClE,MAAM,GAAG,GAAG,IAAI,MAAM,CAAK,OAAO,EAAE;YAClC,aAAa,EAAE,UAAU;YACzB,eAAe,EAAE,oBAAoB;SACt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O,EAAE,SAAS,GAAG,KAAK,EAAE,GAAG,OAAO,CAAC;QAE/G,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,SAAS,CAAC,kBAAkB,CAAC,CAAC;QAClE,MAAM,GAAG,GAAG,IAAI,MAAM,CAAK,OAAO,EAAE;YAClC,aAAa,EAAE,UAAU;YACzB,eAAe,EAAE,oBAAoB;SACtC,CAAC,CAAC;QAEH,MAAM,GAAG,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC,CAAC,iBAAiB,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;QAC9E,IAAI,oBAAoB,EAAE,CAAC;YACzB,MAAM,IAAI,CAAC,GAAG,EAAE,eAAe,CAAC,CAAC;QACnC,CAAC;QACD,MAAM,MAAM,GAAG,GAAG,CAAC,OAAO,CAAC;QAE3B,IAAI,SAAS,EAAE,CAAC;YACd,OAAO,CAAC,MAAM,CAAC,CAAC;QAClB,CAAC;QAED,MAAM,GAAG,CAAC,KAAK,EAAE,CAAC;QAElB,OAAO,EAAE,CAAC,MAAM,CAAC,CAAC;IACpB,CAAC;IACD,OAAO,KAAK,EAAE,CAAC;QACb,OAAO,GAAG,CAAC,KAA8B,CAAC,CAAC;IAC7C,CAAC;AACH,CAAC"}
@@ -1,19 +1,19 @@
1
- /// <reference types="node" />
2
- import { Result } from "ts-results";
3
- import { RC } from "../rc.js";
4
- /**
5
- * Overwrite the complete payload. partialUpdate property is mandatory.
6
- */
7
- export interface writeCompletePayload {
8
- payload: RC;
9
- partialUpdate?: false;
10
- }
11
- /**
12
- * Partially update the payload. This implies not to rewrite the content of the file when enabled.
13
- **/
14
- export interface writePartialPayload {
15
- payload: Partial<RC>;
16
- partialUpdate: true;
17
- }
18
- export type writeOptions = writeCompletePayload | writePartialPayload;
19
- export declare function write(location: string | undefined, options: writeOptions): Promise<Result<void, NodeJS.ErrnoException>>;
1
+ /// <reference types="node" />
2
+ import { Result } from "@openally/result";
3
+ import { RC } from "../rc.js";
4
+ /**
5
+ * Overwrite the complete payload. partialUpdate property is mandatory.
6
+ */
7
+ export interface writeCompletePayload {
8
+ payload: RC;
9
+ partialUpdate?: false;
10
+ }
11
+ /**
12
+ * Partially update the payload. This implies not to rewrite the content of the file when enabled.
13
+ **/
14
+ export interface writePartialPayload {
15
+ payload: Partial<RC>;
16
+ partialUpdate: true;
17
+ }
18
+ export type writeOptions = writeCompletePayload | writePartialPayload;
19
+ export declare function write(location: string | undefined, options: writeOptions): Promise<Result<void, NodeJS.ErrnoException>>;
@@ -1,28 +1,26 @@
1
- // Import Node.js Dependencies
2
- import path from "path";
3
- // Import Third-party Dependencies
4
- import Config from "@slimio/config";
5
- import TR from "ts-results";
6
- // Import Internal Dependencies
7
- import { JSONSchema } from "../rc.js";
8
- import * as CONSTANTS from "../constants.js";
9
- // CONSTANTS
10
- const { Ok, Err } = TR;
11
- export async function write(location = process.cwd(), options) {
12
- try {
13
- const { payload, partialUpdate = false } = options;
14
- const cfgPath = path.join(location, CONSTANTS.CONFIGURATION_NAME);
15
- const cfg = new Config(cfgPath, {
16
- defaultSchema: JSONSchema
17
- });
18
- await cfg.read();
19
- const newPayloadValue = partialUpdate ? Object.assign(cfg.payload, payload) : payload;
20
- cfg.payload = newPayloadValue;
21
- await cfg.close();
22
- return new Ok(void 0);
23
- }
24
- catch (error) {
25
- return new Err(error);
26
- }
27
- }
1
+ // Import Node.js Dependencies
2
+ import path from "path";
3
+ // Import Third-party Dependencies
4
+ import Config from "@slimio/config";
5
+ import { Ok, Err } from "@openally/result";
6
+ // Import Internal Dependencies
7
+ import { JSONSchema } from "../rc.js";
8
+ import * as CONSTANTS from "../constants.js";
9
+ export async function write(location = process.cwd(), options) {
10
+ try {
11
+ const { payload, partialUpdate = false } = options;
12
+ const cfgPath = path.join(location, CONSTANTS.CONFIGURATION_NAME);
13
+ const cfg = new Config(cfgPath, {
14
+ defaultSchema: JSONSchema
15
+ });
16
+ await cfg.read();
17
+ const newPayloadValue = partialUpdate ? Object.assign(cfg.payload, payload) : payload;
18
+ cfg.payload = newPayloadValue;
19
+ await cfg.close();
20
+ return Ok(void 0);
21
+ }
22
+ catch (error) {
23
+ return Err(error);
24
+ }
25
+ }
28
26
  //# sourceMappingURL=write.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"write.js","sourceRoot":"","sources":["../../src/functions/write.ts"],"names":[],"mappings":"AAAA,8BAA8B;AAC9B,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,kCAAkC;AAClC,OAAO,MAAM,MAAM,gBAAgB,CAAC;AACpC,OAAO,EAAc,MAAM,YAAY,CAAC;AAExC,+BAA+B;AAC/B,OAAO,EAAM,UAAU,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,KAAK,SAAS,MAAM,iBAAiB,CAAC;AAE7C,YAAY;AACZ,MAAM,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;AAoBvB,MAAM,CAAC,KAAK,UAAU,KAAK,CACzB,QAAQ,GAAG,OAAO,CAAC,GAAG,EAAE,EACxB,OAAqB;IAErB,IAAI;QACF,MAAM,EAAE,OAAO,EAAE,aAAa,GAAG,KAAK,EAAE,GAAG,OAAO,CAAC;QAEnD,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,SAAS,CAAC,kBAAkB,CAAC,CAAC;QAClE,MAAM,GAAG,GAAG,IAAI,MAAM,CAAK,OAAO,EAAE;YAClC,aAAa,EAAE,UAAU;SAC1B,CAAC,CAAC;QACH,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;QAEjB,MAAM,eAAe,GAAG,aAAa,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,OAAa,CAAC;QAC5F,GAAG,CAAC,OAAO,GAAG,eAAe,CAAC;QAE9B,MAAM,GAAG,CAAC,KAAK,EAAE,CAAC;QAElB,OAAO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G,CAAC,KAA8B,CAAC,CAAC;IAC7C,CAAC;AACH,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- export * from "./functions/read.js";
2
- export * from "./functions/write.js";
3
- export * from "./functions/memoize.js";
4
- export * as CONSTANTS from "./constants.js";
5
- export { RC, JSONSchema, homedir } from "./rc.js";
1
+ export * from "./functions/read.js";
2
+ export * from "./functions/write.js";
3
+ export * from "./functions/memoize.js";
4
+ export * as CONSTANTS from "./constants.js";
5
+ export { type RC, type Author, JSONSchema, homedir } from "./rc.js";
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
- export * from "./functions/read.js";
2
- export * from "./functions/write.js";
3
- export * from "./functions/memoize.js";
4
- export * as CONSTANTS from "./constants.js";
5
- export { JSONSchema, homedir } from "./rc.js";
1
+ export * from "./functions/read.js";
2
+ export * from "./functions/write.js";
3
+ export * from "./functions/memoize.js";
4
+ export * as CONSTANTS from "./constants.js";
5
+ export { JSONSchema, homedir } from "./rc.js";
6
6
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAC;AAE5C,OAAO,EAAM,UAAU,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAC;AAE5C,OAAO,EAAwB,UAAU,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC"}
@@ -1,25 +1,25 @@
1
- import * as jsxray from "@nodesecure/js-x-ray";
2
- /**
3
- * Configuration dedicated for NodeSecure CI (or nsci)
4
- * @see https://github.com/NodeSecure/ci
5
- * @see https://github.com/NodeSecure/ci-action
6
- */
7
- export interface CiConfiguration {
8
- /**
9
- * List of enabled reporters
10
- * @see https://github.com/NodeSecure/ci#reporters
11
- */
12
- reporters?: ("console" | "html")[];
13
- vulnerabilities?: {
14
- severity?: "medium" | "high" | "critical" | "all";
15
- };
16
- /**
17
- * JS-X-Ray warnings configuration
18
- * @see https://github.com/NodeSecure/js-x-ray#warnings-legends-v20
19
- */
20
- warnings?: CiWarnings | Record<jsxray.WarningName, CiWarnings>;
21
- }
22
- export type CiWarnings = "off" | "error" | "warning";
23
- export declare function generateCIConfiguration(): {
24
- ci: CiConfiguration;
25
- };
1
+ import * as jsxray from "@nodesecure/js-x-ray";
2
+ /**
3
+ * Configuration dedicated for NodeSecure CI (or nsci)
4
+ * @see https://github.com/NodeSecure/ci
5
+ * @see https://github.com/NodeSecure/ci-action
6
+ */
7
+ export interface CiConfiguration {
8
+ /**
9
+ * List of enabled reporters
10
+ * @see https://github.com/NodeSecure/ci#reporters
11
+ */
12
+ reporters?: ("console" | "html")[];
13
+ vulnerabilities?: {
14
+ severity?: "medium" | "high" | "critical" | "all";
15
+ };
16
+ /**
17
+ * JS-X-Ray warnings configuration
18
+ * @see https://github.com/NodeSecure/js-x-ray#warnings-legends-v20
19
+ */
20
+ warnings?: CiWarnings | Record<jsxray.WarningName, CiWarnings>;
21
+ }
22
+ export type CiWarnings = "off" | "error" | "warning";
23
+ export declare function generateCIConfiguration(): {
24
+ ci: CiConfiguration;
25
+ };
@@ -1,11 +1,11 @@
1
- export function generateCIConfiguration() {
2
- const ci = {
3
- reporters: ["console"],
4
- vulnerabilities: {
5
- severity: "medium"
6
- },
7
- warnings: "error"
8
- };
9
- return { ci };
10
- }
1
+ export function generateCIConfiguration() {
2
+ const ci = {
3
+ reporters: ["console"],
4
+ vulnerabilities: {
5
+ severity: "medium"
6
+ },
7
+ warnings: "error"
8
+ };
9
+ return { ci };
10
+ }
11
11
  //# sourceMappingURL=ci.js.map