devflare 1.0.0-next.18 → 1.0.0-next.19
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/account-d43d1eqs.js +475 -0
- package/dist/cli/index.js +1 -1
- package/dist/cloudflare/index.js +2 -2
- package/dist/cloudflare/tokens.d.ts.map +1 -1
- package/dist/index-7r7dfpcm.js +133 -0
- package/dist/index-k7m5f1dg.js +200 -0
- package/dist/index-vt803j3b.js +1372 -0
- package/dist/index.js +1 -1
- package/dist/login-7yex6ppq.js +77 -0
- package/dist/previews-6fepv94a.js +1225 -0
- package/dist/productions-2t9q8f57.js +505 -0
- package/dist/token-a2b38w0z.js +419 -0
- package/dist/worker-99tew196.js +513 -0
- package/dist/worker-entry/composed-worker.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,419 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createAccountOwnedAPIToken,
|
|
3
|
+
deleteAccountOwnedAPIToken,
|
|
4
|
+
filterDevflareManagedTokens,
|
|
5
|
+
listAccountOwnedAPITokens,
|
|
6
|
+
listAccountTokenPermissionGroups,
|
|
7
|
+
normalizeDevflareTokenName,
|
|
8
|
+
rollAccountOwnedAPITokenValue,
|
|
9
|
+
selectAllReusablePermissionGroups,
|
|
10
|
+
selectDevflarePermissionGroups,
|
|
11
|
+
stripDevflareTokenNamePrefix
|
|
12
|
+
} from "./index-k7m5f1dg.js";
|
|
13
|
+
import {
|
|
14
|
+
createCliTheme,
|
|
15
|
+
dim,
|
|
16
|
+
green,
|
|
17
|
+
logLine,
|
|
18
|
+
logTable,
|
|
19
|
+
whiteDim,
|
|
20
|
+
yellow
|
|
21
|
+
} from "./index-stgn34cr.js";
|
|
22
|
+
import"./index-3t6rypgc.js";
|
|
23
|
+
import {
|
|
24
|
+
getPrimaryAccount,
|
|
25
|
+
getWorkspaceAccountId
|
|
26
|
+
} from "./index-1d4jg11n.js";
|
|
27
|
+
import {
|
|
28
|
+
AuthenticationError,
|
|
29
|
+
CloudflareAPIError
|
|
30
|
+
} from "./index-mg8vwqxf.js";
|
|
31
|
+
import"./index-37x76zdn.js";
|
|
32
|
+
|
|
33
|
+
// src/cli/commands/token.ts
|
|
34
|
+
var CLI_API_OPTIONS = { timeout: 1e4 };
|
|
35
|
+
var TOKENS_USAGE = "devflare tokens <bootstrap-token> (--list | --new [token-name] | --roll [token-name] | --delete [token-name] | --delete-all) [--account <id>] [--all-flags]";
|
|
36
|
+
var TOKEN_OPERATION_SUMMARY_LINES = [
|
|
37
|
+
"--list List Devflare-managed account-owned tokens",
|
|
38
|
+
"--new [name] Create a Devflare-managed account-owned token",
|
|
39
|
+
"--roll [name] Roll a Devflare-managed account-owned token secret",
|
|
40
|
+
"--delete [name] Delete a Devflare-managed account-owned token",
|
|
41
|
+
"--delete-all Delete every Devflare-managed account-owned token",
|
|
42
|
+
"--all-flags With --new, include every reusable account-scoped permission group"
|
|
43
|
+
];
|
|
44
|
+
function getTrimmedStringOption(options, key) {
|
|
45
|
+
const value = options[key];
|
|
46
|
+
if (typeof value !== "string") {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const trimmedValue = value.trim();
|
|
50
|
+
return trimmedValue || undefined;
|
|
51
|
+
}
|
|
52
|
+
function formatTokenTimestamp(value) {
|
|
53
|
+
if (!value) {
|
|
54
|
+
return "—";
|
|
55
|
+
}
|
|
56
|
+
return value.toISOString().replace(/:\d{2}\.\d{3}Z$/, "Z").replace("T", " ");
|
|
57
|
+
}
|
|
58
|
+
function sortTokens(tokens) {
|
|
59
|
+
return [...tokens].sort((left, right) => {
|
|
60
|
+
const nameComparison = left.name.localeCompare(right.name);
|
|
61
|
+
if (nameComparison !== 0) {
|
|
62
|
+
return nameComparison;
|
|
63
|
+
}
|
|
64
|
+
return (right.modifiedOn?.getTime() ?? 0) - (left.modifiedOn?.getTime() ?? 0);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
function logUsage(logger, theme) {
|
|
68
|
+
logLine(logger);
|
|
69
|
+
logLine(logger, `${dim("Usage:", theme)} ${TOKENS_USAGE}`);
|
|
70
|
+
logLine(logger, dim("Operations:", theme));
|
|
71
|
+
for (const line of TOKEN_OPERATION_SUMMARY_LINES) {
|
|
72
|
+
logLine(logger, ` ${line}`);
|
|
73
|
+
}
|
|
74
|
+
logLine(logger, dim("Token names are normalized to the devflare- prefix automatically.", theme));
|
|
75
|
+
logLine(logger, dim("The bootstrap token must include Cloudflare API token management permissions.", theme));
|
|
76
|
+
logLine(logger);
|
|
77
|
+
}
|
|
78
|
+
function resolveTokenOperation(parsed) {
|
|
79
|
+
const newOption = parsed.options.new;
|
|
80
|
+
const rollOption = parsed.options.roll;
|
|
81
|
+
const deleteOption = parsed.options.delete;
|
|
82
|
+
const requestedOperations = [
|
|
83
|
+
newOption !== undefined ? "new" : null,
|
|
84
|
+
rollOption !== undefined ? "roll" : null,
|
|
85
|
+
deleteOption !== undefined ? "delete" : null,
|
|
86
|
+
parsed.options.list === true ? "list" : null,
|
|
87
|
+
parsed.options["delete-all"] === true ? "delete-all" : null
|
|
88
|
+
].filter(Boolean);
|
|
89
|
+
if (parsed.options["all-flags"] && !requestedOperations.includes("new")) {
|
|
90
|
+
return "--all-flags can only be used together with --new.";
|
|
91
|
+
}
|
|
92
|
+
if (requestedOperations.length === 0) {
|
|
93
|
+
return "Choose one token operation: --list, --new, --roll, --delete, or --delete-all.";
|
|
94
|
+
}
|
|
95
|
+
if (requestedOperations.length > 1) {
|
|
96
|
+
return "Choose only one token operation at a time.";
|
|
97
|
+
}
|
|
98
|
+
switch (requestedOperations[0]) {
|
|
99
|
+
case "new":
|
|
100
|
+
return {
|
|
101
|
+
kind: "new",
|
|
102
|
+
requestedName: typeof newOption === "string" ? newOption.trim() || undefined : undefined
|
|
103
|
+
};
|
|
104
|
+
case "roll":
|
|
105
|
+
return {
|
|
106
|
+
kind: "roll",
|
|
107
|
+
requestedName: typeof rollOption === "string" ? rollOption.trim() || undefined : undefined
|
|
108
|
+
};
|
|
109
|
+
case "delete":
|
|
110
|
+
return {
|
|
111
|
+
kind: "delete",
|
|
112
|
+
requestedName: typeof deleteOption === "string" ? deleteOption.trim() || undefined : undefined
|
|
113
|
+
};
|
|
114
|
+
case "list":
|
|
115
|
+
return { kind: "list" };
|
|
116
|
+
case "delete-all":
|
|
117
|
+
return { kind: "delete-all" };
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
function formatManagedTokenDisplayName(name) {
|
|
121
|
+
return stripDevflareTokenNamePrefix(name);
|
|
122
|
+
}
|
|
123
|
+
async function promptForTokenName(logger, theme, message) {
|
|
124
|
+
while (true) {
|
|
125
|
+
const selected = await logger.prompt(message, {
|
|
126
|
+
type: "text",
|
|
127
|
+
placeholder: "preview",
|
|
128
|
+
cancel: "symbol"
|
|
129
|
+
});
|
|
130
|
+
if (typeof selected === "symbol") {
|
|
131
|
+
logLine(logger, dim("Cancelled", theme));
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
const trimmedValue = selected.trim();
|
|
135
|
+
if (trimmedValue) {
|
|
136
|
+
return trimmedValue;
|
|
137
|
+
}
|
|
138
|
+
logger.error("Token name is required.");
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
async function resolveTokenName(requestedName, logger, theme, promptMessage) {
|
|
142
|
+
const rawName = requestedName ?? await promptForTokenName(logger, theme, promptMessage);
|
|
143
|
+
if (!rawName) {
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
return normalizeDevflareTokenName(rawName);
|
|
147
|
+
}
|
|
148
|
+
async function resolveNamedManagedTokens(accountId, accountSource, bootstrapToken, requestedName, logger, theme, options) {
|
|
149
|
+
const tokenName = await resolveTokenName(requestedName, logger, theme, options.promptMessage);
|
|
150
|
+
if (!tokenName) {
|
|
151
|
+
return { exitCode: 0 };
|
|
152
|
+
}
|
|
153
|
+
logLine(logger);
|
|
154
|
+
logLine(logger, `${yellow("tokens", theme)} ${dim(`${options.actionLabel} a Devflare-managed account-owned token…`, theme)}`);
|
|
155
|
+
logLine(logger, `${dim("Account:", theme)} ${green(accountId, theme)} ${whiteDim(`(${accountSource})`, theme)}`);
|
|
156
|
+
logLine(logger, `${dim("Name:", theme)} ${green(tokenName, theme)}`);
|
|
157
|
+
const accountTokens = await listAccountOwnedAPITokens(accountId, {
|
|
158
|
+
...CLI_API_OPTIONS,
|
|
159
|
+
token: bootstrapToken
|
|
160
|
+
});
|
|
161
|
+
const matchingTokens = filterDevflareManagedTokens(accountTokens).filter((token) => token.name === tokenName);
|
|
162
|
+
if (matchingTokens.length === 0) {
|
|
163
|
+
logger.error(`No Devflare-managed token named ${tokenName} was found.`);
|
|
164
|
+
return { exitCode: 1 };
|
|
165
|
+
}
|
|
166
|
+
if (matchingTokens.length > 1) {
|
|
167
|
+
logLine(logger, dim(`Found ${matchingTokens.length} tokens with that name. ${options.multipleMatchMessage}.`, theme));
|
|
168
|
+
}
|
|
169
|
+
return {
|
|
170
|
+
tokenName,
|
|
171
|
+
matchingTokens
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
async function resolveRequestedAccountId(requestedAccountId, bootstrapToken) {
|
|
175
|
+
if (requestedAccountId) {
|
|
176
|
+
return { accountId: requestedAccountId, source: "flag" };
|
|
177
|
+
}
|
|
178
|
+
const workspaceAccountId = getWorkspaceAccountId();
|
|
179
|
+
if (workspaceAccountId) {
|
|
180
|
+
return {
|
|
181
|
+
accountId: workspaceAccountId,
|
|
182
|
+
source: "workspace"
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
const primaryAccount = await getPrimaryAccount({
|
|
186
|
+
...CLI_API_OPTIONS,
|
|
187
|
+
token: bootstrapToken
|
|
188
|
+
});
|
|
189
|
+
if (!primaryAccount) {
|
|
190
|
+
throw new Error("No Cloudflare accounts found for this bootstrap token");
|
|
191
|
+
}
|
|
192
|
+
return {
|
|
193
|
+
accountId: primaryAccount.id,
|
|
194
|
+
source: "primary"
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
async function createManagedToken(accountId, accountSource, bootstrapToken, requestedName, includeAllFlags, logger, theme) {
|
|
198
|
+
const tokenName = await resolveTokenName(requestedName, logger, theme, "Enter a Devflare token name:");
|
|
199
|
+
if (!tokenName) {
|
|
200
|
+
return { exitCode: 0 };
|
|
201
|
+
}
|
|
202
|
+
logLine(logger);
|
|
203
|
+
logLine(logger, `${yellow("tokens", theme)} ${dim("Creating an account-owned Devflare token…", theme)}`);
|
|
204
|
+
logLine(logger, `${dim("Account:", theme)} ${green(accountId, theme)} ${whiteDim(`(${accountSource})`, theme)}`);
|
|
205
|
+
logLine(logger, `${dim("Name:", theme)} ${green(tokenName, theme)}`);
|
|
206
|
+
const permissionGroups = await listAccountTokenPermissionGroups(accountId, {
|
|
207
|
+
...CLI_API_OPTIONS,
|
|
208
|
+
token: bootstrapToken
|
|
209
|
+
});
|
|
210
|
+
if (permissionGroups.length === 0) {
|
|
211
|
+
logger.error("Cloudflare returned zero account token permission groups for this account.");
|
|
212
|
+
return { exitCode: 1 };
|
|
213
|
+
}
|
|
214
|
+
const selectedPermissionGroups = includeAllFlags ? selectAllReusablePermissionGroups(permissionGroups) : selectDevflarePermissionGroups(permissionGroups);
|
|
215
|
+
const createdToken = await createAccountOwnedAPIToken(accountId, {
|
|
216
|
+
name: tokenName,
|
|
217
|
+
permissionGroupIds: selectedPermissionGroups.map((group) => group.id)
|
|
218
|
+
}, {
|
|
219
|
+
...CLI_API_OPTIONS,
|
|
220
|
+
token: bootstrapToken
|
|
221
|
+
});
|
|
222
|
+
if (!createdToken.value) {
|
|
223
|
+
logger.error("Cloudflare created the token but did not return a token value.");
|
|
224
|
+
return { exitCode: 1 };
|
|
225
|
+
}
|
|
226
|
+
logger.success(`Created ${createdToken.name || tokenName}`);
|
|
227
|
+
logLine(logger, `${dim("Permission groups:", theme)} ${selectedPermissionGroups.length} ${includeAllFlags ? "reusable account-scoped" : "Devflare-relevant account-scoped"} selected from ${permissionGroups.length} available`);
|
|
228
|
+
if (includeAllFlags) {
|
|
229
|
+
logLine(logger, dim("Account-owned tokens only accept account-scoped permission groups, so zone/user-scoped groups are skipped automatically.", theme));
|
|
230
|
+
logLine(logger, dim("Account API Tokens permissions are still excluded because Cloudflare does not allow sub-tokens to manage other tokens.", theme));
|
|
231
|
+
}
|
|
232
|
+
logger.warn("Cloudflare only returns the token secret once. Store it safely now.");
|
|
233
|
+
logger.log(createdToken.value);
|
|
234
|
+
return {
|
|
235
|
+
exitCode: 0,
|
|
236
|
+
output: createdToken.value
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
async function listManagedTokens(accountId, accountSource, bootstrapToken, logger, theme) {
|
|
240
|
+
logLine(logger);
|
|
241
|
+
logLine(logger, `${yellow("tokens", theme)} ${dim("Listing Devflare-managed account-owned tokens…", theme)}`);
|
|
242
|
+
logLine(logger, `${dim("Account:", theme)} ${green(accountId, theme)} ${whiteDim(`(${accountSource})`, theme)}`);
|
|
243
|
+
const accountTokens = await listAccountOwnedAPITokens(accountId, {
|
|
244
|
+
...CLI_API_OPTIONS,
|
|
245
|
+
token: bootstrapToken
|
|
246
|
+
});
|
|
247
|
+
const managedTokens = sortTokens(filterDevflareManagedTokens(accountTokens));
|
|
248
|
+
if (managedTokens.length === 0) {
|
|
249
|
+
logLine(logger, dim("No Devflare-managed account-owned tokens found for this account.", theme));
|
|
250
|
+
return { exitCode: 0, output: "" };
|
|
251
|
+
}
|
|
252
|
+
logTable(logger, {
|
|
253
|
+
title: "Devflare-managed tokens",
|
|
254
|
+
rows: managedTokens,
|
|
255
|
+
columns: [
|
|
256
|
+
{
|
|
257
|
+
label: "Name",
|
|
258
|
+
value: (token) => formatManagedTokenDisplayName(token.name),
|
|
259
|
+
width: 46
|
|
260
|
+
},
|
|
261
|
+
{
|
|
262
|
+
label: "Status",
|
|
263
|
+
value: (token) => token.status ?? "unknown",
|
|
264
|
+
width: 10
|
|
265
|
+
},
|
|
266
|
+
{
|
|
267
|
+
label: "Token ID",
|
|
268
|
+
value: (token) => token.id.slice(0, 12),
|
|
269
|
+
width: 12
|
|
270
|
+
},
|
|
271
|
+
{
|
|
272
|
+
label: "Modified",
|
|
273
|
+
value: (token) => formatTokenTimestamp(token.modifiedOn)
|
|
274
|
+
}
|
|
275
|
+
],
|
|
276
|
+
theme
|
|
277
|
+
});
|
|
278
|
+
const untouchedTokenCount = accountTokens.length - managedTokens.length;
|
|
279
|
+
if (untouchedTokenCount > 0) {
|
|
280
|
+
logLine(logger, dim(`Left ${untouchedTokenCount} non-Devflare token(s) out of this list.`, theme));
|
|
281
|
+
}
|
|
282
|
+
return {
|
|
283
|
+
exitCode: 0,
|
|
284
|
+
output: managedTokens.map((token) => formatManagedTokenDisplayName(token.name)).join(`
|
|
285
|
+
`)
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
async function rollManagedTokensByName(accountId, accountSource, bootstrapToken, requestedName, logger, theme) {
|
|
289
|
+
const selectedTokens = await resolveNamedManagedTokens(accountId, accountSource, bootstrapToken, requestedName, logger, theme, {
|
|
290
|
+
promptMessage: "Enter the Devflare token name to roll:",
|
|
291
|
+
actionLabel: "Rolling",
|
|
292
|
+
multipleMatchMessage: "Rolling all exact matches"
|
|
293
|
+
});
|
|
294
|
+
if ("exitCode" in selectedTokens) {
|
|
295
|
+
return selectedTokens;
|
|
296
|
+
}
|
|
297
|
+
const { tokenName, matchingTokens } = selectedTokens;
|
|
298
|
+
const rolledValues = [];
|
|
299
|
+
for (const token of matchingTokens) {
|
|
300
|
+
const rolledValue = await rollAccountOwnedAPITokenValue(accountId, token.id, {
|
|
301
|
+
...CLI_API_OPTIONS,
|
|
302
|
+
token: bootstrapToken
|
|
303
|
+
});
|
|
304
|
+
rolledValues.push(rolledValue);
|
|
305
|
+
}
|
|
306
|
+
logger.success(`Rolled ${matchingTokens.length} Devflare-managed token(s) named ${tokenName}`);
|
|
307
|
+
logger.warn("Cloudflare only returns the new token secret once. Store it safely now.");
|
|
308
|
+
if (rolledValues.length === 1) {
|
|
309
|
+
logger.log(rolledValues[0]);
|
|
310
|
+
} else {
|
|
311
|
+
for (const [index, value] of rolledValues.entries()) {
|
|
312
|
+
logLine(logger, `${dim(`${matchingTokens[index].id.slice(0, 12)}:`, theme)} ${value}`);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
return {
|
|
316
|
+
exitCode: 0,
|
|
317
|
+
output: rolledValues.join(`
|
|
318
|
+
`)
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
async function deleteManagedTokensByName(accountId, accountSource, bootstrapToken, requestedName, logger, theme) {
|
|
322
|
+
const selectedTokens = await resolveNamedManagedTokens(accountId, accountSource, bootstrapToken, requestedName, logger, theme, {
|
|
323
|
+
promptMessage: "Enter the Devflare token name to delete:",
|
|
324
|
+
actionLabel: "Deleting",
|
|
325
|
+
multipleMatchMessage: "Deleting all exact matches"
|
|
326
|
+
});
|
|
327
|
+
if ("exitCode" in selectedTokens) {
|
|
328
|
+
return selectedTokens;
|
|
329
|
+
}
|
|
330
|
+
const { tokenName, matchingTokens } = selectedTokens;
|
|
331
|
+
for (const token of matchingTokens) {
|
|
332
|
+
await deleteAccountOwnedAPIToken(accountId, token.id, {
|
|
333
|
+
...CLI_API_OPTIONS,
|
|
334
|
+
token: bootstrapToken
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
logger.success(`Deleted ${matchingTokens.length} Devflare-managed token(s) named ${tokenName}`);
|
|
338
|
+
return {
|
|
339
|
+
exitCode: 0,
|
|
340
|
+
output: matchingTokens.map((token) => token.id).join(`
|
|
341
|
+
`)
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
async function deleteAllManagedTokens(accountId, accountSource, bootstrapToken, logger, theme) {
|
|
345
|
+
logLine(logger);
|
|
346
|
+
logLine(logger, `${yellow("tokens", theme)} ${dim("Deleting all Devflare-managed account-owned tokens…", theme)}`);
|
|
347
|
+
logLine(logger, `${dim("Account:", theme)} ${green(accountId, theme)} ${whiteDim(`(${accountSource})`, theme)}`);
|
|
348
|
+
const accountTokens = await listAccountOwnedAPITokens(accountId, {
|
|
349
|
+
...CLI_API_OPTIONS,
|
|
350
|
+
token: bootstrapToken
|
|
351
|
+
});
|
|
352
|
+
const managedTokens = filterDevflareManagedTokens(accountTokens);
|
|
353
|
+
if (managedTokens.length === 0) {
|
|
354
|
+
logger.success("No Devflare-managed tokens were found, so nothing was deleted.");
|
|
355
|
+
return { exitCode: 0 };
|
|
356
|
+
}
|
|
357
|
+
for (const token of managedTokens) {
|
|
358
|
+
await deleteAccountOwnedAPIToken(accountId, token.id, {
|
|
359
|
+
...CLI_API_OPTIONS,
|
|
360
|
+
token: bootstrapToken
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
logger.success(`Deleted ${managedTokens.length} Devflare-managed token(s)`);
|
|
364
|
+
const untouchedTokenCount = accountTokens.length - managedTokens.length;
|
|
365
|
+
if (untouchedTokenCount > 0) {
|
|
366
|
+
logLine(logger, dim(`Left ${untouchedTokenCount} non-Devflare token(s) untouched.`, theme));
|
|
367
|
+
}
|
|
368
|
+
return {
|
|
369
|
+
exitCode: 0,
|
|
370
|
+
output: managedTokens.map((token) => token.id).join(`
|
|
371
|
+
`)
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
async function runTokenCommand(parsed, logger, _options) {
|
|
375
|
+
const bootstrapToken = parsed.args[0]?.trim();
|
|
376
|
+
const theme = createCliTheme(parsed.options);
|
|
377
|
+
if (!bootstrapToken) {
|
|
378
|
+
logUsage(logger, theme);
|
|
379
|
+
return { exitCode: 1 };
|
|
380
|
+
}
|
|
381
|
+
const tokenOperation = resolveTokenOperation(parsed);
|
|
382
|
+
if (typeof tokenOperation === "string") {
|
|
383
|
+
logUsage(logger, theme);
|
|
384
|
+
return { exitCode: 1 };
|
|
385
|
+
}
|
|
386
|
+
const requestedAccountId = getTrimmedStringOption(parsed.options, "account");
|
|
387
|
+
try {
|
|
388
|
+
const { accountId, source } = await resolveRequestedAccountId(requestedAccountId, bootstrapToken);
|
|
389
|
+
switch (tokenOperation.kind) {
|
|
390
|
+
case "new":
|
|
391
|
+
return createManagedToken(accountId, source, bootstrapToken, tokenOperation.requestedName, parsed.options["all-flags"] === true, logger, theme);
|
|
392
|
+
case "roll":
|
|
393
|
+
return rollManagedTokensByName(accountId, source, bootstrapToken, tokenOperation.requestedName, logger, theme);
|
|
394
|
+
case "list":
|
|
395
|
+
return listManagedTokens(accountId, source, bootstrapToken, logger, theme);
|
|
396
|
+
case "delete":
|
|
397
|
+
return deleteManagedTokensByName(accountId, source, bootstrapToken, tokenOperation.requestedName, logger, theme);
|
|
398
|
+
case "delete-all":
|
|
399
|
+
return deleteAllManagedTokens(accountId, source, bootstrapToken, logger, theme);
|
|
400
|
+
}
|
|
401
|
+
} catch (error) {
|
|
402
|
+
if (error instanceof AuthenticationError) {
|
|
403
|
+
logger.error(error.message);
|
|
404
|
+
return { exitCode: 1 };
|
|
405
|
+
}
|
|
406
|
+
if (error instanceof CloudflareAPIError) {
|
|
407
|
+
logger.error(`API Error: ${error.message}`);
|
|
408
|
+
return { exitCode: 1 };
|
|
409
|
+
}
|
|
410
|
+
if (error instanceof Error) {
|
|
411
|
+
logger.error(error.message);
|
|
412
|
+
return { exitCode: 1 };
|
|
413
|
+
}
|
|
414
|
+
throw error;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
export {
|
|
418
|
+
runTokenCommand
|
|
419
|
+
};
|