@prodantix/react 0.0.1 → 0.0.2-beta.348
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 +41 -2
- package/dist/index.d.ts +41 -2
- package/dist/index.js +1 -1
- package/package.json +8 -8
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 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});
|
|
3
3
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.d.cts
CHANGED
|
@@ -4,13 +4,52 @@ import { ProdantixClient } from '@prodantix/sdk';
|
|
|
4
4
|
import { WebClientOptions } from '@prodantix/sdk/web';
|
|
5
5
|
export { WebClientOptions } from '@prodantix/sdk/web';
|
|
6
6
|
|
|
7
|
+
interface ProdantixOptions extends WebClientOptions {
|
|
8
|
+
/** The public browser edge, e.g. `https://eu.edge.prodantix.com`. The
|
|
9
|
+
* messenger appears when this is set AND the project has it switched on in
|
|
10
|
+
* the console; absent, the provider installs analytics only. */
|
|
11
|
+
messengerHost?: string;
|
|
12
|
+
}
|
|
7
13
|
interface ProdantixProviderProps {
|
|
8
14
|
children?: ReactNode;
|
|
9
|
-
options:
|
|
15
|
+
options: ProdantixOptions;
|
|
16
|
+
}
|
|
17
|
+
interface MessengerHandle {
|
|
18
|
+
open(): void;
|
|
19
|
+
close(): void;
|
|
20
|
+
}
|
|
21
|
+
interface ActiveConfig {
|
|
22
|
+
apiKey: string;
|
|
23
|
+
host: string;
|
|
10
24
|
}
|
|
25
|
+
/** The web-client config when both public values are present, else null: an app
|
|
26
|
+
* ships identically with prodantix disabled (no key in the build). */
|
|
27
|
+
declare function prodantixConfig(env: {
|
|
28
|
+
host?: string;
|
|
29
|
+
key?: string;
|
|
30
|
+
}): ActiveConfig | null;
|
|
31
|
+
/**
|
|
32
|
+
* Why this mount will send nothing, or null when it will.
|
|
33
|
+
*
|
|
34
|
+
* Ported from `@bomdisoft/analytics`, where every one of these was a silent
|
|
35
|
+
* return. An app that mounts the provider and ships no events looks exactly like
|
|
36
|
+
* an app that is working, because the component renders null either way and the
|
|
37
|
+
* beacon is the only evidence.
|
|
38
|
+
*/
|
|
39
|
+
declare function skipReason(env: {
|
|
40
|
+
host?: string;
|
|
41
|
+
key?: string;
|
|
42
|
+
}, active: ActiveConfig | null): string | null;
|
|
43
|
+
/** Test seam: the module-level install is deliberately once-per-page-load, so a
|
|
44
|
+
* test needs a way back to a clean slate. */
|
|
45
|
+
declare function resetProdantixForTest(): void;
|
|
11
46
|
declare const ProdantixProvider: ({ children, options }: ProdantixProviderProps) => react.JSX.Element;
|
|
12
47
|
/** The page's client, or null on the server, before the provider's effect has
|
|
13
48
|
* run, or outside a provider. */
|
|
14
49
|
declare const useProdantix: () => ProdantixClient | null;
|
|
50
|
+
/** The messenger, for a site that wants its own button to open it. Null until
|
|
51
|
+
* the project's configuration has been read and says enabled, so a caller must
|
|
52
|
+
* handle that rather than assume a handle exists. */
|
|
53
|
+
declare const useMessenger: () => MessengerHandle | null;
|
|
15
54
|
|
|
16
|
-
export { ProdantixProvider, type ProdantixProviderProps, useProdantix };
|
|
55
|
+
export { type MessengerHandle, type ProdantixOptions, ProdantixProvider, type ProdantixProviderProps, prodantixConfig, resetProdantixForTest, skipReason, useMessenger, useProdantix };
|
package/dist/index.d.ts
CHANGED
|
@@ -4,13 +4,52 @@ import { ProdantixClient } from '@prodantix/sdk';
|
|
|
4
4
|
import { WebClientOptions } from '@prodantix/sdk/web';
|
|
5
5
|
export { WebClientOptions } from '@prodantix/sdk/web';
|
|
6
6
|
|
|
7
|
+
interface ProdantixOptions extends WebClientOptions {
|
|
8
|
+
/** The public browser edge, e.g. `https://eu.edge.prodantix.com`. The
|
|
9
|
+
* messenger appears when this is set AND the project has it switched on in
|
|
10
|
+
* the console; absent, the provider installs analytics only. */
|
|
11
|
+
messengerHost?: string;
|
|
12
|
+
}
|
|
7
13
|
interface ProdantixProviderProps {
|
|
8
14
|
children?: ReactNode;
|
|
9
|
-
options:
|
|
15
|
+
options: ProdantixOptions;
|
|
16
|
+
}
|
|
17
|
+
interface MessengerHandle {
|
|
18
|
+
open(): void;
|
|
19
|
+
close(): void;
|
|
20
|
+
}
|
|
21
|
+
interface ActiveConfig {
|
|
22
|
+
apiKey: string;
|
|
23
|
+
host: string;
|
|
10
24
|
}
|
|
25
|
+
/** The web-client config when both public values are present, else null: an app
|
|
26
|
+
* ships identically with prodantix disabled (no key in the build). */
|
|
27
|
+
declare function prodantixConfig(env: {
|
|
28
|
+
host?: string;
|
|
29
|
+
key?: string;
|
|
30
|
+
}): ActiveConfig | null;
|
|
31
|
+
/**
|
|
32
|
+
* Why this mount will send nothing, or null when it will.
|
|
33
|
+
*
|
|
34
|
+
* Ported from `@bomdisoft/analytics`, where every one of these was a silent
|
|
35
|
+
* return. An app that mounts the provider and ships no events looks exactly like
|
|
36
|
+
* an app that is working, because the component renders null either way and the
|
|
37
|
+
* beacon is the only evidence.
|
|
38
|
+
*/
|
|
39
|
+
declare function skipReason(env: {
|
|
40
|
+
host?: string;
|
|
41
|
+
key?: string;
|
|
42
|
+
}, active: ActiveConfig | null): string | null;
|
|
43
|
+
/** Test seam: the module-level install is deliberately once-per-page-load, so a
|
|
44
|
+
* test needs a way back to a clean slate. */
|
|
45
|
+
declare function resetProdantixForTest(): void;
|
|
11
46
|
declare const ProdantixProvider: ({ children, options }: ProdantixProviderProps) => react.JSX.Element;
|
|
12
47
|
/** The page's client, or null on the server, before the provider's effect has
|
|
13
48
|
* run, or outside a provider. */
|
|
14
49
|
declare const useProdantix: () => ProdantixClient | null;
|
|
50
|
+
/** The messenger, for a site that wants its own button to open it. Null until
|
|
51
|
+
* the project's configuration has been read and says enabled, so a caller must
|
|
52
|
+
* handle that rather than assume a handle exists. */
|
|
53
|
+
declare const useMessenger: () => MessengerHandle | null;
|
|
15
54
|
|
|
16
|
-
export { ProdantixProvider, type ProdantixProviderProps, useProdantix };
|
|
55
|
+
export { type MessengerHandle, 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{createWebClient as
|
|
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};
|
|
3
3
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
"description": "React adapter for the Prodantix SDK: a provider that installs the web client once, StrictMode-safe, and a hook that reads it",
|
|
3
3
|
"devDependencies": {
|
|
4
4
|
"@bomdisoft/typescript-config": "0.0.0",
|
|
5
|
-
"@happy-dom/global-registrator": "^20.
|
|
6
|
-
"@prodantix/sdk": "0.0
|
|
5
|
+
"@happy-dom/global-registrator": "^20.11.6",
|
|
6
|
+
"@prodantix/sdk": "0.1.0",
|
|
7
7
|
"@testing-library/react": "^16.3.2",
|
|
8
|
-
"@types/bun": "^1.
|
|
9
|
-
"@types/react": "^19.2.
|
|
10
|
-
"@types/react-dom": "^19.2.
|
|
11
|
-
"react": "19.2.
|
|
12
|
-
"react-dom": "19.2.
|
|
8
|
+
"@types/bun": "^1.4.0",
|
|
9
|
+
"@types/react": "^19.2.18",
|
|
10
|
+
"@types/react-dom": "^19.2.4",
|
|
11
|
+
"react": "19.2.8",
|
|
12
|
+
"react-dom": "19.2.8",
|
|
13
13
|
"tsup": "8.5.1",
|
|
14
14
|
"typescript": "^6.0.3"
|
|
15
15
|
},
|
|
@@ -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.2-beta.348"
|
|
51
51
|
}
|