@signalwire/js 4.0.0-dev-20260428183200 → 4.0.0-dev-20260429174756
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/browser.mjs +79 -79
- package/dist/browser.mjs.map +1 -1
- package/dist/browser.umd.js +79 -79
- package/dist/browser.umd.js.map +1 -1
- package/dist/index.cjs +65 -65
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +48 -48
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +48 -48
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +65 -65
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1743,15 +1743,15 @@ var DependencyContainer = class {
|
|
|
1743
1743
|
this._baseURL = this.apiHost;
|
|
1744
1744
|
this._credential = {};
|
|
1745
1745
|
}
|
|
1746
|
-
get
|
|
1747
|
-
return this.
|
|
1746
|
+
get userId() {
|
|
1747
|
+
return this.user.id;
|
|
1748
1748
|
}
|
|
1749
|
-
get
|
|
1750
|
-
if (!this.
|
|
1751
|
-
return this.
|
|
1749
|
+
get user() {
|
|
1750
|
+
if (!this._user) throw new require_operators.DependencyError("User");
|
|
1751
|
+
return this._user;
|
|
1752
1752
|
}
|
|
1753
|
-
set
|
|
1754
|
-
this.
|
|
1753
|
+
set user(user) {
|
|
1754
|
+
this._user = user;
|
|
1755
1755
|
}
|
|
1756
1756
|
get storage() {
|
|
1757
1757
|
if (!this._storageManager) {
|
|
@@ -1797,16 +1797,16 @@ var DependencyContainer = class {
|
|
|
1797
1797
|
this._deviceController = void 0;
|
|
1798
1798
|
}
|
|
1799
1799
|
get authorizationStateKey() {
|
|
1800
|
-
return `sw:${this.
|
|
1800
|
+
return `sw:${this.userId}:as`;
|
|
1801
1801
|
}
|
|
1802
1802
|
get protocolKey() {
|
|
1803
|
-
return `sw:${this.
|
|
1803
|
+
return `sw:${this.userId}:pt`;
|
|
1804
1804
|
}
|
|
1805
1805
|
get attachedCallsKey() {
|
|
1806
|
-
return `sw:${this.
|
|
1806
|
+
return `sw:${this.userId}:att`;
|
|
1807
1807
|
}
|
|
1808
|
-
|
|
1809
|
-
return this.
|
|
1808
|
+
getUserFromAddressId() {
|
|
1809
|
+
return this.user.addresses[0]?.id ?? "";
|
|
1810
1810
|
}
|
|
1811
1811
|
set baseURL(baseURL) {
|
|
1812
1812
|
this._baseURL = baseURL;
|
|
@@ -2632,14 +2632,14 @@ var Fetchable = class extends Destroyable {
|
|
|
2632
2632
|
};
|
|
2633
2633
|
|
|
2634
2634
|
//#endregion
|
|
2635
|
-
//#region src/core/entities/
|
|
2635
|
+
//#region src/core/entities/User.ts
|
|
2636
2636
|
/**
|
|
2637
|
-
* Authenticated
|
|
2637
|
+
* Authenticated user profile.
|
|
2638
2638
|
*
|
|
2639
2639
|
* Fetched automatically when a {@link SignalWire} connects.
|
|
2640
2640
|
* Contains identity, contact, and organization details.
|
|
2641
2641
|
*/
|
|
2642
|
-
var
|
|
2642
|
+
var User = class extends Fetchable {
|
|
2643
2643
|
constructor(http) {
|
|
2644
2644
|
super("/api/fabric/subscriber/info", http);
|
|
2645
2645
|
}
|
|
@@ -3334,9 +3334,9 @@ var Participant = class extends Destroyable {
|
|
|
3334
3334
|
get meta$() {
|
|
3335
3335
|
return this.cachedObservable("meta$", () => this._state$.pipe((0, rxjs_operators.map)((state) => state.meta), (0, rxjs_operators.distinctUntilChanged)()));
|
|
3336
3336
|
}
|
|
3337
|
-
/** Observable of the participant's
|
|
3338
|
-
get
|
|
3339
|
-
return this.cachedObservable("
|
|
3337
|
+
/** Observable of the participant's user ID. */
|
|
3338
|
+
get userId$() {
|
|
3339
|
+
return this.cachedObservable("userId$", () => this._state$.pipe((0, rxjs_operators.map)((state) => state.subscriber_id), (0, rxjs_operators.distinctUntilChanged)()));
|
|
3340
3340
|
}
|
|
3341
3341
|
/** Observable of the participant's address ID. */
|
|
3342
3342
|
get addressId$() {
|
|
@@ -3440,8 +3440,8 @@ var Participant = class extends Destroyable {
|
|
|
3440
3440
|
get meta() {
|
|
3441
3441
|
return this._state$.value.meta;
|
|
3442
3442
|
}
|
|
3443
|
-
/**
|
|
3444
|
-
get
|
|
3443
|
+
/** User ID of this participant, or `undefined` if not available. */
|
|
3444
|
+
get userId() {
|
|
3445
3445
|
return this._state$.value.subscriber_id;
|
|
3446
3446
|
}
|
|
3447
3447
|
/** Address ID of this participant, or `undefined` if not available. */
|
|
@@ -9102,7 +9102,7 @@ var ClientSessionManager = class extends Destroyable {
|
|
|
9102
9102
|
this._errors$ = this.createReplaySubject(1);
|
|
9103
9103
|
this._authState$ = this.createBehaviorSubject({ kind: "unauthenticated" });
|
|
9104
9104
|
this._wasClientBound = false;
|
|
9105
|
-
this.
|
|
9105
|
+
this._userInfo$ = this.createBehaviorSubject(null);
|
|
9106
9106
|
this._calls$ = this.createBehaviorSubject({});
|
|
9107
9107
|
this._iceServers$ = this.createBehaviorSubject([]);
|
|
9108
9108
|
attachManager.setSession(this);
|
|
@@ -9115,11 +9115,11 @@ var ClientSessionManager = class extends Destroyable {
|
|
|
9115
9115
|
get incomingCalls() {
|
|
9116
9116
|
return Object.values(this._calls$.value).filter((call) => call.direction === "inbound");
|
|
9117
9117
|
}
|
|
9118
|
-
get
|
|
9119
|
-
return this.
|
|
9118
|
+
get userInfo$() {
|
|
9119
|
+
return this._userInfo$.asObservable();
|
|
9120
9120
|
}
|
|
9121
|
-
get
|
|
9122
|
-
return this.
|
|
9121
|
+
get userInfo() {
|
|
9122
|
+
return this._userInfo$.value;
|
|
9123
9123
|
}
|
|
9124
9124
|
get calls$() {
|
|
9125
9125
|
return this.cachedObservable("calls$", () => this._calls$.pipe((0, rxjs.map)((calls) => Object.values(calls))));
|
|
@@ -9564,22 +9564,22 @@ var ConversationMessageCollection = class extends EntityCollection {
|
|
|
9564
9564
|
}
|
|
9565
9565
|
};
|
|
9566
9566
|
var ConversationsManager = class {
|
|
9567
|
-
constructor(clientSession, http,
|
|
9567
|
+
constructor(clientSession, http, getUserAddressId, onError) {
|
|
9568
9568
|
this.clientSession = clientSession;
|
|
9569
9569
|
this.http = http;
|
|
9570
|
-
this.
|
|
9570
|
+
this.getUserAddressId = getUserAddressId;
|
|
9571
9571
|
this.onError = onError;
|
|
9572
9572
|
this.groupIds = /* @__PURE__ */ new Map();
|
|
9573
9573
|
}
|
|
9574
9574
|
async join(addressId) {
|
|
9575
|
-
const
|
|
9575
|
+
const userFromAddressId = this.getUserAddressId();
|
|
9576
9576
|
try {
|
|
9577
9577
|
const response = await this.http.request({
|
|
9578
9578
|
...POST_PARAMS,
|
|
9579
9579
|
url: `/api/fabric/conversations/join`,
|
|
9580
9580
|
body: JSON.stringify({
|
|
9581
|
-
from_fabric_address_id:
|
|
9582
|
-
fabric_address_ids: [addressId,
|
|
9581
|
+
from_fabric_address_id: userFromAddressId,
|
|
9582
|
+
fabric_address_ids: [addressId, userFromAddressId]
|
|
9583
9583
|
})
|
|
9584
9584
|
});
|
|
9585
9585
|
if (response.ok && !!response.body) {
|
|
@@ -9601,14 +9601,14 @@ var ConversationsManager = class {
|
|
|
9601
9601
|
}
|
|
9602
9602
|
async sendText(text, destinationAddressId) {
|
|
9603
9603
|
const groupId = this.groupIds.get(destinationAddressId) ?? await this.join(destinationAddressId);
|
|
9604
|
-
const
|
|
9604
|
+
const userFromAddressId = this.getUserAddressId();
|
|
9605
9605
|
try {
|
|
9606
9606
|
if ((await this.http.request({
|
|
9607
9607
|
...POST_PARAMS,
|
|
9608
9608
|
url: "/api/fabric/messages",
|
|
9609
9609
|
body: JSON.stringify({
|
|
9610
9610
|
group_id: groupId,
|
|
9611
|
-
from_fabric_address_id:
|
|
9611
|
+
from_fabric_address_id: userFromAddressId,
|
|
9612
9612
|
text
|
|
9613
9613
|
})
|
|
9614
9614
|
})).ok) return;
|
|
@@ -9680,17 +9680,17 @@ var DeviceTokenManager = class extends Destroyable {
|
|
|
9680
9680
|
return this._effectiveExpireIn;
|
|
9681
9681
|
}
|
|
9682
9682
|
/**
|
|
9683
|
-
* Activates the Client Bound SAT flow when the
|
|
9683
|
+
* Activates the Client Bound SAT flow when the user's token has
|
|
9684
9684
|
* `sat:refresh` scope.
|
|
9685
9685
|
*
|
|
9686
9686
|
* Steps:
|
|
9687
|
-
* 1. Check
|
|
9687
|
+
* 1. Check user's `sat_claims` for `sat:refresh` scope
|
|
9688
9688
|
* 2. Call `/api/fabric/subscriber/devices/token` with a DPoP proof
|
|
9689
9689
|
* 3. Reauthenticate the session with the Client Bound SAT + DPoP proof
|
|
9690
9690
|
* 4. Emit token to trigger the reactive refresh pipeline
|
|
9691
9691
|
*/
|
|
9692
|
-
async activate(
|
|
9693
|
-
const { satClaims } =
|
|
9692
|
+
async activate(user, session, updateCredential) {
|
|
9693
|
+
const { satClaims } = user;
|
|
9694
9694
|
if (!satClaims?.scope?.includes(SAT_REFRESH_SCOPE)) {
|
|
9695
9695
|
logger$6.debug("[DeviceToken] No sat:refresh scope, skipping Client Bound SAT activation");
|
|
9696
9696
|
return;
|
|
@@ -10533,7 +10533,7 @@ var SignalWire = class extends Destroyable {
|
|
|
10533
10533
|
constructor(credentialProvider, options = {}) {
|
|
10534
10534
|
super();
|
|
10535
10535
|
this.preferences = new ClientPreferences();
|
|
10536
|
-
this.
|
|
10536
|
+
this._user$ = this.createBehaviorSubject(void 0);
|
|
10537
10537
|
this._directory$ = this.createBehaviorSubject(void 0);
|
|
10538
10538
|
this._isConnected$ = this.createBehaviorSubject(false);
|
|
10539
10539
|
this._isRegistered$ = this.createBehaviorSubject(false);
|
|
@@ -10673,7 +10673,7 @@ var SignalWire = class extends Destroyable {
|
|
|
10673
10673
|
if (this._deps.persistSession) this._deps.storage.setItem("sw:cached_credential", credential, "local");
|
|
10674
10674
|
}
|
|
10675
10675
|
async init() {
|
|
10676
|
-
this.
|
|
10676
|
+
this._user$.next(new User(this._deps.http));
|
|
10677
10677
|
if (!this._options.skipConnection) await this.connect();
|
|
10678
10678
|
if (!this._options.reconnectAttachedCalls && this._attachManager) await this._attachManager.flush();
|
|
10679
10679
|
if (!this._options.skipRegister) try {
|
|
@@ -10737,13 +10737,13 @@ var SignalWire = class extends Destroyable {
|
|
|
10737
10737
|
async connect() {
|
|
10738
10738
|
await this.teardownTransportAndSession();
|
|
10739
10739
|
try {
|
|
10740
|
-
const
|
|
10741
|
-
if (!
|
|
10742
|
-
if (!await (0, rxjs.firstValueFrom)(
|
|
10743
|
-
this._deps.
|
|
10740
|
+
const user = this._user$.value;
|
|
10741
|
+
if (!user) throw new require_operators.UnexpectedError("User not initialized before connect");
|
|
10742
|
+
if (!await (0, rxjs.firstValueFrom)(user.fetched$)) throw new require_operators.UnexpectedError("Failed to fetch user information - fetched$ emitted false");
|
|
10743
|
+
this._deps.user = user;
|
|
10744
10744
|
} catch (error) {
|
|
10745
|
-
logger$1.error(`[SignalWire] Failed to fetch
|
|
10746
|
-
throw new require_operators.UnexpectedError("Error fetching
|
|
10745
|
+
logger$1.error(`[SignalWire] Failed to fetch user information: ${error instanceof Error ? error.message : "Unknown error"}. This usually means the user token is invalid or expired.`);
|
|
10746
|
+
throw new require_operators.UnexpectedError("Error fetching user information", { cause: error });
|
|
10747
10747
|
}
|
|
10748
10748
|
const errorHandler = (error) => {
|
|
10749
10749
|
this._errors$.next(error);
|
|
@@ -10777,7 +10777,7 @@ var SignalWire = class extends Destroyable {
|
|
|
10777
10777
|
logger$1.debug("[SignalWire] Developer refresh disabled — Client Bound SAT activation starting");
|
|
10778
10778
|
}
|
|
10779
10779
|
this._deviceTokenManager = new DeviceTokenManager(this._dpopManager, this._deps.http, (error) => this._errors$.next(error), () => this._deps.credential);
|
|
10780
|
-
await this._deviceTokenManager.activate(this._deps.
|
|
10780
|
+
await this._deviceTokenManager.activate(this._deps.user, this._clientSession, (cred) => {
|
|
10781
10781
|
this._deps.credential = {
|
|
10782
10782
|
...this._deps.credential,
|
|
10783
10783
|
...cred
|
|
@@ -10787,7 +10787,7 @@ var SignalWire = class extends Destroyable {
|
|
|
10787
10787
|
this.subscribeTo(this._clientSession.authenticated$.pipe((0, rxjs.skip)(1), (0, rxjs.filter)(Boolean)), async () => {
|
|
10788
10788
|
try {
|
|
10789
10789
|
if (this._deviceTokenManager) {
|
|
10790
|
-
await this._deviceTokenManager.activate(this._deps.
|
|
10790
|
+
await this._deviceTokenManager.activate(this._deps.user, this._clientSession, (cred) => {
|
|
10791
10791
|
this._deps.credential = {
|
|
10792
10792
|
...this._deps.credential,
|
|
10793
10793
|
...cred
|
|
@@ -10800,15 +10800,15 @@ var SignalWire = class extends Destroyable {
|
|
|
10800
10800
|
this._errors$.next(error instanceof Error ? error : new Error(String(error), { cause: error }));
|
|
10801
10801
|
}
|
|
10802
10802
|
try {
|
|
10803
|
-
logger$1.debug("[SignalWire] Re-registering
|
|
10803
|
+
logger$1.debug("[SignalWire] Re-registering user after reconnect");
|
|
10804
10804
|
await this.register();
|
|
10805
|
-
logger$1.debug("[SignalWire]
|
|
10805
|
+
logger$1.debug("[SignalWire] User re-registered successfully after reconnect");
|
|
10806
10806
|
} catch (error) {
|
|
10807
10807
|
logger$1.error("[SignalWire] Re-registration failed after reconnect:", error);
|
|
10808
10808
|
this._errors$.next(error instanceof Error ? error : new Error(String(error), { cause: error }));
|
|
10809
10809
|
}
|
|
10810
10810
|
});
|
|
10811
|
-
const conversationManager = new ConversationsManager(this._clientSession, this._deps.http, () => this._deps.
|
|
10811
|
+
const conversationManager = new ConversationsManager(this._clientSession, this._deps.http, () => this._deps.getUserFromAddressId(), errorHandler);
|
|
10812
10812
|
const directory = new DirectoryManager(this._deps.http, this._clientSession, conversationManager, errorHandler);
|
|
10813
10813
|
this._directory$.next(directory);
|
|
10814
10814
|
this._clientSession.setDirectory(directory);
|
|
@@ -10819,22 +10819,22 @@ var SignalWire = class extends Destroyable {
|
|
|
10819
10819
|
});
|
|
10820
10820
|
}
|
|
10821
10821
|
/**
|
|
10822
|
-
* Observable that emits the {@link
|
|
10822
|
+
* Observable that emits the {@link User} profile once fetched,
|
|
10823
10823
|
* or `undefined` before authentication completes.
|
|
10824
10824
|
*
|
|
10825
10825
|
* @example
|
|
10826
10826
|
* ```ts
|
|
10827
|
-
* client.
|
|
10828
|
-
* if (
|
|
10827
|
+
* client.user$.subscribe(u => {
|
|
10828
|
+
* if (u) console.log('Logged in as', u.email);
|
|
10829
10829
|
* });
|
|
10830
10830
|
* ```
|
|
10831
10831
|
*/
|
|
10832
|
-
get
|
|
10833
|
-
return this.deferEmission(this.
|
|
10832
|
+
get user$() {
|
|
10833
|
+
return this.deferEmission(this._user$.asObservable());
|
|
10834
10834
|
}
|
|
10835
|
-
/** Current
|
|
10836
|
-
get
|
|
10837
|
-
return this.
|
|
10835
|
+
/** Current user snapshot, or `undefined` if not yet authenticated. */
|
|
10836
|
+
get user() {
|
|
10837
|
+
return this._user$.value;
|
|
10838
10838
|
}
|
|
10839
10839
|
/**
|
|
10840
10840
|
* Observable that emits the {@link Directory} instance once the client is connected,
|
|
@@ -10858,11 +10858,11 @@ var SignalWire = class extends Destroyable {
|
|
|
10858
10858
|
get directory() {
|
|
10859
10859
|
return this._directory$.value;
|
|
10860
10860
|
}
|
|
10861
|
-
/** Observable that emits when the
|
|
10861
|
+
/** Observable that emits when the user registration state changes. */
|
|
10862
10862
|
get isRegistered$() {
|
|
10863
10863
|
return this.deferEmission(this._isRegistered$.asObservable());
|
|
10864
10864
|
}
|
|
10865
|
-
/** Whether the
|
|
10865
|
+
/** Whether the user is currently registered. */
|
|
10866
10866
|
get isRegistered() {
|
|
10867
10867
|
return this._isRegistered$.value;
|
|
10868
10868
|
}
|
|
@@ -10995,7 +10995,7 @@ var SignalWire = class extends Destroyable {
|
|
|
10995
10995
|
await (0, rxjs.firstValueFrom)(this.ready$.pipe((0, rxjs.filter)((ready$1) => ready$1 === true)));
|
|
10996
10996
|
}
|
|
10997
10997
|
/**
|
|
10998
|
-
* Registers the
|
|
10998
|
+
* Registers the user as online to receive inbound calls and events.
|
|
10999
10999
|
*
|
|
11000
11000
|
* Waits for authentication to complete before sending the registration.
|
|
11001
11001
|
* If the initial attempt fails, reauthentication is attempted automatically.
|
|
@@ -11016,7 +11016,7 @@ var SignalWire = class extends Destroyable {
|
|
|
11016
11016
|
this._errors$.next(error instanceof Error ? error : new Error(String(error), { cause: error }));
|
|
11017
11017
|
throw error;
|
|
11018
11018
|
}
|
|
11019
|
-
logger$1.debug("[SignalWire] Failed to register
|
|
11019
|
+
logger$1.debug("[SignalWire] Failed to register user, trying reauthentication...");
|
|
11020
11020
|
try {
|
|
11021
11021
|
await this._clientSession.reauthenticate(this._deps.credential.token);
|
|
11022
11022
|
logger$1.debug("[SignalWire] Reauthentication successful, retrying register()");
|
|
@@ -11027,14 +11027,14 @@ var SignalWire = class extends Destroyable {
|
|
|
11027
11027
|
this._isRegistered$.next(true);
|
|
11028
11028
|
} catch (reauthError) {
|
|
11029
11029
|
logger$1.error("[SignalWire] Reauthentication failed during register():", reauthError);
|
|
11030
|
-
const registerError = new require_operators.InvalidCredentialsError("Failed to register
|
|
11030
|
+
const registerError = new require_operators.InvalidCredentialsError("Failed to register user, and reauthentication attempt also failed. Please check your credentials.", { cause: reauthError instanceof Error ? reauthError : new Error(String(reauthError), { cause: reauthError }) });
|
|
11031
11031
|
this._errors$.next(registerError);
|
|
11032
11032
|
throw registerError;
|
|
11033
11033
|
}
|
|
11034
11034
|
}
|
|
11035
11035
|
}
|
|
11036
11036
|
/**
|
|
11037
|
-
* Unregisters the
|
|
11037
|
+
* Unregisters the user, going offline for inbound calls.
|
|
11038
11038
|
*
|
|
11039
11039
|
* The WebSocket connection remains open; use {@link disconnect} to fully close it.
|
|
11040
11040
|
*/
|
|
@@ -11046,7 +11046,7 @@ var SignalWire = class extends Destroyable {
|
|
|
11046
11046
|
}));
|
|
11047
11047
|
this._isRegistered$.next(false);
|
|
11048
11048
|
} catch (error) {
|
|
11049
|
-
logger$1.error("[SignalWire] Failed to unregister
|
|
11049
|
+
logger$1.error("[SignalWire] Failed to unregister user:", error);
|
|
11050
11050
|
this._errors$.next(error instanceof Error ? error : new Error(String(error), { cause: error }));
|
|
11051
11051
|
throw error;
|
|
11052
11052
|
}
|
|
@@ -11521,9 +11521,9 @@ exports.SelfCapabilities = SelfCapabilities;
|
|
|
11521
11521
|
exports.SelfParticipant = SelfParticipant;
|
|
11522
11522
|
exports.SignalWire = SignalWire;
|
|
11523
11523
|
exports.StaticCredentialProvider = StaticCredentialProvider;
|
|
11524
|
-
exports.Subscriber = Subscriber;
|
|
11525
11524
|
exports.TokenRefreshError = require_operators.TokenRefreshError;
|
|
11526
11525
|
exports.UnexpectedError = require_operators.UnexpectedError;
|
|
11526
|
+
exports.User = User;
|
|
11527
11527
|
exports.VertoPongError = require_operators.VertoPongError;
|
|
11528
11528
|
exports.WebRTCCall = WebRTCCall;
|
|
11529
11529
|
exports.embeddableCall = embeddableCall;
|