@twin.org/api-service 0.0.3-next.4 → 0.0.3-next.41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/README.md +1 -1
  2. package/dist/es/healthRoutes.js +107 -0
  3. package/dist/es/healthRoutes.js.map +1 -0
  4. package/dist/es/healthService.js +155 -0
  5. package/dist/es/healthService.js.map +1 -0
  6. package/dist/es/hostingService.js +115 -0
  7. package/dist/es/hostingService.js.map +1 -0
  8. package/dist/es/index.js +10 -0
  9. package/dist/es/index.js.map +1 -1
  10. package/dist/es/informationRoutes.js +92 -62
  11. package/dist/es/informationRoutes.js.map +1 -1
  12. package/dist/es/informationService.js +12 -58
  13. package/dist/es/informationService.js.map +1 -1
  14. package/dist/es/models/IHealthServiceConfig.js +4 -0
  15. package/dist/es/models/IHealthServiceConfig.js.map +1 -0
  16. package/dist/es/models/IHealthServiceConstructorOptions.js +2 -0
  17. package/dist/es/models/IHealthServiceConstructorOptions.js.map +1 -0
  18. package/dist/es/models/IHostingServiceConfig.js +4 -0
  19. package/dist/es/models/IHostingServiceConfig.js.map +1 -0
  20. package/dist/es/models/IHostingServiceConstructorOptions.js +2 -0
  21. package/dist/es/models/IHostingServiceConstructorOptions.js.map +1 -0
  22. package/dist/es/models/IUrlTransformerServiceConfig.js +4 -0
  23. package/dist/es/models/IUrlTransformerServiceConfig.js.map +1 -0
  24. package/dist/es/models/IUrlTransformerServiceConstructorOptions.js +2 -0
  25. package/dist/es/models/IUrlTransformerServiceConstructorOptions.js.map +1 -0
  26. package/dist/es/restEntryPoints.js +7 -0
  27. package/dist/es/restEntryPoints.js.map +1 -1
  28. package/dist/es/urlTransformerService.js +256 -0
  29. package/dist/es/urlTransformerService.js.map +1 -0
  30. package/dist/types/healthRoutes.d.ts +20 -0
  31. package/dist/types/healthService.d.ts +42 -0
  32. package/dist/types/hostingService.d.ts +45 -0
  33. package/dist/types/index.d.ts +10 -0
  34. package/dist/types/informationRoutes.d.ts +11 -3
  35. package/dist/types/informationService.d.ts +11 -16
  36. package/dist/types/models/IHealthServiceConfig.d.ts +16 -0
  37. package/dist/types/models/IHealthServiceConstructorOptions.d.ts +10 -0
  38. package/dist/types/models/IHostingServiceConfig.d.ts +13 -0
  39. package/dist/types/models/IHostingServiceConstructorOptions.d.ts +15 -0
  40. package/dist/types/models/IUrlTransformerServiceConfig.d.ts +19 -0
  41. package/dist/types/models/IUrlTransformerServiceConstructorOptions.d.ts +15 -0
  42. package/dist/types/urlTransformerService.d.ts +94 -0
  43. package/docs/changelog.md +588 -55
  44. package/docs/examples.md +74 -1
  45. package/docs/reference/classes/HealthService.md +123 -0
  46. package/docs/reference/classes/HostingService.md +157 -0
  47. package/docs/reference/classes/InformationService.md +19 -65
  48. package/docs/reference/classes/UrlTransformerService.md +379 -0
  49. package/docs/reference/functions/generateRestRoutesHealth.md +25 -0
  50. package/docs/reference/functions/serverLivez.md +31 -0
  51. package/docs/reference/functions/serverReadyz.md +31 -0
  52. package/docs/reference/index.md +14 -1
  53. package/docs/reference/interfaces/IHealthServiceConfig.md +32 -0
  54. package/docs/reference/interfaces/IHealthServiceConstructorOptions.md +11 -0
  55. package/docs/reference/interfaces/IHostingServiceConfig.md +19 -0
  56. package/docs/reference/interfaces/IHostingServiceConstructorOptions.md +25 -0
  57. package/docs/reference/interfaces/IInformationServiceConfig.md +5 -5
  58. package/docs/reference/interfaces/IInformationServiceConstructorOptions.md +1 -1
  59. package/docs/reference/interfaces/IUrlTransformerServiceConfig.md +32 -0
  60. package/docs/reference/interfaces/IUrlTransformerServiceConstructorOptions.md +25 -0
  61. package/docs/reference/variables/tagsHealth.md +5 -0
  62. package/locales/en.json +13 -1
  63. package/package.json +9 -5
