UNPKG

congress-dot-gov

Version:
1,333 lines (1,312 loc) 60.1 kB
import 'whatwg-fetch'; class RateLimitExceededError extends Error { statusCode; rateLimit; constructor(message, statusCode = 429, rateLimit) { super(message); this.name = "RateLimitExceededError"; this.statusCode = statusCode; this.rateLimit = rateLimit || { limit: 0, remaining: 0 }; } } class CongressGovApiError extends Error { statusCode; endpoint; data; constructor(message, statusCode, endpoint) { const errorMessage = typeof message === "string" ? message : JSON.stringify(message); super(errorMessage); this.name = "CongressGovApiError"; this.statusCode = statusCode; this.endpoint = endpoint; this.data = typeof message === "string" ? void 0 : message; } } class CongressGovSdkError extends Error { constructor(message) { super(message); this.name = "CongressGovSdkError"; } } class CongressGovURLSearchParams { _params; constructor(params) { this._params = params; } get params() { return Object.fromEntries( Object.entries(this._params).reduce( (acc, [key, value]) => { if (value !== void 0) { if (key === "fromDateTime" || key === "toDateTime") { acc.push([key, this.formatDateTime(value)]); } else { acc.push([key, value.toString()]); } } return acc; }, [] ) ); } formatDateTime(date) { if (typeof date === "string") { date = new Date(date); } return date.toISOString().slice(0, 19) + "Z"; } toUrlSearchParams() { return new URLSearchParams(this.params).toString(); } } class BaseClient { apiKey; baseUrl; endpoint; constructor({ apiKey, endpoint = "" }) { if (!apiKey) { throw new CongressGovSdkError("API key is required"); } this.apiKey = apiKey; this.baseUrl = `https://api.congress.gov`; this.endpoint = endpoint; } async get(endpoint, params) { const searchParams = new CongressGovURLSearchParams(params); const url = new URL(`/v3${this.endpoint}${endpoint}`, this.baseUrl); url.search = searchParams.toUrlSearchParams(); const response = await fetch(url, { headers: { "X-API-Key": this.apiKey, "Content-Type": "application/json" } }); const rateLimit = { limit: parseInt(response.headers.get("x-ratelimit-limit") || "0"), remaining: parseInt(response.headers.get("x-ratelimit-remaining") || "0") }; const data = await response.json(); if (!response.ok) { if (response.status === 429) { throw new RateLimitExceededError( "Rate limit exceeded. Please try again later.", response.status, rateLimit ); } throw new CongressGovApiError(data, response.status, endpoint); } return { ...data, rateLimit }; } } class AmendmentClient extends BaseClient { constructor({ apiKey }) { super({ apiKey, endpoint: "/amendment" }); } /** * Returns a list of amendments sorted by date of latest action. * @param params {PaginationParams & DateFilterParams} - Accepts pagination, date range filter, and format parameters * @returns A list of amendments sorted by date of latest action */ async getAmendments(params = {}) { return this.get("", params); } /** * Returns a list of amendments filtered by the specified congress, sorted by date of latest action. * @param congress - The Congress number (e.g., 117) * @param params {PaginationParams & DateFilterParams} - Accepts pagination, date range filter, and format parameters * @returns List of amendments filtered by the specified congress, sorted by date of latest action */ async getAmendmentsByCongress(congress, params = {}) { return this.get( `/${congress}`, params ); } /** * Returns a list of amendments filtered by the specified congress and amendment type, sorted by date of latest action. * @param congress - The Congress number (e.g., 117) * @param amendmentType - The type of amendment (samdt or hamdt) * @param params {PaginationParams & DateFilterParams} - Accepts pagination, date range filter, and format parameters * @returns List of amendments filtered by the specified congress and amendment type */ async getAmendmentsByCongressAndType(congress, amendmentType, params = {}) { return this.get( `/${congress}/${amendmentType.toLowerCase()}`, params ); } /** * Returns detailed information for a specified amendment. * @param congress - The Congress number (e.g., 117) * @param amendmentType - The type of amendment (samdt or hamdt) * @param amendmentNumber - The amendment number * @param params {BaseParams} - Accepts format parameter (json or xml) * @returns Detailed information for the specified amendment */ async getAmendment(congress, amendmentType, amendmentNumber, params = {}) { return this.get( `/${congress}/${amendmentType.toLowerCase()}/${amendmentNumber}`, params ); } /** * Returns the list of actions on a specified amendment. * @param congress - The Congress number (e.g., 117) * @param amendmentType - The type of amendment (samdt or hamdt) * @param amendmentNumber - The amendment number * @param params {PaginationParams} - Accepts pagination and format parameters * @returns List of actions on the specified amendment */ async getAmendmentActions(congress, amendmentType, amendmentNumber, params = {}) { return this.get( `/${congress}/${amendmentType.toLowerCase()}/${amendmentNumber}/actions`, params ); } /** * Returns the list of cosponsors on a specified amendment. * @param congress - The Congress number (e.g., 117) * @param amendmentType - The type of amendment (samdt or hamdt) * @param amendmentNumber - The amendment number * @param params {PaginationParams} - Accepts pagination and formatparameters * @returns List of cosponsors on the specified amendment */ async getAmendmentCosponsors(congress, amendmentType, amendmentNumber, params = {}) { return this.get( `/${congress}/${amendmentType.toLowerCase()}/${amendmentNumber}/cosponsors`, params ); } /** * Returns the list of amendments to a specified amendment. * @param congress - The Congress number (e.g., 117) * @param amendmentType - The type of amendment (samdt or hamdt) * @param amendmentNumber - The amendment number * @param params {PaginationParams} - Accepts pagination and format parameters * @returns List of amendments to the specified amendment */ async getAmendmentAmendments(congress, amendmentType, amendmentNumber, params = {}) { return this.get( `/${congress}/${amendmentType.toLowerCase()}/${amendmentNumber}/amendments`, params ); } /** * Returns the list of text versions for a specified amendment from the 117th Congress onwards. * @param congress - The Congress number (e.g., 117) * @param amendmentType - The type of amendment (samdt or hamdt) * @param amendmentNumber - The amendment number * @param params {PaginationParams} - Accepts pagination and format parameters * @returns List of text versions for the specified amendment */ async getAmendmentText(congress, amendmentType, amendmentNumber, params = {}) { return this.get( `/${congress}/${amendmentType.toLowerCase()}/${amendmentNumber}/text`, params ); } } class BillClient extends BaseClient { constructor({ apiKey }) { super({ apiKey }); } /** * Returns a list of bills sorted by date of latest action. * @param params {PaginationParams & DateFilterParams & SortParams} - Accepts pagination, date range filter, sort, and format parameters * @returns A list of bills sorted by date of latest action */ async getBills(params = {}) { return this.get("/bill", params); } /** * Returns a list of bills filtered by the specified congress, sorted by date of latest action. * @param congress - The Congress number (e.g., 117) * @param params {PaginationParams & DateFilterParams & SortParams} - Accepts pagination, date range filter, sort, and format parameters * @returns Returns a list of bills filtered by the specified congress, sorted by date of latest action. */ async getBillsByCongress(congress, params = {}) { return this.get( `/bill/${congress}`, params ); } /** * Returns a list of bills filtered by the specified congress and bill type, sorted by date of latest action. * @param congress - The Congress number (e.g., 117) * @param billType - The type of bill. Value can be hr, s, hjres, sjres, hconres, sconres, hres, or sres. * @param params {PaginationParams & DateFilterParams & SortParams} - Accepts pagination, date range filter, sort, and format parameters * @returns List of bills filtered by the specified congress and bill type, sorted by date of latest action. */ async getBillsByCongressAndType(congress, billType, params = {}) { return this.get( `/bill/${congress}/${billType.toLowerCase()}`, params ); } /** * Returns detailed information for a specified bill. * @param congress - The Congress number (e.g., 117) * @param billType - The type of bill. Value can be hr, s, hjres, sjres, hconres, sconres, hres, or sres. * @param billNumber - The bill number * @param params {BaseParams} - Accepts format parameter (json or xml) * @returns Detailed information for a specified bill. */ async getBill(congress, billType, billNumber, params = {}) { return this.get( `/bill/${congress}/${billType.toLowerCase()}/${billNumber}`, params ); } /** * Returns the list of actions on a specified bill. * @param congress - The Congress number (e.g., 117) * @param billType - The type of bill * @param billNumber - The bill number * @param params {PaginationParams} - Accepts pagination and format parameters * @returns List of actions on the specified bill */ async getBillActions(congress, billType, billNumber, params = {}) { return this.get( `/bill/${congress}/${billType.toLowerCase()}/${billNumber}/actions`, params ); } /** * Returns the list of amendments to a specified bill. * @param congress - The Congress number (e.g., 117) * @param billType - The type of bill * @param billNumber - The bill number * @param params {PaginationParams} - Accepts pagination and format parameters * @returns List of amendments to the specified bill */ async getBillAmendments(congress, billType, billNumber, params = {}) { return this.get( `/bill/${congress}/${billType.toLowerCase()}/${billNumber}/amendments`, params ); } /** * Returns the list of committees associated with a specified bill. * @param congress - The Congress number (e.g., 117) * @param billType - The type of bill * @param billNumber - The bill number * @param params {PaginationParams} - Accepts pagination and format parameters * @returns List of committees associated with the specified bill */ async getBillCommittees(congress, billType, billNumber, params = {}) { return this.get( `/bill/${congress}/${billType.toLowerCase()}/${billNumber}/committees`, params ); } /** * Returns the list of cosponsors on a specified bill. * @param congress - The Congress number (e.g., 117) * @param billType - The type of bill * @param billNumber - The bill number * @param params {PaginationParams & DateFilterParams & SortParams} - Accepts pagination, date range filter, sort, and format parameters * @returns List of cosponsors on the specified bill */ async getBillCosponsors(congress, billType, billNumber, params = {}) { return this.get( `/bill/${congress}/${billType.toLowerCase()}/${billNumber}/cosponsors`, params ); } /** * Returns the list of related bills to a specified bill. * @param congress - The Congress number (e.g., 117) * @param billType - The type of bill * @param billNumber - The bill number * @param params {PaginationParams} - Accepts pagination and format parameters * @returns List of related bills to the specified bill */ async getRelatedBills(congress, billType, billNumber, params = {}) { return this.get( `/bill/${congress}/${billType.toLowerCase()}/${billNumber}/relatedbills`, params ); } /** * Returns the list of legislative subjects on a specified bill. * @param congress - The Congress number (e.g., 117) * @param billType - The type of bill * @param billNumber - The bill number * @param params {PaginationParams & DateFilterParams} - Accepts pagination, date range filter, and format parameters * @returns List of legislative subjects on the specified bill */ async getBillSubjects(congress, billType, billNumber, params = {}) { return this.get( `/bill/${congress}/${billType.toLowerCase()}/${billNumber}/subjects`, params ); } /** * Returns the list of summaries for a specified bill. * @param congress - The Congress number (e.g., 117) * @param billType - The type of bill * @param billNumber - The bill number * @param params {PaginationParams} - Accepts pagination and format parameters * @returns List of summaries for the specified bill */ async getBillSummaries(congress, billType, billNumber, params = {}) { return this.get( `/bill/${congress}/${billType.toLowerCase()}/${billNumber}/summaries`, params ); } /** * Returns the list of text versions for a specified bill. * @param congress - The Congress number (e.g., 117) * @param billType - The type of bill * @param billNumber - The bill number * @param params {PaginationParams} - Accepts pagination and format parameters * @returns List of text versions for the specified bill */ async getBillText(congress, billType, billNumber, params = {}) { return this.get( `/bill/${congress}/${billType.toLowerCase()}/${billNumber}/text`, params ); } /** * Returns the list of titles for a specified bill. * @param congress - The Congress number (e.g., 117) * @param billType - The type of bill * @param billNumber - The bill number * @param params {PaginationParams & DateFilterParams} - Accepts pagination, date range filter, and format parameters * @returns List of titles for the specified bill */ async getBillTitles(congress, billType, billNumber, params = {}) { return this.get( `/bill/${congress}/${billType.toLowerCase()}/${billNumber}/titles`, params ); } /** * Returns a list of laws filtered by the specified congress. * @param congress - The Congress number (e.g., 117) * @param params {PaginationParams} - Accepts pagination and format parameters * @returns List of laws for the specified congress */ async getLaws(congress, params = {}) { return this.get(`/law/${congress}`, params); } /** * Returns a list of laws filtered by specified congress and law type. * @param congress - The Congress number (e.g., 117) * @param lawType - The type of law (public or private) * @param params {PaginationParams} - Accepts pagination and format parameters * @returns List of laws for the specified congress and law type */ async getLawsByType(congress, lawType, params = {}) { return this.get( `/law/${congress}/${lawType}`, params ); } /** * Returns a law filtered by specified congress, law type, and law number. * @param congress - The Congress number (e.g., 117) * @param lawType - The type of law (public or private) * @param lawNumber - The law number * @param params {PaginationParams} - Accepts pagination and format parameters * @returns The specified law */ async getLaw(congress, lawType, lawNumber, params = {}) { return this.get(`/law/${congress}/${lawType}/${lawNumber}`, params); } } class BoundCongressionalRecordClient extends BaseClient { constructor({ apiKey }) { super({ apiKey, endpoint: "/bound-congressional-record" }); } /** * Returns a list of bound Congressional Records sorted by most recent. * @param params {PaginationParams} - Pagination and format parameters * @returns A list of bound Congressional Records */ async getRecords(params = {}) { return this.get("", params); } /** * Returns a list of bound Congressional Records filtered by the specified year. * @param year - The year to filter by * @param params {PaginationParams} - Pagination and format parameters * @returns A list of bound Congressional Records for the specified year */ async getRecordsByYear(year, params = {}) { return this.get(`/${year}`, params); } /** * Returns a list of bound Congressional Records filtered by the specified year and month. * @param year - The year to filter by * @param month - The month to filter by (01-12) * @param params {PaginationParams} - Pagination and format parameters * @returns A list of bound Congressional Records for the specified year and month */ async getRecordsByYearAndMonth(year, month, params = {}) { return this.get(`/${year}/${month}`, params); } /** * Returns a list of bound Congressional Records filtered by the specified year, month, and day. * @param year - The year to filter by * @param month - The month to filter by (01-12) * @param day - The day to filter by (01-31) * @param params {PaginationParams} - Pagination and format parameters * @returns A list of bound Congressional Records for the specified date */ async getRecordsByDate(year, month, day, params = {}) { return this.get(`/${year}/${month}/${day}`, params); } } class CommitteeMeetingClient extends BaseClient { constructor({ apiKey }) { super({ apiKey, endpoint: "/committee-meeting" }); } /** * Returns a list of committee meetings. * @param params {PaginationParams} - Pagination parameters * @returns A list of committee meetings */ async getMeetings(params = {}) { return this.get("", params); } /** * Returns a list of committee meetings filtered by the specified congress. * @param congress - The congress to filter by * @param params {PaginationParams} - Pagination parameters * @returns A list of committee meetings for the specified congress */ async getMeetingsByCongress(congress, params = {}) { return this.get( `/${congress}`, params ); } /** * Returns a list of committee meetings filtered by the specified congress and chamber. * @param congress - The congress to filter by * @param chamber - The chamber to filter by * @param params {PaginationParams} - Pagination parameters * @returns A list of committee meetings for the specified congress and chamber */ async getMeetingsByCongressAndChamber(congress, chamber, params = {}) { return this.get( `/${congress}/${chamber.toLowerCase()}`, params ); } /** * Returns detailed information for a specified committee meeting. * @param congress - The congress of the meeting * @param chamber - The chamber of the meeting * @param eventId - The event ID of the meeting * @param params {PaginationParams} - Pagination parameters * @returns Detailed information for the specified committee meeting */ async getMeeting(congress, chamber, eventId, params = {}) { return this.get( `/${congress}/${chamber.toLowerCase()}/${eventId}`, params ); } } class CommitteePrintClient extends BaseClient { constructor({ apiKey }) { super({ apiKey, endpoint: "/committee-print" }); } /** * Returns a list of committee prints. * @param params {PaginationParams & DateFilterParams} - Accepts pagination, date range, and format parameters * @returns A list of committee prints */ async getPrints(params = {}) { return this.get("", params); } /** * Returns a list of committee prints filtered by the specified congress. * @param congress - The congress to filter by * @param params {PaginationParams & DateFilterParams} - Accepts pagination, date range, and format parameters * @returns A list of committee prints for the specified congress */ async getPrintsByCongress(congress, params = {}) { return this.get(`/${congress}`, params); } /** * Returns a list of committee prints filtered by the specified congress and chamber. * @param congress - The congress to filter by * @param chamber - The chamber to filter by * @param params {PaginationParams & DateFilterParams} - Accepts pagination, date range, and format parameters * @returns A list of committee prints for the specified congress and chamber */ async getPrintsByCongressAndChamber(congress, chamber, params = {}) { return this.get( `/${congress}/${chamber}`, params ); } /** * Returns detailed information for a specified committee print. * @param congress - The congress of the print * @param chamber - The chamber of the print * @param printNumber - The print number * @param params {BaseParams} - Accepts format parameters * @returns Detailed information for the specified committee print */ async getPrint(congress, chamber, printNumber, params = {}) { return this.get( `/${congress}/${chamber}/${printNumber}`, params ); } /** * Returns the list of texts for a specified committee print. * @param congress - The congress of the print * @param chamber - The chamber of the print * @param jacketNumber - The jacket number * @param params {PaginationParams} - Accepts pagination and format parameters * @returns List of texts for a specified committee print. */ async getPrintTexts(congress, chamber, jacketNumber, params = {}) { return this.get( `/${congress}/${chamber}/${jacketNumber}/text`, params ); } } class CommitteeReportClient extends BaseClient { constructor({ apiKey }) { super({ apiKey, endpoint: "/committee-report" }); } /** * Returns a list of committee reports. * @param params {PaginationParams & DateFilterParams & { conference: boolean}} - Accepts pagination, date range, and format parameters * @returns A list of committee reports */ async getReports(params = {}) { return this.get("", params); } /** * Returns a list of committee reports filtered by the specified congress. * @param congress - The congress to filter by * @param params {PaginationParams & DateFilterParams & { conference: boolean}} - Accepts pagination, date range, and format parameters * @returns A list of committee reports for the specified congress */ async getReportsByCongress(congress, params = {}) { return this.get( `/${congress}`, params ); } /** * Returns a list of committee reports filtered by the specified congress and chamber. * @param congress - The congress to filter by * @param reportType - The type of the report * @param params {PaginationParams & DateFilterParams & { conference: boolean}} - Accepts pagination, date range, and format parameters * @returns A list of committee reports for the specified congress and chamber */ async getReportsByCongressAndChamber(congress, reportType, params = {}) { return this.get( `/${congress}/${reportType.toLowerCase()}`, params ); } /** * Returns detailed information for a specified committee report. * @param congress - The congress of the report * @param reportType - The type of the report * @param reportNumber - The report number * @param params {BaseParams} - Accepts format parameters * @returns Detailed information for the specified committee report */ async getCommitteeReports(congress, reportType, reportNumber, params = {}) { return this.get( `/${congress}/${reportType.toLowerCase()}/${reportNumber}`, params ); } /** * Returns the list of texts for a specified committee report. * @param congress - The congress of the report * @param reportType - The type of the report * @param reportNumber - The report number * @param params {PaginationParams} - Accepts pagination and format parameters * @returns A list of report texts */ async getReportTexts(congress, reportType, reportNumber, params = {}) { return this.get( `/${congress}/${reportType.toLowerCase()}/${reportNumber}/text`, params ); } } class CommitteeClient extends BaseClient { constructor({ apiKey }) { super({ apiKey, endpoint: "/committee" }); } /** * Returns a list of congressional committees. * @param params {PaginationParams} - Accepts pagination and format parameters * @returns A list of congressional committees */ async getCommittees(params = {}) { return this.get("", params); } /** * Returns a list of congressional committees filtered by the specified chamber. * @param chamber - The chamber to filter by * @param params {PaginationParams} - Accepts pagination and format parameters * @returns A list of congressional committees for the specified chamber */ async getCommitteesByChamber(chamber, params = {}) { return this.get( `/${chamber}`, params ); } /** * Returns a list of congressional committees filtered by the specified congress. * @param congress - The congress to filter by * @param params {PaginationParams} - Accepts pagination and format parameters * @returns A list of congressional committees for the specified congress */ async getCommitteesByCongress(congress, params = {}) { return this.get( `/${congress}`, params ); } /** * Returns a list of committees filtered by the specified congress and chamber. * @param congress - The congress to filter by * @param chamber - The chamber to filter by * @param params {PaginationParams} - Accepts pagination and format parameters * @returns A list of committees for the specified congress and chamber */ async getCommitteesByCongressAndChamber(congress, chamber, params = {}) { return this.get( `/${congress}/${chamber.toLowerCase()}`, params ); } /** * Returns detailed information for a specified congressional committee. * @param chamber - The chamber of the committee * @param committeeCode - The committee code * @param params {PaginationParams} - Accepts pagination and format parameters * @returns Detailed information for the specified committee */ async getCommittee(chamber, committeeCode, params = {}) { return this.get( `/${chamber.toLowerCase()}/${committeeCode}`, params ); } /** * Returns the list of legislation associated with the specified congressional committee. * @param chamber - The chamber of the committee * @param committeeCode - The committee code * @param params {PaginationParams} - Accepts pagination and format parameters * @returns A list of bills associated with the committee */ async getCommitteeBills(chamber, committeeCode, params = {}) { const resp = await this.get(`/${chamber.toLowerCase()}/${committeeCode}/bills`, params); const committeeBills = resp["committee-bills"]; delete resp["committee-bills"]; return { committeeBills, ...resp }; } /** * Returns the list of committee reports associated with a specified congressional committee. * @param chamber - The chamber of the committee * @param committeeCode - The committee code * @param params {PaginationParams} - Accepts pagination and format parameters * @returns A list of committee reports */ async getCommitteeReports(chamber, committeeCode, params = {}) { return this.get( `/${chamber.toLowerCase()}/${committeeCode}/reports`, params ); } /** * Returns the list of nominations associated with a specified congressional committee. * @param chamber - The chamber of the committee * @param committeeCode - The committee code * @param params {PaginationParams} - Accepts pagination and format parameters * @returns A list of nominations */ async getCommitteeNominations(chamber, committeeCode, params = {}) { return this.get( `/${chamber.toLowerCase()}/${committeeCode}/nominations`, params ); } /** * Returns the list of House communications associated with a specified congressional committee. * @param chamber - The chamber of the committee * @param committeeCode - The committee code * @param params {PaginationParams} - Accepts pagination and format parameters * @returns A list of House communications */ async getCommitteeHouseCommunications(chamber, committeeCode, params = {}) { return this.get( `/${chamber.toLowerCase()}/${committeeCode}/house-communication`, params ); } /** * Returns the list of Senate communications associated with a specified congressional committee. * @param chamber - The chamber of the committee * @param committeeCode - The committee code * @param params {PaginationParams} - Accepts pagination and format parameters * @returns A list of Senate communications */ async getCommitteeSenateCommunications(chamber, committeeCode, params = {}) { return this.get(`/${chamber.toLowerCase()}/${committeeCode}/senate-communication`, params); } } class CongressClient extends BaseClient { constructor({ apiKey }) { super({ apiKey, endpoint: "/congress" }); } /** * Returns a list of congresses and congressional sessions. * @param params {@link PaginationParams} - Pagination and format parameters * @returns A list of {@link CongressSummary congresses} and their sessions */ async getCongresses(params = {}) { return this.get("", params); } /** * Returns detailed information for a specified congress. * @param congress - The Congress number (e.g., 117) * @param params {@link BaseParams} - Accepts format parameter (json or xml) * @returns {@link Congress Detail} information for the specified congress */ async getCongress(congress, params = {}) { return this.get(`/${congress}`, params); } /** * Returns detailed information for the current congress. * @param params {@link BaseParams} - Accepts format parameter (json or xml) * @returns {@link Congress Detail} information for the current congress */ async getCurrentCongress(params = {}) { return this.get("/current", params); } } const lowerCaseFirstLetter = (str) => { if (str === "PDF") return "pdf"; return str.charAt(0).toLowerCase() + str.slice(1); }; const recursiveLowerCase = (obj) => { if (Array.isArray(obj)) { return obj.map((item) => recursiveLowerCase(item)); } if (typeof obj === "object" && obj !== null) { return Object.keys(obj).reduce( (acc, key) => ({ ...acc, [lowerCaseFirstLetter(key)]: recursiveLowerCase(obj[key]) }), {} ); } return obj; }; const adaptAbnormalResponseAdapter = (response, params, baseUrl) => { const url = new URL(baseUrl); params.offset = response.Results.IndexStart + response.Results.SetSize; params.limit = response.Results.SetSize; url.search = new URLSearchParams(params).toString(); return { issues: recursiveLowerCase(response.Results.Issues), pagination: { count: response.Results.TotalCount, next: url.toString() }, request: { contentType: "application/json", format: "json" } }; }; class CongressionalRecordClient extends BaseClient { constructor({ apiKey }) { super({ apiKey, endpoint: "/congressional-record" }); } /** * Returns a list of congressional record issues sorted by most recent. * @param params {CongressionalRecordFilterParams} - Pagination parameters as well as y, m, d for filtering by date * @returns A list of congressional record issues */ async getIssues(params = {}) { return adaptAbnormalResponseAdapter( await this.get( "", params ), params, "https://api.congress.gov/v3/congressional-record" ); } } class CRSReportClient extends BaseClient { constructor({ apiKey }) { super({ apiKey, endpoint: "/crsreport" }); } /** * Returns Congressional Research Service (CRS) report data from the API. * @param params {PaginationParams} - Pagination and format parameters * @returns A list of CRS reports */ async getReports(params = {}) { return this.get("", params); } /** * Returns detailed information for a specified Congressional Research Service (CRS) report. * @param reportNumber - The report number to retrieve * @param params {BaseParams} - Format parameters * @returns Detailed information for the specified CRS report */ async getReport(reportNumber, params = {}) { return this.get(`/${reportNumber}`, params); } } class DailyCongressionalRecordClient extends BaseClient { constructor({ apiKey }) { super({ apiKey, endpoint: "/daily-congressional-record" }); } /** * Returns a list of daily congressional record issues sorted by most recent. * @param params {PaginationParams} - Accepts pagination and format parameters * @returns A list of daily congressional record issues */ async getRecords(params = {}) { return this.get("", params); } /** * Returns a list of daily Congressional Records filtered by the specified volume number. * @param volumeNumber - The volume number to filter by * @param params {PaginationParams} - Acceps pagination and format parameters * @returns A list of daily congressional records for the specified volume */ async getRecordsByVolume(volumeNumber, params = {}) { return this.get( `/${volumeNumber}`, params ); } /** * Returns a list of daily Congressional Records filtered by the specified volume number and issue number. * @param volumeNumber - The volume number to filter by * @param issueNumber - The issue number to filter by * @param params {BaseParams} - Accepts format parameters * @returns A list of daily congressional records for the specified volume and issue */ async getRecordsByVolumeAndIssue(volumeNumber, issueNumber, params = {}) { return this.get( `/${volumeNumber}/${issueNumber}`, params ); } /** * Returns a list of daily Congressional Record articles filtered by the specified volume number and issue number. * @param volumeNumber - The volume number to filter by * @param issueNumber - The issue number to filter by * @param params {PaginationParams} - Accepts pagination and format parameters * @returns A list of daily congressional record articles for the specified volume and issue */ async getArticles(volumeNumber, issueNumber, params = {}) { return this.get( `/${volumeNumber}/${issueNumber}/articles`, params ); } } class HearingClient extends BaseClient { constructor({ apiKey }) { super({ apiKey, endpoint: "/hearing" }); } /** * Returns a list of hearings. * @param params {PaginationParams} - Accepts pagination and format parameters * @returns A list of hearings */ async getHearings(params = {}) { return this.get("", params); } /** * Returns a list of hearings filtered by the specified congress. * @param congress - The congress to filter by * @param params {PaginationParams} - Accepts pagination and format parameters * @returns A list of hearings for the specified congress */ async getHearingsByCongress(congress, params = {}) { return this.get( `/${congress}`, params ); } /** * Returns a list of hearings filtered by the specified congress and chamber. * @param congress - The congress to filter by * @param chamber - The chamber to filter by * @param params {PaginationParams} - Pagination parameters * @returns A list of hearings for the specified congress and chamber */ async getHearingsByCongressAndChamber(congress, chamber, params = {}) { return this.get( `/${congress}/${chamber.toLowerCase()}`, params ); } /** * Returns detailed information for a specified hearing. * @param congress - The congress of the hearing * @param chamber - The chamber of the hearing * @param jacketNumber - The jacket number of the hearing * @param params {BaseParams} - Accepts format parameters * @returns Detailed information for the specified hearing */ async getHearing(congress, chamber, jacketNumber, params = {}) { return this.get( `/${congress}/${chamber.toLowerCase()}/${jacketNumber}`, params ); } } class HouseCommunicationClient extends BaseClient { constructor({ apiKey }) { super({ apiKey, endpoint: "/house-communication" }); } /** * Returns a list of House communications. * @param params {PaginationParams} - Accepts pagination and format parameters * @returns A list of House communications */ async getCommunications(params = {}) { return this.get("", params); } /** * Returns a list of House communications filtered by the specified congress. * @param congress - The congress to filter by * @param params {PaginationParams} - Accepts pagination and format parameters * @returns A list of House communications for the specified congress */ async getCommunicationsByCongress(congress, params = {}) { return this.get( `/${congress}`, params ); } /** * Returns a list of House communications filtered by the specified congress and communication type. * @param congress - The congress to filter by * @param communicationType - The communication type to filter by * @param params {PaginationParams} - Accepts pagination and format parameters * @returns A list of House communications for the specified congress and communication type */ async getCommunicationsByCongressAndType(congress, communicationType, params = {}) { return this.get( `/${congress}/${communicationType}`, params ); } /** * Returns detailed information for a specified House communication. * @param congress - The congress of the communication * @param communicationType - The type of the communication * @param communicationNumber - The communication number * @param params {BaseParams} - Accepts format parameter * @returns Detailed information for the specified House communication */ async getCommunication(congress, communicationType, communicationNumber, params = {}) { const resp = await this.get( `/${congress}/${communicationType}/${communicationNumber}`, params ); const houseCommunication = resp["house-communication"]; delete resp["house-communication"]; return { houseCommunication, ...resp }; } } class HouseRequirementClient extends BaseClient { constructor({ apiKey }) { super({ apiKey, endpoint: "/house-requirement" }); } /** * Returns a list of House requirements. * @param params {PaginationParams} - Accepts pagination and format parameters * @returns A list of House requirements */ async getRequirements(params = {}) { return this.get( "", params ); } /** * Returns detailed information for a specified House requirement. * @param requirementNumber - The requirement number * @param params {BaseParams} - Accepts format parameter * @returns Detailed information for the specified House requirement */ async getRequirement(requirementNumber, params = {}) { return this.get( `/${requirementNumber}`, params ); } /** * Returns a list of matching communications to a House requirement. * @param requirementNumber - The requirement number * @param params {PaginationParams} - Accepts pagination and format parameters * @returns A list of matching communications */ async getMatchingCommunications(requirementNumber, params = {}) { return this.get( `/${requirementNumber}/matching-communications`, params ); } } class HouseVoteClient extends BaseClient { constructor({ apiKey }) { super({ apiKey, endpoint: "/house-vote" }); } /** * Returns House of Representatives roll call vote data from the API. This endpoint is currently in beta. * @param params {PaginationParams} - Accepts pagination and format parameters * @returns A list of House roll call votes */ async getHouseRollCallVotes(params = {}) { return this.get( "", params ); } /** * Returns House of Representatives roll call vote data filtered by the specified Congress. This endpoint is currently in beta. * @param congress - The congress to filter by * @param params {PaginationParams} - Accepts pagination and format parameters * @returns A list of House roll call votes for the specified congress */ async getHouseRollCallVotesByCongress(congress, params = {}) { return this.get( `/${congress}`, params ); } /** * Returns House of Representatives roll call vote data filtered by the specified Congress and session. This endpoint is currently in beta. * @param congress - The congress to filter by * @param session - The session to filter by * @param params {PaginationParams} - Accepts pagination and format parameters * @returns A list of House roll call votes for the specified congress and session */ async getHouseRollCallVotesByCongressAndSession(congress, session, params = {}) { return this.get( `/${congress}/${session}`, params ); } /** * Returns detailed information for a specified House of Representatives roll call vote. This endpoint is currently in beta. * @param congress - The congress of the vote * @param session - The session of the vote * @param voteNumber - The vote number * @param params {PaginationParams} - Accepts pagination and format parameters * @returns Detailed information for the specified House roll call vote */ async getHouseRollCallVote(congress, session, voteNumber, params = {}) { return this.get( `/${congress}/${session}/${voteNumber}`, params ); } /** * Returns detailed information for how members voted on a specified House of Representatives roll call vote. This endpoint is currently in beta. * @param congress - The congress of the vote * @param session - The session of the vote * @param voteNumber - The vote number * @param params Accepts format parameters * @returns A list of member votes for the specified House roll call vote */ async getHouseRollCallVoteMembers(congress, session, voteNumber, params = {}) { return this.get( `/${congress}/${session}/${voteNumber}/members`, params ); } } class MemberClient extends BaseClient { constructor({ apiKey }) { super({ apiKey, endpoint: "/member" }); } /** * Returns a list of congressional members. * @param params {PaginationParams & DateFilterParams & MemberParams} - Accepts pagination, date range filter, and format parameter (json or xml) * @returns A list of congressional members */ async getMembers(params = {}) { return this.get("", params); } /** * Returns detailed information for a specified congressional member. * @param bioguideId - The bioguide ID of the member * @param params {BaseParams} - Accepts format parameter (json or xml) * @returns Detailed information for the specified member */ async getMember(bioguideId, params = {}) { return this.get(`/${bioguideId}`, params); } /** * Returns the list of legislation sponsored by a specified congressional member. * @param bioguideId - The bioguide ID of the member * @param params {PaginationParams} - Accepts pagination and format parameters * @returns A list of sponsored legislation */ async getSponsoredLegislation(bioguideId, params = {}) { return this.get( `/${bioguideId}/sponsored-legislation`, params ); } /** * Returns the list of legislation cosponsored by a specified congressional member. * @param bioguideId - The bioguide ID of the member * @param params {PaginationParams} - Accepts pagination and format parameters * @returns A list of cosponsored legislation */ async getCosponsoredLegislation(bioguideId, params = {}) { return this.get(`/${bioguideId}/cosponsored-legislation`, params); } /** * Returns the list of members specified by prior Congress. This queries with currentMember=false filter. [Docs](https://github.com/LibraryOfCongress/api.congress.gov/blob/main/Documentation/MemberEndpoint.md#a-note-on-filtering-members-by-congress) * @param congress - The congress to filter by * @param params {PaginationParams & MemberParams} - Pagination and format parameters * @returns A list of members for the specified congress */ async getMembersByPriorCongress(congress, params = {}) { params.currentMember = false; return this.get( `/congress/${congress}`, params ); } /** * Returns the list of members specified by current Congress. This queries with currentMember=true filter. [Docs](https://github.com/LibraryOfCongress/api.congress.gov/blob/main/Documentation/MemberEndpoint.md#a-note-on-filtering-members-by-congress) * @param congress - The congress to filter by * @param params {PaginationParams & MemberParams} - Pagination and format parameters * @returns A list of members for the specified congress */ async getMembersByCurrentCongress(congress, params = {}) { params.currentMember = true; return this.get( `/congress/${congress}`, params ); } /** * Returns a list of members filtered by state. * @param stateCode - The state code to filter by * @param params {PaginationParams & MemberParams} - Pagination and format parameters * @returns A list of members for the specified state */ async getMembersByState(stateCode, params = {}) { return this.get( `/${stateCode}`, params ); } /** * Returns a list of members filtered by state and district. * @param stateCode - The state code to filter by * @param district - The district to filter by * @param params {PaginationParams & MemberParams} - Pagination and format parameters * @returns A list of members for the specified state and district */ async getMembersByStateAndDistrict(stateCode, district, params = {}) { return this.get( `/${stateCode}/${district}`, params ); } /** * Returns a list of members filtered by congress, state and district. * There are instances where a member has been redistricted but previously represented the district you are generating an API request for and, thus, appears in the returned data. * If you are looking for ONLY the current member of a particular district, please use the currentMember=True filter to get the most accurate results * @param congress - The congress to filter by * @param stateCode - The state code to filter by * @param district - The district to filter by * @param params {PaginationParams & MemberParams} - Pagination and format parameters. Default is currentMember=true. * @returns A list of members for the specified congress, state and district */ async getMembersByCongressStateAndDistrict(congress, stateCode, district, params = { currentMember: true }) { return this.get( `/congress/${congress}/${stateCode}/${district}`, params ); } } class NominationClient extends BaseClient { constructor({ apiKey }) { super({ apiKey, endpoint: "/nomination" }); } /** * Returns a list of nominations sorted by date received from the President. * @param params {PaginationParams & DateFilterParams} - Pagination, date range filter and format parameters * @returns A list of nominations */ async getNominations(params = {}) { return this.get("", params); } /** * Returns a list of nominations filtered by the specified congress and sorted by date received from the President. * @param congress - The congress to filter by * @param params {PaginationParams & DateFilterParams} - Pagination, date range filter and format parameters * @returns A list of nominations for the specified congress */ async getNominationsByCongress(congress, params = {}) { return this.get(`/${congress}`, params); } /** * Returns detailed information for a specified nomination. * @param congress - The congress of the nomination * @param nominationNumber - The nomination number * @param params {BaseParams} - Accepts format parameter * @returns Detailed information for the specified nomination */ async getNomination(congress, nominationNumber, params = {}) { return this.get( `/${congress}/${nominationNumber}`, params ); } /** * Returns the list nominees for a position within the nomination. * @param congress - The congress of the nomination * @param nominationNumber - The nomination number * @param ordinal - The ordinal of the nominee * @param params {PaginationParams} - Accepts pagination and format parameters * @returns The list of nominees for the specified position */ async getNominees(congress, nominationNumber, ordinal, params = {}) { return this.get( `/${congress}/${nominationNumber}/${ordinal}`, params ); } /** * Returns the list of actions on a specified nomination. * @param congress - The congress of the nomination * @param nominationNumber - The nomination number * @param params {PaginationParams} - Accepts pagination and format parameters * @returns The list of actions for the specified nomination