@rstreamlabs/tunnels 3.8.2 → 3.8.3

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.d.mts CHANGED
@@ -234,8 +234,10 @@ type TURNCredentialMode = z.infer<typeof turnCredentialModeSchema>;
234
234
  interface CreateAPITURNCredentialsOptions {
235
235
  apiUrl?: string;
236
236
  credentials: RstreamCredentials;
237
+ fetch?: typeof globalThis.fetch;
237
238
  projectEndpoint?: string;
238
239
  projectId?: string;
240
+ requestTimeoutMilliseconds?: number;
239
241
  ttlSeconds?: number;
240
242
  }
241
243
  interface CreatePATTURNCredentialsOptions {
@@ -271,11 +273,13 @@ interface CreateTURNCredentialsOptions {
271
273
  controlPlaneCredentials?: RstreamCredentials;
272
274
  credentials?: RstreamCredentials;
273
275
  engine?: string;
276
+ fetch?: typeof globalThis.fetch;
274
277
  keyringBaseUrl?: string;
275
278
  mode?: TURNCredentialMode;
276
279
  now?: Date | number;
277
280
  projectEndpoint?: string;
278
281
  projectId?: string;
282
+ requestTimeoutMilliseconds?: number;
279
283
  serverPublicKeyHex?: string;
280
284
  tokenEndpoint?: string;
281
285
  ttlSeconds?: number;
@@ -5511,11 +5515,11 @@ declare const webTTYSessionEventSchema: z.ZodObject<{
5511
5515
  created_at: z.ZodString;
5512
5516
  type: z.ZodEnum<{
5513
5517
  error: "error";
5518
+ close: "close";
5514
5519
  open: "open";
5515
5520
  ack: "ack";
5516
5521
  data: "data";
5517
5522
  resize: "resize";
5518
- close: "close";
5519
5523
  participant: "participant";
5520
5524
  control: "control";
5521
5525
  recording_state: "recording_state";
package/dist/index.d.ts CHANGED
@@ -234,8 +234,10 @@ type TURNCredentialMode = z.infer<typeof turnCredentialModeSchema>;
234
234
  interface CreateAPITURNCredentialsOptions {
235
235
  apiUrl?: string;
236
236
  credentials: RstreamCredentials;
237
+ fetch?: typeof globalThis.fetch;
237
238
  projectEndpoint?: string;
238
239
  projectId?: string;
240
+ requestTimeoutMilliseconds?: number;
239
241
  ttlSeconds?: number;
240
242
  }
241
243
  interface CreatePATTURNCredentialsOptions {
@@ -271,11 +273,13 @@ interface CreateTURNCredentialsOptions {
271
273
  controlPlaneCredentials?: RstreamCredentials;
272
274
  credentials?: RstreamCredentials;
273
275
  engine?: string;
276
+ fetch?: typeof globalThis.fetch;
274
277
  keyringBaseUrl?: string;
275
278
  mode?: TURNCredentialMode;
276
279
  now?: Date | number;
277
280
  projectEndpoint?: string;
278
281
  projectId?: string;
282
+ requestTimeoutMilliseconds?: number;
279
283
  serverPublicKeyHex?: string;
280
284
  tokenEndpoint?: string;
281
285
  ttlSeconds?: number;
@@ -5511,11 +5515,11 @@ declare const webTTYSessionEventSchema: z.ZodObject<{
5511
5515
  created_at: z.ZodString;
5512
5516
  type: z.ZodEnum<{
5513
5517
  error: "error";
5518
+ close: "close";
5514
5519
  open: "open";
5515
5520
  ack: "ack";
5516
5521
  data: "data";
5517
5522
  resize: "resize";
5518
- close: "close";
5519
5523
  participant: "participant";
5520
5524
  control: "control";
5521
5525
  recording_state: "recording_state";
package/dist/index.js CHANGED
@@ -1775,6 +1775,52 @@ var import_rstream8 = require("@rstreamlabs/rstream");
1775
1775
  var import_rstream9 = require("@rstreamlabs/rstream");
1776
1776
  var import_rstream10 = require("@rstreamlabs/rstream");
1777
1777
  var import_turn = require("@rstreamlabs/rstream/turn");
1778
+
1779
+ // src/control-plane-fetch.ts
1780
+ function createRequestLifetime(parent, timeoutMilliseconds) {
1781
+ const controller = new AbortController();
1782
+ const abort = () => controller.abort(parent.reason);
1783
+ if (parent.aborted) {
1784
+ abort();
1785
+ } else {
1786
+ parent.addEventListener("abort", abort, { once: true });
1787
+ }
1788
+ const timeout = setTimeout(
1789
+ () => controller.abort(new Error("Control plane request timed out.")),
1790
+ timeoutMilliseconds
1791
+ );
1792
+ return {
1793
+ close: () => {
1794
+ clearTimeout(timeout);
1795
+ parent.removeEventListener("abort", abort);
1796
+ },
1797
+ signal: controller.signal
1798
+ };
1799
+ }
1800
+ function createBoundedControlPlaneFetch(timeoutMilliseconds) {
1801
+ return async (input, init) => {
1802
+ const request = new Request(input, init);
1803
+ const headers = new Headers(request.headers);
1804
+ headers.set("Connection", "close");
1805
+ const lifetime = createRequestLifetime(request.signal, timeoutMilliseconds);
1806
+ try {
1807
+ const response = await globalThis.fetch(request, {
1808
+ headers,
1809
+ signal: lifetime.signal
1810
+ });
1811
+ const responseBody = response.body === null ? null : new Uint8Array(await response.arrayBuffer());
1812
+ return new Response(responseBody, {
1813
+ headers: Object.fromEntries(response.headers.entries()),
1814
+ status: response.status,
1815
+ statusText: response.statusText
1816
+ });
1817
+ } finally {
1818
+ lifetime.close();
1819
+ }
1820
+ };
1821
+ }
1822
+
1823
+ // src/turn.ts
1778
1824
  var z8 = __toESM(require("zod"));
1779
1825
  var import_crypto = __toESM(require("crypto"));
1780
1826
  var defaultTURNPort = 3478;
@@ -1782,6 +1828,8 @@ var defaultTURNSPort = 5349;
1782
1828
  var defaultTURNCredentialTTLSeconds = 10 * 60;
1783
1829
  var maxTURNCredentialTTLSeconds = 60 * 60;
1784
1830
  var maxTURNKeyringBytes = 8 * 1024;
1831
+ var defaultAPIRequestTimeoutMilliseconds = 1e4;
1832
+ var maxAPIRequestTimeoutMilliseconds = 6e4;
1785
1833
  var turnTokenClaimsSchema = z8.object({
1786
1834
  exp: z8.number().int().optional(),
1787
1835
  iat: z8.number().int().optional(),
@@ -1815,6 +1863,15 @@ function normalizeTTLSeconds(ttlSeconds) {
1815
1863
  }
1816
1864
  return ttl;
1817
1865
  }
1866
+ function normalizeAPIRequestTimeoutMilliseconds(timeoutMilliseconds) {
1867
+ const timeout = timeoutMilliseconds ?? defaultAPIRequestTimeoutMilliseconds;
1868
+ if (!Number.isInteger(timeout) || timeout < 1 || timeout > maxAPIRequestTimeoutMilliseconds) {
1869
+ throw new Error(
1870
+ "TURN API request timeout must be an integer between 1 and 60000 milliseconds."
1871
+ );
1872
+ }
1873
+ return timeout;
1874
+ }
1818
1875
  function createAPITURNCredentialsParams(ttlSeconds) {
1819
1876
  return ttlSeconds === void 0 ? {} : { ttlSeconds: normalizeTTLSeconds(ttlSeconds) };
1820
1877
  }
@@ -2008,11 +2065,16 @@ async function createAPITURNCredentials(options) {
2008
2065
  "Project ID or project endpoint is required for TURN API mode."
2009
2066
  );
2010
2067
  }
2068
+ const requestTimeoutMilliseconds = normalizeAPIRequestTimeoutMilliseconds(
2069
+ options.requestTimeoutMilliseconds
2070
+ );
2071
+ const params = createAPITURNCredentialsParams(options.ttlSeconds);
2072
+ const request = options.fetch ?? createBoundedControlPlaneFetch(requestTimeoutMilliseconds);
2011
2073
  const client = new import_rstream10.RstreamClient({
2012
2074
  apiUrl: options.apiUrl,
2013
- credentials: options.credentials
2075
+ credentials: options.credentials,
2076
+ fetch: request
2014
2077
  });
2015
- const params = createAPITURNCredentialsParams(options.ttlSeconds);
2016
2078
  if (projectId) {
2017
2079
  return await client.tunnels.projects.createTurnCredentials(
2018
2080
  projectId,
@@ -2153,8 +2215,10 @@ async function createTURNCredentials(options) {
2153
2215
  return await createAPITURNCredentials({
2154
2216
  apiUrl: options.apiUrl,
2155
2217
  credentials: controlPlaneCredentials,
2218
+ fetch: options.fetch,
2156
2219
  projectEndpoint,
2157
2220
  projectId: options.projectId,
2221
+ requestTimeoutMilliseconds: options.requestTimeoutMilliseconds,
2158
2222
  ttlSeconds: options.ttlSeconds
2159
2223
  });
2160
2224
  }
package/dist/index.mjs CHANGED
@@ -412,6 +412,52 @@ import { isClientCredentials as isClientCredentials2 } from "@rstreamlabs/rstrea
412
412
  import { isTokenCredentials as isTokenCredentials2 } from "@rstreamlabs/rstream";
413
413
  import { RstreamClient as RstreamClient2 } from "@rstreamlabs/rstream";
414
414
  import { turnCredentialsSchema } from "@rstreamlabs/rstream/turn";
415
+
416
+ // src/control-plane-fetch.ts
417
+ function createRequestLifetime(parent, timeoutMilliseconds) {
418
+ const controller = new AbortController();
419
+ const abort = () => controller.abort(parent.reason);
420
+ if (parent.aborted) {
421
+ abort();
422
+ } else {
423
+ parent.addEventListener("abort", abort, { once: true });
424
+ }
425
+ const timeout = setTimeout(
426
+ () => controller.abort(new Error("Control plane request timed out.")),
427
+ timeoutMilliseconds
428
+ );
429
+ return {
430
+ close: () => {
431
+ clearTimeout(timeout);
432
+ parent.removeEventListener("abort", abort);
433
+ },
434
+ signal: controller.signal
435
+ };
436
+ }
437
+ function createBoundedControlPlaneFetch(timeoutMilliseconds) {
438
+ return async (input, init) => {
439
+ const request = new Request(input, init);
440
+ const headers = new Headers(request.headers);
441
+ headers.set("Connection", "close");
442
+ const lifetime = createRequestLifetime(request.signal, timeoutMilliseconds);
443
+ try {
444
+ const response = await globalThis.fetch(request, {
445
+ headers,
446
+ signal: lifetime.signal
447
+ });
448
+ const responseBody = response.body === null ? null : new Uint8Array(await response.arrayBuffer());
449
+ return new Response(responseBody, {
450
+ headers: Object.fromEntries(response.headers.entries()),
451
+ status: response.status,
452
+ statusText: response.statusText
453
+ });
454
+ } finally {
455
+ lifetime.close();
456
+ }
457
+ };
458
+ }
459
+
460
+ // src/turn.ts
415
461
  import * as z from "zod";
416
462
  import crypto from "crypto";
417
463
  var defaultTURNPort = 3478;
@@ -419,6 +465,8 @@ var defaultTURNSPort = 5349;
419
465
  var defaultTURNCredentialTTLSeconds = 10 * 60;
420
466
  var maxTURNCredentialTTLSeconds = 60 * 60;
421
467
  var maxTURNKeyringBytes = 8 * 1024;
468
+ var defaultAPIRequestTimeoutMilliseconds = 1e4;
469
+ var maxAPIRequestTimeoutMilliseconds = 6e4;
422
470
  var turnTokenClaimsSchema = z.object({
423
471
  exp: z.number().int().optional(),
424
472
  iat: z.number().int().optional(),
@@ -452,6 +500,15 @@ function normalizeTTLSeconds(ttlSeconds) {
452
500
  }
453
501
  return ttl;
454
502
  }
503
+ function normalizeAPIRequestTimeoutMilliseconds(timeoutMilliseconds) {
504
+ const timeout = timeoutMilliseconds ?? defaultAPIRequestTimeoutMilliseconds;
505
+ if (!Number.isInteger(timeout) || timeout < 1 || timeout > maxAPIRequestTimeoutMilliseconds) {
506
+ throw new Error(
507
+ "TURN API request timeout must be an integer between 1 and 60000 milliseconds."
508
+ );
509
+ }
510
+ return timeout;
511
+ }
455
512
  function createAPITURNCredentialsParams(ttlSeconds) {
456
513
  return ttlSeconds === void 0 ? {} : { ttlSeconds: normalizeTTLSeconds(ttlSeconds) };
457
514
  }
@@ -645,11 +702,16 @@ async function createAPITURNCredentials(options) {
645
702
  "Project ID or project endpoint is required for TURN API mode."
646
703
  );
647
704
  }
705
+ const requestTimeoutMilliseconds = normalizeAPIRequestTimeoutMilliseconds(
706
+ options.requestTimeoutMilliseconds
707
+ );
708
+ const params = createAPITURNCredentialsParams(options.ttlSeconds);
709
+ const request = options.fetch ?? createBoundedControlPlaneFetch(requestTimeoutMilliseconds);
648
710
  const client = new RstreamClient2({
649
711
  apiUrl: options.apiUrl,
650
- credentials: options.credentials
712
+ credentials: options.credentials,
713
+ fetch: request
651
714
  });
652
- const params = createAPITURNCredentialsParams(options.ttlSeconds);
653
715
  if (projectId) {
654
716
  return await client.tunnels.projects.createTurnCredentials(
655
717
  projectId,
@@ -790,8 +852,10 @@ async function createTURNCredentials(options) {
790
852
  return await createAPITURNCredentials({
791
853
  apiUrl: options.apiUrl,
792
854
  credentials: controlPlaneCredentials,
855
+ fetch: options.fetch,
793
856
  projectEndpoint,
794
857
  projectId: options.projectId,
858
+ requestTimeoutMilliseconds: options.requestTimeoutMilliseconds,
795
859
  ttlSeconds: options.ttlSeconds
796
860
  });
797
861
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rstreamlabs/tunnels",
3
- "version": "3.8.2",
3
+ "version": "3.8.3",
4
4
  "description": "JS/TS SDK for the rstream Engine API and tunnel runtime APIs.",
5
5
  "author": "@uartnet <hello@rstream.io>",
6
6
  "repository": {
@@ -47,7 +47,7 @@
47
47
  "typescript-config": "*"
48
48
  },
49
49
  "dependencies": {
50
- "@rstreamlabs/rstream": "3.8.1",
50
+ "@rstreamlabs/rstream": "3.8.2",
51
51
  "@types/jsonwebtoken": "^9.0.10",
52
52
  "jsonwebtoken": "^9.0.3",
53
53
  "zod": "^4.4.3"