@tinkerlandai/longplay-sdk 0.10.18 → 0.10.19

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 (55) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +9 -3
  3. package/README.zh-CN.md +1 -1
  4. package/dist/{ai-usage-D7BUuP1H.d.ts → ai-usage-DPGx5otD.d.ts} +3 -3
  5. package/dist/{api-CIbhe8RY.d.ts → api-G8EA_ueL.d.ts} +3596 -200
  6. package/dist/chunk-2JBNOE2D.js +1 -0
  7. package/dist/chunk-4SWGHICJ.js +17 -0
  8. package/dist/chunk-5OD42XQS.js +1 -0
  9. package/dist/{chunk-OMHZBCS3.js → chunk-A7U4Z6EH.js} +1 -1
  10. package/dist/{chunk-LHBBSD77.js → chunk-CCRBXW4M.js} +1 -1
  11. package/dist/chunk-DVKZLOS7.js +1 -0
  12. package/dist/{chunk-ML6EHT43.js → chunk-EDVR7FPD.js} +1 -1
  13. package/dist/chunk-FISFN5IY.js +1 -0
  14. package/dist/chunk-GSFNAB3W.js +6 -0
  15. package/dist/{chunk-26HU2HXU.js → chunk-KHIQQNTR.js} +1 -1
  16. package/dist/{chunk-6HWNW6FJ.js → chunk-LNSFRQ6G.js} +1 -1
  17. package/dist/chunk-W2Z3UVW3.js +1 -0
  18. package/dist/{chunk-T5COWMDA.js → chunk-XIYNQHN7.js} +1 -1
  19. package/dist/{chunk-P6HCD5OQ.js → chunk-XXBN76NP.js} +1 -1
  20. package/dist/{chunk-E4LUW6KP.js → chunk-YNMSSQQY.js} +1 -1
  21. package/dist/{content-DLYNJIEB.js → content-E2OWWKDG.js} +1 -1
  22. package/dist/{customer-page-km5f1PJZ.d.ts → customer-page-BV5EvCUY.d.ts} +20 -0
  23. package/dist/{funnel-local-client-CAuNpJ-e.d.ts → funnel-local-client-DjvVzCfH.d.ts} +14039 -312
  24. package/dist/{funnel-node-evaluation-BLnJp8vj.d.ts → funnel-node-evaluation-D9FwkMa3.d.ts} +425 -1
  25. package/dist/funnel-process-client-bO9Wfumi.d.ts +62372 -0
  26. package/dist/funnel-runtime-host-FOM4Z7ZK.js +1 -0
  27. package/dist/index.d.ts +322 -23334
  28. package/dist/index.js +1 -1
  29. package/dist/native-shell.js +1 -1
  30. package/dist/openrouter.d.ts +2 -2
  31. package/dist/openrouter.js +1 -1
  32. package/dist/page.js +1 -1
  33. package/dist/paywall-OUIB7SVI.js +1 -0
  34. package/dist/popup.d.ts +2 -2
  35. package/dist/popup.js +1 -1
  36. package/dist/react-native.d.ts +41 -38098
  37. package/dist/react-native.js +1 -1
  38. package/dist/screen-renderer-ZNELQB64.js +1 -0
  39. package/dist/server.d.ts +6860 -298
  40. package/dist/server.js +1 -1
  41. package/dist/visual.js +1 -1
  42. package/package.json +1 -1
  43. package/dist/chunk-4ZUMMPHV.js +0 -1
  44. package/dist/chunk-EEZLS2YP.js +0 -1
  45. package/dist/chunk-JVQVQHV2.js +0 -6
  46. package/dist/chunk-KYXX676W.js +0 -1
  47. package/dist/chunk-LC2VUKYM.js +0 -1
  48. package/dist/chunk-N4HZ55YU.js +0 -1
  49. package/dist/chunk-PFHS7HK3.js +0 -17
  50. package/dist/chunk-VVW2J2GL.js +0 -1
  51. package/dist/funnel-process-client-C9EIwNTr.d.ts +0 -20575
  52. package/dist/funnel-runtime-host-FVOUCR35.js +0 -1
  53. package/dist/paywall-6Q3VLXXL.js +0 -1
  54. package/dist/screen-renderer-IZ3VJGU6.js +0 -1
  55. package/dist/{coupon-fA1QujHt.d.ts → coupon-Btz_KFKp.d.ts} +1 -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-CIbhe8RY.js';
