UNPKG

firebase-tools

Version:
104 lines (103 loc) • 4.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.batch_get_events = exports.list_events = void 0; const js_yaml_1 = require("js-yaml"); const zod_1 = require("zod"); const events_1 = require("../../../crashlytics/events"); const filters_1 = require("../../../crashlytics/filters"); const app_id_1 = require("../../resources/guides/app_id"); const tool_1 = require("../../tool"); exports.list_events = (0, tool_1.tool)("crashlytics", { name: "list_events", description: `Use this to list the most recent events matching the given filters, including custom key filter expressions. Can be used to fetch sample crashes and exceptions for an issue, which will include stack traces and other data useful for debugging.`, humanReadableDescription: "List recent crash and exception events matching specified filters for an issue.", inputSchema: zod_1.z.object({ appId: filters_1.ApplicationIdSchema, filter: filters_1.EventFilterSchema, filterExpression: filters_1.FilterExpressionSchema, pageSize: zod_1.z.number().describe("Number of rows to return").default(1), }), annotations: { title: "List Crashlytics Events", readOnlyHint: true, }, _meta: { requiresAuth: true, }, }, async ({ appId, filter, filterExpression, pageSize }) => { const result = { content: [] }; if (!appId) { result.isError = true; result.content.push({ type: "text", text: "Must specify 'appId' parameter" }); result.content.push({ type: "text", text: app_id_1.RESOURCE_CONTENT }); } if (!filter || (!filter.issueId && !filter.issueVariantId)) { result.isError = true; result.content.push({ type: "text", text: `Must specify 'filter.issueId' or 'filter.issueVariantId' parameters.`, }); } else { try { filter = (0, filters_1.validateEventFilters)(filter, appId); } catch (error) { const message = error instanceof Error ? error.message : String(error); result.isError = true; result.content.push({ type: "text", text: `Error: ${message}` }); } } if (result.content.length > 0) { return result; } const response = await (0, events_1.listEvents)(appId, filter, pageSize, filterExpression); const eventsContent = response.events?.map((e) => (0, events_1.toText)(e)) || []; return { content: [{ type: "text", text: (0, js_yaml_1.dump)(eventsContent, events_1.EVENT_DUMP_OPTIONS) }], }; }); exports.batch_get_events = (0, tool_1.tool)("crashlytics", { name: "batch_get_events", description: `Gets specific events by resource name. Can be used to fetch sample crashes and exceptions for an issue, which will include stack traces and other data useful for debugging.`, humanReadableDescription: "Retrieve sample crash and exception events by resource name for debugging.", inputSchema: zod_1.z.object({ appId: filters_1.ApplicationIdSchema, names: zod_1.z .array(zod_1.z.string()) .describe("An array of the event resource names, as found in the sampleEvent field in reports."), }), annotations: { title: "Batch Get Crashlytics Events", readOnlyHint: true, }, _meta: { requiresAuth: true, }, }, async ({ appId, names }) => { const result = { content: [] }; if (!appId) { result.isError = true; result.content.push({ type: "text", text: "Must specify 'appId' parameter." }); result.content.push({ type: "text", text: app_id_1.RESOURCE_CONTENT }); } if (!names || names.length === 0) { result.isError = true; result.content.push({ type: "text", text: "Must provide event resource names in name parameter.", }); } if (result.content.length > 0) { return result; } const response = await (0, events_1.batchGetEvents)(appId, names); const eventsContent = response.events?.map((e) => (0, events_1.toText)(e)) || []; return { content: [{ type: "text", text: (0, js_yaml_1.dump)(eventsContent, events_1.EVENT_DUMP_OPTIONS) }], }; });