@tinkerlandai/longplay-sdk 0.10.86 → 0.10.87
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.
- package/CHANGELOG.md +4 -0
- package/dist/{chunk-PAKL7S5P.js → chunk-2OSK33BH.js} +1 -1
- package/dist/{chunk-WG53PTYZ.js → chunk-3Z4QDEFB.js} +2 -2
- package/dist/chunk-7J6YKR2G.js +1 -0
- package/dist/{chunk-R2GBEHP2.js → chunk-C5HYPVGK.js} +1 -1
- package/dist/chunk-HZP36Y7Y.js +1 -0
- package/dist/{chunk-PPMGIETB.js → chunk-IVKB6I5Y.js} +1 -1
- package/dist/{chunk-KEM6QYLF.js → chunk-KNGQEGBC.js} +1 -1
- package/dist/{chunk-LXFNDTXL.js → chunk-QF6EJUHM.js} +1 -1
- package/dist/{chunk-5U3QABVU.js → chunk-RRNE6CMG.js} +1 -1
- package/dist/{chunk-5RWAJLB3.js → chunk-UCZXFMP4.js} +1 -1
- package/dist/{chunk-XUACQGUI.js → chunk-V6NZ2HM7.js} +1 -1
- package/dist/{chunk-WMUKARGY.js → chunk-ZQXLD2OW.js} +1 -1
- package/dist/{content-2NMAKYJP.js → content-FYROIKHN.js} +1 -1
- package/dist/{funnel-host-purchase-G7K233EQ.js → funnel-host-purchase-2ESNHIY3.js} +1 -1
- package/dist/{funnel-host-recovery-paywall-TCOEU3CT.js → funnel-host-recovery-paywall-4SU6YXVQ.js} +1 -1
- package/dist/{funnel-paywall-prerender-TDBKRRPB.js → funnel-paywall-prerender-RV5HA4BG.js} +1 -1
- package/dist/{funnel-runtime-host-5LXWBUIN.js → funnel-runtime-host-RDKBIW3H.js} +1 -1
- package/dist/index.js +1 -1
- package/dist/openrouter.js +1 -1
- package/dist/page.js +1 -1
- package/dist/{paywall-U4RTF4MV.js → paywall-TMWAGLJC.js} +1 -1
- package/dist/{paywall-content-DIBAGNQG.js → paywall-content-LX3QA6EA.js} +1 -1
- package/dist/{paywall-session-G24MWXYA.js → paywall-session-2FKLMAZX.js} +1 -1
- package/dist/react-native.js +1 -1
- package/dist/server.js +1 -1
- package/dist/visual.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-HXDWW6SU.js +0 -1
- package/dist/chunk-RMELSVQL.js +0 -1
- /package/dist/{chunk-WG53PTYZ.js.LEGAL.txt → chunk-3Z4QDEFB.js.LEGAL.txt} +0 -0
package/dist/react-native.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{b as S,c as E,d as T}from"./chunk-
|
|
1
|
+
import{b as S,c as E,d as T}from"./chunk-IVKB6I5Y.js";import"./chunk-XLGNBPGF.js";import{a as A}from"./chunk-ZQXLD2OW.js";import{e as P}from"./chunk-CKMSSBJM.js";import"./chunk-FPJ3FE26.js";import{h as b,i as x,k as L}from"./chunk-C5HYPVGK.js";import{E as C}from"./chunk-2OSK33BH.js";import"./chunk-F4AIEI5N.js";import"./chunk-S2S4ROGY.js";import"./chunk-Y55OBV7D.js";import"./chunk-MOIVJERE.js";import"./chunk-2OBXRQMW.js";import"./chunk-PUDTOCQF.js";import"./chunk-UCZXFMP4.js";import"./chunk-7QPCNDIY.js";import"./chunk-BT7IC765.js";import"./chunk-ME6QTD5Y.js";import"./chunk-6XRQR43F.js";import"./chunk-3532HSBP.js";import"./chunk-67WFVDTV.js";import"./chunk-KX67ZM7H.js";import"./chunk-6VVQWTHV.js";import"./chunk-VILB5M4X.js";import"./chunk-SX7U2ONB.js";import"./chunk-KNGQEGBC.js";import"./chunk-KCUE2VFJ.js";import"./chunk-Y3W5G4BF.js";import"./chunk-FYUMVOCV.js";import"./chunk-DUS5V65Z.js";import"./chunk-BOT6ZDLK.js";import"./chunk-A5WUQLAO.js";import{a as r}from"./chunk-UGATOG2T.js";import{h as R}from"./chunk-LFR2LWYC.js";import"./chunk-3VUPVXAV.js";import"./chunk-RRNE6CMG.js";import"./chunk-5MRSFLQA.js";import"./chunk-W22ESUYY.js";import"./chunk-DSPLGTQI.js";import"./chunk-FYMVNLQN.js";import"./chunk-FRK6322O.js";import"./chunk-WOT6VMZA.js";function k(t,d){let n,a=0,m=-1,l,i=!1,y=()=>{if(i)throw new r("CLOSED","Native host was destroyed");if(!t.nativeModule)throw new r("CAPABILITY_UNAVAILABLE","Link IndianaBridge and supply nativeModule");return t.nativeModule},o=()=>new r("IDENTITY_CHANGED","Customer identity changed during the native operation"),h=d.subscribeIdentity(()=>{a++,m=-1;let e=a;n&&t.nativeModule&&n.then(c=>t.nativeModule.reset(c,e)).catch(()=>{})}),I=t.nativeEvents?.(e=>{!n||!t.nativeModule||typeof e?.requestId!="string"||(async()=>{let c=await n;if(e.instanceId!==c)return;if(e.kind==="credential"){let w=a,f=null;try{if(!i&&e.revision===w){let N=await d.access();!i&&a===w&&(f=N)}}finally{await t.nativeModule.provideCredential(c,e.requestId,f)}return}let s=!1,u=a;try{if(i||e.revision!==u||!t.onNativeAction)throw o();await t.onNativeAction(e.action),s=!i&&a===u}finally{await t.nativeModule.acknowledge(c,e.requestId,s)}})().catch(()=>{})});async function p(e,c={}){let s=y();if(d.snapshot()&&!t.nativeEvents)throw new r("CAPABILITY_UNAVAILABLE","Supply nativeEvents to share credential refresh with the native host");let u=a,w=await d.access();if(i||a!==u)throw o();if(!n){let v=s.create(JSON.stringify({baseUrl:t.baseUrl??"https://api.longplayai.com",scope:t.scope,timeout:(t.timeoutMs??15e3)/1e3,credentialEvents:!!t.nativeEvents}));n=v,v.catch(()=>{n===v&&(n=void 0)})}let f=await n;if(i||a!==u)throw o();if(m!==u){if(!l||l.epoch!==u){let O=(async()=>{if(await s.identify(f,JSON.stringify({revision:u,credentials:w})),i||a!==u)throw await s.reset(f,u),o();m=u})();l={epoch:u,task:O}}let v=l;try{await v.task}finally{l===v&&(l=void 0)}}let N=await s.invoke(f,e,JSON.stringify(c));if(i||a!==u)throw o();try{return JSON.parse(N)}catch{throw new r("INVALID_RESPONSE","Native host returned invalid JSON")}}async function g(e,c){let s=await p(e,c);if(!s||typeof s!="object"||Array.isArray(s)||s.status!=="complete"&&s.status!=="dismissed")throw new r("INVALID_RESPONSE","Native presentation returned an invalid result");return s}return{showFunnel(e){return g("showFunnel",{runToken:e})},showPaywall(e){return g("showPaywall",e)},showContent(e){return g("showContent",e)},purchaseSubscription(e,c){return p("purchaseSubscription",{operationId:e,accepted:c})},switchSubscription(e,c){return p("switchSubscription",{operationId:e,accepted:c})},restorePurchases(){return p("restorePurchases")},manageSubscriptions(e){return p("manageSubscriptions",e?{productId:e}:{})},async dismiss(){a++,m=-1,n&&await y().reset(await n,a)},async destroy(){i||(i=!0,a++,h(),I?.(),n&&t.nativeModule&&await t.nativeModule.destroy(await n))}}}var M=P.trackUsage.request.shape.command,U=P.trackUsage.response;function F(t){let d=R.parse(t.scope),n=S({...t,scope:d}),a={...t,scope:d,session:n.session},m=k(t,n.session),l=0,i=!1;n.subscribeIdentity(()=>{l++});let y=()=>{if(i)throw new r("CLOSED","SDK client was destroyed");let o=n.session.peek();if(!o)throw new r("UNAUTHENTICATED","Identify the Customer first");return o};return{...n,native:m,async destroy(){i||(i=!0,l++,n.destroy(),await m.destroy())},funnel(){return E({...a,customerToken:y()})},resumeFunnel(o){return y(),C({...a,runToken:o})},paywall(o){return A(a,{...o,customerToken:y()})},async trackUsage(o){if(y(),!t.usageReporter)throw new r("INVALID_REQUEST","Configure your authenticated backend usageReporter");let h=M.parse(o),I=l,p;try{p=await t.usageReporter(h)}catch(e){throw I!==l?new r("IDENTITY_CHANGED","Customer identity changed during usage reporting"):e}if(I!==l)throw new r("IDENTITY_CHANGED","Customer identity changed during usage reporting");let g=U.parse(p);if(g.scope.projectId!==d.projectId||g.scope.environment!==d.environment)throw new r("INVALID_RESPONSE","Usage response scope differs");return g}}}export{r as LongplayError,x as createConfigurationSync,b as createFeatureClient,T as createFunnelProcess,L as createLocalFunnelClient,F as createLongplayReactNative};
|
package/dist/server.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as pn}from"./chunk-
|
|
1
|
+
import{a as pn}from"./chunk-HZP36Y7Y.js";import{a as I}from"./chunk-EQUVI5QU.js";import{a as fn,b as hn,c as gn,d as yn}from"./chunk-Y6KA56V2.js";import{a as xt}from"./chunk-ZQXLD2OW.js";import{a as Ue,b as Ve,c as qe,d as He,e as m}from"./chunk-CKMSSBJM.js";import"./chunk-FPJ3FE26.js";import{a as Te,b as ae,c as yt,d as It,e as wt,f as xe,g as vt,h as Me,i as dn,j as ln,k as mn}from"./chunk-C5HYPVGK.js";import{B as V,C as N,d as ft,e as ht,k as gt,l as z,m as St,p as Ct,q as Rt,r as bt,s as At,t as Ot,y as pe,z as Tt}from"./chunk-2OSK33BH.js";import"./chunk-F4AIEI5N.js";import{c as h}from"./chunk-S2S4ROGY.js";import"./chunk-Y55OBV7D.js";import"./chunk-MOIVJERE.js";import"./chunk-2OBXRQMW.js";import{a as Et,b as _e}from"./chunk-PUDTOCQF.js";import"./chunk-UCZXFMP4.js";import"./chunk-7QPCNDIY.js";import{e as at}from"./chunk-BT7IC765.js";import{B as pt,C as de,D as Z,E as lt,J as mt,a as et,e as q,j as Re,k as st,l as ct,q as ut,r as dt,s as be,t as Ae}from"./chunk-ME6QTD5Y.js";import"./chunk-6XRQR43F.js";import"./chunk-3532HSBP.js";import{A as W,B as oe,C as tt,D as Se,E as ie,G as se,H as Ce,M as j,O as ce,P as nt,R as Ee,S as rt,T as ot,f as Ge,g as je,j as we,r as ze,s as Ke,u as an,v as sn,y as cn,z as X}from"./chunk-67WFVDTV.js";import{b as Oe}from"./chunk-KX67ZM7H.js";import{e as ve,i as Ze,l as it}from"./chunk-6VVQWTHV.js";import"./chunk-VILB5M4X.js";import"./chunk-SX7U2ONB.js";import"./chunk-KNGQEGBC.js";import{a as Ne,b as Le}from"./chunk-KCUE2VFJ.js";import{o as ue}from"./chunk-Y3W5G4BF.js";import"./chunk-FYUMVOCV.js";import{i as un,k as $e,l as Qe,m as Je}from"./chunk-DUS5V65Z.js";import{c as Ie}from"./chunk-BOT6ZDLK.js";import{e as Xe,h as We}from"./chunk-A5WUQLAO.js";import{a as c}from"./chunk-UGATOG2T.js";import{h as Y}from"./chunk-LFR2LWYC.js";import"./chunk-3VUPVXAV.js";import"./chunk-RRNE6CMG.js";import"./chunk-5MRSFLQA.js";import{b as u}from"./chunk-W22ESUYY.js";import"./chunk-DSPLGTQI.js";import{a as Ye}from"./chunk-FYMVNLQN.js";import"./chunk-FRK6322O.js";import"./chunk-WOT6VMZA.js";var _t=4,Mt=[...tt,"requirement_checks","native_offers","preparations","benefit_claims","authorizations","business_results","checkout_termination"],In=u.enum(Mt),ee=(e,n)=>u.array(e).max(n).refine(t=>new Set(t).size===t.length,"Declarations must be unique"),ke=u.strictObject({...se.shape,bridgeVersion:u.literal(_t),capabilities:ee(In,Mt.length),checkKinds:ee(u.enum(["access","metered","credit"]),3),preparationActions:ee(u.enum(["purchase","subscription_change","refund"]),3),authorizationKinds:ee(u.enum(["auto_topup"]),1),nextActionTypes:ee(u.enum(["redirect","authenticate"]),2),resultEvents:ee(u.enum(["benefit.claimed","authorization.updated"]),2)}).superRefine((e,n)=>{e.capabilities.includes("catalog")!==(e.catalog!=="none")&&n.addIssue({code:"custom",path:["catalog"],message:"Catalog declaration differs from its capability"}),(e.capabilities.includes("billing_records")!==e.billingEvents.length>0||new Set(e.billingEvents).size!==e.billingEvents.length)&&n.addIssue({code:"custom",path:["billingEvents"],message:"Declare unique supported billing events"});let t=r=>e.capabilities.includes(r),o=(r,a)=>n.addIssue({code:"custom",path:[r],message:a});t("requirement_checks")!==e.checkKinds.length>0&&o("checkKinds","Declare the supported Check kinds"),t("preparations")!==e.preparationActions.length>0&&o("preparationActions","Declare the supported preparation actions"),t("authorizations")!==e.authorizationKinds.length>0&&o("authorizationKinds","Declare the supported authorization kinds"),t("business_results")!==e.resultEvents.length>0&&o("resultEvents","Declare the supported non-financial results");for(let[r,a,s]of[["purchases","purchase","purchase.completed"],["subscription_changes","subscription_change","subscription.change.completed"],["refunds","refund","refund.updated"]])t(r)&&(!t("operation_status")||!t("billing_records")||!t("preparations")||!e.preparationActions.includes(a)||!e.billingEvents.includes(s))&&o("capabilities",`${r} requires preparation, original lookup and its billing result`);t("purchases")&&!e.billingEvents.includes("purchase.closed")&&o("billingEvents","Purchase execution requires its terminal closure result"),t("checkout_termination")&&(!t("operation_status")||!t("billing_records")||!e.billingEvents.includes("purchase.closed"))&&o("capabilities","Checkout termination requires original lookup and purchase.closed"),t("subscription_changes")&&!e.billingEvents.includes("subscription.change.closed")&&o("billingEvents","Subscription change execution requires its terminal closure result");for(let[r,a]of[["benefit_claims","benefit.claimed"],["authorizations","authorization.updated"]])t(r)&&(!t("operation_status")||!t("business_results")||!e.resultEvents.includes(a))&&o("capabilities",`${r} requires original lookup and its non-financial result`)}),K={"bridge.ping":u.strictObject({challenge:u.uuid()}),"bridge.describe":u.strictObject({}),"requirement.check":$e,"operation.prepare":ze,"benefit.claim":Ue,"operation.read":qe,"purchase.terminate":j},wn={"bridge.ping":u.strictObject({challenge:u.uuid()}),"bridge.describe":ke,"requirement.check":Qe,"operation.prepare":Ke,"benefit.claim":Ve,"operation.read":He,"purchase.terminate":j.extend({outcome:u.enum(["requested","already_paid"])})},Gn=u.enum(["bridge.ping","bridge.describe","requirement.check","operation.prepare","benefit.claim","operation.read","purchase.terminate"]);function $(e,n){return u.strictObject({bridgeVersion:u.literal(_t),requestId:u.uuid(),scope:Ce,command:u.literal(e),data:n})}var kt=u.discriminatedUnion("command",[$("bridge.ping",K["bridge.ping"]),$("bridge.describe",K["bridge.describe"]),$("requirement.check",K["requirement.check"]),$("operation.prepare",K["operation.prepare"]),$("benefit.claim",K["benefit.claim"]),$("operation.read",K["operation.read"]),$("purchase.terminate",K["purchase.terminate"])]),Be=u.strictObject({code:u.string().regex(/^MERCHANT_BRIDGE_[A-Z_]+$/),message:u.string().min(1).max(500),retryable:u.boolean(),recovery:u.string().min(1).max(80),effect:u.enum(["none","unknown"])}).refine(e=>e.effect!=="unknown"||!e.retryable&&e.recovery==="recover_operation","Unknown effects require original-operation recovery");function Bt(e){let n={bridgeVersion:u.literal(4),requestId:u.uuid(),scope:Ce,command:u.literal(e)};return u.union([u.strictObject({...n,data:wn[e]}),u.strictObject({...n,error:Be})])}var Pt="X-Indiana-Bridge-Signature",Q="X-Indiana-Bridge-Key-Id";function vn(e){return new TextEncoder().encode(e)}function Dt(e){return Uint8Array.from(atob(e.replaceAll("-","+").replaceAll("_","/")),n=>n.charCodeAt(0))}function Ft(e,n,t,o){return vn(`indiana-merchant-bridge:${o}
|
|
2
2
|
${n}
|
|
3
3
|
POST
|
|
4
4
|
${W}
|
package/dist/visual.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as pe,c as fe}from"./chunk-KV5MZ4NI.js";import{b as le}from"./chunk-J6KIN4RH.js";import{a as Ve,b as ce,c as de,d as ue}from"./chunk-SLUA7ABW.js";import{a as J,b as F,c as ge,e as me}from"./chunk-
|
|
1
|
+
import{a as pe,c as fe}from"./chunk-KV5MZ4NI.js";import{b as le}from"./chunk-J6KIN4RH.js";import{a as Ve,b as ce,c as de,d as ue}from"./chunk-SLUA7ABW.js";import{a as J,b as F,c as ge,e as me}from"./chunk-3Z4QDEFB.js";import{a as re,b as ae,c as se,d as oe}from"./chunk-MB2U2GWJ.js";import"./chunk-3VUPVXAV.js";import"./chunk-RRNE6CMG.js";import"./chunk-5MRSFLQA.js";import{b as o}from"./chunk-W22ESUYY.js";import"./chunk-DSPLGTQI.js";import{c as te,e as ie,g as M}from"./chunk-FYMVNLQN.js";import"./chunk-FRK6322O.js";import"./chunk-WOT6VMZA.js";var K="indiana-visual-diagnostics-v1",Ae=o.strictObject({environmentId:o.string().uuid(),release:o.string().regex(/^[a-f0-9]{64}$/).nullable(),generation:o.string().regex(/^[a-f0-9]{64}$/).nullable(),publishedGeneration:o.string().regex(/^[a-f0-9]{64}$/).nullable(),checkedAt:o.string().datetime(),origin:o.string().url(),pathname:o.string().max(2048),urlMatches:o.boolean(),stopped:o.boolean(),rows:o.array(o.strictObject({changeId:o.string().regex(/^[a-f0-9]{64}$/),experimentKey:o.string().max(256),variationKey:o.string().max(256),inExperiment:o.boolean(),fingerprint:o.string().regex(/^[a-f0-9]{64}$/),status:o.enum(["inactive","waiting","partial","applied","mismatch","no_changes","unavailable","error"]),total:o.number().int().min(0).max(600),applied:o.number().int().min(0).max(600)})).max(100)});function ye(e){let l=n=>Array.isArray(n)?"["+n.map(l).join(",")+"]":n&&typeof n=="object"?"{"+Object.entries(n).filter(([,c])=>c!==void 0).sort(([c],[y])=>c.localeCompare(y)).map(([c,y])=>JSON.stringify(c)+":"+l(y)).join(",")+"}":JSON.stringify(n);return l({css:e.css,js:e.js,domMutations:e.domMutations,...e.renderGuard?{renderGuard:e.renderGuard}:{}})}function he(e){let l=new URL(e.baseUrl),n=l.origin==="https://api.longplayai.com"||l.origin==="https://api.dev.longplayai.com"?l.hostname.slice(4):void 0,c=e.origins??(n?[`https://console.${n}`]:[]),y=new Set(c.filter(t=>{try{let i=new URL(t);return i.origin===t&&(i.protocol==="https:"||i.protocol==="http:"&&["localhost","127.0.0.1","[::1]"].includes(i.hostname))}catch{return!1}})),v=!1,I=!1,k=0,T=async t=>{if(v||I||!t.source||!y.has(t.origin)||!t.data||typeof t.data!="object")return;let i=t.data;if(!(i.channel!==K||i.type!=="inspect"||i.environmentId!==e.environmentId||typeof i.nonce!="string"||!/^[a-f0-9-]{36}$/i.test(i.nonce)||typeof i.changeId!="string"||!/^[a-f0-9]{64}$/.test(i.changeId)||typeof i.url!="string"||i.url.length>2048||Date.now()-k<250)){try{if(new URL(i.url).origin!==location.origin)return}catch{return}I=!0,k=Date.now();try{let x=await e.inspect(i.changeId,i.url);!v&&x.rows.some(S=>S.changeId===i.changeId)&&t.source.postMessage({channel:K,type:"result",nonce:i.nonce,snapshot:x},t.origin)}finally{I=!1}}},u=t=>{T(t).catch(()=>{})};return window.addEventListener("message",u),()=>{v=!0,window.removeEventListener("message",u)}}var R=e=>!!e&&typeof e=="object"&&!Array.isArray(e),E=(e,l)=>typeof e=="string"&&e.length<=l,Ee=e=>typeof e=="string"&&(["html","class","style","position","href","src","alt","title","id","role","hidden"].includes(e)||/^(aria|data)-[a-z0-9_-]+$/.test(e));function ke(e){if(!R(e)||!E(e.css??"",1e5)||!E(e.js??"",1e5)||!Array.isArray(e.domMutations??[])||Array.isArray(e.domMutations)&&e.domMutations.length>200)throw new Error("Invalid visual variation");let l=e.domMutations??[];for(let n of l)if(!R(n)||!E(n.selector,2048)||!n.selector||!Ee(n.attribute)||!["set","append","remove"].includes(String(n.action))||n.value!==void 0&&!E(n.value,5e4)||n.parentSelector!==void 0&&!E(n.parentSelector,2048)||n.insertBeforeSelector!==void 0&&!E(n.insertBeforeSelector,2048))throw new Error("Invalid visual mutation");return{css:e.css??"",js:e.js??"",domMutations:l,...e.renderGuard===void 0?{}:{renderGuard:le(e.renderGuard)}}}function q(e){if(!R(e)||typeof e.environmentId!="string"||typeof e.trackExposures!="boolean"||!/^[-a-f0-9]{36}$/i.test(e.environmentId)||typeof e.generation!="string"||!/^[a-f0-9]{64}$/.test(e.generation)||!Array.isArray(e.experiments)||e.experiments.length>100||!R(e.savedGroups))throw new Error("Invalid visual experiment payload");let l=e.experiments.map(n=>{if(!R(n)||!["key","changeId"].every(c=>typeof n[c]=="string"&&n[c])||!/^[a-f0-9]{64}$/.test(String(n.changeId))||["namespace","status","groups","url"].some(c=>Object.hasOwn(n,c))||n.hashVersion!==void 0&&n.hashVersion!==2||!Array.isArray(n.variations)||n.variations.length<2||n.variations.length>20||n.urlPatterns!==void 0&&!Array.isArray(n.urlPatterns))throw new Error("Invalid visual experiment");return{...n,variations:n.variations.map(ke)}});return{...e,experiments:l}}var ve=6e4;function qe(e){let l=se(e.baseUrl);if(e.appManifestRelease!==void 0&&!/^[a-f0-9]{64}$/.test(e.appManifestRelease))throw new Error("Invalid IAM manifest digest");if(!/^[0-9a-f-]{36}$/i.test(e.environmentId))throw new Error("Invalid App environment ID");let n=e.fetch??globalThis.fetch.bind(globalThis),c=F(n),y=F(n),v=`${l}/api/v1/visual-experiments/${e.environmentId}`,I=e.appManifestRelease?`${v}?iam=${e.appManifestRelease}`:v,k=re(e.deviceIdCookie??"indiana_did"),T=ae(),u=null,t=!1,i=!1,x="",S={...e.attributes??{}},G,B,D=0,H=-1/0,$,m=new Map,O=new Map,C=new Set,z=ge({endpoint:`${v}/events`,fetch:n,log:e.log,label:"Visual exposure"}),P=z.flush,W,b;function j(){clearTimeout(W),b?.remove(),b=void 0}function Y(s,d){let f=M(s,d);C.has(f)||e.trackExposures===!1||u?.trackExposures===!1||t||(C.add(f),z.push({eventUuid:crypto.randomUUID(),timestamp:new Date().toISOString(),deviceId:k,...T?{sessionId:T}:{},url:location.href,pageTitle:document.title.slice(0,512),experimentKey:s.key,variationKey:d.key}))}function we(s){if(!u||t)return;let d=new Set,f={onExperimentViewed:(r,p)=>{d.add(M(r,p))},url:location.href,attributes:{...me(k,location),...S,indianaAppManifestRelease:e.appManifestRelease??null},savedGroups:te(u.savedGroups),log:e.log},h=new Set;for(let r of u.experiments){if(de(`${e.environmentId}:${r.key}`))continue;let p=r;try{let a=ie(p,f);if(O.set(r.changeId,a),!a.inExperiment)continue;h.add(r.changeId);let w=JSON.stringify([a.key,a.value]),U=m.get(r.changeId);if(U?.signature===w){d.has(M(p,a))&&s.push(()=>{U.applied()&&Y(p,a)});continue}m.get(r.changeId)?.revert(),m.delete(r.changeId);let A=fe(a.value,{requireUniqueTargets:!!e.appManifestRelease&&Array.isArray(r.condition?.$and)&&r.condition.$and.some(g=>g!==null&&typeof g=="object"&&!Array.isArray(g)&&g.indianaAppManifestRelease===e.appManifestRelease),boundVariations:r.variations,allowJs:e.disableJsInjection===!1,nonce:e.nonce,onApplied:()=>{d.has(M(p,a))&&Y(p,a)},onError:g=>e.log?.("Visual experiment stopped",{experiment:r.key,changeId:r.changeId,variation:a.key,error:String(g)}),onTargetStatus:e.log?g=>e.log?.("Visual target status changed",{experiment:r.key,changeId:r.changeId,variation:a.key,...g}):void 0});m.set(r.changeId,{signature:w,revert:A.revert,applied:()=>A.applied,inspect:()=>A.inspect()})}catch(a){e.log?.("Skipping visual experiment",{experiment:r.key,error:String(a)})}}for(let[r,p]of m)h.has(r)||(p.revert(),m.delete(r));j()}let V=()=>{let s=[];pe(()=>we(s));for(let d of s)d()};async function _(){let s=++D,d;try{d=await c.read(I,J)}catch(h){if(t||s!==D)return!1;throw h}let f=q(d);if(f.environmentId.toLowerCase()!==e.environmentId.toLowerCase())throw new Error("Visual payload scope changed");return t||s!==D?!1:(u=f,H=performance.now(),!0)}async function Q(){!await _()||t||(N(),V())}function L(){clearTimeout($),$=setTimeout(()=>{if(document.visibilityState==="hidden")return L();Q().catch(s=>e.log?.("Visual payload refresh failed",{error:String(s)})).finally(()=>{t||L()})},ve)}let X=()=>{t||document.visibilityState==="hidden"||performance.now()-H<ve||(clearTimeout($),Q().catch(s=>e.log?.("Visual payload refresh failed",{error:String(s)})).finally(()=>{t||L()}))},Ie=()=>{x!==location.href&&(x=location.href,V())},Z=()=>{P(!0)},N=()=>{G||t||(G=oe(Ie),addEventListener("pagehide",Z),x=location.href)};async function ee(s,d){let f=location.href,h=u,r=[],p=null;if(!t)try{let a=q(await y.read(I,J));a.environmentId===e.environmentId&&(p=a.generation)}catch{}for(let a of h?.experiments??[]){if(s&&a.changeId!==s)continue;let w=O.get(a.changeId);if(!w)continue;let U=new TextEncoder().encode(ye(w.value)),A=[...new Uint8Array(await crypto.subtle.digest("SHA-256",U))].map(be=>be.toString(16).padStart(2,"0")).join(""),g=m.get(a.changeId)?.inspect()??{status:"inactive",total:0,applied:0};r.push({changeId:a.changeId,experimentKey:a.key,variationKey:w.key,inExperiment:w.inExperiment,fingerprint:A,...g})}return{environmentId:e.environmentId,release:e.appManifestRelease??null,generation:h?.generation??null,publishedGeneration:p,checkedAt:new Date().toISOString(),origin:location.origin,pathname:location.pathname,urlMatches:location.href===f&&(!d||d===f)&&h===u,stopped:t,rows:r}}let ne,xe=ue(()=>{i&&!t&&V()});return{async start(){if(!(i||t)){i=!0,e.appManifestRelease&&(B=ce(e.appManifestRelease)),e.antiFlicker&&(b=document.createElement("style"),e.nonce&&(b.nonce=e.nonce),b.textContent="body { visibility: hidden !important }",document.head.append(b),W=setTimeout(j,Math.min(3e3,Math.max(0,e.antiFlickerTimeout??1e3))));try{if(!await _()||t)return;N(),V()}finally{j(),t||(L(),document.addEventListener("visibilitychange",X),ne=he({environmentId:e.environmentId,baseUrl:l,origins:e.diagnosticsOrigins,inspect:ee}))}}},async refresh(){t||await _()&&(i&&N(),V())},setAttributes(s){S={...s},V()},flush:()=>P(),getDiagnostics:ee,getResults(){return new Map(O)},get generation(){return u?.generation??null},destroy(){t=!0,clearTimeout($),document.removeEventListener("visibilitychange",X),xe(),ne?.(),D++,c.destroy(),y.destroy(),G?.(),B?.destroy(),removeEventListener("pagehide",Z),j();for(let s of m.values())s.revert();m.clear(),P(!0),u=null,O.clear(),C.clear(),S={}}}}export{qe as createVisualExperiments,Ve as loadAppManifestRelease};
|
package/package.json
CHANGED
package/dist/chunk-HXDWW6SU.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{b as Me}from"./chunk-XLGNBPGF.js";import{a as Z}from"./chunk-EQUVI5QU.js";import{D as X,F as Ye,c as De,e as Y,j as Ve,u as Ge,v as ze,x as Qe,z as Be}from"./chunk-PAKL7S5P.js";import{a as xe,b as Ue,c as Te}from"./chunk-S2S4ROGY.js";import{b as ce}from"./chunk-Y55OBV7D.js";import{i as le}from"./chunk-MOIVJERE.js";import{K as B}from"./chunk-ME6QTD5Y.js";import{A as ue,B as W,C as Q,E as je}from"./chunk-3532HSBP.js";import{x as ve}from"./chunk-67WFVDTV.js";import{b as Le}from"./chunk-KEM6QYLF.js";import{a as l}from"./chunk-UGATOG2T.js";import{h as se}from"./chunk-LFR2LWYC.js";import{a as He}from"./chunk-5MRSFLQA.js";import{b as r}from"./chunk-W22ESUYY.js";import{a as Ce}from"./chunk-DSPLGTQI.js";var C=B.options,lt=r.discriminatedUnion("operation",[C[1].omit({customerToken:!0}),C[2].omit({customerToken:!0}),C[3].omit({customerToken:!0}),C[4].omit({customerToken:!0}),C[5].omit({customerToken:!0}),C[6].omit({customerToken:!0}),C[7].omit({customerToken:!0}),C[8].omit({customerToken:!0}),Ve.omit({customerToken:!0})]),Re=r.strictObject({receiptId:r.uuid(),operationId:r.uuid()}),vt=r.discriminatedUnion("operation",[r.strictObject({operation:r.literal("find_purchase")}),r.strictObject({operation:r.literal("recover_start"),intent:r.enum(["lookup","resume","start"]),start:r.strictObject({requestId:C[0].shape.requestId,funnelId:C[0].shape.funnelId,locale:C[0].shape.locale,parameters:C[0].shape.parameters})}),r.strictObject({operation:r.literal("recover_run"),runId:r.uuid(),funnelId:r.uuid()}),r.strictObject({operation:r.literal("recover_purchase"),runId:r.uuid(),funnelId:r.uuid(),purchase:Re,includePaywallVersion:r.literal(!0).optional()}),r.strictObject({operation:r.literal("terminate_checkout"),runId:r.uuid(),funnelId:r.uuid(),purchase:Re,intent:r.literal("expire_unconfirmed_quote").optional()}),r.strictObject({operation:r.literal("settle_command"),runId:r.uuid(),funnelId:r.uuid(),requestId:r.uuid(),command:r.discriminatedUnion("operation",[C[3].omit({customerToken:!0}),C[4].omit({customerToken:!0}),C[5].omit({customerToken:!0}),C[6].omit({customerToken:!0}),C[7].omit({customerToken:!0})]).optional()}).refine(s=>!s.command||s.requestId===s.command.requestId),r.strictObject({operation:r.literal("run_command"),runId:r.uuid(),funnelId:r.uuid(),command:lt})]),de=r.strictObject({runId:r.uuid(),funnelId:r.uuid(),versionId:r.uuid(),startRequestId:r.uuid(),runExpiresAt:r.iso.datetime({offset:!0}),status:Y.shape.run.shape.status}),M={scope:se,customerId:r.uuid()},Je=r.discriminatedUnion("outcome",[r.strictObject({...M,outcome:r.literal("unknown"),target:r.null(),view:r.null(),access:r.null()}),r.strictObject({...M,outcome:r.literal("resolved"),target:de,view:Y.shape.run.nullable(),access:r.discriminatedUnion("type",[r.strictObject({type:r.literal("customer")}),r.strictObject({type:r.literal("operation_only"),cause:r.enum(["run_terminal","run_expired","run_revoked","issuer_unavailable"])})])})]).superRefine((s,d)=>{s.outcome==="resolved"&&(s.access.type==="customer"!=(s.view!==null)||s.view&&(s.view.id!==s.target.runId||s.view.source.id!==s.target.funnelId||s.view.source.versionId!==s.target.versionId||s.view.status!==s.target.status||s.view.runExpiresAt!==s.target.runExpiresAt||s.view.credentialExpiresAt!==null))&&d.addIssue({code:"custom",message:"Recovery view and original Run binding differ"})}),Ke=r.strictObject({...M,target:de,view:Y.shape.run.nullable(),settlement:r.strictObject({requestId:r.uuid(),state:r.enum(["pending","unknown","settled"]),acceptance:r.enum(["accepted","not_accepted","unknown"]),receiptPhase:r.enum(["accepted","processing","done"]).nullable(),basis:r.enum(["receipt","run_terminal","position_advanced","none"]),receiptId:r.uuid().nullable(),operationId:r.uuid().nullable()}),purchase:Y.shape.purchase.unwrap().nullable()}).superRefine((s,d)=>{let f=s.settlement;(f.acceptance==="accepted"!=(f.receiptPhase!==null)||f.acceptance==="accepted"&&f.basis!=="receipt"||f.acceptance==="unknown"&&(f.state!=="unknown"||f.basis!=="none")||f.acceptance!=="accepted"&&(f.operationId!==null||f.receiptId!==null)||f.acceptance==="not_accepted"&&(f.state!=="settled"||!["run_terminal","position_advanced"].includes(f.basis))||s.purchase&&(s.purchase.receiptId!==f.receiptId||s.purchase.operation&&s.purchase.operation.operationId!==f.operationId||s.purchase.quote&&s.purchase.quote.operationId!==f.operationId)||s.view&&(s.view.id!==s.target.runId||s.view.source.id!==s.target.funnelId||s.view.source.versionId!==s.target.versionId||s.view.status!==s.target.status||s.view.runExpiresAt!==s.target.runExpiresAt||s.view.credentialExpiresAt!==null))&&d.addIssue({code:"custom",message:"Original command settlement binding differs"})}),$e=r.strictObject({...M,target:de,purchase:Y.shape.purchase.unwrap(),paywallVersionId:r.uuid().optional()}).superRefine((s,d)=>{(!s.purchase.operation||typeof s.purchase.canReselect!="boolean"||s.purchase.quote&&s.purchase.quote.operationId!==s.purchase.operation.operationId)&&d.addIssue({code:"custom",message:"Original purchase proof is incomplete"})}),We=r.discriminatedUnion("outcome",[r.strictObject({...M,outcome:r.literal("none")}),r.strictObject({...M,outcome:r.literal("blocked")}),r.strictObject({...M,outcome:r.literal("found"),target:de,start:r.strictObject({locale:C[0].shape.locale,parameters:C[0].shape.parameters}),purchase:Re})]);var dt=B.options[0].refine(s=>!s.customer&&!s.customerData),pt=r.strictObject({receiptId:r.uuid(),operationId:r.uuid(),terminal:r.enum(["complete","native"]).nullable()}),Xe=r.strictObject({schemaVersion:r.literal(1),baseUrl:r.url(),scope:se,customerId:r.uuid(),sessionId:r.uuid(),start:dt,allowed:r.array(r.enum(["merchant","record_only","indiana","native"])),run:r.strictObject({id:r.uuid(),versionId:r.uuid(),status:De.shape.status,revision:r.number().int().nonnegative(),runExpiresAt:r.iso.datetime({offset:!0}).optional()}).optional(),purchases:r.array(pt).max(100),operationCommand:r.strictObject({operationId:r.uuid(),intent:r.literal("confirm")}).optional(),journal:r.strictObject({revision:r.number().int().nonnegative(),entry:Ge.nullable()})});function Ze(s){return Qe({...s,namespace:"purchases",identity:[s.scope.projectId,s.scope.environment,s.customerId]})}function et(s){let d=new URL(s.baseUrl??He).href,f=()=>new l("PURCHASE_STORAGE_INVALID","Purchase recovery storage is unavailable or invalid; native fallback is not authorized");async function R(){s.assertCurrent();try{let S=await s.storage.read();if(s.assertCurrent(),!Number.isSafeInteger(S.revision)||S.revision<0)throw f();let c=S.entry===null?null:Xe.parse(S.entry);if(c&&(c.baseUrl!==d||c.customerId!==s.customerId||c.scope.projectId!==s.scope.projectId||c.scope.environment!==s.scope.environment))throw new l("SCOPE_MISMATCH","Purchase recovery belongs to another Customer or environment");if(c?.journal.entry&&(c.journal.entry.scope.projectId!==c.scope.projectId||c.journal.entry.scope.environment!==c.scope.environment||c.journal.entry.funnelId!==c.start.funnelId||c.journal.entry.runId!==c.run?.id||c.journal.entry.versionId!==c.run?.versionId)||c?.operationCommand&&!c.purchases.some(k=>k.operationId===c.operationCommand?.operationId))throw f();return{revision:S.revision,entry:c}}catch(S){throw S instanceof l?S:f()}}async function ee(S){for(let c=0;c<8;c++){let k=await R(),O=S(structuredClone(k.entry));if(JSON.stringify(O)===JSON.stringify(k.entry))return O;O&&Xe.parse(O),s.assertCurrent();let x;try{x=await s.storage.write(k.revision,O)}catch{throw f()}if(s.assertCurrent(),x!==null){if(!Number.isSafeInteger(x)||x<=k.revision)throw f();return O}}throw new l("PURCHASE_STORAGE_CONFLICT","Another consumer changed this purchase; recover the original attempt")}return{read:R,update:ee,baseUrl:d}}var mt=5*6e4,ft=2e3;function ht(s,d){let f=s.purchases.find(R=>R.type==="checkout");if(!s.actions.includes("continue_checkout")||f?.type!=="checkout"||d!==void 0&&f.operationId!==d)throw new l("PURCHASE_PENDING","No single resumable Checkout is confirmed");return f.checkoutUrl}function Jt(s){let d={...s,scope:{...s.scope},executionPolicy:structuredClone(s.executionPolicy)},f=d.session.snapshot();if(!f)throw new l("CUSTOMER_SESSION_REQUIRED","Purchase recovery requires a verified Customer session");let{customerId:R,sessionId:ee}=f,S=!1,c=null,k,O,x=null,F=!1,U,te,ne,_={mode:"idle",status:"idle",actions:["start"],purchases:[]},g=new Map,Se=new Map,T=new Map,pe=new AbortController,re=new Set,J=Le(d),oe=Me(J.request);function K(e){return{code:e instanceof l?e.code:"PURCHASE_RECOVERY_BLOCKED",message:e instanceof Error?e.message:"The original purchase requires server confirmation",...e instanceof l&&e.status!==void 0?{status:e.status}:{}}}function P(){if(S||d.session.snapshot()?.customerId!==R)throw new l("IDENTITY_CHANGED","The original purchase Customer changed")}let w=et({...d,customerId:R,assertCurrent:P,storage:d.storage??Ze({baseUrl:d.baseUrl,scope:d.scope,customerId:R})}),tt,Ee=()=>tt??=import("./funnel-paywall-copies-LPOTYSTS.js").then(({createPaywallCopies:e})=>e({baseUrl:d.baseUrl,scope:d.scope,customerId:R})),nt={read:async e=>(await Ee()).read(e),write:async(e,t)=>(await Ee()).write(e,t)},rt=d.session.subscribeIdentity(be);function be(){S||(S=!0,clearTimeout(ne),pe.abort(new l("IDENTITY_CHANGED","Purchase consumer was destroyed")),rt(),c?.reset(),c=null,x=null,J.dispose(),re.clear(),g.clear(),T.clear())}function v(e){P();let t=JSON.stringify(e)!==JSON.stringify(_);_=e,clearTimeout(ne),(e.mode==="operation"||e.mode==="run"&&!e.actions.includes("close"))&&["waiting_result","fulfillment","recording"].includes(e.status)&&(ne=setTimeout(()=>{z().catch(()=>{})},5e3)),t&&Ce(d.onRecovery,structuredClone(e));for(let n of t?re:[]){if(S)break;Ce(n,structuredClone(e))}return structuredClone(e)}function y(e){if(P(),!e||e.start.requestId!==O)throw new l("PURCHASE_STORAGE_CONFLICT","This purchase was superseded; the old consumer cannot dispatch")}function _e(e){return!e.run&&!E(e).length&&!e.journal.entry&&!e.operationCommand}function me(e){let t=e.journal.entry;return!E(e).length&&!e.operationCommand&&!t?.closeCommand&&(!t?.command||t.command.operation==="close")}function G(e){return!!e.run&&me(e)}function E(e){let t=[...e.purchases],n=e.journal.entry?.purchase;return n&&!t.some(o=>o.operationId===n.operationId)&&t.push({receiptId:n.receiptId,operationId:n.operationId,terminal:null}),t}function N(e){let t=E(e),n=F&&t.length>0&&t.every(o=>o.terminal==="native"&&V(g.get(o.operationId))==="native")&&t.some(o=>{let a=g.get(o.operationId);return!a||T.get(o.operationId)!==!0?!1:Q(a)?!0:a.status==="cancelled"&&a.confirmedAt===null&&!a.quoteFinalized&&!a.merchantExecution&&!a.problem&&!!a.quote&&Date.parse(a.quote.expiresAt)<=Date.now()});return e.run&&(n||!["running","waiting"].includes(e.run.status))&&!e.journal.entry?.command&&!e.journal.entry?.closeCommand&&!e.operationCommand&&t.every(o=>o.terminal!==null)}function A(e,t){let n=e.journal.entry?.command??e.journal.entry?.closeCommand,o=E(e).map(I=>{let b=g.get(I.operationId),L=ce({quote:b?.quote??null,operation:b??null,requestId:n?.requestId??null,pending:!1,destroyed:!1,canReselect:T.get(I.operationId)===!0});return I.terminal&&(L.type==="checkout"||L.type==="recover"||L.type==="cancel")?{type:I.terminal,operationId:I.operationId}:L}),a=o.filter(I=>!["complete","native"].includes(I.type)),u=a[0],i=a.length===1&&u?.operationId?g.get(u.operationId):void 0;if(i&&(u?.type==="checkout"||u?.type==="cancel"))try{X({allowed:e.allowed.filter(I=>d.executionPolicy.allowed.includes(I))},i.quote)}catch(I){return{mode:t,status:"blocked",actions:["refresh",...t==="run"&&e.run&&["running","waiting"].includes(e.run.status)?["close"]:[]],purchases:o,error:K(I)}}let m;if(t==="operation"&&!n&&u?.type==="cancel"&&i?.quote&&!i.problem&&!i.confirmedAt)try{X({allowed:e.allowed.filter(I=>d.executionPolicy.allowed.includes(I))},i.quote),Date.parse(i.quote.expiresAt)>Date.now()&&(m={operationId:i.operationId,quote:i.quote})}catch{}let p=o.length>0&&a.length===0,h=N(e)||t==="operation"&&p&&!n&&!e.operationCommand?"complete":u?.type==="checkout"?"checkout":u?.type==="fulfillment"?"fulfillment":u?.type==="recording"?"recording":n||e.operationCommand||u&&u.type!=="cancel"||t==="operation"&&!m?"waiting_result":"ready";return{mode:t,status:h,purchases:o,...m?{confirmation:structuredClone(m)}:{},actions:["refresh",...N(e)||G(e)?["start"]:[],...t==="run"&&e.run&&["running","waiting"].includes(e.run.status)?["close"]:[],...e.operationCommand?["retry"]:m?["confirm"]:[],...a.length===1&&u?.type==="checkout"?["continue_checkout"]:[]]}}function V(e){let t=ce({quote:e?.quote??null,operation:e??null,requestId:null,pending:!1,destroyed:!1,canReselect:e&&T.get(e.operationId)===!0});return t.type==="complete"||t.type==="native"?t.type:null}function fe(e){if(!e.operation)return;let t=ue.parse({...e.operation,...e.operation.quote?{}:e.quote?{quote:e.quote}:{}});if(t.merchantExecution&&t.merchantExecution.customerId!==R)throw new l("SCOPE_MISMATCH","Purchase execution belongs to another Customer");let n=le(g.get(t.operationId)??null,t);g.set(t.operationId,n),n===t&&T.set(t.operationId,e.canReselect===!0)}async function ot(e){P();for(let n of[e.purchase,e.run.paywall])n&&fe(n);let t=await w.update(n=>{if(y(n),n.run&&(n.run.id!==e.run.id||n.run.versionId!==e.run.source.versionId))throw new l("SCOPE_MISMATCH","The original purchase Run changed");let o=E(n);for(let a of[e.purchase,e.run.paywall]){let u=a?.operation?.operationId??a?.quote?.operationId;if(!a||!u)continue;let i=o.find(p=>p.operationId===u);if(i&&i.receiptId!==a.receiptId)throw new l("INVALID_RESPONSE","The original purchase Receipt changed");let m=V(g.get(u));i?i.terminal??=m:o.push({receiptId:a.receiptId,operationId:u,terminal:m})}return{...n,purchases:o,run:n.run&&(n.run.revision>e.run.revision||!["running","waiting"].includes(n.run.status)&&["running","waiting"].includes(e.run.status))?n.run:{id:e.run.id,versionId:e.run.source.versionId,status:e.run.status,revision:e.run.revision,runExpiresAt:e.run.runExpiresAt}}});y(t),t.run&&!["running","waiting"].includes(t.run.status)&&E(t).some(n=>!n.terminal)&&(t=await H(t,!t.journal.entry?.command&&!t.journal.entry?.closeCommand,new Set([e.purchase?.operation?.operationId,e.run.paywall?.operation?.operationId].filter(n=>!!n)))),y(t),v(A(t,"run"))}function at(){return{async read(){let{entry:e}=await w.read();return y(e),structuredClone(e.journal)},async write(e,t){let n=null;return await w.update(o=>{if(y(o),o.operationCommand&&t?.command&&t.command.operation!=="close")throw new l("PURCHASE_PENDING","Recover the original Operation command before dispatching a Run mutation");return n=null,o.journal.revision!==e?o:(n=e+1,{...o,journal:{revision:n,entry:t}})}),n}}}async function H(e,t=!1,n=new Set){y(e);let o=E(e);for(let u of o){if(u.terminal)continue;let i=n.has(u.operationId)?g.get(u.operationId):void 0;if(i??=await D(e,u),P(),i.operationId!==u.operationId)throw new l("INVALID_RESPONSE","Original Operation changed");if(i.merchantExecution&&i.merchantExecution.customerId!==R)throw new l("SCOPE_MISMATCH","Purchase execution belongs to another Customer");if(t&&!e.operationCommand&&ce({quote:i.quote??null,operation:i,requestId:null,pending:!1,destroyed:!1}).type==="cancel"){let m=Q(i)?await oe.update({operationId:u.operationId,intent:"cancel"}):await oe.attach({operationId:u.operationId,intent:"cancel"});if(i=ue.parse(m.operation),P(),i.operationId!==u.operationId)throw new l("INVALID_RESPONSE","Original cancellation Operation changed");i=await D(e,u)}g.set(u.operationId,le(g.get(u.operationId)??null,i))}let a=await w.update(u=>{y(u);let i=u.operationCommand&&g.get(u.operationCommand.operationId);return{...u,...i&&(i.confirmedAt||i.merchantExecution||!je(i))?{operationCommand:void 0}:{},purchases:E(u).map(m=>({...m,terminal:m.terminal??V(g.get(m.operationId))}))}});return y(a),a}async function $(e){P();let t=await J.request("funnels",e);return P(),t}async function it(e){try{return await $(e)}catch(t){if(e.operation!=="recover_start"||e.intent!=="start"||!(t instanceof l)||t.status!==400||t.code!=="INVALID_REQUEST")throw t;return $({...e,intent:"resume"})}}async function st(){let e=Z(We,await $({operation:"find_purchase"}));if(e.customerId!==R||e.scope.projectId!==d.scope.projectId||e.scope.environment!==d.scope.environment)throw new l("SCOPE_MISMATCH","Recovery Customer or environment changed");if(e.outcome!=="found")return e.outcome;let{target:t,purchase:n}=e;return await w.update(o=>o&&!N(o)&&!G(o)?o:{schemaVersion:1,baseUrl:w.baseUrl,scope:d.scope,customerId:R,sessionId:ee,start:{operation:"start",requestId:t.startRequestId,funnelId:t.funnelId,...e.start},allowed:[...d.executionPolicy.allowed],run:{id:t.runId,versionId:t.versionId,status:t.status,revision:0,runExpiresAt:t.runExpiresAt},purchases:[{...n,terminal:null}],journal:{revision:0,entry:null}}),"found"}let ae;function he(e){let t=ae;if(t&&(!t.outcome||e&&t.outcome==="none"&&Date.now()-t.at<mt))return t.job;let n={at:Date.now(),job:st().then(o=>(n.outcome=o,n.at=Date.now(),o),o=>{throw ae===n&&(ae=void 0),o})};return ae=n,n.job}async function D(e,t,n="recover_purchase",o=!1){let a={runId:e.run.id,funnelId:e.start.funnelId,purchase:{receiptId:t.receiptId,operationId:t.operationId}},u=n==="recover_purchase"?{...a,operation:n,...o?{includePaywallVersion:!0}:{}}:{...a,operation:"terminate_checkout",...n==="expire_unconfirmed_quote"?{intent:n}:{}},i=Z($e,await $(u));if(we(e,i),i.purchase.receiptId!==t.receiptId||i.purchase.operation?.operationId!==t.operationId)throw new l("INVALID_RESPONSE","Original purchase reference changed");return fe(i.purchase),o&&i.paywallVersionId&&Se.set(t.operationId,i.paywallVersionId),g.get(t.operationId)}async function qe(e){for(let t of[e.journal.entry?.command,e.journal.entry?.closeCommand]){if(!t)continue;let n=Z(Ke,await $({operation:"settle_command",runId:e.run.id,funnelId:e.start.funnelId,requestId:t.requestId,...t.operation==="resume"?{}:{command:t}}));if(we(e,n),n.settlement.requestId!==t.requestId)throw new l("INVALID_RESPONSE","Original command settlement changed");n.purchase&&fe(n.purchase);let o=await w.update(a=>{y(a);let u=E(a),{receiptId:i,operationId:m}=n.settlement;if(i&&m){let h=u.find(I=>I.operationId===m);if(h&&h.receiptId!==i)throw new l("INVALID_RESPONSE","Original Receipt changed");h||u.push({receiptId:i,operationId:m,terminal:V(g.get(m))})}let p=n.settlement.state==="settled"?ze(a.journal.entry,t.requestId):a.journal.entry;return{...a,purchases:u,journal:p===a.journal.entry?a.journal:{revision:a.journal.revision+1,entry:p}}});y(o),e=o}return e}function we(e,t){if(t.customerId!==R||t.scope.projectId!==d.scope.projectId||t.scope.environment!==d.scope.environment||t.target.funnelId!==e.start.funnelId||t.target.startRequestId!==e.start.requestId||e.run&&(t.target.runId!==e.run.id||t.target.versionId!==e.run.versionId))throw new l("SCOPE_MISMATCH","The original recovery binding changed")}async function Ie(e,t){if(y(e),e.run&&(e=await qe(e)),!E(e).length&&N(e))return v(A(e,"operation"));if(me(e)){let a=e.start.requestId;if(!await w.update(i=>i&&i.start.requestId===a&&me(i)?null:i))return c?.reset(),c=null,F=!1,v({mode:"idle",status:"idle",actions:["start"],purchases:[]})}if(!E(e).length)return v({mode:"blocked",status:"blocked",actions:["refresh"],purchases:[],error:K(t)});F=!0;let n=E(e);if(e.run&&["running","waiting"].includes(e.run.status)&&n.every(a=>a.terminal==="native"))for(let a of n)V(g.get(a.operationId))!=="native"&&await D(e,a);let o=await ut(await H(e));return v(A(o,"operation"))}async function ut(e){if(e.journal.entry?.command||e.journal.entry?.closeCommand||e.operationCommand)return e;let t=E(e).filter(u=>!u.terminal),n=t[0];if(!n||t.length!==1)return e;let o=g.get(n.operationId),a=o?.quote;if(!o||Q(o)||!a||W(a)||a.provider!=="merchant"||o.status!=="pending"||o.confirmedAt!==null||o.quoteFinalized||o.checkoutUrl||o.nativePurchase||o.merchantExecution||o.problem||Date.parse(a.expiresAt)>Date.now())return e;try{await D(e,n,"expire_unconfirmed_quote")}catch{return P(),e}return H(e,!1,new Set([n.operationId]))}async function ie(e,t=!1,n=!0,o=!1){if(O=e.start.requestId,x=structuredClone({requestId:e.start.requestId,funnelId:e.start.funnelId,locale:e.start.locale,parameters:e.start.parameters}),!c){let a=e.run?{operation:"recover_run",runId:e.run.id,funnelId:e.start.funnelId}:{operation:"recover_start",intent:t?"start":"lookup",start:{requestId:e.start.requestId,funnelId:e.start.funnelId,locale:e.start.locale,parameters:e.start.parameters}},u;try{u=await it(a)}catch(h){if(!e.run&&h instanceof l&&(h.status===void 0||h.status>=500))return v({mode:"blocked",status:"blocked",actions:["refresh","retry"],purchases:_.purchases,error:K(h)});throw h}let i=Z(Je,u);if(i.customerId!==R||i.scope.projectId!==d.scope.projectId||i.scope.environment!==d.scope.environment)throw new l("SCOPE_MISMATCH","Recovery Customer or environment changed");if(i.outcome==="unknown"){if(!t&&_e(e)){let h=e.start.requestId;if(!await w.update(b=>b&&b.start.requestId===h&&_e(b)?null:b))return v({mode:"idle",status:"idle",actions:["start"],purchases:[]})}return v({mode:"blocked",status:"blocked",actions:["refresh","retry"],purchases:_.purchases,error:{code:"RESULT_UNKNOWN",message:"The original Start outcome remains unknown; retry only its original input"}})}we(e,i);let m=await w.update(h=>(y(h),{...h,run:{id:i.target.runId,versionId:i.target.versionId,status:i.target.status,revision:i.view?.revision??h.run?.revision??0,runExpiresAt:i.target.runExpiresAt}}));if(y(m),e=m,i.access.type==="operation_only")return Ie(e,new l("RUN_RECONCILIATION_REQUIRED","Only the original command and Operation can be recovered"));e=await qe(e);let p=i.view;if(p.locale!==e.start.locale||!Be(p.parameters,e.start.parameters))throw new l("INVALID_RESPONSE","The original Start input changed");c=Ye({...d,customerRun:{runId:i.target.runId,customerId:R,startRequestId:e.start.requestId},funnelId:e.start.funnelId,funnelExecutionPolicy:{allowed:e.allowed.filter(h=>d.executionPolicy.allowed.includes(h))},funnelCommandStorage:at(),onAcceptedResponse:ot},{scope:i.scope,run:p})}try{let a=o&&k?.controller===c?performance.now()-k.at:1/0;(a>=ft||c.pendingCommands?.length||(c.viewAgeMs??0)<a)&&(k=void 0,await c.get(),k={controller:c,at:performance.now()}),c.view?.pendingRequest?.requestId===e.start.requestId&&!c.pendingCommands?.length&&await c.resume(c.view.pendingRequest.requestId);for(let i of c.pendingCommands??[])i.operation!=="close"&&await c.settle?.(i.requestId);c.pendingCommands?.length&&await c.retry(),P();let u=(await w.read()).entry;return y(u),v(A(u,"run"))}catch(a){if(P(),n&&a instanceof l&&(a.status===401||a.status===409&&a.reason==="STATE_CHANGED")){c.reset(),c=null;let u=(await w.read()).entry;return y(u),ie(u,!1,!1,!1)}throw a}}function j(e,t="read",n){if(P(),U)return t==="read"||t===te?U:U.then(()=>j(e,t,n),()=>j(e,t,n));clearTimeout(ne);let o=e().catch(a=>{throw!S&&!n?.(a)&&v({mode:"blocked",status:"blocked",actions:["refresh"],purchases:_.purchases,error:K(a)}),a});return U=o,te=t,o.then(()=>{U===o&&(U=void 0,te=void 0)},()=>{U===o&&(U=void 0,te=void 0)}),o}function z(e){let t=e?.reuseRecentRead===!0;return j(async()=>{let{entry:n}=await w.read();if(!n||N(n)){if(await he(!1)==="blocked")return Oe();({entry:n}=await w.read())}return n?(O&&n.start.requestId!==O&&(c?.reset(),c=null,g.clear(),T.clear(),F=!1),F&&O===n.start.requestId?Ie(n,_.error):ie(n,!1,!0,t)):v({mode:"idle",status:"idle",actions:["start"],purchases:[]})})}function Oe(){return v({mode:"blocked",status:"blocked",actions:["refresh"],purchases:[],error:K(new l("PURCHASE_PENDING","Check the outstanding purchases before starting another"))})}async function ke(){let e=await z();return e.mode==="operation"&&!e.actions.includes("confirm")&&!e.actions.includes("retry")?e:j(async()=>{let t=(await w.read()).entry;if(y(t),!F){if(!c?.view?.paywall?.quote)throw new l("PURCHASE_PENDING","Read the original quote before confirming");let p=c.view.paywall.operation;if(p?.confirmedAt||p?.merchantExecution||p&&!(Q(p)?["prepared","quoted"].includes(p.status):p.status==="pending"))return v(A(t,"run"));if(c.pendingCommands?.length)await c.retry();else{let I=c.view;await c.submit({operation:"submit",requestId:crypto.randomUUID(),nodeId:I.nodeId,visit:I.visit,revision:I.revision,input:{type:"paywall_confirm",operationId:I.paywall.quote.operationId,...I.paywall.quote.merchantTerms?{merchantConfirmation:ve(I.paywall.quote.merchantTerms)}:{}}})}let h=(await w.read()).entry;return y(h),v(A(h,"run"))}let n=t.operationCommand?.operationId??_.confirmation?.operationId,o=n&&g.get(n);if(!n||!o||t.journal.entry?.command||t.journal.entry?.closeCommand)throw new l("PURCHASE_PENDING","The original Run command must be settled before Operation confirmation");X({allowed:t.allowed.filter(p=>d.executionPolicy.allowed.includes(p))},o.quote),await w.update(p=>{if(y(p),p.journal.entry?.command||p.journal.entry?.closeCommand||p.operationCommand&&p.operationCommand.operationId!==n)throw new l("PURCHASE_PENDING","Another original command is pending");return{...p,operationCommand:{operationId:n,intent:"confirm"}}});let a={operationId:n,intent:"confirm",...o.quote?.merchantTerms?{merchantConfirmation:ve(o.quote.merchantTerms)}:{}},u=Q(o)?await oe.update(a):await oe.attach(a),i=ue.parse(u.operation);if(P(),u.operation.operationId!==n)throw new l("INVALID_RESPONSE","Original confirmation Operation changed");g.set(n,le(o,i));let m=(await w.read()).entry;return y(m),v(A(await H(m,!1,new Set([n])),"operation"))},"confirm")}function ct(e){let t=e?.quote;return t&&W(t)&&t.timing==="immediate"&&t.execution.provider==="merchant"&&(e.confirmedAt||e.merchantExecution)?t:null}function Fe(){if(_.mode!=="operation"||_.status==="blocked")return null;let e=_.purchases.filter(({type:n})=>n!=="complete"&&n!=="native"),t=e.length===1&&e[0]?.operationId;return t?ct(g.get(t)):null}async function Ae(){P();let{entry:e}=await w.read();return e?N(e)||G(e)?"finished":"pending":"none"}return{get controller(){return c},get recovery(){return structuredClone(_)},get attempt(){return P(),structuredClone(x)},get identitySignal(){return pe.signal},get customerId(){return R},retained:Ae,async pendingFunnel(){P();let{entry:e}=await w.read();return e&&!N(e)&&!G(e)?e.start.funnelId:null},get paywallCopies(){return nt},async findPurchase(){let e=await Ae();if(e==="pending")return e;let t=await he(!0);return P(),t==="none"?e:t},async readPaywall(e){P();let t=xe(e),[n,{readPaywallContent:o},{validateResourceCheck:a}]=await Promise.all([Ue(J.request,"resolvePaywall"),import("./paywall-content-DIBAGNQG.js"),import("./check-response-XGOTG3KL.js")]);P();let u=n.request.parse({selector:t.paywallVersionId?{type:"version",versionId:t.paywallVersionId}:{type:"paywall",paywallId:t.paywallId},commerce:t.commerce,locale:t.locale}),i=await Te(J.request,n,u);a(u,i.paywall.check,i.scope);let m=await o(d,i.paywall);if(P(),t.paywallVersionId?m.id!==t.paywallVersionId:m.paywallId!==t.paywallId)throw new l("INVALID_RESPONSE","The requested Paywall changed");return m},get canRestoreUpgradePaywall(){return Fe()!==null},recoverUpgradePaywall(){let e=Fe();return e?this.recoverPurchasePaywall(void 0,e.operationId):Promise.resolve(null)},async recoverPurchasePaywall(e,t){if(_.mode!=="operation"||_.status==="blocked")return null;let{entry:n}=await w.read();if(!n?.run)return null;y(n);let o=E(n),a=o.filter(q=>!q.terminal),u=o.filter(q=>q.terminal==="complete"),i=a.length===1?a[0]:a.length?void 0:u.find(q=>e&&e.runId===n.run?.id&&q.receiptId===e.receiptId)??(u.length===1?u[0]:void 0);if(!i||t&&i.operationId!==t)return null;let m=e?.runId===n.run.id&&e.receiptId===i.receiptId?e.view:void 0,p;try{p=await D(n,i,"recover_purchase",!0)}catch(q){if(!(q instanceof l&&q.status===400&&q.code==="INVALID_REQUEST"))throw q;if(!m)return null;p=await D(n,i)}let h=p.quote;if(!h||W(h)&&(h.timing!=="immediate"||h.execution.provider!=="merchant")||!(p.confirmedAt||p.merchantExecution||p.checkoutUrl||V(p)==="complete"))return null;V(p)!=="complete"&&X({allowed:n.allowed.filter(q=>d.executionPolicy.allowed.includes(q))},h);let I=Se.get(i.operationId),b=n.start.parameters?.commerce,L=n.start.locale??"en",ye=m;if(I){if(typeof b!="object"||!b||!("provider"in b)||typeof b.provider!="string"||!("currency"in b)||typeof b.currency!="string")return null;ye=await this.readPaywall({paywallVersionId:I,locale:L,commerce:{provider:b.provider,currency:b.currency,...W(h)?{intent:"subscription_change"}:{}}})}if(!ye)return null;P();let Ne=ye,ge=!1,Pe=async()=>{throw new l("PURCHASE_PENDING","Only the original purchase can be recovered")};return{signal:pe.signal,view:Ne,quote:h,locale:L,get operation(){return p},get canReselect(){return T.get(i.operationId)===!0},async refresh(){return Ne},preview:Pe,confirm:Pe,cancel:Pe,async read(){if(ge)throw new DOMException("Purchase view closed","AbortError");p=await D(n,i);let q=await H(n,!1,new Set([i.operationId]));return ge||v(A(q,"operation")),structuredClone(p)},destroy(){ge=!0}}},start(e){let t=B.parse({...structuredClone(e),operation:"start",requestId:e.requestId??crypto.randomUUID()});if(t.operation!=="start"||t.customer||t.customerData)throw new l("INVALID_REQUEST","A Customer-owned Funnel start is required");return j(async()=>{let n=(await w.read()).entry;if((!n||N(n)||G(n))&&await he(!0)==="blocked")return Oe();let o=await w.update(a=>{if(a&&!N(a)&&!(G(a)&&a.start.requestId!==t.requestId)){if(a.start.funnelId!==t.funnelId)throw new l("PURCHASE_PENDING","Recover the original Funnel before starting another purchase");return a}return{schemaVersion:1,baseUrl:w.baseUrl,scope:d.scope,customerId:R,sessionId:ee,start:t,allowed:[...d.executionPolicy.allowed],purchases:[],journal:{revision:0,entry:null}}});if(!o)throw new l("PURCHASE_STORAGE_INVALID","Original start was not retained");return O!==o.start.requestId&&(c?.reset(),c=null,g.clear(),T.clear(),F=!1),F?Ie(o,_.error):ie(o,!0,!0,!0)},`start:${t.funnelId}`)},refresh:z,confirm:ke,retry:()=>F?ke():j(async()=>{let{entry:e}=await w.read();return e?ie(e,!0):v({mode:"idle",status:"idle",actions:["start"],purchases:[]})},"retry"),async close(){return c?.view?j(async()=>{if(!c?.view)throw new l("PURCHASE_PENDING","Recover the original Run before closing");if(c.pendingCommands?.find(n=>n.operation==="close"))await c.retry();else if(["running","waiting"].includes(c.view.status)){let n=c.view;await c.submit({operation:"close",requestId:crypto.randomUUID(),nodeId:n.nodeId,visit:n.visit,revision:n.revision})}let t=(await w.read()).entry;return y(t),v(A(t,"run"))},"close"):z()},async continueCheckout(e,t){let n=t?await j(async()=>{let{entry:o}=await w.read();if(y(o),!o.run||!E(o).some(u=>u.operationId===t&&!u.terminal))throw new l("PURCHASE_PENDING","The original Checkout changed");let a=await H(o);return v(A(a,F?"operation":"run"))},`continue:${t}`,o=>o instanceof l&&o.code==="PURCHASE_PENDING"):await z();P(),await e(ht(n,t))},async terminateCheckout(e){let t=n=>n.actions.includes("continue_checkout")&&n.purchases.some(o=>o.type==="checkout"&&o.operationId===e);if(!t(_)&&!t(await z()))throw new l("PURCHASE_PENDING","The original Checkout has changed");return j(async()=>{let{entry:n}=await w.read();y(n);let o=E(n).find(u=>u.operationId===e&&!u.terminal);if(!o||!n.run)throw new l("PURCHASE_PENDING","The original Checkout has changed");await D(n,o,"terminate_checkout");let a=await H(n,!1,new Set([e]));return v(A(a,F?"operation":"run"))},`terminate:${e}`,n=>n instanceof l&&["CAPABILITY_UNAVAILABLE","NOT_CONFIGURED"].includes(n.code))},subscribe(e){return re.add(e),()=>{re.delete(e)}},destroy:be}}export{Ze as a,ht as b,Jt as c};
|
package/dist/chunk-RMELSVQL.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{o as n,r as t}from"./chunk-PAKL7S5P.js";function u(o,e,a){return n(o,e,a,t)}export{u as a};
|
|
File without changes
|