edgrapi 0.0.0-stage → 0.1.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.
Files changed (4) hide show
  1. package/README.md +48 -2
  2. package/index.d.ts +48 -0
  3. package/index.js +92 -0
  4. package/package.json +11 -4
package/README.md CHANGED
@@ -1,3 +1,49 @@
1
- # Temporary Holding Version
1
+ # edgrapi (JavaScript)
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ US government and SEC EDGAR data as clean JSON: filings, financials, insider trades, 13F holdings,
4
+ SAM.gov contracts, USAspending awards, grants, lobbying and Congress trades. Zero dependencies,
5
+ Node 18+. Python users: `pip install edgrapi`.
6
+
7
+ ```bash
8
+ npm install edgrapi
9
+ ```
10
+
11
+ Get a key at https://edgrapi.com/app (50 free credits, no card). Set `EDGRAPI_KEY` or pass it in.
12
+ Keys go in a header, never in a URL.
13
+
14
+ ## Examples
15
+
16
+ ```js
17
+ const { Client } = require("edgrapi");
18
+ const ed = new Client(process.env.EDGRAPI_KEY);
19
+
20
+ // 1. Company profile (1 credit)
21
+ const co = await ed.company("AAPL");
22
+ console.log(co.company, co.creditsCost, co.creditsRemaining);
23
+
24
+ // 2. Five years of annual financials
25
+ const f = await ed.fundamentals("NVDA", { period: "annual", limit: 5 });
26
+ f.income_statement.forEach((r) => console.log(r.period, r.revenue, r.first_reported));
27
+
28
+ // 3. Today's biggest open-market insider buys
29
+ const buys = await ed.latestInsiderBuys({ minValue: 100000 });
30
+ buys.buys.forEach((b) => console.log(b.ticker, b.owner, b.buy_value));
31
+
32
+ // 4. A fund's 13F with quarter-over-quarter changes
33
+ const brk = await ed.holdings("berkshire", { limit: 10 });
34
+ brk.positions.forEach((p) => console.log(p.ticker, p.pct_portfolio, p.change.status));
35
+
36
+ // 5. Congressional trades disclosed in November, newest disclosure first
37
+ let page = await ed.congress({ disclosed_from: "2026-11-01", sort: "disclosure_date", limit: 100 });
38
+ while (true) {
39
+ page.trades.forEach((t) => console.log(t.member, t.ticker, t.action, t.owner));
40
+ if (!page.next_cursor) break;
41
+ page = await ed.congress({ disclosed_from: "2026-11-01", sort: "disclosure_date", limit: 100, cursor: page.next_cursor });
42
+ }
43
+ ```
44
+
45
+ Every response carries `creditsCost` and `creditsRemaining` from the API's headers, and
46
+ `upgradeHints` when your plan returned a preview or a delayed feed. Errors throw `EdgrapiError`,
47
+ `OutOfCredits` (402) or `RateLimited` (429); 429 and 5xx are retried with backoff first.
48
+
49
+ Docs: https://edgrapi.com/docs
package/index.d.ts ADDED
@@ -0,0 +1,48 @@
1
+ export declare const DEFAULT_BASE: string;
2
+
3
+ export declare class EdgrapiError extends Error {
4
+ status?: number;
5
+ body?: unknown;
6
+ }
7
+ export declare class OutOfCredits extends EdgrapiError {}
8
+ export declare class RateLimited extends EdgrapiError {}
9
+
10
+ /** Parsed JSON plus the credit headers from the response. */
11
+ export type EdgrapiResponse<T = Record<string, any>> = T & {
12
+ readonly creditsCost: number | null;
13
+ readonly creditsRemaining: number | null;
14
+ /** Present when your plan returned a preview, a delayed feed or truncated history. */
15
+ readonly upgradeHints: Array<Record<string, any>> | null;
16
+ };
17
+
18
+ export interface ClientOptions { baseUrl?: string; retries?: number; timeoutMs?: number; }
19
+
20
+ export declare class Client {
21
+ constructor(apiKey?: string, opts?: ClientOptions);
22
+ get(path: string, params?: Record<string, unknown>): Promise<EdgrapiResponse>;
23
+ company(ticker: string): Promise<EdgrapiResponse>;
24
+ filings(ticker: string, opts?: { form?: string; limit?: number }): Promise<EdgrapiResponse>;
25
+ fundamentals(ticker: string, opts?: { period?: "annual" | "quarterly"; limit?: number }): Promise<EdgrapiResponse>;
26
+ ratios(ticker: string): Promise<EdgrapiResponse>;
27
+ insider(ticker: string, opts?: { limit?: number; form?: string; minValue?: number }): Promise<EdgrapiResponse>;
28
+ latestInsiderBuys(opts?: { minValue?: number; limit?: number }): Promise<EdgrapiResponse>;
29
+ clusters(opts?: { days?: number; minInsiders?: number; minValue?: number }): Promise<EdgrapiResponse>;
30
+ holdings(fund: string, opts?: { limit?: number; changes?: boolean }): Promise<EdgrapiResponse>;
31
+ activist(identifier: string, opts?: { activistOnly?: boolean; limit?: number }): Promise<EdgrapiResponse>;
32
+ events(ticker: string, opts?: { limit?: number; notable?: boolean; item?: string }): Promise<EdgrapiResponse>;
33
+ restatements(opts?: { limit?: number; days?: number }): Promise<EdgrapiResponse>;
34
+ auditorChanges(opts?: { limit?: number; days?: number }): Promise<EdgrapiResponse>;
35
+ search(q: string, opts?: { forms?: string; startdt?: string; enddt?: string; offset?: number }): Promise<EdgrapiResponse>;
36
+ sections(ticker: string, opts?: { form?: string; item?: string }): Promise<EdgrapiResponse>;
37
+ xbrl(ident: string, opts?: { period?: string; limit?: number; concept?: string }): Promise<EdgrapiResponse>;
38
+ shares(ticker: string, opts?: { history?: boolean }): Promise<EdgrapiResponse>;
39
+ form144(ticker: string, opts?: { limit?: number }): Promise<EdgrapiResponse>;
40
+ formd(ident: string, opts?: { limit?: number }): Promise<EdgrapiResponse>;
41
+ subsidiaries(ident: string): Promise<EdgrapiResponse>;
42
+ resolve(opts: { ticker?: string; cik?: string; cusip?: string }): Promise<EdgrapiResponse>;
43
+ opportunities(params?: Record<string, unknown>): Promise<EdgrapiResponse>;
44
+ awards(params?: Record<string, unknown>): Promise<EdgrapiResponse>;
45
+ grants(params?: Record<string, unknown>): Promise<EdgrapiResponse>;
46
+ lobbying(params?: Record<string, unknown>): Promise<EdgrapiResponse>;
47
+ congress(params?: { ticker?: string } & Record<string, unknown>): Promise<EdgrapiResponse>;
48
+ }
package/index.js ADDED
@@ -0,0 +1,92 @@
1
+ // Edgrapi: US government and SEC EDGAR data as clean JSON. Zero dependencies (Node 18+ fetch).
2
+ // Mirrors the Python client (pip install edgrapi). Send your key as X-API-Key; never in a URL.
3
+ "use strict";
4
+
5
+ const DEFAULT_BASE = "https://api.edgrapi.com";
6
+
7
+ class EdgrapiError extends Error {
8
+ constructor(message, status, body) { super(message); this.name = "EdgrapiError"; this.status = status; this.body = body; }
9
+ }
10
+ class OutOfCredits extends EdgrapiError { constructor(m, s, b) { super(m, s, b); this.name = "OutOfCredits"; } }
11
+ class RateLimited extends EdgrapiError { constructor(m, s, b) { super(m, s, b); this.name = "RateLimited"; } }
12
+
13
+ const seg = (v) => encodeURIComponent(String(v).trim());
14
+ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
15
+
16
+ class Client {
17
+ /**
18
+ * @param {string} [apiKey] defaults to process.env.EDGRAPI_KEY
19
+ * @param {{baseUrl?: string, retries?: number, timeoutMs?: number}} [opts]
20
+ */
21
+ constructor(apiKey, opts = {}) {
22
+ this.apiKey = apiKey || (typeof process !== "undefined" ? process.env.EDGRAPI_KEY : undefined);
23
+ if (!this.apiKey) throw new EdgrapiError("Pass an API key or set EDGRAPI_KEY. Get one at https://edgrapi.com/app.");
24
+ this.baseUrl = (opts.baseUrl || DEFAULT_BASE).replace(/\/$/, "");
25
+ this.retries = opts.retries ?? 2;
26
+ this.timeoutMs = opts.timeoutMs ?? 60000;
27
+ }
28
+
29
+ /** GET any /v1 path. Returns the parsed JSON with credit info attached as non-enumerable fields. */
30
+ async get(path, params = {}) {
31
+ const qs = Object.entries(params).filter(([, v]) => v !== undefined && v !== null)
32
+ .map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`).join("&");
33
+ const url = this.baseUrl + path + (qs ? "?" + qs : "");
34
+ for (let attempt = 0; ; attempt++) {
35
+ const ctl = new AbortController();
36
+ const t = setTimeout(() => ctl.abort(), this.timeoutMs);
37
+ let res;
38
+ try {
39
+ res = await fetch(url, { headers: { "X-API-Key": this.apiKey, "User-Agent": "edgrapi-js/0.1.0" }, signal: ctl.signal });
40
+ } catch (e) {
41
+ clearTimeout(t);
42
+ if (attempt < this.retries) { await sleep(500 * 2 ** attempt); continue; }
43
+ throw new EdgrapiError("Network error: " + e.message);
44
+ }
45
+ clearTimeout(t);
46
+ const text = await res.text();
47
+ let body; try { body = JSON.parse(text); } catch { body = { raw: text }; }
48
+ if ((res.status === 429 || res.status >= 500) && attempt < this.retries) {
49
+ const wait = Number(res.headers.get("retry-after")) * 1000 || 500 * 2 ** attempt;
50
+ await sleep(Math.min(wait, 30000)); continue;
51
+ }
52
+ if (res.status === 402) throw new OutOfCredits(body.detail || "Out of credits", 402, body);
53
+ if (res.status === 429) throw new RateLimited(body.detail || "Rate limited", 429, body);
54
+ if (res.status >= 400) throw new EdgrapiError(body.detail || body.error || `HTTP ${res.status}`, res.status, body);
55
+ const cost = res.headers.get("x-credits-cost"), left = res.headers.get("x-credits-remaining");
56
+ Object.defineProperty(body, "creditsCost", { value: cost === null ? null : Number(cost), enumerable: false });
57
+ Object.defineProperty(body, "creditsRemaining", { value: left === null ? null : Number(left), enumerable: false });
58
+ Object.defineProperty(body, "upgradeHints", { value: (body.meta && body.meta.upgrade_hints) || null, enumerable: false });
59
+ return body;
60
+ }
61
+ }
62
+
63
+ // SEC EDGAR
64
+ company(ticker) { return this.get(`/v1/company/${seg(ticker)}`); }
65
+ filings(ticker, { form, limit } = {}) { return this.get(`/v1/filings/${seg(ticker)}`, { form, limit }); }
66
+ fundamentals(ticker, { period, limit } = {}) { return this.get(`/v1/fundamentals/${seg(ticker)}`, { period, limit }); }
67
+ ratios(ticker) { return this.get(`/v1/ratios/${seg(ticker)}`); }
68
+ insider(ticker, { limit, form, minValue } = {}) { return this.get(`/v1/insider/${seg(ticker)}`, { limit, form, min_value: minValue }); }
69
+ latestInsiderBuys({ minValue, limit } = {}) { return this.get("/v1/insider/latest", { min_value: minValue, limit }); }
70
+ clusters({ days, minInsiders, minValue } = {}) { return this.get("/v1/insider/clusters", { days, min_insiders: minInsiders, min_value: minValue }); }
71
+ holdings(fund, { limit, changes } = {}) { return this.get(`/v1/holdings/${seg(fund)}`, { limit, changes }); }
72
+ activist(identifier, { activistOnly, limit } = {}) { return this.get(`/v1/activist/${seg(identifier)}`, { activist_only: activistOnly, limit }); }
73
+ events(ticker, { limit, notable, item } = {}) { return this.get(`/v1/events/${seg(ticker)}`, { limit, notable, item }); }
74
+ restatements({ limit, days } = {}) { return this.get("/v1/events/restatements", { limit, days }); }
75
+ auditorChanges({ limit, days } = {}) { return this.get("/v1/events/auditor-changes", { limit, days }); }
76
+ search(q, { forms, startdt, enddt, offset } = {}) { return this.get("/v1/search/fulltext", { q, forms, startdt, enddt, offset }); }
77
+ sections(ticker, { form, item } = {}) { return this.get(`/v1/sections/${seg(ticker)}`, { form, item }); }
78
+ xbrl(ident, { period, limit, concept } = {}) { return this.get(`/v1/xbrl/${seg(ident)}`, { period, limit, concept }); }
79
+ shares(ticker, { history } = {}) { return this.get(`/v1/shares/${seg(ticker)}`, { history }); }
80
+ form144(ticker, { limit } = {}) { return this.get(`/v1/form144/${seg(ticker)}`, { limit }); }
81
+ formd(ident, { limit } = {}) { return this.get(`/v1/formd/${seg(ident)}`, { limit }); }
82
+ subsidiaries(ident) { return this.get(`/v1/subsidiaries/${seg(ident)}`); }
83
+ resolve({ ticker, cik, cusip } = {}) { return this.get("/v1/resolve", { ticker, cik, cusip }); }
84
+ // US government data
85
+ opportunities(params = {}) { return this.get("/v1/opportunities", params); }
86
+ awards(params = {}) { return this.get("/v1/awards", params); }
87
+ grants(params = {}) { return this.get("/v1/grants", params); }
88
+ lobbying(params = {}) { return this.get("/v1/lobbying", params); }
89
+ congress({ ticker, ...params } = {}) { return this.get(ticker ? `/v1/congress/${seg(ticker)}` : "/v1/congress", params); }
90
+ }
91
+
92
+ module.exports = { Client, EdgrapiError, OutOfCredits, RateLimited, DEFAULT_BASE };
package/package.json CHANGED
@@ -1,6 +1,13 @@
1
1
  {
2
2
  "name": "edgrapi",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "US government data as clean JSON: SEC EDGAR filings, financials, insider trades, 13F, SAM.gov contracts, USAspending awards, grants, lobbying and Congress trades. Zero dependencies.",
5
+ "main": "index.js",
6
+ "types": "index.d.ts",
7
+ "files": ["index.js", "index.d.ts", "README.md"],
8
+ "engines": { "node": ">=18" },
9
+ "keywords": ["sec", "edgar", "api", "financial-data", "insider-trading", "13f", "sam.gov", "usaspending", "government-data"],
10
+ "homepage": "https://edgrapi.com/docs",
11
+ "author": "Paper and Beyond <support@edgrapi.com>",
12
+ "license": "MIT"
13
+ }