@@ -0,0 +1,256 @@
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
@@ -0,0 +1 @@
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;;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,CAAC,OAAO,IAAI,IAAI,CAAC,uBAAuB,EAAE,EACjD,mBAAmB,CAAC,gBAAgB,EACpC,cAAc,CACd,CAAC;YAEF,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,cAAc,CAAC,EAAE,CAAC;gBACpC,MAAM,IAAI,YAAY,CAAC,qBAAqB,CAAC,UAAU,EAAE,kBAAkB,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"]}
@@ -0,0 +1,20 @@
1
+ import type { IHttpRequestContext, INoContentRequest, IRestRoute, IServerHealthResponse, ITag } from "@twin.org/api-models";
2
+ /**
3
+ * The tag to associate with the routes.
4
+ */
5
+ export declare const tagsHealth: ITag[];
6
+ /**
7
+ * The REST routes for server health.
8
+ * @param baseRouteName Prefix to prepend to the paths.
9
+ * @param componentName The name of the component to use in the routes stored in the ComponentFactory.
10
+ * @returns The generated routes.
11
+ */
12
+ export declare function generateRestRoutesHealth(baseRouteName: string, componentName: string): IRestRoute[];
13
+ /**
14
+ * Get the health for the server.
15
+ * @param httpRequestContext The request context for the API.
16
+ * @param componentName The name of the component to use in the routes.
17
+ * @param request The request.
18
+ * @returns The response object with additional http response properties.
19
+ */
20
+ export declare function serverHealth(httpRequestContext: IHttpRequestContext, componentName: string, request: INoContentRequest): Promise<IServerHealthResponse>;
@@ -0,0 +1,42 @@
1
+ import type { IHealthComponent } from "@twin.org/api-models";
2
+ import { HealthStatus, type IHealth } from "@twin.org/core";
3
+ import type { IHealthServiceConstructorOptions } from "./models/IHealthServiceConstructorOptions.js";
4
+ /**
5
+ * The health service for the server.
6
+ */
7
+ export declare class HealthService implements IHealthComponent {
8
+ /**
9
+ * Runtime name for the class.
10
+ */
11
+ static readonly CLASS_NAME: string;
12
+ /**
13
+ * Create a new instance of HealthService.
14
+ * @param options The constructor options.
15
+ */
16
+ constructor(options?: IHealthServiceConstructorOptions);
17
+ /**
18
+ * Returns the class name of the component.
19
+ * @returns The class name of the component.
20
+ */
21
+ className(): string;
22
+ /**
23
+ * The component needs to be started when the node is initialized.
24
+ * @param nodeLoggingComponentType The node logging component type.
25
+ * @returns Nothing.
26
+ */
27
+ start(nodeLoggingComponentType?: string): Promise<void>;
28
+ /**
29
+ * The component needs to be stopped when the node is closed.
30
+ * @param nodeLoggingComponentType The node logging component type.
31
+ * @returns Nothing.
32
+ */
33
+ stop(nodeLoggingComponentType?: string): Promise<void>;
34
+ /**
35
+ * Get the server health.
36
+ * @returns The service health.
37
+ */
38
+ healthStatus(): Promise<{
39
+ status: HealthStatus;
40
+ components: IHealth[];
41
+ }>;
42
+ }
@@ -0,0 +1,45 @@
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,5 +1,15 @@
1
+ export * from "./healthRoutes.js";
2
+ export * from "./healthService.js";
3
+ export * from "./hostingService.js";
1
4
  export * from "./informationRoutes.js";
2
5
  export * from "./informationService.js";
6
+ export * from "./urlTransformerService.js";
7
+ export * from "./models/IHealthServiceConfig.js";
8
+ export * from "./models/IHealthServiceConstructorOptions.js";
9
+ export * from "./models/IHostingServiceConfig.js";
10
+ export * from "./models/IHostingServiceConstructorOptions.js";
3
11
  export * from "./models/IInformationServiceConfig.js";
4
12
  export * from "./models/IInformationServiceConstructorOptions.js";
13
+ export * from "./models/IUrlTransformerServiceConfig.js";
14
+ export * from "./models/IUrlTransformerServiceConstructorOptions.js";
5
15
  export * from "./restEntryPoints.js";
