@tinkerlandai/longplay-sdk 0.10.33 → 0.10.34

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 (45) hide show
  1. package/CHANGELOG.md +5 -3
  2. package/README.md +10 -8
  3. package/README.zh-CN.md +2 -2
  4. package/dist/chunk-3JJYWRA3.js +1 -0
  5. package/dist/chunk-4WZVC4TM.js +1 -0
  6. package/dist/chunk-5JWMP4YD.js +1 -0
  7. package/dist/{chunk-KIMX3OIV.js → chunk-6T575JKD.js} +1 -1
  8. package/dist/{chunk-XLSDL4D3.js → chunk-7NELM6EH.js} +1 -1
  9. package/dist/{chunk-KR3KDTVD.js → chunk-7VRZYSTR.js} +1 -1
  10. package/dist/{chunk-YTZQ5BMP.js → chunk-ERJP2GBD.js} +1 -1
  11. package/dist/{chunk-GGRDM54V.js → chunk-I6TSQQ5N.js} +1 -1
  12. package/dist/{chunk-JN6JEKWN.js → chunk-ITGERPCJ.js} +1 -1
  13. package/dist/{chunk-U6E6CM7Z.js → chunk-QBA3B4YK.js} +1 -1
  14. package/dist/chunk-RKPAIF6U.js +1 -0
  15. package/dist/{chunk-MPYJRLKB.js → chunk-TDSATEGE.js} +2 -2
  16. package/dist/{chunk-NVHIGAO3.js → chunk-TYY3MUTF.js} +1 -1
  17. package/dist/chunk-U6UHASIB.js +1 -0
  18. package/dist/{chunk-UHQGO6OR.js → chunk-WKIR2EQG.js} +1 -1
  19. package/dist/{chunk-U2R7MG3J.js → chunk-WTVLNUMS.js} +1 -1
  20. package/dist/{content-CFX2L2BP.js → content-ORU4ODJQ.js} +1 -1
  21. package/dist/funnel-host-purchase-BEFE3N3E.js +1 -0
  22. package/dist/{funnel-runtime-host-ATOA7MGC.js → funnel-runtime-host-V6TYIDX3.js} +1 -1
  23. package/dist/index.d.ts +4 -3
  24. package/dist/index.js +1 -1
  25. package/dist/native-shell.js +1 -1
  26. package/dist/openrouter.js +1 -1
  27. package/dist/page.js +1 -1
  28. package/dist/paywall-HO4PS472.js +1 -0
  29. package/dist/{paywall-session-MB7BD2XP.js → paywall-session-MZXFOPTR.js} +1 -1
  30. package/dist/popup.d.ts +2 -2
  31. package/dist/popup.js +1 -1
  32. package/dist/{presentation-loading-CiEQbUDk.d.ts → presentation-loading-CFSiS0VX.d.ts} +3 -1
  33. package/dist/react-native.js +1 -1
  34. package/dist/{screen-renderer-3CBREMIS.js → screen-renderer-W7ZGBFIR.js} +1 -1
  35. package/dist/server.d.ts +30 -0
  36. package/dist/server.js +3 -3
  37. package/dist/visual.js +1 -1
  38. package/package.json +1 -1
  39. package/dist/chunk-BRAVNBCC.js +0 -1
  40. package/dist/chunk-ENZBWR3Y.js +0 -1
  41. package/dist/chunk-HQPP76BS.js +0 -1
  42. package/dist/chunk-NVIHK5GE.js +0 -1
  43. package/dist/chunk-U6GWWCUS.js +0 -1
  44. package/dist/funnel-host-purchase-MSPLT3ZV.js +0 -1
  45. package/dist/paywall-XAXSMLDU.js +0 -1
