@tinkerlandai/longplay-sdk 0.10.35 → 0.10.37

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 (108) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/README.md +42 -3
  3. package/README.zh-CN.md +14 -0
  4. package/dist/{ai-usage-T62xehqa.d.ts → ai-usage-DXwAGTxT.d.ts} +1 -1
  5. package/dist/{api-Do-6AyWa.d.ts → api-r6FfVQpg.d.ts} +6 -1
  6. package/dist/check-response-N22NNTIT.js +1 -0
  7. package/dist/chunk-2HBIBIOF.js +1 -0
  8. package/dist/{chunk-73NP72FV.js → chunk-2KJLN65C.js} +1 -1
  9. package/dist/{chunk-RML52BOR.js → chunk-2VMEDQHT.js} +1 -1
  10. package/dist/{chunk-CIP5SQ5Y.js → chunk-4KLXQKNO.js} +1 -1
  11. package/dist/{chunk-FMDC6N4W.js → chunk-6F4JS3RK.js} +1 -1
  12. package/dist/{chunk-56BYGPQ6.js → chunk-7XDQKZYA.js} +1 -1
  13. package/dist/{chunk-VEX2FOFZ.js → chunk-AB7GEGZ2.js} +1 -1
  14. package/dist/{chunk-EM3MGDPG.js → chunk-AHUYZ6IW.js} +1 -1
  15. package/dist/chunk-AOGDCT4T.js +1 -0
  16. package/dist/{chunk-EUTWY7A2.js → chunk-CY7OKV7E.js} +1 -1
  17. package/dist/{chunk-7MNJH5GB.js → chunk-D3OYXTMC.js} +1 -1
  18. package/dist/chunk-DDLSQSWO.js +10 -0
  19. package/dist/{chunk-5HJYR6Z4.js → chunk-E7CCHUSO.js} +1 -1
  20. package/dist/{chunk-BOVN2BE3.js → chunk-ECKVJGXQ.js} +1 -1
  21. package/dist/chunk-GH6FM44P.js +1 -0
  22. package/dist/{chunk-TJGIT5CU.js → chunk-HEHLFHW7.js} +1 -1
  23. package/dist/chunk-HKXFCRVT.js +1 -0
  24. package/dist/chunk-KFIL73QY.js +1 -0
  25. package/dist/{chunk-44U3FOBB.js → chunk-LC6UCDWE.js} +1 -1
  26. package/dist/{chunk-KE26KWIU.js → chunk-LOLMUXHW.js} +1 -1
  27. package/dist/{chunk-7QL4GF4C.js → chunk-O4KXODTJ.js} +1 -1
  28. package/dist/{chunk-TLZP7BW6.js → chunk-OCWSWXCW.js} +1 -1
  29. package/dist/chunk-OQRMAU2B.js +1 -0
  30. package/dist/{chunk-SXBM3DWK.js → chunk-OX2A3UD2.js} +1 -1
  31. package/dist/{chunk-LF2UIJYD.js → chunk-PW5PIBSO.js} +1 -1
  32. package/dist/chunk-Q676H74B.js +1 -0
  33. package/dist/chunk-RE4OLOOT.js +1 -0
  34. package/dist/{chunk-CKKIB2HC.js → chunk-S43TYW3V.js} +1 -1
  35. package/dist/{chunk-U4RSRFZY.js → chunk-T2KWLYCW.js} +1 -1
  36. package/dist/chunk-TASEZY5T.js +1 -0
  37. package/dist/{chunk-OX7PA64E.js → chunk-U7NX5ET2.js} +1 -1
  38. package/dist/{chunk-WZR2XCSJ.js → chunk-UV4H6VCS.js} +1 -1
  39. package/dist/{chunk-MSK3VZ3A.js → chunk-VIBJNB5B.js} +1 -1
  40. package/dist/chunk-VLSP3LRH.js +1 -0
  41. package/dist/{chunk-W6OQTXLL.js → chunk-W74JLL2O.js} +1 -1
  42. package/dist/chunk-WQ3O5RXN.js +1 -0
  43. package/dist/chunk-WZMZMJCK.js +1 -0
  44. package/dist/chunk-XGNXZWZL.js +1 -0
  45. package/dist/{chunk-VYFSRHXM.js → chunk-XJRDO3NI.js} +1 -1
  46. package/dist/chunk-YV6UFESO.js +1 -0
  47. package/dist/{chunk-KPDHY76A.js → chunk-ZYOZSUZS.js} +1 -1
  48. package/dist/chunk-ZZIBLQCJ.js +1 -0
  49. package/dist/{configuration-sync-DdTRUv7A.d.ts → configuration-sync-BHrAf-ql.d.ts} +10 -1
  50. package/dist/content-QNBATPA2.js +1 -0
  51. package/dist/{funnel-host-purchase-Z7FCJ5CX.js → funnel-host-purchase-FVYPBPET.js} +1 -1
  52. package/dist/{funnel-local-client-Dz1dTgES.d.ts → funnel-local-client-DR8OpKGU.d.ts} +145 -3
  53. package/dist/funnel-paywall-prerender-Z7RA4YDY.js +1 -0
  54. package/dist/{funnel-process-client-D6qjStm2.d.ts → funnel-process-client-C87U4r_G.d.ts} +17 -3
  55. package/dist/funnel-runtime-host-TJPF3FJS.js +1 -0
  56. package/dist/index.d.ts +49 -12
  57. package/dist/index.js +1 -1
  58. package/dist/merchant-bridge-contracts-67AYXZFI.js +1 -0
  59. package/dist/native-shell.js +1 -1
  60. package/dist/openrouter.d.ts +3 -3
  61. package/dist/openrouter.js +1 -1
  62. package/dist/operation-contracts-EK4RCUWJ.js +1 -0
  63. package/dist/page.d.ts +2 -2
  64. package/dist/page.js +1 -1
  65. package/dist/paywall-OAVC654P.js +1 -0
  66. package/dist/paywall-content-75XEM7K3.js +1 -0
  67. package/dist/paywall-session-U6SPRJRS.js +1 -0
  68. package/dist/popup.d.ts +4 -4
  69. package/dist/popup.js +1 -1
  70. package/dist/{presentation-loading-CFSiS0VX.d.ts → presentation-loading-B_v5XZtM.d.ts} +11 -1
  71. package/dist/react-native.d.ts +7 -7
  72. package/dist/react-native.js +1 -1
  73. package/dist/{screen-CGCJ46b1.d.ts → screen-qUBRsUi9.d.ts} +26 -21
  74. package/dist/screen-renderer-YIIT742O.js +1 -0
  75. package/dist/server.d.ts +37 -7
  76. package/dist/server.js +1 -1
  77. package/dist/{visual-dom-6DCUZGPB.js → visual-dom-5LUN4AHO.js} +1 -1
  78. package/dist/visual.js +1 -1
  79. package/package.json +10 -9
  80. package/dist/check-response-GZZRWBEA.js +0 -1
  81. package/dist/chunk-2FE4FTPH.js +0 -1
  82. package/dist/chunk-BLVBUN2R.js +0 -1
  83. package/dist/chunk-BQRS7Y4K.js +0 -1
  84. package/dist/chunk-ETK6GC5P.js +0 -1
  85. package/dist/chunk-GZRRVHYK.js +0 -1
  86. package/dist/chunk-PUR5CYWX.js +0 -1
  87. package/dist/chunk-RNEF4MZW.js +0 -1
  88. package/dist/chunk-SFHIFCXG.js +0 -1
  89. package/dist/chunk-TAFALMQN.js +0 -1
  90. package/dist/chunk-TOTRALYQ.js +0 -10
  91. package/dist/chunk-UVRT4MY6.js +0 -1
  92. package/dist/chunk-V7MMTILA.js +0 -1
  93. package/dist/chunk-V7PFLFHE.js +0 -1
  94. package/dist/chunk-XUGEOELU.js +0 -1
  95. package/dist/chunk-YVXLCQGM.js +0 -1
  96. package/dist/chunk-ZGCKQWQ5.js +0 -1
  97. package/dist/content-AJDTSI7A.js +0 -1
  98. package/dist/funnel-paywall-prerender-QHCUZZY3.js +0 -1
  99. package/dist/funnel-runtime-host-UKSOOA4H.js +0 -1
  100. package/dist/merchant-bridge-contracts-EAE4HQE4.js +0 -1
  101. package/dist/operation-contracts-HS4M2UXN.js +0 -1
  102. package/dist/paywall-VYUBYBUI.js +0 -1
  103. package/dist/paywall-content-YQAVSO2T.js +0 -1
  104. package/dist/paywall-session-E5V42XUT.js +0 -1
  105. package/dist/screen-renderer-R5GH7XLV.js +0 -1
  106. /package/dist/{chunk-BID4UGWB.js → chunk-CILM5XMH.js} +0 -0
  107. /package/dist/{chunk-VF6QMMEA.js → chunk-CR2XJ2CX.js} +0 -0
  108. /package/dist/{chunk-UKMEW5I7.js → chunk-OJM6ORHE.js} +0 -0
package/dist/index.d.ts CHANGED
@@ -1,18 +1,18 @@
1
1
  import { z } from 'zod';
2
- import { S as ScreenAnswers, P as PresentationLoadingOptions, s as screenInputBindingsSchema, a as SurfaceData, b as PaywallLoadingDocument, C as CustomerDataIntent, c as createPresentationLoading } from './presentation-loading-CFSiS0VX.js';
3
- export { d as PresentationState } from './presentation-loading-CFSiS0VX.js';
2
+ import { S as ScreenAnswers, P as PresentationLoadingOptions, s as screenInputBindingsSchema, a as SurfaceData, b as PaywallLoadingDocument, C as CustomerDataIntent, c as createPresentationLoading } from './presentation-loading-B_v5XZtM.js';
3
+ export { d as PresentationState } from './presentation-loading-B_v5XZtM.js';
4
4
  import { J as JsonValue } from './growth-rules-B4YYy64R.js';
5
- import { S as StackNode, a as ScreenSelection } from './screen-CGCJ46b1.js';
6
- import { P as PaywallSession, S as SubscriptionOperation, F as FunnelCommandStorage, s as scopeSchema, a as FunnelStartInput, I as IndianaOptions, b as SessionCredentials, c as FunnelExecutionPolicy, d as PaywallRecovery, e as SubscriptionAttachQuote, f as FunnelRunController, g as PaywallResolution, h as FunnelRunView, i as IamFunnelEntryDelivery, j as FunnelProcessRunView, k as createPaywallSession$1 } from './funnel-local-client-Dz1dTgES.js';
7
- export { C as CustomerSession, l as FeatureClient, m as FeatureClientOptions, n as FunnelControllerResponse, o as FunnelPendingEntry, p as FunnelPurchaseRecovery, q as FunnelRuntimeResponse, r as FunnelSegmentPrediction, L as LocalFunnelClient, t as LocalFunnelClientOptions, u as LongplayError, v as PaywallPurchaseInput, w as PaywallStartInput, x as PushHost, y as PushJournal, z as createFeatureClient, A as createFunnelRunController, B as createLocalFunnelClient, D as getPaywallRecovery, E as preparePaywallFallback } from './funnel-local-client-Dz1dTgES.js';
5
+ import { S as StackNode, a as ScreenSelection } from './screen-qUBRsUi9.js';
6
+ import { P as PaywallSession, S as SubscriptionOperation, F as FunnelCommandStorage, s as scopeSchema, a as FunnelStartInput, I as IndianaOptions, b as SessionCredentials, c as FunnelExecutionPolicy, d as PaywallRecovery, e as SubscriptionAttachQuote, f as FunnelRunController, g as PaywallResolution, h as FunnelRunView, i as IamFunnelEntryDelivery, j as FunnelProcessRunView, k as createPaywallSession$1 } from './funnel-local-client-DR8OpKGU.js';
7
+ export { C as CustomerSession, l as FeatureClient, m as FeatureClientOptions, n as FunnelControllerResponse, o as FunnelPendingEntry, p as FunnelPurchaseRecovery, q as FunnelRuntimeResponse, r as FunnelSegmentPrediction, L as LocalFunnelClient, t as LocalFunnelClientOptions, u as LongplayError, v as PaywallPurchaseInput, w as PaywallStartInput, x as PushHost, y as PushJournal, z as createFeatureClient, A as createFunnelRunController, B as createLocalFunnelClient, D as getPaywallRecovery, E as preparePaywallFallback } from './funnel-local-client-DR8OpKGU.js';
8
+ import { C as CouponInput, O as Offer } from './coupon-kfkIVf9n.js';
9
+ export { a as OfferUnavailableReason } from './coupon-kfkIVf9n.js';
8
10
  import { E as EntitlementCheckResult, M as MerchantBridgeManifest } from './funnel-node-evaluation-COxXtZEQ.js';
