@prodantix/react 0.0.2-beta.348 → 0.0.2-beta.357

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.cjs CHANGED
@@ -1,3 +1,3 @@
1
1
  'use client';
2
- "use strict";"use client";var x=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var k=Object.getOwnPropertyNames;var $=Object.prototype.hasOwnProperty;var w=(n,e)=>{for(var t in e)x(n,t,{get:e[t],enumerable:!0})},O=(n,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of k(e))!$.call(n,i)&&i!==t&&x(n,i,{get:()=>e[i],enumerable:!(o=b(e,i))||o.enumerable});return n};var A=n=>O(x({},"__esModule",{value:!0}),n);var N={};w(N,{ProdantixProvider:()=>W,prodantixConfig:()=>y,resetProdantixForTest:()=>R,skipReason:()=>K,useMessenger:()=>I,useProdantix:()=>E});module.exports=A(N);var C=require("@prodantix/sdk/chat"),g=require("@prodantix/sdk/messenger"),P=require("@prodantix/sdk/web"),r=require("react"),h=require("react/jsx-runtime"),m=(0,r.createContext)(null),v=(0,r.createContext)(null),f="[prodantix/react]";function y(n){let e=n.key?.trim()??"",t=n.host?.trim()??"";return e===""||t===""?null:{apiKey:e,host:t}}function K(n,e){let t=y(n);if(t===null){let o=[n.key?.trim()?null:"key",n.host?.trim()?null:"host"].filter(Boolean).join(" and ");return`${f} disabled: no ${o}. Nothing will be sent from this app.`}return e===null?null:e.apiKey!==t.apiKey||e.host!==t.host?`${f} already installed against ${e.host}; the new host ${t.host} is ignored for this page load.`:null}var p=null,l=null,a=null;function R(){p=null,a=null,l?.destroy(),l=null}var W=({children:n,options:e})=>{let[t,o]=(0,r.useState)(a),[i,H]=(0,r.useState)(null);return(0,r.useEffect)(()=>{let s={host:e.host,key:e.apiKey},d=K(s,p);if(d!==null){console.warn(d);return}let u=y(s);if(u===null||p!==null){o(a);return}try{a=(0,P.createWebClient)(e),p=u,o(a)}catch(c){console.error(`${f} failed to start against ${u.host}:`,c)}},[e]),(0,r.useEffect)(()=>{let s=e.messengerHost?.trim();if(!s||!e.apiKey||l)return;let d=!1,u=a?.distinctId??"anonymous";return(async()=>{let c=await(0,g.fetchMessengerConfig)({apiKey:e.apiKey,host:s,onError:M=>console.warn(`${f} messenger settings could not be read:`,M)})??(0,g.cachedMessengerConfig)(void 0,e.apiKey);d||!c?.enabled||l||(l=(0,C.mountChat)({apiKey:e.apiKey,appearance:c,distinctId:u,host:s}),H({close:()=>l?.close(),open:()=>l?.open()}))})(),()=>{d=!0}},[e]),(0,h.jsx)(m.Provider,{value:t,children:(0,h.jsx)(v.Provider,{value:i,children:n})})},E=()=>(0,r.useContext)(m),I=()=>(0,r.useContext)(v);0&&(module.exports={ProdantixProvider,prodantixConfig,resetProdantixForTest,skipReason,useMessenger,useProdantix});
2
+ "use strict";"use client";var h=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var $=Object.getOwnPropertyNames;var O=Object.prototype.hasOwnProperty;var w=(t,e)=>{for(var n in e)h(t,n,{get:e[n],enumerable:!0})},N=(t,e,n,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of $(e))!O.call(t,o)&&o!==n&&h(t,o,{get:()=>e[o],enumerable:!(i=k(e,o))||i.enumerable});return t};var R=t=>N(h({},"__esModule",{value:!0}),t);var F={};w(F,{ProdantixProvider:()=>W,prodantixConfig:()=>C,resetProdantixForTest:()=>A,skipReason:()=>b,useMessenger:()=>T,useProdantix:()=>E});module.exports=R(F);var m=require("@prodantix/sdk/chat"),x=require("@prodantix/sdk/messenger"),v=require("@prodantix/sdk/web"),r=require("react"),P=require("react/jsx-runtime"),K=(0,r.createContext)(null),I=(0,r.createContext)(null),g="[prodantix/react]";function C(t){let e=t.key?.trim()??"",n=t.host?.trim()??"";return e===""||n===""?null:{apiKey:e,host:n}}function b(t,e){let n=C(t);if(n===null){let i=[t.key?.trim()?null:"key",t.host?.trim()?null:"host"].filter(Boolean).join(" and ");return`${g} disabled: no ${i}. Nothing will be sent from this app.`}return e===null?null:e.apiKey!==n.apiKey||e.host!==n.host?`${g} already installed against ${e.host}; the new host ${n.host} is ignored for this page load.`:null}var p=null,l=null,d=null;function A(){p=null,d=null,l?.destroy(),l=null}var W=({children:t,options:e})=>{let[n,i]=(0,r.useState)(d),[o,H]=(0,r.useState)(null),s=e.person,y=(0,r.useRef)(null);return(0,r.useEffect)(()=>{let a={host:e.host,key:e.apiKey},u=b(a,p);if(u!==null){console.warn(u);return}let c=C(a);if(c===null||p!==null){i(d);return}try{d=(0,v.createWebClient)(e),p=c,i(d)}catch(f){console.error(`${g} failed to start against ${c.host}:`,f)}},[e]),(0,r.useEffect)(()=>{if(!(n===null||s===void 0)){if(s===null){if(!n.isIdentified)return;n.reset(),y.current=null;return}y.current!==s.distinctId&&(n.identify(s.distinctId,{traits:s.traits}),y.current=s.distinctId)}},[n,s]),(0,r.useEffect)(()=>{let a=e.messengerHost?.trim();if(!a||!e.apiKey||l)return;let u=!1,c=d?.distinctId??"anonymous";return(async()=>{let f=await(0,x.fetchMessengerConfig)({apiKey:e.apiKey,host:a,onError:M=>console.warn(`${g} messenger settings could not be read:`,M)})??(0,x.cachedMessengerConfig)(void 0,e.apiKey);u||!f?.enabled||l||(l=(0,m.mountChat)({apiKey:e.apiKey,appearance:f,distinctId:c,host:a}),H({close:()=>l?.close(),open:()=>l?.open()}))})(),()=>{u=!0}},[e]),(0,P.jsx)(K.Provider,{value:n,children:(0,P.jsx)(I.Provider,{value:o,children:t})})},E=()=>(0,r.useContext)(K),T=()=>(0,r.useContext)(I);0&&(module.exports={ProdantixProvider,prodantixConfig,resetProdantixForTest,skipReason,useMessenger,useProdantix});
3
3
  //# sourceMappingURL=index.cjs.map
