@tinkerlandai/longplay-sdk 0.10.21 → 0.10.22

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.
Files changed (33) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/{ai-usage-3NrLouAi.d.ts → ai-usage-WFwbPTiq.d.ts} +1 -1
  3. package/dist/{api-C65zMJI6.d.ts → api-rZ_QoNQi.d.ts} +642 -21
  4. package/dist/{chunk-Z5CW2N7E.js → chunk-77ZUEWYE.js} +1 -1
  5. package/dist/{chunk-CHQUGYMS.js → chunk-CM75TDWK.js} +1 -1
  6. package/dist/{chunk-53C6LI3D.js → chunk-GQ7B25L5.js} +1 -1
  7. package/dist/{chunk-AX2PJEJP.js → chunk-HCI6E3R7.js} +1 -1
  8. package/dist/{chunk-YDWAT2ID.js → chunk-HK3UIQ4O.js} +1 -1
  9. package/dist/{chunk-BP6G3YGP.js → chunk-KLP5TN5O.js} +1 -1
  10. package/dist/{chunk-JXNNWCEB.js → chunk-KSCITFNQ.js} +3 -3
  11. package/dist/{chunk-LBGCSWVF.js → chunk-NO5GW7GX.js} +1 -1
  12. package/dist/{chunk-JNML7SY4.js → chunk-O5XTOWFZ.js} +1 -1
  13. package/dist/chunk-RNOB7OYB.js +1 -0
  14. package/dist/{content-JS7M7A3P.js → content-RWD3AGMM.js} +1 -1
  15. package/dist/{funnel-local-client-WOMhUCjI.d.ts → funnel-local-client-BYdKGnMb.d.ts} +389 -1
  16. package/dist/{funnel-node-evaluation-Dhv2hYnn.d.ts → funnel-node-evaluation-eLMEZIFz.d.ts} +31 -0
  17. package/dist/{funnel-process-client-C6q2FqFc.d.ts → funnel-process-client-C87pmLC9.d.ts} +800 -2
  18. package/dist/funnel-runtime-host-MRP53J2I.js +1 -0
  19. package/dist/index.d.ts +7 -7
  20. package/dist/index.js +1 -1
  21. package/dist/native-shell.js +1 -1
  22. package/dist/openrouter.d.ts +2 -2
  23. package/dist/openrouter.js +1 -1
  24. package/dist/page.js +1 -1
  25. package/dist/{paywall-VHDTE2N2.js → paywall-5Q4VATYY.js} +1 -1
  26. package/dist/react-native.d.ts +5 -5
  27. package/dist/react-native.js +1 -1
  28. package/dist/server.d.ts +252 -24
  29. package/dist/server.js +1 -1
  30. package/dist/visual.js +1 -1
  31. package/package.json +1 -1
  32. package/dist/chunk-M4LTOSLT.js +0 -1
  33. package/dist/funnel-runtime-host-XYUJ4WFW.js +0 -1
@@ -1,7 +1,7 @@
1
1
  import { OpenRouter } from '@openrouter/sdk';
2
2
  import { ChatUsage } from '@openrouter/sdk/models';
3
- import { F as FoundationApi } from './api-C65zMJI6.js';
4
- import { c as createAiPricing, A as AiUsageContext, a as AiTokenUsage, b as AiTokenQuote } from './ai-usage-3NrLouAi.js';
3
+ import { F as FoundationApi } from './api-rZ_QoNQi.js';
4
+ import { c as createAiPricing, A as AiUsageContext, a as AiTokenUsage, b as AiTokenQuote } from './ai-usage-WFwbPTiq.js';
5
5
  import './screen-DRP7nsrQ.js';
6
6
  import 'zod';
7
7
  import 'zod/v4';