@@ -1,4 +1,4 @@
1
- import type { IHttpRequestContext, INoContentRequest, IRestRoute, IServerFavIconResponse, IServerHealthResponse, IServerInfoResponse, IServerRootResponse, IServerSpecResponse, ITag } from "@twin.org/api-models";
1
+ import type { IHttpRequestContext, INoContentRequest, IRestRoute, IServerFavIconResponse, IServerInfoResponse, IServerLivezResponse, IServerReadyzResponse, IServerRootResponse, IServerSpecResponse, ITag } from "@twin.org/api-models";
2
2
  /**
3
3
  * The tag to associate with the routes.
4
4
  */
@@ -27,13 +27,21 @@ export declare function serverRoot(httpRequestContext: IHttpRequestContext, comp
27
27
  */
28
28
  export declare function serverInfo(httpRequestContext: IHttpRequestContext, componentName: string, request: INoContentRequest): Promise<IServerInfoResponse>;
29
29
  /**
30
- * Get the health for the server.
30
+ * Get the livez for the server.
31
31
  * @param httpRequestContext The request context for the API.
32
32
  * @param componentName The name of the component to use in the routes.
33
33
  * @param request The request.
34
34
  * @returns The response object with additional http response properties.
35
35
  */
36
- export declare function serverHealth(httpRequestContext: IHttpRequestContext, componentName: string, request: INoContentRequest): Promise<IServerHealthResponse>;
36
+ export declare function serverLivez(httpRequestContext: IHttpRequestContext, componentName: string, request: INoContentRequest): Promise<IServerLivezResponse>;
37
+ /**
38
+ * Get the readyz for the server.
39
+ * @param httpRequestContext The request context for the API.
40
+ * @param componentName The name of the component to use in the routes.
41
+ * @param request The request.
42
+ * @returns The response object with additional http response properties.
43
+ */
44
+ export declare function serverReadyz(httpRequestContext: IHttpRequestContext, componentName: string, request: INoContentRequest): Promise<IServerReadyzResponse>;
37
45
  /**
38
46
  * Get the favicon for the server.
39
47
  * @param httpRequestContext The request context for the API.
@@ -1,4 +1,4 @@
1
- import type { HealthStatus, IHealthInfo, IInformationComponent, IServerInfo } from "@twin.org/api-models";
1
+ import type { IInformationComponent, IServerInfo } from "@twin.org/api-models";
2
2
  import type { IInformationServiceConstructorOptions } from "./models/IInformationServiceConstructorOptions.js";
3
3
  /**
4
4
  * The information service for the server.
@@ -44,22 +44,17 @@ export declare class InformationService implements IInformationComponent {
44
44
  */
45
45
  spec(): Promise<unknown>;
46
46
  /**
47
- * Get the server health.
48
- * @returns The service health.
47
+ * Is the server live.
48
+ * @returns True if the server is live.
49
49
  */
50
- health(): Promise<IHealthInfo>;
50
+ livez(): Promise<{
51
+ status: "alive" | "dead";
52
+ }>;
51
53
  /**
52
- * Set the status of a component.
53
- * @param name The component name.
54
- * @param status The status of the component.
55
- * @param details The details for the status.
56
- * @returns Nothing.
57
- */
58
- setComponentHealth(name: string, status: HealthStatus, details?: string): Promise<void>;
59
- /**
60
- * Remove the status of a component.
61
- * @param name The component name.
62
- * @returns Nothing.
54
+ * Is the server ready.
55
+ * @returns The readyz status of the server.
63
56
  */
64
- removeComponentHealth(name: string): Promise<void>;
57
+ readyz(): Promise<{
58
+ status: "ready" | "not ready";
59
+ }>;
65
60
  }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Configuration for the health service.
3
+ */
4
+ export interface IHealthServiceConfig {
5
+ /**
6
+ * The interval for checking the health of the components and setting it in the health service.
7
+ * @default 60000
8
+ */
9
+ healthCheckInterval?: number;
10
+ /**
11
+ * The initial interval for checking the health of the components and setting it in the health service.
12
+ * This is used to check the health of the components immediately after the service is started.
13
+ * @default 2000
14
+ */
15
+ initialInterval?: number;
16
+ }
@@ -0,0 +1,10 @@
1
+ import type { IHealthServiceConfig } from "./IHealthServiceConfig.js";
2
+ /**
3
+ * Options for the HealthService constructor.
4
+ */
5
+ export interface IHealthServiceConstructorOptions {
6
+ /**
7
+ * The configuration for the service.
8
+ */
9
+ config?: IHealthServiceConfig;
10
+ }
@@ -0,0 +1,13 @@
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
+ }
@@ -0,0 +1,15 @@
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
+ }
@@ -0,0 +1,19 @@
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
+ }
@@ -0,0 +1,15 @@
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
+ }