@stratum-hq/sdk 0.2.3 → 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 +77 -0
  3. package/package.json +19 -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,77 @@
1
+ # @stratum-hq/sdk
2
+
3
+ HTTP client, LRU cache, and Express/Fastify middleware for the [Stratum](https://github.com/stratum-hq/Stratum) control plane. Resolves tenant context from incoming requests and attaches it to the request object.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @stratum-hq/sdk @stratum-hq/core
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```typescript
14
+ import { stratum } from "@stratum-hq/sdk";
15
+
16
+ const s = stratum({
17
+ controlPlaneUrl: "http://localhost:3001",
18
+ apiKey: "sk_live_your_key",
19
+ });
20
+
21
+ // Express
22
+ app.use(s.middleware({ jwtClaimPath: "tenant_id" }));
23
+
24
+ // Fastify
25
+ app.register(s.plugin({ jwtClaimPath: "tenant_id" }));
26
+
27
+ // Direct client access
28
+ const ctx = await s.client.resolveTenant("tenant-uuid");
29
+ ```
30
+
31
+ Prefer the pieces individually? Import them directly:
32
+
33
+ ```typescript
34
+ import { StratumClient, expressMiddleware } from "@stratum-hq/sdk";
35
+
36
+ const client = new StratumClient({
37
+ controlPlaneUrl: "http://localhost:3001",
38
+ apiKey: "sk_live_your_key",
39
+ cache: { enabled: true, ttlMs: 60000, maxSize: 100 },
40
+ });
41
+
42
+ app.use(expressMiddleware(client, {
43
+ jwtClaimPath: "tenant_id",
44
+ jwtSecret: process.env.JWT_SECRET,
45
+ headerName: "X-Tenant-ID",
46
+ }));
47
+
48
+ app.get("/data", (req, res) => {
49
+ res.json({ tenantId: req.tenant.tenant_id, config: req.tenant.resolved_config });
50
+ });
51
+ ```
52
+
53
+ ## Features
54
+
55
+ - **`StratumClient`** — HTTP client for the control plane API (`resolveTenant`, `getTenantTree`, `createTenant`, `createWebhook`, `listRegions`, …) with a built-in LRU cache that auto-invalidates on mutations.
56
+ - **`expressMiddleware` / `fastifyPlugin`** — resolve the tenant from a JWT claim, `X-Tenant-ID` header, or custom resolvers (tried in that order), then populate `req.tenant`.
57
+ - **AsyncLocalStorage context** — `getTenantContext()` and `runWithTenantContext()` make the resolved context available to services that never see the request object.
58
+ - **Custom resolvers** — supply async functions (e.g. subdomain- or query-based) via the `resolvers` option.
59
+
60
+ JWT resolution activates only when `jwtSecret` or `jwtVerify` is provided; otherwise Bearer tokens are ignored. If no tenant is found, the middleware returns `400 MISSING_TENANT`.
61
+
62
+ ## Error Handling
63
+
64
+ The SDK throws typed errors from `@stratum-hq/core`:
65
+
66
+ ```typescript
67
+ import { TenantNotFoundError, UnauthorizedError } from "@stratum-hq/core";
68
+ ```
69
+
70
+ ## Links
71
+
72
+ - Documentation: https://docs.stratum-hq.org/packages/sdk/
73
+ - GitHub: https://github.com/stratum-hq/Stratum
74
+
75
+ ## License
76
+
77
+ MIT © Christian Crank
package/package.json CHANGED
@@ -1,7 +1,20 @@
1
1
  {
2
2
  "name": "@stratum-hq/sdk",
3
- "version": "0.2.3",
3
+ "version": "0.3.0",
4
4
  "description": "Stratum Node.js SDK for multi-tenant context propagation",
5
+ "keywords": [
6
+ "multi-tenancy",
7
+ "multi-tenant",
8
+ "saas",
9
+ "tenant",
10
+ "context-propagation",
11
+ "middleware",
12
+ "node",
13
+ "typescript",
14
+ "express",
15
+ "fastify",
16
+ "stratum"
17
+ ],
5
18
  "main": "./dist/index.js",
6
19
  "types": "./dist/index.d.ts",
7
20
  "exports": {
@@ -35,5 +48,10 @@
35
48
  "fastify": "^5.3.2",
36
49
  "typescript": "^5.4.0",
37
50
  "vitest": "^1.6.0"
51
+ },
52
+ "repository": {
53
+ "type": "git",
54
+ "url": "https://github.com/stratum-hq/Stratum.git",
55
+ "directory": "packages/sdk"
38
56
  }
39
57
  }