@telemai/sdk 0.2.5 → 0.2.6

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/dist/index.cjs CHANGED
@@ -33,6 +33,7 @@ __export(index_exports, {
33
33
  sessionKey: () => sessionKey,
34
34
  snapshotNodeKey: () => snapshotNodeKey,
35
35
  toolMarker: () => toolMarker,
36
+ verifyWebhook: () => verifyWebhook,
36
37
  windowAnchor: () => windowAnchor,
37
38
  withTrajectory: () => withTrajectory
38
39
  });
@@ -59,7 +60,7 @@ var TimeoutError = class extends TelemError {
59
60
  };
60
61
 
61
62
  // src/version.ts
62
- var VERSION = "0.2.5";
63
+ var VERSION = "0.2.6";
63
64
 
64
65
  // src/config.ts
65
66
  var DEFAULT_BASE_URL = "https://router.telem.ai";
@@ -706,6 +707,8 @@ function monitorFrom(body) {
706
707
  sessionId: String(data.session_id ?? ""),
707
708
  createdAt: data.created_at ?? "",
708
709
  lastPolledAt: data.last_polled_at ?? null,
710
+ webhookUrl: data.webhook_url ?? null,
711
+ webhookSecret: data.webhook_secret ?? null,
709
712
  raw: data
710
713
  };
711
714
  }
@@ -725,6 +728,7 @@ function createMonitors(config) {
725
728
  body.options.provider_overrides = options.providerOverrides;
726
729
  }
727
730
  if (options.metadata !== void 0) body.metadata = options.metadata;
731
+ if (options.webhookUrl !== void 0) body.webhook_url = options.webhookUrl;
728
732
  const data = await request(config, "POST", "/v1/monitors", body, options.signal, "rate_limit");
729
733
  return monitorFrom(data);
730
734
  },
@@ -744,6 +748,7 @@ function createMonitors(config) {
744
748
  if (options.status !== void 0) body.status = options.status;
745
749
  if (options.frequency !== void 0) body.frequency = options.frequency;
746
750
  if (options.providerOverrides !== void 0) body.provider_overrides = options.providerOverrides;
751
+ if (options.webhookUrl !== void 0) body.webhook_url = options.webhookUrl;
747
752
  const route = path(monitorId);
748
753
  return monitorFrom(await request(config, "PATCH", route, body, options.signal));
749
754
  },
@@ -762,6 +767,23 @@ function createMonitors(config) {
762
767
  }
763
768
  };
764
769
  }
770
+ async function verifyWebhook(body, header, secret, toleranceSeconds = 300) {
771
+ const parts = Object.fromEntries(
772
+ header.split(",").map((item) => [item.slice(0, item.indexOf("=")), item.slice(item.indexOf("=") + 1)])
773
+ );
774
+ const t = parts.t ?? "";
775
+ const v1 = parts.v1 ?? "";
776
+ if (!/^\d+$/.test(t) || Math.abs(Date.now() / 1e3 - Number(t)) > toleranceSeconds) return false;
777
+ if (!/^([0-9a-f]{2})+$/.test(v1)) return false;
778
+ const encoder = new TextEncoder();
779
+ const raw = typeof body === "string" ? encoder.encode(body) : body;
780
+ const signed = new Uint8Array([...encoder.encode(`${t}.`), ...raw]);
781
+ const key = await crypto.subtle.importKey("raw", encoder.encode(secret), { name: "HMAC", hash: "SHA-256" }, false, [
782
+ "verify"
783
+ ]);
784
+ const signature = new Uint8Array(v1.match(/../g).map((byte) => parseInt(byte, 16)));
785
+ return crypto.subtle.verify("HMAC", key, signature, signed);
786
+ }
765
787
 
766
788
  // src/methods/providers.ts
767
789
  async function providers(config) {
@@ -906,6 +928,7 @@ var index_default = Telem;
906
928
  sessionKey,
907
929
  snapshotNodeKey,
908
930
  toolMarker,
931
+ verifyWebhook,
909
932
  windowAnchor,
910
933
  withTrajectory
911
934
  });
