@twin.org/api-service 0.0.3-next.29 → 0.0.3-next.31

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 (56) hide show
  1. package/dist/es/healthRoutes.js +108 -0
  2. package/dist/es/healthRoutes.js.map +1 -0
  3. package/dist/es/healthService.js +136 -0
  4. package/dist/es/healthService.js.map +1 -0
  5. package/dist/es/hostingService.js +1 -209
  6. package/dist/es/hostingService.js.map +1 -1
  7. package/dist/es/index.js +7 -0
  8. package/dist/es/index.js.map +1 -1
  9. package/dist/es/informationRoutes.js +31 -65
  10. package/dist/es/informationRoutes.js.map +1 -1
  11. package/dist/es/informationService.js +9 -85
  12. package/dist/es/informationService.js.map +1 -1
  13. package/dist/es/models/IHealthServiceConfig.js +4 -0
  14. package/dist/es/models/IHealthServiceConfig.js.map +1 -0
  15. package/dist/es/models/IHealthServiceConstructorOptions.js +2 -0
  16. package/dist/es/models/IHealthServiceConstructorOptions.js.map +1 -0
  17. package/dist/es/models/IHostingServiceConfig.js.map +1 -1
  18. package/dist/es/models/IHostingServiceConstructorOptions.js.map +1 -1
  19. package/dist/es/models/IUrlTransformerServiceConfig.js +4 -0
  20. package/dist/es/models/IUrlTransformerServiceConfig.js.map +1 -0
  21. package/dist/es/models/IUrlTransformerServiceConstructorOptions.js +2 -0
  22. package/dist/es/models/IUrlTransformerServiceConstructorOptions.js.map +1 -0
  23. package/dist/es/restEntryPoints.js +7 -0
  24. package/dist/es/restEntryPoints.js.map +1 -1
  25. package/dist/es/urlTransformerService.js +220 -0
  26. package/dist/es/urlTransformerService.js.map +1 -0
  27. package/dist/types/healthRoutes.d.ts +20 -0
  28. package/dist/types/healthService.d.ts +42 -0
  29. package/dist/types/hostingService.d.ts +1 -62
  30. package/dist/types/index.d.ts +7 -0
  31. package/dist/types/informationRoutes.d.ts +3 -3
  32. package/dist/types/informationService.d.ts +9 -21
  33. package/dist/types/models/IHealthServiceConfig.d.ts +10 -0
  34. package/dist/types/models/IHealthServiceConstructorOptions.d.ts +10 -0
  35. package/dist/types/models/IHostingServiceConfig.d.ts +0 -10
  36. package/dist/types/models/IHostingServiceConstructorOptions.d.ts +1 -6
  37. package/dist/types/models/IUrlTransformerServiceConfig.d.ts +19 -0
  38. package/dist/types/models/IUrlTransformerServiceConstructorOptions.d.ts +15 -0
  39. package/dist/types/urlTransformerService.d.ts +81 -0
  40. package/docs/changelog.md +28 -0
  41. package/docs/reference/classes/HealthService.md +123 -0
  42. package/docs/reference/classes/HostingService.md +0 -266
  43. package/docs/reference/classes/InformationService.md +8 -84
  44. package/docs/reference/classes/UrlTransformerService.md +321 -0
  45. package/docs/reference/functions/generateRestRoutesHealth.md +25 -0
  46. package/docs/reference/functions/serverReadyz.md +31 -0
  47. package/docs/reference/index.md +10 -1
  48. package/docs/reference/interfaces/IHealthServiceConfig.md +17 -0
  49. package/docs/reference/interfaces/IHealthServiceConstructorOptions.md +11 -0
  50. package/docs/reference/interfaces/IHostingServiceConfig.md +0 -28
  51. package/docs/reference/interfaces/IHostingServiceConstructorOptions.md +1 -15
  52. package/docs/reference/interfaces/IUrlTransformerServiceConfig.md +32 -0
  53. package/docs/reference/interfaces/IUrlTransformerServiceConstructorOptions.md +25 -0
  54. package/docs/reference/variables/tagsHealth.md +5 -0
  55. package/locales/en.json +6 -3
  56. package/package.json +4 -2
