@traffical/svelte 0.3.2 → 0.3.3
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/README.md +18 -0
- package/dist/context.svelte.d.ts.map +1 -1
- package/dist/context.svelte.js +9 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -402,6 +402,24 @@ const params = resolveParamsSSR(bundle, { userId: 'user_123' }, {
|
|
|
402
402
|
});
|
|
403
403
|
```
|
|
404
404
|
|
|
405
|
+
## Changing User Identity
|
|
406
|
+
|
|
407
|
+
Use `client.identify()` to switch user identity mid-session. All `useTraffical` hooks automatically re-derive with new assignments.
|
|
408
|
+
|
|
409
|
+
```svelte
|
|
410
|
+
<script>
|
|
411
|
+
import { useTrafficalClient } from '@traffical/svelte';
|
|
412
|
+
|
|
413
|
+
const { client } = useTrafficalClient();
|
|
414
|
+
|
|
415
|
+
function handleLogin(userId: string) {
|
|
416
|
+
client?.identify(userId);
|
|
417
|
+
}
|
|
418
|
+
</script>
|
|
419
|
+
```
|
|
420
|
+
|
|
421
|
+
This also works from Traffical DevTools — changing the user ID in DevTools calls `identify()` under the hood, causing reactive updates across all components.
|
|
422
|
+
|
|
405
423
|
## Configuration Options
|
|
406
424
|
|
|
407
425
|
```typescript
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.svelte.d.ts","sourceRoot":"","sources":["../src/context.svelte.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAUH,OAAO,KAAK,EACV,uBAAuB,EACvB,qBAAqB,EACtB,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"context.svelte.d.ts","sourceRoot":"","sources":["../src/context.svelte.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAUH,OAAO,KAAK,EACV,uBAAuB,EACvB,qBAAqB,EACtB,MAAM,YAAY,CAAC;AAoKpB;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,uBAAuB,GAC9B,qBAAqB,CAIvB;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,IAAI,qBAAqB,CAa3D;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,IAAI,OAAO,CAS7C"}
|
package/dist/context.svelte.js
CHANGED
|
@@ -33,6 +33,7 @@ function createTrafficalContextState(config) {
|
|
|
33
33
|
let ready = $state(!!config.initialBundle); // Ready immediately if we have initial bundle
|
|
34
34
|
let error = $state(null);
|
|
35
35
|
let bundle = $state(config.initialBundle ?? null);
|
|
36
|
+
let overrideUnitKey = $state(null);
|
|
36
37
|
// Initialize client only in browser
|
|
37
38
|
// NOTE: We create the client but DO NOT call initialize() here.
|
|
38
39
|
// initialize() triggers fetch(), which causes SSR warnings.
|
|
@@ -61,6 +62,10 @@ function createTrafficalContextState(config) {
|
|
|
61
62
|
plugins: config.plugins,
|
|
62
63
|
});
|
|
63
64
|
client = clientInstance;
|
|
65
|
+
// Subscribe to identity changes from client.identify()
|
|
66
|
+
clientInstance.onIdentityChange((newKey) => {
|
|
67
|
+
overrideUnitKey = newKey;
|
|
68
|
+
});
|
|
64
69
|
// If we have initial bundle, mark as ready immediately (no fetch needed for initial render)
|
|
65
70
|
if (config.initialBundle) {
|
|
66
71
|
ready = true;
|
|
@@ -85,12 +90,14 @@ function createTrafficalContextState(config) {
|
|
|
85
90
|
ready = true;
|
|
86
91
|
}
|
|
87
92
|
}
|
|
88
|
-
// Unit key getter
|
|
93
|
+
// Unit key getter — priority: identify() override > unitKeyFn > auto stable ID
|
|
89
94
|
function getUnitKey() {
|
|
95
|
+
if (overrideUnitKey !== null) {
|
|
96
|
+
return overrideUnitKey;
|
|
97
|
+
}
|
|
90
98
|
if (config.unitKeyFn) {
|
|
91
99
|
return config.unitKeyFn();
|
|
92
100
|
}
|
|
93
|
-
// Fall back to client's auto-generated stable ID
|
|
94
101
|
return client?.getStableId() ?? "";
|
|
95
102
|
}
|
|
96
103
|
// Context getter - merges unit key with additional context
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@traffical/svelte",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.3",
|
|
4
4
|
"description": "Traffical SDK for Svelte 5 - Provider and hooks for parameter resolution with SSR support",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"svelte": "./dist/index.js",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@traffical/core": "0.5.0",
|
|
38
|
-
"@traffical/js-client": "0.
|
|
38
|
+
"@traffical/js-client": "0.9.0",
|
|
39
39
|
"@traffical/node": "0.4.1"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|