@tinkerlandai/longplay-sdk 0.10.52 → 0.10.54

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 (112) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/{ai-usage-gcDQqLb2.d.ts → ai-usage-DBcYB8ix.d.ts} +1 -1
  3. package/dist/{api-D0Qu0isy.d.ts → api-1Tplv-7M.d.ts} +1 -1
  4. package/dist/check-response-MJHH5FWT.js +1 -0
  5. package/dist/{chunk-USM6HOXG.js → chunk-36VNAOG6.js} +1 -1
  6. package/dist/chunk-66TY4EFN.js +1 -0
  7. package/dist/{chunk-PGZZKX5K.js → chunk-6HKQILBV.js} +1 -1
  8. package/dist/{chunk-I643NVMZ.js → chunk-73UFNVEP.js} +1 -1
  9. package/dist/{chunk-UCDQJB53.js → chunk-ADTZEBQF.js} +1 -1
  10. package/dist/chunk-AEQUKR4O.js +1 -0
  11. package/dist/{chunk-5YQZEJBM.js → chunk-ANJPFGFN.js} +1 -1
  12. package/dist/{chunk-XI2NNZBS.js → chunk-BKBWGPNR.js} +1 -1
  13. package/dist/{chunk-7UXQJJFZ.js → chunk-BX2MSRA4.js} +1 -1
  14. package/dist/chunk-C4NXQMSO.js +1 -0
  15. package/dist/{chunk-K644WUOE.js → chunk-CAE4KIZN.js} +1 -1
  16. package/dist/{chunk-3TV3CVNP.js → chunk-CJUODAOF.js} +1 -1
  17. package/dist/{chunk-4CRUNNTC.js → chunk-DXLBEXC6.js} +1 -1
  18. package/dist/{chunk-CJUVMNDB.js → chunk-EACC667P.js} +1 -1
  19. package/dist/{chunk-TSBXPDUQ.js → chunk-GGZG56GR.js} +1 -1
  20. package/dist/{chunk-VPT5MFDG.js → chunk-HMJTABQ5.js} +2 -2
  21. package/dist/{chunk-EDV6ZNPQ.js → chunk-IN32NWRI.js} +1 -1
  22. package/dist/{chunk-2MDJ3JE5.js → chunk-J4RM5GQP.js} +1 -1
  23. package/dist/chunk-JCI5PGY3.js +1 -0
  24. package/dist/{chunk-AFZB2AYU.js → chunk-JJIP6BZL.js} +1 -1
  25. package/dist/{chunk-KXSZTBAG.js → chunk-JXWZS4UM.js} +1 -1
  26. package/dist/{chunk-FAMPOY6L.js → chunk-L64BS65O.js} +1 -1
  27. package/dist/{chunk-VGEH7B6S.js → chunk-LBDLWHBY.js} +1 -1
  28. package/dist/{chunk-AN7CPDBU.js → chunk-LFMAFY3P.js} +1 -1
  29. package/dist/{chunk-3LWZFXLN.js → chunk-LOBZ45T3.js} +1 -1
  30. package/dist/{chunk-CBOIDISB.js → chunk-M4P6TGBU.js} +1 -1
  31. package/dist/chunk-MRL7XUBV.js +1 -0
  32. package/dist/{chunk-XO6GV6O7.js → chunk-MZRDAMFQ.js} +1 -1
  33. package/dist/{chunk-KVIGHX2B.js → chunk-NL7AXMUA.js} +1 -1
  34. package/dist/{chunk-YJRO7NXN.js → chunk-NNJVMJUG.js} +1 -1
  35. package/dist/chunk-OJDO7546.js +1 -0
  36. package/dist/{chunk-RUMGXXVJ.js → chunk-OV46DXRX.js} +1 -1
  37. package/dist/{chunk-LDLS2VL2.js → chunk-OZK47BUU.js} +1 -1
  38. package/dist/{chunk-W3V7DTPC.js → chunk-PB34FLPJ.js} +1 -1
  39. package/dist/{chunk-DJYLJBU2.js → chunk-PPXVRQAG.js} +1 -1
  40. package/dist/{chunk-7Q25R5GL.js → chunk-PVMGYRGE.js} +1 -1
  41. package/dist/chunk-QAGK2SLZ.js +1 -0
  42. package/dist/{chunk-POX2ELNS.js → chunk-QGKROSRD.js} +1 -1
  43. package/dist/{chunk-FKC7TJWM.js → chunk-R2L227PQ.js} +1 -1
  44. package/dist/{chunk-YGOXUDDF.js → chunk-R4BYUK7S.js} +1 -1
  45. package/dist/{chunk-ZVLZLBDA.js → chunk-RJT764B2.js} +1 -1
  46. package/dist/{chunk-BBA64POP.js → chunk-RRZZUIFM.js} +1 -1
  47. package/dist/{chunk-OEUA65JK.js → chunk-S2MSRPR2.js} +1 -1
  48. package/dist/{chunk-PZZLYHKR.js → chunk-SK5JZ7HA.js} +2 -2
  49. package/dist/{chunk-7LHRBNSH.js → chunk-TS26DZNO.js} +1 -1
  50. package/dist/{chunk-NVHRWZIZ.js → chunk-UEKKQHUZ.js} +1 -1
  51. package/dist/{chunk-BYHBBZIO.js → chunk-WE55LJEN.js} +1 -1
  52. package/dist/{chunk-S4YBFFFY.js → chunk-XHZH3E4G.js} +1 -1
  53. package/dist/{chunk-JRHJO4BR.js → chunk-YMRWDMIL.js} +1 -1
  54. package/dist/chunk-ZEU56NVY.js +1 -0
  55. package/dist/{chunk-S6MXUFVF.js → chunk-ZQY7OYHM.js} +1 -1
  56. package/dist/{configuration-sync-DObsuVof.d.ts → configuration-sync-DeWWW5za.d.ts} +1 -1
  57. package/dist/{content-2EEYM7U7.js → content-A4SPKH7N.js} +1 -1
  58. package/dist/funnel-host-purchase-V2TIWGCQ.js +1 -0
  59. package/dist/funnel-host-recovery-paywall-DWKTPDLY.js +1 -0
  60. package/dist/{funnel-local-client-DzRzPX4x.d.ts → funnel-local-client-Fxsyl7rh.d.ts} +26 -26
  61. package/dist/funnel-paywall-prerender-DD7LQXDJ.js +1 -0
  62. package/dist/{funnel-process-client-DGRmy5KN.d.ts → funnel-process-client-D9saqPse.d.ts} +12 -12
  63. package/dist/funnel-route-prediction-ICGW4DPX.js +1 -0
  64. package/dist/funnel-route-source-64LTJZXN.js +1 -0
  65. package/dist/funnel-runtime-host-JG3OAYZ6.js +1 -0
  66. package/dist/index.d.ts +2353 -445
  67. package/dist/index.js +1 -1
  68. package/dist/merchant-bridge-contracts-DEDEIYNU.js +1 -0
  69. package/dist/native-shell.js +1 -1
  70. package/dist/openrouter.d.ts +3 -3
  71. package/dist/openrouter.js +1 -1
  72. package/dist/operation-contracts-RHJJI5NO.js +1 -0
  73. package/dist/page.d.ts +2 -2
  74. package/dist/page.js +1 -1
  75. package/dist/paywall-NM4HMYMK.js +1 -0
  76. package/dist/paywall-content-T2FGNRBR.js +1 -0
  77. package/dist/paywall-session-BAUWSWWR.js +1 -0
  78. package/dist/popup.d.ts +3 -3
  79. package/dist/popup.js +1 -1
  80. package/dist/{presentation-loading-BWUNotNa.d.ts → presentation-loading-sMyRJ21g.d.ts} +4 -2
  81. package/dist/react-native.d.ts +7 -7
  82. package/dist/react-native.js +1 -1
  83. package/dist/screen-renderer-CMFJVI36.js +1 -0
  84. package/dist/server.d.ts +7 -7
  85. package/dist/server.js +1 -1
  86. package/dist/{visual-dom-5LUN4AHO.js → visual-dom-MH3JDJHJ.js} +1 -1
  87. package/dist/visual.js +1 -1
  88. package/package.json +1 -1
  89. package/dist/check-response-AVQ7PY5I.js +0 -1
  90. package/dist/chunk-4OSW2Y67.js +0 -1
  91. package/dist/chunk-EJAF6OGO.js +0 -1
  92. package/dist/chunk-L66EXWTK.js +0 -1
  93. package/dist/chunk-QIY6PCYC.js +0 -1
  94. package/dist/chunk-ZNOVEJLM.js +0 -1
  95. package/dist/chunk-ZY4YDPSI.js +0 -1
  96. package/dist/funnel-host-purchase-UONTZRRJ.js +0 -1
  97. package/dist/funnel-paywall-prerender-AT4BXZIY.js +0 -1
  98. package/dist/funnel-route-prediction-Z3J2HSHI.js +0 -1
  99. package/dist/funnel-route-source-LFE6GSHU.js +0 -1
  100. package/dist/funnel-runtime-host-7ROIR7CU.js +0 -1
  101. package/dist/merchant-bridge-contracts-O6WIWC7T.js +0 -1
  102. package/dist/operation-contracts-H7NKQ373.js +0 -1
  103. package/dist/paywall-25MAYQ4B.js +0 -1
  104. package/dist/paywall-content-7KTEQLRN.js +0 -1
  105. package/dist/paywall-session-7HGW5IKN.js +0 -1
  106. package/dist/screen-renderer-XZWKIJWF.js +0 -1
  107. package/dist/{chunk-PY3AC5KD.js → chunk-5YBTU4KS.js} +0 -0
  108. package/dist/{chunk-CILM5XMH.js → chunk-DLRCJF6U.js} +0 -0
  109. package/dist/{chunk-VPT5MFDG.js.LEGAL.txt → chunk-HMJTABQ5.js.LEGAL.txt} +0 -0
  110. package/dist/{chunk-PZZLYHKR.js.LEGAL.txt → chunk-SK5JZ7HA.js.LEGAL.txt} +0 -0
  111. package/dist/{chunk-OJM6ORHE.js → chunk-VJIONC4S.js} +0 -0
  112. package/dist/{screen-CJepeiBT.d.ts → screen-D2bUmJ4M.d.ts} +1 -1
@@ -1,8 +1,8 @@
1
1
  import { OpenRouter } from '@openrouter/sdk';
2
2
  import { ChatUsage } from '@openrouter/sdk/models';
3
- import { F as FoundationApi } from './api-D0Qu0isy.js';
4
- import { c as createAiPricing, A as AiUsageContext, a as AiTokenUsage, b as AiTokenQuote } from './ai-usage-gcDQqLb2.js';
5
- import './screen-CJepeiBT.js';
3
+ import { F as FoundationApi } from './api-1Tplv-7M.js';
4
+ import { c as createAiPricing, A as AiUsageContext, a as AiTokenUsage, b as AiTokenQuote } from './ai-usage-DBcYB8ix.js';
5
+ import './screen-D2bUmJ4M.js';
6
6
  import 'zod';
7
7
  import 'zod/v4';
8
8
  import '@ai-sdk/provider';
@@ -1 +1 @@
1
- import"./chunk-EDV6ZNPQ.js";import"./chunk-5YQZEJBM.js";import"./chunk-7LHRBNSH.js";import"./chunk-FAMPOY6L.js";import{a as i}from"./chunk-BYHBBZIO.js";import"./chunk-LDLS2VL2.js";import"./chunk-VGEH7B6S.js";import{b as A}from"./chunk-PY3AC5KD.js";import"./chunk-WOT6VMZA.js";var c=A.number().int().min(0).max(1e9);function R(e,o){let a=c.parse(e.promptTokens),p=c.parse(e.completionTokens),s=c.parse(e.promptTokensDetails?.cachedTokens??0),t=c.parse(e.promptTokensDetails?.cacheWriteTokens??0),r=c.parse(e.promptTokensDetails?.audioTokens??0),l=c.parse(e.completionTokensDetails?.audioTokens??0),n=c.parse(e.completionTokensDetails?.reasoningTokens??0);if(c.parse(e.totalTokens)!==a+p||s+t+r>a||n+l>p||(e.promptTokensDetails?.videoTokens??0)>0)throw new i("AI_USAGE_UNAVAILABLE","Token pools must conserve usage; video needs an explicit token mapper");return{input:a-s-t-r,output:p-l-(o==="separate"?n:0),cache_read:s,cache_write:t,input_audio:r,output_audio:l,reasoning:o==="separate"?n:0}}function I(e){if(!Number.isFinite(e)||e<0)throw new i("AI_USAGE_UNAVAILABLE","Provider cost must be a nonnegative USD amount");let o=String(e),a=o.includes("e")?e.toFixed(18).replace(/0+$/,"").replace(/\.$/,""):o;if(!/^(0|[1-9]\d{0,11})(\.\d{1,18})?$/.test(a)||Number(a)!==e)throw new i("AI_USAGE_UNAVAILABLE","Provider cost exceeds the supported precision");return a}async function f(e){if(typeof window<"u")throw new i("SERVER_ONLY","OpenRouter accounting requires your backend");if(!["output","separate"].includes(e.reasoning)||!e.modelId||!e.generationId)throw new i("INVALID_REQUEST","Actual model, generation ID and reasoning pricing are required");let o={context:e.context,generationId:e.generationId,modelId:`openrouter/${e.modelId}`,usage:e.usage,tokens:null,quote:null,receipt:null,phase:"captured"};await e.persist(o);let a=e.mapTokens?e.mapTokens(e.usage):R(e.usage,e.reasoning),p=e.usage.cost==null?void 0:I(e.usage.cost),s=e.quote??await e.pricing.quoteTokens({modelId:o.modelId,tokens:a});if(s.pricing.modelId!==o.modelId||Object.keys(a).some(l=>a[l]!==s.tokens[l]))throw new i("INVALID_REQUEST","Saved quote must match the provider model and token pools");await e.persist({...o,tokens:a,quote:s,phase:"quoted"});let t=await e.pricing.trackTokens(e.client,{...e.context,quote:s,providerCostUsd:p,generationId:e.generationId});if(!t.receipt.accepted)throw new i("AI_BALANCE_REJECTED","OpenRouter usage was saved but the balance request was rejected");let r={...o,tokens:a,quote:s,receipt:t,phase:"settled"};return await e.persist(r),r}function T(e){if(typeof window<"u")throw new i("SERVER_ONLY","OpenRouter accounting requires your backend");if(!["output","separate"].includes(e.reasoning))throw new i("INVALID_REQUEST","Reasoning pricing is required");let o=e.openRouter.chat;async function a(t){if(!t.usage||!t.modelId||!t.generationId)throw new i("AI_USAGE_UNAVAILABLE","OpenRouter did not return final usage and the actual model");await f({...e,context:t.context,generationId:t.generationId,modelId:t.modelId.slice(11),usage:t.usage})}let p=async(t,r)=>{let n={context:await e.context(),generationId:null,modelId:null,usage:null,tokens:null,quote:null,receipt:null,phase:"incomplete"},d;try{d=await o.send(t,r)}catch(g){throw await e.persist(n),g}if(!(d instanceof ReadableStream)){if(n={...n,generationId:d.id,modelId:d.model?`openrouter/${d.model}`:null,usage:d.usage??null},!n.usage||!n.modelId)throw await e.persist(n),new i("AI_USAGE_UNAVAILABLE","OpenRouter omitted final accounting");return await a(n),d}let w=d.getReader(),m=!1;return new ReadableStream({async pull(g){try{let{value:u,done:k}=await w.read();if(k){if(m=!0,!n.usage||!n.modelId)throw await e.persist(n),new i("AI_USAGE_UNAVAILABLE","OpenRouter stream ended without final accounting");await a(n),g.close();return}if(u.error)throw new i("AI_PROVIDER_ERROR",u.error.message);u.usage&&(n={...n,generationId:u.id,modelId:u.model?`openrouter/${u.model}`:null,usage:u.usage}),g.enqueue(u)}catch(u){m||(m=!0,await e.persist(n)),await w.cancel(u),g.error(u)}},async cancel(g){m||(m=!0,await e.persist(n)),await w.cancel(g)}})},s=new Proxy(o,{get(t,r){return r==="send"?p:Reflect.get(t,r,t)}});return new Proxy(e.openRouter,{get(t,r){return r==="chat"?s:Reflect.get(t,r,t)}})}export{T as createOpenRouterUsageClient,f as trackOpenRouterUsage};
1
+ import"./chunk-IN32NWRI.js";import"./chunk-ANJPFGFN.js";import"./chunk-TS26DZNO.js";import"./chunk-L64BS65O.js";import{a as i}from"./chunk-WE55LJEN.js";import"./chunk-OZK47BUU.js";import"./chunk-LBDLWHBY.js";import{b as A}from"./chunk-5YBTU4KS.js";import"./chunk-WOT6VMZA.js";var c=A.number().int().min(0).max(1e9);function R(e,o){let a=c.parse(e.promptTokens),p=c.parse(e.completionTokens),s=c.parse(e.promptTokensDetails?.cachedTokens??0),t=c.parse(e.promptTokensDetails?.cacheWriteTokens??0),r=c.parse(e.promptTokensDetails?.audioTokens??0),l=c.parse(e.completionTokensDetails?.audioTokens??0),n=c.parse(e.completionTokensDetails?.reasoningTokens??0);if(c.parse(e.totalTokens)!==a+p||s+t+r>a||n+l>p||(e.promptTokensDetails?.videoTokens??0)>0)throw new i("AI_USAGE_UNAVAILABLE","Token pools must conserve usage; video needs an explicit token mapper");return{input:a-s-t-r,output:p-l-(o==="separate"?n:0),cache_read:s,cache_write:t,input_audio:r,output_audio:l,reasoning:o==="separate"?n:0}}function I(e){if(!Number.isFinite(e)||e<0)throw new i("AI_USAGE_UNAVAILABLE","Provider cost must be a nonnegative USD amount");let o=String(e),a=o.includes("e")?e.toFixed(18).replace(/0+$/,"").replace(/\.$/,""):o;if(!/^(0|[1-9]\d{0,11})(\.\d{1,18})?$/.test(a)||Number(a)!==e)throw new i("AI_USAGE_UNAVAILABLE","Provider cost exceeds the supported precision");return a}async function f(e){if(typeof window<"u")throw new i("SERVER_ONLY","OpenRouter accounting requires your backend");if(!["output","separate"].includes(e.reasoning)||!e.modelId||!e.generationId)throw new i("INVALID_REQUEST","Actual model, generation ID and reasoning pricing are required");let o={context:e.context,generationId:e.generationId,modelId:`openrouter/${e.modelId}`,usage:e.usage,tokens:null,quote:null,receipt:null,phase:"captured"};await e.persist(o);let a=e.mapTokens?e.mapTokens(e.usage):R(e.usage,e.reasoning),p=e.usage.cost==null?void 0:I(e.usage.cost),s=e.quote??await e.pricing.quoteTokens({modelId:o.modelId,tokens:a});if(s.pricing.modelId!==o.modelId||Object.keys(a).some(l=>a[l]!==s.tokens[l]))throw new i("INVALID_REQUEST","Saved quote must match the provider model and token pools");await e.persist({...o,tokens:a,quote:s,phase:"quoted"});let t=await e.pricing.trackTokens(e.client,{...e.context,quote:s,providerCostUsd:p,generationId:e.generationId});if(!t.receipt.accepted)throw new i("AI_BALANCE_REJECTED","OpenRouter usage was saved but the balance request was rejected");let r={...o,tokens:a,quote:s,receipt:t,phase:"settled"};return await e.persist(r),r}function T(e){if(typeof window<"u")throw new i("SERVER_ONLY","OpenRouter accounting requires your backend");if(!["output","separate"].includes(e.reasoning))throw new i("INVALID_REQUEST","Reasoning pricing is required");let o=e.openRouter.chat;async function a(t){if(!t.usage||!t.modelId||!t.generationId)throw new i("AI_USAGE_UNAVAILABLE","OpenRouter did not return final usage and the actual model");await f({...e,context:t.context,generationId:t.generationId,modelId:t.modelId.slice(11),usage:t.usage})}let p=async(t,r)=>{let n={context:await e.context(),generationId:null,modelId:null,usage:null,tokens:null,quote:null,receipt:null,phase:"incomplete"},d;try{d=await o.send(t,r)}catch(g){throw await e.persist(n),g}if(!(d instanceof ReadableStream)){if(n={...n,generationId:d.id,modelId:d.model?`openrouter/${d.model}`:null,usage:d.usage??null},!n.usage||!n.modelId)throw await e.persist(n),new i("AI_USAGE_UNAVAILABLE","OpenRouter omitted final accounting");return await a(n),d}let w=d.getReader(),m=!1;return new ReadableStream({async pull(g){try{let{value:u,done:k}=await w.read();if(k){if(m=!0,!n.usage||!n.modelId)throw await e.persist(n),new i("AI_USAGE_UNAVAILABLE","OpenRouter stream ended without final accounting");await a(n),g.close();return}if(u.error)throw new i("AI_PROVIDER_ERROR",u.error.message);u.usage&&(n={...n,generationId:u.id,modelId:u.model?`openrouter/${u.model}`:null,usage:u.usage}),g.enqueue(u)}catch(u){m||(m=!0,await e.persist(n)),await w.cancel(u),g.error(u)}},async cancel(g){m||(m=!0,await e.persist(n)),await w.cancel(g)}})},s=new Proxy(o,{get(t,r){return r==="send"?p:Reflect.get(t,r,t)}});return new Proxy(e.openRouter,{get(t,r){return r==="chat"?s:Reflect.get(t,r,t)}})}export{T as createOpenRouterUsageClient,f as trackOpenRouterUsage};
@@ -0,0 +1 @@
1
+ import{e as o}from"./chunk-JXWZS4UM.js";import"./chunk-YMRWDMIL.js";import"./chunk-CJUODAOF.js";import"./chunk-6HKQILBV.js";import"./chunk-EACC667P.js";import"./chunk-BX2MSRA4.js";import"./chunk-J4RM5GQP.js";import"./chunk-M4P6TGBU.js";import"./chunk-GGZG56GR.js";import"./chunk-NL7AXMUA.js";import"./chunk-VILB5M4X.js";import"./chunk-ANJPFGFN.js";import"./chunk-L64BS65O.js";import"./chunk-QGKROSRD.js";import"./chunk-RRZZUIFM.js";import"./chunk-RJT764B2.js";import"./chunk-BKBWGPNR.js";import"./chunk-NNJVMJUG.js";import"./chunk-OZK47BUU.js";import"./chunk-5YBTU4KS.js";import"./chunk-HMJTABQ5.js";import"./chunk-DLRCJF6U.js";import"./chunk-WOT6VMZA.js";export{o as apiOperations};
package/dist/page.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { C as ConfigurationSync } from './configuration-sync-DObsuVof.js';
1
+ import { C as ConfigurationSync } from './configuration-sync-DeWWW5za.js';
2
2
  import { J as JsonValue, R as Result } from './growth-rules-B4YYy64R.js';
