@rockcarver/frodo-cli 5.0.0-6 → 5.0.0-8
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/CHANGELOG.md +30 -0
- package/dist/AuthoringPrintState-vyWOD1Wt.cjs +124 -0
- package/dist/AuthoringPrintState-vyWOD1Wt.cjs.map +1 -0
- package/dist/Console-1LBCP_JZ.cjs +177069 -0
- package/dist/Console-1LBCP_JZ.cjs.map +1 -0
- package/dist/DefaultsStore-RlEkAWqT.cjs +155 -0
- package/dist/DefaultsStore-RlEkAWqT.cjs.map +1 -0
- package/dist/EntityPickers-BGrRn1Yq.cjs +145 -0
- package/dist/EntityPickers-BGrRn1Yq.cjs.map +1 -0
- package/dist/EscapableSelectPrompt-BljVxNDm.cjs +2356 -0
- package/dist/EscapableSelectPrompt-BljVxNDm.cjs.map +1 -0
- package/dist/FrodoCommand-DueD-n-I.cjs +15474 -0
- package/dist/FrodoCommand-DueD-n-I.cjs.map +1 -0
- package/dist/RealmOps-Buhw-nZ1.cjs +340 -0
- package/dist/RealmOps-Buhw-nZ1.cjs.map +1 -0
- package/dist/RealmPickers-IjVJiRB5.cjs +137 -0
- package/dist/RealmPickers-IjVJiRB5.cjs.map +1 -0
- package/dist/ResolveInteractiveInputs-D_-5704M.cjs +1856 -0
- package/dist/ResolveInteractiveInputs-D_-5704M.cjs.map +1 -0
- package/dist/app.cjs +1147 -1148
- package/dist/app.cjs.map +1 -1
- package/package.json +3 -8
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
const require_rolldown_runtime = require("./rolldown-runtime-Ctb5zv51.cjs");
|
|
2
|
+
const require_Console = require("./Console-1LBCP_JZ.cjs");
|
|
3
|
+
let fs = require("fs");
|
|
4
|
+
fs = require_rolldown_runtime.__toESM(fs, 1);
|
|
5
|
+
//#region src/ops/RealmOps.ts
|
|
6
|
+
var RealmOps_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({
|
|
7
|
+
addCustomDomain: () => addCustomDomain,
|
|
8
|
+
describeRealm: () => describeRealm,
|
|
9
|
+
exportRealmById: () => exportRealmById,
|
|
10
|
+
exportRealmByName: () => exportRealmByName,
|
|
11
|
+
exportRealmsToFile: () => exportRealmsToFile,
|
|
12
|
+
exportRealmsToFiles: () => exportRealmsToFiles,
|
|
13
|
+
importRealmFromFile: () => importRealmFromFile,
|
|
14
|
+
importRealmsFromFile: () => importRealmsFromFile,
|
|
15
|
+
importRealmsFromFiles: () => importRealmsFromFiles,
|
|
16
|
+
listRealms: () => listRealms,
|
|
17
|
+
readRealmsCached: () => readRealmsCached
|
|
18
|
+
});
|
|
19
|
+
const { readRealm, readRealms, readRealmByName, exportRealms, importRealms, updateRealm } = require_Console.frodo.realm;
|
|
20
|
+
const { getTypedFilename, saveToFile, saveJsonToFile, getFilePath, getWorkingDirectory } = require_Console.frodo.utils;
|
|
21
|
+
/**
|
|
22
|
+
* Per-invocation cache of the realm list. The realm picker reads
|
|
23
|
+
* realms right after auth, and commands like `frodo realm list` read them
|
|
24
|
+
* again moments later -- two HTTP calls to the same endpoint that would
|
|
25
|
+
* (a) double the latency and (b) break Polly's order-matched replay in e2e
|
|
26
|
+
* recordings, which have one entry for the endpoint. Sharing one memoized
|
|
27
|
+
* read keeps both callers on a single fetch.
|
|
28
|
+
*/
|
|
29
|
+
let realmsCache;
|
|
30
|
+
/**
|
|
31
|
+
* Reads all realms, memoized for the remainder of this invocation. Callers
|
|
32
|
+
* that need fresh data (import/export mutations) call frodo.realm
|
|
33
|
+
* .readRealms directly.
|
|
34
|
+
*/
|
|
35
|
+
async function readRealmsCached() {
|
|
36
|
+
if (!realmsCache) realmsCache = await readRealms();
|
|
37
|
+
return realmsCache;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* List realms
|
|
41
|
+
* @param {boolean} long Long list format with details
|
|
42
|
+
*/
|
|
43
|
+
async function listRealms(long = false) {
|
|
44
|
+
try {
|
|
45
|
+
const realms = await readRealmsCached();
|
|
46
|
+
if (long) {
|
|
47
|
+
const table = require_Console.createTable([
|
|
48
|
+
require_Console.theme.heading("Id"),
|
|
49
|
+
require_Console.theme.heading("Name"),
|
|
50
|
+
require_Console.theme.heading("Status"),
|
|
51
|
+
require_Console.theme.heading("Custom Domains"),
|
|
52
|
+
require_Console.theme.heading("Parent Path")
|
|
53
|
+
]);
|
|
54
|
+
realms.forEach((realmConfig) => {
|
|
55
|
+
table.push([
|
|
56
|
+
realmConfig._id,
|
|
57
|
+
realmConfig.name,
|
|
58
|
+
realmConfig.active ? require_Console.theme.positive("active") : require_Console.theme.negative("inactive"),
|
|
59
|
+
realmConfig.aliases.join("\n"),
|
|
60
|
+
realmConfig.parentPath
|
|
61
|
+
]);
|
|
62
|
+
});
|
|
63
|
+
require_Console.printMessage(table.toString(), "data");
|
|
64
|
+
} else realms.forEach((realmConfig) => {
|
|
65
|
+
require_Console.printMessage((realmConfig.parentPath || "") + (realmConfig.parentPath && !realmConfig.parentPath.endsWith("/") ? "/" : "") + realmConfig.name, "data");
|
|
66
|
+
});
|
|
67
|
+
} catch (error) {
|
|
68
|
+
require_Console.printMessage(error, "error");
|
|
69
|
+
require_Console.printMessage(`Error listing realms: ${error.message}`, "error");
|
|
70
|
+
require_Console.printMessage(error.response?.data, "error");
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Export realm to file by id
|
|
75
|
+
* @param {string} realmId realm id
|
|
76
|
+
* @param {string} file file name
|
|
77
|
+
* @param {boolean} includeMeta true to include metadata, false otherwise. Default: true
|
|
78
|
+
* @returns {Promise<boolean>} true if successful, false otherwise
|
|
79
|
+
*/
|
|
80
|
+
async function exportRealmById(realmId, file, includeMeta = true) {
|
|
81
|
+
const indicatorId = require_Console.createProgressIndicator("determinate", 1, `Exporting ${realmId}...`);
|
|
82
|
+
try {
|
|
83
|
+
const realm = await readRealm(realmId);
|
|
84
|
+
let fileName = getTypedFilename(realmId, `realm`);
|
|
85
|
+
if (file) fileName = file;
|
|
86
|
+
require_Console.updateProgressIndicator(indicatorId, `Saving ${realmId} to ${fileName}...`);
|
|
87
|
+
saveToFile("realm", [realm], "_id", getFilePath(fileName, true), includeMeta);
|
|
88
|
+
require_Console.stopProgressIndicator(indicatorId, `Exported realm ${realmId} to file`, "success");
|
|
89
|
+
return true;
|
|
90
|
+
} catch (error) {
|
|
91
|
+
require_Console.stopProgressIndicator(indicatorId, `Error exporting realm ${realmId} to file`, "fail");
|
|
92
|
+
require_Console.printError(error);
|
|
93
|
+
}
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Export realm to file by name
|
|
98
|
+
* @param {string} realmName realm name
|
|
99
|
+
* @param {string} file file name
|
|
100
|
+
* @param {boolean} includeMeta true to include metadata, false otherwise. Default: true
|
|
101
|
+
* @returns {Promise<boolean>} true if successful, false otherwise
|
|
102
|
+
*/
|
|
103
|
+
async function exportRealmByName(realmName, file, includeMeta = true) {
|
|
104
|
+
const indicatorId = require_Console.createProgressIndicator("determinate", 1, `Exporting ${realmName}...`);
|
|
105
|
+
try {
|
|
106
|
+
const realm = await readRealmByName(realmName);
|
|
107
|
+
let fileName = getTypedFilename(!realmName || realmName === "/" ? "root" : realmName, `realm`);
|
|
108
|
+
if (file) fileName = file;
|
|
109
|
+
require_Console.updateProgressIndicator(indicatorId, `Saving ${realmName} to ${fileName}...`);
|
|
110
|
+
saveToFile("realm", [realm], "_id", getFilePath(fileName, true), includeMeta);
|
|
111
|
+
require_Console.stopProgressIndicator(indicatorId, `Exported realm ${realmName} to file`, "success");
|
|
112
|
+
return true;
|
|
113
|
+
} catch (error) {
|
|
114
|
+
require_Console.stopProgressIndicator(indicatorId, `Error exporting realm ${realmName} to file`, "fail");
|
|
115
|
+
require_Console.printError(error);
|
|
116
|
+
}
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Export all realms to file
|
|
121
|
+
* @param {string} file file name
|
|
122
|
+
* @param {boolean} includeMeta true to include metadata, false otherwise. Default: true
|
|
123
|
+
* @returns {Promise<boolean>} true if successful, false otherwise
|
|
124
|
+
*/
|
|
125
|
+
async function exportRealmsToFile(file, includeMeta = true) {
|
|
126
|
+
try {
|
|
127
|
+
const exportData = await exportRealms();
|
|
128
|
+
let fileName = getTypedFilename(`allRealms`, `realm`);
|
|
129
|
+
if (file) fileName = file;
|
|
130
|
+
saveJsonToFile(exportData, getFilePath(fileName, true), includeMeta);
|
|
131
|
+
return true;
|
|
132
|
+
} catch (error) {
|
|
133
|
+
require_Console.printError(error, `Error exporting realms to file`);
|
|
134
|
+
}
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Export all realms to separate files
|
|
139
|
+
* @param {boolean} includeMeta true to include metadata, false otherwise. Default: true
|
|
140
|
+
* @returns {Promise<boolean>} true if successful, false otherwise
|
|
141
|
+
*/
|
|
142
|
+
async function exportRealmsToFiles(includeMeta = true) {
|
|
143
|
+
try {
|
|
144
|
+
const realms = await readRealms();
|
|
145
|
+
for (const realm of realms) {
|
|
146
|
+
const fileName = getTypedFilename(!realm.name || realm.name === "/" ? "root" : realm.name, "realm");
|
|
147
|
+
saveToFile("realm", realm, "_id", getFilePath(fileName, true), includeMeta);
|
|
148
|
+
}
|
|
149
|
+
return true;
|
|
150
|
+
} catch (error) {
|
|
151
|
+
require_Console.printError(error, `Error exporting realms to files`);
|
|
152
|
+
}
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Import a realm from file. The first realm from the file will be imported if no id/name is provided.
|
|
157
|
+
* @param {string} realmId realm id
|
|
158
|
+
* @param {string} realmName realm name
|
|
159
|
+
* @param {string} file import file name
|
|
160
|
+
* @returns {Promise<boolean>} true if successful, false otherwise
|
|
161
|
+
*/
|
|
162
|
+
async function importRealmFromFile(realmId, realmName, file) {
|
|
163
|
+
const indicatorId = require_Console.createProgressIndicator("determinate", 1, "Importing realm...");
|
|
164
|
+
try {
|
|
165
|
+
const importData = JSON.parse(fs.default.readFileSync(getFilePath(file), "utf8"));
|
|
166
|
+
if (!realmId && !realmName) {
|
|
167
|
+
const firstRealm = Object.values(importData.realm)[0];
|
|
168
|
+
if (!firstRealm) {
|
|
169
|
+
require_Console.stopProgressIndicator(indicatorId, `No realms found!`, "fail");
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
realmName = firstRealm.name;
|
|
173
|
+
}
|
|
174
|
+
require_Console.updateProgressIndicator(indicatorId, `Importing realm ${realmName ? realmName : realmId}.`);
|
|
175
|
+
await importRealms(importData, realmId, realmName);
|
|
176
|
+
require_Console.stopProgressIndicator(indicatorId, `Successfully imported realm.`);
|
|
177
|
+
return true;
|
|
178
|
+
} catch (error) {
|
|
179
|
+
require_Console.stopProgressIndicator(indicatorId, `Error importing realm`, "fail");
|
|
180
|
+
require_Console.printError(error);
|
|
181
|
+
}
|
|
182
|
+
return false;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Import all realms from file
|
|
186
|
+
* @param {string} file import file name
|
|
187
|
+
* @returns {Promise<boolean>} true if successful, false otherwise
|
|
188
|
+
*/
|
|
189
|
+
async function importRealmsFromFile(file) {
|
|
190
|
+
try {
|
|
191
|
+
require_Console.debugMessage(`importRealmsFromFile: start`);
|
|
192
|
+
const filePath = getFilePath(file);
|
|
193
|
+
const data = fs.default.readFileSync(filePath, "utf8");
|
|
194
|
+
require_Console.debugMessage(`importRealmsFromFile: importing ${filePath}`);
|
|
195
|
+
const importData = JSON.parse(data);
|
|
196
|
+
await importRealms(importData);
|
|
197
|
+
require_Console.debugMessage(`importRealmsFromFile: end`);
|
|
198
|
+
return true;
|
|
199
|
+
} catch (error) {
|
|
200
|
+
require_Console.printError(error, `Error importing realms from file`);
|
|
201
|
+
}
|
|
202
|
+
return false;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Import all realms from separate files
|
|
206
|
+
* @returns {Promise<boolean>} true if successful, false otherwise
|
|
207
|
+
*/
|
|
208
|
+
async function importRealmsFromFiles() {
|
|
209
|
+
const errors = [];
|
|
210
|
+
try {
|
|
211
|
+
const realmFiles = fs.default.readdirSync(getWorkingDirectory()).filter((name) => name.toLowerCase().endsWith(".realm.json"));
|
|
212
|
+
for (const file of realmFiles) try {
|
|
213
|
+
await importRealmsFromFile(file);
|
|
214
|
+
} catch (error) {
|
|
215
|
+
errors.push(new require_Console.FrodoError(`Error importing realms from ${file}`, error));
|
|
216
|
+
}
|
|
217
|
+
if (errors.length > 0) throw new require_Console.FrodoError(`One or more errors importing realms`, errors);
|
|
218
|
+
return true;
|
|
219
|
+
} catch (error) {
|
|
220
|
+
if (errors.length > 0) require_Console.printError(error);
|
|
221
|
+
else require_Console.printError(error, `Error importing realms from files`);
|
|
222
|
+
}
|
|
223
|
+
return false;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Describe realm
|
|
227
|
+
* @param {String} realm realm name
|
|
228
|
+
*/
|
|
229
|
+
async function describeRealm(realm) {
|
|
230
|
+
try {
|
|
231
|
+
const realmConfig = await readRealmByName(realm);
|
|
232
|
+
const table = require_Console.createKeyValueTable();
|
|
233
|
+
table.push([require_Console.theme.heading("Name"), realmConfig.name]);
|
|
234
|
+
table.push([require_Console.theme.heading("Status"), realmConfig.active ? require_Console.theme.positive("active") : require_Console.theme.negative("inactive")]);
|
|
235
|
+
table.push([require_Console.theme.heading("Custom Domains"), realmConfig.aliases.join("\n")]);
|
|
236
|
+
table.push([require_Console.theme.heading("Parent"), realmConfig.parentPath]);
|
|
237
|
+
table.push([require_Console.theme.heading("Id"), realmConfig._id]);
|
|
238
|
+
require_Console.printMessage(table.toString(), "data");
|
|
239
|
+
} catch {
|
|
240
|
+
require_Console.printMessage(`Realm ${realm} not found!`, "error");
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Add custom DNS domain name (realm DNS alias)
|
|
245
|
+
* @param {String} realm realm name
|
|
246
|
+
* @param {String} domain domain name
|
|
247
|
+
*/
|
|
248
|
+
async function addCustomDomain(realm, domain) {
|
|
249
|
+
try {
|
|
250
|
+
let realmConfig = await readRealmByName(realm);
|
|
251
|
+
let exists = false;
|
|
252
|
+
realmConfig.aliases.forEach((alias) => {
|
|
253
|
+
if (domain.toLowerCase() === alias.toLowerCase()) exists = true;
|
|
254
|
+
});
|
|
255
|
+
if (!exists) try {
|
|
256
|
+
realmConfig.aliases.push(domain.toLowerCase());
|
|
257
|
+
realmConfig = await updateRealm(realmConfig._id, realmConfig);
|
|
258
|
+
const table = require_Console.createKeyValueTable();
|
|
259
|
+
table.push([require_Console.theme.heading("Name"), realmConfig.name]);
|
|
260
|
+
table.push([require_Console.theme.heading("Status"), realmConfig.active ? require_Console.theme.positive("active") : require_Console.theme.negative("inactive")]);
|
|
261
|
+
table.push([require_Console.theme.heading("Custom Domains"), realmConfig.aliases.join("\n")]);
|
|
262
|
+
table.push([require_Console.theme.heading("Parent"), realmConfig.parentPath]);
|
|
263
|
+
table.push([require_Console.theme.heading("Id"), realmConfig._id]);
|
|
264
|
+
require_Console.printMessage(table.toString());
|
|
265
|
+
} catch (error) {
|
|
266
|
+
require_Console.printMessage(`Error adding custom domain: ${error.message}`, "error");
|
|
267
|
+
}
|
|
268
|
+
} catch (error) {
|
|
269
|
+
require_Console.printMessage(`${error.message}`, "error");
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
//#endregion
|
|
273
|
+
Object.defineProperty(exports, "RealmOps_exports", {
|
|
274
|
+
enumerable: true,
|
|
275
|
+
get: function() {
|
|
276
|
+
return RealmOps_exports;
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
Object.defineProperty(exports, "addCustomDomain", {
|
|
280
|
+
enumerable: true,
|
|
281
|
+
get: function() {
|
|
282
|
+
return addCustomDomain;
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
Object.defineProperty(exports, "describeRealm", {
|
|
286
|
+
enumerable: true,
|
|
287
|
+
get: function() {
|
|
288
|
+
return describeRealm;
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
Object.defineProperty(exports, "exportRealmById", {
|
|
292
|
+
enumerable: true,
|
|
293
|
+
get: function() {
|
|
294
|
+
return exportRealmById;
|
|
295
|
+
}
|
|
296
|
+
});
|
|
297
|
+
Object.defineProperty(exports, "exportRealmByName", {
|
|
298
|
+
enumerable: true,
|
|
299
|
+
get: function() {
|
|
300
|
+
return exportRealmByName;
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
Object.defineProperty(exports, "exportRealmsToFile", {
|
|
304
|
+
enumerable: true,
|
|
305
|
+
get: function() {
|
|
306
|
+
return exportRealmsToFile;
|
|
307
|
+
}
|
|
308
|
+
});
|
|
309
|
+
Object.defineProperty(exports, "exportRealmsToFiles", {
|
|
310
|
+
enumerable: true,
|
|
311
|
+
get: function() {
|
|
312
|
+
return exportRealmsToFiles;
|
|
313
|
+
}
|
|
314
|
+
});
|
|
315
|
+
Object.defineProperty(exports, "importRealmFromFile", {
|
|
316
|
+
enumerable: true,
|
|
317
|
+
get: function() {
|
|
318
|
+
return importRealmFromFile;
|
|
319
|
+
}
|
|
320
|
+
});
|
|
321
|
+
Object.defineProperty(exports, "importRealmsFromFile", {
|
|
322
|
+
enumerable: true,
|
|
323
|
+
get: function() {
|
|
324
|
+
return importRealmsFromFile;
|
|
325
|
+
}
|
|
326
|
+
});
|
|
327
|
+
Object.defineProperty(exports, "importRealmsFromFiles", {
|
|
328
|
+
enumerable: true,
|
|
329
|
+
get: function() {
|
|
330
|
+
return importRealmsFromFiles;
|
|
331
|
+
}
|
|
332
|
+
});
|
|
333
|
+
Object.defineProperty(exports, "listRealms", {
|
|
334
|
+
enumerable: true,
|
|
335
|
+
get: function() {
|
|
336
|
+
return listRealms;
|
|
337
|
+
}
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
//# sourceMappingURL=RealmOps-Buhw-nZ1.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RealmOps-Buhw-nZ1.cjs","names":["frodo","createTable","c","createProgressIndicator","FrodoError","createKeyValueTable"],"sources":["../src/ops/RealmOps.ts"],"sourcesContent":["import fs from 'fs';\nimport {\n frodo,\n FrodoError,\n type RealmExportInterface,\n} from '@rockcarver/frodo-lib';\nimport c from '../utils/ColorTheme';\nimport {\n createKeyValueTable,\n createProgressIndicator,\n createTable,\n debugMessage,\n printError,\n printMessage,\n stopProgressIndicator,\n updateProgressIndicator,\n} from '../utils/Console';\n\nconst {\n readRealm,\n readRealms,\n readRealmByName,\n exportRealms,\n importRealms,\n updateRealm,\n} = frodo.realm;\n\nconst {\n getTypedFilename,\n saveToFile,\n saveJsonToFile,\n getFilePath,\n getWorkingDirectory,\n} = frodo.utils;\n\n/**\n * Per-invocation cache of the realm list. The realm picker reads\n * realms right after auth, and commands like `frodo realm list` read them\n * again moments later -- two HTTP calls to the same endpoint that would\n * (a) double the latency and (b) break Polly's order-matched replay in e2e\n * recordings, which have one entry for the endpoint. Sharing one memoized\n * read keeps both callers on a single fetch.\n */\nlet realmsCache: Awaited<ReturnType<typeof readRealms>> | undefined;\n\n/**\n * Reads all realms, memoized for the remainder of this invocation. Callers\n * that need fresh data (import/export mutations) call frodo.realm\n * .readRealms directly.\n */\nexport async function readRealmsCached() {\n if (!realmsCache) {\n realmsCache = await readRealms();\n }\n return realmsCache;\n}\n\n/**\n * Clears the memoized realm list (test hygiene between invocations).\n */\nexport function resetRealmsCacheForTests(): void {\n realmsCache = undefined;\n}\n\n/**\n * List realms\n * @param {boolean} long Long list format with details\n */\nexport async function listRealms(long = false) {\n try {\n const realms = await readRealmsCached();\n if (long) {\n const table = createTable([\n c.heading('Id'),\n c.heading('Name'),\n c.heading('Status'),\n c.heading('Custom Domains'),\n c.heading('Parent Path'),\n ]);\n realms.forEach((realmConfig) => {\n table.push([\n realmConfig._id,\n realmConfig.name,\n realmConfig.active ? c.positive('active') : c.negative('inactive'),\n realmConfig.aliases.join('\\n'),\n realmConfig.parentPath,\n ]);\n });\n printMessage(table.toString(), 'data');\n } else {\n realms.forEach((realmConfig) => {\n printMessage(\n (realmConfig.parentPath || '') +\n (realmConfig.parentPath && !realmConfig.parentPath.endsWith('/')\n ? '/'\n : '') +\n realmConfig.name,\n 'data'\n );\n });\n }\n } catch (error) {\n printMessage(error, 'error');\n printMessage(`Error listing realms: ${error.message}`, 'error');\n printMessage(error.response?.data, 'error');\n }\n}\n\n/**\n * Export realm to file by id\n * @param {string} realmId realm id\n * @param {string} file file name\n * @param {boolean} includeMeta true to include metadata, false otherwise. Default: true\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function exportRealmById(\n realmId: string,\n file: string,\n includeMeta: boolean = true\n): Promise<boolean> {\n const indicatorId = createProgressIndicator(\n 'determinate',\n 1,\n `Exporting ${realmId}...`\n );\n try {\n const realm = await readRealm(realmId);\n let fileName = getTypedFilename(realmId, `realm`);\n if (file) {\n fileName = file;\n }\n updateProgressIndicator(indicatorId, `Saving ${realmId} to ${fileName}...`);\n saveToFile(\n 'realm',\n [realm],\n '_id',\n getFilePath(fileName, true),\n includeMeta\n );\n stopProgressIndicator(\n indicatorId,\n `Exported realm ${realmId} to file`,\n 'success'\n );\n return true;\n } catch (error) {\n stopProgressIndicator(\n indicatorId,\n `Error exporting realm ${realmId} to file`,\n 'fail'\n );\n printError(error);\n }\n return false;\n}\n\n/**\n * Export realm to file by name\n * @param {string} realmName realm name\n * @param {string} file file name\n * @param {boolean} includeMeta true to include metadata, false otherwise. Default: true\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function exportRealmByName(\n realmName: string,\n file: string,\n includeMeta: boolean = true\n): Promise<boolean> {\n const indicatorId = createProgressIndicator(\n 'determinate',\n 1,\n `Exporting ${realmName}...`\n );\n try {\n const realm = await readRealmByName(realmName);\n let fileName = getTypedFilename(\n !realmName || realmName === '/' ? 'root' : realmName,\n `realm`\n );\n if (file) {\n fileName = file;\n }\n updateProgressIndicator(\n indicatorId,\n `Saving ${realmName} to ${fileName}...`\n );\n saveToFile(\n 'realm',\n [realm],\n '_id',\n getFilePath(fileName, true),\n includeMeta\n );\n stopProgressIndicator(\n indicatorId,\n `Exported realm ${realmName} to file`,\n 'success'\n );\n return true;\n } catch (error) {\n stopProgressIndicator(\n indicatorId,\n `Error exporting realm ${realmName} to file`,\n 'fail'\n );\n printError(error);\n }\n return false;\n}\n\n/**\n * Export all realms to file\n * @param {string} file file name\n * @param {boolean} includeMeta true to include metadata, false otherwise. Default: true\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function exportRealmsToFile(\n file: string,\n includeMeta: boolean = true\n): Promise<boolean> {\n try {\n const exportData = await exportRealms();\n let fileName = getTypedFilename(`allRealms`, `realm`);\n if (file) {\n fileName = file;\n }\n saveJsonToFile(exportData, getFilePath(fileName, true), includeMeta);\n return true;\n } catch (error) {\n printError(error, `Error exporting realms to file`);\n }\n return false;\n}\n\n/**\n * Export all realms to separate files\n * @param {boolean} includeMeta true to include metadata, false otherwise. Default: true\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function exportRealmsToFiles(\n includeMeta: boolean = true\n): Promise<boolean> {\n try {\n const realms = await readRealms();\n for (const realm of realms) {\n const fileName = getTypedFilename(\n !realm.name || realm.name === '/' ? 'root' : realm.name,\n 'realm'\n );\n saveToFile(\n 'realm',\n realm,\n '_id',\n getFilePath(fileName, true),\n includeMeta\n );\n }\n return true;\n } catch (error) {\n printError(error, `Error exporting realms to files`);\n }\n return false;\n}\n\n/**\n * Import a realm from file. The first realm from the file will be imported if no id/name is provided.\n * @param {string} realmId realm id\n * @param {string} realmName realm name\n * @param {string} file import file name\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function importRealmFromFile(\n realmId: string,\n realmName: string,\n file: string\n): Promise<boolean> {\n const indicatorId = createProgressIndicator(\n 'determinate',\n 1,\n 'Importing realm...'\n );\n try {\n const importData = JSON.parse(\n fs.readFileSync(getFilePath(file), 'utf8')\n ) as RealmExportInterface;\n if (!realmId && !realmName) {\n const firstRealm = Object.values(importData.realm)[0];\n if (!firstRealm) {\n stopProgressIndicator(indicatorId, `No realms found!`, 'fail');\n return false;\n }\n realmName = firstRealm.name;\n }\n updateProgressIndicator(\n indicatorId,\n `Importing realm ${realmName ? realmName : realmId}.`\n );\n await importRealms(importData, realmId, realmName);\n stopProgressIndicator(indicatorId, `Successfully imported realm.`);\n return true;\n } catch (error) {\n stopProgressIndicator(indicatorId, `Error importing realm`, 'fail');\n printError(error);\n }\n return false;\n}\n\n/**\n * Import all realms from file\n * @param {string} file import file name\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function importRealmsFromFile(file: string): Promise<boolean> {\n try {\n debugMessage(`importRealmsFromFile: start`);\n const filePath = getFilePath(file);\n const data = fs.readFileSync(filePath, 'utf8');\n debugMessage(`importRealmsFromFile: importing ${filePath}`);\n const importData = JSON.parse(data);\n await importRealms(importData);\n debugMessage(`importRealmsFromFile: end`);\n return true;\n } catch (error) {\n printError(error, `Error importing realms from file`);\n }\n return false;\n}\n\n/**\n * Import all realms from separate files\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function importRealmsFromFiles(): Promise<boolean> {\n const errors: Error[] = [];\n try {\n const names = fs.readdirSync(getWorkingDirectory());\n const realmFiles = names.filter((name) =>\n name.toLowerCase().endsWith('.realm.json')\n );\n for (const file of realmFiles) {\n try {\n await importRealmsFromFile(file);\n } catch (error) {\n errors.push(\n new FrodoError(`Error importing realms from ${file}`, error)\n );\n }\n }\n if (errors.length > 0) {\n throw new FrodoError(`One or more errors importing realms`, errors);\n }\n return true;\n } catch (error) {\n if (errors.length > 0) {\n printError(error);\n } else {\n printError(error, `Error importing realms from files`);\n }\n }\n return false;\n}\n\n/**\n * Describe realm\n * @param {String} realm realm name\n */\nexport async function describeRealm(realm: string) {\n try {\n const realmConfig = await readRealmByName(realm);\n const table = createKeyValueTable();\n table.push([c.heading('Name'), realmConfig.name]);\n table.push([\n c.heading('Status'),\n realmConfig.active ? c.positive('active') : c.negative('inactive'),\n ]);\n table.push([c.heading('Custom Domains'), realmConfig.aliases.join('\\n')]);\n table.push([c.heading('Parent'), realmConfig.parentPath]);\n table.push([c.heading('Id'), realmConfig._id]);\n printMessage(table.toString(), 'data');\n } catch {\n printMessage(`Realm ${realm} not found!`, 'error');\n }\n}\n\n/**\n * Add custom DNS domain name (realm DNS alias)\n * @param {String} realm realm name\n * @param {String} domain domain name\n */\nexport async function addCustomDomain(realm: string, domain: string) {\n try {\n let realmConfig = await readRealmByName(realm);\n let exists = false;\n realmConfig.aliases.forEach((alias) => {\n if (domain.toLowerCase() === alias.toLowerCase()) {\n exists = true;\n }\n });\n if (!exists) {\n try {\n realmConfig.aliases.push(domain.toLowerCase());\n realmConfig = await updateRealm(realmConfig._id, realmConfig);\n const table = createKeyValueTable();\n table.push([c.heading('Name'), realmConfig.name]);\n table.push([\n c.heading('Status'),\n realmConfig.active ? c.positive('active') : c.negative('inactive'),\n ]);\n table.push([\n c.heading('Custom Domains'),\n realmConfig.aliases.join('\\n'),\n ]);\n table.push([c.heading('Parent'), realmConfig.parentPath]);\n table.push([c.heading('Id'), realmConfig._id]);\n printMessage(table.toString());\n } catch (error) {\n printMessage(`Error adding custom domain: ${error.message}`, 'error');\n }\n }\n } catch (error) {\n printMessage(`${error.message}`, 'error');\n }\n}\n\n/**\n * Remove custom DNS domain name (realm DNS alias)\n * @param {String} realm realm name\n * @param {String} domain domain name\n */\nexport async function removeCustomDomain(realm: string, domain: string) {\n try {\n let realmConfig = await readRealmByName(realm);\n const aliases = realmConfig.aliases.filter(\n (alias) => domain.toLowerCase() !== alias.toLowerCase()\n );\n if (aliases.length < realmConfig.aliases.length) {\n try {\n realmConfig.aliases = aliases;\n realmConfig = await updateRealm(realmConfig._id, realmConfig);\n const table = createKeyValueTable();\n table.push([c.heading('Name'), realmConfig.name]);\n table.push([\n c.heading('Status'),\n realmConfig.active ? c.positive('active') : c.negative('inactive'),\n ]);\n table.push([\n c.heading('Custom Domains'),\n realmConfig.aliases.join('\\n'),\n ]);\n table.push([c.heading('Parent'), realmConfig.parentPath]);\n table.push([c.heading('Id'), realmConfig._id]);\n printMessage(table.toString());\n } catch (error) {\n printMessage(`Error removing custom domain: ${error.message}`, 'error');\n }\n }\n } catch (error) {\n printMessage(`${error.message}`, 'error');\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAkBA,MAAM,EACJ,WACA,YACA,iBACA,cACA,cACA,gBACEA,gBAAAA,MAAM;AAEV,MAAM,EACJ,kBACA,YACA,gBACA,aACA,wBACEA,gBAAAA,MAAM;;;;;;;;;AAUV,IAAI;;;;;;AAOJ,eAAsB,mBAAmB;CACvC,IAAI,CAAC,aACH,cAAc,MAAM,WAAW;CAEjC,OAAO;AACT;;;;;AAaA,eAAsB,WAAW,OAAO,OAAO;CAC7C,IAAI;EACF,MAAM,SAAS,MAAM,iBAAiB;EACtC,IAAI,MAAM;GACR,MAAM,QAAQC,gBAAAA,YAAY;IACxBC,gBAAAA,MAAE,QAAQ,IAAI;IACdA,gBAAAA,MAAE,QAAQ,MAAM;IAChBA,gBAAAA,MAAE,QAAQ,QAAQ;IAClBA,gBAAAA,MAAE,QAAQ,gBAAgB;IAC1BA,gBAAAA,MAAE,QAAQ,aAAa;GACzB,CAAC;GACD,OAAO,SAAS,gBAAgB;IAC9B,MAAM,KAAK;KACT,YAAY;KACZ,YAAY;KACZ,YAAY,SAASA,gBAAAA,MAAE,SAAS,QAAQ,IAAIA,gBAAAA,MAAE,SAAS,UAAU;KACjE,YAAY,QAAQ,KAAK,IAAI;KAC7B,YAAY;IACd,CAAC;GACH,CAAC;GACD,gBAAA,aAAa,MAAM,SAAS,GAAG,MAAM;EACvC,OACE,OAAO,SAAS,gBAAgB;GAC9B,gBAAA,cACG,YAAY,cAAc,OACxB,YAAY,cAAc,CAAC,YAAY,WAAW,SAAS,GAAG,IAC3D,MACA,MACJ,YAAY,MACd,MACF;EACF,CAA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/B,SAAS,OAAO;GACd,gBAAA,aAAa,+BAA+B,MAAM,WAAW,OAAO;EACtE;CAEJ,SAAS,OAAO;EACd,gBAAA,aAAa,GAAG,MAAM,WAAW,OAAO;CAC1C;AACF"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
const require_rolldown_runtime = require("./rolldown-runtime-Ctb5zv51.cjs");
|
|
2
|
+
const require_Console = require("./Console-1LBCP_JZ.cjs");
|
|
3
|
+
const require_EscapableSelectPrompt = require("./EscapableSelectPrompt-BljVxNDm.cjs");
|
|
4
|
+
//#region src/utils/interactive/RealmPickers.ts
|
|
5
|
+
/**
|
|
6
|
+
* Realm picker (docs/INTERACTIVE-COMMANDS.md, post-auth pickers).
|
|
7
|
+
*
|
|
8
|
+
* After authentication succeeds, a command whose realm argument was left
|
|
9
|
+
* at its default can offer a dropdown of the target system's realms --
|
|
10
|
+
* but ONLY when the system actually has more than one (a single-realm
|
|
11
|
+
* tenant has no choice to offer; the default is already correct). The
|
|
12
|
+
* pick fires from the getTokens wrapper (AuthenticateOps) immediately
|
|
13
|
+
* after auth succeeds, so every command gets it without per-command
|
|
14
|
+
* wiring; a prompt only happens when
|
|
15
|
+
*
|
|
16
|
+
* - the gate allows prompting (canPrompt()),
|
|
17
|
+
* - the command declares a realm positional argument,
|
|
18
|
+
* - the user did not name a realm explicitly (argument value or
|
|
19
|
+
* FRODO_REALM -- recorded by `noteRealmProvenance` during the
|
|
20
|
+
* resolution pass, BEFORE frodo-lib maps the sentinel default to the
|
|
21
|
+
* deployment type's realm during auth), and
|
|
22
|
+
* - the target system reports more than one realm.
|
|
23
|
+
*
|
|
24
|
+
* Every other path is a no-op. Escape declines the offer and keeps the
|
|
25
|
+
* deployment-type default -- unlike the entity pickers there is no
|
|
26
|
+
* "wrong" continuation to protect here (the default is a valid choice),
|
|
27
|
+
* so backing out just means "keep the default".
|
|
28
|
+
*
|
|
29
|
+
* The loader failing (permission denied on realm listing, older servers,
|
|
30
|
+
* classic deployments where the endpoint differs) is swallowed and the
|
|
31
|
+
* default kept: the command is about to run against the default realm
|
|
32
|
+
* exactly as it did before the interactive layer existed.
|
|
33
|
+
*/
|
|
34
|
+
var RealmPickers_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({
|
|
35
|
+
noteRealmProvenance: () => noteRealmProvenance,
|
|
36
|
+
resolveRealmPick: () => resolveRealmPick
|
|
37
|
+
});
|
|
38
|
+
/** frodo-lib's sentinel default for "no realm chosen yet". */
|
|
39
|
+
const DEFAULT_REALM_KEY = "__default__realm__";
|
|
40
|
+
/** Cache of the realms read during this invocation (one fetch per run). */
|
|
41
|
+
let cachedRealms;
|
|
42
|
+
/**
|
|
43
|
+
* Whether the current invocation's realm was user-specified. Captured by
|
|
44
|
+
* `noteRealmProvenance` during the resolution pass -- it CANNOT be
|
|
45
|
+
* re-derived after auth, because frodo-lib's determineDefaultRealm
|
|
46
|
+
* replaces the sentinel default with the deployment type's realm (alpha
|
|
47
|
+
* or /) during _getTokens, making a user choice and a mapped default
|
|
48
|
+
* indistinguishable afterwards.
|
|
49
|
+
*/
|
|
50
|
+
let realmUserSpecified = false;
|
|
51
|
+
/**
|
|
52
|
+
* Records whether this invocation's realm came from the user (positional
|
|
53
|
+
* argument value or FRODO_REALM) as opposed to the sentinel default.
|
|
54
|
+
* Called by the resolution pass BEFORE auth -- see the `realmUserSpecified`
|
|
55
|
+
* doc for why the timing matters.
|
|
56
|
+
*/
|
|
57
|
+
function noteRealmProvenance() {
|
|
58
|
+
const realm = require_Console.state.getRealm();
|
|
59
|
+
realmUserSpecified = !!realm && realm !== DEFAULT_REALM_KEY;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Offers the realm dropdown for `command`'s realm argument when the
|
|
63
|
+
* conditions in the module doc hold. Called by the getTokens wrapper
|
|
64
|
+
* after a successful login. Never throws; on any problem it simply keeps
|
|
65
|
+
* the default.
|
|
66
|
+
*/
|
|
67
|
+
async function resolveRealmPick(command) {
|
|
68
|
+
if (!require_EscapableSelectPrompt.canPrompt()) return;
|
|
69
|
+
if (!command.registeredArguments.some((a) => a.name() === "realm")) return;
|
|
70
|
+
if (realmUserSpecified) return;
|
|
71
|
+
let realms;
|
|
72
|
+
try {
|
|
73
|
+
if (!cachedRealms) {
|
|
74
|
+
const { readRealmsCached } = await Promise.resolve().then(() => require("./RealmOps-Buhw-nZ1.cjs")).then((n) => n.RealmOps_exports);
|
|
75
|
+
cachedRealms = (await readRealmsCached()).map((realm) => ({
|
|
76
|
+
name: realm.name ?? realm._id ?? "",
|
|
77
|
+
active: realm.active ?? true
|
|
78
|
+
}));
|
|
79
|
+
}
|
|
80
|
+
realms = cachedRealms;
|
|
81
|
+
} catch {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
if (realms.length <= 1) return;
|
|
85
|
+
const current = require_Console.state.getRealm();
|
|
86
|
+
let choice;
|
|
87
|
+
for (;;) {
|
|
88
|
+
const { livePositionalPreviewFor, runInvocationEditorForCommand } = await Promise.resolve().then(() => require("./ResolveInteractiveInputs-D_-5704M.cjs")).then((n) => n.ResolveInteractiveInputs_exports);
|
|
89
|
+
const answer = await require_EscapableSelectPrompt.escapableSelect({
|
|
90
|
+
message: `Choose a realm (default: ${current}):`,
|
|
91
|
+
default: current,
|
|
92
|
+
hint: require_EscapableSelectPrompt.editableOptionsHint(command),
|
|
93
|
+
preview: livePositionalPreviewFor(command, "realm"),
|
|
94
|
+
choices: realms.map((realm) => ({
|
|
95
|
+
value: realm.name,
|
|
96
|
+
name: realm.name,
|
|
97
|
+
description: realm.active ? void 0 : "inactive"
|
|
98
|
+
}))
|
|
99
|
+
});
|
|
100
|
+
if (answer === require_EscapableSelectPrompt.EXIT_ALL) throw require_EscapableSelectPrompt.EXIT_ALL_SIGNAL;
|
|
101
|
+
if (answer === require_EscapableSelectPrompt.RIGHT) {
|
|
102
|
+
await runInvocationEditorForCommand(command);
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
choice = answer;
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
if (choice === require_EscapableSelectPrompt.ESCAPE) {
|
|
109
|
+
require_Console.verboseMessage(`Keeping the default realm ${current}.`);
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
if (!choice || choice === current) {
|
|
113
|
+
require_Console.verboseMessage(`Keeping the default realm ${current}.`);
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
require_Console.state.setRealm(choice);
|
|
117
|
+
{
|
|
118
|
+
const { setPositionalValueForCommand } = await Promise.resolve().then(() => require("./ResolveInteractiveInputs-D_-5704M.cjs")).then((n) => n.ResolveInteractiveInputs_exports);
|
|
119
|
+
setPositionalValueForCommand(command, "realm", choice.replace(/^\//, ""));
|
|
120
|
+
}
|
|
121
|
+
require_Console.verboseMessage(`Using realm ${choice}.`);
|
|
122
|
+
}
|
|
123
|
+
//#endregion
|
|
124
|
+
Object.defineProperty(exports, "RealmPickers_exports", {
|
|
125
|
+
enumerable: true,
|
|
126
|
+
get: function() {
|
|
127
|
+
return RealmPickers_exports;
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
Object.defineProperty(exports, "noteRealmProvenance", {
|
|
131
|
+
enumerable: true,
|
|
132
|
+
get: function() {
|
|
133
|
+
return noteRealmProvenance;
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
//# sourceMappingURL=RealmPickers-IjVJiRB5.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RealmPickers-IjVJiRB5.cjs","names":["state","canPrompt","escapableSelect","editableOptionsHint","EXIT_ALL","EXIT_ALL_SIGNAL","RIGHT","ESCAPE"],"sources":["../src/utils/interactive/RealmPickers.ts"],"sourcesContent":["/**\n * Realm picker (docs/INTERACTIVE-COMMANDS.md, post-auth pickers).\n *\n * After authentication succeeds, a command whose realm argument was left\n * at its default can offer a dropdown of the target system's realms --\n * but ONLY when the system actually has more than one (a single-realm\n * tenant has no choice to offer; the default is already correct). The\n * pick fires from the getTokens wrapper (AuthenticateOps) immediately\n * after auth succeeds, so every command gets it without per-command\n * wiring; a prompt only happens when\n *\n * - the gate allows prompting (canPrompt()),\n * - the command declares a realm positional argument,\n * - the user did not name a realm explicitly (argument value or\n * FRODO_REALM -- recorded by `noteRealmProvenance` during the\n * resolution pass, BEFORE frodo-lib maps the sentinel default to the\n * deployment type's realm during auth), and\n * - the target system reports more than one realm.\n *\n * Every other path is a no-op. Escape declines the offer and keeps the\n * deployment-type default -- unlike the entity pickers there is no\n * \"wrong\" continuation to protect here (the default is a valid choice),\n * so backing out just means \"keep the default\".\n *\n * The loader failing (permission denied on realm listing, older servers,\n * classic deployments where the endpoint differs) is swallowed and the\n * default kept: the command is about to run against the default realm\n * exactly as it did before the interactive layer existed.\n */\n\nimport { state } from '@rockcarver/frodo-lib';\nimport { Command } from 'commander';\nimport { verboseMessage } from '../Console';\nimport { editableOptionsHint } from './EditableOptions';\nimport { escapableSelect, ESCAPE, RIGHT } from './EscapableSelectPrompt';\nimport { EXIT_ALL, EXIT_ALL_SIGNAL } from './ExitAll';\nimport { canPrompt } from './PromptGateState';\n\n/** frodo-lib's sentinel default for \"no realm chosen yet\". */\nconst DEFAULT_REALM_KEY = '__default__realm__';\n\n/** Cache of the realms read during this invocation (one fetch per run). */\nlet cachedRealms: { name: string; active: boolean }[] | undefined;\n\n/**\n * Whether the current invocation's realm was user-specified. Captured by\n * `noteRealmProvenance` during the resolution pass -- it CANNOT be\n * re-derived after auth, because frodo-lib's determineDefaultRealm\n * replaces the sentinel default with the deployment type's realm (alpha\n * or /) during _getTokens, making a user choice and a mapped default\n * indistinguishable afterwards.\n */\nlet realmUserSpecified = false;\n\n/**\n * Records whether this invocation's realm came from the user (positional\n * argument value or FRODO_REALM) as opposed to the sentinel default.\n * Called by the resolution pass BEFORE auth -- see the `realmUserSpecified`\n * doc for why the timing matters.\n */\nexport function noteRealmProvenance(): void {\n const realm = state.getRealm();\n realmUserSpecified = !!realm && realm !== DEFAULT_REALM_KEY;\n}\n\n/** Test hygiene: clears the per-invocation provenance + realm cache. */\nexport function resetRealmPickerStateForTests(): void {\n realmUserSpecified = false;\n cachedRealms = undefined;\n}\n\n/**\n * Offers the realm dropdown for `command`'s realm argument when the\n * conditions in the module doc hold. Called by the getTokens wrapper\n * after a successful login. Never throws; on any problem it simply keeps\n * the default.\n */\nexport async function resolveRealmPick(command: Command): Promise<void> {\n if (!canPrompt()) return;\n if (!command.registeredArguments.some((a) => a.name() === 'realm')) return;\n if (realmUserSpecified) return;\n\n let realms: { name: string; active: boolean }[];\n try {\n if (!cachedRealms) {\n // Via the memoized ops helper: shares one fetch with commands that\n // read realms themselves (frodo realm list), keeping Polly's\n // order-matched replay intact (recordings have one entry for the\n // endpoint) and halving the latency when both run.\n const { readRealmsCached } = await import('../../ops/RealmOps');\n const skeletons = await readRealmsCached();\n cachedRealms = skeletons.map((realm) => ({\n name: realm.name ?? realm._id ?? '',\n active: realm.active ?? true,\n }));\n }\n realms = cachedRealms;\n } catch {\n return; // can't list realms: keep the default\n }\n if (realms.length <= 1) return;\n\n const current = state.getRealm();\n // The picker runs POST-AUTH, so `current` is already frodo-lib's mapped\n // deployment default (alpha on cloud, / on classic/forgeops) -- passing\n // it as the select's default pre-highlights the TRUE default instead of\n // the first row, so a bare <enter> means \"keep the deployment default\".\n // The default may legitimately be absent from the list (the realms\n // endpoint never returns the root realm, so on classic/forgeops \"/\" has\n // no row): escapableSelect falls back to the first row in that case.\n // → (armed by the hint) opens the invocation editor, then\n // re-prompts this picker; ESCAPE keeps the default as before; EXIT_ALL\n // THROWS the unwind signal (the session ends even though auth already\n // succeeded -- the gesture means \"leave everything\", from any depth,\n // per docs/INTERACTIVE-COMMANDS.md).\n // The loop's exit type is string | typeof ESCAPE (the RIGHT case loops;\n // EXIT_ALL never resolves out of the loop -- it throws).\n let choice: string | typeof ESCAPE;\n for (;;) {\n const { livePositionalPreviewFor, runInvocationEditorForCommand } =\n await import('../../cli/ResolveInteractiveInputs');\n const answer = await escapableSelect<string>({\n message: `Choose a realm (default: ${current}):`,\n default: current,\n hint: editableOptionsHint(command),\n // LIVE footer: the highlighted realm shadows the realm positional\n // per render, so the footer's realm token moves with the cursor\n // BEFORE <enter> commits (live preview).\n preview: livePositionalPreviewFor(command, 'realm'),\n choices: realms.map((realm) => ({\n value: realm.name,\n name: realm.name,\n description: realm.active ? undefined : 'inactive',\n })),\n });\n if (answer === EXIT_ALL) throw EXIT_ALL_SIGNAL;\n if (answer === RIGHT) {\n // The hint advertised the editor, so → must open it (this branch\n // used to just re-prompt, making the key look dead). The editor\n // throws EXIT_ALL_SIGNAL on a double-ESC; a plain return loops\n // back here and the user can still ESC the picker.\n await runInvocationEditorForCommand(command);\n continue;\n }\n choice = answer;\n break;\n }\n if (choice === ESCAPE) {\n // Backed out: keep the deployment default (the pre-interactive\n // behavior), AND say so -- a silent return after the frame erased\n // left the terminal idle with no explanation (user report\n // 2026-10-13: \"the picker wasn't active\" -- the prompt had actually\n // concluded; nothing showed why nothing then happened).\n verboseMessage(`Keeping the default realm ${current}.`);\n return;\n }\n if (!choice || choice === current) {\n // <enter> on the already-highlighted default: an explicit \"keep\n // it\". The pick is DONE -- do NOT loop back into another picker\n // instance (the old silent re-prompt read as a dead screen: the\n // prompt concluded and nothing re-appeared).\n verboseMessage(`Keeping the default realm ${current}.`);\n return;\n }\n state.setRealm(choice);\n // Write the picked realm back into the command's realm positional so the\n // deferred authoring print (flushed at the action's postAction hook, see\n // FrodoCommand/AuthoringPrintState) shows the command EXACTLY as it ran\n // -- the printed realm token matches state.getRealm() token for token.\n // Without this, a non-default pick would print the (sentinel-translated)\n // positional while the action actually runs in `choice`. The CLI\n // positional convention is the plain name (no leading slash) -- the\n // exact value the user would type -- and handleDefaultArgsAndOpts\n // re-feeds it into state.setRealm inside the action body, so the value\n // must be positional-shaped, not state-shaped.\n {\n const { setPositionalValueForCommand } =\n await import('../../cli/ResolveInteractiveInputs');\n setPositionalValueForCommand(command, 'realm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