@dotbots-boutique/auth-sdk 1.0.14 → 1.0.16

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,22 @@ 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
+ await this.getUser();
301
+ this.emit('userChanged');
302
+ });
287
303
  }
288
304
  async getUser() {
289
305
  this.assertInitialized();
@@ -456,7 +472,7 @@ class DotBotsAuth {
456
472
  }
457
473
  }
458
474
  }
459
- DotBotsAuth.SDK_VERSION = '1.0.14';
475
+ DotBotsAuth.SDK_VERSION = '1.0.16';
460
476
 
461
477
  exports.DotBotsAuth = DotBotsAuth;
462
478
  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,22 @@ 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
+ await this.getUser();
299
+ this.emit('userChanged');
300
+ });
285
301
  }
286
302
  async getUser() {
287
303
  this.assertInitialized();
@@ -454,6 +470,6 @@ class DotBotsAuth {
454
470
  }
455
471
  }
456
472
  }
457
- DotBotsAuth.SDK_VERSION = '1.0.14';
473
+ DotBotsAuth.SDK_VERSION = '1.0.16';
458
474
 
459
475
  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.16";
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,22 @@ 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
+ await this.getUser();
299
+ this.emit('userChanged');
300
+ });
285
301
  }
286
302
  async getUser() {
287
303
  this.assertInitialized();
@@ -454,6 +470,6 @@ class DotBotsAuth {
454
470
  }
455
471
  }
456
472
  }
457
- DotBotsAuth.SDK_VERSION = '1.0.14';
473
+ DotBotsAuth.SDK_VERSION = '1.0.16';
458
474
 
459
475
  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.16",
4
4
  "description": "Authentication SDK for DotBots marketplace apps",
5
5
  "license": "MIT",
6
6
  "type": "module",