@@ -0,0 +1,220 @@
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
+ * Decrypt specified keys from a query parameter object and return their plain-text values.
121
+ * @param queryParams The HTTP request query containing the encrypted parameters.
122
+ * @param keys The keys to decrypt.
123
+ * @returns A map of the decrypted key/value pairs that were present.
124
+ */
125
+ async getDecryptedFromQueryParams(queryParams, keys) {
126
+ const queryParamsClone = ObjectHelper.clone(queryParams) ?? {};
127
+ await this.decryptQueryParams(queryParamsClone, keys);
128
+ const result = {};
129
+ for (const key of keys) {
130
+ if (Is.stringValue(queryParamsClone[key])) {
131
+ result[key] = queryParamsClone[key];
132
+ }
133
+ }
134
+ return result;
135
+ }
136
+ /**
137
+ * Encrypt query parameters.
138
+ * @param httpRequestQuery The HTTP request query containing the parameters to encrypt.
139
+ * @param keys The keys of the parameters to encrypt.
140
+ * @returns A promise that resolves when the query parameters have been encrypted.
141
+ */
142
+ async encryptQueryParams(httpRequestQuery, keys) {
143
+ if (Is.empty(httpRequestQuery)) {
144
+ return;
145
+ }
146
+ for (const key of keys) {
147
+ if (Is.stringValue(httpRequestQuery[key])) {
148
+ const encryptedValue = await this.encryptParam(httpRequestQuery[key]);
149
+ httpRequestQuery[`${UrlTransformerService._KEY_PREFIX}${key}`] = encryptedValue;
150
+ delete httpRequestQuery[key];
151
+ }
152
+ }
153
+ }
154
+ /**
155
+ * Decrypt query parameters.
156
+ * @param httpRequestQuery The HTTP request query containing the encrypted values.
157
+ * @param keys The keys of the parameters to decrypt.
158
+ * @returns A promise that resolves when the query parameters have been decrypted.
159
+ */
160
+ async decryptQueryParams(httpRequestQuery, keys) {
161
+ if (Is.empty(httpRequestQuery)) {
162
+ return;
163
+ }
164
+ for (const key of Object.keys(httpRequestQuery)) {
165
+ if (key.startsWith(UrlTransformerService._KEY_PREFIX)) {
166
+ const originalKey = key.slice(UrlTransformerService._KEY_PREFIX.length);
167
+ if (keys.includes(originalKey)) {
168
+ const decryptedValue = await this.decryptParam(httpRequestQuery[key]);
169
+ httpRequestQuery[originalKey] = decryptedValue;
170
+ delete httpRequestQuery[key];
171
+ }
172
+ }
173
+ }
174
+ }
175
+ /**
176
+ * Encrypt a parameter value.
177
+ * @param paramValue The value of the parameter to encrypt.
178
+ * @returns A promise that resolves to the encrypted value of the parameter.
179
+ */
180
+ async encryptParam(paramValue) {
181
+ Guards.stringValue(UrlTransformerService.CLASS_NAME, "paramValue", paramValue);
182
+ if (Is.empty(this._nodeId)) {
183
+ throw new GeneralError(UrlTransformerService.CLASS_NAME, "encryptionUnavailable");
184
+ }
185
+ try {
186
+ const salt = RandomHelper.generate(8);
187
+ const encryptedParamValue = await this._vaultConnector.encrypt(`${this._nodeId}/${this._paramEncryptionKeyName}`, VaultEncryptionType.ChaCha20Poly1305, Uint8ArrayHelper.concat([salt, Converter.utf8ToBytes(paramValue)]));
188
+ if (!Is.uint8Array(encryptedParamValue)) {
189
+ throw new GeneralError(UrlTransformerService.CLASS_NAME, "encryptionFailed");
190
+ }
191
+ return Converter.bytesToBase64Url(encryptedParamValue);
192
+ }
193
+ catch (err) {
194
+ throw new GeneralError(UrlTransformerService.CLASS_NAME, "encryptionFailed", undefined, BaseError.fromError(err));
195
+ }
196
+ }
197
+ /**
198
+ * Decrypt a parameter value.
199
+ * @param encryptedValue The encrypted value of the parameter.
200
+ * @returns A promise that resolves to the decrypted value of the parameter.
201
+ */
202
+ async decryptParam(encryptedValue) {
203
+ Guards.stringValue(UrlTransformerService.CLASS_NAME, "encryptedValue", encryptedValue);
204
+ if (Is.empty(this._nodeId)) {
205
+ throw new GeneralError(UrlTransformerService.CLASS_NAME, "decryptionUnavailable");
206
+ }
207
+ try {
208
+ const encryptedBytes = Converter.base64UrlToBytes(encryptedValue);
209
+ const decryptedBytes = await this._vaultConnector.decrypt(`${this._nodeId}/${this._paramEncryptionKeyName}`, VaultEncryptionType.ChaCha20Poly1305, encryptedBytes);
210
+ if (!Is.uint8Array(decryptedBytes)) {
211
+ throw new GeneralError(UrlTransformerService.CLASS_NAME, "decryptionFailed");
212
+ }
213
+ return Converter.bytesToUtf8(decryptedBytes.slice(8));
214
+ }
215
+ catch (err) {
216
+ throw new GeneralError(UrlTransformerService.CLASS_NAME, "decryptionFailed", undefined, BaseError.fromError(err));
217
+ }
218
+ }
219
+ }
220
+ //# 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,wBAA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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","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 * 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"]}
@@ -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
+ }
@@ -1,4 +1,4 @@
1
- import { type IHostingComponent, type IHttpRequestQuery } from "@twin.org/api-models";
1
+ import { type IHostingComponent } from "@twin.org/api-models";
2
2
  import type { IHostingServiceConstructorOptions } from "./models/IHostingServiceConstructorOptions.js";
