@oxyhq/core 2.1.0 → 2.1.2

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.
@@ -21,6 +21,7 @@
21
21
  * const session = await auth.signInWithPopup();
22
22
  * ```
23
23
  */
24
+ import { logger } from './utils/loggerUtils.js';
24
25
  export class CrossDomainAuth {
25
26
  constructor(oxyServices) {
26
27
  this.oxyServices = oxyServices;
@@ -94,7 +95,7 @@ export class CrossDomainAuth {
94
95
  return session;
95
96
  }
96
97
  catch (error) {
97
- console.warn('[CrossDomainAuth] FedCM failed, trying popup...', error);
98
+ logger.warn('FedCM failed, trying popup', { component: 'CrossDomainAuth', method: 'autoSignIn' }, error);
98
99
  }
99
100
  }
100
101
  // 2. Try popup (good UX, widely supported)
@@ -103,7 +104,7 @@ export class CrossDomainAuth {
103
104
  return await this.signInWithPopup(options);
104
105
  }
105
106
  catch (error) {
106
- console.warn('[CrossDomainAuth] Popup failed, falling back to redirect...', error);
107
+ logger.warn('Popup failed, falling back to redirect', { component: 'CrossDomainAuth', method: 'autoSignIn' }, error);
107
108
  // Popup path failed — close the pre-opened popup before redirecting.
108
109
  this.closeOrphanPopup(options.popup);
109
110
  }
@@ -172,7 +173,7 @@ export class CrossDomainAuth {
172
173
  }
173
174
  }
174
175
  catch (error) {
175
- console.warn('[CrossDomainAuth] FedCM silent sign-in failed:', error);
176
+ logger.debug('FedCM silent sign-in did not resolve', { component: 'CrossDomainAuth', method: 'silentSignIn' }, error);
176
177
  }
177
178
  }
178
179
  // Fallback to iframe-based silent auth
@@ -180,7 +181,7 @@ export class CrossDomainAuth {
180
181
  return await this.oxyServices.silentSignIn();
181
182
  }
182
183
  catch (error) {
183
- console.warn('[CrossDomainAuth] Silent sign-in failed:', error);
184
+ logger.debug('iframe silent sign-in did not resolve', { component: 'CrossDomainAuth', method: 'silentSignIn' }, error);
184
185
  return null;
185
186
  }
186
187
  }
@@ -265,7 +266,7 @@ export class CrossDomainAuth {
265
266
  }
266
267
  }
267
268
  catch (error) {
268
- console.warn('[CrossDomainAuth] Stored session invalid:', error);
269
+ logger.debug('stored session invalid', { component: 'CrossDomainAuth', method: 'initialize' }, error);
269
270
  }
270
271
  }
271
272
  // 3. Try silent sign-in (check for SSO session at auth.oxy.so)
@@ -7,6 +7,7 @@ import { jwtDecode } from 'jwt-decode';
7
7
  import { handleHttpError } from './utils/errorUtils.js';
8
8
  import { HttpService } from './HttpService.js';
9
9
  import { OxyAuthenticationError, OxyAuthenticationTimeoutError } from './OxyServices.errors.js';
10
+ import { autoDetectAuthWebUrl } from './utils/fapiAutoDetect.js';
10
11
  /**
11
12
  * Base class for OxyServices with core infrastructure
12
13
  */
@@ -18,10 +19,22 @@ export class OxyServicesBase {
18
19
  if (!config || typeof config !== 'object') {
19
20
  throw new Error('OxyConfig is required');
20
21
  }
21
- this.config = config;
22
- this.cloudURL = config.cloudURL || 'https://cloud.oxy.so';
22
+ // Auto-detect the first-party IdP (`auth.<rp-apex>`) when the caller did not
23
+ // pin `authWebUrl` explicitly. This mirrors the provider-`baseURL` path in
24
+ // `@oxyhq/services` (OxyContext), so apps that construct their OWN
25
+ // `OxyServices` instance and pass it to `<OxyProvider oxyServices={...} />`
26
+ // get the same same-site IdP resolution. On web at `https://mention.earth`
27
+ // this yields `https://auth.mention.earth`; on native/SSR (no `window`)
28
+ // `autoDetectAuthWebUrl()` returns `undefined`, leaving the auth mixins'
29
+ // `DEFAULT_AUTH_URL` fallback in effect — native behavior is unchanged.
30
+ // An explicit `authWebUrl` always wins (we only fill it when absent).
31
+ const resolvedConfig = config.authWebUrl
32
+ ? config
33
+ : { ...config, authWebUrl: autoDetectAuthWebUrl() };
34
+ this.config = resolvedConfig;
35
+ this.cloudURL = resolvedConfig.cloudURL || 'https://cloud.oxy.so';
23
36
  // Initialize unified HTTP service (handles auth, caching, deduplication, queuing, retry)
24
- this.httpService = new HttpService(config);
37
+ this.httpService = new HttpService(resolvedConfig);
25
38
  }
26
39
  // Test-only utility to reset tokens on this instance between jest tests
27
40
  // Note: tokens are now per-instance, so create new instances in tests for isolation