@cernisdata/sdk 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.
package/README.md CHANGED
@@ -1,3 +1,95 @@
1
- # Temporary Holding Version
1
+ # @cernisdata/sdk
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
+ TypeScript SDK for Cernis Data. People, company, contact, signal and web data behind one API key. Zero dependencies, fully typed, ESM and CommonJS. Runs anywhere `fetch` exists (Node 18+, Bun, Deno, Workers, browsers).
4
+
5
+ ```bash
6
+ npm install @cernisdata/sdk
7
+ ```
8
+
9
+ ```ts
10
+ import { CernisData } from '@cernisdata/sdk';
11
+
12
+ const client = new CernisData(); // reads CERNIS_DATA_API_KEY and CERNIS_DATA_BASE_URL (your API base URL)
13
+
14
+ const page = await client.people.search({ jobTitles: ['VP Sales'], companyDomains: 'stripe.com', limit: 10 });
15
+ for (const person of page.data?.results ?? []) console.log(person.full_name, person.title);
16
+ ```
17
+
18
+ Or pass both: `new CernisData({ apiKey: 'ck_live_...', baseUrl: 'https://your-api-host' })`.
19
+
20
+ ## How calls work
21
+
22
+ - Namespaces: `client.people`, `client.companies`, `client.contacts`, `client.signals`, `client.web`.
23
+ - Params take camelCase or snake_case and are sent as snake_case. Filters can be flat (`jobTitles`) or inside `filters`. List filters take a string, an array, or `{ include, exclude }`.
24
+ - Every method resolves to the API envelope: `{ request_id, status, data, meta }`.
25
+
26
+ ### Async endpoints wait for you
27
+
28
+ ```ts
29
+ const found = await client.contacts.email({ firstName: 'Karri', lastName: 'Saarinen', company: 'linear.app' });
30
+
31
+ const pending = await client.contacts.email({ firstName: 'Karri', lastName: 'Saarinen', company: 'linear.app' }, { wait: false });
32
+ const result = await client.requests.wait(pending.job_id!);
33
+ ```
34
+
35
+ ### Bulk jobs
36
+
37
+ ```ts
38
+ const job = await client.contacts.emailBulk({ items: [{ firstName: 'Karri', lastName: 'Saarinen', company: 'linear.app' }] });
39
+ await job.wait();
40
+ for await (const item of job.results()) console.log(item.index, item.status, item.data);
41
+ ```
42
+
43
+ ### Pagination
44
+
45
+ Every page is a billed request, so cap it.
46
+
47
+ ```ts
48
+ for await (const person of client.people.search.iter({ jobTitles: 'CTO', locations: 'Austin' }, { maxItems: 200 })) {
49
+ console.log(person.full_name);
50
+ }
51
+ ```
52
+
53
+ ### Errors
54
+
55
+ ```ts
56
+ import { CernisDataError, InsufficientBalanceError, RateLimitError } from '@cernisdata/sdk';
57
+
58
+ try {
59
+ await client.companies.enrich({ domain: 'stripe.com' });
60
+ } catch (e) {
61
+ if (e instanceof InsufficientBalanceError) console.log('Top up:', e.checkoutUrl);
62
+ else if (e instanceof RateLimitError) console.log('Retry in', e.retryAfter);
63
+ else if (e instanceof CernisDataError) console.log(e.status, e.code, e.message, e.requestId);
64
+ }
65
+ ```
66
+
67
+ Subclasses: `InvalidInputError`, `AuthenticationError`, `InsufficientBalanceError`, `PermissionDeniedError`, `NotFoundError`, `ConflictError`, `RateLimitError`, `EndpointNotAvailableError`, `TimeoutError`, `ServerError`, `APIConnectionError`, `WebhookVerificationError`.
68
+
69
+ ### Retries, idempotency and timeouts
70
+
71
+ 429, 5xx and network errors are retried with backoff and jitter (`maxRetries: 2` by default, honours `Retry-After`). Endpoint POSTs get an automatic `Idempotency-Key`, so a retry is never charged twice; pass `idempotencyKey` to choose your own. A per-call `timeoutMs` is also sent to the API as its time budget.
72
+
73
+ ```ts
74
+ const client = new CernisData({ timeoutMs: 30_000, maxRetries: 4, waitTimeoutMs: 600_000 });
75
+ await client.companies.enrich({ domain: 'stripe.com' }, { timeoutMs: 10_000, idempotencyKey: 'enrich-stripe', signal });
76
+ ```
77
+
78
+ ### Account
79
+
80
+ ```ts
81
+ await client.wallet(); // balance and free_requests { limit, used, remaining }
82
+ await client.usage({ days: 7 });
83
+ await client.requests.list({ limit: 20 });
84
+ await client.keys.create({ name: 'ci', scopes: ['people'] });
85
+ await client.billing.checkout({ amountUsd: 25 });
86
+ await client.call('company.enrich', { domain: 'stripe.com' }); // any endpoint by id, raw
87
+ ```
88
+
89
+ ### Webhooks
90
+
91
+ ```ts
92
+ import { verifyWebhook } from '@cernisdata/sdk';
93
+
94
+ const event = await verifyWebhook(rawBody, request.headers.get('CernisData-Signature'), secret);
95
+ ```