@tinkerlandai/longplay-sdk 0.10.69 → 0.10.71

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 (102) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +1 -1
  3. package/dist/check-response-3EFQG3PL.js +1 -0
  4. package/dist/{chunk-VMYLTNDS.js → chunk-24Z5QET3.js} +1 -1
  5. package/dist/{chunk-YDPF2ZZW.js → chunk-3KIATB75.js} +1 -1
  6. package/dist/{chunk-3NV6NBQB.js → chunk-44SX4C3G.js} +1 -1
  7. package/dist/{chunk-ZRU7WONE.js → chunk-4C4L3JER.js} +1 -1
  8. package/dist/{chunk-BGCCW5QX.js → chunk-4HMPCJOG.js} +2 -2
  9. package/dist/chunk-4XDMBMDA.js +1 -0
  10. package/dist/{chunk-DXNTXCSI.js → chunk-5M2IIZB6.js} +1 -1
  11. package/dist/{chunk-5MOJUGMA.js → chunk-5XMHY7QX.js} +1 -1
  12. package/dist/{chunk-G3YIPDT6.js → chunk-6A4NV4ET.js} +1 -1
  13. package/dist/{chunk-USH4WN6W.js → chunk-6ZUJCHBI.js} +1 -1
  14. package/dist/{chunk-44ZJPQM6.js → chunk-AFQHUBKJ.js} +1 -1
  15. package/dist/chunk-BZRDECZJ.js +10 -0
  16. package/dist/{chunk-DZYMD4MJ.js → chunk-DGMRFL7K.js} +1 -1
  17. package/dist/{chunk-KJTHMRSH.js → chunk-DJTMSBQN.js} +1 -1
  18. package/dist/{chunk-ULED3B5P.js → chunk-EPQUD3S5.js} +1 -1
  19. package/dist/{chunk-LBYMDTGD.js → chunk-EU4NTVRT.js} +1 -1
  20. package/dist/{chunk-T5SCW4IA.js → chunk-F46VXI3Q.js} +1 -1
  21. package/dist/{chunk-6C3ARFEL.js → chunk-G7JQNJM4.js} +1 -1
  22. package/dist/{chunk-GBUGEL6M.js → chunk-IR6ELT3D.js} +1 -1
  23. package/dist/{chunk-NEW77IDA.js → chunk-IUX4CJZM.js} +1 -1
  24. package/dist/{chunk-UFTKCFNI.js → chunk-IXYVLURA.js} +1 -1
  25. package/dist/{chunk-TFPLIX5E.js → chunk-IYVJOUO7.js} +1 -1
  26. package/dist/chunk-KNZ3WTQ5.js +1 -0
  27. package/dist/{chunk-QTXHF27F.js → chunk-LHUZRVAC.js} +1 -1
  28. package/dist/{chunk-6GY2YT3U.js → chunk-LQ2XY26R.js} +1 -1
  29. package/dist/{chunk-SGOVJD5P.js → chunk-MAKRT62V.js} +1 -1
  30. package/dist/{chunk-Q4GG33R5.js → chunk-MUW3SOTB.js} +1 -1
  31. package/dist/{chunk-NNJ7W4KY.js → chunk-NCMKY7D6.js} +1 -1
  32. package/dist/{chunk-WVTKVQLZ.js → chunk-ONYG4VQI.js} +1 -1
  33. package/dist/{chunk-ECUGL7AO.js → chunk-PYM47Z55.js} +1 -1
  34. package/dist/{chunk-2ZMIM4MO.js → chunk-Q5DB34R4.js} +1 -1
  35. package/dist/chunk-QIV2YOVB.js +1 -0
  36. package/dist/{chunk-CQ5EQNQA.js → chunk-RZ7WFYWY.js} +1 -1
  37. package/dist/{chunk-MT4OQFDI.js → chunk-TDMXEI2U.js} +1 -1
  38. package/dist/chunk-TFGIDUGW.js +1 -0
  39. package/dist/{chunk-LUVTP4VU.js → chunk-TLQUUC3G.js} +1 -1
  40. package/dist/{chunk-JW4MSBYN.js → chunk-TNWZWEEY.js} +1 -1
  41. package/dist/{chunk-5NCQOJR2.js → chunk-TYIAPLQP.js} +1 -1
  42. package/dist/{chunk-ST7XO45I.js → chunk-ULJJTIL5.js} +1 -1
  43. package/dist/chunk-UOJSZMKN.js +1 -0
  44. package/dist/chunk-UR2PWRLG.js +1 -0
  45. package/dist/{chunk-26QYDE7V.js → chunk-UWHTCMMF.js} +1 -1
  46. package/dist/{chunk-TYJWRPJY.js → chunk-VCUJMMEM.js} +1 -1
  47. package/dist/{chunk-EJSTRCBQ.js → chunk-YV4HA2DV.js} +1 -1
  48. package/dist/{chunk-2SSOV3OG.js → chunk-ZFNSXRQY.js} +1 -1
  49. package/dist/{chunk-EQ64JD4L.js → chunk-ZJXQTMBW.js} +1 -1
  50. package/dist/{chunk-RMR64P6V.js → chunk-ZVVDPXHC.js} +1 -1
  51. package/dist/content-F3LHKR2S.js +1 -0
  52. package/dist/funnel-host-purchase-WJ2GKXKT.js +1 -0
  53. package/dist/{funnel-host-recovery-paywall-KHBGMNS5.js → funnel-host-recovery-paywall-OANZILW3.js} +1 -1
  54. package/dist/{funnel-local-client-Cb9jJGpo.d.ts → funnel-local-client-2Yx0Q_lF.d.ts} +27 -0
  55. package/dist/{funnel-paywall-copies-A76T5V7B.js → funnel-paywall-copies-ZI6BLXH7.js} +1 -1
  56. package/dist/funnel-paywall-prerender-36ER2LYV.js +1 -0
  57. package/dist/{funnel-process-client-DE650LzB.d.ts → funnel-process-client-BTusJtqx.d.ts} +10 -1
  58. package/dist/funnel-route-prediction-IO6TEHFN.js +1 -0
  59. package/dist/funnel-route-source-VQQIKYXL.js +1 -0
  60. package/dist/funnel-runtime-host-LXIT2QY7.js +1 -0
  61. package/dist/index.d.ts +22 -6
  62. package/dist/index.js +1 -1
  63. package/dist/merchant-bridge-contracts-CJY7TX6J.js +1 -0
  64. package/dist/native-shell.js +1 -1
  65. package/dist/openrouter.js +1 -1
  66. package/dist/operation-contracts-FAW24KGA.js +1 -0
  67. package/dist/page.js +1 -1
  68. package/dist/paywall-TVYLGNDU.js +1 -0
  69. package/dist/paywall-content-NLEGSOUT.js +1 -0
  70. package/dist/paywall-session-ADXZWQPU.js +1 -0
  71. package/dist/popup.d.ts +56 -3
  72. package/dist/popup.js +1 -1
  73. package/dist/{presentation-loading-B8W6a9WB.d.ts → presentation-loading-CU4c-koG.d.ts} +3 -1
  74. package/dist/react-native.d.ts +4 -4
  75. package/dist/react-native.js +1 -1
  76. package/dist/screen-renderer-EWRXGDWQ.js +1 -0
  77. package/dist/server.d.ts +20 -2
  78. package/dist/server.js +1 -1
  79. package/dist/visual.js +1 -1
  80. package/package.json +1 -1
  81. package/dist/check-response-754GDUOJ.js +0 -1
  82. package/dist/chunk-2BSDXKQS.js +0 -1
  83. package/dist/chunk-57ZXT7AS.js +0 -1
  84. package/dist/chunk-5U7LC2NL.js +0 -1
  85. package/dist/chunk-CWBBW6QS.js +0 -10
  86. package/dist/chunk-F5ABUGHD.js +0 -1
  87. package/dist/chunk-JAH62B6J.js +0 -1
  88. package/dist/chunk-UIR5CBCC.js +0 -1
  89. package/dist/content-66BI72XB.js +0 -1
  90. package/dist/funnel-host-purchase-YPAWZLXP.js +0 -1
  91. package/dist/funnel-paywall-prerender-PNJXR4VC.js +0 -1
  92. package/dist/funnel-route-prediction-KFUCAJLL.js +0 -1
  93. package/dist/funnel-route-source-WEYKNM2C.js +0 -1
  94. package/dist/funnel-runtime-host-RWU52BJ7.js +0 -1
  95. package/dist/merchant-bridge-contracts-RWNJHBTR.js +0 -1
  96. package/dist/operation-contracts-NNWS467N.js +0 -1
  97. package/dist/paywall-BSY67NQL.js +0 -1
  98. package/dist/paywall-content-RAB5S6KB.js +0 -1
  99. package/dist/paywall-session-CRIGHMOQ.js +0 -1
  100. package/dist/screen-renderer-H3FBGJZB.js +0 -1
  101. /package/dist/{chunk-BGCCW5QX.js.LEGAL.txt → chunk-4HMPCJOG.js.LEGAL.txt} +0 -0
  102. /package/dist/{chunk-S7NHVERO.js → chunk-CTCK5BUY.js} +0 -0
