@kubb/cli 5.0.0-beta.7 → 5.0.0-beta.70

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (133) hide show
  1. package/LICENSE +17 -10
  2. package/README.md +45 -77
  3. package/bin/kubb.js +9 -3
  4. package/dist/Telemetry-CfPP7MYq.cjs +321 -0
  5. package/dist/Telemetry-CfPP7MYq.cjs.map +1 -0
  6. package/dist/Telemetry-uAr3lK_-.js +284 -0
  7. package/dist/Telemetry-uAr3lK_-.js.map +1 -0
  8. package/dist/{define-Bdn8j5VM.cjs → defineCommand-Bo3yZTWI.cjs} +3 -21
  9. package/dist/defineCommand-Bo3yZTWI.cjs.map +1 -0
  10. package/dist/{define-m_fp-Aqm.js → defineCommand-DMEeqliP.js} +4 -16
  11. package/dist/defineCommand-DMEeqliP.js.map +1 -0
  12. package/dist/{errors-CINO1EIv.js → errors-Dc_d7BfX.js} +2 -2
  13. package/dist/{errors-CINO1EIv.js.map → errors-Dc_d7BfX.js.map} +1 -1
  14. package/dist/{errors-CLCjoSg0.cjs → errors-gxFK0vrp.cjs} +2 -2
  15. package/dist/{errors-CLCjoSg0.cjs.map → errors-gxFK0vrp.cjs.map} +1 -1
  16. package/dist/{generate-BY-juRdH.js → generate-BdxIouwm.js} +21 -16
  17. package/dist/generate-BdxIouwm.js.map +1 -0
  18. package/dist/{generate-Bod9YCbF.cjs → generate-tRupKbnI.cjs} +21 -16
  19. package/dist/generate-tRupKbnI.cjs.map +1 -0
  20. package/dist/index.cjs +34 -81
  21. package/dist/index.cjs.map +1 -1
  22. package/dist/index.d.ts +6 -1
  23. package/dist/index.js +34 -81
  24. package/dist/index.js.map +1 -1
  25. package/dist/{init-Cs3Fp6nN.js → init-D_9I495E.js} +5 -5
  26. package/dist/{init-Cs3Fp6nN.js.map → init-D_9I495E.js.map} +1 -1
  27. package/dist/{init-BIkZU6mB.cjs → init-XlS3aia7.cjs} +6 -6
  28. package/dist/{init-BIkZU6mB.cjs.map → init-XlS3aia7.cjs.map} +1 -1
  29. package/dist/mcp-BlKi3z04.js +21 -0
  30. package/dist/mcp-BlKi3z04.js.map +1 -0
  31. package/dist/mcp-DSo5Ccwz.cjs +21 -0
  32. package/dist/mcp-DSo5Ccwz.cjs.map +1 -0
  33. package/dist/package-CsDaFmfZ.js +6 -0
  34. package/dist/package-CsDaFmfZ.js.map +1 -0
  35. package/dist/{package-DrUndPET.cjs → package-HWZRLSO4.cjs} +2 -2
  36. package/dist/package-HWZRLSO4.cjs.map +1 -0
  37. package/dist/{chunk-BvFE5Tac.js → rolldown-runtime-C0LytTxp.js} +0 -1
  38. package/dist/{run-YsoCk5we.cjs → run-AYlRjIX5.cjs} +136 -98
  39. package/dist/run-AYlRjIX5.cjs.map +1 -0
  40. package/dist/run-BM1t8CSM.cjs +33 -0
  41. package/dist/run-BM1t8CSM.cjs.map +1 -0
  42. package/dist/run-BlFVmIJl.js +32 -0
  43. package/dist/run-BlFVmIJl.js.map +1 -0
  44. package/dist/{run-CQbj3ley.cjs → run-CBc896in.cjs} +6 -6
  45. package/dist/run-CBc896in.cjs.map +1 -0
  46. package/dist/{run-CF97BWVa.js → run-D9mQoQHA.js} +123 -85
  47. package/dist/run-D9mQoQHA.js.map +1 -0
  48. package/dist/{run-CCZ24VKk.js → run-D_dWNFhX.js} +5 -5
  49. package/dist/run-D_dWNFhX.js.map +1 -0
  50. package/dist/run-DwylXpzM.cjs +1380 -0
  51. package/dist/run-DwylXpzM.cjs.map +1 -0
  52. package/dist/run-KlHwxNTr.js +1377 -0
  53. package/dist/run-KlHwxNTr.js.map +1 -0
  54. package/dist/tools-CZT9wSA6.cjs +175 -0
  55. package/dist/tools-CZT9wSA6.cjs.map +1 -0
  56. package/dist/tools-D0UogMU3.js +152 -0
  57. package/dist/tools-D0UogMU3.js.map +1 -0
  58. package/dist/{validate-Bfpf_UIh.cjs → validate-3gu3yglv.cjs} +6 -6
  59. package/dist/{validate-Bfpf_UIh.cjs.map → validate-3gu3yglv.cjs.map} +1 -1
  60. package/dist/{validate-lbUkWQ5o.js → validate-DBqdV14W.js} +5 -5
  61. package/dist/{validate-lbUkWQ5o.js.map → validate-DBqdV14W.js.map} +1 -1
  62. package/package.json +13 -25
  63. package/dist/agent-DN7o8nlE.js +0 -68
  64. package/dist/agent-DN7o8nlE.js.map +0 -1
  65. package/dist/agent-Fm9_8BBH.cjs +0 -70
  66. package/dist/agent-Fm9_8BBH.cjs.map +0 -1
  67. package/dist/constants-B2JTeRBb.js +0 -42
  68. package/dist/constants-B2JTeRBb.js.map +0 -1
  69. package/dist/constants-BINTA5VZ.cjs +0 -77
  70. package/dist/constants-BINTA5VZ.cjs.map +0 -1
  71. package/dist/constants-BYGmiFs0.cjs +0 -139
  72. package/dist/constants-BYGmiFs0.cjs.map +0 -1
  73. package/dist/constants-DSJ-Xrbv.js +0 -116
  74. package/dist/constants-DSJ-Xrbv.js.map +0 -1
  75. package/dist/define-Bdn8j5VM.cjs.map +0 -1
  76. package/dist/define-m_fp-Aqm.js.map +0 -1
  77. package/dist/generate-BY-juRdH.js.map +0 -1
  78. package/dist/generate-Bod9YCbF.cjs.map +0 -1
  79. package/dist/mcp-BSNulBcC.js +0 -39
  80. package/dist/mcp-BSNulBcC.js.map +0 -1
  81. package/dist/mcp-DcSrFhhP.cjs +0 -39
  82. package/dist/mcp-DcSrFhhP.cjs.map +0 -1
  83. package/dist/package-D5wmvFl4.js +0 -6
  84. package/dist/package-D5wmvFl4.js.map +0 -1
  85. package/dist/package-DrUndPET.cjs.map +0 -1
  86. package/dist/run-BAJubgdA.js +0 -1735
  87. package/dist/run-BAJubgdA.js.map +0 -1
  88. package/dist/run-BzpYYOQs.js +0 -121
  89. package/dist/run-BzpYYOQs.js.map +0 -1
  90. package/dist/run-CCZ24VKk.js.map +0 -1
  91. package/dist/run-CF97BWVa.js.map +0 -1
  92. package/dist/run-CQbj3ley.cjs.map +0 -1
  93. package/dist/run-CqKd6JNc.cjs +0 -1738
  94. package/dist/run-CqKd6JNc.cjs.map +0 -1
  95. package/dist/run-D0hmRpHy.js +0 -49
  96. package/dist/run-D0hmRpHy.js.map +0 -1
  97. package/dist/run-DwdAwnLG.cjs +0 -125
  98. package/dist/run-DwdAwnLG.cjs.map +0 -1
  99. package/dist/run-Lr0Ctnu0.cjs +0 -50
  100. package/dist/run-Lr0Ctnu0.cjs.map +0 -1
  101. package/dist/run-YsoCk5we.cjs.map +0 -1
  102. package/dist/shell-475fQKaX.cjs +0 -62
  103. package/dist/shell-475fQKaX.cjs.map +0 -1
  104. package/dist/shell-CN6DNqeC.js +0 -51
  105. package/dist/shell-CN6DNqeC.js.map +0 -1
  106. package/dist/telemetry-B2iWkY5e.cjs +0 -280
  107. package/dist/telemetry-B2iWkY5e.cjs.map +0 -1
  108. package/dist/telemetry-BkektVz6.js +0 -243
  109. package/dist/telemetry-BkektVz6.js.map +0 -1
  110. package/src/commands/agent/start.ts +0 -50
  111. package/src/commands/agent.ts +0 -10
  112. package/src/commands/generate.ts +0 -59
  113. package/src/commands/init.ts +0 -51
  114. package/src/commands/mcp.ts +0 -36
  115. package/src/commands/validate.ts +0 -22
  116. package/src/constants.ts +0 -48
  117. package/src/index.ts +0 -45
  118. package/src/loggers/clackLogger.ts +0 -460
  119. package/src/loggers/fileSystemLogger.ts +0 -148
  120. package/src/loggers/githubActionsLogger.ts +0 -367
  121. package/src/loggers/plainLogger.ts +0 -243
  122. package/src/loggers/types.ts +0 -7
  123. package/src/loggers/utils.ts +0 -252
  124. package/src/runners/agent/run.ts +0 -113
  125. package/src/runners/agent/utils.ts +0 -98
  126. package/src/runners/generate/run.ts +0 -276
  127. package/src/runners/generate/utils.ts +0 -209
  128. package/src/runners/init/run.ts +0 -211
  129. package/src/runners/init/utils.ts +0 -33
  130. package/src/runners/mcp/run.ts +0 -55
  131. package/src/runners/validate/run.ts +0 -63
  132. package/src/telemetry.ts +0 -280
  133. /package/dist/{chunk-ByKO4r7w.cjs → rolldown-runtime-Bx3C2hgW.cjs} +0 -0
