UNPKG

firebase-tools

Version:
71 lines (69 loc) • 3.92 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.command = void 0; const js_yaml_1 = require("js-yaml"); const command_1 = require("../command"); const commandUtils_1 = require("../crashlytics/commandUtils"); const events_1 = require("../crashlytics/events"); const error_1 = require("../error"); const logger_1 = require("../logger"); const requireAuth_1 = require("../requireAuth"); const DEFAULT_LIMIT = 10; const MAX_LIMIT = 100; exports.command = (0, commandUtils_1.withEventFilterOptions)(new command_1.Command("crashlytics:events:list")) .description("list the most recent Crashlytics events matching the given filters") .option("--app <appId>", "the Firebase App ID") .option("--filter <expression>", "AIP-160 filter expression for custom keys (e.g. 'custom_keys.env = \"prod\"')") .option("-n, --limit <number>", `maximum number of events to return (1-${MAX_LIMIT}, default: ${DEFAULT_LIMIT})`) .option("--max-frames <number>", `maximum stack frames per thread or exception (default: ${events_1.DEFAULT_MAX_FRAMES}, ignored when --full is set)`) .option("--full", "include all threads, stack frames, logs, and breadcrumbs without truncation") .option("-o, --output <path>", "write raw JSON output to a file") .withForce("overwrite output file without prompting") .help(`Lists the most recent Crashlytics events matching the specified filters. Requires --issue-id. For Android/Apple apps, add --variant-id to narrow results to one issue variant. Custom Key Filtering (--filter): Filter events by Crashlytics custom keys using AIP-160 syntax: - Exact match: --filter 'custom_keys.env = "prod"' - Key presence: --filter 'custom_keys.experiment_id:*' - Multiple keys: --filter 'custom_keys.env = "prod" AND custom_keys.role = "admin"' - Multiple vals: --filter 'custom_keys.env = "prod" OR custom_keys.env = "staging"' OR is only supported between values of the same key.`) .before(requireAuth_1.requireAuth) .action(async (options) => { const appId = (0, commandUtils_1.requireAppId)(options); const filter = (0, commandUtils_1.parseEventFilters)(options, appId); if (!filter?.issueId) { throw new error_1.FirebaseError(`Must specify '--issue-id <id>' to list events. Run 'firebase crashlytics:reports:get --app ${appId} topIssues' to find issue IDs.`, { exit: 1 }); } const limit = (0, commandUtils_1.parsePositiveIntOption)(options.limit, "--limit", { defaultValue: DEFAULT_LIMIT, max: MAX_LIMIT, }); const maxFrames = (0, commandUtils_1.parsePositiveIntOption)(options.maxFrames, "--max-frames", { defaultValue: events_1.DEFAULT_MAX_FRAMES, }); const filterExpression = typeof options.filter === "string" ? options.filter.trim() || undefined : undefined; let response; try { response = await (0, events_1.listEvents)(appId, filter, limit, filterExpression); } catch (err) { const status = (0, error_1.getErrStatus)(err); const message = (0, error_1.getErrMsg)(err); if (filterExpression && (status === 400 || message.includes("INVALID_ARGUMENT"))) { throw new error_1.FirebaseError(`${message}\nSee 'firebase crashlytics:events:list --help' for --filter syntax and examples.`, { exit: 1, status, original: (0, error_1.getError)(err) }); } throw err; } if (!(await (0, commandUtils_1.writeOutputFileIfRequested)(response, options))) { const events = response.events || []; if (events.length === 0) { logger_1.logger.info("No matching events found."); } else { const formatted = events.map((e) => (0, events_1.toText)(e, { maxFrames, full: Boolean(options.full) })); logger_1.logger.info((0, js_yaml_1.dump)(formatted, events_1.EVENT_DUMP_OPTIONS)); } } return response; });