@@ -1 +1 @@
1
- import"./chunk-CHQUGYMS.js";import"./chunk-BP6G3YGP.js";import{a as i}from"./chunk-QVGTHPWT.js";import"./chunk-JXNNWCEB.js";import"./chunk-HDVLCRC6.js";import{z as k}from"zod";var c=k.number().int().min(0).max(1e9);function R(e,o){let a=c.parse(e.promptTokens),p=c.parse(e.completionTokens),s=c.parse(e.promptTokensDetails?.cachedTokens??0),t=c.parse(e.promptTokensDetails?.cacheWriteTokens??0),r=c.parse(e.promptTokensDetails?.audioTokens??0),l=c.parse(e.completionTokensDetails?.audioTokens??0),n=c.parse(e.completionTokensDetails?.reasoningTokens??0);if(c.parse(e.totalTokens)!==a+p||s+t+r>a||n+l>p||(e.promptTokensDetails?.videoTokens??0)>0)throw new i("AI_USAGE_UNAVAILABLE","Token pools must conserve usage; video needs an explicit token mapper");return{input:a-s-t-r,output:p-l-(o==="separate"?n:0),cache_read:s,cache_write:t,input_audio:r,output_audio:l,reasoning:o==="separate"?n:0}}function I(e){if(!Number.isFinite(e)||e<0)throw new i("AI_USAGE_UNAVAILABLE","Provider cost must be a nonnegative USD amount");let o=String(e),a=o.includes("e")?e.toFixed(18).replace(/0+$/,"").replace(/\.$/,""):o;if(!/^(0|[1-9]\d{0,11})(\.\d{1,18})?$/.test(a)||Number(a)!==e)throw new i("AI_USAGE_UNAVAILABLE","Provider cost exceeds the supported precision");return a}async function f(e){if(typeof window<"u")throw new i("SERVER_ONLY","OpenRouter accounting requires your backend");if(!["output","separate"].includes(e.reasoning)||!e.modelId||!e.generationId)throw new i("INVALID_REQUEST","Actual model, generation ID and reasoning pricing are required");let o={context:e.context,generationId:e.generationId,modelId:`openrouter/${e.modelId}`,usage:e.usage,tokens:null,quote:null,receipt:null,phase:"captured"};await e.persist(o);let a=e.mapTokens?e.mapTokens(e.usage):R(e.usage,e.reasoning),p=e.usage.cost==null?void 0:I(e.usage.cost),s=e.quote??await e.pricing.quoteTokens({modelId:o.modelId,tokens:a});if(s.pricing.modelId!==o.modelId||Object.keys(a).some(l=>a[l]!==s.tokens[l]))throw new i("INVALID_REQUEST","Saved quote must match the provider model and token pools");await e.persist({...o,tokens:a,quote:s,phase:"quoted"});let t=await e.pricing.trackTokens(e.client,{...e.context,quote:s,providerCostUsd:p,generationId:e.generationId});if(!t.receipt.accepted)throw new i("AI_BALANCE_REJECTED","OpenRouter usage was saved but the balance request was rejected");let r={...o,tokens:a,quote:s,receipt:t,phase:"settled"};return await e.persist(r),r}function T(e){if(typeof window<"u")throw new i("SERVER_ONLY","OpenRouter accounting requires your backend");if(!["output","separate"].includes(e.reasoning))throw new i("INVALID_REQUEST","Reasoning pricing is required");let o=e.openRouter.chat;async function a(t){if(!t.usage||!t.modelId||!t.generationId)throw new i("AI_USAGE_UNAVAILABLE","OpenRouter did not return final usage and the actual model");await f({...e,context:t.context,generationId:t.generationId,modelId:t.modelId.slice(11),usage:t.usage})}let p=async(t,r)=>{let n={context:await e.context(),generationId:null,modelId:null,usage:null,tokens:null,quote:null,receipt:null,phase:"incomplete"},d;try{d=await o.send(t,r)}catch(g){throw await e.persist(n),g}if(!(d instanceof ReadableStream)){if(n={...n,generationId:d.id,modelId:d.model?`openrouter/${d.model}`:null,usage:d.usage??null},!n.usage||!n.modelId)throw await e.persist(n),new i("AI_USAGE_UNAVAILABLE","OpenRouter omitted final accounting");return await a(n),d}let w=d.getReader(),m=!1;return new ReadableStream({async pull(g){try{let{value:u,done:A}=await w.read();if(A){if(m=!0,!n.usage||!n.modelId)throw await e.persist(n),new i("AI_USAGE_UNAVAILABLE","OpenRouter stream ended without final accounting");await a(n),g.close();return}if(u.error)throw new i("AI_PROVIDER_ERROR",u.error.message);u.usage&&(n={...n,generationId:u.id,modelId:u.model?`openrouter/${u.model}`:null,usage:u.usage}),g.enqueue(u)}catch(u){m||(m=!0,await e.persist(n)),await w.cancel(u),g.error(u)}},async cancel(g){m||(m=!0,await e.persist(n)),await w.cancel(g)}})},s=new Proxy(o,{get(t,r){return r==="send"?p:Reflect.get(t,r,t)}});return new Proxy(e.openRouter,{get(t,r){return r==="chat"?s:Reflect.get(t,r,t)}})}export{T as createOpenRouterUsageClient,f as trackOpenRouterUsage};
1
+ import"./chunk-CM75TDWK.js";import"./chunk-KLP5TN5O.js";import{a as i}from"./chunk-QVGTHPWT.js";import"./chunk-KSCITFNQ.js";import"./chunk-HDVLCRC6.js";import{z as k}from"zod";var c=k.number().int().min(0).max(1e9);function R(e,o){let a=c.parse(e.promptTokens),p=c.parse(e.completionTokens),s=c.parse(e.promptTokensDetails?.cachedTokens??0),t=c.parse(e.promptTokensDetails?.cacheWriteTokens??0),r=c.parse(e.promptTokensDetails?.audioTokens??0),l=c.parse(e.completionTokensDetails?.audioTokens??0),n=c.parse(e.completionTokensDetails?.reasoningTokens??0);if(c.parse(e.totalTokens)!==a+p||s+t+r>a||n+l>p||(e.promptTokensDetails?.videoTokens??0)>0)throw new i("AI_USAGE_UNAVAILABLE","Token pools must conserve usage; video needs an explicit token mapper");return{input:a-s-t-r,output:p-l-(o==="separate"?n:0),cache_read:s,cache_write:t,input_audio:r,output_audio:l,reasoning:o==="separate"?n:0}}function I(e){if(!Number.isFinite(e)||e<0)throw new i("AI_USAGE_UNAVAILABLE","Provider cost must be a nonnegative USD amount");let o=String(e),a=o.includes("e")?e.toFixed(18).replace(/0+$/,"").replace(/\.$/,""):o;if(!/^(0|[1-9]\d{0,11})(\.\d{1,18})?$/.test(a)||Number(a)!==e)throw new i("AI_USAGE_UNAVAILABLE","Provider cost exceeds the supported precision");return a}async function f(e){if(typeof window<"u")throw new i("SERVER_ONLY","OpenRouter accounting requires your backend");if(!["output","separate"].includes(e.reasoning)||!e.modelId||!e.generationId)throw new i("INVALID_REQUEST","Actual model, generation ID and reasoning pricing are required");let o={context:e.context,generationId:e.generationId,modelId:`openrouter/${e.modelId}`,usage:e.usage,tokens:null,quote:null,receipt:null,phase:"captured"};await e.persist(o);let a=e.mapTokens?e.mapTokens(e.usage):R(e.usage,e.reasoning),p=e.usage.cost==null?void 0:I(e.usage.cost),s=e.quote??await e.pricing.quoteTokens({modelId:o.modelId,tokens:a});if(s.pricing.modelId!==o.modelId||Object.keys(a).some(l=>a[l]!==s.tokens[l]))throw new i("INVALID_REQUEST","Saved quote must match the provider model and token pools");await e.persist({...o,tokens:a,quote:s,phase:"quoted"});let t=await e.pricing.trackTokens(e.client,{...e.context,quote:s,providerCostUsd:p,generationId:e.generationId});if(!t.receipt.accepted)throw new i("AI_BALANCE_REJECTED","OpenRouter usage was saved but the balance request was rejected");let r={...o,tokens:a,quote:s,receipt:t,phase:"settled"};return await e.persist(r),r}function T(e){if(typeof window<"u")throw new i("SERVER_ONLY","OpenRouter accounting requires your backend");if(!["output","separate"].includes(e.reasoning))throw new i("INVALID_REQUEST","Reasoning pricing is required");let o=e.openRouter.chat;async function a(t){if(!t.usage||!t.modelId||!t.generationId)throw new i("AI_USAGE_UNAVAILABLE","OpenRouter did not return final usage and the actual model");await f({...e,context:t.context,generationId:t.generationId,modelId:t.modelId.slice(11),usage:t.usage})}let p=async(t,r)=>{let n={context:await e.context(),generationId:null,modelId:null,usage:null,tokens:null,quote:null,receipt:null,phase:"incomplete"},d;try{d=await o.send(t,r)}catch(g){throw await e.persist(n),g}if(!(d instanceof ReadableStream)){if(n={...n,generationId:d.id,modelId:d.model?`openrouter/${d.model}`:null,usage:d.usage??null},!n.usage||!n.modelId)throw await e.persist(n),new i("AI_USAGE_UNAVAILABLE","OpenRouter omitted final accounting");return await a(n),d}let w=d.getReader(),m=!1;return new ReadableStream({async pull(g){try{let{value:u,done:A}=await w.read();if(A){if(m=!0,!n.usage||!n.modelId)throw await e.persist(n),new i("AI_USAGE_UNAVAILABLE","OpenRouter stream ended without final accounting");await a(n),g.close();return}if(u.error)throw new i("AI_PROVIDER_ERROR",u.error.message);u.usage&&(n={...n,generationId:u.id,modelId:u.model?`openrouter/${u.model}`:null,usage:u.usage}),g.enqueue(u)}catch(u){m||(m=!0,await e.persist(n)),await w.cancel(u),g.error(u)}},async cancel(g){m||(m=!0,await e.persist(n)),await w.cancel(g)}})},s=new Proxy(o,{get(t,r){return r==="send"?p:Reflect.get(t,r,t)}});return new Proxy(e.openRouter,{get(t,r){return r==="chat"?s:Reflect.get(t,r,t)}})}export{T as createOpenRouterUsageClient,f as trackOpenRouterUsage};
package/dist/page.js CHANGED
@@ -1 +1 @@
1
- import{d as o,e as r,f as e,g as f}from"./chunk-AX2PJEJP.js";import"./chunk-53C6LI3D.js";import"./chunk-Z5CW2N7E.js";import"./chunk-JXNNWCEB.js";import"./chunk-DSPLGTQI.js";import"./chunk-HDVLCRC6.js";export{f as createPageExperiments,o as mergeQueryStrings,r as pageAttributes,e as readPayload};
1
+ import{d as o,e as r,f as e,g as f}from"./chunk-HCI6E3R7.js";import"./chunk-GQ7B25L5.js";import"./chunk-77ZUEWYE.js";import"./chunk-KSCITFNQ.js";import"./chunk-DSPLGTQI.js";import"./chunk-HDVLCRC6.js";export{f as createPageExperiments,o as mergeQueryStrings,r as pageAttributes,e as readPayload};
@@ -1 +1 @@
1
- import{b as Je,c as Ke}from"./chunk-JGG4R75K.js";import{c as ze,d as He,e as Be,f as le,g as Qe,h as je,i as Ge,k as We}from"./chunk-6DTGBDYG.js";import{c as qe,f as Ve,g as Ie,h as Fe}from"./chunk-YAVWELIV.js";import"./chunk-BP6G3YGP.js";import{a as S}from"./chunk-QVGTHPWT.js";import{Z}from"./chunk-JXNNWCEB.js";import{a as z}from"./chunk-DSPLGTQI.js";import{La as ee,Na as _e,j as J,o as ke,z as X}from"./chunk-HDVLCRC6.js";async function Ye(o,n,C){if(n.status!=="complete")throw new S("INVALID_RESPONSE","A verified completed purchase is required");let y=o?X.parse(o):null;if(await C.onComplete?.(n),!y||!C.check)return;let m=X.parse(await C.check());if(m.internal_feature_id!==y.internal_feature_id||m.quantity!==y.quantity||y.observation!==void 0&&(m.observation===void 0||m.observation.requirementDigest!==y.observation.requirementDigest||m.observation.authority!==y.observation.authority||ke(m.observation.subject)!==ke(y.observation.subject)))throw new S("INVALID_RESPONSE","The access requirement changed");m.allowed&&await C.onAccessGranted?.(m)}var at={none:0,sm:4,md:8,lg:14,full:9999},ot={system:"system-ui,sans-serif",serif:"Georgia,serif",rounded:"ui-rounded,system-ui,sans-serif",mono:"ui-monospace,monospace"};function st(o){let[n,C,y]=[1,3,5].map(m=>{let g=Number.parseInt(o.slice(m,m+2),16)/255;return g<=.03928?g/12.92:((g+.055)/1.055)**2.4});return .2126*n+.7152*C+.0722*y}function Xe(o){let n=st(o.primary),C=(n+.05)/.05>1.05/(n+.05)?"#111318":"#FFFFFF",y=`color-mix(in srgb, ${o.text} 22%, ${o.background})`,m=`${at[o.radius]}px`,g=`appearance:none;margin:0;min-height:44px;padding:10px 18px;border:0;border-radius:${m};font:inherit;font-size:15px;font-weight:600;line-height:1.25;cursor:pointer;touch-action:manipulation`;return{root:`width:100%;box-sizing:border-box;background:${o.background};color:${o.text};font:14px/1.5 ${ot[o.font]}`,controls:"display:flex;gap:12px;padding:0 20px 12px;align-items:center;flex-wrap:wrap",message:"flex:1 1 200px;min-width:0;margin:0;font-size:13px",panel:`flex:1 0 100%;box-sizing:border-box;display:flex;flex-direction:column;gap:8px;padding:16px;border:1px solid ${y};border-radius:${m}`,summary:"margin:0;font-size:15px;font-weight:600",terms:"display:flex;flex-direction:column;gap:4px;font-size:13px;opacity:.72",actions:"display:flex;gap:8px;flex-wrap:wrap;margin-top:4px",primary:`${g};background:${o.primary};color:${C}`,secondary:`${g};background:transparent;color:${o.text};box-shadow:inset 0 0 0 1px ${y}`,link:`${g};background:transparent;color:${o.text};opacity:.72;font-weight:500`}}function Ae(o){o.style.opacity=o.disabled?".55":"",o.style.cursor=o.disabled?"not-allowed":"pointer"}function Re(o){return Object.entries(o.document.buttons).filter(([,n])=>n.type==="checkout"&&n.product.type==="fixed"&&!Z(n.product,{},o.capabilities)).map(([n])=>n)}async function It(o,n,C){let y=We(o.ownerDocument),m=()=>{v.finish("dismissed"),y()},g=()=>m(),v=Qe(o,n,"paywall",()=>{m(),z(n.onDismiss)});n.signal?.throwIfAborted(),n.signal?.addEventListener("abort",g,{once:!0});let H=null,$,w,Se;try{if(v.start(!0),v.cancelled)throw new DOMException("Presentation cancelled","AbortError");if(H=n.check?X.parse(await v.wait(n.check(),le)):null,H?.allowed)return v.finish("skipped"),n.signal?.removeEventListener("abort",g),y(),await n.onAccessGranted?.(H),{check:H,host:null};let[e,t]=await Promise.allSettled([v.wait(import("./screen-renderer-TEVGVUT5.js")),v.wait(n.start().then(i=>(v.cancelled&&i.destroy(),i)),le)]);if(e.status==="rejected")throw t.status==="fulfilled"&&t.value.destroy(),e.reason;if(t.status==="rejected")throw t.reason;Se=e.value,$=t.value,n.signal?.throwIfAborted(),$.signal?.throwIfAborted(),$.signal?.addEventListener("abort",g,{once:!0});let u=$.view??await v.wait($.refresh(),le);if(!u)throw new S("INVALID_RESPONSE","Paywall presentation is missing");$.signal?.throwIfAborted(),w=u}catch(e){throw v.finish("error",e),n.signal?.removeEventListener("abort",g),$?.signal?.removeEventListener("abort",g),$?.destroy(),y(),e}let r=$,{mountScreenPreview:Ze}=Se,l=o.ownerDocument,ue=new AbortController,L=l.createElement("section"),de=l.createElement("div"),_=l.createElement("div"),x=l.createElement("p"),p=l.createElement("button"),P=l.createElement("button"),h=l.createElement("dialog"),a=w.document.screen.strings.defaultLocale.startsWith("zh"),Te=a?"\u6B63\u5728\u5904\u7406\u2026":"Processing\u2026",T=Xe(w.document.screen.theme);L.dataset.indianaPaywall="",L.setAttribute("aria-label",w.document.name),L.style.cssText=T.root,_.style.cssText=T.controls,x.style.cssText=T.message,x.setAttribute("role","status"),P.style.cssText=T.link,P.textContent=a?"\u5173\u95ED":"Close",p.style.cssText=T.secondary,p.textContent=a?"\u91CD\u8BD5":"Retry",p.hidden=!0,_.append(x,p,P),L.append(de,_);let B=w.document.presentation,Q,Oe,pe=!1,De=JSON.stringify(w.capabilities);function fe(e){if(d)return;w=e;let t=JSON.stringify(e.capabilities);t!==De&&(Q?.updateCapabilities(e.capabilities,Re(e)),De=t),tt(e)}let k;function $e(){let e=l.defaultView;k?.responsive&&e&&Q?.resizeViewport?.(e.innerHeight,e.innerWidth)}let d=!1,te=!1,I=null,ne=!1,Le=!1,q=!1,me,he=!1,M,j;function et(){return te||d||M||he?{type:"recover",operationId:r.operation?.operationId??r.quote?.operationId??null,requestId:null}:Ie(r)}let A=()=>!d&&!ne&&!M&&n.canInteract?.()!==!1,ye=!1,s=null,U=null;function tt(e){r.quote||r.operation||(x.textContent=Object.values(e.capabilities.plans).some(t=>t.available)?"":a?"\u5F53\u524D\u8D26\u53F7\u6682\u65E0\u53EF\u8D2D\u4E70\u7684\u65B9\u6848\u3002":"No plans are currently available for this account.")}let we=new Map;async function be(e){if(!(!A()||!e.checkoutUrl||we.get(e.operationId)===e.checkoutUrl)){we.set(e.operationId,e.checkoutUrl);try{n.onCheckoutUrl?await n.onCheckoutUrl(e.checkoutUrl):l.defaultView?.location.assign(e.checkoutUrl)}catch(t){throw we.delete(e.operationId),t}}}let G=e=>{x.textContent=e instanceof Error?e.message:a?"\u8BF7\u6C42\u5931\u8D25":"Request failed",z(n.onError,e),p.hidden=s===null},re=new WeakMap;function ie(e){te=e;for(let t of U?.querySelectorAll("button")??[])e?(re.set(t,t.disabled),t.disabled=!0):re.has(t)&&(t.disabled=re.get(t),re.delete(t)),Ae(t)}function ge(){x.textContent=a?"\u6682\u65F6\u65E0\u6CD5\u64CD\u4F5C\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\u3002":"This action is unavailable right now. Try again in a moment."}async function nt(e){if(n.beforeAction)try{await n.beforeAction()}catch(t){throw s=e,t}}async function N(e){if(!(te||d)){if(!A()){ge();return}ie(!0),p.hidden=!0,x.textContent=Te;try{if(await nt(e),d)return;if(!A()){s=e,p.hidden=!1,ge();return}await e()}catch(t){d||G(t)}finally{ie(!1),x.textContent===Te&&(x.textContent="")}}}async function rt(e){await Ye(H,e,n)}function Ue(e){return Ie(r).type==="recording"||Ve({quote:r.quote,operation:e,requestId:null,pending:!1,destroyed:!1,canReselect:r.canReselect}).type==="recording"}async function O(e){if(d)return;if(!A()){s=async()=>O(await r.read()),p.hidden=!1;return}if(x.textContent=Ke(e.status,a),Ue(e)){let i=e.merchantExecution?.type==="purchase"&&e.merchantExecution.recordingStatus==="failed";x.textContent=i?a?"\u4ED8\u6B3E\u548C\u5546\u6237\u5904\u7406\u5DF2\u5B8C\u6210\uFF0C\u4F46\u4EA4\u6613\u8BB0\u5F55\u5931\u8D25\u3002\u8BF7\u8054\u7CFB\u5546\u6237\u4FEE\u590D\uFF0C\u52FF\u91CD\u590D\u8D2D\u4E70\u3002":"Payment and fulfillment succeeded, but recording failed. Contact the merchant to repair this purchase; do not buy again.":a?"\u4ED8\u6B3E\u548C\u5546\u6237\u5904\u7406\u5DF2\u5B8C\u6210\uFF0C\u6B63\u5728\u786E\u8BA4\u4EA4\u6613\u8BB0\u5F55\u3002\u8BF7\u52FF\u91CD\u590D\u8D2D\u4E70\u3002":"Payment and merchant fulfillment are complete. Recording is pending confirmation; do not purchase again.",p.textContent=a?"\u67E5\u8BE2\u8BB0\u5F55":"Check recording",s=async()=>O(await r.read()),p.hidden=!1;return}if(e.problem){let i=e.problem;s=ae,p.textContent=a?"\u68C0\u67E5\u5E76\u6062\u590D\u539F\u64CD\u4F5C":"Check and recover original purchase",G(new S(i.code,i.reason==="RESULT_UNKNOWN"?a?"\u4ED8\u6B3E\u7ED3\u679C\u5C1A\u672A\u786E\u5B9A\uFF0C\u8BF7\u6062\u590D\u539F\u64CD\u4F5C\uFF0C\u6682\u52FF\u91CD\u590D\u8D2D\u4E70\u3002":"The payment result is unknown. Recover the original purchase before buying again.":i.phase==="fulfillment"?a?"\u4ED8\u6B3E\u5DF2\u8BB0\u5F55\uFF0C\u5546\u6237\u6743\u76CA\u5904\u7406\u9700\u8981\u6838\u5BF9\u3002":"Payment was recorded. Access fulfillment needs attention.":i.code==="CAPABILITY_UNAVAILABLE"?a?"\u5546\u6237\u5C1A\u4E0D\u652F\u6301\u672C\u6B21\u8D2D\u4E70\u6240\u9700\u7684\u5B8C\u6574\u80FD\u529B\uFF0C\u8BF7\u5904\u7406\u540E\u6062\u590D\u539F\u64CD\u4F5C\u3002":"The merchant does not currently support all actions required by this purchase. Recover the original purchase after this is resolved.":i.code==="NOT_CONFIGURED"?a?"\u4ED8\u6B3E\u670D\u52A1\u8FDE\u63A5\u9700\u8981\u5904\u7406\uFF0C\u8BF7\u8054\u7CFB\u5546\u6237\u540E\u6062\u590D\u539F\u64CD\u4F5C\u3002":"The payment connection needs attention. Contact the merchant, then recover the original purchase.":a?"\u539F\u8D2D\u4E70\u64CD\u4F5C\u9700\u8981\u5904\u7406\uFF0C\u8BF7\u67E5\u8BE2\u6216\u6062\u590D\u6B64\u64CD\u4F5C\u3002":"The original purchase needs attention. Check or recover this operation.",void 0,void 0,i));return}if(e.merchantExecution?.type==="purchase"&&e.merchantExecution.paymentStatus==="succeeded"&&!["applied","not_applicable"].includes(e.merchantExecution.fulfillmentStatus)&&(x.textContent=a?"\u4ED8\u6B3E\u5DF2\u8BB0\u5F55\uFF0C\u6B63\u5728\u7B49\u5F85\u5546\u6237\u5B8C\u6210\u5904\u7406\u3002":"Payment was recorded. Waiting for merchant fulfillment."),e.status==="complete"){s=null,await rt(e);return}if(e.status!=="pending"){if(r.canReselect===!1){x.textContent=a?"\u6B63\u5728\u6838\u5BF9\u539F\u8D2D\u4E70\u7ED3\u679C":"Checking the original purchase result",p.textContent=a?"\u67E5\u8BE2\u7ED3\u679C":"Check result",s=async()=>O(await r.read()),p.hidden=!1;return}p.textContent=a?"\u91CD\u8BD5":"Retry",s=null,I=null;return}await be(e);let t=Date.now()+6e5,u=2e3;pe=!0,z(n.onObservationChange,!0);try{for(;!d&&Date.now()<t;){if(await Je(u,l,ue.signal),d)return;if(!A()){s=async()=>O(await r.read()),p.hidden=!1;return}let i=await r.read();if(!i.problem&&i.status==="pending"&&await be(i),i.status!=="pending"||i.problem||Ue(i)){await O(i);return}u=Math.min(u*1.5,3e4)}}finally{pe=!1,z(n.onObservationChange,!1)}s=async()=>O(await r.read()),p.hidden=!1}async function ve(){let e=await r.read();if(d)return;if(!A()){s=ve,p.hidden=!1;return}let t=r.quote;if(t&&qe(e,{operationId:t.operationId,currency:t.currency},"The original purchase operation changed"),t&&e.status==="pending"&&e.quoteFinalized===!1&&!e.confirmedAt&&!e.checkoutUrl&&!e.nativePurchase&&!e.merchantExecution&&!e.problem&&!r.pendingCancellation){Ne(t);return}await O(e)}async function ae(){U?.remove(),U=null,s=ae;let e=await r.confirm();if(!A()){s=ae,p.hidden=!1;return}if(e.problem){await O(e);return}if(e.status==="pending"){if(e.checkoutUrl)await be(e);else if(e.execution&&e.execution.provider!=="merchant"||e.nativePurchase){if(!n.onPurchase)throw new S("PURCHASE_HANDLER_REQUIRED","Provide the merchant or native purchase handler");await n.onPurchase({operation:e,signal:ue.signal})}}s=async()=>O(await r.read()),await O(e)}function Ne(e){U?.remove();let t=!(Date.parse(e.expiresAt)>Date.now());x.textContent=t?a?"\u6B64\u62A5\u4EF7\u5DF2\u8FC7\u671F\u3002\u8BF7\u5148\u53D6\u6D88\uFF0C\u518D\u91CD\u65B0\u9009\u62E9\u3002":"This quote has expired. Cancel it, then choose again.":"";let u=l.createElement("div"),i=l.createElement("button"),b=l.createElement("button"),V=l.createElement("div"),K=l.createElement("p"),R=e.merchantTerms,oe=R?R.totalMinor:e.charge?.totalMinor??e.catalogAmountMinor-(e.discount?.amountMinor??0),se=a?"zh-CN":"en",ce=R?.subscriptionTerms?.items??[],Y=R?ce.length===1&&ce[0]?.amountMinor===oe&&ce[0]:e.lines.length===1&&e.lines[0]?.catalogAmountMinor===oe&&e.lines[0];K.textContent=e.lines.map(c=>c.productName).join(", ")+" \xB7 "+(oe===null?a?`${J(R.subtotalMinor-R.discountMinor,e.currency)} + \u5F85\u786E\u8BA4\u7A0E\u8D39`:`${J(R.subtotalMinor-R.discountMinor,e.currency)} + tax confirmed at checkout`:J(oe,e.currency)+(Y?ee(Y.interval,se,Y.intervalCount??1):"")),i.textContent=a?"\u786E\u8BA4\u8D2D\u4E70":"Confirm purchase",i.disabled=t,b.textContent=a?"\u53D6\u6D88":"Cancel",u.style.cssText=T.panel,K.style.cssText=T.summary,V.style.cssText=T.actions,i.style.cssText=T.primary,b.style.cssText=T.secondary,Ae(i),i.onclick=()=>{N(ae)};let Me=async()=>{let c=await r.cancel();d||(u.remove(),U=null,await O(c))};b.onclick=()=>{s=Me,N(Me)};let D=l.createElement("div");if(D.style.cssText=T.terms,R){for(let f of ce){if(f===Y)continue;let E=l.createElement("p");E.textContent=J(f.amountMinor,e.currency)+ee(f.interval,se,f.intervalCount),D.append(E)}let c=R.subscriptionTerms?.trial;if(c){let f=l.createElement("p");f.textContent=a?`\u8BD5\u7528 ${c.days} \u5929\uFF1B${c.cardRequired?"\u9700\u8981\u63D0\u4F9B\u4ED8\u6B3E\u65B9\u5F0F":"\u65E0\u9700\u63D0\u4F9B\u4ED8\u6B3E\u65B9\u5F0F"}`:`Trial days: ${c.days}; ${c.cardRequired?"a payment method is required":"no payment method is required"}`,D.append(f)}for(let f of[...R.expectedEffects.map(E=>E.description),...R.requiredConsents.map(E=>E.summary)]){let E=l.createElement("p");E.textContent=f,D.append(E)}}else{for(let c of e.lines){if(c!==Y){let f=l.createElement("p");f.textContent=`${c.productName} \xB7 ${J(c.catalogAmountMinor,e.currency)}${ee(c.interval,se,c.intervalCount??1)}`,D.append(f)}for(let f of c.prepaid??[]){let E=l.createElement("p"),F=r.view?.capabilities.plans[c.productVersionId]?.prepaid?.find(it=>it.internalFeatureId===f.internal_feature_id);E.textContent=`${F?.name??f.internal_feature_id} \xB7 ${f.quantity} ${a?"\u4EFD":"packs"} \xD7 ${f.terms.units}`,F&&(E.textContent+=ee(F.reset==="week"||F.reset==="month"||F.reset==="year"?F.reset:"one_time",se,F.resetCount)),D.append(E)}if(c.trial){let f=l.createElement("p");f.textContent=a?`\u8BD5\u7528 ${c.trial.days} \u5929\uFF1B${c.trial.cardRequired?"\u9700\u8981\u63D0\u4F9B\u4ED8\u6B3E\u65B9\u5F0F":"\u65E0\u9700\u63D0\u4F9B\u4ED8\u6B3E\u65B9\u5F0F"}`:`Trial days: ${c.trial.days}; ${c.trial.cardRequired?"a payment method is required":"no payment method is required"}`,D.append(f)}}if(!e.charge){let c=l.createElement("p");c.textContent=a?"\u76EE\u5F55\u4EF7\u683C\uFF1B\u6700\u7EC8\u91D1\u989D\u4EE5\u7ED3\u8D26\u65F6\u7A0E\u8D39\u548C\u8BD5\u7528\u89C4\u5219\u4E3A\u51C6\u3002":"Catalog price; the final charge depends on checkout taxes and trial terms.",D.append(c)}}for(let c of D.children)c.style.margin="0";V.append(i,b),u.append(K,...D.childElementCount?[D]:[],V),_.prepend(u),u.scrollIntoView?.({block:"nearest"}),i.focus({preventScroll:!0}),U=u,s=null}async function xe(){if(!I)return;if(s=xe,!ye){let t=r.view,u=t?.document.buttons[I.actionId],i=t&&u?.type==="checkout"?Z(u.product,I.selection,t.capabilities):null;if(!i)throw new S("PRODUCT_UNAVAILABLE","Choose an available Product in this purchase area");let b=await n.resolveOfferId?.({actionId:I.actionId,productVersionId:i});if(d)return;b!==void 0&&(I.offerId=b),ye=!0}if(!A()){p.hidden=!1;return}let e=await r.preview(I);d||Ne(e)}function W(e="destroy"){d||(d=!0,n.signal?.removeEventListener("abort",g),r.signal?.removeEventListener("abort",g),v.finish("dismissed"),Oe?.(),ue.abort(),k?.destroy(),Q?.destroy(),r.destroy(),h.open&&h.close(),h.remove(),L.remove(),y(),e==="dismiss"&&z(n.onDismiss))}m=W;async function Ce(){if(!q||d||ne||M==="closing"||!M&&!A())return;if(!C){W("dismiss");return}let e=l.createElement("p");e.setAttribute("role","status"),e.textContent=a?"\u6B63\u5728\u5173\u95ED\u2026":"Closing\u2026",j||(j=l.createElement("div"),j.style.cssText=_.style.cssText,_.replaceWith(j),de.inert=!0),j.replaceChildren(e,P),M="closing",P.setAttribute("aria-disabled","true"),P.focus({preventScroll:!0});try{await C.dismiss()}catch(t){d||z(n.onError,t)}d||(M="retry",e.textContent=a?"\u672A\u80FD\u786E\u8BA4\u5173\u95ED\uFF0C\u8BF7\u91CD\u8BD5\u3002":"Could not confirm closure. Try again.",P.textContent=a?"\u91CD\u8BD5\u5173\u95ED":"Retry closing",P.removeAttribute("aria-disabled"))}P.onclick=()=>{Ce()},h.addEventListener("cancel",e=>{e.preventDefault(),Ce()}),p.onclick=()=>{s&&N(s)};function Pe(e){v.finish("error",e),W()}function Ee(){if(!(!Le||q||d||ne||k&&!A()))try{let e=t=>{me?.(),k&&(h.showModal(),k.responsive&&h.focus({preventScroll:!0}),!t&&n.loading!=="host"&&He(h,k.type,k.responsive)),q=!0};C?C.present(()=>v.present(()=>e(!0))):v.present(e)}catch(e){Pe(e),G(e)}}try{if(B.type==="inline")me=Ge(L,o),o.append(L);else{let t={sm:420,md:640,lg:900};h.style.cssText=`padding:0;border:0;max-width:calc(100vw - 32px);max-height:calc(100dvh - 32px);overflow:auto;width:${"size"in B?t[B.size]+"px":"100vw"}`,h.setAttribute("aria-label",w.document.name),P.textContent="\xD7",P.setAttribute("aria-label",a?"\u5173\u95ED":"Close"),Be(P,w.document.screen.theme),h.append(P,L),o.append(h),k=ze(h,{...w.document.screen,presentation:B},$e),k.latch(),me=je(h)}Q=Ze(de,{mode:"live",rendererUrl:r.webViewUrl,title:w.document.name,hostPresentation:()=>k?.type??B.type,onResize:t=>{k?.responsive&&k.setContentHeight(t+(j??_).getBoundingClientRect().height)},onAction(t,u={}){if(!q||d||M)return;if(!A()){ge();return}let i=r.view,b=i?.document.buttons[t];if(!b)return;if(b.type==="close"){N(async()=>{await n.onAction?.(t),W(n.onAction?"action":"dismiss")});return}if(b.type==="action"){s=async()=>{if(b.action.type==="event"){if(!n.onEvent)throw new S("EVENT_HANDLER_REQUIRED","Provide the event handler");await n.onEvent(b.action.event)}else n.onOpenUrl?await n.onOpenUrl(b.action.url):l.defaultView?.location.assign(b.action.url);await n.onAction?.(t),s=null},N(s);return}if(U&&r.canReselect===!1){x.textContent=a?"\u8BF7\u5148\u786E\u8BA4\u6216\u53D6\u6D88\u5F53\u524D\u8D2D\u4E70\u3002":"Confirm or cancel the current purchase first.",U.scrollIntoView?.({block:"nearest"}),U.querySelector("button")?.focus({preventScroll:!0});return}if((r.quote||I)&&r.canReselect===!1){s=r.quote?ve:xe,N(s);return}let V=i&&Z(b.product,u,i.capabilities);if(!i||!V){G(new S("PRODUCT_UNAVAILABLE","Choose an available Product in this purchase area"));return}if(n.onPurchaseIntent){s=null,N(async()=>{let K={actionId:t,productVersionId:V,selection:structuredClone(u),featureQuantities:_e(i.document.screen,V,u,i.capabilities)};he=!0,await n.onPurchaseIntent(K)});return}if(I&&I.actionId!==t){G(new S("COMMAND_PENDING","Finish the current purchase"));return}I||(I={requestId:crypto.randomUUID(),actionId:t,selection:u},ye=!1),N(xe)},onEscape:()=>{Ce()},onError:t=>{let u=new Error(t);!q&&!d&&Pe(u),G(u)},onRendered:t=>{t&&h.setAttribute("aria-label",t),Le=!0,Ee()}}),$e(),Q.update(w.document.screen,w.document.screen.strings.defaultLocale,{capabilities:w.capabilities,unavailableActions:Re(w),serverInput:{bindings:[],answers:{}}}),Oe=r.subscribe?.(fe),fe(r.view??w),await v.wait(Q.ready);let e=r.operation;(r.quote||e&&(e.confirmedAt||e.checkoutUrl||e.status==="complete"))&&(s=ve,N(s))}catch(e){throw Pe(e),e}return{check:H,host:{get observing(){return pe},get recovery(){return et()},async prepareFallback(){if(te||d||M||he)return{type:"recover",operationId:r.operation?.operationId??r.quote?.operationId??null,requestId:null};ie(!0);try{let e=await Fe(r);return e.type==="native"&&W(),e}finally{ie(!1)}},setSuspended(e){ne=e,L.hidden=e,e&&h.open?h.close():!e&&!q?Ee():!e&&!d&&q&&B.type!=="inline"&&!h.open&&h.showModal()},destroy:W,refresh:async()=>{if(!A()){if(r.view)return r.view;throw new S("PRECONDITION_FAILED","Paywall presentation is suspended")}let e=await r.refresh();return fe(e),Ee(),e}}}}export{It as showPaywall};
1
+ import{b as Je,c as Ke}from"./chunk-JGG4R75K.js";import{c as ze,d as He,e as Be,f as le,g as Qe,h as je,i as Ge,k as We}from"./chunk-6DTGBDYG.js";import{c as qe,f as Ve,g as Ie,h as Fe}from"./chunk-YAVWELIV.js";import"./chunk-KLP5TN5O.js";import{a as S}from"./chunk-QVGTHPWT.js";import{Z}from"./chunk-KSCITFNQ.js";import{a as z}from"./chunk-DSPLGTQI.js";import{La as ee,Na as _e,j as J,o as ke,z as X}from"./chunk-HDVLCRC6.js";async function Ye(o,n,P){if(n.status!=="complete")throw new S("INVALID_RESPONSE","A verified completed purchase is required");let y=o?X.parse(o):null;if(await P.onComplete?.(n),!y||!P.check)return;let m=X.parse(await P.check());if(m.internal_feature_id!==y.internal_feature_id||m.quantity!==y.quantity||y.observation!==void 0&&(m.observation===void 0||m.observation.requirementDigest!==y.observation.requirementDigest||m.observation.authority!==y.observation.authority||ke(m.observation.subject)!==ke(y.observation.subject)))throw new S("INVALID_RESPONSE","The access requirement changed");m.allowed&&await P.onAccessGranted?.(m)}var at={none:0,sm:4,md:8,lg:14,full:9999},ot={system:"system-ui,sans-serif",serif:"Georgia,serif",rounded:"ui-rounded,system-ui,sans-serif",mono:"ui-monospace,monospace"};function st(o){let[n,P,y]=[1,3,5].map(m=>{let g=Number.parseInt(o.slice(m,m+2),16)/255;return g<=.03928?g/12.92:((g+.055)/1.055)**2.4});return .2126*n+.7152*P+.0722*y}function Xe(o){let n=st(o.primary),P=(n+.05)/.05>1.05/(n+.05)?"#111318":"#FFFFFF",y=`color-mix(in srgb, ${o.text} 22%, ${o.background})`,m=`${at[o.radius]}px`,g=`appearance:none;margin:0;min-height:44px;padding:10px 18px;border:0;border-radius:${m};font:inherit;font-size:15px;font-weight:600;line-height:1.25;cursor:pointer;touch-action:manipulation`;return{root:`width:100%;box-sizing:border-box;background:${o.background};color:${o.text};font:14px/1.5 ${ot[o.font]}`,controls:"display:flex;gap:12px;padding:0 20px 12px;align-items:center;flex-wrap:wrap",message:"flex:1 1 200px;min-width:0;margin:0;font-size:13px",panel:`flex:1 0 100%;box-sizing:border-box;display:flex;flex-direction:column;gap:8px;padding:16px;border:1px solid ${y};border-radius:${m}`,summary:"margin:0;font-size:15px;font-weight:600",terms:"display:flex;flex-direction:column;gap:4px;font-size:13px;opacity:.72",actions:"display:flex;gap:8px;flex-wrap:wrap;margin-top:4px",primary:`${g};background:${o.primary};color:${P}`,secondary:`${g};background:transparent;color:${o.text};box-shadow:inset 0 0 0 1px ${y}`,link:`${g};background:transparent;color:${o.text};opacity:.72;font-weight:500`}}function Ae(o){o.style.opacity=o.disabled?".55":"",o.style.cursor=o.disabled?"not-allowed":"pointer"}function Re(o){return Object.entries(o.document.buttons).filter(([,n])=>n.type==="checkout"&&n.product.type==="fixed"&&!Z(n.product,{},o.capabilities)).map(([n])=>n)}async function It(o,n,P){let y=We(o.ownerDocument),m=()=>{v.finish("dismissed"),y()},g=()=>m(),v=Qe(o,n,"paywall",()=>{m(),z(n.onDismiss)});n.signal?.throwIfAborted(),n.signal?.addEventListener("abort",g,{once:!0});let H=null,$,w,Se;try{if(v.start(!0),v.cancelled)throw new DOMException("Presentation cancelled","AbortError");if(H=n.check?X.parse(await v.wait(n.check(),le)):null,H?.allowed)return v.finish("skipped"),n.signal?.removeEventListener("abort",g),y(),await n.onAccessGranted?.(H),{check:H,host:null};let[e,t]=await Promise.allSettled([v.wait(import("./screen-renderer-TEVGVUT5.js")),v.wait(n.start().then(i=>(v.cancelled&&i.destroy(),i)),le)]);if(e.status==="rejected")throw t.status==="fulfilled"&&t.value.destroy(),e.reason;if(t.status==="rejected")throw t.reason;Se=e.value,$=t.value,n.signal?.throwIfAborted(),$.signal?.throwIfAborted(),$.signal?.addEventListener("abort",g,{once:!0});let u=$.view??await v.wait($.refresh(),le);if(!u)throw new S("INVALID_RESPONSE","Paywall presentation is missing");$.signal?.throwIfAborted(),w=u}catch(e){throw v.finish("error",e),n.signal?.removeEventListener("abort",g),$?.signal?.removeEventListener("abort",g),$?.destroy(),y(),e}let r=$,{mountScreenPreview:Ze}=Se,l=o.ownerDocument,ue=new AbortController,L=l.createElement("section"),de=l.createElement("div"),_=l.createElement("div"),x=l.createElement("p"),p=l.createElement("button"),C=l.createElement("button"),h=l.createElement("dialog"),a=w.document.screen.strings.defaultLocale.startsWith("zh"),Te=a?"\u6B63\u5728\u5904\u7406\u2026":"Processing\u2026",T=Xe(w.document.screen.theme);L.dataset.indianaPaywall="",L.setAttribute("aria-label",w.document.name),L.style.cssText=T.root,_.style.cssText=T.controls,x.style.cssText=T.message,x.setAttribute("role","status"),C.style.cssText=T.link,C.textContent=a?"\u5173\u95ED":"Close",p.style.cssText=T.secondary,p.textContent=a?"\u91CD\u8BD5":"Retry",p.hidden=!0,_.append(x,p,C),L.append(de,_);let B=w.document.presentation,Q,Oe,pe=!1,De=JSON.stringify(w.capabilities);function fe(e){if(d)return;w=e;let t=JSON.stringify(e.capabilities);t!==De&&(Q?.updateCapabilities(e.capabilities,Re(e)),De=t),tt(e)}let k;function $e(){let e=l.defaultView;k?.responsive&&e&&Q?.resizeViewport?.(e.innerHeight,e.innerWidth)}let d=!1,te=!1,I=null,ne=!1,Le=!1,q=!1,me,he=!1,M,j;function et(){return te||d||M||he?{type:"recover",operationId:r.operation?.operationId??r.quote?.operationId??null,requestId:null}:Ie(r)}let A=()=>!d&&!ne&&!M&&n.canInteract?.()!==!1,ye=!1,s=null,U=null;function tt(e){r.quote||r.operation||(x.textContent=Object.values(e.capabilities.plans).some(t=>t.available)?"":a?"\u5F53\u524D\u8D26\u53F7\u6682\u65E0\u53EF\u8D2D\u4E70\u7684\u65B9\u6848\u3002":"No plans are currently available for this account.")}let we=new Map;async function be(e){if(!(!A()||!e.checkoutUrl||we.get(e.operationId)===e.checkoutUrl)){we.set(e.operationId,e.checkoutUrl);try{n.onCheckoutUrl?await n.onCheckoutUrl(e.checkoutUrl):l.defaultView?.location.assign(e.checkoutUrl)}catch(t){throw we.delete(e.operationId),t}}}let G=e=>{x.textContent=e instanceof Error?e.message:a?"\u8BF7\u6C42\u5931\u8D25":"Request failed",z(n.onError,e),p.hidden=s===null},re=new WeakMap;function ie(e){te=e;for(let t of U?.querySelectorAll("button")??[])e?(re.set(t,t.disabled),t.disabled=!0):re.has(t)&&(t.disabled=re.get(t),re.delete(t)),Ae(t)}function ge(){x.textContent=a?"\u6682\u65F6\u65E0\u6CD5\u64CD\u4F5C\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\u3002":"This action is unavailable right now. Try again in a moment."}async function nt(e){if(n.beforeAction)try{await n.beforeAction()}catch(t){throw s=e,t}}async function N(e){if(!(te||d)){if(!A()){ge();return}ie(!0),p.hidden=!0,x.textContent=Te;try{if(await nt(e),d)return;if(!A()){s=e,p.hidden=!1,ge();return}await e()}catch(t){d||G(t)}finally{ie(!1),x.textContent===Te&&(x.textContent="")}}}async function rt(e){await Ye(H,e,n)}function Ue(e){return Ie(r).type==="recording"||Ve({quote:r.quote,operation:e,requestId:null,pending:!1,destroyed:!1,canReselect:r.canReselect}).type==="recording"}async function O(e){if(d)return;if(!A()){s=async()=>O(await r.read()),p.hidden=!1;return}if(x.textContent=Ke(e.status,a),Ue(e)){let i=e.merchantExecution?.type==="purchase"&&e.merchantExecution.recordingStatus==="failed";x.textContent=i?a?"\u4ED8\u6B3E\u548C\u5546\u6237\u5904\u7406\u5DF2\u5B8C\u6210\uFF0C\u4F46\u4EA4\u6613\u8BB0\u5F55\u5931\u8D25\u3002\u8BF7\u8054\u7CFB\u5546\u6237\u4FEE\u590D\uFF0C\u52FF\u91CD\u590D\u8D2D\u4E70\u3002":"Payment and fulfillment succeeded, but recording failed. Contact the merchant to repair this purchase; do not buy again.":a?"\u4ED8\u6B3E\u548C\u5546\u6237\u5904\u7406\u5DF2\u5B8C\u6210\uFF0C\u6B63\u5728\u786E\u8BA4\u4EA4\u6613\u8BB0\u5F55\u3002\u8BF7\u52FF\u91CD\u590D\u8D2D\u4E70\u3002":"Payment and merchant fulfillment are complete. Recording is pending confirmation; do not purchase again.",p.textContent=a?"\u67E5\u8BE2\u8BB0\u5F55":"Check recording",s=async()=>O(await r.read()),p.hidden=!1;return}if(e.problem){let i=e.problem;s=ae,p.textContent=a?"\u68C0\u67E5\u5E76\u6062\u590D\u539F\u64CD\u4F5C":"Check and recover original purchase",G(new S(i.code,i.reason==="RESULT_UNKNOWN"?a?"\u4ED8\u6B3E\u7ED3\u679C\u5C1A\u672A\u786E\u5B9A\uFF0C\u8BF7\u6062\u590D\u539F\u64CD\u4F5C\uFF0C\u6682\u52FF\u91CD\u590D\u8D2D\u4E70\u3002":"The payment result is unknown. Recover the original purchase before buying again.":i.phase==="fulfillment"?a?"\u4ED8\u6B3E\u5DF2\u8BB0\u5F55\uFF0C\u5546\u6237\u6743\u76CA\u5904\u7406\u9700\u8981\u6838\u5BF9\u3002":"Payment was recorded. Access fulfillment needs attention.":i.code==="CAPABILITY_UNAVAILABLE"?a?"\u5546\u6237\u5C1A\u4E0D\u652F\u6301\u672C\u6B21\u8D2D\u4E70\u6240\u9700\u7684\u5B8C\u6574\u80FD\u529B\uFF0C\u8BF7\u5904\u7406\u540E\u6062\u590D\u539F\u64CD\u4F5C\u3002":"The merchant does not currently support all actions required by this purchase. Recover the original purchase after this is resolved.":i.code==="NOT_CONFIGURED"?a?"\u4ED8\u6B3E\u670D\u52A1\u8FDE\u63A5\u9700\u8981\u5904\u7406\uFF0C\u8BF7\u8054\u7CFB\u5546\u6237\u540E\u6062\u590D\u539F\u64CD\u4F5C\u3002":"The payment connection needs attention. Contact the merchant, then recover the original purchase.":a?"\u539F\u8D2D\u4E70\u64CD\u4F5C\u9700\u8981\u5904\u7406\uFF0C\u8BF7\u67E5\u8BE2\u6216\u6062\u590D\u6B64\u64CD\u4F5C\u3002":"The original purchase needs attention. Check or recover this operation.",void 0,void 0,i));return}if(e.merchantExecution?.type==="purchase"&&e.merchantExecution.paymentStatus==="succeeded"&&!["applied","not_applicable"].includes(e.merchantExecution.fulfillmentStatus)&&(x.textContent=a?"\u4ED8\u6B3E\u5DF2\u8BB0\u5F55\uFF0C\u6B63\u5728\u7B49\u5F85\u5546\u6237\u5B8C\u6210\u5904\u7406\u3002":"Payment was recorded. Waiting for merchant fulfillment."),e.status==="complete"){s=null,await rt(e);return}if(e.status!=="pending"){if(r.canReselect===!1){x.textContent=a?"\u6B63\u5728\u6838\u5BF9\u539F\u8D2D\u4E70\u7ED3\u679C":"Checking the original purchase result",p.textContent=a?"\u67E5\u8BE2\u7ED3\u679C":"Check result",s=async()=>O(await r.read()),p.hidden=!1;return}p.textContent=a?"\u91CD\u8BD5":"Retry",s=null,I=null;return}await be(e);let t=Date.now()+6e5,u=2e3;pe=!0,z(n.onObservationChange,!0);try{for(;!d&&Date.now()<t;){if(await Je(u,l,ue.signal),d)return;if(!A()){s=async()=>O(await r.read()),p.hidden=!1;return}let i=await r.read();if(!i.problem&&i.status==="pending"&&await be(i),i.status!=="pending"||i.problem||Ue(i)){await O(i);return}u=Math.min(u*1.5,3e4)}}finally{pe=!1,z(n.onObservationChange,!1)}s=async()=>O(await r.read()),p.hidden=!1}async function ve(){let e=await r.read();if(d)return;if(!A()){s=ve,p.hidden=!1;return}let t=r.quote;if(t&&qe(e,{operationId:t.operationId,currency:t.currency},"The original purchase operation changed"),t&&e.status==="pending"&&e.quoteFinalized===!1&&!e.confirmedAt&&!e.checkoutUrl&&!e.nativePurchase&&!e.merchantExecution&&!e.problem&&!r.pendingCancellation){Ne(t);return}await O(e)}async function ae(){U?.remove(),U=null,s=ae;let e=await r.confirm();if(!A()){s=ae,p.hidden=!1;return}if(e.problem){await O(e);return}if(e.status==="pending"){if(e.checkoutUrl)await be(e);else if(e.execution&&e.execution.provider!=="merchant"||e.nativePurchase){if(!n.onPurchase)throw new S("PURCHASE_HANDLER_REQUIRED","Provide the merchant or native purchase handler");await n.onPurchase({operation:e,signal:ue.signal})}}s=async()=>O(await r.read()),await O(e)}function Ne(e){U?.remove();let t=!(Date.parse(e.expiresAt)>Date.now());x.textContent=t?a?"\u6B64\u62A5\u4EF7\u5DF2\u8FC7\u671F\u3002\u8BF7\u5148\u53D6\u6D88\uFF0C\u518D\u91CD\u65B0\u9009\u62E9\u3002":"This quote has expired. Cancel it, then choose again.":"";let u=l.createElement("div"),i=l.createElement("button"),b=l.createElement("button"),V=l.createElement("div"),K=l.createElement("p"),R=e.merchantTerms,oe=R?R.totalMinor:e.charge?.totalMinor??e.catalogAmountMinor-(e.discount?.amountMinor??0),se=a?"zh-CN":"en",ce=R?.subscriptionTerms?.items??[],Y=R?ce.length===1&&ce[0]?.amountMinor===oe&&ce[0]:e.lines.length===1&&e.lines[0]?.catalogAmountMinor===oe&&e.lines[0];K.textContent=e.lines.map(c=>c.productName).join(", ")+" \xB7 "+(oe===null?a?`${J(R.subtotalMinor-R.discountMinor,e.currency)} + \u5F85\u786E\u8BA4\u7A0E\u8D39`:`${J(R.subtotalMinor-R.discountMinor,e.currency)} + tax confirmed at checkout`:J(oe,e.currency)+(Y?ee(Y.interval,se,Y.intervalCount??1):"")),i.textContent=a?"\u786E\u8BA4\u8D2D\u4E70":"Confirm purchase",i.disabled=t,b.textContent=a?"\u53D6\u6D88":"Cancel",u.style.cssText=T.panel,K.style.cssText=T.summary,V.style.cssText=T.actions,i.style.cssText=T.primary,b.style.cssText=T.secondary,Ae(i),i.onclick=()=>{N(ae)};let Me=async()=>{let c=await r.cancel();d||(u.remove(),U=null,await O(c))};b.onclick=()=>{s=Me,N(Me)};let D=l.createElement("div");if(D.style.cssText=T.terms,R){for(let f of ce){if(f===Y)continue;let E=l.createElement("p");E.textContent=J(f.amountMinor,e.currency)+ee(f.interval,se,f.intervalCount),D.append(E)}let c=R.subscriptionTerms?.trial;if(c){let f=l.createElement("p");f.textContent=a?`\u8BD5\u7528 ${c.days} \u5929\uFF1B${c.cardRequired?"\u9700\u8981\u63D0\u4F9B\u4ED8\u6B3E\u65B9\u5F0F":"\u65E0\u9700\u63D0\u4F9B\u4ED8\u6B3E\u65B9\u5F0F"}`:`Trial days: ${c.days}; ${c.cardRequired?"a payment method is required":"no payment method is required"}`,D.append(f)}for(let f of[...R.expectedEffects.map(E=>E.description),...R.requiredConsents.map(E=>E.summary)]){let E=l.createElement("p");E.textContent=f,D.append(E)}}else{for(let c of e.lines){if(c!==Y){let f=l.createElement("p");f.textContent=`${c.productName} \xB7 ${J(c.catalogAmountMinor,e.currency)}${ee(c.interval,se,c.intervalCount??1)}`,D.append(f)}for(let f of c.prepaid??[]){let E=l.createElement("p"),F=r.view?.capabilities.plans[c.productVersionId]?.prepaid?.find(it=>it.internalFeatureId===f.internal_feature_id);E.textContent=`${F?.name??f.internal_feature_id} \xB7 ${f.quantity} ${a?"\u4EFD":"packs"} \xD7 ${f.terms.units}`,F&&(E.textContent+=ee(F.reset==="week"||F.reset==="month"||F.reset==="year"?F.reset:"one_time",se,F.resetCount)),D.append(E)}if(c.trial){let f=l.createElement("p");f.textContent=a?`\u8BD5\u7528 ${c.trial.days} \u5929\uFF1B${c.trial.cardRequired?"\u9700\u8981\u63D0\u4F9B\u4ED8\u6B3E\u65B9\u5F0F":"\u65E0\u9700\u63D0\u4F9B\u4ED8\u6B3E\u65B9\u5F0F"}`:`Trial days: ${c.trial.days}; ${c.trial.cardRequired?"a payment method is required":"no payment method is required"}`,D.append(f)}}if(!e.charge){let c=l.createElement("p");c.textContent=a?"\u76EE\u5F55\u4EF7\u683C\uFF1B\u6700\u7EC8\u91D1\u989D\u4EE5\u7ED3\u8D26\u65F6\u7A0E\u8D39\u548C\u8BD5\u7528\u89C4\u5219\u4E3A\u51C6\u3002":"Catalog price; the final charge depends on checkout taxes and trial terms.",D.append(c)}}for(let c of D.children)c.style.margin="0";V.append(i,b),u.append(K,...D.childElementCount?[D]:[],V),_.prepend(u),u.scrollIntoView?.({block:"nearest"}),i.focus({preventScroll:!0}),U=u,s=null}async function xe(){if(!I)return;if(s=xe,!ye){let t=r.view,u=t?.document.buttons[I.actionId],i=t&&u?.type==="checkout"?Z(u.product,I.selection,t.capabilities):null;if(!i)throw new S("PRODUCT_UNAVAILABLE","Choose an available Product in this purchase area");let b=await n.resolveOfferId?.({actionId:I.actionId,productVersionId:i});if(d)return;b!==void 0&&(I.offerId=b),ye=!0}if(!A()){p.hidden=!1;return}let e=await r.preview(I);d||Ne(e)}function W(e="destroy"){d||(d=!0,n.signal?.removeEventListener("abort",g),r.signal?.removeEventListener("abort",g),v.finish("dismissed"),Oe?.(),ue.abort(),k?.destroy(),Q?.destroy(),r.destroy(),h.open&&h.close(),h.remove(),L.remove(),y(),e==="dismiss"&&z(n.onDismiss))}m=W;async function Ce(){if(!q||d||ne||M==="closing"||!M&&!A())return;if(!P){W("dismiss");return}let e=l.createElement("p");e.setAttribute("role","status"),e.textContent=a?"\u6B63\u5728\u5173\u95ED\u2026":"Closing\u2026",j||(j=l.createElement("div"),j.style.cssText=_.style.cssText,_.replaceWith(j),de.inert=!0),j.replaceChildren(e,C),M="closing",C.setAttribute("aria-disabled","true"),C.focus({preventScroll:!0});try{await P.dismiss()}catch(t){d||z(n.onError,t)}d||(M="retry",e.textContent=a?"\u672A\u80FD\u786E\u8BA4\u5173\u95ED\uFF0C\u8BF7\u91CD\u8BD5\u3002":"Could not confirm closure. Try again.",C.textContent=a?"\u91CD\u8BD5\u5173\u95ED":"Retry closing",C.removeAttribute("aria-label"),C.removeAttribute("aria-disabled"))}C.onclick=()=>{Ce()},h.addEventListener("cancel",e=>{e.preventDefault(),Ce()}),p.onclick=()=>{s&&N(s)};function Pe(e){v.finish("error",e),W()}function Ee(){if(!(!Le||q||d||ne||k&&!A()))try{let e=t=>{me?.(),k&&(h.showModal(),k.responsive&&h.focus({preventScroll:!0}),!t&&n.loading!=="host"&&He(h,k.type,k.responsive)),q=!0};P?P.present(()=>v.present(()=>e(!0))):v.present(e)}catch(e){Pe(e),G(e)}}try{if(B.type==="inline")me=Ge(L,o),o.append(L);else{let t={sm:420,md:640,lg:900};h.style.cssText=`padding:0;border:0;max-width:calc(100vw - 32px);max-height:calc(100dvh - 32px);overflow:auto;width:${"size"in B?t[B.size]+"px":"100vw"}`,h.setAttribute("aria-label",w.document.name),C.textContent="\xD7",C.setAttribute("aria-label",a?"\u5173\u95ED":"Close"),Be(C,w.document.screen.theme),h.append(C,L),o.append(h),k=ze(h,{...w.document.screen,presentation:B},$e),k.latch(),me=je(h)}Q=Ze(de,{mode:"live",rendererUrl:r.webViewUrl,title:w.document.name,hostPresentation:()=>k?.type??B.type,onResize:t=>{k?.responsive&&k.setContentHeight(t+(j??_).getBoundingClientRect().height)},onAction(t,u={}){if(!q||d||M)return;if(!A()){ge();return}let i=r.view,b=i?.document.buttons[t];if(!b)return;if(b.type==="close"){N(async()=>{await n.onAction?.(t),W(n.onAction?"action":"dismiss")});return}if(b.type==="action"){s=async()=>{if(b.action.type==="event"){if(!n.onEvent)throw new S("EVENT_HANDLER_REQUIRED","Provide the event handler");await n.onEvent(b.action.event)}else n.onOpenUrl?await n.onOpenUrl(b.action.url):l.defaultView?.location.assign(b.action.url);await n.onAction?.(t),s=null},N(s);return}if(U&&r.canReselect===!1){x.textContent=a?"\u8BF7\u5148\u786E\u8BA4\u6216\u53D6\u6D88\u5F53\u524D\u8D2D\u4E70\u3002":"Confirm or cancel the current purchase first.",U.scrollIntoView?.({block:"nearest"}),U.querySelector("button")?.focus({preventScroll:!0});return}if((r.quote||I)&&r.canReselect===!1){s=r.quote?ve:xe,N(s);return}let V=i&&Z(b.product,u,i.capabilities);if(!i||!V){G(new S("PRODUCT_UNAVAILABLE","Choose an available Product in this purchase area"));return}if(n.onPurchaseIntent){s=null,N(async()=>{let K={actionId:t,productVersionId:V,selection:structuredClone(u),featureQuantities:_e(i.document.screen,V,u,i.capabilities)};he=!0,await n.onPurchaseIntent(K)});return}if(I&&I.actionId!==t){G(new S("COMMAND_PENDING","Finish the current purchase"));return}I||(I={requestId:crypto.randomUUID(),actionId:t,selection:u},ye=!1),N(xe)},onEscape:()=>{Ce()},onError:t=>{let u=new Error(t);!q&&!d&&Pe(u),G(u)},onRendered:t=>{t&&h.setAttribute("aria-label",t),Le=!0,Ee()}}),$e(),Q.update(w.document.screen,w.document.screen.strings.defaultLocale,{capabilities:w.capabilities,unavailableActions:Re(w),serverInput:{bindings:[],answers:{}}}),Oe=r.subscribe?.(fe),fe(r.view??w),await v.wait(Q.ready);let e=r.operation;(r.quote||e&&(e.confirmedAt||e.checkoutUrl||e.status==="complete"))&&(s=ve,N(s))}catch(e){throw Pe(e),e}return{check:H,host:{get observing(){return pe},get recovery(){return et()},async prepareFallback(){if(te||d||M||he)return{type:"recover",operationId:r.operation?.operationId??r.quote?.operationId??null,requestId:null};ie(!0);try{let e=await Fe(r);return e.type==="native"&&W(),e}finally{ie(!1)}},setSuspended(e){ne=e,L.hidden=e,e&&h.open?h.close():!e&&!q?Ee():!e&&!d&&q&&B.type!=="inline"&&!h.open&&h.showModal()},destroy:W,refresh:async()=>{if(!A()){if(r.view)return r.view;throw new S("PRECONDITION_FAILED","Paywall presentation is suspended")}let e=await r.refresh();return fe(e),Ee(),e}}}}export{It as showPaywall};
@@ -1,11 +1,11 @@
1
- import { f as createCustomerClient, d as createFunnelClient } from './funnel-process-client-C6q2FqFc.js';
2
- export { F as FunnelProcessAdapter, a as FunnelProcessOptions, c as createFunnelProcess } from './funnel-process-client-C6q2FqFc.js';
3
- import { I as IndianaOptions, s as SessionCredentials, z as Scope, u as createFunnelRunController, p as PaywallStartInput, w as createPaywallSession } from './funnel-local-client-WOMhUCjI.js';
4
- export { c as FunnelCommandStorage, F as FunnelRunController, m as LocalFunnelClientOptions, n as LongplayError, o as PaywallPurchaseInput, P as PaywallSession, q as PushHost, r as PushJournal, t as createFeatureClient, v as createLocalFunnelClient } from './funnel-local-client-WOMhUCjI.js';
1
+ import { f as createCustomerClient, d as createFunnelClient } from './funnel-process-client-C87pmLC9.js';
2
+ export { F as FunnelProcessAdapter, a as FunnelProcessOptions, c as createFunnelProcess } from './funnel-process-client-C87pmLC9.js';
3
+ import { I as IndianaOptions, s as SessionCredentials, z as Scope, u as createFunnelRunController, p as PaywallStartInput, w as createPaywallSession } from './funnel-local-client-BYdKGnMb.js';
4
+ export { c as FunnelCommandStorage, F as FunnelRunController, m as LocalFunnelClientOptions, n as LongplayError, o as PaywallPurchaseInput, P as PaywallSession, q as PushHost, r as PushJournal, t as createFeatureClient, v as createLocalFunnelClient } from './funnel-local-client-BYdKGnMb.js';
5
5
  import { z } from 'zod';
