@alagoni97/cli 0.72.1
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/LICENSE +201 -0
- package/README.md +336 -0
- package/bin/dev.cmd +3 -0
- package/bin/dev.mjs +3 -0
- package/bin/run.cmd +3 -0
- package/bin/run.mjs +4 -0
- package/dist/LoggingInterface.d.ts +123 -0
- package/dist/LoggingInterface.js +300 -0
- package/dist/PersistedConfig.d.ts +46 -0
- package/dist/PersistedConfig.js +94 -0
- package/dist/browser/adapters/output.d.ts +69 -0
- package/dist/browser/adapters/output.js +91 -0
- package/dist/browser/config.d.ts +18 -0
- package/dist/browser/config.js +59 -0
- package/dist/browser/generate.d.ts +20 -0
- package/dist/browser/generate.js +129 -0
- package/dist/browser/index.d.ts +17 -0
- package/dist/browser/index.js +26 -0
- package/dist/browser/parser.d.ts +9 -0
- package/dist/browser/parser.js +61 -0
- package/dist/browser/shims/asyncapi-parser.d.ts +30 -0
- package/dist/browser/shims/asyncapi-parser.js +52 -0
- package/dist/browser/shims/fs.d.ts +190 -0
- package/dist/browser/shims/fs.js +188 -0
- package/dist/browser/shims/json-schema-ref-parser.d.ts +73 -0
- package/dist/browser/shims/json-schema-ref-parser.js +246 -0
- package/dist/browser/shims/swagger-parser.d.ts +20 -0
- package/dist/browser/shims/swagger-parser.js +40 -0
- package/dist/codegen/configurationSchemaBuilder.d.ts +15 -0
- package/dist/codegen/configurationSchemaBuilder.js +48 -0
- package/dist/codegen/configurations.d.ts +29 -0
- package/dist/codegen/configurations.js +260 -0
- package/dist/codegen/detection.d.ts +19 -0
- package/dist/codegen/detection.js +174 -0
- package/dist/codegen/errors.d.ts +111 -0
- package/dist/codegen/errors.js +352 -0
- package/dist/codegen/generators/generic/custom.d.ts +75 -0
- package/dist/codegen/generators/generic/custom.js +66 -0
- package/dist/codegen/generators/index.d.ts +14 -0
- package/dist/codegen/generators/index.js +42 -0
- package/dist/codegen/generators/typescript/channels/asyncapi.d.ts +10 -0
- package/dist/codegen/generators/typescript/channels/asyncapi.js +131 -0
- package/dist/codegen/generators/typescript/channels/index.d.ts +8 -0
- package/dist/codegen/generators/typescript/channels/index.js +142 -0
- package/dist/codegen/generators/typescript/channels/openapi.d.ts +9 -0
- package/dist/codegen/generators/typescript/channels/openapi.js +168 -0
- package/dist/codegen/generators/typescript/channels/protocols/amqp/index.d.ts +7 -0
- package/dist/codegen/generators/typescript/channels/protocols/amqp/index.js +149 -0
- package/dist/codegen/generators/typescript/channels/protocols/amqp/publishExchange.d.ts +5 -0
- package/dist/codegen/generators/typescript/channels/protocols/amqp/publishExchange.js +106 -0
- package/dist/codegen/generators/typescript/channels/protocols/amqp/publishQueue.d.ts +3 -0
- package/dist/codegen/generators/typescript/channels/protocols/amqp/publishQueue.js +102 -0
- package/dist/codegen/generators/typescript/channels/protocols/amqp/subscribeQueue.d.ts +3 -0
- package/dist/codegen/generators/typescript/channels/protocols/amqp/subscribeQueue.js +133 -0
- package/dist/codegen/generators/typescript/channels/protocols/eventsource/express.d.ts +3 -0
- package/dist/codegen/generators/typescript/channels/protocols/eventsource/express.js +100 -0
- package/dist/codegen/generators/typescript/channels/protocols/eventsource/fetch.d.ts +5 -0
- package/dist/codegen/generators/typescript/channels/protocols/eventsource/fetch.js +144 -0
- package/dist/codegen/generators/typescript/channels/protocols/eventsource/index.d.ts +6 -0
- package/dist/codegen/generators/typescript/channels/protocols/eventsource/index.js +132 -0
- package/dist/codegen/generators/typescript/channels/protocols/http/client.d.ts +10 -0
- package/dist/codegen/generators/typescript/channels/protocols/http/client.js +224 -0
- package/dist/codegen/generators/typescript/channels/protocols/http/common-types.d.ts +14 -0
- package/dist/codegen/generators/typescript/channels/protocols/http/common-types.js +800 -0
- package/dist/codegen/generators/typescript/channels/protocols/http/index.d.ts +8 -0
- package/dist/codegen/generators/typescript/channels/protocols/http/index.js +96 -0
- package/dist/codegen/generators/typescript/channels/protocols/http/security.d.ts +48 -0
- package/dist/codegen/generators/typescript/channels/protocols/http/security.js +491 -0
- package/dist/codegen/generators/typescript/channels/protocols/kafka/index.d.ts +6 -0
- package/dist/codegen/generators/typescript/channels/protocols/kafka/index.js +127 -0
- package/dist/codegen/generators/typescript/channels/protocols/kafka/publish.d.ts +3 -0
- package/dist/codegen/generators/typescript/channels/protocols/kafka/publish.js +108 -0
- package/dist/codegen/generators/typescript/channels/protocols/kafka/subscribe.d.ts +3 -0
- package/dist/codegen/generators/typescript/channels/protocols/kafka/subscribe.js +154 -0
- package/dist/codegen/generators/typescript/channels/protocols/kafka/utils.d.ts +11 -0
- package/dist/codegen/generators/typescript/channels/protocols/kafka/utils.js +58 -0
- package/dist/codegen/generators/typescript/channels/protocols/mqtt/index.d.ts +6 -0
- package/dist/codegen/generators/typescript/channels/protocols/mqtt/index.js +113 -0
- package/dist/codegen/generators/typescript/channels/protocols/mqtt/publish.d.ts +3 -0
- package/dist/codegen/generators/typescript/channels/protocols/mqtt/publish.js +99 -0
- package/dist/codegen/generators/typescript/channels/protocols/mqtt/subscribe.d.ts +3 -0
- package/dist/codegen/generators/typescript/channels/protocols/mqtt/subscribe.js +186 -0
- package/dist/codegen/generators/typescript/channels/protocols/nats/corePublish.d.ts +3 -0
- package/dist/codegen/generators/typescript/channels/protocols/nats/corePublish.js +90 -0
- package/dist/codegen/generators/typescript/channels/protocols/nats/coreReply.d.ts +3 -0
- package/dist/codegen/generators/typescript/channels/protocols/nats/coreReply.js +142 -0
- package/dist/codegen/generators/typescript/channels/protocols/nats/coreRequest.d.ts +3 -0
- package/dist/codegen/generators/typescript/channels/protocols/nats/coreRequest.js +100 -0
- package/dist/codegen/generators/typescript/channels/protocols/nats/coreSubscribe.d.ts +3 -0
- package/dist/codegen/generators/typescript/channels/protocols/nats/coreSubscribe.js +143 -0
- package/dist/codegen/generators/typescript/channels/protocols/nats/index.d.ts +11 -0
- package/dist/codegen/generators/typescript/channels/protocols/nats/index.js +224 -0
- package/dist/codegen/generators/typescript/channels/protocols/nats/jetstreamPublish.d.ts +3 -0
- package/dist/codegen/generators/typescript/channels/protocols/nats/jetstreamPublish.js +89 -0
- package/dist/codegen/generators/typescript/channels/protocols/nats/jetstreamPullSubscribe.d.ts +3 -0
- package/dist/codegen/generators/typescript/channels/protocols/nats/jetstreamPullSubscribe.js +146 -0
- package/dist/codegen/generators/typescript/channels/protocols/nats/jetstreamPushSubscription.d.ts +3 -0
- package/dist/codegen/generators/typescript/channels/protocols/nats/jetstreamPushSubscription.js +149 -0
- package/dist/codegen/generators/typescript/channels/protocols/nats/utils.d.ts +35 -0
- package/dist/codegen/generators/typescript/channels/protocols/nats/utils.js +120 -0
- package/dist/codegen/generators/typescript/channels/protocols/websocket/index.d.ts +7 -0
- package/dist/codegen/generators/typescript/channels/protocols/websocket/index.js +152 -0
- package/dist/codegen/generators/typescript/channels/protocols/websocket/publish.d.ts +3 -0
- package/dist/codegen/generators/typescript/channels/protocols/websocket/publish.js +64 -0
- package/dist/codegen/generators/typescript/channels/protocols/websocket/register.d.ts +3 -0
- package/dist/codegen/generators/typescript/channels/protocols/websocket/register.js +115 -0
- package/dist/codegen/generators/typescript/channels/protocols/websocket/subscribe.d.ts +3 -0
- package/dist/codegen/generators/typescript/channels/protocols/websocket/subscribe.js +151 -0
- package/dist/codegen/generators/typescript/channels/types.d.ts +181 -0
- package/dist/codegen/generators/typescript/channels/types.js +131 -0
- package/dist/codegen/generators/typescript/channels/utils.d.ts +64 -0
- package/dist/codegen/generators/typescript/channels/utils.js +163 -0
- package/dist/codegen/generators/typescript/client/index.d.ts +8 -0
- package/dist/codegen/generators/typescript/client/index.js +61 -0
- package/dist/codegen/generators/typescript/client/protocols/nats/corePublish.d.ts +6 -0
- package/dist/codegen/generators/typescript/client/protocols/nats/corePublish.js +53 -0
- package/dist/codegen/generators/typescript/client/protocols/nats/coreSubscribe.d.ts +6 -0
- package/dist/codegen/generators/typescript/client/protocols/nats/coreSubscribe.js +90 -0
- package/dist/codegen/generators/typescript/client/protocols/nats/jetStreamPullSubscription.d.ts +6 -0
- package/dist/codegen/generators/typescript/client/protocols/nats/jetStreamPullSubscription.js +83 -0
- package/dist/codegen/generators/typescript/client/protocols/nats/jetstreamPublish.d.ts +6 -0
- package/dist/codegen/generators/typescript/client/protocols/nats/jetstreamPublish.js +54 -0
- package/dist/codegen/generators/typescript/client/protocols/nats/jetstreamPushSubscription.d.ts +6 -0
- package/dist/codegen/generators/typescript/client/protocols/nats/jetstreamPushSubscription.js +82 -0
- package/dist/codegen/generators/typescript/client/protocols/nats.d.ts +2 -0
- package/dist/codegen/generators/typescript/client/protocols/nats.js +182 -0
- package/dist/codegen/generators/typescript/client/types.d.ts +49 -0
- package/dist/codegen/generators/typescript/client/types.js +37 -0
- package/dist/codegen/generators/typescript/headers.d.ts +54 -0
- package/dist/codegen/generators/typescript/headers.js +138 -0
- package/dist/codegen/generators/typescript/index.d.ts +7 -0
- package/dist/codegen/generators/typescript/index.js +38 -0
- package/dist/codegen/generators/typescript/models.d.ts +21761 -0
- package/dist/codegen/generators/typescript/models.js +64 -0
- package/dist/codegen/generators/typescript/parameters.d.ts +37 -0
- package/dist/codegen/generators/typescript/parameters.js +101 -0
- package/dist/codegen/generators/typescript/payloads.d.ts +73 -0
- package/dist/codegen/generators/typescript/payloads.js +250 -0
- package/dist/codegen/generators/typescript/types.d.ts +34 -0
- package/dist/codegen/generators/typescript/types.js +70 -0
- package/dist/codegen/generators/typescript/utils.d.ts +38 -0
- package/dist/codegen/generators/typescript/utils.js +195 -0
- package/dist/codegen/index.d.ts +7 -0
- package/dist/codegen/index.js +38 -0
- package/dist/codegen/inputs/asyncapi/generators/headers.d.ts +3 -0
- package/dist/codegen/inputs/asyncapi/generators/headers.js +41 -0
- package/dist/codegen/inputs/asyncapi/generators/parameters.d.ts +14 -0
- package/dist/codegen/inputs/asyncapi/generators/parameters.js +120 -0
- package/dist/codegen/inputs/asyncapi/generators/payloads.d.ts +16 -0
- package/dist/codegen/inputs/asyncapi/generators/payloads.js +124 -0
- package/dist/codegen/inputs/asyncapi/generators/types.d.ts +9 -0
- package/dist/codegen/inputs/asyncapi/generators/types.js +61 -0
- package/dist/codegen/inputs/asyncapi/index.d.ts +1 -0
- package/dist/codegen/inputs/asyncapi/index.js +7 -0
- package/dist/codegen/inputs/asyncapi/parser.d.ts +4 -0
- package/dist/codegen/inputs/asyncapi/parser.js +90 -0
- package/dist/codegen/inputs/index.d.ts +3 -0
- package/dist/codegen/inputs/index.js +19 -0
- package/dist/codegen/inputs/jsonschema/generators/index.d.ts +1 -0
- package/dist/codegen/inputs/jsonschema/generators/index.js +5 -0
- package/dist/codegen/inputs/jsonschema/generators/models.d.ts +7 -0
- package/dist/codegen/inputs/jsonschema/generators/models.js +26 -0
- package/dist/codegen/inputs/jsonschema/index.d.ts +1 -0
- package/dist/codegen/inputs/jsonschema/index.js +7 -0
- package/dist/codegen/inputs/jsonschema/parser.d.ts +31 -0
- package/dist/codegen/inputs/jsonschema/parser.js +128 -0
- package/dist/codegen/inputs/openapi/generators/headers.d.ts +3 -0
- package/dist/codegen/inputs/openapi/generators/headers.js +101 -0
- package/dist/codegen/inputs/openapi/generators/parameters.d.ts +10 -0
- package/dist/codegen/inputs/openapi/generators/parameters.js +852 -0
- package/dist/codegen/inputs/openapi/generators/payloads.d.ts +3 -0
- package/dist/codegen/inputs/openapi/generators/payloads.js +231 -0
- package/dist/codegen/inputs/openapi/generators/types.d.ts +9 -0
- package/dist/codegen/inputs/openapi/generators/types.js +86 -0
- package/dist/codegen/inputs/openapi/index.d.ts +2 -0
- package/dist/codegen/inputs/openapi/index.js +8 -0
- package/dist/codegen/inputs/openapi/parser.d.ts +4 -0
- package/dist/codegen/inputs/openapi/parser.js +115 -0
- package/dist/codegen/inputs/openapi/security.d.ts +56 -0
- package/dist/codegen/inputs/openapi/security.js +193 -0
- package/dist/codegen/modelina/index.d.ts +2 -0
- package/dist/codegen/modelina/index.js +20 -0
- package/dist/codegen/modelina/presets/index.d.ts +3 -0
- package/dist/codegen/modelina/presets/index.js +14 -0
- package/dist/codegen/modelina/presets/primitives.d.ts +34 -0
- package/dist/codegen/modelina/presets/primitives.js +211 -0
- package/dist/codegen/modelina/presets/union.d.ts +33 -0
- package/dist/codegen/modelina/presets/union.js +197 -0
- package/dist/codegen/modelina/presets/validation.d.ts +66 -0
- package/dist/codegen/modelina/presets/validation.js +183 -0
- package/dist/codegen/modelina/types.d.ts +61845 -0
- package/dist/codegen/modelina/types.js +412 -0
- package/dist/codegen/output/filesystem.d.ts +30 -0
- package/dist/codegen/output/filesystem.js +61 -0
- package/dist/codegen/output/index.d.ts +16 -0
- package/dist/codegen/output/index.js +57 -0
- package/dist/codegen/output/memory.d.ts +54 -0
- package/dist/codegen/output/memory.js +81 -0
- package/dist/codegen/output/modelina.d.ts +30 -0
- package/dist/codegen/output/modelina.js +30 -0
- package/dist/codegen/output/types.d.ts +47 -0
- package/dist/codegen/output/types.js +6 -0
- package/dist/codegen/renderer.d.ts +13 -0
- package/dist/codegen/renderer.js +309 -0
- package/dist/codegen/schemaPostProcess.d.ts +25 -0
- package/dist/codegen/schemaPostProcess.js +38 -0
- package/dist/codegen/types.d.ts +285187 -0
- package/dist/codegen/types.js +177 -0
- package/dist/codegen/utils.d.ts +126 -0
- package/dist/codegen/utils.js +373 -0
- package/dist/commands/base.d.ts +18 -0
- package/dist/commands/base.js +59 -0
- package/dist/commands/generate.d.ts +46 -0
- package/dist/commands/generate.js +305 -0
- package/dist/commands/init.d.ts +55 -0
- package/dist/commands/init.js +544 -0
- package/dist/commands/telemetry.d.ts +25 -0
- package/dist/commands/telemetry.js +115 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.js +35 -0
- package/dist/telemetry/anonymize.d.ts +19 -0
- package/dist/telemetry/anonymize.js +73 -0
- package/dist/telemetry/collector.d.ts +26 -0
- package/dist/telemetry/collector.js +57 -0
- package/dist/telemetry/config.d.ts +32 -0
- package/dist/telemetry/config.js +97 -0
- package/dist/telemetry/events.d.ts +72 -0
- package/dist/telemetry/events.js +5 -0
- package/dist/telemetry/index.d.ts +46 -0
- package/dist/telemetry/index.js +91 -0
- package/dist/telemetry/notice.d.ts +8 -0
- package/dist/telemetry/notice.js +50 -0
- package/dist/telemetry/sender.d.ts +14 -0
- package/dist/telemetry/sender.js +125 -0
- package/dist/utils/gitignore.d.ts +66 -0
- package/dist/utils/gitignore.js +111 -0
- package/dist/utils/inputSource.d.ts +3 -0
- package/dist/utils/inputSource.js +26 -0
- package/dist/utils/refResolvers.d.ts +29 -0
- package/dist/utils/refResolvers.js +83 -0
- package/dist/utils/remoteFetch.d.ts +18 -0
- package/dist/utils/remoteFetch.js +64 -0
- package/oclif.manifest.json +510 -0
- package/package.json +155 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { TelemetryEvent } from './events';
|
|
2
|
+
import { ProjectTelemetryConfig } from '../codegen/types';
|
|
3
|
+
/**
|
|
4
|
+
* Send telemetry event to tracking endpoint.
|
|
5
|
+
*
|
|
6
|
+
* **CRITICAL**: This function is designed to NEVER throw or reject.
|
|
7
|
+
* All errors are handled internally and logged only in debug mode.
|
|
8
|
+
* It is safe to call without .catch() or try/catch.
|
|
9
|
+
*
|
|
10
|
+
* @param event - The telemetry event to send
|
|
11
|
+
* @param projectConfig - Optional project-level telemetry config
|
|
12
|
+
* @returns Promise that always resolves (never rejects)
|
|
13
|
+
*/
|
|
14
|
+
export declare function sendEvent(event: TelemetryEvent, projectConfig?: ProjectTelemetryConfig): Promise<void>;
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.sendEvent = void 0;
|
|
7
|
+
/* eslint-disable no-undef */
|
|
8
|
+
/* eslint-disable no-console */
|
|
9
|
+
const https_1 = __importDefault(require("https"));
|
|
10
|
+
const config_1 = require("./config");
|
|
11
|
+
const LoggingInterface_1 = require("../LoggingInterface");
|
|
12
|
+
/**
|
|
13
|
+
* Send telemetry event to tracking endpoint.
|
|
14
|
+
*
|
|
15
|
+
* **CRITICAL**: This function is designed to NEVER throw or reject.
|
|
16
|
+
* All errors are handled internally and logged only in debug mode.
|
|
17
|
+
* It is safe to call without .catch() or try/catch.
|
|
18
|
+
*
|
|
19
|
+
* @param event - The telemetry event to send
|
|
20
|
+
* @param projectConfig - Optional project-level telemetry config
|
|
21
|
+
* @returns Promise that always resolves (never rejects)
|
|
22
|
+
*/
|
|
23
|
+
async function sendEvent(event, projectConfig) {
|
|
24
|
+
try {
|
|
25
|
+
const config = await (0, config_1.getTelemetryConfig)(projectConfig);
|
|
26
|
+
// Don't send if telemetry is disabled
|
|
27
|
+
if (config.enabled === false) {
|
|
28
|
+
if (process.env.CODEGEN_TELEMETRY_DEBUG === '1') {
|
|
29
|
+
LoggingInterface_1.Logger.info(`[Telemetry Debug] Telemetry is disabled (${JSON.stringify(config)}), skipping send`);
|
|
30
|
+
}
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
// Don't send if required config is missing
|
|
34
|
+
if (!config.endpoint || !config.trackingId || !config.anonymousId) {
|
|
35
|
+
if (process.env.CODEGEN_TELEMETRY_DEBUG === '1') {
|
|
36
|
+
LoggingInterface_1.Logger.info(`[Telemetry Debug] Missing required config (${JSON.stringify(config)}), skipping send`);
|
|
37
|
+
}
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
// Build GA4 Measurement Protocol payload
|
|
41
|
+
const payload = {
|
|
42
|
+
client_id: config.anonymousId,
|
|
43
|
+
events: [
|
|
44
|
+
{
|
|
45
|
+
name: event.event,
|
|
46
|
+
params: {
|
|
47
|
+
...Object.fromEntries(Object.entries(event).filter(([key]) => key !== 'event')),
|
|
48
|
+
// Use provided engagement time or duration, fallback to 100ms minimum
|
|
49
|
+
engagement_time_msec: String(event.duration || 100)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
]
|
|
53
|
+
};
|
|
54
|
+
// Debug mode: log event without sending
|
|
55
|
+
if (process.env.CODEGEN_TELEMETRY_DEBUG === '1') {
|
|
56
|
+
LoggingInterface_1.Logger.info('[Telemetry Debug] Prepared event:', JSON.stringify(payload, null, 2));
|
|
57
|
+
}
|
|
58
|
+
// Build URL with query parameters
|
|
59
|
+
const url = new URL(config.endpoint);
|
|
60
|
+
url.searchParams.set('measurement_id', config.trackingId);
|
|
61
|
+
if (config.apiSecret) {
|
|
62
|
+
url.searchParams.set('api_secret', config.apiSecret);
|
|
63
|
+
}
|
|
64
|
+
// Send to endpoint
|
|
65
|
+
await sendHttpRequest({ url: url.toString(), payload });
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
// Catch any unexpected errors (config issues, JSON stringify errors, etc.)
|
|
69
|
+
if (process.env.CODEGEN_TELEMETRY_DEBUG === '1') {
|
|
70
|
+
LoggingInterface_1.Logger.error('[Telemetry Debug] Error:', error);
|
|
71
|
+
}
|
|
72
|
+
// Always resolve, never reject
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
exports.sendEvent = sendEvent;
|
|
76
|
+
/**
|
|
77
|
+
* Send HTTP POST request.
|
|
78
|
+
* This function never throws - all errors are handled internally.
|
|
79
|
+
*
|
|
80
|
+
* @param params - Request parameters
|
|
81
|
+
* @returns Promise that always resolves
|
|
82
|
+
*/
|
|
83
|
+
async function sendHttpRequest(params) {
|
|
84
|
+
const { url, payload } = params;
|
|
85
|
+
return new Promise((resolve) => {
|
|
86
|
+
try {
|
|
87
|
+
const data = JSON.stringify(payload);
|
|
88
|
+
const req = https_1.default.request(url, {
|
|
89
|
+
method: 'POST',
|
|
90
|
+
headers: {
|
|
91
|
+
'Content-Type': 'application/json',
|
|
92
|
+
'Content-Length': Buffer.byteLength(data)
|
|
93
|
+
},
|
|
94
|
+
timeout: 1000 // Fail fast
|
|
95
|
+
}, (res) => {
|
|
96
|
+
// Log success in debug mode
|
|
97
|
+
if (process.env.CODEGEN_TELEMETRY_DEBUG === '1') {
|
|
98
|
+
LoggingInterface_1.Logger.info(`[Telemetry Debug] Send succeeded with status: ${res.statusCode}`);
|
|
99
|
+
}
|
|
100
|
+
// Don't wait for response body, resolve immediately
|
|
101
|
+
resolve();
|
|
102
|
+
});
|
|
103
|
+
req.on('error', (err) => {
|
|
104
|
+
// Fail silently, don't break CLI
|
|
105
|
+
if (process.env.CODEGEN_TELEMETRY_DEBUG === '1') {
|
|
106
|
+
LoggingInterface_1.Logger.error(`[Telemetry Debug] Send failed: ${err.message}`);
|
|
107
|
+
}
|
|
108
|
+
resolve();
|
|
109
|
+
});
|
|
110
|
+
req.on('timeout', () => {
|
|
111
|
+
req.destroy();
|
|
112
|
+
resolve();
|
|
113
|
+
});
|
|
114
|
+
req.write(data);
|
|
115
|
+
req.end();
|
|
116
|
+
}
|
|
117
|
+
catch (error) {
|
|
118
|
+
// Catch any unexpected errors
|
|
119
|
+
if (process.env.CODEGEN_TELEMETRY_DEBUG === '1') {
|
|
120
|
+
LoggingInterface_1.Logger.error('[Telemetry Debug] Request error:', error);
|
|
121
|
+
}
|
|
122
|
+
resolve();
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
export interface GitignoreUpdateOptions {
|
|
2
|
+
/**
|
|
3
|
+
* The base directory where .gitignore is located (defaults to process.cwd())
|
|
4
|
+
*/
|
|
5
|
+
baseDirectory?: string;
|
|
6
|
+
/**
|
|
7
|
+
* Custom comment header to add before the gitignore entries
|
|
8
|
+
*/
|
|
9
|
+
commentHeader?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface GitignoreUpdateResult {
|
|
12
|
+
/**
|
|
13
|
+
* Whether the operation was successful
|
|
14
|
+
*/
|
|
15
|
+
success: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* The action that was performed
|
|
18
|
+
*/
|
|
19
|
+
action: 'created' | 'updated' | 'skipped' | 'error';
|
|
20
|
+
/**
|
|
21
|
+
* A message describing what happened
|
|
22
|
+
*/
|
|
23
|
+
message: string;
|
|
24
|
+
/**
|
|
25
|
+
* The paths that were added (if any)
|
|
26
|
+
*/
|
|
27
|
+
addedPaths?: string[];
|
|
28
|
+
/**
|
|
29
|
+
* Error details if the operation failed
|
|
30
|
+
*/
|
|
31
|
+
error?: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Updates or creates a .gitignore file with the specified output paths
|
|
35
|
+
*
|
|
36
|
+
* @param outputPaths - Array of paths to add to .gitignore
|
|
37
|
+
* @param options - Optional configuration for the gitignore update
|
|
38
|
+
* @returns Result object with operation details
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```typescript
|
|
42
|
+
* const result = await updateGitignore(['src/__gen__/payloads', 'src/__gen__/channels']);
|
|
43
|
+
* if (result.success) {
|
|
44
|
+
* console.log(result.message);
|
|
45
|
+
* }
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export declare function updateGitignore(outputPaths: string[], options?: GitignoreUpdateOptions): Promise<GitignoreUpdateResult>;
|
|
49
|
+
/**
|
|
50
|
+
* Collects output paths from generator flags
|
|
51
|
+
*
|
|
52
|
+
* @param generatorConfigs - Map of generator names to their configurations
|
|
53
|
+
* @returns Array of output paths
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* const paths = collectOutputPaths({
|
|
58
|
+
* payloads: { outputPath: 'src/__gen__/payloads' },
|
|
59
|
+
* channels: { outputPath: 'src/__gen__/channels' }
|
|
60
|
+
* });
|
|
61
|
+
* // Returns: ['src/__gen__/payloads', 'src/__gen__/channels']
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
export declare function collectOutputPaths(generatorConfigs: Record<string, {
|
|
65
|
+
outputPath: string;
|
|
66
|
+
} | undefined>): string[];
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.collectOutputPaths = exports.updateGitignore = void 0;
|
|
7
|
+
const promises_1 = require("node:fs/promises");
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
/**
|
|
10
|
+
* Updates or creates a .gitignore file with the specified output paths
|
|
11
|
+
*
|
|
12
|
+
* @param outputPaths - Array of paths to add to .gitignore
|
|
13
|
+
* @param options - Optional configuration for the gitignore update
|
|
14
|
+
* @returns Result object with operation details
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* const result = await updateGitignore(['src/__gen__/payloads', 'src/__gen__/channels']);
|
|
19
|
+
* if (result.success) {
|
|
20
|
+
* console.log(result.message);
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
async function updateGitignore(outputPaths, options = {}) {
|
|
25
|
+
// eslint-disable-next-line no-undef
|
|
26
|
+
const baseDirectory = options.baseDirectory || process.cwd();
|
|
27
|
+
const commentHeader = options.commentHeader || '# The Codegen Project - generated files';
|
|
28
|
+
const gitignorePath = path_1.default.join(baseDirectory, '.gitignore');
|
|
29
|
+
try {
|
|
30
|
+
// Check if .gitignore exists
|
|
31
|
+
await (0, promises_1.access)(gitignorePath);
|
|
32
|
+
// Read existing content
|
|
33
|
+
const existingContent = await (0, promises_1.readFile)(gitignorePath, 'utf-8');
|
|
34
|
+
// Filter out paths that already exist in .gitignore
|
|
35
|
+
const newPaths = outputPaths.filter((outputPath) => !existingContent.includes(outputPath));
|
|
36
|
+
if (newPaths.length === 0) {
|
|
37
|
+
return {
|
|
38
|
+
success: true,
|
|
39
|
+
action: 'skipped',
|
|
40
|
+
message: 'All output directories already present in .gitignore, skipping',
|
|
41
|
+
addedPaths: []
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
// Ensure file ends with newline before adding new entries
|
|
45
|
+
const separator = existingContent.endsWith('\n') ? '' : '\n';
|
|
46
|
+
const gitignoreEntry = `${separator}\n${commentHeader}\n${newPaths.join('\n')}\n`;
|
|
47
|
+
await (0, promises_1.appendFile)(gitignorePath, gitignoreEntry);
|
|
48
|
+
return {
|
|
49
|
+
success: true,
|
|
50
|
+
action: 'updated',
|
|
51
|
+
message: `Added ${newPaths.length} output director${newPaths.length === 1 ? 'y' : 'ies'} to .gitignore`,
|
|
52
|
+
addedPaths: newPaths
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
if (error.code === 'ENOENT') {
|
|
57
|
+
// .gitignore doesn't exist, try to create it
|
|
58
|
+
try {
|
|
59
|
+
const gitignoreContent = `${commentHeader}\n${outputPaths.join('\n')}\n`;
|
|
60
|
+
await (0, promises_1.writeFile)(gitignorePath, gitignoreContent);
|
|
61
|
+
return {
|
|
62
|
+
success: true,
|
|
63
|
+
action: 'created',
|
|
64
|
+
message: 'Created .gitignore with generated output directories',
|
|
65
|
+
addedPaths: outputPaths
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
catch (writeError) {
|
|
69
|
+
// Failed to create .gitignore (e.g., directory doesn't exist)
|
|
70
|
+
return {
|
|
71
|
+
success: false,
|
|
72
|
+
action: 'error',
|
|
73
|
+
message: `Could not create .gitignore: ${writeError.message}`,
|
|
74
|
+
error: writeError.message
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
success: false,
|
|
80
|
+
action: 'error',
|
|
81
|
+
message: `Could not update .gitignore: ${error.message}`,
|
|
82
|
+
error: error.message
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
exports.updateGitignore = updateGitignore;
|
|
87
|
+
/**
|
|
88
|
+
* Collects output paths from generator flags
|
|
89
|
+
*
|
|
90
|
+
* @param generatorConfigs - Map of generator names to their configurations
|
|
91
|
+
* @returns Array of output paths
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```typescript
|
|
95
|
+
* const paths = collectOutputPaths({
|
|
96
|
+
* payloads: { outputPath: 'src/__gen__/payloads' },
|
|
97
|
+
* channels: { outputPath: 'src/__gen__/channels' }
|
|
98
|
+
* });
|
|
99
|
+
* // Returns: ['src/__gen__/payloads', 'src/__gen__/channels']
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
function collectOutputPaths(generatorConfigs) {
|
|
103
|
+
const outputPaths = [];
|
|
104
|
+
for (const config of Object.values(generatorConfigs)) {
|
|
105
|
+
if (config?.outputPath) {
|
|
106
|
+
outputPaths.push(config.outputPath);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return outputPaths;
|
|
110
|
+
}
|
|
111
|
+
exports.collectOutputPaths = collectOutputPaths;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getInputSourceType = exports.isRemoteUrl = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Helpers for classifying an input path as a remote URL or a local
|
|
9
|
+
* filesystem path. Used at the configuration layer to decide whether to
|
|
10
|
+
* pass the path through `path.resolve` (local) or untouched (remote).
|
|
11
|
+
*/
|
|
12
|
+
const path_1 = __importDefault(require("path"));
|
|
13
|
+
function isRemoteUrl(inputPath) {
|
|
14
|
+
return inputPath.startsWith('http://') || inputPath.startsWith('https://');
|
|
15
|
+
}
|
|
16
|
+
exports.isRemoteUrl = isRemoteUrl;
|
|
17
|
+
function getInputSourceType(inputPath) {
|
|
18
|
+
if (isRemoteUrl(inputPath)) {
|
|
19
|
+
return 'remote_url';
|
|
20
|
+
}
|
|
21
|
+
if (path_1.default.isAbsolute(inputPath)) {
|
|
22
|
+
return 'local_absolute';
|
|
23
|
+
}
|
|
24
|
+
return 'local_relative';
|
|
25
|
+
}
|
|
26
|
+
exports.getInputSourceType = getInputSourceType;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { InputAuthConfig } from '../codegen/types';
|
|
2
|
+
export interface RefResolverContext {
|
|
3
|
+
/** The URL of the root input document — used to detect cross-host fetches. */
|
|
4
|
+
rootUrl: string;
|
|
5
|
+
}
|
|
6
|
+
interface OpenapiHttpResolver {
|
|
7
|
+
order: number;
|
|
8
|
+
canRead: (file: {
|
|
9
|
+
url: string;
|
|
10
|
+
}) => boolean;
|
|
11
|
+
read: (file: {
|
|
12
|
+
url: string;
|
|
13
|
+
}) => Promise<string>;
|
|
14
|
+
/**
|
|
15
|
+
* v14 of @apidevtools/json-schema-ref-parser blocks loopback / internal
|
|
16
|
+
* URLs (127.0.0.1, localhost, etc.) by default. We trust the user's
|
|
17
|
+
* inputPath, so disable the safe-url check.
|
|
18
|
+
*/
|
|
19
|
+
safeUrlResolver: false;
|
|
20
|
+
}
|
|
21
|
+
interface AsyncapiResolver {
|
|
22
|
+
schema: 'http' | 'https';
|
|
23
|
+
read: (uri: {
|
|
24
|
+
toString(): string;
|
|
25
|
+
}) => Promise<string>;
|
|
26
|
+
}
|
|
27
|
+
export declare function createOpenapiRefParserResolver(auth: InputAuthConfig | undefined, context: RefResolverContext): OpenapiHttpResolver;
|
|
28
|
+
export declare function createAsyncapiResolvers(auth: InputAuthConfig | undefined, context: RefResolverContext): AsyncapiResolver[];
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createAsyncapiResolvers = exports.createOpenapiRefParserResolver = void 0;
|
|
4
|
+
/* eslint-disable no-undef */
|
|
5
|
+
/**
|
|
6
|
+
* Custom http/https resolver factories for cross-spec `$ref`
|
|
7
|
+
* dereferencing. Both factories delegate to `fetchRemoteDocument` so the
|
|
8
|
+
* same auth headers are attached to every resolved reference.
|
|
9
|
+
*
|
|
10
|
+
* - `createOpenapiRefParserResolver` returns the `resolve.http` shape
|
|
11
|
+
* expected by `@apidevtools/json-schema-ref-parser`.
|
|
12
|
+
* - `createAsyncapiResolvers` returns the resolver array expected by
|
|
13
|
+
* `@asyncapi/parser`'s `__unstable.resolver` option (Spectral resolver
|
|
14
|
+
* shape, `read(uri): string | undefined | Promise<string | undefined>`).
|
|
15
|
+
*
|
|
16
|
+
* Both factories emit a debug log per fetched URL, and an info-level
|
|
17
|
+
* warning the first time auth headers are sent to a host that differs
|
|
18
|
+
* from the root document's host.
|
|
19
|
+
*/
|
|
20
|
+
const remoteFetch_1 = require("./remoteFetch");
|
|
21
|
+
const LoggingInterface_1 = require("../LoggingInterface");
|
|
22
|
+
function rootHost(rootUrl) {
|
|
23
|
+
try {
|
|
24
|
+
return new URL(rootUrl).host;
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function createCrossHostWarner(rootUrl, hasAuth) {
|
|
31
|
+
const root = rootHost(rootUrl);
|
|
32
|
+
const warnedHosts = new Set();
|
|
33
|
+
return (refUrl) => {
|
|
34
|
+
if (!hasAuth || !root) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
let refUrlHost;
|
|
38
|
+
try {
|
|
39
|
+
refUrlHost = new URL(refUrl).host;
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
if (!refUrlHost || refUrlHost === root) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (warnedHosts.has(refUrlHost)) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
warnedHosts.add(refUrlHost);
|
|
51
|
+
LoggingInterface_1.Logger.info(`[remote-fetch] auth headers sent to '${refUrlHost}' while resolving $ref from '${root}'. If this is unexpected, review the spec.`);
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function createOpenapiRefParserResolver(auth, context) {
|
|
55
|
+
const warn = createCrossHostWarner(context.rootUrl, Boolean(auth));
|
|
56
|
+
return {
|
|
57
|
+
order: 1,
|
|
58
|
+
safeUrlResolver: false,
|
|
59
|
+
canRead: (file) => file.url.startsWith('http://') || file.url.startsWith('https://'),
|
|
60
|
+
read: async (file) => {
|
|
61
|
+
LoggingInterface_1.Logger.debug(`[remote-fetch] $ref ${file.url}`);
|
|
62
|
+
warn(file.url);
|
|
63
|
+
const { content } = await (0, remoteFetch_1.fetchRemoteDocument)(file.url, auth);
|
|
64
|
+
return content;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
exports.createOpenapiRefParserResolver = createOpenapiRefParserResolver;
|
|
69
|
+
function createAsyncapiResolvers(auth, context) {
|
|
70
|
+
const warn = createCrossHostWarner(context.rootUrl, Boolean(auth));
|
|
71
|
+
const read = async (uri) => {
|
|
72
|
+
const url = uri.toString();
|
|
73
|
+
LoggingInterface_1.Logger.debug(`[remote-fetch] $ref ${url}`);
|
|
74
|
+
warn(url);
|
|
75
|
+
const { content } = await (0, remoteFetch_1.fetchRemoteDocument)(url, auth);
|
|
76
|
+
return content;
|
|
77
|
+
};
|
|
78
|
+
return [
|
|
79
|
+
{ schema: 'http', read },
|
|
80
|
+
{ schema: 'https', read }
|
|
81
|
+
];
|
|
82
|
+
}
|
|
83
|
+
exports.createAsyncapiResolvers = createAsyncapiResolvers;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fetches a remote document over http(s) with optional auth headers,
|
|
3
|
+
* a timeout, and typed errors. Used by every input parser when
|
|
4
|
+
* `inputPath` is a URL.
|
|
5
|
+
*
|
|
6
|
+
* SECURITY NOTE: When `auth` is configured, the headers are sent to
|
|
7
|
+
* **every** URL fetched through this helper, including external `$ref`
|
|
8
|
+
* targets on other hosts. See docs/configurations#auth-scope for details.
|
|
9
|
+
*/
|
|
10
|
+
import { InputAuthConfig } from '../codegen/types';
|
|
11
|
+
export interface FetchedDocument {
|
|
12
|
+
content: string;
|
|
13
|
+
contentType: string | null;
|
|
14
|
+
finalUrl: string;
|
|
15
|
+
}
|
|
16
|
+
export declare function fetchRemoteDocument(url: string, auth?: InputAuthConfig, options?: {
|
|
17
|
+
timeoutMs?: number;
|
|
18
|
+
}): Promise<FetchedDocument>;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fetchRemoteDocument = void 0;
|
|
4
|
+
const errors_1 = require("../codegen/errors");
|
|
5
|
+
const LoggingInterface_1 = require("../LoggingInterface");
|
|
6
|
+
const DEFAULT_TIMEOUT_MS = 30_000;
|
|
7
|
+
async function fetchRemoteDocument(url, auth, options = {}) {
|
|
8
|
+
LoggingInterface_1.Logger.debug(`[remote-fetch] GET ${url}`);
|
|
9
|
+
const controller = new AbortController();
|
|
10
|
+
const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
11
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
12
|
+
try {
|
|
13
|
+
const response = await fetch(url, {
|
|
14
|
+
method: 'GET',
|
|
15
|
+
headers: buildAuthHeaders(auth),
|
|
16
|
+
signal: controller.signal,
|
|
17
|
+
redirect: 'follow'
|
|
18
|
+
});
|
|
19
|
+
if (!response.ok) {
|
|
20
|
+
throw (0, errors_1.createRemoteFetchError)({
|
|
21
|
+
url,
|
|
22
|
+
status: response.status,
|
|
23
|
+
statusText: response.statusText,
|
|
24
|
+
reason: 'http'
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
const content = await response.text();
|
|
28
|
+
return {
|
|
29
|
+
content,
|
|
30
|
+
contentType: response.headers.get('content-type'),
|
|
31
|
+
finalUrl: response.url || url
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
catch (cause) {
|
|
35
|
+
if (cause instanceof errors_1.CodegenError) {
|
|
36
|
+
throw cause;
|
|
37
|
+
}
|
|
38
|
+
if (cause instanceof Error &&
|
|
39
|
+
(cause.name === 'AbortError' ||
|
|
40
|
+
cause.message?.toLowerCase().includes('aborted'))) {
|
|
41
|
+
throw (0, errors_1.createRemoteFetchError)({ url, reason: 'timeout', cause });
|
|
42
|
+
}
|
|
43
|
+
throw (0, errors_1.createRemoteFetchError)({ url, reason: 'network', cause });
|
|
44
|
+
}
|
|
45
|
+
finally {
|
|
46
|
+
clearTimeout(timer);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.fetchRemoteDocument = fetchRemoteDocument;
|
|
50
|
+
function buildAuthHeaders(auth) {
|
|
51
|
+
if (!auth) {
|
|
52
|
+
return {};
|
|
53
|
+
}
|
|
54
|
+
switch (auth.type) {
|
|
55
|
+
case 'bearer':
|
|
56
|
+
return { Authorization: `Bearer ${auth.token}` };
|
|
57
|
+
case 'apiKey':
|
|
58
|
+
return { [auth.header]: auth.value };
|
|
59
|
+
case 'custom':
|
|
60
|
+
return { ...auth.headers };
|
|
61
|
+
default:
|
|
62
|
+
return {};
|
|
63
|
+
}
|
|
64
|
+
}
|