@poolse/sdk 2.22.0 → 2.24.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 +99 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +102 -3
- package/dist/index.d.ts +102 -3
- package/dist/index.js +99 -8
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1539,13 +1539,43 @@ var MeResource = class {
|
|
|
1539
1539
|
this.client = client;
|
|
1540
1540
|
}
|
|
1541
1541
|
client;
|
|
1542
|
+
current = null;
|
|
1543
|
+
listeners = /* @__PURE__ */ new Set();
|
|
1542
1544
|
/** GET /v1/me */
|
|
1543
|
-
show(signal) {
|
|
1544
|
-
|
|
1545
|
+
async show(signal) {
|
|
1546
|
+
const me = await this.client.request({
|
|
1545
1547
|
method: "GET",
|
|
1546
1548
|
path: "/v1/me",
|
|
1547
1549
|
...signal ? { signal } : {}
|
|
1548
1550
|
});
|
|
1551
|
+
this.set(me);
|
|
1552
|
+
return me;
|
|
1553
|
+
}
|
|
1554
|
+
/** PATCH /v1/me — the user's own preferences. */
|
|
1555
|
+
async update(body, signal) {
|
|
1556
|
+
const me = await this.client.request({
|
|
1557
|
+
method: "PATCH",
|
|
1558
|
+
path: "/v1/me",
|
|
1559
|
+
body,
|
|
1560
|
+
...signal ? { signal } : {}
|
|
1561
|
+
});
|
|
1562
|
+
this.set(me);
|
|
1563
|
+
return me;
|
|
1564
|
+
}
|
|
1565
|
+
/** The last user `show` / `update` returned, or null before the first. */
|
|
1566
|
+
peek() {
|
|
1567
|
+
return this.current;
|
|
1568
|
+
}
|
|
1569
|
+
/** Called with the user whenever `show` or `update` returns a new one. */
|
|
1570
|
+
onChange(fn) {
|
|
1571
|
+
this.listeners.add(fn);
|
|
1572
|
+
return () => {
|
|
1573
|
+
this.listeners.delete(fn);
|
|
1574
|
+
};
|
|
1575
|
+
}
|
|
1576
|
+
set(me) {
|
|
1577
|
+
this.current = me;
|
|
1578
|
+
for (const fn of this.listeners) fn(me);
|
|
1549
1579
|
}
|
|
1550
1580
|
};
|
|
1551
1581
|
|
|
@@ -1693,6 +1723,49 @@ var LiveCallsResource = class {
|
|
|
1693
1723
|
}
|
|
1694
1724
|
};
|
|
1695
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
|
+
|
|
1696
1769
|
// src/voice/call-room.ts
|
|
1697
1770
|
function toDevices(raw, kind) {
|
|
1698
1771
|
const out = [];
|
|
@@ -2192,7 +2265,12 @@ var RestClient = class {
|
|
|
2192
2265
|
let triedAuthRefresh = false;
|
|
2193
2266
|
for (; ; ) {
|
|
2194
2267
|
const body = opts.body === void 0 ? void 0 : JSON.stringify(opts.body);
|
|
2195
|
-
const headers = await this.buildHeaders(
|
|
2268
|
+
const headers = await this.buildHeaders(
|
|
2269
|
+
opts.method,
|
|
2270
|
+
idempotencyKey,
|
|
2271
|
+
body !== void 0,
|
|
2272
|
+
opts.bearer
|
|
2273
|
+
);
|
|
2196
2274
|
let response;
|
|
2197
2275
|
try {
|
|
2198
2276
|
const init = { method: opts.method, headers };
|
|
@@ -2214,7 +2292,7 @@ var RestClient = class {
|
|
|
2214
2292
|
return await parseJsonOrNull(response);
|
|
2215
2293
|
}
|
|
2216
2294
|
if (response.status === 401) {
|
|
2217
|
-
if (!triedAuthRefresh) {
|
|
2295
|
+
if (!triedAuthRefresh && opts.bearer === void 0) {
|
|
2218
2296
|
this.tokenCache.invalidate();
|
|
2219
2297
|
triedAuthRefresh = true;
|
|
2220
2298
|
continue;
|
|
@@ -2252,10 +2330,10 @@ var RestClient = class {
|
|
|
2252
2330
|
const qs = params.toString();
|
|
2253
2331
|
return qs ? `${base}?${qs}` : base;
|
|
2254
2332
|
}
|
|
2255
|
-
async buildHeaders(method, idempotencyKey, hasBody) {
|
|
2333
|
+
async buildHeaders(method, idempotencyKey, hasBody, bearer) {
|
|
2256
2334
|
const headers = { Accept: "application/json" };
|
|
2257
2335
|
if (hasBody) headers["Content-Type"] = "application/json";
|
|
2258
|
-
const token = await this.config.getToken();
|
|
2336
|
+
const token = bearer ?? await this.config.getToken();
|
|
2259
2337
|
if (token) headers["Authorization"] = `Bearer ${token}`;
|
|
2260
2338
|
if (!IDEMPOTENT_METHODS.has(method) && idempotencyKey) {
|
|
2261
2339
|
headers["Idempotency-Key"] = idempotencyKey;
|
|
@@ -2431,6 +2509,8 @@ var Poolse = class {
|
|
|
2431
2509
|
callTokens;
|
|
2432
2510
|
/** Whether a call is running on a conversation — for a Join banner. */
|
|
2433
2511
|
liveCalls;
|
|
2512
|
+
/** A conversation's drop-in room: voice or video, nobody rung. */
|
|
2513
|
+
rooms;
|
|
2434
2514
|
resolved;
|
|
2435
2515
|
tokenCache;
|
|
2436
2516
|
constructor(config) {
|
|
@@ -2450,6 +2530,7 @@ var Poolse = class {
|
|
|
2450
2530
|
this.iceServers = new IceServersResource(this.rest);
|
|
2451
2531
|
this.callTokens = new CallTokensResource(this.rest);
|
|
2452
2532
|
this.liveCalls = new LiveCallsResource(this.rest);
|
|
2533
|
+
this.rooms = new RoomsResource(this.rest);
|
|
2453
2534
|
this.realtime = new PoolseRealtime(cachedConfig, this.tokenCache, {
|
|
2454
2535
|
...this.resolved.wsUrl !== void 0 ? { wsUrl: this.resolved.wsUrl } : {},
|
|
2455
2536
|
socketPath: this.resolved.socketPath,
|
|
@@ -2492,7 +2573,7 @@ var Poolse = class {
|
|
|
2492
2573
|
};
|
|
2493
2574
|
|
|
2494
2575
|
// src/version.ts
|
|
2495
|
-
var version = "2.
|
|
2576
|
+
var version = "2.24.0";
|
|
2496
2577
|
|
|
2497
2578
|
// src/call-log.ts
|
|
2498
2579
|
function parseCallLogBody(body) {
|
|
@@ -2528,6 +2609,7 @@ function parseCallLogBody(body) {
|
|
|
2528
2609
|
durationMs,
|
|
2529
2610
|
joinedUserIds: joined,
|
|
2530
2611
|
version: obj.v === 2 ? 2 : 1,
|
|
2612
|
+
callKind: obj.call_kind === "room" ? "room" : "call",
|
|
2531
2613
|
callerUserId: typeof obj.caller_user_id === "string" ? obj.caller_user_id : null,
|
|
2532
2614
|
participants,
|
|
2533
2615
|
endReason: isEndReason(obj.end_reason) ? obj.end_reason : null,
|
|
@@ -2578,6 +2660,15 @@ function describeCallLog(log, currentUserId) {
|
|
|
2578
2660
|
const duration = log.durationMs !== null ? formatCallDuration(log.durationMs) : null;
|
|
2579
2661
|
const group = log.participants.length > 1;
|
|
2580
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
|
+
}
|
|
2581
2672
|
const mine = me !== null ? log.participants.find((p) => p.userId === me) : void 0;
|
|
2582
2673
|
const isCaller = me !== null && log.callerUserId === me;
|
|
2583
2674
|
if (log.version === 1 || !isCaller && !mine) {
|
|
@@ -2670,6 +2761,7 @@ exports.Poolse = Poolse;
|
|
|
2670
2761
|
exports.PoolseError = PoolseError;
|
|
2671
2762
|
exports.PoolseRealtime = PoolseRealtime;
|
|
2672
2763
|
exports.RateLimitedError = RateLimitedError;
|
|
2764
|
+
exports.RoomsResource = RoomsResource;
|
|
2673
2765
|
exports.UserChannel = UserChannel;
|
|
2674
2766
|
exports.UsersResource = UsersResource;
|
|
2675
2767
|
exports.VoiceRoom = VoiceRoom;
|