4
- import { c as createAiPricing, A as AiUsageContext, a as AiTokenUsage, b as AiTokenQuote } from './ai-usage-D7BUuP1H.js';
3
+ import { F as FoundationApi } from './api-G8EA_ueL.js';
4
+ import { c as createAiPricing, A as AiUsageContext, a as AiTokenUsage, b as AiTokenQuote } from './ai-usage-DPGx5otD.js';
5
5
  import './screen-DRP7nsrQ.js';
6
6
  import 'zod';
7
7
  import 'zod/v4';
@@ -1 +1 @@
1
- import"./chunk-P6HCD5OQ.js";import"./chunk-E4LUW6KP.js";import{a as i}from"./chunk-26HU2HXU.js";import"./chunk-JVQVQHV2.js";import"./chunk-PFHS7HK3.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-XXBN76NP.js";import"./chunk-YNMSSQQY.js";import{a as i}from"./chunk-KHIQQNTR.js";import"./chunk-GSFNAB3W.js";import"./chunk-4SWGHICJ.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-OMHZBCS3.js";import"./chunk-6HWNW6FJ.js";import"./chunk-DSPLGTQI.js";import"./chunk-LHBBSD77.js";import"./chunk-JVQVQHV2.js";import"./chunk-PFHS7HK3.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-A7U4Z6EH.js";import"./chunk-LNSFRQ6G.js";import"./chunk-DSPLGTQI.js";import"./chunk-CCRBXW4M.js";import"./chunk-GSFNAB3W.js";import"./chunk-4SWGHICJ.js";export{f as createPageExperiments,o as mergeQueryStrings,r as pageAttributes,e as readPayload};
@@ -0,0 +1 @@
1
+ import{b as Pe}from"./chunk-SSLZKIIU.js";import{b as ve,c as ge}from"./chunk-XIYNQHN7.js";import{c as ye,f as we,g as ae,h as be}from"./chunk-FISFN5IY.js";import"./chunk-YNMSSQQY.js";import{a as g}from"./chunk-KHIQQNTR.js";import{a as ie}from"./chunk-DSPLGTQI.js";import{Z as z}from"./chunk-GSFNAB3W.js";import{La as j,Na as he,j as L,o as re,z as $}from"./chunk-4SWGHICJ.js";async function Ce(E,r,k){if(r.status!=="complete")throw new g("INVALID_RESPONSE","A verified completed purchase is required");let x=E?$.parse(E):null;if(await k.onComplete?.(r),!x||!k.check)return;let I=$.parse(await k.check());if(I.internal_feature_id!==x.internal_feature_id||I.quantity!==x.quantity||x.observation!==void 0&&(I.observation===void 0||I.observation.requirementDigest!==x.observation.requirementDigest||I.observation.authority!==x.observation.authority||re(I.observation.subject)!==re(x.observation.subject)))throw new g("INVALID_RESPONSE","The access requirement changed");I.allowed&&await k.onAccessGranted?.(I)}function oe(E){return Object.entries(E.document.buttons).filter(([,r])=>r.type==="checkout"&&r.product.type==="fixed"&&!z(r.product,{},E.capabilities)).map(([r])=>r)}async function ze(E,r){let k=r.check?$.parse(await r.check()):null;if(k?.allowed)return await r.onAccessGranted?.(k),{check:k,host:null};let x=Pe(E.ownerDocument),{mountScreenPreview:I}=await import("./screen-renderer-ZNELQB64.js"),n=await r.start(),b;try{let e=n.view??await n.refresh();if(!e)throw new g("INVALID_RESPONSE","Paywall presentation is missing");b=e}catch(e){throw n.destroy(),x(),e}let c=E.ownerDocument,H=new AbortController,O=c.createElement("section"),se=c.createElement("div"),M=c.createElement("div"),y=c.createElement("p"),l=c.createElement("button"),W=c.createElement("button"),d=c.createElement("dialog"),i=b.document.screen.strings.defaultLocale.startsWith("zh");O.dataset.indianaPaywall="",O.setAttribute("aria-label",b.document.name),O.style.cssText="width:100%;box-sizing:border-box;background:#fff;color:#172033;font:14px/1.5 system-ui,sans-serif",M.style.cssText="display:flex;gap:12px;padding:12px 20px;align-items:center;flex-wrap:wrap",y.setAttribute("role","status"),W.textContent=i?"\u5173\u95ED":"Close",l.textContent=i?"\u91CD\u8BD5":"Retry",l.hidden=!0,M.append(y,l,W),O.append(se,M);let q=b.document.presentation,_,R;function ce(){let e=c.defaultView;R?.responsive&&e&&_?.resizeViewport?.(e.innerHeight,e.innerWidth)}let m=!1,B=!1,v=null,le=!1,K=!1;function Ee(){return B||m||K?{type:"recover",operationId:n.operation?.operationId??n.quote?.operationId??null,requestId:null}:ae(n)}let w=()=>!le&&r.canInteract?.()!==!1,Y=!1,o=null,A=null;function ue(e){n.quote||n.operation||(y.textContent=Object.values(e.capabilities.plans).some(t=>t.available)?"":i?"\u5F53\u524D\u8D26\u53F7\u6682\u65E0\u53EF\u8D2D\u4E70\u7684\u65B9\u6848\u3002":"No plans are currently available for this account.")}let J=new Map;async function X(e){if(!(!w()||!e.checkoutUrl||J.get(e.operationId)===e.checkoutUrl)){J.set(e.operationId,e.checkoutUrl);try{r.onCheckoutUrl?await r.onCheckoutUrl(e.checkoutUrl):c.defaultView?.location.assign(e.checkoutUrl)}catch(t){throw J.delete(e.operationId),t}}}let V=e=>{y.textContent=e instanceof Error?e.message:i?"\u8BF7\u6C42\u5931\u8D25":"Request failed",ie(r.onError,e),l.hidden=o===null},F=new WeakMap;function Q(e){B=e;for(let t of A?.querySelectorAll("button")??[])e?(F.set(t,t.disabled),t.disabled=!0):F.has(t)&&(t.disabled=F.get(t),F.delete(t))}function Z(){y.textContent=i?"\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 ke(e){if(r.beforeAction){y.textContent=i?"\u6B63\u5728\u5904\u7406":"Processing";try{await r.beforeAction()}catch(t){throw o=e,t}y.textContent=""}}async function S(e){if(!(B||m)){if(!w()){Z();return}Q(!0),l.hidden=!0,y.textContent="";try{if(await ke(e),m)return;if(!w()){o=e,l.hidden=!1,Z();return}await e()}catch(t){m||V(t)}finally{Q(!1)}}}async function xe(e){await Ce(k,e,r)}function de(e){return ae(n).type==="recording"||we({quote:n.quote,operation:e,requestId:null,pending:!1,destroyed:!1,canReselect:n.canReselect}).type==="recording"}async function P(e){if(m)return;if(!w()){o=async()=>P(await n.read()),l.hidden=!1;return}if(y.textContent=e.status,de(e)){let a=e.merchantExecution?.type==="purchase"&&e.merchantExecution.recordingStatus==="failed";y.textContent=a?i?"\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.":i?"\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.",l.textContent=i?"\u67E5\u8BE2\u8BB0\u5F55":"Check recording",o=async()=>P(await n.read()),l.hidden=!1;return}if(e.problem){let a=e.problem;o=G,l.textContent=i?"\u68C0\u67E5\u5E76\u6062\u590D\u539F\u64CD\u4F5C":"Check and recover original purchase",V(new g(a.code,a.reason==="RESULT_UNKNOWN"?i?"\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.":a.phase==="fulfillment"?i?"\u4ED8\u6B3E\u5DF2\u8BB0\u5F55\uFF0C\u5546\u6237\u6743\u76CA\u5904\u7406\u9700\u8981\u6838\u5BF9\u3002":"Payment was recorded. Access fulfillment needs attention.":a.code==="CAPABILITY_UNAVAILABLE"?i?"\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.":a.code==="NOT_CONFIGURED"?i?"\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.":i?"\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,a));return}if(e.merchantExecution?.type==="purchase"&&e.merchantExecution.paymentStatus==="succeeded"&&!["applied","not_applicable"].includes(e.merchantExecution.fulfillmentStatus)&&(y.textContent=i?"\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"){o=null,await xe(e);return}if(e.status!=="pending"){if(n.canReselect===!1){y.textContent=i?"\u6B63\u5728\u6838\u5BF9\u539F\u8D2D\u4E70\u7ED3\u679C":"Checking the original purchase result",l.textContent=i?"\u67E5\u8BE2\u7ED3\u679C":"Check result",o=async()=>P(await n.read()),l.hidden=!1;return}l.textContent=i?"\u91CD\u8BD5":"Retry",o=null,v=null;return}await X(e);let t=Date.now()+6e5,p=2e3;for(;!m&&Date.now()<t;){if(await new Promise(u=>{let U=()=>{clearTimeout(h),u()},h=setTimeout(()=>{H.signal.removeEventListener("abort",U),u()},p);H.signal.addEventListener("abort",U,{once:!0})}),m)return;if(!w()){o=async()=>P(await n.read()),l.hidden=!1;return}let a=await n.read();if(!a.problem&&a.status==="pending"&&await X(a),a.status!=="pending"||a.problem||de(a)){await P(a);return}p=Math.min(p*1.5,3e4)}o=async()=>P(await n.read()),l.hidden=!1}async function ee(){let e=await n.read();if(m)return;if(!w()){o=ee,l.hidden=!1;return}let t=n.quote;if(t&&ye(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&&!n.pendingCancellation){pe(t);return}await P(e)}async function G(){A?.remove(),A=null,o=G;let e=await n.confirm();if(!w()){o=G,l.hidden=!1;return}if(e.problem){await P(e);return}if(e.status==="pending"){if(e.checkoutUrl)await X(e);else if(e.execution&&e.execution.provider!=="merchant"||e.nativePurchase){if(!r.onPurchase)throw new g("PURCHASE_HANDLER_REQUIRED","Provide the merchant or native purchase handler");await r.onPurchase({operation:e,signal:H.signal})}}o=async()=>P(await n.read()),await P(e)}function pe(e){A?.remove();let t=!(Date.parse(e.expiresAt)>Date.now());y.textContent=t?i?"\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 p=c.createElement("div"),a=c.createElement("button"),u=c.createElement("button"),U=c.createElement("p"),h=e.merchantTerms,fe=h?h.totalMinor:e.charge?.totalMinor??e.catalogAmountMinor-(e.discount?.amountMinor??0);U.textContent=e.lines.map(s=>s.productName).join(", ")+" \xB7 "+(fe===null?i?`${L(h.subtotalMinor-h.discountMinor,e.currency)} + \u5F85\u786E\u8BA4\u7A0E\u8D39`:`${L(h.subtotalMinor-h.discountMinor,e.currency)} + tax confirmed at checkout`:L(fe,e.currency)),a.textContent=i?"\u786E\u8BA4\u8D2D\u4E70":"Confirm purchase",a.disabled=t,u.textContent=i?"\u53D6\u6D88":"Cancel",a.onclick=()=>{S(G)};let me=async()=>{let s=await n.cancel();m||(p.remove(),A=null,await P(s))};u.onclick=()=>{o=me,S(me)};let T=c.createElement("div");if(h){for(let C of h.subscriptionTerms?.items??[]){let f=c.createElement("p");f.textContent=L(C.amountMinor,e.currency)+j(C.interval,i?"zh-CN":"en",C.intervalCount),T.append(f)}let s=h.subscriptionTerms?.trial;if(s){let C=c.createElement("p");C.textContent=i?`\u8BD5\u7528 ${s.days} \u5929\uFF1B${s.cardRequired?"\u9700\u8981\u63D0\u4F9B\u4ED8\u6B3E\u65B9\u5F0F":"\u65E0\u9700\u63D0\u4F9B\u4ED8\u6B3E\u65B9\u5F0F"}`:`Trial days: ${s.days}; ${s.cardRequired?"a payment method is required":"no payment method is required"}`,T.append(C)}for(let C of[...h.expectedEffects.map(f=>f.description),...h.requiredConsents.map(f=>f.summary)]){let f=c.createElement("p");f.textContent=C,T.append(f)}}else{for(let s of e.lines){let C=c.createElement("p");C.textContent=`${s.productName} \xB7 ${L(s.catalogAmountMinor,e.currency)}${j(s.interval,i?"zh-CN":"en",s.intervalCount??1)}`,T.append(C);for(let f of s.prepaid??[]){let ne=c.createElement("p"),N=n.view?.capabilities.plans[s.productVersionId]?.prepaid?.find(Ie=>Ie.internalFeatureId===f.internal_feature_id);ne.textContent=`${N?.name??f.internal_feature_id} \xB7 ${f.quantity} ${i?"\u4EFD":"packs"} \xD7 ${f.terms.units}`,N&&(ne.textContent+=j(N.reset==="week"||N.reset==="month"||N.reset==="year"?N.reset:"one_time",i?"zh-CN":"en",N.resetCount)),T.append(ne)}if(s.trial){let f=c.createElement("p");f.textContent=i?`\u8BD5\u7528 ${s.trial.days} \u5929\uFF1B${s.trial.cardRequired?"\u9700\u8981\u63D0\u4F9B\u4ED8\u6B3E\u65B9\u5F0F":"\u65E0\u9700\u63D0\u4F9B\u4ED8\u6B3E\u65B9\u5F0F"}`:`Trial days: ${s.trial.days}; ${s.trial.cardRequired?"a payment method is required":"no payment method is required"}`,T.append(f)}}if(!e.charge){let s=c.createElement("p");s.textContent=i?"\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.",T.append(s)}}p.append(U,T,a,u),M.prepend(p),p.scrollIntoView?.({block:"nearest"}),a.focus({preventScroll:!0}),A=p,o=null}async function te(){if(!v)return;if(o=te,!Y){let t=n.view,p=t?.document.buttons[v.actionId],a=t&&p?.type==="checkout"?z(p.product,v.selection,t.capabilities):null;if(!a)throw new g("PRODUCT_UNAVAILABLE","Choose an available Product in this purchase area");let u=await r.resolveOfferId?.({actionId:v.actionId,productVersionId:a});if(m)return;u!==void 0&&(v.offerId=u),Y=!0}if(!w()){l.hidden=!1;return}let e=await n.preview(v);m||pe(e)}function D(e="destroy"){m||(m=!0,H.abort(),R?.destroy(),_?.destroy(),n.destroy(),d.open&&d.close(),d.remove(),O.remove(),x(),e==="dismiss"&&ie(r.onDismiss))}W.onclick=()=>{w()&&D("dismiss")},d.addEventListener("cancel",e=>{e.preventDefault(),w()&&D("dismiss")}),l.onclick=()=>{o&&S(o)};try{if(q.type==="inline")E.append(O);else{let t={sm:420,md:640,lg:900};d.style.cssText=`padding:0;border:0;max-width:calc(100vw - 32px);max-height:calc(100dvh - 32px);overflow:auto;width:${"size"in q?t[q.size]+"px":"100vw"}`,d.setAttribute("aria-label",b.document.name),d.append(O),E.append(d),R=ve(d,{...b.document.screen,presentation:q},ce),R.latch(),w()&&(d.showModal(),R.responsive&&d.focus({preventScroll:!0}),ge(d,R.type,R.responsive))}_=I(se,{mode:"live",rendererUrl:n.webViewUrl,title:b.document.name,hostPresentation:()=>R?.type??q.type,onResize:t=>{R?.responsive&&R.setContentHeight(t+M.getBoundingClientRect().height)},onAction(t,p={}){if(!w()){Z();return}let a=n.view,u=a?.document.buttons[t];if(!u)return;if(u.type==="close"){S(async()=>{await r.onAction?.(t),D(r.onAction?"action":"dismiss")});return}if(u.type==="action"){o=async()=>{if(u.action.type==="event"){if(!r.onEvent)throw new g("EVENT_HANDLER_REQUIRED","Provide the event handler");await r.onEvent(u.action.event)}else r.onOpenUrl?await r.onOpenUrl(u.action.url):c.defaultView?.location.assign(u.action.url);await r.onAction?.(t),o=null},S(o);return}if(A&&n.canReselect===!1){y.textContent=i?"\u8BF7\u5148\u786E\u8BA4\u6216\u53D6\u6D88\u5F53\u524D\u8D2D\u4E70\u3002":"Confirm or cancel the current purchase first.",A.scrollIntoView?.({block:"nearest"}),A.querySelector("button")?.focus({preventScroll:!0});return}if((n.quote||v)&&n.canReselect===!1){o=n.quote?ee:te,S(o);return}let U=a&&z(u.product,p,a.capabilities);if(!a||!U){V(new g("PRODUCT_UNAVAILABLE","Choose an available Product in this purchase area"));return}if(r.onPurchaseIntent){o=null,S(async()=>{let h={actionId:t,productVersionId:U,selection:structuredClone(p),featureQuantities:he(a.document.screen,U,p,a.capabilities)};K=!0,await r.onPurchaseIntent(h)});return}if(v&&v.actionId!==t){V(new g("COMMAND_PENDING","Finish the current purchase"));return}v||(v={requestId:crypto.randomUUID(),actionId:t,selection:p},Y=!1),S(te)},onEscape:()=>{w()&&D("dismiss")},onError:t=>V(new Error(t)),onRendered:t=>{t&&d.setAttribute("aria-label",t)}}),ce(),_.update(b.document.screen,b.document.screen.strings.defaultLocale,{capabilities:b.capabilities,unavailableActions:oe(b),serverInput:{bindings:[],answers:{}}}),await _.ready,ue(b);let e=n.operation;(n.quote||e&&(e.confirmedAt||e.checkoutUrl||e.status==="complete"))&&(o=ee,S(o))}catch(e){throw D(),e}return{check:k,host:{get recovery(){return Ee()},async prepareFallback(){if(B||m||K)return{type:"recover",operationId:n.operation?.operationId??n.quote?.operationId??null,requestId:null};Q(!0);try{let e=await be(n);return e.type==="native"&&D(),e}finally{Q(!1)}},setSuspended(e){le=e,O.hidden=e,e&&d.open?d.close():!e&&!m&&q.type!=="inline"&&!d.open&&d.showModal()},destroy:D,refresh:async()=>{if(!w()){if(n.view)return n.view;throw new g("PRECONDITION_FAILED","Paywall presentation is suspended")}let e=await n.refresh();return m||(_?.updateCapabilities(e.capabilities,oe(e)),ue(e)),e}}}}export{ze as showPaywall};
package/dist/popup.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { b as ScreenAction, c as ScreenNode, d as ScreenInteractivity, e as ScreenDocument } from './screen-DRP7nsrQ.js';
2
- import { O as Offer, a as OfferUnavailableReason } from './coupon-fA1QujHt.js';
3
- import { b as CustomerPageData, a as SurfaceData, c as ScreenParameters, d as ScreenRendererInput, S as ScreenAnswers, C as CustomerDataIntent } from './customer-page-km5f1PJZ.js';
2
+ import { O as Offer, a as OfferUnavailableReason } from './coupon-Btz_KFKp.js';
3
+ import { b as CustomerPageData, a as SurfaceData, c as ScreenParameters, d as ScreenRendererInput, S as ScreenAnswers, C as CustomerDataIntent } from './customer-page-BV5EvCUY.js';
4
4
  import { WindowLike } from 'dompurify';
5
5
  import 'zod';
6
6
 
package/dist/popup.js CHANGED
@@ -1 +1 @@
1
- import{a as o,b as r,c as e,d as f,e as m,g as p,h as t,i as x,j as a}from"./chunk-ML6EHT43.js";import"./chunk-SSLZKIIU.js";import"./chunk-T5COWMDA.js";import"./chunk-26HU2HXU.js";import"./chunk-DSPLGTQI.js";import"./chunk-PFHS7HK3.js";export{p as formatCustomerDecimal,r as hostedRendererScript,o as hostedRendererShell,f as inspectCustomHtml,a as mountScreenPreview,x as preparePopup,m as prepareScreen,e as sanitizeCustomHtml,t as showPopup};
1
+ import{a as o,b as r,c as e,d as f,e as m,g as p,h as t,i as x,j as a}from"./chunk-EDVR7FPD.js";import"./chunk-SSLZKIIU.js";import"./chunk-XIYNQHN7.js";import"./chunk-KHIQQNTR.js";import"./chunk-DSPLGTQI.js";import"./chunk-4SWGHICJ.js";export{p as formatCustomerDecimal,r as hostedRendererScript,o as hostedRendererShell,f as inspectCustomHtml,a as mountScreenPreview,x as preparePopup,m as prepareScreen,e as sanitizeCustomHtml,t as showPopup};