@clianta/sdk 1.6.5 → 1.6.7

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/index.d.ts CHANGED
@@ -524,7 +524,7 @@ interface StoredConsent {
524
524
  */
525
525
 
526
526
  /** SDK Version */
527
- declare const SDK_VERSION = "1.6.5";
527
+ declare const SDK_VERSION = "1.6.7";
528
528
 
529
529
  /**
530
530
  * Clianta SDK
package/dist/react.cjs.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Clianta SDK v1.6.5
2
+ * Clianta SDK v1.6.7
3
3
  * (c) 2026 Clianta
4
4
  * Released under the MIT License.
5
5
  */
@@ -14,7 +14,7 @@ var _documentCurrentScript = typeof document !== 'undefined' ? document.currentS
14
14
  * @see SDK_VERSION in core/config.ts
15
15
  */
16
16
  /** SDK Version */
17
- const SDK_VERSION = '1.6.5';
17
+ const SDK_VERSION = '1.6.7';
18
18
  /** Default API endpoint — reads from env or falls back to localhost */
19
19
  const getDefaultApiEndpoint = () => {
20
20
  // Next.js (process.env)
@@ -2318,19 +2318,26 @@ class AutoIdentifyPlugin extends BasePlugin {
2318
2318
  if (typeof window === 'undefined')
2319
2319
  return;
2320
2320
  // First check after 2 seconds (give auth providers time to init)
2321
- setTimeout(() => this.checkForAuthUser(), 2000);
2321
+ setTimeout(() => {
2322
+ try {
2323
+ this.checkForAuthUser();
2324
+ }
2325
+ catch { /* silently fail */ }
2326
+ }, 2000);
2322
2327
  // Then check periodically
2323
2328
  this.checkInterval = setInterval(() => {
2324
2329
  this.checkCount++;
2325
2330
  if (this.checkCount >= this.MAX_CHECKS) {
2326
- // Stop checking after MAX_CHECKS — user probably isn't logged in
2327
2331
  if (this.checkInterval) {
2328
2332
  clearInterval(this.checkInterval);
2329
2333
  this.checkInterval = null;
2330
2334
  }
2331
2335
  return;
2332
2336
  }
2333
- this.checkForAuthUser();
2337
+ try {
2338
+ this.checkForAuthUser();
2339
+ }
2340
+ catch { /* silently fail */ }
2334
2341
  }, this.CHECK_INTERVAL_MS);
2335
2342
  }
2336
2343
  destroy() {
@@ -2346,24 +2353,131 @@ class AutoIdentifyPlugin extends BasePlugin {
2346
2353
  checkForAuthUser() {
2347
2354
  if (!this.tracker || this.identifiedEmail)
2348
2355
  return;
2349
- // 1. Check cookies for JWTs
2350
- const cookieUser = this.checkCookies();
2351
- if (cookieUser) {
2352
- this.identifyUser(cookieUser);
2353
- return;
2356
+ // 0. Check well-known auth provider globals (most reliable)
2357
+ try {
2358
+ const providerUser = this.checkAuthProviders();
2359
+ if (providerUser) {
2360
+ this.identifyUser(providerUser);
2361
+ return;
2362
+ }
2354
2363
  }
2355
- // 2. Check localStorage
2356
- const localUser = this.checkStorage(localStorage);
2357
- if (localUser) {
2358
- this.identifyUser(localUser);
2359
- return;
2364
+ catch { /* provider check failed */ }
2365
+ try {
2366
+ // 1. Check cookies for JWTs
2367
+ const cookieUser = this.checkCookies();
2368
+ if (cookieUser) {
2369
+ this.identifyUser(cookieUser);
2370
+ return;
2371
+ }
2360
2372
  }
2361
- // 3. Check sessionStorage
2362
- const sessionUser = this.checkStorage(sessionStorage);
2363
- if (sessionUser) {
2364
- this.identifyUser(sessionUser);
2365
- return;
2373
+ catch { /* cookie access blocked */ }
2374
+ try {
2375
+ // 2. Check localStorage
2376
+ if (typeof localStorage !== 'undefined') {
2377
+ const localUser = this.checkStorage(localStorage);
2378
+ if (localUser) {
2379
+ this.identifyUser(localUser);
2380
+ return;
2381
+ }
2382
+ }
2383
+ }
2384
+ catch { /* localStorage access blocked */ }
2385
+ try {
2386
+ // 3. Check sessionStorage
2387
+ if (typeof sessionStorage !== 'undefined') {
2388
+ const sessionUser = this.checkStorage(sessionStorage);
2389
+ if (sessionUser) {
2390
+ this.identifyUser(sessionUser);
2391
+ return;
2392
+ }
2393
+ }
2394
+ }
2395
+ catch { /* sessionStorage access blocked */ }
2396
+ }
2397
+ /**
2398
+ * Check well-known auth provider globals on window
2399
+ * These are the most reliable — they expose user data directly
2400
+ */
2401
+ checkAuthProviders() {
2402
+ const win = window;
2403
+ // ─── Clerk ───
2404
+ // Clerk exposes window.Clerk after initialization
2405
+ try {
2406
+ const clerkUser = win.Clerk?.user;
2407
+ if (clerkUser) {
2408
+ const email = clerkUser.primaryEmailAddress?.emailAddress
2409
+ || clerkUser.emailAddresses?.[0]?.emailAddress;
2410
+ if (email) {
2411
+ return {
2412
+ email,
2413
+ firstName: clerkUser.firstName || undefined,
2414
+ lastName: clerkUser.lastName || undefined,
2415
+ };
2416
+ }
2417
+ }
2418
+ }
2419
+ catch { /* Clerk not available */ }
2420
+ // ─── Firebase Auth ───
2421
+ try {
2422
+ const fbAuth = win.firebase?.auth?.();
2423
+ const fbUser = fbAuth?.currentUser;
2424
+ if (fbUser?.email) {
2425
+ const parts = (fbUser.displayName || '').split(' ');
2426
+ return {
2427
+ email: fbUser.email,
2428
+ firstName: parts[0] || undefined,
2429
+ lastName: parts.slice(1).join(' ') || undefined,
2430
+ };
2431
+ }
2432
+ }
2433
+ catch { /* Firebase not available */ }
2434
+ // ─── Supabase ───
2435
+ try {
2436
+ const sbClient = win.__SUPABASE_CLIENT__ || win.supabase;
2437
+ if (sbClient?.auth) {
2438
+ // Supabase v2 stores session
2439
+ const session = sbClient.auth.session?.() || sbClient.auth.getSession?.();
2440
+ const user = session?.data?.session?.user || session?.user;
2441
+ if (user?.email) {
2442
+ const meta = user.user_metadata || {};
2443
+ return {
2444
+ email: user.email,
2445
+ firstName: meta.first_name || meta.full_name?.split(' ')[0] || undefined,
2446
+ lastName: meta.last_name || meta.full_name?.split(' ').slice(1).join(' ') || undefined,
2447
+ };
2448
+ }
2449
+ }
2450
+ }
2451
+ catch { /* Supabase not available */ }
2452
+ // ─── Auth0 SPA ───
2453
+ try {
2454
+ const auth0 = win.__auth0Client || win.auth0Client;
2455
+ if (auth0?.isAuthenticated?.()) {
2456
+ const user = auth0.getUser?.();
2457
+ if (user?.email) {
2458
+ return {
2459
+ email: user.email,
2460
+ firstName: user.given_name || user.name?.split(' ')[0] || undefined,
2461
+ lastName: user.family_name || user.name?.split(' ').slice(1).join(' ') || undefined,
2462
+ };
2463
+ }
2464
+ }
2366
2465
  }
2466
+ catch { /* Auth0 not available */ }
2467
+ // ─── Global clianta identify hook ───
2468
+ // Any auth system can set: window.__clianta_user = { email, firstName, lastName }
2469
+ try {
2470
+ const manualUser = win.__clianta_user;
2471
+ if (manualUser?.email && typeof manualUser.email === 'string' && manualUser.email.includes('@')) {
2472
+ return {
2473
+ email: manualUser.email,
2474
+ firstName: manualUser.firstName || undefined,
2475
+ lastName: manualUser.lastName || undefined,
2476
+ };
2477
+ }
2478
+ }
2479
+ catch { /* manual user not set */ }
2480
+ return null;
2367
2481
  }
2368
2482
  /**
2369
2483
  * Identify the user and stop checking