@tinkerlandai/indiana-sdk 0.6.2 → 0.6.4

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 (47) hide show
  1. package/CHANGELOG.md +17 -1
  2. package/README.md +10 -6
  3. package/README.zh-CN.md +9 -5
  4. package/THIRD_PARTY_NOTICES.md +28 -0
  5. package/dist/{chunk-M3DG6ZCT.js → chunk-2EJSV6BA.js} +1 -1
  6. package/dist/chunk-4K25DELJ.js +1 -0
  7. package/dist/chunk-63BWE27V.js +1 -0
  8. package/dist/chunk-CB63JLGT.js +1 -0
  9. package/dist/{chunk-N6UIDDAX.js → chunk-D7YHFS6B.js} +2 -2
  10. package/dist/chunk-HTRQPMJO.js +11 -0
  11. package/dist/chunk-ISUXYPYL.js +1 -0
  12. package/dist/chunk-QG3WUJG5.js +1 -0
  13. package/dist/chunk-U6S6AZM6.js +1 -0
  14. package/dist/chunk-VVSQKVE7.js +1 -0
  15. package/dist/client-OYRHOMUQ.js +1 -0
  16. package/dist/{configuration-sync-Bnu8s4pc.d.ts → configuration-sync-C2mytNwU.d.ts} +18 -0
  17. package/dist/errors-DrdTlPwf.d.ts +57 -0
  18. package/dist/funnel-runtime-host-NWS3URFA.js +1 -0
  19. package/dist/{funnel-runtime-start-Zbd5ro5r.d.ts → funnel-runtime-start-sZ8ZCNlq.d.ts} +42 -58
  20. package/dist/iam.d.ts +131 -0
  21. package/dist/iam.js +1 -0
  22. package/dist/index.d.ts +41 -4
  23. package/dist/index.js +1 -1
  24. package/dist/native-shell.js +1 -1
  25. package/dist/openrouter.js +1 -1
  26. package/dist/page.d.ts +1 -1
  27. package/dist/page.js +1 -1
  28. package/dist/paywall-4XZ6NDMY.js +1 -0
  29. package/dist/popup.d.ts +2 -5
  30. package/dist/popup.js +3 -14
  31. package/dist/react-native.d.ts +327 -0
  32. package/dist/react-native.js +1 -0
  33. package/dist/server.d.ts +4 -3
  34. package/dist/server.js +1 -1
  35. package/dist/src-WV6GZYWA.js +1 -0
  36. package/dist/visual.d.ts +10 -1
  37. package/dist/visual.js +2 -1
  38. package/package.json +15 -2
  39. package/dist/chunk-BIFEEVQO.js +0 -1
  40. package/dist/chunk-ET4NANGB.js +0 -1
  41. package/dist/chunk-J7M7UH74.js +0 -1
  42. package/dist/chunk-OHDY27EI.js +0 -1
  43. package/dist/chunk-VMLGV5OS.js +0 -11
  44. package/dist/funnel-runtime-host-3STQUS6F.js +0 -1
  45. package/dist/paywall-LBDMGVWZ.js +0 -1
  46. package/dist/src-X6KT6WIH.js +0 -1
  47. package/dist/visual-editor-agent-WW65CMKW.js +0 -1
package/dist/index.d.ts CHANGED
@@ -1,14 +1,15 @@
1
1
  import * as zod from 'zod';
2
2
  import { z } from 'zod';
3
- import { F as FunnelRuntimeResponse, a as FunnelRunView, b as FunnelCommand, c as FunnelPurchaseRecovery, d as FunnelDataQueries, I as IndianaOptions, P as PaywallSession, S as SubscriptionOperation, e as FeatureClientOptions, f as FunnelCommandStorage, g as FunnelStartInput, R as RemoteFeatureResult } from './funnel-runtime-start-Zbd5ro5r.js';
4
- export { h as FeatureClient, i as FunnelNodeEvaluationContext, j as FunnelPendingEntry, k as IndianaError, L as LocalFunnelClient, l as LocalFunnelClientOptions, m as PaywallPurchaseInput, n as PaywallStartInput, o as createFeatureClient, p as createLocalFunnelClient, q as createPaywallSession, r as evaluateFunnelNode } from './funnel-runtime-start-Zbd5ro5r.js';
3
+ import { F as FunnelRuntimeResponse, a as FunnelRunView, b as FunnelCommand, c as FunnelPurchaseRecovery, d as FunnelDataQueries, I as IndianaOptions, P as PaywallSession, S as SubscriptionOperation, e as FeatureClientOptions, f as FunnelCommandStorage, g as FunnelStartInput, R as RemoteFeatureResult } from './funnel-runtime-start-sZ8ZCNlq.js';
4
+ export { h as FeatureClient, i as FunnelNodeEvaluationContext, j as FunnelPendingEntry, L as LocalFunnelClient, k as LocalFunnelClientOptions, l as PaywallPurchaseInput, m as PaywallStartInput, n as createFeatureClient, o as createLocalFunnelClient, p as createPaywallSession, q as evaluateFunnelNode } from './funnel-runtime-start-sZ8ZCNlq.js';
5
5
  import { C as CouponInput, a as CustomerDataIntent, O as Offer } from './customer-page-B4FGCVpt.js';
