UNPKG

firebase-tools

Version:
63 lines (62 loc) • 3.59 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.command = void 0; const clc = require("colorette"); const command_1 = require("../command"); const projectUtils_1 = require("../projectUtils"); const debugTokens_1 = require("../appcheck/debugTokens"); const localConfig_1 = require("../appcheck/localConfig"); const appcheck_prompts_1 = require("./appcheck-prompts"); const requireAuth_1 = require("../requireAuth"); const utils_1 = require("../utils"); const prompt_1 = require("../prompt"); const error_1 = require("../error"); const logger_1 = require("../logger"); exports.command = new command_1.Command("appcheck:debugtokens:delete <debugTokenId>") .description("delete a Firebase App Check debug token for an app") .help(`deletes a server-registered Firebase App Check debug token for an app (accepting either the short \`<debugTokenId>\` or the full \`projects/<projectNumber>/apps/<appId>/debugTokens/<debugTokenId>\` resource name) and removes the matching entry from ~/.config/configstore/firebase-appcheck.json if present.`) .option("--app <appId>", "the app id of your Firebase app") .withForce("attempt to delete debug token without prompting for confirmation") .before((options) => (0, requireAuth_1.requireAuth)(options)) .action(async (debugTokenId, options) => { let inferredAppId; if (debugTokenId.startsWith("projects/")) { const match = /^projects\/[^/]+\/apps\/([^/]+)\/debugTokens\/[^/]+$/.exec(debugTokenId); if (match) { inferredAppId = match[1]; } } const { appId } = await (0, appcheck_prompts_1.getOrPromptProjectAndAppId)({ ...options, app: options.app || inferredAppId }, "Select the app to delete a debug token from:"); const projectNumber = await (0, projectUtils_1.needProjectNumber)(options); let debugTokenName = debugTokenId; if (!debugTokenName.startsWith("projects/")) { debugTokenName = `projects/${projectNumber}/apps/${appId}/debugTokens/${debugTokenId}`; } else { const expectedPrefix = `projects/${projectNumber}/apps/${appId}/debugTokens/`; if (!debugTokenName.startsWith(expectedPrefix)) { throw new error_1.FirebaseError(`Debug token ${debugTokenId} does not belong to app ${appId} in project ${projectNumber}. ` + `Pass --app <appId> for the matching app or run "firebase appcheck:debugtokens:list" to view valid debug tokens.`, { exit: 1 }); } } if (!options.force) { if (options.nonInteractive) { throw new error_1.FirebaseError("Must pass --force to delete in non-interactive mode.", { exit: 1, }); } const confirmMessage = `You are about to delete App Check debug token ${clc.bold(debugTokenName)}. Do you wish to continue?`; const consent = await (0, prompt_1.confirm)({ message: confirmMessage, default: false, }); if (!consent) { throw new error_1.FirebaseError("Delete App Check debug token canceled.", { exit: 1 }); } } const removedLocal = await (0, utils_1.promiseWithSpinner)(() => (0, debugTokens_1.deleteDebugTokenAndCleanLocal)({ appId, debugTokenName }), `Deleting App Check debug token ${clc.bold(debugTokenName)}`); (0, utils_1.logSuccess)(`Successfully deleted App Check debug token ${clc.bold(debugTokenName)}`); if (removedLocal) { logger_1.logger.info(`Removed matching debug token from local config: ${clc.bold((0, localConfig_1.getLocalConfigPath)())}`); } });