@auxx/chat 0.0.2 → 0.0.5

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.
@@ -14,11 +14,23 @@ declare global {
14
14
  declare function boot(options: BootOptions): void;
15
15
  declare function update(attributes: Record<string, unknown>): void;
16
16
  declare function shutdown(): void;
17
+ /**
18
+ * Identity rotation. Clears the cached passport so the next request mints
19
+ * fresh, drops the in-memory JWT. Does NOT remove the script tag or hide
20
+ * the widget — the visitor can still chat anonymously after logout if the
21
+ * channel allows it.
22
+ *
23
+ * Use `shutdown()` for a soft teardown (unmount) where the visitor session
24
+ * should survive a re-mount. Use `logout()` when the visitor's identity
25
+ * just changed (logged out, switched accounts).
26
+ */
27
+ declare function logout(): void;
17
28
  declare const Auxx: {
18
29
  boot: typeof boot;
19
30
  update: typeof update;
20
31
  shutdown: typeof shutdown;
32
+ logout: typeof logout;
21
33
  };
22
34
  export default Auxx;
23
- export { boot, update, shutdown };
35
+ export { boot, update, shutdown, logout };
24
36
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/client/index.ts"],"names":[],"mappings":"AA0BA,MAAM,WAAW,WAAW;IAC1B,SAAS,EAAE,MAAM,CAAA;IACjB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACpC,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,KAAK,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,QAAQ,CAAA;CACpC;AAYD,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,QAAQ,CAAC,EAAE,OAAO,CAAA;KACnB;CACF;AA0BD,iBAAS,IAAI,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI,CA0DxC;AAED,iBAAS,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAOzD;AAED,iBAAS,QAAQ,IAAI,IAAI,CAYxB;AAED,QAAA,MAAM,IAAI;;;;CAA6B,CAAA;AAEvC,eAAe,IAAI,CAAA;AACnB,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/client/index.ts"],"names":[],"mappings":"AA0BA,MAAM,WAAW,WAAW;IAC1B,SAAS,EAAE,MAAM,CAAA;IACjB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACpC,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,KAAK,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,QAAQ,CAAA;CACpC;AAYD,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,QAAQ,CAAC,EAAE,OAAO,CAAA;KACnB;CACF;AA0BD,iBAAS,IAAI,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI,CA0DxC;AAED,iBAAS,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAOzD;AAED,iBAAS,QAAQ,IAAI,IAAI,CAYxB;AAED;;;;;;;;;GASG;AACH,iBAAS,MAAM,IAAI,IAAI,CAWtB;AAED,QAAA,MAAM,IAAI;;;;;CAAqC,CAAA;AAE/C,eAAe,IAAI,CAAA;AACnB,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAA"}
@@ -122,6 +122,31 @@ function shutdown() {
122
122
  }
123
123
  state = null;
124
124
  }
125
- const Auxx = { boot, update, shutdown };
125
+ /**
126
+ * Identity rotation. Clears the cached passport so the next request mints
127
+ * fresh, drops the in-memory JWT. Does NOT remove the script tag or hide
128
+ * the widget — the visitor can still chat anonymously after logout if the
129
+ * channel allows it.
130
+ *
131
+ * Use `shutdown()` for a soft teardown (unmount) where the visitor session
132
+ * should survive a re-mount. Use `logout()` when the visitor's identity
133
+ * just changed (logged out, switched accounts).
134
+ */
135
+ function logout() {
136
+ if (typeof window === 'undefined')
137
+ return;
138
+ if (!state)
139
+ return;
140
+ try {
141
+ window.localStorage.removeItem(`auxx_passport_chat_${state.channelId}`);
142
+ }
143
+ catch {
144
+ /* ignore */
145
+ }
146
+ state.userJwt = undefined;
147
+ const cfg = (window.__AUXX_CONFIG__ ??= {});
148
+ delete cfg.userJwt;
149
+ }
150
+ const Auxx = { boot, update, shutdown, logout };
126
151
  export default Auxx;
127
- export { boot, update, shutdown };
152
+ export { boot, update, shutdown, logout };
@@ -14,11 +14,23 @@ declare global {
14
14
  declare function boot(options: BootOptions): void;
15
15
  declare function update(attributes: Record<string, unknown>): void;
16
16
  declare function shutdown(): void;
17
+ /**
18
+ * Identity rotation. Clears the cached passport so the next request mints
19
+ * fresh, drops the in-memory JWT. Does NOT remove the script tag or hide
20
+ * the widget — the visitor can still chat anonymously after logout if the
21
+ * channel allows it.
22
+ *
23
+ * Use `shutdown()` for a soft teardown (unmount) where the visitor session
24
+ * should survive a re-mount. Use `logout()` when the visitor's identity
25
+ * just changed (logged out, switched accounts).
26
+ */
27
+ declare function logout(): void;
17
28
  declare const Auxx: {
18
29
  boot: typeof boot;
19
30
  update: typeof update;
20
31
  shutdown: typeof shutdown;
32
+ logout: typeof logout;
21
33
  };
22
34
  export default Auxx;
23
- export { boot, update, shutdown };
35
+ export { boot, update, shutdown, logout };
24
36
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/client/index.ts"],"names":[],"mappings":"AA0BA,MAAM,WAAW,WAAW;IAC1B,SAAS,EAAE,MAAM,CAAA;IACjB,OAAO,CAAC,EAAE,MAAM,C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,IAAI,CAOzD;AAED,iBAAS,QAAQ,IAAI,IAAI,CAYxB;AAED;;;;;;;;;GASG;AACH,iBAAS,MAAM,IAAI,IAAI,CAWtB;AAED,QAAA,MAAM,IAAI;;;;;CAAqC,CAAA;AAE/C,eAAe,IAAI,CAAA;AACnB,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAA"}
@@ -122,6 +122,31 @@ function shutdown() {
122
122
  }
123
123
  state = null;
124
124
  }