9
11
  export { a as EntitlementCheckInput, b as EntitlementCheckObservation, c as EntitlementRequirement, F as FunnelNodeEvaluationContext, e as evaluateFunnelNode } from './funnel-node-evaluation-COxXtZEQ.js';
10
- import { C as CouponInput } from './coupon-kfkIVf9n.js';
11
- export { O as Offer, a as OfferUnavailableReason } from './coupon-kfkIVf9n.js';
12
- import { c as createFunnelProcess } from './funnel-process-client-D6qjStm2.js';
13
- export { F as FunnelProcessAdapter, a as FunnelProcessOptions, b as FunnelResourceSource, I as LongplayFeatureOptions, d as createFunnelClient, e as createLongplay } from './funnel-process-client-D6qjStm2.js';
14
- export { C as ConfigurationStorage, a as ConfigurationSync, b as ConfigurationSyncOptions, c as createConfigurationSync } from './configuration-sync-DdTRUv7A.js';
15
- import './api-Do-6AyWa.js';
12
+ import { c as createFunnelProcess } from './funnel-process-client-C87U4r_G.js';
13
+ export { F as FunnelProcessAdapter, a as FunnelProcessOptions, b as FunnelResourceSource, I as LongplayFeatureOptions, d as createFunnelClient, e as createLongplay } from './funnel-process-client-C87U4r_G.js';
14
+ export { C as ConfigurationStorage, a as ConfigurationSync, b as ConfigurationSyncOptions, c as createConfigurationSync } from './configuration-sync-BHrAf-ql.js';
15
+ import './api-r6FfVQpg.js';
16
16
  import 'zod/v4';
17
17
 
18
18
  /** Currency always comes from business data; locale only controls notation. No currency conversion. */
@@ -80,6 +80,11 @@ declare const contentVersionSchema: z.ZodObject<{
80
80
  blur: "blur";
81
81
  }>>;
82
82
  type: z.ZodLiteral<"modal">;
