@tinkerlandai/indiana-sdk 0.8.1 → 0.8.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/README.md +44 -3
  3. package/README.zh-CN.md +8 -0
  4. package/dist/{ai-usage-JoM7ZWk-.d.ts → ai-usage-DUlre7JC.d.ts} +1 -1
  5. package/dist/{api-JVC7x2FV.d.ts → api-XDc4pRlN.d.ts} +444 -17
  6. package/dist/chunk-3F2NQOR2.js +1 -0
  7. package/dist/chunk-663UOBHL.js +1 -0
  8. package/dist/chunk-BUDTHBFF.js +173 -0
  9. package/dist/chunk-EJTBSGLV.js +10 -0
  10. package/dist/{chunk-USLZX2ZA.js → chunk-F2GOIBDQ.js} +1 -1
  11. package/dist/{chunk-YWFNWK7C.js → chunk-GRLMT5PR.js} +1 -1
  12. package/dist/chunk-LMR2TM3X.js +1 -0
  13. package/dist/chunk-OBYJWIRB.js +1 -0
  14. package/dist/chunk-RZBZ6LCT.js +4 -0
  15. package/dist/{chunk-6HG7U6AU.js → chunk-SOQO2RDZ.js} +1 -1
  16. package/dist/chunk-SSHUBTT3.js +1 -0
  17. package/dist/chunk-SSLZKIIU.js +1 -0
  18. package/dist/{chunk-KSNOXNTC.js → chunk-VVV3JNS3.js} +1 -1
  19. package/dist/{configuration-sync-BexM2qbg.d.ts → configuration-sync-Ce3dShy7.d.ts} +8 -3
  20. package/dist/content-2FCUY6XX.js +1 -0
  21. package/dist/{customer-page-WUQVK_tp.d.ts → customer-page-9B97Qdt_.d.ts} +21 -1
  22. package/dist/{errors-DrdTlPwf.d.ts → errors-C8lRYZ0n.d.ts} +48 -1
  23. package/dist/{funnel-local-client-D1Fe7CZ6.d.ts → funnel-local-client-CUGavICI.d.ts} +69 -40
  24. package/dist/{funnel-runtime-host-CAMI6BJS.js → funnel-runtime-host-ENRTSXPJ.js} +1 -1
  25. package/dist/index.d.ts +175 -35
  26. package/dist/index.js +1 -1
  27. package/dist/native-shell.js +1 -1
  28. package/dist/openrouter.d.ts +3 -3
  29. package/dist/openrouter.js +1 -1
  30. package/dist/page.d.ts +2 -2
  31. package/dist/page.js +1 -1
  32. package/dist/paywall-734GWAS4.js +1 -0
  33. package/dist/popup.d.ts +15 -5
  34. package/dist/popup.js +1 -1
  35. package/dist/react-native.d.ts +97 -4
  36. package/dist/react-native.js +1 -1
  37. package/dist/screen-renderer-DLXDQQKK.js +1 -0
  38. package/dist/server.d.ts +18 -15
  39. package/dist/server.js +1 -1
  40. package/dist/src-CLEFCTAU.js +1 -0
  41. package/dist/visual.js +2 -2
  42. package/package.json +1 -1
  43. package/dist/chunk-3BQFJANQ.js +0 -1
  44. package/dist/chunk-56AYS7RS.js +0 -1
  45. package/dist/chunk-AE4CUTUE.js +0 -1
  46. package/dist/chunk-AEUFCOFG.js +0 -1
  47. package/dist/chunk-F767CM3T.js +0 -7
  48. package/dist/chunk-X747SY26.js +0 -4
  49. package/dist/chunk-X7JJAEQQ.js +0 -350
  50. package/dist/content-YNL2CRJZ.js +0 -1
  51. package/dist/paywall-MXRMMF3R.js +0 -1
  52. package/dist/screen-renderer-P7MLBHY5.js +0 -1
  53. package/dist/src-G7UQB3QE.js +0 -1
  54. package/dist/{screen-i6eHL11m.d.ts → screen-BpAejkn0.d.ts} +1 -1
@@ -1,10 +1,10 @@
1
- import { I as InvoiceModeParams, a as InvoiceModeParamsInput, A as ApiInput } from './api-JVC7x2FV.js';
2
- import { S as StackNode, d as ScreenSelection } from './screen-i6eHL11m.js';
1
+ import { I as InvoiceModeParams, b as InvoiceModeParamsInput, A as ApiInput } from './api-XDc4pRlN.js';
2
+ import { S as StackNode, d as ScreenSelection } from './screen-BpAejkn0.js';
3
3
  import * as zod from 'zod';
4
4
  import { z } from 'zod';
5
5
  import { E as EvaluationContext, J as JsonValue, F as FeatureResult } from './growth-rules-B4YYy64R.js';
6
- import { S as Scope } from './errors-DrdTlPwf.js';
7
- import { C as ConfigurationSync } from './configuration-sync-BexM2qbg.js';
6
+ import { a as PushHost, S as Scope } from './errors-C8lRYZ0n.js';
7
+ import { C as ConfigurationSync } from './configuration-sync-Ce3dShy7.js';
8
8
 
9
9
  declare const currencySchema: z.ZodEnum<{
10
10
  USD: "USD";
@@ -99,6 +99,7 @@ declare const funnelCommandSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
99
99
  customerData: z.ZodOptional<z.ZodObject<{
100
100
  name: z.ZodOptional<z.ZodString>;
101
101
  email: z.ZodOptional<z.ZodUnion<readonly [z.ZodEmail, z.ZodLiteral<"">]>>;
102
+ phone: z.ZodOptional<z.ZodNullable<z.ZodString>>;
102
103
  attributes: z.ZodOptional<z.ZodIntersection<z.ZodRecord<z.ZodString, z.ZodJSONSchema>, z.ZodObject<{
103
104
  tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
104
105
  }, z.core.$loose>>>;
@@ -197,8 +198,8 @@ declare const funnelCommandSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
197
198
  success: "success";
198
199
  failed: "failed";
199
200
  cancel: "cancel";
200
- failure: "failure";
201
201
  opened: "opened";
202
+ failure: "failure";
202
203
  }>;
203
204
  }, z.core.$strict>], "type">;
204
205
  requestId: z.ZodUUID;
@@ -260,12 +261,12 @@ declare const funnelRunViewSchema: z.ZodObject<{
260
261
  feature: "feature";
261
262
  split: "split";
262
263
  condition: "condition";
264
+ entry: "entry";
263
265
  coupon: "coupon";
264
266
  end: "end";
265
267
  screen: "screen";
266
268
  offering: "offering";
267
269
  coupons: "coupons";
268
- entry: "entry";
269
270
  external_page: "external_page";
270
271
  wait: "wait";
271
272
  }>;
@@ -2303,12 +2304,12 @@ declare const funnelRuntimeResponseSchema: z.ZodObject<{
2303
2304
  feature: "feature";
2304
2305
  split: "split";
2305
2306
  condition: "condition";
2307
+ entry: "entry";
2306
2308
  coupon: "coupon";
2307
2309
  end: "end";
2308
2310
  screen: "screen";
2309
2311
  offering: "offering";
2310
2312
  coupons: "coupons";
2311
- entry: "entry";
2312
2313
  external_page: "external_page";
2313
2314
  wait: "wait";
2314
2315
  }>;
@@ -5397,12 +5398,12 @@ declare const funnelConfigurationSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
5397
5398
  feature: "feature";
5398
5399
  split: "split";
5399
5400
  condition: "condition";
5401
+ entry: "entry";
5400
5402
  coupon: "coupon";
5401
5403
  end: "end";
5402
5404
  screen: "screen";
5403
5405
  offering: "offering";
5404
5406
  coupons: "coupons";
5405
- entry: "entry";
5406
5407
  external_page: "external_page";
5407
5408
  wait: "wait";
5408
5409
  }>;
@@ -5442,12 +5443,12 @@ declare const funnelConfigurationSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
5442
5443
  feature: "feature";
5443
5444
  split: "split";
5444
5445
  condition: "condition";
5446
+ entry: "entry";
5445
5447
  coupon: "coupon";
5446
5448
  end: "end";
5447
5449
  screen: "screen";
5448
5450
  offering: "offering";
5449
5451
  coupons: "coupons";
5450
- entry: "entry";
5451
5452
  external_page: "external_page";
5452
5453
  wait: "wait";
5453
5454
  }>;
@@ -5661,12 +5662,12 @@ declare const funnelLocalConfigurationSchema: z.ZodObject<{
5661
5662
  feature: "feature";
5662
5663
  split: "split";
5663
5664
  condition: "condition";
5665
+ entry: "entry";
5664
5666
  coupon: "coupon";
5665
5667
  end: "end";
5666
5668
  screen: "screen";
5667
5669
  offering: "offering";
5668
5670
  coupons: "coupons";
5669
- entry: "entry";
5670
5671
  external_page: "external_page";
5671
5672
  wait: "wait";
5672
5673
  }>;
@@ -7460,6 +7461,10 @@ declare const evaluateFeaturesResultSchema: z.ZodObject<{
7460
7461
  stickyBucketUsed: z.ZodOptional<z.ZodBoolean>;
7461
7462
  }, z.core.$strict>>;
7462
7463
  }, z.core.$strict>>;
7464
+ merchandiseContext: z.ZodOptional<z.ZodObject<{
7465
+ merchandiseId: z.ZodUUID;
7466
+ merchandise: z.ZodRecord<z.ZodString, z.ZodJSONSchema>;
7467
+ }, z.core.$strict>>;
7463
7468
  }, z.core.$strict>;
7464
7469
 
7465
7470
  type FunnelNodeEvaluationContext = Pick<EvaluationContext, "attributes" | "stickyBucketAssignmentDocs" | "saveStickyBucketAssignmentDoc" | "onFeatureUsage" | "onExperimentViewed">;
@@ -7490,6 +7495,7 @@ declare const funnelPendingEntrySchema: z.ZodObject<{
7490
7495
  customerData: z.ZodOptional<z.ZodObject<{
7491
7496
  name: z.ZodOptional<z.ZodString>;
7492
7497
  email: z.ZodOptional<z.ZodUnion<readonly [z.ZodEmail, z.ZodLiteral<"">]>>;
7498
+ phone: z.ZodOptional<z.ZodNullable<z.ZodString>>;
7493
7499
  attributes: z.ZodOptional<z.ZodIntersection<z.ZodRecord<z.ZodString, z.ZodJSONSchema>, z.ZodObject<{
7494
7500
  tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
7495
7501
  }, z.core.$loose>>>;
@@ -7588,8 +7594,8 @@ declare const funnelPendingEntrySchema: z.ZodObject<{
7588
7594
  success: "success";
7589
7595
  failed: "failed";
7590
7596
  cancel: "cancel";
7591
- failure: "failure";
7592
7597
  opened: "opened";
7598
+ failure: "failure";
7593
7599
  }>;
7594
7600
  }, z.core.$strict>], "type">;
7595
7601
  requestId: z.ZodUUID;
@@ -7666,7 +7672,7 @@ declare const funnelPendingEntrySchema: z.ZodObject<{
7666
7672
  } | {
7667
7673
  type: "client_action";
7668
7674
  receiptId: string;
7669
- outcome: "success" | "failed" | "cancel" | "failure" | "opened";
7675
+ outcome: "success" | "failed" | "cancel" | "opened" | "failure";
7670
7676
  };
7671
7677
  requestId: string;
7672
7678
  nodeId: string;