3
3
  /**
4
4
  * The hosting service for the server.
@@ -18,12 +18,6 @@ export declare class HostingService implements IHostingComponent {
18
18
  * @returns The class name of the component.
19
19
  */
20
20
  className(): string;
21
- /**
22
- * The component needs to be started when the node is initialized.
23
- * @param nodeLoggingComponentType The node logging component type.
24
- * @returns Nothing.
25
- */
26
- start(nodeLoggingComponentType?: string): Promise<void>;
27
21
  /**
28
22
  * Get the public origin for the hosting.
29
23
  * @param serverRequestUrl The url of the current server request if there is one.
@@ -42,59 +36,4 @@ export declare class HostingService implements IHostingComponent {
42
36
  * @returns The full url based on the public origin.
43
37
  */
44
38
  buildPublicUrl(url: string): Promise<string>;
45
- /**
46
- * Add encrypted key/value pairs to a URL's query string.
47
- * Existing query parameters on the URL are preserved; the provided params are
48
- * merged in and then encrypted before being written back to the URL.
49
- * @param url The base URL to add parameters to.
50
- * @param params The key/value pairs to encrypt and append.
51
- * @returns The URL with the encrypted parameters added.
52
- */
53
- addEncryptedParamsToUrl(url: string, params: IHttpRequestQuery): Promise<string>;
54
- /**
55
- * Decrypt specified keys from a query parameter object and return their plain-text values.
56
- * @param queryParams The HTTP request query containing the encrypted parameters.
57
- * @param keys The keys to decrypt.
58
- * @returns A map of the decrypted key/value pairs that were present.
59
- */
60
- getDecryptedParamsFromQueryParams(queryParams: IHttpRequestQuery | undefined, keys: string[]): Promise<IHttpRequestQuery>;
61
- /**
62
- * Encrypt the tenant id and append it as a query parameter to the given URL.
63
- * @param url The URL to append the encrypted tenant token to.
64
- * @param tenantId The tenant identifier to encrypt and add.
65
- * @returns The URL with the encrypted tenant token added as a query parameter.
66
- */
67
- addTenantTokenToUrl(url: string, tenantId: string): Promise<string>;
68
- /**
69
- * Get the tenant token from the query parameters.
70
- * @param queryParams The HTTP request query containing the parameters.
71
- * @returns The tenant token if it exists.
72
- */
73
- getTenantTokenFromQueryParams(queryParams: IHttpRequestQuery | undefined): Promise<string | undefined>;
74
- /**
75
- * Encrypt query parameters using the hosting component's encryption mechanism.
76
- * @param httpRequestQuery The HTTP request query containing the parameters to encrypt.
77
- * @param keys The keys of the parameters to encrypt.
78
- * @returns A promise that resolves when the query parameters have been encrypted.
79
- */
80
- encryptQueryParams(httpRequestQuery: IHttpRequestQuery | undefined, keys: string[]): Promise<void>;
81
- /**
82
- * Decrypt query parameters using the hosting component's encryption mechanism.
83
- * @param httpRequestQuery The HTTP request query containing the encrypted values.
84
- * @param keys The keys of the parameters to decrypt.
85
- * @returns A promise that resolves when the query parameters have been decrypted.
86
- */
87
- decryptQueryParams(httpRequestQuery: IHttpRequestQuery | undefined, keys: string[]): Promise<void>;
88
- /**
89
- * Encrypt a parameter value using the hosting component's encryption mechanism.
90
- * @param paramValue The value of the parameter to encrypt.
91
- * @returns A promise that resolves to the encrypted value of the parameter.
92
- */
93
- encryptParam(paramValue: string): Promise<string>;
94
- /**
95
- * Decrypt a parameter value using the hosting component's encryption mechanism.
96
- * @param encryptedValue The encrypted value of the parameter.
97
- * @returns A promise that resolves to the decrypted value of the parameter.
98
- */
99
- decryptParam(encryptedValue: string): Promise<string>;
100
39
  }
