@eliware/common 15.0.1 → 15.2.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 (193) hide show
  1. package/AGENTS.md +7 -5
  2. package/README.md +12 -12
  3. package/RELEASE_NOTES.md +46 -0
  4. package/docs/README.md +10 -4
  5. package/docs/api.md +35 -164
  6. package/docs/logging.md +66 -0
  7. package/docs/package.md +44 -30
  8. package/docs/paths.md +57 -0
  9. package/docs/process-errors.md +62 -0
  10. package/docs/redaction.md +115 -0
  11. package/docs/signals.md +67 -0
  12. package/docs/snowflake-ids.md +77 -0
  13. package/docs/troubleshooting.md +33 -29
  14. package/docs/usage.md +42 -138
  15. package/package.json +28 -8
  16. package/specs/README.md +6 -0
  17. package/specs/directives.yaml +11 -6
  18. package/specs/errors.yaml +23 -0
  19. package/specs/log.yaml +19 -0
  20. package/specs/path.yaml +18 -0
  21. package/specs/redact.yaml +20 -0
  22. package/specs/signals.yaml +16 -0
  23. package/specs/snowflake.yaml +18 -0
  24. package/src/errors/cleanup/abort-listener.mjs +19 -0
  25. package/src/errors/cleanup/attached-handlers.mjs +30 -0
  26. package/src/errors/cleanup/detached-state.mjs +8 -0
  27. package/src/errors/cleanup/finalize.mjs +5 -0
  28. package/src/errors/cleanup/listener.mjs +27 -0
  29. package/src/errors/cleanup.mjs +43 -0
  30. package/src/errors/constants.mjs +1 -0
  31. package/src/errors/event/handler.mjs +38 -0
  32. package/src/errors/event/one-shot.mjs +37 -0
  33. package/src/errors/event-handlers.mjs +33 -0
  34. package/src/errors/failure.mjs +10 -0
  35. package/src/errors/finalize.mjs +27 -0
  36. package/src/errors/handler-removal.mjs +18 -0
  37. package/src/errors/index.d.mts +28 -0
  38. package/src/errors/index.d.ts +28 -0
  39. package/src/errors/index.mjs +6 -0
  40. package/src/errors/logging/diagnostic.mjs +9 -0
  41. package/src/errors/logging/error-diagnostic.mjs +5 -0
  42. package/src/errors/logging/value-diagnostic.mjs +5 -0
  43. package/src/errors/logging.mjs +10 -0
  44. package/src/errors/registration/events.mjs +9 -0
  45. package/src/errors/registration/lifecycle.mjs +18 -0
  46. package/src/errors/registration/registry.mjs +5 -0
  47. package/src/errors/registration/setup-state.mjs +20 -0
  48. package/src/errors/registration/state.mjs +28 -0
  49. package/src/errors/registration.mjs +80 -0
  50. package/src/errors/setup/installation.mjs +52 -0
  51. package/src/errors/setup/rollback.mjs +35 -0
  52. package/src/errors/setup.mjs +7 -0
  53. package/src/errors/validation/events.mjs +17 -0
  54. package/src/errors/validation/logger.mjs +8 -0
  55. package/src/errors/validation/process-object.mjs +11 -0
  56. package/src/errors/validation/signal.mjs +9 -0
  57. package/src/index.d.ts +14 -14
  58. package/src/index.mjs +9 -7
  59. package/src/log/child-logger.mjs +5 -0
  60. package/src/log/configuration/build-logger.mjs +13 -0
  61. package/src/log/configuration/default-options.mjs +5 -0
  62. package/src/log/configuration/normalize-options.mjs +14 -0
  63. package/src/log/configuration/validate-options.mjs +16 -0
  64. package/src/log/create-logger.mjs +18 -0
  65. package/src/log/formats/json-record.mjs +19 -0
  66. package/src/log/formats/json.mjs +38 -0
  67. package/src/log/formats/message.mjs +13 -0
  68. package/src/log/formats/text.mjs +21 -0
  69. package/src/log/index.d.mts +74 -0
  70. package/src/log/index.d.ts +74 -0
  71. package/src/log/index.mjs +15 -0
  72. package/src/log/logger-levels.mjs +37 -0
  73. package/src/path/base.mjs +17 -0
  74. package/src/path/conversions.mjs +7 -0
  75. package/src/path/create-path-helpers.mjs +58 -0
  76. package/src/path/current-path.mjs +13 -0
  77. package/src/path/file-url-to-path.mjs +5 -0
  78. package/src/path/index.d.mts +66 -0
  79. package/src/path/index.d.ts +66 -0
  80. package/src/path/index.mjs +12 -0
  81. package/src/path/input-classification.mjs +11 -0
  82. package/src/path/operation/failure.mjs +12 -0
  83. package/src/path/operation/logging.mjs +24 -0
  84. package/src/redact/headers/inspect-header-input.mjs +17 -0
  85. package/src/redact/headers/redact/entries.mjs +33 -0
  86. package/src/redact/headers/redact/headers.mjs +12 -0
  87. package/src/redact/headers/valid-entries.mjs +15 -0
  88. package/src/redact/index.d.mts +49 -0
  89. package/src/redact/index.d.ts +49 -0
  90. package/src/redact/index.mjs +7 -0
  91. package/src/redact/inspection/add-truncation-marker.mjs +13 -0
  92. package/src/redact/inspection/copy-error-fields.mjs +20 -0
  93. package/src/redact/inspection/inspect/entries.mjs +15 -0
  94. package/src/redact/inspection/inspect/error-fields.mjs +44 -0
  95. package/src/redact/inspection/safe-entries.mjs +7 -0
  96. package/src/redact/limits/default-limits.mjs +6 -0
  97. package/src/redact/limits/normalize/output-limit.mjs +8 -0
  98. package/src/redact/limits/normalize/traversal-limits.mjs +12 -0
  99. package/src/redact/markers/default-marker.mjs +1 -0
  100. package/src/redact/policy/create/policy.mjs +9 -0
  101. package/src/redact/policy/create/readonly-set.mjs +31 -0
  102. package/src/redact/policy/default/key-names.mjs +23 -0
  103. package/src/redact/policy/default/policy.mjs +9 -0
  104. package/src/redact/policy/normalize/keys.mjs +13 -0
  105. package/src/redact/policy/normalize-policy.mjs +14 -0
  106. package/src/redact/serialization/safe-serialize.mjs +34 -0
  107. package/src/redact/serialization/serialize/array.mjs +13 -0
  108. package/src/redact/serialization/serialize/buffer.mjs +5 -0
  109. package/src/redact/serialization/serialize/error.mjs +12 -0
  110. package/src/redact/serialization/serialize/object.mjs +22 -0
  111. package/src/redact/serialization/serialize/primitive.mjs +21 -0
  112. package/src/redact/structured/redact/array/attempt.mjs +9 -0
  113. package/src/redact/structured/redact/array/index-name.mjs +12 -0
  114. package/src/redact/structured/redact/array/indices.mjs +18 -0
  115. package/src/redact/structured/redact/array/properties.mjs +60 -0
  116. package/src/redact/structured/redact/array/result.mjs +11 -0
  117. package/src/redact/structured/redact/array.mjs +26 -0
  118. package/src/redact/structured/redact/classify.mjs +13 -0
  119. package/src/redact/structured/redact/error-fields.mjs +6 -0
  120. package/src/redact/structured/redact/error.mjs +14 -0
  121. package/src/redact/structured/redact/object.mjs +23 -0
  122. package/src/redact/structured/redact/value.mjs +49 -0
  123. package/src/redact/text/apply/configured/rules.mjs +9 -0
  124. package/src/redact/text/apply/configured/text-redactions.mjs +11 -0
  125. package/src/redact/text/apply/redactions.mjs +17 -0
  126. package/src/redact/text/apply/text-rules.mjs +8 -0
  127. package/src/redact/text/boundary/detect-jwt.mjs +18 -0
  128. package/src/redact/text/boundary/finish.mjs +15 -0
  129. package/src/redact/text/boundary/input.mjs +10 -0
  130. package/src/redact/text/boundary/jwt.mjs +22 -0
  131. package/src/redact/text/boundary/prepare.mjs +16 -0
  132. package/src/redact/text/boundary/process.mjs +9 -0
  133. package/src/redact/text/boundary/redaction.mjs +20 -0
  134. package/src/redact/text/boundary/secrets.mjs +21 -0
  135. package/src/redact/text/limit-output.mjs +12 -0
  136. package/src/redact/text/patterns/secret-key-patterns.mjs +2 -0
  137. package/src/redact/text/redact-text.mjs +8 -0
  138. package/src/redact/text/replace-literal/matches.mjs +39 -0
  139. package/src/redact/text/replace-literal/secret.mjs +6 -0
  140. package/src/redact/text/replace-literal/secrets.mjs +18 -0
  141. package/src/redact/text/replace-literal/trie.mjs +36 -0
  142. package/src/redact/text/rules/built-in.mjs +8 -0
  143. package/src/redact/text/rules/redact/authorization.mjs +12 -0
  144. package/src/redact/text/rules/redact/jwt/pattern.mjs +2 -0
  145. package/src/redact/text/rules/redact/jwt.mjs +10 -0
  146. package/src/redact/text/rules/redact/key/configured-values.mjs +25 -0
  147. package/src/redact/text/rules/redact/key/material.mjs +9 -0
  148. package/src/redact/text/rules/redact/key/values.mjs +16 -0
  149. package/src/redact/text/rules/redact/provider-token.mjs +9 -0
  150. package/src/signals/index.d.mts +29 -0
  151. package/src/signals/index.d.ts +29 -0
  152. package/src/signals/index.mjs +1 -0
  153. package/src/signals/lifecycle/abort/aggregate-cleanup.mjs +21 -0
  154. package/src/signals/lifecycle/abort/cleanup.mjs +9 -0
  155. package/src/signals/lifecycle/abort/listener-registration.mjs +14 -0
  156. package/src/signals/lifecycle/abort/listener.mjs +16 -0
  157. package/src/signals/lifecycle/abort/registration-cleanup.mjs +14 -0
  158. package/src/signals/lifecycle/abort/registration.mjs +19 -0
  159. package/src/signals/lifecycle/before/exit-registration.mjs +36 -0
  160. package/src/signals/lifecycle/before/exit.mjs +33 -0
  161. package/src/signals/lifecycle/cleanup/process-handlers.mjs +27 -0
  162. package/src/signals/lifecycle/cleanup/registration.mjs +5 -0
  163. package/src/signals/lifecycle/cleanup.mjs +17 -0
  164. package/src/signals/lifecycle/defaults.mjs +1 -0
  165. package/src/signals/lifecycle/exit-policy.mjs +17 -0
  166. package/src/signals/lifecycle/handlers/rollback.mjs +14 -0
  167. package/src/signals/lifecycle/handlers.mjs +35 -0
  168. package/src/signals/lifecycle/hooks.mjs +19 -0
  169. package/src/signals/lifecycle/logging.mjs +11 -0
  170. package/src/signals/lifecycle/registration-policy.mjs +29 -0
  171. package/src/signals/lifecycle/registration.mjs +7 -0
  172. package/src/signals/lifecycle/shutdown.mjs +75 -0
  173. package/src/signals/lifecycle/validation/lifecycle-options.mjs +8 -0
  174. package/src/signals/lifecycle/validation/logger.mjs +9 -0
  175. package/src/signals/lifecycle/validation/options.mjs +19 -0
  176. package/src/signals/lifecycle/validation/registration-options.mjs +36 -0
  177. package/src/signals/lifecycle/validation/signals.mjs +9 -0
  178. package/src/signals/register.mjs +76 -0
  179. package/src/snowflake/constants.mjs +15 -0
  180. package/src/snowflake/generator-options.mjs +27 -0
  181. package/src/snowflake/generator.mjs +82 -0
  182. package/src/snowflake/index.d.mts +24 -0
  183. package/src/snowflake/index.d.ts +24 -0
  184. package/src/snowflake/index.mjs +8 -0
  185. package/src/snowflake/log-generation-failure.mjs +9 -0
  186. package/src/snowflake/logger-validation.mjs +10 -0
  187. package/src/snowflake/validation.mjs +18 -0
  188. package/src/errors.d.mts +0 -9
  189. package/src/errors.mjs +0 -4
  190. package/src/fs.mjs +0 -4
  191. package/src/path.d.mts +0 -12
  192. package/src/path.mjs +0 -22
  193. package/src/signals.mjs +0 -4