@@ -1 +1 @@
1
- import"./chunk-6C3ARFEL.js";import"./chunk-5NCQOJR2.js";import"./chunk-MT4OQFDI.js";import"./chunk-KJTHMRSH.js";import{a as i}from"./chunk-ZRU7WONE.js";import"./chunk-TFPLIX5E.js";import"./chunk-G3YIPDT6.js";import"./chunk-5MRSFLQA.js";import{b as A}from"./chunk-S7NHVERO.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-G7JQNJM4.js";import"./chunk-TYIAPLQP.js";import"./chunk-TDMXEI2U.js";import"./chunk-DJTMSBQN.js";import{a as i}from"./chunk-4C4L3JER.js";import"./chunk-IYVJOUO7.js";import"./chunk-6A4NV4ET.js";import"./chunk-5MRSFLQA.js";import{b as A}from"./chunk-CTCK5BUY.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-6ZUJCHBI.js";import"./chunk-NCMKY7D6.js";import"./chunk-ZFNSXRQY.js";import"./chunk-EPQUD3S5.js";import"./chunk-PYM47Z55.js";import"./chunk-44SX4C3G.js";import"./chunk-MUW3SOTB.js";import"./chunk-ONYG4VQI.js";import"./chunk-LHUZRVAC.js";import"./chunk-AFQHUBKJ.js";import"./chunk-VILB5M4X.js";import"./chunk-TYIAPLQP.js";import"./chunk-DJTMSBQN.js";import"./chunk-TNWZWEEY.js";import"./chunk-YV4HA2DV.js";import"./chunk-UWHTCMMF.js";import"./chunk-DGMRFL7K.js";import"./chunk-TLQUUC3G.js";import"./chunk-IYVJOUO7.js";import"./chunk-CTCK5BUY.js";import"./chunk-VPT5MFDG.js";import"./chunk-CILM5XMH.js";import"./chunk-WOT6VMZA.js";export{o as apiOperations};
package/dist/page.js CHANGED
@@ -1 +1 @@
1
- import{d as o,e as r,f as e,g as f}from"./chunk-BGCCW5QX.js";import"./chunk-MB2U2GWJ.js";import"./chunk-3VUPVXAV.js";import"./chunk-G3YIPDT6.js";import"./chunk-5MRSFLQA.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-4HMPCJOG.js";import"./chunk-MB2U2GWJ.js";import"./chunk-3VUPVXAV.js";import"./chunk-6A4NV4ET.js";import"./chunk-5MRSFLQA.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};
@@ -0,0 +1 @@
1
+ import{a}from"./chunk-4XDMBMDA.js";import"./chunk-LQ2XY26R.js";import"./chunk-W32FI2A2.js";import"./chunk-UR2PWRLG.js";import"./chunk-EU4NTVRT.js";import"./chunk-RZ7WFYWY.js";import"./chunk-MUW3SOTB.js";import"./chunk-ONYG4VQI.js";import"./chunk-LHUZRVAC.js";import"./chunk-VILB5M4X.js";import"./chunk-TDMXEI2U.js";import"./chunk-DJTMSBQN.js";import"./chunk-TNWZWEEY.js";import"./chunk-YV4HA2DV.js";import"./chunk-UWHTCMMF.js";import"./chunk-DGMRFL7K.js";import"./chunk-TLQUUC3G.js";import"./chunk-4C4L3JER.js";import"./chunk-IYVJOUO7.js";import"./chunk-6A4NV4ET.js";import"./chunk-5MRSFLQA.js";import"./chunk-CTCK5BUY.js";import"./chunk-DSPLGTQI.js";import"./chunk-VPT5MFDG.js";import"./chunk-CILM5XMH.js";import"./chunk-WOT6VMZA.js";export{a as showPaywall};
@@ -0,0 +1 @@
1
+ import{b as a}from"./chunk-ULJJTIL5.js";import"./chunk-EPQUD3S5.js";import"./chunk-PYM47Z55.js";import"./chunk-44SX4C3G.js";import"./chunk-MUW3SOTB.js";import"./chunk-ONYG4VQI.js";import"./chunk-LHUZRVAC.js";import"./chunk-AFQHUBKJ.js";import"./chunk-VILB5M4X.js";import"./chunk-TDMXEI2U.js";import"./chunk-DJTMSBQN.js";import"./chunk-TNWZWEEY.js";import"./chunk-YV4HA2DV.js";import"./chunk-UWHTCMMF.js";import"./chunk-DGMRFL7K.js";import"./chunk-TLQUUC3G.js";import"./chunk-4C4L3JER.js";import"./chunk-IYVJOUO7.js";import"./chunk-3VUPVXAV.js";import"./chunk-6A4NV4ET.js";import"./chunk-5MRSFLQA.js";import"./chunk-CTCK5BUY.js";import"./chunk-VPT5MFDG.js";import"./chunk-CILM5XMH.js";import"./chunk-WOT6VMZA.js";export{a as readPaywallContent};
@@ -0,0 +1 @@
1
+ import{a}from"./chunk-IXYVLURA.js";import"./chunk-6ZUJCHBI.js";import"./chunk-NCMKY7D6.js";import"./chunk-F46VXI3Q.js";import"./chunk-EU4NTVRT.js";import"./chunk-RZ7WFYWY.js";import"./chunk-ZFNSXRQY.js";import"./chunk-MAKRT62V.js";import"./chunk-ULJJTIL5.js";import"./chunk-EPQUD3S5.js";import"./chunk-PYM47Z55.js";import"./chunk-44SX4C3G.js";import"./chunk-MUW3SOTB.js";import"./chunk-ONYG4VQI.js";import"./chunk-LHUZRVAC.js";import"./chunk-AFQHUBKJ.js";import"./chunk-VILB5M4X.js";import"./chunk-TYIAPLQP.js";import"./chunk-TDMXEI2U.js";import"./chunk-DJTMSBQN.js";import"./chunk-TNWZWEEY.js";import"./chunk-YV4HA2DV.js";import"./chunk-UWHTCMMF.js";import"./chunk-DGMRFL7K.js";import"./chunk-TLQUUC3G.js";import"./chunk-4C4L3JER.js";import"./chunk-IYVJOUO7.js";import"./chunk-3VUPVXAV.js";import"./chunk-6A4NV4ET.js";import"./chunk-5MRSFLQA.js";import"./chunk-CTCK5BUY.js";import"./chunk-DSPLGTQI.js";import"./chunk-VPT5MFDG.js";import"./chunk-CILM5XMH.js";import"./chunk-WOT6VMZA.js";export{a as createPaywallSession};
package/dist/popup.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { b as ScreenAction, c as ScreenNode, d as ScreenInteractivity, e as ScreenDocument } from './screen-Pv_pViF6.js';
2
2
  import { O as Offer, a as OfferUnavailableReason } from './coupon-kfkIVf9n.js';
3
- import { e as CustomerPageData, a as SurfaceData, P as PresentationLoadingOptions, f as ScreenParameters, g as ScreenRendererInput, S as ScreenAnswers, C as CustomerDataIntent } from './presentation-loading-B8W6a9WB.js';
4
- export { d as PresentationState } from './presentation-loading-B8W6a9WB.js';
3
+ import { e as CustomerPageData, a as SurfaceData, P as PresentationLoadingOptions, f as ScreenParameters, g as ScreenRendererInput, S as ScreenAnswers, C as CustomerDataIntent, D as DialogHost } from './presentation-loading-CU4c-koG.js';
4
+ export { d as PresentationState } from './presentation-loading-CU4c-koG.js';
5
5
  import { WindowLike } from 'dompurify';
6
6
  import 'zod';
7
7
 
@@ -69,6 +69,21 @@ type ScreenNodeRect = {
69
69
  width: number;
70
70
  height: number;
71
71
  };
72
+ /** Text styles drawn on the current page and the state of each brand face. */
73
+ type ScreenFontInspection = {
74
+ used: {
75
+ family: string;
76
+ weight: number;
77
+ style: string;
78
+ count: number;
79
+ }[];
80
+ faces: {
81
+ family: string;
82
+ weight: number;
83
+ /** `dropped`: the opening-font rule removed its family for this display. */
84
+ status: "loaded" | "loading" | "unloaded" | "error" | "dropped";
85
+ }[];
86
+ };
72
87
  /**
73
88
  * Live purchase buttons the host is driving: `resume` actions read `resumeLabel` (the original
74
89
  * Checkout continues) and the `busy` action spins while every listed action is held.
@@ -189,6 +204,8 @@ type ScreenPreviewHandle = {
189
204
  setHidden(hidden: boolean): void;
190
205
  /** 编辑模式下的悬停与选中描边。 */
191
206
  highlight(hoverId: string | null, selectedId: string | null): void;
207
+ /** Preview diagnostics from the rendered page; null when this renderer cannot answer. */
208
+ inspect?(): Promise<ScreenFontInspection | null>;
192
209
  destroy(): void;
