@dotbots-boutique/auth-sdk 1.0.14 → 1.0.15

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/cjs/index.js CHANGED
@@ -261,9 +261,9 @@ class DotBotsAuth {
261
261
  this.config = config;
262
262
  this.environment = this.detectEnvironment();
263
263
  console.warn(`[DotBotsAuth] SDK v${DotBotsAuth.SDK_VERSION} — env: ${this.environment}, appId: ${config.appId}`);
264
- const marketplaceOrigin = config.marketplaceOrigin ?? 'https://dotbots.boutique';
264
+ this.marketplaceOrigin = config.marketplaceOrigin ?? 'https://dotbots.boutique';
265
265
  this.tokenManager = new TokenManager(config, this.environment, () => this.emit('tokenRefreshed'), () => this.emit('sessionExpired'), () => this.proxyConfigManager.getBaseUrl());
266
- this.postMessageHandler = new PostMessageHandler(marketplaceOrigin);
266
+ this.postMessageHandler = new PostMessageHandler(this.marketplaceOrigin);
267
267
  this.proxyConfigManager = new ProxyConfigManager(config.apiUrl, config.appId, this.environment);
268
268
  }
269
269
  async initialize() {
@@ -284,6 +284,21 @@ class DotBotsAuth {
284
284
  await this.initializeStandalone();
285
285
  }
286
286
  this.initialized = true;
287
+ // Listen for user switch (new auth code from marketplace after init)
288
+ window.addEventListener('message', async (event) => {
289
+ if (event.origin !== this.marketplaceOrigin)
290
+ return;
291
+ if (event.data?.type !== 'DOTBOTS_AUTH_CODE')
292
+ return;
293
+ if (!this.initialized)
294
+ return;
295
+ console.warn(`[DotBotsAuth] Received new DOTBOTS_AUTH_CODE — user switch`);
296
+ this.initializePromise = null;
297
+ this.cachedUser = null;
298
+ this.tokenManager.clear();
299
+ await this.tokenManager.exchangeCode(event.data.code);
300
+ this.emit('userChanged');
301
+ });
287
302
  }
288
303
  async getUser() {
289
304
  this.assertInitialized();
@@ -456,7 +471,7 @@ class DotBotsAuth {
456
471
  }
457
472
  }
458
473
  }
459
- DotBotsAuth.SDK_VERSION = '1.0.14';
474
+ DotBotsAuth.SDK_VERSION = '1.0.15';
460
475
 
461
476
  exports.DotBotsAuth = DotBotsAuth;
462
477
  exports.DotBotsAuthError = DotBotsAuthError;
package/dist/esm/index.js CHANGED
@@ -259,9 +259,9 @@ class DotBotsAuth {
259
259
  this.config = config;
260
260
  this.environment = this.detectEnvironment();
261
261
  console.warn(`[DotBotsAuth] SDK v${DotBotsAuth.SDK_VERSION} — env: ${this.environment}, appId: ${config.appId}`);
262
- const marketplaceOrigin = config.marketplaceOrigin ?? 'https://dotbots.boutique';
262
+ this.marketplaceOrigin = config.marketplaceOrigin ?? 'https://dotbots.boutique';
263
263
  this.tokenManager = new TokenManager(config, this.environment, () => this.emit('tokenRefreshed'), () => this.emit('sessionExpired'), () => this.proxyConfigManager.getBaseUrl());
264
- this.postMessageHandler = new PostMessageHandler(marketplaceOrigin);
264
+ this.postMessageHandler = new PostMessageHandler(this.marketplaceOrigin);
265
265
  this.proxyConfigManager = new ProxyConfigManager(config.apiUrl, config.appId, this.environment);
266
266
  }
267
267
  async initialize() {
@@ -282,6 +282,21 @@ class DotBotsAuth {
282
282
  await this.initializeStandalone();
283
283
  }
284
284
  this.initialized = true;
285
+ // Listen for user switch (new auth code from marketplace after init)
286
+ window.addEventListener('message', async (event) => {
287
+ if (event.origin !== this.marketplaceOrigin)
288
+ return;
289
+ if (event.data?.type !== 'DOTBOTS_AUTH_CODE')
290
+ return;
291
+ if (!this.initialized)
292
+ return;
293
+ console.warn(`[DotBotsAuth] Received new DOTBOTS_AUTH_CODE — user switch`);
294
+ this.initializePromise = null;
295
+ this.cachedUser = null;
296
+ this.tokenManager.clear();
297
+ await this.tokenManager.exchangeCode(event.data.code);
298
+ this.emit('userChanged');
299
+ });
285
300
  }