@@ -1,8 +1,15 @@
1
+ export * from "./healthRoutes.js";
2
+ export * from "./healthService.js";
1
3
  export * from "./hostingService.js";
2
4
  export * from "./informationRoutes.js";
3
5
  export * from "./informationService.js";
6
+ export * from "./urlTransformerService.js";
7
+ export * from "./models/IHealthServiceConfig.js";
8
+ export * from "./models/IHealthServiceConstructorOptions.js";
4
9
  export * from "./models/IHostingServiceConfig.js";
5
10
  export * from "./models/IHostingServiceConstructorOptions.js";
6
11
  export * from "./models/IInformationServiceConfig.js";
7
12
  export * from "./models/IInformationServiceConstructorOptions.js";
13
+ export * from "./models/IUrlTransformerServiceConfig.js";
14
+ export * from "./models/IUrlTransformerServiceConstructorOptions.js";
8
15
  export * from "./restEntryPoints.js";
@@ -1,4 +1,4 @@
1
- import type { IHttpRequestContext, INoContentRequest, IRestRoute, IServerFavIconResponse, IServerHealthResponse, IServerInfoResponse, IServerLivezResponse, 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
  */
@@ -35,13 +35,13 @@ export declare function serverInfo(httpRequestContext: IHttpRequestContext, comp
35
35
  */
36
36
  export declare function serverLivez(httpRequestContext: IHttpRequestContext, componentName: string, request: INoContentRequest): Promise<IServerLivezResponse>;
37
37
  /**
38
- * Get the health for the server.
38
+ * Get the readyz for the server.
39
39
  * @param httpRequestContext The request context for the API.
40
40
  * @param componentName The name of the component to use in the routes.
41
41
  * @param request The request.
42
42
  * @returns The response object with additional http response properties.
43
43
  */
44
- export declare function serverHealth(httpRequestContext: IHttpRequestContext, componentName: string, request: INoContentRequest): Promise<IServerHealthResponse>;
44
+ export declare function serverReadyz(httpRequestContext: IHttpRequestContext, componentName: string, request: INoContentRequest): Promise<IServerReadyzResponse>;
45
45
  /**
46
46
  * Get the favicon for the server.
47
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.
@@ -47,26 +47,14 @@ export declare class InformationService implements IInformationComponent {
47
47
  * Is the server live.
48
48
  * @returns True if the server is live.
49
49
  */
50
- livez(): Promise<boolean>;
50
+ livez(): Promise<{
51
+ status: "alive" | "dead";
52
+ }>;
51
53
  /**
52
- * Get the server health.
53
- * @returns The service health.
54
+ * Is the server ready.
55
+ * @returns The readyz status of the server.
54
56
  */
55
- health(): Promise<IHealthInfo>;
56
- /**
57
- * Set the status of a component.
58
- * @param name The component name.
59
- * @param status The status of the component.
60
- * @param details The details for the status.
61
- * @param tenantId The tenant id, optional if the health status is not tenant specific.
62
- * @returns Nothing.
63
- */
64
- setComponentHealth(name: string, status: HealthStatus, details?: string, tenantId?: string): Promise<void>;
65
- /**
66
- * Remove the status of a component.
67
- * @param name The component name.
68
- * @param tenantId The tenant id, optional if the health status is not tenant specific.
69
- * @returns Nothing.
70
- */
71
- removeComponentHealth(name: string, tenantId?: string): Promise<void>;
57
+ readyz(): Promise<{
58
+ status: "ready" | "not ready";
59
+ }>;
72
60
  }
@@ -0,0 +1,10 @@
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 30000
8
+ */
9
+ healthCheckInterval?: number;
10
+ }
@@ -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
+ }
@@ -10,14 +10,4 @@ export interface IHostingServiceConfig {
10
10
  * The APIs public base URL e.g. "https://api.example.com:1234".
11
11
  */
12
12
  publicOrigin?: string;
13
- /**
14
- * The name of the key to retrieve from the vault for encryption/decryption of parameters.
15
- * @default param-encryption
16
- */
17
- paramEncryptionKeyName?: string;
18
- /**
19
- * The query param name to look for the encrypted tenant token.
20
- * @default tenant-token
21
- */
22
- tenantTokenName?: string;
23
13
  }
