@poolse/sdk 2.23.0 → 2.25.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/dist/index.cjs CHANGED
@@ -1723,6 +1723,49 @@ var LiveCallsResource = class {
1723
1723
  }
1724
1724
  };
1725
1725
 
1726
+ // src/resources/rooms.ts
1727
+ var RoomsResource = class {
1728
+ constructor(client) {
1729
+ this.client = client;
1730
+ }
1731
+ client;
1732
+ /** POST /v1/conversations/:id/room — start the room, or join what is live. */
1733
+ start(conversationId, media = "audio", signal) {
1734
+ return this.client.request({
1735
+ method: "POST",
1736
+ path: `/v1/conversations/${encodeURIComponent(conversationId)}/room`,
1737
+ body: { media },
1738
+ ...signal ? { signal } : {}
1739
+ });
1740
+ }
1741
+ /**
1742
+ * POST /v1/conversations/:id/calls — like `start`, but RINGS the other
1743
+ * members' phones (a support desk calling a customer). Off by default
1744
+ * in the room UI; an app opts in. Joins whatever is live instead, the
1745
+ * same as `start`.
1746
+ */
1747
+ ring(conversationId, media = "audio", signal) {
1748
+ return this.client.request({
1749
+ method: "POST",
1750
+ path: `/v1/conversations/${encodeURIComponent(conversationId)}/calls`,
1751
+ body: { media },
1752
+ ...signal ? { signal } : {}
1753
+ });
1754
+ }
1755
+ /**
1756
+ * POST /v1/calls/:id/hangup — leave. Never ends the room for the others;
1757
+ * it ends once empty. Authorized by the session's control token.
1758
+ */
1759
+ leave(session) {
1760
+ return this.client.request({
1761
+ method: "POST",
1762
+ path: `/v1/calls/${encodeURIComponent(session.call.id)}/hangup`,
1763
+ bearer: session.control_token,
1764
+ idempotencyKey: null
1765
+ });
1766
+ }
1767
+ };
1768
+
1726
1769
  // src/voice/call-room.ts
1727
1770
  function toDevices(raw, kind) {
1728
1771
  const out = [];
@@ -2222,7 +2265,12 @@ var RestClient = class {
2222
2265
  let triedAuthRefresh = false;
2223
2266
  for (; ; ) {
2224
2267
  const body = opts.body === void 0 ? void 0 : JSON.stringify(opts.body);
2225
- const headers = await this.buildHeaders(opts.method, idempotencyKey, body !== void 0);
2268
+ const headers = await this.buildHeaders(
2269
+ opts.method,
2270
+ idempotencyKey,
2271
+ body !== void 0,
2272
+ opts.bearer
2273
+ );
2226
2274
  let response;
2227
2275
  try {
2228
2276
  const init = { method: opts.method, headers };
@@ -2244,7 +2292,7 @@ var RestClient = class {
2244
2292
  return await parseJsonOrNull(response);
2245
2293
  }
2246
2294
  if (response.status === 401) {
2247
- if (!triedAuthRefresh) {
2295
+ if (!triedAuthRefresh && opts.bearer === void 0) {
2248
2296
  this.tokenCache.invalidate();
2249
2297
  triedAuthRefresh = true;
2250
2298
  continue;
@@ -2282,10 +2330,10 @@ var RestClient = class {
2282
2330
  const qs = params.toString();
2283
2331
  return qs ? `${base}?${qs}` : base;
2284
2332
  }
2285
- async buildHeaders(method, idempotencyKey, hasBody) {
2333
+ async buildHeaders(method, idempotencyKey, hasBody, bearer) {
2286
2334
  const headers = { Accept: "application/json" };
2287
2335
  if (hasBody) headers["Content-Type"] = "application/json";
2288
- const token = await this.config.getToken();
2336
+ const token = bearer ?? await this.config.getToken();
2289
2337
  if (token) headers["Authorization"] = `Bearer ${token}`;
2290
2338
  if (!IDEMPOTENT_METHODS.has(method) && idempotencyKey) {
2291
2339
  headers["Idempotency-Key"] = idempotencyKey;
@@ -2461,6 +2509,8 @@ var Poolse = class {
2461
2509
  callTokens;
2462
2510
  /** Whether a call is running on a conversation — for a Join banner. */
2463
2511
  liveCalls;
2512
+ /** A conversation's drop-in room: voice or video, nobody rung. */
2513
+ rooms;
2464
2514
  resolved;
2465
2515
  tokenCache;
2466
2516
  constructor(config) {
@@ -2480,6 +2530,7 @@ var Poolse = class {
2480
2530
  this.iceServers = new IceServersResource(this.rest);
2481
2531
  this.callTokens = new CallTokensResource(this.rest);
2482
2532
  this.liveCalls = new LiveCallsResource(this.rest);
2533
+ this.rooms = new RoomsResource(this.rest);
2483
2534
  this.realtime = new PoolseRealtime(cachedConfig, this.tokenCache, {
2484
2535
  ...this.resolved.wsUrl !== void 0 ? { wsUrl: this.resolved.wsUrl } : {},
2485
2536
  socketPath: this.resolved.socketPath,
@@ -2522,7 +2573,7 @@ var Poolse = class {
2522
2573
  };
2523
2574
 
2524
2575
  // src/version.ts
2525
- var version = "2.23.0";
2576
+ var version = "2.24.0";
2526
2577
 
2527
2578
  // src/call-log.ts
2528
2579
  function parseCallLogBody(body) {
@@ -2558,6 +2609,7 @@ function parseCallLogBody(body) {
2558
2609
  durationMs,
2559
2610
  joinedUserIds: joined,
2560
2611
  version: obj.v === 2 ? 2 : 1,
2612
+ callKind: obj.call_kind === "room" ? "room" : "call",
2561
2613
  callerUserId: typeof obj.caller_user_id === "string" ? obj.caller_user_id : null,
2562
2614
  participants,
2563
2615
  endReason: isEndReason(obj.end_reason) ? obj.end_reason : null,
@@ -2608,6 +2660,15 @@ function describeCallLog(log, currentUserId) {
2608
2660
  const duration = log.durationMs !== null ? formatCallDuration(log.durationMs) : null;
2609
2661
  const group = log.participants.length > 1;
2610
2662
  const me = currentUserId;
2663
+ if (log.callKind === "room") {
2664
+ const n = (/* @__PURE__ */ new Set([...log.joinedUserIds, ...log.participants.map((p) => p.userId)])).size;
2665
+ const title = log.media === "video" ? "Video room" : "Voice room";
2666
+ const people = n > 0 ? `${n} joined` : null;
2667
+ return display(log.media, title, [duration, people].filter(Boolean).join(" \xB7 ") || null, {
2668
+ direction: null,
2669
+ callBack: false
2670
+ });
2671
+ }
2611
2672
  const mine = me !== null ? log.participants.find((p) => p.userId === me) : void 0;
2612
2673
  const isCaller = me !== null && log.callerUserId === me;
2613
2674
  if (log.version === 1 || !isCaller && !mine) {
@@ -2700,6 +2761,7 @@ exports.Poolse = Poolse;
2700
2761
  exports.PoolseError = PoolseError;
2701
2762
  exports.PoolseRealtime = PoolseRealtime;
2702
2763
  exports.RateLimitedError = RateLimitedError;
2764
+ exports.RoomsResource = RoomsResource;
2703
2765
  exports.UserChannel = UserChannel;
2704
2766
  exports.UsersResource = UsersResource;
2705
2767
  exports.VoiceRoom = VoiceRoom;