package/AGENTS.md CHANGED
@@ -2,19 +2,19 @@
2
2
 
3
3
  ## Project
4
4
 
5
- See `README.md` for the repository purpose, owner, scope, and boundaries.
5
+ Eliware maintains `@eliware/common`, a shared native ESM package for Node.js utilities.
6
6
 
7
7
  ## Scope and boundaries
8
8
 
9
- Keep repository requirements in `specs/directives.yaml`.
9
+ Keep repository requirements in `specs/directives.yaml` and library behavior in the matching specifications under `specs/`.
10
10
 
11
11
  ## Layout
12
12
 
13
- Use `README.md` and `specs/README.md` to find maintained files.
13
+ Use `README.md`, `docs/README.md`, and `specs/README.md` to find maintained files.
14
14
 
15
15
  ## Development
16
16
 
17
- Give each source and test module one cohesive purpose.
17
+ Keep each source and test module focused on one responsibility. Keep public documentation aligned with maintained behavior.
18
18
 
19
19
  ## Validation
20
20
 
@@ -22,8 +22,10 @@ Use Node.js 26 or later and native ESM for maintained JavaScript modules.
22
22
  Run `npm test` for aggregate validation.
23
23
  Run `npm run lint` for lint checks.
24
24
  Run `npm run audit` for dependency checks.
