@runtypelabs/cli 2.59.1 → 2.59.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-0-T9NWjH.js +3899 -0
- package/dist/chunk-0x7UKC1U.js +17 -0
- package/dist/chunk-2ySxXtcg.js +418 -0
- package/dist/chunk-3An_BRHv.js +501 -0
- package/dist/chunk-6uTxgdiY.js +16218 -0
- package/dist/chunk-87nRnNRG.js +1363 -0
- package/dist/chunk-B3wo8uRx.js +322 -0
- package/dist/chunk-BGp3ZdBy.js +560 -0
- package/dist/chunk-BJQv9Elp.js +107 -0
- package/dist/chunk-BOpO6xE-.js +6053 -0
- package/dist/chunk-BQXXCL8B.js +102 -0
- package/dist/chunk-BV-8isOd.js +34 -0
- package/dist/chunk-BVMhjGVe.js +826 -0
- package/dist/chunk-BW2fg46T.js +141 -0
- package/dist/chunk-BWJdY5Ag.js +36 -0
- package/dist/chunk-BYJOrLhh.js +302 -0
- package/dist/chunk-BYab8EVL.js +127 -0
- package/dist/chunk-BfEKvp7h.js +82 -0
- package/dist/chunk-BhgLSfH6.js +1123 -0
- package/dist/chunk-BirUxTtH.js +296 -0
- package/dist/chunk-BmB6UVZ9.js +1559 -0
- package/dist/chunk-BnWhIqW1.js +109 -0
- package/dist/chunk-Bpfnfk0t.js +123 -0
- package/dist/chunk-BrhgdnM3.js +108 -0
- package/dist/chunk-Bt0XAgX5.js +327 -0
- package/dist/chunk-Bu0FJr6S.js +84 -0
- package/dist/chunk-BvEoKpN3.js +255 -0
- package/dist/chunk-BxNJgYbE.js +28 -0
- package/dist/chunk-C1OFhd7F.js +6131 -0
- package/dist/chunk-C7e7WwbU.js +331 -0
- package/dist/chunk-CDTYP6bN.js +558 -0
- package/dist/chunk-CGDQoqDC.js +24 -0
- package/dist/chunk-CJraEBVd.js +127 -0
- package/dist/chunk-CQrNhOtv.js +40 -0
- package/dist/chunk-CW6AzBH6.js +128 -0
- package/dist/chunk-CXgL4w-9.js +317 -0
- package/dist/chunk-CZrqoPyf.js +233 -0
- package/dist/chunk-CcFCyqbB.js +83 -0
- package/dist/chunk-CdaIvO-y.js +485 -0
- package/dist/chunk-CehSXtgK.js +624 -0
- package/dist/chunk-Ciqkop65.js +218 -0
- package/dist/chunk-CoAWdSiE.js +43 -0
- package/dist/chunk-Crb4y7t4.js +830 -0
- package/dist/chunk-CrlqIfmb.js +337 -0
- package/dist/chunk-Cs4pwCQ-.js +324 -0
- package/dist/chunk-CwM_9y01.js +519 -0
- package/dist/chunk-CyRbIJg8.js +440 -0
- package/dist/chunk-D0OHsyMy.js +212 -0
- package/dist/chunk-D3y2bURs.js +1347 -0
- package/dist/chunk-D4_mJk03.js +2338 -0
- package/dist/chunk-D6C8rned.js +578 -0
- package/dist/chunk-D9ZbUnks.js +11 -0
- package/dist/chunk-DEPmLshX.js +834 -0
- package/dist/chunk-DFj1UPB2.js +330 -0
- package/dist/chunk-DGdFdZVf.js +197 -0
- package/dist/chunk-DGv7X9S_.js +63 -0
- package/dist/chunk-DJQ47WYZ.js +664 -0
- package/dist/chunk-DJw3O61j.js +1974 -0
- package/dist/chunk-DK4FbWVK.js +100 -0
- package/dist/chunk-DSRYhUus.js +993 -0
- package/dist/chunk-DajZ9Eg4.js +299 -0
- package/dist/chunk-Df4dunvU.js +195 -0
- package/dist/chunk-DjNTPhfO.js +481 -0
- package/dist/chunk-Dn8eaJuu.js +1042 -0
- package/dist/chunk-DwDWqSxM.js +637 -0
- package/dist/chunk-Dz7cEtxl.js +84 -0
- package/dist/chunk-E_0bgjrS.js +359 -0
- package/dist/chunk-KPYN2vUp.js +776 -0
- package/dist/chunk-KcqPQJBi.js +86 -0
- package/dist/chunk-N9H0JnoG.js +349 -0
- package/dist/chunk-NONFcXkn.js +728 -0
- package/dist/chunk-PrFjcpmH.js +256 -0
- package/dist/chunk-QSfNYiw9.js +11 -0
- package/dist/chunk-R265bzj9.js +226 -0
- package/dist/chunk-X9V_r6jM.js +166 -0
- package/dist/chunk-ZBtPUtyA.js +55 -0
- package/dist/chunk-ZCTfmOs7.js +4939 -0
- package/dist/chunk-h6oavj0t.js +97 -0
- package/dist/chunk-i7DwkvvD.js +42 -0
- package/dist/chunk-mG-4eZ6S.js +203 -0
- package/dist/chunk-o0ygUbCf.js +313 -0
- package/dist/chunk-ucu5lrDZ.js +5715 -0
- package/dist/index.js +11367 -73789
- package/package.json +4 -4
|
@@ -0,0 +1,501 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { t as isTTY } from "./index.js";
|
|
3
|
+
import { ConfirmPrompt, DataList, EntityCard, MutationResult, React, Text, render, useEffect, useState } from "./chunk-CoAWdSiE.js";
|
|
4
|
+
import { r as createCliClient } from "./chunk-BW2fg46T.js";
|
|
5
|
+
import { n as ensureAuth } from "./chunk-CJraEBVd.js";
|
|
6
|
+
import { a as printJson, i as printDetail } from "./chunk-CcFCyqbB.js";
|
|
7
|
+
import { l as clientTokenEnsureCommand } from "./chunk-BirUxTtH.js";
|
|
8
|
+
import { Command } from "commander";
|
|
9
|
+
import chalk from "chalk";
|
|
10
|
+
// src/commands/client-tokens.ts
|
|
11
|
+
const clientTokensCommand = new Command("client-tokens").description("Manage client tokens for Persona widget embedding");
|
|
12
|
+
clientTokensCommand.command("list").description("List your client tokens").option("--json", "Output as JSON").option("--tty", "Force TTY mode").option("--no-tty", "Force non-TTY mode").action(async (options) => {
|
|
13
|
+
const apiKey = await ensureAuth();
|
|
14
|
+
if (!apiKey) return;
|
|
15
|
+
const client = createCliClient(apiKey);
|
|
16
|
+
if (!isTTY(options) || options.json) {
|
|
17
|
+
try {
|
|
18
|
+
const data = await client.get("/client-tokens");
|
|
19
|
+
const tokens = data.clientTokens ?? [];
|
|
20
|
+
if (options.json) printJson(data);
|
|
21
|
+
else {
|
|
22
|
+
if (tokens.length === 0) {
|
|
23
|
+
console.log(chalk.gray("No client tokens found"));
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
console.log(chalk.cyan("Your Client Tokens:"));
|
|
27
|
+
for (const token of tokens) {
|
|
28
|
+
const env = token.environment === "live" ? chalk.green("live") : chalk.yellow("test");
|
|
29
|
+
const active = token.isActive ? "" : chalk.red(" (inactive)");
|
|
30
|
+
const origins = chalk.gray(` origins: ${(token.allowedOrigins || []).join(", ")}`);
|
|
31
|
+
console.log(` ${chalk.green(token.id)} ${token.name} [${env}]${active}${origins}`);
|
|
32
|
+
}
|
|
33
|
+
console.log(chalk.dim(`\n Total: ${tokens.length} tokens`));
|
|
34
|
+
}
|
|
35
|
+
} catch (error) {
|
|
36
|
+
const message = error instanceof Error ? error.message : "Unknown error";
|
|
37
|
+
console.error(chalk.red("Failed to fetch client tokens"));
|
|
38
|
+
console.error(chalk.red(message));
|
|
39
|
+
process.exit(1);
|
|
40
|
+
}
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const App = () => {
|
|
44
|
+
const [loading, setLoading] = useState(true);
|
|
45
|
+
const [items, setItems] = useState(null);
|
|
46
|
+
const [total, setTotal] = useState(void 0);
|
|
47
|
+
const [error, setError] = useState(null);
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
const run = async () => {
|
|
50
|
+
try {
|
|
51
|
+
const tokens = (await client.get("/client-tokens")).clientTokens ?? [];
|
|
52
|
+
setItems(tokens);
|
|
53
|
+
setTotal(tokens.length);
|
|
54
|
+
setLoading(false);
|
|
55
|
+
} catch (err) {
|
|
56
|
+
setError(err instanceof Error ? err : new Error(String(err)));
|
|
57
|
+
setLoading(false);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
run();
|
|
61
|
+
}, []);
|
|
62
|
+
return React.createElement(DataList, {
|
|
63
|
+
title: "Your Client Tokens",
|
|
64
|
+
items,
|
|
65
|
+
error,
|
|
66
|
+
loading,
|
|
67
|
+
total,
|
|
68
|
+
emptyMessage: "No client tokens found",
|
|
69
|
+
renderCard: (item) => {
|
|
70
|
+
const t = item;
|
|
71
|
+
const env = t.environment === "live" ? "live" : "test";
|
|
72
|
+
const active = t.isActive ? "" : " (inactive)";
|
|
73
|
+
return React.createElement(Text, null, ` ${t.id} ${t.name} [${env}]${active}`);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
const { waitUntilExit } = render(React.createElement(App));
|
|
78
|
+
await waitUntilExit();
|
|
79
|
+
});
|
|
80
|
+
clientTokensCommand.command("get <id>").description("Get client token details").option("--json", "Output as JSON").option("--tty", "Force TTY mode").option("--no-tty", "Force non-TTY mode").action(async (id, options) => {
|
|
81
|
+
const apiKey = await ensureAuth();
|
|
82
|
+
if (!apiKey) return;
|
|
83
|
+
const client = createCliClient(apiKey);
|
|
84
|
+
if (!isTTY(options) || options.json) {
|
|
85
|
+
try {
|
|
86
|
+
const data = await client.get(`/client-tokens/${id}`);
|
|
87
|
+
const token = data.clientToken;
|
|
88
|
+
if (options.json) printJson(data);
|
|
89
|
+
else printDetail("Client Token", [
|
|
90
|
+
{
|
|
91
|
+
label: "ID",
|
|
92
|
+
value: token.id
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
label: "Name",
|
|
96
|
+
value: token.name
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
label: "Environment",
|
|
100
|
+
value: token.environment
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
label: "Active",
|
|
104
|
+
value: token.isActive
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
label: "Token Value",
|
|
108
|
+
value: token.tokenValue
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
label: "Flow IDs",
|
|
112
|
+
value: (token.flowIds || []).join(", ") || null
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
label: "Default Flow ID",
|
|
116
|
+
value: token.defaultFlowId
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
label: "Agent IDs",
|
|
120
|
+
value: (token.agentIds || []).join(", ") || null
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
label: "Allowed Origins",
|
|
124
|
+
value: (token.allowedOrigins || []).join(", ")
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
label: "Rate Limit/min",
|
|
128
|
+
value: token.rateLimitPerMinute
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
label: "Rate Limit/hr",
|
|
132
|
+
value: token.rateLimitPerHour
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
label: "Max Messages/Session",
|
|
136
|
+
value: token.maxMessagesPerSession
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
label: "Session Timeout (min)",
|
|
140
|
+
value: token.sessionIdleTimeoutMinutes
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
label: "Conversations",
|
|
144
|
+
value: token.conversationCount
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
label: "Last Used",
|
|
148
|
+
value: token.lastUsedAt
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
label: "Created",
|
|
152
|
+
value: token.createdAt
|
|
153
|
+
}
|
|
154
|
+
]);
|
|
155
|
+
} catch (error) {
|
|
156
|
+
const message = error instanceof Error ? error.message : "Unknown error";
|
|
157
|
+
console.error(chalk.red("Failed to fetch client token"));
|
|
158
|
+
console.error(chalk.red(message));
|
|
159
|
+
process.exit(1);
|
|
160
|
+
}
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
const App = () => {
|
|
164
|
+
const [loading, setLoading] = useState(true);
|
|
165
|
+
const [success, setSuccess] = useState(null);
|
|
166
|
+
const [error, setError] = useState(null);
|
|
167
|
+
const [resultNode, setResultNode] = useState(void 0);
|
|
168
|
+
useEffect(() => {
|
|
169
|
+
const run = async () => {
|
|
170
|
+
try {
|
|
171
|
+
const token = (await client.get(`/client-tokens/${id}`)).clientToken;
|
|
172
|
+
setResultNode(React.createElement(EntityCard, { fields: [
|
|
173
|
+
{
|
|
174
|
+
label: "ID",
|
|
175
|
+
value: token.id
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
label: "Name",
|
|
179
|
+
value: token.name
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
label: "Environment",
|
|
183
|
+
value: token.environment
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
label: "Active",
|
|
187
|
+
value: String(token.isActive)
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
label: "Token Value",
|
|
191
|
+
value: token.tokenValue
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
label: "Flow IDs",
|
|
195
|
+
value: (token.flowIds || []).join(", ") || null
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
label: "Agent IDs",
|
|
199
|
+
value: (token.agentIds || []).join(", ") || null
|
|
200
|
+
},
|
|
201
|
+
{
|
|
202
|
+
label: "Allowed Origins",
|
|
203
|
+
value: (token.allowedOrigins || []).join(", ")
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
label: "Last Used",
|
|
207
|
+
value: token.lastUsedAt
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
label: "Created",
|
|
211
|
+
value: token.createdAt
|
|
212
|
+
}
|
|
213
|
+
] }));
|
|
214
|
+
setSuccess(true);
|
|
215
|
+
setLoading(false);
|
|
216
|
+
} catch (err) {
|
|
217
|
+
setError(err instanceof Error ? err : new Error(String(err)));
|
|
218
|
+
setSuccess(false);
|
|
219
|
+
setLoading(false);
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
run();
|
|
223
|
+
}, []);
|
|
224
|
+
return React.createElement(MutationResult, {
|
|
225
|
+
loading,
|
|
226
|
+
loadingLabel: "Fetching client token...",
|
|
227
|
+
success,
|
|
228
|
+
successMessage: "Client Token",
|
|
229
|
+
error,
|
|
230
|
+
result: resultNode
|
|
231
|
+
});
|
|
232
|
+
};
|
|
233
|
+
const { waitUntilExit } = render(React.createElement(App));
|
|
234
|
+
await waitUntilExit();
|
|
235
|
+
});
|
|
236
|
+
clientTokensCommand.command("create").description("Create a new client token").requiredOption("-n, --name <name>", "Token name").option("--origins <origins...>", "Allowed origins (e.g. https://example.com). Defaults to * (all origins)").option("--environment <env>", "Token environment: test or live", "test").option("--flow-ids <ids...>", "Flow IDs to associate").option("--default-flow-id <id>", "Default flow ID (required when flow-ids provided)").option("--agent-ids <ids...>", "Agent IDs to associate").option("--target-alias <name>", "Release alias this token follows for its agent target").option("--target-version-id <id>", "Exact agent version this token pins").option("--rate-limit-per-minute <n>", "Rate limit per minute", "10").option("--rate-limit-per-hour <n>", "Rate limit per hour", "100").option("--max-messages <n>", "Max messages per session", "100").option("--session-timeout <n>", "Session idle timeout in minutes", "30").option("--json", "Output as JSON").option("--tty", "Force TTY mode").option("--no-tty", "Force non-TTY mode").action(async (options) => {
|
|
237
|
+
const flowIds = options.flowIds || [];
|
|
238
|
+
const agentIds = options.agentIds || [];
|
|
239
|
+
if (flowIds.length === 0 && agentIds.length === 0) {
|
|
240
|
+
console.error(chalk.red("Error: At least one --flow-ids or --agent-ids is required"));
|
|
241
|
+
process.exit(1);
|
|
242
|
+
}
|
|
243
|
+
if (flowIds.length > 0 && !options.defaultFlowId) {
|
|
244
|
+
console.error(chalk.red("Error: --default-flow-id is required when --flow-ids is provided"));
|
|
245
|
+
process.exit(1);
|
|
246
|
+
}
|
|
247
|
+
if (!["test", "live"].includes(options.environment)) {
|
|
248
|
+
console.error(chalk.red("Error: --environment must be \"test\" or \"live\""));
|
|
249
|
+
process.exit(1);
|
|
250
|
+
}
|
|
251
|
+
if (options.targetAlias && options.targetVersionId) {
|
|
252
|
+
console.error(chalk.red("Error: provide at most one of --target-alias or --target-version-id"));
|
|
253
|
+
process.exit(1);
|
|
254
|
+
}
|
|
255
|
+
const apiKey = await ensureAuth();
|
|
256
|
+
if (!apiKey) return;
|
|
257
|
+
const client = createCliClient(apiKey);
|
|
258
|
+
const body = {
|
|
259
|
+
name: options.name,
|
|
260
|
+
flowIds,
|
|
261
|
+
defaultFlowId: options.defaultFlowId,
|
|
262
|
+
agentIds,
|
|
263
|
+
...options.targetAlias ? { targetAlias: options.targetAlias } : {},
|
|
264
|
+
...options.targetVersionId ? { targetVersionId: options.targetVersionId } : {},
|
|
265
|
+
allowedOrigins: options.origins || ["*"],
|
|
266
|
+
environment: options.environment,
|
|
267
|
+
rateLimitPerMinute: parseInt(options.rateLimitPerMinute, 10),
|
|
268
|
+
rateLimitPerHour: parseInt(options.rateLimitPerHour, 10),
|
|
269
|
+
maxMessagesPerSession: parseInt(options.maxMessages, 10),
|
|
270
|
+
sessionIdleTimeoutMinutes: parseInt(options.sessionTimeout, 10)
|
|
271
|
+
};
|
|
272
|
+
if (!isTTY(options) || options.json) {
|
|
273
|
+
try {
|
|
274
|
+
const data = await client.post("/client-tokens", body);
|
|
275
|
+
if (options.json) printJson(data);
|
|
276
|
+
else {
|
|
277
|
+
const token = data.clientToken;
|
|
278
|
+
console.log(chalk.green("Client token created"));
|
|
279
|
+
console.log(` ID: ${chalk.green(token.id)}`);
|
|
280
|
+
console.log(` Name: ${token.name}`);
|
|
281
|
+
console.log(` Environment: ${token.environment}`);
|
|
282
|
+
console.log(` Token: ${chalk.yellow(data.token)}`);
|
|
283
|
+
if (data.warnings?.length > 0) {
|
|
284
|
+
console.log("");
|
|
285
|
+
for (const w of data.warnings) console.log(chalk.yellow(` ⚠ ${w.message}`));
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
} catch (error) {
|
|
289
|
+
const message = error instanceof Error ? error.message : "Unknown error";
|
|
290
|
+
console.error(chalk.red("Failed to create client token"));
|
|
291
|
+
console.error(chalk.red(message));
|
|
292
|
+
process.exit(1);
|
|
293
|
+
}
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
const App = () => {
|
|
297
|
+
const [loading, setLoading] = useState(true);
|
|
298
|
+
const [success, setSuccess] = useState(null);
|
|
299
|
+
const [error, setError] = useState(null);
|
|
300
|
+
const [resultNode, setResultNode] = useState(void 0);
|
|
301
|
+
useEffect(() => {
|
|
302
|
+
const run = async () => {
|
|
303
|
+
try {
|
|
304
|
+
const data = await client.post("/client-tokens", body);
|
|
305
|
+
const fields = [
|
|
306
|
+
{
|
|
307
|
+
label: "ID",
|
|
308
|
+
value: data.clientToken.id,
|
|
309
|
+
color: "green"
|
|
310
|
+
},
|
|
311
|
+
{
|
|
312
|
+
label: "Name",
|
|
313
|
+
value: data.clientToken.name
|
|
314
|
+
},
|
|
315
|
+
{
|
|
316
|
+
label: "Environment",
|
|
317
|
+
value: data.clientToken.environment
|
|
318
|
+
},
|
|
319
|
+
{
|
|
320
|
+
label: "Token",
|
|
321
|
+
value: data.token,
|
|
322
|
+
color: "yellow"
|
|
323
|
+
}
|
|
324
|
+
];
|
|
325
|
+
if (data.warnings?.length > 0) for (const w of data.warnings) fields.push({
|
|
326
|
+
label: "Warning",
|
|
327
|
+
value: w.message,
|
|
328
|
+
color: "yellow"
|
|
329
|
+
});
|
|
330
|
+
setResultNode(React.createElement(EntityCard, { fields }));
|
|
331
|
+
setSuccess(true);
|
|
332
|
+
setLoading(false);
|
|
333
|
+
} catch (err) {
|
|
334
|
+
setError(err instanceof Error ? err : new Error(String(err)));
|
|
335
|
+
setSuccess(false);
|
|
336
|
+
setLoading(false);
|
|
337
|
+
}
|
|
338
|
+
};
|
|
339
|
+
run();
|
|
340
|
+
}, []);
|
|
341
|
+
return React.createElement(MutationResult, {
|
|
342
|
+
loading,
|
|
343
|
+
loadingLabel: "Creating client token...",
|
|
344
|
+
success,
|
|
345
|
+
successMessage: "Client token created",
|
|
346
|
+
error,
|
|
347
|
+
result: resultNode
|
|
348
|
+
});
|
|
349
|
+
};
|
|
350
|
+
const { waitUntilExit } = render(React.createElement(App));
|
|
351
|
+
await waitUntilExit();
|
|
352
|
+
});
|
|
353
|
+
clientTokensCommand.command("delete <id>").description("Delete a client token").option("--tty", "Force TTY mode").option("--no-tty", "Force non-TTY mode").option("--yes", "Skip confirmation").action(async (id, options) => {
|
|
354
|
+
const apiKey = await ensureAuth();
|
|
355
|
+
if (!apiKey) return;
|
|
356
|
+
const client = createCliClient(apiKey);
|
|
357
|
+
if (!isTTY(options)) {
|
|
358
|
+
try {
|
|
359
|
+
await client.clientTokens.delete(id);
|
|
360
|
+
console.log(chalk.green("Client token deleted"));
|
|
361
|
+
} catch (error) {
|
|
362
|
+
const message = error instanceof Error ? error.message : "Unknown error";
|
|
363
|
+
console.error(chalk.red("Failed to delete client token"));
|
|
364
|
+
console.error(chalk.red(message));
|
|
365
|
+
process.exit(1);
|
|
366
|
+
}
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
if (options.yes) {
|
|
370
|
+
const App = () => {
|
|
371
|
+
const [loading, setLoading] = useState(true);
|
|
372
|
+
const [success, setSuccess] = useState(null);
|
|
373
|
+
const [error, setError] = useState(null);
|
|
374
|
+
useEffect(() => {
|
|
375
|
+
const run = async () => {
|
|
376
|
+
try {
|
|
377
|
+
await client.clientTokens.delete(id);
|
|
378
|
+
setSuccess(true);
|
|
379
|
+
setLoading(false);
|
|
380
|
+
} catch (err) {
|
|
381
|
+
setError(err instanceof Error ? err : new Error(String(err)));
|
|
382
|
+
setSuccess(false);
|
|
383
|
+
setLoading(false);
|
|
384
|
+
}
|
|
385
|
+
};
|
|
386
|
+
run();
|
|
387
|
+
}, []);
|
|
388
|
+
return React.createElement(MutationResult, {
|
|
389
|
+
loading,
|
|
390
|
+
loadingLabel: "Deleting client token...",
|
|
391
|
+
success,
|
|
392
|
+
successMessage: "Client token deleted",
|
|
393
|
+
error
|
|
394
|
+
});
|
|
395
|
+
};
|
|
396
|
+
const { waitUntilExit } = render(React.createElement(App));
|
|
397
|
+
await waitUntilExit();
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
400
|
+
if (!await new Promise((resolve) => {
|
|
401
|
+
const { unmount } = render(React.createElement(ConfirmPrompt, {
|
|
402
|
+
message: `Delete client token ${id}?`,
|
|
403
|
+
defaultValue: false,
|
|
404
|
+
onConfirm: (result) => {
|
|
405
|
+
resolve(result);
|
|
406
|
+
unmount();
|
|
407
|
+
}
|
|
408
|
+
}));
|
|
409
|
+
})) return;
|
|
410
|
+
const DeleteApp = () => {
|
|
411
|
+
const [loading, setLoading] = useState(true);
|
|
412
|
+
const [success, setSuccess] = useState(null);
|
|
413
|
+
const [error, setError] = useState(null);
|
|
414
|
+
useEffect(() => {
|
|
415
|
+
const run = async () => {
|
|
416
|
+
try {
|
|
417
|
+
await client.clientTokens.delete(id);
|
|
418
|
+
setSuccess(true);
|
|
419
|
+
setLoading(false);
|
|
420
|
+
} catch (err) {
|
|
421
|
+
setError(err instanceof Error ? err : new Error(String(err)));
|
|
422
|
+
setSuccess(false);
|
|
423
|
+
setLoading(false);
|
|
424
|
+
}
|
|
425
|
+
};
|
|
426
|
+
run();
|
|
427
|
+
}, []);
|
|
428
|
+
return React.createElement(MutationResult, {
|
|
429
|
+
loading,
|
|
430
|
+
loadingLabel: "Deleting client token...",
|
|
431
|
+
success,
|
|
432
|
+
successMessage: "Client token deleted",
|
|
433
|
+
error
|
|
434
|
+
});
|
|
435
|
+
};
|
|
436
|
+
const { waitUntilExit } = render(React.createElement(DeleteApp));
|
|
437
|
+
await waitUntilExit();
|
|
438
|
+
});
|
|
439
|
+
clientTokensCommand.command("regenerate <id>").description("Regenerate a client token (invalidates the old token)").option("--json", "Output as JSON").option("--tty", "Force TTY mode").option("--no-tty", "Force non-TTY mode").action(async (id, options) => {
|
|
440
|
+
const apiKey = await ensureAuth();
|
|
441
|
+
if (!apiKey) return;
|
|
442
|
+
const client = createCliClient(apiKey);
|
|
443
|
+
if (!isTTY(options) || options.json) {
|
|
444
|
+
try {
|
|
445
|
+
const data = await client.post(`/client-tokens/${id}/regenerate`);
|
|
446
|
+
if (options.json) printJson(data);
|
|
447
|
+
else {
|
|
448
|
+
console.log(chalk.green("Client token regenerated"));
|
|
449
|
+
console.log(` New Token: ${chalk.yellow(data.token)}`);
|
|
450
|
+
console.log(chalk.gray(" Previous token is now invalid. Update your client-side code."));
|
|
451
|
+
}
|
|
452
|
+
} catch (error) {
|
|
453
|
+
const message = error instanceof Error ? error.message : "Unknown error";
|
|
454
|
+
console.error(chalk.red("Failed to regenerate client token"));
|
|
455
|
+
console.error(chalk.red(message));
|
|
456
|
+
process.exit(1);
|
|
457
|
+
}
|
|
458
|
+
return;
|
|
459
|
+
}
|
|
460
|
+
const App = () => {
|
|
461
|
+
const [loading, setLoading] = useState(true);
|
|
462
|
+
const [success, setSuccess] = useState(null);
|
|
463
|
+
const [error, setError] = useState(null);
|
|
464
|
+
const [resultNode, setResultNode] = useState(void 0);
|
|
465
|
+
useEffect(() => {
|
|
466
|
+
const run = async () => {
|
|
467
|
+
try {
|
|
468
|
+
const data = await client.post(`/client-tokens/${id}/regenerate`);
|
|
469
|
+
setResultNode(React.createElement(EntityCard, { fields: [{
|
|
470
|
+
label: "New Token",
|
|
471
|
+
value: data.token,
|
|
472
|
+
color: "yellow"
|
|
473
|
+
}, {
|
|
474
|
+
label: "Note",
|
|
475
|
+
value: "Previous token is now invalid. Update your client-side code."
|
|
476
|
+
}] }));
|
|
477
|
+
setSuccess(true);
|
|
478
|
+
setLoading(false);
|
|
479
|
+
} catch (err) {
|
|
480
|
+
setError(err instanceof Error ? err : new Error(String(err)));
|
|
481
|
+
setSuccess(false);
|
|
482
|
+
setLoading(false);
|
|
483
|
+
}
|
|
484
|
+
};
|
|
485
|
+
run();
|
|
486
|
+
}, []);
|
|
487
|
+
return React.createElement(MutationResult, {
|
|
488
|
+
loading,
|
|
489
|
+
loadingLabel: "Regenerating client token...",
|
|
490
|
+
success,
|
|
491
|
+
successMessage: "Client token regenerated",
|
|
492
|
+
error,
|
|
493
|
+
result: resultNode
|
|
494
|
+
});
|
|
495
|
+
};
|
|
496
|
+
const { waitUntilExit } = render(React.createElement(App));
|
|
497
|
+
await waitUntilExit();
|
|
498
|
+
});
|
|
499
|
+
clientTokensCommand.addCommand(clientTokenEnsureCommand);
|
|
500
|
+
export { clientTokensCommand };
|
|
501
|
+
|