286
301
  async getUser() {
287
302
  this.assertInitialized();
@@ -454,6 +469,6 @@ class DotBotsAuth {
454
469
  }
455
470
  }
456
471
  }
457
- DotBotsAuth.SDK_VERSION = '1.0.14';
472
+ DotBotsAuth.SDK_VERSION = '1.0.15';
458
473
 
459
474
  export { DotBotsAuth, DotBotsAuthError };
@@ -5,11 +5,12 @@ export declare class DotBotsAuth {
5
5
  private readonly tokenManager;
6
6
  private readonly postMessageHandler;
7
7
  private readonly proxyConfigManager;
8
+ private readonly marketplaceOrigin;
8
9
  private readonly listeners;
9
10
  private cachedUser;
10
11
  private initialized;
11
12
  private initializePromise;
12
- static readonly SDK_VERSION = "1.0.14";
13
+ static readonly SDK_VERSION = "1.0.15";
13
14
  constructor(config: DotBotsConfig);
14
15
  initialize(): Promise<void>;
15
16
  private _doInitialize;
@@ -259,9 +259,9 @@ class DotBotsAuth {
259
259
  this.config = config;
260
260
  this.environment = this.detectEnvironment();
261
261
  console.warn(`[DotBotsAuth] SDK v${DotBotsAuth.SDK_VERSION} — env: ${this.environment}, appId: ${config.appId}`);
262
- const marketplaceOrigin = config.marketplaceOrigin ?? 'https://dotbots.boutique';
262
+ this.marketplaceOrigin = config.marketplaceOrigin ?? 'https://dotbots.boutique';
263
263
  this.tokenManager = new TokenManager(config, this.environment, () => this.emit('tokenRefreshed'), () => this.emit('sessionExpired'), () => this.proxyConfigManager.getBaseUrl());
264
- this.postMessageHandler = new PostMessageHandler(marketplaceOrigin);
264
+ this.postMessageHandler = new PostMessageHandler(this.marketplaceOrigin);
265
265
  this.proxyConfigManager = new ProxyConfigManager(config.apiUrl, config.appId, this.environment);
266
266
  }
267
267
  async initialize() {
@@ -282,6 +282,21 @@ class DotBotsAuth {
282
282
  await this.initializeStandalone();
283
283
  }
284
284
  this.initialized = true;
285
+ // Listen for user switch (new auth code from marketplace after init)
286
+ window.addEventListener('message', async (event) => {
287
+ if (event.origin !== this.marketplaceOrigin)
288
+ return;
289
+ if (event.data?.type !== 'DOTBOTS_AUTH_CODE')
290
+ return;
291
+ if (!this.initialized)
292
+ return;
293
+ console.warn(`[DotBotsAuth] Received new DOTBOTS_AUTH_CODE — user switch`);
294
+ this.initializePromise = null;
295
+ this.cachedUser = null;
296
+ this.tokenManager.clear();
297
+ await this.tokenManager.exchangeCode(event.data.code);
298
+ this.emit('userChanged');
299
+ });
285
300
  }
286
301
  async getUser() {
287
302
  this.assertInitialized();
@@ -454,6 +469,6 @@ class DotBotsAuth {
454
469
  }
455
470
  }
456
471
  }
457
- DotBotsAuth.SDK_VERSION = '1.0.14';
472
+ DotBotsAuth.SDK_VERSION = '1.0.15';
458
473
 
459
474
  export { DotBotsAuth, DotBotsAuthError };
@@ -40,7 +40,7 @@ export interface DotBotsProxyConfig {
40
40
  cacheTtl: number;
41
41
  }
42
42
  export type ProxyFeature = 'cache' | 'localdb' | 'webhooks' | 'ratelimit';
43
- export type DotBotsAuthEvent = 'tokenRefreshed' | 'loggedOut' | 'sessionExpired' | 'userLoaded' | 'charged';
43
+ export type DotBotsAuthEvent = 'tokenRefreshed' | 'loggedOut' | 'sessionExpired' | 'userLoaded' | 'charged' | 'userChanged';
44
44
  export type DotBotsAuthErrorCode = 'IFRAME_TIMEOUT' | 'CODE_EXPIRED' | 'UNAUTHORIZED' | 'REFRESH_FAILED' | 'NETWORK_ERROR' | 'NOT_INITIALIZED' | 'PROXY_UNAVAILABLE' | 'PAYMENT_FAILED';
45
45
  export interface TokenPair {
46
46
  accessToken: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dotbots-boutique/auth-sdk",
3
- "version": "1.0.14",
3
+ "version": "1.0.15",
4
4
  "description": "Authentication SDK for DotBots marketplace apps",
5
5
  "license": "MIT",
6
6
  "type": "module",