firebase-tools
Version:
Command-Line Interface for Firebase
65 lines (64 loc) • 2.98 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.command = void 0;
const clc = require("colorette");
const Table = require("cli-table3");
const command_1 = require("../command");
const projectUtils_1 = require("../projectUtils");
const api_1 = require("../appcheck/api");
const debugTokens_1 = require("../appcheck/debugTokens");
const appcheck_prompts_1 = require("./appcheck-prompts");
const requireAuth_1 = require("../requireAuth");
const logger_1 = require("../logger");
const utils_1 = require("../utils");
function logServerDebugTokensList(debugTokens) {
if (debugTokens.length === 0) {
logger_1.logger.info(clc.bold("No App Check debug tokens found."));
return;
}
const table = new Table({
head: ["Display Name", "Resource Name", "Update Time"],
style: { head: ["green"] },
});
for (const { displayName, name, updateTime } of debugTokens) {
table.push([displayName, name, updateTime || "N/A"]);
}
logger_1.logger.info(table.toString());
}
function logLocalDebugTokensList(entries) {
if (entries.length === 0) {
logger_1.logger.info(clc.bold("No local App Check debug tokens found."));
return;
}
const table = new Table({
head: ["App ID", "Token Prefix", "Server Status"],
style: { head: ["green"] },
});
for (const entry of entries) {
table.push([entry.appId, entry.tokenPrefix, (0, debugTokens_1.formatLocalTokenStatus)(entry.status)]);
}
logger_1.logger.info(table.toString());
}
exports.command = new command_1.Command("appcheck:debugtokens:list")
.description("list Firebase App Check debug tokens for an app or stored locally on this machine")
.help(`lists server-registered Firebase App Check debug tokens for an app, or passes \`--local\` to inspect debug tokens saved in ~/.config/configstore/firebase-appcheck.json on this machine (optionally filtered by \`--app\`).`)
.option("--app <appId>", "the app id of your Firebase app")
.option("--local", "list debug tokens stored locally on this machine instead of querying all server tokens for an app")
.before((options) => {
if (options.local) {
return;
}
return (0, requireAuth_1.requireAuth)(options);
})
.action(async (options) => {
if (options.local) {
const localEntries = await (0, debugTokens_1.inspectLocalDebugTokens)(options);
logLocalDebugTokensList(localEntries);
return localEntries;
}
const { appId } = await (0, appcheck_prompts_1.getOrPromptProjectAndAppId)(options, "Select the app to list debug tokens for:");
const projectNumber = await (0, projectUtils_1.needProjectNumber)(options);
const debugTokens = await (0, utils_1.promiseWithSpinner)(() => (0, api_1.listDebugTokens)(projectNumber, appId), `Listing App Check debug tokens for app ${clc.bold(appId)}`);
logServerDebugTokensList(debugTokens);
return debugTokens;
});