@twin.org/api-tenant-processor 0.0.3-next.20 → 0.0.3-next.21

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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # TWIN API Tenant Processor
2
2
 
3
- Will read `x-api-key` from HTTP header or query params and convert it to a tenant id, to be used for partitioning data.
3
+ This package provides tenant resolution services and route handlers that derive tenant context from API keys.
4
4
 
5
5
  ## Installation
6
6
 
package/docs/changelog.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.0.3-next.21](https://github.com/twinfoundation/api/compare/api-tenant-processor-v0.0.3-next.20...api-tenant-processor-v0.0.3-next.21) (2026-03-11)
4
+
5
+
6
+ ### Miscellaneous Chores
7
+
8
+ * **api-tenant-processor:** Synchronize repo versions
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * The following workspace dependencies were updated
14
+ * dependencies
15
+ * @twin.org/api-models bumped from 0.0.3-next.20 to 0.0.3-next.21
16
+
3
17
  ## [0.0.3-next.20](https://github.com/twinfoundation/api/compare/api-tenant-processor-v0.0.3-next.19...api-tenant-processor-v0.0.3-next.20) (2026-02-09)
4
18
 
5
19
 
@@ -311,4 +325,4 @@
311
325
  * dependencies
312
326
  * @twin.org/api-models bumped from 0.0.3-next.0 to 0.0.3-next.1
313
327
 
314
- ## @twin.org/api-tenant-processor - Changelog
328
+ ## Changelog
package/docs/examples.md CHANGED
@@ -1 +1,81 @@
1
- # @twin.org/api-tenant-processor - Examples
1
+ # Tenant Processor Examples
2
+
3
+ These snippets show tenant lifecycle management and request context routing for multi-tenant deployments.
4
+
5
+ ## TenantAdminService
6
+
7
+ ```typescript
8
+ import { TenantAdminService } from '@twin.org/api-tenant-processor';
9
+
10
+ const tenantAdmin = new TenantAdminService();
11
+
12
+ console.log(tenantAdmin.className()); // TenantAdminService
13
+
14
+ const createdTenantId = await tenantAdmin.create({
15
+ label: 'North Region',
16
+ apiKey: '0123456789abcdef0123456789abcdef',
17
+ publicOrigin: 'https://north.example.org'
18
+ });
19
+
20
+ await tenantAdmin.update({
21
+ id: createdTenantId,
22
+ label: 'North Region EU'
23
+ });
24
+
25
+ const byKey = await tenantAdmin.getByApiKey('0123456789abcdef0123456789abcdef');
26
+ console.log(byKey.id.length); // 32
27
+ ```
28
+
29
+ ```typescript
30
+ import { TenantAdminService } from '@twin.org/api-tenant-processor';
31
+
32
+ const tenantAdmin = new TenantAdminService();
33
+
34
+ const byId = await tenantAdmin.get('0123456789abcdef0123456789abcdef');
35
+ const byOrigin = await tenantAdmin.getByPublicOrigin('https://north.example.org');
36
+ const page = await tenantAdmin.query({ isNodeTenant: false }, '', 10);
37
+
38
+ await tenantAdmin.remove(byId.id);
39
+
40
+ console.log(byOrigin.label); // North Region EU
41
+ console.log(page.tenants.length); // 1
42
+ ```
43
+
44
+ ## TenantIdContextIdHandler
45
+
46
+ ```typescript
47
+ import { TenantIdContextIdHandler } from '@twin.org/api-tenant-processor';
48
+
49
+ const handler = new TenantIdContextIdHandler();
50
+
51
+ console.log(handler.className()); // TenantIdContextIdHandler
52
+ console.log(handler.short('0123456789abcdef0123456789abcdef')); // ASNFZ4mrze8BI0VniavN7w
53
+
54
+ handler.guard('0123456789abcdef0123456789abcdef');
55
+ ```
56
+
57
+ ## TenantProcessor
58
+
59
+ ```typescript
60
+ import { TenantProcessor } from '@twin.org/api-tenant-processor';
61
+
62
+ const tenantProcessor = new TenantProcessor();
63
+
64
+ console.log(tenantProcessor.className()); // TenantProcessor
65
+
66
+ const request = {
67
+ method: 'get',
68
+ url: '/info',
69
+ headers: {
70
+ 'x-api-key': '0123456789abcdef0123456789abcdef'
71
+ },
72
+ query: {}
73
+ };
74
+
75
+ const response = {};
76
+ const contextIds = {};
77
+ const processorState: { [id: string]: unknown } = {};
78
+
79
+ await tenantProcessor.pre(request, response, { skipTenant: false }, contextIds, processorState);
80
+ console.log(typeof contextIds.tenant); // string
81
+ ```
@@ -10,12 +10,6 @@ Options for the Tenant Admin Service constructor.
10
10
 
11
11
  The entity storage for the tenants.
12
12
 
13
- #### Default
14
-
15
- ```ts
16
- tenant
17
- ```
18
-
19
13
  ***
20
14
 
21
15
  ### config?
@@ -9,9 +9,3 @@ Configuration for the tenant processor
9
9
  > `optional` **apiKeyName**: `string`
10
10
 
11
11
  The key to look for in the header or query params for the api key.
12
-
13
- #### Default
14
-
15
- ```ts
16
- x-api-key
17
- ```
@@ -10,12 +10,6 @@ Options for the Tenant Processor constructor.
10
10
 
11
11
  The entity storage for the tenants.
12
12
 
13
- #### Default
14
-
15
- ```ts
16
- tenant
17
- ```
18
-
19
13
  ***
20
14
 
21
15
  ### config?
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@twin.org/api-tenant-processor",
3
- "version": "0.0.3-next.20",
4
- "description": "API Tenant Processor for converting and api key to a tenant id.",
3
+ "version": "0.0.3-next.21",
4
+ "description": "Tenant resolution services and route handlers that derive tenant context from API keys.",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/twinfoundation/api.git",
@@ -14,7 +14,7 @@
14
14
  "node": ">=20.0.0"
15
15
  },
16
16
  "dependencies": {
17
- "@twin.org/api-models": "0.0.3-next.20",
17
+ "@twin.org/api-models": "0.0.3-next.21",
18
18
  "@twin.org/context": "next",
19
19
  "@twin.org/core": "next",
20
20
  "@twin.org/entity": "next",