@dotbots-boutique/auth-sdk 1.0.20 → 1.0.22

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
@@ -281,15 +281,16 @@ class DotBotsAuth {
281
281
  return this.initializePromise;
282
282
  }
283
283
  async _doInitialize() {
284
+ // Redirect to marketplace if opened directly (not in iframe)
285
+ if (!this.postMessageHandler.isInIframe()) {
286
+ const mode = this.environment === 'test' ? '?mode=test' : '';
287
+ window.location.href = `https://dotbots.boutique/boutique/${this.config.appId}/open${mode}`;
288
+ return;
289
+ }
284
290
  // Step 1 — Fetch proxy config
285
291
  await this.proxyConfigManager.fetchConfig();
286
292
  // Step 2 — Authenticate
287
- if (this.postMessageHandler.isInIframe()) {
288
- await this.initializeIframe();
289
- }
290
- else {
291
- await this.initializeStandalone();
292
- }
293
+ await this.initializeIframe();
293
294
  this.initialized = true;
294
295
  // Step 3 — Forward console output to marketplace when in iframe
295
296
  if (this.postMessageHandler.isInIframe()) {
@@ -498,13 +499,7 @@ class DotBotsAuth {
498
499
  await this.tokenManager.revoke();
499
500
  this.cachedUser = null;
500
501
  this.emit('loggedOut');
501
- if (this.postMessageHandler.isInIframe()) {
502
- this.postMessageHandler.sendLogout();
503
- }
504
- else {
505
- const redirectUri = encodeURIComponent(window.location.origin);
506
- window.location.href = `${this.config.apiUrl}/api/auth/logout?redirectUri=${redirectUri}`;
507
- }
502
+ this.postMessageHandler.sendLogout();
508
503
  }
509
504
  destroy() {
510
505
  console.log = this._console.log;
@@ -544,22 +539,6 @@ class DotBotsAuth {
544
539
  console.warn(`[DotBotsAuth] Received auth code from iframe: ${code.substring(0, 2)}**`);
545
540
  await this.tokenManager.exchangeCode(code);
546
541
  }
547
- async initializeStandalone() {
548
- const url = new URL(window.location.href);
549
- const code = url.searchParams.get('code');
550
- if (code) {
551
- console.warn(`[DotBotsAuth] Received auth code from URL: ${code.substring(0, 2)}**`);
552
- // Remove code from URL immediately
553
- url.searchParams.delete('code');
554
- window.history.replaceState({}, '', url.toString());
555
- await this.tokenManager.exchangeCode(code);
556
- }
557
- else if (!this.tokenManager.isAuthenticated()) {
558
- // Redirect to auth
559
- const redirectUri = encodeURIComponent(window.location.href);
560
- window.location.href = `${this.config.apiUrl}/api/auth/authorize?appId=${this.config.appId}&redirectUri=${redirectUri}`;
561
- }
562
- }
563
542
  interceptConsole() {
564
543
  const appId = this.config.appId;
565
544
  const forward = (level, original) => {
@@ -588,6 +567,27 @@ class DotBotsAuth {
588
567
  console.info = forward('info', this._console.info);
589
568
  console.warn = forward('warn', this._console.warn);
590
569
  console.error = forward('error', this._console.error);
570
+ window.addEventListener('error', (event) => {
571
+ window.parent.postMessage({
572
+ type: 'DOTBOTS_LOG',
573
+ level: 'error',
574
+ message: `Uncaught error: ${event.message} (${event.filename}:${event.lineno}:${event.colno})`,
575
+ timestamp: new Date().toISOString(),
576
+ appId,
577
+ }, '*');
578
+ });
579
+ window.addEventListener('unhandledrejection', (event) => {
580
+ const reason = event.reason instanceof Error
581
+ ? `${event.reason.message}\n${event.reason.stack ?? ''}`
582
+ : String(event.reason);
583
+ window.parent.postMessage({
584
+ type: 'DOTBOTS_LOG',
585
+ level: 'error',
586
+ message: `Unhandled promise rejection: ${reason}`,
587
+ timestamp: new Date().toISOString(),
588
+ appId,
589
+ }, '*');
590
+ });
591
591
  }
592
592
  async buildRequest(url, options) {
593
593
  const headers = new Headers(options?.headers);
@@ -618,7 +618,7 @@ class DotBotsAuth {
618
618
  }
619
619
  }
620
620
  }
621
- DotBotsAuth.SDK_VERSION = '1.0.20';
621
+ DotBotsAuth.SDK_VERSION = '1.0.22';
622
622
 
623
623
  exports.DotBotsAuth = DotBotsAuth;
624
624
  exports.DotBotsAuthError = DotBotsAuthError;
package/dist/esm/index.js CHANGED
@@ -279,15 +279,16 @@ class DotBotsAuth {
279
279
  return this.initializePromise;
280
280
  }
281
281
  async _doInitialize() {
282
+ // Redirect to marketplace if opened directly (not in iframe)
283
+ if (!this.postMessageHandler.isInIframe()) {
284
+ const mode = this.environment === 'test' ? '?mode=test' : '';
285
+ window.location.href = `https://dotbots.boutique/boutique/${this.config.appId}/open${mode}`;
286
+ return;
287
+ }
282
288
  // Step 1 — Fetch proxy config
283
289
  await this.proxyConfigManager.fetchConfig();
284
290
  // Step 2 — Authenticate
285
- if (this.postMessageHandler.isInIframe()) {
286
- await this.initializeIframe();
287
- }
288
- else {
289
- await this.initializeStandalone();
290
- }
291
+ await this.initializeIframe();
291
292
  this.initialized = true;
292
293
  // Step 3 — Forward console output to marketplace when in iframe
293
294
  if (this.postMessageHandler.isInIframe()) {
@@ -496,13 +497,7 @@ class DotBotsAuth {
496
497
  await this.tokenManager.revoke();
497
498
  this.cachedUser = null;
498
499
  this.emit('loggedOut');
499
- if (this.postMessageHandler.isInIframe()) {
500
- this.postMessageHandler.sendLogout();
501
- }
502
- else {
503
- const redirectUri = encodeURIComponent(window.location.origin);
504
- window.location.href = `${this.config.apiUrl}/api/auth/logout?redirectUri=${redirectUri}`;
505
- }
500
+ this.postMessageHandler.sendLogout();
506
501
  }
507
502
  destroy() {
508
503
  console.log = this._console.log;
@@ -542,22 +537,6 @@ class DotBotsAuth {
542
537
  console.warn(`[DotBotsAuth] Received auth code from iframe: ${code.substring(0, 2)}**`);
543
538
  await this.tokenManager.exchangeCode(code);
544
539
  }
545
- async initializeStandalone() {
546
- const url = new URL(window.location.href);
547
- const code = url.searchParams.get('code');
548
- if (code) {
549
- console.warn(`[DotBotsAuth] Received auth code from URL: ${code.substring(0, 2)}**`);
550
- // Remove code from URL immediately
551
- url.searchParams.delete('code');
552
- window.history.replaceState({}, '', url.toString());
553
- await this.tokenManager.exchangeCode(code);
554
- }
555
- else if (!this.tokenManager.isAuthenticated()) {
556
- // Redirect to auth
557
- const redirectUri = encodeURIComponent(window.location.href);
558
- window.location.href = `${this.config.apiUrl}/api/auth/authorize?appId=${this.config.appId}&redirectUri=${redirectUri}`;
559
- }
560
- }
561
540
  interceptConsole() {
562
541
  const appId = this.config.appId;
563
542
  const forward = (level, original) => {
@@ -586,6 +565,27 @@ class DotBotsAuth {
586
565
  console.info = forward('info', this._console.info);
587
566
  console.warn = forward('warn', this._console.warn);
588
567
  console.error = forward('error', this._console.error);
568
+ window.addEventListener('error', (event) => {
569
+ window.parent.postMessage({
570
+ type: 'DOTBOTS_LOG',
571
+ level: 'error',
572
+ message: `Uncaught error: ${event.message} (${event.filename}:${event.lineno}:${event.colno})`,
573
+ timestamp: new Date().toISOString(),
574
+ appId,
575
+ }, '*');
576
+ });
577
+ window.addEventListener('unhandledrejection', (event) => {
578
+ const reason = event.reason instanceof Error
579
+ ? `${event.reason.message}\n${event.reason.stack ?? ''}`
580
+ : String(event.reason);
581
+ window.parent.postMessage({
582
+ type: 'DOTBOTS_LOG',
583
+ level: 'error',
584
+ message: `Unhandled promise rejection: ${reason}`,
585
+ timestamp: new Date().toISOString(),
586
+ appId,
587
+ }, '*');
588
+ });
589
589
  }
590
590
  async buildRequest(url, options) {
591
591
  const headers = new Headers(options?.headers);
@@ -616,6 +616,6 @@ class DotBotsAuth {
616
616
  }
617
617
  }
618
618
  }
619
- DotBotsAuth.SDK_VERSION = '1.0.20';
619
+ DotBotsAuth.SDK_VERSION = '1.0.22';
620
620
 
621
621
  export { DotBotsAuth, DotBotsAuthError };
@@ -11,7 +11,7 @@ export declare class DotBotsAuth {
11
11
  private initialized;
12
12
  private initializePromise;
13
13
  private readonly _console;
14
- static readonly SDK_VERSION = "1.0.20";
14
+ static readonly SDK_VERSION = "1.0.22";
15
15
  constructor(config: DotBotsConfig);
16
16
  initialize(): Promise<void>;
17
17
  private _doInitialize;
@@ -36,7 +36,6 @@ export declare class DotBotsAuth {
36
36
  getProxyConfig(): DotBotsProxyConfig | null;
37
37
  private detectEnvironment;
38
38
  private initializeIframe;
39
- private initializeStandalone;
40
39
  private interceptConsole;
41
40
  private buildRequest;
42
41
  private assertInitialized;
@@ -279,15 +279,16 @@ class DotBotsAuth {
279
279
  return this.initializePromise;
280
280
  }
281
281
  async _doInitialize() {
282
+ // Redirect to marketplace if opened directly (not in iframe)
283
+ if (!this.postMessageHandler.isInIframe()) {
284
+ const mode = this.environment === 'test' ? '?mode=test' : '';
285
+ window.location.href = `https://dotbots.boutique/boutique/${this.config.appId}/open${mode}`;
286
+ return;
287
+ }
282
288
  // Step 1 — Fetch proxy config
283
289
  await this.proxyConfigManager.fetchConfig();
284
290
  // Step 2 — Authenticate
285
- if (this.postMessageHandler.isInIframe()) {
286
- await this.initializeIframe();
287
- }
288
- else {
289
- await this.initializeStandalone();
290
- }
291
+ await this.initializeIframe();
291
292
  this.initialized = true;
292
293
  // Step 3 — Forward console output to marketplace when in iframe
293
294
  if (this.postMessageHandler.isInIframe()) {
@@ -496,13 +497,7 @@ class DotBotsAuth {
496
497
  await this.tokenManager.revoke();
497
498
  this.cachedUser = null;
498
499
  this.emit('loggedOut');
499
- if (this.postMessageHandler.isInIframe()) {
500
- this.postMessageHandler.sendLogout();
501
- }
502
- else {
503
- const redirectUri = encodeURIComponent(window.location.origin);
504
- window.location.href = `${this.config.apiUrl}/api/auth/logout?redirectUri=${redirectUri}`;
505
- }
500
+ this.postMessageHandler.sendLogout();
506
501
  }
507
502
  destroy() {
508
503
  console.log = this._console.log;
@@ -542,22 +537,6 @@ class DotBotsAuth {
542
537
  console.warn(`[DotBotsAuth] Received auth code from iframe: ${code.substring(0, 2)}**`);
543
538
  await this.tokenManager.exchangeCode(code);
544
539
  }
545
- async initializeStandalone() {
546
- const url = new URL(window.location.href);
547
- const code = url.searchParams.get('code');
548
- if (code) {
549
- console.warn(`[DotBotsAuth] Received auth code from URL: ${code.substring(0, 2)}**`);
550
- // Remove code from URL immediately
551
- url.searchParams.delete('code');
552
- window.history.replaceState({}, '', url.toString());
553
- await this.tokenManager.exchangeCode(code);
554
- }
555
- else if (!this.tokenManager.isAuthenticated()) {
556
- // Redirect to auth
557
- const redirectUri = encodeURIComponent(window.location.href);
558
- window.location.href = `${this.config.apiUrl}/api/auth/authorize?appId=${this.config.appId}&redirectUri=${redirectUri}`;
559
- }
560
- }
561
540
  interceptConsole() {
562
541
  const appId = this.config.appId;
563
542
  const forward = (level, original) => {
@@ -586,6 +565,27 @@ class DotBotsAuth {
586
565
  console.info = forward('info', this._console.info);
587
566
  console.warn = forward('warn', this._console.warn);
588
567
  console.error = forward('error', this._console.error);
568
+ window.addEventListener('error', (event) => {
569
+ window.parent.postMessage({
570
+ type: 'DOTBOTS_LOG',
571
+ level: 'error',
572
+ message: `Uncaught error: ${event.message} (${event.filename}:${event.lineno}:${event.colno})`,
573
+ timestamp: new Date().toISOString(),
574
+ appId,
575
+ }, '*');
576
+ });
577
+ window.addEventListener('unhandledrejection', (event) => {
578
+ const reason = event.reason instanceof Error
579
+ ? `${event.reason.message}\n${event.reason.stack ?? ''}`
580
+ : String(event.reason);
581
+ window.parent.postMessage({
582
+ type: 'DOTBOTS_LOG',
583
+ level: 'error',
584
+ message: `Unhandled promise rejection: ${reason}`,
585
+ timestamp: new Date().toISOString(),
586
+ appId,
587
+ }, '*');
588
+ });
589
589
  }
590
590
  async buildRequest(url, options) {
591
591
  const headers = new Headers(options?.headers);
@@ -616,6 +616,6 @@ class DotBotsAuth {
616
616
  }
617
617
  }
618
618
  }
619
- DotBotsAuth.SDK_VERSION = '1.0.20';
619
+ DotBotsAuth.SDK_VERSION = '1.0.22';
620
620
 
621
621
  export { DotBotsAuth, DotBotsAuthError };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dotbots-boutique/auth-sdk",
3
- "version": "1.0.20",
3
+ "version": "1.0.22",
4
4
  "description": "Authentication SDK for DotBots marketplace apps",
5
5
  "license": "MIT",
6
6
  "type": "module",