@twin.org/api-tenant-processor 0.0.3-next.4 → 0.0.3-next.40
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 +1 -1
- package/dist/es/entities/tenant.js +17 -1
- package/dist/es/entities/tenant.js.map +1 -1
- package/dist/es/index.js +13 -2
- package/dist/es/index.js.map +1 -1
- package/dist/es/models/ITenantProcessorConfig.js.map +1 -1
- package/dist/es/models/ITenantProcessorConstructorOptions.js.map +1 -1
- package/dist/es/models/ITenantServiceConfig.js +4 -0
- package/dist/es/models/ITenantServiceConfig.js.map +1 -0
- package/dist/es/models/ITenantServiceConstructorOptions.js +2 -0
- package/dist/es/models/ITenantServiceConstructorOptions.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 +10 -0
- package/dist/es/restEntryPoints.js.map +1 -0
- package/dist/es/tenantAdminService.js +101 -16
- package/dist/es/tenantAdminService.js.map +1 -1
- package/dist/es/tenantIdContextIdHandler.js +7 -0
- package/dist/es/tenantIdContextIdHandler.js.map +1 -1
- package/dist/es/tenantProcessor.js +75 -17
- package/dist/es/tenantProcessor.js.map +1 -1
- package/dist/es/tenantRoutes.js +394 -0
- package/dist/es/tenantRoutes.js.map +1 -0
- package/dist/es/tenantService.js +51 -0
- package/dist/es/tenantService.js.map +1 -0
- package/dist/es/utils/tenantIdHelper.js +3 -3
- package/dist/es/utils/tenantIdHelper.js.map +1 -1
- package/dist/types/entities/tenant.d.ts +8 -0
- package/dist/types/index.d.ts +13 -2
- package/dist/types/models/ITenantProcessorConfig.d.ts +4 -0
- package/dist/types/models/ITenantProcessorConstructorOptions.d.ts +5 -0
- package/dist/types/models/ITenantServiceConfig.d.ts +5 -0
- package/dist/types/models/ITenantServiceConstructorOptions.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 +23 -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 +2 -0
- package/dist/types/tenantAdminService.d.ts +28 -11
- package/dist/types/tenantIdContextIdHandler.d.ts +5 -0
- package/dist/types/tenantProcessor.d.ts +1 -1
- package/dist/types/tenantRoutes.d.ts +77 -0
- package/dist/types/tenantService.d.ts +27 -0
- package/docs/changelog.md +532 -15
- package/docs/examples.md +81 -1
- package/docs/reference/classes/Tenant.md +20 -4
- package/docs/reference/classes/TenantAdminService.md +96 -26
- package/docs/reference/classes/TenantIdContextIdHandler.md +21 -3
- package/docs/reference/classes/TenantIdHelper.md +2 -2
- package/docs/reference/classes/TenantProcessor.md +6 -6
- package/docs/reference/classes/TenantService.md +79 -0
- package/docs/reference/functions/generateRestRoutesTenants.md +25 -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 +31 -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 +24 -2
- package/docs/reference/interfaces/ITenantAdminServiceConstructorOptions.md +4 -4
- 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 +30 -0
- package/docs/reference/interfaces/ITenantListResponse.md +23 -0
- package/docs/reference/interfaces/ITenantProcessorConfig.md +10 -2
- package/docs/reference/interfaces/ITenantProcessorConstructorOptions.md +18 -4
- package/docs/reference/interfaces/ITenantRemoveRequest.md +17 -0
- package/docs/reference/interfaces/ITenantServiceConfig.md +3 -0
- package/docs/reference/interfaces/ITenantServiceConstructorOptions.md +25 -0
- package/docs/reference/interfaces/ITenantUpdateRequest.md +25 -0
- package/docs/reference/variables/tagsTenants.md +5 -0
- package/locales/en.json +8 -2
- package/package.json +6 -5
- package/dist/es/models/ITenant.js +0 -4
- package/dist/es/models/ITenant.js.map +0 -1
- package/dist/es/models/ITenantAdminComponent.js +0 -2
- package/dist/es/models/ITenantAdminComponent.js.map +0 -1
- package/dist/types/models/ITenant.d.ts +0 -21
- package/dist/types/models/ITenantAdminComponent.d.ts +0 -41
- package/docs/reference/interfaces/ITenant.md +0 -35
- package/docs/reference/interfaces/ITenantAdminComponent.md +0 -123
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { ContextIdKeys, ContextIdStore } from "@twin.org/context";
|
|
2
|
+
import { Is } from "@twin.org/core";
|
|
3
|
+
import { EntityStorageConnectorFactory } from "@twin.org/entity-storage-models";
|
|
4
|
+
/**
|
|
5
|
+
* Service for performing tenant administration operations.
|
|
6
|
+
*/
|
|
7
|
+
export class TenantService {
|
|
8
|
+
/**
|
|
9
|
+
* Runtime name for the class.
|
|
10
|
+
*/
|
|
11
|
+
static CLASS_NAME = "TenantService";
|
|
12
|
+
/**
|
|
13
|
+
* Entity storage connector used by the service.
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
_entityStorageConnector;
|
|
17
|
+
/**
|
|
18
|
+
* Create a new instance of TenantService.
|
|
19
|
+
* @param options The options for the connector.
|
|
20
|
+
*/
|
|
21
|
+
constructor(options) {
|
|
22
|
+
this._entityStorageConnector = EntityStorageConnectorFactory.get(options?.tenantEntityStorageType ?? "tenant");
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Returns the class name of the component.
|
|
26
|
+
* @returns The class name of the component.
|
|
27
|
+
*/
|
|
28
|
+
className() {
|
|
29
|
+
return TenantService.CLASS_NAME;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Run a per tenant operation.
|
|
33
|
+
* @param method The method to run for each tenant.
|
|
34
|
+
* @returns Nothing.
|
|
35
|
+
*/
|
|
36
|
+
async runPerTenant(method) {
|
|
37
|
+
let cursor;
|
|
38
|
+
const contextIds = (await ContextIdStore.getContextIds()) ?? {};
|
|
39
|
+
do {
|
|
40
|
+
const result = await this._entityStorageConnector.query(undefined, undefined, ["id"], cursor);
|
|
41
|
+
for (const tenant of result.entities) {
|
|
42
|
+
contextIds[ContextIdKeys.Tenant] = tenant.id;
|
|
43
|
+
await ContextIdStore.run(contextIds, async () => {
|
|
44
|
+
await method();
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
cursor = result.cursor;
|
|
48
|
+
} while (Is.stringValue(cursor));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=tenantService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tenantService.js","sourceRoot":"","sources":["../../src/tenantService.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AACpC,OAAO,EACN,6BAA6B,EAE7B,MAAM,iCAAiC,CAAC;AAKzC;;GAEG;AACH,MAAM,OAAO,aAAa;IACzB;;OAEG;IACI,MAAM,CAAU,UAAU,mBAAmC;IAEpE;;;OAGG;IACc,uBAAuB,CAAkC;IAE1E;;;OAGG;IACH,YAAY,OAA+C;QAC1D,IAAI,CAAC,uBAAuB,GAAG,6BAA6B,CAAC,GAAG,CAC/D,OAAO,EAAE,uBAAuB,IAAI,QAAQ,CAC5C,CAAC;IACH,CAAC;IAED;;;OAGG;IACI,SAAS;QACf,OAAO,aAAa,CAAC,UAAU,CAAC;IACjC,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,YAAY,CAAC,MAA2B;QACpD,IAAI,MAA0B,CAAC;QAE/B,MAAM,UAAU,GAAG,CAAC,MAAM,cAAc,CAAC,aAAa,EAAE,CAAC,IAAI,EAAE,CAAC;QAEhE,GAAG,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,uBAAuB,CAAC,KAAK,CAAC,SAAS,EAAE,SAAS,EAAE,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,CAAC;YAE9F,KAAK,MAAM,MAAM,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC;gBACtC,UAAU,CAAC,aAAa,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,EAAE,CAAC;gBAE7C,MAAM,cAAc,CAAC,GAAG,CAAC,UAAU,EAAE,KAAK,IAAI,EAAE;oBAC/C,MAAM,MAAM,EAAE,CAAC;gBAChB,CAAC,CAAC,CAAC;YACJ,CAAC;YAED,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QACxB,CAAC,QAAQ,EAAE,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE;IAClC,CAAC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { ITenantComponent } from \"@twin.org/api-models\";\nimport { ContextIdKeys, ContextIdStore } from \"@twin.org/context\";\nimport { Is } from \"@twin.org/core\";\nimport {\n\tEntityStorageConnectorFactory,\n\ttype IEntityStorageConnector\n} from \"@twin.org/entity-storage-models\";\nimport { nameof } from \"@twin.org/nameof\";\nimport type { Tenant } from \"./entities/tenant.js\";\nimport type { ITenantAdminServiceConstructorOptions } from \"./models/ITenantAdminServiceConstructorOptions.js\";\n\n/**\n * Service for performing tenant administration operations.\n */\nexport class TenantService implements ITenantComponent {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<TenantService>();\n\n\t/**\n\t * Entity storage connector used by the service.\n\t * @internal\n\t */\n\tprivate readonly _entityStorageConnector: IEntityStorageConnector<Tenant>;\n\n\t/**\n\t * Create a new instance of TenantService.\n\t * @param options The options for the connector.\n\t */\n\tconstructor(options?: ITenantAdminServiceConstructorOptions) {\n\t\tthis._entityStorageConnector = EntityStorageConnectorFactory.get(\n\t\t\toptions?.tenantEntityStorageType ?? \"tenant\"\n\t\t);\n\t}\n\n\t/**\n\t * Returns the class name of the component.\n\t * @returns The class name of the component.\n\t */\n\tpublic className(): string {\n\t\treturn TenantService.CLASS_NAME;\n\t}\n\n\t/**\n\t * Run a per tenant operation.\n\t * @param method The method to run for each tenant.\n\t * @returns Nothing.\n\t */\n\tpublic async runPerTenant(method: () => Promise<void>): Promise<void> {\n\t\tlet cursor: string | undefined;\n\n\t\tconst contextIds = (await ContextIdStore.getContextIds()) ?? {};\n\n\t\tdo {\n\t\t\tconst result = await this._entityStorageConnector.query(undefined, undefined, [\"id\"], cursor);\n\n\t\t\tfor (const tenant of result.entities) {\n\t\t\t\tcontextIds[ContextIdKeys.Tenant] = tenant.id;\n\n\t\t\t\tawait ContextIdStore.run(contextIds, async () => {\n\t\t\t\t\tawait method();\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tcursor = result.cursor;\n\t\t} while (Is.stringValue(cursor));\n\t}\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Copyright 2025 IOTA Stiftung.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
-
import {
|
|
3
|
+
import { RandomHelper } from "@twin.org/core";
|
|
4
4
|
/**
|
|
5
5
|
* Helper class for tenant id related operations.
|
|
6
6
|
*/
|
|
@@ -10,14 +10,14 @@ export class TenantIdHelper {
|
|
|
10
10
|
* @returns A new tenant ID.
|
|
11
11
|
*/
|
|
12
12
|
static generateTenantId() {
|
|
13
|
-
return
|
|
13
|
+
return RandomHelper.generateUuidV7("compact");
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
16
16
|
* Generates a new API Key.
|
|
17
17
|
* @returns A new API Key.
|
|
18
18
|
*/
|
|
19
19
|
static generateApiKey() {
|
|
20
|
-
return
|
|
20
|
+
return RandomHelper.generateUuidV7("compact");
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
//# sourceMappingURL=tenantIdHelper.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tenantIdHelper.js","sourceRoot":"","sources":["../../../src/utils/tenantIdHelper.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"tenantIdHelper.js","sourceRoot":"","sources":["../../../src/utils/tenantIdHelper.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C;;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 \"@twin.org/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"]}
|
|
@@ -18,4 +18,12 @@ export declare class Tenant {
|
|
|
18
18
|
* The date the tenant was created.
|
|
19
19
|
*/
|
|
20
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;
|
|
21
29
|
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,12 +1,23 @@
|
|
|
1
1
|
export * from "./entities/tenant.js";
|
|
2
|
-
export * from "./models/
|
|
3
|
-
export * from "./models/
|
|
2
|
+
export * from "./models/api/ITenantCreateRequest.js";
|
|
3
|
+
export * from "./models/api/ITenantGetByApiKeyRequest.js";
|
|
4
|
+
export * from "./models/api/ITenantGetByIdRequest.js";
|
|
5
|
+
export * from "./models/api/ITenantGetByPublicOriginRequest.js";
|
|
6
|
+
export * from "./models/api/ITenantGetResponse.js";
|
|
7
|
+
export * from "./models/api/ITenantListRequest.js";
|
|
8
|
+
export * from "./models/api/ITenantListResponse.js";
|
|
9
|
+
export * from "./models/api/ITenantRemoveRequest.js";
|
|
10
|
+
export * from "./models/api/ITenantUpdateRequest.js";
|
|
4
11
|
export * from "./models/ITenantAdminServiceConfig.js";
|
|
5
12
|
export * from "./models/ITenantAdminServiceConstructorOptions.js";
|
|
6
13
|
export * from "./models/ITenantProcessorConfig.js";
|
|
7
14
|
export * from "./models/ITenantProcessorConstructorOptions.js";
|
|
15
|
+
export * from "./models/ITenantServiceConfig.js";
|
|
16
|
+
export * from "./models/ITenantServiceConstructorOptions.js";
|
|
8
17
|
export * from "./schema.js";
|
|
9
18
|
export * from "./tenantAdminService.js";
|
|
10
19
|
export * from "./tenantIdContextIdHandler.js";
|
|
11
20
|
export * from "./tenantProcessor.js";
|
|
21
|
+
export * from "./tenantRoutes.js";
|
|
22
|
+
export * from "./tenantService.js";
|
|
12
23
|
export * from "./utils/tenantIdHelper.js";
|
|
@@ -7,4 +7,8 @@ export interface ITenantProcessorConfig {
|
|
|
7
7
|
* @default x-api-key
|
|
8
8
|
*/
|
|
9
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[];
|
|
10
14
|
}
|
|
@@ -8,6 +8,11 @@ export interface ITenantProcessorConstructorOptions {
|
|
|
8
8
|
* @default tenant
|
|
9
9
|
*/
|
|
10
10
|
tenantEntityStorageType?: string;
|
|
11
|
+
/**
|
|
12
|
+
* The URL transformer component for the tenants.
|
|
13
|
+
* @default url-transformer
|
|
14
|
+
*/
|
|
15
|
+
urlTransformerComponentType?: string;
|
|
11
16
|
/**
|
|
12
17
|
* Configuration for the processor.
|
|
13
18
|
*/
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ITenantServiceConfig } from "./ITenantServiceConfig.js";
|
|
2
|
+
/**
|
|
3
|
+
* Options for the Tenant Service constructor.
|
|
4
|
+
*/
|
|
5
|
+
export interface ITenantServiceConstructorOptions {
|
|
6
|
+
/**
|
|
7
|
+
* The entity storage for the tenants.
|
|
8
|
+
* @default tenant
|
|
9
|
+
*/
|
|
10
|
+
tenantEntityStorageType?: string;
|
|
11
|
+
/**
|
|
12
|
+
* Configuration for the service.
|
|
13
|
+
*/
|
|
14
|
+
config?: ITenantServiceConfig;
|
|
15
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ITenant } from "@twin.org/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,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The list of tenants.
|
|
3
|
+
*/
|
|
4
|
+
export interface ITenantListRequest {
|
|
5
|
+
/**
|
|
6
|
+
* The query parameters.
|
|
7
|
+
*/
|
|
8
|
+
query: {
|
|
9
|
+
/**
|
|
10
|
+
* The properties to include in the returned tenants, separated by commas.
|
|
11
|
+
* If not provided, all properties will be returned.
|
|
12
|
+
*/
|
|
13
|
+
properties?: string;
|
|
14
|
+
/**
|
|
15
|
+
* The cursor to get the next chunk of tenants.
|
|
16
|
+
*/
|
|
17
|
+
cursor?: string;
|
|
18
|
+
/**
|
|
19
|
+
* The number of tenants to return.
|
|
20
|
+
*/
|
|
21
|
+
limit?: string;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ITenant } from "@twin.org/api-models";
|
|
2
|
+
import type { HeaderTypes } from "@twin.org/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 "@twin.org/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
|
+
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import type { ITenant } from "
|
|
2
|
-
import type { ITenantAdminComponent } from "./models/ITenantAdminComponent.js";
|
|
1
|
+
import type { ITenant, ITenantAdminComponent } from "@twin.org/api-models";
|
|
3
2
|
import type { ITenantAdminServiceConstructorOptions } from "./models/ITenantAdminServiceConstructorOptions.js";
|
|
4
3
|
/**
|
|
5
|
-
* Service for performing
|
|
4
|
+
* Service for performing tenant administration operations.
|
|
6
5
|
*/
|
|
7
6
|
export declare class TenantAdminService implements ITenantAdminComponent {
|
|
8
7
|
/**
|
|
@@ -22,21 +21,38 @@ export declare class TenantAdminService implements ITenantAdminComponent {
|
|
|
22
21
|
/**
|
|
23
22
|
* Get a tenant by its id.
|
|
24
23
|
* @param tenantId The id of the tenant.
|
|
25
|
-
* @returns The tenant
|
|
24
|
+
* @returns The tenant.
|
|
25
|
+
* @throws Error if the tenant is not found.
|
|
26
26
|
*/
|
|
27
|
-
get(tenantId: string): Promise<ITenant
|
|
27
|
+
get(tenantId: string): Promise<ITenant>;
|
|
28
28
|
/**
|
|
29
29
|
* Get a tenant by its api key.
|
|
30
30
|
* @param apiKey The api key of the tenant.
|
|
31
|
-
* @returns The tenant
|
|
31
|
+
* @returns The tenant.
|
|
32
|
+
* @throws Error if the tenant is not found.
|
|
32
33
|
*/
|
|
33
|
-
getByApiKey(apiKey: string): Promise<ITenant
|
|
34
|
+
getByApiKey(apiKey: string): Promise<ITenant>;
|
|
34
35
|
/**
|
|
35
|
-
*
|
|
36
|
+
* Get a tenant by its public origin.
|
|
37
|
+
* @param publicOrigin The origin of the tenant.
|
|
38
|
+
* @returns The tenant.
|
|
39
|
+
* @throws Error if the tenant is not found.
|
|
40
|
+
*/
|
|
41
|
+
getByPublicOrigin(publicOrigin: string): Promise<ITenant>;
|
|
42
|
+
/**
|
|
43
|
+
* Create a tenant.
|
|
36
44
|
* @param tenant The tenant to store.
|
|
37
|
-
* @returns
|
|
45
|
+
* @returns The tenant id.
|
|
46
|
+
*/
|
|
47
|
+
create(tenant: Omit<ITenant, "id" | "dateCreated" | "dateModified"> & {
|
|
48
|
+
id?: string;
|
|
49
|
+
}): Promise<string>;
|
|
50
|
+
/**
|
|
51
|
+
* Update a tenant.
|
|
52
|
+
* @param tenant The tenant to update.
|
|
53
|
+
* @returns The nothing.
|
|
38
54
|
*/
|
|
39
|
-
|
|
55
|
+
update(tenant: Partial<Omit<ITenant, "dateCreated" | "dateModified">>): Promise<void>;
|
|
40
56
|
/**
|
|
41
57
|
* Remove a tenant by its id.
|
|
42
58
|
* @param tenantId The id of the tenant.
|
|
@@ -45,11 +61,12 @@ export declare class TenantAdminService implements ITenantAdminComponent {
|
|
|
45
61
|
remove(tenantId: string): Promise<void>;
|
|
46
62
|
/**
|
|
47
63
|
* Query tenants with pagination.
|
|
64
|
+
* @param properties The properties to include in the returned tenants.
|
|
48
65
|
* @param cursor The cursor to start from.
|
|
49
66
|
* @param limit The maximum number of tenants to return.
|
|
50
67
|
* @returns The tenants and the next cursor if more tenants are available.
|
|
51
68
|
*/
|
|
52
|
-
query(cursor?: string, limit?: number): Promise<{
|
|
69
|
+
query(properties: (keyof ITenant)[] | undefined, cursor?: string, limit?: number): Promise<{
|
|
53
70
|
tenants: ITenant[];
|
|
54
71
|
cursor?: string;
|
|
55
72
|
}>;
|
|
@@ -7,6 +7,11 @@ export declare class TenantIdContextIdHandler implements IContextIdHandler {
|
|
|
7
7
|
* Runtime name for the class.
|
|
8
8
|
*/
|
|
9
9
|
static readonly CLASS_NAME: string;
|
|
10
|
+
/**
|
|
11
|
+
* The class name of the component.
|
|
12
|
+
* @returns The class name.
|
|
13
|
+
*/
|
|
14
|
+
className(): string;
|
|
10
15
|
/**
|
|
11
16
|
* The short form of the tenant id is the base64 version to compact.
|
|
12
17
|
* @param value The full context id value.
|
|
@@ -10,7 +10,7 @@ export declare class TenantProcessor implements IBaseRouteProcessor {
|
|
|
10
10
|
*/
|
|
11
11
|
static readonly CLASS_NAME: string;
|
|
12
12
|
/**
|
|
13
|
-
* Create a new instance of
|
|
13
|
+
* Create a new instance of TenantProcessor.
|
|
14
14
|
* @param options Options for the processor.
|
|
15
15
|
*/
|
|
16
16
|
constructor(options?: ITenantProcessorConstructorOptions);
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { type ICreatedResponse, type IHttpRequestContext, type INoContentResponse, type IRestRoute, type ITag } from "@twin.org/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
|
+
* @returns The response object with additional http response properties.
|
|
68
|
+
*/
|
|
69
|
+
export declare function tenantCreate(httpRequestContext: IHttpRequestContext, componentName: string, request: ITenantCreateRequest): Promise<ICreatedResponse>;
|
|
70
|
+
/**
|
|
71
|
+
* Update the tenant.
|
|
72
|
+
* @param httpRequestContext The request context for the API.
|
|
73
|
+
* @param componentName The name of the component to use in the routes.
|
|
74
|
+
* @param request The request.
|
|
75
|
+
* @returns The response object with additional http response properties.
|
|
76
|
+
*/
|
|
77
|
+
export declare function tenantUpdate(httpRequestContext: IHttpRequestContext, componentName: string, request: ITenantUpdateRequest): Promise<INoContentResponse>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ITenantComponent } from "@twin.org/api-models";
|
|
2
|
+
import type { ITenantAdminServiceConstructorOptions } from "./models/ITenantAdminServiceConstructorOptions.js";
|
|
3
|
+
/**
|
|
4
|
+
* Service for performing tenant administration operations.
|
|
5
|
+
*/
|
|
6
|
+
export declare class TenantService implements ITenantComponent {
|
|
7
|
+
/**
|
|
8
|
+
* Runtime name for the class.
|
|
9
|
+
*/
|
|
10
|
+
static readonly CLASS_NAME: string;
|
|
11
|
+
/**
|
|
12
|
+
* Create a new instance of TenantService.
|
|
13
|
+
* @param options The options for the connector.
|
|
14
|
+
*/
|
|
15
|
+
constructor(options?: ITenantAdminServiceConstructorOptions);
|
|
16
|
+
/**
|
|
17
|
+
* Returns the class name of the component.
|
|
18
|
+
* @returns The class name of the component.
|
|
19
|
+
*/
|
|
20
|
+
className(): string;
|
|
21
|
+
/**
|
|
22
|
+
* Run a per tenant operation.
|
|
23
|
+
* @param method The method to run for each tenant.
|
|
24
|
+
* @returns Nothing.
|
|
25
|
+
*/
|
|
26
|
+
runPerTenant(method: () => Promise<void>): Promise<void>;
|
|
27
|
+
}
|