@scalemule/nextjs 0.0.8 → 0.0.9

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/client.d.mts CHANGED
@@ -64,6 +64,7 @@ declare class ScaleMuleClient {
64
64
  private enableOfflineQueue;
65
65
  private sessionGate;
66
66
  private resolveSessionGate;
67
+ private workspaceId;
67
68
  constructor(config: ClientConfig);
68
69
  /**
69
70
  * Sync offline queue when coming back online
@@ -85,6 +86,15 @@ declare class ScaleMuleClient {
85
86
  * Check if currently rate limited
86
87
  */
87
88
  isRateLimited(): boolean;
89
+ /**
90
+ * Set the active workspace context. All subsequent requests will include
91
+ * x-sm-workspace-id header. Pass null to clear.
92
+ */
93
+ setWorkspaceContext(id: string | null): void;
94
+ /**
95
+ * Get the current workspace ID
96
+ */
97
+ getWorkspaceId(): string | null;
88
98
  /**
89
99
  * Get the gateway URL
90
100
  */
package/dist/client.d.ts CHANGED
@@ -64,6 +64,7 @@ declare class ScaleMuleClient {
64
64
  private enableOfflineQueue;
65
65
  private sessionGate;
66
66
  private resolveSessionGate;
67
+ private workspaceId;
67
68
  constructor(config: ClientConfig);
68
69
  /**
69
70
  * Sync offline queue when coming back online
@@ -85,6 +86,15 @@ declare class ScaleMuleClient {
85
86
  * Check if currently rate limited
86
87
  */
87
88
  isRateLimited(): boolean;
89
+ /**
90
+ * Set the active workspace context. All subsequent requests will include
91
+ * x-sm-workspace-id header. Pass null to clear.
92
+ */
93
+ setWorkspaceContext(id: string | null): void;
94
+ /**
95
+ * Get the current workspace ID
96
+ */
97
+ getWorkspaceId(): string | null;
88
98
  /**
89
99
  * Get the gateway URL
90
100
  */
package/dist/client.js CHANGED
@@ -17,6 +17,7 @@ var GATEWAY_URLS = {
17
17
  };
18
18
  var SESSION_STORAGE_KEY = "scalemule_session";
19
19
  var USER_ID_STORAGE_KEY = "scalemule_user_id";
20
+ var WORKSPACE_STORAGE_KEY = "scalemule_workspace_id";
20
21
  var RETRYABLE_STATUS_CODES = /* @__PURE__ */ new Set([408, 429, 500, 502, 503, 504]);
21
22
  function sleep(ms) {
22
23
  return new Promise((resolve) => setTimeout(resolve, ms));
@@ -275,6 +276,7 @@ var ScaleMuleClient = class {
275
276
  this.offlineQueue = null;
276
277
  this.sessionGate = null;
277
278
  this.resolveSessionGate = null;
279
+ this.workspaceId = null;
278
280
  this.apiKey = config.apiKey;
279
281
  this.applicationId = config.applicationId || null;
280
282
  this.gatewayUrl = resolveGatewayUrl(config);
@@ -345,6 +347,24 @@ var ScaleMuleClient = class {
345
347
  isRateLimited() {
346
348
  return this.rateLimitQueue?.isRateLimited || false;
347
349
  }
350
+ /**
351
+ * Set the active workspace context. All subsequent requests will include
352
+ * x-sm-workspace-id header. Pass null to clear.
353
+ */
354
+ setWorkspaceContext(id) {
355
+ this.workspaceId = id;
356
+ if (id) {
357
+ this.storage.setItem(WORKSPACE_STORAGE_KEY, id);
358
+ } else {
359
+ this.storage.removeItem(WORKSPACE_STORAGE_KEY);
360
+ }
361
+ }
362
+ /**
363
+ * Get the current workspace ID
364
+ */
365
+ getWorkspaceId() {
366
+ return this.workspaceId;
367
+ }
348
368
  /**
349
369
  * Get the gateway URL
350
370
  */
@@ -387,6 +407,8 @@ var ScaleMuleClient = class {
387
407
  const userId = await this.storage.getItem(USER_ID_STORAGE_KEY);
388
408
  if (token) this.sessionToken = token;
389
409
  if (userId) this.userId = userId;
410
+ const wsId = await this.storage.getItem(WORKSPACE_STORAGE_KEY);
411
+ if (wsId) this.workspaceId = wsId;
390
412
  if (token) {
391
413
  this.resolveSessionPending();
392
414
  }
@@ -412,8 +434,10 @@ var ScaleMuleClient = class {
412
434
  async clearSession() {
413
435
  this.sessionToken = null;
414
436
  this.userId = null;
437
+ this.workspaceId = null;
415
438
  await this.storage.removeItem(SESSION_STORAGE_KEY);
416
439
  await this.storage.removeItem(USER_ID_STORAGE_KEY);
440
+ await this.storage.removeItem(WORKSPACE_STORAGE_KEY);
417
441
  if (this.debug) {
418
442
  console.log("[ScaleMule] Session cleared");
419
443
  }
@@ -445,6 +469,9 @@ var ScaleMuleClient = class {
445
469
  if (!options?.skipAuth && this.sessionToken) {
446
470
  headers.set("Authorization", `Bearer ${this.sessionToken}`);
447
471
  }
472
+ if (this.workspaceId) {
473
+ headers.set("x-sm-workspace-id", this.workspaceId);
474
+ }
448
475
  if (!headers.has("Content-Type") && options?.body && typeof options.body === "string") {
449
476
  headers.set("Content-Type", "application/json");
450
477
  }
@@ -600,6 +627,9 @@ var ScaleMuleClient = class {
600
627
  if (this.sessionToken) {
601
628
  headers.set("Authorization", `Bearer ${this.sessionToken}`);
602
629
  }
630
+ if (this.workspaceId) {
631
+ headers.set("x-sm-workspace-id", this.workspaceId);
632
+ }
603
633
  let lastError = null;
604
634
  for (let attempt = 0; attempt <= maxRetries; attempt++) {
605
635
  try {
@@ -737,6 +767,9 @@ var ScaleMuleClient = class {
737
767
  if (this.sessionToken) {
738
768
  xhr.setRequestHeader("Authorization", `Bearer ${this.sessionToken}`);
739
769
  }
770
+ if (this.workspaceId) {
771
+ xhr.setRequestHeader("x-sm-workspace-id", this.workspaceId);
772
+ }
740
773
  xhr.send(formData);
741
774
  });
742
775
  }
package/dist/client.mjs CHANGED
@@ -15,6 +15,7 @@ var GATEWAY_URLS = {
15
15
  };
16
16
  var SESSION_STORAGE_KEY = "scalemule_session";
17
17
  var USER_ID_STORAGE_KEY = "scalemule_user_id";
18
+ var WORKSPACE_STORAGE_KEY = "scalemule_workspace_id";
18
19
  var RETRYABLE_STATUS_CODES = /* @__PURE__ */ new Set([408, 429, 500, 502, 503, 504]);
19
20
  function sleep(ms) {
20
21
  return new Promise((resolve) => setTimeout(resolve, ms));
@@ -273,6 +274,7 @@ var ScaleMuleClient = class {
273
274
  this.offlineQueue = null;
274
275
  this.sessionGate = null;
275
276
  this.resolveSessionGate = null;
277
+ this.workspaceId = null;
276
278
  this.apiKey = config.apiKey;
277
279
  this.applicationId = config.applicationId || null;
278
280
  this.gatewayUrl = resolveGatewayUrl(config);
@@ -343,6 +345,24 @@ var ScaleMuleClient = class {
343
345
  isRateLimited() {
344
346
  return this.rateLimitQueue?.isRateLimited || false;
345
347
  }
348
+ /**
349
+ * Set the active workspace context. All subsequent requests will include
350
+ * x-sm-workspace-id header. Pass null to clear.
351
+ */
352
+ setWorkspaceContext(id) {
353
+ this.workspaceId = id;
354
+ if (id) {
355
+ this.storage.setItem(WORKSPACE_STORAGE_KEY, id);
356
+ } else {
357
+ this.storage.removeItem(WORKSPACE_STORAGE_KEY);
358
+ }
359
+ }
360
+ /**
361
+ * Get the current workspace ID
362
+ */
363
+ getWorkspaceId() {
364
+ return this.workspaceId;
365
+ }
346
366
  /**
347
367
  * Get the gateway URL
348
368
  */
@@ -385,6 +405,8 @@ var ScaleMuleClient = class {
385
405
  const userId = await this.storage.getItem(USER_ID_STORAGE_KEY);
386
406
  if (token) this.sessionToken = token;
387
407
  if (userId) this.userId = userId;
408
+ const wsId = await this.storage.getItem(WORKSPACE_STORAGE_KEY);
409
+ if (wsId) this.workspaceId = wsId;
388
410
  if (token) {
389
411
  this.resolveSessionPending();
390
412
  }
@@ -410,8 +432,10 @@ var ScaleMuleClient = class {
410
432
  async clearSession() {
411
433
  this.sessionToken = null;
412
434
  this.userId = null;
435
+ this.workspaceId = null;
413
436
  await this.storage.removeItem(SESSION_STORAGE_KEY);
414
437
  await this.storage.removeItem(USER_ID_STORAGE_KEY);
438
+ await this.storage.removeItem(WORKSPACE_STORAGE_KEY);
415
439
  if (this.debug) {
416
440
  console.log("[ScaleMule] Session cleared");
417
441
  }
@@ -443,6 +467,9 @@ var ScaleMuleClient = class {
443
467
  if (!options?.skipAuth && this.sessionToken) {
444
468
  headers.set("Authorization", `Bearer ${this.sessionToken}`);
445
469
  }
470
+ if (this.workspaceId) {
471
+ headers.set("x-sm-workspace-id", this.workspaceId);
472
+ }
446
473
  if (!headers.has("Content-Type") && options?.body && typeof options.body === "string") {
447
474
  headers.set("Content-Type", "application/json");
448
475
  }
@@ -598,6 +625,9 @@ var ScaleMuleClient = class {
598
625
  if (this.sessionToken) {
599
626
  headers.set("Authorization", `Bearer ${this.sessionToken}`);
600
627
  }
628
+ if (this.workspaceId) {
629
+ headers.set("x-sm-workspace-id", this.workspaceId);
630
+ }
601
631
  let lastError = null;
602
632
  for (let attempt = 0; attempt <= maxRetries; attempt++) {
603
633
  try {
@@ -735,6 +765,9 @@ var ScaleMuleClient = class {
735
765
  if (this.sessionToken) {
736
766
  xhr.setRequestHeader("Authorization", `Bearer ${this.sessionToken}`);
737
767
  }
768
+ if (this.workspaceId) {
769
+ xhr.setRequestHeader("x-sm-workspace-id", this.workspaceId);
770
+ }
738
771
  xhr.send(formData);
739
772
  });
740
773
  }
package/dist/index.js CHANGED
@@ -22,6 +22,7 @@ var GATEWAY_URLS = {
22
22
  };
23
23
  var SESSION_STORAGE_KEY = "scalemule_session";
24
24
  var USER_ID_STORAGE_KEY = "scalemule_user_id";
25
+ var WORKSPACE_STORAGE_KEY = "scalemule_workspace_id";
25
26
  var RETRYABLE_STATUS_CODES = /* @__PURE__ */ new Set([408, 429, 500, 502, 503, 504]);
26
27
  function sleep(ms) {
27
28
  return new Promise((resolve) => setTimeout(resolve, ms));
@@ -280,6 +281,7 @@ var ScaleMuleClient = class {
280
281
  this.offlineQueue = null;
281
282
  this.sessionGate = null;
282
283
  this.resolveSessionGate = null;
284
+ this.workspaceId = null;
283
285
  this.apiKey = config.apiKey;
284
286
  this.applicationId = config.applicationId || null;
285
287
  this.gatewayUrl = resolveGatewayUrl(config);
@@ -350,6 +352,24 @@ var ScaleMuleClient = class {
350
352
  isRateLimited() {
351
353
  return this.rateLimitQueue?.isRateLimited || false;
352
354
  }
355
+ /**
356
+ * Set the active workspace context. All subsequent requests will include
357
+ * x-sm-workspace-id header. Pass null to clear.
358
+ */
359
+ setWorkspaceContext(id) {
360
+ this.workspaceId = id;
361
+ if (id) {
362
+ this.storage.setItem(WORKSPACE_STORAGE_KEY, id);
363
+ } else {
364
+ this.storage.removeItem(WORKSPACE_STORAGE_KEY);
365
+ }
366
+ }
367
+ /**
368
+ * Get the current workspace ID
369
+ */
370
+ getWorkspaceId() {
371
+ return this.workspaceId;
372
+ }
353
373
  /**
354
374
  * Get the gateway URL
355
375
  */
@@ -392,6 +412,8 @@ var ScaleMuleClient = class {
392
412
  const userId = await this.storage.getItem(USER_ID_STORAGE_KEY);
393
413
  if (token) this.sessionToken = token;
394
414
  if (userId) this.userId = userId;
415
+ const wsId = await this.storage.getItem(WORKSPACE_STORAGE_KEY);
416
+ if (wsId) this.workspaceId = wsId;
395
417
  if (token) {
396
418
  this.resolveSessionPending();
397
419
  }
@@ -417,8 +439,10 @@ var ScaleMuleClient = class {
417
439
  async clearSession() {
418
440
  this.sessionToken = null;
419
441
  this.userId = null;
442
+ this.workspaceId = null;
420
443
  await this.storage.removeItem(SESSION_STORAGE_KEY);
421
444
  await this.storage.removeItem(USER_ID_STORAGE_KEY);
445
+ await this.storage.removeItem(WORKSPACE_STORAGE_KEY);
422
446
  if (this.debug) {
423
447
  console.log("[ScaleMule] Session cleared");
424
448
  }
@@ -450,6 +474,9 @@ var ScaleMuleClient = class {
450
474
  if (!options?.skipAuth && this.sessionToken) {
451
475
  headers.set("Authorization", `Bearer ${this.sessionToken}`);
452
476
  }
477
+ if (this.workspaceId) {
478
+ headers.set("x-sm-workspace-id", this.workspaceId);
479
+ }
453
480
  if (!headers.has("Content-Type") && options?.body && typeof options.body === "string") {
454
481
  headers.set("Content-Type", "application/json");
455
482
  }
@@ -605,6 +632,9 @@ var ScaleMuleClient = class {
605
632
  if (this.sessionToken) {
606
633
  headers.set("Authorization", `Bearer ${this.sessionToken}`);
607
634
  }
635
+ if (this.workspaceId) {
636
+ headers.set("x-sm-workspace-id", this.workspaceId);
637
+ }
608
638
  let lastError = null;
609
639
  for (let attempt = 0; attempt <= maxRetries; attempt++) {
610
640
  try {
@@ -742,6 +772,9 @@ var ScaleMuleClient = class {
742
772
  if (this.sessionToken) {
743
773
  xhr.setRequestHeader("Authorization", `Bearer ${this.sessionToken}`);
744
774
  }
775
+ if (this.workspaceId) {
776
+ xhr.setRequestHeader("x-sm-workspace-id", this.workspaceId);
777
+ }
745
778
  xhr.send(formData);
746
779
  });
747
780
  }
package/dist/index.mjs CHANGED
@@ -20,6 +20,7 @@ var GATEWAY_URLS = {
20
20
  };
21
21
  var SESSION_STORAGE_KEY = "scalemule_session";
22
22
  var USER_ID_STORAGE_KEY = "scalemule_user_id";
23
+ var WORKSPACE_STORAGE_KEY = "scalemule_workspace_id";
23
24
  var RETRYABLE_STATUS_CODES = /* @__PURE__ */ new Set([408, 429, 500, 502, 503, 504]);
24
25
  function sleep(ms) {
25
26
  return new Promise((resolve) => setTimeout(resolve, ms));
@@ -278,6 +279,7 @@ var ScaleMuleClient = class {
278
279
  this.offlineQueue = null;
279
280
  this.sessionGate = null;
280
281
  this.resolveSessionGate = null;
282
+ this.workspaceId = null;
281
283
  this.apiKey = config.apiKey;
282
284
  this.applicationId = config.applicationId || null;
283
285
  this.gatewayUrl = resolveGatewayUrl(config);
@@ -348,6 +350,24 @@ var ScaleMuleClient = class {
348
350
  isRateLimited() {
349
351
  return this.rateLimitQueue?.isRateLimited || false;
350
352
  }
353
+ /**
354
+ * Set the active workspace context. All subsequent requests will include
355
+ * x-sm-workspace-id header. Pass null to clear.
356
+ */
357
+ setWorkspaceContext(id) {
358
+ this.workspaceId = id;
359
+ if (id) {
360
+ this.storage.setItem(WORKSPACE_STORAGE_KEY, id);
361
+ } else {
362
+ this.storage.removeItem(WORKSPACE_STORAGE_KEY);
363
+ }
364
+ }
365
+ /**
366
+ * Get the current workspace ID
367
+ */
368
+ getWorkspaceId() {
369
+ return this.workspaceId;
370
+ }
351
371
  /**
352
372
  * Get the gateway URL
353
373
  */
@@ -390,6 +410,8 @@ var ScaleMuleClient = class {
390
410
  const userId = await this.storage.getItem(USER_ID_STORAGE_KEY);
391
411
  if (token) this.sessionToken = token;
392
412
  if (userId) this.userId = userId;
413
+ const wsId = await this.storage.getItem(WORKSPACE_STORAGE_KEY);
414
+ if (wsId) this.workspaceId = wsId;
393
415
  if (token) {
394
416
  this.resolveSessionPending();
395
417
  }
@@ -415,8 +437,10 @@ var ScaleMuleClient = class {
415
437
  async clearSession() {
416
438
  this.sessionToken = null;
417
439
  this.userId = null;
440
+ this.workspaceId = null;
418
441
  await this.storage.removeItem(SESSION_STORAGE_KEY);
419
442
  await this.storage.removeItem(USER_ID_STORAGE_KEY);
443
+ await this.storage.removeItem(WORKSPACE_STORAGE_KEY);
420
444
  if (this.debug) {
421
445
  console.log("[ScaleMule] Session cleared");
422
446
  }
@@ -448,6 +472,9 @@ var ScaleMuleClient = class {
448
472
  if (!options?.skipAuth && this.sessionToken) {
449
473
  headers.set("Authorization", `Bearer ${this.sessionToken}`);
450
474
  }
475
+ if (this.workspaceId) {
476
+ headers.set("x-sm-workspace-id", this.workspaceId);
477
+ }
451
478
  if (!headers.has("Content-Type") && options?.body && typeof options.body === "string") {
452
479
  headers.set("Content-Type", "application/json");
453
480
  }
@@ -603,6 +630,9 @@ var ScaleMuleClient = class {
603
630
  if (this.sessionToken) {
604
631
  headers.set("Authorization", `Bearer ${this.sessionToken}`);
605
632
  }
633
+ if (this.workspaceId) {
634
+ headers.set("x-sm-workspace-id", this.workspaceId);
635
+ }
606
636
  let lastError = null;
607
637
  for (let attempt = 0; attempt <= maxRetries; attempt++) {
608
638
  try {
@@ -740,6 +770,9 @@ var ScaleMuleClient = class {
740
770
  if (this.sessionToken) {
741
771
  xhr.setRequestHeader("Authorization", `Bearer ${this.sessionToken}`);
742
772
  }
773
+ if (this.workspaceId) {
774
+ xhr.setRequestHeader("x-sm-workspace-id", this.workspaceId);
775
+ }
743
776
  xhr.send(formData);
744
777
  });
745
778
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scalemule/nextjs",
3
- "version": "0.0.8",
3
+ "version": "0.0.9",
4
4
  "description": "ScaleMule SDK for Next.js applications - authentication, storage, and user management",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",