6
6
  export { b as OfferUnavailableReason } from './customer-page-B4FGCVpt.js';
7
7
  import { O as OfferingItem, I as InvoiceModeParams, A as ApiInput } from './ai-usage-B4W5m4Ie.js';
8
8
  import { S as StackNode } from './screen-16d-xADb.js';
9
- import { C as ConfigurationSync } from './configuration-sync-Bnu8s4pc.js';
10
- export { a as ConfigurationStorage, b as ConfigurationSyncOptions, c as createConfigurationSync } from './configuration-sync-Bnu8s4pc.js';
9
+ import { C as ConfigurationSync } from './configuration-sync-C2mytNwU.js';
10
+ export { a as ConfigurationStorage, b as ConfigurationSyncOptions, c as createConfigurationSync } from './configuration-sync-C2mytNwU.js';
11
11
  import { J as JsonValue, F as FeatureResult } from './growth-rules-B4YYy64R.js';
12
+ export { I as IndianaError } from './errors-DrdTlPwf.js';
12
13
  import '@ai-sdk/provider';
13
14
  import 'zod/v4';
14
15
 
@@ -746,6 +747,24 @@ declare function createFunnelRunController(options: IndianaOptions & {
746
747
  failed: string;
747
748
  id: string;
748
749
  name: string;
750
+ appManifest?: {
751
+ versionId: string;
752
+ manifestDigest: string;
753
+ sourceGraphDigest: string;
754
+ pageKey: string;
755
+ stateKey: string;
756
+ documentKey: string;
757
+ documentHash: string;
758
+ elementKey?: string | undefined;
759
+ nodeId?: string | undefined;
760
+ contentHash?: string | undefined;
761
+ renderKey?: string | undefined;
762
+ observed?: {
763
+ versionId: string;
764
+ sha256: string;
765
+ contentHash: string;
766
+ } | undefined;
767
+ } | undefined;
749
768
  position?: {
750
769
  x: number;
751
770
  y: number;
@@ -8553,6 +8572,24 @@ declare function createFunnelClient(options: IndianaOptions & {
8553
8572
  failed: string;
8554
8573
  id: string;
8555
8574
  name: string;
8575
+ appManifest?: {
8576
+ versionId: string;
8577
+ manifestDigest: string;
8578
+ sourceGraphDigest: string;
8579
+ pageKey: string;
8580
+ stateKey: string;
8581
+ documentKey: string;
8582
+ documentHash: string;
8583
+ elementKey?: string | undefined;
8584
+ nodeId?: string | undefined;
8585
+ contentHash?: string | undefined;
8586
+ renderKey?: string | undefined;
8587
+ observed?: {
8588
+ versionId: string;
8589
+ sha256: string;
8590
+ contentHash: string;
8591
+ } | undefined;
8592
+ } | undefined;
8556
8593
  position?: {
8557
8594
  x: number;
8558
8595
  y: number;
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{a as _,e as X,h as ee,i as V,j as te,k as re,l as j,m as ne}from"./chunk-J7M7UH74.js";import{a as B}from"./chunk-ET4NANGB.js";import{a as s}from"./chunk-5TEZEOHX.js";import"./chunk-S5TVMQRC.js";import{Vf as n,W as Z,X as $,Y as W,wf as L}from"./chunk-VMLGV5OS.js";import"./chunk-RMJJOSVZ.js";import"./chunk-OHDY27EI.js";import"./chunk-S2MSIA57.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=i.run.instruction?.type==="evaluate"?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-LBDMGVWZ.js")).showPaywall(...o)}async function Ae(...o){return(await import("./funnel-runtime-host-3STQUS6F.js")).showFunnelRun(...o)}export{s as IndianaError,ee as createBrowserFunnelCommandStorage,re as createConfigurationSync,_ as createFeatureClient,se as createFunnelClient,V as createFunnelRunController,ge as createIndiana,ne as createLocalFunnelClient,te as createPaywallSession,X as evaluateFunnelNode,$ as formatCouponDiscount,Z as formatCouponMoney,W as formatCouponTerms,Ae as showFunnelRun,Ee as showPaywall};
1
+ import{a as _,g as X,h as V,i as ee,j as te,k as re,l as j,m as ne}from"./chunk-63BWE27V.js";import{a as B}from"./chunk-QG3WUJG5.js";import{Vf as n,W as Z,X as $,Y as W,wf as L}from"./chunk-HTRQPMJO.js";import"./chunk-S5TVMQRC.js";import"./chunk-ISUXYPYL.js";import"./chunk-U6S6AZM6.js";import"./chunk-4K25DELJ.js";import{a as s}from"./chunk-5TEZEOHX.js";import"./chunk-RMJJOSVZ.js";import"./chunk-S2MSIA57.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=i.run.instruction?.type==="evaluate"?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-4XZ6NDMY.js")).showPaywall(...o)}async function Ae(...o){return(await import("./funnel-runtime-host-NWS3URFA.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};