6
6
  import { J as JsonValue } from './growth-rules-B4YYy64R.js';
7
7
  export { C as ConfigurationStorage, b as ConfigurationSyncOptions, c as createConfigurationSync } from './configuration-sync-eEFj_oKG.js';
8
- import './api-C65zMJI6.js';
8
+ import './api-rZ_QoNQi.js';
9
9
  import './screen-DRP7nsrQ.js';
10
10
  import 'zod/v4';
11
11
  import './coupon-Btz_KFKp.js';
@@ -1 +1 @@
1
- import{b as S,c as A,d as T}from"./chunk-LBGCSWVF.js";import{d as b,n as C,o as E,p as x,r as L}from"./chunk-JNML7SY4.js";import"./chunk-YAVWELIV.js";import"./chunk-BP6G3YGP.js";import{a as r}from"./chunk-QVGTHPWT.js";import"./chunk-Z5CW2N7E.js";import{Da as P}from"./chunk-JXNNWCEB.js";import"./chunk-DSPLGTQI.js";import{a as R}from"./chunk-HDVLCRC6.js";function k(t,d){let n,a=0,m=-1,l,i=!1,y=()=>{if(i)throw new r("CLOSED","Native host was destroyed");if(!t.nativeModule)throw new r("CAPABILITY_UNAVAILABLE","Link IndianaBridge and supply nativeModule");return t.nativeModule},o=()=>new r("IDENTITY_CHANGED","Customer identity changed during the native operation"),h=d.subscribeIdentity(()=>{a++,m=-1;let e=a;n&&t.nativeModule&&n.then(c=>t.nativeModule.reset(c,e)).catch(()=>{})}),I=t.nativeEvents?.(e=>{!n||!t.nativeModule||typeof e?.requestId!="string"||(async()=>{let c=await n;if(e.instanceId!==c)return;if(e.kind==="credential"){let w=a,f=null;try{if(!i&&e.revision===w){let N=await d.access();!i&&a===w&&(f=N)}}finally{await t.nativeModule.provideCredential(c,e.requestId,f)}return}let s=!1,u=a;try{if(i||e.revision!==u||!t.onNativeAction)throw o();await t.onNativeAction(e.action),s=!i&&a===u}finally{await t.nativeModule.acknowledge(c,e.requestId,s)}})().catch(()=>{})});async function p(e,c={}){let s=y();if(d.snapshot()&&!t.nativeEvents)throw new r("CAPABILITY_UNAVAILABLE","Supply nativeEvents to share credential refresh with the native host");let u=a,w=await d.access();if(i||a!==u)throw o();if(!n){let v=s.create(JSON.stringify({baseUrl:t.baseUrl??"https://api.longplayai.com",scope:t.scope,timeout:(t.timeoutMs??15e3)/1e3,credentialEvents:!!t.nativeEvents}));n=v,v.catch(()=>{n===v&&(n=void 0)})}let f=await n;if(i||a!==u)throw o();if(m!==u){if(!l||l.epoch!==u){let O=(async()=>{if(await s.identify(f,JSON.stringify({revision:u,credentials:w})),i||a!==u)throw await s.reset(f,u),o();m=u})();l={epoch:u,task:O}}let v=l;try{await v.task}finally{l===v&&(l=void 0)}}let N=await s.invoke(f,e,JSON.stringify(c));if(i||a!==u)throw o();try{return JSON.parse(N)}catch{throw new r("INVALID_RESPONSE","Native host returned invalid JSON")}}async function g(e,c){let s=await p(e,c);if(!s||typeof s!="object"||Array.isArray(s)||s.status!=="complete"&&s.status!=="dismissed")throw new r("INVALID_RESPONSE","Native presentation returned an invalid result");return s}return{showFunnel(e){return g("showFunnel",{runToken:e})},showPaywall(e){return g("showPaywall",e)},showContent(e){return g("showContent",e)},purchaseSubscription(e,c){return p("purchaseSubscription",{operationId:e,accepted:c})},switchSubscription(e,c){return p("switchSubscription",{operationId:e,accepted:c})},restorePurchases(){return p("restorePurchases")},manageSubscriptions(e){return p("manageSubscriptions",e?{productId:e}:{})},async dismiss(){a++,m=-1,n&&await y().reset(await n,a)},async destroy(){i||(i=!0,a++,h(),I?.(),n&&t.nativeModule&&await t.nativeModule.destroy(await n))}}}var M=P.trackUsage.request.shape.command,U=P.trackUsage.response;function F(t){let d=R.parse(t.scope),n=S({...t,scope:d}),a={...t,scope:d,session:n.session},m=k(t,n.session),l=0,i=!1;n.subscribeIdentity(()=>{l++});let y=()=>{if(i)throw new r("CLOSED","SDK client was destroyed");let o=n.session.peek();if(!o)throw new r("UNAUTHENTICATED","Identify the Customer first");return o};return{...n,native:m,async destroy(){i||(i=!0,l++,n.destroy(),await m.destroy())},funnel(){return A({...a,customerToken:y()})},resumeFunnel(o){return y(),C({...a,runToken:o})},paywall(o){return E(a,{...o,customerToken:y()})},async trackUsage(o){if(y(),!t.usageReporter)throw new r("INVALID_REQUEST","Configure your authenticated backend usageReporter");let h=M.parse(o),I=l,p;try{p=await t.usageReporter(h)}catch(e){throw I!==l?new r("IDENTITY_CHANGED","Customer identity changed during usage reporting"):e}if(I!==l)throw new r("IDENTITY_CHANGED","Customer identity changed during usage reporting");let g=U.parse(p);if(g.scope.projectId!==d.projectId||g.scope.environment!==d.environment)throw new r("INVALID_RESPONSE","Usage response scope differs");return g}}}export{r as LongplayError,x as createConfigurationSync,b as createFeatureClient,T as createFunnelProcess,L as createLocalFunnelClient,F as createLongplayReactNative};
1
+ import{b as S,c as A,d as T}from"./chunk-NO5GW7GX.js";import{d as b,n as C,o as E,p as x,r as L}from"./chunk-O5XTOWFZ.js";import"./chunk-YAVWELIV.js";import"./chunk-KLP5TN5O.js";import{a as r}from"./chunk-QVGTHPWT.js";import"./chunk-77ZUEWYE.js";import{Da as P}from"./chunk-KSCITFNQ.js";import"./chunk-DSPLGTQI.js";import{a as R}from"./chunk-HDVLCRC6.js";function k(t,d){let n,a=0,m=-1,l,i=!1,y=()=>{if(i)throw new r("CLOSED","Native host was destroyed");if(!t.nativeModule)throw new r("CAPABILITY_UNAVAILABLE","Link IndianaBridge and supply nativeModule");return t.nativeModule},o=()=>new r("IDENTITY_CHANGED","Customer identity changed during the native operation"),h=d.subscribeIdentity(()=>{a++,m=-1;let e=a;n&&t.nativeModule&&n.then(c=>t.nativeModule.reset(c,e)).catch(()=>{})}),I=t.nativeEvents?.(e=>{!n||!t.nativeModule||typeof e?.requestId!="string"||(async()=>{let c=await n;if(e.instanceId!==c)return;if(e.kind==="credential"){let w=a,f=null;try{if(!i&&e.revision===w){let N=await d.access();!i&&a===w&&(f=N)}}finally{await t.nativeModule.provideCredential(c,e.requestId,f)}return}let s=!1,u=a;try{if(i||e.revision!==u||!t.onNativeAction)throw o();await t.onNativeAction(e.action),s=!i&&a===u}finally{await t.nativeModule.acknowledge(c,e.requestId,s)}})().catch(()=>{})});async function p(e,c={}){let s=y();if(d.snapshot()&&!t.nativeEvents)throw new r("CAPABILITY_UNAVAILABLE","Supply nativeEvents to share credential refresh with the native host");let u=a,w=await d.access();if(i||a!==u)throw o();if(!n){let v=s.create(JSON.stringify({baseUrl:t.baseUrl??"https://api.longplayai.com",scope:t.scope,timeout:(t.timeoutMs??15e3)/1e3,credentialEvents:!!t.nativeEvents}));n=v,v.catch(()=>{n===v&&(n=void 0)})}let f=await n;if(i||a!==u)throw o();if(m!==u){if(!l||l.epoch!==u){let O=(async()=>{if(await s.identify(f,JSON.stringify({revision:u,credentials:w})),i||a!==u)throw await s.reset(f,u),o();m=u})();l={epoch:u,task:O}}let v=l;try{await v.task}finally{l===v&&(l=void 0)}}let N=await s.invoke(f,e,JSON.stringify(c));if(i||a!==u)throw o();try{return JSON.parse(N)}catch{throw new r("INVALID_RESPONSE","Native host returned invalid JSON")}}async function g(e,c){let s=await p(e,c);if(!s||typeof s!="object"||Array.isArray(s)||s.status!=="complete"&&s.status!=="dismissed")throw new r("INVALID_RESPONSE","Native presentation returned an invalid result");return s}return{showFunnel(e){return g("showFunnel",{runToken:e})},showPaywall(e){return g("showPaywall",e)},showContent(e){return g("showContent",e)},purchaseSubscription(e,c){return p("purchaseSubscription",{operationId:e,accepted:c})},switchSubscription(e,c){return p("switchSubscription",{operationId:e,accepted:c})},restorePurchases(){return p("restorePurchases")},manageSubscriptions(e){return p("manageSubscriptions",e?{productId:e}:{})},async dismiss(){a++,m=-1,n&&await y().reset(await n,a)},async destroy(){i||(i=!0,a++,h(),I?.(),n&&t.nativeModule&&await t.nativeModule.destroy(await n))}}}var M=P.trackUsage.request.shape.command,U=P.trackUsage.response;function F(t){let d=R.parse(t.scope),n=S({...t,scope:d}),a={...t,scope:d,session:n.session},m=k(t,n.session),l=0,i=!1;n.subscribeIdentity(()=>{l++});let y=()=>{if(i)throw new r("CLOSED","SDK client was destroyed");let o=n.session.peek();if(!o)throw new r("UNAUTHENTICATED","Identify the Customer first");return o};return{...n,native:m,async destroy(){i||(i=!0,l++,n.destroy(),await m.destroy())},funnel(){return A({...a,customerToken:y()})},resumeFunnel(o){return y(),C({...a,runToken:o})},paywall(o){return E(a,{...o,customerToken:y()})},async trackUsage(o){if(y(),!t.usageReporter)throw new r("INVALID_REQUEST","Configure your authenticated backend usageReporter");let h=M.parse(o),I=l,p;try{p=await t.usageReporter(h)}catch(e){throw I!==l?new r("IDENTITY_CHANGED","Customer identity changed during usage reporting"):e}if(I!==l)throw new r("IDENTITY_CHANGED","Customer identity changed during usage reporting");let g=U.parse(p);if(g.scope.projectId!==d.projectId||g.scope.environment!==d.environment)throw new r("INVALID_RESPONSE","Usage response scope differs");return g}}}export{r as LongplayError,x as createConfigurationSync,b as createFeatureClient,T as createFunnelProcess,L as createLocalFunnelClient,F as createLongplayReactNative};