emilsoftware-utilities 2.0.0-dev.65 → 2.0.0-dev.67
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.MD +28 -1
- package/dist/EmilsoftwareModule.d.ts +11 -3
- package/dist/EmilsoftwareModule.js +1 -1
- package/dist/EmilsoftwareModule.js.map +1 -1
- package/dist/Orm.d.ts +1 -1
- package/dist/Orm.js +4 -23
- package/dist/Orm.js.map +1 -1
- package/dist/Utilities.js +1 -0
- package/dist/Utilities.js.map +1 -1
- package/dist/accessi/client/index.d.ts +26 -0
- package/dist/accessi/client/index.js +49 -0
- package/dist/accessi/client/index.js.map +1 -0
- package/dist/accessi/console/index.d.ts +15 -0
- package/dist/accessi/console/index.js +25 -0
- package/dist/accessi/console/index.js.map +1 -0
- package/dist/accessi/contracts/dtos.d.ts +8 -0
- package/dist/accessi/contracts/dtos.js +25 -0
- package/dist/accessi/contracts/dtos.js.map +1 -0
- package/dist/accessi/contracts/index.d.ts +25 -0
- package/dist/accessi/contracts/index.js +28 -0
- package/dist/accessi/contracts/index.js.map +1 -0
- package/dist/accessi/openapi/index.d.ts +2 -0
- package/dist/accessi/openapi/index.js +19 -0
- package/dist/accessi/openapi/index.js.map +1 -0
- package/dist/accessi/resource-server/core.d.ts +6 -0
- package/dist/accessi/resource-server/core.js +23 -0
- package/dist/accessi/resource-server/core.js.map +1 -0
- package/dist/accessi/resource-server/errors.d.ts +10 -0
- package/dist/accessi/resource-server/errors.js +19 -0
- package/dist/accessi/resource-server/errors.js.map +1 -0
- package/dist/accessi/resource-server/express.d.ts +17 -0
- package/dist/accessi/resource-server/express.js +66 -0
- package/dist/accessi/resource-server/express.js.map +1 -0
- package/dist/accessi/resource-server/index.d.ts +3 -0
- package/dist/accessi/resource-server/index.js +20 -0
- package/dist/accessi/resource-server/index.js.map +1 -0
- package/dist/accessi/resource-server/introspection.d.ts +16 -0
- package/dist/accessi/resource-server/introspection.js +115 -0
- package/dist/accessi/resource-server/introspection.js.map +1 -0
- package/dist/accessi/resource-server/keys.d.ts +11 -0
- package/dist/accessi/resource-server/keys.js +22 -0
- package/dist/accessi/resource-server/keys.js.map +1 -0
- package/dist/accessi/resource-server/nest.d.ts +9 -0
- package/dist/accessi/resource-server/nest.js +62 -0
- package/dist/accessi/resource-server/nest.js.map +1 -0
- package/dist/accessi/resource-server/runtime.d.ts +27 -0
- package/dist/accessi/resource-server/runtime.js +128 -0
- package/dist/accessi/resource-server/runtime.js.map +1 -0
- package/dist/accessi/resource-server/token.d.ts +23 -0
- package/dist/accessi/resource-server/token.js +230 -0
- package/dist/accessi/resource-server/token.js.map +1 -0
- package/dist/accessi/resource-server/types.d.ts +78 -0
- package/dist/accessi/resource-server/types.js +3 -0
- package/dist/accessi/resource-server/types.js.map +1 -0
- package/dist/accessi/server/index.d.ts +10 -0
- package/dist/accessi/server/index.js +29 -0
- package/dist/accessi/server/index.js.map +1 -0
- package/dist/accessi/ui/index.d.ts +13 -0
- package/dist/accessi/ui/index.js +19 -0
- package/dist/accessi/ui/index.js.map +1 -0
- package/dist/accessi-module/AccessiModule.d.ts +25 -1
- package/dist/accessi-module/AccessiModule.js +2 -0
- package/dist/accessi-module/AccessiModule.js.map +1 -1
- package/dist/accessi-module/Console/accessiFetch.d.ts +4 -0
- package/dist/accessi-module/Console/accessiFetch.js +18 -4
- package/dist/accessi-module/Console/accessiFetch.js.map +1 -1
- package/dist/accessi-module/Console/console.js +114 -9
- package/dist/accessi-module/Console/console.js.map +1 -1
- package/dist/accessi-module/Console/generated/{accessiApi.d.ts → emilsoftware-utilities.d.ts} +11 -1
- package/dist/accessi-module/Console/generated/{accessiApi.js → emilsoftware-utilities.js} +10 -2
- package/dist/accessi-module/Console/generated/emilsoftware-utilities.js.map +1 -0
- package/dist/accessi-module/Console/generated/model/accessiIntrospectionResultDto.d.ts +16 -0
- package/dist/accessi-module/Console/generated/model/accessiIntrospectionResultDto.js +3 -0
- package/dist/accessi-module/Console/generated/model/accessiIntrospectionResultDto.js.map +1 -0
- package/dist/accessi-module/Console/generated/model/index.d.ts +3 -0
- package/dist/accessi-module/Console/generated/model/index.js +3 -0
- package/dist/accessi-module/Console/generated/model/index.js.map +1 -1
- package/dist/accessi-module/Console/generated/model/introspectAccessiTokenRequest.d.ts +10 -0
- package/dist/accessi-module/Console/generated/model/introspectAccessiTokenRequest.js +9 -0
- package/dist/accessi-module/Console/generated/model/introspectAccessiTokenRequest.js.map +1 -0
- package/dist/accessi-module/Console/generated/model/introspectAccessiTokenResponse.d.ts +14 -0
- package/dist/accessi-module/Console/generated/model/introspectAccessiTokenResponse.js +3 -0
- package/dist/accessi-module/Console/generated/model/introspectAccessiTokenResponse.js.map +1 -0
- package/dist/accessi-module/Console/wiki.js +98 -3
- package/dist/accessi-module/Console/wiki.js.map +1 -1
- package/dist/accessi-module/Controllers/AccessiIntrospectionController.d.ts +17 -0
- package/dist/accessi-module/Controllers/AccessiIntrospectionController.js +93 -0
- package/dist/accessi-module/Controllers/AccessiIntrospectionController.js.map +1 -0
- package/dist/accessi-module/Dtos/IntrospectionDtos.d.ts +16 -0
- package/dist/accessi-module/Dtos/IntrospectionDtos.js +59 -0
- package/dist/accessi-module/Dtos/IntrospectionDtos.js.map +1 -0
- package/dist/accessi-module/Dtos/index.d.ts +1 -0
- package/dist/accessi-module/Dtos/index.js +1 -0
- package/dist/accessi-module/Dtos/index.js.map +1 -1
- package/dist/accessi-module/Services/AuthService/AuthService.d.ts +13 -0
- package/dist/accessi-module/Services/AuthService/AuthService.js +42 -10
- package/dist/accessi-module/Services/AuthService/AuthService.js.map +1 -1
- package/dist/accessi-module/database-updates/accessiOptionsFromEnv.js +11 -4
- package/dist/accessi-module/database-updates/accessiOptionsFromEnv.js.map +1 -1
- package/dist/accessi-module/database-updates/menuScopeSeed.d.ts +2 -2
- package/dist/accessi-module/database-updates/menuScopeSeed.js +101 -53
- package/dist/accessi-module/database-updates/menuScopeSeed.js.map +1 -1
- package/dist/accessi-module/database-updates/menuScopeSeeder.js +1 -1
- package/dist/accessi-module/database-updates/menuScopeSeeder.js.map +1 -1
- package/dist/accessi-module/index.d.ts +16 -3
- package/dist/accessi-module/index.js +15 -19
- package/dist/accessi-module/index.js.map +1 -1
- package/dist/accessi-module/jwt/jwt.strategy.js +5 -5
- package/dist/accessi-module/jwt/jwt.strategy.js.map +1 -1
- package/dist/accessi-module/middleware/authenticateGen.js +5 -5
- package/dist/accessi-module/middleware/authenticateGen.js.map +1 -1
- package/dist/accessi-module/security/jwtTokenOptions.d.ts +15 -0
- package/dist/accessi-module/security/jwtTokenOptions.js +44 -0
- package/dist/accessi-module/security/jwtTokenOptions.js.map +1 -0
- package/dist/accessi-module/startupLog.d.ts +3 -2
- package/dist/accessi-module/startupLog.js +8 -4
- package/dist/accessi-module/startupLog.js.map +1 -1
- package/dist/allegati-module/index.js +2 -2
- package/dist/allegati-module/index.js.map +1 -1
- package/dist/angular-components/aree-disponibili/demo.html +4 -4
- package/dist/emilsoftware-utilities-2.0.0-dev.67.tgz +0 -0
- package/dist/firebird-compat.d.ts +27 -0
- package/dist/firebird-compat.js +52 -2
- package/dist/firebird-compat.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/initEmilsoftwareModule.d.ts +11 -1
- package/dist/initEmilsoftwareModule.js +11 -23
- package/dist/initEmilsoftwareModule.js.map +1 -1
- package/dist/openapi/OpenApiConfig.d.ts +68 -0
- package/dist/openapi/OpenApiConfig.js +157 -0
- package/dist/openapi/OpenApiConfig.js.map +1 -0
- package/dist/openapi/OpenApiMerge.d.ts +15 -0
- package/dist/openapi/OpenApiMerge.js +119 -0
- package/dist/openapi/OpenApiMerge.js.map +1 -0
- package/integration-prompt.md +481 -0
- package/package.json +89 -6
- package/dist/accessi-module/Console/generated/accessiApi.js.map +0 -1
- package/dist/emilsoftware-utilities-2.0.0-dev.65.tgz +0 -0
- package/dist/swagger/SwaggerConfig.d.ts +0 -8
- package/dist/swagger/SwaggerConfig.js +0 -41
- package/dist/swagger/SwaggerConfig.js.map +0 -1
package/dist/firebird-compat.js
CHANGED
|
@@ -44,6 +44,8 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
44
44
|
return t;
|
|
45
45
|
};
|
|
46
46
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
47
|
+
exports.toUtcDate = toUtcDate;
|
|
48
|
+
exports.normalizeFirebirdResult = normalizeFirebirdResult;
|
|
47
49
|
exports.normalizeFirebirdOptions = normalizeFirebirdOptions;
|
|
48
50
|
exports.describeFirebirdCompatibilityOptions = describeFirebirdCompatibilityOptions;
|
|
49
51
|
exports.enhanceFirebirdError = enhanceFirebirdError;
|
|
@@ -54,6 +56,53 @@ const Firebird = __importStar(require("node-firebird"));
|
|
|
54
56
|
function isBlank(value) {
|
|
55
57
|
return value === undefined || value === null || (typeof value === "string" && value.trim() === "");
|
|
56
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* Reinterprets a Date's local wall-clock components as UTC.
|
|
61
|
+
*
|
|
62
|
+
* `node-firebird` 2.x decodes Firebird DATE/TIME/TIMESTAMP (which are
|
|
63
|
+
* timezone-less) as *local* time via `setMilliseconds(... + getTimezoneOffset())`.
|
|
64
|
+
* The legacy `es-node-firebird` fork instead decoded them as UTC
|
|
65
|
+
* (`setUTCMilliseconds`). This helper reproduces that legacy behaviour by
|
|
66
|
+
* taking the local wall-clock fields and rebuilding the Date as if they were
|
|
67
|
+
* UTC, so existing applications keep seeing the same values.
|
|
68
|
+
*/
|
|
69
|
+
function toUtcDate(date) {
|
|
70
|
+
return new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds()));
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Normalizes a decoded Firebird result value to reproduce the legacy
|
|
74
|
+
* `es-node-firebird` fork behaviour:
|
|
75
|
+
*
|
|
76
|
+
* - strings are trimmed (the fork called `.trim()` on every text field);
|
|
77
|
+
* - `Date` values are reinterpreted as UTC (the fork used `setUTCMilliseconds`);
|
|
78
|
+
* - arrays and plain objects are normalized recursively;
|
|
79
|
+
* - `Buffer`, `null` and `undefined` are left untouched.
|
|
80
|
+
*/
|
|
81
|
+
function normalizeFirebirdResult(value, trimStringResults, utcDates) {
|
|
82
|
+
if (value === undefined || value === null) {
|
|
83
|
+
return value;
|
|
84
|
+
}
|
|
85
|
+
if (typeof value === "string" || value instanceof String) {
|
|
86
|
+
return trimStringResults ? String(value).trim() : value;
|
|
87
|
+
}
|
|
88
|
+
if (Array.isArray(value)) {
|
|
89
|
+
return value.map((item) => normalizeFirebirdResult(item, trimStringResults, utcDates));
|
|
90
|
+
}
|
|
91
|
+
if (value instanceof Date) {
|
|
92
|
+
return utcDates ? toUtcDate(value) : value;
|
|
93
|
+
}
|
|
94
|
+
if (Buffer.isBuffer(value)) {
|
|
95
|
+
return value;
|
|
96
|
+
}
|
|
97
|
+
if (typeof value === "object") {
|
|
98
|
+
const source = value;
|
|
99
|
+
return Object.keys(source).reduce((normalized, key) => {
|
|
100
|
+
normalized[key] = normalizeFirebirdResult(source[key], trimStringResults, utcDates);
|
|
101
|
+
return normalized;
|
|
102
|
+
}, {});
|
|
103
|
+
}
|
|
104
|
+
return value;
|
|
105
|
+
}
|
|
57
106
|
function normalizeWireCryptMode(value) {
|
|
58
107
|
if (isBlank(value)) {
|
|
59
108
|
return undefined;
|
|
@@ -173,8 +222,9 @@ function formatFirebirdMetadata(source) {
|
|
|
173
222
|
function normalizeFirebirdOptions(options) {
|
|
174
223
|
var _a, _b;
|
|
175
224
|
const compatibilityOptions = options;
|
|
176
|
-
const { authPlugins: _authPlugins, compatibilityProbeTimeoutMs: _compatibilityProbeTimeoutMs, compatibilityTotalTimeoutMs, connectTimeoutMs, firebirdDriver: _firebirdDriver, logQueryParameters: _logQueryParameters, poolSize: _poolSize, trimStringResults } = compatibilityOptions, baseOptions = __rest(compatibilityOptions, ["authPlugins", "compatibilityProbeTimeoutMs", "compatibilityTotalTimeoutMs", "connectTimeoutMs", "firebirdDriver", "logQueryParameters", "poolSize", "trimStringResults"]);
|
|
177
|
-
const normalizedOptions = Object.assign(Object.assign({}, baseOptions), { pluginName: normalizeAuthPlugin(compatibilityOptions.pluginName), trimStringResults,
|
|
225
|
+
const { authPlugins: _authPlugins, compatibilityProbeTimeoutMs: _compatibilityProbeTimeoutMs, compatibilityTotalTimeoutMs, connectTimeoutMs, firebirdDriver: _firebirdDriver, logQueryParameters: _logQueryParameters, poolSize: _poolSize, trimStringResults, utcDates } = compatibilityOptions, baseOptions = __rest(compatibilityOptions, ["authPlugins", "compatibilityProbeTimeoutMs", "compatibilityTotalTimeoutMs", "connectTimeoutMs", "firebirdDriver", "logQueryParameters", "poolSize", "trimStringResults", "utcDates"]);
|
|
226
|
+
const normalizedOptions = Object.assign(Object.assign({}, baseOptions), { pluginName: normalizeAuthPlugin(compatibilityOptions.pluginName), trimStringResults,
|
|
227
|
+
utcDates, wireCrypt: normalizeWireCryptMode(compatibilityOptions.wireCrypt) });
|
|
178
228
|
const timeoutCandidate = (_b = (_a = compatibilityOptions.connectTimeout) !== null && _a !== void 0 ? _a : connectTimeoutMs) !== null && _b !== void 0 ? _b : compatibilityTotalTimeoutMs;
|
|
179
229
|
if (Number.isFinite(timeoutCandidate) && Number(timeoutCandidate) > 0) {
|
|
180
230
|
normalizedOptions.connectTimeout = Math.trunc(Number(timeoutCandidate));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"firebird-compat.js","sourceRoot":"","sources":["../src/firebird-compat.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiMA,4DA8BC;AAED,oFAGC;AAED,oDAqBC;AAED,oFAEC;AAED,4EAEC;AAED,wFAIC;AAzQD,wDAA0C;AA2C1C,SAAS,OAAO,CAAC,KAAc;IAC3B,OAAO,KAAK,KAAK,SAAS,IAAI,KAAK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AC;AACjB,CAAC;AAED,SAAgB,sCAAsC;IAClD,uEAAuE;IACvE,sEAAsE;IACtE,wBAAwB;AAC5B,CAAC","sourcesContent":["import * as Firebird from \"node-firebird\";\nimport type { Options } from \"node-firebird\";\n\nexport type FirebirdWireCryptMode = \"disabled\" | \"enabled\" | \"required\";\nexport type FirebirdAuthPlugin = \"Legacy_Auth\" | \"Srp\" | \"Srp256\" | \"Srp384\" | \"Srp512\";\nexport type FirebirdDriverStrategy = \"modern\";\n\nexport type FirebirdOptions = Options & {\n wireCrypt?: FirebirdWireCryptMode | number;\n pluginName?: FirebirdAuthPlugin;\n authPlugins?: FirebirdAuthPlugin[];\n connectTimeoutMs?: number;\n compatibilityProbeTimeoutMs?: number;\n compatibilityTotalTimeoutMs?: number;\n firebirdDriver?: FirebirdDriverStrategy;\n trimStringResults?: boolean;\n /**\n * When `true`, query parameters are interpolated into the logged SQL. Off by\n * default so that secrets, credentials and personal data are not written to\n * the console or to the daily log files.\n */\n logQueryParameters?: boolean;\n /**\n * When greater than zero, enables an opt-in connection pool of the given\n * maximum size for this connection target instead of attaching/detaching a\n * physical connection for every query. Default `0` keeps the historic\n * one-connection-per-query behaviour.\n */\n poolSize?: number;\n};\n\ntype FirebirdErrorContext = {\n stage: \"attach\" | \"query\" | \"execute\" | \"transaction\";\n sql?: string;\n};\n\ntype EnhancedFirebirdError = Error & {\n cause?: unknown;\n gdscode?: number;\n gdsparams?: unknown;\n __emilsoftwareFirebirdEnhanced?: boolean;\n};\n\nfunction isBlank(value: unknown): boolean {\n return value === undefined || value === null || (typeof value === \"string\" && value.trim() === \"\");\n}\n\nfunction normalizeWireCryptMode(value: FirebirdOptions[\"wireCrypt\"]): number | undefined {\n if (isBlank(value)) {\n return undefined;\n }\n\n if (typeof value === \"number\") {\n return value;\n }\n\n const normalized = String(value).trim().toLowerCase();\n if (normalized === \"disabled\") {\n return Firebird.WIRE_CRYPT_DISABLE;\n }\n\n return Firebird.WIRE_CRYPT_ENABLE;\n}\n\nfunction normalizeAuthPlugin(value: unknown): FirebirdAuthPlugin | undefined {\n if (isBlank(value)) {\n return undefined;\n }\n\n const normalized = String(value).trim().toLowerCase();\n if (normalized === \"legacy\" || normalized === \"legacy_auth\") {\n return \"Legacy_Auth\";\n }\n\n if (normalized === \"srp256\") {\n return \"Srp256\";\n }\n\n if (normalized === \"srp384\") {\n return \"Srp384\";\n }\n\n if (normalized === \"srp512\") {\n return \"Srp512\";\n }\n\n return \"Srp\";\n}\n\nfunction formatWireCryptValue(value: FirebirdOptions[\"wireCrypt\"]): string {\n if (isBlank(value)) {\n return \"auto\";\n }\n\n if (typeof value === \"number\") {\n if (value === Firebird.WIRE_CRYPT_DISABLE) {\n return \"disabled\";\n }\n\n if (value === Firebird.WIRE_CRYPT_ENABLE) {\n return \"enabled\";\n }\n\n return String(value);\n }\n\n return String(value);\n}\n\nfunction formatTarget(options: Options): string {\n return `${options.host ?? \"?\"}:${options.port ?? \"?\"} -> ${options.database ?? \"?\"}`;\n}\n\nfunction uniqueDiagnostics(values: string[]): string[] {\n return values.filter((value, index) => values.indexOf(value) === index);\n}\n\nfunction buildDiagnostics(message: string, options: FirebirdOptions): string[] {\n const diagnostics: string[] = [];\n const pluginMismatch = message.match(/Server don't accept plugin\\s*:\\s*([^,]+),\\s*but support\\s*:\\s*(.+)$/i);\n\n if (pluginMismatch) {\n const supportedPlugins = (pluginMismatch[2] ?? \"\")\n .split(\",\")\n .map((plugin) => plugin.trim())\n .filter((plugin) => plugin.length > 0);\n const supportedMessage = supportedPlugins.length === 1\n ? `The server explicitly reported that only the \"${supportedPlugins[0]}\" authentication plugin is supported.`\n : `The server explicitly reported the supported authentication plugins: ${supportedPlugins.join(\", \")}.`;\n diagnostics.push(supportedMessage);\n }\n\n if (/Incompatible wire encryption levels requested on client and server/i.test(message)) {\n diagnostics.push(\"The server rejected the requested wire encryption mode. Keep wire encryption auto-enabled unless the server is known to allow disabled encryption.\");\n }\n\n if (/No matching plugins on server/i.test(message)) {\n diagnostics.push(\"The server did not find a common authentication plugin with the client configuration.\");\n }\n\n if (/Connection timeout after \\d+ms/i.test(message) || /Timeout during Firebird attach after \\d+ ms/i.test(message)) {\n diagnostics.push(\"The TCP connection was accepted but the Firebird wire-protocol attach did not complete in time.\");\n }\n\n if (options.pluginName) {\n diagnostics.push(`Client authentication plugin was forced to \"${options.pluginName}\". Leave pluginName empty to let the driver auto-negotiate when possible.`);\n }\n\n if (!isBlank(options.wireCrypt)) {\n diagnostics.push(`Client wire encryption was forced to \"${formatWireCryptValue(options.wireCrypt)}\".`);\n }\n\n return uniqueDiagnostics(diagnostics);\n}\n\nfunction copyFirebirdMetadata(target: EnhancedFirebirdError, source: unknown): void {\n if (!source || typeof source !== \"object\") {\n return;\n }\n\n const firebirdSource = source as Record<string, unknown>;\n if (\"gdscode\" in firebirdSource) {\n target.gdscode = firebirdSource.gdscode as number;\n }\n\n if (\"gdsparams\" in firebirdSource) {\n target.gdsparams = firebirdSource.gdsparams;\n }\n}\n\nfunction formatFirebirdMetadata(source: unknown): string {\n if (!source || typeof source !== \"object\") {\n return \"\";\n }\n\n const firebirdSource = source as Record<string, unknown>;\n const metadata: string[] = [];\n\n if (typeof firebirdSource.gdscode === \"number\") {\n metadata.push(`gdscode=${firebirdSource.gdscode}`);\n }\n\n if (firebirdSource.gdsparams !== undefined) {\n try {\n metadata.push(`gdsparams=${JSON.stringify(firebirdSource.gdsparams)}`);\n } catch {\n metadata.push(`gdsparams=${String(firebirdSource.gdsparams)}`);\n }\n }\n\n return metadata.length > 0 ? ` Metadata: ${metadata.join(\", \")}.` : \"\";\n}\n\nexport function normalizeFirebirdOptions(options: Options): FirebirdOptions {\n const compatibilityOptions = options as FirebirdOptions;\n const {\n authPlugins: _authPlugins,\n compatibilityProbeTimeoutMs: _compatibilityProbeTimeoutMs,\n compatibilityTotalTimeoutMs,\n connectTimeoutMs,\n firebirdDriver: _firebirdDriver,\n logQueryParameters: _logQueryParameters,\n poolSize: _poolSize,\n trimStringResults,\n ...baseOptions\n } = compatibilityOptions;\n\n const normalizedOptions: FirebirdOptions = {\n ...baseOptions,\n pluginName: normalizeAuthPlugin(compatibilityOptions.pluginName),\n trimStringResults,\n wireCrypt: normalizeWireCryptMode(compatibilityOptions.wireCrypt),\n };\n\n const timeoutCandidate = compatibilityOptions.connectTimeout\n ?? connectTimeoutMs\n ?? compatibilityTotalTimeoutMs;\n\n if (Number.isFinite(timeoutCandidate) && Number(timeoutCandidate) > 0) {\n normalizedOptions.connectTimeout = Math.trunc(Number(timeoutCandidate));\n }\n\n return normalizedOptions;\n}\n\nexport function describeFirebirdCompatibilityOptions(options: Options): string {\n const normalized = normalizeFirebirdOptions(options);\n return `plugin=${normalized.pluginName ?? \"auto\"}, wireCrypt=${formatWireCryptValue(normalized.wireCrypt)}, connectTimeout=${normalized.connectTimeout ?? \"default\"}`;\n}\n\nexport function enhanceFirebirdError(error: unknown, options: Options, context: FirebirdErrorContext): Error {\n if (error instanceof Error && (error as EnhancedFirebirdError).__emilsoftwareFirebirdEnhanced) {\n return error;\n }\n\n const normalizedOptions = normalizeFirebirdOptions(options);\n const target = formatTarget(normalizedOptions);\n const original = error instanceof Error ? error : new Error(String(error));\n const diagnostics = buildDiagnostics(original.message, normalizedOptions);\n const sqlSuffix = context.sql ? ` SQL: ${context.sql.replace(/\\s+/g, \" \").trim()}` : \"\";\n const diagnosticsSuffix = diagnostics.length > 0 ? ` Diagnostics: ${diagnostics.join(\" \")}` : \"\";\n const metadataSuffix = formatFirebirdMetadata(original);\n const enhanced = new Error(\n `Firebird ${context.stage} failed on ${target}: ${original.message}.${diagnosticsSuffix}${metadataSuffix}${sqlSuffix}`\n ) as EnhancedFirebirdError;\n\n enhanced.cause = original;\n enhanced.__emilsoftwareFirebirdEnhanced = true;\n copyFirebirdMetadata(enhanced, original);\n enhanced.stack = `${enhanced.name}: ${enhanced.message}\\nCaused by: ${original.stack ?? original.message}`;\n return enhanced;\n}\n\nexport function buildFirebirdCompatibilityCandidates(options: Options): FirebirdOptions[] {\n return [normalizeFirebirdOptions(options)];\n}\n\nexport function shouldRetryFirebirdCompatibility(): boolean {\n return false;\n}\n\nexport function ensureEsNodeFirebirdCompatibilityPatch(): void {\n // No-op kept for backward compatibility. The library now relies on the\n // official node-firebird driver, which handles Firebird 2.5+ protocol\n // negotiation natively.\n}\n"]}
|
|
1
|
+
{"version":3,"file":"firebird-compat.js","sourceRoot":"","sources":["../src/firebird-compat.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+DA,8BAUC;AAWD,0DAkCC;AAoJD,4DAgCC;AAED,oFAGC;AAED,oDAqBC;AAED,oFAEC;AAED,4EAEC;AAED,wFAIC;AApVD,wDAA0C;AAiD1C,SAAS,OAAO,CAAC,KAAc;IAC3B,OAAO,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;AACvG,CAAC;AAED;;;;;;;;;GASG;AACH,SAAgB,SAAS,CAAC,IAAU;IAChC,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CACpB,IAAI,CAAC,WAAW,EAAE,EAClB,IAAI,CAAC,QAAQ,EAAE,EACf,IAAI,CAAC,OAAO,EAAE,EACd,IAAI,CAAC,QAAQ,EAAE,EACf,IAAI,CAAC,UAAU,EAAE,EACjB,IAAI,CAAC,UAAU,EAAE,EACjB,IAAI,CAAC,eAAe,EAAE,CACzB,CAAC,CAAC;AACP,CAAC;AAED;;;;;;;;GAQG;AACH,SAAgB,uBAAuB,CACnC,KAAc,EACd,iBAA0B,EAC1B,QAAiB;IAEjB,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QACxC,OAAO,KAAK,CAAC;IACjB,CAAC;IAED,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,YAAY,MAAM,E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E,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IACxF,MAAM,iBAAiB,GAAG,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,iBAAiB,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IACjG,MAAM,cAAc,GAAG,sBAAsB,CAAC,QAAQ,CAAC,CAAC;IACxD,MAAM,QAAQ,GAAG,IAAI,KAAK,CACtB,YAAY,OAAO,CAAC,KAAK,cAAc,MAAM,KAAK,QAAQ,CAAC,OAAO,IAAI,iBAAiB,GAAG,cAAc,GAAG,SAAS,EAAE,CAChG,CAAC;IAE3B,QAAQ,CAAC,KAAK,GAAG,QAAQ,CAAC;IAC1B,QAAQ,CAAC,8BAA8B,GAAG,IAAI,CAAC;IAC/C,oBAAoB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IACzC,QAAQ,CAAC,KAAK,GAAG,GAAG,QAAQ,CAAC,IAAI,KAAK,QAAQ,CAAC,OAAO,gBAAgB,MAAA,QAAQ,CAAC,KAAK,mCAAI,QAAQ,CAAC,OAAO,EAAE,CAAC;IAC3G,OAAO,QAAQ,CAAC;AACpB,CAAC;AAED,SAAgB,oCAAoC,CAAC,OAAgB;IACjE,OAAO,CAAC,wBAAwB,CAAC,OAAO,CAAC,CAAC,CAAC;AAC/C,CAAC;AAED,SAAgB,gCAAgC;IAC5C,OAAO,KAAK,CAAC;AACjB,CAAC;AAED,SAAgB,sCAAsC;IAClD,uEAAuE;IACvE,sEAAsE;IACtE,wBAAwB;AAC5B,CAAC","sourcesContent":["import * as Firebird from \"node-firebird\";\nimport type { Options } from \"node-firebird\";\n\nexport type FirebirdWireCryptMode = \"disabled\" | \"enabled\" | \"required\";\nexport type FirebirdAuthPlugin = \"Legacy_Auth\" | \"Srp\" | \"Srp256\" | \"Srp384\" | \"Srp512\";\nexport type FirebirdDriverStrategy = \"modern\";\n\nexport type FirebirdOptions = Options & {\n wireCrypt?: FirebirdWireCryptMode | number;\n pluginName?: FirebirdAuthPlugin;\n authPlugins?: FirebirdAuthPlugin[];\n connectTimeoutMs?: number;\n compatibilityProbeTimeoutMs?: number;\n compatibilityTotalTimeoutMs?: number;\n firebirdDriver?: FirebirdDriverStrategy;\n trimStringResults?: boolean;\n /**\n * When `true` (default), DATE/TIME/TIMESTAMP values are returned as UTC,\n * reproducing the legacy `es-node-firebird` fork behaviour. When `false`,\n * the values are left as decoded by `node-firebird` (local time).\n */\n utcDates?: boolean;\n /**\n * When `true`, query parameters are interpolated into the logged SQL. Off by\n * default so that secrets, credentials and personal data are not written to\n * the console or to the daily log files.\n */\n logQueryParameters?: boolean;\n /**\n * When greater than zero, enables an opt-in connection pool of the given\n * maximum size for this connection target instead of attaching/detaching a\n * physical connection for every query. Default `0` keeps the historic\n * one-connection-per-query behaviour.\n */\n poolSize?: number;\n};\n\ntype FirebirdErrorContext = {\n stage: \"attach\" | \"query\" | \"execute\" | \"transaction\";\n sql?: string;\n};\n\ntype EnhancedFirebirdError = Error & {\n cause?: unknown;\n gdscode?: number;\n gdsparams?: unknown;\n __emilsoftwareFirebirdEnhanced?: boolean;\n};\n\nfunction isBlank(value: unknown): boolean {\n return value === undefined || value === null || (typeof value === \"string\" && value.trim() === \"\");\n}\n\n/**\n * Reinterprets a Date's local wall-clock components as UTC.\n *\n * `node-firebird` 2.x decodes Firebird DATE/TIME/TIMESTAMP (which are\n * timezone-less) as *local* time via `setMilliseconds(... + getTimezoneOffset())`.\n * The legacy `es-node-firebird` fork instead decoded them as UTC\n * (`setUTCMilliseconds`). This helper reproduces that legacy behaviour by\n * taking the local wall-clock fields and rebuilding the Date as if they were\n * UTC, so existing applications keep seeing the same values.\n */\nexport function toUtcDate(date: Date): Date {\n return new Date(Date.UTC(\n date.getFullYear(),\n date.getMonth(),\n date.getDate(),\n date.getHours(),\n date.getMinutes(),\n date.getSeconds(),\n date.getMilliseconds(),\n ));\n}\n\n/**\n * Normalizes a decoded Firebird result value to reproduce the legacy\n * `es-node-firebird` fork behaviour:\n *\n * - strings are trimmed (the fork called `.trim()` on every text field);\n * - `Date` values are reinterpreted as UTC (the fork used `setUTCMilliseconds`);\n * - arrays and plain objects are normalized recursively;\n * - `Buffer`, `null` and `undefined` are left untouched.\n */\nexport function normalizeFirebirdResult(\n value: unknown,\n trimStringResults: boolean,\n utcDates: boolean,\n): unknown {\n if (value === undefined || value === null) {\n return value;\n }\n\n if (typeof value === \"string\" || value instanceof String) {\n return trimStringResults ? String(value).trim() : value;\n }\n\n if (Array.isArray(value)) {\n return value.map((item) => normalizeFirebirdResult(item, trimStringResults, utcDates));\n }\n\n if (value instanceof Date) {\n return utcDates ? toUtcDate(value) : value;\n }\n\n if (Buffer.isBuffer(value)) {\n return value;\n }\n\n if (typeof value === \"object\") {\n const source = value as Record<string, unknown>;\n return Object.keys(source).reduce((normalized: Record<string, unknown>, key: string) => {\n normalized[key] = normalizeFirebirdResult(source[key], trimStringResults, utcDates);\n return normalized;\n }, {});\n }\n\n return value;\n}\n\nfunction normalizeWireCryptMode(value: FirebirdOptions[\"wireCrypt\"]): number | undefined {\n if (isBlank(value)) {\n return undefined;\n }\n\n if (typeof value === \"number\") {\n return value;\n }\n\n const normalized = String(value).trim().toLowerCase();\n if (normalized === \"disabled\") {\n return Firebird.WIRE_CRYPT_DISABLE;\n }\n\n return Firebird.WIRE_CRYPT_ENABLE;\n}\n\nfunction normalizeAuthPlugin(value: unknown): FirebirdAuthPlugin | undefined {\n if (isBlank(value)) {\n return undefined;\n }\n\n const normalized = String(value).trim().toLowerCase();\n if (normalized === \"legacy\" || normalized === \"legacy_auth\") {\n return \"Legacy_Auth\";\n }\n\n if (normalized === \"srp256\") {\n return \"Srp256\";\n }\n\n if (normalized === \"srp384\") {\n return \"Srp384\";\n }\n\n if (normalized === \"srp512\") {\n return \"Srp512\";\n }\n\n return \"Srp\";\n}\n\nfunction formatWireCryptValue(value: FirebirdOptions[\"wireCrypt\"]): string {\n if (isBlank(value)) {\n return \"auto\";\n }\n\n if (typeof value === \"number\") {\n if (value === Firebird.WIRE_CRYPT_DISABLE) {\n return \"disabled\";\n }\n\n if (value === Firebird.WIRE_CRYPT_ENABLE) {\n return \"enabled\";\n }\n\n return String(value);\n }\n\n return String(value);\n}\n\nfunction formatTarget(options: Options): string {\n return `${options.host ?? \"?\"}:${options.port ?? \"?\"} -> ${options.database ?? \"?\"}`;\n}\n\nfunction uniqueDiagnostics(values: string[]): string[] {\n return values.filter((value, index) => values.indexOf(value) === index);\n}\n\nfunction buildDiagnostics(message: string, options: FirebirdOptions): string[] {\n const diagnostics: string[] = [];\n const pluginMismatch = message.match(/Server don't accept plugin\\s*:\\s*([^,]+),\\s*but support\\s*:\\s*(.+)$/i);\n\n if (pluginMismatch) {\n const supportedPlugins = (pluginMismatch[2] ?? \"\")\n .split(\",\")\n .map((plugin) => plugin.trim())\n .filter((plugin) => plugin.length > 0);\n const supportedMessage = supportedPlugins.length === 1\n ? `The server explicitly reported that only the \"${supportedPlugins[0]}\" authentication plugin is supported.`\n : `The server explicitly reported the supported authentication plugins: ${supportedPlugins.join(\", \")}.`;\n diagnostics.push(supportedMessage);\n }\n\n if (/Incompatible wire encryption levels requested on client and server/i.test(message)) {\n diagnostics.push(\"The server rejected the requested wire encryption mode. Keep wire encryption auto-enabled unless the server is known to allow disabled encryption.\");\n }\n\n if (/No matching plugins on server/i.test(message)) {\n diagnostics.push(\"The server did not find a common authentication plugin with the client configuration.\");\n }\n\n if (/Connection timeout after \\d+ms/i.test(message) || /Timeout during Firebird attach after \\d+ ms/i.test(message)) {\n diagnostics.push(\"The TCP connection was accepted but the Firebird wire-protocol attach did not complete in time.\");\n }\n\n if (options.pluginName) {\n diagnostics.push(`Client authentication plugin was forced to \"${options.pluginName}\". Leave pluginName empty to let the driver auto-negotiate when possible.`);\n }\n\n if (!isBlank(options.wireCrypt)) {\n diagnostics.push(`Client wire encryption was forced to \"${formatWireCryptValue(options.wireCrypt)}\".`);\n }\n\n return uniqueDiagnostics(diagnostics);\n}\n\nfunction copyFirebirdMetadata(target: EnhancedFirebirdError, source: unknown): void {\n if (!source || typeof source !== \"object\") {\n return;\n }\n\n const firebirdSource = source as Record<string, unknown>;\n if (\"gdscode\" in firebirdSource) {\n target.gdscode = firebirdSource.gdscode as number;\n }\n\n if (\"gdsparams\" in firebirdSource) {\n target.gdsparams = firebirdSource.gdsparams;\n }\n}\n\nfunction formatFirebirdMetadata(source: unknown): string {\n if (!source || typeof source !== \"object\") {\n return \"\";\n }\n\n const firebirdSource = source as Record<string, unknown>;\n const metadata: string[] = [];\n\n if (typeof firebirdSource.gdscode === \"number\") {\n metadata.push(`gdscode=${firebirdSource.gdscode}`);\n }\n\n if (firebirdSource.gdsparams !== undefined) {\n try {\n metadata.push(`gdsparams=${JSON.stringify(firebirdSource.gdsparams)}`);\n } catch {\n metadata.push(`gdsparams=${String(firebirdSource.gdsparams)}`);\n }\n }\n\n return metadata.length > 0 ? ` Metadata: ${metadata.join(\", \")}.` : \"\";\n}\n\nexport function normalizeFirebirdOptions(options: Options): FirebirdOptions {\n const compatibilityOptions = options as FirebirdOptions;\n const {\n authPlugins: _authPlugins,\n compatibilityProbeTimeoutMs: _compatibilityProbeTimeoutMs,\n compatibilityTotalTimeoutMs,\n connectTimeoutMs,\n firebirdDriver: _firebirdDriver,\n logQueryParameters: _logQueryParameters,\n poolSize: _poolSize,\n trimStringResults,\n utcDates,\n ...baseOptions\n } = compatibilityOptions;\n\n const normalizedOptions: FirebirdOptions = {\n ...baseOptions,\n pluginName: normalizeAuthPlugin(compatibilityOptions.pluginName),\n trimStringResults,\n utcDates,\n wireCrypt: normalizeWireCryptMode(compatibilityOptions.wireCrypt),\n };\n\n const timeoutCandidate = compatibilityOptions.connectTimeout\n ?? connectTimeoutMs\n ?? compatibilityTotalTimeoutMs;\n\n if (Number.isFinite(timeoutCandidate) && Number(timeoutCandidate) > 0) {\n normalizedOptions.connectTimeout = Math.trunc(Number(timeoutCandidate));\n }\n\n return normalizedOptions;\n}\n\nexport function describeFirebirdCompatibilityOptions(options: Options): string {\n const normalized = normalizeFirebirdOptions(options);\n return `plugin=${normalized.pluginName ?? \"auto\"}, wireCrypt=${formatWireCryptValue(normalized.wireCrypt)}, connectTimeout=${normalized.connectTimeout ?? \"default\"}`;\n}\n\nexport function enhanceFirebirdError(error: unknown, options: Options, context: FirebirdErrorContext): Error {\n if (error instanceof Error && (error as EnhancedFirebirdError).__emilsoftwareFirebirdEnhanced) {\n return error;\n }\n\n const normalizedOptions = normalizeFirebirdOptions(options);\n const target = formatTarget(normalizedOptions);\n const original = error instanceof Error ? error : new Error(String(error));\n const diagnostics = buildDiagnostics(original.message, normalizedOptions);\n const sqlSuffix = context.sql ? ` SQL: ${context.sql.replace(/\\s+/g, \" \").trim()}` : \"\";\n const diagnosticsSuffix = diagnostics.length > 0 ? ` Diagnostics: ${diagnostics.join(\" \")}` : \"\";\n const metadataSuffix = formatFirebirdMetadata(original);\n const enhanced = new Error(\n `Firebird ${context.stage} failed on ${target}: ${original.message}.${diagnosticsSuffix}${metadataSuffix}${sqlSuffix}`\n ) as EnhancedFirebirdError;\n\n enhanced.cause = original;\n enhanced.__emilsoftwareFirebirdEnhanced = true;\n copyFirebirdMetadata(enhanced, original);\n enhanced.stack = `${enhanced.name}: ${enhanced.message}\\nCaused by: ${original.stack ?? original.message}`;\n return enhanced;\n}\n\nexport function buildFirebirdCompatibilityCandidates(options: Options): FirebirdOptions[] {\n return [normalizeFirebirdOptions(options)];\n}\n\nexport function shouldRetryFirebirdCompatibility(): boolean {\n return false;\n}\n\nexport function ensureEsNodeFirebirdCompatibilityPatch(): void {\n // No-op kept for backward compatibility. The library now relies on the\n // official node-firebird driver, which handles Firebird 2.5+ protocol\n // negotiation natively.\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -20,5 +20,6 @@ export * from "./accessi-module";
|
|
|
20
20
|
export * from "./allegati-module";
|
|
21
21
|
export * from "node-firebird";
|
|
22
22
|
export { autobind, ExecutionTimeLogger, Logger, LogLevels, Orm, DateUtilities, RestUtilities, DatabaseUtilities, DatabaseUpdater, StatusCode, DocumentGenerator, Firebird };
|
|
23
|
-
export * from "./
|
|
23
|
+
export * from "./openapi/OpenApiConfig";
|
|
24
|
+
export * from "./openapi/OpenApiMerge";
|
|
24
25
|
export * from "./initEmilsoftwareModule";
|
package/dist/index.js
CHANGED
|
@@ -71,6 +71,7 @@ __exportStar(require("./accessi-module"), exports);
|
|
|
71
71
|
__exportStar(require("./allegati-module"), exports);
|
|
72
72
|
__exportStar(require("node-firebird"), exports);
|
|
73
73
|
// Unified module exports
|
|
74
|
-
__exportStar(require("./
|
|
74
|
+
__exportStar(require("./openapi/OpenApiConfig"), exports);
|
|
75
|
+
__exportStar(require("./openapi/OpenApiMerge"), exports);
|
|
75
76
|
__exportStar(require("./initEmilsoftwareModule"), exports);
|
|
76
77
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uDAAoD;AAuB6D,gGAvBxG,iCAAe,OAuBwG;AAtBhI,+DAA2D;AAsBxC,oGAtBV,yCAAmB,OAsBU;AArBtC,wDAA0C;AAqBuH,4BAAQ;AApBzK,qCAA6C;AAoBG,0FApBvC,kBAAS,OAoBuC;AAAjB,uFApBpB,eAAM,OAoBoB;AAnB9C,+BAA4B;AAmB+B,oFAnBlD,SAAG,OAmBkD;AAlB9D,2CAA0F;AAkB1B,8FAlBvD,yBAAa,OAkBuD;AAAE,8FAlBvD,yBAAa,OAkBuD;AAAE,kGAlBvD,6BAAiB,OAkBuD;AAAmB,2FAlBxE,sBAAU,OAkBwE;AAjB5I,yCAAsC;AAiB7B,yFAjBA,mBAAQ,OAiBA;AAhBjB,2DAAwD;AAgBsF,kGAhBrI,qCAAiB,OAgBqI;AAf/J,6BAA2B;AAE3B,wCAAsB;AACtB,8CAA4B;AAC5B,2CAAyB;AACzB,6CAA2B;AAC3B,wDAAsC;AACtC,2DAAyC;AACzC,sDAAoC;AACpC,oDAAkC;AAClC,oDAAkC;AAElC,mDAAiC;AACjC,oDAAkC;AAClC,gDAA8B;AAE9B,yBAAyB;AACzB,0DAAwC;AACxC,2DAAyC","sourcesContent":["import { DatabaseUpdater } from \"./DatabaseUpdater\";\nimport { ExecutionTimeLogger } from \"./ExecutionTimeLogger\"\nimport * as Firebird from \"node-firebird\";\nimport { LogLevels, Logger } from \"./Logger\";\nimport { Orm } from \"./Orm\";\nimport { DateUtilities, RestUtilities, DatabaseUtilities, StatusCode } from \"./Utilities\";\nimport { autobind } from \"./autobind\";\nimport { DocumentGenerator } from \"./ContractGenerator\";\nimport \"./firebird-compat\";\n\nexport * from \"./Orm\";\nexport * from \"./Utilities\";\nexport * from \"./Logger\";\nexport * from \"./autobind\";\nexport * from \"./ExecutionTimeLogger\";\nexport * from \"./RoutesLoggerMiddleware\";\nexport * from \"./ContractGenerator\";\nexport * from \"./DatabaseUpdater\";\nexport * from \"./firebird-compat\";\n\nexport * from \"./accessi-module\";\nexport * from \"./allegati-module\";\nexport * from \"node-firebird\";\nexport { autobind, ExecutionTimeLogger, Logger, LogLevels, Orm, DateUtilities, RestUtilities, DatabaseUtilities, DatabaseUpdater, StatusCode, DocumentGenerator, Firebird };\n// Unified module exports\nexport * from \"./
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uDAAoD;AAuB6D,gGAvBxG,iCAAe,OAuBwG;AAtBhI,+DAA2D;AAsBxC,oGAtBV,yCAAmB,OAsBU;AArBtC,wDAA0C;AAqBuH,4BAAQ;AApBzK,qCAA6C;AAoBG,0FApBvC,kBAAS,OAoBuC;AAAjB,uFApBpB,eAAM,OAoBoB;AAnB9C,+BAA4B;AAmB+B,oFAnBlD,SAAG,OAmBkD;AAlB9D,2CAA0F;AAkB1B,8FAlBvD,yBAAa,OAkBuD;AAAE,8FAlBvD,yBAAa,OAkBuD;AAAE,kGAlBvD,6BAAiB,OAkBuD;AAAmB,2FAlBxE,sBAAU,OAkBwE;AAjB5I,yCAAsC;AAiB7B,yFAjBA,mBAAQ,OAiBA;AAhBjB,2DAAwD;AAgBsF,kGAhBrI,qCAAiB,OAgBqI;AAf/J,6BAA2B;AAE3B,wCAAsB;AACtB,8CAA4B;AAC5B,2CAAyB;AACzB,6CAA2B;AAC3B,wDAAsC;AACtC,2DAAyC;AACzC,sDAAoC;AACpC,oDAAkC;AAClC,oDAAkC;AAElC,mDAAiC;AACjC,oDAAkC;AAClC,gDAA8B;AAE9B,yBAAyB;AACzB,0DAAwC;AACxC,yDAAuC;AACvC,2DAAyC","sourcesContent":["import { DatabaseUpdater } from \"./DatabaseUpdater\";\nimport { ExecutionTimeLogger } from \"./ExecutionTimeLogger\"\nimport * as Firebird from \"node-firebird\";\nimport { LogLevels, Logger } from \"./Logger\";\nimport { Orm } from \"./Orm\";\nimport { DateUtilities, RestUtilities, DatabaseUtilities, StatusCode } from \"./Utilities\";\nimport { autobind } from \"./autobind\";\nimport { DocumentGenerator } from \"./ContractGenerator\";\nimport \"./firebird-compat\";\n\nexport * from \"./Orm\";\nexport * from \"./Utilities\";\nexport * from \"./Logger\";\nexport * from \"./autobind\";\nexport * from \"./ExecutionTimeLogger\";\nexport * from \"./RoutesLoggerMiddleware\";\nexport * from \"./ContractGenerator\";\nexport * from \"./DatabaseUpdater\";\nexport * from \"./firebird-compat\";\n\nexport * from \"./accessi-module\";\nexport * from \"./allegati-module\";\nexport * from \"node-firebird\";\nexport { autobind, ExecutionTimeLogger, Logger, LogLevels, Orm, DateUtilities, RestUtilities, DatabaseUtilities, DatabaseUpdater, StatusCode, DocumentGenerator, Firebird };\n// Unified module exports\nexport * from \"./openapi/OpenApiConfig\";\nexport * from \"./openapi/OpenApiMerge\";\nexport * from \"./initEmilsoftwareModule\";\n"]}
|
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
import { Application } from "express";
|
|
2
|
+
import type { INestApplication } from "@nestjs/common";
|
|
3
|
+
import type { OpenAPIObject } from "@nestjs/swagger";
|
|
2
4
|
import { EmilsoftwareOptions } from "./EmilsoftwareModule";
|
|
5
|
+
/** Esito del bootstrap del modulo unificato. */
|
|
6
|
+
export interface EmilsoftwareModuleInitializationResult {
|
|
7
|
+
/** Sotto-app Nest che serve Accessi, Allegati e la documentazione. */
|
|
8
|
+
nestApp: INestApplication;
|
|
9
|
+
/** Documento OpenAPI generato, mergiabile nel documento unico dell'host. */
|
|
10
|
+
document: OpenAPIObject;
|
|
11
|
+
}
|
|
3
12
|
/**
|
|
4
13
|
* Initializes the unified module that combines Accessi and Allegati functionality
|
|
5
14
|
* @param app Express application instance
|
|
6
15
|
* @param options Configuration options for both modules
|
|
16
|
+
* @returns Il sotto-app Nest e il documento OpenAPI generato.
|
|
7
17
|
*/
|
|
8
|
-
export declare function initEmilsoftwareModule(app: Application, options: EmilsoftwareOptions): Promise<
|
|
18
|
+
export declare function initEmilsoftwareModule(app: Application, options: EmilsoftwareOptions): Promise<EmilsoftwareModuleInitializationResult>;
|
|
@@ -16,7 +16,7 @@ exports.initEmilsoftwareModule = initEmilsoftwareModule;
|
|
|
16
16
|
const express_1 = __importDefault(require("express"));
|
|
17
17
|
const core_1 = require("@nestjs/core");
|
|
18
18
|
const platform_express_1 = require("@nestjs/platform-express");
|
|
19
|
-
const
|
|
19
|
+
const OpenApiConfig_1 = require("./openapi/OpenApiConfig");
|
|
20
20
|
const Logger_1 = require("./Logger");
|
|
21
21
|
const EmilsoftwareModule_1 = require("./EmilsoftwareModule");
|
|
22
22
|
const authenticateGen_1 = require("./accessi-module/middleware/authenticateGen");
|
|
@@ -28,10 +28,11 @@ const AccessiHttpExceptionFilter_1 = require("./accessi-module/security/AccessiH
|
|
|
28
28
|
* Initializes the unified module that combines Accessi and Allegati functionality
|
|
29
29
|
* @param app Express application instance
|
|
30
30
|
* @param options Configuration options for both modules
|
|
31
|
+
* @returns Il sotto-app Nest e il documento OpenAPI generato.
|
|
31
32
|
*/
|
|
32
33
|
function initEmilsoftwareModule(app, options) {
|
|
33
34
|
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
-
var _a
|
|
35
|
+
var _a;
|
|
35
36
|
const logger = new Logger_1.Logger(initEmilsoftwareModule.name);
|
|
36
37
|
if (options === null || options === void 0 ? void 0 : options.accessiOptions) {
|
|
37
38
|
(0, authenticateGen_1.beginAccessiAuthInitialization)();
|
|
@@ -42,19 +43,12 @@ function initEmilsoftwareModule(app, options) {
|
|
|
42
43
|
// Prefisso OpenAPI configurabile (default `accessi/openapi`), cosi' piu'
|
|
43
44
|
// documentazioni possono convivere (backend su `/openapi`, moduli sotto
|
|
44
45
|
// `/<modulo>/openapi`).
|
|
45
|
-
|
|
46
|
-
const
|
|
47
|
-
const legacySwaggerJsonPath = `${swaggerPath}-json`;
|
|
48
|
-
const swaggerRoutePaths = [
|
|
49
|
-
`/${swaggerPath}`,
|
|
50
|
-
`/${swaggerPath}/`,
|
|
51
|
-
`/${swaggerJsonPath}`,
|
|
52
|
-
`/${legacySwaggerJsonPath}`,
|
|
53
|
-
];
|
|
46
|
+
// Precedenza: EmilsoftwareOptions.openapi > AccessiOptions.openapi > default.
|
|
47
|
+
const resolvedOpenApi = (0, OpenApiConfig_1.resolveAccessiOpenApiOptions)((_a = options === null || options === void 0 ? void 0 : options.accessiOptions) === null || _a === void 0 ? void 0 : _a.openapi, options === null || options === void 0 ? void 0 : options.openapi);
|
|
54
48
|
const nestHostApp = (0, express_1.default)();
|
|
55
49
|
const isNestRoute = (path) => path === "/api" ||
|
|
56
50
|
path.startsWith("/api/") ||
|
|
57
|
-
|
|
51
|
+
(0, OpenApiConfig_1.isOpenApiRequestPath)(path, resolvedOpenApi);
|
|
58
52
|
app.use((req, res, next) => {
|
|
59
53
|
if (!isNestRoute(req.path)) {
|
|
60
54
|
return next();
|
|
@@ -62,9 +56,7 @@ function initEmilsoftwareModule(app, options) {
|
|
|
62
56
|
return nestHostApp(req, res, next);
|
|
63
57
|
});
|
|
64
58
|
const nestExpressInstance = new platform_express_1.ExpressAdapter(nestHostApp);
|
|
65
|
-
const nestApp = yield core_1.NestFactory.create(EmilsoftwareModule_1.EmilsoftwareModule.forRoot(options), nestExpressInstance, {
|
|
66
|
-
bufferLogs: true
|
|
67
|
-
});
|
|
59
|
+
const nestApp = yield core_1.NestFactory.create(EmilsoftwareModule_1.EmilsoftwareModule.forRoot(options), nestExpressInstance, Object.assign({ bufferLogs: (options === null || options === void 0 ? void 0 : options.bufferLogs) !== false }, ((options === null || options === void 0 ? void 0 : options.logger) ? { logger: options.logger } : {})));
|
|
68
60
|
nestApp.enableCors();
|
|
69
61
|
if (options === null || options === void 0 ? void 0 : options.accessiOptions) {
|
|
70
62
|
// Keep the Accessi API contract identical for standalone and unified bootstraps.
|
|
@@ -72,23 +64,19 @@ function initEmilsoftwareModule(app, options) {
|
|
|
72
64
|
nestApp.useGlobalFilters(new AccessiHttpExceptionFilter_1.AccessiHttpExceptionFilter());
|
|
73
65
|
}
|
|
74
66
|
nestApp.setGlobalPrefix('api', {
|
|
75
|
-
exclude:
|
|
67
|
+
exclude: (0, OpenApiConfig_1.buildOpenApiExcludePaths)(resolvedOpenApi)
|
|
76
68
|
});
|
|
77
69
|
// Documentazione OpenAPI del modulo unificato (Accessi + Allegati).
|
|
78
|
-
(0,
|
|
79
|
-
swaggerPath,
|
|
80
|
-
swaggerJsonPath,
|
|
81
|
-
title: (_e = options === null || options === void 0 ? void 0 : options.swagger) === null || _e === void 0 ? void 0 : _e.title,
|
|
82
|
-
description: (_f = options === null || options === void 0 ? void 0 : options.swagger) === null || _f === void 0 ? void 0 : _f.description,
|
|
83
|
-
});
|
|
70
|
+
const document = (0, OpenApiConfig_1.setupOpenApi)(nestApp, resolvedOpenApi);
|
|
84
71
|
yield nestApp.init();
|
|
85
72
|
if (options === null || options === void 0 ? void 0 : options.accessiOptions) {
|
|
86
73
|
const accessiServices = (0, accessiRuntime_1.registerAccessiModuleServices)(app, nestApp);
|
|
87
74
|
app.locals.accessiAuthService = accessiServices.authenticateGenService;
|
|
88
75
|
(0, authenticateGen_1.setAccessiAuthService)(accessiServices.authenticateGenService);
|
|
89
|
-
(0, startupLog_1.logAccessiStartup)(options.accessiOptions);
|
|
76
|
+
(0, startupLog_1.logAccessiStartup)(options.accessiOptions, resolvedOpenApi);
|
|
90
77
|
}
|
|
91
78
|
logger.info("Emilsoftware module initialized successfully");
|
|
79
|
+
return { nestApp, document };
|
|
92
80
|
}
|
|
93
81
|
catch (error) {
|
|
94
82
|
if (options === null || options === void 0 ? void 0 : options.accessiOptions) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initEmilsoftwareModule.js","sourceRoot":"","sources":["../src/initEmilsoftwareModule.ts"],"names":[],"mappings":";;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"initEmilsoftwareModule.js","sourceRoot":"","sources":["../src/initEmilsoftwareModule.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAqCA,wDAwEC;AA7GD,sDAAwD;AACxD,uCAA2C;AAC3C,+DAA0D;AAG1D,2DAKiC;AACjC,qCAAkC;AAClC,6DAA+E;AAC/E,iFAIqD;AACrD,oEAAgF;AAChF,4DAAgE;AAChE,mFAA0F;AAC1F,qGAAkG;AAUlG;;;;;GAKG;AACH,SAAsB,sBAAsB,CACxC,GAAgB,EAChB,OAA4B;;;QAE5B,MAAM,MAAM,GAAW,IAAI,eAAM,CAAC,sBAAsB,CAAC,IAAI,CAAC,CAAC;QAC/D,IAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,cAAc,EAAE,CAAC;YAC1B,IAAA,gDAA8B,GAAE,CAAC;QACrC,CAAC;QAED,IAAI,CAAC;YACD,gFAAgF;YAChF,wEAAwE;YACxE,yEAAyE;YACzE,w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gBAC1B,iFAAiF;gBACjF,OAAO,CAAC,cAAc,CAAC,IAAA,+CAA2B,GAAE,CAAC,CAAC;gBACtD,OAAO,CAAC,gBAAgB,CAAC,IAAI,uDAA0B,EAAE,CAAC,CAAC;YAC/D,CAAC;YAED,OAAO,CAAC,eAAe,CAAC,KAAK,EAAE;gBAC3B,OAAO,EAAE,IAAA,wCAAwB,EAAC,eAAe,CAAC;aACrD,CAAC,CAAC;YAEH,oEAAoE;YACpE,MAAM,QAAQ,GAAG,IAAA,4BAAY,EAAC,OAAO,EAAE,eAAe,CAAC,CAAC;YAExD,MAAM,OAAO,CAAC,IAAI,EAAE,CAAC;YACrB,IAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,cAAc,EAAE,CAAC;gBAC1B,MAAM,eAAe,GAAG,IAAA,8CAA6B,EAAC,GAAG,EAAE,OAAO,CAAC,CAAC;gBACpE,GAAG,CAAC,MAAM,CAAC,kBAAkB,GAAG,eAAe,CAAC,sBAAsB,CAAC;gBACvE,IAAA,uCAAqB,EAAC,eAAe,CAAC,sBAAsB,CAAC,CAAC;gBAC9D,IAAA,8BAAiB,EAAC,OAAO,CAAC,cAAc,EAAE,eAAe,CAAC,CAAC;YAC/D,CAAC;YAED,MAAM,CAAC,IAAI,CAAC,8CAA8C,CAAC,CAAC;YAE5D,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;QACjC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,IAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,cAAc,EAAE,CAAC;gBAC1B,IAAA,+CAA6B,EAAC,KAAK,CAAC,CAAC;YACzC,CAAC;YACD,MAAM,CAAC,KAAK,CAAC,yCAAyC,EAAE,KAAK,CAAC,CAAC;YAC/D,MAAM,KAAK,CAAC;QAChB,CAAC;IACL,CAAC;CAAA","sourcesContent":["import express, { Application, Request } from \"express\";\nimport { NestFactory } from \"@nestjs/core\";\nimport { ExpressAdapter } from \"@nestjs/platform-express\";\nimport type { INestApplication } from \"@nestjs/common\";\nimport type { OpenAPIObject } from \"@nestjs/swagger\";\nimport {\n buildOpenApiExcludePaths,\n isOpenApiRequestPath,\n resolveAccessiOpenApiOptions,\n setupOpenApi\n} from \"./openapi/OpenApiConfig\";\nimport { Logger } from \"./Logger\";\nimport { EmilsoftwareModule, EmilsoftwareOptions } from \"./EmilsoftwareModule\";\nimport {\n beginAccessiAuthInitialization,\n failAccessiAuthInitialization,\n setAccessiAuthService\n} from \"./accessi-module/middleware/authenticateGen\";\nimport { registerAccessiModuleServices } from \"./accessi-module/accessiRuntime\";\nimport { logAccessiStartup } from \"./accessi-module/startupLog\";\nimport { createAccessiValidationPipe } from './accessi-module/security/accessiValidation';\nimport { AccessiHttpExceptionFilter } from './accessi-module/security/AccessiHttpExceptionFilter';\n\n/** Esito del bootstrap del modulo unificato. */\nexport interface EmilsoftwareModuleInitializationResult {\n /** Sotto-app Nest che serve Accessi, Allegati e la documentazione. */\n nestApp: INestApplication;\n /** Documento OpenAPI generato, mergiabile nel documento unico dell'host. */\n document: OpenAPIObject;\n}\n\n/**\n * Initializes the unified module that combines Accessi and Allegati functionality\n * @param app Express application instance\n * @param options Configuration options for both modules\n * @returns Il sotto-app Nest e il documento OpenAPI generato.\n */\nexport async function initEmilsoftwareModule(\n app: Application,\n options: EmilsoftwareOptions\n): Promise<EmilsoftwareModuleInitializationResult> {\n const logger: Logger = new Logger(initEmilsoftwareModule.name);\n if (options?.accessiOptions) {\n beginAccessiAuthInitialization();\n }\n\n try {\n // Isolate Nest on a dedicated Express instance and dispatch only module routes.\n // This keeps pre-existing routes/middlewares on the host app untouched.\n // Prefisso OpenAPI configurabile (default `accessi/openapi`), cosi' piu'\n // documentazioni possono convivere (backend su `/openapi`, moduli sotto\n // `/<modulo>/openapi`).\n // Precedenza: EmilsoftwareOptions.openapi > AccessiOptions.openapi > default.\n const resolvedOpenApi = resolveAccessiOpenApiOptions(\n options?.accessiOptions?.openapi,\n options?.openapi\n );\n\n const nestHostApp = express();\n const isNestRoute = (path: string) =>\n path === \"/api\" ||\n path.startsWith(\"/api/\") ||\n isOpenApiRequestPath(path, resolvedOpenApi);\n\n app.use((req: Request, res, next) => {\n if (!isNestRoute(req.path)) {\n return next();\n }\n return nestHostApp(req, res, next);\n });\n\n const nestExpressInstance = new ExpressAdapter(nestHostApp);\n const nestApp = await NestFactory.create(EmilsoftwareModule.forRoot(options), nestExpressInstance, {\n bufferLogs: options?.bufferLogs !== false,\n ...(options?.logger ? { logger: options.logger } : {})\n });\n\n nestApp.enableCors();\n if (options?.accessiOptions) {\n // Keep the Accessi API contract identical for standalone and unified bootstraps.\n nestApp.useGlobalPipes(createAccessiValidationPipe());\n nestApp.useGlobalFilters(new AccessiHttpExceptionFilter());\n }\n\n nestApp.setGlobalPrefix('api', {\n exclude: buildOpenApiExcludePaths(resolvedOpenApi)\n });\n\n // Documentazione OpenAPI del modulo unificato (Accessi + Allegati).\n const document = setupOpenApi(nestApp, resolvedOpenApi);\n\n await nestApp.init();\n if (options?.accessiOptions) {\n const accessiServices = registerAccessiModuleServices(app, nestApp);\n app.locals.accessiAuthService = accessiServices.authenticateGenService;\n setAccessiAuthService(accessiServices.authenticateGenService);\n logAccessiStartup(options.accessiOptions, resolvedOpenApi);\n }\n\n logger.info(\"Emilsoftware module initialized successfully\");\n\n return { nestApp, document };\n } catch (error) {\n if (options?.accessiOptions) {\n failAccessiAuthInitialization(error);\n }\n logger.error(\"Error initializing Emilsoftware Module:\", error);\n throw error;\n }\n}\n"]}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { INestApplication } from "@nestjs/common";
|
|
2
|
+
import type { OpenAPIObject } from "@nestjs/swagger";
|
|
3
|
+
/**
|
|
4
|
+
* Opzioni di setup della documentazione OpenAPI.
|
|
5
|
+
*
|
|
6
|
+
* `enabled: false` disabilita UI e JSON ma non il documento generato, che resta
|
|
7
|
+
* disponibile al chiamante per essere mergiato nel documento OpenAPI dell'host.
|
|
8
|
+
*/
|
|
9
|
+
export type OpenApiSetupOptions = {
|
|
10
|
+
enabled?: boolean;
|
|
11
|
+
openApiPath?: string;
|
|
12
|
+
openApiJsonPath?: string;
|
|
13
|
+
title?: string;
|
|
14
|
+
description?: string;
|
|
15
|
+
/** Callback invocata subito dopo la generazione del documento OpenAPI. */
|
|
16
|
+
onDocument?: (document: OpenAPIObject) => void;
|
|
17
|
+
};
|
|
18
|
+
/** Opzioni OpenAPI risolte: nessun campo opzionale salvo il callback. */
|
|
19
|
+
export interface ResolvedOpenApiSetupOptions {
|
|
20
|
+
enabled: boolean;
|
|
21
|
+
openApiPath: string;
|
|
22
|
+
openApiJsonPath: string;
|
|
23
|
+
title: string;
|
|
24
|
+
description: string;
|
|
25
|
+
onDocument?: (document: OpenAPIObject) => void;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Default storici della documentazione Accessi.
|
|
29
|
+
*
|
|
30
|
+
* I consumer esistenti non devono cambiare comportamento: senza override la UI
|
|
31
|
+
* resta su `accessi/openapi` e la spec su `accessi/openapi.json`.
|
|
32
|
+
*/
|
|
33
|
+
export declare const DEFAULT_ACCESSI_OPENAPI: {
|
|
34
|
+
readonly enabled: true;
|
|
35
|
+
readonly openApiPath: "accessi/openapi";
|
|
36
|
+
readonly openApiJsonPath: "accessi/openapi.json";
|
|
37
|
+
readonly title: "Accessi API Documentation";
|
|
38
|
+
readonly description: "API del modulo accessi";
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Risolve i default e i vari livelli di override in un'unica configurazione.
|
|
42
|
+
*
|
|
43
|
+
* L'ordine dei livelli e esplicito: i parametri successivi vincono sui precedenti.
|
|
44
|
+
*/
|
|
45
|
+
export declare function resolveOpenApiSetupOptions(defaults?: OpenApiSetupOptions, ...overrides: Array<OpenApiSetupOptions | undefined>): ResolvedOpenApiSetupOptions;
|
|
46
|
+
/**
|
|
47
|
+
* Risolve la configurazione OpenAPI di Accessi.
|
|
48
|
+
*
|
|
49
|
+
* I livelli successivi vincono sui precedenti, quindi la variante unificata puo
|
|
50
|
+
* usare `resolveAccessiOpenApiOptions(accessiOptions.openapi, emilsoftwareOptions.openapi)`.
|
|
51
|
+
*/
|
|
52
|
+
export declare function resolveAccessiOpenApiOptions(...overrides: Array<OpenApiSetupOptions | undefined>): ResolvedOpenApiSetupOptions;
|
|
53
|
+
/**
|
|
54
|
+
* Path da passare a `setGlobalPrefix` per escludere la documentazione.
|
|
55
|
+
*
|
|
56
|
+
* Usa la sintassi wildcard di path-to-regexp v8 (`{*path}`) per evitare il
|
|
57
|
+
* LegacyRouteConverter warning di Nest.
|
|
58
|
+
*/
|
|
59
|
+
export declare function buildOpenApiExcludePaths(options: ResolvedOpenApiSetupOptions): string[];
|
|
60
|
+
/** True se il path Express appartiene alla documentazione OpenAPI configurata. */
|
|
61
|
+
export declare function isOpenApiRequestPath(path: string, options: ResolvedOpenApiSetupOptions): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Genera il documento OpenAPI e, se `enabled` non e false, monta UI e JSON.
|
|
64
|
+
*
|
|
65
|
+
* Il documento viene sempre restituito: questo permette all'host di mergiarlo
|
|
66
|
+
* nel proprio documento unico anche quando la UI del modulo e disabilitata.
|
|
67
|
+
*/
|
|
68
|
+
export declare function setupOpenApi(app: INestApplication, options?: OpenApiSetupOptions): OpenAPIObject;
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_ACCESSI_OPENAPI = void 0;
|
|
4
|
+
exports.resolveOpenApiSetupOptions = resolveOpenApiSetupOptions;
|
|
5
|
+
exports.resolveAccessiOpenApiOptions = resolveAccessiOpenApiOptions;
|
|
6
|
+
exports.buildOpenApiExcludePaths = buildOpenApiExcludePaths;
|
|
7
|
+
exports.isOpenApiRequestPath = isOpenApiRequestPath;
|
|
8
|
+
exports.setupOpenApi = setupOpenApi;
|
|
9
|
+
const swagger_1 = require("@nestjs/swagger");
|
|
10
|
+
const Logger_1 = require("../Logger");
|
|
11
|
+
/**
|
|
12
|
+
* Default storici della documentazione Accessi.
|
|
13
|
+
*
|
|
14
|
+
* I consumer esistenti non devono cambiare comportamento: senza override la UI
|
|
15
|
+
* resta su `accessi/openapi` e la spec su `accessi/openapi.json`.
|
|
16
|
+
*/
|
|
17
|
+
exports.DEFAULT_ACCESSI_OPENAPI = {
|
|
18
|
+
enabled: true,
|
|
19
|
+
openApiPath: "accessi/openapi",
|
|
20
|
+
openApiJsonPath: "accessi/openapi.json",
|
|
21
|
+
title: "Accessi API Documentation",
|
|
22
|
+
description: "API del modulo accessi",
|
|
23
|
+
};
|
|
24
|
+
/** Default del setup OpenAPI generico (usato direttamente da `setupOpenApi`). */
|
|
25
|
+
const DEFAULT_OPENAPI_SETUP = {
|
|
26
|
+
enabled: true,
|
|
27
|
+
openApiPath: "openapi",
|
|
28
|
+
openApiJsonPath: "openapi.json",
|
|
29
|
+
title: "API Documentation",
|
|
30
|
+
description: "API per la gestione di accessi utenti e allegati",
|
|
31
|
+
};
|
|
32
|
+
function normalizeOpenApiPath(value) {
|
|
33
|
+
return value.replace(/^\/+|\/+$/g, "");
|
|
34
|
+
}
|
|
35
|
+
function normalizeOpenApiJsonPath(value) {
|
|
36
|
+
return value.replace(/^\/+|\/+$/g, "");
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Unisce i livelli di configurazione ignorando le proprieta `undefined`.
|
|
40
|
+
*
|
|
41
|
+
* A differenza dello spread semplice, un `{ openApiPath: undefined }` esplicito
|
|
42
|
+
* non cancella il default del livello precedente.
|
|
43
|
+
*/
|
|
44
|
+
function mergeOpenApiSetupOptions(defaults, ...overrides) {
|
|
45
|
+
const merged = Object.assign({}, defaults);
|
|
46
|
+
for (const override of overrides) {
|
|
47
|
+
if (!override)
|
|
48
|
+
continue;
|
|
49
|
+
if (override.enabled !== undefined)
|
|
50
|
+
merged.enabled = override.enabled;
|
|
51
|
+
if (override.openApiPath !== undefined)
|
|
52
|
+
merged.openApiPath = override.openApiPath;
|
|
53
|
+
if (override.openApiJsonPath !== undefined)
|
|
54
|
+
merged.openApiJsonPath = override.openApiJsonPath;
|
|
55
|
+
if (override.title !== undefined)
|
|
56
|
+
merged.title = override.title;
|
|
57
|
+
if (override.description !== undefined)
|
|
58
|
+
merged.description = override.description;
|
|
59
|
+
if (override.onDocument !== undefined)
|
|
60
|
+
merged.onDocument = override.onDocument;
|
|
61
|
+
}
|
|
62
|
+
return merged;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Risolve i default e i vari livelli di override in un'unica configurazione.
|
|
66
|
+
*
|
|
67
|
+
* L'ordine dei livelli e esplicito: i parametri successivi vincono sui precedenti.
|
|
68
|
+
*/
|
|
69
|
+
function resolveOpenApiSetupOptions(defaults = DEFAULT_OPENAPI_SETUP, ...overrides) {
|
|
70
|
+
var _a, _b, _c, _d, _e, _f;
|
|
71
|
+
const merged = mergeOpenApiSetupOptions(defaults, ...overrides);
|
|
72
|
+
const defaultOpenApiPath = normalizeOpenApiPath((_a = defaults.openApiPath) !== null && _a !== void 0 ? _a : "openapi") || "openapi";
|
|
73
|
+
const openApiPath = normalizeOpenApiPath((_b = merged.openApiPath) !== null && _b !== void 0 ? _b : defaultOpenApiPath) || defaultOpenApiPath;
|
|
74
|
+
// Storico: se si cambia solo `openApiPath`, il JSON segue il nuovo path
|
|
75
|
+
// (`<path>.json`). Un `openApiJsonPath` esplicito in un override vince sempre.
|
|
76
|
+
const explicitJsonPath = (_c = [...overrides]
|
|
77
|
+
.reverse()
|
|
78
|
+
.find((override) => (override === null || override === void 0 ? void 0 : override.openApiJsonPath) !== undefined)) === null || _c === void 0 ? void 0 : _c.openApiJsonPath;
|
|
79
|
+
const hasOverrides = overrides.some((override) => override !== undefined);
|
|
80
|
+
const jsonPathCandidate = explicitJsonPath !== null && explicitJsonPath !== void 0 ? explicitJsonPath : (hasOverrides ? `${openApiPath}.json` : ((_d = merged.openApiJsonPath) !== null && _d !== void 0 ? _d : `${openApiPath}.json`));
|
|
81
|
+
const openApiJsonPath = normalizeOpenApiJsonPath(jsonPathCandidate) || `${openApiPath}.json`;
|
|
82
|
+
return Object.assign({ enabled: merged.enabled !== false, openApiPath,
|
|
83
|
+
openApiJsonPath, title: (_e = merged.title) !== null && _e !== void 0 ? _e : "API Documentation", description: (_f = merged.description) !== null && _f !== void 0 ? _f : "API per la gestione di accessi utenti e allegati" }, (merged.onDocument ? { onDocument: merged.onDocument } : {}));
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Risolve la configurazione OpenAPI di Accessi.
|
|
87
|
+
*
|
|
88
|
+
* I livelli successivi vincono sui precedenti, quindi la variante unificata puo
|
|
89
|
+
* usare `resolveAccessiOpenApiOptions(accessiOptions.openapi, emilsoftwareOptions.openapi)`.
|
|
90
|
+
*/
|
|
91
|
+
function resolveAccessiOpenApiOptions(...overrides) {
|
|
92
|
+
return resolveOpenApiSetupOptions(exports.DEFAULT_ACCESSI_OPENAPI, ...overrides);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Path da passare a `setGlobalPrefix` per escludere la documentazione.
|
|
96
|
+
*
|
|
97
|
+
* Usa la sintassi wildcard di path-to-regexp v8 (`{*path}`) per evitare il
|
|
98
|
+
* LegacyRouteConverter warning di Nest.
|
|
99
|
+
*/
|
|
100
|
+
function buildOpenApiExcludePaths(options) {
|
|
101
|
+
if (!options.enabled)
|
|
102
|
+
return [];
|
|
103
|
+
return [`/${options.openApiPath}`, `/${options.openApiPath}/{*path}`];
|
|
104
|
+
}
|
|
105
|
+
/** True se il path Express appartiene alla documentazione OpenAPI configurata. */
|
|
106
|
+
function isOpenApiRequestPath(path, options) {
|
|
107
|
+
if (!options.enabled)
|
|
108
|
+
return false;
|
|
109
|
+
const uiPath = `/${options.openApiPath}`;
|
|
110
|
+
if (path === uiPath || path.startsWith(`${uiPath}/`))
|
|
111
|
+
return true;
|
|
112
|
+
return path === `/${options.openApiJsonPath}` || path === `/${options.openApiPath}-json`;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Genera il documento OpenAPI e, se `enabled` non e false, monta UI e JSON.
|
|
116
|
+
*
|
|
117
|
+
* Il documento viene sempre restituito: questo permette all'host di mergiarlo
|
|
118
|
+
* nel proprio documento unico anche quando la UI del modulo e disabilitata.
|
|
119
|
+
*/
|
|
120
|
+
function setupOpenApi(app, options) {
|
|
121
|
+
var _a, _b, _c;
|
|
122
|
+
const logger = new Logger_1.Logger("OpenApiConfig");
|
|
123
|
+
const resolved = resolveOpenApiSetupOptions(DEFAULT_OPENAPI_SETUP, options);
|
|
124
|
+
const config = new swagger_1.DocumentBuilder()
|
|
125
|
+
.setTitle(resolved.title)
|
|
126
|
+
.setDescription(resolved.description)
|
|
127
|
+
.setVersion("1.0")
|
|
128
|
+
.addBearerAuth() // Per abilitare l'autenticazione JWT
|
|
129
|
+
.build();
|
|
130
|
+
const document = swagger_1.SwaggerModule.createDocument(app, config);
|
|
131
|
+
(_a = resolved.onDocument) === null || _a === void 0 ? void 0 : _a.call(resolved, document);
|
|
132
|
+
if (!resolved.enabled) {
|
|
133
|
+
logger.info("OpenAPI disabilitato: UI e JSON non montati.");
|
|
134
|
+
return document;
|
|
135
|
+
}
|
|
136
|
+
swagger_1.SwaggerModule.setup(resolved.openApiPath, app, document);
|
|
137
|
+
app.use(`/${resolved.openApiJsonPath}`, (_req, res) => {
|
|
138
|
+
res.setHeader("Content-Type", "application/json");
|
|
139
|
+
res.send(document);
|
|
140
|
+
});
|
|
141
|
+
// Manteniamo l'alias storico `<path>-json` per non rompere i consumer esistenti.
|
|
142
|
+
const legacyOpenApiJsonPath = `${resolved.openApiPath}-json`;
|
|
143
|
+
if (legacyOpenApiJsonPath !== resolved.openApiJsonPath) {
|
|
144
|
+
app.use(`/${legacyOpenApiJsonPath}`, (_req, res) => {
|
|
145
|
+
res.setHeader("Content-Type", "application/json");
|
|
146
|
+
res.send(document);
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
const serverAddress = (_c = (_b = app.getHttpServer()) === null || _b === void 0 ? void 0 : _b.address) === null || _c === void 0 ? void 0 : _c.call(_b);
|
|
150
|
+
const port = serverAddress && typeof serverAddress === "object"
|
|
151
|
+
? serverAddress.port
|
|
152
|
+
: 3000;
|
|
153
|
+
logger.info(`OpenAPI documentation available at: http://localhost:${port}/${resolved.openApiPath}`);
|
|
154
|
+
logger.info(`OpenAPI JSON available at: http://localhost:${port}/${resolved.openApiJsonPath}`);
|
|
155
|
+
return document;
|
|
156
|
+
}
|
|
157
|
+
//# sourceMappingURL=OpenApiConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OpenApiConfig.js","sourceRoot":"","sources":["../../src/openapi/OpenApiConfig.ts"],"names":[],"mappings":";;;AA4FA,gEA2BC;AAQD,oEAIC;AAQD,4DAGC;AAGD,oDAOC;AAQD,oCAgDC;AA/MD,6CAAiE;AAIjE,sCAAmC;AA4BnC;;;;;GAKG;AACU,QAAA,uBAAuB,GAAG;IACnC,OAAO,EAAE,IAAI;IACb,WAAW,EAAE,iBAAiB;IAC9B,eAAe,EAAE,sBAAsB;IACvC,KAAK,EAAE,2BAA2B;IAClC,WAAW,EAAE,wBAAwB;CACO,CAAC;AAEjD,iFAAiF;AACjF,MAAM,qBAAqB,GAAG;IAC1B,OAAO,EAAE,IAAI;IACb,WAAW,EAAE,SAAS;IACtB,eAAe,EAAE,cAAc;IAC/B,KAAK,EAAE,mBAAmB;IAC1B,WAAW,EAAE,kDAAkD;CACnB,CAAC;AAEjD,SAAS,oBAAoB,CAAC,KAAa;IACvC,OAAO,KAAK,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;AAC3C,CAAC;AAED,SAAS,wBAAwB,CAAC,KAAa;IAC3C,OAAO,KAAK,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;AAC3C,CAAC;AAED;;;;;GAKG;AAC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E,QAAQ,CAAC,CAAC;IAEzD,GAAG,CAAC,GAAG,CAAC,IAAI,QAAQ,CAAC,eAAe,EAAE,EAAE,CAAC,IAAa,EAAE,GAAa,EAAE,EAAE;QACrE,GAAG,CAAC,SAAS,CAAC,cAAc,EAAE,kBAAkB,CAAC,CAAC;QAClD,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACvB,CAAC,CAAC,CAAC;IAEH,iFAAiF;IACjF,MAAM,qBAAqB,GAAG,GAAG,QAAQ,CAAC,WAAW,OAAO,CAAC;IAC7D,IAAI,qBAAqB,KAAK,QAAQ,CAAC,eAAe,EAAE,CAAC;QACrD,GAAG,CAAC,GAAG,CAAC,IAAI,qBAAqB,EAAE,EAAE,CAAC,IAAa,EAAE,GAAa,EAAE,EAAE;YAClE,GAAG,CAAC,SAAS,CAAC,cAAc,EAAE,kBAAkB,CAAC,CAAC;YAClD,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACvB,CAAC,CAAC,CAAC;IACP,CAAC;IAED,MAAM,aAAa,GAAG,MAAA,MAAA,GAAG,CAAC,aAAa,EAAE,0CAAE,OAAO,kDAAI,CAAC;IACvD,MAAM,IAAI,GAAG,aAAa,IAAI,OAAO,aAAa,KAAK,QAAQ;QAC3D,CAAC,CAAE,aAA6B,CAAC,IAAI;QACrC,CAAC,CAAC,IAAI,CAAC;IAEX,MAAM,CAAC,IAAI,CACP,wDAAwD,IAAI,IAAI,QAAQ,CAAC,WAAW,EAAE,CACzF,CAAC;IACF,MAAM,CAAC,IAAI,CACP,+CAA+C,IAAI,IAAI,QAAQ,CAAC,eAAe,EAAE,CACpF,CAAC;IAEF,OAAO,QAAQ,CAAC;AACpB,CAAC","sourcesContent":["import { INestApplication } from \"@nestjs/common\";\nimport { DocumentBuilder, SwaggerModule } from \"@nestjs/swagger\";\nimport type { OpenAPIObject } from \"@nestjs/swagger\";\nimport { Request, Response } from \"express\";\nimport { AddressInfo } from \"net\";\nimport { Logger } from \"../Logger\";\n\n/**\n * Opzioni di setup della documentazione OpenAPI.\n *\n * `enabled: false` disabilita UI e JSON ma non il documento generato, che resta\n * disponibile al chiamante per essere mergiato nel documento OpenAPI dell'host.\n */\nexport type OpenApiSetupOptions = {\n enabled?: boolean;\n openApiPath?: string;\n openApiJsonPath?: string;\n title?: string;\n description?: string;\n /** Callback invocata subito dopo la generazione del documento OpenAPI. */\n onDocument?: (document: OpenAPIObject) => void;\n};\n\n/** Opzioni OpenAPI risolte: nessun campo opzionale salvo il callback. */\nexport interface ResolvedOpenApiSetupOptions {\n enabled: boolean;\n openApiPath: string;\n openApiJsonPath: string;\n title: string;\n description: string;\n onDocument?: (document: OpenAPIObject) => void;\n}\n\n/**\n * Default storici della documentazione Accessi.\n *\n * I consumer esistenti non devono cambiare comportamento: senza override la UI\n * resta su `accessi/openapi` e la spec su `accessi/openapi.json`.\n */\nexport const DEFAULT_ACCESSI_OPENAPI = {\n enabled: true,\n openApiPath: \"accessi/openapi\",\n openApiJsonPath: \"accessi/openapi.json\",\n title: \"Accessi API Documentation\",\n description: \"API del modulo accessi\",\n} as const satisfies ResolvedOpenApiSetupOptions;\n\n/** Default del setup OpenAPI generico (usato direttamente da `setupOpenApi`). */\nconst DEFAULT_OPENAPI_SETUP = {\n enabled: true,\n openApiPath: \"openapi\",\n openApiJsonPath: \"openapi.json\",\n title: \"API Documentation\",\n description: \"API per la gestione di accessi utenti e allegati\",\n} as const satisfies ResolvedOpenApiSetupOptions;\n\nfunction normalizeOpenApiPath(value: string): string {\n return value.replace(/^\\/+|\\/+$/g, \"\");\n}\n\nfunction normalizeOpenApiJsonPath(value: string): string {\n return value.replace(/^\\/+|\\/+$/g, \"\");\n}\n\n/**\n * Unisce i livelli di configurazione ignorando le proprieta `undefined`.\n *\n * A differenza dello spread semplice, un `{ openApiPath: undefined }` esplicito\n * non cancella il default del livello precedente.\n */\nfunction mergeOpenApiSetupOptions(\n defaults: OpenApiSetupOptions,\n ...overrides: Array<OpenApiSetupOptions | undefined>\n): OpenApiSetupOptions {\n const merged: OpenApiSetupOptions = { ...defaults };\n for (const override of overrides) {\n if (!override) continue;\n if (override.enabled !== undefined) merged.enabled = override.enabled;\n if (override.openApiPath !== undefined) merged.openApiPath = override.openApiPath;\n if (override.openApiJsonPath !== undefined) merged.openApiJsonPath = override.openApiJsonPath;\n if (override.title !== undefined) merged.title = override.title;\n if (override.description !== undefined) merged.description = override.description;\n if (override.onDocument !== undefined) merged.onDocument = override.onDocument;\n }\n return merged;\n}\n\n/**\n * Risolve i default e i vari livelli di override in un'unica configurazione.\n *\n * L'ordine dei livelli e esplicito: i parametri successivi vincono sui precedenti.\n */\nexport function resolveOpenApiSetupOptions(\n defaults: OpenApiSetupOptions = DEFAULT_OPENAPI_SETUP,\n ...overrides: Array<OpenApiSetupOptions | undefined>\n): ResolvedOpenApiSetupOptions {\n const merged = mergeOpenApiSetupOptions(defaults, ...overrides);\n const defaultOpenApiPath = normalizeOpenApiPath(defaults.openApiPath ?? \"openapi\") || \"openapi\";\n const openApiPath = normalizeOpenApiPath(merged.openApiPath ?? defaultOpenApiPath) || defaultOpenApiPath;\n\n // Storico: se si cambia solo `openApiPath`, il JSON segue il nuovo path\n // (`<path>.json`). Un `openApiJsonPath` esplicito in un override vince sempre.\n const explicitJsonPath = [...overrides]\n .reverse()\n .find((override) => override?.openApiJsonPath !== undefined)\n ?.openApiJsonPath;\n const hasOverrides = overrides.some((override) => override !== undefined);\n const jsonPathCandidate = explicitJsonPath\n ?? (hasOverrides ? `${openApiPath}.json` : (merged.openApiJsonPath ?? `${openApiPath}.json`));\n const openApiJsonPath = normalizeOpenApiJsonPath(jsonPathCandidate) || `${openApiPath}.json`;\n\n return {\n enabled: merged.enabled !== false,\n openApiPath,\n openApiJsonPath,\n title: merged.title ?? \"API Documentation\",\n description: merged.description ?? \"API per la gestione di accessi utenti e allegati\",\n ...(merged.onDocument ? { onDocument: merged.onDocument } : {}),\n };\n}\n\n/**\n * Risolve la configurazione OpenAPI di Accessi.\n *\n * I livelli successivi vincono sui precedenti, quindi la variante unificata puo\n * usare `resolveAccessiOpenApiOptions(accessiOptions.openapi, emilsoftwareOptions.openapi)`.\n */\nexport function resolveAccessiOpenApiOptions(\n ...overrides: Array<OpenApiSetupOptions | undefined>\n): ResolvedOpenApiSetupOptions {\n return resolveOpenApiSetupOptions(DEFAULT_ACCESSI_OPENAPI, ...overrides);\n}\n\n/**\n * Path da passare a `setGlobalPrefix` per escludere la documentazione.\n *\n * Usa la sintassi wildcard di path-to-regexp v8 (`{*path}`) per evitare il\n * LegacyRouteConverter warning di Nest.\n */\nexport function buildOpenApiExcludePaths(options: ResolvedOpenApiSetupOptions): string[] {\n if (!options.enabled) return [];\n return [`/${options.openApiPath}`, `/${options.openApiPath}/{*path}`];\n}\n\n/** True se il path Express appartiene alla documentazione OpenAPI configurata. */\nexport function isOpenApiRequestPath(path: string, options: ResolvedOpenApiSetupOptions): boolean {\n if (!options.enabled) return false;\n\n const uiPath = `/${options.openApiPath}`;\n if (path === uiPath || path.startsWith(`${uiPath}/`)) return true;\n\n return path === `/${options.openApiJsonPath}` || path === `/${options.openApiPath}-json`;\n}\n\n/**\n * Genera il documento OpenAPI e, se `enabled` non e false, monta UI e JSON.\n *\n * Il documento viene sempre restituito: questo permette all'host di mergiarlo\n * nel proprio documento unico anche quando la UI del modulo e disabilitata.\n */\nexport function setupOpenApi(app: INestApplication, options?: OpenApiSetupOptions): OpenAPIObject {\n const logger: Logger = new Logger(\"OpenApiConfig\");\n const resolved = resolveOpenApiSetupOptions(DEFAULT_OPENAPI_SETUP, options);\n\n const config = new DocumentBuilder()\n .setTitle(resolved.title)\n .setDescription(resolved.description)\n .setVersion(\"1.0\")\n .addBearerAuth() // Per abilitare l'autenticazione JWT\n .build();\n\n const document = SwaggerModule.createDocument(app, config);\n resolved.onDocument?.(document);\n\n if (!resolved.enabled) {\n logger.info(\"OpenAPI disabilitato: UI e JSON non montati.\");\n return document;\n }\n\n SwaggerModule.setup(resolved.openApiPath, app, document);\n\n app.use(`/${resolved.openApiJsonPath}`, (_req: Request, res: Response) => {\n res.setHeader(\"Content-Type\", \"application/json\");\n res.send(document);\n });\n\n // Manteniamo l'alias storico `<path>-json` per non rompere i consumer esistenti.\n const legacyOpenApiJsonPath = `${resolved.openApiPath}-json`;\n if (legacyOpenApiJsonPath !== resolved.openApiJsonPath) {\n app.use(`/${legacyOpenApiJsonPath}`, (_req: Request, res: Response) => {\n res.setHeader(\"Content-Type\", \"application/json\");\n res.send(document);\n });\n }\n\n const serverAddress = app.getHttpServer()?.address?.();\n const port = serverAddress && typeof serverAddress === \"object\"\n ? (serverAddress as AddressInfo).port\n : 3000;\n\n logger.info(\n `OpenAPI documentation available at: http://localhost:${port}/${resolved.openApiPath}`\n );\n logger.info(\n `OpenAPI JSON available at: http://localhost:${port}/${resolved.openApiJsonPath}`\n );\n\n return document;\n}\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { OpenAPIObject } from "@nestjs/swagger";
|
|
2
|
+
/** Politica di risoluzione quando due documenti definiscono la stessa chiave. */
|
|
3
|
+
export type OpenApiMergeConflictPolicy = "error" | "keep" | "overwrite";
|
|
4
|
+
export interface MergeOpenApiOptions {
|
|
5
|
+
/** Default: `error`. */
|
|
6
|
+
conflict?: OpenApiMergeConflictPolicy;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Unisce il documento Accessi nel documento OpenAPI dell'host.
|
|
10
|
+
*
|
|
11
|
+
* Per default un conflitto su path, schema o security scheme produce errore:
|
|
12
|
+
* e meglio accorgersi subito di due contratti incompatibili. Usare
|
|
13
|
+
* `conflict: "overwrite"` solo quando il documento host deve vincere.
|
|
14
|
+
*/
|
|
15
|
+
export declare function mergeOpenApiDocuments(target: OpenAPIObject, source: OpenAPIObject, options?: MergeOpenApiOptions): OpenAPIObject;
|