@@ -1,33 +0,0 @@
1
- import fs from 'node:fs'
2
- import path from 'node:path'
3
- import process from 'node:process'
4
- import type { PackageManagerInfo, PackageManagerName } from '@internals/utils'
5
- import { spawnAsync } from '@internals/utils'
6
-
7
- /**
8
- * Returns `true` when a `package.json` exists at `cwd`.
9
- */
10
- export function hasPackageJson(cwd: string = process.cwd()): boolean {
11
- return fs.existsSync(path.join(cwd, 'package.json'))
12
- }
13
-
14
- /**
15
- * Initializes a new `package.json` at `cwd` using the detected package manager.
16
- */
17
- export async function initPackageJson(cwd: string, packageManager: PackageManagerInfo): Promise<void> {
18
- const commands: Record<PackageManagerName, string[]> = {
19
- npm: ['init', '-y'],
20
- pnpm: ['init'],
21
- yarn: ['init', '-y'],
22
- bun: ['init', '-y'],
23
- }
24
-
25
- await spawnAsync(packageManager.name, commands[packageManager.name], { cwd })
26
- }
27
-
28
- /**
29
- * Installs the given packages at `cwd` using the detected package manager.
30
- */
31
- export async function installPackages(packages: string[], packageManager: PackageManagerInfo, cwd: string = process.cwd()): Promise<void> {
32
- await spawnAsync(packageManager.name, [...packageManager.installCommand, ...packages], { cwd })
33
- }
@@ -1,55 +0,0 @@
1
- import process from 'node:process'
2
- import { styleText } from 'node:util'
3
- import { getErrorMessage } from '@internals/utils'
4
- import type * as McpModule from '@kubb/mcp'
5
- import { buildTelemetryEvent, sendTelemetry } from '../../telemetry.ts'
6
-
7
- type McpOptions = {
8
- /**
9
- * Current `@kubb/cli` version string, used for the telemetry payload.
10
- */
11
- version: string
12
- /**
13
- * TCP port for the HTTP MCP server. When `undefined`, the server uses stdio transport.
14
- */
15
- port?: string
16
- /**
17
- * Hostname to bind to when running in HTTP mode.
18
- *
19
- * @default 'localhost'
20
- */
21
- host?: string
22
- }
23
-
24
- /**
25
- * Starts the Kubb MCP server using `@kubb/mcp`.
26
- * Exits the process with code 1 if `@kubb/mcp` is not installed.
27
- */
28
- export async function run({ version, port, host }: McpOptions): Promise<void> {
29
- let mod: typeof McpModule
30
- try {
31
- mod = (await import('@kubb/mcp')) as typeof McpModule
32
- } catch (_e) {
33
- console.error(styleText('red', 'The @kubb/mcp package is not installed.'))
34
- console.error('')
35
- console.error('Install it with:')
36
- console.error(styleText('cyan', ' npm install @kubb/mcp'))
37
- console.error(styleText('cyan', ' # or'))
38
- console.error(styleText('cyan', ' pnpm install @kubb/mcp'))
39
- console.error('')
40
- process.exit(1)
41
- }
42
-
43
- const { run: startMcpServer } = mod
44
- const hrStart = process.hrtime()
45
- const report = (status: 'success' | 'failed') => sendTelemetry(buildTelemetryEvent({ command: 'mcp', kubbVersion: version, hrStart, status }))
46
- try {
47
- console.log(styleText('cyan', '⏳ Starting MCP server...'))
48
- console.warn(styleText('yellow', 'This feature is still under development, use with caution'))
49
- await startMcpServer(undefined, { port: port !== undefined ? Number(port) : undefined, host })
50
- await report('success')
51
- } catch (error) {
52
- await report('failed')
53
- console.error(getErrorMessage(error))
54
- }
55
- }
@@ -1,63 +0,0 @@
1
- import process from 'node:process'
2
- import { styleText } from 'node:util'
3
- import { getErrorMessage } from '@internals/utils'
4
- import { buildTelemetryEvent, sendTelemetry } from '../../telemetry.ts'
5
-
6
- type ValidateOptions = {
7
- /**
8
- * Path or URL to the OpenAPI/Swagger file to validate.
9
- */
10
- input: string
11
- /**
12
- * Current `@kubb/cli` version string, used for the telemetry payload.
13
- */
14
- version: string
15
- }
16
-
17
- type ValidateModule = typeof import('@kubb/adapter-oas')
18
- type ValidateDependencies = {
19
- /**
20
- * Loads `@kubb/adapter-oas`. Injected so tests can substitute a mock.
21
- */
22
- loadValidateModule: () => Promise<ValidateModule>
23
- }
24
-
25
- /**
26
- * Dynamically loads `@kubb/adapter-oas` for OpenAPI validation.
27
- */
28
- export function loadValidateModule(): Promise<ValidateModule> {
29
- return import('@kubb/adapter-oas') as Promise<ValidateModule>
30
- }
31
-
32
- /**
33
- * Validates an OpenAPI/Swagger file at `input` using `@kubb/adapter-oas`.
34
- * Exits the process with code 1 on validation failure or missing dependency.
35
- */
36
- export async function run({ input, version }: ValidateOptions, dependencies: ValidateDependencies = { loadValidateModule }): Promise<void> {
37
- const hrStart = process.hrtime()
38
- const report = (status: 'success' | 'failed') => sendTelemetry(buildTelemetryEvent({ command: 'validate', kubbVersion: version, hrStart, status }))
39
- try {
40
- const { adapterOas } = await dependencies.loadValidateModule()
41
- const adapter = adapterOas()
42
- if (!adapter.validate) {
43
- throw new Error('The loaded adapter does not support validation.')
44
- }
45
- await adapter.validate(input, { throwOnError: true })
46
- await report('success')
47
- console.log('✅ Validation success')
48
- } catch (error) {
49
- await report('failed')
50
- if (error instanceof Error && /@kubb\/adapter-oas/.test(error.message)) {
51
- console.error(styleText('red', 'The @kubb/adapter-oas package is not installed.'))
52
- console.error('')
53
- console.error('Install it with:')
54
- console.error(styleText('cyan', ' npm install @kubb/adapter-oas'))
55
- console.error(styleText('cyan', ' # or'))
56
- console.error(styleText('cyan', ' pnpm install @kubb/adapter-oas'))
57
- console.error('')
58
- }
59
- console.error('❌ Validation failed')
60
- console.error(getErrorMessage(error))
61
- process.exit(1)
62
- }
63
- }
package/src/telemetry.ts DELETED
@@ -1,280 +0,0 @@
1
- import { randomBytes } from 'node:crypto'
2
- import os from 'node:os'
3
- import process from 'node:process'
4
- import { executeIfOnline, isCIEnvironment } from '@internals/utils'
5
- import { OTLP_ENDPOINT } from './constants.ts'
6
-
7
- // OpenTelemetry OTLP JSON types
8
- // https://github.com/open-telemetry/opentelemetry-proto/blob/main/opentelemetry/proto/trace/v1/trace.proto
9
- // https://github.com/open-telemetry/opentelemetry-proto/blob/main/opentelemetry/proto/common/v1/common.proto
10
-
11
- type OtlpStringValue = { stringValue: string }
12
- type OtlpBoolValue = { boolValue: boolean }
13
- type OtlpIntValue = { intValue: number }
14
- type OtlpDoubleValue = { doubleValue: number }
15
- type OtlpBytesValue = { bytesValue: string }
16
- type OtlpArrayValue = { arrayValue: { values: OtlpAnyValue[] } }
17
- type OtlpKvListValue = { kvlistValue: { values: OtlpKeyValue[] } }
18
-
19
- type OtlpAnyValue = OtlpStringValue | OtlpBoolValue | OtlpIntValue | OtlpDoubleValue | OtlpBytesValue | OtlpArrayValue | OtlpKvListValue
20
-
21
- type OtlpKeyValue = {
22
- key: string
23
- value: OtlpAnyValue
24
- }
25
-
26
- type OtlpResource = {
27
- attributes: OtlpKeyValue[]
28
- droppedAttributesCount?: number
29
- }
30
-
31
- type OtlpInstrumentationScope = {
32
- name: string
33
- version?: string
34
- attributes?: OtlpKeyValue[]
35
- droppedAttributesCount?: number
36
- }
37
-
38
- /** https://github.com/open-telemetry/opentelemetry-proto/blob/main/opentelemetry/proto/trace/v1/trace.proto#L103 */
39
- type OtlpSpanKind = 0 | 1 | 2 | 3 | 4 | 5
40
-
41
- /** 0 = STATUS_CODE_UNSET, 1 = STATUS_CODE_OK, 2 = STATUS_CODE_ERROR */
42
- type OtlpStatusCode = 0 | 1 | 2
43
-
44
- type OtlpStatus = {
45
- code: OtlpStatusCode
46
- message?: string
47
- }
48
-
49
- type OtlpSpan = {
50
- traceId: string
51
- spanId: string
52
- traceState?: string
53
- parentSpanId?: string
54
- name: string
55
- kind: OtlpSpanKind
56
- startTimeUnixNano: string
57
- endTimeUnixNano: string
58
- attributes?: OtlpKeyValue[]
59
- droppedAttributesCount?: number
60
- events?: OtlpSpanEvent[]
61
- droppedEventsCount?: number
62
- links?: OtlpSpanLink[]
63
- droppedLinksCount?: number
64
- status?: OtlpStatus
65
- }
66
-
67
- type OtlpSpanEvent = {
68
- timeUnixNano: string
69
- name: string
70
- attributes?: OtlpKeyValue[]
71
- droppedAttributesCount?: number
72
- }
73
-
74
- type OtlpSpanLink = {
75
- traceId: string
76
- spanId: string
77
- traceState?: string
78
- attributes?: OtlpKeyValue[]
79
- droppedAttributesCount?: number
80
- }
81
-
82
- type OtlpScopeSpans = {
83
- scope: OtlpInstrumentationScope
84
- spans: OtlpSpan[]
85
- schemaUrl?: string
86
- }
87
-
88
- type OtlpResourceSpans = {
89
- resource: OtlpResource
90
- scopeSpans: OtlpScopeSpans[]
91
- schemaUrl?: string
92
- }
93
-
94
- /** Root payload sent to POST /v1/traces */
95
- type OtlpExportTraceServiceRequest = {
96
- resourceSpans: OtlpResourceSpans[]
97
- }
98
-
99
- /**
100
- * Anonymous plugin name and options snapshot sent with each telemetry event.
101
- */
102
- export type TelemetryPlugin = {
103
- /**
104
- * Plugin name as registered in the Kubb config, e.g. `'@kubb/plugin-ts'`.
105
- */
106
- name: string
107
- /**
108
- * anonymized plugin options snapshot — values are included but cannot be traced back to the user.
109
- */
110
- options: Record<string, unknown>
111
- }
112
-
113
- type TelemetryEvent = {
114
- command: string
115
- kubbVersion: string
116
- nodeVersion: string
117
- platform: string
118
- ci: boolean
119
- plugins: TelemetryPlugin[]
120
- duration: number
121
- filesCreated: number
122
- status: 'success' | 'failed'
123
- }
124
-
125
- /**
126
- * Returns `true` when the current process runs inside a CI environment.
127
- */
128
- export function isCi(): boolean {
129
- return isCIEnvironment()
130
- }
131
-
132
- /**
133
- * Returns `true` when telemetry is disabled via `DO_NOT_TRACK` or `KUBB_DISABLE_TELEMETRY`.
134
- */
135
- export function isTelemetryDisabled(): boolean {
136
- return (
137
- process.env['DO_NOT_TRACK'] === '1' ||
138
- process.env['DO_NOT_TRACK'] === 'true' ||
139
- process.env['KUBB_DISABLE_TELEMETRY'] === '1' ||
140
- process.env['KUBB_DISABLE_TELEMETRY'] === 'true'
141
- )
142
- }
143
-
144
- /**
145
- * Convert a TelemetryEvent into an OTLP-compatible JSON trace payload.
146
- * See https://opentelemetry.io/docs/languages/sdk-configuration/otlp-exporter/
147
- */
148
- export function buildOtlpPayload(event: TelemetryEvent): OtlpExportTraceServiceRequest {
149
- const traceId = randomBytes(16).toString('hex')
150
- const spanId = randomBytes(8).toString('hex')
151
- const endTimeNs = BigInt(Date.now()) * 1_000_000n
152
- const startTimeNs = endTimeNs - BigInt(event.duration) * 1_000_000n
153
-
154
- const attributes: OtlpKeyValue[] = [
155
- { key: 'kubb.command', value: { stringValue: event.command } },
156
- { key: 'kubb.version', value: { stringValue: event.kubbVersion } },
157
- { key: 'kubb.node_version', value: { stringValue: event.nodeVersion } },
158
- { key: 'kubb.platform', value: { stringValue: event.platform } },
159
- { key: 'kubb.ci', value: { boolValue: event.ci } },
160
- { key: 'kubb.files_created', value: { intValue: event.filesCreated } },
161
- { key: 'kubb.status', value: { stringValue: event.status } },
162
- {
163
- key: 'kubb.plugins',
164
- value: {
165
- arrayValue: {
166
- values: event.plugins.map(
167
- (p): OtlpKvListValue => ({
168
- kvlistValue: {
169
- values: [
170
- { key: 'name', value: { stringValue: p.name } },
171
- {
172
- key: 'options',
173
- value: {
174
- stringValue: JSON.stringify({
175
- ...p.options,
176
- usedEnumNames: undefined,
177
- }),
178
- },
179
- },
180
- ],
181
- },
182
- }),
183
- ),
184
- },
185
- },
186
- },
187
- ]
188
-
189
- return {
190
- resourceSpans: [
191
- {
192
- resource: {
193
- attributes: [
194
- { key: 'service.name', value: { stringValue: 'kubb-cli' } },
195
- {
196
- key: 'service.version',
197
- value: { stringValue: event.kubbVersion },
198
- },
199
- { key: 'telemetry.sdk.language', value: { stringValue: 'nodejs' } },
200
- ],
201
- },
202
- scopeSpans: [
203
- {
204
- scope: { name: 'kubb-cli', version: event.kubbVersion },
205
- spans: [
206
- {
207
- traceId,
208
- spanId,
209
- name: event.command,
210
- kind: 1 satisfies OtlpSpanKind,
211
- startTimeUnixNano: String(startTimeNs),
212
- endTimeUnixNano: String(endTimeNs),
213
- attributes,
214
- status: {
215
- code: (event.status === 'success' ? 1 : 2) satisfies OtlpStatusCode,
216
- },
217
- },
218
- ],
219
- },
220
- ],
221
- },
222
- ],
223
- }
224
- }
225
-
226
- /**
227
- * Send an anonymous telemetry event to the Kubb OTLP endpoint.
228
- * Respects DO_NOT_TRACK and KUBB_DISABLE_TELEMETRY environment variables.
229
- * Fails silently to never interrupt the generation process.
230
- */
231
- export async function sendTelemetry(event: TelemetryEvent): Promise<void> {
232
- if (isTelemetryDisabled()) {
233
- return
234
- }
235
-
236
- await executeIfOnline(async () => {
237
- try {
238
- await fetch(`${OTLP_ENDPOINT}/v1/traces`, {
239
- method: 'POST',
240
- headers: {
241
- 'Content-Type': 'application/json',
242
- 'Kubb-Telemetry-Version': '1',
243
- 'Kubb-Telemetry-Source': 'kubb-cli',
244
- },
245
- body: JSON.stringify(buildOtlpPayload(event)),
246
- signal: AbortSignal.timeout(5_000),
247
- })
248
- } catch (_e) {
249
- // Fail silently – telemetry must never break the CLI
250
- }
251
- })
252
- }
253
-
254
- /**
255
- * Build an anonymous telemetry payload from a completed generation run.
256
- * No file paths, OpenAPI specs, or secrets are included.
257
- */
258
- export function buildTelemetryEvent(options: {
259
- command: 'generate' | 'mcp' | 'validate' | 'agent'
260
- kubbVersion: string
261
- plugins?: TelemetryPlugin[]
262
- hrStart: [number, number]
263
- filesCreated?: number
264
- status: 'success' | 'failed'
265
- }): TelemetryEvent {
266
- const [seconds, nanoseconds] = process.hrtime(options.hrStart)
267
- const duration = Math.round(seconds * 1000 + nanoseconds / 1e6)
268
-
269
- return {
270
- command: options.command,
271
- kubbVersion: options.kubbVersion,
272
- nodeVersion: process.versions.node.split('.')[0] as string,
273
- platform: os.platform(),
274
- ci: isCi(),
275
- plugins: options.plugins ?? [],
276
- duration,
277
- filesCreated: options.filesCreated ?? 0,
278
- status: options.status,
279
- }
280
- }