@3sixty/api-tenant-processor 0.0.0-stage → 0.20.0-next.1

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 (122) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +24 -2
  3. package/dist/es/entities/tenant.js +77 -0
  4. package/dist/es/entities/tenant.js.map +1 -0
  5. package/dist/es/entities/tenantV0.js +61 -0
  6. package/dist/es/entities/tenantV0.js.map +1 -0
  7. package/dist/es/entities/tenantV1.js +77 -0
  8. package/dist/es/entities/tenantV1.js.map +1 -0
  9. package/dist/es/index.js +30 -0
  10. package/dist/es/index.js.map +1 -0
  11. package/dist/es/models/ISingleTenantProcessorConfig.js +4 -0
  12. package/dist/es/models/ISingleTenantProcessorConfig.js.map +1 -0
  13. package/dist/es/models/ISingleTenantProcessorConstructorOptions.js +2 -0
  14. package/dist/es/models/ISingleTenantProcessorConstructorOptions.js.map +1 -0
  15. package/dist/es/models/ITenantAdminServiceConfig.js +4 -0
  16. package/dist/es/models/ITenantAdminServiceConfig.js.map +1 -0
  17. package/dist/es/models/ITenantAdminServiceConstructorOptions.js +2 -0
  18. package/dist/es/models/ITenantAdminServiceConstructorOptions.js.map +1 -0
  19. package/dist/es/models/ITenantProcessorConfig.js +4 -0
  20. package/dist/es/models/ITenantProcessorConfig.js.map +1 -0
  21. package/dist/es/models/ITenantProcessorConstructorOptions.js +2 -0
  22. package/dist/es/models/ITenantProcessorConstructorOptions.js.map +1 -0
  23. package/dist/es/models/api/ITenantCreateRequest.js +2 -0
  24. package/dist/es/models/api/ITenantCreateRequest.js.map +1 -0
  25. package/dist/es/models/api/ITenantGetByApiKeyRequest.js +4 -0
  26. package/dist/es/models/api/ITenantGetByApiKeyRequest.js.map +1 -0
  27. package/dist/es/models/api/ITenantGetByIdRequest.js +4 -0
  28. package/dist/es/models/api/ITenantGetByIdRequest.js.map +1 -0
  29. package/dist/es/models/api/ITenantGetByPublicOriginRequest.js +4 -0
  30. package/dist/es/models/api/ITenantGetByPublicOriginRequest.js.map +1 -0
  31. package/dist/es/models/api/ITenantGetResponse.js +2 -0
  32. package/dist/es/models/api/ITenantGetResponse.js.map +1 -0
  33. package/dist/es/models/api/ITenantListRequest.js +4 -0
  34. package/dist/es/models/api/ITenantListRequest.js.map +1 -0
  35. package/dist/es/models/api/ITenantListResponse.js +2 -0
  36. package/dist/es/models/api/ITenantListResponse.js.map +1 -0
  37. package/dist/es/models/api/ITenantRemoveRequest.js +4 -0
  38. package/dist/es/models/api/ITenantRemoveRequest.js.map +1 -0
  39. package/dist/es/models/api/ITenantUpdateRequest.js +2 -0
  40. package/dist/es/models/api/ITenantUpdateRequest.js.map +1 -0
  41. package/dist/es/restEntryPoints.js +13 -0
  42. package/dist/es/restEntryPoints.js.map +1 -0
  43. package/dist/es/schema.js +64 -0
  44. package/dist/es/schema.js.map +1 -0
  45. package/dist/es/singleTenantProcessor.js +81 -0
  46. package/dist/es/singleTenantProcessor.js.map +1 -0
  47. package/dist/es/tenantAdminService.js +510 -0
  48. package/dist/es/tenantAdminService.js.map +1 -0
  49. package/dist/es/tenantIdContextIdHandler.js +47 -0
  50. package/dist/es/tenantIdContextIdHandler.js.map +1 -0
  51. package/dist/es/tenantProcessor.js +164 -0
  52. package/dist/es/tenantProcessor.js.map +1 -0
  53. package/dist/es/tenantRoutes.js +417 -0
  54. package/dist/es/tenantRoutes.js.map +1 -0
  55. package/dist/es/utils/tenantIdHelper.js +23 -0
  56. package/dist/es/utils/tenantIdHelper.js.map +1 -0
  57. package/dist/types/entities/tenant.d.ts +37 -0
  58. package/dist/types/entities/tenantV0.d.ts +29 -0
  59. package/dist/types/entities/tenantV1.d.ts +37 -0
  60. package/dist/types/index.d.ts +26 -0
  61. package/dist/types/models/ISingleTenantProcessorConfig.d.ts +9 -0
  62. package/dist/types/models/ISingleTenantProcessorConstructorOptions.d.ts +10 -0
  63. package/dist/types/models/ITenantAdminServiceConfig.d.ts +24 -0
  64. package/dist/types/models/ITenantAdminServiceConstructorOptions.d.ts +20 -0
  65. package/dist/types/models/ITenantProcessorConfig.d.ts +18 -0
  66. package/dist/types/models/ITenantProcessorConstructorOptions.d.ts +15 -0
  67. package/dist/types/models/api/ITenantCreateRequest.d.ts +12 -0
  68. package/dist/types/models/api/ITenantGetByApiKeyRequest.d.ts +14 -0
  69. package/dist/types/models/api/ITenantGetByIdRequest.d.ts +14 -0
  70. package/dist/types/models/api/ITenantGetByPublicOriginRequest.d.ts +14 -0
  71. package/dist/types/models/api/ITenantGetResponse.d.ts +10 -0
  72. package/dist/types/models/api/ITenantListRequest.d.ts +27 -0
  73. package/dist/types/models/api/ITenantListResponse.d.ts +17 -0
  74. package/dist/types/models/api/ITenantRemoveRequest.d.ts +14 -0
  75. package/dist/types/models/api/ITenantUpdateRequest.d.ts +19 -0
  76. package/dist/types/restEntryPoints.d.ts +5 -0
  77. package/dist/types/schema.d.ts +5 -0
  78. package/dist/types/singleTenantProcessor.d.ts +41 -0
  79. package/dist/types/tenantAdminService.d.ts +109 -0
  80. package/dist/types/tenantIdContextIdHandler.d.ts +33 -0
  81. package/dist/types/tenantProcessor.d.ts +34 -0
  82. package/dist/types/tenantRoutes.d.ts +78 -0
  83. package/dist/types/utils/tenantIdHelper.d.ts +15 -0
  84. package/docs/changelog.md +17 -0
  85. package/docs/examples.md +81 -0
  86. package/docs/reference/classes/SingleTenantProcessor.md +130 -0
  87. package/docs/reference/classes/Tenant.md +77 -0
  88. package/docs/reference/classes/TenantAdminService.md +393 -0
  89. package/docs/reference/classes/TenantIdContextIdHandler.md +123 -0
  90. package/docs/reference/classes/TenantIdHelper.md +41 -0
  91. package/docs/reference/classes/TenantProcessor.md +103 -0
  92. package/docs/reference/classes/TenantV0.md +61 -0
  93. package/docs/reference/classes/TenantV1.md +77 -0
  94. package/docs/reference/functions/generateRestRoutesTenants.md +25 -0
  95. package/docs/reference/functions/initSchema.md +10 -0
  96. package/docs/reference/functions/tenantByApiKey.md +31 -0
  97. package/docs/reference/functions/tenantById.md +31 -0
  98. package/docs/reference/functions/tenantByPublicOrigin.md +31 -0
  99. package/docs/reference/functions/tenantCreate.md +37 -0
  100. package/docs/reference/functions/tenantList.md +31 -0
  101. package/docs/reference/functions/tenantRemove.md +31 -0
  102. package/docs/reference/functions/tenantUpdate.md +31 -0
  103. package/docs/reference/index.md +47 -0
  104. package/docs/reference/interfaces/ISingleTenantProcessorConfig.md +11 -0
  105. package/docs/reference/interfaces/ISingleTenantProcessorConstructorOptions.md +11 -0
  106. package/docs/reference/interfaces/ITenantAdminServiceConfig.md +49 -0
  107. package/docs/reference/interfaces/ITenantAdminServiceConstructorOptions.md +39 -0
  108. package/docs/reference/interfaces/ITenantCreateRequest.md +17 -0
  109. package/docs/reference/interfaces/ITenantGetByApiKeyRequest.md +17 -0
  110. package/docs/reference/interfaces/ITenantGetByIdRequest.md +17 -0
  111. package/docs/reference/interfaces/ITenantGetByPublicOriginRequest.md +17 -0
  112. package/docs/reference/interfaces/ITenantGetResponse.md +11 -0
  113. package/docs/reference/interfaces/ITenantListRequest.md +36 -0
  114. package/docs/reference/interfaces/ITenantListResponse.md +23 -0
  115. package/docs/reference/interfaces/ITenantProcessorConfig.md +33 -0
  116. package/docs/reference/interfaces/ITenantProcessorConstructorOptions.md +25 -0
  117. package/docs/reference/interfaces/ITenantRemoveRequest.md +17 -0
  118. package/docs/reference/interfaces/ITenantUpdateRequest.md +25 -0
  119. package/docs/reference/variables/restEntryPoints.md +5 -0
  120. package/docs/reference/variables/tagsTenants.md +5 -0
  121. package/locales/en.json +20 -0
  122. package/package.json +57 -5
