@3sixty/api-tenant-processor 0.0.0-stage → 0.20.0-next.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 (131) 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 +29 -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/ITenantOverrideProcessorConfig.js +4 -0
  20. package/dist/es/models/ITenantOverrideProcessorConfig.js.map +1 -0
  21. package/dist/es/models/ITenantOverrideProcessorConstructorOptions.js +2 -0
  22. package/dist/es/models/ITenantOverrideProcessorConstructorOptions.js.map +1 -0
  23. package/dist/es/models/ITenantProcessorConfig.js +4 -0
  24. package/dist/es/models/ITenantProcessorConfig.js.map +1 -0
  25. package/dist/es/models/ITenantProcessorConstructorOptions.js +2 -0
  26. package/dist/es/models/ITenantProcessorConstructorOptions.js.map +1 -0
  27. package/dist/es/models/api/ITenantCreateRequest.js +2 -0
  28. package/dist/es/models/api/ITenantCreateRequest.js.map +1 -0
  29. package/dist/es/models/api/ITenantGetByApiKeyRequest.js +4 -0
  30. package/dist/es/models/api/ITenantGetByApiKeyRequest.js.map +1 -0
  31. package/dist/es/models/api/ITenantGetByIdRequest.js +4 -0
  32. package/dist/es/models/api/ITenantGetByIdRequest.js.map +1 -0
  33. package/dist/es/models/api/ITenantGetByPublicOriginRequest.js +4 -0
  34. package/dist/es/models/api/ITenantGetByPublicOriginRequest.js.map +1 -0
  35. package/dist/es/models/api/ITenantGetResponse.js +2 -0
  36. package/dist/es/models/api/ITenantGetResponse.js.map +1 -0
  37. package/dist/es/models/api/ITenantListRequest.js +4 -0
  38. package/dist/es/models/api/ITenantListRequest.js.map +1 -0
  39. package/dist/es/models/api/ITenantListResponse.js +2 -0
  40. package/dist/es/models/api/ITenantListResponse.js.map +1 -0
  41. package/dist/es/models/api/ITenantRemoveRequest.js +4 -0
  42. package/dist/es/models/api/ITenantRemoveRequest.js.map +1 -0
  43. package/dist/es/models/api/ITenantUpdateRequest.js +2 -0
  44. package/dist/es/models/api/ITenantUpdateRequest.js.map +1 -0
  45. package/dist/es/restEntryPoints.js +13 -0
  46. package/dist/es/restEntryPoints.js.map +1 -0
  47. package/dist/es/schema.js +64 -0
  48. package/dist/es/schema.js.map +1 -0
  49. package/dist/es/singleTenantProcessor.js +81 -0
  50. package/dist/es/singleTenantProcessor.js.map +1 -0
  51. package/dist/es/tenantAdminService.js +500 -0
  52. package/dist/es/tenantAdminService.js.map +1 -0
  53. package/dist/es/tenantIdContextIdHandler.js +47 -0
  54. package/dist/es/tenantIdContextIdHandler.js.map +1 -0
  55. package/dist/es/tenantOverrideProcessor.js +119 -0
  56. package/dist/es/tenantOverrideProcessor.js.map +1 -0
  57. package/dist/es/tenantProcessor.js +164 -0
  58. package/dist/es/tenantProcessor.js.map +1 -0
  59. package/dist/es/tenantRoutes.js +404 -0
  60. package/dist/es/tenantRoutes.js.map +1 -0
  61. package/dist/es/utils/tenantIdHelper.js +23 -0
  62. package/dist/es/utils/tenantIdHelper.js.map +1 -0
  63. package/dist/types/entities/tenant.d.ts +37 -0
  64. package/dist/types/entities/tenantV0.d.ts +29 -0
  65. package/dist/types/entities/tenantV1.d.ts +37 -0
  66. package/dist/types/index.d.ts +26 -0
  67. package/dist/types/models/ISingleTenantProcessorConfig.d.ts +9 -0
  68. package/dist/types/models/ISingleTenantProcessorConstructorOptions.d.ts +10 -0
  69. package/dist/types/models/ITenantAdminServiceConfig.d.ts +24 -0
  70. package/dist/types/models/ITenantAdminServiceConstructorOptions.d.ts +15 -0
  71. package/dist/types/models/ITenantOverrideProcessorConfig.d.ts +13 -0
  72. package/dist/types/models/ITenantOverrideProcessorConstructorOptions.d.ts +15 -0
  73. package/dist/types/models/ITenantProcessorConfig.d.ts +18 -0
  74. package/dist/types/models/ITenantProcessorConstructorOptions.d.ts +15 -0
  75. package/dist/types/models/api/ITenantCreateRequest.d.ts +12 -0
  76. package/dist/types/models/api/ITenantGetByApiKeyRequest.d.ts +14 -0
  77. package/dist/types/models/api/ITenantGetByIdRequest.d.ts +14 -0
  78. package/dist/types/models/api/ITenantGetByPublicOriginRequest.d.ts +14 -0
  79. package/dist/types/models/api/ITenantGetResponse.d.ts +10 -0
  80. package/dist/types/models/api/ITenantListRequest.d.ts +27 -0
  81. package/dist/types/models/api/ITenantListResponse.d.ts +17 -0
  82. package/dist/types/models/api/ITenantRemoveRequest.d.ts +14 -0
  83. package/dist/types/models/api/ITenantUpdateRequest.d.ts +19 -0
  84. package/dist/types/restEntryPoints.d.ts +5 -0
  85. package/dist/types/schema.d.ts +5 -0
  86. package/dist/types/singleTenantProcessor.d.ts +41 -0
  87. package/dist/types/tenantAdminService.d.ts +109 -0
  88. package/dist/types/tenantIdContextIdHandler.d.ts +33 -0
  89. package/dist/types/tenantOverrideProcessor.d.ts +44 -0
  90. package/dist/types/tenantProcessor.d.ts +34 -0
  91. package/dist/types/tenantRoutes.d.ts +78 -0
  92. package/dist/types/utils/tenantIdHelper.d.ts +15 -0
  93. package/docs/changelog.md +0 -0
  94. package/docs/examples.md +81 -0
  95. package/docs/reference/classes/SingleTenantProcessor.md +128 -0
  96. package/docs/reference/classes/Tenant.md +77 -0
  97. package/docs/reference/classes/TenantAdminService.md +393 -0
  98. package/docs/reference/classes/TenantIdContextIdHandler.md +123 -0
  99. package/docs/reference/classes/TenantIdHelper.md +41 -0
  100. package/docs/reference/classes/TenantOverrideProcessor.md +119 -0
  101. package/docs/reference/classes/TenantProcessor.md +101 -0
  102. package/docs/reference/functions/generateRestRoutesTenants.md +25 -0
  103. package/docs/reference/functions/initSchema.md +10 -0
  104. package/docs/reference/functions/tenantByApiKey.md +31 -0
  105. package/docs/reference/functions/tenantById.md +31 -0
  106. package/docs/reference/functions/tenantByPublicOrigin.md +31 -0
  107. package/docs/reference/functions/tenantCreate.md +37 -0
  108. package/docs/reference/functions/tenantList.md +31 -0
  109. package/docs/reference/functions/tenantRemove.md +31 -0
  110. package/docs/reference/functions/tenantUpdate.md +31 -0
  111. package/docs/reference/index.md +47 -0
  112. package/docs/reference/interfaces/ISingleTenantProcessorConfig.md +11 -0
  113. package/docs/reference/interfaces/ISingleTenantProcessorConstructorOptions.md +11 -0
  114. package/docs/reference/interfaces/ITenantAdminServiceConfig.md +49 -0
  115. package/docs/reference/interfaces/ITenantAdminServiceConstructorOptions.md +25 -0
  116. package/docs/reference/interfaces/ITenantCreateRequest.md +17 -0
  117. package/docs/reference/interfaces/ITenantGetByApiKeyRequest.md +17 -0
  118. package/docs/reference/interfaces/ITenantGetByIdRequest.md +17 -0
  119. package/docs/reference/interfaces/ITenantGetByPublicOriginRequest.md +17 -0
  120. package/docs/reference/interfaces/ITenantGetResponse.md +11 -0
  121. package/docs/reference/interfaces/ITenantListRequest.md +36 -0
  122. package/docs/reference/interfaces/ITenantListResponse.md +23 -0
  123. package/docs/reference/interfaces/ITenantOverrideProcessorConfig.md +19 -0
  124. package/docs/reference/interfaces/ITenantOverrideProcessorConstructorOptions.md +25 -0
  125. package/docs/reference/interfaces/ITenantProcessorConfig.md +33 -0
  126. package/docs/reference/interfaces/ITenantProcessorConstructorOptions.md +25 -0
  127. package/docs/reference/interfaces/ITenantRemoveRequest.md +17 -0
  128. package/docs/reference/interfaces/ITenantUpdateRequest.md +25 -0
  129. package/docs/reference/variables/tagsTenants.md +5 -0
  130. package/locales/en.json +24 -0
  131. package/package.json +57 -5
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Configuration for the tenant admin service.
3
+ */
4
+ export interface ITenantAdminServiceConfig {
5
+ /**
6
+ * The time in milliseconds a tenant is kept in the in-memory lookup cache, counted from when it
7
+ * was read and not extended by use, set to 0 to disable caching. Entries are invalidated when a
8
+ * tenant is created, updated or removed through this service, but only in the process that made
9
+ * the change, so this is also the longest another node can serve a tenant that has been edited
10
+ * elsewhere.
11
+ * @default 30000
12
+ */
13
+ tenantCacheTtlMs?: number;
14
+ /**
15
+ * The maximum number of tenant lookups to hold in the in-memory cache.
16
+ * @default undefined (LfuCache default)
17
+ */
18
+ tenantCacheCapacity?: number;
19
+ /**
20
+ * Maximum time in milliseconds to wait for the tenant cache mutex during a cache population.
21
+ * @default undefined (LfuCache default)
22
+ */
23
+ tenantCacheMutexTimeoutMs?: number;
24
+ }
@@ -0,0 +1,15 @@
1
+ import type { ITenantAdminServiceConfig } from "./ITenantAdminServiceConfig.js";
2
+ /**
3
+ * Options for the Tenant Admin Service constructor.
4
+ */
5
+ export interface ITenantAdminServiceConstructorOptions {
6
+ /**
7
+ * The entity storage for the tenants.
8
+ * @default tenant
9
+ */
10
+ tenantEntityStorageType?: string;
11
+ /**
12
+ * Configuration for the service.
13
+ */
14
+ config?: ITenantAdminServiceConfig;
15
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Configuration for the TenantOverrideProcessor.
3
+ */
4
+ export interface ITenantOverrideProcessorConfig {
5
+ /**
6
+ * Include the stack with errors.
7
+ */
8
+ includeErrorStack?: boolean;
9
+ /**
10
+ * The scope value that grants escalated privilege for cross-tenant access. Defaults to "global-admin".
11
+ */
12
+ escalatedPrivilegeScope?: string;
13
+ }
@@ -0,0 +1,15 @@
1
+ import type { ITenantOverrideProcessorConfig } from "./ITenantOverrideProcessorConfig.js";
2
+ /**
3
+ * Options for the TenantOverrideProcessor constructor.
4
+ */
5
+ export interface ITenantOverrideProcessorConstructorOptions {
6
+ /**
7
+ * The component used to resolve tenants, which also provides the lookup caching.
8
+ * @default tenant-admin
9
+ */
10
+ tenantAdminComponentType?: string;
11
+ /**
12
+ * Configuration for the processor.
13
+ */
14
+ config?: ITenantOverrideProcessorConfig;
15
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Configuration for the tenant processor
3
+ */
4
+ export interface ITenantProcessorConfig {
5
+ /**
6
+ * The key to look for in the header or query params for the api key.
7
+ * @default x-api-key
8
+ */
9
+ apiKeyName?: string;
10
+ /**
11
+ * The list of endpoint paths that should be checked for an api key header, can be regexp strings. Defaults to ["/login$"].
12
+ */
13
+ apiKeyEndpoints?: string[];
14
+ /**
15
+ * Include the stack with errors.
16
+ */
17
+ includeErrorStack?: boolean;
18
+ }
@@ -0,0 +1,15 @@
1
+ import type { ITenantProcessorConfig } from "./ITenantProcessorConfig.js";
2
+ /**
3
+ * Options for the Tenant Processor constructor.
4
+ */
5
+ export interface ITenantProcessorConstructorOptions {
6
+ /**
7
+ * The component used to resolve tenants, which also provides the lookup caching.
8
+ * @default tenant-admin
9
+ */
10
+ tenantAdminComponentType?: string;
11
+ /**
12
+ * Configuration for the processor.
13
+ */
14
+ config?: ITenantProcessorConfig;
15
+ }
@@ -0,0 +1,12 @@
1
+ import type { ITenant } from "@3sixty/api-models";
2
+ /**
3
+ * The tenant to create.
4
+ */
5
+ export interface ITenantCreateRequest {
6
+ /**
7
+ * The tenant to create.
8
+ */
9
+ body: Omit<ITenant, "id" | "dateCreated" | "dateModified"> & {
10
+ id?: string;
11
+ };
12
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * The tenant to get by API key.
3
+ */
4
+ export interface ITenantGetByApiKeyRequest {
5
+ /**
6
+ * The path parameters.
7
+ */
8
+ pathParams: {
9
+ /**
10
+ * The API key of the tenant to get.
11
+ */
12
+ apiKey: string;
13
+ };
14
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * The tenant to get by id.
3
+ */
4
+ export interface ITenantGetByIdRequest {
5
+ /**
6
+ * The path parameters.
7
+ */
8
+ pathParams: {
9
+ /**
10
+ * The id of the tenant to get.
11
+ */
12
+ id: string;
13
+ };
14
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * The tenant to get by public origin.
3
+ */
4
+ export interface ITenantGetByPublicOriginRequest {
5
+ /**
6
+ * The path parameters.
7
+ */
8
+ pathParams: {
9
+ /**
10
+ * The public origin of the tenant to get.
11
+ */
12
+ publicOrigin: string;
13
+ };
14
+ }
@@ -0,0 +1,10 @@
1
+ import type { ITenant } from "@3sixty/api-models";
2
+ /**
3
+ * The tenant get response.
4
+ */
5
+ export interface ITenantGetResponse {
6
+ /**
7
+ * The tenant.
8
+ */
9
+ body: ITenant;
10
+ }
@@ -0,0 +1,27 @@
1
+ /**
2
+ * The list of tenants.
3
+ */
4
+ export interface ITenantListRequest {
5
+ /**
6
+ * The query parameters.
7
+ */
8
+ query: {
9
+ /**
10
+ * The condition for the query as JSON version of EntityCondition type.
11
+ */
12
+ conditions?: string;
13
+ /**
14
+ * The properties to include in the returned tenants, separated by commas.
15
+ * If not provided, all properties will be returned.
16
+ */
17
+ properties?: string;
18
+ /**
19
+ * The cursor to get the next chunk of tenants.
20
+ */
21
+ cursor?: string;
22
+ /**
23
+ * The number of tenants to return.
24
+ */
25
+ limit?: string;
26
+ };
27
+ }
@@ -0,0 +1,17 @@
1
+ import type { ITenant } from "@3sixty/api-models";
2
+ import type { HeaderTypes } from "@3sixty/web";
3
+ /**
4
+ * The list of tenants.
5
+ */
6
+ export interface ITenantListResponse {
7
+ /**
8
+ * The headers which can be used to include the cursor.
9
+ */
10
+ headers?: {
11
+ [HeaderTypes.Link]?: string | string[];
12
+ };
13
+ /**
14
+ * The list of tenants.
15
+ */
16
+ body: ITenant[];
17
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * The tenant to remove by id.
3
+ */
4
+ export interface ITenantRemoveRequest {
5
+ /**
6
+ * The path parameters.
7
+ */
8
+ pathParams: {
9
+ /**
10
+ * The id of the tenant to remove.
11
+ */
12
+ id: string;
13
+ };
14
+ }
@@ -0,0 +1,19 @@
1
+ import type { ITenant } from "@3sixty/api-models";
2
+ /**
3
+ * The tenant to update.
4
+ */
5
+ export interface ITenantUpdateRequest {
6
+ /**
7
+ * The path parameters.
8
+ */
9
+ pathParams: {
10
+ /**
11
+ * The id of the tenant to update.
12
+ */
13
+ id: string;
14
+ };
15
+ /**
16
+ * The tenant to update.
17
+ */
18
+ body: Omit<ITenant, "id" | "dateCreated" | "dateModified">;
19
+ }
@@ -0,0 +1,5 @@
1
+ import type { IRestRouteEntryPoint } from "@3sixty/api-models";
2
+ /**
3
+ * REST entry points for the tenant administration service.
4
+ */
5
+ export declare const restEntryPoints: IRestRouteEntryPoint[];
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Initialize the schema for the node tenant processor, including the Tenant 1 to 2 migration
3
+ * step which converts organizationIdLegacy from a pipe-delimited string to an array of ids.
4
+ */
5
+ export declare function initSchema(): void;
@@ -0,0 +1,41 @@
1
+ import { type IBaseRoute, type IBaseRouteProcessor, type IHttpResponse, type IHttpServerRequest } from "@3sixty/api-models";
2
+ import { type IContextIds } from "@3sixty/context";
3
+ import type { ISingleTenantProcessorConstructorOptions } from "./models/ISingleTenantProcessorConstructorOptions.js";
4
+ /**
5
+ * Injects the single-tenant organization ID into every request context and validates any organization query parameter.
6
+ */
7
+ export declare class SingleTenantProcessor implements IBaseRouteProcessor {
8
+ /**
9
+ * Runtime name for the class.
10
+ */
11
+ static readonly CLASS_NAME: string;
12
+ /**
13
+ * Create a new instance of SingleTenantProcessor.
14
+ * @param options Options for the processor.
15
+ */
16
+ constructor(options?: ISingleTenantProcessorConstructorOptions);
17
+ /**
18
+ * Returns the class name of the component.
19
+ * @returns The class name of the component.
20
+ */
21
+ className(): string;
22
+ /**
23
+ * Cache the node organization ID from the engine context so it can be injected into each
24
+ * per-request context without requiring a separate ContextIdProcessor for Organization.
25
+ * @param nodeLoggingComponentType The node logging component type.
26
+ * @returns A promise that resolves when the node organization ID has been cached.
27
+ */
28
+ start(nodeLoggingComponentType?: string): Promise<void>;
29
+ /**
30
+ * Pre process the REST request for the specified route.
31
+ * @param request The incoming request.
32
+ * @param response The outgoing response.
33
+ * @param route The route to process.
34
+ * @param contextIds The context IDs of the request.
35
+ * @param processorState The state handed through the processors.
36
+ * @returns A promise that resolves when the organization ID has been injected and any query parameter validated.
37
+ */
38
+ pre(request: IHttpServerRequest, response: IHttpResponse, route: IBaseRoute | undefined, contextIds: IContextIds, processorState: {
39
+ [id: string]: unknown;
40
+ }): Promise<void>;
41
+ }
@@ -0,0 +1,109 @@
1
+ import { type HealthApplicationCallback, type IHealth, type IHealthProviderComponent, type ITenant, type ITenantAdminComponent } from "@3sixty/api-models";
2
+ import { type IContextIds } from "@3sixty/context";
3
+ import { type EntityCondition } from "@3sixty/entity";
4
+ import type { ITenantAdminServiceConstructorOptions } from "./models/ITenantAdminServiceConstructorOptions.js";
5
+ /**
6
+ * Service for performing tenant administration operations.
7
+ */
8
+ export declare class TenantAdminService implements ITenantAdminComponent, IHealthProviderComponent {
9
+ /**
10
+ * Runtime name for the class.
11
+ */
12
+ static readonly CLASS_NAME: string;
13
+ /**
14
+ * Create a new instance of TenantAdminService.
15
+ * @param options The options for the connector.
16
+ */
17
+ constructor(options?: ITenantAdminServiceConstructorOptions);
18
+ /**
19
+ * Returns the class name of the component.
20
+ * @returns The class name of the component.
21
+ */
22
+ className(): string;
23
+ /**
24
+ * Stop the service and release the tenant cache.
25
+ * @returns A promise that resolves when the service has stopped.
26
+ */
27
+ stop(): Promise<void>;
28
+ /**
29
+ * Get a tenant by its id.
30
+ * @param tenantId The id of the tenant.
31
+ * @returns The tenant.
32
+ * @throws Error if the tenant is not found.
33
+ */
34
+ get(tenantId: string): Promise<ITenant>;
35
+ /**
36
+ * Get a tenant by its api key.
37
+ * @param apiKey The api key of the tenant.
38
+ * @returns The tenant.
39
+ * @throws Error if the tenant is not found.
40
+ */
41
+ getByApiKey(apiKey: string): Promise<ITenant>;
42
+ /**
43
+ * Get a tenant by its public origin.
44
+ * @param publicOrigin The origin of the tenant.
45
+ * @returns The tenant.
46
+ * @throws Error if the tenant is not found.
47
+ */
48
+ getByPublicOrigin(publicOrigin: string): Promise<ITenant>;
49
+ /**
50
+ * Get a tenant by its organization id, optionally searching legacy ids.
51
+ * @param organizationId The organization id of the tenant.
52
+ * @param includeLegacy Whether to also search the legacy organization id array.
53
+ * @returns The tenant.
54
+ * @throws Error if the tenant is not found.
55
+ */
56
+ getTenantByOrganizationId(organizationId: string, includeLegacy?: boolean): Promise<ITenant>;
57
+ /**
58
+ * Create a tenant.
59
+ * @param tenant The tenant to store.
60
+ * @returns The tenant id.
61
+ */
62
+ create(tenant: Omit<ITenant, "id" | "dateCreated" | "dateModified"> & {
63
+ id?: string;
64
+ }): Promise<string>;
65
+ /**
66
+ * Update a tenant.
67
+ * @param tenant The tenant to update.
68
+ * @returns A promise that resolves when the tenant has been updated.
69
+ */
70
+ update(tenant: Partial<Omit<ITenant, "dateCreated" | "dateModified">>): Promise<void>;
71
+ /**
72
+ * Remove a tenant by its id.
73
+ * @param tenantId The id of the tenant.
74
+ * @returns Nothing.
75
+ */
76
+ remove(tenantId: string): Promise<void>;
77
+ /**
78
+ * Query tenants with pagination.
79
+ * @param conditions The conditions to filter the tenants.
80
+ * @param properties The properties to include in the returned tenants.
81
+ * @param cursor The cursor to start from.
82
+ * @param limit The maximum number of tenants to return.
83
+ * @returns The tenants and the next cursor if more tenants are available.
84
+ */
85
+ query(conditions?: EntityCondition<ITenant>, properties?: (keyof ITenant)[], cursor?: string, limit?: number): Promise<{
86
+ tenants: ITenant[];
87
+ cursor?: string;
88
+ }>;
89
+ /**
90
+ * Provision a temporary tenant for the application health cycle.
91
+ * @param contextIds Accumulated context IDs; receives the provisional tenant ID.
92
+ * @returns A promise that resolves when provisioning is complete.
93
+ */
94
+ healthApplicationInit(contextIds: IContextIds): Promise<void>;
95
+ /**
96
+ * Verify the provisioned tenant can be retrieved.
97
+ * The tenant ID is read from the active context set by the init pass.
98
+ * @param callback The callback to invoke when a deferred health result is ready.
99
+ * @returns The health entries for this component.
100
+ */
101
+ healthApplication(callback: HealthApplicationCallback): Promise<IHealth[] | undefined>;
102
+ /**
103
+ * Remove the temporary tenant provisioned during init.
104
+ * The tenant ID is read from the active context set by the init pass.
105
+ * Does nothing when no tenant ID is present.
106
+ * @returns A promise that resolves when teardown is complete.
107
+ */
108
+ healthApplicationTeardown(): Promise<void>;
109
+ }
@@ -0,0 +1,33 @@
1
+ import type { IContextIdHandler } from "@3sixty/context";
2
+ /**
3
+ * Context ID handler that treats a tenant ID as a compact base64url-encoded hex string.
4
+ */
5
+ export declare class TenantIdContextIdHandler implements IContextIdHandler {
6
+ /**
7
+ * Runtime name for the class.
8
+ */
9
+ static readonly CLASS_NAME: string;
10
+ /**
11
+ * The class name of the component.
12
+ * @returns The class name.
13
+ */
14
+ className(): string;
15
+ /**
16
+ * The short form of the tenant id is the base64 version to compact.
17
+ * @param value The full context id value.
18
+ * @returns Short form string.
19
+ */
20
+ short(value: string): string;
21
+ /**
22
+ * The long form version of the context ID, expanded from a short version.
23
+ * @param value The short form context ID value.
24
+ * @returns The long form version of the context ID.
25
+ */
26
+ long(value: string): string;
27
+ /**
28
+ * Guard the value ensuring length.
29
+ * @param value The value to guard.
30
+ * @throws GeneralError if the value is too short.
31
+ */
32
+ guard(value: string): void;
33
+ }
@@ -0,0 +1,44 @@
1
+ import { type IBaseRoute, type IBaseRouteProcessor, type IHttpResponse, type IHttpServerRequest } from "@3sixty/api-models";
2
+ import { type IContextIds } from "@3sixty/context";
3
+ import type { ITenantOverrideProcessorConstructorOptions } from "./models/ITenantOverrideProcessorConstructorOptions.js";
4
+ /**
5
+ * Processes the overrideTenant query parameter for routes that allow tenant override.
6
+ * Requires the caller to hold the escalated privilege scope. Runs after AuthHeaderProcessor so
7
+ * authentication is always resolved in the caller's own partition first.
8
+ */
9
+ export declare class TenantOverrideProcessor implements IBaseRouteProcessor {
10
+ /**
11
+ * The query parameter name used to supply the override tenant ID.
12
+ */
13
+ static readonly OVERRIDE_TENANT_PARAM: string;
14
+ /**
15
+ * The scope string required to perform a tenant override.
16
+ */
17
+ static readonly DEFAULT_ESCALATED_PRIVILEGE_SCOPE: string;
18
+ /**
19
+ * Runtime name for the class.
20
+ */
21
+ static readonly CLASS_NAME: string;
22
+ /**
23
+ * Create a new instance of TenantOverrideProcessor.
24
+ * @param options Options for the processor.
25
+ */
26
+ constructor(options?: ITenantOverrideProcessorConstructorOptions);
27
+ /**
28
+ * Returns the class name of the component.
29
+ * @returns The class name of the component.
30
+ */
31
+ className(): string;
32
+ /**
33
+ * Pre process the REST request for the specified route.
34
+ * @param request The incoming request.
35
+ * @param response The outgoing response.
36
+ * @param route The route to process.
37
+ * @param contextIds The context IDs of the request.
38
+ * @param processorState The state handed through the processors.
39
+ * @returns A promise that resolves when the tenant override has been applied or skipped.
40
+ */
41
+ pre(request: IHttpServerRequest, response: IHttpResponse, route: IBaseRoute | undefined, contextIds: IContextIds, processorState: {
42
+ [id: string]: unknown;
43
+ }): Promise<void>;
44
+ }
@@ -0,0 +1,34 @@
1
+ import { type IBaseRoute, type IBaseRouteProcessor, type IHttpResponse, type IHttpServerRequest } from "@3sixty/api-models";
2
+ import { type IContextIds } from "@3sixty/context";
3
+ import type { ITenantProcessorConstructorOptions } from "./models/ITenantProcessorConstructorOptions.js";
4
+ /**
5
+ * Handles incoming api keys and maps them to tenant ids.
6
+ */
7
+ export declare class TenantProcessor implements IBaseRouteProcessor {
8
+ /**
9
+ * Runtime name for the class.
10
+ */
11
+ static readonly CLASS_NAME: string;
12
+ /**
13
+ * Create a new instance of TenantProcessor.
14
+ * @param options Options for the processor.
15
+ */
16
+ constructor(options?: ITenantProcessorConstructorOptions);
17
+ /**
18
+ * Returns the class name of the component.
19
+ * @returns The class name of the component.
20
+ */
21
+ className(): string;
22
+ /**
23
+ * Pre process the REST request for the specified route.
24
+ * @param request The incoming request.
25
+ * @param response The outgoing response.
26
+ * @param route The route to process.
27
+ * @param contextIds The context IDs of the request.
28
+ * @param processorState The state handed through the processors.
29
+ * @returns A promise that resolves when the tenant context has been resolved and injected, or an error response set.
30
+ */
31
+ pre(request: IHttpServerRequest, response: IHttpResponse, route: IBaseRoute | undefined, contextIds: IContextIds, processorState: {
32
+ [id: string]: unknown;
33
+ }): Promise<void>;
34
+ }
@@ -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
+ }
File without changes