package/dist/index.d.cts CHANGED
@@ -1,14 +1,41 @@
1
1
  import * as react from 'react';
2
2
  import { ReactNode } from 'react';
3
- import { ProdantixClient } from '@prodantix/sdk';
3
+ import { IdentifyOptions, ProdantixClient } from '@prodantix/sdk';
4
4
  import { WebClientOptions } from '@prodantix/sdk/web';
5
5
  export { WebClientOptions } from '@prodantix/sdk/web';
6
6
 
7
+ type PersonTraits = NonNullable<IdentifyOptions['traits']>;
8
+ interface Person {
9
+ distinctId: string;
10
+ traits?: PersonTraits;
11
+ }
7
12
  interface ProdantixOptions extends WebClientOptions {
8
13
  /** The public browser edge, e.g. `https://eu.edge.prodantix.com`. The
9
14
  * messenger appears when this is set AND the project has it switched on in
10
15
  * the console; absent, the provider installs analytics only. */
11
16
  messengerHost?: string;
17
+ /**
18
+ * The signed-in person, as the surface's session knows them: the token's
19
+ * `sub`. A prop rather than a call, so sign-in and sign-out reach the client
20
+ * as the values they are. Three states, and the surface owes the right one:
21
+ *
22
+ * `undefined` means the surface does not know yet, and nothing happens. A
23
+ * mount that consults no session at all passes this too: `null` is a claim
24
+ * that a session was consulted and found empty, and a hand-passed `null` from
25
+ * a page with no session would reset a person who is still signed in
26
+ * elsewhere on the site, rotating their anonymous id mid-session.
27
+ *
28
+ * A value identifies, on the first value and whenever the distinct id
29
+ * changes.
30
+ *
31
+ * `null` means the surface KNOWS nobody is signed in, and resets the client if
32
+ * it still holds someone, which rotates the anonymous id so the next visitor
33
+ * on this browser is not the person who signed out. It must never stand for
34
+ * "loading": sign-out on a BFF surface is a hard navigation, so the reset has
35
+ * to fire on a first render with `null`, and a signed-in person reloading a
36
+ * page would be reset before their session hydrated.
37
+ */
38
+ person?: Person | null;
12
39
  }