25
+
25
26
  Run `npm run format` to format files.
26
27
  Run `npm run format:check` to check formatting.
28
+ Run `npm run typecheck` to check TypeScript declarations.
27
29
 
28
30
  ## Security
29
31
 
@@ -45,4 +47,4 @@ Run the full `npm test` suite for final validation before a commit, milestone, o
45
47
  ## npm publication
46
48
 
47
49
  Run `npm run pack` to check package contents.
48
- Publish only after approved release steps.
50
+ Follow Operations release procedures before publication.
package/README.md CHANGED
@@ -23,16 +23,15 @@ A shared ESM compatibility package for Eliware filesystem, path, logging, error,
23
23
 
24
24
  ## Features
25
25
 
26
- Eliware maintains this shared package for common Node.js APIs.
27
- It re-exports filesystem, path, logger, error, signal, redaction, and Snowflake APIs.
26
+ This package provides filesystem, redaction, logging, path, process error, signal, and Snowflake ID APIs.
28
27
 
29
28
  ## Requirements
30
29
 
31
- Use Node.js 26 or later.
30
+ Use Node.js 26 or later and a project that supports native ECMAScript modules.
32
31
 
33
32
  ## Setup
34
33
 
35
- Install the package.
34
+ Install the package with npm.
36
35
 
37
36
  ```text
38
37
  npm install @eliware/common
@@ -40,35 +39,36 @@ npm install @eliware/common
40
39
 
41
40
  ## Usage
42
41
 
43
- Read the [user docs](docs/README.md) and [release notes](RELEASE_NOTES.md).
42
+ Import APIs from `@eliware/common` or one of its focused subpaths. Read the [user documentation](docs/README.md) to find an API and learn its behavior.
43
+ Read the [release notes](RELEASE_NOTES.md) for version changes.
44
44
 
45
45
  ## Development
46
46
 
47
- Read the [specifications index](specs/README.md) before you change files.
47
+ Read [repository requirements](specs/README.md) before changing maintained files.
48
48
 
49
49
  ## Testing
50
50
 
51
- Run `npm test` to check the repository.
51
+ Run `npm test` to validate the package, tests, types, and published contents.
52
52
 
53
53
  ## Troubleshooting
54
54
 
55
- Read the [troubleshooting guide](docs/troubleshooting.md).
55
+ Use the [troubleshooting guide](docs/troubleshooting.md) to resolve common import, type, API, and runtime issues.
56
56
 
57
57
  ## Security
58
58
 
59
- Read the [redaction API guide](docs/api.md#redaction-apis) before you use sensitive data.
59
+ Read the [redaction guide](docs/redaction.md) before logging data that may contain secrets.
60
60
 
61
61
  ## API
62
62
 
63
- Read the [API reference](docs/api.md).
63
+ Read the [API reference](docs/api.md) for exports and the [usage guide](docs/usage.md) for examples.
64
64
 
65
65
  ## Packaging
66
66
 
67
- Read the [package guide](docs/package.md).
67
+ Read the [package guide](docs/package.md) for public entry points, included files, migration notes, and publication details.
68
68
 
69
69
  ## Examples
70
70
 
71
- Read the [examples index](examples/README.md).
71
+ Browse the [examples index](examples/README.md) for runnable native ESM examples.
72
72
 
73
73
  ## Support
74
74
 
package/RELEASE_NOTES.md CHANGED
@@ -1,5 +1,51 @@
1
1
  # Release Notes
2
2
 
3
+ ## 15.2.0 — 2026-11-27
4
+
5
+ ### Added
6
+
7
+ - Consolidate the Redact, Log, Path, Errors, Signals, and Snowflake libraries in `@eliware/common`.
8
+ - Export each library API from the package root and its focused subpath with public TypeScript declarations.
9
+ - Add API-specific source folders, tests, behavior specifications, and end-user guides.
10
+ - Add the error registration `ready` state and expose it as a read-only property.
11
+ - Add limits for configured literal secrets and document the supported redaction behavior.
12
+
13
+ ### Changed
14
+
15
+ - Remove the six former Eliware runtime packages from the package dependencies.
16
+ - Require `listeners()` on Signals process objects and verify handler removal before cleanup completes.
17
+ - Require error event sources to provide `on()`, `off()`, and `listeners()` methods.
18
+ - Require error handler abort signals to support listener removal.
19
+ - Preserve default sensitive key redaction when logger callers omit custom keys.
20
+ - Limit configured literal secrets to 100 values and 10,000 total characters.
21
+ - Require JWT separators before redacting a token at a text boundary.
22
+ - Keep TypeScript declarations aligned with runtime signal names, process objects, and cleanup state.
23
+ - Rewrite user guides for the consolidated package and document package publication details.
24
+
25
+ ### Fixed
26
+
27
+ - Keep signal and error handler cleanup retryable after a removal failure.
28
+ - Preserve accurate cleanup state when abort listener removal fails.
29
+ - Remove handlers after setup or registration logging fails.
30
+ - Preserve valid header redactions when input also contains malformed pairs or duplicate names.
31
+ - Preserve readable error fields when a standard getter throws.
32
+ - Redact JWT prefixes at the bounded text scan boundary.
33
+
34
+ ### Breaking changes
35
+
36
+ - Replace former package imports with `@eliware/common` or a focused subpath, then remove the former package dependencies.
37
+ - Add `@eliware/common` to application dependencies before removing the former packages.
38
+ - Provide `listeners()` on custom Signals process objects passed to `registerSignals()`.
39
+ - Provide `removeEventListener()` on AbortSignal-like values used by error handlers.
40
+ - Limit configured literal secrets to 100 values and 10,000 total characters.
41
+
42
+ ### Migration
43
+
44
+ - Install `@eliware/common` in each application that used a former library package.
45
+ - Replace imports with the matching root or focused subpath exports.
46
+ - Update custom process and abort signal objects to provide the required cleanup methods.
47
+ - Read the [package migration guide](docs/package.md) and [API reference](docs/api.md) before updating application code.
48
+
3
49
  ## 15.0.1 — 2026-10-26
4
50
 
5
51
  ### Changed
package/docs/README.md CHANGED
@@ -1,12 +1,18 @@
1
- # User docs
1
+ # Common Package Documentation
2
2
 
3
- Use these guides to install and use `@eliware/common`.
3
+ Use these guides to install `@eliware/common`, select APIs, and understand package limits.
4
4
 
5
5
  ## Guides
6
6
 
7
7
  - [Setup and usage](usage.md)
8
8
  - [API reference](api.md)
9
- - [Package contents and compatibility](package.md)
9
+ - [Redaction and safe serialization](redaction.md)
10
+ - [Logging](logging.md)
11
+ - [Path utilities](paths.md)
12
+ - [Process error handlers](process-errors.md)
13
+ - [Signal handling and shutdown](signals.md)
14
+ - [Snowflake IDs](snowflake-ids.md)
15
+ - [Package contents and migration](package.md)
10
16
  - [Troubleshooting](troubleshooting.md)
11
17
 
12
- Use Node.js 26 or later. Use an ESM project.
18
+ Use Node.js 26 or later. Use a project that supports native ECMAScript modules.
package/docs/api.md CHANGED
@@ -1,180 +1,51 @@
1
- # API reference
1
+ # API Reference
2
2
 
3
- Import public values from `@eliware/common`.
3
+ Import values from `@eliware/common` or use a focused package subpath.
4
4
 
5
5
  ```js