125
- const Auxx = { boot, update, shutdown };
125
+ /**
126
+ * Identity rotation. Clears the cached passport so the next request mints
127
+ * fresh, drops the in-memory JWT. Does NOT remove the script tag or hide
128
+ * the widget — the visitor can still chat anonymously after logout if the
129
+ * channel allows it.
130
+ *
131
+ * Use `shutdown()` for a soft teardown (unmount) where the visitor session
132
+ * should survive a re-mount. Use `logout()` when the visitor's identity
133
+ * just changed (logged out, switched accounts).
134
+ */
135
+ function logout() {
136
+ if (typeof window === 'undefined')
137
+ return;
138
+ if (!state)
139
+ return;
140
+ try {
141
+ window.localStorage.removeItem(`auxx_passport_chat_${state.channelId}`);
142
+ }
143
+ catch {
144
+ /* ignore */
145
+ }
146
+ state.userJwt = undefined;
147
+ const cfg = (window.__AUXX_CONFIG__ ??= {});
148
+ delete cfg.userJwt;
149
+ }
150
+ const Auxx = { boot, update, shutdown, logout };
126
151
  export default Auxx;
127
- export { boot, update, shutdown };
152
+ export { boot, update, shutdown, logout };
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/react/index.tsx"],"names":[],"mappings":"AAcA,OAAa,EAAE,KAAK,WAAW,EAAE,MAAM,WAAW,CAAA;AAElD,MAAM,WAAW,aAAc,SAAQ,WAAW;CAAG;AAErD,wBAAgB,QAAQ,CAAC,KAAK,EAAE,aAAa,GAAG,IAAI,CA2BnD;AAED,eAAe,QAAQ,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/react/index.tsx"],"names":[],"mappings":"AAcA,OAAa,EAAE,KAAK,WAAW,EAAE,MAAM,WAAW,CAAA;AAElD,MAAM,WAAW,aAAc,SAAQ,WAAW;CAAG;AAErD,wBAAgB,QAAQ,CAAC,KAAK,EAAE,aAAa,GAAG,IAAI,CA+CnD;AAED,eAAe,QAAQ,CAAA"}
@@ -15,24 +15,46 @@ export function AuxxChat(props) {
15
15
  const { channelId, userJwt, attributes, apiBase, widgetBase, theme } = props;
16
16
  // Track whether boot() has run so attribute changes route through update().
17
17
  const bootedRef = useRef(false);
18
+ // Track previous userJwt so a defined → undefined transition can route
19
+ // through logout() (clears the cached passport) instead of a full reboot.
20
+ const prevJwtRef = useRef(userJwt);
21
+ // Boot once per channel/hosting target. JWT changes are handled by the
22
+ // second effect so a simple logout doesn't have to tear down the bundle.
23
+ // biome-ignore lint/correctness/useExhaustiveDependencies: boot is keyed on channel/hosting target only; JWT and attribute changes are handled by sibling effects.
18
24
  useEffect(() => {
19
25
  Auxx.boot({ channelId, userJwt, attributes, apiBase, widgetBase, theme });
20
26
  bootedRef.current = true;
27
+ prevJwtRef.current = userJwt;
21
28
  return () => {
22
29
  Auxx.shutdown();
23
30
  bootedRef.current = false;
24
31
  };
25
- // Reboot whenever the channel / JWT / hosting URLs change. Attribute
26
- // changes are handled by the second effect via `update()`.
27
- // eslint-disable-next-line react-hooks/exhaustive-deps
28
- }, [channelId, userJwt, apiBase, widgetBase, theme]);
32
+ }, [channelId, apiBase, widgetBase, theme]);
33
+ // React to JWT changes after boot:
34
+ // - defined → undefined : logout() (clear cached passport, drop in-memory JWT)
35
+ // - any change with a defined next value : re-boot to rotate the token
36
+ // biome-ignore lint/correctness/useExhaustiveDependencies: intentionally fires on userJwt only — re-boot reads the latest channelId/hosting props from closure.
37
+ useEffect(() => {
38
+ if (!bootedRef.current)
39
+ return;
40
+ const prev = prevJwtRef.current;
41
+ if (prev === userJwt)
42
+ return;
43
+ if (userJwt === undefined) {
44
+ Auxx.logout();
45
+ }
46
+ else {
47
+ Auxx.boot({ channelId, userJwt, attributes, apiBase, widgetBase, theme });
48
+ }
49
+ prevJwtRef.current = userJwt;
50
+ }, [userJwt]);
29
51
  // Serialize attributes so reference-only changes don't fire spurious updates.
30
52
  const attributesKey = attributes ? JSON.stringify(attributes) : '';
53
+ // biome-ignore lint/correctness/useExhaustiveDependencies: attributesKey is the stable serialized form; attributes is read from closure.
31
54
  useEffect(() => {
32
55
  if (!bootedRef.current || !attributes)
33
56
  return;
34
57
  Auxx.update(attributes);
35
- // eslint-disable-next-line react-hooks/exhaustive-deps
36
58
  }, [attributesKey]);
37
59
  return null;
38
60
  }