@secblast/sdk
v3.1.0
Published
TypeScript SDK for the SEC Blast v3 API: SEC EDGAR filings, documents, full-text search, and XBRL financial data
Maintainers
Readme
SEC Blast TypeScript SDK
The TypeScript and JavaScript client for the SEC Blast v3 API: SEC EDGAR filings, documents, full-text search, XBRL financial data, ownership data, and the filing stream.
Version 3 targets the v3 API (https://api.secblast.com/v3). Versions 2.x targeted the v2 API.
Install
npm install @secblast/sdkIt runs on Node.js 18 or later, Deno, Bun, and browsers, with the built-in fetch. It has no runtime dependencies. It ships ES modules, CommonJS, and type declarations.
Quickstart
import { SecBlastClient } from '@secblast/sdk';
const client = new SecBlastClient(); // reads SECBLAST_API_KEY
const page = await client.listFilings({ ticker: 'AAPL', form: '10-K', limit: 5 });
for (const filing of page.data) console.log(filing.accession, filing.filing_date);The client
const client = new SecBlastClient({
apiKey: 'sb_...', // an API key or an OAuth access token; default: SECBLAST_API_KEY
baseUrl: 'https://api.secblast.com/v3', // default: SECBLAST_BASE_URL, then this URL
timeoutMs: 60_000,
maxRetries: 3, // retries of 429 and 503 responses
maxRetryWaitMs: 60_000, // the longest Retry-After to wait for
fetch: customFetch, // optional
});The credential is sent as Authorization: Bearer <credential>.
Methods
There is one method for each v3 operation, such as listFilings, getFiling, getEntity, search, getIncomeStatement, listInsiderTransactions, and createEndpoint. Path parameters come first. Query parameters are one object with the API's names. The last argument takes signal, timeoutMs, extraParams, and headers.
const entity = await client.getEntity('AAPL'); // a CIK or a ticker
const filing = await client.getFiling('0000320193-26-000026');
const hits = await client.search({ q: '"going concern"', forms: '10-K', filed_from: '2024-01-01', limit: 10 });
const income = await client.getIncomeStatement('MSFT', { period: 'annual', limit: 5 });- List parameters take an array or a comma-separated string:
ticker: ['AAPL', 'MSFT']andticker: 'AAPL,MSFT'are the same. Booleans are sent astrueandfalse. Dates take a string or aDate(its UTC day is sent). - Every schema in the OpenAPI document is an exported type, such as
Filing,Entity, andSearchHit.
Paging
List methods return one page: data, has_more, and next_cursor. Each paged method has an iter* twin that follows next_cursor until has_more is false. It makes requests as you iterate.
for await (const row of client.iterInsiderTransactions({ issuer_ticker: 'TSLA', filed_from: '2025-01-01' })) {
console.log(row);
}
const page = await client.listFilings({ cik: 320193, limit: 100 });
const next = await client.listFilings({ cik: 320193, limit: 100, cursor: page.next_cursor ?? undefined });Documents
const docs = (await client.listDocuments('0000320193-26-000026')).data;
const raw = await client.getDocument('0000320193-26-000026', 1); // Uint8Array, as filed
const text = await client.getDocumentText('0000320193-26-000026', 1); // string, the extracted text
const pdf = await client.getDocumentPdf('0000320193-26-000026', 1); // Uint8Array, a PDF of one document
const whole = await client.getFilingPdf('0000320193-26-000026'); // Uint8Array, a PDF of the filingA document is named by its sequence number or its file name.
Errors
Every error response throws an APIError subclass built from the RFC 9457 problem body. It has status, code, detail, requestId, parameter, and the whole body in problem. code is stable.
| Status | Error |
|---|---|
| 400, 422 | ValidationError |
| 401 | AuthenticationError |
| 403 | PermissionDeniedError |
| 404 | NotFoundError |
| 409 | ConflictError |
| 410 | GoneError |
| 429 | RateLimitError, with retryAfter in seconds |
| 503 | ServiceUnavailableError |
| other 5xx | ServerError |
No HTTP response (DNS, connection, or timeout) throws APIConnectionError. All of them are SecBlastError.
import { ValidationError } from '@secblast/sdk';
try {
await client.listFilings({ ticker: 'NOPE' });
} catch (e) {
if (e instanceof ValidationError) console.log(e.status, e.code, e.detail, e.requestId); // 400 unknown_ticker ...
}Retries: a 429 or 503 response is retried up to maxRetries times. The client waits for Retry-After when the header is present and at most maxRetryWaitMs; a longer Retry-After throws the error at once. Without the header, it waits about 0.5, 1, 2, and 4 seconds. A GET that gets no response is retried the same way.
Stream
stream() long-polls GET /v3/stream and returns events as they arrive. It takes the getStream filters (forms, tickers, ciks, items, types, and so on).
const stream = client.stream({ after: savedCursor, forms: ['8-K'], items: ['2.02'] });
for await (const event of stream) {
await handle(event); // event.id, event.type, event.data.filing
await save(stream.cursor); // where to resume
}afteris anext_cursorfrom an earlier run, or'now'. Left out, the stream starts at the newest event.stream.cursormoves to a page'snext_cursorafter the last event of that page. Resuming from it in the middle of a page delivers the rest of that page again. Each event has anid.- The iterator runs until you stop it (
break). WithstopWhenCaughtUp: true, it stops when a page hashas_morefalse; addwait: 0to return at once.
Webhooks
verifyWebhook checks the webhook-id, webhook-timestamp, and webhook-signature headers of a delivery (Standard Webhooks v1) against the endpoint's signing secret and returns the parsed JSON body.
import { verifyWebhook, WebhookVerificationError } from '@secblast/sdk/webhooks';
try {
const event = verifyWebhook(rawBody, req.headers as Record<string, string>, 'whsec_...');
} catch (e) {
if (e instanceof WebhookVerificationError) {
// answer 400
}
}- Node only: the verifier is the
@secblast/sdk/webhookssubpath, so the main entry has nonode:cryptoimport and bundles for browsers. rawBodyis the request body as a string or bytes, exactly as received; the signature covers<webhook-id>.<webhook-timestamp>.<body>. A string is encoded as UTF-8 before checking. A body parsed and serialized again (express.json(),JSON.stringify) is not the signed byte sequence and does not verify;express.raw({ type: 'application/json' })keeps the bytes.- Signature check: base64(HMAC-SHA256) with the secret's bytes (the base64 after
whsec_), compared in constant time. The header holds one or more space-separatedv1,<signature>entries; two entries are sent while a rotated secret's previous value still signs, and the delivery verifies when any entry matches.secretcan also be an array ofwhsec_values. - Tolerance: the
webhook-timestampmust be within 5 minutes of the clock (toleranceS: 300;nowsets the reference time, in Unix seconds). A non-finite or negativetoleranceS, or a non-finitenow, throwsWebhookVerificationError. SEC Blast stamps every attempt with its own time. - Deduplication: the
webhook-idis the same on every attempt of a delivery, and is theidin the body. - Throws
WebhookVerificationErrorfor a missing header, a timestamp outside the tolerance, no matchingv1signature, a secret that is not awhsec_value, or a body that is not a JSON object.
License
MIT
