@twin.org/api-service 0.0.3-next.43 → 0.0.3-next.44
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/dist/es/index.js +3 -3
- package/dist/es/index.js.map +1 -1
- package/dist/es/models/IPlatformServiceConfig.js +4 -0
- package/dist/es/models/IPlatformServiceConfig.js.map +1 -0
- package/dist/es/models/IPlatformServiceConstructorOptions.js +2 -0
- package/dist/es/models/IPlatformServiceConstructorOptions.js.map +1 -0
- package/dist/es/platformService.js +76 -0
- package/dist/es/platformService.js.map +1 -0
- package/dist/types/index.d.ts +3 -3
- package/dist/types/models/IPlatformServiceConfig.d.ts +10 -0
- package/dist/types/models/IPlatformServiceConstructorOptions.d.ts +15 -0
- package/dist/types/platformService.d.ts +32 -0
- package/docs/changelog.md +14 -0
- package/docs/reference/classes/PlatformService.md +97 -0
- package/docs/reference/index.md +3 -3
- package/docs/reference/interfaces/IPlatformServiceConfig.md +17 -0
- package/docs/reference/interfaces/IPlatformServiceConstructorOptions.md +25 -0
- package/locales/en.json +0 -6
- package/package.json +3 -2
- package/dist/es/models/IUrlTransformerServiceConfig.js +0 -4
- package/dist/es/models/IUrlTransformerServiceConfig.js.map +0 -1
- package/dist/es/models/IUrlTransformerServiceConstructorOptions.js +0 -2
- package/dist/es/models/IUrlTransformerServiceConstructorOptions.js.map +0 -1
- package/dist/es/urlTransformerService.js +0 -256
- package/dist/es/urlTransformerService.js.map +0 -1
- package/dist/types/models/IUrlTransformerServiceConfig.d.ts +0 -19
- package/dist/types/models/IUrlTransformerServiceConstructorOptions.d.ts +0 -15
- package/dist/types/urlTransformerService.d.ts +0 -94
- package/docs/reference/classes/UrlTransformerService.md +0 -379
- package/docs/reference/interfaces/IUrlTransformerServiceConfig.md +0 -32
- package/docs/reference/interfaces/IUrlTransformerServiceConstructorOptions.md +0 -25
package/dist/es/index.js
CHANGED
|
@@ -5,14 +5,14 @@ export * from "./healthService.js";
|
|
|
5
5
|
export * from "./hostingService.js";
|
|
6
6
|
export * from "./informationRoutes.js";
|
|
7
7
|
export * from "./informationService.js";
|
|
8
|
-
export * from "./urlTransformerService.js";
|
|
9
8
|
export * from "./models/IHealthServiceConfig.js";
|
|
10
9
|
export * from "./models/IHealthServiceConstructorOptions.js";
|
|
11
10
|
export * from "./models/IHostingServiceConfig.js";
|
|
12
11
|
export * from "./models/IHostingServiceConstructorOptions.js";
|
|
13
12
|
export * from "./models/IInformationServiceConfig.js";
|
|
14
13
|
export * from "./models/IInformationServiceConstructorOptions.js";
|
|
15
|
-
export * from "./models/
|
|
16
|
-
export * from "./models/
|
|
14
|
+
export * from "./models/IPlatformServiceConfig.js";
|
|
15
|
+
export * from "./models/IPlatformServiceConstructorOptions.js";
|
|
16
|
+
export * from "./platformService.js";
|
|
17
17
|
export * from "./restEntryPoints.js";
|
|
18
18
|
//# sourceMappingURL=index.js.map
|
package/dist/es/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,kCAAkC,CAAC;AACjD,cAAc,8CAA8C,CAAC;AAC7D,cAAc,mCAAmC,CAAC;AAClD,cAAc,+CAA+C,CAAC;AAC9D,cAAc,uCAAuC,CAAC;AACtD,cAAc,mDAAmD,CAAC;AAClE,cAAc,oCAAoC,CAAC;AACnD,cAAc,gDAAgD,CAAC;AAC/D,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nexport * from \"./healthRoutes.js\";\nexport * from \"./healthService.js\";\nexport * from \"./hostingService.js\";\nexport * from \"./informationRoutes.js\";\nexport * from \"./informationService.js\";\nexport * from \"./models/IHealthServiceConfig.js\";\nexport * from \"./models/IHealthServiceConstructorOptions.js\";\nexport * from \"./models/IHostingServiceConfig.js\";\nexport * from \"./models/IHostingServiceConstructorOptions.js\";\nexport * from \"./models/IInformationServiceConfig.js\";\nexport * from \"./models/IInformationServiceConstructorOptions.js\";\nexport * from \"./models/IPlatformServiceConfig.js\";\nexport * from \"./models/IPlatformServiceConstructorOptions.js\";\nexport * from \"./platformService.js\";\nexport * from \"./restEntryPoints.js\";\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IPlatformServiceConfig.js","sourceRoot":"","sources":["../../../src/models/IPlatformServiceConfig.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * Configuration for the platform service\n */\nexport interface IPlatformServiceConfig {\n\t/**\n\t * Indicates whether the service is running in a multi-tenant environment.\n\t * @default false\n\t */\n\tisMultiTenant?: boolean;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IPlatformServiceConstructorOptions.js","sourceRoot":"","sources":["../../../src/models/IPlatformServiceConstructorOptions.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IPlatformServiceConfig } from \"./IPlatformServiceConfig.js\";\n\n/**\n * Options for the Platform Service constructor.\n */\nexport interface IPlatformServiceConstructorOptions {\n\t/**\n\t * The entity storage for the tenants.\n\t * @default tenant\n\t */\n\ttenantEntityStorageType?: string;\n\n\t/**\n\t * Configuration for the service.\n\t */\n\tconfig?: IPlatformServiceConfig;\n}\n"]}
|
|
@@ -0,0 +1,76 @@
|
|
|
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 platform operations.
|
|
6
|
+
*/
|
|
7
|
+
export class PlatformService {
|
|
8
|
+
/**
|
|
9
|
+
* Runtime name for the class.
|
|
10
|
+
*/
|
|
11
|
+
static CLASS_NAME = "PlatformService";
|
|
12
|
+
/**
|
|
13
|
+
* The type of entity storage connector to use for tenant lookups, if multi-tenant.
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
_entityStorageConnectorType;
|
|
17
|
+
/**
|
|
18
|
+
* Entity storage connector used by the service.
|
|
19
|
+
* @internal
|
|
20
|
+
*/
|
|
21
|
+
_entityStorageConnector;
|
|
22
|
+
/**
|
|
23
|
+
* Indicates whether the service is running in a multi-tenant environment.
|
|
24
|
+
* @internal
|
|
25
|
+
*/
|
|
26
|
+
_isMultiTenant;
|
|
27
|
+
/**
|
|
28
|
+
* Create a new instance of PlatformService.
|
|
29
|
+
* @param options The options for the connector.
|
|
30
|
+
*/
|
|
31
|
+
constructor(options) {
|
|
32
|
+
this._entityStorageConnectorType = options?.tenantEntityStorageType ?? "tenant";
|
|
33
|
+
this._isMultiTenant = options?.config?.isMultiTenant ?? false;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Returns the class name of the component.
|
|
37
|
+
* @returns The class name of the component.
|
|
38
|
+
*/
|
|
39
|
+
className() {
|
|
40
|
+
return PlatformService.CLASS_NAME;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Indicates whether the component is running in a multi-tenant environment.
|
|
44
|
+
* @returns True if the component is running in a multi-tenant environment, false otherwise.
|
|
45
|
+
*/
|
|
46
|
+
isMultiTenant() {
|
|
47
|
+
return this._isMultiTenant;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Execute a method, if single tenant will run once, if multi-tenant will run for each tenant.
|
|
51
|
+
* @param method The method to run for each tenant.
|
|
52
|
+
* @returns Nothing.
|
|
53
|
+
*/
|
|
54
|
+
async execute(method) {
|
|
55
|
+
if (this._isMultiTenant) {
|
|
56
|
+
if (Is.empty(this._entityStorageConnector)) {
|
|
57
|
+
this._entityStorageConnector = EntityStorageConnectorFactory.get(this._entityStorageConnectorType);
|
|
58
|
+
}
|
|
59
|
+
let cursor;
|
|
60
|
+
const baseContextIds = (await ContextIdStore.getContextIds()) ?? {};
|
|
61
|
+
do {
|
|
62
|
+
const result = await this._entityStorageConnector.query(undefined, undefined, ["id"], cursor);
|
|
63
|
+
for (const tenant of result.entities) {
|
|
64
|
+
await ContextIdStore.run({ ...baseContextIds, [ContextIdKeys.Tenant]: tenant.id }, async () => {
|
|
65
|
+
await method();
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
cursor = result.cursor;
|
|
69
|
+
} while (Is.stringValue(cursor));
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
await method();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=platformService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platformService.js","sourceRoot":"","sources":["../../src/platformService.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;AAIzC;;GAEG;AACH,MAAM,OAAO,eAAe;IAC3B;;OAEG;IACI,MAAM,CAAU,UAAU,qBAAqC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D,CAAC;gBACH,CAAC;gBAED,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;YACxB,CAAC,QAAQ,EAAE,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE;QAClC,CAAC;aAAM,CAAC;YACP,MAAM,MAAM,EAAE,CAAC;QAChB,CAAC;IACF,CAAC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IPlatformComponent, ITenant } 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 { IPlatformServiceConstructorOptions } from \"./models/IPlatformServiceConstructorOptions.js\";\n\n/**\n * Service for performing platform operations.\n */\nexport class PlatformService implements IPlatformComponent {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<PlatformService>();\n\n\t/**\n\t * The type of entity storage connector to use for tenant lookups, if multi-tenant.\n\t * @internal\n\t */\n\tprivate readonly _entityStorageConnectorType: string;\n\n\t/**\n\t * Entity storage connector used by the service.\n\t * @internal\n\t */\n\tprivate _entityStorageConnector?: IEntityStorageConnector<ITenant>;\n\n\t/**\n\t * Indicates whether the service is running in a multi-tenant environment.\n\t * @internal\n\t */\n\tprivate readonly _isMultiTenant: boolean;\n\n\t/**\n\t * Create a new instance of PlatformService.\n\t * @param options The options for the connector.\n\t */\n\tconstructor(options?: IPlatformServiceConstructorOptions) {\n\t\tthis._entityStorageConnectorType = options?.tenantEntityStorageType ?? \"tenant\";\n\t\tthis._isMultiTenant = options?.config?.isMultiTenant ?? false;\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 PlatformService.CLASS_NAME;\n\t}\n\n\t/**\n\t * Indicates whether the component is running in a multi-tenant environment.\n\t * @returns True if the component is running in a multi-tenant environment, false otherwise.\n\t */\n\tpublic isMultiTenant(): boolean {\n\t\treturn this._isMultiTenant;\n\t}\n\n\t/**\n\t * Execute a method, if single tenant will run once, if multi-tenant will run for each tenant.\n\t * @param method The method to run for each tenant.\n\t * @returns Nothing.\n\t */\n\tpublic async execute(method: () => Promise<void>): Promise<void> {\n\t\tif (this._isMultiTenant) {\n\t\t\tif (Is.empty(this._entityStorageConnector)) {\n\t\t\t\tthis._entityStorageConnector = EntityStorageConnectorFactory.get(\n\t\t\t\t\tthis._entityStorageConnectorType\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tlet cursor: string | undefined;\n\n\t\t\tconst baseContextIds = (await ContextIdStore.getContextIds()) ?? {};\n\n\t\t\tdo {\n\t\t\t\tconst result = await this._entityStorageConnector.query(\n\t\t\t\t\tundefined,\n\t\t\t\t\tundefined,\n\t\t\t\t\t[\"id\"],\n\t\t\t\t\tcursor\n\t\t\t\t);\n\n\t\t\t\tfor (const tenant of result.entities) {\n\t\t\t\t\tawait ContextIdStore.run(\n\t\t\t\t\t\t{ ...baseContextIds, [ContextIdKeys.Tenant]: tenant.id },\n\t\t\t\t\t\tasync () => {\n\t\t\t\t\t\t\tawait method();\n\t\t\t\t\t\t}\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tcursor = result.cursor;\n\t\t\t} while (Is.stringValue(cursor));\n\t\t} else {\n\t\t\tawait method();\n\t\t}\n\t}\n}\n"]}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -3,13 +3,13 @@ export * from "./healthService.js";
|
|
|
3
3
|
export * from "./hostingService.js";
|
|
4
4
|
export * from "./informationRoutes.js";
|
|
5
5
|
export * from "./informationService.js";
|
|
6
|
-
export * from "./urlTransformerService.js";
|
|
7
6
|
export * from "./models/IHealthServiceConfig.js";
|
|
8
7
|
export * from "./models/IHealthServiceConstructorOptions.js";
|
|
9
8
|
export * from "./models/IHostingServiceConfig.js";
|
|
10
9
|
export * from "./models/IHostingServiceConstructorOptions.js";
|
|
11
10
|
export * from "./models/IInformationServiceConfig.js";
|
|
12
11
|
export * from "./models/IInformationServiceConstructorOptions.js";
|
|
13
|
-
export * from "./models/
|
|
14
|
-
export * from "./models/
|
|
12
|
+
export * from "./models/IPlatformServiceConfig.js";
|
|
13
|
+
export * from "./models/IPlatformServiceConstructorOptions.js";
|
|
14
|
+
export * from "./platformService.js";
|
|
15
15
|
export * from "./restEntryPoints.js";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { IPlatformServiceConfig } from "./IPlatformServiceConfig.js";
|
|
2
|
+
/**
|
|
3
|
+
* Options for the Platform Service constructor.
|
|
4
|
+
*/
|
|
5
|
+
export interface IPlatformServiceConstructorOptions {
|
|
6
|
+
/**
|
|
7
|
+
* The entity storage for the tenants.
|
|
8
|
+
* @default tenant
|
|
9
|
+
*/
|
|
10
|
+
tenantEntityStorageType?: string;
|
|
11
|
+
/**
|
|
12
|
+
* Configuration for the service.
|
|
13
|
+
*/
|
|
14
|
+
config?: IPlatformServiceConfig;
|
|
15
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { IPlatformComponent } from "@twin.org/api-models";
|
|
2
|
+
import type { IPlatformServiceConstructorOptions } from "./models/IPlatformServiceConstructorOptions.js";
|
|
3
|
+
/**
|
|
4
|
+
* Service for performing platform operations.
|
|
5
|
+
*/
|
|
6
|
+
export declare class PlatformService implements IPlatformComponent {
|
|
7
|
+
/**
|
|
8
|
+
* Runtime name for the class.
|
|
9
|
+
*/
|
|
10
|
+
static readonly CLASS_NAME: string;
|
|
11
|
+
/**
|
|
12
|
+
* Create a new instance of PlatformService.
|
|
13
|
+
* @param options The options for the connector.
|
|
14
|
+
*/
|
|
15
|
+
constructor(options?: IPlatformServiceConstructorOptions);
|
|
16
|
+
/**
|
|
17
|
+
* Returns the class name of the component.
|
|
18
|
+
* @returns The class name of the component.
|
|
19
|
+
*/
|
|
20
|
+
className(): string;
|
|
21
|
+
/**
|
|
22
|
+
* Indicates whether the component is running in a multi-tenant environment.
|
|
23
|
+
* @returns True if the component is running in a multi-tenant environment, false otherwise.
|
|
24
|
+
*/
|
|
25
|
+
isMultiTenant(): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Execute a method, if single tenant will run once, if multi-tenant will run for each tenant.
|
|
28
|
+
* @param method The method to run for each tenant.
|
|
29
|
+
* @returns Nothing.
|
|
30
|
+
*/
|
|
31
|
+
execute(method: () => Promise<void>): Promise<void>;
|
|
32
|
+
}
|
package/docs/changelog.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.0.3-next.44](https://github.com/iotaledger/twin-api/compare/api-service-v0.0.3-next.43...api-service-v0.0.3-next.44) (2026-06-11)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* organization identifiers ([#158](https://github.com/iotaledger/twin-api/issues/158)) ([ce13244](https://github.com/iotaledger/twin-api/commit/ce13244aaacbf82d9e5f87d905e283b36ad63bbf))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Dependencies
|
|
12
|
+
|
|
13
|
+
* The following workspace dependencies were updated
|
|
14
|
+
* dependencies
|
|
15
|
+
* @twin.org/api-models bumped from 0.0.3-next.43 to 0.0.3-next.44
|
|
16
|
+
|
|
3
17
|
## [0.0.3-next.43](https://github.com/iotaledger/twin-api/compare/api-service-v0.0.3-next.42...api-service-v0.0.3-next.43) (2026-06-10)
|
|
4
18
|
|
|
5
19
|
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# Class: PlatformService
|
|
2
|
+
|
|
3
|
+
Service for performing platform operations.
|
|
4
|
+
|
|
5
|
+
## Implements
|
|
6
|
+
|
|
7
|
+
- `IPlatformComponent`
|
|
8
|
+
|
|
9
|
+
## Constructors
|
|
10
|
+
|
|
11
|
+
### Constructor
|
|
12
|
+
|
|
13
|
+
> **new PlatformService**(`options?`): `PlatformService`
|
|
14
|
+
|
|
15
|
+
Create a new instance of PlatformService.
|
|
16
|
+
|
|
17
|
+
#### Parameters
|
|
18
|
+
|
|
19
|
+
##### options?
|
|
20
|
+
|
|
21
|
+
[`IPlatformServiceConstructorOptions`](../interfaces/IPlatformServiceConstructorOptions.md)
|
|
22
|
+
|
|
23
|
+
The options for the connector.
|
|
24
|
+
|
|
25
|
+
#### Returns
|
|
26
|
+
|
|
27
|
+
`PlatformService`
|
|
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
|
+
`IPlatformComponent.className`
|
|
54
|
+
|
|
55
|
+
***
|
|
56
|
+
|
|
57
|
+
### isMultiTenant() {#ismultitenant}
|
|
58
|
+
|
|
59
|
+
> **isMultiTenant**(): `boolean`
|
|
60
|
+
|
|
61
|
+
Indicates whether the component is running in a multi-tenant environment.
|
|
62
|
+
|
|
63
|
+
#### Returns
|
|
64
|
+
|
|
65
|
+
`boolean`
|
|
66
|
+
|
|
67
|
+
True if the component is running in a multi-tenant environment, false otherwise.
|
|
68
|
+
|
|
69
|
+
#### Implementation of
|
|
70
|
+
|
|
71
|
+
`IPlatformComponent.isMultiTenant`
|
|
72
|
+
|
|
73
|
+
***
|
|
74
|
+
|
|
75
|
+
### execute() {#execute}
|
|
76
|
+
|
|
77
|
+
> **execute**(`method`): `Promise`\<`void`\>
|
|
78
|
+
|
|
79
|
+
Execute a method, if single tenant will run once, if multi-tenant will run for each tenant.
|
|
80
|
+
|
|
81
|
+
#### Parameters
|
|
82
|
+
|
|
83
|
+
##### method
|
|
84
|
+
|
|
85
|
+
() => `Promise`\<`void`\>
|
|
86
|
+
|
|
87
|
+
The method to run for each tenant.
|
|
88
|
+
|
|
89
|
+
#### Returns
|
|
90
|
+
|
|
91
|
+
`Promise`\<`void`\>
|
|
92
|
+
|
|
93
|
+
Nothing.
|
|
94
|
+
|
|
95
|
+
#### Implementation of
|
|
96
|
+
|
|
97
|
+
`IPlatformComponent.execute`
|
package/docs/reference/index.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
- [HealthService](classes/HealthService.md)
|
|
6
6
|
- [HostingService](classes/HostingService.md)
|
|
7
7
|
- [InformationService](classes/InformationService.md)
|
|
8
|
-
- [
|
|
8
|
+
- [PlatformService](classes/PlatformService.md)
|
|
9
9
|
|
|
10
10
|
## Interfaces
|
|
11
11
|
|
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
- [IHostingServiceConstructorOptions](interfaces/IHostingServiceConstructorOptions.md)
|
|
16
16
|
- [IInformationServiceConfig](interfaces/IInformationServiceConfig.md)
|
|
17
17
|
- [IInformationServiceConstructorOptions](interfaces/IInformationServiceConstructorOptions.md)
|
|
18
|
-
- [
|
|
19
|
-
- [
|
|
18
|
+
- [IPlatformServiceConfig](interfaces/IPlatformServiceConfig.md)
|
|
19
|
+
- [IPlatformServiceConstructorOptions](interfaces/IPlatformServiceConstructorOptions.md)
|
|
20
20
|
|
|
21
21
|
## Variables
|
|
22
22
|
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Interface: IPlatformServiceConfig
|
|
2
|
+
|
|
3
|
+
Configuration for the platform service
|
|
4
|
+
|
|
5
|
+
## Properties
|
|
6
|
+
|
|
7
|
+
### isMultiTenant? {#ismultitenant}
|
|
8
|
+
|
|
9
|
+
> `optional` **isMultiTenant?**: `boolean`
|
|
10
|
+
|
|
11
|
+
Indicates whether the service is running in a multi-tenant environment.
|
|
12
|
+
|
|
13
|
+
#### Default
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
false
|
|
17
|
+
```
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Interface: IPlatformServiceConstructorOptions
|
|
2
|
+
|
|
3
|
+
Options for the Platform Service constructor.
|
|
4
|
+
|
|
5
|
+
## Properties
|
|
6
|
+
|
|
7
|
+
### tenantEntityStorageType? {#tenantentitystoragetype}
|
|
8
|
+
|
|
9
|
+
> `optional` **tenantEntityStorageType?**: `string`
|
|
10
|
+
|
|
11
|
+
The entity storage for the tenants.
|
|
12
|
+
|
|
13
|
+
#### Default
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
tenant
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
***
|
|
20
|
+
|
|
21
|
+
### config? {#config}
|
|
22
|
+
|
|
23
|
+
> `optional` **config?**: [`IPlatformServiceConfig`](IPlatformServiceConfig.md)
|
|
24
|
+
|
|
25
|
+
Configuration for the service.
|
package/locales/en.json
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
{
|
|
2
2
|
"error": {
|
|
3
|
-
"urlTransformerService": {
|
|
4
|
-
"encryptionUnavailable": "Encryption is unavailable because no nodeId is configured",
|
|
5
|
-
"decryptionUnavailable": "Decryption is unavailable because no nodeId is configured",
|
|
6
|
-
"encryptionFailed": "An error occurred during encryption",
|
|
7
|
-
"decryptionFailed": "An error occurred during decryption"
|
|
8
|
-
},
|
|
9
3
|
"healthService": {
|
|
10
4
|
"componentHealthCheckFailed": "Health check failed for component \"{className}\""
|
|
11
5
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twin.org/api-service",
|
|
3
|
-
"version": "0.0.3-next.
|
|
3
|
+
"version": "0.0.3-next.44",
|
|
4
4
|
"description": "Information and hosting service implementations with generated REST route handlers.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -14,10 +14,11 @@
|
|
|
14
14
|
"node": ">=20.0.0"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@twin.org/api-models": "0.0.3-next.
|
|
17
|
+
"@twin.org/api-models": "0.0.3-next.44",
|
|
18
18
|
"@twin.org/context": "next",
|
|
19
19
|
"@twin.org/core": "next",
|
|
20
20
|
"@twin.org/engine-models": "next",
|
|
21
|
+
"@twin.org/entity-storage-models": "next",
|
|
21
22
|
"@twin.org/logging-models": "next",
|
|
22
23
|
"@twin.org/nameof": "next",
|
|
23
24
|
"@twin.org/vault-models": "next",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"IUrlTransformerServiceConfig.js","sourceRoot":"","sources":["../../../src/models/IUrlTransformerServiceConfig.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * Configuration for the URL transformer service.\n */\nexport interface IUrlTransformerServiceConfig {\n\t/**\n\t * The name of the key to retrieve from the vault for encryption/decryption of parameters.\n\t * @default param-encryption\n\t */\n\tparamEncryptionKeyName?: string;\n\n\t/**\n\t * A dictionary mapping logical token identifiers to their URL query parameter names.\n\t * For example: tenant => tenant-token maps the logical id \"tenant\" to the\n\t * query param \"tenant-token\". When an id is not present the id itself is used as\n\t * the param name.\n\t */\n\tqueryParamNames?: { [id: string]: string };\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"IUrlTransformerServiceConstructorOptions.js","sourceRoot":"","sources":["../../../src/models/IUrlTransformerServiceConstructorOptions.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IUrlTransformerServiceConfig } from \"./IUrlTransformerServiceConfig.js\";\n\n/**\n * Options for the UrlTransformerService constructor.\n */\nexport interface IUrlTransformerServiceConstructorOptions {\n\t/**\n\t * The vault connector type.\n\t * @default vault\n\t */\n\tvaultConnectorType?: string;\n\n\t/**\n\t * The configuration for the service.\n\t */\n\tconfig?: IUrlTransformerServiceConfig;\n}\n"]}
|
|
@@ -1,256 +0,0 @@
|
|
|
1
|
-
import { ContextIdKeys, ContextIdStore } from "@twin.org/context";
|
|
2
|
-
import { BaseError, Converter, GeneralError, Guards, Is, ObjectHelper, RandomHelper, Uint8ArrayHelper } from "@twin.org/core";
|
|
3
|
-
import { VaultConnectorFactory, VaultEncryptionType } from "@twin.org/vault-models";
|
|
4
|
-
/**
|
|
5
|
-
* The URL transformer service for encrypting and decrypting URL parameters.
|
|
6
|
-
*/
|
|
7
|
-
export class UrlTransformerService {
|
|
8
|
-
/**
|
|
9
|
-
* Runtime name for the class.
|
|
10
|
-
*/
|
|
11
|
-
static CLASS_NAME = "UrlTransformerService";
|
|
12
|
-
/**
|
|
13
|
-
* The prefix to use for encrypted query parameters.
|
|
14
|
-
* @internal
|
|
15
|
-
*/
|
|
16
|
-
static _KEY_PREFIX = "x-enc-";
|
|
17
|
-
/**
|
|
18
|
-
* The default name for the parameter encryption key query parameter.
|
|
19
|
-
* @internal
|
|
20
|
-
*/
|
|
21
|
-
static _DEFAULT_PARAM_ENCRYPTION_KEY_NAME = "param-encryption";
|
|
22
|
-
/**
|
|
23
|
-
* The vault connector.
|
|
24
|
-
* @internal
|
|
25
|
-
*/
|
|
26
|
-
_vaultConnector;
|
|
27
|
-
/**
|
|
28
|
-
* The name of the key to retrieve from the vault for encryption/decryption of parameters.
|
|
29
|
-
* @internal
|
|
30
|
-
*/
|
|
31
|
-
_paramEncryptionKeyName;
|
|
32
|
-
/**
|
|
33
|
-
* Maps logical token ids to their URL query parameter names.
|
|
34
|
-
* @internal
|
|
35
|
-
*/
|
|
36
|
-
_queryParamNames;
|
|
37
|
-
/**
|
|
38
|
-
* The node identity, captured at start.
|
|
39
|
-
* @internal
|
|
40
|
-
*/
|
|
41
|
-
_nodeId;
|
|
42
|
-
/**
|
|
43
|
-
* Create a new instance of UrlTransformerService.
|
|
44
|
-
* @param options The options to create the service.
|
|
45
|
-
*/
|
|
46
|
-
constructor(options) {
|
|
47
|
-
this._vaultConnector = VaultConnectorFactory.get(options?.vaultConnectorType ?? "vault");
|
|
48
|
-
this._paramEncryptionKeyName =
|
|
49
|
-
options?.config?.paramEncryptionKeyName ??
|
|
50
|
-
UrlTransformerService._DEFAULT_PARAM_ENCRYPTION_KEY_NAME;
|
|
51
|
-
this._queryParamNames = options?.config?.queryParamNames ?? {};
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Returns the class name of the component.
|
|
55
|
-
* @returns The class name of the component.
|
|
56
|
-
*/
|
|
57
|
-
className() {
|
|
58
|
-
return UrlTransformerService.CLASS_NAME;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* The component needs to be started when the node is initialized.
|
|
62
|
-
* @returns Nothing.
|
|
63
|
-
*/
|
|
64
|
-
async start() {
|
|
65
|
-
const contextIds = await ContextIdStore.getContextIds();
|
|
66
|
-
this._nodeId = contextIds?.[ContextIdKeys.Node];
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Encrypt a named token value and append it as a query parameter to the given URL.
|
|
70
|
-
* @param url The URL to append the encrypted token to.
|
|
71
|
-
* @param id The logical token identifier (e.g. "tenant").
|
|
72
|
-
* @param value The value to encrypt and add.
|
|
73
|
-
* @returns The URL with the encrypted token added as a query parameter.
|
|
74
|
-
*/
|
|
75
|
-
async addEncryptedQueryParamToUrl(url, id, value) {
|
|
76
|
-
const paramName = this._queryParamNames[id] ?? id;
|
|
77
|
-
return this.addEncryptedToUrl(url, { [paramName]: value });
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Get a named token value from the query parameters.
|
|
81
|
-
* @param queryParams The HTTP request query containing the parameters.
|
|
82
|
-
* @param id The logical token identifier (e.g. "tenant").
|
|
83
|
-
* @returns The decrypted token value if it exists.
|
|
84
|
-
*/
|
|
85
|
-
async getEncryptedQueryParam(queryParams, id) {
|
|
86
|
-
const paramName = this._queryParamNames[id] ?? id;
|
|
87
|
-
const decrypted = await this.getDecryptedFromQueryParams(queryParams, [paramName]);
|
|
88
|
-
return decrypted[paramName];
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Add encrypted key/value pairs to a URL's query string.
|
|
92
|
-
* @param url The base URL to add parameters to.
|
|
93
|
-
* @param params The key/value pairs to encrypt and append.
|
|
94
|
-
* @returns The URL with the encrypted parameters added.
|
|
95
|
-
*/
|
|
96
|
-
async addEncryptedToUrl(url, params) {
|
|
97
|
-
let urlObj;
|
|
98
|
-
try {
|
|
99
|
-
urlObj = new URL(url);
|
|
100
|
-
}
|
|
101
|
-
catch {
|
|
102
|
-
return url;
|
|
103
|
-
}
|
|
104
|
-
const query = {};
|
|
105
|
-
for (const [key, value] of urlObj.searchParams.entries()) {
|
|
106
|
-
query[key] = value;
|
|
107
|
-
}
|
|
108
|
-
const keysToEncrypt = Object.keys(params);
|
|
109
|
-
for (const [key, value] of Object.entries(params)) {
|
|
110
|
-
query[key] = value;
|
|
111
|
-
}
|
|
112
|
-
await this.encryptQueryParams(query, keysToEncrypt);
|
|
113
|
-
urlObj.search = "";
|
|
114
|
-
for (const [key, value] of Object.entries(query)) {
|
|
115
|
-
urlObj.searchParams.set(key, value);
|
|
116
|
-
}
|
|
117
|
-
return urlObj.toString();
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* Get an encrypted value from a URL's query string.
|
|
121
|
-
* @param url The URL to extract the encrypted value from.
|
|
122
|
-
* @param id The logical identifier for the value to retrieve (e.g. "tenant").
|
|
123
|
-
* @returns The decrypted value if it exists.
|
|
124
|
-
*/
|
|
125
|
-
async getEncryptedFromUrl(url, id) {
|
|
126
|
-
let urlObj;
|
|
127
|
-
try {
|
|
128
|
-
urlObj = new URL(url);
|
|
129
|
-
}
|
|
130
|
-
catch {
|
|
131
|
-
return undefined;
|
|
132
|
-
}
|
|
133
|
-
const name = this.getParamName(id);
|
|
134
|
-
if (!Is.stringValue(name)) {
|
|
135
|
-
return undefined;
|
|
136
|
-
}
|
|
137
|
-
if (urlObj.searchParams.has(name)) {
|
|
138
|
-
const encryptedValue = urlObj.searchParams.get(name);
|
|
139
|
-
if (Is.stringValue(encryptedValue)) {
|
|
140
|
-
return this.decryptParam(encryptedValue);
|
|
141
|
-
}
|
|
142
|
-
return undefined;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* Decrypt specified keys from a query parameter object and return their plain-text values.
|
|
147
|
-
* @param queryParams The HTTP request query containing the encrypted parameters.
|
|
148
|
-
* @param keys The keys to decrypt.
|
|
149
|
-
* @returns A map of the decrypted key/value pairs that were present.
|
|
150
|
-
*/
|
|
151
|
-
async getDecryptedFromQueryParams(queryParams, keys) {
|
|
152
|
-
const queryParamsClone = ObjectHelper.clone(queryParams) ?? {};
|
|
153
|
-
await this.decryptQueryParams(queryParamsClone, keys);
|
|
154
|
-
const result = {};
|
|
155
|
-
for (const key of keys) {
|
|
156
|
-
if (Is.stringValue(queryParamsClone[key])) {
|
|
157
|
-
result[key] = queryParamsClone[key];
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
return result;
|
|
161
|
-
}
|
|
162
|
-
/**
|
|
163
|
-
* Encrypt query parameters.
|
|
164
|
-
* @param httpRequestQuery The HTTP request query containing the parameters to encrypt.
|
|
165
|
-
* @param keys The keys of the parameters to encrypt.
|
|
166
|
-
* @returns A promise that resolves when the query parameters have been encrypted.
|
|
167
|
-
*/
|
|
168
|
-
async encryptQueryParams(httpRequestQuery, keys) {
|
|
169
|
-
if (Is.empty(httpRequestQuery)) {
|
|
170
|
-
return;
|
|
171
|
-
}
|
|
172
|
-
for (const key of keys) {
|
|
173
|
-
if (Is.stringValue(httpRequestQuery[key])) {
|
|
174
|
-
const encryptedValue = await this.encryptParam(httpRequestQuery[key]);
|
|
175
|
-
httpRequestQuery[`${UrlTransformerService._KEY_PREFIX}${key}`] = encryptedValue;
|
|
176
|
-
delete httpRequestQuery[key];
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
/**
|
|
181
|
-
* Decrypt query parameters.
|
|
182
|
-
* @param httpRequestQuery The HTTP request query containing the encrypted values.
|
|
183
|
-
* @param keys The keys of the parameters to decrypt.
|
|
184
|
-
* @returns A promise that resolves when the query parameters have been decrypted.
|
|
185
|
-
*/
|
|
186
|
-
async decryptQueryParams(httpRequestQuery, keys) {
|
|
187
|
-
if (Is.empty(httpRequestQuery)) {
|
|
188
|
-
return;
|
|
189
|
-
}
|
|
190
|
-
for (const key of Object.keys(httpRequestQuery)) {
|
|
191
|
-
if (key.startsWith(UrlTransformerService._KEY_PREFIX)) {
|
|
192
|
-
const originalKey = key.slice(UrlTransformerService._KEY_PREFIX.length);
|
|
193
|
-
if (keys.includes(originalKey)) {
|
|
194
|
-
const decryptedValue = await this.decryptParam(httpRequestQuery[key]);
|
|
195
|
-
httpRequestQuery[originalKey] = decryptedValue;
|
|
196
|
-
delete httpRequestQuery[key];
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
/**
|
|
202
|
-
* Encrypt a parameter value.
|
|
203
|
-
* @param paramValue The value of the parameter to encrypt.
|
|
204
|
-
* @returns A promise that resolves to the encrypted value of the parameter.
|
|
205
|
-
*/
|
|
206
|
-
async encryptParam(paramValue) {
|
|
207
|
-
Guards.stringValue(UrlTransformerService.CLASS_NAME, "paramValue", paramValue);
|
|
208
|
-
if (Is.empty(this._nodeId)) {
|
|
209
|
-
throw new GeneralError(UrlTransformerService.CLASS_NAME, "encryptionUnavailable");
|
|
210
|
-
}
|
|
211
|
-
try {
|
|
212
|
-
const salt = RandomHelper.generate(8);
|
|
213
|
-
const encryptedParamValue = await this._vaultConnector.encrypt(`${this._nodeId}/${this._paramEncryptionKeyName}`, VaultEncryptionType.ChaCha20Poly1305, Uint8ArrayHelper.concat([salt, Converter.utf8ToBytes(paramValue)]));
|
|
214
|
-
if (!Is.uint8Array(encryptedParamValue)) {
|
|
215
|
-
throw new GeneralError(UrlTransformerService.CLASS_NAME, "encryptionFailed");
|
|
216
|
-
}
|
|
217
|
-
return Converter.bytesToBase64Url(encryptedParamValue);
|
|
218
|
-
}
|
|
219
|
-
catch (err) {
|
|
220
|
-
throw new GeneralError(UrlTransformerService.CLASS_NAME, "encryptionFailed", undefined, BaseError.fromError(err));
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
/**
|
|
224
|
-
* Decrypt a parameter value.
|
|
225
|
-
* @param encryptedValue The encrypted value of the parameter.
|
|
226
|
-
* @returns A promise that resolves to the decrypted value of the parameter.
|
|
227
|
-
*/
|
|
228
|
-
async decryptParam(encryptedValue) {
|
|
229
|
-
Guards.stringValue(UrlTransformerService.CLASS_NAME, "encryptedValue", encryptedValue);
|
|
230
|
-
if (Is.empty(this._nodeId)) {
|
|
231
|
-
throw new GeneralError(UrlTransformerService.CLASS_NAME, "decryptionUnavailable");
|
|
232
|
-
}
|
|
233
|
-
try {
|
|
234
|
-
const encryptedBytes = Converter.base64UrlToBytes(encryptedValue);
|
|
235
|
-
const decryptedBytes = await this._vaultConnector.decrypt(`${this._nodeId}/${this._paramEncryptionKeyName}`, VaultEncryptionType.ChaCha20Poly1305, encryptedBytes);
|
|
236
|
-
if (!Is.uint8Array(decryptedBytes)) {
|
|
237
|
-
throw new GeneralError(UrlTransformerService.CLASS_NAME, "decryptionFailed");
|
|
238
|
-
}
|
|
239
|
-
return Converter.bytesToUtf8(decryptedBytes.slice(8));
|
|
240
|
-
}
|
|
241
|
-
catch (err) {
|
|
242
|
-
throw new GeneralError(UrlTransformerService.CLASS_NAME, "decryptionFailed", undefined, BaseError.fromError(err));
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
/**
|
|
246
|
-
* Get the parameter name for a given key.
|
|
247
|
-
* @param key The key of the parameter.
|
|
248
|
-
* @returns The parameter name.
|
|
249
|
-
*/
|
|
250
|
-
getParamName(key) {
|
|
251
|
-
return Is.stringValue(this._queryParamNames[key])
|
|
252
|
-
? `${UrlTransformerService._KEY_PREFIX}${this._queryParamNames[key]}`
|
|
253
|
-
: undefined;
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
//# sourceMappingURL=urlTransformerService.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"urlTransformerService.js","sourceRoot":"","sources":["../../src/urlTransformerService.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,EACN,SAAS,EACT,SAAS,EACT,YAAY,EACZ,MAAM,EACN,EAAE,EACF,YAAY,EACZ,YAAY,EACZ,gBAAgB,EAChB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAEN,qBAAqB,EACrB,mBAAmB,EACnB,MAAM,wBAAwB,CAAC;AAGhC;;GAEG;AACH,MAAM,OAAO,qBAAqB;IACjC;;OAEG;IACI,MAAM,CAAU,UAAU,2BAA2C;IAE5E;;;OAGG;IACK,MAAM,CAAU,WAAW,GAAG,QAAQ,CAAC;IAE/C;;;OAGG;IACK,MAAM,CAAU,kCAAkC,GAAW,kBAAkB,CAAC;IAExF;;;OAGG;IACc,eAAe,CAAkB;IAElD;;;OAGG;IACc,uBAAuB,CAAS;IAEjD;;;OAGG;IACc,gBAAgB,CAA2B;IAE5D;;;OAGG;IACK,OAAO,CAAU;IAEzB;;;OAGG;IACH,YAAY,OAAkD;QAC7D,IAAI,CAAC,eAAe,GAAG,qBAAqB,CAAC,GAAG,CAAC,OAAO,EAAE,kBAAkB,IAAI,OAAO,CAAC,CAAC;QACzF,IAAI,CAAC,uBAAuB;YAC3B,OAAO,EAAE,MAAM,EAAE,sBAAsB;gBACvC,qBAAqB,CAAC,kCAAkC,CAAC;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CAAC,CAAC;YAC9E,CAAC;YAED,OAAO,SAAS,CAAC,WAAW,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QACvD,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACd,MAAM,IAAI,YAAY,CACrB,qBAAqB,CAAC,UAAU,EAChC,kBAAkB,EAClB,SAAS,EACT,SAAS,CAAC,SAAS,CAAC,GAAG,CAAC,CACxB,CAAC;QACH,CAAC;IACF,CAAC;IAED;;;;OAIG;IACI,YAAY,CAAC,GAAW;QAC9B,OAAO,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC;YAChD,CAAC,CAAC,GAAG,qBAAqB,CAAC,WAAW,GAAG,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,EAAE;YACrE,CAAC,CAAC,SAAS,CAAC;IACd,CAAC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IHttpRequestQuery, IUrlTransformerComponent } from \"@twin.org/api-models\";\nimport { ContextIdKeys, ContextIdStore } from \"@twin.org/context\";\nimport {\n\tBaseError,\n\tConverter,\n\tGeneralError,\n\tGuards,\n\tIs,\n\tObjectHelper,\n\tRandomHelper,\n\tUint8ArrayHelper\n} from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\nimport {\n\ttype IVaultConnector,\n\tVaultConnectorFactory,\n\tVaultEncryptionType\n} from \"@twin.org/vault-models\";\nimport type { IUrlTransformerServiceConstructorOptions } from \"./models/IUrlTransformerServiceConstructorOptions.js\";\n\n/**\n * The URL transformer service for encrypting and decrypting URL parameters.\n */\nexport class UrlTransformerService implements IUrlTransformerComponent {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<UrlTransformerService>();\n\n\t/**\n\t * The prefix to use for encrypted query parameters.\n\t * @internal\n\t */\n\tprivate static readonly _KEY_PREFIX = \"x-enc-\";\n\n\t/**\n\t * The default name for the parameter encryption key query parameter.\n\t * @internal\n\t */\n\tprivate static readonly _DEFAULT_PARAM_ENCRYPTION_KEY_NAME: string = \"param-encryption\";\n\n\t/**\n\t * The vault connector.\n\t * @internal\n\t */\n\tprivate readonly _vaultConnector: IVaultConnector;\n\n\t/**\n\t * The name of the key to retrieve from the vault for encryption/decryption of parameters.\n\t * @internal\n\t */\n\tprivate readonly _paramEncryptionKeyName: string;\n\n\t/**\n\t * Maps logical token ids to their URL query parameter names.\n\t * @internal\n\t */\n\tprivate readonly _queryParamNames: { [id: string]: string };\n\n\t/**\n\t * The node identity, captured at start.\n\t * @internal\n\t */\n\tprivate _nodeId?: string;\n\n\t/**\n\t * Create a new instance of UrlTransformerService.\n\t * @param options The options to create the service.\n\t */\n\tconstructor(options?: IUrlTransformerServiceConstructorOptions) {\n\t\tthis._vaultConnector = VaultConnectorFactory.get(options?.vaultConnectorType ?? \"vault\");\n\t\tthis._paramEncryptionKeyName =\n\t\t\toptions?.config?.paramEncryptionKeyName ??\n\t\t\tUrlTransformerService._DEFAULT_PARAM_ENCRYPTION_KEY_NAME;\n\t\tthis._queryParamNames = options?.config?.queryParamNames ?? {};\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 UrlTransformerService.CLASS_NAME;\n\t}\n\n\t/**\n\t * The component needs to be started when the node is initialized.\n\t * @returns Nothing.\n\t */\n\tpublic async start(): Promise<void> {\n\t\tconst contextIds = await ContextIdStore.getContextIds();\n\t\tthis._nodeId = contextIds?.[ContextIdKeys.Node];\n\t}\n\n\t/**\n\t * Encrypt a named token value and append it as a query parameter to the given URL.\n\t * @param url The URL to append the encrypted token to.\n\t * @param id The logical token identifier (e.g. \"tenant\").\n\t * @param value The value to encrypt and add.\n\t * @returns The URL with the encrypted token added as a query parameter.\n\t */\n\tpublic async addEncryptedQueryParamToUrl(\n\t\turl: string,\n\t\tid: string,\n\t\tvalue: string\n\t): Promise<string> {\n\t\tconst paramName = this._queryParamNames[id] ?? id;\n\t\treturn this.addEncryptedToUrl(url, { [paramName]: value });\n\t}\n\n\t/**\n\t * Get a named token value from the query parameters.\n\t * @param queryParams The HTTP request query containing the parameters.\n\t * @param id The logical token identifier (e.g. \"tenant\").\n\t * @returns The decrypted token value if it exists.\n\t */\n\tpublic async getEncryptedQueryParam(\n\t\tqueryParams: IHttpRequestQuery | undefined,\n\t\tid: string\n\t): Promise<string | undefined> {\n\t\tconst paramName = this._queryParamNames[id] ?? id;\n\t\tconst decrypted = await this.getDecryptedFromQueryParams(queryParams, [paramName]);\n\t\treturn decrypted[paramName];\n\t}\n\n\t/**\n\t * Add encrypted key/value pairs to a URL's query string.\n\t * @param url The base URL to add parameters to.\n\t * @param params The key/value pairs to encrypt and append.\n\t * @returns The URL with the encrypted parameters added.\n\t */\n\tpublic async addEncryptedToUrl(url: string, params: IHttpRequestQuery): Promise<string> {\n\t\tlet urlObj: URL;\n\t\ttry {\n\t\t\turlObj = new URL(url);\n\t\t} catch {\n\t\t\treturn url;\n\t\t}\n\n\t\tconst query: IHttpRequestQuery = {};\n\t\tfor (const [key, value] of urlObj.searchParams.entries()) {\n\t\t\tquery[key] = value;\n\t\t}\n\t\tconst keysToEncrypt = Object.keys(params);\n\t\tfor (const [key, value] of Object.entries(params)) {\n\t\t\tquery[key] = value;\n\t\t}\n\t\tawait this.encryptQueryParams(query, keysToEncrypt);\n\t\turlObj.search = \"\";\n\t\tfor (const [key, value] of Object.entries(query)) {\n\t\t\turlObj.searchParams.set(key, value);\n\t\t}\n\t\treturn urlObj.toString();\n\t}\n\n\t/**\n\t * Get an encrypted value from a URL's query string.\n\t * @param url The URL to extract the encrypted value from.\n\t * @param id The logical identifier for the value to retrieve (e.g. \"tenant\").\n\t * @returns The decrypted value if it exists.\n\t */\n\tpublic async getEncryptedFromUrl(url: string, id: string): Promise<string | undefined> {\n\t\tlet urlObj: URL;\n\t\ttry {\n\t\t\turlObj = new URL(url);\n\t\t} catch {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst name = this.getParamName(id);\n\t\tif (!Is.stringValue(name)) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tif (urlObj.searchParams.has(name)) {\n\t\t\tconst encryptedValue = urlObj.searchParams.get(name);\n\t\t\tif (Is.stringValue(encryptedValue)) {\n\t\t\t\treturn this.decryptParam(encryptedValue);\n\t\t\t}\n\t\t\treturn undefined;\n\t\t}\n\t}\n\n\t/**\n\t * Decrypt specified keys from a query parameter object and return their plain-text values.\n\t * @param queryParams The HTTP request query containing the encrypted parameters.\n\t * @param keys The keys to decrypt.\n\t * @returns A map of the decrypted key/value pairs that were present.\n\t */\n\tpublic async getDecryptedFromQueryParams(\n\t\tqueryParams: IHttpRequestQuery | undefined,\n\t\tkeys: string[]\n\t): Promise<IHttpRequestQuery> {\n\t\tconst queryParamsClone = ObjectHelper.clone(queryParams) ?? {};\n\t\tawait this.decryptQueryParams(queryParamsClone, keys);\n\t\tconst result: IHttpRequestQuery = {};\n\t\tfor (const key of keys) {\n\t\t\tif (Is.stringValue(queryParamsClone[key])) {\n\t\t\t\tresult[key] = queryParamsClone[key];\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t}\n\n\t/**\n\t * Encrypt query parameters.\n\t * @param httpRequestQuery The HTTP request query containing the parameters to encrypt.\n\t * @param keys The keys of the parameters to encrypt.\n\t * @returns A promise that resolves when the query parameters have been encrypted.\n\t */\n\tpublic async encryptQueryParams(\n\t\thttpRequestQuery: IHttpRequestQuery | undefined,\n\t\tkeys: string[]\n\t): Promise<void> {\n\t\tif (Is.empty(httpRequestQuery)) {\n\t\t\treturn;\n\t\t}\n\n\t\tfor (const key of keys) {\n\t\t\tif (Is.stringValue(httpRequestQuery[key])) {\n\t\t\t\tconst encryptedValue = await this.encryptParam(httpRequestQuery[key]);\n\t\t\t\thttpRequestQuery[`${UrlTransformerService._KEY_PREFIX}${key}`] = encryptedValue;\n\t\t\t\tdelete httpRequestQuery[key];\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Decrypt query parameters.\n\t * @param httpRequestQuery The HTTP request query containing the encrypted values.\n\t * @param keys The keys of the parameters to decrypt.\n\t * @returns A promise that resolves when the query parameters have been decrypted.\n\t */\n\tpublic async decryptQueryParams(\n\t\thttpRequestQuery: IHttpRequestQuery | undefined,\n\t\tkeys: string[]\n\t): Promise<void> {\n\t\tif (Is.empty(httpRequestQuery)) {\n\t\t\treturn;\n\t\t}\n\t\tfor (const key of Object.keys(httpRequestQuery)) {\n\t\t\tif (key.startsWith(UrlTransformerService._KEY_PREFIX)) {\n\t\t\t\tconst originalKey = key.slice(UrlTransformerService._KEY_PREFIX.length);\n\n\t\t\t\tif (keys.includes(originalKey)) {\n\t\t\t\t\tconst decryptedValue = await this.decryptParam(httpRequestQuery[key]);\n\t\t\t\t\thttpRequestQuery[originalKey] = decryptedValue;\n\t\t\t\t\tdelete httpRequestQuery[key];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Encrypt a parameter value.\n\t * @param paramValue The value of the parameter to encrypt.\n\t * @returns A promise that resolves to the encrypted value of the parameter.\n\t */\n\tpublic async encryptParam(paramValue: string): Promise<string> {\n\t\tGuards.stringValue(UrlTransformerService.CLASS_NAME, nameof(paramValue), paramValue);\n\n\t\tif (Is.empty(this._nodeId)) {\n\t\t\tthrow new GeneralError(UrlTransformerService.CLASS_NAME, \"encryptionUnavailable\");\n\t\t}\n\n\t\ttry {\n\t\t\tconst salt = RandomHelper.generate(8);\n\n\t\t\tconst encryptedParamValue = await this._vaultConnector.encrypt(\n\t\t\t\t`${this._nodeId}/${this._paramEncryptionKeyName}`,\n\t\t\t\tVaultEncryptionType.ChaCha20Poly1305,\n\t\t\t\tUint8ArrayHelper.concat([salt, Converter.utf8ToBytes(paramValue)])\n\t\t\t);\n\n\t\t\tif (!Is.uint8Array(encryptedParamValue)) {\n\t\t\t\tthrow new GeneralError(UrlTransformerService.CLASS_NAME, \"encryptionFailed\");\n\t\t\t}\n\n\t\t\treturn Converter.bytesToBase64Url(encryptedParamValue);\n\t\t} catch (err) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tUrlTransformerService.CLASS_NAME,\n\t\t\t\t\"encryptionFailed\",\n\t\t\t\tundefined,\n\t\t\t\tBaseError.fromError(err)\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Decrypt a parameter value.\n\t * @param encryptedValue The encrypted value of the parameter.\n\t * @returns A promise that resolves to the decrypted value of the parameter.\n\t */\n\tpublic async decryptParam(encryptedValue: string): Promise<string> {\n\t\tGuards.stringValue(UrlTransformerService.CLASS_NAME, nameof(encryptedValue), encryptedValue);\n\n\t\tif (Is.empty(this._nodeId)) {\n\t\t\tthrow new GeneralError(UrlTransformerService.CLASS_NAME, \"decryptionUnavailable\");\n\t\t}\n\n\t\ttry {\n\t\t\tconst encryptedBytes = Converter.base64UrlToBytes(encryptedValue);\n\t\t\tconst decryptedBytes = await this._vaultConnector.decrypt(\n\t\t\t\t`${this._nodeId}/${this._paramEncryptionKeyName}`,\n\t\t\t\tVaultEncryptionType.ChaCha20Poly1305,\n\t\t\t\tencryptedBytes\n\t\t\t);\n\n\t\t\tif (!Is.uint8Array(decryptedBytes)) {\n\t\t\t\tthrow new GeneralError(UrlTransformerService.CLASS_NAME, \"decryptionFailed\");\n\t\t\t}\n\n\t\t\treturn Converter.bytesToUtf8(decryptedBytes.slice(8));\n\t\t} catch (err) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tUrlTransformerService.CLASS_NAME,\n\t\t\t\t\"decryptionFailed\",\n\t\t\t\tundefined,\n\t\t\t\tBaseError.fromError(err)\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Get the parameter name for a given key.\n\t * @param key The key of the parameter.\n\t * @returns The parameter name.\n\t */\n\tpublic getParamName(key: string): string | undefined {\n\t\treturn Is.stringValue(this._queryParamNames[key])\n\t\t\t? `${UrlTransformerService._KEY_PREFIX}${this._queryParamNames[key]}`\n\t\t\t: undefined;\n\t}\n}\n"]}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Configuration for the URL transformer service.
|
|
3
|
-
*/
|
|
4
|
-
export interface IUrlTransformerServiceConfig {
|
|
5
|
-
/**
|
|
6
|
-
* The name of the key to retrieve from the vault for encryption/decryption of parameters.
|
|
7
|
-
* @default param-encryption
|
|
8
|
-
*/
|
|
9
|
-
paramEncryptionKeyName?: string;
|
|
10
|
-
/**
|
|
11
|
-
* A dictionary mapping logical token identifiers to their URL query parameter names.
|
|
12
|
-
* For example: tenant => tenant-token maps the logical id "tenant" to the
|
|
13
|
-
* query param "tenant-token". When an id is not present the id itself is used as
|
|
14
|
-
* the param name.
|
|
15
|
-
*/
|
|
16
|
-
queryParamNames?: {
|
|
17
|
-
[id: string]: string;
|
|
18
|
-
};
|
|
19
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { IUrlTransformerServiceConfig } from "./IUrlTransformerServiceConfig.js";
|
|
2
|
-
/**
|
|
3
|
-
* Options for the UrlTransformerService constructor.
|
|
4
|
-
*/
|
|
5
|
-
export interface IUrlTransformerServiceConstructorOptions {
|
|
6
|
-
/**
|
|
7
|
-
* The vault connector type.
|
|
8
|
-
* @default vault
|
|
9
|
-
*/
|
|
10
|
-
vaultConnectorType?: string;
|
|
11
|
-
/**
|
|
12
|
-
* The configuration for the service.
|
|
13
|
-
*/
|
|
14
|
-
config?: IUrlTransformerServiceConfig;
|
|
15
|
-
}
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import type { IHttpRequestQuery, IUrlTransformerComponent } from "@twin.org/api-models";
|
|
2
|
-
import type { IUrlTransformerServiceConstructorOptions } from "./models/IUrlTransformerServiceConstructorOptions.js";
|
|
3
|
-
/**
|
|
4
|
-
* The URL transformer service for encrypting and decrypting URL parameters.
|
|
5
|
-
*/
|
|
6
|
-
export declare class UrlTransformerService implements IUrlTransformerComponent {
|
|
7
|
-
/**
|
|
8
|
-
* Runtime name for the class.
|
|
9
|
-
*/
|
|
10
|
-
static readonly CLASS_NAME: string;
|
|
11
|
-
/**
|
|
12
|
-
* Create a new instance of UrlTransformerService.
|
|
13
|
-
* @param options The options to create the service.
|
|
14
|
-
*/
|
|
15
|
-
constructor(options?: IUrlTransformerServiceConstructorOptions);
|
|
16
|
-
/**
|
|
17
|
-
* Returns the class name of the component.
|
|
18
|
-
* @returns The class name of the component.
|
|
19
|
-
*/
|
|
20
|
-
className(): string;
|
|
21
|
-
/**
|
|
22
|
-
* The component needs to be started when the node is initialized.
|
|
23
|
-
* @returns Nothing.
|
|
24
|
-
*/
|
|
25
|
-
start(): Promise<void>;
|
|
26
|
-
/**
|
|
27
|
-
* Encrypt a named token value and append it as a query parameter to the given URL.
|
|
28
|
-
* @param url The URL to append the encrypted token to.
|
|
29
|
-
* @param id The logical token identifier (e.g. "tenant").
|
|
30
|
-
* @param value The value to encrypt and add.
|
|
31
|
-
* @returns The URL with the encrypted token added as a query parameter.
|
|
32
|
-
*/
|
|
33
|
-
addEncryptedQueryParamToUrl(url: string, id: string, value: string): Promise<string>;
|
|
34
|
-
/**
|
|
35
|
-
* Get a named token value from the query parameters.
|
|
36
|
-
* @param queryParams The HTTP request query containing the parameters.
|
|
37
|
-
* @param id The logical token identifier (e.g. "tenant").
|
|
38
|
-
* @returns The decrypted token value if it exists.
|
|
39
|
-
*/
|
|
40
|
-
getEncryptedQueryParam(queryParams: IHttpRequestQuery | undefined, id: string): Promise<string | undefined>;
|
|
41
|
-
/**
|
|
42
|
-
* Add encrypted key/value pairs to a URL's query string.
|
|
43
|
-
* @param url The base URL to add parameters to.
|
|
44
|
-
* @param params The key/value pairs to encrypt and append.
|
|
45
|
-
* @returns The URL with the encrypted parameters added.
|
|
46
|
-
*/
|
|
47
|
-
addEncryptedToUrl(url: string, params: IHttpRequestQuery): Promise<string>;
|
|
48
|
-
/**
|
|
49
|
-
* Get an encrypted value from a URL's query string.
|
|
50
|
-
* @param url The URL to extract the encrypted value from.
|
|
51
|
-
* @param id The logical identifier for the value to retrieve (e.g. "tenant").
|
|
52
|
-
* @returns The decrypted value if it exists.
|
|
53
|
-
*/
|
|
54
|
-
getEncryptedFromUrl(url: string, id: string): Promise<string | undefined>;
|
|
55
|
-
/**
|
|
56
|
-
* Decrypt specified keys from a query parameter object and return their plain-text values.
|
|
57
|
-
* @param queryParams The HTTP request query containing the encrypted parameters.
|
|
58
|
-
* @param keys The keys to decrypt.
|
|
59
|
-
* @returns A map of the decrypted key/value pairs that were present.
|
|
60
|
-
*/
|
|
61
|
-
getDecryptedFromQueryParams(queryParams: IHttpRequestQuery | undefined, keys: string[]): Promise<IHttpRequestQuery>;
|
|
62
|
-
/**
|
|
63
|
-
* Encrypt query parameters.
|
|
64
|
-
* @param httpRequestQuery The HTTP request query containing the parameters to encrypt.
|
|
65
|
-
* @param keys The keys of the parameters to encrypt.
|
|
66
|
-
* @returns A promise that resolves when the query parameters have been encrypted.
|
|
67
|
-
*/
|
|
68
|
-
encryptQueryParams(httpRequestQuery: IHttpRequestQuery | undefined, keys: string[]): Promise<void>;
|
|
69
|
-
/**
|
|
70
|
-
* Decrypt query parameters.
|
|
71
|
-
* @param httpRequestQuery The HTTP request query containing the encrypted values.
|
|
72
|
-
* @param keys The keys of the parameters to decrypt.
|
|
73
|
-
* @returns A promise that resolves when the query parameters have been decrypted.
|
|
74
|
-
*/
|
|
75
|
-
decryptQueryParams(httpRequestQuery: IHttpRequestQuery | undefined, keys: string[]): Promise<void>;
|
|
76
|
-
/**
|
|
77
|
-
* Encrypt a parameter value.
|
|
78
|
-
* @param paramValue The value of the parameter to encrypt.
|
|
79
|
-
* @returns A promise that resolves to the encrypted value of the parameter.
|
|
80
|
-
*/
|
|
81
|
-
encryptParam(paramValue: string): Promise<string>;
|
|
82
|
-
/**
|
|
83
|
-
* Decrypt a parameter value.
|
|
84
|
-
* @param encryptedValue The encrypted value of the parameter.
|
|
85
|
-
* @returns A promise that resolves to the decrypted value of the parameter.
|
|
86
|
-
*/
|
|
87
|
-
decryptParam(encryptedValue: string): Promise<string>;
|
|
88
|
-
/**
|
|
89
|
-
* Get the parameter name for a given key.
|
|
90
|
-
* @param key The key of the parameter.
|
|
91
|
-
* @returns The parameter name.
|
|
92
|
-
*/
|
|
93
|
-
getParamName(key: string): string | undefined;
|
|
94
|
-
}
|
|
@@ -1,379 +0,0 @@
|
|
|
1
|
-
# Class: UrlTransformerService
|
|
2
|
-
|
|
3
|
-
The URL transformer service for encrypting and decrypting URL parameters.
|
|
4
|
-
|
|
5
|
-
## Implements
|
|
6
|
-
|
|
7
|
-
- `IUrlTransformerComponent`
|
|
8
|
-
|
|
9
|
-
## Constructors
|
|
10
|
-
|
|
11
|
-
### Constructor
|
|
12
|
-
|
|
13
|
-
> **new UrlTransformerService**(`options?`): `UrlTransformerService`
|
|
14
|
-
|
|
15
|
-
Create a new instance of UrlTransformerService.
|
|
16
|
-
|
|
17
|
-
#### Parameters
|
|
18
|
-
|
|
19
|
-
##### options?
|
|
20
|
-
|
|
21
|
-
[`IUrlTransformerServiceConstructorOptions`](../interfaces/IUrlTransformerServiceConstructorOptions.md)
|
|
22
|
-
|
|
23
|
-
The options to create the service.
|
|
24
|
-
|
|
25
|
-
#### Returns
|
|
26
|
-
|
|
27
|
-
`UrlTransformerService`
|
|
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
|
-
`IUrlTransformerComponent.className`
|
|
54
|
-
|
|
55
|
-
***
|
|
56
|
-
|
|
57
|
-
### start() {#start}
|
|
58
|
-
|
|
59
|
-
> **start**(): `Promise`\<`void`\>
|
|
60
|
-
|
|
61
|
-
The component needs to be started when the node is initialized.
|
|
62
|
-
|
|
63
|
-
#### Returns
|
|
64
|
-
|
|
65
|
-
`Promise`\<`void`\>
|
|
66
|
-
|
|
67
|
-
Nothing.
|
|
68
|
-
|
|
69
|
-
#### Implementation of
|
|
70
|
-
|
|
71
|
-
`IUrlTransformerComponent.start`
|
|
72
|
-
|
|
73
|
-
***
|
|
74
|
-
|
|
75
|
-
### addEncryptedQueryParamToUrl() {#addencryptedqueryparamtourl}
|
|
76
|
-
|
|
77
|
-
> **addEncryptedQueryParamToUrl**(`url`, `id`, `value`): `Promise`\<`string`\>
|
|
78
|
-
|
|
79
|
-
Encrypt a named token value and append it as a query parameter to the given URL.
|
|
80
|
-
|
|
81
|
-
#### Parameters
|
|
82
|
-
|
|
83
|
-
##### url
|
|
84
|
-
|
|
85
|
-
`string`
|
|
86
|
-
|
|
87
|
-
The URL to append the encrypted token to.
|
|
88
|
-
|
|
89
|
-
##### id
|
|
90
|
-
|
|
91
|
-
`string`
|
|
92
|
-
|
|
93
|
-
The logical token identifier (e.g. "tenant").
|
|
94
|
-
|
|
95
|
-
##### value
|
|
96
|
-
|
|
97
|
-
`string`
|
|
98
|
-
|
|
99
|
-
The value to encrypt and add.
|
|
100
|
-
|
|
101
|
-
#### Returns
|
|
102
|
-
|
|
103
|
-
`Promise`\<`string`\>
|
|
104
|
-
|
|
105
|
-
The URL with the encrypted token added as a query parameter.
|
|
106
|
-
|
|
107
|
-
#### Implementation of
|
|
108
|
-
|
|
109
|
-
`IUrlTransformerComponent.addEncryptedQueryParamToUrl`
|
|
110
|
-
|
|
111
|
-
***
|
|
112
|
-
|
|
113
|
-
### getEncryptedQueryParam() {#getencryptedqueryparam}
|
|
114
|
-
|
|
115
|
-
> **getEncryptedQueryParam**(`queryParams`, `id`): `Promise`\<`string` \| `undefined`\>
|
|
116
|
-
|
|
117
|
-
Get a named token value from the query parameters.
|
|
118
|
-
|
|
119
|
-
#### Parameters
|
|
120
|
-
|
|
121
|
-
##### queryParams
|
|
122
|
-
|
|
123
|
-
`IHttpRequestQuery` \| `undefined`
|
|
124
|
-
|
|
125
|
-
The HTTP request query containing the parameters.
|
|
126
|
-
|
|
127
|
-
##### id
|
|
128
|
-
|
|
129
|
-
`string`
|
|
130
|
-
|
|
131
|
-
The logical token identifier (e.g. "tenant").
|
|
132
|
-
|
|
133
|
-
#### Returns
|
|
134
|
-
|
|
135
|
-
`Promise`\<`string` \| `undefined`\>
|
|
136
|
-
|
|
137
|
-
The decrypted token value if it exists.
|
|
138
|
-
|
|
139
|
-
#### Implementation of
|
|
140
|
-
|
|
141
|
-
`IUrlTransformerComponent.getEncryptedQueryParam`
|
|
142
|
-
|
|
143
|
-
***
|
|
144
|
-
|
|
145
|
-
### addEncryptedToUrl() {#addencryptedtourl}
|
|
146
|
-
|
|
147
|
-
> **addEncryptedToUrl**(`url`, `params`): `Promise`\<`string`\>
|
|
148
|
-
|
|
149
|
-
Add encrypted key/value pairs to a URL's query string.
|
|
150
|
-
|
|
151
|
-
#### Parameters
|
|
152
|
-
|
|
153
|
-
##### url
|
|
154
|
-
|
|
155
|
-
`string`
|
|
156
|
-
|
|
157
|
-
The base URL to add parameters to.
|
|
158
|
-
|
|
159
|
-
##### params
|
|
160
|
-
|
|
161
|
-
`IHttpRequestQuery`
|
|
162
|
-
|
|
163
|
-
The key/value pairs to encrypt and append.
|
|
164
|
-
|
|
165
|
-
#### Returns
|
|
166
|
-
|
|
167
|
-
`Promise`\<`string`\>
|
|
168
|
-
|
|
169
|
-
The URL with the encrypted parameters added.
|
|
170
|
-
|
|
171
|
-
#### Implementation of
|
|
172
|
-
|
|
173
|
-
`IUrlTransformerComponent.addEncryptedToUrl`
|
|
174
|
-
|
|
175
|
-
***
|
|
176
|
-
|
|
177
|
-
### getEncryptedFromUrl() {#getencryptedfromurl}
|
|
178
|
-
|
|
179
|
-
> **getEncryptedFromUrl**(`url`, `id`): `Promise`\<`string` \| `undefined`\>
|
|
180
|
-
|
|
181
|
-
Get an encrypted value from a URL's query string.
|
|
182
|
-
|
|
183
|
-
#### Parameters
|
|
184
|
-
|
|
185
|
-
##### url
|
|
186
|
-
|
|
187
|
-
`string`
|
|
188
|
-
|
|
189
|
-
The URL to extract the encrypted value from.
|
|
190
|
-
|
|
191
|
-
##### id
|
|
192
|
-
|
|
193
|
-
`string`
|
|
194
|
-
|
|
195
|
-
The logical identifier for the value to retrieve (e.g. "tenant").
|
|
196
|
-
|
|
197
|
-
#### Returns
|
|
198
|
-
|
|
199
|
-
`Promise`\<`string` \| `undefined`\>
|
|
200
|
-
|
|
201
|
-
The decrypted value if it exists.
|
|
202
|
-
|
|
203
|
-
#### Implementation of
|
|
204
|
-
|
|
205
|
-
`IUrlTransformerComponent.getEncryptedFromUrl`
|
|
206
|
-
|
|
207
|
-
***
|
|
208
|
-
|
|
209
|
-
### getDecryptedFromQueryParams() {#getdecryptedfromqueryparams}
|
|
210
|
-
|
|
211
|
-
> **getDecryptedFromQueryParams**(`queryParams`, `keys`): `Promise`\<`IHttpRequestQuery`\>
|
|
212
|
-
|
|
213
|
-
Decrypt specified keys from a query parameter object and return their plain-text values.
|
|
214
|
-
|
|
215
|
-
#### Parameters
|
|
216
|
-
|
|
217
|
-
##### queryParams
|
|
218
|
-
|
|
219
|
-
`IHttpRequestQuery` \| `undefined`
|
|
220
|
-
|
|
221
|
-
The HTTP request query containing the encrypted parameters.
|
|
222
|
-
|
|
223
|
-
##### keys
|
|
224
|
-
|
|
225
|
-
`string`[]
|
|
226
|
-
|
|
227
|
-
The keys to decrypt.
|
|
228
|
-
|
|
229
|
-
#### Returns
|
|
230
|
-
|
|
231
|
-
`Promise`\<`IHttpRequestQuery`\>
|
|
232
|
-
|
|
233
|
-
A map of the decrypted key/value pairs that were present.
|
|
234
|
-
|
|
235
|
-
#### Implementation of
|
|
236
|
-
|
|
237
|
-
`IUrlTransformerComponent.getDecryptedFromQueryParams`
|
|
238
|
-
|
|
239
|
-
***
|
|
240
|
-
|
|
241
|
-
### encryptQueryParams() {#encryptqueryparams}
|
|
242
|
-
|
|
243
|
-
> **encryptQueryParams**(`httpRequestQuery`, `keys`): `Promise`\<`void`\>
|
|
244
|
-
|
|
245
|
-
Encrypt query parameters.
|
|
246
|
-
|
|
247
|
-
#### Parameters
|
|
248
|
-
|
|
249
|
-
##### httpRequestQuery
|
|
250
|
-
|
|
251
|
-
`IHttpRequestQuery` \| `undefined`
|
|
252
|
-
|
|
253
|
-
The HTTP request query containing the parameters to encrypt.
|
|
254
|
-
|
|
255
|
-
##### keys
|
|
256
|
-
|
|
257
|
-
`string`[]
|
|
258
|
-
|
|
259
|
-
The keys of the parameters to encrypt.
|
|
260
|
-
|
|
261
|
-
#### Returns
|
|
262
|
-
|
|
263
|
-
`Promise`\<`void`\>
|
|
264
|
-
|
|
265
|
-
A promise that resolves when the query parameters have been encrypted.
|
|
266
|
-
|
|
267
|
-
#### Implementation of
|
|
268
|
-
|
|
269
|
-
`IUrlTransformerComponent.encryptQueryParams`
|
|
270
|
-
|
|
271
|
-
***
|
|
272
|
-
|
|
273
|
-
### decryptQueryParams() {#decryptqueryparams}
|
|
274
|
-
|
|
275
|
-
> **decryptQueryParams**(`httpRequestQuery`, `keys`): `Promise`\<`void`\>
|
|
276
|
-
|
|
277
|
-
Decrypt query parameters.
|
|
278
|
-
|
|
279
|
-
#### Parameters
|
|
280
|
-
|
|
281
|
-
##### httpRequestQuery
|
|
282
|
-
|
|
283
|
-
`IHttpRequestQuery` \| `undefined`
|
|
284
|
-
|
|
285
|
-
The HTTP request query containing the encrypted values.
|
|
286
|
-
|
|
287
|
-
##### keys
|
|
288
|
-
|
|
289
|
-
`string`[]
|
|
290
|
-
|
|
291
|
-
The keys of the parameters to decrypt.
|
|
292
|
-
|
|
293
|
-
#### Returns
|
|
294
|
-
|
|
295
|
-
`Promise`\<`void`\>
|
|
296
|
-
|
|
297
|
-
A promise that resolves when the query parameters have been decrypted.
|
|
298
|
-
|
|
299
|
-
#### Implementation of
|
|
300
|
-
|
|
301
|
-
`IUrlTransformerComponent.decryptQueryParams`
|
|
302
|
-
|
|
303
|
-
***
|
|
304
|
-
|
|
305
|
-
### encryptParam() {#encryptparam}
|
|
306
|
-
|
|
307
|
-
> **encryptParam**(`paramValue`): `Promise`\<`string`\>
|
|
308
|
-
|
|
309
|
-
Encrypt a parameter value.
|
|
310
|
-
|
|
311
|
-
#### Parameters
|
|
312
|
-
|
|
313
|
-
##### paramValue
|
|
314
|
-
|
|
315
|
-
`string`
|
|
316
|
-
|
|
317
|
-
The value of the parameter to encrypt.
|
|
318
|
-
|
|
319
|
-
#### Returns
|
|
320
|
-
|
|
321
|
-
`Promise`\<`string`\>
|
|
322
|
-
|
|
323
|
-
A promise that resolves to the encrypted value of the parameter.
|
|
324
|
-
|
|
325
|
-
#### Implementation of
|
|
326
|
-
|
|
327
|
-
`IUrlTransformerComponent.encryptParam`
|
|
328
|
-
|
|
329
|
-
***
|
|
330
|
-
|
|
331
|
-
### decryptParam() {#decryptparam}
|
|
332
|
-
|
|
333
|
-
> **decryptParam**(`encryptedValue`): `Promise`\<`string`\>
|
|
334
|
-
|
|
335
|
-
Decrypt a parameter value.
|
|
336
|
-
|
|
337
|
-
#### Parameters
|
|
338
|
-
|
|
339
|
-
##### encryptedValue
|
|
340
|
-
|
|
341
|
-
`string`
|
|
342
|
-
|
|
343
|
-
The encrypted value of the parameter.
|
|
344
|
-
|
|
345
|
-
#### Returns
|
|
346
|
-
|
|
347
|
-
`Promise`\<`string`\>
|
|
348
|
-
|
|
349
|
-
A promise that resolves to the decrypted value of the parameter.
|
|
350
|
-
|
|
351
|
-
#### Implementation of
|
|
352
|
-
|
|
353
|
-
`IUrlTransformerComponent.decryptParam`
|
|
354
|
-
|
|
355
|
-
***
|
|
356
|
-
|
|
357
|
-
### getParamName() {#getparamname}
|
|
358
|
-
|
|
359
|
-
> **getParamName**(`key`): `string` \| `undefined`
|
|
360
|
-
|
|
361
|
-
Get the parameter name for a given key.
|
|
362
|
-
|
|
363
|
-
#### Parameters
|
|
364
|
-
|
|
365
|
-
##### key
|
|
366
|
-
|
|
367
|
-
`string`
|
|
368
|
-
|
|
369
|
-
The key of the parameter.
|
|
370
|
-
|
|
371
|
-
#### Returns
|
|
372
|
-
|
|
373
|
-
`string` \| `undefined`
|
|
374
|
-
|
|
375
|
-
The parameter name.
|
|
376
|
-
|
|
377
|
-
#### Implementation of
|
|
378
|
-
|
|
379
|
-
`IUrlTransformerComponent.getParamName`
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
# Interface: IUrlTransformerServiceConfig
|
|
2
|
-
|
|
3
|
-
Configuration for the URL transformer service.
|
|
4
|
-
|
|
5
|
-
## Properties
|
|
6
|
-
|
|
7
|
-
### paramEncryptionKeyName? {#paramencryptionkeyname}
|
|
8
|
-
|
|
9
|
-
> `optional` **paramEncryptionKeyName?**: `string`
|
|
10
|
-
|
|
11
|
-
The name of the key to retrieve from the vault for encryption/decryption of parameters.
|
|
12
|
-
|
|
13
|
-
#### Default
|
|
14
|
-
|
|
15
|
-
```ts
|
|
16
|
-
param-encryption
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
***
|
|
20
|
-
|
|
21
|
-
### queryParamNames? {#queryparamnames}
|
|
22
|
-
|
|
23
|
-
> `optional` **queryParamNames?**: `object`
|
|
24
|
-
|
|
25
|
-
A dictionary mapping logical token identifiers to their URL query parameter names.
|
|
26
|
-
For example: tenant => tenant-token maps the logical id "tenant" to the
|
|
27
|
-
query param "tenant-token". When an id is not present the id itself is used as
|
|
28
|
-
the param name.
|
|
29
|
-
|
|
30
|
-
#### Index Signature
|
|
31
|
-
|
|
32
|
-
\[`id`: `string`\]: `string`
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
# Interface: IUrlTransformerServiceConstructorOptions
|
|
2
|
-
|
|
3
|
-
Options for the UrlTransformerService constructor.
|
|
4
|
-
|
|
5
|
-
## Properties
|
|
6
|
-
|
|
7
|
-
### vaultConnectorType? {#vaultconnectortype}
|
|
8
|
-
|
|
9
|
-
> `optional` **vaultConnectorType?**: `string`
|
|
10
|
-
|
|
11
|
-
The vault connector type.
|
|
12
|
-
|
|
13
|
-
#### Default
|
|
14
|
-
|
|
15
|
-
```ts
|
|
16
|
-
vault
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
***
|
|
20
|
-
|
|
21
|
-
### config? {#config}
|
|
22
|
-
|
|
23
|
-
> `optional` **config?**: [`IUrlTransformerServiceConfig`](IUrlTransformerServiceConfig.md)
|
|
24
|
-
|
|
25
|
-
The configuration for the service.
|