Skip to content

Commit 7ec2eda

Browse files
committed
feat(sdk): add per-request user impersonation to Context
Adds ctx.impersonate() with callback (auto-revert) and explicit (caller-managed) modes. Borrows a dedicated pool connection via Kysely's .connection() API, switches identity with dialect-specific SQL (EXECUTE AS USER for MSSQL, SET ROLE for PostgreSQL), and guarantees revert even on throw. Unsupported dialects throw at call time. Includes username validation and dialect-specific quoting for SQL injection prevention.
1 parent 359c28e commit 7ec2eda

18 files changed

Lines changed: 2755 additions & 9 deletions

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
"@noormdev/sdk": minor
3+
---
4+
5+
## Added
6+
7+
* `feat(sdk):` Per-request user impersonation via `ctx.impersonate()` — borrow a dedicated pool connection, switch database identity, and run queries as a specific principal with guaranteed revert
8+
* `feat(sdk):` Callback mode (auto-reverts on completion or throw) and explicit mode (caller-managed lifecycle for cross-boundary use cases like Hapi request hooks)
9+
* `feat(sdk):` MSSQL (`EXECUTE AS USER` / `REVERT`) and PostgreSQL (`SET ROLE` / `RESET ROLE`) dialect support with SQL injection prevention via username validation and dialect-specific quoting

0 commit comments

Comments
 (0)