hierarchical-approval 0.4.0 → 0.5.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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,33 @@
3
3
  All notable changes to `hierarchical-approval` are documented here. This project
4
4
  adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
5
5
 
6
+ ## [0.5.0] - 2026-07-23
7
+
8
+ ### Added — NestJS integration
9
+
10
+ - **`hierarchical-approval/nestjs`** — first-class NestJS support on its own
11
+ tree-shakeable subpath. `@nestjs/common` is an **optional peer dependency**.
12
+ - `HierarchicalApprovalModule.forRoot(options)` and `.forRootAsync(asyncOptions)`
13
+ provide a configured `ApprovalEngine` under the `APPROVAL_ENGINE` token, with
14
+ an `isGlobal` flag and `imports`/`inject`/`useFactory` async wiring.
15
+ - `@InjectApprovalEngine()` decorator for injecting the engine into services.
16
+ - The module stops the engine's escalation scheduler on application shutdown
17
+ via `onModuleDestroy`.
18
+
19
+ ### Added — adoption & discoverability
20
+
21
+ - `examples/playground/` — a StackBlitz-ready, in-browser runnable demo of a
22
+ purchase-order approval chain, plus "Try it live" (RunKit + StackBlitz) links
23
+ in the README.
24
+ - Expanded npm `keywords` for problem-based search (approval-workflow,
25
+ maker-checker, four-eyes, delegation, escalation, …).
26
+
27
+ ### Fixed
28
+
29
+ - Replaced the non-standard `peerDependenciesOptional` field with the correct
30
+ `peerDependenciesMeta`, so `pg` (and now `@nestjs/common`) are properly marked
31
+ optional and no longer emit install-time peer warnings.
32
+
6
33
  ## [0.4.0] - 2026-07-23
7
34
 
8
35
  ### Added — per-template analytics
package/README.md CHANGED
@@ -11,7 +11,7 @@ Multi-tenant · audit-ready · fully pluggable · zero runtime dependencies you
11
11
  [![types](https://img.shields.io/npm/types/hierarchical-approval.svg?logo=typescript&logoColor=white&color=3178c6)](https://www.typescriptlang.org/)
12
12
  [![minzipped size](https://img.shields.io/bundlephobia/minzip/hierarchical-approval?color=44cc11)](https://bundlephobia.com/package/hierarchical-approval)
13
13
  [![license](https://img.shields.io/npm/l/hierarchical-approval.svg?color=blue)](./LICENSE)
14
- [![tests](https://img.shields.io/badge/tests-195%20passing-44cc11.svg?logo=vitest&logoColor=white)](./tests)
14
+ [![tests](https://img.shields.io/badge/tests-404%20passing-44cc11.svg?logo=vitest&logoColor=white)](./tests)
15
15
 
16
16
  [**Documentation**](https://hierarchical-approval.matthewswong.com) ·
17
17
  [**npm**](https://www.npmjs.com/package/hierarchical-approval) ·
@@ -28,6 +28,11 @@ npm install pg @types/pg
28
28
 
29
29
  > 📖 Full docs & live guides: **[hierarchical-approval.matthewswong.com](https://hierarchical-approval.matthewswong.com)**
30
30
 
31
+ ### ▶️ Try it live (no install)
32
+
33
+ - **[Run in your browser on RunKit →](https://npm.runkit.com/hierarchical-approval)** — `require('hierarchical-approval')` in an instant notebook.
34
+ - **[Open the interactive playground on StackBlitz →](https://stackblitz.com/github/matthews-wong/hierarchical-approval/tree/main/examples/playground)** — a full purchase-order approval chain running in-browser.
35
+
31
36
  <details>
32
37
  <summary><strong>Table of contents</strong></summary>
33
38
 
@@ -1069,6 +1074,65 @@ Every operation is wrapped in a span named `approval.<operation>` (e.g. `approva
1069
1074
 
1070
1075
  ---
1071
1076
 
1077
+ ## NestJS integration
1078
+
1079
+ First-class NestJS support ships as the `hierarchical-approval/nestjs` subpath. `@nestjs/common` is an **optional peer dependency** — you only pull it in if you use this module.
1080
+
1081
+ ```ts
1082
+ import { Module } from '@nestjs/common';
1083
+ import { HierarchicalApprovalModule } from 'hierarchical-approval/nestjs';
1084
+ import { MemoryAdapter } from 'hierarchical-approval/adapters/memory';
1085
+
1086
+ @Module({
1087
+ imports: [
1088
+ HierarchicalApprovalModule.forRoot({
1089
+ adapter: new MemoryAdapter(),
1090
+ isGlobal: true, // inject ApprovalEngine anywhere without re-importing
1091
+ }),
1092
+ ],
1093
+ })
1094
+ export class AppModule {}
1095
+ ```
1096
+
1097
+ Inject the configured engine with the `@InjectApprovalEngine()` decorator:
1098
+
1099
+ ```ts
1100
+ import { Injectable } from '@nestjs/common';
1101
+ import { ApprovalEngine } from 'hierarchical-approval';
1102
+ import { InjectApprovalEngine } from 'hierarchical-approval/nestjs';
1103
+
1104
+ @Injectable()
1105
+ export class InvoiceService {
1106
+ constructor(@InjectApprovalEngine() private readonly approvals: ApprovalEngine) {}
1107
+
1108
+ submit(invoiceId: string, amount: number) {
1109
+ return this.approvals.submit({
1110
+ templateName: 'Invoice',
1111
+ documentId: invoiceId,
1112
+ documentType: 'invoice',
1113
+ submittedBy: 'system',
1114
+ data: { amount },
1115
+ });
1116
+ }
1117
+ }
1118
+ ```
1119
+
1120
+ Configure asynchronously from your `ConfigService` (or any provider) with `forRootAsync`:
1121
+
1122
+ ```ts
1123
+ HierarchicalApprovalModule.forRootAsync({
1124
+ imports: [ConfigModule],
1125
+ inject: [ConfigService],
1126
+ useFactory: (config: ConfigService) => ({
1127
+ adapter: new PostgresAdapter({ connectionString: config.get('DATABASE_URL') }),
1128
+ }),
1129
+ });
1130
+ ```
1131
+
1132
+ The module registers the engine under the `APPROVAL_ENGINE` token and stops its escalation scheduler on application shutdown via `onModuleDestroy` (call `app.enableShutdownHooks()` to activate Nest's shutdown lifecycle).
1133
+
1134
+ ---
1135
+
1072
1136
  ## Custom storage adapter
1073
1137
 
1074
1138
  Implement `IStorageAdapter` to use any database: