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