UNPKG

firebase-tools

Version:
60 lines (58 loc) • 3.87 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.command = void 0; const clc = require("colorette"); const command_1 = require("../command"); const debugTokens_1 = require("../appcheck/debugTokens"); const localConfig_1 = require("../appcheck/localConfig"); const error_1 = require("../error"); const logger_1 = require("../logger"); const projectUtils_1 = require("../projectUtils"); const prompt_1 = require("../prompt"); const requireAuth_1 = require("../requireAuth"); const utils_1 = require("../utils"); function logServerTokensUntouchedNote() { logger_1.logger.info(`Server-registered debug tokens are untouched. Manage server tokens with ${clc.bold("firebase appcheck:debugtokens:list")} and ${clc.bold("firebase appcheck:debugtokens:delete")}.`); } exports.command = new command_1.Command("appcheck:debugtokens:prune") .description("remove stale App Check debug tokens from the local machine config") .help(`removes stale App Check debug token entries from ~/.config/configstore/firebase-appcheck.json (and $XDG_CONFIG_HOME/configstore/firebase-appcheck.json when $XDG_CONFIG_HOME is set) on this machine whose Firebase app has been deleted from the active project or whose debug token has been revoked on the server. This command only modifies the local machine config (~/.config/configstore/firebase-appcheck.json and any $XDG_CONFIG_HOME mirror); server-registered debug tokens are untouched and can be managed via \`firebase appcheck:debugtokens:list\` and \`firebase appcheck:debugtokens:delete\`.`) .withForce("remove stale local debug tokens without prompting") .before((options) => (0, requireAuth_1.requireAuth)(options)) .action(async (options) => { const projectId = (0, projectUtils_1.needProjectId)(options); const projectNumber = await (0, projectUtils_1.needProjectNumber)(options); if (Object.keys((0, localConfig_1.getAllLocalTokens)()).length === 0) { logger_1.logger.info(clc.bold("No local App Check debug tokens found.")); logServerTokensUntouchedNote(); return { prunedAppIds: [] }; } const staleEntries = await (0, utils_1.promiseWithSpinner)(() => (0, debugTokens_1.findStaleLocalDebugTokens)({ projectId, projectNumber }), `Checking local App Check debug tokens against project ${clc.bold(projectId)}`); if (staleEntries.length === 0) { logger_1.logger.info(clc.bold(`No stale local App Check debug tokens found for project ${projectId}.`)); logServerTokensUntouchedNote(); return { prunedAppIds: [] }; } logger_1.logger.info(`Found ${staleEntries.length} stale local debug token(s) in ${clc.bold((0, localConfig_1.getLocalConfigPath)())}:`); for (const entry of staleEntries) { logger_1.logger.info(` - ${clc.bold(entry.appId)} (${entry.tokenPrefix}): ${(0, debugTokens_1.formatLocalTokenStatus)(entry.status)}`); } logServerTokensUntouchedNote(); if (!options.force) { if (options.nonInteractive) { throw new error_1.FirebaseError("Must pass --force to prune stale local debug tokens in non-interactive mode.", { exit: 1 }); } const consent = await (0, prompt_1.confirm)({ message: `Remove ${staleEntries.length} stale local debug token(s) from ${(0, localConfig_1.getLocalConfigPath)()}?`, default: false, }); if (!consent) { throw new error_1.FirebaseError("Prune local App Check debug tokens canceled.", { exit: 1 }); } } const prunedAppIds = staleEntries.map((entry) => entry.appId); (0, localConfig_1.removeLocalTokens)(prunedAppIds); (0, utils_1.logSuccess)(`Pruned ${prunedAppIds.length} stale local App Check debug token(s) from ${clc.bold((0, localConfig_1.getLocalConfigPath)())}: ${prunedAppIds.join(", ")}`); return { prunedAppIds }; });