@stratum-hq/lib 0.2.4 → 0.3.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 (3) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +83 -0
  3. package/package.json +6 -1
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Christian Crank
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,83 @@
1
+ # @stratum-hq/lib
2
+
3
+ Framework-agnostic library for embedding [Stratum](https://github.com/stratum-hq/Stratum) directly in your Node.js app. Talks straight to PostgreSQL with no HTTP server in between — maximum performance for tenant operations.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @stratum-hq/lib @stratum-hq/core pg
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```typescript
14
+ import { Pool } from "pg";
15
+ import { Stratum } from "@stratum-hq/lib";
16
+
17
+ const pool = new Pool({ connectionString: process.env.DATABASE_URL });
18
+ const stratum = new Stratum({ pool, autoMigrate: true });
19
+ await stratum.initialize();
20
+
21
+ const msp = await stratum.createTenant({ name: "NorthStar MSP", slug: "northstar" });
22
+ const customer = await stratum.createTenant({
23
+ name: "Acme Corp",
24
+ slug: "acme",
25
+ parent_id: msp.id,
26
+ isolation_strategy: "SHARED_RLS",
27
+ });
28
+
29
+ // Config flows root → leaf — children inherit automatically
30
+ await stratum.setConfig(msp.id, "max_seats", { value: 500, locked: true });
31
+ const config = await stratum.resolveConfig(customer.id);
32
+ // → { max_seats: { value: 500, inherited: true, locked: true } }
33
+
34
+ const permissions = await stratum.resolvePermissions(customer.id);
35
+ ```
36
+
37
+ The `pool` is **borrowed, not owned** — Stratum never creates or closes it. With `autoMigrate: true`, `initialize()` runs the schema migrations on first start; leave it off and manage migrations yourself via `migrate`.
38
+
39
+ ## API Summary
40
+
41
+ The `Stratum` instance covers the full tenant lifecycle:
42
+
43
+ - **Tenants** — `createTenant`, `getTenant`, `listTenants`, `updateTenant`, `moveTenant`, `getAncestors`, `getDescendants`, `batchCreateTenants`
44
+ - **Config** — `resolveConfig`, `setConfig`, `deleteConfig`, `batchSetConfig`, `diffConfig`
45
+ - **Permissions & ABAC** — `resolvePermissions`, `createPermission`, `createAbacPolicy`, `evaluateAbac`
46
+ - **API keys & roles** — `createApiKey`, `validateApiKey`, `rotateApiKey`, `createRole`, `assignRoleToKey`
47
+ - **Webhooks & audit** — `createWebhook`, `testWebhook`, `queryAuditLogs`, `listFailedDeliveries`
48
+ - **GDPR & regions** — `exportTenantData`, `purgeTenant`, `grantConsent`, `createRegion`, `migrateRegion`
49
+
50
+ Low-level pool helpers are also exported:
51
+
52
+ ```typescript
53
+ import { withClient, withTransaction } from "@stratum-hq/lib";
54
+
55
+ await withTransaction(pool, async (client) => {
56
+ await client.query("INSERT INTO ...");
57
+ });
58
+ ```
59
+
60
+ ## Error Handling
61
+
62
+ All errors come from `@stratum-hq/core` and extend `StratumError`:
63
+
64
+ ```typescript
65
+ import { ConfigLockedError } from "@stratum-hq/core";
66
+
67
+ try {
68
+ await stratum.setConfig(childId, "max_seats", { value: 999 });
69
+ } catch (err) {
70
+ if (err instanceof ConfigLockedError) {
71
+ // A parent locked this key — child cannot override
72
+ }
73
+ }
74
+ ```
75
+
76
+ ## Links
77
+
78
+ - Documentation: https://docs.stratum-hq.org/packages/lib/
79
+ - GitHub: https://github.com/stratum-hq/Stratum
80
+
81
+ ## License
82
+
83
+ MIT © Christian Crank
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stratum-hq/lib",
3
- "version": "0.2.4",
3
+ "version": "0.3.0",
4
4
  "description": "Stratum tenant management library - framework-agnostic business logic",
5
5
  "keywords": [
6
6
  "multi-tenancy",
@@ -61,5 +61,10 @@
61
61
  "@types/pg": "^8.11.0",
62
62
  "typescript": "^5.4.0",
63
63
  "vitest": "^1.6.0"
64
+ },
65
+ "repository": {
66
+ "type": "git",
67
+ "url": "https://github.com/stratum-hq/Stratum.git",
68
+ "directory": "packages/lib"
64
69
  }
65
70
  }