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