drishti-sdk
v1.0.2
Published
TypeScript/JavaScript client for the Drishti API (/v1)
Maintainers
Readme
Drishti SDK (JavaScript / TypeScript)
Official JavaScript/TypeScript SDK for the Manasija Drishti API (/v1).
This SDK provides:
- A typed HTTP client for all endpoints of drishti api
- A low-level request layer for custom endpoint access
- A WebSocket session client for real-time streams
- Configurable retry/backoff for transient HTTP failures
Requirements
- Node.js
18+, or a modern browser withfetchandWebSocket - A valid Drishti API key
Installation
Install from npm:
npm install drishti-sdkOr load the browser bundle from a CDN (demos and prototypes only — see warning below):
<script src="https://cdn.jsdelivr.net/npm/drishti-sdk"></script>
<script>
const { DrishtiClient } = DrishtiSDK;
const client = new DrishtiClient({ apiKey: "YOUR_API_KEY" });
</script>Warning: Any API key used in the browser is visible in page source and network requests. Use the CDN bundle only for demos, prototypes, or internal tools where users supply their own key. For production apps, install with npm on the server or proxy Drishti calls through your backend.
Unpkg works the same way:
<script src="https://unpkg.com/drishti-sdk"></script>Pin a package version in the URL when you ship a prototype, for example https://cdn.jsdelivr.net/npm/[email protected].
If you are developing this package locally:
npm install
npm run buildQuick Start
import { DrishtiClient } from "drishti-sdk";
const client = new DrishtiClient({
apiKey: process.env.DRISHTI_API_KEY!,
});
const news = await client.getNews({
symbols: ["RELIANCE", "TCS"],
limit: 10,
});
console.log(news.data.length);All SDK calls automatically send X-API-Key using the key passed to DrishtiClient.
Retry Configuration
Retries are configurable globally on the client and per request.
import { DrishtiClient } from "drishti-sdk";
const client = new DrishtiClient({
apiKey: process.env.DRISHTI_API_KEY!,
retry: {
maxRetries: 3,
initialDelayMs: 250,
maxDelayMs: 4000,
multiplier: 2,
retryOnStatuses: [408, 429, 500, 502, 503, 504],
},
});
const news = await client.get("/v1/news", {
query: { limit: 10 },
retry: { maxRetries: 1 },
});HTTP Usage
Common endpoint examples
import { DrishtiClient } from "drishti-sdk";
const client = new DrishtiClient({ apiKey: process.env.DRISHTI_API_KEY! });
// Announcements
const announcements = await client.getAnnouncements({
symbols: ["RELIANCE"],
important: true,
detailed: true,
limit: 20,
});
// Earnings detail
const earnings = await client.getEarningsDetail({
symbol: "MEDIASSIST",
quarter: "q4_26",
detailed: true,
});
// Concall transcript URLs
const transcript = await client.getConcallsTranscript({
symbol: "TCS",
quarter: "q4_26",
});
// Alerts feed
const alerts = await client.getAlerts({
symbols: ["INFY"],
important: true,
limit: 25,
});
// Account usage
const usage = await client.getAccountUsage();Low-level request access
Use this when you need an endpoint not yet wrapped by a helper method.
import { DrishtiClient } from "drishti-sdk";
const client = new DrishtiClient({ apiKey: process.env.DRISHTI_API_KEY! });
const response = await client.request("GET", "/v1/news", {
query: { symbols: "RELIANCE", limit: 5 },
});You can also use shortcut methods: get, post, put, patch, delete.
Error Handling
HTTP failures throw DrishtiApiError.
import { DrishtiApiError, DrishtiClient } from "drishti-sdk";
const client = new DrishtiClient({ apiKey: process.env.DRISHTI_API_KEY! });
try {
await client.getAccount();
} catch (error) {
if (error instanceof DrishtiApiError) {
console.error(error.statusCode);
console.error(error.body);
}
throw error;
}WebSocket Usage (/v1/ws)
Event listeners
import { DrishtiClient } from "drishti-sdk";
const client = new DrishtiClient({ apiKey: process.env.DRISHTI_API_KEY! });
const ws = client.websocket({
reconnectInitialDelayMs: 1000,
reconnectMaxDelayMs: 30000,
onReconnectAttempt: (attempt, delayMs, reason) => {
console.log("reconnect", { attempt, delayMs, reason });
},
onData: (event) => {
if (event.kind === "data") console.log(event.channel, event.data);
},
onAnnouncements: (announcement) => {
console.log("announcement", announcement);
},
onAlerts: (alert) => {
console.log("alert", alert);
},
});
await ws.subscribe({ product: "alerts", symbols: ["RELIANCE"] });
// listeners fire as events arrive; the session reconnects automaticallyAsync iterator style
import { DrishtiClient } from "drishti-sdk";
const client = new DrishtiClient({ apiKey: process.env.DRISHTI_API_KEY! });
const ws = client.websocket();
await ws.subscribe({ product: "announcements", symbols: ["RELIANCE"], detailed: false });
for await (const event of ws.events()) {
if (event.kind === "subscribed") {
console.log("subscribed", event.product, event.tier);
} else if (event.kind === "data") {
console.log(event.channel, event.data);
} else if (event.kind === "error") {
console.error(event.message);
}
}Channel-specific listeners can be registered after connect:
const onAnnouncement = (announcement: Record<string, unknown>) => {
console.log("announcement", announcement);
};
ws.onAnnouncements(onAnnouncement);
ws.off("announcements", onAnnouncement);The same channels are also available via ws.on("announcements", handler).
onData still receives every data event across all channels.
Direct import is also supported:
import { DrishtiWebSocketSession } from "drishti-sdk";WebSocket Reference
The WebSocket session is created from the HTTP client, so it inherits the same
apiKey, baseUrl, and extra headers. In Node and other environments that
support custom WebSocket headers, the client sends X-API-Key. In browser-like
constructors that do not allow headers, the SDK falls back to
?api_key=... automatically.
Supported subscription products:
newsannouncementsearningsconcallsalerts
Useful session options:
reconnectInitialDelayMsreconnectMaxDelayMsreconnectBackoffMultiplierreconnectJitterRatioreconnectWarnAfterAttemptsonSubscribedonDataonNewsonAnnouncementsonEarningsonConcallsonAlertsonErroronMessageonOpenonCloseonReconnectAttemptonReconnectWarning
The session connects automatically when created and keeps retrying in the
background after disconnects. Connection failures are retried with backoff; a
warning is logged (or onReconnectWarning is called) after repeated failures,
then retries continue indefinitely until close() is called.
Subscription messages accept an object shaped like
{ product, symbols?, detailed? }. Symbols are normalized to uppercase and
de-duplicated before the message is sent. Subscriptions are replayed after
every reconnect.
Event shapes:
subscribed: acknowledgement withproduct,tier,fullFeed,symbols, anddetaileddata: payload event withchannelanddataerror: error event withmessageand optionalcoderaw: unclassified JSON payload
Direct helpers exported from the package:
DRISHTI_WS_PRODUCTSDrishtiWebSocketSessionbuildWebSocketUrlparseWebSocketMessagestreamProductSubscribeOptionsDataEventErrorEventRawEventSubscribedEventWebSocketEventWebSocketHandler
DataEvent["data"] is typed by channel for the known products:
news->NewsItemannouncements->AnnouncementDetail | AnnouncementListItemearnings->EarningsDetail | EarningsListItemconcalls->Concall | ConcallListItemalerts->Alert
Batch Jobs
Upload JSONL files for batch processing:
import { readFile } from "node:fs/promises";
import { Blob } from "node:buffer";
import { DrishtiClient } from "drishti-sdk";
const client = new DrishtiClient({ apiKey: process.env.DRISHTI_API_KEY! });
const fileBuffer = await readFile("./batch.jsonl");
const fileBlob = new Blob([fileBuffer], { type: "application/jsonl" });
const job = await client.postBatchJobsFile({
file: fileBlob,
filename: "batch.jsonl",
display_name: "Quarterly run",
});
const status = await client.getBatchJobsJobId({ job_id: job.id });Wait until completion:
const finalJob = await client.waitForBatchJobCompletion({
job_id: job.id,
pollIntervalMs: 2000,
timeoutMs: 300000,
});Submit and wait in one call:
const finalJob = await client.submitBatchJobAndWait({
file: fileBlob,
filename: "batch.jsonl",
display_name: "Quarterly run",
pollIntervalMs: 2000,
timeoutMs: 300000,
});API Surface
REST helper methods
getNewsgetSymbolsMetadatagetAnnouncementsCategoriesgetAnnouncementsgetAnnouncementsAttachmentspostDailySummarygetEarningsgetEarningsDetailgetEarningsAttachmentsgetConcallsgetUpcomingConcallsgetConcallsDetailgetConcallsTranscriptpostConcallsTranscriptsgetAlertsgetAccountgetAccountLimitsgetAccountUsagegetAccountLedgerpostBatchJobspostBatchJobsFilegetBatchJobsgetBatchJobsJobIddeleteBatchJobsJobIdgetBatchJobsJobIdResultswaitForBatchJobCompletionsubmitBatchJobAndWaitwebsocket
Low-level HTTP methods
requestgetpostputpatchdelete
TypeScript Support
The package ships with .d.ts files and typed request/response models from:
types.ts(response payloads)params.ts(query/body input models)
This enables strong autocomplete and type checking for both endpoint helpers and WebSocket events.