83
+ position: z.ZodOptional<z.ZodEnum<{
84
+ center: "center";
85
+ top: "top";
86
+ bottom: "bottom";
87
+ }>>;
83
88
  size: z.ZodEnum<{
84
89
  sm: "sm";
85
90
  md: "md";
@@ -299,6 +304,8 @@ type PaywallPurchaseIntent = {
299
304
  featureQuantities: Record<string, number>;
300
305
  };
301
306
  type PaywallHostOptions = PresentationLoadingOptions & {
307
+ /** Mount host controls inside this Paywall. Return synchronous teardown for destroy, cancellation or failure. */
308
+ mountControls?: (container: HTMLElement) => void | (() => void);
302
309
  /** An already available Paywall design for the first frame. */
303
310
  loadingDocument?: PaywallLoadingDocument;
304
311
  /** Coordinates presentation reads with an enclosing host. */
@@ -339,6 +346,13 @@ type PaywallHostOptions = PresentationLoadingOptions & {
339
346
  productVersionId: string;
340
347
  featureQuantities: Readonly<Record<string, number>>;
341
348
  }) => string | undefined | Promise<string | undefined>;
349
+ /**
350
+ * Opt in to the Coupon an authored purchase button is bound to: the SDK claims it for the
351
+ * Customer at the click and quotes with that offer instead of calling `resolveOfferId`.
352
+ */
353
+ claimCoupon?: (couponId: string, requestId: string) => Promise<{
354
+ offer: Offer | null;
355
+ }>;
342
356
  onOpenUrl?: (url: string) => unknown;
343
357
  onEvent?: (name: string) => unknown;
344
358
  /** An authored non-purchase button completed its action. */
@@ -1606,6 +1620,7 @@ declare function prerenderFunnelPurchase$1(container: HTMLElement, input: {
1606
1620
 
1607
1621
  type FunnelHostOptions = PresentationLoadingOptions & {
1608
1622
  client: FunnelRunController;
1623
+ closeActions?: readonly string[];
1609
1624
  /**
1610
1625
  * A pre-rendered Paywall, handed to the SDK: revealed, the first Paywall takes it over when it is
1611
1626
  * the same and untouched; otherwise it is released. Closed before the takeover, the Run closes.
@@ -1626,6 +1641,7 @@ type FunnelHostOptions = PresentationLoadingOptions & {
1626
1641
  terminateCheckout?: PaywallHostOptions["terminateCheckout"];
1627
1642
  confirmOnHostedCheckout?: PaywallHostOptions["confirmOnHostedCheckout"];
1628
1643
  resolveOfferId?: PaywallHostOptions["resolveOfferId"];
1644
+ claimCoupon?: PaywallHostOptions["claimCoupon"];
1629
1645
  /**
1630
1646
  * Opens an external page or a Paywall link. Return `false` (or throw) when the page could not be
1631
1647
  * opened; an external page then takes its `failed` route. Without a handler, `same_window` navigates
@@ -1891,6 +1907,8 @@ type IamFunnelEntriesOptions = IndianaOptions & {
1891
1907
  container: HTMLElement;
1892
1908
  /** Credential-free original starts survive reloads in this tab. Requires a full Customer session. */
1893
1909
  recoveryStorage?: Storage | false;
1910
+ /** Per-tab frequency state. A capped entry requires a full Customer session. */
1911
+ deliveryStorage?: Storage;
1894
1912
  host?: Omit<FunnelHostOptions, "client">;
1895
1913
  onStatus?: (status: string, entryId?: string) => void;
1896
1914
  };
@@ -1913,6 +1931,11 @@ declare function createFunnelPageExperiments(options: {
1913
1931
  destroy(): void;
1914
1932
  };
1915
1933
 
1934
+ type EntryDeliveryIdentity = {
1935
+ type: "customer" | "guest";
1936
+ id: string;
1937
+ };
1938
+
1916
1939
  type Entry = IamFunnelEntryDelivery["entries"][number];
1917
1940
  type Process = ReturnType<typeof createFunnelProcess>;
1918
1941
  type IamFunnelProcessEntriesOptions = Pick<IndianaOptions, "baseUrl" | "fetch" | "timeoutMs"> & {
@@ -1924,6 +1947,9 @@ type IamFunnelProcessEntriesOptions = Pick<IndianaOptions, "baseUrl" | "fetch" |
1924
1947
  createProcess(entry: Entry): Process;
1925
1948
  host?: Omit<FunnelHostOptions, "client">;
1926
1949
  locale?: string;
1950
+ /** Required for session-capped entries. Return the current Customer ID or a per-tab guest ID, never a credential. Update it before syncIdentity(). */
1951
+ deliveryIdentity?: () => EntryDeliveryIdentity | undefined;
1952
+ deliveryStorage?: Storage;
1927
1953
  onStatus?: (status: string, entryId?: string) => void;
1928
1954
  };
1929
1955
  /** Explicit process-capable IAM host. Merely fetching configuration creates no identity. */
@@ -2034,6 +2060,7 @@ declare function showPaywall(container: HTMLElement, options: PaywallHostOptions
2034
2060
  } | undefined;
2035
2061
  mobile?: "sheet" | "fullscreen" | undefined;
2036
2062
  backdrop?: "none" | "scrim" | "dim" | "strong-dim" | "blur" | undefined;
2063
+ position?: "center" | "top" | "bottom" | undefined;
2037
2064
  } | {
2038
2065
  type: "sheet";
2039
2066
  size: "sm" | "md" | "lg";
@@ -2064,6 +2091,7 @@ declare function showPaywall(container: HTMLElement, options: PaywallHostOptions
2064
2091
  } | undefined;
2065
2092
  mobile?: "sheet" | "fullscreen" | undefined;
2066
2093
  backdrop?: "none" | "scrim" | "dim" | "strong-dim" | "blur" | undefined;
2094
+ position?: "center" | "top" | "bottom" | undefined;
2067
2095
  } | {
2068
2096
  type: "sheet";
2069
2097
  size: "sm" | "md" | "lg";
@@ -2390,6 +2418,8 @@ declare function showPaywall(container: HTMLElement, options: PaywallHostOptions
2390
2418
  }>;
2391
2419
  };
2392
2420
  }>;
2421
+ /** Load presentation code without starting a session; return the public Paywall factory. */
2422
+ declare function preloadPaywall(): Promise<typeof showPaywall>;
2393
2423
  declare function createPaywallSession(...args: Parameters<typeof createPaywallSession$1>): Promise<PaywallSession>;
2394
2424
 
2395
2425
  /** Loading customer API clients does not initialize the UI renderer. */
@@ -2421,6 +2451,13 @@ declare function showFunnelPurchase(...args: Parameters<typeof showFunnelPurchas
2421
2451
  * `locale` are required while `start` is a promise.
2422
2452
  */
2423
2453
  declare function prerenderFunnelPurchase(...args: Parameters<typeof prerenderFunnelPurchase$1>): Promise<PreparedFunnelPurchase>;
2454
+ /**
2455
+ * Loads the code a Funnel purchase presents with, before any Customer is known: the pre-render,
2456
+ * the purchase host, the Paywall and its renderer. No session, request or DOM. Call it as soon as
2457
+ * the page can spare the download, so a later `prerenderFunnelPurchase` reads its Paywall at once
2458
+ * instead of waiting for these chunks one after another.
2459
+ */
2460
+ declare function preloadFunnelPurchase(): Promise<void>;
2424
2461
 
2425
2462
  declare function mountContent(...args: Parameters<typeof mountContent$1>): Promise<{
2426
2463
  destroy: () => void;
@@ -2440,4 +2477,4 @@ declare function prepareContent(...args: Parameters<typeof prepareContent$1>): P
2440
2477
  updateCapabilities(data: SurfaceData): void;
2441
2478
  }>;
2442
2479
 
2443
- export { type ContentActionIntent, type ContentHostOptions, EntitlementCheckResult, FunnelCommandStorage, FunnelExecutionPolicy, type FunnelHostOptions, type FunnelPurchaseAttempt, type FunnelPurchaseClient, type FunnelPurchaseEntry, type FunnelPurchaseHostOptions, type FunnelPurchaseOptions, type FunnelPurchaseStart, type FunnelPurchaseState, type FunnelPurchaseStorage, FunnelRunController, type IamFunnelEntriesOptions, type IamFunnelProcessEntriesOptions, IndianaOptions as LongplayOptions, MerchantBridgeError, type MerchantBridgeOptions, type PaywallHostOptions, PaywallLoadingDocument, type PaywallPurchaseIntent, PaywallRecovery, PaywallSession, type PreparedFunnelPurchase, type PreparedState, PresentationLoadingOptions, SessionCredentials, createBrowserFunnelCommandStorage, createBrowserFunnelPurchaseStorage, createFunnelPageExperiments, createFunnelProcess, createFunnelPurchaseClient, createIamFunnelEntries, createIamFunnelProcessEntries, createMerchantBridge, createPaywallSession, formatCouponDiscount, formatCouponMoney, formatCouponTerms, mountContent, prepareContent, prerenderFunnelPurchase, showFunnelPurchase, showFunnelRun, showPaywall };
2480
+ export { type ContentActionIntent, type ContentHostOptions, EntitlementCheckResult, FunnelCommandStorage, FunnelExecutionPolicy, type FunnelHostOptions, type FunnelPurchaseAttempt, type FunnelPurchaseClient, type FunnelPurchaseEntry, type FunnelPurchaseHostOptions, type FunnelPurchaseOptions, type FunnelPurchaseStart, type FunnelPurchaseState, type FunnelPurchaseStorage, FunnelRunController, type IamFunnelEntriesOptions, type IamFunnelProcessEntriesOptions, IndianaOptions as LongplayOptions, MerchantBridgeError, type MerchantBridgeOptions, Offer, type PaywallHostOptions, PaywallLoadingDocument, type PaywallPurchaseIntent, PaywallRecovery, PaywallSession, type PreparedFunnelPurchase, type PreparedState, PresentationLoadingOptions, SessionCredentials, createBrowserFunnelCommandStorage, createBrowserFunnelPurchaseStorage, createFunnelPageExperiments, createFunnelProcess, createFunnelPurchaseClient, createIamFunnelEntries, createIamFunnelProcessEntries, createMerchantBridge, createPaywallSession, formatCouponDiscount, formatCouponMoney, formatCouponTerms, mountContent, preloadFunnelPurchase, preloadPaywall, prepareContent, prerenderFunnelPurchase, showFunnelPurchase, showFunnelRun, showPaywall };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{a as dn,c as un}from"./chunk-RNEF4MZW.js";import{a as Ue,c as mn}from"./chunk-73NP72FV.js";import{a as pe}from"./chunk-W32FI2A2.js";import{a as nn,c as cn,d as ln}from"./chunk-RML52BOR.js";import"./chunk-KPDHY76A.js";import{a as sn}from"./chunk-UVRT4MY6.js";import"./chunk-MSK3VZ3A.js";import{h as en,i as an,k as fn}from"./chunk-BLVBUN2R.js";import{F as be,e as Ve,g as je,h as fe,i as me,j as Ge,x as tn}from"./chunk-2FE4FTPH.js";import{a as qe}from"./chunk-EUTWY7A2.js";import"./chunk-7MNJH5GB.js";import"./chunk-CIP5SQ5Y.js";import"./chunk-LF2UIJYD.js";import{B as Ne,D as Oe,E as xe,G as De,H as Te,I as ke,J as Be,K as ve,L as He,x as we,y as Me,z as Fe}from"./chunk-CKKIB2HC.js";import"./chunk-W6OQTXLL.js";import"./chunk-BOVN2BE3.js";import"./chunk-PUR5CYWX.js";import{$ as Le,l as Ze,m as We,n as Qe}from"./chunk-TAFALMQN.js";import"./chunk-ZGCKQWQ5.js";import{c as rn,e as on}from"./chunk-3NCMYTNG.js";import"./chunk-VEX2FOFZ.js";import"./chunk-V7PFLFHE.js";import{b as Ee}from"./chunk-56BYGPQ6.js";import"./chunk-VYFSRHXM.js";import"./chunk-BQRS7Y4K.js";import"./chunk-U4RSRFZY.js";import"./chunk-KE26KWIU.js";import"./chunk-TJGIT5CU.js";import{a as L}from"./chunk-OX7PA64E.js";import"./chunk-V7MMTILA.js";import"./chunk-SLUA7ABW.js";import{a as Ie,c as se}from"./chunk-J6KIN4RH.js";import{c as ye,d as he}from"./chunk-TLZP7BW6.js";import"./chunk-3VUPVXAV.js";import"./chunk-EM3MGDPG.js";import{b as G}from"./chunk-VF6QMMEA.js";import"./chunk-7QL4GF4C.js";import"./chunk-BID4UGWB.js";import{a as Z}from"./chunk-DSPLGTQI.js";import"./chunk-WOT6VMZA.js";var y=class extends Error{constructor(m,D=0,_=!1,b="fix_request"){super(m);this.code=m;this.status=D;this.retryable=_;this.recovery=b;this.name="MerchantBridgeError"}code;status;retryable;recovery};async function pn(n,w){if(!n.headers.get("content-type")?.split(";",1)[0].trim().match(/^application\/(?:json|[a-z0-9.+-]+\+json)$/i))throw new y("MERCHANT_BRIDGE_INVALID_RESPONSE");let m=n.body?.getReader();if(!m)throw new y("MERCHANT_BRIDGE_INVALID_RESPONSE");let D=()=>{m.cancel().catch(()=>{})};w.addEventListener("abort",D,{once:!0});let _=0,b="",r=new TextDecoder("utf-8",{fatal:!0});try{for(w.throwIfAborted();;){let i=await m.read();if(w.throwIfAborted(),i.done)break;if(_+=i.value.byteLength,_>262144)throw new y("MERCHANT_BRIDGE_INVALID_RESPONSE");b+=r.decode(i.value,{stream:!0})}return b+=r.decode(),JSON.parse(b)}catch(i){throw w.throwIfAborted(),i instanceof y?i:new y("MERCHANT_BRIDGE_INVALID_RESPONSE")}finally{w.removeEventListener("abort",D),await m.cancel().catch(()=>{}),m.releaseLock()}}function yn(n){let w=Oe.parse(n.origin),m=xe.parse(n.manifest),D={projectId:n.scope.projectId,environmentId:n.scope.environmentId,environment:n.scope.environment};for(let c of["projectId","environmentId","environment"])if(m[c]!==n.scope[c])throw new y("MERCHANT_BRIDGE_SCOPE_MISMATCH");let _=n.customerId===void 0?null:G.uuid().parse(n.customerId),b=0,r=null,i=null,I=new AbortController,g=n.fetch??globalThis.fetch;async function U(c,s,p,v,h){if(!m.capabilities.includes(c))throw new y("MERCHANT_BRIDGE_CAPABILITY_UNSUPPORTED",501);let d=Ne[c];if(["merchant_catalog_reader","merchant_refund_authority","indiana_server_key"].includes(d.authority))throw new y("MERCHANT_BRIDGE_FORBIDDEN",403);let l=b,o=AbortSignal.any([I.signal,AbortSignal.timeout(Math.min(3e4,Math.max(1e3,n.timeoutMs??1e4))),...n.signal?[n.signal]:[],...v?[v]:[]]);o.throwIfAborted();let F=new Headers(await n.headers?.());if(o.throwIfAborted(),l!==b)throw new DOMException("Merchant identity changed","AbortError");if(/\bgg_(?:sk|ct|rt)_/.test(F.get("authorization")??"")||F.has("X-Indiana-Bridge-Signature")||F.has("X-Indiana-Bridge-Key-Id"))throw new y("MERCHANT_BRIDGE_FORBIDDEN",403);F.set(Fe,String(we)),F.set("Accept","application/json");let A=crypto.randomUUID();F.set("X-Request-Id",A),F.set("Content-Type","application/json");let R=await g(w+Me,{method:"POST",credentials:"include",redirect:"error",cache:"no-store",headers:F,signal:o,body:JSON.stringify({bridgeVersion:we,requestId:A,command:d.command,scope:D,data:h??(p===void 0?{}:{operationId:p})})}),V=await pn(R,o);if(o.throwIfAborted(),l!==b)throw new DOMException("Merchant identity changed","AbortError");if(!R.ok){let T=He.safeParse(V);throw!T.success||T.data.scope.projectId!==n.scope.projectId||T.data.scope.environment!==n.scope.environment||T.data.scope.environmentId!==n.scope.environmentId||T.data.requestId!==A||T.data.command!==d.command?new y("MERCHANT_BRIDGE_INVALID_RESPONSE",R.status):new y(T.data.error.code,R.status,T.data.error.retryable,T.data.error.recovery)}let u=De(G.unknown()).safeParse(V);if(!u.success||u.data.scope.projectId!==n.scope.projectId||u.data.scope.environment!==n.scope.environment||u.data.scope.environmentId!==n.scope.environmentId||u.data.requestId!==A||u.data.command!==d.command)throw new y("MERCHANT_BRIDGE_INVALID_RESPONSE",R.status);let j=s.safeParse(u.data.data);if(!j.success)throw new y("MERCHANT_BRIDGE_INVALID_RESPONSE",R.status);return j.data}function M(){if(!_)throw new y("MERCHANT_BRIDGE_UNAUTHENTICATED",401);return _}async function $(c,s,p,v){let h=M();if(v!==void 0&&ve.parse({operationId:v,customerId:h}),!m.capabilities.includes(c))throw new y("MERCHANT_BRIDGE_CAPABILITY_UNSUPPORTED",501);let d=b,l=AbortSignal.any([I.signal,AbortSignal.timeout(Math.min(3e4,Math.max(1e3,n.timeoutMs??1e4))),...n.signal?[n.signal]:[],...s?[s]:[]]);l.throwIfAborted();let o,F=new Promise((A,R)=>{o=()=>R(l.reason),l.addEventListener("abort",o,{once:!0})});try{let R=p(async()=>{let u=await import("./merchant-bridge-contracts-EAE4HQE4.js");if(l.throwIfAborted(),d!==b||_!==h)throw new DOMException("Merchant identity changed","AbortError");return u},l),V=await Promise.race([R,F]);return l.throwIfAborted(),V}finally{l.removeEventListener("abort",o)}}async function J(c,s,p,v){let h=M(),d=ve.parse({operationId:p,customerId:h}),l=await U(c,s,d.operationId,v,d);if(l.customerId!==h||l.operationId!==d.operationId)throw new y("MERCHANT_BRIDGE_SCOPE_MISMATCH");return l}return{async readPresentation(c){let s=await U("presentation",ke,void 0,c);if(i!==null&&i!==s.nativeUserId)throw new y("MERCHANT_BRIDGE_SCOPE_MISMATCH");if(s.presentation&&_!==null&&s.presentation.customerId!==_)throw new y("MERCHANT_BRIDGE_SCOPE_MISMATCH");return i=s.nativeUserId,r=s.presentation,s},async createSession(c){let s=await U("session",Te,void 0,c);if(i!==null&&i!==s.nativeUserId)throw new y("MERCHANT_BRIDGE_SCOPE_MISMATCH");if(_!==null&&_!==s.session.customerId)throw new y("MERCHANT_BRIDGE_SCOPE_MISMATCH");if(r&&r.customerId!==s.session.customerId)throw new y("MERCHANT_BRIDGE_SCOPE_MISMATCH");return _=s.session.customerId,i=s.nativeUserId,s.session},async reportPresentation(c,s){let p=M(),v=Be.parse(c);if(!r||r.customerId!==p||r.decisionId!==v.decisionId)throw new y("MERCHANT_BRIDGE_SCOPE_MISMATCH");return U("presentation_events",G.strictObject({queued:G.literal(!0)}),void 0,s,v)},async readCustomerCommerce(c){let s=M(),p=await $("customer_commerce",c,async(v,h)=>{let[d,l]=await Promise.all([v(),U("customer_commerce",G.unknown(),void 0,h)]),o=d.merchantBridgeCommerceSchema.safeParse(l);if(!o.success)throw new y("MERCHANT_BRIDGE_INVALID_RESPONSE");return o.data});if(p.customerId!==s)throw new y("MERCHANT_BRIDGE_SCOPE_MISMATCH");return p},async executePurchase(c,s){let p=await $("purchases",s,async(v,h)=>J("purchases",(await v()).merchantBridgeOperationSchema,c,h),c);if(p.type!=="purchase")throw new y("MERCHANT_BRIDGE_INVALID_RESPONSE");return p},readOperation:(c,s)=>$("operation_status",s,async(p,v)=>J("operation_status",(await p()).merchantOperationLookupSchema,c,v),c),async executeSubscriptionChange(c,s){let p=await $("subscription_changes",s,async(v,h)=>J("subscription_changes",(await v()).merchantBridgeOperationSchema,c,h),c);if(p.type!=="subscription_change")throw new y("MERCHANT_BRIDGE_INVALID_RESPONSE");return p},reset(){b++,I.abort(),I=new AbortController,_=null,r=null,i=null}}}var $e=G.strictObject({command:me,target:je,runId:G.uuid().optional(),expiresAt:G.iso.datetime({offset:!0}).optional()}).refine(n=>n.command.release===n.target.release),Ke=G.strictObject({schemaVersion:G.literal(1),entries:G.array($e).max(4e3)});function ze(n){let w=!1,m=()=>{w||n.unavailable(),w=!0};function D(){return n.storage===!1?void 0:n.storage??globalThis.sessionStorage}function _(r){let i=D()?.getItem(r);if(!i)return[];if(i.length>1048576)throw Error("Entry recovery is too large");return Ke.parse(JSON.parse(i)).entries}function b(r,i){let I=D();if(!I)return;if(!i.length)return I.removeItem(r);let g=JSON.stringify(Ke.parse({schemaVersion:1,entries:i}));if(g.length>1048576)throw Error("Entry recovery is too large");I.setItem(r,g)}return{load(){try{let r=n.binding();if(!r||n.storage===!1)return;let i="indiana.funnel.entries.v1."+JSON.stringify(r);return{key:i,entries:_(i)}}catch{m();return}},retain(r,i){if(r)try{let I=$e.parse(i);b(r,[..._(r).filter(g=>g.command.funnelId!==I.command.funnelId),I])}catch{m()}},forget(r,i){if(r)try{b(r,_(r).filter(I=>I.command.requestId!==i))}catch{m()}}}}var ge=n=>["running","waiting"].includes(n.status)&&!n.pendingRequest&&(n.stopped||!n.screen&&!n.paywall&&n.instruction?.type==="wait"&&n.instruction.kind!=="operation");function hn(n){let w=ye(n.baseUrl),m=n.scope,D=Ee(n),_=n.fetch??globalThis.fetch.bind(globalThis),b,r=!1,i=!1,I=0,g=0,U="",M=0,$=0,J=0,c=!1,s,p=!0,v,h,d,l,o,F=-1,A,R=e=>{A===e&&(A=void 0,q())},V=new Set,u=(e,a)=>Z(n.onStatus,e,a),j=new Set,T=ze({storage:n.recoveryStorage,binding:()=>{let e=n.session.snapshot()?.customerId;return e?[w,m.projectId,m.environment,n.environmentId,n.appManifestRelease,e]:void 0},unavailable:()=>u("recovery_unavailable")}),X=e=>T.forget(e.storageKey,e.command.requestId);function oe(e,a){a&&(e.runId=a.id,e.expiresAt=a.runExpiresAt),T.retain(e.storageKey,{command:e.command,target:e.target,...e.runId&&{runId:e.runId},...e.expiresAt&&{expiresAt:e.expiresAt}})}function te(){let e=o;o=void 0,e?.host.destroy(),e?.slot.remove(),e?.client.reset(),q()}let ce=()=>A!==void 0||o!==void 0&&!o.background;function t(e,a){if(o?.client!==e)return;oe(o.recovery,a);let f=ge(a);o.slot.hidden=f,f!==o.background&&(o.background=f,f?u("run_background",o.entryId):F=g,q())}function S(e,a,f){let P=e.client.view;if(!a||e.background||!P?.screen||P.paywall||P.pendingRequest||P.stopped||P.status!=="waiting")return;let O=Le.parse({operation:"close",requestId:crypto.randomUUID(),nodeId:P.nodeId,visit:P.visit,revision:P.revision,customerToken:a}),K=Ee({...n,session:void 0});K.requestWithCredential("funnels",O,e.runToken,{keepalive:f}).then(()=>X(e.recovery)).catch(()=>{}).finally(()=>K.dispose())}let N=()=>{o&&S(o,n.session.peek(),!0)},z=()=>Date.now()<$&&performance.now()<J;function B(e){if(e.target.release!==n.appManifestRelease||!z())return!1;try{return se(e.target.render,document,location.pathname,()=>{})}catch{return u("incompatible",e.id),!1}}function Q(e){if(r||e.epoch!==M||e.visit!==g||document.visibilityState==="hidden")return!1;try{return se(e.target.render,document,location.pathname,()=>{})}catch{return!1}}async function ee(e){if(ce()){u("in_progress",e.id);return}if(!n.session.peek()){u("identity_required",e.id);return}let a=T.load(),f=a?.entries.find(O=>O.command.funnelId===e.funnelId&&(!O.expiresAt||Date.parse(O.expiresAt)>Date.now()));if(f){if(!ae(f)){u("recovery_pending",e.id);return}let O={...f,storageKey:a.key,epoch:M,visit:g};j.add(O.command.requestId),A=O,await re(O);return}let P={freshStart:!0,command:me.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:M,visit:g,target:e.target,storageKey:a?.key};j.add(P.command.requestId),A=P,await re(P)}async function re(e){if(e.dispatching)return;e.dispatching=!0;let a=e.freshStart===!0;e.freshStart=!1;let f,P=!1,O=!1;async function K(k){if(e.epoch!==M)return;let E=k.view;if(!(e.storageKey&&E&&(ge(E)||E.paywall||E.pendingRequest))&&E&&["running","waiting"].includes(E.status))try{await k.submit({operation:"close",requestId:crypto.randomUUID(),nodeId:E.nodeId,visit:E.visit,revision:E.revision}),X(e)}catch(x){if(!(x instanceof L&&x.code==="FORBIDDEN"))throw x}}try{oe(e),u("starting",e.command.entryId);let k=await D.request("funnels",e.command),E=Ge.safeParse(k);if(E.success){if(E.data.scope.projectId!==m.projectId||E.data.scope.environment!==m.environment)throw new L("SCOPE_MISMATCH","Entry scope changed");e.epoch===M&&u(E.data.reason,e.command.entryId),X(e),R(e);return}let x=Ve.parse(k);if(!x.runToken||x.scope.projectId!==m.projectId||x.scope.environment!==m.environment||x.run.source.type!=="funnel"||x.run.source.id!==e.command.funnelId||x.run.source.versionId!==e.command.versionId||e.runId!==void 0&&x.run.id!==e.runId)throw new L("INVALID_RESPONSE","Invalid entry Run");if(e.epoch!==M){R(e),u("identity_changed",e.command.entryId);return}oe(e,x.run);let C=be({...n,runToken:x.runToken,funnelId:e.command.funnelId,initialResponse:a?k:void 0});f=C,O=!0,await C.get(),O=!1;let Y=C.view;if(!Y||Y.id!==x.run.id||Y.source.type!=="funnel"||Y.source.id!==e.command.funnelId||Y.source.versionId!==e.command.versionId)throw new L("INVALID_RESPONSE","Entry Run version changed");if(!["running","waiting"].includes(Y.status)){X(e),R(e),u("run_ended",e.command.entryId);return}let{showFunnelRun:ue}=await import("./funnel-runtime-host-UKSOOA4H.js");if(!Q(e)){await K(C),u("left_screen",e.command.entryId),R(e);return}let _e=!1,Ae=!1;if(o&&!o.background){await K(C),u("in_progress",e.command.entryId),R(e);return}o&&te();let ne=document.createElement("div");ne.hidden=ge(Y),n.container.append(ne);let Ce=await ue(ne,{...n.host,client:C,appManifestRelease:n.appManifestRelease,onState(H){t(C,H),Z(n.host?.onState,H)},onDismiss(H){_e=!0,ne.remove(),H&&!["running","waiting"].includes(H.status)&&X(e),o?.client===C&&(o=void 0,C.reset(),q(),H&&H.status!=="completed"&&u("run_ended",e.command.entryId)),Z(n.host?.onDismiss,H)},onComplete(H){Ae=!0,X(e),o?.client===C&&te(),Z(n.host?.onComplete,H)},onError(H){Z(n.host?.onError,H),o?.client===C&&H instanceof L&&H.code==="FORBIDDEN"&&(X(e),te(),u("run_ended",e.command.entryId))}}).catch(H=>{throw ne.remove(),H});if(!Q(e)||_e||Ae){Ce.destroy(),ne.remove(),Q(e)||await K(C),R(e);return}let le=ge(C.view??Y);ne.hidden=le,o={host:Ce,client:C,slot:ne,entryId:e.command.entryId,background:le,runToken:x.runToken,owner:n.session.peek(),recovery:e},le||(F=e.visit),P=!0,R(e),u("started",e.command.entryId),le&&u("run_background",e.command.entryId)}catch(k){k instanceof L&&(!f||O&&k.code==="FORBIDDEN")&&k.status!==void 0&&k.status>=400&&k.status<500&&!k.retryable&&(X(e),R(e)),e.epoch===M&&!r&&(u("start_failed",e.command.entryId),Z(n.host?.onError,k))}finally{P||f?.reset(),e.dispatching=!1}}function ae(e){if(e.command.release!==n.appManifestRelease||e.target.release!==n.appManifestRelease)return!1;try{return se(e.target.render,document,location.pathname,()=>{})}catch{return!1}}function W(){if(ce())return!1;let e=T.load();for(let a of e?.entries??[]){if(a.expiresAt&&Date.parse(a.expiresAt)<=Date.now()){T.forget(e.key,a.command.requestId);continue}if(a.command.requestId===o?.recovery.command.requestId||j.has(a.command.requestId)||!ae(a))continue;j.add(a.command.requestId);let f={...a,storageKey:e.key,epoch:M,visit:g};return A=f,re(f),!0}return!1}function de(){if(c=!1,r||!i||document.visibilityState==="hidden")return;ie();let e=o!==void 0&&!o.background;if(e&&(F=g),!W()){if(!z()){p=!0;return}p=!1;for(let a of b?.entries??[]){let f=`${a.funnelId}:${a.id}`;if(!(a.event!=="screen_enter"||V.has(f)||!B(a))){if(!n.session.peek()){u("identity_required",a.id);continue}if(F===g){V.add(f),e&&u("in_progress",a.id);continue}if(A){u("in_progress",a.id);return}V.add(f),ee(a);break}}}}let q=()=>{!c&&!r&&(c=!0,queueMicrotask(de))};function ie(){let e=location.origin+location.pathname;return e===U?!1:(U=e,g++,p=!0,V.clear(),j.clear(),!0)}function Xe(){ie()&&q()}function Re(e){if(!e.isTrusted||e.button!==0||e.ctrlKey||e.metaKey||e.shiftKey||e.altKey||document.visibilityState==="hidden")return;let a=e.target;if(!(a instanceof Element)||a.closest("[data-indiana-funnel]"))return;let f=a.closest("button,a,input");if(!(!f||f.matches(":disabled,[aria-disabled='true']")||f.closest("[hidden],[inert],[aria-hidden='true']")))for(let P of b?.entries??[]){let O=P.target.button;if(!(P.event!=="button_click"||!O||!B(P))){try{let K=Ie(document);if(!f.matches(O.selector)||K(O.selector,f)!==1)continue}catch{u("incompatible",P.id);continue}ee(P);break}}}async function Se(){if(r)return;if(s)return s;let e=++I,a=new AbortController;v=a;let f,P=new Promise((k,E)=>{f=()=>E(new L("TIMEOUT","Funnel entry configuration read cancelled or timed out")),a.signal.addEventListener("abort",f,{once:!0})}),O=setTimeout(()=>a.abort(),n.timeoutMs??5e3),K=(async()=>{let k=async()=>{let ue=await _(`${w}/api/v1/funnel-entries/${n.environmentId}?iam=${n.appManifestRelease}`,{credentials:"omit",cache:"no-store",redirect:"error",signal:a.signal});if(!ue.ok)throw new L("SERVICE_UNAVAILABLE","Funnel entries unavailable",ue.status);return fe.parse(await ue.json())},E=await Promise.race([k(),P]),x=Date.parse(E.validatedAt),C=Date.parse(E.validUntil);if(E.scope.projectId!==m.projectId||E.scope.environment!==m.environment||E.scope.environmentId!==n.environmentId||E.release!==n.appManifestRelease||C<=Date.now()||x>Date.now()+5e3||C-x>6e4||C<=x)throw new L("INVALID_RESPONSE","Entry configuration scope or deadline changed");if(r||e!==I)return;let Y=b===void 0;b=E,$=C,J=performance.now()+Math.min(C-Date.now(),6e4),(Y||p)&&q()})();s=K;try{await K}finally{clearTimeout(O),a.signal.removeEventListener("abort",f),s===K&&(s=void 0)}}async function Ye(){if(!(!i||r)){try{await Se()}catch{r||u("configuration_unavailable")}q()}}let Pe=pe({document,run:Ye,delay:()=>i&&!r?15e3:void 0});return{async start(){i||r||(i=!0,U=location.origin+location.pathname,h=he(Xe),d=n.session.subscribeIdentity(()=>{M++,p=!0,A=void 0,V.clear(),F=-1,j.clear(),o&&S(o,o.owner,!1),te(),q()}),l=new MutationObserver(q),l.observe(document.documentElement,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["hidden","inert","aria-hidden","data-indiana-id","id","style","data-testid","data-test","data-qa"]}),document.addEventListener("click",Re,!0),addEventListener("pagehide",N),await Pe.refresh())},refresh:Se,async retry(){A&&!r&&A.epoch===M&&await re(A)},destroy(){r=!0,I++,Pe.destroy(),v?.abort(),l?.disconnect(),h?.(),d?.(),document.removeEventListener("click",Re,!0),removeEventListener("pagehide",N),N(),te(),D.dispose(),b=void 0}}}function In(n){let w=ye(n.baseUrl),m=n.fetch??globalThis.fetch.bind(globalThis),D,_=0,b=0,r=!1,i=!1,I=0,g=0,U=-1,M=!1,$="",J,c,s,p,v=new Set,h,d,l,o=(t,S)=>Z(n.onStatus,t,S),F=()=>Date.now()<_&&performance.now()<b;function A(t){try{return F()&&t.target.release===n.appManifestRelease&&se(t.target.render,document,location.pathname,()=>{})}catch{return o("incompatible",t.id),!1}}function R(){let t=l;l=void 0,t?.host.destroy(),t?.slot.remove()}async function V(t){if(t.dispatching)return;t.dispatching=!0;let S=I;try{let N=await t.process.open({operation:"entry_start",funnelId:t.entry.funnelId,versionId:t.entry.versionId,entryId:t.entry.id,release:n.appManifestRelease,locale:n.locale??"en"}),{showFunnelRun:z}=await import("./funnel-runtime-host-UKSOOA4H.js");if(r||S!==I||d!==t)return;let B=document.createElement("div");n.container.append(B),U=g;let Q=await z(B,{...n.host,client:N.controller,appManifestRelease:n.appManifestRelease,onDismiss(ee){l?.process===t.process&&(l=void 0,B.remove()),Z(n.host?.onDismiss,ee)}});if(r||S!==I||d!==t){Q.destroy(),B.remove();return}l={entry:t.entry,process:t.process,host:Q,slot:B},d=void 0,o("run_presented",t.entry.id)}catch(N){if(r||S!==I||d!==t)return;N instanceof L&&"result"in N?(d=void 0,t.process.destroy(),o("suppressed",t.entry.id),j()):o("entry_unavailable",t.entry.id)}finally{t.dispatching=!1}}function u(t){if(r||d||l||h||U===g||!A(t))return;let S=`${g}:${t.id}`;if(v.has(S))return;v.add(S);let N={entry:t,process:n.createProcess(t),visit:g};d=N,V(N)}function j(){M||r||(M=!0,queueMicrotask(()=>{if(M=!1,!(r||document.visibilityState==="hidden"||!F()||d||l||h||U===g)){for(let t of D?.entries??[])if(t.event==="screen_enter"&&A(t)){u(t);break}}}))}function T(t){if(!t.isTrusted||t.defaultPrevented||!(t.target instanceof Element)||d||l||h||U===g)return;let S=Ie(document,()=>{});for(let N of D?.entries??[]){let z=N.target.button;if(N.event!=="button_click"||!z||!A(N))continue;let B=t.target.closest(z.selector);if(!(!B||B.tagName.toLowerCase()!==z.tag||S(z.selector)!==1||B.matches(":disabled")||B.closest('[inert],[hidden],[aria-hidden="true"]'))){u(N);break}}}let X=()=>{let t=location.origin+location.pathname;t!==$&&($=t,g++,v.clear(),j())};async function oe(){if(r)return;if(c)return c;let t=I,S=new AbortController;J=S;let N,z=new Promise((re,ae)=>{N=ae}),B=()=>N(new L("TIMEOUT","Funnel entry read cancelled"));S.signal.addEventListener("abort",B,{once:!0});let Q=setTimeout(()=>S.abort(),n.timeoutMs??5e3),ee=(async()=>{let re=encodeURIComponent(JSON.stringify(["funnel-process/1"])),ae=async()=>{let ie=await m(`${w}/api/v1/funnel-entries/${n.environmentId}?iam=${n.appManifestRelease}&executionContracts=${re}`,{credentials:"omit",cache:"no-store",redirect:"error",signal:S.signal});if(!ie.ok)throw new L("SERVICE_UNAVAILABLE","Funnel entries unavailable",ie.status);return fe.parse(await ie.json())},W=await Promise.race([ae(),z]),de=Date.parse(W.validatedAt),q=Date.parse(W.validUntil);if(W.scope.projectId!==n.scope.projectId||W.scope.environment!==n.scope.environment||W.scope.environmentId!==n.environmentId||W.release!==n.appManifestRelease||q<=Date.now()||de>Date.now()+5e3||q<=de||q-de>6e4)throw new L("INVALID_RESPONSE","Entry scope or deadline changed");r||t!==I||(D=W,_=q,b=performance.now()+Math.min(q-Date.now(),6e4),j())})();c=ee;try{await ee}finally{clearTimeout(Q),S.signal.removeEventListener("abort",B),c===ee&&(c=void 0)}}async function te(){if(!(!i||r))try{await oe()}catch{r||o("configuration_unavailable")}}let ce=pe({document,run:te,delay:()=>i&&!r?15e3:void 0});return{async start(){i||r||(i=!0,$=location.origin+location.pathname,s=he(X),p=new MutationObserver(j),p.observe(document.documentElement,{subtree:!0,childList:!0,attributes:!0,attributeFilter:["hidden","inert","aria-hidden","data-indiana-id","id","style","data-testid","data-test","data-qa"]}),document.addEventListener("click",T,!0),await ce.refresh())},refresh:oe,async retry(){d&&!r&&await V(d)},async syncIdentity(){let t=l??d??h;if(t)try{let S=await t.process.syncIdentity();return h===t&&(d={entry:t.entry,process:t.process,visit:g},h=void 0,await V(d)),S}catch(S){throw t.process.view||(h={entry:t.entry,process:t.process,visit:g},d=void 0,R()),S}},async detach(){I++,J?.abort();let t=l??d??h;t&&(h={entry:t.entry,process:t.process,visit:g}),d=void 0,R(),t&&await t.process.detach()},destroy(){r=!0,I++,ce.destroy(),J?.abort(),p?.disconnect(),s?.(),document.removeEventListener("click",T,!0);let t=l??d??h;d=void 0,h=void 0,R(),t?.process.destroy(),D=void 0}}}async function $n(n,w){return(await import("./paywall-VYUBYBUI.js")).showPaywall(n,w)}async function zn(...n){return n[1]=qe(n[1]),(await import("./paywall-session-E5V42XUT.js")).createPaywallSession(...n)}async function Jn(...n){let w=n[1].signal?.aborted?void 0:Ue(n[1].client);try{return import("./screen-renderer-R5GH7XLV.js").catch(()=>{}),import("./paywall-VYUBYBUI.js").catch(()=>{}),await(await Je(()=>import("./funnel-runtime-host-UKSOOA4H.js"),n[1].prepared)).showFunnelRun(...n)}finally{w?.()}}async function Je(n,w){try{return await n()}catch(m){throw w&&w.state!=="adopted"&&await import("./funnel-paywall-prerender-QHCUZZY3.js").then(D=>D.preparedInternals(w)?.release(),()=>{}),m}}async function Xn(...n){return import("./screen-renderer-R5GH7XLV.js").catch(()=>{}),import("./paywall-VYUBYBUI.js").catch(()=>{}),(await Je(()=>import("./funnel-host-purchase-Z7FCJ5CX.js"),n[1].prepared)).showFunnelPurchase(...n)}async function Yn(...n){return import("./funnel-host-purchase-Z7FCJ5CX.js").catch(()=>{}),import("./screen-renderer-R5GH7XLV.js").catch(()=>{}),(await import("./funnel-paywall-prerender-QHCUZZY3.js")).prerenderFunnelPurchase(...n)}async function Zn(...n){return(await import("./content-AJDTSI7A.js")).mountContent(...n)}async function Wn(...n){return(await import("./content-AJDTSI7A.js")).prepareContent(...n)}export{L as LongplayError,y as MerchantBridgeError,tn as createBrowserFunnelCommandStorage,dn as createBrowserFunnelPurchaseStorage,an as createConfigurationSync,en as createFeatureClient,cn as createFunnelClient,mn as createFunnelPageExperiments,ln as createFunnelProcess,un as createFunnelPurchaseClient,be as createFunnelRunController,hn as createIamFunnelEntries,In as createIamFunnelProcessEntries,fn as createLocalFunnelClient,nn as createLongplay,yn as createMerchantBridge,zn as createPaywallSession,sn as evaluateFunnelNode,We as formatCouponDiscount,Ze as formatCouponMoney,Qe as formatCouponTerms,rn as getPaywallRecovery,Zn as mountContent,Wn as prepareContent,on as preparePaywallFallback,Yn as prerenderFunnelPurchase,Xn as showFunnelPurchase,Jn as showFunnelRun,$n as showPaywall};
1
+ import{a as gn,c as vn}from"./chunk-OQRMAU2B.js";import{a as We,c as En}from"./chunk-2KJLN65C.js";import{a as Ie}from"./chunk-W32FI2A2.js";import{a as ln,c as hn,d as In}from"./chunk-2VMEDQHT.js";import"./chunk-ZYOZSUZS.js";import{a as yn}from"./chunk-2HBIBIOF.js";import"./chunk-VIBJNB5B.js";import{h as dn,i as pn,k as wn}from"./chunk-ZZIBLQCJ.js";import{F as Ce,e as Xe,g as Ye,h as ge,i as ve,j as Ze,x as un}from"./chunk-KFIL73QY.js";import{a as ze}from"./chunk-CY7OKV7E.js";import"./chunk-D3OYXTMC.js";import"./chunk-4KLXQKNO.js";import"./chunk-PW5PIBSO.js";import{B as He,D as qe,E as Ue,G as Ve,H as je,I as Ge,J as Je,K as Te,L as $e,x as _e,y as Le,z as Be}from"./chunk-S43TYW3V.js";import"./chunk-W74JLL2O.js";import"./chunk-ECKVJGXQ.js";import"./chunk-GH6FM44P.js";import{aa as Ke,l as an,m as sn,n as cn}from"./chunk-YV6UFESO.js";import"./chunk-WQ3O5RXN.js";import{c as fn,e as mn}from"./chunk-3NCMYTNG.js";import"./chunk-AB7GEGZ2.js";import"./chunk-Q676H74B.js";import{b as Ae}from"./chunk-7XDQKZYA.js";import"./chunk-XJRDO3NI.js";import"./chunk-WZMZMJCK.js";import"./chunk-T2KWLYCW.js";import"./chunk-LOLMUXHW.js";import"./chunk-HEHLFHW7.js";import{a as G}from"./chunk-U7NX5ET2.js";import"./chunk-VLSP3LRH.js";import"./chunk-SLUA7ABW.js";import{a as be,c as de}from"./chunk-J6KIN4RH.js";import{c as we,d as Ee}from"./chunk-OCWSWXCW.js";import"./chunk-3VUPVXAV.js";import"./chunk-AHUYZ6IW.js";import{b as U}from"./chunk-CR2XJ2CX.js";import"./chunk-O4KXODTJ.js";import"./chunk-CILM5XMH.js";import{a as Q}from"./chunk-DSPLGTQI.js";import"./chunk-WOT6VMZA.js";var I=class extends Error{constructor(f,b=0,w=!1,h="fix_request"){super(f);this.code=f;this.status=b;this.retryable=w;this.recovery=h;this.name="MerchantBridgeError"}code;status;retryable;recovery};async function bn(n,d){if(!n.headers.get("content-type")?.split(";",1)[0].trim().match(/^application\/(?:json|[a-z0-9.+-]+\+json)$/i))throw new I("MERCHANT_BRIDGE_INVALID_RESPONSE");let f=n.body?.getReader();if(!f)throw new I("MERCHANT_BRIDGE_INVALID_RESPONSE");let b=()=>{f.cancel().catch(()=>{})};d.addEventListener("abort",b,{once:!0});let w=0,h="",t=new TextDecoder("utf-8",{fatal:!0});try{for(d.throwIfAborted();;){let i=await f.read();if(d.throwIfAborted(),i.done)break;if(w+=i.value.byteLength,w>262144)throw new I("MERCHANT_BRIDGE_INVALID_RESPONSE");h+=t.decode(i.value,{stream:!0})}return h+=t.decode(),JSON.parse(h)}catch(i){throw d.throwIfAborted(),i instanceof I?i:new I("MERCHANT_BRIDGE_INVALID_RESPONSE")}finally{d.removeEventListener("abort",b),await f.cancel().catch(()=>{}),f.releaseLock()}}function Sn(n){let d=qe.parse(n.origin),f=Ue.parse(n.manifest),b={projectId:n.scope.projectId,environmentId:n.scope.environmentId,environment:n.scope.environment};for(let m of["projectId","environmentId","environment"])if(f[m]!==n.scope[m])throw new I("MERCHANT_BRIDGE_SCOPE_MISMATCH");let w=n.customerId===void 0?null:U.uuid().parse(n.customerId),h=0,t=null,i=null,u=new AbortController,y=n.fetch??globalThis.fetch;async function R(m,s,E,_,M){if(!f.capabilities.includes(m))throw new I("MERCHANT_BRIDGE_CAPABILITY_UNSUPPORTED",501);let S=He[m];if(["merchant_catalog_reader","merchant_refund_authority","indiana_server_key"].includes(S.authority))throw new I("MERCHANT_BRIDGE_FORBIDDEN",403);let l=h,o=AbortSignal.any([u.signal,AbortSignal.timeout(Math.min(3e4,Math.max(1e3,n.timeoutMs??1e4))),...n.signal?[n.signal]:[],..._?[_]:[]]);o.throwIfAborted();let T=new Headers(await n.headers?.());if(o.throwIfAborted(),l!==h)throw new DOMException("Merchant identity changed","AbortError");if(/\bgg_(?:sk|ct|rt)_/.test(T.get("authorization")??"")||T.has("X-Indiana-Bridge-Signature")||T.has("X-Indiana-Bridge-Key-Id"))throw new I("MERCHANT_BRIDGE_FORBIDDEN",403);T.set(Be,String(_e)),T.set("Accept","application/json");let g=crypto.randomUUID();T.set("X-Request-Id",g),T.set("Content-Type","application/json");let N=await y(d+Le,{method:"POST",credentials:"include",redirect:"error",cache:"no-store",headers:T,signal:o,body:JSON.stringify({bridgeVersion:_e,requestId:g,command:S.command,scope:b,data:M??(E===void 0?{}:{operationId:E})})}),J=await bn(N,o);if(o.throwIfAborted(),l!==h)throw new DOMException("Merchant identity changed","AbortError");if(!N.ok){let O=$e.safeParse(J);throw!O.success||O.data.scope.projectId!==n.scope.projectId||O.data.scope.environment!==n.scope.environment||O.data.scope.environmentId!==n.scope.environmentId||O.data.requestId!==g||O.data.command!==S.command?new I("MERCHANT_BRIDGE_INVALID_RESPONSE",N.status):new I(O.data.error.code,N.status,O.data.error.retryable,O.data.error.recovery)}let c=Ve(U.unknown()).safeParse(J);if(!c.success||c.data.scope.projectId!==n.scope.projectId||c.data.scope.environment!==n.scope.environment||c.data.scope.environmentId!==n.scope.environmentId||c.data.requestId!==g||c.data.command!==S.command)throw new I("MERCHANT_BRIDGE_INVALID_RESPONSE",N.status);let $=s.safeParse(c.data.data);if(!$.success)throw new I("MERCHANT_BRIDGE_INVALID_RESPONSE",N.status);return $.data}function P(){if(!w)throw new I("MERCHANT_BRIDGE_UNAUTHENTICATED",401);return w}async function B(m,s,E,_){let M=P();if(_!==void 0&&Te.parse({operationId:_,customerId:M}),!f.capabilities.includes(m))throw new I("MERCHANT_BRIDGE_CAPABILITY_UNSUPPORTED",501);let S=h,l=AbortSignal.any([u.signal,AbortSignal.timeout(Math.min(3e4,Math.max(1e3,n.timeoutMs??1e4))),...n.signal?[n.signal]:[],...s?[s]:[]]);l.throwIfAborted();let o,T=new Promise((g,N)=>{o=()=>N(l.reason),l.addEventListener("abort",o,{once:!0})});try{let N=E(async()=>{let c=await import("./merchant-bridge-contracts-67AYXZFI.js");if(l.throwIfAborted(),S!==h||w!==M)throw new DOMException("Merchant identity changed","AbortError");return c},l),J=await Promise.race([N,T]);return l.throwIfAborted(),J}finally{l.removeEventListener("abort",o)}}async function z(m,s,E,_){let M=P(),S=Te.parse({operationId:E,customerId:M}),l=await R(m,s,S.operationId,_,S);if(l.customerId!==M||l.operationId!==S.operationId)throw new I("MERCHANT_BRIDGE_SCOPE_MISMATCH");return l}return{async readPresentation(m){let s=await R("presentation",Ge,void 0,m);if(i!==null&&i!==s.nativeUserId)throw new I("MERCHANT_BRIDGE_SCOPE_MISMATCH");if(s.presentation&&w!==null&&s.presentation.customerId!==w)throw new I("MERCHANT_BRIDGE_SCOPE_MISMATCH");return i=s.nativeUserId,t=s.presentation,s},async createSession(m){let s=await R("session",je,void 0,m);if(i!==null&&i!==s.nativeUserId)throw new I("MERCHANT_BRIDGE_SCOPE_MISMATCH");if(w!==null&&w!==s.session.customerId)throw new I("MERCHANT_BRIDGE_SCOPE_MISMATCH");if(t&&t.customerId!==s.session.customerId)throw new I("MERCHANT_BRIDGE_SCOPE_MISMATCH");return w=s.session.customerId,i=s.nativeUserId,s.session},async reportPresentation(m,s){let E=P(),_=Je.parse(m);if(!t||t.customerId!==E||t.decisionId!==_.decisionId)throw new I("MERCHANT_BRIDGE_SCOPE_MISMATCH");return R("presentation_events",U.strictObject({queued:U.literal(!0)}),void 0,s,_)},async readCustomerCommerce(m){let s=P(),E=await B("customer_commerce",m,async(_,M)=>{let[S,l]=await Promise.all([_(),R("customer_commerce",U.unknown(),void 0,M)]),o=S.merchantBridgeCommerceSchema.safeParse(l);if(!o.success)throw new I("MERCHANT_BRIDGE_INVALID_RESPONSE");return o.data});if(E.customerId!==s)throw new I("MERCHANT_BRIDGE_SCOPE_MISMATCH");return E},async executePurchase(m,s){let E=await B("purchases",s,async(_,M)=>z("purchases",(await _()).merchantBridgeOperationSchema,m,M),m);if(E.type!=="purchase")throw new I("MERCHANT_BRIDGE_INVALID_RESPONSE");return E},readOperation:(m,s)=>B("operation_status",s,async(E,_)=>z("operation_status",(await E()).merchantOperationLookupSchema,m,_),m),async executeSubscriptionChange(m,s){let E=await B("subscription_changes",s,async(_,M)=>z("subscription_changes",(await _()).merchantBridgeOperationSchema,m,M),m);if(E.type!=="subscription_change")throw new I("MERCHANT_BRIDGE_INVALID_RESPONSE");return E},reset(){h++,u.abort(),u=new AbortController,w=null,t=null,i=null}}}var en=U.strictObject({command:ve,target:Ye,runId:U.uuid().optional(),expiresAt:U.iso.datetime({offset:!0}).optional(),deliveryLimit:U.number().int().min(1).max(100).optional()}).refine(n=>n.command.release===n.target.release),Qe=U.strictObject({schemaVersion:U.literal(1),entries:U.array(en).max(4e3)});function nn(n){let d=!1,f=()=>{d||n.unavailable(),d=!0};function b(){return n.storage===!1?void 0:n.storage??globalThis.sessionStorage}function w(t){let i=b()?.getItem(t);if(!i)return[];if(i.length>1048576)throw Error("Entry recovery is too large");return Qe.parse(JSON.parse(i)).entries}function h(t,i){let u=b();if(!u)return;if(!i.length)return u.removeItem(t);let y=JSON.stringify(Qe.parse({schemaVersion:1,entries:i}));if(y.length>1048576)throw Error("Entry recovery is too large");u.setItem(t,y)}return{load(){try{let t=n.binding();if(!t||n.storage===!1)return;let i="indiana.funnel.entries.v1."+JSON.stringify(t);return{key:i,entries:w(i)}}catch{f();return}},retain(t,i){if(t)try{let u=en.parse(i);h(t,[...w(t).filter(y=>y.command.funnelId!==u.command.funnelId),u])}catch{f()}},forget(t,i){if(t)try{h(t,w(t).filter(u=>u.command.requestId!==i))}catch{f()}}}}var tn=U.strictObject({version:U.literal(1),runs:U.array(U.uuid()).max(100)}),De=new WeakMap,Me=new WeakMap;function Se(n){let d=!1;function f(){d||n.unavailable(),d=!0}function b(t){let i=t.storage.getItem(t.key);if(!i)return[];if(i.length>8192)throw Error("Invalid entry delivery record");return tn.parse(JSON.parse(i)).runs}function w(t){let i=De.get(t.storage);i||De.set(t.storage,i=new Map);let u=i.get(t.key);return u||i.set(t.key,u=new Set),u}function h(t){if(!t)return;let i=De.get(t.storage),u=i?.get(t.key);u?.delete(t.requestId),u?.size===0&&i?.delete(t.key)}return{claim(t,i,u,y,R=!1){if(u!==void 0)try{let P=n.binding();if(!P)throw Error("Entry delivery identity is unavailable");let B={storage:n.storage??globalThis.sessionStorage,key:"indiana.funnel.delivery.v1."+JSON.stringify([...P,i,t]),requestId:y},z=b(B);if(Me.get(B.storage)?.has(B.key))throw Error("Entry delivery storage is unavailable");B.storage.setItem(B.key,JSON.stringify({version:1,runs:z}));let m=w(B);return!R&&!m.has(y)&&z.length+m.size>=u?!1:(m.add(y),B)}catch{return f(),!1}},accept(t,i){if(t)try{let u=b(t);u.includes(i)||t.storage.setItem(t.key,JSON.stringify(tn.parse({version:1,runs:[...u,i].slice(-100)})))}catch{let u=Me.get(t.storage);u||Me.set(t.storage,u=new Set),u.add(t.key),f()}finally{h(t)}},release:h}}function Re(){let n,d,f=()=>{clearTimeout(n),n=void 0;let b=d;d=void 0,b?.cancelled()};return{get active(){return d!==void 0},start(b,w,h,t){if(d)return;if(b===0){w()?h():t();return}let i={valid:w,cancelled:t};d=i,n=setTimeout(()=>{d===i&&(d=void 0,n=void 0,w()?h():t())},b*1e3)},recheck(){d&&!d.valid()&&f()},cancel:f}}var Pe=n=>["running","waiting"].includes(n.status)&&!n.pendingRequest&&(n.stopped||!n.screen&&!n.paywall&&n.instruction?.type==="wait"&&n.instruction.kind!=="operation");function Rn(n){let d=we(n.baseUrl),f=n.scope,b=Ae(n),w=n.fetch??globalThis.fetch.bind(globalThis),h,t=!1,i=!1,u=0,y=0,R="",P=0,B=0,z=0,m=!1,s,E=!0,_,M,S,l,o,T=-1,g,N=e=>{g===e&&(O.release(e.deliveryTicket),g=void 0,k())},J=new Set,c=(e,a)=>Q(n.onStatus,e,a),$=Re(),O=Se({storage:n.deliveryStorage,binding:()=>{let e=n.session.snapshot()?.customerId;return e?[d,f.projectId,f.environment,n.environmentId,"customer",e]:void 0},unavailable:()=>c("delivery_unavailable")}),ee=new Set,te=nn({storage:n.recoveryStorage,binding:()=>{let e=n.session.snapshot()?.customerId;return e?[d,f.projectId,f.environment,n.environmentId,n.appManifestRelease,e]:void 0},unavailable:()=>c("recovery_unavailable")}),Z=e=>te.forget(e.storageKey,e.command.requestId);function Y(e,a){a&&(e.runId=a.id,e.expiresAt=a.runExpiresAt),te.retain(e.storageKey,{command:e.command,target:e.target,...e.runId&&{runId:e.runId},...e.expiresAt&&{expiresAt:e.expiresAt},...e.deliveryLimit!==void 0&&{deliveryLimit:e.deliveryLimit}})}function re(){let e=o;o=void 0,e?.host.destroy(),e?.slot.remove(),e?.client.reset(),k()}let le=()=>$.active||g!==void 0||o!==void 0&&!o.background;function me(e,a){if(o?.client!==e)return;Y(o.recovery,a);let p=Pe(a);o.slot.hidden=p,p!==o.background&&(o.background=p,p?c("run_background",o.entryId):T=y,k())}function pe(e,a,p){let v=e.client.view;if(!a||e.background||!v?.screen||v.paywall||v.pendingRequest||v.stopped||v.status!=="waiting")return;let K=Ke.parse({operation:"close",requestId:crypto.randomUUID(),nodeId:v.nodeId,visit:v.visit,revision:v.revision,customerToken:a}),j=Ae({...n,session:void 0});j.requestWithCredential("funnels",K,e.runToken,{keepalive:p}).then(()=>Z(e.recovery)).catch(()=>{}).finally(()=>j.dispose())}let ae=()=>{o&&pe(o,n.session.peek(),!0)},r=()=>Date.now()<B&&performance.now()<z;function A(e){if(e.target.release!==n.appManifestRelease||!r())return!1;try{return de(e.target.render,document,location.pathname,()=>{})}catch{return c("incompatible",e.id),!1}}function H(e){if(t||e.epoch!==P||e.visit!==y||document.visibilityState==="hidden")return!1;try{return de(e.target.render,document,location.pathname,()=>{})}catch{return!1}}function W(e){if(le()){c("in_progress",e.id);return}let a=P,p=y;$.start(e.delivery?.delaySeconds??0,()=>!t&&a===P&&p===y&&document.visibilityState!=="hidden"&&A(e)&&h?.entries.some(v=>v.id===e.id&&v.funnelId===e.funnelId&&v.versionId===e.versionId&&v.event===e.event&&JSON.stringify(v.target)===JSON.stringify(e.target)&&JSON.stringify(v.delivery)===JSON.stringify(e.delivery))===!0,()=>{V(e)},()=>{J.delete(`${e.funnelId}:${e.id}`)})}async function V(e){if(le()){c("in_progress",e.id);return}if(!n.session.peek()){c("identity_required",e.id);return}let a=te.load(),p=a?.entries.find(C=>C.command.funnelId===e.funnelId&&(!C.expiresAt||Date.parse(C.expiresAt)>Date.now()));if(p){if(!X(p)){c("recovery_pending",e.id);return}let C={...p,storageKey:a.key,epoch:P,visit:y};ee.add(C.command.requestId),g=C,await F(C);return}let v=crypto.randomUUID(),K=O.claim(e.id,e.funnelId,e.delivery?.maxPerSession,v);if(K===!1){c("frequency",e.id),k();return}let j={freshStart:!0,deliveryLimit:e.delivery?.maxPerSession,deliveryTicket:K,command:ve.parse({operation:"entry_start",entryId:e.id,funnelId:e.funnelId,versionId:e.versionId,release:n.appManifestRelease,requestId:v,locale:document.documentElement.lang||"en"}),epoch:P,visit:y,target:e.target,storageKey:a?.key};ee.add(j.command.requestId),g=j,await F(j)}async function F(e){if(e.dispatching)return;e.dispatching=!0;let a=e.freshStart===!0;e.freshStart=!1;let p,v=!1,K=!1;async function j(C){if(e.epoch!==P)return;let D=C.view;if(!(e.storageKey&&D&&(Pe(D)||D.paywall||D.pendingRequest))&&D&&["running","waiting"].includes(D.status))try{await C.submit({operation:"close",requestId:crypto.randomUUID(),nodeId:D.nodeId,visit:D.visit,revision:D.revision}),Z(e)}catch(x){if(!(x instanceof G&&x.code==="FORBIDDEN"))throw x}}try{if(!e.deliveryTicket&&e.deliveryLimit!==void 0){let q=O.claim(e.command.entryId,e.command.funnelId,e.deliveryLimit,e.command.requestId,!0);q!==!1&&(e.deliveryTicket=q)}Y(e),c("starting",e.command.entryId);let C=await b.request("funnels",e.command),D=Ze.safeParse(C);if(D.success){if(D.data.scope.projectId!==f.projectId||D.data.scope.environment!==f.environment)throw new G("SCOPE_MISMATCH","Entry scope changed");e.epoch===P&&c(D.data.reason,e.command.entryId),Z(e),N(e);return}let x=Xe.parse(C);if(!x.runToken||x.scope.projectId!==f.projectId||x.scope.environment!==f.environment||x.run.source.type!=="funnel"||x.run.source.id!==e.command.funnelId||x.run.source.versionId!==e.command.versionId||e.runId!==void 0&&x.run.id!==e.runId)throw new G("INVALID_RESPONSE","Invalid entry Run");if(O.accept(e.deliveryTicket,x.run.id),e.epoch!==P){N(e),c("identity_changed",e.command.entryId);return}Y(e,x.run);let L=Ce({...n,runToken:x.runToken,funnelId:e.command.funnelId,initialResponse:a?C:void 0});p=L,K=!0,await L.get(),K=!1;let ne=L.view;if(!ne||ne.id!==x.run.id||ne.source.type!=="funnel"||ne.source.id!==e.command.funnelId||ne.source.versionId!==e.command.versionId)throw new G("INVALID_RESPONSE","Entry Run version changed");if(!["running","waiting"].includes(ne.status)){Z(e),N(e),c("run_ended",e.command.entryId);return}let{showFunnelRun:fe}=await import("./funnel-runtime-host-TJPF3FJS.js");if(!H(e)){await j(L),c("left_screen",e.command.entryId),N(e);return}let Fe=!1,ke=!1;if(o&&!o.background){await j(L),c("in_progress",e.command.entryId),N(e);return}o&&re();let ie=document.createElement("div");ie.hidden=Pe(ne),n.container.append(ie);let xe=await fe(ie,{...n.host,client:L,appManifestRelease:n.appManifestRelease,onState(q){me(L,q),Q(n.host?.onState,q)},onDismiss(q){Fe=!0,ie.remove(),q&&!["running","waiting"].includes(q.status)&&Z(e),o?.client===L&&(o=void 0,L.reset(),k(),q&&q.status!=="completed"&&c("run_ended",e.command.entryId)),Q(n.host?.onDismiss,q)},onComplete(q){ke=!0,Z(e),o?.client===L&&re(),Q(n.host?.onComplete,q)},onError(q){Q(n.host?.onError,q),o?.client===L&&q instanceof G&&q.code==="FORBIDDEN"&&(Z(e),re(),c("run_ended",e.command.entryId))}}).catch(q=>{throw ie.remove(),q});if(!H(e)||Fe||ke){xe.destroy(),ie.remove(),H(e)||await j(L),N(e);return}let he=Pe(L.view??ne);ie.hidden=he,o={host:xe,client:L,slot:ie,entryId:e.command.entryId,background:he,runToken:x.runToken,owner:n.session.peek(),recovery:e},he||(T=e.visit),v=!0,N(e),c("started",e.command.entryId),he&&c("run_background",e.command.entryId)}catch(C){C instanceof G&&(!p||K&&C.code==="FORBIDDEN")&&C.status!==void 0&&C.status>=400&&C.status<500&&!C.retryable&&(Z(e),N(e)),e.epoch===P&&!t&&(c("start_failed",e.command.entryId),Q(n.host?.onError,C))}finally{v||p?.reset(),e.dispatching=!1}}function X(e){if(e.command.release!==n.appManifestRelease||e.target.release!==n.appManifestRelease)return!1;try{return de(e.target.render,document,location.pathname,()=>{})}catch{return!1}}function ye(){if(le())return!1;let e=te.load();for(let a of e?.entries??[]){if(a.expiresAt&&Date.parse(a.expiresAt)<=Date.now()){te.forget(e.key,a.command.requestId);continue}if(a.command.requestId===o?.recovery.command.requestId||ee.has(a.command.requestId)||!X(a))continue;ee.add(a.command.requestId);let p={...a,storageKey:e.key,epoch:P,visit:y};return g=p,F(p),!0}return!1}function ue(){if(m=!1,$.recheck(),t||!i||document.visibilityState==="hidden")return;se();let e=o!==void 0&&!o.background;if(e&&(T=y),!ye()){if(!r()){E=!0;return}E=!1;for(let a of h?.entries??[]){let p=`${a.funnelId}:${a.id}`;if(!(a.event!=="screen_enter"||J.has(p)||!A(a))){if(!n.session.peek()){c("identity_required",a.id);continue}if(T===y){J.add(p),e&&c("in_progress",a.id);continue}if(g||$.active){c("in_progress",a.id);return}J.add(p),W(a);break}}}}let k=()=>{!m&&!t&&(m=!0,queueMicrotask(ue))};function se(){let e=location.origin+location.pathname;return e===R?!1:(R=e,y++,$.cancel(),E=!0,J.clear(),ee.clear(),!0)}function oe(){se()&&k()}function ce(e){if(!e.isTrusted||e.button!==0||e.ctrlKey||e.metaKey||e.shiftKey||e.altKey||document.visibilityState==="hidden")return;let a=e.target;if(!(a instanceof Element)||a.closest("[data-indiana-funnel]"))return;let p=a.closest("button,a,input");if(!(!p||p.matches(":disabled,[aria-disabled='true']")||p.closest("[hidden],[inert],[aria-hidden='true']")))for(let v of h?.entries??[]){let K=v.target.button;if(!(v.event!=="button_click"||!K||!A(v))){try{let j=be(document);if(!p.matches(K.selector)||j(K.selector,p)!==1)continue}catch{c("incompatible",v.id);continue}W(v);break}}}async function Ne(){if(t)return;if(s)return s;let e=++u,a=new AbortController;_=a;let p,v=new Promise((C,D)=>{p=()=>D(new G("TIMEOUT","Funnel entry configuration read cancelled or timed out")),a.signal.addEventListener("abort",p,{once:!0})}),K=setTimeout(()=>a.abort(),n.timeoutMs??5e3),j=(async()=>{let C=async()=>{let fe=await w(`${d}/api/v1/funnel-entries/${n.environmentId}?iam=${n.appManifestRelease}`,{credentials:"omit",cache:"no-store",redirect:"error",signal:a.signal});if(!fe.ok)throw new G("SERVICE_UNAVAILABLE","Funnel entries unavailable",fe.status);return ge.parse(await fe.json())},D=await Promise.race([C(),v]),x=Date.parse(D.validatedAt),L=Date.parse(D.validUntil);if(D.scope.projectId!==f.projectId||D.scope.environment!==f.environment||D.scope.environmentId!==n.environmentId||D.release!==n.appManifestRelease||L<=Date.now()||x>Date.now()+5e3||L-x>6e4||L<=x)throw new G("INVALID_RESPONSE","Entry configuration scope or deadline changed");if(t||e!==u)return;let ne=h===void 0;h=D,B=L,z=performance.now()+Math.min(L-Date.now(),6e4),$.recheck(),(ne||E)&&k()})();s=j;try{await j}finally{clearTimeout(K),a.signal.removeEventListener("abort",p),s===j&&(s=void 0)}}async function on(){if(!(!i||t)){try{await Ne()}catch{t||c("configuration_unavailable")}k()}}let Oe=Ie({document,run:on,delay:()=>i&&!t?15e3:void 0});return{async start(){i||t||(i=!0,R=location.origin+location.pathname,M=Ee(oe),S=n.session.subscribeIdentity(()=>{P++,$.cancel(),O.release(g?.deliveryTicket),E=!0,g=void 0,J.clear(),T=-1,ee.clear(),o&&pe(o,o.owner,!1),re(),k()}),l=new MutationObserver(k),l.observe(document.documentElement,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["hidden","inert","aria-hidden","data-indiana-id","id","style","data-testid","data-test","data-qa"]}),document.addEventListener("click",ce,!0),document.addEventListener("visibilitychange",k),addEventListener("pagehide",ae),await Oe.refresh())},refresh:Ne,async retry(){g&&!t&&g.epoch===P&&await F(g)},destroy(){t=!0,u++,$.cancel(),O.release(g?.deliveryTicket),Oe.destroy(),_?.abort(),l?.disconnect(),M?.(),S?.(),document.removeEventListener("click",ce,!0),document.removeEventListener("visibilitychange",k),removeEventListener("pagehide",ae),ae(),re(),b.dispose(),h=void 0}}}function Pn(n){let d=we(n.baseUrl),f=n.fetch??globalThis.fetch.bind(globalThis),b,w=0,h=0,t=!1,i=!1,u=!1,y=0,R=0,P=-1,B=!1,z="",m,s,E,_,M=new Set,S,l,o,T=(r,A)=>Q(n.onStatus,r,A),g=Re(),N=()=>{try{return n.deliveryIdentity?.()}catch{return}},J=()=>JSON.stringify(N()),c=Se({storage:n.deliveryStorage,binding:()=>{let r=N();return r?.id?[d,n.scope.projectId,n.scope.environment,n.environmentId,r.type,r.id]:void 0},unavailable:()=>T("delivery_unavailable")}),$=()=>Date.now()<w&&performance.now()<h;function O(r){try{return $()&&r.target.release===n.appManifestRelease&&de(r.target.render,document,location.pathname,()=>{})}catch{return T("incompatible",r.id),!1}}function ee(){let r=o;o=void 0,r?.host.destroy(),r?.slot.remove()}async function te(r){if(r.dispatching)return;r.dispatching=!0;let A=y;try{let H=await r.process.open({operation:"entry_start",funnelId:r.entry.funnelId,versionId:r.entry.versionId,entryId:r.entry.id,release:n.appManifestRelease,locale:n.locale??"en"});c.accept(r.deliveryTicket,H.run.id);let{showFunnelRun:W}=await import("./funnel-runtime-host-TJPF3FJS.js");if(t||A!==y||l!==r)return;let V=document.createElement("div");n.container.append(V),P=R;let F=await W(V,{...n.host,client:H.controller,appManifestRelease:n.appManifestRelease,onDismiss(X){o?.process===r.process&&(o=void 0,V.remove()),Q(n.host?.onDismiss,X)}});if(t||A!==y||l!==r){F.destroy(),V.remove();return}o={entry:r.entry,process:r.process,host:F,slot:V,deliveryTicket:r.deliveryTicket},l=void 0,T("run_presented",r.entry.id)}catch(H){if(t||A!==y||l!==r)return;H instanceof G&&"result"in H?(c.release(r.deliveryTicket),l=void 0,r.process.destroy(),T("suppressed",r.entry.id),Y()):T("entry_unavailable",r.entry.id)}finally{r.dispatching=!1}}function Z(r){if(t||i||l||o||S||g.active||P===R||!O(r))return;let A=`${R}:${r.id}`;if(M.has(A))return;M.add(A);let H=R,W=y,V=J();g.start(r.delivery?.delaySeconds??0,()=>!t&&y===W&&R===H&&J()===V&&document.visibilityState!=="hidden"&&O(r)&&b?.entries.some(F=>F.id===r.id&&F.funnelId===r.funnelId&&F.versionId===r.versionId&&F.event===r.event&&JSON.stringify(F.target)===JSON.stringify(r.target)&&JSON.stringify(F.delivery)===JSON.stringify(r.delivery))===!0,()=>{let F=c.claim(r.id,r.funnelId,r.delivery?.maxPerSession,crypto.randomUUID());if(F===!1){T("frequency",r.id),Y();return}try{let X={entry:r,process:n.createProcess(r),visit:R,deliveryTicket:F};l=X,te(X)}catch(X){c.release(F),T("entry_unavailable",r.id),Q(n.host?.onError,X)}},()=>{M.delete(A)})}function Y(){B||t||(B=!0,queueMicrotask(()=>{if(B=!1,g.recheck(),!(t||i||document.visibilityState==="hidden"||!$()||l||o||S||g.active||P===R)){for(let r of b?.entries??[])if(r.event==="screen_enter"&&!M.has(`${R}:${r.id}`)&&O(r)){Z(r);break}}}))}function re(r){if(!r.isTrusted||r.defaultPrevented||!(r.target instanceof Element)||l||o||S||P===R)return;let A=be(document,()=>{});for(let H of b?.entries??[]){let W=H.target.button;if(H.event!=="button_click"||!W||!O(H))continue;let V=r.target.closest(W.selector);if(!(!V||V.tagName.toLowerCase()!==W.tag||A(W.selector)!==1||V.matches(":disabled")||V.closest('[inert],[hidden],[aria-hidden="true"]'))){Z(H);break}}}let le=()=>{let r=location.origin+location.pathname;r!==z&&(z=r,R++,g.cancel(),M.clear(),Y())};async function me(){if(t)return;if(s)return s;let r=y,A=new AbortController;m=A;let H,W=new Promise((ye,ue)=>{H=ue}),V=()=>H(new G("TIMEOUT","Funnel entry read cancelled"));A.signal.addEventListener("abort",V,{once:!0});let F=setTimeout(()=>A.abort(),n.timeoutMs??5e3),X=(async()=>{let ye=encodeURIComponent(JSON.stringify(["funnel-process/1"])),ue=async()=>{let ce=await f(`${d}/api/v1/funnel-entries/${n.environmentId}?iam=${n.appManifestRelease}&executionContracts=${ye}`,{credentials:"omit",cache:"no-store",redirect:"error",signal:A.signal});if(!ce.ok)throw new G("SERVICE_UNAVAILABLE","Funnel entries unavailable",ce.status);return ge.parse(await ce.json())},k=await Promise.race([ue(),W]),se=Date.parse(k.validatedAt),oe=Date.parse(k.validUntil);if(k.scope.projectId!==n.scope.projectId||k.scope.environment!==n.scope.environment||k.scope.environmentId!==n.environmentId||k.release!==n.appManifestRelease||oe<=Date.now()||se>Date.now()+5e3||oe<=se||oe-se>6e4)throw new G("INVALID_RESPONSE","Entry scope or deadline changed");t||r!==y||(b=k,w=oe,h=performance.now()+Math.min(oe-Date.now(),6e4),g.recheck(),Y())})();s=X;try{await X}finally{clearTimeout(F),A.signal.removeEventListener("abort",V),s===X&&(s=void 0)}}async function pe(){if(!(!u||t))try{await me()}catch{t||T("configuration_unavailable")}}let ae=Ie({document,run:pe,delay:()=>u&&!t?15e3:void 0});return{async start(){u||t||(u=!0,z=location.origin+location.pathname,E=Ee(le),_=new MutationObserver(Y),_.observe(document.documentElement,{subtree:!0,childList:!0,attributes:!0,attributeFilter:["hidden","inert","aria-hidden","data-indiana-id","id","style","data-testid","data-test","data-qa"]}),document.addEventListener("click",re,!0),document.addEventListener("visibilitychange",Y),await ae.refresh())},refresh:me,async retry(){l&&!t&&await te(l)},async syncIdentity(){g.cancel();let r=o??l??S;if(!r){i=!1,Y();return}try{let A=await r.process.syncIdentity();return i=!1,S===r&&(l={...r,visit:R},S=void 0,await te(l)),A}catch(A){throw r.process.view||(S={...r,visit:R},l=void 0,ee()),A}},async detach(){i=!0,y++,g.cancel(),m?.abort();let r=o??l??S;r&&(S={...r,visit:R}),l=void 0,ee(),r&&await r.process.detach()},destroy(){t=!0,y++,g.cancel(),ae.destroy(),m?.abort(),_?.disconnect(),E?.(),document.removeEventListener("click",re,!0),document.removeEventListener("visibilitychange",Y);let r=o??l??S;c.release(r?.deliveryTicket),l=void 0,S=void 0,ee(),r?.process.destroy(),b=void 0}}}async function _n(n,d){return(await import("./paywall-OAVC654P.js")).showPaywall(n,d)}async function ot(){return await Promise.all([import("./paywall-OAVC654P.js"),import("./screen-renderer-YIIT742O.js")]),_n}async function at(...n){return n[1]=ze(n[1]),(await import("./paywall-session-U6SPRJRS.js")).createPaywallSession(...n)}async function st(...n){let d=n[1].signal?.aborted?void 0:We(n[1].client);try{return import("./screen-renderer-YIIT742O.js").catch(()=>{}),import("./paywall-OAVC654P.js").catch(()=>{}),await(await rn(()=>import("./funnel-runtime-host-TJPF3FJS.js"),n[1].prepared)).showFunnelRun(...n)}finally{d?.()}}async function rn(n,d){try{return await n()}catch(f){throw d&&d.state!=="adopted"&&await import("./funnel-paywall-prerender-Z7RA4YDY.js").then(b=>b.preparedInternals(d)?.release(),()=>{}),f}}async function ct(...n){return import("./screen-renderer-YIIT742O.js").catch(()=>{}),import("./paywall-OAVC654P.js").catch(()=>{}),(await rn(()=>import("./funnel-host-purchase-FVYPBPET.js"),n[1].prepared)).showFunnelPurchase(...n)}async function dt(...n){return import("./funnel-host-purchase-FVYPBPET.js").catch(()=>{}),import("./screen-renderer-YIIT742O.js").catch(()=>{}),(await import("./funnel-paywall-prerender-Z7RA4YDY.js")).prerenderFunnelPurchase(...n)}async function lt(){await Promise.all([import("./funnel-paywall-prerender-Z7RA4YDY.js"),import("./funnel-host-purchase-FVYPBPET.js"),import("./paywall-OAVC654P.js"),import("./screen-renderer-YIIT742O.js"),import("./paywall-content-75XEM7K3.js"),import("./check-response-N22NNTIT.js"),import("./operation-contracts-EK4RCUWJ.js")])}async function ut(...n){return(await import("./content-QNBATPA2.js")).mountContent(...n)}async function ft(...n){return(await import("./content-QNBATPA2.js")).prepareContent(...n)}export{G as LongplayError,I as MerchantBridgeError,un as createBrowserFunnelCommandStorage,gn as createBrowserFunnelPurchaseStorage,pn as createConfigurationSync,dn as createFeatureClient,hn as createFunnelClient,En as createFunnelPageExperiments,In as createFunnelProcess,vn as createFunnelPurchaseClient,Ce as createFunnelRunController,Rn as createIamFunnelEntries,Pn as createIamFunnelProcessEntries,wn as createLocalFunnelClient,ln as createLongplay,Sn as createMerchantBridge,at as createPaywallSession,yn as evaluateFunnelNode,sn as formatCouponDiscount,an as formatCouponMoney,cn as formatCouponTerms,fn as getPaywallRecovery,ut as mountContent,lt as preloadFunnelPurchase,ot as preloadPaywall,ft as prepareContent,mn as preparePaywallFallback,dt as prerenderFunnelPurchase,ct as showFunnelPurchase,st as showFunnelRun,_n as showPaywall};
@@ -0,0 +1 @@
1
+ import{N as r,O as m,h as e}from"./chunk-S43TYW3V.js";import"./chunk-WQ3O5RXN.js";import"./chunk-XJRDO3NI.js";import"./chunk-LOLMUXHW.js";import"./chunk-HEHLFHW7.js";import"./chunk-VLSP3LRH.js";import"./chunk-CR2XJ2CX.js";import"./chunk-CILM5XMH.js";import"./chunk-WOT6VMZA.js";export{m as merchantBridgeCommerceSchema,r as merchantBridgeOperationSchema,e as merchantOperationLookupSchema};