@prodantix/react 0.0.2 → 0.0.3-beta.370
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 +1 -1
- package/dist/index.d.cts +29 -2
- package/dist/index.d.ts +29 -2
- package/dist/index.js +1 -1
- package/package.json +5 -5
package/dist/index.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
"use strict";"use client";var
|
|
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
|
|
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.
|
|
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
|
},
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"module": "./dist/index.js",
|
|
29
29
|
"name": "@prodantix/react",
|
|
30
30
|
"peerDependencies": {
|
|
31
|
-
"@prodantix/sdk": "^0.0
|
|
31
|
+
"@prodantix/sdk": "^0.2.0",
|
|
32
32
|
"react": ">=18"
|
|
33
33
|
},
|
|
34
34
|
"publishConfig": {
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
"sideEffects": false,
|
|
48
48
|
"type": "module",
|
|
49
49
|
"types": "./dist/index.d.ts",
|
|
50
|
-
"version": "0.0.
|
|
50
|
+
"version": "0.0.3-beta.370"
|
|
51
51
|
}
|