package/dist/index.d.cts CHANGED
@@ -232,15 +232,19 @@ type MonitorCreateOptions = {
232
232
  providerOverrides?: Record<string, Json>;
233
233
  /** Request metadata (query lineage keys), sent as given. */
234
234
  metadata?: Json;
235
+ /** An `https` URL that receives the new results. */
236
+ webhookUrl?: string;
235
237
  signal?: AbortSignal;
236
238
  };
237
- /** Options for `monitors.update`. Send at least one of the three fields. */
239
+ /** Options for `monitors.update`. Send at least one field. */
238
240
  type MonitorUpdateOptions = {
239
241
  /** `"paused"` or `"active"`. */
240
242
  status?: string;
241
243
  frequency?: string;
242
244
  /** New overrides for the providers named. They replace the ones sent before. */
243
245
  providerOverrides?: Record<string, Json>;
246
+ /** A new webhook URL, with a new `webhookSecret` in the response. `null` removes it. */
247
+ webhookUrl?: string | null;
244
248
  signal?: AbortSignal;
245
249
  };
246
250
  /** Options for `monitors.poll`. */
@@ -266,6 +270,9 @@ type Monitor = {
266
270
  sessionId: string;
267
271
  createdAt: string;
268
272
  lastPolledAt: string | null;
273
+ webhookUrl: string | null;
274
+ /** Signs the webhook deliveries. Only in the response that set `webhookUrl`. */
275
+ webhookSecret: string | null;
269
276
  raw: Json;
270
277
  };
271
278
  /** The `telem.monitors` namespace. */
@@ -323,6 +330,12 @@ declare class TimeoutError extends TelemError {
323
330
  constructor(message: string, cause?: unknown);
324
331
  }
325
332
 
333
+ /**
334
+ * Check a monitor webhook: the `Telem-Signature` header against the raw body.
335
+ * True when the signature is correct and not older than `toleranceSeconds`.
336
+ */
337
+ declare function verifyWebhook(body: string | Uint8Array, header: string, secret: string, toleranceSeconds?: number): Promise<boolean>;
338
+
326
339
  /** Metadata keys the trajectory payload owns. A caller-supplied value for any of
327
340
  * these is dropped rather than allowed to forge identity. */
328
341
  declare const RESERVED_METADATA: ReadonlySet<string>;
@@ -453,4 +466,4 @@ declare class Telem {
453
466
  providers(): Promise<ProviderInfo[]>;
454
467
  }
455
468
 
456
- export { type FetchOptions, type FetchResponse, type FetchResult, type Json, type Monitor, type MonitorCreateOptions, type MonitorPollOptions, type MonitorProvider, type MonitorUpdateOptions, type MonitorsResource, type ProviderInfo, type ProviderRun, RESERVED_METADATA, type SearchDefaults, type SearchOptions, type SearchResponse, type SearchResult, type SessionResults, type SessionSummary, type SessionsResource, type SnapshotArgs, Telem, type TelemClientErrorCode, TelemError, type TelemErrorOptions, type TelemOptions, TimeoutError, type TrajectoryArgs, type TrajectoryEnvelope, type TrajectorySnapshot, buildMetadata, buildSnapshot, contentAnchor, Telem as default, eventNodeKey, fingerprint, sessionKey, snapshotNodeKey, toolMarker, windowAnchor, withTrajectory };
469
+ export { type FetchOptions, type FetchResponse, type FetchResult, type Json, type Monitor, type MonitorCreateOptions, type MonitorPollOptions, type MonitorProvider, type MonitorUpdateOptions, type MonitorsResource, type ProviderInfo, type ProviderRun, RESERVED_METADATA, type SearchDefaults, type SearchOptions, type SearchResponse, type SearchResult, type SessionResults, type SessionSummary, type SessionsResource, type SnapshotArgs, Telem, type TelemClientErrorCode, TelemError, type TelemErrorOptions, type TelemOptions, TimeoutError, type TrajectoryArgs, type TrajectoryEnvelope, type TrajectorySnapshot, buildMetadata, buildSnapshot, contentAnchor, Telem as default, eventNodeKey, fingerprint, sessionKey, snapshotNodeKey, toolMarker, verifyWebhook, windowAnchor, withTrajectory };
package/dist/index.d.ts CHANGED
@@ -232,15 +232,19 @@ type MonitorCreateOptions = {
232
232
  providerOverrides?: Record<string, Json>;
233
233
  /** Request metadata (query lineage keys), sent as given. */
234
234
  metadata?: Json;
235
+ /** An `https` URL that receives the new results. */
236
+ webhookUrl?: string;
235
237
  signal?: AbortSignal;
236
238
  };
