@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.
- package/LICENSE +201 -0
- package/README.md +24 -2
- package/dist/es/entities/tenant.js +77 -0
- package/dist/es/entities/tenant.js.map +1 -0
- package/dist/es/entities/tenantV0.js +61 -0
- package/dist/es/entities/tenantV0.js.map +1 -0
- package/dist/es/entities/tenantV1.js +77 -0
- package/dist/es/entities/tenantV1.js.map +1 -0
- package/dist/es/index.js +30 -0
- package/dist/es/index.js.map +1 -0
- package/dist/es/models/ISingleTenantProcessorConfig.js +4 -0
- package/dist/es/models/ISingleTenantProcessorConfig.js.map +1 -0
- package/dist/es/models/ISingleTenantProcessorConstructorOptions.js +2 -0
- package/dist/es/models/ISingleTenantProcessorConstructorOptions.js.map +1 -0
- package/dist/es/models/ITenantAdminServiceConfig.js +4 -0
- package/dist/es/models/ITenantAdminServiceConfig.js.map +1 -0
- package/dist/es/models/ITenantAdminServiceConstructorOptions.js +2 -0
- package/dist/es/models/ITenantAdminServiceConstructorOptions.js.map +1 -0
- package/dist/es/models/ITenantProcessorConfig.js +4 -0
- package/dist/es/models/ITenantProcessorConfig.js.map +1 -0
- package/dist/es/models/ITenantProcessorConstructorOptions.js +2 -0
- package/dist/es/models/ITenantProcessorConstructorOptions.js.map +1 -0
- package/dist/es/models/api/ITenantCreateRequest.js +2 -0
- package/dist/es/models/api/ITenantCreateRequest.js.map +1 -0
- package/dist/es/models/api/ITenantGetByApiKeyRequest.js +4 -0
- package/dist/es/models/api/ITenantGetByApiKeyRequest.js.map +1 -0
- package/dist/es/models/api/ITenantGetByIdRequest.js +4 -0
- package/dist/es/models/api/ITenantGetByIdRequest.js.map +1 -0
- package/dist/es/models/api/ITenantGetByPublicOriginRequest.js +4 -0
- package/dist/es/models/api/ITenantGetByPublicOriginRequest.js.map +1 -0
- package/dist/es/models/api/ITenantGetResponse.js +2 -0
- package/dist/es/models/api/ITenantGetResponse.js.map +1 -0
- package/dist/es/models/api/ITenantListRequest.js +4 -0
- package/dist/es/models/api/ITenantListRequest.js.map +1 -0
- package/dist/es/models/api/ITenantListResponse.js +2 -0
- package/dist/es/models/api/ITenantListResponse.js.map +1 -0
- package/dist/es/models/api/ITenantRemoveRequest.js +4 -0
- package/dist/es/models/api/ITenantRemoveRequest.js.map +1 -0
- package/dist/es/models/api/ITenantUpdateRequest.js +2 -0
- package/dist/es/models/api/ITenantUpdateRequest.js.map +1 -0
- package/dist/es/restEntryPoints.js +13 -0
- package/dist/es/restEntryPoints.js.map +1 -0
- package/dist/es/schema.js +64 -0
- package/dist/es/schema.js.map +1 -0
- package/dist/es/singleTenantProcessor.js +81 -0
- package/dist/es/singleTenantProcessor.js.map +1 -0
- package/dist/es/tenantAdminService.js +510 -0
- package/dist/es/tenantAdminService.js.map +1 -0
- package/dist/es/tenantIdContextIdHandler.js +47 -0
- package/dist/es/tenantIdContextIdHandler.js.map +1 -0
- package/dist/es/tenantProcessor.js +164 -0
- package/dist/es/tenantProcessor.js.map +1 -0
- package/dist/es/tenantRoutes.js +417 -0
- package/dist/es/tenantRoutes.js.map +1 -0
- package/dist/es/utils/tenantIdHelper.js +23 -0
- package/dist/es/utils/tenantIdHelper.js.map +1 -0
- package/dist/types/entities/tenant.d.ts +37 -0
- package/dist/types/entities/tenantV0.d.ts +29 -0
- package/dist/types/entities/tenantV1.d.ts +37 -0
- package/dist/types/index.d.ts +26 -0
- package/dist/types/models/ISingleTenantProcessorConfig.d.ts +9 -0
- package/dist/types/models/ISingleTenantProcessorConstructorOptions.d.ts +10 -0
- package/dist/types/models/ITenantAdminServiceConfig.d.ts +24 -0
- package/dist/types/models/ITenantAdminServiceConstructorOptions.d.ts +20 -0
- package/dist/types/models/ITenantProcessorConfig.d.ts +18 -0
- package/dist/types/models/ITenantProcessorConstructorOptions.d.ts +15 -0
- package/dist/types/models/api/ITenantCreateRequest.d.ts +12 -0
- package/dist/types/models/api/ITenantGetByApiKeyRequest.d.ts +14 -0
- package/dist/types/models/api/ITenantGetByIdRequest.d.ts +14 -0
- package/dist/types/models/api/ITenantGetByPublicOriginRequest.d.ts +14 -0
- package/dist/types/models/api/ITenantGetResponse.d.ts +10 -0
- package/dist/types/models/api/ITenantListRequest.d.ts +27 -0
- package/dist/types/models/api/ITenantListResponse.d.ts +17 -0
- package/dist/types/models/api/ITenantRemoveRequest.d.ts +14 -0
- package/dist/types/models/api/ITenantUpdateRequest.d.ts +19 -0
- package/dist/types/restEntryPoints.d.ts +5 -0
- package/dist/types/schema.d.ts +5 -0
- package/dist/types/singleTenantProcessor.d.ts +41 -0
- package/dist/types/tenantAdminService.d.ts +109 -0
- package/dist/types/tenantIdContextIdHandler.d.ts +33 -0
- package/dist/types/tenantProcessor.d.ts +34 -0
- package/dist/types/tenantRoutes.d.ts +78 -0
- package/dist/types/utils/tenantIdHelper.d.ts +15 -0
- package/docs/changelog.md +17 -0
- package/docs/examples.md +81 -0
- package/docs/reference/classes/SingleTenantProcessor.md +130 -0
- package/docs/reference/classes/Tenant.md +77 -0
- package/docs/reference/classes/TenantAdminService.md +393 -0
- package/docs/reference/classes/TenantIdContextIdHandler.md +123 -0
- package/docs/reference/classes/TenantIdHelper.md +41 -0
- package/docs/reference/classes/TenantProcessor.md +103 -0
- package/docs/reference/classes/TenantV0.md +61 -0
- package/docs/reference/classes/TenantV1.md +77 -0
- package/docs/reference/functions/generateRestRoutesTenants.md +25 -0
- package/docs/reference/functions/initSchema.md +10 -0
- package/docs/reference/functions/tenantByApiKey.md +31 -0
- package/docs/reference/functions/tenantById.md +31 -0
- package/docs/reference/functions/tenantByPublicOrigin.md +31 -0
- package/docs/reference/functions/tenantCreate.md +37 -0
- package/docs/reference/functions/tenantList.md +31 -0
- package/docs/reference/functions/tenantRemove.md +31 -0
- package/docs/reference/functions/tenantUpdate.md +31 -0
- package/docs/reference/index.md +47 -0
- package/docs/reference/interfaces/ISingleTenantProcessorConfig.md +11 -0
- package/docs/reference/interfaces/ISingleTenantProcessorConstructorOptions.md +11 -0
- package/docs/reference/interfaces/ITenantAdminServiceConfig.md +49 -0
- package/docs/reference/interfaces/ITenantAdminServiceConstructorOptions.md +39 -0
- package/docs/reference/interfaces/ITenantCreateRequest.md +17 -0
- package/docs/reference/interfaces/ITenantGetByApiKeyRequest.md +17 -0
- package/docs/reference/interfaces/ITenantGetByIdRequest.md +17 -0
- package/docs/reference/interfaces/ITenantGetByPublicOriginRequest.md +17 -0
- package/docs/reference/interfaces/ITenantGetResponse.md +11 -0
- package/docs/reference/interfaces/ITenantListRequest.md +36 -0
- package/docs/reference/interfaces/ITenantListResponse.md +23 -0
- package/docs/reference/interfaces/ITenantProcessorConfig.md +33 -0
- package/docs/reference/interfaces/ITenantProcessorConstructorOptions.md +25 -0
- package/docs/reference/interfaces/ITenantRemoveRequest.md +17 -0
- package/docs/reference/interfaces/ITenantUpdateRequest.md +25 -0
- package/docs/reference/variables/restEntryPoints.md +5 -0
- package/docs/reference/variables/tagsTenants.md +5 -0
- package/locales/en.json +20 -0
- package/package.json +57 -5
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// Copyright 2025 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
import { RandomHelper } from "@3sixty/core";
|
|
4
|
+
/**
|
|
5
|
+
* Helper class for tenant id related operations.
|
|
6
|
+
*/
|
|
7
|
+
export class TenantIdHelper {
|
|
8
|
+
/**
|
|
9
|
+
* Generates a new tenant ID.
|
|
10
|
+
* @returns A new tenant ID.
|
|
11
|
+
*/
|
|
12
|
+
static generateTenantId() {
|
|
13
|
+
return RandomHelper.generateUuidV7("compact");
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Generates a new API Key.
|
|
17
|
+
* @returns A new API Key.
|
|
18
|
+
*/
|
|
19
|
+
static generateApiKey() {
|
|
20
|
+
return RandomHelper.generateUuidV7("compact");
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=tenantIdHelper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tenantIdHelper.js","sources":["../../../src/utils/tenantIdHelper.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C;;GAEG;AACH,MAAM,OAAO,cAAc;IAC1B;;;OAGG;IACI,MAAM,CAAC,gBAAgB;QAC7B,OAAO,YAAY,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC;IAC/C,CAAC;IAED;;;OAGG;IACI,MAAM,CAAC,cAAc;QAC3B,OAAO,YAAY,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC;IAC/C,CAAC;CACD","sourcesContent":["// Copyright 2025 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { RandomHelper } from \"@3sixty/core\";\n\n/**\n * Helper class for tenant id related operations.\n */\nexport class TenantIdHelper {\n\t/**\n\t * Generates a new tenant ID.\n\t * @returns A new tenant ID.\n\t */\n\tpublic static generateTenantId(): string {\n\t\treturn RandomHelper.generateUuidV7(\"compact\");\n\t}\n\n\t/**\n\t * Generates a new API Key.\n\t * @returns A new API Key.\n\t */\n\tpublic static generateApiKey(): string {\n\t\treturn RandomHelper.generateUuidV7(\"compact\");\n\t}\n}\n"]}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Class defining the storage for node tenants.
|
|
3
|
+
*/
|
|
4
|
+
export declare class Tenant {
|
|
5
|
+
/**
|
|
6
|
+
* The unique identifier for the tenant.
|
|
7
|
+
*/
|
|
8
|
+
id: string;
|
|
9
|
+
/**
|
|
10
|
+
* The api key for the tenant.
|
|
11
|
+
*/
|
|
12
|
+
apiKey: string;
|
|
13
|
+
/**
|
|
14
|
+
* The label of the tenant.
|
|
15
|
+
*/
|
|
16
|
+
label: string;
|
|
17
|
+
/**
|
|
18
|
+
* The date the tenant was created.
|
|
19
|
+
*/
|
|
20
|
+
dateCreated: string;
|
|
21
|
+
/**
|
|
22
|
+
* The date the tenant was modified.
|
|
23
|
+
*/
|
|
24
|
+
dateModified: string;
|
|
25
|
+
/**
|
|
26
|
+
* The origin available to the public for accessing the API.
|
|
27
|
+
*/
|
|
28
|
+
publicOrigin?: string;
|
|
29
|
+
/**
|
|
30
|
+
* The organization id for the tenant.
|
|
31
|
+
*/
|
|
32
|
+
organizationId: string;
|
|
33
|
+
/**
|
|
34
|
+
* Optional list of organization aliases that can be used for legacy lookups, indexed format.
|
|
35
|
+
*/
|
|
36
|
+
organizationIdLegacy?: string[];
|
|
37
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Class defining the storage for node tenants.
|
|
3
|
+
*/
|
|
4
|
+
export declare class TenantV0 {
|
|
5
|
+
/**
|
|
6
|
+
* The unique identifier for the tenant.
|
|
7
|
+
*/
|
|
8
|
+
id: string;
|
|
9
|
+
/**
|
|
10
|
+
* The api key for the tenant.
|
|
11
|
+
*/
|
|
12
|
+
apiKey: string;
|
|
13
|
+
/**
|
|
14
|
+
* The label of the tenant.
|
|
15
|
+
*/
|
|
16
|
+
label: string;
|
|
17
|
+
/**
|
|
18
|
+
* The date the tenant was created.
|
|
19
|
+
*/
|
|
20
|
+
dateCreated: string;
|
|
21
|
+
/**
|
|
22
|
+
* The date the tenant was modified.
|
|
23
|
+
*/
|
|
24
|
+
dateModified: string;
|
|
25
|
+
/**
|
|
26
|
+
* The origin available to the public for accessing the API.
|
|
27
|
+
*/
|
|
28
|
+
publicOrigin?: string;
|
|
29
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Class defining the storage for node tenants.
|
|
3
|
+
*/
|
|
4
|
+
export declare class TenantV1 {
|
|
5
|
+
/**
|
|
6
|
+
* The unique identifier for the tenant.
|
|
7
|
+
*/
|
|
8
|
+
id: string;
|
|
9
|
+
/**
|
|
10
|
+
* The api key for the tenant.
|
|
11
|
+
*/
|
|
12
|
+
apiKey: string;
|
|
13
|
+
/**
|
|
14
|
+
* The label of the tenant.
|
|
15
|
+
*/
|
|
16
|
+
label: string;
|
|
17
|
+
/**
|
|
18
|
+
* The date the tenant was created.
|
|
19
|
+
*/
|
|
20
|
+
dateCreated: string;
|
|
21
|
+
/**
|
|
22
|
+
* The date the tenant was modified.
|
|
23
|
+
*/
|
|
24
|
+
dateModified: string;
|
|
25
|
+
/**
|
|
26
|
+
* The origin available to the public for accessing the API.
|
|
27
|
+
*/
|
|
28
|
+
publicOrigin?: string;
|
|
29
|
+
/**
|
|
30
|
+
* The organization id for the tenant.
|
|
31
|
+
*/
|
|
32
|
+
organizationId: string;
|
|
33
|
+
/**
|
|
34
|
+
* Optional list of organization aliases that can be used for legacy lookups, indexed format.
|
|
35
|
+
*/
|
|
36
|
+
organizationIdLegacy?: string;
|
|
37
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export * from "./entities/tenant.js";
|
|
2
|
+
export * from "./entities/tenantV0.js";
|
|
3
|
+
export * from "./entities/tenantV1.js";
|
|
4
|
+
export * from "./models/api/ITenantCreateRequest.js";
|
|
5
|
+
export * from "./models/api/ITenantGetByApiKeyRequest.js";
|
|
6
|
+
export * from "./models/api/ITenantGetByIdRequest.js";
|
|
7
|
+
export * from "./models/api/ITenantGetByPublicOriginRequest.js";
|
|
8
|
+
export * from "./models/api/ITenantGetResponse.js";
|
|
9
|
+
export * from "./models/api/ITenantListRequest.js";
|
|
10
|
+
export * from "./models/api/ITenantListResponse.js";
|
|
11
|
+
export * from "./models/api/ITenantRemoveRequest.js";
|
|
12
|
+
export * from "./models/api/ITenantUpdateRequest.js";
|
|
13
|
+
export * from "./models/ISingleTenantProcessorConfig.js";
|
|
14
|
+
export * from "./models/ISingleTenantProcessorConstructorOptions.js";
|
|
15
|
+
export * from "./models/ITenantAdminServiceConfig.js";
|
|
16
|
+
export * from "./models/ITenantAdminServiceConstructorOptions.js";
|
|
17
|
+
export * from "./models/ITenantProcessorConfig.js";
|
|
18
|
+
export * from "./models/ITenantProcessorConstructorOptions.js";
|
|
19
|
+
export * from "./restEntryPoints.js";
|
|
20
|
+
export * from "./schema.js";
|
|
21
|
+
export * from "./singleTenantProcessor.js";
|
|
22
|
+
export * from "./tenantAdminService.js";
|
|
23
|
+
export * from "./tenantIdContextIdHandler.js";
|
|
24
|
+
export * from "./tenantProcessor.js";
|
|
25
|
+
export * from "./tenantRoutes.js";
|
|
26
|
+
export * from "./utils/tenantIdHelper.js";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ISingleTenantProcessorConfig } from "./ISingleTenantProcessorConfig.js";
|
|
2
|
+
/**
|
|
3
|
+
* Options for the Single Tenant Processor constructor.
|
|
4
|
+
*/
|
|
5
|
+
export interface ISingleTenantProcessorConstructorOptions {
|
|
6
|
+
/**
|
|
7
|
+
* Configuration for the processor.
|
|
8
|
+
*/
|
|
9
|
+
config?: ISingleTenantProcessorConfig;
|
|
10
|
+
}
|
|
@@ -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,20 @@
|
|
|
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
|
+
* The component type to use for firing tenant events.
|
|
13
|
+
* @default platform
|
|
14
|
+
*/
|
|
15
|
+
platformComponentType?: string;
|
|
16
|
+
/**
|
|
17
|
+
* Configuration for the service.
|
|
18
|
+
*/
|
|
19
|
+
config?: ITenantAdminServiceConfig;
|
|
20
|
+
}
|
|
@@ -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,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,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,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,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
|
+
}
|