UNPKG

@jupiterone/jupiterone-mcp

Version:

Model Context Protocol server for JupiterOne account rules and rule details

130 lines 4.9 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.RuleService = void 0; const queries_js_1 = require("../graphql/queries.js"); const mutations_js_1 = require("../graphql/mutations.js"); const appUrl_js_1 = require("../../utils/appUrl.js"); class RuleService { client; constructor(client) { this.client = client; } /** * Construct rule URL based on subdomain */ constructRuleUrl(ruleId, subdomain) { return (0, appUrl_js_1.constructAppUrl)(`rules/${ruleId}/history`, subdomain); } /** * List rule instances using the new GraphQL query */ async listRuleInstances(limit, cursor, filters) { const variables = {}; if (limit) variables.limit = limit; if (cursor) variables.cursor = cursor; if (filters) variables.filters = filters; const response = await this.client.request(queries_js_1.LIST_RULE_INSTANCES, variables); return response.listRuleInstances; } /** * Get all rule instances by paginating through all pages */ async getAllRuleInstances(filters) { const allInstances = []; let cursor = null; let hasNextPage = true; while (hasNextPage) { const response = await this.listRuleInstances(100, cursor || undefined, filters); if (!response?.questionInstances) { console.error('Unexpected response structure:', response); break; } allInstances.push(...response.questionInstances); cursor = response.pageInfo.endCursor; hasNextPage = response.pageInfo.hasNextPage; } return allInstances; } /** * Create an inline question rule instance */ async createInlineQuestionRuleInstance(instance) { const response = await this.client.request(mutations_js_1.CREATE_INLINE_QUESTION_RULE, { instance }); return response.createInlineQuestionRuleInstance; } /** * Update an inline question rule instance */ async updateInlineQuestionRuleInstance(instance) { const response = await this.client.request(mutations_js_1.UPDATE_INLINE_QUESTION_RULE, { instance }); return response.updateInlineQuestionRuleInstance; } /** * Trigger an alert rule on demand */ async evaluateRuleInstance(id) { const response = await this.client.request(mutations_js_1.EVALUATE_RULE, { id }); return response.evaluateRuleInstance; } /** * List rule evaluations for a specific rule instance */ async listRuleEvaluations(filters) { const response = await this.client.request(queries_js_1.LIST_RULE_EVALUATIONS, filters); return response.listCollectionResults; } /** * Get all rule evaluations for a specific rule instance by paginating through all pages */ async getAllRuleEvaluations(filters) { const allEvaluations = []; let cursor = null; let hasNextPage = true; while (hasNextPage) { const response = await this.listRuleEvaluations({ collectionType: filters.collectionType, collectionOwnerId: filters.collectionOwnerId, beginTimestamp: filters.beginTimestamp, endTimestamp: filters.endTimestamp, limit: filters.limit, tag: filters.tag, cursor: cursor || undefined, }); if (!response?.results) { console.error('Unexpected response structure:', response); break; } allEvaluations.push(...response.results); cursor = response.pageInfo.endCursor; hasNextPage = response.pageInfo.hasNextPage; } return allEvaluations; } /** * Get detailed information about a specific rule evaluation */ async getRuleEvaluationDetails(input) { const response = await this.client.request(queries_js_1.GET_RULE_EVALUATION_DETAILS, { ruleEvaluationDetailsInput: input }); return response.ruleEvaluationDetails; } /** * Get a download URL for raw data associated with a rule evaluation */ async getRawDataDownloadUrl(rawDataKey) { const response = await this.client.request(queries_js_1.GET_RAW_DATA_DOWNLOAD_URL, { rawDataKey }); return response.getRawDataDownloadUrl; } async getRawDataResults(rawDataKey) { const downloadUrl = await this.getRawDataDownloadUrl(rawDataKey); const response = await fetch(downloadUrl); if (!response.ok) { throw new Error(`Failed to fetch query results: ${response.statusText}`); } return response.json(); } } exports.RuleService = RuleService; //# sourceMappingURL=rule-service.js.map