@tinkerlandai/indiana-sdk 0.6.1 → 0.6.2
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 +6 -0
- package/README.md +13 -9
- package/README.zh-CN.md +19 -16
- package/dist/{ai-usage-C4Eg6sSr.d.ts → ai-usage-B4W5m4Ie.d.ts} +346 -346
- package/dist/{chunk-FRZNOXK6.js → chunk-ET4NANGB.js} +1 -1
- package/dist/{chunk-U3TULZCD.js → chunk-J7M7UH74.js} +1 -1
- package/dist/{chunk-GJGI34Q7.js → chunk-M3DG6ZCT.js} +1 -1
- package/dist/chunk-N6UIDDAX.js +4 -0
- package/dist/chunk-VMLGV5OS.js +11 -0
- package/dist/{configuration-sync-BWn1YZ78.d.ts → configuration-sync-Bnu8s4pc.d.ts} +41 -41
- package/dist/{funnel-runtime-host-YXWVCKAJ.js → funnel-runtime-host-3STQUS6F.js} +1 -1
- package/dist/{funnel-runtime-start-CKVuIOFs.d.ts → funnel-runtime-start-Zbd5ro5r.d.ts} +787 -787
- package/dist/index.d.ts +603 -603
- package/dist/index.js +1 -1
- package/dist/openrouter.d.ts +2 -2
- package/dist/openrouter.js +1 -1
- package/dist/page.d.ts +19 -18
- package/dist/page.js +1 -1
- package/dist/{paywall-GRSGZLVG.js → paywall-LBDMGVWZ.js} +1 -1
- package/dist/popup.d.ts +16 -12
- package/dist/popup.js +176 -6
- package/dist/server.d.ts +4 -4
- package/dist/server.js +1 -1
- package/dist/src-X6KT6WIH.js +1 -0
- package/dist/visual.js +1 -1
- package/package.json +10 -9
- package/dist/chunk-46S4DTCD.js +0 -11
- package/dist/chunk-4JBIKJMU.js +0 -4
- package/dist/src-UWBQFGYH.js +0 -1
- package/dist/{customer-page-OBB82t8_.d.ts → customer-page-B4FGCVpt.d.ts} +4 -4
- package/dist/{screen-BbLE1OMn.d.ts → screen-16d-xADb.d.ts} +160 -160
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { S as StackNode } from './screen-
|
|
2
|
+
import { S as StackNode } from './screen-16d-xADb.js';
|
|
3
3
|
|
|
4
4
|
declare const configurationScopeSchema: z.ZodObject<{
|
|
5
5
|
projectId: z.ZodString;
|
|
6
6
|
environment: z.ZodEnum<{
|
|
7
|
-
live: "live";
|
|
8
7
|
sandbox: "sandbox";
|
|
8
|
+
live: "live";
|
|
9
9
|
}>;
|
|
10
10
|
environmentId: z.ZodUUID;
|
|
11
11
|
}, z.core.$strict>;
|
|
@@ -15,8 +15,8 @@ declare const sdkConfigurationManifestSchema: z.ZodObject<{
|
|
|
15
15
|
scope: z.ZodObject<{
|
|
16
16
|
projectId: z.ZodString;
|
|
17
17
|
environment: z.ZodEnum<{
|
|
18
|
-
live: "live";
|
|
19
18
|
sandbox: "sandbox";
|
|
19
|
+
live: "live";
|
|
20
20
|
}>;
|
|
21
21
|
environmentId: z.ZodUUID;
|
|
22
22
|
}, z.core.$strict>;
|
|
@@ -90,7 +90,7 @@ type Listener = () => void;
|
|
|
90
90
|
declare function createConfigurationSync(options: ConfigurationSyncOptions): {
|
|
91
91
|
scope: Readonly<{
|
|
92
92
|
projectId: string;
|
|
93
|
-
environment: "
|
|
93
|
+
environment: "sandbox" | "live";
|
|
94
94
|
environmentId: string;
|
|
95
95
|
}>;
|
|
96
96
|
refresh: () => Promise<Manifest>;
|
|
@@ -103,7 +103,7 @@ declare function createConfigurationSync(options: ConfigurationSyncOptions): {
|
|
|
103
103
|
schemaVersion: 1;
|
|
104
104
|
scope: {
|
|
105
105
|
projectId: string;
|
|
106
|
-
environment: "
|
|
106
|
+
environment: "sandbox" | "live";
|
|
107
107
|
environmentId: string;
|
|
108
108
|
};
|
|
109
109
|
revision: number;
|
|
@@ -146,6 +146,10 @@ declare function createConfigurationSync(options: ConfigurationSyncOptions): {
|
|
|
146
146
|
features(): Promise<{
|
|
147
147
|
evaluatedAt: string;
|
|
148
148
|
expiresAt: string;
|
|
149
|
+
scope: {
|
|
150
|
+
projectId: string;
|
|
151
|
+
environment: "sandbox" | "live";
|
|
152
|
+
};
|
|
149
153
|
features: Record<string, {
|
|
150
154
|
defaultValue?: z.core.util.JSONType | undefined;
|
|
151
155
|
rules?: {
|
|
@@ -242,10 +246,6 @@ declare function createConfigurationSync(options: ConfigurationSyncOptions): {
|
|
|
242
246
|
phase?: string | undefined;
|
|
243
247
|
}[] | undefined;
|
|
244
248
|
}>;
|
|
245
|
-
scope: {
|
|
246
|
-
projectId: string;
|
|
247
|
-
environment: "live" | "sandbox";
|
|
248
|
-
};
|
|
249
249
|
generation: string;
|
|
250
250
|
savedGroups: Record<string, {
|
|
251
251
|
type: "hashed";
|
|
@@ -318,41 +318,41 @@ declare function createConfigurationSync(options: ConfigurationSyncOptions): {
|
|
|
318
318
|
urlRedirect: string;
|
|
319
319
|
}[];
|
|
320
320
|
name?: string | undefined;
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
name?: string | undefined;
|
|
324
|
-
passthrough?: boolean | undefined;
|
|
325
|
-
}[] | undefined;
|
|
326
|
-
filters?: {
|
|
327
|
-
seed: string;
|
|
328
|
-
hashVersion: 2;
|
|
329
|
-
ranges: [number, number][];
|
|
330
|
-
attribute?: string | undefined;
|
|
331
|
-
}[] | undefined;
|
|
321
|
+
coverage?: number | undefined;
|
|
322
|
+
condition?: Record<string, z.core.util.JSONType> | undefined;
|
|
332
323
|
seed?: string | undefined;
|
|
333
324
|
hashVersion?: 2 | undefined;
|
|
334
325
|
ranges?: [number, number][] | undefined;
|
|
335
|
-
|
|
326
|
+
force?: number | undefined;
|
|
336
327
|
urlPatterns?: {
|
|
337
328
|
include: boolean;
|
|
338
329
|
type: "regex" | "simple";
|
|
339
330
|
pattern: string;
|
|
340
331
|
}[] | undefined;
|
|
341
|
-
force?: number | undefined;
|
|
342
332
|
persistQueryString?: boolean | undefined;
|
|
343
333
|
hashAttribute?: string | undefined;
|
|
334
|
+
phase?: string | undefined;
|
|
335
|
+
filters?: {
|
|
336
|
+
seed: string;
|
|
337
|
+
hashVersion: 2;
|
|
338
|
+
ranges: [number, number][];
|
|
339
|
+
attribute?: string | undefined;
|
|
340
|
+
}[] | undefined;
|
|
344
341
|
parentConditions?: {
|
|
345
342
|
id: string;
|
|
346
343
|
condition: Record<string, z.core.util.JSONType>;
|
|
347
344
|
gate?: boolean | undefined;
|
|
348
345
|
}[] | undefined;
|
|
349
346
|
weights?: number[] | undefined;
|
|
350
|
-
coverage?: number | undefined;
|
|
351
347
|
fallbackAttribute?: string | undefined;
|
|
352
348
|
disableStickyBucketing?: boolean | undefined;
|
|
353
349
|
bucketVersion?: number | undefined;
|
|
354
350
|
minBucketVersion?: number | undefined;
|
|
355
|
-
|
|
351
|
+
meta?: {
|
|
352
|
+
key?: string | undefined;
|
|
353
|
+
name?: string | undefined;
|
|
354
|
+
passthrough?: boolean | undefined;
|
|
355
|
+
}[] | undefined;
|
|
356
356
|
}[];
|
|
357
357
|
savedGroups: Record<string, {
|
|
358
358
|
type: "hashed";
|
|
@@ -584,7 +584,7 @@ declare function createConfigurationSync(options: ConfigurationSyncOptions): {
|
|
|
584
584
|
event: string;
|
|
585
585
|
} | {
|
|
586
586
|
type: "api";
|
|
587
|
-
operation: "update" | "
|
|
587
|
+
operation: "update" | "refund" | "setupPayment" | "readBalanceSource" | "adjustBalance" | "readUsage" | "setUsage" | "manageBalanceGrant" | "listBalanceGrants" | "restoreNativePurchase" | "readPaymentSetup" | "verifySubscriptions" | "previewAttach" | "attach" | "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";
|
|
588
588
|
inputs: Record<string, {
|
|
589
589
|
source: "literal";
|
|
590
590
|
value: z.core.util.JSONType;
|
|
@@ -627,7 +627,7 @@ declare function createConfigurationSync(options: ConfigurationSyncOptions): {
|
|
|
627
627
|
} | undefined;
|
|
628
628
|
} | {
|
|
629
629
|
type: "end";
|
|
630
|
-
outcome: "
|
|
630
|
+
outcome: "failed" | "completed" | "closed" | "ineligible";
|
|
631
631
|
id: string;
|
|
632
632
|
name: string;
|
|
633
633
|
output?: {
|
|
@@ -692,7 +692,7 @@ declare function createConfigurationSync(options: ConfigurationSyncOptions): {
|
|
|
692
692
|
primary: string;
|
|
693
693
|
background: string;
|
|
694
694
|
text: string;
|
|
695
|
-
radius: "
|
|
695
|
+
radius: "none" | "full" | "sm" | "md" | "lg";
|
|
696
696
|
font: "system" | "serif" | "rounded" | "mono";
|
|
697
697
|
};
|
|
698
698
|
pages: {
|
|
@@ -703,7 +703,7 @@ declare function createConfigurationSync(options: ConfigurationSyncOptions): {
|
|
|
703
703
|
primary: string;
|
|
704
704
|
background: string;
|
|
705
705
|
text: string;
|
|
706
|
-
radius: "
|
|
706
|
+
radius: "none" | "full" | "sm" | "md" | "lg";
|
|
707
707
|
font: "system" | "serif" | "rounded" | "mono";
|
|
708
708
|
} | undefined;
|
|
709
709
|
editorPosition?: {
|
|
@@ -753,20 +753,20 @@ declare function createConfigurationSync(options: ConfigurationSyncOptions): {
|
|
|
753
753
|
};
|
|
754
754
|
publicData?: {
|
|
755
755
|
couponDigests: Record<string, string>;
|
|
756
|
-
variables: Record<string, Record<string, Partial<Record<"offer.
|
|
756
|
+
variables: Record<string, Record<string, Partial<Record<"offer.headline" | "offer.name" | "offer.description" | "offer.eligibility" | "offer.validity" | "offer.terms" | "offer.discount" | "offer.months" | "offer.ends_at", string>>>>;
|
|
757
757
|
locales: Record<string, {
|
|
758
|
+
plans: Record<string, never>;
|
|
758
759
|
nodes: Record<string, {
|
|
759
760
|
base: {
|
|
760
|
-
|
|
761
|
+
couponId?: string | undefined;
|
|
761
762
|
label?: string | undefined;
|
|
763
|
+
text?: string | undefined;
|
|
762
764
|
alt?: string | undefined;
|
|
763
765
|
html?: string | undefined;
|
|
764
766
|
countdownAt?: string | undefined;
|
|
765
|
-
couponId?: string | undefined;
|
|
766
767
|
missing?: string[] | undefined;
|
|
767
768
|
};
|
|
768
769
|
}>;
|
|
769
|
-
plans: Record<string, never>;
|
|
770
770
|
pickers: Record<string, never>;
|
|
771
771
|
diagnostics: {
|
|
772
772
|
nodeId: string;
|
|
@@ -846,6 +846,10 @@ declare function createConfigurationSync(options: ConfigurationSyncOptions): {
|
|
|
846
846
|
growth: {
|
|
847
847
|
evaluatedAt: string;
|
|
848
848
|
expiresAt: string;
|
|
849
|
+
scope: {
|
|
850
|
+
projectId: string;
|
|
851
|
+
environment: "sandbox" | "live";
|
|
852
|
+
};
|
|
849
853
|
features: Record<string, {
|
|
850
854
|
defaultValue?: z.core.util.JSONType | undefined;
|
|
851
855
|
rules?: {
|
|
@@ -942,10 +946,6 @@ declare function createConfigurationSync(options: ConfigurationSyncOptions): {
|
|
|
942
946
|
phase?: string | undefined;
|
|
943
947
|
}[] | undefined;
|
|
944
948
|
}>;
|
|
945
|
-
scope: {
|
|
946
|
-
projectId: string;
|
|
947
|
-
environment: "live" | "sandbox";
|
|
948
|
-
};
|
|
949
949
|
generation: string;
|
|
950
950
|
savedGroups: Record<string, {
|
|
951
951
|
type: "hashed";
|
|
@@ -1030,7 +1030,7 @@ declare function createConfigurationSync(options: ConfigurationSyncOptions): {
|
|
|
1030
1030
|
schemaVersion: 1;
|
|
1031
1031
|
scope: {
|
|
1032
1032
|
projectId: string;
|
|
1033
|
-
environment: "
|
|
1033
|
+
environment: "sandbox" | "live";
|
|
1034
1034
|
environmentId: string;
|
|
1035
1035
|
};
|
|
1036
1036
|
revision: number;
|
|
@@ -1075,7 +1075,7 @@ declare function createConfigurationSync(options: ConfigurationSyncOptions): {
|
|
|
1075
1075
|
growth: {
|
|
1076
1076
|
scope: {
|
|
1077
1077
|
projectId: string;
|
|
1078
|
-
environment: "
|
|
1078
|
+
environment: "sandbox" | "live";
|
|
1079
1079
|
};
|
|
1080
1080
|
generation: string;
|
|
1081
1081
|
evaluatedAt: string;
|
|
@@ -1236,7 +1236,7 @@ declare function createConfigurationSync(options: ConfigurationSyncOptions): {
|
|
|
1236
1236
|
}[]>;
|
|
1237
1237
|
scope: {
|
|
1238
1238
|
projectId: string;
|
|
1239
|
-
environment: "
|
|
1239
|
+
environment: "sandbox" | "live";
|
|
1240
1240
|
};
|
|
1241
1241
|
funnelId: string;
|
|
1242
1242
|
versionId: string;
|
|
@@ -1246,7 +1246,7 @@ declare function createConfigurationSync(options: ConfigurationSyncOptions): {
|
|
|
1246
1246
|
entry: string;
|
|
1247
1247
|
nodes: {
|
|
1248
1248
|
id: string;
|
|
1249
|
-
type: "output" | "action" | "
|
|
1249
|
+
type: "output" | "action" | "condition" | "split" | "end" | "coupon" | "coupons" | "screen" | "offering" | "feature" | "entry" | "external_page" | "wait";
|
|
1250
1250
|
outputs: Record<string, string>;
|
|
1251
1251
|
writes: Record<string, string>;
|
|
1252
1252
|
resources: {
|
|
@@ -1291,7 +1291,7 @@ declare function createConfigurationSync(options: ConfigurationSyncOptions): {
|
|
|
1291
1291
|
} | undefined;
|
|
1292
1292
|
};
|
|
1293
1293
|
terminals: Record<string, {
|
|
1294
|
-
outcome: "
|
|
1294
|
+
outcome: "failed" | "completed" | "closed" | "ineligible";
|
|
1295
1295
|
output: {
|
|
1296
1296
|
type: "literal";
|
|
1297
1297
|
value: z.core.util.JSONType;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as ne}from"./chunk-6X42DWOM.js";import"./chunk-FRZNOXK6.js";import{a as f}from"./chunk-5TEZEOHX.js";import"./chunk-S5TVMQRC.js";import{Gd as Ie,ni as me}from"./chunk-46S4DTCD.js";import{Gb as Ce}from"./chunk-RMJJOSVZ.js";import"./chunk-OHDY27EI.js";import"./chunk-S2MSIA57.js";function be(b){let q=b.view;if(!q?.paywall)throw new f("INVALID_REQUEST","The current node is not a Paywall");let n=q.paywall.receiptId,Z=q.nodeId,te=q.visit,w=q.paywall.resolution,E=q.paywall.quote,y=q.paywall.operation,O=!1,L=new AbortController,v=q.paywall.purchaseRequestId,k=0,F=q.paywall.selectionGeneration??0,U=q.paywall.canReselect===!0,A=null,j=new Map,V=new Map;function R(t){if(t.purchase&&t.purchase.receiptId!==n)throw new f("INVALID_RESPONSE","Purchase receipt changed");let i=t.run.paywall;return t.purchase??(i?.receiptId===n?i:null)}function C(){if(O)throw new f("IDENTITY_CHANGED","Paywall presentation has closed")}function N(t,i,a){if(C(),i!==k||a!==void 0&&E?.operationId!==a)return!1;let m=F,l=t.run.paywall;if(l?.receiptId===n){if((l.selectionGeneration??0)<F)return!1;if(F=l.selectionGeneration??0,U=l.canReselect===!0,l.resolution.id!==w.id||l.resolution.offering.id!==w.offering.id)throw new f("INVALID_RESPONSE","The pinned Paywall binding changed")}let c=R(t),u=F>m,D=u?c?.quote??null:c?.quote??E,P=c?.operation??(D?.operationId===E?.operationId?y:null);if(D&&P&&D.operationId!==P.operationId)throw new f("INVALID_RESPONSE","Purchase operation changed");return l?.receiptId===n&&(w=l.resolution),(u||D?.operationId!==E?.operationId)&&(k++,l?.receiptId===n&&(v=l.purchaseRequestId)),E=D,(y?.operationId!==P?.operationId||y?.status==="pending"||P?.status==="complete")&&(y=P),!0}function z(t,i,a){return new Promise((m,l)=>{let c=!1,u=()=>{clearTimeout(ie),L.signal.removeEventListener("abort",$)},D=ee=>{c||(c=!0,u(),m(ee))},P=ee=>{c||(c=!0,u(),l(ee))},$=()=>P(new f("IDENTITY_CHANGED","Paywall presentation has closed")),ie=setTimeout(()=>P(new f("COMMAND_PENDING","The purchase command is still pending; retry the original request",202,a)),Math.max(0,i-Date.now()));L.signal.addEventListener("abort",$,{once:!0}),L.signal.aborted&&$(),t.then(D,P)})}function Q(t){return new Promise(i=>{let a=()=>{clearTimeout(m),L.signal.removeEventListener("abort",a),i()},m=setTimeout(a,t);L.signal.addEventListener("abort",a,{once:!0}),L.signal.aborted&&a()})}async function W(t,i,a){C();let m=j.get(t);if(!m){let u=b.pendingCommands?.find(D=>D.requestId===t)??b.pendingCommand;if(u?.operation==="submit"&&u.requestId===t&&u.nodeId===Z&&u.visit===te){i.type==="paywall_quote"&&u.input.type==="paywall_quote"&&u.input.predecessor&&!i.predecessor&&(i={...i,predecessor:u.input.predecessor});let D=me.parse(u),P=me.parse({...u,input:i});if(P.operation!=="submit"||D.operation!=="submit"||JSON.stringify(P.input)!==JSON.stringify(D.input))throw new f("CONFLICT","A restored purchase request cannot change its input");i=P.input,m=D,j.set(t,m)}}if(m){if(JSON.stringify(m.input)!==JSON.stringify(i))throw new f("CONFLICT","A purchase request cannot change its input")}else{let u=b.view;if(!u||u.nodeId!==Z||u.visit!==te||u.paywall?.receiptId!==n)throw new f("PRECONDITION_FAILED","The Paywall visit has changed");m={operation:"submit",requestId:t,nodeId:Z,visit:te,revision:u.revision,input:i},j.set(t,m)}let l=Date.now()+3e4,c=await z(b.submit(m),l,t);for(;c.run.pendingRequest?.requestId===t&&Date.now()<l&&!O&&(await Q(Math.min(1e3,l-Date.now())),!(O||Date.now()>=l));)c=await z(b.resume(t),l,t);if(O)throw new f("IDENTITY_CHANGED","Paywall presentation has closed");if(c.run.pendingRequest?.requestId===t)throw new f("COMMAND_PENDING","The purchase command is still pending; retry the original request",202,t);if(!N(c,a,i.type==="paywall_confirm"||i.type==="paywall_cancel"?i.operationId:void 0))throw new f("PRECONDITION_FAILED","The purchase selection has changed")}async function K(t){if(!E)throw new f("INVALID_REQUEST","A quoted purchase is required");let i=`${t}:${E.operationId}`,a=V.get(i);if(!a){let m=t==="confirm"?"paywall_confirm":"paywall_cancel",l=b.pendingCommands?.find(c=>c.operation==="submit"&&c.input.type===m&&"operationId"in c.input&&c.input.operationId===E.operationId)??b.pendingCommand;a=l?.operation==="submit"&&l.input.type===m&&"operationId"in l.input&&l.input.operationId===E.operationId?l.requestId:crypto.randomUUID(),V.set(i,a)}if(await W(a,{type:t==="confirm"?"paywall_confirm":"paywall_cancel",operationId:E.operationId},k),!y)throw new f("INVALID_RESPONSE","The accepted purchase result is missing");return structuredClone(y)}return{get view(){return structuredClone(w)},get quote(){return E?structuredClone(E):null},get operation(){return y?structuredClone(y):null},get webViewUrl(){return b.webViewUrl},get canReselect(){return U},async refresh(){C();let t=k;return N(await b.get(),t),structuredClone(w)},preview(t){if(v&&v!==t.requestId&&(A||!U))return Promise.reject(new f("COMMAND_PENDING","Retry the original purchase before starting another"));if(v===t.requestId&&A)return A;let i=w.document.buttons[t.actionId],a=i?.type==="checkout"?Ie(i.product,t.selection,w.capabilities):null;if(!a)return Promise.reject(new f("PRODUCT_UNAVAILABLE","Choose an available Product in this purchase area"));let m=v!==t.requestId&&F>0?{operationId:E?.operationId??null,generation:F}:void 0;if(m&&(!U||F<=0))return Promise.reject(new f("COMMAND_PENDING","Original purchase requires authoritative termination"));v!==t.requestId&&k++;let l=k;v=t.requestId;let c=(async()=>{if(await W(t.requestId,{type:"paywall_quote",actionId:t.actionId,productVersionId:a,...m?{predecessor:m}:{},...t.offerId?{offerId:t.offerId}:{},...t.nativeOffer?{nativeOffer:t.nativeOffer}:{}},l),!E)throw new f("INVALID_RESPONSE","The accepted quote is missing");return structuredClone(E)})();return A=c,c.then(()=>{A===c&&(A=null)},u=>{A===c&&(A=null),v===t.requestId&&b.pendingCommand?.requestId!==t.requestId&&u instanceof f&&u.status!==void 0&&u.status<500&&![401,425].includes(u.status)&&(v=null)}),c},confirm:()=>K("confirm"),cancel:()=>K("cancel"),async read(){if(C(),!E)throw new f("INVALID_REQUEST","A quoted purchase is required");let t=E.operationId,i=k,a=b.pendingCommands?.find(u=>u.operation==="submit"&&(u.input.type==="paywall_confirm"||u.input.type==="paywall_cancel")&&u.input.operationId===t)??b.pendingCommand;a?.operation==="submit"&&(a.input.type==="paywall_confirm"||a.input.type==="paywall_cancel")&&a.input.operationId===t&&await b.settle?.(a.requestId);let m=await b.get(void 0,{receiptId:n,operationId:t});C();let l=R(m);if(l?.quote&&l.quote.operationId!==t||l?.operation&&l.operation.operationId!==t)throw new f("INVALID_RESPONSE","Purchase operation changed");let c=N(m,i,t)?y:l?.operation;if(!c)throw new f("INVALID_RESPONSE","The current purchase result is missing");return structuredClone(c)},destroy(){O=!0,L.abort(),j.clear(),V.clear()}}}async function Fe(b,q){let n=q,{mountScreenPreview:Z}=await import("./popup.js"),{showPaywall:te}=await import("./paywall-GRSGZLVG.js"),w=b.ownerDocument,E=w.activeElement,y=w.createElement("section"),O=w.createElement("div"),L=w.createElement("div"),v=w.createElement("div"),k=w.createElement("button");v.hidden=!0,k.type="button";let F=w.createElement("p"),U=w.createElement("p"),A=w.createElement("button"),j=w.createElement("button"),V=w.createElement("button"),R=w.createElement("dialog");y.dataset.indianaFunnel="",y.setAttribute("aria-busy","false"),y.style.cssText="box-sizing:border-box;width:100%;min-width:0;font:14px/1.5 system-ui,sans-serif;color:#172033;background:#fff",L.style.cssText="display:flex;gap:12px;align-items:center;flex-wrap:wrap;padding:12px 20px",F.setAttribute("role","status"),U.setAttribute("role","alert"),U.hidden=!0,A.type=j.type=V.type="button",L.append(A,F,U,V,k,j),y.append(O,v,L),b.append(y);let C=null,N=null,z=null,Q="",W="",K="",t="",i=!1,a=0,m=!1,l="",c=null,u=Promise.resolve(),D=null,P=null,$={},ie=new Map,ee=new Set,se=new Set,ae=new Set,oe=null,H={},g=!1,he,G=0,T=null,re="",le=new Map,ye=e=>e?`${e.id}:${e.nodeId}:${e.visit}:${e.revision}:${e.paywall?.quote?.operationId??""}`:"",J=(e,o=null)=>{i||(P=o,U.textContent=e instanceof Error?e.message:"Request failed",U.hidden=!1,V.hidden=n.client.pendingCommand===null,ne(n.onError,e))};function B(){let e=n.client.view;if(!e)throw new f("INVALID_REQUEST","No current Run is available");return{requestId:crypto.randomUUID(),nodeId:e.nodeId,visit:e.visit,revision:e.revision}}async function Y(e,o=!1){if(!(a&&!o||i||(g||n.client.view?.recoveryRestricted)&&!o)){a++,y.setAttribute("aria-busy","true"),U.hidden=!0,P=null;try{if(!o&&oe){let r=n.client.view;await oe;let h=n.client.view;if(!r||!h||h.id!==r.id||h.nodeId!==r.nodeId||h.visit!==r.visit||h.stopped||!["running","waiting"].includes(h.status))throw new f("PRECONDITION_FAILED","The screen changed while its display was acknowledged")}if(i)return;let d=await e();i||await X(n.client.view??d.run)}catch(d){J(d,n.client.pendingCommand?.requestId??null)}finally{a=Math.max(0,a-1),y.setAttribute("aria-busy",String(a>0)),i||(V.hidden=n.client.pendingCommand===null,A.disabled=a>0||!!n.client.pendingCommand||!n.client.view?.canBack)}}}function ve(e){if(g||ee.has(e)||se.has(e)||i)return;se.add(e);let o=async()=>{if(g||i||Q!==e){se.delete(e);return}if(a||n.client.pendingCommand){setTimeout(()=>{o()},250);return}let d=(async()=>{let h=n.client.view,p=B();try{await n.client.submit({operation:"shown",...p})}catch(S){if(!(S instanceof f)||S.code!=="CONFLICT"||S.status!==409||n.client.pendingCommand)throw S;await n.client.get();let s=n.client.view;if(i||g||Q!==e||!s||!h||s.id!==h.id||s.source.versionId!==h.source.versionId||s.nodeId!==p.nodeId||s.visit!==p.visit||s.revision<=p.revision||s.stopped||!s.screen||!["running","waiting"].includes(s.status)||n.client.pendingCommand)throw S;await n.client.submit({operation:"shown",...B()})}ee.add(e)})();oe=d;let r=()=>{oe===d&&(oe=null),se.delete(e)};d.then(r,h=>{r(),a||J(h)})};o()}function ue(){c&&clearTimeout(c),!(i||!z||!["running","waiting"].includes(z.status)&&!n.client.pendingCommand)&&(c=setTimeout(()=>{c=null,ge().finally(ue)},z.pendingRequest||n.client.pendingCommand?1500:5e3))}async function ge(){if(!(i||m||a)){if(g){await ce(he);return}m=!0;try{let e=n.client.pendingCommand;e&&n.client.settle&&await n.client.settle(e.requestId);let o=n.client.view,d=$,r=await n.client.get(o?.screen&&Object.keys(d).length?{nodeId:o.nodeId,visit:o.visit,revision:o.revision,components:d}:void 0);!i&&d===$&&await X(n.client.view??r.run)}catch(e){J(e)}finally{m=!1}}}async function Ee(e){let o=n.client.view,d=o?.screen,r=d?.customerData.nodes[e.nodeId];if(i||a||!o||!d||!r)return;if(!["refresh","next","previous","filter","sources_next","sources_previous"].includes(e.action)){let x=C?.document,M=x?Ce(x,e.nodeId):null,we=M?.type==="customer_data"?M.data.outputs?.[e.action]:void 0;we&&d.outputs.includes(we)?await Y(()=>n.client.submit({operation:"submit",...B(),input:{type:"screen",output:we,answers:H,selection:e.value?{[e.nodeId]:e.value}:{}}})):await n.onCustomerDataIntent?.(e,o);return}let p=e.action.startsWith("sources_")?r.resources.find(x=>x.key===e.value):null;if(e.action.startsWith("sources_")&&!p)throw new f("INVALID_REQUEST","Choose a current resource");let S=`${o.visit}:${e.nodeId}:${p?.key??""}`,s=ie.get(S)??[null],I=$[e.nodeId]??{page:1,after:null,filter:"all",...p?{resourceKey:p.key}:{}};if(e.action==="filter"){let x=e.value;if(!x||!(r.source==="offer_history"?["all","issued","reserved","redeemed","expired","revoked"]:["all","purchase","refund","source","usage","debt","settlement"]).includes(x))throw new f("INVALID_REQUEST","Unknown data filter");I={page:1,after:null,filter:x},s.splice(0,s.length,null)}else if(e.action==="next"||e.action==="sources_next"){let x=p?.sources.at(-1),M=p?x?{kind:"ledger",cursor:{at:x.detail[0],id:x.id,type:"source"}}:null:d.dataCursors[e.nodeId];if(!M||!p&&!r.hasNext)return;s[I.page]=M,I={...I,page:I.page+1,after:M}}else if(e.action==="previous"||e.action==="sources_previous"){if(I.page<=1)return;I={...I,page:I.page-1,after:s[I.page-2]??null}}ie.set(S,s),$={...$,[e.nodeId]:I},await Y(()=>n.client.get({nodeId:o.nodeId,visit:o.visit,revision:o.revision,components:$}))}function Re(e){let o=e.screen?.presentation;if(!o||o.type==="inline"){R.open&&R.close(),y.parentElement!==b&&b.append(y);return}y.parentElement!==R&&(R.append(y),b.append(R));let d={sm:420,md:640,lg:900};R.style.cssText=`padding:0;border:0;max-width:calc(100vw - 32px);max-height:calc(100dvh - 32px);overflow:auto;width:${"size"in o?d[o.size]+"px":"100vw"}`,R.setAttribute("aria-label",C?.document?.name??e.screen?.content.document.name??"Funnel"),R.open||R.showModal()}async function De(e){if(i)return;z=e,P&&n.client.pendingCommand?.requestId!==P&&(U.hidden=!0,P=null);let o=e.locale.startsWith("zh");if(k.textContent=o?"\u56DE\u770B":"History",k.hidden=!n.client.review,A.textContent=g?o?"\u8FD4\u56DE\u5F53\u524D":"Return to current":o?"\u8FD4\u56DE":"Back",j.textContent=o?"\u5173\u95ED":"Close",V.textContent=o?"\u91CD\u8BD5":"Retry",A.disabled=!g&&(a>0||!!n.client.pendingCommand||!e.canBack),V.hidden=n.client.pendingCommand===null,F.textContent=e.pendingRequest?o?"\u6B63\u5728\u5904\u7406":"Processing":e.instruction?.type==="wait"?o?"\u7B49\u5F85\u4E2D":"Waiting":"",l!==`${e.revision}:${e.visit}:${e.status}:${e.stopped}`&&(l=`${e.revision}:${e.visit}:${e.status}:${e.stopped}`,ne(n.onState,structuredClone(e))),e.stopped||n.client.configurationReady===!1){g=!1,G++,T?.destroy(),T=null,v.replaceChildren(),v.hidden=!0,O.hidden=!1,C?.destroy(),C=null,N?.destroy(),N=null,O.replaceChildren(),Q="",W="",t="",R.open&&R.close(),y.hidden=!0,ue();return}if(y.hidden=!1,g){ue();return}if(e.recoveryRestricted){C?.destroy(),C=null,N?.destroy(),N=null,O.replaceChildren(),Q="",F.textContent=o?"\u539F\u8BB0\u5F55\u9700\u8981\u6838\u5BF9\uFF0C\u53EF\u53EA\u8BFB\u56DE\u770B":"Original records require reconciliation; read-only history is available";return}let d=e.screen||e.paywall?`${e.id}:${e.nodeId}:${e.visit}`:"";if(d!==Q&&(C?.destroy(),C=null,N?.destroy(),N=null,O.replaceChildren(),Q=d,W="",t="",H={...e.answers},$={},ie.clear()),Re(e),e.screen){let h=e.screen.content;C||(C=Z(O,{mode:"live",rendererUrl:n.client.webViewUrl,title:h.document.name,onAction(s,_={},I={}){if(g)return;H={...H,...I};let x=Object.fromEntries((e.screen?.inputs??[]).filter(({variable:M})=>Object.hasOwn(H,M)).map(({variable:M})=>[M,H[M]]));Y(()=>n.client.submit({operation:"submit",...B(),input:{type:"screen",output:s,answers:x,selection:_}}))},onAnswers:s=>{g||(H={...H,...s})},onCustomerDataIntent:s=>{g||Ee(s).catch(J)},onEscape:()=>{g||de()},onError:s=>J(new Error(s)),onRendered:()=>ve(d)}));let p={capabilities:e.screen.capabilities,customerData:e.screen.customerData,parameters:e.parameters,serverInput:{bindings:e.screen.inputs,answers:H,values:e.screen.values}},S=JSON.stringify([h,e.locale,p.parameters,e.screen.inputs,e.screen.values]);if(S!==W)C.update(h.document,e.locale,p),W=S,K=JSON.stringify(p.capabilities),t=JSON.stringify(p.customerData);else{let s=JSON.stringify(p.capabilities);s!==K&&(C.updateCapabilities(p.capabilities),K=s),JSON.stringify(p.customerData)!==t&&(C.updateCustomerData(p.customerData),t=JSON.stringify(p.customerData))}await C.ready}else if(e.paywall&&!N){let h=await te(O,{canInteract:()=>!g&&!i&&!n.client.view?.recoveryRestricted,start:async()=>be(n.client),onPurchase:n.onPurchase,onCheckoutUrl:n.onCheckoutUrl,resolveOfferId:n.resolveOfferId,onEvent:n.onEvent,onOpenUrl:p=>n.onOpenUrl?n.onOpenUrl({receiptId:e.paywall.receiptId,url:p,openIn:"same_window"}):w.defaultView?.location.assign(p),onAction:async p=>{if(g)return;let S=await n.client.submit({operation:"submit",requestId:crypto.randomUUID(),nodeId:e.nodeId,visit:e.visit,revision:e.revision,input:{type:"screen",output:p,answers:{}}});await X(n.client.view??S.run)},onError:J,onDismiss:()=>{!g&&!i&&n.client.view?.visit===e.visit&&de()}});i?h.host?.destroy():(N=h.host,N?.setSuspended(g)),ve(d)}let r=e.instruction;if(r&&(r.type==="open_url"||r.type==="event")&&!ae.has(r.receiptId)){let h=w.createElement("button");h.type="button",h.textContent=r.type==="open_url"?`${o?"\u524D\u5F80":"Continue to"} ${new URL(r.url).host}`:o?"\u7EE7\u7EED":"Continue",h.onclick=()=>{let p=B(),S=r.type==="open_url"&&!n.onOpenUrl&&r.openIn==="new_window"?Pe(r.url):null;Y(async()=>{let s="success";if(r.type==="open_url")if(n.onOpenUrl)try{s=await n.onOpenUrl({receiptId:r.receiptId,url:r.url,openIn:r.openIn})===!1?"failed":"opened"}catch(I){ne(n.onError,I),s="failed"}else s=r.openIn==="new_window"&&!S?"failed":"opened";if(r.type==="event"){if(!n.onEvent)throw new f("EVENT_HANDLER_REQUIRED","Provide the event handler");await n.onEvent(r.event)}if(i||n.client.view?.nodeId!==p.nodeId||n.client.view.visit!==p.visit)throw new f("PRECONDITION_FAILED","The client action visit changed");let _=await n.client.submit({operation:"submit",...p,input:{type:"client_action",receiptId:r.receiptId,outcome:s}});return ae.add(r.receiptId),r.type==="open_url"&&!n.onOpenUrl&&r.openIn==="same_window"&&w.defaultView?.location.assign(r.url),_})},O.replaceChildren(h)}!e.pendingRequest&&e.status==="completed"&&!ae.has(`complete:${e.id}`)&&(ae.add(`complete:${e.id}`),ne(n.onComplete,structuredClone(e))),ue()}function Pe(e){let o=w.defaultView?.open(e,"_blank")??null;return o&&(o.opener=null),o}function X(e){return u=u.catch(()=>{}).then(()=>De(e)),u}async function ce(e){if(i||!n.client.review)return;g||(re=ye(n.client.view),le.set(re,structuredClone(H))),g=!0,he=e,O.hidden=!0,N?.setSuspended(!0),v.hidden=!1;let o=++G;try{let d=await n.client.review(e);if(i||o!==G||!g)return;if(!d.review)throw new f("INVALID_RESPONSE","Historical projection is missing");T?.destroy(),T=null,v.replaceChildren();let r=d.run.locale.startsWith("zh"),h=w.createElement("p");h.textContent=r?"\u53EA\u8BFB\u56DE\u770B":"Read-only history",v.append(h);for(let[s,_]of d.review.pages.entries()){let I=w.createElement("button");I.type="button",I.textContent=r?`\u7B2C ${s+1} \u9875`:`Page ${s+1}`,I.onclick=()=>{ce(_.receiptId)},v.append(I)}if(d.review.page){let s=d.review.page,_=w.createElement("div");if(_.inert=!0,v.append(_),T=Z(_,{mode:"live",rendererUrl:n.client.webViewUrl,title:s.document.name,onAction:()=>{},onAnswers:()=>{},onCustomerDataIntent:()=>{},onRendered:()=>{},onEscape:()=>{fe()}}),T.update(s.document,d.run.locale,{serverInput:{bindings:s.inputs,answers:s.answers,values:s.values}}),await T.ready,i||o!==G||!g)return}let p=r?{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"},S=r?{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 s of[...d.review.coupons.map((_,I)=>`${r?"\u4F18\u60E0\u5238":"Coupon"} ${I+1}: ${p[_.status]}`),...d.review.purchases.map((_,I)=>`${r?"\u8D2D\u4E70":"Purchase"} ${I+1}: ${S[_.status]}`)]){let _=w.createElement("p");_.textContent=s,v.append(_)}n.client.view&&await X(n.client.view)}catch(d){if(o!==G||i)return;T?.destroy(),T=null,v.replaceChildren(),J(d)}}async function fe(){if(!g||i||!n.client.review)return;let e=++G;try{if(await n.client.review(),i||e!==G)return;g=!1,G++,T?.destroy(),T=null,v.replaceChildren(),v.hidden=!0,O.hidden=!1;let o=n.client.view;ye(o)!==re?(le.set(re,structuredClone(H)),Q="",W=""):(le.delete(re),N?.setSuspended(!1)),o&&await X(o)}catch(o){if(e!==G||i)return;T?.destroy(),T=null,v.replaceChildren(),J(o)}}let Ne=n.client.subscribe(e=>{n.client.configurationReady===!1&&(y.hidden=!0,C?.destroy(),C=null,N?.destroy(),N=null,O.replaceChildren(),Q="",W="",t="",R.open&&R.close()),X(e).catch(J)}),Oe=n.client.subscribeError?.(J);function de(){return D||(i?Promise.resolve():n.client.view&&!["running","waiting"].includes(n.client.view.status)?(pe(),Promise.resolve()):(D=Y(()=>n.client.submit({operation:"close",...B()}),!0).then(()=>{n.client.view?.status==="closed"&&pe()}).finally(()=>{D=null}),D))}function pe(){i||(i=!0,c&&clearTimeout(c),Ne(),Oe?.(),C?.destroy(),G++,T?.destroy(),N?.destroy(),R.close(),R.remove(),y.remove(),E instanceof HTMLElement&&E.isConnected&&E.focus(),ne(n.onDismiss,z?structuredClone(z):null))}A.onclick=()=>{if(g){fe();return}Y(()=>n.client.submit({operation:"back",...B()}))},k.onclick=()=>{ce()},j.onclick=()=>{de()},V.onclick=()=>{Y(()=>n.client.retry())},R.addEventListener("cancel",e=>{e.preventDefault(),de()});try{let e=await n.client.get();await X(n.client.view??e.run)}catch(e){throw pe(),e}return{destroy:pe,refresh:ge,review:ce,exitReview:fe,get unappliedDrafts(){return new Map([...le].map(([e,o])=>[e,structuredClone(o)]))}}}export{Fe as showFunnelRun};
|
|
1
|
+
import{a as ne}from"./chunk-6X42DWOM.js";import"./chunk-ET4NANGB.js";import{a as f}from"./chunk-5TEZEOHX.js";import"./chunk-S5TVMQRC.js";import{Gd as Ie,ri as me}from"./chunk-VMLGV5OS.js";import{Gb as Ce}from"./chunk-RMJJOSVZ.js";import"./chunk-OHDY27EI.js";import"./chunk-S2MSIA57.js";function be(b){let q=b.view;if(!q?.paywall)throw new f("INVALID_REQUEST","The current node is not a Paywall");let n=q.paywall.receiptId,Z=q.nodeId,te=q.visit,w=q.paywall.resolution,E=q.paywall.quote,y=q.paywall.operation,O=!1,L=new AbortController,v=q.paywall.purchaseRequestId,k=0,F=q.paywall.selectionGeneration??0,U=q.paywall.canReselect===!0,A=null,j=new Map,V=new Map;function R(t){if(t.purchase&&t.purchase.receiptId!==n)throw new f("INVALID_RESPONSE","Purchase receipt changed");let i=t.run.paywall;return t.purchase??(i?.receiptId===n?i:null)}function C(){if(O)throw new f("IDENTITY_CHANGED","Paywall presentation has closed")}function N(t,i,a){if(C(),i!==k||a!==void 0&&E?.operationId!==a)return!1;let m=F,l=t.run.paywall;if(l?.receiptId===n){if((l.selectionGeneration??0)<F)return!1;if(F=l.selectionGeneration??0,U=l.canReselect===!0,l.resolution.id!==w.id||l.resolution.offering.id!==w.offering.id)throw new f("INVALID_RESPONSE","The pinned Paywall binding changed")}let c=R(t),u=F>m,D=u?c?.quote??null:c?.quote??E,P=c?.operation??(D?.operationId===E?.operationId?y:null);if(D&&P&&D.operationId!==P.operationId)throw new f("INVALID_RESPONSE","Purchase operation changed");return l?.receiptId===n&&(w=l.resolution),(u||D?.operationId!==E?.operationId)&&(k++,l?.receiptId===n&&(v=l.purchaseRequestId)),E=D,(y?.operationId!==P?.operationId||y?.status==="pending"||P?.status==="complete")&&(y=P),!0}function z(t,i,a){return new Promise((m,l)=>{let c=!1,u=()=>{clearTimeout(ie),L.signal.removeEventListener("abort",$)},D=ee=>{c||(c=!0,u(),m(ee))},P=ee=>{c||(c=!0,u(),l(ee))},$=()=>P(new f("IDENTITY_CHANGED","Paywall presentation has closed")),ie=setTimeout(()=>P(new f("COMMAND_PENDING","The purchase command is still pending; retry the original request",202,a)),Math.max(0,i-Date.now()));L.signal.addEventListener("abort",$,{once:!0}),L.signal.aborted&&$(),t.then(D,P)})}function Q(t){return new Promise(i=>{let a=()=>{clearTimeout(m),L.signal.removeEventListener("abort",a),i()},m=setTimeout(a,t);L.signal.addEventListener("abort",a,{once:!0}),L.signal.aborted&&a()})}async function W(t,i,a){C();let m=j.get(t);if(!m){let u=b.pendingCommands?.find(D=>D.requestId===t)??b.pendingCommand;if(u?.operation==="submit"&&u.requestId===t&&u.nodeId===Z&&u.visit===te){i.type==="paywall_quote"&&u.input.type==="paywall_quote"&&u.input.predecessor&&!i.predecessor&&(i={...i,predecessor:u.input.predecessor});let D=me.parse(u),P=me.parse({...u,input:i});if(P.operation!=="submit"||D.operation!=="submit"||JSON.stringify(P.input)!==JSON.stringify(D.input))throw new f("CONFLICT","A restored purchase request cannot change its input");i=P.input,m=D,j.set(t,m)}}if(m){if(JSON.stringify(m.input)!==JSON.stringify(i))throw new f("CONFLICT","A purchase request cannot change its input")}else{let u=b.view;if(!u||u.nodeId!==Z||u.visit!==te||u.paywall?.receiptId!==n)throw new f("PRECONDITION_FAILED","The Paywall visit has changed");m={operation:"submit",requestId:t,nodeId:Z,visit:te,revision:u.revision,input:i},j.set(t,m)}let l=Date.now()+3e4,c=await z(b.submit(m),l,t);for(;c.run.pendingRequest?.requestId===t&&Date.now()<l&&!O&&(await Q(Math.min(1e3,l-Date.now())),!(O||Date.now()>=l));)c=await z(b.resume(t),l,t);if(O)throw new f("IDENTITY_CHANGED","Paywall presentation has closed");if(c.run.pendingRequest?.requestId===t)throw new f("COMMAND_PENDING","The purchase command is still pending; retry the original request",202,t);if(!N(c,a,i.type==="paywall_confirm"||i.type==="paywall_cancel"?i.operationId:void 0))throw new f("PRECONDITION_FAILED","The purchase selection has changed")}async function K(t){if(!E)throw new f("INVALID_REQUEST","A quoted purchase is required");let i=`${t}:${E.operationId}`,a=V.get(i);if(!a){let m=t==="confirm"?"paywall_confirm":"paywall_cancel",l=b.pendingCommands?.find(c=>c.operation==="submit"&&c.input.type===m&&"operationId"in c.input&&c.input.operationId===E.operationId)??b.pendingCommand;a=l?.operation==="submit"&&l.input.type===m&&"operationId"in l.input&&l.input.operationId===E.operationId?l.requestId:crypto.randomUUID(),V.set(i,a)}if(await W(a,{type:t==="confirm"?"paywall_confirm":"paywall_cancel",operationId:E.operationId},k),!y)throw new f("INVALID_RESPONSE","The accepted purchase result is missing");return structuredClone(y)}return{get view(){return structuredClone(w)},get quote(){return E?structuredClone(E):null},get operation(){return y?structuredClone(y):null},get webViewUrl(){return b.webViewUrl},get canReselect(){return U},async refresh(){C();let t=k;return N(await b.get(),t),structuredClone(w)},preview(t){if(v&&v!==t.requestId&&(A||!U))return Promise.reject(new f("COMMAND_PENDING","Retry the original purchase before starting another"));if(v===t.requestId&&A)return A;let i=w.document.buttons[t.actionId],a=i?.type==="checkout"?Ie(i.product,t.selection,w.capabilities):null;if(!a)return Promise.reject(new f("PRODUCT_UNAVAILABLE","Choose an available Product in this purchase area"));let m=v!==t.requestId&&F>0?{operationId:E?.operationId??null,generation:F}:void 0;if(m&&(!U||F<=0))return Promise.reject(new f("COMMAND_PENDING","Original purchase requires authoritative termination"));v!==t.requestId&&k++;let l=k;v=t.requestId;let c=(async()=>{if(await W(t.requestId,{type:"paywall_quote",actionId:t.actionId,productVersionId:a,...m?{predecessor:m}:{},...t.offerId?{offerId:t.offerId}:{},...t.nativeOffer?{nativeOffer:t.nativeOffer}:{}},l),!E)throw new f("INVALID_RESPONSE","The accepted quote is missing");return structuredClone(E)})();return A=c,c.then(()=>{A===c&&(A=null)},u=>{A===c&&(A=null),v===t.requestId&&b.pendingCommand?.requestId!==t.requestId&&u instanceof f&&u.status!==void 0&&u.status<500&&![401,425].includes(u.status)&&(v=null)}),c},confirm:()=>K("confirm"),cancel:()=>K("cancel"),async read(){if(C(),!E)throw new f("INVALID_REQUEST","A quoted purchase is required");let t=E.operationId,i=k,a=b.pendingCommands?.find(u=>u.operation==="submit"&&(u.input.type==="paywall_confirm"||u.input.type==="paywall_cancel")&&u.input.operationId===t)??b.pendingCommand;a?.operation==="submit"&&(a.input.type==="paywall_confirm"||a.input.type==="paywall_cancel")&&a.input.operationId===t&&await b.settle?.(a.requestId);let m=await b.get(void 0,{receiptId:n,operationId:t});C();let l=R(m);if(l?.quote&&l.quote.operationId!==t||l?.operation&&l.operation.operationId!==t)throw new f("INVALID_RESPONSE","Purchase operation changed");let c=N(m,i,t)?y:l?.operation;if(!c)throw new f("INVALID_RESPONSE","The current purchase result is missing");return structuredClone(c)},destroy(){O=!0,L.abort(),j.clear(),V.clear()}}}async function Fe(b,q){let n=q,{mountScreenPreview:Z}=await import("./popup.js"),{showPaywall:te}=await import("./paywall-LBDMGVWZ.js"),w=b.ownerDocument,E=w.activeElement,y=w.createElement("section"),O=w.createElement("div"),L=w.createElement("div"),v=w.createElement("div"),k=w.createElement("button");v.hidden=!0,k.type="button";let F=w.createElement("p"),U=w.createElement("p"),A=w.createElement("button"),j=w.createElement("button"),V=w.createElement("button"),R=w.createElement("dialog");y.dataset.indianaFunnel="",y.setAttribute("aria-busy","false"),y.style.cssText="box-sizing:border-box;width:100%;min-width:0;font:14px/1.5 system-ui,sans-serif;color:#172033;background:#fff",L.style.cssText="display:flex;gap:12px;align-items:center;flex-wrap:wrap;padding:12px 20px",F.setAttribute("role","status"),U.setAttribute("role","alert"),U.hidden=!0,A.type=j.type=V.type="button",L.append(A,F,U,V,k,j),y.append(O,v,L),b.append(y);let C=null,N=null,z=null,Q="",W="",K="",t="",i=!1,a=0,m=!1,l="",c=null,u=Promise.resolve(),D=null,P=null,$={},ie=new Map,ee=new Set,se=new Set,ae=new Set,oe=null,H={},g=!1,he,G=0,T=null,re="",le=new Map,ye=e=>e?`${e.id}:${e.nodeId}:${e.visit}:${e.revision}:${e.paywall?.quote?.operationId??""}`:"",J=(e,o=null)=>{i||(P=o,U.textContent=e instanceof Error?e.message:"Request failed",U.hidden=!1,V.hidden=n.client.pendingCommand===null,ne(n.onError,e))};function B(){let e=n.client.view;if(!e)throw new f("INVALID_REQUEST","No current Run is available");return{requestId:crypto.randomUUID(),nodeId:e.nodeId,visit:e.visit,revision:e.revision}}async function Y(e,o=!1){if(!(a&&!o||i||(g||n.client.view?.recoveryRestricted)&&!o)){a++,y.setAttribute("aria-busy","true"),U.hidden=!0,P=null;try{if(!o&&oe){let r=n.client.view;await oe;let h=n.client.view;if(!r||!h||h.id!==r.id||h.nodeId!==r.nodeId||h.visit!==r.visit||h.stopped||!["running","waiting"].includes(h.status))throw new f("PRECONDITION_FAILED","The screen changed while its display was acknowledged")}if(i)return;let d=await e();i||await X(n.client.view??d.run)}catch(d){J(d,n.client.pendingCommand?.requestId??null)}finally{a=Math.max(0,a-1),y.setAttribute("aria-busy",String(a>0)),i||(V.hidden=n.client.pendingCommand===null,A.disabled=a>0||!!n.client.pendingCommand||!n.client.view?.canBack)}}}function ve(e){if(g||ee.has(e)||se.has(e)||i)return;se.add(e);let o=async()=>{if(g||i||Q!==e){se.delete(e);return}if(a||n.client.pendingCommand){setTimeout(()=>{o()},250);return}let d=(async()=>{let h=n.client.view,p=B();try{await n.client.submit({operation:"shown",...p})}catch(S){if(!(S instanceof f)||S.code!=="CONFLICT"||S.status!==409||n.client.pendingCommand)throw S;await n.client.get();let s=n.client.view;if(i||g||Q!==e||!s||!h||s.id!==h.id||s.source.versionId!==h.source.versionId||s.nodeId!==p.nodeId||s.visit!==p.visit||s.revision<=p.revision||s.stopped||!s.screen||!["running","waiting"].includes(s.status)||n.client.pendingCommand)throw S;await n.client.submit({operation:"shown",...B()})}ee.add(e)})();oe=d;let r=()=>{oe===d&&(oe=null),se.delete(e)};d.then(r,h=>{r(),a||J(h)})};o()}function ue(){c&&clearTimeout(c),!(i||!z||!["running","waiting"].includes(z.status)&&!n.client.pendingCommand)&&(c=setTimeout(()=>{c=null,ge().finally(ue)},z.pendingRequest||n.client.pendingCommand?1500:5e3))}async function ge(){if(!(i||m||a)){if(g){await ce(he);return}m=!0;try{let e=n.client.pendingCommand;e&&n.client.settle&&await n.client.settle(e.requestId);let o=n.client.view,d=$,r=await n.client.get(o?.screen&&Object.keys(d).length?{nodeId:o.nodeId,visit:o.visit,revision:o.revision,components:d}:void 0);!i&&d===$&&await X(n.client.view??r.run)}catch(e){J(e)}finally{m=!1}}}async function Ee(e){let o=n.client.view,d=o?.screen,r=d?.customerData.nodes[e.nodeId];if(i||a||!o||!d||!r)return;if(!["refresh","next","previous","filter","sources_next","sources_previous"].includes(e.action)){let x=C?.document,M=x?Ce(x,e.nodeId):null,we=M?.type==="customer_data"?M.data.outputs?.[e.action]:void 0;we&&d.outputs.includes(we)?await Y(()=>n.client.submit({operation:"submit",...B(),input:{type:"screen",output:we,answers:H,selection:e.value?{[e.nodeId]:e.value}:{}}})):await n.onCustomerDataIntent?.(e,o);return}let p=e.action.startsWith("sources_")?r.resources.find(x=>x.key===e.value):null;if(e.action.startsWith("sources_")&&!p)throw new f("INVALID_REQUEST","Choose a current resource");let S=`${o.visit}:${e.nodeId}:${p?.key??""}`,s=ie.get(S)??[null],I=$[e.nodeId]??{page:1,after:null,filter:"all",...p?{resourceKey:p.key}:{}};if(e.action==="filter"){let x=e.value;if(!x||!(r.source==="offer_history"?["all","issued","reserved","redeemed","expired","revoked"]:["all","purchase","refund","source","usage","debt","settlement"]).includes(x))throw new f("INVALID_REQUEST","Unknown data filter");I={page:1,after:null,filter:x},s.splice(0,s.length,null)}else if(e.action==="next"||e.action==="sources_next"){let x=p?.sources.at(-1),M=p?x?{kind:"ledger",cursor:{at:x.detail[0],id:x.id,type:"source"}}:null:d.dataCursors[e.nodeId];if(!M||!p&&!r.hasNext)return;s[I.page]=M,I={...I,page:I.page+1,after:M}}else if(e.action==="previous"||e.action==="sources_previous"){if(I.page<=1)return;I={...I,page:I.page-1,after:s[I.page-2]??null}}ie.set(S,s),$={...$,[e.nodeId]:I},await Y(()=>n.client.get({nodeId:o.nodeId,visit:o.visit,revision:o.revision,components:$}))}function Re(e){let o=e.screen?.presentation;if(!o||o.type==="inline"){R.open&&R.close(),y.parentElement!==b&&b.append(y);return}y.parentElement!==R&&(R.append(y),b.append(R));let d={sm:420,md:640,lg:900};R.style.cssText=`padding:0;border:0;max-width:calc(100vw - 32px);max-height:calc(100dvh - 32px);overflow:auto;width:${"size"in o?d[o.size]+"px":"100vw"}`,R.setAttribute("aria-label",C?.document?.name??e.screen?.content.document.name??"Funnel"),R.open||R.showModal()}async function De(e){if(i)return;z=e,P&&n.client.pendingCommand?.requestId!==P&&(U.hidden=!0,P=null);let o=e.locale.startsWith("zh");if(k.textContent=o?"\u56DE\u770B":"History",k.hidden=!n.client.review,A.textContent=g?o?"\u8FD4\u56DE\u5F53\u524D":"Return to current":o?"\u8FD4\u56DE":"Back",j.textContent=o?"\u5173\u95ED":"Close",V.textContent=o?"\u91CD\u8BD5":"Retry",A.disabled=!g&&(a>0||!!n.client.pendingCommand||!e.canBack),V.hidden=n.client.pendingCommand===null,F.textContent=e.pendingRequest?o?"\u6B63\u5728\u5904\u7406":"Processing":e.instruction?.type==="wait"?o?"\u7B49\u5F85\u4E2D":"Waiting":"",l!==`${e.revision}:${e.visit}:${e.status}:${e.stopped}`&&(l=`${e.revision}:${e.visit}:${e.status}:${e.stopped}`,ne(n.onState,structuredClone(e))),e.stopped||n.client.configurationReady===!1){g=!1,G++,T?.destroy(),T=null,v.replaceChildren(),v.hidden=!0,O.hidden=!1,C?.destroy(),C=null,N?.destroy(),N=null,O.replaceChildren(),Q="",W="",t="",R.open&&R.close(),y.hidden=!0,ue();return}if(y.hidden=!1,g){ue();return}if(e.recoveryRestricted){C?.destroy(),C=null,N?.destroy(),N=null,O.replaceChildren(),Q="",F.textContent=o?"\u539F\u8BB0\u5F55\u9700\u8981\u6838\u5BF9\uFF0C\u53EF\u53EA\u8BFB\u56DE\u770B":"Original records require reconciliation; read-only history is available";return}let d=e.screen||e.paywall?`${e.id}:${e.nodeId}:${e.visit}`:"";if(d!==Q&&(C?.destroy(),C=null,N?.destroy(),N=null,O.replaceChildren(),Q=d,W="",t="",H={...e.answers},$={},ie.clear()),Re(e),e.screen){let h=e.screen.content;C||(C=Z(O,{mode:"live",rendererUrl:n.client.webViewUrl,title:h.document.name,onAction(s,_={},I={}){if(g)return;H={...H,...I};let x=Object.fromEntries((e.screen?.inputs??[]).filter(({variable:M})=>Object.hasOwn(H,M)).map(({variable:M})=>[M,H[M]]));Y(()=>n.client.submit({operation:"submit",...B(),input:{type:"screen",output:s,answers:x,selection:_}}))},onAnswers:s=>{g||(H={...H,...s})},onCustomerDataIntent:s=>{g||Ee(s).catch(J)},onEscape:()=>{g||de()},onError:s=>J(new Error(s)),onRendered:()=>ve(d)}));let p={capabilities:e.screen.capabilities,customerData:e.screen.customerData,parameters:e.parameters,serverInput:{bindings:e.screen.inputs,answers:H,values:e.screen.values}},S=JSON.stringify([h,e.locale,p.parameters,e.screen.inputs,e.screen.values]);if(S!==W)C.update(h.document,e.locale,p),W=S,K=JSON.stringify(p.capabilities),t=JSON.stringify(p.customerData);else{let s=JSON.stringify(p.capabilities);s!==K&&(C.updateCapabilities(p.capabilities),K=s),JSON.stringify(p.customerData)!==t&&(C.updateCustomerData(p.customerData),t=JSON.stringify(p.customerData))}await C.ready}else if(e.paywall&&!N){let h=await te(O,{canInteract:()=>!g&&!i&&!n.client.view?.recoveryRestricted,start:async()=>be(n.client),onPurchase:n.onPurchase,onCheckoutUrl:n.onCheckoutUrl,resolveOfferId:n.resolveOfferId,onEvent:n.onEvent,onOpenUrl:p=>n.onOpenUrl?n.onOpenUrl({receiptId:e.paywall.receiptId,url:p,openIn:"same_window"}):w.defaultView?.location.assign(p),onAction:async p=>{if(g)return;let S=await n.client.submit({operation:"submit",requestId:crypto.randomUUID(),nodeId:e.nodeId,visit:e.visit,revision:e.revision,input:{type:"screen",output:p,answers:{}}});await X(n.client.view??S.run)},onError:J,onDismiss:()=>{!g&&!i&&n.client.view?.visit===e.visit&&de()}});i?h.host?.destroy():(N=h.host,N?.setSuspended(g)),ve(d)}let r=e.instruction;if(r&&(r.type==="open_url"||r.type==="event")&&!ae.has(r.receiptId)){let h=w.createElement("button");h.type="button",h.textContent=r.type==="open_url"?`${o?"\u524D\u5F80":"Continue to"} ${new URL(r.url).host}`:o?"\u7EE7\u7EED":"Continue",h.onclick=()=>{let p=B(),S=r.type==="open_url"&&!n.onOpenUrl&&r.openIn==="new_window"?Pe(r.url):null;Y(async()=>{let s="success";if(r.type==="open_url")if(n.onOpenUrl)try{s=await n.onOpenUrl({receiptId:r.receiptId,url:r.url,openIn:r.openIn})===!1?"failed":"opened"}catch(I){ne(n.onError,I),s="failed"}else s=r.openIn==="new_window"&&!S?"failed":"opened";if(r.type==="event"){if(!n.onEvent)throw new f("EVENT_HANDLER_REQUIRED","Provide the event handler");await n.onEvent(r.event)}if(i||n.client.view?.nodeId!==p.nodeId||n.client.view.visit!==p.visit)throw new f("PRECONDITION_FAILED","The client action visit changed");let _=await n.client.submit({operation:"submit",...p,input:{type:"client_action",receiptId:r.receiptId,outcome:s}});return ae.add(r.receiptId),r.type==="open_url"&&!n.onOpenUrl&&r.openIn==="same_window"&&w.defaultView?.location.assign(r.url),_})},O.replaceChildren(h)}!e.pendingRequest&&e.status==="completed"&&!ae.has(`complete:${e.id}`)&&(ae.add(`complete:${e.id}`),ne(n.onComplete,structuredClone(e))),ue()}function Pe(e){let o=w.defaultView?.open(e,"_blank")??null;return o&&(o.opener=null),o}function X(e){return u=u.catch(()=>{}).then(()=>De(e)),u}async function ce(e){if(i||!n.client.review)return;g||(re=ye(n.client.view),le.set(re,structuredClone(H))),g=!0,he=e,O.hidden=!0,N?.setSuspended(!0),v.hidden=!1;let o=++G;try{let d=await n.client.review(e);if(i||o!==G||!g)return;if(!d.review)throw new f("INVALID_RESPONSE","Historical projection is missing");T?.destroy(),T=null,v.replaceChildren();let r=d.run.locale.startsWith("zh"),h=w.createElement("p");h.textContent=r?"\u53EA\u8BFB\u56DE\u770B":"Read-only history",v.append(h);for(let[s,_]of d.review.pages.entries()){let I=w.createElement("button");I.type="button",I.textContent=r?`\u7B2C ${s+1} \u9875`:`Page ${s+1}`,I.onclick=()=>{ce(_.receiptId)},v.append(I)}if(d.review.page){let s=d.review.page,_=w.createElement("div");if(_.inert=!0,v.append(_),T=Z(_,{mode:"live",rendererUrl:n.client.webViewUrl,title:s.document.name,onAction:()=>{},onAnswers:()=>{},onCustomerDataIntent:()=>{},onRendered:()=>{},onEscape:()=>{fe()}}),T.update(s.document,d.run.locale,{serverInput:{bindings:s.inputs,answers:s.answers,values:s.values}}),await T.ready,i||o!==G||!g)return}let p=r?{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"},S=r?{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 s of[...d.review.coupons.map((_,I)=>`${r?"\u4F18\u60E0\u5238":"Coupon"} ${I+1}: ${p[_.status]}`),...d.review.purchases.map((_,I)=>`${r?"\u8D2D\u4E70":"Purchase"} ${I+1}: ${S[_.status]}`)]){let _=w.createElement("p");_.textContent=s,v.append(_)}n.client.view&&await X(n.client.view)}catch(d){if(o!==G||i)return;T?.destroy(),T=null,v.replaceChildren(),J(d)}}async function fe(){if(!g||i||!n.client.review)return;let e=++G;try{if(await n.client.review(),i||e!==G)return;g=!1,G++,T?.destroy(),T=null,v.replaceChildren(),v.hidden=!0,O.hidden=!1;let o=n.client.view;ye(o)!==re?(le.set(re,structuredClone(H)),Q="",W=""):(le.delete(re),N?.setSuspended(!1)),o&&await X(o)}catch(o){if(e!==G||i)return;T?.destroy(),T=null,v.replaceChildren(),J(o)}}let Ne=n.client.subscribe(e=>{n.client.configurationReady===!1&&(y.hidden=!0,C?.destroy(),C=null,N?.destroy(),N=null,O.replaceChildren(),Q="",W="",t="",R.open&&R.close()),X(e).catch(J)}),Oe=n.client.subscribeError?.(J);function de(){return D||(i?Promise.resolve():n.client.view&&!["running","waiting"].includes(n.client.view.status)?(pe(),Promise.resolve()):(D=Y(()=>n.client.submit({operation:"close",...B()}),!0).then(()=>{n.client.view?.status==="closed"&&pe()}).finally(()=>{D=null}),D))}function pe(){i||(i=!0,c&&clearTimeout(c),Ne(),Oe?.(),C?.destroy(),G++,T?.destroy(),N?.destroy(),R.close(),R.remove(),y.remove(),E instanceof HTMLElement&&E.isConnected&&E.focus(),ne(n.onDismiss,z?structuredClone(z):null))}A.onclick=()=>{if(g){fe();return}Y(()=>n.client.submit({operation:"back",...B()}))},k.onclick=()=>{ce()},j.onclick=()=>{de()},V.onclick=()=>{Y(()=>n.client.retry())},R.addEventListener("cancel",e=>{e.preventDefault(),de()});try{let e=await n.client.get();await X(n.client.view??e.run)}catch(e){throw pe(),e}return{destroy:pe,refresh:ge,review:ce,exitReview:fe,get unappliedDrafts(){return new Map([...le].map(([e,o])=>[e,structuredClone(o)]))}}}export{Fe as showFunnelRun};
|