@tinkerlandai/longplay-sdk 0.10.31 → 0.10.32

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 (75) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/{ai-usage-E4c9NSJK.d.ts → ai-usage-T62xehqa.d.ts} +1 -1
  3. package/dist/{api-BpeJkr6U.d.ts → api-Do-6AyWa.d.ts} +24 -0
  4. package/dist/{chunk-2TPPGW7V.js → chunk-4XC34JBS.js} +1 -1
  5. package/dist/{chunk-BQLT2LDP.js → chunk-5HJYR6Z4.js} +1 -1
  6. package/dist/chunk-5UFRIIGC.js +1 -0
  7. package/dist/{chunk-TF2OFTYS.js → chunk-6KBCR7JJ.js} +1 -1
  8. package/dist/{chunk-JNSU2AP2.js → chunk-7MNJH5GB.js} +1 -1
  9. package/dist/{chunk-6BTJNSQQ.js → chunk-7QL4GF4C.js} +1 -1
  10. package/dist/{chunk-ACFQLHJR.js → chunk-BXPXJARS.js} +1 -1
  11. package/dist/{chunk-FVGUBIVT.js → chunk-CZ2RY6RG.js} +1 -1
  12. package/dist/{chunk-B3KFE57L.js → chunk-EHDHWYVJ.js} +1 -1
  13. package/dist/{chunk-D3UU546S.js → chunk-EMVWUEW4.js} +1 -1
  14. package/dist/{chunk-PI25NLDV.js → chunk-EMYZUBWL.js} +1 -1
  15. package/dist/{chunk-YXCEZAQL.js → chunk-EQPEUPMG.js} +1 -1
  16. package/dist/{chunk-7Z7JT4HE.js → chunk-EUVLXS2V.js} +1 -1
  17. package/dist/{chunk-23WNEOK4.js → chunk-FYQXSGRT.js} +1 -1
  18. package/dist/{chunk-S5H3WJVQ.js → chunk-GLQXJMKL.js} +1 -1
  19. package/dist/{chunk-5N7QFF5M.js → chunk-HQITRRHF.js} +1 -1
  20. package/dist/{chunk-UWYL2QCF.js → chunk-HQPP76BS.js} +1 -1
  21. package/dist/{chunk-EZ5RCVVY.js → chunk-ILEDKSRQ.js} +1 -1
  22. package/dist/{chunk-2QQZSMTB.js → chunk-KHM6IHPJ.js} +1 -1
  23. package/dist/{chunk-FJGJQGYF.js → chunk-MIBRUDIS.js} +1 -1
  24. package/dist/{chunk-WRUW2UIJ.js → chunk-N7YXDSQL.js} +1 -1
  25. package/dist/{chunk-4ZVVG5LM.js → chunk-NAZU3EEJ.js} +1 -1
  26. package/dist/{chunk-S57HRPT2.js → chunk-P5K67CKS.js} +1 -1
  27. package/dist/{chunk-ITVSLSRM.js → chunk-R23IGK5U.js} +1 -1
  28. package/dist/chunk-R4FDIYMN.js +1 -0
  29. package/dist/{chunk-LZV4QJ5E.js → chunk-SCC3O2RD.js} +1 -1
  30. package/dist/{chunk-WK4WQZHK.js → chunk-SP5AQION.js} +1 -1
  31. package/dist/{chunk-QPHT6QHE.js → chunk-THMGTRXP.js} +1 -1
  32. package/dist/{chunk-YEXRETKV.js → chunk-UESDHJRB.js} +1 -1
  33. package/dist/{chunk-TMZGZAWM.js → chunk-UWLEGMWX.js} +1 -1
  34. package/dist/{chunk-J4VTKRH7.js → chunk-VYFSRHXM.js} +1 -1
  35. package/dist/{chunk-HJLGRW4A.js → chunk-X4W22IH6.js} +1 -1
  36. package/dist/{chunk-ZYTT7ZAB.js → chunk-XH7RJPBV.js} +1 -1
  37. package/dist/{chunk-RBMOWJGE.js → chunk-Y3MQLWGD.js} +1 -1
  38. package/dist/chunk-ZGCKQWQ5.js +1 -0
  39. package/dist/chunk-ZIQENZDI.js +1 -0
  40. package/dist/{content-OY5MRXF5.js → content-YRQSNKN7.js} +1 -1
  41. package/dist/{funnel-host-purchase-IRFPNIZY.js → funnel-host-purchase-SWYFJOVN.js} +1 -1
  42. package/dist/{funnel-local-client-D7e3rP5-.d.ts → funnel-local-client-BeGBvi3z.d.ts} +66 -37
  43. package/dist/{funnel-process-client-BEPv6guV.d.ts → funnel-process-client-C6QKDZun.d.ts} +46 -46
  44. package/dist/funnel-runtime-host-J2PQHVSO.js +1 -0
  45. package/dist/index.d.ts +10 -10
  46. package/dist/index.js +1 -1
  47. package/dist/merchant-bridge-contracts-ZUQ6SGXZ.js +1 -0
  48. package/dist/native-shell.js +1 -1
  49. package/dist/openrouter.d.ts +2 -2
  50. package/dist/openrouter.js +1 -1
  51. package/dist/operation-contracts-443N2P3A.js +1 -0
  52. package/dist/page.js +1 -1
  53. package/dist/{paywall-DI62MX5L.js → paywall-RQ66UZLW.js} +1 -1
  54. package/dist/paywall-session-PPECL5XK.js +1 -0
  55. package/dist/popup.js +1 -1
  56. package/dist/react-native.d.ts +5 -5
  57. package/dist/react-native.js +1 -1
  58. package/dist/screen-renderer-NHLIJDCW.js +1 -0
  59. package/dist/server.d.ts +64 -52
  60. package/dist/server.js +1 -1
  61. package/dist/{visual-dom-32PB6MMP.js → visual-dom-6DCUZGPB.js} +1 -1
  62. package/dist/visual.js +1 -1
  63. package/package.json +1 -1
  64. package/dist/chunk-NH5ML5SB.js +0 -1
  65. package/dist/chunk-SJSCROSL.js +0 -1
  66. package/dist/chunk-XIP32WI7.js +0 -1
  67. package/dist/chunk-XZEGVBAI.js +0 -1
  68. package/dist/funnel-runtime-host-CJTPLZ4N.js +0 -1
  69. package/dist/merchant-bridge-contracts-LJKL7PNJ.js +0 -1
  70. package/dist/operation-contracts-SP2RZUT3.js +0 -1
  71. package/dist/paywall-session-AW6R3PJB.js +0 -1
  72. package/dist/screen-renderer-W5MP4KVG.js +0 -1
  73. /package/dist/{chunk-PWXN3W4Q.js → chunk-BID4UGWB.js} +0 -0
  74. /package/dist/{chunk-RFUXSC52.js → chunk-UKMEW5I7.js} +0 -0
  75. /package/dist/{chunk-ZY4XAKNQ.js → chunk-VF6QMMEA.js} +0 -0
