@datacline/langos-sdk-node 0.2.0-alpha.1

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/CHANGELOG.md ADDED
@@ -0,0 +1,63 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ### Security
11
+ - **Webhook empty / short signing secret rejected.** `Webhooks.constructEvent` now requires `secret` to be a non-empty string of at least 16 characters. Prevents a forgery path where a partner who forgot to set `LANGOS_WEBHOOK_SECRET` would silently HMAC events against the empty string, allowing an attacker who knows this default to forge events that pass verification.
12
+ - **Webhook timestamp parser hardened.** The `t=` value in the `Langos-Signature` header is now rejected if it is non-positive, NaN, or larger than `2**32` seconds (past the unix-epoch overflow boundary). Previously `t=0` and `t=-1` parsed as valid integers and only failed via the tolerance check, which is a fail-late posture for a malformed-input class.
13
+ - **Header injection guard on `appName` and `apiKey`.** The `Langos` constructor now rejects strings containing `\r`, `\n`, `\0`, or any C0 control character. These would otherwise let an attacker who controls the partner's `appName` env splice arbitrary headers into every outbound request via the `User-Agent` line. Same guard applies to `apiKey` for the `Authorization` header.
14
+
15
+ ### Fixed
16
+ - **`WebhookEventType` aligned with server-side publishers.** The union now matches the canonical set emitted by the server (`session.submitted`, `session.completed`, `candidate.cancelled`). The previous test fixture referenced a fictional `candidate.completed` event; that has been corrected. Also adds an `Event` discriminated union so partners can `switch (event.type)` and let the compiler enforce exhaustive handling.
17
+ - **`409 Conflict` no longer auto-retried.** 409 is non-idempotent (duplicate email, version conflict, race against a parallel mutation) — retrying just burns the partner's rate-limit budget and amplifies the conflict. Partners should surface 409 to their caller and resolve the conflict explicitly.
18
+ - **`WebhookEvent.created` matches the server's wire field.** The webhook envelope's timestamp field was typed as `createdAt`, but the server-side publisher emits `created`. Reading `event.createdAt` returned `undefined` at runtime while the type system claimed it was a string. Renamed to `created` on `WebhookEvent` and `BaseEvent` to remove the lie; partners using `event.created` get the real timestamp.
19
+
20
+ ## [0.2.0-alpha.1] - 2026-05-08
21
+
22
+ ### Added
23
+ - **Customer Partner API SDK** — official Node.js / TypeScript client for the Langos Partner API (`@datacline/langos-sdk-node`)
24
+ - **Assessment resource** — list published assessments, retrieve by id
25
+ - **Challenge resource** — list coding challenges, retrieve by id
26
+ - **Candidate resource** — invite candidates to assessments, list, retrieve, cancel invitations
27
+ - **Session resource** — retrieve scoring results, analytics, and recruiter reports
28
+ - **Account resource** — retrieve workspace plan tier, session quota, feature flags, and webhook configuration
29
+ - **Webhook support** — register webhook endpoints, set signing secrets, validate inbound webhook signatures with `Langos.webhooks.constructEvent`
30
+ - **Pagination** — async iterable cursor-based pagination on all list endpoints
31
+ - **Error handling** — typed error classes: `LangosAPIError`, `LangosAuthenticationError`, `LangosForbiddenError`, `LangosNotFoundError`, `LangosBadRequestError`, `LangosRateLimitError`, `LangosServerError`, `LangosConnectionError`, `LangosTimeoutError`
32
+ - **Automatic retries** — configurable exponential backoff with jitter on 5xx and `408`/`409`/`429` (max 2 retries by default)
33
+ - **Idempotency** — automatic `Idempotency-Key` header generation for safe POST/PATCH/DELETE/PUT, honors `Retry-After` headers
34
+ - **Zero runtime dependencies** — uses only Node.js built-ins (`fetch`, `crypto`)
35
+ - **Dual module distribution** — ESM (`.mjs`), CommonJS (`.cjs`), and TypeScript declaration files (`.d.ts`)
36
+ - **TypeScript first** — full type safety for all resources, error classes, and webhook events
37
+ - **Webhook signature verification** — HMAC-SHA256 validation with static `Langos.webhooks.constructEvent` helper
38
+
39
+ ### Configuration
40
+ - `apiKey` — required Bearer token for authentication
41
+ - `baseUrl` — override default (production) endpoint for staging / self-hosted deploys
42
+ - `timeout` — request timeout in milliseconds (default: 30,000)
43
+ - `maxRetries` — max retry attempts on retryable errors (default: 2)
44
+ - `appName` — optional app name appended to User-Agent
45
+ - `logger` — optional Pino-shaped logger for debugging
46
+ - `telemetry` — opt out of `X-Langos-Client-Telemetry` header (default: enabled)
47
+ - `fetch` — optional custom fetch implementation for advanced use cases (e.g., custom proxies)
48
+
49
+ ### Documentation
50
+ - Full integration guide in [CLAUDE.md](./CLAUDE.md) for SDK consumers and contributors
51
+ - API reference in [README.md](./README.md) covering quickstart, auth, resources, pagination, errors, webhooks
52
+ - Contributing guide in [CONTRIBUTING.md](./CONTRIBUTING.md) with testing and PR submission requirements
53
+
54
+ ### Known Limitations
55
+ - Alpha release — surface is small and may change before `1.0.0`
56
+ - Webhook delivery from Langos is on the v1.x roadmap; verification helper ships now so integrators can wire handlers ahead of GA
57
+
58
+ ### Development
59
+ - **Testing** — unit tests with Vitest (~46 tests, no network dependency)
60
+ - **Linting** — TypeScript strict mode with `tsc --noEmit`
61
+ - **Build** — dual ESM+CJS build with tsup
62
+ - **Package content** — validated tarball contents with `npm pack --dry-run`
63
+ - **CI/CD** — GitHub Actions workflow testing Node 18.17, 20, and 22
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Datacline Limited
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,190 @@
1
+ # `@datacline/langos-sdk-node`
2
+
3
+ Official Node.js / TypeScript SDK for the Langos Partner API.
4
+
5
+ This SDK is for ATS partners (Greenhouse, Lever, Ashby, custom in-house ATSs) embedding Langos coding assessments into their hiring workflow. It wraps the public Partner API at `app.langos.io/api/v1`.
6
+
7
+ > **Status:** alpha. Surface is small (assessments, candidates, sessions, webhook signature verification) and may change before `1.0.0`.
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ npm install @datacline/langos-sdk-node
13
+ # or
14
+ pnpm add @datacline/langos-sdk-node
15
+ # or
16
+ yarn add @datacline/langos-sdk-node
17
+ ```
18
+
19
+ Requires **Node 18.17+** (Node 20 LTS recommended). Works in Bun, Deno (via npm:), Cloudflare Workers, and Vercel Edge as long as `fetch` and `crypto` are available.
20
+
21
+ ## Quickstart
22
+
23
+ ```ts
24
+ import { Langos } from '@datacline/langos-sdk-node';
25
+
26
+ const client = new Langos({ apiKey: process.env.LANGOS_API_KEY! });
27
+
28
+ // 1. Find an assessment to invite a candidate to.
29
+ for await (const a of await client.assessments.list()) {
30
+ console.log(a.id, a.name);
31
+ }
32
+
33
+ // 2. Invite a candidate.
34
+ const candidate = await client.candidates.create({
35
+ email: 'jane@example.com',
36
+ name: 'Jane Doe',
37
+ assessmentId: 'asm_abc',
38
+ externalId: 'greenhouse-app-12345',
39
+ });
40
+ console.log('Invitation URL:', candidate.invitationUrl);
41
+
42
+ // 3. Poll for results (or use webhooks once outbound delivery ships).
43
+ const fresh = await client.candidates.retrieve(candidate.id);
44
+ if (fresh.status === 'completed' && fresh.latestSessionId) {
45
+ const session = await client.sessions.retrieve(fresh.latestSessionId);
46
+ console.log('Score:', session.score);
47
+ }
48
+ ```
49
+
50
+ ## Authentication
51
+
52
+ Set `Authorization: Bearer <api_key>`. The SDK does this for you — just pass `apiKey` to the constructor. API keys are issued by the Langos workspace owner via the recruiter dashboard.
53
+
54
+ ## Other integration paths
55
+
56
+ Langos integrates with ATS platforms directly (Ashby today; more coming). If your team uses Ashby, you can connect Langos via the Ashby App Marketplace instead of this SDK — both paths surface the same `/v1/account` data, but Ashby manages auth on your behalf. Use this SDK when you want a direct API integration; use the Ashby flow when you'd rather operate Langos inside Ashby's UI.
57
+
58
+ The `account.integration.provider` field tells you which path your key is using:
59
+ - `'customer'` — you minted this key from the Langos dashboard (this SDK)
60
+ - `'ashby'` (or another ATS slug) — Langos was wired through your ATS partner
61
+
62
+ ## Resources
63
+
64
+ | Resource | Methods |
65
+ |---|---|
66
+ | `client.assessments` | `list`, `retrieve` |
67
+ | `client.candidates` | `list`, `retrieve`, `create`, `cancel` |
68
+ | `client.sessions` | `retrieve`, `listForCandidate` |
69
+ | `Langos.webhooks` | `constructEvent` (signature verification) |
70
+
71
+ ## Pagination
72
+
73
+ List methods return an `AsyncIterablePage`. Either iterate across pages automatically:
74
+
75
+ ```ts
76
+ for await (const c of await client.candidates.list({ status: 'completed' })) {
77
+ console.log(c.email);
78
+ }
79
+ ```
80
+
81
+ Or page manually:
82
+
83
+ ```ts
84
+ const page = await client.candidates.list({ limit: 50 });
85
+ console.log(page.data, page.hasMore, page.nextCursor);
86
+ const next = await page.getNextPage(); // null when hasMore is false
87
+ ```
88
+
89
+ ## Error handling
90
+
91
+ All API errors throw a typed subclass of `LangosError`:
92
+
93
+ ```ts
94
+ import {
95
+ LangosAPIError,
96
+ LangosAuthenticationError,
97
+ LangosForbiddenError,
98
+ LangosNotFoundError,
99
+ LangosBadRequestError,
100
+ LangosRateLimitError,
101
+ LangosServerError,
102
+ LangosConnectionError,
103
+ LangosTimeoutError,
104
+ } from '@datacline/langos-sdk-node';
105
+
106
+ try {
107
+ await client.candidates.create({ email: 'x@y.com', assessmentId: 'asm_abc' });
108
+ } catch (err) {
109
+ if (err instanceof LangosRateLimitError) {
110
+ await sleep((err.retryAfter ?? 1) * 1000);
111
+ // retry
112
+ } else if (err instanceof LangosBadRequestError) {
113
+ console.warn('field errors:', err.errors); // [{ field, message, code }]
114
+ } else if (err instanceof LangosAPIError) {
115
+ console.error(err.status, err.code, err.requestId);
116
+ // Include err.requestId when reporting bugs to Langos support.
117
+ } else throw err;
118
+ }
119
+ ```
120
+
121
+ ## Retries & idempotency
122
+
123
+ The SDK retries on connection errors and `408`/`409`/`429`/`5xx` (except `501`) up to `maxRetries: 2` by default, with exponential backoff and jitter, honoring `Retry-After`.
124
+
125
+ For unsafe methods (`POST`, `PATCH`, `DELETE`, `PUT`), an `Idempotency-Key` header is auto-generated and reused across retries — duplicate side effects are eliminated. Override with your own:
126
+
127
+ ```ts
128
+ await client.candidates.create(
129
+ { email: 'x@y.com', assessmentId: 'asm_abc' },
130
+ { idempotencyKey: 'greenhouse-app-12345-v1' },
131
+ );
132
+ ```
133
+
134
+ ## Webhook signature verification
135
+
136
+ Verify incoming Langos webhooks with the static helper:
137
+
138
+ ```ts
139
+ import express from 'express';
140
+ import { Langos } from '@datacline/langos-sdk-node';
141
+
142
+ const app = express();
143
+
144
+ app.post(
145
+ '/webhooks/langos',
146
+ express.raw({ type: 'application/json' }), // CRITICAL: raw body required
147
+ (req, res) => {
148
+ try {
149
+ const event = Langos.webhooks.constructEvent(
150
+ req.body,
151
+ req.headers['langos-signature'],
152
+ process.env.LANGOS_WEBHOOK_SECRET!,
153
+ );
154
+ console.log(event.type, event.data);
155
+ res.status(204).end();
156
+ } catch {
157
+ res.status(400).send('invalid signature');
158
+ }
159
+ },
160
+ );
161
+ ```
162
+
163
+ > **Important:** pass the **raw body**, not the parsed JSON. `express.json()` will reformat keys/whitespace and break signature verification.
164
+
165
+ > **Note:** Outbound webhook delivery from Langos is on the v1.x roadmap. The verification helper ships now so you can wire your handler ahead of GA without an SDK upgrade later.
166
+
167
+ ## Configuration
168
+
169
+ ```ts
170
+ const client = new Langos({
171
+ apiKey: process.env.LANGOS_API_KEY!,
172
+ baseUrl: 'https://app.langos.io/api/v1', // override for self-host / staging
173
+ timeout: 30_000, // ms
174
+ maxRetries: 2,
175
+ appName: 'GreenhouseConnector/2.1.0', // appended to User-Agent
176
+ logger: pino(), // optional Pino-shaped logger
177
+ telemetry: false, // opt out of X-Langos-Client-Telemetry
178
+ fetch: customFetch, // inject custom fetch
179
+ });
180
+ ```
181
+
182
+ Per-call overrides via `RequestOptions`:
183
+
184
+ ```ts
185
+ await client.assessments.list({}, { timeout: 60_000, maxRetries: 5, signal: ac.signal });
186
+ ```
187
+
188
+ ## License
189
+
190
+ MIT — see [LICENSE](./LICENSE)