@cliwant/mcp-sam-gov 0.2.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.ja.md +48 -16
- package/README.ko.md +48 -16
- package/README.md +279 -67
- package/dist/attachments.d.ts +63 -0
- package/dist/attachments.d.ts.map +1 -0
- package/dist/attachments.js +576 -0
- package/dist/attachments.js.map +1 -0
- package/dist/bls.d.ts +267 -0
- package/dist/bls.d.ts.map +1 -0
- package/dist/bls.js +1549 -0
- package/dist/bls.js.map +1 -0
- package/dist/cache.d.ts +42 -0
- package/dist/cache.d.ts.map +1 -0
- package/dist/cache.js +64 -0
- package/dist/cache.js.map +1 -0
- package/dist/census.d.ts +182 -0
- package/dist/census.d.ts.map +1 -0
- package/dist/census.js +576 -0
- package/dist/census.js.map +1 -0
- package/dist/ckan.d.ts +141 -0
- package/dist/ckan.d.ts.map +1 -0
- package/dist/ckan.js +393 -0
- package/dist/ckan.js.map +1 -0
- package/dist/clinicaltrials.d.ts +180 -0
- package/dist/clinicaltrials.d.ts.map +1 -0
- package/dist/clinicaltrials.js +730 -0
- package/dist/clinicaltrials.js.map +1 -0
- package/dist/cms.d.ts +140 -0
- package/dist/cms.d.ts.map +1 -0
- package/dist/cms.js +482 -0
- package/dist/cms.js.map +1 -0
- package/dist/coerce.d.ts +32 -0
- package/dist/coerce.d.ts.map +1 -0
- package/dist/coerce.js +50 -0
- package/dist/coerce.js.map +1 -0
- package/dist/datagov-catalog.d.ts +84 -0
- package/dist/datagov-catalog.d.ts.map +1 -0
- package/dist/datagov-catalog.js +233 -0
- package/dist/datagov-catalog.js.map +1 -0
- package/dist/datagov.d.ts +146 -0
- package/dist/datagov.d.ts.map +1 -0
- package/dist/datagov.js +689 -0
- package/dist/datagov.js.map +1 -0
- package/dist/datagovKey.d.ts +36 -0
- package/dist/datagovKey.d.ts.map +1 -0
- package/dist/datagovKey.js +60 -0
- package/dist/datagovKey.js.map +1 -0
- package/dist/datasource.d.ts +313 -0
- package/dist/datasource.d.ts.map +1 -0
- package/dist/datasource.js +551 -0
- package/dist/datasource.js.map +1 -0
- package/dist/disclosure.d.ts +55 -0
- package/dist/disclosure.d.ts.map +1 -0
- package/dist/disclosure.js +57 -0
- package/dist/disclosure.js.map +1 -0
- package/dist/ecfr.d.ts +4 -2
- package/dist/ecfr.d.ts.map +1 -1
- package/dist/ecfr.js +92 -17
- package/dist/ecfr.js.map +1 -1
- package/dist/echo.d.ts +143 -0
- package/dist/echo.d.ts.map +1 -0
- package/dist/echo.js +424 -0
- package/dist/echo.js.map +1 -0
- package/dist/edgar.d.ts +377 -0
- package/dist/edgar.d.ts.map +1 -0
- package/dist/edgar.js +2418 -0
- package/dist/edgar.js.map +1 -0
- package/dist/errors.d.ts +102 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +247 -0
- package/dist/errors.js.map +1 -0
- package/dist/fac.d.ts +180 -0
- package/dist/fac.d.ts.map +1 -0
- package/dist/fac.js +416 -0
- package/dist/fac.js.map +1 -0
- package/dist/far.d.ts +170 -0
- package/dist/far.d.ts.map +1 -0
- package/dist/far.js +804 -0
- package/dist/far.js.map +1 -0
- package/dist/fdic.d.ts +599 -0
- package/dist/fdic.d.ts.map +1 -0
- package/dist/fdic.js +1624 -0
- package/dist/fdic.js.map +1 -0
- package/dist/federal-register.d.ts +139 -2
- package/dist/federal-register.d.ts.map +1 -1
- package/dist/federal-register.js +432 -15
- package/dist/federal-register.js.map +1 -1
- package/dist/fema.d.ts +181 -0
- package/dist/fema.d.ts.map +1 -0
- package/dist/fema.js +436 -0
- package/dist/fema.js.map +1 -0
- package/dist/fpds.d.ts +108 -0
- package/dist/fpds.d.ts.map +1 -0
- package/dist/fpds.js +519 -0
- package/dist/fpds.js.map +1 -0
- package/dist/gao.d.ts +64 -0
- package/dist/gao.d.ts.map +1 -0
- package/dist/gao.js +640 -0
- package/dist/gao.js.map +1 -0
- package/dist/govinfo.d.ts +111 -0
- package/dist/govinfo.d.ts.map +1 -0
- package/dist/govinfo.js +422 -0
- package/dist/govinfo.js.map +1 -0
- package/dist/grants.d.ts +27 -4
- package/dist/grants.d.ts.map +1 -1
- package/dist/grants.js +114 -11
- package/dist/grants.js.map +1 -1
- package/dist/gsa-csv.d.ts +249 -0
- package/dist/gsa-csv.d.ts.map +1 -0
- package/dist/gsa-csv.js +784 -0
- package/dist/gsa-csv.js.map +1 -0
- package/dist/integrity.d.ts +212 -0
- package/dist/integrity.d.ts.map +1 -0
- package/dist/integrity.js +707 -0
- package/dist/integrity.js.map +1 -0
- package/dist/meta.d.ts +165 -0
- package/dist/meta.d.ts.map +1 -0
- package/dist/meta.js +162 -0
- package/dist/meta.js.map +1 -0
- package/dist/nih.d.ts +117 -0
- package/dist/nih.d.ts.map +1 -0
- package/dist/nih.js +291 -0
- package/dist/nih.js.map +1 -0
- package/dist/nppes.d.ts +157 -0
- package/dist/nppes.d.ts.map +1 -0
- package/dist/nppes.js +648 -0
- package/dist/nppes.js.map +1 -0
- package/dist/nsf.d.ts +176 -0
- package/dist/nsf.d.ts.map +1 -0
- package/dist/nsf.js +554 -0
- package/dist/nsf.js.map +1 -0
- package/dist/nvd.d.ts +176 -0
- package/dist/nvd.d.ts.map +1 -0
- package/dist/nvd.js +912 -0
- package/dist/nvd.js.map +1 -0
- package/dist/ofac.d.ts +205 -0
- package/dist/ofac.d.ts.map +1 -0
- package/dist/ofac.js +919 -0
- package/dist/ofac.js.map +1 -0
- package/dist/pricing.d.ts +110 -0
- package/dist/pricing.d.ts.map +1 -0
- package/dist/pricing.js +843 -0
- package/dist/pricing.js.map +1 -0
- package/dist/sam-gov/client.d.ts +60 -2
- package/dist/sam-gov/client.d.ts.map +1 -1
- package/dist/sam-gov/client.js +320 -54
- package/dist/sam-gov/client.js.map +1 -1
- package/dist/sam-gov/index.d.ts +1 -1
- package/dist/sam-gov/index.d.ts.map +1 -1
- package/dist/sam-gov/index.js +1 -1
- package/dist/sam-gov/index.js.map +1 -1
- package/dist/sam-gov/types.d.ts +24 -0
- package/dist/sam-gov/types.d.ts.map +1 -1
- package/dist/sba.d.ts +72 -0
- package/dist/sba.d.ts.map +1 -0
- package/dist/sba.js +281 -0
- package/dist/sba.js.map +1 -0
- package/dist/server.d.ts +14 -2
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +3897 -295
- package/dist/server.js.map +1 -1
- package/dist/snapshot.d.ts +98 -0
- package/dist/snapshot.d.ts.map +1 -0
- package/dist/snapshot.js +146 -0
- package/dist/snapshot.js.map +1 -0
- package/dist/socrata.d.ts +157 -0
- package/dist/socrata.d.ts.map +1 -0
- package/dist/socrata.js +448 -0
- package/dist/socrata.js.map +1 -0
- package/dist/treasury.d.ts +143 -0
- package/dist/treasury.d.ts.map +1 -0
- package/dist/treasury.js +436 -0
- package/dist/treasury.js.map +1 -0
- package/dist/usaspending.d.ts +260 -65
- package/dist/usaspending.d.ts.map +1 -1
- package/dist/usaspending.js +1664 -228
- package/dist/usaspending.js.map +1 -1
- package/dist/usitc.d.ts +142 -0
- package/dist/usitc.d.ts.map +1 -0
- package/dist/usitc.js +339 -0
- package/dist/usitc.js.map +1 -0
- package/package.json +24 -2
- package/src/attachments.ts +652 -0
- package/src/bls.ts +1943 -0
- package/src/cache.ts +73 -0
- package/src/census.ts +735 -0
- package/src/ckan.ts +495 -0
- package/src/clinicaltrials.ts +923 -0
- package/src/cms.ts +634 -0
- package/src/coerce.ts +47 -0
- package/src/datagov-catalog.ts +296 -0
- package/src/datagov.ts +907 -0
- package/src/datagovKey.ts +68 -0
- package/src/datasource.ts +721 -0
- package/src/disclosure.ts +61 -0
- package/src/ecfr.ts +231 -127
- package/src/echo.ts +496 -0
- package/src/edgar.ts +3014 -0
- package/src/errors.ts +303 -0
- package/src/fac.ts +529 -0
- package/src/far.ts +1007 -0
- package/src/fdic.ts +2052 -0
- package/src/federal-register.ts +706 -191
- package/src/fema.ts +541 -0
- package/src/fpds.ts +620 -0
- package/src/gao.ts +744 -0
- package/src/govinfo.ts +497 -0
- package/src/grants.ts +290 -155
- package/src/gsa-csv.ts +992 -0
- package/src/integrity.ts +928 -0
- package/src/meta.ts +292 -0
- package/src/nih.ts +375 -0
- package/src/nppes.ts +834 -0
- package/src/nsf.ts +706 -0
- package/src/nvd.ts +1124 -0
- package/src/ofac.ts +1166 -0
- package/src/pricing.ts +1075 -0
- package/src/sam-gov/client.ts +345 -63
- package/src/sam-gov/index.ts +5 -1
- package/src/sam-gov/types.ts +22 -0
- package/src/sba.ts +357 -0
- package/src/server.ts +4559 -327
- package/src/snapshot.ts +192 -0
- package/src/socrata.ts +532 -0
- package/src/treasury.ts +575 -0
- package/src/usaspending.ts +2680 -925
- package/src/usitc.ts +420 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* disclosure.ts — the single audited disclosure-note TOKENIZER shared across the
|
|
3
|
+
* keyless DataSources (ADR-0022: an honesty-layer primitive, split into its own
|
|
4
|
+
* tiny single-concern module — the sibling of coerce.ts's map-layer primitives).
|
|
5
|
+
*
|
|
6
|
+
* WHY IT EXISTS: two independent sources (NSF Awards C108 = the OR-note,
|
|
7
|
+
* ClinicalTrials.gov C109 = the AND-note) each built a mandatory multi-token
|
|
8
|
+
* disclosure note from the SAME character-for-character delimiter class, and
|
|
9
|
+
* adversarial verification caught the SAME latent gap on BOTH — a whitespace-only
|
|
10
|
+
* `.split(/\s+/)` misses the API's PUNCTUATION delimiters, so a compound that only
|
|
11
|
+
* LOOKS like one token ("coral-reef" = coral OR reef; "Sanofi-Aventis" = Sanofi
|
|
12
|
+
* AND Aventis) leaks through and the mandatory note is silently SKIPPED. Hoisting
|
|
13
|
+
* ONE audited tokenizer removes the drift risk (a class regression now fails NSF
|
|
14
|
+
* AND ClinicalTrials suites at once instead of silently in one) and gives the lint
|
|
15
|
+
* guardrail (lint-invariants.mjs) + the parity fault test a single home to point
|
|
16
|
+
* at: "the ONLY sanctioned way to tokenize a disclosure value lives here."
|
|
17
|
+
*
|
|
18
|
+
* THE CLASS (`DISCLOSURE_SPLIT_RE`) is the PRECISE ES/Essie confirmed-splitter set,
|
|
19
|
+
* live-verified byte-identically on BOTH sources 2026-07-12:
|
|
20
|
+
* - SPLIT (→ multi-token, the note fires): whitespace + `- , / ; + & | @ # =`
|
|
21
|
+
* - DO NOT split (→ one token, no note): `. : _ '` (NSF also `\` `*`)
|
|
22
|
+
* It is deliberately NOT a `[^A-Za-z0-9]+` superset — that would over-disclose a
|
|
23
|
+
* split the APIs did NOT make on `.`/`_`/`'` (a fabricated union/conjunction). `-`
|
|
24
|
+
* is placed LAST (a literal, not a range); `/` is escaped for the regex delimiter.
|
|
25
|
+
*
|
|
26
|
+
* NOTE-AGNOSTIC BY DESIGN: this returns ONLY the token array. The `.length > 1`
|
|
27
|
+
* decision, the per-source note WORDING (NSF = OR-union, ClinicalTrials = AND
|
|
28
|
+
* co-occurrence), and any downstream suppression (ClinicalTrials' sponsor
|
|
29
|
+
* broadening-note) stay in each CALLER — they are genuinely source-specific and do
|
|
30
|
+
* NOT belong to the tokenizer.
|
|
31
|
+
*
|
|
32
|
+
* THE OPTIONAL `splitRe` PARAM is the sanctioned, honest escape hatch: a FUTURE
|
|
33
|
+
* source whose analyzer genuinely splits on a DIFFERENT class routes through THIS
|
|
34
|
+
* helper with its own `splitRe` (explicit, greppable, reviewable) rather than
|
|
35
|
+
* re-inlining a raw `.split(/\s+/)`. That is exactly what lets the lint ban the
|
|
36
|
+
* bare whitespace split outright (there is one sanctioned tokenizer, not many).
|
|
37
|
+
*
|
|
38
|
+
* No new dep, no I/O, pure function — the exact shape of a coerce.ts primitive.
|
|
39
|
+
*/
|
|
40
|
+
/**
|
|
41
|
+
* The shared ES/Essie confirmed-splitter class (byte-identical to NSF's former
|
|
42
|
+
* `NSF_KEYWORD_SPLIT_RE` and ClinicalTrials' former `CT_TOKEN_SPLIT_RE`). Stateless
|
|
43
|
+
* (no `/g`), so a single module-level RegExp is safe to share across callers.
|
|
44
|
+
*/
|
|
45
|
+
export const DISCLOSURE_SPLIT_RE = /[\s,;+&|@#=\/-]+/;
|
|
46
|
+
/**
|
|
47
|
+
* Tokenize a disclosure value for a multi-token honesty note: trim, split on the
|
|
48
|
+
* confirmed-splitter class (default `DISCLOSURE_SPLIT_RE`), and drop empty tokens.
|
|
49
|
+
* Returns ONLY the token array — the caller owns the `.length > 1` gate + note
|
|
50
|
+
* wording. `tokenizeForDisclosure("coral-reef")` → `["coral", "reef"]`;
|
|
51
|
+
* `tokenizeForDisclosure("web_service")` → `["web_service"]` (the class does NOT
|
|
52
|
+
* split `_`); `tokenizeForDisclosure("robotics")` → `["robotics"]`.
|
|
53
|
+
*/
|
|
54
|
+
export function tokenizeForDisclosure(value, splitRe = DISCLOSURE_SPLIT_RE) {
|
|
55
|
+
return value.trim().split(splitRe).filter((t) => t.length > 0);
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=disclosure.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"disclosure.js","sourceRoot":"","sources":["../src/disclosure.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAEH;;;;GAIG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,kBAAkB,CAAC;AAEtD;;;;;;;GAOG;AACH,MAAM,UAAU,qBAAqB,CACnC,KAAa,EACb,UAAkB,mBAAmB;IAErC,OAAO,KAAK,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AACjE,CAAC"}
|
package/dist/ecfr.d.ts
CHANGED
|
@@ -25,8 +25,9 @@ export declare function listTitles(): Promise<{
|
|
|
25
25
|
export declare function search(args: {
|
|
26
26
|
query: string;
|
|
27
27
|
titleNumber?: number;
|
|
28
|
+
chapter?: number;
|
|
28
29
|
perPage?: number;
|
|
29
|
-
}): Promise<{
|
|
30
|
+
}): Promise<import("./meta.js").MetaBundle<{
|
|
30
31
|
results: {
|
|
31
32
|
type: string;
|
|
32
33
|
title: string;
|
|
@@ -39,6 +40,7 @@ export declare function search(args: {
|
|
|
39
40
|
score: number;
|
|
40
41
|
ecfrUrl: string;
|
|
41
42
|
effectiveOn: string;
|
|
43
|
+
endsOn: string | null;
|
|
42
44
|
}[];
|
|
43
|
-
}
|
|
45
|
+
}>>;
|
|
44
46
|
//# sourceMappingURL=ecfr.d.ts.map
|
package/dist/ecfr.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ecfr.d.ts","sourceRoot":"","sources":["../src/ecfr.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;
|
|
1
|
+
{"version":3,"file":"ecfr.d.ts","sourceRoot":"","sources":["../src/ecfr.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AA2BH,wBAAsB,UAAU;;;;;;;;;GAyB/B;AAED,wBAAsB,MAAM,CAAC,IAAI,EAAE;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;;;;;;;;;;;;;;;IA0IA"}
|
package/dist/ecfr.js
CHANGED
|
@@ -12,29 +12,38 @@
|
|
|
12
12
|
*
|
|
13
13
|
* Both keyless. Documented at https://www.ecfr.gov/developers/.
|
|
14
14
|
*/
|
|
15
|
+
import { fetchWithRetry } from "./errors.js";
|
|
16
|
+
import { driftError } from "./datasource.js";
|
|
17
|
+
import { memoize } from "./cache.js";
|
|
18
|
+
import { withMeta } from "./meta.js";
|
|
15
19
|
const ECFR = "https://www.ecfr.gov/api";
|
|
20
|
+
// eCFR's /search/v1/results `meta.total_count` is capped by Elasticsearch's
|
|
21
|
+
// `index.max_result_window` (live-verified 10,000). A total AT OR ABOVE this
|
|
22
|
+
// sentinel is a LOWER BOUND, not an exact count — see the totalIsLowerBound
|
|
23
|
+
// wiring in `search` (D1). A genuine count below this stays exact.
|
|
24
|
+
const ECFR_TOTAL_COUNT_CAP = 10000;
|
|
16
25
|
async function fetchJson(url) {
|
|
17
|
-
const r = await
|
|
26
|
+
const r = await fetchWithRetry(url, {
|
|
18
27
|
headers: { Accept: "application/json" },
|
|
19
28
|
signal: AbortSignal.timeout(15_000),
|
|
20
|
-
});
|
|
21
|
-
if (!r.ok) {
|
|
22
|
-
throw new Error(`eCFR ${url} returned ${r.status}`);
|
|
23
|
-
}
|
|
29
|
+
}, `ecfr:${url.split("/api/")[1] ?? url}`);
|
|
24
30
|
return (await r.json());
|
|
25
31
|
}
|
|
26
32
|
export async function listTitles() {
|
|
27
|
-
|
|
28
|
-
return {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
// 50 CFR titles change very infrequently. Cache aggressively (5 min).
|
|
34
|
+
return memoize("ecfr:titles", async () => {
|
|
35
|
+
const json = await fetchJson(`${ECFR}/versioner/v1/titles.json`);
|
|
36
|
+
return {
|
|
37
|
+
titles: (json.titles ?? []).map((t) => ({
|
|
38
|
+
number: t.number ?? 0,
|
|
39
|
+
name: t.name ?? "",
|
|
40
|
+
latestAmendedOn: t.latest_amended_on,
|
|
41
|
+
latestIssueDate: t.latest_issue_date,
|
|
42
|
+
upToDateAsOf: t.up_to_date_as_of,
|
|
43
|
+
reserved: !!t.reserved,
|
|
44
|
+
})),
|
|
45
|
+
};
|
|
46
|
+
});
|
|
38
47
|
}
|
|
39
48
|
export async function search(args) {
|
|
40
49
|
const url = new URL(`${ECFR}/search/v1/results`);
|
|
@@ -45,8 +54,28 @@ export async function search(args) {
|
|
|
45
54
|
// an "unpermitted parameter" error from the eCFR API).
|
|
46
55
|
url.searchParams.set("hierarchy[title]", String(args.titleNumber));
|
|
47
56
|
}
|
|
57
|
+
// Optional chapter filter (additive; existing ecfr_search callers pass none).
|
|
58
|
+
// Within Title 48: chapter 1 = FAR, chapter 2 = DFARS, chapter 5 = GSAM, etc.
|
|
59
|
+
// This is what lets far_search scope to FAR/DFARS and keep GSAM/agency
|
|
60
|
+
// supplements out server-side. Same hierarchy[…] contract as the title filter.
|
|
61
|
+
if (args.chapter !== undefined) {
|
|
62
|
+
url.searchParams.set("hierarchy[chapter]", String(args.chapter));
|
|
63
|
+
}
|
|
48
64
|
const json = await fetchJson(url.toString());
|
|
49
|
-
|
|
65
|
+
// F6 (P2 empty-vs-outage): a 200 whose `results` is PRESENT-but-non-array — or
|
|
66
|
+
// a body carrying NEITHER a `results` array NOR a `meta` object — is drift / an
|
|
67
|
+
// unexpected shape, NOT a genuine no-match. Throw (schema_drift) rather than
|
|
68
|
+
// letting `(json.results ?? []).map` coalesce it into a fake AUTHORITATIVE empty.
|
|
69
|
+
// A GENUINE empty (results:[] with meta.total_count:0) flows through honestly
|
|
70
|
+
// below. (eCFR normally signals errors via HTTP status caught by fetchWithRetry;
|
|
71
|
+
// this closes the previously-unhandled + untested 200-body drift path.)
|
|
72
|
+
if (json.results !== undefined && !Array.isArray(json.results)) {
|
|
73
|
+
throw driftError("ecfr.gov", "eCFR search returned HTTP 200 but `results` is not an array — treating it as schema drift, NOT an empty result set.");
|
|
74
|
+
}
|
|
75
|
+
if (json.results === undefined && json.meta === undefined) {
|
|
76
|
+
throw driftError("ecfr.gov", "eCFR search returned HTTP 200 with neither a `results` array nor a `meta` object — an unexpected shape; treating it as schema drift, NOT an empty result set.");
|
|
77
|
+
}
|
|
78
|
+
const data = {
|
|
50
79
|
results: (json.results ?? []).map((r) => ({
|
|
51
80
|
type: r.type ?? "",
|
|
52
81
|
title: r.hierarchy?.title ?? "",
|
|
@@ -64,8 +93,54 @@ export async function search(args) {
|
|
|
64
93
|
? buildEcfrUrl(r.hierarchy)
|
|
65
94
|
: "",
|
|
66
95
|
effectiveOn: r.starts_on ?? "",
|
|
96
|
+
// Additive: the version's end date. null = the CURRENT (in-force) version;
|
|
97
|
+
// a non-null date = a HISTORICAL version. eCFR search returns ~5 versions
|
|
98
|
+
// per section; existing ecfr_search callers simply ignore this extra field,
|
|
99
|
+
// while far_search uses it to collapse historical dups to the current one.
|
|
100
|
+
endsOn: r.ends_on ?? null,
|
|
67
101
|
})),
|
|
68
102
|
};
|
|
103
|
+
// Truthful `_meta` (spec §1.2 A6, §2.3). eCFR returns a hit count in
|
|
104
|
+
// `meta.total_count`, BUT that count is capped by Elasticsearch's
|
|
105
|
+
// `index.max_result_window` at 10,000 (a real ceiling — unlike a genuine
|
|
106
|
+
// small count, a value at/above the cap is a LOWER BOUND, not an exact
|
|
107
|
+
// total). Below the cap `totalAvailable` is exact (the AI can tell a top-N
|
|
108
|
+
// slice from the full match set); at/above the cap we flag
|
|
109
|
+
// `totalIsLowerBound:true` + a note so a broad query that truly matches
|
|
110
|
+
// >10,000 sections is NOT reported as if exactly 10,000 (D1). A6: echo the
|
|
111
|
+
// applied title scope so the AI can VERIFY it searched the intended corpus —
|
|
112
|
+
// Title 48 (FAR) vs every CFR title — rather than silently trusting a filter
|
|
113
|
+
// that could return cross-title results if the eCFR param contract ever changes.
|
|
114
|
+
const returned = data.results.length;
|
|
115
|
+
const totalAvailable = typeof json.meta?.total_count === "number" ? json.meta.total_count : null;
|
|
116
|
+
// eCFR's search total_count saturates at the Elasticsearch max_result_window
|
|
117
|
+
// (live-verified 10,000). Use `>= cap` (not `=== cap`) so a total AT OR ABOVE
|
|
118
|
+
// the ceiling is treated as a lower bound — strictly safe if the window were
|
|
119
|
+
// ever configured higher. Mirrors federal-register.ts's FR_COUNT_CAP and
|
|
120
|
+
// edgar.ts's FTS_WINDOW.
|
|
121
|
+
const totalIsLowerBound = totalAvailable !== null && totalAvailable >= ECFR_TOTAL_COUNT_CAP;
|
|
122
|
+
const scopeNote = args.titleNumber !== undefined
|
|
123
|
+
? `searched CFR Title ${args.titleNumber}${args.titleNumber === 48 ? " (FAR — Federal Acquisition Regulation)" : ""} only`
|
|
124
|
+
: "searched all CFR titles (no title filter applied)";
|
|
125
|
+
const notes = [scopeNote];
|
|
126
|
+
if (totalIsLowerBound) {
|
|
127
|
+
notes.push(`eCFR caps total_count at ${ECFR_TOTAL_COUNT_CAP} (Elasticsearch index.max_result_window); totalAvailable is a LOWER BOUND — the true match count may be higher and is UNKNOWN. See totalIsLowerBound. Narrow by title/chapter/date for an exact count.`);
|
|
128
|
+
}
|
|
129
|
+
return withMeta(data, {
|
|
130
|
+
source: "ecfr.gov/api (search/v1)",
|
|
131
|
+
keylessMode: true,
|
|
132
|
+
returned,
|
|
133
|
+
totalAvailable,
|
|
134
|
+
// Explicit boolean (not conditional): a below-cap count is DEFINITIVELY
|
|
135
|
+
// exact (totalIsLowerBound:false), an at/above-cap count is a lower bound
|
|
136
|
+
// (true). The AI can trust `false` as "this is the real total".
|
|
137
|
+
totalIsLowerBound,
|
|
138
|
+
truncated: totalAvailable !== null ? returned < totalAvailable : undefined,
|
|
139
|
+
filtersApplied: args.titleNumber !== undefined ? ["titleNumber"] : [],
|
|
140
|
+
filtersDropped: [],
|
|
141
|
+
fieldsUnavailable: [],
|
|
142
|
+
notes,
|
|
143
|
+
});
|
|
69
144
|
}
|
|
70
145
|
function stripHtml(s) {
|
|
71
146
|
return s
|
package/dist/ecfr.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ecfr.js","sourceRoot":"","sources":["../src/ecfr.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,MAAM,IAAI,GAAG,0BAA0B,CAAC;AAExC,KAAK,UAAU,SAAS,CAAI,GAAW;IACrC,MAAM,CAAC,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"ecfr.js","sourceRoot":"","sources":["../src/ecfr.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EA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AAE;QAClB,iBAAiB,EAAE,EAAE;QACrB,KAAK;KACN,CAAC,CAAC;AACL,CAAC;AAED,SAAS,SAAS,CAAC,CAAS;IAC1B,OAAO,CAAC;SACL,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC;SACvB,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC;SACpB,IAAI,EAAE,CAAC;AACZ,CAAC;AAED,SAAS,YAAY,CAAC,CAKrB;IACC,MAAM,IAAI,GAAG,sCAAsC,CAAC,CAAC,KAAK,EAAE,CAAC;IAC7D,IAAI,CAAC,CAAC,OAAO;QAAE,OAAO,GAAG,IAAI,YAAY,CAAC,CAAC,OAAO,EAAE,CAAC;IACrD,IAAI,CAAC,CAAC,IAAI;QAAE,OAAO,GAAG,IAAI,SAAS,CAAC,CAAC,IAAI,EAAE,CAAC;IAC5C,IAAI,CAAC,CAAC,OAAO;QAAE,OAAO,GAAG,IAAI,YAAY,CAAC,CAAC,OAAO,EAAE,CAAC;IACrD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/dist/echo.d.ts
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EPA ECHO REST services — keyless facility environmental compliance / enforcement
|
|
3
|
+
* screening (ADR-0009). A NEW capability axis for the product: facility &
|
|
4
|
+
* competitor environmental compliance-risk screening / due diligence (EPA
|
|
5
|
+
* enforcement, inspection, violation, and penalty history keyed to a facility),
|
|
6
|
+
* orthogonal to the spend/contract/regulatory layers.
|
|
7
|
+
*
|
|
8
|
+
* The THIRD source on the R2 `DataSource` port (ADR-0005, after Socrata/CKAN):
|
|
9
|
+
* `echo.ts` writes ZERO fetch/coercion/error code — it REUSES `getJson` /
|
|
10
|
+
* `driftError` / `num`·`str` / `withMeta`, and COPIES (does NOT import) the
|
|
11
|
+
* fixed-host SSRF + honesty PATTERN. Fully PUBLIC, KEYLESS (`keylessMode:true`,
|
|
12
|
+
* byte-clean init — NO headers, like ckan.ts). ECHO is neither Socrata nor CKAN:
|
|
13
|
+
* it is a bespoke Oracle-PL/SQL-fronted REST facade with a TWO-STEP QueryID
|
|
14
|
+
* pagination model and a 200-with-error-body failure mode.
|
|
15
|
+
*
|
|
16
|
+
* Step 1 (search): https://echodata.epa.gov/echo/echo_rest_services.get_facilities?output=JSON&p_st=…
|
|
17
|
+
* → { Results:{ Message, QueryRows:"N", …counts…, QueryID:"n" } } (NO rows)
|
|
18
|
+
* Step 2 (rows): https://echodata.epa.gov/echo/echo_rest_services.get_qid?output=JSON&qid=n&pageno=k
|
|
19
|
+
* → { Results:{ Message:"Working", Facilities:[ …rows… ] } }
|
|
20
|
+
* Detail (DFR): https://echodata.epa.gov/echo/dfr_rest_services.get_dfr?output=JSON&p_id={RegistryID}
|
|
21
|
+
* → { Results:{ Message:"Success", RegistryID, Reports, Permits, … } }
|
|
22
|
+
*
|
|
23
|
+
* ★ SSRF GUARD (policy① — the central design risk; a TIGHTER copy of the
|
|
24
|
+
* Socrata/CKAN fixed-host shape). The attack surface is SMALLER than CKAN's:
|
|
25
|
+
* (1) SINGLE fixed host constant `ECHO_HOST` — the caller NEVER supplies a host.
|
|
26
|
+
* (2) THREE fixed service-path constants (a frozen Set) — the caller NEVER
|
|
27
|
+
* supplies a path fragment; a service outside the Set ⇒ invalid_input before
|
|
28
|
+
* any fetch (the path-injection guard).
|
|
29
|
+
* (3) Every interpolated id is grammar-validated BEFORE use — `state` ∈ a frozen
|
|
30
|
+
* US state/territory enum (also the silent-zero guard, below); `naics`
|
|
31
|
+
* ^[0-9]{2,6}$ / `sic` ^[0-9]{2,4}$; `registryId` ^[0-9]{9,12}$ (FRS IDs are
|
|
32
|
+
* 12 digits; all-digit is the security property); the UPSTREAM-supplied
|
|
33
|
+
* `qid` is validated ^[0-9]+$ BECAUSE it is external (echodata.epa.gov mints
|
|
34
|
+
* it), before it is used in step 2; the internally-computed `pageno` is a
|
|
35
|
+
* plain integer. `facilityName` (p_fn) is a free-text filter VALUE — encoded
|
|
36
|
+
* through URLSearchParams, never touching the host/path.
|
|
37
|
+
* (4) Construct the URL, then ASSERT `new URL(built).hostname === ECHO_HOST` and
|
|
38
|
+
* `protocol === "https:"` ⇒ invalid_input on mismatch (belt-and-suspenders).
|
|
39
|
+
* B1 (redirect SSRF): every getJson sets `redirect:"error"` — a 3xx off
|
|
40
|
+
* echodata.epa.gov (migration / DNS-hijack / reused domain) throws; its body is
|
|
41
|
+
* never read. Adding a service/filter later = a CONSTANT edit + a live
|
|
42
|
+
* `output=JSON` verification — NEVER a free runtime host/path param.
|
|
43
|
+
*
|
|
44
|
+
* ★ 200-WITH-ERROR-BODY (the fake-empty trap — OBSERVED live, not defensive).
|
|
45
|
+
* A bogus `qid`, a bad DFR `p_id`, AND a queryset-limit overflow all return HTTP
|
|
46
|
+
* 200 carrying `{Results:{Error:{ErrorMessage}}}`. `errorFromResponse` keys off
|
|
47
|
+
* HTTP status and would pass a 200 straight through. So on EVERY response we
|
|
48
|
+
* detect `Results.Error` FIRST and THROW (classified) BEFORE reading
|
|
49
|
+
* QueryRows/Facilities — the ECHO analogue of CKAN's success:false-on-200 guard.
|
|
50
|
+
* Classification (by ErrorMessage):
|
|
51
|
+
* - "Queryset Limit would be exceeded" ⇒ invalid_input (narrow the query)
|
|
52
|
+
* - "…not found in ECHO" (recycled qid) ⇒ not_found, RETRYABLE (the QueryID
|
|
53
|
+
* is an ephemeral globally-recycled slot — a transient, not a missing
|
|
54
|
+
* facility; retry echo_search_facilities)
|
|
55
|
+
* - "ID … is invalid" (bad DFR id) ⇒ not_found (no report for that id)
|
|
56
|
+
* - anything else ⇒ schema_drift (surfaced, never
|
|
57
|
+
* silently swallowed)
|
|
58
|
+
*
|
|
59
|
+
* ★ TWO-STEP HIDDEN IN-CALL (ADR-0009 §1a). The QueryID is an ephemeral,
|
|
60
|
+
* globally-recycled, monotonically-incrementing cache slot (live-verified:
|
|
61
|
+
* IDs jumped 835→909 across a handful of calls) — NOT deterministic, NOT safe to
|
|
62
|
+
* persist across tool calls. `echo_search_facilities` therefore performs BOTH
|
|
63
|
+
* steps inside ONE invocation (get_facilities → capture QueryRows + fresh
|
|
64
|
+
* QueryID → immediately get_qid at the requested page) and NEVER exposes the
|
|
65
|
+
* QueryID to the caller. Paginating to page N re-runs get_facilities fresh.
|
|
66
|
+
* Two HTTP round-trips per search; robust against id recycling (memoize is
|
|
67
|
+
* unsafe here). Pagination is the standard offset/limit contract, translated to
|
|
68
|
+
* `pageno = offset/limit + 1` and `responseset = limit`; because ECHO can only
|
|
69
|
+
* page on page boundaries, `offset` MUST be an exact multiple of `limit`
|
|
70
|
+
* (else invalid_input locally, before any fetch).
|
|
71
|
+
*
|
|
72
|
+
* ★ M2 — NAICS vs SIC filtering, LIVE-VERIFIED 2026-07-12 (the data-lie guard).
|
|
73
|
+
* `p_st=DC` bare ⇒ QueryRows 4714. `p_st=DC&p_naics=325` / `=32511` / `=54` /
|
|
74
|
+
* even a bogus `=999999` ALL returned the identical 4714 ⇒ ECHO DROPS NAICS
|
|
75
|
+
* entirely (a real filter would return 0 for a nonexistent code). BUT
|
|
76
|
+
* `p_st=DC&p_sic=2911` ⇒ 1 and `&p_sic=9999`/`=8011` ⇒ 0 ⇒ SIC DOES narrow.
|
|
77
|
+
* So the two behave DIFFERENTLY (a MIXED outcome — a deviation from the ADR's
|
|
78
|
+
* unified Case-A/B framing):
|
|
79
|
+
* - `sic` = Case A (works) ⇒ a REAL filter; listed in filtersApplied.
|
|
80
|
+
* - `naics` = Case B (dropped) ⇒ BEST-EFFORT: marked best-effort in the
|
|
81
|
+
* tool-schema description, added to `_meta.filtersDropped` whenever passed,
|
|
82
|
+
* AND a `_meta.notes` disclosure warns the returned facilities are NOT
|
|
83
|
+
* guaranteed to match the NAICS code. NEVER silently presented as filtered.
|
|
84
|
+
*
|
|
85
|
+
* ★ HONESTY (`_meta`; REUSE withMeta/buildMeta). `totalAvailable = num(QueryRows)`
|
|
86
|
+
* — the EXACT upstream total, NEVER the page size. `returned =
|
|
87
|
+
* Results.Facilities.length`. `hasMore = offset + returned < total` (exact — no
|
|
88
|
+
* page-fullness hedge). Genuine-empty (`QueryRows:"0"`, no Results.Error) ⇒
|
|
89
|
+
* complete:true / totalAvailable:0. Outage/5xx/timeout ⇒ getJson throws (never a
|
|
90
|
+
* fake empty). `num`/`str` are null-never-0. Row-level currency/count fields
|
|
91
|
+
* (e.g. TotalPenalties "$1,056,616") pass through VERBATIM.
|
|
92
|
+
*/
|
|
93
|
+
import { num } from "./coerce.js";
|
|
94
|
+
import { type MetaBundle } from "./meta.js";
|
|
95
|
+
export { num };
|
|
96
|
+
export declare const ECHO_STATES: readonly ["AL", "AK", "AZ", "AR", "CA", "CO", "CT", "DE", "DC", "FL", "GA", "HI", "ID", "IL", "IN", "IA", "KS", "KY", "LA", "ME", "MD", "MA", "MI", "MN", "MS", "MO", "MT", "NE", "NV", "NH", "NJ", "NM", "NY", "NC", "ND", "OH", "OK", "OR", "PA", "RI", "SC", "SD", "TN", "TX", "UT", "VT", "VA", "WA", "WV", "WI", "WY", "AS", "GU", "MP", "PR", "VI"];
|
|
97
|
+
export type EchoState = (typeof ECHO_STATES)[number];
|
|
98
|
+
export type EchoRow = Record<string, unknown>;
|
|
99
|
+
/**
|
|
100
|
+
* GET one ECHO REST service. SSRF guard: `service` ∈ the frozen 3-member Set
|
|
101
|
+
* (the path-injection guard), params via URLSearchParams (encoded values, no
|
|
102
|
+
* host-alteration surface), then the CONSTRUCTED URL's hostname === ECHO_HOST
|
|
103
|
+
* (https) assertion. Sets `redirect:"error"` (B1); NO headers (keyless — ECHO is
|
|
104
|
+
* anonymous, byte-clean init). Reuses errors.ts retry/timeout/taxonomy (429 →
|
|
105
|
+
* rate_limited; 5xx → upstream_unavailable; 404 → not_found; 400 → invalid_input).
|
|
106
|
+
* Returns the parsed JSON (unknown; the caller validates the Results envelope).
|
|
107
|
+
*/
|
|
108
|
+
export declare function echoGet(service: string, params: URLSearchParams): Promise<unknown>;
|
|
109
|
+
/**
|
|
110
|
+
* Search EPA-regulated facilities by state (+ optional sic / facilityName /
|
|
111
|
+
* majorOnly / federalOnly / naics-best-effort) with compliance/enforcement
|
|
112
|
+
* screening fields. The workhorse: state + industry + name + major/federal
|
|
113
|
+
* across CAA/CWA/RCRA/SDWA. `state` is REQUIRED (an unscoped national query is
|
|
114
|
+
* ~5.6M rows AND the state enum is the silent-zero guard).
|
|
115
|
+
*
|
|
116
|
+
* Hides the two-step QueryID pagination behind ONE call: internally get_facilities
|
|
117
|
+
* (→ exact QueryRows + a fresh QueryID) then get_qid?pageno=offset/limit+1 (→ the
|
|
118
|
+
* rows). The QueryID is captured and consumed in-call, NEVER exposed. Rows pass
|
|
119
|
+
* through verbatim. HONESTY: totalAvailable = num(QueryRows) (exact, never the page
|
|
120
|
+
* size); genuine-empty (QueryRows:"0") ⇒ complete:true/total:0; a Results.Error ⇒
|
|
121
|
+
* classified throw (never a fake empty); an outage ⇒ getJson throws.
|
|
122
|
+
*/
|
|
123
|
+
export declare function searchFacilities(args: {
|
|
124
|
+
state: EchoState;
|
|
125
|
+
naics?: string;
|
|
126
|
+
sic?: string;
|
|
127
|
+
facilityName?: string;
|
|
128
|
+
majorOnly?: boolean;
|
|
129
|
+
federalOnly?: boolean;
|
|
130
|
+
limit?: number;
|
|
131
|
+
offset?: number;
|
|
132
|
+
}): Promise<MetaBundle>;
|
|
133
|
+
/**
|
|
134
|
+
* Fetch the Detailed Facility Report (DFR) for ONE facility by its FRS RegistryID
|
|
135
|
+
* (from echo_search_facilities rows): the per-facility compliance / enforcement /
|
|
136
|
+
* inspection / permit deep-dive for competitor / acquisition-target due diligence.
|
|
137
|
+
* Single record (no pagination). A bad/unknown RegistryID ⇒ the 200-with-error-
|
|
138
|
+
* body guard classifies "ID … is invalid" ⇒ not_found (never a fabricated report).
|
|
139
|
+
*/
|
|
140
|
+
export declare function facilityReport(args: {
|
|
141
|
+
registryId: string;
|
|
142
|
+
}): Promise<MetaBundle>;
|
|
143
|
+
//# sourceMappingURL=echo.d.ts.map
|
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