@@ -7720,6 +7726,7 @@ declare const funnelPendingEntrySchema: z.ZodObject<{
7720
7726
  customerData?: {
7721
7727
  name?: string | undefined;
7722
7728
  email?: string | undefined;
7729
+ phone?: string | null | undefined;
7723
7730
  attributes?: (Record<string, z.core.util.JSONType> & {
7724
7731
  [x: string]: unknown;
7725
7732
  tags?: string[] | undefined;
@@ -7789,7 +7796,7 @@ declare const funnelPendingEntrySchema: z.ZodObject<{
7789
7796
  } | {
7790
7797
  type: "client_action";
7791
7798
  receiptId: string;
7792
- outcome: "success" | "failed" | "cancel" | "failure" | "opened";
7799
+ outcome: "success" | "failed" | "cancel" | "opened" | "failure";
7793
7800
  };
7794
7801
  requestId: string;
7795
7802
  nodeId: string;
@@ -7846,6 +7853,7 @@ declare const funnelPendingEntrySchema: z.ZodObject<{
7846
7853
  customerData: z.ZodOptional<z.ZodObject<{
7847
7854
  name: z.ZodOptional<z.ZodString>;
7848
7855
  email: z.ZodOptional<z.ZodUnion<readonly [z.ZodEmail, z.ZodLiteral<"">]>>;
7856
+ phone: z.ZodOptional<z.ZodNullable<z.ZodString>>;
7849
7857
  attributes: z.ZodOptional<z.ZodIntersection<z.ZodRecord<z.ZodString, z.ZodJSONSchema>, z.ZodObject<{
7850
7858
  tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
7851
7859
  }, z.core.$loose>>>;
@@ -7944,8 +7952,8 @@ declare const funnelPendingEntrySchema: z.ZodObject<{
7944
7952
  success: "success";
7945
7953
  failed: "failed";
7946
7954
  cancel: "cancel";
7947
- failure: "failure";
7948
7955
  opened: "opened";
7956
+ failure: "failure";
7949
7957
  }>;
7950
7958
  }, z.core.$strict>], "type">;
7951
7959
  requestId: z.ZodUUID;
@@ -8022,7 +8030,7 @@ declare const funnelPendingEntrySchema: z.ZodObject<{
8022
8030
  } | {
8023
8031
  type: "client_action";
8024
8032
  receiptId: string;
8025
- outcome: "success" | "failed" | "cancel" | "failure" | "opened";
8033
+ outcome: "success" | "failed" | "cancel" | "opened" | "failure";
8026
8034
  };
8027
8035
  requestId: string;
8028
8036
  nodeId: string;
@@ -8076,6 +8084,7 @@ declare const funnelPendingEntrySchema: z.ZodObject<{
8076
8084
  customerData?: {
8077
8085
  name?: string | undefined;
8078
8086
  email?: string | undefined;
8087
+ phone?: string | null | undefined;
8079
8088
  attributes?: (Record<string, z.core.util.JSONType> & {
8080
8089
  [x: string]: unknown;
8081
8090
  tags?: string[] | undefined;
@@ -8145,7 +8154,7 @@ declare const funnelPendingEntrySchema: z.ZodObject<{
8145
8154
  } | {
8146
8155
  type: "client_action";
8147
8156
  receiptId: string;
8148
- outcome: "success" | "failed" | "cancel" | "failure" | "opened";
8157
+ outcome: "success" | "failed" | "cancel" | "opened" | "failure";
8149
8158
  };
8150
8159
  requestId: string;
8151
8160
  nodeId: string;
@@ -8210,6 +8219,7 @@ declare const funnelPendingEntrySchema: z.ZodObject<{
8210
8219
  customerData?: {
8211
8220
  name?: string | undefined;
8212
8221
  email?: string | undefined;
8222
+ phone?: string | null | undefined;
8213
8223
  attributes?: (Record<string, z.core.util.JSONType> & {
8214
8224
  [x: string]: unknown;
8215
8225
  tags?: string[] | undefined;
@@ -8279,7 +8289,7 @@ declare const funnelPendingEntrySchema: z.ZodObject<{
8279
8289
  } | {
8280
8290
  type: "client_action";
8281
8291
  receiptId: string;
8282
- outcome: "success" | "failed" | "cancel" | "failure" | "opened";
8292
+ outcome: "success" | "failed" | "cancel" | "opened" | "failure";
8283
8293
  };
8284
8294
  requestId: string;
8285
8295
  nodeId: string;
@@ -8344,6 +8354,7 @@ declare const funnelPendingEntrySchema: z.ZodObject<{
8344
8354
  customerData?: {
8345
8355
  name?: string | undefined;
8346
8356
  email?: string | undefined;
8357
+ phone?: string | null | undefined;
8347
8358
  attributes?: (Record<string, z.core.util.JSONType> & {
8348
8359
  [x: string]: unknown;
8349
8360
  tags?: string[] | undefined;
@@ -8413,7 +8424,7 @@ declare const funnelPendingEntrySchema: z.ZodObject<{
8413
8424
  } | {
8414
8425
  type: "client_action";
8415
8426
  receiptId: string;
8416
- outcome: "success" | "failed" | "cancel" | "failure" | "opened";
8427
+ outcome: "success" | "failed" | "cancel" | "opened" | "failure";
8417
8428
  };
8418
8429
  requestId: string;
8419
8430
  nodeId: string;
@@ -8475,6 +8486,8 @@ interface FunnelCommandStorage {
8475
8486
  }
8476
8487
 
8477
8488
  interface IndianaOptions {
8489
+ /** Optional native installation adapter; shares this client's identity and transport. */
8490
+ push?: PushHost;
8478
8491
  /** Override the per-Run CAS adapter. Secure browser hosts use Web Locks/localStorage by default; non-browser hosts supply their own adapter. */
8479
8492
  funnelCommandStorage?: FunnelCommandStorage;
8480
8493
  /** One public GB/Funnel configuration manager shared by this App/environment's consumers. */
@@ -8558,8 +8571,14 @@ type FeatureClientOptions = {
8558
8571
  attributes?: Record<string, JsonValue>;
8559
8572
  scope: FeaturePayload["scope"];
8560
8573
  onError?: (error: unknown) => void;
8561
- onFeatureUsage?: EvaluationContext["onFeatureUsage"];
8562
- onExperimentViewed?: EvaluationContext["onExperimentViewed"];
8574
+ onFeatureUsage?: (...args: [
8575
+ ...Parameters<NonNullable<EvaluationContext["onFeatureUsage"]>>,
8576
+ Record<string, JsonValue>
8577
+ ]) => void;
8578
+ onExperimentViewed?: (...args: [
8579
+ ...Parameters<NonNullable<EvaluationContext["onExperimentViewed"]>>,
8580
+ Record<string, JsonValue>
8581
+ ]) => void;
8563
8582
  stickyBucketAssignmentDocs?: EvaluationContext["stickyBucketAssignmentDocs"];
8564
8583
  saveStickyBucketAssignmentDoc?: EvaluationContext["saveStickyBucketAssignmentDoc"];
8565
8584
  };
@@ -9493,7 +9512,7 @@ declare function createLocalFunnelClient(options: LocalFunnelClientOptions): Pro
9493
9512
  event: string;
9494
9513
  } | {
9495
9514
  type: "api";
9496
- operation: "update" | "attach" | "refund" | "readBalanceSource" | "adjustBalance" | "readUsage" | "setUsage" | "manageBalanceGrant" | "listBalanceGrants" | "restoreNativePurchase" | "setupPayment" | "readPaymentSetup" | "verifySubscriptions" | "previewAttach" | "readSubscriptionOperation" | "previewUpdate" | "readSubscriptionUpdate" | "previewRefund" | "readRefund" | "readBillingControls" | "prepareBillingAuthorization" | "confirmBillingAuthorization" | "setBillingCoupons" | "revokeBillingAuthorization" | "listBillingInvoices" | "confirmBillingAdjustment" | "manageBillingLimits" | "manageUsageEntity" | "readUsageAnalytics" | "readCreditAnalytics" | "submitUsageBatch" | "readUsageBatch" | "checkEntitlement" | "resolveOffering" | "readHoldings" | "readLedger" | "readBillingInvoice" | "readCreditStatement" | "quoteBalance" | "trackUsage" | "mutateBalance" | "redeemReward" | "createReferralCode" | "claimRewardProduct" | "readSeats" | "manageSeat" | "redeemCoupon" | "listOffers" | "grantOffer";
9515
+ operation: "update" | "attach" | "refund" | "sendMessage" | "readBalanceSource" | "adjustBalance" | "readUsage" | "setUsage" | "manageBalanceGrant" | "listBalanceGrants" | "restoreNativePurchase" | "setupPayment" | "readPaymentSetup" | "verifySubscriptions" | "previewAttach" | "readSubscriptionOperation" | "previewUpdate" | "readSubscriptionUpdate" | "previewRefund" | "readRefund" | "readBillingControls" | "prepareBillingAuthorization" | "confirmBillingAuthorization" | "setBillingCoupons" | "revokeBillingAuthorization" | "listBillingInvoices" | "confirmBillingAdjustment" | "manageBillingLimits" | "manageUsageEntity" | "readUsageAnalytics" | "readCreditAnalytics" | "submitUsageBatch" | "readUsageBatch" | "checkEntitlement" | "resolveOffering" | "readHoldings" | "readLedger" | "readBillingInvoice" | "readCreditStatement" | "quoteBalance" | "trackUsage" | "mutateBalance" | "redeemReward" | "createReferralCode" | "claimRewardProduct" | "readSeats" | "manageSeat" | "redeemCoupon" | "listOffers" | "grantOffer";
9497
9516
  inputs: Record<string, {
9498
9517
  source: "literal";
9499
9518
  value: zod.JSONType;
@@ -10196,6 +10215,11 @@ declare function createLocalFunnelClient(options: LocalFunnelClientOptions): Pro
10196
10215
  } | {
10197
10216
  type: "plans";
10198
10217
  planIds: string[];
10218
+ } | {
10219
+ type: "merchandise";
10220
+ scope: {
10221
+ type: "selected" | "all" | "condition";
10222
+ };
10199
10223
  };
10200
10224
  displayCopy: {
10201
10225
  defaultLocale: string;
@@ -10456,7 +10480,7 @@ declare function createLocalFunnelClient(options: LocalFunnelClientOptions): Pro
10456
10480
  entry: string;
10457
10481
  nodes: {
10458
10482
  id: string;
10459
- type: "output" | "action" | "feature" | "split" | "condition" | "coupon" | "end" | "screen" | "offering" | "coupons" | "entry" | "external_page" | "wait";
10483
+ type: "output" | "action" | "feature" | "split" | "condition" | "entry" | "coupon" | "end" | "screen" | "offering" | "coupons" | "external_page" | "wait";
10460
10484
  outputs: Record<string, string>;
10461
10485
  writes: Record<string, string>;
10462
10486
  resources: {
@@ -10530,7 +10554,7 @@ declare function createLocalFunnelClient(options: LocalFunnelClientOptions): Pro
10530
10554
  revision: number;
10531
10555
  visit: number;
10532
10556
  nodeId: string;
10533
- nodeType: "output" | "action" | "feature" | "split" | "condition" | "coupon" | "end" | "screen" | "offering" | "coupons" | "entry" | "external_page" | "wait";
10557
+ nodeType: "output" | "action" | "feature" | "split" | "condition" | "entry" | "coupon" | "end" | "screen" | "offering" | "coupons" | "external_page" | "wait";
10534
10558
  status: "failed" | "completed" | "running" | "closed" | "ineligible" | "waiting";
10535
10559
  stopped: boolean;
10536
10560
  canBack: boolean;
@@ -11563,7 +11587,7 @@ declare function createLocalFunnelClient(options: LocalFunnelClientOptions): Pro
11563
11587
  } | {
11564
11588
  type: "client_action";
11565
11589
  receiptId: string;
11566
- outcome: "success" | "failed" | "cancel" | "failure" | "opened";
11590
+ outcome: "success" | "failed" | "cancel" | "opened" | "failure";
11567
11591
  };
11568
11592
  requestId: string;
11569
11593
  nodeId: string;
@@ -11636,7 +11660,7 @@ declare function createLocalFunnelClient(options: LocalFunnelClientOptions): Pro
11636
11660
  } | {
11637
11661
  type: "client_action";
11638
11662
  receiptId: string;
11639
- outcome: "success" | "failed" | "cancel" | "failure" | "opened";
11663
+ outcome: "success" | "failed" | "cancel" | "opened" | "failure";
11640
11664
  };
11641
11665
  requestId: string;
11642
11666
  nodeId: string;
@@ -11696,7 +11720,7 @@ declare function createLocalFunnelClient(options: LocalFunnelClientOptions): Pro
11696
11720
  revision: number;
11697
11721
  visit: number;
11698
11722
  nodeId: string;
11699
- nodeType: "output" | "action" | "feature" | "split" | "condition" | "coupon" | "end" | "screen" | "offering" | "coupons" | "entry" | "external_page" | "wait";
11723
+ nodeType: "output" | "action" | "feature" | "split" | "condition" | "entry" | "coupon" | "end" | "screen" | "offering" | "coupons" | "external_page" | "wait";
11700
11724
  status: "failed" | "completed" | "running" | "closed" | "ineligible" | "waiting";
11701
11725
  stopped: boolean;
11702
11726
  canBack: boolean;
@@ -13377,7 +13401,7 @@ declare function createLocalFunnelClient(options: LocalFunnelClientOptions): Pro
13377
13401
  revision: number;
13378
13402
  visit: number;
13379
13403
  nodeId: string;
13380
- nodeType: "output" | "action" | "feature" | "split" | "condition" | "coupon" | "end" | "screen" | "offering" | "coupons" | "entry" | "external_page" | "wait";
13404
+ nodeType: "output" | "action" | "feature" | "split" | "condition" | "entry" | "coupon" | "end" | "screen" | "offering" | "coupons" | "external_page" | "wait";
13381
13405
  status: "failed" | "completed" | "running" | "closed" | "ineligible" | "waiting";
13382
13406
  stopped: boolean;
13383
13407
  canBack: boolean;
@@ -14796,7 +14820,7 @@ declare function createLocalFunnelClient(options: LocalFunnelClientOptions): Pro
14796
14820
  revision: number;
14797
14821
  visit: number;
14798
14822
  nodeId: string;
14799
- nodeType: "output" | "action" | "feature" | "split" | "condition" | "coupon" | "end" | "screen" | "offering" | "coupons" | "entry" | "external_page" | "wait";
14823
+ nodeType: "output" | "action" | "feature" | "split" | "condition" | "entry" | "coupon" | "end" | "screen" | "offering" | "coupons" | "external_page" | "wait";
14800
14824
  status: "failed" | "completed" | "running" | "closed" | "ineligible" | "waiting";
14801
14825
  stopped: boolean;
14802
14826
  canBack: boolean;
@@ -16213,7 +16237,7 @@ declare function createLocalFunnelClient(options: LocalFunnelClientOptions): Pro
16213
16237
  revision: number;
16214
16238
  visit: number;
16215
16239
  nodeId: string;
16216
- nodeType: "output" | "action" | "feature" | "split" | "condition" | "coupon" | "end" | "screen" | "offering" | "coupons" | "entry" | "external_page" | "wait";
16240
+ nodeType: "output" | "action" | "feature" | "split" | "condition" | "entry" | "coupon" | "end" | "screen" | "offering" | "coupons" | "external_page" | "wait";
16217
16241
  status: "failed" | "completed" | "running" | "closed" | "ineligible" | "waiting";
16218
16242
  stopped: boolean;
16219
16243
  canBack: boolean;
@@ -17633,7 +17657,7 @@ declare function createLocalFunnelClient(options: LocalFunnelClientOptions): Pro
17633
17657
  revision: number;
17634
17658
  visit: number;
17635
17659
  nodeId: string;
17636
- nodeType: "output" | "action" | "feature" | "split" | "condition" | "coupon" | "end" | "screen" | "offering" | "coupons" | "entry" | "external_page" | "wait";
17660
+ nodeType: "output" | "action" | "feature" | "split" | "condition" | "entry" | "coupon" | "end" | "screen" | "offering" | "coupons" | "external_page" | "wait";
17637
17661
  status: "failed" | "completed" | "running" | "closed" | "ineligible" | "waiting";
17638
17662
  stopped: boolean;
17639
17663
  canBack: boolean;
@@ -19598,7 +19622,7 @@ declare function createLocalFunnelClient(options: LocalFunnelClientOptions): Pro
19598
19622
  event: string;
19599
19623
  } | {
19600
19624
  type: "api";
19601
- operation: "update" | "attach" | "refund" | "readBalanceSource" | "adjustBalance" | "readUsage" | "setUsage" | "manageBalanceGrant" | "listBalanceGrants" | "restoreNativePurchase" | "setupPayment" | "readPaymentSetup" | "verifySubscriptions" | "previewAttach" | "readSubscriptionOperation" | "previewUpdate" | "readSubscriptionUpdate" | "previewRefund" | "readRefund" | "readBillingControls" | "prepareBillingAuthorization" | "confirmBillingAuthorization" | "setBillingCoupons" | "revokeBillingAuthorization" | "listBillingInvoices" | "confirmBillingAdjustment" | "manageBillingLimits" | "manageUsageEntity" | "readUsageAnalytics" | "readCreditAnalytics" | "submitUsageBatch" | "readUsageBatch" | "checkEntitlement" | "resolveOffering" | "readHoldings" | "readLedger" | "readBillingInvoice" | "readCreditStatement" | "quoteBalance" | "trackUsage" | "mutateBalance" | "redeemReward" | "createReferralCode" | "claimRewardProduct" | "readSeats" | "manageSeat" | "redeemCoupon" | "listOffers" | "grantOffer";
19625
+ operation: "update" | "attach" | "refund" | "sendMessage" | "readBalanceSource" | "adjustBalance" | "readUsage" | "setUsage" | "manageBalanceGrant" | "listBalanceGrants" | "restoreNativePurchase" | "setupPayment" | "readPaymentSetup" | "verifySubscriptions" | "previewAttach" | "readSubscriptionOperation" | "previewUpdate" | "readSubscriptionUpdate" | "previewRefund" | "readRefund" | "readBillingControls" | "prepareBillingAuthorization" | "confirmBillingAuthorization" | "setBillingCoupons" | "revokeBillingAuthorization" | "listBillingInvoices" | "confirmBillingAdjustment" | "manageBillingLimits" | "manageUsageEntity" | "readUsageAnalytics" | "readCreditAnalytics" | "submitUsageBatch" | "readUsageBatch" | "checkEntitlement" | "resolveOffering" | "readHoldings" | "readLedger" | "readBillingInvoice" | "readCreditStatement" | "quoteBalance" | "trackUsage" | "mutateBalance" | "redeemReward" | "createReferralCode" | "claimRewardProduct" | "readSeats" | "manageSeat" | "redeemCoupon" | "listOffers" | "grantOffer";
19602
19626
  inputs: Record<string, {
19603
19627
  source: "literal";
19604
19628
  value: zod.JSONType;
@@ -20301,6 +20325,11 @@ declare function createLocalFunnelClient(options: LocalFunnelClientOptions): Pro
20301
20325
  } | {
20302
20326
  type: "plans";
20303
20327
  planIds: string[];
20328
+ } | {
20329
+ type: "merchandise";
20330
+ scope: {
20331
+ type: "selected" | "all" | "condition";
20332
+ };
20304
20333
  };
20305
20334
  displayCopy: {
20306
20335
  defaultLocale: string;
@@ -20561,7 +20590,7 @@ declare function createLocalFunnelClient(options: LocalFunnelClientOptions): Pro
20561
20590
  entry: string;
20562
20591
  nodes: {
20563
20592
  id: string;
20564
- type: "output" | "action" | "feature" | "split" | "condition" | "coupon" | "end" | "screen" | "offering" | "coupons" | "entry" | "external_page" | "wait";
20593
+ type: "output" | "action" | "feature" | "split" | "condition" | "entry" | "coupon" | "end" | "screen" | "offering" | "coupons" | "external_page" | "wait";
20565
20594
  outputs: Record<string, string>;
20566
20595
  writes: Record<string, string>;
20567
20596
  resources: {
@@ -20635,7 +20664,7 @@ declare function createLocalFunnelClient(options: LocalFunnelClientOptions): Pro
20635
20664
  revision: number;
20636
20665
  visit: number;
20637
20666
  nodeId: string;
20638
- nodeType: "output" | "action" | "feature" | "split" | "condition" | "coupon" | "end" | "screen" | "offering" | "coupons" | "entry" | "external_page" | "wait";
20667
+ nodeType: "output" | "action" | "feature" | "split" | "condition" | "entry" | "coupon" | "end" | "screen" | "offering" | "coupons" | "external_page" | "wait";
20639
20668
  status: "failed" | "completed" | "running" | "closed" | "ineligible" | "waiting";
20640
20669
  stopped: boolean;
20641
20670
  canBack: boolean;
@@ -21668,7 +21697,7 @@ declare function createLocalFunnelClient(options: LocalFunnelClientOptions): Pro
21668
21697
  } | {
21669
21698
  type: "client_action";
21670
21699
  receiptId: string;
21671
- outcome: "success" | "failed" | "cancel" | "failure" | "opened";
21700
+ outcome: "success" | "failed" | "cancel" | "opened" | "failure";
21672
21701
  };
21673
21702
  requestId: string;
21674
21703
  nodeId: string;
@@ -21741,7 +21770,7 @@ declare function createLocalFunnelClient(options: LocalFunnelClientOptions): Pro
21741
21770
  } | {
21742
21771
  type: "client_action";
21743
21772
  receiptId: string;
21744
- outcome: "success" | "failed" | "cancel" | "failure" | "opened";
21773
+ outcome: "success" | "failed" | "cancel" | "opened" | "failure";
21745
21774
  };
21746
21775
  requestId: string;
21747
21776
  nodeId: string;
@@ -21801,7 +21830,7 @@ declare function createLocalFunnelClient(options: LocalFunnelClientOptions): Pro
21801
21830
  revision: number;
21802
21831
  visit: number;
21803
21832
  nodeId: string;
21804
- nodeType: "output" | "action" | "feature" | "split" | "condition" | "coupon" | "end" | "screen" | "offering" | "coupons" | "entry" | "external_page" | "wait";
21833
+ nodeType: "output" | "action" | "feature" | "split" | "condition" | "entry" | "coupon" | "end" | "screen" | "offering" | "coupons" | "external_page" | "wait";
21805
21834
  status: "failed" | "completed" | "running" | "closed" | "ineligible" | "waiting";
21806
21835
  stopped: boolean;
21807
21836
  canBack: boolean;
@@ -23482,7 +23511,7 @@ declare function createLocalFunnelClient(options: LocalFunnelClientOptions): Pro
23482
23511
  revision: number;
23483
23512
  visit: number;
23484
23513
  nodeId: string;
23485
- nodeType: "output" | "action" | "feature" | "split" | "condition" | "coupon" | "end" | "screen" | "offering" | "coupons" | "entry" | "external_page" | "wait";
23514
+ nodeType: "output" | "action" | "feature" | "split" | "condition" | "entry" | "coupon" | "end" | "screen" | "offering" | "coupons" | "external_page" | "wait";
23486
23515
  status: "failed" | "completed" | "running" | "closed" | "ineligible" | "waiting";
23487
23516
  stopped: boolean;
23488
23517
  canBack: boolean;
@@ -24901,7 +24930,7 @@ declare function createLocalFunnelClient(options: LocalFunnelClientOptions): Pro
24901
24930
  revision: number;
24902
24931
  visit: number;
24903
24932
  nodeId: string;
24904
- nodeType: "output" | "action" | "feature" | "split" | "condition" | "coupon" | "end" | "screen" | "offering" | "coupons" | "entry" | "external_page" | "wait";
24933
+ nodeType: "output" | "action" | "feature" | "split" | "condition" | "entry" | "coupon" | "end" | "screen" | "offering" | "coupons" | "external_page" | "wait";
24905
24934
  status: "failed" | "completed" | "running" | "closed" | "ineligible" | "waiting";
24906
24935
  stopped: boolean;
24907
24936
  canBack: boolean;
@@ -26318,7 +26347,7 @@ declare function createLocalFunnelClient(options: LocalFunnelClientOptions): Pro
26318
26347
  revision: number;
26319
26348
  visit: number;
26320
26349
  nodeId: string;
26321
- nodeType: "output" | "action" | "feature" | "split" | "condition" | "coupon" | "end" | "screen" | "offering" | "coupons" | "entry" | "external_page" | "wait";
26350
+ nodeType: "output" | "action" | "feature" | "split" | "condition" | "entry" | "coupon" | "end" | "screen" | "offering" | "coupons" | "external_page" | "wait";
26322
26351
  status: "failed" | "completed" | "running" | "closed" | "ineligible" | "waiting";
26323
26352
  stopped: boolean;
26324
26353
  canBack: boolean;
@@ -27738,7 +27767,7 @@ declare function createLocalFunnelClient(options: LocalFunnelClientOptions): Pro
27738
27767
  revision: number;
27739
27768
  visit: number;
27740
27769
  nodeId: string;
27741
- nodeType: "output" | "action" | "feature" | "split" | "condition" | "coupon" | "end" | "screen" | "offering" | "coupons" | "entry" | "external_page" | "wait";
27770
+ nodeType: "output" | "action" | "feature" | "split" | "condition" | "entry" | "coupon" | "end" | "screen" | "offering" | "coupons" | "external_page" | "wait";
27742
27771
  status: "failed" | "completed" | "running" | "closed" | "ineligible" | "waiting";
27743
27772
  stopped: boolean;
27744
27773
  canBack: boolean;
@@ -1 +1 @@
1
- import{a as X}from"./chunk-DSPLGTQI.js";import{a as le,b as ue,d as de}from"./chunk-YWFNWK7C.js";import"./chunk-AEUFCOFG.js";import{Qd as ae,bg as re}from"./chunk-F767CM3T.js";import{a as u}from"./chunk-6HG7U6AU.js";import{Hb as se}from"./chunk-3BQFJANQ.js";import"./chunk-AE4CUTUE.js";import"./chunk-EXCPE2XH.js";import"./chunk-RRII2DMC.js";import"./chunk-KQCTDXVD.js";function ce(e){let C=e.view;if(!C?.paywall)throw new u("INVALID_REQUEST","The current node is not a Paywall");let n=C.paywall.receiptId,P=C.nodeId,h=C.visit,o=C.paywall.resolution,k=o,s="document"in o?o:null;function v(i){if(!le(i,o))throw new u("INVALID_RESPONSE","The pinned Paywall binding changed")}let a=C.paywall.quote,R=C.paywall.operation,S=!1,T=new AbortController,l=C.paywall.purchaseRequestId,r=0,f=C.paywall.selectionGeneration??0,E=C.paywall.canReselect===!0,y=null,O=new Map,U=new Map;function G(i){if(i.purchase&&i.purchase.receiptId!==n)throw new u("INVALID_RESPONSE","Purchase receipt changed");let w=i.run.paywall;return i.purchase??(w?.receiptId===n?w:null)}function F(){if(S)throw new u("IDENTITY_CHANGED","Paywall presentation has closed")}function _(i,w,c){if(F(),w!==r||c!==void 0&&a?.operationId!==c)return!1;let I=f,d=i.run.paywall;if(d?.receiptId===n){if((d.selectionGeneration??0)<f)return!1;f=d.selectionGeneration??0,E=d.canReselect===!0,v(d.resolution)}let m=G(i),p=f>I,N=p?m?.quote??null:m?.quote??a,q=m?.operation??(N?.operationId===a?.operationId?R:null);return N&&q&&ue(q,{operationId:N.operationId},"Purchase operation changed"),d?.receiptId===n&&(k=d.resolution,s="document"in k?k:s?{...k,document:s.document,offering:s.offering}:null),(p||N?.operationId!==a?.operationId)&&(r++,d?.receiptId===n&&(l=d.purchaseRequestId)),a=N,R=de(R,q,!0),!0}function $(i,w,c){return new Promise((I,d)=>{let m=!1,p=()=>{clearTimeout(D),T.signal.removeEventListener("abort",J)},N=z=>{m||(m=!0,p(),I(z))},q=z=>{m||(m=!0,p(),d(z))},J=()=>q(new u("IDENTITY_CHANGED","Paywall presentation has closed")),D=setTimeout(()=>q(new u("COMMAND_PENDING","The purchase command is still pending; retry the original request",202,c)),Math.max(0,w-Date.now()));T.signal.addEventListener("abort",J,{once:!0}),T.signal.aborted&&J(),i.then(N,q)})}function j(i){return new Promise(w=>{let c=()=>{clearTimeout(I),T.signal.removeEventListener("abort",c),w()},I=setTimeout(c,i);T.signal.addEventListener("abort",c,{once:!0}),T.signal.aborted&&c()})}async function A(i,w,c){F();let I=O.get(i);if(!I){let p=e.pendingCommands?.find(N=>N.requestId===i)??e.pendingCommand;if(p?.operation==="submit"&&p.requestId===i&&p.nodeId===P&&p.visit===h){w.type==="paywall_quote"&&p.input.type==="paywall_quote"&&p.input.predecessor&&!w.predecessor&&(w={...w,predecessor:p.input.predecessor});let N=re.parse(p),q=re.parse({...p,input:w});if(q.operation!=="submit"||N.operation!=="submit"||JSON.stringify(q.input)!==JSON.stringify(N.input))throw new u("CONFLICT","A restored purchase request cannot change its input");w=q.input,I=N,O.set(i,I)}}if(I){if(JSON.stringify(I.input)!==JSON.stringify(w))throw new u("CONFLICT","A purchase request cannot change its input")}else{let p=e.view;if(!p||p.nodeId!==P||p.visit!==h||p.paywall?.receiptId!==n)throw new u("PRECONDITION_FAILED","The Paywall visit has changed");I={operation:"submit",requestId:i,nodeId:P,visit:h,revision:p.revision,input:w},O.set(i,I)}let d=Date.now()+3e4,m=await $(e.submit(I),d,i);for(;m.run.pendingRequest?.requestId===i&&Date.now()<d&&!S&&(await j(Math.min(1e3,d-Date.now())),!(S||Date.now()>=d));)m=await $(e.resume(i),d,i);if(S)throw new u("IDENTITY_CHANGED","Paywall presentation has closed");if(m.run.pendingRequest?.requestId===i)throw new u("COMMAND_PENDING","The purchase command is still pending; retry the original request",202,i);if(!_(m,c,w.type==="paywall_confirm"||w.type==="paywall_cancel"?w.operationId:void 0))throw new u("PRECONDITION_FAILED","The purchase selection has changed")}async function Q(i){if(!a)throw new u("INVALID_REQUEST","A quoted purchase is required");let w=`${i}:${a.operationId}`,c=U.get(w);if(!c){let I=i==="confirm"?"paywall_confirm":"paywall_cancel",d=e.pendingCommands?.find(m=>m.operation==="submit"&&m.input.type===I&&"operationId"in m.input&&m.input.operationId===a.operationId)??e.pendingCommand;c=d?.operation==="submit"&&d.input.type===I&&"operationId"in d.input&&d.input.operationId===a.operationId?d.requestId:crypto.randomUUID(),U.set(w,c)}if(await A(c,{type:i==="confirm"?"paywall_confirm":"paywall_cancel",operationId:a.operationId},r),!R)throw new u("INVALID_RESPONSE","The accepted purchase result is missing");return structuredClone(R)}return{get view(){return structuredClone(s)},get quote(){return a?structuredClone(a):null},get operation(){return R?structuredClone(R):null},get webViewUrl(){return e.webViewUrl},get canReselect(){return E},async refresh(){F();let i=r,w=await e.get();if(_(w,i),w.run.paywall?.receiptId!==n)throw new u("PRECONDITION_FAILED","Paywall presentation has changed");if(!s){if("document"in k||!e.resolvePaywall)throw new u("INVALID_RESPONSE","Public Paywall reader is unavailable");let c=await e.resolvePaywall(k);F(),v(c),s={...k,document:c.document,offering:c.offering}}return structuredClone(s)},preview(i){if(!s)return Promise.reject(new u("PRECONDITION_FAILED","Load the Paywall presentation first"));if(l&&l!==i.requestId&&(y||!E))return Promise.reject(new u("COMMAND_PENDING","Retry the original purchase before starting another"));if(l===i.requestId&&y)return y;let w=s.document.buttons[i.actionId],c=w?.type==="checkout"?ae(w.product,i.selection,s.capabilities):null;if(!c)return Promise.reject(new u("PRODUCT_UNAVAILABLE","Choose an available Product in this purchase area"));let I=l!==i.requestId&&f>0?{operationId:a?.operationId??null,generation:f}:void 0;if(I&&(!E||f<=0))return Promise.reject(new u("COMMAND_PENDING","Original purchase requires authoritative termination"));l!==i.requestId&&r++;let d=r;l=i.requestId;let m=(async()=>{if(await A(i.requestId,{type:"paywall_quote",actionId:i.actionId,productVersionId:c,...I?{predecessor:I}:{},...i.offerId?{offerId:i.offerId}:{},...i.nativeOffer?{nativeOffer:i.nativeOffer}:{}},d),!a)throw new u("INVALID_RESPONSE","The accepted quote is missing");return structuredClone(a)})();return y=m,m.then(()=>{y===m&&(y=null)},p=>{y===m&&(y=null),l===i.requestId&&e.pendingCommand?.requestId!==i.requestId&&p instanceof u&&p.status!==void 0&&p.status<500&&![401,425].includes(p.status)&&(l=null)}),m},confirm:()=>Q("confirm"),cancel:()=>Q("cancel"),async read(){if(F(),!a)throw new u("INVALID_REQUEST","A quoted purchase is required");let i=a.operationId,w=r,c=e.pendingCommands?.find(p=>p.operation==="submit"&&(p.input.type==="paywall_confirm"||p.input.type==="paywall_cancel")&&p.input.operationId===i)??e.pendingCommand;c?.operation==="submit"&&(c.input.type==="paywall_confirm"||c.input.type==="paywall_cancel")&&c.input.operationId===i&&await e.settle?.(c.requestId);let I=await e.get(void 0,{receiptId:n,operationId:i});F();let d=G(I);if(d?.quote&&d.quote.operationId!==i||d?.operation&&d.operation.operationId!==i)throw new u("INVALID_RESPONSE","Purchase operation changed");let m=_(I,w,i)?R:d?.operation;if(!m)throw new u("INVALID_RESPONSE","The current purchase result is missing");return structuredClone(m)},destroy(){S=!0,T.abort(),O.clear(),U.clear()}}}function pe(e){let C=new Set,n=new Set,P=null;function h(o){if(e.reviewing||C.has(o)||n.has(o)||e.stopped)return;n.add(o);let k=async()=>{if(e.reviewing||e.stopped||e.key!==o){n.delete(o);return}if(e.busy||e.client.pendingCommand){setTimeout(()=>{k()},250);return}let s=(async()=>{let a=e.client.view,R=e.expected(),S=R.requestId,T=!1;try{await e.client.submit({operation:"shown",...R})}catch(l){if(!(l instanceof u)||l.code!=="CONFLICT"||l.status!==409||e.client.pendingCommand)throw l;await e.client.get();let r=e.client.view;if(e.stopped||e.reviewing||e.key!==o||!r||!a||r.id!==a.id||r.source.versionId!==a.source.versionId||r.nodeId!==R.nodeId||r.visit!==R.visit||r.revision<=R.revision||r.stopped||!r.screen||!["running","waiting"].includes(r.status)||e.client.pendingCommand)throw l;let f=e.expected();S=f.requestId,await e.client.submit({operation:"shown",...f})}for(;!e.stopped&&e.key===o&&e.client.pendingCommand?.requestId===S;){if(!e.client.settle)throw new u("COMMAND_PENDING","The original display acknowledgement is still pending");await e.client.settle(S),T=!0,e.client.pendingCommand?.requestId===S&&await new Promise(l=>setTimeout(l,1500))}e.stopped||e.key!==o||(T&&await e.client.get(),!(e.stopped||e.key!==o)&&C.add(o))})();P=s;let v=()=>{P===s&&(P=null),n.delete(o)};s.then(v,a=>{v(),e.busy||e.fail(a)})};k()}return{report:h,get inFlight(){return P}}}function fe(e){let C={},n=new Map;async function P(h){let o=e.client.view,k=o?.screen,s=k?.customerData.nodes[h.nodeId];if(e.stopped||e.busy||!o||!k||!s)return;if(!["refresh","next","previous","filter","sources_next","sources_previous"].includes(h.action)){let r=e.document,f=r?se(r,h.nodeId):null,E=f?.type==="customer_data"?f.data.outputs?.[h.action]:void 0;E&&k.outputs.includes(E)?await e.perform(()=>e.client.submit({operation:"submit",...e.expected(),input:{type:"screen",output:E,answers:e.answers,selection:h.value?{[h.nodeId]:h.value}:{}}})):await e.onIntent?.(h,o);return}let a=h.action.startsWith("sources_")?s.resources.find(r=>r.key===h.value):null;if(h.action.startsWith("sources_")&&!a)throw new u("INVALID_REQUEST","Choose a current resource");let R=`${o.visit}:${h.nodeId}:${a?.key??""}`,S=n.get(R)??[null],l=C[h.nodeId]??{page:1,after:null,filter:"all",...a?{resourceKey:a.key}:{}};if(h.action==="filter"){let r=h.value;if(!r||!(s.source==="offer_history"?["all","issued","reserved","redeemed","expired","revoked"]:["all","purchase","refund","source","usage","debt","settlement"]).includes(r))throw new u("INVALID_REQUEST","Unknown data filter");l={page:1,after:null,filter:r},S.splice(0,S.length,null)}else if(h.action==="next"||h.action==="sources_next"){let r=a?.sources.at(-1),f=a?r?{kind:"ledger",cursor:{at:r.detail[0],id:r.id,type:"source"}}:null:k.dataCursors[h.nodeId];if(!f||!a&&!s.hasNext)return;S[l.page]=f,l={...l,page:l.page+1,after:f}}else if(h.action==="previous"||h.action==="sources_previous"){if(l.page<=1)return;l={...l,page:l.page-1,after:S[l.page-2]??null}}n.set(R,S),C={...C,[h.nodeId]:l},await e.perform(()=>e.client.get({nodeId:o.nodeId,visit:o.visit,revision:o.revision,components:C}))}return{get queries(){return C},intent:P,reset(){C={},n.clear()}}}function we(e){let{doc:C,holder:n,reviewHolder:P,mountScreenPreview:h}=e,o=!1,k,s=0,v=null,a="",R=new Map,S=r=>r?`${r.id}:${r.nodeId}:${r.visit}:${r.revision}:${r.paywall?.quote?.operationId??""}`:"";async function T(r){if(e.stopped||!e.client.review)return;o||(a=S(e.client.view),R.set(a,structuredClone(e.answers))),o=!0,k=r,n.hidden=!0,e.suspend(!0),P.hidden=!1;let f=++s;try{let E=await e.client.review(r);if(e.stopped||f!==s||!o)return;if(!E.review)throw new u("INVALID_RESPONSE","Historical projection is missing");v?.destroy(),v=null,P.replaceChildren();let y=E.run.locale.startsWith("zh"),O=C.createElement("p");O.textContent=y?"\u53EA\u8BFB\u56DE\u770B":"Read-only history",P.append(O);for(let[F,_]of E.review.pages.entries()){let $=C.createElement("button");$.type="button",$.textContent=y?`\u7B2C ${F+1} \u9875`:`Page ${F+1}`,$.onclick=()=>{T(_.receiptId)},P.append($)}if(E.review.page){let F=E.review.page,_=C.createElement("div");if(_.inert=!0,P.append(_),v=h(_,{mode:"live",rendererUrl:e.client.webViewUrl,title:F.document.name,onAction:()=>{},onAnswers:()=>{},onCustomerDataIntent:()=>{},onRendered:()=>{},onEscape:()=>{l()}}),v.update(F.document,E.run.locale,{serverInput:{bindings:F.inputs,answers:F.answers,values:F.values}}),await v.ready,e.stopped||f!==s||!o)return}let U=y?{issued:"\u5DF2\u9886\u53D6",reserved:"\u5DF2\u9884\u7559",redeemed:"\u5DF2\u4F7F\u7528",expired:"\u5DF2\u8FC7\u671F",revoked:"\u5DF2\u64A4\u9500",unknown:"\u72B6\u6001\u5F85\u786E\u8BA4"}:{issued:"Issued",reserved:"Reserved",redeemed:"Used",expired:"Expired",revoked:"Revoked",unknown:"Status unconfirmed"},G=y?{pending:"\u5904\u7406\u4E2D",complete:"\u5DF2\u5B8C\u6210",cancelled:"\u5DF2\u53D6\u6D88",failed:"\u5931\u8D25",unknown:"\u72B6\u6001\u5F85\u786E\u8BA4"}:{pending:"Processing",complete:"Completed",cancelled:"Cancelled",failed:"Failed",unknown:"Status unconfirmed"};for(let F of[...E.review.coupons.map((_,$)=>`${y?"\u4F18\u60E0\u5238":"Coupon"} ${$+1}: ${U[_.status]}`),...E.review.purchases.map((_,$)=>`${y?"\u8D2D\u4E70":"Purchase"} ${$+1}: ${G[_.status]}`)]){let _=C.createElement("p");_.textContent=F,P.append(_)}e.client.view&&await e.enqueue(e.client.view)}catch(E){if(f!==s||e.stopped)return;v?.destroy(),v=null,P.replaceChildren(),e.fail(E)}}async function l(){if(!o||e.stopped||!e.client.review)return;let r=++s;try{if(await e.client.review(),e.stopped||r!==s)return;o=!1,s++,v?.destroy(),v=null,P.replaceChildren(),P.hidden=!0,n.hidden=!1;let f=e.client.view;S(f)!==a?(R.set(a,structuredClone(e.answers)),e.resetScreen()):(R.delete(a),e.suspend(!1)),f&&await e.enqueue(f)}catch(f){if(r!==s||e.stopped)return;v?.destroy(),v=null,P.replaceChildren(),e.fail(f)}}return{get active(){return o},get receipt(){return k},open:T,exit:l,get drafts(){return new Map([...R].map(([r,f])=>[r,structuredClone(f)]))},stop(){o=!1,s++,v?.destroy(),v=null,P.replaceChildren(),P.hidden=!0,n.hidden=!1}}}async function Ue(e,C){let n=C,{mountScreenPreview:P}=await import("./screen-renderer-P7MLBHY5.js"),{showPaywall:h}=await import("./paywall-MXRMMF3R.js"),o=e.ownerDocument,k=o.activeElement,s=o.createElement("section"),v=o.createElement("div"),a=o.createElement("div"),R=o.createElement("div"),S=o.createElement("button");R.hidden=!0,S.type="button";let T=o.createElement("p"),l=o.createElement("p"),r=o.createElement("button"),f=o.createElement("button"),E=o.createElement("button"),y=o.createElement("dialog");s.dataset.indianaFunnel="",s.setAttribute("aria-busy","false"),s.style.cssText="box-sizing:border-box;width:100%;min-width:0;font:14px/1.5 system-ui,sans-serif;color:#172033;background:#fff",a.style.cssText="display:flex;gap:12px;align-items:center;flex-wrap:wrap;padding:12px 20px",T.setAttribute("role","status"),l.setAttribute("role","alert"),l.hidden=!0,r.type=f.type=E.type="button",a.append(r,T,l,E,S,f),s.append(v,R,a),e.append(s);let O=null,U=null,G=null,F="",_="",$="",j="",A=!1,Q=0,i=!1,w="",c=null,I=Promise.resolve(),d=null,m=null,p=new Set,N={},q=(t,g=null)=>{A||(m=g,l.textContent=t instanceof Error?t.message:"Request failed",l.hidden=!1,E.hidden=n.client.pendingCommand===null,X(n.onError,t))};function J(){let t=n.client.view;if(!t)throw new u("INVALID_REQUEST","No current Run is available");return{requestId:crypto.randomUUID(),nodeId:t.nodeId,visit:t.visit,revision:t.revision}}let D=we({client:n.client,doc:o,holder:v,reviewHolder:R,mountScreenPreview:P,get stopped(){return A},get answers(){return N},suspend(t){U?.setSuspended(t)},resetScreen(){F="",_=""},enqueue:W,fail:q}),z=pe({client:n.client,expected:J,fail:q,get stopped(){return A},get reviewing(){return D.active},get key(){return F},get busy(){return Q}}),Z=fe({client:n.client,expected:J,perform:B,onIntent:n.onCustomerDataIntent,get stopped(){return A},get busy(){return Q},get document(){return O?.document},get answers(){return N}});async function B(t,g=!1){if(!(Q&&!g||A||D.active&&!g)){Q++,s.setAttribute("aria-busy","true"),l.hidden=!0,m=null;try{if(!g&&z.inFlight){let b=n.client.view;await z.inFlight;let L=n.client.view;if(!b||!L||L.id!==b.id||L.nodeId!==b.nodeId||L.visit!==b.visit||L.stopped||!["running","waiting"].includes(L.status))throw new u("PRECONDITION_FAILED","The screen changed while its display was acknowledged")}if(A)return;let M=await t();A||await W(n.client.view??M.run)}catch(M){q(M,n.client.pendingCommand?.requestId??null)}finally{Q=Math.max(0,Q-1),s.setAttribute("aria-busy",String(Q>0)),A||(E.hidden=n.client.pendingCommand===null,r.disabled=Q>0||!!n.client.pendingCommand||!n.client.view?.canBack)}}}function x(){c&&clearTimeout(c),!(A||!G||!["running","waiting"].includes(G.status)&&!n.client.pendingCommand)&&(c=setTimeout(()=>{c=null,oe().finally(x)},G.pendingRequest||n.client.pendingCommand?1500:5e3))}async function oe(){if(!(A||i||Q)){if(D.active){await D.open(D.receipt);return}i=!0;try{let t=n.client.pendingCommand;t&&n.client.settle&&await n.client.settle(t.requestId);let g=n.client.view,M=Z.queries,b=await n.client.get(g?.screen&&Object.keys(M).length?{nodeId:g.nodeId,visit:g.visit,revision:g.revision,components:M}:void 0);!A&&M===Z.queries&&await W(n.client.view??b.run)}catch(t){q(t)}finally{i=!1}}}function me(t){let g=t.screen?.presentation;if(!g||g.type==="inline"){y.open&&y.close(),s.parentElement!==e&&e.append(s);return}s.parentElement!==y&&(y.append(s),e.append(y));let M={sm:420,md:640,lg:900};y.style.cssText=`padding:0;border:0;max-width:calc(100vw - 32px);max-height:calc(100dvh - 32px);overflow:auto;width:${"size"in g?M[g.size]+"px":"100vw"}`,y.setAttribute("aria-label",O?.document?.name??t.screen?.content.document.name??"Funnel"),y.open||y.showModal()}async function ye(t){if(A)return;G=t,m&&n.client.pendingCommand?.requestId!==m&&(l.hidden=!0,m=null);let g=t.locale.startsWith("zh");if(S.textContent=g?"\u56DE\u770B":"History",S.hidden=!n.client.review,r.textContent=D.active?g?"\u8FD4\u56DE\u5F53\u524D":"Return to current":g?"\u8FD4\u56DE":"Back",f.textContent=g?"\u5173\u95ED":"Close",E.textContent=g?"\u91CD\u8BD5":"Retry",r.disabled=!D.active&&(Q>0||!!n.client.pendingCommand||!t.canBack),E.hidden=n.client.pendingCommand===null,T.textContent=t.pendingRequest?g?"\u6B63\u5728\u5904\u7406":"Processing":t.instruction?.type==="wait"?g?"\u7B49\u5F85\u4E2D":"Waiting":"",w!==`${t.revision}:${t.visit}:${t.status}:${t.stopped}`&&(w=`${t.revision}:${t.visit}:${t.status}:${t.stopped}`,X(n.onState,structuredClone(t))),t.stopped||n.client.configurationReady===!1){D.stop(),O?.destroy(),O=null,U?.destroy(),U=null,v.replaceChildren(),F="",_="",j="",y.open&&y.close(),s.hidden=!0,x();return}if(s.hidden=!1,D.active){x();return}let M=t.screen||t.paywall?`${t.id}:${t.nodeId}:${t.visit}`:"";if(M!==F&&(O?.destroy(),O=null,U?.destroy(),U=null,v.replaceChildren(),F=M,_="",j="",N={...t.answers},Z.reset()),me(t),t.screen){let L=t.screen.content;O||(O=P(v,{mode:"live",rendererUrl:n.client.webViewUrl,title:L.document.name,onAction(H,te={},ie={}){if(D.active)return;N={...N,...ie};let Ie=Object.fromEntries((t.screen?.inputs??[]).filter(({variable:ne})=>Object.hasOwn(N,ne)).map(({variable:ne})=>[ne,N[ne]]));B(()=>n.client.submit({operation:"submit",...J(),input:{type:"screen",output:H,answers:Ie,selection:te}}))},onAnswers:H=>{D.active||(N={...N,...H})},onCustomerDataIntent:H=>{D.active||Z.intent(H).catch(q)},onEscape:()=>{D.active||K()},onError:H=>q(new Error(H)),onRendered:()=>z.report(M)}));let V={capabilities:t.screen.capabilities,customerData:t.screen.customerData,parameters:t.parameters,serverInput:{bindings:t.screen.inputs,answers:N,values:t.screen.values}},Y=JSON.stringify([L,t.locale,V.parameters,t.screen.inputs,t.screen.values]);if(Y!==_)O.update(L.document,t.locale,V),_=Y,$=JSON.stringify(V.capabilities),j=JSON.stringify(V.customerData);else{let H=JSON.stringify(V.capabilities);H!==$&&(O.updateCapabilities(V.capabilities),$=H),JSON.stringify(V.customerData)!==j&&(O.updateCustomerData(V.customerData),j=JSON.stringify(V.customerData))}await O.ready}else if(t.paywall&&!U){let L=await h(v,{canInteract:()=>!D.active&&!A,start:async()=>ce(n.client),onPurchase:n.onPurchase,onCheckoutUrl:n.onCheckoutUrl,resolveOfferId:n.resolveOfferId,onEvent:n.onEvent,onOpenUrl:V=>n.onOpenUrl?n.onOpenUrl({receiptId:t.paywall.receiptId,url:V,openIn:"same_window"}):o.defaultView?.location.assign(V),onAction:async V=>{if(D.active)return;let Y=await n.client.submit({operation:"submit",requestId:crypto.randomUUID(),nodeId:t.nodeId,visit:t.visit,revision:t.revision,input:{type:"screen",output:V,answers:{}}});await W(n.client.view??Y.run)},onError:q,onDismiss:()=>{!D.active&&!A&&n.client.view?.visit===t.visit&&K()}});A?L.host?.destroy():(U=L.host,U?.setSuspended(D.active)),z.report(M)}let b=t.instruction;if(b&&(b.type==="open_url"||b.type==="event")&&!p.has(b.receiptId)){let L=o.createElement("button");L.type="button",L.textContent=b.type==="open_url"?`${g?"\u524D\u5F80":"Continue to"} ${new URL(b.url).host}`:g?"\u7EE7\u7EED":"Continue",L.onclick=()=>{let V=J(),Y=b.type==="open_url"&&!n.onOpenUrl&&b.openIn==="new_window"?he(b.url):null;B(async()=>{let H="success";if(b.type==="open_url")if(n.onOpenUrl)try{H=await n.onOpenUrl({receiptId:b.receiptId,url:b.url,openIn:b.openIn})===!1?"failed":"opened"}catch(ie){X(n.onError,ie),H="failed"}else H=b.openIn==="new_window"&&!Y?"failed":"opened";if(b.type==="event"){if(!n.onEvent)throw new u("EVENT_HANDLER_REQUIRED","Provide the event handler");await n.onEvent(b.event)}if(A||n.client.view?.nodeId!==V.nodeId||n.client.view.visit!==V.visit)throw new u("PRECONDITION_FAILED","The client action visit changed");let te=await n.client.submit({operation:"submit",...V,input:{type:"client_action",receiptId:b.receiptId,outcome:H}});return p.add(b.receiptId),b.type==="open_url"&&!n.onOpenUrl&&b.openIn==="same_window"&&o.defaultView?.location.assign(b.url),te})},v.replaceChildren(L)}!t.pendingRequest&&t.status==="completed"&&!p.has(`complete:${t.id}`)&&(p.add(`complete:${t.id}`),X(n.onComplete,structuredClone(t))),x()}function he(t){let g=o.defaultView?.open(t,"_blank")??null;return g&&(g.opener=null),g}function W(t){return I=I.catch(()=>{}).then(()=>ye(t)),I}let ve=n.client.subscribe(t=>{n.client.configurationReady===!1&&(s.hidden=!0,O?.destroy(),O=null,U?.destroy(),U=null,v.replaceChildren(),F="",_="",j="",y.open&&y.close()),W(t).catch(q)}),ge=n.client.subscribeError?.(q);function K(){return d||(A?Promise.resolve():n.client.view&&!["running","waiting"].includes(n.client.view.status)?(ee(),Promise.resolve()):(d=B(()=>n.client.submit({operation:"close",...J()}),!0).then(()=>{n.client.view?.status==="closed"&&ee()}).finally(()=>{d=null}),d))}function ee(){A||(A=!0,c&&clearTimeout(c),ve(),ge?.(),O?.destroy(),D.stop(),U?.destroy(),y.close(),y.remove(),s.remove(),k instanceof HTMLElement&&k.isConnected&&k.focus(),X(n.onDismiss,G?structuredClone(G):null))}r.onclick=()=>{if(D.active){D.exit();return}B(()=>n.client.submit({operation:"back",...J()}))},S.onclick=()=>{D.open()},f.onclick=()=>{K()},E.onclick=()=>{B(()=>n.client.retry())},y.addEventListener("cancel",t=>{t.preventDefault(),K()});try{let t=await n.client.get();await W(n.client.view??t.run)}catch(t){throw ee(),t}return{destroy:ee,refresh:oe,review:D.open,exitReview:D.exit,get unappliedDrafts(){return D.drafts}}}export{Ue as showFunnelRun};
1
+ import{a as le,b as ue,d as de}from"./chunk-GRLMT5PR.js";import"./chunk-SSHUBTT3.js";import{Je as ae,Vg as re}from"./chunk-EJTBSGLV.js";import{a as u}from"./chunk-SOQO2RDZ.js";import{Hb as se}from"./chunk-LMR2TM3X.js";import{a as X}from"./chunk-DSPLGTQI.js";import"./chunk-OBYJWIRB.js";import"./chunk-EXCPE2XH.js";import"./chunk-RRII2DMC.js";import"./chunk-KQCTDXVD.js";function ce(e){let C=e.view;if(!C?.paywall)throw new u("INVALID_REQUEST","The current node is not a Paywall");let n=C.paywall.receiptId,P=C.nodeId,h=C.visit,o=C.paywall.resolution,k=o,s="document"in o?o:null;function v(i){if(!le(i,o))throw new u("INVALID_RESPONSE","The pinned Paywall binding changed")}let a=C.paywall.quote,R=C.paywall.operation,S=!1,T=new AbortController,l=C.paywall.purchaseRequestId,r=0,f=C.paywall.selectionGeneration??0,E=C.paywall.canReselect===!0,y=null,O=new Map,U=new Map;function G(i){if(i.purchase&&i.purchase.receiptId!==n)throw new u("INVALID_RESPONSE","Purchase receipt changed");let w=i.run.paywall;return i.purchase??(w?.receiptId===n?w:null)}function F(){if(S)throw new u("IDENTITY_CHANGED","Paywall presentation has closed")}function _(i,w,c){if(F(),w!==r||c!==void 0&&a?.operationId!==c)return!1;let I=f,d=i.run.paywall;if(d?.receiptId===n){if((d.selectionGeneration??0)<f)return!1;f=d.selectionGeneration??0,E=d.canReselect===!0,v(d.resolution)}let m=G(i),p=f>I,N=p?m?.quote??null:m?.quote??a,q=m?.operation??(N?.operationId===a?.operationId?R:null);return N&&q&&ue(q,{operationId:N.operationId},"Purchase operation changed"),d?.receiptId===n&&(k=d.resolution,s="document"in k?k:s?{...k,document:s.document,offering:s.offering}:null),(p||N?.operationId!==a?.operationId)&&(r++,d?.receiptId===n&&(l=d.purchaseRequestId)),a=N,R=de(R,q,!0),!0}function $(i,w,c){return new Promise((I,d)=>{let m=!1,p=()=>{clearTimeout(D),T.signal.removeEventListener("abort",J)},N=z=>{m||(m=!0,p(),I(z))},q=z=>{m||(m=!0,p(),d(z))},J=()=>q(new u("IDENTITY_CHANGED","Paywall presentation has closed")),D=setTimeout(()=>q(new u("COMMAND_PENDING","The purchase command is still pending; retry the original request",202,c)),Math.max(0,w-Date.now()));T.signal.addEventListener("abort",J,{once:!0}),T.signal.aborted&&J(),i.then(N,q)})}function j(i){return new Promise(w=>{let c=()=>{clearTimeout(I),T.signal.removeEventListener("abort",c),w()},I=setTimeout(c,i);T.signal.addEventListener("abort",c,{once:!0}),T.signal.aborted&&c()})}async function A(i,w,c){F();let I=O.get(i);if(!I){let p=e.pendingCommands?.find(N=>N.requestId===i)??e.pendingCommand;if(p?.operation==="submit"&&p.requestId===i&&p.nodeId===P&&p.visit===h){w.type==="paywall_quote"&&p.input.type==="paywall_quote"&&p.input.predecessor&&!w.predecessor&&(w={...w,predecessor:p.input.predecessor});let N=re.parse(p),q=re.parse({...p,input:w});if(q.operation!=="submit"||N.operation!=="submit"||JSON.stringify(q.input)!==JSON.stringify(N.input))throw new u("CONFLICT","A restored purchase request cannot change its input");w=q.input,I=N,O.set(i,I)}}if(I){if(JSON.stringify(I.input)!==JSON.stringify(w))throw new u("CONFLICT","A purchase request cannot change its input")}else{let p=e.view;if(!p||p.nodeId!==P||p.visit!==h||p.paywall?.receiptId!==n)throw new u("PRECONDITION_FAILED","The Paywall visit has changed");I={operation:"submit",requestId:i,nodeId:P,visit:h,revision:p.revision,input:w},O.set(i,I)}let d=Date.now()+3e4,m=await $(e.submit(I),d,i);for(;m.run.pendingRequest?.requestId===i&&Date.now()<d&&!S&&(await j(Math.min(1e3,d-Date.now())),!(S||Date.now()>=d));)m=await $(e.resume(i),d,i);if(S)throw new u("IDENTITY_CHANGED","Paywall presentation has closed");if(m.run.pendingRequest?.requestId===i)throw new u("COMMAND_PENDING","The purchase command is still pending; retry the original request",202,i);if(!_(m,c,w.type==="paywall_confirm"||w.type==="paywall_cancel"?w.operationId:void 0))throw new u("PRECONDITION_FAILED","The purchase selection has changed")}async function Q(i){if(!a)throw new u("INVALID_REQUEST","A quoted purchase is required");let w=`${i}:${a.operationId}`,c=U.get(w);if(!c){let I=i==="confirm"?"paywall_confirm":"paywall_cancel",d=e.pendingCommands?.find(m=>m.operation==="submit"&&m.input.type===I&&"operationId"in m.input&&m.input.operationId===a.operationId)??e.pendingCommand;c=d?.operation==="submit"&&d.input.type===I&&"operationId"in d.input&&d.input.operationId===a.operationId?d.requestId:crypto.randomUUID(),U.set(w,c)}if(await A(c,{type:i==="confirm"?"paywall_confirm":"paywall_cancel",operationId:a.operationId},r),!R)throw new u("INVALID_RESPONSE","The accepted purchase result is missing");return structuredClone(R)}return{get view(){return structuredClone(s)},get quote(){return a?structuredClone(a):null},get operation(){return R?structuredClone(R):null},get webViewUrl(){return e.webViewUrl},get canReselect(){return E},async refresh(){F();let i=r,w=await e.get();if(_(w,i),w.run.paywall?.receiptId!==n)throw new u("PRECONDITION_FAILED","Paywall presentation has changed");if(!s){if("document"in k||!e.resolvePaywall)throw new u("INVALID_RESPONSE","Public Paywall reader is unavailable");let c=await e.resolvePaywall(k);F(),v(c),s={...k,document:c.document,offering:c.offering}}return structuredClone(s)},preview(i){if(!s)return Promise.reject(new u("PRECONDITION_FAILED","Load the Paywall presentation first"));if(l&&l!==i.requestId&&(y||!E))return Promise.reject(new u("COMMAND_PENDING","Retry the original purchase before starting another"));if(l===i.requestId&&y)return y;let w=s.document.buttons[i.actionId],c=w?.type==="checkout"?ae(w.product,i.selection,s.capabilities):null;if(!c)return Promise.reject(new u("PRODUCT_UNAVAILABLE","Choose an available Product in this purchase area"));let I=l!==i.requestId&&f>0?{operationId:a?.operationId??null,generation:f}:void 0;if(I&&(!E||f<=0))return Promise.reject(new u("COMMAND_PENDING","Original purchase requires authoritative termination"));l!==i.requestId&&r++;let d=r;l=i.requestId;let m=(async()=>{if(await A(i.requestId,{type:"paywall_quote",actionId:i.actionId,productVersionId:c,...I?{predecessor:I}:{},...i.offerId?{offerId:i.offerId}:{},...i.nativeOffer?{nativeOffer:i.nativeOffer}:{}},d),!a)throw new u("INVALID_RESPONSE","The accepted quote is missing");return structuredClone(a)})();return y=m,m.then(()=>{y===m&&(y=null)},p=>{y===m&&(y=null),l===i.requestId&&e.pendingCommand?.requestId!==i.requestId&&p instanceof u&&p.status!==void 0&&p.status<500&&![401,425].includes(p.status)&&(l=null)}),m},confirm:()=>Q("confirm"),cancel:()=>Q("cancel"),async read(){if(F(),!a)throw new u("INVALID_REQUEST","A quoted purchase is required");let i=a.operationId,w=r,c=e.pendingCommands?.find(p=>p.operation==="submit"&&(p.input.type==="paywall_confirm"||p.input.type==="paywall_cancel")&&p.input.operationId===i)??e.pendingCommand;c?.operation==="submit"&&(c.input.type==="paywall_confirm"||c.input.type==="paywall_cancel")&&c.input.operationId===i&&await e.settle?.(c.requestId);let I=await e.get(void 0,{receiptId:n,operationId:i});F();let d=G(I);if(d?.quote&&d.quote.operationId!==i||d?.operation&&d.operation.operationId!==i)throw new u("INVALID_RESPONSE","Purchase operation changed");let m=_(I,w,i)?R:d?.operation;if(!m)throw new u("INVALID_RESPONSE","The current purchase result is missing");return structuredClone(m)},destroy(){S=!0,T.abort(),O.clear(),U.clear()}}}function pe(e){let C=new Set,n=new Set,P=null;function h(o){if(e.reviewing||C.has(o)||n.has(o)||e.stopped)return;n.add(o);let k=async()=>{if(e.reviewing||e.stopped||e.key!==o){n.delete(o);return}if(e.busy||e.client.pendingCommand){setTimeout(()=>{k()},250);return}let s=(async()=>{let a=e.client.view,R=e.expected(),S=R.requestId,T=!1;try{await e.client.submit({operation:"shown",...R})}catch(l){if(!(l instanceof u)||l.code!=="CONFLICT"||l.status!==409||e.client.pendingCommand)throw l;await e.client.get();let r=e.client.view;if(e.stopped||e.reviewing||e.key!==o||!r||!a||r.id!==a.id||r.source.versionId!==a.source.versionId||r.nodeId!==R.nodeId||r.visit!==R.visit||r.revision<=R.revision||r.stopped||!r.screen||!["running","waiting"].includes(r.status)||e.client.pendingCommand)throw l;let f=e.expected();S=f.requestId,await e.client.submit({operation:"shown",...f})}for(;!e.stopped&&e.key===o&&e.client.pendingCommand?.requestId===S;){if(!e.client.settle)throw new u("COMMAND_PENDING","The original display acknowledgement is still pending");await e.client.settle(S),T=!0,e.client.pendingCommand?.requestId===S&&await new Promise(l=>setTimeout(l,1500))}e.stopped||e.key!==o||(T&&await e.client.get(),!(e.stopped||e.key!==o)&&C.add(o))})();P=s;let v=()=>{P===s&&(P=null),n.delete(o)};s.then(v,a=>{v(),e.busy||e.fail(a)})};k()}return{report:h,get inFlight(){return P}}}function fe(e){let C={},n=new Map;async function P(h){let o=e.client.view,k=o?.screen,s=k?.customerData.nodes[h.nodeId];if(e.stopped||e.busy||!o||!k||!s)return;if(!["refresh","next","previous","filter","sources_next","sources_previous"].includes(h.action)){let r=e.document,f=r?se(r,h.nodeId):null,E=f?.type==="customer_data"?f.data.outputs?.[h.action]:void 0;E&&k.outputs.includes(E)?await e.perform(()=>e.client.submit({operation:"submit",...e.expected(),input:{type:"screen",output:E,answers:e.answers,selection:h.value?{[h.nodeId]:h.value}:{}}})):await e.onIntent?.(h,o);return}let a=h.action.startsWith("sources_")?s.resources.find(r=>r.key===h.value):null;if(h.action.startsWith("sources_")&&!a)throw new u("INVALID_REQUEST","Choose a current resource");let R=`${o.visit}:${h.nodeId}:${a?.key??""}`,S=n.get(R)??[null],l=C[h.nodeId]??{page:1,after:null,filter:"all",...a?{resourceKey:a.key}:{}};if(h.action==="filter"){let r=h.value;if(!r||!(s.source==="offer_history"?["all","issued","reserved","redeemed","expired","revoked"]:["all","purchase","refund","source","usage","debt","settlement"]).includes(r))throw new u("INVALID_REQUEST","Unknown data filter");l={page:1,after:null,filter:r},S.splice(0,S.length,null)}else if(h.action==="next"||h.action==="sources_next"){let r=a?.sources.at(-1),f=a?r?{kind:"ledger",cursor:{at:r.detail[0],id:r.id,type:"source"}}:null:k.dataCursors[h.nodeId];if(!f||!a&&!s.hasNext)return;S[l.page]=f,l={...l,page:l.page+1,after:f}}else if(h.action==="previous"||h.action==="sources_previous"){if(l.page<=1)return;l={...l,page:l.page-1,after:S[l.page-2]??null}}n.set(R,S),C={...C,[h.nodeId]:l},await e.perform(()=>e.client.get({nodeId:o.nodeId,visit:o.visit,revision:o.revision,components:C}))}return{get queries(){return C},intent:P,reset(){C={},n.clear()}}}function we(e){let{doc:C,holder:n,reviewHolder:P,mountScreenPreview:h}=e,o=!1,k,s=0,v=null,a="",R=new Map,S=r=>r?`${r.id}:${r.nodeId}:${r.visit}:${r.revision}:${r.paywall?.quote?.operationId??""}`:"";async function T(r){if(e.stopped||!e.client.review)return;o||(a=S(e.client.view),R.set(a,structuredClone(e.answers))),o=!0,k=r,n.hidden=!0,e.suspend(!0),P.hidden=!1;let f=++s;try{let E=await e.client.review(r);if(e.stopped||f!==s||!o)return;if(!E.review)throw new u("INVALID_RESPONSE","Historical projection is missing");v?.destroy(),v=null,P.replaceChildren();let y=E.run.locale.startsWith("zh"),O=C.createElement("p");O.textContent=y?"\u53EA\u8BFB\u56DE\u770B":"Read-only history",P.append(O);for(let[F,_]of E.review.pages.entries()){let $=C.createElement("button");$.type="button",$.textContent=y?`\u7B2C ${F+1} \u9875`:`Page ${F+1}`,$.onclick=()=>{T(_.receiptId)},P.append($)}if(E.review.page){let F=E.review.page,_=C.createElement("div");if(_.inert=!0,P.append(_),v=h(_,{mode:"live",rendererUrl:e.client.webViewUrl,title:F.document.name,onAction:()=>{},onAnswers:()=>{},onCustomerDataIntent:()=>{},onRendered:()=>{},onEscape:()=>{l()}}),v.update(F.document,E.run.locale,{serverInput:{bindings:F.inputs,answers:F.answers,values:F.values}}),await v.ready,e.stopped||f!==s||!o)return}let U=y?{issued:"\u5DF2\u9886\u53D6",reserved:"\u5DF2\u9884\u7559",redeemed:"\u5DF2\u4F7F\u7528",expired:"\u5DF2\u8FC7\u671F",revoked:"\u5DF2\u64A4\u9500",unknown:"\u72B6\u6001\u5F85\u786E\u8BA4"}:{issued:"Issued",reserved:"Reserved",redeemed:"Used",expired:"Expired",revoked:"Revoked",unknown:"Status unconfirmed"},G=y?{pending:"\u5904\u7406\u4E2D",complete:"\u5DF2\u5B8C\u6210",cancelled:"\u5DF2\u53D6\u6D88",failed:"\u5931\u8D25",unknown:"\u72B6\u6001\u5F85\u786E\u8BA4"}:{pending:"Processing",complete:"Completed",cancelled:"Cancelled",failed:"Failed",unknown:"Status unconfirmed"};for(let F of[...E.review.coupons.map((_,$)=>`${y?"\u4F18\u60E0\u5238":"Coupon"} ${$+1}: ${U[_.status]}`),...E.review.purchases.map((_,$)=>`${y?"\u8D2D\u4E70":"Purchase"} ${$+1}: ${G[_.status]}`)]){let _=C.createElement("p");_.textContent=F,P.append(_)}e.client.view&&await e.enqueue(e.client.view)}catch(E){if(f!==s||e.stopped)return;v?.destroy(),v=null,P.replaceChildren(),e.fail(E)}}async function l(){if(!o||e.stopped||!e.client.review)return;let r=++s;try{if(await e.client.review(),e.stopped||r!==s)return;o=!1,s++,v?.destroy(),v=null,P.replaceChildren(),P.hidden=!0,n.hidden=!1;let f=e.client.view;S(f)!==a?(R.set(a,structuredClone(e.answers)),e.resetScreen()):(R.delete(a),e.suspend(!1)),f&&await e.enqueue(f)}catch(f){if(r!==s||e.stopped)return;v?.destroy(),v=null,P.replaceChildren(),e.fail(f)}}return{get active(){return o},get receipt(){return k},open:T,exit:l,get drafts(){return new Map([...R].map(([r,f])=>[r,structuredClone(f)]))},stop(){o=!1,s++,v?.destroy(),v=null,P.replaceChildren(),P.hidden=!0,n.hidden=!1}}}async function Ue(e,C){let n=C,{mountScreenPreview:P}=await import("./screen-renderer-DLXDQQKK.js"),{showPaywall:h}=await import("./paywall-734GWAS4.js"),o=e.ownerDocument,k=o.activeElement,s=o.createElement("section"),v=o.createElement("div"),a=o.createElement("div"),R=o.createElement("div"),S=o.createElement("button");R.hidden=!0,S.type="button";let T=o.createElement("p"),l=o.createElement("p"),r=o.createElement("button"),f=o.createElement("button"),E=o.createElement("button"),y=o.createElement("dialog");s.dataset.indianaFunnel="",s.setAttribute("aria-busy","false"),s.style.cssText="box-sizing:border-box;width:100%;min-width:0;font:14px/1.5 system-ui,sans-serif;color:#172033;background:#fff",a.style.cssText="display:flex;gap:12px;align-items:center;flex-wrap:wrap;padding:12px 20px",T.setAttribute("role","status"),l.setAttribute("role","alert"),l.hidden=!0,r.type=f.type=E.type="button",a.append(r,T,l,E,S,f),s.append(v,R,a),e.append(s);let O=null,U=null,G=null,F="",_="",$="",j="",A=!1,Q=0,i=!1,w="",c=null,I=Promise.resolve(),d=null,m=null,p=new Set,N={},q=(t,g=null)=>{A||(m=g,l.textContent=t instanceof Error?t.message:"Request failed",l.hidden=!1,E.hidden=n.client.pendingCommand===null,X(n.onError,t))};function J(){let t=n.client.view;if(!t)throw new u("INVALID_REQUEST","No current Run is available");return{requestId:crypto.randomUUID(),nodeId:t.nodeId,visit:t.visit,revision:t.revision}}let D=we({client:n.client,doc:o,holder:v,reviewHolder:R,mountScreenPreview:P,get stopped(){return A},get answers(){return N},suspend(t){U?.setSuspended(t)},resetScreen(){F="",_=""},enqueue:W,fail:q}),z=pe({client:n.client,expected:J,fail:q,get stopped(){return A},get reviewing(){return D.active},get key(){return F},get busy(){return Q}}),Z=fe({client:n.client,expected:J,perform:B,onIntent:n.onCustomerDataIntent,get stopped(){return A},get busy(){return Q},get document(){return O?.document},get answers(){return N}});async function B(t,g=!1){if(!(Q&&!g||A||D.active&&!g)){Q++,s.setAttribute("aria-busy","true"),l.hidden=!0,m=null;try{if(!g&&z.inFlight){let b=n.client.view;await z.inFlight;let L=n.client.view;if(!b||!L||L.id!==b.id||L.nodeId!==b.nodeId||L.visit!==b.visit||L.stopped||!["running","waiting"].includes(L.status))throw new u("PRECONDITION_FAILED","The screen changed while its display was acknowledged")}if(A)return;let M=await t();A||await W(n.client.view??M.run)}catch(M){q(M,n.client.pendingCommand?.requestId??null)}finally{Q=Math.max(0,Q-1),s.setAttribute("aria-busy",String(Q>0)),A||(E.hidden=n.client.pendingCommand===null,r.disabled=Q>0||!!n.client.pendingCommand||!n.client.view?.canBack)}}}function x(){c&&clearTimeout(c),!(A||!G||!["running","waiting"].includes(G.status)&&!n.client.pendingCommand)&&(c=setTimeout(()=>{c=null,oe().finally(x)},G.pendingRequest||n.client.pendingCommand?1500:5e3))}async function oe(){if(!(A||i||Q)){if(D.active){await D.open(D.receipt);return}i=!0;try{let t=n.client.pendingCommand;t&&n.client.settle&&await n.client.settle(t.requestId);let g=n.client.view,M=Z.queries,b=await n.client.get(g?.screen&&Object.keys(M).length?{nodeId:g.nodeId,visit:g.visit,revision:g.revision,components:M}:void 0);!A&&M===Z.queries&&await W(n.client.view??b.run)}catch(t){q(t)}finally{i=!1}}}function me(t){let g=t.screen?.presentation;if(!g||g.type==="inline"){y.open&&y.close(),s.parentElement!==e&&e.append(s);return}s.parentElement!==y&&(y.append(s),e.append(y));let M={sm:420,md:640,lg:900};y.style.cssText=`padding:0;border:0;max-width:calc(100vw - 32px);max-height:calc(100dvh - 32px);overflow:auto;width:${"size"in g?M[g.size]+"px":"100vw"}`,y.setAttribute("aria-label",O?.document?.name??t.screen?.content.document.name??"Funnel"),y.open||y.showModal()}async function ye(t){if(A)return;G=t,m&&n.client.pendingCommand?.requestId!==m&&(l.hidden=!0,m=null);let g=t.locale.startsWith("zh");if(S.textContent=g?"\u56DE\u770B":"History",S.hidden=!n.client.review,r.textContent=D.active?g?"\u8FD4\u56DE\u5F53\u524D":"Return to current":g?"\u8FD4\u56DE":"Back",f.textContent=g?"\u5173\u95ED":"Close",E.textContent=g?"\u91CD\u8BD5":"Retry",r.disabled=!D.active&&(Q>0||!!n.client.pendingCommand||!t.canBack),E.hidden=n.client.pendingCommand===null,T.textContent=t.pendingRequest?g?"\u6B63\u5728\u5904\u7406":"Processing":t.instruction?.type==="wait"?g?"\u7B49\u5F85\u4E2D":"Waiting":"",w!==`${t.revision}:${t.visit}:${t.status}:${t.stopped}`&&(w=`${t.revision}:${t.visit}:${t.status}:${t.stopped}`,X(n.onState,structuredClone(t))),t.stopped||n.client.configurationReady===!1){D.stop(),O?.destroy(),O=null,U?.destroy(),U=null,v.replaceChildren(),F="",_="",j="",y.open&&y.close(),s.hidden=!0,x();return}if(s.hidden=!1,D.active){x();return}let M=t.screen||t.paywall?`${t.id}:${t.nodeId}:${t.visit}`:"";if(M!==F&&(O?.destroy(),O=null,U?.destroy(),U=null,v.replaceChildren(),F=M,_="",j="",N={...t.answers},Z.reset()),me(t),t.screen){let L=t.screen.content;O||(O=P(v,{mode:"live",rendererUrl:n.client.webViewUrl,title:L.document.name,onAction(H,te={},ie={}){if(D.active)return;N={...N,...ie};let Ie=Object.fromEntries((t.screen?.inputs??[]).filter(({variable:ne})=>Object.hasOwn(N,ne)).map(({variable:ne})=>[ne,N[ne]]));B(()=>n.client.submit({operation:"submit",...J(),input:{type:"screen",output:H,answers:Ie,selection:te}}))},onAnswers:H=>{D.active||(N={...N,...H})},onCustomerDataIntent:H=>{D.active||Z.intent(H).catch(q)},onEscape:()=>{D.active||K()},onError:H=>q(new Error(H)),onRendered:()=>z.report(M)}));let V={capabilities:t.screen.capabilities,customerData:t.screen.customerData,parameters:t.parameters,serverInput:{bindings:t.screen.inputs,answers:N,values:t.screen.values}},Y=JSON.stringify([L,t.locale,V.parameters,t.screen.inputs,t.screen.values]);if(Y!==_)O.update(L.document,t.locale,V),_=Y,$=JSON.stringify(V.capabilities),j=JSON.stringify(V.customerData);else{let H=JSON.stringify(V.capabilities);H!==$&&(O.updateCapabilities(V.capabilities),$=H),JSON.stringify(V.customerData)!==j&&(O.updateCustomerData(V.customerData),j=JSON.stringify(V.customerData))}await O.ready}else if(t.paywall&&!U){let L=await h(v,{canInteract:()=>!D.active&&!A,start:async()=>ce(n.client),onPurchase:n.onPurchase,onCheckoutUrl:n.onCheckoutUrl,resolveOfferId:n.resolveOfferId,onEvent:n.onEvent,onOpenUrl:V=>n.onOpenUrl?n.onOpenUrl({receiptId:t.paywall.receiptId,url:V,openIn:"same_window"}):o.defaultView?.location.assign(V),onAction:async V=>{if(D.active)return;let Y=await n.client.submit({operation:"submit",requestId:crypto.randomUUID(),nodeId:t.nodeId,visit:t.visit,revision:t.revision,input:{type:"screen",output:V,answers:{}}});await W(n.client.view??Y.run)},onError:q,onDismiss:()=>{!D.active&&!A&&n.client.view?.visit===t.visit&&K()}});A?L.host?.destroy():(U=L.host,U?.setSuspended(D.active)),z.report(M)}let b=t.instruction;if(b&&(b.type==="open_url"||b.type==="event")&&!p.has(b.receiptId)){let L=o.createElement("button");L.type="button",L.textContent=b.type==="open_url"?`${g?"\u524D\u5F80":"Continue to"} ${new URL(b.url).host}`:g?"\u7EE7\u7EED":"Continue",L.onclick=()=>{let V=J(),Y=b.type==="open_url"&&!n.onOpenUrl&&b.openIn==="new_window"?he(b.url):null;B(async()=>{let H="success";if(b.type==="open_url")if(n.onOpenUrl)try{H=await n.onOpenUrl({receiptId:b.receiptId,url:b.url,openIn:b.openIn})===!1?"failed":"opened"}catch(ie){X(n.onError,ie),H="failed"}else H=b.openIn==="new_window"&&!Y?"failed":"opened";if(b.type==="event"){if(!n.onEvent)throw new u("EVENT_HANDLER_REQUIRED","Provide the event handler");await n.onEvent(b.event)}if(A||n.client.view?.nodeId!==V.nodeId||n.client.view.visit!==V.visit)throw new u("PRECONDITION_FAILED","The client action visit changed");let te=await n.client.submit({operation:"submit",...V,input:{type:"client_action",receiptId:b.receiptId,outcome:H}});return p.add(b.receiptId),b.type==="open_url"&&!n.onOpenUrl&&b.openIn==="same_window"&&o.defaultView?.location.assign(b.url),te})},v.replaceChildren(L)}!t.pendingRequest&&t.status==="completed"&&!p.has(`complete:${t.id}`)&&(p.add(`complete:${t.id}`),X(n.onComplete,structuredClone(t))),x()}function he(t){let g=o.defaultView?.open(t,"_blank")??null;return g&&(g.opener=null),g}function W(t){return I=I.catch(()=>{}).then(()=>ye(t)),I}let ve=n.client.subscribe(t=>{n.client.configurationReady===!1&&(s.hidden=!0,O?.destroy(),O=null,U?.destroy(),U=null,v.replaceChildren(),F="",_="",j="",y.open&&y.close()),W(t).catch(q)}),ge=n.client.subscribeError?.(q);function K(){return d||(A?Promise.resolve():n.client.view&&!["running","waiting"].includes(n.client.view.status)?(ee(),Promise.resolve()):(d=B(()=>n.client.submit({operation:"close",...J()}),!0).then(()=>{n.client.view?.status==="closed"&&ee()}).finally(()=>{d=null}),d))}function ee(){A||(A=!0,c&&clearTimeout(c),ve(),ge?.(),O?.destroy(),D.stop(),U?.destroy(),y.close(),y.remove(),s.remove(),k instanceof HTMLElement&&k.isConnected&&k.focus(),X(n.onDismiss,G?structuredClone(G):null))}r.onclick=()=>{if(D.active){D.exit();return}B(()=>n.client.submit({operation:"back",...J()}))},S.onclick=()=>{D.open()},f.onclick=()=>{K()},E.onclick=()=>{B(()=>n.client.retry())},y.addEventListener("cancel",t=>{t.preventDefault(),K()});try{let t=await n.client.get();await W(n.client.view??t.run)}catch(t){throw ee(),t}return{destroy:ee,refresh:oe,review:D.open,exitReview:D.exit,get unappliedDrafts(){return D.drafts}}}export{Ue as showFunnelRun};