package/dist/visual.js CHANGED
@@ -1 +1 @@
1
- import{a as pe,c as fe}from"./chunk-UKMEW5I7.js";import{b as ue}from"./chunk-J6KIN4RH.js";import{a as Ve,b as re,c as ce,d as de}from"./chunk-SLUA7ABW.js";import{a as J,b as F,c as ge,e as me}from"./chunk-NVHIGAO3.js";import{a as ae,b as se,c as oe,d as le}from"./chunk-KIMX3OIV.js";import"./chunk-3VUPVXAV.js";import"./chunk-UHQGO6OR.js";import{b as o}from"./chunk-VF6QMMEA.js";import"./chunk-DSPLGTQI.js";import{c as te,e as ie,g as M}from"./chunk-7QL4GF4C.js";import"./chunk-BID4UGWB.js";import"./chunk-WOT6VMZA.js";var K="indiana-visual-diagnostics-v1",Ae=o.strictObject({environmentId:o.string().uuid(),release:o.string().regex(/^[a-f0-9]{64}$/).nullable(),generation:o.string().regex(/^[a-f0-9]{64}$/).nullable(),publishedGeneration:o.string().regex(/^[a-f0-9]{64}$/).nullable(),checkedAt:o.string().datetime(),origin:o.string().url(),pathname:o.string().max(2048),urlMatches:o.boolean(),stopped:o.boolean(),rows:o.array(o.strictObject({changeId:o.string().regex(/^[a-f0-9]{64}$/),experimentKey:o.string().max(256),variationKey:o.string().max(256),inExperiment:o.boolean(),fingerprint:o.string().regex(/^[a-f0-9]{64}$/),status:o.enum(["inactive","waiting","partial","applied","mismatch","no_changes","unavailable","error"]),total:o.number().int().min(0).max(600),applied:o.number().int().min(0).max(600)})).max(100)});function ye(e){let l=n=>Array.isArray(n)?"["+n.map(l).join(",")+"]":n&&typeof n=="object"?"{"+Object.entries(n).filter(([,c])=>c!==void 0).sort(([c],[y])=>c.localeCompare(y)).map(([c,y])=>JSON.stringify(c)+":"+l(y)).join(",")+"}":JSON.stringify(n);return l({css:e.css,js:e.js,domMutations:e.domMutations,...e.renderGuard?{renderGuard:e.renderGuard}:{}})}function he(e){let l=new URL(e.baseUrl),n=l.origin==="https://api.longplayai.com"||l.origin==="https://api.dev.longplayai.com"?l.hostname.slice(4):void 0,c=e.origins??(n?[`https://console.${n}`]:[]),y=new Set(c.filter(t=>{try{let i=new URL(t);return i.origin===t&&(i.protocol==="https:"||i.protocol==="http:"&&["localhost","127.0.0.1","[::1]"].includes(i.hostname))}catch{return!1}})),v=!1,I=!1,k=0,T=async t=>{if(v||I||!t.source||!y.has(t.origin)||!t.data||typeof t.data!="object")return;let i=t.data;if(!(i.channel!==K||i.type!=="inspect"||i.environmentId!==e.environmentId||typeof i.nonce!="string"||!/^[a-f0-9-]{36}$/i.test(i.nonce)||typeof i.changeId!="string"||!/^[a-f0-9]{64}$/.test(i.changeId)||typeof i.url!="string"||i.url.length>2048||Date.now()-k<250)){try{if(new URL(i.url).origin!==location.origin)return}catch{return}I=!0,k=Date.now();try{let x=await e.inspect(i.changeId,i.url);!v&&x.rows.some(S=>S.changeId===i.changeId)&&t.source.postMessage({channel:K,type:"result",nonce:i.nonce,snapshot:x},t.origin)}finally{I=!1}}},u=t=>{T(t).catch(()=>{})};return window.addEventListener("message",u),()=>{v=!0,window.removeEventListener("message",u)}}var R=e=>!!e&&typeof e=="object"&&!Array.isArray(e),E=(e,l)=>typeof e=="string"&&e.length<=l,Ee=e=>typeof e=="string"&&(["html","class","style","position","href","src","alt","title","id","role","hidden"].includes(e)||/^(aria|data)-[a-z0-9_-]+$/.test(e));function ke(e){if(!R(e)||!E(e.css??"",1e5)||!E(e.js??"",1e5)||!Array.isArray(e.domMutations??[])||Array.isArray(e.domMutations)&&e.domMutations.length>200)throw new Error("Invalid visual variation");let l=e.domMutations??[];for(let n of l)if(!R(n)||!E(n.selector,2048)||!n.selector||!Ee(n.attribute)||!["set","append","remove"].includes(String(n.action))||n.value!==void 0&&!E(n.value,5e4)||n.parentSelector!==void 0&&!E(n.parentSelector,2048)||n.insertBeforeSelector!==void 0&&!E(n.insertBeforeSelector,2048))throw new Error("Invalid visual mutation");return{css:e.css??"",js:e.js??"",domMutations:l,...e.renderGuard===void 0?{}:{renderGuard:ue(e.renderGuard)}}}function q(e){if(!R(e)||typeof e.environmentId!="string"||typeof e.trackExposures!="boolean"||!/^[-a-f0-9]{36}$/i.test(e.environmentId)||typeof e.generation!="string"||!/^[a-f0-9]{64}$/.test(e.generation)||!Array.isArray(e.experiments)||e.experiments.length>100||!R(e.savedGroups))throw new Error("Invalid visual experiment payload");let l=e.experiments.map(n=>{if(!R(n)||!["key","changeId"].every(c=>typeof n[c]=="string"&&n[c])||!/^[a-f0-9]{64}$/.test(String(n.changeId))||["namespace","status","groups","url"].some(c=>Object.hasOwn(n,c))||n.hashVersion!==void 0&&n.hashVersion!==2||!Array.isArray(n.variations)||n.variations.length<2||n.variations.length>20||n.urlPatterns!==void 0&&!Array.isArray(n.urlPatterns))throw new Error("Invalid visual experiment");return{...n,variations:n.variations.map(ke)}});return{...e,experiments:l}}var ve=6e4;function qe(e){let l=oe(e.baseUrl);if(e.appManifestRelease!==void 0&&!/^[a-f0-9]{64}$/.test(e.appManifestRelease))throw new Error("Invalid IAM manifest digest");if(!/^[0-9a-f-]{36}$/i.test(e.environmentId))throw new Error("Invalid App environment ID");let n=e.fetch??globalThis.fetch.bind(globalThis),c=F(n),y=F(n),v=`${l}/api/v1/visual-experiments/${e.environmentId}`,I=e.appManifestRelease?`${v}?iam=${e.appManifestRelease}`:v,k=ae(e.deviceIdCookie??"indiana_did"),T=se(),u=null,t=!1,i=!1,x="",S={...e.attributes??{}},G,B,D=0,H=-1/0,$,m=new Map,O=new Map,C=new Set,z=ge({endpoint:`${v}/events`,fetch:n,log:e.log,label:"Visual exposure"}),P=z.flush,W,b;function j(){clearTimeout(W),b?.remove(),b=void 0}function Y(s,d){let f=M(s,d);C.has(f)||e.trackExposures===!1||u?.trackExposures===!1||t||(C.add(f),z.push({eventUuid:crypto.randomUUID(),timestamp:new Date().toISOString(),deviceId:k,...T?{sessionId:T}:{},url:location.href,pageTitle:document.title.slice(0,512),experimentKey:s.key,variationKey:d.key}))}function we(s){if(!u||t)return;let d=new Set,f={onExperimentViewed:(r,p)=>{d.add(M(r,p))},url:location.href,attributes:{...me(k,location),...S,indianaAppManifestRelease:e.appManifestRelease??null},savedGroups:te(u.savedGroups),log:e.log},h=new Set;for(let r of u.experiments){if(ce(`${e.environmentId}:${r.key}`))continue;let p=r;try{let a=ie(p,f);if(O.set(r.changeId,a),!a.inExperiment)continue;h.add(r.changeId);let w=JSON.stringify([a.key,a.value]),U=m.get(r.changeId);if(U?.signature===w){d.has(M(p,a))&&s.push(()=>{U.applied()&&Y(p,a)});continue}m.get(r.changeId)?.revert(),m.delete(r.changeId);let A=fe(a.value,{requireUniqueTargets:!!e.appManifestRelease&&Array.isArray(r.condition?.$and)&&r.condition.$and.some(g=>g!==null&&typeof g=="object"&&!Array.isArray(g)&&g.indianaAppManifestRelease===e.appManifestRelease),boundVariations:r.variations,allowJs:e.disableJsInjection===!1,nonce:e.nonce,onApplied:()=>{d.has(M(p,a))&&Y(p,a)},onError:g=>e.log?.("Visual experiment stopped",{experiment:r.key,changeId:r.changeId,variation:a.key,error:String(g)}),onTargetStatus:e.log?g=>e.log?.("Visual target status changed",{experiment:r.key,changeId:r.changeId,variation:a.key,...g}):void 0});m.set(r.changeId,{signature:w,revert:A.revert,applied:()=>A.applied,inspect:()=>A.inspect()})}catch(a){e.log?.("Skipping visual experiment",{experiment:r.key,error:String(a)})}}for(let[r,p]of m)h.has(r)||(p.revert(),m.delete(r));j()}let V=()=>{let s=[];pe(()=>we(s));for(let d of s)d()};async function _(){let s=++D,d;try{d=await c.read(I,J)}catch(h){if(t||s!==D)return!1;throw h}let f=q(d);if(f.environmentId.toLowerCase()!==e.environmentId.toLowerCase())throw new Error("Visual payload scope changed");return t||s!==D?!1:(u=f,H=performance.now(),!0)}async function Q(){!await _()||t||(N(),V())}function L(){clearTimeout($),$=setTimeout(()=>{if(document.visibilityState==="hidden")return L();Q().catch(s=>e.log?.("Visual payload refresh failed",{error:String(s)})).finally(()=>{t||L()})},ve)}let X=()=>{t||document.visibilityState==="hidden"||performance.now()-H<ve||(clearTimeout($),Q().catch(s=>e.log?.("Visual payload refresh failed",{error:String(s)})).finally(()=>{t||L()}))},Ie=()=>{x!==location.href&&(x=location.href,V())},Z=()=>{P(!0)},N=()=>{G||t||(G=le(Ie),addEventListener("pagehide",Z),x=location.href)};async function ee(s,d){let f=location.href,h=u,r=[],p=null;if(!t)try{let a=q(await y.read(I,J));a.environmentId===e.environmentId&&(p=a.generation)}catch{}for(let a of h?.experiments??[]){if(s&&a.changeId!==s)continue;let w=O.get(a.changeId);if(!w)continue;let U=new TextEncoder().encode(ye(w.value)),A=[...new Uint8Array(await crypto.subtle.digest("SHA-256",U))].map(be=>be.toString(16).padStart(2,"0")).join(""),g=m.get(a.changeId)?.inspect()??{status:"inactive",total:0,applied:0};r.push({changeId:a.changeId,experimentKey:a.key,variationKey:w.key,inExperiment:w.inExperiment,fingerprint:A,...g})}return{environmentId:e.environmentId,release:e.appManifestRelease??null,generation:h?.generation??null,publishedGeneration:p,checkedAt:new Date().toISOString(),origin:location.origin,pathname:location.pathname,urlMatches:location.href===f&&(!d||d===f)&&h===u,stopped:t,rows:r}}let ne,xe=de(()=>{i&&!t&&V()});return{async start(){if(!(i||t)){i=!0,e.appManifestRelease&&(B=re(e.appManifestRelease)),e.antiFlicker&&(b=document.createElement("style"),e.nonce&&(b.nonce=e.nonce),b.textContent="body { visibility: hidden !important }",document.head.append(b),W=setTimeout(j,Math.min(3e3,Math.max(0,e.antiFlickerTimeout??1e3))));try{if(!await _()||t)return;N(),V()}finally{j(),t||(L(),document.addEventListener("visibilitychange",X),ne=he({environmentId:e.environmentId,baseUrl:l,origins:e.diagnosticsOrigins,inspect:ee}))}}},async refresh(){t||await _()&&(i&&N(),V())},setAttributes(s){S={...s},V()},flush:()=>P(),getDiagnostics:ee,getResults(){return new Map(O)},get generation(){return u?.generation??null},destroy(){t=!0,clearTimeout($),document.removeEventListener("visibilitychange",X),xe(),ne?.(),D++,c.destroy(),y.destroy(),G?.(),B?.destroy(),removeEventListener("pagehide",Z),j();for(let s of m.values())s.revert();m.clear(),P(!0),u=null,O.clear(),C.clear(),S={}}}}export{qe as createVisualExperiments,Ve as loadAppManifestRelease};
1
+ import{a as pe,c as fe}from"./chunk-UKMEW5I7.js";import{b as ue}from"./chunk-J6KIN4RH.js";import{a as Ve,b as re,c as ce,d as de}from"./chunk-SLUA7ABW.js";import{a as J,b as F,c as ge,e as me}from"./chunk-TYY3MUTF.js";import{a as ae,b as se,c as oe,d as le}from"./chunk-6T575JKD.js";import"./chunk-3VUPVXAV.js";import"./chunk-WKIR2EQG.js";import{b as o}from"./chunk-VF6QMMEA.js";import"./chunk-DSPLGTQI.js";import{c as te,e as ie,g as M}from"./chunk-7QL4GF4C.js";import"./chunk-BID4UGWB.js";import"./chunk-WOT6VMZA.js";var K="indiana-visual-diagnostics-v1",Ae=o.strictObject({environmentId:o.string().uuid(),release:o.string().regex(/^[a-f0-9]{64}$/).nullable(),generation:o.string().regex(/^[a-f0-9]{64}$/).nullable(),publishedGeneration:o.string().regex(/^[a-f0-9]{64}$/).nullable(),checkedAt:o.string().datetime(),origin:o.string().url(),pathname:o.string().max(2048),urlMatches:o.boolean(),stopped:o.boolean(),rows:o.array(o.strictObject({changeId:o.string().regex(/^[a-f0-9]{64}$/),experimentKey:o.string().max(256),variationKey:o.string().max(256),inExperiment:o.boolean(),fingerprint:o.string().regex(/^[a-f0-9]{64}$/),status:o.enum(["inactive","waiting","partial","applied","mismatch","no_changes","unavailable","error"]),total:o.number().int().min(0).max(600),applied:o.number().int().min(0).max(600)})).max(100)});function ye(e){let l=n=>Array.isArray(n)?"["+n.map(l).join(",")+"]":n&&typeof n=="object"?"{"+Object.entries(n).filter(([,c])=>c!==void 0).sort(([c],[y])=>c.localeCompare(y)).map(([c,y])=>JSON.stringify(c)+":"+l(y)).join(",")+"}":JSON.stringify(n);return l({css:e.css,js:e.js,domMutations:e.domMutations,...e.renderGuard?{renderGuard:e.renderGuard}:{}})}function he(e){let l=new URL(e.baseUrl),n=l.origin==="https://api.longplayai.com"||l.origin==="https://api.dev.longplayai.com"?l.hostname.slice(4):void 0,c=e.origins??(n?[`https://console.${n}`]:[]),y=new Set(c.filter(t=>{try{let i=new URL(t);return i.origin===t&&(i.protocol==="https:"||i.protocol==="http:"&&["localhost","127.0.0.1","[::1]"].includes(i.hostname))}catch{return!1}})),v=!1,I=!1,k=0,T=async t=>{if(v||I||!t.source||!y.has(t.origin)||!t.data||typeof t.data!="object")return;let i=t.data;if(!(i.channel!==K||i.type!=="inspect"||i.environmentId!==e.environmentId||typeof i.nonce!="string"||!/^[a-f0-9-]{36}$/i.test(i.nonce)||typeof i.changeId!="string"||!/^[a-f0-9]{64}$/.test(i.changeId)||typeof i.url!="string"||i.url.length>2048||Date.now()-k<250)){try{if(new URL(i.url).origin!==location.origin)return}catch{return}I=!0,k=Date.now();try{let x=await e.inspect(i.changeId,i.url);!v&&x.rows.some(S=>S.changeId===i.changeId)&&t.source.postMessage({channel:K,type:"result",nonce:i.nonce,snapshot:x},t.origin)}finally{I=!1}}},u=t=>{T(t).catch(()=>{})};return window.addEventListener("message",u),()=>{v=!0,window.removeEventListener("message",u)}}var R=e=>!!e&&typeof e=="object"&&!Array.isArray(e),E=(e,l)=>typeof e=="string"&&e.length<=l,Ee=e=>typeof e=="string"&&(["html","class","style","position","href","src","alt","title","id","role","hidden"].includes(e)||/^(aria|data)-[a-z0-9_-]+$/.test(e));function ke(e){if(!R(e)||!E(e.css??"",1e5)||!E(e.js??"",1e5)||!Array.isArray(e.domMutations??[])||Array.isArray(e.domMutations)&&e.domMutations.length>200)throw new Error("Invalid visual variation");let l=e.domMutations??[];for(let n of l)if(!R(n)||!E(n.selector,2048)||!n.selector||!Ee(n.attribute)||!["set","append","remove"].includes(String(n.action))||n.value!==void 0&&!E(n.value,5e4)||n.parentSelector!==void 0&&!E(n.parentSelector,2048)||n.insertBeforeSelector!==void 0&&!E(n.insertBeforeSelector,2048))throw new Error("Invalid visual mutation");return{css:e.css??"",js:e.js??"",domMutations:l,...e.renderGuard===void 0?{}:{renderGuard:ue(e.renderGuard)}}}function q(e){if(!R(e)||typeof e.environmentId!="string"||typeof e.trackExposures!="boolean"||!/^[-a-f0-9]{36}$/i.test(e.environmentId)||typeof e.generation!="string"||!/^[a-f0-9]{64}$/.test(e.generation)||!Array.isArray(e.experiments)||e.experiments.length>100||!R(e.savedGroups))throw new Error("Invalid visual experiment payload");let l=e.experiments.map(n=>{if(!R(n)||!["key","changeId"].every(c=>typeof n[c]=="string"&&n[c])||!/^[a-f0-9]{64}$/.test(String(n.changeId))||["namespace","status","groups","url"].some(c=>Object.hasOwn(n,c))||n.hashVersion!==void 0&&n.hashVersion!==2||!Array.isArray(n.variations)||n.variations.length<2||n.variations.length>20||n.urlPatterns!==void 0&&!Array.isArray(n.urlPatterns))throw new Error("Invalid visual experiment");return{...n,variations:n.variations.map(ke)}});return{...e,experiments:l}}var ve=6e4;function qe(e){let l=oe(e.baseUrl);if(e.appManifestRelease!==void 0&&!/^[a-f0-9]{64}$/.test(e.appManifestRelease))throw new Error("Invalid IAM manifest digest");if(!/^[0-9a-f-]{36}$/i.test(e.environmentId))throw new Error("Invalid App environment ID");let n=e.fetch??globalThis.fetch.bind(globalThis),c=F(n),y=F(n),v=`${l}/api/v1/visual-experiments/${e.environmentId}`,I=e.appManifestRelease?`${v}?iam=${e.appManifestRelease}`:v,k=ae(e.deviceIdCookie??"indiana_did"),T=se(),u=null,t=!1,i=!1,x="",S={...e.attributes??{}},G,B,D=0,H=-1/0,$,m=new Map,O=new Map,C=new Set,z=ge({endpoint:`${v}/events`,fetch:n,log:e.log,label:"Visual exposure"}),P=z.flush,W,b;function j(){clearTimeout(W),b?.remove(),b=void 0}function Y(s,d){let f=M(s,d);C.has(f)||e.trackExposures===!1||u?.trackExposures===!1||t||(C.add(f),z.push({eventUuid:crypto.randomUUID(),timestamp:new Date().toISOString(),deviceId:k,...T?{sessionId:T}:{},url:location.href,pageTitle:document.title.slice(0,512),experimentKey:s.key,variationKey:d.key}))}function we(s){if(!u||t)return;let d=new Set,f={onExperimentViewed:(r,p)=>{d.add(M(r,p))},url:location.href,attributes:{...me(k,location),...S,indianaAppManifestRelease:e.appManifestRelease??null},savedGroups:te(u.savedGroups),log:e.log},h=new Set;for(let r of u.experiments){if(ce(`${e.environmentId}:${r.key}`))continue;let p=r;try{let a=ie(p,f);if(O.set(r.changeId,a),!a.inExperiment)continue;h.add(r.changeId);let w=JSON.stringify([a.key,a.value]),U=m.get(r.changeId);if(U?.signature===w){d.has(M(p,a))&&s.push(()=>{U.applied()&&Y(p,a)});continue}m.get(r.changeId)?.revert(),m.delete(r.changeId);let A=fe(a.value,{requireUniqueTargets:!!e.appManifestRelease&&Array.isArray(r.condition?.$and)&&r.condition.$and.some(g=>g!==null&&typeof g=="object"&&!Array.isArray(g)&&g.indianaAppManifestRelease===e.appManifestRelease),boundVariations:r.variations,allowJs:e.disableJsInjection===!1,nonce:e.nonce,onApplied:()=>{d.has(M(p,a))&&Y(p,a)},onError:g=>e.log?.("Visual experiment stopped",{experiment:r.key,changeId:r.changeId,variation:a.key,error:String(g)}),onTargetStatus:e.log?g=>e.log?.("Visual target status changed",{experiment:r.key,changeId:r.changeId,variation:a.key,...g}):void 0});m.set(r.changeId,{signature:w,revert:A.revert,applied:()=>A.applied,inspect:()=>A.inspect()})}catch(a){e.log?.("Skipping visual experiment",{experiment:r.key,error:String(a)})}}for(let[r,p]of m)h.has(r)||(p.revert(),m.delete(r));j()}let V=()=>{let s=[];pe(()=>we(s));for(let d of s)d()};async function _(){let s=++D,d;try{d=await c.read(I,J)}catch(h){if(t||s!==D)return!1;throw h}let f=q(d);if(f.environmentId.toLowerCase()!==e.environmentId.toLowerCase())throw new Error("Visual payload scope changed");return t||s!==D?!1:(u=f,H=performance.now(),!0)}async function Q(){!await _()||t||(N(),V())}function L(){clearTimeout($),$=setTimeout(()=>{if(document.visibilityState==="hidden")return L();Q().catch(s=>e.log?.("Visual payload refresh failed",{error:String(s)})).finally(()=>{t||L()})},ve)}let X=()=>{t||document.visibilityState==="hidden"||performance.now()-H<ve||(clearTimeout($),Q().catch(s=>e.log?.("Visual payload refresh failed",{error:String(s)})).finally(()=>{t||L()}))},Ie=()=>{x!==location.href&&(x=location.href,V())},Z=()=>{P(!0)},N=()=>{G||t||(G=le(Ie),addEventListener("pagehide",Z),x=location.href)};async function ee(s,d){let f=location.href,h=u,r=[],p=null;if(!t)try{let a=q(await y.read(I,J));a.environmentId===e.environmentId&&(p=a.generation)}catch{}for(let a of h?.experiments??[]){if(s&&a.changeId!==s)continue;let w=O.get(a.changeId);if(!w)continue;let U=new TextEncoder().encode(ye(w.value)),A=[...new Uint8Array(await crypto.subtle.digest("SHA-256",U))].map(be=>be.toString(16).padStart(2,"0")).join(""),g=m.get(a.changeId)?.inspect()??{status:"inactive",total:0,applied:0};r.push({changeId:a.changeId,experimentKey:a.key,variationKey:w.key,inExperiment:w.inExperiment,fingerprint:A,...g})}return{environmentId:e.environmentId,release:e.appManifestRelease??null,generation:h?.generation??null,publishedGeneration:p,checkedAt:new Date().toISOString(),origin:location.origin,pathname:location.pathname,urlMatches:location.href===f&&(!d||d===f)&&h===u,stopped:t,rows:r}}let ne,xe=de(()=>{i&&!t&&V()});return{async start(){if(!(i||t)){i=!0,e.appManifestRelease&&(B=re(e.appManifestRelease)),e.antiFlicker&&(b=document.createElement("style"),e.nonce&&(b.nonce=e.nonce),b.textContent="body { visibility: hidden !important }",document.head.append(b),W=setTimeout(j,Math.min(3e3,Math.max(0,e.antiFlickerTimeout??1e3))));try{if(!await _()||t)return;N(),V()}finally{j(),t||(L(),document.addEventListener("visibilitychange",X),ne=he({environmentId:e.environmentId,baseUrl:l,origins:e.diagnosticsOrigins,inspect:ee}))}}},async refresh(){t||await _()&&(i&&N(),V())},setAttributes(s){S={...s},V()},flush:()=>P(),getDiagnostics:ee,getResults(){return new Map(O)},get generation(){return u?.generation??null},destroy(){t=!0,clearTimeout($),document.removeEventListener("visibilitychange",X),xe(),ne?.(),D++,c.destroy(),y.destroy(),G?.(),B?.destroy(),removeEventListener("pagehide",Z),j();for(let s of m.values())s.revert();m.clear(),P(!0),u=null,O.clear(),C.clear(),S={}}}}export{qe as createVisualExperiments,Ve as loadAppManifestRelease};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tinkerlandai/longplay-sdk",
3
- "version": "0.10.33",
3
+ "version": "0.10.34",
4
4
  "description": "Framework-independent Longplay SDK for customer identity, entitlements, credits, offers and growth surfaces.",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {
@@ -1 +0,0 @@
1
- import{E as T}from"./chunk-N7YXDSQL.js";import{a as k}from"./chunk-DSPLGTQI.js";var O={sm:420,md:640,lg:900},I=767;function ue(e,n,s=()=>!0,l="Close"){let r=e.ownerDocument.defaultView,i=e.ownerDocument.createElement("button");i.type="button",i.setAttribute("aria-label",l),i.style.cssText="position:absolute;inset:0 48px auto;z-index:2;height:24px;border:0;padding:0;background:transparent;touch-action:none;cursor:grab";let a=e.ownerDocument.createElement("span");a.style.cssText="display:block;width:36px;height:4px;border-radius:4px;margin:8px auto 12px;background:currentColor;opacity:.22;pointer-events:none",i.append(a),e.prepend(i);let d,c=0,p=!1,y=()=>{i.hidden=e.dataset.presentation!=="sheet",i.setAttribute("aria-disabled",String(!s()))},v=t=>{y(),!(i.hidden||!s()||t.button!==0)&&(d={y:t.clientY,time:Date.now(),id:t.pointerId},c=0,p=!1,i.setPointerCapture?.(t.pointerId))},m=t=>{!d||t.pointerId!==d.id||(c=Math.max(0,t.clientY-d.y),e.style.transform=`translateY(${c}px)`)},x=t=>{if(!d||t.pointerId!==d.id)return;let h=Math.max(1,Date.now()-d.time),f=t.type!=="pointercancel"&&s()&&(c>120||c>40&&c/h>.5);p=c>6,d=void 0,i.releasePointerCapture?.(t.pointerId),e.style.transform="",f?n():c&&typeof e.animate=="function"&&!r?.matchMedia?.("(prefers-reduced-motion: reduce)").matches&&e.animate([{transform:`translateY(${c}px)`},{transform:"none"}],{duration:200,easing:"cubic-bezier(.2,.8,.2,1)"}),c=0},o=()=>{if(p){p=!1;return}!d&&c===0&&s()&&n()};i.addEventListener("pointerdown",v),i.addEventListener("pointermove",m),i.addEventListener("pointerup",x),i.addEventListener("pointercancel",x),i.addEventListener("click",o);let u=typeof MutationObserver=="function"?new MutationObserver(y):void 0;return u?.observe(e,{attributes:!0,attributeFilter:["data-presentation"]}),r?.addEventListener("resize",y),y(),()=>{u?.disconnect(),r?.removeEventListener("resize",y),i.remove(),e.style.transform=""}}function W(e,n,s=!1){return(e.type==="modal"||e.type==="sheet")&&e.mobile&&s&&n<=I?e.mobile:e.type}function _(e,n,s){let l=e.ownerDocument.defaultView,r=n.presentation,i;if((r.type==="modal"||r.type==="sheet")&&r.backdrop){let t=`lp-backdrop-${crypto.randomUUID()}`,h={none:"transparent",scrim:"#f2f2f2cc",dim:"#0006","strong-dim":"#000000bf",blur:"#0006"};e.dataset.indianaBackdrop=t,i=e.ownerDocument.createElement("style"),i.textContent=`dialog[data-indiana-backdrop="${t}"]::backdrop{background:${h[r.backdrop]};backdrop-filter:${r.backdrop==="blur"?"blur(16px)":"none"}}`,e.append(i)}let a=n.pages?.[0]?.root.style?.shape,d=a?.type==="pill"?"9999px":a?.type==="rect"?typeof a.radius=="number"?`${a.radius}px`:[a.radius.topLeft,a.radius.topRight,a.radius.bottomRight,a.radius.bottomLeft].map(t=>`${t}px`).join(" "):void 0,c=(r.type==="modal"||r.type==="sheet")&&(r.desktopWidth!==void 0||r.mobile!==void 0),p=r.type,y,v,m=!1,x=t=>{m||!Number.isFinite(t)||t<0||(v=t,p!=="fullscreen"&&p!=="inline"&&(e.style.height=`min(${Math.max(t,40)}px, calc(100dvh - ${p==="sheet"?0:32}px))`))},o=()=>{if(!m&&(p=y??W(r,l?.innerWidth??1024,l?.matchMedia?.("(pointer: coarse)").matches===!0),e.dataset.presentation=p,!(!c||r.type!=="modal"&&r.type!=="sheet"))){if(e.style.boxSizing="border-box",e.style.padding="0",e.style.border="0",e.style.overflow="hidden",e.style.outline="none",e.tabIndex=-1,e.style.background=n.theme.background,e.style.color=n.theme.text,p==="fullscreen")e.style.width="100vw",e.style.height="100dvh",e.style.maxWidth="100vw",e.style.maxHeight="100dvh",e.style.margin="0",e.style.borderRadius="0";else{let t=r.mobile==="sheet"&&p==="sheet",h=r.desktopWidth,f=l?.innerWidth??1024;e.style.width=t?`${f}px`:h?`${Math.min(h.max,Math.max(f*h.viewport/100,h.min))}px`:`${T[r.size]}px`,e.style.maxWidth=`${Math.max(0,f-(p==="sheet"?0:32))}px`,e.style.maxHeight=p==="sheet"?"100dvh":"calc(100dvh - 32px)",e.style.margin=p==="sheet"?"auto auto 0":"auto",e.style.borderRadius=d??(p==="sheet"?"16px 16px 0 0":"24px"),e.style.height="",v!==void 0&&x(v)}s?.(p)}},u=c?[l?.matchMedia?.(`(max-width: ${I}px)`),l?.matchMedia?.("(pointer: coarse)")].filter(t=>t!==void 0):[];if(c){l?.addEventListener("resize",o);for(let t of u)t.addEventListener?t.addEventListener("change",o):t.addListener?.(o)}return o(),{responsive:c,get type(){return p},latch(){m||y!==void 0||(o(),y=p)},setContentHeight:x,destroy(){if(!m){m=!0,i?.remove(),delete e.dataset.indianaBackdrop,l?.removeEventListener("resize",o);for(let t of u)t.removeEventListener?t.removeEventListener("change",o):t.removeListener?.(o)}}}}function A(e,n,s){let{presentation:l}=n,r="size"in l?`${O[l.size]}px`:"100vw";return e.style.cssText=`padding:0;border:0;max-width:calc(100vw - 32px);max-height:calc(100dvh - 32px);overflow:auto;width:${r}`,_(e,n,s)}function me(e,n,s=!1){let l=e.ownerDocument.defaultView;if(typeof e.animate!="function"||l?.matchMedia?.("(prefers-reduced-motion: reduce)").matches)return;let r=s?{duration:300,easing:"cubic-bezier(0.23, 1, 0.32, 1)"}:{duration:240,easing:"cubic-bezier(0.2, 0.8, 0.2, 1)"};e.animate(n==="sheet"?[{transform:"translateY(100%)"},{transform:"none"}]:n==="modal"?[{opacity:0,transform:s?"translateY(12px) scale(0.96)":"translateY(8px) scale(0.98)"},{opacity:1,transform:"none"}]:[{opacity:0},{opacity:1}],r);try{e.animate([{opacity:0},{opacity:1}],{...r,pseudoElement:"::backdrop"})}catch{}}function $(e,n){e.style.cssText=["position:absolute","z-index:1","top:calc(4px + env(safe-area-inset-top, 0px))","inset-inline-end:calc(4px + env(safe-area-inset-right, 0px))","width:44px","height:44px","padding:0","border:0","font:400 20px/1 system-ui,sans-serif","cursor:pointer","touch-action:manipulation"].join(";"),e.style.background=`radial-gradient(circle, ${n.background} 0 15px, color-mix(in srgb, ${n.text} 22%, ${n.background}) 15px 16px, transparent 16.5px)`,e.style.color=n.text}var M=new WeakMap;function he(e,n){return M.set(e,n),()=>M.delete(e)}function ye(e){let n=e.defaultView?.HTMLElement,s=e.activeElement;for(let r=0;r<16&&s?.shadowRoot?.activeElement;r++)s=s.shadowRoot.activeElement;let l=s?M.get(s)?.():void 0;return()=>{!s?.isConnected||!n||!(s instanceof n)||(s.focus({preventScroll:!0}),l?.())}}function F(e){let n={display:"block",position:"fixed",top:"0",left:"0",opacity:"0",pointerEvents:"none",zIndex:"-1"},s=Object.keys(n).map(i=>{let a=i,d=e.style[a];return e.style[a]=n[a],[a,d]}),l=e.inert??!1,r=e.getAttribute("aria-hidden");return e.inert=!0,e.setAttribute("aria-hidden","true"),()=>{for(let[i,a]of s)e.style[i]=a;e.inert=l,r===null?e.removeAttribute("aria-hidden"):e.setAttribute("aria-hidden",r)}}function be(e,n){let s=e.style.width;e.style.width=`${n.getBoundingClientRect().width||n.ownerDocument.defaultView?.innerWidth||800}px`;let l=F(e);return()=>{l(),e.style.width=s}}function R(e,n,s,l,r){let{presentation:i,screen:a}=s,d=Object.entries(s.buttons??{}).filter(([,u])=>u.type==="close").map(([u])=>u),c=e.ownerDocument.defaultView,p=a.pages.find(u=>u.id===a.initialPageId)?.theme??a.theme,y={background:a.theme.background,text:a.theme.text};n.inert=!0,n.style.cssText="width:100%;min-width:0;overflow:hidden;visibility:hidden";let v=!1,m,x=u=>{c&&m?.resizeViewport(Math.max(1,c.innerHeight-(u==="modal"?32:0)),c.innerWidth)},o=i.type==="inline"?void 0:A(e,{...a,presentation:i,theme:y},x);return o?.latch(),c&&o?.responsive&&o.setContentHeight(c.innerHeight-(o.type==="modal"?32:0)),e.style.background=p.background,e.style.color=p.text,o?(i.type==="fullscreen"||i.type==="sheet")&&(e.style.position="fixed"):e.style.position="relative",import("./screen-renderer-3CBREMIS.js").then(({mountScreenPreview:u})=>{v||(m=u(n,{mode:"live",skeleton:!0,closeActions:d,hostPresentation:()=>o?.type??i.type,reportContentHeight:o?.responsive,onResize(t){if(!c||!o?.responsive)return;let h=o.type==="modal"?32:0,f=Math.min(t,Math.max(0,c.innerHeight-h));n.style.height=`${f}px`,o.setContentHeight(f)},onRendered:r,onError(){m&&(m.destroy(),m=void 0)}}),o?.responsive&&x(o.type),m.update({...a,presentation:i},l,{serverInput:{bindings:[],answers:{}}}))}).catch(()=>{m?.destroy(),m=void 0}),()=>{v=!0,m?.destroy(),o?.destroy()}}var De=15e3;function Le(e,n,s,l){let r=e.ownerDocument,i=new AbortController,a=!1,d=!1,c,p;function y(){p?.(),p=void 0,c?.tagName==="DIALOG"&&c.close?.(),c?.remove(),c=void 0}function v(o,u){d||(d=!0,y(),(o==="dismissed"||o==="error")&&i.abort(u??new DOMException("Presentation cancelled","AbortError")),!(!a&&o!=="ready")&&k(n.onPresentationState,o==="error"?{surface:s,state:o,error:u}:{surface:s,state:o}))}let m=l,x=()=>{d||m()};return{setDismissHandler(o){m=o},get active(){return a&&!d},get cancelled(){return i.signal.aborted},start(o,u,t){if(!(a||d)){if(a=!0,n.loading!=="host"){let h=(u??r.documentElement.lang)||"en",f=o&&t?.presentation?.type!=="inline",P=t!==void 0,b=r.createElement(f?"dialog":"div");c=b,b.dataset.longplayLoading=s;let w=h.startsWith("zh"),H=P?w?"\u6B63\u5728\u52A0\u8F7D\u5957\u9910":"Loading plans":w?"\u6B63\u5728\u52A0\u8F7D":"Loading",z=t?.screen.theme??{background:"Canvas",text:"CanvasText"};b.setAttribute("aria-label",H);let S=r.createElement("div");S.setAttribute("role","status");let E=r.createElement("div");E.setAttribute("aria-hidden","true");let C=()=>{S.style.cssText="position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%)"};P?S.style.cssText="padding:24px 60px 24px 24px;font:500 16px/1.5 system-ui,sans-serif":C(),S.textContent=H;let g=r.createElement("button");g.type="button",g.textContent="\xD7",g.setAttribute("aria-label",w?"\u53D6\u6D88\u52A0\u8F7D":"Cancel loading"),$(g,z),g.addEventListener("click",x),b.addEventListener("cancel",D=>{D.preventDefault(),x()}),b.append(S,E,g),e.append(b);let L=()=>{if(!d&&f){let D=b;D.showModal?D.showModal():D.open=!0,g.focus({preventScroll:!0})}};t?(p=R(b,E,t,h,()=>{d||(E.style.visibility="",C())}),L()):P?(b.style.cssText=f?"padding:0;border:0;border-radius:24px;background:Canvas;color:CanvasText;width:min(420px,calc(100vw - 32px))":"position:relative;background:Canvas;color:CanvasText;width:100%",L()):(V(b,E,f,s),L())}k(n.onPresentationState,{surface:s,state:"loading",dismiss:x})}},present(o){if(d)return;let u=!!c;y(),o(u),v("ready")},dismiss:x,finish:v,async wait(o,u){let t=i.signal,h,f,P=new Promise((b,w)=>{f=()=>w(t.reason),t.aborted?f():t.addEventListener("abort",f,{once:!0}),u!==void 0&&(h=setTimeout(()=>w(new Error("Presentation data timed out")),u))});try{let b=await Promise.race([P,o]);return t.throwIfAborted(),b}finally{t.removeEventListener("abort",f),clearTimeout(h)}}}}function V(e,n,s,l){e.style.cssText="position:relative;box-sizing:border-box;background:Canvas;color:CanvasText;padding:24px 48px 24px 24px;"+(s?"position:fixed;width:min(480px,calc(100% - 32px));border:0;border-radius:16px;max-height:calc(100dvh - 32px)":"width:100%"),n.style.cssText="display:grid;gap:12px";let r=l==="banner"?[["72%",12],["44%",10]]:[["46%",20],["84%",12],["65%",12],["100%",64]];for(let[i,a]of r){let d=e.ownerDocument.createElement("div");d.style.cssText=`width:${i};height:${a}px;background:currentColor;opacity:.11;border-radius:6px`,n.append(d)}}export{ue as a,W as b,_ as c,A as d,me as e,$ as f,he as g,ye as h,F as i,be as j,De as k,Le as l};
@@ -1 +0,0 @@
1
- import{p as n,s as t}from"./chunk-U6E6CM7Z.js";function u(o,e,a){return n(o,e,a,t)}export{u as a};
@@ -1 +0,0 @@
1
- import{a as c}from"./chunk-X4W22IH6.js";var u={none:0,sm:4,md:8,lg:14,full:9999},f={system:"system-ui,sans-serif",serif:"Georgia,serif",rounded:"ui-rounded,system-ui,sans-serif",mono:"ui-monospace,monospace"},g={primary:"#172033",background:"#FFFFFF",text:"#172033",radius:"md",font:"system"};function p(e){let[n,i,r]=[1,3,5].map(t=>{let o=Number.parseInt(e.slice(t,t+2),16)/255;return o<=.03928?o/12.92:((o+.055)/1.055)**2.4});return .2126*n+.7152*i+.0722*r}function y(e,n=!0){let i=p(e.primary),r=(i+.05)/.05>1.05/(i+.05)?"#111318":"#FFFFFF",t=`color-mix(in srgb, ${e.text} 22%, ${e.background})`,o=`${u[e.radius]}px`,s=`appearance:none;margin:0;min-height:44px;padding:10px 18px;border:0;border-radius:${o};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;${n?`background:${e.background};`:""}color:${e.text};font:14px/1.5 ${f[e.font]}`,controls:"display:flex;gap:12px;padding:0 20px 12px;align-items:center;flex-wrap:wrap",pinned:`position:sticky;bottom:0;z-index:1;box-sizing:border-box;padding-top:12px;background:${e.background};border-top:1px solid ${t}`,bar:`display:flex;gap:8px;padding:12px 16px;align-items:center;flex-wrap:wrap;border-top:1px solid ${t}`,message:"flex:1 1 200px;min-width:0;margin:0;font-size:13px",status:"margin:0;font-size:13px;opacity:.72",alert:`flex:1 1 200px;min-width:0;margin:0;font-size:13px;font-weight:500;color:${p(e.background)>.4?"#B42318":"#FDA29B"}`,panel:`flex:1 0 100%;box-sizing:border-box;display:flex;flex-direction:column;gap:8px;padding:16px;border:1px solid ${t};border-radius:${o}`,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:`${s};background:${e.primary};color:${r}`,secondary:`${s};background:transparent;color:${e.text};box-shadow:inset 0 0 0 1px ${t}`,link:`${s};background:transparent;color:${e.text};opacity:.72;font-weight:500`,stage:"display:flex;justify-content:center;padding:24px 20px",history:"display:flex;flex-direction:column;gap:12px;padding:20px",historyTitle:"margin:0;padding-inline-end:40px;font-size:17px;font-weight:600;line-height:1.3",historyNote:"margin:0;font-size:13px;opacity:.72",historyPages:"display:flex;gap:8px;flex-wrap:wrap;margin:0;padding:0;list-style:none",historyPage:`border:1px solid ${t};border-radius:${o};overflow:hidden`,historyRecords:`display:flex;flex-direction:column;gap:4px;margin:0;padding:12px 0 0;list-style:none;font-size:13px;border-top:1px solid ${t}`,focus:e.text}}function b(e){e.style.opacity=e.disabled?".55":"",e.style.cursor=e.disabled?"not-allowed":"pointer"}function h(e,n){e.addEventListener("focus",()=>{let i=!0;try{i=e.matches(":focus-visible")}catch{}i&&(e.style.outline=`2px solid ${n()}`,e.style.outlineOffset="2px")}),e.addEventListener("blur",()=>{e.style.outline="",e.style.outlineOffset=""})}var x={en:{network:"Connection problem. Check your network and try again.",timeout:"This is taking longer than expected. Try again.",other:"Something went wrong. Try again."},zh:{network:"\u7F51\u7EDC\u8FDE\u63A5\u5F02\u5E38\uFF0C\u8BF7\u68C0\u67E5\u7F51\u7EDC\u540E\u91CD\u8BD5\u3002",timeout:"\u54CD\u5E94\u65F6\u95F4\u8FC7\u957F\uFF0C\u8BF7\u91CD\u8BD5\u3002",other:"\u51FA\u4E86\u70B9\u95EE\u9898\uFF0C\u8BF7\u91CD\u8BD5\u3002"}};function k(e,n){let i=x[n?"zh":"en"],r=e instanceof c?e.code:void 0;return r==="NETWORK_ERROR"?i.network:r==="TIMEOUT"?i.timeout:i.other}function T(e){let n=!1,i,r,t=()=>{clearTimeout(i),i=void 0};function o(){if(t(),n)return;let a=e.document.visibilityState==="hidden"?e.hiddenDelay?.():e.delay();a!==void 0&&(i=setTimeout(()=>{s().catch(()=>{})},a))}function s(){if(n)return Promise.resolve();if(r)return r;t();let a=Promise.resolve().then(()=>n?void 0:e.run());r=a;let l=()=>{r===a&&(r=void 0),o()};return a.then(l,l),a}let d=()=>{e.document.visibilityState==="hidden"?o():s().catch(()=>{})};return e.document.addEventListener("visibilitychange",d),{schedule:o,refresh:s,destroy(){n=!0,t(),e.document.removeEventListener("visibilitychange",d)}}}function E(e,n,i){return new Promise(r=>{let t,o=()=>{clearTimeout(t),n.removeEventListener("visibilitychange",d),i.removeEventListener("abort",o),r()},s=()=>{clearTimeout(t),t=setTimeout(o,n.visibilityState==="hidden"?Math.max(e,3e4):e)},d=()=>{n.visibilityState==="visible"?o():s()};n.addEventListener("visibilitychange",d),i.addEventListener("abort",o,{once:!0}),s(),i.aborted&&o()})}var m={zh:{pending:"\u5904\u7406\u4E2D",complete:"\u5DF2\u5B8C\u6210",cancelled:"\u5DF2\u53D6\u6D88",failed:"\u5931\u8D25",unknown:"\u72B6\u6001\u5F85\u786E\u8BA4"},en:{pending:"Processing",complete:"Completed",cancelled:"Cancelled",failed:"Failed",unknown:"Status unconfirmed"}};function z(e,n){return m[n?"zh":"en"][e]}export{g as a,y as b,b as c,h as d,k as e,T as f,E as g,z as h};
@@ -1 +0,0 @@
1
- import{b as we}from"./chunk-GGRDM54V.js";import{a as Q}from"./chunk-UWLEGMWX.js";import{A as Pe,E as B,G as Re,d as me,f as N,k as fe,v as ge,w as ye,y as Se}from"./chunk-U6E6CM7Z.js";import{$ as k}from"./chunk-R23IGK5U.js";import{a as U,i as J}from"./chunk-EHDHWYVJ.js";import{b as Ie}from"./chunk-U2R7MG3J.js";import{a as l}from"./chunk-X4W22IH6.js";import{h as z}from"./chunk-R4FDIYMN.js";import{b as he}from"./chunk-UHQGO6OR.js";import{b as r}from"./chunk-VF6QMMEA.js";import{a as ae}from"./chunk-DSPLGTQI.js";var g=k.options,ke=r.discriminatedUnion("operation",[g[1].omit({customerToken:!0}),g[2].omit({customerToken:!0}),g[3].omit({customerToken:!0}),g[4].omit({customerToken:!0}),g[5].omit({customerToken:!0}),g[6].omit({customerToken:!0}),g[7].omit({customerToken:!0}),g[8].omit({customerToken:!0}),fe.omit({customerToken:!0})]),Ne=r.strictObject({receiptId:r.uuid(),operationId:r.uuid()}),Ge=r.discriminatedUnion("operation",[r.strictObject({operation:r.literal("recover_start"),intent:r.enum(["lookup","resume"]),start:r.strictObject({requestId:g[0].shape.requestId,funnelId:g[0].shape.funnelId,locale:g[0].shape.locale,parameters:g[0].shape.parameters})}),r.strictObject({operation:r.literal("recover_run"),runId:r.uuid(),funnelId:r.uuid()}),r.strictObject({operation:r.literal("recover_purchase"),runId:r.uuid(),funnelId:r.uuid(),purchase:Ne}),r.strictObject({operation:r.literal("settle_command"),runId:r.uuid(),funnelId:r.uuid(),requestId:r.uuid(),command:r.discriminatedUnion("operation",[g[3].omit({customerToken:!0}),g[4].omit({customerToken:!0}),g[5].omit({customerToken:!0}),g[6].omit({customerToken:!0}),g[7].omit({customerToken:!0})]).optional()}).refine(o=>!o.command||o.requestId===o.command.requestId),r.strictObject({operation:r.literal("run_command"),runId:r.uuid(),funnelId:r.uuid(),command:ke})]),ie=r.strictObject({runId:r.uuid(),funnelId:r.uuid(),versionId:r.uuid(),startRequestId:r.uuid(),runExpiresAt:r.iso.datetime({offset:!0}),status:N.shape.run.shape.status}),K={scope:z,customerId:r.uuid()},Ce=r.discriminatedUnion("outcome",[r.strictObject({...K,outcome:r.literal("unknown"),target:r.null(),view:r.null(),access:r.null()}),r.strictObject({...K,outcome:r.literal("resolved"),target:ie,view:N.shape.run.nullable(),access:r.discriminatedUnion("type",[r.strictObject({type:r.literal("customer")}),r.strictObject({type:r.literal("operation_only"),cause:r.enum(["run_terminal","run_expired","run_revoked","issuer_unavailable"])})])})]).superRefine((o,d)=>{o.outcome==="resolved"&&(o.access.type==="customer"!=(o.view!==null)||o.view&&(o.view.id!==o.target.runId||o.view.source.id!==o.target.funnelId||o.view.source.versionId!==o.target.versionId||o.view.status!==o.target.status||o.view.runExpiresAt!==o.target.runExpiresAt||o.view.credentialExpiresAt!==null))&&d.addIssue({code:"custom",message:"Recovery view and original Run binding differ"})}),ve=r.strictObject({...K,target:ie,view:N.shape.run.nullable(),settlement:r.strictObject({requestId:r.uuid(),state:r.enum(["pending","unknown","settled"]),acceptance:r.enum(["accepted","not_accepted","unknown"]),receiptPhase:r.enum(["accepted","processing","done"]).nullable(),basis:r.enum(["receipt","run_terminal","position_advanced","none"]),receiptId:r.uuid().nullable(),operationId:r.uuid().nullable()}),purchase:N.shape.purchase.unwrap().nullable()}).superRefine((o,d)=>{let p=o.settlement;(p.acceptance==="accepted"!=(p.receiptPhase!==null)||p.acceptance==="accepted"&&p.basis!=="receipt"||p.acceptance==="unknown"&&(p.state!=="unknown"||p.basis!=="none")||p.acceptance!=="accepted"&&(p.operationId!==null||p.receiptId!==null)||p.acceptance==="not_accepted"&&(p.state!=="settled"||!["run_terminal","position_advanced"].includes(p.basis))||o.purchase&&(o.purchase.receiptId!==p.receiptId||o.purchase.operation&&o.purchase.operation.operationId!==p.operationId||o.purchase.quote&&o.purchase.quote.operationId!==p.operationId)||o.view&&(o.view.id!==o.target.runId||o.view.source.id!==o.target.funnelId||o.view.source.versionId!==o.target.versionId||o.view.status!==o.target.status||o.view.runExpiresAt!==o.target.runExpiresAt||o.view.credentialExpiresAt!==null))&&d.addIssue({code:"custom",message:"Original command settlement binding differs"})}),Ee=r.strictObject({...K,target:ie,purchase:N.shape.purchase.unwrap()}).superRefine((o,d)=>{(!o.purchase.operation||typeof o.purchase.canReselect!="boolean"||o.purchase.quote&&o.purchase.quote.operationId!==o.purchase.operation.operationId)&&d.addIssue({code:"custom",message:"Original purchase proof is incomplete"})});var Te=k.options[0].refine(o=>!o.customer&&!o.customerData),xe=r.strictObject({receiptId:r.uuid(),operationId:r.uuid(),terminal:r.enum(["complete","native"]).nullable()}),be=r.strictObject({schemaVersion:r.literal(1),baseUrl:r.url(),scope:z,customerId:r.uuid(),sessionId:r.uuid(),start:Te,allowed:r.array(r.enum(["merchant","record_only","indiana","native"])),run:r.strictObject({id:r.uuid(),versionId:r.uuid(),status:me.shape.status,revision:r.number().int().nonnegative(),runExpiresAt:r.iso.datetime({offset:!0}).optional()}).optional(),purchases:r.array(xe).max(100),operationCommand:r.strictObject({operationId:r.uuid(),intent:r.literal("confirm")}).optional(),journal:r.strictObject({revision:r.number().int().nonnegative(),entry:ge.nullable()})});function Fe(o){return Se({...o,namespace:"purchases",identity:[o.scope.projectId,o.scope.environment,o.customerId]})}function Oe(o){let d=new URL(o.baseUrl??he).href,p=()=>new l("PURCHASE_STORAGE_INVALID","Purchase recovery storage is unavailable or invalid; native fallback is not authorized");async function v(){o.assertCurrent();try{let y=await o.storage.read();if(o.assertCurrent(),!Number.isSafeInteger(y.revision)||y.revision<0)throw p();let a=y.entry===null?null:be.parse(y.entry);if(a&&(a.baseUrl!==d||a.customerId!==o.customerId||a.scope.projectId!==o.scope.projectId||a.scope.environment!==o.scope.environment))throw new l("SCOPE_MISMATCH","Purchase recovery belongs to another Customer or environment");if(a?.journal.entry&&(a.journal.entry.scope.projectId!==a.scope.projectId||a.journal.entry.scope.environment!==a.scope.environment||a.journal.entry.funnelId!==a.start.funnelId||a.journal.entry.runId!==a.run?.id||a.journal.entry.versionId!==a.run?.versionId)||a?.operationCommand&&!a.purchases.some(P=>P.operationId===a.operationCommand?.operationId))throw p();return{revision:y.revision,entry:a}}catch(y){throw y instanceof l?y:p()}}async function Y(y){for(let a=0;a<8;a++){let P=await v(),b=y(structuredClone(P.entry));if(JSON.stringify(b)===JSON.stringify(P.entry))return b;b&&be.parse(b),o.assertCurrent();let E;try{E=await o.storage.write(P.revision,b)}catch{throw p()}if(o.assertCurrent(),E!==null){if(!Number.isSafeInteger(E)||E<=P.revision)throw p();return b}}throw new l("PURCHASE_STORAGE_CONFLICT","Another consumer changed this purchase; recover the original attempt")}return{read:v,update:Y,baseUrl:d}}function Ue(o){let d=o.purchases.find(p=>p.type==="checkout");if(!o.actions.includes("continue_checkout")||d?.type!=="checkout")throw new l("PURCHASE_PENDING","No single resumable Checkout is confirmed");return d.checkoutUrl}function fn(o){let d={...o,scope:{...o.scope},executionPolicy:structuredClone(o.executionPolicy)},p=d.session.snapshot();if(!p)throw new l("CUSTOMER_SESSION_REQUIRED","Purchase recovery requires a verified Customer session");let{customerId:v,sessionId:Y}=p,y=!1,a=null,P,b=null,E=!1,q,D,H,O={mode:"idle",status:"idle",actions:["start"],purchases:[]},I=new Map,j=new Map,se=new AbortController,L=new Set,W=Ie(d),ue=we(W.request);function M(e){return{code:e instanceof l?e.code:"PURCHASE_RECOVERY_BLOCKED",message:e instanceof Error?e.message:"The original purchase requires server confirmation",...e instanceof l&&e.status!==void 0?{status:e.status}:{}}}function R(){if(y||d.session.snapshot()?.customerId!==v)throw new l("IDENTITY_CHANGED","The original purchase Customer changed")}let w=Oe({...d,customerId:v,assertCurrent:R,storage:d.storage??Fe({baseUrl:d.baseUrl,scope:d.scope,customerId:v})}),qe=d.session.subscribeIdentity(ce);function ce(){y||(y=!0,clearTimeout(H),se.abort(new l("IDENTITY_CHANGED","Purchase consumer was destroyed")),qe(),a?.reset(),a=null,b=null,W.dispose(),L.clear(),I.clear(),j.clear())}function C(e){R();let n=JSON.stringify(e)!==JSON.stringify(O);O=e,clearTimeout(H),(e.mode==="operation"||e.mode==="run"&&!e.actions.includes("close"))&&["waiting_result","fulfillment","recording"].includes(e.status)&&(H=setTimeout(()=>{T().catch(()=>{})},5e3)),n&&ae(d.onRecovery,structuredClone(e));for(let t of n?L:[]){if(y)break;ae(t,structuredClone(e))}return structuredClone(e)}function h(e){if(R(),!e||e.start.requestId!==P)throw new l("PURCHASE_STORAGE_CONFLICT","This purchase was superseded; the old consumer cannot dispatch")}function F(e){let n=[...e.purchases],t=e.journal.entry?.purchase;return t&&!n.some(u=>u.operationId===t.operationId)&&n.push({receiptId:t.receiptId,operationId:t.operationId,terminal:null}),n}function V(e){return e.run&&!["running","waiting"].includes(e.run.status)&&!e.journal.entry?.command&&!e.journal.entry?.closeCommand&&!e.operationCommand&&F(e).every(n=>n.terminal!==null)}function $(e){if(e.journal.entry?.command||e.journal.entry?.closeCommand||e.operationCommand)return!1;let n=F(e).filter(t=>t.terminal===null);return n.length>0&&n.every(t=>{let u=I.get(t.operationId);return u?.executor==="merchant"&&U({quote:u.quote??null,operation:u,requestId:null,pending:!1,destroyed:!1,canReselect:!1}).type==="checkout"})}function _(e,n){let t=e.journal.entry?.command??e.journal.entry?.closeCommand,u=F(e).map(S=>{let oe=I.get(S.operationId);return S.terminal&&!oe?{type:S.terminal,operationId:S.operationId}:U({quote:oe?.quote??null,operation:oe??null,requestId:t?.requestId??null,pending:!1,destroyed:!1,canReselect:j.get(S.operationId)===!0})}),c=u.filter(S=>!["complete","native"].includes(S.type)),i=c[0],s=c.length===1&&i?.operationId?I.get(i.operationId):void 0;if(s&&(i?.type==="checkout"||i?.type==="cancel"))try{B({allowed:e.allowed.filter(S=>d.executionPolicy.allowed.includes(S))},s.quote)}catch(S){return{mode:n,status:"blocked",actions:["refresh",...n==="run"&&e.run&&["running","waiting"].includes(e.run.status)?["close"]:[]],purchases:u,error:M(S)}}let m;if(n==="operation"&&!t&&i?.type==="cancel"&&s?.quote&&!s.problem&&!s.confirmedAt)try{B({allowed:e.allowed.filter(S=>d.executionPolicy.allowed.includes(S))},s.quote),Date.parse(s.quote.expiresAt)>Date.now()&&(m={operationId:s.operationId,quote:s.quote})}catch{}let f=u.length>0&&c.length===0,x=V(e)||n==="operation"&&f&&!t&&!e.operationCommand?"complete":i?.type==="checkout"?"checkout":i?.type==="fulfillment"?"fulfillment":i?.type==="recording"?"recording":t||e.operationCommand||i&&i.type!=="cancel"||n==="operation"&&!m?"waiting_result":"ready";return{mode:n,status:x,purchases:u,...m?{confirmation:structuredClone(m)}:{},actions:["refresh",...V(e)||$(e)?["start"]:[],...n==="run"&&e.run&&["running","waiting"].includes(e.run.status)?["close"]:[],...e.operationCommand?["retry"]:m?["confirm"]:[],...c.length===1&&i?.type==="checkout"?["continue_checkout"]:[]]}}function X(e){let n=U({quote:e?.quote??null,operation:e??null,requestId:null,pending:!1,destroyed:!1,canReselect:e&&j.get(e.operationId)===!0});return n.type==="complete"||n.type==="native"?n.type:null}function Z(e){if(!e.operation)return;let n={...e.operation,...e.operation.quote?{}:e.quote?{quote:e.quote}:{}};if(n.merchantExecution&&n.merchantExecution.customerId!==v)throw new l("SCOPE_MISMATCH","Purchase execution belongs to another Customer");let t=J(I.get(n.operationId)??null,n);I.set(n.operationId,t),t===n&&j.set(n.operationId,e.canReselect===!0)}async function _e(e){R();for(let t of[e.purchase,e.run.paywall])t&&Z(t);let n=await w.update(t=>{if(h(t),t.run&&(t.run.id!==e.run.id||t.run.versionId!==e.run.source.versionId))throw new l("SCOPE_MISMATCH","The original purchase Run changed");let u=F(t);for(let c of[e.purchase,e.run.paywall]){let i=c?.operation?.operationId??c?.quote?.operationId;if(!c||!i)continue;let s=u.find(f=>f.operationId===i);if(s&&s.receiptId!==c.receiptId)throw new l("INVALID_RESPONSE","The original purchase Receipt changed");let m=X(I.get(i));s?s.terminal??=m:u.push({receiptId:c.receiptId,operationId:i,terminal:m})}return{...t,purchases:u,run:t.run&&(t.run.revision>e.run.revision||!["running","waiting"].includes(t.run.status)&&["running","waiting"].includes(e.run.status))?t.run:{id:e.run.id,versionId:e.run.source.versionId,status:e.run.status,revision:e.run.revision,runExpiresAt:e.run.runExpiresAt}}});h(n),n.run&&!["running","waiting"].includes(n.run.status)&&F(n).some(t=>!t.terminal)&&(n=await ee(n,!n.journal.entry?.command&&!n.journal.entry?.closeCommand,new Set([e.purchase?.operation?.operationId,e.run.paywall?.operation?.operationId].filter(t=>!!t)))),h(n),C(_(n,"run"))}function Ae(){return{async read(){let{entry:e}=await w.read();return h(e),structuredClone(e.journal)},async write(e,n){let t=null;return await w.update(u=>{if(h(u),u.operationCommand&&n?.command&&n.command.operation!=="close")throw new l("PURCHASE_PENDING","Recover the original Operation command before dispatching a Run mutation");return t=null,u.journal.revision!==e?u:(t=e+1,{...u,journal:{revision:t,entry:n}})}),t}}}async function ee(e,n=!1,t=new Set){h(e);let u=F(e);for(let i of u){if(i.terminal)continue;let s=t.has(i.operationId)?I.get(i.operationId):void 0;if(s??=await le(e,i),R(),s.operationId!==i.operationId)throw new l("INVALID_RESPONSE","Original Operation changed");if(s.merchantExecution&&s.merchantExecution.customerId!==v)throw new l("SCOPE_MISMATCH","Purchase execution belongs to another Customer");if(n&&!e.operationCommand&&U({quote:s.quote??null,operation:s,requestId:null,pending:!1,destroyed:!1}).type==="cancel"){if({operation:s}=await ue.attach({operationId:i.operationId,intent:"cancel"}),R(),s.operationId!==i.operationId)throw new l("INVALID_RESPONSE","Original cancellation Operation changed");s=await le(e,i)}I.set(i.operationId,J(I.get(i.operationId)??null,s))}let c=await w.update(i=>{h(i);let s=i.operationCommand&&I.get(i.operationCommand.operationId);return{...i,...s&&(s.confirmedAt||s.merchantExecution||s.status!=="pending")?{operationCommand:void 0}:{},purchases:F(i).map(m=>({...m,terminal:m.terminal??X(I.get(m.operationId))}))}});return h(c),c}async function ne(e){R();let n=await W.request("funnels",e);return R(),n}async function le(e,n){let t=Q(Ee,await ne({operation:"recover_purchase",runId:e.run.id,funnelId:e.start.funnelId,purchase:{receiptId:n.receiptId,operationId:n.operationId}}));if(te(e,t),t.purchase.receiptId!==n.receiptId||t.purchase.operation?.operationId!==n.operationId)throw new l("INVALID_RESPONSE","Original purchase reference changed");return Z(t.purchase),I.get(n.operationId)}async function de(e){for(let n of[e.journal.entry?.command,e.journal.entry?.closeCommand]){if(!n)continue;let t=Q(ve,await ne({operation:"settle_command",runId:e.run.id,funnelId:e.start.funnelId,requestId:n.requestId,...n.operation==="resume"?{}:{command:n}}));if(te(e,t),t.settlement.requestId!==n.requestId)throw new l("INVALID_RESPONSE","Original command settlement changed");t.purchase&&Z(t.purchase);let u=await w.update(c=>{h(c);let i=F(c),{receiptId:s,operationId:m}=t.settlement;if(s&&m){let x=i.find(S=>S.operationId===m);if(x&&x.receiptId!==s)throw new l("INVALID_RESPONSE","Original Receipt changed");x||i.push({receiptId:s,operationId:m,terminal:X(I.get(m))})}let f=t.settlement.state==="settled"?ye(c.journal.entry,n.requestId):c.journal.entry;return{...c,purchases:i,journal:f===c.journal.entry?c.journal:{revision:c.journal.revision+1,entry:f}}});h(u),e=u}return e}function te(e,n){if(n.customerId!==v||n.scope.projectId!==d.scope.projectId||n.scope.environment!==d.scope.environment||n.target.funnelId!==e.start.funnelId||n.target.startRequestId!==e.start.requestId||e.run&&(n.target.runId!==e.run.id||n.target.versionId!==e.run.versionId))throw new l("SCOPE_MISMATCH","The original recovery binding changed")}async function re(e,n){if(h(e),e.run&&(e=await de(e)),!F(e).length&&V(e))return C(_(e,"operation"));if(!F(e).length)return C({mode:"blocked",status:"blocked",actions:["refresh"],purchases:[],error:M(n)});E=!0;let t=await ee(e);return C(_(t,"operation"))}async function G(e,n=!1,t=!0){if(P=e.start.requestId,b=structuredClone({requestId:e.start.requestId,funnelId:e.start.funnelId,locale:e.start.locale,parameters:e.start.parameters}),!a){let u=e.run?{operation:"recover_run",runId:e.run.id,funnelId:e.start.funnelId}:{operation:"recover_start",intent:n?"resume":"lookup",start:{requestId:e.start.requestId,funnelId:e.start.funnelId,locale:e.start.locale,parameters:e.start.parameters}},c;try{c=await ne(u)}catch(f){if(!e.run&&f instanceof l&&(f.status===void 0||f.status>=500))return C({mode:"blocked",status:"blocked",actions:["refresh","retry"],purchases:O.purchases,error:M(f)});throw f}let i=Q(Ce,c);if(i.customerId!==v||i.scope.projectId!==d.scope.projectId||i.scope.environment!==d.scope.environment)throw new l("SCOPE_MISMATCH","Recovery Customer or environment changed");if(i.outcome==="unknown")return C({mode:"blocked",status:"blocked",actions:["refresh","retry"],purchases:O.purchases,error:{code:"RESULT_UNKNOWN",message:"The original Start outcome remains unknown; retry only its original input"}});te(e,i);let s=await w.update(f=>(h(f),{...f,run:{id:i.target.runId,versionId:i.target.versionId,status:i.target.status,revision:i.view?.revision??f.run?.revision??0,runExpiresAt:i.target.runExpiresAt}}));if(h(s),e=s,i.access.type==="operation_only")return re(e,new l("RUN_RECONCILIATION_REQUIRED","Only the original command and Operation can be recovered"));e=await de(e);let m=i.view;if(m.locale!==e.start.locale||!Pe(m.parameters,e.start.parameters))throw new l("INVALID_RESPONSE","The original Start input changed");a=Re({...d,customerRun:{runId:i.target.runId,customerId:v,startRequestId:e.start.requestId},funnelId:e.start.funnelId,funnelExecutionPolicy:{allowed:e.allowed.filter(f=>d.executionPolicy.allowed.includes(f))},funnelCommandStorage:Ae(),onAcceptedResponse:_e},{scope:i.scope,run:m})}try{await a.get(),a.view?.pendingRequest?.requestId===e.start.requestId&&!a.pendingCommands?.length&&await a.resume(a.view.pendingRequest.requestId);for(let c of a.pendingCommands??[])c.operation!=="close"&&await a.settle?.(c.requestId);a.pendingCommands?.length&&await a.retry(),R();let u=(await w.read()).entry;return h(u),C(_(u,"run"))}catch(u){if(R(),t&&u instanceof l&&(u.status===401||u.status===409&&u.reason==="STATE_CHANGED")){a.reset(),a=null;let c=(await w.read()).entry;return h(c),G(c,!1,!1)}throw u}}function A(e,n="read"){if(R(),q)return n==="read"||n===D?q:q.then(()=>A(e,n),()=>A(e,n));clearTimeout(H);let t=e().catch(u=>{throw y||C({mode:"blocked",status:"blocked",actions:["refresh"],purchases:O.purchases,error:M(u)}),u});return q=t,D=n,t.then(()=>{q===t&&(q=void 0,D=void 0)},()=>{q===t&&(q=void 0,D=void 0)}),t}function T(){return A(async()=>{let{entry:e}=await w.read();return e?(P&&e.start.requestId!==P&&(a?.reset(),a=null,I.clear(),j.clear()),E&&P===e.start.requestId?re(e,O.error):G(e)):C({mode:"idle",status:"idle",actions:["start"],purchases:[]})})}async function pe(){let e=await T();return e.mode==="operation"&&!e.actions.includes("confirm")&&!e.actions.includes("retry")?e:A(async()=>{let n=(await w.read()).entry;if(h(n),!E){if(!a?.view?.paywall?.quote)throw new l("PURCHASE_PENDING","Read the original quote before confirming");let s=a.view.paywall.operation;if(s?.confirmedAt||s?.merchantExecution||s&&s.status!=="pending")return C(_(n,"run"));if(a.pendingCommands?.length)await a.retry();else{let f=a.view;await a.submit({operation:"submit",requestId:crypto.randomUUID(),nodeId:f.nodeId,visit:f.visit,revision:f.revision,input:{type:"paywall_confirm",operationId:f.paywall.quote.operationId}})}let m=(await w.read()).entry;return h(m),C(_(m,"run"))}let t=n.operationCommand?.operationId??O.confirmation?.operationId,u=t&&I.get(t);if(!t||!u||n.journal.entry?.command||n.journal.entry?.closeCommand)throw new l("PURCHASE_PENDING","The original Run command must be settled before Operation confirmation");B({allowed:n.allowed.filter(s=>d.executionPolicy.allowed.includes(s))},u.quote),await w.update(s=>{if(h(s),s.journal.entry?.command||s.journal.entry?.closeCommand||s.operationCommand&&s.operationCommand.operationId!==t)throw new l("PURCHASE_PENDING","Another original command is pending");return{...s,operationCommand:{operationId:t,intent:"confirm"}}});let c=await ue.attach({operationId:t,intent:"confirm"});if(R(),c.operation.operationId!==t)throw new l("INVALID_RESPONSE","Original confirmation Operation changed");I.set(t,J(u,c.operation));let i=(await w.read()).entry;return h(i),C(_(await ee(i,!1,new Set([t])),"operation"))},"confirm")}async function je(){let e=a?.view;if(!(!a||!e||!["running","waiting"].includes(e.status)))try{await a.submit({operation:"close",requestId:crypto.randomUUID(),nodeId:e.nodeId,visit:e.visit,revision:e.revision})}catch{}}return{get controller(){return a},get recovery(){return structuredClone(O)},get attempt(){return R(),structuredClone(b)},get identitySignal(){return se.signal},start(e){let n=k.parse({...structuredClone(e),operation:"start",requestId:e.requestId??crypto.randomUUID()});if(n.operation!=="start"||n.customer||n.customerData)throw new l("INVALID_REQUEST","A Customer-owned Funnel start is required");return A(async()=>{let t=(await w.read()).entry;t&&t.start.requestId===P&&$(t)&&await je();let u=await w.update(c=>{if(c&&!V(c)&&!$(c)){if(c.start.funnelId!==n.funnelId)throw new l("PURCHASE_PENDING","Recover the original Funnel before starting another purchase");return c}return{schemaVersion:1,baseUrl:w.baseUrl,scope:d.scope,customerId:v,sessionId:Y,start:n,allowed:[...d.executionPolicy.allowed],purchases:[],journal:{revision:0,entry:null}}});if(!u)throw new l("PURCHASE_STORAGE_INVALID","Original start was not retained");return P!==u.start.requestId&&(a?.reset(),a=null,I.clear(),j.clear(),E=!1),E?re(u,O.error):G(u,!0)},`start:${n.funnelId}`)},refresh:T,confirm:pe,retry:()=>E?pe():A(async()=>{let{entry:e}=await w.read();return e?G(e,!0):C({mode:"idle",status:"idle",actions:["start"],purchases:[]})},"retry"),async close(){return a?.view?A(async()=>{if(!a?.view)throw new l("PURCHASE_PENDING","Recover the original Run before closing");if(a.pendingCommands?.find(t=>t.operation==="close"))await a.retry();else if(["running","waiting"].includes(a.view.status)){let t=a.view;await a.submit({operation:"close",requestId:crypto.randomUUID(),nodeId:t.nodeId,visit:t.visit,revision:t.revision})}let n=(await w.read()).entry;return h(n),C(_(n,"run"))},"close"):T()},async continueCheckout(e){let n=await T();R(),await e(Ue(n))},subscribe(e){return L.add(e),()=>{L.delete(e)}},destroy:ce}}export{Fe as a,Ue as b,fn as c};
@@ -1 +0,0 @@
1
- import{a as kn,b as rn,c as on,d as _e,e as Fn,f as We,h as Dn}from"./chunk-HQPP76BS.js";import{c as Cn,e as Pn,f as Rn,h as En,i as qn,j as Be,k as Ae,l as je}from"./chunk-BRAVNBCC.js";import{$ as Qe}from"./chunk-R23IGK5U.js";import{a as ze,e as gn,f as vn,g as hn,h as In,i as bn}from"./chunk-EHDHWYVJ.js";import{b as wn}from"./chunk-BXPXJARS.js";import{R as fn,qa as yn}from"./chunk-N7YXDSQL.js";import{a as P}from"./chunk-X4W22IH6.js";import{b as Sn,e as On}from"./chunk-SLUA7ABW.js";import{d as Tn}from"./chunk-KIMX3OIV.js";import{a as le}from"./chunk-DSPLGTQI.js";import{b as mn}from"./chunk-7QL4GF4C.js";var Te=new WeakMap;function Bn(n){let g=n.view,w=g?.paywall?.resolution;if(!g||!["running","waiting"].includes(g.status)||g.stopped||!w||"document"in w||!n.resolvePaywall||n.identitySignal?.aborted)return;let e=JSON.stringify(w);if(Te.get(n)?.key===e)return;let p=JSON.parse(e),D=n.identitySignal,a=Promise.resolve().then(async()=>{D?.throwIfAborted();let s=await n.resolvePaywall(p);return D?.throwIfAborted(),s}),S={key:e,content:a};return Te.set(n,S),a.catch(()=>{}),()=>{Te.get(n)===S&&Te.delete(n)}}function Nn(n,g){let w=Te.get(n);return Te.delete(n),w?.key===JSON.stringify(g)?w.content:n.resolvePaywall(g)}async function An(n){let{session:g,load:w}=Qn(n);try{return await w(),g}catch(e){throw g.destroy(),e}}function Qn(n){let g=n.view;if(!g?.paywall)throw new P("INVALID_REQUEST","The current node is not a Paywall");let w=g.paywall.receiptId,e=g.nodeId,p=g.visit,D=g.paywall.resolution,a=g.paywall,S="document"in D?{document:D.document,offering:D.offering,capabilities:D.capabilities}:null;function s(){let i=a.resolution;return"document"in i?i:S&&{...i,document:S.document,offering:S.offering,capabilities:gn(i.capabilities,S.capabilities)}}function v(i){if(!vn(i,D))throw new P("INVALID_RESPONSE","The pinned Paywall binding changed")}let u=!1,q=new Set,A=null;function V(){let i=s();if(i&&!u)for(let l of q)le(l,structuredClone(i))}async function k(){J();let i=s();if(i)return structuredClone(i);if(!A){let l=(async()=>{if("document"in a.resolution||!n.resolvePaywall)throw new P("INVALID_RESPONSE","Public Paywall reader is unavailable");let c=await Nn(n,a.resolution);return J(),v(c),S={document:c.document,offering:c.offering,capabilities:c.capabilities},V(),s()})();A=l;let o=()=>{A===l&&(A=null)};l.then(o,o)}return A.then(l=>structuredClone(l))}let d=new AbortController,F=(n.pendingCommands??(n.pendingCommand?[n.pendingCommand]:[])).find(i=>i.operation==="submit"&&i.nodeId===e&&i.visit===p&&i.input.type==="paywall_quote")?.requestId??g.paywall.purchaseRequestId,R=0,M=null,C=new Set,H=null,h=new Map;function _(i){if(i.purchase&&i.purchase.receiptId!==w)throw new P("INVALID_RESPONSE","Purchase receipt changed");let l=i.run.paywall;return i.purchase??(l?.receiptId===w?l:null)}function J(){if(u)throw new P("IDENTITY_CHANGED","Paywall presentation has closed")}function z(i,l,o){if(J(),l!==R||o!==void 0&&a.quote?.operationId!==o)return!1;let c=a.selectionGeneration??0,y=i.run.paywall;if(y?.receiptId===w){if((y.selectionGeneration??0)<(a.selectionGeneration??0))return!1;v(y.resolution)}let I=_(i),B=y?.receiptId===w&&(y.selectionGeneration??0)>c,G=B?I?.quote??null:I?.quote??a.quote,b=I?.operation??(G?.operationId===a.quote?.operationId?a.operation:null);return G&&b&&hn(b,{operationId:G.operationId},"Purchase operation changed"),(B||G?.operationId!==a.quote?.operationId)&&(R++,y?.receiptId===w&&(F=y.purchaseRequestId)),y?.canReselect===!0&&y.purchaseRequestId===H&&!(n.pendingCommands??[n.pendingCommand]).some($=>$?.requestId===H)&&(H=null),a={...a,...y?.receiptId===w?y:{},quote:G,operation:bn(a.operation,b,!0)},V(),!0}function L(i,l,o){return new Promise((c,y)=>{let I=!1,B=()=>{clearTimeout(Re),d.signal.removeEventListener("abort",$)},G=Ee=>{I||(I=!0,B(),c(Ee))},b=Ee=>{I||(I=!0,B(),y(Ee))},$=()=>b(new P("IDENTITY_CHANGED","Paywall presentation has closed")),Re=setTimeout(()=>b(new P("COMMAND_PENDING","The purchase command is still pending; retry the original request",202,o)),Math.max(0,l-Date.now()));d.signal.addEventListener("abort",$,{once:!0}),d.signal.aborted&&$(),i.then(G,b)})}function de(i){return new Promise(l=>{let o=()=>{clearTimeout(c),d.signal.removeEventListener("abort",o),l()},c=setTimeout(o,i);d.signal.addEventListener("abort",o,{once:!0}),d.signal.aborted&&o()})}function Y(i,l){J();let o=h.get(i)??n.pendingCommands?.find(I=>I.requestId===i)??n.pendingCommand;if(o?.operation==="submit"&&o.requestId===i&&o.nodeId===e&&o.visit===p){l.type==="paywall_quote"&&o.input.type==="paywall_quote"&&o.input.predecessor&&!l.predecessor&&(l={...l,predecessor:o.input.predecessor});let I=Qe.parse(o),B=Qe.parse({...o,input:l});if(I.operation!=="submit"||B.operation!=="submit"||JSON.stringify(I.input)!==JSON.stringify(B.input))throw new P("CONFLICT","A purchase request cannot change its input");return h.set(i,I),I}let c=n.view;if(!c||c.nodeId!==e||c.visit!==p||c.paywall?.receiptId!==w)throw new P("PRECONDITION_FAILED","The Paywall visit has changed");let y=Qe.parse({operation:"submit",requestId:i,nodeId:e,visit:p,revision:c.revision,input:structuredClone(l)});if(y.operation!=="submit")throw new P("INVALID_REQUEST","A purchase submission is required");return h.set(i,y),y}async function ce(i,l){J();let{requestId:o,input:c}=i,y=Date.now()+3e4;C.add(o);try{let I=await L(n.submit(i),y,o);for(;I.run.pendingRequest?.requestId===o&&Date.now()<y&&!u&&(await de(Math.min(1e3,y-Date.now())),!(u||Date.now()>=y));)I=await L(n.resume(o),y,o);if(u)throw new P("IDENTITY_CHANGED","Paywall presentation has closed");if(I.run.pendingRequest?.requestId===o)throw new P("COMMAND_PENDING","The purchase command is still pending; retry the original request",202,o);if(!z(I,l,c.type==="paywall_confirm"||c.type==="paywall_cancel"?c.operationId:void 0))throw new P("PRECONDITION_FAILED","The purchase selection has changed");H===o&&(H=null)}catch(I){if(H=o,c.type==="paywall_quote"&&n.settle&&!u&&I instanceof P&&I.status!==void 0&&![401,425].includes(I.status)&&!I.retryable&&I.recovery!=="recover_operation")try{if((await L(n.settle(o),y,o)).settlement?.state==="settled"){let G=await L(n.get(),y,o);z(G,l)&&G.run.paywall?.purchaseRequestId===o&&a.canReselect===!0&&h.delete(o)}}catch{}throw I instanceof P&&I.code==="COMMAND_PENDING"&&I.status===void 0&&h.delete(o),I}finally{C.delete(o)}}async function re(i){if(!a.quote)throw new P("INVALID_REQUEST","A quoted purchase is required");let l=i==="confirm"?"paywall_confirm":"paywall_cancel",o=[...h.values(),...n.pendingCommands??(n.pendingCommand?[n.pendingCommand]:[])].find(y=>y.operation==="submit"&&y.input.type===l&&"operationId"in y.input&&y.input.operationId===a.quote.operationId),c=o?.operation==="submit"&&o.input.type===l&&"operationId"in o.input&&o.input.operationId===a.quote.operationId?o.requestId:crypto.randomUUID();if(await ce(Y(c,{type:i==="confirm"?"paywall_confirm":"paywall_cancel",operationId:a.quote.operationId}),R),!a.operation)throw new P("INVALID_RESPONSE","The accepted purchase result is missing");return structuredClone(a.operation)}let T={get view(){return structuredClone(s())},get quote(){return a.quote?structuredClone(a.quote):null},get operation(){return a.operation?structuredClone(a.operation):null},get webViewUrl(){return n.webViewUrl},get canReselect(){return a.canReselect===!0&&H===null},get recovery(){let i=n.pendingCommands??(n.pendingCommand?[n.pendingCommand]:[]),l=n.pendingPurchase;if(l&&(l.receiptId!==w||l.operationId!==a.quote?.operationId))return{type:"recover",operationId:l.operationId,requestId:i[0]?.requestId??null};let o=ze({quote:a.quote,operation:a.operation,requestId:i[0]?.requestId??H??F,pending:C.size>0||i.length>0||H!==null,destroyed:u,canReselect:a.canReselect});return o.type==="recover"&&o.requestId===null&&!u&&n.hasDurableJournal===!0&&!a.quote&&!a.operation&&(a.selectionGeneration??0)===0&&!l&&!i.length&&!C.size&&!F?{type:"native",operationId:null}:o},get pendingCancellation(){return!u&&(n.pendingCommands??(n.pendingCommand?[n.pendingCommand]:[])).some(i=>i.operation==="submit"&&i.nodeId===e&&i.visit===p&&i.input.type==="paywall_cancel"&&i.input.operationId===a.quote?.operationId)},subscribe(i){return u?()=>{}:(q.add(i),()=>q.delete(i))},async refresh(){J();let i=R,l=await n.get();if(z(l,i),l.run.paywall?.receiptId!==w)throw new P("PRECONDITION_FAILED","Paywall presentation has changed");return k()},preview(i){let l=s();if(!l)return Promise.reject(new P("PRECONDITION_FAILED","Load the Paywall presentation first"));if(F&&F!==i.requestId&&(M||a.canReselect!==!0))return Promise.reject(new P("COMMAND_PENDING","Retry the original purchase before starting another"));let o=l.document.buttons[i.actionId],c=o?.type==="checkout"?wn(o.product,i.selection,l.capabilities):null;if(!c)return Promise.reject(new P("PRODUCT_UNAVAILABLE","Choose an available Product in this purchase area"));let y=yn(l.document.screen,c,i.selection,l.capabilities),I=F!==i.requestId&&(a.selectionGeneration??0)>0?{operationId:a.quote?.operationId??null,generation:a.selectionGeneration??0}:void 0;if(I&&a.canReselect!==!0)return Promise.reject(new P("COMMAND_PENDING","Original purchase requires authoritative termination"));let B;try{B=Y(i.requestId,{type:"paywall_quote",actionId:i.actionId,productVersionId:c,...Object.keys(y).length?{featureQuantities:y}:{},...I?{predecessor:I}:{},...i.offerId?{offerId:i.offerId}:{},...i.nativeOffer?{nativeOffer:i.nativeOffer}:{}})}catch($){return Promise.reject($)}if(F===i.requestId&&M)return M;F!==i.requestId&&R++;let G=R;F=i.requestId;let b=(async()=>{if(await ce(B,G),!a.quote)throw new P("INVALID_RESPONSE","The accepted quote is missing");return In(a.quote,{productVersionId:c,featureQuantities:y},"The selected purchase changed"),structuredClone(a.quote)})();return M=b,b.then(()=>{M===b&&(M=null)},$=>{M===b&&(M=null),F===i.requestId&&n.pendingCommand?.requestId!==i.requestId&&$ instanceof P&&$.status!==void 0&&$.status<500&&![401,425].includes($.status)&&(F=null)}),b},confirm:()=>re("confirm"),cancel:()=>re("cancel"),async read(){if(J(),!a.quote)throw new P("INVALID_REQUEST","A quoted purchase is required");let i=a.quote.operationId,l=R,o=n.pendingCommands?.find(G=>G.operation==="submit"&&(G.input.type==="paywall_confirm"||G.input.type==="paywall_cancel")&&G.input.operationId===i)??n.pendingCommand;o?.operation==="submit"&&(o.input.type==="paywall_confirm"||o.input.type==="paywall_cancel")&&o.input.operationId===i&&await n.settle?.(o.requestId);let c=await n.get(void 0,{receiptId:w,operationId:i});J();let y=_(c);if(y?.quote&&y.quote.operationId!==i||y?.operation&&y.operation.operationId!==i)throw new P("INVALID_RESPONSE","Purchase operation changed");let I=z(c,l,i),B=I?a.operation:y?.operation;if(!B)throw new P("INVALID_RESPONSE","The current purchase result is missing");return I&&C.size===0&&!(n.pendingCommands?.length??(n.pendingCommand?1:0))&&(H=null),structuredClone(B)},destroy(){u=!0,E(),q.clear(),d.abort(),h.clear()}},E=n.subscribe(i=>{u||i.nodeId!==e||i.visit!==p||i.paywall?.receiptId!==w||(i.paywall.selectionGeneration??0)<(a.selectionGeneration??0)||(v(i.paywall.resolution),a={...a,resolution:i.paywall.resolution},V())});return{session:T,load:k}}function _n(n){let g=new Set,w=new Set,e=null;async function p(s,v){let u=!1;for(;!n.stopped&&n.key===s&&n.client.pendingCommand?.requestId===v;){if(!n.client.settle)throw new P("COMMAND_PENDING","The original display acknowledgement is still pending");await n.client.settle(v),u=!0,n.client.pendingCommand?.requestId===v&&await new Promise(q=>setTimeout(q,1500))}n.stopped||n.key!==s||(u&&await n.client.get(),!(n.stopped||n.key!==s)&&g.add(s))}function D(s,v){e=v;let u=()=>{e===v&&(e=null),w.delete(s)};return v.then(u,q=>{u(),n.busy||n.fail(q)}),v}function a(s){if(n.reviewing||g.has(s)||w.has(s)||n.stopped)return;w.add(s);let v=async()=>{if(n.reviewing||n.stopped||n.key!==s||g.has(s)){w.delete(s);return}if(n.busy||n.client.pendingCommand){setTimeout(()=>{v()},250);return}let u=(async()=>{if(n.staleRead){if(await n.staleRead,n.stopped||n.key!==s)return;if(n.client.pendingCommand){setTimeout(()=>{v()},250);return}}let q=n.client.view,A=n.expected(),V=A.requestId;try{await n.client.submit({operation:"shown",...A})}catch(k){if(!(k instanceof P)||k.code!=="CONFLICT"||k.status!==409||n.client.pendingCommand)throw k;await n.client.get();let d=n.client.view;if(n.stopped||n.reviewing||n.key!==s||!d||!q||d.id!==q.id||d.source.versionId!==q.source.versionId||d.nodeId!==A.nodeId||d.visit!==A.visit||d.revision<=A.revision||d.stopped||!d.screen&&(!d.paywall||d.paywall.receiptId!==q.paywall?.receiptId)||!["running","waiting"].includes(d.status)||n.client.pendingCommand)throw k;let O=n.expected();V=O.requestId,await n.client.submit({operation:"shown",...O})}await p(s,V)})();D(s,u)};v()}function S(){if(e)return e;let s=n.client.pendingCommand;if(s?.operation!=="shown")return null;let v=n.key;return w.add(v),D(v,(async()=>{await n.client.retry(),await p(v,s.requestId)})())}return{report:a,settled:S,get inFlight(){return e}}}function Ln(n){let g={},w=new Map;async function e(p){let D=n.client.view,a=D?.screen,S=a?.customerData.nodes[p.nodeId];if(n.stopped||n.busy||!D||!a||!S)return;if(!["refresh","next","previous","filter","sources_next","sources_previous"].includes(p.action)){let k=n.document,d=k?fn(k,p.nodeId):null,O=d?.type==="customer_data"?d.data.outputs?.[p.action]:void 0;O&&a.outputs.includes(O)?await n.perform(()=>n.client.submit({operation:"submit",...n.expected(),input:{type:"screen",output:O,answers:n.answers,selection:p.value?{[p.nodeId]:p.value}:{}}})):await n.onIntent?.(p,D);return}let v=p.action.startsWith("sources_")?S.resources.find(k=>k.key===p.value):null;if(p.action.startsWith("sources_")&&!v)throw new P("INVALID_REQUEST","Choose a current resource");let u=`${D.visit}:${p.nodeId}:${v?.key??""}`,q=w.get(u)??[null],V=g[p.nodeId]??{page:1,after:null,filter:"all",...v?{resourceKey:v.key}:{}};if(p.action==="filter"){let k=p.value;if(!k||!(S.source==="offer_history"?["all","issued","reserved","redeemed","expired","revoked"]:["all","purchase","refund","source","usage","debt","settlement"]).includes(k))throw new P("INVALID_REQUEST","Unknown data filter");V={page:1,after:null,filter:k},q.splice(0,q.length,null)}else if(p.action==="next"||p.action==="sources_next"){let k=v?.sources.at(-1),d=v?k?{kind:"ledger",cursor:{at:k.detail[0],id:k.id,type:"source"}}:null:a.dataCursors[p.nodeId];if(!d||!v&&!S.hasNext)return;q[V.page]=d,V={...V,page:V.page+1,after:d}}else if(p.action==="previous"||p.action==="sources_previous"){if(V.page<=1)return;V={...V,page:V.page-1,after:q[V.page-2]??null}}w.set(u,q),g={...g,[p.nodeId]:V},await n.perform(()=>n.client.get({nodeId:D.nodeId,visit:D.visit,revision:D.revision,components:g}))}return{get queries(){return g},intent:e,reset(){g={},w.clear()}}}function Vn(n){let{doc:g,holder:w,reviewHolder:e,mountScreenPreview:p}=n,D=!1,a,S=0,s=null,v="",u,q=new Map,A=d=>d?`${d.id}:${d.nodeId}:${d.visit}:${d.revision}:${d.paywall?.quote?.operationId??""}`:"";async function V(d){if(n.stopped||!n.client.review||D&&d===a&&u?.active)return;let O=!D||d!==a;D||(v=A(n.client.view),q.set(v,structuredClone(n.answers))),D=!0,a=d,w.hidden=!0,n.suspend(!0),e.hidden=!1;let F=++S;O&&(u?.finish("dismissed"),s?.destroy(),s=null,e.replaceChildren(),u=je(e,n.loadingOptions,"funnel",()=>{k()}));let R=O?u:void 0;try{if(R?.start(!1,n.client.view?.locale),F!==S||n.stopped)return;let M=n.client.review(d),C=await(R?.wait(M,Ae)??M);if(n.stopped||F!==S||!D)return;if(!C.review)throw new P("INVALID_RESPONSE","Historical projection is missing");s?.destroy(),s=null,R||e.replaceChildren();let H=g.createElement("div"),h=R?Be(H,e):()=>{};e.append(H);let _=C.run.locale.startsWith("zh"),J=n.chrome;H.style.cssText=J.history;let z=g.createElement("p");z.textContent=_?"\u53EA\u8BFB\u56DE\u770B":"Read-only history",z.style.cssText=J.historyTitle,H.append(z);let L=g.createElement("p");L.style.cssText=J.historyNote,L.textContent=C.review.pages.length?_?"\u9009\u62E9\u4E00\u9875\u67E5\u770B\u5F53\u65F6\u7684\u5185\u5BB9\uFF0C\u56DE\u770B\u4E0D\u4F1A\u6539\u52A8\u4EFB\u4F55\u4FE1\u606F\u3002":"Choose a page to see it as it was. Nothing here can be changed.":_?"\u8FD8\u6CA1\u6709\u53EF\u56DE\u770B\u7684\u9875\u9762\u3002":"There are no earlier pages yet.",H.append(L);let de=C.review.page?.receiptId,Y=g.createElement("div");Y.style.cssText=J.historyPages;for(let[T,E]of C.review.pages.entries()){let i=g.createElement("button");i.type="button",i.textContent=_?`\u7B2C ${T+1} \u9875`:`Page ${T+1}`;let l=de!==void 0&&E.receiptId===de;i.style.cssText=l?J.primary:J.secondary,l&&i.setAttribute("aria-current","page"),_e(i,()=>n.chrome.focus),i.onclick=()=>{V(E.receiptId)},Y.append(i)}if(Y.childElementCount&&H.append(Y),C.review.page){let T=C.review.page,E=g.createElement("div");E.inert=!0,E.style.cssText=J.historyPage,H.append(E),s=p(E,{mode:"live",rendererUrl:n.client.webViewUrl,title:T.document.name,onAction:()=>{},onAnswers:()=>{},onCustomerDataIntent:()=>{},onRendered:()=>{F===S&&!n.stopped&&R?.present(h)},onError:l=>{if(F!==S||n.stopped)return;let o=new Error(l);R?.finish("error",o),s?.destroy(),s=null,H.remove(),n.fail(o)},onEscape:()=>{k()}});let i=s;if(i.update(T.document,C.run.locale,{serverInput:{bindings:T.inputs,answers:T.answers,values:T.values}}),await i.ready,n.stopped||F!==S||!D)return}let ce=_?{issued:"\u5DF2\u9886\u53D6",reserved:"\u5DF2\u9884\u7559",redeemed:"\u5DF2\u4F7F\u7528",expired:"\u5DF2\u8FC7\u671F",revoked:"\u5DF2\u64A4\u9500",unknown:"\u72B6\u6001\u5F85\u786E\u8BA4"}:{issued:"Issued",reserved:"Reserved",redeemed:"Used",expired:"Expired",revoked:"Revoked",unknown:"Status unconfirmed"},re=g.createElement("div");re.style.cssText=J.historyRecords;for(let T of[...C.review.coupons.map((E,i)=>`${_?"\u4F18\u60E0\u5238":"Coupon"} ${i+1}: ${ce[E.status]}`),...C.review.purchases.map((E,i)=>`${_?"\u8D2D\u4E70":"Purchase"} ${i+1}: ${Dn(E.status,_)}`)]){let E=g.createElement("p");E.textContent=T,E.style.margin="0",re.append(E)}re.childElementCount&&H.append(re),C.review.page||R?.present(h),n.client.view&&await n.enqueue(n.client.view)}catch(M){if(F!==S||n.stopped)return;R?.finish("error",M),s?.destroy(),s=null,e.replaceChildren(),n.fail(M)}}async function k(){if(!D||n.stopped||!n.client.review)return;let d=++S;u?.finish("dismissed");try{if(await n.client.review(),n.stopped||d!==S)return;D=!1,S++,u?.finish("dismissed"),s?.destroy(),s=null,e.replaceChildren(),e.hidden=!0,w.hidden=!1;let O=n.client.view;A(O)!==v?(q.set(v,structuredClone(n.answers)),n.resetScreen()):(q.delete(v),n.suspend(!1)),O&&await n.enqueue(O)}catch(O){if(d!==S||n.stopped)return;s?.destroy(),s=null,e.replaceChildren(),n.fail(O)}}return{get active(){return D},get receipt(){return a},open:V,exit:k,get drafts(){return new Map([...q].map(([d,O])=>[d,structuredClone(O)]))},stop(){D=!1,S++,u?.finish("dismissed"),s?.destroy(),s=null,e.replaceChildren(),e.hidden=!0,w.hidden=!1}}}function Mn(n){if(!n.client.pageExperiments)throw new Error("The Run controller does not support page experiments");let g=n.client.pageExperiments.bind(n.client),w=!1,e=!1,p=0,D=!1,a=!1,S="",s=()=>{let h=n.client.view;return JSON.stringify([h?.id,h?.source.versionId,h?.visit,h?.revision,h?.status,h?.stopped])},v=new Map,u=new Set,q={},A=new Map,V=Sn(n.appManifestRelease),k=()=>{for(let h of v.values())h.effect.revert();v.clear()},d=()=>{k();for(let h of A.values())h();A.clear()};function O(h){if(w||u.has(h))return;u.add(h);let _=p;g(n.appManifestRelease,[h]).catch(J=>{u.delete(h),!w&&_===p&&le(n.onError,J)})}async function F(){if(w)return;S=s();let h=n.client.view;if(!h||h.stopped||!["running","waiting"].includes(h.status)){p++,d();return}if(document.visibilityState==="hidden")return;if(D){a=!0;return}D=!0;let _=++p,J=`${h.id}:${h.visit}:${h.revision}`,z=location.href;try{let[L,{applyVisualVariation:de}]=await Promise.all([g(n.appManifestRelease),import("./visual-dom-6DCUZGPB.js")]),Y=n.client.view;if(w||_!==p||!Y||Y.stopped||!["running","waiting"].includes(Y.status)||`${Y.id}:${Y.visit}:${Y.revision}`!==J||location.href!==z)return;let ce=new Set,re=new Set;for(let T of L.assignments){let E=`${L.payload.environmentId}:${T.experimentKey}`;if(re.add(E),A.has(E)||A.set(E,On(E,q)),!!T.inExperiment)for(let i of L.payload.experiments){if(i.key!==T.experimentKey||!mn(location.href,i.urlPatterns??[]))continue;let l=i.meta?.findIndex(G=>G.key===T.variationKey)??-1,o=i.variations[l];if(!o?.renderGuard)continue;let c=T.receiptId+":"+i.changeId,y=JSON.stringify([T.variationKey,o]);ce.add(c);let I=v.get(c);if(I?.signature===y){I.effect.applied&&O(T.receiptId);continue}v.get(c)?.effect.revert(),v.delete(c);let B=de(o,{requireUniqueTargets:!0,boundVariations:i.variations,allowJs:!1,onApplied:()=>O(T.receiptId),onError:G=>le(n.onError,G)});v.set(c,{signature:y,effect:B}),B.applied&&O(T.receiptId)}}for(let[T,E]of v)ce.has(T)||(E.effect.revert(),v.delete(T));for(let[T,E]of A)re.has(T)||(E(),A.delete(T))}catch(L){_===p&&d(),!w&&_===p&&le(n.onError,L)}finally{D=!1,a&&!w&&(a=!1,F())}}let R=n.client.subscribe(()=>{if(s()===S)return;S=s(),p++;let h=n.client.view;(!h||h.stopped||!["running","waiting"].includes(h.status))&&d(),e&&F()}),M=Tn(()=>{p++,d(),e&&F()}),C=()=>{p++,k()};document.addEventListener("visibilitychange",C);let H=We({document,run:async()=>{e&&await F()},delay:()=>e&&!w?15e3:void 0});return{async start(){e||w||(e=!0,await H.refresh())},refresh:F,destroy(){w=!0,p++,H.destroy(),document.removeEventListener("visibilitychange",C),R(),M(),d(),V.destroy()}}}var sn=5e3;async function zn(n,g,w){let e=g,[{mountScreenPreview:p},{showPaywall:D}]=await Promise.all([import("./screen-renderer-3CBREMIS.js"),import("./paywall-XAXSMLDU.js")]),a=e.client.identitySignal;e.signal?.throwIfAborted(),a?.throwIfAborted();let S=e.appManifestRelease?Mn({client:e.client,appManifestRelease:e.appManifestRelease,onError:e.onError}):void 0;S?.start();let s=n.ownerDocument,v=En(s),u=s.createElement("section"),q=s.createElement("div"),A=s.createElement("div"),V=s.createElement("div"),k=s.createElement("button");V.hidden=!0,k.type="button";let d=s.createElement("p"),O=s.createElement("p"),F=s.createElement("button"),R=s.createElement("button"),M=s.createElement("button"),C=s.createElement("dialog"),H;u.dataset.indianaFunnel="",u.setAttribute("aria-busy","false"),d.setAttribute("role","status"),O.setAttribute("role","alert"),O.hidden=!0,F.type=R.type=M.type="button",A.append(F,k,d,O,M,R),u.append(q,V,A),n.append(u);let h=kn,_=rn(h),J="",z=(s.documentElement.lang||"").startsWith("zh"),L,de="",Y;for(let t of[F,k,M,R])_e(t,()=>_.focus);function ce(){let t=z?"\u5173\u95ED":"Close";R.parentElement===C?(R.textContent="\xD7",R.setAttribute("aria-label",t),Rn(R,h)):(R.textContent=t,R.removeAttribute("aria-label"),R.style.cssText=_.link+";margin-inline-start:auto")}function re(t){let r=t?.screen?.content.document.theme??h,f=JSON.stringify([r.primary,r.background,r.text,r.radius,r.font,R.parentElement===C]);f!==J&&(J=f,h=r,_=rn(h,R.parentElement===C),u.style.cssText=_.root+";min-width:0",A.style.cssText=_.bar,F.style.cssText=k.style.cssText=_.secondary,M.style.cssText=_.primary,d.style.cssText=_.status,O.style.cssText=_.alert,ce(),on(F))}function T(){A.hidden=F.hidden&&k.hidden&&M.hidden&&O.hidden&&!d.textContent&&(R.hidden||R.parentElement!==A),L?.responsive&&Y!==void 0&&L.setContentHeight(Y+A.getBoundingClientRect().height)}re();let E=null,i=null,l=null,o="",c="",y=!1,I="",B="",G="",b=!1,$=0,Re=!1,Ee="",Ke=null,Ye=Promise.resolve(),an=!e.client.view,W=w,qe,Oe,Le="",Ve,pe=!1,Ie=null,ye=!1,Me=()=>e.client.pendingCommand?.operation==="close",se=null,K=null,ln=We({document:s,run:async()=>{(!i?.observing||e.client.pendingCommand)&&await Ze()},delay:()=>{if(!(b||!l||!["running","waiting"].includes(l.status)&&!e.client.pendingCommand)&&!(i?.observing&&!e.client.pendingCommand))return l.pendingRequest||e.client.pendingCommand?1500:sn},hiddenDelay:()=>!b&&e.client.pendingCommand?15e3:void 0}),X=null;function Xe(){return K&&e.client.hasDurableJournal===!0&&X?.acknowledged===!0&&X.operationId===K.operationId&&e.client.view?.id===X.runId&&e.client.view?.status==="closed"&&e.client.view.revision===X.revision+1&&!(e.client.pendingCommands?.length??(e.client.pendingCommand?1:0))&&!e.client.pendingPurchase?K:null}function un(t){let r=t.run.paywall;if(X&&t.settlement?.requestId===X.requestId&&t.settlement.state==="settled"&&t.settlement.operationId===null&&t.run.id===X.runId&&t.run.status==="closed"&&!t.run.pendingRequest&&t.run.revision===X.revision+1&&t.run.nodeId===X.nodeId&&t.run.visit===X.visit&&r?.receiptId===X.receiptId&&r.selectionGeneration===X.selectionGeneration&&(r.quote?.operationId??null)===X.operationId&&(r.operation?.operationId??r.quote?.operationId??null)===X.operationId){let f=X.operationId===null&&r.selectionGeneration===0&&!r.quote&&!r.operation&&!r.purchaseRequestId,ne=ze({quote:r.quote,operation:r.operation,requestId:r.purchaseRequestId,pending:!1,destroyed:!1,canReselect:r.canReselect});(f||r.canReselect===!0&&ne.type==="native")&&(X.acknowledged=!0)}}let ke=null,He=new Set,fe={},Fe=!1,ue=(t,r=null)=>{b||(ke=r,Fe=!1,O.textContent=Fn(t,z),O.hidden=!1,M.hidden=e.client.pendingCommand===null,T(),le(e.onError,t))};function be(){let t=e.client.view;if(!t)throw new P("INVALID_REQUEST","No current Run is available");return{requestId:crypto.randomUUID(),nodeId:t.nodeId,visit:t.visit,revision:t.revision}}let U=Vn({client:e.client,doc:s,holder:q,reviewHolder:V,mountScreenPreview:p,loadingOptions:e,get chrome(){return _},get stopped(){return b},get answers(){return fe},suspend(t){i?.setSuspended(t)},resetScreen(){o="",c="",I=""},enqueue:me,fail:ue}),$e=_n({client:e.client,expected:be,fail:ue,get stopped(){return b},get reviewing(){return U.active},get key(){return o},get busy(){return $},get staleRead(){return Ke}}),Ue=Ln({client:e.client,expected:be,perform:Se,onIntent:e.onCustomerDataIntent,get stopped(){return b},get busy(){return $},get document(){return E?.document},get answers(){return fe}}),xe=t=>`${t.id}:${t.nodeId}:${t.visit}`,De=t=>t&&(t.screen||t.paywall)?xe(t):"";function Ce(){let t=e.client.view;F.disabled=!U.active&&($>0||!!e.client.pendingCommand||!t?.canBack||t.stopped||!["running","waiting"].includes(t.status)||!De(t)||c!==De(t)),F.hidden=!U.active&&!t?.canBack,on(F);let r=!!i&&!U.active;R.hidden=r&&!W?.active,k.hidden=!e.client.review||r&&!t?.canBack,r&&(d.textContent=""),T()}async function dn(t){if(!t)return;let r=e.client.view;await t;let f=e.client.view;if(!r||!f||f.id!==r.id||f.nodeId!==r.nodeId||f.visit!==r.visit||f.stopped||!["running","waiting"].includes(f.status))throw new P("PRECONDITION_FAILED","The screen changed while its display was acknowledged")}async function Se(t,r=!1){if(!(($||ye||se||K)&&!r||b||U.active&&!r)){$++,u.setAttribute("aria-busy","true"),O.hidden=!0,ke=null,Fe=!1,Ce();try{if(r||await dn($e.inFlight),b)return;let f=await t();b||await me(e.client.view??f.run)}catch(f){ue(f,e.client.pendingCommand?.requestId??null)}finally{$=Math.max(0,$-1),u.setAttribute("aria-busy",String($>0)),b||(M.hidden=e.client.pendingCommand===null,Ce())}}}function Ne(){ln.schedule()}async function Ze(){if(!(b||Re||$)){if(U.active){await U.open(U.receipt);return}Re=!0;try{let t=e.client.pendingCommand;t&&e.client.settle&&await e.client.settle(t.requestId);let r=e.client.view,f=Ue.queries,ne=await e.client.get(r?.screen&&Object.keys(f).length?{nodeId:r.nodeId,visit:r.visit,revision:r.revision,components:f}:void 0);Fe&&!b&&(Fe=!1,O.hidden=!0,T()),!b&&f===Ue.queries&&await me(e.client.view??ne.run)}catch(t){ue(t),Fe=!b}finally{Re=!1}}}function Ge(t,r){if(W?.active){let ne=W;return ne.setDismissHandler(()=>cn(ne)),ne}let f=je(n,e,"funnel",()=>cn(f));return W=f,f.start(t,r),f}function cn(t){b||pe||(pe=!0,t.finish("dismissed"),ve(),u.hidden=!0,e.client.view?Pe().finally(ae):ae())}function en(){clearTimeout(Ve?.timeout),Ve=void 0}function ve(){en(),qe?.abort(),qe=void 0,E?.destroy(),E=null,i?.destroy(),i=null,Oe?.(),Oe=void 0,C.open&&C.close(),q.replaceChildren(),q.style.cssText="",Y=void 0,o="",c="",y=!1,I="",G=""}function pn(){let t=s.defaultView;L?.responsive&&t&&E?.resizeViewport?.(t.innerHeight,t.innerWidth)}function nn(){L?.destroy(),L=void 0,de=""}function tn(t){let r=t.screen?.presentation;if(!r||r.type==="inline"){C.open&&C.close(),nn(),R.parentElement!==A&&A.append(R),u.parentElement!==n&&n.append(u),re(t),T();return}u.parentElement!==C&&(C.append(R,u),n.append(C)),re(t);let f=t.screen.content.document,ne=JSON.stringify([r,J]);if(ne!==de){nn(),de=ne;let ge={sm:420,md:640,lg:900},we="size"in r&&!r.backdrop?",0 0 0 100vmax #16142566":"";C.style.cssText=`box-sizing:border-box;padding:0;border:0;overflow:auto;background:${h.background};color:${h.text};`+(r.type==="fullscreen"?"width:100vw;height:100dvh;max-width:100vw;max-height:100dvh;margin:0;border-radius:0":`width:${ge[r.size]}px;max-width:calc(100vw - 32px);max-height:calc(100dvh - 32px);box-shadow:0 24px 80px #0003${we};`+(r.type==="sheet"?"margin:auto auto 0;border-radius:14px 14px 0 0":"border-radius:14px")),L=Cn(C,{presentation:r,theme:f.theme,pages:f.pages},pn),L.latch()}T(),C.setAttribute("aria-label",(H?.screen===t.screen?.content.document.name?H?.label:void 0)??E?.document?.name??t.screen?.content.document.name??"Funnel")}async function Hn(t){if(b||pe||ye&&(Me()||["running","waiting"].includes(t.status))||(l=t,ke&&e.client.pendingCommand?.requestId!==ke&&(O.hidden=!0,ke=null),z=t.locale.startsWith("zh"),k.textContent=z?"\u56DE\u770B":"History",F.textContent=U.active?z?"\u8FD4\u56DE\u5F53\u524D":"Return to current":z?"\u8FD4\u56DE":"Back",ce(),M.textContent=z?"\u91CD\u8BD5":"Retry",M.hidden=e.client.pendingCommand===null,d.textContent=t.pendingRequest?z?"\u6B63\u5728\u5904\u7406":"Processing":t.instruction?.type==="wait"?z?"\u7B49\u5F85\u4E2D":"Waiting":"",Ce(),Ee!==`${t.revision}:${t.visit}:${t.status}:${t.stopped}`&&(Ee=`${t.revision}:${t.visit}:${t.status}:${t.stopped}`,le(e.onState,structuredClone(t))),b||pe))return;if((!t.pendingRequest||ye&&t.status==="closed")&&["closed","ineligible","failed"].includes(t.status)){ae();return}if(t.stopped||e.client.configurationReady===!1){U.stop(),ve(),W?.finish("skipped"),u.hidden=!0,Ne();return}if(u.hidden=!1,U.active){Ne();return}let r=De(t),f=e.client.view;if(f&&f.revision>t.revision&&De(f)!==r)return;let ne=!t.instruction&&!t.pendingRequest&&t.nodeType==="screen"&&["running","waiting"].includes(t.status);r!==o&&(o&&W?.finish("dismissed"),ve(),o=r,fe={...t.answers},Ue.reset());let ge=xe(t);if(Le===ge){u.hidden=!0;return}if(ne&&!r){u.hidden=!0;let Q=Ge(!0,t.locale);!b&&!pe&&Ve?.key!==ge&&(en(),Ve={key:ge,timeout:setTimeout(()=>{let m=e.client.view;if(!Q.active||!m||xe(m)!==ge)return;Le=ge;let j=new Error("Funnel screen preparation timed out");Q.finish("error",j),ve(),ue(j)},Ae)}),Ne();return}en();let Z=Q=>{let m=e.client.view;return!b&&!pe&&!Ie&&!Q.aborted&&e.client.configurationReady!==!1&&!!m&&!m.stopped&&!["closed","ineligible","failed"].includes(m.status)&&De(m)===r},we=(Q,m)=>{Z(m)&&(Le=r,W?.finish("error",Q),ve(),u.hidden=!0,ue(Q))};if(r||(tn(t),t.instruction?.type!=="event"&&t.instruction?.type!=="open_url"&&W?.finish("skipped")),t.screen){let Q=t.screen.content;if(!E){let te=t.screen.presentation.type!=="inline",oe=Ge(te,t.locale);if(b||pe)return;let ie=(qe=new AbortController).signal;tn(t),Oe=te?qn(C):Be(u,n),E=p(q,{mode:"live",rendererUrl:e.client.webViewUrl,title:Q.document.name,...te?{hostPresentation:()=>L?.type??t.screen.presentation.type}:{},onResize:ee=>{Y=ee,L?.responsive&&L.setContentHeight(ee+A.getBoundingClientRect().height)},onAction(ee,he={},Gn={}){if(U.active||!Z(ie)||c!==r)return;fe={...fe,...Gn};let Jn=Object.fromEntries((t.screen?.inputs??[]).filter(({variable:Je})=>Object.hasOwn(fe,Je)).map(({variable:Je})=>[Je,fe[Je]]));Se(()=>e.client.submit({operation:"submit",...be(),input:{type:"screen",output:ee,answers:Jn,selection:he}}))},onAnswers:ee=>{U.active||!Z(ie)||c!==r||(fe={...fe,...ee})},onCustomerDataIntent:ee=>{U.active||!Z(ie)||c!==r||Ue.intent(ee).catch(ue)},onEscape:()=>{!Z(ie)||c!==r||U.active||se||K||Pe()},onError:ee=>{let he=new Error(ee);c===r?ue(he):we(he,ie)},onRendered:ee=>{if(!(!Z(ie)||c===r))try{oe.present(he=>{Oe?.(),Oe=void 0,ee&&(H={screen:Q.document.name,label:ee},C.setAttribute("aria-label",ee)),te&&(C.showModal(),L?.responsive&&C.focus({preventScroll:!0}),!he&&e.loading!=="host"&&Pn(C,L?.type??t.screen.presentation.type,L?.responsive)),c=r,y=te,Ce()}),Z(ie)&&$e.report(r)}catch(he){we(he,ie)}}}),pn()}let m={capabilities:t.screen.capabilities,customerData:t.screen.customerData,parameters:t.parameters,serverInput:{bindings:t.screen.inputs,answers:fe,values:t.screen.values}},j=JSON.stringify([Q,t.locale,m.parameters,t.screen.inputs,t.screen.values]);if(j!==I)E.update(Q.document,t.locale,m),I=j,B=JSON.stringify(m.capabilities),G=JSON.stringify(m.customerData);else{let te=JSON.stringify(m.capabilities);te!==B&&(E.updateCapabilities(m.capabilities),B=te),JSON.stringify(m.customerData)!==G&&(E.updateCustomerData(m.customerData),G=JSON.stringify(m.customerData))}let x=E;if(x)try{await(W?.wait(x.ready)??x.ready)}catch(te){qe&&we(te,qe.signal)}}else if(t.paywall&&!i){let Q=Ge(!0,t.locale);if(b||pe)return;let m=(qe=new AbortController).signal;tn(t);let j=await D(q,{loading:"host",signal:m,canInteract:()=>Z(m)&&!U.active&&!se&&!K,beforeAction:async()=>{$++;try{await dn($e.settled()),O.hidden=!0,ke=null,Fe=!1,T()}finally{$=Math.max(0,$-1)}},start:()=>An(e.client),onObservationChange:Ne,onPurchase:e.onPurchase,onCheckoutUrl:e.onCheckoutUrl,checkoutNavigation:e.checkoutNavigation,confirmOnHostedCheckout:e.confirmOnHostedCheckout,resolveOfferId:e.resolveOfferId,onEvent:e.onEvent,onOpenUrl:x=>e.onOpenUrl?e.onOpenUrl({receiptId:t.paywall.receiptId,url:x,openIn:"same_window"}):s.defaultView?.location.assign(x),onAction:async x=>{if(U.active)return;let te=await e.client.submit({operation:"submit",requestId:crypto.randomUUID(),nodeId:t.nodeId,visit:t.visit,revision:e.client.view?.revision??t.revision,input:{type:"screen",output:x,answers:{}}});await me(e.client.view??te.run)},onError:x=>{c===r?ue(x):we(x,m)}},{quoteError:x=>le(e.onError,x),present(x){Z(m)&&(Q.present(()=>{x(),c=r,y=!!q.querySelector("dialog[open]"),Ce()}),Z(m)&&$e.report(r))},async dismiss(){b||m.aborted||U.active||se||K||!ye&&!Z(m)||(ye=!0,await Pe())}}).catch(x=>(we(x,m),null));!Z(m)&&!(ye&&!b&&!m.aborted)?j?.host?.destroy():j&&(i=j.host,i?.setSuspended(U.active))}if(b||pe)return;Ce();let N=t.instruction;if(N&&(N.type==="open_url"||N.type==="event")&&!He.has(N.receiptId)){let Q=s.createElement("button");Q.type="button",Q.style.cssText=_.primary,_e(Q,()=>_.focus),q.style.cssText=_.stage,Q.textContent=N.type==="open_url"?`${z?"\u524D\u5F80":"Continue to"} ${new URL(N.url).host}`:z?"\u7EE7\u7EED":"Continue",Q.onclick=()=>{let m=be(),j=N.type==="open_url"&&!e.onOpenUrl&&N.openIn==="new_window"?$n(N.url):null;Se(async()=>{let x="success";if(N.type==="open_url")if(e.onOpenUrl)try{x=await e.onOpenUrl({receiptId:N.receiptId,url:N.url,openIn:N.openIn})===!1?"failed":"opened"}catch(oe){le(e.onError,oe),x="failed"}else x=N.openIn==="new_window"&&!j?"failed":"opened";if(N.type==="event"){if(!e.onEvent)throw new P("EVENT_HANDLER_REQUIRED","Provide the event handler");await e.onEvent(N.event)}if(b||e.client.view?.nodeId!==m.nodeId||e.client.view.visit!==m.visit)throw new P("PRECONDITION_FAILED","The client action visit changed");let te=await e.client.submit({operation:"submit",...m,input:{type:"client_action",receiptId:N.receiptId,outcome:x}});return He.add(N.receiptId),N.type==="open_url"&&!e.onOpenUrl&&N.openIn==="same_window"&&s.defaultView?.location.assign(N.url),te})},W?.active?W.present(()=>q.replaceChildren(Q)):q.replaceChildren(Q)}!t.pendingRequest&&t.status==="completed"&&!He.has(`complete:${t.id}`)&&(He.add(`complete:${t.id}`),le(e.onComplete,structuredClone(t))),Ne()}function $n(t){let r=s.defaultView?.open(t,"_blank")??null;return r&&(r.opener=null),r}function me(t){return Ce(),Ye=Ye.catch(()=>{}).then(async()=>{try{await Hn(t)}catch(r){throw W?.active&&(Le=xe(t),W.finish("error",r),ve(),u.hidden=!0),r}}),Ye}let Un=e.client.subscribe(t=>{if(!an){if(t.stopped&&y&&!ye){l=t,ae();return}!ye&&(t.stopped||e.client.configurationReady===!1||o&&c!==o&&(De(t)!==o||["closed","ineligible","failed"].includes(t.status)))&&(ve(),W?.finish("dismissed"),u.hidden=!0),me(t).catch(ue)}}),xn=e.client.subscribeError?.(ue);function Pe(t){if(Ie)return Ie;if(b||!t&&(se||K))return Promise.resolve();let r=!t&&Me();return!r&&e.client.view&&!["running","waiting"].includes(e.client.view.status)?(l=e.client.view,ae(),Promise.resolve()):(Ie=Se(async()=>{let f=r?await e.client.retry():await e.client.submit({operation:"close",...t??be()});return t&&un(f),f},!0).then(()=>{let f=e.client.view;f?.status==="closed"&&!Me()&&(l=f,ae())}).finally(()=>{Ie=null}),Ie)}function ae(){S?.destroy(),!b&&(b=!0,e.signal?.removeEventListener("abort",ae),a?.removeEventListener("abort",ae),W?.finish("dismissed"),ln.destroy(),Un(),xn?.(),ve(),nn(),U.stop(),C.remove(),u.remove(),v(),le(e.onDismiss,l?structuredClone(l):null))}F.onclick=()=>{if(!F.disabled){if(U.active){U.exit();return}Se(()=>e.client.submit({operation:"back",...be()}))}},k.onclick=()=>{U.open()},R.onclick=()=>{W?.active?W.dismiss():se||Pe()},M.onclick=()=>{Me()?Pe():Se(()=>e.client.retry())},C.addEventListener("cancel",t=>{t.preventDefault(),W?.active?W.dismiss():se||Pe()}),e.signal?.addEventListener("abort",ae,{once:!0}),a?.addEventListener("abort",ae,{once:!0});try{let t=e.client.view;if(t)((e.client.viewAgeMs??sn)>=sn||t.instruction?.type==="evaluate_segment")&&(Ke=Ze().finally(()=>{Ke=null})),await me(t);else{u.hidden=!0;let r=Ge(e.client.view?.screen?.presentation.type!=="inline",e.client.view?.locale);if(b||pe)throw new DOMException("Presentation cancelled","AbortError");let f=await r.wait(e.client.get(),Ae);an=!1,await me(e.client.view??f.run)}}catch(t){throw W?.finish("error",t),ae(),t}return{destroy:ae,refresh:Ze,get recovery(){let t=Xe();if(t)return t;if(!b&&!$&&!ye&&!se&&i){let r=i.recovery;if(r.type!=="native")return r}return{type:"recover",operationId:e.client.pendingPurchase?.operationId??e.client.view?.paywall?.quote?.operationId??K?.operationId??null,requestId:e.client.pendingCommand?.requestId??null}},prepareFallback(){if(se)return se;let t=Xe();if(t)return Promise.resolve(t);let r=e.client.pendingPurchase?.operationId??e.client.view?.paywall?.quote?.operationId??K?.operationId??null,f=()=>({type:"recover",operationId:r,requestId:e.client.pendingCommand?.requestId??null});if(e.client.hasDurableJournal!==!0){let N=i?.recovery;return Promise.resolve(N&&N.type!=="native"&&N.type!=="cancel"?N:f())}let ne=(e.client.pendingCommands??(e.client.pendingCommand?[e.client.pendingCommand]:[])).some(N=>N.operation==="close");if(b&&!(ne||K&&e.client.view?.status==="closed")||$||Re||Ie||U.active||!i&&!K&&!ne)return Promise.resolve(f());let ge=i,Z=(async()=>{try{if(!K&&ne){let m=await e.client.retry();return await me(e.client.view??m.run),f()}if(!K){let m=await ge.prepareFallback();if(m.type!=="native")return m;if(e.client.hasDurableJournal!==!0)return f();K=m}let N=e.client.pendingCommands??(e.client.pendingCommand?[e.client.pendingCommand]:[]);if(N.length){let m=N.find(x=>x.operation==="close");if(!m||!X||m.requestId!==X.requestId)return f();let j=await e.client.retry();un(j),await me(e.client.view??j.run)}else{let m=e.client.view,j=m?.paywall;if(!m||!j||j.selectionGeneration===void 0||(j.quote?.operationId??null)!==K.operationId||K.operationId!==null&&j.canReselect!==!0)return f();let x=j.selectionGeneration,te=await e.client.get();await me(e.client.view??te.run);let oe=e.client.view,ie=oe?.paywall;if(!oe||!ie||!["running","waiting"].includes(oe.status)||oe.stopped||oe.id!==m.id||oe.nodeId!==m.nodeId||oe.visit!==m.visit||ie.receiptId!==j.receiptId||ie.selectionGeneration!==x||(ie.quote?.operationId??null)!==K.operationId||K.operationId!==null&&ie.canReselect!==!0||e.client.pendingPurchase||(e.client.pendingCommands?.length??(e.client.pendingCommand?1:0)))return f();let ee=be();X={runId:oe.id,operationId:K.operationId,revision:ee.revision,requestId:ee.requestId,nodeId:oe.nodeId,visit:oe.visit,receiptId:ie.receiptId,selectionGeneration:x,acknowledged:!1},await Pe(ee)}let Q=Xe();return Q?(ae(),Q):f()}catch(N){return ue(N),f()}})();se=Z;let we=()=>{se===Z&&(se=null)};return Z.then(we,we),Z},review:U.open,exitReview:U.exit,get unappliedDrafts(){return U.drafts}}}function Vt(n,g,w){return zn(n,g,w)}export{Bn as a,Mn as b,zn as c,Vt as d};
@@ -1 +0,0 @@
1
- import{b as I}from"./chunk-NVIHK5GE.js";import{d as p}from"./chunk-U6GWWCUS.js";import"./chunk-HQPP76BS.js";import{k as A,l as F}from"./chunk-BRAVNBCC.js";import"./chunk-GGRDM54V.js";import"./chunk-UWLEGMWX.js";import"./chunk-U6E6CM7Z.js";import"./chunk-JN6JEKWN.js";import"./chunk-THMGTRXP.js";import"./chunk-NAZU3EEJ.js";import"./chunk-SCC3O2RD.js";import"./chunk-R23IGK5U.js";import"./chunk-ZGCKQWQ5.js";import"./chunk-EHDHWYVJ.js";import"./chunk-BXPXJARS.js";import"./chunk-U2R7MG3J.js";import"./chunk-VYFSRHXM.js";import"./chunk-N7YXDSQL.js";import"./chunk-MIBRUDIS.js";import{a as c}from"./chunk-X4W22IH6.js";import"./chunk-R4FDIYMN.js";import"./chunk-SLUA7ABW.js";import"./chunk-KIMX3OIV.js";import"./chunk-3VUPVXAV.js";import"./chunk-UHQGO6OR.js";import"./chunk-VF6QMMEA.js";import{a as o}from"./chunk-DSPLGTQI.js";import"./chunk-7QL4GF4C.js";import"./chunk-BID4UGWB.js";import"./chunk-WOT6VMZA.js";var d=new WeakMap;function k(m,e){let g=d.get(e.client);if(g)return g;let h=Promise.resolve().then(async()=>{let n=!1,a,w,P=!1,y=()=>{},t=e.signal?AbortSignal.any([e.signal,e.client.identitySignal]):e.client.identitySignal,u=()=>{d.get(e.client)===h&&d.delete(e.client),t.removeEventListener("abort",f),y()},i=F(m,e,"funnel",f);function f(){n||(n=!0,i.finish("dismissed"),a?a.destroy():(u(),o(e.onDismiss,null)))}t.addEventListener("abort",f,{once:!0});try{let b=function(){!n&&!t.aborted&&!P&&w&&e.client.recovery.status==="complete"&&(P=!0,o(e.onComplete,structuredClone(w)))};var D=b;t.throwIfAborted();let l=e.client.controller?.view?.paywall?.resolution,E=l&&"document"in l?l.document:e.loadingDocument;if(i.start(!0,e.start?.locale??e.client.attempt?.locale??E?.screen.strings.defaultLocale,E??null),n)return null;t.throwIfAborted();let v=await i.wait(e.start?e.client.start(e.start):e.client.refresh(),A);t.throwIfAborted();let O=e.client.controller;return v.mode!=="run"||v.status==="blocked"||!O?(i.finish("skipped"),u(),null):(t.removeEventListener("abort",f),y=e.client.subscribe(b),a=await p(m,{...e,client:O,signal:t,checkoutNavigation:"after_confirmation",onCheckoutUrl(r){if(t.throwIfAborted(),n)throw new DOMException("Presentation dismissed","AbortError");if(I(e.client.recovery)!==r)throw new c("PURCHASE_PENDING","Checkout differs from the original recovery proof");return e.onCheckoutUrl?e.onCheckoutUrl(r):m.ownerDocument.defaultView?.location.assign(r)},async resolveOfferId(r){if(t.throwIfAborted(),n)throw new DOMException("Presentation dismissed","AbortError");let s=e.client.attempt;if(!s)throw new c("PURCHASE_PENDING","Read the original Start before selecting an offer");let C=await e.resolveOfferId?.(r,s);if(t.throwIfAborted(),n)throw new DOMException("Presentation dismissed","AbortError");if(e.client.attempt?.requestId!==s.requestId)throw new c("PURCHASE_STORAGE_CONFLICT","The original purchase changed while selecting an offer");return C},onComplete(r){w=r,b()},onError(r){o(e.onError,r),r instanceof c&&r.status===401&&!t.aborted&&e.client.refresh().catch(s=>o(e.onError,s))},onDismiss(r){n=!0,u(),o(e.onDismiss,r)}},i),n||t.aborted?(a.destroy(),null):a)}catch(l){if(n)return null;throw i.finish("error",l),u(),o(e.onError,l),l}});return d.set(e.client,h),h}export{k as showFunnelPurchase};
@@ -1 +0,0 @@
1
- import{b as at,c as De,e as ot,g as st,h as lt}from"./chunk-HQPP76BS.js";import{d as Xe,e as Ze,f as et,h as tt,i as nt,j as rt,k as pe,l as it}from"./chunk-BRAVNBCC.js";import{a as Ge,c as Se,d as Ye,g as Je,j as Ke}from"./chunk-EHDHWYVJ.js";import{b as ee}from"./chunk-BXPXJARS.js";import"./chunk-U2R7MG3J.js";import"./chunk-VYFSRHXM.js";import{c as Z,o as ne,oa as re,qa as Oe}from"./chunk-N7YXDSQL.js";import{c as Te}from"./chunk-MIBRUDIS.js";import{a as k}from"./chunk-X4W22IH6.js";import"./chunk-R4FDIYMN.js";import"./chunk-UHQGO6OR.js";import"./chunk-VF6QMMEA.js";import{a as z}from"./chunk-DSPLGTQI.js";import"./chunk-7QL4GF4C.js";import"./chunk-BID4UGWB.js";import"./chunk-WOT6VMZA.js";async function ct(T,i,N){if(i.status!=="complete")throw new k("INVALID_RESPONSE","A verified completed purchase is required");let O=T?ne.parse(T):null;if(await N.onComplete?.(i),!O||!N.check)return;let S=ne.parse(await N.check());if(S.internal_feature_id!==O.internal_feature_id||S.quantity!==O.quantity||O.observation!==void 0&&(S.observation===void 0||S.observation.requirementDigest!==O.observation.requirementDigest||S.observation.authority!==O.observation.authority||Te(S.observation.subject)!==Te(O.observation.subject)))throw new k("INVALID_RESPONSE","The access requirement changed");S.allowed&&await N.onAccessGranted?.(S)}function Ne(T){return Object.entries(T.document.buttons).filter(([,i])=>i.type==="checkout"&&i.product.type==="fixed"&&!ee(i.product,{},T.capabilities)).map(([i])=>i)}async function zt(T,i,N){let O=tt(T.ownerDocument),S=()=>{C.finish("dismissed"),O()},j=()=>S(),C=it(T,i,"paywall",()=>{S(),z(i.onDismiss)});i.signal?.throwIfAborted(),i.signal?.addEventListener("abort",j,{once:!0});let G=null,_,m,Le;try{let e=i.loadingDocument;if(C.start(!0,e?.screen.strings.defaultLocale,e??null),C.cancelled)throw new DOMException("Presentation cancelled","AbortError");if(G=i.check?ne.parse(await C.wait(i.check(),pe)):null,G?.allowed)return C.finish("skipped"),i.signal?.removeEventListener("abort",j),O(),await i.onAccessGranted?.(G),{check:G,host:null};let[t,n]=await Promise.allSettled([C.wait(import("./screen-renderer-3CBREMIS.js")),C.wait(i.start().then(r=>(C.cancelled&&r.destroy(),r)),pe)]);if(t.status==="rejected")throw n.status==="fulfilled"&&n.value.destroy(),t.reason;if(n.status==="rejected")throw n.reason;Le=t.value,_=n.value,i.signal?.throwIfAborted(),_.signal?.throwIfAborted(),_.signal?.addEventListener("abort",j,{once:!0});let s=_.view??await C.wait(_.refresh(),pe);if(!s)throw new k("INVALID_RESPONSE","Paywall presentation is missing");_.signal?.throwIfAborted(),m=s}catch(e){throw C.finish("error",e),i.signal?.removeEventListener("abort",j),_?.signal?.removeEventListener("abort",j),_?.destroy(),O(),e}let a=_,{mountScreenPreview:ut}=Le,d=T.ownerDocument,fe=new AbortController,I=d.createElement("section"),Y=d.createElement("div"),U=d.createElement("div"),u=d.createElement("p"),w=d.createElement("button"),h=d.createElement("button"),b=d.createElement("dialog"),o=m.document.screen.strings.defaultLocale.startsWith("zh"),dt=o?"\u6B63\u5728\u5904\u7406\u2026":"Processing\u2026",pt=o?"\u6B63\u5728\u51C6\u5907\u62A5\u4EF7\u2026":"Preparing your price\u2026",P=at(m.document.screen.theme);I.dataset.indianaPaywall="",I.setAttribute("aria-label",m.document.name),I.style.cssText=P.root,U.style.cssText=P.controls,u.style.cssText=P.message,u.setAttribute("role","status"),h.style.cssText=P.link,h.textContent=o?"\u5173\u95ED":"Close",w.style.cssText=P.secondary,w.textContent=o?"\u91CD\u8BD5":"Retry",w.hidden=!0,U.append(u,w,h),I.append(Y,U);let Me=()=>{let e=H??U,t=[...e.children].every(s=>s===u?!u.textContent:s.hidden),n=[...e.children].some(s=>s===h?!1:s===u?!!u.textContent:!s.hidden);e.style.cssText=t?P.controls.replace(/padding:[^;]+/,"padding:0"):n?`${P.controls};${P.pinned}`:P.controls,we()},_e=typeof MutationObserver>"u"?void 0:new MutationObserver(Me);_e?.observe(I,{attributes:!0,attributeFilter:["hidden"],characterData:!0,childList:!0,subtree:!0});let ie=m.document.presentation,ft=Object.entries(m.document.buttons).filter(([,e])=>e.type==="close").map(([e])=>e),B,Ue,me=!1,$e=JSON.stringify(m.capabilities),qe=e=>J?Object.entries(e.document.buttons).filter(([,t])=>t.type==="checkout").map(([t])=>t):Ne(e);function he(e){if(p)return;m=e;let t=JSON.stringify(e.capabilities);t!==$e&&(B?.updateCapabilities(e.capabilities,qe(e)),$e=t),ht(e)}let g,ye=0;function we(){let e=d.defaultView;if(!g?.responsive||!e)return;let t=H??U,n=e.innerHeight-(g.type==="modal"?32:0);t.style.maxHeight=`${Math.max(1,n)}px`,t.style.overflowY="auto",t.style.flexShrink="0",ye=Math.max(1,n-t.getBoundingClientRect().height),B?.resizeViewport?.(ye,e.innerWidth)}let p=!1,J=!1,E=null,ae=!1,Ve=!1,F=!1,be,ge=!1,$,H;function mt(){return J||p||$||ge?{type:"recover",operationId:a.operation?.operationId??a.quote?.operationId??null,requestId:null}:Se(a)}let R=()=>!p&&!ae&&!$&&i.canInteract?.()!==!1,oe=!1,c=null,q=null;function ht(e){J||E||a.quote||a.operation||(u.textContent=Object.values(e.capabilities.plans).some(t=>t.available)?"":o?"\u5F53\u524D\u8D26\u53F7\u6682\u65E0\u53EF\u8D2D\u4E70\u7684\u65B9\u6848\u3002":"No plans are currently available for this account.")}let ve=new Map,Ce=!1;function yt(e,t,n,s){let r=e.lines.length===1?e.lines[0]:void 0,y=ee(n,s,t.capabilities);if(!r||!y||r.productVersionId!==y)return!1;let x;try{x=Oe(t.document.screen,y,s,t.capabilities)}catch{return!1}let A=Object.fromEntries((r.prepaid??[]).map(W=>[W.internal_feature_id,W.quantity]));return[...new Set([...Object.keys(x),...Object.keys(A)])].every(W=>(x[W]??0)===(A[W]??0))}let se=e=>Ge({quote:a.quote,operation:e,requestId:null,pending:!1,destroyed:p,canReselect:a.canReselect});async function Pe(e){let t=e.merchantExecution;if(!(!R()||!e.checkoutUrl||i.checkoutNavigation==="after_confirmation"&&se(e).type!=="checkout"||t?.type==="purchase"&&!["not_started","pending"].includes(t.paymentStatus)||ve.get(e.operationId)===e.checkoutUrl)){ve.set(e.operationId,e.checkoutUrl);try{i.onCheckoutUrl?await i.onCheckoutUrl(e.checkoutUrl):d.defaultView?.location.assign(e.checkoutUrl)}catch(n){throw ve.delete(e.operationId),n}}}let Q=(e,t=!1)=>{if(t){let n=e instanceof k?e.code:void 0;n==="CAPABILITY_UNAVAILABLE"||n==="NOT_CONFIGURED"?(c=null,u.textContent=o?"\u6682\u65F6\u65E0\u6CD5\u4E3A\u6B64\u5957\u9910\u62A5\u4EF7\uFF0C\u4ED8\u6B3E\u5C1A\u672A\u5F00\u59CB\u3002":"Pricing for this plan is unavailable. Payment hasn\u2019t started."):a.canReselect===!0&&!E?u.textContent=o?"\u672A\u80FD\u53D6\u5F97\u62A5\u4EF7\uFF0C\u4ED8\u6B3E\u5C1A\u672A\u5F00\u59CB\u3002\u8BF7\u91CD\u65B0\u9009\u62E9\u5957\u9910\u3002":"We couldn\u2019t prepare your price. Payment hasn\u2019t started. Choose a plan again.":n==="COMMAND_PENDING"?u.textContent=o?"\u4ECD\u5728\u51C6\u5907\u62A5\u4EF7\uFF0C\u8BF7\u91CD\u8BD5\u4EE5\u67E5\u770B\u7ED3\u679C\u3002":"Your price is still being prepared. Retry to check the result.":u.textContent=o?"\u672A\u80FD\u53D6\u5F97\u62A5\u4EF7\uFF0C\u4ED8\u6B3E\u5C1A\u672A\u5F00\u59CB\u3002\u8BF7\u91CD\u8BD5\u3002":"We couldn\u2019t prepare your price. Payment hasn\u2019t started. Try again."}else u.textContent=e instanceof k&&(e.code==="NETWORK_ERROR"||e.code==="TIMEOUT")?ot(e,o):e instanceof k?e.message:o?"\u64CD\u4F5C\u672A\u5B8C\u6210\uFF0C\u8BF7\u91CD\u8BD5\u3002":"This action couldn\u2019t be completed. Try again.";w.hidden=c===null,t&&!g?.responsive&&u.scrollIntoView?.({block:"nearest"}),z(t&&N?.quoteError?N.quoteError:i.onError,e)},le=new WeakMap;function ce(e){J=e,B?.updateCapabilities?.(m.capabilities,qe(m));for(let t of q?.querySelectorAll("button")??[])e?(le.set(t,t.disabled),t.disabled=!0):le.has(t)&&(t.disabled=le.get(t),le.delete(t)),De(t)}function Ee(){u.textContent=o?"\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 wt(e){if(i.beforeAction)try{await i.beforeAction()}catch(t){throw c=e,t}}async function V(e){if(J||p)return;if(!R()){Ee();return}let t=e===ue,n=t?pt:dt;ce(!0),w.hidden=!0,u.textContent=n;try{if(await wt(e),p)return;if(!R()){c=e,w.hidden=!1,Ee();return}await e()}catch(s){p||Q(s,t)}finally{ce(!1),u.textContent===n&&(u.textContent="")}}async function bt(e){await ct(G,e,i)}function He(e){return Se(a).type==="recording"||se(e).type==="recording"}function je(e){let t=e.merchantTerms,n=t?.subscriptionTerms?.items??[],s=t?t.totalMinor:e.charge?.totalMinor??e.catalogAmountMinor-(e.discount?.amountMinor??0),r=t?n.length===1&&n[0]?.amountMinor===s&&n[0]:e.lines.length===1&&e.lines[0]?.catalogAmountMinor===s&&e.lines[0],y=s===null?Z(t.subtotalMinor-t.discountMinor,e.currency)+(o?" + \u5F85\u786E\u8BA4\u7A0E\u8D39":" + tax confirmed at checkout"):Z(s,e.currency)+(r?re(r.interval,o?"zh-CN":"en",r.intervalCount??1):""),x=e.lines.map(A=>A.productName).join(", ");return{label:x?`${x} \xB7 ${y}`:y,recurring:r}}async function D(e,t=i.checkoutNavigation!=="after_confirmation"){if(p)return;if(!R()){c=async()=>D(await a.read()),w.hidden=!1;return}if(u.textContent=lt(e.status,o),He(e)){let r=e.merchantExecution?.type==="purchase"&&e.merchantExecution.recordingStatus==="failed";u.textContent=r?o?"\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.":o?"\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.",w.textContent=o?"\u67E5\u8BE2\u8BB0\u5F55":"Check recording",c=async()=>D(await a.read()),w.hidden=!1;return}if(e.problem){let r=e.problem;c=te,w.textContent=o?"\u68C0\u67E5\u5E76\u6062\u590D\u539F\u64CD\u4F5C":"Check and recover original purchase",Q(new k(r.code,r.reason==="RESULT_UNKNOWN"?o?"\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.":r.phase==="fulfillment"?o?"\u4ED8\u6B3E\u5DF2\u8BB0\u5F55\uFF0C\u5546\u6237\u6743\u76CA\u5904\u7406\u9700\u8981\u6838\u5BF9\u3002":"Payment was recorded. Access fulfillment needs attention.":r.code==="CAPABILITY_UNAVAILABLE"?o?"\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.":r.code==="NOT_CONFIGURED"?o?"\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.":o?"\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,r));return}if(e.merchantExecution?.type==="purchase"&&e.merchantExecution.paymentStatus==="succeeded"&&!["applied","not_applicable"].includes(e.merchantExecution.fulfillmentStatus)&&(u.textContent=o?"\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"){c=null,await bt(e);return}if(e.status!=="pending"){if(a.canReselect===!1){u.textContent=o?"\u6B63\u5728\u6838\u5BF9\u539F\u8D2D\u4E70\u7ED3\u679C":"Checking the original purchase result",w.textContent=o?"\u67E5\u8BE2\u7ED3\u679C":"Check result",c=async()=>D(await a.read()),w.hidden=!1;return}e.status==="cancelled"?u.textContent=o?"\u8FD9\u7B14\u8D2D\u4E70\u5DF2\u53D6\u6D88\uFF0C\u53EF\u4EE5\u91CD\u65B0\u9009\u62E9\u65B9\u6848\u3002":"This purchase was cancelled. Choose a plan to start again.":e.status==="failed"&&(u.textContent=o?"\u8FD9\u7B14\u8D2D\u4E70\u672A\u80FD\u5B8C\u6210\uFF0C\u53EF\u4EE5\u91CD\u65B0\u9009\u62E9\u65B9\u6848\u3002":"This purchase didn\u2019t go through. Choose a plan to try again."),w.textContent=o?"\u91CD\u8BD5":"Retry",c=null,E=null;return}if(!t&&se(e).type==="checkout"){let r=a.quote,y=r?.operationId===e.operationId?je(r).label:"";u.textContent=Ce?y?o?`${y} \u5C1A\u672A\u4ED8\u6B3E\u3002\u518D\u6B21\u9009\u62E9\u8BE5\u65B9\u6848\u5373\u53EF\u7EE7\u7EED\u4ED8\u6B3E\u3002`:`${y} is still unpaid. Choose it again to continue paying.`:o?"\u4E4B\u524D\u7684\u8D2D\u4E70\u5C1A\u672A\u4ED8\u6B3E\u3002\u518D\u6B21\u9009\u62E9\u8BE5\u65B9\u6848\u5373\u53EF\u7EE7\u7EED\u4ED8\u6B3E\u3002":"Your earlier purchase is still unpaid. Choose that plan again to continue paying.":"",Ce=!1,c=null;return}await Pe(e);let n=Date.now()+6e5,s=2e3;me=!0,z(i.onObservationChange,!0);try{for(;!p&&Date.now()<n;){if(await st(s,d,fe.signal),p)return;if(!R()){c=async()=>D(await a.read()),w.hidden=!1;return}let r=await a.read();if(!t&&se(r).type==="checkout"){await D(r,!1);return}if(!r.problem&&r.status==="pending"&&await Pe(r),r.status!=="pending"||r.problem||He(r)){await D(r);return}s=Math.min(s*1.5,3e4)}}finally{me=!1,z(i.onObservationChange,!1)}c=async()=>D(await a.read()),w.hidden=!1}async function xe(e=!1){let t=await a.read();if(p)return;if(!R()){c=()=>xe(e),w.hidden=!1;return}let n=a.quote;if(n&&Je(t,{operationId:n.operationId,currency:n.currency},"The original purchase operation changed"),n&&t.status==="pending"&&t.quoteFinalized===!1&&!t.confirmedAt&&!t.checkoutUrl&&!t.nativePurchase&&!t.merchantExecution&&!t.problem&&!a.pendingCancellation){Be(n);return}await D(t,e||void 0)}async function te(){q?.remove(),q=null,c=te;let e=await a.confirm();if(!R()){c=te,w.hidden=!1;return}if(e.problem){await D(e);return}if(e.status==="pending"){if(e.checkoutUrl)await Pe(e);else if(e.execution&&e.execution.provider!=="merchant"||e.nativePurchase){if(!i.onPurchase)throw new k("PURCHASE_HANDLER_REQUIRED","Provide the merchant or native purchase handler");await i.onPurchase({operation:e,signal:fe.signal})}}c=async()=>D(await a.read()),await D(e,!0)}function Be(e){q?.remove();let t=!(Date.parse(e.expiresAt)>Date.now());u.textContent=t?o?"\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 n=d.createElement("div"),s=d.createElement("button"),r=d.createElement("button"),y=d.createElement("div"),x=d.createElement("p"),A=e.merchantTerms,de=o?"zh-CN":"en",W=A?.subscriptionTerms?.items??[],Re=A?A.subscriptionTerms?.trial?.days:e.lines.find(l=>l.trial)?.trial?.days,X=Re===void 0?null:A?A.totalMinor:e.charge?e.charge.totalMinor:e.lines.every(l=>l.trial)?0:null,Fe=(l,f)=>o?`${f} \u5929\u8BD5\u7528\u7ED3\u675F\u540E ${l}`:`Then ${l} after the ${f}-day trial`,{label:gt,recurring:Qe}=je(e),vt=e.lines.map(l=>l.productName).join(", "),We=X===null?"":`${o?"\u4ECA\u5929\u5E94\u4ED8":"Due today"} ${Z(X,e.currency)}`;x.textContent=We?[vt,We].filter(Boolean).join(" \xB7 "):gt,s.textContent=o?"\u786E\u8BA4\u8D2D\u4E70":"Confirm purchase",s.disabled=t,r.textContent=o?"\u53D6\u6D88":"Cancel",n.style.cssText=P.panel,x.style.cssText=P.summary,y.style.cssText=P.actions,s.style.cssText=P.primary,r.style.cssText=P.secondary,De(s),s.onclick=()=>{V(te)};let ze=async()=>{let l=await a.cancel();p||(n.remove(),q=null,await D(l))};r.onclick=()=>{c=ze,V(ze)};let L=d.createElement("div");if(L.style.cssText=P.terms,A){for(let f of W){if(X===null&&f===Qe)continue;let v=d.createElement("p"),M=Z(f.amountMinor,e.currency)+re(f.interval,de,f.intervalCount);v.textContent=X!==null&&Re!==void 0?Fe(M,Re):M,L.append(v)}let l=A.subscriptionTerms?.trial;if(l){let f=d.createElement("p");f.textContent=o?`\u8BD5\u7528 ${l.days} \u5929\uFF1B${l.cardRequired?"\u9700\u8981\u63D0\u4F9B\u4ED8\u6B3E\u65B9\u5F0F":"\u65E0\u9700\u63D0\u4F9B\u4ED8\u6B3E\u65B9\u5F0F"}`:`Trial days: ${l.days}; ${l.cardRequired?"a payment method is required":"no payment method is required"}`,L.append(f)}for(let f of[...A.expectedEffects.map(v=>v.description),...A.requiredConsents.map(v=>v.summary)]){let v=d.createElement("p");v.textContent=f,L.append(v)}}else{for(let l of e.lines){if(X!==null||l!==Qe){let f=d.createElement("p"),v=`${Z(l.catalogAmountMinor,e.currency)}${re(l.interval,de,l.intervalCount??1)}`;f.textContent=X!==null&&l.trial?(e.lines.length>1?`${l.productName} \xB7 `:"")+Fe(v,l.trial.days):`${l.productName} \xB7 ${v}`,L.append(f)}for(let f of l.prepaid??[]){let v=d.createElement("p"),M=a.view?.capabilities.plans[l.productVersionId]?.prepaid?.find(Ct=>Ct.internalFeatureId===f.internal_feature_id);v.textContent=`${M?.name??f.internal_feature_id} \xB7 ${f.quantity} ${o?"\u4EFD":"packs"} \xD7 ${f.terms.units}`,M&&(v.textContent+=re(M.reset==="week"||M.reset==="month"||M.reset==="year"?M.reset:"one_time",de,M.resetCount)),L.append(v)}if(l.trial){let f=d.createElement("p");f.textContent=o?`\u8BD5\u7528 ${l.trial.days} \u5929\uFF1B${l.trial.cardRequired?"\u9700\u8981\u63D0\u4F9B\u4ED8\u6B3E\u65B9\u5F0F":"\u65E0\u9700\u63D0\u4F9B\u4ED8\u6B3E\u65B9\u5F0F"}`:`Trial days: ${l.trial.days}; ${l.trial.cardRequired?"a payment method is required":"no payment method is required"}`,L.append(f)}}if(!e.charge){let l=d.createElement("p");l.textContent=o?"\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.",L.append(l)}}for(let l of L.children)l.style.margin="0";y.append(s,r),n.append(x,...L.childElementCount?[L]:[],y),U.prepend(n),g?.responsive||n.scrollIntoView?.({block:"nearest"}),s.focus({preventScroll:!0}),q=n,c=null}async function ue(){if(!E)return;if(c=ue,!oe){let n=a.view,s=n?.document.buttons[E.actionId],r=n&&s?.type==="checkout"?ee(s.product,E.selection,n.capabilities):null;if(!r)throw new k("PRODUCT_UNAVAILABLE","Choose an available Product in this purchase area");let y=await i.resolveOfferId?.({actionId:E.actionId,productVersionId:r});if(p)return;y!==void 0&&(E.offerId=y),oe=!0}if(!R()){w.hidden=!1;return}let e;try{e=await a.preview(E)}catch(n){throw a.canReselect===!0&&(E=null,oe=!1,c=null),n}if(p)return;let t=e.merchantTerms;if(i.confirmOnHostedCheckout&&R()&&e.provider==="merchant"&&e.billingSubscriptionId===null&&t?.request.action==="purchase"&&t.request.mode==="subscription"&&t.subscriptionTerms?.trial===null&&t.requiredConsents.length===0&&Date.parse(e.expiresAt)>Date.now()){let n=o?"\u6B63\u5728\u6253\u5F00\u6536\u94F6\u53F0\u2026":"Opening checkout\u2026";u.textContent=n;try{await te()}catch(s){p||Q(s)}finally{u.textContent===n&&(u.textContent="")}return}Be(e)}function K(e="destroy"){p||(p=!0,i.signal?.removeEventListener("abort",j),a.signal?.removeEventListener("abort",j),C.finish("dismissed"),Ue?.(),fe.abort(),_e?.disconnect(),g?.destroy(),B?.destroy(),a.destroy(),b.open&&b.close(),b.remove(),I.remove(),O(),e==="dismiss"&&z(i.onDismiss))}S=K;async function ke(){if(!F||p||ae||$==="closing"||!$&&!R())return;if(!N){K("dismiss");return}let e=d.createElement("p");e.setAttribute("role","status"),e.textContent=o?"\u6B63\u5728\u5173\u95ED\u2026":"Closing\u2026",H||(H=d.createElement("div"),H.style.cssText=U.style.cssText,U.replaceWith(H),Y.inert=!0),h.hidden=!1,H.replaceChildren(e,h),$="closing",h.setAttribute("aria-disabled","true"),h.focus({preventScroll:!0});try{await N.dismiss()}catch(t){p||z(i.onError,t)}p||($="retry",e.textContent=o?"\u672A\u80FD\u786E\u8BA4\u5173\u95ED\uFF0C\u8BF7\u91CD\u8BD5\u3002":"Could not confirm closure. Try again.",h.textContent=o?"\u91CD\u8BD5\u5173\u95ED":"Retry closing",h.removeAttribute("aria-label"),h.removeAttribute("aria-disabled"))}h.onclick=()=>{ke()},b.addEventListener("cancel",e=>{e.preventDefault(),ke()}),w.onclick=()=>{c&&V(c)};function Ie(e){C.finish("error",e),K()}function Ae(){if(!(!Ve||F||p||ae||g&&!R()))try{let e=t=>{be?.(),g&&(b.showModal(),g.responsive&&b.focus({preventScroll:!0}),!t&&i.loading!=="host"&&Ze(b,g.type,g.responsive)),F=!0};N?N.present(()=>C.present(()=>e(!0))):C.present(e)}catch(e){Ie(e),Q(e)}}try{ie.type==="inline"?(h.hidden=Object.values(m.document.buttons).some(t=>t.type==="close"),Me(),be=rt(I,T),T.append(I)):(b.setAttribute("aria-label",m.document.name),h.textContent="\xD7",h.setAttribute("aria-label",o?"\u5173\u95ED":"Close"),et(h,m.document.screen.theme),Ke(m.document)?(h.hidden=!0,b.append(I)):b.append(h,I),T.append(b),g=Xe(b,{...m.document.screen,presentation:ie},we),g.latch(),g.responsive&&(I.style.display="flex",I.style.flexDirection="column",I.style.maxHeight="100%",Y.style.overflow="clip",Y.style.minHeight="0"),be=nt(b)),B=ut(Y,{mode:"live",rendererUrl:a.webViewUrl,title:m.document.name,closeActions:ft,onAuthoredClose(t){p||$||(h.hidden=t,g&&!t&&h.parentElement!==b&&b.prepend(h))},hostPresentation:()=>g?.type??ie.type,reportContentHeight:g?.responsive,onResize:t=>{if(!g?.responsive)return;let n=Math.min(t,ye);Y.style.height=`${n}px`,g.setContentHeight(n+(H??U).getBoundingClientRect().height)},onAction(t,n={}){if(!F||p||$)return;if(!R()){Ee();return}let s=a.view,r=s?.document.buttons[t];if(!r)return;if(r.type==="close"){V(async()=>{await i.onAction?.(t),K(i.onAction?"action":"dismiss")});return}if(r.type==="action"){c=async()=>{if(r.action.type==="event"){if(!i.onEvent)throw new k("EVENT_HANDLER_REQUIRED","Provide the event handler");await i.onEvent(r.action.event)}else i.onOpenUrl?await i.onOpenUrl(r.action.url):d.defaultView?.location.assign(r.action.url);await i.onAction?.(t),c=null},V(c);return}if(q&&a.canReselect===!1){u.textContent=o?"\u8BF7\u5148\u786E\u8BA4\u6216\u53D6\u6D88\u5F53\u524D\u8D2D\u4E70\u3002":"Confirm or cancel the current purchase first.",g?.responsive||q.scrollIntoView?.({block:"nearest"}),q.querySelector("button")?.focus({preventScroll:!0});return}if((a.quote||E)&&a.canReselect===!1){let x=!!s&&!!a.quote&&yt(a.quote,s,r.product,n);Ce=!!a.quote&&!x,c=a.quote?()=>xe(x):ue,V(c);return}let y=s&&ee(r.product,n,s.capabilities);if(!s||!y){Q(new k("PRODUCT_UNAVAILABLE","Choose an available Product in this purchase area"));return}if(i.onPurchaseIntent){c=null,V(async()=>{let x={actionId:t,productVersionId:y,selection:structuredClone(n),featureQuantities:Oe(s.document.screen,y,n,s.capabilities)};ge=!0,await i.onPurchaseIntent(x)});return}if(E&&E.actionId!==t){Q(new k("COMMAND_PENDING","Finish the current purchase"));return}E||(E={requestId:crypto.randomUUID(),actionId:t,selection:n},oe=!1),V(ue)},onEscape:()=>{ke()},onError:t=>{let n=new Error(t);!F&&!p&&Ie(n),Q(n)},onRendered:t=>{t&&b.setAttribute("aria-label",t),Ve=!0,Ae()}}),we(),B.update(m.document.screen,m.document.screen.strings.defaultLocale,{capabilities:m.capabilities,unavailableActions:Ne(m),serverInput:{bindings:[],answers:{}}}),Ue=a.subscribe?.(he),he(a.view??m),await C.wait(B.ready);let e=a.operation;(a.quote||e&&(e.confirmedAt||e.checkoutUrl||e.status==="complete"))&&(c=()=>xe(),V(c))}catch(e){throw Ie(e),e}return{check:G,host:{get observing(){return me},get recovery(){return mt()},async prepareFallback(){if(J||p||$||ge)return{type:"recover",operationId:a.operation?.operationId??a.quote?.operationId??null,requestId:null};ce(!0);try{let e=await Ye(a);return e.type==="native"&&K(),e}finally{ce(!1)}},setSuspended(e){ae=e,I.hidden=e,e&&b.open?b.close():!e&&!F?Ae():!e&&!p&&F&&ie.type!=="inline"&&!b.open&&b.showModal()},destroy:K,refresh:async()=>{if(!R()){if(a.view)return a.view;throw new k("PRECONDITION_FAILED","Paywall presentation is suspended")}let e=await a.refresh();return he(e),Ae(),e}}}}export{zt as showPaywall};