@tinkerlandai/indiana-sdk 0.9.2 → 0.9.5
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 +10 -0
- package/README.md +60 -4
- package/README.zh-CN.md +26 -3
- package/dist/{ai-usage-DMNKvCiq.d.ts → ai-usage-CUTIHAU0.d.ts} +5 -5
- package/dist/{api--Zf0gxfj.d.ts → api-BXu6TAoB.d.ts} +274 -127
- package/dist/{chunk-65TBYVCS.js → chunk-4C3HUZ3B.js} +1 -1
- package/dist/chunk-5ZWSFE2C.js +1 -0
- package/dist/chunk-6ZZUNGNE.js +1 -0
- package/dist/chunk-AOGPGUWE.js +1 -0
- package/dist/chunk-BOCKPUCM.js +2 -0
- package/dist/chunk-CLXORAOK.js +1 -0
- package/dist/chunk-HEGNIATD.js +1 -0
- package/dist/{chunk-WSVH6IQA.js → chunk-LMO3FXRT.js} +1 -1
- package/dist/chunk-M7JWCLYX.js +173 -0
- package/dist/chunk-MKV726FV.js +1 -0
- package/dist/chunk-QYECMZJJ.js +1 -0
- package/dist/chunk-UBMPFTGE.js +1 -0
- package/dist/chunk-UWFYBRM2.js +6 -0
- package/dist/chunk-XRXI3DMZ.js +1 -0
- package/dist/chunk-XSOEA4A5.js +4 -0
- package/dist/{configuration-sync-E98CqVwh.d.ts → configuration-sync-DuJl4SbM.d.ts} +64 -11
- package/dist/content-PQJYLAGQ.js +1 -0
- package/dist/coupon-fA1QujHt.d.ts +184 -0
- package/dist/{customer-page-9B97Qdt_.d.ts → customer-page-km5f1PJZ.d.ts} +86 -182
- package/dist/{funnel-local-client-BjPwXlQb.d.ts → funnel-local-client-BhHdi5_V.d.ts} +2843 -1187
- package/dist/funnel-node-evaluation-DuPmqIo1.d.ts +998 -0
- package/dist/funnel-resource-client-BoIhL_my.d.ts +9674 -0
- package/dist/funnel-runtime-host-3YUGXD3Y.js +1 -0
- package/dist/index.d.ts +1292 -9349
- package/dist/index.js +1 -1
- package/dist/native-shell.js +1 -1
- package/dist/openrouter.d.ts +3 -3
- package/dist/openrouter.js +1 -1
- package/dist/page.d.ts +3 -3
- package/dist/page.js +1 -1
- package/dist/paywall-CSAGKPCP.js +1 -0
- package/dist/popup.d.ts +7 -5
- package/dist/popup.js +1 -1
- package/dist/react-native.d.ts +23680 -173
- package/dist/react-native.js +1 -1
- package/dist/{screen-BITZ11jn.d.ts → screen-CvfI_L41.d.ts} +157 -4
- package/dist/{screen-renderer-A6VYE2QL.js → screen-renderer-VAMWY7ID.js} +1 -1
- package/dist/server.d.ts +355 -95
- package/dist/server.js +1 -1
- package/dist/visual-dom-OFB7BFFB.js +1 -0
- package/dist/visual.d.ts +1 -1
- package/dist/visual.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-5O667MKA.js +0 -1
- package/dist/chunk-67A7I6MB.js +0 -1
- package/dist/chunk-CCQHYQ4P.js +0 -1
- package/dist/chunk-CPLLMISZ.js +0 -1
- package/dist/chunk-G23YNWWI.js +0 -1
- package/dist/chunk-L7LKE3MG.js +0 -173
- package/dist/chunk-NH2PTTNK.js +0 -2
- package/dist/chunk-PK5HYUHD.js +0 -1
- package/dist/chunk-SEW4YVR7.js +0 -1
- package/dist/chunk-UYSOTMY3.js +0 -1
- package/dist/chunk-YZSQDZXW.js +0 -4
- package/dist/content-3LOJVYQO.js +0 -1
- package/dist/errors-0TSUIbUi.d.ts +0 -115
- package/dist/funnel-runtime-host-NYHKQT6T.js +0 -1
- package/dist/paywall-ISCYOGPZ.js +0 -1
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as De,b as se}from"./chunk-SEW4YVR7.js";import{a as te,b as ne}from"./chunk-CCQHYQ4P.js";import{a as z,f as Se,k as L,l as xe,m as Te,n as ke,o as re,p as Pe}from"./chunk-UYSOTMY3.js";import"./chunk-CPLLMISZ.js";import{a as i}from"./chunk-5O667MKA.js";import{R as o,T as J,U as W,g as Ae,h as Re,i as Fe,j as M,na as X,oa as Z,p as $,pa as ee,sa as H}from"./chunk-PK5HYUHD.js";import{fa as l}from"./chunk-G23YNWWI.js";import{b as oe}from"./chunk-NH2PTTNK.js";import{c as ie,d as ae}from"./chunk-65TBYVCS.js";import"./chunk-DSPLGTQI.js";import"./chunk-G56XGVMS.js";import"./chunk-WSVH6IQA.js";import"./chunk-7DXL3LHT.js";import"./chunk-3PZ4Y6UD.js";function ce(t,e,n={}){let s=!!t.session.peek(),c=new Set,u=r=>{for(let d of c)try{d(r)}catch{}};return t.session.subscribeIdentity(()=>{s=!!t.session.peek(),u(s),n.afterChange?.()},()=>{s=!1,e()}),{isIdentified:()=>s,methods:{subscribeIdentity(r){return c.add(r),()=>{c.delete(r)}},identify(r){let d=typeof r=="string"?r:r.accessToken;if(!M.test(d))throw new l("INVALID_TOKEN","Browser SDK requires a customer session");n.beforeIdentify?.(d),t.identify(r)},reset(){try{n.beforeReset?.()}finally{t.reset()}}}}}function p(t){if(t!==null&&typeof t=="object"&&"customerId"in t)throw new l("INVALID_REQUEST","Customer requests use the verified session identity")}function ue(t){return{async checkEntitlement(e){p(e);let n=o.checkEntitlement;return i(t,n,e)},async readHoldings(e={}){let n=o.readHoldings;return i(t,{...n,request:n.request.omit({customerId:!0})},e)}}}function de(t){return{async readLedger(e){let n=o.readLedger;return i(t,n,{query:e})},async readCreditStatement(e){p(e);let n=o.readCreditStatement;return i(t,n,e)},async quoteBalance(e){p(e);let n=o.quoteBalance;return i(t,n,{command:e})}}}function pe(t){return{async setupPayment(e){p(e);let n=o.setupPayment;return i(t,n,e)},async readPaymentSetup(e){p(e);let n=o.readPaymentSetup;return i(t,n,e)},async readBillingInvoice(e){p(e);let n=o.readBillingInvoice;return i(t,n,e)},async readBillingControls(e={}){p(e);let n=o.readBillingControls;return i(t,n,e)},async prepareBillingAuthorization(e){p(e);let n=o.prepareBillingAuthorization;return i(t,n,e)},async confirmBillingAuthorization(e){p(e);let n=o.confirmBillingAuthorization;return i(t,n,e)},async setBillingCoupons(e){p(e);let n=o.setBillingCoupons;return i(t,n,e,{request:"Invalid billing coupon list",response:"Invalid billing coupon receipt"})},async revokeBillingAuthorization(e){p(e);let n=o.revokeBillingAuthorization;return i(t,n,e)},async listBillingInvoices(e={after:null,limit:25}){p(e);let n=o.listBillingInvoices;return i(t,n,e)},async confirmBillingAdjustment(e){p(e);let n=o.confirmBillingAdjustment;return i(t,n,e)}}}function le(t){return{async previewUpdate(e){p(e);let n=o.previewUpdate;return i(t,n,e)},async update(e){p(e);let n=o.update;return i(t,n,e)},async readSubscriptionUpdate(e){p(e);let n=o.readSubscriptionUpdate;return i(t,n,e)},async restoreNativePurchase(e){p(e);let n=o.restoreNativePurchase;return i(t,n,e)},async previewAttach(e){p(e);let n=o.previewAttach;return i(t,n,e)},async attach(e){p(e);let n=o.attach;return i(t,n,e)},async readSubscriptionOperation(e){p(e);let n=o.readSubscriptionOperation;return i(t,n,e)}}}function me(t){return{async redeemReward(e){return p(e),(await i(t,o.redeemReward,{...e,requestId:e.requestId??crypto.randomUUID()},{request:"Invalid reward redemption",response:"Invalid reward receipt"})).redemption},async claimRewardProduct(e){return p(e),(await i(t,o.claimRewardProduct,e,{request:"Invalid reward product claim",response:"Invalid reward product checkout"})).checkout},async createReferralCode(e){return p(e),(await i(t,o.createReferralCode,{...e,requestId:e.requestId??crypto.randomUUID()},{request:"Invalid referral program",response:"Invalid referral code"})).referralCode},async redeemCoupon(e,n=crypto.randomUUID()){let s=await i(t,o.redeemCoupon,{code:e,requestId:n},{request:"Invalid coupon code",response:"Invalid Coupon receipt"});return{offer:s.offer,reason:s.reason}},async claimCoupon(e,n=crypto.randomUUID()){let s=await i(t,o.grantOffer,{couponId:e,requestId:n},{request:"Invalid Coupon claim",response:"Invalid Coupon receipt"});return{offer:s.offer,reason:s.reason}},async listOffers(){return(await i(t,o.listOffers,{},{response:"Invalid offers response"})).offers}}}function fe(t){return{...ue(t),...de(t),...pe(t),...le(t),...me(t)}}function ye(t){return{async resolveContent(e){p(e);let n=o.resolveContent;return i(t,n,e)},async resolvePaywall(e){p(e);let n=o.resolvePaywall;return i(t,n,e)},async resolveOffering(e){p(e);let n=o.resolveOffering;return i(t,n,e)}}}var Ie=t=>new TextEncoder().encode(JSON.stringify(t)).length,he=16384;function ve(t,e){let n=0,s,c=v=>{s={config:structuredClone(v),until:Date.now()+3e4}},u=[],r=null,d;function T(){if(!e())throw new l("NOT_IDENTIFIED","Call identify before using Features or events")}function f(){d||!u.length||(d=setTimeout(()=>{d=void 0,E().catch(()=>{}).finally(f)},5e3),typeof d=="object"&&"unref"in d&&d.unref())}function k(v,g={},I={}){if(T(),s&&Date.now()<s.until&&!$(s.config,v))return;_();let A=o.trackEvents.request.parse({events:[{eventUuid:crypto.randomUUID(),timestamp:new Date().toISOString(),name:v,properties:g,...I}]}).events[0];if(Ie({events:[A]})>he)throw new l("INVALID_REQUEST","Event exceeds the delivery size limit");if(u.length>=500)throw new l("EVENT_QUEUE_FULL","Flush pending events before tracking more");u.push(structuredClone(A)),f()}async function E(v=!1){if(T(),r)return r;let g=n,I=(async()=>{let A={inserted:0,duplicates:0,rejected:0,skipped:0},R=u.length;for(;R&&g===n;){let P=[];for(let F of u.slice(0,Math.min(R,100))){if(P.length&&Ie({events:[...P,F]})>he)break;P.push(F)}let V=o.trackEvents,m=await i(t,V,{events:P},void 0,{keepalive:v});if(g!==n)throw new l("IDENTITY_CHANGED","Event identity changed during delivery");if(m.inserted+m.duplicates+m.rejected+m.skipped!==P.length)throw new l("INVALID_RESPONSE","Incomplete event acknowledgement");c(m.analyticsConfig),u.splice(0,P.length),R-=P.length,A.inserted+=m.inserted,A.duplicates+=m.duplicates,A.rejected+=m.rejected,A.skipped+=m.skipped}return A})();r=I;try{return await I}finally{r===I&&(r=null)}}let N;function _(){if(N||typeof document>"u")return;let v=()=>{document.visibilityState==="hidden"&&e()&&u.length&&E(!0).catch(()=>{})};document.addEventListener("visibilitychange",v),N=()=>document.removeEventListener("visibilitychange",v)}return{rememberConfiguration:c,track(v,g,I={}){return _(),k(v,g,I)},flush:E,reset(){n++,s=void 0,clearTimeout(d),d=void 0,u=[],r=null},detachVisibility(){N?.(),N=void 0}}}function ge(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}}}function Ne(t){let e=ge(t),{merchandiseId:n,merchandise:s,...c}=t;return{...c,...e?{merchandise:e}:{}}}function we(t,e,n,s,c){if(c&&s&&(c.scope.projectId!==s.projectId||c.scope.environment!==s.environment))throw new l("SCOPE_MISMATCH","Configuration belongs to another App/environment");let u=0,r=new Set;function d(){if(!e())throw new l("NOT_IDENTIFIED","Call identify before using Features or events")}async function T(f={}){c||d();let k=u,E=!1,N=async()=>{if(E||k!==u)throw new l("IDENTITY_CHANGED","Feature identity changed");let w=o.getFeatures,y=c?{scope:{projectId:c.scope.projectId,environment:c.scope.environment},payload:await c.features()}:await i(t,w,{});if(k!==u)throw new l("IDENTITY_CHANGED","Feature identity changed");if(s&&(y.scope.projectId!==s.projectId||y.scope.environment!==s.environment))throw new l("INVALID_RESPONSE","Feature response scope changed");return n.rememberConfiguration(y.payload.analyticsConfig),y},_=await N(),v=!0,g,I=w=>{try{f.onError?.(w)}catch{}},A=(w,y,C)=>{try{let j=ge(C);n.track(w,y,j?{merchandise:j}:{})}catch(j){I(j)}},R=z({assertUsable:c?.assertFeatures,scope:_.scope,attributes:f.attributes,onError:f.onError,load:async()=>v?(v=!1,_.payload):(await N()).payload,evaluateRemote:async w=>{if(k!==u)throw new l("IDENTITY_CHANGED","Feature identity changed");let y=o.evaluateFeatures,C=await i(t,y,{...w,attributes:Ne(w.attributes)});if(C.scope.projectId!==_.scope.projectId||C.scope.environment!==_.scope.environment)throw new l("INVALID_RESPONSE","Remote Feature response scope changed");return{generation:C.generation,evaluatedAt:C.evaluatedAt,expiresAt:C.expiresAt,features:C.features,...C.merchandiseContext?{merchandiseContext:C.merchandiseContext}:{}}},onExperimentViewed:(w,y,C)=>A("Experiment Viewed",{experimentId:w.key,variationId:y.key},C),onFeatureUsage:(w,y,C)=>A("Feature Evaluated",{feature:w,value:y.value,source:y.source,ruleId:y.ruleId,...y.experimentResult?{variationId:y.experimentResult.key}:{}},C)}),P=R.refresh;function V(){clearTimeout(g),!c&&(E||k!==u||!R.expiresAt||(g=setTimeout(()=>{m().catch(I)},Math.min(2147483647,Math.max(1e3,Date.parse(R.expiresAt)-Date.now()))),typeof g=="object"&&"unref"in g&&g.unref()))}async function m(){try{return await P()}finally{V()}}let F=()=>{E||m().catch(I)},B=R.subscribe(V),S=c?.subscribe(()=>{!E&&c.fresh&&m().catch(I)});function U(){E||(E=!0,clearTimeout(g),typeof window<"u"&&window.removeEventListener("focus",F),B(),S?.(),R.reset(),r.delete(U))}r.add(U);try{await R.init(),(f.attributes?.merchandise||f.attributes?.merchandiseId)&&await R.refreshRemote()}catch(w){throw U(),w}return V(),!c&&typeof window<"u"&&window.addEventListener("focus",F),Object.assign(R,{refresh:m,destroy:U})}return{features:T,reset(f){u++,f();for(let k of r)k()}}}import{z as _e}from"zod";function Ce(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,s=_e.object({funnelId:J.shape.id,funnelVersionId:J.shape.versionId.optional()}).safeParse(n);if(!s.success)throw new l("INVALID_REQUEST","A valid Funnel source is required");let c=Object.freeze(s.data);function u(r){if("customerId"in r)throw new l("INVALID_REQUEST","Customer identity cannot be overridden");if("funnelId"in r&&r.funnelId!==void 0&&r.funnelId!==c.funnelId||"funnelVersionId"in r&&r.funnelVersionId!==void 0&&r.funnelVersionId!==c.funnelVersionId)throw new l("SCOPE_MISMATCH","The original Funnel source cannot change");return{...r,...c}}return{async claimCoupon(r,d=crypto.randomUUID()){let T=o.grantOffer,f=await i(t,T,u({couponId:r,requestId:d}));return{offer:f.offer,reason:f.reason}},async resolveOffering(r){let d=o.resolveOffering;return i(t,d,u(r))},async resolvePaywall(r){let d=o.resolvePaywall;return i(t,d,u(r))},async previewAttach(r){let d=o.previewAttach;return i(t,d,u(r))}}}function Ve(t){let e=H(t),n=e.request,s=te(t.push,e,t.scope??t.configuration?.scope),c=ce(e,()=>{r.reset(u.reset),u.detachVisibility()},{beforeIdentify:s.identify,beforeReset:s.reset,afterChange:s.start}),u=ve(n,c.isIdentified),r=we(n,c.isIdentified,u,t.scope,t.configuration);return{session:e.session,...ne(n,s),...fe(n),...ye(n),forFunnel(d){return Ce(n,d)},async features(d={}){return r.features(d)},track(d,T,f={}){return u.track(d,T,f)},flush(){return u.flush()},...c.methods}}function Ue(t){if(!M.test(t.customerToken))throw new l("INVALID_TOKEN","A customer credential is required");if(!t.scope)throw new l("INVALID_REQUEST","An explicit App and environment scope is required");let e=re({...t,scope:t.scope,apiKey:t.customerToken});return{async start(n){let s=await e.start(n),c=L({...t,runToken:s.runToken});c.identify(t.customerToken);let u=s.run.instruction?.type==="evaluate_segment"?await c.get():s;return{...s,...u,controller:c}}}}function je(t){let e=ie(t.baseUrl),n=t.scope,s=H(t),c=t.fetch??globalThis.fetch.bind(globalThis),u,r=!1,d=!1,T=0,f=0,k="",E=0,N=0,_=0,v,g=!1,I,A,R,P,V,m,F,B=new Set,S=(a,O)=>t.onStatus?.(a,O),U=()=>Date.now()<N&&performance.now()<_;function w(a){if(a.target.release!==t.appManifestRelease||!U())return!1;try{return oe(a.target.render,document,location.pathname,()=>{})}catch{return S("incompatible",a.id),!1}}function y(a){return!r&&a.epoch===E&&a.visit===f&&document.visibilityState!=="hidden"}async function C(a){if(F||m){S("in_progress",a.id);return}if(!t.session.peek()){S("identity_required",a.id);return}let O={command:Z.parse({operation:"entry_start",entryId:a.id,entryRevision:a.revision,release:t.appManifestRelease,requestId:crypto.randomUUID(),locale:document.documentElement.lang||"en"}),epoch:E,visit:f};F=O,await j(O)}async function j(a){try{S("starting",a.command.entryId);let O=await s.request("funnels",a.command),x=ee.safeParse(O);if(x.success){if(x.data.scope.projectId!==n.projectId||x.data.scope.environment!==n.environment)throw new l("SCOPE_MISMATCH","Entry scope changed");S(x.data.reason,a.command.entryId),F=void 0;return}let b=W.parse(O);if(!b.runToken||b.scope.projectId!==n.projectId||b.scope.environment!==n.environment)throw new l("INVALID_RESPONSE","Invalid entry Run");if(a.epoch!==E){F=void 0,S("identity_changed",a.command.entryId);return}let D=L({...t,runToken:b.runToken});if(await D.get(),!y(a)){let h=D.view;h&&["running","waiting"].includes(h.status)&&await D.submit({operation:"close",requestId:crypto.randomUUID(),nodeId:h.nodeId,visit:h.visit,revision:h.revision}),D.reset(),S("left_screen",a.command.entryId),F=void 0;return}m=await se(t.container,{...t.host,client:D,appManifestRelease:t.appManifestRelease,onDismiss(h){m=void 0,t.host?.onDismiss?.(h)},onComplete(h){m?.destroy(),m=void 0,t.host?.onComplete?.(h)}}),F=void 0,S("started",a.command.entryId)}catch(O){S("start_failed",a.command.entryId),t.host?.onError?.(O)}}function Oe(){if(g=!1,!(r||!d||!U()||document.visibilityState==="hidden")){for(let a of u?.entries??[])if(!(a.event!=="screen_enter"||B.has(a.id)||!w(a))){if(!t.session.peek()){S("identity_required",a.id);continue}B.add(a.id),C(a);break}}}let q=()=>{!g&&!r&&(g=!0,queueMicrotask(Oe))};function be(){let a=location.origin+location.pathname;a!==k&&(k=a,f++,B.clear(),q())}function K(a){if(!a.isTrusted||a.button!==0||a.ctrlKey||a.metaKey||a.shiftKey||a.altKey||document.visibilityState==="hidden")return;let O=a.target;if(!(O instanceof Element)||O.closest("[data-indiana-funnel]"))return;let x=O.closest("button,a,input");if(!(!x||x.matches(":disabled,[aria-disabled='true']")||x.closest("[hidden],[inert],[aria-hidden='true']")))for(let b of u?.entries??[]){let D=b.target.button;if(b.event!=="button_click"||!D||!w(b))continue;let h=document.querySelectorAll(D.selector);if(!(h.length!==1||h[0]!==x)){C(b);break}}}async function Q(){if(r)return;if(I)return I;let a=++T;A=new AbortController;let O=(async()=>{let x=await c(`${e}/api/v1/funnel-entries/${t.environmentId}?iam=${t.appManifestRelease}`,{credentials:"omit",cache:"no-store",signal:A.signal});if(!x.ok)throw new l("SERVICE_UNAVAILABLE","Funnel entries unavailable",x.status);let b=X.parse(await x.json()),D=Date.parse(b.validatedAt),h=Date.parse(b.validUntil);if(b.scope.projectId!==n.projectId||b.scope.environment!==n.environment||b.scope.environmentId!==t.environmentId||b.release!==t.appManifestRelease||h<=Date.now()||D>Date.now()+5e3||h-D>6e4||h<=D)throw new l("INVALID_RESPONSE","Entry configuration scope or deadline changed");if(r||a!==T)return;let Ee=u===void 0;u=b,N=h,_=performance.now()+Math.min(h-Date.now(),6e4),Ee&&q()})();I=O;try{await O}finally{I===O&&(I=void 0)}}async function G(){try{await Q()}catch{S("configuration_unavailable")}r||(v=setTimeout(()=>{G()},15e3))}let Y=()=>q();return{async start(){d||r||(d=!0,k=location.origin+location.pathname,R=ae(be),P=t.session.subscribeIdentity(()=>{E++,B.clear(),m?.destroy(),m=void 0,q()}),V=new MutationObserver(q),V.observe(document.documentElement,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["hidden","inert","aria-hidden","data-indiana-id","id"]}),document.addEventListener("click",K,!0),document.addEventListener("visibilitychange",Y),await G())},refresh:Q,async retry(){F&&y(F)&&await j(F)},destroy(){r=!0,T++,clearTimeout(v),A?.abort(),V?.disconnect(),R?.(),P?.(),document.removeEventListener("click",K,!0),document.removeEventListener("visibilitychange",Y),m?.destroy(),m=void 0,u=void 0}}}async function rn(...t){return(await import("./paywall-ISCYOGPZ.js")).showPaywall(...t)}async function on(...t){return(await import("./funnel-runtime-host-NYHKQT6T.js")).showFunnelRun(...t)}async function an(...t){return(await import("./content-3LOJVYQO.js")).mountContent(...t)}async function sn(...t){return(await import("./content-3LOJVYQO.js")).prepareContent(...t)}export{l as IndianaError,Se as createBrowserFunnelCommandStorage,Te as createConfigurationSync,z as createFeatureClient,Ue as createFunnelClient,De as createFunnelPageExperiments,L as createFunnelRunController,je as createIamFunnelEntries,Ve as createIndiana,Pe as createLocalFunnelClient,xe as createPaywallSession,ke as evaluateFunnelNode,Re as formatCouponDiscount,Ae as formatCouponMoney,Fe as formatCouponTerms,an as mountContent,sn as prepareContent,on as showFunnelRun,rn as showPaywall};
|
|
1
|
+
import{a as Le,b as be}from"./chunk-AOGPGUWE.js";import{a as Pe,c as Fe}from"./chunk-QYECMZJJ.js";import{a as Be}from"./chunk-XRXI3DMZ.js";import{b as Te,g as De,l as $,m as Oe,n as xe,p as He}from"./chunk-UBMPFTGE.js";import"./chunk-5ZWSFE2C.js";import{B as Ae,C as Me,D as Ne,Ga as ye,Ha as ge,Ia as we,Ma as Ee,h as V,i as re,j as oe,k as ae,l as ie,m as se,ma as Ie,n as ce,o as de,p as ue,q as le,r as me,s as fe,t as pe,u as he}from"./chunk-UWFYBRM2.js";import{oa as D}from"./chunk-HEGNIATD.js";import{c as Re}from"./chunk-CLXORAOK.js";import"./chunk-6ZZUNGNE.js";import{c as ve,d as Se}from"./chunk-4C3HUZ3B.js";import{a as G}from"./chunk-DSPLGTQI.js";import"./chunk-G56XGVMS.js";import"./chunk-LMO3FXRT.js";import"./chunk-7DXL3LHT.js";import"./chunk-3PZ4Y6UD.js";import{z as U}from"zod";var r=class extends Error{constructor(d,O=0,p=!1,l="fix_request"){super(d);this.code=d;this.status=O;this.retryable=p;this.recovery=l;this.name="MerchantBridgeError"}code;status;retryable;recovery};async function ke(n,b){if(!n.headers.get("content-type")?.split(";",1)[0].trim().match(/^application\/(?:json|[a-z0-9.+-]+\+json)$/i))throw new r("MERCHANT_BRIDGE_INVALID_RESPONSE");let d=n.body?.getReader();if(!d)throw new r("MERCHANT_BRIDGE_INVALID_RESPONSE");let O=()=>{d.cancel().catch(()=>{})};b.addEventListener("abort",O,{once:!0});let p=0,l="",a=new TextDecoder("utf-8",{fatal:!0});try{for(b.throwIfAborted();;){let c=await d.read();if(b.throwIfAborted(),c.done)break;if(p+=c.value.byteLength,p>262144)throw new r("MERCHANT_BRIDGE_INVALID_RESPONSE");l+=a.decode(c.value,{stream:!0})}return l+=a.decode(),JSON.parse(l)}catch(c){throw b.throwIfAborted(),c instanceof r?c:new r("MERCHANT_BRIDGE_INVALID_RESPONSE")}finally{b.removeEventListener("abort",O),await d.cancel().catch(()=>{}),d.releaseLock()}}function Ge(n){let b=ie.parse(n.origin),d=se.parse(n.manifest),O={projectId:n.scope.projectId,environmentId:n.scope.environmentId,environment:n.scope.environment,accountId:n.scope.accountId};for(let o of["projectId","environmentId","environment","accountId"])if(d[o]!==n.scope[o])throw new r("MERCHANT_BRIDGE_SCOPE_MISMATCH");let p=n.customerId===void 0?null:U.uuid().parse(n.customerId),l=0,a=null,c=null,x=new AbortController,F=n.fetch??globalThis.fetch;async function M(o,t,y,g,N){if(!n.scope.accountId)throw new r("MERCHANT_BRIDGE_CAPABILITY_UNSUPPORTED",501,!1,"check_availability");if(!d.capabilities.includes(o))throw new r("MERCHANT_BRIDGE_CAPABILITY_UNSUPPORTED",501);let v=ae[o];if(["merchant_catalog_reader","merchant_refund_authority","indiana_server_key"].includes(v.authority))throw new r("MERCHANT_BRIDGE_FORBIDDEN",403);let H=l,P=AbortSignal.any([x.signal,AbortSignal.timeout(Math.min(3e4,Math.max(1e3,n.timeoutMs??1e4))),...n.signal?[n.signal]:[],...g?[g]:[]]);P.throwIfAborted();let S=new Headers(await n.headers?.());if(P.throwIfAborted(),H!==l)throw new DOMException("Merchant identity changed","AbortError");if(/\bgg_(?:sk|ct|rt)_/.test(S.get("authorization")??"")||S.has("X-Indiana-Bridge-Signature")||S.has("X-Indiana-Bridge-Key-Id"))throw new r("MERCHANT_BRIDGE_FORBIDDEN",403);S.set(oe,String(V)),S.set("Accept","application/json");let R=crypto.randomUUID();S.set("X-Request-Id",R),S.set("Content-Type","application/json");let m=await F(b+re,{method:"POST",credentials:"include",redirect:"error",cache:"no-store",headers:S,signal:P,body:JSON.stringify({bridgeVersion:V,requestId:R,command:v.command,scope:O,data:N??(y===void 0?{}:{operationId:y})})}),T=await ke(m,P);if(P.throwIfAborted(),H!==l)throw new DOMException("Merchant identity changed","AbortError");if(!m.ok){let I=he.safeParse(T);throw!I.success||I.data.scope.projectId!==n.scope.projectId||I.data.scope.environment!==n.scope.environment||I.data.scope.environmentId!==n.scope.environmentId||I.data.scope.accountId!==n.scope.accountId||I.data.requestId!==R||I.data.command!==v.command?new r("MERCHANT_BRIDGE_INVALID_RESPONSE",m.status):new r(I.data.error.code,m.status,I.data.error.retryable,I.data.error.recovery)}let w=ce(U.unknown()).safeParse(T);if(!w.success||w.data.scope.projectId!==n.scope.projectId||w.data.scope.environment!==n.scope.environment||w.data.scope.environmentId!==n.scope.environmentId||w.data.scope.accountId!==n.scope.accountId||w.data.requestId!==R||w.data.command!==v.command)throw new r("MERCHANT_BRIDGE_INVALID_RESPONSE",m.status);let h=t.safeParse(w.data.data);if(!h.success)throw new r("MERCHANT_BRIDGE_INVALID_RESPONSE",m.status);return h.data}function E(){if(!p)throw new r("MERCHANT_BRIDGE_UNAUTHENTICATED",401);return p}async function B(o,t,y){let g=E(),N=me.parse({operationId:t}).operationId,v=await M(o,fe,N,y);if(v.customerId!==g||v.operationId!==N)throw new r("MERCHANT_BRIDGE_SCOPE_MISMATCH");return v}return{async readPresentation(o){let t=await M("presentation",ue,void 0,o);if(c!==null&&c!==t.nativeUserId)throw new r("MERCHANT_BRIDGE_SCOPE_MISMATCH");if(t.presentation&&p!==null&&t.presentation.customerId!==p)throw new r("MERCHANT_BRIDGE_SCOPE_MISMATCH");return c=t.nativeUserId,a=t.presentation,t},async createSession(o){let t=await M("session",de,void 0,o);if(c!==null&&c!==t.nativeUserId)throw new r("MERCHANT_BRIDGE_SCOPE_MISMATCH");if(p!==null&&p!==t.session.customerId)throw new r("MERCHANT_BRIDGE_SCOPE_MISMATCH");if(a&&a.customerId!==t.session.customerId)throw new r("MERCHANT_BRIDGE_SCOPE_MISMATCH");return p=t.session.customerId,c=t.nativeUserId,t.session},async reportPresentation(o,t){let y=E(),g=le.parse(o);if(!a||a.customerId!==y||a.decisionId!==g.decisionId)throw new r("MERCHANT_BRIDGE_SCOPE_MISMATCH");return M("presentation_events",U.strictObject({queued:U.literal(!0)}),void 0,t,g)},async readCustomerCommerce(o){let t=E(),y=await M("customer_commerce",pe,void 0,o);if(y.customerId!==t)throw new r("MERCHANT_BRIDGE_SCOPE_MISMATCH");return y},executePurchase:(o,t)=>B("purchases",o,t),readOperation:(o,t)=>B("operation_status",o,t),executeSubscriptionChange:(o,t)=>B("subscription_changes",o,t),reset(){l++,x.abort(),x=new AbortController,p=null,a=null,c=null}}}function Ue(n){let b=ve(n.baseUrl),d=n.scope,O=Ee(n),p=n.fetch??globalThis.fetch.bind(globalThis),l,a=!1,c=!1,x=0,F=0,M="",E=0,B=0,o=0,t,y=!1,g,N=!0,v,H,P,S,R,m,T=e=>{m===e&&(m=void 0)},w=new Set,h=(e,u)=>G(n.onStatus,e,u);function I(){let e=R;R=void 0,e?.host.destroy(),e?.client.reset()}let z=()=>Date.now()<B&&performance.now()<o;function K(e){if(e.target.release!==n.appManifestRelease||!z())return!1;try{return Re(e.target.render,document,location.pathname,()=>{})}catch{return h("incompatible",e.id),!1}}function j(e){return!a&&e.epoch===E&&e.visit===F&&document.visibilityState!=="hidden"}async function J(e){if(m||R){h("in_progress",e.id);return}if(!n.session.peek()){h("identity_required",e.id);return}let u={command:ge.parse({operation:"entry_start",entryId:e.id,funnelId:e.funnelId,versionId:e.versionId,release:n.appManifestRelease,requestId:crypto.randomUUID(),locale:document.documentElement.lang||"en"}),epoch:E,visit:F};m=u,await X(u)}async function X(e){if(e.dispatching)return;e.dispatching=!0;let u,C=!1;async function f(i){if(e.epoch!==E)return;let s=i.view;s&&["running","waiting"].includes(s.status)&&await i.submit({operation:"close",requestId:crypto.randomUUID(),nodeId:s.nodeId,visit:s.visit,revision:s.revision})}try{h("starting",e.command.entryId);let i=await O.request("funnels",e.command),s=we.safeParse(i);if(s.success){if(s.data.scope.projectId!==d.projectId||s.data.scope.environment!==d.environment)throw new D("SCOPE_MISMATCH","Entry scope changed");e.epoch===E&&h(s.data.reason,e.command.entryId),T(e);return}let _=Ie.parse(i);if(!_.runToken||_.scope.projectId!==d.projectId||_.scope.environment!==d.environment||_.run.source.type!=="funnel"||_.run.source.id!==e.command.funnelId||_.run.source.versionId!==e.command.versionId)throw new D("INVALID_RESPONSE","Invalid entry Run");if(e.epoch!==E){T(e),h("identity_changed",e.command.entryId);return}let A=$({...n,runToken:_.runToken,funnelId:e.command.funnelId});u=A,await A.get();let k=A.view;if(!k||k.id!==_.run.id||k.source.type!=="funnel"||k.source.id!==e.command.funnelId||k.source.versionId!==e.command.versionId)throw new D("INVALID_RESPONSE","Entry Run version changed");if(!j(e)){await f(A),h("left_screen",e.command.entryId),T(e);return}let ee=!1,ne=!1,te=await be(n.container,{...n.host,client:A,appManifestRelease:n.appManifestRelease,onDismiss(q){ee=!0,R?.client===A&&(R=void 0,A.reset()),G(n.host?.onDismiss,q)},onComplete(q){ne=!0,R?.client===A&&I(),G(n.host?.onComplete,q)}});if(!j(e)||ee||ne){te.destroy(),j(e)||await f(A),T(e);return}R={host:te,client:A},C=!0,T(e),h("started",e.command.entryId)}catch(i){!u&&i instanceof D&&i.status!==void 0&&i.status>=400&&i.status<500&&!i.retryable&&T(e),e.epoch===E&&!a&&(h("start_failed",e.command.entryId),G(n.host?.onError,i))}finally{C||u?.reset(),e.dispatching=!1}}function Ce(){if(y=!1,!(a||!c||!z()||document.visibilityState==="hidden")){N=!1;for(let e of l?.entries??[])if(!(e.event!=="screen_enter"||w.has(`${e.funnelId}:${e.id}`)||!K(e))){if(!n.session.peek()){h("identity_required",e.id);continue}w.add(`${e.funnelId}:${e.id}`),J(e);break}}}let L=()=>{!y&&!a&&(y=!0,queueMicrotask(Ce))};function _e(){let e=location.origin+location.pathname;e!==M&&(M=e,F++,N=!0,w.clear(),L())}function Y(e){if(!e.isTrusted||e.button!==0||e.ctrlKey||e.metaKey||e.shiftKey||e.altKey||document.visibilityState==="hidden")return;let u=e.target;if(!(u instanceof Element)||u.closest("[data-indiana-funnel]"))return;let C=u.closest("button,a,input");if(!(!C||C.matches(":disabled,[aria-disabled='true']")||C.closest("[hidden],[inert],[aria-hidden='true']")))for(let f of l?.entries??[]){let i=f.target.button;if(f.event!=="button_click"||!i||!K(f))continue;let s=document.querySelectorAll(i.selector);if(!(s.length!==1||s[0]!==C)){J(f);break}}}async function Z(){if(a)return;if(g)return g;let e=++x;v=new AbortController;let u=(async()=>{let C=await p(`${b}/api/v1/funnel-entries/${n.environmentId}?iam=${n.appManifestRelease}`,{credentials:"omit",cache:"no-store",signal:v.signal});if(!C.ok)throw new D("SERVICE_UNAVAILABLE","Funnel entries unavailable",C.status);let f=ye.parse(await C.json()),i=Date.parse(f.validatedAt),s=Date.parse(f.validUntil);if(f.scope.projectId!==d.projectId||f.scope.environment!==d.environment||f.scope.environmentId!==n.environmentId||f.release!==n.appManifestRelease||s<=Date.now()||i>Date.now()+5e3||s-i>6e4||s<=i)throw new D("INVALID_RESPONSE","Entry configuration scope or deadline changed");if(a||e!==x)return;let _=l===void 0;l=f,B=s,o=performance.now()+Math.min(s-Date.now(),6e4),(_||N)&&L()})();g=u;try{await u}finally{g===u&&(g=void 0)}}async function Q(){try{await Z()}catch{h("configuration_unavailable")}a||(t=setTimeout(()=>{Q()},15e3))}let W=()=>L();return{async start(){c||a||(c=!0,M=location.origin+location.pathname,H=Se(_e),P=n.session.subscribeIdentity(()=>{E++,N=!0,m=void 0,w.clear(),I(),L()}),S=new MutationObserver(L),S.observe(document.documentElement,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["hidden","inert","aria-hidden","data-indiana-id","id"]}),document.addEventListener("click",Y,!0),document.addEventListener("visibilitychange",W),await Q())},refresh:Z,async retry(){m&&!a&&m.epoch===E&&await X(m)},destroy(){a=!0,x++,clearTimeout(t),v?.abort(),S?.disconnect(),H?.(),P?.(),document.removeEventListener("click",Y,!0),document.removeEventListener("visibilitychange",W),I(),l=void 0}}}async function en(...n){return(await import("./paywall-CSAGKPCP.js")).showPaywall(...n)}async function nn(...n){return(await import("./funnel-runtime-host-3YUGXD3Y.js")).showFunnelRun(...n)}async function tn(...n){return(await import("./content-PQJYLAGQ.js")).mountContent(...n)}async function rn(...n){return(await import("./content-PQJYLAGQ.js")).prepareContent(...n)}export{D as IndianaError,r as MerchantBridgeError,De as createBrowserFunnelCommandStorage,xe as createConfigurationSync,Te as createFeatureClient,Fe as createFunnelClient,Le as createFunnelPageExperiments,$ as createFunnelRunController,Ue as createIamFunnelEntries,Pe as createIndiana,He as createLocalFunnelClient,Ge as createMerchantBridge,Oe as createPaywallSession,Be as evaluateFunnelNode,Me as formatCouponDiscount,Ae as formatCouponMoney,Ne as formatCouponTerms,tn as mountContent,rn as prepareContent,nn as showFunnelRun,en as showPaywall};
|