193
210
  };
194
211
  /**
@@ -228,6 +245,8 @@ declare function mountScreenPreview(container: HTMLElement, options?: {
228
245
  /** For hosts that already budgeted their viewport, report the unclipped content height. */
229
246
  reportContentHeight?: boolean;
230
247
  onResize?: (height: number) => void;
248
+ /** The unclipped content height, for previews comparing it with the visible area. */
249
+ onContentHeight?: (height: number) => void;
231
250
  /** Editing-only geometry in iframe viewport coordinates; no DOM access across the sandbox. */
232
251
  onLayout?: (nodes: ScreenNodeRect[]) => void;
233
252
  /** Editing-only shortcuts typed while focus is inside the canvas. */
@@ -244,4 +263,38 @@ type CustomerPageHandle = {
244
263
  destroy(): void;
245
264
  };
246
265
 
247
- export { type CustomerPageHandle, type HtmlCodeDiagnostic, type PopupEvent, type PopupHandle, type PopupOptions, type PreparedPopupHandle, PresentationLoadingOptions, type RendererEditorKey, type RendererEditorMessages, ScreenDocument, type ScreenNodeRect, type ScreenPreviewHandle, formatCustomerDecimal, hostedRendererScript, hostedRendererShell, inspectCustomHtml, mountScreenPreview, preparePopup, prepareScreen, sanitizeCustomHtml, showPopup };
266
+ type DialogPreviewOptions = {
267
+ /** The live host this design appears in: `mountContent`, a Funnel screen or a Paywall. */
268
+ host: DialogHost;
269
+ /** Actions that close the screen; a visible authored Close hides the Funnel or Paywall corner Close. */
270
+ closeActions?: readonly string[];
271
+ locale: string;
272
+ capabilities?: SurfaceData;
273
+ customerData?: CustomerPageData;
274
+ title?: string;
275
+ closeLabel: string;
276
+ rendererUrl?: string;
277
+ onAction?: (actionId: string, selection?: Record<string, string | boolean | number>) => void;
278
+ onPageChange?: (pageId: string) => void;
279
+ /** The host Close control, its sheet grip, a click outside or Escape. */
280
+ onDismiss?: (reason: "close_button" | "escape") => void;
281
+ /** The unclipped content height and the height shown without scrolling. */
282
+ onContentHeight?: (content: number, visible: number) => void;
283
+ onError?: (message: string) => void;
284
+ };
285
+ type DialogPreviewHandle = {
286
+ /** The presentation the host chose for this viewport. */
287
+ readonly presentation: ScreenDocument["presentation"]["type"];
288
+ /** Fonts drawn by the rendered page; null when the renderer cannot answer. */
289
+ inspect(): Promise<ScreenFontInspection | null>;
290
+ destroy(): void;
291
+ };
292
+ /**
293
+ * A screen inside the outer frame its live host draws, for Console previews.
294
+ * Mount it in a same-origin device viewport: the dialog, its backdrop and
295
+ * viewport units then resolve against that device. Actions are reported, never
296
+ * executed.
297
+ */
298
+ declare function mountDialogPreview(container: HTMLElement, screen: ScreenDocument, options: DialogPreviewOptions): DialogPreviewHandle;
299
+
300
+ export { type CustomerPageHandle, DialogHost, type DialogPreviewHandle, type DialogPreviewOptions, type HtmlCodeDiagnostic, type PopupEvent, type PopupHandle, type PopupOptions, type PreparedPopupHandle, PresentationLoadingOptions, type RendererEditorKey, type RendererEditorMessages, ScreenDocument, type ScreenFontInspection, type ScreenNodeRect, type ScreenPreviewHandle, formatCustomerDecimal, hostedRendererScript, hostedRendererShell, inspectCustomHtml, mountDialogPreview, mountScreenPreview, preparePopup, prepareScreen, sanitizeCustomHtml, showPopup };
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-CWBBW6QS.js";import"./chunk-57ZXT7AS.js";import"./chunk-JW4MSBYN.js";import"./chunk-EJSTRCBQ.js";import"./chunk-26QYDE7V.js";import"./chunk-DZYMD4MJ.js";import"./chunk-LUVTP4VU.js";import"./chunk-ZRU7WONE.js";import"./chunk-TFPLIX5E.js";import"./chunk-S7NHVERO.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 _,b as z,c as M,d as U,e as W,f as q,g as V,h as j,i as S}from"./chunk-BZRDECZJ.js";import{a as H,b as x,d as y,f as C,g as A,m as E}from"./chunk-UR2PWRLG.js";import"./chunk-TNWZWEEY.js";import{D as b}from"./chunk-YV4HA2DV.js";import"./chunk-UWHTCMMF.js";import"./chunk-DGMRFL7K.js";import"./chunk-TLQUUC3G.js";import"./chunk-4C4L3JER.js";import"./chunk-IYVJOUO7.js";import"./chunk-CTCK5BUY.js";import{a as p}from"./chunk-DSPLGTQI.js";import"./chunk-VPT5MFDG.js";import"./chunk-CILM5XMH.js";import"./chunk-WOT6VMZA.js";function O(m,r,n){let d=m.ownerDocument,s=d.defaultView;if(!s)throw new Error("Preview container has no browser window");let l=!1,u=!1,f=0,c,i=d.createElement("div");i.style.cssText="width:100%;min-width:0";let v=(e,F)=>{c=S(e,{mode:"live",rendererUrl:n.rendererUrl,title:n.title??r.name,onPageChange:n.onPageChange,onAction:(R,I)=>p(n.onAction,R,I),onError:n.onError,...F}),c.update(r,n.locale,{capabilities:n.capabilities,customerData:n.customerData})},h=r.presentation;if(h.type==="inline")return m.append(i),v(i,{onContentHeight(e){f=e,p(n.onContentHeight,e,m.clientHeight)}}),{presentation:"inline",inspect:()=>c?.inspect?.()??Promise.resolve(null),destroy(){l||(l=!0,c?.destroy(),i.remove())}};let t=d.createElement("dialog");t.lang=n.locale,t.dir=b(n.locale)?"rtl":"ltr",t.setAttribute("aria-label",r.name),t.style.cssText=H(n.host,h,r.theme);let a=d.createElement("button");a.type="button",a.textContent="×",a.setAttribute("aria-label",n.closeLabel),A(a,r.theme);let g=e=>{u&&!l&&p(n.onDismiss,e)};a.addEventListener("click",()=>g("close_button"));let D=()=>c?.resizeViewport(s.innerHeight||800,s.innerWidth||1024),o;if(n.host==="funnel"){let e=d.createElement("section");e.style.cssText="min-width:0;display:flex;flex-direction:column;min-height:100%",i.style.cssText+=";flex:1 0 auto;display:flex;flex-direction:column;justify-content:center",e.append(i),t.append(a,e),o=y(t,r,D)}else i.setAttribute("aria-label",r.name),o=y(t,r,D),t.append(i),t.prepend(a);let L=n.host==="content"&&o.responsive?x(t,()=>g("close_button"),()=>!0,n.closeLabel):void 0;t.addEventListener("cancel",e=>{e.preventDefault(),g("escape")});let w=e=>s.requestAnimationFrame?s.requestAnimationFrame(e):s.setTimeout(e,0),P=()=>{u&&!l&&p(n.onContentHeight,f,t.clientHeight)},T=E(t);return m.append(t),v(i,{viewportHeight:o.responsive?s.innerHeight||800:void 0,...o.responsive?{viewportWidth:s.innerWidth||1024,hostPresentation:()=>o.type}:{},...n.host!=="content"?{closeActions:n.closeActions??r.actions.filter(e=>e.close).map(e=>e.id),onAuthoredClose(e){a.hidden=e}}:{},onResize(e){o.responsive&&(i.style.height=`${e}px`,i.style.overflow="clip",o.setContentHeight(e)),w(P)},onContentHeight(e){f=e},onRendered(e){e&&t.setAttribute("aria-label",e),!(u||l)&&(u=!0,T(),o.latch(),t.showModal(),o.responsive&&t.focus({preventScroll:!0}),C(t,o.type,o.responsive),w(P))},onEscape:()=>g("escape")}),{get presentation(){return o.type},inspect:()=>c?.inspect?.()??Promise.resolve(null),destroy(){l||(l=!0,c?.destroy(),L?.(),o.destroy(),t.open&&t.close(),t.remove())}}}export{q as formatCustomerDecimal,z as hostedRendererScript,_ as hostedRendererShell,U as inspectCustomHtml,O as mountDialogPreview,S as mountScreenPreview,j as preparePopup,W as prepareScreen,M as sanitizeCustomHtml,V as showPopup};
@@ -997,6 +997,8 @@ declare const publicPaywallSchema: z.ZodObject<{
997
997
  }, z.core.$strict>;
998
998
  type PublicPaywall = z.infer<typeof publicPaywallSchema>;
999
999
 