@@ -1,4 +1,4 @@
1
- import{a as I,b as L}from"./chunk-PWXN3W4Q.js";function M(e){try{let n=e.replace(/([^\\])\//g,"$1\\/");return new RegExp(n)}catch{return}}function j(e,n){if(!n.length)return!1;let t=!1,r=!1;for(let o of n){let s=pe(e,o.type,o.pattern);if(o.include===!1){if(s)return!1}else t=!0,s&&(r=!0)}return r||!t}function he(e,n,t){try{let r=n.replace(/[*.+?^${}()|[\]\\]/g,"\\$&").replace(/_____/g,".*");return t&&(r="\\/?"+r.replace(/(^\/|\/$)/g,"")+"\\/?"),new RegExp("^"+r+"$","i").test(e)}catch{return!1}}function be(e,n){try{let t=new URL(n.replace(/^([^:/?]*)\./i,"https://$1.").replace(/\*/g,"_____"),"https://_____"),r=[[e.host,t.host,!1],[e.pathname,t.pathname,!0]];return t.hash&&r.push([e.hash,t.hash,!1]),t.searchParams.forEach((o,s)=>{r.push([e.searchParams.get(s)||"",o,!1])}),!r.some(o=>!he(o[0],o[1],o[2]))}catch{return!1}}function pe(e,n,t){try{let r=new URL(e,"https://_");if(n==="regex"){let o=M(t);return o?o.test(r.href)||o.test(r.href.substring(r.origin.length)):!1}else if(n==="simple")return be(r,t);return!1}catch{return!1}}function K(e){for(let t of["namespace","status","url","groups"])if(Object.hasOwn(e,t))throw new TypeError(`Retired experiment field: ${t}`);let n=e;if(n.hashVersion!==void 0&&n.hashVersion!==2)throw new TypeError("Only hash version 2 is supported");if(n.filters?.some(t=>t.hashVersion!==2))throw new TypeError("Only hash version 2 is supported")}function T(e){for(let n of Object.values(e)){if(Array.isArray(n))throw new TypeError("Saved groups require typed list or condition entries");if(n&&Object.hasOwn(n,"useEmptyListGroup"))throw new TypeError("Retired saved group field: useEmptyListGroup")}}function H(e){for(let n of["overrides","groups"])if(Object.hasOwn(e,n))throw new TypeError(`Retired evaluation context field: ${n}`);T(e.savedGroups??{})}function J(e){let n=2166136261,t=e.length;for(let r=0;r<t;r++)n^=e.charCodeAt(r),n+=(n<<1)+(n<<4)+(n<<7)+(n<<8)+(n<<24);return n>>>0}function C(e,n,t){return t===2?J(J(e+n)+"")%1e4/1e4:null}function me(e){return e<=0?[]:new Array(e).fill(1/e)}function $(e,n){return e>=n[0]&&e<n[1]}function W(e,n){for(let[t,r]of n.entries())if($(e,r))return t;return-1}function Q(e,n,t){n=n===void 0?1:n,n<0?n=0:n>1&&(n=1);let r=me(e);t=t||r,t.length!==e&&(t=r);let o=t.reduce((a,u)=>u+a,0);(o<.99||o>1.01)&&(t=r);let s=0,i=n;return t.map(a=>{let u=s;return s+=a,[u,u+i*a]})}function z(e,n,t){if(!n)return null;let r=n.split("?")[1];if(!r)return null;let s=r.replace(/#.*/,"").split("&").map(i=>i.split("=",2)).filter(([i])=>i===e).map(([,i])=>i===void 0?NaN:parseInt(i))[0];return s!==void 0&&s>=0&&s<t?s:null}function X(e){try{return e()}catch{return!1}}function E(e){return typeof e=="string"?e:JSON.stringify(e)}function y(e){typeof e=="number"&&(e=e+""),(!e||typeof e!="string")&&(e="0");let n=e.replace(/(^v|\+.*$)/g,"").split(/[-.]/);return n.length===3&&n.push("~"),n.map(t=>t.match(/^[0-9]+$/)?t.padStart(5," "):t).join("-")}var Y=new Map,D=32,Z=new WeakMap,ee=new WeakMap;function Se(e){return I(L(new TextEncoder().encode(String(e))))}var B=e=>Array.isArray(e)?e.map(B):typeof e=="string"||typeof e=="number"?Se(e):null,O=e=>typeof e=="string"?e.toLowerCase():e;function oe(e){let n=Z.get(e);return n||(n=new Set(e),Z.set(e,n)),n}function ve(e){let n=ee.get(e);return n||(n=new Set(e.map(O)),ee.set(e,n)),n}function Ae(e){T(e);for(let n of Object.values(e)){let t=n?.type==="list"||n?.type==="hashed"?n.values:null;t&&t.length>=D&&oe(t)}return e}function h(e,n,t,r){t=t||{},r||T(t),r=r||new Set;for(let[o,s]of Object.entries(n))switch(o){case"$or":if(!ie(e,s,t,r))return!1;break;case"$nor":if(ie(e,s,t,r))return!1;break;case"$and":if(!Fe(e,s,t,r))return!1;break;case"$not":if(h(e,s,t,r))return!1;break;case"$savedGroup":if(!we(e,s,t,r))return!1;break;default:if(!V(s,se(e,o),t,!1,r))return!1}return!0}function we(e,n,t,r){if(!n||typeof n!="object"||Array.isArray(n))return!1;let{id:o,attributeKey:s}=n;if(typeof o!="string"||r.has(o)||s!==void 0&&typeof s!="string")return!1;let i=t[o];if(!i||Array.isArray(i)||typeof i!="object")return!1;let a=new Set(r).add(o);if(i.type==="list"||i.type==="hashed"){let u=s??i.attributeKey;if(typeof u!="string"||!Array.isArray(i.values))return!1;let f=se(e,u);return S(i.type==="hashed"?B(f):f,i.values)}return i.type==="condition"?!i.condition||typeof i.condition!="object"?!1:h(e,i.condition,t,a):!1}function se(e,n){let t=n.split("."),r=e;for(let o of t)if(r&&typeof r=="object"&&o in r)r=r[o];else return null;return r}function ne(e,n=!1){let t=`${e}${n?"/i":""}`,r=Y.get(t);return r||(r=new RegExp(e.replace(/([^\\])\//g,"$1\\/"),n?"i":void 0),Y.set(t,r)),r}function V(e,n,t,r=!1,o=new Set){if(typeof e=="string")return r?String(n).toLowerCase()===e.toLowerCase():n+""===e;if(typeof e=="number")return n*1===e;if(typeof e=="boolean")return n!==null&&!!n===e;if(e===null)return n===null;if(Array.isArray(e)||!ae(e))return JSON.stringify(n)===JSON.stringify(e);let s=e;for(let i in s)if(!Re(i,n,s[i],t,o))return!1;return!0}function ae(e){let n=Object.keys(e);return n.length>0&&n.filter(t=>t[0]==="$").length===n.length}function Ee(e){if(e===null)return"null";if(Array.isArray(e))return"array";let n=typeof e;return["string","number","boolean","object","undefined"].includes(n)?n:"unknown"}function Ve(e,n,t,r){if(!Array.isArray(e))return!1;let o=ae(n)?s=>V(n,s,t,!1,r):s=>h(s,n,t,r);for(let s=0;s<e.length;s++)if((e[s]??null)!==null&&o(e[s]))return!0;return!1}function S(e,n,t=!1){if(t){let o;if(n.length>=D){let s=ve(n);o=i=>{let a=O(i);return!(typeof a=="number"&&Number.isNaN(a))&&s.has(a)}}else o=s=>n.some(i=>O(s)===O(i));return Array.isArray(e)?e.some(s=>o(s)):o(e)}let r=n.length>=D?(o=>s=>o.has(s))(oe(n)):o=>n.includes(o);return Array.isArray(e)?e.some(o=>r(o)):r(e)}function te(e){return e===void 0?[]:e&&typeof e=="object"&&(e.type==="list"||e.type==="hashed")&&Array.isArray(e.values)?e.values:null}function re(e,n,t,r=!1,o=new Set){if(!Array.isArray(e))return!1;for(let s=0;s<n.length;s++){let i=!1;for(let a=0;a<e.length;a++)if(V(n[s],e[a],t,r,o)){i=!0;break}if(!i)return!1}return!0}function Re(e,n,t,r,o=new Set){let s=n,i=t;switch(e){case"$veq":return y(n)===y(t);case"$vne":return y(n)!==y(t);case"$vgt":return y(n)>y(t);case"$vgte":return y(n)>=y(t);case"$vlt":return y(n)<y(t);case"$vlte":return y(n)<=y(t);case"$eq":return n===t;case"$ne":return n!==t;case"$lt":return s<i;case"$lte":return s<=i;case"$gt":return s>i;case"$gte":return s>=i;case"$exists":return t?n!=null:n==null;case"$in":return Array.isArray(t)?S(n,t):!1;case"$ini":return Array.isArray(t)?S(n,t,!0):!1;case"$inGroup":{let a=r[t],u=te(a);return u===null?!1:S(a?.type==="hashed"?B(n):n,u)}case"$notInGroup":{let a=r[t],u=te(a);return u===null?!1:!S(a?.type==="hashed"?B(n):n,u)}case"$nin":return Array.isArray(t)?!S(n,t):!1;case"$nini":return Array.isArray(t)?!S(n,t,!0):!1;case"$not":return!V(t,n,r,!1,o);case"$size":return Array.isArray(n)?V(t,n.length,r,!1,o):!1;case"$elemMatch":return Ve(n,t,r,o);case"$all":return Array.isArray(t)?re(n,t,r,!1,o):!1;case"$alli":return Array.isArray(t)?re(n,t,r,!0,o):!1;case"$regex":try{return ne(t).test(n)}catch{return!1}case"$regexi":try{return ne(t,!0).test(n)}catch{return!1}case"$type":return Ee(n)===t;default:return!1}}function ie(e,n,t,r){if(!n.length)return!0;for(let o of n)if(h(e,o,t,r))return!0;return!1}function Fe(e,n,t,r){for(let o of n)if(!h(e,o,t,r))return!1;return!0}function ue(e){return Object.fromEntries(Object.entries(e).filter(([,n])=>n!==void 0))}function U(e){return H(e),{context:e,stack:{evaluatedFeatures:new Set}}}function _(e){return{...e.attributes,...e.attributeOverrides}}function p(e,n,t){let r=n||"id",o="",s=_(e);return s[r]&&(o=s[r]),!o&&t&&(s[t]&&(o=s[t]),o&&(r=t)),{hashAttribute:r,hashValue:o}}function l(e,n,t){e.context.log?.(n,t)}function x(e,n){return n=n||0,`${e}__${n}`}function q(e,n){return`${e}||${n}`}function Te(e,n,t){let r=e.stickyBucketAssignmentDocs;if(!r)return{};let{hashAttribute:o,hashValue:s}=p(e,n),i=q(o,E(s)),{hashAttribute:a,hashValue:u}=p(e,t),f=u?q(a,E(u)):null,c={};return f&&r[f]&&Object.assign(c,r[f].assignments||{}),r[i]&&Object.assign(c,r[i].assignments||{}),c}function le({context:e,expKey:n,expBucketVersion:t,expHashAttribute:r,expFallbackAttribute:o,expMinBucketVersion:s,expMeta:i}){t=t||0,s=s||0,r=r||"id",i=i||[];let a=x(n,t),u=Te(e,r,o);if(s>0)for(let d=0;d<s;d++){let k=x(n,d);if(u[k]!==void 0)return{variation:-1,versionIsBlocked:!0}}let f=u[a];if(f===void 0)return{variation:-1};let c=i.findIndex(d=>d.key===f);return c<0?{variation:-1}:{variation:c}}function fe(e,n,t,r){let o=q(n,t),s=e.stickyBucketAssignmentDocs,i=s&&s[o]?s[o].assignments||{}:{},a={...i,...r},u=JSON.stringify(i)!==JSON.stringify(a);return{key:o,doc:{attributeName:n,attributeValue:t,assignments:a},changed:u}}function Ce(e,n){let t=U(n),r=ge(e,null,t);return n.onExperimentEval?.(e,r),r}function $e(e,n){return N(e,U(n))}function Oe(e){return e.forcedVariations||{}}function ce(e,n,t){let{context:r}=e;if(r.trackedExperiments){let o=ke(n,t);if(r.trackedExperiments.has(o))return;r.trackedExperiments.add(o)}G(()=>r.onExperimentViewed?.(n,t))}function Be(e,n,t){let{context:r}=e;if(r.trackedFeatureUsage){let o=JSON.stringify(t.value);if(r.trackedFeatureUsage[n]===o)return;r.trackedFeatureUsage[n]=o}G(()=>r.onFeatureUsage?.(n,t))}function G(e){try{let n=e();n&&typeof n.catch=="function"&&n.catch(()=>{})}catch{}}function N(e,n){let{context:t}=n;if(n.stack.evaluatedFeatures.has(e))return l(n,`evalFeature: circular dependency detected: ${n.stack.id} -> ${e}`,{from:n.stack.id,to:e}),m(n,e,null,"cyclicPrerequisite");n.stack.evaluatedFeatures.add(e),n.stack.id=e;let r=t.features?.[e];for(let s of r?.rules??[])K(s);let o=t.forcedFeatureValues;if(o&&o.has(e))return l(n,"Global override",{id:e,value:o.get(e)}),m(n,e,o.get(e),"override");if(!r)return l(n,"Unknown feature",{id:e}),m(n,e,null,"unknownFeature");if(r.rules){let s=new Set(n.stack.evaluatedFeatures);e:for(let i of r.rules){if(i.parentConditions)for(let f of i.parentConditions){n.stack.evaluatedFeatures=new Set(s);let c=N(f.id,n);if(c.source==="cyclicPrerequisite")return m(n,e,null,"cyclicPrerequisite");let d={value:c.value};if(!h(d,f.condition||{},t.savedGroups||{})){if(f.gate)return l(n,"Feature blocked by prerequisite",{id:e,rule:i}),m(n,e,null,"prerequisite");l(n,"Skip rule because prerequisite evaluation fails",{id:e,rule:i});continue e}}if(i.filters&&ye(i.filters,n)){l(n,"Skip rule because of filters",{id:e,rule:i});continue}if("force"in i){if(i.condition&&!de(i.condition,n)){l(n,"Skip rule because of condition ff",{id:e,rule:i});continue}if(!xe(n,i.seed||e,i.hashAttribute,t.saveStickyBucketAssignmentDoc&&!i.disableStickyBucketing?i.fallbackAttribute:void 0,i.range,i.coverage,i.hashVersion)){l(n,"Skip rule because user not included in rollout",{id:e,rule:i});continue}return l(n,"Force value from rule",{id:e,rule:i}),i.tracks&&i.tracks.forEach(f=>{ce(n,f.experiment,f.result)}),m(n,e,i.force,"force",i.id)}if(!i.variations){l(n,"Skip invalid rule",{id:e,rule:i});continue}let a={variations:i.variations,key:i.key||e};"coverage"in i&&(a.coverage=i.coverage),i.weights&&(a.weights=i.weights),i.hashAttribute&&(a.hashAttribute=i.hashAttribute),i.fallbackAttribute&&(a.fallbackAttribute=i.fallbackAttribute),i.disableStickyBucketing&&(a.disableStickyBucketing=i.disableStickyBucketing),i.bucketVersion!==void 0&&(a.bucketVersion=i.bucketVersion),i.minBucketVersion!==void 0&&(a.minBucketVersion=i.minBucketVersion),i.meta&&(a.meta=i.meta),i.ranges&&(a.ranges=i.ranges),i.name&&(a.name=i.name),i.phase&&(a.phase=i.phase),i.seed&&(a.seed=i.seed),i.hashVersion&&(a.hashVersion=i.hashVersion),i.filters&&(a.filters=i.filters),i.condition&&(a.condition=i.condition);let u=ge(a,e,n);if(t.onExperimentEval?.(a,u),u.inExperiment&&!u.passthrough)return m(n,e,u.value,"experiment",i.id,a,u)}}return l(n,"Use default value",{id:e,value:r.defaultValue}),m(n,e,r.defaultValue===void 0?null:r.defaultValue,"defaultValue")}function ge(e,n,t){let{context:r}=t;K(e);let o=e.key,s=e.variations.length;if(s<2)return l(t,"Invalid experiment",{id:o}),g(t,e,-1,!1,n);if(r.enabled===!1)return l(t,"Context disabled",{id:o}),g(t,e,-1,!1,n);if(e.urlPatterns&&!j(r.url||"",e.urlPatterns))return l(t,"Skip because of url targeting",{id:o}),g(t,e,-1,!1,n);let i=z(o,r.url||"",s);if(i!==null)return l(t,"Force via querystring",{id:o,variation:i}),g(t,e,i,!1,n);let u=Oe(r)[o];if(u!==void 0)return l(t,"Force via dev tools",{id:o,variation:u}),g(t,e,u,!1,n);if(e.active===!1)return l(t,"Skip because inactive",{id:o}),g(t,e,-1,!1,n);let{hashAttribute:f,hashValue:c}=p(r,e.hashAttribute,r.saveStickyBucketAssignmentDoc&&!e.disableStickyBucketing?e.fallbackAttribute:void 0);if(!c)return l(t,"Skip because missing hashAttribute",{id:o}),g(t,e,-1,!1,n);let d=-1,k=!1,R=!1;if(r.saveStickyBucketAssignmentDoc&&!e.disableStickyBucketing){let{variation:b,versionIsBlocked:v}=le(ue({context:r,expKey:e.key,expBucketVersion:e.bucketVersion,expHashAttribute:e.hashAttribute,expFallbackAttribute:e.fallbackAttribute,expMinBucketVersion:e.minBucketVersion,expMeta:e.meta}));k=b>=0,d=b,R=!!v}if(!k){if(e.filters&&ye(e.filters,t))return l(t,"Skip because of filters",{id:o}),g(t,e,-1,!1,n);if(e.include&&!X(e.include))return l(t,"Skip because of include function",{id:o}),g(t,e,-1,!1,n);if(e.condition&&!de(e.condition,t))return l(t,"Skip because of condition exp",{id:o}),g(t,e,-1,!1,n);if(e.parentConditions){let b=new Set(t.stack.evaluatedFeatures);for(let v of e.parentConditions){t.stack.evaluatedFeatures=new Set(b);let w=N(v.id,t);if(w.source==="cyclicPrerequisite")return g(t,e,-1,!1,n);let P={value:w.value};if(!h(P,v.condition||{},r.savedGroups||{}))return l(t,"Skip because prerequisite evaluation fails",{id:o}),g(t,e,-1,!1,n)}}}let A=C(e.seed||o,c,e.hashVersion??2);if(A===null)return l(t,"Skip because of invalid hash version",{id:o}),g(t,e,-1,!1,n);if(!k){let b=e.ranges||Q(s,e.coverage===void 0?1:e.coverage,e.weights);d=W(A,b)}if(R)return l(t,"Skip because sticky bucket version is blocked",{id:o}),g(t,e,-1,!1,n,void 0,!0);if(d<0)return l(t,"Skip because of coverage",{id:o}),g(t,e,-1,!1,n);if("force"in e)return l(t,"Force variation",{id:o,variation:e.force}),g(t,e,e.force===void 0?-1:e.force,!1,n);if(r.qaMode)return l(t,"Skip because QA mode",{id:o}),g(t,e,-1,!1,n);let F=g(t,e,d,!0,n,A,k);if(r.saveStickyBucketAssignmentDoc&&!e.disableStickyBucketing){let{changed:b,key:v,doc:w}=fe(r,f,E(c),{[x(e.key,e.bucketVersion)]:F.key});if(b){r.stickyBucketAssignmentDocs=r.stickyBucketAssignmentDocs||{},r.stickyBucketAssignmentDocs[v]=w;let P=r.saveStickyBucketAssignmentDoc;G(()=>P(w))}}return ce(t,e,F),l(t,"In experiment",{id:o,variation:F.variationId}),F}function m(e,n,t,r,o,s,i){let a={value:t,on:!!t,off:!t,source:r,ruleId:o||""};return s&&(a.experiment=s),i&&(a.experimentResult=i),r!=="override"&&Be(e,n,a),a}function de(e,n){return h(_(n.context),e,n.context.savedGroups||{})}function ye(e,n){return e.some(t=>{let{hashValue:r}=p(n.context,t.attribute);if(!r)return!0;let o=C(t.seed,r,t.hashVersion||2);return o===null?!0:!t.ranges.some(s=>$(o,s))})}function xe(e,n,t,r,o,s,i){if(!o&&s===void 0)return!0;if(!o&&s===0)return!1;let{hashValue:a}=p(e.context,t,r);if(!a)return!1;let u=C(n,a,i??2);return u===null?!1:o?$(u,o):s!==void 0?u<=s:!0}function g(e,n,t,r,o,s,i){let a=!0;(t<0||t>=n.variations.length)&&(t=0,a=!1);let{hashAttribute:u,hashValue:f}=p(e.context,n.hashAttribute,e.context.saveStickyBucketAssignmentDoc&&!n.disableStickyBucketing?n.fallbackAttribute:void 0),c=n.meta?.[t]??{},d=n.variations[0];for(let[R,A]of n.variations.entries())if(R===t){d=A;break}let k={key:c.key||""+t,featureId:o,inExperiment:a,hashUsed:r,variationId:t,value:d,hashAttribute:u,hashValue:f,stickyBucketUsed:!!i};return c.name&&(k.name=c.name),s!==void 0&&(k.bucket=s),c.passthrough&&(k.passthrough=c.passthrough),k}function ke(e,n){return n.hashAttribute+n.hashValue+e.key+n.variationId}/*!
1
+ import{a as I,b as L}from"./chunk-BID4UGWB.js";function M(e){try{let n=e.replace(/([^\\])\//g,"$1\\/");return new RegExp(n)}catch{return}}function j(e,n){if(!n.length)return!1;let t=!1,r=!1;for(let o of n){let s=pe(e,o.type,o.pattern);if(o.include===!1){if(s)return!1}else t=!0,s&&(r=!0)}return r||!t}function he(e,n,t){try{let r=n.replace(/[*.+?^${}()|[\]\\]/g,"\\$&").replace(/_____/g,".*");return t&&(r="\\/?"+r.replace(/(^\/|\/$)/g,"")+"\\/?"),new RegExp("^"+r+"$","i").test(e)}catch{return!1}}function be(e,n){try{let t=new URL(n.replace(/^([^:/?]*)\./i,"https://$1.").replace(/\*/g,"_____"),"https://_____"),r=[[e.host,t.host,!1],[e.pathname,t.pathname,!0]];return t.hash&&r.push([e.hash,t.hash,!1]),t.searchParams.forEach((o,s)=>{r.push([e.searchParams.get(s)||"",o,!1])}),!r.some(o=>!he(o[0],o[1],o[2]))}catch{return!1}}function pe(e,n,t){try{let r=new URL(e,"https://_");if(n==="regex"){let o=M(t);return o?o.test(r.href)||o.test(r.href.substring(r.origin.length)):!1}else if(n==="simple")return be(r,t);return!1}catch{return!1}}function K(e){for(let t of["namespace","status","url","groups"])if(Object.hasOwn(e,t))throw new TypeError(`Retired experiment field: ${t}`);let n=e;if(n.hashVersion!==void 0&&n.hashVersion!==2)throw new TypeError("Only hash version 2 is supported");if(n.filters?.some(t=>t.hashVersion!==2))throw new TypeError("Only hash version 2 is supported")}function T(e){for(let n of Object.values(e)){if(Array.isArray(n))throw new TypeError("Saved groups require typed list or condition entries");if(n&&Object.hasOwn(n,"useEmptyListGroup"))throw new TypeError("Retired saved group field: useEmptyListGroup")}}function H(e){for(let n of["overrides","groups"])if(Object.hasOwn(e,n))throw new TypeError(`Retired evaluation context field: ${n}`);T(e.savedGroups??{})}function J(e){let n=2166136261,t=e.length;for(let r=0;r<t;r++)n^=e.charCodeAt(r),n+=(n<<1)+(n<<4)+(n<<7)+(n<<8)+(n<<24);return n>>>0}function C(e,n,t){return t===2?J(J(e+n)+"")%1e4/1e4:null}function me(e){return e<=0?[]:new Array(e).fill(1/e)}function $(e,n){return e>=n[0]&&e<n[1]}function W(e,n){for(let[t,r]of n.entries())if($(e,r))return t;return-1}function Q(e,n,t){n=n===void 0?1:n,n<0?n=0:n>1&&(n=1);let r=me(e);t=t||r,t.length!==e&&(t=r);let o=t.reduce((a,u)=>u+a,0);(o<.99||o>1.01)&&(t=r);let s=0,i=n;return t.map(a=>{let u=s;return s+=a,[u,u+i*a]})}function z(e,n,t){if(!n)return null;let r=n.split("?")[1];if(!r)return null;let s=r.replace(/#.*/,"").split("&").map(i=>i.split("=",2)).filter(([i])=>i===e).map(([,i])=>i===void 0?NaN:parseInt(i))[0];return s!==void 0&&s>=0&&s<t?s:null}function X(e){try{return e()}catch{return!1}}function E(e){return typeof e=="string"?e:JSON.stringify(e)}function y(e){typeof e=="number"&&(e=e+""),(!e||typeof e!="string")&&(e="0");let n=e.replace(/(^v|\+.*$)/g,"").split(/[-.]/);return n.length===3&&n.push("~"),n.map(t=>t.match(/^[0-9]+$/)?t.padStart(5," "):t).join("-")}var Y=new Map,D=32,Z=new WeakMap,ee=new WeakMap;function Se(e){return I(L(new TextEncoder().encode(String(e))))}var B=e=>Array.isArray(e)?e.map(B):typeof e=="string"||typeof e=="number"?Se(e):null,O=e=>typeof e=="string"?e.toLowerCase():e;function oe(e){let n=Z.get(e);return n||(n=new Set(e),Z.set(e,n)),n}function ve(e){let n=ee.get(e);return n||(n=new Set(e.map(O)),ee.set(e,n)),n}function Ae(e){T(e);for(let n of Object.values(e)){let t=n?.type==="list"||n?.type==="hashed"?n.values:null;t&&t.length>=D&&oe(t)}return e}function h(e,n,t,r){t=t||{},r||T(t),r=r||new Set;for(let[o,s]of Object.entries(n))switch(o){case"$or":if(!ie(e,s,t,r))return!1;break;case"$nor":if(ie(e,s,t,r))return!1;break;case"$and":if(!Fe(e,s,t,r))return!1;break;case"$not":if(h(e,s,t,r))return!1;break;case"$savedGroup":if(!we(e,s,t,r))return!1;break;default:if(!V(s,se(e,o),t,!1,r))return!1}return!0}function we(e,n,t,r){if(!n||typeof n!="object"||Array.isArray(n))return!1;let{id:o,attributeKey:s}=n;if(typeof o!="string"||r.has(o)||s!==void 0&&typeof s!="string")return!1;let i=t[o];if(!i||Array.isArray(i)||typeof i!="object")return!1;let a=new Set(r).add(o);if(i.type==="list"||i.type==="hashed"){let u=s??i.attributeKey;if(typeof u!="string"||!Array.isArray(i.values))return!1;let f=se(e,u);return S(i.type==="hashed"?B(f):f,i.values)}return i.type==="condition"?!i.condition||typeof i.condition!="object"?!1:h(e,i.condition,t,a):!1}function se(e,n){let t=n.split("."),r=e;for(let o of t)if(r&&typeof r=="object"&&o in r)r=r[o];else return null;return r}function ne(e,n=!1){let t=`${e}${n?"/i":""}`,r=Y.get(t);return r||(r=new RegExp(e.replace(/([^\\])\//g,"$1\\/"),n?"i":void 0),Y.set(t,r)),r}function V(e,n,t,r=!1,o=new Set){if(typeof e=="string")return r?String(n).toLowerCase()===e.toLowerCase():n+""===e;if(typeof e=="number")return n*1===e;if(typeof e=="boolean")return n!==null&&!!n===e;if(e===null)return n===null;if(Array.isArray(e)||!ae(e))return JSON.stringify(n)===JSON.stringify(e);let s=e;for(let i in s)if(!Re(i,n,s[i],t,o))return!1;return!0}function ae(e){let n=Object.keys(e);return n.length>0&&n.filter(t=>t[0]==="$").length===n.length}function Ee(e){if(e===null)return"null";if(Array.isArray(e))return"array";let n=typeof e;return["string","number","boolean","object","undefined"].includes(n)?n:"unknown"}function Ve(e,n,t,r){if(!Array.isArray(e))return!1;let o=ae(n)?s=>V(n,s,t,!1,r):s=>h(s,n,t,r);for(let s=0;s<e.length;s++)if((e[s]??null)!==null&&o(e[s]))return!0;return!1}function S(e,n,t=!1){if(t){let o;if(n.length>=D){let s=ve(n);o=i=>{let a=O(i);return!(typeof a=="number"&&Number.isNaN(a))&&s.has(a)}}else o=s=>n.some(i=>O(s)===O(i));return Array.isArray(e)?e.some(s=>o(s)):o(e)}let r=n.length>=D?(o=>s=>o.has(s))(oe(n)):o=>n.includes(o);return Array.isArray(e)?e.some(o=>r(o)):r(e)}function te(e){return e===void 0?[]:e&&typeof e=="object"&&(e.type==="list"||e.type==="hashed")&&Array.isArray(e.values)?e.values:null}function re(e,n,t,r=!1,o=new Set){if(!Array.isArray(e))return!1;for(let s=0;s<n.length;s++){let i=!1;for(let a=0;a<e.length;a++)if(V(n[s],e[a],t,r,o)){i=!0;break}if(!i)return!1}return!0}function Re(e,n,t,r,o=new Set){let s=n,i=t;switch(e){case"$veq":return y(n)===y(t);case"$vne":return y(n)!==y(t);case"$vgt":return y(n)>y(t);case"$vgte":return y(n)>=y(t);case"$vlt":return y(n)<y(t);case"$vlte":return y(n)<=y(t);case"$eq":return n===t;case"$ne":return n!==t;case"$lt":return s<i;case"$lte":return s<=i;case"$gt":return s>i;case"$gte":return s>=i;case"$exists":return t?n!=null:n==null;case"$in":return Array.isArray(t)?S(n,t):!1;case"$ini":return Array.isArray(t)?S(n,t,!0):!1;case"$inGroup":{let a=r[t],u=te(a);return u===null?!1:S(a?.type==="hashed"?B(n):n,u)}case"$notInGroup":{let a=r[t],u=te(a);return u===null?!1:!S(a?.type==="hashed"?B(n):n,u)}case"$nin":return Array.isArray(t)?!S(n,t):!1;case"$nini":return Array.isArray(t)?!S(n,t,!0):!1;case"$not":return!V(t,n,r,!1,o);case"$size":return Array.isArray(n)?V(t,n.length,r,!1,o):!1;case"$elemMatch":return Ve(n,t,r,o);case"$all":return Array.isArray(t)?re(n,t,r,!1,o):!1;case"$alli":return Array.isArray(t)?re(n,t,r,!0,o):!1;case"$regex":try{return ne(t).test(n)}catch{return!1}case"$regexi":try{return ne(t,!0).test(n)}catch{return!1}case"$type":return Ee(n)===t;default:return!1}}function ie(e,n,t,r){if(!n.length)return!0;for(let o of n)if(h(e,o,t,r))return!0;return!1}function Fe(e,n,t,r){for(let o of n)if(!h(e,o,t,r))return!1;return!0}function ue(e){return Object.fromEntries(Object.entries(e).filter(([,n])=>n!==void 0))}function U(e){return H(e),{context:e,stack:{evaluatedFeatures:new Set}}}function _(e){return{...e.attributes,...e.attributeOverrides}}function p(e,n,t){let r=n||"id",o="",s=_(e);return s[r]&&(o=s[r]),!o&&t&&(s[t]&&(o=s[t]),o&&(r=t)),{hashAttribute:r,hashValue:o}}function l(e,n,t){e.context.log?.(n,t)}function x(e,n){return n=n||0,`${e}__${n}`}function q(e,n){return`${e}||${n}`}function Te(e,n,t){let r=e.stickyBucketAssignmentDocs;if(!r)return{};let{hashAttribute:o,hashValue:s}=p(e,n),i=q(o,E(s)),{hashAttribute:a,hashValue:u}=p(e,t),f=u?q(a,E(u)):null,c={};return f&&r[f]&&Object.assign(c,r[f].assignments||{}),r[i]&&Object.assign(c,r[i].assignments||{}),c}function le({context:e,expKey:n,expBucketVersion:t,expHashAttribute:r,expFallbackAttribute:o,expMinBucketVersion:s,expMeta:i}){t=t||0,s=s||0,r=r||"id",i=i||[];let a=x(n,t),u=Te(e,r,o);if(s>0)for(let d=0;d<s;d++){let k=x(n,d);if(u[k]!==void 0)return{variation:-1,versionIsBlocked:!0}}let f=u[a];if(f===void 0)return{variation:-1};let c=i.findIndex(d=>d.key===f);return c<0?{variation:-1}:{variation:c}}function fe(e,n,t,r){let o=q(n,t),s=e.stickyBucketAssignmentDocs,i=s&&s[o]?s[o].assignments||{}:{},a={...i,...r},u=JSON.stringify(i)!==JSON.stringify(a);return{key:o,doc:{attributeName:n,attributeValue:t,assignments:a},changed:u}}function Ce(e,n){let t=U(n),r=ge(e,null,t);return n.onExperimentEval?.(e,r),r}function $e(e,n){return N(e,U(n))}function Oe(e){return e.forcedVariations||{}}function ce(e,n,t){let{context:r}=e;if(r.trackedExperiments){let o=ke(n,t);if(r.trackedExperiments.has(o))return;r.trackedExperiments.add(o)}G(()=>r.onExperimentViewed?.(n,t))}function Be(e,n,t){let{context:r}=e;if(r.trackedFeatureUsage){let o=JSON.stringify(t.value);if(r.trackedFeatureUsage[n]===o)return;r.trackedFeatureUsage[n]=o}G(()=>r.onFeatureUsage?.(n,t))}function G(e){try{let n=e();n&&typeof n.catch=="function"&&n.catch(()=>{})}catch{}}function N(e,n){let{context:t}=n;if(n.stack.evaluatedFeatures.has(e))return l(n,`evalFeature: circular dependency detected: ${n.stack.id} -> ${e}`,{from:n.stack.id,to:e}),m(n,e,null,"cyclicPrerequisite");n.stack.evaluatedFeatures.add(e),n.stack.id=e;let r=t.features?.[e];for(let s of r?.rules??[])K(s);let o=t.forcedFeatureValues;if(o&&o.has(e))return l(n,"Global override",{id:e,value:o.get(e)}),m(n,e,o.get(e),"override");if(!r)return l(n,"Unknown feature",{id:e}),m(n,e,null,"unknownFeature");if(r.rules){let s=new Set(n.stack.evaluatedFeatures);e:for(let i of r.rules){if(i.parentConditions)for(let f of i.parentConditions){n.stack.evaluatedFeatures=new Set(s);let c=N(f.id,n);if(c.source==="cyclicPrerequisite")return m(n,e,null,"cyclicPrerequisite");let d={value:c.value};if(!h(d,f.condition||{},t.savedGroups||{})){if(f.gate)return l(n,"Feature blocked by prerequisite",{id:e,rule:i}),m(n,e,null,"prerequisite");l(n,"Skip rule because prerequisite evaluation fails",{id:e,rule:i});continue e}}if(i.filters&&ye(i.filters,n)){l(n,"Skip rule because of filters",{id:e,rule:i});continue}if("force"in i){if(i.condition&&!de(i.condition,n)){l(n,"Skip rule because of condition ff",{id:e,rule:i});continue}if(!xe(n,i.seed||e,i.hashAttribute,t.saveStickyBucketAssignmentDoc&&!i.disableStickyBucketing?i.fallbackAttribute:void 0,i.range,i.coverage,i.hashVersion)){l(n,"Skip rule because user not included in rollout",{id:e,rule:i});continue}return l(n,"Force value from rule",{id:e,rule:i}),i.tracks&&i.tracks.forEach(f=>{ce(n,f.experiment,f.result)}),m(n,e,i.force,"force",i.id)}if(!i.variations){l(n,"Skip invalid rule",{id:e,rule:i});continue}let a={variations:i.variations,key:i.key||e};"coverage"in i&&(a.coverage=i.coverage),i.weights&&(a.weights=i.weights),i.hashAttribute&&(a.hashAttribute=i.hashAttribute),i.fallbackAttribute&&(a.fallbackAttribute=i.fallbackAttribute),i.disableStickyBucketing&&(a.disableStickyBucketing=i.disableStickyBucketing),i.bucketVersion!==void 0&&(a.bucketVersion=i.bucketVersion),i.minBucketVersion!==void 0&&(a.minBucketVersion=i.minBucketVersion),i.meta&&(a.meta=i.meta),i.ranges&&(a.ranges=i.ranges),i.name&&(a.name=i.name),i.phase&&(a.phase=i.phase),i.seed&&(a.seed=i.seed),i.hashVersion&&(a.hashVersion=i.hashVersion),i.filters&&(a.filters=i.filters),i.condition&&(a.condition=i.condition);let u=ge(a,e,n);if(t.onExperimentEval?.(a,u),u.inExperiment&&!u.passthrough)return m(n,e,u.value,"experiment",i.id,a,u)}}return l(n,"Use default value",{id:e,value:r.defaultValue}),m(n,e,r.defaultValue===void 0?null:r.defaultValue,"defaultValue")}function ge(e,n,t){let{context:r}=t;K(e);let o=e.key,s=e.variations.length;if(s<2)return l(t,"Invalid experiment",{id:o}),g(t,e,-1,!1,n);if(r.enabled===!1)return l(t,"Context disabled",{id:o}),g(t,e,-1,!1,n);if(e.urlPatterns&&!j(r.url||"",e.urlPatterns))return l(t,"Skip because of url targeting",{id:o}),g(t,e,-1,!1,n);let i=z(o,r.url||"",s);if(i!==null)return l(t,"Force via querystring",{id:o,variation:i}),g(t,e,i,!1,n);let u=Oe(r)[o];if(u!==void 0)return l(t,"Force via dev tools",{id:o,variation:u}),g(t,e,u,!1,n);if(e.active===!1)return l(t,"Skip because inactive",{id:o}),g(t,e,-1,!1,n);let{hashAttribute:f,hashValue:c}=p(r,e.hashAttribute,r.saveStickyBucketAssignmentDoc&&!e.disableStickyBucketing?e.fallbackAttribute:void 0);if(!c)return l(t,"Skip because missing hashAttribute",{id:o}),g(t,e,-1,!1,n);let d=-1,k=!1,R=!1;if(r.saveStickyBucketAssignmentDoc&&!e.disableStickyBucketing){let{variation:b,versionIsBlocked:v}=le(ue({context:r,expKey:e.key,expBucketVersion:e.bucketVersion,expHashAttribute:e.hashAttribute,expFallbackAttribute:e.fallbackAttribute,expMinBucketVersion:e.minBucketVersion,expMeta:e.meta}));k=b>=0,d=b,R=!!v}if(!k){if(e.filters&&ye(e.filters,t))return l(t,"Skip because of filters",{id:o}),g(t,e,-1,!1,n);if(e.include&&!X(e.include))return l(t,"Skip because of include function",{id:o}),g(t,e,-1,!1,n);if(e.condition&&!de(e.condition,t))return l(t,"Skip because of condition exp",{id:o}),g(t,e,-1,!1,n);if(e.parentConditions){let b=new Set(t.stack.evaluatedFeatures);for(let v of e.parentConditions){t.stack.evaluatedFeatures=new Set(b);let w=N(v.id,t);if(w.source==="cyclicPrerequisite")return g(t,e,-1,!1,n);let P={value:w.value};if(!h(P,v.condition||{},r.savedGroups||{}))return l(t,"Skip because prerequisite evaluation fails",{id:o}),g(t,e,-1,!1,n)}}}let A=C(e.seed||o,c,e.hashVersion??2);if(A===null)return l(t,"Skip because of invalid hash version",{id:o}),g(t,e,-1,!1,n);if(!k){let b=e.ranges||Q(s,e.coverage===void 0?1:e.coverage,e.weights);d=W(A,b)}if(R)return l(t,"Skip because sticky bucket version is blocked",{id:o}),g(t,e,-1,!1,n,void 0,!0);if(d<0)return l(t,"Skip because of coverage",{id:o}),g(t,e,-1,!1,n);if("force"in e)return l(t,"Force variation",{id:o,variation:e.force}),g(t,e,e.force===void 0?-1:e.force,!1,n);if(r.qaMode)return l(t,"Skip because QA mode",{id:o}),g(t,e,-1,!1,n);let F=g(t,e,d,!0,n,A,k);if(r.saveStickyBucketAssignmentDoc&&!e.disableStickyBucketing){let{changed:b,key:v,doc:w}=fe(r,f,E(c),{[x(e.key,e.bucketVersion)]:F.key});if(b){r.stickyBucketAssignmentDocs=r.stickyBucketAssignmentDocs||{},r.stickyBucketAssignmentDocs[v]=w;let P=r.saveStickyBucketAssignmentDoc;G(()=>P(w))}}return ce(t,e,F),l(t,"In experiment",{id:o,variation:F.variationId}),F}function m(e,n,t,r,o,s,i){let a={value:t,on:!!t,off:!t,source:r,ruleId:o||""};return s&&(a.experiment=s),i&&(a.experimentResult=i),r!=="override"&&Be(e,n,a),a}function de(e,n){return h(_(n.context),e,n.context.savedGroups||{})}function ye(e,n){return e.some(t=>{let{hashValue:r}=p(n.context,t.attribute);if(!r)return!0;let o=C(t.seed,r,t.hashVersion||2);return o===null?!0:!t.ranges.some(s=>$(o,s))})}function xe(e,n,t,r,o,s,i){if(!o&&s===void 0)return!0;if(!o&&s===0)return!1;let{hashValue:a}=p(e.context,t,r);if(!a)return!1;let u=C(n,a,i??2);return u===null?!1:o?$(u,o):s!==void 0?u<=s:!0}function g(e,n,t,r,o,s,i){let a=!0;(t<0||t>=n.variations.length)&&(t=0,a=!1);let{hashAttribute:u,hashValue:f}=p(e.context,n.hashAttribute,e.context.saveStickyBucketAssignmentDoc&&!n.disableStickyBucketing?n.fallbackAttribute:void 0),c=n.meta?.[t]??{},d=n.variations[0];for(let[R,A]of n.variations.entries())if(R===t){d=A;break}let k={key:c.key||""+t,featureId:o,inExperiment:a,hashUsed:r,variationId:t,value:d,hashAttribute:u,hashValue:f,stickyBucketUsed:!!i};return c.name&&(k.name=c.name),s!==void 0&&(k.bucket=s),c.passthrough&&(k.passthrough=c.passthrough),k}function ke(e,n){return n.hashAttribute+n.hashValue+e.key+n.variationId}/*!
2
2
  Copyright (c) 2025 GrowthBook, Inc.
3
3
 
4
4
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
@@ -1 +1 @@
1
- import{x as c}from"./chunk-WRUW2UIJ.js";import{b as r}from"./chunk-ZY4XAKNQ.js";var s=r.strictObject({items:r.array(r.strictObject({productVersionId:r.string().min(1).max(200),label:r.string().trim().max(40)})).max(20).refine(e=>new Set(e.map(t=>t.productVersionId)).size===e.length,"Duplicate Paywall Product"),defaultProductVersionId:r.string().min(1).max(200).nullable(),grouping:c.optional()});function p(e,t,n){let i=e.type==="fixed"?e.productVersionId:t[e.pickerId];return typeof i!="string"||!Object.values(n.plans).some(o=>o.versionId===i&&o.available)||e.type==="picker"&&(!e.allowedProductVersionIds.includes(i)||!n.pickers[e.pickerId]?.options.includes(i))?null:i}export{s as a,p as b};
1
+ import{x as c}from"./chunk-N7YXDSQL.js";import{b as r}from"./chunk-VF6QMMEA.js";var s=r.strictObject({items:r.array(r.strictObject({productVersionId:r.string().min(1).max(200),label:r.string().trim().max(40)})).max(20).refine(e=>new Set(e.map(t=>t.productVersionId)).size===e.length,"Duplicate Paywall Product"),defaultProductVersionId:r.string().min(1).max(200).nullable(),grouping:c.optional()});function p(e,t,n){let i=e.type==="fixed"?e.productVersionId:t[e.pickerId];return typeof i!="string"||!Object.values(n.plans).some(o=>o.versionId===i&&o.available)||e.type==="picker"&&(!e.allowedProductVersionIds.includes(i)||!n.pickers[e.pickerId]?.options.includes(i))?null:i}export{s as a,p as b};
@@ -1 +1 @@
1
- var s={name:"@tinkerlandai/longplay-sdk",version:"0.10.31",description:"Framework-independent Longplay SDK for customer identity, entitlements, credits, offers and growth surfaces.",license:"UNLICENSED",repository:{type:"git",url:"git+https://github.com/tinkerlandai/Indiana.git",directory:"packages/sdk"},engines:{node:">=22"},publishConfig:{access:"public",tag:"beta"},type:"module",sideEffects:!1,files:["dist","README.md","README.zh-CN.md","CHANGELOG.md","THIRD_PARTY_NOTICES.md"],exports:{"./react-native":{types:"./dist/react-native.d.ts","react-native":"./dist/react-native.js",import:"./dist/react-native.js",default:"./dist/react-native.js"},".":{types:"./dist/index.d.ts",import:"./dist/index.js"},"./popup":{types:"./dist/popup.d.ts",import:"./dist/popup.js"},"./server":{types:"./dist/server.d.ts",import:"./dist/server.js"},"./openrouter":{types:"./dist/openrouter.d.ts",import:"./dist/openrouter.js"},"./native-shell":{types:"./dist/native-shell.d.ts",import:"./dist/native-shell.js"},"./page":{types:"./dist/page.d.ts",import:"./dist/page.js"},"./visual":{types:"./dist/visual.d.ts",import:"./dist/visual.js"}},scripts:{build:"tsup",prepack:"pnpm run build",typecheck:"tsc --noEmit && tsc --noEmit -p tsconfig.test.json",lint:"node ../../scripts/ci/lint.mjs --workspace packages/sdk"},dependencies:{"@ai-sdk/provider":"4.0.26","@types/json-schema":"7.0.15","css-tree":"^3.2.1","dom-mutator":"0.7.0",dompurify:"^3.4.15",zod:"4.6.6"},devDependencies:{"@indiana/contracts":"workspace:*","@openrouter/sdk":"^1.4.25","@types/css-tree":"^3.2.0",ai:"7.0.136",tsup:"^8.5.1",typescript:"^5.9.3","whatwg-url-minimum":"0.2.0"},peerDependencies:{"@openrouter/sdk":"^1.4.25"},peerDependenciesMeta:{"@openrouter/sdk":{optional:!0}}};var i="https://api.longplayai.com";export{s as a,i as b};
1
+ var s={name:"@tinkerlandai/longplay-sdk",version:"0.10.32",description:"Framework-independent Longplay SDK for customer identity, entitlements, credits, offers and growth surfaces.",license:"UNLICENSED",repository:{type:"git",url:"git+https://github.com/tinkerlandai/Indiana.git",directory:"packages/sdk"},engines:{node:">=22"},publishConfig:{access:"public",tag:"beta"},type:"module",sideEffects:!1,files:["dist","README.md","README.zh-CN.md","CHANGELOG.md","THIRD_PARTY_NOTICES.md"],exports:{"./react-native":{types:"./dist/react-native.d.ts","react-native":"./dist/react-native.js",import:"./dist/react-native.js",default:"./dist/react-native.js"},".":{types:"./dist/index.d.ts",import:"./dist/index.js"},"./popup":{types:"./dist/popup.d.ts",import:"./dist/popup.js"},"./server":{types:"./dist/server.d.ts",import:"./dist/server.js"},"./openrouter":{types:"./dist/openrouter.d.ts",import:"./dist/openrouter.js"},"./native-shell":{types:"./dist/native-shell.d.ts",import:"./dist/native-shell.js"},"./page":{types:"./dist/page.d.ts",import:"./dist/page.js"},"./visual":{types:"./dist/visual.d.ts",import:"./dist/visual.js"}},scripts:{build:"tsup",prepack:"pnpm run build",typecheck:"tsc --noEmit && tsc --noEmit -p tsconfig.test.json",lint:"node ../../scripts/ci/lint.mjs --workspace packages/sdk"},dependencies:{"@ai-sdk/provider":"4.0.26","@types/json-schema":"7.0.15","css-tree":"^3.2.1","dom-mutator":"0.7.0",dompurify:"^3.4.15",zod:"4.6.6"},devDependencies:{"@indiana/contracts":"workspace:*","@openrouter/sdk":"^1.4.25","@types/css-tree":"^3.2.0",ai:"7.0.136",tsup:"^8.5.1",typescript:"^5.9.3","whatwg-url-minimum":"0.2.0"},peerDependencies:{"@openrouter/sdk":"^1.4.25"},peerDependenciesMeta:{"@openrouter/sdk":{optional:!0}}};var i="https://api.longplayai.com";export{s as a,i as b};
@@ -1 +1 @@
1
- import{a as c}from"./chunk-HJLGRW4A.js";function d(t){let{quote:r,operation:e,requestId:i}=t,o={type:"recover",operationId:e?.operationId??r?.operationId??null,requestId:i};if(t.destroyed||t.pending)return o;if(!e)return r?{type:"cancel",operationId:r.operationId}:o;let n=e.merchantExecution;if(n?.type==="purchase"){if(["succeeded","not_required"].includes(n.paymentStatus))return!["applied","not_applicable"].includes(n.fulfillmentStatus)||e.problem?.phase==="fulfillment"||n.problem?.phase==="fulfillment"?{type:"fulfillment",operationId:e.operationId}:{type:n.recordingStatus==="accepted"&&e.status==="complete"&&!e.problem&&!n.problem?"complete":"recording",operationId:e.operationId};if(e.status==="pending"&&e.checkoutUrl&&n.checkoutUrl===e.checkoutUrl&&n.checkoutExpiresAt&&Date.parse(n.checkoutExpiresAt)>Date.now()&&["not_started","pending"].includes(n.paymentStatus))return{type:"checkout",operationId:e.operationId,checkoutUrl:e.checkoutUrl}}if(e.executor==="indiana"&&e.status==="pending"&&e.checkoutUrl&&!e.problem&&!e.nativePurchase&&(!r||Date.parse(r.expiresAt)>Date.now()))return{type:"checkout",operationId:e.operationId,checkoutUrl:e.checkoutUrl};let p=[e.problem,n?.problem],s=p.every(u=>!u||u.phase==="execution"&&u.reason!=="RESULT_UNKNOWN");return!p.some(Boolean)&&e.status==="complete"&&e.executor!=="merchant"?{type:"complete",operationId:e.operationId}:s&&t.canReselect!==!1&&["cancelled","failed"].includes(e.status)&&!e.checkoutUrl&&!e.execution&&!e.nativePurchase&&(e.executor!=="merchant"?!e.confirmedAt&&(e.status==="cancelled"||!e.quoteFinalized):!n&&!e.quoteFinalized||n?.type==="purchase"&&["failed","expired"].includes(n.paymentStatus)&&n.fulfillmentStatus==="not_applicable"&&n.recordingStatus==="accepted")?{type:"native",operationId:e.operationId}:e.status==="pending"&&s&&!e.quoteFinalized&&!n&&!e.checkoutUrl&&!e.execution&&!e.nativePurchase?{type:"cancel",operationId:e.operationId}:o}function f(t,r=!0){if(!t)return!1;let e=d({quote:t.quote??null,operation:t,requestId:null,pending:!1,destroyed:!1,canReselect:r});return e.type==="complete"||e.type==="native"}function l(t){return t.recovery??{type:"recover",operationId:t.operation?.operationId??t.quote?.operationId??null,requestId:null}}async function y(t){let r=l(t);if(r.type==="recover"&&t.quote)try{await t.read(),r=l(t)}catch{return r}if(r.type!=="cancel"&&!(r.type==="recover"&&t.pendingCancellation))return r;try{await t.cancel();let e=l(t);return e.type==="cancel"?{type:"recover",operationId:r.operationId,requestId:null}:e}catch{let e=l(t);return e.type==="recover"?e:{type:"recover",operationId:r.operationId,requestId:null}}}function m(t,r){let e=structuredClone(t);for(let[i,a]of Object.entries(e.plans)){let o=r.plans[i];!o||o.versionId!==a.versionId||(o.amountMinor!==void 0&&(a.amountMinor=o.amountMinor),o.interval!==void 0&&(a.interval=o.interval),o.intervalCount!==void 0&&(a.intervalCount=o.intervalCount),o.prepaid!==void 0&&(a.prepaid=structuredClone(o.prepaid)))}return e}function b(t,r){let e=i=>"document"in i?i.offering.id:i.content.offeringVersionId;return t.id===r.id&&e(t)===e(r)&&t.content?.artifact.sha256===r.content?.artifact.sha256}function S(t,r,e){if(t.operationId!==r.operationId||r.currency!==void 0&&t.currency!==r.currency)throw new c("INVALID_RESPONSE",e)}function v(t,r,e){let i=Object.fromEntries((t.lines[0]?.prepaid??[]).map(a=>[a.internal_feature_id,a.quantity]));if(r.featureQuantities&&(Object.keys(i).length!==Object.keys(r.featureQuantities).length||Object.entries(r.featureQuantities).some(([a,o])=>i[a]!==o)))throw new c("INVALID_RESPONSE","The purchase quote changed its selected quantities");if(t.lines.length!==1||t.lines[0].productVersionId!==r.productVersionId||r.currency!==void 0&&t.currency!==r.currency||r.provider!==void 0&&t.provider!==r.provider&&!(r.provider==="stripe"&&t.provider==="merchant"&&t.execution?.provider==="merchant"))throw new c("INVALID_RESPONSE",e)}function g(t,r,e=!1){if(!t||t.operationId!==r?.operationId)return r;let i=t.merchantExecution,a=r.merchantExecution;return i&&(!a||Date.parse(a.updatedAt)<Date.parse(i.updatedAt))||t.status==="complete"&&r.status!=="complete"||t.status!=="pending"&&(r.status==="pending"||e&&r.status!=="complete")?t:r}function w(t){return t.screen.actions.some(r=>r.properties.closeControl==="content"&&t.buttons[r.id]?.type==="close")}export{d as a,f as b,l as c,y as d,m as e,b as f,S as g,v as h,g as i,w as j};
1
+ import{a as c}from"./chunk-X4W22IH6.js";function d(t){let{quote:r,operation:e,requestId:i}=t,o={type:"recover",operationId:e?.operationId??r?.operationId??null,requestId:i};if(t.destroyed||t.pending)return o;if(!e)return r?{type:"cancel",operationId:r.operationId}:o;let n=e.merchantExecution;if(n?.type==="purchase"){if(["succeeded","not_required"].includes(n.paymentStatus))return!["applied","not_applicable"].includes(n.fulfillmentStatus)||e.problem?.phase==="fulfillment"||n.problem?.phase==="fulfillment"?{type:"fulfillment",operationId:e.operationId}:{type:n.recordingStatus==="accepted"&&e.status==="complete"&&!e.problem&&!n.problem?"complete":"recording",operationId:e.operationId};if(e.status==="pending"&&e.checkoutUrl&&n.checkoutUrl===e.checkoutUrl&&n.checkoutExpiresAt&&Date.parse(n.checkoutExpiresAt)>Date.now()&&["not_started","pending"].includes(n.paymentStatus))return{type:"checkout",operationId:e.operationId,checkoutUrl:e.checkoutUrl}}if(e.executor==="indiana"&&e.status==="pending"&&e.checkoutUrl&&!e.problem&&!e.nativePurchase&&(!r||Date.parse(r.expiresAt)>Date.now()))return{type:"checkout",operationId:e.operationId,checkoutUrl:e.checkoutUrl};let p=[e.problem,n?.problem],s=p.every(u=>!u||u.phase==="execution"&&u.reason!=="RESULT_UNKNOWN");return!p.some(Boolean)&&e.status==="complete"&&e.executor!=="merchant"?{type:"complete",operationId:e.operationId}:s&&t.canReselect!==!1&&["cancelled","failed"].includes(e.status)&&!e.checkoutUrl&&!e.execution&&!e.nativePurchase&&(e.executor!=="merchant"?!e.confirmedAt&&(e.status==="cancelled"||!e.quoteFinalized):!n&&!e.quoteFinalized||n?.type==="purchase"&&["failed","expired"].includes(n.paymentStatus)&&n.fulfillmentStatus==="not_applicable"&&n.recordingStatus==="accepted")?{type:"native",operationId:e.operationId}:e.status==="pending"&&s&&!e.quoteFinalized&&!n&&!e.checkoutUrl&&!e.execution&&!e.nativePurchase?{type:"cancel",operationId:e.operationId}:o}function f(t,r=!0){if(!t)return!1;let e=d({quote:t.quote??null,operation:t,requestId:null,pending:!1,destroyed:!1,canReselect:r});return e.type==="complete"||e.type==="native"}function l(t){return t.recovery??{type:"recover",operationId:t.operation?.operationId??t.quote?.operationId??null,requestId:null}}async function y(t){let r=l(t);if(r.type==="recover"&&t.quote)try{await t.read(),r=l(t)}catch{return r}if(r.type!=="cancel"&&!(r.type==="recover"&&t.pendingCancellation))return r;try{await t.cancel();let e=l(t);return e.type==="cancel"?{type:"recover",operationId:r.operationId,requestId:null}:e}catch{let e=l(t);return e.type==="recover"?e:{type:"recover",operationId:r.operationId,requestId:null}}}function m(t,r){let e=structuredClone(t);for(let[i,a]of Object.entries(e.plans)){let o=r.plans[i];!o||o.versionId!==a.versionId||(o.amountMinor!==void 0&&(a.amountMinor=o.amountMinor),o.interval!==void 0&&(a.interval=o.interval),o.intervalCount!==void 0&&(a.intervalCount=o.intervalCount),o.prepaid!==void 0&&(a.prepaid=structuredClone(o.prepaid)))}return e}function b(t,r){let e=i=>"document"in i?i.offering.id:i.content.offeringVersionId;return t.id===r.id&&e(t)===e(r)&&t.content?.artifact.sha256===r.content?.artifact.sha256}function S(t,r,e){if(t.operationId!==r.operationId||r.currency!==void 0&&t.currency!==r.currency)throw new c("INVALID_RESPONSE",e)}function v(t,r,e){let i=Object.fromEntries((t.lines[0]?.prepaid??[]).map(a=>[a.internal_feature_id,a.quantity]));if(r.featureQuantities&&(Object.keys(i).length!==Object.keys(r.featureQuantities).length||Object.entries(r.featureQuantities).some(([a,o])=>i[a]!==o)))throw new c("INVALID_RESPONSE","The purchase quote changed its selected quantities");if(t.lines.length!==1||t.lines[0].productVersionId!==r.productVersionId||r.currency!==void 0&&t.currency!==r.currency||r.provider!==void 0&&t.provider!==r.provider&&!(r.provider==="stripe"&&t.provider==="merchant"&&t.execution?.provider==="merchant"))throw new c("INVALID_RESPONSE",e)}function g(t,r,e=!1){if(!t||t.operationId!==r?.operationId)return r;let i=t.merchantExecution,a=r.merchantExecution;return i&&(!a||Date.parse(a.updatedAt)<Date.parse(i.updatedAt))||t.status==="complete"&&r.status!=="complete"||t.status!=="pending"&&(r.status==="pending"||e&&r.status!=="complete")?t:r}function w(t){return t.screen.actions.some(r=>r.properties.closeControl==="content"&&t.buttons[r.id]?.type==="close")}export{d as a,f as b,l as c,y as d,m as e,b as f,S as g,v as h,g as i,w as j};
@@ -1 +1 @@
1
- import{a as T,b as se}from"./chunk-2TPPGW7V.js";import{b as re,h as ae,j as ce}from"./chunk-2QQZSMTB.js";import{a as oe,b as j}from"./chunk-23WNEOK4.js";import{c as Z,e as ee,f as te,g as H,h as G,j as ne}from"./chunk-JNSU2AP2.js";import{F as M,b as J}from"./chunk-7Z7JT4HE.js";import{a as b,b as f,c as m}from"./chunk-WK4WQZHK.js";import{b as W,j as X}from"./chunk-4ZVVG5LM.js";import{E as $}from"./chunk-ITVSLSRM.js";import{b as ie}from"./chunk-XZEGVBAI.js";import{a as B}from"./chunk-J4VTKRH7.js";import{a as s}from"./chunk-HJLGRW4A.js";import{h as Q}from"./chunk-XIP32WI7.js";import{b as K}from"./chunk-ZY4XAKNQ.js";import{a as z}from"./chunk-DSPLGTQI.js";var U=t=>{if(!Number.isSafeInteger(t)||t<0||t>=Number.MAX_SAFE_INTEGER)throw new s("INVALID_STATE","Installation sequence exhausted");return t+1},Se=async t=>[...new Uint8Array(await crypto.subtle.digest("SHA-256",Uint8Array.from(t,e=>e.charCodeAt(0))))].map(e=>e.toString(16).padStart(2,"0")).join("");function _(t,e){return t.transaction(n=>{if(!Number.isSafeInteger(n.identitySeq)||n.identitySeq<0||!Number.isSafeInteger(n.addressSeq)||n.addressSeq<0||n.detachSeq!==null&&(!Number.isSafeInteger(n.detachSeq)||n.detachSeq<1||n.detachSeq>n.identitySeq))throw new s("INVALID_STATE","Installation journal is invalid");return e({...n})})}function ue(t,e,n){let r=null,o=0,a=0,d=0,y=Promise.resolve(),g=!1;if(t&&(!n||Q.parse(t.scope).projectId!==n.projectId||t.scope.environment!==n.environment))throw new s("SCOPE_MISMATCH","Push installation belongs to another scope");let l=()=>{if(g)throw new s("CLOSED","SDK client was destroyed");if(!t)throw new s("NOT_CONFIGURED","Configure this client's native Push host first");return t},O=i=>{if(i!==o)throw new s("IDENTITY_CHANGED","Identity changed during Push operation")};async function F(i){let c=l();if(!c.sha256&&!globalThis.crypto?.subtle)throw new s("NOT_CONFIGURED","Configure native SHA-256 for this Push host");let u=c.sha256?await c.sha256(Uint8Array.from(i,A=>A.charCodeAt(0))):await Se(i);if(!/^[a-f0-9]{64}$/.test(u))throw new s("INVALID_STATE","Push credential digest is invalid");return u}function p(i){let c=G.parse(i);if(c.installationId.toLowerCase()!==l().installationId.toLowerCase())throw new s("INVALID_RESPONSE","Push response belongs to another installation");return c}async function S(i,c){let u=l(),A={installationId:u.installationId,publicKey:u.publicKey,issuedAt:new Date().toISOString(),...c},w=await u.sign(ne(i,u.scope,A));return{...A,signature:w}}let I=(i,c,u)=>e.requestWithCredential?e.requestWithCredential(i,c,u):e.request(i,c);async function q(){let i=l(),c=o,u=r?await(e.session?.access()??r):null,A=_(i,v=>v),w;if(A.detachSeq!==null){let v=A.detachSeq,V=Z.parse(await S("detach",{sequence:v,platform:i.platform}));try{let k=await e.request("push/installations/detach",{...i.scope,...V},"POST",{installationDetach:!0});if(!k||typeof k!="object"||!("installation"in k))throw new s("INVALID_RESPONSE","Push detach acknowledgement is invalid");let x=p(k.installation);if(x.bound||x.identitySeq!==v)throw new s("INVALID_RESPONSE","Push detach acknowledgement does not match its intent")}catch(k){if(k instanceof s&&k.status===404)w=k;else if(!(k instanceof s)||k.status!==412)throw k}w||_(i,k=>({...k,detachSeq:k.detachSeq===v?null:k.detachSeq}))}if(O(c),!u){if(w)throw w;return null}let C=(await import("./operation-contracts-SP2RZUT3.js")).apiOperations.bindPushInstallation,D=C.request.parse(await S("bind",{sequence:d,platform:i.platform,credentialDigest:await F(u)}));O(c);let R=C.response.parse(await I(C.path,D,u));O(c);let N=p(R.installation);if(!N.bound||N.identitySeq!==d)throw new s("INVALID_RESPONSE","Push binding acknowledgement does not match its intent");return w&&A.detachSeq!==null&&d>A.detachSeq&&_(i,v=>({...v,detachSeq:v.detachSeq===A.detachSeq?null:v.detachSeq})),N}async function h(){l();let i=o,c=r?await(e.session?.access()??r):null;if(!c)throw new s("NOT_IDENTIFIED","Identify before reading this installation");let u=(await import("./operation-contracts-SP2RZUT3.js")).apiOperations.readPushInstallation,A=u.request.parse(await S("read",{credentialDigest:await F(c)}));O(i);let w=u.response.parse(await I(u.path,A,c));return O(i),p(w.installation)}function P(i=q){let c=y.catch(()=>{}).then(i);return y=c,c.catch(u=>{try{t?.onError?.(u instanceof Error?u:new Error("Push synchronization failed"))}catch{}}),c}async function E(i,c,u){let A=l(),w=c.identity,C=c.observation,D=r?await(e.session?.access()??r):null;if(O(w),C!==a)throw new s("INVALID_STATE","Push observation changed during recovery");if(!D)throw new s("NOT_IDENTIFIED","Identify before recovering a Push address");if(!i.connectionId||!i.kind||!i.token||!["granted","provisional"].includes(i.permission))throw new s("INVALID_REQUEST","Recovery needs a provider token and notification permission");return await P(async()=>{if(O(w),await q(),O(w),C!==a)throw new s("INVALID_STATE","Push observation changed during recovery");let R=_(A,x=>u?x:{...x,addressSeq:U(x.addressSeq)}),v=await S(u?"recovery_confirm":"recovery_request",{...i,sequence:R.addressSeq,credentialDigest:await F(D),...u?{challenge:u}:{}}),V=u?te.parse(v):ee.parse(v);if(O(w),C!==a)throw new s("INVALID_STATE","Push observation changed during recovery");let k=await I(`push/installations/recovery/${u?"confirm":"request"}`,V,D);if(O(w),C!==a||_(A,x=>x).addressSeq!==R.addressSeq)throw new s("INVALID_STATE","Push observation changed during recovery");if(u){let{apiOperations:x}=await import("./operation-contracts-SP2RZUT3.js");if(O(w),C!==a||_(A,Oe=>Oe).addressSeq!==R.addressSeq)throw new s("INVALID_STATE","Push observation changed during recovery");let Ae=x.updatePushAddress.response.parse(k),L=p(Ae.installation);if(!L.bound||L.identitySeq!==d||L.addressSeq!==R.addressSeq||L.connectionId!==i.connectionId||L.addressStatus!=="active")throw new s("INVALID_RESPONSE","Push recovery acknowledgement does not match its intent");return L}if(!k||typeof k!="object"||!("recovery"in k))throw new s("INVALID_RESPONSE","Push recovery acknowledgement is invalid");return H.parse(k.recovery)})}return{recoveryObserver(){l();let i={identity:o,observation:++a};return{async request(c){return H.parse(await E(c,i))},async confirm(c,u){return G.parse(await E(u,i,c))}}},identify(i){if(!t)return;d=_(t,u=>({...u,identitySeq:U(u.identitySeq)})).identitySeq,r=i,o++,a++},reset(){if(t)try{_(t,i=>{let c=U(i.identitySeq);return{...i,identitySeq:c,detachSeq:c}})}finally{r=null,o++,a++}},start(){t&&!g&&P()},destroy(){g=!0,r=null,o++,a++},async sync(){return await P()},read:h,async recover(){let i=l(),c=o,u=d;return a++,await P(async()=>{O(c);let A=await h();return O(c),d=_(i,C=>{if(C.identitySeq!==u)throw new s("IDENTITY_CHANGED","A newer installation intent exists");return{...C,identitySeq:U(Math.max(C.identitySeq,A.identitySeq)),addressSeq:Math.max(C.addressSeq,A.addressSeq)}}).identitySeq,await q()})},tokenObserver(){l();let i=++a,c=o;return async u=>{if(i!==a||c!==o)return null;let A=l(),w=r?await(e.session?.access()??r):null;if(!w)throw new s("NOT_IDENTIFIED","Identify before registering a Push token");if(await P(),O(c),i!==a)return null;let C=_(A,v=>({...v,addressSeq:U(v.addressSeq)})),D=(await import("./operation-contracts-SP2RZUT3.js")).apiOperations.updatePushAddress,R=D.request.parse(await S("address",{...u,sequence:C.addressSeq,credentialDigest:await F(w)}));if(O(c),i!==a)return null;let N=await I(D.path,R,w);return O(c),i!==a||_(A,v=>v).addressSeq!==C.addressSeq?null:p(D.response.parse(N).installation)}}}}function de(t,e){let n={async preference(r){let o=await f(t,"readMessagingPreference");return(await m(t,o,{channel:r})).preference},async setPreference(r){r=b(r);let o=await f(t,"setMessagingPreference");return(await m(t,o,r)).preference}};return{messaging:n,push:{sync:e.sync,read:e.read,recover:e.recover,tokenObserver:e.tokenObserver,recoveryObserver:e.recoveryObserver,async preference(){return n.preference("push")},async setPreference(r){return r=b(r),n.setPreference({...r,channel:"push"})}}}}function le(t,e,n={}){let r=!1;function o(){if(r)throw new s("CLOSED","SDK client was destroyed")}let a=new Set,d=g=>{for(let l of a)try{l(g)}catch{}},y=t.session.subscribeIdentity(()=>{d(!!t.session.peek()),n.afterChange?.()},()=>{e()});return{assertActive:o,isIdentified:()=>!r&&!!t.session.peek(),methods:{subscribeIdentity(g){return o(),a.add(g),()=>{a.delete(g)}},identify(g){o();let l=typeof g=="string"?g:g.accessToken;if(!B.test(l))throw new s("INVALID_TOKEN","Browser SDK requires a customer session");n.beforeIdentify?.(l),t.identify(g)},reset(){if(!r)try{n.beforeReset?.()}finally{t.reset()}},destroy(){if(!r){r=!0,y(),a.clear();try{n.beforeDestroy?.(),e()}finally{t.dispose()}}}}}}function pe(t){return{async checkEntitlement(e){e=b(e),T(e);let n=await f(t,"checkEntitlement"),r=n.request.parse(e),o=await m(t,n,r);return oe(r.requirement,o.check,void 0,o.scope),o},async readHoldings(e={}){e=b(e);let n=await f(t,"readHoldings"),r={...n,request:n.request.omit({customerId:!0})};return m(t,r,e)}}}function fe(t){return{async readLedger(e){e=b(e);let n=await f(t,"readLedger");return m(t,n,{query:e})},async readCreditStatement(e){e=b(e),T(e);let n=await f(t,"readCreditStatement");return m(t,n,e)},async quoteBalance(e){e=b(e),T(e);let n=await f(t,"quoteBalance");return m(t,n,{command:e})}}}function me(t){return{async setupPayment(e){e=b(e),T(e);let n=await f(t,"setupPayment");return m(t,n,e)},async readPaymentSetup(e){e=b(e),T(e);let n=await f(t,"readPaymentSetup");return m(t,n,e)},async readBillingInvoice(e){e=b(e),T(e);let n=await f(t,"readBillingInvoice");return m(t,n,e)},async readBillingControls(e={}){e=b(e),T(e);let n=await f(t,"readBillingControls");return m(t,n,e)},async prepareBillingAuthorization(e){e=b(e),T(e);let n=await f(t,"prepareBillingAuthorization");return m(t,n,e)},async confirmBillingAuthorization(e){e=b(e),T(e);let n=await f(t,"confirmBillingAuthorization");return m(t,n,e)},async setBillingCoupons(e){e=b(e),T(e);let n=await f(t,"setBillingCoupons");return m(t,n,e,{request:"Invalid billing coupon list",response:"Invalid billing coupon receipt"})},async revokeBillingAuthorization(e){e=b(e),T(e);let n=await f(t,"revokeBillingAuthorization");return m(t,n,e)},async listBillingInvoices(e={after:null,limit:25}){e=b(e),T(e);let n=await f(t,"listBillingInvoices");return m(t,n,e)},async confirmBillingAdjustment(e){e=b(e),T(e);let n=await f(t,"confirmBillingAdjustment");return m(t,n,e)}}}function ye(t){return{async redeemReward(e){return e=b(e),T(e),(await m(t,await f(t,"redeemReward"),{...e,requestId:e.requestId??crypto.randomUUID()},{request:"Invalid reward redemption",response:"Invalid reward receipt"})).redemption},async claimRewardProduct(e){return e=b(e),T(e),(await m(t,await f(t,"claimRewardProduct"),e,{request:"Invalid reward product claim",response:"Invalid reward product checkout"})).checkout},async createReferralCode(e){return e=b(e),T(e),(await m(t,await f(t,"createReferralCode"),{...e,requestId:e.requestId??crypto.randomUUID()},{request:"Invalid referral program",response:"Invalid referral code"})).referralCode},async redeemCoupon(e,n=crypto.randomUUID()){typeof e=="string"&&(e=e.trim().toUpperCase());let r=await m(t,await f(t,"redeemCoupon"),{code:e,requestId:n},{request:"Invalid coupon code",response:"Invalid Coupon receipt"});return{offer:r.offer,reason:r.reason}},async claimCoupon(e,n=crypto.randomUUID()){let r=await m(t,await f(t,"grantOffer"),{couponId:e,requestId:n},{request:"Invalid Coupon claim",response:"Invalid Coupon receipt"});return{offer:r.offer,reason:r.reason}},async listOffers(){return(await m(t,await f(t,"listOffers"),{},{response:"Invalid offers response"})).offers}}}function Ie(t){return{...pe(t),...fe(t),...me(t),...se(t),...ye(t)}}function he(t){return{async resolveContent(e){e=b(e),T(e);let n=await f(t,"resolveContent");return m(t,n,e)},async resolvePaywall(e){e=b(e),T(e);let n=await f(t,"resolvePaywall"),r=n.request.parse(e),o=await m(t,n,r);return j(r,o.paywall.check,o.scope),o},async resolveOffering(e){e=b(e),T(e);let n=await f(t,"resolveOffering"),r=n.request.parse(e),o=await m(t,n,r);return j(r,o.check,o.scope),o}}}var Y=t=>new TextEncoder().encode(JSON.stringify(t)).length,we=16384,Pe=5e3,Ce=6e4,Re=5;function Te(t){return t instanceof s&&t.status!==void 0&&t.status>=400&&t.status<500&&!t.retryable}function ge(t,e){let n=0,r,o=h=>{r={config:structuredClone(h),until:Date.now()+3e4}},a=[],d=null,y,g=0;function l(){if(!e())throw new s("NOT_IDENTIFIED","Call identify before using Features or events")}function O(){y||!a.length||!e()||(y=setTimeout(()=>{y=void 0,S().catch(()=>{}).finally(O)},Math.min(Pe*2**g,Ce)),typeof y=="object"&&"unref"in y&&y.unref())}function F(h){if(l(),r&&Date.now()<r.until&&!W(r.config,h.kind))return;q();let P=X.parse({events:[{...h,eventUuid:crypto.randomUUID(),timestamp:new Date().toISOString()}]}).events[0];if(Y({events:[P]})>we)throw new s("INVALID_REQUEST","Event exceeds the delivery size limit");if(a.length>=500)throw new s("EVENT_QUEUE_FULL","Flush pending events before tracking more");a.push(structuredClone(P)),O()}function p(h,P={},E={}){F({kind:"custom",name:h,properties:P,...E})}async function S(h=!1){if(l(),d)return d;let P=n,E=(async()=>{let i={inserted:0,duplicates:0,rejected:0,skipped:0,rejections:[]},c=a.length;for(;c&&P===n;){let u=[],A=Y({events:[]});for(let C of a.slice(0,Math.min(c,100))){let D=Y(C)+(u.length?1:0);if(u.length&&A+D>we)break;u.push(C),A+=D}let w;try{let C=await f(t,"trackEvents");if(w=await m(t,C,{events:u},void 0,{keepalive:h}),P!==n)throw new s("IDENTITY_CHANGED","Event identity changed during delivery");if(w.inserted+w.duplicates+w.rejected+w.skipped!==u.length||w.rejections.length!==w.rejected)throw new s("INVALID_RESPONSE","Incomplete event acknowledgement")}catch(C){throw P===n&&(g++,(Te(C)||g>=Re)&&(a.splice(0,u.length),g=0)),C}g=0,o(w.analyticsConfig),a.splice(0,u.length),c-=u.length,i.inserted+=w.inserted,i.duplicates+=w.duplicates,i.rejected+=w.rejected,i.skipped+=w.skipped,i.rejections.push(...w.rejections)}return i})();d=E;try{return await E}finally{d===E&&(d=null)}}let I;function q(){if(I||typeof document>"u")return;let h=()=>{document.visibilityState==="hidden"&&e()&&a.length&&S(!0).catch(()=>{})};document.addEventListener("visibilitychange",h),I=()=>document.removeEventListener("visibilitychange",h)}return{rememberConfiguration:o,track:p,observe:F,flush:S,reset(){n++,r=void 0,clearTimeout(y),y=void 0,a=[],g=0,d=null},detachVisibility(){I?.(),I=void 0}}}function ve(t){let e=t.merchandise;if(typeof t.merchandiseId=="string")return{internalId:t.merchandiseId};if(!(!e||typeof e!="object"||Array.isArray(e))){if(typeof e.internalId=="string")return{internalId:e.internalId};if(typeof e.externalId=="string")return{id:e.externalId};if(typeof e.id=="string")return{id:e.id}}}var qe=new Set([...$,"merchandiseId","merchandise"]);function ke(t){let e=ve(t);return{...Object.fromEntries(Object.entries(t).filter(([r])=>!qe.has(r))),...e?{merchandise:e}:{}}}function Ee(t,e,n,r,o){if(o&&r&&(o.scope.projectId!==r.projectId||o.scope.environment!==r.environment))throw new s("SCOPE_MISMATCH","Configuration belongs to another App/environment");let a=0,d=new Set;function y(){if(!e())throw new s("NOT_IDENTIFIED","Call identify before using Features or events")}async function g(l={}){o||y();let O=a,F=!1,p=async()=>{if(F||O!==a)throw new s("IDENTITY_CHANGED","Feature identity changed");let R=o?{scope:{projectId:o.scope.projectId,environment:o.scope.environment},payload:await o.features()}:await m(t,await f(t,"getFeatures"),{});if(O!==a)throw new s("IDENTITY_CHANGED","Feature identity changed");if(r&&(R.scope.projectId!==r.projectId||R.scope.environment!==r.environment))throw new s("INVALID_RESPONSE","Feature response scope changed");return n.rememberConfiguration(R.payload.analyticsConfig),R},S=await p(),I=!0,q,h=R=>{try{l.onError?.(R)}catch{}},P=(R,N)=>{try{let v=ve(N);n.observe({...R,...v?{merchandise:v}:{}})}catch(v){h(v)}},E=ae({assertUsable:o?.assertFeatures,scope:S.scope,attributes:l.attributes,onError:l.onError,load:async()=>I?(I=!1,S.payload):(await p()).payload,evaluateRemote:async R=>{if(O!==a)throw new s("IDENTITY_CHANGED","Feature identity changed");let N=await f(t,"evaluateFeatures"),v=await m(t,N,{...R,attributes:ke(R.attributes)});if(v.scope.projectId!==S.scope.projectId||v.scope.environment!==S.scope.environment)throw new s("INVALID_RESPONSE","Remote Feature response scope changed");return{generation:v.generation,evaluatedAt:v.evaluatedAt,expiresAt:v.expiresAt,features:v.features,...v.merchandiseContext?{merchandiseContext:v.merchandiseContext}:{}}},onExperimentViewed:(R,N,v,V)=>P({kind:"experiment_exposure",generation:V,experimentId:R.key,variationId:N.key},v),onFeatureUsage:(R,N,v,V)=>P({kind:"feature_usage",generation:V,feature:R,value:N.value??null,source:N.source,ruleId:N.ruleId,...N.experimentResult?{variationId:N.experimentResult.key}:{}},v)}),i=E.refresh;function c(){clearTimeout(q),!o&&(F||O!==a||!E.expiresAt||(q=setTimeout(()=>{u().catch(h)},Math.min(2147483647,Math.max(1e3,Date.parse(E.expiresAt)-Date.now()))),typeof q=="object"&&"unref"in q&&q.unref()))}async function u(){try{return await i()}finally{c()}}let A=()=>{F||u().catch(h)},w=E.subscribe(c),C=o?.subscribe(()=>{!F&&o.fresh&&u().catch(h)});function D(){F||(F=!0,clearTimeout(q),typeof window<"u"&&window.removeEventListener("focus",A),w(),C?.(),E.reset(),d.delete(D))}d.add(D);try{await E.init(),(l.attributes?.merchandise||l.attributes?.merchandiseId)&&await E.refreshRemote()}catch(R){throw D(),R}return c(),!o&&typeof window<"u"&&window.addEventListener("focus",A),Object.assign(E,{refresh:u,destroy:D})}return{features:g,reset(l){a++,l();for(let O of d)O()}}}function be(t,e){let n="source"in e?{funnelId:e.source.id,funnelVersionId:e.source.versionId}:"versionId"in e?{funnelId:e.funnelId,funnelVersionId:e.versionId}:e,r=K.object({funnelId:J.shape.id,funnelVersionId:J.shape.versionId.optional()}).safeParse(n);if(!r.success)throw new s("INVALID_REQUEST","A valid Funnel source is required");let o=Object.freeze(r.data);function a(d){if("customerId"in d)throw new s("INVALID_REQUEST","Customer identity cannot be overridden");if("funnelId"in d&&d.funnelId!==void 0&&d.funnelId!==o.funnelId||"funnelVersionId"in d&&d.funnelVersionId!==void 0&&d.funnelVersionId!==o.funnelVersionId)throw new s("SCOPE_MISMATCH","The original Funnel source cannot change");return{...d,...o}}return{async claimCoupon(d,y=crypto.randomUUID()){let g=await f(t,"grantOffer"),l=await m(t,g,a({couponId:d,requestId:y}));return{offer:l.offer,reason:l.reason}},async resolveOffering(d){d=b(d);let y=await f(t,"resolveOffering"),g=y.request.parse(a(d)),l=await m(t,y,g);return j(g,l.check,l.scope),l},async resolvePaywall(d){d=b(d);let y=await f(t,"resolvePaywall"),g=y.request.parse(a(d)),l=await m(t,y,g);return j(g,l.paywall.check,l.scope),l},async previewAttach(d){d=b(d);let y=await f(t,"previewAttach");return m(t,y,a(d))}}}function xt(t){return Ne(t)}function Ne(t){let e=ie(t),n=e.request,r;try{r=ue(t.push,e,t.scope??t.configuration?.scope)}catch(y){throw e.dispose(),y}let o=le(e,()=>{d.reset(a.reset),a.detachVisibility()},{beforeIdentify:r.identify,beforeReset:r.reset,afterChange:r.start,beforeDestroy:r.destroy}),a=ge(n,o.isIdentified),d=Ee(n,o.isIdentified,a,t.scope,t.configuration);return{session:e.session,...de(n,r),...Ie(n),...he(n),forFunnel(y){return o.assertActive(),be(n,y)},async features(y={}){return o.assertActive(),d.features(y)},track(y,g,l={}){return a.track(y,g,l)},flush(){return a.flush()},...o.methods}}function Mt(t){if(!B.test(t.customerToken))throw new s("INVALID_TOKEN","A customer credential is required");if(!t.scope)throw new s("INVALID_REQUEST","An explicit App and environment scope is required");let e=ce({...t,scope:t.scope,apiKey:t.customerToken});return{async start(n){let r=await e.start(n),o=M({...t,runToken:r.runToken,initialResponse:r});o.identify(t.customerToken);let a=await o.get();return{...r,...a,controller:o}}}}function Kt(t){if(!t.scope)throw new s("INVALID_CONFIGURATION","An explicit process App/environment scope is required");if(t.session!==void 0)throw new s("INVALID_CONFIGURATION","The merchant process adapter owns the session");let e=null,n,r=0,o=new Set,a=new Map,d=new Map;async function y(p){let S,I=new Promise((q,h)=>{S=setTimeout(()=>h(new s("TIMEOUT","Process bridge request timed out")),t.timeoutMs??35e3)});try{return await Promise.race([Promise.resolve().then(p),I])}finally{clearTimeout(S)}}function g(p){throw p instanceof s&&(p.status===401||p.reason==="CUSTOMER_BINDING_CONFLICT")&&(r++,n?.reset(),n=void 0,e=null,a.clear(),d.clear()),p}function l(p,S){if(S!==r)throw new s("IDENTITY_CHANGED","Process was detached during a request");let I=re.parse(p);if(I.scope.projectId!==t.scope.projectId||I.scope.environment!==t.scope.environment)throw new s("SCOPE_MISMATCH","Process response belongs to another App/environment");if(e&&(e.run.id!==I.run.id||e.run.source.versionId!==I.run.source.versionId||e.run.source.id!==I.run.source.id||e.run.runExpiresAt!==I.run.runExpiresAt||e.run.identity.startedAs!==I.run.identity.startedAs||e.run.identity.participantId!==I.run.identity.participantId||e.run.identity.binding&&I.run.identity.binding&&e.run.identity.binding.id!==I.run.identity.binding.id))throw new s("INVALID_RESPONSE","The process changed its Run or Customer binding");if(!e||I.run.revision>=e.run.revision){if(e?.run.identity.binding&&!I.run.identity.binding)throw new s("INVALID_RESPONSE","The process lost its Customer binding");e=I;for(let A of o)z(A,I.run);I.run.instruction?.type==="authentication_required"&&z(t.onAuthenticationRequired,I.run)}I.settlement?.accepted!==void 0&&d.set(I.settlement.requestId,I.settlement.accepted);let{identity:q,instruction:h,...P}=I.run,{contract:E,settlement:i,...c}=I,u=i&&(({accepted:A,...w})=>w)(i);return{...c,run:{...P,authenticated:q.binding!==null,instruction:h?.type==="authentication_required"?null:h},...u?{settlement:u}:{}}}let O=p=>(a.has(p)||a.set(p,e?.run.identity.binding?.id??null),a.get(p));async function F(p){let S=r,I=e?.run.identity.binding?.id??null,q=P=>{if(I!==(e?.run.identity.binding?.id??null))throw P;return g(P)};if(p.operation==="page_experiments"){if(!t.adapter.pageExperiments)throw new s("CAPABILITY_UNAVAILABLE","Process page experiments are unavailable",501);return y(()=>t.adapter.pageExperiments(p.release,p.usedReceiptIds)).catch(q)}let h;if(p.operation==="get"){let{operation:P,customerToken:E,...i}=p;h=await y(()=>t.adapter.get({...i,...i.settlementRequestId?{settlementBindingId:O(i.settlementRequestId)}:{}})).catch(q)}else if(p.operation==="review")h=await y(()=>t.adapter.review(p.receiptId)).catch(q);else{if(p.operation==="start")throw new s("INVALID_REQUEST","Use process.open for entry");{let{customerToken:P,...E}=p;h=await y(()=>t.adapter.command(E,O(E.requestId))).catch(q)}}return l(h,S)}return{get view(){return e?.run??null},get controller(){return n},async open(p){let S=r,I=await y(()=>t.adapter.open(p)).catch(g),q=l(I,S);if(!n){n=M({...t,runToken:I.runToken,initialResponse:q,process:{request:F,binding:O,restore(E){for(let[i,c]of Object.entries(E))a.set(i,c)}}});let h=n,P=h.submit;h.submit=async E=>{try{return await P(E)}catch(i){if(!(i instanceof s)||i.reason!=="IDENTITY_CONTEXT_CHANGED"||E.operation!=="submit"||E.input.type!=="screen"||a.get(E.requestId)!==null)throw i;await h.settle?.(E.requestId),await h.get();let c=h.view;if(d.get(E.requestId)!==!1||!c||c.id!==e?.run.id||c.nodeId!==E.nodeId||c.visit!==E.visit||!e?.run.identity.binding)throw i;return P({...E,requestId:crypto.randomUUID(),revision:c.revision})}}}await n.get();for(let h of n.pendingCommands??[])a.has(h.requestId)&&a.get(h.requestId)!==(e?.run.identity.binding?.id??null)&&await n.settle?.(h.requestId);return{run:e.run,controller:n}},async syncIdentity(){let p=r;l(await y(()=>t.adapter.syncIdentity()).catch(g),p),await n?.get();for(let S of n?.pendingCommands??[])a.has(S.requestId)&&a.get(S.requestId)!==(e?.run.identity.binding?.id??null)&&await n?.settle?.(S.requestId);return e.run},async detach(){r++,n?.reset(),n=void 0,e=null,a.clear(),d.clear(),await y(()=>t.adapter.detach())},forProcess(p){if(!e?.run.identity.binding)throw new s("UNAUTHENTICATED","Sign in before a commercial operation",401);return{runId:e.run.id,bindingId:e.run.identity.binding.id,receiptId:p}},subscribe(p){return o.add(p),()=>{o.delete(p)}},destroy(){r++,n?.reset(),n=void 0,e=null,a.clear(),d.clear(),o.clear()}}}export{xt as a,Ne as b,Mt as c,Kt as d};
1
+ import{a as T,b as se}from"./chunk-4XC34JBS.js";import{b as re,h as ae,j as ce}from"./chunk-KHM6IHPJ.js";import{a as oe,b as j}from"./chunk-FYQXSGRT.js";import{c as Z,e as ee,f as te,g as H,h as G,j as ne}from"./chunk-7MNJH5GB.js";import{F as M,b as J}from"./chunk-EUVLXS2V.js";import{a as b,b as f,c as m}from"./chunk-SP5AQION.js";import{b as W,j as X}from"./chunk-NAZU3EEJ.js";import{E as $}from"./chunk-R23IGK5U.js";import{b as ie}from"./chunk-ZIQENZDI.js";import{a as B}from"./chunk-VYFSRHXM.js";import{a as s}from"./chunk-X4W22IH6.js";import{h as Q}from"./chunk-R4FDIYMN.js";import{b as K}from"./chunk-VF6QMMEA.js";import{a as z}from"./chunk-DSPLGTQI.js";var U=t=>{if(!Number.isSafeInteger(t)||t<0||t>=Number.MAX_SAFE_INTEGER)throw new s("INVALID_STATE","Installation sequence exhausted");return t+1},Se=async t=>[...new Uint8Array(await crypto.subtle.digest("SHA-256",Uint8Array.from(t,e=>e.charCodeAt(0))))].map(e=>e.toString(16).padStart(2,"0")).join("");function _(t,e){return t.transaction(n=>{if(!Number.isSafeInteger(n.identitySeq)||n.identitySeq<0||!Number.isSafeInteger(n.addressSeq)||n.addressSeq<0||n.detachSeq!==null&&(!Number.isSafeInteger(n.detachSeq)||n.detachSeq<1||n.detachSeq>n.identitySeq))throw new s("INVALID_STATE","Installation journal is invalid");return e({...n})})}function ue(t,e,n){let r=null,o=0,a=0,d=0,y=Promise.resolve(),g=!1;if(t&&(!n||Q.parse(t.scope).projectId!==n.projectId||t.scope.environment!==n.environment))throw new s("SCOPE_MISMATCH","Push installation belongs to another scope");let l=()=>{if(g)throw new s("CLOSED","SDK client was destroyed");if(!t)throw new s("NOT_CONFIGURED","Configure this client's native Push host first");return t},O=i=>{if(i!==o)throw new s("IDENTITY_CHANGED","Identity changed during Push operation")};async function F(i){let c=l();if(!c.sha256&&!globalThis.crypto?.subtle)throw new s("NOT_CONFIGURED","Configure native SHA-256 for this Push host");let u=c.sha256?await c.sha256(Uint8Array.from(i,A=>A.charCodeAt(0))):await Se(i);if(!/^[a-f0-9]{64}$/.test(u))throw new s("INVALID_STATE","Push credential digest is invalid");return u}function p(i){let c=G.parse(i);if(c.installationId.toLowerCase()!==l().installationId.toLowerCase())throw new s("INVALID_RESPONSE","Push response belongs to another installation");return c}async function S(i,c){let u=l(),A={installationId:u.installationId,publicKey:u.publicKey,issuedAt:new Date().toISOString(),...c},w=await u.sign(ne(i,u.scope,A));return{...A,signature:w}}let I=(i,c,u)=>e.requestWithCredential?e.requestWithCredential(i,c,u):e.request(i,c);async function q(){let i=l(),c=o,u=r?await(e.session?.access()??r):null,A=_(i,v=>v),w;if(A.detachSeq!==null){let v=A.detachSeq,V=Z.parse(await S("detach",{sequence:v,platform:i.platform}));try{let k=await e.request("push/installations/detach",{...i.scope,...V},"POST",{installationDetach:!0});if(!k||typeof k!="object"||!("installation"in k))throw new s("INVALID_RESPONSE","Push detach acknowledgement is invalid");let x=p(k.installation);if(x.bound||x.identitySeq!==v)throw new s("INVALID_RESPONSE","Push detach acknowledgement does not match its intent")}catch(k){if(k instanceof s&&k.status===404)w=k;else if(!(k instanceof s)||k.status!==412)throw k}w||_(i,k=>({...k,detachSeq:k.detachSeq===v?null:k.detachSeq}))}if(O(c),!u){if(w)throw w;return null}let C=(await import("./operation-contracts-443N2P3A.js")).apiOperations.bindPushInstallation,D=C.request.parse(await S("bind",{sequence:d,platform:i.platform,credentialDigest:await F(u)}));O(c);let R=C.response.parse(await I(C.path,D,u));O(c);let N=p(R.installation);if(!N.bound||N.identitySeq!==d)throw new s("INVALID_RESPONSE","Push binding acknowledgement does not match its intent");return w&&A.detachSeq!==null&&d>A.detachSeq&&_(i,v=>({...v,detachSeq:v.detachSeq===A.detachSeq?null:v.detachSeq})),N}async function h(){l();let i=o,c=r?await(e.session?.access()??r):null;if(!c)throw new s("NOT_IDENTIFIED","Identify before reading this installation");let u=(await import("./operation-contracts-443N2P3A.js")).apiOperations.readPushInstallation,A=u.request.parse(await S("read",{credentialDigest:await F(c)}));O(i);let w=u.response.parse(await I(u.path,A,c));return O(i),p(w.installation)}function P(i=q){let c=y.catch(()=>{}).then(i);return y=c,c.catch(u=>{try{t?.onError?.(u instanceof Error?u:new Error("Push synchronization failed"))}catch{}}),c}async function E(i,c,u){let A=l(),w=c.identity,C=c.observation,D=r?await(e.session?.access()??r):null;if(O(w),C!==a)throw new s("INVALID_STATE","Push observation changed during recovery");if(!D)throw new s("NOT_IDENTIFIED","Identify before recovering a Push address");if(!i.connectionId||!i.kind||!i.token||!["granted","provisional"].includes(i.permission))throw new s("INVALID_REQUEST","Recovery needs a provider token and notification permission");return await P(async()=>{if(O(w),await q(),O(w),C!==a)throw new s("INVALID_STATE","Push observation changed during recovery");let R=_(A,x=>u?x:{...x,addressSeq:U(x.addressSeq)}),v=await S(u?"recovery_confirm":"recovery_request",{...i,sequence:R.addressSeq,credentialDigest:await F(D),...u?{challenge:u}:{}}),V=u?te.parse(v):ee.parse(v);if(O(w),C!==a)throw new s("INVALID_STATE","Push observation changed during recovery");let k=await I(`push/installations/recovery/${u?"confirm":"request"}`,V,D);if(O(w),C!==a||_(A,x=>x).addressSeq!==R.addressSeq)throw new s("INVALID_STATE","Push observation changed during recovery");if(u){let{apiOperations:x}=await import("./operation-contracts-443N2P3A.js");if(O(w),C!==a||_(A,Oe=>Oe).addressSeq!==R.addressSeq)throw new s("INVALID_STATE","Push observation changed during recovery");let Ae=x.updatePushAddress.response.parse(k),L=p(Ae.installation);if(!L.bound||L.identitySeq!==d||L.addressSeq!==R.addressSeq||L.connectionId!==i.connectionId||L.addressStatus!=="active")throw new s("INVALID_RESPONSE","Push recovery acknowledgement does not match its intent");return L}if(!k||typeof k!="object"||!("recovery"in k))throw new s("INVALID_RESPONSE","Push recovery acknowledgement is invalid");return H.parse(k.recovery)})}return{recoveryObserver(){l();let i={identity:o,observation:++a};return{async request(c){return H.parse(await E(c,i))},async confirm(c,u){return G.parse(await E(u,i,c))}}},identify(i){if(!t)return;d=_(t,u=>({...u,identitySeq:U(u.identitySeq)})).identitySeq,r=i,o++,a++},reset(){if(t)try{_(t,i=>{let c=U(i.identitySeq);return{...i,identitySeq:c,detachSeq:c}})}finally{r=null,o++,a++}},start(){t&&!g&&P()},destroy(){g=!0,r=null,o++,a++},async sync(){return await P()},read:h,async recover(){let i=l(),c=o,u=d;return a++,await P(async()=>{O(c);let A=await h();return O(c),d=_(i,C=>{if(C.identitySeq!==u)throw new s("IDENTITY_CHANGED","A newer installation intent exists");return{...C,identitySeq:U(Math.max(C.identitySeq,A.identitySeq)),addressSeq:Math.max(C.addressSeq,A.addressSeq)}}).identitySeq,await q()})},tokenObserver(){l();let i=++a,c=o;return async u=>{if(i!==a||c!==o)return null;let A=l(),w=r?await(e.session?.access()??r):null;if(!w)throw new s("NOT_IDENTIFIED","Identify before registering a Push token");if(await P(),O(c),i!==a)return null;let C=_(A,v=>({...v,addressSeq:U(v.addressSeq)})),D=(await import("./operation-contracts-443N2P3A.js")).apiOperations.updatePushAddress,R=D.request.parse(await S("address",{...u,sequence:C.addressSeq,credentialDigest:await F(w)}));if(O(c),i!==a)return null;let N=await I(D.path,R,w);return O(c),i!==a||_(A,v=>v).addressSeq!==C.addressSeq?null:p(D.response.parse(N).installation)}}}}function de(t,e){let n={async preference(r){let o=await f(t,"readMessagingPreference");return(await m(t,o,{channel:r})).preference},async setPreference(r){r=b(r);let o=await f(t,"setMessagingPreference");return(await m(t,o,r)).preference}};return{messaging:n,push:{sync:e.sync,read:e.read,recover:e.recover,tokenObserver:e.tokenObserver,recoveryObserver:e.recoveryObserver,async preference(){return n.preference("push")},async setPreference(r){return r=b(r),n.setPreference({...r,channel:"push"})}}}}function le(t,e,n={}){let r=!1;function o(){if(r)throw new s("CLOSED","SDK client was destroyed")}let a=new Set,d=g=>{for(let l of a)try{l(g)}catch{}},y=t.session.subscribeIdentity(()=>{d(!!t.session.peek()),n.afterChange?.()},()=>{e()});return{assertActive:o,isIdentified:()=>!r&&!!t.session.peek(),methods:{subscribeIdentity(g){return o(),a.add(g),()=>{a.delete(g)}},identify(g){o();let l=typeof g=="string"?g:g.accessToken;if(!B.test(l))throw new s("INVALID_TOKEN","Browser SDK requires a customer session");n.beforeIdentify?.(l),t.identify(g)},reset(){if(!r)try{n.beforeReset?.()}finally{t.reset()}},destroy(){if(!r){r=!0,y(),a.clear();try{n.beforeDestroy?.(),e()}finally{t.dispose()}}}}}}function pe(t){return{async checkEntitlement(e){e=b(e),T(e);let n=await f(t,"checkEntitlement"),r=n.request.parse(e),o=await m(t,n,r);return oe(r.requirement,o.check,void 0,o.scope),o},async readHoldings(e={}){e=b(e);let n=await f(t,"readHoldings"),r={...n,request:n.request.omit({customerId:!0})};return m(t,r,e)}}}function fe(t){return{async readLedger(e){e=b(e);let n=await f(t,"readLedger");return m(t,n,{query:e})},async readCreditStatement(e){e=b(e),T(e);let n=await f(t,"readCreditStatement");return m(t,n,e)},async quoteBalance(e){e=b(e),T(e);let n=await f(t,"quoteBalance");return m(t,n,{command:e})}}}function me(t){return{async setupPayment(e){e=b(e),T(e);let n=await f(t,"setupPayment");return m(t,n,e)},async readPaymentSetup(e){e=b(e),T(e);let n=await f(t,"readPaymentSetup");return m(t,n,e)},async readBillingInvoice(e){e=b(e),T(e);let n=await f(t,"readBillingInvoice");return m(t,n,e)},async readBillingControls(e={}){e=b(e),T(e);let n=await f(t,"readBillingControls");return m(t,n,e)},async prepareBillingAuthorization(e){e=b(e),T(e);let n=await f(t,"prepareBillingAuthorization");return m(t,n,e)},async confirmBillingAuthorization(e){e=b(e),T(e);let n=await f(t,"confirmBillingAuthorization");return m(t,n,e)},async setBillingCoupons(e){e=b(e),T(e);let n=await f(t,"setBillingCoupons");return m(t,n,e,{request:"Invalid billing coupon list",response:"Invalid billing coupon receipt"})},async revokeBillingAuthorization(e){e=b(e),T(e);let n=await f(t,"revokeBillingAuthorization");return m(t,n,e)},async listBillingInvoices(e={after:null,limit:25}){e=b(e),T(e);let n=await f(t,"listBillingInvoices");return m(t,n,e)},async confirmBillingAdjustment(e){e=b(e),T(e);let n=await f(t,"confirmBillingAdjustment");return m(t,n,e)}}}function ye(t){return{async redeemReward(e){return e=b(e),T(e),(await m(t,await f(t,"redeemReward"),{...e,requestId:e.requestId??crypto.randomUUID()},{request:"Invalid reward redemption",response:"Invalid reward receipt"})).redemption},async claimRewardProduct(e){return e=b(e),T(e),(await m(t,await f(t,"claimRewardProduct"),e,{request:"Invalid reward product claim",response:"Invalid reward product checkout"})).checkout},async createReferralCode(e){return e=b(e),T(e),(await m(t,await f(t,"createReferralCode"),{...e,requestId:e.requestId??crypto.randomUUID()},{request:"Invalid referral program",response:"Invalid referral code"})).referralCode},async redeemCoupon(e,n=crypto.randomUUID()){typeof e=="string"&&(e=e.trim().toUpperCase());let r=await m(t,await f(t,"redeemCoupon"),{code:e,requestId:n},{request:"Invalid coupon code",response:"Invalid Coupon receipt"});return{offer:r.offer,reason:r.reason}},async claimCoupon(e,n=crypto.randomUUID()){let r=await m(t,await f(t,"grantOffer"),{couponId:e,requestId:n},{request:"Invalid Coupon claim",response:"Invalid Coupon receipt"});return{offer:r.offer,reason:r.reason}},async listOffers(){return(await m(t,await f(t,"listOffers"),{},{response:"Invalid offers response"})).offers}}}function Ie(t){return{...pe(t),...fe(t),...me(t),...se(t),...ye(t)}}function he(t){return{async resolveContent(e){e=b(e),T(e);let n=await f(t,"resolveContent");return m(t,n,e)},async resolvePaywall(e){e=b(e),T(e);let n=await f(t,"resolvePaywall"),r=n.request.parse(e),o=await m(t,n,r);return j(r,o.paywall.check,o.scope),o},async resolveOffering(e){e=b(e),T(e);let n=await f(t,"resolveOffering"),r=n.request.parse(e),o=await m(t,n,r);return j(r,o.check,o.scope),o}}}var Y=t=>new TextEncoder().encode(JSON.stringify(t)).length,we=16384,Pe=5e3,Ce=6e4,Re=5;function Te(t){return t instanceof s&&t.status!==void 0&&t.status>=400&&t.status<500&&!t.retryable}function ge(t,e){let n=0,r,o=h=>{r={config:structuredClone(h),until:Date.now()+3e4}},a=[],d=null,y,g=0;function l(){if(!e())throw new s("NOT_IDENTIFIED","Call identify before using Features or events")}function O(){y||!a.length||!e()||(y=setTimeout(()=>{y=void 0,S().catch(()=>{}).finally(O)},Math.min(Pe*2**g,Ce)),typeof y=="object"&&"unref"in y&&y.unref())}function F(h){if(l(),r&&Date.now()<r.until&&!W(r.config,h.kind))return;q();let P=X.parse({events:[{...h,eventUuid:crypto.randomUUID(),timestamp:new Date().toISOString()}]}).events[0];if(Y({events:[P]})>we)throw new s("INVALID_REQUEST","Event exceeds the delivery size limit");if(a.length>=500)throw new s("EVENT_QUEUE_FULL","Flush pending events before tracking more");a.push(structuredClone(P)),O()}function p(h,P={},E={}){F({kind:"custom",name:h,properties:P,...E})}async function S(h=!1){if(l(),d)return d;let P=n,E=(async()=>{let i={inserted:0,duplicates:0,rejected:0,skipped:0,rejections:[]},c=a.length;for(;c&&P===n;){let u=[],A=Y({events:[]});for(let C of a.slice(0,Math.min(c,100))){let D=Y(C)+(u.length?1:0);if(u.length&&A+D>we)break;u.push(C),A+=D}let w;try{let C=await f(t,"trackEvents");if(w=await m(t,C,{events:u},void 0,{keepalive:h}),P!==n)throw new s("IDENTITY_CHANGED","Event identity changed during delivery");if(w.inserted+w.duplicates+w.rejected+w.skipped!==u.length||w.rejections.length!==w.rejected)throw new s("INVALID_RESPONSE","Incomplete event acknowledgement")}catch(C){throw P===n&&(g++,(Te(C)||g>=Re)&&(a.splice(0,u.length),g=0)),C}g=0,o(w.analyticsConfig),a.splice(0,u.length),c-=u.length,i.inserted+=w.inserted,i.duplicates+=w.duplicates,i.rejected+=w.rejected,i.skipped+=w.skipped,i.rejections.push(...w.rejections)}return i})();d=E;try{return await E}finally{d===E&&(d=null)}}let I;function q(){if(I||typeof document>"u")return;let h=()=>{document.visibilityState==="hidden"&&e()&&a.length&&S(!0).catch(()=>{})};document.addEventListener("visibilitychange",h),I=()=>document.removeEventListener("visibilitychange",h)}return{rememberConfiguration:o,track:p,observe:F,flush:S,reset(){n++,r=void 0,clearTimeout(y),y=void 0,a=[],g=0,d=null},detachVisibility(){I?.(),I=void 0}}}function ve(t){let e=t.merchandise;if(typeof t.merchandiseId=="string")return{internalId:t.merchandiseId};if(!(!e||typeof e!="object"||Array.isArray(e))){if(typeof e.internalId=="string")return{internalId:e.internalId};if(typeof e.externalId=="string")return{id:e.externalId};if(typeof e.id=="string")return{id:e.id}}}var qe=new Set([...$,"merchandiseId","merchandise"]);function ke(t){let e=ve(t);return{...Object.fromEntries(Object.entries(t).filter(([r])=>!qe.has(r))),...e?{merchandise:e}:{}}}function Ee(t,e,n,r,o){if(o&&r&&(o.scope.projectId!==r.projectId||o.scope.environment!==r.environment))throw new s("SCOPE_MISMATCH","Configuration belongs to another App/environment");let a=0,d=new Set;function y(){if(!e())throw new s("NOT_IDENTIFIED","Call identify before using Features or events")}async function g(l={}){o||y();let O=a,F=!1,p=async()=>{if(F||O!==a)throw new s("IDENTITY_CHANGED","Feature identity changed");let R=o?{scope:{projectId:o.scope.projectId,environment:o.scope.environment},payload:await o.features()}:await m(t,await f(t,"getFeatures"),{});if(O!==a)throw new s("IDENTITY_CHANGED","Feature identity changed");if(r&&(R.scope.projectId!==r.projectId||R.scope.environment!==r.environment))throw new s("INVALID_RESPONSE","Feature response scope changed");return n.rememberConfiguration(R.payload.analyticsConfig),R},S=await p(),I=!0,q,h=R=>{try{l.onError?.(R)}catch{}},P=(R,N)=>{try{let v=ve(N);n.observe({...R,...v?{merchandise:v}:{}})}catch(v){h(v)}},E=ae({assertUsable:o?.assertFeatures,scope:S.scope,attributes:l.attributes,onError:l.onError,load:async()=>I?(I=!1,S.payload):(await p()).payload,evaluateRemote:async R=>{if(O!==a)throw new s("IDENTITY_CHANGED","Feature identity changed");let N=await f(t,"evaluateFeatures"),v=await m(t,N,{...R,attributes:ke(R.attributes)});if(v.scope.projectId!==S.scope.projectId||v.scope.environment!==S.scope.environment)throw new s("INVALID_RESPONSE","Remote Feature response scope changed");return{generation:v.generation,evaluatedAt:v.evaluatedAt,expiresAt:v.expiresAt,features:v.features,...v.merchandiseContext?{merchandiseContext:v.merchandiseContext}:{}}},onExperimentViewed:(R,N,v,V)=>P({kind:"experiment_exposure",generation:V,experimentId:R.key,variationId:N.key},v),onFeatureUsage:(R,N,v,V)=>P({kind:"feature_usage",generation:V,feature:R,value:N.value??null,source:N.source,ruleId:N.ruleId,...N.experimentResult?{variationId:N.experimentResult.key}:{}},v)}),i=E.refresh;function c(){clearTimeout(q),!o&&(F||O!==a||!E.expiresAt||(q=setTimeout(()=>{u().catch(h)},Math.min(2147483647,Math.max(1e3,Date.parse(E.expiresAt)-Date.now()))),typeof q=="object"&&"unref"in q&&q.unref()))}async function u(){try{return await i()}finally{c()}}let A=()=>{F||u().catch(h)},w=E.subscribe(c),C=o?.subscribe(()=>{!F&&o.fresh&&u().catch(h)});function D(){F||(F=!0,clearTimeout(q),typeof window<"u"&&window.removeEventListener("focus",A),w(),C?.(),E.reset(),d.delete(D))}d.add(D);try{await E.init(),(l.attributes?.merchandise||l.attributes?.merchandiseId)&&await E.refreshRemote()}catch(R){throw D(),R}return c(),!o&&typeof window<"u"&&window.addEventListener("focus",A),Object.assign(E,{refresh:u,destroy:D})}return{features:g,reset(l){a++,l();for(let O of d)O()}}}function be(t,e){let n="source"in e?{funnelId:e.source.id,funnelVersionId:e.source.versionId}:"versionId"in e?{funnelId:e.funnelId,funnelVersionId:e.versionId}:e,r=K.object({funnelId:J.shape.id,funnelVersionId:J.shape.versionId.optional()}).safeParse(n);if(!r.success)throw new s("INVALID_REQUEST","A valid Funnel source is required");let o=Object.freeze(r.data);function a(d){if("customerId"in d)throw new s("INVALID_REQUEST","Customer identity cannot be overridden");if("funnelId"in d&&d.funnelId!==void 0&&d.funnelId!==o.funnelId||"funnelVersionId"in d&&d.funnelVersionId!==void 0&&d.funnelVersionId!==o.funnelVersionId)throw new s("SCOPE_MISMATCH","The original Funnel source cannot change");return{...d,...o}}return{async claimCoupon(d,y=crypto.randomUUID()){let g=await f(t,"grantOffer"),l=await m(t,g,a({couponId:d,requestId:y}));return{offer:l.offer,reason:l.reason}},async resolveOffering(d){d=b(d);let y=await f(t,"resolveOffering"),g=y.request.parse(a(d)),l=await m(t,y,g);return j(g,l.check,l.scope),l},async resolvePaywall(d){d=b(d);let y=await f(t,"resolvePaywall"),g=y.request.parse(a(d)),l=await m(t,y,g);return j(g,l.paywall.check,l.scope),l},async previewAttach(d){d=b(d);let y=await f(t,"previewAttach");return m(t,y,a(d))}}}function xt(t){return Ne(t)}function Ne(t){let e=ie(t),n=e.request,r;try{r=ue(t.push,e,t.scope??t.configuration?.scope)}catch(y){throw e.dispose(),y}let o=le(e,()=>{d.reset(a.reset),a.detachVisibility()},{beforeIdentify:r.identify,beforeReset:r.reset,afterChange:r.start,beforeDestroy:r.destroy}),a=ge(n,o.isIdentified),d=Ee(n,o.isIdentified,a,t.scope,t.configuration);return{session:e.session,...de(n,r),...Ie(n),...he(n),forFunnel(y){return o.assertActive(),be(n,y)},async features(y={}){return o.assertActive(),d.features(y)},track(y,g,l={}){return a.track(y,g,l)},flush(){return a.flush()},...o.methods}}function Mt(t){if(!B.test(t.customerToken))throw new s("INVALID_TOKEN","A customer credential is required");if(!t.scope)throw new s("INVALID_REQUEST","An explicit App and environment scope is required");let e=ce({...t,scope:t.scope,apiKey:t.customerToken});return{async start(n){let r=await e.start(n),o=M({...t,runToken:r.runToken,initialResponse:r});o.identify(t.customerToken);let a=await o.get();return{...r,...a,controller:o}}}}function Kt(t){if(!t.scope)throw new s("INVALID_CONFIGURATION","An explicit process App/environment scope is required");if(t.session!==void 0)throw new s("INVALID_CONFIGURATION","The merchant process adapter owns the session");let e=null,n,r=0,o=new Set,a=new Map,d=new Map;async function y(p){let S,I=new Promise((q,h)=>{S=setTimeout(()=>h(new s("TIMEOUT","Process bridge request timed out")),t.timeoutMs??35e3)});try{return await Promise.race([Promise.resolve().then(p),I])}finally{clearTimeout(S)}}function g(p){throw p instanceof s&&(p.status===401||p.reason==="CUSTOMER_BINDING_CONFLICT")&&(r++,n?.reset(),n=void 0,e=null,a.clear(),d.clear()),p}function l(p,S){if(S!==r)throw new s("IDENTITY_CHANGED","Process was detached during a request");let I=re.parse(p);if(I.scope.projectId!==t.scope.projectId||I.scope.environment!==t.scope.environment)throw new s("SCOPE_MISMATCH","Process response belongs to another App/environment");if(e&&(e.run.id!==I.run.id||e.run.source.versionId!==I.run.source.versionId||e.run.source.id!==I.run.source.id||e.run.runExpiresAt!==I.run.runExpiresAt||e.run.identity.startedAs!==I.run.identity.startedAs||e.run.identity.participantId!==I.run.identity.participantId||e.run.identity.binding&&I.run.identity.binding&&e.run.identity.binding.id!==I.run.identity.binding.id))throw new s("INVALID_RESPONSE","The process changed its Run or Customer binding");if(!e||I.run.revision>=e.run.revision){if(e?.run.identity.binding&&!I.run.identity.binding)throw new s("INVALID_RESPONSE","The process lost its Customer binding");e=I;for(let A of o)z(A,I.run);I.run.instruction?.type==="authentication_required"&&z(t.onAuthenticationRequired,I.run)}I.settlement?.accepted!==void 0&&d.set(I.settlement.requestId,I.settlement.accepted);let{identity:q,instruction:h,...P}=I.run,{contract:E,settlement:i,...c}=I,u=i&&(({accepted:A,...w})=>w)(i);return{...c,run:{...P,authenticated:q.binding!==null,instruction:h?.type==="authentication_required"?null:h},...u?{settlement:u}:{}}}let O=p=>(a.has(p)||a.set(p,e?.run.identity.binding?.id??null),a.get(p));async function F(p){let S=r,I=e?.run.identity.binding?.id??null,q=P=>{if(I!==(e?.run.identity.binding?.id??null))throw P;return g(P)};if(p.operation==="page_experiments"){if(!t.adapter.pageExperiments)throw new s("CAPABILITY_UNAVAILABLE","Process page experiments are unavailable",501);return y(()=>t.adapter.pageExperiments(p.release,p.usedReceiptIds)).catch(q)}let h;if(p.operation==="get"){let{operation:P,customerToken:E,...i}=p;h=await y(()=>t.adapter.get({...i,...i.settlementRequestId?{settlementBindingId:O(i.settlementRequestId)}:{}})).catch(q)}else if(p.operation==="review")h=await y(()=>t.adapter.review(p.receiptId)).catch(q);else{if(p.operation==="start")throw new s("INVALID_REQUEST","Use process.open for entry");{let{customerToken:P,...E}=p;h=await y(()=>t.adapter.command(E,O(E.requestId))).catch(q)}}return l(h,S)}return{get view(){return e?.run??null},get controller(){return n},async open(p){let S=r,I=await y(()=>t.adapter.open(p)).catch(g),q=l(I,S);if(!n){n=M({...t,runToken:I.runToken,initialResponse:q,process:{request:F,binding:O,restore(E){for(let[i,c]of Object.entries(E))a.set(i,c)}}});let h=n,P=h.submit;h.submit=async E=>{try{return await P(E)}catch(i){if(!(i instanceof s)||i.reason!=="IDENTITY_CONTEXT_CHANGED"||E.operation!=="submit"||E.input.type!=="screen"||a.get(E.requestId)!==null)throw i;await h.settle?.(E.requestId),await h.get();let c=h.view;if(d.get(E.requestId)!==!1||!c||c.id!==e?.run.id||c.nodeId!==E.nodeId||c.visit!==E.visit||!e?.run.identity.binding)throw i;return P({...E,requestId:crypto.randomUUID(),revision:c.revision})}}}await n.get();for(let h of n.pendingCommands??[])a.has(h.requestId)&&a.get(h.requestId)!==(e?.run.identity.binding?.id??null)&&await n.settle?.(h.requestId);return{run:e.run,controller:n}},async syncIdentity(){let p=r;l(await y(()=>t.adapter.syncIdentity()).catch(g),p),await n?.get();for(let S of n?.pendingCommands??[])a.has(S.requestId)&&a.get(S.requestId)!==(e?.run.identity.binding?.id??null)&&await n?.settle?.(S.requestId);return e.run},async detach(){r++,n?.reset(),n=void 0,e=null,a.clear(),d.clear(),await y(()=>t.adapter.detach())},forProcess(p){if(!e?.run.identity.binding)throw new s("UNAUTHENTICATED","Sign in before a commercial operation",401);return{runId:e.run.id,bindingId:e.run.identity.binding.id,receiptId:p}},subscribe(p){return o.add(p),()=>{o.delete(p)}},destroy(){r++,n?.reset(),n=void 0,e=null,a.clear(),d.clear(),o.clear()}}}export{xt as a,Ne as b,Mt as c,Kt as d};
@@ -1 +1 @@
1
- import{a as kn,b as rn,c as on,d as _e,e as Fn,f as We,h as Dn}from"./chunk-UWYL2QCF.js";import{c as Cn,d as Pn,e as Rn,f as Ae,g as Be,h as En,i as je,k as qn}from"./chunk-RBMOWJGE.js";import{$ as Qe}from"./chunk-ITVSLSRM.js";import{a as ze,e as gn,f as vn,g as hn,h as In,i as bn}from"./chunk-B3KFE57L.js";import{b as wn}from"./chunk-ACFQLHJR.js";import{R as fn,qa as yn}from"./chunk-WRUW2UIJ.js";import{a as P}from"./chunk-HJLGRW4A.js";import{b as Sn,e as On}from"./chunk-SLUA7ABW.js";import{d as Tn}from"./chunk-ZYTT7ZAB.js";import{a as le}from"./chunk-DSPLGTQI.js";import{b as mn}from"./chunk-6BTJNSQQ.js";var Te=new WeakMap;function Bn(n){let g=n.view,w=g?.paywall?.resolution;if(!g||!["running","waiting"].includes(g.status)||g.stopped||!w||"document"in w||!n.resolvePaywall||n.identitySignal?.aborted)return;let e=JSON.stringify(w);if(Te.get(n)?.key===e)return;let p=JSON.parse(e),D=n.identitySignal,a=Promise.resolve().then(async()=>{D?.throwIfAborted();let s=await n.resolvePaywall(p);return D?.throwIfAborted(),s}),S={key:e,content:a};return Te.set(n,S),a.catch(()=>{}),()=>{Te.get(n)===S&&Te.delete(n)}}function Nn(n,g){let w=Te.get(n);return Te.delete(n),w?.key===JSON.stringify(g)?w.content:n.resolvePaywall(g)}async function An(n){let{session:g,load:w}=Qn(n);try{return await w(),g}catch(e){throw g.destroy(),e}}function Qn(n){let g=n.view;if(!g?.paywall)throw new P("INVALID_REQUEST","The current node is not a Paywall");let w=g.paywall.receiptId,e=g.nodeId,p=g.visit,D=g.paywall.resolution,a=g.paywall,S="document"in D?{document:D.document,offering:D.offering,capabilities:D.capabilities}:null;function s(){let i=a.resolution;return"document"in i?i:S&&{...i,document:S.document,offering:S.offering,capabilities:gn(i.capabilities,S.capabilities)}}function v(i){if(!vn(i,D))throw new P("INVALID_RESPONSE","The pinned Paywall binding changed")}let u=!1,q=new Set,A=null;function V(){let i=s();if(i&&!u)for(let l of q)le(l,structuredClone(i))}async function k(){J();let i=s();if(i)return structuredClone(i);if(!A){let l=(async()=>{if("document"in a.resolution||!n.resolvePaywall)throw new P("INVALID_RESPONSE","Public Paywall reader is unavailable");let c=await Nn(n,a.resolution);return J(),v(c),S={document:c.document,offering:c.offering,capabilities:c.capabilities},V(),s()})();A=l;let o=()=>{A===l&&(A=null)};l.then(o,o)}return A.then(l=>structuredClone(l))}let d=new AbortController,F=(n.pendingCommands??(n.pendingCommand?[n.pendingCommand]:[])).find(i=>i.operation==="submit"&&i.nodeId===e&&i.visit===p&&i.input.type==="paywall_quote")?.requestId??g.paywall.purchaseRequestId,R=0,M=null,C=new Set,H=null,h=new Map;function _(i){if(i.purchase&&i.purchase.receiptId!==w)throw new P("INVALID_RESPONSE","Purchase receipt changed");let l=i.run.paywall;return i.purchase??(l?.receiptId===w?l:null)}function J(){if(u)throw new P("IDENTITY_CHANGED","Paywall presentation has closed")}function z(i,l,o){if(J(),l!==R||o!==void 0&&a.quote?.operationId!==o)return!1;let c=a.selectionGeneration??0,y=i.run.paywall;if(y?.receiptId===w){if((y.selectionGeneration??0)<(a.selectionGeneration??0))return!1;v(y.resolution)}let I=_(i),B=y?.receiptId===w&&(y.selectionGeneration??0)>c,G=B?I?.quote??null:I?.quote??a.quote,b=I?.operation??(G?.operationId===a.quote?.operationId?a.operation:null);return G&&b&&hn(b,{operationId:G.operationId},"Purchase operation changed"),(B||G?.operationId!==a.quote?.operationId)&&(R++,y?.receiptId===w&&(F=y.purchaseRequestId)),y?.canReselect===!0&&y.purchaseRequestId===H&&!(n.pendingCommands??[n.pendingCommand]).some($=>$?.requestId===H)&&(H=null),a={...a,...y?.receiptId===w?y:{},quote:G,operation:bn(a.operation,b,!0)},V(),!0}function L(i,l,o){return new Promise((c,y)=>{let I=!1,B=()=>{clearTimeout(Re),d.signal.removeEventListener("abort",$)},G=Ee=>{I||(I=!0,B(),c(Ee))},b=Ee=>{I||(I=!0,B(),y(Ee))},$=()=>b(new P("IDENTITY_CHANGED","Paywall presentation has closed")),Re=setTimeout(()=>b(new P("COMMAND_PENDING","The purchase command is still pending; retry the original request",202,o)),Math.max(0,l-Date.now()));d.signal.addEventListener("abort",$,{once:!0}),d.signal.aborted&&$(),i.then(G,b)})}function de(i){return new Promise(l=>{let o=()=>{clearTimeout(c),d.signal.removeEventListener("abort",o),l()},c=setTimeout(o,i);d.signal.addEventListener("abort",o,{once:!0}),d.signal.aborted&&o()})}function Y(i,l){J();let o=h.get(i)??n.pendingCommands?.find(I=>I.requestId===i)??n.pendingCommand;if(o?.operation==="submit"&&o.requestId===i&&o.nodeId===e&&o.visit===p){l.type==="paywall_quote"&&o.input.type==="paywall_quote"&&o.input.predecessor&&!l.predecessor&&(l={...l,predecessor:o.input.predecessor});let I=Qe.parse(o),B=Qe.parse({...o,input:l});if(I.operation!=="submit"||B.operation!=="submit"||JSON.stringify(I.input)!==JSON.stringify(B.input))throw new P("CONFLICT","A purchase request cannot change its input");return h.set(i,I),I}let c=n.view;if(!c||c.nodeId!==e||c.visit!==p||c.paywall?.receiptId!==w)throw new P("PRECONDITION_FAILED","The Paywall visit has changed");let y=Qe.parse({operation:"submit",requestId:i,nodeId:e,visit:p,revision:c.revision,input:structuredClone(l)});if(y.operation!=="submit")throw new P("INVALID_REQUEST","A purchase submission is required");return h.set(i,y),y}async function ce(i,l){J();let{requestId:o,input:c}=i,y=Date.now()+3e4;C.add(o);try{let I=await L(n.submit(i),y,o);for(;I.run.pendingRequest?.requestId===o&&Date.now()<y&&!u&&(await de(Math.min(1e3,y-Date.now())),!(u||Date.now()>=y));)I=await L(n.resume(o),y,o);if(u)throw new P("IDENTITY_CHANGED","Paywall presentation has closed");if(I.run.pendingRequest?.requestId===o)throw new P("COMMAND_PENDING","The purchase command is still pending; retry the original request",202,o);if(!z(I,l,c.type==="paywall_confirm"||c.type==="paywall_cancel"?c.operationId:void 0))throw new P("PRECONDITION_FAILED","The purchase selection has changed");H===o&&(H=null)}catch(I){if(H=o,c.type==="paywall_quote"&&n.settle&&!u&&I instanceof P&&I.status!==void 0&&![401,425].includes(I.status)&&!I.retryable&&I.recovery!=="recover_operation")try{if((await L(n.settle(o),y,o)).settlement?.state==="settled"){let G=await L(n.get(),y,o);z(G,l)&&G.run.paywall?.purchaseRequestId===o&&a.canReselect===!0&&h.delete(o)}}catch{}throw I instanceof P&&I.code==="COMMAND_PENDING"&&I.status===void 0&&h.delete(o),I}finally{C.delete(o)}}async function re(i){if(!a.quote)throw new P("INVALID_REQUEST","A quoted purchase is required");let l=i==="confirm"?"paywall_confirm":"paywall_cancel",o=[...h.values(),...n.pendingCommands??(n.pendingCommand?[n.pendingCommand]:[])].find(y=>y.operation==="submit"&&y.input.type===l&&"operationId"in y.input&&y.input.operationId===a.quote.operationId),c=o?.operation==="submit"&&o.input.type===l&&"operationId"in o.input&&o.input.operationId===a.quote.operationId?o.requestId:crypto.randomUUID();if(await ce(Y(c,{type:i==="confirm"?"paywall_confirm":"paywall_cancel",operationId:a.quote.operationId}),R),!a.operation)throw new P("INVALID_RESPONSE","The accepted purchase result is missing");return structuredClone(a.operation)}let T={get view(){return structuredClone(s())},get quote(){return a.quote?structuredClone(a.quote):null},get operation(){return a.operation?structuredClone(a.operation):null},get webViewUrl(){return n.webViewUrl},get canReselect(){return a.canReselect===!0&&H===null},get recovery(){let i=n.pendingCommands??(n.pendingCommand?[n.pendingCommand]:[]),l=n.pendingPurchase;if(l&&(l.receiptId!==w||l.operationId!==a.quote?.operationId))return{type:"recover",operationId:l.operationId,requestId:i[0]?.requestId??null};let o=ze({quote:a.quote,operation:a.operation,requestId:i[0]?.requestId??H??F,pending:C.size>0||i.length>0||H!==null,destroyed:u,canReselect:a.canReselect});return o.type==="recover"&&o.requestId===null&&!u&&n.hasDurableJournal===!0&&!a.quote&&!a.operation&&(a.selectionGeneration??0)===0&&!l&&!i.length&&!C.size&&!F?{type:"native",operationId:null}:o},get pendingCancellation(){return!u&&(n.pendingCommands??(n.pendingCommand?[n.pendingCommand]:[])).some(i=>i.operation==="submit"&&i.nodeId===e&&i.visit===p&&i.input.type==="paywall_cancel"&&i.input.operationId===a.quote?.operationId)},subscribe(i){return u?()=>{}:(q.add(i),()=>q.delete(i))},async refresh(){J();let i=R,l=await n.get();if(z(l,i),l.run.paywall?.receiptId!==w)throw new P("PRECONDITION_FAILED","Paywall presentation has changed");return k()},preview(i){let l=s();if(!l)return Promise.reject(new P("PRECONDITION_FAILED","Load the Paywall presentation first"));if(F&&F!==i.requestId&&(M||a.canReselect!==!0))return Promise.reject(new P("COMMAND_PENDING","Retry the original purchase before starting another"));let o=l.document.buttons[i.actionId],c=o?.type==="checkout"?wn(o.product,i.selection,l.capabilities):null;if(!c)return Promise.reject(new P("PRODUCT_UNAVAILABLE","Choose an available Product in this purchase area"));let y=yn(l.document.screen,c,i.selection,l.capabilities),I=F!==i.requestId&&(a.selectionGeneration??0)>0?{operationId:a.quote?.operationId??null,generation:a.selectionGeneration??0}:void 0;if(I&&a.canReselect!==!0)return Promise.reject(new P("COMMAND_PENDING","Original purchase requires authoritative termination"));let B;try{B=Y(i.requestId,{type:"paywall_quote",actionId:i.actionId,productVersionId:c,...Object.keys(y).length?{featureQuantities:y}:{},...I?{predecessor:I}:{},...i.offerId?{offerId:i.offerId}:{},...i.nativeOffer?{nativeOffer:i.nativeOffer}:{}})}catch($){return Promise.reject($)}if(F===i.requestId&&M)return M;F!==i.requestId&&R++;let G=R;F=i.requestId;let b=(async()=>{if(await ce(B,G),!a.quote)throw new P("INVALID_RESPONSE","The accepted quote is missing");return In(a.quote,{productVersionId:c,featureQuantities:y},"The selected purchase changed"),structuredClone(a.quote)})();return M=b,b.then(()=>{M===b&&(M=null)},$=>{M===b&&(M=null),F===i.requestId&&n.pendingCommand?.requestId!==i.requestId&&$ instanceof P&&$.status!==void 0&&$.status<500&&![401,425].includes($.status)&&(F=null)}),b},confirm:()=>re("confirm"),cancel:()=>re("cancel"),async read(){if(J(),!a.quote)throw new P("INVALID_REQUEST","A quoted purchase is required");let i=a.quote.operationId,l=R,o=n.pendingCommands?.find(G=>G.operation==="submit"&&(G.input.type==="paywall_confirm"||G.input.type==="paywall_cancel")&&G.input.operationId===i)??n.pendingCommand;o?.operation==="submit"&&(o.input.type==="paywall_confirm"||o.input.type==="paywall_cancel")&&o.input.operationId===i&&await n.settle?.(o.requestId);let c=await n.get(void 0,{receiptId:w,operationId:i});J();let y=_(c);if(y?.quote&&y.quote.operationId!==i||y?.operation&&y.operation.operationId!==i)throw new P("INVALID_RESPONSE","Purchase operation changed");let I=z(c,l,i),B=I?a.operation:y?.operation;if(!B)throw new P("INVALID_RESPONSE","The current purchase result is missing");return I&&C.size===0&&!(n.pendingCommands?.length??(n.pendingCommand?1:0))&&(H=null),structuredClone(B)},destroy(){u=!0,E(),q.clear(),d.abort(),h.clear()}},E=n.subscribe(i=>{u||i.nodeId!==e||i.visit!==p||i.paywall?.receiptId!==w||(i.paywall.selectionGeneration??0)<(a.selectionGeneration??0)||(v(i.paywall.resolution),a={...a,resolution:i.paywall.resolution},V())});return{session:T,load:k}}function _n(n){let g=new Set,w=new Set,e=null;async function p(s,v){let u=!1;for(;!n.stopped&&n.key===s&&n.client.pendingCommand?.requestId===v;){if(!n.client.settle)throw new P("COMMAND_PENDING","The original display acknowledgement is still pending");await n.client.settle(v),u=!0,n.client.pendingCommand?.requestId===v&&await new Promise(q=>setTimeout(q,1500))}n.stopped||n.key!==s||(u&&await n.client.get(),!(n.stopped||n.key!==s)&&g.add(s))}function D(s,v){e=v;let u=()=>{e===v&&(e=null),w.delete(s)};return v.then(u,q=>{u(),n.busy||n.fail(q)}),v}function a(s){if(n.reviewing||g.has(s)||w.has(s)||n.stopped)return;w.add(s);let v=async()=>{if(n.reviewing||n.stopped||n.key!==s||g.has(s)){w.delete(s);return}if(n.busy||n.client.pendingCommand){setTimeout(()=>{v()},250);return}let u=(async()=>{if(n.staleRead){if(await n.staleRead,n.stopped||n.key!==s)return;if(n.client.pendingCommand){setTimeout(()=>{v()},250);return}}let q=n.client.view,A=n.expected(),V=A.requestId;try{await n.client.submit({operation:"shown",...A})}catch(k){if(!(k instanceof P)||k.code!=="CONFLICT"||k.status!==409||n.client.pendingCommand)throw k;await n.client.get();let d=n.client.view;if(n.stopped||n.reviewing||n.key!==s||!d||!q||d.id!==q.id||d.source.versionId!==q.source.versionId||d.nodeId!==A.nodeId||d.visit!==A.visit||d.revision<=A.revision||d.stopped||!d.screen&&(!d.paywall||d.paywall.receiptId!==q.paywall?.receiptId)||!["running","waiting"].includes(d.status)||n.client.pendingCommand)throw k;let O=n.expected();V=O.requestId,await n.client.submit({operation:"shown",...O})}await p(s,V)})();D(s,u)};v()}function S(){if(e)return e;let s=n.client.pendingCommand;if(s?.operation!=="shown")return null;let v=n.key;return w.add(v),D(v,(async()=>{await n.client.retry(),await p(v,s.requestId)})())}return{report:a,settled:S,get inFlight(){return e}}}function Ln(n){let g={},w=new Map;async function e(p){let D=n.client.view,a=D?.screen,S=a?.customerData.nodes[p.nodeId];if(n.stopped||n.busy||!D||!a||!S)return;if(!["refresh","next","previous","filter","sources_next","sources_previous"].includes(p.action)){let k=n.document,d=k?fn(k,p.nodeId):null,O=d?.type==="customer_data"?d.data.outputs?.[p.action]:void 0;O&&a.outputs.includes(O)?await n.perform(()=>n.client.submit({operation:"submit",...n.expected(),input:{type:"screen",output:O,answers:n.answers,selection:p.value?{[p.nodeId]:p.value}:{}}})):await n.onIntent?.(p,D);return}let v=p.action.startsWith("sources_")?S.resources.find(k=>k.key===p.value):null;if(p.action.startsWith("sources_")&&!v)throw new P("INVALID_REQUEST","Choose a current resource");let u=`${D.visit}:${p.nodeId}:${v?.key??""}`,q=w.get(u)??[null],V=g[p.nodeId]??{page:1,after:null,filter:"all",...v?{resourceKey:v.key}:{}};if(p.action==="filter"){let k=p.value;if(!k||!(S.source==="offer_history"?["all","issued","reserved","redeemed","expired","revoked"]:["all","purchase","refund","source","usage","debt","settlement"]).includes(k))throw new P("INVALID_REQUEST","Unknown data filter");V={page:1,after:null,filter:k},q.splice(0,q.length,null)}else if(p.action==="next"||p.action==="sources_next"){let k=v?.sources.at(-1),d=v?k?{kind:"ledger",cursor:{at:k.detail[0],id:k.id,type:"source"}}:null:a.dataCursors[p.nodeId];if(!d||!v&&!S.hasNext)return;q[V.page]=d,V={...V,page:V.page+1,after:d}}else if(p.action==="previous"||p.action==="sources_previous"){if(V.page<=1)return;V={...V,page:V.page-1,after:q[V.page-2]??null}}w.set(u,q),g={...g,[p.nodeId]:V},await n.perform(()=>n.client.get({nodeId:D.nodeId,visit:D.visit,revision:D.revision,components:g}))}return{get queries(){return g},intent:e,reset(){g={},w.clear()}}}function Vn(n){let{doc:g,holder:w,reviewHolder:e,mountScreenPreview:p}=n,D=!1,a,S=0,s=null,v="",u,q=new Map,A=d=>d?`${d.id}:${d.nodeId}:${d.visit}:${d.revision}:${d.paywall?.quote?.operationId??""}`:"";async function V(d){if(n.stopped||!n.client.review||D&&d===a&&u?.active)return;let O=!D||d!==a;D||(v=A(n.client.view),q.set(v,structuredClone(n.answers))),D=!0,a=d,w.hidden=!0,n.suspend(!0),e.hidden=!1;let F=++S;O&&(u?.finish("dismissed"),s?.destroy(),s=null,e.replaceChildren(),u=Be(e,n.loadingOptions,"funnel",()=>{k()}));let R=O?u:void 0;try{if(R?.start(!1,n.client.view?.locale),F!==S||n.stopped)return;let M=n.client.review(d),C=await(R?.wait(M,Ae)??M);if(n.stopped||F!==S||!D)return;if(!C.review)throw new P("INVALID_RESPONSE","Historical projection is missing");s?.destroy(),s=null,R||e.replaceChildren();let H=g.createElement("div"),h=R?je(H,e):()=>{};e.append(H);let _=C.run.locale.startsWith("zh"),J=n.chrome;H.style.cssText=J.history;let z=g.createElement("p");z.textContent=_?"\u53EA\u8BFB\u56DE\u770B":"Read-only history",z.style.cssText=J.historyTitle,H.append(z);let L=g.createElement("p");L.style.cssText=J.historyNote,L.textContent=C.review.pages.length?_?"\u9009\u62E9\u4E00\u9875\u67E5\u770B\u5F53\u65F6\u7684\u5185\u5BB9\uFF0C\u56DE\u770B\u4E0D\u4F1A\u6539\u52A8\u4EFB\u4F55\u4FE1\u606F\u3002":"Choose a page to see it as it was. Nothing here can be changed.":_?"\u8FD8\u6CA1\u6709\u53EF\u56DE\u770B\u7684\u9875\u9762\u3002":"There are no earlier pages yet.",H.append(L);let de=C.review.page?.receiptId,Y=g.createElement("div");Y.style.cssText=J.historyPages;for(let[T,E]of C.review.pages.entries()){let i=g.createElement("button");i.type="button",i.textContent=_?`\u7B2C ${T+1} \u9875`:`Page ${T+1}`;let l=de!==void 0&&E.receiptId===de;i.style.cssText=l?J.primary:J.secondary,l&&i.setAttribute("aria-current","page"),_e(i,()=>n.chrome.focus),i.onclick=()=>{V(E.receiptId)},Y.append(i)}if(Y.childElementCount&&H.append(Y),C.review.page){let T=C.review.page,E=g.createElement("div");E.inert=!0,E.style.cssText=J.historyPage,H.append(E),s=p(E,{mode:"live",rendererUrl:n.client.webViewUrl,title:T.document.name,onAction:()=>{},onAnswers:()=>{},onCustomerDataIntent:()=>{},onRendered:()=>{F===S&&!n.stopped&&R?.present(h)},onError:l=>{if(F!==S||n.stopped)return;let o=new Error(l);R?.finish("error",o),s?.destroy(),s=null,H.remove(),n.fail(o)},onEscape:()=>{k()}});let i=s;if(i.update(T.document,C.run.locale,{serverInput:{bindings:T.inputs,answers:T.answers,values:T.values}}),await i.ready,n.stopped||F!==S||!D)return}let ce=_?{issued:"\u5DF2\u9886\u53D6",reserved:"\u5DF2\u9884\u7559",redeemed:"\u5DF2\u4F7F\u7528",expired:"\u5DF2\u8FC7\u671F",revoked:"\u5DF2\u64A4\u9500",unknown:"\u72B6\u6001\u5F85\u786E\u8BA4"}:{issued:"Issued",reserved:"Reserved",redeemed:"Used",expired:"Expired",revoked:"Revoked",unknown:"Status unconfirmed"},re=g.createElement("div");re.style.cssText=J.historyRecords;for(let T of[...C.review.coupons.map((E,i)=>`${_?"\u4F18\u60E0\u5238":"Coupon"} ${i+1}: ${ce[E.status]}`),...C.review.purchases.map((E,i)=>`${_?"\u8D2D\u4E70":"Purchase"} ${i+1}: ${Dn(E.status,_)}`)]){let E=g.createElement("p");E.textContent=T,E.style.margin="0",re.append(E)}re.childElementCount&&H.append(re),C.review.page||R?.present(h),n.client.view&&await n.enqueue(n.client.view)}catch(M){if(F!==S||n.stopped)return;R?.finish("error",M),s?.destroy(),s=null,e.replaceChildren(),n.fail(M)}}async function k(){if(!D||n.stopped||!n.client.review)return;let d=++S;u?.finish("dismissed");try{if(await n.client.review(),n.stopped||d!==S)return;D=!1,S++,u?.finish("dismissed"),s?.destroy(),s=null,e.replaceChildren(),e.hidden=!0,w.hidden=!1;let O=n.client.view;A(O)!==v?(q.set(v,structuredClone(n.answers)),n.resetScreen()):(q.delete(v),n.suspend(!1)),O&&await n.enqueue(O)}catch(O){if(d!==S||n.stopped)return;s?.destroy(),s=null,e.replaceChildren(),n.fail(O)}}return{get active(){return D},get receipt(){return a},open:V,exit:k,get drafts(){return new Map([...q].map(([d,O])=>[d,structuredClone(O)]))},stop(){D=!1,S++,u?.finish("dismissed"),s?.destroy(),s=null,e.replaceChildren(),e.hidden=!0,w.hidden=!1}}}function Mn(n){if(!n.client.pageExperiments)throw new Error("The Run controller does not support page experiments");let g=n.client.pageExperiments.bind(n.client),w=!1,e=!1,p=0,D=!1,a=!1,S="",s=()=>{let h=n.client.view;return JSON.stringify([h?.id,h?.source.versionId,h?.visit,h?.revision,h?.status,h?.stopped])},v=new Map,u=new Set,q={},A=new Map,V=Sn(n.appManifestRelease),k=()=>{for(let h of v.values())h.effect.revert();v.clear()},d=()=>{k();for(let h of A.values())h();A.clear()};function O(h){if(w||u.has(h))return;u.add(h);let _=p;g(n.appManifestRelease,[h]).catch(J=>{u.delete(h),!w&&_===p&&le(n.onError,J)})}async function F(){if(w)return;S=s();let h=n.client.view;if(!h||h.stopped||!["running","waiting"].includes(h.status)){p++,d();return}if(document.visibilityState==="hidden")return;if(D){a=!0;return}D=!0;let _=++p,J=`${h.id}:${h.visit}:${h.revision}`,z=location.href;try{let[L,{applyVisualVariation:de}]=await Promise.all([g(n.appManifestRelease),import("./visual-dom-32PB6MMP.js")]),Y=n.client.view;if(w||_!==p||!Y||Y.stopped||!["running","waiting"].includes(Y.status)||`${Y.id}:${Y.visit}:${Y.revision}`!==J||location.href!==z)return;let ce=new Set,re=new Set;for(let T of L.assignments){let E=`${L.payload.environmentId}:${T.experimentKey}`;if(re.add(E),A.has(E)||A.set(E,On(E,q)),!!T.inExperiment)for(let i of L.payload.experiments){if(i.key!==T.experimentKey||!mn(location.href,i.urlPatterns??[]))continue;let l=i.meta?.findIndex(G=>G.key===T.variationKey)??-1,o=i.variations[l];if(!o?.renderGuard)continue;let c=T.receiptId+":"+i.changeId,y=JSON.stringify([T.variationKey,o]);ce.add(c);let I=v.get(c);if(I?.signature===y){I.effect.applied&&O(T.receiptId);continue}v.get(c)?.effect.revert(),v.delete(c);let B=de(o,{requireUniqueTargets:!0,boundVariations:i.variations,allowJs:!1,onApplied:()=>O(T.receiptId),onError:G=>le(n.onError,G)});v.set(c,{signature:y,effect:B}),B.applied&&O(T.receiptId)}}for(let[T,E]of v)ce.has(T)||(E.effect.revert(),v.delete(T));for(let[T,E]of A)re.has(T)||(E(),A.delete(T))}catch(L){_===p&&d(),!w&&_===p&&le(n.onError,L)}finally{D=!1,a&&!w&&(a=!1,F())}}let R=n.client.subscribe(()=>{if(s()===S)return;S=s(),p++;let h=n.client.view;(!h||h.stopped||!["running","waiting"].includes(h.status))&&d(),e&&F()}),M=Tn(()=>{p++,d(),e&&F()}),C=()=>{p++,k()};document.addEventListener("visibilitychange",C);let H=We({document,run:async()=>{e&&await F()},delay:()=>e&&!w?15e3:void 0});return{async start(){e||w||(e=!0,await H.refresh())},refresh:F,destroy(){w=!0,p++,H.destroy(),document.removeEventListener("visibilitychange",C),R(),M(),d(),V.destroy()}}}var sn=5e3;async function zn(n,g,w){let e=g,[{mountScreenPreview:p},{showPaywall:D}]=await Promise.all([import("./screen-renderer-W5MP4KVG.js"),import("./paywall-DI62MX5L.js")]),a=e.client.identitySignal;e.signal?.throwIfAborted(),a?.throwIfAborted();let S=e.appManifestRelease?Mn({client:e.client,appManifestRelease:e.appManifestRelease,onError:e.onError}):void 0;S?.start();let s=n.ownerDocument,v=qn(s),u=s.createElement("section"),q=s.createElement("div"),A=s.createElement("div"),V=s.createElement("div"),k=s.createElement("button");V.hidden=!0,k.type="button";let d=s.createElement("p"),O=s.createElement("p"),F=s.createElement("button"),R=s.createElement("button"),M=s.createElement("button"),C=s.createElement("dialog"),H;u.dataset.indianaFunnel="",u.setAttribute("aria-busy","false"),d.setAttribute("role","status"),O.setAttribute("role","alert"),O.hidden=!0,F.type=R.type=M.type="button",A.append(F,k,d,O,M,R),u.append(q,V,A),n.append(u);let h=kn,_=rn(h),J="",z=(s.documentElement.lang||"").startsWith("zh"),L,de="",Y;for(let t of[F,k,M,R])_e(t,()=>_.focus);function ce(){let t=z?"\u5173\u95ED":"Close";R.parentElement===C?(R.textContent="\xD7",R.setAttribute("aria-label",t),Rn(R,h)):(R.textContent=t,R.removeAttribute("aria-label"),R.style.cssText=_.link+";margin-inline-start:auto")}function re(t){let r=t?.screen?.content.document.theme??h,f=JSON.stringify([r.primary,r.background,r.text,r.radius,r.font,R.parentElement===C]);f!==J&&(J=f,h=r,_=rn(h,R.parentElement===C),u.style.cssText=_.root+";min-width:0",A.style.cssText=_.bar,F.style.cssText=k.style.cssText=_.secondary,M.style.cssText=_.primary,d.style.cssText=_.status,O.style.cssText=_.alert,ce(),on(F))}function T(){A.hidden=F.hidden&&k.hidden&&M.hidden&&O.hidden&&!d.textContent&&(R.hidden||R.parentElement!==A),L?.responsive&&Y!==void 0&&L.setContentHeight(Y+A.getBoundingClientRect().height)}re();let E=null,i=null,l=null,o="",c="",y=!1,I="",B="",G="",b=!1,$=0,Re=!1,Ee="",Ke=null,Ye=Promise.resolve(),an=!e.client.view,W=w,qe,Oe,Le="",Ve,pe=!1,Ie=null,ye=!1,Me=()=>e.client.pendingCommand?.operation==="close",se=null,K=null,ln=We({document:s,run:async()=>{(!i?.observing||e.client.pendingCommand)&&await Ze()},delay:()=>{if(!(b||!l||!["running","waiting"].includes(l.status)&&!e.client.pendingCommand)&&!(i?.observing&&!e.client.pendingCommand))return l.pendingRequest||e.client.pendingCommand?1500:sn},hiddenDelay:()=>!b&&e.client.pendingCommand?15e3:void 0}),X=null;function Xe(){return K&&e.client.hasDurableJournal===!0&&X?.acknowledged===!0&&X.operationId===K.operationId&&e.client.view?.id===X.runId&&e.client.view?.status==="closed"&&e.client.view.revision===X.revision+1&&!(e.client.pendingCommands?.length??(e.client.pendingCommand?1:0))&&!e.client.pendingPurchase?K:null}function un(t){let r=t.run.paywall;if(X&&t.settlement?.requestId===X.requestId&&t.settlement.state==="settled"&&t.settlement.operationId===null&&t.run.id===X.runId&&t.run.status==="closed"&&!t.run.pendingRequest&&t.run.revision===X.revision+1&&t.run.nodeId===X.nodeId&&t.run.visit===X.visit&&r?.receiptId===X.receiptId&&r.selectionGeneration===X.selectionGeneration&&(r.quote?.operationId??null)===X.operationId&&(r.operation?.operationId??r.quote?.operationId??null)===X.operationId){let f=X.operationId===null&&r.selectionGeneration===0&&!r.quote&&!r.operation&&!r.purchaseRequestId,ne=ze({quote:r.quote,operation:r.operation,requestId:r.purchaseRequestId,pending:!1,destroyed:!1,canReselect:r.canReselect});(f||r.canReselect===!0&&ne.type==="native")&&(X.acknowledged=!0)}}let ke=null,He=new Set,fe={},Fe=!1,ue=(t,r=null)=>{b||(ke=r,Fe=!1,O.textContent=Fn(t,z),O.hidden=!1,M.hidden=e.client.pendingCommand===null,T(),le(e.onError,t))};function be(){let t=e.client.view;if(!t)throw new P("INVALID_REQUEST","No current Run is available");return{requestId:crypto.randomUUID(),nodeId:t.nodeId,visit:t.visit,revision:t.revision}}let U=Vn({client:e.client,doc:s,holder:q,reviewHolder:V,mountScreenPreview:p,loadingOptions:e,get chrome(){return _},get stopped(){return b},get answers(){return fe},suspend(t){i?.setSuspended(t)},resetScreen(){o="",c="",I=""},enqueue:me,fail:ue}),$e=_n({client:e.client,expected:be,fail:ue,get stopped(){return b},get reviewing(){return U.active},get key(){return o},get busy(){return $},get staleRead(){return Ke}}),Ue=Ln({client:e.client,expected:be,perform:Se,onIntent:e.onCustomerDataIntent,get stopped(){return b},get busy(){return $},get document(){return E?.document},get answers(){return fe}}),xe=t=>`${t.id}:${t.nodeId}:${t.visit}`,De=t=>t&&(t.screen||t.paywall)?xe(t):"";function Ce(){let t=e.client.view;F.disabled=!U.active&&($>0||!!e.client.pendingCommand||!t?.canBack||t.stopped||!["running","waiting"].includes(t.status)||!De(t)||c!==De(t)),F.hidden=!U.active&&!t?.canBack,on(F);let r=!!i&&!U.active;R.hidden=r&&!W?.active,k.hidden=!e.client.review||r&&!t?.canBack,r&&(d.textContent=""),T()}async function dn(t){if(!t)return;let r=e.client.view;await t;let f=e.client.view;if(!r||!f||f.id!==r.id||f.nodeId!==r.nodeId||f.visit!==r.visit||f.stopped||!["running","waiting"].includes(f.status))throw new P("PRECONDITION_FAILED","The screen changed while its display was acknowledged")}async function Se(t,r=!1){if(!(($||ye||se||K)&&!r||b||U.active&&!r)){$++,u.setAttribute("aria-busy","true"),O.hidden=!0,ke=null,Fe=!1,Ce();try{if(r||await dn($e.inFlight),b)return;let f=await t();b||await me(e.client.view??f.run)}catch(f){ue(f,e.client.pendingCommand?.requestId??null)}finally{$=Math.max(0,$-1),u.setAttribute("aria-busy",String($>0)),b||(M.hidden=e.client.pendingCommand===null,Ce())}}}function Ne(){ln.schedule()}async function Ze(){if(!(b||Re||$)){if(U.active){await U.open(U.receipt);return}Re=!0;try{let t=e.client.pendingCommand;t&&e.client.settle&&await e.client.settle(t.requestId);let r=e.client.view,f=Ue.queries,ne=await e.client.get(r?.screen&&Object.keys(f).length?{nodeId:r.nodeId,visit:r.visit,revision:r.revision,components:f}:void 0);Fe&&!b&&(Fe=!1,O.hidden=!0,T()),!b&&f===Ue.queries&&await me(e.client.view??ne.run)}catch(t){ue(t),Fe=!b}finally{Re=!1}}}function Ge(t,r){if(W?.active){let ne=W;return ne.setDismissHandler(()=>cn(ne)),ne}let f=Be(n,e,"funnel",()=>cn(f));return W=f,f.start(t,r),f}function cn(t){b||pe||(pe=!0,t.finish("dismissed"),ve(),u.hidden=!0,e.client.view?Pe().finally(ae):ae())}function en(){clearTimeout(Ve?.timeout),Ve=void 0}function ve(){en(),qe?.abort(),qe=void 0,E?.destroy(),E=null,i?.destroy(),i=null,Oe?.(),Oe=void 0,C.open&&C.close(),q.replaceChildren(),q.style.cssText="",Y=void 0,o="",c="",y=!1,I="",G=""}function pn(){let t=s.defaultView;L?.responsive&&t&&E?.resizeViewport?.(t.innerHeight,t.innerWidth)}function nn(){L?.destroy(),L=void 0,de=""}function tn(t){let r=t.screen?.presentation;if(!r||r.type==="inline"){C.open&&C.close(),nn(),R.parentElement!==A&&A.append(R),u.parentElement!==n&&n.append(u),re(t),T();return}u.parentElement!==C&&(C.append(R,u),n.append(C)),re(t);let f=t.screen.content.document,ne=JSON.stringify([r,J]);if(ne!==de){nn(),de=ne;let ge={sm:420,md:640,lg:900},we="size"in r&&!r.backdrop?",0 0 0 100vmax #16142566":"";C.style.cssText=`box-sizing:border-box;padding:0;border:0;overflow:auto;background:${h.background};color:${h.text};`+(r.type==="fullscreen"?"width:100vw;height:100dvh;max-width:100vw;max-height:100dvh;margin:0;border-radius:0":`width:${ge[r.size]}px;max-width:calc(100vw - 32px);max-height:calc(100dvh - 32px);box-shadow:0 24px 80px #0003${we};`+(r.type==="sheet"?"margin:auto auto 0;border-radius:14px 14px 0 0":"border-radius:14px")),L=Cn(C,{presentation:r,theme:f.theme,pages:f.pages},pn),L.latch()}T(),C.setAttribute("aria-label",(H?.screen===t.screen?.content.document.name?H?.label:void 0)??E?.document?.name??t.screen?.content.document.name??"Funnel")}async function Hn(t){if(b||pe||ye&&(Me()||["running","waiting"].includes(t.status))||(l=t,ke&&e.client.pendingCommand?.requestId!==ke&&(O.hidden=!0,ke=null),z=t.locale.startsWith("zh"),k.textContent=z?"\u56DE\u770B":"History",F.textContent=U.active?z?"\u8FD4\u56DE\u5F53\u524D":"Return to current":z?"\u8FD4\u56DE":"Back",ce(),M.textContent=z?"\u91CD\u8BD5":"Retry",M.hidden=e.client.pendingCommand===null,d.textContent=t.pendingRequest?z?"\u6B63\u5728\u5904\u7406":"Processing":t.instruction?.type==="wait"?z?"\u7B49\u5F85\u4E2D":"Waiting":"",Ce(),Ee!==`${t.revision}:${t.visit}:${t.status}:${t.stopped}`&&(Ee=`${t.revision}:${t.visit}:${t.status}:${t.stopped}`,le(e.onState,structuredClone(t))),b||pe))return;if((!t.pendingRequest||ye&&t.status==="closed")&&["closed","ineligible","failed"].includes(t.status)){ae();return}if(t.stopped||e.client.configurationReady===!1){U.stop(),ve(),W?.finish("skipped"),u.hidden=!0,Ne();return}if(u.hidden=!1,U.active){Ne();return}let r=De(t),f=e.client.view;if(f&&f.revision>t.revision&&De(f)!==r)return;let ne=!t.instruction&&!t.pendingRequest&&t.nodeType==="screen"&&["running","waiting"].includes(t.status);r!==o&&(o&&W?.finish("dismissed"),ve(),o=r,fe={...t.answers},Ue.reset());let ge=xe(t);if(Le===ge){u.hidden=!0;return}if(ne&&!r){u.hidden=!0;let Q=Ge(!0,t.locale);!b&&!pe&&Ve?.key!==ge&&(en(),Ve={key:ge,timeout:setTimeout(()=>{let m=e.client.view;if(!Q.active||!m||xe(m)!==ge)return;Le=ge;let j=new Error("Funnel screen preparation timed out");Q.finish("error",j),ve(),ue(j)},Ae)}),Ne();return}en();let Z=Q=>{let m=e.client.view;return!b&&!pe&&!Ie&&!Q.aborted&&e.client.configurationReady!==!1&&!!m&&!m.stopped&&!["closed","ineligible","failed"].includes(m.status)&&De(m)===r},we=(Q,m)=>{Z(m)&&(Le=r,W?.finish("error",Q),ve(),u.hidden=!0,ue(Q))};if(r||(tn(t),t.instruction?.type!=="event"&&t.instruction?.type!=="open_url"&&W?.finish("skipped")),t.screen){let Q=t.screen.content;if(!E){let te=t.screen.presentation.type!=="inline",oe=Ge(te,t.locale);if(b||pe)return;let ie=(qe=new AbortController).signal;tn(t),Oe=te?En(C):je(u,n),E=p(q,{mode:"live",rendererUrl:e.client.webViewUrl,title:Q.document.name,...te?{hostPresentation:()=>L?.type??t.screen.presentation.type}:{},onResize:ee=>{Y=ee,L?.responsive&&L.setContentHeight(ee+A.getBoundingClientRect().height)},onAction(ee,he={},Gn={}){if(U.active||!Z(ie)||c!==r)return;fe={...fe,...Gn};let Jn=Object.fromEntries((t.screen?.inputs??[]).filter(({variable:Je})=>Object.hasOwn(fe,Je)).map(({variable:Je})=>[Je,fe[Je]]));Se(()=>e.client.submit({operation:"submit",...be(),input:{type:"screen",output:ee,answers:Jn,selection:he}}))},onAnswers:ee=>{U.active||!Z(ie)||c!==r||(fe={...fe,...ee})},onCustomerDataIntent:ee=>{U.active||!Z(ie)||c!==r||Ue.intent(ee).catch(ue)},onEscape:()=>{!Z(ie)||c!==r||U.active||se||K||Pe()},onError:ee=>{let he=new Error(ee);c===r?ue(he):we(he,ie)},onRendered:ee=>{if(!(!Z(ie)||c===r))try{oe.present(he=>{Oe?.(),Oe=void 0,ee&&(H={screen:Q.document.name,label:ee},C.setAttribute("aria-label",ee)),te&&(C.showModal(),L?.responsive&&C.focus({preventScroll:!0}),!he&&e.loading!=="host"&&Pn(C,L?.type??t.screen.presentation.type,L?.responsive)),c=r,y=te,Ce()}),Z(ie)&&$e.report(r)}catch(he){we(he,ie)}}}),pn()}let m={capabilities:t.screen.capabilities,customerData:t.screen.customerData,parameters:t.parameters,serverInput:{bindings:t.screen.inputs,answers:fe,values:t.screen.values}},j=JSON.stringify([Q,t.locale,m.parameters,t.screen.inputs,t.screen.values]);if(j!==I)E.update(Q.document,t.locale,m),I=j,B=JSON.stringify(m.capabilities),G=JSON.stringify(m.customerData);else{let te=JSON.stringify(m.capabilities);te!==B&&(E.updateCapabilities(m.capabilities),B=te),JSON.stringify(m.customerData)!==G&&(E.updateCustomerData(m.customerData),G=JSON.stringify(m.customerData))}let x=E;if(x)try{await(W?.wait(x.ready)??x.ready)}catch(te){qe&&we(te,qe.signal)}}else if(t.paywall&&!i){let Q=Ge(!0,t.locale);if(b||pe)return;let m=(qe=new AbortController).signal;tn(t);let j=await D(q,{loading:"host",signal:m,canInteract:()=>Z(m)&&!U.active&&!se&&!K,beforeAction:async()=>{$++;try{await dn($e.settled()),O.hidden=!0,ke=null,Fe=!1,T()}finally{$=Math.max(0,$-1)}},start:()=>An(e.client),onObservationChange:Ne,onPurchase:e.onPurchase,onCheckoutUrl:e.onCheckoutUrl,checkoutNavigation:e.checkoutNavigation,confirmOnHostedCheckout:e.confirmOnHostedCheckout,resolveOfferId:e.resolveOfferId,onEvent:e.onEvent,onOpenUrl:x=>e.onOpenUrl?e.onOpenUrl({receiptId:t.paywall.receiptId,url:x,openIn:"same_window"}):s.defaultView?.location.assign(x),onAction:async x=>{if(U.active)return;let te=await e.client.submit({operation:"submit",requestId:crypto.randomUUID(),nodeId:t.nodeId,visit:t.visit,revision:e.client.view?.revision??t.revision,input:{type:"screen",output:x,answers:{}}});await me(e.client.view??te.run)},onError:x=>{c===r?ue(x):we(x,m)}},{quoteError:x=>le(e.onError,x),present(x){Z(m)&&(Q.present(()=>{x(),c=r,y=!!q.querySelector("dialog[open]"),Ce()}),Z(m)&&$e.report(r))},async dismiss(){b||m.aborted||U.active||se||K||!ye&&!Z(m)||(ye=!0,await Pe())}}).catch(x=>(we(x,m),null));!Z(m)&&!(ye&&!b&&!m.aborted)?j?.host?.destroy():j&&(i=j.host,i?.setSuspended(U.active))}if(b||pe)return;Ce();let N=t.instruction;if(N&&(N.type==="open_url"||N.type==="event")&&!He.has(N.receiptId)){let Q=s.createElement("button");Q.type="button",Q.style.cssText=_.primary,_e(Q,()=>_.focus),q.style.cssText=_.stage,Q.textContent=N.type==="open_url"?`${z?"\u524D\u5F80":"Continue to"} ${new URL(N.url).host}`:z?"\u7EE7\u7EED":"Continue",Q.onclick=()=>{let m=be(),j=N.type==="open_url"&&!e.onOpenUrl&&N.openIn==="new_window"?$n(N.url):null;Se(async()=>{let x="success";if(N.type==="open_url")if(e.onOpenUrl)try{x=await e.onOpenUrl({receiptId:N.receiptId,url:N.url,openIn:N.openIn})===!1?"failed":"opened"}catch(oe){le(e.onError,oe),x="failed"}else x=N.openIn==="new_window"&&!j?"failed":"opened";if(N.type==="event"){if(!e.onEvent)throw new P("EVENT_HANDLER_REQUIRED","Provide the event handler");await e.onEvent(N.event)}if(b||e.client.view?.nodeId!==m.nodeId||e.client.view.visit!==m.visit)throw new P("PRECONDITION_FAILED","The client action visit changed");let te=await e.client.submit({operation:"submit",...m,input:{type:"client_action",receiptId:N.receiptId,outcome:x}});return He.add(N.receiptId),N.type==="open_url"&&!e.onOpenUrl&&N.openIn==="same_window"&&s.defaultView?.location.assign(N.url),te})},W?.active?W.present(()=>q.replaceChildren(Q)):q.replaceChildren(Q)}!t.pendingRequest&&t.status==="completed"&&!He.has(`complete:${t.id}`)&&(He.add(`complete:${t.id}`),le(e.onComplete,structuredClone(t))),Ne()}function $n(t){let r=s.defaultView?.open(t,"_blank")??null;return r&&(r.opener=null),r}function me(t){return Ce(),Ye=Ye.catch(()=>{}).then(async()=>{try{await Hn(t)}catch(r){throw W?.active&&(Le=xe(t),W.finish("error",r),ve(),u.hidden=!0),r}}),Ye}let Un=e.client.subscribe(t=>{if(!an){if(t.stopped&&y&&!ye){l=t,ae();return}!ye&&(t.stopped||e.client.configurationReady===!1||o&&c!==o&&(De(t)!==o||["closed","ineligible","failed"].includes(t.status)))&&(ve(),W?.finish("dismissed"),u.hidden=!0),me(t).catch(ue)}}),xn=e.client.subscribeError?.(ue);function Pe(t){if(Ie)return Ie;if(b||!t&&(se||K))return Promise.resolve();let r=!t&&Me();return!r&&e.client.view&&!["running","waiting"].includes(e.client.view.status)?(l=e.client.view,ae(),Promise.resolve()):(Ie=Se(async()=>{let f=r?await e.client.retry():await e.client.submit({operation:"close",...t??be()});return t&&un(f),f},!0).then(()=>{let f=e.client.view;f?.status==="closed"&&!Me()&&(l=f,ae())}).finally(()=>{Ie=null}),Ie)}function ae(){S?.destroy(),!b&&(b=!0,e.signal?.removeEventListener("abort",ae),a?.removeEventListener("abort",ae),W?.finish("dismissed"),ln.destroy(),Un(),xn?.(),ve(),nn(),U.stop(),C.remove(),u.remove(),v(),le(e.onDismiss,l?structuredClone(l):null))}F.onclick=()=>{if(!F.disabled){if(U.active){U.exit();return}Se(()=>e.client.submit({operation:"back",...be()}))}},k.onclick=()=>{U.open()},R.onclick=()=>{W?.active?W.dismiss():se||Pe()},M.onclick=()=>{Me()?Pe():Se(()=>e.client.retry())},C.addEventListener("cancel",t=>{t.preventDefault(),W?.active?W.dismiss():se||Pe()}),e.signal?.addEventListener("abort",ae,{once:!0}),a?.addEventListener("abort",ae,{once:!0});try{let t=e.client.view;if(t)((e.client.viewAgeMs??sn)>=sn||t.instruction?.type==="evaluate_segment")&&(Ke=Ze().finally(()=>{Ke=null})),await me(t);else{u.hidden=!0;let r=Ge(e.client.view?.screen?.presentation.type!=="inline",e.client.view?.locale);if(b||pe)throw new DOMException("Presentation cancelled","AbortError");let f=await r.wait(e.client.get(),Ae);an=!1,await me(e.client.view??f.run)}}catch(t){throw W?.finish("error",t),ae(),t}return{destroy:ae,refresh:Ze,get recovery(){let t=Xe();if(t)return t;if(!b&&!$&&!ye&&!se&&i){let r=i.recovery;if(r.type!=="native")return r}return{type:"recover",operationId:e.client.pendingPurchase?.operationId??e.client.view?.paywall?.quote?.operationId??K?.operationId??null,requestId:e.client.pendingCommand?.requestId??null}},prepareFallback(){if(se)return se;let t=Xe();if(t)return Promise.resolve(t);let r=e.client.pendingPurchase?.operationId??e.client.view?.paywall?.quote?.operationId??K?.operationId??null,f=()=>({type:"recover",operationId:r,requestId:e.client.pendingCommand?.requestId??null});if(e.client.hasDurableJournal!==!0){let N=i?.recovery;return Promise.resolve(N&&N.type!=="native"&&N.type!=="cancel"?N:f())}let ne=(e.client.pendingCommands??(e.client.pendingCommand?[e.client.pendingCommand]:[])).some(N=>N.operation==="close");if(b&&!(ne||K&&e.client.view?.status==="closed")||$||Re||Ie||U.active||!i&&!K&&!ne)return Promise.resolve(f());let ge=i,Z=(async()=>{try{if(!K&&ne){let m=await e.client.retry();return await me(e.client.view??m.run),f()}if(!K){let m=await ge.prepareFallback();if(m.type!=="native")return m;if(e.client.hasDurableJournal!==!0)return f();K=m}let N=e.client.pendingCommands??(e.client.pendingCommand?[e.client.pendingCommand]:[]);if(N.length){let m=N.find(x=>x.operation==="close");if(!m||!X||m.requestId!==X.requestId)return f();let j=await e.client.retry();un(j),await me(e.client.view??j.run)}else{let m=e.client.view,j=m?.paywall;if(!m||!j||j.selectionGeneration===void 0||(j.quote?.operationId??null)!==K.operationId||K.operationId!==null&&j.canReselect!==!0)return f();let x=j.selectionGeneration,te=await e.client.get();await me(e.client.view??te.run);let oe=e.client.view,ie=oe?.paywall;if(!oe||!ie||!["running","waiting"].includes(oe.status)||oe.stopped||oe.id!==m.id||oe.nodeId!==m.nodeId||oe.visit!==m.visit||ie.receiptId!==j.receiptId||ie.selectionGeneration!==x||(ie.quote?.operationId??null)!==K.operationId||K.operationId!==null&&ie.canReselect!==!0||e.client.pendingPurchase||(e.client.pendingCommands?.length??(e.client.pendingCommand?1:0)))return f();let ee=be();X={runId:oe.id,operationId:K.operationId,revision:ee.revision,requestId:ee.requestId,nodeId:oe.nodeId,visit:oe.visit,receiptId:ie.receiptId,selectionGeneration:x,acknowledged:!1},await Pe(ee)}let Q=Xe();return Q?(ae(),Q):f()}catch(N){return ue(N),f()}})();se=Z;let we=()=>{se===Z&&(se=null)};return Z.then(we,we),Z},review:U.open,exitReview:U.exit,get unappliedDrafts(){return U.drafts}}}function Vt(n,g,w){return zn(n,g,w)}export{Bn as a,Mn as b,zn as c,Vt as d};
1
+ import{a as kn,b as rn,c as on,d as _e,e as Fn,f as We,h as Dn}from"./chunk-HQPP76BS.js";import{c as Cn,d as Pn,e as Rn,f as Ae,g as Be,h as En,i as je,k as qn}from"./chunk-Y3MQLWGD.js";import{$ as Qe}from"./chunk-R23IGK5U.js";import{a as ze,e as gn,f as vn,g as hn,h as In,i as bn}from"./chunk-EHDHWYVJ.js";import{b as wn}from"./chunk-BXPXJARS.js";import{R as fn,qa as yn}from"./chunk-N7YXDSQL.js";import{a as P}from"./chunk-X4W22IH6.js";import{b as Sn,e as On}from"./chunk-SLUA7ABW.js";import{d as Tn}from"./chunk-XH7RJPBV.js";import{a as le}from"./chunk-DSPLGTQI.js";import{b as mn}from"./chunk-7QL4GF4C.js";var Te=new WeakMap;function Bn(n){let g=n.view,w=g?.paywall?.resolution;if(!g||!["running","waiting"].includes(g.status)||g.stopped||!w||"document"in w||!n.resolvePaywall||n.identitySignal?.aborted)return;let e=JSON.stringify(w);if(Te.get(n)?.key===e)return;let p=JSON.parse(e),D=n.identitySignal,a=Promise.resolve().then(async()=>{D?.throwIfAborted();let s=await n.resolvePaywall(p);return D?.throwIfAborted(),s}),S={key:e,content:a};return Te.set(n,S),a.catch(()=>{}),()=>{Te.get(n)===S&&Te.delete(n)}}function Nn(n,g){let w=Te.get(n);return Te.delete(n),w?.key===JSON.stringify(g)?w.content:n.resolvePaywall(g)}async function An(n){let{session:g,load:w}=Qn(n);try{return await w(),g}catch(e){throw g.destroy(),e}}function Qn(n){let g=n.view;if(!g?.paywall)throw new P("INVALID_REQUEST","The current node is not a Paywall");let w=g.paywall.receiptId,e=g.nodeId,p=g.visit,D=g.paywall.resolution,a=g.paywall,S="document"in D?{document:D.document,offering:D.offering,capabilities:D.capabilities}:null;function s(){let i=a.resolution;return"document"in i?i:S&&{...i,document:S.document,offering:S.offering,capabilities:gn(i.capabilities,S.capabilities)}}function v(i){if(!vn(i,D))throw new P("INVALID_RESPONSE","The pinned Paywall binding changed")}let u=!1,q=new Set,A=null;function V(){let i=s();if(i&&!u)for(let l of q)le(l,structuredClone(i))}async function k(){J();let i=s();if(i)return structuredClone(i);if(!A){let l=(async()=>{if("document"in a.resolution||!n.resolvePaywall)throw new P("INVALID_RESPONSE","Public Paywall reader is unavailable");let c=await Nn(n,a.resolution);return J(),v(c),S={document:c.document,offering:c.offering,capabilities:c.capabilities},V(),s()})();A=l;let o=()=>{A===l&&(A=null)};l.then(o,o)}return A.then(l=>structuredClone(l))}let d=new AbortController,F=(n.pendingCommands??(n.pendingCommand?[n.pendingCommand]:[])).find(i=>i.operation==="submit"&&i.nodeId===e&&i.visit===p&&i.input.type==="paywall_quote")?.requestId??g.paywall.purchaseRequestId,R=0,M=null,C=new Set,H=null,h=new Map;function _(i){if(i.purchase&&i.purchase.receiptId!==w)throw new P("INVALID_RESPONSE","Purchase receipt changed");let l=i.run.paywall;return i.purchase??(l?.receiptId===w?l:null)}function J(){if(u)throw new P("IDENTITY_CHANGED","Paywall presentation has closed")}function z(i,l,o){if(J(),l!==R||o!==void 0&&a.quote?.operationId!==o)return!1;let c=a.selectionGeneration??0,y=i.run.paywall;if(y?.receiptId===w){if((y.selectionGeneration??0)<(a.selectionGeneration??0))return!1;v(y.resolution)}let I=_(i),B=y?.receiptId===w&&(y.selectionGeneration??0)>c,G=B?I?.quote??null:I?.quote??a.quote,b=I?.operation??(G?.operationId===a.quote?.operationId?a.operation:null);return G&&b&&hn(b,{operationId:G.operationId},"Purchase operation changed"),(B||G?.operationId!==a.quote?.operationId)&&(R++,y?.receiptId===w&&(F=y.purchaseRequestId)),y?.canReselect===!0&&y.purchaseRequestId===H&&!(n.pendingCommands??[n.pendingCommand]).some($=>$?.requestId===H)&&(H=null),a={...a,...y?.receiptId===w?y:{},quote:G,operation:bn(a.operation,b,!0)},V(),!0}function L(i,l,o){return new Promise((c,y)=>{let I=!1,B=()=>{clearTimeout(Re),d.signal.removeEventListener("abort",$)},G=Ee=>{I||(I=!0,B(),c(Ee))},b=Ee=>{I||(I=!0,B(),y(Ee))},$=()=>b(new P("IDENTITY_CHANGED","Paywall presentation has closed")),Re=setTimeout(()=>b(new P("COMMAND_PENDING","The purchase command is still pending; retry the original request",202,o)),Math.max(0,l-Date.now()));d.signal.addEventListener("abort",$,{once:!0}),d.signal.aborted&&$(),i.then(G,b)})}function de(i){return new Promise(l=>{let o=()=>{clearTimeout(c),d.signal.removeEventListener("abort",o),l()},c=setTimeout(o,i);d.signal.addEventListener("abort",o,{once:!0}),d.signal.aborted&&o()})}function Y(i,l){J();let o=h.get(i)??n.pendingCommands?.find(I=>I.requestId===i)??n.pendingCommand;if(o?.operation==="submit"&&o.requestId===i&&o.nodeId===e&&o.visit===p){l.type==="paywall_quote"&&o.input.type==="paywall_quote"&&o.input.predecessor&&!l.predecessor&&(l={...l,predecessor:o.input.predecessor});let I=Qe.parse(o),B=Qe.parse({...o,input:l});if(I.operation!=="submit"||B.operation!=="submit"||JSON.stringify(I.input)!==JSON.stringify(B.input))throw new P("CONFLICT","A purchase request cannot change its input");return h.set(i,I),I}let c=n.view;if(!c||c.nodeId!==e||c.visit!==p||c.paywall?.receiptId!==w)throw new P("PRECONDITION_FAILED","The Paywall visit has changed");let y=Qe.parse({operation:"submit",requestId:i,nodeId:e,visit:p,revision:c.revision,input:structuredClone(l)});if(y.operation!=="submit")throw new P("INVALID_REQUEST","A purchase submission is required");return h.set(i,y),y}async function ce(i,l){J();let{requestId:o,input:c}=i,y=Date.now()+3e4;C.add(o);try{let I=await L(n.submit(i),y,o);for(;I.run.pendingRequest?.requestId===o&&Date.now()<y&&!u&&(await de(Math.min(1e3,y-Date.now())),!(u||Date.now()>=y));)I=await L(n.resume(o),y,o);if(u)throw new P("IDENTITY_CHANGED","Paywall presentation has closed");if(I.run.pendingRequest?.requestId===o)throw new P("COMMAND_PENDING","The purchase command is still pending; retry the original request",202,o);if(!z(I,l,c.type==="paywall_confirm"||c.type==="paywall_cancel"?c.operationId:void 0))throw new P("PRECONDITION_FAILED","The purchase selection has changed");H===o&&(H=null)}catch(I){if(H=o,c.type==="paywall_quote"&&n.settle&&!u&&I instanceof P&&I.status!==void 0&&![401,425].includes(I.status)&&!I.retryable&&I.recovery!=="recover_operation")try{if((await L(n.settle(o),y,o)).settlement?.state==="settled"){let G=await L(n.get(),y,o);z(G,l)&&G.run.paywall?.purchaseRequestId===o&&a.canReselect===!0&&h.delete(o)}}catch{}throw I instanceof P&&I.code==="COMMAND_PENDING"&&I.status===void 0&&h.delete(o),I}finally{C.delete(o)}}async function re(i){if(!a.quote)throw new P("INVALID_REQUEST","A quoted purchase is required");let l=i==="confirm"?"paywall_confirm":"paywall_cancel",o=[...h.values(),...n.pendingCommands??(n.pendingCommand?[n.pendingCommand]:[])].find(y=>y.operation==="submit"&&y.input.type===l&&"operationId"in y.input&&y.input.operationId===a.quote.operationId),c=o?.operation==="submit"&&o.input.type===l&&"operationId"in o.input&&o.input.operationId===a.quote.operationId?o.requestId:crypto.randomUUID();if(await ce(Y(c,{type:i==="confirm"?"paywall_confirm":"paywall_cancel",operationId:a.quote.operationId}),R),!a.operation)throw new P("INVALID_RESPONSE","The accepted purchase result is missing");return structuredClone(a.operation)}let T={get view(){return structuredClone(s())},get quote(){return a.quote?structuredClone(a.quote):null},get operation(){return a.operation?structuredClone(a.operation):null},get webViewUrl(){return n.webViewUrl},get canReselect(){return a.canReselect===!0&&H===null},get recovery(){let i=n.pendingCommands??(n.pendingCommand?[n.pendingCommand]:[]),l=n.pendingPurchase;if(l&&(l.receiptId!==w||l.operationId!==a.quote?.operationId))return{type:"recover",operationId:l.operationId,requestId:i[0]?.requestId??null};let o=ze({quote:a.quote,operation:a.operation,requestId:i[0]?.requestId??H??F,pending:C.size>0||i.length>0||H!==null,destroyed:u,canReselect:a.canReselect});return o.type==="recover"&&o.requestId===null&&!u&&n.hasDurableJournal===!0&&!a.quote&&!a.operation&&(a.selectionGeneration??0)===0&&!l&&!i.length&&!C.size&&!F?{type:"native",operationId:null}:o},get pendingCancellation(){return!u&&(n.pendingCommands??(n.pendingCommand?[n.pendingCommand]:[])).some(i=>i.operation==="submit"&&i.nodeId===e&&i.visit===p&&i.input.type==="paywall_cancel"&&i.input.operationId===a.quote?.operationId)},subscribe(i){return u?()=>{}:(q.add(i),()=>q.delete(i))},async refresh(){J();let i=R,l=await n.get();if(z(l,i),l.run.paywall?.receiptId!==w)throw new P("PRECONDITION_FAILED","Paywall presentation has changed");return k()},preview(i){let l=s();if(!l)return Promise.reject(new P("PRECONDITION_FAILED","Load the Paywall presentation first"));if(F&&F!==i.requestId&&(M||a.canReselect!==!0))return Promise.reject(new P("COMMAND_PENDING","Retry the original purchase before starting another"));let o=l.document.buttons[i.actionId],c=o?.type==="checkout"?wn(o.product,i.selection,l.capabilities):null;if(!c)return Promise.reject(new P("PRODUCT_UNAVAILABLE","Choose an available Product in this purchase area"));let y=yn(l.document.screen,c,i.selection,l.capabilities),I=F!==i.requestId&&(a.selectionGeneration??0)>0?{operationId:a.quote?.operationId??null,generation:a.selectionGeneration??0}:void 0;if(I&&a.canReselect!==!0)return Promise.reject(new P("COMMAND_PENDING","Original purchase requires authoritative termination"));let B;try{B=Y(i.requestId,{type:"paywall_quote",actionId:i.actionId,productVersionId:c,...Object.keys(y).length?{featureQuantities:y}:{},...I?{predecessor:I}:{},...i.offerId?{offerId:i.offerId}:{},...i.nativeOffer?{nativeOffer:i.nativeOffer}:{}})}catch($){return Promise.reject($)}if(F===i.requestId&&M)return M;F!==i.requestId&&R++;let G=R;F=i.requestId;let b=(async()=>{if(await ce(B,G),!a.quote)throw new P("INVALID_RESPONSE","The accepted quote is missing");return In(a.quote,{productVersionId:c,featureQuantities:y},"The selected purchase changed"),structuredClone(a.quote)})();return M=b,b.then(()=>{M===b&&(M=null)},$=>{M===b&&(M=null),F===i.requestId&&n.pendingCommand?.requestId!==i.requestId&&$ instanceof P&&$.status!==void 0&&$.status<500&&![401,425].includes($.status)&&(F=null)}),b},confirm:()=>re("confirm"),cancel:()=>re("cancel"),async read(){if(J(),!a.quote)throw new P("INVALID_REQUEST","A quoted purchase is required");let i=a.quote.operationId,l=R,o=n.pendingCommands?.find(G=>G.operation==="submit"&&(G.input.type==="paywall_confirm"||G.input.type==="paywall_cancel")&&G.input.operationId===i)??n.pendingCommand;o?.operation==="submit"&&(o.input.type==="paywall_confirm"||o.input.type==="paywall_cancel")&&o.input.operationId===i&&await n.settle?.(o.requestId);let c=await n.get(void 0,{receiptId:w,operationId:i});J();let y=_(c);if(y?.quote&&y.quote.operationId!==i||y?.operation&&y.operation.operationId!==i)throw new P("INVALID_RESPONSE","Purchase operation changed");let I=z(c,l,i),B=I?a.operation:y?.operation;if(!B)throw new P("INVALID_RESPONSE","The current purchase result is missing");return I&&C.size===0&&!(n.pendingCommands?.length??(n.pendingCommand?1:0))&&(H=null),structuredClone(B)},destroy(){u=!0,E(),q.clear(),d.abort(),h.clear()}},E=n.subscribe(i=>{u||i.nodeId!==e||i.visit!==p||i.paywall?.receiptId!==w||(i.paywall.selectionGeneration??0)<(a.selectionGeneration??0)||(v(i.paywall.resolution),a={...a,resolution:i.paywall.resolution},V())});return{session:T,load:k}}function _n(n){let g=new Set,w=new Set,e=null;async function p(s,v){let u=!1;for(;!n.stopped&&n.key===s&&n.client.pendingCommand?.requestId===v;){if(!n.client.settle)throw new P("COMMAND_PENDING","The original display acknowledgement is still pending");await n.client.settle(v),u=!0,n.client.pendingCommand?.requestId===v&&await new Promise(q=>setTimeout(q,1500))}n.stopped||n.key!==s||(u&&await n.client.get(),!(n.stopped||n.key!==s)&&g.add(s))}function D(s,v){e=v;let u=()=>{e===v&&(e=null),w.delete(s)};return v.then(u,q=>{u(),n.busy||n.fail(q)}),v}function a(s){if(n.reviewing||g.has(s)||w.has(s)||n.stopped)return;w.add(s);let v=async()=>{if(n.reviewing||n.stopped||n.key!==s||g.has(s)){w.delete(s);return}if(n.busy||n.client.pendingCommand){setTimeout(()=>{v()},250);return}let u=(async()=>{if(n.staleRead){if(await n.staleRead,n.stopped||n.key!==s)return;if(n.client.pendingCommand){setTimeout(()=>{v()},250);return}}let q=n.client.view,A=n.expected(),V=A.requestId;try{await n.client.submit({operation:"shown",...A})}catch(k){if(!(k instanceof P)||k.code!=="CONFLICT"||k.status!==409||n.client.pendingCommand)throw k;await n.client.get();let d=n.client.view;if(n.stopped||n.reviewing||n.key!==s||!d||!q||d.id!==q.id||d.source.versionId!==q.source.versionId||d.nodeId!==A.nodeId||d.visit!==A.visit||d.revision<=A.revision||d.stopped||!d.screen&&(!d.paywall||d.paywall.receiptId!==q.paywall?.receiptId)||!["running","waiting"].includes(d.status)||n.client.pendingCommand)throw k;let O=n.expected();V=O.requestId,await n.client.submit({operation:"shown",...O})}await p(s,V)})();D(s,u)};v()}function S(){if(e)return e;let s=n.client.pendingCommand;if(s?.operation!=="shown")return null;let v=n.key;return w.add(v),D(v,(async()=>{await n.client.retry(),await p(v,s.requestId)})())}return{report:a,settled:S,get inFlight(){return e}}}function Ln(n){let g={},w=new Map;async function e(p){let D=n.client.view,a=D?.screen,S=a?.customerData.nodes[p.nodeId];if(n.stopped||n.busy||!D||!a||!S)return;if(!["refresh","next","previous","filter","sources_next","sources_previous"].includes(p.action)){let k=n.document,d=k?fn(k,p.nodeId):null,O=d?.type==="customer_data"?d.data.outputs?.[p.action]:void 0;O&&a.outputs.includes(O)?await n.perform(()=>n.client.submit({operation:"submit",...n.expected(),input:{type:"screen",output:O,answers:n.answers,selection:p.value?{[p.nodeId]:p.value}:{}}})):await n.onIntent?.(p,D);return}let v=p.action.startsWith("sources_")?S.resources.find(k=>k.key===p.value):null;if(p.action.startsWith("sources_")&&!v)throw new P("INVALID_REQUEST","Choose a current resource");let u=`${D.visit}:${p.nodeId}:${v?.key??""}`,q=w.get(u)??[null],V=g[p.nodeId]??{page:1,after:null,filter:"all",...v?{resourceKey:v.key}:{}};if(p.action==="filter"){let k=p.value;if(!k||!(S.source==="offer_history"?["all","issued","reserved","redeemed","expired","revoked"]:["all","purchase","refund","source","usage","debt","settlement"]).includes(k))throw new P("INVALID_REQUEST","Unknown data filter");V={page:1,after:null,filter:k},q.splice(0,q.length,null)}else if(p.action==="next"||p.action==="sources_next"){let k=v?.sources.at(-1),d=v?k?{kind:"ledger",cursor:{at:k.detail[0],id:k.id,type:"source"}}:null:a.dataCursors[p.nodeId];if(!d||!v&&!S.hasNext)return;q[V.page]=d,V={...V,page:V.page+1,after:d}}else if(p.action==="previous"||p.action==="sources_previous"){if(V.page<=1)return;V={...V,page:V.page-1,after:q[V.page-2]??null}}w.set(u,q),g={...g,[p.nodeId]:V},await n.perform(()=>n.client.get({nodeId:D.nodeId,visit:D.visit,revision:D.revision,components:g}))}return{get queries(){return g},intent:e,reset(){g={},w.clear()}}}function Vn(n){let{doc:g,holder:w,reviewHolder:e,mountScreenPreview:p}=n,D=!1,a,S=0,s=null,v="",u,q=new Map,A=d=>d?`${d.id}:${d.nodeId}:${d.visit}:${d.revision}:${d.paywall?.quote?.operationId??""}`:"";async function V(d){if(n.stopped||!n.client.review||D&&d===a&&u?.active)return;let O=!D||d!==a;D||(v=A(n.client.view),q.set(v,structuredClone(n.answers))),D=!0,a=d,w.hidden=!0,n.suspend(!0),e.hidden=!1;let F=++S;O&&(u?.finish("dismissed"),s?.destroy(),s=null,e.replaceChildren(),u=Be(e,n.loadingOptions,"funnel",()=>{k()}));let R=O?u:void 0;try{if(R?.start(!1,n.client.view?.locale),F!==S||n.stopped)return;let M=n.client.review(d),C=await(R?.wait(M,Ae)??M);if(n.stopped||F!==S||!D)return;if(!C.review)throw new P("INVALID_RESPONSE","Historical projection is missing");s?.destroy(),s=null,R||e.replaceChildren();let H=g.createElement("div"),h=R?je(H,e):()=>{};e.append(H);let _=C.run.locale.startsWith("zh"),J=n.chrome;H.style.cssText=J.history;let z=g.createElement("p");z.textContent=_?"\u53EA\u8BFB\u56DE\u770B":"Read-only history",z.style.cssText=J.historyTitle,H.append(z);let L=g.createElement("p");L.style.cssText=J.historyNote,L.textContent=C.review.pages.length?_?"\u9009\u62E9\u4E00\u9875\u67E5\u770B\u5F53\u65F6\u7684\u5185\u5BB9\uFF0C\u56DE\u770B\u4E0D\u4F1A\u6539\u52A8\u4EFB\u4F55\u4FE1\u606F\u3002":"Choose a page to see it as it was. Nothing here can be changed.":_?"\u8FD8\u6CA1\u6709\u53EF\u56DE\u770B\u7684\u9875\u9762\u3002":"There are no earlier pages yet.",H.append(L);let de=C.review.page?.receiptId,Y=g.createElement("div");Y.style.cssText=J.historyPages;for(let[T,E]of C.review.pages.entries()){let i=g.createElement("button");i.type="button",i.textContent=_?`\u7B2C ${T+1} \u9875`:`Page ${T+1}`;let l=de!==void 0&&E.receiptId===de;i.style.cssText=l?J.primary:J.secondary,l&&i.setAttribute("aria-current","page"),_e(i,()=>n.chrome.focus),i.onclick=()=>{V(E.receiptId)},Y.append(i)}if(Y.childElementCount&&H.append(Y),C.review.page){let T=C.review.page,E=g.createElement("div");E.inert=!0,E.style.cssText=J.historyPage,H.append(E),s=p(E,{mode:"live",rendererUrl:n.client.webViewUrl,title:T.document.name,onAction:()=>{},onAnswers:()=>{},onCustomerDataIntent:()=>{},onRendered:()=>{F===S&&!n.stopped&&R?.present(h)},onError:l=>{if(F!==S||n.stopped)return;let o=new Error(l);R?.finish("error",o),s?.destroy(),s=null,H.remove(),n.fail(o)},onEscape:()=>{k()}});let i=s;if(i.update(T.document,C.run.locale,{serverInput:{bindings:T.inputs,answers:T.answers,values:T.values}}),await i.ready,n.stopped||F!==S||!D)return}let ce=_?{issued:"\u5DF2\u9886\u53D6",reserved:"\u5DF2\u9884\u7559",redeemed:"\u5DF2\u4F7F\u7528",expired:"\u5DF2\u8FC7\u671F",revoked:"\u5DF2\u64A4\u9500",unknown:"\u72B6\u6001\u5F85\u786E\u8BA4"}:{issued:"Issued",reserved:"Reserved",redeemed:"Used",expired:"Expired",revoked:"Revoked",unknown:"Status unconfirmed"},re=g.createElement("div");re.style.cssText=J.historyRecords;for(let T of[...C.review.coupons.map((E,i)=>`${_?"\u4F18\u60E0\u5238":"Coupon"} ${i+1}: ${ce[E.status]}`),...C.review.purchases.map((E,i)=>`${_?"\u8D2D\u4E70":"Purchase"} ${i+1}: ${Dn(E.status,_)}`)]){let E=g.createElement("p");E.textContent=T,E.style.margin="0",re.append(E)}re.childElementCount&&H.append(re),C.review.page||R?.present(h),n.client.view&&await n.enqueue(n.client.view)}catch(M){if(F!==S||n.stopped)return;R?.finish("error",M),s?.destroy(),s=null,e.replaceChildren(),n.fail(M)}}async function k(){if(!D||n.stopped||!n.client.review)return;let d=++S;u?.finish("dismissed");try{if(await n.client.review(),n.stopped||d!==S)return;D=!1,S++,u?.finish("dismissed"),s?.destroy(),s=null,e.replaceChildren(),e.hidden=!0,w.hidden=!1;let O=n.client.view;A(O)!==v?(q.set(v,structuredClone(n.answers)),n.resetScreen()):(q.delete(v),n.suspend(!1)),O&&await n.enqueue(O)}catch(O){if(d!==S||n.stopped)return;s?.destroy(),s=null,e.replaceChildren(),n.fail(O)}}return{get active(){return D},get receipt(){return a},open:V,exit:k,get drafts(){return new Map([...q].map(([d,O])=>[d,structuredClone(O)]))},stop(){D=!1,S++,u?.finish("dismissed"),s?.destroy(),s=null,e.replaceChildren(),e.hidden=!0,w.hidden=!1}}}function Mn(n){if(!n.client.pageExperiments)throw new Error("The Run controller does not support page experiments");let g=n.client.pageExperiments.bind(n.client),w=!1,e=!1,p=0,D=!1,a=!1,S="",s=()=>{let h=n.client.view;return JSON.stringify([h?.id,h?.source.versionId,h?.visit,h?.revision,h?.status,h?.stopped])},v=new Map,u=new Set,q={},A=new Map,V=Sn(n.appManifestRelease),k=()=>{for(let h of v.values())h.effect.revert();v.clear()},d=()=>{k();for(let h of A.values())h();A.clear()};function O(h){if(w||u.has(h))return;u.add(h);let _=p;g(n.appManifestRelease,[h]).catch(J=>{u.delete(h),!w&&_===p&&le(n.onError,J)})}async function F(){if(w)return;S=s();let h=n.client.view;if(!h||h.stopped||!["running","waiting"].includes(h.status)){p++,d();return}if(document.visibilityState==="hidden")return;if(D){a=!0;return}D=!0;let _=++p,J=`${h.id}:${h.visit}:${h.revision}`,z=location.href;try{let[L,{applyVisualVariation:de}]=await Promise.all([g(n.appManifestRelease),import("./visual-dom-6DCUZGPB.js")]),Y=n.client.view;if(w||_!==p||!Y||Y.stopped||!["running","waiting"].includes(Y.status)||`${Y.id}:${Y.visit}:${Y.revision}`!==J||location.href!==z)return;let ce=new Set,re=new Set;for(let T of L.assignments){let E=`${L.payload.environmentId}:${T.experimentKey}`;if(re.add(E),A.has(E)||A.set(E,On(E,q)),!!T.inExperiment)for(let i of L.payload.experiments){if(i.key!==T.experimentKey||!mn(location.href,i.urlPatterns??[]))continue;let l=i.meta?.findIndex(G=>G.key===T.variationKey)??-1,o=i.variations[l];if(!o?.renderGuard)continue;let c=T.receiptId+":"+i.changeId,y=JSON.stringify([T.variationKey,o]);ce.add(c);let I=v.get(c);if(I?.signature===y){I.effect.applied&&O(T.receiptId);continue}v.get(c)?.effect.revert(),v.delete(c);let B=de(o,{requireUniqueTargets:!0,boundVariations:i.variations,allowJs:!1,onApplied:()=>O(T.receiptId),onError:G=>le(n.onError,G)});v.set(c,{signature:y,effect:B}),B.applied&&O(T.receiptId)}}for(let[T,E]of v)ce.has(T)||(E.effect.revert(),v.delete(T));for(let[T,E]of A)re.has(T)||(E(),A.delete(T))}catch(L){_===p&&d(),!w&&_===p&&le(n.onError,L)}finally{D=!1,a&&!w&&(a=!1,F())}}let R=n.client.subscribe(()=>{if(s()===S)return;S=s(),p++;let h=n.client.view;(!h||h.stopped||!["running","waiting"].includes(h.status))&&d(),e&&F()}),M=Tn(()=>{p++,d(),e&&F()}),C=()=>{p++,k()};document.addEventListener("visibilitychange",C);let H=We({document,run:async()=>{e&&await F()},delay:()=>e&&!w?15e3:void 0});return{async start(){e||w||(e=!0,await H.refresh())},refresh:F,destroy(){w=!0,p++,H.destroy(),document.removeEventListener("visibilitychange",C),R(),M(),d(),V.destroy()}}}var sn=5e3;async function zn(n,g,w){let e=g,[{mountScreenPreview:p},{showPaywall:D}]=await Promise.all([import("./screen-renderer-NHLIJDCW.js"),import("./paywall-RQ66UZLW.js")]),a=e.client.identitySignal;e.signal?.throwIfAborted(),a?.throwIfAborted();let S=e.appManifestRelease?Mn({client:e.client,appManifestRelease:e.appManifestRelease,onError:e.onError}):void 0;S?.start();let s=n.ownerDocument,v=qn(s),u=s.createElement("section"),q=s.createElement("div"),A=s.createElement("div"),V=s.createElement("div"),k=s.createElement("button");V.hidden=!0,k.type="button";let d=s.createElement("p"),O=s.createElement("p"),F=s.createElement("button"),R=s.createElement("button"),M=s.createElement("button"),C=s.createElement("dialog"),H;u.dataset.indianaFunnel="",u.setAttribute("aria-busy","false"),d.setAttribute("role","status"),O.setAttribute("role","alert"),O.hidden=!0,F.type=R.type=M.type="button",A.append(F,k,d,O,M,R),u.append(q,V,A),n.append(u);let h=kn,_=rn(h),J="",z=(s.documentElement.lang||"").startsWith("zh"),L,de="",Y;for(let t of[F,k,M,R])_e(t,()=>_.focus);function ce(){let t=z?"\u5173\u95ED":"Close";R.parentElement===C?(R.textContent="\xD7",R.setAttribute("aria-label",t),Rn(R,h)):(R.textContent=t,R.removeAttribute("aria-label"),R.style.cssText=_.link+";margin-inline-start:auto")}function re(t){let r=t?.screen?.content.document.theme??h,f=JSON.stringify([r.primary,r.background,r.text,r.radius,r.font,R.parentElement===C]);f!==J&&(J=f,h=r,_=rn(h,R.parentElement===C),u.style.cssText=_.root+";min-width:0",A.style.cssText=_.bar,F.style.cssText=k.style.cssText=_.secondary,M.style.cssText=_.primary,d.style.cssText=_.status,O.style.cssText=_.alert,ce(),on(F))}function T(){A.hidden=F.hidden&&k.hidden&&M.hidden&&O.hidden&&!d.textContent&&(R.hidden||R.parentElement!==A),L?.responsive&&Y!==void 0&&L.setContentHeight(Y+A.getBoundingClientRect().height)}re();let E=null,i=null,l=null,o="",c="",y=!1,I="",B="",G="",b=!1,$=0,Re=!1,Ee="",Ke=null,Ye=Promise.resolve(),an=!e.client.view,W=w,qe,Oe,Le="",Ve,pe=!1,Ie=null,ye=!1,Me=()=>e.client.pendingCommand?.operation==="close",se=null,K=null,ln=We({document:s,run:async()=>{(!i?.observing||e.client.pendingCommand)&&await Ze()},delay:()=>{if(!(b||!l||!["running","waiting"].includes(l.status)&&!e.client.pendingCommand)&&!(i?.observing&&!e.client.pendingCommand))return l.pendingRequest||e.client.pendingCommand?1500:sn},hiddenDelay:()=>!b&&e.client.pendingCommand?15e3:void 0}),X=null;function Xe(){return K&&e.client.hasDurableJournal===!0&&X?.acknowledged===!0&&X.operationId===K.operationId&&e.client.view?.id===X.runId&&e.client.view?.status==="closed"&&e.client.view.revision===X.revision+1&&!(e.client.pendingCommands?.length??(e.client.pendingCommand?1:0))&&!e.client.pendingPurchase?K:null}function un(t){let r=t.run.paywall;if(X&&t.settlement?.requestId===X.requestId&&t.settlement.state==="settled"&&t.settlement.operationId===null&&t.run.id===X.runId&&t.run.status==="closed"&&!t.run.pendingRequest&&t.run.revision===X.revision+1&&t.run.nodeId===X.nodeId&&t.run.visit===X.visit&&r?.receiptId===X.receiptId&&r.selectionGeneration===X.selectionGeneration&&(r.quote?.operationId??null)===X.operationId&&(r.operation?.operationId??r.quote?.operationId??null)===X.operationId){let f=X.operationId===null&&r.selectionGeneration===0&&!r.quote&&!r.operation&&!r.purchaseRequestId,ne=ze({quote:r.quote,operation:r.operation,requestId:r.purchaseRequestId,pending:!1,destroyed:!1,canReselect:r.canReselect});(f||r.canReselect===!0&&ne.type==="native")&&(X.acknowledged=!0)}}let ke=null,He=new Set,fe={},Fe=!1,ue=(t,r=null)=>{b||(ke=r,Fe=!1,O.textContent=Fn(t,z),O.hidden=!1,M.hidden=e.client.pendingCommand===null,T(),le(e.onError,t))};function be(){let t=e.client.view;if(!t)throw new P("INVALID_REQUEST","No current Run is available");return{requestId:crypto.randomUUID(),nodeId:t.nodeId,visit:t.visit,revision:t.revision}}let U=Vn({client:e.client,doc:s,holder:q,reviewHolder:V,mountScreenPreview:p,loadingOptions:e,get chrome(){return _},get stopped(){return b},get answers(){return fe},suspend(t){i?.setSuspended(t)},resetScreen(){o="",c="",I=""},enqueue:me,fail:ue}),$e=_n({client:e.client,expected:be,fail:ue,get stopped(){return b},get reviewing(){return U.active},get key(){return o},get busy(){return $},get staleRead(){return Ke}}),Ue=Ln({client:e.client,expected:be,perform:Se,onIntent:e.onCustomerDataIntent,get stopped(){return b},get busy(){return $},get document(){return E?.document},get answers(){return fe}}),xe=t=>`${t.id}:${t.nodeId}:${t.visit}`,De=t=>t&&(t.screen||t.paywall)?xe(t):"";function Ce(){let t=e.client.view;F.disabled=!U.active&&($>0||!!e.client.pendingCommand||!t?.canBack||t.stopped||!["running","waiting"].includes(t.status)||!De(t)||c!==De(t)),F.hidden=!U.active&&!t?.canBack,on(F);let r=!!i&&!U.active;R.hidden=r&&!W?.active,k.hidden=!e.client.review||r&&!t?.canBack,r&&(d.textContent=""),T()}async function dn(t){if(!t)return;let r=e.client.view;await t;let f=e.client.view;if(!r||!f||f.id!==r.id||f.nodeId!==r.nodeId||f.visit!==r.visit||f.stopped||!["running","waiting"].includes(f.status))throw new P("PRECONDITION_FAILED","The screen changed while its display was acknowledged")}async function Se(t,r=!1){if(!(($||ye||se||K)&&!r||b||U.active&&!r)){$++,u.setAttribute("aria-busy","true"),O.hidden=!0,ke=null,Fe=!1,Ce();try{if(r||await dn($e.inFlight),b)return;let f=await t();b||await me(e.client.view??f.run)}catch(f){ue(f,e.client.pendingCommand?.requestId??null)}finally{$=Math.max(0,$-1),u.setAttribute("aria-busy",String($>0)),b||(M.hidden=e.client.pendingCommand===null,Ce())}}}function Ne(){ln.schedule()}async function Ze(){if(!(b||Re||$)){if(U.active){await U.open(U.receipt);return}Re=!0;try{let t=e.client.pendingCommand;t&&e.client.settle&&await e.client.settle(t.requestId);let r=e.client.view,f=Ue.queries,ne=await e.client.get(r?.screen&&Object.keys(f).length?{nodeId:r.nodeId,visit:r.visit,revision:r.revision,components:f}:void 0);Fe&&!b&&(Fe=!1,O.hidden=!0,T()),!b&&f===Ue.queries&&await me(e.client.view??ne.run)}catch(t){ue(t),Fe=!b}finally{Re=!1}}}function Ge(t,r){if(W?.active){let ne=W;return ne.setDismissHandler(()=>cn(ne)),ne}let f=Be(n,e,"funnel",()=>cn(f));return W=f,f.start(t,r),f}function cn(t){b||pe||(pe=!0,t.finish("dismissed"),ve(),u.hidden=!0,e.client.view?Pe().finally(ae):ae())}function en(){clearTimeout(Ve?.timeout),Ve=void 0}function ve(){en(),qe?.abort(),qe=void 0,E?.destroy(),E=null,i?.destroy(),i=null,Oe?.(),Oe=void 0,C.open&&C.close(),q.replaceChildren(),q.style.cssText="",Y=void 0,o="",c="",y=!1,I="",G=""}function pn(){let t=s.defaultView;L?.responsive&&t&&E?.resizeViewport?.(t.innerHeight,t.innerWidth)}function nn(){L?.destroy(),L=void 0,de=""}function tn(t){let r=t.screen?.presentation;if(!r||r.type==="inline"){C.open&&C.close(),nn(),R.parentElement!==A&&A.append(R),u.parentElement!==n&&n.append(u),re(t),T();return}u.parentElement!==C&&(C.append(R,u),n.append(C)),re(t);let f=t.screen.content.document,ne=JSON.stringify([r,J]);if(ne!==de){nn(),de=ne;let ge={sm:420,md:640,lg:900},we="size"in r&&!r.backdrop?",0 0 0 100vmax #16142566":"";C.style.cssText=`box-sizing:border-box;padding:0;border:0;overflow:auto;background:${h.background};color:${h.text};`+(r.type==="fullscreen"?"width:100vw;height:100dvh;max-width:100vw;max-height:100dvh;margin:0;border-radius:0":`width:${ge[r.size]}px;max-width:calc(100vw - 32px);max-height:calc(100dvh - 32px);box-shadow:0 24px 80px #0003${we};`+(r.type==="sheet"?"margin:auto auto 0;border-radius:14px 14px 0 0":"border-radius:14px")),L=Cn(C,{presentation:r,theme:f.theme,pages:f.pages},pn),L.latch()}T(),C.setAttribute("aria-label",(H?.screen===t.screen?.content.document.name?H?.label:void 0)??E?.document?.name??t.screen?.content.document.name??"Funnel")}async function Hn(t){if(b||pe||ye&&(Me()||["running","waiting"].includes(t.status))||(l=t,ke&&e.client.pendingCommand?.requestId!==ke&&(O.hidden=!0,ke=null),z=t.locale.startsWith("zh"),k.textContent=z?"\u56DE\u770B":"History",F.textContent=U.active?z?"\u8FD4\u56DE\u5F53\u524D":"Return to current":z?"\u8FD4\u56DE":"Back",ce(),M.textContent=z?"\u91CD\u8BD5":"Retry",M.hidden=e.client.pendingCommand===null,d.textContent=t.pendingRequest?z?"\u6B63\u5728\u5904\u7406":"Processing":t.instruction?.type==="wait"?z?"\u7B49\u5F85\u4E2D":"Waiting":"",Ce(),Ee!==`${t.revision}:${t.visit}:${t.status}:${t.stopped}`&&(Ee=`${t.revision}:${t.visit}:${t.status}:${t.stopped}`,le(e.onState,structuredClone(t))),b||pe))return;if((!t.pendingRequest||ye&&t.status==="closed")&&["closed","ineligible","failed"].includes(t.status)){ae();return}if(t.stopped||e.client.configurationReady===!1){U.stop(),ve(),W?.finish("skipped"),u.hidden=!0,Ne();return}if(u.hidden=!1,U.active){Ne();return}let r=De(t),f=e.client.view;if(f&&f.revision>t.revision&&De(f)!==r)return;let ne=!t.instruction&&!t.pendingRequest&&t.nodeType==="screen"&&["running","waiting"].includes(t.status);r!==o&&(o&&W?.finish("dismissed"),ve(),o=r,fe={...t.answers},Ue.reset());let ge=xe(t);if(Le===ge){u.hidden=!0;return}if(ne&&!r){u.hidden=!0;let Q=Ge(!0,t.locale);!b&&!pe&&Ve?.key!==ge&&(en(),Ve={key:ge,timeout:setTimeout(()=>{let m=e.client.view;if(!Q.active||!m||xe(m)!==ge)return;Le=ge;let j=new Error("Funnel screen preparation timed out");Q.finish("error",j),ve(),ue(j)},Ae)}),Ne();return}en();let Z=Q=>{let m=e.client.view;return!b&&!pe&&!Ie&&!Q.aborted&&e.client.configurationReady!==!1&&!!m&&!m.stopped&&!["closed","ineligible","failed"].includes(m.status)&&De(m)===r},we=(Q,m)=>{Z(m)&&(Le=r,W?.finish("error",Q),ve(),u.hidden=!0,ue(Q))};if(r||(tn(t),t.instruction?.type!=="event"&&t.instruction?.type!=="open_url"&&W?.finish("skipped")),t.screen){let Q=t.screen.content;if(!E){let te=t.screen.presentation.type!=="inline",oe=Ge(te,t.locale);if(b||pe)return;let ie=(qe=new AbortController).signal;tn(t),Oe=te?En(C):je(u,n),E=p(q,{mode:"live",rendererUrl:e.client.webViewUrl,title:Q.document.name,...te?{hostPresentation:()=>L?.type??t.screen.presentation.type}:{},onResize:ee=>{Y=ee,L?.responsive&&L.setContentHeight(ee+A.getBoundingClientRect().height)},onAction(ee,he={},Gn={}){if(U.active||!Z(ie)||c!==r)return;fe={...fe,...Gn};let Jn=Object.fromEntries((t.screen?.inputs??[]).filter(({variable:Je})=>Object.hasOwn(fe,Je)).map(({variable:Je})=>[Je,fe[Je]]));Se(()=>e.client.submit({operation:"submit",...be(),input:{type:"screen",output:ee,answers:Jn,selection:he}}))},onAnswers:ee=>{U.active||!Z(ie)||c!==r||(fe={...fe,...ee})},onCustomerDataIntent:ee=>{U.active||!Z(ie)||c!==r||Ue.intent(ee).catch(ue)},onEscape:()=>{!Z(ie)||c!==r||U.active||se||K||Pe()},onError:ee=>{let he=new Error(ee);c===r?ue(he):we(he,ie)},onRendered:ee=>{if(!(!Z(ie)||c===r))try{oe.present(he=>{Oe?.(),Oe=void 0,ee&&(H={screen:Q.document.name,label:ee},C.setAttribute("aria-label",ee)),te&&(C.showModal(),L?.responsive&&C.focus({preventScroll:!0}),!he&&e.loading!=="host"&&Pn(C,L?.type??t.screen.presentation.type,L?.responsive)),c=r,y=te,Ce()}),Z(ie)&&$e.report(r)}catch(he){we(he,ie)}}}),pn()}let m={capabilities:t.screen.capabilities,customerData:t.screen.customerData,parameters:t.parameters,serverInput:{bindings:t.screen.inputs,answers:fe,values:t.screen.values}},j=JSON.stringify([Q,t.locale,m.parameters,t.screen.inputs,t.screen.values]);if(j!==I)E.update(Q.document,t.locale,m),I=j,B=JSON.stringify(m.capabilities),G=JSON.stringify(m.customerData);else{let te=JSON.stringify(m.capabilities);te!==B&&(E.updateCapabilities(m.capabilities),B=te),JSON.stringify(m.customerData)!==G&&(E.updateCustomerData(m.customerData),G=JSON.stringify(m.customerData))}let x=E;if(x)try{await(W?.wait(x.ready)??x.ready)}catch(te){qe&&we(te,qe.signal)}}else if(t.paywall&&!i){let Q=Ge(!0,t.locale);if(b||pe)return;let m=(qe=new AbortController).signal;tn(t);let j=await D(q,{loading:"host",signal:m,canInteract:()=>Z(m)&&!U.active&&!se&&!K,beforeAction:async()=>{$++;try{await dn($e.settled()),O.hidden=!0,ke=null,Fe=!1,T()}finally{$=Math.max(0,$-1)}},start:()=>An(e.client),onObservationChange:Ne,onPurchase:e.onPurchase,onCheckoutUrl:e.onCheckoutUrl,checkoutNavigation:e.checkoutNavigation,confirmOnHostedCheckout:e.confirmOnHostedCheckout,resolveOfferId:e.resolveOfferId,onEvent:e.onEvent,onOpenUrl:x=>e.onOpenUrl?e.onOpenUrl({receiptId:t.paywall.receiptId,url:x,openIn:"same_window"}):s.defaultView?.location.assign(x),onAction:async x=>{if(U.active)return;let te=await e.client.submit({operation:"submit",requestId:crypto.randomUUID(),nodeId:t.nodeId,visit:t.visit,revision:e.client.view?.revision??t.revision,input:{type:"screen",output:x,answers:{}}});await me(e.client.view??te.run)},onError:x=>{c===r?ue(x):we(x,m)}},{quoteError:x=>le(e.onError,x),present(x){Z(m)&&(Q.present(()=>{x(),c=r,y=!!q.querySelector("dialog[open]"),Ce()}),Z(m)&&$e.report(r))},async dismiss(){b||m.aborted||U.active||se||K||!ye&&!Z(m)||(ye=!0,await Pe())}}).catch(x=>(we(x,m),null));!Z(m)&&!(ye&&!b&&!m.aborted)?j?.host?.destroy():j&&(i=j.host,i?.setSuspended(U.active))}if(b||pe)return;Ce();let N=t.instruction;if(N&&(N.type==="open_url"||N.type==="event")&&!He.has(N.receiptId)){let Q=s.createElement("button");Q.type="button",Q.style.cssText=_.primary,_e(Q,()=>_.focus),q.style.cssText=_.stage,Q.textContent=N.type==="open_url"?`${z?"\u524D\u5F80":"Continue to"} ${new URL(N.url).host}`:z?"\u7EE7\u7EED":"Continue",Q.onclick=()=>{let m=be(),j=N.type==="open_url"&&!e.onOpenUrl&&N.openIn==="new_window"?$n(N.url):null;Se(async()=>{let x="success";if(N.type==="open_url")if(e.onOpenUrl)try{x=await e.onOpenUrl({receiptId:N.receiptId,url:N.url,openIn:N.openIn})===!1?"failed":"opened"}catch(oe){le(e.onError,oe),x="failed"}else x=N.openIn==="new_window"&&!j?"failed":"opened";if(N.type==="event"){if(!e.onEvent)throw new P("EVENT_HANDLER_REQUIRED","Provide the event handler");await e.onEvent(N.event)}if(b||e.client.view?.nodeId!==m.nodeId||e.client.view.visit!==m.visit)throw new P("PRECONDITION_FAILED","The client action visit changed");let te=await e.client.submit({operation:"submit",...m,input:{type:"client_action",receiptId:N.receiptId,outcome:x}});return He.add(N.receiptId),N.type==="open_url"&&!e.onOpenUrl&&N.openIn==="same_window"&&s.defaultView?.location.assign(N.url),te})},W?.active?W.present(()=>q.replaceChildren(Q)):q.replaceChildren(Q)}!t.pendingRequest&&t.status==="completed"&&!He.has(`complete:${t.id}`)&&(He.add(`complete:${t.id}`),le(e.onComplete,structuredClone(t))),Ne()}function $n(t){let r=s.defaultView?.open(t,"_blank")??null;return r&&(r.opener=null),r}function me(t){return Ce(),Ye=Ye.catch(()=>{}).then(async()=>{try{await Hn(t)}catch(r){throw W?.active&&(Le=xe(t),W.finish("error",r),ve(),u.hidden=!0),r}}),Ye}let Un=e.client.subscribe(t=>{if(!an){if(t.stopped&&y&&!ye){l=t,ae();return}!ye&&(t.stopped||e.client.configurationReady===!1||o&&c!==o&&(De(t)!==o||["closed","ineligible","failed"].includes(t.status)))&&(ve(),W?.finish("dismissed"),u.hidden=!0),me(t).catch(ue)}}),xn=e.client.subscribeError?.(ue);function Pe(t){if(Ie)return Ie;if(b||!t&&(se||K))return Promise.resolve();let r=!t&&Me();return!r&&e.client.view&&!["running","waiting"].includes(e.client.view.status)?(l=e.client.view,ae(),Promise.resolve()):(Ie=Se(async()=>{let f=r?await e.client.retry():await e.client.submit({operation:"close",...t??be()});return t&&un(f),f},!0).then(()=>{let f=e.client.view;f?.status==="closed"&&!Me()&&(l=f,ae())}).finally(()=>{Ie=null}),Ie)}function ae(){S?.destroy(),!b&&(b=!0,e.signal?.removeEventListener("abort",ae),a?.removeEventListener("abort",ae),W?.finish("dismissed"),ln.destroy(),Un(),xn?.(),ve(),nn(),U.stop(),C.remove(),u.remove(),v(),le(e.onDismiss,l?structuredClone(l):null))}F.onclick=()=>{if(!F.disabled){if(U.active){U.exit();return}Se(()=>e.client.submit({operation:"back",...be()}))}},k.onclick=()=>{U.open()},R.onclick=()=>{W?.active?W.dismiss():se||Pe()},M.onclick=()=>{Me()?Pe():Se(()=>e.client.retry())},C.addEventListener("cancel",t=>{t.preventDefault(),W?.active?W.dismiss():se||Pe()}),e.signal?.addEventListener("abort",ae,{once:!0}),a?.addEventListener("abort",ae,{once:!0});try{let t=e.client.view;if(t)((e.client.viewAgeMs??sn)>=sn||t.instruction?.type==="evaluate_segment")&&(Ke=Ze().finally(()=>{Ke=null})),await me(t);else{u.hidden=!0;let r=Ge(e.client.view?.screen?.presentation.type!=="inline",e.client.view?.locale);if(b||pe)throw new DOMException("Presentation cancelled","AbortError");let f=await r.wait(e.client.get(),Ae);an=!1,await me(e.client.view??f.run)}}catch(t){throw W?.finish("error",t),ae(),t}return{destroy:ae,refresh:Ze,get recovery(){let t=Xe();if(t)return t;if(!b&&!$&&!ye&&!se&&i){let r=i.recovery;if(r.type!=="native")return r}return{type:"recover",operationId:e.client.pendingPurchase?.operationId??e.client.view?.paywall?.quote?.operationId??K?.operationId??null,requestId:e.client.pendingCommand?.requestId??null}},prepareFallback(){if(se)return se;let t=Xe();if(t)return Promise.resolve(t);let r=e.client.pendingPurchase?.operationId??e.client.view?.paywall?.quote?.operationId??K?.operationId??null,f=()=>({type:"recover",operationId:r,requestId:e.client.pendingCommand?.requestId??null});if(e.client.hasDurableJournal!==!0){let N=i?.recovery;return Promise.resolve(N&&N.type!=="native"&&N.type!=="cancel"?N:f())}let ne=(e.client.pendingCommands??(e.client.pendingCommand?[e.client.pendingCommand]:[])).some(N=>N.operation==="close");if(b&&!(ne||K&&e.client.view?.status==="closed")||$||Re||Ie||U.active||!i&&!K&&!ne)return Promise.resolve(f());let ge=i,Z=(async()=>{try{if(!K&&ne){let m=await e.client.retry();return await me(e.client.view??m.run),f()}if(!K){let m=await ge.prepareFallback();if(m.type!=="native")return m;if(e.client.hasDurableJournal!==!0)return f();K=m}let N=e.client.pendingCommands??(e.client.pendingCommand?[e.client.pendingCommand]:[]);if(N.length){let m=N.find(x=>x.operation==="close");if(!m||!X||m.requestId!==X.requestId)return f();let j=await e.client.retry();un(j),await me(e.client.view??j.run)}else{let m=e.client.view,j=m?.paywall;if(!m||!j||j.selectionGeneration===void 0||(j.quote?.operationId??null)!==K.operationId||K.operationId!==null&&j.canReselect!==!0)return f();let x=j.selectionGeneration,te=await e.client.get();await me(e.client.view??te.run);let oe=e.client.view,ie=oe?.paywall;if(!oe||!ie||!["running","waiting"].includes(oe.status)||oe.stopped||oe.id!==m.id||oe.nodeId!==m.nodeId||oe.visit!==m.visit||ie.receiptId!==j.receiptId||ie.selectionGeneration!==x||(ie.quote?.operationId??null)!==K.operationId||K.operationId!==null&&ie.canReselect!==!0||e.client.pendingPurchase||(e.client.pendingCommands?.length??(e.client.pendingCommand?1:0)))return f();let ee=be();X={runId:oe.id,operationId:K.operationId,revision:ee.revision,requestId:ee.requestId,nodeId:oe.nodeId,visit:oe.visit,receiptId:ie.receiptId,selectionGeneration:x,acknowledged:!1},await Pe(ee)}let Q=Xe();return Q?(ae(),Q):f()}catch(N){return ue(N),f()}})();se=Z;let we=()=>{se===Z&&(se=null)};return Z.then(we,we),Z},review:U.open,exitReview:U.exit,get unappliedDrafts(){return U.drafts}}}function Vt(n,g,w){return zn(n,g,w)}export{Bn as a,Mn as b,zn as c,Vt as d};
@@ -1 +1 @@
1
- import{h as p,i as d}from"./chunk-ITVSLSRM.js";import{I as a,L as u,O as m}from"./chunk-WRUW2UIJ.js";import{b as e}from"./chunk-ZY4XAKNQ.js";var s=e.enum(["page","popup","banner"]),y=3e5,f=e.strictObject({type:e.enum(["string","number","boolean","strings","json"]),nullable:e.boolean()}),h=e.strictObject({inputs:e.record(a,f.extend({required:e.boolean()})).refine(t=>Object.keys(t).length<=40,"Too many content inputs"),outputs:e.record(a,f).refine(t=>Object.keys(t).length<=40,"Too many content outputs")}),g=e.strictObject({kind:s,schemaVersion:e.literal(1),name:e.string().trim().min(1).max(80),screen:u,contract:h}),c=g.superRefine((t,r)=>{let n=(o,b)=>r.addIssue({code:"custom",message:o,path:b});t.screen.surface!==t.kind&&n("Content surface must match its domain",["screen","surface"]),t.screen.name!==t.name&&n("Content has one editable name",["screen","name"]),t.kind==="banner"&&t.screen.presentation.type!=="inline"&&n("Banner requires an inline container",["screen","presentation"]),t.kind!=="banner"&&t.screen.presentation.type==="inline"&&n("Inline presentation belongs to Banner",["screen","presentation"]),t.screen.actions.some(o=>o.type!=="event"&&o.type!=="navigate")&&n("Content actions must emit host intents or navigate locally",["screen","actions"]);let i=new Set(t.screen.actions.filter(o=>o.type==="event").map(o=>o.id));(Object.keys(t.contract.outputs).some(o=>!i.has(o))||[...i].some(o=>!Object.hasOwn(t.contract.outputs,o)))&&n("Every event needs exactly one output declaration",["contract","outputs"]),d(t)>y&&n("Content document exceeds its byte budget",[])});function S(t,r){if(t===null)return r.nullable;switch(r.type){case"json":return!0;case"string":return typeof t=="string";case"number":return typeof t=="number"&&Number.isFinite(t);case"boolean":return typeof t=="boolean";case"strings":return Array.isArray(t)&&t.every(n=>typeof n=="string")}}var x=c.superRefine((t,r)=>{for(let n of p(t.screen))Object.keys(t.contract.inputs).some(i=>n===i||n.startsWith(i+"."))||r.addIssue({code:"custom",path:["contract","inputs"],message:"Declare every reusable input read"});for(let n of t.screen.actions){if(n.type!=="event")continue;let i=t.contract.outputs[n.id],o=Object.hasOwn(n.properties,"value")?n.properties.value:n.properties;i&&!S(o,i)&&r.addIssue({code:"custom",path:["contract","outputs",n.id],message:"Action value differs from its declared type"})}m(t.screen).some(n=>!n.complete)&&r.addIssue({code:"custom",path:["screen","strings"],message:"Content needs complete localized copy"})}),l=e.strictObject({id:e.uuid(),kind:s,projectId:e.uuid(),environmentId:e.uuid(),name:e.string(),revision:e.number().int().nonnegative(),status:e.enum(["draft","published","archived"]),publishedVersionId:e.uuid().nullable(),createdAt:e.iso.datetime({offset:!0}),updatedAt:e.iso.datetime({offset:!0})}),D=l.extend({draft:c}),I=e.strictObject({rows:e.array(l).max(200),nextCursor:e.uuid().nullable()}),v=e.strictObject({id:e.uuid(),kind:s,resourceId:e.uuid(),projectId:e.uuid(),environmentId:e.uuid(),version:e.number().int().positive(),sourceRevision:e.number().int().nonnegative(),document:x,createdAt:e.iso.datetime({offset:!0})}),z=v.omit({document:!0}),V=e.discriminatedUnion("action",[e.strictObject({action:e.literal("create"),kind:s,id:e.uuid(),document:c}),e.strictObject({action:e.literal("save"),kind:s,id:e.uuid(),revision:e.number().int().nonnegative(),document:c}),e.strictObject({action:e.enum(["publish","archive"]),kind:s,id:e.uuid(),revision:e.number().int().nonnegative()})]).superRefine((t,r)=>{"document"in t&&t.document.kind!==t.kind&&r.addIssue({code:"custom",path:["document","kind"],message:"Content cannot change domain"})});export{s as a,v as b};
1
+ import{h as p,i as d}from"./chunk-R23IGK5U.js";import{I as a,L as u,O as m}from"./chunk-N7YXDSQL.js";import{b as e}from"./chunk-VF6QMMEA.js";var s=e.enum(["page","popup","banner"]),y=3e5,f=e.strictObject({type:e.enum(["string","number","boolean","strings","json"]),nullable:e.boolean()}),h=e.strictObject({inputs:e.record(a,f.extend({required:e.boolean()})).refine(t=>Object.keys(t).length<=40,"Too many content inputs"),outputs:e.record(a,f).refine(t=>Object.keys(t).length<=40,"Too many content outputs")}),g=e.strictObject({kind:s,schemaVersion:e.literal(1),name:e.string().trim().min(1).max(80),screen:u,contract:h}),c=g.superRefine((t,r)=>{let n=(o,b)=>r.addIssue({code:"custom",message:o,path:b});t.screen.surface!==t.kind&&n("Content surface must match its domain",["screen","surface"]),t.screen.name!==t.name&&n("Content has one editable name",["screen","name"]),t.kind==="banner"&&t.screen.presentation.type!=="inline"&&n("Banner requires an inline container",["screen","presentation"]),t.kind!=="banner"&&t.screen.presentation.type==="inline"&&n("Inline presentation belongs to Banner",["screen","presentation"]),t.screen.actions.some(o=>o.type!=="event"&&o.type!=="navigate")&&n("Content actions must emit host intents or navigate locally",["screen","actions"]);let i=new Set(t.screen.actions.filter(o=>o.type==="event").map(o=>o.id));(Object.keys(t.contract.outputs).some(o=>!i.has(o))||[...i].some(o=>!Object.hasOwn(t.contract.outputs,o)))&&n("Every event needs exactly one output declaration",["contract","outputs"]),d(t)>y&&n("Content document exceeds its byte budget",[])});function S(t,r){if(t===null)return r.nullable;switch(r.type){case"json":return!0;case"string":return typeof t=="string";case"number":return typeof t=="number"&&Number.isFinite(t);case"boolean":return typeof t=="boolean";case"strings":return Array.isArray(t)&&t.every(n=>typeof n=="string")}}var x=c.superRefine((t,r)=>{for(let n of p(t.screen))Object.keys(t.contract.inputs).some(i=>n===i||n.startsWith(i+"."))||r.addIssue({code:"custom",path:["contract","inputs"],message:"Declare every reusable input read"});for(let n of t.screen.actions){if(n.type!=="event")continue;let i=t.contract.outputs[n.id],o=Object.hasOwn(n.properties,"value")?n.properties.value:n.properties;i&&!S(o,i)&&r.addIssue({code:"custom",path:["contract","outputs",n.id],message:"Action value differs from its declared type"})}m(t.screen).some(n=>!n.complete)&&r.addIssue({code:"custom",path:["screen","strings"],message:"Content needs complete localized copy"})}),l=e.strictObject({id:e.uuid(),kind:s,projectId:e.uuid(),environmentId:e.uuid(),name:e.string(),revision:e.number().int().nonnegative(),status:e.enum(["draft","published","archived"]),publishedVersionId:e.uuid().nullable(),createdAt:e.iso.datetime({offset:!0}),updatedAt:e.iso.datetime({offset:!0})}),D=l.extend({draft:c}),I=e.strictObject({rows:e.array(l).max(200),nextCursor:e.uuid().nullable()}),v=e.strictObject({id:e.uuid(),kind:s,resourceId:e.uuid(),projectId:e.uuid(),environmentId:e.uuid(),version:e.number().int().positive(),sourceRevision:e.number().int().nonnegative(),document:x,createdAt:e.iso.datetime({offset:!0})}),z=v.omit({document:!0}),V=e.discriminatedUnion("action",[e.strictObject({action:e.literal("create"),kind:s,id:e.uuid(),document:c}),e.strictObject({action:e.literal("save"),kind:s,id:e.uuid(),revision:e.number().int().nonnegative(),document:c}),e.strictObject({action:e.enum(["publish","archive"]),kind:s,id:e.uuid(),revision:e.number().int().nonnegative()})]).superRefine((t,r)=>{"document"in t&&t.document.kind!==t.kind&&r.addIssue({code:"custom",path:["document","kind"],message:"Content cannot change domain"})});export{s as a,v as b};