@@ -1,6 +1,6 @@
1
1
  import type { IHostingServiceConfig } from "./IHostingServiceConfig.js";
2
2
  /**
3
- * Options for the IHostingService constructor.
3
+ * Options for the HostingService constructor.
4
4
  */
5
5
  export interface IHostingServiceConstructorOptions {
6
6
  /**
@@ -8,11 +8,6 @@ export interface IHostingServiceConstructorOptions {
8
8
  * @default tenant-admin
9
9
  */
10
10
  tenantAdminComponentType?: string;
11
- /**
12
- * The vault connector type.
13
- * @default vault
14
- */
15
- vaultConnectorType?: string;
16
11
  /**
17
12
  * The configuration for the service.
18
13
  */
@@ -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
+ }
@@ -0,0 +1,81 @@
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
+ * Decrypt specified keys from a query parameter object and return their plain-text values.
50
+ * @param queryParams The HTTP request query containing the encrypted parameters.
51
+ * @param keys The keys to decrypt.
52
+ * @returns A map of the decrypted key/value pairs that were present.
53
+ */
54
+ getDecryptedFromQueryParams(queryParams: IHttpRequestQuery | undefined, keys: string[]): Promise<IHttpRequestQuery>;
55
+ /**
56
+ * Encrypt query parameters.
57
+ * @param httpRequestQuery The HTTP request query containing the parameters to encrypt.
58
+ * @param keys The keys of the parameters to encrypt.
59
+ * @returns A promise that resolves when the query parameters have been encrypted.
60
+ */
61
+ encryptQueryParams(httpRequestQuery: IHttpRequestQuery | undefined, keys: string[]): Promise<void>;
62
+ /**
63
+ * Decrypt query parameters.
64
+ * @param httpRequestQuery The HTTP request query containing the encrypted values.
65
+ * @param keys The keys of the parameters to decrypt.
66
+ * @returns A promise that resolves when the query parameters have been decrypted.
67
+ */
68
+ decryptQueryParams(httpRequestQuery: IHttpRequestQuery | undefined, keys: string[]): Promise<void>;
69
+ /**
70
+ * Encrypt a parameter value.
71
+ * @param paramValue The value of the parameter to encrypt.
72
+ * @returns A promise that resolves to the encrypted value of the parameter.
73
+ */
74
+ encryptParam(paramValue: string): Promise<string>;
75
+ /**
76
+ * Decrypt a parameter value.
77
+ * @param encryptedValue The encrypted value of the parameter.
78
+ * @returns A promise that resolves to the decrypted value of the parameter.
79
+ */
80
+ decryptParam(encryptedValue: string): Promise<string>;
81
+ }