@scalemule/sdk 0.0.29 → 0.0.30

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
@@ -1542,6 +1542,7 @@ declare class RealtimeService extends ServiceModule {
1542
1542
  /** Disconnect and clean up all subscriptions. */
1543
1543
  disconnect(): void;
1544
1544
  private connect;
1545
+ private fetchTicketAndConnect;
1545
1546
  private authenticate;
1546
1547
  private handleMessage;
1547
1548
  private dispatchMessage;
package/dist/index.d.ts CHANGED
@@ -1542,6 +1542,7 @@ declare class RealtimeService extends ServiceModule {
1542
1542
  /** Disconnect and clean up all subscriptions. */
1543
1543
  disconnect(): void;
1544
1544
  private connect;
1545
+ private fetchTicketAndConnect;
1545
1546
  private authenticate;
1546
1547
  private handleMessage;
1547
1548
  private dispatchMessage;
package/dist/index.js CHANGED
@@ -3775,10 +3775,29 @@ var RealtimeService = class extends ServiceModule {
3775
3775
  // --------------------------------------------------------------------------
3776
3776
  connect() {
3777
3777
  if (this._status === "connecting" || this._status === "connected") return;
3778
- const baseUrl = this.client.getBaseUrl();
3779
- const wsUrl = baseUrl.replace(/^http/, "ws") + "/v1/realtime/ws";
3780
3778
  this.setStatus(this.reconnectAttempt > 0 ? "reconnecting" : "connecting");
3779
+ this.fetchTicketAndConnect();
3780
+ }
3781
+ async fetchTicketAndConnect() {
3782
+ const baseUrl = this.client.getBaseUrl();
3781
3783
  try {
3784
+ const headers = { "Content-Type": "application/json" };
3785
+ const apiKey = this.client.getApiKey();
3786
+ if (apiKey) headers["x-api-key"] = apiKey;
3787
+ const token = this.client.getSessionToken();
3788
+ if (token) headers["Authorization"] = `Bearer ${token}`;
3789
+ const ticketRes = await fetch(`${baseUrl}/v1/realtime/ws/ticket`, {
3790
+ method: "POST",
3791
+ headers
3792
+ });
3793
+ let wsUrl;
3794
+ if (ticketRes.ok) {
3795
+ const ticketData = await ticketRes.json();
3796
+ const ticket = ticketData.ticket;
3797
+ wsUrl = baseUrl.replace(/^http/, "ws") + `/v1/realtime/ws?ticket=${encodeURIComponent(ticket)}`;
3798
+ } else {
3799
+ wsUrl = baseUrl.replace(/^http/, "ws") + "/v1/realtime/ws";
3800
+ }
3782
3801
  this.ws = new WebSocket(wsUrl);
3783
3802
  } catch {
3784
3803
  this.scheduleReconnect();
package/dist/index.mjs CHANGED
@@ -3404,10 +3404,29 @@ var RealtimeService = class extends ServiceModule {
3404
3404
  // --------------------------------------------------------------------------
3405
3405
  connect() {
3406
3406
  if (this._status === "connecting" || this._status === "connected") return;
3407
- const baseUrl = this.client.getBaseUrl();
3408
- const wsUrl = baseUrl.replace(/^http/, "ws") + "/v1/realtime/ws";
3409
3407
  this.setStatus(this.reconnectAttempt > 0 ? "reconnecting" : "connecting");
3408
+ this.fetchTicketAndConnect();
3409
+ }
3410
+ async fetchTicketAndConnect() {
3411
+ const baseUrl = this.client.getBaseUrl();
3410
3412
  try {
3413
+ const headers = { "Content-Type": "application/json" };
3414
+ const apiKey = this.client.getApiKey();
3415
+ if (apiKey) headers["x-api-key"] = apiKey;
3416
+ const token = this.client.getSessionToken();
3417
+ if (token) headers["Authorization"] = `Bearer ${token}`;
3418
+ const ticketRes = await fetch(`${baseUrl}/v1/realtime/ws/ticket`, {
3419
+ method: "POST",
3420
+ headers
3421
+ });
3422
+ let wsUrl;
3423
+ if (ticketRes.ok) {
3424
+ const ticketData = await ticketRes.json();
3425
+ const ticket = ticketData.ticket;
3426
+ wsUrl = baseUrl.replace(/^http/, "ws") + `/v1/realtime/ws?ticket=${encodeURIComponent(ticket)}`;
3427
+ } else {
3428
+ wsUrl = baseUrl.replace(/^http/, "ws") + "/v1/realtime/ws";
3429
+ }
3411
3430
  this.ws = new WebSocket(wsUrl);
3412
3431
  } catch {
3413
3432
  this.scheduleReconnect();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scalemule/sdk",
3
- "version": "0.0.29",
3
+ "version": "0.0.30",
4
4
  "description": "Official TypeScript/JavaScript SDK for ScaleMule Backend-as-a-Service",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",