@scalemule/sdk 0.0.68 → 0.0.69

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
@@ -130,6 +130,9 @@ interface ScaleMuleConfig {
130
130
  applicationId?: string;
131
131
  /** Base URL for API requests. Overrides environment preset. */
132
132
  baseUrl?: string;
133
+ /** Public gateway for WebSockets when HTTP uses a same-origin cookie proxy.
134
+ * When set, realtime requires a successful ticket exchange; bearer fallback is disabled. */
135
+ realtimeUrl?: string;
133
136
  /** Environment preset ('dev' or 'prod'). Defaults to 'prod'. */
134
137
  environment?: 'dev' | 'prod';
135
138
  /** Retry configuration for transient failures */
@@ -442,6 +445,7 @@ declare class ScaleMuleClient {
442
445
  private apiKey;
443
446
  private applicationId;
444
447
  private baseUrl;
448
+ private realtimeUrl?;
445
449
  private debug;
446
450
  private storage;
447
451
  private defaultTimeout;
@@ -525,6 +529,8 @@ declare class ScaleMuleClient {
525
529
  /** Persist known accounts to storage */
526
530
  private persistKnownAccounts;
527
531
  getBaseUrl(): string;
532
+ getRealtimeUrl(): string;
533
+ requiresRealtimeTicket(): boolean;
528
534
  getApiKey(): string;
529
535
  isOnline(): boolean;
530
536
  getOfflineQueueLength(): number;
package/dist/index.d.ts CHANGED
@@ -130,6 +130,9 @@ interface ScaleMuleConfig {
130
130
  applicationId?: string;
131
131
  /** Base URL for API requests. Overrides environment preset. */
132
132
  baseUrl?: string;
133
+ /** Public gateway for WebSockets when HTTP uses a same-origin cookie proxy.
134
+ * When set, realtime requires a successful ticket exchange; bearer fallback is disabled. */
135
+ realtimeUrl?: string;
133
136
  /** Environment preset ('dev' or 'prod'). Defaults to 'prod'. */
134
137
  environment?: 'dev' | 'prod';
135
138
  /** Retry configuration for transient failures */
@@ -442,6 +445,7 @@ declare class ScaleMuleClient {
442
445
  private apiKey;
443
446
  private applicationId;
444
447
  private baseUrl;
448
+ private realtimeUrl?;
445
449
  private debug;
446
450
  private storage;
447
451
  private defaultTimeout;
@@ -525,6 +529,8 @@ declare class ScaleMuleClient {
525
529
  /** Persist known accounts to storage */
526
530
  private persistKnownAccounts;
527
531
  getBaseUrl(): string;
532
+ getRealtimeUrl(): string;
533
+ requiresRealtimeTicket(): boolean;
528
534
  getApiKey(): string;
529
535
  isOnline(): boolean;
530
536
  getOfflineQueueLength(): number;
package/dist/index.js CHANGED
@@ -830,6 +830,7 @@ var ScaleMuleClient = class {
830
830
  this.apiKey = config.apiKey;
831
831
  this.applicationId = config.applicationId || null;
832
832
  this.baseUrl = config.baseUrl || GATEWAY_URLS[config.environment || "prod"];
833
+ this.realtimeUrl = config.realtimeUrl;
833
834
  this.debug = config.debug || false;
834
835
  this.storage = config.storage || createDefaultStorage();
835
836
  this.defaultTimeout = config.timeout || DEFAULT_TIMEOUT;
@@ -1122,6 +1123,12 @@ var ScaleMuleClient = class {
1122
1123
  getBaseUrl() {
1123
1124
  return this.baseUrl;
1124
1125
  }
1126
+ getRealtimeUrl() {
1127
+ return this.realtimeUrl || this.baseUrl;
1128
+ }
1129
+ requiresRealtimeTicket() {
1130
+ return this.realtimeUrl !== void 0;
1131
+ }
1125
1132
  getApiKey() {
1126
1133
  return this.apiKey;
1127
1134
  }
@@ -4322,6 +4329,7 @@ var RealtimeService = class extends ServiceModule {
4322
4329
  }
4323
4330
  async fetchTicketAndConnect() {
4324
4331
  const baseUrl = this.client.getBaseUrl();
4332
+ const realtimeUrl = this.client.getRealtimeUrl();
4325
4333
  try {
4326
4334
  const headers = { "Content-Type": "application/json" };
4327
4335
  const apiKey = this.client.getApiKey();
@@ -4344,10 +4352,12 @@ var RealtimeService = class extends ServiceModule {
4344
4352
  if (ticketRes.ok) {
4345
4353
  const ticketData = await ticketRes.json();
4346
4354
  const ticket = ticketData.ticket;
4347
- wsUrl = baseUrl.replace(/^http/, "ws") + `/v1/realtime/ws?ticket=${encodeURIComponent(ticket)}`;
4355
+ if (typeof ticket !== "string" || !ticket) throw new Error("Missing realtime ticket");
4356
+ wsUrl = realtimeUrl.replace(/^http/, "ws") + `/v1/realtime/ws?ticket=${encodeURIComponent(ticket)}`;
4348
4357
  this.usedTicketAuth = true;
4349
4358
  } else {
4350
- wsUrl = baseUrl.replace(/^http/, "ws") + "/v1/realtime/ws";
4359
+ if (this.client.requiresRealtimeTicket()) throw new Error("Realtime ticket required");
4360
+ wsUrl = realtimeUrl.replace(/^http/, "ws") + "/v1/realtime/ws";
4351
4361
  this.usedTicketAuth = false;
4352
4362
  }
4353
4363
  this.ws = new WebSocket(wsUrl);
package/dist/index.mjs CHANGED
@@ -721,6 +721,7 @@ var ScaleMuleClient = class {
721
721
  this.apiKey = config.apiKey;
722
722
  this.applicationId = config.applicationId || null;
723
723
  this.baseUrl = config.baseUrl || GATEWAY_URLS[config.environment || "prod"];
724
+ this.realtimeUrl = config.realtimeUrl;
724
725
  this.debug = config.debug || false;
725
726
  this.storage = config.storage || createDefaultStorage();
726
727
  this.defaultTimeout = config.timeout || DEFAULT_TIMEOUT;
@@ -1013,6 +1014,12 @@ var ScaleMuleClient = class {
1013
1014
  getBaseUrl() {
1014
1015
  return this.baseUrl;
1015
1016
  }
1017
+ getRealtimeUrl() {
1018
+ return this.realtimeUrl || this.baseUrl;
1019
+ }
1020
+ requiresRealtimeTicket() {
1021
+ return this.realtimeUrl !== void 0;
1022
+ }
1016
1023
  getApiKey() {
1017
1024
  return this.apiKey;
1018
1025
  }
@@ -4213,6 +4220,7 @@ var RealtimeService = class extends ServiceModule {
4213
4220
  }
4214
4221
  async fetchTicketAndConnect() {
4215
4222
  const baseUrl = this.client.getBaseUrl();
4223
+ const realtimeUrl = this.client.getRealtimeUrl();
4216
4224
  try {
4217
4225
  const headers = { "Content-Type": "application/json" };
4218
4226
  const apiKey = this.client.getApiKey();
@@ -4235,10 +4243,12 @@ var RealtimeService = class extends ServiceModule {
4235
4243
  if (ticketRes.ok) {
4236
4244
  const ticketData = await ticketRes.json();
4237
4245
  const ticket = ticketData.ticket;
4238
- wsUrl = baseUrl.replace(/^http/, "ws") + `/v1/realtime/ws?ticket=${encodeURIComponent(ticket)}`;
4246
+ if (typeof ticket !== "string" || !ticket) throw new Error("Missing realtime ticket");
4247
+ wsUrl = realtimeUrl.replace(/^http/, "ws") + `/v1/realtime/ws?ticket=${encodeURIComponent(ticket)}`;
4239
4248
  this.usedTicketAuth = true;
4240
4249
  } else {
4241
- wsUrl = baseUrl.replace(/^http/, "ws") + "/v1/realtime/ws";
4250
+ if (this.client.requiresRealtimeTicket()) throw new Error("Realtime ticket required");
4251
+ wsUrl = realtimeUrl.replace(/^http/, "ws") + "/v1/realtime/ws";
4242
4252
  this.usedTicketAuth = false;
4243
4253
  }
4244
4254
  this.ws = new WebSocket(wsUrl);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scalemule/sdk",
3
- "version": "0.0.68",
3
+ "version": "0.0.69",
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",