@swarm.ing/pieui 2.1.5 → 2.1.6

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.
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- var Z$=Object.create;var{getPrototypeOf:I$,defineProperty:y,getOwnPropertyNames:KU,getOwnPropertyDescriptor:X$}=Object,TU=Object.prototype.hasOwnProperty;var Y$=(U,$,H)=>{H=U!=null?Z$(I$(U)):{};let J=$||!U||!U.__esModule?y(H,"default",{value:U,enumerable:!0}):H;for(let I of KU(U))if(!TU.call(J,I))y(J,I,{get:()=>U[I],enumerable:!0});return J},LU=new WeakMap,z$=(U)=>{var $=LU.get(U),H;if($)return $;if($=y({},"__esModule",{value:!0}),U&&typeof U==="object"||typeof U==="function")KU(U).map((J)=>!TU.call($,J)&&y($,J,{get:()=>U[J],enumerable:!(H=X$(U,J))||H.enumerable}));return LU.set(U,$),$};var G$=(U,$)=>{for(var H in $)y(U,H,{get:$[H],enumerable:!0,configurable:!0,set:(J)=>$[H]=()=>J})};var v$={};G$(v$,{useWebApp:()=>v,useInitData:()=>lU,SecureStorageCard:()=>J$,PieTelegramRoot:()=>eU,CloudStorageCard:()=>$$});module.exports=z$(v$);var x=require("react"),k=require("@tanstack/react-query");var _U=Y$(require("mitt")),h=require("react");var IU=globalThis,Q=(U,$)=>{let H=Symbol.for(U);if(!(H in IU))IU[H]=$();return IU[H]};function qU(){return Q("@swarm.ing/pieui:mitt-emitter",()=>_U.default())}var B$=Q("@swarm.ing/pieui:context:mitt",()=>h.createContext(null));var p=B$;var WU=require("socket.io-client"),VU=require("react");var OU=Q("@swarm.ing/pieui:socket-cache",()=>new Map),RU=(U)=>{let $=OU.get(U);if($)return $;let H=WU.io(U,{autoConnect:!1,transports:["websocket"]});return OU.set(U,H),H},Q$=Q("@swarm.ing/pieui:context:socket",()=>VU.createContext(null)),E=Q$;var AU=require("react"),XU=require("centrifuge");var MU=Q("@swarm.ing/pieui:centrifuge-cache",()=>new Map),EU=(U,$)=>{if(!$)return null;let H=`${U}::${$}`,J=MU.get(H);if(J)return J;async function I(){let X=await fetch(U+"api/centrifuge/gen_token",{credentials:"include"});if(!X.ok){if(X.status===401||X.status===403)throw new XU.Centrifuge.UnauthorizedError("Backend is not answering");throw Error(`Unexpected status code ${X.status}`)}return(await X.json()).token}let Z=new XU.Centrifuge($,{getToken:I});return MU.set(H,Z),Z},D$=Q("@swarm.ing/pieui:context:centrifuge",()=>AU.createContext(null)),j=D$;var r=require("react");var d=require("react"),c=new Map,l=new Map;function u(U,$){let H=`${U}::${$}`,J=U?c.get(H):void 0,[I,Z]=d.useState(J??null);return d.useEffect(()=>{if(!U)return;if(c.has(H)){Z(c.get(H));return}let X=l.get(H);if(!X)X=fetch(U+`api/support/${$}`,{method:"GET"}).then((z)=>z.json()).then((z)=>{return c.set(H,z),l.delete(H),z}).catch((z)=>{throw l.delete(H),z}),l.set(H,X);let B=!1;return X.then((z)=>{if(!B)Z(z)}).catch(()=>{}),()=>{B=!0}},[U,$,H]),I}var o=require("react");var YU=Q("@swarm.ing/pieui:context:pieConfig",()=>o.createContext(null)),s=()=>{let U=o.useContext(YU);if(!U)throw Error("usePieConfig must be used within PieConfigProvider");return U},zU=()=>{let{apiServer:U}=s();return U},n=zU,jU=()=>{let{centrifugeServer:U}=s();return U};var M=()=>{let{enableRenderingLog:U}=s();return U},PU=M,NU=()=>{let{pageProcessor:U}=s();return U};var F$=(U)=>{let $=document.cookie?document.cookie.split(";"):[];for(let H of $){let J=H.indexOf("=");if((J===-1?H:H.slice(0,J)).trim()===U){let Z=J===-1?"":H.slice(J+1).trim();try{return decodeURIComponent(Z)}catch{return Z}}}return null},L$={isClient(){return typeof window<"u"&&typeof document<"u"},readSid(){return typeof window>"u"?void 0:window.sid},setSid(U){if(typeof window<"u")window.sid=U},readWebStorage(U,$){return(U==="local"?window.localStorage:window.sessionStorage).getItem($)},readCookie:F$,readUrlParams(U){return new URLSearchParams(window.location.search).getAll(U)},readDomInput(U){let $=document.getElementsByName(U);if(!$.length)return null;let H=$[0];if(H instanceof HTMLInputElement){if(H.type==="file"&&H.files)return Array.from(H.files);return[H.value]}if(H instanceof HTMLTextAreaElement)return[H.value];return[]},submitGlobalForm(){if(typeof document>"u")return;let U=document.getElementById("piedata_global_form");U&&U.submit()}},wU=L$;var K$={};function A(){return K$}var xU=new Map;var kU=(U)=>{return xU.has(U)?xU.get(U):null};var bU,T$={isClient(){return!0},readSid(){return bU},setSid(U){bU=U},readWebStorage(U,$){let H=A(),J=U==="local"?H.storage:H.sessionStorage;return J?J.getItem($):null},async readWebStorageAsync(U,$){let H=A(),J=U==="local"?H.asyncStorage:H.asyncSessionStorage;if(J)return J.getItem($);let I=U==="local"?H.storage:H.sessionStorage;return I?I.getItem($):null},readCookie(U){let $=A();return $.getCookie?$.getCookie(U):null},readUrlParams(U){let $=A();return $.getRouteParams?$.getRouteParams(U):[]},readDomInput(U){let $=A();return $.getInput?$.getInput(U):kU(U)},submitGlobalForm(){A().submitForm?.()}},yU=T$;var _$=typeof navigator<"u"&&navigator.product==="ReactNative",q$=_$?yU:wU,i=q$;var O$=Q("@swarm.ing/pieui:sid-state",()=>({promise:null,resolve:null}));function fU(){O$.resolve?.()}var W$=({children:U})=>{let $=r.useContext(E),H=n(),J=u(H,"socketIO"),I=(Z)=>{if(i.isClient())i.setSid(Z.sid),fU(),console.log(`SocketIO initialized: ${i.readSid()}`)};return r.useEffect(()=>{if(!$)return;let Z=()=>{console.log("SocketIO connected")},X=(B)=>{console.log(`SocketIO disconnected: ${B}`),$.connect()};if(J)$.on("pieinit",I),$.on("connect",Z),$.on("disconnect",X),$.connect();return()=>{if(J)$.off("pieinit",I),$.off("connect",Z),$.off("disconnect",X),$.disconnect()}},[$,J]),U},CU=W$;var a=require("react");var V$=({children:U})=>{let $=a.useContext(j),H=n(),J=u(H,"centrifuge");return a.useEffect(()=>{if(!$)return;let I=()=>{console.log("Centrifuge connected")},Z=(X)=>{console.log("Centrifuge disconnected:",X)};if(J)$.on("connected",I),$.on("disconnected",Z),$.connect();return()=>{if(J)$.disconnect()}},[$,J]),U},vU=V$;var SU=require("react");var t=require("react/jsx-runtime"),R$=Q("@swarm.ing/pieui:context:fallback",()=>SU.createContext(t.jsx(t.Fragment,{}))),P=R$;var gU=require("react");var M$=Q("@swarm.ing/pieui:context:lazyError",()=>gU.createContext(void 0)),N=M$;var mU=require("react"),f=new Map;function A$(U,$){return $.catch(()=>{if(f.get(U)===$)f.delete(U)}),f.set(U,$),$}function hU(U,$){return mU.lazy(()=>{if(f.has($))return f.get($);return A$($,U().then((H)=>H))})}var pU=Q("@swarm.ing/pieui:component-registry",()=>new Map),E$=(U)=>{if(!U.name)throw Error("Component registration requires a name");if(!U.component&&!U.loader)throw Error(`Component "${U.name}" requires component or loader`);let $={name:U.name,component:U.component,loader:U.loader,metadata:U.metadata,fallback:U.fallback,isLazy:!1};if(!$.component&&$.loader)$.component=hU($.loader,U.name),$.isLazy=!0;return $};function e(U){let $=E$(U);return pU.set($.name,$),$.component}var UU=(U)=>{return pU.get(U)};var C=require("react");var $U=require("react"),cU=require("react/jsx-runtime"),j$=2,P$=400;class w extends $U.Component{state={failed:!1,attempt:0};timer;static getDerivedStateFromError(){return{failed:!0}}componentDidCatch(U){if(this.props.onError?.(U),this.state.attempt<j$){let $=P$*(this.state.attempt+1);this.timer=setTimeout(()=>{this.setState((H)=>({failed:!1,attempt:H.attempt+1}))},$)}}componentDidUpdate(U){if(U.name!==this.props.name&&this.state.attempt!==0)this.setState({failed:!1,attempt:0})}componentWillUnmount(){if(this.timer)clearTimeout(this.timer)}render(){if(this.state.failed)return this.props.fallback;return cU.jsx($U.Suspense,{fallback:this.props.fallback,children:this.props.children},`${this.props.name}:${this.state.attempt}`)}}var HU=require("react/jsx-runtime");function N$({uiConfig:U,setUiAjaxConfiguration:$}){let H=C.useContext(P),J=C.useContext(N),I=M();if(I)console.log("[UI] Rendering component:",U.card),console.log("[UI] Component data:",U.data),console.log("[UI] Component content:",U.content),console.log("[UI] Has setUiAjaxConfiguration:",!!$);let Z=UU(U.card);if(!Z?.component){if(I)console.warn(`[UI] Component not found in registry: ${U.card}`),console.log("[UI] Returning fallback component");return H}if(I)console.log("[UI] Found component in registry:",{name:Z.name,isLazy:Z.isLazy,hasMetadata:!!Z.metadata});let X=Z.component,B=HU.jsx(X,{data:U.data,content:U.content,setUiAjaxConfiguration:$});if(Z.isLazy){if(I)console.log("[UI] Rendering lazy component with Suspense:",Z.name);return HU.jsx(w,{name:Z.name,fallback:Z.fallback?HU.jsx(Z.fallback,{}):H,onError:J,children:B})}if(I)console.log("[UI] Rendering component directly:",Z.name);return B}var GU=C.memo(N$);var tU=require("axios-date-transformer");var JU=require("react");var v=({onError:U}={})=>{let[$,H]=JU.useState(null),J=NU();return JU.useEffect(()=>{if(typeof window>"u")return;let I=window.Telegram?.WebApp;if(!I)return;try{I.ready?.()}catch(Z){U?.()}if(J==="telegram_expanded"&&(I.platform==="ios"||I.platform==="android"))I.expand();H(I)},[]),$},lU=()=>{let U=v();return[U?.initDataUnsafe,U?.initData]};var dU=require("react");var w$=Q("@swarm.ing/pieui:context:navigate",()=>dU.createContext(void 0)),uU=w$;var BU=require("react");var oU=require("react");var x$=Q("@swarm.ing/pieui:context:uiRenderer",()=>oU.createContext(null)),sU=x$;var S=require("react/jsx-runtime");function nU({uiConfig:U,setUiAjaxConfiguration:$}){let H=BU.useContext(P),J=BU.useContext(N),I=M();if(I)console.log("[UILoading] Rendering fallback for:",U.card),console.log("[UILoading] Component data:",U.data),console.log("[UILoading] Component content:",U.content),console.log("[UILoading] Has setUiAjaxConfiguration:",!!$);let Z=UU(U.card);if(!Z?.component){if(I)console.warn(`[UILoading] Component not found in registry: ${U.card}`),console.log("[UILoading] Returning fallback component");return H}if(I)console.log("[UILoading] Found component in registry:",{name:Z.name,isLazy:Z.isLazy,hasMetadata:!!Z.metadata,hasFallback:!!Z.fallback});if(Z.fallback){if(I)console.log("[UILoading] Rendering fallback for:",Z.name);let z=Z.fallback;return S.jsx(z,{})}if(I)console.log("[UILoading] No fallback, rendering full component:",Z.name);let X=Z.component,B=S.jsx(sU.Provider,{value:nU,children:S.jsx(X,{data:U.data,content:U.content,setUiAjaxConfiguration:$})});if(Z.isLazy)return S.jsx(w,{name:Z.name,fallback:H,onError:J,children:B});return B}var iU=nU;var aU=require("react/jsx-runtime");function rU(U,$,H){if(!$)return H;let J=U.replace(/^\//,""),I=$[J];if(!I)return H;return aU.jsx(iU,{uiConfig:I})}var L=require("react/jsx-runtime"),k$=({location:U,fallback:$,piecache:H,onError:J,queryOptions:I,disableGlobalForm:Z})=>{let X=zU(),B=jU(),z=M(),D=x.useMemo(()=>tU.createAxiosDateTransformer({baseURL:X}),[X]),Y=x.useMemo(()=>qU(),[]),V=x.useMemo(()=>X?RU(X):null,[X]),R=x.useMemo(()=>X?EU(X,B):null,[X,B]),T=v({onError:J}),{data:q,isLoading:O,error:G}=k.useQuery({queryKey:["uiConfig",U.pathname+U.search,T?.initData],enabled:!!T?.initData,queryFn:async()=>{let K=new URLSearchParams(U.search);if(K.set("__pieroot","telegram"),T?.initData)K.set("initData",T.initData);let W="/api/content"+U.pathname+"?"+K.toString();if(z)console.log("[PieRoot] Fetching UI configuration from:",W);let FU=await D.get(W,{headers:{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"GET,PUT,POST,DELETE,PATCH,OPTIONS","Content-type":"application/json"},withCredentials:!0});if(z)console.log("[PieRoot] Received UI configuration:",FU.data);return FU.data},staleTime:1/0,gcTime:1/0,refetchOnWindowFocus:!1,refetchOnMount:!1,refetchOnReconnect:!1,retry:!0,retryDelay:(K)=>Math.min(1000*2**K,30000),...I}),F=rU(U.pathname,H,$);if(!X)throw Error("Set PIE_API_SERVER and PIE_CENTRIFUGE_SERVER");if(G&&z)return console.error("[PieRoot] Error fetching UI configuration:",G),console.error("[PieRoot] Error details:",{message:G.message,status:G.response?.status,data:G.response?.data}),J?.(G),F;if(O||!q){if(z)console.log("[PieRoot] Loading state:",{isLoading:O,hasUiConfiguration:!!q});return F}if(z)console.log("[PieRoot] UI configuration loaded successfully:",q),console.log("[PieRoot] Rendering UI with configuration");return L.jsx(p.Provider,{value:Y,children:L.jsx(E.Provider,{value:V,children:L.jsx(j.Provider,{value:R,children:L.jsx(P.Provider,{value:$??L.jsx(L.Fragment,{}),children:L.jsx(CU,{children:L.jsx(vU,{children:Z?L.jsx(GU,{uiConfig:q}):L.jsx("form",{id:"piedata_global_form",action:X+"api/process"+U.pathname,method:"post",encType:"multipart/form-data",children:L.jsx(GU,{uiConfig:q})})})})})})})})},b$=(U)=>{let $=x.useMemo(()=>new k.QueryClient,[]),H=U.queryClient??$;return L.jsx(uU.Provider,{value:U.onNavigate,children:L.jsx(YU.Provider,{value:U.config,children:L.jsx(N.Provider,{value:U.onError,children:L.jsx(k.QueryClientProvider,{client:H,children:L.jsx(k$,{...U})})})})})},eU=b$;var g=require("react");var _=require("react");var b=require("react/jsx-runtime"),y$=({card:U,data:$,children:H,useSocketioSupport:J=!1,useCentrifugeSupport:I=!1,useMittSupport:Z=!1,centrifugeChannel:X=void 0,methods:B=void 0,stored:z=void 0})=>{let D=PU(),Y=_.useRef(B);if(Y.current=B,D)console.log("[PieCard] Rendering card:",U),console.log("[PieCard] Card data:",$),console.log("[PieCard] Component name:",$?.name),console.log("[PieCard] Real-time support:",{socketio:J,centrifuge:I,mitt:Z,centrifugeChannel:X}),console.log("[PieCard] Methods:",B?Object.keys(B):"none"),console.log("[PieCard] Has children:",!!H);let V=_.useContext(E),R=_.useContext(j),T=_.useContext(p);if(_.useEffect(()=>{if(!V||!J||!Y.current||!$.name){if(D&&J)console.log("[PieCard] Socket.IO setup skipped:",{hasSocket:!!V,useSocketioSupport:J,hasMethods:!!Y.current,hasDataName:!!$?.name});return}let O=Object.keys(Y.current??{}).map((G)=>{let F=`pie${G}_${$.name}`;if(D)console.log(`[PieCard] Socket.IO registering event: ${F}`);let K=(W)=>{Y.current?.[G]?.(W)};return V.on(F,K),[F,K]});return()=>{O.forEach(([G,F])=>{if(D)console.log(`[PieCard] Socket.IO unregistering event: ${G}`);V.off(G,F)})}},[V,$.name,J]),_.useEffect(()=>{if(!R||!I||!X||!$.name){if(D&&I)console.log("[PieCard] Centrifuge setup skipped:",{hasCentrifuge:!!R,useCentrifugeSupport:I,hasCentrifugeChannel:!!X,hasMethods:!!Y.current,hasDataName:!!$?.name});return}let O=Object.keys(Y.current??{}).map((G)=>{let F=`pie${G}_${$.name}_${X}`;if(D)console.log(`[PieCard] Centrifuge subscribing to channel: ${F}`);let K=R.newSubscription(F);return K.on("publication",(W)=>{if(D)console.log(`[PieCard] Centrifuge received data on ${F}:`,W.data);Y.current?.[G]?.(W.data)}),K.subscribe(),K});return()=>{O.forEach((G)=>{if(D)console.log("[PieCard] Centrifuge unsubscribing from channel");G.unsubscribe(),R.removeSubscription(G)})}},[R,X,$.name,I]),_.useEffect(()=>{if(!T||!Z||!$.name){if(D&&Z)console.log("[PieCard] Mitt setup skipped:",{hasMitt:!!T,useMittSupport:Z,hasMethods:!!Y.current,hasDataName:!!$?.name});return}let q=Object.keys(Y.current??{}),O={};return q.forEach((G)=>{let F=`pie${G}_${$.name}`,K=(W)=>{if(D)console.log(`[PieCard] Mitt registering event: ${F}`);Y.current?.[G]?.(W)};O[F]=K,T.on(F,K)}),()=>{Object.entries(O).forEach(([G,F])=>{if(D)console.log(`[PieCard] Mitt unregistering event: ${G}`);T.off(G,F)})}},[T,$.name,Z]),D)console.log("[PieCard] Rendering complete, returning children");if(z!==void 0)return b.jsxs(b.Fragment,{children:[b.jsx("input",{type:"hidden",name:$.name,value:JSON.stringify(z)}),H]});return H},ZU=y$;var QU=require("react/jsx-runtime"),f$=({data:U})=>{let{name:$,key:H,value:J,useSocketioSupport:I,useCentrifugeSupport:Z,useMittSupport:X,centrifugeChannel:B}=U,[z,D]=g.useState(J);return g.useEffect(()=>{D(J)},[J]),g.useEffect(()=>{if(typeof window>"u")return;let Y=window.Telegram?.WebApp?.CloudStorage;if(!Y)return;Y.setItem(H,z)},[H,z]),QU.jsx(ZU,{card:"CloudStorageCard",data:U,useSocketioSupport:I,useCentrifugeSupport:Z,useMittSupport:X,centrifugeChannel:B,methods:{update:({value:Y})=>{D(Y)},remove:()=>{let Y=window.Telegram?.WebApp?.CloudStorage;if(Y)Y.removeItem(H);D("")}},children:QU.jsx("input",{type:"hidden",id:$,name:$,value:z})})},U$=f$;var $$=e({name:"CloudStorageCard",component:U$,metadata:{author:"PieData"}});var m=require("react");var DU=require("react/jsx-runtime"),C$=({data:U})=>{let{name:$,key:H,value:J,useSocketioSupport:I,useCentrifugeSupport:Z,useMittSupport:X,centrifugeChannel:B}=U,[z,D]=m.useState(J);return m.useEffect(()=>{D(J)},[J]),m.useEffect(()=>{if(typeof window>"u")return;let Y=window.Telegram?.WebApp?.SecureStorage;if(!Y)return;Y.setItem(H,z)},[H,z]),DU.jsx(ZU,{card:"SecureStorageCard",data:U,useSocketioSupport:I,useCentrifugeSupport:Z,useMittSupport:X,centrifugeChannel:B,methods:{update:({value:Y})=>{D(Y)},remove:()=>{let Y=window.Telegram?.WebApp?.SecureStorage;if(Y)Y.removeItem(H);D("")}},children:DU.jsx("input",{type:"hidden",id:$,name:$,value:z})})},H$=C$;var J$=e({name:"SecureStorageCard",component:H$,metadata:{author:"PieData"}});
2
+ var Y$=Object.create;var{getPrototypeOf:z$,defineProperty:y,getOwnPropertyNames:KU,getOwnPropertyDescriptor:G$}=Object,LU=Object.prototype.hasOwnProperty;var B$=(U,$,H)=>{H=U!=null?Y$(z$(U)):{};let I=$||!U||!U.__esModule?y(H,"default",{value:U,enumerable:!0}):H;for(let Z of KU(U))if(!LU.call(I,Z))y(I,Z,{get:()=>U[Z],enumerable:!0});return I},TU=new WeakMap,Q$=(U)=>{var $=TU.get(U),H;if($)return $;if($=y({},"__esModule",{value:!0}),U&&typeof U==="object"||typeof U==="function")KU(U).map((I)=>!LU.call($,I)&&y($,I,{get:()=>U[I],enumerable:!(H=G$(U,I))||H.enumerable}));return TU.set(U,$),$};var _$=(U,$)=>{for(var H in $)y(U,H,{get:$[H],enumerable:!0,configurable:!0,set:(I)=>$[H]=()=>I})};var g$={};_$(g$,{useWebApp:()=>S,useInitData:()=>lU,SecureStorageCard:()=>X$,PieTelegramRoot:()=>U$,CloudStorageCard:()=>J$});module.exports=Q$(g$);var k=require("react"),b=require("@tanstack/react-query");var qU=B$(require("mitt")),d=require("react");var YU=globalThis,Q=(U,$)=>{let H=Symbol.for(U);if(!(H in YU))YU[H]=$();return YU[H]};function OU(){return Q("@swarm.ing/pieui:mitt-emitter",()=>qU.default())}var D$=Q("@swarm.ing/pieui:context:mitt",()=>d.createContext(null));var c=D$;var VU=require("socket.io-client"),MU=require("react");var WU=Q("@swarm.ing/pieui:socket-cache",()=>new Map),AU=(U)=>{let $=WU.get(U);if($)return $;let H=VU.io(U,{autoConnect:!1,transports:["websocket"]});return WU.set(U,H),H},F$=Q("@swarm.ing/pieui:context:socket",()=>MU.createContext(null)),P=F$;var RU=require("react"),zU=require("centrifuge");var EU=Q("@swarm.ing/pieui:centrifuge-cache",()=>new Map),PU=(U,$)=>{if(!$)return null;let H=`${U}::${$}`,I=EU.get(H);if(I)return I;async function Z(){let X=await fetch(U+"api/centrifuge/gen_token",{credentials:"include"});if(!X.ok){if(X.status===401||X.status===403)throw new zU.Centrifuge.UnauthorizedError("Backend is not answering");throw Error(`Unexpected status code ${X.status}`)}return(await X.json()).token}let J=new zU.Centrifuge($,{getToken:Z});return EU.set(H,J),J},T$=Q("@swarm.ing/pieui:context:centrifuge",()=>RU.createContext(null)),j=T$;var t=require("react");var o=require("react"),l=new Map,u=new Map;function s(U,$){let H=`${U}::${$}`,I=U?l.get(H):void 0,[Z,J]=o.useState(I??null);return o.useEffect(()=>{if(!U)return;if(l.has(H)){J(l.get(H));return}let X=u.get(H);if(!X)X=fetch(U+`api/support/${$}`,{method:"GET"}).then((z)=>z.json()).then((z)=>{return l.set(H,z),u.delete(H),z}).catch((z)=>{throw u.delete(H),z}),u.set(H,X);let G=!1;return X.then((z)=>{if(!G)J(z)}).catch(()=>{}),()=>{G=!0}},[U,$,H]),Z}var n=require("react");var GU=Q("@swarm.ing/pieui:context:pieConfig",()=>n.createContext(null)),i=()=>{let U=n.useContext(GU);if(!U)throw Error("usePieConfig must be used within PieConfigProvider");return U},BU=()=>{let{apiServer:U}=i();return U},r=BU,jU=()=>{let{centrifugeServer:U}=i();return U};var E=()=>{let{enableRenderingLog:U}=i();return U},NU=E,wU=()=>{let{pageProcessor:U}=i();return U};var K$=(U)=>{let $=document.cookie?document.cookie.split(";"):[];for(let H of $){let I=H.indexOf("=");if((I===-1?H:H.slice(0,I)).trim()===U){let J=I===-1?"":H.slice(I+1).trim();try{return decodeURIComponent(J)}catch{return J}}}return null},L$={isClient(){return typeof window<"u"&&typeof document<"u"},readSid(){return typeof window>"u"?void 0:window.sid},setSid(U){if(typeof window<"u")window.sid=U},readWebStorage(U,$){return(U==="local"?window.localStorage:window.sessionStorage).getItem($)},readCookie:K$,readUrlParams(U){return new URLSearchParams(window.location.search).getAll(U)},readDomInput(U){let $=document.getElementsByName(U);if(!$.length)return null;let H=$[0];if(H instanceof HTMLInputElement){if(H.type==="file"&&H.files)return Array.from(H.files);return[H.value]}if(H instanceof HTMLTextAreaElement)return[H.value];return[]},submitGlobalForm(){if(typeof document>"u")return;let U=document.getElementById("piedata_global_form");U&&U.submit()}},xU=L$;var q$={};function R(){return q$}var kU=new Map;var bU=(U)=>{return kU.has(U)?kU.get(U):null};var fU,O$={isClient(){return!0},readSid(){return fU},setSid(U){fU=U},readWebStorage(U,$){let H=R(),I=U==="local"?H.storage:H.sessionStorage;return I?I.getItem($):null},async readWebStorageAsync(U,$){let H=R(),I=U==="local"?H.asyncStorage:H.asyncSessionStorage;if(I)return I.getItem($);let Z=U==="local"?H.storage:H.sessionStorage;return Z?Z.getItem($):null},readCookie(U){let $=R();return $.getCookie?$.getCookie(U):null},readUrlParams(U){let $=R();return $.getRouteParams?$.getRouteParams(U):[]},readDomInput(U){let $=R();return $.getInput?$.getInput(U):bU(U)},submitGlobalForm(){R().submitForm?.()}},yU=O$;var W$=typeof navigator<"u"&&navigator.product==="ReactNative",V$=W$?yU:xU,a=V$;var M$=Q("@swarm.ing/pieui:sid-state",()=>({promise:null,resolve:null}));function CU(){M$.resolve?.()}var A$=({children:U})=>{let $=t.useContext(P),H=r(),I=s(H,"socketIO"),Z=(J)=>{if(a.isClient())a.setSid(J.sid),CU(),console.log(`SocketIO initialized: ${a.readSid()}`)};return t.useEffect(()=>{if(!$)return;let J=()=>{console.log("SocketIO connected")},X=(G)=>{console.log(`SocketIO disconnected: ${G}`),$.connect()};if(I)$.on("pieinit",Z),$.on("connect",J),$.on("disconnect",X),$.connect();return()=>{if(I)$.off("pieinit",Z),$.off("connect",J),$.off("disconnect",X),$.disconnect()}},[$,I]),U},vU=A$;var e=require("react");var E$=({children:U})=>{let $=e.useContext(j),H=r(),I=s(H,"centrifuge");return e.useEffect(()=>{if(!$)return;let Z=()=>{console.log("Centrifuge connected")},J=(X)=>{console.log("Centrifuge disconnected:",X)};if(I)$.on("connected",Z),$.on("disconnected",J),$.connect();return()=>{if(I)$.disconnect()}},[$,I]),U},SU=E$;var mU=require("react");var UU=require("react/jsx-runtime"),R$=Q("@swarm.ing/pieui:context:fallback",()=>mU.createContext(UU.jsx(UU.Fragment,{}))),N=R$;var gU=require("react");var P$=Q("@swarm.ing/pieui:context:lazyError",()=>gU.createContext(void 0)),w=P$;var hU=require("react"),C=new Map;function j$(U,$){return $.catch(()=>{if(C.get(U)===$)C.delete(U)}),C.set(U,$),$}function pU(U,$){return hU.lazy(()=>{if(C.has($))return C.get($);return j$($,U().then((H)=>H))})}var dU=Q("@swarm.ing/pieui:component-registry",()=>new Map),N$=(U)=>{if(!U.name)throw Error("Component registration requires a name");if(!U.component&&!U.loader)throw Error(`Component "${U.name}" requires component or loader`);let $={name:U.name,component:U.component,loader:U.loader,metadata:U.metadata,fallback:U.fallback,isLazy:!1};if(!$.component&&$.loader)$.component=pU($.loader,U.name),$.isLazy=!0;return $};function $U(U){let $=N$(U);return dU.set($.name,$),$.component}var HU=(U)=>{return dU.get(U)};var v=require("react");var IU=require("react"),cU=require("react/jsx-runtime"),w$=2,x$=400;class x extends IU.Component{state={failed:!1,attempt:0};timer;static getDerivedStateFromError(){return{failed:!0}}componentDidCatch(U){if(this.props.onError?.(U),this.state.attempt<w$){let $=x$*(this.state.attempt+1);this.timer=setTimeout(()=>{this.setState((H)=>({failed:!1,attempt:H.attempt+1}))},$)}}componentDidUpdate(U){if(U.name!==this.props.name&&this.state.attempt!==0)this.setState({failed:!1,attempt:0})}componentWillUnmount(){if(this.timer)clearTimeout(this.timer)}render(){if(this.state.failed)return this.props.fallback;return cU.jsx(IU.Suspense,{fallback:this.props.fallback,children:this.props.children},`${this.props.name}:${this.state.attempt}`)}}var JU=require("react/jsx-runtime");function k$({uiConfig:U,setUiAjaxConfiguration:$}){let H=v.useContext(N),I=v.useContext(w),Z=E();if(Z)console.log("[UI] Rendering component:",U.card),console.log("[UI] Component data:",U.data),console.log("[UI] Component content:",U.content),console.log("[UI] Has setUiAjaxConfiguration:",!!$);let J=HU(U.card);if(!J?.component){if(Z)console.warn(`[UI] Component not found in registry: ${U.card}`),console.log("[UI] Returning fallback component");return H}if(Z)console.log("[UI] Found component in registry:",{name:J.name,isLazy:J.isLazy,hasMetadata:!!J.metadata});let X=J.component,G=JU.jsx(X,{data:U.data,content:U.content,setUiAjaxConfiguration:$});if(J.isLazy){if(Z)console.log("[UI] Rendering lazy component with Suspense:",J.name);return JU.jsx(x,{name:J.name,fallback:J.fallback?JU.jsx(J.fallback,{}):H,onError:I,children:G})}if(Z)console.log("[UI] Rendering component directly:",J.name);return G}var QU=v.memo(k$);var eU=require("axios-date-transformer");var ZU=require("react");var S=({onError:U}={})=>{let[$,H]=ZU.useState(null),I=wU();return ZU.useEffect(()=>{if(typeof window>"u")return;let Z=window.Telegram?.WebApp;if(!Z)return;try{Z.ready?.()}catch(J){U?.()}if(I==="telegram_expanded"&&(Z.platform==="ios"||Z.platform==="android"))Z.expand();H(Z)},[]),$},lU=()=>{let U=S();return[U?.initDataUnsafe,U?.initData]};var uU=require("react");var b$=Q("@swarm.ing/pieui:context:navigate",()=>uU.createContext(void 0)),oU=b$;var _U=require("react");var sU=require("react");var f$=Q("@swarm.ing/pieui:context:uiRenderer",()=>sU.createContext(null)),nU=f$;var m=require("react/jsx-runtime");function iU({uiConfig:U,setUiAjaxConfiguration:$}){let H=_U.useContext(N),I=_U.useContext(w),Z=E();if(Z)console.log("[UILoading] Rendering fallback for:",U.card),console.log("[UILoading] Component data:",U.data),console.log("[UILoading] Component content:",U.content),console.log("[UILoading] Has setUiAjaxConfiguration:",!!$);let J=HU(U.card);if(!J?.component){if(Z)console.warn(`[UILoading] Component not found in registry: ${U.card}`),console.log("[UILoading] Returning fallback component");return H}if(Z)console.log("[UILoading] Found component in registry:",{name:J.name,isLazy:J.isLazy,hasMetadata:!!J.metadata,hasFallback:!!J.fallback});if(J.fallback){if(Z)console.log("[UILoading] Rendering fallback for:",J.name);let z=J.fallback;return m.jsx(z,{})}if(Z)console.log("[UILoading] No fallback, rendering full component:",J.name);let X=J.component,G=m.jsx(nU.Provider,{value:iU,children:m.jsx(X,{data:U.data,content:U.content,setUiAjaxConfiguration:$})});if(J.isLazy)return m.jsx(x,{name:J.name,fallback:H,onError:I,children:G});return G}var rU=iU;var tU=require("react/jsx-runtime");function aU(U,$,H){if(!$)return H;let I=U.replace(/^\//,""),Z=$[I];if(!Z)return H;return tU.jsx(rU,{uiConfig:Z})}var D=require("react/jsx-runtime"),y$=({location:U,fallback:$,piecache:H,onError:I,queryOptions:Z,disableGlobalForm:J})=>{let X=BU(),G=jU(),z=E(),K=k.useMemo(()=>eU.createAxiosDateTransformer({baseURL:X}),[X]),Y=k.useMemo(()=>OU(),[]),F=k.useMemo(()=>X?AU(X):null,[X]),p=k.useMemo(()=>X?PU(X,G):null,[X,G]),O=S({onError:I}),{data:L,isLoading:A,error:W}=b.useQuery({queryKey:["uiConfig",U.pathname+U.search,O?.initData],enabled:!!O?.initData,queryFn:async()=>{let B=new URLSearchParams(U.search);if(B.set("__pieroot","telegram"),O?.initData)B.set("initData",O.initData);let _="/api/content"+U.pathname+"?"+B.toString();if(z)console.log("[PieRoot] Fetching UI configuration from:",_);let T=await K.get(_,{headers:{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"GET,PUT,POST,DELETE,PATCH,OPTIONS","Content-type":"application/json"},withCredentials:!0});if(z)console.log("[PieRoot] Received UI configuration:",T.data);return T.data},staleTime:1/0,gcTime:1/0,refetchOnWindowFocus:!1,refetchOnMount:!1,refetchOnReconnect:!1,retry:!0,retryDelay:(B)=>Math.min(1000*2**B,30000),...Z}),V=aU(U.pathname,H,$);if(!X)throw Error("Set PIE_API_SERVER and PIE_CENTRIFUGE_SERVER");if(W&&z)return console.error("[PieRoot] Error fetching UI configuration:",W),console.error("[PieRoot] Error details:",{message:W.message,status:W.response?.status,data:W.response?.data}),I?.(W),V;if(A||!L){if(z)console.log("[PieRoot] Loading state:",{isLoading:A,hasUiConfiguration:!!L});return V}if(z)console.log("[PieRoot] UI configuration loaded successfully:",L),console.log("[PieRoot] Rendering UI with configuration");return D.jsx(c.Provider,{value:Y,children:D.jsx(P.Provider,{value:F,children:D.jsx(j.Provider,{value:p,children:D.jsx(N.Provider,{value:$??D.jsx(D.Fragment,{}),children:D.jsx(vU,{children:D.jsx(SU,{children:J?D.jsx(QU,{uiConfig:L}):D.jsx("form",{id:"piedata_global_form",action:X+"api/process"+U.pathname,method:"post",encType:"multipart/form-data",children:D.jsx(QU,{uiConfig:L})})})})})})})})},C$=(U)=>{let $=k.useMemo(()=>new b.QueryClient,[]),H=U.queryClient??$;return D.jsx(oU.Provider,{value:U.onNavigate,children:D.jsx(GU.Provider,{value:U.config,children:D.jsx(w.Provider,{value:U.onError,children:D.jsx(b.QueryClientProvider,{client:H,children:D.jsx(y$,{...U})})})})})},U$=C$;var g=require("react");var q=require("react");function $$(U){return U.wasRecovering===!0&&U.recovered===!1}function H$(U){return U.recoverable===!1}var f=require("react/jsx-runtime"),v$=({card:U,data:$,children:H,useSocketioSupport:I=!1,useCentrifugeSupport:Z=!1,useMittSupport:J=!1,centrifugeChannel:X=void 0,methods:G=void 0,stored:z=void 0,onResync:K=void 0})=>{let Y=NU(),F=q.useRef(G);F.current=G;let p=q.useRef(K);if(p.current=K,Y)console.log("[PieCard] Rendering card:",U),console.log("[PieCard] Card data:",$),console.log("[PieCard] Component name:",$?.name),console.log("[PieCard] Real-time support:",{socketio:I,centrifuge:Z,mitt:J,centrifugeChannel:X}),console.log("[PieCard] Methods:",G?Object.keys(G):"none"),console.log("[PieCard] Has children:",!!H);let O=q.useContext(P),L=q.useContext(j),A=q.useContext(c);if(q.useEffect(()=>{if(!O||!I||!F.current||!$.name){if(Y&&I)console.log("[PieCard] Socket.IO setup skipped:",{hasSocket:!!O,useSocketioSupport:I,hasMethods:!!F.current,hasDataName:!!$?.name});return}let V=Object.keys(F.current??{}).map((B)=>{let _=`pie${B}_${$.name}`;if(Y)console.log(`[PieCard] Socket.IO registering event: ${_}`);let T=(M)=>{F.current?.[B]?.(M)};return O.on(_,T),[_,T]});return()=>{V.forEach(([B,_])=>{if(Y)console.log(`[PieCard] Socket.IO unregistering event: ${B}`);O.off(B,_)})}},[O,$.name,I]),q.useEffect(()=>{if(!L||!Z||!X||!$.name){if(Y&&Z)console.log("[PieCard] Centrifuge setup skipped:",{hasCentrifuge:!!L,useCentrifugeSupport:Z,hasCentrifugeChannel:!!X,hasMethods:!!F.current,hasDataName:!!$?.name});return}let V=Object.keys(F.current??{}).map((B)=>{let _=`pie${B}_${$.name}_${X}`;if(Y)console.log(`[PieCard] Centrifuge subscribing to channel: ${_}`);let T=L.newSubscription(_,{recoverable:!0,positioned:!0});return T.on("publication",(M)=>{if(Y)console.log(`[PieCard] Centrifuge received data on ${_}:`,M.data);F.current?.[B]?.(M.data)}),T.on("subscribed",(M)=>{if(H$(M))console.warn(`[PieCard] Centrifuge channel ${_} is not `+"recoverable — enable history on the server "+"namespace for exact replay; relying on resync fallback only.");if($$(M)){if(Y)console.log(`[PieCard] Centrifuge recovery gap on ${_}; requesting resync`);p.current?.({channel:_,reason:"gap"})}}),T.subscribe(),T});return()=>{V.forEach((B)=>{if(Y)console.log("[PieCard] Centrifuge unsubscribing from channel");B.unsubscribe(),L.removeSubscription(B)})}},[L,X,$.name,Z]),q.useEffect(()=>{if(!A||!J||!$.name){if(Y&&J)console.log("[PieCard] Mitt setup skipped:",{hasMitt:!!A,useMittSupport:J,hasMethods:!!F.current,hasDataName:!!$?.name});return}let W=Object.keys(F.current??{}),V={};return W.forEach((B)=>{let _=`pie${B}_${$.name}`,T=(M)=>{if(Y)console.log(`[PieCard] Mitt registering event: ${_}`);F.current?.[B]?.(M)};V[_]=T,A.on(_,T)}),()=>{Object.entries(V).forEach(([B,_])=>{if(Y)console.log(`[PieCard] Mitt unregistering event: ${B}`);A.off(B,_)})}},[A,$.name,J]),Y)console.log("[PieCard] Rendering complete, returning children");if(z!==void 0)return f.jsxs(f.Fragment,{children:[f.jsx("input",{type:"hidden",name:$.name,value:JSON.stringify(z)}),H]});return H},XU=v$;var DU=require("react/jsx-runtime"),S$=({data:U})=>{let{name:$,key:H,value:I,useSocketioSupport:Z,useCentrifugeSupport:J,useMittSupport:X,centrifugeChannel:G}=U,[z,K]=g.useState(I);return g.useEffect(()=>{K(I)},[I]),g.useEffect(()=>{if(typeof window>"u")return;let Y=window.Telegram?.WebApp?.CloudStorage;if(!Y)return;Y.setItem(H,z)},[H,z]),DU.jsx(XU,{card:"CloudStorageCard",data:U,useSocketioSupport:Z,useCentrifugeSupport:J,useMittSupport:X,centrifugeChannel:G,methods:{update:({value:Y})=>{K(Y)},remove:()=>{let Y=window.Telegram?.WebApp?.CloudStorage;if(Y)Y.removeItem(H);K("")}},children:DU.jsx("input",{type:"hidden",id:$,name:$,value:z})})},I$=S$;var J$=$U({name:"CloudStorageCard",component:I$,metadata:{author:"PieData"}});var h=require("react");var FU=require("react/jsx-runtime"),m$=({data:U})=>{let{name:$,key:H,value:I,useSocketioSupport:Z,useCentrifugeSupport:J,useMittSupport:X,centrifugeChannel:G}=U,[z,K]=h.useState(I);return h.useEffect(()=>{K(I)},[I]),h.useEffect(()=>{if(typeof window>"u")return;let Y=window.Telegram?.WebApp?.SecureStorage;if(!Y)return;Y.setItem(H,z)},[H,z]),FU.jsx(XU,{card:"SecureStorageCard",data:U,useSocketioSupport:Z,useCentrifugeSupport:J,useMittSupport:X,centrifugeChannel:G,methods:{update:({value:Y})=>{K(Y)},remove:()=>{let Y=window.Telegram?.WebApp?.SecureStorage;if(Y)Y.removeItem(H);K("")}},children:FU.jsx("input",{type:"hidden",id:$,name:$,value:z})})},Z$=m$;var X$=$U({name:"SecureStorageCard",component:Z$,metadata:{author:"PieData"}});
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=centrifugeRecovery.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"centrifugeRecovery.test.d.ts","sourceRoot":"","sources":["../../src/tests/centrifugeRecovery.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=piecardRecovery.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"piecardRecovery.test.d.ts","sourceRoot":"","sources":["../../src/tests/piecardRecovery.test.ts"],"names":[],"mappings":""}
@@ -10,6 +10,11 @@ import { Centrifuge } from 'centrifuge';
10
10
  * calls with the same arguments always return the same instance — which is
11
11
  * important because `Centrifuge` holds a live WebSocket connection.
12
12
  *
13
+ * Message recovery (exact replay of missed publications on reconnect)
14
+ * requires history retention on the server namespace — see
15
+ * `docs/realtime-recovery.md`. PieCard requests recoverable subscriptions and
16
+ * provides a resync fallback for gaps the history buffer cannot cover.
17
+ *
13
18
  * @param apiServer Base URL of the PieUI API server (must end with `/`).
14
19
  * @param centrifugeServer WebSocket URL of the Centrifuge server. When
15
20
  * omitted, the function returns `null` and the
@@ -1 +1 @@
1
- {"version":3,"file":"centrifuge.d.ts","sourceRoot":"","sources":["../../src/util/centrifuge.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAQvC;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,aAAa,GACtB,WAAW,MAAM,EACjB,mBAAmB,MAAM,KAC1B,UAAU,GAAG,IAgCf,CAAA;AAED;;;;GAIG;AACH,QAAA,MAAM,mBAAmB,4CAGxB,CAAA;AACD,eAAe,mBAAmB,CAAA"}
1
+ {"version":3,"file":"centrifuge.d.ts","sourceRoot":"","sources":["../../src/util/centrifuge.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAQvC;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,aAAa,GACtB,WAAW,MAAM,EACjB,mBAAmB,MAAM,KAC1B,UAAU,GAAG,IAgCf,CAAA;AAED;;;;GAIG;AACH,QAAA,MAAM,mBAAmB,4CAGxB,CAAA;AACD,eAAe,mBAAmB,CAAA"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Subset of the Centrifuge `subscribed` event context relevant to message
3
+ * recovery. Mirrors the fields centrifuge-js v5 sets on resubscribe
4
+ * (see `SubscribedContext` in `centrifuge/build/types.d.ts`).
5
+ */
6
+ export interface RecoveryContext {
7
+ /** subscription is recoverable – server has history for this channel. */
8
+ recoverable?: boolean;
9
+ /** true when this `subscribed` followed a recovery attempt (a reconnect). */
10
+ wasRecovering?: boolean;
11
+ /** whether the recovery attempt restored the full missed stream. */
12
+ recovered?: boolean;
13
+ }
14
+ /**
15
+ * Returns true when a resubscribe tried to recover missed publications and
16
+ * failed — i.e. there is a gap the client could not fill, so the consumer
17
+ * must resync full state to avoid staying stale.
18
+ */
19
+ export declare function shouldResync(ctx: RecoveryContext): boolean;
20
+ /**
21
+ * Returns true when the server explicitly reports the channel as
22
+ * non-recoverable. In that case exact replay is impossible (no history
23
+ * configured) and only the resync fallback can prevent event loss.
24
+ */
25
+ export declare function isUnrecoverableChannel(ctx: RecoveryContext): boolean;
26
+ //# sourceMappingURL=centrifugeRecovery.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"centrifugeRecovery.d.ts","sourceRoot":"","sources":["../../src/util/centrifugeRecovery.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC5B,yEAAyE;IACzE,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,6EAA6E;IAC7E,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,oEAAoE;IACpE,SAAS,CAAC,EAAE,OAAO,CAAA;CACtB;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,eAAe,GAAG,OAAO,CAE1D;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,eAAe,GAAG,OAAO,CAEpE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swarm.ing/pieui",
3
- "version": "2.1.5",
3
+ "version": "2.1.6",
4
4
  "description": "A React component library featuring PieCard component",
5
5
  "repository": {
6
6
  "type": "git",