1000
+ /** The live hosts that put a bounded or full-screen screen in a dialog. */
1001
+ type DialogHost = "content" | "funnel" | "paywall";
1000
1002
  type RetainedPurchaseDialog = {
1001
1003
  dialog: HTMLDialogElement;
1002
1004
  content?: HTMLElement;
@@ -1054,4 +1056,4 @@ declare function createPresentationLoading(container: HTMLElement | ShadowRoot,
1054
1056
  wait<T>(work: Promise<T>, timeoutMs?: number): Promise<T>;
1055
1057
  };
1056
1058
 
1057
- export { type CustomerDataIntent as C, type PresentationLoadingOptions as P, type RetainedPurchaseDialog as R, type ScreenAnswers as S, type SurfaceData as a, type PaywallLoadingDocument as b, createPresentationLoading as c, type PresentationState as d, type CustomerPageData as e, type ScreenParameters as f, type ScreenRendererInput as g, screenInputBindingsSchema as s };
1059
+ export { type CustomerDataIntent as C, type DialogHost as D, type PresentationLoadingOptions as P, type RetainedPurchaseDialog as R, type ScreenAnswers as S, type SurfaceData as a, type PaywallLoadingDocument as b, createPresentationLoading as c, type PresentationState as d, type CustomerPageData as e, type ScreenParameters as f, type ScreenRendererInput as g, screenInputBindingsSchema as s };
@@ -1,7 +1,7 @@
1
- import { f as createCustomerClient, d as createFunnelClient } from './funnel-process-client-DE650LzB.js';
2
- export { F as FunnelProcessAdapter, a as FunnelProcessOptions, c as createFunnelProcess } from './funnel-process-client-DE650LzB.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-Cb9jJGpo.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-Cb9jJGpo.js';
1
+ import { f as createCustomerClient, d as createFunnelClient } from './funnel-process-client-BTusJtqx.js';
2
+ export { F as FunnelProcessAdapter, a as FunnelProcessOptions, c as createFunnelProcess } from './funnel-process-client-BTusJtqx.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-2Yx0Q_lF.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-2Yx0Q_lF.js';
5
5
  import { z } from 'zod';
6
6
  import { J as JsonValue } from './growth-rules-B4YYy64R.js';
7
7
  export { a as ConfigurationStorage, b as ConfigurationSyncOptions, c as createConfigurationSync } from './configuration-sync-Dad8B5Pv.js';
@@ -1 +1 @@
1
- import{b as S,c as E,d as T}from"./chunk-TYJWRPJY.js";import"./chunk-NEW77IDA.js";import{a as A}from"./chunk-UFTKCFNI.js";import{e as P}from"./chunk-USH4WN6W.js";import"./chunk-NNJ7W4KY.js";import{h as b,i as x,k as L}from"./chunk-GBUGEL6M.js";import{E as C}from"./chunk-UIR5CBCC.js";import"./chunk-EQ64JD4L.js";import"./chunk-T5SCW4IA.js";import"./chunk-LBYMDTGD.js";import"./chunk-CQ5EQNQA.js";import"./chunk-2SSOV3OG.js";import"./chunk-SGOVJD5P.js";import"./chunk-ST7XO45I.js";import"./chunk-ULED3B5P.js";import"./chunk-ECUGL7AO.js";import"./chunk-3NV6NBQB.js";import"./chunk-Q4GG33R5.js";import"./chunk-WVTKVQLZ.js";import"./chunk-QTXHF27F.js";import"./chunk-DXNTXCSI.js";import"./chunk-44ZJPQM6.js";import"./chunk-VILB5M4X.js";import"./chunk-5NCQOJR2.js";import"./chunk-MT4OQFDI.js";import"./chunk-KJTHMRSH.js";import"./chunk-JW4MSBYN.js";import"./chunk-EJSTRCBQ.js";import"./chunk-26QYDE7V.js";import"./chunk-DZYMD4MJ.js";import"./chunk-LUVTP4VU.js";import{a as r}from"./chunk-ZRU7WONE.js";import{h as R}from"./chunk-TFPLIX5E.js";import"./chunk-3VUPVXAV.js";import"./chunk-G3YIPDT6.js";import"./chunk-5MRSFLQA.js";import"./chunk-S7NHVERO.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-VCUJMMEM.js";import"./chunk-IUX4CJZM.js";import{a as A}from"./chunk-IXYVLURA.js";import{e as P}from"./chunk-6ZUJCHBI.js";import"./chunk-NCMKY7D6.js";import{h as b,i as x,k as L}from"./chunk-IR6ELT3D.js";import{E as C}from"./chunk-UOJSZMKN.js";import"./chunk-ZJXQTMBW.js";import"./chunk-F46VXI3Q.js";import"./chunk-EU4NTVRT.js";import"./chunk-RZ7WFYWY.js";import"./chunk-ZFNSXRQY.js";import"./chunk-MAKRT62V.js";import"./chunk-ULJJTIL5.js";import"./chunk-EPQUD3S5.js";import"./chunk-PYM47Z55.js";import"./chunk-44SX4C3G.js";import"./chunk-MUW3SOTB.js";import"./chunk-ONYG4VQI.js";import"./chunk-LHUZRVAC.js";import"./chunk-5M2IIZB6.js";import"./chunk-AFQHUBKJ.js";import"./chunk-VILB5M4X.js";import"./chunk-TYIAPLQP.js";import"./chunk-TDMXEI2U.js";import"./chunk-DJTMSBQN.js";import"./chunk-TNWZWEEY.js";import"./chunk-YV4HA2DV.js";import"./chunk-UWHTCMMF.js";import"./chunk-DGMRFL7K.js";import"./chunk-TLQUUC3G.js";import{a as r}from"./chunk-4C4L3JER.js";import{h as R}from"./chunk-IYVJOUO7.js";import"./chunk-3VUPVXAV.js";import"./chunk-6A4NV4ET.js";import"./chunk-5MRSFLQA.js";import"./chunk-CTCK5BUY.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};
@@ -0,0 +1 @@
1
+ import{a,b,c,d,e,f,g,h,i}from"./chunk-BZRDECZJ.js";import"./chunk-UR2PWRLG.js";import"./chunk-TNWZWEEY.js";import"./chunk-YV4HA2DV.js";import"./chunk-UWHTCMMF.js";import"./chunk-DGMRFL7K.js";import"./chunk-TLQUUC3G.js";import"./chunk-4C4L3JER.js";import"./chunk-IYVJOUO7.js";import"./chunk-CTCK5BUY.js";import"./chunk-DSPLGTQI.js";import"./chunk-VPT5MFDG.js";import"./chunk-CILM5XMH.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,6 +1,6 @@
1
1
  import { F as FoundationApi, I as InvoiceModeParams } from './api-KIp0I50M.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-Cb9jJGpo.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-Cb9jJGpo.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-2Yx0Q_lF.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-2Yx0Q_lF.js';
4
4
  import * as zod from 'zod';
5
5
  import { z } from 'zod';
6
6
  import { S as StackNode } from './screen-Pv_pViF6.js';
@@ -7258,6 +7258,9 @@ declare function createFunnelProcessAdapter<Request>(options: FunnelProcessAdapt
7258
7258
  kind: "billing";
7259
7259
  cursor: string;
7260
7260
  } | null>;
7261
+ nextPaywalls?: Record<string, {
7262
+ paywallVersionId: string;
7263
+ }> | undefined;
7261
7264
  values?: Record<string, zod.JSONType> | undefined;
7262
7265
  offeringKey?: string | undefined;
7263
7266
  } | null;
@@ -14026,6 +14029,9 @@ declare function createFunnelProcessAdapter<Request>(options: FunnelProcessAdapt
14026
14029
  kind: "billing";
14027
14030
  cursor: string;
14028
14031
  } | null>;
14032
+ nextPaywalls?: Record<string, {
14033
+ paywallVersionId: string;
14034
+ }> | undefined;
14029
14035
  values?: Record<string, zod.JSONType> | undefined;
14030
14036
  offeringKey?: string | undefined;
14031
14037
  } | null;
@@ -20792,6 +20798,9 @@ declare function createFunnelProcessAdapter<Request>(options: FunnelProcessAdapt
20792
20798
  kind: "billing";
20793
20799
  cursor: string;
20794
20800
  } | null>;
20801
+ nextPaywalls?: Record<string, {
20802
+ paywallVersionId: string;
20803
+ }> | undefined;
20795
20804
  values?: Record<string, zod.JSONType> | undefined;
20796
20805
  offeringKey?: string | undefined;
20797
20806
  } | null;
@@ -27558,6 +27567,9 @@ declare function createFunnelProcessAdapter<Request>(options: FunnelProcessAdapt
27558
27567
  kind: "billing";
27559
27568
  cursor: string;
27560
27569
  } | null>;
27570
+ nextPaywalls?: Record<string, {
27571
+ paywallVersionId: string;
27572
+ }> | undefined;
27561
27573
  values?: Record<string, zod.JSONType> | undefined;
27562
27574
  offeringKey?: string | undefined;
27563
27575
  } | null;