6
- import { fs, log, path, createSnowflakeGenerator } from "@eliware/common";
6
+ import { createLogger, path, redactText } from "@eliware/common";
7
+ import { registerSignals } from "@eliware/common/signals";
7
8
  ```
8
9
 
9
- The package re-exports APIs from Node.js and the Eliware packages listed in [package contents](package.md).
10
+ ## Export groups
10
11
 
11
- ## File system
12
+ | Group | Main exports | Guide |
13
+ | -------------- | --------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------- |
14
+ | File system | `fs` | [Node.js file system API](https://nodejs.org/api/fs.html) |
15
+ | Redaction | `createPolicy`, `defaultPolicy`, `redactHeaders`, `redactText`, `redactValue`, `replaceLiteralSecret`, `safeSerialize` | [Redaction and serialization](redaction.md) |
16
+ | Logging | `log`, `createLogger` | [Logging](logging.md) |
17
+ | Paths | `path`, `pathUrl`, `resolvePath`, `relativePath`, `fileUrlToPath`, `getCurrentDirname`, `getCurrentFilename`, `createPathHelpers` | [Path utilities](paths.md) |
18
+ | Process errors | `defaultEvents`, `registerHandlers` | [Process error handlers](process-errors.md) |
19
+ | Signals | `registerSignals` | [Signal handling](signals.md) |
20
+ | Snowflake IDs | `createSnowflakeGenerator`, `generate`, `snowflake`, `constants` | [Snowflake IDs](snowflake-ids.md) |
12
21
 
13
- `fs` is the Node.js `fs` module namespace. Use its standard functions, such as `readFile`, `readdir`, and `stat`.
14
- Read the [Node.js file system API](https://nodejs.org/api/fs.html) for functions, options, and errors.
22
+ The `log`, `path`, `snowflake`, `registerHandlers`, and `registerSignals` values also have default exports from their focused subpaths.
15
23
 
16
- ## Path helpers
24
+ ## Import paths
17
25
 
18
- | Export | Call | Result |
19
- | -------------------- | ------------------------------------------ | -------------------------------------------------- |
20
- | `path` | `path(metaOrDir, ...segments)` | Add segments to a module directory. |
21
- | `createPathHelpers` | `createPathHelpers(options?)` | Create path helpers that log each operation. |
22
- | `pathUrl` | `pathUrl(metaOrDir, ...segments)` | Return a file URL string. |
23
- | `getCurrentDirname` | `getCurrentDirname(metaOrDir, dirnameFn?)` | Return the module directory. |
24
- | `getCurrentFilename` | `getCurrentFilename(metaOrDir)` | Return the module filename or input string. |
25
- | `resolvePath` | `resolvePath(metaOrDir, ...segments)` | Return an absolute path. |
26
- | `relativePath` | `relativePath(metaOrDir, ...segments)` | Return a path from the module directory. |
27
- | `fileUrlToPath` | `fileUrlToPath(fileUrl)` | Convert a file URL string or `URL` to a file path. |
26
+ Use the root import for the complete API.
27
+ Use these subpaths for focused imports:
28
28
 
29
- Pass `import.meta` or a directory string as `metaOrDir`. Pass `dirnameFn` only with `import.meta`.
29
+ - `@eliware/common/redact`
30
+ - `@eliware/common/log`
31
+ - `@eliware/common/path`
32
+ - `@eliware/common/errors`
33
+ - `@eliware/common/signals`
34
+ - `@eliware/common/snowflake`
30
35
 
31
- Call `createPathHelpers()` to use the default logger. Pass `options.logger` to set the logger.
32
- The helpers write debug records after operations. They write error records before they throw an error.
33
- The default logger uses the `info` level, so it filters debug records. Set its level to `debug` to receive operation records.
34
-
35
- The default export from `@eliware/path` is named `path` here.
36
- Read the [path package docs](https://github.com/eliware/path/tree/main/docs) for details.
37
-
38
- ## Logger APIs
39
-
40
- | Export | Call | Result |
41
- | -------------- | ----------------------------------------------- | ------------------------------ |
42
- | `log` | `log.debug/info/warn/error(message, metadata?)` | Use the shared default logger. |
43
- | `createLogger` | `createLogger(options?)` | Create a logger instance. |
44
-
45
- `createLogger` accepts `level`, `transports`, `format`, `timestamp`, and `keys` options.
46
- Use `format: "text"` or `format: "json"`. The default level is `info`.
47
- The other defaults are a console transport, text format, no timestamp, and no custom redaction keys.
48
-
49
- `safeSerialize` accepts `keys`, `redactKeys`, `marker`, `circularMarker`, `maxDepth`, `maxKeys`, `maxArray`, and `maxString` options.
50
- It does not call `toJSON`. It uses default secret keys and limits when you omit options.
51
- It returns JSON-safe values. It converts BigInt values to text and marks circular or truncated values.
52
- Read the [logger package docs](https://github.com/eliware/log/tree/main/docs) for defaults and details.
53
-
54
- ## Redaction APIs
55
-
56
- | Export | Call | Result |
57
- | ---------------------- | ---------------------------------------------- | ----------------------------------------------- |
58
- | `createPolicy` | `createPolicy(options?)` | Create a frozen redaction policy. |
59
- | `defaultPolicy` | value | Provide the default sensitive names and marker. |
60
- | `redactValue` | `redactValue(value, options?)` | Return a redacted copy of structured data. |
61
- | `redactHeaders` | `redactHeaders(headers, options?)` | Return redacted header data. |
62
- | `redactText` | `redactText(value, options?)` | Return text with secret values replaced. |
63
- | `replaceLiteralSecret` | `replaceLiteralSecret(value, secret, marker?)` | Replace each exact secret occurrence. |
64
- | `safeSerialize` | `safeSerialize(value, options?)` | Return bounded data for logs and diagnostics. |
65
-
66
- `defaultPolicy` provides the default sensitive key names and marker.
67
- Call `createPolicy(options?)` to make a frozen policy with custom key names or markers.
68
- Call `redactValue(value, options?)` to return a redacted copy of an object or array.
69
- Call `redactHeaders(headers, options?)` to redact header values in an object, pair array, or entries object.
70
- Call `redactText(value, options?)` to redact standard credential patterns, custom key values, and literal secrets.
71
- Call `replaceLiteralSecret(value, secret, marker?)` to replace one exact secret in text.
72
-
73
- Policy options include `keys`, `redactKeys`, `marker`, and `circularMarker`.
74
- Structured values also support `maxDepth`, `maxKeys`, and `maxArray` limits.
75
- Text also supports `secrets` and the `maxOutputLength` limit.
76
-
77
- The default marker is `[REDACTED]`. The default text output limit is 10,000 characters.
78
- Redact limits input text before it applies the redaction rules.
79
- `redactText` detects authorization values, secret assignments, provider tokens, JWT-like strings, and key blocks.
80
-
81
- `redactValue` returns a copy and does not change its input.
82
- `redactHeaders` keeps the input shape for objects and pair arrays. It returns a lowercase object for entries objects.
83
- For arrays, `maxKeys` limits non-sensitive index and property values. Redact marks sensitive properties without reading their values.
84
-
85
- Common exports `safeSerialize` directly from `@eliware/redact`.
86
-
87
- Read the [Redact API guide](https://github.com/eliware/redact/blob/main/docs/api.md) for full rules and limits.
88
-
89
- ## Error handlers
90
-
91
- Call `registerHandlers(options?)` to add handlers for process events.
92
- The default events are `uncaughtException`, `unhandledRejection`, and `warning`.
93
- The `defaultEvents` export contains the default event names.
94
-
95
- | Option | Default | Purpose |
96
- | ------------ | -------------------------- | --------------------------------------------- |
97
- | `processObj` | `process` | Set the process-like event source. |
98
- | `log` | `@eliware/log` | Set the logger. |
99
- | `events` | Three process error events | Set the events for this function. |
100
- | `once` | `false` | Set one-time handler behavior. |
101
- | `signal` | None | Remove handlers when an `AbortSignal` aborts. |
102
-
103
- The result has a read-only `removed` value and a `removeHandlers()` method.
104
- Set a custom logger with `error`, `warn`, and `debug` methods.
105
- Pass a non-empty array of supported event names. The package rejects unsupported event names.
106
- Read the [errors package docs](https://github.com/eliware/errors/tree/main/docs) for event behavior and errors.
107
-
108
- ## Shutdown handlers
109
-
110
- Call `registerSignals(options?)` to add process shutdown handlers.
111
- The default signals are `SIGTERM`, `SIGINT`, and `SIGHUP`.
112
-
113
- | Option | Default | Purpose |
114
- | -------------- | ----------------------------- | ----------------------------------------------------- |
115
- | `processObj` | `process` | Set the process-like event source. |
116
- | `log` | `@eliware/log` | Set the logger. |
117
- | `signals` | `SIGTERM`, `SIGINT`, `SIGHUP` | Set the signals for this function. |
118
- | `shutdownHook` | None | Set cleanup work. This function can return a promise. |
119
- | `exitCode` | `0` | Set the process exit code. |
120
- | `exit` | `true` | Allow or prevent process exit. |
121
- | `signal` | None | Remove handlers when an `AbortSignal` aborts. |
122
-
123
- The result has `removed`, `shutdown(signal?)`, `getShuttingDown()`, and `removeHandlers()` members.
124
-
125
- The default `exit` value is `true`. Set `exit: false` when your app controls process exit.
126
-
127
- Each callback runs once. The package calls callbacks in order and continues after an error.
128
-
129
- Pass an empty `signals` array to disable signal events. A `beforeExit` handler also runs.
130
- Read the [signals API docs](https://github.com/eliware/signals/blob/main/docs/api.md) for shutdown order and error behavior.
131
-
132
- ## Snowflake IDs
133
-
134
- Call `createSnowflakeGenerator(options?)` to make a generator. Each call returns a decimal string.
135
-
136
- | Option | Type | Default | Purpose |
137
- | ----------- | ---------------------------- | ------------------ | ------------------------------------------------- |
138
- | `epoch` | `number` or `bigint` | `365662380000n` | Set the epoch in Unix milliseconds. |
139
- | `workerId` | `number` or `bigint` | `0` | Set a worker value from 0 through 31. |
140
- | `processId` | `number` or `bigint` | `process.pid % 32` | Set a process value from 0 through 31. |
141
- | `now` | function | `Date.now` | Set a clock that returns Unix milliseconds. |
142
- | `logger` | `LoggerWithConfiguredLevels` | None | Record generator events with a structured logger. |
143
-
144
- Use one epoch for all generators in one application. Give each active generator a unique worker and process ID pair.
145
- Keep each ID as a string. An ID uses a 42-bit timestamp, 5-bit worker value, 5-bit process value, and 12-bit sequence.
146
-
147
- Each generator can create 4096 IDs for each millisecond. It throws `RangeError` when time or sequence limits fail.
148
-
149
- Pass a safe integer or `bigint` to `epoch`, `workerId`, and `processId`.
150
- Set `epoch` from zero through `(1n << 42n) - 1n`. Set `workerId` and `processId` from 0 through 31.
151
-
152
- Pass a clock that returns Unix milliseconds as a safe integer or `bigint`.
153
- Set the first clock value at or after the epoch.
154
- After the first ID, the generator uses its last timestamp when the clock moves to an earlier time.
155
-
156
- The generator increments its sequence during a clock rollback. It throws `RangeError` when one generator creates more than 4096 IDs in one millisecond.
157
-
158
- Pass a logger with `error`, `warn`, `info`, and `debug` methods to record generator events. The generator writes no records when you omit the logger.
159
- The records do not include generated IDs, credentials, tokens, or error messages.
160
-
161
- The exports `generate`, `snowflake`, and the default export from `@eliware/snowflake` use one shared generator.
162
- The `constants` export provides `epoch`, `sequenceBits`, `processBits`, and `workerBits` values as `bigint`.
163
-
164
- Read the [Snowflake usage guide](https://github.com/eliware/snowflake/blob/main/docs/usage.md) for timestamp limits and clock behavior.
36
+ The package exposes native ESM entry points and TypeScript declarations.
37
+ It does not expose internal source modules as public import paths.
165
38
 
166
39
  ## TypeScript types
167
40
 
168
- The package exports these types:
41
+ The root entry point exports these types:
169
42
 
170
- - `Logger`
171
- - `LoggerWithConfiguredLevels`, `RedactionOptions`, and `SafeSerializedValue`
172
- - `PathLogger`, `PathHelpersOptions`, and `PathHelpers`
173
- - `NodeSignal`, `SignalsLogger`, and `SignalsProcessLike`
174
- - `ProcessEvent`, `ProcessListener`, and `ProcessLike`
175
- - `RegisterHandlersOptions` and `RegisteredHandlers`
176
- - `RegisterSignalsOptions` and `SignalsRegistration`
177
- - `RedactionPolicy`, `SerializationOptions`, `StructuredRedactionOptions`, and `TextRedactionOptions`
178
- - `SnowflakeGeneratorOptions` and `SnowflakeConstants`
43
+ - `Logger`, `LoggerWithConfiguredLevels`, `RedactionOptions`, and `SafeSerializedValue`.
44
+ - `PathLogger`, `PathHelpersOptions`, and `PathHelpers`.
45
+ - `ProcessEvent`, `ProcessListener`, `ProcessLike`, `RegisterHandlersOptions`, and `RegisteredHandlers`.
46
+ - `NodeSignal`, `SignalsLogger`, `SignalsProcessLike`, `RegisterSignalsOptions`, and `SignalsRegistration`.
47
+ - `RedactionPolicy`, `SerializationOptions`, `StructuredRedactionOptions`, and `TextRedactionOptions`.
48
+ - `SnowflakeGeneratorOptions` and `SnowflakeConstants`.
179
49
 
180
- Read the [declaration file](../src/index.d.ts) for the current type exports.
50
+ The focused subpaths export the type definitions for their APIs.
51
+ Read each guide for option details and return values.
@@ -0,0 +1,66 @@
1
+ # Logging
2
+
3
+ Use the default `log` object for shared logging.
4
+ Call `createLogger(options)` when an application needs separate settings or transports.
5
+
6
+ ```js
7
+ import { createLogger } from "@eliware/common";
8
+
9
+ const logger = createLogger({
10
+ level: "info",
11
+ format: "json",
12
+ timestamp: true,
13
+ keys: ["sessionId"],
14
+ });
15
+
16
+ logger.info("Request completed", { requestId: "demo", sessionId: "private-value" });
17
+ ```
18
+
19
+ The root package and `@eliware/common/log` subpath export the logger APIs.
20
+
21
+ ## Configure a logger
22
+
23
+ | Option | Default | Purpose |
24
+ | ------------ | ------------------------ | --------------------------------- |
25
+ | `level` | `info` | Set the minimum Winston level. |
26
+ | `transports` | Console transport | Set Winston output transports. |
27
+ | `format` | `text` | Select `text` or `json` output. |
28
+ | `timestamp` | `false` | Add timestamps to JSON output. |
29
+ | `keys` | Standard sensitive names | Set property names for redaction. |
30
+
31
+ The logger uses Winston levels: `error`, `warn`, `info`, `http`, `verbose`, `debug`, and `silly`.
32
+ Winston filters records with a lower level than the configured level.
33
+ The default `log` object uses the default `info` level.
34
+
35
+ Logger methods accept a message and optional metadata.
36
+ Primitive and array metadata values appear under the `value` field.
37
+ Use `logger.child(context)` to add shared context to a child logger.
38
+
39
+ ## Redact and serialize metadata
40
+
41
+ The logger redacts standard sensitive keys when `keys` is omitted.
42
+ When callers set `keys`, those names replace the standard sensitive keys.
43
+ The logger serializes metadata defensively.
44
+ Use `safeSerialize(value, options)` when an application requires a bounded representation before logging.
45
+ The function does not call `toJSON`.
46
+
47
+ ```js
48
+ import { createLogger, safeSerialize } from "@eliware/common";
49
+
50
+ const logger = createLogger({ format: "json", keys: ["sessionId"] });
51
+ const metadata = safeSerialize({ sessionId: "private-value", count: 2n });
52
+
53
+ logger.info("Job completed", metadata);
54
+ ```
55
+
56
+ `safeSerialize` accepts `keys`, `redactKeys`, `marker`, `circularMarker`, `maxDepth`, `maxKeys`, `maxArray`, and `maxString`.
57
+ It marks cycles, truncated values, BigInts, and special values.
58
+ Read [Redaction and safe serialization](redaction.md) for exact limits.
59
+
60
+ Redaction can miss unknown secrets.
61
+ Use it as one layer in safe logging, then check output before you share it.
62
+
63
+ ## Use logging with other APIs
64
+
65
+ Signals, path helpers, and Snowflake generators accept custom logger shapes.
66
+ Read [Path utilities](paths.md), [Signal handling](signals.md), and [Snowflake IDs](snowflake-ids.md) for required methods.
package/docs/package.md CHANGED
@@ -1,45 +1,59 @@
1
- # Package contents and compatibility
1
+ # Package Contents and Migration
2
2
 
3
- ## Runtime
3
+ `@eliware/common` combines filesystem, redaction, logging, path, process error, signal, and Snowflake APIs in one installable package.
4
4
 
5
- Use Node.js 26 or later. Use the package from a native ESM module.
6
- Install `@eliware/common` from [npm](https://www.npmjs.com/package/@eliware/common).
5
+ ## Requirements
7
6
 
8
- ## Entry points
7
+ Use Node.js 26 or later. Use a native ESM project.
9
8
 
10
- Import `@eliware/common` for the public runtime APIs.
11
- The runtime entry point is `src/index.mjs`.
12
- The TypeScript declaration entry point is `src/index.d.ts`.
13
- The package does not provide a CommonJS entry point.
9
+ ```text
10
+ npm install @eliware/common
11
+ ```
12
+
13
+ ## Public entry points
14
+
15
+ Import from `@eliware/common` for the complete API.
16
+ Use focused subpaths when an application needs only one area.
17
+
18
+ | Subpath | Library area |
19
+ | --------------------------- | -------------------------------- |
20
+ | `@eliware/common/redact` | Redaction and safe serialization |
21
+ | `@eliware/common/log` | Logging |
22
+ | `@eliware/common/path` | Path utilities |
23
+ | `@eliware/common/errors` | Process error handlers |
24
+ | `@eliware/common/signals` | Signal handling |
25
+ | `@eliware/common/snowflake` | Snowflake IDs |
26
+
27
+ The package exposes native ESM entry points and TypeScript declarations.
28
+ It does not expose CommonJS entry points or private source files.
14
29
 
15
30
  ## Runtime dependencies
16
31
 
17
- The package uses major version 15 of these Eliware packages:
32
+ The package uses Winston for logger transports and output.
33
+ The package includes the Node.js type declarations required by its TypeScript API.
34
+ It no longer requires the six former Eliware runtime packages.
18
35
 
19
- - `@eliware/errors`
20
- - `@eliware/log`
21
- - `@eliware/path`
22
- - `@eliware/redact`
23
- - `@eliware/signals`
24
- - `@eliware/snowflake`
36
+ ## Move from the former packages
25
37
 
26
- Use the exports in this package. Use a dependency directly when your app requires its own entry point.
27
- Read the [API reference](api.md) for each exported value.
38
+ Replace imports from former package names with `@eliware/common` or a focused subpath.
39
+ For example, import `createLogger` from `@eliware/common/log` and `redactText` from `@eliware/common/redact`.
40
+ Both imports resolve to implementations that the root package also exports.
28
41
 
29
- ## Published files
42
+ Update dependency declarations in your application before you remove former packages.
43
+ Read the [API reference](api.md) and each guide before you change imports.
30
44
 
31
- The npm package contains:
45
+ ## Published files
32
46
 
33
- - `src/` for runtime modules and declarations.
34
- - `docs/` for user docs.
35
- - `examples/` for native ESM examples.
36
- - `specs/` for repository specifications.
37
- - `README.md`, `AGENTS.md`, `LICENSE`, and `RELEASE_NOTES.md`.
47
+ The package includes `src/`, `docs/`, `examples/`, and `specs/`.
48
+ It also includes the package readme, license, and release notes.
49
+ The package excludes its tests, workflow files, and lockfile.
38
50
 
39
- The package excludes tests, workflows, and lock files.
51
+ ## Version and publication
40
52
 
41
- ## Version and release
53
+ Use a numeric `MAJOR.MINOR.PATCH` package version.
54
+ The npm workflow validates the package before publication.
55
+ It publishes only when a version tag matches the package version.
56
+ The workflow publishes with npm provenance.
57
+ Follow the current Operations release procedures before publication.
42
58
 
43
- Use the published npm version that matches your application requirements.
44
- Read [release notes](../RELEASE_NOTES.md) for changes by package version.
45
- Repository validation does not publish this package. Follow the Eliware Operations release process before publication.
59
+ Read the [release notes](../RELEASE_NOTES.md) for version changes.
package/docs/paths.md ADDED
@@ -0,0 +1,57 @@
1
+ # Path Utilities
2
+
3
+ Use path helpers to build filesystem paths and file URLs from an ESM module location.
4
+ The helpers use native Node.js path behavior and do not read or write files.
5
+
6
+ ```js
7
+ import { fileUrlToPath, path, pathUrl, relativePath, resolvePath } from "@eliware/common";
8
+
9
+ const file = path(import.meta, "data", "input.json");
10
+ const absolute = resolvePath(import.meta, "data", "input.json");
11
+ const relative = relativePath(import.meta, "data", "input.json");
12
+ const url = pathUrl(import.meta, "data", "input.json");
13
+ const localFile = fileUrlToPath(url);
14
+ ```
15
+
16
+ The root package and `@eliware/common/path` subpath export these APIs.
17
+
18
+ ## Select a helper
19
+
20
+ | Function | Result |
21
+ | -------------------------------------- | ---------------------------------------------------------------------------- |
22
+ | `getCurrentFilename(input)` | Return a filename from `import.meta` or return a directory string unchanged. |
23
+ | `getCurrentDirname(input, dirnameFn?)` | Return a module directory or apply `dirnameFn` to a filename. |
24
+ | `path(input, ...segments)` | Join segments to the module directory. |
25
+ | `resolvePath(input, ...segments)` | Resolve segments from the module directory. |
26
+ | `relativePath(input, ...segments)` | Return a relative path from the module directory. |
27
+ | `pathUrl(input, ...segments)` | Return a file URL string for a joined path. |
28
+ | `fileUrlToPath(url)` | Convert a file URL string or `URL` object to a filesystem path. |
29
+
30
+ Pass `import.meta` or a directory string as `input`.
31
+ A string always means a directory path.
32
+ The helpers use that string only as a directory path.
33
+ Pass `dirnameFn` only with `import.meta` input.
34
+
35
+ ## Add operation logging
36
+
37
+ Call `createPathHelpers({ logger })` to create helpers that report operations.
38
+ The logger must provide a `log(record)` method.
39
+ The default logger is the package `log` object.
40
+
41
+ ```js
42
+ import { createPathHelpers } from "@eliware/common";
43
+
44
+ const records = [];
45
+ const helpers = createPathHelpers({ logger: { log: (record) => records.push(record) } });
46
+ const file = helpers.path(import.meta, "data", "input.json");
47
+ ```
48
+
49
+ Each completed call writes a `debug` record with the operation and result type.
50
+ Each failed call writes an `error` record, then rethrows the same error.
51
+ The default logger filters debug records at its `info` level.
52
+
53
+ ## Input errors
54
+
55
+ Pass a valid `import.meta` object or a directory string.
56
+ Pass a file URL to `fileUrlToPath`.
57
+ The helpers do not normalize away parent segments or access the filesystem.