13
40
  interface ProdantixProviderProps {
14
41
  children?: ReactNode;
@@ -52,4 +79,4 @@ declare const useProdantix: () => ProdantixClient | null;
52
79
  * handle that rather than assume a handle exists. */
53
80
  declare const useMessenger: () => MessengerHandle | null;
54
81
 
55
- export { type MessengerHandle, type ProdantixOptions, ProdantixProvider, type ProdantixProviderProps, prodantixConfig, resetProdantixForTest, skipReason, useMessenger, useProdantix };
82
+ export { type MessengerHandle, type Person, type PersonTraits, type ProdantixOptions, ProdantixProvider, type ProdantixProviderProps, prodantixConfig, resetProdantixForTest, skipReason, useMessenger, useProdantix };
package/dist/index.d.ts CHANGED
@@ -1,14 +1,41 @@
1
1
  import * as react from 'react';
2
2
  import { ReactNode } from 'react';
3
- import { ProdantixClient } from '@prodantix/sdk';
3
+ import { IdentifyOptions, ProdantixClient } from '@prodantix/sdk';
4
4
  import { WebClientOptions } from '@prodantix/sdk/web';
5
5
  export { WebClientOptions } from '@prodantix/sdk/web';
6
6
 
7
+ type PersonTraits = NonNullable<IdentifyOptions['traits']>;
8
+ interface Person {
9
+ distinctId: string;
10
+ traits?: PersonTraits;
11
+ }
7
12
  interface ProdantixOptions extends WebClientOptions {
8
13
  /** The public browser edge, e.g. `https://eu.edge.prodantix.com`. The
9
14
  * messenger appears when this is set AND the project has it switched on in
10
15
  * the console; absent, the provider installs analytics only. */
11
16
  messengerHost?: string;
17
+ /**
18
+ * The signed-in person, as the surface's session knows them: the token's
19
+ * `sub`. A prop rather than a call, so sign-in and sign-out reach the client
20
+ * as the values they are. Three states, and the surface owes the right one:
21
+ *
22
+ * `undefined` means the surface does not know yet, and nothing happens. A
23
+ * mount that consults no session at all passes this too: `null` is a claim
24
+ * that a session was consulted and found empty, and a hand-passed `null` from
25
+ * a page with no session would reset a person who is still signed in
26
+ * elsewhere on the site, rotating their anonymous id mid-session.
27
+ *
28
+ * A value identifies, on the first value and whenever the distinct id
29
+ * changes.
30
+ *
31
+ * `null` means the surface KNOWS nobody is signed in, and resets the client if
32
+ * it still holds someone, which rotates the anonymous id so the next visitor
33
+ * on this browser is not the person who signed out. It must never stand for
34
+ * "loading": sign-out on a BFF surface is a hard navigation, so the reset has
35
+ * to fire on a first render with `null`, and a signed-in person reloading a
36
+ * page would be reset before their session hydrated.
37
+ */
38
+ person?: Person | null;
12
39
  }
13
40
  interface ProdantixProviderProps {
14
41
  children?: ReactNode;
@@ -52,4 +79,4 @@ declare const useProdantix: () => ProdantixClient | null;
52
79
  * handle that rather than assume a handle exists. */
53
80
  declare const useMessenger: () => MessengerHandle | null;
54
81
 
55
- export { type MessengerHandle, type ProdantixOptions, ProdantixProvider, type ProdantixProviderProps, prodantixConfig, resetProdantixForTest, skipReason, useMessenger, useProdantix };
82
+ export { type MessengerHandle, type Person, type PersonTraits, type ProdantixOptions, ProdantixProvider, type ProdantixProviderProps, prodantixConfig, resetProdantixForTest, skipReason, useMessenger, useProdantix };
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
1
  'use client';
2
- "use client";import{mountChat as H}from"@prodantix/sdk/chat";import{cachedMessengerConfig as M,fetchMessengerConfig as b}from"@prodantix/sdk/messenger";import{createWebClient as k}from"@prodantix/sdk/web";import{createContext as x,useContext as h,useEffect as p,useState as f}from"react";import{jsx as g}from"react/jsx-runtime";var y=x(null),C=x(null),c="[prodantix/react]";function P(t){let e=t.key?.trim()??"",n=t.host?.trim()??"";return e===""||n===""?null:{apiKey:e,host:n}}function $(t,e){let n=P(t);if(n===null){let a=[t.key?.trim()?null:"key",t.host?.trim()?null:"host"].filter(Boolean).join(" and ");return`${c} disabled: no ${a}. Nothing will be sent from this app.`}return e===null?null:e.apiKey!==n.apiKey||e.host!==n.host?`${c} already installed against ${e.host}; the new host ${n.host} is ignored for this page load.`:null}var u=null,r=null,i=null;function W(){u=null,i=null,r?.destroy(),r=null}var E=({children:t,options:e})=>{let[n,a]=f(i),[m,v]=f(null);return p(()=>{let o={host:e.host,key:e.apiKey},l=$(o,u);if(l!==null){console.warn(l);return}let s=P(o);if(s===null||u!==null){a(i);return}try{i=k(e),u=s,a(i)}catch(d){console.error(`${c} failed to start against ${s.host}:`,d)}},[e]),p(()=>{let o=e.messengerHost?.trim();if(!o||!e.apiKey||r)return;let l=!1,s=i?.distinctId??"anonymous";return(async()=>{let d=await b({apiKey:e.apiKey,host:o,onError:K=>console.warn(`${c} messenger settings could not be read:`,K)})??M(void 0,e.apiKey);l||!d?.enabled||r||(r=H({apiKey:e.apiKey,appearance:d,distinctId:s,host:o}),v({close:()=>r?.close(),open:()=>r?.open()}))})(),()=>{l=!0}},[e]),g(y.Provider,{value:n,children:g(C.Provider,{value:m,children:t})})},I=()=>h(y),N=()=>h(C);export{E as ProdantixProvider,P as prodantixConfig,W as resetProdantixForTest,$ as skipReason,N as useMessenger,I as useProdantix};
2
+ "use client";import{mountChat as H}from"@prodantix/sdk/chat";import{cachedMessengerConfig as M,fetchMessengerConfig as k}from"@prodantix/sdk/messenger";import{createWebClient as $}from"@prodantix/sdk/web";import{createContext as h,useContext as P,useEffect as g,useRef as O,useState as x}from"react";import{jsx as y}from"react/jsx-runtime";var C=h(null),m=h(null),f="[prodantix/react]";function v(t){let e=t.key?.trim()??"",n=t.host?.trim()??"";return e===""||n===""?null:{apiKey:e,host:n}}function w(t,e){let n=v(t);if(n===null){let d=[t.key?.trim()?null:"key",t.host?.trim()?null:"host"].filter(Boolean).join(" and ");return`${f} disabled: no ${d}. Nothing will be sent from this app.`}return e===null?null:e.apiKey!==n.apiKey||e.host!==n.host?`${f} already installed against ${e.host}; the new host ${n.host} is ignored for this page load.`:null}var c=null,i=null,s=null;function E(){c=null,s=null,i?.destroy(),i=null}var T=({children:t,options:e})=>{let[n,d]=x(s),[K,I]=x(null),r=e.person,p=O(null);return g(()=>{let o={host:e.host,key:e.apiKey},l=w(o,c);if(l!==null){console.warn(l);return}let a=v(o);if(a===null||c!==null){d(s);return}try{s=$(e),c=a,d(s)}catch(u){console.error(`${f} failed to start against ${a.host}:`,u)}},[e]),g(()=>{if(!(n===null||r===void 0)){if(r===null){if(!n.isIdentified)return;n.reset(),p.current=null;return}p.current!==r.distinctId&&(n.identify(r.distinctId,{traits:r.traits}),p.current=r.distinctId)}},[n,r]),g(()=>{let o=e.messengerHost?.trim();if(!o||!e.apiKey||i)return;let l=!1,a=s?.distinctId??"anonymous";return(async()=>{let u=await k({apiKey:e.apiKey,host:o,onError:b=>console.warn(`${f} messenger settings could not be read:`,b)})??M(void 0,e.apiKey);l||!u?.enabled||i||(i=H({apiKey:e.apiKey,appearance:u,distinctId:a,host:o}),I({close:()=>i?.close(),open:()=>i?.open()}))})(),()=>{l=!0}},[e]),y(C.Provider,{value:n,children:y(m.Provider,{value:K,children:t})})},F=()=>P(C),B=()=>P(m);export{T as ProdantixProvider,v as prodantixConfig,E as resetProdantixForTest,w as skipReason,B as useMessenger,F as useProdantix};
3
3
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "devDependencies": {
4
4
  "@bomdisoft/typescript-config": "0.0.0",
5
5
  "@happy-dom/global-registrator": "^20.11.6",
6
- "@prodantix/sdk": "0.1.0",
6
+ "@prodantix/sdk": "0.2.0",
7
7
  "@testing-library/react": "^16.3.2",
8
8
  "@types/bun": "^1.4.0",
9
9
  "@types/react": "^19.2.18",
@@ -15,9 +15,9 @@
15
15
  },
16
16
  "exports": {
17
17
  ".": {
18
+ "types": "./dist/index.d.ts",
18
19
  "import": "./dist/index.js",
19
- "require": "./dist/index.cjs",
20
- "types": "./dist/index.d.ts"
20
+ "require": "./dist/index.cjs"
21
21
  },
22
22
  "./package.json": "./package.json"
23
23
  },
@@ -47,5 +47,5 @@
47
47
  "sideEffects": false,
48
48
  "type": "module",
49
49
  "types": "./dist/index.d.ts",
50
- "version": "0.0.2-beta.348"
50
+ "version": "0.0.2-beta.357"
51
51
  }