237
- /** Options for `monitors.update`. Send at least one of the three fields. */
239
+ /** Options for `monitors.update`. Send at least one field. */
238
240
  type MonitorUpdateOptions = {
239
241
  /** `"paused"` or `"active"`. */
240
242
  status?: string;
241
243
  frequency?: string;
242
244
  /** New overrides for the providers named. They replace the ones sent before. */
243
245
  providerOverrides?: Record<string, Json>;
246
+ /** A new webhook URL, with a new `webhookSecret` in the response. `null` removes it. */
247
+ webhookUrl?: string | null;
244
248
  signal?: AbortSignal;
245
249
  };
246
250
  /** Options for `monitors.poll`. */
@@ -266,6 +270,9 @@ type Monitor = {
266
270
  sessionId: string;
267
271
  createdAt: string;
268
272
  lastPolledAt: string | null;
273
+ webhookUrl: string | null;
274
+ /** Signs the webhook deliveries. Only in the response that set `webhookUrl`. */
275
+ webhookSecret: string | null;
269
276
  raw: Json;
270
277
  };
271
278
  /** The `telem.monitors` namespace. */
@@ -323,6 +330,12 @@ declare class TimeoutError extends TelemError {
323
330
  constructor(message: string, cause?: unknown);
324
331
  }
325
332
 
333
+ /**
334
+ * Check a monitor webhook: the `Telem-Signature` header against the raw body.
335
+ * True when the signature is correct and not older than `toleranceSeconds`.
336
+ */
337
+ declare function verifyWebhook(body: string | Uint8Array, header: string, secret: string, toleranceSeconds?: number): Promise<boolean>;
338
+
326
339
  /** Metadata keys the trajectory payload owns. A caller-supplied value for any of
327
340
  * these is dropped rather than allowed to forge identity. */
328
341
  declare const RESERVED_METADATA: ReadonlySet<string>;
@@ -453,4 +466,4 @@ declare class Telem {
453
466
  providers(): Promise<ProviderInfo[]>;
454
467
  }
455
468
 
456
- export { type FetchOptions, type FetchResponse, type FetchResult, type Json, type Monitor, type MonitorCreateOptions, type MonitorPollOptions, type MonitorProvider, type MonitorUpdateOptions, type MonitorsResource, type ProviderInfo, type ProviderRun, RESERVED_METADATA, type SearchDefaults, type SearchOptions, type SearchResponse, type SearchResult, type SessionResults, type SessionSummary, type SessionsResource, type SnapshotArgs, Telem, type TelemClientErrorCode, TelemError, type TelemErrorOptions, type TelemOptions, TimeoutError, type TrajectoryArgs, type TrajectoryEnvelope, type TrajectorySnapshot, buildMetadata, buildSnapshot, contentAnchor, Telem as default, eventNodeKey, fingerprint, sessionKey, snapshotNodeKey, toolMarker, windowAnchor, withTrajectory };
469
+ export { type FetchOptions, type FetchResponse, type FetchResult, type Json, type Monitor, type MonitorCreateOptions, type MonitorPollOptions, type MonitorProvider, type MonitorUpdateOptions, type MonitorsResource, type ProviderInfo, type ProviderRun, RESERVED_METADATA, type SearchDefaults, type SearchOptions, type SearchResponse, type SearchResult, type SessionResults, type SessionSummary, type SessionsResource, type SnapshotArgs, Telem, type TelemClientErrorCode, TelemError, type TelemErrorOptions, type TelemOptions, TimeoutError, type TrajectoryArgs, type TrajectoryEnvelope, type TrajectorySnapshot, buildMetadata, buildSnapshot, contentAnchor, Telem as default, eventNodeKey, fingerprint, sessionKey, snapshotNodeKey, toolMarker, verifyWebhook, windowAnchor, withTrajectory };
package/dist/index.js CHANGED
@@ -22,7 +22,7 @@ import {
22
22
  } from "./chunk-DKTEG7EY.js";