@@ -31103,6 +31115,9 @@ declare function renewFunnelRun(options: IndianaServerOptions, input: {
31103
31115
  kind: "billing";
31104
31116
  cursor: string;
31105
31117
  } | null>;
31118
+ nextPaywalls?: Record<string, {
31119
+ paywallVersionId: string;
31120
+ }> | undefined;
31106
31121
  values?: Record<string, zod.JSONType> | undefined;
31107
31122
  offeringKey?: string | undefined;
31108
31123
  } | null;
@@ -39435,6 +39450,9 @@ declare function createFunnelCampaignClient(options: IndianaServerOptions & {
39435
39450
  kind: "billing";
39436
39451
  cursor: string;
39437
39452
  } | null>;
39453
+ nextPaywalls?: Record<string, {
39454
+ paywallVersionId: string;
39455
+ }> | undefined;
39438
39456
  values?: Record<string, zod.JSONType> | undefined;
39439
39457
  offeringKey?: string | undefined;
39440
39458
  } | null;
package/dist/server.js CHANGED
@@ -1,4 +1,4 @@
1
- import{a as pn}from"./chunk-2BSDXKQS.js";import{a as I}from"./chunk-YDPF2ZZW.js";import{a as fn,b as hn,c as gn,d as yn}from"./chunk-6C3ARFEL.js";import{a as xt}from"./chunk-UFTKCFNI.js";import{a as Ue,b as Ve,c as qe,d as He,e as m}from"./chunk-USH4WN6W.js";import"./chunk-NNJ7W4KY.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-GBUGEL6M.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-UIR5CBCC.js";import"./chunk-EQ64JD4L.js";import{c as h}from"./chunk-T5SCW4IA.js";import"./chunk-LBYMDTGD.js";import"./chunk-CQ5EQNQA.js";import"./chunk-2SSOV3OG.js";import{a as Et,b as _e}from"./chunk-SGOVJD5P.js";import"./chunk-ST7XO45I.js";import"./chunk-ULED3B5P.js";import{e as at}from"./chunk-ECUGL7AO.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-3NV6NBQB.js";import"./chunk-Q4GG33R5.js";import"./chunk-WVTKVQLZ.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-QTXHF27F.js";import{b as Oe}from"./chunk-DXNTXCSI.js";import{e as ve,i as Ze,l as it}from"./chunk-44ZJPQM6.js";import"./chunk-VILB5M4X.js";import"./chunk-5NCQOJR2.js";import"./chunk-MT4OQFDI.js";import{a as Ne,b as Le}from"./chunk-KJTHMRSH.js";import{o as ue}from"./chunk-JW4MSBYN.js";import"./chunk-EJSTRCBQ.js";import{i as un,k as $e,l as Qe,m as Je}from"./chunk-26QYDE7V.js";import{c as Ie}from"./chunk-DZYMD4MJ.js";import{e as Xe,h as We}from"./chunk-LUVTP4VU.js";import{a as c}from"./chunk-ZRU7WONE.js";import{h as Y}from"./chunk-TFPLIX5E.js";import"./chunk-3VUPVXAV.js";import"./chunk-G3YIPDT6.js";import"./chunk-5MRSFLQA.js";import{b as u}from"./chunk-S7NHVERO.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-TFGIDUGW.js";import{a as I}from"./chunk-3KIATB75.js";import{a as fn,b as hn,c as gn,d as yn}from"./chunk-G7JQNJM4.js";import{a as xt}from"./chunk-IXYVLURA.js";import{a as Ue,b as Ve,c as qe,d as He,e as m}from"./chunk-6ZUJCHBI.js";import"./chunk-NCMKY7D6.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-IR6ELT3D.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-UOJSZMKN.js";import"./chunk-ZJXQTMBW.js";import{c as h}from"./chunk-F46VXI3Q.js";import"./chunk-EU4NTVRT.js";import"./chunk-RZ7WFYWY.js";import"./chunk-ZFNSXRQY.js";import{a as Et,b as _e}from"./chunk-MAKRT62V.js";import"./chunk-ULJJTIL5.js";import"./chunk-EPQUD3S5.js";import{e as at}from"./chunk-PYM47Z55.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-44SX4C3G.js";import"./chunk-MUW3SOTB.js";import"./chunk-ONYG4VQI.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-LHUZRVAC.js";import{b as Oe}from"./chunk-5M2IIZB6.js";import{e as ve,i as Ze,l as it}from"./chunk-AFQHUBKJ.js";import"./chunk-VILB5M4X.js";import"./chunk-TYIAPLQP.js";import"./chunk-TDMXEI2U.js";import{a as Ne,b as Le}from"./chunk-DJTMSBQN.js";import{o as ue}from"./chunk-TNWZWEEY.js";import"./chunk-YV4HA2DV.js";import{i as un,k as $e,l as Qe,m as Je}from"./chunk-UWHTCMMF.js";import{c as Ie}from"./chunk-DGMRFL7K.js";import{e as Xe,h as We}from"./chunk-TLQUUC3G.js";import{a as c}from"./chunk-4C4L3JER.js";import{h as Y}from"./chunk-IYVJOUO7.js";import"./chunk-3VUPVXAV.js";import"./chunk-6A4NV4ET.js";import"./chunk-5MRSFLQA.js";import{b as u}from"./chunk-CTCK5BUY.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}
2
2
  ${n}
3
3
  POST
