@kivacore/ui-cli 0.26.4 → 0.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -145
- package/dist/cli.js +156 -1350
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +3 -74
- package/dist/index.js +1 -746
- package/dist/index.js.map +1 -1
- package/package.json +6 -9
package/dist/cli.js
CHANGED
|
@@ -1,867 +1,16 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { Command } from 'commander';
|
|
3
|
-
import { RestApiClient, AuthenticationError as AuthenticationError$1 } from '@kivacore/api-client';
|
|
4
|
-
import { createServer } from 'http';
|
|
5
|
-
import { URL as URL$1 } from 'url';
|
|
6
|
-
import { randomBytes, createDecipheriv, createCipheriv, scryptSync, createHash } from 'crypto';
|
|
7
|
-
import open from 'open';
|
|
8
|
-
import { existsSync, readFileSync, writeFileSync, mkdirSync, renameSync, statSync, readdirSync, rmSync, unlinkSync } from 'fs';
|
|
9
|
-
import { join, relative, resolve, dirname } from 'path';
|
|
10
|
-
import { homedir, arch, release, platform, hostname, userInfo } from 'os';
|
|
11
|
-
import Conf from 'conf';
|
|
12
|
-
import chalk4 from 'chalk';
|
|
13
|
-
import ora from 'ora';
|
|
14
|
-
import { confirm, select, checkbox, input, password } from '@inquirer/prompts';
|
|
15
|
-
import { generateFromOpenAPI } from '@kivacore/tanstack-db-generator';
|
|
16
|
-
import { readFile, mkdir, writeFile, chmod } from 'fs/promises';
|
|
17
3
|
import { exec, execFileSync } from 'child_process';
|
|
18
4
|
import { promisify } from 'util';
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
function joinRegistryPath(baseUrl, segment) {
|
|
30
|
-
return `${trimTrailingSlashes(baseUrl)}/${segment.replace(/^\/+/, "")}`;
|
|
31
|
-
}
|
|
32
|
-
function resolveThemesApiUrl(registryBaseUrl) {
|
|
33
|
-
const normalized = trimTrailingSlashes(registryBaseUrl);
|
|
34
|
-
if (normalized.endsWith("/r")) {
|
|
35
|
-
return `${normalized.slice(0, -2)}/api/themes`;
|
|
36
|
-
}
|
|
37
|
-
return `${normalized}/api/themes`;
|
|
38
|
-
}
|
|
39
|
-
var KIVA_API_URL = "https://alpha-api.docyrus.com";
|
|
40
|
-
var OAUTH_CLIENT_ID = "90565525-8283-4881-82a9-8613eb82ae27";
|
|
41
|
-
var OAUTH_SCOPES = "offline_access Read.All Users.Read Users.Read.All DS.Read.All".split(" ");
|
|
42
|
-
var OAUTH_CALLBACK_PORT_MIN = 9876;
|
|
43
|
-
var OAUTH_CALLBACK_PORT_MAX = 9899;
|
|
44
|
-
var OAUTH_REDIRECT_URI = (port) => `http://localhost:${port}/callback`;
|
|
45
|
-
var OAUTH_TIMEOUT_MS = 5 * 60 * 1e3;
|
|
46
|
-
var KEYCHAIN_SERVICE = "docyrus-cli";
|
|
47
|
-
var CONFIG_DIR = ".docyrus";
|
|
48
|
-
var CONFIG_PROJECT_NAME = "docyrus";
|
|
49
|
-
var CREDENTIALS_FILE = "credentials.enc";
|
|
50
|
-
var TOKEN_KEYS = {
|
|
51
|
-
ACCESS_TOKEN: "accessToken",
|
|
52
|
-
REFRESH_TOKEN: "refreshToken",
|
|
53
|
-
USER_EMAIL: "userEmail",
|
|
54
|
-
GITHUB_TOKEN: "githubToken"
|
|
55
|
-
// For private template access - persists after logout
|
|
56
|
-
};
|
|
57
|
-
var REGISTRY_BASE_URL = withFallback(process.env.KIVA_REGISTRY_URL, DEFAULT_REGISTRY_BASE_URL);
|
|
58
|
-
var SHADCN_REGISTRY_URL = withFallback(
|
|
59
|
-
process.env.KIVA_SHADCN_REGISTRY_URL,
|
|
60
|
-
joinRegistryPath(REGISTRY_BASE_URL, "shadcn")
|
|
61
|
-
);
|
|
62
|
-
var PLATE_REGISTRY_URL = withFallback(
|
|
63
|
-
process.env.KIVA_PLATE_REGISTRY_URL,
|
|
64
|
-
joinRegistryPath(REGISTRY_BASE_URL, "plate")
|
|
65
|
-
);
|
|
66
|
-
var AI_ELEMENTS_REGISTRY_URL = withFallback(
|
|
67
|
-
process.env.KIVA_AI_ELEMENTS_REGISTRY_URL,
|
|
68
|
-
joinRegistryPath(REGISTRY_BASE_URL, "ai-elements")
|
|
69
|
-
);
|
|
70
|
-
var THEMES_API_URL = resolveThemesApiUrl(REGISTRY_BASE_URL);
|
|
71
|
-
var CLI_NAME = "kiva-ui";
|
|
72
|
-
var CLI_FUNCTION_NAME = "kiva_ui";
|
|
73
|
-
var CLI_VERSION = "0.26.0";
|
|
74
|
-
var NPM_PACKAGE_NAME = "@kivacore/ui-cli";
|
|
75
|
-
|
|
76
|
-
// src/utils/errors.ts
|
|
77
|
-
var CliError = class extends Error {
|
|
78
|
-
exitCode;
|
|
79
|
-
suggestion;
|
|
80
|
-
constructor(message, exitCode = 1, suggestion) {
|
|
81
|
-
super(message);
|
|
82
|
-
this.name = "CliError";
|
|
83
|
-
this.exitCode = exitCode;
|
|
84
|
-
this.suggestion = suggestion;
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
var AuthenticationError = class extends CliError {
|
|
88
|
-
constructor(message = "Authentication failed", suggestion) {
|
|
89
|
-
super(message, 1, suggestion || "Please check your credentials and try again.");
|
|
90
|
-
this.name = "AuthenticationError";
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
var NotLoggedInError = class extends CliError {
|
|
94
|
-
constructor(message = "You are not logged in.") {
|
|
95
|
-
super(message, 1, "Run `kiva-ui login` to authenticate.");
|
|
96
|
-
this.name = "NotLoggedInError";
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
var NetworkError = class extends CliError {
|
|
100
|
-
constructor(message = "Network request failed", suggestion) {
|
|
101
|
-
super(message, 1, suggestion || "Please check your internet connection and try again.");
|
|
102
|
-
this.name = "NetworkError";
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
var TimeoutError = class extends CliError {
|
|
106
|
-
constructor(message = "Operation timed out") {
|
|
107
|
-
super(message, 1, "Please try again.");
|
|
108
|
-
this.name = "TimeoutError";
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
var OAuthError = class extends CliError {
|
|
112
|
-
constructor(message, suggestion) {
|
|
113
|
-
super(message, 1, suggestion || "Please try again or use email/password login.");
|
|
114
|
-
this.name = "OAuthError";
|
|
115
|
-
}
|
|
116
|
-
};
|
|
117
|
-
var ComponentNotFoundError = class extends CliError {
|
|
118
|
-
constructor(name) {
|
|
119
|
-
super(
|
|
120
|
-
`"${name}" not found in the registry.`,
|
|
121
|
-
1,
|
|
122
|
-
"Check the name and try again. Run `kiva-ui add --help` for usage."
|
|
123
|
-
);
|
|
124
|
-
this.name = "ComponentNotFoundError";
|
|
125
|
-
}
|
|
126
|
-
};
|
|
127
|
-
var PremiumAuthError = class extends CliError {
|
|
128
|
-
constructor(name) {
|
|
129
|
-
super(
|
|
130
|
-
`"${name}" is a premium component. Authentication required.`,
|
|
131
|
-
1,
|
|
132
|
-
"Run `kiva-ui login` to authenticate, then try again."
|
|
133
|
-
);
|
|
134
|
-
this.name = "PremiumAuthError";
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
var MissingConfigError = class extends CliError {
|
|
138
|
-
constructor() {
|
|
139
|
-
super(
|
|
140
|
-
"components.json not found.",
|
|
141
|
-
1,
|
|
142
|
-
"Run `npx shadcn@latest init` first to initialize your project."
|
|
143
|
-
);
|
|
144
|
-
this.name = "MissingConfigError";
|
|
145
|
-
}
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
// src/auth/credential-auth.ts
|
|
149
|
-
function getApiClient() {
|
|
150
|
-
return new RestApiClient({ baseURL: KIVA_API_URL });
|
|
151
|
-
}
|
|
152
|
-
async function loginWithCredentials(credentials) {
|
|
153
|
-
const client = getApiClient();
|
|
154
|
-
try {
|
|
155
|
-
const response = await client.post("/v1/auth/token", {
|
|
156
|
-
email: credentials.email,
|
|
157
|
-
password: credentials.password
|
|
158
|
-
});
|
|
159
|
-
const tokens = {
|
|
160
|
-
accessToken: response.data.access_token,
|
|
161
|
-
refreshToken: response.data.refresh_token,
|
|
162
|
-
expiresIn: response.data.expires_in
|
|
163
|
-
};
|
|
164
|
-
if (tokens.expiresIn) {
|
|
165
|
-
tokens.expiresAt = Date.now() + tokens.expiresIn * 1e3;
|
|
166
|
-
}
|
|
167
|
-
return {
|
|
168
|
-
tokens,
|
|
169
|
-
user: response.data.user
|
|
170
|
-
};
|
|
171
|
-
} catch (error) {
|
|
172
|
-
if (error instanceof AuthenticationError$1) {
|
|
173
|
-
throw new AuthenticationError("Invalid email or password.");
|
|
174
|
-
}
|
|
175
|
-
if (error instanceof Error && error.message.includes("fetch")) {
|
|
176
|
-
throw new NetworkError();
|
|
177
|
-
}
|
|
178
|
-
throw error;
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
async function getUserInfo(accessToken) {
|
|
182
|
-
const client = new RestApiClient({ baseURL: KIVA_API_URL });
|
|
183
|
-
await client.setAccessToken(accessToken);
|
|
184
|
-
try {
|
|
185
|
-
const response = await client.get("/v1/users/me");
|
|
186
|
-
return response.data;
|
|
187
|
-
} catch (error) {
|
|
188
|
-
if (error instanceof AuthenticationError$1) {
|
|
189
|
-
throw new AuthenticationError("Session expired. Please log in again.");
|
|
190
|
-
}
|
|
191
|
-
throw error;
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
async function refreshAccessToken(refreshToken) {
|
|
195
|
-
const tokenUrl = `${KIVA_API_URL}/v1/oauth2/token`;
|
|
196
|
-
try {
|
|
197
|
-
const response = await fetch(tokenUrl, {
|
|
198
|
-
method: "POST",
|
|
199
|
-
headers: {
|
|
200
|
-
"Content-Type": "application/x-www-form-urlencoded"
|
|
201
|
-
},
|
|
202
|
-
body: new URLSearchParams({
|
|
203
|
-
grant_type: "refresh_token",
|
|
204
|
-
client_id: OAUTH_CLIENT_ID,
|
|
205
|
-
refresh_token: refreshToken
|
|
206
|
-
}).toString()
|
|
207
|
-
});
|
|
208
|
-
if (!response.ok) {
|
|
209
|
-
const errorData = await response.json().catch(() => ({}));
|
|
210
|
-
throw new AuthenticationError(
|
|
211
|
-
errorData.error_description || "Failed to refresh token"
|
|
212
|
-
);
|
|
213
|
-
}
|
|
214
|
-
const data = await response.json();
|
|
215
|
-
const tokens = {
|
|
216
|
-
accessToken: data.access_token,
|
|
217
|
-
refreshToken: data.refresh_token || refreshToken,
|
|
218
|
-
expiresIn: data.expires_in,
|
|
219
|
-
tokenType: data.token_type
|
|
220
|
-
};
|
|
221
|
-
if (tokens.expiresIn) {
|
|
222
|
-
tokens.expiresAt = Date.now() + tokens.expiresIn * 1e3;
|
|
223
|
-
}
|
|
224
|
-
return tokens;
|
|
225
|
-
} catch (error) {
|
|
226
|
-
if (error instanceof AuthenticationError) {
|
|
227
|
-
throw error;
|
|
228
|
-
}
|
|
229
|
-
if (error instanceof Error && error.message.includes("fetch")) {
|
|
230
|
-
throw new NetworkError();
|
|
231
|
-
}
|
|
232
|
-
throw new AuthenticationError("Session expired. Please log in again.");
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
var SUCCESS_HTML = `
|
|
236
|
-
<!DOCTYPE html>
|
|
237
|
-
<html>
|
|
238
|
-
<head>
|
|
239
|
-
<title>Authentication Successful - Kiva UI CLI</title>
|
|
240
|
-
<style>
|
|
241
|
-
* { box-sizing: border-box; }
|
|
242
|
-
body {
|
|
243
|
-
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
244
|
-
display: flex;
|
|
245
|
-
justify-content: center;
|
|
246
|
-
align-items: center;
|
|
247
|
-
min-height: 100vh;
|
|
248
|
-
margin: 0;
|
|
249
|
-
background: linear-gradient(to bottom right, #f8fafc, #f1f5f9);
|
|
250
|
-
}
|
|
251
|
-
.container {
|
|
252
|
-
width: 100%;
|
|
253
|
-
max-width: 400px;
|
|
254
|
-
padding: 32px;
|
|
255
|
-
background: white;
|
|
256
|
-
border-radius: 16px;
|
|
257
|
-
box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.15);
|
|
258
|
-
text-align: center;
|
|
259
|
-
}
|
|
260
|
-
.logo {
|
|
261
|
-
margin-bottom: 24px;
|
|
262
|
-
}
|
|
263
|
-
.logo svg {
|
|
264
|
-
height: 40px;
|
|
265
|
-
width: auto;
|
|
266
|
-
}
|
|
267
|
-
h1 {
|
|
268
|
-
margin: 0 0 8px;
|
|
269
|
-
font-size: 20px;
|
|
270
|
-
font-weight: 600;
|
|
271
|
-
color: #1e293b;
|
|
272
|
-
}
|
|
273
|
-
p {
|
|
274
|
-
margin: 0;
|
|
275
|
-
color: #64748b;
|
|
276
|
-
font-size: 14px;
|
|
277
|
-
}
|
|
278
|
-
</style>
|
|
279
|
-
</head>
|
|
280
|
-
<body>
|
|
281
|
-
<div class="container">
|
|
282
|
-
<div class="logo">
|
|
283
|
-
<svg viewBox="0 0 1325.62 253.55" xmlns="http://www.w3.org/2000/svg">
|
|
284
|
-
<path fill="#dc2626" d="M169.13,133.22l-.07.06v29.48c0,7.81-6.35,14.17-14.16,14.17h-29.48c-2.54,0-4.9-.68-6.96-1.85l-33.13,33.14c2.16,3.21,3.43,7.09,3.43,11.21,0,5.53-2.22,10.54-5.84,14.17-3.62,3.62-8.64,5.84-14.17,5.84s-10.55-2.22-14.17-5.84c-3.62-3.63-5.84-8.64-5.84-14.17,0-11.06,8.96-20.08,20.07-20.08,4.22,0,8.09,1.29,11.3,3.48l33.11-33.11c-1.22-2.07-1.91-4.46-1.91-7.02v-29.48c0-3.24,1.11-6.26,2.97-8.65l-27.31-37.16H19.96V15.5h71.85v65.82l28.44,38.71c1.62-.65,3.39-.98,5.23-.98h29.48c7.81,0,14.17,6.36,14.17,14.17Z"/>
|
|
285
|
-
<path fill="#1c1c1c" d="M241.24,60.57h48.58c12.19,0,23,2.42,32.44,7.25,9.44,4.83,16.77,11.61,21.98,20.34,5.21,8.73,7.82,18.75,7.82,30.05s-2.61,21.32-7.82,30.05c-5.22,8.73-12.54,15.51-21.98,20.34-9.44,4.83-20.25,7.25-32.44,7.25h-48.58V60.57ZM288.83,161.51c9.33,0,17.54-1.81,24.62-5.43,7.08-3.62,12.54-8.7,16.38-15.23,3.84-6.53,5.76-14.08,5.76-22.64s-1.92-16.11-5.76-22.64c-3.84-6.53-9.3-11.61-16.38-15.23-7.08-3.62-15.29-5.43-24.62-5.43h-31.12v86.61h31.12Z"/>
|
|
286
|
-
<path fill="#1c1c1c" d="M430.77,169.5c-9.33-5.1-16.66-12.16-21.98-21.16-5.33-9-7.99-19.04-7.99-30.13s2.66-21.13,7.99-30.13c5.32-9,12.65-16.06,21.98-21.16,9.33-5.1,19.81-7.66,31.45-7.66s21.96,2.55,31.29,7.66c9.33,5.1,16.63,12.13,21.9,21.08,5.27,8.95,7.9,19.02,7.9,30.22s-2.63,21.27-7.9,30.22c-5.27,8.95-12.57,15.97-21.9,21.08-9.33,5.1-19.76,7.66-31.29,7.66s-22.12-2.55-31.45-7.66ZM485.03,156.74c6.75-3.84,12.07-9.14,15.97-15.89,3.9-6.75,5.85-14.3,5.85-22.64s-1.95-15.89-5.85-22.64c-3.9-6.75-9.22-12.05-15.97-15.89-6.75-3.84-14.35-5.76-22.81-5.76s-16.11,1.92-22.97,5.76c-6.86,3.84-12.24,9.14-16.14,15.89-3.9,6.75-5.85,14.3-5.85,22.64s1.95,15.89,5.85,22.64c3.9,6.75,9.28,12.05,16.14,15.89,6.86,3.84,14.52,5.76,22.97,5.76s16.06-1.92,22.81-5.76Z"/>
|
|
287
|
-
<path fill="#1c1c1c" d="M601.78,169.5c-9.28-5.1-16.55-12.13-21.82-21.08-5.27-8.95-7.9-19.02-7.9-30.22s2.63-21.27,7.9-30.22c5.27-8.95,12.57-15.97,21.9-21.08,9.33-5.1,19.76-7.66,31.29-7.66,9,0,17.23,1.51,24.7,4.53,7.46,3.02,13.83,7.49,19.1,13.42l-10.7,10.37c-8.67-9.11-19.49-13.67-32.44-13.67-8.56,0-16.3,1.92-23.22,5.76-6.92,3.84-12.32,9.14-16.22,15.89-3.9,6.75-5.85,14.3-5.85,22.64s1.95,15.89,5.85,22.64c3.9,6.75,9.3,12.05,16.22,15.89,6.92,3.84,14.66,5.76,23.22,5.76,12.84,0,23.66-4.61,32.44-13.83l10.7,10.37c-5.27,5.93-11.67,10.43-19.18,13.5-7.52,3.07-15.78,4.61-24.78,4.61-11.53,0-21.93-2.55-31.2-7.66Z"/>
|
|
288
|
-
<path fill="#1c1c1c" d="M775.59,135.99v39.85h-16.3v-40.18l-45.78-75.09h17.62l36.89,60.76,37.05-60.76h16.3l-45.78,75.42Z"/>
|
|
289
|
-
<path fill="#1c1c1c" d="M946.01,175.84l-24.87-35.4c-3.07.22-5.49.33-7.25.33h-28.49v35.07h-16.47V60.57h44.95c14.93,0,26.68,3.57,35.24,10.7,8.56,7.14,12.84,16.96,12.84,29.48,0,8.89-2.2,16.47-6.59,22.72-4.39,6.26-10.65,10.81-18.77,13.67l27.33,38.7h-17.95ZM937.29,120.02c5.49-4.5,8.23-10.92,8.23-19.27s-2.75-14.74-8.23-19.18c-5.49-4.45-13.45-6.67-23.88-6.67h-27.99v51.87h27.99c10.43,0,18.39-2.25,23.88-6.75Z"/>
|
|
290
|
-
<path fill="#1c1c1c" d="M1033.45,163.98c-8.56-8.78-12.84-21.41-12.84-37.87V60.57h16.47v64.88c0,24.7,10.81,37.05,32.44,37.05,10.54,0,18.61-3.05,24.21-9.14s8.4-15.4,8.4-27.91V60.57h15.97v65.54c0,16.58-4.28,29.23-12.84,37.96-8.56,8.73-20.53,13.09-35.9,13.09s-27.33-4.39-35.9-13.17Z"/>
|
|
291
|
-
<path fill="#1c1c1c" d="M1193.26,173.12c-8.07-2.69-14.41-6.18-19.02-10.46l6.09-12.84c4.39,3.95,10.02,7.16,16.88,9.63,6.86,2.47,13.91,3.7,21.16,3.7,9.55,0,16.69-1.62,21.41-4.86,4.72-3.24,7.08-7.55,7.08-12.93,0-3.95-1.29-7.16-3.87-9.63-2.58-2.47-5.76-4.36-9.55-5.68s-9.14-2.8-16.05-4.45c-8.67-2.08-15.67-4.17-21-6.26-5.33-2.08-9.88-5.29-13.67-9.63-3.79-4.34-5.68-10.18-5.68-17.54,0-6.15,1.62-11.69,4.86-16.63,3.24-4.94,8.15-8.89,14.74-11.86,6.59-2.96,14.76-4.45,24.54-4.45,6.81,0,13.5.88,20.09,2.63,6.59,1.76,12.24,4.28,16.96,7.57l-5.43,13.17c-4.83-3.07-9.99-5.41-15.48-7-5.49-1.59-10.87-2.39-16.14-2.39-9.33,0-16.33,1.7-21,5.1-4.67,3.4-7,7.8-7,13.17,0,3.95,1.32,7.16,3.95,9.63,2.63,2.47,5.9,4.39,9.8,5.76,3.9,1.37,9.19,2.83,15.89,4.36,8.67,2.09,15.64,4.17,20.91,6.26,5.27,2.09,9.8,5.27,13.58,9.55,3.79,4.28,5.68,10.04,5.68,17.29,0,6.04-1.65,11.55-4.94,16.55-3.29,5-8.29,8.95-14.99,11.86-6.7,2.91-14.93,4.36-24.7,4.36-8.67,0-17.04-1.34-25.11-4.03Z"/>
|
|
292
|
-
</svg>
|
|
293
|
-
</div>
|
|
294
|
-
<h1>Authentication Successful</h1>
|
|
295
|
-
<p>You can close this tab and return to the CLI.</p>
|
|
296
|
-
</div>
|
|
297
|
-
</body>
|
|
298
|
-
</html>
|
|
299
|
-
`;
|
|
300
|
-
var ERROR_HTML = (message) => `
|
|
301
|
-
<!DOCTYPE html>
|
|
302
|
-
<html>
|
|
303
|
-
<head>
|
|
304
|
-
<title>Authentication Failed - Kiva UI CLI</title>
|
|
305
|
-
<style>
|
|
306
|
-
* { box-sizing: border-box; }
|
|
307
|
-
body {
|
|
308
|
-
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
309
|
-
display: flex;
|
|
310
|
-
justify-content: center;
|
|
311
|
-
align-items: center;
|
|
312
|
-
min-height: 100vh;
|
|
313
|
-
margin: 0;
|
|
314
|
-
background: linear-gradient(to bottom right, #f8fafc, #f1f5f9);
|
|
315
|
-
}
|
|
316
|
-
.container {
|
|
317
|
-
width: 100%;
|
|
318
|
-
max-width: 400px;
|
|
319
|
-
padding: 32px;
|
|
320
|
-
background: white;
|
|
321
|
-
border-radius: 16px;
|
|
322
|
-
box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.15);
|
|
323
|
-
text-align: center;
|
|
324
|
-
}
|
|
325
|
-
.logo {
|
|
326
|
-
margin-bottom: 24px;
|
|
327
|
-
}
|
|
328
|
-
.logo svg {
|
|
329
|
-
height: 40px;
|
|
330
|
-
width: auto;
|
|
331
|
-
}
|
|
332
|
-
h1 {
|
|
333
|
-
margin: 0 0 8px;
|
|
334
|
-
font-size: 20px;
|
|
335
|
-
font-weight: 600;
|
|
336
|
-
color: #1e293b;
|
|
337
|
-
}
|
|
338
|
-
p {
|
|
339
|
-
margin: 0;
|
|
340
|
-
color: #64748b;
|
|
341
|
-
font-size: 14px;
|
|
342
|
-
}
|
|
343
|
-
.error-message {
|
|
344
|
-
margin-top: 16px;
|
|
345
|
-
padding: 12px;
|
|
346
|
-
background: #fef2f2;
|
|
347
|
-
border-radius: 8px;
|
|
348
|
-
color: #dc2626;
|
|
349
|
-
font-size: 13px;
|
|
350
|
-
}
|
|
351
|
-
</style>
|
|
352
|
-
</head>
|
|
353
|
-
<body>
|
|
354
|
-
<div class="container">
|
|
355
|
-
<div class="logo">
|
|
356
|
-
<svg viewBox="0 0 1325.62 253.55" xmlns="http://www.w3.org/2000/svg">
|
|
357
|
-
<path fill="#dc2626" d="M169.13,133.22l-.07.06v29.48c0,7.81-6.35,14.17-14.16,14.17h-29.48c-2.54,0-4.9-.68-6.96-1.85l-33.13,33.14c2.16,3.21,3.43,7.09,3.43,11.21,0,5.53-2.22,10.54-5.84,14.17-3.62,3.62-8.64,5.84-14.17,5.84s-10.55-2.22-14.17-5.84c-3.62-3.63-5.84-8.64-5.84-14.17,0-11.06,8.96-20.08,20.07-20.08,4.22,0,8.09,1.29,11.3,3.48l33.11-33.11c-1.22-2.07-1.91-4.46-1.91-7.02v-29.48c0-3.24,1.11-6.26,2.97-8.65l-27.31-37.16H19.96V15.5h71.85v65.82l28.44,38.71c1.62-.65,3.39-.98,5.23-.98h29.48c7.81,0,14.17,6.36,14.17,14.17Z"/>
|
|
358
|
-
<path fill="#1c1c1c" d="M241.24,60.57h48.58c12.19,0,23,2.42,32.44,7.25,9.44,4.83,16.77,11.61,21.98,20.34,5.21,8.73,7.82,18.75,7.82,30.05s-2.61,21.32-7.82,30.05c-5.22,8.73-12.54,15.51-21.98,20.34-9.44,4.83-20.25,7.25-32.44,7.25h-48.58V60.57ZM288.83,161.51c9.33,0,17.54-1.81,24.62-5.43,7.08-3.62,12.54-8.7,16.38-15.23,3.84-6.53,5.76-14.08,5.76-22.64s-1.92-16.11-5.76-22.64c-3.84-6.53-9.3-11.61-16.38-15.23-7.08-3.62-15.29-5.43-24.62-5.43h-31.12v86.61h31.12Z"/>
|
|
359
|
-
<path fill="#1c1c1c" d="M430.77,169.5c-9.33-5.1-16.66-12.16-21.98-21.16-5.33-9-7.99-19.04-7.99-30.13s2.66-21.13,7.99-30.13c5.32-9,12.65-16.06,21.98-21.16,9.33-5.1,19.81-7.66,31.45-7.66s21.96,2.55,31.29,7.66c9.33,5.1,16.63,12.13,21.9,21.08,5.27,8.95,7.9,19.02,7.9,30.22s-2.63,21.27-7.9,30.22c-5.27,8.95-12.57,15.97-21.9,21.08-9.33,5.1-19.76,7.66-31.29,7.66s-22.12-2.55-31.45-7.66ZM485.03,156.74c6.75-3.84,12.07-9.14,15.97-15.89,3.9-6.75,5.85-14.3,5.85-22.64s-1.95-15.89-5.85-22.64c-3.9-6.75-9.22-12.05-15.97-15.89-6.75-3.84-14.35-5.76-22.81-5.76s-16.11,1.92-22.97,5.76c-6.86,3.84-12.24,9.14-16.14,15.89-3.9,6.75-5.85,14.3-5.85,22.64s1.95,15.89,5.85,22.64c3.9,6.75,9.28,12.05,16.14,15.89,6.86,3.84,14.52,5.76,22.97,5.76s16.06-1.92,22.81-5.76Z"/>
|
|
360
|
-
<path fill="#1c1c1c" d="M601.78,169.5c-9.28-5.1-16.55-12.13-21.82-21.08-5.27-8.95-7.9-19.02-7.9-30.22s2.63-21.27,7.9-30.22c5.27-8.95,12.57-15.97,21.9-21.08,9.33-5.1,19.76-7.66,31.29-7.66,9,0,17.23,1.51,24.7,4.53,7.46,3.02,13.83,7.49,19.1,13.42l-10.7,10.37c-8.67-9.11-19.49-13.67-32.44-13.67-8.56,0-16.3,1.92-23.22,5.76-6.92,3.84-12.32,9.14-16.22,15.89-3.9,6.75-5.85,14.3-5.85,22.64s1.95,15.89,5.85,22.64c3.9,6.75,9.3,12.05,16.22,15.89,6.92,3.84,14.66,5.76,23.22,5.76,12.84,0,23.66-4.61,32.44-13.83l10.7,10.37c-5.27,5.93-11.67,10.43-19.18,13.5-7.52,3.07-15.78,4.61-24.78,4.61-11.53,0-21.93-2.55-31.2-7.66Z"/>
|
|
361
|
-
<path fill="#1c1c1c" d="M775.59,135.99v39.85h-16.3v-40.18l-45.78-75.09h17.62l36.89,60.76,37.05-60.76h16.3l-45.78,75.42Z"/>
|
|
362
|
-
<path fill="#1c1c1c" d="M946.01,175.84l-24.87-35.4c-3.07.22-5.49.33-7.25.33h-28.49v35.07h-16.47V60.57h44.95c14.93,0,26.68,3.57,35.24,10.7,8.56,7.14,12.84,16.96,12.84,29.48,0,8.89-2.2,16.47-6.59,22.72-4.39,6.26-10.65,10.81-18.77,13.67l27.33,38.7h-17.95ZM937.29,120.02c5.49-4.5,8.23-10.92,8.23-19.27s-2.75-14.74-8.23-19.18c-5.49-4.45-13.45-6.67-23.88-6.67h-27.99v51.87h27.99c10.43,0,18.39-2.25,23.88-6.75Z"/>
|
|
363
|
-
<path fill="#1c1c1c" d="M1033.45,163.98c-8.56-8.78-12.84-21.41-12.84-37.87V60.57h16.47v64.88c0,24.7,10.81,37.05,32.44,37.05,10.54,0,18.61-3.05,24.21-9.14s8.4-15.4,8.4-27.91V60.57h15.97v65.54c0,16.58-4.28,29.23-12.84,37.96-8.56,8.73-20.53,13.09-35.9,13.09s-27.33-4.39-35.9-13.17Z"/>
|
|
364
|
-
<path fill="#1c1c1c" d="M1193.26,173.12c-8.07-2.69-14.41-6.18-19.02-10.46l6.09-12.84c4.39,3.95,10.02,7.16,16.88,9.63,6.86,2.47,13.91,3.7,21.16,3.7,9.55,0,16.69-1.62,21.41-4.86,4.72-3.24,7.08-7.55,7.08-12.93,0-3.95-1.29-7.16-3.87-9.63-2.58-2.47-5.76-4.36-9.55-5.68s-9.14-2.8-16.05-4.45c-8.67-2.08-15.67-4.17-21-6.26-5.33-2.08-9.88-5.29-13.67-9.63-3.79-4.34-5.68-10.18-5.68-17.54,0-6.15,1.62-11.69,4.86-16.63,3.24-4.94,8.15-8.89,14.74-11.86,6.59-2.96,14.76-4.45,24.54-4.45,6.81,0,13.5.88,20.09,2.63,6.59,1.76,12.24,4.28,16.96,7.57l-5.43,13.17c-4.83-3.07-9.99-5.41-15.48-7-5.49-1.59-10.87-2.39-16.14-2.39-9.33,0-16.33,1.7-21,5.1-4.67,3.4-7,7.8-7,13.17,0,3.95,1.32,7.16,3.95,9.63,2.63,2.47,5.9,4.39,9.8,5.76,3.9,1.37,9.19,2.83,15.89,4.36,8.67,2.09,15.64,4.17,20.91,6.26,5.27,2.09,9.8,5.27,13.58,9.55,3.79,4.28,5.68,10.04,5.68,17.29,0,6.04-1.65,11.55-4.94,16.55-3.29,5-8.29,8.95-14.99,11.86-6.7,2.91-14.93,4.36-24.7,4.36-8.67,0-17.04-1.34-25.11-4.03Z"/>
|
|
365
|
-
</svg>
|
|
366
|
-
</div>
|
|
367
|
-
<h1>Authentication Failed</h1>
|
|
368
|
-
<p>Something went wrong during authentication.</p>
|
|
369
|
-
<div class="error-message">${message}</div>
|
|
370
|
-
</div>
|
|
371
|
-
</body>
|
|
372
|
-
</html>
|
|
373
|
-
`;
|
|
374
|
-
function generateState() {
|
|
375
|
-
return randomBytes(32).toString("hex");
|
|
376
|
-
}
|
|
377
|
-
function generateCodeVerifier() {
|
|
378
|
-
return randomBytes(32).toString("base64url");
|
|
379
|
-
}
|
|
380
|
-
async function generateCodeChallenge(verifier) {
|
|
381
|
-
const encoder = new TextEncoder();
|
|
382
|
-
const data = encoder.encode(verifier);
|
|
383
|
-
const hashBuffer = await crypto.subtle.digest("SHA-256", data);
|
|
384
|
-
return Buffer.from(hashBuffer).toString("base64url");
|
|
385
|
-
}
|
|
386
|
-
async function findAvailablePort() {
|
|
387
|
-
return new Promise((resolve4, reject) => {
|
|
388
|
-
const tryPort = (port) => {
|
|
389
|
-
if (port > OAUTH_CALLBACK_PORT_MAX) {
|
|
390
|
-
reject(new OAuthError("Could not find an available port for OAuth callback."));
|
|
391
|
-
return;
|
|
392
|
-
}
|
|
393
|
-
const server = createServer();
|
|
394
|
-
server.listen(port, "127.0.0.1");
|
|
395
|
-
server.once("listening", () => {
|
|
396
|
-
server.close(() => resolve4(port));
|
|
397
|
-
});
|
|
398
|
-
server.once("error", () => {
|
|
399
|
-
tryPort(port + 1);
|
|
400
|
-
});
|
|
401
|
-
};
|
|
402
|
-
tryPort(OAUTH_CALLBACK_PORT_MIN);
|
|
403
|
-
});
|
|
404
|
-
}
|
|
405
|
-
async function startCallbackServer(expectedState) {
|
|
406
|
-
const port = await findAvailablePort();
|
|
407
|
-
let resolveResult;
|
|
408
|
-
let rejectResult;
|
|
409
|
-
const resultPromise = new Promise((resolve4, reject) => {
|
|
410
|
-
resolveResult = resolve4;
|
|
411
|
-
rejectResult = reject;
|
|
412
|
-
});
|
|
413
|
-
const timeoutId = setTimeout(() => {
|
|
414
|
-
rejectResult(new TimeoutError("OAuth authentication timed out."));
|
|
415
|
-
}, OAUTH_TIMEOUT_MS);
|
|
416
|
-
const server = createServer((req, res) => {
|
|
417
|
-
const url = new URL$1(req.url || "/", `http://127.0.0.1:${port}`);
|
|
418
|
-
if (url.pathname === "/callback") {
|
|
419
|
-
const code = url.searchParams.get("code");
|
|
420
|
-
const state2 = url.searchParams.get("state");
|
|
421
|
-
const error = url.searchParams.get("error");
|
|
422
|
-
const errorDescription = url.searchParams.get("error_description");
|
|
423
|
-
if (error) {
|
|
424
|
-
res.writeHead(400, { "Content-Type": "text/html" });
|
|
425
|
-
res.end(ERROR_HTML(errorDescription || error));
|
|
426
|
-
rejectResult(new OAuthError(errorDescription || error));
|
|
427
|
-
return;
|
|
428
|
-
}
|
|
429
|
-
if (!code || !state2) {
|
|
430
|
-
res.writeHead(400, { "Content-Type": "text/html" });
|
|
431
|
-
res.end(ERROR_HTML("Missing authorization code or state."));
|
|
432
|
-
rejectResult(new OAuthError("Missing authorization code or state."));
|
|
433
|
-
return;
|
|
434
|
-
}
|
|
435
|
-
if (state2 !== expectedState) {
|
|
436
|
-
res.writeHead(400, { "Content-Type": "text/html" });
|
|
437
|
-
res.end(ERROR_HTML("Invalid state parameter. Possible CSRF attack."));
|
|
438
|
-
rejectResult(new OAuthError("Invalid state parameter."));
|
|
439
|
-
return;
|
|
440
|
-
}
|
|
441
|
-
res.writeHead(200, { "Content-Type": "text/html" });
|
|
442
|
-
res.end(SUCCESS_HTML);
|
|
443
|
-
resolveResult({ code, state: state2 });
|
|
444
|
-
} else {
|
|
445
|
-
res.writeHead(404);
|
|
446
|
-
res.end("Not Found");
|
|
447
|
-
}
|
|
448
|
-
});
|
|
449
|
-
server.listen(port, "127.0.0.1");
|
|
450
|
-
const cleanup = () => {
|
|
451
|
-
clearTimeout(timeoutId);
|
|
452
|
-
server.close();
|
|
453
|
-
};
|
|
454
|
-
return {
|
|
455
|
-
server,
|
|
456
|
-
port,
|
|
457
|
-
resultPromise,
|
|
458
|
-
cleanup
|
|
459
|
-
};
|
|
460
|
-
}
|
|
461
|
-
async function openBrowser(url) {
|
|
462
|
-
await open(url);
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
// src/auth/oauth-auth.ts
|
|
466
|
-
function getOAuthConfig(port) {
|
|
467
|
-
return {
|
|
468
|
-
authorizationUrl: `${KIVA_API_URL}/v1/oauth2/authorize`,
|
|
469
|
-
tokenUrl: `${KIVA_API_URL}/v1/oauth2/token`,
|
|
470
|
-
clientId: OAUTH_CLIENT_ID,
|
|
471
|
-
redirectUri: OAUTH_REDIRECT_URI(port),
|
|
472
|
-
scopes: OAUTH_SCOPES
|
|
473
|
-
};
|
|
474
|
-
}
|
|
475
|
-
function buildAuthorizationUrl(config, state2, codeChallenge) {
|
|
476
|
-
const params = new URLSearchParams({
|
|
477
|
-
response_type: "code",
|
|
478
|
-
client_id: config.clientId,
|
|
479
|
-
redirect_uri: config.redirectUri,
|
|
480
|
-
scope: config.scopes.join(" "),
|
|
481
|
-
state: state2,
|
|
482
|
-
code_challenge: codeChallenge,
|
|
483
|
-
code_challenge_method: "S256"
|
|
484
|
-
});
|
|
485
|
-
return `${config.authorizationUrl}?${params.toString()}`;
|
|
486
|
-
}
|
|
487
|
-
async function exchangeCodeForTokens(config, code, codeVerifier) {
|
|
488
|
-
const response = await fetch(config.tokenUrl, {
|
|
489
|
-
method: "POST",
|
|
490
|
-
headers: {
|
|
491
|
-
"Content-Type": "application/x-www-form-urlencoded"
|
|
492
|
-
},
|
|
493
|
-
body: new URLSearchParams({
|
|
494
|
-
grant_type: "authorization_code",
|
|
495
|
-
client_id: config.clientId,
|
|
496
|
-
code,
|
|
497
|
-
redirect_uri: config.redirectUri,
|
|
498
|
-
code_verifier: codeVerifier
|
|
499
|
-
}).toString()
|
|
500
|
-
});
|
|
501
|
-
if (!response.ok) {
|
|
502
|
-
const errorText = await response.text();
|
|
503
|
-
throw new OAuthError(`Failed to exchange authorization code: ${errorText}`);
|
|
504
|
-
}
|
|
505
|
-
const data = await response.json();
|
|
506
|
-
const tokens = {
|
|
507
|
-
accessToken: data.access_token,
|
|
508
|
-
refreshToken: data.refresh_token,
|
|
509
|
-
expiresIn: data.expires_in,
|
|
510
|
-
tokenType: data.token_type
|
|
511
|
-
};
|
|
512
|
-
if (tokens.expiresIn) {
|
|
513
|
-
tokens.expiresAt = Date.now() + tokens.expiresIn * 1e3;
|
|
514
|
-
}
|
|
515
|
-
return tokens;
|
|
516
|
-
}
|
|
517
|
-
async function getUserInfoFromToken(accessToken) {
|
|
518
|
-
const client = new RestApiClient({ baseURL: KIVA_API_URL });
|
|
519
|
-
await client.setAccessToken(accessToken);
|
|
520
|
-
try {
|
|
521
|
-
return await client.get("/v1/users/me");
|
|
522
|
-
} catch {
|
|
523
|
-
return void 0;
|
|
524
|
-
}
|
|
525
|
-
}
|
|
526
|
-
async function loginWithOAuth(options = {}) {
|
|
527
|
-
const state2 = generateState();
|
|
528
|
-
const codeVerifier = generateCodeVerifier();
|
|
529
|
-
const codeChallenge = await generateCodeChallenge(codeVerifier);
|
|
530
|
-
const { port, resultPromise, cleanup } = await startCallbackServer(state2);
|
|
531
|
-
const config = getOAuthConfig(port);
|
|
532
|
-
const authUrl = buildAuthorizationUrl(config, state2, codeChallenge);
|
|
533
|
-
try {
|
|
534
|
-
options.onOpeningBrowser?.();
|
|
535
|
-
await openBrowser(authUrl);
|
|
536
|
-
options.onWaitingForAuth?.(authUrl);
|
|
537
|
-
const { code } = await resultPromise;
|
|
538
|
-
const tokens = await exchangeCodeForTokens(config, code, codeVerifier);
|
|
539
|
-
const user = await getUserInfoFromToken(tokens.accessToken);
|
|
540
|
-
return { tokens, user };
|
|
541
|
-
} finally {
|
|
542
|
-
cleanup();
|
|
543
|
-
}
|
|
544
|
-
}
|
|
545
|
-
function getHomeDir() {
|
|
546
|
-
return homedir();
|
|
547
|
-
}
|
|
548
|
-
function getConfigDir() {
|
|
549
|
-
return join(getHomeDir(), CONFIG_DIR);
|
|
550
|
-
}
|
|
551
|
-
var ALGORITHM = "aes-256-gcm";
|
|
552
|
-
var KEY_LENGTH = 32;
|
|
553
|
-
var IV_LENGTH = 16;
|
|
554
|
-
var AUTH_TAG_LENGTH = 16;
|
|
555
|
-
var SALT_LENGTH = 32;
|
|
556
|
-
function getMachineId() {
|
|
557
|
-
const parts = [
|
|
558
|
-
hostname(),
|
|
559
|
-
userInfo().username,
|
|
560
|
-
process.platform,
|
|
561
|
-
process.arch
|
|
562
|
-
];
|
|
563
|
-
return createHash("sha256").update(parts.join("-")).digest("hex");
|
|
564
|
-
}
|
|
565
|
-
function deriveKey(salt) {
|
|
566
|
-
const machineId = getMachineId();
|
|
567
|
-
return scryptSync(machineId, salt, KEY_LENGTH);
|
|
568
|
-
}
|
|
569
|
-
function encrypt(data) {
|
|
570
|
-
const salt = randomBytes(SALT_LENGTH);
|
|
571
|
-
const key = deriveKey(salt);
|
|
572
|
-
const iv = randomBytes(IV_LENGTH);
|
|
573
|
-
const cipher = createCipheriv(ALGORITHM, key, iv, { authTagLength: AUTH_TAG_LENGTH });
|
|
574
|
-
const encrypted = Buffer.concat([cipher.update(data, "utf8"), cipher.final()]);
|
|
575
|
-
const authTag = cipher.getAuthTag();
|
|
576
|
-
return [
|
|
577
|
-
salt.toString("base64"),
|
|
578
|
-
iv.toString("base64"),
|
|
579
|
-
authTag.toString("base64"),
|
|
580
|
-
encrypted.toString("base64")
|
|
581
|
-
].join(":");
|
|
582
|
-
}
|
|
583
|
-
function decrypt(encryptedData) {
|
|
584
|
-
const parts = encryptedData.split(":");
|
|
585
|
-
if (parts.length !== 4) {
|
|
586
|
-
throw new Error("Invalid encrypted data format");
|
|
587
|
-
}
|
|
588
|
-
const saltB64 = parts[0];
|
|
589
|
-
const ivB64 = parts[1];
|
|
590
|
-
const authTagB64 = parts[2];
|
|
591
|
-
const dataB64 = parts[3];
|
|
592
|
-
const salt = Buffer.from(saltB64, "base64");
|
|
593
|
-
const iv = Buffer.from(ivB64, "base64");
|
|
594
|
-
const authTag = Buffer.from(authTagB64, "base64");
|
|
595
|
-
const encrypted = Buffer.from(dataB64, "base64");
|
|
596
|
-
const key = deriveKey(salt);
|
|
597
|
-
const decipher = createDecipheriv(ALGORITHM, key, iv, { authTagLength: AUTH_TAG_LENGTH });
|
|
598
|
-
decipher.setAuthTag(authTag);
|
|
599
|
-
const decrypted = Buffer.concat([decipher.update(encrypted), decipher.final()]);
|
|
600
|
-
return decrypted.toString("utf8");
|
|
601
|
-
}
|
|
602
|
-
|
|
603
|
-
// src/storage/file-storage.ts
|
|
604
|
-
var FileStorage = class {
|
|
605
|
-
filePath;
|
|
606
|
-
constructor() {
|
|
607
|
-
const configDir = getConfigDir();
|
|
608
|
-
this.filePath = join(configDir, CREDENTIALS_FILE);
|
|
609
|
-
}
|
|
610
|
-
ensureConfigDir() {
|
|
611
|
-
const configDir = getConfigDir();
|
|
612
|
-
if (!existsSync(configDir)) {
|
|
613
|
-
mkdirSync(configDir, { recursive: true, mode: 448 });
|
|
614
|
-
}
|
|
615
|
-
}
|
|
616
|
-
readData() {
|
|
617
|
-
if (!existsSync(this.filePath)) {
|
|
618
|
-
return {};
|
|
619
|
-
}
|
|
620
|
-
try {
|
|
621
|
-
const encrypted = readFileSync(this.filePath, "utf8");
|
|
622
|
-
const decrypted = decrypt(encrypted);
|
|
623
|
-
return JSON.parse(decrypted);
|
|
624
|
-
} catch {
|
|
625
|
-
return {};
|
|
626
|
-
}
|
|
627
|
-
}
|
|
628
|
-
writeData(data) {
|
|
629
|
-
this.ensureConfigDir();
|
|
630
|
-
const json = JSON.stringify(data);
|
|
631
|
-
const encrypted = encrypt(json);
|
|
632
|
-
writeFileSync(this.filePath, encrypted, { mode: 384 });
|
|
633
|
-
}
|
|
634
|
-
async get(key) {
|
|
635
|
-
const data = this.readData();
|
|
636
|
-
return data[key] ?? null;
|
|
637
|
-
}
|
|
638
|
-
async set(key, value) {
|
|
639
|
-
const data = this.readData();
|
|
640
|
-
data[key] = value;
|
|
641
|
-
this.writeData(data);
|
|
642
|
-
}
|
|
643
|
-
async delete(key) {
|
|
644
|
-
const data = this.readData();
|
|
645
|
-
delete data[key];
|
|
646
|
-
if (Object.keys(data).length === 0) {
|
|
647
|
-
this.clear();
|
|
648
|
-
} else {
|
|
649
|
-
this.writeData(data);
|
|
650
|
-
}
|
|
651
|
-
}
|
|
652
|
-
async clear() {
|
|
653
|
-
if (existsSync(this.filePath)) {
|
|
654
|
-
unlinkSync(this.filePath);
|
|
655
|
-
}
|
|
656
|
-
}
|
|
657
|
-
};
|
|
658
|
-
|
|
659
|
-
// src/storage/keychain-storage.ts
|
|
660
|
-
var keytar = null;
|
|
661
|
-
async function getKeytar() {
|
|
662
|
-
if (keytar !== null) {
|
|
663
|
-
return keytar;
|
|
664
|
-
}
|
|
665
|
-
try {
|
|
666
|
-
keytar = await import('keytar');
|
|
667
|
-
return keytar;
|
|
668
|
-
} catch {
|
|
669
|
-
keytar = null;
|
|
670
|
-
return null;
|
|
671
|
-
}
|
|
672
|
-
}
|
|
673
|
-
var KeychainStorage = class {
|
|
674
|
-
service;
|
|
675
|
-
constructor(service = KEYCHAIN_SERVICE) {
|
|
676
|
-
this.service = service;
|
|
677
|
-
}
|
|
678
|
-
async isAvailable() {
|
|
679
|
-
const kt = await getKeytar();
|
|
680
|
-
if (!kt) return false;
|
|
681
|
-
try {
|
|
682
|
-
await kt.findCredentials(this.service);
|
|
683
|
-
return true;
|
|
684
|
-
} catch {
|
|
685
|
-
return false;
|
|
686
|
-
}
|
|
687
|
-
}
|
|
688
|
-
async get(key) {
|
|
689
|
-
const kt = await getKeytar();
|
|
690
|
-
if (!kt) return null;
|
|
691
|
-
try {
|
|
692
|
-
return await kt.getPassword(this.service, key);
|
|
693
|
-
} catch {
|
|
694
|
-
return null;
|
|
695
|
-
}
|
|
696
|
-
}
|
|
697
|
-
async set(key, value) {
|
|
698
|
-
const kt = await getKeytar();
|
|
699
|
-
if (!kt) return false;
|
|
700
|
-
try {
|
|
701
|
-
await kt.setPassword(this.service, key, value);
|
|
702
|
-
return true;
|
|
703
|
-
} catch {
|
|
704
|
-
return false;
|
|
705
|
-
}
|
|
706
|
-
}
|
|
707
|
-
async delete(key) {
|
|
708
|
-
const kt = await getKeytar();
|
|
709
|
-
if (!kt) return false;
|
|
710
|
-
try {
|
|
711
|
-
return await kt.deletePassword(this.service, key);
|
|
712
|
-
} catch {
|
|
713
|
-
return false;
|
|
714
|
-
}
|
|
715
|
-
}
|
|
716
|
-
async clear() {
|
|
717
|
-
const kt = await getKeytar();
|
|
718
|
-
if (!kt) return;
|
|
719
|
-
try {
|
|
720
|
-
const credentials = await kt.findCredentials(this.service);
|
|
721
|
-
for (const cred of credentials) {
|
|
722
|
-
await kt.deletePassword(this.service, cred.account);
|
|
723
|
-
}
|
|
724
|
-
} catch {
|
|
725
|
-
}
|
|
726
|
-
}
|
|
727
|
-
};
|
|
728
|
-
var CliTokenManager = class {
|
|
729
|
-
keychain;
|
|
730
|
-
fileStorage;
|
|
731
|
-
keychainAvailable = null;
|
|
732
|
-
constructor() {
|
|
733
|
-
this.keychain = new KeychainStorage();
|
|
734
|
-
this.fileStorage = new FileStorage();
|
|
735
|
-
}
|
|
736
|
-
async isKeychainAvailable() {
|
|
737
|
-
if (this.keychainAvailable === null) {
|
|
738
|
-
this.keychainAvailable = await this.keychain.isAvailable();
|
|
739
|
-
}
|
|
740
|
-
return this.keychainAvailable;
|
|
741
|
-
}
|
|
742
|
-
async getToken() {
|
|
743
|
-
if (await this.isKeychainAvailable()) {
|
|
744
|
-
const token = await this.keychain.get(TOKEN_KEYS.ACCESS_TOKEN);
|
|
745
|
-
if (token) return token;
|
|
746
|
-
}
|
|
747
|
-
return await this.fileStorage.get(TOKEN_KEYS.ACCESS_TOKEN);
|
|
748
|
-
}
|
|
749
|
-
async setToken(token) {
|
|
750
|
-
if (await this.isKeychainAvailable()) {
|
|
751
|
-
const success = await this.keychain.set(TOKEN_KEYS.ACCESS_TOKEN, token);
|
|
752
|
-
if (success) return;
|
|
753
|
-
}
|
|
754
|
-
await this.fileStorage.set(TOKEN_KEYS.ACCESS_TOKEN, token);
|
|
755
|
-
}
|
|
756
|
-
async clearToken() {
|
|
757
|
-
await this.keychain.delete(TOKEN_KEYS.ACCESS_TOKEN);
|
|
758
|
-
await this.fileStorage.delete(TOKEN_KEYS.ACCESS_TOKEN);
|
|
759
|
-
}
|
|
760
|
-
async getRefreshToken() {
|
|
761
|
-
if (await this.isKeychainAvailable()) {
|
|
762
|
-
const token = await this.keychain.get(TOKEN_KEYS.REFRESH_TOKEN);
|
|
763
|
-
if (token) return token;
|
|
764
|
-
}
|
|
765
|
-
return await this.fileStorage.get(TOKEN_KEYS.REFRESH_TOKEN);
|
|
766
|
-
}
|
|
767
|
-
async setRefreshToken(token) {
|
|
768
|
-
if (await this.isKeychainAvailable()) {
|
|
769
|
-
const success = await this.keychain.set(TOKEN_KEYS.REFRESH_TOKEN, token);
|
|
770
|
-
if (success) return;
|
|
771
|
-
}
|
|
772
|
-
await this.fileStorage.set(TOKEN_KEYS.REFRESH_TOKEN, token);
|
|
773
|
-
}
|
|
774
|
-
async clearRefreshToken() {
|
|
775
|
-
await this.keychain.delete(TOKEN_KEYS.REFRESH_TOKEN);
|
|
776
|
-
await this.fileStorage.delete(TOKEN_KEYS.REFRESH_TOKEN);
|
|
777
|
-
}
|
|
778
|
-
async getUserEmail() {
|
|
779
|
-
if (await this.isKeychainAvailable()) {
|
|
780
|
-
const email = await this.keychain.get(TOKEN_KEYS.USER_EMAIL);
|
|
781
|
-
if (email) return email;
|
|
782
|
-
}
|
|
783
|
-
return await this.fileStorage.get(TOKEN_KEYS.USER_EMAIL);
|
|
784
|
-
}
|
|
785
|
-
async setUserEmail(email) {
|
|
786
|
-
if (await this.isKeychainAvailable()) {
|
|
787
|
-
const success = await this.keychain.set(TOKEN_KEYS.USER_EMAIL, email);
|
|
788
|
-
if (success) return;
|
|
789
|
-
}
|
|
790
|
-
await this.fileStorage.set(TOKEN_KEYS.USER_EMAIL, email);
|
|
791
|
-
}
|
|
792
|
-
// GitHub token for private template access (persists after logout)
|
|
793
|
-
async getGithubToken() {
|
|
794
|
-
if (await this.isKeychainAvailable()) {
|
|
795
|
-
const token = await this.keychain.get(TOKEN_KEYS.GITHUB_TOKEN);
|
|
796
|
-
if (token) return token;
|
|
797
|
-
}
|
|
798
|
-
return await this.fileStorage.get(TOKEN_KEYS.GITHUB_TOKEN);
|
|
799
|
-
}
|
|
800
|
-
async setGithubToken(token) {
|
|
801
|
-
if (await this.isKeychainAvailable()) {
|
|
802
|
-
const success = await this.keychain.set(TOKEN_KEYS.GITHUB_TOKEN, token);
|
|
803
|
-
if (success) return;
|
|
804
|
-
}
|
|
805
|
-
await this.fileStorage.set(TOKEN_KEYS.GITHUB_TOKEN, token);
|
|
806
|
-
}
|
|
807
|
-
async clearAll() {
|
|
808
|
-
const githubToken = await this.getGithubToken();
|
|
809
|
-
await this.keychain.clear();
|
|
810
|
-
await this.fileStorage.clear();
|
|
811
|
-
if (githubToken) {
|
|
812
|
-
await this.setGithubToken(githubToken);
|
|
813
|
-
}
|
|
814
|
-
}
|
|
815
|
-
async isLoggedIn() {
|
|
816
|
-
const token = await this.getToken();
|
|
817
|
-
return token !== null;
|
|
818
|
-
}
|
|
819
|
-
};
|
|
820
|
-
var instance = null;
|
|
821
|
-
function getTokenManager() {
|
|
822
|
-
if (!instance) {
|
|
823
|
-
instance = new CliTokenManager();
|
|
824
|
-
}
|
|
825
|
-
return instance;
|
|
826
|
-
}
|
|
827
|
-
|
|
828
|
-
// src/config/component-list.ts
|
|
829
|
-
function parseCsv(value) {
|
|
830
|
-
return (value ?? "").split(",").map((item) => item.trim()).filter(Boolean);
|
|
831
|
-
}
|
|
832
|
-
parseCsv(
|
|
833
|
-
"slate,gray,zinc,neutral,stone,red,orange,amber,yellow,lime,green,emerald,teal,cyan,sky"
|
|
834
|
-
);
|
|
835
|
-
var PLATE_COMPONENTS = parseCsv(
|
|
836
|
-
"@plate/align-base-kit,@plate/align-kit,@plate/autoformat-kit,@plate/basic-blocks-base-kit,@plate/basic-blocks-kit,@plate/basic-marks-base-kit,@plate/basic-marks-kit,@plate/block-menu-kit,@plate/block-placeholder-kit,@plate/block-selection-kit,@plate/callout-base-kit,@plate/callout-kit,@plate/code-block-base-kit,@plate/code-block-kit,@plate/column-base-kit,@plate/column-kit,@plate/comment-base-kit,@plate/comment-kit,@plate/cursor-overlay-kit,@plate/date-base-kit,@plate/date-kit,@plate/discussion-kit,@plate/dnd-kit,@plate/editor-base-kit,@plate/emoji-kit,@plate/exit-break-kit,@plate/fixed-toolbar-kit,@plate/floating-toolbar-kit,@plate/font-base-kit,@plate/font-kit,@plate/indent-base-kit,@plate/indent-kit,@plate/line-height-base-kit,@plate/line-height-kit,@plate/link-base-kit,@plate/link-kit,@plate/list-base-kit,@plate/list-kit,@plate/markdown-kit,@plate/math-base-kit,@plate/math-kit,@plate/media-base-kit,@plate/mention-base-kit,@plate/mention-kit,@plate/suggestion-base-kit,@plate/suggestion-kit,@plate/table-base-kit,@plate/table-kit,@plate/toc-base-kit,@plate/toc-kit,@plate/toggle-base-kit,@plate/toggle-kit,@plate/transforms"
|
|
837
|
-
).map((component) => component.replace(/^@plate\//, ""));
|
|
838
|
-
var AI_ELEMENTS_COMPONENTS = parseCsv(
|
|
839
|
-
"agent,artifact,attachments,audio-player,chain-of-thought,checkpoint,code-block,commit,confirmation,context,conversation,environment-variables,file-tree,image,inline-citation,jsx-preview,message,mic-selector,model-selector,open-in-chat,package-info,persona,plan,prompt-input,queue,reasoning,sandbox,schema-display,shimmer,snippet,sources,speech-input,stack-trace,suggestion,task,terminal,test-results,tool,transcription,voice-selector,web-preview"
|
|
840
|
-
);
|
|
841
|
-
var PLATE_COMPONENTS_SET = new Set(PLATE_COMPONENTS);
|
|
842
|
-
var AI_ELEMENTS_COMPONENTS_SET = new Set(AI_ELEMENTS_COMPONENTS);
|
|
843
|
-
var defaults = {
|
|
844
|
-
helpTheme: "default"
|
|
845
|
-
};
|
|
846
|
-
var ConfigManager = class {
|
|
847
|
-
config;
|
|
848
|
-
constructor() {
|
|
849
|
-
this.config = new Conf({
|
|
850
|
-
projectName: CONFIG_PROJECT_NAME,
|
|
851
|
-
defaults
|
|
852
|
-
});
|
|
853
|
-
}
|
|
854
|
-
get(key) {
|
|
855
|
-
return this.config.get(key);
|
|
856
|
-
}
|
|
857
|
-
set(key, value) {
|
|
858
|
-
this.config.set(key, value);
|
|
859
|
-
}
|
|
860
|
-
get path() {
|
|
861
|
-
return this.config.path;
|
|
862
|
-
}
|
|
863
|
-
};
|
|
864
|
-
var configManager = new ConfigManager();
|
|
5
|
+
import chalk4 from 'chalk';
|
|
6
|
+
import ora from 'ora';
|
|
7
|
+
import { confirm, select, checkbox, input } from '@inquirer/prompts';
|
|
8
|
+
import Conf from 'conf';
|
|
9
|
+
import { arch, release, platform } from 'os';
|
|
10
|
+
import { readFile, mkdir, writeFile, chmod } from 'fs/promises';
|
|
11
|
+
import { existsSync, readFileSync, writeFileSync, mkdirSync, renameSync, statSync, readdirSync, rmSync } from 'fs';
|
|
12
|
+
import { join, relative, resolve, dirname } from 'path';
|
|
13
|
+
|
|
865
14
|
var logger = {
|
|
866
15
|
success(message) {
|
|
867
16
|
console.info(chalk4.green("\u2713"), message);
|
|
@@ -974,53 +123,6 @@ var output = {
|
|
|
974
123
|
|
|
975
124
|
// src/ui/messages.ts
|
|
976
125
|
var MESSAGES = {
|
|
977
|
-
// Login
|
|
978
|
-
LOGIN_SUCCESS: (email) => `Successfully logged in as ${email}`,
|
|
979
|
-
LOGIN_PROMPT_EMAIL: "Email:",
|
|
980
|
-
LOGIN_PROMPT_PASSWORD: "Password:",
|
|
981
|
-
LOGIN_AUTHENTICATING: "Authenticating...",
|
|
982
|
-
// SSO
|
|
983
|
-
SSO_OPENING_BROWSER: "Opening browser for authentication...",
|
|
984
|
-
SSO_WAITING: "Waiting for browser authentication...",
|
|
985
|
-
SSO_SUCCESS: "Browser authentication successful!",
|
|
986
|
-
SSO_TIMEOUT: "Authentication timed out. Please try again.",
|
|
987
|
-
SSO_CANCELLED: "Authentication cancelled.",
|
|
988
|
-
// Logout
|
|
989
|
-
LOGOUT_SUCCESS: "Successfully logged out.",
|
|
990
|
-
LOGOUT_IN_PROGRESS: "Logging out...",
|
|
991
|
-
// Whoami
|
|
992
|
-
WHOAMI_NOT_LOGGED_IN: "You are not logged in.",
|
|
993
|
-
WHOAMI_FETCHING: "Fetching user info...",
|
|
994
|
-
// General
|
|
995
|
-
NOT_LOGGED_IN: "You are not logged in.",
|
|
996
|
-
NETWORK_ERROR: "Network request failed. Please check your internet connection.",
|
|
997
|
-
UNKNOWN_ERROR: "An unexpected error occurred.",
|
|
998
|
-
// Errors
|
|
999
|
-
INVALID_CREDENTIALS: "Invalid email or password.",
|
|
1000
|
-
SESSION_EXPIRED: "Your session has expired. Please log in again.",
|
|
1001
|
-
SERVER_ERROR: "Server error. Please try again later.",
|
|
1002
|
-
// Create command
|
|
1003
|
-
// TanStack DB Generator
|
|
1004
|
-
TANSTACK_GENERATOR_PROMPT: "Generate TanStack Query collections from OpenAPI spec?",
|
|
1005
|
-
TANSTACK_GENERATOR_RUNNING: "Generating TanStack Query collections...",
|
|
1006
|
-
TANSTACK_GENERATOR_SUCCESS: "TanStack Query collections generated",
|
|
1007
|
-
TANSTACK_GENERATOR_FAILED: "Failed to generate TanStack Query collections",
|
|
1008
|
-
// Linter Setup
|
|
1009
|
-
LINTER_SETUP_TITLE: "Setting up Linter...",
|
|
1010
|
-
// State Management
|
|
1011
|
-
STATE_MANAGEMENT_SETUP_TITLE: "Setting up State Management...",
|
|
1012
|
-
// OpenAPI Setup
|
|
1013
|
-
OPENAPI_SETUP_TITLE: "Setting up API...",
|
|
1014
|
-
// API Client
|
|
1015
|
-
API_CLIENT_DOCS: "API Client: https://www.npmjs.com/package/@kivacore/api-client",
|
|
1016
|
-
// UI Library Setup
|
|
1017
|
-
UI_SETUP_TITLE: "Setting up UI Library...",
|
|
1018
|
-
UI_MULTIPLE_LIBRARIES: "Cannot use multiple UI libraries together",
|
|
1019
|
-
// Kiva Token (for private template access)
|
|
1020
|
-
KIVA_TOKEN_REQUIRED: "Kiva token required for template download",
|
|
1021
|
-
KIVA_TOKEN_PROMPT: "Enter Kiva token:",
|
|
1022
|
-
KIVA_TOKEN_SAVED: "Kiva token saved successfully",
|
|
1023
|
-
KIVA_TOKEN_INVALID: "Invalid Kiva token. Please check and try again.",
|
|
1024
126
|
// Add command
|
|
1025
127
|
ADD_RESOLVING: "Resolving components and dependencies...",
|
|
1026
128
|
ADD_INSTALLING_ITEM: (name) => `Installing ${name}...`,
|
|
@@ -1028,7 +130,6 @@ var MESSAGES = {
|
|
|
1028
130
|
ADD_SUCCESS: (items, files) => `Done! Added ${items} item(s), ${files} file(s).`,
|
|
1029
131
|
ADD_NO_ITEMS: "Please specify at least one item to add.",
|
|
1030
132
|
ADD_NOT_FOUND: (name) => `"${name}" not found in the registry.`,
|
|
1031
|
-
ADD_PREMIUM_AUTH: (name) => `"${name}" is a premium component. Authentication required.`,
|
|
1032
133
|
ADD_FILE_EXISTS: (path) => `File ${path} already exists. Overwrite?`,
|
|
1033
134
|
ADD_FILE_SKIPPED: (path) => `Skipped: ${path}`,
|
|
1034
135
|
ADD_DRY_RUN_HEADER: "Dry run \u2014 the following changes would be made:",
|
|
@@ -1114,30 +215,6 @@ async function withSpinner(text, fn, options) {
|
|
|
1114
215
|
throw error;
|
|
1115
216
|
}
|
|
1116
217
|
}
|
|
1117
|
-
async function promptEmail(defaultValue) {
|
|
1118
|
-
return input({
|
|
1119
|
-
message: MESSAGES.LOGIN_PROMPT_EMAIL,
|
|
1120
|
-
default: defaultValue,
|
|
1121
|
-
validate: (value) => {
|
|
1122
|
-
if (!value || !value.includes("@")) {
|
|
1123
|
-
return "Please enter a valid email address.";
|
|
1124
|
-
}
|
|
1125
|
-
return true;
|
|
1126
|
-
}
|
|
1127
|
-
});
|
|
1128
|
-
}
|
|
1129
|
-
async function promptPassword() {
|
|
1130
|
-
return password({
|
|
1131
|
-
message: MESSAGES.LOGIN_PROMPT_PASSWORD,
|
|
1132
|
-
mask: "*",
|
|
1133
|
-
validate: (value) => {
|
|
1134
|
-
if (!value || value.length < 1) {
|
|
1135
|
-
return "Please enter your password.";
|
|
1136
|
-
}
|
|
1137
|
-
return true;
|
|
1138
|
-
}
|
|
1139
|
-
});
|
|
1140
|
-
}
|
|
1141
218
|
var SYMBOLS = {
|
|
1142
219
|
pending: chalk4.dim("\u25CB"),
|
|
1143
220
|
in_progress: chalk4.cyan("\u25D0"),
|
|
@@ -1211,6 +288,71 @@ function createMultiStepProgress(title, stepLabels) {
|
|
|
1211
288
|
}
|
|
1212
289
|
};
|
|
1213
290
|
}
|
|
291
|
+
|
|
292
|
+
// src/config/constants.ts
|
|
293
|
+
var DEFAULT_REGISTRY_BASE_URL = "https://ui.kivacore.com/r";
|
|
294
|
+
function trimTrailingSlashes(value) {
|
|
295
|
+
return value.replace(/\/+$/, "");
|
|
296
|
+
}
|
|
297
|
+
function withFallback(value, fallback) {
|
|
298
|
+
const candidate = value?.trim() || fallback;
|
|
299
|
+
return trimTrailingSlashes(candidate);
|
|
300
|
+
}
|
|
301
|
+
function joinRegistryPath(baseUrl, segment) {
|
|
302
|
+
return `${trimTrailingSlashes(baseUrl)}/${segment.replace(/^\/+/, "")}`;
|
|
303
|
+
}
|
|
304
|
+
function resolveThemesApiUrl(registryBaseUrl) {
|
|
305
|
+
const normalized = trimTrailingSlashes(registryBaseUrl);
|
|
306
|
+
if (normalized.endsWith("/r")) {
|
|
307
|
+
return `${normalized.slice(0, -2)}/api/themes`;
|
|
308
|
+
}
|
|
309
|
+
return `${normalized}/api/themes`;
|
|
310
|
+
}
|
|
311
|
+
var CONFIG_PROJECT_NAME = "docyrus";
|
|
312
|
+
var REGISTRY_BASE_URL = withFallback(process.env.KIVA_REGISTRY_URL, DEFAULT_REGISTRY_BASE_URL);
|
|
313
|
+
var SHADCN_REGISTRY_URL = withFallback(
|
|
314
|
+
process.env.KIVA_SHADCN_REGISTRY_URL,
|
|
315
|
+
joinRegistryPath(REGISTRY_BASE_URL, "shadcn")
|
|
316
|
+
);
|
|
317
|
+
var PLATE_REGISTRY_URL = withFallback(
|
|
318
|
+
process.env.KIVA_PLATE_REGISTRY_URL,
|
|
319
|
+
joinRegistryPath(REGISTRY_BASE_URL, "plate")
|
|
320
|
+
);
|
|
321
|
+
var AI_ELEMENTS_REGISTRY_URL = withFallback(
|
|
322
|
+
process.env.KIVA_AI_ELEMENTS_REGISTRY_URL,
|
|
323
|
+
joinRegistryPath(REGISTRY_BASE_URL, "ai-elements")
|
|
324
|
+
);
|
|
325
|
+
var THEMES_API_URL = resolveThemesApiUrl(REGISTRY_BASE_URL);
|
|
326
|
+
var CLI_NAME = "kiva-ui";
|
|
327
|
+
var CLI_FUNCTION_NAME = "kiva_ui";
|
|
328
|
+
var CLI_VERSION = "0.26.0";
|
|
329
|
+
var NPM_PACKAGE_NAME = "@kivacore/ui-cli";
|
|
330
|
+
|
|
331
|
+
// src/config/config-manager.ts
|
|
332
|
+
var defaults = {
|
|
333
|
+
helpTheme: "default"
|
|
334
|
+
};
|
|
335
|
+
var ConfigManager = class {
|
|
336
|
+
config;
|
|
337
|
+
constructor() {
|
|
338
|
+
this.config = new Conf({
|
|
339
|
+
projectName: CONFIG_PROJECT_NAME,
|
|
340
|
+
defaults
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
get(key) {
|
|
344
|
+
return this.config.get(key);
|
|
345
|
+
}
|
|
346
|
+
set(key, value) {
|
|
347
|
+
this.config.set(key, value);
|
|
348
|
+
}
|
|
349
|
+
get path() {
|
|
350
|
+
return this.config.path;
|
|
351
|
+
}
|
|
352
|
+
};
|
|
353
|
+
var configManager = new ConfigManager();
|
|
354
|
+
|
|
355
|
+
// src/ui/help.ts
|
|
1214
356
|
var palettes = {
|
|
1215
357
|
default: {
|
|
1216
358
|
title: (str) => chalk4.bold.cyan(str),
|
|
@@ -1274,298 +416,45 @@ function getHelpConfig(theme = "default") {
|
|
|
1274
416
|
};
|
|
1275
417
|
}
|
|
1276
418
|
|
|
1277
|
-
// src/
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
const tokenManager = getTokenManager();
|
|
1287
|
-
await tokenManager.setToken(result.tokens.accessToken);
|
|
1288
|
-
if (result.tokens.refreshToken) {
|
|
1289
|
-
await tokenManager.setRefreshToken(result.tokens.refreshToken);
|
|
1290
|
-
}
|
|
1291
|
-
const finalEmail = result.user?.email || userEmail;
|
|
1292
|
-
await tokenManager.setUserEmail(finalEmail);
|
|
1293
|
-
configManager.set("lastLoginEmail", finalEmail);
|
|
1294
|
-
output.success(MESSAGES.LOGIN_SUCCESS(finalEmail), { email: finalEmail });
|
|
1295
|
-
}
|
|
1296
|
-
async function handleSsoLogin() {
|
|
1297
|
-
const result = await loginWithOAuth({
|
|
1298
|
-
onOpeningBrowser: () => {
|
|
1299
|
-
logger.info(MESSAGES.SSO_OPENING_BROWSER);
|
|
1300
|
-
},
|
|
1301
|
-
onWaitingForAuth: (url) => {
|
|
1302
|
-
logger.dim(` ${url}`);
|
|
1303
|
-
logger.info(MESSAGES.SSO_WAITING);
|
|
1304
|
-
}
|
|
1305
|
-
});
|
|
1306
|
-
const tokenManager = getTokenManager();
|
|
1307
|
-
await tokenManager.setToken(result.tokens.accessToken);
|
|
1308
|
-
if (result.tokens.refreshToken) {
|
|
1309
|
-
await tokenManager.setRefreshToken(result.tokens.refreshToken);
|
|
1310
|
-
}
|
|
1311
|
-
let email = result.user?.email;
|
|
1312
|
-
if (!email && result.tokens.accessToken) {
|
|
1313
|
-
try {
|
|
1314
|
-
const userInfo2 = await getUserInfo(result.tokens.accessToken);
|
|
1315
|
-
({ email } = userInfo2);
|
|
1316
|
-
} catch {
|
|
1317
|
-
}
|
|
419
|
+
// src/utils/errors.ts
|
|
420
|
+
var CliError = class extends Error {
|
|
421
|
+
exitCode;
|
|
422
|
+
suggestion;
|
|
423
|
+
constructor(message, exitCode = 1, suggestion) {
|
|
424
|
+
super(message);
|
|
425
|
+
this.name = "CliError";
|
|
426
|
+
this.exitCode = exitCode;
|
|
427
|
+
this.suggestion = suggestion;
|
|
1318
428
|
}
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
output.success("Successfully logged in.");
|
|
429
|
+
};
|
|
430
|
+
var NetworkError = class extends CliError {
|
|
431
|
+
constructor(message = "Network request failed", suggestion) {
|
|
432
|
+
super(message, 1, suggestion || "Please check your internet connection and try again.");
|
|
433
|
+
this.name = "NetworkError";
|
|
1325
434
|
}
|
|
1326
|
-
}
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
output.warn(`Already logged in${email ? ` as ${email}` : ""}. Run \`kiva-ui logout\` first to log in as a different user.`);
|
|
1334
|
-
return;
|
|
1335
|
-
}
|
|
1336
|
-
if (options.email !== void 0) {
|
|
1337
|
-
const emailValue = typeof options.email === "string" ? options.email : void 0;
|
|
1338
|
-
await handleCredentialLogin(emailValue);
|
|
1339
|
-
} else {
|
|
1340
|
-
await handleSsoLogin();
|
|
1341
|
-
}
|
|
1342
|
-
} catch (error) {
|
|
1343
|
-
if (error instanceof AuthenticationError) {
|
|
1344
|
-
output.error(error.message);
|
|
1345
|
-
if (error.suggestion && !output.isJson()) {
|
|
1346
|
-
logger.dim(error.suggestion);
|
|
1347
|
-
}
|
|
1348
|
-
process.exit(error.exitCode);
|
|
1349
|
-
}
|
|
1350
|
-
throw error;
|
|
1351
|
-
}
|
|
1352
|
-
});
|
|
1353
|
-
}
|
|
1354
|
-
function registerLogoutCommand(program2) {
|
|
1355
|
-
program2.command("logout").description("Log out from Kiva").action(async () => {
|
|
1356
|
-
const tokenManager = getTokenManager();
|
|
1357
|
-
if (!await tokenManager.isLoggedIn()) {
|
|
1358
|
-
output.warn(MESSAGES.WHOAMI_NOT_LOGGED_IN);
|
|
1359
|
-
return;
|
|
1360
|
-
}
|
|
1361
|
-
const email = await tokenManager.getUserEmail();
|
|
1362
|
-
await withSpinner(
|
|
1363
|
-
MESSAGES.LOGOUT_IN_PROGRESS,
|
|
1364
|
-
async () => {
|
|
1365
|
-
await tokenManager.clearAll();
|
|
1366
|
-
},
|
|
1367
|
-
{ silent: output.isJson() }
|
|
435
|
+
};
|
|
436
|
+
var ComponentNotFoundError = class extends CliError {
|
|
437
|
+
constructor(name) {
|
|
438
|
+
super(
|
|
439
|
+
`"${name}" not found in the registry.`,
|
|
440
|
+
1,
|
|
441
|
+
"Check the name and try again. Run `kiva-ui add --help` for usage."
|
|
1368
442
|
);
|
|
1369
|
-
|
|
1370
|
-
if (email && !output.isJson()) {
|
|
1371
|
-
logger.dim(`Logged out from ${email}`);
|
|
1372
|
-
}
|
|
1373
|
-
});
|
|
1374
|
-
}
|
|
1375
|
-
|
|
1376
|
-
// src/utils/auth-guard.ts
|
|
1377
|
-
function decodeJwtPayload(token) {
|
|
1378
|
-
try {
|
|
1379
|
-
const parts = token.split(".");
|
|
1380
|
-
if (parts.length !== 3) return null;
|
|
1381
|
-
const payloadPart = parts[1];
|
|
1382
|
-
if (!payloadPart) return null;
|
|
1383
|
-
const payload = Buffer.from(payloadPart, "base64url").toString("utf8");
|
|
1384
|
-
return JSON.parse(payload);
|
|
1385
|
-
} catch {
|
|
1386
|
-
return null;
|
|
1387
|
-
}
|
|
1388
|
-
}
|
|
1389
|
-
function isTokenExpired(token) {
|
|
1390
|
-
const payload = decodeJwtPayload(token);
|
|
1391
|
-
if (!payload?.exp) return false;
|
|
1392
|
-
const expirationTime = payload.exp * 1e3;
|
|
1393
|
-
const now = Date.now();
|
|
1394
|
-
return now >= expirationTime - 3e4;
|
|
1395
|
-
}
|
|
1396
|
-
async function requireAuth() {
|
|
1397
|
-
const tokenManager = getTokenManager();
|
|
1398
|
-
if (!await tokenManager.isLoggedIn()) {
|
|
1399
|
-
throw new NotLoggedInError();
|
|
1400
|
-
}
|
|
1401
|
-
let token = await tokenManager.getToken();
|
|
1402
|
-
if (!token) {
|
|
1403
|
-
throw new NotLoggedInError();
|
|
443
|
+
this.name = "ComponentNotFoundError";
|
|
1404
444
|
}
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
if (newTokens.refreshToken) {
|
|
1415
|
-
await tokenManager.setRefreshToken(newTokens.refreshToken);
|
|
1416
|
-
}
|
|
1417
|
-
token = newTokens.accessToken;
|
|
1418
|
-
} catch (error) {
|
|
1419
|
-
await tokenManager.clearAll();
|
|
1420
|
-
if (error instanceof AuthenticationError) {
|
|
1421
|
-
throw new NotLoggedInError("Your session has expired. Please log in again.");
|
|
1422
|
-
}
|
|
1423
|
-
throw error;
|
|
1424
|
-
}
|
|
445
|
+
};
|
|
446
|
+
var MissingConfigError = class extends CliError {
|
|
447
|
+
constructor() {
|
|
448
|
+
super(
|
|
449
|
+
"components.json not found.",
|
|
450
|
+
1,
|
|
451
|
+
"Run `npx shadcn@latest init` first to initialize your project."
|
|
452
|
+
);
|
|
453
|
+
this.name = "MissingConfigError";
|
|
1425
454
|
}
|
|
1426
|
-
|
|
1427
|
-
}
|
|
1428
|
-
|
|
1429
|
-
// src/commands/whoami.ts
|
|
1430
|
-
function registerWhoamiCommand(program2) {
|
|
1431
|
-
program2.command("whoami").description("Display the current logged-in user").action(async () => {
|
|
1432
|
-
const tokenManager = getTokenManager();
|
|
1433
|
-
const token = await requireAuth();
|
|
1434
|
-
try {
|
|
1435
|
-
const user = await withSpinner(
|
|
1436
|
-
MESSAGES.WHOAMI_FETCHING,
|
|
1437
|
-
() => getUserInfo(token),
|
|
1438
|
-
{ silent: output.isJson() }
|
|
1439
|
-
);
|
|
1440
|
-
if (output.isJson()) {
|
|
1441
|
-
output.set("user", {
|
|
1442
|
-
email: user.email,
|
|
1443
|
-
firstname: user.firstname,
|
|
1444
|
-
lastname: user.lastname
|
|
1445
|
-
});
|
|
1446
|
-
} else {
|
|
1447
|
-
logger.newline();
|
|
1448
|
-
logger.log(`Email: ${user.email}`);
|
|
1449
|
-
if (user.firstname || user.lastname) {
|
|
1450
|
-
const fullName = [user.firstname, user.lastname].filter(Boolean).join(" ");
|
|
1451
|
-
logger.log(`Name: ${fullName}`);
|
|
1452
|
-
}
|
|
1453
|
-
logger.newline();
|
|
1454
|
-
}
|
|
1455
|
-
} catch (error) {
|
|
1456
|
-
const cachedEmail = await tokenManager.getUserEmail();
|
|
1457
|
-
if (cachedEmail) {
|
|
1458
|
-
if (output.isJson()) {
|
|
1459
|
-
output.set("user", { email: cachedEmail, cached: true });
|
|
1460
|
-
} else {
|
|
1461
|
-
logger.newline();
|
|
1462
|
-
logger.log(`Email: ${cachedEmail}`);
|
|
1463
|
-
logger.dim("(Unable to fetch full profile from server)");
|
|
1464
|
-
logger.newline();
|
|
1465
|
-
}
|
|
1466
|
-
} else {
|
|
1467
|
-
throw error;
|
|
1468
|
-
}
|
|
1469
|
-
}
|
|
1470
|
-
});
|
|
1471
|
-
}
|
|
1472
|
-
function createAuthenticatedClient(accessToken) {
|
|
1473
|
-
const apiUrl = configManager.get("apiUrl") || KIVA_API_URL;
|
|
1474
|
-
const client = new RestApiClient({ baseURL: apiUrl });
|
|
1475
|
-
client.setAccessToken(accessToken);
|
|
1476
|
-
return client;
|
|
1477
|
-
}
|
|
1478
|
-
async function downloadOpenApiSpec(accessToken, targetDir, filename = "openapi.json") {
|
|
1479
|
-
const client = createAuthenticatedClient(accessToken);
|
|
1480
|
-
const spec = await client.get("/v1/api/openapi.json");
|
|
1481
|
-
const targetPath = join(targetDir, filename);
|
|
1482
|
-
const targetDirPath = dirname(targetPath);
|
|
1483
|
-
await mkdir(targetDirPath, { recursive: true });
|
|
1484
|
-
await writeFile(targetPath, JSON.stringify(spec, null, 2));
|
|
1485
|
-
return targetPath;
|
|
1486
|
-
}
|
|
455
|
+
};
|
|
1487
456
|
|
|
1488
|
-
// src/commands/
|
|
1489
|
-
function registerGenerateCommand(program2) {
|
|
1490
|
-
const generate = program2.command("generate").description("Generate code from OpenAPI specs (e.g. TanStack Query collections)");
|
|
1491
|
-
generate.command("api-spec").description("Download OpenAPI specification from Kiva API").option("-o, --output <path>", "Output file path", "openapi.json").action(async (options) => {
|
|
1492
|
-
const token = await requireAuth();
|
|
1493
|
-
const outputPath = resolve(options.output);
|
|
1494
|
-
if (!output.isJson()) {
|
|
1495
|
-
logger.info("Downloading OpenAPI specification...");
|
|
1496
|
-
}
|
|
1497
|
-
try {
|
|
1498
|
-
const savedPath = await withSpinner(
|
|
1499
|
-
"Fetching OpenAPI spec from API...",
|
|
1500
|
-
async () => downloadOpenApiSpec(token, dirname(outputPath), outputPath.split("/").pop()),
|
|
1501
|
-
{ silent: output.isJson() }
|
|
1502
|
-
);
|
|
1503
|
-
output.success("OpenAPI specification downloaded!", { path: savedPath });
|
|
1504
|
-
if (!output.isJson()) {
|
|
1505
|
-
logger.dim(`Saved to: ${savedPath}`);
|
|
1506
|
-
}
|
|
1507
|
-
} catch (error) {
|
|
1508
|
-
const message = error instanceof Error ? error.message : "Unknown error";
|
|
1509
|
-
throw new CliError(`Failed to download OpenAPI spec: ${message}`);
|
|
1510
|
-
}
|
|
1511
|
-
});
|
|
1512
|
-
generate.command("db").description("Generate TanStack Query collections from OpenAPI spec").argument("[spec]", "Path to OpenAPI specification file (JSON)").option("-o, --output <dir>", "Output directory (defaults to src in same folder as spec)").option("-w, --watch", "Watch for changes in the spec file").action(async (specPath, options) => {
|
|
1513
|
-
const resolvedPath = findSpecFile(specPath);
|
|
1514
|
-
if (!resolvedPath) {
|
|
1515
|
-
throw new CliError(
|
|
1516
|
-
"OpenAPI spec file not found.",
|
|
1517
|
-
1,
|
|
1518
|
-
"Provide a path: kiva-ui generate db <spec-file>\nOr create one of: openapi.json, api.json, spec.json"
|
|
1519
|
-
);
|
|
1520
|
-
}
|
|
1521
|
-
if (!existsSync(resolvedPath)) {
|
|
1522
|
-
throw new CliError(`OpenAPI spec file not found: ${resolvedPath}`);
|
|
1523
|
-
}
|
|
1524
|
-
const outputDir = options.output || join(dirname(resolvedPath), "src");
|
|
1525
|
-
if (!output.isJson()) {
|
|
1526
|
-
logger.info("TanStack DB Generator");
|
|
1527
|
-
logger.dim(` Spec: ${resolvedPath}`);
|
|
1528
|
-
logger.dim(` Output: ${outputDir}`);
|
|
1529
|
-
logger.newline();
|
|
1530
|
-
}
|
|
1531
|
-
try {
|
|
1532
|
-
const specContent = readFileSync(resolvedPath, "utf-8");
|
|
1533
|
-
const spec = JSON.parse(specContent);
|
|
1534
|
-
await withSpinner(
|
|
1535
|
-
"Generating TanStack Query collections...",
|
|
1536
|
-
async () => {
|
|
1537
|
-
await generateFromOpenAPI(spec, outputDir);
|
|
1538
|
-
},
|
|
1539
|
-
{
|
|
1540
|
-
silent: output.isJson(),
|
|
1541
|
-
successText: "Generation completed!"
|
|
1542
|
-
}
|
|
1543
|
-
);
|
|
1544
|
-
output.success("TanStack Query collections generated successfully!", {
|
|
1545
|
-
spec: resolvedPath,
|
|
1546
|
-
output: outputDir
|
|
1547
|
-
});
|
|
1548
|
-
if (options.watch) {
|
|
1549
|
-
if (!output.isJson()) {
|
|
1550
|
-
logger.info("Watch mode is not yet implemented.");
|
|
1551
|
-
}
|
|
1552
|
-
}
|
|
1553
|
-
} catch (error) {
|
|
1554
|
-
const message = error instanceof Error ? error.message : "Unknown error";
|
|
1555
|
-
throw new CliError(`Generation failed: ${message}`);
|
|
1556
|
-
}
|
|
1557
|
-
});
|
|
1558
|
-
}
|
|
1559
|
-
function findSpecFile(specPath) {
|
|
1560
|
-
if (specPath) {
|
|
1561
|
-
return resolve(specPath);
|
|
1562
|
-
}
|
|
1563
|
-
const defaultSpec = resolve("openapi.json");
|
|
1564
|
-
if (existsSync(defaultSpec)) {
|
|
1565
|
-
return defaultSpec;
|
|
1566
|
-
}
|
|
1567
|
-
return null;
|
|
1568
|
-
}
|
|
457
|
+
// src/commands/upgrade.ts
|
|
1569
458
|
var execAsync = promisify(exec);
|
|
1570
459
|
async function getLatestVersion() {
|
|
1571
460
|
try {
|
|
@@ -1665,12 +554,7 @@ _${CLI_FUNCTION_NAME}_completions() {
|
|
|
1665
554
|
args=("\${COMP_WORDS[@]}")
|
|
1666
555
|
|
|
1667
556
|
# Commands
|
|
1668
|
-
type_list="
|
|
1669
|
-
|
|
1670
|
-
# Subcommands for generate
|
|
1671
|
-
if [[ \${args[1]} == "generate" ]]; then
|
|
1672
|
-
type_list="api-spec db"
|
|
1673
|
-
fi
|
|
557
|
+
type_list="add update migrate list themes commitlint upgrade completion info config help"
|
|
1674
558
|
|
|
1675
559
|
COMPREPLY=($(compgen -W "\${type_list}" -- \${cur_word}))
|
|
1676
560
|
return 0
|
|
@@ -1683,10 +567,6 @@ var ZSH_COMPLETION = `
|
|
|
1683
567
|
_${CLI_FUNCTION_NAME}() {
|
|
1684
568
|
local -a commands
|
|
1685
569
|
commands=(
|
|
1686
|
-
'login:Log in to Kiva'
|
|
1687
|
-
'logout:Log out from Kiva'
|
|
1688
|
-
'whoami:Display the current logged-in user'
|
|
1689
|
-
'generate:Generate code from OpenAPI specs'
|
|
1690
570
|
'upgrade:Upgrade Kiva UI CLI to the latest version'
|
|
1691
571
|
'completion:Generate shell completion script'
|
|
1692
572
|
'add:Add a component from the registry'
|
|
@@ -1700,12 +580,6 @@ _${CLI_FUNCTION_NAME}() {
|
|
|
1700
580
|
'help:Display help for command'
|
|
1701
581
|
)
|
|
1702
582
|
|
|
1703
|
-
local -a generate_commands
|
|
1704
|
-
generate_commands=(
|
|
1705
|
-
'api-spec:Download OpenAPI specification from Kiva API'
|
|
1706
|
-
'db:Generate TanStack Query collections from OpenAPI spec'
|
|
1707
|
-
)
|
|
1708
|
-
|
|
1709
583
|
_arguments -C \\
|
|
1710
584
|
'1: :->command' \\
|
|
1711
585
|
'*::arg:->args'
|
|
@@ -1714,13 +588,6 @@ _${CLI_FUNCTION_NAME}() {
|
|
|
1714
588
|
command)
|
|
1715
589
|
_describe 'command' commands
|
|
1716
590
|
;;
|
|
1717
|
-
args)
|
|
1718
|
-
case $words[1] in
|
|
1719
|
-
generate)
|
|
1720
|
-
_describe 'subcommand' generate_commands
|
|
1721
|
-
;;
|
|
1722
|
-
esac
|
|
1723
|
-
;;
|
|
1724
591
|
esac
|
|
1725
592
|
}
|
|
1726
593
|
compdef _${CLI_FUNCTION_NAME} ${CLI_NAME}
|
|
@@ -1731,10 +598,6 @@ var FISH_COMPLETION = `
|
|
|
1731
598
|
complete -c ${CLI_NAME} -f
|
|
1732
599
|
|
|
1733
600
|
# Commands
|
|
1734
|
-
complete -c ${CLI_NAME} -n "__fish_use_subcommand" -a "login" -d "Log in to Kiva"
|
|
1735
|
-
complete -c ${CLI_NAME} -n "__fish_use_subcommand" -a "logout" -d "Log out from Kiva"
|
|
1736
|
-
complete -c ${CLI_NAME} -n "__fish_use_subcommand" -a "whoami" -d "Display the current logged-in user"
|
|
1737
|
-
complete -c ${CLI_NAME} -n "__fish_use_subcommand" -a "generate" -d "Generate code from OpenAPI specs"
|
|
1738
601
|
complete -c ${CLI_NAME} -n "__fish_use_subcommand" -a "upgrade" -d "Upgrade Kiva UI CLI"
|
|
1739
602
|
complete -c ${CLI_NAME} -n "__fish_use_subcommand" -a "completion" -d "Generate shell completion"
|
|
1740
603
|
complete -c ${CLI_NAME} -n "__fish_use_subcommand" -a "add" -d "Add a component from the registry"
|
|
@@ -1746,10 +609,6 @@ complete -c ${CLI_NAME} -n "__fish_use_subcommand" -a "commitlint" -d "Set up co
|
|
|
1746
609
|
complete -c ${CLI_NAME} -n "__fish_use_subcommand" -a "info" -d "Display CLI and environment information"
|
|
1747
610
|
complete -c ${CLI_NAME} -n "__fish_use_subcommand" -a "config" -d "Show or update configuration"
|
|
1748
611
|
complete -c ${CLI_NAME} -n "__fish_use_subcommand" -a "help" -d "Display help"
|
|
1749
|
-
|
|
1750
|
-
# generate subcommands
|
|
1751
|
-
complete -c ${CLI_NAME} -n "__fish_seen_subcommand_from generate" -a "api-spec" -d "Download OpenAPI specification"
|
|
1752
|
-
complete -c ${CLI_NAME} -n "__fish_seen_subcommand_from generate" -a "db" -d "Generate TanStack Query collections"
|
|
1753
612
|
###-end-${CLI_NAME}-completions-###
|
|
1754
613
|
`.trim();
|
|
1755
614
|
function registerCompletionCommand(program2) {
|
|
@@ -1792,10 +651,7 @@ function registerCompletionCommand(program2) {
|
|
|
1792
651
|
});
|
|
1793
652
|
}
|
|
1794
653
|
function registerInfoCommand(program2) {
|
|
1795
|
-
program2.command("info").description("Display CLI and environment information").action(
|
|
1796
|
-
const tokenManager = getTokenManager();
|
|
1797
|
-
const isLoggedIn = await tokenManager.isLoggedIn();
|
|
1798
|
-
const email = isLoggedIn ? await tokenManager.getUserEmail() : void 0;
|
|
654
|
+
program2.command("info").description("Display CLI and environment information").action(() => {
|
|
1799
655
|
const info = {
|
|
1800
656
|
cli: {
|
|
1801
657
|
name: CLI_NAME,
|
|
@@ -1810,12 +666,8 @@ function registerInfoCommand(program2) {
|
|
|
1810
666
|
arch: arch()
|
|
1811
667
|
},
|
|
1812
668
|
environment: {
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
},
|
|
1816
|
-
auth: {
|
|
1817
|
-
loggedIn: isLoggedIn,
|
|
1818
|
-
...email && { email }
|
|
669
|
+
registryUrl: REGISTRY_BASE_URL,
|
|
670
|
+
configFile: configManager.path
|
|
1819
671
|
}
|
|
1820
672
|
};
|
|
1821
673
|
if (output.isJson()) {
|
|
@@ -1828,40 +680,20 @@ function registerInfoCommand(program2) {
|
|
|
1828
680
|
logger.dim(` OS: ${info.os.platform} ${info.os.release} (${info.os.arch})`);
|
|
1829
681
|
logger.newline();
|
|
1830
682
|
logger.log("Environment:");
|
|
1831
|
-
logger.dim(`
|
|
1832
|
-
logger.dim(` Config: ${info.environment.
|
|
1833
|
-
logger.newline();
|
|
1834
|
-
logger.log("Authentication:");
|
|
1835
|
-
if (info.auth.loggedIn) {
|
|
1836
|
-
logger.dim(` Status: Logged in`);
|
|
1837
|
-
if (info.auth.email) {
|
|
1838
|
-
logger.dim(` Email: ${info.auth.email}`);
|
|
1839
|
-
}
|
|
1840
|
-
} else {
|
|
1841
|
-
logger.dim(` Status: Not logged in`);
|
|
1842
|
-
}
|
|
683
|
+
logger.dim(` Registry: ${info.environment.registryUrl}`);
|
|
684
|
+
logger.dim(` Config: ${info.environment.configFile}`);
|
|
1843
685
|
}
|
|
1844
686
|
});
|
|
1845
687
|
}
|
|
1846
|
-
function showConfig(
|
|
1847
|
-
const currentTheme = configManager.get("helpTheme");
|
|
688
|
+
function showConfig() {
|
|
1848
689
|
logger.log("Current configuration:");
|
|
1849
690
|
logger.newline();
|
|
1850
|
-
logger.log(`
|
|
1851
|
-
logger.log(`
|
|
1852
|
-
logger.log(` Help Theme: ${currentTheme}`);
|
|
691
|
+
logger.log(` Help Theme: ${configManager.get("helpTheme")}`);
|
|
692
|
+
logger.log(` Config File: ${configManager.path}`);
|
|
1853
693
|
logger.newline();
|
|
1854
694
|
}
|
|
1855
695
|
function registerConfigCommand(program2) {
|
|
1856
|
-
program2.command("config").description("Manage CLI configuration").option("--
|
|
1857
|
-
const tokenManager = getTokenManager();
|
|
1858
|
-
if (options.show) {
|
|
1859
|
-
const githubToken2 = await tokenManager.getGithubToken();
|
|
1860
|
-
const isLoggedIn2 = await tokenManager.isLoggedIn();
|
|
1861
|
-
const email2 = await tokenManager.getUserEmail();
|
|
1862
|
-
showConfig(isLoggedIn2, email2, githubToken2);
|
|
1863
|
-
return;
|
|
1864
|
-
}
|
|
696
|
+
program2.command("config").description("Manage CLI configuration").option("--theme", "Change help output color theme").option("--show", "Show current configuration").action(async (options) => {
|
|
1865
697
|
if (options.theme) {
|
|
1866
698
|
const currentTheme = configManager.get("helpTheme");
|
|
1867
699
|
const theme = await select({
|
|
@@ -1876,29 +708,10 @@ function registerConfigCommand(program2) {
|
|
|
1876
708
|
logger.success(`Help theme set to "${theme}"`);
|
|
1877
709
|
return;
|
|
1878
710
|
}
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
logger.log("Current Kiva token will be replaced.");
|
|
1883
|
-
}
|
|
1884
|
-
const newToken = await password({
|
|
1885
|
-
message: MESSAGES.KIVA_TOKEN_PROMPT,
|
|
1886
|
-
mask: "*"
|
|
1887
|
-
});
|
|
1888
|
-
if (newToken) {
|
|
1889
|
-
await tokenManager.setGithubToken(newToken);
|
|
1890
|
-
logger.success(MESSAGES.KIVA_TOKEN_SAVED);
|
|
1891
|
-
} else {
|
|
1892
|
-
logger.warn("No token provided. Token not updated.");
|
|
1893
|
-
}
|
|
1894
|
-
return;
|
|
711
|
+
showConfig();
|
|
712
|
+
if (!options.show) {
|
|
713
|
+
logger.log("To change theme: kiva-ui config --theme");
|
|
1895
714
|
}
|
|
1896
|
-
const githubToken = await tokenManager.getGithubToken();
|
|
1897
|
-
const isLoggedIn = await tokenManager.isLoggedIn();
|
|
1898
|
-
const email = await tokenManager.getUserEmail();
|
|
1899
|
-
showConfig(isLoggedIn, email, githubToken);
|
|
1900
|
-
logger.log("To update token: kiva-ui config --token");
|
|
1901
|
-
logger.log("To change theme: kiva-ui config --theme");
|
|
1902
715
|
});
|
|
1903
716
|
}
|
|
1904
717
|
async function readComponentsJson(projectRoot) {
|
|
@@ -1938,9 +751,25 @@ function buildConfigFromTsconfig(projectRoot) {
|
|
|
1938
751
|
};
|
|
1939
752
|
}
|
|
1940
753
|
|
|
754
|
+
// src/config/component-list.ts
|
|
755
|
+
function parseCsv(value) {
|
|
756
|
+
return (value ?? "").split(",").map((item) => item.trim()).filter(Boolean);
|
|
757
|
+
}
|
|
758
|
+
parseCsv(
|
|
759
|
+
"slate,gray,zinc,neutral,stone,red,orange,amber,yellow,lime,green,emerald,teal,cyan,sky"
|
|
760
|
+
);
|
|
761
|
+
var PLATE_COMPONENTS = parseCsv(
|
|
762
|
+
"@plate/align-base-kit,@plate/align-kit,@plate/autoformat-kit,@plate/basic-blocks-base-kit,@plate/basic-blocks-kit,@plate/basic-marks-base-kit,@plate/basic-marks-kit,@plate/block-menu-kit,@plate/block-placeholder-kit,@plate/block-selection-kit,@plate/callout-base-kit,@plate/callout-kit,@plate/code-block-base-kit,@plate/code-block-kit,@plate/column-base-kit,@plate/column-kit,@plate/comment-base-kit,@plate/comment-kit,@plate/cursor-overlay-kit,@plate/date-base-kit,@plate/date-kit,@plate/discussion-kit,@plate/dnd-kit,@plate/editor-base-kit,@plate/emoji-kit,@plate/exit-break-kit,@plate/fixed-toolbar-kit,@plate/floating-toolbar-kit,@plate/font-base-kit,@plate/font-kit,@plate/indent-base-kit,@plate/indent-kit,@plate/line-height-base-kit,@plate/line-height-kit,@plate/link-base-kit,@plate/link-kit,@plate/list-base-kit,@plate/list-kit,@plate/markdown-kit,@plate/math-base-kit,@plate/math-kit,@plate/media-base-kit,@plate/mention-base-kit,@plate/mention-kit,@plate/suggestion-base-kit,@plate/suggestion-kit,@plate/table-base-kit,@plate/table-kit,@plate/toc-base-kit,@plate/toc-kit,@plate/toggle-base-kit,@plate/toggle-kit,@plate/transforms"
|
|
763
|
+
).map((component) => component.replace(/^@plate\//, ""));
|
|
764
|
+
var AI_ELEMENTS_COMPONENTS = parseCsv(
|
|
765
|
+
"agent,artifact,attachments,audio-player,chain-of-thought,checkpoint,code-block,commit,confirmation,context,conversation,environment-variables,file-tree,image,inline-citation,jsx-preview,message,mic-selector,model-selector,open-in-chat,package-info,persona,plan,prompt-input,queue,reasoning,sandbox,schema-display,shimmer,snippet,sources,speech-input,stack-trace,suggestion,task,terminal,test-results,tool,transcription,voice-selector,web-preview"
|
|
766
|
+
);
|
|
767
|
+
var PLATE_COMPONENTS_SET = new Set(PLATE_COMPONENTS);
|
|
768
|
+
var AI_ELEMENTS_COMPONENTS_SET = new Set(AI_ELEMENTS_COMPONENTS);
|
|
769
|
+
|
|
1941
770
|
// src/utils/dep-versions.ts
|
|
1942
|
-
function parseVersion(
|
|
1943
|
-
const match = /^v?(\d+)(?:\.(\d+))?(?:\.(\d+))?/.exec(
|
|
771
|
+
function parseVersion(input2) {
|
|
772
|
+
const match = /^v?(\d+)(?:\.(\d+))?(?:\.(\d+))?/.exec(input2.trim());
|
|
1944
773
|
if (!match) return null;
|
|
1945
774
|
return [Number(match[1]), Number(match[2] ?? 0), Number(match[3] ?? 0)];
|
|
1946
775
|
}
|
|
@@ -2042,35 +871,26 @@ function detectPackageManager2(projectRoot) {
|
|
|
2042
871
|
}
|
|
2043
872
|
return "npm";
|
|
2044
873
|
}
|
|
2045
|
-
function normalizeRegistryName(
|
|
2046
|
-
if (
|
|
2047
|
-
if (
|
|
2048
|
-
if (
|
|
2049
|
-
if (
|
|
2050
|
-
if (
|
|
2051
|
-
if (/^use-[a-z]/.test(
|
|
2052
|
-
return `@kivacore/ui-${
|
|
874
|
+
function normalizeRegistryName(input2) {
|
|
875
|
+
if (input2.startsWith("@kivacore/")) return input2;
|
|
876
|
+
if (input2.startsWith("@plate/")) return input2;
|
|
877
|
+
if (input2.startsWith("rn-")) return `@kivacore/${input2}`;
|
|
878
|
+
if (input2.startsWith("hooks-")) return `@kivacore/${input2}`;
|
|
879
|
+
if (input2.startsWith("utils-")) return `@kivacore/${input2}`;
|
|
880
|
+
if (/^use-[a-z]/.test(input2)) return `@kivacore/hooks-${input2}`;
|
|
881
|
+
return `@kivacore/ui-${input2}`;
|
|
2053
882
|
}
|
|
2054
883
|
function registryFileName(name) {
|
|
2055
884
|
return name.startsWith("@") ? name.replace("/", "__") : encodeURIComponent(name);
|
|
2056
885
|
}
|
|
2057
|
-
async function fetchRegistryItem(name
|
|
886
|
+
async function fetchRegistryItem(name) {
|
|
2058
887
|
const url = `${REGISTRY_BASE_URL}/${registryFileName(name)}.json`;
|
|
2059
|
-
const headers = {
|
|
2060
|
-
Accept: "application/json"
|
|
2061
|
-
};
|
|
2062
|
-
if (token) {
|
|
2063
|
-
headers.Authorization = `Bearer ${token}`;
|
|
2064
|
-
}
|
|
2065
888
|
let response;
|
|
2066
889
|
try {
|
|
2067
|
-
response = await fetch(url, { headers });
|
|
890
|
+
response = await fetch(url, { headers: { Accept: "application/json" } });
|
|
2068
891
|
} catch {
|
|
2069
892
|
throw new NetworkError();
|
|
2070
893
|
}
|
|
2071
|
-
if (response.status === 401 || response.status === 403) {
|
|
2072
|
-
throw new PremiumAuthError(name);
|
|
2073
|
-
}
|
|
2074
894
|
if (response.status === 404) {
|
|
2075
895
|
throw new ComponentNotFoundError(name);
|
|
2076
896
|
}
|
|
@@ -2079,15 +899,15 @@ async function fetchRegistryItem(name, token) {
|
|
|
2079
899
|
}
|
|
2080
900
|
return response.json();
|
|
2081
901
|
}
|
|
2082
|
-
async function tryFetchRegistryItem(name
|
|
902
|
+
async function tryFetchRegistryItem(name) {
|
|
2083
903
|
try {
|
|
2084
|
-
return await fetchRegistryItem(name
|
|
904
|
+
return await fetchRegistryItem(name);
|
|
2085
905
|
} catch (err) {
|
|
2086
906
|
if (err instanceof ComponentNotFoundError) return null;
|
|
2087
907
|
throw err;
|
|
2088
908
|
}
|
|
2089
909
|
}
|
|
2090
|
-
async function resolveAllDependencies(names,
|
|
910
|
+
async function resolveAllDependencies(names, options) {
|
|
2091
911
|
const items = /* @__PURE__ */ new Map();
|
|
2092
912
|
const vendorDeps = /* @__PURE__ */ new Set();
|
|
2093
913
|
const visited = /* @__PURE__ */ new Set();
|
|
@@ -2101,7 +921,7 @@ async function resolveAllDependencies(names, token, options) {
|
|
|
2101
921
|
let item = null;
|
|
2102
922
|
if (isTopLevel && !options?.skipMissing) {
|
|
2103
923
|
try {
|
|
2104
|
-
item = await fetchRegistryItem(name
|
|
924
|
+
item = await fetchRegistryItem(name);
|
|
2105
925
|
} catch (err) {
|
|
2106
926
|
if (err instanceof ComponentNotFoundError) {
|
|
2107
927
|
const bareName = name.replace(/^@kivacore\/ui-/, "");
|
|
@@ -2111,7 +931,7 @@ async function resolveAllDependencies(names, token, options) {
|
|
|
2111
931
|
throw err;
|
|
2112
932
|
}
|
|
2113
933
|
} else {
|
|
2114
|
-
item = await tryFetchRegistryItem(name
|
|
934
|
+
item = await tryFetchRegistryItem(name);
|
|
2115
935
|
}
|
|
2116
936
|
if (!item) {
|
|
2117
937
|
const bareName = name.replace(/^@kivacore\/ui-/, "");
|
|
@@ -2902,15 +1722,10 @@ Examples:
|
|
|
2902
1722
|
if (config.style.startsWith("base")) {
|
|
2903
1723
|
logger.warn(MESSAGES.ADD_DEPRECATED_BASE_STYLE);
|
|
2904
1724
|
}
|
|
2905
|
-
let token;
|
|
2906
|
-
try {
|
|
2907
|
-
token = await requireAuth();
|
|
2908
|
-
} catch {
|
|
2909
|
-
}
|
|
2910
1725
|
const registryNames = items.map((item) => normalizeRegistryName(item));
|
|
2911
1726
|
const { items: allItems, vendorDeps: resolvedVendorDeps } = await withSpinner(
|
|
2912
1727
|
MESSAGES.ADD_RESOLVING,
|
|
2913
|
-
() => resolveAllDependencies(registryNames
|
|
1728
|
+
() => resolveAllDependencies(registryNames),
|
|
2914
1729
|
{ successText: `Resolved ${registryNames.length} item(s)` }
|
|
2915
1730
|
);
|
|
2916
1731
|
const vendorDeps = Array.from(/* @__PURE__ */ new Set([...resolvedVendorDeps, ...allModeVendorDeps]));
|
|
@@ -4179,11 +2994,6 @@ Dependency reconciliation:
|
|
|
4179
2994
|
logger.dim(` ${installed.join(", ")}`);
|
|
4180
2995
|
logger.newline();
|
|
4181
2996
|
}
|
|
4182
|
-
let token;
|
|
4183
|
-
try {
|
|
4184
|
-
token = await requireAuth();
|
|
4185
|
-
} catch {
|
|
4186
|
-
}
|
|
4187
2997
|
const normalizedTargets = targetComponents.map((name) => normalizeRegistryName(name));
|
|
4188
2998
|
let registryNames = normalizedTargets;
|
|
4189
2999
|
let staleComponents = [];
|
|
@@ -4229,7 +3039,7 @@ Dependency reconciliation:
|
|
|
4229
3039
|
}
|
|
4230
3040
|
const { items: allItems, vendorDeps } = await withSpinner(
|
|
4231
3041
|
MESSAGES.UPDATE_RESOLVING(registryNames.length),
|
|
4232
|
-
() => resolveAllDependencies(registryNames,
|
|
3042
|
+
() => resolveAllDependencies(registryNames, { skipMissing: true })
|
|
4233
3043
|
);
|
|
4234
3044
|
if (allItems.size === 0) {
|
|
4235
3045
|
logger.success(MESSAGES.UPDATE_UP_TO_DATE);
|
|
@@ -4990,13 +3800,9 @@ Examples:
|
|
|
4990
3800
|
|
|
4991
3801
|
// src/commands/index.ts
|
|
4992
3802
|
function registerCommands(program2) {
|
|
4993
|
-
registerLoginCommand(program2);
|
|
4994
|
-
registerLogoutCommand(program2);
|
|
4995
|
-
registerWhoamiCommand(program2);
|
|
4996
3803
|
registerAddCommand(program2);
|
|
4997
3804
|
registerListCommand(program2);
|
|
4998
3805
|
registerCommitlintCommand(program2);
|
|
4999
|
-
registerGenerateCommand(program2);
|
|
5000
3806
|
registerUpgradeCommand(program2);
|
|
5001
3807
|
registerCompletionCommand(program2);
|
|
5002
3808
|
registerInfoCommand(program2);
|
|
@@ -5042,7 +3848,7 @@ async function checkForUpdates(packageName, currentVersion) {
|
|
|
5042
3848
|
|
|
5043
3849
|
// src/cli.ts
|
|
5044
3850
|
var program = new Command();
|
|
5045
|
-
program.name(CLI_NAME).description("Kiva UI CLI -
|
|
3851
|
+
program.name(CLI_NAME).description("Kiva UI CLI - add, update and theme Kiva UI components").version(CLI_VERSION, "-v, --version", "Display version number").option("--json", "Output results in JSON format").configureHelp(getHelpConfig(configManager.get("helpTheme"))).hook("preAction", (thisCommand) => {
|
|
5046
3852
|
const opts = thisCommand.opts();
|
|
5047
3853
|
if (opts.json) {
|
|
5048
3854
|
output.setFormat("json");
|