23
23
 
24
24
  // src/version.ts
25
- var VERSION = "0.2.5";
25
+ var VERSION = "0.2.6";
26
26
 
27
27
  // src/config.ts
28
28
  var DEFAULT_BASE_URL = "https://router.telem.ai";
@@ -340,6 +340,8 @@ function monitorFrom(body) {
340
340
  sessionId: String(data.session_id ?? ""),
341
341
  createdAt: data.created_at ?? "",
342
342
  lastPolledAt: data.last_polled_at ?? null,
343
+ webhookUrl: data.webhook_url ?? null,
344
+ webhookSecret: data.webhook_secret ?? null,
343
345
  raw: data
344
346
  };
345
347
  }
@@ -359,6 +361,7 @@ function createMonitors(config) {
359
361
  body.options.provider_overrides = options.providerOverrides;
360
362
  }
361
363
  if (options.metadata !== void 0) body.metadata = options.metadata;
364
+ if (options.webhookUrl !== void 0) body.webhook_url = options.webhookUrl;
362
365
  const data = await request(config, "POST", "/v1/monitors", body, options.signal, "rate_limit");
363
366
  return monitorFrom(data);
364
367
  },
@@ -378,6 +381,7 @@ function createMonitors(config) {
378
381
  if (options.status !== void 0) body.status = options.status;
379
382
  if (options.frequency !== void 0) body.frequency = options.frequency;
380
383
  if (options.providerOverrides !== void 0) body.provider_overrides = options.providerOverrides;
384
+ if (options.webhookUrl !== void 0) body.webhook_url = options.webhookUrl;
381
385
  const route = path(monitorId);
382
386
  return monitorFrom(await request(config, "PATCH", route, body, options.signal));
383
387
  },
@@ -396,6 +400,23 @@ function createMonitors(config) {
396
400
  }
397
401
  };
398
402
  }
403
+ async function verifyWebhook(body, header, secret, toleranceSeconds = 300) {
404
+ const parts = Object.fromEntries(
405
+ header.split(",").map((item) => [item.slice(0, item.indexOf("=")), item.slice(item.indexOf("=") + 1)])
406
+ );
407
+ const t = parts.t ?? "";
408
+ const v1 = parts.v1 ?? "";
409
+ if (!/^\d+$/.test(t) || Math.abs(Date.now() / 1e3 - Number(t)) > toleranceSeconds) return false;
410
+ if (!/^([0-9a-f]{2})+$/.test(v1)) return false;
411
+ const encoder = new TextEncoder();
412
+ const raw = typeof body === "string" ? encoder.encode(body) : body;
413
+ const signed = new Uint8Array([...encoder.encode(`${t}.`), ...raw]);
414
+ const key = await crypto.subtle.importKey("raw", encoder.encode(secret), { name: "HMAC", hash: "SHA-256" }, false, [
415
+ "verify"
416
+ ]);
417
+ const signature = new Uint8Array(v1.match(/../g).map((byte) => parseInt(byte, 16)));
418
+ return crypto.subtle.verify("HMAC", key, signature, signed);
419
+ }
399
420
 
400
421
  // src/methods/providers.ts
401
422
  async function providers(config) {
@@ -540,6 +561,7 @@ export {
540
561
  sessionKey,
541
562
  snapshotNodeKey,
542
563
  toolMarker,
564
+ verifyWebhook,
543
565
  windowAnchor,
544
566
  withTrajectory
545
567
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@telemai/sdk",
3
- "version": "0.2.5",
3
+ "version": "0.2.6",
4
4
  "description": "Telem web search and fetch for JavaScript and TypeScript.",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",