@dotbots-boutique/auth-sdk 1.0.13 → 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 +26 -3
- package/dist/esm/index.js +26 -3
- package/dist/types/DotBotsAuth.d.ts +4 -1
- package/dist/types/index.js +26 -3
- package/dist/types/types.d.ts +1 -1
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -257,15 +257,23 @@ class DotBotsAuth {
|
|
|
257
257
|
this.listeners = new Map();
|
|
258
258
|
this.cachedUser = null;
|
|
259
259
|
this.initialized = false;
|
|
260
|
+
this.initializePromise = null;
|
|
260
261
|
this.config = config;
|
|
261
262
|
this.environment = this.detectEnvironment();
|
|
262
263
|
console.warn(`[DotBotsAuth] SDK v${DotBotsAuth.SDK_VERSION} — env: ${this.environment}, appId: ${config.appId}`);
|
|
263
|
-
|
|
264
|
+
this.marketplaceOrigin = config.marketplaceOrigin ?? 'https://dotbots.boutique';
|
|
264
265
|
this.tokenManager = new TokenManager(config, this.environment, () => this.emit('tokenRefreshed'), () => this.emit('sessionExpired'), () => this.proxyConfigManager.getBaseUrl());
|
|
265
|
-
this.postMessageHandler = new PostMessageHandler(marketplaceOrigin);
|
|
266
|
+
this.postMessageHandler = new PostMessageHandler(this.marketplaceOrigin);
|
|
266
267
|
this.proxyConfigManager = new ProxyConfigManager(config.apiUrl, config.appId, this.environment);
|
|
267
268
|
}
|
|
268
269
|
async initialize() {
|
|
270
|
+
// Idempotency guard — safe to call multiple times (React StrictMode)
|
|
271
|
+
if (this.initializePromise)
|
|
272
|
+
return this.initializePromise;
|
|
273
|
+
this.initializePromise = this._doInitialize();
|
|
274
|
+
return this.initializePromise;
|
|
275
|
+
}
|
|
276
|
+
async _doInitialize() {
|
|
269
277
|
// Step 1 — Fetch proxy config
|
|
270
278
|
await this.proxyConfigManager.fetchConfig();
|
|
271
279
|
// Step 2 — Authenticate
|
|
@@ -276,6 +284,21 @@ class DotBotsAuth {
|
|
|
276
284
|
await this.initializeStandalone();
|
|
277
285
|
}
|
|
278
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
|
+
});
|
|
279
302
|
}
|
|
280
303
|
async getUser() {
|
|
281
304
|
this.assertInitialized();
|
|
@@ -448,7 +471,7 @@ class DotBotsAuth {
|
|
|
448
471
|
}
|
|
449
472
|
}
|
|
450
473
|
}
|
|
451
|
-
DotBotsAuth.SDK_VERSION = '1.0.
|
|
474
|
+
DotBotsAuth.SDK_VERSION = '1.0.15';
|
|
452
475
|
|
|
453
476
|
exports.DotBotsAuth = DotBotsAuth;
|
|
454
477
|
exports.DotBotsAuthError = DotBotsAuthError;
|
package/dist/esm/index.js
CHANGED
|
@@ -255,15 +255,23 @@ class DotBotsAuth {
|
|
|
255
255
|
this.listeners = new Map();
|
|
256
256
|
this.cachedUser = null;
|
|
257
257
|
this.initialized = false;
|
|
258
|
+
this.initializePromise = null;
|
|
258
259
|
this.config = config;
|
|
259
260
|
this.environment = this.detectEnvironment();
|
|
260
261
|
console.warn(`[DotBotsAuth] SDK v${DotBotsAuth.SDK_VERSION} — env: ${this.environment}, appId: ${config.appId}`);
|
|
261
|
-
|
|
262
|
+
this.marketplaceOrigin = config.marketplaceOrigin ?? 'https://dotbots.boutique';
|
|
262
263
|
this.tokenManager = new TokenManager(config, this.environment, () => this.emit('tokenRefreshed'), () => this.emit('sessionExpired'), () => this.proxyConfigManager.getBaseUrl());
|
|
263
|
-
this.postMessageHandler = new PostMessageHandler(marketplaceOrigin);
|
|
264
|
+
this.postMessageHandler = new PostMessageHandler(this.marketplaceOrigin);
|
|
264
265
|
this.proxyConfigManager = new ProxyConfigManager(config.apiUrl, config.appId, this.environment);
|
|
265
266
|
}
|
|
266
267
|
async initialize() {
|
|
268
|
+
// Idempotency guard — safe to call multiple times (React StrictMode)
|
|
269
|
+
if (this.initializePromise)
|
|
270
|
+
return this.initializePromise;
|
|
271
|
+
this.initializePromise = this._doInitialize();
|
|
272
|
+
return this.initializePromise;
|
|
273
|
+
}
|
|
274
|
+
async _doInitialize() {
|
|
267
275
|
// Step 1 — Fetch proxy config
|
|
268
276
|
await this.proxyConfigManager.fetchConfig();
|
|
269
277
|
// Step 2 — Authenticate
|
|
@@ -274,6 +282,21 @@ class DotBotsAuth {
|
|
|
274
282
|
await this.initializeStandalone();
|
|
275
283
|
}
|
|
276
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
|
+
});
|
|
277
300
|
}
|
|
278
301
|
async getUser() {
|
|
279
302
|
this.assertInitialized();
|
|
@@ -446,6 +469,6 @@ class DotBotsAuth {
|
|
|
446
469
|
}
|
|
447
470
|
}
|
|
448
471
|
}
|
|
449
|
-
DotBotsAuth.SDK_VERSION = '1.0.
|
|
472
|
+
DotBotsAuth.SDK_VERSION = '1.0.15';
|
|
450
473
|
|
|
451
474
|
export { DotBotsAuth, DotBotsAuthError };
|
|
@@ -5,12 +5,15 @@ 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;
|
|
13
|
+
static readonly SDK_VERSION = "1.0.15";
|
|
12
14
|
constructor(config: DotBotsConfig);
|
|
13
15
|
initialize(): Promise<void>;
|
|
16
|
+
private _doInitialize;
|
|
14
17
|
getUser(): Promise<DotBotsUser>;
|
|
15
18
|
can(permission: string): boolean;
|
|
16
19
|
canAll(permissions: string[]): boolean;
|
package/dist/types/index.js
CHANGED
|
@@ -255,15 +255,23 @@ class DotBotsAuth {
|
|
|
255
255
|
this.listeners = new Map();
|
|
256
256
|
this.cachedUser = null;
|
|
257
257
|
this.initialized = false;
|
|
258
|
+
this.initializePromise = null;
|
|
258
259
|
this.config = config;
|
|
259
260
|
this.environment = this.detectEnvironment();
|
|
260
261
|
console.warn(`[DotBotsAuth] SDK v${DotBotsAuth.SDK_VERSION} — env: ${this.environment}, appId: ${config.appId}`);
|
|
261
|
-
|
|
262
|
+
this.marketplaceOrigin = config.marketplaceOrigin ?? 'https://dotbots.boutique';
|
|
262
263
|
this.tokenManager = new TokenManager(config, this.environment, () => this.emit('tokenRefreshed'), () => this.emit('sessionExpired'), () => this.proxyConfigManager.getBaseUrl());
|
|
263
|
-
this.postMessageHandler = new PostMessageHandler(marketplaceOrigin);
|
|
264
|
+
this.postMessageHandler = new PostMessageHandler(this.marketplaceOrigin);
|
|
264
265
|
this.proxyConfigManager = new ProxyConfigManager(config.apiUrl, config.appId, this.environment);
|
|
265
266
|
}
|
|
266
267
|
async initialize() {
|
|
268
|
+
// Idempotency guard — safe to call multiple times (React StrictMode)
|
|
269
|
+
if (this.initializePromise)
|
|
270
|
+
return this.initializePromise;
|
|
271
|
+
this.initializePromise = this._doInitialize();
|
|
272
|
+
return this.initializePromise;
|
|
273
|
+
}
|
|
274
|
+
async _doInitialize() {
|
|
267
275
|
// Step 1 — Fetch proxy config
|
|
268
276
|
await this.proxyConfigManager.fetchConfig();
|
|
269
277
|
// Step 2 — Authenticate
|
|
@@ -274,6 +282,21 @@ class DotBotsAuth {
|
|
|
274
282
|
await this.initializeStandalone();
|
|
275
283
|
}
|
|
276
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
|
+
});
|
|
277
300
|
}
|
|
278
301
|
async getUser() {
|
|
279
302
|
this.assertInitialized();
|
|
@@ -446,6 +469,6 @@ class DotBotsAuth {
|
|
|
446
469
|
}
|
|
447
470
|
}
|
|
448
471
|
}
|
|
449
|
-
DotBotsAuth.SDK_VERSION = '1.0.
|
|
472
|
+
DotBotsAuth.SDK_VERSION = '1.0.15';
|
|
450
473
|
|
|
451
474
|
export { DotBotsAuth, DotBotsAuthError };
|
package/dist/types/types.d.ts
CHANGED
|
@@ -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;
|