4
4
  ${W}
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-BGCCW5QX.js";import{a as re,b as ae,c as se,d as oe}from"./chunk-MB2U2GWJ.js";import"./chunk-3VUPVXAV.js";import"./chunk-G3YIPDT6.js";import"./chunk-5MRSFLQA.js";import{b as o}from"./chunk-S7NHVERO.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-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-4HMPCJOG.js";import{a as re,b as ae,c as se,d as oe}from"./chunk-MB2U2GWJ.js";import"./chunk-3VUPVXAV.js";import"./chunk-6A4NV4ET.js";import"./chunk-5MRSFLQA.js";import{b as o}from"./chunk-CTCK5BUY.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};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tinkerlandai/longplay-sdk",
3
- "version": "0.10.69",
3
+ "version": "0.10.71",
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-SGOVJD5P.js";import"./chunk-26QYDE7V.js";import"./chunk-DZYMD4MJ.js";import"./chunk-ZRU7WONE.js";import"./chunk-TFPLIX5E.js";import"./chunk-S7NHVERO.js";import"./chunk-CILM5XMH.js";import"./chunk-WOT6VMZA.js";export{a as validateEntitlementCheck,b as validateResourceCheck};
@@ -1 +0,0 @@
1
- import{o as n,r as t}from"./chunk-UIR5CBCC.js";function u(o,e,a){return n(o,e,a,t)}export{u as a};
@@ -1 +0,0 @@
1
- import{c as $}from"./chunk-LUVTP4VU.js";import{a as z}from"./chunk-DSPLGTQI.js";var G={sm:420,md:640,lg:900},F=767;function Pe(e,t,r=()=>!0,a="Close"){let n=e.ownerDocument.defaultView,o=e.ownerDocument.createElement("button");o.type="button",o.setAttribute("aria-label",a),o.style.cssText="position:absolute;inset:0 48px auto;z-index:2;height:24px;border:0;padding:0;background:transparent;touch-action:none;cursor:grab";let d=e.ownerDocument.createElement("span");d.style.cssText="display:block;width:36px;height:4px;border-radius:4px;margin:8px auto 12px;background:currentColor;opacity:.22;pointer-events:none",o.append(d),e.prepend(o);let l,c=0,s=!1,p=()=>{o.hidden=e.dataset.presentation!=="sheet",o.setAttribute("aria-disabled",String(!r()))},b=i=>{p(),!(o.hidden||!r()||i.button!==0)&&(l={y:i.clientY,time:Date.now(),id:i.pointerId},c=0,s=!1,o.setPointerCapture?.(i.pointerId))},x=i=>{!l||i.pointerId!==l.id||(c=Math.max(0,i.clientY-l.y),e.style.transform=`translateY(${c}px)`)},v=i=>{if(!l||i.pointerId!==l.id)return;let g=Math.max(1,Date.now()-l.time),P=i.type!=="pointercancel"&&r()&&(c>120||c>40&&c/g>.5);s=c>6,l=void 0,o.releasePointerCapture?.(i.pointerId),e.style.transform="",P?t():c&&typeof e.animate=="function"&&!n?.matchMedia?.("(prefers-reduced-motion: reduce)").matches&&e.animate([{transform:`translateY(${c}px)`},{transform:"none"}],{duration:200,easing:"cubic-bezier(.2,.8,.2,1)"}),c=0},m=()=>{if(s){s=!1;return}!l&&c===0&&r()&&t()};o.addEventListener("pointerdown",b),o.addEventListener("pointermove",x),o.addEventListener("pointerup",v),o.addEventListener("pointercancel",v),o.addEventListener("click",m);let L=typeof MutationObserver=="function"?new MutationObserver(p):void 0;return L?.observe(e,{attributes:!0,attributeFilter:["data-presentation"]}),n?.addEventListener("resize",p),p(),()=>{L?.disconnect(),n?.removeEventListener("resize",p),o.remove(),e.style.transform=""}}function q(e,t,r=!1){return(e.type==="modal"||e.type==="sheet")&&e.mobile&&r&&t<=F?e.mobile:e.type}function j(e,t,r){let a=e.ownerDocument.defaultView,n=t.presentation,o;if((n.type==="modal"||n.type==="sheet")&&n.backdrop){let i=`lp-backdrop-${crypto.randomUUID()}`,g={none:"transparent",scrim:"#f2f2f2cc",dim:"#0006","strong-dim":"#000000bf",blur:"#0006"};e.dataset.indianaBackdrop=i,o=e.ownerDocument.createElement("style"),o.textContent=`dialog[data-indiana-backdrop="${i}"]::backdrop{background:${g[n.backdrop]};backdrop-filter:${n.backdrop==="blur"?"blur(16px)":"none"}}`,e.append(o)}let d=t.pages?.[0]?.root.style?.shape,l=d?.type==="pill"?"9999px":d?.type==="rect"?typeof d.radius=="number"?`${d.radius}px`:[d.radius.topLeft,d.radius.topRight,d.radius.bottomRight,d.radius.bottomLeft].map(i=>`${i}px`).join(" "):void 0,c=(n.type==="modal"||n.type==="sheet")&&(n.desktopWidth!==void 0||n.mobile!==void 0||n.type==="modal"&&n.position!==void 0),s=n.type,p,b,x=!1,v=i=>{x||!Number.isFinite(i)||i<0||(b=i,s!=="fullscreen"&&s!=="inline"&&(e.style.height=`min(${Math.max(i,40)}px, calc(100dvh - ${s==="sheet"?0:32}px))`))},m=()=>{if(!x&&(s=p??q(n,a?.innerWidth??1024,a?.matchMedia?.("(pointer: coarse)").matches===!0),e.dataset.presentation=s,!(!c||n.type!=="modal"&&n.type!=="sheet"))){if(e.style.boxSizing="border-box",e.style.padding="0",e.style.border="0",e.style.overflow="hidden",e.style.outline="none",e.tabIndex=-1,e.style.background=t.theme.background,e.style.color=t.theme.text,s==="fullscreen")e.style.width="100vw",e.style.height="100dvh",e.style.maxWidth="100vw",e.style.maxHeight="100dvh",e.style.margin="0",e.style.borderRadius="0";else{let i=n.mobile==="sheet"&&s==="sheet",g=n.desktopWidth,P=a?.innerWidth??1024;e.style.width=i?`${P}px`:g?`${Math.min(g.max,Math.max(P*g.viewport/100,g.min))}px`:`${$[n.size]}px`,e.style.maxWidth=`${Math.max(0,P-(s==="sheet"?0:32))}px`,e.style.maxHeight=s==="sheet"?"100dvh":"calc(100dvh - 32px)",e.style.margin=s==="sheet"?"auto auto 0":n.type==="modal"&&n.position==="top"?"16px auto auto":n.type==="modal"&&n.position==="bottom"?"auto auto 16px":"auto",e.style.borderRadius=l??(s==="sheet"?"16px 16px 0 0":"24px"),e.style.height="",b!==void 0&&v(b)}r?.(s)}},L=c?[a?.matchMedia?.(`(max-width: ${F}px)`),a?.matchMedia?.("(pointer: coarse)")].filter(i=>i!==void 0):[];if(c){a?.addEventListener("resize",m);for(let i of L)i.addEventListener?i.addEventListener("change",m):i.addListener?.(m)}return m(),{responsive:c,get type(){return s},latch(){x||p!==void 0||(m(),p=s)},setContentHeight:v,destroy(){if(!x){x=!0,o?.remove(),delete e.dataset.indianaBackdrop,a?.removeEventListener("resize",m);for(let i of L)i.removeEventListener?i.removeEventListener("change",m):i.removeListener?.(m)}}}}function Se(e,t,r){let{presentation:a}=t,n="size"in a?`${G[a.size]}px`:"100vw";return e.style.cssText=`padding:0;border:0;max-width:calc(100vw - 32px);max-height:calc(100dvh - 32px);overflow:auto;width:${n}`,j(e,t,r)}function Le(e,t,r=!1){let a=e.ownerDocument.defaultView;if(typeof e.animate!="function"||a?.matchMedia?.("(prefers-reduced-motion: reduce)").matches)return;let n=r?{duration:300,easing:"cubic-bezier(0.23, 1, 0.32, 1)"}:{duration:240,easing:"cubic-bezier(0.2, 0.8, 0.2, 1)"};e.animate(t==="sheet"?[{transform:"translateY(100%)"},{transform:"none"}]:t==="modal"?[{opacity:0,transform:r?"translateY(12px) scale(0.96)":"translateY(8px) scale(0.98)"},{opacity:1,transform:"none"}]:[{opacity:0},{opacity:1}],n);try{e.animate([{opacity:0},{opacity:1}],{...n,pseudoElement:"::backdrop"})}catch{}}function V(e,t){e.style.cssText=["position:absolute","z-index:1","top:calc(4px + env(safe-area-inset-top, 0px))","inset-inline-end:calc(4px + env(safe-area-inset-right, 0px))","width:44px","height:44px","padding:0","border:0","border-radius:50%","font:400 20px/1 system-ui,sans-serif","cursor:pointer","touch-action:manipulation"].join(";"),e.style.background=`radial-gradient(circle, ${t.background} 0 15px, color-mix(in srgb, ${t.text} 22%, ${t.background}) 15px 16px, transparent 16.5px)`,e.style.color=t.text}function De(e){let t=e.closest("dialog");if(!t?.open||!t.isConnected)return;let r=["style","tabindex","aria-label","data-presentation","data-indiana-backdrop"].map(a=>[a,t.getAttribute(a)]);return{dialog:t,content:e,release(){for(let[a,n]of r)n===null?t.removeAttribute(a):t.setAttribute(a,n)}}}var O=new WeakMap;function ke(e,t){return O.set(e,t),()=>O.delete(e)}function B(e){let t=e.defaultView?.HTMLElement,r=e.activeElement;for(let n=0;n<16&&r?.shadowRoot?.activeElement;n++)r=r.shadowRoot.activeElement;let a=r?O.get(r)?.():void 0;return()=>{!r?.isConnected||!t||!(r instanceof t)||(r.focus({preventScroll:!0}),a?.())}}var Ie=15e3;function Ae(e,t,r,a,n){let o=e.ownerDocument,d=new AbortController,l=!1,c=!1,s,p,b,x,v,m;function L(){clearTimeout(m),m=void 0,b?.(),b=void 0,s?.tagName==="DIALOG"&&s.close?.(),s?.remove(),s=void 0,p=void 0,v=void 0}function i(u,w){c||(c=!0,L(),(u==="dismissed"||u==="error")&&d.abort(w??new DOMException("Presentation cancelled","AbortError")),!(!l&&u!=="ready")&&z(t.onPresentationState,u==="error"?{surface:r,state:u,error:w}:{surface:r,state:u}))}let g=a,P=()=>{c||g()};return{setDismissHandler(u){g=u},get active(){return l&&!c},get cancelled(){return d.signal.aborted},retainPurchaseDialog(){return p?.()},setPurchaseRecovery(u,w){x={message:u,retry:w},v?.()},start(u,w,y){if(l||c)return;l=!0;let C=()=>{if(!c&&t.loading!=="host"){let k=(w??o.documentElement.lang)||"en",M=u&&y?.presentation?.type!=="inline",D=y!==void 0,h=o.createElement(M?"dialog":"div");s=h,h.dataset.longplayLoading=r;let R=k.startsWith("zh"),W=D?R?"正在加载套餐":"Loading plans":R?"正在加载":"Loading",N=y?.screen.theme??{background:"Canvas",text:"CanvasText"};h.setAttribute("aria-label",W);let S=o.createElement("div");S.setAttribute("role","status");let H=o.createElement("div");H.setAttribute("aria-hidden","true"),D?(S.style.cssText="padding:calc(24px + env(safe-area-inset-top, 0px)) 24px 16px;padding-inline-end:68px;font:650 20px/1.3 system-ui,sans-serif;letter-spacing:-.015em",y||(S.style.paddingBlockEnd="24px")):S.style.cssText="position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%)",S.textContent=W;let T=o.createElement("button");T.type="button",T.textContent=R?"重试":"Retry",T.style.cssText="margin:0 24px 20px;padding:8px 16px",T.onclick=()=>x?.retry?.(),v=()=>{x&&(S.textContent=x.message,x.retry?S.after(T):T.remove())};let E=o.createElement("button");E.type="button",E.textContent="×",E.setAttribute("aria-label",R?"取消加载":"Cancel loading"),V(E,N),D&&(E.style.borderRadius="50%",E.style.top="calc(15px + env(safe-area-inset-top, 0px))",E.style.insetInlineEnd="calc(15px + env(safe-area-inset-right, 0px))"),E.addEventListener("click",P);let _=f=>{f.preventDefault(),P()};h.addEventListener("cancel",_);let I=o.createElement("style");I.textContent="[data-longplay-loading] > button:focus-visible{outline:2px solid currentColor;outline-offset:-2px}",h.append(S,H,E,I),v(),e.append(h);let A=()=>{if(!c&&M){let f=h,Y=B(o);f.showModal?f.showModal():f.open=!0,E.focus({preventScroll:!0}),p=()=>{if(!f.open||!f.isConnected)return;let U=b;return b=void 0,s=void 0,p=void 0,delete f.dataset.longplayLoading,f.removeAttribute("aria-label"),f.style.padding="0",f.removeEventListener("cancel",_),S.remove(),H.remove(),E.remove(),I.remove(),T.remove(),v=void 0,{dialog:f,release(){U?.(),f.close?.(),f.remove(),Y()}}}}};y&&n?(b=n(h,H,y),A()):D?(h.style.cssText=M?"padding:0;border:0;border-radius:24px;background:Canvas;color:CanvasText;width:min(420px,calc(100vw - 32px))":"position:relative;background:Canvas;color:CanvasText;width:100%",A()):(X(h,H,M,r),A())}};y!==void 0&&t.loading!=="host"?m=setTimeout(C,120):C(),z(t.onPresentationState,{surface:r,state:"loading",dismiss:P})},present(u){if(c)return;let w=!!s;L(),u(w),i("ready")},dismiss:P,finish:i,async wait(u,w){let y=d.signal,C,k,M=new Promise((D,h)=>{k=()=>h(y.reason),y.aborted?k():y.addEventListener("abort",k,{once:!0}),w!==void 0&&(C=setTimeout(()=>h(new Error("Presentation data timed out")),w))});try{let D=await Promise.race([M,u]);return y.throwIfAborted(),D}finally{y.removeEventListener("abort",k),clearTimeout(C)}}}}function X(e,t,r,a){e.style.cssText="position:relative;box-sizing:border-box;background:Canvas;color:CanvasText;padding:24px 48px 24px 24px;"+(r?"position:fixed;width:min(480px,calc(100% - 32px));border:0;border-radius:16px;max-height:calc(100dvh - 32px)":"width:100%"),t.style.cssText="display:grid;gap:12px";let n=a==="banner"?[["72%",12],["44%",10]]:[["46%",20],["84%",12],["65%",12],["100%",64]];for(let[o,d]of n){let l=e.ownerDocument.createElement("div");l.style.cssText=`width:${o};height:${d}px;background:currentColor;opacity:.11;border-radius:6px`,t.append(l)}}function J(e){let t={display:"block",position:"fixed",top:"0",left:"0",opacity:"0",pointerEvents:"none",zIndex:"-1"},r=Object.keys(t).map(o=>{let d=o,l=e.style[d];return e.style[d]=t[d],[d,l]}),a=e.inert??!1,n=e.getAttribute("aria-hidden");return e.inert=!0,e.setAttribute("aria-hidden","true"),()=>{for(let[o,d]of r)e.style[o]=d;e.inert=a,n===null?e.removeAttribute("aria-hidden"):e.setAttribute("aria-hidden",n)}}function ze(e,t){let r=e.style.width;e.style.width=`${t.getBoundingClientRect().width||t.ownerDocument.defaultView?.innerWidth||800}px`;let a=J(e);return()=>{a(),e.style.width=r}}export{Pe as a,q as b,j as c,Se as d,Le as e,V as f,De as g,ke as h,B as i,Ie as j,Ae as k,J as l,ze as m};
@@ -1 +0,0 @@
1
- import{a as fe,b as pe}from"./chunk-2ZMIM4MO.js";import{d as De,e as B}from"./chunk-CQ5EQNQA.js";import{a as Ve}from"./chunk-ZRU7WONE.js";import{a as C}from"./chunk-DSPLGTQI.js";var Te=5*6e4,je=15e3,Oe=new WeakMap;function Be(c){return Oe.get(c)}var A=c=>Array.isArray(c)?c.map(A):c&&typeof c=="object"?Object.fromEntries(Object.keys(c).sort().map(a=>[a,A(c[a])])):c,N=(c,a)=>JSON.stringify(A(c))===JSON.stringify(A(a)),X=c=>JSON.stringify(A([c.funnelId,c.locale??null,c.parameters??{}])),Je=["onObservationChange","onPurchase","onCheckoutUrl","resumeCheckout","allowNewPurchase","checkoutNavigation","terminateCheckout","beforeCheckoutReplacement","purchaseConfirmation","confirmOnHostedCheckout","resolveOfferId","prepareSubscriptionChange","resolveSubscriptionChange","onOpenUrl","onEvent","onAction","onComplete","onError"];function Xe(c,a){let we=e=>structuredClone({funnelId:e.funnelId,locale:e.locale,parameters:e.parameters}),m,x="",R=a.start instanceof Promise?void 0:we(a.start),$=e=>e?.parameters?.commerce,M=Promise.resolve(a.start).then(e=>e?we(e):void 0),z=a.maxAgeMs??Te,ye=new AbortController,w=AbortSignal.any([ye.signal,a.client.identitySignal,...a.signal?[a.signal]:[]]),Q=()=>d("released","aborted"),r="preparing",me,q,Y=()=>{},L=0,P=null,b=null,v=null,y=null,g,D,Z,ge=new Map,h=null,T=new Set,k=new Map,ee,he=new Promise(e=>ee=e),j,be=new Promise(e=>j=e),ne,He=new Promise(e=>ne=e);function J(e,n){r!==e&&(r=e,me=n,C(a.onState,e))}function Fe(){w.removeEventListener("abort",Q),U(),b?.destroy(),b=null,P?.remove(),P=null,v=null}function d(e,n){["adopted","unavailable","released","closed"].includes(r)||(J(e,n),Fe(),ee(!1),j(!1),ne(null))}function O(e){r!=="shown"&&d("unavailable",e)}let p,ae=!1,E=a.client.paywallCopies,te,Pe=new Promise(e=>te=e),re=!1;function ve(e){Pe.then(n=>{n&&E&&E.write(n,e).catch(()=>{})})}function Ie(e){Pe.then(async n=>{if(!n||!E)return;let t=await E.read(n);ae||t&&"presented"in t||await E.write(n,e)}).catch(()=>{})}let oe=e=>`error:${e?.code??e?.name??"unknown"}`,le=c.ownerDocument.defaultView,H=!0,Se=null,_=!1,Ne=e=>e.storageArea===le?.localStorage&&(e.key===null||e.key.startsWith("indiana.funnel.purchases.")),Ce=e=>{Ne(e)&&G()},xe=a.client.subscribe(()=>G());function U(){H&&(H=!1,le?.removeEventListener("storage",Ce),xe(),Y())}let ie=()=>H&&(r==="ready"||r==="preparing");function se(e){(r==="ready"||r==="preparing")&&d("unavailable",e)}function G(){if(r==="ready"&&Date.now()-L>=z)return U();_=!0,Se??=(async()=>{for(;_&&m&&ie();){_=!1;try{await a.client.retained()==="pending"&&se("purchase_pending")}catch(e){w.aborted?d("released","aborted"):se(oe(e))}}})().finally(()=>{Se=null,_&&m&&ie()&&G()})}le?.addEventListener("storage",Ce),w.addEventListener("abort",Q,{once:!0});let Ae=a.client.findPurchase();Ae.catch(()=>{});let W;function K(e){let n=W?.paywallVersionId??a.paywallVersionId??p?.resolution.id??y?.id,t=JSON.stringify(A([n??null,e])),l=ge.get(t);return l||(l=a.client.readPaywall({paywallVersionId:n,...n?{}:{paywallId:W?.paywallId??a.paywallId},...e}),ge.set(t,l)),l}function V(e,n){let t=Object.values(e.capabilities.plans),l=Object.values(e.document.buttons).some(i=>i.type==="checkout");return l&&t.length===0?!1:n.intent==="subscription_change"&&l?t.some(i=>i.available):t.every(i=>i.available)}function ce(e,n){if(y&&!B(e,y))return d("unavailable","paywall_changed"),!1;y=e,Z=n;for(let t of k.keys())C(t,structuredClone(e));return!0}function Re(e,n){if(!(!y||!["preparing","ready","shown"].includes(r))){if(!B(e,y))return O("paywall_changed");if(!V(e,n.commerce))return O("plan_unavailable");ce(e,n)}}async function F(){let e=await He;if(!e)throw new Ve("PURCHASE_PENDING","The purchase did not start; open it again");return e}let Me={get view(){return h?h.view:y},get signal(){return h?.signal??a.client.identitySignal},get quote(){return h?.quote??null},get operation(){return h?.operation??null},webViewUrl:"bundled",get canReselect(){return h?.canReselect},get recovery(){return h?.recovery},get pendingCancellation(){return h?.pendingCancellation},subscribe(e){return k.set(e,h?.subscribe?.(e)??(()=>{})),()=>{k.get(e)?.(),k.delete(e)}},refresh:async()=>h?h.refresh():structuredClone(y),preview:async e=>(await F()).preview(e),confirm:async()=>(await F()).confirm(),cancel:async()=>(await F()).cancel(),read:async()=>(await F()).read(),destroy(){h?.destroy()}},u={options:{},handoff:{}},ke={loading:"host",focusAtReveal:!0,signal:a.client.identitySignal,start:async()=>Me,canInteract:()=>u.options.canInteract?u.options.canInteract():!["unavailable","released","closed"].includes(r),async beforeAction(){let e=r!=="adopted",n=y?.capabilities,t=await F();if(e&&!N(t.view?.capabilities,n))throw new De;await u.options.beforeAction?.()}};for(let e of Je)Object.defineProperty(ke,e,{enumerable:!0,get:()=>u.options[e]});function de(){r!=="preparing"||!v||!b||!p&&(!m||!N(Z?.commerce,$(m))||Z?.locale!==m.locale)||(J("ready"),ee(!0))}let Ee={present(e){if(u.handoff.present)return u.handoff.present(e);r==="preparing"&&(v=e,L=Date.now(),de())},async dismiss(){if(u.handoff.dismiss)return u.handoff.dismiss();d("closed");for(let e of[...T])C(e)},async closeAction(e){if(u.handoff.closeAction)return u.handoff.closeAction(e);u.options.onAction?await u.options.onAction(e):await Ee.dismiss()},quoteError(e){u.handoff.quoteError?u.handoff.quoteError(e):C(u.options.onError,e)}};async function qe(){if(a.paywallVersionId||a.paywallId)return{paywallVersionId:a.paywallVersionId,paywallId:a.paywallId};let e=a.configuration;if(!e)return d("unavailable","paywall_missing"),null;let n=await Promise.resolve(a.start).catch(()=>null);if(!n||r!=="preparing")return null;let t=()=>fe(e,{funnelId:n.funnelId,customerId:a.client.customerId,parameters:n.parameters??{}});if(q=await t(),r!=="preparing")return null;let l=q;if(l.type!=="paywall")return d("unavailable",pe(l)??"route"),null;let i=!1;return Y=e.subscribe(()=>{i||!ie()||(i=!0,t().then(s=>{!(s.type==="unavailable"&&!["funnel_stopped","route_unavailable"].includes(s.reason))&&(s.type!=="paywall"||s.paywallVersionId!==l.paywallVersionId)&&se("route_changed")}).finally(()=>i=!1))}),H||Y(),{paywallVersionId:l.paywallVersionId}}(async()=>{try{let[{showPaywall:e},n]=await Promise.all([import("./paywall-BSY67NQL.js"),qe()]),t=a.commerce??$(R),l=a.locale??R?.locale,i=n&&t&&l?JSON.stringify(A([n.paywallVersionId??null,n.paywallId??null,{commerce:t,locale:l}])):null;if(te(i),w.throwIfAborted(),r!=="preparing"||!n)return;if(!t)return d("unavailable","commerce_missing");if(!l)return d("unavailable","locale_missing");W=n;let s={commerce:t,locale:l},f=i?await E?.read(i).catch(()=>null):null;if(re=!!f&&"presented"in f&&(!R||f.funnelId===R.funnelId),w.throwIfAborted(),r!=="preparing"||re)return;f&&!("presented"in f)&&(!R||f.funnelId===R.funnelId)&&V(f.resolution,f.context.commerce)&&(p=f),j(!!p);let o;if(p){let ue=p.context;s=ue,o=structuredClone(p.resolution),K(ue).then(Le=>Re(Le,ue),()=>{})}else o=await K(s);if(w.throwIfAborted(),r!=="preparing"||(!V(o,s.commerce)&&a.start instanceof Promise&&!g&&await M,!p&&g&&!N(s,g)&&(s=g,o=await K(s)),w.throwIfAborted(),r!=="preparing"))return;if(!V(o,s.commerce))return d("unavailable","plan_unavailable");if(!ce(o,s))return;P=c.ownerDocument.createElement("div"),c.append(P);let S=setTimeout(()=>r==="preparing"&&d("unavailable","timeout"),je);he.then(()=>clearTimeout(S));let I=await e(P,ke,Ee);if(!I.host||w.aborted||r!=="preparing"){I.host?.destroy(),d(w.aborted?"released":"unavailable","error");return}b=I.host,de()}catch(e){d(w.aborted?"released":"unavailable",oe(e))}finally{te(null),j(!1)}})(),M.then(async e=>{let n=s=>{Ie(null),O(s)};if(!e)return n("gated");let t=e,l=$(t),i=a.commerce??l;if(!N(l&&{...l,intent:void 0},i&&{...i,intent:void 0})||a.locale!==void 0&&t.locale!==a.locale)return n("start_mismatch");if(!l)return n("commerce_missing");g={commerce:l,locale:t.locale},D=t,p&&["preparing","ready","shown"].includes(r)&&(m=t,x=X(t));try{let s=await Ae,f=s==="pending"?"purchase_pending":s==="found"?"original_purchase":s==="blocked"?"purchase_blocked":void 0;if(f)return n(f);if(!["preparing","ready","shown"].includes(r))return;if(a.configuration&&(a.paywallId||a.paywallVersionId)){let o=await fe(a.configuration,{funnelId:t.funnelId,customerId:a.client.customerId,parameters:t.parameters??{}});w.throwIfAborted();let S=o.type==="unknown"||o.type==="unavailable"&&o.reason!=="funnel_stopped";if(o.type==="paywall"?p?o.paywallId!==p.resolution.paywallId:a.paywallVersionId?o.paywallVersionId!==a.paywallVersionId:o.paywallId!==a.paywallId:!S)return n(pe(o)??"route_changed")}if(H&&(_=!1,await a.client.retained()==="pending"))return n("purchase_pending");if(await be,re){m=t,x=X(t);return}if(W||a.paywallId||a.paywallVersionId||y){let o=await K(g);if(w.throwIfAborted(),Ie(V(o,g.commerce)?{savedAt:Date.now(),funnelId:t.funnelId,context:g,resolution:o}:null),p)Re(o,g);else{if(r!=="preparing")return;if(y){if(!V(o,g.commerce))return d("unavailable","plan_unavailable");if(!ce(o,g))return}}}}catch(s){return w.aborted?d("released","aborted"):O(oe(s))}["preparing","ready","shown"].includes(r)&&(m=t,x=X(t),de(),_&&G())},()=>O("gated"));let _e={get state(){return r},get reason(){return me},ready:he,local:be,get start(){return m},get prediction(){return q?structuredClone(q):void 0},matches:e=>m?X(e)===x:!!p&&e.funnelId===p.funnelId&&e.locale===p.context.locale,open(){if(r==="preparing")return"pending";if(r!=="ready"||!v)return!1;if(Date.now()-L>=z)return d("unavailable","expired"),!1;let e=v;return v=null,U(),J("shown"),e(),"shown"},destroy(){ye.abort()}};return Oe.set(_e,{onClose(e){return r==="closed"?(C(e),()=>{}):(T.add(e),()=>{T.delete(e)})},claim(){U()},remember(e){ae=!0;let n=structuredClone(e);M.then(()=>{!D||!g||ve({savedAt:Date.now(),funnelId:D.funnelId,context:g,resolution:n})},()=>{})},withhold(){ae=!0,M.then(()=>{D&&ve({savedAt:Date.now(),funnelId:D.funnelId,presented:"nothing"})},()=>{})},async adopt(e,n){let t=e.paywall?.resolution,l=e.paywall&&!e.paywall.quote&&!e.paywall.operation&&!e.paywall.purchaseRequestId&&!(e.paywall.selectionGeneration??0);if(r!=="shown"||!b||!y||!t||!l||e.source.id!==m?.funnelId||e.locale!==m?.locale||!N(e.parameters??{},m?.parameters??{})||!["running","waiting"].includes(e.status)||!B(t,y))return null;let i;try{i=await n.start()}catch{return null}if(r!=="shown"||!b)return i.destroy(),null;h=i,u.options=n.options,u.handoff=n.handoff;for(let[o]of k)k.set(o,i.subscribe?.(o)??(()=>{})),i.view&&C(o,structuredClone(i.view));w.removeEventListener("abort",Q),J("adopted"),ne(i),T.clear();let s=b,f=P;return b=null,P=null,v=null,new Proxy(s,{get(o,S){return S==="destroy"?()=>{o.destroy(),f?.remove()}:S==="retainPurchaseDialog"?()=>{let I=o.retainPurchaseDialog();if(I)return{dialog:I.dialog,release(){I.release(),f?.remove()}}}:Reflect.get(o,S,o)}})},retainPurchaseDialog(){if(r!=="shown")return;let e=b?.retainPurchaseDialog();if(!e)return;let n=P;return b=null,P=null,d("released"),{dialog:e.dialog,release(){e.release(),n?.remove()}}},get modal(){return y?.document.presentation.type!=="inline"},get revealable(){return r==="ready"&&!!v&&Date.now()-L<z},release(){d("released")}}),_e}export{Te as a,Be as b,Xe as c};