@twin.org/api-service 0.0.3-next.46 → 0.0.3-next.48
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 +0 -3
- package/dist/es/index.js.map +1 -1
- package/dist/es/platformService.js +40 -1
- package/dist/es/platformService.js.map +1 -1
- package/dist/types/index.d.ts +0 -3
- package/dist/types/platformService.d.ts +7 -1
- package/docs/changelog.md +28 -0
- package/docs/reference/classes/PlatformService.md +26 -0
- package/docs/reference/index.md +0 -3
- package/package.json +2 -2
- package/dist/es/hostingService.js +0 -115
- package/dist/es/hostingService.js.map +0 -1
- package/dist/es/models/IHostingServiceConfig.js +0 -4
- package/dist/es/models/IHostingServiceConfig.js.map +0 -1
- package/dist/es/models/IHostingServiceConstructorOptions.js +0 -2
- package/dist/es/models/IHostingServiceConstructorOptions.js.map +0 -1
- package/dist/types/hostingService.d.ts +0 -45
- package/dist/types/models/IHostingServiceConfig.d.ts +0 -13
- package/dist/types/models/IHostingServiceConstructorOptions.d.ts +0 -15
- package/docs/reference/classes/HostingService.md +0 -157
- package/docs/reference/interfaces/IHostingServiceConfig.md +0 -19
- package/docs/reference/interfaces/IHostingServiceConstructorOptions.md +0 -25
package/dist/es/index.js
CHANGED
|
@@ -2,13 +2,10 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0.
|
|
3
3
|
export * from "./healthRoutes.js";
|
|
4
4
|
export * from "./healthService.js";
|
|
5
|
-
export * from "./hostingService.js";
|
|
6
5
|
export * from "./informationRoutes.js";
|
|
7
6
|
export * from "./informationService.js";
|
|
8
7
|
export * from "./models/IHealthServiceConfig.js";
|
|
9
8
|
export * from "./models/IHealthServiceConstructorOptions.js";
|
|
10
|
-
export * from "./models/IHostingServiceConfig.js";
|
|
11
|
-
export * from "./models/IHostingServiceConstructorOptions.js";
|
|
12
9
|
export * from "./models/IInformationServiceConfig.js";
|
|
13
10
|
export * from "./models/IInformationServiceConstructorOptions.js";
|
|
14
11
|
export * from "./models/IPlatformServiceConfig.js";
|
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,
|
|
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,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,kCAAkC,CAAC;AACjD,cAAc,8CAA8C,CAAC;AAC7D,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 \"./informationRoutes.js\";\nexport * from \"./informationService.js\";\nexport * from \"./models/IHealthServiceConfig.js\";\nexport * from \"./models/IHealthServiceConstructorOptions.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"]}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
// Copyright 2026 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
import { HttpContextIdKeys, HttpUrlHelper } from "@twin.org/api-models";
|
|
1
4
|
import { ContextIdKeys, ContextIdStore } from "@twin.org/context";
|
|
2
|
-
import { Is } from "@twin.org/core";
|
|
5
|
+
import { Guards, Is } from "@twin.org/core";
|
|
3
6
|
import { EntityStorageConnectorFactory } from "@twin.org/entity-storage-models";
|
|
4
7
|
/**
|
|
5
8
|
* Service for performing platform operations.
|
|
@@ -72,5 +75,41 @@ export class PlatformService {
|
|
|
72
75
|
await method();
|
|
73
76
|
}
|
|
74
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* Determines if the given URL is a local origin.
|
|
80
|
+
* @param url The URL to check.
|
|
81
|
+
* @returns A promise that resolves to true if the URL is a local origin, false otherwise.
|
|
82
|
+
*/
|
|
83
|
+
async isLocalOrigin(url) {
|
|
84
|
+
Guards.stringValue(PlatformService.CLASS_NAME, "url", url);
|
|
85
|
+
const origin = HttpUrlHelper.extractOrigin(url);
|
|
86
|
+
if (!Is.stringValue(origin)) {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
const contextIds = await ContextIdStore.getContextIds();
|
|
90
|
+
const publicOrigin = contextIds?.[HttpContextIdKeys.PublicOrigin];
|
|
91
|
+
if (publicOrigin === origin) {
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
const localOrigin = contextIds?.[HttpContextIdKeys.LocalOrigin];
|
|
95
|
+
if (localOrigin === origin) {
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
if (Is.empty(this._entityStorageConnector)) {
|
|
99
|
+
this._entityStorageConnector = EntityStorageConnectorFactory.get(this._entityStorageConnectorType);
|
|
100
|
+
}
|
|
101
|
+
let cursor;
|
|
102
|
+
do {
|
|
103
|
+
const result = await this._entityStorageConnector.query(undefined, undefined, ["publicOrigin"], cursor);
|
|
104
|
+
for (const tenant of result.entities) {
|
|
105
|
+
const tenantPublicOrigin = tenant.publicOrigin;
|
|
106
|
+
if (Is.stringValue(tenantPublicOrigin) && tenantPublicOrigin === origin) {
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
cursor = result.cursor;
|
|
111
|
+
} while (Is.stringValue(cursor));
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
75
114
|
}
|
|
76
115
|
//# sourceMappingURL=platformService.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"platformService.js","sourceRoot":"","sources":["../../src/platformService.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"platformService.js","sourceRoot":"","sources":["../../src/platformService.ts"],"names":[],"mappings":"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","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport {\n\tHttpContextIdKeys,\n\tHttpUrlHelper,\n\ttype IPlatformComponent,\n\ttype ITenant\n} from \"@twin.org/api-models\";\nimport { ContextIdKeys, ContextIdStore } from \"@twin.org/context\";\nimport { Guards, 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 A promise that resolves when the method has been executed for all applicable tenants.\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\t/**\n\t * Determines if the given URL is a local origin.\n\t * @param url The URL to check.\n\t * @returns A promise that resolves to true if the URL is a local origin, false otherwise.\n\t */\n\tpublic async isLocalOrigin(url: string): Promise<boolean> {\n\t\tGuards.stringValue(PlatformService.CLASS_NAME, nameof(url), url);\n\n\t\tconst origin = HttpUrlHelper.extractOrigin(url);\n\t\tif (!Is.stringValue(origin)) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst contextIds = await ContextIdStore.getContextIds();\n\t\tconst publicOrigin = contextIds?.[HttpContextIdKeys.PublicOrigin];\n\t\tif (publicOrigin === origin) {\n\t\t\treturn true;\n\t\t}\n\n\t\tconst localOrigin = contextIds?.[HttpContextIdKeys.LocalOrigin];\n\t\tif (localOrigin === origin) {\n\t\t\treturn true;\n\t\t}\n\n\t\tif (Is.empty(this._entityStorageConnector)) {\n\t\t\tthis._entityStorageConnector = EntityStorageConnectorFactory.get(\n\t\t\t\tthis._entityStorageConnectorType\n\t\t\t);\n\t\t}\n\n\t\tlet cursor: string | undefined;\n\n\t\tdo {\n\t\t\tconst result = await this._entityStorageConnector.query(\n\t\t\t\tundefined,\n\t\t\t\tundefined,\n\t\t\t\t[\"publicOrigin\"],\n\t\t\t\tcursor\n\t\t\t);\n\t\t\tfor (const tenant of result.entities) {\n\t\t\t\tconst tenantPublicOrigin = tenant.publicOrigin;\n\n\t\t\t\tif (Is.stringValue(tenantPublicOrigin) && tenantPublicOrigin === origin) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tcursor = result.cursor;\n\t\t} while (Is.stringValue(cursor));\n\n\t\treturn false;\n\t}\n}\n"]}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
export * from "./healthRoutes.js";
|
|
2
2
|
export * from "./healthService.js";
|
|
3
|
-
export * from "./hostingService.js";
|
|
4
3
|
export * from "./informationRoutes.js";
|
|
5
4
|
export * from "./informationService.js";
|
|
6
5
|
export * from "./models/IHealthServiceConfig.js";
|
|
7
6
|
export * from "./models/IHealthServiceConstructorOptions.js";
|
|
8
|
-
export * from "./models/IHostingServiceConfig.js";
|
|
9
|
-
export * from "./models/IHostingServiceConstructorOptions.js";
|
|
10
7
|
export * from "./models/IInformationServiceConfig.js";
|
|
11
8
|
export * from "./models/IInformationServiceConstructorOptions.js";
|
|
12
9
|
export * from "./models/IPlatformServiceConfig.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type IPlatformComponent } from "@twin.org/api-models";
|
|
2
2
|
import type { IPlatformServiceConstructorOptions } from "./models/IPlatformServiceConstructorOptions.js";
|
|
3
3
|
/**
|
|
4
4
|
* Service for performing platform operations.
|
|
@@ -29,4 +29,10 @@ export declare class PlatformService implements IPlatformComponent {
|
|
|
29
29
|
* @returns A promise that resolves when the method has been executed for all applicable tenants.
|
|
30
30
|
*/
|
|
31
31
|
execute(method: () => Promise<void>): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Determines if the given URL is a local origin.
|
|
34
|
+
* @param url The URL to check.
|
|
35
|
+
* @returns A promise that resolves to true if the URL is a local origin, false otherwise.
|
|
36
|
+
*/
|
|
37
|
+
isLocalOrigin(url: string): Promise<boolean>;
|
|
32
38
|
}
|
package/docs/changelog.md
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.0.3-next.48](https://github.com/iotaledger/twin-api/compare/api-service-v0.0.3-next.47...api-service-v0.0.3-next.48) (2026-06-19)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* add platform isLocalOrigin ([#173](https://github.com/iotaledger/twin-api/issues/173)) ([5e024d5](https://github.com/iotaledger/twin-api/commit/5e024d55c0201a5109ad9c688c0e755fe50cb554))
|
|
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.47 to 0.0.3-next.48
|
|
16
|
+
|
|
17
|
+
## [0.0.3-next.47](https://github.com/iotaledger/twin-api/compare/api-service-v0.0.3-next.46...api-service-v0.0.3-next.47) (2026-06-18)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Features
|
|
21
|
+
|
|
22
|
+
* remove hosting component ([#170](https://github.com/iotaledger/twin-api/issues/170)) ([e78c1e8](https://github.com/iotaledger/twin-api/commit/e78c1e87d2747bf58da02b6b77680708ff681122))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Dependencies
|
|
26
|
+
|
|
27
|
+
* The following workspace dependencies were updated
|
|
28
|
+
* dependencies
|
|
29
|
+
* @twin.org/api-models bumped from 0.0.3-next.46 to 0.0.3-next.47
|
|
30
|
+
|
|
3
31
|
## [0.0.3-next.46](https://github.com/iotaledger/twin-api/compare/api-service-v0.0.3-next.45...api-service-v0.0.3-next.46) (2026-06-17)
|
|
4
32
|
|
|
5
33
|
|
|
@@ -95,3 +95,29 @@ A promise that resolves when the method has been executed for all applicable ten
|
|
|
95
95
|
#### Implementation of
|
|
96
96
|
|
|
97
97
|
`IPlatformComponent.execute`
|
|
98
|
+
|
|
99
|
+
***
|
|
100
|
+
|
|
101
|
+
### isLocalOrigin() {#islocalorigin}
|
|
102
|
+
|
|
103
|
+
> **isLocalOrigin**(`url`): `Promise`\<`boolean`\>
|
|
104
|
+
|
|
105
|
+
Determines if the given URL is a local origin.
|
|
106
|
+
|
|
107
|
+
#### Parameters
|
|
108
|
+
|
|
109
|
+
##### url
|
|
110
|
+
|
|
111
|
+
`string`
|
|
112
|
+
|
|
113
|
+
The URL to check.
|
|
114
|
+
|
|
115
|
+
#### Returns
|
|
116
|
+
|
|
117
|
+
`Promise`\<`boolean`\>
|
|
118
|
+
|
|
119
|
+
A promise that resolves to true if the URL is a local origin, false otherwise.
|
|
120
|
+
|
|
121
|
+
#### Implementation of
|
|
122
|
+
|
|
123
|
+
`IPlatformComponent.isLocalOrigin`
|
package/docs/reference/index.md
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
## Classes
|
|
4
4
|
|
|
5
5
|
- [HealthService](classes/HealthService.md)
|
|
6
|
-
- [HostingService](classes/HostingService.md)
|
|
7
6
|
- [InformationService](classes/InformationService.md)
|
|
8
7
|
- [PlatformService](classes/PlatformService.md)
|
|
9
8
|
|
|
@@ -11,8 +10,6 @@
|
|
|
11
10
|
|
|
12
11
|
- [IHealthServiceConfig](interfaces/IHealthServiceConfig.md)
|
|
13
12
|
- [IHealthServiceConstructorOptions](interfaces/IHealthServiceConstructorOptions.md)
|
|
14
|
-
- [IHostingServiceConfig](interfaces/IHostingServiceConfig.md)
|
|
15
|
-
- [IHostingServiceConstructorOptions](interfaces/IHostingServiceConstructorOptions.md)
|
|
16
13
|
- [IInformationServiceConfig](interfaces/IInformationServiceConfig.md)
|
|
17
14
|
- [IInformationServiceConstructorOptions](interfaces/IInformationServiceConstructorOptions.md)
|
|
18
15
|
- [IPlatformServiceConfig](interfaces/IPlatformServiceConfig.md)
|
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.48",
|
|
4
4
|
"description": "Information and hosting service implementations with generated REST route handlers.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -14,7 +14,7 @@
|
|
|
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.48",
|
|
18
18
|
"@twin.org/context": "next",
|
|
19
19
|
"@twin.org/core": "next",
|
|
20
20
|
"@twin.org/engine-models": "next",
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
// Copyright 2024 IOTA Stiftung.
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
-
import { HttpUrlHelper } from "@twin.org/api-models";
|
|
4
|
-
import { ContextIdKeys, ContextIdStore } from "@twin.org/context";
|
|
5
|
-
import { ComponentFactory, Guards, Is } from "@twin.org/core";
|
|
6
|
-
/**
|
|
7
|
-
* The hosting service for the server.
|
|
8
|
-
*/
|
|
9
|
-
export class HostingService {
|
|
10
|
-
/**
|
|
11
|
-
* Runtime name for the class.
|
|
12
|
-
*/
|
|
13
|
-
static CLASS_NAME = "HostingService";
|
|
14
|
-
/**
|
|
15
|
-
* The tenant admin component.
|
|
16
|
-
* @internal
|
|
17
|
-
*/
|
|
18
|
-
_tenantAdminComponentType;
|
|
19
|
-
/**
|
|
20
|
-
* The local origin URL e.g. "http://localhost:3000".
|
|
21
|
-
* @internal
|
|
22
|
-
*/
|
|
23
|
-
_localOrigin;
|
|
24
|
-
/**
|
|
25
|
-
* The APIs public base URL e.g. "https://api.example.com:1234".
|
|
26
|
-
* @internal
|
|
27
|
-
*/
|
|
28
|
-
_publicOrigin;
|
|
29
|
-
/**
|
|
30
|
-
* Create a new instance of HostingService.
|
|
31
|
-
* @param options The options to create the service.
|
|
32
|
-
*/
|
|
33
|
-
constructor(options) {
|
|
34
|
-
Guards.object(HostingService.CLASS_NAME, "options", options);
|
|
35
|
-
Guards.object(HostingService.CLASS_NAME, "options.config", options.config);
|
|
36
|
-
Guards.stringValue(HostingService.CLASS_NAME, "options.config.localOrigin", options.config.localOrigin);
|
|
37
|
-
this._tenantAdminComponentType = options?.tenantAdminComponentType ?? "tenant-admin";
|
|
38
|
-
this._localOrigin = options.config.localOrigin;
|
|
39
|
-
this._publicOrigin = options.config.publicOrigin;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Returns the class name of the component.
|
|
43
|
-
* @returns The class name of the component.
|
|
44
|
-
*/
|
|
45
|
-
className() {
|
|
46
|
-
return HostingService.CLASS_NAME;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Get the public origin for the hosting.
|
|
50
|
-
* @param serverRequestUrl The url of the current server request if there is one.
|
|
51
|
-
* @returns The public origin.
|
|
52
|
-
*/
|
|
53
|
-
async getPublicOrigin(serverRequestUrl) {
|
|
54
|
-
const contextIds = await ContextIdStore.getContextIds();
|
|
55
|
-
const tenantId = contextIds?.[ContextIdKeys.Tenant];
|
|
56
|
-
let tenantPublicOrigin;
|
|
57
|
-
if (Is.stringValue(tenantId)) {
|
|
58
|
-
tenantPublicOrigin = await this.getTenantOrigin(tenantId);
|
|
59
|
-
}
|
|
60
|
-
const serverRequestOrigin = Is.stringValue(serverRequestUrl)
|
|
61
|
-
? HttpUrlHelper.extractOrigin(serverRequestUrl)
|
|
62
|
-
: undefined;
|
|
63
|
-
return tenantPublicOrigin ?? this._publicOrigin ?? serverRequestOrigin ?? this._localOrigin;
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Get the public origin for the tenant if one exists.
|
|
67
|
-
* @param tenantId The tenant identifier.
|
|
68
|
-
* @returns The public origin for the tenant.
|
|
69
|
-
*/
|
|
70
|
-
async getTenantOrigin(tenantId) {
|
|
71
|
-
Guards.stringHexLength(HostingService.CLASS_NAME, "tenantId", tenantId, 32);
|
|
72
|
-
const tenantAdminComponent = ComponentFactory.getIfExists(this._tenantAdminComponentType);
|
|
73
|
-
if (Is.empty(tenantAdminComponent)) {
|
|
74
|
-
return undefined;
|
|
75
|
-
}
|
|
76
|
-
const tenant = await tenantAdminComponent.get(tenantId);
|
|
77
|
-
return tenant?.publicOrigin;
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Build a public url based on the public origin and the url provided.
|
|
81
|
-
* @param url The url to build upon the public origin.
|
|
82
|
-
* @returns The full url based on the public origin.
|
|
83
|
-
*/
|
|
84
|
-
async buildPublicUrl(url) {
|
|
85
|
-
const publicOrigin = await this.getPublicOrigin(url);
|
|
86
|
-
return HttpUrlHelper.replaceOrigin(url, publicOrigin);
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Check if the origin of the given url matches the node public origin or any tenant's public origin.
|
|
90
|
-
* @param url The url whose origin to check.
|
|
91
|
-
* @returns "node" for the node public origin, the tenant id for a tenant public origin, or undefined.
|
|
92
|
-
*/
|
|
93
|
-
async matchesLocalOrigin(url) {
|
|
94
|
-
Guards.stringValue(HostingService.CLASS_NAME, "url", url);
|
|
95
|
-
const origin = HttpUrlHelper.extractOrigin(url);
|
|
96
|
-
if (!Is.stringValue(origin)) {
|
|
97
|
-
return undefined;
|
|
98
|
-
}
|
|
99
|
-
if (Is.stringValue(this._publicOrigin) && origin === this._publicOrigin) {
|
|
100
|
-
return "node";
|
|
101
|
-
}
|
|
102
|
-
const tenantAdminComponent = ComponentFactory.getIfExists(this._tenantAdminComponentType);
|
|
103
|
-
if (Is.empty(tenantAdminComponent)) {
|
|
104
|
-
return undefined;
|
|
105
|
-
}
|
|
106
|
-
try {
|
|
107
|
-
const tenant = await tenantAdminComponent.getByPublicOrigin(origin);
|
|
108
|
-
return tenant?.id;
|
|
109
|
-
}
|
|
110
|
-
catch {
|
|
111
|
-
return undefined;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
//# sourceMappingURL=hostingService.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hostingService.js","sourceRoot":"","sources":["../../src/hostingService.ts"],"names":[],"mappings":"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","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport {\n\tHttpUrlHelper,\n\ttype IHostingComponent,\n\ttype ITenantAdminComponent\n} from \"@twin.org/api-models\";\nimport { ContextIdKeys, ContextIdStore } from \"@twin.org/context\";\nimport { ComponentFactory, Guards, Is } from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\nimport type { IHostingServiceConstructorOptions } from \"./models/IHostingServiceConstructorOptions.js\";\n\n/**\n * The hosting service for the server.\n */\nexport class HostingService implements IHostingComponent {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<HostingService>();\n\n\t/**\n\t * The tenant admin component.\n\t * @internal\n\t */\n\tprivate readonly _tenantAdminComponentType?: string;\n\n\t/**\n\t * The local origin URL e.g. \"http://localhost:3000\".\n\t * @internal\n\t */\n\tprivate readonly _localOrigin: string;\n\n\t/**\n\t * The APIs public base URL e.g. \"https://api.example.com:1234\".\n\t * @internal\n\t */\n\tprivate readonly _publicOrigin?: string;\n\n\t/**\n\t * Create a new instance of HostingService.\n\t * @param options The options to create the service.\n\t */\n\tconstructor(options: IHostingServiceConstructorOptions) {\n\t\tGuards.object(HostingService.CLASS_NAME, nameof(options), options);\n\t\tGuards.object(HostingService.CLASS_NAME, nameof(options.config), options.config);\n\t\tGuards.stringValue(\n\t\t\tHostingService.CLASS_NAME,\n\t\t\tnameof(options.config.localOrigin),\n\t\t\toptions.config.localOrigin\n\t\t);\n\t\tthis._tenantAdminComponentType = options?.tenantAdminComponentType ?? \"tenant-admin\";\n\t\tthis._localOrigin = options.config.localOrigin;\n\t\tthis._publicOrigin = options.config.publicOrigin;\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 HostingService.CLASS_NAME;\n\t}\n\n\t/**\n\t * Get the public origin for the hosting.\n\t * @param serverRequestUrl The url of the current server request if there is one.\n\t * @returns The public origin.\n\t */\n\tpublic async getPublicOrigin(serverRequestUrl?: string): Promise<string> {\n\t\tconst contextIds = await ContextIdStore.getContextIds();\n\t\tconst tenantId = contextIds?.[ContextIdKeys.Tenant];\n\t\tlet tenantPublicOrigin;\n\t\tif (Is.stringValue(tenantId)) {\n\t\t\ttenantPublicOrigin = await this.getTenantOrigin(tenantId);\n\t\t}\n\n\t\tconst serverRequestOrigin = Is.stringValue(serverRequestUrl)\n\t\t\t? HttpUrlHelper.extractOrigin(serverRequestUrl)\n\t\t\t: undefined;\n\n\t\treturn tenantPublicOrigin ?? this._publicOrigin ?? serverRequestOrigin ?? this._localOrigin;\n\t}\n\n\t/**\n\t * Get the public origin for the tenant if one exists.\n\t * @param tenantId The tenant identifier.\n\t * @returns The public origin for the tenant.\n\t */\n\tpublic async getTenantOrigin(tenantId: string): Promise<string | undefined> {\n\t\tGuards.stringHexLength(HostingService.CLASS_NAME, nameof(tenantId), tenantId, 32);\n\n\t\tconst tenantAdminComponent = ComponentFactory.getIfExists<ITenantAdminComponent>(\n\t\t\tthis._tenantAdminComponentType\n\t\t);\n\n\t\tif (Is.empty(tenantAdminComponent)) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst tenant = await tenantAdminComponent.get(tenantId);\n\t\treturn tenant?.publicOrigin;\n\t}\n\n\t/**\n\t * Build a public url based on the public origin and the url provided.\n\t * @param url The url to build upon the public origin.\n\t * @returns The full url based on the public origin.\n\t */\n\tpublic async buildPublicUrl(url: string): Promise<string> {\n\t\tconst publicOrigin = await this.getPublicOrigin(url);\n\t\treturn HttpUrlHelper.replaceOrigin(url, publicOrigin);\n\t}\n\n\t/**\n\t * Check if the origin of the given url matches the node public origin or any tenant's public origin.\n\t * @param url The url whose origin to check.\n\t * @returns \"node\" for the node public origin, the tenant id for a tenant public origin, or undefined.\n\t */\n\tpublic async matchesLocalOrigin(url: string): Promise<string | undefined> {\n\t\tGuards.stringValue(HostingService.CLASS_NAME, nameof(url), url);\n\n\t\tconst origin = HttpUrlHelper.extractOrigin(url);\n\t\tif (!Is.stringValue(origin)) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tif (Is.stringValue(this._publicOrigin) && origin === this._publicOrigin) {\n\t\t\treturn \"node\";\n\t\t}\n\n\t\tconst tenantAdminComponent = ComponentFactory.getIfExists<ITenantAdminComponent>(\n\t\t\tthis._tenantAdminComponentType\n\t\t);\n\n\t\tif (Is.empty(tenantAdminComponent)) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\ttry {\n\t\t\tconst tenant = await tenantAdminComponent.getByPublicOrigin(origin);\n\t\t\treturn tenant?.id;\n\t\t} catch {\n\t\t\treturn undefined;\n\t\t}\n\t}\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"IHostingServiceConfig.js","sourceRoot":"","sources":["../../../src/models/IHostingServiceConfig.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 hosting service.\n */\nexport interface IHostingServiceConfig {\n\t/**\n\t * The local origin, must be provided as a fallback e.g. http://localhost:1234.\n\t */\n\tlocalOrigin: string;\n\n\t/**\n\t * The APIs public base URL e.g. \"https://api.example.com:1234\".\n\t */\n\tpublicOrigin?: string;\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"IHostingServiceConstructorOptions.js","sourceRoot":"","sources":["../../../src/models/IHostingServiceConstructorOptions.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IHostingServiceConfig } from \"./IHostingServiceConfig.js\";\n\n/**\n * Options for the HostingService constructor.\n */\nexport interface IHostingServiceConstructorOptions {\n\t/**\n\t * The tenant admin component type.\n\t * @default tenant-admin\n\t */\n\ttenantAdminComponentType?: string;\n\n\t/**\n\t * The configuration for the service.\n\t */\n\tconfig: IHostingServiceConfig;\n}\n"]}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { type IHostingComponent } from "@twin.org/api-models";
|
|
2
|
-
import type { IHostingServiceConstructorOptions } from "./models/IHostingServiceConstructorOptions.js";
|
|
3
|
-
/**
|
|
4
|
-
* The hosting service for the server.
|
|
5
|
-
*/
|
|
6
|
-
export declare class HostingService implements IHostingComponent {
|
|
7
|
-
/**
|
|
8
|
-
* Runtime name for the class.
|
|
9
|
-
*/
|
|
10
|
-
static readonly CLASS_NAME: string;
|
|
11
|
-
/**
|
|
12
|
-
* Create a new instance of HostingService.
|
|
13
|
-
* @param options The options to create the service.
|
|
14
|
-
*/
|
|
15
|
-
constructor(options: IHostingServiceConstructorOptions);
|
|
16
|
-
/**
|
|
17
|
-
* Returns the class name of the component.
|
|
18
|
-
* @returns The class name of the component.
|
|
19
|
-
*/
|
|
20
|
-
className(): string;
|
|
21
|
-
/**
|
|
22
|
-
* Get the public origin for the hosting.
|
|
23
|
-
* @param serverRequestUrl The url of the current server request if there is one.
|
|
24
|
-
* @returns The public origin.
|
|
25
|
-
*/
|
|
26
|
-
getPublicOrigin(serverRequestUrl?: string): Promise<string>;
|
|
27
|
-
/**
|
|
28
|
-
* Get the public origin for the tenant if one exists.
|
|
29
|
-
* @param tenantId The tenant identifier.
|
|
30
|
-
* @returns The public origin for the tenant.
|
|
31
|
-
*/
|
|
32
|
-
getTenantOrigin(tenantId: string): Promise<string | undefined>;
|
|
33
|
-
/**
|
|
34
|
-
* Build a public url based on the public origin and the url provided.
|
|
35
|
-
* @param url The url to build upon the public origin.
|
|
36
|
-
* @returns The full url based on the public origin.
|
|
37
|
-
*/
|
|
38
|
-
buildPublicUrl(url: string): Promise<string>;
|
|
39
|
-
/**
|
|
40
|
-
* Check if the origin of the given url matches the node public origin or any tenant's public origin.
|
|
41
|
-
* @param url The url whose origin to check.
|
|
42
|
-
* @returns "node" for the node public origin, the tenant id for a tenant public origin, or undefined.
|
|
43
|
-
*/
|
|
44
|
-
matchesLocalOrigin(url: string): Promise<string | undefined>;
|
|
45
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Configuration for the hosting service.
|
|
3
|
-
*/
|
|
4
|
-
export interface IHostingServiceConfig {
|
|
5
|
-
/**
|
|
6
|
-
* The local origin, must be provided as a fallback e.g. http://localhost:1234.
|
|
7
|
-
*/
|
|
8
|
-
localOrigin: string;
|
|
9
|
-
/**
|
|
10
|
-
* The APIs public base URL e.g. "https://api.example.com:1234".
|
|
11
|
-
*/
|
|
12
|
-
publicOrigin?: string;
|
|
13
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { IHostingServiceConfig } from "./IHostingServiceConfig.js";
|
|
2
|
-
/**
|
|
3
|
-
* Options for the HostingService constructor.
|
|
4
|
-
*/
|
|
5
|
-
export interface IHostingServiceConstructorOptions {
|
|
6
|
-
/**
|
|
7
|
-
* The tenant admin component type.
|
|
8
|
-
* @default tenant-admin
|
|
9
|
-
*/
|
|
10
|
-
tenantAdminComponentType?: string;
|
|
11
|
-
/**
|
|
12
|
-
* The configuration for the service.
|
|
13
|
-
*/
|
|
14
|
-
config: IHostingServiceConfig;
|
|
15
|
-
}
|
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
# Class: HostingService
|
|
2
|
-
|
|
3
|
-
The hosting service for the server.
|
|
4
|
-
|
|
5
|
-
## Implements
|
|
6
|
-
|
|
7
|
-
- `IHostingComponent`
|
|
8
|
-
|
|
9
|
-
## Constructors
|
|
10
|
-
|
|
11
|
-
### Constructor
|
|
12
|
-
|
|
13
|
-
> **new HostingService**(`options`): `HostingService`
|
|
14
|
-
|
|
15
|
-
Create a new instance of HostingService.
|
|
16
|
-
|
|
17
|
-
#### Parameters
|
|
18
|
-
|
|
19
|
-
##### options
|
|
20
|
-
|
|
21
|
-
[`IHostingServiceConstructorOptions`](../interfaces/IHostingServiceConstructorOptions.md)
|
|
22
|
-
|
|
23
|
-
The options to create the service.
|
|
24
|
-
|
|
25
|
-
#### Returns
|
|
26
|
-
|
|
27
|
-
`HostingService`
|
|
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
|
-
`IHostingComponent.className`
|
|
54
|
-
|
|
55
|
-
***
|
|
56
|
-
|
|
57
|
-
### getPublicOrigin() {#getpublicorigin}
|
|
58
|
-
|
|
59
|
-
> **getPublicOrigin**(`serverRequestUrl?`): `Promise`\<`string`\>
|
|
60
|
-
|
|
61
|
-
Get the public origin for the hosting.
|
|
62
|
-
|
|
63
|
-
#### Parameters
|
|
64
|
-
|
|
65
|
-
##### serverRequestUrl?
|
|
66
|
-
|
|
67
|
-
`string`
|
|
68
|
-
|
|
69
|
-
The url of the current server request if there is one.
|
|
70
|
-
|
|
71
|
-
#### Returns
|
|
72
|
-
|
|
73
|
-
`Promise`\<`string`\>
|
|
74
|
-
|
|
75
|
-
The public origin.
|
|
76
|
-
|
|
77
|
-
#### Implementation of
|
|
78
|
-
|
|
79
|
-
`IHostingComponent.getPublicOrigin`
|
|
80
|
-
|
|
81
|
-
***
|
|
82
|
-
|
|
83
|
-
### getTenantOrigin() {#gettenantorigin}
|
|
84
|
-
|
|
85
|
-
> **getTenantOrigin**(`tenantId`): `Promise`\<`string` \| `undefined`\>
|
|
86
|
-
|
|
87
|
-
Get the public origin for the tenant if one exists.
|
|
88
|
-
|
|
89
|
-
#### Parameters
|
|
90
|
-
|
|
91
|
-
##### tenantId
|
|
92
|
-
|
|
93
|
-
`string`
|
|
94
|
-
|
|
95
|
-
The tenant identifier.
|
|
96
|
-
|
|
97
|
-
#### Returns
|
|
98
|
-
|
|
99
|
-
`Promise`\<`string` \| `undefined`\>
|
|
100
|
-
|
|
101
|
-
The public origin for the tenant.
|
|
102
|
-
|
|
103
|
-
#### Implementation of
|
|
104
|
-
|
|
105
|
-
`IHostingComponent.getTenantOrigin`
|
|
106
|
-
|
|
107
|
-
***
|
|
108
|
-
|
|
109
|
-
### buildPublicUrl() {#buildpublicurl}
|
|
110
|
-
|
|
111
|
-
> **buildPublicUrl**(`url`): `Promise`\<`string`\>
|
|
112
|
-
|
|
113
|
-
Build a public url based on the public origin and the url provided.
|
|
114
|
-
|
|
115
|
-
#### Parameters
|
|
116
|
-
|
|
117
|
-
##### url
|
|
118
|
-
|
|
119
|
-
`string`
|
|
120
|
-
|
|
121
|
-
The url to build upon the public origin.
|
|
122
|
-
|
|
123
|
-
#### Returns
|
|
124
|
-
|
|
125
|
-
`Promise`\<`string`\>
|
|
126
|
-
|
|
127
|
-
The full url based on the public origin.
|
|
128
|
-
|
|
129
|
-
#### Implementation of
|
|
130
|
-
|
|
131
|
-
`IHostingComponent.buildPublicUrl`
|
|
132
|
-
|
|
133
|
-
***
|
|
134
|
-
|
|
135
|
-
### matchesLocalOrigin() {#matcheslocalorigin}
|
|
136
|
-
|
|
137
|
-
> **matchesLocalOrigin**(`url`): `Promise`\<`string` \| `undefined`\>
|
|
138
|
-
|
|
139
|
-
Check if the origin of the given url matches the node public origin or any tenant's public origin.
|
|
140
|
-
|
|
141
|
-
#### Parameters
|
|
142
|
-
|
|
143
|
-
##### url
|
|
144
|
-
|
|
145
|
-
`string`
|
|
146
|
-
|
|
147
|
-
The url whose origin to check.
|
|
148
|
-
|
|
149
|
-
#### Returns
|
|
150
|
-
|
|
151
|
-
`Promise`\<`string` \| `undefined`\>
|
|
152
|
-
|
|
153
|
-
"node" for the node public origin, the tenant id for a tenant public origin, or undefined.
|
|
154
|
-
|
|
155
|
-
#### Implementation of
|
|
156
|
-
|
|
157
|
-
`IHostingComponent.matchesLocalOrigin`
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
# Interface: IHostingServiceConfig
|
|
2
|
-
|
|
3
|
-
Configuration for the hosting service.
|
|
4
|
-
|
|
5
|
-
## Properties
|
|
6
|
-
|
|
7
|
-
### localOrigin {#localorigin}
|
|
8
|
-
|
|
9
|
-
> **localOrigin**: `string`
|
|
10
|
-
|
|
11
|
-
The local origin, must be provided as a fallback e.g. http://localhost:1234.
|
|
12
|
-
|
|
13
|
-
***
|
|
14
|
-
|
|
15
|
-
### publicOrigin? {#publicorigin}
|
|
16
|
-
|
|
17
|
-
> `optional` **publicOrigin?**: `string`
|
|
18
|
-
|
|
19
|
-
The APIs public base URL e.g. "https://api.example.com:1234".
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
# Interface: IHostingServiceConstructorOptions
|
|
2
|
-
|
|
3
|
-
Options for the HostingService constructor.
|
|
4
|
-
|
|
5
|
-
## Properties
|
|
6
|
-
|
|
7
|
-
### tenantAdminComponentType? {#tenantadmincomponenttype}
|
|
8
|
-
|
|
9
|
-
> `optional` **tenantAdminComponentType?**: `string`
|
|
10
|
-
|
|
11
|
-
The tenant admin component type.
|
|
12
|
-
|
|
13
|
-
#### Default
|
|
14
|
-
|
|
15
|
-
```ts
|
|
16
|
-
tenant-admin
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
***
|
|
20
|
-
|
|
21
|
-
### config {#config}
|
|
22
|
-
|
|
23
|
-
> **config**: [`IHostingServiceConfig`](IHostingServiceConfig.md)
|
|
24
|
-
|
|
25
|
-
The configuration for the service.
|