@chatlychat/sdk-node 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/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ # @chatlychat/sdk-node — changelog
2
+
3
+ ## 0.1.0 — 2026-05-25
4
+
5
+ - Initial public release.
6
+ - `ChatlyClient` with `contacts`, `conversations`, `tickets`, `cdp`, `webhooks`,
7
+ `audit` modules.
8
+ - `verifyWebhook()` helper with constant-time signature compare and replay-window
9
+ enforcement.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Chatly Engineering
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 CHANGED
@@ -1,3 +1,108 @@
1
- # Temporary Holding Version
1
+ # @chatlychat/sdk-node
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
+ Server-side client for the Chatly API. Authenticates with an API key, so it is
4
+ for your backend — not a browser, where the key would be readable.
5
+
6
+ ```bash
7
+ pnpm add @chatlychat/sdk-node
8
+ ```
9
+
10
+ ## Quick start
11
+
12
+ ```ts
13
+ import { ChatlyClient } from '@chatlychat/sdk-node';
14
+
15
+ const chatly = new ChatlyClient({
16
+ apiKey: process.env.CHATLY_API_KEY!, // ck_live_…
17
+ apiUrl: 'https://api.chatlychat.com', // optional
18
+ });
19
+
20
+ const contacts = await chatly.contacts.list({ limit: 20 });
21
+ ```
22
+
23
+ Create a key under **Workspace → Developer → API keys**. The token is shown
24
+ once and stored only as a hash — if you lose it, revoke and mint another.
25
+
26
+ Make `whoami()` your first call. It returns the workspace the key belongs to
27
+ and the scopes it actually holds, so a mis-scoped key fails loudly at
28
+ integration time instead of surfacing as a puzzling 403 from an unrelated
29
+ endpoint in production:
30
+
31
+ ```ts
32
+ const { workspaceId, scopes } = await chatly.whoami();
33
+ ```
34
+
35
+ It is the only api-keys route a key may call: minting or listing keys with a
36
+ key would let a leaked read-only key escalate itself.
37
+
38
+ ## What the client can do
39
+
40
+ Every method below maps to an endpoint that accepts key authentication. Scope
41
+ the key to only what your integration needs; a key can never do more than the
42
+ scopes ticked when it was created.
43
+
44
+ | Call | Scope required |
45
+ | ------------------------------------------------------ | -------------------- |
46
+ | `chatly.whoami()` | `workspace:read` |
47
+ | `chatly.contacts.list({ cursor?, limit? })` | `contacts:read` |
48
+ | `chatly.contacts.upsert({ email, name, … })` | `contacts:write` |
49
+ | `chatly.conversations.list({ cursor?, limit? })` | `conversations:read` |
50
+ | `chatly.conversations.messages(conversationId)` | `conversations:read` |
51
+ | `chatly.conversations.send({ conversationId, body })` | `messages:write` |
52
+ | `chatly.search.query('refund', { … })` | `search:read` |
53
+ | `chatly.search.kb('refund')` | `search:read` |
54
+ | `chatly.events.track({ contactId, name, properties })` | `contacts:write` |
55
+
56
+ Messages you send with a key are recorded as sent by an integration, not by
57
+ the person who created the key — a key outlives whoever issued it, so
58
+ attributing its writes to them would be wrong the moment they leave.
59
+
60
+ ## Not included, and why
61
+
62
+ Reactions and channel/widget configuration are absent on purpose. A reaction
63
+ records _who_ reacted and a key is not a person, so those endpoints require a
64
+ signed-in user. Channel configuration needs a scope no key can hold. Both used
65
+ to be here and both returned 403 to every caller.
66
+
67
+ ## Idempotency
68
+
69
+ Writes accept an idempotency key so a retry after a network failure does not
70
+ duplicate work:
71
+
72
+ ```ts
73
+ await chatly.withIdempotencyKey('order-4471-refund').contacts.upsert({ … });
74
+ ```
75
+
76
+ ## Verifying webhooks
77
+
78
+ ```ts
79
+ import { verifyWebhookSignature } from '@chatlychat/sdk-node';
80
+
81
+ const ok = verifyWebhookSignature({
82
+ body: rawBody, // the EXACT bytes, before JSON.parse
83
+ signatureHeader: req.headers['x-livechat-signature'] as string,
84
+ secret: process.env.CHATLY_WEBHOOK_SECRET!,
85
+ });
86
+ ```
87
+
88
+ Pass the raw body — re-serialising parsed JSON reorders keys and changes
89
+ whitespace, so the digest will not match.
90
+
91
+ The scheme is `t=<unix seconds>,v1=<hex>`, where `v1` is HMAC-SHA256 over
92
+ `` `${t}.${body}` ``. The timestamp is inside the signed string, so a captured
93
+ delivery stops verifying once it falls outside `toleranceSeconds`.
94
+
95
+ > **This example was wrong until 2026-10-12, in three ways** — it said
96
+ > `payload` (the field is `body`), `signature` (it is `signatureHeader`) and
97
+ > `x-chatly-signature` (webhooks use **`x-livechat-signature`**). In
98
+ > TypeScript the old snippet was a compile error; in plain JavaScript it was
99
+ > worse than returning `false`, because the verifier splits
100
+ > `input.signatureHeader` first and an absent one throws a `TypeError` out of
101
+ > your webhook handler.
102
+ >
103
+ > The header name is the trap worth knowing: **`x-chatly-signature` is real,
104
+ > but it belongs to four other surfaces** — external-agent deliveries, custom
105
+ > AI tool calls, customer cards and the workflow `fire_webhook` action — and
106
+ > each of those constructs its base string differently. Outbound event
107
+ > webhooks are the one surface using `x-livechat-signature`. Do not share one
108
+ > verifier across them without checking the construction.
@@ -0,0 +1,225 @@
1
+ export interface ClientOptions {
2
+ apiKey: string;
3
+ apiUrl?: string;
4
+ timeoutMs?: number;
5
+ fetchFn?: typeof fetch;
6
+ }
7
+ export interface PageQuery {
8
+ cursor?: string;
9
+ limit?: number;
10
+ }
11
+ export interface Page<T> {
12
+ items: ReadonlyArray<T>;
13
+ nextCursor: string | null;
14
+ }
15
+ /** Query for {@link ChatlyClient.events}.list — a page, optionally one contact's. */
16
+ export interface EventListQuery extends PageQuery {
17
+ /** Restrict the stream to one contact. Omit for the whole workspace. */
18
+ contactId?: string;
19
+ }
20
+ export interface ContactInput {
21
+ externalId?: string;
22
+ email?: string;
23
+ phone?: string;
24
+ name?: string;
25
+ attributes?: Record<string, unknown>;
26
+ }
27
+ export interface MessageInput {
28
+ conversationId: string;
29
+ body: string;
30
+ kind?: 'text' | 'rich' | 'note' | 'system_event';
31
+ }
32
+ /**
33
+ * Reaction payload.
34
+ *
35
+ * Declared here rather than imported from `@livechat/shared`: this package is
36
+ * published to consumers who must not have to install monorepo internals, so
37
+ * it stays dependency-free by design. The shape mirrors
38
+ * `@livechat/shared/reactions` and is covered by the API's own contract tests.
39
+ */
40
+ export interface MessageReactions {
41
+ readonly messageId: string;
42
+ readonly entries: ReadonlyArray<{
43
+ emoji: string;
44
+ count: number;
45
+ reacted: boolean;
46
+ }>;
47
+ }
48
+ /**
49
+ * Widget behaviour config. Structural, for the same reason as above — pass a
50
+ * plain object; the API validates it against the authoritative zod schema and
51
+ * rejects anything malformed.
52
+ */
53
+ export type WidgetFeatureConfig = Record<string, unknown>;
54
+ export declare class ChatlyClient {
55
+ private readonly base;
56
+ private readonly baseHeaders;
57
+ private readonly timeoutMs;
58
+ private readonly fetchFn;
59
+ /**
60
+ * When set, every write made through this client instance uses this
61
+ * exact `Idempotency-Key` instead of minting a fresh UUID per call.
62
+ * Created via {@link withIdempotencyKey}; the original client is left
63
+ * untouched (the method returns a derived view, not a mutation).
64
+ */
65
+ private readonly pinnedIdempotencyKey;
66
+ constructor(opts: ClientOptions);
67
+ /**
68
+ * Private clone constructor — used by {@link withIdempotencyKey} so we
69
+ * can return a derived client without mutating the original (and
70
+ * without re-running the public ctor's defaulting logic).
71
+ */
72
+ private static derive;
73
+ /**
74
+ * Pin a specific `Idempotency-Key` for one or more upcoming writes.
75
+ *
76
+ * Returns a derived client (the original is unchanged). Use this when
77
+ * you want to retry the *same* logical operation: the API treats two
78
+ * writes with the same key + same body as a single accepted operation
79
+ * and replays the cached response. Two writes with the same key but a
80
+ * different body return HTTP 409.
81
+ *
82
+ * ```ts
83
+ * const key = crypto.randomUUID();
84
+ * for (let attempt = 0; attempt < 3; attempt++) {
85
+ * try {
86
+ * return await chatly.withIdempotencyKey(key).contacts.upsert(body);
87
+ * } catch (err) { ...backoff }
88
+ * }
89
+ * ```
90
+ */
91
+ withIdempotencyKey(key: string): ChatlyClient;
92
+ /**
93
+ * Describe the credential this client is using: which workspace it belongs
94
+ * to and which scopes it was granted.
95
+ *
96
+ * `GET /v1/api-keys/whoami` is deliberately the ONLY route on the api-keys
97
+ * controller that accepts an API key (managing keys with a key is a
98
+ * privilege-escalation shape). It is the call to make first: it turns a
99
+ * mis-scoped key into an obvious error at integration time rather than a
100
+ * 403 from an unrelated endpoint later.
101
+ *
102
+ * It was reachable over raw HTTP but appeared in no SDK and no doc, so
103
+ * there was no way for an integrator to discover it.
104
+ */
105
+ whoami(): Promise<{
106
+ workspaceId: string;
107
+ scopes: readonly string[];
108
+ }>;
109
+ contacts: {
110
+ list: (q?: PageQuery) => Promise<Page<unknown>>;
111
+ upsert: (body: ContactInput) => Promise<unknown>;
112
+ };
113
+ conversations: {
114
+ list: (q?: PageQuery) => Promise<Page<unknown>>;
115
+ /**
116
+ * Read a thread before replying to it.
117
+ *
118
+ * The MCP server has exposed this as `get_messages` since it shipped and
119
+ * the SDK did not, so an integrator writing "read the conversation, then
120
+ * decide" against the SDK had to hand-roll the request while the same
121
+ * capability sat behind a tool call.
122
+ */
123
+ messages: (conversationId: string, q?: PageQuery) => Promise<Page<unknown>>;
124
+ send: (body: MessageInput) => Promise<unknown>;
125
+ };
126
+ /**
127
+ * Reactions and channel configuration are deliberately absent.
128
+ *
129
+ * Both were here and neither worked: a reaction records *who* reacted, and
130
+ * a key is not a person, so those routes require a signed-in user and
131
+ * return 403 to any key. Channel configuration needs `channels:write`,
132
+ * which no key-accessible route grants. Shipping methods that always fail
133
+ * is worse than not shipping them — the failure arrives at runtime, in
134
+ * production, in someone else's integration.
135
+ */
136
+ /** Full-text search across contacts, conversations, messages, tickets, KB. */
137
+ search: {
138
+ query: (q: string, opts?: Record<string, unknown>) => Promise<unknown>;
139
+ /**
140
+ * Help-centre articles only.
141
+ *
142
+ * The same `/v1/search` route narrowed to `kinds[]=kb`, which is exactly
143
+ * what the MCP server's `search_kb` tool does. Worth its own method
144
+ * because "find the article that answers this" is the common case and
145
+ * getting there otherwise means knowing the `kinds[]` parameter exists.
146
+ */
147
+ kb: (q: string, opts?: Record<string, unknown>) => Promise<unknown>;
148
+ };
149
+ events: {
150
+ track: (input: {
151
+ contactId: string;
152
+ name: string;
153
+ properties?: Record<string, unknown>;
154
+ }) => Promise<unknown>;
155
+ /**
156
+ * Read back what was tracked — the same `/v1/cdp/events` collection
157
+ * {@link track} writes to, cursor-paginated newest-first.
158
+ *
159
+ * The SDK could write events and never read them, so "did my tracking
160
+ * call actually land?" had no answer outside the dashboard. Pass
161
+ * `contactId` to scope the stream to one person.
162
+ */
163
+ list: (q?: EventListQuery) => Promise<Page<unknown>>;
164
+ };
165
+ private get;
166
+ private post;
167
+ /** PATCH. Same idempotency contract as `post` — it is a write. */
168
+ private patch;
169
+ private dispatch;
170
+ }
171
+ /** Freshness window for `t`, in seconds. Matches what the docs recommend. */
172
+ export declare const WEBHOOK_SIGNATURE_TOLERANCE_SECONDS = 300;
173
+ export interface VerifyWebhookSignatureInput {
174
+ /**
175
+ * The EXACT bytes we POSTed. Pass the raw body — re-serialising parsed JSON
176
+ * reorders keys and changes whitespace, and the digest will not match.
177
+ */
178
+ body: string | Uint8Array;
179
+ /** The `x-livechat-signature` header value: `t=<unix seconds>,v1=<hex>`. */
180
+ signatureHeader: string;
181
+ /** The endpoint's `whsec_…` signing secret. */
182
+ secret: string;
183
+ /**
184
+ * How far `t` may be from now before the delivery is treated as a replay.
185
+ * Defaults to {@link WEBHOOK_SIGNATURE_TOLERANCE_SECONDS}; pass `Infinity`
186
+ * only when re-verifying an archived delivery.
187
+ */
188
+ toleranceSeconds?: number;
189
+ /** Escape hatch for tests. Unix seconds. */
190
+ nowSeconds?: number;
191
+ }
192
+ /**
193
+ * Verify the signature header on a webhook delivery from the platform.
194
+ *
195
+ * `v1` is HMAC-SHA256 over `` `${t}.${body}` `` — the timestamp is bound INTO
196
+ * the digest, which is what makes the replay window enforceable at all.
197
+ *
198
+ * This used to HMAC the body ALONE, so it rejected every genuine delivery the
199
+ * platform sent: the producer has always signed `${t}.${body}` and our own
200
+ * published documentation has always described that construction. Anyone
201
+ * following either the SDK or the docs got a hard "invalid signature" on 100%
202
+ * of real traffic. The wire format is unchanged — only this verifier was wrong.
203
+ */
204
+ export declare function verifyWebhookSignature(input: VerifyWebhookSignatureInput): boolean;
205
+ /**
206
+ * Compute the `userHash` the widget needs for identity verification.
207
+ *
208
+ * When a workspace turns identity verification on, the widget must prove the
209
+ * `externalId` it claims was issued by the customer's backend rather than
210
+ * typed into a browser console -- otherwise anyone can open a chat as anyone
211
+ * else's account. This is the backend half of that handshake:
212
+ *
213
+ * const userHash = chatlyIdentityHash(process.env.CHATLY_IDV_SECRET, user.id);
214
+ * // then render:
215
+ * // Chatly('identify', { externalId: user.id, userHash, email: user.email })
216
+ *
217
+ * It lived in the API's own source as a comment-only snippet, where the
218
+ * people who need it -- customers integrating their backend -- could never
219
+ * import it.
220
+ *
221
+ * The secret is the workspace's identity-verification secret. It must never
222
+ * reach the browser; only the digest does.
223
+ */
224
+ export declare function chatlyIdentityHash(secret: string, externalId: string): string;
225
+ //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D,KAAK;YASL,QAAQ;CA+BvB;AAED,6EAA6E;AAC7E,eAAO,MAAM,mCAAmC,MAAM,CAAC;AAEvD,MAAM,WAAW,2BAA2B;IAC1C;;;OAGG;IACH,IAAI,EAAE,MAAM,GAAG,UAAU,CAAC;IAC1B,4EAA4E;IAC5E,eAAe,EAAE,MAAM,CAAC;IACxB,gDAAgD;IAChD,MAAM,EAAE,MAAM,CAAC;IACf;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,4CAA4C;IAC5C,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,2BAA2B,GAAG,OAAO,CAiClF;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAQ7E"}
package/dist/index.js ADDED
@@ -0,0 +1,315 @@
1
+ import { createHmac, randomUUID, timingSafeEqual } from 'node:crypto';
2
+ /** Node 14.17+ has `crypto.randomUUID`; the SDK targets Node 20+ so it's safe. */
3
+ function nodeRandomUuid() {
4
+ return randomUUID();
5
+ }
6
+ export class ChatlyClient {
7
+ base;
8
+ baseHeaders;
9
+ timeoutMs;
10
+ fetchFn;
11
+ /**
12
+ * When set, every write made through this client instance uses this
13
+ * exact `Idempotency-Key` instead of minting a fresh UUID per call.
14
+ * Created via {@link withIdempotencyKey}; the original client is left
15
+ * untouched (the method returns a derived view, not a mutation).
16
+ */
17
+ pinnedIdempotencyKey;
18
+ constructor(opts) {
19
+ /*
20
+ * Production, not a dev hostname.
21
+ *
22
+ * This was `https://api.livechat.local`, which resolves nowhere — so a
23
+ * developer who followed the published docs and omitted `apiUrl` got an
24
+ * SDK whose every call failed, and the docs page carried a warning
25
+ * telling each reader to override it. Reported by a customer who
26
+ * integrated from the docs alone, not caught here, because every test in
27
+ * this package passes an explicit `apiUrl`.
28
+ *
29
+ * A self-hosted install still overrides it; that is the only caller that
30
+ * ever should.
31
+ */
32
+ this.base = opts.apiUrl ?? 'https://api.chatlychat.com';
33
+ this.baseHeaders = new Headers({
34
+ authorization: `Bearer ${opts.apiKey}`,
35
+ 'content-type': 'application/json',
36
+ accept: 'application/json',
37
+ 'user-agent': '@chatlychat/sdk-node/0.1.0',
38
+ });
39
+ this.timeoutMs = opts.timeoutMs ?? 15_000;
40
+ this.fetchFn = opts.fetchFn ?? globalThis.fetch;
41
+ this.pinnedIdempotencyKey = null;
42
+ }
43
+ /**
44
+ * Private clone constructor — used by {@link withIdempotencyKey} so we
45
+ * can return a derived client without mutating the original (and
46
+ * without re-running the public ctor's defaulting logic).
47
+ */
48
+ static derive(parent, pinnedIdempotencyKey) {
49
+ const child = Object.create(ChatlyClient.prototype);
50
+ Object.assign(child, {
51
+ base: parent.base,
52
+ baseHeaders: parent.baseHeaders,
53
+ timeoutMs: parent.timeoutMs,
54
+ fetchFn: parent.fetchFn,
55
+ pinnedIdempotencyKey,
56
+ });
57
+ // The route bags are field-initialized below the class body via the
58
+ // arrow-property pattern; re-bind them so they target the derived
59
+ // instance and call the child's `post`/`get`.
60
+ child.contacts = {
61
+ list: (q = {}) => child.get('/v1/contacts', { ...q }),
62
+ upsert: (body) => child.post('/v1/contacts', body),
63
+ };
64
+ child.conversations = {
65
+ list: (q = {}) => child.get('/v1/conversations', { ...q }),
66
+ messages: (conversationId, q = {}) => child.get(`/v1/conversations/${conversationId}/messages`, { ...q }),
67
+ send: (body) => child.post(`/v1/conversations/${body.conversationId}/messages`, body),
68
+ };
69
+ child.events = {
70
+ track: (input) => child.post('/v1/cdp/events', input),
71
+ list: (q = {}) => child.get('/v1/cdp/events', { ...q }),
72
+ };
73
+ // `search` was never rebound here, so a derived client's search methods
74
+ // still called the PARENT's `get`. Harmless today because both are reads
75
+ // against the same base URL, and a live bug the moment anything on
76
+ // `search` becomes a write or the derived client differs by more than a
77
+ // pinned key. `derivedSurfaceMatches` in the spec fails if any namespace
78
+ // is forgotten again — TypeScript only caught `messages` because that
79
+ // namespace was already rebound.
80
+ child.search = {
81
+ query: (q, opts = {}) => child.get('/v1/search', { q, ...opts }),
82
+ kb: (q, opts = {}) => child.get('/v1/search', { q, 'kinds[]': 'kb', ...opts }),
83
+ };
84
+ return child;
85
+ }
86
+ /**
87
+ * Pin a specific `Idempotency-Key` for one or more upcoming writes.
88
+ *
89
+ * Returns a derived client (the original is unchanged). Use this when
90
+ * you want to retry the *same* logical operation: the API treats two
91
+ * writes with the same key + same body as a single accepted operation
92
+ * and replays the cached response. Two writes with the same key but a
93
+ * different body return HTTP 409.
94
+ *
95
+ * ```ts
96
+ * const key = crypto.randomUUID();
97
+ * for (let attempt = 0; attempt < 3; attempt++) {
98
+ * try {
99
+ * return await chatly.withIdempotencyKey(key).contacts.upsert(body);
100
+ * } catch (err) { ...backoff }
101
+ * }
102
+ * ```
103
+ */
104
+ withIdempotencyKey(key) {
105
+ if (typeof key !== 'string' || key.length === 0) {
106
+ throw new TypeError('withIdempotencyKey: key must be a non-empty string');
107
+ }
108
+ return ChatlyClient.derive(this, key);
109
+ }
110
+ /**
111
+ * Describe the credential this client is using: which workspace it belongs
112
+ * to and which scopes it was granted.
113
+ *
114
+ * `GET /v1/api-keys/whoami` is deliberately the ONLY route on the api-keys
115
+ * controller that accepts an API key (managing keys with a key is a
116
+ * privilege-escalation shape). It is the call to make first: it turns a
117
+ * mis-scoped key into an obvious error at integration time rather than a
118
+ * 403 from an unrelated endpoint later.
119
+ *
120
+ * It was reachable over raw HTTP but appeared in no SDK and no doc, so
121
+ * there was no way for an integrator to discover it.
122
+ */
123
+ async whoami() {
124
+ return this.get('/v1/api-keys/whoami', {});
125
+ }
126
+ contacts = {
127
+ list: (q = {}) => this.get('/v1/contacts', { ...q }),
128
+ upsert: (body) => this.post('/v1/contacts', body),
129
+ };
130
+ conversations = {
131
+ list: (q = {}) => this.get('/v1/conversations', { ...q }),
132
+ /**
133
+ * Read a thread before replying to it.
134
+ *
135
+ * The MCP server has exposed this as `get_messages` since it shipped and
136
+ * the SDK did not, so an integrator writing "read the conversation, then
137
+ * decide" against the SDK had to hand-roll the request while the same
138
+ * capability sat behind a tool call.
139
+ */
140
+ messages: (conversationId, q = {}) => this.get(`/v1/conversations/${conversationId}/messages`, { ...q }),
141
+ send: (body) => this.post(`/v1/conversations/${body.conversationId}/messages`, body),
142
+ };
143
+ /**
144
+ * Reactions and channel configuration are deliberately absent.
145
+ *
146
+ * Both were here and neither worked: a reaction records *who* reacted, and
147
+ * a key is not a person, so those routes require a signed-in user and
148
+ * return 403 to any key. Channel configuration needs `channels:write`,
149
+ * which no key-accessible route grants. Shipping methods that always fail
150
+ * is worse than not shipping them — the failure arrives at runtime, in
151
+ * production, in someone else's integration.
152
+ */
153
+ /** Full-text search across contacts, conversations, messages, tickets, KB. */
154
+ search = {
155
+ query: (q, opts = {}) => this.get('/v1/search', { q, ...opts }),
156
+ /**
157
+ * Help-centre articles only.
158
+ *
159
+ * The same `/v1/search` route narrowed to `kinds[]=kb`, which is exactly
160
+ * what the MCP server's `search_kb` tool does. Worth its own method
161
+ * because "find the article that answers this" is the common case and
162
+ * getting there otherwise means knowing the `kinds[]` parameter exists.
163
+ */
164
+ kb: (q, opts = {}) => this.get('/v1/search', { q, 'kinds[]': 'kb', ...opts }),
165
+ };
166
+ events = {
167
+ track: (input) => this.post('/v1/cdp/events', input),
168
+ /**
169
+ * Read back what was tracked — the same `/v1/cdp/events` collection
170
+ * {@link track} writes to, cursor-paginated newest-first.
171
+ *
172
+ * The SDK could write events and never read them, so "did my tracking
173
+ * call actually land?" had no answer outside the dashboard. Pass
174
+ * `contactId` to scope the stream to one person.
175
+ */
176
+ list: (q = {}) => this.get('/v1/cdp/events', { ...q }),
177
+ };
178
+ async get(path, q) {
179
+ const url = new URL(`${this.base}${path}`);
180
+ for (const [k, v] of Object.entries(q)) {
181
+ if (v !== undefined) {
182
+ url.searchParams.set(k, String(v));
183
+ }
184
+ }
185
+ return this.dispatch(url, { method: 'GET' });
186
+ }
187
+ async post(path, body) {
188
+ // Production API requires Idempotency-Key on every write. The
189
+ // `pinnedIdempotencyKey` path is the supported way to retry the
190
+ // SAME logical operation (set via `withIdempotencyKey(key)`); when
191
+ // unset we mint a fresh UUID per call so a fetch-level network
192
+ // retry inside this SDK still won't double-write upstream.
193
+ const idempotencyKey = this.pinnedIdempotencyKey ?? nodeRandomUuid();
194
+ return this.dispatch(new URL(`${this.base}${path}`), {
195
+ method: 'POST',
196
+ body: JSON.stringify(body),
197
+ headers: { 'idempotency-key': idempotencyKey },
198
+ });
199
+ }
200
+ /** PATCH. Same idempotency contract as `post` — it is a write. */
201
+ async patch(path, body) {
202
+ const idempotencyKey = this.pinnedIdempotencyKey ?? nodeRandomUuid();
203
+ return this.dispatch(new URL(`${this.base}${path}`), {
204
+ method: 'PATCH',
205
+ body: JSON.stringify(body),
206
+ headers: { 'idempotency-key': idempotencyKey },
207
+ });
208
+ }
209
+ async dispatch(url, init) {
210
+ const ctrl = new AbortController();
211
+ const timer = setTimeout(() => ctrl.abort(), this.timeoutMs);
212
+ try {
213
+ // Merge base auth/content headers with any per-call overrides
214
+ // (e.g. `idempotency-key` from `post`). Previously this dropped
215
+ // per-call headers because it reassigned `headers` wholesale —
216
+ // which silently broke the idempotency contract on every write.
217
+ const headers = new Headers(this.baseHeaders);
218
+ if (init.headers !== undefined) {
219
+ new Headers(init.headers).forEach((value, name) => {
220
+ headers.set(name, value);
221
+ });
222
+ }
223
+ const res = await this.fetchFn(url.toString(), {
224
+ ...init,
225
+ signal: ctrl.signal,
226
+ headers,
227
+ });
228
+ if (!res.ok) {
229
+ const text = await res.text();
230
+ throw new Error(`livechat ${res.status}: ${text}`);
231
+ }
232
+ if (res.status === 204) {
233
+ return undefined;
234
+ }
235
+ return (await res.json());
236
+ }
237
+ finally {
238
+ clearTimeout(timer);
239
+ }
240
+ }
241
+ }
242
+ /** Freshness window for `t`, in seconds. Matches what the docs recommend. */
243
+ export const WEBHOOK_SIGNATURE_TOLERANCE_SECONDS = 300;
244
+ /**
245
+ * Verify the signature header on a webhook delivery from the platform.
246
+ *
247
+ * `v1` is HMAC-SHA256 over `` `${t}.${body}` `` — the timestamp is bound INTO
248
+ * the digest, which is what makes the replay window enforceable at all.
249
+ *
250
+ * This used to HMAC the body ALONE, so it rejected every genuine delivery the
251
+ * platform sent: the producer has always signed `${t}.${body}` and our own
252
+ * published documentation has always described that construction. Anyone
253
+ * following either the SDK or the docs got a hard "invalid signature" on 100%
254
+ * of real traffic. The wire format is unchanged — only this verifier was wrong.
255
+ */
256
+ export function verifyWebhookSignature(input) {
257
+ const parts = new Map();
258
+ for (const part of input.signatureHeader.split(',')) {
259
+ const eq = part.indexOf('=');
260
+ if (eq > 0) {
261
+ parts.set(part.slice(0, eq).trim(), part.slice(eq + 1).trim());
262
+ }
263
+ }
264
+ const rawTs = parts.get('t');
265
+ const tag = parts.get('v1');
266
+ if (rawTs === undefined || tag === undefined) {
267
+ return false;
268
+ }
269
+ const issuedAt = Number.parseInt(rawTs, 10);
270
+ if (!Number.isFinite(issuedAt)) {
271
+ return false;
272
+ }
273
+ const tolerance = input.toleranceSeconds ?? WEBHOOK_SIGNATURE_TOLERANCE_SECONDS;
274
+ const now = input.nowSeconds ?? Math.floor(Date.now() / 1000);
275
+ if (Math.abs(now - issuedAt) > tolerance) {
276
+ return false;
277
+ }
278
+ const hmac = createHmac('sha256', input.secret);
279
+ hmac.update(`${rawTs}.`);
280
+ hmac.update(typeof input.body === 'string' ? Buffer.from(input.body, 'utf8') : input.body);
281
+ const a = Buffer.from(tag, 'hex');
282
+ const b = Buffer.from(hmac.digest('hex'), 'hex');
283
+ // Length check first: timingSafeEqual throws on a length mismatch, and a
284
+ // thrown verifier is an accepted webhook in a handler that forgot try/catch.
285
+ return a.length === b.length && timingSafeEqual(a, b);
286
+ }
287
+ /**
288
+ * Compute the `userHash` the widget needs for identity verification.
289
+ *
290
+ * When a workspace turns identity verification on, the widget must prove the
291
+ * `externalId` it claims was issued by the customer's backend rather than
292
+ * typed into a browser console -- otherwise anyone can open a chat as anyone
293
+ * else's account. This is the backend half of that handshake:
294
+ *
295
+ * const userHash = chatlyIdentityHash(process.env.CHATLY_IDV_SECRET, user.id);
296
+ * // then render:
297
+ * // Chatly('identify', { externalId: user.id, userHash, email: user.email })
298
+ *
299
+ * It lived in the API's own source as a comment-only snippet, where the
300
+ * people who need it -- customers integrating their backend -- could never
301
+ * import it.
302
+ *
303
+ * The secret is the workspace's identity-verification secret. It must never
304
+ * reach the browser; only the digest does.
305
+ */
306
+ export function chatlyIdentityHash(secret, externalId) {
307
+ if (secret.length === 0) {
308
+ throw new Error('chatlyIdentityHash: secret is empty');
309
+ }
310
+ if (externalId.length === 0) {
311
+ throw new Error('chatlyIdentityHash: externalId is empty');
312
+ }
313
+ return createHmac('sha256', secret).update(externalId).digest('hex');
314
+ }
315
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEtE,kFAAkF;AAClF,SAAS,cAAc;IACrB,OAAO,UAAU,EAAE,CAAC;AACtB,CAAC;AA2DD,MAAM,OAAO,YAAY;IACN,IAAI,CAAS;IACb,WAAW,CAAU;IACrB,SAAS,CAAS;IAClB,OAAO,CAAe;IACvC;;;;;OAKG;IACc,oBAAoB,CAAgB;IAErD,YAAmB,IAAmB;QACpC;;;;;;;;;;;;WAYG;QACH,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,MAAM,IAAI,4BAA4B,CAAC;QACxD,IAAI,CAAC,WAAW,GAAG,IAAI,OAAO,CAAC;YAC7B,aAAa,EAAE,UAAU,IAAI,CAAC,MAAM,EAAE;YACtC,cAAc,EAAE,kBAAkB;YAClC,MAAM,EAAE,kBAAkB;YAC1B,YAAY,EAAE,4BAA4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,CAAC,qCAAqC,CAAC,CAAC;IACzD,CAAC;IACD,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC5B,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;IAC7D,CAAC;IACD,OAAO,UAAU,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACvE,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.spec.d.ts","sourceRoot":"","sources":["../src/index.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,315 @@
1
+ /**
2
+ * Behaviour tests for the public SDK surface that the dashboard /
3
+ * partner integrators depend on. Focused on the bits that are easy to
4
+ * regress and load-bearing for correctness:
5
+ *
6
+ * - every write sends an `Idempotency-Key` (no header drop on dispatch)
7
+ * - `withIdempotencyKey(key)` pins the key across multiple writes
8
+ * - `withIdempotencyKey` returns a derived client, not a mutated one
9
+ * - webhook signature verification (timing-safe, malformed inputs ok)
10
+ *
11
+ * `fetch` is injected via `ClientOptions.fetchFn`, so we don't touch the
12
+ * network — the spec asserts on the request shape the SDK builds.
13
+ */
14
+ import { createHmac } from 'node:crypto';
15
+ import { at } from '@livechat/shared/narrow';
16
+ import { describe, expect, it } from 'vitest';
17
+ import { ChatlyClient, verifyWebhookSignature, chatlyIdentityHash, WEBHOOK_SIGNATURE_TOLERANCE_SECONDS, } from './index.js';
18
+ function recordingFetch() {
19
+ const calls = [];
20
+ const fn = async (url, init) => {
21
+ calls.push({ url: String(url), init: init ?? {} });
22
+ return new Response(JSON.stringify({ ok: true }), {
23
+ status: 200,
24
+ headers: { 'content-type': 'application/json' },
25
+ });
26
+ };
27
+ return { calls, fn: fn };
28
+ }
29
+ describe('ChatlyClient — Idempotency-Key on writes', () => {
30
+ it('attaches a fresh idempotency-key to every POST when no key is pinned', async () => {
31
+ const rec = recordingFetch();
32
+ const client = new ChatlyClient({
33
+ apiKey: 'k',
34
+ apiUrl: 'https://api.test',
35
+ fetchFn: rec.fn,
36
+ });
37
+ await client.events.track({ contactId: 'c1', name: 'signup' });
38
+ await client.events.track({ contactId: 'c2', name: 'signup' });
39
+ expect(rec.calls).toHaveLength(2);
40
+ const k1 = new Headers(at(rec.calls, 0, 'recorded requests').init.headers).get('idempotency-key');
41
+ const k2 = new Headers(at(rec.calls, 1, 'recorded requests').init.headers).get('idempotency-key');
42
+ expect(k1).toBeTruthy();
43
+ expect(k2).toBeTruthy();
44
+ expect(k1).not.toEqual(k2);
45
+ });
46
+ it('preserves the base auth headers on the dispatch path', async () => {
47
+ const rec = recordingFetch();
48
+ const client = new ChatlyClient({
49
+ apiKey: 'secret-token',
50
+ apiUrl: 'https://api.test',
51
+ fetchFn: rec.fn,
52
+ });
53
+ await client.contacts.upsert({ email: 'a@b.c' });
54
+ const h = new Headers(at(rec.calls, 0, 'recorded requests').init.headers);
55
+ expect(h.get('authorization')).toBe('Bearer secret-token');
56
+ expect(h.get('content-type')).toBe('application/json');
57
+ expect(h.get('idempotency-key')).toBeTruthy();
58
+ });
59
+ });
60
+ describe('ChatlyClient — withIdempotencyKey', () => {
61
+ it('pins a stable key across multiple writes on the derived client', async () => {
62
+ const rec = recordingFetch();
63
+ const client = new ChatlyClient({
64
+ apiKey: 'k',
65
+ apiUrl: 'https://api.test',
66
+ fetchFn: rec.fn,
67
+ });
68
+ const pinned = client.withIdempotencyKey('fixed-key-123');
69
+ await pinned.events.track({ contactId: 'c1', name: 'a' });
70
+ await pinned.events.track({ contactId: 'c2', name: 'b' });
71
+ expect(rec.calls).toHaveLength(2);
72
+ for (const call of rec.calls) {
73
+ const h = new Headers(call.init.headers);
74
+ expect(h.get('idempotency-key')).toBe('fixed-key-123');
75
+ }
76
+ });
77
+ it('does not mutate the original client', async () => {
78
+ const rec = recordingFetch();
79
+ const client = new ChatlyClient({
80
+ apiKey: 'k',
81
+ apiUrl: 'https://api.test',
82
+ fetchFn: rec.fn,
83
+ });
84
+ client.withIdempotencyKey('pinned'); // intentionally unused
85
+ await client.events.track({ contactId: 'c1', name: 'x' });
86
+ const h = new Headers(at(rec.calls, 0, 'recorded requests').init.headers);
87
+ expect(h.get('idempotency-key')).not.toBe('pinned');
88
+ });
89
+ it('rejects empty / non-string keys with a TypeError (cheap mistake guard)', () => {
90
+ const client = new ChatlyClient({ apiKey: 'k' });
91
+ expect(() => client.withIdempotencyKey('')).toThrow(TypeError);
92
+ // @ts-expect-error — intentional misuse
93
+ expect(() => client.withIdempotencyKey(undefined)).toThrow(TypeError);
94
+ });
95
+ });
96
+ describe('ChatlyClient — withIdempotencyKey keeps the full surface', () => {
97
+ /**
98
+ * `derive` rebuilds every route namespace by hand so the closures target
99
+ * the derived instance. That is easy to forget: `search` was never rebound
100
+ * at all, and `messages` was caught only by the compiler because its
101
+ * namespace happened to already be listed.
102
+ *
103
+ * This compares the shape of a derived client against its parent, so a new
104
+ * method on any namespace fails here rather than silently calling the
105
+ * parent's request methods.
106
+ */
107
+ it('exposes exactly the same namespaces and methods as the parent', () => {
108
+ const rec = recordingFetch();
109
+ const parent = new ChatlyClient({ apiKey: 'k', apiUrl: 'https://api.test', fetchFn: rec.fn });
110
+ const child = parent.withIdempotencyKey('order-1');
111
+ const surface = (c) => {
112
+ const bags = ['contacts', 'conversations', 'events', 'search'];
113
+ return bags
114
+ .flatMap((bag) => Object.keys(c[bag] ?? {}).map((k) => `${bag}.${k}`))
115
+ .sort();
116
+ };
117
+ expect(surface(child)).toEqual(surface(parent));
118
+ });
119
+ it('routes a derived namespace through the derived client', async () => {
120
+ const rec = recordingFetch();
121
+ const parent = new ChatlyClient({ apiKey: 'k', apiUrl: 'https://api.test', fetchFn: rec.fn });
122
+ await parent.withIdempotencyKey('order-1').contacts.upsert({ email: 'a@b.c' });
123
+ const headers = new Headers(rec.calls[0]?.init.headers);
124
+ expect(headers.get('idempotency-key')).toBe('order-1');
125
+ });
126
+ });
127
+ describe('ChatlyClient — parity with the MCP tools', () => {
128
+ /**
129
+ * The MCP server exposed `get_messages` and `search_kb` while the SDK did
130
+ * not, so the same capability was reachable from a tool call and not from
131
+ * the published client. These pin the request shapes against the routes the
132
+ * MCP tools use.
133
+ */
134
+ it('reads a thread by conversation id', async () => {
135
+ const rec = recordingFetch();
136
+ const client = new ChatlyClient({ apiKey: 'k', apiUrl: 'https://api.test', fetchFn: rec.fn });
137
+ await client.conversations.messages('c-1', { limit: 50 });
138
+ expect(rec.calls[0]?.url).toBe('https://api.test/v1/conversations/c-1/messages?limit=50');
139
+ });
140
+ it('narrows KB search with the kinds[] parameter the API expects', async () => {
141
+ // The bracket in `kinds[]` is the whole point: `kinds=kb` is silently
142
+ // ignored by the list-filter parser and returns everything.
143
+ const rec = recordingFetch();
144
+ const client = new ChatlyClient({ apiKey: 'k', apiUrl: 'https://api.test', fetchFn: rec.fn });
145
+ await client.search.kb('refund');
146
+ const url = new URL(rec.calls[0]?.url ?? '');
147
+ expect(url.pathname).toBe('/v1/search');
148
+ expect(url.searchParams.get('q')).toBe('refund');
149
+ expect(url.searchParams.get('kinds[]')).toBe('kb');
150
+ });
151
+ });
152
+ describe('ChatlyClient — events.list', () => {
153
+ /**
154
+ * The SDK could POST an event and never read one back: `/v1/cdp/events`
155
+ * was referenced only under POST, so the read half of the CDP integration
156
+ * had no shipped caller at all. These pin the exact request.
157
+ */
158
+ it('GETs the same collection track() posts to', async () => {
159
+ const rec = recordingFetch();
160
+ const client = new ChatlyClient({ apiKey: 'k', apiUrl: 'https://api.test', fetchFn: rec.fn });
161
+ await client.events.list();
162
+ expect(rec.calls).toHaveLength(1);
163
+ expect(new URL(at(rec.calls, 0, 'recorded requests').url).pathname).toBe('/v1/cdp/events');
164
+ expect(at(rec.calls, 0, 'recorded requests').init.method).toBe('GET');
165
+ });
166
+ it('scopes the stream to one contact and passes the page cursor through', async () => {
167
+ const rec = recordingFetch();
168
+ const client = new ChatlyClient({ apiKey: 'k', apiUrl: 'https://api.test', fetchFn: rec.fn });
169
+ await client.events.list({ contactId: 'ct-1', limit: 25, cursor: 'abc' });
170
+ const url = new URL(at(rec.calls, 0, 'recorded requests').url);
171
+ expect(url.pathname).toBe('/v1/cdp/events');
172
+ expect(url.searchParams.get('contactId')).toBe('ct-1');
173
+ expect(url.searchParams.get('limit')).toBe('25');
174
+ expect(url.searchParams.get('cursor')).toBe('abc');
175
+ });
176
+ it('is a read, so it sends no idempotency key', async () => {
177
+ const rec = recordingFetch();
178
+ const client = new ChatlyClient({ apiKey: 'k', apiUrl: 'https://api.test', fetchFn: rec.fn });
179
+ await client.events.list();
180
+ const headers = new Headers(at(rec.calls, 0, 'recorded requests').init.headers);
181
+ expect(headers.get('idempotency-key')).toBeNull();
182
+ });
183
+ });
184
+ describe('ChatlyClient — whoami', () => {
185
+ it('GETs the one api-keys route a key is allowed to call', async () => {
186
+ const rec = recordingFetch();
187
+ const client = new ChatlyClient({
188
+ apiKey: 'k',
189
+ apiUrl: 'https://api.test',
190
+ fetchFn: rec.fn,
191
+ });
192
+ await client.whoami();
193
+ expect(rec.calls).toHaveLength(1);
194
+ expect(rec.calls[0]?.url).toBe('https://api.test/v1/api-keys/whoami');
195
+ expect(rec.calls[0]?.init.method).toBe('GET');
196
+ });
197
+ it('is a read, so it sends no idempotency key', async () => {
198
+ const rec = recordingFetch();
199
+ const client = new ChatlyClient({
200
+ apiKey: 'k',
201
+ apiUrl: 'https://api.test',
202
+ fetchFn: rec.fn,
203
+ });
204
+ await client.whoami();
205
+ const headers = new Headers(rec.calls[0]?.init.headers);
206
+ expect(headers.get('idempotency-key')).toBeNull();
207
+ });
208
+ });
209
+ describe('verifyWebhookSignature', () => {
210
+ const secret = 'shh';
211
+ const body = '{"type":"message.created","payload":{"id":"m1"}}';
212
+ const t = 1_714_060_800;
213
+ // The construction the producer uses and the docs describe: HMAC over
214
+ // `${t}.${body}`, never the body alone. Computed here rather than
215
+ // hard-coded so the spec doesn't rot, but note that the round-trip
216
+ // assertion lives in the worker
217
+ // (`apps/worker/src/__tests__/webhook-sig.spec.ts`) — this file can only
218
+ // ever prove the verifier agrees with ITSELF.
219
+ const header = (ts, payload = body, key = secret) => `t=${String(ts)},v1=${createHmac('sha256', key)
220
+ .update(`${String(ts)}.${payload}`)
221
+ .digest('hex')}`;
222
+ it('returns true for a signature over `t.body`', () => {
223
+ expect(verifyWebhookSignature({ body, signatureHeader: header(t), secret, nowSeconds: t })).toBe(true);
224
+ });
225
+ it('accepts the raw body as bytes', () => {
226
+ expect(verifyWebhookSignature({
227
+ body: Buffer.from(body, 'utf8'),
228
+ signatureHeader: header(t),
229
+ secret,
230
+ nowSeconds: t,
231
+ })).toBe(true);
232
+ });
233
+ it('rejects a signature over the body alone', () => {
234
+ // This is what this verifier used to COMPUTE. If it ever passes again,
235
+ // every genuine delivery is being rejected in the field.
236
+ const bodyOnly = `t=${String(t)},v1=${createHmac('sha256', secret).update(body).digest('hex')}`;
237
+ expect(verifyWebhookSignature({ body, signatureHeader: bodyOnly, secret, nowSeconds: t })).toBe(false);
238
+ });
239
+ it('returns false for a tampered body', () => {
240
+ expect(verifyWebhookSignature({
241
+ body: '{"type":"message.created","payload":{"id":"m2"}}',
242
+ signatureHeader: header(t),
243
+ secret,
244
+ nowSeconds: t,
245
+ })).toBe(false);
246
+ });
247
+ it('returns false for a wrong secret', () => {
248
+ expect(verifyWebhookSignature({
249
+ body,
250
+ signatureHeader: header(t, body, 'evil'),
251
+ secret,
252
+ nowSeconds: t,
253
+ })).toBe(false);
254
+ });
255
+ it('returns false when the header is missing the v1= scheme', () => {
256
+ expect(verifyWebhookSignature({ body, signatureHeader: `t=${String(t)}`, secret, nowSeconds: t })).toBe(false);
257
+ });
258
+ it('returns false when the header is missing t=', () => {
259
+ // Without `t` there is no replay window to enforce, so a header that
260
+ // omits it is not verifiable — not merely unfresh.
261
+ const sig = createHmac('sha256', secret)
262
+ .update(`${String(t)}.${body}`)
263
+ .digest('hex');
264
+ expect(verifyWebhookSignature({ body, signatureHeader: `v1=${sig}`, secret, nowSeconds: t })).toBe(false);
265
+ });
266
+ it('rejects a replayed delivery outside the tolerance window', () => {
267
+ expect(verifyWebhookSignature({
268
+ body,
269
+ signatureHeader: header(t),
270
+ secret,
271
+ nowSeconds: t + WEBHOOK_SIGNATURE_TOLERANCE_SECONDS + 1,
272
+ })).toBe(false);
273
+ expect(verifyWebhookSignature({
274
+ body,
275
+ signatureHeader: header(t),
276
+ secret,
277
+ nowSeconds: t + WEBHOOK_SIGNATURE_TOLERANCE_SECONDS,
278
+ })).toBe(true);
279
+ });
280
+ it('rejects a delivery timestamped in the future beyond tolerance', () => {
281
+ // Clock skew cuts both ways; an attacker post-dating `t` to buy a longer
282
+ // replay window is the case that matters.
283
+ expect(verifyWebhookSignature({
284
+ body,
285
+ signatureHeader: header(t),
286
+ secret,
287
+ nowSeconds: t - WEBHOOK_SIGNATURE_TOLERANCE_SECONDS - 1,
288
+ })).toBe(false);
289
+ });
290
+ });
291
+ describe('chatlyIdentityHash', () => {
292
+ it('matches the digest the API verifies against', () => {
293
+ // The API computes HMAC-SHA256(secret, externalId) and compares with
294
+ // timingSafeEqual. If these two ever disagree, identity verification
295
+ // rejects every legitimate visitor -- and the failure looks like a
296
+ // widget bug rather than a hashing mismatch.
297
+ const expected = createHmac('sha256', 'shh').update('user-42').digest('hex');
298
+ expect(chatlyIdentityHash('shh', 'user-42')).toBe(expected);
299
+ });
300
+ it('differs per user, which is the entire point', () => {
301
+ expect(chatlyIdentityHash('shh', 'user-1')).not.toBe(chatlyIdentityHash('shh', 'user-2'));
302
+ });
303
+ it('differs per workspace secret', () => {
304
+ expect(chatlyIdentityHash('a', 'user-1')).not.toBe(chatlyIdentityHash('b', 'user-1'));
305
+ });
306
+ it.each([
307
+ ['an empty secret', '', 'user-1'],
308
+ ['an empty externalId', 'shh', ''],
309
+ ])('refuses %s rather than returning a hash of nothing', (_label, secret, externalId) => {
310
+ // An empty secret produces a perfectly valid-looking digest that any
311
+ // attacker can also compute.
312
+ expect(() => chatlyIdentityHash(secret, externalId)).toThrow();
313
+ });
314
+ });
315
+ //# sourceMappingURL=index.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.spec.js","sourceRoot":"","sources":["../src/index.spec.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,EAAE,EAAE,MAAM,yBAAyB,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAE9C,OAAO,EACL,YAAY,EACZ,sBAAsB,EACtB,kBAAkB,EAClB,mCAAmC,GACpC,MAAM,YAAY,CAAC;AAEpB,SAAS,cAAc;IACrB,MAAM,KAAK,GAA8C,EAAE,CAAC;IAC5D,MAAM,EAAE,GAAG,KAAK,EAAE,GAA2B,EAAE,IAAkB,EAAE,EAAE;QACnE,KAAK,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,IAAI,IAAI,EAAE,EAAE,CAAC,CAAC;QACnD,OAAO,IAAI,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE;YAChD,MAAM,EAAE,GAAG;YACX,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;SAChD,CAAC,CAAC;IACL,CAAC,CAAC;IACF,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,EAA6B,EAAE,CAAC;AACtD,CAAC;AAED,QAAQ,CAAC,0CAA0C,EAAE,GAAG,EAAE;IACxD,EAAE,CAAC,sEAAsE,EAAE,KAAK,IAAI,EAAE;QACpF,MAAM,GAAG,GAAG,cAAc,EAAE,CAAC;QAC7B,MAAM,MAAM,GAAG,IAAI,YAAY,CAAC;YAC9B,MAAM,EAAE,GAAG;YAC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MAAM,CAAC,GAAG,EAAE,CAAC,kBAAkB,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;IACjE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,64 @@
1
1
  {
2
2
  "name": "@chatlychat/sdk-node",
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": "Server-side SDK for the LiveChat platform — REST client + webhook signature verification.",
5
+ "license": "MIT",
6
+ "homepage": "https://github.com/livechat/platform/tree/main/packages/sdk-node",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/livechat/platform.git",
10
+ "directory": "packages/sdk-node"
11
+ },
12
+ "bugs": "https://github.com/livechat/platform/issues",
13
+ "keywords": [
14
+ "livechat",
15
+ "chat",
16
+ "messaging",
17
+ "support",
18
+ "webhooks",
19
+ "sdk",
20
+ "server"
21
+ ],
22
+ "author": "LiveChat Platform Engineering",
23
+ "type": "module",
24
+ "main": "./dist/index.js",
25
+ "module": "./dist/index.js",
26
+ "types": "./dist/index.d.ts",
27
+ "exports": {
28
+ ".": {
29
+ "types": "./dist/index.d.ts",
30
+ "import": "./dist/index.js",
31
+ "default": "./dist/index.js"
32
+ }
33
+ },
34
+ "files": [
35
+ "dist",
36
+ "README.md",
37
+ "LICENSE",
38
+ "CHANGELOG.md"
39
+ ],
40
+ "sideEffects": false,
41
+ "scripts": {
42
+ "build": "tsc -p tsconfig.json",
43
+ "prepublishOnly": "pnpm build",
44
+ "typecheck": "tsc -p tsconfig.json --noEmit",
45
+ "lint": "eslint src --max-warnings=0",
46
+ "test": "vitest run"
47
+ },
48
+ "publishConfig": {
49
+ "access": "public",
50
+ "registry": "https://registry.npmjs.org/",
51
+ "provenance": true
52
+ },
53
+ "engines": {
54
+ "node": ">=18"
55
+ },
56
+ "devDependencies": {
57
+ "@livechat/config": "workspace:*",
58
+ "@livechat/shared": "workspace:*",
59
+ "@types/node": "catalog:",
60
+ "typescript": "catalog:",
61
+ "vitest": "catalog:"
62
+ },
63
+ "dependencies": {}
64
+ }