@zzznpm/clavis 1.2.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 +198 -0
- package/bunfig.toml +1 -0
- package/dist/index.js +2097 -0
- package/dist/tui.js +1568 -0
- package/package.json +52 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,2097 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __esm = (fn, res) => function __init() {
|
|
5
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
6
|
+
};
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
// src/models/Secret.js
|
|
13
|
+
var Secret, Secret_default;
|
|
14
|
+
var init_Secret = __esm({
|
|
15
|
+
"src/models/Secret.js"() {
|
|
16
|
+
Secret = class _Secret {
|
|
17
|
+
constructor({ key, token, expiration = null, tag = "", comment = "", env = "", sid = null }) {
|
|
18
|
+
this.sid = sid;
|
|
19
|
+
this.key = key;
|
|
20
|
+
this.token = token;
|
|
21
|
+
this.expiration = expiration;
|
|
22
|
+
this.tag = tag;
|
|
23
|
+
this.comment = comment;
|
|
24
|
+
this.env = env;
|
|
25
|
+
this.createdAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
26
|
+
this.updatedAt = this.createdAt;
|
|
27
|
+
}
|
|
28
|
+
validate() {
|
|
29
|
+
const errors = [];
|
|
30
|
+
if (!this.key || typeof this.key !== "string" || this.key.trim() === "") {
|
|
31
|
+
errors.push("Key is required and must be a non-empty string");
|
|
32
|
+
}
|
|
33
|
+
if (!this.token || typeof this.token !== "string" || this.token.trim() === "") {
|
|
34
|
+
errors.push("Token is required and must be a non-empty string");
|
|
35
|
+
}
|
|
36
|
+
if (this.expiration && !this.isValidDate(this.expiration)) {
|
|
37
|
+
errors.push("Expiration must be a valid date string");
|
|
38
|
+
}
|
|
39
|
+
return errors;
|
|
40
|
+
}
|
|
41
|
+
isValidDate(dateString) {
|
|
42
|
+
const date = new Date(dateString);
|
|
43
|
+
return date instanceof Date && !isNaN(date);
|
|
44
|
+
}
|
|
45
|
+
toJSON() {
|
|
46
|
+
return {
|
|
47
|
+
sid: this.sid,
|
|
48
|
+
key: this.key,
|
|
49
|
+
token: this.token,
|
|
50
|
+
expiration: this.expiration,
|
|
51
|
+
tag: this.tag,
|
|
52
|
+
comment: this.comment,
|
|
53
|
+
env: this.env,
|
|
54
|
+
createdAt: this.createdAt,
|
|
55
|
+
updatedAt: this.updatedAt
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
static fromJSON(data) {
|
|
59
|
+
const secret = new _Secret(data);
|
|
60
|
+
if (data.sid !== void 0) {
|
|
61
|
+
secret.sid = data.sid;
|
|
62
|
+
}
|
|
63
|
+
if (data.createdAt) {
|
|
64
|
+
secret.createdAt = data.createdAt;
|
|
65
|
+
}
|
|
66
|
+
if (data.updatedAt) {
|
|
67
|
+
secret.updatedAt = data.updatedAt;
|
|
68
|
+
}
|
|
69
|
+
return secret;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
Secret_default = Secret;
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
// src/services/ConfigService.js
|
|
77
|
+
import { promises as fs } from "fs";
|
|
78
|
+
import path from "path";
|
|
79
|
+
import os from "os";
|
|
80
|
+
import { getPassword, setPassword } from "cross-keychain";
|
|
81
|
+
var KEYCHAIN_SERVICE, KEYCHAIN_ACCOUNT_GIST_TOKEN, CONFIG_DIR, CONFIG_FILE, parseTOML, serializeTOML, ConfigService, ConfigService_default;
|
|
82
|
+
var init_ConfigService = __esm({
|
|
83
|
+
"src/services/ConfigService.js"() {
|
|
84
|
+
KEYCHAIN_SERVICE = "clavis";
|
|
85
|
+
KEYCHAIN_ACCOUNT_GIST_TOKEN = "gist-token";
|
|
86
|
+
CONFIG_DIR = process.platform === "win32" ? path.join(process.env.APPDATA || path.join(os.homedir(), "AppData", "Roaming"), "clavis") : path.join(os.homedir(), ".config", "clavis");
|
|
87
|
+
CONFIG_FILE = path.join(CONFIG_DIR, "config.toml");
|
|
88
|
+
parseTOML = (content) => {
|
|
89
|
+
const result = {};
|
|
90
|
+
for (const line of content.split("\n")) {
|
|
91
|
+
const trimmed = line.trim();
|
|
92
|
+
if (!trimmed || trimmed.startsWith("#")) continue;
|
|
93
|
+
const intMatch = trimmed.match(/^(\w+)\s*=\s*(\d+)$/);
|
|
94
|
+
if (intMatch) {
|
|
95
|
+
result[intMatch[1]] = parseInt(intMatch[2], 10);
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
const strMatch = trimmed.match(/^(\w+)\s*=\s*"(.*)"$/);
|
|
99
|
+
if (strMatch) {
|
|
100
|
+
result[strMatch[1]] = strMatch[2];
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return result;
|
|
104
|
+
};
|
|
105
|
+
serializeTOML = (data) => {
|
|
106
|
+
const lines = ["# Clavis configuration", ""];
|
|
107
|
+
for (const [key, value] of Object.entries(data)) {
|
|
108
|
+
if (typeof value === "string") {
|
|
109
|
+
lines.push(`${key} = "${value}"`);
|
|
110
|
+
} else {
|
|
111
|
+
lines.push(`${key} = ${value}`);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return lines.join("\n") + "\n";
|
|
115
|
+
};
|
|
116
|
+
ConfigService = class {
|
|
117
|
+
constructor() {
|
|
118
|
+
this.configFile = CONFIG_FILE;
|
|
119
|
+
this.config = { next_sid: 1 };
|
|
120
|
+
}
|
|
121
|
+
async init() {
|
|
122
|
+
await fs.mkdir(CONFIG_DIR, { recursive: true, mode: 448 });
|
|
123
|
+
try {
|
|
124
|
+
const content = await fs.readFile(this.configFile, "utf8");
|
|
125
|
+
this.config = { next_sid: 1, ...parseTOML(content) };
|
|
126
|
+
} catch (error) {
|
|
127
|
+
if (error.code !== "ENOENT") throw error;
|
|
128
|
+
await this.save();
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
async save() {
|
|
132
|
+
await fs.mkdir(path.dirname(this.configFile), { recursive: true, mode: 448 });
|
|
133
|
+
await fs.writeFile(this.configFile, serializeTOML(this.config), "utf8");
|
|
134
|
+
}
|
|
135
|
+
/** Returns the next sid and increments the counter in config.toml */
|
|
136
|
+
async getNextSid() {
|
|
137
|
+
const sid = this.config.next_sid;
|
|
138
|
+
this.config.next_sid = sid + 1;
|
|
139
|
+
await this.save();
|
|
140
|
+
return sid;
|
|
141
|
+
}
|
|
142
|
+
/** Returns the current next_sid value without incrementing */
|
|
143
|
+
peekNextSid() {
|
|
144
|
+
return this.config.next_sid;
|
|
145
|
+
}
|
|
146
|
+
/** Sets the next_sid value */
|
|
147
|
+
async setNextSid(sid) {
|
|
148
|
+
this.config.next_sid = sid;
|
|
149
|
+
await this.save();
|
|
150
|
+
}
|
|
151
|
+
/** Retrieves the GitHub token from the OS keychain */
|
|
152
|
+
getGistToken() {
|
|
153
|
+
return getPassword(KEYCHAIN_SERVICE, KEYCHAIN_ACCOUNT_GIST_TOKEN).then((val) => val || null);
|
|
154
|
+
}
|
|
155
|
+
/** Stores the GitHub token in the OS keychain */
|
|
156
|
+
async setGistToken(token) {
|
|
157
|
+
await setPassword(KEYCHAIN_SERVICE, KEYCHAIN_ACCOUNT_GIST_TOKEN, token);
|
|
158
|
+
}
|
|
159
|
+
getGistId() {
|
|
160
|
+
return this.config.gist_id || null;
|
|
161
|
+
}
|
|
162
|
+
async setGistId(id) {
|
|
163
|
+
this.config.gist_id = id;
|
|
164
|
+
await this.save();
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
ConfigService_default = ConfigService;
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
// src/services/CryptoService.js
|
|
172
|
+
import { createCipheriv, createDecipheriv, createHash, randomBytes } from "crypto";
|
|
173
|
+
import { getPassword as getPassword2 } from "cross-keychain";
|
|
174
|
+
var KEYCHAIN_SERVICE2, KEYCHAIN_ACCOUNT, ENC_PREFIX, cachedKey, getAesKey, encrypt, decrypt;
|
|
175
|
+
var init_CryptoService = __esm({
|
|
176
|
+
"src/services/CryptoService.js"() {
|
|
177
|
+
KEYCHAIN_SERVICE2 = "clavis";
|
|
178
|
+
KEYCHAIN_ACCOUNT = "master";
|
|
179
|
+
ENC_PREFIX = "enc:";
|
|
180
|
+
cachedKey = null;
|
|
181
|
+
getAesKey = () => {
|
|
182
|
+
if (cachedKey) return Promise.resolve(cachedKey);
|
|
183
|
+
return getPassword2(KEYCHAIN_SERVICE2, KEYCHAIN_ACCOUNT).then((password) => {
|
|
184
|
+
if (!password) throw new Error("Master password not found in keychain. Run: clavis add pwd");
|
|
185
|
+
cachedKey = createHash("sha256").update(password).digest();
|
|
186
|
+
return cachedKey;
|
|
187
|
+
});
|
|
188
|
+
};
|
|
189
|
+
encrypt = (plaintext) => getAesKey().then((key) => {
|
|
190
|
+
const iv = randomBytes(12);
|
|
191
|
+
const cipher = createCipheriv("aes-256-gcm", key, iv);
|
|
192
|
+
const ciphertext = Buffer.concat([cipher.update(plaintext, "utf8"), cipher.final()]);
|
|
193
|
+
const authTag = cipher.getAuthTag();
|
|
194
|
+
const payload = Buffer.concat([iv, authTag, ciphertext]);
|
|
195
|
+
return `${ENC_PREFIX}${payload.toString("base64")}`;
|
|
196
|
+
});
|
|
197
|
+
decrypt = (value) => {
|
|
198
|
+
if (!value || !value.startsWith(ENC_PREFIX)) return Promise.resolve(value);
|
|
199
|
+
return getAesKey().then((key) => {
|
|
200
|
+
const payload = Buffer.from(value.slice(ENC_PREFIX.length), "base64");
|
|
201
|
+
if (payload.length < 28) return Promise.reject(new Error("Corrupted encrypted value: payload too short"));
|
|
202
|
+
const iv = payload.subarray(0, 12);
|
|
203
|
+
const authTag = payload.subarray(12, 28);
|
|
204
|
+
const ciphertext = payload.subarray(28);
|
|
205
|
+
const decipher = createDecipheriv("aes-256-gcm", key, iv);
|
|
206
|
+
decipher.setAuthTag(authTag);
|
|
207
|
+
return Buffer.concat([decipher.update(ciphertext), decipher.final()]).toString("utf8");
|
|
208
|
+
});
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
// src/utils/validators.js
|
|
214
|
+
function validateKey(key) {
|
|
215
|
+
if (!key || typeof key !== "string") {
|
|
216
|
+
return { valid: false, error: "Key must be a string" };
|
|
217
|
+
}
|
|
218
|
+
const trimmedKey = key.trim();
|
|
219
|
+
if (trimmedKey === "") {
|
|
220
|
+
return { valid: false, error: "Key cannot be empty" };
|
|
221
|
+
}
|
|
222
|
+
if (trimmedKey.includes("..")) {
|
|
223
|
+
return { valid: false, error: "Key cannot contain consecutive dots" };
|
|
224
|
+
}
|
|
225
|
+
if (trimmedKey.startsWith(".") || trimmedKey.endsWith(".")) {
|
|
226
|
+
return { valid: false, error: "Key cannot start or end with a dot" };
|
|
227
|
+
}
|
|
228
|
+
const parts = trimmedKey.split(".");
|
|
229
|
+
for (const part of parts) {
|
|
230
|
+
if (part.trim() === "") {
|
|
231
|
+
return { valid: false, error: "Key parts cannot be empty" };
|
|
232
|
+
}
|
|
233
|
+
if (!/^[a-zA-Z0-9_-]+$/.test(part)) {
|
|
234
|
+
return { valid: false, error: `Key part "${part}" contains invalid characters. Only letters, numbers, underscores and hyphens are allowed` };
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
return { valid: true };
|
|
238
|
+
}
|
|
239
|
+
function validateToken(token) {
|
|
240
|
+
if (!token || typeof token !== "string") {
|
|
241
|
+
return { valid: false, error: "Token must be a string" };
|
|
242
|
+
}
|
|
243
|
+
const trimmedToken = token.trim();
|
|
244
|
+
if (trimmedToken === "") {
|
|
245
|
+
return { valid: false, error: "Token cannot be empty" };
|
|
246
|
+
}
|
|
247
|
+
if (trimmedToken.length < 8) {
|
|
248
|
+
return { valid: false, error: "Token must be at least 8 characters long" };
|
|
249
|
+
}
|
|
250
|
+
return { valid: true };
|
|
251
|
+
}
|
|
252
|
+
function validateDate(dateString) {
|
|
253
|
+
if (!dateString) {
|
|
254
|
+
return { valid: true };
|
|
255
|
+
}
|
|
256
|
+
const date = new Date(dateString);
|
|
257
|
+
if (isNaN(date.getTime())) {
|
|
258
|
+
return { valid: false, error: "Invalid date format. Use YYYY-MM-DD" };
|
|
259
|
+
}
|
|
260
|
+
return { valid: true };
|
|
261
|
+
}
|
|
262
|
+
function validateTag(tag) {
|
|
263
|
+
if (!tag) {
|
|
264
|
+
return { valid: true };
|
|
265
|
+
}
|
|
266
|
+
if (typeof tag !== "string") {
|
|
267
|
+
return { valid: false, error: "Tag must be a string" };
|
|
268
|
+
}
|
|
269
|
+
if (tag.length > 50) {
|
|
270
|
+
return { valid: false, error: "Tag cannot exceed 50 characters" };
|
|
271
|
+
}
|
|
272
|
+
return { valid: true };
|
|
273
|
+
}
|
|
274
|
+
function validateComment(comment) {
|
|
275
|
+
if (!comment) {
|
|
276
|
+
return { valid: true };
|
|
277
|
+
}
|
|
278
|
+
if (typeof comment !== "string") {
|
|
279
|
+
return { valid: false, error: "Comment must be a string" };
|
|
280
|
+
}
|
|
281
|
+
if (comment.length > 500) {
|
|
282
|
+
return { valid: false, error: "Comment cannot exceed 500 characters" };
|
|
283
|
+
}
|
|
284
|
+
return { valid: true };
|
|
285
|
+
}
|
|
286
|
+
function validateEnv(env) {
|
|
287
|
+
if (!env) {
|
|
288
|
+
return { valid: true };
|
|
289
|
+
}
|
|
290
|
+
if (typeof env !== "string") {
|
|
291
|
+
return { valid: false, error: "Env must be a string" };
|
|
292
|
+
}
|
|
293
|
+
if (env.length > 100) {
|
|
294
|
+
return { valid: false, error: "Env cannot exceed 100 characters" };
|
|
295
|
+
}
|
|
296
|
+
if (!/^[A-Z_][A-Z0-9_]*$/.test(env)) {
|
|
297
|
+
return { valid: false, error: "Env must contain only uppercase letters, numbers, and underscores, and start with a letter or underscore" };
|
|
298
|
+
}
|
|
299
|
+
return { valid: true };
|
|
300
|
+
}
|
|
301
|
+
var init_validators = __esm({
|
|
302
|
+
"src/utils/validators.js"() {
|
|
303
|
+
}
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
// src/services/SecretStorage.js
|
|
307
|
+
import { promises as fs2 } from "fs";
|
|
308
|
+
import os2 from "os";
|
|
309
|
+
import path2 from "path";
|
|
310
|
+
var getDefaultDataDir, SecretStorage, SecretStorage_default;
|
|
311
|
+
var init_SecretStorage = __esm({
|
|
312
|
+
"src/services/SecretStorage.js"() {
|
|
313
|
+
init_Secret();
|
|
314
|
+
init_ConfigService();
|
|
315
|
+
init_CryptoService();
|
|
316
|
+
init_validators();
|
|
317
|
+
getDefaultDataDir = () => {
|
|
318
|
+
if (process.platform === "win32") {
|
|
319
|
+
const appData = process.env.APPDATA || path2.join(os2.homedir(), "AppData", "Roaming");
|
|
320
|
+
return path2.join(appData, "clavis");
|
|
321
|
+
}
|
|
322
|
+
const xdgDataHome = process.env.XDG_DATA_HOME || path2.join(os2.homedir(), ".local", "share");
|
|
323
|
+
return path2.join(xdgDataHome, "clavis");
|
|
324
|
+
};
|
|
325
|
+
SecretStorage = class {
|
|
326
|
+
constructor(dataDir = getDefaultDataDir()) {
|
|
327
|
+
this.dataDir = path2.resolve(dataDir);
|
|
328
|
+
this.dataFile = path2.join(this.dataDir, "tokens.json");
|
|
329
|
+
this.secrets = /* @__PURE__ */ new Map();
|
|
330
|
+
this.config = new ConfigService_default();
|
|
331
|
+
}
|
|
332
|
+
async init() {
|
|
333
|
+
await this.config.init();
|
|
334
|
+
try {
|
|
335
|
+
await fs2.mkdir(this.dataDir, { recursive: true, mode: 448 });
|
|
336
|
+
await this.load();
|
|
337
|
+
} catch (error) {
|
|
338
|
+
if (error.code !== "ENOENT") {
|
|
339
|
+
throw error;
|
|
340
|
+
}
|
|
341
|
+
await this.save();
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
async load() {
|
|
345
|
+
try {
|
|
346
|
+
const data = await fs2.readFile(this.dataFile, "utf8");
|
|
347
|
+
const parsed = JSON.parse(data);
|
|
348
|
+
const tokensData = Array.isArray(parsed) ? parsed : parsed.tokens;
|
|
349
|
+
const decrypted = await Promise.all(
|
|
350
|
+
tokensData.map(
|
|
351
|
+
(entry) => decrypt(entry.token).then((tokenValue) => ({ ...entry, token: tokenValue }))
|
|
352
|
+
)
|
|
353
|
+
);
|
|
354
|
+
this.secrets.clear();
|
|
355
|
+
decrypted.forEach((secretData) => {
|
|
356
|
+
const secret = Secret_default.fromJSON(secretData);
|
|
357
|
+
this.secrets.set(secret.key, secret);
|
|
358
|
+
});
|
|
359
|
+
} catch (error) {
|
|
360
|
+
if (error.code === "ENOENT") {
|
|
361
|
+
this.secrets.clear();
|
|
362
|
+
} else {
|
|
363
|
+
throw error;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
async save() {
|
|
368
|
+
const tokensArray = await Promise.all(
|
|
369
|
+
Array.from(this.secrets.values()).map(
|
|
370
|
+
(secret) => encrypt(secret.token).then((encryptedToken) => ({
|
|
371
|
+
...secret.toJSON(),
|
|
372
|
+
token: encryptedToken
|
|
373
|
+
}))
|
|
374
|
+
)
|
|
375
|
+
);
|
|
376
|
+
const fileData = {
|
|
377
|
+
sid: this.config.peekNextSid(),
|
|
378
|
+
tokens: tokensArray
|
|
379
|
+
};
|
|
380
|
+
const data = JSON.stringify(fileData, null, 2);
|
|
381
|
+
await fs2.writeFile(this.dataFile, data, "utf8");
|
|
382
|
+
}
|
|
383
|
+
async create(secretData) {
|
|
384
|
+
const validationResults = [
|
|
385
|
+
validateKey(secretData.key),
|
|
386
|
+
validateToken(secretData.token),
|
|
387
|
+
validateDate(secretData.expiration),
|
|
388
|
+
validateTag(secretData.tag),
|
|
389
|
+
validateComment(secretData.comment),
|
|
390
|
+
validateEnv(secretData.env)
|
|
391
|
+
];
|
|
392
|
+
const errors = validationResults.filter((result) => !result.valid).map((result) => result.error);
|
|
393
|
+
if (errors.length > 0) {
|
|
394
|
+
throw new Error(`Validation failed: ${errors.join(", ")}`);
|
|
395
|
+
}
|
|
396
|
+
if (this.secrets.has(secretData.key)) {
|
|
397
|
+
throw new Error(`Secret with key "${secretData.key}" already exists`);
|
|
398
|
+
}
|
|
399
|
+
const sid = await this.config.getNextSid();
|
|
400
|
+
const secret = new Secret_default({ ...secretData, sid });
|
|
401
|
+
this.secrets.set(secret.key, secret);
|
|
402
|
+
await this.save();
|
|
403
|
+
return secret;
|
|
404
|
+
}
|
|
405
|
+
async update(key, updates) {
|
|
406
|
+
const secret = this.secrets.get(key);
|
|
407
|
+
if (!secret) {
|
|
408
|
+
throw new Error(`Secret with key "${key}" not found`);
|
|
409
|
+
}
|
|
410
|
+
const updatedData = {
|
|
411
|
+
...secret.toJSON(),
|
|
412
|
+
...updates,
|
|
413
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
414
|
+
};
|
|
415
|
+
const validationResults = [
|
|
416
|
+
updates.key !== void 0 ? validateKey(updates.key) : { valid: true },
|
|
417
|
+
updates.token !== void 0 ? validateToken(updates.token) : { valid: true },
|
|
418
|
+
updates.expiration !== void 0 ? validateDate(updates.expiration) : { valid: true },
|
|
419
|
+
updates.tag !== void 0 ? validateTag(updates.tag) : { valid: true },
|
|
420
|
+
updates.comment !== void 0 ? validateComment(updates.comment) : { valid: true },
|
|
421
|
+
updates.env !== void 0 ? validateEnv(updates.env) : { valid: true }
|
|
422
|
+
];
|
|
423
|
+
const errors = validationResults.filter((result) => !result.valid).map((result) => result.error);
|
|
424
|
+
if (errors.length > 0) {
|
|
425
|
+
throw new Error(`Validation failed: ${errors.join(", ")}`);
|
|
426
|
+
}
|
|
427
|
+
const newKey = updates.key !== void 0 ? updates.key : key;
|
|
428
|
+
if (newKey !== key && this.secrets.has(newKey)) {
|
|
429
|
+
throw new Error(`Secret with key "${newKey}" already exists`);
|
|
430
|
+
}
|
|
431
|
+
const updatedSecret = new Secret_default(updatedData);
|
|
432
|
+
if (newKey !== key) {
|
|
433
|
+
this.secrets.delete(key);
|
|
434
|
+
}
|
|
435
|
+
this.secrets.set(newKey, updatedSecret);
|
|
436
|
+
await this.save();
|
|
437
|
+
return updatedSecret;
|
|
438
|
+
}
|
|
439
|
+
async delete(key) {
|
|
440
|
+
if (!this.secrets.has(key)) {
|
|
441
|
+
throw new Error(`Secret with key "${key}" not found`);
|
|
442
|
+
}
|
|
443
|
+
this.secrets.delete(key);
|
|
444
|
+
await this.save();
|
|
445
|
+
return true;
|
|
446
|
+
}
|
|
447
|
+
get(key) {
|
|
448
|
+
return this.secrets.get(key);
|
|
449
|
+
}
|
|
450
|
+
getAll() {
|
|
451
|
+
return Array.from(this.secrets.values());
|
|
452
|
+
}
|
|
453
|
+
searchByKey(pattern) {
|
|
454
|
+
const secrets = this.getAll();
|
|
455
|
+
if (!pattern || pattern.trim() === "") {
|
|
456
|
+
return secrets;
|
|
457
|
+
}
|
|
458
|
+
const searchPattern = pattern.toLowerCase();
|
|
459
|
+
return secrets.filter(
|
|
460
|
+
(secret) => secret.key.toLowerCase().includes(searchPattern) || secret.key.toLowerCase().split(".").some((part) => part.includes(searchPattern))
|
|
461
|
+
);
|
|
462
|
+
}
|
|
463
|
+
getBySid(sid) {
|
|
464
|
+
const sidNum = Number(sid);
|
|
465
|
+
return Array.from(this.secrets.values()).find((secret) => secret.sid === sidNum) || null;
|
|
466
|
+
}
|
|
467
|
+
searchByTag(tag) {
|
|
468
|
+
const secrets = this.getAll();
|
|
469
|
+
if (!tag || tag.trim() === "") {
|
|
470
|
+
return secrets;
|
|
471
|
+
}
|
|
472
|
+
const searchTag = tag.toLowerCase();
|
|
473
|
+
return secrets.filter(
|
|
474
|
+
(secret) => secret.tag && secret.tag.toLowerCase().includes(searchTag)
|
|
475
|
+
);
|
|
476
|
+
}
|
|
477
|
+
clear() {
|
|
478
|
+
this.secrets.clear();
|
|
479
|
+
return this.save();
|
|
480
|
+
}
|
|
481
|
+
};
|
|
482
|
+
SecretStorage_default = SecretStorage;
|
|
483
|
+
}
|
|
484
|
+
});
|
|
485
|
+
|
|
486
|
+
// src/tui/theme.js
|
|
487
|
+
var theme;
|
|
488
|
+
var init_theme = __esm({
|
|
489
|
+
"src/tui/theme.js"() {
|
|
490
|
+
theme = {
|
|
491
|
+
text: "white",
|
|
492
|
+
muted: "gray",
|
|
493
|
+
accent: "cyan",
|
|
494
|
+
focusBackground: "cyan",
|
|
495
|
+
focusText: "black",
|
|
496
|
+
success: "green",
|
|
497
|
+
warning: "yellow",
|
|
498
|
+
danger: "red"
|
|
499
|
+
};
|
|
500
|
+
}
|
|
501
|
+
});
|
|
502
|
+
|
|
503
|
+
// src/tui/utils/format.js
|
|
504
|
+
import { format, differenceInDays, parseISO } from "date-fns";
|
|
505
|
+
function getSecretStatus(secret) {
|
|
506
|
+
if (!secret.expiration) {
|
|
507
|
+
return {
|
|
508
|
+
char: "\u2713",
|
|
509
|
+
color: theme.success,
|
|
510
|
+
label: "Active"
|
|
511
|
+
};
|
|
512
|
+
}
|
|
513
|
+
const expDate = parseISO(secret.expiration);
|
|
514
|
+
const now = /* @__PURE__ */ new Date();
|
|
515
|
+
const diffDays = differenceInDays(expDate, now);
|
|
516
|
+
if (diffDays < 0) {
|
|
517
|
+
return {
|
|
518
|
+
char: "\u2717",
|
|
519
|
+
color: theme.danger,
|
|
520
|
+
label: "Expired"
|
|
521
|
+
};
|
|
522
|
+
}
|
|
523
|
+
if (diffDays <= 7) {
|
|
524
|
+
return {
|
|
525
|
+
char: "!",
|
|
526
|
+
color: theme.warning,
|
|
527
|
+
label: `Expires in ${diffDays}d`
|
|
528
|
+
};
|
|
529
|
+
}
|
|
530
|
+
return {
|
|
531
|
+
char: "\u2713",
|
|
532
|
+
color: theme.success,
|
|
533
|
+
label: "Active"
|
|
534
|
+
};
|
|
535
|
+
}
|
|
536
|
+
function truncateKey(key, width) {
|
|
537
|
+
if (!key || key.length <= width) {
|
|
538
|
+
return key.padEnd(width);
|
|
539
|
+
}
|
|
540
|
+
const parts = key.split(".");
|
|
541
|
+
let result = "";
|
|
542
|
+
for (let i = parts.length - 1; i >= 0; i--) {
|
|
543
|
+
const newResult = (i > 0 ? "\u2026" : "") + parts.slice(i).join(".");
|
|
544
|
+
if (newResult.length <= width) {
|
|
545
|
+
result = newResult;
|
|
546
|
+
} else {
|
|
547
|
+
break;
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
return (result || key.slice(-width)).padEnd(width);
|
|
551
|
+
}
|
|
552
|
+
function truncateTag(tag, width) {
|
|
553
|
+
if (!tag || tag === "") {
|
|
554
|
+
return "-".padEnd(width);
|
|
555
|
+
}
|
|
556
|
+
if (tag.length <= width) {
|
|
557
|
+
return tag.padEnd(width);
|
|
558
|
+
}
|
|
559
|
+
return (tag.slice(0, width - 1) + "\u2026").padEnd(width);
|
|
560
|
+
}
|
|
561
|
+
function formatExpiration(expiration, width = 12) {
|
|
562
|
+
if (!expiration) {
|
|
563
|
+
return "Never".padStart(width);
|
|
564
|
+
}
|
|
565
|
+
const expDate = parseISO(expiration);
|
|
566
|
+
const now = /* @__PURE__ */ new Date();
|
|
567
|
+
const diffDays = differenceInDays(expDate, now);
|
|
568
|
+
if (diffDays < 0) {
|
|
569
|
+
return format(expDate, "yyyy-MM-dd").padStart(width);
|
|
570
|
+
}
|
|
571
|
+
if (diffDays <= 7) {
|
|
572
|
+
return `${diffDays}d`.padStart(width);
|
|
573
|
+
}
|
|
574
|
+
return format(expDate, "yyyy-MM-dd").padStart(width);
|
|
575
|
+
}
|
|
576
|
+
function formatCreatedAt(createdAt, width = 10) {
|
|
577
|
+
if (!createdAt) {
|
|
578
|
+
return "-".padStart(width);
|
|
579
|
+
}
|
|
580
|
+
return format(parseISO(createdAt), "yyyy-MM-dd").padStart(width);
|
|
581
|
+
}
|
|
582
|
+
function previewToken(token, width = 20) {
|
|
583
|
+
if (!token || token.length <= 12) {
|
|
584
|
+
return (token || "").padEnd(width);
|
|
585
|
+
}
|
|
586
|
+
const preview = token.slice(0, 8) + "\u2026" + token.slice(-4);
|
|
587
|
+
return preview.padEnd(width);
|
|
588
|
+
}
|
|
589
|
+
function calculateColumnWidths(terminalWidth) {
|
|
590
|
+
const minWidths = {
|
|
591
|
+
key: 20,
|
|
592
|
+
tag: 15,
|
|
593
|
+
expires: 12,
|
|
594
|
+
created: 10,
|
|
595
|
+
token: 20
|
|
596
|
+
};
|
|
597
|
+
const columnSpacing = 4;
|
|
598
|
+
const totalMinWidth = Object.values(minWidths).reduce((a, b) => a + b, 0) + columnSpacing;
|
|
599
|
+
if (terminalWidth >= totalMinWidth + 20) {
|
|
600
|
+
const extraWidth = terminalWidth - totalMinWidth;
|
|
601
|
+
return {
|
|
602
|
+
...minWidths,
|
|
603
|
+
key: minWidths.key + Math.floor(extraWidth * 0.6),
|
|
604
|
+
tag: minWidths.tag + Math.floor(extraWidth * 0.2),
|
|
605
|
+
token: minWidths.token + Math.floor(extraWidth * 0.2)
|
|
606
|
+
};
|
|
607
|
+
}
|
|
608
|
+
if (terminalWidth >= totalMinWidth) {
|
|
609
|
+
return minWidths;
|
|
610
|
+
}
|
|
611
|
+
const scale = (terminalWidth - columnSpacing) / (totalMinWidth - columnSpacing);
|
|
612
|
+
return {
|
|
613
|
+
key: Math.max(10, Math.floor(minWidths.key * scale)),
|
|
614
|
+
tag: Math.max(8, Math.floor(minWidths.tag * scale)),
|
|
615
|
+
expires: Math.max(8, Math.floor(minWidths.expires * scale)),
|
|
616
|
+
created: Math.max(8, Math.floor(minWidths.created * scale)),
|
|
617
|
+
token: Math.max(12, Math.floor(minWidths.token * scale))
|
|
618
|
+
};
|
|
619
|
+
}
|
|
620
|
+
var init_format = __esm({
|
|
621
|
+
"src/tui/utils/format.js"() {
|
|
622
|
+
init_theme();
|
|
623
|
+
}
|
|
624
|
+
});
|
|
625
|
+
|
|
626
|
+
// src/tui/components/SecretTable.jsx
|
|
627
|
+
import { memo as _$memo } from "@opentui/solid";
|
|
628
|
+
import { insert as _$insert } from "@opentui/solid";
|
|
629
|
+
import { effect as _$effect } from "@opentui/solid";
|
|
630
|
+
import { createTextNode as _$createTextNode } from "@opentui/solid";
|
|
631
|
+
import { insertNode as _$insertNode } from "@opentui/solid";
|
|
632
|
+
import { setProp as _$setProp } from "@opentui/solid";
|
|
633
|
+
import { createElement as _$createElement } from "@opentui/solid";
|
|
634
|
+
import { createMemo } from "solid-js";
|
|
635
|
+
import { useTerminalDimensions } from "@opentui/solid";
|
|
636
|
+
var SecretTable, SecretTable_default;
|
|
637
|
+
var init_SecretTable = __esm({
|
|
638
|
+
"src/tui/components/SecretTable.jsx"() {
|
|
639
|
+
init_theme();
|
|
640
|
+
init_format();
|
|
641
|
+
SecretTable = (props) => {
|
|
642
|
+
const dimensions = useTerminalDimensions();
|
|
643
|
+
const widths = createMemo(() => calculateColumnWidths(dimensions().width || 80));
|
|
644
|
+
const visibleRows = createMemo(() => Math.max(5, dimensions().height - 10));
|
|
645
|
+
const startIndex = createMemo(() => Math.max(0, props.selectedIndex - visibleRows() + 1));
|
|
646
|
+
const visibleTokens = createMemo(() => props.tokens.slice(startIndex(), startIndex() + visibleRows()));
|
|
647
|
+
if (props.tokens.length === 0) return (() => {
|
|
648
|
+
var _el$ = _$createElement("box"), _el$2 = _$createElement("text");
|
|
649
|
+
_$insertNode(_el$, _el$2);
|
|
650
|
+
_$setProp(_el$, "border", true);
|
|
651
|
+
_$setProp(_el$, "borderStyle", "rounded");
|
|
652
|
+
_$setProp(_el$, "padding", 2);
|
|
653
|
+
_$setProp(_el$, "flexGrow", 1);
|
|
654
|
+
_$setProp(_el$, "justifyContent", "center");
|
|
655
|
+
_$setProp(_el$, "alignItems", "center");
|
|
656
|
+
_$insertNode(_el$2, _$createTextNode(`No secrets found. Press 'q' to quit.`));
|
|
657
|
+
_$effect((_p$) => {
|
|
658
|
+
var _v$ = theme.muted, _v$2 = theme.warning;
|
|
659
|
+
_v$ !== _p$.e && (_p$.e = _$setProp(_el$, "borderColor", _v$, _p$.e));
|
|
660
|
+
_v$2 !== _p$.t && (_p$.t = _$setProp(_el$2, "fg", _v$2, _p$.t));
|
|
661
|
+
return _p$;
|
|
662
|
+
}, {
|
|
663
|
+
e: void 0,
|
|
664
|
+
t: void 0
|
|
665
|
+
});
|
|
666
|
+
return _el$;
|
|
667
|
+
})();
|
|
668
|
+
const header = () => {
|
|
669
|
+
const width = widths();
|
|
670
|
+
return (() => {
|
|
671
|
+
var _el$4 = _$createElement("box"), _el$5 = _$createElement("text"), _el$7 = _$createElement("text"), _el$9 = _$createElement("text"), _el$1 = _$createElement("text"), _el$11 = _$createElement("text"), _el$13 = _$createElement("text"), _el$15 = _$createElement("text"), _el$17 = _$createElement("text"), _el$19 = _$createElement("text");
|
|
672
|
+
_$insertNode(_el$4, _el$5);
|
|
673
|
+
_$insertNode(_el$4, _el$7);
|
|
674
|
+
_$insertNode(_el$4, _el$9);
|
|
675
|
+
_$insertNode(_el$4, _el$1);
|
|
676
|
+
_$insertNode(_el$4, _el$11);
|
|
677
|
+
_$insertNode(_el$4, _el$13);
|
|
678
|
+
_$insertNode(_el$4, _el$15);
|
|
679
|
+
_$insertNode(_el$4, _el$17);
|
|
680
|
+
_$insertNode(_el$4, _el$19);
|
|
681
|
+
_$setProp(_el$4, "flexDirection", "row");
|
|
682
|
+
_$insertNode(_el$5, _$createTextNode(`Key`));
|
|
683
|
+
_$setProp(_el$5, "bold", true);
|
|
684
|
+
_$insertNode(_el$7, _$createTextNode(` `));
|
|
685
|
+
_$insertNode(_el$9, _$createTextNode(`Tag`));
|
|
686
|
+
_$setProp(_el$9, "bold", true);
|
|
687
|
+
_$insertNode(_el$1, _$createTextNode(` `));
|
|
688
|
+
_$insertNode(_el$11, _$createTextNode(`Expires`));
|
|
689
|
+
_$setProp(_el$11, "bold", true);
|
|
690
|
+
_$insertNode(_el$13, _$createTextNode(` `));
|
|
691
|
+
_$insertNode(_el$15, _$createTextNode(`Created`));
|
|
692
|
+
_$setProp(_el$15, "bold", true);
|
|
693
|
+
_$insertNode(_el$17, _$createTextNode(` `));
|
|
694
|
+
_$insertNode(_el$19, _$createTextNode(`Token Preview`));
|
|
695
|
+
_$setProp(_el$19, "bold", true);
|
|
696
|
+
_$effect((_p$) => {
|
|
697
|
+
var _v$3 = theme.accent, _v$4 = width.key, _v$5 = theme.accent, _v$6 = width.tag, _v$7 = theme.accent, _v$8 = width.expires, _v$9 = theme.accent, _v$0 = width.created, _v$1 = theme.accent, _v$10 = width.token;
|
|
698
|
+
_v$3 !== _p$.e && (_p$.e = _$setProp(_el$5, "fg", _v$3, _p$.e));
|
|
699
|
+
_v$4 !== _p$.t && (_p$.t = _$setProp(_el$5, "width", _v$4, _p$.t));
|
|
700
|
+
_v$5 !== _p$.a && (_p$.a = _$setProp(_el$9, "fg", _v$5, _p$.a));
|
|
701
|
+
_v$6 !== _p$.o && (_p$.o = _$setProp(_el$9, "width", _v$6, _p$.o));
|
|
702
|
+
_v$7 !== _p$.i && (_p$.i = _$setProp(_el$11, "fg", _v$7, _p$.i));
|
|
703
|
+
_v$8 !== _p$.n && (_p$.n = _$setProp(_el$11, "width", _v$8, _p$.n));
|
|
704
|
+
_v$9 !== _p$.s && (_p$.s = _$setProp(_el$15, "fg", _v$9, _p$.s));
|
|
705
|
+
_v$0 !== _p$.h && (_p$.h = _$setProp(_el$15, "width", _v$0, _p$.h));
|
|
706
|
+
_v$1 !== _p$.r && (_p$.r = _$setProp(_el$19, "fg", _v$1, _p$.r));
|
|
707
|
+
_v$10 !== _p$.d && (_p$.d = _$setProp(_el$19, "width", _v$10, _p$.d));
|
|
708
|
+
return _p$;
|
|
709
|
+
}, {
|
|
710
|
+
e: void 0,
|
|
711
|
+
t: void 0,
|
|
712
|
+
a: void 0,
|
|
713
|
+
o: void 0,
|
|
714
|
+
i: void 0,
|
|
715
|
+
n: void 0,
|
|
716
|
+
s: void 0,
|
|
717
|
+
h: void 0,
|
|
718
|
+
r: void 0,
|
|
719
|
+
d: void 0
|
|
720
|
+
});
|
|
721
|
+
return _el$4;
|
|
722
|
+
})();
|
|
723
|
+
};
|
|
724
|
+
const row = (secret, index) => {
|
|
725
|
+
const width = widths();
|
|
726
|
+
const selected = index === props.selectedIndex;
|
|
727
|
+
const status = getSecretStatus(secret);
|
|
728
|
+
return (() => {
|
|
729
|
+
var _el$21 = _$createElement("box"), _el$22 = _$createElement("text"), _el$23 = _$createElement("text"), _el$25 = _$createElement("text"), _el$26 = _$createElement("text"), _el$28 = _$createElement("text"), _el$29 = _$createElement("text"), _el$31 = _$createElement("text"), _el$32 = _$createElement("text"), _el$34 = _$createElement("text");
|
|
730
|
+
_$insertNode(_el$21, _el$22);
|
|
731
|
+
_$insertNode(_el$21, _el$23);
|
|
732
|
+
_$insertNode(_el$21, _el$25);
|
|
733
|
+
_$insertNode(_el$21, _el$26);
|
|
734
|
+
_$insertNode(_el$21, _el$28);
|
|
735
|
+
_$insertNode(_el$21, _el$29);
|
|
736
|
+
_$insertNode(_el$21, _el$31);
|
|
737
|
+
_$insertNode(_el$21, _el$32);
|
|
738
|
+
_$insertNode(_el$21, _el$34);
|
|
739
|
+
_$setProp(_el$21, "flexDirection", "row");
|
|
740
|
+
_$insert(_el$22, () => truncateKey(secret.key, width.key));
|
|
741
|
+
_$insertNode(_el$23, _$createTextNode(` `));
|
|
742
|
+
_$insert(_el$25, () => truncateTag(secret.tag, width.tag));
|
|
743
|
+
_$insertNode(_el$26, _$createTextNode(` `));
|
|
744
|
+
_$insert(_el$28, () => formatExpiration(secret.expiration, width.expires));
|
|
745
|
+
_$insertNode(_el$29, _$createTextNode(` `));
|
|
746
|
+
_$insert(_el$31, () => formatCreatedAt(secret.createdAt, width.created));
|
|
747
|
+
_$insertNode(_el$32, _$createTextNode(` `));
|
|
748
|
+
_$insert(_el$34, () => previewToken(secret.token, width.token));
|
|
749
|
+
_$effect((_p$) => {
|
|
750
|
+
var _v$11 = selected ? theme.focusBackground : void 0, _v$12 = selected ? theme.focusText : theme.text, _v$13 = width.key, _v$14 = selected ? theme.focusText : theme.accent, _v$15 = width.tag, _v$16 = selected ? theme.focusText : status.color, _v$17 = width.expires, _v$18 = selected ? theme.focusText : theme.muted, _v$19 = width.created, _v$20 = selected ? theme.focusText : theme.muted, _v$21 = width.token;
|
|
751
|
+
_v$11 !== _p$.e && (_p$.e = _$setProp(_el$21, "backgroundColor", _v$11, _p$.e));
|
|
752
|
+
_v$12 !== _p$.t && (_p$.t = _$setProp(_el$22, "fg", _v$12, _p$.t));
|
|
753
|
+
_v$13 !== _p$.a && (_p$.a = _$setProp(_el$22, "width", _v$13, _p$.a));
|
|
754
|
+
_v$14 !== _p$.o && (_p$.o = _$setProp(_el$25, "fg", _v$14, _p$.o));
|
|
755
|
+
_v$15 !== _p$.i && (_p$.i = _$setProp(_el$25, "width", _v$15, _p$.i));
|
|
756
|
+
_v$16 !== _p$.n && (_p$.n = _$setProp(_el$28, "fg", _v$16, _p$.n));
|
|
757
|
+
_v$17 !== _p$.s && (_p$.s = _$setProp(_el$28, "width", _v$17, _p$.s));
|
|
758
|
+
_v$18 !== _p$.h && (_p$.h = _$setProp(_el$31, "fg", _v$18, _p$.h));
|
|
759
|
+
_v$19 !== _p$.r && (_p$.r = _$setProp(_el$31, "width", _v$19, _p$.r));
|
|
760
|
+
_v$20 !== _p$.d && (_p$.d = _$setProp(_el$34, "fg", _v$20, _p$.d));
|
|
761
|
+
_v$21 !== _p$.l && (_p$.l = _$setProp(_el$34, "width", _v$21, _p$.l));
|
|
762
|
+
return _p$;
|
|
763
|
+
}, {
|
|
764
|
+
e: void 0,
|
|
765
|
+
t: void 0,
|
|
766
|
+
a: void 0,
|
|
767
|
+
o: void 0,
|
|
768
|
+
i: void 0,
|
|
769
|
+
n: void 0,
|
|
770
|
+
s: void 0,
|
|
771
|
+
h: void 0,
|
|
772
|
+
r: void 0,
|
|
773
|
+
d: void 0,
|
|
774
|
+
l: void 0
|
|
775
|
+
});
|
|
776
|
+
return _el$21;
|
|
777
|
+
})();
|
|
778
|
+
};
|
|
779
|
+
return (() => {
|
|
780
|
+
var _el$35 = _$createElement("box"), _el$36 = _$createElement("box"), _el$37 = _$createElement("box"), _el$38 = _$createElement("text"), _el$39 = _$createElement("text"), _el$40 = _$createTextNode(`Showing `), _el$41 = _$createTextNode(`-`), _el$42 = _$createTextNode(` of `), _el$43 = _$createElement("text");
|
|
781
|
+
_$insertNode(_el$35, _el$36);
|
|
782
|
+
_$insertNode(_el$35, _el$37);
|
|
783
|
+
_$setProp(_el$35, "flexDirection", "column");
|
|
784
|
+
_$setProp(_el$35, "flexGrow", 1);
|
|
785
|
+
_$setProp(_el$35, "overflow", "hidden");
|
|
786
|
+
_$setProp(_el$36, "marginBottom", 1);
|
|
787
|
+
_$insert(_el$36, header);
|
|
788
|
+
_$insert(_el$35, () => visibleTokens().map((secret, index) => row(secret, startIndex() + index)), _el$37);
|
|
789
|
+
_$insertNode(_el$37, _el$38);
|
|
790
|
+
_$insertNode(_el$37, _el$39);
|
|
791
|
+
_$insertNode(_el$37, _el$43);
|
|
792
|
+
_$setProp(_el$37, "flexDirection", "row");
|
|
793
|
+
_$setProp(_el$37, "justifyContent", "space-between");
|
|
794
|
+
_$setProp(_el$38, "dim", true);
|
|
795
|
+
_$insert(_el$38, () => startIndex() > 0 ? "\u2191 More above" : "");
|
|
796
|
+
_$insertNode(_el$39, _el$40);
|
|
797
|
+
_$insertNode(_el$39, _el$41);
|
|
798
|
+
_$insertNode(_el$39, _el$42);
|
|
799
|
+
_$setProp(_el$39, "dim", true);
|
|
800
|
+
_$insert(_el$39, () => startIndex() + 1, _el$41);
|
|
801
|
+
_$insert(_el$39, () => Math.min(startIndex() + visibleTokens().length, props.tokens.length), _el$42);
|
|
802
|
+
_$insert(_el$39, () => props.tokens.length, null);
|
|
803
|
+
_$setProp(_el$43, "dim", true);
|
|
804
|
+
_$insert(_el$43, () => startIndex() + visibleTokens().length < props.tokens.length ? "\u2193 More below" : "");
|
|
805
|
+
return _el$35;
|
|
806
|
+
})();
|
|
807
|
+
};
|
|
808
|
+
SecretTable_default = SecretTable;
|
|
809
|
+
}
|
|
810
|
+
});
|
|
811
|
+
|
|
812
|
+
// src/tui/components/EditForm.jsx
|
|
813
|
+
import { effect as _$effect2 } from "@opentui/solid";
|
|
814
|
+
import { insert as _$insert2 } from "@opentui/solid";
|
|
815
|
+
import { createTextNode as _$createTextNode2 } from "@opentui/solid";
|
|
816
|
+
import { insertNode as _$insertNode2 } from "@opentui/solid";
|
|
817
|
+
import { setProp as _$setProp2 } from "@opentui/solid";
|
|
818
|
+
import { createElement as _$createElement2 } from "@opentui/solid";
|
|
819
|
+
import { createSignal } from "solid-js";
|
|
820
|
+
import { useKeyboard } from "@opentui/solid";
|
|
821
|
+
var EditForm, EditForm_default;
|
|
822
|
+
var init_EditForm = __esm({
|
|
823
|
+
"src/tui/components/EditForm.jsx"() {
|
|
824
|
+
init_theme();
|
|
825
|
+
EditForm = (props) => {
|
|
826
|
+
const fields = ["token", "expiration", "tag", "comment", "env"];
|
|
827
|
+
const labels = {
|
|
828
|
+
token: "Token",
|
|
829
|
+
expiration: "Expiration",
|
|
830
|
+
tag: "Tag",
|
|
831
|
+
comment: "Comment",
|
|
832
|
+
env: "Env Var"
|
|
833
|
+
};
|
|
834
|
+
const [data, setData] = createSignal({
|
|
835
|
+
token: props.token.token,
|
|
836
|
+
expiration: props.token.expiration || "",
|
|
837
|
+
tag: props.token.tag || "",
|
|
838
|
+
comment: props.token.comment || "",
|
|
839
|
+
env: props.token.env || ""
|
|
840
|
+
});
|
|
841
|
+
const [active, setActive] = createSignal(0);
|
|
842
|
+
const save = () => {
|
|
843
|
+
const current = data();
|
|
844
|
+
const updates = Object.fromEntries(fields.filter((field) => current[field] !== (props.token[field] || "")).map((field) => [field, field === "expiration" ? current[field] || null : current[field]]));
|
|
845
|
+
Object.keys(updates).length ? props.onSave(updates) : props.onCancel();
|
|
846
|
+
};
|
|
847
|
+
useKeyboard((key) => {
|
|
848
|
+
if (key.name === "escape") props.onCancel();
|
|
849
|
+
else if (key.name === "return" || key.name === "enter") save();
|
|
850
|
+
else if (key.name === "tab") setActive((index) => (index + (key.shift ? fields.length - 1 : 1)) % fields.length);
|
|
851
|
+
});
|
|
852
|
+
return (() => {
|
|
853
|
+
var _el$ = _$createElement2("box"), _el$2 = _$createElement2("text"), _el$3 = _$createTextNode2(`Editing Token: `), _el$4 = _$createElement2("text");
|
|
854
|
+
_$insertNode2(_el$, _el$2);
|
|
855
|
+
_$insertNode2(_el$, _el$4);
|
|
856
|
+
_$setProp2(_el$, "border", true);
|
|
857
|
+
_$setProp2(_el$, "borderStyle", "rounded");
|
|
858
|
+
_$setProp2(_el$, "paddingX", 2);
|
|
859
|
+
_$setProp2(_el$, "flexDirection", "column");
|
|
860
|
+
_$setProp2(_el$, "flexGrow", 1);
|
|
861
|
+
_$insertNode2(_el$2, _el$3);
|
|
862
|
+
_$setProp2(_el$2, "bold", true);
|
|
863
|
+
_$insert2(_el$2, () => props.token.key, null);
|
|
864
|
+
_$insertNode2(_el$4, _$createTextNode2(`Key cannot be changed (create new token instead)`));
|
|
865
|
+
_$insert2(_el$, () => fields.map((field, index) => (() => {
|
|
866
|
+
var _el$6 = _$createElement2("box"), _el$7 = _$createElement2("text"), _el$8 = _$createTextNode2(`:`), _el$9 = _$createElement2("input");
|
|
867
|
+
_$insertNode2(_el$6, _el$7);
|
|
868
|
+
_$insertNode2(_el$6, _el$9);
|
|
869
|
+
_$insertNode2(_el$7, _el$8);
|
|
870
|
+
_$setProp2(_el$7, "width", 12);
|
|
871
|
+
_$insert2(_el$7, () => labels[field], _el$8);
|
|
872
|
+
_$setProp2(_el$9, "onInput", (value) => setData({
|
|
873
|
+
...data(),
|
|
874
|
+
[field]: value
|
|
875
|
+
}));
|
|
876
|
+
_$setProp2(_el$9, "flexGrow", 1);
|
|
877
|
+
_$effect2((_p$) => {
|
|
878
|
+
var _v$4 = active() === index ? theme.accent : theme.text, _v$5 = data()[field], _v$6 = active() === index;
|
|
879
|
+
_v$4 !== _p$.e && (_p$.e = _$setProp2(_el$7, "fg", _v$4, _p$.e));
|
|
880
|
+
_v$5 !== _p$.t && (_p$.t = _$setProp2(_el$9, "value", _v$5, _p$.t));
|
|
881
|
+
_v$6 !== _p$.a && (_p$.a = _$setProp2(_el$9, "focused", _v$6, _p$.a));
|
|
882
|
+
return _p$;
|
|
883
|
+
}, {
|
|
884
|
+
e: void 0,
|
|
885
|
+
t: void 0,
|
|
886
|
+
a: void 0
|
|
887
|
+
});
|
|
888
|
+
return _el$6;
|
|
889
|
+
})()), null);
|
|
890
|
+
_$effect2((_p$) => {
|
|
891
|
+
var _v$ = theme.accent, _v$2 = theme.accent, _v$3 = theme.muted;
|
|
892
|
+
_v$ !== _p$.e && (_p$.e = _$setProp2(_el$, "borderColor", _v$, _p$.e));
|
|
893
|
+
_v$2 !== _p$.t && (_p$.t = _$setProp2(_el$2, "fg", _v$2, _p$.t));
|
|
894
|
+
_v$3 !== _p$.a && (_p$.a = _$setProp2(_el$4, "fg", _v$3, _p$.a));
|
|
895
|
+
return _p$;
|
|
896
|
+
}, {
|
|
897
|
+
e: void 0,
|
|
898
|
+
t: void 0,
|
|
899
|
+
a: void 0
|
|
900
|
+
});
|
|
901
|
+
return _el$;
|
|
902
|
+
})();
|
|
903
|
+
};
|
|
904
|
+
EditForm_default = EditForm;
|
|
905
|
+
}
|
|
906
|
+
});
|
|
907
|
+
|
|
908
|
+
// src/tui/components/CreateForm.jsx
|
|
909
|
+
import { effect as _$effect3 } from "@opentui/solid";
|
|
910
|
+
import { insert as _$insert3 } from "@opentui/solid";
|
|
911
|
+
import { createTextNode as _$createTextNode3 } from "@opentui/solid";
|
|
912
|
+
import { insertNode as _$insertNode3 } from "@opentui/solid";
|
|
913
|
+
import { setProp as _$setProp3 } from "@opentui/solid";
|
|
914
|
+
import { createElement as _$createElement3 } from "@opentui/solid";
|
|
915
|
+
import { createSignal as createSignal2 } from "solid-js";
|
|
916
|
+
import { useKeyboard as useKeyboard2 } from "@opentui/solid";
|
|
917
|
+
var CreateForm, CreateForm_default;
|
|
918
|
+
var init_CreateForm = __esm({
|
|
919
|
+
"src/tui/components/CreateForm.jsx"() {
|
|
920
|
+
init_theme();
|
|
921
|
+
CreateForm = (props) => {
|
|
922
|
+
const fields = ["key", "token", "expiration", "tag", "comment", "env"];
|
|
923
|
+
const labels = {
|
|
924
|
+
key: "Key",
|
|
925
|
+
token: "Token",
|
|
926
|
+
expiration: "Expiration",
|
|
927
|
+
tag: "Tag",
|
|
928
|
+
comment: "Comment",
|
|
929
|
+
env: "Env Var"
|
|
930
|
+
};
|
|
931
|
+
const [data, setData] = createSignal2({
|
|
932
|
+
key: "",
|
|
933
|
+
token: "",
|
|
934
|
+
expiration: "",
|
|
935
|
+
tag: "",
|
|
936
|
+
comment: "",
|
|
937
|
+
env: ""
|
|
938
|
+
});
|
|
939
|
+
const [active, setActive] = createSignal2(0);
|
|
940
|
+
const save = () => {
|
|
941
|
+
const value = data();
|
|
942
|
+
if (value.key.trim() && value.token.trim()) props.onSave({
|
|
943
|
+
...value,
|
|
944
|
+
key: value.key.trim(),
|
|
945
|
+
token: value.token.trim(),
|
|
946
|
+
expiration: value.expiration.trim() || null
|
|
947
|
+
});
|
|
948
|
+
};
|
|
949
|
+
useKeyboard2((key) => {
|
|
950
|
+
if (key.name === "escape") props.onCancel();
|
|
951
|
+
else if (key.name === "return" || key.name === "enter") save();
|
|
952
|
+
else if (key.name === "tab") setActive((index) => (index + (key.shift ? fields.length - 1 : 1)) % fields.length);
|
|
953
|
+
});
|
|
954
|
+
return (() => {
|
|
955
|
+
var _el$ = _$createElement3("box"), _el$2 = _$createElement3("text");
|
|
956
|
+
_$insertNode3(_el$, _el$2);
|
|
957
|
+
_$setProp3(_el$, "border", true);
|
|
958
|
+
_$setProp3(_el$, "borderStyle", "rounded");
|
|
959
|
+
_$setProp3(_el$, "paddingX", 2);
|
|
960
|
+
_$setProp3(_el$, "flexDirection", "column");
|
|
961
|
+
_$setProp3(_el$, "flexGrow", 1);
|
|
962
|
+
_$insertNode3(_el$2, _$createTextNode3(`Create New Token`));
|
|
963
|
+
_$setProp3(_el$2, "bold", true);
|
|
964
|
+
_$insert3(_el$, () => fields.map((field, index) => (() => {
|
|
965
|
+
var _el$4 = _$createElement3("box"), _el$5 = _$createElement3("text"), _el$6 = _$createTextNode3(`:`), _el$7 = _$createElement3("input");
|
|
966
|
+
_$insertNode3(_el$4, _el$5);
|
|
967
|
+
_$insertNode3(_el$4, _el$7);
|
|
968
|
+
_$insertNode3(_el$5, _el$6);
|
|
969
|
+
_$setProp3(_el$5, "width", 12);
|
|
970
|
+
_$insert3(_el$5, () => labels[field], _el$6);
|
|
971
|
+
_$setProp3(_el$7, "onInput", (value) => setData({
|
|
972
|
+
...data(),
|
|
973
|
+
[field]: value
|
|
974
|
+
}));
|
|
975
|
+
_$setProp3(_el$7, "placeholder", field === "expiration" ? "YYYY-MM-DD or empty" : "");
|
|
976
|
+
_$setProp3(_el$7, "flexGrow", 1);
|
|
977
|
+
_$effect3((_p$) => {
|
|
978
|
+
var _v$3 = active() === index ? theme.accent : theme.text, _v$4 = data()[field], _v$5 = active() === index;
|
|
979
|
+
_v$3 !== _p$.e && (_p$.e = _$setProp3(_el$5, "fg", _v$3, _p$.e));
|
|
980
|
+
_v$4 !== _p$.t && (_p$.t = _$setProp3(_el$7, "value", _v$4, _p$.t));
|
|
981
|
+
_v$5 !== _p$.a && (_p$.a = _$setProp3(_el$7, "focused", _v$5, _p$.a));
|
|
982
|
+
return _p$;
|
|
983
|
+
}, {
|
|
984
|
+
e: void 0,
|
|
985
|
+
t: void 0,
|
|
986
|
+
a: void 0
|
|
987
|
+
});
|
|
988
|
+
return _el$4;
|
|
989
|
+
})()), null);
|
|
990
|
+
_$effect3((_p$) => {
|
|
991
|
+
var _v$ = theme.accent, _v$2 = theme.accent;
|
|
992
|
+
_v$ !== _p$.e && (_p$.e = _$setProp3(_el$, "borderColor", _v$, _p$.e));
|
|
993
|
+
_v$2 !== _p$.t && (_p$.t = _$setProp3(_el$2, "fg", _v$2, _p$.t));
|
|
994
|
+
return _p$;
|
|
995
|
+
}, {
|
|
996
|
+
e: void 0,
|
|
997
|
+
t: void 0
|
|
998
|
+
});
|
|
999
|
+
return _el$;
|
|
1000
|
+
})();
|
|
1001
|
+
};
|
|
1002
|
+
CreateForm_default = CreateForm;
|
|
1003
|
+
}
|
|
1004
|
+
});
|
|
1005
|
+
|
|
1006
|
+
// src/tui/components/HelpPanel.jsx
|
|
1007
|
+
import { effect as _$effect4 } from "@opentui/solid";
|
|
1008
|
+
import { insert as _$insert4 } from "@opentui/solid";
|
|
1009
|
+
import { createTextNode as _$createTextNode4 } from "@opentui/solid";
|
|
1010
|
+
import { insertNode as _$insertNode4 } from "@opentui/solid";
|
|
1011
|
+
import { setProp as _$setProp4 } from "@opentui/solid";
|
|
1012
|
+
import { createElement as _$createElement4 } from "@opentui/solid";
|
|
1013
|
+
var HelpPanel, HelpPanel_default;
|
|
1014
|
+
var init_HelpPanel = __esm({
|
|
1015
|
+
"src/tui/components/HelpPanel.jsx"() {
|
|
1016
|
+
init_theme();
|
|
1017
|
+
HelpPanel = () => {
|
|
1018
|
+
const bindings = [["\u2191 / k", "Move selection up"], ["\u2193 / j", "Move selection down"], ["Home / g", "Jump to first token"], ["End / G", "Jump to last token"], ["c", "Create new token"], ["e", "Edit selected token"], ["dd", "Delete selected token"], ["y / Y", "Copy token / sid"], ["f", "Filter tokens"], ["?", "Close this help"], ["q / Ctrl+C", "Quit application"]];
|
|
1019
|
+
return (() => {
|
|
1020
|
+
var _el$ = _$createElement4("box"), _el$2 = _$createElement4("text"), _el$4 = _$createElement4("text");
|
|
1021
|
+
_$insertNode4(_el$, _el$2);
|
|
1022
|
+
_$insertNode4(_el$, _el$4);
|
|
1023
|
+
_$setProp4(_el$, "border", true);
|
|
1024
|
+
_$setProp4(_el$, "borderStyle", "rounded");
|
|
1025
|
+
_$setProp4(_el$, "paddingX", 2);
|
|
1026
|
+
_$setProp4(_el$, "flexDirection", "column");
|
|
1027
|
+
_$setProp4(_el$, "flexGrow", 1);
|
|
1028
|
+
_$insertNode4(_el$2, _$createTextNode4(`Clavis TUI Help`));
|
|
1029
|
+
_$setProp4(_el$2, "bold", true);
|
|
1030
|
+
_$insertNode4(_el$4, _$createTextNode4(`Navigation`));
|
|
1031
|
+
_$setProp4(_el$4, "bold", true);
|
|
1032
|
+
_$insert4(_el$, () => bindings.map(([key, description]) => (() => {
|
|
1033
|
+
var _el$6 = _$createElement4("box"), _el$7 = _$createElement4("text"), _el$8 = _$createElement4("text");
|
|
1034
|
+
_$insertNode4(_el$6, _el$7);
|
|
1035
|
+
_$insertNode4(_el$6, _el$8);
|
|
1036
|
+
_$setProp4(_el$6, "marginLeft", 2);
|
|
1037
|
+
_$setProp4(_el$7, "width", 20);
|
|
1038
|
+
_$setProp4(_el$7, "bold", true);
|
|
1039
|
+
_$insert4(_el$7, key);
|
|
1040
|
+
_$insert4(_el$8, description);
|
|
1041
|
+
_$effect4((_p$) => {
|
|
1042
|
+
var _v$4 = theme.warning, _v$5 = theme.text;
|
|
1043
|
+
_v$4 !== _p$.e && (_p$.e = _$setProp4(_el$7, "fg", _v$4, _p$.e));
|
|
1044
|
+
_v$5 !== _p$.t && (_p$.t = _$setProp4(_el$8, "fg", _v$5, _p$.t));
|
|
1045
|
+
return _p$;
|
|
1046
|
+
}, {
|
|
1047
|
+
e: void 0,
|
|
1048
|
+
t: void 0
|
|
1049
|
+
});
|
|
1050
|
+
return _el$6;
|
|
1051
|
+
})()), null);
|
|
1052
|
+
_$effect4((_p$) => {
|
|
1053
|
+
var _v$ = theme.accent, _v$2 = theme.accent, _v$3 = theme.text;
|
|
1054
|
+
_v$ !== _p$.e && (_p$.e = _$setProp4(_el$, "borderColor", _v$, _p$.e));
|
|
1055
|
+
_v$2 !== _p$.t && (_p$.t = _$setProp4(_el$2, "fg", _v$2, _p$.t));
|
|
1056
|
+
_v$3 !== _p$.a && (_p$.a = _$setProp4(_el$4, "fg", _v$3, _p$.a));
|
|
1057
|
+
return _p$;
|
|
1058
|
+
}, {
|
|
1059
|
+
e: void 0,
|
|
1060
|
+
t: void 0,
|
|
1061
|
+
a: void 0
|
|
1062
|
+
});
|
|
1063
|
+
return _el$;
|
|
1064
|
+
})();
|
|
1065
|
+
};
|
|
1066
|
+
HelpPanel_default = HelpPanel;
|
|
1067
|
+
}
|
|
1068
|
+
});
|
|
1069
|
+
|
|
1070
|
+
// src/tui/components/Header.jsx
|
|
1071
|
+
import { effect as _$effect5 } from "@opentui/solid";
|
|
1072
|
+
import { insert as _$insert5 } from "@opentui/solid";
|
|
1073
|
+
import { memo as _$memo2 } from "@opentui/solid";
|
|
1074
|
+
import { createTextNode as _$createTextNode5 } from "@opentui/solid";
|
|
1075
|
+
import { insertNode as _$insertNode5 } from "@opentui/solid";
|
|
1076
|
+
import { setProp as _$setProp5 } from "@opentui/solid";
|
|
1077
|
+
import { createElement as _$createElement5 } from "@opentui/solid";
|
|
1078
|
+
var Header, Header_default;
|
|
1079
|
+
var init_Header = __esm({
|
|
1080
|
+
"src/tui/components/Header.jsx"() {
|
|
1081
|
+
init_theme();
|
|
1082
|
+
Header = (props) => (() => {
|
|
1083
|
+
var _el$ = _$createElement5("box"), _el$2 = _$createElement5("box"), _el$3 = _$createElement5("text"), _el$5 = _$createElement5("text");
|
|
1084
|
+
_$insertNode5(_el$, _el$2);
|
|
1085
|
+
_$setProp5(_el$, "border", true);
|
|
1086
|
+
_$setProp5(_el$, "borderStyle", "rounded");
|
|
1087
|
+
_$setProp5(_el$, "paddingX", 1);
|
|
1088
|
+
_$setProp5(_el$, "height", 3);
|
|
1089
|
+
_$setProp5(_el$, "flexDirection", "column");
|
|
1090
|
+
_$insertNode5(_el$2, _el$3);
|
|
1091
|
+
_$insertNode5(_el$2, _el$5);
|
|
1092
|
+
_$setProp5(_el$2, "flexDirection", "row");
|
|
1093
|
+
_$setProp5(_el$2, "justifyContent", "space-between");
|
|
1094
|
+
_$insertNode5(_el$3, _$createTextNode5(`Clavis Token Manager v1.0.0`));
|
|
1095
|
+
_$setProp5(_el$3, "bold", true);
|
|
1096
|
+
_$insert5(_el$5, (() => {
|
|
1097
|
+
var _c$ = _$memo2(() => !!props.filter);
|
|
1098
|
+
return () => _c$() ? (() => {
|
|
1099
|
+
var _el$6 = _$createElement5("span"), _el$7 = _$createTextNode5(`Filter: `);
|
|
1100
|
+
_$insertNode5(_el$6, _el$7);
|
|
1101
|
+
_$insert5(_el$6, () => props.filter, null);
|
|
1102
|
+
_$effect5((_$p) => _$setProp5(_el$6, "fg", theme.warning, _$p));
|
|
1103
|
+
return _el$6;
|
|
1104
|
+
})() : [_$memo2(() => props.tokenCount), " tokens", _$memo2(() => _$memo2(() => props.expiredCount > 0)() && (() => {
|
|
1105
|
+
var _el$8 = _$createElement5("span"), _el$9 = _$createTextNode5(` (`), _el$0 = _$createTextNode5(` expired)`);
|
|
1106
|
+
_$insertNode5(_el$8, _el$9);
|
|
1107
|
+
_$insertNode5(_el$8, _el$0);
|
|
1108
|
+
_$insert5(_el$8, () => props.expiredCount, _el$0);
|
|
1109
|
+
_$effect5((_$p) => _$setProp5(_el$8, "fg", theme.danger, _$p));
|
|
1110
|
+
return _el$8;
|
|
1111
|
+
})()), _$memo2(() => _$memo2(() => props.warningCount > 0)() && (() => {
|
|
1112
|
+
var _el$1 = _$createElement5("span"), _el$10 = _$createTextNode5(`, `), _el$11 = _$createTextNode5(` expiring`);
|
|
1113
|
+
_$insertNode5(_el$1, _el$10);
|
|
1114
|
+
_$insertNode5(_el$1, _el$11);
|
|
1115
|
+
_$insert5(_el$1, () => props.warningCount, _el$11);
|
|
1116
|
+
_$effect5((_$p) => _$setProp5(_el$1, "fg", theme.warning, _$p));
|
|
1117
|
+
return _el$1;
|
|
1118
|
+
})())];
|
|
1119
|
+
})());
|
|
1120
|
+
_$effect5((_p$) => {
|
|
1121
|
+
var _v$ = theme.accent, _v$2 = theme.accent, _v$3 = theme.text;
|
|
1122
|
+
_v$ !== _p$.e && (_p$.e = _$setProp5(_el$, "borderColor", _v$, _p$.e));
|
|
1123
|
+
_v$2 !== _p$.t && (_p$.t = _$setProp5(_el$3, "fg", _v$2, _p$.t));
|
|
1124
|
+
_v$3 !== _p$.a && (_p$.a = _$setProp5(_el$5, "fg", _v$3, _p$.a));
|
|
1125
|
+
return _p$;
|
|
1126
|
+
}, {
|
|
1127
|
+
e: void 0,
|
|
1128
|
+
t: void 0,
|
|
1129
|
+
a: void 0
|
|
1130
|
+
});
|
|
1131
|
+
return _el$;
|
|
1132
|
+
})();
|
|
1133
|
+
Header_default = Header;
|
|
1134
|
+
}
|
|
1135
|
+
});
|
|
1136
|
+
|
|
1137
|
+
// src/tui/components/Footer.jsx
|
|
1138
|
+
import { effect as _$effect6 } from "@opentui/solid";
|
|
1139
|
+
import { insertNode as _$insertNode6 } from "@opentui/solid";
|
|
1140
|
+
import { insert as _$insert6 } from "@opentui/solid";
|
|
1141
|
+
import { setProp as _$setProp6 } from "@opentui/solid";
|
|
1142
|
+
import { createElement as _$createElement6 } from "@opentui/solid";
|
|
1143
|
+
var Footer, Footer_default;
|
|
1144
|
+
var init_Footer = __esm({
|
|
1145
|
+
"src/tui/components/Footer.jsx"() {
|
|
1146
|
+
init_theme();
|
|
1147
|
+
Footer = (props) => {
|
|
1148
|
+
const status = props.isSelectingEnvVar ? "Select Env Var" : props.showHelp ? "Press any key to close help" : props.isCreating ? "Creating New Token" : props.isEditing ? `Editing: ${props.selectedToken?.key ?? ""}` : `Selected: ${props.selectedToken?.key ?? "None"}`;
|
|
1149
|
+
const shortcuts = props.isSelectingEnvVar ? "[\u2191\u2193] Navigate [Enter] Select [Esc] Cancel" : props.isCreating || props.isEditing ? "[Tab] Next [Enter] Save [Esc] Cancel" : "c:New e:Edit dd:Del y:Yank Y:SID f:Find ?:Help q:Quit";
|
|
1150
|
+
return (() => {
|
|
1151
|
+
var _el$ = _$createElement6("box"), _el$2 = _$createElement6("text"), _el$3 = _$createElement6("text");
|
|
1152
|
+
_$insertNode6(_el$, _el$2);
|
|
1153
|
+
_$insertNode6(_el$, _el$3);
|
|
1154
|
+
_$setProp6(_el$, "border", true);
|
|
1155
|
+
_$setProp6(_el$, "borderStyle", "rounded");
|
|
1156
|
+
_$setProp6(_el$, "paddingX", 1);
|
|
1157
|
+
_$setProp6(_el$, "height", 3);
|
|
1158
|
+
_$setProp6(_el$, "flexDirection", "row");
|
|
1159
|
+
_$setProp6(_el$, "justifyContent", "space-between");
|
|
1160
|
+
_$insert6(_el$2, status);
|
|
1161
|
+
_$insert6(_el$3, shortcuts);
|
|
1162
|
+
_$effect6((_p$) => {
|
|
1163
|
+
var _v$ = theme.muted, _v$2 = theme.accent, _v$3 = theme.muted;
|
|
1164
|
+
_v$ !== _p$.e && (_p$.e = _$setProp6(_el$, "borderColor", _v$, _p$.e));
|
|
1165
|
+
_v$2 !== _p$.t && (_p$.t = _$setProp6(_el$2, "fg", _v$2, _p$.t));
|
|
1166
|
+
_v$3 !== _p$.a && (_p$.a = _$setProp6(_el$3, "fg", _v$3, _p$.a));
|
|
1167
|
+
return _p$;
|
|
1168
|
+
}, {
|
|
1169
|
+
e: void 0,
|
|
1170
|
+
t: void 0,
|
|
1171
|
+
a: void 0
|
|
1172
|
+
});
|
|
1173
|
+
return _el$;
|
|
1174
|
+
})();
|
|
1175
|
+
};
|
|
1176
|
+
Footer_default = Footer;
|
|
1177
|
+
}
|
|
1178
|
+
});
|
|
1179
|
+
|
|
1180
|
+
// src/tui/components/ConfirmDialog.jsx
|
|
1181
|
+
import { effect as _$effect7 } from "@opentui/solid";
|
|
1182
|
+
import { createTextNode as _$createTextNode6 } from "@opentui/solid";
|
|
1183
|
+
import { insertNode as _$insertNode7 } from "@opentui/solid";
|
|
1184
|
+
import { insert as _$insert7 } from "@opentui/solid";
|
|
1185
|
+
import { memo as _$memo3 } from "@opentui/solid";
|
|
1186
|
+
import { setProp as _$setProp7 } from "@opentui/solid";
|
|
1187
|
+
import { createElement as _$createElement7 } from "@opentui/solid";
|
|
1188
|
+
import { createSignal as createSignal3 } from "solid-js";
|
|
1189
|
+
import { useKeyboard as useKeyboard3 } from "@opentui/solid";
|
|
1190
|
+
var ConfirmDialog, ConfirmDialog_default;
|
|
1191
|
+
var init_ConfirmDialog = __esm({
|
|
1192
|
+
"src/tui/components/ConfirmDialog.jsx"() {
|
|
1193
|
+
init_theme();
|
|
1194
|
+
ConfirmDialog = (props) => {
|
|
1195
|
+
const [selected, setSelected] = createSignal3(0);
|
|
1196
|
+
useKeyboard3((key) => {
|
|
1197
|
+
if (key.name === "escape") props.onCancel();
|
|
1198
|
+
else if (key.name === "return" || key.name === "enter") selected() === 0 ? props.onConfirm() : props.onCancel();
|
|
1199
|
+
else if (key.name === "left" || key.name === "h") setSelected(0);
|
|
1200
|
+
else if (key.name === "right" || key.name === "l") setSelected(1);
|
|
1201
|
+
});
|
|
1202
|
+
return (() => {
|
|
1203
|
+
var _el$ = _$createElement7("box"), _el$2 = _$createElement7("text"), _el$3 = _$createElement7("text"), _el$4 = _$createElement7("box"), _el$5 = _$createElement7("text"), _el$6 = _$createTextNode6(`[ `), _el$7 = _$createTextNode6(` ]`), _el$8 = _$createElement7("text"), _el$9 = _$createTextNode6(`[ `), _el$0 = _$createTextNode6(` ]`), _el$1 = _$createElement7("text");
|
|
1204
|
+
_$insertNode7(_el$, _el$2);
|
|
1205
|
+
_$insertNode7(_el$, _el$3);
|
|
1206
|
+
_$insertNode7(_el$, _el$4);
|
|
1207
|
+
_$insertNode7(_el$, _el$1);
|
|
1208
|
+
_$setProp7(_el$, "border", true);
|
|
1209
|
+
_$setProp7(_el$, "borderStyle", "rounded");
|
|
1210
|
+
_$setProp7(_el$, "padding", 2);
|
|
1211
|
+
_$setProp7(_el$, "flexDirection", "column");
|
|
1212
|
+
_$setProp7(_el$, "flexGrow", 1);
|
|
1213
|
+
_$setProp7(_el$2, "bold", true);
|
|
1214
|
+
_$insert7(_el$2, () => props.title || "Confirm Action");
|
|
1215
|
+
_$setProp7(_el$3, "marginTop", 1);
|
|
1216
|
+
_$insert7(_el$3, () => props.message);
|
|
1217
|
+
_$insertNode7(_el$4, _el$5);
|
|
1218
|
+
_$insertNode7(_el$4, _el$8);
|
|
1219
|
+
_$setProp7(_el$4, "justifyContent", "center");
|
|
1220
|
+
_$setProp7(_el$4, "gap", 3);
|
|
1221
|
+
_$setProp7(_el$4, "marginTop", 2);
|
|
1222
|
+
_$insertNode7(_el$5, _el$6);
|
|
1223
|
+
_$insertNode7(_el$5, _el$7);
|
|
1224
|
+
_$insert7(_el$5, () => props.confirmText || "Yes", _el$7);
|
|
1225
|
+
_$insertNode7(_el$8, _el$9);
|
|
1226
|
+
_$insertNode7(_el$8, _el$0);
|
|
1227
|
+
_$insert7(_el$8, () => props.cancelText || "No", _el$0);
|
|
1228
|
+
_$insertNode7(_el$1, _$createTextNode6(`Press [\u2190\u2192/hl] to select, [Enter] to confirm, [Esc] to cancel`));
|
|
1229
|
+
_$setProp7(_el$1, "marginTop", 1);
|
|
1230
|
+
_$effect7((_p$) => {
|
|
1231
|
+
var _v$ = theme.warning, _v$2 = theme.warning, _v$3 = theme.text, _v$4 = selected() === 0 ? theme.success : theme.muted, _v$5 = selected() === 0, _v$6 = selected() === 1 ? theme.accent : theme.muted, _v$7 = selected() === 1, _v$8 = theme.muted;
|
|
1232
|
+
_v$ !== _p$.e && (_p$.e = _$setProp7(_el$, "borderColor", _v$, _p$.e));
|
|
1233
|
+
_v$2 !== _p$.t && (_p$.t = _$setProp7(_el$2, "fg", _v$2, _p$.t));
|
|
1234
|
+
_v$3 !== _p$.a && (_p$.a = _$setProp7(_el$3, "fg", _v$3, _p$.a));
|
|
1235
|
+
_v$4 !== _p$.o && (_p$.o = _$setProp7(_el$5, "fg", _v$4, _p$.o));
|
|
1236
|
+
_v$5 !== _p$.i && (_p$.i = _$setProp7(_el$5, "bold", _v$5, _p$.i));
|
|
1237
|
+
_v$6 !== _p$.n && (_p$.n = _$setProp7(_el$8, "fg", _v$6, _p$.n));
|
|
1238
|
+
_v$7 !== _p$.s && (_p$.s = _$setProp7(_el$8, "bold", _v$7, _p$.s));
|
|
1239
|
+
_v$8 !== _p$.h && (_p$.h = _$setProp7(_el$1, "fg", _v$8, _p$.h));
|
|
1240
|
+
return _p$;
|
|
1241
|
+
}, {
|
|
1242
|
+
e: void 0,
|
|
1243
|
+
t: void 0,
|
|
1244
|
+
a: void 0,
|
|
1245
|
+
o: void 0,
|
|
1246
|
+
i: void 0,
|
|
1247
|
+
n: void 0,
|
|
1248
|
+
s: void 0,
|
|
1249
|
+
h: void 0
|
|
1250
|
+
});
|
|
1251
|
+
return _el$;
|
|
1252
|
+
})();
|
|
1253
|
+
};
|
|
1254
|
+
ConfirmDialog_default = ConfirmDialog;
|
|
1255
|
+
}
|
|
1256
|
+
});
|
|
1257
|
+
|
|
1258
|
+
// src/tui/components/Warning.jsx
|
|
1259
|
+
import { effect as _$effect8 } from "@opentui/solid";
|
|
1260
|
+
import { createTextNode as _$createTextNode7 } from "@opentui/solid";
|
|
1261
|
+
import { insertNode as _$insertNode8 } from "@opentui/solid";
|
|
1262
|
+
import { insert as _$insert8 } from "@opentui/solid";
|
|
1263
|
+
import { memo as _$memo4 } from "@opentui/solid";
|
|
1264
|
+
import { setProp as _$setProp8 } from "@opentui/solid";
|
|
1265
|
+
import { createElement as _$createElement8 } from "@opentui/solid";
|
|
1266
|
+
import { createEffect, onCleanup } from "solid-js";
|
|
1267
|
+
import { useKeyboard as useKeyboard4 } from "@opentui/solid";
|
|
1268
|
+
var Warning, Warning_default;
|
|
1269
|
+
var init_Warning = __esm({
|
|
1270
|
+
"src/tui/components/Warning.jsx"() {
|
|
1271
|
+
init_theme();
|
|
1272
|
+
Warning = (props) => {
|
|
1273
|
+
const color = () => ({
|
|
1274
|
+
error: theme.danger,
|
|
1275
|
+
warning: theme.warning,
|
|
1276
|
+
success: theme.success,
|
|
1277
|
+
info: theme.accent
|
|
1278
|
+
})[props.type] || theme.warning;
|
|
1279
|
+
const close = () => props.onClose?.();
|
|
1280
|
+
useKeyboard4((key) => {
|
|
1281
|
+
if (key.name === "escape" || key.name === "space") close();
|
|
1282
|
+
});
|
|
1283
|
+
createEffect(() => {
|
|
1284
|
+
if (!props.autoClose) return;
|
|
1285
|
+
const timer = setTimeout(close, props.duration || 3e3);
|
|
1286
|
+
onCleanup(() => clearTimeout(timer));
|
|
1287
|
+
});
|
|
1288
|
+
return (() => {
|
|
1289
|
+
var _el$ = _$createElement8("box"), _el$2 = _$createElement8("text"), _el$3 = _$createElement8("text"), _el$4 = _$createElement8("text");
|
|
1290
|
+
_$insertNode8(_el$, _el$2);
|
|
1291
|
+
_$insertNode8(_el$, _el$3);
|
|
1292
|
+
_$insertNode8(_el$, _el$4);
|
|
1293
|
+
_$setProp8(_el$, "border", true);
|
|
1294
|
+
_$setProp8(_el$, "borderStyle", "rounded");
|
|
1295
|
+
_$setProp8(_el$, "padding", 1);
|
|
1296
|
+
_$setProp8(_el$, "flexDirection", "column");
|
|
1297
|
+
_$setProp8(_el$2, "bold", true);
|
|
1298
|
+
_$insert8(_el$2, () => props.title || "Warning");
|
|
1299
|
+
_$insert8(_el$3, () => props.message);
|
|
1300
|
+
_$insertNode8(_el$4, _$createTextNode7(`Press [Space] or [Esc] to dismiss`));
|
|
1301
|
+
_$effect8((_p$) => {
|
|
1302
|
+
var _v$ = color(), _v$2 = color(), _v$3 = theme.text, _v$4 = theme.muted;
|
|
1303
|
+
_v$ !== _p$.e && (_p$.e = _$setProp8(_el$, "borderColor", _v$, _p$.e));
|
|
1304
|
+
_v$2 !== _p$.t && (_p$.t = _$setProp8(_el$2, "fg", _v$2, _p$.t));
|
|
1305
|
+
_v$3 !== _p$.a && (_p$.a = _$setProp8(_el$3, "fg", _v$3, _p$.a));
|
|
1306
|
+
_v$4 !== _p$.o && (_p$.o = _$setProp8(_el$4, "fg", _v$4, _p$.o));
|
|
1307
|
+
return _p$;
|
|
1308
|
+
}, {
|
|
1309
|
+
e: void 0,
|
|
1310
|
+
t: void 0,
|
|
1311
|
+
a: void 0,
|
|
1312
|
+
o: void 0
|
|
1313
|
+
});
|
|
1314
|
+
return _el$;
|
|
1315
|
+
})();
|
|
1316
|
+
};
|
|
1317
|
+
Warning_default = Warning;
|
|
1318
|
+
}
|
|
1319
|
+
});
|
|
1320
|
+
|
|
1321
|
+
// src/tui/components/SearchInput.jsx
|
|
1322
|
+
import { effect as _$effect9 } from "@opentui/solid";
|
|
1323
|
+
import { createTextNode as _$createTextNode8 } from "@opentui/solid";
|
|
1324
|
+
import { insertNode as _$insertNode9 } from "@opentui/solid";
|
|
1325
|
+
import { setProp as _$setProp9 } from "@opentui/solid";
|
|
1326
|
+
import { createElement as _$createElement9 } from "@opentui/solid";
|
|
1327
|
+
import { createSignal as createSignal4 } from "solid-js";
|
|
1328
|
+
import { useKeyboard as useKeyboard5 } from "@opentui/solid";
|
|
1329
|
+
var SearchInput, SearchInput_default;
|
|
1330
|
+
var init_SearchInput = __esm({
|
|
1331
|
+
"src/tui/components/SearchInput.jsx"() {
|
|
1332
|
+
init_theme();
|
|
1333
|
+
SearchInput = (props) => {
|
|
1334
|
+
const [value, setValue] = createSignal4(props.initialValue || "");
|
|
1335
|
+
const submit = () => {
|
|
1336
|
+
props.onSearch(value());
|
|
1337
|
+
props.onCancel();
|
|
1338
|
+
};
|
|
1339
|
+
useKeyboard5((key) => {
|
|
1340
|
+
if (key.name === "escape") props.onCancel();
|
|
1341
|
+
else if (key.name === "return" || key.name === "enter") submit();
|
|
1342
|
+
else if (key.ctrl && key.name === "u") {
|
|
1343
|
+
setValue("");
|
|
1344
|
+
props.onSearch("");
|
|
1345
|
+
}
|
|
1346
|
+
});
|
|
1347
|
+
return (() => {
|
|
1348
|
+
var _el$ = _$createElement9("box"), _el$2 = _$createElement9("text"), _el$4 = _$createElement9("text"), _el$6 = _$createElement9("box"), _el$7 = _$createElement9("text"), _el$9 = _$createElement9("input"), _el$0 = _$createElement9("text");
|
|
1349
|
+
_$insertNode9(_el$, _el$2);
|
|
1350
|
+
_$insertNode9(_el$, _el$4);
|
|
1351
|
+
_$insertNode9(_el$, _el$6);
|
|
1352
|
+
_$insertNode9(_el$, _el$0);
|
|
1353
|
+
_$setProp9(_el$, "border", true);
|
|
1354
|
+
_$setProp9(_el$, "borderStyle", "rounded");
|
|
1355
|
+
_$setProp9(_el$, "padding", 2);
|
|
1356
|
+
_$setProp9(_el$, "flexDirection", "column");
|
|
1357
|
+
_$setProp9(_el$, "flexGrow", 1);
|
|
1358
|
+
_$insertNode9(_el$2, _$createTextNode8(`Search Tokens`));
|
|
1359
|
+
_$setProp9(_el$2, "bold", true);
|
|
1360
|
+
_$insertNode9(_el$4, _$createTextNode8(`Search by key, tag, or comment:`));
|
|
1361
|
+
_$setProp9(_el$4, "marginTop", 1);
|
|
1362
|
+
_$insertNode9(_el$6, _el$7);
|
|
1363
|
+
_$insertNode9(_el$6, _el$9);
|
|
1364
|
+
_$setProp9(_el$6, "marginTop", 1);
|
|
1365
|
+
_$insertNode9(_el$7, _$createTextNode8(`\u203A `));
|
|
1366
|
+
_$setProp9(_el$9, "onInput", (next) => {
|
|
1367
|
+
setValue(next);
|
|
1368
|
+
props.onSearch(next);
|
|
1369
|
+
});
|
|
1370
|
+
_$setProp9(_el$9, "placeholder", "Type to search...");
|
|
1371
|
+
_$setProp9(_el$9, "focused", true);
|
|
1372
|
+
_$insertNode9(_el$0, _$createTextNode8(`Press [Enter] to finish, [Ctrl+U] to clear, [Esc] to cancel`));
|
|
1373
|
+
_$setProp9(_el$0, "marginTop", 1);
|
|
1374
|
+
_$effect9((_p$) => {
|
|
1375
|
+
var _v$ = theme.accent, _v$2 = theme.accent, _v$3 = theme.text, _v$4 = theme.accent, _v$5 = value(), _v$6 = theme.muted;
|
|
1376
|
+
_v$ !== _p$.e && (_p$.e = _$setProp9(_el$, "borderColor", _v$, _p$.e));
|
|
1377
|
+
_v$2 !== _p$.t && (_p$.t = _$setProp9(_el$2, "fg", _v$2, _p$.t));
|
|
1378
|
+
_v$3 !== _p$.a && (_p$.a = _$setProp9(_el$4, "fg", _v$3, _p$.a));
|
|
1379
|
+
_v$4 !== _p$.o && (_p$.o = _$setProp9(_el$7, "fg", _v$4, _p$.o));
|
|
1380
|
+
_v$5 !== _p$.i && (_p$.i = _$setProp9(_el$9, "value", _v$5, _p$.i));
|
|
1381
|
+
_v$6 !== _p$.n && (_p$.n = _$setProp9(_el$0, "fg", _v$6, _p$.n));
|
|
1382
|
+
return _p$;
|
|
1383
|
+
}, {
|
|
1384
|
+
e: void 0,
|
|
1385
|
+
t: void 0,
|
|
1386
|
+
a: void 0,
|
|
1387
|
+
o: void 0,
|
|
1388
|
+
i: void 0,
|
|
1389
|
+
n: void 0
|
|
1390
|
+
});
|
|
1391
|
+
return _el$;
|
|
1392
|
+
})();
|
|
1393
|
+
};
|
|
1394
|
+
SearchInput_default = SearchInput;
|
|
1395
|
+
}
|
|
1396
|
+
});
|
|
1397
|
+
|
|
1398
|
+
// src/tui/utils/fuzzySearch.js
|
|
1399
|
+
var fuzzyMatch, simpleFuzzySearch;
|
|
1400
|
+
var init_fuzzySearch = __esm({
|
|
1401
|
+
"src/tui/utils/fuzzySearch.js"() {
|
|
1402
|
+
fuzzyMatch = (text, pattern) => {
|
|
1403
|
+
if (!pattern) {
|
|
1404
|
+
return true;
|
|
1405
|
+
}
|
|
1406
|
+
if (!text) {
|
|
1407
|
+
return false;
|
|
1408
|
+
}
|
|
1409
|
+
const textLower = text.toLowerCase();
|
|
1410
|
+
const patternLower = pattern.toLowerCase();
|
|
1411
|
+
if (textLower.includes(patternLower)) {
|
|
1412
|
+
return true;
|
|
1413
|
+
}
|
|
1414
|
+
let patternIndex = 0;
|
|
1415
|
+
let textIndex = 0;
|
|
1416
|
+
while (patternIndex < patternLower.length && textIndex < textLower.length) {
|
|
1417
|
+
if (patternLower[patternIndex] === textLower[textIndex]) {
|
|
1418
|
+
patternIndex++;
|
|
1419
|
+
}
|
|
1420
|
+
textIndex++;
|
|
1421
|
+
}
|
|
1422
|
+
return patternIndex === patternLower.length;
|
|
1423
|
+
};
|
|
1424
|
+
simpleFuzzySearch = (tokens, searchTerm, fields = ["key", "tag", "comment"]) => {
|
|
1425
|
+
if (!searchTerm.trim()) {
|
|
1426
|
+
return tokens;
|
|
1427
|
+
}
|
|
1428
|
+
const searchTermLower = searchTerm.toLowerCase().trim();
|
|
1429
|
+
return tokens.filter((token) => fields.some((field) => {
|
|
1430
|
+
const fieldValue = token[field];
|
|
1431
|
+
return fieldValue && fuzzyMatch(fieldValue, searchTermLower);
|
|
1432
|
+
}));
|
|
1433
|
+
};
|
|
1434
|
+
}
|
|
1435
|
+
});
|
|
1436
|
+
|
|
1437
|
+
// src/tui/utils/clipboard.js
|
|
1438
|
+
import { execSync } from "child_process";
|
|
1439
|
+
function copyToClipboard(text) {
|
|
1440
|
+
if (!text || typeof text !== "string") {
|
|
1441
|
+
return false;
|
|
1442
|
+
}
|
|
1443
|
+
try {
|
|
1444
|
+
const platform = process.platform;
|
|
1445
|
+
if (platform === "darwin") {
|
|
1446
|
+
execSync("pbcopy", {
|
|
1447
|
+
input: text
|
|
1448
|
+
});
|
|
1449
|
+
return true;
|
|
1450
|
+
} else if (platform === "win32") {
|
|
1451
|
+
execSync("clip", {
|
|
1452
|
+
input: text
|
|
1453
|
+
});
|
|
1454
|
+
return true;
|
|
1455
|
+
} else if (platform === "linux" || platform === "freebsd" || platform === "openbsd") {
|
|
1456
|
+
try {
|
|
1457
|
+
execSync("which xclip", {
|
|
1458
|
+
stdio: "ignore"
|
|
1459
|
+
});
|
|
1460
|
+
execSync("xclip -selection clipboard", {
|
|
1461
|
+
input: text
|
|
1462
|
+
});
|
|
1463
|
+
return true;
|
|
1464
|
+
} catch {
|
|
1465
|
+
try {
|
|
1466
|
+
execSync("which xsel", {
|
|
1467
|
+
stdio: "ignore"
|
|
1468
|
+
});
|
|
1469
|
+
execSync("xsel --clipboard --input", {
|
|
1470
|
+
input: text
|
|
1471
|
+
});
|
|
1472
|
+
return true;
|
|
1473
|
+
} catch {
|
|
1474
|
+
return false;
|
|
1475
|
+
}
|
|
1476
|
+
}
|
|
1477
|
+
} else {
|
|
1478
|
+
return false;
|
|
1479
|
+
}
|
|
1480
|
+
} catch (error) {
|
|
1481
|
+
console.error("Clipboard error:", error.message);
|
|
1482
|
+
return false;
|
|
1483
|
+
}
|
|
1484
|
+
}
|
|
1485
|
+
var init_clipboard = __esm({
|
|
1486
|
+
"src/tui/utils/clipboard.js"() {
|
|
1487
|
+
}
|
|
1488
|
+
});
|
|
1489
|
+
|
|
1490
|
+
// src/tui/components/App.jsx
|
|
1491
|
+
import { mergeProps as _$mergeProps } from "@opentui/solid";
|
|
1492
|
+
import { effect as _$effect10 } from "@opentui/solid";
|
|
1493
|
+
import { insertNode as _$insertNode10 } from "@opentui/solid";
|
|
1494
|
+
import { insert as _$insert9 } from "@opentui/solid";
|
|
1495
|
+
import { memo as _$memo5 } from "@opentui/solid";
|
|
1496
|
+
import { setProp as _$setProp10 } from "@opentui/solid";
|
|
1497
|
+
import { createElement as _$createElement10 } from "@opentui/solid";
|
|
1498
|
+
import { createComponent as _$createComponent } from "@opentui/solid";
|
|
1499
|
+
import { createMemo as createMemo2, createSignal as createSignal5 } from "solid-js";
|
|
1500
|
+
import { useKeyboard as useKeyboard6, useRenderer, useTerminalDimensions as useTerminalDimensions2 } from "@opentui/solid";
|
|
1501
|
+
var App, App_default;
|
|
1502
|
+
var init_App = __esm({
|
|
1503
|
+
"src/tui/components/App.jsx"() {
|
|
1504
|
+
init_SecretTable();
|
|
1505
|
+
init_EditForm();
|
|
1506
|
+
init_CreateForm();
|
|
1507
|
+
init_HelpPanel();
|
|
1508
|
+
init_Header();
|
|
1509
|
+
init_Footer();
|
|
1510
|
+
init_ConfirmDialog();
|
|
1511
|
+
init_Warning();
|
|
1512
|
+
init_SearchInput();
|
|
1513
|
+
init_fuzzySearch();
|
|
1514
|
+
init_format();
|
|
1515
|
+
init_clipboard();
|
|
1516
|
+
App = (props) => {
|
|
1517
|
+
const renderer = useRenderer();
|
|
1518
|
+
const dimensions = useTerminalDimensions2();
|
|
1519
|
+
const [secrets, setSecrets] = createSignal5(props.secrets);
|
|
1520
|
+
const [selectedIndex, setSelectedIndex] = createSignal5(0);
|
|
1521
|
+
const [mode, setMode] = createSignal5("table");
|
|
1522
|
+
const [filter, setFilter] = createSignal5("");
|
|
1523
|
+
const [warning, setWarning] = createSignal5(null);
|
|
1524
|
+
const filtered = createMemo2(() => simpleFuzzySearch(secrets(), filter(), ["key", "tag", "comment"]));
|
|
1525
|
+
const selected = createMemo2(() => filtered()[selectedIndex()]);
|
|
1526
|
+
const notify = (message, type = "success", title = "Success") => setWarning({
|
|
1527
|
+
message,
|
|
1528
|
+
type,
|
|
1529
|
+
title
|
|
1530
|
+
});
|
|
1531
|
+
const reload = () => setSecrets(props.storage.getAll());
|
|
1532
|
+
const close = () => renderer.destroy();
|
|
1533
|
+
const save = (updates) => props.storage.update(selected().key, updates).then(() => {
|
|
1534
|
+
reload();
|
|
1535
|
+
setMode("table");
|
|
1536
|
+
notify("Token updated successfully");
|
|
1537
|
+
}).catch((error) => notify(`Error saving token: ${error.message}`, "error", "Error"));
|
|
1538
|
+
const create = (data) => props.storage.create(data).then(() => {
|
|
1539
|
+
reload();
|
|
1540
|
+
setMode("table");
|
|
1541
|
+
notify("Token created successfully");
|
|
1542
|
+
}).catch((error) => notify(`Error creating token: ${error.message}`, "error", "Error"));
|
|
1543
|
+
const remove = () => props.storage.delete(selected().key).then(() => {
|
|
1544
|
+
reload();
|
|
1545
|
+
setSelectedIndex((index) => Math.min(index, Math.max(filtered().length - 2, 0)));
|
|
1546
|
+
setMode("table");
|
|
1547
|
+
}).catch((error) => {
|
|
1548
|
+
setMode("table");
|
|
1549
|
+
notify(`Error deleting token: ${error.message}`, "error", "Error");
|
|
1550
|
+
});
|
|
1551
|
+
let lastD = 0;
|
|
1552
|
+
useKeyboard6((key) => {
|
|
1553
|
+
if (warning()) return;
|
|
1554
|
+
if (mode() === "help") {
|
|
1555
|
+
setMode("table");
|
|
1556
|
+
return;
|
|
1557
|
+
}
|
|
1558
|
+
if (mode() !== "table") return;
|
|
1559
|
+
if (key.name === "q" || key.ctrl && key.name === "c") close();
|
|
1560
|
+
else if (key.name === "?") setMode("help");
|
|
1561
|
+
else if (key.name === "c") setMode("create");
|
|
1562
|
+
else if (key.name === "e" && selected()) setMode("edit");
|
|
1563
|
+
else if (key.name === "f" || key.name === "/") setMode("search");
|
|
1564
|
+
else if (key.name === "up" || key.name === "k") setSelectedIndex((index) => Math.max(0, index - 1));
|
|
1565
|
+
else if (key.name === "down" || key.name === "j") setSelectedIndex((index) => Math.min(Math.max(filtered().length - 1, 0), index + 1));
|
|
1566
|
+
else if (key.name === "home" || key.name === "g") setSelectedIndex(0);
|
|
1567
|
+
else if (key.name === "end" || key.name === "G") setSelectedIndex(Math.max(filtered().length - 1, 0));
|
|
1568
|
+
else if (key.name === "d" && selected()) {
|
|
1569
|
+
const now = Date.now();
|
|
1570
|
+
if (now - lastD < 500) setMode("delete");
|
|
1571
|
+
lastD = now;
|
|
1572
|
+
} else if (key.name === "y" && selected()) {
|
|
1573
|
+
const copied = copyToClipboard(selected().token);
|
|
1574
|
+
notify(copied ? `Copied token "${selected().key}" to clipboard` : "Failed to copy to clipboard", copied ? "success" : "error", copied ? "Copied" : "Error");
|
|
1575
|
+
} else if (key.name === "Y" && selected()) {
|
|
1576
|
+
const copied = selected().sid != null && copyToClipboard(String(selected().sid));
|
|
1577
|
+
notify(selected().sid == null ? "No sid to copy" : copied ? `Copied sid "${selected().sid}" to clipboard` : "Failed to copy to clipboard", copied ? "success" : "error", copied ? "Copied" : "Error");
|
|
1578
|
+
}
|
|
1579
|
+
});
|
|
1580
|
+
const expired = createMemo2(() => secrets().filter((secret) => getSecretStatus(secret).label === "Expired").length);
|
|
1581
|
+
const expiring = createMemo2(() => secrets().filter((secret) => getSecretStatus(secret).label.startsWith("Expires in")).length);
|
|
1582
|
+
const content = () => mode() === "delete" ? _$createComponent(ConfirmDialog_default, {
|
|
1583
|
+
get message() {
|
|
1584
|
+
return `Delete token "${selected()?.key}"? This action cannot be undone.`;
|
|
1585
|
+
},
|
|
1586
|
+
onConfirm: remove,
|
|
1587
|
+
onCancel: () => setMode("table")
|
|
1588
|
+
}) : mode() === "search" ? _$createComponent(SearchInput_default, {
|
|
1589
|
+
get initialValue() {
|
|
1590
|
+
return filter();
|
|
1591
|
+
},
|
|
1592
|
+
onSearch: (value) => {
|
|
1593
|
+
setFilter(value);
|
|
1594
|
+
setSelectedIndex(0);
|
|
1595
|
+
},
|
|
1596
|
+
onCancel: () => setMode("table")
|
|
1597
|
+
}) : mode() === "create" ? _$createComponent(CreateForm_default, {
|
|
1598
|
+
onSave: create,
|
|
1599
|
+
onCancel: () => setMode("table")
|
|
1600
|
+
}) : mode() === "edit" ? _$createComponent(EditForm_default, {
|
|
1601
|
+
get token() {
|
|
1602
|
+
return selected();
|
|
1603
|
+
},
|
|
1604
|
+
onSave: save,
|
|
1605
|
+
onCancel: () => setMode("table")
|
|
1606
|
+
}) : mode() === "help" ? _$createComponent(HelpPanel_default, {}) : _$createComponent(SecretTable_default, {
|
|
1607
|
+
get tokens() {
|
|
1608
|
+
return filtered();
|
|
1609
|
+
},
|
|
1610
|
+
get selectedIndex() {
|
|
1611
|
+
return selectedIndex();
|
|
1612
|
+
}
|
|
1613
|
+
});
|
|
1614
|
+
return (() => {
|
|
1615
|
+
var _el$ = _$createElement10("box"), _el$2 = _$createElement10("box");
|
|
1616
|
+
_$insertNode10(_el$, _el$2);
|
|
1617
|
+
_$setProp10(_el$, "flexDirection", "column");
|
|
1618
|
+
_$insert9(_el$, _$createComponent(Header_default, {
|
|
1619
|
+
get tokenCount() {
|
|
1620
|
+
return secrets().length;
|
|
1621
|
+
},
|
|
1622
|
+
get expiredCount() {
|
|
1623
|
+
return expired();
|
|
1624
|
+
},
|
|
1625
|
+
get warningCount() {
|
|
1626
|
+
return expiring();
|
|
1627
|
+
},
|
|
1628
|
+
get filter() {
|
|
1629
|
+
return filter();
|
|
1630
|
+
}
|
|
1631
|
+
}), _el$2);
|
|
1632
|
+
_$insert9(_el$, (() => {
|
|
1633
|
+
var _c$ = _$memo5(() => !!warning());
|
|
1634
|
+
return () => _c$() && _$createComponent(Warning_default, _$mergeProps(warning, {
|
|
1635
|
+
autoClose: true,
|
|
1636
|
+
onClose: () => setWarning(null)
|
|
1637
|
+
}));
|
|
1638
|
+
})(), _el$2);
|
|
1639
|
+
_$setProp10(_el$2, "flexGrow", 1);
|
|
1640
|
+
_$setProp10(_el$2, "overflow", "hidden");
|
|
1641
|
+
_$insert9(_el$2, content);
|
|
1642
|
+
_$insert9(_el$, _$createComponent(Footer_default, {
|
|
1643
|
+
get selectedToken() {
|
|
1644
|
+
return selected();
|
|
1645
|
+
},
|
|
1646
|
+
get isEditing() {
|
|
1647
|
+
return mode() === "edit";
|
|
1648
|
+
},
|
|
1649
|
+
get isCreating() {
|
|
1650
|
+
return mode() === "create";
|
|
1651
|
+
},
|
|
1652
|
+
get showHelp() {
|
|
1653
|
+
return mode() === "help";
|
|
1654
|
+
}
|
|
1655
|
+
}), null);
|
|
1656
|
+
_$effect10((_$p) => _$setProp10(_el$, "height", dimensions().height || 24, _$p));
|
|
1657
|
+
return _el$;
|
|
1658
|
+
})();
|
|
1659
|
+
};
|
|
1660
|
+
App_default = App;
|
|
1661
|
+
}
|
|
1662
|
+
});
|
|
1663
|
+
|
|
1664
|
+
// src/tui/index.js
|
|
1665
|
+
var tui_exports = {};
|
|
1666
|
+
__export(tui_exports, {
|
|
1667
|
+
default: () => tui_default
|
|
1668
|
+
});
|
|
1669
|
+
import { createComponent as _$createComponent2 } from "@opentui/solid";
|
|
1670
|
+
import os3 from "os";
|
|
1671
|
+
import { render } from "@opentui/solid";
|
|
1672
|
+
var checkWindowsVersion, main, tui_default;
|
|
1673
|
+
var init_tui = __esm({
|
|
1674
|
+
"src/tui/index.js"() {
|
|
1675
|
+
init_App();
|
|
1676
|
+
init_SecretStorage();
|
|
1677
|
+
checkWindowsVersion = () => {
|
|
1678
|
+
if (os3.platform() !== "win32") return;
|
|
1679
|
+
const build = parseInt(os3.release().split(".")[2], 10);
|
|
1680
|
+
if (Number.isNaN(build) || build < 22e3) throw new Error(`Clavis requires Windows 11 or later. Detected Windows build: ${os3.release()}`);
|
|
1681
|
+
};
|
|
1682
|
+
main = () => {
|
|
1683
|
+
checkWindowsVersion();
|
|
1684
|
+
if (process.stdout.isTTY === false) throw new Error("stdout is not a TTY. This application requires an interactive terminal.");
|
|
1685
|
+
const storage2 = new SecretStorage_default();
|
|
1686
|
+
return storage2.init().then(() => render(() => _$createComponent2(App_default, {
|
|
1687
|
+
get secrets() {
|
|
1688
|
+
return storage2.getAll();
|
|
1689
|
+
},
|
|
1690
|
+
storage: storage2
|
|
1691
|
+
})));
|
|
1692
|
+
};
|
|
1693
|
+
tui_default = main;
|
|
1694
|
+
}
|
|
1695
|
+
});
|
|
1696
|
+
|
|
1697
|
+
// src/index.js
|
|
1698
|
+
init_SecretStorage();
|
|
1699
|
+
init_ConfigService();
|
|
1700
|
+
import { program } from "commander";
|
|
1701
|
+
import { createInterface } from "readline";
|
|
1702
|
+
import { spawn } from "child_process";
|
|
1703
|
+
import { createRequire } from "module";
|
|
1704
|
+
import { promises as fs3 } from "fs";
|
|
1705
|
+
|
|
1706
|
+
// src/services/gist.js
|
|
1707
|
+
import { Octokit } from "@octokit/rest";
|
|
1708
|
+
var desc = "clavis cloud backup";
|
|
1709
|
+
var META_FILE = "...clavis";
|
|
1710
|
+
var TOKENS_FILE = "tokens.json";
|
|
1711
|
+
var getOctokit = (token) => {
|
|
1712
|
+
return new Octokit({ auth: token });
|
|
1713
|
+
};
|
|
1714
|
+
var buildMeta = (version2) => {
|
|
1715
|
+
return JSON.stringify({
|
|
1716
|
+
lastUpload: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1717
|
+
version: version2
|
|
1718
|
+
});
|
|
1719
|
+
};
|
|
1720
|
+
var gist_default = {
|
|
1721
|
+
createGist(token, version2) {
|
|
1722
|
+
const octokit = getOctokit(token);
|
|
1723
|
+
return octokit.gists.create({
|
|
1724
|
+
description: desc,
|
|
1725
|
+
files: {
|
|
1726
|
+
[META_FILE]: {
|
|
1727
|
+
content: buildMeta(version2)
|
|
1728
|
+
}
|
|
1729
|
+
},
|
|
1730
|
+
public: false
|
|
1731
|
+
}).then((result) => {
|
|
1732
|
+
return result.data.id;
|
|
1733
|
+
});
|
|
1734
|
+
},
|
|
1735
|
+
deleteGist(token, id) {
|
|
1736
|
+
const octokit = getOctokit(token);
|
|
1737
|
+
return octokit.gists.delete({
|
|
1738
|
+
gist_id: id
|
|
1739
|
+
});
|
|
1740
|
+
},
|
|
1741
|
+
/** Upload tokens.json content and update metadata file */
|
|
1742
|
+
upload(token, id, tokensContent, version2) {
|
|
1743
|
+
const octokit = getOctokit(token);
|
|
1744
|
+
return octokit.gists.update({
|
|
1745
|
+
gist_id: id,
|
|
1746
|
+
description: desc,
|
|
1747
|
+
files: {
|
|
1748
|
+
[TOKENS_FILE]: {
|
|
1749
|
+
content: tokensContent
|
|
1750
|
+
},
|
|
1751
|
+
[META_FILE]: {
|
|
1752
|
+
content: buildMeta(version2)
|
|
1753
|
+
}
|
|
1754
|
+
}
|
|
1755
|
+
});
|
|
1756
|
+
},
|
|
1757
|
+
/** Download tokens.json content from gist */
|
|
1758
|
+
download(token, id) {
|
|
1759
|
+
const octokit = getOctokit(token);
|
|
1760
|
+
return octokit.gists.get({
|
|
1761
|
+
gist_id: id
|
|
1762
|
+
}).then((result) => {
|
|
1763
|
+
const file = result.data.files[TOKENS_FILE];
|
|
1764
|
+
if (!file) {
|
|
1765
|
+
throw new Error(`"${TOKENS_FILE}" not found in gist`);
|
|
1766
|
+
}
|
|
1767
|
+
return file.content;
|
|
1768
|
+
});
|
|
1769
|
+
}
|
|
1770
|
+
};
|
|
1771
|
+
|
|
1772
|
+
// src/index.js
|
|
1773
|
+
import { setPassword as setPassword2, getPassword as getPassword3 } from "cross-keychain";
|
|
1774
|
+
var require2 = createRequire(import.meta.url);
|
|
1775
|
+
var { version } = require2("../package.json");
|
|
1776
|
+
var storage = new SecretStorage_default();
|
|
1777
|
+
var readPassword = (prompt) => new Promise((resolve) => {
|
|
1778
|
+
process.stdout.write(prompt);
|
|
1779
|
+
if (!process.stdin.isTTY) {
|
|
1780
|
+
const rl = createInterface({ input: process.stdin });
|
|
1781
|
+
rl.once("line", (line) => {
|
|
1782
|
+
rl.close();
|
|
1783
|
+
resolve(line);
|
|
1784
|
+
});
|
|
1785
|
+
return;
|
|
1786
|
+
}
|
|
1787
|
+
process.stdin.setRawMode(true);
|
|
1788
|
+
process.stdin.setEncoding("utf8");
|
|
1789
|
+
let input = "";
|
|
1790
|
+
const onData = (ch) => {
|
|
1791
|
+
if (ch === "\r" || ch === "\n") {
|
|
1792
|
+
process.stdin.removeListener("data", onData);
|
|
1793
|
+
process.stdin.setRawMode(false);
|
|
1794
|
+
process.stdin.pause();
|
|
1795
|
+
process.stdout.write("\n");
|
|
1796
|
+
resolve(input);
|
|
1797
|
+
} else if (ch === "") {
|
|
1798
|
+
process.stdout.write("\n");
|
|
1799
|
+
process.exit(0);
|
|
1800
|
+
} else if (ch === "\x7F") {
|
|
1801
|
+
if (input.length > 0) {
|
|
1802
|
+
input = input.slice(0, -1);
|
|
1803
|
+
}
|
|
1804
|
+
} else {
|
|
1805
|
+
input += ch;
|
|
1806
|
+
}
|
|
1807
|
+
};
|
|
1808
|
+
process.stdin.resume();
|
|
1809
|
+
process.stdin.on("data", onData);
|
|
1810
|
+
});
|
|
1811
|
+
async function init() {
|
|
1812
|
+
await storage.init();
|
|
1813
|
+
}
|
|
1814
|
+
function formatSecret(secret) {
|
|
1815
|
+
const expired = secret.expiration && new Date(secret.expiration) < /* @__PURE__ */ new Date();
|
|
1816
|
+
const status = expired ? "\u2717 EXPIRED" : "\u2713 ACTIVE";
|
|
1817
|
+
return `${secret.key} ${status}
|
|
1818
|
+
Token: ${secret.token.substring(0, 20)}...
|
|
1819
|
+
Expiration: ${secret.expiration || "Never"}
|
|
1820
|
+
Tag: ${secret.tag || "None"}
|
|
1821
|
+
Comment: ${secret.comment || "None"}
|
|
1822
|
+
Created: ${new Date(secret.createdAt).toLocaleDateString()}
|
|
1823
|
+
Updated: ${new Date(secret.updatedAt).toLocaleDateString()}
|
|
1824
|
+
`;
|
|
1825
|
+
}
|
|
1826
|
+
function formatSecretList(secrets) {
|
|
1827
|
+
if (secrets.length === 0) {
|
|
1828
|
+
return "No tokens found";
|
|
1829
|
+
}
|
|
1830
|
+
return secrets.map((secret) => {
|
|
1831
|
+
const expired = secret.expiration && new Date(secret.expiration) < /* @__PURE__ */ new Date();
|
|
1832
|
+
const status = expired ? "\u2717" : "\u2713";
|
|
1833
|
+
return `${status} ${secret.key} - ${secret.tag || "No tag"}`;
|
|
1834
|
+
}).join("\n");
|
|
1835
|
+
}
|
|
1836
|
+
program.name("clavis").description("API Token Management System").version(version);
|
|
1837
|
+
program.command("create").description("Create a new API token").requiredOption("-k, --key <key>", "Token key (e.g., foo.bar.baz)").requiredOption("-t, --token <token>", "API token value").option("-e, --expiration <date>", "Expiration date (YYYY-MM-DD)").option("--tag <tag>", "Tag for categorization").option("-c, --comment <comment>", "Comment/description").action(async (options) => {
|
|
1838
|
+
await init();
|
|
1839
|
+
try {
|
|
1840
|
+
const secret = await storage.create({
|
|
1841
|
+
key: options.key,
|
|
1842
|
+
token: options.token,
|
|
1843
|
+
expiration: options.expiration,
|
|
1844
|
+
tag: options.tag,
|
|
1845
|
+
comment: options.comment
|
|
1846
|
+
});
|
|
1847
|
+
console.log("\u2713 Token created successfully");
|
|
1848
|
+
console.log(formatSecret(secret));
|
|
1849
|
+
} catch (error) {
|
|
1850
|
+
console.error("\u2717 Error:", error.message);
|
|
1851
|
+
process.exit(1);
|
|
1852
|
+
}
|
|
1853
|
+
});
|
|
1854
|
+
program.command("list").description("List all tokens or search by key pattern").option("-s, --search <pattern>", "Search pattern for key").option("--tag <tag>", "Filter by tag").action(async (options) => {
|
|
1855
|
+
await init();
|
|
1856
|
+
let secrets;
|
|
1857
|
+
if (options.search) {
|
|
1858
|
+
secrets = storage.searchByKey(options.search);
|
|
1859
|
+
} else if (options.tag) {
|
|
1860
|
+
secrets = storage.searchByTag(options.tag);
|
|
1861
|
+
} else {
|
|
1862
|
+
secrets = storage.getAll();
|
|
1863
|
+
}
|
|
1864
|
+
console.log(`Found ${secrets.length} token(s):`);
|
|
1865
|
+
console.log(formatSecretList(secrets));
|
|
1866
|
+
});
|
|
1867
|
+
program.command("show <key>").description("Show details of a specific token").action(async (key) => {
|
|
1868
|
+
await init();
|
|
1869
|
+
const secret = storage.get(key);
|
|
1870
|
+
if (!secret) {
|
|
1871
|
+
console.error(`\u2717 Token with key "${key}" not found`);
|
|
1872
|
+
process.exit(1);
|
|
1873
|
+
}
|
|
1874
|
+
console.log(formatSecret(secret));
|
|
1875
|
+
});
|
|
1876
|
+
program.command("update <key>").description("Update an existing token").option("-t, --token <token>", "New API token value").option("-e, --expiration <date>", "New expiration date (YYYY-MM-DD)").option("--tag <tag>", "New tag").option("-c, --comment <comment>", "New comment").action(async (key, options) => {
|
|
1877
|
+
await init();
|
|
1878
|
+
const updates = {};
|
|
1879
|
+
if (options.token) {
|
|
1880
|
+
updates.token = options.token;
|
|
1881
|
+
}
|
|
1882
|
+
if (options.expiration !== void 0) {
|
|
1883
|
+
updates.expiration = options.expiration;
|
|
1884
|
+
}
|
|
1885
|
+
if (options.tag !== void 0) {
|
|
1886
|
+
updates.tag = options.tag;
|
|
1887
|
+
}
|
|
1888
|
+
if (options.comment !== void 0) {
|
|
1889
|
+
updates.comment = options.comment;
|
|
1890
|
+
}
|
|
1891
|
+
if (Object.keys(updates).length === 0) {
|
|
1892
|
+
console.error("No updates specified");
|
|
1893
|
+
return;
|
|
1894
|
+
}
|
|
1895
|
+
try {
|
|
1896
|
+
const secret = await storage.update(key, updates);
|
|
1897
|
+
console.log("\u2713 Token updated successfully");
|
|
1898
|
+
console.log(formatSecret(secret));
|
|
1899
|
+
} catch (error) {
|
|
1900
|
+
console.error("\u2717 Error:", error.message);
|
|
1901
|
+
process.exit(1);
|
|
1902
|
+
}
|
|
1903
|
+
});
|
|
1904
|
+
program.command("delete <key>").description("Delete a token").action(async (key) => {
|
|
1905
|
+
await init();
|
|
1906
|
+
try {
|
|
1907
|
+
await storage.delete(key);
|
|
1908
|
+
console.log(`\u2713 Token "${key}" deleted successfully`);
|
|
1909
|
+
} catch (error) {
|
|
1910
|
+
console.error("\u2717 Error:", error.message);
|
|
1911
|
+
process.exit(1);
|
|
1912
|
+
}
|
|
1913
|
+
});
|
|
1914
|
+
program.command("clear").description("Clear all tokens (use with caution!)").action(async () => {
|
|
1915
|
+
await init();
|
|
1916
|
+
console.log("Warning: This will delete ALL tokens");
|
|
1917
|
+
console.log('Type "YES" to confirm:');
|
|
1918
|
+
const readline = createInterface({
|
|
1919
|
+
input: process.stdin,
|
|
1920
|
+
output: process.stdout
|
|
1921
|
+
});
|
|
1922
|
+
readline.question("", async (answer) => {
|
|
1923
|
+
if (answer === "YES") {
|
|
1924
|
+
await storage.clear();
|
|
1925
|
+
console.log("\u2713 All tokens cleared");
|
|
1926
|
+
} else {
|
|
1927
|
+
console.log("Operation cancelled");
|
|
1928
|
+
}
|
|
1929
|
+
readline.close();
|
|
1930
|
+
});
|
|
1931
|
+
});
|
|
1932
|
+
program.command("tui").description("Start interactive TUI interface").action(async () => {
|
|
1933
|
+
try {
|
|
1934
|
+
const startTUI = (await Promise.resolve().then(() => (init_tui(), tui_exports))).default;
|
|
1935
|
+
await startTUI();
|
|
1936
|
+
} catch (error) {
|
|
1937
|
+
console.error("Failed to start TUI:", error.message);
|
|
1938
|
+
if (error.message.includes("OpenTUI native FFI is not available")) {
|
|
1939
|
+
console.error("OpenTUI requires Bun because the current Node.js runtime does not provide node:ffi.");
|
|
1940
|
+
console.error("Install Bun from https://bun.sh, then run: npm run go");
|
|
1941
|
+
} else {
|
|
1942
|
+
console.error("Make sure all dependencies are installed: npm install");
|
|
1943
|
+
}
|
|
1944
|
+
process.exit(1);
|
|
1945
|
+
}
|
|
1946
|
+
});
|
|
1947
|
+
program.command("exec").description("Execute a command with a token injected as environment variable").argument("<sid>", "Token sid").allowExcessArguments(true).action(async (sid) => {
|
|
1948
|
+
const dashDashIndex = process.argv.indexOf("--");
|
|
1949
|
+
if (dashDashIndex === -1 || dashDashIndex >= process.argv.length - 1) {
|
|
1950
|
+
console.error("Usage: clavis exec <sid> -- <command> [args...]");
|
|
1951
|
+
process.exit(1);
|
|
1952
|
+
}
|
|
1953
|
+
const commandArgs = process.argv.slice(dashDashIndex + 1);
|
|
1954
|
+
await init();
|
|
1955
|
+
const secret = storage.getBySid(sid);
|
|
1956
|
+
if (!secret) {
|
|
1957
|
+
console.error(`\u2717 Token with sid "${sid}" not found`);
|
|
1958
|
+
process.exit(1);
|
|
1959
|
+
}
|
|
1960
|
+
if (!secret.env) {
|
|
1961
|
+
console.error(`\u2717 Token "${secret.key}" has no env variable name configured`);
|
|
1962
|
+
process.exit(1);
|
|
1963
|
+
}
|
|
1964
|
+
const env = { ...process.env, [secret.env]: secret.token };
|
|
1965
|
+
const child = spawn(commandArgs[0], commandArgs.slice(1), {
|
|
1966
|
+
env,
|
|
1967
|
+
stdio: "inherit"
|
|
1968
|
+
});
|
|
1969
|
+
child.on("error", (error) => {
|
|
1970
|
+
console.error(`\u2717 Failed to execute command: ${error.message}`);
|
|
1971
|
+
process.exit(1);
|
|
1972
|
+
});
|
|
1973
|
+
child.on("exit", (code) => {
|
|
1974
|
+
process.exit(code ?? 0);
|
|
1975
|
+
});
|
|
1976
|
+
});
|
|
1977
|
+
var KEYCHAIN_SERVICE3 = "clavis";
|
|
1978
|
+
var addCmd = program.command("add").description('Add credentials (pwd | gist-token | gist-id \u2014 run "clavis add --help")');
|
|
1979
|
+
addCmd.command("pwd").description("Store a password in the OS keychain").argument("[account]", "Account name / label", "master").action(async (account) => {
|
|
1980
|
+
const existing = await getPassword3(KEYCHAIN_SERVICE3, account).catch(() => null);
|
|
1981
|
+
if (existing) {
|
|
1982
|
+
const current = await readPassword(`Current password for "${account}": `);
|
|
1983
|
+
if (existing !== current) {
|
|
1984
|
+
console.error("\u2717 Current password is incorrect");
|
|
1985
|
+
process.exit(1);
|
|
1986
|
+
}
|
|
1987
|
+
}
|
|
1988
|
+
const password = await readPassword(`New password for "${account}": `);
|
|
1989
|
+
if (!password) {
|
|
1990
|
+
console.error("\u2717 Password cannot be empty");
|
|
1991
|
+
process.exit(1);
|
|
1992
|
+
}
|
|
1993
|
+
const confirm = await readPassword(`Confirm new password for "${account}": `);
|
|
1994
|
+
if (password !== confirm) {
|
|
1995
|
+
console.error("\u2717 Passwords do not match");
|
|
1996
|
+
process.exit(1);
|
|
1997
|
+
}
|
|
1998
|
+
try {
|
|
1999
|
+
await setPassword2(KEYCHAIN_SERVICE3, account, password);
|
|
2000
|
+
console.log(`\u2713 Password stored in keychain (service: ${KEYCHAIN_SERVICE3}, account: ${account})`);
|
|
2001
|
+
} catch (error) {
|
|
2002
|
+
console.error("\u2717 Failed to store password:", error.message);
|
|
2003
|
+
process.exit(1);
|
|
2004
|
+
}
|
|
2005
|
+
});
|
|
2006
|
+
var getCmd = program.command("get").description("Retrieve various types of credentials");
|
|
2007
|
+
getCmd.command("pwd").description("Retrieve a password from the OS keychain").argument("[account]", "Account name / label", "master").action(async (account) => {
|
|
2008
|
+
try {
|
|
2009
|
+
const password = await getPassword3(KEYCHAIN_SERVICE3, account);
|
|
2010
|
+
if (password === null || password === void 0) {
|
|
2011
|
+
console.error(`\u2717 No password found for account "${account}" in keychain`);
|
|
2012
|
+
process.exit(1);
|
|
2013
|
+
}
|
|
2014
|
+
console.log(password);
|
|
2015
|
+
} catch (error) {
|
|
2016
|
+
console.error("\u2717 Failed to retrieve password:", error.message);
|
|
2017
|
+
process.exit(1);
|
|
2018
|
+
}
|
|
2019
|
+
});
|
|
2020
|
+
var ensureGistConfig = (config) => {
|
|
2021
|
+
const ensureToken = config.getGistToken().then((existing) => {
|
|
2022
|
+
if (existing) return existing;
|
|
2023
|
+
return readPassword("GitHub Personal Access Token: ").then((token) => {
|
|
2024
|
+
if (!token) {
|
|
2025
|
+
console.error("\u2717 Token cannot be empty");
|
|
2026
|
+
process.exit(1);
|
|
2027
|
+
}
|
|
2028
|
+
return config.setGistToken(token).then(() => token);
|
|
2029
|
+
});
|
|
2030
|
+
});
|
|
2031
|
+
return ensureToken.then((token) => {
|
|
2032
|
+
const existingId = config.getGistId();
|
|
2033
|
+
if (existingId) {
|
|
2034
|
+
return { token, id: existingId };
|
|
2035
|
+
}
|
|
2036
|
+
process.stdout.write("No gist ID found \u2014 creating a new private gist...\n");
|
|
2037
|
+
return gist_default.createGist(token, version).then((id) => {
|
|
2038
|
+
return config.setGistId(id).then(() => {
|
|
2039
|
+
console.log(`\u2713 Gist created: ${id}`);
|
|
2040
|
+
return { token, id };
|
|
2041
|
+
});
|
|
2042
|
+
});
|
|
2043
|
+
});
|
|
2044
|
+
};
|
|
2045
|
+
addCmd.command("gist-token").description("Set GitHub Personal Access Token for gist sync").action(async () => {
|
|
2046
|
+
const config = new ConfigService_default();
|
|
2047
|
+
await config.init();
|
|
2048
|
+
const token = await readPassword("GitHub Personal Access Token: ");
|
|
2049
|
+
if (!token) {
|
|
2050
|
+
console.error("\u2717 Token cannot be empty");
|
|
2051
|
+
process.exit(1);
|
|
2052
|
+
}
|
|
2053
|
+
await config.setGistToken(token);
|
|
2054
|
+
console.log("\u2713 Gist token saved to OS keychain");
|
|
2055
|
+
});
|
|
2056
|
+
addCmd.command("gist-id").description("Set an existing GitHub Gist ID for sync").argument("<id>", "Gist ID").action(async (id) => {
|
|
2057
|
+
const config = new ConfigService_default();
|
|
2058
|
+
await config.init();
|
|
2059
|
+
await config.setGistId(id);
|
|
2060
|
+
console.log(`\u2713 Gist ID saved: ${id}`);
|
|
2061
|
+
});
|
|
2062
|
+
program.command("upload").description("Upload tokens.json to GitHub Gist").action(async () => {
|
|
2063
|
+
const config = new ConfigService_default();
|
|
2064
|
+
await config.init();
|
|
2065
|
+
try {
|
|
2066
|
+
const { token, id } = await ensureGistConfig(config);
|
|
2067
|
+
const storageInstance = new SecretStorage_default();
|
|
2068
|
+
await storageInstance.init();
|
|
2069
|
+
const tokensContent = await fs3.readFile(storageInstance.dataFile, "utf8");
|
|
2070
|
+
await gist_default.upload(token, id, tokensContent, version);
|
|
2071
|
+
console.log(`\u2713 Uploaded tokens.json to gist ${id}`);
|
|
2072
|
+
} catch (error) {
|
|
2073
|
+
console.error("\u2717 Upload failed:", error.message);
|
|
2074
|
+
process.exit(1);
|
|
2075
|
+
}
|
|
2076
|
+
});
|
|
2077
|
+
program.command("download").description("Download tokens.json from GitHub Gist and overwrite local file").action(async () => {
|
|
2078
|
+
const config = new ConfigService_default();
|
|
2079
|
+
await config.init();
|
|
2080
|
+
try {
|
|
2081
|
+
const { token, id } = await ensureGistConfig(config);
|
|
2082
|
+
const content = await gist_default.download(token, id);
|
|
2083
|
+
const storageInstance = new SecretStorage_default();
|
|
2084
|
+
await storageInstance.init();
|
|
2085
|
+
await fs3.writeFile(storageInstance.dataFile, content, "utf8");
|
|
2086
|
+
console.log(`\u2713 Downloaded tokens.json from gist ${id}`);
|
|
2087
|
+
} catch (error) {
|
|
2088
|
+
console.error("\u2717 Download failed:", error.message);
|
|
2089
|
+
process.exit(1);
|
|
2090
|
+
}
|
|
2091
|
+
});
|
|
2092
|
+
program.addHelpText("after", `
|
|
2093
|
+
Gist sync sub-commands (via "clavis add"):
|
|
2094
|
+
clavis add gist-token Set GitHub Personal Access Token for gist sync
|
|
2095
|
+
clavis add gist-id <id> Set an existing GitHub Gist ID for sync`);
|
|
2096
|
+
program.parse();
|
|
2097
|
+
//# sourceMappingURL=index.js.map
|