@kubb/cli 5.0.0-beta.5 → 5.0.0-beta.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent-BJEvbSiP.js +68 -0
- package/dist/agent-BJEvbSiP.js.map +1 -0
- package/dist/agent-CXNO6dgj.cjs +70 -0
- package/dist/agent-CXNO6dgj.cjs.map +1 -0
- package/dist/{agent-CS45W0kL.cjs → agent-D9CKYh4K.cjs} +3 -3
- package/dist/{agent-CS45W0kL.cjs.map → agent-D9CKYh4K.cjs.map} +1 -1
- package/dist/{agent-IP0eLV3C.js → agent-VXKxLCho.js} +3 -3
- package/dist/{agent-IP0eLV3C.js.map → agent-VXKxLCho.js.map} +1 -1
- package/dist/constants-BPJBMT_6.js +45 -0
- package/dist/constants-BPJBMT_6.js.map +1 -0
- package/dist/constants-BYGmiFs0.cjs +139 -0
- package/dist/constants-BYGmiFs0.cjs.map +1 -0
- package/dist/constants-DSJ-Xrbv.js +116 -0
- package/dist/constants-DSJ-Xrbv.js.map +1 -0
- package/dist/constants-Rcaqzyd-.cjs +80 -0
- package/dist/constants-Rcaqzyd-.cjs.map +1 -0
- package/dist/define-Bdn8j5VM.cjs.map +1 -1
- package/dist/define-Ctii4bel.js.map +1 -1
- package/dist/errors-CLCjoSg0.cjs.map +1 -1
- package/dist/errors-CjPmyZHy.js.map +1 -1
- package/dist/{generate-7td_hs73.cjs → generate-BB2Q7I9s.cjs} +9 -3
- package/dist/{generate-7td_hs73.cjs.map → generate-BB2Q7I9s.cjs.map} +1 -1
- package/dist/{generate-CUd1dUY5.cjs → generate-B_p5dl68.cjs} +4 -4
- package/dist/{generate-CUd1dUY5.cjs.map → generate-B_p5dl68.cjs.map} +1 -1
- package/dist/{generate-BqeFFQGD.js → generate-BmulGxIM.js} +9 -3
- package/dist/{generate-BqeFFQGD.js.map → generate-BmulGxIM.js.map} +1 -1
- package/dist/{generate-DVmGtwWe.js → generate-DAsdUw3z.js} +4 -4
- package/dist/{generate-DVmGtwWe.js.map → generate-DAsdUw3z.js.map} +1 -1
- package/dist/index.cjs +19 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +19 -10
- package/dist/index.js.map +1 -1
- package/dist/init-BTp9if7K.js +53 -0
- package/dist/init-BTp9if7K.js.map +1 -0
- package/dist/{init-C5sZulT6.cjs → init-CJ80lKSP.cjs} +47 -101
- package/dist/init-CJ80lKSP.cjs.map +1 -0
- package/dist/{init-Cag3082g.js → init-DCqcEq86.js} +44 -98
- package/dist/init-DCqcEq86.js.map +1 -0
- package/dist/init-Dpg8e1HN.cjs +53 -0
- package/dist/init-Dpg8e1HN.cjs.map +1 -0
- package/dist/mcp-C9RoU-Dg.js +39 -0
- package/dist/mcp-C9RoU-Dg.js.map +1 -0
- package/dist/{mcp-BfORW-mY.cjs → mcp-D1llTaRM.cjs} +7 -4
- package/dist/mcp-D1llTaRM.cjs.map +1 -0
- package/dist/{mcp-DtQ5o0On.js → mcp-DNUw8nqb.js} +7 -4
- package/dist/mcp-DNUw8nqb.js.map +1 -0
- package/dist/mcp-wpl6sYYR.cjs +39 -0
- package/dist/mcp-wpl6sYYR.cjs.map +1 -0
- package/dist/{package-BmYRU2hz.cjs → package-iheSdfas.cjs} +2 -2
- package/dist/package-iheSdfas.cjs.map +1 -0
- package/dist/package-vLafMWCe.js +6 -0
- package/dist/package-vLafMWCe.js.map +1 -0
- package/dist/shell-475fQKaX.cjs.map +1 -1
- package/dist/shell-DLzN4fRo.js.map +1 -1
- package/dist/{telemetry-BU25EoI-.cjs → telemetry-BLX0NzRk.cjs} +2 -2
- package/dist/{telemetry-BU25EoI-.cjs.map → telemetry-BLX0NzRk.cjs.map} +1 -1
- package/dist/{telemetry-CaNU4-Bf.js → telemetry-juq4QBf7.js} +2 -2
- package/dist/{telemetry-CaNU4-Bf.js.map → telemetry-juq4QBf7.js.map} +1 -1
- package/dist/validate-BU4fPTMc.cjs +47 -0
- package/dist/validate-BU4fPTMc.cjs.map +1 -0
- package/dist/validate-BfJoCxrC.js +26 -0
- package/dist/validate-BfJoCxrC.js.map +1 -0
- package/dist/validate-DIDBROB2.cjs +26 -0
- package/dist/validate-DIDBROB2.cjs.map +1 -0
- package/dist/validate-k9s_hFah.js +46 -0
- package/dist/validate-k9s_hFah.js.map +1 -0
- package/package.json +11 -6
- package/src/commands/agent/start.ts +8 -5
- package/src/commands/agent.ts +3 -1
- package/src/commands/generate.ts +3 -1
- package/src/commands/init.ts +33 -2
- package/src/commands/mcp.ts +27 -3
- package/src/commands/validate.ts +4 -2
- package/src/constants.ts +1 -53
- package/src/runners/init.ts +29 -118
- package/src/runners/mcp.ts +7 -2
- package/src/runners/validate.ts +23 -4
- package/dist/agent-BcUEl9yB.js +0 -56
- package/dist/agent-BcUEl9yB.js.map +0 -1
- package/dist/agent-CsMvXeqI.cjs +0 -58
- package/dist/agent-CsMvXeqI.cjs.map +0 -1
- package/dist/constants-B4iBDvCe.cjs +0 -148
- package/dist/constants-B4iBDvCe.cjs.map +0 -1
- package/dist/constants-DmPrkaz8.js +0 -95
- package/dist/constants-DmPrkaz8.js.map +0 -1
- package/dist/init-C5sZulT6.cjs.map +0 -1
- package/dist/init-Cag3082g.js.map +0 -1
- package/dist/init-CfAn19gC.js +0 -25
- package/dist/init-CfAn19gC.js.map +0 -1
- package/dist/init-CfsYoyGe.cjs +0 -25
- package/dist/init-CfsYoyGe.cjs.map +0 -1
- package/dist/mcp-BfORW-mY.cjs.map +0 -1
- package/dist/mcp-BtOV6acy.js +0 -16
- package/dist/mcp-BtOV6acy.js.map +0 -1
- package/dist/mcp-CIbuLGMx.cjs +0 -16
- package/dist/mcp-CIbuLGMx.cjs.map +0 -1
- package/dist/mcp-DtQ5o0On.js.map +0 -1
- package/dist/package-BmYRU2hz.cjs.map +0 -1
- package/dist/package-DBU5ii-k.js +0 -6
- package/dist/package-DBU5ii-k.js.map +0 -1
- package/dist/validate-CQqM9siF.js +0 -25
- package/dist/validate-CQqM9siF.js.map +0 -1
- package/dist/validate-DBXLaLIn.cjs +0 -34
- package/dist/validate-DBXLaLIn.cjs.map +0 -1
- package/dist/validate-DI23zgmL.js +0 -33
- package/dist/validate-DI23zgmL.js.map +0 -1
- package/dist/validate-DwX4LzYq.cjs +0 -25
- package/dist/validate-DwX4LzYq.cjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"telemetry-BU25EoI-.cjs","names":["dnsPromises","process","OTLP_ENDPOINT","os"],"sources":["../../../internals/utils/src/env.ts","../../../internals/utils/src/network.ts","../src/utils/telemetry.ts"],"sourcesContent":["/**\n * Returns `true` when running inside a GitHub Actions workflow.\n *\n * @example\n * ```ts\n * if (isGitHubActions()) {\n * core.setOutput('result', 'ok')\n * }\n * ```\n */\nexport function isGitHubActions(): boolean {\n return !!process.env.GITHUB_ACTIONS\n}\n\n/**\n * Returns `true` when the process is running in a CI environment.\n * Covers GitHub Actions, GitLab CI, CircleCI, Travis CI, Jenkins, Bitbucket,\n * TeamCity, Buildkite, and Azure Pipelines.\n *\n * @example\n * ```ts\n * if (isCIEnvironment()) {\n * logger.level = 'error'\n * }\n * ```\n */\nexport function isCIEnvironment(): boolean {\n return !!(\n process.env.CI ||\n process.env.GITHUB_ACTIONS ||\n process.env.GITLAB_CI ||\n process.env.BITBUCKET_BUILD_NUMBER ||\n process.env.JENKINS_URL ||\n process.env.CIRCLECI ||\n process.env.TRAVIS ||\n process.env.TEAMCITY_VERSION ||\n process.env.BUILDKITE ||\n process.env.TF_BUILD\n )\n}\n\n/**\n * Returns `true` when the process has an interactive TTY with a valid terminal\n * width and is not running in CI.\n *\n * Some IDE-embedded terminals report `isTTY = true` but set `columns` to `0`,\n * which breaks clack's box-drawing helpers (they call `String.prototype.repeat`\n * with a negative count and throw a `RangeError`). We therefore require a\n * positive column count before declaring the TTY usable.\n *\n * @example\n * ```ts\n * if (canUseTTY()) {\n * renderProgressBar()\n * }\n * ```\n */\nexport function canUseTTY(): boolean {\n return !!process.stdout.isTTY && (process.stdout.columns ?? 0) > 0 && !isCIEnvironment()\n}\n","import { promises as dnsPromises } from 'node:dns'\n\n/**\n * Well-known stable domains used as DNS probes to check internet connectivity.\n */\nconst TEST_DOMAINS = ['dns.google.com', 'cloudflare.com', 'one.one.one.one'] as const\n\n/**\n * Returns `true` when the system has internet connectivity.\n * Probes DNS resolution against well-known stable domains.\n *\n * @example\n * ```ts\n * if (await isOnline()) {\n * await fetchLatestVersion()\n * }\n * ```\n */\nexport async function isOnline(): Promise<boolean> {\n for (const domain of TEST_DOMAINS) {\n try {\n await dnsPromises.resolve(domain)\n return true\n } catch {\n // Try next domain\n }\n }\n\n return false\n}\n\n/**\n * Executes `fn` only when the system is online. Returns `null` when offline or on error.\n *\n * @example\n * ```ts\n * const version = await executeIfOnline(() => fetchLatestVersion('kubb'))\n * // null when offline\n * ```\n */\nexport async function executeIfOnline<T>(fn: () => Promise<T>): Promise<T | null> {\n if (!(await isOnline())) return null\n\n try {\n return await fn()\n } catch {\n return null\n }\n}\n","import { randomBytes } from 'node:crypto'\nimport os from 'node:os'\nimport process from 'node:process'\nimport { executeIfOnline, isCIEnvironment } from '@internals/utils'\nimport { OTLP_ENDPOINT } from '../constants.ts'\n\n// OpenTelemetry OTLP JSON types\n// https://github.com/open-telemetry/opentelemetry-proto/blob/main/opentelemetry/proto/trace/v1/trace.proto\n// https://github.com/open-telemetry/opentelemetry-proto/blob/main/opentelemetry/proto/common/v1/common.proto\n\ntype OtlpStringValue = { stringValue: string }\ntype OtlpBoolValue = { boolValue: boolean }\ntype OtlpIntValue = { intValue: number }\ntype OtlpDoubleValue = { doubleValue: number }\ntype OtlpBytesValue = { bytesValue: string }\ntype OtlpArrayValue = { arrayValue: { values: OtlpAnyValue[] } }\ntype OtlpKvListValue = { kvlistValue: { values: OtlpKeyValue[] } }\n\ntype OtlpAnyValue = OtlpStringValue | OtlpBoolValue | OtlpIntValue | OtlpDoubleValue | OtlpBytesValue | OtlpArrayValue | OtlpKvListValue\n\ntype OtlpKeyValue = {\n key: string\n value: OtlpAnyValue\n}\n\ntype OtlpResource = {\n attributes: OtlpKeyValue[]\n droppedAttributesCount?: number\n}\n\ntype OtlpInstrumentationScope = {\n name: string\n version?: string\n attributes?: OtlpKeyValue[]\n droppedAttributesCount?: number\n}\n\n/** https://github.com/open-telemetry/opentelemetry-proto/blob/main/opentelemetry/proto/trace/v1/trace.proto#L103 */\ntype OtlpSpanKind = 0 | 1 | 2 | 3 | 4 | 5\n\n/** 0 = STATUS_CODE_UNSET, 1 = STATUS_CODE_OK, 2 = STATUS_CODE_ERROR */\ntype OtlpStatusCode = 0 | 1 | 2\n\ntype OtlpStatus = {\n code: OtlpStatusCode\n message?: string\n}\n\ntype OtlpSpan = {\n traceId: string\n spanId: string\n traceState?: string\n parentSpanId?: string\n name: string\n kind: OtlpSpanKind\n startTimeUnixNano: string\n endTimeUnixNano: string\n attributes?: OtlpKeyValue[]\n droppedAttributesCount?: number\n events?: OtlpSpanEvent[]\n droppedEventsCount?: number\n links?: OtlpSpanLink[]\n droppedLinksCount?: number\n status?: OtlpStatus\n}\n\ntype OtlpSpanEvent = {\n timeUnixNano: string\n name: string\n attributes?: OtlpKeyValue[]\n droppedAttributesCount?: number\n}\n\ntype OtlpSpanLink = {\n traceId: string\n spanId: string\n traceState?: string\n attributes?: OtlpKeyValue[]\n droppedAttributesCount?: number\n}\n\ntype OtlpScopeSpans = {\n scope: OtlpInstrumentationScope\n spans: OtlpSpan[]\n schemaUrl?: string\n}\n\ntype OtlpResourceSpans = {\n resource: OtlpResource\n scopeSpans: OtlpScopeSpans[]\n schemaUrl?: string\n}\n\n/** Root payload sent to POST /v1/traces */\ntype OtlpExportTraceServiceRequest = {\n resourceSpans: OtlpResourceSpans[]\n}\n\nexport type TelemetryPlugin = {\n name: string\n options: Record<string, unknown>\n}\n\ntype TelemetryEvent = {\n command: string\n kubbVersion: string\n nodeVersion: string\n platform: string\n ci: boolean\n plugins: TelemetryPlugin[]\n duration: number\n filesCreated: number\n status: 'success' | 'failed'\n}\n\n/**\n * Detect whether the current process is running inside a CI environment.\n * Delegates to the canonical isCIEnvironment() from envDetection.\n */\nexport function isCi(): boolean {\n return isCIEnvironment()\n}\n\n/**\n * Check if telemetry is disabled via DO_NOT_TRACK or KUBB_DISABLE_TELEMETRY.\n * Respects the standard DO_NOT_TRACK convention used across development tools.\n */\nexport function isTelemetryDisabled(): boolean {\n return (\n process.env['DO_NOT_TRACK'] === '1' ||\n process.env['DO_NOT_TRACK'] === 'true' ||\n process.env['KUBB_DISABLE_TELEMETRY'] === '1' ||\n process.env['KUBB_DISABLE_TELEMETRY'] === 'true'\n )\n}\n\n/**\n * Convert a TelemetryEvent into an OTLP-compatible JSON trace payload.\n * See https://opentelemetry.io/docs/languages/sdk-configuration/otlp-exporter/\n */\nexport function buildOtlpPayload(event: TelemetryEvent): OtlpExportTraceServiceRequest {\n const traceId = randomBytes(16).toString('hex')\n const spanId = randomBytes(8).toString('hex')\n const endTimeNs = BigInt(Date.now()) * 1_000_000n\n const startTimeNs = endTimeNs - BigInt(event.duration) * 1_000_000n\n\n const attributes: OtlpKeyValue[] = [\n { key: 'kubb.command', value: { stringValue: event.command } },\n { key: 'kubb.version', value: { stringValue: event.kubbVersion } },\n { key: 'kubb.node_version', value: { stringValue: event.nodeVersion } },\n { key: 'kubb.platform', value: { stringValue: event.platform } },\n { key: 'kubb.ci', value: { boolValue: event.ci } },\n { key: 'kubb.files_created', value: { intValue: event.filesCreated } },\n { key: 'kubb.status', value: { stringValue: event.status } },\n {\n key: 'kubb.plugins',\n value: {\n arrayValue: {\n values: event.plugins.map(\n (p): OtlpKvListValue => ({\n kvlistValue: {\n values: [\n { key: 'name', value: { stringValue: p.name } },\n {\n key: 'options',\n value: {\n stringValue: JSON.stringify({\n ...p.options,\n usedEnumNames: undefined,\n }),\n },\n },\n ],\n },\n }),\n ),\n },\n },\n },\n ]\n\n return {\n resourceSpans: [\n {\n resource: {\n attributes: [\n { key: 'service.name', value: { stringValue: 'kubb-cli' } },\n {\n key: 'service.version',\n value: { stringValue: event.kubbVersion },\n },\n { key: 'telemetry.sdk.language', value: { stringValue: 'nodejs' } },\n ],\n },\n scopeSpans: [\n {\n scope: { name: 'kubb-cli', version: event.kubbVersion },\n spans: [\n {\n traceId,\n spanId,\n name: event.command,\n kind: 1 satisfies OtlpSpanKind,\n startTimeUnixNano: String(startTimeNs),\n endTimeUnixNano: String(endTimeNs),\n attributes,\n status: {\n code: (event.status === 'success' ? 1 : 2) satisfies OtlpStatusCode,\n },\n },\n ],\n },\n ],\n },\n ],\n }\n}\n\n/**\n * Send an anonymous telemetry event to the Kubb OTLP endpoint.\n * Respects DO_NOT_TRACK and KUBB_DISABLE_TELEMETRY environment variables.\n * Fails silently to never interrupt the generation process.\n */\nexport async function sendTelemetry(event: TelemetryEvent): Promise<void> {\n if (isTelemetryDisabled()) {\n return\n }\n\n await executeIfOnline(async () => {\n try {\n await fetch(`${OTLP_ENDPOINT}/v1/traces`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'Kubb-Telemetry-Version': '1',\n 'Kubb-Telemetry-Source': 'kubb-cli',\n },\n body: JSON.stringify(buildOtlpPayload(event)),\n signal: AbortSignal.timeout(5_000),\n })\n } catch (_e) {\n // Fail silently – telemetry must never break the CLI\n }\n })\n}\n\n/**\n * Build an anonymous telemetry payload from a completed generation run.\n * No file paths, OpenAPI specs, or secrets are included.\n */\nexport function buildTelemetryEvent(options: {\n command: 'generate' | 'mcp' | 'validate' | 'agent'\n kubbVersion: string\n plugins?: TelemetryPlugin[]\n hrStart: [number, number]\n filesCreated?: number\n status: 'success' | 'failed'\n}): TelemetryEvent {\n const [seconds, nanoseconds] = process.hrtime(options.hrStart)\n const duration = Math.round(seconds * 1000 + nanoseconds / 1e6)\n\n return {\n command: options.command,\n kubbVersion: options.kubbVersion,\n nodeVersion: process.versions.node.split('.')[0] as string,\n platform: os.platform(),\n ci: isCi(),\n plugins: options.plugins ?? [],\n duration,\n filesCreated: options.filesC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iB,OAAO,UAAU;IAClC;IACA,QAAQ,EACN,MAAO,MAAM,WAAW,YAAY,IAAI,GACzC;IACF,CACF;GACF,CACF;EACF,CACF,EACF;;;;;;;AAQH,eAAsB,cAAc,OAAsC;AACxE,KAAI,qBAAqB,CACvB;AAGF,OAAM,gBAAgB,YAAY;AAChC,MAAI;AACF,SAAM,MAAM,GAAGC,kBAAAA,cAAc,aAAa;IACxC,QAAQ;IACR,SAAS;KACP,gBAAgB;KAChB,0BAA0B;KAC1B,yBAAyB;KAC1B;IACD,MAAM,KAAK,UAAU,iBAAiB,MAAM,CAAC;IAC7C,QAAQ,YAAY,QAAQ,IAAM;IACnC,CAAC;WACK,IAAI;GAGb;;;;;;AAOJ,SAAgB,oBAAoB,SAOjB;CACjB,MAAM,CAAC,SAAS,eAAeD,aAAAA,QAAQ,OAAO,QAAQ,QAAQ;CAC9D,MAAM,WAAW,KAAK,MAAM,UAAU,MAAO,cAAc,IAAI;AAE/D,QAAO;EACL,SAAS,QAAQ;EACjB,aAAa,QAAQ;EACrB,aAAaA,aAAAA,QAAQ,SAAS,KAAK,MAAM,IAAI,CAAC;EAC9C,UAAUE,QAAAA,QAAG,UAAU;EACvB,IAAI,MAAM;EACV,SAAS,QAAQ,WAAW,EAAE;EAC9B;EACA,cAAc,QAAQ,gBAAgB;EACtC,QAAQ,QAAQ;EACjB"}
|
|
1
|
+
{"version":3,"file":"telemetry-BLX0NzRk.cjs","names":["dnsPromises","process","OTLP_ENDPOINT","os"],"sources":["../../../internals/utils/src/env.ts","../../../internals/utils/src/network.ts","../src/utils/telemetry.ts"],"sourcesContent":["/**\n * Returns `true` when running inside a GitHub Actions workflow.\n *\n * @example\n * ```ts\n * if (isGitHubActions()) {\n * core.setOutput('result', 'ok')\n * }\n * ```\n */\nexport function isGitHubActions(): boolean {\n return !!process.env.GITHUB_ACTIONS\n}\n\n/**\n * Returns `true` when the process is running in a CI environment.\n * Covers GitHub Actions, GitLab CI, CircleCI, Travis CI, Jenkins, Bitbucket,\n * TeamCity, Buildkite, and Azure Pipelines.\n *\n * @example\n * ```ts\n * if (isCIEnvironment()) {\n * logger.level = 'error'\n * }\n * ```\n */\nexport function isCIEnvironment(): boolean {\n return !!(\n process.env.CI ||\n process.env.GITHUB_ACTIONS ||\n process.env.GITLAB_CI ||\n process.env.BITBUCKET_BUILD_NUMBER ||\n process.env.JENKINS_URL ||\n process.env.CIRCLECI ||\n process.env.TRAVIS ||\n process.env.TEAMCITY_VERSION ||\n process.env.BUILDKITE ||\n process.env.TF_BUILD\n )\n}\n\n/**\n * Returns `true` when the process has an interactive TTY with a valid terminal\n * width and is not running in CI.\n *\n * Some IDE-embedded terminals report `isTTY = true` but set `columns` to `0`,\n * which breaks clack's box-drawing helpers (they call `String.prototype.repeat`\n * with a negative count and throw a `RangeError`). We therefore require a\n * positive column count before declaring the TTY usable.\n *\n * @example\n * ```ts\n * if (canUseTTY()) {\n * renderProgressBar()\n * }\n * ```\n */\nexport function canUseTTY(): boolean {\n return !!process.stdout.isTTY && (process.stdout.columns ?? 0) > 0 && !isCIEnvironment()\n}\n","import { promises as dnsPromises } from 'node:dns'\n\n/**\n * Well-known stable domains used as DNS probes to check internet connectivity.\n */\nconst TEST_DOMAINS = ['dns.google.com', 'cloudflare.com', 'one.one.one.one'] as const\n\n/**\n * Returns `true` when the system has internet connectivity.\n * Probes DNS resolution against well-known stable domains.\n *\n * @example\n * ```ts\n * if (await isOnline()) {\n * await fetchLatestVersion()\n * }\n * ```\n */\nexport async function isOnline(): Promise<boolean> {\n for (const domain of TEST_DOMAINS) {\n try {\n await dnsPromises.resolve(domain)\n return true\n } catch {\n // Try next domain\n }\n }\n\n return false\n}\n\n/**\n * Executes `fn` only when the system is online. Returns `null` when offline or on error.\n *\n * @example\n * ```ts\n * const version = await executeIfOnline(() => fetchLatestVersion('kubb'))\n * // null when offline\n * ```\n */\nexport async function executeIfOnline<T>(fn: () => Promise<T>): Promise<T | null> {\n if (!(await isOnline())) return null\n\n try {\n return await fn()\n } catch {\n return null\n }\n}\n","import { randomBytes } from 'node:crypto'\nimport os from 'node:os'\nimport process from 'node:process'\nimport { executeIfOnline, isCIEnvironment } from '@internals/utils'\nimport { OTLP_ENDPOINT } from '../constants.ts'\n\n// OpenTelemetry OTLP JSON types\n// https://github.com/open-telemetry/opentelemetry-proto/blob/main/opentelemetry/proto/trace/v1/trace.proto\n// https://github.com/open-telemetry/opentelemetry-proto/blob/main/opentelemetry/proto/common/v1/common.proto\n\ntype OtlpStringValue = { stringValue: string }\ntype OtlpBoolValue = { boolValue: boolean }\ntype OtlpIntValue = { intValue: number }\ntype OtlpDoubleValue = { doubleValue: number }\ntype OtlpBytesValue = { bytesValue: string }\ntype OtlpArrayValue = { arrayValue: { values: OtlpAnyValue[] } }\ntype OtlpKvListValue = { kvlistValue: { values: OtlpKeyValue[] } }\n\ntype OtlpAnyValue = OtlpStringValue | OtlpBoolValue | OtlpIntValue | OtlpDoubleValue | OtlpBytesValue | OtlpArrayValue | OtlpKvListValue\n\ntype OtlpKeyValue = {\n key: string\n value: OtlpAnyValue\n}\n\ntype OtlpResource = {\n attributes: OtlpKeyValue[]\n droppedAttributesCount?: number\n}\n\ntype OtlpInstrumentationScope = {\n name: string\n version?: string\n attributes?: OtlpKeyValue[]\n droppedAttributesCount?: number\n}\n\n/** https://github.com/open-telemetry/opentelemetry-proto/blob/main/opentelemetry/proto/trace/v1/trace.proto#L103 */\ntype OtlpSpanKind = 0 | 1 | 2 | 3 | 4 | 5\n\n/** 0 = STATUS_CODE_UNSET, 1 = STATUS_CODE_OK, 2 = STATUS_CODE_ERROR */\ntype OtlpStatusCode = 0 | 1 | 2\n\ntype OtlpStatus = {\n code: OtlpStatusCode\n message?: string\n}\n\ntype OtlpSpan = {\n traceId: string\n spanId: string\n traceState?: string\n parentSpanId?: string\n name: string\n kind: OtlpSpanKind\n startTimeUnixNano: string\n endTimeUnixNano: string\n attributes?: OtlpKeyValue[]\n droppedAttributesCount?: number\n events?: OtlpSpanEvent[]\n droppedEventsCount?: number\n links?: OtlpSpanLink[]\n droppedLinksCount?: number\n status?: OtlpStatus\n}\n\ntype OtlpSpanEvent = {\n timeUnixNano: string\n name: string\n attributes?: OtlpKeyValue[]\n droppedAttributesCount?: number\n}\n\ntype OtlpSpanLink = {\n traceId: string\n spanId: string\n traceState?: string\n attributes?: OtlpKeyValue[]\n droppedAttributesCount?: number\n}\n\ntype OtlpScopeSpans = {\n scope: OtlpInstrumentationScope\n spans: OtlpSpan[]\n schemaUrl?: string\n}\n\ntype OtlpResourceSpans = {\n resource: OtlpResource\n scopeSpans: OtlpScopeSpans[]\n schemaUrl?: string\n}\n\n/** Root payload sent to POST /v1/traces */\ntype OtlpExportTraceServiceRequest = {\n resourceSpans: OtlpResourceSpans[]\n}\n\nexport type TelemetryPlugin = {\n name: string\n options: Record<string, unknown>\n}\n\ntype TelemetryEvent = {\n command: string\n kubbVersion: string\n nodeVersion: string\n platform: string\n ci: boolean\n plugins: TelemetryPlugin[]\n duration: number\n filesCreated: number\n status: 'success' | 'failed'\n}\n\n/**\n * Detect whether the current process is running inside a CI environment.\n * Delegates to the canonical isCIEnvironment() from envDetection.\n */\nexport function isCi(): boolean {\n return isCIEnvironment()\n}\n\n/**\n * Check if telemetry is disabled via DO_NOT_TRACK or KUBB_DISABLE_TELEMETRY.\n * Respects the standard DO_NOT_TRACK convention used across development tools.\n */\nexport function isTelemetryDisabled(): boolean {\n return (\n process.env['DO_NOT_TRACK'] === '1' ||\n process.env['DO_NOT_TRACK'] === 'true' ||\n process.env['KUBB_DISABLE_TELEMETRY'] === '1' ||\n process.env['KUBB_DISABLE_TELEMETRY'] === 'true'\n )\n}\n\n/**\n * Convert a TelemetryEvent into an OTLP-compatible JSON trace payload.\n * See https://opentelemetry.io/docs/languages/sdk-configuration/otlp-exporter/\n */\nexport function buildOtlpPayload(event: TelemetryEvent): OtlpExportTraceServiceRequest {\n const traceId = randomBytes(16).toString('hex')\n const spanId = randomBytes(8).toString('hex')\n const endTimeNs = BigInt(Date.now()) * 1_000_000n\n const startTimeNs = endTimeNs - BigInt(event.duration) * 1_000_000n\n\n const attributes: OtlpKeyValue[] = [\n { key: 'kubb.command', value: { stringValue: event.command } },\n { key: 'kubb.version', value: { stringValue: event.kubbVersion } },\n { key: 'kubb.node_version', value: { stringValue: event.nodeVersion } },\n { key: 'kubb.platform', value: { stringValue: event.platform } },\n { key: 'kubb.ci', value: { boolValue: event.ci } },\n { key: 'kubb.files_created', value: { intValue: event.filesCreated } },\n { key: 'kubb.status', value: { stringValue: event.status } },\n {\n key: 'kubb.plugins',\n value: {\n arrayValue: {\n values: event.plugins.map(\n (p): OtlpKvListValue => ({\n kvlistValue: {\n values: [\n { key: 'name', value: { stringValue: p.name } },\n {\n key: 'options',\n value: {\n stringValue: JSON.stringify({\n ...p.options,\n usedEnumNames: undefined,\n }),\n },\n },\n ],\n },\n }),\n ),\n },\n },\n },\n ]\n\n return {\n resourceSpans: [\n {\n resource: {\n attributes: [\n { key: 'service.name', value: { stringValue: 'kubb-cli' } },\n {\n key: 'service.version',\n value: { stringValue: event.kubbVersion },\n },\n { key: 'telemetry.sdk.language', value: { stringValue: 'nodejs' } },\n ],\n },\n scopeSpans: [\n {\n scope: { name: 'kubb-cli', version: event.kubbVersion },\n spans: [\n {\n traceId,\n spanId,\n name: event.command,\n kind: 1 satisfies OtlpSpanKind,\n startTimeUnixNano: String(startTimeNs),\n endTimeUnixNano: String(endTimeNs),\n attributes,\n status: {\n code: (event.status === 'success' ? 1 : 2) satisfies OtlpStatusCode,\n },\n },\n ],\n },\n ],\n },\n ],\n }\n}\n\n/**\n * Send an anonymous telemetry event to the Kubb OTLP endpoint.\n * Respects DO_NOT_TRACK and KUBB_DISABLE_TELEMETRY environment variables.\n * Fails silently to never interrupt the generation process.\n */\nexport async function sendTelemetry(event: TelemetryEvent): Promise<void> {\n if (isTelemetryDisabled()) {\n return\n }\n\n await executeIfOnline(async () => {\n try {\n await fetch(`${OTLP_ENDPOINT}/v1/traces`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'Kubb-Telemetry-Version': '1',\n 'Kubb-Telemetry-Source': 'kubb-cli',\n },\n body: JSON.stringify(buildOtlpPayload(event)),\n signal: AbortSignal.timeout(5_000),\n })\n } catch (_e) {\n // Fail silently – telemetry must never break the CLI\n }\n })\n}\n\n/**\n * Build an anonymous telemetry payload from a completed generation run.\n * No file paths, OpenAPI specs, or secrets are included.\n */\nexport function buildTelemetryEvent(options: {\n command: 'generate' | 'mcp' | 'validate' | 'agent'\n kubbVersion: string\n plugins?: TelemetryPlugin[]\n hrStart: [number, number]\n filesCreated?: number\n status: 'success' | 'failed'\n}): TelemetryEvent {\n const [seconds, nanoseconds] = process.hrtime(options.hrStart)\n const duration = Math.round(seconds * 1000 + nanoseconds / 1e6)\n\n return {\n command: options.command,\n kubbVersion: options.kubbVersion,\n nodeVersion: process.versions.node.split('.')[0] as string,\n platform: os.platform(),\n ci: isCi(),\n plugins: options.plugins ?? [],\n duration,\n filesCreated: options.filesCreated ?? 0,\n status: options.status,\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAUA,SAAgB,kBAA2B;CACzC,OAAO,CAAC,CAAC,QAAQ,IAAI;;;;;;;;;;;;;;AAevB,SAAgB,kBAA2B;CACzC,OAAO,CAAC,EACN,QAAQ,IAAI,MACZ,QAAQ,IAAI,kBACZ,QAAQ,IAAI,aACZ,QAAQ,IAAI,0BACZ,QAAQ,IAAI,eACZ,QAAQ,IAAI,YACZ,QAAQ,IAAI,UACZ,QAAQ,IAAI,oBACZ,QAAQ,IAAI,aACZ,QAAQ,IAAI;;;;;;;;;;;;;;;;;;AAoBhB,SAAgB,YAAqB;CACnC,OAAO,CAAC,CAAC,QAAQ,OAAO,UAAU,QAAQ,OAAO,WAAW,KAAK,KAAK,CAAC,iBAAiB;;;;;;;ACrD1F,MAAM,eAAe;CAAC;CAAkB;CAAkB;CAAkB;;;;;;;;;;;;AAa5E,eAAsB,WAA6B;CACjD,KAAK,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ACL,SAAS,QAAQ;EACjB,aAAa,QAAQ;EACrB,aAAaA,aAAAA,QAAQ,SAAS,KAAK,MAAM,IAAI,CAAC;EAC9C,UAAUE,QAAAA,QAAG,UAAU;EACvB,IAAI,MAAM;EACV,SAAS,QAAQ,WAAW,EAAE;EAC9B;EACA,cAAc,QAAQ,gBAAgB;EACtC,QAAQ,QAAQ;EACjB"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "./chunk--u3MIqq1.js";
|
|
2
|
-
import {
|
|
2
|
+
import { n as OTLP_ENDPOINT } from "./constants-BPJBMT_6.js";
|
|
3
3
|
import { randomBytes } from "node:crypto";
|
|
4
4
|
import { promises } from "node:dns";
|
|
5
5
|
import os from "node:os";
|
|
@@ -242,4 +242,4 @@ function buildTelemetryEvent(options) {
|
|
|
242
242
|
//#endregion
|
|
243
243
|
export { canUseTTY as a, executeIfOnline as i, isTelemetryDisabled as n, isGitHubActions as o, sendTelemetry as r, buildTelemetryEvent as t };
|
|
244
244
|
|
|
245
|
-
//# sourceMappingURL=telemetry-
|
|
245
|
+
//# sourceMappingURL=telemetry-juq4QBf7.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"telemetry-CaNU4-Bf.js","names":["dnsPromises","process"],"sources":["../../../internals/utils/src/env.ts","../../../internals/utils/src/network.ts","../src/utils/telemetry.ts"],"sourcesContent":["/**\n * Returns `true` when running inside a GitHub Actions workflow.\n *\n * @example\n * ```ts\n * if (isGitHubActions()) {\n * core.setOutput('result', 'ok')\n * }\n * ```\n */\nexport function isGitHubActions(): boolean {\n return !!process.env.GITHUB_ACTIONS\n}\n\n/**\n * Returns `true` when the process is running in a CI environment.\n * Covers GitHub Actions, GitLab CI, CircleCI, Travis CI, Jenkins, Bitbucket,\n * TeamCity, Buildkite, and Azure Pipelines.\n *\n * @example\n * ```ts\n * if (isCIEnvironment()) {\n * logger.level = 'error'\n * }\n * ```\n */\nexport function isCIEnvironment(): boolean {\n return !!(\n process.env.CI ||\n process.env.GITHUB_ACTIONS ||\n process.env.GITLAB_CI ||\n process.env.BITBUCKET_BUILD_NUMBER ||\n process.env.JENKINS_URL ||\n process.env.CIRCLECI ||\n process.env.TRAVIS ||\n process.env.TEAMCITY_VERSION ||\n process.env.BUILDKITE ||\n process.env.TF_BUILD\n )\n}\n\n/**\n * Returns `true` when the process has an interactive TTY with a valid terminal\n * width and is not running in CI.\n *\n * Some IDE-embedded terminals report `isTTY = true` but set `columns` to `0`,\n * which breaks clack's box-drawing helpers (they call `String.prototype.repeat`\n * with a negative count and throw a `RangeError`). We therefore require a\n * positive column count before declaring the TTY usable.\n *\n * @example\n * ```ts\n * if (canUseTTY()) {\n * renderProgressBar()\n * }\n * ```\n */\nexport function canUseTTY(): boolean {\n return !!process.stdout.isTTY && (process.stdout.columns ?? 0) > 0 && !isCIEnvironment()\n}\n","import { promises as dnsPromises } from 'node:dns'\n\n/**\n * Well-known stable domains used as DNS probes to check internet connectivity.\n */\nconst TEST_DOMAINS = ['dns.google.com', 'cloudflare.com', 'one.one.one.one'] as const\n\n/**\n * Returns `true` when the system has internet connectivity.\n * Probes DNS resolution against well-known stable domains.\n *\n * @example\n * ```ts\n * if (await isOnline()) {\n * await fetchLatestVersion()\n * }\n * ```\n */\nexport async function isOnline(): Promise<boolean> {\n for (const domain of TEST_DOMAINS) {\n try {\n await dnsPromises.resolve(domain)\n return true\n } catch {\n // Try next domain\n }\n }\n\n return false\n}\n\n/**\n * Executes `fn` only when the system is online. Returns `null` when offline or on error.\n *\n * @example\n * ```ts\n * const version = await executeIfOnline(() => fetchLatestVersion('kubb'))\n * // null when offline\n * ```\n */\nexport async function executeIfOnline<T>(fn: () => Promise<T>): Promise<T | null> {\n if (!(await isOnline())) return null\n\n try {\n return await fn()\n } catch {\n return null\n }\n}\n","import { randomBytes } from 'node:crypto'\nimport os from 'node:os'\nimport process from 'node:process'\nimport { executeIfOnline, isCIEnvironment } from '@internals/utils'\nimport { OTLP_ENDPOINT } from '../constants.ts'\n\n// OpenTelemetry OTLP JSON types\n// https://github.com/open-telemetry/opentelemetry-proto/blob/main/opentelemetry/proto/trace/v1/trace.proto\n// https://github.com/open-telemetry/opentelemetry-proto/blob/main/opentelemetry/proto/common/v1/common.proto\n\ntype OtlpStringValue = { stringValue: string }\ntype OtlpBoolValue = { boolValue: boolean }\ntype OtlpIntValue = { intValue: number }\ntype OtlpDoubleValue = { doubleValue: number }\ntype OtlpBytesValue = { bytesValue: string }\ntype OtlpArrayValue = { arrayValue: { values: OtlpAnyValue[] } }\ntype OtlpKvListValue = { kvlistValue: { values: OtlpKeyValue[] } }\n\ntype OtlpAnyValue = OtlpStringValue | OtlpBoolValue | OtlpIntValue | OtlpDoubleValue | OtlpBytesValue | OtlpArrayValue | OtlpKvListValue\n\ntype OtlpKeyValue = {\n key: string\n value: OtlpAnyValue\n}\n\ntype OtlpResource = {\n attributes: OtlpKeyValue[]\n droppedAttributesCount?: number\n}\n\ntype OtlpInstrumentationScope = {\n name: string\n version?: string\n attributes?: OtlpKeyValue[]\n droppedAttributesCount?: number\n}\n\n/** https://github.com/open-telemetry/opentelemetry-proto/blob/main/opentelemetry/proto/trace/v1/trace.proto#L103 */\ntype OtlpSpanKind = 0 | 1 | 2 | 3 | 4 | 5\n\n/** 0 = STATUS_CODE_UNSET, 1 = STATUS_CODE_OK, 2 = STATUS_CODE_ERROR */\ntype OtlpStatusCode = 0 | 1 | 2\n\ntype OtlpStatus = {\n code: OtlpStatusCode\n message?: string\n}\n\ntype OtlpSpan = {\n traceId: string\n spanId: string\n traceState?: string\n parentSpanId?: string\n name: string\n kind: OtlpSpanKind\n startTimeUnixNano: string\n endTimeUnixNano: string\n attributes?: OtlpKeyValue[]\n droppedAttributesCount?: number\n events?: OtlpSpanEvent[]\n droppedEventsCount?: number\n links?: OtlpSpanLink[]\n droppedLinksCount?: number\n status?: OtlpStatus\n}\n\ntype OtlpSpanEvent = {\n timeUnixNano: string\n name: string\n attributes?: OtlpKeyValue[]\n droppedAttributesCount?: number\n}\n\ntype OtlpSpanLink = {\n traceId: string\n spanId: string\n traceState?: string\n attributes?: OtlpKeyValue[]\n droppedAttributesCount?: number\n}\n\ntype OtlpScopeSpans = {\n scope: OtlpInstrumentationScope\n spans: OtlpSpan[]\n schemaUrl?: string\n}\n\ntype OtlpResourceSpans = {\n resource: OtlpResource\n scopeSpans: OtlpScopeSpans[]\n schemaUrl?: string\n}\n\n/** Root payload sent to POST /v1/traces */\ntype OtlpExportTraceServiceRequest = {\n resourceSpans: OtlpResourceSpans[]\n}\n\nexport type TelemetryPlugin = {\n name: string\n options: Record<string, unknown>\n}\n\ntype TelemetryEvent = {\n command: string\n kubbVersion: string\n nodeVersion: string\n platform: string\n ci: boolean\n plugins: TelemetryPlugin[]\n duration: number\n filesCreated: number\n status: 'success' | 'failed'\n}\n\n/**\n * Detect whether the current process is running inside a CI environment.\n * Delegates to the canonical isCIEnvironment() from envDetection.\n */\nexport function isCi(): boolean {\n return isCIEnvironment()\n}\n\n/**\n * Check if telemetry is disabled via DO_NOT_TRACK or KUBB_DISABLE_TELEMETRY.\n * Respects the standard DO_NOT_TRACK convention used across development tools.\n */\nexport function isTelemetryDisabled(): boolean {\n return (\n process.env['DO_NOT_TRACK'] === '1' ||\n process.env['DO_NOT_TRACK'] === 'true' ||\n process.env['KUBB_DISABLE_TELEMETRY'] === '1' ||\n process.env['KUBB_DISABLE_TELEMETRY'] === 'true'\n )\n}\n\n/**\n * Convert a TelemetryEvent into an OTLP-compatible JSON trace payload.\n * See https://opentelemetry.io/docs/languages/sdk-configuration/otlp-exporter/\n */\nexport function buildOtlpPayload(event: TelemetryEvent): OtlpExportTraceServiceRequest {\n const traceId = randomBytes(16).toString('hex')\n const spanId = randomBytes(8).toString('hex')\n const endTimeNs = BigInt(Date.now()) * 1_000_000n\n const startTimeNs = endTimeNs - BigInt(event.duration) * 1_000_000n\n\n const attributes: OtlpKeyValue[] = [\n { key: 'kubb.command', value: { stringValue: event.command } },\n { key: 'kubb.version', value: { stringValue: event.kubbVersion } },\n { key: 'kubb.node_version', value: { stringValue: event.nodeVersion } },\n { key: 'kubb.platform', value: { stringValue: event.platform } },\n { key: 'kubb.ci', value: { boolValue: event.ci } },\n { key: 'kubb.files_created', value: { intValue: event.filesCreated } },\n { key: 'kubb.status', value: { stringValue: event.status } },\n {\n key: 'kubb.plugins',\n value: {\n arrayValue: {\n values: event.plugins.map(\n (p): OtlpKvListValue => ({\n kvlistValue: {\n values: [\n { key: 'name', value: { stringValue: p.name } },\n {\n key: 'options',\n value: {\n stringValue: JSON.stringify({\n ...p.options,\n usedEnumNames: undefined,\n }),\n },\n },\n ],\n },\n }),\n ),\n },\n },\n },\n ]\n\n return {\n resourceSpans: [\n {\n resource: {\n attributes: [\n { key: 'service.name', value: { stringValue: 'kubb-cli' } },\n {\n key: 'service.version',\n value: { stringValue: event.kubbVersion },\n },\n { key: 'telemetry.sdk.language', value: { stringValue: 'nodejs' } },\n ],\n },\n scopeSpans: [\n {\n scope: { name: 'kubb-cli', version: event.kubbVersion },\n spans: [\n {\n traceId,\n spanId,\n name: event.command,\n kind: 1 satisfies OtlpSpanKind,\n startTimeUnixNano: String(startTimeNs),\n endTimeUnixNano: String(endTimeNs),\n attributes,\n status: {\n code: (event.status === 'success' ? 1 : 2) satisfies OtlpStatusCode,\n },\n },\n ],\n },\n ],\n },\n ],\n }\n}\n\n/**\n * Send an anonymous telemetry event to the Kubb OTLP endpoint.\n * Respects DO_NOT_TRACK and KUBB_DISABLE_TELEMETRY environment variables.\n * Fails silently to never interrupt the generation process.\n */\nexport async function sendTelemetry(event: TelemetryEvent): Promise<void> {\n if (isTelemetryDisabled()) {\n return\n }\n\n await executeIfOnline(async () => {\n try {\n await fetch(`${OTLP_ENDPOINT}/v1/traces`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'Kubb-Telemetry-Version': '1',\n 'Kubb-Telemetry-Source': 'kubb-cli',\n },\n body: JSON.stringify(buildOtlpPayload(event)),\n signal: AbortSignal.timeout(5_000),\n })\n } catch (_e) {\n // Fail silently – telemetry must never break the CLI\n }\n })\n}\n\n/**\n * Build an anonymous telemetry payload from a completed generation run.\n * No file paths, OpenAPI specs, or secrets are included.\n */\nexport function buildTelemetryEvent(options: {\n command: 'generate' | 'mcp' | 'validate' | 'agent'\n kubbVersion: string\n plugins?: TelemetryPlugin[]\n hrStart: [number, number]\n filesCreated?: number\n status: 'success' | 'failed'\n}): TelemetryEvent {\n const [seconds, nanoseconds] = process.hrtime(options.hrStart)\n const duration = Math.round(seconds * 1000 + nanoseconds / 1e6)\n\n return {\n command: options.command,\n kubbVersion: options.kubbVersion,\n nodeVersion: process.versions.node.split('.')[0] as string,\n platform: os.platform(),\n ci: isCi(),\n plugins: options.plugins ?? [],\n duration,\n filesCreated: options.filesCreated ?? 0,\n status: options.status,\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAUA,SAAgB,kBAA2B;AACzC,QAAO,CAAC,CAAC,QAAQ,IAAI;;;;;;;;;;;;;;AAevB,SAAgB,kBAA2B;AACzC,QAAO,CAAC,EACN,QAAQ,IAAI,MACZ,QAAQ,IAAI,kBACZ,QAAQ,IAAI,aACZ,QAAQ,IAAI,0BACZ,QAAQ,IAAI,eACZ,QAAQ,IAAI,YACZ,QAAQ,IAAI,UACZ,QAAQ,IAAI,oBACZ,QAAQ,IAAI,aACZ,QAAQ,IAAI;;;;;;;;;;;;;;;;;;AAoBhB,SAAgB,YAAqB;AACnC,QAAO,CAAC,CAAC,QAAQ,OAAO,UAAU,QAAQ,OAAO,WAAW,KAAK,KAAK,CAAC,iBAAiB;;;;;;;ACrD1F,MAAM,eAAe;CAAC;CAAkB;CAAkB;CAAkB;;;;;;;;;;;;AAa5E,eAAsB,WAA6B;AACjD,MAAK,MAAM,UAAU,aACnB,KAAI;AACF,QAAMA,SAAY,QAAQ,OAAO;AACjC,SAAO;SACD;AAKV,QAAO;;;;;;;;;;;AAYT,eAAsB,gBAAmB,IAAyC;AAChF,KAAI,CAAE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
|
|
1
|
+
{"version":3,"file":"telemetry-juq4QBf7.js","names":["dnsPromises","process"],"sources":["../../../internals/utils/src/env.ts","../../../internals/utils/src/network.ts","../src/utils/telemetry.ts"],"sourcesContent":["/**\n * Returns `true` when running inside a GitHub Actions workflow.\n *\n * @example\n * ```ts\n * if (isGitHubActions()) {\n * core.setOutput('result', 'ok')\n * }\n * ```\n */\nexport function isGitHubActions(): boolean {\n return !!process.env.GITHUB_ACTIONS\n}\n\n/**\n * Returns `true` when the process is running in a CI environment.\n * Covers GitHub Actions, GitLab CI, CircleCI, Travis CI, Jenkins, Bitbucket,\n * TeamCity, Buildkite, and Azure Pipelines.\n *\n * @example\n * ```ts\n * if (isCIEnvironment()) {\n * logger.level = 'error'\n * }\n * ```\n */\nexport function isCIEnvironment(): boolean {\n return !!(\n process.env.CI ||\n process.env.GITHUB_ACTIONS ||\n process.env.GITLAB_CI ||\n process.env.BITBUCKET_BUILD_NUMBER ||\n process.env.JENKINS_URL ||\n process.env.CIRCLECI ||\n process.env.TRAVIS ||\n process.env.TEAMCITY_VERSION ||\n process.env.BUILDKITE ||\n process.env.TF_BUILD\n )\n}\n\n/**\n * Returns `true` when the process has an interactive TTY with a valid terminal\n * width and is not running in CI.\n *\n * Some IDE-embedded terminals report `isTTY = true` but set `columns` to `0`,\n * which breaks clack's box-drawing helpers (they call `String.prototype.repeat`\n * with a negative count and throw a `RangeError`). We therefore require a\n * positive column count before declaring the TTY usable.\n *\n * @example\n * ```ts\n * if (canUseTTY()) {\n * renderProgressBar()\n * }\n * ```\n */\nexport function canUseTTY(): boolean {\n return !!process.stdout.isTTY && (process.stdout.columns ?? 0) > 0 && !isCIEnvironment()\n}\n","import { promises as dnsPromises } from 'node:dns'\n\n/**\n * Well-known stable domains used as DNS probes to check internet connectivity.\n */\nconst TEST_DOMAINS = ['dns.google.com', 'cloudflare.com', 'one.one.one.one'] as const\n\n/**\n * Returns `true` when the system has internet connectivity.\n * Probes DNS resolution against well-known stable domains.\n *\n * @example\n * ```ts\n * if (await isOnline()) {\n * await fetchLatestVersion()\n * }\n * ```\n */\nexport async function isOnline(): Promise<boolean> {\n for (const domain of TEST_DOMAINS) {\n try {\n await dnsPromises.resolve(domain)\n return true\n } catch {\n // Try next domain\n }\n }\n\n return false\n}\n\n/**\n * Executes `fn` only when the system is online. Returns `null` when offline or on error.\n *\n * @example\n * ```ts\n * const version = await executeIfOnline(() => fetchLatestVersion('kubb'))\n * // null when offline\n * ```\n */\nexport async function executeIfOnline<T>(fn: () => Promise<T>): Promise<T | null> {\n if (!(await isOnline())) return null\n\n try {\n return await fn()\n } catch {\n return null\n }\n}\n","import { randomBytes } from 'node:crypto'\nimport os from 'node:os'\nimport process from 'node:process'\nimport { executeIfOnline, isCIEnvironment } from '@internals/utils'\nimport { OTLP_ENDPOINT } from '../constants.ts'\n\n// OpenTelemetry OTLP JSON types\n// https://github.com/open-telemetry/opentelemetry-proto/blob/main/opentelemetry/proto/trace/v1/trace.proto\n// https://github.com/open-telemetry/opentelemetry-proto/blob/main/opentelemetry/proto/common/v1/common.proto\n\ntype OtlpStringValue = { stringValue: string }\ntype OtlpBoolValue = { boolValue: boolean }\ntype OtlpIntValue = { intValue: number }\ntype OtlpDoubleValue = { doubleValue: number }\ntype OtlpBytesValue = { bytesValue: string }\ntype OtlpArrayValue = { arrayValue: { values: OtlpAnyValue[] } }\ntype OtlpKvListValue = { kvlistValue: { values: OtlpKeyValue[] } }\n\ntype OtlpAnyValue = OtlpStringValue | OtlpBoolValue | OtlpIntValue | OtlpDoubleValue | OtlpBytesValue | OtlpArrayValue | OtlpKvListValue\n\ntype OtlpKeyValue = {\n key: string\n value: OtlpAnyValue\n}\n\ntype OtlpResource = {\n attributes: OtlpKeyValue[]\n droppedAttributesCount?: number\n}\n\ntype OtlpInstrumentationScope = {\n name: string\n version?: string\n attributes?: OtlpKeyValue[]\n droppedAttributesCount?: number\n}\n\n/** https://github.com/open-telemetry/opentelemetry-proto/blob/main/opentelemetry/proto/trace/v1/trace.proto#L103 */\ntype OtlpSpanKind = 0 | 1 | 2 | 3 | 4 | 5\n\n/** 0 = STATUS_CODE_UNSET, 1 = STATUS_CODE_OK, 2 = STATUS_CODE_ERROR */\ntype OtlpStatusCode = 0 | 1 | 2\n\ntype OtlpStatus = {\n code: OtlpStatusCode\n message?: string\n}\n\ntype OtlpSpan = {\n traceId: string\n spanId: string\n traceState?: string\n parentSpanId?: string\n name: string\n kind: OtlpSpanKind\n startTimeUnixNano: string\n endTimeUnixNano: string\n attributes?: OtlpKeyValue[]\n droppedAttributesCount?: number\n events?: OtlpSpanEvent[]\n droppedEventsCount?: number\n links?: OtlpSpanLink[]\n droppedLinksCount?: number\n status?: OtlpStatus\n}\n\ntype OtlpSpanEvent = {\n timeUnixNano: string\n name: string\n attributes?: OtlpKeyValue[]\n droppedAttributesCount?: number\n}\n\ntype OtlpSpanLink = {\n traceId: string\n spanId: string\n traceState?: string\n attributes?: OtlpKeyValue[]\n droppedAttributesCount?: number\n}\n\ntype OtlpScopeSpans = {\n scope: OtlpInstrumentationScope\n spans: OtlpSpan[]\n schemaUrl?: string\n}\n\ntype OtlpResourceSpans = {\n resource: OtlpResource\n scopeSpans: OtlpScopeSpans[]\n schemaUrl?: string\n}\n\n/** Root payload sent to POST /v1/traces */\ntype OtlpExportTraceServiceRequest = {\n resourceSpans: OtlpResourceSpans[]\n}\n\nexport type TelemetryPlugin = {\n name: string\n options: Record<string, unknown>\n}\n\ntype TelemetryEvent = {\n command: string\n kubbVersion: string\n nodeVersion: string\n platform: string\n ci: boolean\n plugins: TelemetryPlugin[]\n duration: number\n filesCreated: number\n status: 'success' | 'failed'\n}\n\n/**\n * Detect whether the current process is running inside a CI environment.\n * Delegates to the canonical isCIEnvironment() from envDetection.\n */\nexport function isCi(): boolean {\n return isCIEnvironment()\n}\n\n/**\n * Check if telemetry is disabled via DO_NOT_TRACK or KUBB_DISABLE_TELEMETRY.\n * Respects the standard DO_NOT_TRACK convention used across development tools.\n */\nexport function isTelemetryDisabled(): boolean {\n return (\n process.env['DO_NOT_TRACK'] === '1' ||\n process.env['DO_NOT_TRACK'] === 'true' ||\n process.env['KUBB_DISABLE_TELEMETRY'] === '1' ||\n process.env['KUBB_DISABLE_TELEMETRY'] === 'true'\n )\n}\n\n/**\n * Convert a TelemetryEvent into an OTLP-compatible JSON trace payload.\n * See https://opentelemetry.io/docs/languages/sdk-configuration/otlp-exporter/\n */\nexport function buildOtlpPayload(event: TelemetryEvent): OtlpExportTraceServiceRequest {\n const traceId = randomBytes(16).toString('hex')\n const spanId = randomBytes(8).toString('hex')\n const endTimeNs = BigInt(Date.now()) * 1_000_000n\n const startTimeNs = endTimeNs - BigInt(event.duration) * 1_000_000n\n\n const attributes: OtlpKeyValue[] = [\n { key: 'kubb.command', value: { stringValue: event.command } },\n { key: 'kubb.version', value: { stringValue: event.kubbVersion } },\n { key: 'kubb.node_version', value: { stringValue: event.nodeVersion } },\n { key: 'kubb.platform', value: { stringValue: event.platform } },\n { key: 'kubb.ci', value: { boolValue: event.ci } },\n { key: 'kubb.files_created', value: { intValue: event.filesCreated } },\n { key: 'kubb.status', value: { stringValue: event.status } },\n {\n key: 'kubb.plugins',\n value: {\n arrayValue: {\n values: event.plugins.map(\n (p): OtlpKvListValue => ({\n kvlistValue: {\n values: [\n { key: 'name', value: { stringValue: p.name } },\n {\n key: 'options',\n value: {\n stringValue: JSON.stringify({\n ...p.options,\n usedEnumNames: undefined,\n }),\n },\n },\n ],\n },\n }),\n ),\n },\n },\n },\n ]\n\n return {\n resourceSpans: [\n {\n resource: {\n attributes: [\n { key: 'service.name', value: { stringValue: 'kubb-cli' } },\n {\n key: 'service.version',\n value: { stringValue: event.kubbVersion },\n },\n { key: 'telemetry.sdk.language', value: { stringValue: 'nodejs' } },\n ],\n },\n scopeSpans: [\n {\n scope: { name: 'kubb-cli', version: event.kubbVersion },\n spans: [\n {\n traceId,\n spanId,\n name: event.command,\n kind: 1 satisfies OtlpSpanKind,\n startTimeUnixNano: String(startTimeNs),\n endTimeUnixNano: String(endTimeNs),\n attributes,\n status: {\n code: (event.status === 'success' ? 1 : 2) satisfies OtlpStatusCode,\n },\n },\n ],\n },\n ],\n },\n ],\n }\n}\n\n/**\n * Send an anonymous telemetry event to the Kubb OTLP endpoint.\n * Respects DO_NOT_TRACK and KUBB_DISABLE_TELEMETRY environment variables.\n * Fails silently to never interrupt the generation process.\n */\nexport async function sendTelemetry(event: TelemetryEvent): Promise<void> {\n if (isTelemetryDisabled()) {\n return\n }\n\n await executeIfOnline(async () => {\n try {\n await fetch(`${OTLP_ENDPOINT}/v1/traces`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'Kubb-Telemetry-Version': '1',\n 'Kubb-Telemetry-Source': 'kubb-cli',\n },\n body: JSON.stringify(buildOtlpPayload(event)),\n signal: AbortSignal.timeout(5_000),\n })\n } catch (_e) {\n // Fail silently – telemetry must never break the CLI\n }\n })\n}\n\n/**\n * Build an anonymous telemetry payload from a completed generation run.\n * No file paths, OpenAPI specs, or secrets are included.\n */\nexport function buildTelemetryEvent(options: {\n command: 'generate' | 'mcp' | 'validate' | 'agent'\n kubbVersion: string\n plugins?: TelemetryPlugin[]\n hrStart: [number, number]\n filesCreated?: number\n status: 'success' | 'failed'\n}): TelemetryEvent {\n const [seconds, nanoseconds] = process.hrtime(options.hrStart)\n const duration = Math.round(seconds * 1000 + nanoseconds / 1e6)\n\n return {\n command: options.command,\n kubbVersion: options.kubbVersion,\n nodeVersion: process.versions.node.split('.')[0] as string,\n platform: os.platform(),\n ci: isCi(),\n plugins: options.plugins ?? [],\n duration,\n filesCreated: options.filesCreated ?? 0,\n status: options.status,\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAUA,SAAgB,kBAA2B;CACzC,OAAO,CAAC,CAAC,QAAQ,IAAI;;;;;;;;;;;;;;AAevB,SAAgB,kBAA2B;CACzC,OAAO,CAAC,EACN,QAAQ,IAAI,MACZ,QAAQ,IAAI,kBACZ,QAAQ,IAAI,aACZ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,yBAAyB;KAC1B;IACD,MAAM,KAAK,UAAU,iBAAiB,MAAM,CAAC;IAC7C,QAAQ,YAAY,QAAQ,IAAM;IACnC,CAAC;WACK,IAAI;GAGb;;;;;;AAOJ,SAAgB,oBAAoB,SAOjB;CACjB,MAAM,CAAC,SAAS,eAAeA,UAAQ,OAAO,QAAQ,QAAQ;CAC9D,MAAM,WAAW,KAAK,MAAM,UAAU,MAAO,cAAc,IAAI;CAE/D,OAAO;EACL,SAAS,QAAQ;EACjB,aAAa,QAAQ;EACrB,aAAaA,UAAQ,SAAS,KAAK,MAAM,IAAI,CAAC;EAC9C,UAAU,GAAG,UAAU;EACvB,IAAI,MAAM;EACV,SAAS,QAAQ,WAAW,EAAE;EAC9B;EACA,cAAc,QAAQ,gBAAgB;EACtC,QAAQ,QAAQ;EACjB"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
const require_chunk = require("./chunk-ByKO4r7w.cjs");
|
|
2
|
+
const require_errors = require("./errors-CLCjoSg0.cjs");
|
|
3
|
+
const require_telemetry = require("./telemetry-BLX0NzRk.cjs");
|
|
4
|
+
let node_util = require("node:util");
|
|
5
|
+
let node_process = require("node:process");
|
|
6
|
+
node_process = require_chunk.__toESM(node_process, 1);
|
|
7
|
+
//#region src/runners/validate.ts
|
|
8
|
+
function loadValidateModule() {
|
|
9
|
+
return import("@kubb/adapter-oas");
|
|
10
|
+
}
|
|
11
|
+
async function runValidate({ input, version }, dependencies = { loadValidateModule }) {
|
|
12
|
+
const hrStart = node_process.default.hrtime();
|
|
13
|
+
try {
|
|
14
|
+
const { adapterOas } = await dependencies.loadValidateModule();
|
|
15
|
+
await adapterOas().validate(input, { throwOnError: true });
|
|
16
|
+
await require_telemetry.sendTelemetry(require_telemetry.buildTelemetryEvent({
|
|
17
|
+
command: "validate",
|
|
18
|
+
kubbVersion: version,
|
|
19
|
+
hrStart,
|
|
20
|
+
status: "success"
|
|
21
|
+
}));
|
|
22
|
+
console.log("✅ Validation success");
|
|
23
|
+
} catch (error) {
|
|
24
|
+
await require_telemetry.sendTelemetry(require_telemetry.buildTelemetryEvent({
|
|
25
|
+
command: "validate",
|
|
26
|
+
kubbVersion: version,
|
|
27
|
+
hrStart,
|
|
28
|
+
status: "failed"
|
|
29
|
+
}));
|
|
30
|
+
if (error instanceof Error && /@kubb\/adapter-oas/.test(error.message)) {
|
|
31
|
+
console.error((0, node_util.styleText)("red", "The @kubb/adapter-oas package is not installed."));
|
|
32
|
+
console.error("");
|
|
33
|
+
console.error("Install it with:");
|
|
34
|
+
console.error((0, node_util.styleText)("cyan", " npm install @kubb/adapter-oas"));
|
|
35
|
+
console.error((0, node_util.styleText)("cyan", " # or"));
|
|
36
|
+
console.error((0, node_util.styleText)("cyan", " pnpm install @kubb/adapter-oas"));
|
|
37
|
+
console.error("");
|
|
38
|
+
}
|
|
39
|
+
console.error("❌ Validation failed");
|
|
40
|
+
console.error(require_errors.getErrorMessage(error));
|
|
41
|
+
node_process.default.exit(1);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
//#endregion
|
|
45
|
+
exports.runValidate = runValidate;
|
|
46
|
+
|
|
47
|
+
//# sourceMappingURL=validate-BU4fPTMc.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate-BU4fPTMc.cjs","names":["process","sendTelemetry","buildTelemetryEvent","getErrorMessage"],"sources":["../src/runners/validate.ts"],"sourcesContent":["import process from 'node:process'\nimport { styleText } from 'node:util'\nimport { getErrorMessage } from '@internals/utils'\nimport { buildTelemetryEvent, sendTelemetry } from '../utils/telemetry.ts'\n\ntype ValidateOptions = {\n input: string\n version: string\n}\n\ntype ValidateModule = typeof import('@kubb/adapter-oas')\ntype ValidateDependencies = {\n loadValidateModule: () => Promise<ValidateModule>\n}\n\nexport function loadValidateModule(): Promise<ValidateModule> {\n return import('@kubb/adapter-oas') as Promise<ValidateModule>\n}\n\nexport async function runValidate({ input, version }: ValidateOptions, dependencies: ValidateDependencies = { loadValidateModule }): Promise<void> {\n const hrStart = process.hrtime()\n try {\n const { adapterOas } = await dependencies.loadValidateModule()\n const adapter = adapterOas()\n await adapter.validate!(input, { throwOnError: true })\n\n await sendTelemetry(\n buildTelemetryEvent({\n command: 'validate',\n kubbVersion: version,\n hrStart,\n status: 'success',\n }),\n )\n console.log('✅ Validation success')\n } catch (error) {\n await sendTelemetry(\n buildTelemetryEvent({\n command: 'validate',\n kubbVersion: version,\n hrStart,\n status: 'failed',\n }),\n )\n if (error instanceof Error && /@kubb\\/adapter-oas/.test(error.message)) {\n console.error(styleText('red', 'The @kubb/adapter-oas package is not installed.'))\n console.error('')\n console.error('Install it with:')\n console.error(styleText('cyan', ' npm install @kubb/adapter-oas'))\n console.error(styleText('cyan', ' # or'))\n console.error(styleText('cyan', ' pnpm install @kubb/adapter-oas'))\n console.error('')\n }\n console.error('❌ Validation failed')\n console.error(getErrorMessage(error))\n process.exit(1)\n }\n}\n"],"mappings":";;;;;;;AAeA,SAAgB,qBAA8C;CAC5D,OAAO,OAAO;;AAGhB,eAAsB,YAAY,EAAE,OAAO,WAA4B,eAAqC,EAAE,oBAAoB,EAAiB;CACjJ,MAAM,UAAUA,aAAAA,QAAQ,QAAQ;CAChC,IAAI;EACF,MAAM,EAAE,eAAe,MAAM,aAAa,oBAAoB;EAE9D,MADgB,YACH,CAAC,SAAU,OAAO,EAAE,cAAc,MAAM,CAAC;EAEtD,MAAMC,kBAAAA,cACJC,kBAAAA,oBAAoB;GAClB,SAAS;GACT,aAAa;GACb;GACA,QAAQ;GACT,CAAC,CACH;EACD,QAAQ,IAAI,uBAAuB;UAC5B,OAAO;EACd,MAAMD,kBAAAA,cACJC,kBAAAA,oBAAoB;GAClB,SAAS;GACT,aAAa;GACb;GACA,QAAQ;GACT,CAAC,CACH;EACD,IAAI,iBAAiB,SAAS,qBAAqB,KAAK,MAAM,QAAQ,EAAE;GACtE,QAAQ,OAAA,GAAA,UAAA,WAAgB,OAAO,kDAAkD,CAAC;GAClF,QAAQ,MAAM,GAAG;GACjB,QAAQ,MAAM,mBAAmB;GACjC,QAAQ,OAAA,GAAA,UAAA,WAAgB,QAAQ,kCAAkC,CAAC;GACnE,QAAQ,OAAA,GAAA,UAAA,WAAgB,QAAQ,SAAS,CAAC;GAC1C,QAAQ,OAAA,GAAA,UAAA,WAAgB,QAAQ,mCAAmC,CAAC;GACpE,QAAQ,MAAM,GAAG;;EAEnB,QAAQ,MAAM,sBAAsB;EACpC,QAAQ,MAAMC,eAAAA,gBAAgB,MAAM,CAAC;EACrC,aAAA,QAAQ,KAAK,EAAE"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import "./chunk--u3MIqq1.js";
|
|
2
|
+
import { n as defineCommand } from "./define-Ctii4bel.js";
|
|
3
|
+
import { t as version } from "./package-vLafMWCe.js";
|
|
4
|
+
//#region src/commands/validate.ts
|
|
5
|
+
const command = defineCommand({
|
|
6
|
+
name: "validate",
|
|
7
|
+
description: "Parse and validate an OpenAPI/Swagger file for structural correctness. Reports schema errors, missing required fields, and malformed references. Use this before running generate to catch spec issues early.",
|
|
8
|
+
examples: ["kubb validate --input ./openapi.yaml", "kubb validate --input https://petstore3.swagger.io/api/v3/openapi.json"],
|
|
9
|
+
options: { input: {
|
|
10
|
+
type: "string",
|
|
11
|
+
description: "Path or URL to the OpenAPI/Swagger file to validate",
|
|
12
|
+
short: "i",
|
|
13
|
+
required: true
|
|
14
|
+
} },
|
|
15
|
+
async run({ values }) {
|
|
16
|
+
const { runValidate } = await import("./validate-k9s_hFah.js");
|
|
17
|
+
await runValidate({
|
|
18
|
+
input: values.input,
|
|
19
|
+
version
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
//#endregion
|
|
24
|
+
export { command };
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=validate-BfJoCxrC.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate-BfJoCxrC.js","names":[],"sources":["../src/commands/validate.ts"],"sourcesContent":["import { defineCommand } from '@internals/utils'\nimport { version } from '../../package.json'\n\nexport const command = defineCommand({\n name: 'validate',\n description:\n 'Parse and validate an OpenAPI/Swagger file for structural correctness. Reports schema errors, missing required fields, and malformed references. Use this before running generate to catch spec issues early.',\n examples: ['kubb validate --input ./openapi.yaml', 'kubb validate --input https://petstore3.swagger.io/api/v3/openapi.json'],\n options: {\n input: {\n type: 'string',\n description: 'Path or URL to the OpenAPI/Swagger file to validate',\n short: 'i',\n required: true,\n },\n },\n async run({ values }) {\n const { runValidate } = await import('../runners/validate.ts')\n\n await runValidate({ input: values.input, version })\n },\n})\n"],"mappings":";;;;AAGA,MAAa,UAAU,cAAc;CACnC,MAAM;CACN,aACE;CACF,UAAU,CAAC,wCAAwC,yEAAyE;CAC5H,SAAS,EACP,OAAO;EACL,MAAM;EACN,aAAa;EACb,OAAO;EACP,UAAU;EACX,EACF;CACD,MAAM,IAAI,EAAE,UAAU;EACpB,MAAM,EAAE,gBAAgB,MAAM,OAAO;EAErC,MAAM,YAAY;GAAE,OAAO,OAAO;GAAO;GAAS,CAAC;;CAEtD,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
require("./chunk-ByKO4r7w.cjs");
|
|
2
|
+
const require_define = require("./define-Bdn8j5VM.cjs");
|
|
3
|
+
const require_package = require("./package-iheSdfas.cjs");
|
|
4
|
+
//#region src/commands/validate.ts
|
|
5
|
+
const command = require_define.defineCommand({
|
|
6
|
+
name: "validate",
|
|
7
|
+
description: "Parse and validate an OpenAPI/Swagger file for structural correctness. Reports schema errors, missing required fields, and malformed references. Use this before running generate to catch spec issues early.",
|
|
8
|
+
examples: ["kubb validate --input ./openapi.yaml", "kubb validate --input https://petstore3.swagger.io/api/v3/openapi.json"],
|
|
9
|
+
options: { input: {
|
|
10
|
+
type: "string",
|
|
11
|
+
description: "Path or URL to the OpenAPI/Swagger file to validate",
|
|
12
|
+
short: "i",
|
|
13
|
+
required: true
|
|
14
|
+
} },
|
|
15
|
+
async run({ values }) {
|
|
16
|
+
const { runValidate } = await Promise.resolve().then(() => require("./validate-BU4fPTMc.cjs"));
|
|
17
|
+
await runValidate({
|
|
18
|
+
input: values.input,
|
|
19
|
+
version: require_package.version
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
//#endregion
|
|
24
|
+
exports.command = command;
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=validate-DIDBROB2.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate-DIDBROB2.cjs","names":["defineCommand"],"sources":["../src/commands/validate.ts"],"sourcesContent":["import { defineCommand } from '@internals/utils'\nimport { version } from '../../package.json'\n\nexport const command = defineCommand({\n name: 'validate',\n description:\n 'Parse and validate an OpenAPI/Swagger file for structural correctness. Reports schema errors, missing required fields, and malformed references. Use this before running generate to catch spec issues early.',\n examples: ['kubb validate --input ./openapi.yaml', 'kubb validate --input https://petstore3.swagger.io/api/v3/openapi.json'],\n options: {\n input: {\n type: 'string',\n description: 'Path or URL to the OpenAPI/Swagger file to validate',\n short: 'i',\n required: true,\n },\n },\n async run({ values }) {\n const { runValidate } = await import('../runners/validate.ts')\n\n await runValidate({ input: values.input, version })\n },\n})\n"],"mappings":";;;;AAGA,MAAa,UAAUA,eAAAA,cAAc;CACnC,MAAM;CACN,aACE;CACF,UAAU,CAAC,wCAAwC,yEAAyE;CAC5H,SAAS,EACP,OAAO;EACL,MAAM;EACN,aAAa;EACb,OAAO;EACP,UAAU;EACX,EACF;CACD,MAAM,IAAI,EAAE,UAAU;EACpB,MAAM,EAAE,gBAAgB,MAAA,QAAA,SAAA,CAAA,WAAA,QAAM,0BAAA,CAAA;EAE9B,MAAM,YAAY;GAAE,OAAO,OAAO;GAAO,SAAA,gBAAA;GAAS,CAAC;;CAEtD,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import "./chunk--u3MIqq1.js";
|
|
2
|
+
import { t as getErrorMessage } from "./errors-CjPmyZHy.js";
|
|
3
|
+
import { r as sendTelemetry, t as buildTelemetryEvent } from "./telemetry-juq4QBf7.js";
|
|
4
|
+
import { styleText } from "node:util";
|
|
5
|
+
import process from "node:process";
|
|
6
|
+
//#region src/runners/validate.ts
|
|
7
|
+
function loadValidateModule() {
|
|
8
|
+
return import("@kubb/adapter-oas");
|
|
9
|
+
}
|
|
10
|
+
async function runValidate({ input, version }, dependencies = { loadValidateModule }) {
|
|
11
|
+
const hrStart = process.hrtime();
|
|
12
|
+
try {
|
|
13
|
+
const { adapterOas } = await dependencies.loadValidateModule();
|
|
14
|
+
await adapterOas().validate(input, { throwOnError: true });
|
|
15
|
+
await sendTelemetry(buildTelemetryEvent({
|
|
16
|
+
command: "validate",
|
|
17
|
+
kubbVersion: version,
|
|
18
|
+
hrStart,
|
|
19
|
+
status: "success"
|
|
20
|
+
}));
|
|
21
|
+
console.log("✅ Validation success");
|
|
22
|
+
} catch (error) {
|
|
23
|
+
await sendTelemetry(buildTelemetryEvent({
|
|
24
|
+
command: "validate",
|
|
25
|
+
kubbVersion: version,
|
|
26
|
+
hrStart,
|
|
27
|
+
status: "failed"
|
|
28
|
+
}));
|
|
29
|
+
if (error instanceof Error && /@kubb\/adapter-oas/.test(error.message)) {
|
|
30
|
+
console.error(styleText("red", "The @kubb/adapter-oas package is not installed."));
|
|
31
|
+
console.error("");
|
|
32
|
+
console.error("Install it with:");
|
|
33
|
+
console.error(styleText("cyan", " npm install @kubb/adapter-oas"));
|
|
34
|
+
console.error(styleText("cyan", " # or"));
|
|
35
|
+
console.error(styleText("cyan", " pnpm install @kubb/adapter-oas"));
|
|
36
|
+
console.error("");
|
|
37
|
+
}
|
|
38
|
+
console.error("❌ Validation failed");
|
|
39
|
+
console.error(getErrorMessage(error));
|
|
40
|
+
process.exit(1);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
//#endregion
|
|
44
|
+
export { runValidate };
|
|
45
|
+
|
|
46
|
+
//# sourceMappingURL=validate-k9s_hFah.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate-k9s_hFah.js","names":[],"sources":["../src/runners/validate.ts"],"sourcesContent":["import process from 'node:process'\nimport { styleText } from 'node:util'\nimport { getErrorMessage } from '@internals/utils'\nimport { buildTelemetryEvent, sendTelemetry } from '../utils/telemetry.ts'\n\ntype ValidateOptions = {\n input: string\n version: string\n}\n\ntype ValidateModule = typeof import('@kubb/adapter-oas')\ntype ValidateDependencies = {\n loadValidateModule: () => Promise<ValidateModule>\n}\n\nexport function loadValidateModule(): Promise<ValidateModule> {\n return import('@kubb/adapter-oas') as Promise<ValidateModule>\n}\n\nexport async function runValidate({ input, version }: ValidateOptions, dependencies: ValidateDependencies = { loadValidateModule }): Promise<void> {\n const hrStart = process.hrtime()\n try {\n const { adapterOas } = await dependencies.loadValidateModule()\n const adapter = adapterOas()\n await adapter.validate!(input, { throwOnError: true })\n\n await sendTelemetry(\n buildTelemetryEvent({\n command: 'validate',\n kubbVersion: version,\n hrStart,\n status: 'success',\n }),\n )\n console.log('✅ Validation success')\n } catch (error) {\n await sendTelemetry(\n buildTelemetryEvent({\n command: 'validate',\n kubbVersion: version,\n hrStart,\n status: 'failed',\n }),\n )\n if (error instanceof Error && /@kubb\\/adapter-oas/.test(error.message)) {\n console.error(styleText('red', 'The @kubb/adapter-oas package is not installed.'))\n console.error('')\n console.error('Install it with:')\n console.error(styleText('cyan', ' npm install @kubb/adapter-oas'))\n console.error(styleText('cyan', ' # or'))\n console.error(styleText('cyan', ' pnpm install @kubb/adapter-oas'))\n console.error('')\n }\n console.error('❌ Validation failed')\n console.error(getErrorMessage(error))\n process.exit(1)\n }\n}\n"],"mappings":";;;;;;AAeA,SAAgB,qBAA8C;CAC5D,OAAO,OAAO;;AAGhB,eAAsB,YAAY,EAAE,OAAO,WAA4B,eAAqC,EAAE,oBAAoB,EAAiB;CACjJ,MAAM,UAAU,QAAQ,QAAQ;CAChC,IAAI;EACF,MAAM,EAAE,eAAe,MAAM,aAAa,oBAAoB;EAE9D,MADgB,YACH,CAAC,SAAU,OAAO,EAAE,cAAc,MAAM,CAAC;EAEtD,MAAM,cACJ,oBAAoB;GAClB,SAAS;GACT,aAAa;GACb;GACA,QAAQ;GACT,CAAC,CACH;EACD,QAAQ,IAAI,uBAAuB;UAC5B,OAAO;EACd,MAAM,cACJ,oBAAoB;GAClB,SAAS;GACT,aAAa;GACb;GACA,QAAQ;GACT,CAAC,CACH;EACD,IAAI,iBAAiB,SAAS,qBAAqB,KAAK,MAAM,QAAQ,EAAE;GACtE,QAAQ,MAAM,UAAU,OAAO,kDAAkD,CAAC;GAClF,QAAQ,MAAM,GAAG;GACjB,QAAQ,MAAM,mBAAmB;GACjC,QAAQ,MAAM,UAAU,QAAQ,kCAAkC,CAAC;GACnE,QAAQ,MAAM,UAAU,QAAQ,SAAS,CAAC;GAC1C,QAAQ,MAAM,UAAU,QAAQ,mCAAmC,CAAC;GACpE,QAAQ,MAAM,GAAG;;EAEnB,QAAQ,MAAM,sBAAsB;EACpC,QAAQ,MAAM,gBAAgB,MAAM,CAAC;EACrC,QAAQ,KAAK,EAAE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/cli",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.6",
|
|
4
4
|
"description": "Command-line interface for Kubb, enabling easy generation of TypeScript, React-Query, Zod, and other code from OpenAPI specifications.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cli",
|
|
@@ -57,17 +57,22 @@
|
|
|
57
57
|
"cosmiconfig": "^9.0.1",
|
|
58
58
|
"jiti": "^2.7.0",
|
|
59
59
|
"tinyexec": "^1.1.2",
|
|
60
|
-
"@kubb/
|
|
61
|
-
"@kubb/core": "5.0.0-beta.5"
|
|
60
|
+
"@kubb/core": "5.0.0-beta.6"
|
|
62
61
|
},
|
|
63
62
|
"devDependencies": {
|
|
64
|
-
"@internals/
|
|
63
|
+
"@internals/shared": "0.0.0",
|
|
64
|
+
"@internals/utils": "0.0.0",
|
|
65
|
+
"@kubb/adapter-oas": "5.0.0-beta.6"
|
|
65
66
|
},
|
|
66
67
|
"peerDependencies": {
|
|
67
|
-
"@kubb/
|
|
68
|
-
"@kubb/
|
|
68
|
+
"@kubb/adapter-oas": "5.0.0-beta.6",
|
|
69
|
+
"@kubb/agent": "5.0.0-beta.6",
|
|
70
|
+
"@kubb/mcp": "5.0.0-beta.6"
|
|
69
71
|
},
|
|
70
72
|
"peerDependenciesMeta": {
|
|
73
|
+
"@kubb/adapter-oas": {
|
|
74
|
+
"optional": true
|
|
75
|
+
},
|
|
71
76
|
"@kubb/agent": {
|
|
72
77
|
"optional": true
|
|
73
78
|
},
|
|
@@ -4,26 +4,29 @@ import { agentDefaults } from '../../constants.ts'
|
|
|
4
4
|
|
|
5
5
|
export const command = defineCommand({
|
|
6
6
|
name: 'start',
|
|
7
|
-
description:
|
|
7
|
+
description:
|
|
8
|
+
'Start the Kubb Agent HTTP server. Exposes a REST API that accepts a kubb.config.ts patch and returns generated code as a stream. Use --allow-write to also write files to disk.',
|
|
9
|
+
examples: ['kubb agent start', 'kubb agent start --port 4000', 'kubb agent start --allow-write', 'kubb agent start --config ./kubb.config.ts --allow-all'],
|
|
8
10
|
options: {
|
|
9
11
|
config: {
|
|
10
12
|
type: 'string',
|
|
11
|
-
description: 'Path to the Kubb config',
|
|
13
|
+
description: 'Path to the Kubb config file',
|
|
12
14
|
short: 'c',
|
|
13
15
|
},
|
|
14
16
|
port: {
|
|
15
17
|
type: 'string',
|
|
16
|
-
description:
|
|
18
|
+
description: 'Port the HTTP server listens on',
|
|
17
19
|
short: 'p',
|
|
20
|
+
default: agentDefaults.port,
|
|
18
21
|
},
|
|
19
22
|
host: {
|
|
20
23
|
type: 'string',
|
|
21
|
-
description: '
|
|
24
|
+
description: 'Hostname the HTTP server binds to',
|
|
22
25
|
default: agentDefaults.host,
|
|
23
26
|
},
|
|
24
27
|
'allow-write': {
|
|
25
28
|
type: 'boolean',
|
|
26
|
-
description: '
|
|
29
|
+
description: 'Write generated files to the filesystem. When omitted, output is streamed only and no files are written.',
|
|
27
30
|
default: false,
|
|
28
31
|
},
|
|
29
32
|
'allow-all': {
|
package/src/commands/agent.ts
CHANGED
|
@@ -3,6 +3,8 @@ import { command as startCommand } from './agent/start.ts'
|
|
|
3
3
|
|
|
4
4
|
export const command = defineCommand({
|
|
5
5
|
name: 'agent',
|
|
6
|
-
description:
|
|
6
|
+
description:
|
|
7
|
+
'Manage the Kubb Agent — an HTTP server that lets AI agents trigger code generation programmatically via a REST API. Useful when an AI workflow needs to generate code without direct CLI access.',
|
|
8
|
+
examples: ['kubb agent start', 'kubb agent start --port 4000 --allow-write', 'kubb agent start --config ./kubb.config.ts --allow-all'],
|
|
7
9
|
subCommands: [startCommand],
|
|
8
10
|
})
|
package/src/commands/generate.ts
CHANGED
|
@@ -2,8 +2,10 @@ import { defineCommand } from '@internals/utils'
|
|
|
2
2
|
|
|
3
3
|
export const command = defineCommand({
|
|
4
4
|
name: 'generate',
|
|
5
|
-
description:
|
|
5
|
+
description:
|
|
6
|
+
'Generate TypeScript types, API clients, React Query hooks, Zod schemas, and more from an OpenAPI specification. Reads kubb.config.ts by default. Pass an OpenAPI file path as the first argument to override the input without editing the config.',
|
|
6
7
|
arguments: ['[input]'],
|
|
8
|
+
examples: ['kubb generate', 'kubb generate ./openapi.yaml', 'kubb generate --config kubb.config.ts', 'kubb generate --watch'],
|
|
7
9
|
options: {
|
|
8
10
|
config: {
|
|
9
11
|
type: 'string',
|
package/src/commands/init.ts
CHANGED
|
@@ -3,7 +3,14 @@ import { version } from '../../package.json'
|
|
|
3
3
|
|
|
4
4
|
export const command = defineCommand({
|
|
5
5
|
name: 'init',
|
|
6
|
-
description:
|
|
6
|
+
description:
|
|
7
|
+
'Scaffold a kubb.config.ts and install plugins for code generation from an OpenAPI spec. Run without flags for interactive setup, or pass --input, --output, and --plugins to skip the prompts.',
|
|
8
|
+
examples: [
|
|
9
|
+
'kubb init',
|
|
10
|
+
'kubb init --yes',
|
|
11
|
+
'kubb init --input ./openapi.yaml --output ./src/gen --plugins plugin-ts,plugin-zod',
|
|
12
|
+
'kubb init --plugins plugin-ts,plugin-client,plugin-react-query',
|
|
13
|
+
],
|
|
7
14
|
options: {
|
|
8
15
|
yes: {
|
|
9
16
|
type: 'boolean',
|
|
@@ -11,10 +18,34 @@ export const command = defineCommand({
|
|
|
11
18
|
short: 'y',
|
|
12
19
|
default: false,
|
|
13
20
|
},
|
|
21
|
+
input: {
|
|
22
|
+
type: 'string',
|
|
23
|
+
description: 'Path to the OpenAPI specification',
|
|
24
|
+
short: 'i',
|
|
25
|
+
hint: 'path',
|
|
26
|
+
},
|
|
27
|
+
output: {
|
|
28
|
+
type: 'string',
|
|
29
|
+
description: 'Output directory for generated files',
|
|
30
|
+
short: 'o',
|
|
31
|
+
hint: 'path',
|
|
32
|
+
},
|
|
33
|
+
plugins: {
|
|
34
|
+
type: 'string',
|
|
35
|
+
description:
|
|
36
|
+
'Comma-separated list of plugins to use (plugin-ts, plugin-client, plugin-react-query, plugin-vue-query, plugin-zod, plugin-faker, plugin-msw, plugin-cypress, plugin-mcp, plugin-redoc)',
|
|
37
|
+
hint: 'plugin-ts,plugin-zod,...',
|
|
38
|
+
},
|
|
14
39
|
},
|
|
15
40
|
async run({ values }) {
|
|
16
41
|
const { runInit } = await import('../runners/init.ts')
|
|
17
42
|
|
|
18
|
-
await runInit({
|
|
43
|
+
await runInit({
|
|
44
|
+
yes: values.yes,
|
|
45
|
+
version,
|
|
46
|
+
input: values.input,
|
|
47
|
+
output: values.output,
|
|
48
|
+
plugins: values.plugins,
|
|
49
|
+
})
|
|
19
50
|
},
|
|
20
51
|
})
|
package/src/commands/mcp.ts
CHANGED
|
@@ -3,10 +3,34 @@ import { version } from '../../package.json'
|
|
|
3
3
|
|
|
4
4
|
export const command = defineCommand({
|
|
5
5
|
name: 'mcp',
|
|
6
|
-
description:
|
|
7
|
-
|
|
6
|
+
description:
|
|
7
|
+
'Start a Model Context Protocol (MCP) server that exposes Kubb code generation as tools for AI assistants. Once running, configure your AI client (Claude, Cursor, Windsurf, etc.) to connect to it — the assistant can then call kubb generate directly without leaving the chat.',
|
|
8
|
+
examples: [
|
|
9
|
+
'kubb mcp',
|
|
10
|
+
'kubb mcp --port 3001',
|
|
11
|
+
'# Then add to your MCP client config:',
|
|
12
|
+
'# { "mcpServers": { "kubb": { "command": "npx", "args": ["kubb", "mcp"] } } }',
|
|
13
|
+
],
|
|
14
|
+
options: {
|
|
15
|
+
port: {
|
|
16
|
+
type: 'string',
|
|
17
|
+
short: 'p',
|
|
18
|
+
description: 'Port for HTTP MCP server (omit for stdio)',
|
|
19
|
+
hint: 'number',
|
|
20
|
+
},
|
|
21
|
+
host: {
|
|
22
|
+
type: 'string',
|
|
23
|
+
description: 'Hostname to bind to (HTTP mode only)',
|
|
24
|
+
default: 'localhost',
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
async run({ values }) {
|
|
8
28
|
const { runMcp } = await import('../runners/mcp.ts')
|
|
9
29
|
|
|
10
|
-
await runMcp({
|
|
30
|
+
await runMcp({
|
|
31
|
+
version,
|
|
32
|
+
port: values.port,
|
|
33
|
+
host: values.host,
|
|
34
|
+
})
|
|
11
35
|
},
|
|
12
36
|
})
|
package/src/commands/validate.ts
CHANGED
|
@@ -3,11 +3,13 @@ import { version } from '../../package.json'
|
|
|
3
3
|
|
|
4
4
|
export const command = defineCommand({
|
|
5
5
|
name: 'validate',
|
|
6
|
-
description:
|
|
6
|
+
description:
|
|
7
|
+
'Parse and validate an OpenAPI/Swagger file for structural correctness. Reports schema errors, missing required fields, and malformed references. Use this before running generate to catch spec issues early.',
|
|
8
|
+
examples: ['kubb validate --input ./openapi.yaml', 'kubb validate --input https://petstore3.swagger.io/api/v3/openapi.json'],
|
|
7
9
|
options: {
|
|
8
10
|
input: {
|
|
9
11
|
type: 'string',
|
|
10
|
-
description: 'Path to Swagger
|
|
12
|
+
description: 'Path or URL to the OpenAPI/Swagger file to validate',
|
|
11
13
|
short: 'i',
|
|
12
14
|
required: true,
|
|
13
15
|
},
|
package/src/constants.ts
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* Default filename for the Kubb configuration file.
|
|
3
|
-
*
|
|
4
|
-
* Used by the `init` command when scaffolding new projects and by the `agent` default config.
|
|
5
|
-
*/
|
|
6
|
-
export const KUBB_CONFIG_FILENAME = 'kubb.config.ts' as const
|
|
1
|
+
import { KUBB_CONFIG_FILENAME } from '@internals/shared'
|
|
7
2
|
|
|
8
3
|
/**
|
|
9
4
|
* NPM registry endpoint used to check for @kubb/cli updates.
|
|
@@ -52,53 +47,6 @@ export const agentDefaults = {
|
|
|
52
47
|
serverEntryPath: '.output/server/index.mjs',
|
|
53
48
|
} as const
|
|
54
49
|
|
|
55
|
-
/**
|
|
56
|
-
* Default values used during interactive `init` scaffolding.
|
|
57
|
-
*/
|
|
58
|
-
export const initDefaults = {
|
|
59
|
-
inputPath: './openapi.yaml',
|
|
60
|
-
outputPath: './src/gen',
|
|
61
|
-
plugins: ['plugin-ts'],
|
|
62
|
-
} as const
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Maps each plugin value to the default config snippet inserted by `init`.
|
|
66
|
-
* The `satisfies` constraint ensures all values remain plain strings while
|
|
67
|
-
* `as const` keeps the object deeply immutable.
|
|
68
|
-
*/
|
|
69
|
-
export const pluginDefaultConfigs = {
|
|
70
|
-
'plugin-ts': `pluginTs({
|
|
71
|
-
output: { path: 'models' },
|
|
72
|
-
})`,
|
|
73
|
-
'plugin-client': `pluginClient({
|
|
74
|
-
output: { path: 'clients' },
|
|
75
|
-
})`,
|
|
76
|
-
'plugin-react-query': `pluginReactQuery({
|
|
77
|
-
output: { path: 'hooks' },
|
|
78
|
-
})`,
|
|
79
|
-
'plugin-vue-query': `pluginVueQuery({
|
|
80
|
-
output: { path: 'hooks' },
|
|
81
|
-
})`,
|
|
82
|
-
'plugin-zod': `pluginZod({
|
|
83
|
-
output: { path: 'zod' },
|
|
84
|
-
})`,
|
|
85
|
-
'plugin-faker': `pluginFaker({
|
|
86
|
-
output: { path: 'mocks' },
|
|
87
|
-
})`,
|
|
88
|
-
'plugin-msw': `pluginMsw({
|
|
89
|
-
output: { path: 'msw' },
|
|
90
|
-
})`,
|
|
91
|
-
'plugin-cypress': `pluginCypress({
|
|
92
|
-
output: { path: 'cypress' },
|
|
93
|
-
})`,
|
|
94
|
-
'plugin-mcp': `pluginMcp({
|
|
95
|
-
output: { path: 'mcp' },
|
|
96
|
-
})`,
|
|
97
|
-
'plugin-redoc': `pluginRedoc({
|
|
98
|
-
output: { path: 'redoc' },
|
|
99
|
-
})`,
|
|
100
|
-
} as const satisfies Record<string, string>
|
|
101
|
-
|
|
102
50
|
/**
|
|
103
51
|
* Color palette used by randomCliColor() for deterministic plugin name coloring.
|
|
104
52
|
*/
|