@tinkerlandai/longplay-sdk 0.10.34 → 0.10.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/README.md +83 -5
- package/README.zh-CN.md +26 -3
- package/dist/{ai-usage-T62xehqa.d.ts → ai-usage-DXwAGTxT.d.ts} +1 -1
- package/dist/{api-Do-6AyWa.d.ts → api-r6FfVQpg.d.ts} +6 -1
- package/dist/check-response-DHY6T5Z2.js +1 -0
- package/dist/{chunk-7MNJH5GB.js → chunk-2HSD2SEU.js} +1 -1
- package/dist/chunk-2KKLY323.js +1 -0
- package/dist/{chunk-BXPXJARS.js → chunk-35VG2IYD.js} +1 -1
- package/dist/chunk-3NCMYTNG.js +1 -0
- package/dist/{chunk-HQITRRHF.js → chunk-5XIKN35D.js} +1 -1
- package/dist/chunk-5XKFUFXK.js +1 -0
- package/dist/chunk-7ZEXY4GC.js +1 -0
- package/dist/chunk-BL7E4RZ2.js +1 -0
- package/dist/{chunk-FYQXSGRT.js → chunk-BTPEXSNY.js} +1 -1
- package/dist/chunk-C4GBV32U.js +10 -0
- package/dist/chunk-CGXNU5BC.js +1 -0
- package/dist/chunk-DB4EO3JG.js +1 -0
- package/dist/chunk-DHT3AWJQ.js +1 -0
- package/dist/chunk-GLYFT5WW.js +1 -0
- package/dist/chunk-HS56A4IK.js +1 -0
- package/dist/chunk-HVVJGLYZ.js +1 -0
- package/dist/chunk-HYE2YQYM.js +1 -0
- package/dist/chunk-I6D25FWU.js +1 -0
- package/dist/{chunk-TYY3MUTF.js → chunk-IOBB6KFK.js} +1 -1
- package/dist/chunk-JOIPLLHK.js +1 -0
- package/dist/{chunk-MIBRUDIS.js → chunk-LAGGWYH3.js} +1 -1
- package/dist/{chunk-6T575JKD.js → chunk-LVG5ED52.js} +1 -1
- package/dist/{chunk-I6TSQQ5N.js → chunk-M3GGR53D.js} +1 -1
- package/dist/chunk-MHWPEMX7.js +1 -0
- package/dist/chunk-MYBUQFTC.js +1 -0
- package/dist/{chunk-7QL4GF4C.js → chunk-O4KXODTJ.js} +1 -1
- package/dist/chunk-OL2AI6DA.js +1 -0
- package/dist/chunk-QHJWVLJC.js +1 -0
- package/dist/chunk-R3YVDRTB.js +1 -0
- package/dist/chunk-RHF4NFCZ.js +1 -0
- package/dist/{chunk-5HJYR6Z4.js → chunk-RHWZRHK7.js} +1 -1
- package/dist/{chunk-X4W22IH6.js → chunk-TIQS5DUF.js} +1 -1
- package/dist/chunk-U4WUX3WB.js +1 -0
- package/dist/chunk-UHTTCVSL.js +1 -0
- package/dist/{chunk-UWLEGMWX.js → chunk-UVUFJO2V.js} +1 -1
- package/dist/{chunk-7NELM6EH.js → chunk-VKG6BB3Z.js} +1 -1
- package/dist/chunk-VWMFR22O.js +1 -0
- package/dist/chunk-W32FI2A2.js +1 -0
- package/dist/chunk-W3K5ARMY.js +1 -0
- package/dist/chunk-WRLVPHPE.js +1 -0
- package/dist/chunk-XE7GU6FZ.js +1 -0
- package/dist/{chunk-EQPEUPMG.js → chunk-XQTCEQXI.js} +1 -1
- package/dist/chunk-YQX27SBG.js +1 -0
- package/dist/{chunk-VYFSRHXM.js → chunk-ZYF6TRJ3.js} +1 -1
- package/dist/{configuration-sync-DdTRUv7A.d.ts → configuration-sync-BHrAf-ql.d.ts} +10 -1
- package/dist/content-RGKTEV23.js +1 -0
- package/dist/funnel-host-purchase-M7MM33EC.js +1 -0
- package/dist/{funnel-local-client-BeGBvi3z.d.ts → funnel-local-client-DR8OpKGU.d.ts} +167 -25
- package/dist/funnel-paywall-prerender-OSBI4VMY.js +1 -0
- package/dist/{funnel-process-client-C6QKDZun.d.ts → funnel-process-client-C87U4r_G.d.ts} +17 -3
- package/dist/funnel-runtime-host-AMJXEASH.js +1 -0
- package/dist/index.d.ts +214 -63
- package/dist/index.js +1 -1
- package/dist/merchant-bridge-contracts-GJQVKEAG.js +1 -0
- package/dist/native-shell.js +1 -1
- package/dist/openrouter.d.ts +3 -3
- package/dist/openrouter.js +1 -1
- package/dist/operation-contracts-MFK2KORK.js +1 -0
- package/dist/page.d.ts +2 -2
- package/dist/page.js +1 -1
- package/dist/paywall-ATZ2IZPS.js +1 -0
- package/dist/paywall-content-XERXGNND.js +1 -0
- package/dist/paywall-session-EMMF6IYS.js +1 -0
- package/dist/popup.d.ts +21 -3
- package/dist/popup.js +1 -1
- package/dist/{presentation-loading-CFSiS0VX.d.ts → presentation-loading-B_v5XZtM.d.ts} +11 -1
- package/dist/react-native.d.ts +7 -7
- package/dist/react-native.js +1 -1
- package/dist/{screen-CGCJ46b1.d.ts → screen-qUBRsUi9.d.ts} +26 -21
- package/dist/screen-renderer-B7LUTPTJ.js +1 -0
- package/dist/server.d.ts +37 -7
- package/dist/server.js +2 -2
- package/dist/{visual-dom-6DCUZGPB.js → visual-dom-5LUN4AHO.js} +1 -1
- package/dist/visual.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-3JJYWRA3.js +0 -1
- package/dist/chunk-4WZVC4TM.js +0 -1
- package/dist/chunk-5JWMP4YD.js +0 -1
- package/dist/chunk-7VRZYSTR.js +0 -1
- package/dist/chunk-EHDHWYVJ.js +0 -1
- package/dist/chunk-ERJP2GBD.js +0 -1
- package/dist/chunk-ILEDKSRQ.js +0 -1
- package/dist/chunk-ITGERPCJ.js +0 -1
- package/dist/chunk-N7YXDSQL.js +0 -1
- package/dist/chunk-NAZU3EEJ.js +0 -1
- package/dist/chunk-QBA3B4YK.js +0 -1
- package/dist/chunk-R23IGK5U.js +0 -1
- package/dist/chunk-R4FDIYMN.js +0 -1
- package/dist/chunk-RKPAIF6U.js +0 -1
- package/dist/chunk-SCC3O2RD.js +0 -1
- package/dist/chunk-TDSATEGE.js +0 -10
- package/dist/chunk-THMGTRXP.js +0 -1
- package/dist/chunk-U6UHASIB.js +0 -1
- package/dist/chunk-WKIR2EQG.js +0 -1
- package/dist/chunk-WTVLNUMS.js +0 -1
- package/dist/chunk-ZGCKQWQ5.js +0 -1
- package/dist/content-ORU4ODJQ.js +0 -1
- package/dist/funnel-host-purchase-BEFE3N3E.js +0 -1
- package/dist/funnel-runtime-host-V6TYIDX3.js +0 -1
- package/dist/merchant-bridge-contracts-ZUQ6SGXZ.js +0 -1
- package/dist/operation-contracts-443N2P3A.js +0 -1
- package/dist/paywall-HO4PS472.js +0 -1
- package/dist/paywall-session-MZXFOPTR.js +0 -1
- package/dist/screen-renderer-W7ZGBFIR.js +0 -1
- /package/dist/{chunk-BID4UGWB.js → chunk-CILM5XMH.js} +0 -0
- /package/dist/{chunk-UKMEW5I7.js → chunk-OJM6ORHE.js} +0 -0
- /package/dist/{chunk-VF6QMMEA.js → chunk-ZYN4CRHS.js} +0 -0
package/dist/server.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { F as FoundationApi, I as InvoiceModeParams } from './api-
|
|
2
|
-
import {
|
|
3
|
-
export {
|
|
1
|
+
import { F as FoundationApi, I as InvoiceModeParams } from './api-r6FfVQpg.js';
|
|
2
|
+
import { Q as IndianaServerOptions, u as IndianaError, T as FunnelProcessSuppression, U as FunnelProcessCommand, K as FunnelProcessResponse, C as CustomerSession, J as FunnelProcessOpenInput, N as FunnelProcessMutation, w as PaywallStartInput, P as PaywallSession, m as FeatureClientOptions, R as RemoteFeatureResult } from './funnel-local-client-DR8OpKGU.js';
|
|
3
|
+
export { l as FeatureClient, a as FunnelStartInput, L as LocalFunnelClient, t as LocalFunnelClientOptions, z as createFeatureClient, V as createFunnelStartClient, B as createLocalFunnelClient } from './funnel-local-client-DR8OpKGU.js';
|
|
4
4
|
import * as zod from 'zod';
|
|
5
5
|
import { z } from 'zod';
|
|
6
|
-
import { S as StackNode } from './screen-
|
|
7
|
-
import { a as ConfigurationSync } from './configuration-sync-
|
|
8
|
-
export { c as createConfigurationSync } from './configuration-sync-
|
|
6
|
+
import { S as StackNode } from './screen-qUBRsUi9.js';
|
|
7
|
+
import { a as ConfigurationSync } from './configuration-sync-BHrAf-ql.js';
|
|
8
|
+
export { c as createConfigurationSync } from './configuration-sync-BHrAf-ql.js';
|
|
9
9
|
import { J as JsonValue, E as EvaluationContext, s as stickyAssignmentDocumentSchema, F as FeatureResult } from './growth-rules-B4YYy64R.js';
|
|
10
10
|
import { d as FunnelLocalConfiguration, f as MerchantBridgeCommand, M as MerchantBridgeManifest, m as merchantBridgeOperationInputSchema } from './funnel-node-evaluation-COxXtZEQ.js';
|
|
11
11
|
export { F as FunnelNodeEvaluationContext, g as MerchantRequirementCheckInput, h as MerchantRequirementCheckResult, i as entitlementRequirementDigest, e as evaluateFunnelNode } from './funnel-node-evaluation-COxXtZEQ.js';
|
|
12
|
-
export { d as AiPricingOptions, b as AiTokenQuote, a as AiTokenUsage, A as AiUsageContext, e as AiUsageMiddlewareOptions, f as AiUsageRecord, g as aiPriceSnapshotSchema, h as aiTokenQuoteSchema, c as createAiPricing, i as createAiUsageMiddleware, j as createConfiguredAiPricing } from './ai-usage-
|
|
12
|
+
export { d as AiPricingOptions, b as AiTokenQuote, a as AiTokenUsage, A as AiUsageContext, e as AiUsageMiddlewareOptions, f as AiUsageRecord, g as aiPriceSnapshotSchema, h as aiTokenQuoteSchema, c as createAiPricing, i as createAiUsageMiddleware, j as createConfiguredAiPricing } from './ai-usage-DXwAGTxT.js';
|
|
13
13
|
import 'zod/v4';
|
|
14
14
|
import '@ai-sdk/provider';
|
|
15
15
|
|
|
@@ -3525,6 +3525,7 @@ declare function createFunnelProcessAdapter<Request>(options: FunnelProcessAdapt
|
|
|
3525
3525
|
} | undefined;
|
|
3526
3526
|
mobile?: "sheet" | "fullscreen" | undefined;
|
|
3527
3527
|
backdrop?: "none" | "blur" | "scrim" | "dim" | "strong-dim" | undefined;
|
|
3528
|
+
position?: "top" | "bottom" | "center" | undefined;
|
|
3528
3529
|
} | {
|
|
3529
3530
|
type: "sheet";
|
|
3530
3531
|
size: "sm" | "md" | "lg";
|
|
@@ -3575,6 +3576,7 @@ declare function createFunnelProcessAdapter<Request>(options: FunnelProcessAdapt
|
|
|
3575
3576
|
} | undefined;
|
|
3576
3577
|
mobile?: "sheet" | "fullscreen" | undefined;
|
|
3577
3578
|
backdrop?: "none" | "blur" | "scrim" | "dim" | "strong-dim" | undefined;
|
|
3579
|
+
position?: "top" | "bottom" | "center" | undefined;
|
|
3578
3580
|
} | {
|
|
3579
3581
|
type: "sheet";
|
|
3580
3582
|
size: "sm" | "md" | "lg";
|
|
@@ -5522,6 +5524,7 @@ declare function createFunnelProcessAdapter<Request>(options: FunnelProcessAdapt
|
|
|
5522
5524
|
} | undefined;
|
|
5523
5525
|
mobile?: "sheet" | "fullscreen" | undefined;
|
|
5524
5526
|
backdrop?: "none" | "blur" | "scrim" | "dim" | "strong-dim" | undefined;
|
|
5527
|
+
position?: "top" | "bottom" | "center" | undefined;
|
|
5525
5528
|
} | {
|
|
5526
5529
|
type: "sheet";
|
|
5527
5530
|
size: "sm" | "md" | "lg";
|
|
@@ -5628,6 +5631,7 @@ declare function createFunnelProcessAdapter<Request>(options: FunnelProcessAdapt
|
|
|
5628
5631
|
} | undefined;
|
|
5629
5632
|
mobile?: "sheet" | "fullscreen" | undefined;
|
|
5630
5633
|
backdrop?: "none" | "blur" | "scrim" | "dim" | "strong-dim" | undefined;
|
|
5634
|
+
position?: "top" | "bottom" | "center" | undefined;
|
|
5631
5635
|
} | {
|
|
5632
5636
|
type: "sheet";
|
|
5633
5637
|
size: "sm" | "md" | "lg";
|
|
@@ -7396,6 +7400,7 @@ declare function createFunnelProcessAdapter<Request>(options: FunnelProcessAdapt
|
|
|
7396
7400
|
} | undefined;
|
|
7397
7401
|
mobile?: "sheet" | "fullscreen" | undefined;
|
|
7398
7402
|
backdrop?: "none" | "blur" | "scrim" | "dim" | "strong-dim" | undefined;
|
|
7403
|
+
position?: "top" | "bottom" | "center" | undefined;
|
|
7399
7404
|
} | {
|
|
7400
7405
|
type: "sheet";
|
|
7401
7406
|
size: "sm" | "md" | "lg";
|
|
@@ -7555,6 +7560,7 @@ declare function createFunnelProcessAdapter<Request>(options: FunnelProcessAdapt
|
|
|
7555
7560
|
} | undefined;
|
|
7556
7561
|
mobile?: "sheet" | "fullscreen" | undefined;
|
|
7557
7562
|
backdrop?: "none" | "blur" | "scrim" | "dim" | "strong-dim" | undefined;
|
|
7563
|
+
position?: "top" | "bottom" | "center" | undefined;
|
|
7558
7564
|
} | {
|
|
7559
7565
|
type: "sheet";
|
|
7560
7566
|
size: "sm" | "md" | "lg";
|
|
@@ -7605,6 +7611,7 @@ declare function createFunnelProcessAdapter<Request>(options: FunnelProcessAdapt
|
|
|
7605
7611
|
} | undefined;
|
|
7606
7612
|
mobile?: "sheet" | "fullscreen" | undefined;
|
|
7607
7613
|
backdrop?: "none" | "blur" | "scrim" | "dim" | "strong-dim" | undefined;
|
|
7614
|
+
position?: "top" | "bottom" | "center" | undefined;
|
|
7608
7615
|
} | {
|
|
7609
7616
|
type: "sheet";
|
|
7610
7617
|
size: "sm" | "md" | "lg";
|
|
@@ -9552,6 +9559,7 @@ declare function createFunnelProcessAdapter<Request>(options: FunnelProcessAdapt
|
|
|
9552
9559
|
} | undefined;
|
|
9553
9560
|
mobile?: "sheet" | "fullscreen" | undefined;
|
|
9554
9561
|
backdrop?: "none" | "blur" | "scrim" | "dim" | "strong-dim" | undefined;
|
|
9562
|
+
position?: "top" | "bottom" | "center" | undefined;
|
|
9555
9563
|
} | {
|
|
9556
9564
|
type: "sheet";
|
|
9557
9565
|
size: "sm" | "md" | "lg";
|
|
@@ -9658,6 +9666,7 @@ declare function createFunnelProcessAdapter<Request>(options: FunnelProcessAdapt
|
|
|
9658
9666
|
} | undefined;
|
|
9659
9667
|
mobile?: "sheet" | "fullscreen" | undefined;
|
|
9660
9668
|
backdrop?: "none" | "blur" | "scrim" | "dim" | "strong-dim" | undefined;
|
|
9669
|
+
position?: "top" | "bottom" | "center" | undefined;
|
|
9661
9670
|
} | {
|
|
9662
9671
|
type: "sheet";
|
|
9663
9672
|
size: "sm" | "md" | "lg";
|
|
@@ -11426,6 +11435,7 @@ declare function createFunnelProcessAdapter<Request>(options: FunnelProcessAdapt
|
|
|
11426
11435
|
} | undefined;
|
|
11427
11436
|
mobile?: "sheet" | "fullscreen" | undefined;
|
|
11428
11437
|
backdrop?: "none" | "blur" | "scrim" | "dim" | "strong-dim" | undefined;
|
|
11438
|
+
position?: "top" | "bottom" | "center" | undefined;
|
|
11429
11439
|
} | {
|
|
11430
11440
|
type: "sheet";
|
|
11431
11441
|
size: "sm" | "md" | "lg";
|
|
@@ -11583,6 +11593,7 @@ declare function createFunnelProcessAdapter<Request>(options: FunnelProcessAdapt
|
|
|
11583
11593
|
} | undefined;
|
|
11584
11594
|
mobile?: "sheet" | "fullscreen" | undefined;
|
|
11585
11595
|
backdrop?: "none" | "blur" | "scrim" | "dim" | "strong-dim" | undefined;
|
|
11596
|
+
position?: "top" | "bottom" | "center" | undefined;
|
|
11586
11597
|
} | {
|
|
11587
11598
|
type: "sheet";
|
|
11588
11599
|
size: "sm" | "md" | "lg";
|
|
@@ -11633,6 +11644,7 @@ declare function createFunnelProcessAdapter<Request>(options: FunnelProcessAdapt
|
|
|
11633
11644
|
} | undefined;
|
|
11634
11645
|
mobile?: "sheet" | "fullscreen" | undefined;
|
|
11635
11646
|
backdrop?: "none" | "blur" | "scrim" | "dim" | "strong-dim" | undefined;
|
|
11647
|
+
position?: "top" | "bottom" | "center" | undefined;
|
|
11636
11648
|
} | {
|
|
11637
11649
|
type: "sheet";
|
|
11638
11650
|
size: "sm" | "md" | "lg";
|
|
@@ -13580,6 +13592,7 @@ declare function createFunnelProcessAdapter<Request>(options: FunnelProcessAdapt
|
|
|
13580
13592
|
} | undefined;
|
|
13581
13593
|
mobile?: "sheet" | "fullscreen" | undefined;
|
|
13582
13594
|
backdrop?: "none" | "blur" | "scrim" | "dim" | "strong-dim" | undefined;
|
|
13595
|
+
position?: "top" | "bottom" | "center" | undefined;
|
|
13583
13596
|
} | {
|
|
13584
13597
|
type: "sheet";
|
|
13585
13598
|
size: "sm" | "md" | "lg";
|
|
@@ -13686,6 +13699,7 @@ declare function createFunnelProcessAdapter<Request>(options: FunnelProcessAdapt
|
|
|
13686
13699
|
} | undefined;
|
|
13687
13700
|
mobile?: "sheet" | "fullscreen" | undefined;
|
|
13688
13701
|
backdrop?: "none" | "blur" | "scrim" | "dim" | "strong-dim" | undefined;
|
|
13702
|
+
position?: "top" | "bottom" | "center" | undefined;
|
|
13689
13703
|
} | {
|
|
13690
13704
|
type: "sheet";
|
|
13691
13705
|
size: "sm" | "md" | "lg";
|
|
@@ -15454,6 +15468,7 @@ declare function createFunnelProcessAdapter<Request>(options: FunnelProcessAdapt
|
|
|
15454
15468
|
} | undefined;
|
|
15455
15469
|
mobile?: "sheet" | "fullscreen" | undefined;
|
|
15456
15470
|
backdrop?: "none" | "blur" | "scrim" | "dim" | "strong-dim" | undefined;
|
|
15471
|
+
position?: "top" | "bottom" | "center" | undefined;
|
|
15457
15472
|
} | {
|
|
15458
15473
|
type: "sheet";
|
|
15459
15474
|
size: "sm" | "md" | "lg";
|
|
@@ -15611,6 +15626,7 @@ declare function createFunnelProcessAdapter<Request>(options: FunnelProcessAdapt
|
|
|
15611
15626
|
} | undefined;
|
|
15612
15627
|
mobile?: "sheet" | "fullscreen" | undefined;
|
|
15613
15628
|
backdrop?: "none" | "blur" | "scrim" | "dim" | "strong-dim" | undefined;
|
|
15629
|
+
position?: "top" | "bottom" | "center" | undefined;
|
|
15614
15630
|
} | {
|
|
15615
15631
|
type: "sheet";
|
|
15616
15632
|
size: "sm" | "md" | "lg";
|
|
@@ -15661,6 +15677,7 @@ declare function createFunnelProcessAdapter<Request>(options: FunnelProcessAdapt
|
|
|
15661
15677
|
} | undefined;
|
|
15662
15678
|
mobile?: "sheet" | "fullscreen" | undefined;
|
|
15663
15679
|
backdrop?: "none" | "blur" | "scrim" | "dim" | "strong-dim" | undefined;
|
|
15680
|
+
position?: "top" | "bottom" | "center" | undefined;
|
|
15664
15681
|
} | {
|
|
15665
15682
|
type: "sheet";
|
|
15666
15683
|
size: "sm" | "md" | "lg";
|
|
@@ -17608,6 +17625,7 @@ declare function createFunnelProcessAdapter<Request>(options: FunnelProcessAdapt
|
|
|
17608
17625
|
} | undefined;
|
|
17609
17626
|
mobile?: "sheet" | "fullscreen" | undefined;
|
|
17610
17627
|
backdrop?: "none" | "blur" | "scrim" | "dim" | "strong-dim" | undefined;
|
|
17628
|
+
position?: "top" | "bottom" | "center" | undefined;
|
|
17611
17629
|
} | {
|
|
17612
17630
|
type: "sheet";
|
|
17613
17631
|
size: "sm" | "md" | "lg";
|
|
@@ -17714,6 +17732,7 @@ declare function createFunnelProcessAdapter<Request>(options: FunnelProcessAdapt
|
|
|
17714
17732
|
} | undefined;
|
|
17715
17733
|
mobile?: "sheet" | "fullscreen" | undefined;
|
|
17716
17734
|
backdrop?: "none" | "blur" | "scrim" | "dim" | "strong-dim" | undefined;
|
|
17735
|
+
position?: "top" | "bottom" | "center" | undefined;
|
|
17717
17736
|
} | {
|
|
17718
17737
|
type: "sheet";
|
|
17719
17738
|
size: "sm" | "md" | "lg";
|
|
@@ -19482,6 +19501,7 @@ declare function createFunnelProcessAdapter<Request>(options: FunnelProcessAdapt
|
|
|
19482
19501
|
} | undefined;
|
|
19483
19502
|
mobile?: "sheet" | "fullscreen" | undefined;
|
|
19484
19503
|
backdrop?: "none" | "blur" | "scrim" | "dim" | "strong-dim" | undefined;
|
|
19504
|
+
position?: "top" | "bottom" | "center" | undefined;
|
|
19485
19505
|
} | {
|
|
19486
19506
|
type: "sheet";
|
|
19487
19507
|
size: "sm" | "md" | "lg";
|
|
@@ -19785,6 +19805,7 @@ declare function renewFunnelRun(options: IndianaServerOptions, input: {
|
|
|
19785
19805
|
} | undefined;
|
|
19786
19806
|
mobile?: "sheet" | "fullscreen" | undefined;
|
|
19787
19807
|
backdrop?: "none" | "blur" | "scrim" | "dim" | "strong-dim" | undefined;
|
|
19808
|
+
position?: "top" | "bottom" | "center" | undefined;
|
|
19788
19809
|
} | {
|
|
19789
19810
|
type: "sheet";
|
|
19790
19811
|
size: "sm" | "md" | "lg";
|
|
@@ -19891,6 +19912,7 @@ declare function renewFunnelRun(options: IndianaServerOptions, input: {
|
|
|
19891
19912
|
} | undefined;
|
|
19892
19913
|
mobile?: "sheet" | "fullscreen" | undefined;
|
|
19893
19914
|
backdrop?: "none" | "blur" | "scrim" | "dim" | "strong-dim" | undefined;
|
|
19915
|
+
position?: "top" | "bottom" | "center" | undefined;
|
|
19894
19916
|
} | {
|
|
19895
19917
|
type: "sheet";
|
|
19896
19918
|
size: "sm" | "md" | "lg";
|
|
@@ -20160,6 +20182,7 @@ declare function renewFunnelRun(options: IndianaServerOptions, input: {
|
|
|
20160
20182
|
} | undefined;
|
|
20161
20183
|
mobile?: "sheet" | "fullscreen" | undefined;
|
|
20162
20184
|
backdrop?: "none" | "blur" | "scrim" | "dim" | "strong-dim" | undefined;
|
|
20185
|
+
position?: "top" | "bottom" | "center" | undefined;
|
|
20163
20186
|
} | {
|
|
20164
20187
|
type: "sheet";
|
|
20165
20188
|
size: "sm" | "md" | "lg";
|
|
@@ -20210,6 +20233,7 @@ declare function renewFunnelRun(options: IndianaServerOptions, input: {
|
|
|
20210
20233
|
} | undefined;
|
|
20211
20234
|
mobile?: "sheet" | "fullscreen" | undefined;
|
|
20212
20235
|
backdrop?: "none" | "blur" | "scrim" | "dim" | "strong-dim" | undefined;
|
|
20236
|
+
position?: "top" | "bottom" | "center" | undefined;
|
|
20213
20237
|
} | {
|
|
20214
20238
|
type: "sheet";
|
|
20215
20239
|
size: "sm" | "md" | "lg";
|
|
@@ -23639,6 +23663,7 @@ declare function renewFunnelRun(options: IndianaServerOptions, input: {
|
|
|
23639
23663
|
} | undefined;
|
|
23640
23664
|
mobile?: "sheet" | "fullscreen" | undefined;
|
|
23641
23665
|
backdrop?: "none" | "blur" | "scrim" | "dim" | "strong-dim" | undefined;
|
|
23666
|
+
position?: "top" | "bottom" | "center" | undefined;
|
|
23642
23667
|
} | {
|
|
23643
23668
|
type: "sheet";
|
|
23644
23669
|
size: "sm" | "md" | "lg";
|
|
@@ -25379,6 +25404,7 @@ declare function createFunnelCampaignClient(options: IndianaServerOptions & {
|
|
|
25379
25404
|
} | undefined;
|
|
25380
25405
|
mobile?: "sheet" | "fullscreen" | undefined;
|
|
25381
25406
|
backdrop?: "none" | "blur" | "scrim" | "dim" | "strong-dim" | undefined;
|
|
25407
|
+
position?: "top" | "bottom" | "center" | undefined;
|
|
25382
25408
|
} | {
|
|
25383
25409
|
type: "sheet";
|
|
25384
25410
|
size: "sm" | "md" | "lg";
|
|
@@ -25485,6 +25511,7 @@ declare function createFunnelCampaignClient(options: IndianaServerOptions & {
|
|
|
25485
25511
|
} | undefined;
|
|
25486
25512
|
mobile?: "sheet" | "fullscreen" | undefined;
|
|
25487
25513
|
backdrop?: "none" | "blur" | "scrim" | "dim" | "strong-dim" | undefined;
|
|
25514
|
+
position?: "top" | "bottom" | "center" | undefined;
|
|
25488
25515
|
} | {
|
|
25489
25516
|
type: "sheet";
|
|
25490
25517
|
size: "sm" | "md" | "lg";
|
|
@@ -25754,6 +25781,7 @@ declare function createFunnelCampaignClient(options: IndianaServerOptions & {
|
|
|
25754
25781
|
} | undefined;
|
|
25755
25782
|
mobile?: "sheet" | "fullscreen" | undefined;
|
|
25756
25783
|
backdrop?: "none" | "blur" | "scrim" | "dim" | "strong-dim" | undefined;
|
|
25784
|
+
position?: "top" | "bottom" | "center" | undefined;
|
|
25757
25785
|
} | {
|
|
25758
25786
|
type: "sheet";
|
|
25759
25787
|
size: "sm" | "md" | "lg";
|
|
@@ -25804,6 +25832,7 @@ declare function createFunnelCampaignClient(options: IndianaServerOptions & {
|
|
|
25804
25832
|
} | undefined;
|
|
25805
25833
|
mobile?: "sheet" | "fullscreen" | undefined;
|
|
25806
25834
|
backdrop?: "none" | "blur" | "scrim" | "dim" | "strong-dim" | undefined;
|
|
25835
|
+
position?: "top" | "bottom" | "center" | undefined;
|
|
25807
25836
|
} | {
|
|
25808
25837
|
type: "sheet";
|
|
25809
25838
|
size: "sm" | "md" | "lg";
|
|
@@ -29233,6 +29262,7 @@ declare function createFunnelCampaignClient(options: IndianaServerOptions & {
|
|
|
29233
29262
|
} | undefined;
|
|
29234
29263
|
mobile?: "sheet" | "fullscreen" | undefined;
|
|
29235
29264
|
backdrop?: "none" | "blur" | "scrim" | "dim" | "strong-dim" | undefined;
|
|
29265
|
+
position?: "top" | "bottom" | "center" | undefined;
|
|
29236
29266
|
} | {
|
|
29237
29267
|
type: "sheet";
|
|
29238
29268
|
size: "sm" | "md" | "lg";
|
package/dist/server.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import{a as pn}from"./chunk-
|
|
1
|
+
import{a as pn}from"./chunk-W3K5ARMY.js";import{a as I}from"./chunk-UVUFJO2V.js";import{a as fn,b as hn,c as gn,d as yn}from"./chunk-5XIKN35D.js";import{a as xt}from"./chunk-MYBUQFTC.js";import{a as Ue,b as Ve,c as qe,d as He,e as m}from"./chunk-UHTTCVSL.js";import"./chunk-XQTCEQXI.js";import{a as Te,b as ae,c as yt,d as It,e as wt,f as xe,g as vt,h as Me,i as dn,j as ln,k as mn}from"./chunk-HS56A4IK.js";import{A as Tt,C as V,D as N,a as Oe,e as ft,f as ht,l as gt,m as z,n as St,q as Ct,r as Rt,s as bt,t as At,u as Ot,z as pe}from"./chunk-HYE2YQYM.js";import{c as h}from"./chunk-MHWPEMX7.js";import"./chunk-2HSD2SEU.js";import"./chunk-5XKFUFXK.js";import{a as Et,b as _e}from"./chunk-BTPEXSNY.js";import{A as tt,B as Se,C as ie,E as se,F as Ce,K as j,M as ce,N as nt,P as Ee,Q as rt,R as ot,d as Ge,e as je,h as we,p as ze,q as Ke,s as an,t as sn,w as cn,x as X,y as W,z as oe}from"./chunk-2KKLY323.js";import"./chunk-R3YVDRTB.js";import"./chunk-U4WUX3WB.js";import{e as at}from"./chunk-JOIPLLHK.js";import{$ as mt,A as it,B as Re,C as st,D as ct,I as ut,J as dt,K as be,L as Ae,T as pt,U as de,V as Z,W as lt,d as ve,f as Ze,g as et,u as q}from"./chunk-GLYFT5WW.js";import"./chunk-WRLVPHPE.js";import"./chunk-3NCMYTNG.js";import"./chunk-35VG2IYD.js";import"./chunk-CGXNU5BC.js";import"./chunk-RHWZRHK7.js";import"./chunk-HVVJGLYZ.js";import{a as Ne,b as Le}from"./chunk-ZYF6TRJ3.js";import{I as Xe,L as We,_ as ue}from"./chunk-QHJWVLJC.js";import{i as un,k as $e,l as Qe,m as Je}from"./chunk-XE7GU6FZ.js";import{c as Ie}from"./chunk-LAGGWYH3.js";import{b as Y}from"./chunk-DHT3AWJQ.js";import{a as c}from"./chunk-TIQS5DUF.js";import"./chunk-7ZEXY4GC.js";import"./chunk-3VUPVXAV.js";import"./chunk-RHF4NFCZ.js";import{b as u}from"./chunk-ZYN4CRHS.js";import{a as Ye}from"./chunk-O4KXODTJ.js";import"./chunk-CILM5XMH.js";import"./chunk-DSPLGTQI.js";import"./chunk-WOT6VMZA.js";var _t=4,Mt=[...tt,"requirement_checks","native_offers","preparations","benefit_claims","authorizations","business_results","checkout_termination"],In=u.enum(Mt),ee=(e,n)=>u.array(e).max(n).refine(t=>new Set(t).size===t.length,"Declarations must be unique"),ke=u.strictObject({...se.shape,bridgeVersion:u.literal(_t),capabilities:ee(In,Mt.length),checkKinds:ee(u.enum(["access","metered","credit"]),3),preparationActions:ee(u.enum(["purchase","subscription_change","refund"]),3),authorizationKinds:ee(u.enum(["auto_topup"]),1),nextActionTypes:ee(u.enum(["redirect","authenticate"]),2),resultEvents:ee(u.enum(["benefit.claimed","authorization.updated"]),2)}).superRefine((e,n)=>{e.capabilities.includes("catalog")!==(e.catalog!=="none")&&n.addIssue({code:"custom",path:["catalog"],message:"Catalog declaration differs from its capability"}),(e.capabilities.includes("billing_records")!==e.billingEvents.length>0||new Set(e.billingEvents).size!==e.billingEvents.length)&&n.addIssue({code:"custom",path:["billingEvents"],message:"Declare unique supported billing events"});let t=r=>e.capabilities.includes(r),o=(r,a)=>n.addIssue({code:"custom",path:[r],message:a});t("requirement_checks")!==e.checkKinds.length>0&&o("checkKinds","Declare the supported Check kinds"),t("preparations")!==e.preparationActions.length>0&&o("preparationActions","Declare the supported preparation actions"),t("authorizations")!==e.authorizationKinds.length>0&&o("authorizationKinds","Declare the supported authorization kinds"),t("business_results")!==e.resultEvents.length>0&&o("resultEvents","Declare the supported non-financial results");for(let[r,a,s]of[["purchases","purchase","purchase.completed"],["subscription_changes","subscription_change","subscription.change.completed"],["refunds","refund","refund.updated"]])t(r)&&(!t("operation_status")||!t("billing_records")||!t("preparations")||!e.preparationActions.includes(a)||!e.billingEvents.includes(s))&&o("capabilities",`${r} requires preparation, original lookup and its billing result`);t("purchases")&&!e.billingEvents.includes("purchase.closed")&&o("billingEvents","Purchase execution requires its terminal closure result"),t("checkout_termination")&&(!t("operation_status")||!t("billing_records")||!e.billingEvents.includes("purchase.closed"))&&o("capabilities","Checkout termination requires original lookup and purchase.closed"),t("subscription_changes")&&!e.billingEvents.includes("subscription.change.closed")&&o("billingEvents","Subscription change execution requires its terminal closure result");for(let[r,a]of[["benefit_claims","benefit.claimed"],["authorizations","authorization.updated"]])t(r)&&(!t("operation_status")||!t("business_results")||!e.resultEvents.includes(a))&&o("capabilities",`${r} requires original lookup and its non-financial result`)}),K={"bridge.ping":u.strictObject({challenge:u.uuid()}),"bridge.describe":u.strictObject({}),"requirement.check":$e,"operation.prepare":ze,"benefit.claim":Ue,"operation.read":qe,"purchase.terminate":j},wn={"bridge.ping":u.strictObject({challenge:u.uuid()}),"bridge.describe":ke,"requirement.check":Qe,"operation.prepare":Ke,"benefit.claim":Ve,"operation.read":He,"purchase.terminate":j.extend({outcome:u.enum(["requested","already_paid"])})},Gn=u.enum(["bridge.ping","bridge.describe","requirement.check","operation.prepare","benefit.claim","operation.read","purchase.terminate"]);function $(e,n){return u.strictObject({bridgeVersion:u.literal(_t),requestId:u.uuid(),scope:Ce,command:u.literal(e),data:n})}var kt=u.discriminatedUnion("command",[$("bridge.ping",K["bridge.ping"]),$("bridge.describe",K["bridge.describe"]),$("requirement.check",K["requirement.check"]),$("operation.prepare",K["operation.prepare"]),$("benefit.claim",K["benefit.claim"]),$("operation.read",K["operation.read"]),$("purchase.terminate",K["purchase.terminate"])]),Be=u.strictObject({code:u.string().regex(/^MERCHANT_BRIDGE_[A-Z_]+$/),message:u.string().min(1).max(500),retryable:u.boolean(),recovery:u.string().min(1).max(80),effect:u.enum(["none","unknown"])}).refine(e=>e.effect!=="unknown"||!e.retryable&&e.recovery==="recover_operation","Unknown effects require original-operation recovery");function Bt(e){let n={bridgeVersion:u.literal(4),requestId:u.uuid(),scope:Ce,command:u.literal(e)};return u.union([u.strictObject({...n,data:wn[e]}),u.strictObject({...n,error:Be})])}var Pt="X-Indiana-Bridge-Signature",Q="X-Indiana-Bridge-Key-Id";function vn(e){return new TextEncoder().encode(e)}function Dt(e){return Uint8Array.from(atob(e.replaceAll("-","+").replaceAll("_","/")),n=>n.charCodeAt(0))}function Ft(e,n,t,o){return vn(`indiana-merchant-bridge:${o}
|
|
2
2
|
${n}
|
|
3
3
|
POST
|
|
4
4
|
${W}
|
|
5
5
|
${t}
|
|
6
|
-
${e}`)}async function Nt(e){let n=ie.parse(e);return crypto.subtle.importKey("raw",Dt(n.signingSecret),{name:"HMAC",hash:"SHA-256"},!1,["sign","verify"])}async function te(e,n,t,o=Date.now(),r=X){let a=String(Math.floor(o/1e3)),s=new Uint8Array(await crypto.subtle.sign("HMAC",await Nt(n),Ft(e,t,a,r))),l=btoa(String.fromCharCode(...s)).replaceAll("+","-").replaceAll("/","_").replace(/=+$/,"");return{[Q]:n.keyId,[Pt]:`t=${a},v1=${l}`}}async function ne(e,n,t,o,r=Date.now(),a=X){try{if(n.get(Q)!==t.keyId)return!1;let s=/^t=([0-9]{1,12}),v1=([A-Za-z0-9_-]{43})$/.exec(n.get(Pt)??"");return!s||Math.abs(r/1e3-Number(s[1]))>300?!1:await crypto.subtle.verify("HMAC",await Nt(t),Dt(s[2]),Ft(e,o,s[1],a))}catch{return!1}}var Lt=u.strictObject({operation:u.literal("renew_run"),runId:u.uuid(),customerId:u.uuid()}),le=ft.refine(e=>!!e.runToken,"Renewal returns a credential"),Ut=ht.refine(e=>!!e.runToken,"Renewal returns a credential");var Pe=u.discriminatedUnion("operation",[u.strictObject({operation:u.literal("campaign_decide"),...pt}).refine(be,Ae),u.strictObject({operation:u.literal("campaign_start"),funnelId:u.uuid(),requestId:u.uuid(),customer:ut,customerData:dt.optional(),locale:u.string().min(1).max(35),parameters:ue,cooldownSeconds:u.number().int().min(1).max(2592e3)}).refine(be,Ae)]),Sn=u.union([u.strictObject({scope:Y,suppressed:u.literal(!0),reason:u.enum(["frequency","in_progress"]),retryAt:u.iso.datetime({offset:!0})}),le]),Vt=u.union([Sn.options[0],Ut]);var qt=u.discriminatedUnion("provider",[u.strictObject({provider:u.literal("apple"),orderId:u.uuid(),receiptId:u.uuid(),signedTransaction:u.string().min(1).max(131072)}),u.strictObject({provider:u.literal("google"),orderId:u.uuid(),receiptId:u.uuid(),purchaseToken:u.string().min(1).max(16384)})]),Ht=u.strictObject({orderId:u.uuid(),receiptId:u.uuid(),transactionIds:u.array(u.string().min(1).max(255)).min(1).max(50),membership:u.boolean()});var Gt=u.strictObject({operation:u.literal("native_receipt"),requestId:u.uuid(),customerToken:u.string().regex(Ne),orderId:u.uuid(),receiptId:u.uuid(),nativeEvidence:qt.nullable()}).refine(e=>e.nativeEvidence===null||e.nativeEvidence.orderId===e.orderId&&e.nativeEvidence.receiptId===e.receiptId,"Evidence must use this current order receipt"),jt=u.strictObject({scope:Y,requestId:u.uuid(),orderId:u.uuid(),receiptId:u.uuid(),orderStatus:u.enum(["created","pending","trialing","paid","cancelled","failed"]),refunded:u.boolean(),nativeCompletion:Ht.optional()});var zt=u.strictObject({document:mt,configuration:z.options[0]});function me(e){return{async getCustomer(n){let t=m.getCustomer;return f(e,t,n,{request:"Invalid customer lookup",response:"Invalid customer response"})},async listCustomers(n={}){let t=m.listCustomers;return f(e,t,n,{request:"Invalid customer filters",response:"Invalid customer response"})},async updateCustomer(n){let t=m.updateCustomer;return f(e,t,n,{request:"Invalid customer patch",response:"Invalid customer response"})},async createGuestCustomer(n){let t=m.createGuestCustomer;return f(e,t,n)},async resumeGuestSession(n){let t=m.resumeGuestSession;return f(e,t,n)},async claimGuestCustomer(n){let t=m.claimGuestCustomer;return f(e,t,n)},async revokeCustomerSessions(n){let t=m.revokeSessions;return f(e,t,n)},async createCustomerSession(n){return f(e,m.createSession,{customerId:n},{request:"A customer ID is required",response:"Invalid customer session response"})},async getOrCreateCustomer(n){return f(e,m.createCustomer,n,{request:"Invalid customer input",response:"Invalid customer response"})}}}function Kt(e){return{async checkEntitlement(n){let t=m.checkEntitlement,o=t.request.parse(n),r=await f(e,t,o,I);return Et(o.requirement,r.check,o.customerId,r.scope),r},async readHoldings(n){let t=m.readHoldings;return f(e,t,n,I)},async readSeats(n){let t=m.readSeats;return f(e,t,n,I)},async manageSeat(n){let t=m.manageSeat;return f(e,t,n,I)}}}function $t(e){return{async readAiPricing(n){let t=m.readAiPricing;return f(e,t,n,I)},async readUsage(n){let t=m.readUsage;return f(e,t,n,I)},async setUsage(n){let t=m.setUsage;return f(e,t,n,I)},async manageBalanceGrant(n){let t=m.manageBalanceGrant;return f(e,t,n,I)},async readBalanceSource(n){let t=m.readBalanceSource;return f(e,t,n,I)},async adjustBalance(n){let t=m.adjustBalance;return f(e,t,n,I)},async listBalanceGrants(n){let t=m.listBalanceGrants;return f(e,t,n,I)},async manageBillingLimits(n){let t=m.manageBillingLimits;return f(e,t,n,I)},async manageUsageEntity(n){let t=m.manageUsageEntity;return f(e,t,n,I)},async readUsageAnalytics(n){let t=m.readUsageAnalytics;return f(e,t,n,I)},async readCreditAnalytics(n){let t=m.readCreditAnalytics;return f(e,t,n,I)},async submitUsageBatch(n){let t=m.submitUsageBatch;return f(e,t,n,I)},async readUsageBatch(n){let t=m.readUsageBatch;return f(e,t,n,I)},async readLedger(n){let t=m.readLedger;return f(e,t,n,I)},async readCreditStatement(n){let t=m.readCreditStatement;return f(e,t,n,I)},async quoteBalance(n){let t=m.quoteBalance;return f(e,t,n,I)},async trackUsage(n){let t=m.trackUsage;return f(e,t,n,I)},async mutateBalance(n){let t=m.mutateBalance;return f(e,t,n,I)}}}function Qt(e){return{async listInvoiceTemplates(n={}){let t=m.listInvoiceTemplates;return f(e,t,n,I)},async previewInvoice(n){let t=m.previewInvoice;return f(e,t,n,I)},async createInvoice(n){let t=m.createInvoice;return f(e,t,n,I)},async prepareBillingAdjustment(n){let t=m.prepareBillingAdjustment;return f(e,t,n,I)},async manageInvoice(n){let t=m.manageInvoice;return f(e,t,n,I)},async readInvoiceOperation(n){let t=m.readInvoiceOperation;return f(e,t,n,I)},async listInvoices(n){let t=m.listInvoices;return f(e,t,n,I)},async getInvoice(n){let t=m.getInvoice;return f(e,t,n,I)},async setupPayment(n){let t=m.setupPayment;return f(e,t,n,I)},async readPaymentSetup(n){let t=m.readPaymentSetup;return f(e,t,n,I)},async readBillingInvoice(n){let t=m.readBillingInvoice;return f(e,t,n,I)},async previewRefund(n){let t=m.previewRefund;return f(e,t,n,I)},async refund(n){let t=m.refund;return f(e,t,n,I)},async readRefund(n){let t=m.readRefund;return f(e,t,n,I)}}}function Jt(e){return{async previewSubscriptionBatch(n){let t=m.previewSubscriptionBatch;return f(e,t,n,I)},async confirmSubscriptionBatch(n){let t=m.confirmSubscriptionBatch;return f(e,t,n,I)},async readSubscriptionBatch(n){let t=m.readSubscriptionBatch;return f(e,t,n,I)},async abandonSubscriptionBatch(n){let t=m.abandonSubscriptionBatch;return f(e,t,n,I)},async manageSubscriptionTrial(n){let t=m.manageSubscriptionTrial;return f(e,t,n,I)},async readSubscriptionTrial(n){let t=m.readSubscriptionTrial;return f(e,t,n,I)},async listSubscriptions(n){let t=m.listSubscriptions;return f(e,t,n,I)},async listPurchases(n){let t=m.listPurchases;return f(e,t,n,I)},async listSubscriptionConflicts(n){let t=m.listSubscriptionConflicts;return f(e,t,n,I)},async retrySubscriptionConflict(n){let t=m.retrySubscriptionConflict;return f(e,t,n,I)},async previewUpdate(n){let t=m.previewUpdate;return f(e,t,n,I)},async update(n){let t=m.update;return f(e,t,n,I)},async readSubscriptionUpdate(n){let t=m.readSubscriptionUpdate;return f(e,t,n,I)},async restoreNativePurchase(n){let t=m.restoreNativePurchase;return f(e,t,n,I)},async verifySubscriptions(n){let t=m.verifySubscriptions;return f(e,t,n,I)},async previewAttach(n){let t=m.previewAttach;return f(e,t,n,I)},async recordMerchantEvent(n){return f(e,m.recordMerchantEvent,n,{request:"Invalid merchant event",parseResponse:I})},async attach(n){let t=m.attach;return f(e,t,n,I)},async readSubscriptionOperation(n){let t=m.readSubscriptionOperation;return f(e,t,n,I)}}}function Yt(e){return{async grantModelBenefit(n){return f(e,m.grantModelBenefit,n,{request:"Invalid model benefit grant",response:"Invalid model benefit response"})},async readModelBenefit(n){return f(e,m.readModelBenefit,n,{request:"Invalid model benefit operation",response:"Invalid model benefit response"})},async grantOffer(n){let t=m.grantOffer;return f(e,{...t,request:t.request.refine(o=>!!o.customerId)},{...n,requestId:n.requestId??crypto.randomUUID()},{request:"Invalid offer grant",response:"Invalid offer response"})}}}function Xt(e){return{...Kt(e),...$t(e),...Qt(e),...Jt(e),...Yt(e)}}function Wt(e){return{async getFeatures(n={}){let t=m.getFeatures;return f(e,t,n,I)},async evaluateFeatures(n){let t=m.evaluateFeatures;return f(e,t,n,I)}}}function Zt(e){return{async trackEvents(n){let t=m.trackEvents;return f(e,t,n,I)}}}function en(e){return{async resolveContent(n){let t=m.resolveContent;return f(e,t,n,I)},async resolvePaywall(n){let t=m.resolvePaywall,o=t.request.parse(n),r=await f(e,t,o,I);return _e(o,r.paywall.check,r.scope),r},async resolveOffering(n){let t=m.resolveOffering,o=t.request.parse(n),r=await f(e,t,o,I);return _e(o,r.check,r.scope),r}}}function Cn(e){V(e.apiKey,"Secret API keys must stay on your backend");let t=N(e).request;return{async sendMessage(o){let r=m.sendMessage;return r.response.parse(await t(r.path,r.request.parse(o)))},async readMessage(o){let r=m.readMessage;return r.response.parse(await t(r.path,r.request.parse(o)))},...me(t),...Xt(t),...Wt(t),...Zt(t),...en(t)}}function De(){if(typeof window<"u")throw new c("SERVER_ONLY","Guest identity is issued by your backend");let e=crypto.getRandomValues(new Uint8Array(32));return"gg_gc_"+btoa(String.fromCharCode(...e)).replaceAll("+","-").replaceAll("/","_").replaceAll("=","")}var tn=()=>new c("CONFLICT","Process synchronization is in progress",425),L=()=>new c("CONFLICT","This process belongs to a different account",409,void 0,{reason:"CUSTOMER_BINDING_CONFLICT"}),En=(e,n)=>JSON.stringify(e)===JSON.stringify(n),fe=class extends c{constructor(t){super("CONFLICT","Funnel entry is suppressed",409,void 0,{reason:t.reason==="in_progress"?"OPERATION_IN_PROGRESS":"STATE_CHANGED",recovery:"check_availability"});this.result=t}result};function Rn(e){if(V(e.apiKey,"Funnel process identity belongs to your backend"),e.session)throw new c("INVALID_CONFIGURATION","The process adapter owns its credential lifecycle");let n=N(e),t=me(n.request),o=`longplay:process:${e.scope.projectId}:${e.scope.environment}:`;async function r(g){let i=await e.resolveUser(g);if(i!==null&&(typeof i?.externalUserId!="string"||!i.externalUserId||i.externalUserId!==i.externalUserId.trim()||i.externalUserId.startsWith("gg_guest_")))throw new c("INVALID_RESPONSE","The merchant identity resolver returned an invalid subject");return i}async function a(g){let i=await e.resolveContext(g);if(i?.confirmed!==!0||!i.processKey||!i.guestKey)throw new c("INVALID_CONFIGURATION","A confirmed durable process handle is required");return{process:o+"run:"+i.processKey,guest:o+"guest:"+i.guestKey}}async function s(g,i){for(let w=0;w<8;w++){let R=await e.store.read(g),C=i(R?structuredClone(R.value):null);if(R&&En(R.value,C)||await e.store.compareAndSwap(g,R?.revision??null,C))return C}throw tn()}async function l(g){let i=await e.store.read(g);if(!i)throw new c("NOT_FOUND","Open the process before continuing",404);return i.value}async function p(g){let i=await l(g);for(let w of i.revocations??[])await t.revokeCustomerSessions(w),await s(g,R=>{if(!R)throw L();return R.revocations=R.revocations?.filter(C=>C.sessionId!==w.sessionId),R})}async function v(g,i){let w=Te.parse(g);return i?n.requestWithCredential("funnel-processes",w,i):n.request("funnel-processes",w)}function E(g,i){if(i.scope.projectId!==e.scope.projectId||i.scope.environment!==e.scope.environment||g.run&&(g.run.id!==i.run.id||g.run.source.versionId!==i.run.source.versionId||g.run.source.id!==i.run.source.id||g.run.runExpiresAt!==i.run.runExpiresAt||g.run.identity.startedAs!==i.run.identity.startedAs||g.run.identity.participantId!==i.run.identity.participantId||g.run.identity.binding&&g.run.identity.binding.id!==i.run.identity.binding?.id)||g.runToken&&i.runToken&&g.runToken!==i.runToken)throw new c("INVALID_RESPONSE","Process identity or Run changed")}async function b(g,i,w){return s(g,R=>{if(!R)throw new c("NOT_FOUND","Process handle is missing",404);return E(R,i),(!R.run||i.run.revision>=R.run.revision)&&(R.run=i.run),R.runToken??=i.runToken,w!==void 0&&(R.target=w),R})}async function d(g,i){if(i.detached)throw new c("UNAUTHENTICATED","The process is detached",401);let w=i.run?.identity.binding?.customerId??i.run?.identity.participantId;if(!w)throw new c("INVALID_RESPONSE","Process participant is missing");if(i.session?.customerId===w&&Date.parse(i.session.expiresAt)>Date.now()+3e4)return i.session;let R={id:crypto.randomUUID(),until:Date.now()+(e.timeoutMs??35e3)+5e3},C=await s(g,O=>{if(!O||O.detached||O.run?.id!==i.run?.id)throw L();if(O.sessionLease&&O.sessionLease.until>Date.now())throw tn();return O.sessionLease=R,O}),A;try{if(C.session?.customerId===w&&Date.parse(C.session.refreshExpiresAt)>Date.now())try{if(A=Le.parse(await n.requestWithCredential("customer-sessions/refresh",{},C.session.refreshToken)),A.sessionId!==C.session.sessionId)throw new c("INVALID_RESPONSE","Refresh changed the logical session")}catch(M){if(!(M instanceof c)||M.status!==401)throw M}if(A??=C.run?.identity.binding?await t.createCustomerSession(w):await t.resumeGuestSession({guestToken:C.guest.token}),A.customerId!==w)throw new c("INVALID_RESPONSE","Session Customer changed");let O=A;return await s(g,M=>{if(!M||M.detached||M.sessionLease?.id!==R.id||M.run?.identity.binding?.id!==i.run?.identity.binding?.id)throw new c("CONFLICT","Process identity changed during session issuance",409,void 0,{reason:"IDENTITY_CONTEXT_CHANGED",recovery:"reload_state"});return M.session=O,delete M.sessionLease,M}),A}catch(O){throw A&&A.sessionId!==C.session?.sessionId&&await t.revokeCustomerSessions({customerId:A.customerId,sessionId:A.sessionId}).catch(()=>{}),await s(g,M=>{if(!M)throw L();return M.sessionLease?.id===R.id&&delete M.sessionLease,M}).catch(()=>{}),O}}let h;async function y(){if(h??=vt.parse(await v({contract:q,operation:"describe"})),h.scope.projectId!==e.scope.projectId||h.scope.environment!==e.scope.environment)throw L();return h}async function S(g,i,w=!1){let R=await r(g),C=await l(i);if(C.issuingKeyId!==(await y()).keyId)throw new c("INVALID_CONFIGURATION","Restore this process with its original issuing Server Key");if(!C.runToken||!C.run)throw new c("CONFLICT","Recover the original start first",425);if(C.detached){if(!w)throw new c("UNAUTHENTICATED","Explicitly restore the process after sign-in",401);if(C.run.identity.binding&&(!R||C.target&&C.target!==R.externalUserId))throw L();await p(i),C=await s(i,A=>{if(!A||A.run?.id!==C.run?.id)throw L();return delete A.detached,A})}if(!C.runToken||!C.run)throw new c("INVALID_RESPONSE","Process identity is missing");if(C.run.identity.binding){if(R&&!C.target){let A=xe.parse(await v({contract:q,operation:"binding_status",runToken:C.runToken,requestId:C.bindingIntent?.requestId??C.start.requestId,externalUserId:R.externalUserId}));if(A.state!=="bound"||A.binding.id!==C.run.identity.binding.id)throw L();C=await s(i,O=>{if(!O)throw L();return O.target=R.externalUserId,O})}if(!R||C.target!==R.externalUserId)throw L()}else if(R){if(!C.guest)throw L();C=await s(i,O=>{if(!O||O.bindingIntent&&O.bindingIntent.externalUserId!==R.externalUserId)throw L();return O.bindingIntent??={requestId:crypto.randomUUID(),externalUserId:R.externalUserId},O});let A=C.bindingIntent;try{let O=wt.parse(await v({contract:q,operation:"bind_customer",...A,runToken:C.runToken,guestToken:C.guest.token,claimRequestId:C.guest.claimRequestId,expectedBindingId:null}));C=await b(i,O,R.externalUserId)}catch(O){let M=xe.parse(await v({contract:q,operation:"binding_status",...A,runToken:C.runToken,guestToken:C.guest.token}));if(M.state!=="bound")throw O;C=await s(i,F=>{if(!F?.run||F.run.id!==M.binding.runId)throw L();return F.run.identity.binding={id:M.binding.id,customerId:M.binding.customerId,acceptedAt:M.binding.acceptedAt},F.target=R.externalUserId,F})}}return{state:C,session:await d(i,C)}}async function k(g,i,w,R){try{return await R(w)}catch(C){if(!(C instanceof c)||C.status!==401)throw C;return await s(i,A=>{if(!A||A.detached)throw C;return A.session?.accessToken===w.session.accessToken&&(A.session.expiresAt=new Date(0).toISOString()),A}),R(await S(g,i))}}async function D(g,i,w=!1){let R=await a(g),C=await S(g,R.process,w),A=ae.parse(await k(g,R.process,C,O=>v({...i,customerToken:O.session.accessToken},O.state.runToken)));return await b(R.process,A),A}return{async open(g,i){i=It.parse(i);let w=await a(g),R=await y(),C=w.guest+":"+R.keyId,A=await e.store.read(w.process);if(!A){let B=await r(g),T,_,P;if(B)T={type:"customer",customer:{type:"externalUserId",value:B.externalUserId}};else{let H=await e.store.read(C);if(H)try{P=await t.resumeGuestSession({guestToken:H.value.token}),_=H.value}catch(U){if(!(U instanceof c)||U.status!==401)throw U}let G={token:De(),claimRequestId:crypto.randomUUID()};_=await s(C,U=>_??(U&&U.token!==H?.value.token?U:G)),T={type:"guest",guestToken:_.token}}await s(w.process,H=>H??{issuingKeyId:R.keyId,start:Te.parse({...i,contract:q,requestId:crypto.randomUUID(),source:T}),..._?{guest:_}:{},...B?{target:B.externalUserId}:{},...P?{session:P}:{}}),A=await e.store.read(w.process)}let O=A.value;if(O.issuingKeyId!==R.keyId)throw new c("INVALID_CONFIGURATION","Restore the original issuing Server Key before retrying this start");if(O.start.funnelId!==i.funnelId||O.start.operation!==i.operation)throw new c("CONFLICT","This handle already owns another process",409);if(!O.runToken){if(O.start.source.type==="customer"){let P=await r(g);if(!P||P.externalUserId!==O.target)throw L()}let B=await v(O.start),T=yt.safeParse(B);if(T.success)throw new fe(T.data);let _=ae.parse(B);if(!_.runToken)throw new c("INVALID_RESPONSE","Process credential is missing");O=await b(w.process,_)}let M=await S(g,w.process,!0),F=ae.parse(await k(g,w.process,M,B=>v({contract:q,operation:"get",customerToken:B.session.accessToken},B.state.runToken)));return await b(w.process,F),{...F,runToken:O.runToken}},async syncIdentity(g){return D(g,{contract:q,operation:"get",customerToken:""},!0)},async get(g,i={}){return D(g,{...i,contract:q,operation:"get",customerToken:""})},async review(g,i){return D(g,{contract:q,operation:"review",customerToken:"",...i?{receiptId:i}:{}})},async command(g,i,w){let R=await a(g),C=await S(g,R.process),A=ae.parse(await k(g,R.process,C,O=>v({contract:q,operation:"command",command:i,identity:{bindingId:w},customerToken:O.session.accessToken},O.state.runToken)));return await b(R.process,A),A},async pageExperiments(g,i,w=[]){let R=await a(g),C=await S(g,R.process);return gt.parse(await k(g,R.process,C,A=>v({contract:q,operation:"page_experiments",release:i,usedReceiptIds:w,customerToken:A.session.accessToken},A.state.runToken)))},async detach(g){let i=await a(g);await s(i.process,w=>{if(!w)throw L();return w.session&&!w.revocations?.some(R=>R.sessionId===w.session.sessionId)&&(w.revocations??=[]).push({customerId:w.session.customerId,sessionId:w.session.sessionId}),w.detached=!0,delete w.session,delete w.sessionLease,w}),await p(i.process)},destroy(){n.dispose()}}}async function bn(e,n){V(e.apiKey,"Renewal requires your backend");let t=N(e),o=le.parse(Rt(e,await t.request("funnels",Lt.parse({...n,operation:"renew_run"}))));if(o.run.id!==n.runId)throw new c("INVALID_RESPONSE","Run renewal identity changed");return o}function nn(e){let n=At(e),t=l=>{throw new c("INVALID_RESPONSE",l)};n.nodes.size!==e.topology.nodes.length&&t("Duplicate local node identity"),n.nodes.get(e.topology.entry)?.type!=="entry"&&t("A local Funnel must start at Entry");let o=new Set(["entry","condition","feature","split","end","output"]);for(let l of n.nodes.values()){if(!o.has(l.type))throw new c("SERVER_REQUIRED","This Funnel requires authoritative server execution");if(l.type==="entry"&&l.id!==e.topology.entry&&t("Unexpected Entry node"),["entry","feature"].includes(l.type)&&!l.outputs.next&&t("Local next exit is unavailable"),l.type==="feature"){let p=l.resources.featureKey;(!p||!Object.hasOwn(e.evaluation.variables,l.writes.value)||!Object.hasOwn(n.features,p))&&t("Local Feature definition or declaration is unavailable")}if(l.type==="condition"){let p=e.conditions[l.id];(!p||!l.outputs.default||p.some((v,E)=>v.port!==`case:${E}`||!l.outputs[v.port]))&&t("Local Condition exits are unavailable")}if(l.type==="split"&&(!l.resources.experimentId||!Object.hasOwn(e.growth.experiments,l.resources.experimentId)||!l.outputs.notParticipating)&&t("Local Experiment definition or exit is unavailable"),l.type==="end"||l.type==="output"){let p=e.evaluation.terminals[l.id];if(!p)throw new c("SERVER_REQUIRED","Terminal resource delivery requires the server");Object.keys(l.outputs).length&&t("A terminal cannot have outgoing edges"),p.output?.type==="feature"&&!Object.hasOwn(n.features,p.output.featureKey)&&t("Terminal Feature definition is unavailable")}for(let p of Object.values(l.outputs))n.nodes.has(p)||t("Local target is unavailable")}let r=new Set,a=new Set;function s(l){if(a.has(l)&&t("Local graph contains a cycle"),!r.has(l)){a.add(l);for(let p of Object.values(n.nodes.get(l).outputs))s(p);a.delete(l),r.add(l)}}return s(e.topology.entry),r.size!==n.nodes.size&&t("Local graph contains unreachable nodes"),{evaluate(l){let p={},v=l.context;v.features=n.features,v.savedGroups=n.savedGroups;let E=()=>{v.attributes=it({declarations:e.evaluation.variables,attributes:l.attributes,parameters:l.parameters,answers:{},results:p,savedGroups:n.savedGroups})};E();let b=e.topology.entry,d=0;for(;;){let h=n.nodes.get(b);if(h.type==="end"||h.type==="output"){let y=e.evaluation.terminals[b],S=y.output,k=S?.type==="feature"?n.feature(S.featureKey,v):S?.type==="variable"?et({source:"variable",key:S.key,...S.path?{path:S.path}:{}},{declarations:e.evaluation.variables,answers:{},results:p,parameters:l.parameters,attributes:l.attributes,savedGroups:n.savedGroups}):S?.value??null;return ve(e.evaluation.outputSchema,k)||t("Local output does not match its declaration"),{outcome:y.outcome,value:k}}if(d++>=e.evaluation.maxTransitions)throw new c("TRANSITION_LIMIT","Local Funnel transition budget exceeded");if(h.type==="entry")b=h.outputs.next;else{let y=n.evaluate(b,v);if(h.type==="feature"){let S=h.writes.value,k=y.value??null;ve(e.evaluation.variables[S],k)||t("Local Feature value does not match its declaration"),Ze(e.evaluation.variables,{writes:h.writes},{[S]:k}),p[S]=k,E()}b=y.target}}}}}function rn(e,n,t){let o=Xe.parse(e.attributes);if(["parameters","answers","results"].some(g=>Object.hasOwn(o,g)))throw new c("INVALID_REQUEST","Flow namespaces cannot be caller attributes");let r=ue.parse(e.parameters??{}),a=u.record(u.string(),We).parse(e.stickyBucketAssignmentDocs??{});for(let[g,i]of Object.entries(a))if(g!==`${i.attributeName}||${i.attributeValue}`||!Object.hasOwn(o,i.attributeName)||Ye(o[i.attributeName])!==i.attributeValue)throw new c("INVALID_REQUEST","Sticky document identity does not match this session");let s=e.saveStickyBucketAssignmentDoc,l=e.onFeatureUsage,p=e.onExperimentViewed,v=e.onError,E=new Map,b=new Set,d={},h=Promise.resolve();function y(g){let i=h.then(()=>(t(),g()));return h=i.catch(()=>{}),i}function S(g){try{v?.(g)}catch{}}function k(g){try{let i=g();i&&typeof i.catch=="function"&&i.catch(S)}catch(i){S(i)}}async function D(){for(let[g,i]of E){if(t(),s)try{await s(structuredClone(i))}catch{throw new c("STICKY_SAVE_FAILED","Persist the pending Sticky assignment before using this evaluation")}t(),E.delete(g)}}return{evaluate(g={}){let i=g.track===!0;return y(async()=>{let w=await n();t(w);let R=new Set(b),C={...d},A=new Map,O=[],M={stickyBucketAssignmentDocs:structuredClone(a),saveStickyBucketAssignmentDoc(T){A.set(`${T.attributeName}||${T.attributeValue}`,structuredClone(T))},...i?{trackedExperiments:R,trackedFeatureUsage:C,onExperimentViewed(T,_){let P=structuredClone(T),H=structuredClone(_);p&&O.push(()=>p(structuredClone(P),structuredClone(H)))},onFeatureUsage(T,_){let P=structuredClone(_);l&&O.push(()=>l(T,structuredClone(P)))}}:{}},F=w.program.evaluate({attributes:o,parameters:r,context:M});t(w);for(let[T,_]of A)a[T]=_,E.set(T,_);await D(),t(w),i&&(b=R,d=C);for(let T of O)k(T);let B=w.configuration;return structuredClone({evaluationMode:"local",scope:B.scope,funnelId:B.funnelId,versionId:B.versionId,evaluationRevision:B.evaluationRevision,generation:B.growth.generation,...F})})},flush:()=>y(D),get stickyBucketAssignmentDocs(){return t(),structuredClone(a)}}}var An=6e4;function he(e){if(typeof window<"u")throw new c("SERVER_ONLY","Local Funnel sessions run on your backend");let n=Y.parse(e.scope),t=e.funnelId,o=e.load,r,a,s,l=0,p=b=>Date.now()>=b.expiresAt;async function v(){if(a)return a;let b=l;r=void 0;let d=(async()=>{let h=await o();if(b!==l)throw new c("IDENTITY_CHANGED","Local evaluator was reset");if(h&&typeof h=="object"&&"evaluationMode"in h&&h.evaluationMode==="remote")throw I(z,h),new c("EVALUATION_MODE","This Funnel requires remote decide");let y=I(St,h);if(b!==l)throw new c("IDENTITY_CHANGED","Local evaluator was reset");if(y.scope.projectId!==n.projectId||y.scope.environment!==n.environment||y.funnelId!==t)throw new c("SCOPE_MISMATCH","Local configuration scope changed");if(y.growth.scope.projectId!==n.projectId||y.growth.scope.environment!==n.environment||y.growth.expiresAt!==y.expiresAt)throw new c("INVALID_RESPONSE","GB configuration scope or expiry changed");let S=Math.min(Date.now()+An,y.expiresAt?Date.parse(y.expiresAt):1/0);if(Date.now()>=S)throw new c("CONFIGURATION_EXPIRED","Refresh expired local rules");let k=JSON.stringify([n.projectId,n.environment,t,y.versionId,y.evaluationRevision,y.growth.generation]),D=[y.topology,y.conditions,y.evaluation,y.growth.features,y.growth.experiments,y.growth.savedGroups];if(s?.key===k&&!Tt(s.body,D))throw new c("INVALID_RESPONSE","Immutable local configuration identity changed");return s?.key!==k&&(s={key:k,body:D,program:nn(y)}),r={key:k,configuration:y,expiresAt:S,program:s.program},r})();a=d;try{return await d}finally{a===d&&(a=void 0)}}function E(){return a??(r&&!p(r)?Promise.resolve(r):v())}return{session(b){let d=l;return rn(b,E,h=>{if(e.assertUsable?.(),d!==l)throw new c("IDENTITY_CHANGED","Local evaluator was reset");if(h&&(p(h)||r?.key!==h.key))throw new c("CONFIGURATION_EXPIRED","Refresh local rules before using this result")})},async refresh(){return structuredClone((await v()).configuration)},reset(){l++,r=void 0,a=void 0,s=void 0}}}function On(e,n){let t=e.snapshot?.generation,o=he({scope:{projectId:e.scope.projectId,environment:e.scope.environment},funnelId:n,load:()=>e.localFunnel(n),assertUsable:()=>e.assertFunnel(n)}),r=e.subscribe(()=>{let s=e.snapshot?.generation;e.fresh&&s!==t&&(t=s,o.refresh().catch(()=>{}))}),a=o.session;return Object.assign(o,{session(s){let l=a(s),p=l.evaluate;return Object.assign(l,{async evaluate(...v){return e.fresh||await e.refresh(),p(...v)}})},destroy(){r(),o.reset()}})}function Tn(e){if(typeof window<"u")throw new c("SERVER_ONLY","Secret API keys must stay on the backend");return{start:n=>xt(e,n)}}var re=class extends c{constructor(t,o){super("DECISION_PENDING","Decision is still pending; read this decision ID or retry the original request ID",202,o);this.decisionId=t;this.decisionRequestId=o}decisionId;decisionRequestId};async function ge(e,n,t,o){let{decisionId:r,requestId:a}=e,s=e,l=250,p=0;for(;;){if(s.decisionId!==r||s.requestId!==a||s.decision&&!pe(s.decision,n))throw new c("INVALID_RESPONSE","Decision request or customer changed");if(s.decision)return s.decision;if(s.status==="failed")throw new c("DECISION_FAILED","Decision execution failed",503,a);if(Date.now()>=t)throw new re(r,a);if(await new Promise(v=>setTimeout(v,Math.min(Math.max(l,p-Date.now()),t-Date.now()))),Date.now()>=t)throw new re(r,a);l=Math.min(1e3,l*2);try{s=await o(r,t)}catch(v){if(v instanceof c&&["TIMEOUT","NETWORK_ERROR","SERVICE_UNAVAILABLE","RATE_LIMITED"].includes(v.code)){p=Date.now()+(v.retryAfterSeconds??0)*1e3;continue}throw v}}}function Fe(e){if("remoteEval"in e)throw new c("INVALID_REQUEST","Configure evaluation mode on the Funnel; remoteEval is not supported");V(e.apiKey,"Funnel decisions are requested by your backend");let n,t,o=new Map;async function r(p,v){let E=p;E.status!=="pending"&&o.delete(E.decisionId);for(let b=0;b<32&&E.evaluation;b++){let d=E.evaluation;if(d.runId!==E.decisionId)throw new c("INVALID_RESPONSE","Local evaluation Run changed");let h=o.get(E.decisionId);if(!h&&d.type==="evaluate_segment"){let S=zt.parse(await a({operation:"segment_configuration",funnelId:e.funnelId,versionId:d.versionId},v));if(S.configuration.scope.projectId!==e.scope.projectId||S.configuration.scope.environment!==e.scope.environment||S.configuration.funnelId!==e.funnelId||S.configuration.versionId!==d.versionId||S.configuration.evaluationRevision!==d.policyRevision)throw new c("SCOPE_MISMATCH","Original decision segment configuration changed");if(o.size>=128)throw new c("COMMAND_PENDING","Reconcile outstanding decisions first");h={operation:"commit_decision_segment",decisionId:E.decisionId,requestId:Oe(E.decisionId,d.visit,`segment:${d.revision}`),nodeId:d.nodeId,visit:d.visit,revision:d.revision,policyRevision:d.policyRevision,generation:S.configuration.growth.generation,...Ot(S.configuration,S.document,d)},o.set(E.decisionId,h)}if(!h){if(d.type!=="evaluate")throw new c("INVALID_RESPONSE","Unknown decision instruction");if((!t||t.versionId!==d.versionId||t.evaluationRevision!==d.policyRevision||t.expiresAt&&Date.parse(t.expiresAt)<=Date.now())&&(t=z.parse(await a({operation:"configuration",funnelId:e.funnelId,versionId:d.versionId},v))),t.scope.projectId!==e.scope.projectId||t.scope.environment!==e.scope.environment||t.funnelId!==e.funnelId)throw new c("SCOPE_MISMATCH","Local evaluation configuration scope changed");if(t.evaluationMode!=="local"||t.versionId!==d.versionId||t.evaluationRevision!==d.policyRevision)throw new c("EVALUATION_MODE","Original Local evaluation policy is unavailable");if(o.size>=128)throw new c("COMMAND_PENDING","Reconcile outstanding Local decisions first");h={operation:"evaluate_decision",decisionId:E.decisionId,requestId:Oe(E.decisionId,d.visit,"evaluation"),nodeId:d.nodeId,visit:d.visit,revision:d.revision,receiptId:d.receiptId,policyRevision:d.policyRevision,generation:t.growth.generation,result:Ct(t,d.nodeId,d,bt)},o.set(E.decisionId,h)}let y=Z.parse(await a(h,v));if(y.decisionId!==p.decisionId||y.requestId!==p.requestId)throw new c("INVALID_RESPONSE","Decision identity changed during local evaluation");o.delete(E.decisionId),E=y}return E}async function a(p,v,E=!1){return N({...e,fetch:(d,h)=>{let y=new Headers(h?.headers);return y.set("Accept-Encoding","identity"),E&&y.set("Prefer","respond-async"),(e.fetch??globalThis.fetch)(d,{...h,headers:y})},timeoutMs:Math.min(e.timeoutMs??1e4,v?Math.max(1,v-Date.now()):12e4)}).request("funnels",p)}async function s(p,v){let E=Z.parse(await a(de.parse({operation:"read_decision",decisionId:p}),v));if(E.decisionId!==p)throw new c("INVALID_RESPONSE","Decision identity changed");return r(E,v)}async function l(p,v,E=!1){let b=de.options[0].parse({...p,operation:"decide",funnelId:e.funnelId}),d;try{d=Z.parse(await a(b,v,E))}catch(h){throw h instanceof c&&["TIMEOUT","NETWORK_ERROR","SERVICE_UNAVAILABLE"].includes(h.code)?new c("DECISION_ACCEPTANCE_UNKNOWN","Decision acceptance is unknown; retry the original request ID and input",h.status,p.requestId):h}if(d.requestId!==p.requestId||d.decision&&!pe(d.decision,b.customer))throw new c("INVALID_RESPONSE","Decision request or customer changed");return{response:await r(d,v),customer:b.customer}}return{local(){return n??=he({scope:e.scope,funnelId:e.funnelId,load:()=>a({operation:"local_configuration",funnelId:e.funnelId})})},async configuration(){let p=z.parse(await a({operation:"configuration",funnelId:e.funnelId}));if(p.scope.projectId!==e.scope.projectId||p.scope.environment!==e.scope.environment||p.funnelId!==e.funnelId)throw new c("SCOPE_MISMATCH","Configuration scope changed");return p},features(p={}){return Me({...p,scope:e.scope,load:async()=>at.parse(await a({operation:"feature_config",funnelId:e.funnelId}))})},read:p=>s(p),async submit(p){return(await l(p,void 0,!0)).response},async decide(p){let v=Date.now()+3e4,E=await l(p,v);return ge(E.response,E.customer,v,s)},async reportUsed(p){let v=lt.parse(await a(de.parse({...p,operation:"report_used"})));if(v.decisionId!==p.decisionId||v.eventId!==p.eventId)throw new c("INVALID_RESPONSE","Usage receipt identity changed");return v}}}function xn(e){V(e.apiKey,"Native receipts are verified by your backend","Server API key required");let n=N({...e,timeoutMs:e.timeoutMs??35e3});return{async recover(t){let o=Gt.parse(t);if(o.orderId!==o.receiptId)throw new c("INVALID_REQUEST","Native recovery requires the accepted commercial intent");let r=o.nativeEvidence,a={requestId:o.requestId,customerToken:o.customerToken,purchaseIntentId:o.orderId,...r===null?{intent:"read"}:r.provider==="apple"?{provider:"apple",signedTransaction:r.signedTransaction}:{provider:"google",purchaseToken:r.purchaseToken}},s=m.restoreNativePurchase.response.parse(await n.request(m.restoreNativePurchase.path,a));if(s.operation.requestId!==o.requestId||s.operation.purchaseIntentId!==o.orderId)throw new c("INVALID_RESPONSE","Native receipt request identity changed");let l=jt.parse({scope:s.scope,requestId:o.requestId,orderId:s.operation.orderId,receiptId:s.operation.orderId,orderStatus:s.operation.status,refunded:s.operation.refunded,...s.operation.completion===null?{}:{nativeCompletion:{orderId:s.operation.orderId,receiptId:s.operation.orderId,...s.operation.completion}}});if(l.requestId!==o.requestId||l.orderId!==o.orderId||l.receiptId!==o.receiptId||l.scope.projectId!==e.scope.projectId||l.scope.environment!==e.scope.environment)throw new c("INVALID_RESPONSE","Current order receipt scope changed");return l}}}var J=u.number().int().min(0).max(Number.MAX_SAFE_INTEGER);function _n(e,n){let t=J.parse(e.inputTokens.total),o=J.parse(e.outputTokens.total),r=J.parse(e.inputTokens.cacheRead??0),a=J.parse(e.inputTokens.cacheWrite??0),s=J.parse(e.outputTokens.reasoning??0);if(r+a>t||s>o||e.inputTokens.noCache!==void 0&&J.parse(e.inputTokens.noCache)!==t-r-a||e.outputTokens.text!==void 0&&J.parse(e.outputTokens.text)!==o-s)throw new c("AI_USAGE_UNAVAILABLE","Provider token counts do not conserve total usage");return{input:t-r-a,cache_read:r,cache_write:a,output:n==="output"?o:o-s,reasoning:n==="separate"?s:0,input_audio:0,output_audio:0}}function Mn(e){if(typeof window<"u")throw new c("SERVER_ONLY","AI usage belongs on the trusted backend");if(!e.modelId||!["output","separate"].includes(e.reasoning))throw new c("INVALID_REQUEST","Model ID and reasoning pricing are required");async function n(o){await e.persist({context:o,modelId:e.modelId,usage:null,tokens:null,quote:null,receipt:null,phase:"incomplete"})}async function t(o,r){let a={context:o,modelId:e.modelId,usage:r,tokens:null,quote:null,receipt:null,phase:"captured"};await e.persist(a);let s=e.mapTokens?e.mapTokens(r):_n(r,e.reasoning),l=await e.pricing.quoteTokens({modelId:e.modelId,tokens:s});await e.persist({...a,tokens:s,quote:l,phase:"quoted"});let p=await e.pricing.trackTokens(e.client,{...o,quote:l});if(!p.receipt.accepted)throw new c("AI_BALANCE_REJECTED","AI usage was captured but the balance operation was rejected");await e.persist({...a,tokens:s,quote:l,receipt:p,phase:"settled"})}return{specificationVersion:"v4",async wrapGenerate({doGenerate:o}){let r=await e.context(),a;try{a=await o()}catch(s){throw await n(r),s}return await t(r,a.usage),a},async wrapStream({doStream:o}){let r=await e.context(),a;try{a=await o()}catch(E){throw await n(r),E}let s=!1,l=!1,p=a.stream.getReader();async function v(){s||l||(l=!0,await n(r))}return{...a,stream:new ReadableStream({async pull(E){try{let{value:b,done:d}=await p.read();if(d){if(!s)throw await v(),new c("AI_USAGE_UNAVAILABLE","Stream ended without final usage; no amount was invented");E.close();return}if(b.type==="finish"){if(s)throw new c("AI_USAGE_UNAVAILABLE","Provider sent more than one final usage record");s=!0,await t(r,b.usage)}E.enqueue(b)}catch(b){try{await v()}finally{E.error(b),await p.cancel(b)}}},async cancel(E){try{await v()}finally{await p.cancel(E)}}})}}}}function kn(e){V(e.apiKey,"Funnel receipts are sent by your backend");let n=N(e);return{async signal(t){let o=Re.parse({...t,operation:"signal"}),r=st.parse(await n.request("funnels",o));if(r.runId!==t.runId||r.eventId!==t.eventId||r.scope.projectId!==e.scope.projectId||r.scope.environment!==e.scope.environment)throw new c("INVALID_RESPONSE","Receipt identity changed");return r},async readResults(t){let o=Re.parse({operation:"read_results",runId:t}),r=ct.parse(await n.request("funnels",o));if(r.runId!==t||r.scope.projectId!==e.scope.projectId||r.scope.environment!==e.scope.environment)throw new c("INVALID_RESPONSE","Result identity changed");return r}}}function Bn(e){if("remoteEval"in e)throw new c("INVALID_REQUEST","Configure evaluation mode on the Funnel; remoteEval is not supported");V(e.apiKey,"Campaign entry requires your backend");let n=N({...e,timeoutMs:e.timeoutMs??35e3});return{async decide(t){let o=Date.now()+(e.timeoutMs??3e4),r=Pe.parse({...t,funnelId:e.funnelId,operation:"campaign_decide"}),a=N({...e,timeoutMs:Math.min(e.timeoutMs??35e3,Math.max(1,o-Date.now()))}),s=Z.parse(await a.request("funnels",r));if(s.scope.projectId!==e.scope.projectId||s.scope.environment!==e.scope.environment)throw new c("SCOPE_MISMATCH","Campaign scope changed");return ge(s,r.customer,o,(l,p)=>Fe({...e,timeoutMs:Math.min(e.timeoutMs??1e4,Math.max(1,p-Date.now()))}).read(l))},async start(t){let o=Pe.parse({...t,funnelId:e.funnelId,operation:"campaign_start"}),r=Vt.parse(await n.request("funnels",o));if(r.scope.projectId!==e.scope.projectId||r.scope.environment!==e.scope.environment)throw new c("SCOPE_MISMATCH","Campaign scope changed");if(!("suppressed"in r)&&(r.run.source.id!==e.funnelId||!r.customerId||o.customer.type==="id"&&r.customerId!==o.customer.value))throw new c("INVALID_RESPONSE","Campaign Funnel or Customer changed");return r}}}var x=class extends Error{constructor(t,o=409,r=!1,a="fix_request"){super(t);this.code=t;this.status=o;this.retryable=r;this.recovery=a}code;status;retryable;recovery};function Pn(e){if(typeof window<"u")throw new Error("Merchant bridge credentials require a trusted server");let n=se.parse(e.manifest),t={projectId:n.projectId,environmentId:n.environmentId,environment:n.environment},o=n.capabilities.some(r=>["purchases","subscription_changes","refunds","operation_status"].includes(r));for(let[r,a]of Object.entries(Se))if(a.command&&n.capabilities.includes(r)&&!(r==="catalog"&&n.catalog==="static")&&!e.handlers[a.command])throw new Error(`Missing merchant command handler: ${a.command}`);if(o&&(!e.resolveOperationAuthority||!e.handlers["operation.read"]||!n.capabilities.includes("operation_status")))throw new Error("Merchant operations require fresh Longplay authority and an operation lookup handler");return async function(a){let s=crypto.randomUUID(),l="bridge.ping",p,v=async(E,b,d=!1)=>{let h=JSON.stringify({bridgeVersion:X,requestId:s,command:l,scope:t,[d?"error":"data"]:E});if(new TextEncoder().encode(h).byteLength>262144)throw new Error("Merchant response exceeds limit");return new Response(h,{status:b,headers:{"Content-Type":"application/json","Cache-Control":"private, no-store","X-Request-Id":s,...p?await te(h,p,"response"):{}}})};try{if(a.headers.get("X-Indiana-Merchant-Bridge-Version")!==String(X)||a.method!=="POST"||new URL(a.url).pathname!==W)throw new x("MERCHANT_BRIDGE_INVALID_REQUEST",400);if(!/^application\/json(?:\s*;|$)/i.test(a.headers.get("Content-Type")??""))throw new x("MERCHANT_BRIDGE_INVALID_REQUEST",400);let E=a.body?.getReader();if(!E)throw new x("MERCHANT_BRIDGE_INVALID_REQUEST",400);let b=new TextDecoder("utf-8",{fatal:!0}),d="",h=0;try{for(;;){let _=await E.read();if(_.done)break;if(h+=_.value.byteLength,h>16384)throw new x("MERCHANT_BRIDGE_INVALID_REQUEST",413);d+=b.decode(_.value,{stream:!0})}d+=b.decode()}finally{await E.cancel().catch(()=>{}),E.releaseLock()}let y=ot.safeParse(JSON.parse(d));if(!y.success)throw new x("MERCHANT_BRIDGE_INVALID_REQUEST",400);let S=y.data;if(s=S.requestId,l=S.command,Object.keys(t).some(_=>S.scope[_]!==t[_]))throw new x("MERCHANT_BRIDGE_SCOPE_MISMATCH",403);let k=S.command==="bridge.ping"||S.command==="bridge.describe",D=S.command==="catalog.read";if((k||D||a.headers.has(Q))&&(p=e.authentication.find(_=>_.keyId===a.headers.get(Q)),!p||!await ne(d,a.headers,p,"request")))throw p=void 0,new x("MERCHANT_BRIDGE_AUTHENTICATION_FAILED",401);if(S.command==="bridge.ping")return v(Ee["bridge.ping"].parse(S.data),200);if(S.command==="bridge.describe")return v(n,200);let g=Object.entries(Se).find(([,_])=>_.command===S.command);if(!g||!n.capabilities.includes(g[0]))throw new x("MERCHANT_BRIDGE_CAPABILITY_UNSUPPORTED",501);let i=e.handlers[S.command];if(!i)throw new x("MERCHANT_BRIDGE_CAPABILITY_UNSUPPORTED",501);if(!D&&a.headers.has("Cookie")&&(a.headers.get("Origin")!==new URL(a.url).origin||["cross-site","same-site"].includes(a.headers.get("Sec-Fetch-Site")??"")))throw new x("MERCHANT_BRIDGE_FORBIDDEN",403);let w=D?{kind:"service"}:await e.authorize(a,S),R=w.kind,C=["purchase.execute","subscription.change","refund.execute"].includes(S.command),A=C||S.command==="operation.read";if(!(A&&p!==void 0&&R==="service")&&(S.command==="refund.execute"?R!=="administrator":!D&&R!=="user"))throw new x("MERCHANT_BRIDGE_FORBIDDEN",403);if(w.kind==="user"&&["purchase.execute","operation.read","subscription.change","customer.commerce.read","presentation.report"].includes(S.command)&&!u.uuid().safeParse(w.customerId).success)throw new x("MERCHANT_BRIDGE_UNAUTHENTICATED",401);let M=i,F=Ee[S.command].parse(S.data),B={request:a,command:S.command,scope:t,principal:w},T;if(A){let _=j.parse(F);if(w.kind==="user"&&w.customerId!==_.customerId)throw new x("MERCHANT_BRIDGE_SCOPE_MISMATCH",403);if(!e.resolveOperationAuthority)throw new x("MERCHANT_BRIDGE_CAPABILITY_UNSUPPORTED",501);let P=ce.parse(await e.resolveOperationAuthority(_,B));if(P.operationId!==_.operationId||P.customerId!==_.customerId||Object.keys(t).some(G=>P.scope[G]!==t[G]))throw new x("MERCHANT_BRIDGE_SCOPE_MISMATCH",403);B.authority=P;let H=S.command==="purchase.execute"?"purchase":S.command==="subscription.change"?"subscription_change":S.command==="refund.execute"?"refund":P.instruction.type;if(P.instruction.type!==H)throw new x("MERCHANT_BRIDGE_SCOPE_MISMATCH",403);if(!C)T=we.parse(await M(F,B));else{if(P.confirmedAt===null)throw new x("MERCHANT_BRIDGE_OPERATION_NOT_CONFIRMED",409);let G=we.parse(await e.handlers["operation.read"](_,{...B,command:"operation.read"}));if(G.operationId!==_.operationId||G.customerId!==_.customerId)throw new x("MERCHANT_BRIDGE_SCOPE_MISMATCH",403);if(G.lookup==="found")T=G.execution;else{if(!P.initialExecutionAllowed)throw new x("MERCHANT_BRIDGE_RECOVERY_REQUIRED",409,!1,"recover_operation");if(Date.parse(P.instruction.expiresAt)<=Date.now())throw new x("MERCHANT_BRIDGE_OPERATION_EXPIRED",409,!1,"reload_state");if(!n.capabilities.includes("billing_records")||je(P.instruction).some(U=>!n.billingEvents.some(on=>on===U))||Ge(P.instruction).some(U=>!n.profiles.includes(U)))throw new x("MERCHANT_BRIDGE_CAPABILITY_UNSUPPORTED",501,!1,"check_availability");try{T=nt.parse(await M(F,B))}catch(U){throw U instanceof x?U:new x("MERCHANT_BRIDGE_RESULT_UNKNOWN",503,!1,"recover_operation")}}if(T.type!==H)throw new x("MERCHANT_BRIDGE_SCOPE_MISMATCH",403)}}else T=rt[S.command].parse(await M(F,B));if(w.kind==="user"){if("nativeUserId"in T&&T.nativeUserId!==w.nativeUserId)throw new x("MERCHANT_BRIDGE_SCOPE_MISMATCH",403);if("customerId"in T&&T.customerId!==w.customerId)throw new x("MERCHANT_BRIDGE_SCOPE_MISMATCH",403);if("session"in T&&w.customerId&&T.session.customerId!==w.customerId)throw new x("MERCHANT_BRIDGE_SCOPE_MISMATCH",403);if("presentation"in T&&T.presentation&&w.customerId&&T.presentation.customerId!==w.customerId)throw new x("MERCHANT_BRIDGE_SCOPE_MISMATCH",403)}if("operationId"in T&&(T.operationId!==j.parse(S.data).operationId||T.customerId!==j.parse(S.data).customerId))throw new x("MERCHANT_BRIDGE_SCOPE_MISMATCH",403);return v(T,C&&("paymentStatus"in T&&["pending","unknown"].includes(T.paymentStatus)||"status"in T&&["pending","unknown","scheduled"].includes(T.status))?202:200)}catch(E){let b=E instanceof x?E:E instanceof SyntaxError?new x("MERCHANT_BRIDGE_INVALID_REQUEST",400):new x("MERCHANT_BRIDGE_INVALID_RESPONSE",500);return v({code:b.code,message:b.code,retryable:b.retryable,recovery:b.recovery},b.status,!0)}}}function Dn(e){return async(n,t)=>{let o=()=>e.readSubscriptionOperation(n),r=()=>e.readSubscriptionUpdate(n),a=()=>e.readRefund(n),s=t.command==="purchase.execute"?[o]:t.command==="subscription.change"?[r]:t.command==="refund.execute"?[a]:[o,r,a];for(let l of s)try{let p=await l(),v="authority"in p.operation?p.operation.authority:void 0;if(!v)throw new x("MERCHANT_BRIDGE_CAPABILITY_UNSUPPORTED",501,!1,"check_availability");let E=ce.parse(v);if(E.customerId!==n.customerId||E.operationId!==n.operationId||Object.keys(t.scope).some(b=>E.scope[b]!==t.scope[b]))throw new x("MERCHANT_BRIDGE_SCOPE_MISMATCH",403);return E}catch(p){if(t.command==="operation.read"&&p instanceof c&&p.code==="NOT_FOUND")continue;throw p}throw new x("MERCHANT_BRIDGE_OPERATION_NOT_FOUND",404,!1,"reload_state")}}function Fn(e){if(typeof window<"u")throw new Error("Merchant protocol credentials require a trusted server");let n=ke.parse(e.manifest),t=ie.parse(e.authentication),o={projectId:n.projectId,environmentId:n.environmentId,environment:n.environment},r=e.now??Date.now,a=d=>{throw new c("INVALID_RESPONSE",d)},s=(d,h)=>Ie(d)===Ie(h);function l(d){new TextEncoder().encode(d).byteLength>262144&&a("Merchant protocol body exceeds limit");try{return JSON.parse(d)}catch{return a("Invalid merchant protocol JSON")}}function p(d){let h=kt.parse(d);return s(h.scope,o)||a("Merchant protocol scope mismatch"),h.command==="requirement.check"&&(n.capabilities.includes("requirement_checks")||a("Merchant Check capability unavailable"),s(h.data.subject.scope,o)||a("Merchant Check subject crosses scope")),h.command==="operation.prepare"&&(!n.capabilities.includes("preparations")||!s(h.data.request.subject.scope,o))&&a("Merchant preparation capability unavailable"),h}function v(d){if(d.command!=="operation.prepare")return;let h=d.data;return(!s(h.request.subject.scope,o)||!h.preparationAllowed||Date.parse(h.requestedAt)>r()||Date.parse(h.request.expiresAt)<=r()||!n.preparationActions.includes(h.request.action))&&a("Merchant preparation requires fresh scoped authority"),h}function E(d,h){let y=Bt(d.command).parse(h);if((y.requestId!==d.requestId||!s(y.scope,o))&&a("Merchant reply correlation mismatch"),"error"in y)return y;if(d.command==="bridge.ping"&&"challenge"in y.data&&y.data.challenge!==d.data.challenge&&a("Merchant ping challenge mismatch"),d.command==="bridge.describe"&&"bridgeVersion"in y.data&&!s({projectId:y.data.projectId,environmentId:y.data.environmentId,environment:y.data.environment},o)&&a("Merchant declaration crosses scope"),d.command==="requirement.check"&&"observation"in y.data&&(!s(y.data.observation.subject,d.data.subject)||!Je(d.data.requirement,y.data)||!n.checkKinds.includes(y.data.kind))&&a("Merchant Check changed the original requirement or subject"),d.command==="operation.prepare"&&"quoteTermsDigest"in y.data){let S=v(d);(!s(y.data.request,S.request)||Date.parse(y.data.expiresAt)<=r()||Date.parse(y.data.observedAt)<Date.parse(S.requestedAt)||Date.parse(y.data.observedAt)>r())&&a("Merchant quote changed its authorized request or validity")}return y}let b=async d=>{let h=JSON.stringify(d);return l(h),{body:h,headers:new Headers({"Content-Type":"application/json","Cache-Control":"private, no-store",[oe]:"4",...await te(h,t,"response",r(),4)})}};return{version:4,path:W,async encodeRequest(d,h){let y=p({bridgeVersion:4,requestId:crypto.randomUUID(),scope:o,command:d,data:h});v(y);let S=JSON.stringify(y);l(S);let k=new Headers({"Content-Type":"application/json",[oe]:"4",...await te(S,t,"request",r(),4)});return{body:S,headers:k,async readResponse(D,g){l(D),(g.get(oe)!=="4"||!await ne(D,g,t,"response",r(),4))&&a("Merchant response authentication failed");let i=E(y,l(D));if("error"in i)throw new ye(i.error);return i.data}}},async decodeRequest(d,h){l(d),(h.get(oe)!=="4"||h.get(Q)!==t.keyId||!await ne(d,h,t,"request",r(),4))&&a("Merchant request authentication failed");let y=p(l(d));return v(y),y},async encodeResponse(d,h){let y=p(d),S=E(y,{...y,data:h});return b(S)},async encodeError(d,h){let y=p(d),{data:S,...k}=y;return b(E(y,{...k,error:Be.parse(h)}))}}}var ye=class extends Error{constructor(t){super(t.message);this.problem=t}problem};export{re as FunnelDecisionTimeoutError,fe as FunnelProcessEntrySuppressedError,c as LongplayError,x as MerchantBridgeHandlerError,ye as MerchantBridgeProtocolError,fn as aiPriceSnapshotSchema,hn as aiTokenQuoteSchema,gn as createAiPricing,Mn as createAiUsageMiddleware,dn as createConfigurationSync,yn as createConfiguredAiPricing,Me as createFeatureClient,Bn as createFunnelCampaignClient,Fe as createFunnelDecisionClient,he as createFunnelLocalEvaluator,kn as createFunnelOrchestrationClient,Rn as createFunnelProcessAdapter,ln as createFunnelStartClient,De as createGuestToken,mn as createLocalFunnelClient,Cn as createLongplayServer,Dn as createMerchantBridgeAuthorityResolver,Pn as createMerchantBridgeHandler,Fn as createMerchantBridgeProtocol,xn as createNativeReceiptClient,Tn as createPaywallStartClient,On as createSynchronizedFunnelLocalEvaluator,un as entitlementRequirementDigest,pn as evaluateFunnelNode,cn as merchantConfirmationMatchesTerms,an as merchantPreparationRequestDigest,sn as merchantQuoteTermsDigest,bn as renewFunnelRun,te as signMerchantBridgeMessage,ne as verifyMerchantBridgeMessage};
|
|
6
|
+
${e}`)}async function Nt(e){let n=ie.parse(e);return crypto.subtle.importKey("raw",Dt(n.signingSecret),{name:"HMAC",hash:"SHA-256"},!1,["sign","verify"])}async function te(e,n,t,o=Date.now(),r=X){let a=String(Math.floor(o/1e3)),s=new Uint8Array(await crypto.subtle.sign("HMAC",await Nt(n),Ft(e,t,a,r))),l=btoa(String.fromCharCode(...s)).replaceAll("+","-").replaceAll("/","_").replace(/=+$/,"");return{[Q]:n.keyId,[Pt]:`t=${a},v1=${l}`}}async function ne(e,n,t,o,r=Date.now(),a=X){try{if(n.get(Q)!==t.keyId)return!1;let s=/^t=([0-9]{1,12}),v1=([A-Za-z0-9_-]{43})$/.exec(n.get(Pt)??"");return!s||Math.abs(r/1e3-Number(s[1]))>300?!1:await crypto.subtle.verify("HMAC",await Nt(t),Dt(s[2]),Ft(e,o,s[1],a))}catch{return!1}}var Lt=u.strictObject({operation:u.literal("renew_run"),runId:u.uuid(),customerId:u.uuid()}),le=ft.refine(e=>!!e.runToken,"Renewal returns a credential"),Ut=ht.refine(e=>!!e.runToken,"Renewal returns a credential");var Pe=u.discriminatedUnion("operation",[u.strictObject({operation:u.literal("campaign_decide"),...pt}).refine(be,Ae),u.strictObject({operation:u.literal("campaign_start"),funnelId:u.uuid(),requestId:u.uuid(),customer:ut,customerData:dt.optional(),locale:u.string().min(1).max(35),parameters:ue,cooldownSeconds:u.number().int().min(1).max(2592e3)}).refine(be,Ae)]),Sn=u.union([u.strictObject({scope:Y,suppressed:u.literal(!0),reason:u.enum(["frequency","in_progress"]),retryAt:u.iso.datetime({offset:!0})}),le]),Vt=u.union([Sn.options[0],Ut]);var qt=u.discriminatedUnion("provider",[u.strictObject({provider:u.literal("apple"),orderId:u.uuid(),receiptId:u.uuid(),signedTransaction:u.string().min(1).max(131072)}),u.strictObject({provider:u.literal("google"),orderId:u.uuid(),receiptId:u.uuid(),purchaseToken:u.string().min(1).max(16384)})]),Ht=u.strictObject({orderId:u.uuid(),receiptId:u.uuid(),transactionIds:u.array(u.string().min(1).max(255)).min(1).max(50),membership:u.boolean()});var Gt=u.strictObject({operation:u.literal("native_receipt"),requestId:u.uuid(),customerToken:u.string().regex(Ne),orderId:u.uuid(),receiptId:u.uuid(),nativeEvidence:qt.nullable()}).refine(e=>e.nativeEvidence===null||e.nativeEvidence.orderId===e.orderId&&e.nativeEvidence.receiptId===e.receiptId,"Evidence must use this current order receipt"),jt=u.strictObject({scope:Y,requestId:u.uuid(),orderId:u.uuid(),receiptId:u.uuid(),orderStatus:u.enum(["created","pending","trialing","paid","cancelled","failed"]),refunded:u.boolean(),nativeCompletion:Ht.optional()});var zt=u.strictObject({document:mt,configuration:z.options[0]});function me(e){return{async getCustomer(n){let t=m.getCustomer;return h(e,t,n,{request:"Invalid customer lookup",response:"Invalid customer response"})},async listCustomers(n={}){let t=m.listCustomers;return h(e,t,n,{request:"Invalid customer filters",response:"Invalid customer response"})},async updateCustomer(n){let t=m.updateCustomer;return h(e,t,n,{request:"Invalid customer patch",response:"Invalid customer response"})},async createGuestCustomer(n){let t=m.createGuestCustomer;return h(e,t,n)},async resumeGuestSession(n){let t=m.resumeGuestSession;return h(e,t,n)},async claimGuestCustomer(n){let t=m.claimGuestCustomer;return h(e,t,n)},async revokeCustomerSessions(n){let t=m.revokeSessions;return h(e,t,n)},async createCustomerSession(n){return h(e,m.createSession,{customerId:n},{request:"A customer ID is required",response:"Invalid customer session response"})},async getOrCreateCustomer(n){return h(e,m.createCustomer,n,{request:"Invalid customer input",response:"Invalid customer response"})}}}function Kt(e){return{async checkEntitlement(n){let t=m.checkEntitlement,o=t.request.parse(n),r=await h(e,t,o,I);return Et(o.requirement,r.check,o.customerId,r.scope),r},async readHoldings(n){let t=m.readHoldings;return h(e,t,n,I)},async readSeats(n){let t=m.readSeats;return h(e,t,n,I)},async manageSeat(n){let t=m.manageSeat;return h(e,t,n,I)}}}function $t(e){return{async readAiPricing(n){let t=m.readAiPricing;return h(e,t,n,I)},async readUsage(n){let t=m.readUsage;return h(e,t,n,I)},async setUsage(n){let t=m.setUsage;return h(e,t,n,I)},async manageBalanceGrant(n){let t=m.manageBalanceGrant;return h(e,t,n,I)},async readBalanceSource(n){let t=m.readBalanceSource;return h(e,t,n,I)},async adjustBalance(n){let t=m.adjustBalance;return h(e,t,n,I)},async listBalanceGrants(n){let t=m.listBalanceGrants;return h(e,t,n,I)},async manageBillingLimits(n){let t=m.manageBillingLimits;return h(e,t,n,I)},async manageUsageEntity(n){let t=m.manageUsageEntity;return h(e,t,n,I)},async readUsageAnalytics(n){let t=m.readUsageAnalytics;return h(e,t,n,I)},async readCreditAnalytics(n){let t=m.readCreditAnalytics;return h(e,t,n,I)},async submitUsageBatch(n){let t=m.submitUsageBatch;return h(e,t,n,I)},async readUsageBatch(n){let t=m.readUsageBatch;return h(e,t,n,I)},async readLedger(n){let t=m.readLedger;return h(e,t,n,I)},async readCreditStatement(n){let t=m.readCreditStatement;return h(e,t,n,I)},async quoteBalance(n){let t=m.quoteBalance;return h(e,t,n,I)},async trackUsage(n){let t=m.trackUsage;return h(e,t,n,I)},async mutateBalance(n){let t=m.mutateBalance;return h(e,t,n,I)}}}function Qt(e){return{async listInvoiceTemplates(n={}){let t=m.listInvoiceTemplates;return h(e,t,n,I)},async previewInvoice(n){let t=m.previewInvoice;return h(e,t,n,I)},async createInvoice(n){let t=m.createInvoice;return h(e,t,n,I)},async prepareBillingAdjustment(n){let t=m.prepareBillingAdjustment;return h(e,t,n,I)},async manageInvoice(n){let t=m.manageInvoice;return h(e,t,n,I)},async readInvoiceOperation(n){let t=m.readInvoiceOperation;return h(e,t,n,I)},async listInvoices(n){let t=m.listInvoices;return h(e,t,n,I)},async getInvoice(n){let t=m.getInvoice;return h(e,t,n,I)},async setupPayment(n){let t=m.setupPayment;return h(e,t,n,I)},async readPaymentSetup(n){let t=m.readPaymentSetup;return h(e,t,n,I)},async readBillingInvoice(n){let t=m.readBillingInvoice;return h(e,t,n,I)},async previewRefund(n){let t=m.previewRefund;return h(e,t,n,I)},async refund(n){let t=m.refund;return h(e,t,n,I)},async readRefund(n){let t=m.readRefund;return h(e,t,n,I)}}}function Jt(e){return{async previewSubscriptionBatch(n){let t=m.previewSubscriptionBatch;return h(e,t,n,I)},async confirmSubscriptionBatch(n){let t=m.confirmSubscriptionBatch;return h(e,t,n,I)},async readSubscriptionBatch(n){let t=m.readSubscriptionBatch;return h(e,t,n,I)},async abandonSubscriptionBatch(n){let t=m.abandonSubscriptionBatch;return h(e,t,n,I)},async manageSubscriptionTrial(n){let t=m.manageSubscriptionTrial;return h(e,t,n,I)},async readSubscriptionTrial(n){let t=m.readSubscriptionTrial;return h(e,t,n,I)},async listSubscriptions(n){let t=m.listSubscriptions;return h(e,t,n,I)},async listPurchases(n){let t=m.listPurchases;return h(e,t,n,I)},async listSubscriptionConflicts(n){let t=m.listSubscriptionConflicts;return h(e,t,n,I)},async retrySubscriptionConflict(n){let t=m.retrySubscriptionConflict;return h(e,t,n,I)},async previewUpdate(n){let t=m.previewUpdate;return h(e,t,n,I)},async update(n){let t=m.update;return h(e,t,n,I)},async readSubscriptionUpdate(n){let t=m.readSubscriptionUpdate;return h(e,t,n,I)},async restoreNativePurchase(n){let t=m.restoreNativePurchase;return h(e,t,n,I)},async verifySubscriptions(n){let t=m.verifySubscriptions;return h(e,t,n,I)},async previewAttach(n){let t=m.previewAttach;return h(e,t,n,I)},async recordMerchantEvent(n){return h(e,m.recordMerchantEvent,n,{request:"Invalid merchant event",parseResponse:I})},async attach(n){let t=m.attach;return h(e,t,n,I)},async readSubscriptionOperation(n){let t=m.readSubscriptionOperation;return h(e,t,n,I)}}}function Yt(e){return{async grantModelBenefit(n){return h(e,m.grantModelBenefit,n,{request:"Invalid model benefit grant",response:"Invalid model benefit response"})},async readModelBenefit(n){return h(e,m.readModelBenefit,n,{request:"Invalid model benefit operation",response:"Invalid model benefit response"})},async grantOffer(n){let t=m.grantOffer;return h(e,{...t,request:t.request.refine(o=>!!o.customerId)},{...n,requestId:n.requestId??crypto.randomUUID()},{request:"Invalid offer grant",response:"Invalid offer response"})}}}function Xt(e){return{...Kt(e),...$t(e),...Qt(e),...Jt(e),...Yt(e)}}function Wt(e){return{async getFeatures(n={}){let t=m.getFeatures;return h(e,t,n,I)},async evaluateFeatures(n){let t=m.evaluateFeatures;return h(e,t,n,I)}}}function Zt(e){return{async trackEvents(n){let t=m.trackEvents;return h(e,t,n,I)}}}function en(e){return{async resolveContent(n){let t=m.resolveContent;return h(e,t,n,I)},async resolvePaywall(n){let t=m.resolvePaywall,o=t.request.parse(n),r=await h(e,t,o,I);return _e(o,r.paywall.check,r.scope),r},async resolveOffering(n){let t=m.resolveOffering,o=t.request.parse(n),r=await h(e,t,o,I);return _e(o,r.check,r.scope),r}}}function Cn(e){V(e.apiKey,"Secret API keys must stay on your backend");let t=N(e).request;return{async sendMessage(o){let r=m.sendMessage;return r.response.parse(await t(r.path,r.request.parse(o)))},async readMessage(o){let r=m.readMessage;return r.response.parse(await t(r.path,r.request.parse(o)))},...me(t),...Xt(t),...Wt(t),...Zt(t),...en(t)}}function De(){if(typeof window<"u")throw new c("SERVER_ONLY","Guest identity is issued by your backend");let e=crypto.getRandomValues(new Uint8Array(32));return"gg_gc_"+btoa(String.fromCharCode(...e)).replaceAll("+","-").replaceAll("/","_").replaceAll("=","")}var tn=()=>new c("CONFLICT","Process synchronization is in progress",425),L=()=>new c("CONFLICT","This process belongs to a different account",409,void 0,{reason:"CUSTOMER_BINDING_CONFLICT"}),En=(e,n)=>JSON.stringify(e)===JSON.stringify(n),fe=class extends c{constructor(t){super("CONFLICT","Funnel entry is suppressed",409,void 0,{reason:t.reason==="in_progress"?"OPERATION_IN_PROGRESS":"STATE_CHANGED",recovery:"check_availability"});this.result=t}result};function Rn(e){if(V(e.apiKey,"Funnel process identity belongs to your backend"),e.session)throw new c("INVALID_CONFIGURATION","The process adapter owns its credential lifecycle");let n=N(e),t=me(n.request),o=`longplay:process:${e.scope.projectId}:${e.scope.environment}:`;async function r(g){let i=await e.resolveUser(g);if(i!==null&&(typeof i?.externalUserId!="string"||!i.externalUserId||i.externalUserId!==i.externalUserId.trim()||i.externalUserId.startsWith("gg_guest_")))throw new c("INVALID_RESPONSE","The merchant identity resolver returned an invalid subject");return i}async function a(g){let i=await e.resolveContext(g);if(i?.confirmed!==!0||!i.processKey||!i.guestKey)throw new c("INVALID_CONFIGURATION","A confirmed durable process handle is required");return{process:o+"run:"+i.processKey,guest:o+"guest:"+i.guestKey}}async function s(g,i){for(let w=0;w<8;w++){let R=await e.store.read(g),C=i(R?structuredClone(R.value):null);if(R&&En(R.value,C)||await e.store.compareAndSwap(g,R?.revision??null,C))return C}throw tn()}async function l(g){let i=await e.store.read(g);if(!i)throw new c("NOT_FOUND","Open the process before continuing",404);return i.value}async function p(g){let i=await l(g);for(let w of i.revocations??[])await t.revokeCustomerSessions(w),await s(g,R=>{if(!R)throw L();return R.revocations=R.revocations?.filter(C=>C.sessionId!==w.sessionId),R})}async function v(g,i){let w=Te.parse(g);return i?n.requestWithCredential("funnel-processes",w,i):n.request("funnel-processes",w)}function E(g,i){if(i.scope.projectId!==e.scope.projectId||i.scope.environment!==e.scope.environment||g.run&&(g.run.id!==i.run.id||g.run.source.versionId!==i.run.source.versionId||g.run.source.id!==i.run.source.id||g.run.runExpiresAt!==i.run.runExpiresAt||g.run.identity.startedAs!==i.run.identity.startedAs||g.run.identity.participantId!==i.run.identity.participantId||g.run.identity.binding&&g.run.identity.binding.id!==i.run.identity.binding?.id)||g.runToken&&i.runToken&&g.runToken!==i.runToken)throw new c("INVALID_RESPONSE","Process identity or Run changed")}async function b(g,i,w){return s(g,R=>{if(!R)throw new c("NOT_FOUND","Process handle is missing",404);return E(R,i),(!R.run||i.run.revision>=R.run.revision)&&(R.run=i.run),R.runToken??=i.runToken,w!==void 0&&(R.target=w),R})}async function d(g,i){if(i.detached)throw new c("UNAUTHENTICATED","The process is detached",401);let w=i.run?.identity.binding?.customerId??i.run?.identity.participantId;if(!w)throw new c("INVALID_RESPONSE","Process participant is missing");if(i.session?.customerId===w&&Date.parse(i.session.expiresAt)>Date.now()+3e4)return i.session;let R={id:crypto.randomUUID(),until:Date.now()+(e.timeoutMs??35e3)+5e3},C=await s(g,O=>{if(!O||O.detached||O.run?.id!==i.run?.id)throw L();if(O.sessionLease&&O.sessionLease.until>Date.now())throw tn();return O.sessionLease=R,O}),A;try{if(C.session?.customerId===w&&Date.parse(C.session.refreshExpiresAt)>Date.now())try{if(A=Le.parse(await n.requestWithCredential("customer-sessions/refresh",{},C.session.refreshToken)),A.sessionId!==C.session.sessionId)throw new c("INVALID_RESPONSE","Refresh changed the logical session")}catch(M){if(!(M instanceof c)||M.status!==401)throw M}if(A??=C.run?.identity.binding?await t.createCustomerSession(w):await t.resumeGuestSession({guestToken:C.guest.token}),A.customerId!==w)throw new c("INVALID_RESPONSE","Session Customer changed");let O=A;return await s(g,M=>{if(!M||M.detached||M.sessionLease?.id!==R.id||M.run?.identity.binding?.id!==i.run?.identity.binding?.id)throw new c("CONFLICT","Process identity changed during session issuance",409,void 0,{reason:"IDENTITY_CONTEXT_CHANGED",recovery:"reload_state"});return M.session=O,delete M.sessionLease,M}),A}catch(O){throw A&&A.sessionId!==C.session?.sessionId&&await t.revokeCustomerSessions({customerId:A.customerId,sessionId:A.sessionId}).catch(()=>{}),await s(g,M=>{if(!M)throw L();return M.sessionLease?.id===R.id&&delete M.sessionLease,M}).catch(()=>{}),O}}let f;async function y(){if(f??=vt.parse(await v({contract:q,operation:"describe"})),f.scope.projectId!==e.scope.projectId||f.scope.environment!==e.scope.environment)throw L();return f}async function S(g,i,w=!1){let R=await r(g),C=await l(i);if(C.issuingKeyId!==(await y()).keyId)throw new c("INVALID_CONFIGURATION","Restore this process with its original issuing Server Key");if(!C.runToken||!C.run)throw new c("CONFLICT","Recover the original start first",425);if(C.detached){if(!w)throw new c("UNAUTHENTICATED","Explicitly restore the process after sign-in",401);if(C.run.identity.binding&&(!R||C.target&&C.target!==R.externalUserId))throw L();await p(i),C=await s(i,A=>{if(!A||A.run?.id!==C.run?.id)throw L();return delete A.detached,A})}if(!C.runToken||!C.run)throw new c("INVALID_RESPONSE","Process identity is missing");if(C.run.identity.binding){if(R&&!C.target){let A=xe.parse(await v({contract:q,operation:"binding_status",runToken:C.runToken,requestId:C.bindingIntent?.requestId??C.start.requestId,externalUserId:R.externalUserId}));if(A.state!=="bound"||A.binding.id!==C.run.identity.binding.id)throw L();C=await s(i,O=>{if(!O)throw L();return O.target=R.externalUserId,O})}if(!R||C.target!==R.externalUserId)throw L()}else if(R){if(!C.guest)throw L();C=await s(i,O=>{if(!O||O.bindingIntent&&O.bindingIntent.externalUserId!==R.externalUserId)throw L();return O.bindingIntent??={requestId:crypto.randomUUID(),externalUserId:R.externalUserId},O});let A=C.bindingIntent;try{let O=wt.parse(await v({contract:q,operation:"bind_customer",...A,runToken:C.runToken,guestToken:C.guest.token,claimRequestId:C.guest.claimRequestId,expectedBindingId:null}));C=await b(i,O,R.externalUserId)}catch(O){let M=xe.parse(await v({contract:q,operation:"binding_status",...A,runToken:C.runToken,guestToken:C.guest.token}));if(M.state!=="bound")throw O;C=await s(i,F=>{if(!F?.run||F.run.id!==M.binding.runId)throw L();return F.run.identity.binding={id:M.binding.id,customerId:M.binding.customerId,acceptedAt:M.binding.acceptedAt},F.target=R.externalUserId,F})}}return{state:C,session:await d(i,C)}}async function k(g,i,w,R){try{return await R(w)}catch(C){if(!(C instanceof c)||C.status!==401)throw C;return await s(i,A=>{if(!A||A.detached)throw C;return A.session?.accessToken===w.session.accessToken&&(A.session.expiresAt=new Date(0).toISOString()),A}),R(await S(g,i))}}async function D(g,i,w=!1){let R=await a(g),C=await S(g,R.process,w),A=ae.parse(await k(g,R.process,C,O=>v({...i,customerToken:O.session.accessToken},O.state.runToken)));return await b(R.process,A),A}return{async open(g,i){i=It.parse(i);let w=await a(g),R=await y(),C=w.guest+":"+R.keyId,A=await e.store.read(w.process);if(!A){let B=await r(g),T,_,P;if(B)T={type:"customer",customer:{type:"externalUserId",value:B.externalUserId}};else{let H=await e.store.read(C);if(H)try{P=await t.resumeGuestSession({guestToken:H.value.token}),_=H.value}catch(U){if(!(U instanceof c)||U.status!==401)throw U}let G={token:De(),claimRequestId:crypto.randomUUID()};_=await s(C,U=>_??(U&&U.token!==H?.value.token?U:G)),T={type:"guest",guestToken:_.token}}await s(w.process,H=>H??{issuingKeyId:R.keyId,start:Te.parse({...i,contract:q,requestId:crypto.randomUUID(),source:T}),..._?{guest:_}:{},...B?{target:B.externalUserId}:{},...P?{session:P}:{}}),A=await e.store.read(w.process)}let O=A.value;if(O.issuingKeyId!==R.keyId)throw new c("INVALID_CONFIGURATION","Restore the original issuing Server Key before retrying this start");if(O.start.funnelId!==i.funnelId||O.start.operation!==i.operation)throw new c("CONFLICT","This handle already owns another process",409);if(!O.runToken){if(O.start.source.type==="customer"){let P=await r(g);if(!P||P.externalUserId!==O.target)throw L()}let B=await v(O.start),T=yt.safeParse(B);if(T.success)throw new fe(T.data);let _=ae.parse(B);if(!_.runToken)throw new c("INVALID_RESPONSE","Process credential is missing");O=await b(w.process,_)}let M=await S(g,w.process,!0),F=ae.parse(await k(g,w.process,M,B=>v({contract:q,operation:"get",customerToken:B.session.accessToken},B.state.runToken)));return await b(w.process,F),{...F,runToken:O.runToken}},async syncIdentity(g){return D(g,{contract:q,operation:"get",customerToken:""},!0)},async get(g,i={}){return D(g,{...i,contract:q,operation:"get",customerToken:""})},async review(g,i){return D(g,{contract:q,operation:"review",customerToken:"",...i?{receiptId:i}:{}})},async command(g,i,w){let R=await a(g),C=await S(g,R.process),A=ae.parse(await k(g,R.process,C,O=>v({contract:q,operation:"command",command:i,identity:{bindingId:w},customerToken:O.session.accessToken},O.state.runToken)));return await b(R.process,A),A},async pageExperiments(g,i,w=[]){let R=await a(g),C=await S(g,R.process);return gt.parse(await k(g,R.process,C,A=>v({contract:q,operation:"page_experiments",release:i,usedReceiptIds:w,customerToken:A.session.accessToken},A.state.runToken)))},async detach(g){let i=await a(g);await s(i.process,w=>{if(!w)throw L();return w.session&&!w.revocations?.some(R=>R.sessionId===w.session.sessionId)&&(w.revocations??=[]).push({customerId:w.session.customerId,sessionId:w.session.sessionId}),w.detached=!0,delete w.session,delete w.sessionLease,w}),await p(i.process)},destroy(){n.dispose()}}}async function bn(e,n){V(e.apiKey,"Renewal requires your backend");let t=N(e),o=le.parse(Rt(e,await t.request("funnels",Lt.parse({...n,operation:"renew_run"}))));if(o.run.id!==n.runId)throw new c("INVALID_RESPONSE","Run renewal identity changed");return o}function nn(e){let n=At(e),t=l=>{throw new c("INVALID_RESPONSE",l)};n.nodes.size!==e.topology.nodes.length&&t("Duplicate local node identity"),n.nodes.get(e.topology.entry)?.type!=="entry"&&t("A local Funnel must start at Entry");let o=new Set(["entry","condition","feature","split","end","output"]);for(let l of n.nodes.values()){if(!o.has(l.type))throw new c("SERVER_REQUIRED","This Funnel requires authoritative server execution");if(l.type==="entry"&&l.id!==e.topology.entry&&t("Unexpected Entry node"),["entry","feature"].includes(l.type)&&!l.outputs.next&&t("Local next exit is unavailable"),l.type==="feature"){let p=l.resources.featureKey;(!p||!Object.hasOwn(e.evaluation.variables,l.writes.value)||!Object.hasOwn(n.features,p))&&t("Local Feature definition or declaration is unavailable")}if(l.type==="condition"){let p=e.conditions[l.id];(!p||!l.outputs.default||p.some((v,E)=>v.port!==`case:${E}`||!l.outputs[v.port]))&&t("Local Condition exits are unavailable")}if(l.type==="split"&&(!l.resources.experimentId||!Object.hasOwn(e.growth.experiments,l.resources.experimentId)||!l.outputs.notParticipating)&&t("Local Experiment definition or exit is unavailable"),l.type==="end"||l.type==="output"){let p=e.evaluation.terminals[l.id];if(!p)throw new c("SERVER_REQUIRED","Terminal resource delivery requires the server");Object.keys(l.outputs).length&&t("A terminal cannot have outgoing edges"),p.output?.type==="feature"&&!Object.hasOwn(n.features,p.output.featureKey)&&t("Terminal Feature definition is unavailable")}for(let p of Object.values(l.outputs))n.nodes.has(p)||t("Local target is unavailable")}let r=new Set,a=new Set;function s(l){if(a.has(l)&&t("Local graph contains a cycle"),!r.has(l)){a.add(l);for(let p of Object.values(n.nodes.get(l).outputs))s(p);a.delete(l),r.add(l)}}return s(e.topology.entry),r.size!==n.nodes.size&&t("Local graph contains unreachable nodes"),{evaluate(l){let p={},v=l.context;v.features=n.features,v.savedGroups=n.savedGroups;let E=()=>{v.attributes=it({declarations:e.evaluation.variables,attributes:l.attributes,parameters:l.parameters,answers:{},results:p,savedGroups:n.savedGroups})};E();let b=e.topology.entry,d=0;for(;;){let f=n.nodes.get(b);if(f.type==="end"||f.type==="output"){let y=e.evaluation.terminals[b],S=y.output,k=S?.type==="feature"?n.feature(S.featureKey,v):S?.type==="variable"?et({source:"variable",key:S.key,...S.path?{path:S.path}:{}},{declarations:e.evaluation.variables,answers:{},results:p,parameters:l.parameters,attributes:l.attributes,savedGroups:n.savedGroups}):S?.value??null;return ve(e.evaluation.outputSchema,k)||t("Local output does not match its declaration"),{outcome:y.outcome,value:k}}if(d++>=e.evaluation.maxTransitions)throw new c("TRANSITION_LIMIT","Local Funnel transition budget exceeded");if(f.type==="entry")b=f.outputs.next;else{let y=n.evaluate(b,v);if(f.type==="feature"){let S=f.writes.value,k=y.value??null;ve(e.evaluation.variables[S],k)||t("Local Feature value does not match its declaration"),Ze(e.evaluation.variables,{writes:f.writes},{[S]:k}),p[S]=k,E()}b=y.target}}}}}function rn(e,n,t){let o=Xe.parse(e.attributes);if(["parameters","answers","results"].some(g=>Object.hasOwn(o,g)))throw new c("INVALID_REQUEST","Flow namespaces cannot be caller attributes");let r=ue.parse(e.parameters??{}),a=u.record(u.string(),We).parse(e.stickyBucketAssignmentDocs??{});for(let[g,i]of Object.entries(a))if(g!==`${i.attributeName}||${i.attributeValue}`||!Object.hasOwn(o,i.attributeName)||Ye(o[i.attributeName])!==i.attributeValue)throw new c("INVALID_REQUEST","Sticky document identity does not match this session");let s=e.saveStickyBucketAssignmentDoc,l=e.onFeatureUsage,p=e.onExperimentViewed,v=e.onError,E=new Map,b=new Set,d={},f=Promise.resolve();function y(g){let i=f.then(()=>(t(),g()));return f=i.catch(()=>{}),i}function S(g){try{v?.(g)}catch{}}function k(g){try{let i=g();i&&typeof i.catch=="function"&&i.catch(S)}catch(i){S(i)}}async function D(){for(let[g,i]of E){if(t(),s)try{await s(structuredClone(i))}catch{throw new c("STICKY_SAVE_FAILED","Persist the pending Sticky assignment before using this evaluation")}t(),E.delete(g)}}return{evaluate(g={}){let i=g.track===!0;return y(async()=>{let w=await n();t(w);let R=new Set(b),C={...d},A=new Map,O=[],M={stickyBucketAssignmentDocs:structuredClone(a),saveStickyBucketAssignmentDoc(T){A.set(`${T.attributeName}||${T.attributeValue}`,structuredClone(T))},...i?{trackedExperiments:R,trackedFeatureUsage:C,onExperimentViewed(T,_){let P=structuredClone(T),H=structuredClone(_);p&&O.push(()=>p(structuredClone(P),structuredClone(H)))},onFeatureUsage(T,_){let P=structuredClone(_);l&&O.push(()=>l(T,structuredClone(P)))}}:{}},F=w.program.evaluate({attributes:o,parameters:r,context:M});t(w);for(let[T,_]of A)a[T]=_,E.set(T,_);await D(),t(w),i&&(b=R,d=C);for(let T of O)k(T);let B=w.configuration;return structuredClone({evaluationMode:"local",scope:B.scope,funnelId:B.funnelId,versionId:B.versionId,evaluationRevision:B.evaluationRevision,generation:B.growth.generation,...F})})},flush:()=>y(D),get stickyBucketAssignmentDocs(){return t(),structuredClone(a)}}}var An=6e4;function he(e){if(typeof window<"u")throw new c("SERVER_ONLY","Local Funnel sessions run on your backend");let n=Y.parse(e.scope),t=e.funnelId,o=e.load,r,a,s,l=0,p=b=>Date.now()>=b.expiresAt;async function v(){if(a)return a;let b=l;r=void 0;let d=(async()=>{let f=await o();if(b!==l)throw new c("IDENTITY_CHANGED","Local evaluator was reset");if(f&&typeof f=="object"&&"evaluationMode"in f&&f.evaluationMode==="remote")throw I(z,f),new c("EVALUATION_MODE","This Funnel requires remote decide");let y=I(St,f);if(b!==l)throw new c("IDENTITY_CHANGED","Local evaluator was reset");if(y.scope.projectId!==n.projectId||y.scope.environment!==n.environment||y.funnelId!==t)throw new c("SCOPE_MISMATCH","Local configuration scope changed");if(y.growth.scope.projectId!==n.projectId||y.growth.scope.environment!==n.environment||y.growth.expiresAt!==y.expiresAt)throw new c("INVALID_RESPONSE","GB configuration scope or expiry changed");let S=Math.min(Date.now()+An,y.expiresAt?Date.parse(y.expiresAt):1/0);if(Date.now()>=S)throw new c("CONFIGURATION_EXPIRED","Refresh expired local rules");let k=JSON.stringify([n.projectId,n.environment,t,y.versionId,y.evaluationRevision,y.growth.generation]),D=[y.topology,y.conditions,y.evaluation,y.growth.features,y.growth.experiments,y.growth.savedGroups];if(s?.key===k&&!Tt(s.body,D))throw new c("INVALID_RESPONSE","Immutable local configuration identity changed");return s?.key!==k&&(s={key:k,body:D,program:nn(y)}),r={key:k,configuration:y,expiresAt:S,program:s.program},r})();a=d;try{return await d}finally{a===d&&(a=void 0)}}function E(){return a??(r&&!p(r)?Promise.resolve(r):v())}return{session(b){let d=l;return rn(b,E,f=>{if(e.assertUsable?.(),d!==l)throw new c("IDENTITY_CHANGED","Local evaluator was reset");if(f&&(p(f)||r?.key!==f.key))throw new c("CONFIGURATION_EXPIRED","Refresh local rules before using this result")})},async refresh(){return structuredClone((await v()).configuration)},reset(){l++,r=void 0,a=void 0,s=void 0}}}function On(e,n){let t=e.snapshot?.generation,o=he({scope:{projectId:e.scope.projectId,environment:e.scope.environment},funnelId:n,load:()=>e.localFunnel(n),assertUsable:()=>e.assertFunnel(n)}),r=e.subscribe(()=>{let s=e.snapshot?.generation;e.fresh&&s!==t&&(t=s,o.refresh().catch(()=>{}))}),a=o.session;return Object.assign(o,{session(s){let l=a(s),p=l.evaluate;return Object.assign(l,{async evaluate(...v){return e.fresh||await e.refresh(),p(...v)}})},destroy(){r(),o.reset()}})}function Tn(e){if(typeof window<"u")throw new c("SERVER_ONLY","Secret API keys must stay on the backend");return{start:n=>xt(e,n)}}var re=class extends c{constructor(t,o){super("DECISION_PENDING","Decision is still pending; read this decision ID or retry the original request ID",202,o);this.decisionId=t;this.decisionRequestId=o}decisionId;decisionRequestId};async function ge(e,n,t,o){let{decisionId:r,requestId:a}=e,s=e,l=250,p=0;for(;;){if(s.decisionId!==r||s.requestId!==a||s.decision&&!pe(s.decision,n))throw new c("INVALID_RESPONSE","Decision request or customer changed");if(s.decision)return s.decision;if(s.status==="failed")throw new c("DECISION_FAILED","Decision execution failed",503,a);if(Date.now()>=t)throw new re(r,a);if(await new Promise(v=>setTimeout(v,Math.min(Math.max(l,p-Date.now()),t-Date.now()))),Date.now()>=t)throw new re(r,a);l=Math.min(1e3,l*2);try{s=await o(r,t)}catch(v){if(v instanceof c&&["TIMEOUT","NETWORK_ERROR","SERVICE_UNAVAILABLE","RATE_LIMITED"].includes(v.code)){p=Date.now()+(v.retryAfterSeconds??0)*1e3;continue}throw v}}}function Fe(e){if("remoteEval"in e)throw new c("INVALID_REQUEST","Configure evaluation mode on the Funnel; remoteEval is not supported");V(e.apiKey,"Funnel decisions are requested by your backend");let n,t,o=new Map;async function r(p,v){let E=p;E.status!=="pending"&&o.delete(E.decisionId);for(let b=0;b<32&&E.evaluation;b++){let d=E.evaluation;if(d.runId!==E.decisionId)throw new c("INVALID_RESPONSE","Local evaluation Run changed");let f=o.get(E.decisionId);if(!f&&d.type==="evaluate_segment"){let S=zt.parse(await a({operation:"segment_configuration",funnelId:e.funnelId,versionId:d.versionId},v));if(S.configuration.scope.projectId!==e.scope.projectId||S.configuration.scope.environment!==e.scope.environment||S.configuration.funnelId!==e.funnelId||S.configuration.versionId!==d.versionId||S.configuration.evaluationRevision!==d.policyRevision)throw new c("SCOPE_MISMATCH","Original decision segment configuration changed");if(o.size>=128)throw new c("COMMAND_PENDING","Reconcile outstanding decisions first");f={operation:"commit_decision_segment",decisionId:E.decisionId,requestId:Oe(E.decisionId,d.visit,`segment:${d.revision}`),nodeId:d.nodeId,visit:d.visit,revision:d.revision,policyRevision:d.policyRevision,generation:S.configuration.growth.generation,...Ot(S.configuration,S.document,d)},o.set(E.decisionId,f)}if(!f){if(d.type!=="evaluate")throw new c("INVALID_RESPONSE","Unknown decision instruction");if((!t||t.versionId!==d.versionId||t.evaluationRevision!==d.policyRevision||t.expiresAt&&Date.parse(t.expiresAt)<=Date.now())&&(t=z.parse(await a({operation:"configuration",funnelId:e.funnelId,versionId:d.versionId},v))),t.scope.projectId!==e.scope.projectId||t.scope.environment!==e.scope.environment||t.funnelId!==e.funnelId)throw new c("SCOPE_MISMATCH","Local evaluation configuration scope changed");if(t.evaluationMode!=="local"||t.versionId!==d.versionId||t.evaluationRevision!==d.policyRevision)throw new c("EVALUATION_MODE","Original Local evaluation policy is unavailable");if(o.size>=128)throw new c("COMMAND_PENDING","Reconcile outstanding Local decisions first");f={operation:"evaluate_decision",decisionId:E.decisionId,requestId:Oe(E.decisionId,d.visit,"evaluation"),nodeId:d.nodeId,visit:d.visit,revision:d.revision,receiptId:d.receiptId,policyRevision:d.policyRevision,generation:t.growth.generation,result:Ct(t,d.nodeId,d,bt)},o.set(E.decisionId,f)}let y=Z.parse(await a(f,v));if(y.decisionId!==p.decisionId||y.requestId!==p.requestId)throw new c("INVALID_RESPONSE","Decision identity changed during local evaluation");o.delete(E.decisionId),E=y}return E}async function a(p,v,E=!1){return N({...e,fetch:(d,f)=>{let y=new Headers(f?.headers);return y.set("Accept-Encoding","identity"),E&&y.set("Prefer","respond-async"),(e.fetch??globalThis.fetch)(d,{...f,headers:y})},timeoutMs:Math.min(e.timeoutMs??1e4,v?Math.max(1,v-Date.now()):12e4)}).request("funnels",p)}async function s(p,v){let E=Z.parse(await a(de.parse({operation:"read_decision",decisionId:p}),v));if(E.decisionId!==p)throw new c("INVALID_RESPONSE","Decision identity changed");return r(E,v)}async function l(p,v,E=!1){let b=de.options[0].parse({...p,operation:"decide",funnelId:e.funnelId}),d;try{d=Z.parse(await a(b,v,E))}catch(f){throw f instanceof c&&["TIMEOUT","NETWORK_ERROR","SERVICE_UNAVAILABLE"].includes(f.code)?new c("DECISION_ACCEPTANCE_UNKNOWN","Decision acceptance is unknown; retry the original request ID and input",f.status,p.requestId):f}if(d.requestId!==p.requestId||d.decision&&!pe(d.decision,b.customer))throw new c("INVALID_RESPONSE","Decision request or customer changed");return{response:await r(d,v),customer:b.customer}}return{local(){return n??=he({scope:e.scope,funnelId:e.funnelId,load:()=>a({operation:"local_configuration",funnelId:e.funnelId})})},async configuration(){let p=z.parse(await a({operation:"configuration",funnelId:e.funnelId}));if(p.scope.projectId!==e.scope.projectId||p.scope.environment!==e.scope.environment||p.funnelId!==e.funnelId)throw new c("SCOPE_MISMATCH","Configuration scope changed");return p},features(p={}){return Me({...p,scope:e.scope,load:async()=>at.parse(await a({operation:"feature_config",funnelId:e.funnelId}))})},read:p=>s(p),async submit(p){return(await l(p,void 0,!0)).response},async decide(p){let v=Date.now()+3e4,E=await l(p,v);return ge(E.response,E.customer,v,s)},async reportUsed(p){let v=lt.parse(await a(de.parse({...p,operation:"report_used"})));if(v.decisionId!==p.decisionId||v.eventId!==p.eventId)throw new c("INVALID_RESPONSE","Usage receipt identity changed");return v}}}function xn(e){V(e.apiKey,"Native receipts are verified by your backend","Server API key required");let n=N({...e,timeoutMs:e.timeoutMs??35e3});return{async recover(t){let o=Gt.parse(t);if(o.orderId!==o.receiptId)throw new c("INVALID_REQUEST","Native recovery requires the accepted commercial intent");let r=o.nativeEvidence,a={requestId:o.requestId,customerToken:o.customerToken,purchaseIntentId:o.orderId,...r===null?{intent:"read"}:r.provider==="apple"?{provider:"apple",signedTransaction:r.signedTransaction}:{provider:"google",purchaseToken:r.purchaseToken}},s=m.restoreNativePurchase.response.parse(await n.request(m.restoreNativePurchase.path,a));if(s.operation.requestId!==o.requestId||s.operation.purchaseIntentId!==o.orderId)throw new c("INVALID_RESPONSE","Native receipt request identity changed");let l=jt.parse({scope:s.scope,requestId:o.requestId,orderId:s.operation.orderId,receiptId:s.operation.orderId,orderStatus:s.operation.status,refunded:s.operation.refunded,...s.operation.completion===null?{}:{nativeCompletion:{orderId:s.operation.orderId,receiptId:s.operation.orderId,...s.operation.completion}}});if(l.requestId!==o.requestId||l.orderId!==o.orderId||l.receiptId!==o.receiptId||l.scope.projectId!==e.scope.projectId||l.scope.environment!==e.scope.environment)throw new c("INVALID_RESPONSE","Current order receipt scope changed");return l}}}var J=u.number().int().min(0).max(Number.MAX_SAFE_INTEGER);function _n(e,n){let t=J.parse(e.inputTokens.total),o=J.parse(e.outputTokens.total),r=J.parse(e.inputTokens.cacheRead??0),a=J.parse(e.inputTokens.cacheWrite??0),s=J.parse(e.outputTokens.reasoning??0);if(r+a>t||s>o||e.inputTokens.noCache!==void 0&&J.parse(e.inputTokens.noCache)!==t-r-a||e.outputTokens.text!==void 0&&J.parse(e.outputTokens.text)!==o-s)throw new c("AI_USAGE_UNAVAILABLE","Provider token counts do not conserve total usage");return{input:t-r-a,cache_read:r,cache_write:a,output:n==="output"?o:o-s,reasoning:n==="separate"?s:0,input_audio:0,output_audio:0}}function Mn(e){if(typeof window<"u")throw new c("SERVER_ONLY","AI usage belongs on the trusted backend");if(!e.modelId||!["output","separate"].includes(e.reasoning))throw new c("INVALID_REQUEST","Model ID and reasoning pricing are required");async function n(o){await e.persist({context:o,modelId:e.modelId,usage:null,tokens:null,quote:null,receipt:null,phase:"incomplete"})}async function t(o,r){let a={context:o,modelId:e.modelId,usage:r,tokens:null,quote:null,receipt:null,phase:"captured"};await e.persist(a);let s=e.mapTokens?e.mapTokens(r):_n(r,e.reasoning),l=await e.pricing.quoteTokens({modelId:e.modelId,tokens:s});await e.persist({...a,tokens:s,quote:l,phase:"quoted"});let p=await e.pricing.trackTokens(e.client,{...o,quote:l});if(!p.receipt.accepted)throw new c("AI_BALANCE_REJECTED","AI usage was captured but the balance operation was rejected");await e.persist({...a,tokens:s,quote:l,receipt:p,phase:"settled"})}return{specificationVersion:"v4",async wrapGenerate({doGenerate:o}){let r=await e.context(),a;try{a=await o()}catch(s){throw await n(r),s}return await t(r,a.usage),a},async wrapStream({doStream:o}){let r=await e.context(),a;try{a=await o()}catch(E){throw await n(r),E}let s=!1,l=!1,p=a.stream.getReader();async function v(){s||l||(l=!0,await n(r))}return{...a,stream:new ReadableStream({async pull(E){try{let{value:b,done:d}=await p.read();if(d){if(!s)throw await v(),new c("AI_USAGE_UNAVAILABLE","Stream ended without final usage; no amount was invented");E.close();return}if(b.type==="finish"){if(s)throw new c("AI_USAGE_UNAVAILABLE","Provider sent more than one final usage record");s=!0,await t(r,b.usage)}E.enqueue(b)}catch(b){try{await v()}finally{E.error(b),await p.cancel(b)}}},async cancel(E){try{await v()}finally{await p.cancel(E)}}})}}}}function kn(e){V(e.apiKey,"Funnel receipts are sent by your backend");let n=N(e);return{async signal(t){let o=Re.parse({...t,operation:"signal"}),r=st.parse(await n.request("funnels",o));if(r.runId!==t.runId||r.eventId!==t.eventId||r.scope.projectId!==e.scope.projectId||r.scope.environment!==e.scope.environment)throw new c("INVALID_RESPONSE","Receipt identity changed");return r},async readResults(t){let o=Re.parse({operation:"read_results",runId:t}),r=ct.parse(await n.request("funnels",o));if(r.runId!==t||r.scope.projectId!==e.scope.projectId||r.scope.environment!==e.scope.environment)throw new c("INVALID_RESPONSE","Result identity changed");return r}}}function Bn(e){if("remoteEval"in e)throw new c("INVALID_REQUEST","Configure evaluation mode on the Funnel; remoteEval is not supported");V(e.apiKey,"Campaign entry requires your backend");let n=N({...e,timeoutMs:e.timeoutMs??35e3});return{async decide(t){let o=Date.now()+(e.timeoutMs??3e4),r=Pe.parse({...t,funnelId:e.funnelId,operation:"campaign_decide"}),a=N({...e,timeoutMs:Math.min(e.timeoutMs??35e3,Math.max(1,o-Date.now()))}),s=Z.parse(await a.request("funnels",r));if(s.scope.projectId!==e.scope.projectId||s.scope.environment!==e.scope.environment)throw new c("SCOPE_MISMATCH","Campaign scope changed");return ge(s,r.customer,o,(l,p)=>Fe({...e,timeoutMs:Math.min(e.timeoutMs??1e4,Math.max(1,p-Date.now()))}).read(l))},async start(t){let o=Pe.parse({...t,funnelId:e.funnelId,operation:"campaign_start"}),r=Vt.parse(await n.request("funnels",o));if(r.scope.projectId!==e.scope.projectId||r.scope.environment!==e.scope.environment)throw new c("SCOPE_MISMATCH","Campaign scope changed");if(!("suppressed"in r)&&(r.run.source.id!==e.funnelId||!r.customerId||o.customer.type==="id"&&r.customerId!==o.customer.value))throw new c("INVALID_RESPONSE","Campaign Funnel or Customer changed");return r}}}var x=class extends Error{constructor(t,o=409,r=!1,a="fix_request"){super(t);this.code=t;this.status=o;this.retryable=r;this.recovery=a}code;status;retryable;recovery};function Pn(e){if(typeof window<"u")throw new Error("Merchant bridge credentials require a trusted server");let n=se.parse(e.manifest),t={projectId:n.projectId,environmentId:n.environmentId,environment:n.environment},o=n.capabilities.some(r=>["purchases","subscription_changes","refunds","operation_status"].includes(r));for(let[r,a]of Object.entries(Se))if(a.command&&n.capabilities.includes(r)&&!(r==="catalog"&&n.catalog==="static")&&!e.handlers[a.command])throw new Error(`Missing merchant command handler: ${a.command}`);if(o&&(!e.resolveOperationAuthority||!e.handlers["operation.read"]||!n.capabilities.includes("operation_status")))throw new Error("Merchant operations require fresh Longplay authority and an operation lookup handler");return async function(a){let s=crypto.randomUUID(),l="bridge.ping",p,v=async(E,b,d=!1)=>{let f=JSON.stringify({bridgeVersion:X,requestId:s,command:l,scope:t,[d?"error":"data"]:E});if(new TextEncoder().encode(f).byteLength>262144)throw new Error("Merchant response exceeds limit");return new Response(f,{status:b,headers:{"Content-Type":"application/json","Cache-Control":"private, no-store","X-Request-Id":s,...p?await te(f,p,"response"):{}}})};try{if(a.headers.get("X-Indiana-Merchant-Bridge-Version")!==String(X)||a.method!=="POST"||new URL(a.url).pathname!==W)throw new x("MERCHANT_BRIDGE_INVALID_REQUEST",400);if(!/^application\/json(?:\s*;|$)/i.test(a.headers.get("Content-Type")??""))throw new x("MERCHANT_BRIDGE_INVALID_REQUEST",400);let E=a.body?.getReader();if(!E)throw new x("MERCHANT_BRIDGE_INVALID_REQUEST",400);let b=new TextDecoder("utf-8",{fatal:!0}),d="",f=0;try{for(;;){let _=await E.read();if(_.done)break;if(f+=_.value.byteLength,f>16384)throw new x("MERCHANT_BRIDGE_INVALID_REQUEST",413);d+=b.decode(_.value,{stream:!0})}d+=b.decode()}finally{await E.cancel().catch(()=>{}),E.releaseLock()}let y=ot.safeParse(JSON.parse(d));if(!y.success)throw new x("MERCHANT_BRIDGE_INVALID_REQUEST",400);let S=y.data;if(s=S.requestId,l=S.command,Object.keys(t).some(_=>S.scope[_]!==t[_]))throw new x("MERCHANT_BRIDGE_SCOPE_MISMATCH",403);let k=S.command==="bridge.ping"||S.command==="bridge.describe",D=S.command==="catalog.read";if((k||D||a.headers.has(Q))&&(p=e.authentication.find(_=>_.keyId===a.headers.get(Q)),!p||!await ne(d,a.headers,p,"request")))throw p=void 0,new x("MERCHANT_BRIDGE_AUTHENTICATION_FAILED",401);if(S.command==="bridge.ping")return v(Ee["bridge.ping"].parse(S.data),200);if(S.command==="bridge.describe")return v(n,200);let g=Object.entries(Se).find(([,_])=>_.command===S.command);if(!g||!n.capabilities.includes(g[0]))throw new x("MERCHANT_BRIDGE_CAPABILITY_UNSUPPORTED",501);let i=e.handlers[S.command];if(!i)throw new x("MERCHANT_BRIDGE_CAPABILITY_UNSUPPORTED",501);if(!D&&a.headers.has("Cookie")&&(a.headers.get("Origin")!==new URL(a.url).origin||["cross-site","same-site"].includes(a.headers.get("Sec-Fetch-Site")??"")))throw new x("MERCHANT_BRIDGE_FORBIDDEN",403);let w=D?{kind:"service"}:await e.authorize(a,S),R=w.kind,C=["purchase.execute","subscription.change","refund.execute"].includes(S.command),A=C||S.command==="operation.read";if(!(A&&p!==void 0&&R==="service")&&(S.command==="refund.execute"?R!=="administrator":!D&&R!=="user"))throw new x("MERCHANT_BRIDGE_FORBIDDEN",403);if(w.kind==="user"&&["purchase.execute","operation.read","subscription.change","customer.commerce.read","presentation.report"].includes(S.command)&&!u.uuid().safeParse(w.customerId).success)throw new x("MERCHANT_BRIDGE_UNAUTHENTICATED",401);let M=i,F=Ee[S.command].parse(S.data),B={request:a,command:S.command,scope:t,principal:w},T;if(A){let _=j.parse(F);if(w.kind==="user"&&w.customerId!==_.customerId)throw new x("MERCHANT_BRIDGE_SCOPE_MISMATCH",403);if(!e.resolveOperationAuthority)throw new x("MERCHANT_BRIDGE_CAPABILITY_UNSUPPORTED",501);let P=ce.parse(await e.resolveOperationAuthority(_,B));if(P.operationId!==_.operationId||P.customerId!==_.customerId||Object.keys(t).some(G=>P.scope[G]!==t[G]))throw new x("MERCHANT_BRIDGE_SCOPE_MISMATCH",403);B.authority=P;let H=S.command==="purchase.execute"?"purchase":S.command==="subscription.change"?"subscription_change":S.command==="refund.execute"?"refund":P.instruction.type;if(P.instruction.type!==H)throw new x("MERCHANT_BRIDGE_SCOPE_MISMATCH",403);if(!C)T=we.parse(await M(F,B));else{if(P.confirmedAt===null)throw new x("MERCHANT_BRIDGE_OPERATION_NOT_CONFIRMED",409);let G=we.parse(await e.handlers["operation.read"](_,{...B,command:"operation.read"}));if(G.operationId!==_.operationId||G.customerId!==_.customerId)throw new x("MERCHANT_BRIDGE_SCOPE_MISMATCH",403);if(G.lookup==="found")T=G.execution;else{if(!P.initialExecutionAllowed)throw new x("MERCHANT_BRIDGE_RECOVERY_REQUIRED",409,!1,"recover_operation");if(Date.parse(P.instruction.expiresAt)<=Date.now())throw new x("MERCHANT_BRIDGE_OPERATION_EXPIRED",409,!1,"reload_state");if(!n.capabilities.includes("billing_records")||je(P.instruction).some(U=>!n.billingEvents.some(on=>on===U))||Ge(P.instruction).some(U=>!n.profiles.includes(U)))throw new x("MERCHANT_BRIDGE_CAPABILITY_UNSUPPORTED",501,!1,"check_availability");try{T=nt.parse(await M(F,B))}catch(U){throw U instanceof x?U:new x("MERCHANT_BRIDGE_RESULT_UNKNOWN",503,!1,"recover_operation")}}if(T.type!==H)throw new x("MERCHANT_BRIDGE_SCOPE_MISMATCH",403)}}else T=rt[S.command].parse(await M(F,B));if(w.kind==="user"){if("nativeUserId"in T&&T.nativeUserId!==w.nativeUserId)throw new x("MERCHANT_BRIDGE_SCOPE_MISMATCH",403);if("customerId"in T&&T.customerId!==w.customerId)throw new x("MERCHANT_BRIDGE_SCOPE_MISMATCH",403);if("session"in T&&w.customerId&&T.session.customerId!==w.customerId)throw new x("MERCHANT_BRIDGE_SCOPE_MISMATCH",403);if("presentation"in T&&T.presentation&&w.customerId&&T.presentation.customerId!==w.customerId)throw new x("MERCHANT_BRIDGE_SCOPE_MISMATCH",403)}if("operationId"in T&&(T.operationId!==j.parse(S.data).operationId||T.customerId!==j.parse(S.data).customerId))throw new x("MERCHANT_BRIDGE_SCOPE_MISMATCH",403);return v(T,C&&("paymentStatus"in T&&["pending","unknown"].includes(T.paymentStatus)||"status"in T&&["pending","unknown","scheduled"].includes(T.status))?202:200)}catch(E){let b=E instanceof x?E:E instanceof SyntaxError?new x("MERCHANT_BRIDGE_INVALID_REQUEST",400):new x("MERCHANT_BRIDGE_INVALID_RESPONSE",500);return v({code:b.code,message:b.code,retryable:b.retryable,recovery:b.recovery},b.status,!0)}}}function Dn(e){return async(n,t)=>{let o=()=>e.readSubscriptionOperation(n),r=()=>e.readSubscriptionUpdate(n),a=()=>e.readRefund(n),s=t.command==="purchase.execute"?[o]:t.command==="subscription.change"?[r]:t.command==="refund.execute"?[a]:[o,r,a];for(let l of s)try{let p=await l(),v="authority"in p.operation?p.operation.authority:void 0;if(!v)throw new x("MERCHANT_BRIDGE_CAPABILITY_UNSUPPORTED",501,!1,"check_availability");let E=ce.parse(v);if(E.customerId!==n.customerId||E.operationId!==n.operationId||Object.keys(t.scope).some(b=>E.scope[b]!==t.scope[b]))throw new x("MERCHANT_BRIDGE_SCOPE_MISMATCH",403);return E}catch(p){if(t.command==="operation.read"&&p instanceof c&&p.code==="NOT_FOUND")continue;throw p}throw new x("MERCHANT_BRIDGE_OPERATION_NOT_FOUND",404,!1,"reload_state")}}function Fn(e){if(typeof window<"u")throw new Error("Merchant protocol credentials require a trusted server");let n=ke.parse(e.manifest),t=ie.parse(e.authentication),o={projectId:n.projectId,environmentId:n.environmentId,environment:n.environment},r=e.now??Date.now,a=d=>{throw new c("INVALID_RESPONSE",d)},s=(d,f)=>Ie(d)===Ie(f);function l(d){new TextEncoder().encode(d).byteLength>262144&&a("Merchant protocol body exceeds limit");try{return JSON.parse(d)}catch{return a("Invalid merchant protocol JSON")}}function p(d){let f=kt.parse(d);return s(f.scope,o)||a("Merchant protocol scope mismatch"),f.command==="requirement.check"&&(n.capabilities.includes("requirement_checks")||a("Merchant Check capability unavailable"),s(f.data.subject.scope,o)||a("Merchant Check subject crosses scope")),f.command==="operation.prepare"&&(!n.capabilities.includes("preparations")||!s(f.data.request.subject.scope,o))&&a("Merchant preparation capability unavailable"),f.command==="purchase.terminate"&&!n.capabilities.includes("checkout_termination")&&a("Checkout termination capability unavailable"),f}function v(d){if(d.command!=="operation.prepare")return;let f=d.data;return(!s(f.request.subject.scope,o)||!f.preparationAllowed||Date.parse(f.requestedAt)>r()||Date.parse(f.request.expiresAt)<=r()||!n.preparationActions.includes(f.request.action))&&a("Merchant preparation requires fresh scoped authority"),f}function E(d,f){let y=Bt(d.command).parse(f);if((y.requestId!==d.requestId||!s(y.scope,o))&&a("Merchant reply correlation mismatch"),"error"in y)return y;if(d.command==="purchase.terminate"&&"outcome"in y.data&&(y.data.operationId!==d.data.operationId||y.data.customerId!==d.data.customerId)&&a("Checkout termination changed the original operation"),d.command==="bridge.ping"&&"challenge"in y.data&&y.data.challenge!==d.data.challenge&&a("Merchant ping challenge mismatch"),d.command==="bridge.describe"&&"bridgeVersion"in y.data&&!s({projectId:y.data.projectId,environmentId:y.data.environmentId,environment:y.data.environment},o)&&a("Merchant declaration crosses scope"),d.command==="requirement.check"&&"observation"in y.data&&(!s(y.data.observation.subject,d.data.subject)||!Je(d.data.requirement,y.data)||!n.checkKinds.includes(y.data.kind))&&a("Merchant Check changed the original requirement or subject"),d.command==="operation.prepare"&&"quoteTermsDigest"in y.data){let S=v(d);(!s(y.data.request,S.request)||Date.parse(y.data.expiresAt)<=r()||Date.parse(y.data.observedAt)<Date.parse(S.requestedAt)||Date.parse(y.data.observedAt)>r())&&a("Merchant quote changed its authorized request or validity")}return y}let b=async d=>{let f=JSON.stringify(d);return l(f),{body:f,headers:new Headers({"Content-Type":"application/json","Cache-Control":"private, no-store",[oe]:"4",...await te(f,t,"response",r(),4)})}};return{version:4,path:W,async encodeRequest(d,f){let y=p({bridgeVersion:4,requestId:crypto.randomUUID(),scope:o,command:d,data:f});v(y);let S=JSON.stringify(y);l(S);let k=new Headers({"Content-Type":"application/json",[oe]:"4",...await te(S,t,"request",r(),4)});return{body:S,headers:k,async readResponse(D,g){l(D),(g.get(oe)!=="4"||!await ne(D,g,t,"response",r(),4))&&a("Merchant response authentication failed");let i=E(y,l(D));if("error"in i)throw new ye(i.error);return i.data}}},async decodeRequest(d,f){l(d),(f.get(oe)!=="4"||f.get(Q)!==t.keyId||!await ne(d,f,t,"request",r(),4))&&a("Merchant request authentication failed");let y=p(l(d));return v(y),y},async encodeResponse(d,f){let y=p(d),S=E(y,{...y,data:f});return b(S)},async encodeError(d,f){let y=p(d),{data:S,...k}=y;return b(E(y,{...k,error:Be.parse(f)}))}}}var ye=class extends Error{constructor(t){super(t.message);this.problem=t}problem};export{re as FunnelDecisionTimeoutError,fe as FunnelProcessEntrySuppressedError,c as LongplayError,x as MerchantBridgeHandlerError,ye as MerchantBridgeProtocolError,fn as aiPriceSnapshotSchema,hn as aiTokenQuoteSchema,gn as createAiPricing,Mn as createAiUsageMiddleware,dn as createConfigurationSync,yn as createConfiguredAiPricing,Me as createFeatureClient,Bn as createFunnelCampaignClient,Fe as createFunnelDecisionClient,he as createFunnelLocalEvaluator,kn as createFunnelOrchestrationClient,Rn as createFunnelProcessAdapter,ln as createFunnelStartClient,De as createGuestToken,mn as createLocalFunnelClient,Cn as createLongplayServer,Dn as createMerchantBridgeAuthorityResolver,Pn as createMerchantBridgeHandler,Fn as createMerchantBridgeProtocol,xn as createNativeReceiptClient,Tn as createPaywallStartClient,On as createSynchronizedFunnelLocalEvaluator,un as entitlementRequirementDigest,pn as evaluateFunnelNode,cn as merchantConfirmationMatchesTerms,an as merchantPreparationRequestDigest,sn as merchantQuoteTermsDigest,bn as renewFunnelRun,te as signMerchantBridgeMessage,ne as verifyMerchantBridgeMessage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{b as a,c as b}from"./chunk-
|
|
1
|
+
import{b as a,c as b}from"./chunk-OJM6ORHE.js";import"./chunk-J6KIN4RH.js";import"./chunk-WOT6VMZA.js";export{b as applyVisualVariation,a as safeVisualMutation};
|