@tinkerlandai/indiana-sdk 0.7.0 → 0.8.1

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 (59) hide show
  1. package/CHANGELOG.md +13 -1
  2. package/README.md +73 -25
  3. package/README.zh-CN.md +77 -25
  4. package/dist/ai-usage-JoM7ZWk-.d.ts +247 -0
  5. package/dist/{ai-usage-BsrSG955.d.ts → api-JVC7x2FV.d.ts} +337 -386
  6. package/dist/chunk-3BQFJANQ.js +1 -0
  7. package/dist/chunk-56AYS7RS.js +1 -0
  8. package/dist/{chunk-6MO6Y24B.js → chunk-6HG7U6AU.js} +1 -1
  9. package/dist/chunk-AE4CUTUE.js +1 -0
  10. package/dist/chunk-AEUFCOFG.js +1 -0
  11. package/dist/chunk-F767CM3T.js +7 -0
  12. package/dist/chunk-KSNOXNTC.js +1 -0
  13. package/dist/{chunk-4AWSZWZD.js → chunk-USLZX2ZA.js} +1 -1
  14. package/dist/{chunk-YAFMBXIE.js → chunk-X747SY26.js} +1 -1
  15. package/dist/chunk-X7JJAEQQ.js +350 -0
  16. package/dist/chunk-YWFNWK7C.js +1 -0
  17. package/dist/{configuration-sync-Bvd956GL.d.ts → configuration-sync-BexM2qbg.d.ts} +17 -18
  18. package/dist/content-YNL2CRJZ.js +1 -0
  19. package/dist/{customer-page-B4LkIr5q.d.ts → customer-page-WUQVK_tp.d.ts} +276 -3
  20. package/dist/{funnel-runtime-start-ChVYbLzV.d.ts → funnel-local-client-D1Fe7CZ6.d.ts} +2507 -8137
  21. package/dist/funnel-runtime-host-CAMI6BJS.js +1 -0
  22. package/dist/index.d.ts +13578 -13442
  23. package/dist/index.js +1 -1
  24. package/dist/native-shell.js +1 -1
  25. package/dist/openrouter.d.ts +5 -3
  26. package/dist/openrouter.js +1 -1
  27. package/dist/page.d.ts +4 -4
  28. package/dist/page.js +1 -1
  29. package/dist/paywall-MXRMMF3R.js +1 -0
  30. package/dist/popup.d.ts +3 -271
  31. package/dist/popup.js +1 -350
  32. package/dist/react-native.d.ts +7 -7
  33. package/dist/react-native.js +1 -1
  34. package/dist/{screen-iFngkxaL.d.ts → screen-i6eHL11m.d.ts} +120 -117
  35. package/dist/screen-renderer-P7MLBHY5.js +1 -0
  36. package/dist/server.d.ts +4645 -8
  37. package/dist/server.js +1 -1
  38. package/dist/src-G7UQB3QE.js +1 -0
  39. package/dist/visual.d.ts +5 -2
  40. package/dist/visual.js +2 -2
  41. package/package.json +3 -9
  42. package/dist/chunk-3SONNXFG.js +0 -1
  43. package/dist/chunk-467Z5ISI.js +0 -11
  44. package/dist/chunk-4K25DELJ.js +0 -1
  45. package/dist/chunk-HD74AAFS.js +0 -1
  46. package/dist/chunk-J4RHVU3W.js +0 -1
  47. package/dist/chunk-NOFNOHUI.js +0 -1
  48. package/dist/chunk-QO4YQLZ4.js +0 -1
  49. package/dist/chunk-U6S6AZM6.js +0 -1
  50. package/dist/chunk-WCFVNF5D.js +0 -1
  51. package/dist/client-F6UPJMHR.js +0 -1
  52. package/dist/controls-XG46TKUU.js +0 -2
  53. package/dist/funnel-runtime-host-26QI2W3S.js +0 -1
  54. package/dist/iam.d.ts +0 -131
  55. package/dist/iam.js +0 -1
  56. package/dist/paywall-WKOHBYW7.js +0 -1
  57. package/dist/src-UHLPVD6E.js +0 -1
  58. /package/dist/{chunk-6X42DWOM.js → chunk-DSPLGTQI.js} +0 -0
  59. /package/dist/{chunk-S5TVMQRC.js → chunk-EXCPE2XH.js} +0 -0
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{a as _,h as X,i as V,j as ee,k as te,l as re,m as j,n as ne}from"./chunk-NOFNOHUI.js";import{a as B}from"./chunk-QO4YQLZ4.js";import{W as Z,X as $,Xd as L,Y as W,li as n}from"./chunk-467Z5ISI.js";import"./chunk-3SONNXFG.js";import"./chunk-U6S6AZM6.js";import"./chunk-4K25DELJ.js";import"./chunk-S5TVMQRC.js";import{a as s}from"./chunk-6MO6Y24B.js";import"./chunk-HD74AAFS.js";import"./chunk-RRII2DMC.js";import"./chunk-KQCTDXVD.js";var z=o=>new TextEncoder().encode(JSON.stringify(o)).length,Q=16384;function H(o,f,r,i){if(i&&r&&(i.scope.projectId!==r.projectId||i.scope.environment!==r.environment))throw new s("SCOPE_MISMATCH","Configuration belongs to another App/environment");let p=0,I,c=m=>{I={config:structuredClone(m),until:Date.now()+3e4}},t=[],e=null,a,l=new Set;function E(){if(!f())throw new s("NOT_IDENTIFIED","Call identify before using Features or events")}function P(){a||!t.length||(a=setTimeout(()=>{a=void 0,N().catch(()=>{}).finally(P)},5e3),typeof a=="object"&&"unref"in a&&a.unref())}function x(m,v={}){if(E(),I&&Date.now()<I.until&&!L(I.config,m))return;k();let h=n.trackEvents.request.parse({events:[{eventUuid:crypto.randomUUID(),timestamp:new Date().toISOString(),name:m,properties:v}]}).events[0];if(z({events:[h]})>Q)throw new s("INVALID_REQUEST","Event exceeds the delivery size limit");if(t.length>=500)throw new s("EVENT_QUEUE_FULL","Flush pending events before tracking more");t.push(structuredClone(h)),P()}async function N(m=!1){if(E(),e)return e;let v=p,h=(async()=>{let O={inserted:0,duplicates:0,rejected:0,skipped:0},C=t.length;for(;C&&v===p;){let A=[];for(let F of t.slice(0,Math.min(C,100))){if(A.length&&z({events:[...A,F]})>Q)break;A.push(F)}let g=n.trackEvents,w=g.response.parse(await o(g.path,g.request.parse({events:A}),g.method,{keepalive:m}));if(v!==p)throw new s("IDENTITY_CHANGED","Event identity changed during delivery");if(w.inserted+w.duplicates+w.rejected+w.skipped!==A.length)throw new s("INVALID_RESPONSE","Incomplete event acknowledgement");c(w.analyticsConfig),t.splice(0,A.length),C-=A.length,O.inserted+=w.inserted,O.duplicates+=w.duplicates,O.rejected+=w.rejected,O.skipped+=w.skipped}return O})();e=h;try{return await h}finally{e===h&&(e=null)}}async function J(m={}){i||E();let v=p,h=!1,O=async()=>{if(h||v!==p)throw new s("IDENTITY_CHANGED","Feature identity changed");let y=n.getFeatures,d=i?{scope:{projectId:i.scope.projectId,environment:i.scope.environment},payload:await i.features()}:y.response.parse(await o(y.path,y.request.parse({}),y.method));if(v!==p)throw new s("IDENTITY_CHANGED","Feature identity changed");if(r&&(d.scope.projectId!==r.projectId||d.scope.environment!==r.environment))throw new s("INVALID_RESPONSE","Feature response scope changed");return c(d.payload.analyticsConfig),d},C=await O(),A=!0,g,w=y=>{try{m.onError?.(y)}catch{}},F=(y,d)=>{try{x(y,d)}catch(S){w(S)}},R=_({assertUsable:i?.assertFeatures,scope:C.scope,attributes:m.attributes,onError:m.onError,load:async()=>A?(A=!1,C.payload):(await O()).payload,evaluateRemote:async y=>{if(v!==p)throw new s("IDENTITY_CHANGED","Feature identity changed");let d=n.evaluateFeatures,S=d.response.parse(await o(d.path,d.request.parse(y),d.method));if(S.scope.projectId!==C.scope.projectId||S.scope.environment!==C.scope.environment)throw new s("INVALID_RESPONSE","Remote Feature response scope changed");return{generation:S.generation,evaluatedAt:S.evaluatedAt,expiresAt:S.expiresAt,features:S.features}},onExperimentViewed:(y,d)=>F("Experiment Viewed",{experimentId:y.key,variationId:d.key}),onFeatureUsage:(y,d)=>F("Feature Evaluated",{feature:y,value:d.value,source:d.source,ruleId:d.ruleId,...d.experimentResult?{variationId:d.experimentResult.key}:{}})}),M=R.refresh;function D(){clearTimeout(g),!i&&(h||v!==p||!R.expiresAt||(g=setTimeout(()=>{b().catch(w)},Math.min(2147483647,Math.max(1e3,Date.parse(R.expiresAt)-Date.now()))),typeof g=="object"&&"unref"in g&&g.unref()))}async function b(){try{return await M()}finally{D()}}let U=()=>{h||b().catch(w)},Y=R.subscribe(D),K=i?.subscribe(()=>{!h&&i.fresh&&b().catch(w)});function q(){h||(h=!0,clearTimeout(g),typeof window<"u"&&window.removeEventListener("focus",U),Y(),K?.(),R.reset(),l.delete(q))}l.add(q);try{await R.init()}catch(y){throw q(),y}return D(),!i&&typeof window<"u"&&window.addEventListener("focus",U),Object.assign(R,{refresh:b,destroy:q})}let T;function k(){if(T||typeof document>"u")return;let m=()=>{document.visibilityState==="hidden"&&f()&&t.length&&N(!0).catch(()=>{})};document.addEventListener("visibilitychange",m),T=()=>document.removeEventListener("visibilitychange",m)}return{features:J,track(m,v){return k(),x(m,v)},flush:N,reset(){p++,I=void 0,clearTimeout(a),a=void 0,t=[],e=null;for(let m of l)m();T?.(),T=void 0}}}function G(o,f){let r="source"in f?{funnelId:f.source.id,funnelVersionId:f.source.versionId}:"versionId"in f?{funnelId:f.funnelId,funnelVersionId:f.versionId}:f,i=n.grantOffer.request.pick({funnelId:!0,funnelVersionId:!0}).required({funnelId:!0}).safeParse(r);if(!i.success)throw new s("INVALID_REQUEST","A valid Funnel source is required");let p=Object.freeze(i.data);function I(c){if("customerId"in c)throw new s("INVALID_REQUEST","Customer identity cannot be overridden");if("funnelId"in c&&c.funnelId!==void 0&&c.funnelId!==p.funnelId||"funnelVersionId"in c&&c.funnelVersionId!==void 0&&c.funnelVersionId!==p.funnelVersionId)throw new s("SCOPE_MISMATCH","The original Funnel source cannot change");return{...c,...p}}return{async claimCoupon(c,t=crypto.randomUUID()){let e=n.grantOffer,a=e.response.parse(await o(e.path,e.request.parse(I({couponId:c,requestId:t}))));return{offer:a.offer,reason:a.reason}},async resolveOffering(c){let t=n.resolveOffering;return t.response.parse(await o(t.path,t.request.parse(I(c))))},async resolvePaywall(c){let t=n.resolvePaywall;return t.response.parse(await o(t.path,t.request.parse(I(c))))},async previewAttach(c){let t=n.previewAttach;return t.response.parse(await o(t.path,t.request.parse(I(c))))}}}function se(o){if(!/^gg_ct_[A-Za-z0-9_-]{32,128}$/.test(o.customerToken))throw new s("INVALID_TOKEN","A customer credential is required");if(!o.scope)throw new s("INVALID_REQUEST","An explicit App and environment scope is required");let f=j({...o,scope:o.scope,apiKey:o.customerToken});return{async start(r){let i=await f.start(r),p=V({...o,runToken:i.runToken});p.identify(o.customerToken);let I=["evaluate","evaluate_segment"].includes(i.run.instruction?.type??"")?await p.get():i;return{...i,...I,controller:p}}}}function u(o){if(o!==null&&typeof o=="object"&&"customerId"in o)throw new s("INVALID_REQUEST","Customer requests use the verified session identity")}function ge(o){let f=B(o),r=f.request,i=!1,p=H(r,()=>i,o.scope,o.configuration),I=new Set,c=t=>{for(let e of I)try{e(t)}catch{}};return{forFunnel(t){return G(r,t)},async features(t={}){return p.features(t)},track(t,e){return p.track(t,e)},flush(){return p.flush()},async setupPayment(t){u(t);let e=n.setupPayment;return e.response.parse(await r(e.path,e.request.parse(t)))},async readPaymentSetup(t){u(t);let e=n.readPaymentSetup;return e.response.parse(await r(e.path,e.request.parse(t)))},async previewUpdate(t){u(t);let e=n.previewUpdate;return e.response.parse(await r(e.path,e.request.parse(t)))},async update(t){u(t);let e=n.update;return e.response.parse(await r(e.path,e.request.parse(t)))},async readSubscriptionUpdate(t){u(t);let e=n.readSubscriptionUpdate;return e.response.parse(await r(e.path,e.request.parse(t)))},async restoreNativePurchase(t){u(t);let e=n.restoreNativePurchase;return e.response.parse(await r(e.path,e.request.parse(t)))},async previewAttach(t){u(t);let e=n.previewAttach;return e.response.parse(await r(e.path,e.request.parse(t)))},async attach(t){u(t);let e=n.attach;return e.response.parse(await r(e.path,e.request.parse(t)))},async readSubscriptionOperation(t){u(t);let e=n.readSubscriptionOperation;return e.response.parse(await r(e.path,e.request.parse(t)))},async checkEntitlement(t){u(t);let e=n.checkEntitlement;return e.response.parse(await r(e.path,e.request.parse(t)))},async resolvePaywall(t){u(t);let e=n.resolvePaywall;return e.response.parse(await r(e.path,e.request.parse(t)))},async resolveOffering(t){u(t);let e=n.resolveOffering;return e.response.parse(await r(e.path,e.request.parse(t)))},async readHoldings(t={}){let e=n.readHoldings;return e.response.parse(await r(e.path,e.request.omit({customerId:!0}).parse(t)))},async readLedger(t){let e=n.readLedger;return e.response.parse(await r(e.path,e.request.parse({query:t})))},async readBillingInvoice(t){u(t);let e=n.readBillingInvoice;return e.response.parse(await r(e.path,e.request.parse(t)))},async readCreditStatement(t){u(t);let e=n.readCreditStatement;return e.response.parse(await r(e.path,e.request.parse(t)))},async quoteBalance(t){u(t);let e=n.quoteBalance;return e.response.parse(await r(e.path,e.request.parse({command:t})))},async readBillingControls(t={}){u(t);let e=n.readBillingControls;return e.response.parse(await r(e.path,e.request.parse(t)))},async prepareBillingAuthorization(t){u(t);let e=n.prepareBillingAuthorization;return e.response.parse(await r(e.path,e.request.parse(t)))},async confirmBillingAuthorization(t){u(t);let e=n.confirmBillingAuthorization;return e.response.parse(await r(e.path,e.request.parse(t)))},async setBillingCoupons(t){u(t);let e=n.setBillingCoupons,a=e.request.safeParse(t);if(!a.success)throw new s("INVALID_REQUEST","Invalid billing coupon list");let l=e.response.safeParse(await r(e.path,a.data));if(!l.success)throw new s("INVALID_RESPONSE","Invalid billing coupon receipt");return l.data},async revokeBillingAuthorization(t){u(t);let e=n.revokeBillingAuthorization;return e.response.parse(await r(e.path,e.request.parse(t)))},async listBillingInvoices(t={after:null,limit:25}){u(t);let e=n.listBillingInvoices;return e.response.parse(await r(e.path,e.request.parse(t)))},async confirmBillingAdjustment(t){u(t);let e=n.confirmBillingAdjustment;return e.response.parse(await r(e.path,e.request.parse(t)))},subscribeIdentity(t){return I.add(t),()=>{I.delete(t)}},identify(t){if(!/^gg_ct_[A-Za-z0-9_-]{43}$/.test(t))throw new s("INVALID_TOKEN","Browser SDK requires a customer session");p.reset(),f.identify(t),i=!0,c(!0)},reset(){i=!1,p.reset(),f.reset(),c(!1)},async redeemReward(t){u(t);let e=n.redeemReward,a=e.request.safeParse({...t,requestId:t.requestId??crypto.randomUUID()});if(!a.success)throw new s("INVALID_REQUEST","Invalid reward redemption");let l=e.response.safeParse(await r(e.path,a.data));if(!l.success)throw new s("INVALID_RESPONSE","Invalid reward receipt");return l.data.redemption},async claimRewardProduct(t){u(t);let e=n.claimRewardProduct,a=e.request.safeParse(t);if(!a.success)throw new s("INVALID_REQUEST","Invalid reward product claim");let l=e.response.safeParse(await r(e.path,a.data));if(!l.success)throw new s("INVALID_RESPONSE","Invalid reward product checkout");return l.data.checkout},async createReferralCode(t){u(t);let e=n.createReferralCode,a=e.request.safeParse({...t,requestId:t.requestId??crypto.randomUUID()});if(!a.success)throw new s("INVALID_REQUEST","Invalid referral program");let l=e.response.safeParse(await r(e.path,a.data));if(!l.success)throw new s("INVALID_RESPONSE","Invalid referral code");return l.data.referralCode},async redeemCoupon(t,e=crypto.randomUUID()){let a=n.redeemCoupon,l=a.request.safeParse({code:t,requestId:e});if(!l.success)throw new s("INVALID_REQUEST","Invalid coupon code");let E=a.response.safeParse(await r(a.path,l.data));if(!E.success)throw new s("INVALID_RESPONSE","Invalid Coupon receipt");let P=E.data;return{offer:P.offer,reason:P.reason}},async claimCoupon(t,e=crypto.randomUUID()){let a=n.grantOffer,l=a.request.safeParse({couponId:t,requestId:e});if(!l.success)throw new s("INVALID_REQUEST","Invalid Coupon claim");let E=a.response.safeParse(await r(a.path,l.data));if(!E.success)throw new s("INVALID_RESPONSE","Invalid Coupon receipt");return{offer:E.data.offer,reason:E.data.reason}},async listOffers(){let t=n.listOffers.response.safeParse(await r("offers",{},"GET"));if(!t.success)throw new s("INVALID_RESPONSE","Invalid offers response");return t.data.offers}}}async function Ee(...o){return(await import("./paywall-WKOHBYW7.js")).showPaywall(...o)}async function Ae(...o){return(await import("./funnel-runtime-host-26QI2W3S.js")).showFunnelRun(...o)}export{s as IndianaError,X as createBrowserFunnelCommandStorage,te as createConfigurationSync,_ as createFeatureClient,se as createFunnelClient,V as createFunnelRunController,ge as createIndiana,ne as createLocalFunnelClient,ee as createPaywallSession,re as evaluateFunnelNode,$ as formatCouponDiscount,Z as formatCouponMoney,W as formatCouponTerms,Ae as showFunnelRun,Ee as showPaywall};
1
+ import{a as k,f as te,i as D,j as ne,k as re,l as oe,m as V,n as ie}from"./chunk-56AYS7RS.js";import"./chunk-YWFNWK7C.js";import{a as o}from"./chunk-KSNOXNTC.js";import{a as B}from"./chunk-AEUFCOFG.js";import{ei as r,fe as N,ga as W,ha as X,ia as ee,ri as P}from"./chunk-F767CM3T.js";import{a as p}from"./chunk-6HG7U6AU.js";import"./chunk-3BQFJANQ.js";import"./chunk-AE4CUTUE.js";import"./chunk-EXCPE2XH.js";import"./chunk-RRII2DMC.js";import"./chunk-KQCTDXVD.js";function _(t,e){let n=!1,a=new Set,s=u=>{for(let i of a)try{i(u)}catch{}};return{isIdentified:()=>n,methods:{subscribeIdentity(u){return a.add(u),()=>{a.delete(u)}},identify(u){if(!/^gg_ct_[A-Za-z0-9_-]{43}$/.test(u))throw new p("INVALID_TOKEN","Browser SDK requires a customer session");n=!1,t.reset(),e(),t.identify(u),n=!0,s(!0)},reset(){n=!1,t.reset(),e(),s(!1)}}}}function c(t){if(t!==null&&typeof t=="object"&&"customerId"in t)throw new p("INVALID_REQUEST","Customer requests use the verified session identity")}function U(t){return{async checkEntitlement(e){c(e);let n=r.checkEntitlement;return o(t,n,e)},async readHoldings(e={}){let n=r.readHoldings;return o(t,{...n,request:n.request.omit({customerId:!0})},e)}}}function j(t){return{async readLedger(e){let n=r.readLedger;return o(t,n,{query:e})},async readCreditStatement(e){c(e);let n=r.readCreditStatement;return o(t,n,e)},async quoteBalance(e){c(e);let n=r.quoteBalance;return o(t,n,{command:e})}}}function q(t){return{async setupPayment(e){c(e);let n=r.setupPayment;return o(t,n,e)},async readPaymentSetup(e){c(e);let n=r.readPaymentSetup;return o(t,n,e)},async readBillingInvoice(e){c(e);let n=r.readBillingInvoice;return o(t,n,e)},async readBillingControls(e={}){c(e);let n=r.readBillingControls;return o(t,n,e)},async prepareBillingAuthorization(e){c(e);let n=r.prepareBillingAuthorization;return o(t,n,e)},async confirmBillingAuthorization(e){c(e);let n=r.confirmBillingAuthorization;return o(t,n,e)},async setBillingCoupons(e){c(e);let n=r.setBillingCoupons;return o(t,n,e,{request:"Invalid billing coupon list",response:"Invalid billing coupon receipt"})},async revokeBillingAuthorization(e){c(e);let n=r.revokeBillingAuthorization;return o(t,n,e)},async listBillingInvoices(e={after:null,limit:25}){c(e);let n=r.listBillingInvoices;return o(t,n,e)},async confirmBillingAdjustment(e){c(e);let n=r.confirmBillingAdjustment;return o(t,n,e)}}}function L(t){return{async previewUpdate(e){c(e);let n=r.previewUpdate;return o(t,n,e)},async update(e){c(e);let n=r.update;return o(t,n,e)},async readSubscriptionUpdate(e){c(e);let n=r.readSubscriptionUpdate;return o(t,n,e)},async restoreNativePurchase(e){c(e);let n=r.restoreNativePurchase;return o(t,n,e)},async previewAttach(e){c(e);let n=r.previewAttach;return o(t,n,e)},async attach(e){c(e);let n=r.attach;return o(t,n,e)},async readSubscriptionOperation(e){c(e);let n=r.readSubscriptionOperation;return o(t,n,e)}}}function z(t){return{async redeemReward(e){return c(e),(await o(t,r.redeemReward,{...e,requestId:e.requestId??crypto.randomUUID()},{request:"Invalid reward redemption",response:"Invalid reward receipt"})).redemption},async claimRewardProduct(e){return c(e),(await o(t,r.claimRewardProduct,e,{request:"Invalid reward product claim",response:"Invalid reward product checkout"})).checkout},async createReferralCode(e){return c(e),(await o(t,r.createReferralCode,{...e,requestId:e.requestId??crypto.randomUUID()},{request:"Invalid referral program",response:"Invalid referral code"})).referralCode},async redeemCoupon(e,n=crypto.randomUUID()){let a=await o(t,r.redeemCoupon,{code:e,requestId:n},{request:"Invalid coupon code",response:"Invalid Coupon receipt"});return{offer:a.offer,reason:a.reason}},async claimCoupon(e,n=crypto.randomUUID()){let a=await o(t,r.grantOffer,{couponId:e,requestId:n},{request:"Invalid Coupon claim",response:"Invalid Coupon receipt"});return{offer:a.offer,reason:a.reason}},async listOffers(){return(await o(t,r.listOffers,{},{response:"Invalid offers response"})).offers}}}function H(t){return{...U(t),...j(t),...q(t),...L(t),...z(t)}}function J(t){return{async resolveContent(e){c(e);let n=r.resolveContent;return o(t,n,e)},async resolvePaywall(e){c(e);let n=r.resolvePaywall;return o(t,n,e)},async resolveOffering(e){c(e);let n=r.resolveOffering;return o(t,n,e)}}}var M=t=>new TextEncoder().encode(JSON.stringify(t)).length,Q=16384;function G(t,e){let n=0,a,s=m=>{a={config:structuredClone(m),until:Date.now()+3e4}},u=[],i=null,l;function F(){if(!e())throw new p("NOT_IDENTIFIED","Call identify before using Features or events")}function v(){l||!u.length||(l=setTimeout(()=>{l=void 0,h().catch(()=>{}).finally(v)},5e3),typeof l=="object"&&"unref"in l&&l.unref())}function O(m,y={}){if(F(),a&&Date.now()<a.until&&!N(a.config,m))return;b();let w=r.trackEvents.request.parse({events:[{eventUuid:crypto.randomUUID(),timestamp:new Date().toISOString(),name:m,properties:y}]}).events[0];if(M({events:[w]})>Q)throw new p("INVALID_REQUEST","Event exceeds the delivery size limit");if(u.length>=500)throw new p("EVENT_QUEUE_FULL","Flush pending events before tracking more");u.push(structuredClone(w)),v()}async function h(m=!1){if(F(),i)return i;let y=n,w=(async()=>{let A={inserted:0,duplicates:0,rejected:0,skipped:0},g=u.length;for(;g&&y===n;){let C=[];for(let x of u.slice(0,Math.min(g,100))){if(C.length&&M({events:[...C,x]})>Q)break;C.push(x)}let S=r.trackEvents,f=await o(t,S,{events:C},void 0,{keepalive:m});if(y!==n)throw new p("IDENTITY_CHANGED","Event identity changed during delivery");if(f.inserted+f.duplicates+f.rejected+f.skipped!==C.length)throw new p("INVALID_RESPONSE","Incomplete event acknowledgement");s(f.analyticsConfig),u.splice(0,C.length),g-=C.length,A.inserted+=f.inserted,A.duplicates+=f.duplicates,A.rejected+=f.rejected,A.skipped+=f.skipped}return A})();i=w;try{return await w}finally{i===w&&(i=null)}}let R;function b(){if(R||typeof document>"u")return;let m=()=>{document.visibilityState==="hidden"&&e()&&u.length&&h(!0).catch(()=>{})};document.addEventListener("visibilitychange",m),R=()=>document.removeEventListener("visibilitychange",m)}return{rememberConfiguration:s,track(m,y){return b(),O(m,y)},flush:h,reset(){n++,a=void 0,clearTimeout(l),l=void 0,u=[],i=null},detachVisibility(){R?.(),R=void 0}}}function Y(t,e,n,a,s){if(s&&a&&(s.scope.projectId!==a.projectId||s.scope.environment!==a.environment))throw new p("SCOPE_MISMATCH","Configuration belongs to another App/environment");let u=0,i=new Set;function l(){if(!e())throw new p("NOT_IDENTIFIED","Call identify before using Features or events")}async function F(v={}){s||l();let O=u,h=!1,R=async()=>{if(h||O!==u)throw new p("IDENTITY_CHANGED","Feature identity changed");let I=r.getFeatures,d=s?{scope:{projectId:s.scope.projectId,environment:s.scope.environment},payload:await s.features()}:await o(t,I,{});if(O!==u)throw new p("IDENTITY_CHANGED","Feature identity changed");if(a&&(d.scope.projectId!==a.projectId||d.scope.environment!==a.environment))throw new p("INVALID_RESPONSE","Feature response scope changed");return n.rememberConfiguration(d.payload.analyticsConfig),d},b=await R(),m=!0,y,w=I=>{try{v.onError?.(I)}catch{}},A=(I,d)=>{try{n.track(I,d)}catch(E){w(E)}},g=k({assertUsable:s?.assertFeatures,scope:b.scope,attributes:v.attributes,onError:v.onError,load:async()=>m?(m=!1,b.payload):(await R()).payload,evaluateRemote:async I=>{if(O!==u)throw new p("IDENTITY_CHANGED","Feature identity changed");let d=r.evaluateFeatures,E=await o(t,d,I);if(E.scope.projectId!==b.scope.projectId||E.scope.environment!==b.scope.environment)throw new p("INVALID_RESPONSE","Remote Feature response scope changed");return{generation:E.generation,evaluatedAt:E.evaluatedAt,expiresAt:E.expiresAt,features:E.features}},onExperimentViewed:(I,d)=>A("Experiment Viewed",{experimentId:I.key,variationId:d.key}),onFeatureUsage:(I,d)=>A("Feature Evaluated",{feature:I,value:d.value,source:d.source,ruleId:d.ruleId,...d.experimentResult?{variationId:d.experimentResult.key}:{}})}),C=g.refresh;function S(){clearTimeout(y),!s&&(h||O!==u||!g.expiresAt||(y=setTimeout(()=>{f().catch(w)},Math.min(2147483647,Math.max(1e3,Date.parse(g.expiresAt)-Date.now()))),typeof y=="object"&&"unref"in y&&y.unref()))}async function f(){try{return await C()}finally{S()}}let x=()=>{h||f().catch(w)},Z=g.subscribe(S),$=s?.subscribe(()=>{!h&&s.fresh&&f().catch(w)});function T(){h||(h=!0,clearTimeout(y),typeof window<"u"&&window.removeEventListener("focus",x),Z(),$?.(),g.reset(),i.delete(T))}i.add(T);try{await g.init()}catch(I){throw T(),I}return S(),!s&&typeof window<"u"&&window.addEventListener("focus",x),Object.assign(g,{refresh:f,destroy:T})}return{features:F,reset(v){u++,v();for(let O of i)O()}}}import{z as ae}from"zod";function K(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,a=ae.object({funnelId:P.shape.id,funnelVersionId:P.shape.versionId.optional()}).safeParse(n);if(!a.success)throw new p("INVALID_REQUEST","A valid Funnel source is required");let s=Object.freeze(a.data);function u(i){if("customerId"in i)throw new p("INVALID_REQUEST","Customer identity cannot be overridden");if("funnelId"in i&&i.funnelId!==void 0&&i.funnelId!==s.funnelId||"funnelVersionId"in i&&i.funnelVersionId!==void 0&&i.funnelVersionId!==s.funnelVersionId)throw new p("SCOPE_MISMATCH","The original Funnel source cannot change");return{...i,...s}}return{async claimCoupon(i,l=crypto.randomUUID()){let F=r.grantOffer,v=await o(t,F,u({couponId:i,requestId:l}));return{offer:v.offer,reason:v.reason}},async resolveOffering(i){let l=r.resolveOffering;return o(t,l,u(i))},async resolvePaywall(i){let l=r.resolvePaywall;return o(t,l,u(i))},async previewAttach(i){let l=r.previewAttach;return o(t,l,u(i))}}}function se(t){let e=B(t),n=e.request,a=_(e,()=>{u.reset(s.reset),s.detachVisibility()}),s=G(n,a.isIdentified),u=Y(n,a.isIdentified,s,t.scope,t.configuration);return{...H(n),...J(n),forFunnel(i){return K(n,i)},async features(i={}){return u.features(i)},track(i,l){return s.track(i,l)},flush(){return s.flush()},...a.methods}}function ue(t){if(!/^gg_ct_[A-Za-z0-9_-]{32,128}$/.test(t.customerToken))throw new p("INVALID_TOKEN","A customer credential is required");if(!t.scope)throw new p("INVALID_REQUEST","An explicit App and environment scope is required");let e=V({...t,scope:t.scope,apiKey:t.customerToken});return{async start(n){let a=await e.start(n),s=D({...t,runToken:a.runToken});s.identify(t.customerToken);let u=["evaluate","evaluate_segment"].includes(a.run.instruction?.type??"")?await s.get():a;return{...a,...u,controller:s}}}}async function yt(...t){return(await import("./paywall-MXRMMF3R.js")).showPaywall(...t)}async function It(...t){return(await import("./funnel-runtime-host-CAMI6BJS.js")).showFunnelRun(...t)}async function vt(...t){return(await import("./content-YNL2CRJZ.js")).mountContent(...t)}export{p as IndianaError,te as createBrowserFunnelCommandStorage,re as createConfigurationSync,k as createFeatureClient,ue as createFunnelClient,D as createFunnelRunController,se as createIndiana,ie as createLocalFunnelClient,ne as createPaywallSession,oe as evaluateFunnelNode,X as formatCouponDiscount,W as formatCouponMoney,ee as formatCouponTerms,vt as mountContent,It as showFunnelRun,yt as showPaywall};