3
3
  import { z } from 'zod';
4
- import './screen-CJepeiBT.js';
4
+ import './screen-D2bUmJ4M.js';
5
5
 
6
6
  /** GET /api/v1/page-experiments/{environmentId}: page experiments and the saved groups they reference only. */
7
7
  declare const pageExperimentPayloadSchema: z.ZodObject<{
package/dist/page.js CHANGED
@@ -1 +1 @@
1
- import{d as o,e as r,f as e,g as f}from"./chunk-PZZLYHKR.js";import"./chunk-FKC7TJWM.js";import"./chunk-3VUPVXAV.js";import"./chunk-VGEH7B6S.js";import"./chunk-DSPLGTQI.js";import"./chunk-VPT5MFDG.js";import"./chunk-CILM5XMH.js";import"./chunk-WOT6VMZA.js";export{f as createPageExperiments,o as mergeQueryStrings,r as pageAttributes,e as readPayload};
1
+ import{d as o,e as r,f as e,g as f}from"./chunk-SK5JZ7HA.js";import"./chunk-R2L227PQ.js";import"./chunk-3VUPVXAV.js";import"./chunk-LBDLWHBY.js";import"./chunk-DSPLGTQI.js";import"./chunk-HMJTABQ5.js";import"./chunk-DLRCJF6U.js";import"./chunk-WOT6VMZA.js";export{f as createPageExperiments,o as mergeQueryStrings,r as pageAttributes,e as readPayload};
@@ -0,0 +1 @@
1
+ import{a}from"./chunk-OJDO7546.js";import"./chunk-DXLBEXC6.js";import"./chunk-W32FI2A2.js";import"./chunk-QAGK2SLZ.js";import"./chunk-ADTZEBQF.js";import"./chunk-OV46DXRX.js";import"./chunk-M4P6TGBU.js";import"./chunk-GGZG56GR.js";import"./chunk-NL7AXMUA.js";import"./chunk-VILB5M4X.js";import"./chunk-TS26DZNO.js";import"./chunk-L64BS65O.js";import"./chunk-QGKROSRD.js";import"./chunk-RRZZUIFM.js";import"./chunk-RJT764B2.js";import"./chunk-BKBWGPNR.js";import"./chunk-NNJVMJUG.js";import"./chunk-WE55LJEN.js";import"./chunk-OZK47BUU.js";import"./chunk-LBDLWHBY.js";import"./chunk-5YBTU4KS.js";import"./chunk-DSPLGTQI.js";import"./chunk-HMJTABQ5.js";import"./chunk-DLRCJF6U.js";import"./chunk-WOT6VMZA.js";export{a as showPaywall};
@@ -0,0 +1 @@
1
+ import{b as a}from"./chunk-LFMAFY3P.js";import"./chunk-6HKQILBV.js";import"./chunk-EACC667P.js";import"./chunk-BX2MSRA4.js";import"./chunk-J4RM5GQP.js";import"./chunk-M4P6TGBU.js";import"./chunk-GGZG56GR.js";import"./chunk-NL7AXMUA.js";import"./chunk-VILB5M4X.js";import"./chunk-TS26DZNO.js";import"./chunk-L64BS65O.js";import"./chunk-QGKROSRD.js";import"./chunk-RRZZUIFM.js";import"./chunk-RJT764B2.js";import"./chunk-BKBWGPNR.js";import"./chunk-NNJVMJUG.js";import"./chunk-WE55LJEN.js";import"./chunk-OZK47BUU.js";import"./chunk-3VUPVXAV.js";import"./chunk-LBDLWHBY.js";import"./chunk-5YBTU4KS.js";import"./chunk-HMJTABQ5.js";import"./chunk-DLRCJF6U.js";import"./chunk-WOT6VMZA.js";export{a as readPaywallContent};
@@ -0,0 +1 @@
1
+ import{a}from"./chunk-ZQY7OYHM.js";import"./chunk-JXWZS4UM.js";import"./chunk-YMRWDMIL.js";import"./chunk-CAE4KIZN.js";import"./chunk-CJUODAOF.js";import"./chunk-XHZH3E4G.js";import"./chunk-LFMAFY3P.js";import"./chunk-6HKQILBV.js";import"./chunk-EACC667P.js";import"./chunk-BX2MSRA4.js";import"./chunk-J4RM5GQP.js";import"./chunk-ADTZEBQF.js";import"./chunk-OV46DXRX.js";import"./chunk-M4P6TGBU.js";import"./chunk-GGZG56GR.js";import"./chunk-NL7AXMUA.js";import"./chunk-VILB5M4X.js";import"./chunk-ANJPFGFN.js";import"./chunk-TS26DZNO.js";import"./chunk-L64BS65O.js";import"./chunk-QGKROSRD.js";import"./chunk-RRZZUIFM.js";import"./chunk-RJT764B2.js";import"./chunk-BKBWGPNR.js";import"./chunk-NNJVMJUG.js";import"./chunk-WE55LJEN.js";import"./chunk-OZK47BUU.js";import"./chunk-3VUPVXAV.js";import"./chunk-LBDLWHBY.js";import"./chunk-5YBTU4KS.js";import"./chunk-DSPLGTQI.js";import"./chunk-HMJTABQ5.js";import"./chunk-DLRCJF6U.js";import"./chunk-WOT6VMZA.js";export{a as createPaywallSession};
package/dist/popup.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { e as CustomerPageData, a as SurfaceData, P as PresentationLoadingOptions, L as LoadingLayout, f as ScreenParameters, g as ScreenRendererInput, S as ScreenAnswers, C as CustomerDataIntent } from './presentation-loading-BWUNotNa.js';
2
- export { d as PresentationState } from './presentation-loading-BWUNotNa.js';
3
- import { b as ScreenAction, c as ScreenNode, d as ScreenInteractivity, e as ScreenDocument } from './screen-CJepeiBT.js';
1
+ import { e as CustomerPageData, a as SurfaceData, P as PresentationLoadingOptions, L as LoadingLayout, f as ScreenParameters, g as ScreenRendererInput, S as ScreenAnswers, C as CustomerDataIntent } from './presentation-loading-sMyRJ21g.js';
2
+ export { d as PresentationState } from './presentation-loading-sMyRJ21g.js';
3
+ import { b as ScreenAction, c as ScreenNode, d as ScreenInteractivity, e as ScreenDocument } from './screen-D2bUmJ4M.js';
4
4
  import { O as Offer, a as OfferUnavailableReason } from './coupon-kfkIVf9n.js';
5
5
  import { WindowLike } from 'dompurify';
6
6
  import 'zod';
package/dist/popup.js CHANGED
@@ -1 +1 @@
1
- import{a as o,b as r,c as e,d as f,e as m,f as p,g as t,h as x,i as a}from"./chunk-NVHRWZIZ.js";import"./chunk-ZNOVEJLM.js";import"./chunk-POX2ELNS.js";import"./chunk-BBA64POP.js";import"./chunk-ZVLZLBDA.js";import"./chunk-XI2NNZBS.js";import"./chunk-YJRO7NXN.js";import"./chunk-BYHBBZIO.js";import"./chunk-LDLS2VL2.js";import"./chunk-PY3AC5KD.js";import"./chunk-DSPLGTQI.js";import"./chunk-VPT5MFDG.js";import"./chunk-CILM5XMH.js";import"./chunk-WOT6VMZA.js";export{p as formatCustomerDecimal,r as hostedRendererScript,o as hostedRendererShell,f as inspectCustomHtml,a as mountScreenPreview,x as preparePopup,m as prepareScreen,e as sanitizeCustomHtml,t as showPopup};
1
+ import{a as o,b as r,c as e,d as f,e as m,f as p,g as t,h as x,i as a}from"./chunk-UEKKQHUZ.js";import"./chunk-QAGK2SLZ.js";import"./chunk-QGKROSRD.js";import"./chunk-RRZZUIFM.js";import"./chunk-RJT764B2.js";import"./chunk-BKBWGPNR.js";import"./chunk-NNJVMJUG.js";import"./chunk-WE55LJEN.js";import"./chunk-OZK47BUU.js";import"./chunk-5YBTU4KS.js";import"./chunk-DSPLGTQI.js";import"./chunk-HMJTABQ5.js";import"./chunk-DLRCJF6U.js";import"./chunk-WOT6VMZA.js";export{p as formatCustomerDecimal,r as hostedRendererScript,o as hostedRendererShell,f as inspectCustomHtml,a as mountScreenPreview,x as preparePopup,m as prepareScreen,e as sanitizeCustomHtml,t as showPopup};
@@ -1,5 +1,5 @@
1
1
  import { z } from 'zod';
2
- import { S as StackNode, e as ScreenDocument } from './screen-CJepeiBT.js';
2
+ import { S as StackNode, e as ScreenDocument } from './screen-D2bUmJ4M.js';
3
3
 
4
4
  declare const surfaceDataSchema: z.ZodObject<{
5
5
  paywall: z.ZodOptional<z.ZodObject<{
@@ -384,9 +384,9 @@ declare const customerPageDataSchema: z.ZodObject<{
384
384
  nodes: z.ZodRecord<z.ZodString, z.ZodObject<{
385
385
  source: z.ZodEnum<{
386
386
  membership: "membership";
387
+ billing: "billing";
387
388
  credit_balance: "credit_balance";
388
389
  credit_transactions: "credit_transactions";
389
- billing: "billing";
390
390
  billing_controls: "billing_controls";
391
391
  customer_plans: "customer_plans";
392
392
  credit_packs: "credit_packs";
@@ -1061,6 +1061,7 @@ declare function createPresentationLoading(container: HTMLElement | ShadowRoot,
1061
1061
  readonly cancelled: boolean;
1062
1062
  getLoadingLayout(): LoadingLayout | undefined;
1063
1063
  retainPurchaseDialog(): RetainedPurchaseDialog | undefined;
1064
+ setPurchaseRecovery(message: string, retry?: () => void): void;
1064
1065
  /** Null selects the Paywall loading status when its layout is unavailable. */
1065
1066
  start(modal: boolean, locale?: string, paywall?: PaywallLoadingDocument | null): void;
1066
1067
  /** Remove the placeholder and reveal in the same turn, before notifying the host. */
@@ -1076,6 +1077,7 @@ declare function createPresentationLoading(container: HTMLElement | ShadowRoot,
1076
1077
  readonly cancelled: boolean;
1077
1078
  getLoadingLayout(): LoadingLayout | undefined;
1078
1079
  retainPurchaseDialog(): RetainedPurchaseDialog | undefined;
1080
+ setPurchaseRecovery(message: string, retry?: () => void): void;
1079
1081
  /** Null selects the Paywall loading status when its layout is unavailable. */
1080
1082
  start(modal: boolean, locale?: string, paywall?: PaywallLoadingDocument | null): void;
1081
1083
  /** Remove the placeholder and reveal in the same turn, before notifying the host. */
@@ -1,12 +1,12 @@
1
- import { f as createCustomerClient, d as createFunnelClient } from './funnel-process-client-DGRmy5KN.js';
2
- export { F as FunnelProcessAdapter, a as FunnelProcessOptions, c as createFunnelProcess } from './funnel-process-client-DGRmy5KN.js';
3
- import { I as IndianaOptions, S as SessionCredentials, N as Scope, B as createFunnelRunController, x as PaywallStartInput, l as createPaywallSession } from './funnel-local-client-DzRzPX4x.js';
4
- export { F as FunnelCommandStorage, g as FunnelRunController, u as LocalFunnelClientOptions, v as LongplayError, w as PaywallPurchaseInput, P as PaywallSession, y as PushHost, z as PushJournal, A as createFeatureClient, D as createLocalFunnelClient } from './funnel-local-client-DzRzPX4x.js';
1
+ import { f as createCustomerClient, d as createFunnelClient } from './funnel-process-client-D9saqPse.js';
2
+ export { F as FunnelProcessAdapter, a as FunnelProcessOptions, c as createFunnelProcess } from './funnel-process-client-D9saqPse.js';
3
+ import { I as IndianaOptions, S as SessionCredentials, N as Scope, B as createFunnelRunController, x as PaywallStartInput, l as createPaywallSession } from './funnel-local-client-Fxsyl7rh.js';
4
+ export { F as FunnelCommandStorage, h as FunnelRunController, u as LocalFunnelClientOptions, v as LongplayError, w as PaywallPurchaseInput, P as PaywallSession, y as PushHost, z as PushJournal, A as createFeatureClient, D as createLocalFunnelClient } from './funnel-local-client-Fxsyl7rh.js';
5
5
  import { z } from 'zod';
6
6
  import { J as JsonValue } from './growth-rules-B4YYy64R.js';
7
- export { a as ConfigurationStorage, b as ConfigurationSyncOptions, c as createConfigurationSync } from './configuration-sync-DObsuVof.js';
8
- import './api-D0Qu0isy.js';
9
- import './screen-CJepeiBT.js';
7
+ export { a as ConfigurationStorage, b as ConfigurationSyncOptions, c as createConfigurationSync } from './configuration-sync-DeWWW5za.js';
8
+ import './api-1Tplv-7M.js';
9
+ import './screen-D2bUmJ4M.js';
10
10
  import 'zod/v4';
11
11
  import './coupon-kfkIVf9n.js';
12
12
 
@@ -1 +1 @@
1
- import{b as S,c as E,d as T}from"./chunk-DJYLJBU2.js";import"./chunk-7Q25R5GL.js";import{a as A}from"./chunk-S6MXUFVF.js";import{e as P}from"./chunk-KXSZTBAG.js";import"./chunk-JRHJO4BR.js";import{h as b,i as x,k as L}from"./chunk-W3V7DTPC.js";import{E as C}from"./chunk-XO6GV6O7.js";import"./chunk-I643NVMZ.js";import"./chunk-K644WUOE.js";import"./chunk-3TV3CVNP.js";import"./chunk-S4YBFFFY.js";import"./chunk-AN7CPDBU.js";import"./chunk-PGZZKX5K.js";import"./chunk-CJUVMNDB.js";import"./chunk-7UXQJJFZ.js";import"./chunk-3LWZFXLN.js";import"./chunk-2MDJ3JE5.js";import"./chunk-UCDQJB53.js";import"./chunk-RUMGXXVJ.js";import"./chunk-CBOIDISB.js";import"./chunk-TSBXPDUQ.js";import"./chunk-KVIGHX2B.js";import"./chunk-VILB5M4X.js";import"./chunk-5YQZEJBM.js";import"./chunk-7LHRBNSH.js";import"./chunk-FAMPOY6L.js";import"./chunk-POX2ELNS.js";import"./chunk-BBA64POP.js";import"./chunk-ZVLZLBDA.js";import"./chunk-XI2NNZBS.js";import"./chunk-YJRO7NXN.js";import{a as r}from"./chunk-BYHBBZIO.js";import{h as R}from"./chunk-LDLS2VL2.js";import"./chunk-3VUPVXAV.js";import"./chunk-VGEH7B6S.js";import"./chunk-PY3AC5KD.js";import"./chunk-DSPLGTQI.js";import"./chunk-VPT5MFDG.js";import"./chunk-CILM5XMH.js";import"./chunk-WOT6VMZA.js";function k(t,d){let n,a=0,m=-1,l,i=!1,y=()=>{if(i)throw new r("CLOSED","Native host was destroyed");if(!t.nativeModule)throw new r("CAPABILITY_UNAVAILABLE","Link IndianaBridge and supply nativeModule");return t.nativeModule},o=()=>new r("IDENTITY_CHANGED","Customer identity changed during the native operation"),h=d.subscribeIdentity(()=>{a++,m=-1;let e=a;n&&t.nativeModule&&n.then(c=>t.nativeModule.reset(c,e)).catch(()=>{})}),I=t.nativeEvents?.(e=>{!n||!t.nativeModule||typeof e?.requestId!="string"||(async()=>{let c=await n;if(e.instanceId!==c)return;if(e.kind==="credential"){let w=a,f=null;try{if(!i&&e.revision===w){let N=await d.access();!i&&a===w&&(f=N)}}finally{await t.nativeModule.provideCredential(c,e.requestId,f)}return}let s=!1,u=a;try{if(i||e.revision!==u||!t.onNativeAction)throw o();await t.onNativeAction(e.action),s=!i&&a===u}finally{await t.nativeModule.acknowledge(c,e.requestId,s)}})().catch(()=>{})});async function p(e,c={}){let s=y();if(d.snapshot()&&!t.nativeEvents)throw new r("CAPABILITY_UNAVAILABLE","Supply nativeEvents to share credential refresh with the native host");let u=a,w=await d.access();if(i||a!==u)throw o();if(!n){let v=s.create(JSON.stringify({baseUrl:t.baseUrl??"https://api.longplayai.com",scope:t.scope,timeout:(t.timeoutMs??15e3)/1e3,credentialEvents:!!t.nativeEvents}));n=v,v.catch(()=>{n===v&&(n=void 0)})}let f=await n;if(i||a!==u)throw o();if(m!==u){if(!l||l.epoch!==u){let O=(async()=>{if(await s.identify(f,JSON.stringify({revision:u,credentials:w})),i||a!==u)throw await s.reset(f,u),o();m=u})();l={epoch:u,task:O}}let v=l;try{await v.task}finally{l===v&&(l=void 0)}}let N=await s.invoke(f,e,JSON.stringify(c));if(i||a!==u)throw o();try{return JSON.parse(N)}catch{throw new r("INVALID_RESPONSE","Native host returned invalid JSON")}}async function g(e,c){let s=await p(e,c);if(!s||typeof s!="object"||Array.isArray(s)||s.status!=="complete"&&s.status!=="dismissed")throw new r("INVALID_RESPONSE","Native presentation returned an invalid result");return s}return{showFunnel(e){return g("showFunnel",{runToken:e})},showPaywall(e){return g("showPaywall",e)},showContent(e){return g("showContent",e)},purchaseSubscription(e,c){return p("purchaseSubscription",{operationId:e,accepted:c})},switchSubscription(e,c){return p("switchSubscription",{operationId:e,accepted:c})},restorePurchases(){return p("restorePurchases")},manageSubscriptions(e){return p("manageSubscriptions",e?{productId:e}:{})},async dismiss(){a++,m=-1,n&&await y().reset(await n,a)},async destroy(){i||(i=!0,a++,h(),I?.(),n&&t.nativeModule&&await t.nativeModule.destroy(await n))}}}var M=P.trackUsage.request.shape.command,U=P.trackUsage.response;function F(t){let d=R.parse(t.scope),n=S({...t,scope:d}),a={...t,scope:d,session:n.session},m=k(t,n.session),l=0,i=!1;n.subscribeIdentity(()=>{l++});let y=()=>{if(i)throw new r("CLOSED","SDK client was destroyed");let o=n.session.peek();if(!o)throw new r("UNAUTHENTICATED","Identify the Customer first");return o};return{...n,native:m,async destroy(){i||(i=!0,l++,n.destroy(),await m.destroy())},funnel(){return E({...a,customerToken:y()})},resumeFunnel(o){return y(),C({...a,runToken:o})},paywall(o){return A(a,{...o,customerToken:y()})},async trackUsage(o){if(y(),!t.usageReporter)throw new r("INVALID_REQUEST","Configure your authenticated backend usageReporter");let h=M.parse(o),I=l,p;try{p=await t.usageReporter(h)}catch(e){throw I!==l?new r("IDENTITY_CHANGED","Customer identity changed during usage reporting"):e}if(I!==l)throw new r("IDENTITY_CHANGED","Customer identity changed during usage reporting");let g=U.parse(p);if(g.scope.projectId!==d.projectId||g.scope.environment!==d.environment)throw new r("INVALID_RESPONSE","Usage response scope differs");return g}}}export{r as LongplayError,x as createConfigurationSync,b as createFeatureClient,T as createFunnelProcess,L as createLocalFunnelClient,F as createLongplayReactNative};
1
+ import{b as S,c as E,d as T}from"./chunk-PPXVRQAG.js";import"./chunk-PVMGYRGE.js";import{a as A}from"./chunk-ZQY7OYHM.js";import{e as P}from"./chunk-JXWZS4UM.js";import"./chunk-YMRWDMIL.js";import{h as b,i as x,k as L}from"./chunk-PB34FLPJ.js";import{E as C}from"./chunk-MZRDAMFQ.js";import"./chunk-73UFNVEP.js";import"./chunk-CAE4KIZN.js";import"./chunk-CJUODAOF.js";import"./chunk-XHZH3E4G.js";import"./chunk-LFMAFY3P.js";import"./chunk-6HKQILBV.js";import"./chunk-EACC667P.js";import"./chunk-BX2MSRA4.js";import"./chunk-LOBZ45T3.js";import"./chunk-J4RM5GQP.js";import"./chunk-ADTZEBQF.js";import"./chunk-OV46DXRX.js";import"./chunk-M4P6TGBU.js";import"./chunk-GGZG56GR.js";import"./chunk-NL7AXMUA.js";import"./chunk-VILB5M4X.js";import"./chunk-ANJPFGFN.js";import"./chunk-TS26DZNO.js";import"./chunk-L64BS65O.js";import"./chunk-QGKROSRD.js";import"./chunk-RRZZUIFM.js";import"./chunk-RJT764B2.js";import"./chunk-BKBWGPNR.js";import"./chunk-NNJVMJUG.js";import{a as r}from"./chunk-WE55LJEN.js";import{h as R}from"./chunk-OZK47BUU.js";import"./chunk-3VUPVXAV.js";import"./chunk-LBDLWHBY.js";import"./chunk-5YBTU4KS.js";import"./chunk-DSPLGTQI.js";import"./chunk-HMJTABQ5.js";import"./chunk-DLRCJF6U.js";import"./chunk-WOT6VMZA.js";function k(t,d){let n,a=0,m=-1,l,i=!1,y=()=>{if(i)throw new r("CLOSED","Native host was destroyed");if(!t.nativeModule)throw new r("CAPABILITY_UNAVAILABLE","Link IndianaBridge and supply nativeModule");return t.nativeModule},o=()=>new r("IDENTITY_CHANGED","Customer identity changed during the native operation"),h=d.subscribeIdentity(()=>{a++,m=-1;let e=a;n&&t.nativeModule&&n.then(c=>t.nativeModule.reset(c,e)).catch(()=>{})}),I=t.nativeEvents?.(e=>{!n||!t.nativeModule||typeof e?.requestId!="string"||(async()=>{let c=await n;if(e.instanceId!==c)return;if(e.kind==="credential"){let w=a,f=null;try{if(!i&&e.revision===w){let N=await d.access();!i&&a===w&&(f=N)}}finally{await t.nativeModule.provideCredential(c,e.requestId,f)}return}let s=!1,u=a;try{if(i||e.revision!==u||!t.onNativeAction)throw o();await t.onNativeAction(e.action),s=!i&&a===u}finally{await t.nativeModule.acknowledge(c,e.requestId,s)}})().catch(()=>{})});async function p(e,c={}){let s=y();if(d.snapshot()&&!t.nativeEvents)throw new r("CAPABILITY_UNAVAILABLE","Supply nativeEvents to share credential refresh with the native host");let u=a,w=await d.access();if(i||a!==u)throw o();if(!n){let v=s.create(JSON.stringify({baseUrl:t.baseUrl??"https://api.longplayai.com",scope:t.scope,timeout:(t.timeoutMs??15e3)/1e3,credentialEvents:!!t.nativeEvents}));n=v,v.catch(()=>{n===v&&(n=void 0)})}let f=await n;if(i||a!==u)throw o();if(m!==u){if(!l||l.epoch!==u){let O=(async()=>{if(await s.identify(f,JSON.stringify({revision:u,credentials:w})),i||a!==u)throw await s.reset(f,u),o();m=u})();l={epoch:u,task:O}}let v=l;try{await v.task}finally{l===v&&(l=void 0)}}let N=await s.invoke(f,e,JSON.stringify(c));if(i||a!==u)throw o();try{return JSON.parse(N)}catch{throw new r("INVALID_RESPONSE","Native host returned invalid JSON")}}async function g(e,c){let s=await p(e,c);if(!s||typeof s!="object"||Array.isArray(s)||s.status!=="complete"&&s.status!=="dismissed")throw new r("INVALID_RESPONSE","Native presentation returned an invalid result");return s}return{showFunnel(e){return g("showFunnel",{runToken:e})},showPaywall(e){return g("showPaywall",e)},showContent(e){return g("showContent",e)},purchaseSubscription(e,c){return p("purchaseSubscription",{operationId:e,accepted:c})},switchSubscription(e,c){return p("switchSubscription",{operationId:e,accepted:c})},restorePurchases(){return p("restorePurchases")},manageSubscriptions(e){return p("manageSubscriptions",e?{productId:e}:{})},async dismiss(){a++,m=-1,n&&await y().reset(await n,a)},async destroy(){i||(i=!0,a++,h(),I?.(),n&&t.nativeModule&&await t.nativeModule.destroy(await n))}}}var M=P.trackUsage.request.shape.command,U=P.trackUsage.response;function F(t){let d=R.parse(t.scope),n=S({...t,scope:d}),a={...t,scope:d,session:n.session},m=k(t,n.session),l=0,i=!1;n.subscribeIdentity(()=>{l++});let y=()=>{if(i)throw new r("CLOSED","SDK client was destroyed");let o=n.session.peek();if(!o)throw new r("UNAUTHENTICATED","Identify the Customer first");return o};return{...n,native:m,async destroy(){i||(i=!0,l++,n.destroy(),await m.destroy())},funnel(){return E({...a,customerToken:y()})},resumeFunnel(o){return y(),C({...a,runToken:o})},paywall(o){return A(a,{...o,customerToken:y()})},async trackUsage(o){if(y(),!t.usageReporter)throw new r("INVALID_REQUEST","Configure your authenticated backend usageReporter");let h=M.parse(o),I=l,p;try{p=await t.usageReporter(h)}catch(e){throw I!==l?new r("IDENTITY_CHANGED","Customer identity changed during usage reporting"):e}if(I!==l)throw new r("IDENTITY_CHANGED","Customer identity changed during usage reporting");let g=U.parse(p);if(g.scope.projectId!==d.projectId||g.scope.environment!==d.environment)throw new r("INVALID_RESPONSE","Usage response scope differs");return g}}}export{r as LongplayError,x as createConfigurationSync,b as createFeatureClient,T as createFunnelProcess,L as createLocalFunnelClient,F as createLongplayReactNative};
@@ -0,0 +1 @@
1
+ import{a,b,c,d,e,f,g,h,i}from"./chunk-UEKKQHUZ.js";import"./chunk-QAGK2SLZ.js";import"./chunk-QGKROSRD.js";import"./chunk-RRZZUIFM.js";import"./chunk-RJT764B2.js";import"./chunk-BKBWGPNR.js";import"./chunk-NNJVMJUG.js";import"./chunk-WE55LJEN.js";import"./chunk-OZK47BUU.js";import"./chunk-5YBTU4KS.js";import"./chunk-DSPLGTQI.js";import"./chunk-HMJTABQ5.js";import"./chunk-DLRCJF6U.js";import"./chunk-WOT6VMZA.js";export{f as formatCustomerDecimal,b as hostedRendererScript,a as hostedRendererShell,d as inspectCustomHtml,i as mountScreenPreview,h as preparePopup,e as prepareScreen,c as sanitizeCustomHtml,g as showPopup};
package/dist/server.d.ts CHANGED
@@ -1,15 +1,15 @@
1
- import { F as FoundationApi, I as InvoiceModeParams } from './api-D0Qu0isy.js';
2
- import { X as IndianaServerOptions, v as IndianaError, Y as FunnelProcessSuppression, Z as FunnelProcessCommand, T as FunnelProcessResponse, C as CustomerSession, Q as FunnelProcessOpenInput, V as FunnelProcessMutation, x as PaywallStartInput, P as PaywallSession, n as FeatureClientOptions, R as RemoteFeatureResult } from './funnel-local-client-DzRzPX4x.js';
3
- export { m as FeatureClient, c as FunnelStartInput, L as LocalFunnelClient, u as LocalFunnelClientOptions, A as createFeatureClient, _ as createFunnelStartClient, D as createLocalFunnelClient } from './funnel-local-client-DzRzPX4x.js';
1
+ import { F as FoundationApi, I as InvoiceModeParams } from './api-1Tplv-7M.js';
2
+ import { X as IndianaServerOptions, v as IndianaError, Y as FunnelProcessSuppression, Z as FunnelProcessCommand, T as FunnelProcessResponse, C as CustomerSession, Q as FunnelProcessOpenInput, V as FunnelProcessMutation, x as PaywallStartInput, P as PaywallSession, n as FeatureClientOptions, R as RemoteFeatureResult } from './funnel-local-client-Fxsyl7rh.js';
3
+ export { m as FeatureClient, d as FunnelStartInput, L as LocalFunnelClient, u as LocalFunnelClientOptions, A as createFeatureClient, _ as createFunnelStartClient, D as createLocalFunnelClient } from './funnel-local-client-Fxsyl7rh.js';
4
4
  import * as zod from 'zod';
5
5
  import { z } from 'zod';
6
- import { S as StackNode } from './screen-CJepeiBT.js';
7
- import { C as ConfigurationSync } from './configuration-sync-DObsuVof.js';
8
- export { c as createConfigurationSync } from './configuration-sync-DObsuVof.js';
6
+ import { S as StackNode } from './screen-D2bUmJ4M.js';
7
+ import { C as ConfigurationSync } from './configuration-sync-DeWWW5za.js';
8
+ export { c as createConfigurationSync } from './configuration-sync-DeWWW5za.js';
9
9
  import { J as JsonValue, E as EvaluationContext, s as stickyAssignmentDocumentSchema, F as FeatureResult } from './growth-rules-B4YYy64R.js';
10
10
  import { d as FunnelLocalConfiguration, f as MerchantBridgeCommand, M as MerchantBridgeManifest, m as merchantBridgeOperationInputSchema } from './funnel-node-evaluation-CRRTh1je.js';
11
11
  export { F as FunnelNodeEvaluationContext, g as MerchantRequirementCheckInput, h as MerchantRequirementCheckResult, i as entitlementRequirementDigest, e as evaluateFunnelNode } from './funnel-node-evaluation-CRRTh1je.js';
12
- export { d as AiPricingOptions, b as AiTokenQuote, a as AiTokenUsage, A as AiUsageContext, e as AiUsageMiddlewareOptions, f as AiUsageRecord, g as aiPriceSnapshotSchema, h as aiTokenQuoteSchema, c as createAiPricing, i as createAiUsageMiddleware, j as createConfiguredAiPricing } from './ai-usage-gcDQqLb2.js';
12
+ export { d as AiPricingOptions, b as AiTokenQuote, a as AiTokenUsage, A as AiUsageContext, e as AiUsageMiddlewareOptions, f as AiUsageRecord, g as aiPriceSnapshotSchema, h as aiTokenQuoteSchema, c as createAiPricing, i as createAiUsageMiddleware, j as createConfiguredAiPricing } from './ai-usage-DBcYB8ix.js';
13
13
  import 'zod/v4';
14
14
  import '@ai-sdk/provider';
15
15
 
package/dist/server.js CHANGED
@@ -1,4 +1,4 @@
1
- import{a as pn}from"./chunk-L66EXWTK.js";import{a as I}from"./chunk-USM6HOXG.js";import{a as fn,b as hn,c as gn,d as yn}from"./chunk-EDV6ZNPQ.js";import{a as xt}from"./chunk-S6MXUFVF.js";import{a as Ue,b as Ve,c as qe,d as He,e as m}from"./chunk-KXSZTBAG.js";import"./chunk-JRHJO4BR.js";import{a as Te,b as ae,c as yt,d as It,e as wt,f as xe,g as vt,h as Me,i as dn,j as ln,k as mn}from"./chunk-W3V7DTPC.js";import{B as V,C as N,d as ft,e as ht,k as gt,l as z,m as St,p as Ct,q as Rt,r as bt,s as At,t as Ot,y as pe,z as Tt}from"./chunk-XO6GV6O7.js";import"./chunk-I643NVMZ.js";import{c as h}from"./chunk-K644WUOE.js";import"./chunk-3TV3CVNP.js";import{a as Et,b as _e}from"./chunk-S4YBFFFY.js";import"./chunk-AN7CPDBU.js";import"./chunk-PGZZKX5K.js";import{e as at}from"./chunk-CJUVMNDB.js";import{B as pt,C as de,D as Z,E as lt,J as mt,a as et,e as q,j as Re,k as st,l as ct,q as ut,r as dt,s as be,t as Ae}from"./chunk-7UXQJJFZ.js";import{b as Oe}from"./chunk-3LWZFXLN.js";import{e as ve,i as Ze,l as it}from"./chunk-2MDJ3JE5.js";import"./chunk-UCDQJB53.js";import"./chunk-RUMGXXVJ.js";import"./chunk-CBOIDISB.js";import"./chunk-TSBXPDUQ.js";import{A as W,B as oe,C as tt,D as Se,E as ie,G as se,H as Ce,M as j,O as ce,P as nt,R as Ee,S as rt,T as ot,f as Ge,g as je,j as we,r as ze,s as Ke,u as an,v as sn,y as cn,z as X}from"./chunk-KVIGHX2B.js";import"./chunk-VILB5M4X.js";import"./chunk-5YQZEJBM.js";import"./chunk-7LHRBNSH.js";import{a as Ne,b as Le}from"./chunk-FAMPOY6L.js";import{o as ue}from"./chunk-POX2ELNS.js";import"./chunk-BBA64POP.js";import{i as un,k as $e,l as Qe,m as Je}from"./chunk-ZVLZLBDA.js";import{c as Ie}from"./chunk-XI2NNZBS.js";import{e as Xe,h as We}from"./chunk-YJRO7NXN.js";import{a as c}from"./chunk-BYHBBZIO.js";import{h as Y}from"./chunk-LDLS2VL2.js";import"./chunk-3VUPVXAV.js";import"./chunk-VGEH7B6S.js";import{b as u}from"./chunk-PY3AC5KD.js";import"./chunk-DSPLGTQI.js";import{a as Ye}from"./chunk-VPT5MFDG.js";import"./chunk-CILM5XMH.js";import"./chunk-WOT6VMZA.js";var _t=4,Mt=[...tt,"requirement_checks","native_offers","preparations","benefit_claims","authorizations","business_results","checkout_termination"],In=u.enum(Mt),ee=(e,n)=>u.array(e).max(n).refine(t=>new Set(t).size===t.length,"Declarations must be unique"),ke=u.strictObject({...se.shape,bridgeVersion:u.literal(_t),capabilities:ee(In,Mt.length),checkKinds:ee(u.enum(["access","metered","credit"]),3),preparationActions:ee(u.enum(["purchase","subscription_change","refund"]),3),authorizationKinds:ee(u.enum(["auto_topup"]),1),nextActionTypes:ee(u.enum(["redirect","authenticate"]),2),resultEvents:ee(u.enum(["benefit.claimed","authorization.updated"]),2)}).superRefine((e,n)=>{e.capabilities.includes("catalog")!==(e.catalog!=="none")&&n.addIssue({code:"custom",path:["catalog"],message:"Catalog declaration differs from its capability"}),(e.capabilities.includes("billing_records")!==e.billingEvents.length>0||new Set(e.billingEvents).size!==e.billingEvents.length)&&n.addIssue({code:"custom",path:["billingEvents"],message:"Declare unique supported billing events"});let t=r=>e.capabilities.includes(r),o=(r,a)=>n.addIssue({code:"custom",path:[r],message:a});t("requirement_checks")!==e.checkKinds.length>0&&o("checkKinds","Declare the supported Check kinds"),t("preparations")!==e.preparationActions.length>0&&o("preparationActions","Declare the supported preparation actions"),t("authorizations")!==e.authorizationKinds.length>0&&o("authorizationKinds","Declare the supported authorization kinds"),t("business_results")!==e.resultEvents.length>0&&o("resultEvents","Declare the supported non-financial results");for(let[r,a,s]of[["purchases","purchase","purchase.completed"],["subscription_changes","subscription_change","subscription.change.completed"],["refunds","refund","refund.updated"]])t(r)&&(!t("operation_status")||!t("billing_records")||!t("preparations")||!e.preparationActions.includes(a)||!e.billingEvents.includes(s))&&o("capabilities",`${r} requires preparation, original lookup and its billing result`);t("purchases")&&!e.billingEvents.includes("purchase.closed")&&o("billingEvents","Purchase execution requires its terminal closure result"),t("checkout_termination")&&(!t("operation_status")||!t("billing_records")||!e.billingEvents.includes("purchase.closed"))&&o("capabilities","Checkout termination requires original lookup and purchase.closed"),t("subscription_changes")&&!e.billingEvents.includes("subscription.change.closed")&&o("billingEvents","Subscription change execution requires its terminal closure result");for(let[r,a]of[["benefit_claims","benefit.claimed"],["authorizations","authorization.updated"]])t(r)&&(!t("operation_status")||!t("business_results")||!e.resultEvents.includes(a))&&o("capabilities",`${r} requires original lookup and its non-financial result`)}),K={"bridge.ping":u.strictObject({challenge:u.uuid()}),"bridge.describe":u.strictObject({}),"requirement.check":$e,"operation.prepare":ze,"benefit.claim":Ue,"operation.read":qe,"purchase.terminate":j},wn={"bridge.ping":u.strictObject({challenge:u.uuid()}),"bridge.describe":ke,"requirement.check":Qe,"operation.prepare":Ke,"benefit.claim":Ve,"operation.read":He,"purchase.terminate":j.extend({outcome:u.enum(["requested","already_paid"])})},Gn=u.enum(["bridge.ping","bridge.describe","requirement.check","operation.prepare","benefit.claim","operation.read","purchase.terminate"]);function $(e,n){return u.strictObject({bridgeVersion:u.literal(_t),requestId:u.uuid(),scope:Ce,command:u.literal(e),data:n})}var kt=u.discriminatedUnion("command",[$("bridge.ping",K["bridge.ping"]),$("bridge.describe",K["bridge.describe"]),$("requirement.check",K["requirement.check"]),$("operation.prepare",K["operation.prepare"]),$("benefit.claim",K["benefit.claim"]),$("operation.read",K["operation.read"]),$("purchase.terminate",K["purchase.terminate"])]),Be=u.strictObject({code:u.string().regex(/^MERCHANT_BRIDGE_[A-Z_]+$/),message:u.string().min(1).max(500),retryable:u.boolean(),recovery:u.string().min(1).max(80),effect:u.enum(["none","unknown"])}).refine(e=>e.effect!=="unknown"||!e.retryable&&e.recovery==="recover_operation","Unknown effects require original-operation recovery");function Bt(e){let n={bridgeVersion:u.literal(4),requestId:u.uuid(),scope:Ce,command:u.literal(e)};return u.union([u.strictObject({...n,data:wn[e]}),u.strictObject({...n,error:Be})])}var Pt="X-Indiana-Bridge-Signature",Q="X-Indiana-Bridge-Key-Id";function vn(e){return new TextEncoder().encode(e)}function Dt(e){return Uint8Array.from(atob(e.replaceAll("-","+").replaceAll("_","/")),n=>n.charCodeAt(0))}function Ft(e,n,t,o){return vn(`indiana-merchant-bridge:${o}
1
+ import{a as pn}from"./chunk-MRL7XUBV.js";import{a as I}from"./chunk-36VNAOG6.js";import{a as fn,b as hn,c as gn,d as yn}from"./chunk-IN32NWRI.js";import{a as xt}from"./chunk-ZQY7OYHM.js";import{a as Ue,b as Ve,c as qe,d as He,e as m}from"./chunk-JXWZS4UM.js";import"./chunk-YMRWDMIL.js";import{a as Te,b as ae,c as yt,d as It,e as wt,f as xe,g as vt,h as Me,i as dn,j as ln,k as mn}from"./chunk-PB34FLPJ.js";import{B as V,C as N,d as ft,e as ht,k as gt,l as z,m as St,p as Ct,q as Rt,r as bt,s as At,t as Ot,y as pe,z as Tt}from"./chunk-MZRDAMFQ.js";import"./chunk-73UFNVEP.js";import{c as h}from"./chunk-CAE4KIZN.js";import"./chunk-CJUODAOF.js";import{a as Et,b as _e}from"./chunk-XHZH3E4G.js";import"./chunk-LFMAFY3P.js";import"./chunk-6HKQILBV.js";import{e as at}from"./chunk-EACC667P.js";import{B as pt,C as de,D as Z,E as lt,J as mt,a as et,e as q,j as Re,k as st,l as ct,q as ut,r as dt,s as be,t as Ae}from"./chunk-BX2MSRA4.js";import{b as Oe}from"./chunk-LOBZ45T3.js";import{e as ve,i as Ze,l as it}from"./chunk-J4RM5GQP.js";import"./chunk-ADTZEBQF.js";import"./chunk-OV46DXRX.js";import"./chunk-M4P6TGBU.js";import"./chunk-GGZG56GR.js";import{A as W,B as oe,C as tt,D as Se,E as ie,G as se,H as Ce,M as j,O as ce,P as nt,R as Ee,S as rt,T as ot,f as Ge,g as je,j as we,r as ze,s as Ke,u as an,v as sn,y as cn,z as X}from"./chunk-NL7AXMUA.js";import"./chunk-VILB5M4X.js";import"./chunk-ANJPFGFN.js";import"./chunk-TS26DZNO.js";import{a as Ne,b as Le}from"./chunk-L64BS65O.js";import{o as ue}from"./chunk-QGKROSRD.js";import"./chunk-RRZZUIFM.js";import{i as un,k as $e,l as Qe,m as Je}from"./chunk-RJT764B2.js";import{c as Ie}from"./chunk-BKBWGPNR.js";import{e as Xe,h as We}from"./chunk-NNJVMJUG.js";import{a as c}from"./chunk-WE55LJEN.js";import{h as Y}from"./chunk-OZK47BUU.js";import"./chunk-3VUPVXAV.js";import"./chunk-LBDLWHBY.js";import{b as u}from"./chunk-5YBTU4KS.js";import"./chunk-DSPLGTQI.js";import{a as Ye}from"./chunk-HMJTABQ5.js";import"./chunk-DLRCJF6U.js";import"./chunk-WOT6VMZA.js";var _t=4,Mt=[...tt,"requirement_checks","native_offers","preparations","benefit_claims","authorizations","business_results","checkout_termination"],In=u.enum(Mt),ee=(e,n)=>u.array(e).max(n).refine(t=>new Set(t).size===t.length,"Declarations must be unique"),ke=u.strictObject({...se.shape,bridgeVersion:u.literal(_t),capabilities:ee(In,Mt.length),checkKinds:ee(u.enum(["access","metered","credit"]),3),preparationActions:ee(u.enum(["purchase","subscription_change","refund"]),3),authorizationKinds:ee(u.enum(["auto_topup"]),1),nextActionTypes:ee(u.enum(["redirect","authenticate"]),2),resultEvents:ee(u.enum(["benefit.claimed","authorization.updated"]),2)}).superRefine((e,n)=>{e.capabilities.includes("catalog")!==(e.catalog!=="none")&&n.addIssue({code:"custom",path:["catalog"],message:"Catalog declaration differs from its capability"}),(e.capabilities.includes("billing_records")!==e.billingEvents.length>0||new Set(e.billingEvents).size!==e.billingEvents.length)&&n.addIssue({code:"custom",path:["billingEvents"],message:"Declare unique supported billing events"});let t=r=>e.capabilities.includes(r),o=(r,a)=>n.addIssue({code:"custom",path:[r],message:a});t("requirement_checks")!==e.checkKinds.length>0&&o("checkKinds","Declare the supported Check kinds"),t("preparations")!==e.preparationActions.length>0&&o("preparationActions","Declare the supported preparation actions"),t("authorizations")!==e.authorizationKinds.length>0&&o("authorizationKinds","Declare the supported authorization kinds"),t("business_results")!==e.resultEvents.length>0&&o("resultEvents","Declare the supported non-financial results");for(let[r,a,s]of[["purchases","purchase","purchase.completed"],["subscription_changes","subscription_change","subscription.change.completed"],["refunds","refund","refund.updated"]])t(r)&&(!t("operation_status")||!t("billing_records")||!t("preparations")||!e.preparationActions.includes(a)||!e.billingEvents.includes(s))&&o("capabilities",`${r} requires preparation, original lookup and its billing result`);t("purchases")&&!e.billingEvents.includes("purchase.closed")&&o("billingEvents","Purchase execution requires its terminal closure result"),t("checkout_termination")&&(!t("operation_status")||!t("billing_records")||!e.billingEvents.includes("purchase.closed"))&&o("capabilities","Checkout termination requires original lookup and purchase.closed"),t("subscription_changes")&&!e.billingEvents.includes("subscription.change.closed")&&o("billingEvents","Subscription change execution requires its terminal closure result");for(let[r,a]of[["benefit_claims","benefit.claimed"],["authorizations","authorization.updated"]])t(r)&&(!t("operation_status")||!t("business_results")||!e.resultEvents.includes(a))&&o("capabilities",`${r} requires original lookup and its non-financial result`)}),K={"bridge.ping":u.strictObject({challenge:u.uuid()}),"bridge.describe":u.strictObject({}),"requirement.check":$e,"operation.prepare":ze,"benefit.claim":Ue,"operation.read":qe,"purchase.terminate":j},wn={"bridge.ping":u.strictObject({challenge:u.uuid()}),"bridge.describe":ke,"requirement.check":Qe,"operation.prepare":Ke,"benefit.claim":Ve,"operation.read":He,"purchase.terminate":j.extend({outcome:u.enum(["requested","already_paid"])})},Gn=u.enum(["bridge.ping","bridge.describe","requirement.check","operation.prepare","benefit.claim","operation.read","purchase.terminate"]);function $(e,n){return u.strictObject({bridgeVersion:u.literal(_t),requestId:u.uuid(),scope:Ce,command:u.literal(e),data:n})}var kt=u.discriminatedUnion("command",[$("bridge.ping",K["bridge.ping"]),$("bridge.describe",K["bridge.describe"]),$("requirement.check",K["requirement.check"]),$("operation.prepare",K["operation.prepare"]),$("benefit.claim",K["benefit.claim"]),$("operation.read",K["operation.read"]),$("purchase.terminate",K["purchase.terminate"])]),Be=u.strictObject({code:u.string().regex(/^MERCHANT_BRIDGE_[A-Z_]+$/),message:u.string().min(1).max(500),retryable:u.boolean(),recovery:u.string().min(1).max(80),effect:u.enum(["none","unknown"])}).refine(e=>e.effect!=="unknown"||!e.retryable&&e.recovery==="recover_operation","Unknown effects require original-operation recovery");function Bt(e){let n={bridgeVersion:u.literal(4),requestId:u.uuid(),scope:Ce,command:u.literal(e)};return u.union([u.strictObject({...n,data:wn[e]}),u.strictObject({...n,error:Be})])}var Pt="X-Indiana-Bridge-Signature",Q="X-Indiana-Bridge-Key-Id";function vn(e){return new TextEncoder().encode(e)}function Dt(e){return Uint8Array.from(atob(e.replaceAll("-","+").replaceAll("_","/")),n=>n.charCodeAt(0))}function Ft(e,n,t,o){return vn(`indiana-merchant-bridge:${o}
2
2
  ${n}
3
3
  POST
4
4
  ${W}
@@ -1 +1 @@
1
- import{b as a,c as b}from"./chunk-OJM6ORHE.js";import"./chunk-J6KIN4RH.js";import"./chunk-WOT6VMZA.js";export{b as applyVisualVariation,a as safeVisualMutation};
1
+ import{b as a,c as b}from"./chunk-VJIONC4S.js";import"./chunk-J6KIN4RH.js";import"./chunk-WOT6VMZA.js";export{b as applyVisualVariation,a as safeVisualMutation};
package/dist/visual.js CHANGED
@@ -1 +1 @@
1
- import{a as pe,c as fe}from"./chunk-OJM6ORHE.js";import{b as le}from"./chunk-J6KIN4RH.js";import{a as Ve,b as ce,c as de,d as ue}from"./chunk-SLUA7ABW.js";import{a as J,b as F,c as ge,e as me}from"./chunk-PZZLYHKR.js";import{a as re,b as ae,c as se,d as oe}from"./chunk-FKC7TJWM.js";import"./chunk-3VUPVXAV.js";import"./chunk-VGEH7B6S.js";import{b as o}from"./chunk-PY3AC5KD.js";import"./chunk-DSPLGTQI.js";import{c as te,e as ie,g as M}from"./chunk-VPT5MFDG.js";import"./chunk-CILM5XMH.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:le(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=se(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=re(e.deviceIdCookie??"indiana_did"),T=ae(),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(de(`${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=oe(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=ue(()=>{i&&!t&&V()});return{async start(){if(!(i||t)){i=!0,e.appManifestRelease&&(B=ce(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-VJIONC4S.js";import{b as le}from"./chunk-J6KIN4RH.js";import{a as Ve,b as ce,c as de,d as ue}from"./chunk-SLUA7ABW.js";import{a as J,b as F,c as ge,e as me}from"./chunk-SK5JZ7HA.js";import{a as re,b as ae,c as se,d as oe}from"./chunk-R2L227PQ.js";import"./chunk-3VUPVXAV.js";import"./chunk-LBDLWHBY.js";import{b as o}from"./chunk-5YBTU4KS.js";import"./chunk-DSPLGTQI.js";import{c as te,e as ie,g as M}from"./chunk-HMJTABQ5.js";import"./chunk-DLRCJF6U.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:le(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=se(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=re(e.deviceIdCookie??"indiana_did"),T=ae(),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(de(`${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=oe(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=ue(()=>{i&&!t&&V()});return{async start(){if(!(i||t)){i=!0,e.appManifestRelease&&(B=ce(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.52",
3
+ "version": "0.10.54",
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{a,b}from"./chunk-S4YBFFFY.js";import"./chunk-ZVLZLBDA.js";import"./chunk-XI2NNZBS.js";import"./chunk-BYHBBZIO.js";import"./chunk-LDLS2VL2.js";import"./chunk-PY3AC5KD.js";import"./chunk-CILM5XMH.js";import"./chunk-WOT6VMZA.js";export{a as validateEntitlementCheck,b as validateResourceCheck};
@@ -1 +0,0 @@
1
- import{a as A}from"./chunk-W32FI2A2.js";import{b as D,e as L}from"./chunk-SLUA7ABW.js";import{d as T}from"./chunk-FKC7TJWM.js";import{a as R}from"./chunk-DSPLGTQI.js";import{b as O}from"./chunk-VPT5MFDG.js";var m=new WeakMap;function B(e){let o=e.view,n=o?.paywall?.resolution;if(!o||!["running","waiting"].includes(o.status)||o.stopped||!n||"document"in n||!e.resolvePaywall||e.identitySignal?.aborted)return;let a=JSON.stringify(n);if(m.get(e)?.key===a)return;let i=JSON.parse(a),c=e.identitySignal,u=Promise.resolve().then(async()=>{c?.throwIfAborted();let v=await e.resolvePaywall(i);return c?.throwIfAborted(),v}),f={key:a,content:u};return m.set(e,f),u.catch(()=>{}),()=>{m.get(e)===f&&m.delete(e)}}function Q(e,o){let n=m.get(e);return m.delete(e),n?.key===JSON.stringify(o)?n.content:e.resolvePaywall(o)}function re(e){if(!e.client.pageExperiments)throw new Error("The Run controller does not support page experiments");let o=e.client.pageExperiments.bind(e.client),n=!1,a=!1,i=0,c=!1,u=!1,f="",v=()=>{let t=e.client.view;return JSON.stringify([t?.id,t?.source.versionId,t?.visit,t?.revision,t?.status,t?.stopped])},s=new Map,x=new Set,q={},d=new Map,U=D(e.appManifestRelease),C=()=>{for(let t of s.values())t.effect.revert();s.clear()},g=()=>{C();for(let t of d.values())t();d.clear()};function E(t){if(n||x.has(t))return;x.add(t);let h=i;o(e.appManifestRelease,[t]).catch(k=>{x.delete(t),!n&&h===i&&R(e.onError,k)})}async function w(){if(n)return;f=v();let t=e.client.view;if(!t||t.stopped||!["running","waiting"].includes(t.status)){i++,g();return}if(document.visibilityState==="hidden")return;if(c){u=!0;return}c=!0;let h=++i,k=`${t.id}:${t.visit}:${t.revision}`,W=location.href;try{let[P,{applyVisualVariation:j}]=await Promise.all([o(e.appManifestRelease),import("./visual-dom-5LUN4AHO.js")]),p=e.client.view;if(n||h!==i||!p||p.stopped||!["running","waiting"].includes(p.status)||`${p.id}:${p.visit}:${p.revision}`!==k||location.href!==W)return;let $=new Set,I=new Set;for(let r of P.assignments){let l=`${P.payload.environmentId}:${r.experimentKey}`;if(I.add(l),d.has(l)||d.set(l,L(l,q)),!!r.inExperiment)for(let y of P.payload.experiments){if(y.key!==r.experimentKey||!O(location.href,y.urlPatterns??[]))continue;let z=y.meta?.findIndex(F=>F.key===r.variationKey)??-1,S=y.variations[z];if(!S?.renderGuard)continue;let b=r.receiptId+":"+y.changeId,J=JSON.stringify([r.variationKey,S]);$.add(b);let N=s.get(b);if(N?.signature===J){N.effect.applied&&E(r.receiptId);continue}s.get(b)?.effect.revert(),s.delete(b);let K=j(S,{requireUniqueTargets:!0,boundVariations:y.variations,allowJs:!1,onApplied:()=>E(r.receiptId),onError:F=>R(e.onError,F)});s.set(b,{signature:J,effect:K}),K.applied&&E(r.receiptId)}}for(let[r,l]of s)$.has(r)||(l.effect.revert(),s.delete(r));for(let[r,l]of d)I.has(r)||(l(),d.delete(r))}catch(P){h===i&&g(),!n&&h===i&&R(e.onError,P)}finally{c=!1,u&&!n&&(u=!1,w())}}let G=e.client.subscribe(()=>{if(v()===f)return;f=v(),i++;let t=e.client.view;(!t||t.stopped||!["running","waiting"].includes(t.status))&&g(),a&&w()}),H=T(()=>{i++,g(),a&&w()}),V=()=>{i++,C()};document.addEventListener("visibilitychange",V);let M=A({document,run:async()=>{a&&await w()},delay:()=>a&&!n?15e3:void 0});return{async start(){a||n||(a=!0,await M.refresh())},refresh:w,destroy(){n=!0,i++,M.destroy(),document.removeEventListener("visibilitychange",V),G(),H(),g(),U.destroy()}}}export{B as a,Q as b,re as c};
@@ -1 +0,0 @@
1
- import{b as et}from"./chunk-OEUA65JK.js";import{a as jn,b as Bn,c as mn,d as wn,e as xe,f as Wn,h as Yn,i as Xn,j as Zn,k as Kn}from"./chunk-4CRUNNTC.js";import{b as Fn,c as nt}from"./chunk-4OSW2Y67.js";import{a as $n}from"./chunk-W32FI2A2.js";import{c as xn,e as Gn,f as Qn,h as zn,i as He,j as tn,k as Jn,l as rn}from"./chunk-ZNOVEJLM.js";import{b as Nn}from"./chunk-I643NVMZ.js";import{K as nn}from"./chunk-7UXQJJFZ.js";import{a as $e,d as On}from"./chunk-UCDQJB53.js";import{c as _n,e as Ln,f as Hn,g as Vn,h as Un,i as Mn}from"./chunk-RUMGXXVJ.js";import{b as An}from"./chunk-CBOIDISB.js";import{B as fn}from"./chunk-TSBXPDUQ.js";import{x as kn}from"./chunk-KVIGHX2B.js";import{t as Sn}from"./chunk-POX2ELNS.js";import{C as Tn}from"./chunk-BBA64POP.js";import{a as w}from"./chunk-BYHBBZIO.js";import{a as Pe}from"./chunk-DSPLGTQI.js";async function yn(t){let{session:b,load:R}=dt(t);try{return await R(),b}catch(n){throw b.destroy(),n}}function dt(t){let b=t.view;if(!b?.paywall)throw new w("INVALID_REQUEST","The current node is not a Paywall");let R=b.paywall.receiptId,n=b.nodeId,g=b.visit,S=b.paywall.resolution,o=b.paywall,_="document"in S?{document:S.document,offering:S.offering,capabilities:S.capabilities}:null;function d(){let i=o.resolution;return"document"in i?i:_&&{...i,document:_.document,offering:_.offering,capabilities:_n(i.capabilities,_.capabilities)}}function C(i){if(!Ln(i,S))throw new w("INVALID_RESPONSE","The pinned Paywall binding changed")}let E=!1,G=new Set,re=null;function y(){let i=d();if(i&&!E)for(let a of G)Pe(a,structuredClone(i))}async function N(){I();let i=d();if(i)return structuredClone(i);if(!re){let a=(async()=>{if("document"in o.resolution||!t.resolvePaywall)throw new w("INVALID_RESPONSE","Public Paywall reader is unavailable");let D=await Fn(t,o.resolution);return I(),C(D),_={document:D.document,offering:D.offering,capabilities:D.capabilities},y(),d()})();re=a;let s=()=>{re===a&&(re=null)};a.then(s,s)}return re.then(a=>structuredClone(a))}let l=new AbortController,q=(t.pendingCommands??(t.pendingCommand?[t.pendingCommand]:[])).find(i=>i.operation==="submit"&&i.nodeId===n&&i.visit===g&&i.input.type==="paywall_quote")?.requestId??b.paywall.purchaseRequestId,T=0,ne=null,U=new Set,M=null,z=new Map;function Q(i){if(i.purchase&&i.purchase.receiptId!==R)throw new w("INVALID_RESPONSE","Purchase receipt changed");let a=i.run.paywall;return i.purchase??(a?.receiptId===R?a:null)}function I(){if(E)throw new w("IDENTITY_CHANGED","Paywall presentation has closed")}function K(i,a,s){if(I(),a!==T||s!==void 0&&o.quote?.operationId!==s)return!1;let D=o.selectionGeneration??0,m=i.run.paywall;if(m?.receiptId===R){if((m.selectionGeneration??0)<(o.selectionGeneration??0))return!1;C(m.resolution)}let p=Q(i),F=m?.receiptId===R&&(m.selectionGeneration??0)>D,f=F?p?.quote??null:p?.quote??o.quote,Y=p?.operation??(f?.operationId===o.quote?.operationId?o.operation:null);return o.quote&&f&&Un(o.quote,f),f&&Y&&Hn(Y,{operationId:f.operationId,membershipId:fn(f)?f.membershipId:null,...fn(f)?{featureQuantities:f.featureQuantities??{}}:{}},"Purchase operation changed"),(F||f?.operationId!==o.quote?.operationId)&&(T++,m?.receiptId===R&&(q=m.purchaseRequestId)),m?.canReselect===!0&&m.purchaseRequestId===M&&!(t.pendingCommands??[t.pendingCommand]).some(X=>X?.requestId===M)&&(M=null),o={...o,...m?.receiptId===R?m:{},...s!==void 0&&!F&&p?.canReselect!==void 0?{canReselect:p.canReselect}:{},quote:f,operation:Mn(o.operation,Y,!0)},y(),!0}function O(i,a,s){return new Promise((D,m)=>{let p=!1,F=()=>{clearTimeout(j),l.signal.removeEventListener("abort",X)},f=ge=>{p||(p=!0,F(),D(ge))},Y=ge=>{p||(p=!0,F(),m(ge))},X=()=>Y(new w("IDENTITY_CHANGED","Paywall presentation has closed")),j=setTimeout(()=>Y(new w("COMMAND_PENDING","The purchase command is still pending; retry the original request",202,s)),Math.max(0,a-Date.now()));l.signal.addEventListener("abort",X,{once:!0}),l.signal.aborted&&X(),i.then(f,Y)})}function qe(i){return new Promise(a=>{let s=()=>{clearTimeout(D),l.signal.removeEventListener("abort",s),a()},D=setTimeout(s,i);l.signal.addEventListener("abort",s,{once:!0}),l.signal.aborted&&s()})}function he(i,a){I();let s=z.get(i)??t.pendingCommands?.find(p=>p.requestId===i)??t.pendingCommand;if(s?.operation==="submit"&&s.requestId===i&&s.nodeId===n&&s.visit===g){a.type==="paywall_quote"&&s.input.type==="paywall_quote"&&s.input.predecessor&&!a.predecessor&&(a={...a,predecessor:s.input.predecessor});let p=nn.parse(s),F=nn.parse({...s,input:a});if(p.operation!=="submit"||F.operation!=="submit"||JSON.stringify(p.input)!==JSON.stringify(F.input))throw new w("CONFLICT","A purchase request cannot change its input");return z.set(i,p),p}let D=t.view;if(!D||D.nodeId!==n||D.visit!==g||D.paywall?.receiptId!==R)throw new w("PRECONDITION_FAILED","The Paywall visit has changed");let m=nn.parse({operation:"submit",requestId:i,nodeId:n,visit:g,revision:D.revision,input:structuredClone(a)});if(m.operation!=="submit")throw new w("INVALID_REQUEST","A purchase submission is required");return z.set(i,m),m}async function we(i,a){I();let{requestId:s,input:D}=i,m=Date.now()+3e4;U.add(s);try{let p=await O(t.submit(i),m,s);for(;p.run.pendingRequest?.requestId===s&&Date.now()<m&&!E&&(await qe(Math.min(1e3,m-Date.now())),!(E||Date.now()>=m));)p=await O(t.resume(s),m,s);if(E)throw new w("IDENTITY_CHANGED","Paywall presentation has closed");if(p.run.pendingRequest?.requestId===s)throw new w("COMMAND_PENDING","The purchase command is still pending; retry the original request",202,s);if(!K(p,a,D.type==="paywall_confirm"||D.type==="paywall_cancel"?D.operationId:void 0))throw new w("PRECONDITION_FAILED","The purchase selection has changed");M===s&&(M=null)}catch(p){if(M=s,D.type==="paywall_quote"&&t.settle&&!E&&p instanceof w&&p.status!==void 0&&![401,425].includes(p.status)&&!p.retryable&&p.recovery!=="recover_operation")try{if((await O(t.settle(s),m,s)).settlement?.state==="settled"){let f=await O(t.get(),m,s);K(f,a)&&f.run.paywall?.purchaseRequestId===s&&o.canReselect===!0&&z.delete(s)}}catch{}throw p instanceof w&&p.code==="COMMAND_PENDING"&&p.status===void 0&&z.delete(s),p}finally{U.delete(s)}}async function W(i){if(!o.quote)throw new w("INVALID_REQUEST","A quoted purchase is required");let a=i==="confirm"?"paywall_confirm":"paywall_cancel",s=[...z.values(),...t.pendingCommands??(t.pendingCommand?[t.pendingCommand]:[])].find(m=>m.operation==="submit"&&m.input.type===a&&"operationId"in m.input&&m.input.operationId===o.quote.operationId),D=s?.operation==="submit"&&s.input.type===a&&"operationId"in s.input&&s.input.operationId===o.quote.operationId?s.requestId:crypto.randomUUID();if(await we(he(D,{type:i==="confirm"?"paywall_confirm":"paywall_cancel",operationId:o.quote.operationId,...i==="confirm"&&o.quote.merchantTerms?{merchantConfirmation:kn(o.quote.merchantTerms)}:{}}),T),!o.operation)throw new w("INVALID_RESPONSE","The accepted purchase result is missing");return structuredClone(o.operation)}let le={get view(){return structuredClone(d())},get quote(){return o.quote?structuredClone(o.quote):null},get operation(){return o.operation?structuredClone(o.operation):null},get webViewUrl(){return t.webViewUrl},get locale(){return t.view?.locale??b.locale},get canReselect(){return o.canReselect===!0&&M===null},get recovery(){let i=t.pendingCommands??(t.pendingCommand?[t.pendingCommand]:[]),a=t.pendingPurchase;if(a&&(a.receiptId!==R||a.operationId!==o.quote?.operationId))return{type:"recover",operationId:a.operationId,requestId:i[0]?.requestId??null};let s=$e({quote:o.quote,operation:o.operation,requestId:i[0]?.requestId??M??q,pending:U.size>0||i.length>0||M!==null,destroyed:E,canReselect:o.canReselect});return s.type==="recover"&&s.requestId===null&&!E&&t.hasDurableJournal===!0&&!o.quote&&!o.operation&&(o.selectionGeneration??0)===0&&!a&&!i.length&&!U.size&&!q?{type:"native",operationId:null}:s},get pendingCancellation(){return!E&&(t.pendingCommands??(t.pendingCommand?[t.pendingCommand]:[])).some(i=>i.operation==="submit"&&i.nodeId===n&&i.visit===g&&i.input.type==="paywall_cancel"&&i.input.operationId===o.quote?.operationId)},subscribe(i){return E?()=>{}:(G.add(i),()=>G.delete(i))},async refresh(){I();let i=T,a=await t.get();if(K(a,i),a.run.paywall?.receiptId!==R)throw new w("PRECONDITION_FAILED","Paywall presentation has changed");return N()},preview(i){let a=d();if(!a)return Promise.reject(new w("PRECONDITION_FAILED","Load the Paywall presentation first"));if(q&&q!==i.requestId&&(ne||o.canReselect!==!0))return Promise.reject(new w("COMMAND_PENDING","Retry the original purchase before starting another"));let s=a.document.buttons[i.actionId],D=s?.type==="checkout"?An(s.product,i.selection,a.capabilities):null;if(!D)return Promise.reject(new w("PRODUCT_UNAVAILABLE","Choose an available Product in this purchase area"));let m=Sn(a.document.screen,D,i.selection,a.capabilities),p=q!==i.requestId&&(o.selectionGeneration??0)>0?{operationId:o.quote?.operationId??null,generation:o.selectionGeneration??0}:void 0,F=t.view?.parameters.commerce;if(F&&typeof F=="object"&&!Array.isArray(F)&&F.intent==="subscription_change"&&!i.subscriptionChange)return Promise.reject(new w("INVALID_REQUEST","Choose the existing membership for this subscription change"));if(i.subscriptionChange&&i.nativeOffer)return Promise.reject(new w("INVALID_REQUEST","A web membership change cannot include a store offer"));if(p&&o.canReselect!==!0)return Promise.reject(new w("COMMAND_PENDING","Original purchase requires authoritative termination"));let f;try{f=he(i.requestId,{type:"paywall_quote",actionId:i.actionId,productVersionId:D,...Object.keys(m).length?{featureQuantities:m}:{},...p?{predecessor:p}:{},...i.offerId?{offerId:i.offerId}:{},...i.nativeOffer?{nativeOffer:i.nativeOffer}:{},...i.subscriptionChange?{subscriptionChange:i.subscriptionChange}:{}})}catch(j){return Promise.reject(j)}if(q===i.requestId&&ne)return ne;q!==i.requestId&&T++;let Y=T;q=i.requestId;let X=(async()=>{if(await we(f,Y),!o.quote)throw new w("INVALID_RESPONSE","The accepted quote is missing");return Vn(o.quote,{productVersionId:D,featureQuantities:m,subscriptionChange:i.subscriptionChange},"The selected purchase changed"),structuredClone(o.quote)})();return ne=X,X.then(()=>{ne===X&&(ne=null)},j=>{ne===X&&(ne=null),q===i.requestId&&t.pendingCommand?.requestId!==i.requestId&&j instanceof w&&j.status!==void 0&&j.status<500&&![401,425].includes(j.status)&&(q=null)}),X},confirm:()=>W("confirm"),cancel:()=>W("cancel"),async read(){if(I(),!o.quote)throw new w("INVALID_REQUEST","A quoted purchase is required");let i=o.quote.operationId,a=T,s=t.pendingCommands?.find(f=>f.operation==="submit"&&(f.input.type==="paywall_confirm"||f.input.type==="paywall_cancel")&&f.input.operationId===i)??t.pendingCommand;s?.operation==="submit"&&(s.input.type==="paywall_confirm"||s.input.type==="paywall_cancel")&&s.input.operationId===i&&await t.settle?.(s.requestId);let D=await t.get(void 0,{receiptId:R,operationId:i});I();let m=Q(D);if(m?.quote&&m.quote.operationId!==i||m?.operation&&m.operation.operationId!==i)throw new w("INVALID_RESPONSE","Purchase operation changed");let p=K(D,a,i),F=p?o.operation:m?.operation;if(!F)throw new w("INVALID_RESPONSE","The current purchase result is missing");return p&&U.size===0&&!(t.pendingCommands?.length??(t.pendingCommand?1:0))&&(M=null),structuredClone(F)},destroy(){E=!0,L(),G.clear(),l.abort(),z.clear()}},L=t.subscribe(i=>{E||i.nodeId!==n||i.visit!==g||i.paywall?.receiptId!==R||(i.paywall.selectionGeneration??0)<(o.selectionGeneration??0)||(C(i.paywall.resolution),o={...o,resolution:i.paywall.resolution},y())});return{session:le,load:N}}function tt(t){let b=new Set,R=new Set,n=null;async function g(d,C){let E=!1;for(;!t.stopped&&t.key===d&&t.client.pendingCommand?.requestId===C;){if(!t.client.settle)throw new w("COMMAND_PENDING","The original display acknowledgement is still pending");await t.client.settle(C),E=!0,t.client.pendingCommand?.requestId===C&&await new Promise(G=>setTimeout(G,1500))}t.stopped||t.key!==d||(E&&await t.client.get(),!(t.stopped||t.key!==d)&&b.add(d))}function S(d,C){n=C;let E=()=>{n===C&&(n=null),R.delete(d)};return C.then(E,G=>{E(),t.busy||t.fail(G)}),C}function o(d){if(t.reviewing||b.has(d)||R.has(d)||t.stopped)return;R.add(d);let C=async()=>{if(t.reviewing||t.stopped||t.key!==d||b.has(d)){R.delete(d);return}if(t.busy||t.client.pendingCommand){setTimeout(()=>{C()},250);return}let E=(async()=>{if(t.staleRead){if(await t.staleRead,t.stopped||t.key!==d)return;if(t.client.pendingCommand){setTimeout(()=>{C()},250);return}}let G=t.client.view,re=t.expected(),y=re.requestId;try{await t.client.submit({operation:"shown",...re})}catch(N){if(!(N instanceof w)||N.code!=="CONFLICT"||N.status!==409||t.client.pendingCommand)throw N;await t.client.get();let l=t.client.view;if(t.stopped||t.reviewing||t.key!==d||!l||!G||l.id!==G.id||l.source.versionId!==G.source.versionId||l.nodeId!==re.nodeId||l.visit!==re.visit||l.revision<=re.revision||l.stopped||!l.screen&&(!l.paywall||l.paywall.receiptId!==G.paywall?.receiptId)||!["running","waiting"].includes(l.status)||t.client.pendingCommand)throw N;let u=t.expected();y=u.requestId,await t.client.submit({operation:"shown",...u})}await g(d,y)})();S(d,E)};C()}function _(){if(n)return n;let d=t.client.pendingCommand;if(d?.operation!=="shown")return null;let C=t.key;return R.add(C),S(C,(async()=>{await t.client.retry(),await g(C,d.requestId)})())}return{report:o,settled:_,get inFlight(){return n}}}function it(t){let b={},R=new Map;async function n(g){let S=t.client.view,o=S?.screen,_=o?.customerData.nodes[g.nodeId];if(t.stopped||t.busy||!S||!o||!_)return;if(!["refresh","next","previous","filter","sources_next","sources_previous"].includes(g.action)){let N=t.document,l=N?Tn(N,g.nodeId):null,u=l?.type==="customer_data"?l.data.outputs?.[g.action]:void 0;u&&o.outputs.includes(u)?await t.perform(()=>t.client.submit({operation:"submit",...t.expected(),input:{type:"screen",output:u,answers:t.answers,selection:g.value?{[g.nodeId]:g.value}:{}}})):await t.onIntent?.(g,S);return}let C=g.action.startsWith("sources_")?_.resources.find(N=>N.key===g.value):null;if(g.action.startsWith("sources_")&&!C)throw new w("INVALID_REQUEST","Choose a current resource");let E=`${S.visit}:${g.nodeId}:${C?.key??""}`,G=R.get(E)??[null],y=b[g.nodeId]??{page:1,after:null,filter:"all",...C?{resourceKey:C.key}:{}};if(g.action==="filter"){let N=g.value;if(!N||!(_.source==="offer_history"?["all","issued","reserved","redeemed","expired","revoked"]:["all","purchase","refund","source","usage","debt","settlement"]).includes(N))throw new w("INVALID_REQUEST","Unknown data filter");y={page:1,after:null,filter:N},G.splice(0,G.length,null)}else if(g.action==="next"||g.action==="sources_next"){let N=C?.sources.at(-1),l=C?N?{kind:"ledger",cursor:{at:N.detail[0],id:N.id,type:"source"}}:null:o.dataCursors[g.nodeId];if(!l||!C&&!_.hasNext)return;G[y.page]=l,y={...y,page:y.page+1,after:l}}else if(g.action==="previous"||g.action==="sources_previous"){if(y.page<=1)return;y={...y,page:y.page-1,after:G[y.page-2]??null}}R.set(E,G),b={...b,[g.nodeId]:y},await t.perform(()=>t.client.get({nodeId:S.nodeId,visit:S.visit,revision:S.revision,components:b}))}return{get queries(){return b},intent:n,reset(){b={},R.clear()}}}function rt(t){let{doc:b,holder:R,reviewHolder:n,mountScreenPreview:g}=t,S=!1,o,_=0,d=null,C="",E,G=new Map,re=l=>l?`${l.id}:${l.nodeId}:${l.visit}:${l.revision}:${l.paywall?.quote?.operationId??""}`:"";async function y(l){if(t.stopped||!t.client.review||S&&l===o&&E?.active)return;let u=!S||l!==o;S||(C=re(t.client.view),G.set(C,structuredClone(t.answers))),S=!0,o=l,R.hidden=!0,t.suspend(!0),n.hidden=!1;let q=++_;u&&(E?.finish("dismissed"),d?.destroy(),d=null,n.replaceChildren(),E=tn(n,t.loadingOptions,"funnel",()=>{N()}));let T=u?E:void 0;try{if(T?.start(!1,t.client.view?.locale),q!==_||t.stopped)return;let ne=t.client.review(l),U=await(T?.wait(ne,He)??ne);if(t.stopped||q!==_||!S)return;if(!U.review)throw new w("INVALID_RESPONSE","Historical projection is missing");d?.destroy(),d=null,T||n.replaceChildren();let M=b.createElement("div"),z=T?rn(M,n):()=>{};n.append(M);let Q=U.run.locale.startsWith("zh"),I=t.chrome;M.style.cssText=I.history;let K=b.createElement("p");K.textContent=Q?"只读回看":"Read-only history",K.style.cssText=I.historyTitle,M.append(K);let O=b.createElement("p");O.style.cssText=I.historyNote,O.textContent=U.review.pages.length?Q?"选择一页查看当时的内容,回看不会改动任何信息。":"Choose a page to see it as it was. Nothing here can be changed.":Q?"还没有可回看的页面。":"There are no earlier pages yet.",M.append(O);let qe=U.review.page?.receiptId,he=b.createElement("div");he.style.cssText=I.historyPages;for(let[le,L]of U.review.pages.entries()){let i=b.createElement("button");i.type="button",i.textContent=Q?`第 ${le+1} 页`:`Page ${le+1}`;let a=qe!==void 0&&L.receiptId===qe;i.style.cssText=a?I.primary:I.secondary,a&&i.setAttribute("aria-current","page"),xe(i,()=>t.chrome.focus),i.onclick=()=>{y(L.receiptId)},he.append(i)}if(he.childElementCount&&M.append(he),U.review.page){let le=U.review.page,L=b.createElement("div");L.inert=!0,L.style.cssText=I.historyPage,M.append(L),d=g(L,{mode:"live",rendererUrl:t.client.webViewUrl,title:le.document.name,onAction:()=>{},onAnswers:()=>{},onCustomerDataIntent:()=>{},onRendered:()=>{q===_&&!t.stopped&&T?.present(z)},onError:a=>{if(q!==_||t.stopped)return;let s=new Error(a);T?.finish("error",s),d?.destroy(),d=null,M.remove(),t.fail(s)},onEscape:()=>{N()}});let i=d;if(i.update(le.document,U.run.locale,{serverInput:{bindings:le.inputs,answers:le.answers,values:le.values}}),await i.ready,t.stopped||q!==_||!S)return}let we=Q?{issued:"已领取",reserved:"已预留",redeemed:"已使用",expired:"已过期",revoked:"已撤销",unknown:"状态待确认"}:{issued:"Issued",reserved:"Reserved",redeemed:"Used",expired:"Expired",revoked:"Revoked",unknown:"Status unconfirmed"},W=b.createElement("div");W.style.cssText=I.historyRecords;for(let le of[...U.review.coupons.map((L,i)=>`${Q?"优惠券":"Coupon"} ${i+1}: ${we[L.status]}`),...U.review.purchases.map((L,i)=>`${Q?"购买":"Purchase"} ${i+1}: ${Kn(L.status,Q)}`)]){let L=b.createElement("p");L.textContent=le,L.style.margin="0",W.append(L)}W.childElementCount&&M.append(W),U.review.page||T?.present(z),t.client.view&&await t.enqueue(t.client.view)}catch(ne){if(q!==_||t.stopped)return;T?.finish("error",ne),d?.destroy(),d=null,n.replaceChildren(),t.fail(ne)}}async function N(){if(!S||t.stopped||!t.client.review)return;let l=++_;E?.finish("dismissed");try{if(await t.client.review(),t.stopped||l!==_)return;S=!1,_++,E?.finish("dismissed"),d?.destroy(),d=null,n.replaceChildren(),n.hidden=!0,R.hidden=!1;let u=t.client.view;re(u)!==C?(G.set(C,structuredClone(t.answers)),t.resetScreen()):(G.delete(C),t.suspend(!1)),u&&await t.enqueue(u)}catch(u){if(l!==_||t.stopped)return;d?.destroy(),d=null,n.replaceChildren(),t.fail(u)}}return{get active(){return S},get receipt(){return o},open:y,exit:N,get drafts(){return new Map([...G].map(([l,u])=>[l,structuredClone(u)]))},stop(){S=!1,_++,E?.finish("dismissed"),d?.destroy(),d=null,n.replaceChildren(),n.hidden=!0,R.hidden=!1}}}var hn=5e3;async function ct(t,b,R){let n=b,g=n.prepared&&et(n.prepared),S=()=>{};function o(){n.prepared&&n.prepared.state!=="adopted"&&g?.release()}let _=()=>n.prepared?.state==="shown"&&!!g?.modal,d=n.client.identitySignal,C;try{C=await Promise.all([import("./screen-renderer-XZWKIJWF.js"),import("./paywall-25MAYQ4B.js")]),n.signal?.throwIfAborted(),d?.throwIfAborted()}catch(e){throw o(),e}let[{mountScreenPreview:E},{showPaywall:G}]=C,re=(typeof INDIANA_NATIVE_SHELL_BUILD>"u"||!INDIANA_NATIVE_SHELL_BUILD)&&n.appManifestRelease?nt({client:n.client,appManifestRelease:n.appManifestRelease,onError:n.onError}):void 0;re?.start();let y=t.ownerDocument,N=zn(y),l=!1,u=y.createElement("section"),q=y.createElement("div"),T=y.createElement("div"),ne=y.createElement("div"),U=y.createElement("button");ne.hidden=!0,U.type="button";let M=y.createElement("p"),z=y.createElement("p"),Q=y.createElement("button"),I=y.createElement("button"),K=y.createElement("button"),O=y.createElement("dialog"),qe,he=!1;u.dataset.indianaFunnel="",u.dataset.longplayCloseOwner="sdk",u.setAttribute("aria-busy","false"),M.setAttribute("role","status"),z.setAttribute("role","alert"),z.hidden=!0,Q.type=I.type=K.type="button",T.append(Q,U,M,z,K,I),u.append(q,ne,T),t.append(u);let we=Bn,W=mn(we),le="",L=(y.documentElement.lang||"").startsWith("zh"),i,a="",s;for(let e of[Q,U,K,I])xe(e,()=>W.focus);function D(){let e=L?"关闭":"Close";I.parentElement===O?(I.textContent="×",I.setAttribute("aria-label",e),Qn(I,we)):(I.textContent=e,I.removeAttribute("aria-label"),I.style.cssText=W.link+";margin-inline-start:auto")}function m(e){let r=e?.screen?.content.document.theme??we,c=JSON.stringify([r.primary,r.background,r.text,r.radius,r.font,I.parentElement===O]);if(c===le)return;le=c,we=r;let H=I.parentElement===O;W=mn(we,H),u.style.cssText=W.root+";min-width:0"+(H?";display:flex;flex-direction:column;min-height:100%":""),T.style.cssText=W.bar+(H?";margin-top:auto":""),T.hidden&&(T.style.display="none"),Q.style.cssText=U.style.cssText=W.secondary,K.style.cssText=W.primary,M.style.cssText=W.status,z.style.cssText=W.alert,D(),wn(Q)}function p(){T.hidden=Q.hidden&&U.hidden&&K.hidden&&z.hidden&&!M.textContent&&(I.hidden||I.parentElement!==T),T.style.display=T.hidden?"none":"flex",i?.responsive&&s!==void 0&&i.setContentHeight(s+T.getBoundingClientRect().height)}m();let F=null,f=null,Y=null,X="",j="",ge=!1,Ge="",on="",Qe="",h=!1,ue=0,ze=!1,gn="",sn=null,an=Promise.resolve(),vn=!n.client.view,J=R,Se,Ve,Je="",je,pe=!1,De=null,ve=!1,Be=()=>n.client.pendingCommand?.operation==="close",fe=null,ee=null,ln=$n({document:y,run:async()=>{(!f?.observing||n.client.pendingCommand)&&await dn()},delay:()=>{if(!me.pending&&!(h||!Y||!["running","waiting"].includes(Y.status)&&!n.client.pendingCommand)&&!(f?.observing&&!n.client.pendingCommand))return Y.pendingRequest||n.client.pendingCommand?1500:hn},hiddenDelay:()=>!h&&!me.pending&&n.client.pendingCommand?15e3:void 0}),te=null;function un(){return ee&&n.client.hasDurableJournal===!0&&te?.acknowledged===!0&&te.operationId===ee.operationId&&n.client.view?.id===te.runId&&n.client.view?.status==="closed"&&n.client.view.revision===te.revision+1&&!(n.client.pendingCommands?.length??(n.client.pendingCommand?1:0))&&!n.client.pendingPurchase?ee:null}function In(e){let r=e.run.paywall;if(te&&e.settlement?.requestId===te.requestId&&e.settlement.state==="settled"&&e.settlement.operationId===null&&e.run.id===te.runId&&e.run.status==="closed"&&!e.run.pendingRequest&&e.run.revision===te.revision+1&&e.run.nodeId===te.nodeId&&e.run.visit===te.visit&&r?.receiptId===te.receiptId&&r.selectionGeneration===te.selectionGeneration&&(r.quote?.operationId??null)===te.operationId&&(r.operation?.operationId??r.quote?.operationId??null)===te.operationId){let c=te.operationId===null&&r.selectionGeneration===0&&!r.quote&&!r.operation&&!r.purchaseRequestId,H=$e({quote:r.quote,operation:r.operation,requestId:r.purchaseRequestId,pending:!1,destroyed:!1,canReselect:r.canReselect});(c||r.canReselect===!0&&H.type==="native")&&(te.acknowledged=!0)}}let ke=null,Ue=new Set,Ie={},Fe=!1,de=(e,r=null)=>{h||(e instanceof w&&e.status===409&&e.reason==="STATE_CHANGED"&&e.recovery==="recover_operation"&&ln.destroy(),ke=r,Fe=!1,z.textContent=Wn(e,L),z.hidden=!1,K.hidden=n.client.pendingCommand===null,p(),Pe(n.onError,e))},me=Nn({client:n.client,document:y,conceal(){h||(be(),J?.finish("dismissed"),u.hidden=!0,l||(l=!0,N()))},async receive(e){h||await ye(n.client.view??e.run)},failed(e){if(!h){if(!me.pending){ve=!1;let r=n.client.view;r&&ye(r).then(()=>de(e),de);return}Ze(),u.parentElement!==t&&t.append(u),u.hidden=!1,Q.hidden=U.hidden=I.hidden=!0,M.textContent="",m(),de(e,n.client.pendingCommand?.requestId??null)}}}),bn=()=>{h||(ke=null,z.textContent=Xn(L),z.hidden=!1,K.hidden=!0,p())};function Te(){let e=n.client.view;if(!e)throw new w("INVALID_REQUEST","No current Run is available");return{requestId:crypto.randomUUID(),nodeId:e.nodeId,visit:e.visit,revision:e.revision}}let A=rt({client:n.client,doc:y,holder:q,reviewHolder:ne,mountScreenPreview:E,loadingOptions:n,get chrome(){return W},get stopped(){return h},get answers(){return Ie},suspend(e){f?.setSuspended(e)},resetScreen(){X="",j="",Ge=""},enqueue:ye,fail:de}),Me=tt({client:n.client,expected:Te,fail:de,get stopped(){return h},get reviewing(){return A.active},get key(){return X},get busy(){return ue},get staleRead(){return sn}}),We=it({client:n.client,expected:Te,perform:Oe,onIntent:n.onCustomerDataIntent,get stopped(){return h},get busy(){return ue},get document(){return F?.document},get answers(){return Ie}}),Ye=e=>`${e.id}:${e.nodeId}:${e.visit}`,Ne=e=>e&&(e.screen||e.paywall)?Ye(e):"";function Re(){let e=n.client.view;Q.disabled=!A.active&&(ue>0||!!n.client.pendingCommand||!e?.canBack||e.stopped||!["running","waiting"].includes(e.status)||!Ne(e)||j!==Ne(e)),Q.hidden=!A.active&&!e?.canBack,wn(Q);let r=!!f&&!A.active;I.hidden=r&&!J?.active||he&&!A.active,U.hidden=!n.client.review||!A.active&&!e?.canBack;let c=e?.locale.startsWith("zh");M.textContent=r?"":ue>0||e?.pendingRequest?c?"正在处理":"Processing":e?.instruction?.type==="wait"?c?"等待中":"Waiting":"",p()}async function Cn(e){if(!e)return;let r=n.client.view;await e;let c=n.client.view;if(!r||!c||c.id!==r.id||c.nodeId!==r.nodeId||c.visit!==r.visit||c.stopped||!["running","waiting"].includes(c.status))throw new w("PRECONDITION_FAILED","The screen changed while its display was acknowledged")}async function Oe(e,r=!1,c){if(!((ue||ve||fe||ee)&&!r||h||A.active&&!r)){ue++,u.setAttribute("aria-busy","true"),z.hidden=!0,ke=null,Fe=!1,Re();try{if(r||await Cn(Me.inFlight),h)return;let H=await e();h||await ye(n.client.view??H.run)}catch(H){c?.(H)&&n.client.pendingCommand===null?bn():me.pending||de(H,n.client.pendingCommand?.requestId??null)}finally{ue=Math.max(0,ue-1),u.setAttribute("aria-busy",String(ue>0)),h||(K.hidden=n.client.pendingCommand===null,Re())}}}function _e(){ln.schedule()}async function dn(){if(!(h||ze||ue)&&!me.pending){if(A.active){await A.open(A.receipt);return}ze=!0;try{let e=n.client.pendingCommand;e&&n.client.settle&&await n.client.settle(e.requestId);let r=n.client.view,c=We.queries,H=await n.client.get(r?.screen&&Object.keys(c).length?{nodeId:r.nodeId,visit:r.visit,revision:r.revision,components:c}:void 0);Fe&&!h&&(Fe=!1,z.hidden=!0,p()),!h&&c===We.queries&&await ye(n.client.view??H.run)}catch(e){de(e),Fe=!h}finally{ze=!1}}}function Xe(e,r,c){if(J?.active){let ce=J;return ce.setDismissHandler(()=>Pn(ce)),ce}let H=tn(t,n,"funnel",()=>Pn(H),jn);return J=H,H.start(e,r,c),H}function Pn(e){h||pe||(pe=!0,e.finish("dismissed"),be(),u.hidden=!0,n.client.view?Ee().finally(oe):oe())}function cn(){clearTimeout(je?.timeout),je=void 0}function be(e){he=!1,cn(),Se?.abort(),Se=void 0,F?.destroy(),F=null,f?.destroy(),f=null,Ve?.(),Ve=void 0,O.open&&O.close();for(let r of Array.from(q.children))(!e||!r.contains(e))&&r.remove();q.style.cssText="",s=void 0,X="",j="",ge=!1,Ge="",Qe=""}function Rn(){let e=y.defaultView;i?.responsive&&e&&F?.resizeViewport?.(e.innerHeight,e.innerWidth)}function Ze(){i?.destroy(),i=void 0,a=""}function Ke(e){let r=e.screen?.presentation;if(!r||r.type==="inline"){O.open&&O.close(),Ze(),I.parentElement!==T&&T.append(I),u.parentElement!==t&&t.append(u);for(let ce of["flex","display","flex-direction","justify-content"])q.style.removeProperty(ce);m(e),p();return}u.parentElement!==O&&(O.append(I,u),t.append(O)),q.style.flex="1 0 auto",q.style.display="flex",q.style.flexDirection="column",q.style.justifyContent="center",m(e);let c=e.screen.content.document,H=JSON.stringify([r,le]);if(H!==a){Ze(),a=H;let ce={sm:420,md:640,lg:900},Ce="size"in r&&!r.backdrop?",0 0 0 100vmax #16142566":"";O.style.cssText=`box-sizing:border-box;padding:0;border:0;overflow:auto;background:${we.background};color:${we.text};`+(r.type==="fullscreen"?"width:100vw;height:100dvh;max-width:100vw;max-height:100dvh;margin:0;border-radius:0":`width:${ce[r.size]}px;max-width:calc(100vw - 32px);max-height:calc(100dvh - 32px);box-shadow:0 24px 80px #0003${Ce};`+(r.type==="sheet"?"margin:auto auto 0;border-radius:14px 14px 0 0":"border-radius:14px")),i=xn(O,{presentation:r,theme:c.theme,pages:c.pages},Rn),i.latch()}p(),O.setAttribute("aria-label",(qe?.screen===e.screen?.content.document.name?qe?.label:void 0)??F?.document?.name??e.screen?.content.document.name??"Funnel")}async function ot(e){if(h||pe)return;if(me.observe(),me.pending){Y=e;return}if(ve&&(Be()||["running","waiting"].includes(e.status))||(Y=e,ke&&n.client.pendingCommand?.requestId!==ke&&(z.hidden=!0,ke=null),L=e.locale.startsWith("zh"),U.textContent=L?"回看":"History",Q.textContent=A.active?L?"返回当前":"Return to current":L?"返回":"Back",D(),K.textContent=L?"重试":"Retry",K.hidden=n.client.pendingCommand===null,Re(),gn!==`${e.revision}:${e.visit}:${e.status}:${e.stopped}`&&(gn=`${e.revision}:${e.visit}:${e.status}:${e.stopped}`,Pe(n.onState,structuredClone(e))),h||pe))return;if((!e.pendingRequest||ve&&e.status==="closed")&&["closed","ineligible","failed"].includes(e.status)){oe();return}if(e.stopped&&_()){oe();return}if(e.stopped||n.client.configurationReady===!1){A.stop(),o(),be(),J?.finish("skipped"),u.hidden=!0,_e();return}if(u.hidden=!1,A.active){_e();return}if(e.status==="completed"&&f?.subscriptionUpgradeActive){_e();return}let r=Ne(e),c=n.client.view;if(c&&c.revision>e.revision&&Ne(c)!==r)return;let H=!e.instruction&&!e.pendingRequest&&e.nodeType==="screen"&&["running","waiting"].includes(e.status);r!==X&&(X&&J?.finish("dismissed"),be(),X=r,Ie={...e.answers},We.reset());let ce=Ye(e);if(Je===ce){u.hidden=!0;return}if(H&&!r){u.hidden=!0;let $=n.prepared?.state==="shown"?null:Xe(!0,e.locale);!h&&!pe&&je?.key!==ce&&(cn(),je={key:ce,timeout:setTimeout(()=>{let v=n.client.view;if(h||!$?.active&&n.prepared?.state!=="shown"||!v||Ye(v)!==ce)return;Je=ce;let B=new Error("Funnel screen preparation timed out");$?.finish("error",B),o(),be(),de(B)},He)}),_e();return}cn();let Z=$=>{let v=n.client.view;return!h&&!pe&&!De&&!$.aborted&&n.client.configurationReady!==!1&&!!v&&!v.stopped&&!["closed","ineligible","failed"].includes(v.status)&&(Ne(v)===r||v.status==="completed"&&f?.subscriptionUpgradeActive===!0)},Ce=($,v)=>{Z(v)&&(Je=r,J?.finish("error",$),be(),u.hidden=!0,de($))};if(r||((e.instruction&&e.instruction.type!=="evaluate_segment"||!["running","waiting"].includes(e.status))&&o(),Ke(e),e.instruction?.type!=="event"&&e.instruction?.type!=="open_url"&&J?.finish("skipped")),e.screen){o();let $=e.screen.content;if(!F){let se=e.screen.presentation.type!=="inline",x=Xe(se,e.locale);if(h||pe)return;let ie=(Se=new AbortController).signal;Ke(e),Ve=se?Jn(O):rn(u,t),F=E(q,{mode:"live",closeActions:Array.from(new Set([...n.closeActions??[],...$.document.actions.filter(V=>V.type==="event"&&V.close).map(V=>V.id)])),onAuthoredClose(V){Z(ie)&&(he=V,Re())},rendererUrl:n.client.webViewUrl,title:$.document.name,...se?{hostPresentation:()=>i?.type??e.screen.presentation.type}:{},onResize:V=>{s=V,i?.responsive&&i.setContentHeight(V+T.getBoundingClientRect().height)},onAction(V,P={},Ae={}){if(A.active||!Z(ie)||j!==r)return;Ie={...Ie,...Ae};let pn=e.screen?.inputs??[],Dn=Object.fromEntries(pn.filter(({variable:Le})=>Object.hasOwn(Ie,Le)).map(({variable:Le})=>[Le,Ie[Le]]));if(Zn(pn,Dn).length){bn();return}Oe(()=>n.client.submit({operation:"submit",...Te(),input:{type:"screen",output:V,answers:Dn,selection:P}}),!1,Le=>Yn(Le,pn))},onAnswers:V=>{A.active||!Z(ie)||j!==r||(Ie={...Ie,...V})},onCustomerDataIntent:V=>{A.active||!Z(ie)||j!==r||We.intent(V).catch(de)},onEscape:()=>{!Z(ie)||j!==r||A.active||fe||ee||Ee()},onError:V=>{let P=new Error(V);j===r?de(P):Ce(P,ie)},onRendered:V=>{if(!(!Z(ie)||j===r))try{x.present(P=>{Ve?.(),Ve=void 0,V&&(qe={screen:$.document.name,label:V},O.setAttribute("aria-label",V)),se&&(O.showModal(),l=!1,i?.responsive&&O.focus({preventScroll:!0}),!P&&n.loading!=="host"&&Gn(O,i?.type??e.screen.presentation.type,i?.responsive)),j=r,ge=se,Re()}),Z(ie)&&Me.report(r)}catch(P){Ce(P,ie)}}}),Rn()}let v={capabilities:e.screen.capabilities,customerData:e.screen.customerData,parameters:e.parameters,serverInput:{bindings:e.screen.inputs,answers:Ie,values:e.screen.values}},B=JSON.stringify([$,e.locale,v.parameters,e.screen.inputs,e.screen.values]);if(B!==Ge)F.update($.document,e.locale,v),Ge=B,on=JSON.stringify(v.capabilities),Qe=JSON.stringify(v.customerData);else{let se=JSON.stringify(v.capabilities);se!==on&&(F.updateCapabilities(v.capabilities),on=se),JSON.stringify(v.customerData)!==Qe&&(F.updateCustomerData(v.customerData),Qe=JSON.stringify(v.customerData))}let ae=F;if(ae)try{await(J?.wait(ae.ready)??ae.ready)}catch(se){Se&&Ce(se,Se.signal)}}else if(e.paywall&&!f){let $=e.paywall.resolution,v="document"in $?$.document:null,B=g,ae=n.mountPaywallControls,se=null,x=(Se=new AbortController).signal,ie={loading:"host",signal:x,...ae&&{mountControls:P=>ae(P,e)},canInteract:()=>Z(x)&&!A.active&&!fe&&!ee,beforeAction:async()=>{ue++;try{await Cn(Me.settled()),z.hidden=!0,ke=null,Fe=!1,p()}finally{ue=Math.max(0,ue-1)}},start:()=>yn(n.client),onObservationChange:_e,onPurchase:n.onPurchase,onCheckoutUrl:n.onCheckoutUrl,resumeCheckout:n.resumeCheckout,allowNewPurchase:n.allowNewPurchase,checkoutNavigation:n.checkoutNavigation,terminateCheckout:n.terminateCheckout,beforeCheckoutReplacement:n.beforeCheckoutReplacement,purchaseConfirmation:n.purchaseConfirmation,confirmOnHostedCheckout:n.confirmOnHostedCheckout,resolveOfferId:n.resolveOfferId,resolveSubscriptionChange:n.resolveSubscriptionChange,claimCoupon:n.claimCoupon,onEvent:n.onEvent,onOpenUrl:P=>n.onOpenUrl?n.onOpenUrl({receiptId:e.paywall.receiptId,url:P,openIn:"same_window"}):y.defaultView?.location.assign(P),onAction:async P=>{if(A.active)return;let Ae=await n.client.submit({operation:"submit",requestId:crypto.randomUUID(),nodeId:e.nodeId,visit:e.visit,revision:n.client.view?.revision??e.revision,input:{type:"screen",output:P,answers:{}}});await ye(n.client.view??Ae.run)},onError:P=>{j===r?de(P):Ce(P,x)}},V={quoteError:P=>Pe(n.onError,P),loadingLayout:()=>Z(x)?se?.getLoadingLayout?.():void 0,present(P){Z(x)&&(se?.present(Ae=>{P(Ae),j=r,ge=!!q.querySelector("dialog[open]"),ge&&(l=!1),Re()}),Z(x)&&Me.report(r))},async closeAction(P){h||A.active||await me.submit({operation:"submit",requestId:crypto.randomUUID(),nodeId:e.nodeId,visit:e.visit,revision:n.client.view?.revision??e.revision,input:{type:"screen",output:P,answers:{}}})},async dismiss(){if(h||x.aborted||A.active||fe||ee||!ve&&!Z(x))return;ve=!0;let P=n.client.view;if(P?.status==="completed"&&f?.subscriptionUpgradeActive){Ue.add(`complete:${P.id}`),Pe(n.onComplete,structuredClone(P)),oe();return}if((n.resumeCheckout||n.terminateCheckout)&&ut()){Y=n.client.view,oe();return}await Ee()}};if(B&&ae)o();else if(B){let P=await B.adopt(e,{options:ie,handoff:V,start:()=>yn(n.client)});P&&Z(x)&&!h?(Ke(e),f=P,J?.active&&J.present(()=>{}),j=r,ge=B.modal,ge&&(l=!1),Re(),Me.report(r),A.active&&f.setSuspended(!0)):(P?.destroy(),o())}if(h||pe)return;if(!f){if(se=Xe(!0,e.locale,v),h||pe)return;Ke(e);let P=await G(q,ie,V).catch(Ae=>(Ce(Ae,x),null));!Z(x)&&!(ve&&!h&&!x.aborted)?P?.host?.destroy():P&&(f=P.host,f?.setSuspended(A.active))}}if(h||pe)return;Re();let k=e.instruction;if(k&&(k.type==="open_url"||k.type==="event")&&!Ue.has(k.receiptId)){let $=y.createElement("button");$.type="button",$.style.cssText=W.primary,xe($,()=>W.focus),q.style.cssText=W.stage,$.textContent=k.type==="open_url"?`${L?"前往":"Continue to"} ${new URL(k.url).host}`:L?"继续":"Continue",$.onclick=()=>{let v=Te(),B=k.type==="open_url"&&!n.onOpenUrl&&k.openIn==="new_window"?st(k.url):null;Oe(async()=>{let ae="success";if(k.type==="open_url")if(n.onOpenUrl)try{ae=await n.onOpenUrl({receiptId:k.receiptId,url:k.url,openIn:k.openIn})===!1?"failed":"opened"}catch(x){Pe(n.onError,x),ae="failed"}else ae=k.openIn==="new_window"&&!B?"failed":"opened";if(k.type==="event"){if(!n.onEvent)throw new w("EVENT_HANDLER_REQUIRED","Provide the event handler");await n.onEvent(k.event)}if(h||n.client.view?.nodeId!==v.nodeId||n.client.view.visit!==v.visit)throw new w("PRECONDITION_FAILED","The client action visit changed");let se=await n.client.submit({operation:"submit",...v,input:{type:"client_action",receiptId:k.receiptId,outcome:ae}});return Ue.add(k.receiptId),k.type==="open_url"&&!n.onOpenUrl&&k.openIn==="same_window"&&y.defaultView?.location.assign(k.url),se})},J?.active?J.present(()=>q.replaceChildren($)):q.replaceChildren($)}!e.pendingRequest&&e.status==="completed"&&!Ue.has(`complete:${e.id}`)&&(Ue.add(`complete:${e.id}`),Pe(n.onComplete,structuredClone(e))),_e()}function st(e){let r=y.defaultView?.open(e,"_blank")??null;return r&&(r.opener=null),r}function ye(e){return Re(),an=an.catch(()=>{}).then(async()=>{try{await ot(e)}catch(r){throw J?.active&&(Je=Ye(e),J.finish("error",r),be(),u.hidden=!0),r}}),an}let at=n.client.subscribe(e=>{if(!vn){if(e.stopped&&(ge||_())&&!ve){Y=e,oe();return}!ve&&(e.stopped||n.client.configurationReady===!1||X&&j!==X&&(Ne(e)!==X||["closed","ineligible","failed"].includes(e.status)))&&(be(),J?.finish("dismissed"),u.hidden=!0),ye(e).catch(de)}}),lt=n.client.subscribeError?.(e=>{me.pending||de(e)});function ut(){let e=n.client.view,r=e?.paywall;return!!r?.operation&&!!e&&["running","waiting"].includes(e.status)&&On($e({quote:r.quote,operation:r.operation,requestId:r.purchaseRequestId,pending:!1,destroyed:!1,canReselect:r.canReselect}))}function Ee(e){if(De)return De;if(h||!e&&(fe||ee))return Promise.resolve();let r=!e&&Be();return!r&&n.client.view&&!["running","waiting"].includes(n.client.view.status)?(Y=n.client.view,oe(),Promise.resolve()):(De=Oe(async()=>{let c=r?await n.client.retry():await(e?n.client.submit.bind(n.client):me.submit)({operation:"close",...e??Te()});return e&&In(c),c},!0).then(()=>{let c=n.client.view;c?.status==="closed"&&!Be()&&(Y=c,oe())}).finally(()=>{De=null}),De)}function oe(){En()}function En(e){re?.destroy(),!h&&(h=!0,me.destroy(),S(),o(),n.signal?.removeEventListener("abort",oe),d?.removeEventListener("abort",oe),J?.finish("dismissed"),ln.destroy(),at(),lt?.(),be(e),Ze(),A.stop(),O.remove(),!e||!u.contains(e)?u.remove():(T.remove(),ne.remove()),!e&&!l&&N(),Pe(n.onDismiss,Y?structuredClone(Y):null))}Q.onclick=()=>{if(!Q.disabled){if(A.active){A.exit();return}Oe(()=>n.client.submit({operation:"back",...Te()}))}},U.onclick=()=>{A.open()},I.onclick=()=>{J?.active?J.dismiss():fe||Ee()},K.onclick=()=>{me.pending?me.retry().catch(()=>{}):Be()?Ee():Oe(()=>n.client.retry())},O.addEventListener("cancel",e=>{e.preventDefault(),J?.active?J.dismiss():fe||Ee()}),n.signal?.addEventListener("abort",oe,{once:!0}),d?.addEventListener("abort",oe,{once:!0});let en=!1;g&&(S=g.onClose(()=>{h||pe||(pe=!0,J?.finish("dismissed"),be(),u.hidden=!0,n.client.view?Ee().finally(oe):en=!0)}));let qn={destroy:oe,refresh:dn,retainPurchaseDialog(){let e=f?.retainPurchaseDialog();if(e)return f=null,En(e.dialog),{dialog:e.dialog,release(){e.release(),u.remove(),l||N()}}},get recovery(){let e=un();if(e)return e;if(!h&&!ue&&!ve&&!fe&&f){let r=f.recovery;if(r.type!=="native")return r}return{type:"recover",operationId:n.client.pendingPurchase?.operationId??n.client.view?.paywall?.quote?.operationId??ee?.operationId??null,requestId:n.client.pendingCommand?.requestId??null}},prepareFallback(){if(fe)return fe;let e=un();if(e)return Promise.resolve(e);let r=n.client.pendingPurchase?.operationId??n.client.view?.paywall?.quote?.operationId??ee?.operationId??null,c=()=>({type:"recover",operationId:r,requestId:n.client.pendingCommand?.requestId??null});if(n.client.hasDurableJournal!==!0){let k=f?.recovery;return Promise.resolve(k&&k.type!=="native"&&k.type!=="cancel"?k:c())}let H=(n.client.pendingCommands??(n.client.pendingCommand?[n.client.pendingCommand]:[])).some(k=>k.operation==="close");if(h&&!(H||ee&&n.client.view?.status==="closed")||ue||ze||De||A.active||!f&&!ee&&!H)return Promise.resolve(c());let ce=f,Z=(async()=>{try{if(!ee&&H){let v=await n.client.retry();return await ye(n.client.view??v.run),c()}if(!ee){let v=await ce.prepareFallback();if(v.type!=="native")return v;if(n.client.hasDurableJournal!==!0)return c();ee=v}let k=n.client.pendingCommands??(n.client.pendingCommand?[n.client.pendingCommand]:[]);if(k.length){let v=k.find(ae=>ae.operation==="close");if(!v||!te||v.requestId!==te.requestId)return c();let B=await n.client.retry();In(B),await ye(n.client.view??B.run)}else{let v=n.client.view,B=v?.paywall;if(!v||!B||B.selectionGeneration===void 0||(B.quote?.operationId??null)!==ee.operationId||ee.operationId!==null&&B.canReselect!==!0)return c();let ae=B.selectionGeneration,se=await n.client.get();await ye(n.client.view??se.run);let x=n.client.view,ie=x?.paywall;if(!x||!ie||!["running","waiting"].includes(x.status)||x.stopped||x.id!==v.id||x.nodeId!==v.nodeId||x.visit!==v.visit||ie.receiptId!==B.receiptId||ie.selectionGeneration!==ae||(ie.quote?.operationId??null)!==ee.operationId||ee.operationId!==null&&ie.canReselect!==!0||n.client.pendingPurchase||(n.client.pendingCommands?.length??(n.client.pendingCommand?1:0)))return c();let V=Te();te={runId:x.id,operationId:ee.operationId,revision:V.revision,requestId:V.requestId,nodeId:x.nodeId,visit:x.visit,receiptId:ie.receiptId,selectionGeneration:ae,acknowledged:!1},await Ee(V)}let $=un();return $?(oe(),$):c()}catch(k){return de(k),c()}})();fe=Z;let Ce=()=>{fe===Z&&(fe=null)};return Z.then(Ce,Ce),Z},review:A.open,exitReview:A.exit,get unappliedDrafts(){return A.drafts}};try{let e=n.client.view;if(e)((n.client.viewAgeMs??hn)>=hn||e.instruction?.type==="evaluate_segment")&&(sn=dn().finally(()=>{sn=null})),await ye(e);else{if(u.hidden=!0,h)throw new DOMException("Presentation cancelled","AbortError");let r=en||n.prepared?.state==="shown"?null:Xe(n.client.view?.screen?.presentation.type!=="inline",n.client.view?.locale);if(h||pe&&!en)throw new DOMException("Presentation cancelled","AbortError");let c=n.client.get(),H=await(r?r.wait(c,He):pt(c,He));if(vn=!1,en)return h||await Ee().finally(oe),qn;await ye(n.client.view??H.run)}}catch(e){throw J?.finish("error",e),oe(),e}return qn}function pt(t,b){let R;return Promise.race([t,new Promise((n,g)=>{R=setTimeout(()=>g(new Error("Presentation data timed out")),b)})]).finally(()=>clearTimeout(R))}function Kt(t,b,R){return ct(t,b,R)}export{ct as a,Kt as b};
@@ -1 +0,0 @@
1
- import{o as n,r as t}from"./chunk-XO6GV6O7.js";function u(o,e,a){return n(o,e,a,t)}export{u as a};
@@ -1 +0,0 @@
1
- import{a as on,c as sn,d as kt,f as Et,g as cn,k as ln}from"./chunk-4CRUNNTC.js";import{b as Ze}from"./chunk-W32FI2A2.js";import{d as Zt,e as en,f as tn,h as Pt,i as et,j as nn,k as rn,l as an}from"./chunk-ZNOVEJLM.js";import{a as Yt,c as bt,d as Kt,e as Jt}from"./chunk-UCDQJB53.js";import{a as Xe,b as me,d as Ct,f as vt,j as Xt}from"./chunk-RUMGXXVJ.js";import{b as pe}from"./chunk-CBOIDISB.js";import{B as T,C as Je,D as $e,E as Ae,y as zt}from"./chunk-TSBXPDUQ.js";import{r as Re,t as Ce}from"./chunk-POX2ELNS.js";import{i as Wt}from"./chunk-BBA64POP.js";import{c as fe,j as Me}from"./chunk-ZVLZLBDA.js";import{c as gt}from"./chunk-XI2NNZBS.js";import{a as P}from"./chunk-BYHBBZIO.js";import{a as F}from"./chunk-DSPLGTQI.js";async function un($,a,x){if(!$e(a))throw new P("INVALID_RESPONSE","A verified completed purchase is required");let I=$?Me.parse($):null;if(await x.onComplete?.(a),!I||!x.check)return;let H=Me.parse(await x.check());if(H.internal_feature_id!==I.internal_feature_id||H.quantity!==I.quantity||I.observation!==void 0&&(H.observation===void 0||H.observation.requirementDigest!==I.observation.requirementDigest||H.observation.authority!==I.observation.authority||gt(H.observation.subject)!==gt(I.observation.subject)))throw new P("INVALID_RESPONSE","The access requirement changed");H.allowed&&await x.onAccessGranted?.(H)}function tt($){return Object.entries($.document.buttons).filter(([,a])=>a.type==="checkout"&&a.product.type==="fixed"&&!pe(a.product,{},$.capabilities)).map(([a])=>a)}function dn($,a){let x=T(a)?void 0:a.lines[0];if(!T(a)&&(a.lines.length!==1||!x))return;let I=T(a)?a.productVersionId:x.productVersionId,{screen:H,buttons:Z}=$.document,D=new Map(T(a)?Object.entries(a.featureQuantities??{}):(x?.prepaid??[]).map(w=>[w.internal_feature_id,w.quantity]));function ee(w,p){if(w.hidden)return!1;if(w.type==="plan_picker"&&$.capabilities.pickers[w.id]?.options.includes(I))return p[w.id]=I,!0;if(w.type==="quantity_picker"){let K=D.get(w.internalFeatureId);return K!==void 0&&(!w.bind?.plan||w.bind.plan===I)&&(p[w.id]=K),!1}if(w.type==="button"&&w.action){let K=Z[w.action];return K?.type==="checkout"&&K.product.type==="fixed"&&K.product.productVersionId===I}if(w.type!=="stack")return!1;let Y=w.interaction,i=w.bind?.plan===I;for(let[K,m]of w.children.entries()){let te={},U=ee(m,te);if(Y?.type==="toggle"||Y?.type==="tabs"){if(!U)continue;return p[w.id]=Y.type==="toggle"?K===0:m.id,Object.assign(p,te),!0}Object.assign(p,te),U&&(i=!0,Y?.type==="select"&&Y.purpose==="product"&&Y.pickerId&&m.type==="stack"&&m.bind?.plan===I&&(p[w.id]=m.id,p[Y.pickerId]=I))}return i}for(let w of H.pages){let p={__page:w.id};if(ee(w.root,p))return p}}async function Jn($,a,x){let I=a.focusAtReveal?()=>{}:Pt($.ownerDocument),H=()=>{D.finish("dismissed"),I()},Z=()=>H(),D=nn($,a,"paywall",()=>{H(),F(a.onDismiss)},on);a.signal?.throwIfAborted(),a.signal?.addEventListener("abort",Z,{once:!0});let ee=null,w,p,Y;try{if(D.start(!0,a.loadingDocument?.screen.strings.defaultLocale,a.loadingDocument??null),D.cancelled)throw new DOMException("Presentation cancelled","AbortError");if(ee=a.check?Me.parse(await D.wait(a.check(),et)):null,ee?.allowed)return D.finish("skipped"),a.signal?.removeEventListener("abort",Z),I(),await a.onAccessGranted?.(ee),{check:ee,host:null};let[e,t]=await Promise.allSettled([D.wait(import("./screen-renderer-XZWKIJWF.js")),D.wait(a.start().then(r=>(D.cancelled&&r.destroy(),r)),et)]);if(e.status==="rejected")throw t.status==="fulfilled"&&t.value.destroy(),e.reason;if(t.status==="rejected")throw t.reason;Y=e.value,w=t.value,a.signal?.throwIfAborted(),w.signal?.throwIfAborted(),w.signal?.addEventListener("abort",Z,{once:!0});let n=w.view??await D.wait(w.refresh(),et);if(!n)throw new P("INVALID_RESPONSE","Paywall presentation is missing");w.signal?.throwIfAborted(),p=n}catch(e){throw D.finish("error",e),x?.retainedDialog?.release(),a.signal?.removeEventListener("abort",Z),w?.signal?.removeEventListener("abort",Z),w?.destroy(),I(),e}let i=w,{mountScreenPreview:K}=Y,m=$.ownerDocument,te=new AbortController,U=m.createElement("section"),se=m.createElement("div"),J=m.createElement("div"),nt=a.mountControls,z=nt?m.createElement("div"):void 0,d=m.createElement("p"),v=m.createElement("button"),he=m.createElement("button"),O=m.createElement("button"),ve=x?.retainedDialog,k=ve?.dialog??m.createElement("dialog"),rt=i.locale||p.document.screen.strings.defaultLocale,o=rt.toLowerCase().startsWith("zh"),fn=o?"正在处理…":"Processing…",pn=o?"正在准备报价…":"Preparing your price…",_=sn(p.document.screen.theme);U.dataset.indianaPaywall="",U.setAttribute("aria-label",p.document.name),U.style.cssText=_.root,J.style.cssText=_.controls,d.style.cssText=_.message,d.setAttribute("role","status"),O.style.cssText=_.link,O.textContent=o?"关闭":"Close",v.style.cssText=_.secondary,v.textContent=o?"重试":"Retry",v.hidden=!0,he.type="button",he.style.cssText=_.primary,he.textContent=o?"继续付款":"Continue payment",he.hidden=!0,J.append(d,he,v,O),z&&(z.style.cssText="flex:1 0 100%;min-width:0",z.hidden=!0,J.prepend(z)),U.append(se,J);let it=()=>{if(z){let r=!z.childElementCount&&!z.textContent?.trim();z.hidden!==r&&(z.hidden=r)}let e=le??J,t=[...e.children].every(r=>r===d?!d.textContent:r.hidden),n=[...e.children].some(r=>r===O?!1:r===d?!!d.textContent:!r.hidden);e.style.cssText=t?_.controls.replace(/padding:[^;]+/,"padding:0"):n?`${_.controls};${_.pinned}`:_.controls,ot()},xt=typeof MutationObserver>"u"?void 0:new MutationObserver(it);xt?.observe(U,{attributes:!0,attributeFilter:["hidden"],characterData:!0,childList:!0,subtree:!0});let Ve=ve&&p.document.presentation.type==="inline"?{type:"modal",size:"md"}:p.document.presentation,mn=Object.entries(p.document.buttons).filter(([,e])=>e.type==="close").map(([e])=>e),q,It,Oe=!1,At=JSON.stringify(p.capabilities),Qe=e=>M?[...new Set([...tt(e),...dt(e).filter(({actionId:t})=>!Dt(e).includes(t)).map(({actionId:t})=>t)])]:ce&&!ie?Object.entries(e.document.buttons).filter(([,t])=>t.type==="checkout").map(([t])=>t):tt(e);function He(e){if(g)return;p=e;let t=JSON.stringify(e.capabilities);if(t!==At){let n=!C&&!i.quote&&!i.operation?Xe(e,G,Ot):G;JSON.stringify(n)!==JSON.stringify(G)?(G=n,q?.update(e.document.screen,rt,{capabilities:me(e),unavailableActions:Qe(e),serverInput:{bindings:[],answers:{}},selection:G})):q?.updateCapabilities(me(e),Qe(e)),At=t}yn(e),Ee()}let N,at=0;function ot(){let e=m.defaultView;if(!N?.responsive||!e)return;let t=le??J,n=e.innerHeight-(N.type==="modal"?32:0);t.style.maxHeight=`${Math.max(1,n)}px`,t.style.overflowY="auto",t.style.flexShrink="0",at=Math.max(1,n-t.getBoundingClientRect().height),q?.resizeViewport?.(at,e.innerWidth)}let g=!1,ce=!1,C=null,st,je=!1,Rt=!1,ye=!1,ct,lt=!1,ne,le;function hn(){return ce||g||ne||lt?{type:"recover",operationId:i.operation?.operationId??i.quote?.operationId??null,requestId:null}:bt(i)}let A=()=>!g&&!je&&!ne&&a.canInteract?.()!==!1,W,Pe=!1,ke=!1,u=null,re=null,Be="",we=()=>a.checkoutNavigation==="after_confirmation"&&!!(a.terminateCheckout||a.resumeCheckout),G={},Ot=new Set,ie,M;function ut(e){return!!e&&T(e)&&e.timing==="immediate"&&e.execution.provider==="merchant"}let St=o?"正在确认付款…":"Confirming payment…",X=null;function dt(e){return Object.entries(e.document.buttons).flatMap(([t,n])=>n.type==="checkout"?[{actionId:t,policy:n}]:[])}function Tt(e){let t=M?.quote;return t?dt(e).filter(({actionId:n,policy:r})=>xe(t,e,n,r.product,G)).map(({actionId:n})=>n):[]}function Dt(e){return M?.phase==="payment"?Tt(e):[]}function Ee(){let e=Dt(p);if(he.hidden=M?.phase!=="payment"||e.length>0,!we()&&!M||!q?.updateCheckoutControls)return;let t=i.quote,n=!X&&!!t&&!!i.operation&&R(i.operation).type==="checkout",r=dt(p),c=M?.phase==="checking"?ie:void 0;q.updateCheckoutControls({actions:r.map(({actionId:l})=>l),resume:c?[c]:M?e:n?r.filter(({actionId:l,policy:s})=>xe(t,p,l,s.product,G)).map(({actionId:l})=>l):[],resumeLabel:c?St:o?"继续付款":M?"Continue payment":"Continue checkout",busy:ie})}function Nt(){re?.remove(),re=null}async function ft(){if(X)return;if(a.resumeCheckout&&i.operation){await a.resumeCheckout(i.operation.operationId);return}let e=await i.read();if(R(e).type!=="checkout")return V(e,!1);A()&&(Se.delete(e.operationId),await Te(e))}function Lt(){d.textContent=o?"暂时无法打开付款页面。请重试。":"Couldn’t open checkout. Try again.",v.hidden=!0}async function Ut(e=!1){let t=X;if(!t)return;v.hidden=!0;let n=Date.now()+2e4;for(;A();){let r=await i.read();if(r.operationId!==t.operationId)throw new P("PURCHASE_PENDING","The original Checkout changed");if(!A())break;let c=R(r);if(c.type==="native"){X=null,Nt(),C=t.selection,W=t.coupon,Pe=!1,ke=!1,await _e();return}if(c.type==="complete"||c.type==="fulfillment"||c.type==="recording"){X=null,await V(r,!1);return}if(e&&c.type==="checkout"){e=!1;try{await a.terminateCheckout(t.operationId)}catch(l){F(a.onError,l)}}if(Date.now()>=n)break;await Ze(1e3,m,te.signal)}g||Lt()}async function _t(e,t,n,r){if(u=()=>_t(e,t,n,r),await a.beforeCheckoutReplacement?.(structuredClone(r)),!A())return;let c=i.operation;if(c?.operationId!==e||R(c).type!=="checkout"){u=null,c&&await V(c,!1);return}X={operationId:e,selection:t,coupon:n};let l=!1;try{await a.terminateCheckout(e)}catch(s){if(s instanceof P&&["CAPABILITY_UNAVAILABLE","NOT_CONFIGURED"].includes(s.code)){X=null,d.textContent=o?"请继续原订单,或等待它过期后再更换方案。":"Continue your original checkout, or wait for it to expire before changing plans.",F(a.onError,s);return}l=s instanceof P&&(s.status??0)>=500,F(a.onError,s)}A()&&await Ut(l)}function Fe(e,t,n,r,c){let l=me(e).checkoutCoupons?.[t],s=l?l.products[n]:a.claimCoupon&&c?Wt(e.capabilities,c,r):void 0;return s?.couponId&&s.planVersionId===n?{id:s.couponId,offerId:s.offerId}:void 0}function yn(e){ce||C||i.quote||i.operation||Be&&d.textContent===Be||(d.textContent=Object.values(e.capabilities.plans).some(t=>t.available)?"":o?"当前账号暂无可购买的方案。":"No plans are currently available for this account.")}let Se=new Map,qe=!1;function xe(e,t,n,r,c,l){if(T(e)){let Q=pe(r,c,t.capabilities),de=Q&&Fe(t,n,Q,c,l),be=e.merchantTerms?.discount??(e.execution.provider==="merchant"?e.execution.discount:void 0),We=Ce(t.document.screen,e.productVersionId,c,t.capabilities);return Q===e.productVersionId&&Object.keys(We).length===Object.keys(e.featureQuantities??{}).length&&Object.entries(We).every(([ze,Ye])=>e.featureQuantities?.[ze]===Ye)&&(!de||be?.couponId===de.id&&(!de.offerId||be.grantId===de.offerId))}let s=e.lines.length===1?e.lines[0]:void 0,f=pe(r,c,t.capabilities);if(!s||!f||s.productVersionId!==f)return!1;let h=Fe(t,n,f,c,l);if((h||me(t).checkoutCoupons?.[n])&&(h?.id??null)!==(e.discount?.couponId??null))return!1;let S;try{S=Ce(t.document.screen,f,c,t.capabilities)}catch{return!1}let ae=Object.fromEntries((s.prepaid??[]).map(Q=>[Q.internal_feature_id,Q.quantity]));return[...new Set([...Object.keys(S),...Object.keys(ae)])].every(Q=>(S[Q]??0)===(ae[Q]??0))}let R=e=>Yt({quote:i.quote,operation:e,requestId:null,pending:!1,destroyed:g,canReselect:i.canReselect});async function Te(e){let t=e.merchantExecution,n=R(e),r=n.type==="checkout"?n.checkoutUrl:e.checkoutUrl;if(!(!A()||!r||Je(e)&&n.type!=="checkout"||a.checkoutNavigation==="after_confirmation"&&n.type!=="checkout"||t?.type==="purchase"&&!["not_started","pending"].includes(t.paymentStatus)||Se.get(e.operationId)===r)){Se.set(e.operationId,r);try{a.onCheckoutUrl?await a.onCheckoutUrl(r):m.defaultView?.location.assign(r)}catch(c){throw Se.delete(e.operationId),c}}}let ue=(e,t=!1)=>{if(e instanceof Ct)u=null,d.textContent=e.customerMessage(o);else if(cn(e))u=null,d.textContent=t?o?"当前无法在此购买,付款尚未开始。请联系商户。":"Purchases aren’t available here right now. Payment hasn’t started. Contact the merchant for help.":Et(e,o);else if(t){let n=e instanceof P?e.code:void 0;n==="CAPABILITY_UNAVAILABLE"||n==="NOT_CONFIGURED"?(u=null,d.textContent=o?"暂时无法为此套餐报价,付款尚未开始。":"Pricing for this plan is unavailable. Payment hasn’t started."):i.canReselect===!0&&!C?d.textContent=o?"未能取得报价,付款尚未开始。请重新选择套餐。":"We couldn’t prepare your price. Payment hasn’t started. Choose a plan again.":n==="COMMAND_PENDING"?d.textContent=o?"仍在准备报价,请重试以查看结果。":"Your price is still being prepared. Retry to check the result.":d.textContent=o?"未能取得报价,付款尚未开始。请重试。":"We couldn’t prepare your price. Payment hasn’t started. Try again."}else d.textContent=e instanceof P&&(e.code==="NETWORK_ERROR"||e.code==="TIMEOUT")?Et(e,o):e instanceof P?e.message:o?"操作未完成,请重试。":"This action couldn’t be completed. Try again.";v.hidden=u===null,Be=d.textContent,t&&ie===void 0&&!N?.responsive&&d.scrollIntoView?.({block:"nearest"}),F(t&&x?.quoteError?x.quoteError:a.onError,e)},De=new WeakMap;function Ne(e){ce=e,v.disabled=e,he.disabled=e,q?.updateCapabilities?.(me(p),Qe(p));for(let t of re?.querySelectorAll("button")??[])e?(De.has(t)||De.set(t,t.disabled),t.disabled=!0):De.has(t)&&(t.disabled=De.get(t),De.delete(t)),kt(t)}function pt(){d.textContent=o?"暂时无法操作,请稍后重试。":"This action is unavailable right now. Try again in a moment."}async function wn(e){if(a.beforeAction)try{await a.beforeAction()}catch(t){throw t instanceof Ct?(C=null,Pe=!1,ke=!1,u=null):u=e,t}}async function j(e,t){if(ce||g)return;if(!A()){pt();return}let n=e===_e,r=n?pn:fn,c=we()&&t!==void 0;ie=c?t:void 0,Ne(!0),Ee(),v.hidden=!0,d.textContent=c?"":r;try{if(e!==Bt&&e!==mt&&e!==Qt&&e!==mt&&(e!==ft||!a.resumeCheckout)&&await wn(e),g)return;if(!A()){u=e,v.hidden=!1,pt();return}await e()}catch(l){g||ue(l,n)}finally{ie=void 0,Ne(!1),Ee(),d.textContent===r&&(d.textContent="")}}async function Mt(e){await un(ee,e,a)}function Le(e,t){M=t?{quote:e,phase:t}:void 0,t==="checking"?(ie??=C?.actionId??Tt(p)[0],d.textContent=St,u=mt,v.textContent=o?"查询状态":"Check status",v.hidden=!0):ie=void 0,q?.updateCapabilities(me(p),Qe(p)),Ee()}function $t(e){return e instanceof P&&(e.code==="COMMAND_PENDING"||e.reason==="RESULT_UNKNOWN"||e.code==="NETWORK_ERROR"||e.code==="TIMEOUT"||e.status===429||(e.status??0)>=500)}function Vt(e,t){vt(e,{...t,featureQuantities:t.featureQuantities??{}},"Purchase operation changed")}async function mt(){M&&await Ue(M.quote)}async function Ue(e,t){Le(e,"checking"),Be="";let n=1e3;Oe=!0,F(a.onObservationChange,!0);try{for(let r=t;A();r=void 0){if(!r){try{r=await i.read()}catch(c){if(!$t(c))throw c}if(!A())return}if(r){Vt(r,e);let c=R(r);if(c.type==="checkout"){Le(e,"payment"),d.textContent=o?"请先完成原订单的付款。":"Finish paying for this upgrade.",v.hidden=!1;return}if(c.type==="complete"){Le(e,"complete"),u=null;let l=p.capabilities.plans[e.productVersionId]?.name,s=e.merchantTerms?.subscriptionTerms?.items,f=s?.length===1?s[0].interval:void 0,h=f==="year"?o?"年付":"annual billing":f==="month"?o?"月付":"monthly billing":null;d.textContent=l?o?`已升级到 ${l}${h?" "+h:""}。`:`Upgraded to ${l}${h?" ("+h+")":""}.`:o?"已成功升级。":"Plan upgraded.",await Mt(r);return}if(c.type==="native"&&!Ae(r)){Le(e),C=null,u=null,d.textContent=o?"付款未完成,请重新选择套餐。":"Payment failed. Choose a plan to start again.",v.textContent=o?"重试":"Retry";return}if(r.problem&&!["RESULT_UNKNOWN","STATE_CHANGED"].includes(r.problem.reason??""))throw new P(r.problem.code,o?"暂时无法完成升级。":"The upgrade needs attention.",void 0,void 0,r.problem)}await Ze(n,m,te.signal),n=Math.min(n*1.5,15e3)}}finally{Oe=!1,F(a.onObservationChange,!1)}}async function Qt(){let e=M?.quote;if(!e)return;let t=await i.read();if(Vt(t,e),R(t).type!=="checkout")return Ue(e,t);if(a.resumeCheckout){await a.resumeCheckout(t.operationId);return}Se.delete(t.operationId),await Te(t)}function Ht(e){return bt(i).type==="recording"||R(e).type==="recording"}function jt(e){let t=e.merchantTerms,n=t?.subscriptionTerms?.items??[],r=t?t.totalMinor:T(e)?e.totalMinor:e.charge?.totalMinor??e.catalogAmountMinor-(e.discount?.amountMinor??0),c=t?n.length===1&&n[0]?.amountMinor===r&&n[0]:!T(e)&&e.lines.length===1&&e.lines[0]?.catalogAmountMinor===r&&e.lines[0],l=r===null?fe(t.subtotalMinor-t.discountMinor,e.currency)+(o?" + 待确认税费":" + tax confirmed at checkout"):fe(r,e.currency)+(c?Re(c.interval,o?"zh-CN":"en",c.intervalCount??1):""),s=T(e)?i.view?.capabilities.plans[e.productVersionId]?.name??"":e.lines.map(f=>f.productName).join(", ");return{label:s?`${s} · ${l}`:l,recurring:c}}async function V(e,t=a.checkoutNavigation!=="after_confirmation"){if(g)return;if(!A()){u=async()=>V(await i.read()),v.hidden=!1;return}let n=e.quote??i.quote;if(ut(n)&&(e.confirmedAt||e.merchantExecution))return Ue(n,e);if(d.textContent=ln(e.status,o),Ht(e)){let h=e.merchantExecution?.recordingStatus==="failed";d.textContent=h?o?"付款和商户处理已完成,但交易记录失败。请联系商户修复,勿重复购买。":"Payment and fulfillment succeeded, but recording failed. Contact the merchant to repair this purchase; do not buy again.":o?"付款和商户处理已完成,正在确认交易记录。请勿重复购买。":"Payment and merchant fulfillment are complete. Recording is pending confirmation; do not purchase again.",v.textContent=o?"查询记录":"Check recording",u=async()=>V(await i.read()),v.hidden=!1;return}if(e.problem&&R(e).type!=="native"){let h=e.problem;u=Ie,v.textContent=o?"检查并恢复原操作":"Check and recover original purchase",ue(new P(h.code,h.reason==="RESULT_UNKNOWN"?o?"付款结果尚未确定,请恢复原操作,暂勿重复购买。":"The payment result is unknown. Recover the original purchase before buying again.":h.phase==="fulfillment"?o?"付款已记录,商户权益处理需要核对。":"Payment was recorded. Access fulfillment needs attention.":h.code==="CAPABILITY_UNAVAILABLE"?o?"商户尚不支持本次购买所需的完整能力,请处理后恢复原操作。":"The merchant does not currently support all actions required by this purchase. Recover the original purchase after this is resolved.":h.code==="NOT_CONFIGURED"?o?"付款服务连接需要处理,请联系商户后恢复原操作。":"The payment connection needs attention. Contact the merchant, then recover the original purchase.":o?"原购买操作需要处理,请查询或恢复此操作。":"The original purchase needs attention. Check or recover this operation.",void 0,void 0,h));return}if((e.merchantExecution?.type==="purchase"&&e.merchantExecution.paymentStatus==="succeeded"||e.merchantExecution?.type==="subscription_change"&&e.merchantExecution.status==="applied")&&!["applied","not_applicable"].includes(e.merchantExecution.fulfillmentStatus)&&(d.textContent=o?"付款已记录,正在等待商户完成处理。":"Payment was recorded. Waiting for merchant fulfillment."),$e(e)&&R(e).type==="complete"){u=null,await Mt(e);return}if(!Ae(e)&&R(e).type!=="fulfillment"){if(i.canReselect===!1){d.textContent=o?"正在核对原购买结果":"Checking the original purchase result",v.textContent=o?"查询结果":"Check result",u=async()=>V(await i.read()),v.hidden=!1;return}e.status==="cancelled"?d.textContent=o?"这笔购买已取消,可以重新选择方案。":"This purchase was cancelled. Choose a plan to start again.":e.status==="failed"&&(d.textContent=o?"这笔购买未能完成,可以重新选择方案。":"This purchase didn’t go through. Choose a plan to try again."),v.textContent=o?"重试":"Retry",u=null,C=null;return}if(!t&&R(e).type==="checkout"){if(X){Lt();return}if(we()){d.textContent="",qe=!1,u=null,Ee();return}let h=i.quote,S=h?.operationId===e.operationId?jt(h).label:"";d.textContent=qe?S?o?`${S} 尚未付款。再次选择该方案即可继续付款。`:`${S} is still unpaid. Choose it again to continue paying.`:o?"之前的购买尚未付款。再次选择该方案即可继续付款。":"Your earlier purchase is still unpaid. Choose that plan again to continue paying.":"",qe=!1,u=null;return}await Te(e);let r=Date.now(),c=r+6e5,l=2e3,s=R(e).type!=="checkout",f=()=>s&&Date.now()-r<15e3;Oe=!0,F(a.onObservationChange,!0);try{for(;!g&&Date.now()<c;){if(await Ze(f()?700:l,m,te.signal),g)return;if(!A()){u=async()=>V(await i.read()),v.hidden=!1;return}let h=await i.read();if(R(h).type==="checkout"&&(s=!1),!t&&R(h).type==="checkout"){await V(h,!1);return}if(!h.problem&&Ae(h)&&await Te(h),!Ae(h)||h.problem||Ht(h)){await V(h);return}f()||(l=Math.min(l*1.5,3e4))}}finally{Oe=!1,F(a.onObservationChange,!1)}u=async()=>V(await i.read()),v.hidden=!1}async function ht(e=!1){let t=await i.read();if(g)return;if(!A()){u=()=>ht(e),v.hidden=!1;return}let n=i.quote;if(n&&vt(t,{operationId:n.operationId,currency:n.currency},"The original purchase operation changed"),n&&(Je(t)?["prepared","quoted"].includes(t.status):t.status==="pending")&&(Je(t)||t.quoteFinalized===!1)&&!t.confirmedAt&&!t.checkoutUrl&&!("nativePurchase"in t&&t.nativePurchase)&&!t.merchantExecution&&!t.problem&&!i.pendingCancellation){if(a.purchaseConfirmation!=="paywall"){e?await Ie():u=null;return}setTimeout(Ft,0,n);return}await V(t,e||void 0)}async function Bt(){await ht()}async function Ie(){if(i.quote&&!(Date.parse(i.quote.expiresAt)>Date.now()))throw new P("INVALID_REQUEST",o?"此报价已过期,请重新选择套餐。":"This quote has expired. Choose a plan again.");Nt();let e=i.quote;if(ut(e)){Le(e,"checking");let n;try{n=await i.confirm()}catch(r){if(!$t(r))throw r;return Ue(e)}return Ue(e,n)}u=Ie;let t=await i.confirm();if(!A()){u=Ie,v.hidden=!1;return}if(t.problem){await V(t);return}if(Ae(t)){if(R(t).type==="checkout")await Te(t);else if(t.execution&&t.execution.provider!=="merchant"||"nativePurchase"in t&&t.nativePurchase){if(!a.onPurchase)throw new P("PURCHASE_HANDLER_REQUIRED","Provide the merchant or native purchase handler");await a.onPurchase({operation:t,signal:te.signal})}}u=async()=>V(await i.read()),await V(t,!0)}function Ft(e){if(g)return;re?.remove();let t=!(Date.parse(e.expiresAt)>Date.now());d.textContent=t?o?"此报价已过期。请先取消,再重新选择。":"This quote has expired. Cancel it, then choose again.":"";let n=m.createElement("div"),r=m.createElement("button"),c=m.createElement("button"),l=m.createElement("div"),s=m.createElement("p"),f=e.merchantTerms,h=o?"zh-CN":"en",S=f?.subscriptionTerms?.items??[],ae=f?f.subscriptionTerms?.trial?.days:T(e)?void 0:e.lines.find(y=>y.trial)?.trial?.days,oe=T(e)?f?f.totalMinor:e.totalMinor:ae===void 0?null:f?f.totalMinor:e.charge?e.charge.totalMinor:e.lines.every(y=>y.trial)?0:null,Q=(y,b)=>o?`${b} 天试用结束后 ${y}`:`Then ${y} after the ${b}-day trial`,{label:de,recurring:be}=jt(e),We=T(e)?i.view?.capabilities.plans[e.productVersionId]?.name??"":e.lines.map(y=>y.productName).join(", "),ze=oe===null?"":`${o?"今天应付":"Due today"} ${fe(oe,e.currency)}`;s.textContent=ze?[We,ze].filter(Boolean).join(" · "):de,r.textContent=T(e)?o?"确认变更":"Confirm change":o?"确认购买":"Confirm purchase",r.disabled=t,c.textContent=o?"取消":"Cancel",n.style.cssText=_.panel,s.style.cssText=_.summary,l.style.cssText=_.actions,r.style.cssText=_.primary,c.style.cssText=_.secondary,kt(r),r.onclick=()=>{j(Ie)};let Ye=async()=>{let y=await i.cancel();g||(n.remove(),re=null,await V(y))};c.onclick=()=>{u=Ye,j(Ye)};let B=m.createElement("div");if(B.style.cssText=_.terms,T(e)){for(let[b,E]of Object.entries(e.featureQuantities??{})){let L=i.view?.capabilities.plans[e.productVersionId]?.prepaid?.find(gn=>gn.internalFeatureId===b),Ke=m.createElement("p");Ke.textContent=`${L?.name??b} · ${E} ${o?"份":"packs"}${L?` × ${L.terms.units}`:""}`,B.append(Ke)}for(let[b,E]of[[o?"原订阅抵扣":"Unused subscription credit",e.creditMinor],[o?"新套餐费用":"New plan charge",e.debitMinor],[o?"优惠减免":"Offer savings",f?.discountMinor??e.discountMinor],[o?"税费":"Tax",f?f.taxMinor:e.taxMinor]]){let L=m.createElement("p");L.textContent=`${b}: ${E===null?o?"结账时确认":"Confirmed at checkout":fe(E,e.currency)}`,B.append(L)}let y=m.createElement("p");y.textContent=`${o?"生效时间":"Effective"}: ${e.effectiveAt}`,B.append(y)}if(f){for(let b of S){if(oe===null&&b===be)continue;let E=m.createElement("p"),L=fe(b.amountMinor,e.currency)+Re(b.interval,h,b.intervalCount);E.textContent=oe!==null&&ae!==void 0?Q(L,ae):L,b.amountAfterOfferMinor!==void 0&&(E.textContent+=` · ${o?"优惠结束后":"After the offer"} ${fe(b.amountAfterOfferMinor,e.currency)}${Re(b.interval,h,b.intervalCount)}`),B.append(E)}let y=f.subscriptionTerms?.trial;if(y){let b=m.createElement("p");b.textContent=o?`试用 ${y.days} 天;${y.cardRequired?"需要提供付款方式":"无需提供付款方式"}`:`Trial days: ${y.days}; ${y.cardRequired?"a payment method is required":"no payment method is required"}`,B.append(b)}for(let b of[...f.expectedEffects.map(E=>E.description),...f.requiredConsents.map(E=>E.summary)]){let E=m.createElement("p");E.textContent=b,B.append(E)}}else if(!T(e)){for(let y of e.lines){if(oe!==null||y!==be){let b=m.createElement("p"),E=`${fe(y.catalogAmountMinor,e.currency)}${Re(y.interval,h,y.intervalCount??1)}`;b.textContent=oe!==null&&y.trial?(e.lines.length>1?`${y.productName} · `:"")+Q(E,y.trial.days):`${y.productName} · ${E}`,B.append(b)}for(let b of y.prepaid??[]){let E=m.createElement("p"),L=i.view?.capabilities.plans[y.productVersionId]?.prepaid?.find(Ke=>Ke.internalFeatureId===b.internal_feature_id);E.textContent=`${L?.name??b.internal_feature_id} · ${b.quantity} ${o?"份":"packs"} × ${b.terms.units}`,L&&(E.textContent+=Re(L.reset==="week"||L.reset==="month"||L.reset==="year"?L.reset:"one_time",h,L.resetCount)),B.append(E)}if(y.trial){let b=m.createElement("p");b.textContent=o?`试用 ${y.trial.days} 天;${y.trial.cardRequired?"需要提供付款方式":"无需提供付款方式"}`:`Trial days: ${y.trial.days}; ${y.trial.cardRequired?"a payment method is required":"no payment method is required"}`,B.append(b)}}if(!e.charge){let y=m.createElement("p");y.textContent=o?"目录价格;最终金额以结账时税费和试用规则为准。":"Catalog price; the final charge depends on checkout taxes and trial terms.",B.append(y)}}for(let y of B.children)y.style.margin="0";l.append(r,c),n.append(s,...B.childElementCount?[B]:[],l),J.prepend(n),N?.responsive||n.scrollIntoView?.({block:"nearest"}),r.focus({preventScroll:!0}),re=n,ce&&Ne(!0),u=null}async function _e(){if(!C)return;if(u=_e,!Pe){let n=i.view,r=n?.document.buttons[C.actionId],c=n&&r?.type==="checkout"?pe(r.product,C.selection,n.capabilities):null;if(!n||!c)throw new P("PRODUCT_UNAVAILABLE","Choose an available Product in this purchase area");if(!ke){let s=await a.resolveSubscriptionChange?.({actionId:C.actionId,productVersionId:c,featureQuantities:Ce(n.document.screen,c,C.selection,n.capabilities)});if(g)return;s!==void 0&&(C.subscriptionChange=zt.parse(s)),ke=!0}let l=W?.offerId;if(W&&!l){if(!a.claimCoupon)throw new P("CAPABILITY_UNAVAILABLE","Coupon claiming is unavailable");let{offer:s}=await a.claimCoupon(W.id,C.requestId);if(g)return;if(!s||s.couponId!==W.id||s.status!=="issued"||!(Date.parse(s.expiresAt)>Date.now()))throw C=null,W=void 0,u=async()=>{He(await i.refresh()),u=null},new P("COUPON_UNAVAILABLE","This Coupon is no longer available for this purchase");l=s.id}if(!W&&!n.document.screen.actions.some(s=>s.id===C?.actionId&&typeof s.properties.couponBinding=="string")&&(l=await a.resolveOfferId?.({actionId:C.actionId,productVersionId:c,featureQuantities:Ce(n.document.screen,c,C.selection,n.capabilities)})),g)return;l!==void 0&&(C.offerId=l),Pe=!0}if(!A()){v.hidden=!1;return}let e;try{e=await i.preview(C)}catch(n){throw i.canReselect===!0&&(C=null,Pe=!1,ke=!1,W=void 0,u=null),n}if(W&&(T(e)?(()=>{let n=e.merchantTerms?.discount??(e.execution.provider==="merchant"?e.execution.discount:void 0);return n?.couponId!==W.id||n.grantId!==C.offerId})():e.discount?.couponId!==W.id||e.discount.offerId!==C.offerId))throw new P("INVALID_RESPONSE","The quote did not apply the Coupon selected on this Paywall");if(g)return;let t=e.merchantTerms;if(a.purchaseConfirmation!=="paywall"||a.confirmOnHostedCheckout&&A()&&!T(e)&&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()){if(!A()){v.hidden=!1;return}if(!(Date.parse(e.expiresAt)>Date.now()))throw new P("INVALID_REQUEST",o?"此报价已过期,请重新选择套餐。":"This quote has expired. Choose a plan again.");let n=ie?"":o?"正在打开收银台…":"Opening checkout…";d.textContent=n;try{await Ie()}catch(r){g||ue(r)}finally{d.textContent===n&&(d.textContent="")}return}Ft(e)}function ge(e="destroy",t=!1){if(g)return;g=!0;let n=st;st=void 0,F(n),a.signal?.removeEventListener("abort",Z),i.signal?.removeEventListener("abort",Z),D.finish("dismissed"),It?.(),te.abort(),xt?.disconnect(),q?.destroy(),i.destroy(),k.removeEventListener("cancel",Gt),O.remove(),U.remove(),t||qt(),e==="dismiss"&&F(a.onDismiss)}function qt(){if(N?.destroy(),ve){ve.release();return}k.open&&k.close(),k.remove(),I()}H=ge;async function Ge(){if(!ye||g||je||ne==="closing"||!ne&&!A())return;if(!x){ge("dismiss");return}let e=m.createElement("p");e.setAttribute("role","status"),e.textContent=o?"正在关闭…":"Closing…",le||(le=m.createElement("div"),le.style.cssText=J.style.cssText,J.replaceWith(le),se.inert=!0),O.hidden=!1,le.replaceChildren(e,O),ne="closing",O.setAttribute("aria-disabled","true"),O.focus({preventScroll:!0});try{await x.dismiss()}catch(t){g||F(a.onError,t)}g||(ne="retry",e.textContent=o?"未能确认关闭,请重试。":"Could not confirm closure. Try again.",O.textContent=o?"重试关闭":"Retry closing",O.removeAttribute("aria-label"),O.removeAttribute("aria-disabled"))}O.onclick=()=>{Ge()};function Gt(e){e.preventDefault(),Ge()}k.addEventListener("cancel",Gt),v.onclick=()=>{u&&j(u)};function yt(e){D.finish("error",e),ge()}function wt(){if(!(!Rt||ye||g||je||N&&!A()))try{let e=t=>{a.focusAtReveal&&(I=Pt(m)),q?.setHidden?.(!1),ct?.(),N&&(k.open||k.showModal(),N.responsive&&k.focus({preventScroll:!0}),!t&&a.loading!=="host"&&en(k,N.type,N.responsive)),t&&a.loading!=="host"&&typeof se.animate=="function"&&!m.defaultView?.matchMedia?.("(prefers-reduced-motion: reduce)").matches&&se.animate([{opacity:.55},{opacity:1}],{duration:160,easing:"ease-out"}),ye=!0};x?x.present(t=>D.present(n=>e(t??n))):D.present(e)}catch(e){yt(e),ue(e)}}try{if(Ve.type==="inline"?(it(),ct=an(U,$),$.append(U)):(k.setAttribute("aria-label",p.document.name),O.textContent="×",O.setAttribute("aria-label",o?"关闭":"Close"),tn(O,p.document.screen.theme),O.hidden=Xt(p.document),k.replaceChildren(O,U),ve||$.append(k),N=Zt(k,{...p.document.screen,presentation:Ve},ot),N.latch(),N.responsive&&(U.style.display="flex",U.style.flexDirection="column",U.style.maxHeight="100%",se.style.overflow="clip",se.style.minHeight="0"),ve||(ct=rn(k))),nt&&z){let n=nt(z);if(typeof n=="function"&&(g?F(n):st=n),g)throw new DOMException("Presentation cancelled","AbortError");it()}q=K(se,{mode:"live",loadingLayout:()=>D.getLoadingLayout?.()??x?.loadingLayout?.(),rendererUrl:"bundled",title:p.document.name,closeActions:mn,onAuthoredClose(n){ne||g||(O.hidden=n)},hostPresentation:()=>N?.type??Ve.type,reportContentHeight:N?.responsive,onResize:n=>{if(!N?.responsive)return;let r=Math.min(n,at);se.style.height=`${r}px`,N.setContentHeight(r+(le??J).getBoundingClientRect().height)},onSelection(n){for(let[r,c]of Object.entries(n))typeof c=="number"&&typeof G[r]=="number"&&G[r]!==c&&Ot.add(r);G=n,Ee()},onAction(n,r={},c,l){if(!ye||g||ne)return;let s=i.view,f=s?.document.buttons[n];if(!f)return;if(f.type==="close"&&x&&a.resumeCheckout&&i.operation&&Kt(R(i.operation))){Ge();return}if(ce)return;if(!A()){pt();return}if(f.type==="close"){j(async()=>{x?.closeAction?await x.closeAction(n):await a.onAction?.(n),ge(a.onAction?"action":"dismiss")});return}if(f.type==="action"){u=async()=>{if(f.action.type==="event"){if(!a.onEvent)throw new P("EVENT_HANDLER_REQUIRED","Provide the event handler");await a.onEvent(f.action.event)}else a.onOpenUrl?await a.onOpenUrl(f.action.url):m.defaultView?.location.assign(f.action.url);await a.onAction?.(n),u=null},j(u);return}if(M){M.phase==="payment"&&s&&xe(M.quote,s,n,f.product,r,l)&&j(Qt,n);return}if(a.allowNewPurchase===!1){we()&&s&&i.quote&&i.operation&&R(i.operation).type==="checkout"&&xe(i.quote,s,n,f.product,r,l)?j(ft,n):d.textContent=o?"当前只能继续原订单。":"Only your original checkout is available.";return}if(re&&i.canReselect===!1){d.textContent=o?"请先确认或取消当前购买。":"Confirm or cancel the current purchase first.",N?.responsive||re.scrollIntoView?.({block:"nearest"}),re.querySelector("button")?.focus({preventScroll:!0});return}if(we()&&X){X.selection.actionId===n&&j(()=>Ut(!0),n);return}if(we()&&a.terminateCheckout&&s&&i.quote&&i.operation&&i.canReselect===!1&&R(i.operation).type==="checkout"){if(xe(i.quote,s,n,f.product,r,l)){j(ft,n);return}let S=pe(f.product,r,s.capabilities),ae;try{if(!S)throw new P("PRODUCT_UNAVAILABLE","Choose an available Product in this purchase area");ae=Ce(s.document.screen,S,r,s.capabilities)}catch(be){ue(be);return}let oe=i.operation.operationId,Q={actionId:n,requestId:crypto.randomUUID(),selection:structuredClone(r)},de=Fe(s,n,S,r,l);j(()=>_t(oe,Q,de,{actionId:n,productVersionId:S,selection:Q.selection,featureQuantities:ae}),n);return}if((i.quote||C)&&i.canReselect===!1){let S=!!s&&!!i.quote&&xe(i.quote,s,n,f.product,r,l);qe=!!i.quote&&!S,u=i.quote?()=>ht(S):_e,j(u);return}let h=s&&pe(f.product,r,s.capabilities);if(!s||!h){ue(new P("PRODUCT_UNAVAILABLE","Choose an available Product in this purchase area"));return}if(a.onPurchaseIntent){u=null,j(async()=>{let S={actionId:n,productVersionId:h,selection:structuredClone(r),featureQuantities:Ce(s.document.screen,h,r,s.capabilities)};lt=!0,await a.onPurchaseIntent(S)});return}if(C&&C.actionId!==n){ue(new P("COMMAND_PENDING","Finish the current purchase"));return}C||(W=Fe(s,n,h,r,l),C={requestId:crypto.randomUUID(),actionId:n,selection:structuredClone(r)},Pe=!1,ke=!1),j(_e,n)},onEscape:()=>{Ge()},onError:n=>{let r=new Error(n);!ye&&!g&&yt(r),ue(r)},onRendered:n=>{n&&k.setAttribute("aria-label",n),Rt=!0,wt()}}),q.setHidden?.(!0),ot();let e=we()&&!!i.quote&&!!i.operation&&R(i.operation).type==="checkout";G=i.quote?dn(p,i.quote)??Xe(p,{}):Xe(p,{}),q.update(p.document.screen,rt,{capabilities:me(p),unavailableActions:tt(p),serverInput:{bindings:[],answers:{}},...Object.keys(G).length?{selection:G}:{}}),It=i.subscribe?.(He),He(i.view??p),await D.wait(q.ready);let t=i.operation;(!e||ut(i.quote))&&(i.quote||t&&(t.confirmedAt||t.checkoutUrl||$e(t)))&&(u=Bt,j(u))}catch(e){throw yt(e),e}return{check:ee,host:{get subscriptionUpgradeActive(){return M!==void 0},get observing(){return Oe},get recovery(){return hn()},async prepareFallback(){if(ce||g||ne||lt)return{type:"recover",operationId:i.operation?.operationId??i.quote?.operationId??null,requestId:null};Ne(!0);try{let e=await Jt(i);return e.type==="native"&&ge(),e}finally{Ne(!1)}},setSuspended(e){je=e,U.hidden=e,e&&k.open?k.close():!e&&!ye?wt():!e&&!g&&ye&&Ve.type!=="inline"&&!k.open&&k.showModal()},destroy:ge,retainPurchaseDialog(){if(!(g||!k.open||!k.isConnected))return ge("destroy",!0),{dialog:k,release:qt}},refresh:async()=>{if(!A()){if(i.view)return i.view;throw new P("PRECONDITION_FAILED","Paywall presentation is suspended")}let e=await i.refresh();return He(e),wt(),e}}}}export{Jn as a};