diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a2b1fe..4358036 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,19 @@ +## [1.0.2](https://github.com/4very/ferc-elibrary-api/compare/v1.0.1...v1.0.2) (2024-06-06) + + +### Features + +* :sparkles: docket search ([b9f278c](https://github.com/4very/ferc-elibrary-api/commit/b9f278c867ac06b61133b69c01046800ebd11cb7)) +* :sparkles: new docket search ([e5de589](https://github.com/4very/ferc-elibrary-api/commit/e5de58913885f400d7cee02ed97b46d05afffec5)) + + +### Bug Fixes + +* :bug: failing tests ([365350c](https://github.com/4very/ferc-elibrary-api/commit/365350c4a23e47259bf81907ebaf344fa63594f7)) +* :bug: failing tests ([f61afa2](https://github.com/4very/ferc-elibrary-api/commit/f61afa277417ab5bc40a0615ee42654c56a24884)) +* :bug: fetch without body on get ([54463a9](https://github.com/4very/ferc-elibrary-api/commit/54463a91370b32a1aafad464ef305da1f1f2a572)) +* :bug: fix build ([40ce396](https://github.com/4very/ferc-elibrary-api/commit/40ce396e0a72209f9e6bc4322b5977ab90614280)) + ## [1.0.1](https://github.com/4very/ferc-elibrary-api/compare/v1.0.0...v1.0.1) (2024-05-14) diff --git a/dist/index.cjs b/dist/index.cjs new file mode 100644 index 0000000..8585de2 --- /dev/null +++ b/dist/index.cjs @@ -0,0 +1 @@ +"use strict";var f=Object.defineProperty;var d=(a,t,e)=>t in a?f(a,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):a[t]=e;var i=(a,t,e)=>(d(a,typeof t!="symbol"?t+"":t,e),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("fs"),g=require("path");class h{constructor(){i(this,"params",{});i(this,"data")}}function c(a,t="post"){return async e=>fetch(`https://elibrary.ferc.gov/eLibrarywebapi/api/${a}`,{headers:{"content-type":"application/json"},method:t,...t!=="get"?{body:JSON.stringify(e)}:{}}).then(s=>s.json())}const u={dockets:"rp24-769",subdockets:"000",filed_date_beg:"01-01-1960",filed_date_end:"06-04-2024",complete_flag:0,numHits:100,pageNumber:0};class P extends h{constructor(e){super();i(this,"defaultParams",u);i(this,"fetch",c("Docket/GetSingleDocketSheet"));this.params={...this.defaultParams,...e}}async getData(){this.data=await this.fetch(this.params)}updateParams(e){this.params={...u,...e}}async nextPage(){var r;const{numHits:e,pageNumber:s}=this.params;return(((r=this.data)==null?void 0:r.Page.totalHits)??-1)>e*(s+1)?(this.params.pageNumber++,await this.getData(),!0):!1}async prevPage(){const{pageNumber:e}=this.params;return e>0?(this.params.pageNumber--,await this.getData(),!0):!1}}const o={by:"rbFilingDate",start:"06-04-2024",end:"06-04-2024"};class y extends h{constructor(e){super();i(this,"defaultParams",o);i(this,"fetch",c(""));this.params={...this.defaultParams,...e},this.setFetch()}setFetch(){this.fetch=c(`Docket/GetATMSdocs/${this.params.by}/${this.params.start}/${this.params.end}/DocketFullNumber`,"get")}async getData(){this.data=await this.fetch({})}updateParams(e){this.params={...o,...e},this.setFetch()}}const l={searchText:"*",searchFullText:!0,searchDescription:!0,dateSearches:[],availability:null,affiliations:[],categories:[],libraries:[],accessionNumber:null,eFiling:!1,docketSearches:[{docketNumber:"P-15056-000",subDocketNumbers:[]}],resultsPerPage:100,curPage:1,classTypes:[],sortBy:"",groupBy:"NONE",idolResultID:"",allDates:!1};class D extends h{constructor(e){super();i(this,"defaultParams",l);i(this,"fetch",c("Search/AdvancedSearch"));this.params={...this.defaultParams,...e},this.params.curPage===0&&(this.params.curPage=1)}async getData(){this.data=await this.fetch(this.params)}updateParams(e){this.params={...l,...e}}async nextPage(){var r;const{resultsPerPage:e,curPage:s}=this.params;return(((r=this.data)==null?void 0:r.totalHits)??-1)>e*s?(this.params.curPage++,await this.getData(),!0):!1}async prevPage(){const{curPage:e}=this.params;return e>1?(this.params.curPage--,await this.getData(),!0):!1}}const n={path:"temp",format:"pdf",file:"temp"};async function b(a,t){const e={...n,file:a.fileidLst[0]??n.file,...t};return p(e,"File/DownloadP8File",{},a)}async function S(a,t){const e={...n,file:a,...t};return p(e,"File/DownloadPDF",{accessionNumber:a},'{serverLocation: ""}')}async function p(a,t,e,s){return fetch(`https://elibrary.ferc.gov/eLibrarywebapi/api/${t}?`+new URLSearchParams(e),{headers:{accept:"application/json, text/plain, */*","content-type":"application/json"},body:typeof s=="string"?s:JSON.stringify(s),method:"POST"}).then(r=>r.arrayBuffer()).then(r=>m.writeFileSync(g.join(a.path,`${a.file}.${a.format}`),Buffer.from(r),"binary"))}exports.DocketSearch=P;exports.GeneralSearch=D;exports.NewDocketSearch=y;exports.downloadFile=b;exports.generatePDF=S; diff --git a/dist/index.d.ts b/dist/index.d.ts new file mode 100644 index 0000000..54d4e72 --- /dev/null +++ b/dist/index.d.ts @@ -0,0 +1,6 @@ +import { default as DocketSearch } from './search/docket'; +import { default as NewDocketSearch } from './search/newDocket'; +import { default as GeneralSearch } from './search/general'; +import { downloadFile, generatePDF } from './util/download'; + +export { DocketSearch, NewDocketSearch, GeneralSearch, downloadFile, generatePDF, }; diff --git a/dist/index.js b/dist/index.js new file mode 100644 index 0000000..6cbb09d --- /dev/null +++ b/dist/index.js @@ -0,0 +1,177 @@ +var f = Object.defineProperty; +var m = (t, e, a) => e in t ? f(t, e, { enumerable: !0, configurable: !0, writable: !0, value: a }) : t[e] = a; +var i = (t, e, a) => (m(t, typeof e != "symbol" ? e + "" : e, a), a); +import { writeFileSync as d } from "fs"; +import { join as g } from "path"; +class h { + constructor() { + i(this, "params", {}); + i(this, "data"); + } +} +function c(t, e = "post") { + return async (a) => fetch(`https://elibrary.ferc.gov/eLibrarywebapi/api/${t}`, { + headers: { + "content-type": "application/json" + }, + method: e, + ...e !== "get" ? { body: JSON.stringify(a) } : {} + }).then((s) => s.json()); +} +const u = { + dockets: "rp24-769", + subdockets: "000", + filed_date_beg: "01-01-1960", + filed_date_end: "06-04-2024", + complete_flag: 0, + numHits: 100, + pageNumber: 0 +}; +class D extends h { + constructor(a) { + super(); + i(this, "defaultParams", u); + i(this, "fetch", c("Docket/GetSingleDocketSheet")); + this.params = { ...this.defaultParams, ...a }; + } + async getData() { + this.data = await this.fetch(this.params); + } + updateParams(a) { + this.params = { ...u, ...a }; + } + async nextPage() { + var r; + const { numHits: a, pageNumber: s } = this.params; + return (((r = this.data) == null ? void 0 : r.Page.totalHits) ?? -1) > a * (s + 1) ? (this.params.pageNumber++, await this.getData(), !0) : !1; + } + async prevPage() { + const { pageNumber: a } = this.params; + return a > 0 ? (this.params.pageNumber--, await this.getData(), !0) : !1; + } +} +const o = { + by: "rbFilingDate", + start: "06-04-2024", + end: "06-04-2024" +}; +class S extends h { + constructor(a) { + super(); + i(this, "defaultParams", o); + i(this, "fetch", c("")); + this.params = { ...this.defaultParams, ...a }, this.setFetch(); + } + setFetch() { + this.fetch = c( + `Docket/GetATMSdocs/${this.params.by}/${this.params.start}/${this.params.end}/DocketFullNumber`, + "get" + ); + } + async getData() { + this.data = await this.fetch({}); + } + updateParams(a) { + this.params = { ...o, ...a }, this.setFetch(); + } +} +const l = { + searchText: "*", + searchFullText: !0, + searchDescription: !0, + dateSearches: [], + availability: null, + affiliations: [], + categories: [], + libraries: [], + accessionNumber: null, + eFiling: !1, + docketSearches: [ + { + docketNumber: "P-15056-000", + subDocketNumbers: [] + } + ], + resultsPerPage: 100, + curPage: 1, + classTypes: [], + sortBy: "", + groupBy: "NONE", + idolResultID: "", + allDates: !1 +}; +class w extends h { + constructor(a) { + super(); + i(this, "defaultParams", l); + i(this, "fetch", c("Search/AdvancedSearch")); + this.params = { ...this.defaultParams, ...a }, this.params.curPage === 0 && (this.params.curPage = 1); + } + async getData() { + this.data = await this.fetch(this.params); + } + updateParams(a) { + this.params = { ...l, ...a }; + } + async nextPage() { + var r; + const { resultsPerPage: a, curPage: s } = this.params; + return (((r = this.data) == null ? void 0 : r.totalHits) ?? -1) > a * s ? (this.params.curPage++, await this.getData(), !0) : !1; + } + async prevPage() { + const { curPage: a } = this.params; + return a > 1 ? (this.params.curPage--, await this.getData(), !0) : !1; + } +} +const n = { + path: "temp", + format: "pdf", + file: "temp" +}; +async function F(t, e) { + const a = { + ...n, + file: t.fileidLst[0] ?? n.file, + ...e + }; + return p(a, "File/DownloadP8File", {}, t); +} +async function N(t, e) { + const a = { + ...n, + file: t, + ...e + }; + return p( + a, + "File/DownloadPDF", + { accessionNumber: t }, + '{serverLocation: ""}' + ); +} +async function p(t, e, a, s) { + return fetch( + `https://elibrary.ferc.gov/eLibrarywebapi/api/${e}?` + new URLSearchParams(a), + { + headers: { + accept: "application/json, text/plain, */*", + "content-type": "application/json" + }, + body: typeof s == "string" ? s : JSON.stringify(s), + method: "POST" + } + ).then((r) => r.arrayBuffer()).then( + (r) => d( + g(t.path, `${t.file}.${t.format}`), + Buffer.from(r), + "binary" + ) + ); +} +export { + D as DocketSearch, + w as GeneralSearch, + S as NewDocketSearch, + F as downloadFile, + N as generatePDF +}; diff --git a/dist/search/docket.d.ts b/dist/search/docket.d.ts new file mode 100644 index 0000000..5b2e7c5 --- /dev/null +++ b/dist/search/docket.d.ts @@ -0,0 +1,12 @@ +import { DocketSearchParams, DocketSearchResults } from '../types/DocketSearch'; +import { Search } from './search'; + +export default class DocketSearch extends Search { + readonly defaultParams: DocketSearchParams; + readonly fetch: (params: DocketSearchParams) => Promise; + constructor(params: Partial); + getData(): Promise; + updateParams(params: Partial): void; + nextPage(): Promise; + prevPage(): Promise; +} diff --git a/dist/search/general.d.ts b/dist/search/general.d.ts new file mode 100644 index 0000000..d4ea143 --- /dev/null +++ b/dist/search/general.d.ts @@ -0,0 +1,12 @@ +import { GeneralSearchParams, GeneralSearchResult } from '../types'; +import { Search } from './search'; + +export default class GeneralSearch extends Search { + readonly defaultParams: GeneralSearchParams; + readonly fetch: (params: GeneralSearchParams) => Promise; + constructor(params: Partial); + getData(): Promise; + updateParams(params: Partial): void; + nextPage(): Promise; + prevPage(): Promise; +} diff --git a/dist/search/newDocket.d.ts b/dist/search/newDocket.d.ts new file mode 100644 index 0000000..124b364 --- /dev/null +++ b/dist/search/newDocket.d.ts @@ -0,0 +1,11 @@ +import { NewDocketParams, NewDocketResults } from '../types/NewDocket'; +import { Search } from './search'; + +export default class NewDocketSearch extends Search { + readonly defaultParams: NewDocketParams; + fetch: (params: {}) => Promise; + constructor(params: Partial); + setFetch(): void; + getData(): Promise; + updateParams(params: Partial): void; +} diff --git a/dist/search/search.d.ts b/dist/search/search.d.ts new file mode 100644 index 0000000..ad002c5 --- /dev/null +++ b/dist/search/search.d.ts @@ -0,0 +1,6 @@ +export declare abstract class Search, SearchResults extends Record> { + params: SearchParams; + abstract defaultParams: SearchParams; + data: SearchResults | undefined; + abstract readonly fetch: (params: SearchParams) => Promise; +} diff --git a/dist/types/DocketSearch.d.ts b/dist/types/DocketSearch.d.ts new file mode 100644 index 0000000..dcdd15e --- /dev/null +++ b/dist/types/DocketSearch.d.ts @@ -0,0 +1,46 @@ +import { Categories } from './stubs'; + +export type DocketSearchParams = { + dockets: string; + subdockets: 'All' | string; + filed_date_beg: string; + filed_date_end: string; + numHits: number; + pageNumber: number; + complete_flag: 0; +}; +export type DocketSearchResults = { + Page: { + totalHits: number; + numHits: number; + pageNumber: number; + }; + ErrorList: unknown[]; + DataList: { + DocumentsItem: { + document_id: 0; + category_cd: 0; + DOCKET_TEXT: string; + SUBDOCKET_TEXT: string; + DOCKET_CODE: null; + subDocketNumber: 0; + accession_no: string; + accession_date: string; + accession_series: null; + availability_code: null; + category: Categories; + doc_desc: string; + source: null; + Affiliation_Organization: string[]; + fed_reg_num: null; + filed_date: string; + issued_date: string; + fed_reg_date: string; + comments_due_date: string; + FEE_AMT_CUR: 0; + FERC_CITE: null; + }[]; + AuthorsItem: []; + FedCitesItem: []; + }[]; +}; diff --git a/dist/types/DownloadFile.d.ts b/dist/types/DownloadFile.d.ts new file mode 100644 index 0000000..279ae91 --- /dev/null +++ b/dist/types/DownloadFile.d.ts @@ -0,0 +1,8 @@ +export type DownloadFileParams = { + FileType: string; + accession: string; + fileid: number; + FileIDAll: string; + fileidLst: string[]; + Islegacy: boolean; +}; diff --git a/dist/types/GeneralSearch.d.ts b/dist/types/GeneralSearch.d.ts new file mode 100644 index 0000000..173c1da --- /dev/null +++ b/dist/types/GeneralSearch.d.ts @@ -0,0 +1,76 @@ +import { ClassType, Affiliations, SecurityLevel, Categories, Libraries } from './stubs'; + +export type DocketSearch = { + docketNumber: string | null; + subDocketNumbers: string[] | null; +}; +export type DateSearch = { + dateType: 'issued_date' | 'filed_date' | 'posted_date'; + startDate: string; + endDate: string; +}; +export type GeneralSearchParams = { + docketSearches: DocketSearch[]; + accessionNumber?: string | null; + parentAccessionNumber?: string; + fedRegisterCite?: string; + fedCourtCaseNumber?: string; + fercCite?: string; + opinion?: string; + orderNumber?: string; + searchText: string; + searchFullText: boolean; + searchDescription: boolean; + allDates: boolean; + dateSearches: DateSearch[]; + classTypes: ClassType[]; + affiliations: Affiliations[]; + availability: SecurityLevel[] | null; + categories: Categories[]; + libraries: Libraries[]; + eFiling: boolean; + sortBy: string; + groupBy: string; + /** + * Number of results to return per page. + * @type {number} + */ + resultsPerPage: number; + curPage: number; + idolResultID: string; +}; +export type Transmittal = { + fileId: string; + fileType: string; + fileFormat: string; + fileName: string; + fileDesc: string; + fileSize: number; + transmittalFk: null; +}; +export type GeneralSearchResult = { + errorMessage: unknown; + numHits: number; + searchResultId: unknown; + success: boolean; + totalHits: number; + searchHits: { + reference: string; + documentId: string; + acesssionNumber: string; + docketNumbers: string[]; + description: string; + summary: null; + familyValue: 'None' | 'none' | 'child' | 'Parent'; + issuedDate: string; + filedDate: string; + postedDate: string; + category: Categories; + classTypes: ClassType[]; + availCode: SecurityLevel; + libraries: Libraries[]; + transmittals: Transmittal[]; + affiliations: Affiliations[]; + score: 83.35; + }[]; +}; diff --git a/dist/types/NewDocket.d.ts b/dist/types/NewDocket.d.ts new file mode 100644 index 0000000..8610076 --- /dev/null +++ b/dist/types/NewDocket.d.ts @@ -0,0 +1,19 @@ +export type NewDocketParams = { + by: 'rbFilingDate' | 'rbCreateDate'; + start: string; + end: string; +}; +export type NewDocketResults = { + DataList: { + DocketID: number; + DocketShortNumber: string; + SubDocketNumber: string; + DocketFullNumber: string; + DocketCreationDate: string; + DocketFilingDate: string; + DocketDescription: string; + CommaDelimitedApplicantsList: string; + DocketSheetlink: string; + }[]; + ErrorList: unknown[]; +}; diff --git a/dist/types/index.d.ts b/dist/types/index.d.ts new file mode 100644 index 0000000..c47e073 --- /dev/null +++ b/dist/types/index.d.ts @@ -0,0 +1 @@ +export type { GeneralSearchParams, GeneralSearchResult } from './GeneralSearch'; diff --git a/dist/types/stubs.d.ts b/dist/types/stubs.d.ts new file mode 100644 index 0000000..7434e5c --- /dev/null +++ b/dist/types/stubs.d.ts @@ -0,0 +1,14 @@ +export type Libraries = 'General' | 'Electric' | 'Gas' | 'Oil' | 'Rulemaking' | 'Hydro'; +export type Categories = 'Issuance' | 'Submittal'; +export type SecurityLevel = 'c' | 's' | 'n' | 'p'; +export type Affiliations = { + afType: 'author' | 'agent' | 'recipient'; + affiliation: string; + firstInitial: string; + lastName: string; + middleInitial: string; +}; +export type ClassType = { + documentClass: string; + documentType: string; +}; diff --git a/dist/util/download.d.ts b/dist/util/download.d.ts new file mode 100644 index 0000000..83592ef --- /dev/null +++ b/dist/util/download.d.ts @@ -0,0 +1,9 @@ +import { DownloadFileParams } from '../types/DownloadFile'; + +export type FileInfo = { + path: string; + file: string; + format: string; +}; +export declare function downloadFile(params: DownloadFileParams, fileInfo?: Partial): Promise; +export declare function generatePDF(accessionNumber: string, fileInfo?: Partial): Promise; diff --git a/dist/util/fetch.d.ts b/dist/util/fetch.d.ts new file mode 100644 index 0000000..ab6adf0 --- /dev/null +++ b/dist/util/fetch.d.ts @@ -0,0 +1 @@ +export declare function fetchFunction(searchType: string, method?: string): (params: SearchParams) => Promise; diff --git a/package.json b/package.json index 72abe9a..80d0984 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ferc-elibrary-api", - "version": "1.0.1", + "version": "1.0.2", "description": "", "repository": "github:4very/ferc-elibrary-api", "main": "index.js",