UNPKG

@us-legal-tools/ecfr-sdk

Version:

TypeScript SDK and MCP server for the eCFR (Electronic Code of Federal Regulations) API

542 lines (537 loc) 20.8 kB
var __create = Object.create; var __getProtoOf = Object.getPrototypeOf; var __defProp = Object.defineProperty; var __getOwnPropNames = Object.getOwnPropertyNames; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __hasOwnProp = Object.prototype.hasOwnProperty; var __toESM = (mod, isNodeMode, target) => { target = mod != null ? __create(__getProtoOf(mod)) : {}; const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target; for (let key of __getOwnPropNames(mod)) if (!__hasOwnProp.call(to, key)) __defProp(to, key, { get: () => mod[key], enumerable: true }); return to; }; var __moduleCache = /* @__PURE__ */ new WeakMap; var __toCommonJS = (from) => { var entry = __moduleCache.get(from), desc; if (entry) return entry; entry = __defProp({}, "__esModule", { value: true }); if (from && typeof from === "object" || typeof from === "function") __getOwnPropNames(from).map((key) => !__hasOwnProp.call(entry, key) && __defProp(entry, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable })); __moduleCache.set(from, entry); return entry; }; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true, configurable: true, set: (newValue) => all[name] = () => newValue }); }; // src/mcp/index.ts var exports_mcp = {}; __export(exports_mcp, { getApiVersionerV1VersionsTitleTitleJsonHandler: () => getApiVersionerV1VersionsTitleTitleJsonHandler, getApiVersionerV1TitlesJsonHandler: () => getApiVersionerV1TitlesJsonHandler, getApiVersionerV1StructureDateTitleTitleJsonHandler: () => getApiVersionerV1StructureDateTitleTitleJsonHandler, getApiVersionerV1FullDateTitleTitleXmlHandler: () => getApiVersionerV1FullDateTitleTitleXmlHandler, getApiVersionerV1AncestryDateTitleTitleJsonHandler: () => getApiVersionerV1AncestryDateTitleTitleJsonHandler, getApiSearchV1SummaryHandler: () => getApiSearchV1SummaryHandler, getApiSearchV1SuggestionsHandler: () => getApiSearchV1SuggestionsHandler, getApiSearchV1ResultsHandler: () => getApiSearchV1ResultsHandler, getApiSearchV1CountsTitlesHandler: () => getApiSearchV1CountsTitlesHandler, getApiSearchV1CountsHierarchyHandler: () => getApiSearchV1CountsHierarchyHandler, getApiSearchV1CountsDailyHandler: () => getApiSearchV1CountsDailyHandler, getApiSearchV1CountHandler: () => getApiSearchV1CountHandler, getApiAdminV1CorrectionsTitleTitleJsonHandler: () => getApiAdminV1CorrectionsTitleTitleJsonHandler, getApiAdminV1CorrectionsJsonHandler: () => getApiAdminV1CorrectionsJsonHandler, getApiAdminV1AgenciesJsonHandler: () => getApiAdminV1AgenciesJsonHandler, GetApiSearchV1ResultsPaginateBy: () => GetApiSearchV1ResultsPaginateBy, GetApiSearchV1ResultsOrder: () => GetApiSearchV1ResultsOrder }); module.exports = __toCommonJS(exports_mcp); // src/mcp/http-client.ts var getGetApiAdminV1AgenciesJsonUrl = () => { return `https://www.ecfr.gov/api/admin/v1/agencies.json`; }; var getApiAdminV1AgenciesJson = async (options) => { const res = await fetch(getGetApiAdminV1AgenciesJsonUrl(), { ...options, method: "GET" }); const body = [204, 205, 304].includes(res.status) ? null : await res.text(); const data = body ? JSON.parse(body) : {}; return { data, status: res.status, headers: res.headers }; }; var getGetApiAdminV1CorrectionsJsonUrl = (params) => { const normalizedParams = new URLSearchParams; Object.entries(params || {}).forEach(([key, value]) => { if (value !== undefined) { normalizedParams.append(key, value === null ? "null" : value.toString()); } }); const stringifiedParams = normalizedParams.toString(); return stringifiedParams.length > 0 ? `https://www.ecfr.gov/api/admin/v1/corrections.json?${stringifiedParams}` : `https://www.ecfr.gov/api/admin/v1/corrections.json`; }; var getApiAdminV1CorrectionsJson = async (params, options) => { const res = await fetch(getGetApiAdminV1CorrectionsJsonUrl(params), { ...options, method: "GET" }); const body = [204, 205, 304].includes(res.status) ? null : await res.text(); const data = body ? JSON.parse(body) : {}; return { data, status: res.status, headers: res.headers }; }; var getGetApiAdminV1CorrectionsTitleTitleJsonUrl = (title) => { return `https://www.ecfr.gov/api/admin/v1/corrections/title/${title}.json`; }; var getApiAdminV1CorrectionsTitleTitleJson = async (title, options) => { const res = await fetch(getGetApiAdminV1CorrectionsTitleTitleJsonUrl(title), { ...options, method: "GET" }); const body = [204, 205, 304].includes(res.status) ? null : await res.text(); const data = body ? JSON.parse(body) : {}; return { data, status: res.status, headers: res.headers }; }; var getGetApiSearchV1ResultsUrl = (params) => { const normalizedParams = new URLSearchParams; Object.entries(params || {}).forEach(([key, value]) => { const explodeParameters = ["agency_slugs[]"]; if (value instanceof Array && explodeParameters.includes(key)) { value.forEach((v) => normalizedParams.append(key, v === null ? "null" : v.toString())); return; } if (value !== undefined) { normalizedParams.append(key, value === null ? "null" : value.toString()); } }); const stringifiedParams = normalizedParams.toString(); return stringifiedParams.length > 0 ? `https://www.ecfr.gov/api/search/v1/results?${stringifiedParams}` : `https://www.ecfr.gov/api/search/v1/results`; }; var getApiSearchV1Results = async (params, options) => { const res = await fetch(getGetApiSearchV1ResultsUrl(params), { ...options, method: "GET" }); const body = [204, 205, 304].includes(res.status) ? null : await res.text(); const data = body ? JSON.parse(body) : {}; return { data, status: res.status, headers: res.headers }; }; var getGetApiSearchV1CountUrl = (params) => { const normalizedParams = new URLSearchParams; Object.entries(params || {}).forEach(([key, value]) => { const explodeParameters = ["agency_slugs[]"]; if (value instanceof Array && explodeParameters.includes(key)) { value.forEach((v) => normalizedParams.append(key, v === null ? "null" : v.toString())); return; } if (value !== undefined) { normalizedParams.append(key, value === null ? "null" : value.toString()); } }); const stringifiedParams = normalizedParams.toString(); return stringifiedParams.length > 0 ? `https://www.ecfr.gov/api/search/v1/count?${stringifiedParams}` : `https://www.ecfr.gov/api/search/v1/count`; }; var getApiSearchV1Count = async (params, options) => { const res = await fetch(getGetApiSearchV1CountUrl(params), { ...options, method: "GET" }); const body = [204, 205, 304].includes(res.status) ? null : await res.text(); const data = body ? JSON.parse(body) : {}; return { data, status: res.status, headers: res.headers }; }; var getGetApiSearchV1SummaryUrl = (params) => { const normalizedParams = new URLSearchParams; Object.entries(params || {}).forEach(([key, value]) => { const explodeParameters = ["agency_slugs[]"]; if (value instanceof Array && explodeParameters.includes(key)) { value.forEach((v) => normalizedParams.append(key, v === null ? "null" : v.toString())); return; } if (value !== undefined) { normalizedParams.append(key, value === null ? "null" : value.toString()); } }); const stringifiedParams = normalizedParams.toString(); return stringifiedParams.length > 0 ? `https://www.ecfr.gov/api/search/v1/summary?${stringifiedParams}` : `https://www.ecfr.gov/api/search/v1/summary`; }; var getApiSearchV1Summary = async (params, options) => { const res = await fetch(getGetApiSearchV1SummaryUrl(params), { ...options, method: "GET" }); const body = [204, 205, 304].includes(res.status) ? null : await res.text(); const data = body ? JSON.parse(body) : {}; return { data, status: res.status, headers: res.headers }; }; var getGetApiSearchV1CountsDailyUrl = (params) => { const normalizedParams = new URLSearchParams; Object.entries(params || {}).forEach(([key, value]) => { const explodeParameters = ["agency_slugs[]"]; if (value instanceof Array && explodeParameters.includes(key)) { value.forEach((v) => normalizedParams.append(key, v === null ? "null" : v.toString())); return; } if (value !== undefined) { normalizedParams.append(key, value === null ? "null" : value.toString()); } }); const stringifiedParams = normalizedParams.toString(); return stringifiedParams.length > 0 ? `https://www.ecfr.gov/api/search/v1/counts/daily?${stringifiedParams}` : `https://www.ecfr.gov/api/search/v1/counts/daily`; }; var getApiSearchV1CountsDaily = async (params, options) => { const res = await fetch(getGetApiSearchV1CountsDailyUrl(params), { ...options, method: "GET" }); const body = [204, 205, 304].includes(res.status) ? null : await res.text(); const data = body ? JSON.parse(body) : {}; return { data, status: res.status, headers: res.headers }; }; var getGetApiSearchV1CountsTitlesUrl = (params) => { const normalizedParams = new URLSearchParams; Object.entries(params || {}).forEach(([key, value]) => { const explodeParameters = ["agency_slugs[]"]; if (value instanceof Array && explodeParameters.includes(key)) { value.forEach((v) => normalizedParams.append(key, v === null ? "null" : v.toString())); return; } if (value !== undefined) { normalizedParams.append(key, value === null ? "null" : value.toString()); } }); const stringifiedParams = normalizedParams.toString(); return stringifiedParams.length > 0 ? `https://www.ecfr.gov/api/search/v1/counts/titles?${stringifiedParams}` : `https://www.ecfr.gov/api/search/v1/counts/titles`; }; var getApiSearchV1CountsTitles = async (params, options) => { const res = await fetch(getGetApiSearchV1CountsTitlesUrl(params), { ...options, method: "GET" }); const body = [204, 205, 304].includes(res.status) ? null : await res.text(); const data = body ? JSON.parse(body) : {}; return { data, status: res.status, headers: res.headers }; }; var getGetApiSearchV1CountsHierarchyUrl = (params) => { const normalizedParams = new URLSearchParams; Object.entries(params || {}).forEach(([key, value]) => { const explodeParameters = ["agency_slugs[]"]; if (value instanceof Array && explodeParameters.includes(key)) { value.forEach((v) => normalizedParams.append(key, v === null ? "null" : v.toString())); return; } if (value !== undefined) { normalizedParams.append(key, value === null ? "null" : value.toString()); } }); const stringifiedParams = normalizedParams.toString(); return stringifiedParams.length > 0 ? `https://www.ecfr.gov/api/search/v1/counts/hierarchy?${stringifiedParams}` : `https://www.ecfr.gov/api/search/v1/counts/hierarchy`; }; var getApiSearchV1CountsHierarchy = async (params, options) => { const res = await fetch(getGetApiSearchV1CountsHierarchyUrl(params), { ...options, method: "GET" }); const body = [204, 205, 304].includes(res.status) ? null : await res.text(); const data = body ? JSON.parse(body) : {}; return { data, status: res.status, headers: res.headers }; }; var getGetApiSearchV1SuggestionsUrl = (params) => { const normalizedParams = new URLSearchParams; Object.entries(params || {}).forEach(([key, value]) => { const explodeParameters = ["agency_slugs[]"]; if (value instanceof Array && explodeParameters.includes(key)) { value.forEach((v) => normalizedParams.append(key, v === null ? "null" : v.toString())); return; } if (value !== undefined) { normalizedParams.append(key, value === null ? "null" : value.toString()); } }); const stringifiedParams = normalizedParams.toString(); return stringifiedParams.length > 0 ? `https://www.ecfr.gov/api/search/v1/suggestions?${stringifiedParams}` : `https://www.ecfr.gov/api/search/v1/suggestions`; }; var getApiSearchV1Suggestions = async (params, options) => { const res = await fetch(getGetApiSearchV1SuggestionsUrl(params), { ...options, method: "GET" }); const body = [204, 205, 304].includes(res.status) ? null : await res.text(); const data = body ? JSON.parse(body) : {}; return { data, status: res.status, headers: res.headers }; }; var getGetApiVersionerV1AncestryDateTitleTitleJsonUrl = (date, title, params) => { const normalizedParams = new URLSearchParams; Object.entries(params || {}).forEach(([key, value]) => { if (value !== undefined) { normalizedParams.append(key, value === null ? "null" : value.toString()); } }); const stringifiedParams = normalizedParams.toString(); return stringifiedParams.length > 0 ? `https://www.ecfr.gov/api/versioner/v1/ancestry/${date}/title-${title}.json?${stringifiedParams}` : `https://www.ecfr.gov/api/versioner/v1/ancestry/${date}/title-${title}.json`; }; var getApiVersionerV1AncestryDateTitleTitleJson = async (date, title, params, options) => { const res = await fetch(getGetApiVersionerV1AncestryDateTitleTitleJsonUrl(date, title, params), { ...options, method: "GET" }); const body = [204, 205, 304].includes(res.status) ? null : await res.text(); const data = body ? JSON.parse(body) : {}; return { data, status: res.status, headers: res.headers }; }; var getGetApiVersionerV1FullDateTitleTitleXmlUrl = (date, title, params) => { const normalizedParams = new URLSearchParams; Object.entries(params || {}).forEach(([key, value]) => { if (value !== undefined) { normalizedParams.append(key, value === null ? "null" : value.toString()); } }); const stringifiedParams = normalizedParams.toString(); return stringifiedParams.length > 0 ? `https://www.ecfr.gov/api/versioner/v1/full/${date}/title-${title}.xml?${stringifiedParams}` : `https://www.ecfr.gov/api/versioner/v1/full/${date}/title-${title}.xml`; }; var getApiVersionerV1FullDateTitleTitleXml = async (date, title, params, options) => { const res = await fetch(getGetApiVersionerV1FullDateTitleTitleXmlUrl(date, title, params), { ...options, method: "GET" }); const body = [204, 205, 304].includes(res.status) ? null : await res.text(); const data = body ? JSON.parse(body) : {}; return { data, status: res.status, headers: res.headers }; }; var getGetApiVersionerV1StructureDateTitleTitleJsonUrl = (date, title) => { return `https://www.ecfr.gov/api/versioner/v1/structure/${date}/title-${title}.json`; }; var getApiVersionerV1StructureDateTitleTitleJson = async (date, title, options) => { const res = await fetch(getGetApiVersionerV1StructureDateTitleTitleJsonUrl(date, title), { ...options, method: "GET" }); const body = [204, 205, 304].includes(res.status) ? null : await res.text(); const data = body ? JSON.parse(body) : {}; return { data, status: res.status, headers: res.headers }; }; var getGetApiVersionerV1TitlesJsonUrl = () => { return `https://www.ecfr.gov/api/versioner/v1/titles.json`; }; var getApiVersionerV1TitlesJson = async (options) => { const res = await fetch(getGetApiVersionerV1TitlesJsonUrl(), { ...options, method: "GET" }); const body = [204, 205, 304].includes(res.status) ? null : await res.text(); const data = body ? JSON.parse(body) : {}; return { data, status: res.status, headers: res.headers }; }; var getGetApiVersionerV1VersionsTitleTitleJsonUrl = (title, params) => { const normalizedParams = new URLSearchParams; Object.entries(params || {}).forEach(([key, value]) => { if (value !== undefined) { normalizedParams.append(key, value === null ? "null" : value.toString()); } }); const stringifiedParams = normalizedParams.toString(); return stringifiedParams.length > 0 ? `https://www.ecfr.gov/api/versioner/v1/versions/title-${title}.json?${stringifiedParams}` : `https://www.ecfr.gov/api/versioner/v1/versions/title-${title}.json`; }; var getApiVersionerV1VersionsTitleTitleJson = async (title, params, options) => { const res = await fetch(getGetApiVersionerV1VersionsTitleTitleJsonUrl(title, params), { ...options, method: "GET" }); const body = [204, 205, 304].includes(res.status) ? null : await res.text(); const data = body ? JSON.parse(body) : {}; return { data, status: res.status, headers: res.headers }; }; // src/mcp/handlers.ts var getApiAdminV1AgenciesJsonHandler = async () => { const res = await getApiAdminV1AgenciesJson(); return { content: [ { type: "text", text: JSON.stringify(res) } ] }; }; var getApiAdminV1CorrectionsJsonHandler = async (args) => { const res = await getApiAdminV1CorrectionsJson(args.queryParams); return { content: [ { type: "text", text: JSON.stringify(res) } ] }; }; var getApiAdminV1CorrectionsTitleTitleJsonHandler = async (args) => { const res = await getApiAdminV1CorrectionsTitleTitleJson(args.pathParams.title); return { content: [ { type: "text", text: JSON.stringify(res) } ] }; }; var getApiSearchV1ResultsHandler = async (args) => { const res = await getApiSearchV1Results(args.queryParams); return { content: [ { type: "text", text: JSON.stringify(res) } ] }; }; var getApiSearchV1CountHandler = async (args) => { const res = await getApiSearchV1Count(args.queryParams); return { content: [ { type: "text", text: JSON.stringify(res) } ] }; }; var getApiSearchV1SummaryHandler = async (args) => { const res = await getApiSearchV1Summary(args.queryParams); return { content: [ { type: "text", text: JSON.stringify(res) } ] }; }; var getApiSearchV1CountsDailyHandler = async (args) => { const res = await getApiSearchV1CountsDaily(args.queryParams); return { content: [ { type: "text", text: JSON.stringify(res) } ] }; }; var getApiSearchV1CountsTitlesHandler = async (args) => { const res = await getApiSearchV1CountsTitles(args.queryParams); return { content: [ { type: "text", text: JSON.stringify(res) } ] }; }; var getApiSearchV1CountsHierarchyHandler = async (args) => { const res = await getApiSearchV1CountsHierarchy(args.queryParams); return { content: [ { type: "text", text: JSON.stringify(res) } ] }; }; var getApiSearchV1SuggestionsHandler = async (args) => { const res = await getApiSearchV1Suggestions(args.queryParams); return { content: [ { type: "text", text: JSON.stringify(res) } ] }; }; var getApiVersionerV1AncestryDateTitleTitleJsonHandler = async (args) => { const res = await getApiVersionerV1AncestryDateTitleTitleJson(args.pathParams.date, args.pathParams.title, args.queryParams); return { content: [ { type: "text", text: JSON.stringify(res) } ] }; }; var getApiVersionerV1FullDateTitleTitleXmlHandler = async (args) => { const res = await getApiVersionerV1FullDateTitleTitleXml(args.pathParams.date, args.pathParams.title, args.queryParams); return { content: [ { type: "text", text: JSON.stringify(res) } ] }; }; var getApiVersionerV1StructureDateTitleTitleJsonHandler = async (args) => { const res = await getApiVersionerV1StructureDateTitleTitleJson(args.pathParams.date, args.pathParams.title); return { content: [ { type: "text", text: JSON.stringify(res) } ] }; }; var getApiVersionerV1TitlesJsonHandler = async () => { const res = await getApiVersionerV1TitlesJson(); return { content: [ { type: "text", text: JSON.stringify(res) } ] }; }; var getApiVersionerV1VersionsTitleTitleJsonHandler = async (args) => { const res = await getApiVersionerV1VersionsTitleTitleJson(args.pathParams.title, args.queryParams); return { content: [ { type: "text", text: JSON.stringify(res) } ] }; }; // src/mcp/http-schemas/getApiSearchV1ResultsOrder.ts var GetApiSearchV1ResultsOrder = { citations: "citations", relevance: "relevance", hierarchy: "hierarchy", newest_first: "newest_first", oldest_first: "oldest_first", suggestions: "suggestions" }; // src/mcp/http-schemas/getApiSearchV1ResultsPaginateBy.ts var GetApiSearchV1ResultsPaginateBy = { date: "date", results: "results" }; //# debugId=167452842EAE07F864756E2164756E21 //# sourceMappingURL=index.js.map