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

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,33 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.0.3-next.22](https://github.com/twinfoundation/api/compare/api-tenant-processor-v0.0.3-next.21...api-tenant-processor-v0.0.3-next.22) (2026-03-27)
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.21 to 0.0.3-next.22
16
+
17
+ ## [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)
18
+
19
+
20
+ ### Miscellaneous Chores
21
+
22
+ * **api-tenant-processor:** Synchronize repo versions
23
+
24
+
25
+ ### Dependencies
26
+
27
+ * The following workspace dependencies were updated
28
+ * dependencies
29
+ * @twin.org/api-models bumped from 0.0.3-next.20 to 0.0.3-next.21
30
+
3
31
  ## [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
32
 
5
33
 
@@ -311,4 +339,4 @@
311
339
  * dependencies
312
340
  * @twin.org/api-models bumped from 0.0.3-next.0 to 0.0.3-next.1
313
341
 
314
- ## @twin.org/api-tenant-processor - Changelog
342
+ ## 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
+ ```
@@ -14,7 +14,7 @@ Class defining the storage for node tenants.
14
14
 
15
15
  ## Properties
16
16
 
17
- ### id
17
+ ### id {#id}
18
18
 
19
19
  > **id**: `string`
20
20
 
@@ -22,7 +22,7 @@ The unique identifier for the tenant.
22
22
 
23
23
  ***
24
24
 
25
- ### apiKey
25
+ ### apiKey {#apikey}
26
26
 
27
27
  > **apiKey**: `string`
28
28
 
@@ -30,7 +30,7 @@ The api key for the tenant.
30
30
 
31
31
  ***
32
32
 
33
- ### label
33
+ ### label {#label}
34
34
 
35
35
  > **label**: `string`
36
36
 
@@ -38,7 +38,7 @@ The label of the tenant.
38
38
 
39
39
  ***
40
40
 
41
- ### dateCreated
41
+ ### dateCreated {#datecreated}
42
42
 
43
43
  > **dateCreated**: `string`
44
44
 
@@ -46,7 +46,7 @@ The date the tenant was created.
46
46
 
47
47
  ***
48
48
 
49
- ### dateModified
49
+ ### dateModified {#datemodified}
50
50
 
51
51
  > **dateModified**: `string`
52
52
 
@@ -54,15 +54,15 @@ The date the tenant was modified.
54
54
 
55
55
  ***
56
56
 
57
- ### publicOrigin?
57
+ ### publicOrigin? {#publicorigin}
58
58
 
59
- > `optional` **publicOrigin**: `string`
59
+ > `optional` **publicOrigin?**: `string`
60
60
 
61
61
  The origin available to the public for accessing the API.
62
62
 
63
63
  ***
64
64
 
65
- ### isNodeTenant
65
+ ### isNodeTenant {#isnodetenant}
66
66
 
67
67
  > **isNodeTenant**: `boolean`
68
68
 
@@ -28,7 +28,7 @@ The options for the connector.
28
28
 
29
29
  ## Properties
30
30
 
31
- ### CLASS\_NAME
31
+ ### CLASS\_NAME {#class_name}
32
32
 
33
33
  > `readonly` `static` **CLASS\_NAME**: `string`
34
34
 
@@ -36,7 +36,7 @@ Runtime name for the class.
36
36
 
37
37
  ## Methods
38
38
 
39
- ### className()
39
+ ### className() {#classname}
40
40
 
41
41
  > **className**(): `string`
42
42
 
@@ -54,7 +54,7 @@ The class name of the component.
54
54
 
55
55
  ***
56
56
 
57
- ### get()
57
+ ### get() {#get}
58
58
 
59
59
  > **get**(`tenantId`): `Promise`\<`ITenant`\>
60
60
 
@@ -84,7 +84,7 @@ Error if the tenant is not found.
84
84
 
85
85
  ***
86
86
 
87
- ### getByApiKey()
87
+ ### getByApiKey() {#getbyapikey}
88
88
 
89
89
  > **getByApiKey**(`apiKey`): `Promise`\<`ITenant`\>
90
90
 
@@ -114,7 +114,7 @@ Error if the tenant is not found.
114
114
 
115
115
  ***
116
116
 
117
- ### getByPublicOrigin()
117
+ ### getByPublicOrigin() {#getbypublicorigin}
118
118
 
119
119
  > **getByPublicOrigin**(`publicOrigin`): `Promise`\<`ITenant`\>
120
120
 
@@ -144,7 +144,7 @@ Error if the tenant is not found.
144
144
 
145
145
  ***
146
146
 
147
- ### create()
147
+ ### create() {#create}
148
148
 
149
149
  > **create**(`tenant`): `Promise`\<`string`\>
150
150
 
@@ -170,7 +170,7 @@ The tenant id.
170
170
 
171
171
  ***
172
172
 
173
- ### update()
173
+ ### update() {#update}
174
174
 
175
175
  > **update**(`tenant`): `Promise`\<`void`\>
176
176
 
@@ -196,7 +196,7 @@ The nothing.
196
196
 
197
197
  ***
198
198
 
199
- ### remove()
199
+ ### remove() {#remove}
200
200
 
201
201
  > **remove**(`tenantId`): `Promise`\<`void`\>
202
202
 
@@ -222,7 +222,7 @@ Nothing.
222
222
 
223
223
  ***
224
224
 
225
- ### query()
225
+ ### query() {#query}
226
226
 
227
227
  > **query**(`options?`, `cursor?`, `limit?`): `Promise`\<\{ `tenants`: `ITenant`[]; `cursor?`: `string`; \}\>
228
228
 
@@ -18,7 +18,7 @@ Context Id handler for testing as a tenant id.
18
18
 
19
19
  ## Properties
20
20
 
21
- ### CLASS\_NAME
21
+ ### CLASS\_NAME {#class_name}
22
22
 
23
23
  > `readonly` `static` **CLASS\_NAME**: `string`
24
24
 
@@ -26,7 +26,7 @@ Runtime name for the class.
26
26
 
27
27
  ## Methods
28
28
 
29
- ### className()
29
+ ### className() {#classname}
30
30
 
31
31
  > **className**(): `string`
32
32
 
@@ -44,7 +44,7 @@ The class name.
44
44
 
45
45
  ***
46
46
 
47
- ### short()
47
+ ### short() {#short}
48
48
 
49
49
  > **short**(`value`): `string`
50
50
 
@@ -70,7 +70,7 @@ Short form string.
70
70
 
71
71
  ***
72
72
 
73
- ### guard()
73
+ ### guard() {#guard}
74
74
 
75
75
  > **guard**(`value`): `void`
76
76
 
@@ -14,7 +14,7 @@ Helper class for tenant id related operations.
14
14
 
15
15
  ## Methods
16
16
 
17
- ### generateTenantId()
17
+ ### generateTenantId() {#generatetenantid}
18
18
 
19
19
  > `static` **generateTenantId**(): `string`
20
20
 
@@ -28,7 +28,7 @@ A new tenant ID.
28
28
 
29
29
  ***
30
30
 
31
- ### generateApiKey()
31
+ ### generateApiKey() {#generateapikey}
32
32
 
33
33
  > `static` **generateApiKey**(): `string`
34
34
 
@@ -28,7 +28,7 @@ Options for the processor.
28
28
 
29
29
  ## Properties
30
30
 
31
- ### CLASS\_NAME
31
+ ### CLASS\_NAME {#class_name}
32
32
 
33
33
  > `readonly` `static` **CLASS\_NAME**: `string`
34
34
 
@@ -36,7 +36,7 @@ Runtime name for the class.
36
36
 
37
37
  ## Methods
38
38
 
39
- ### className()
39
+ ### className() {#classname}
40
40
 
41
41
  > **className**(): `string`
42
42
 
@@ -54,7 +54,7 @@ The class name of the component.
54
54
 
55
55
  ***
56
56
 
57
- ### pre()
57
+ ### pre() {#pre}
58
58
 
59
59
  > **pre**(`request`, `response`, `route`, `contextIds`, `processorState`): `Promise`\<`void`\>
60
60
 
@@ -76,9 +76,9 @@ The outgoing response.
76
76
 
77
77
  ##### route
78
78
 
79
- The route to process.
79
+ `IBaseRoute` \| `undefined`
80
80
 
81
- `IBaseRoute` | `undefined`
81
+ The route to process.
82
82
 
83
83
  ##### contextIds
84
84
 
@@ -4,9 +4,9 @@ Options for the Tenant Admin Service constructor.
4
4
 
5
5
  ## Properties
6
6
 
7
- ### tenantEntityStorageType?
7
+ ### tenantEntityStorageType? {#tenantentitystoragetype}
8
8
 
9
- > `optional` **tenantEntityStorageType**: `string`
9
+ > `optional` **tenantEntityStorageType?**: `string`
10
10
 
11
11
  The entity storage for the tenants.
12
12
 
@@ -18,8 +18,8 @@ tenant
18
18
 
19
19
  ***
20
20
 
21
- ### config?
21
+ ### config? {#config}
22
22
 
23
- > `optional` **config**: [`ITenantAdminServiceConfig`](ITenantAdminServiceConfig.md)
23
+ > `optional` **config?**: [`ITenantAdminServiceConfig`](ITenantAdminServiceConfig.md)
24
24
 
25
25
  Configuration for the admin service.
@@ -4,7 +4,7 @@ The tenant to create.
4
4
 
5
5
  ## Properties
6
6
 
7
- ### body
7
+ ### body {#body}
8
8
 
9
9
  > **body**: `Omit`\<`ITenant`, `"id"` \| `"dateCreated"` \| `"dateModified"`\> & `object`
10
10
 
@@ -14,4 +14,4 @@ The tenant to create.
14
14
 
15
15
  ##### id?
16
16
 
17
- > `optional` **id**: `string`
17
+ > `optional` **id?**: `string`
@@ -4,7 +4,7 @@ The tenant to get by API key.
4
4
 
5
5
  ## Properties
6
6
 
7
- ### pathParams
7
+ ### pathParams {#pathparams}
8
8
 
9
9
  > **pathParams**: `object`
10
10
 
@@ -4,7 +4,7 @@ The tenant to get by id.
4
4
 
5
5
  ## Properties
6
6
 
7
- ### pathParams
7
+ ### pathParams {#pathparams}
8
8
 
9
9
  > **pathParams**: `object`
10
10
 
@@ -4,7 +4,7 @@ The tenant to get by public origin.
4
4
 
5
5
  ## Properties
6
6
 
7
- ### pathParams
7
+ ### pathParams {#pathparams}
8
8
 
9
9
  > **pathParams**: `object`
10
10
 
@@ -4,7 +4,7 @@ The tenant get response.
4
4
 
5
5
  ## Properties
6
6
 
7
- ### body
7
+ ### body {#body}
8
8
 
9
9
  > **body**: `ITenant`
10
10
 
@@ -4,7 +4,7 @@ The list of tenants.
4
4
 
5
5
  ## Properties
6
6
 
7
- ### query
7
+ ### query {#query}
8
8
 
9
9
  > **query**: `object`
10
10
 
@@ -12,12 +12,12 @@ The query parameters.
12
12
 
13
13
  #### cursor?
14
14
 
15
- > `optional` **cursor**: `string`
15
+ > `optional` **cursor?**: `string`
16
16
 
17
17
  The cursor to get the next chunk of tenants.
18
18
 
19
19
  #### limit?
20
20
 
21
- > `optional` **limit**: `string`
21
+ > `optional` **limit?**: `string`
22
22
 
23
23
  The number of tenants to return.
@@ -4,19 +4,19 @@ The list of tenants.
4
4
 
5
5
  ## Properties
6
6
 
7
- ### headers?
7
+ ### headers? {#headers}
8
8
 
9
- > `optional` **headers**: `object`
9
+ > `optional` **headers?**: `object`
10
10
 
11
11
  The headers which can be used to include the cursor.
12
12
 
13
13
  #### link?
14
14
 
15
- > `optional` **link**: `string` \| `string`[]
15
+ > `optional` **link?**: `string` \| `string`[]
16
16
 
17
17
  ***
18
18
 
19
- ### body
19
+ ### body {#body}
20
20
 
21
21
  > **body**: `ITenant`[]
22
22
 
@@ -4,9 +4,9 @@ Configuration for the tenant processor
4
4
 
5
5
  ## Properties
6
6
 
7
- ### apiKeyName?
7
+ ### apiKeyName? {#apikeyname}
8
8
 
9
- > `optional` **apiKeyName**: `string`
9
+ > `optional` **apiKeyName?**: `string`
10
10
 
11
11
  The key to look for in the header or query params for the api key.
12
12
 
@@ -4,9 +4,9 @@ Options for the Tenant Processor constructor.
4
4
 
5
5
  ## Properties
6
6
 
7
- ### tenantEntityStorageType?
7
+ ### tenantEntityStorageType? {#tenantentitystoragetype}
8
8
 
9
- > `optional` **tenantEntityStorageType**: `string`
9
+ > `optional` **tenantEntityStorageType?**: `string`
10
10
 
11
11
  The entity storage for the tenants.
12
12
 
@@ -18,8 +18,8 @@ tenant
18
18
 
19
19
  ***
20
20
 
21
- ### config?
21
+ ### config? {#config}
22
22
 
23
- > `optional` **config**: [`ITenantProcessorConfig`](ITenantProcessorConfig.md)
23
+ > `optional` **config?**: [`ITenantProcessorConfig`](ITenantProcessorConfig.md)
24
24
 
25
25
  Configuration for the processor.
@@ -4,7 +4,7 @@ The tenant to remove by id.
4
4
 
5
5
  ## Properties
6
6
 
7
- ### pathParams
7
+ ### pathParams {#pathparams}
8
8
 
9
9
  > **pathParams**: `object`
10
10
 
@@ -4,7 +4,7 @@ The tenant to update.
4
4
 
5
5
  ## Properties
6
6
 
7
- ### pathParams
7
+ ### pathParams {#pathparams}
8
8
 
9
9
  > **pathParams**: `object`
10
10
 
@@ -18,7 +18,7 @@ The id of the tenant to update.
18
18
 
19
19
  ***
20
20
 
21
- ### body
21
+ ### body {#body}
22
22
 
23
23
  > **body**: `Omit`\<`ITenant`, `"id"` \| `"dateCreated"` \| `"dateModified"`\>
24
24
 
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.22",
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.22",
18
18
  "@twin.org/context": "next",
19
19
  "@twin.org/core": "next",
20
20
  "@twin.org/entity": "next",