@@ -0,0 +1,78 @@
1
+ import { type ICreatedResponse, type IHttpRequestContext, type INoContentResponse, type IRestRoute, type ITag } from "@3sixty/api-models";
2
+ import type { ITenantCreateRequest } from "./models/api/ITenantCreateRequest.js";
3
+ import type { ITenantGetByApiKeyRequest } from "./models/api/ITenantGetByApiKeyRequest.js";
4
+ import type { ITenantGetByIdRequest } from "./models/api/ITenantGetByIdRequest.js";
5
+ import type { ITenantGetByPublicOriginRequest } from "./models/api/ITenantGetByPublicOriginRequest.js";
6
+ import type { ITenantGetResponse } from "./models/api/ITenantGetResponse.js";
7
+ import type { ITenantListRequest } from "./models/api/ITenantListRequest.js";
8
+ import type { ITenantListResponse } from "./models/api/ITenantListResponse.js";
9
+ import type { ITenantRemoveRequest } from "./models/api/ITenantRemoveRequest.js";
10
+ import type { ITenantUpdateRequest } from "./models/api/ITenantUpdateRequest.js";
11
+ /**
12
+ * The tag to associate with the routes.
13
+ */
14
+ export declare const tagsTenants: ITag[];
15
+ /**
16
+ * The REST routes for tenant management.
17
+ * @param baseRouteName Prefix to prepend to the paths.
18
+ * @param componentName The name of the component to use in the routes stored in the ComponentFactory.
19
+ * @returns The generated routes.
20
+ */
21
+ export declare function generateRestRoutesTenants(baseRouteName: string, componentName: string): IRestRoute[];
22
+ /**
23
+ * Get the list of tenants.
24
+ * @param httpRequestContext The request context for the API.
25
+ * @param componentName The name of the component to use in the routes.
26
+ * @param request The request.
27
+ * @returns The response object with additional http response properties.
28
+ */
29
+ export declare function tenantList(httpRequestContext: IHttpRequestContext, componentName: string, request: ITenantListRequest): Promise<ITenantListResponse>;
30
+ /**
31
+ * Get the tenant by id.
32
+ * @param httpRequestContext The request context for the API.
33
+ * @param componentName The name of the component to use in the routes.
34
+ * @param request The request.
35
+ * @returns The response object with additional http response properties.
36
+ */
37
+ export declare function tenantById(httpRequestContext: IHttpRequestContext, componentName: string, request: ITenantGetByIdRequest): Promise<ITenantGetResponse>;
38
+ /**
39
+ * Get the tenant by api key.
40
+ * @param httpRequestContext The request context for the API.
41
+ * @param componentName The name of the component to use in the routes.
42
+ * @param request The request.
43
+ * @returns The response object with additional http response properties.
44
+ */
45
+ export declare function tenantByApiKey(httpRequestContext: IHttpRequestContext, componentName: string, request: ITenantGetByApiKeyRequest): Promise<ITenantGetResponse>;
46
+ /**
47
+ * Get the tenant by public origin.
48
+ * @param httpRequestContext The request context for the API.
49
+ * @param componentName The name of the component to use in the routes.
50
+ * @param request The request.
51
+ * @returns The response object with additional http response properties.
52
+ */
53
+ export declare function tenantByPublicOrigin(httpRequestContext: IHttpRequestContext, componentName: string, request: ITenantGetByPublicOriginRequest): Promise<ITenantGetResponse>;
54
+ /**
55
+ * Remove the tenant by id.
56
+ * @param httpRequestContext The request context for the API.
57
+ * @param componentName The name of the component to use in the routes.
58
+ * @param request The request.
59
+ * @returns The response object with additional http response properties.
60
+ */
61
+ export declare function tenantRemove(httpRequestContext: IHttpRequestContext, componentName: string, request: ITenantRemoveRequest): Promise<INoContentResponse>;
62
+ /**
63
+ * Create the tenant.
64
+ * @param httpRequestContext The request context for the API.
65
+ * @param componentName The name of the component to use in the routes.
66
+ * @param request The request.
67
+ * @param baseRouteName The base route name for the tenant.
68
+ * @returns The response object with additional http response properties.
69
+ */
70
+ export declare function tenantCreate(httpRequestContext: IHttpRequestContext, componentName: string, request: ITenantCreateRequest, baseRouteName: string): Promise<ICreatedResponse>;
71
+ /**
72
+ * Update the tenant.
73
+ * @param httpRequestContext The request context for the API.
74
+ * @param componentName The name of the component to use in the routes.
75
+ * @param request The request.
76
+ * @returns The response object with additional http response properties.
77
+ */
78
+ export declare function tenantUpdate(httpRequestContext: IHttpRequestContext, componentName: string, request: ITenantUpdateRequest): Promise<INoContentResponse>;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Helper class for tenant id related operations.
3
+ */
4
+ export declare class TenantIdHelper {
5
+ /**
6
+ * Generates a new tenant ID.
7
+ * @returns A new tenant ID.
8
+ */
9
+ static generateTenantId(): string;
10
+ /**
11
+ * Generates a new API Key.
12
+ * @returns A new API Key.
13
+ */
14
+ static generateApiKey(): string;
15
+ }
@@ -0,0 +1,17 @@
1
+ # Changelog
2
+
3
+ ## [0.20.0-next.1](https://github.com/3sixtyglobal/api/compare/api-tenant-processor-v0.20.0-next.0...api-tenant-processor-v0.20.0-next.1) (2026-10-23)
4
+
5
+
6
+ ### Features
7
+
8
+ * authorization ([#51](https://github.com/3sixtyglobal/api/issues/51)) ([023ef94](https://github.com/3sixtyglobal/api/commit/023ef94925114e88522cbe6f703d9b05a202bc6d))
9
+ * publish packages under the [@3sixty](https://github.com/3sixty) namespace ([91b1822](https://github.com/3sixtyglobal/api/commit/91b1822dba38f70692087ad4643572531d6634dc))
10
+ * updated ts compile ([d9a5c86](https://github.com/3sixtyglobal/api/commit/d9a5c86ec7dd1faf3045b5cd1e0d38a4b331313d))
11
+
12
+
13
+ ### Dependencies
14
+
15
+ * The following workspace dependencies were updated
16
+ * dependencies
17
+ * @3sixty/api-models bumped from 0.20.0-next.0 to 0.20.0-next.1
@@ -0,0 +1,81 @@
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 '@3sixty/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 '@3sixty/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 '@3sixty/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 '@3sixty/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
+ ```
@@ -0,0 +1,130 @@
1
+ # Class: SingleTenantProcessor
2
+
3
+ Injects the single-tenant organization ID into every request context and validates any organization query parameter.
4
+
5
+ ## Implements
6
+
7
+ - `IBaseRouteProcessor`
8
+
9
+ ## Constructors
10
+
11
+ ### Constructor
12
+
13
+ > **new SingleTenantProcessor**(`options?`): `SingleTenantProcessor`
14
+
15
+ Create a new instance of SingleTenantProcessor.
16
+
17
+ #### Parameters
18
+
19
+ ##### options?
20
+
21
+ [`ISingleTenantProcessorConstructorOptions`](../interfaces/ISingleTenantProcessorConstructorOptions.md)
22
+
23
+ Options for the processor.
24
+
25
+ #### Returns
26
+
27
+ `SingleTenantProcessor`
28
+
29
+ ## Properties
30
+
31
+ ### CLASS\_NAME {#class_name}
32
+
33
+ > `readonly` `static` **CLASS\_NAME**: `string`
34
+
35
+ Runtime name for the class.
36
+
37
+ ## Methods
38
+
39
+ ### className() {#classname}
40
+
41
+ > **className**(): `string`
42
+
43
+ Returns the class name of the component.
44
+
45
+ #### Returns
46
+
47
+ `string`
48
+
49
+ The class name of the component.
50
+
51
+ #### Implementation of
52
+
53
+ `IBaseRouteProcessor.className`
54
+
55
+ ***
56
+
57
+ ### start() {#start}
58
+
59
+ > **start**(`nodeLoggingComponentType?`): `Promise`\<`void`\>
60
+
61
+ Cache the node organization ID from the engine context so it can be injected into each
62
+ per-request context without requiring a separate ContextIdProcessor for Organization.
63
+
64
+ #### Parameters
65
+
66
+ ##### nodeLoggingComponentType?
67
+
68
+ `string`
69
+
70
+ The node logging component type.
71
+
72
+ #### Returns
73
+
74
+ `Promise`\<`void`\>
75
+
76
+ A promise that resolves when the node organization ID has been cached.
77
+
78
+ #### Implementation of
79
+
80
+ `IBaseRouteProcessor.start`
81
+
82
+ ***
83
+
84
+ ### pre() {#pre}
85
+
86
+ > **pre**(`request`, `response`, `route`, `contextIds`, `processorState`): `Promise`\<`void`\>
87
+
88
+ Pre process the REST request for the specified route.
89
+
90
+ #### Parameters
91
+
92
+ ##### request
93
+
94
+ `IHttpServerRequest`
95
+
96
+ The incoming request.
97
+
98
+ ##### response
99
+
100
+ `IHttpResponse`
101
+
102
+ The outgoing response.
103
+
104
+ ##### route
105
+
106
+ `IBaseRoute` \| `undefined`
107
+
108
+ The route to process.
109
+
110
+ ##### contextIds
111
+
112
+ `IContextIds`
113
+
114
+ The context IDs of the request.
115
+
116
+ ##### processorState
117
+
118
+ \{\[`id`: `string`\]: `unknown`; \}
119
+
120
+ The state handed through the processors.
121
+
122
+ #### Returns
123
+
124
+ `Promise`\<`void`\>
125
+
126
+ A promise that resolves when the organization ID has been injected and any query parameter validated.
127
+
128
+ #### Implementation of
129
+
130
+ `IBaseRouteProcessor.pre`
@@ -0,0 +1,77 @@
1
+ # Class: Tenant
2
+
3
+ Class defining the storage for node tenants.
4
+
5
+ ## Constructors
6
+
7
+ ### Constructor
8
+
9
+ > **new Tenant**(): `Tenant`
10
+
11
+ #### Returns
12
+
13
+ `Tenant`
14
+
15
+ ## Properties
16
+
17
+ ### id {#id}
18
+
19
+ > **id**: `string`
20
+
21
+ The unique identifier for the tenant.
22
+
23
+ ***
24
+
25
+ ### apiKey {#apikey}
26
+
27
+ > **apiKey**: `string`
28
+
29
+ The api key for the tenant.
30
+
31
+ ***
32
+
33
+ ### label {#label}
34
+
35
+ > **label**: `string`
36
+
37
+ The label of the tenant.
38
+
39
+ ***
40
+
41
+ ### dateCreated {#datecreated}
42
+
43
+ > **dateCreated**: `string`
44
+
45
+ The date the tenant was created.
46
+
47
+ ***
48
+
49
+ ### dateModified {#datemodified}
50
+
51
+ > **dateModified**: `string`
52
+
53
+ The date the tenant was modified.
54
+
55
+ ***
56
+
57
+ ### publicOrigin? {#publicorigin}
58
+
59
+ > `optional` **publicOrigin?**: `string`
60
+
61
+ The origin available to the public for accessing the API.
62
+
63
+ ***
64
+
65
+ ### organizationId {#organizationid}
66
+
67
+ > **organizationId**: `string`
68
+
69
+ The organization id for the tenant.
70
+
71
+ ***
72
+
73
+ ### organizationIdLegacy? {#organizationidlegacy}
74
+
75
+ > `optional` **organizationIdLegacy?**: `string`[]
76
+
77
+ Optional list of organization aliases that can be used for legacy lookups, indexed format.