tokentracker-cli 1.3.4 → 1.3.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.
- package/README.de.md +5 -5
- package/README.ja.md +3 -3
- package/README.ko.md +3 -3
- package/README.md +6 -5
- package/README.zh-CN.md +3 -3
- package/dashboard/dist/assets/{AchievementBadge-CKjtQp-U.js → AchievementBadge-Dazs3pEa.js} +1 -1
- package/dashboard/dist/assets/{AchievementsPage-DpOXrabE.js → AchievementsPage-LWnxZvmw.js} +2 -2
- package/dashboard/dist/assets/{AchievementsSection-DiXyIoa0.js → AchievementsSection-BLqczmU9.js} +1 -1
- package/dashboard/dist/assets/{BadgeDetailModal-CILTTkPF.js → BadgeDetailModal-B_n4aj2S.js} +1 -1
- package/dashboard/dist/assets/{BotAnimated-CrBHWiRi.js → BotAnimated-KDWI_YcZ.js} +1 -1
- package/dashboard/dist/assets/{Card-DUItW3xI.js → Card-BYoxd4OC.js} +1 -1
- package/dashboard/dist/assets/{CloudCheckoutPage-C_t_PDlG.js → CloudCheckoutPage-BR2_B03P.js} +1 -1
- package/dashboard/dist/assets/{CloudPage-pvJUrhya.js → CloudPage-DL5RkJKK.js} +1 -1
- package/dashboard/dist/assets/{CloudUsageExport-DQbDwiyk.js → CloudUsageExport-C_DqZKo1.js} +1 -1
- package/dashboard/dist/assets/{CommandPalette-BvHilrbV.js → CommandPalette-DkCaIQI4.js} +1 -1
- package/dashboard/dist/assets/{CommunityStatsModal-CizxEYv-.js → CommunityStatsModal-pX9OePi4.js} +1 -1
- package/dashboard/dist/assets/{ConfirmModal-h9nISVy7.js → ConfirmModal-tkgZwz4u.js} +1 -1
- package/dashboard/dist/assets/{Controls-BjdIonTX.js → Controls-MTUhGWy8.js} +1 -1
- package/dashboard/dist/assets/{DashboardPage-Bxryr4qp.js → DashboardPage-SOx-A7lH.js} +1 -1
- package/dashboard/dist/assets/{DateRangePopover-DpKh-0l8.js → DateRangePopover-B-BMOm3O.js} +1 -1
- package/dashboard/dist/assets/{DevicePage-DUJR9hJC.js → DevicePage-DSK9lm7v.js} +1 -1
- package/dashboard/dist/assets/{DialogClose-BmVAmN-o.js → DialogClose-uVUNu4rg.js} +1 -1
- package/dashboard/dist/assets/DialogDescription-DBqGGWNj.js +1 -0
- package/dashboard/dist/assets/{DialogTitle-BsaIbN8k.js → DialogTitle-B-VifiA3.js} +1 -1
- package/dashboard/dist/assets/{FadeIn-BpSt2P_W.js → FadeIn-B6lrj4uo.js} +1 -1
- package/dashboard/dist/assets/{HeaderGithubStar-Cc_VHB0R.js → HeaderGithubStar-Cx5zOhXa.js} +1 -1
- package/dashboard/dist/assets/{HoverTooltip-WFd21iP9.js → HoverTooltip-DY1ENf69.js} +1 -1
- package/dashboard/dist/assets/{IpCheckPage-C_mUPSRB.js → IpCheckPage-D6TEq64d.js} +1 -1
- package/dashboard/dist/assets/{LandingPage-DVR8ClZO.js → LandingPage-OdZUfq--.js} +2 -2
- package/dashboard/dist/assets/LeaderboardPage-DCK5xcAt.js +2 -0
- package/dashboard/dist/assets/{LeaderboardProBadge-BjX4EFl2.js → LeaderboardProBadge-CBXJ1u_m.js} +1 -1
- package/dashboard/dist/assets/{LeaderboardProfileModal-vbPMNn7W.js → LeaderboardProfileModal-Ccdzb7QK.js} +4 -4
- package/dashboard/dist/assets/{LeaderboardProfilePage-CqClmuA-.js → LeaderboardProfilePage-CFXlZ0fL.js} +1 -1
- package/dashboard/dist/assets/LimitsPage-5krjm-g9.js +9 -0
- package/dashboard/dist/assets/{LocalOnlyNotice-B6nDke_u.js → LocalOnlyNotice-Rk1B8PaZ.js} +1 -1
- package/dashboard/dist/assets/{LoginCard-C28QVjd7.js → LoginCard-DTTIm8vk.js} +1 -1
- package/dashboard/dist/assets/{LoginModal-Bx1btNhH.js → LoginModal-BNcDdjfr.js} +1 -1
- package/dashboard/dist/assets/{LoginPage-DVOGNGYI.js → LoginPage-CQgXP7Ee.js} +1 -1
- package/dashboard/dist/assets/{PetPage-nOKryTde.js → PetPage-Cw_kAPRs.js} +1 -1
- package/dashboard/dist/assets/{PopoverPopup-Ch6NLnu6.js → PopoverPopup-NYiGE8A2.js} +1 -1
- package/dashboard/dist/assets/{ProviderIcon-BRY2br-g.js → ProviderIcon-Bp7iFJ_m.js} +1 -1
- package/dashboard/dist/assets/{ResetPasswordPage-ko1OQecQ.js → ResetPasswordPage-Cf9kAWDW.js} +1 -1
- package/dashboard/dist/assets/{Select-Q8mS3_od.js → Select-kIcvQFAo.js} +1 -1
- package/dashboard/dist/assets/{SelectItemText-C1id8GDj.js → SelectItemText-BpIsAg3b.js} +1 -1
- package/dashboard/dist/assets/{SelfHostPage-Dzb2bDiM.js → SelfHostPage-Ch2vvSwI.js} +1 -1
- package/dashboard/dist/assets/{ServiceStatusPage-ewFwz29J.js → ServiceStatusPage-hoYBvGbu.js} +1 -1
- package/dashboard/dist/assets/SessionsPage-BzRB6q-Z.js +3 -0
- package/dashboard/dist/assets/SettingsPage-DRl2uX-i.js +2 -0
- package/dashboard/dist/assets/{SkillsPage-CcG77tqU.js → SkillsPage-CkqThTZL.js} +1 -1
- package/dashboard/dist/assets/{TokenGalaxy-D2HDrbQR.js → TokenGalaxy-eLG-UIZY.js} +1 -1
- package/dashboard/dist/assets/{TooltipPopup-C_bF2ZwO.js → TooltipPopup-bnMJyilQ.js} +1 -1
- package/dashboard/dist/assets/{TrendMonitor-BcyoN5ns.js → TrendMonitor-X7-aGzIv.js} +1 -1
- package/dashboard/dist/assets/{WidgetsPage-BirK0U_N.js → WidgetsPage-CGznIzrW.js} +1 -1
- package/dashboard/dist/assets/{WrappedPage-thsXBuw6.js → WrappedPage-p31-uUoF.js} +1 -1
- package/dashboard/dist/assets/{__vite-browser-external-Bq8nj-JV.js → __vite-browser-external-2g_4s3ot.js} +12 -12
- package/dashboard/dist/assets/__vite-browser-external-LpFw4zXh.css +1 -0
- package/dashboard/dist/assets/agent-logos-2TVT3fIE.js +1 -0
- package/dashboard/dist/assets/{arrow-left-c_NOSfoq.js → arrow-left-DL0hAp_7.js} +1 -1
- package/dashboard/dist/assets/{arrow-right-CP7drKCT.js → arrow-right-DFCpnV_9.js} +1 -1
- package/dashboard/dist/assets/{arrow-up-right-DQ6QfCpo.js → arrow-up-right-DLvfE0Wu.js} +1 -1
- package/dashboard/dist/assets/{calendar-days-D_pxFQvT.js → calendar-days-B0aDoKSG.js} +1 -1
- package/dashboard/dist/assets/{check-HAS31kTT.js → check-C_cfrxiz.js} +1 -1
- package/dashboard/dist/assets/{chevron-down-BIMuk6oN.js → chevron-down-Ck8ml43e.js} +1 -1
- package/dashboard/dist/assets/{cloud-checkout-COmDwrUT.js → cloud-checkout-PYnwNfdH.js} +1 -1
- package/dashboard/dist/assets/{composite-kLwqpqEk.js → composite-INW-ELWX.js} +1 -1
- package/dashboard/dist/assets/{download-9RgsZIiH.js → download-B7uokeIo.js} +1 -1
- package/dashboard/dist/assets/{external-link-C_gYjHGF.js → external-link-CI3crg4K.js} +1 -1
- package/dashboard/dist/assets/{flame-BSsCvgT8.js → flame-DCzvFKV1.js} +1 -1
- package/dashboard/dist/assets/{format-tokens-N22Wqv1X.js → format-tokens-CSTEYK2m.js} +1 -1
- package/dashboard/dist/assets/gift-dEHDFMc6.js +1 -0
- package/dashboard/dist/assets/{host-mode-JzrhHX7F.js → host-mode-r2SW9Mdv.js} +1 -1
- package/dashboard/dist/assets/{icons-pK99mIMv.js → icons-q-3zvEkh.js} +1 -1
- package/dashboard/dist/assets/{index-CmD84EJi.js → index-BV7qwUw4.js} +1 -1
- package/dashboard/dist/assets/{index-Dk43KNa6.js → index-BbrsgHf4.js} +1 -1
- package/dashboard/dist/assets/{index-BhviBroj.js → index-CyHYj9XI.js} +1 -1
- package/dashboard/dist/assets/{info-D-RLFnSK.js → info-BBdY9hV4.js} +1 -1
- package/dashboard/dist/assets/{link-2-BiKXW9mV.js → link-2-CLPePfXs.js} +1 -1
- package/dashboard/dist/assets/{loader-circle-KVUaEKV2.js → loader-circle-ETrjzfmn.js} +1 -1
- package/dashboard/dist/assets/{modifiers.esm-5NK8j3mT.js → modifiers.esm-DHqnp2ol.js} +1 -1
- package/dashboard/dist/assets/module-BNnaKM__.js +3 -0
- package/dashboard/dist/assets/{monitor-smartphone-u9yr-_Es.js → monitor-smartphone-D1kdzrdb.js} +1 -1
- package/dashboard/dist/assets/{play-D0MaDCOx.js → play-Cxp-ronD.js} +1 -1
- package/dashboard/dist/assets/{plus-DTJVtoAJ.js → plus-4n94VzDK.js} +1 -1
- package/dashboard/dist/assets/{provider-display-YhtG0I9Y.js → provider-display-CRlbeO7t.js} +1 -1
- package/dashboard/dist/assets/{react-gIVxucOB.js → react-DlHjGQFN.js} +1 -1
- package/dashboard/dist/assets/{safePolygon-C_sPnJ1L.js → safePolygon-CVZ27a2_.js} +1 -1
- package/dashboard/dist/assets/{search-DdQRwFYV.js → search-BDPr56_h.js} +1 -1
- package/dashboard/dist/assets/{server-M0rmbGWy.js → server-Bm7fHvVa.js} +1 -1
- package/dashboard/dist/assets/{shield-check-9-sqQKdD.js → shield-check-DtT8ACzI.js} +1 -1
- package/dashboard/dist/assets/{skills-api-B0qBWnuK.js → skills-api-Dc1-2qu6.js} +1 -1
- package/dashboard/dist/assets/{sortable.esm-iqbm7x5D.js → sortable.esm-B-qN-Xk2.js} +1 -1
- package/dashboard/dist/assets/{store-DstuWd4a.js → store-gHeBU8dQ.js} +1 -1
- package/dashboard/dist/assets/{terminal-Dz0MxHNG.js → terminal-D4VZbvhg.js} +1 -1
- package/dashboard/dist/assets/{trash-DBMFOFVz.js → trash-BZtLAFQy.js} +1 -1
- package/dashboard/dist/assets/{use-community-stats-CacbAcUR.js → use-community-stats-BdqndrbB.js} +1 -1
- package/dashboard/dist/assets/{use-latest-request-guard-nBuQVZOR.js → use-latest-request-guard-DhGg1cDS.js} +1 -1
- package/dashboard/dist/assets/use-limits-display-prefs-D3HOcRFv.js +1 -0
- package/dashboard/dist/assets/{use-native-settings-EAqAFx2x.js → use-native-settings-BniKwA_n.js} +1 -1
- package/dashboard/dist/assets/{use-ordered-list-DGLjjU6Q.js → use-ordered-list-b09H7EHq.js} +1 -1
- package/dashboard/dist/assets/{use-pet-settings-C5MzWHE7.js → use-pet-settings-CPZdlq_e.js} +2 -2
- package/dashboard/dist/assets/use-reduced-motion-D1gcKJUo.js +1 -0
- package/dashboard/dist/assets/{use-transform-C25eCuz_.js → use-transform-CIdxjmI8.js} +1 -1
- package/dashboard/dist/assets/use-usage-limits-eJlU65yY.js +1 -0
- package/dashboard/dist/assets/{useCurrency-t3PYQi1l.js → useCurrency-CM22CmAq.js} +1 -1
- package/dashboard/dist/assets/{usePositioner-C59mj6kG.js → usePositioner-B3l2ulTw.js} +1 -1
- package/dashboard/dist/assets/{useTokenFormat-C0xQsBGf.js → useTokenFormat-D7nzgxKw.js} +1 -1
- package/dashboard/dist/assets/{zap-CyH0tvKM.js → zap-Daxct1WV.js} +1 -1
- package/dashboard/dist/index.html +14 -12
- package/dashboard/dist/ip-check.html +2 -2
- package/dashboard/dist/leaderboard.html +2 -2
- package/dashboard/dist/llms.txt +2 -2
- package/dashboard/dist/share.html +2 -2
- package/package.json +2 -2
- package/src/commands/init.js +43 -1
- package/src/commands/status.js +27 -0
- package/src/commands/sync.js +54 -4
- package/src/commands/uninstall.js +19 -0
- package/src/lib/claude-config.js +47 -15
- package/src/lib/codex-rollout-parser.js +11 -3
- package/src/lib/command-runner.js +15 -1
- package/src/lib/cursor-config.js +2 -1
- package/src/lib/gemini-config.js +3 -2
- package/src/lib/local-api.js +13 -3
- package/src/lib/notify-command.js +38 -0
- package/src/lib/openclaw-session-plugin.js +47 -14
- package/src/lib/passive-mode.js +12 -0
- package/src/lib/pricing/curated-overrides.json +42 -5
- package/src/lib/pricing/matcher.js +14 -5
- package/src/lib/pricing/seed-snapshot.json +1 -1
- package/src/lib/rollout.js +150 -28
- package/src/lib/session-analytics.js +108 -9
- package/src/lib/usage-limits.js +183 -20
- package/src/lib/zcode-limits.js +218 -18
- package/src/lib/zcode-reset-credits.js +66 -0
- package/dashboard/dist/assets/DialogDescription-C0Cgq67g.js +0 -1
- package/dashboard/dist/assets/LeaderboardPage-D8ydzVpn.js +0 -2
- package/dashboard/dist/assets/LimitsPage-DaRggHge.js +0 -8
- package/dashboard/dist/assets/SessionsPage-C6Y8kbnM.js +0 -3
- package/dashboard/dist/assets/SettingsPage-nztCXEPs.js +0 -2
- package/dashboard/dist/assets/__vite-browser-external-BwmeEfv7.css +0 -1
- package/dashboard/dist/assets/agent-logos-CK6SzhI7.js +0 -1
- package/dashboard/dist/assets/module-WSx8viXK.js +0 -3
- package/dashboard/dist/assets/use-limits-display-prefs-fqg8hs6b.js +0 -1
- package/dashboard/dist/assets/use-reduced-motion-DK2oZ2uC.js +0 -1
- package/dashboard/dist/assets/use-usage-limits-BhqnEai3.js +0 -1
package/dashboard/dist/assets/{CloudCheckoutPage-C_t_PDlG.js → CloudCheckoutPage-BR2_B03P.js}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{o as nt,d as ct,u as it,r as o,e as ot,a0 as lt,a1 as dt,a2 as ut,a3 as mt,a4 as Te,c as t,t as ht,v as xt,p as ft,a5 as ee,a6 as Me,a7 as pt,j as e,B as x,a8 as je,L as w,a9 as E,aa as gt,ab as _t,ac as kt,ad as yt,ae as bt,af as vt,ag as wt}from"./__vite-browser-external-Bq8nj-JV.js";import{c as fe,r as pe,C as Ne,a as jt,g as Nt,s as ze,o as $e,b as Ct}from"./cloud-checkout-COmDwrUT.js";import{d as It}from"./os-DMmhX9tk.js";import{C as St}from"./Card-DUItW3xI.js";import{T as Lt}from"./Controls-BjdIonTX.js";import{CloudPlanView as Rt}from"./CloudPage-pvJUrhya.js";import{L as Ue}from"./loader-circle-KVUaEKV2.js";import{S as Et}from"./shield-check-9-sqQKdD.js";import{E as Pt}from"./external-link-C_gYjHGF.js";import{A as Fe}from"./arrow-left-c_NOSfoq.js";import"./arrow-right-CP7drKCT.js";import"./chevron-down-BIMuk6oN.js";import"./server-M0rmbGWy.js";import"./check-HAS31kTT.js";const He={name:"circle-check",size:24,node:[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m16 9-5.5 5.5L8 12",key:"xofnsj"}]],aliases:["check-circle-2"]};He.node;const At=nt(He);function Kt(){const H=ct(),{openLoginModal:te}=it(),re=o.useRef(null),[P,A]=ot();o.useEffect(()=>{if(!P.has("_ptxn"))return;const a=new URLSearchParams(P);a.delete("_ptxn"),A(a,{replace:!0})},[P,A]);const{catalog:S,loading:_,error:j,refresh:Ce}=lt(),{account:f,auth:k,loading:G,error:U,refresh:q}=dt(),s=P.get("order")||"",L=P.get("intent")==="trial",Ge=P.get("sku"),u=`/billing/checkout?${P}`,[V,ae]=o.useState(null),[h,Ie]=o.useState(!1),[ge,_e]=o.useState(!!s),[Se,Q]=o.useState(null),[ke,Ve]=o.useState(null),[se,ye]=o.useState(null),[We,Le]=o.useState(!1),[X,Re]=o.useState(null),ne=o.useRef(null),ce=o.useRef(!1),Y=o.useRef(0),be=o.useRef(null),y=o.useRef(!0),r=k?.signedIn?k.user?.id:null,i=ut(),T=o.useRef(i);T.current=i;const Ee=o.useRef(s);Ee.current=s;const N=o.useRef(r);N.current=r;const ie=V?.ownerId===r&&V?.backend===i&&(s?V.order?.id?.toLowerCase()===s.toLowerCase():!V.verified&&V.createdFrom===u)?V:null,Pe=ke?.ownerId===r&&ke?.backend===i?ke:null,Je=se?.ownerId===r&&se?.backend===i&&se?.orderId===s?se.error:null,R=Se||Je,n=ie?.order,p=Pe||ie?.membership||f?.membership,B=S?.policy?.hosting_mode==="self_hosted"||p?.status==="self_hosted",M=n?.sku||Ge,m=S?.prices?.find(a=>a.sku===M),Ke=n?.currency||m?.currency,Qe=n?.amount_cents??m?.amount_cents,C=n?.billing_mode||m?.billing_mode,Xe=n?.term_months||m?.term_months,F=n?.provider||"waffo",l=Pe?"trial_success":h&&!n?"creating":fe(n,p),g=mt(S),I=!!S?.providers?.[F],b=!!(n?.retry_payment_conflict_at||[...f?.conflict_orders||[],...f?.pending_orders||[]].some(a=>a.retry_payment_conflict_at)),W=p?.has_gift===!0||p?.access_source==="gift"||f?.membership?.has_gift===!0||f?.gifts?.some(a=>["active","pending"].includes(a.state)),Ye=n?.provider==="waffo"&&n.payment_state==="unpaid"&&n.status!=="paid"&&["awaiting","expired","canceled"].includes(l)&&g&&I&&!b&&!W,z=k?.getAccessToken,v=pe(r),oe=f?.subscriptions?.some(a=>["active","trialing","past_due","paused"].includes(a.status)&&!a.cancel_at_period_end),le=p?.status==="active"||f?.payments?.some(a=>a.refunded_cents<a.amount_cents&&Date.parse(a.ends_at)>Date.now()),Ae=["fixed","recurring"].includes(m?.billing_mode)?S?.prices?.find(a=>a.currency===m.currency&&a.term_months===m.term_months&&a.billing_mode===(m.billing_mode==="recurring"?"fixed":"recurring")):null,qe=!!(r&&p&&!k?.loading&&!G&&!U&&l==="review"&&!L&&!s&&!n&&!h&&g&&I&&!_&&!j&&Ae&&!le&&!W&&!oe&&!b&&!v?.request_id&&!v?.order_id&&!f?.pending_orders?.length),Ze=()=>{if(!qe||ce.current)return;const a=pe(r);if(a?.request_id||a?.order_id)return;const c=new URLSearchParams(P);c.set("sku",Ae.sku),A(c,{replace:!0})},et=Te(u,r)||(X?.nextPath===u&&X?.ownerId===r&&X?.backend===i?X:null),de=t(L?"cloud.login.trial_context":"cloud.login.purchase_context");o.useEffect(()=>{if(r){re.current=null;return}k?.loading||_||B||re.current===u||(re.current=u,te({nextPath:u,subtitle:de,closePath:"/cloud"}))},[r,k?.loading,_,B,u,de,te]);const Be=S?.environment==="live"&&!L&&P.getAll("order").length===1&&Ne.test(s)&&["mac","windows"].includes(It())&&!(navigator.platform==="MacIntel"&&navigator.maxTouchPoints>1)&&!ht()&&!xt()&&!ft()?`tokentracker://billing/return?order=${s.toLowerCase()}`:null;o.useEffect(()=>(y.current=!0,()=>{y.current=!1}),[]);const J=o.useCallback(async()=>{if(B||!s||!r||N.current!==r)return null;if(!Ne.test(s))return Q({code:"order_not_found"}),_e(!1),null;const a=++Y.current;try{const c=await ee("order",{auth:z,params:{id:s}});if(a!==Y.current||N.current!==r||T.current!==i)return null;ae({...c,ownerId:r,backend:i,verified:!0}),Q(null);const d=fe(c.order,c.membership);if(d==="success"&&ye(null),["success","refunded"].includes(d)){const $=`${r}:${s}:${d}`;be.current!==$&&(be.current=$,q())}if(["success","expired","canceled","refunded"].includes(fe(c.order,c.membership))){const $=pe(r),K=c.order.payment_state==="unpaid"&&c.order.status!=="paid"&&["expired","canceled"].includes(fe(c.order,c.membership))&&$?.retry_order_id===s&&$?.retry_request_id;$?.order_id===s&&!K&&jt(r)}return c}catch(c){return a===Y.current&&Q(c),null}finally{a===Y.current&&_e(!1)}},[s,r,z,B,q,i]);o.useEffect(()=>(ae(null),Q(null),be.current=null,_e(!!(s&&r)),J(),()=>{Y.current+=1}),[J,s,r]),o.useEffect(()=>{if(B||!s||!r||["success","canceled","expired","refunded"].includes(l))return;const a=()=>{document.visibilityState==="visible"&&J()},c=window.setInterval(a,5e3);return window.addEventListener("focus",a),document.addEventListener("visibilitychange",a),()=>{window.clearInterval(c),window.removeEventListener("focus",a),document.removeEventListener("visibilitychange",a)}},[s,r,l,J,B]);const D=o.useCallback(async a=>{if(!ce.current){ce.current=!0,Ie(!0),Q(null),ye(null);try{await a()}catch(c){y.current&&N.current===r&&T.current===i&&ye({ownerId:r,backend:i,orderId:s,error:c})}finally{ce.current=!1,y.current&&Ie(!1)}}},[r,s,i]),ue=o.useCallback((a=!1)=>D(async()=>{const c=Nt(r,M,F),d=await ee("checkout",{auth:z,body:{sku:M,provider:F,request_id:c.request_id,mobile:window.matchMedia("(max-width: 640px)").matches}});T.current===i&&(ze(r,{...c,order_id:d.order.id}),!(!y.current||N.current!==r)&&(a===!0&&(ne.current={ownerId:r,backend:i,orderId:d.order.id,opened:!1}),ae({...d,ownerId:r,backend:i,createdFrom:u,order:{...m,provider:F,...d.order}}),A({order:d.order.id},{replace:!0})))}),[D,r,M,F,z,m,A,i,u]),me=o.useCallback((a=!1)=>D(async()=>{let c;try{c=await ee("trial",{auth:z,body:{}})}catch(d){if(a===!0&&(d.code||d.message)==="trial_unavailable"){y.current&&N.current===r&&T.current===i&&(await q(),y.current&&N.current===r&&T.current===i&&H("/cloud",{replace:!0}));return}throw d}!y.current||N.current!==r||T.current!==i||(Ve({...c.membership,ownerId:r,backend:i}),a===!0?(await q(),y.current&&N.current===r&&T.current===i&&H("/dashboard",{replace:!0})):q())}),[D,z,r,q,H,i]);o.useEffect(()=>{const a=Te(u,r);if(!a||!r||h||k?.loading||G||U||_||j||!p||B||!g)return;if(a.orderId){if(a.orderId!==s)return;const xe=Me(u,r);if(!xe)return;Re({...xe,ownerId:r}),b||(ne.current={ownerId:r,backend:i,orderId:s,opened:!1});return}if(s||!a.trial&&(!m||!I||!C))return;const c=Me(u,r);if(!c)return;if(Re({...c,ownerId:r}),a.trial){if(p.trial_available)me(!0);else{const xe=p.can_read_cloud||["active","trial","transition"].includes(p.status);H(xe?"/dashboard":"/cloud",{replace:!0})}return}if(W||oe||le&&C!=="fixed"||b){H("/settings?section=cloud",{replace:!0});return}const d=pe(r),$=f?.pending_orders?.[0],K=d?.order_id||$?.id;K&&Ne.test(K)?(ne.current={ownerId:r,backend:i,orderId:K,opened:!1},A({order:K},{replace:!0})):d?.request_id&&(d.sku!==M||d.provider!==F)?A({sku:d.sku},{replace:!0}):ue(!0)},[u,r,s,h,k?.loading,G,U,_,j,p,B,g,m,I,C,W,oe,le,b,f?.pending_orders,M,F,me,ue,H,A,i]),o.useEffect(()=>{const a=ne.current;!a||a.opened||a.ownerId!==r||a.backend!==i||a.orderId!==s||!ie?.verified||n?.id?.toLowerCase()!==s.toLowerCase()||!n?.checkout_url||l!=="awaiting"||h||!g||!I||b||(a.opened=!0,D(()=>$e(n.checkout_url,{sameTab:!0})))},[r,s,n?.id,n?.checkout_url,ie?.verified,X?.nextPath,l,h,g,I,b,D,i]);const De=()=>D(async()=>{await ee("reconcile",{auth:z,body:{id:s}}),!(!y.current||N.current!==r)&&(await J(),await q())}),tt=()=>D(async()=>{const a=Ct(r,n);Le(!0);try{const c=await ee("restart-checkout",{auth:z,body:{id:n.id,request_id:a.retry_request_id}});if(ze(r,{sku:n.sku,provider:n.provider,request_id:a.retry_request_id,order_id:c.order.id}),!y.current||N.current!==r||Ee.current!==n.id)return;ae({...c,ownerId:r,backend:i}),A({order:c.order.id},{replace:!0})}finally{y.current&&Le(!1)}}),rt=()=>D(async()=>{await $e(n.checkout_url)}),ve=S?.limits?.trial_days||7,we=wt(),Z=we&&!pt(),at=new Date(Date.now()+ve*864e5).toISOString(),he=L?t("cloud.checkout.starting_trial"):t("cloud.checkout.creating"),st={review:L?t("cloud.checkout.trial_title"):t("cloud.checkout.title"),creating:he,awaiting:t("cloud.checkout.awaiting"),activating:t("cloud.checkout.activating"),success:t("cloud.checkout.success"),canceled:t("cloud.checkout.canceled"),expired:n?.status==="paid"?t("cloud.checkout.term_ended"):t("cloud.checkout.expired"),refunded:t("cloud.checkout.refunded"),trial_success:t("cloud.checkout.trial_success")};let O=null;if(!r)O=e.jsx("div",{className:"space-y-5",children:e.jsx(x,{onClick:()=>te({nextPath:u,subtitle:de,closePath:"/cloud"}),className:"w-full",disabled:k?.loading,children:t("cloud.action.sign_in_continue")})});else if(ge||h&&!n)O=e.jsxs("p",{role:"status",className:"flex items-center gap-2 text-sm",children:[e.jsx(Ue,{className:"motion-safe:animate-spin",size:17,"aria-hidden":!0}),ge?t("cloud.checkout.loading"):he]});else if(l==="trial_success"||l==="success")O=e.jsxs("div",{className:"space-y-5",children:[e.jsx(At,{size:32,className:"text-oai-gray-700 dark:text-oai-gray-200","aria-hidden":!0}),e.jsx("p",{className:"text-sm leading-6",children:l==="trial_success"?t("cloud.trial.ends",{date:je(p.trial_ends_at)}):t("cloud.membership.expires",{date:je(p.expires_at)})}),Z||!we?e.jsx("p",{className:"text-sm leading-6 text-oai-gray-500 dark:text-oai-gray-400",children:t(we?"cloud.onboarding.local_next":"cloud.onboarding.web_next")}):null,e.jsx(x,{as:w,to:Z?"/settings?section=cloud":"/dashboard",className:"w-full no-underline",children:t(Z?"cloud.action.setup_sync":"cloud.action.open_dashboard")}),e.jsx(w,{to:Z?"/dashboard":"/settings?section=cloud",className:"flex min-h-10 items-center justify-center text-sm underline underline-offset-4",children:t(Z?"cloud.action.open_dashboard":"cloud.action.manage_membership")})]});else if(l==="review"&&!s&&W)O=e.jsxs("div",{className:"space-y-5",children:[e.jsx(E,{children:t("cloud.gift.error_active")}),e.jsx(x,{as:w,to:"/settings?section=cloud",variant:"secondary",className:"w-full no-underline",children:t("cloud.action.manage_membership")})]});else if(l==="review"&&!s&&L)O=e.jsxs("div",{className:"space-y-5",children:[e.jsx("p",{className:"text-sm leading-6",children:t("cloud.trial.disclosure",{days:ve,date:je(at)})}),e.jsx("p",{className:"text-sm leading-6 text-oai-gray-500 dark:text-oai-gray-400",children:t("cloud.trial.expiry")}),f?.membership&&!f.membership.trial_available?e.jsxs("div",{className:"space-y-3",children:[e.jsx(E,{children:t("cloud.error.trial")}),m?null:e.jsx(x,{as:w,to:"/cloud",variant:"secondary",className:"w-full no-underline",children:t("cloud.action.view_plans")})]}):null,e.jsx(x,{onClick:me,disabled:h||!g||!f?.membership?.trial_available,className:"w-full",children:t("cloud.action.start_trial",{days:ve})}),m&&g&&I&&!h?e.jsx(x,{as:w,to:`/billing/checkout?sku=${encodeURIComponent(m.sku)}`,variant:"ghost",className:"mx-auto flex w-fit no-underline",children:t("cloud.plan.skip_trial")}):null]});else if(l==="review"&&!s&&m)O=e.jsxs("div",{className:"space-y-5",children:[e.jsx("p",{className:"text-sm leading-6",children:t("cloud.checkout.review")}),e.jsxs("p",{className:"inline-flex items-center gap-2 text-sm",children:[e.jsx(Et,{size:16,"aria-hidden":!0}),t("cloud.checkout.waffo")]}),C?e.jsx("p",{className:"text-sm leading-6 text-oai-gray-500 dark:text-oai-gray-400",children:C==="fixed"?t("cloud.checkout.methods_fixed"):t("cloud.checkout.methods_recurring")}):null,C?e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("p",{className:"text-sm leading-6 text-oai-gray-500 dark:text-oai-gray-400",children:C==="fixed"?t("cloud.renewal.manual"):t("cloud.renewal.auto")}),qe?e.jsx(Lt,{checked:C==="recurring",onChange:Ze,ariaLabel:t("cloud.billing_mode.recurring")}):null]}):null,v?.order_id?e.jsx(x,{as:w,to:`/billing/checkout?order=${encodeURIComponent(v.order_id)}`,className:"w-full no-underline",children:t("cloud.action.resume_order")}):null,v?.request_id&&!v.order_id&&v.sku!==M?e.jsx(x,{as:w,to:`/billing/checkout?sku=${encodeURIComponent(v.sku)}`,className:"w-full no-underline",children:t("cloud.action.resume_purchase")}):null,!v?.order_id&&!(v?.request_id&&v.sku!==M)?e.jsx(x,{onClick:ue,disabled:h||!g||!I||!C||!!v?.order_id||b,className:"w-full",children:t("cloud.action.create_checkout",{amount:gt(Qe,Ke)})}):null]});else if(n){const a={creating:t("cloud.checkout.pending_creation"),awaiting:t("cloud.checkout.pending_payment"),activating:t("cloud.checkout.received"),expired:n?.status==="paid"?t("cloud.checkout.term_ended_detail"):t("cloud.checkout.expired_detail"),canceled:t("cloud.checkout.canceled_detail"),refunded:t("cloud.checkout.refunded_detail")};O=e.jsxs("div",{className:"space-y-5",children:[e.jsx("p",{className:"text-sm leading-6 text-oai-gray-500 dark:text-oai-gray-400",children:a[l]}),l==="awaiting"&&n.checkout_url&&g&&I&&!b?e.jsxs(x,{onClick:rt,disabled:h,className:"w-full",children:[t("cloud.action.open_payment"),e.jsx(Pt,{size:15,className:"ml-2","aria-hidden":!0})]}):null,l!=="refunded"?e.jsxs(e.Fragment,{children:[e.jsx(x,{onClick:De,disabled:h,variant:"ghost",className:"mx-auto flex underline underline-offset-4",children:h?t("cloud.action.checking"):t("cloud.action.check_payment")}),e.jsx("p",{className:"text-xs leading-5 text-oai-gray-500 dark:text-oai-gray-400",children:t("cloud.checkout.recovery_hint")})]}):null,Ye?e.jsxs("details",{open:l!=="awaiting",className:"border-t border-oai-gray-200 pt-4 dark:border-oai-gray-800",children:[e.jsx("summary",{className:"min-h-10 cursor-pointer text-sm font-medium leading-10 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2",children:t("cloud.checkout.help_title")}),e.jsxs("div",{className:"space-y-3 pt-2",children:[e.jsx("p",{className:"text-xs leading-5 text-oai-gray-500 dark:text-oai-gray-400",children:t("cloud.checkout.restart_detail")}),e.jsx(x,{onClick:tt,disabled:h,variant:l==="awaiting"?"secondary":"primary",className:"w-full",children:We?t("cloud.action.restarting_checkout"):t("cloud.action.restart_checkout")})]})]}):null,["canceled","expired"].includes(l)&&!b?e.jsx(w,{to:"/cloud",className:"flex min-h-10 items-center justify-center text-sm underline underline-offset-4",children:n.status==="paid"?t("cloud.action.renew"):t("cloud.action.choose_plan")}):null,l==="refunded"?e.jsx(x,{as:w,to:"/settings?section=cloud",className:"w-full no-underline",children:t("cloud.action.manage_membership")}):null,e.jsxs("details",{className:"border-t border-oai-gray-200 pt-4 dark:border-oai-gray-800",children:[e.jsxs("summary",{className:"min-h-10 cursor-pointer text-xs leading-10 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2",children:[t("cloud.checkout.order_id")," · ",n.id.slice(0,8)]}),e.jsx("p",{className:"mb-2 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:_t(n.provider)}),e.jsx("p",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-400",children:t("cloud.checkout.order_id")}),e.jsx("p",{className:"mt-1 break-all font-mono text-xs select-all",children:n.id}),n.status!=="paid"&&n.expires_at?e.jsx("p",{className:"mt-2 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:t("cloud.checkout.expires",{date:kt(n.expires_at)})}):null]})]})}else O=e.jsx(E,{children:s?t("cloud.error.order_not_found"):t("cloud.checkout.choose_plan")});const Oe=e.jsxs("div",{className:"space-y-3",children:[R?e.jsx(E,{error:R,onRetry:s?Se?J:De:void 0}):null,R&&["subscription_already_exists","fixed_term_still_active","checkout_request_conflict","pending_checkout_exists","gift_membership_active"].includes(R.code||R.message)?e.jsx(x,{as:w,to:"/settings?section=cloud",variant:"secondary",className:"no-underline",children:t("cloud.action.manage_membership")}):null,R&&["authentication_required","invalid_token","invalid_authentication"].includes(R.code||R.message)?e.jsx(x,{onClick:async()=>{await k?.signOut?.(),re.current=u,te({nextPath:u,subtitle:de,closePath:"/cloud"})},variant:"secondary",children:t("cloud.action.sign_in_continue")}):null,j?e.jsx(E,{error:j,onRetry:Ce}):null,U?e.jsx(E,{error:U,onRetry:q}):null,!j&&_?e.jsx(E,{children:t("cloud.catalog.loading")}):null,!j&&!_&&!g?e.jsx(E,{children:t("cloud.catalog.preview")}):null,!j&&!_&&g&&!L&&!R&&!I&&["review","creating","awaiting"].includes(l)?e.jsx(E,{children:t("cloud.catalog.provider_unavailable")}):null,!j&&!_&&g&&S?.environment==="sandbox"?e.jsx(E,{children:t("cloud.catalog.sandbox")}):null]});return B?e.jsx(yt,{}):!r&&!s?e.jsx(e.Fragment,{children:e.jsx(Rt,{catalogState:{catalog:S,loading:_,error:j,refresh:Ce},accountState:{account:f,auth:k,loading:G,error:U,refresh:q},selection:{termMonths:Xe,billingMode:C}})}):et&&r&&!s?e.jsx("div",{className:"tt-cloud-theme flex flex-1 flex-col font-oai text-oai-black dark:text-oai-white",children:e.jsxs("main",{className:"mx-auto w-full max-w-lg px-4 py-12 sm:px-6",children:[e.jsxs(w,{to:"/cloud",onClick:()=>bt(u),className:"mb-6 inline-flex min-h-10 items-center gap-2 text-sm text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsx(Fe,{size:16,"aria-hidden":!0}),t("cloud.checkout.back")]}),e.jsx("h1",{className:"text-2xl font-semibold tracking-tight",children:he}),h||k?.loading||_||G?e.jsxs("p",{role:"status",className:"mt-5 flex items-center gap-2 text-sm text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsx(Ue,{className:"motion-safe:animate-spin",size:17,"aria-hidden":!0}),he]}):null,e.jsx("div",{className:"mt-5",children:Oe}),R&&!h?e.jsx(x,{onClick:()=>L?me(!0):ue(!0),disabled:G||!!U||_||!!j||!g||(L?!p?.trial_available:!m||!I||b||W||le&&C!=="fixed"||oe),className:"mt-5 w-full",children:t("cloud.action.retry")}):null]})}):e.jsx("div",{className:"tt-cloud-theme flex flex-1 flex-col font-oai text-oai-black dark:text-oai-white",children:e.jsxs("main",{className:"mx-auto w-full max-w-xl px-4 py-8 sm:px-6 sm:py-12",children:[e.jsxs(w,{to:"/cloud",className:"mb-7 inline-flex min-h-10 items-center gap-2 text-sm text-oai-gray-500 dark:text-oai-gray-400 hover:text-oai-brand focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand",children:[e.jsx(Fe,{size:16,"aria-hidden":!0}),t("cloud.checkout.back")]}),e.jsx("h1",{className:"text-3xl font-semibold tracking-tight","aria-live":"polite",children:ge?t("cloud.checkout.loading"):st[l]}),S?.environment==="sandbox"&&!L?e.jsx("p",{className:"mt-2 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:t("cloud.price.draft")}):null,b?e.jsx("div",{className:"mt-5",children:e.jsx(vt,{})}):null,e.jsx("div",{className:"mt-7",children:e.jsxs(St,{bodyClassName:"sm:p-7",children:[O,Be?e.jsxs("div",{className:"mt-5 space-y-3 border-t border-oai-gray-200 pt-5 dark:border-oai-gray-800",children:[e.jsx("p",{className:"text-sm leading-6 text-oai-gray-500 dark:text-oai-gray-400",children:t("cloud.checkout.return_app_hint")}),e.jsx("a",{href:Be,className:"inline-flex min-h-10 items-center text-sm underline underline-offset-4",children:t("cloud.action.open_app")})]}):null]})}),e.jsx("div",{className:"mt-5",children:Oe})]})})}export{Kt as CloudCheckoutPage};
|
|
1
|
+
import{o as nt,d as ct,u as it,r as o,e as ot,a0 as lt,a1 as dt,a2 as ut,a3 as mt,a4 as Te,c as t,t as ht,v as xt,p as ft,a5 as ee,a6 as Me,a7 as pt,j as e,B as x,a8 as je,L as w,a9 as E,aa as gt,ab as _t,ac as kt,ad as yt,ae as bt,af as vt,ag as wt}from"./__vite-browser-external-2g_4s3ot.js";import{c as fe,r as pe,C as Ne,a as jt,g as Nt,s as ze,o as $e,b as Ct}from"./cloud-checkout-PYnwNfdH.js";import{d as It}from"./os-DMmhX9tk.js";import{C as St}from"./Card-BYoxd4OC.js";import{T as Lt}from"./Controls-MTUhGWy8.js";import{CloudPlanView as Rt}from"./CloudPage-DL5RkJKK.js";import{L as Ue}from"./loader-circle-ETrjzfmn.js";import{S as Et}from"./shield-check-DtT8ACzI.js";import{E as Pt}from"./external-link-CI3crg4K.js";import{A as Fe}from"./arrow-left-DL0hAp_7.js";import"./arrow-right-DFCpnV_9.js";import"./chevron-down-Ck8ml43e.js";import"./server-Bm7fHvVa.js";import"./check-C_cfrxiz.js";const He={name:"circle-check",size:24,node:[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m16 9-5.5 5.5L8 12",key:"xofnsj"}]],aliases:["check-circle-2"]};He.node;const At=nt(He);function Kt(){const H=ct(),{openLoginModal:te}=it(),re=o.useRef(null),[P,A]=ot();o.useEffect(()=>{if(!P.has("_ptxn"))return;const a=new URLSearchParams(P);a.delete("_ptxn"),A(a,{replace:!0})},[P,A]);const{catalog:S,loading:_,error:j,refresh:Ce}=lt(),{account:f,auth:k,loading:G,error:U,refresh:q}=dt(),s=P.get("order")||"",L=P.get("intent")==="trial",Ge=P.get("sku"),u=`/billing/checkout?${P}`,[V,ae]=o.useState(null),[h,Ie]=o.useState(!1),[ge,_e]=o.useState(!!s),[Se,Q]=o.useState(null),[ke,Ve]=o.useState(null),[se,ye]=o.useState(null),[We,Le]=o.useState(!1),[X,Re]=o.useState(null),ne=o.useRef(null),ce=o.useRef(!1),Y=o.useRef(0),be=o.useRef(null),y=o.useRef(!0),r=k?.signedIn?k.user?.id:null,i=ut(),T=o.useRef(i);T.current=i;const Ee=o.useRef(s);Ee.current=s;const N=o.useRef(r);N.current=r;const ie=V?.ownerId===r&&V?.backend===i&&(s?V.order?.id?.toLowerCase()===s.toLowerCase():!V.verified&&V.createdFrom===u)?V:null,Pe=ke?.ownerId===r&&ke?.backend===i?ke:null,Je=se?.ownerId===r&&se?.backend===i&&se?.orderId===s?se.error:null,R=Se||Je,n=ie?.order,p=Pe||ie?.membership||f?.membership,B=S?.policy?.hosting_mode==="self_hosted"||p?.status==="self_hosted",M=n?.sku||Ge,m=S?.prices?.find(a=>a.sku===M),Ke=n?.currency||m?.currency,Qe=n?.amount_cents??m?.amount_cents,C=n?.billing_mode||m?.billing_mode,Xe=n?.term_months||m?.term_months,F=n?.provider||"waffo",l=Pe?"trial_success":h&&!n?"creating":fe(n,p),g=mt(S),I=!!S?.providers?.[F],b=!!(n?.retry_payment_conflict_at||[...f?.conflict_orders||[],...f?.pending_orders||[]].some(a=>a.retry_payment_conflict_at)),W=p?.has_gift===!0||p?.access_source==="gift"||f?.membership?.has_gift===!0||f?.gifts?.some(a=>["active","pending"].includes(a.state)),Ye=n?.provider==="waffo"&&n.payment_state==="unpaid"&&n.status!=="paid"&&["awaiting","expired","canceled"].includes(l)&&g&&I&&!b&&!W,z=k?.getAccessToken,v=pe(r),oe=f?.subscriptions?.some(a=>["active","trialing","past_due","paused"].includes(a.status)&&!a.cancel_at_period_end),le=p?.status==="active"||f?.payments?.some(a=>a.refunded_cents<a.amount_cents&&Date.parse(a.ends_at)>Date.now()),Ae=["fixed","recurring"].includes(m?.billing_mode)?S?.prices?.find(a=>a.currency===m.currency&&a.term_months===m.term_months&&a.billing_mode===(m.billing_mode==="recurring"?"fixed":"recurring")):null,qe=!!(r&&p&&!k?.loading&&!G&&!U&&l==="review"&&!L&&!s&&!n&&!h&&g&&I&&!_&&!j&&Ae&&!le&&!W&&!oe&&!b&&!v?.request_id&&!v?.order_id&&!f?.pending_orders?.length),Ze=()=>{if(!qe||ce.current)return;const a=pe(r);if(a?.request_id||a?.order_id)return;const c=new URLSearchParams(P);c.set("sku",Ae.sku),A(c,{replace:!0})},et=Te(u,r)||(X?.nextPath===u&&X?.ownerId===r&&X?.backend===i?X:null),de=t(L?"cloud.login.trial_context":"cloud.login.purchase_context");o.useEffect(()=>{if(r){re.current=null;return}k?.loading||_||B||re.current===u||(re.current=u,te({nextPath:u,subtitle:de,closePath:"/cloud"}))},[r,k?.loading,_,B,u,de,te]);const Be=S?.environment==="live"&&!L&&P.getAll("order").length===1&&Ne.test(s)&&["mac","windows"].includes(It())&&!(navigator.platform==="MacIntel"&&navigator.maxTouchPoints>1)&&!ht()&&!xt()&&!ft()?`tokentracker://billing/return?order=${s.toLowerCase()}`:null;o.useEffect(()=>(y.current=!0,()=>{y.current=!1}),[]);const J=o.useCallback(async()=>{if(B||!s||!r||N.current!==r)return null;if(!Ne.test(s))return Q({code:"order_not_found"}),_e(!1),null;const a=++Y.current;try{const c=await ee("order",{auth:z,params:{id:s}});if(a!==Y.current||N.current!==r||T.current!==i)return null;ae({...c,ownerId:r,backend:i,verified:!0}),Q(null);const d=fe(c.order,c.membership);if(d==="success"&&ye(null),["success","refunded"].includes(d)){const $=`${r}:${s}:${d}`;be.current!==$&&(be.current=$,q())}if(["success","expired","canceled","refunded"].includes(fe(c.order,c.membership))){const $=pe(r),K=c.order.payment_state==="unpaid"&&c.order.status!=="paid"&&["expired","canceled"].includes(fe(c.order,c.membership))&&$?.retry_order_id===s&&$?.retry_request_id;$?.order_id===s&&!K&&jt(r)}return c}catch(c){return a===Y.current&&Q(c),null}finally{a===Y.current&&_e(!1)}},[s,r,z,B,q,i]);o.useEffect(()=>(ae(null),Q(null),be.current=null,_e(!!(s&&r)),J(),()=>{Y.current+=1}),[J,s,r]),o.useEffect(()=>{if(B||!s||!r||["success","canceled","expired","refunded"].includes(l))return;const a=()=>{document.visibilityState==="visible"&&J()},c=window.setInterval(a,5e3);return window.addEventListener("focus",a),document.addEventListener("visibilitychange",a),()=>{window.clearInterval(c),window.removeEventListener("focus",a),document.removeEventListener("visibilitychange",a)}},[s,r,l,J,B]);const D=o.useCallback(async a=>{if(!ce.current){ce.current=!0,Ie(!0),Q(null),ye(null);try{await a()}catch(c){y.current&&N.current===r&&T.current===i&&ye({ownerId:r,backend:i,orderId:s,error:c})}finally{ce.current=!1,y.current&&Ie(!1)}}},[r,s,i]),ue=o.useCallback((a=!1)=>D(async()=>{const c=Nt(r,M,F),d=await ee("checkout",{auth:z,body:{sku:M,provider:F,request_id:c.request_id,mobile:window.matchMedia("(max-width: 640px)").matches}});T.current===i&&(ze(r,{...c,order_id:d.order.id}),!(!y.current||N.current!==r)&&(a===!0&&(ne.current={ownerId:r,backend:i,orderId:d.order.id,opened:!1}),ae({...d,ownerId:r,backend:i,createdFrom:u,order:{...m,provider:F,...d.order}}),A({order:d.order.id},{replace:!0})))}),[D,r,M,F,z,m,A,i,u]),me=o.useCallback((a=!1)=>D(async()=>{let c;try{c=await ee("trial",{auth:z,body:{}})}catch(d){if(a===!0&&(d.code||d.message)==="trial_unavailable"){y.current&&N.current===r&&T.current===i&&(await q(),y.current&&N.current===r&&T.current===i&&H("/cloud",{replace:!0}));return}throw d}!y.current||N.current!==r||T.current!==i||(Ve({...c.membership,ownerId:r,backend:i}),a===!0?(await q(),y.current&&N.current===r&&T.current===i&&H("/dashboard",{replace:!0})):q())}),[D,z,r,q,H,i]);o.useEffect(()=>{const a=Te(u,r);if(!a||!r||h||k?.loading||G||U||_||j||!p||B||!g)return;if(a.orderId){if(a.orderId!==s)return;const xe=Me(u,r);if(!xe)return;Re({...xe,ownerId:r}),b||(ne.current={ownerId:r,backend:i,orderId:s,opened:!1});return}if(s||!a.trial&&(!m||!I||!C))return;const c=Me(u,r);if(!c)return;if(Re({...c,ownerId:r}),a.trial){if(p.trial_available)me(!0);else{const xe=p.can_read_cloud||["active","trial","transition"].includes(p.status);H(xe?"/dashboard":"/cloud",{replace:!0})}return}if(W||oe||le&&C!=="fixed"||b){H("/settings?section=cloud",{replace:!0});return}const d=pe(r),$=f?.pending_orders?.[0],K=d?.order_id||$?.id;K&&Ne.test(K)?(ne.current={ownerId:r,backend:i,orderId:K,opened:!1},A({order:K},{replace:!0})):d?.request_id&&(d.sku!==M||d.provider!==F)?A({sku:d.sku},{replace:!0}):ue(!0)},[u,r,s,h,k?.loading,G,U,_,j,p,B,g,m,I,C,W,oe,le,b,f?.pending_orders,M,F,me,ue,H,A,i]),o.useEffect(()=>{const a=ne.current;!a||a.opened||a.ownerId!==r||a.backend!==i||a.orderId!==s||!ie?.verified||n?.id?.toLowerCase()!==s.toLowerCase()||!n?.checkout_url||l!=="awaiting"||h||!g||!I||b||(a.opened=!0,D(()=>$e(n.checkout_url,{sameTab:!0})))},[r,s,n?.id,n?.checkout_url,ie?.verified,X?.nextPath,l,h,g,I,b,D,i]);const De=()=>D(async()=>{await ee("reconcile",{auth:z,body:{id:s}}),!(!y.current||N.current!==r)&&(await J(),await q())}),tt=()=>D(async()=>{const a=Ct(r,n);Le(!0);try{const c=await ee("restart-checkout",{auth:z,body:{id:n.id,request_id:a.retry_request_id}});if(ze(r,{sku:n.sku,provider:n.provider,request_id:a.retry_request_id,order_id:c.order.id}),!y.current||N.current!==r||Ee.current!==n.id)return;ae({...c,ownerId:r,backend:i}),A({order:c.order.id},{replace:!0})}finally{y.current&&Le(!1)}}),rt=()=>D(async()=>{await $e(n.checkout_url)}),ve=S?.limits?.trial_days||7,we=wt(),Z=we&&!pt(),at=new Date(Date.now()+ve*864e5).toISOString(),he=L?t("cloud.checkout.starting_trial"):t("cloud.checkout.creating"),st={review:L?t("cloud.checkout.trial_title"):t("cloud.checkout.title"),creating:he,awaiting:t("cloud.checkout.awaiting"),activating:t("cloud.checkout.activating"),success:t("cloud.checkout.success"),canceled:t("cloud.checkout.canceled"),expired:n?.status==="paid"?t("cloud.checkout.term_ended"):t("cloud.checkout.expired"),refunded:t("cloud.checkout.refunded"),trial_success:t("cloud.checkout.trial_success")};let O=null;if(!r)O=e.jsx("div",{className:"space-y-5",children:e.jsx(x,{onClick:()=>te({nextPath:u,subtitle:de,closePath:"/cloud"}),className:"w-full",disabled:k?.loading,children:t("cloud.action.sign_in_continue")})});else if(ge||h&&!n)O=e.jsxs("p",{role:"status",className:"flex items-center gap-2 text-sm",children:[e.jsx(Ue,{className:"motion-safe:animate-spin",size:17,"aria-hidden":!0}),ge?t("cloud.checkout.loading"):he]});else if(l==="trial_success"||l==="success")O=e.jsxs("div",{className:"space-y-5",children:[e.jsx(At,{size:32,className:"text-oai-gray-700 dark:text-oai-gray-200","aria-hidden":!0}),e.jsx("p",{className:"text-sm leading-6",children:l==="trial_success"?t("cloud.trial.ends",{date:je(p.trial_ends_at)}):t("cloud.membership.expires",{date:je(p.expires_at)})}),Z||!we?e.jsx("p",{className:"text-sm leading-6 text-oai-gray-500 dark:text-oai-gray-400",children:t(we?"cloud.onboarding.local_next":"cloud.onboarding.web_next")}):null,e.jsx(x,{as:w,to:Z?"/settings?section=cloud":"/dashboard",className:"w-full no-underline",children:t(Z?"cloud.action.setup_sync":"cloud.action.open_dashboard")}),e.jsx(w,{to:Z?"/dashboard":"/settings?section=cloud",className:"flex min-h-10 items-center justify-center text-sm underline underline-offset-4",children:t(Z?"cloud.action.open_dashboard":"cloud.action.manage_membership")})]});else if(l==="review"&&!s&&W)O=e.jsxs("div",{className:"space-y-5",children:[e.jsx(E,{children:t("cloud.gift.error_active")}),e.jsx(x,{as:w,to:"/settings?section=cloud",variant:"secondary",className:"w-full no-underline",children:t("cloud.action.manage_membership")})]});else if(l==="review"&&!s&&L)O=e.jsxs("div",{className:"space-y-5",children:[e.jsx("p",{className:"text-sm leading-6",children:t("cloud.trial.disclosure",{days:ve,date:je(at)})}),e.jsx("p",{className:"text-sm leading-6 text-oai-gray-500 dark:text-oai-gray-400",children:t("cloud.trial.expiry")}),f?.membership&&!f.membership.trial_available?e.jsxs("div",{className:"space-y-3",children:[e.jsx(E,{children:t("cloud.error.trial")}),m?null:e.jsx(x,{as:w,to:"/cloud",variant:"secondary",className:"w-full no-underline",children:t("cloud.action.view_plans")})]}):null,e.jsx(x,{onClick:me,disabled:h||!g||!f?.membership?.trial_available,className:"w-full",children:t("cloud.action.start_trial",{days:ve})}),m&&g&&I&&!h?e.jsx(x,{as:w,to:`/billing/checkout?sku=${encodeURIComponent(m.sku)}`,variant:"ghost",className:"mx-auto flex w-fit no-underline",children:t("cloud.plan.skip_trial")}):null]});else if(l==="review"&&!s&&m)O=e.jsxs("div",{className:"space-y-5",children:[e.jsx("p",{className:"text-sm leading-6",children:t("cloud.checkout.review")}),e.jsxs("p",{className:"inline-flex items-center gap-2 text-sm",children:[e.jsx(Et,{size:16,"aria-hidden":!0}),t("cloud.checkout.waffo")]}),C?e.jsx("p",{className:"text-sm leading-6 text-oai-gray-500 dark:text-oai-gray-400",children:C==="fixed"?t("cloud.checkout.methods_fixed"):t("cloud.checkout.methods_recurring")}):null,C?e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("p",{className:"text-sm leading-6 text-oai-gray-500 dark:text-oai-gray-400",children:C==="fixed"?t("cloud.renewal.manual"):t("cloud.renewal.auto")}),qe?e.jsx(Lt,{checked:C==="recurring",onChange:Ze,ariaLabel:t("cloud.billing_mode.recurring")}):null]}):null,v?.order_id?e.jsx(x,{as:w,to:`/billing/checkout?order=${encodeURIComponent(v.order_id)}`,className:"w-full no-underline",children:t("cloud.action.resume_order")}):null,v?.request_id&&!v.order_id&&v.sku!==M?e.jsx(x,{as:w,to:`/billing/checkout?sku=${encodeURIComponent(v.sku)}`,className:"w-full no-underline",children:t("cloud.action.resume_purchase")}):null,!v?.order_id&&!(v?.request_id&&v.sku!==M)?e.jsx(x,{onClick:ue,disabled:h||!g||!I||!C||!!v?.order_id||b,className:"w-full",children:t("cloud.action.create_checkout",{amount:gt(Qe,Ke)})}):null]});else if(n){const a={creating:t("cloud.checkout.pending_creation"),awaiting:t("cloud.checkout.pending_payment"),activating:t("cloud.checkout.received"),expired:n?.status==="paid"?t("cloud.checkout.term_ended_detail"):t("cloud.checkout.expired_detail"),canceled:t("cloud.checkout.canceled_detail"),refunded:t("cloud.checkout.refunded_detail")};O=e.jsxs("div",{className:"space-y-5",children:[e.jsx("p",{className:"text-sm leading-6 text-oai-gray-500 dark:text-oai-gray-400",children:a[l]}),l==="awaiting"&&n.checkout_url&&g&&I&&!b?e.jsxs(x,{onClick:rt,disabled:h,className:"w-full",children:[t("cloud.action.open_payment"),e.jsx(Pt,{size:15,className:"ml-2","aria-hidden":!0})]}):null,l!=="refunded"?e.jsxs(e.Fragment,{children:[e.jsx(x,{onClick:De,disabled:h,variant:"ghost",className:"mx-auto flex underline underline-offset-4",children:h?t("cloud.action.checking"):t("cloud.action.check_payment")}),e.jsx("p",{className:"text-xs leading-5 text-oai-gray-500 dark:text-oai-gray-400",children:t("cloud.checkout.recovery_hint")})]}):null,Ye?e.jsxs("details",{open:l!=="awaiting",className:"border-t border-oai-gray-200 pt-4 dark:border-oai-gray-800",children:[e.jsx("summary",{className:"min-h-10 cursor-pointer text-sm font-medium leading-10 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2",children:t("cloud.checkout.help_title")}),e.jsxs("div",{className:"space-y-3 pt-2",children:[e.jsx("p",{className:"text-xs leading-5 text-oai-gray-500 dark:text-oai-gray-400",children:t("cloud.checkout.restart_detail")}),e.jsx(x,{onClick:tt,disabled:h,variant:l==="awaiting"?"secondary":"primary",className:"w-full",children:We?t("cloud.action.restarting_checkout"):t("cloud.action.restart_checkout")})]})]}):null,["canceled","expired"].includes(l)&&!b?e.jsx(w,{to:"/cloud",className:"flex min-h-10 items-center justify-center text-sm underline underline-offset-4",children:n.status==="paid"?t("cloud.action.renew"):t("cloud.action.choose_plan")}):null,l==="refunded"?e.jsx(x,{as:w,to:"/settings?section=cloud",className:"w-full no-underline",children:t("cloud.action.manage_membership")}):null,e.jsxs("details",{className:"border-t border-oai-gray-200 pt-4 dark:border-oai-gray-800",children:[e.jsxs("summary",{className:"min-h-10 cursor-pointer text-xs leading-10 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2",children:[t("cloud.checkout.order_id")," · ",n.id.slice(0,8)]}),e.jsx("p",{className:"mb-2 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:_t(n.provider)}),e.jsx("p",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-400",children:t("cloud.checkout.order_id")}),e.jsx("p",{className:"mt-1 break-all font-mono text-xs select-all",children:n.id}),n.status!=="paid"&&n.expires_at?e.jsx("p",{className:"mt-2 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:t("cloud.checkout.expires",{date:kt(n.expires_at)})}):null]})]})}else O=e.jsx(E,{children:s?t("cloud.error.order_not_found"):t("cloud.checkout.choose_plan")});const Oe=e.jsxs("div",{className:"space-y-3",children:[R?e.jsx(E,{error:R,onRetry:s?Se?J:De:void 0}):null,R&&["subscription_already_exists","fixed_term_still_active","checkout_request_conflict","pending_checkout_exists","gift_membership_active"].includes(R.code||R.message)?e.jsx(x,{as:w,to:"/settings?section=cloud",variant:"secondary",className:"no-underline",children:t("cloud.action.manage_membership")}):null,R&&["authentication_required","invalid_token","invalid_authentication"].includes(R.code||R.message)?e.jsx(x,{onClick:async()=>{await k?.signOut?.(),re.current=u,te({nextPath:u,subtitle:de,closePath:"/cloud"})},variant:"secondary",children:t("cloud.action.sign_in_continue")}):null,j?e.jsx(E,{error:j,onRetry:Ce}):null,U?e.jsx(E,{error:U,onRetry:q}):null,!j&&_?e.jsx(E,{children:t("cloud.catalog.loading")}):null,!j&&!_&&!g?e.jsx(E,{children:t("cloud.catalog.preview")}):null,!j&&!_&&g&&!L&&!R&&!I&&["review","creating","awaiting"].includes(l)?e.jsx(E,{children:t("cloud.catalog.provider_unavailable")}):null,!j&&!_&&g&&S?.environment==="sandbox"?e.jsx(E,{children:t("cloud.catalog.sandbox")}):null]});return B?e.jsx(yt,{}):!r&&!s?e.jsx(e.Fragment,{children:e.jsx(Rt,{catalogState:{catalog:S,loading:_,error:j,refresh:Ce},accountState:{account:f,auth:k,loading:G,error:U,refresh:q},selection:{termMonths:Xe,billingMode:C}})}):et&&r&&!s?e.jsx("div",{className:"tt-cloud-theme flex flex-1 flex-col font-oai text-oai-black dark:text-oai-white",children:e.jsxs("main",{className:"mx-auto w-full max-w-lg px-4 py-12 sm:px-6",children:[e.jsxs(w,{to:"/cloud",onClick:()=>bt(u),className:"mb-6 inline-flex min-h-10 items-center gap-2 text-sm text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsx(Fe,{size:16,"aria-hidden":!0}),t("cloud.checkout.back")]}),e.jsx("h1",{className:"text-2xl font-semibold tracking-tight",children:he}),h||k?.loading||_||G?e.jsxs("p",{role:"status",className:"mt-5 flex items-center gap-2 text-sm text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsx(Ue,{className:"motion-safe:animate-spin",size:17,"aria-hidden":!0}),he]}):null,e.jsx("div",{className:"mt-5",children:Oe}),R&&!h?e.jsx(x,{onClick:()=>L?me(!0):ue(!0),disabled:G||!!U||_||!!j||!g||(L?!p?.trial_available:!m||!I||b||W||le&&C!=="fixed"||oe),className:"mt-5 w-full",children:t("cloud.action.retry")}):null]})}):e.jsx("div",{className:"tt-cloud-theme flex flex-1 flex-col font-oai text-oai-black dark:text-oai-white",children:e.jsxs("main",{className:"mx-auto w-full max-w-xl px-4 py-8 sm:px-6 sm:py-12",children:[e.jsxs(w,{to:"/cloud",className:"mb-7 inline-flex min-h-10 items-center gap-2 text-sm text-oai-gray-500 dark:text-oai-gray-400 hover:text-oai-brand focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand",children:[e.jsx(Fe,{size:16,"aria-hidden":!0}),t("cloud.checkout.back")]}),e.jsx("h1",{className:"text-3xl font-semibold tracking-tight","aria-live":"polite",children:ge?t("cloud.checkout.loading"):st[l]}),S?.environment==="sandbox"&&!L?e.jsx("p",{className:"mt-2 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:t("cloud.price.draft")}):null,b?e.jsx("div",{className:"mt-5",children:e.jsx(vt,{})}):null,e.jsx("div",{className:"mt-7",children:e.jsxs(St,{bodyClassName:"sm:p-7",children:[O,Be?e.jsxs("div",{className:"mt-5 space-y-3 border-t border-oai-gray-200 pt-5 dark:border-oai-gray-800",children:[e.jsx("p",{className:"text-sm leading-6 text-oai-gray-500 dark:text-oai-gray-400",children:t("cloud.checkout.return_app_hint")}),e.jsx("a",{href:Be,className:"inline-flex min-h-10 items-center text-sm underline underline-offset-4",children:t("cloud.action.open_app")})]}):null]})}),e.jsx("div",{className:"mt-5",children:Oe})]})})}export{Kt as CloudCheckoutPage};
|