@tinkerlandai/indiana-sdk 0.6.2 → 0.6.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -1
- package/README.md +10 -6
- package/README.zh-CN.md +9 -5
- package/THIRD_PARTY_NOTICES.md +28 -0
- package/dist/{chunk-M3DG6ZCT.js → chunk-2EJSV6BA.js} +1 -1
- package/dist/chunk-4K25DELJ.js +1 -0
- package/dist/chunk-63BWE27V.js +1 -0
- package/dist/chunk-CB63JLGT.js +1 -0
- package/dist/{chunk-N6UIDDAX.js → chunk-D7YHFS6B.js} +2 -2
- package/dist/chunk-HTRQPMJO.js +11 -0
- package/dist/chunk-ISUXYPYL.js +1 -0
- package/dist/chunk-QG3WUJG5.js +1 -0
- package/dist/chunk-U6S6AZM6.js +1 -0
- package/dist/chunk-VVSQKVE7.js +1 -0
- package/dist/client-OYRHOMUQ.js +1 -0
- package/dist/{configuration-sync-Bnu8s4pc.d.ts → configuration-sync-C2mytNwU.d.ts} +18 -0
- package/dist/errors-DrdTlPwf.d.ts +57 -0
- package/dist/funnel-runtime-host-NWS3URFA.js +1 -0
- package/dist/{funnel-runtime-start-Zbd5ro5r.d.ts → funnel-runtime-start-sZ8ZCNlq.d.ts} +42 -58
- package/dist/iam.d.ts +131 -0
- package/dist/iam.js +1 -0
- package/dist/index.d.ts +41 -4
- package/dist/index.js +1 -1
- package/dist/native-shell.js +1 -1
- package/dist/openrouter.js +1 -1
- package/dist/page.d.ts +1 -1
- package/dist/page.js +1 -1
- package/dist/paywall-4XZ6NDMY.js +1 -0
- package/dist/popup.d.ts +2 -5
- package/dist/popup.js +3 -14
- package/dist/react-native.d.ts +327 -0
- package/dist/react-native.js +1 -0
- package/dist/server.d.ts +4 -3
- package/dist/server.js +1 -1
- package/dist/src-WV6GZYWA.js +1 -0
- package/dist/visual.d.ts +10 -1
- package/dist/visual.js +2 -1
- package/package.json +15 -2
- package/dist/chunk-BIFEEVQO.js +0 -1
- package/dist/chunk-ET4NANGB.js +0 -1
- package/dist/chunk-J7M7UH74.js +0 -1
- package/dist/chunk-OHDY27EI.js +0 -1
- package/dist/chunk-VMLGV5OS.js +0 -11
- package/dist/funnel-runtime-host-3STQUS6F.js +0 -1
- package/dist/paywall-LBDMGVWZ.js +0 -1
- package/dist/src-X6KT6WIH.js +0 -1
- package/dist/visual-editor-agent-WW65CMKW.js +0 -1
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { S as Scope } from './errors-DrdTlPwf.js';
|
|
3
|
+
export { I as IndianaError } from './errors-DrdTlPwf.js';
|
|
4
|
+
|
|
5
|
+
declare const usageCommandSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
6
|
+
eventName: z.ZodString;
|
|
7
|
+
quantity: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>>;
|
|
8
|
+
properties: z.ZodOptional<z.ZodPipe<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>, z.ZodTransform<{
|
|
9
|
+
[k: string]: string;
|
|
10
|
+
}, Record<string, string | number | boolean>>>>;
|
|
11
|
+
entityId: z.ZodOptional<z.ZodUUID>;
|
|
12
|
+
idempotencyKey: z.ZodString;
|
|
13
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
14
|
+
internal_feature_id: z.ZodUUID;
|
|
15
|
+
quantity: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>>;
|
|
16
|
+
properties: z.ZodOptional<z.ZodPipe<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>, z.ZodTransform<{
|
|
17
|
+
[k: string]: string;
|
|
18
|
+
}, Record<string, string | number | boolean>>>>;
|
|
19
|
+
entityId: z.ZodOptional<z.ZodUUID>;
|
|
20
|
+
idempotencyKey: z.ZodString;
|
|
21
|
+
}, z.core.$strict>]>;
|
|
22
|
+
declare const usageResponseSchema: z.ZodObject<{
|
|
23
|
+
requestId: z.ZodUUID;
|
|
24
|
+
scope: z.ZodObject<{
|
|
25
|
+
projectId: z.ZodString;
|
|
26
|
+
environment: z.ZodEnum<{
|
|
27
|
+
sandbox: "sandbox";
|
|
28
|
+
live: "live";
|
|
29
|
+
}>;
|
|
30
|
+
}, z.core.$strict>;
|
|
31
|
+
receipts: z.ZodArray<z.ZodObject<{
|
|
32
|
+
id: z.ZodUUID;
|
|
33
|
+
internal_feature_id: z.ZodUUID;
|
|
34
|
+
kind: z.ZodEnum<{
|
|
35
|
+
release: "release";
|
|
36
|
+
confirm: "confirm";
|
|
37
|
+
consume: "consume";
|
|
38
|
+
reserve: "reserve";
|
|
39
|
+
refund: "refund";
|
|
40
|
+
expire: "expire";
|
|
41
|
+
}>;
|
|
42
|
+
originalId: z.ZodNullable<z.ZodUUID>;
|
|
43
|
+
quantity: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
|
|
44
|
+
requestedQuantity: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>>;
|
|
45
|
+
overageBehavior: z.ZodOptional<z.ZodEnum<{
|
|
46
|
+
cap: "cap";
|
|
47
|
+
overflow: "overflow";
|
|
48
|
+
}>>;
|
|
49
|
+
accepted: z.ZodBoolean;
|
|
50
|
+
reason: z.ZodNullable<z.ZodEnum<{
|
|
51
|
+
expired: "expired";
|
|
52
|
+
unavailable: "unavailable";
|
|
53
|
+
insufficient_balance: "insufficient_balance";
|
|
54
|
+
limit_exceeded: "limit_exceeded";
|
|
55
|
+
awaiting_topup: "awaiting_topup";
|
|
56
|
+
authorization_required: "authorization_required";
|
|
57
|
+
payment_blocked: "payment_blocked";
|
|
58
|
+
cash_budget_exceeded: "cash_budget_exceeded";
|
|
59
|
+
}>>;
|
|
60
|
+
createdAt: z.ZodISODateTime;
|
|
61
|
+
reservationStatus: z.ZodNullable<z.ZodEnum<{
|
|
62
|
+
pending: "pending";
|
|
63
|
+
expired: "expired";
|
|
64
|
+
confirmed: "confirmed";
|
|
65
|
+
released: "released";
|
|
66
|
+
}>>;
|
|
67
|
+
expiresAt: z.ZodNullable<z.ZodISODateTime>;
|
|
68
|
+
allocations: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
69
|
+
funding: z.ZodLiteral<"balance">;
|
|
70
|
+
sourceId: z.ZodUUID;
|
|
71
|
+
rolloverId: z.ZodNullable<z.ZodUUID>;
|
|
72
|
+
units: z.ZodString;
|
|
73
|
+
amount: z.ZodString;
|
|
74
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
75
|
+
funding: z.ZodLiteral<"unbilled">;
|
|
76
|
+
units: z.ZodString;
|
|
77
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
78
|
+
funding: z.ZodLiteral<"prepaid">;
|
|
79
|
+
sourceId: z.ZodUUID;
|
|
80
|
+
units: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
|
|
81
|
+
amount: z.ZodString;
|
|
82
|
+
pricing: z.ZodArray<z.ZodObject<{
|
|
83
|
+
internal_credit_feature_id: z.ZodNullable<z.ZodUUID>;
|
|
84
|
+
internal_metered_feature_id: z.ZodUUID;
|
|
85
|
+
dimension: z.ZodString;
|
|
86
|
+
counterKey: z.ZodString;
|
|
87
|
+
cycleStart: z.ZodISODateTime;
|
|
88
|
+
unitCost: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
|
|
89
|
+
units: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
|
|
90
|
+
amount: z.ZodString;
|
|
91
|
+
tier: z.ZodNullable<z.ZodNumber>;
|
|
92
|
+
}, z.core.$strict>>;
|
|
93
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
94
|
+
funding: z.ZodLiteral<"postpaid">;
|
|
95
|
+
invoiceLineId: z.ZodNullable<z.ZodUUID>;
|
|
96
|
+
units: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
|
|
97
|
+
authorizationId: z.ZodUUID;
|
|
98
|
+
}, z.core.$strict>], "funding">>;
|
|
99
|
+
}, z.core.$strict>>;
|
|
100
|
+
}, z.core.$strict>;
|
|
101
|
+
declare const entitlementInputSchema: z.ZodObject<{
|
|
102
|
+
requirement: z.ZodObject<{
|
|
103
|
+
internal_feature_id: z.ZodUUID;
|
|
104
|
+
quantity: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
|
|
105
|
+
properties: z.ZodPipe<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>, z.ZodTransform<{
|
|
106
|
+
[k: string]: string;
|
|
107
|
+
}, Record<string, string | number | boolean>>>;
|
|
108
|
+
entityId: z.ZodOptional<z.ZodUUID>;
|
|
109
|
+
}, z.core.$strict>;
|
|
110
|
+
commerce: z.ZodOptional<z.ZodObject<{
|
|
111
|
+
provider: z.ZodEnum<{
|
|
112
|
+
apple: "apple";
|
|
113
|
+
google: "google";
|
|
114
|
+
stripe: "stripe";
|
|
115
|
+
}>;
|
|
116
|
+
currency: z.ZodEnum<{
|
|
117
|
+
USD: "USD";
|
|
118
|
+
EUR: "EUR";
|
|
119
|
+
CNY: "CNY";
|
|
120
|
+
GBP: "GBP";
|
|
121
|
+
JPY: "JPY";
|
|
122
|
+
CAD: "CAD";
|
|
123
|
+
AUD: "AUD";
|
|
124
|
+
NZD: "NZD";
|
|
125
|
+
CHF: "CHF";
|
|
126
|
+
HKD: "HKD";
|
|
127
|
+
SGD: "SGD";
|
|
128
|
+
KRW: "KRW";
|
|
129
|
+
INR: "INR";
|
|
130
|
+
BRL: "BRL";
|
|
131
|
+
MXN: "MXN";
|
|
132
|
+
TWD: "TWD";
|
|
133
|
+
THB: "THB";
|
|
134
|
+
IDR: "IDR";
|
|
135
|
+
MYR: "MYR";
|
|
136
|
+
PHP: "PHP";
|
|
137
|
+
VND: "VND";
|
|
138
|
+
ZAR: "ZAR";
|
|
139
|
+
AED: "AED";
|
|
140
|
+
SAR: "SAR";
|
|
141
|
+
SEK: "SEK";
|
|
142
|
+
NOK: "NOK";
|
|
143
|
+
DKK: "DKK";
|
|
144
|
+
PLN: "PLN";
|
|
145
|
+
CZK: "CZK";
|
|
146
|
+
HUF: "HUF";
|
|
147
|
+
ILS: "ILS";
|
|
148
|
+
TRY: "TRY";
|
|
149
|
+
RON: "RON";
|
|
150
|
+
}>;
|
|
151
|
+
}, z.core.$strict>>;
|
|
152
|
+
paywallId: z.ZodOptional<z.ZodUUID>;
|
|
153
|
+
}, z.core.$strict>;
|
|
154
|
+
type UsageCommand = z.input<typeof usageCommandSchema>;
|
|
155
|
+
interface IndianaReactNativeOptions {
|
|
156
|
+
baseUrl?: string;
|
|
157
|
+
fetch?: typeof globalThis.fetch;
|
|
158
|
+
timeoutMs?: number;
|
|
159
|
+
scope: Scope;
|
|
160
|
+
/** Authenticate the app user on your backend and select its Customer there. No Indiana credential is passed to this callback. */
|
|
161
|
+
usageReporter?: (command: UsageCommand) => Promise<z.output<typeof usageResponseSchema>>;
|
|
162
|
+
}
|
|
163
|
+
/** React Native core APIs. No DOM, WebView, store SDK or server credential is required. */
|
|
164
|
+
declare function createIndianaReactNative(options: IndianaReactNativeOptions): {
|
|
165
|
+
identify(customerToken: string): void;
|
|
166
|
+
reset(): void;
|
|
167
|
+
readHoldings(): Promise<{
|
|
168
|
+
requestId: string;
|
|
169
|
+
scope: {
|
|
170
|
+
projectId: string;
|
|
171
|
+
environment: "sandbox" | "live";
|
|
172
|
+
};
|
|
173
|
+
holdings: {
|
|
174
|
+
customerId: string;
|
|
175
|
+
snapshotAt: string;
|
|
176
|
+
memberships: {
|
|
177
|
+
id: string;
|
|
178
|
+
productId: string;
|
|
179
|
+
productVersionId: string;
|
|
180
|
+
billingProductVersionId: string;
|
|
181
|
+
version: number;
|
|
182
|
+
key: string;
|
|
183
|
+
name: string;
|
|
184
|
+
groupId: string | null;
|
|
185
|
+
membershipType: "addon" | "main";
|
|
186
|
+
status: "unknown" | "active" | "pending" | "trialing" | "expired" | "scheduled" | "trial" | "past_due" | "ended" | "paused";
|
|
187
|
+
cancelAtPeriodEnd: boolean;
|
|
188
|
+
accessEnabled: boolean;
|
|
189
|
+
renewalChange: {
|
|
190
|
+
productVersionId: string;
|
|
191
|
+
name: string;
|
|
192
|
+
version: number;
|
|
193
|
+
effectiveAt: string;
|
|
194
|
+
benefitsAppliedAt: string | null;
|
|
195
|
+
timing: "immediate" | "renewal";
|
|
196
|
+
changeKind: "quantity" | "seats" | "plan";
|
|
197
|
+
seat: {
|
|
198
|
+
key: string;
|
|
199
|
+
fromQuantity: number;
|
|
200
|
+
toQuantity: number;
|
|
201
|
+
} | null;
|
|
202
|
+
status: "pending" | "prepared" | "confirmed" | "scheduled" | "quoted";
|
|
203
|
+
feature?: {
|
|
204
|
+
internal_feature_id: string;
|
|
205
|
+
name: string;
|
|
206
|
+
fromQuantity: number;
|
|
207
|
+
toQuantity: number;
|
|
208
|
+
} | undefined;
|
|
209
|
+
} | null;
|
|
210
|
+
period: {
|
|
211
|
+
phase: "paid" | "trial";
|
|
212
|
+
startsAt: string;
|
|
213
|
+
endsAt: string | null;
|
|
214
|
+
} | null;
|
|
215
|
+
}[];
|
|
216
|
+
membershipsLimited: boolean;
|
|
217
|
+
balances: {
|
|
218
|
+
usageType: "consumable" | "non_consumable" | null;
|
|
219
|
+
accessible: boolean;
|
|
220
|
+
unlimited: boolean;
|
|
221
|
+
available: string;
|
|
222
|
+
held: string;
|
|
223
|
+
debt: string;
|
|
224
|
+
nextExpiresAt: string | null;
|
|
225
|
+
usage: {
|
|
226
|
+
internal_feature_id: string;
|
|
227
|
+
entityId: string | null;
|
|
228
|
+
operationId: string | null;
|
|
229
|
+
usage: string;
|
|
230
|
+
capacity: string | null;
|
|
231
|
+
remaining: string | null;
|
|
232
|
+
withinLimit: boolean;
|
|
233
|
+
revision: number;
|
|
234
|
+
updatedAt: string | null;
|
|
235
|
+
} | null;
|
|
236
|
+
internal_feature_id: string;
|
|
237
|
+
key: string;
|
|
238
|
+
name: string;
|
|
239
|
+
kind: "access" | "metered" | "credit";
|
|
240
|
+
}[];
|
|
241
|
+
balancesLimited: boolean;
|
|
242
|
+
};
|
|
243
|
+
}>;
|
|
244
|
+
checkEntitlement(input: z.input<typeof entitlementInputSchema>): Promise<{
|
|
245
|
+
requestId: string;
|
|
246
|
+
scope: {
|
|
247
|
+
projectId: string;
|
|
248
|
+
environment: "sandbox" | "live";
|
|
249
|
+
};
|
|
250
|
+
check: {
|
|
251
|
+
internal_feature_id: string;
|
|
252
|
+
name: string;
|
|
253
|
+
kind: "access" | "metered" | "credit";
|
|
254
|
+
quantity: string;
|
|
255
|
+
allowed: boolean;
|
|
256
|
+
reason: "unavailable" | "insufficient_balance" | "limit_exceeded" | "awaiting_topup" | "authorization_required" | "payment_blocked" | "cash_budget_exceeded" | "not_entitled" | "capacity_exceeded" | "authentication_required" | null;
|
|
257
|
+
preview: {
|
|
258
|
+
scenario: "feature_flag" | "usage_limit";
|
|
259
|
+
candidates: {
|
|
260
|
+
productId: string;
|
|
261
|
+
productVersionId: string;
|
|
262
|
+
name: string;
|
|
263
|
+
action: "purchase" | "upgrade" | "addon" | "topup";
|
|
264
|
+
membershipId: string | null;
|
|
265
|
+
currency: "USD" | "EUR" | "CNY" | "GBP" | "JPY" | "CAD" | "AUD" | "NZD" | "CHF" | "HKD" | "SGD" | "KRW" | "INR" | "BRL" | "MXN" | "TWD" | "THB" | "IDR" | "MYR" | "PHP" | "VND" | "ZAR" | "AED" | "SAR" | "SEK" | "NOK" | "DKK" | "PLN" | "CZK" | "HUF" | "ILS" | "TRY" | "RON";
|
|
266
|
+
amountMinor: string;
|
|
267
|
+
interval: "week" | "month" | "year" | "free" | "one_time";
|
|
268
|
+
intervalCount: number;
|
|
269
|
+
}[];
|
|
270
|
+
} | null;
|
|
271
|
+
};
|
|
272
|
+
}>;
|
|
273
|
+
trackUsage(command: UsageCommand): Promise<{
|
|
274
|
+
requestId: string;
|
|
275
|
+
scope: {
|
|
276
|
+
projectId: string;
|
|
277
|
+
environment: "sandbox" | "live";
|
|
278
|
+
};
|
|
279
|
+
receipts: {
|
|
280
|
+
id: string;
|
|
281
|
+
internal_feature_id: string;
|
|
282
|
+
kind: "release" | "confirm" | "consume" | "reserve" | "refund" | "expire";
|
|
283
|
+
originalId: string | null;
|
|
284
|
+
quantity: string;
|
|
285
|
+
accepted: boolean;
|
|
286
|
+
reason: "expired" | "unavailable" | "insufficient_balance" | "limit_exceeded" | "awaiting_topup" | "authorization_required" | "payment_blocked" | "cash_budget_exceeded" | null;
|
|
287
|
+
createdAt: string;
|
|
288
|
+
reservationStatus: "pending" | "expired" | "confirmed" | "released" | null;
|
|
289
|
+
expiresAt: string | null;
|
|
290
|
+
allocations: ({
|
|
291
|
+
funding: "prepaid";
|
|
292
|
+
sourceId: string;
|
|
293
|
+
units: string;
|
|
294
|
+
amount: string;
|
|
295
|
+
pricing: {
|
|
296
|
+
internal_credit_feature_id: string | null;
|
|
297
|
+
internal_metered_feature_id: string;
|
|
298
|
+
dimension: string;
|
|
299
|
+
counterKey: string;
|
|
300
|
+
cycleStart: string;
|
|
301
|
+
unitCost: string;
|
|
302
|
+
units: string;
|
|
303
|
+
amount: string;
|
|
304
|
+
tier: number | null;
|
|
305
|
+
}[];
|
|
306
|
+
} | {
|
|
307
|
+
funding: "balance";
|
|
308
|
+
sourceId: string;
|
|
309
|
+
rolloverId: string | null;
|
|
310
|
+
units: string;
|
|
311
|
+
amount: string;
|
|
312
|
+
} | {
|
|
313
|
+
funding: "unbilled";
|
|
314
|
+
units: string;
|
|
315
|
+
} | {
|
|
316
|
+
funding: "postpaid";
|
|
317
|
+
invoiceLineId: string | null;
|
|
318
|
+
units: string;
|
|
319
|
+
authorizationId: string;
|
|
320
|
+
})[];
|
|
321
|
+
requestedQuantity?: string | undefined;
|
|
322
|
+
overageBehavior?: "cap" | "overflow" | undefined;
|
|
323
|
+
}[];
|
|
324
|
+
}>;
|
|
325
|
+
};
|
|
326
|
+
|
|
327
|
+
export { type IndianaReactNativeOptions, type UsageCommand, createIndianaReactNative };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as mA}from"./chunk-QG3WUJG5.js";import{Vf as $}from"./chunk-HTRQPMJO.js";import"./chunk-S5TVMQRC.js";import{b as gA}from"./chunk-ISUXYPYL.js";import"./chunk-U6S6AZM6.js";import"./chunk-4K25DELJ.js";import{a as R}from"./chunk-5TEZEOHX.js";import"./chunk-RMJJOSVZ.js";import"./chunk-S2MSIA57.js";function P(A){return typeof A=="string"?A:String(A)}var MA=/[\ud800-\udbff](?![\udc00-\udfff])|(^|[^\ud800-\udbff])[\udc00-\udfff]/g;function OA(A){return A.replace(MA,"$1\uFFFD")}function AA(A,e){if(typeof A!="object"||A==null){let t="";throw t+="The provided value is not an object",new TypeError(t)}return A}function IA(A){if(A!=null&&(typeof A=="object"||typeof A=="function")){let e=A[Symbol.iterator];if(e==null)return;if(typeof e!="function")throw new TypeError("The provided value is not iterable");let t=e.call(A);if(!t||typeof t!="object")throw new TypeError("Result of the Symbol.iterator method is not an object");return t}}function wA(A){let e;if(Array.isArray(A)){let t=A.map(P);if(t.length===2)return t}else if((e=IA(A))!=null){let t=AA(e.next()),r=AA(e.next());if(!t.done&&!r.done)return[P(t.value),P(r.value)]}throw new TypeError("Each query pair must be an iterable [name, value] tuple")}var PA="0123456789ABCDEF",jA=/(?:%[0-9A-Fa-f]{2})+/g;function B(A){return`%${PA[A>>4&15]}${PA[15&A]}`}function vA(A,e,t=!1){return A>=55296&&A<=57343&&(A=65533),A<=127?t&&A===32?"+":e(A)?B(A):String.fromCharCode(A):A<=2047?B(192|A>>6)+B(128|63&A):A<=65535?B(224|A>>12)+B(128|A>>6&63)+B(128|63&A):B(240|A>>18)+B(128|A>>12&63)+B(128|A>>6&63)+B(128|63&A)}function eA(A){return A>=48&&A<=57?A-48:A>=65&&A<=70?A-65+10:A>=97&&A<=102?A-97+10:-1}function tA(A,e=!1){let t=0;for(;t<A.length;t++){let r=A.charCodeAt(t);if(r===37||e&&r===43)break}return t===A.length?A:(e?A.replace(/\+/g," "):A).replace(jA,r=>{try{return decodeURIComponent(r)}catch{return"\uFFFD".repeat(r.length/3)}})}function O(A){return A<=31||A>126}function QA(A){switch(A){case 32:case 34:case 60:case 62:case 96:return!0;default:return O(A)}}function uA(A){switch(A){case 32:case 34:case 35:case 60:case 62:return!0;default:return O(A)}}function FA(A){return uA(A)||A===39}function rA(A){switch(A){case 63:case 94:case 96:case 123:case 125:return!0;default:return uA(A)}}function G(A){switch(A){case 47:case 58:case 59:case 61:case 64:case 91:case 92:case 93:case 124:return!0;default:return rA(A)}}function yA(A){switch(A){case 33:case 39:case 40:case 41:case 126:return!0;default:return(function(t){switch(t){case 36:case 37:case 38:case 43:case 44:return!0;default:return G(t)}})(A)}}function qA(A,e){return vA(A=A||0,e)}function k(A,e,t=!1){let r=0;for(;r<A.length;r++){let u=A.charCodeAt(r);if(u>=128||t&&u===32||e(u))break}if(r===A.length)return A;let n=A.slice(0,r);for(;r<A.length;r++){let u=A.charCodeAt(r),o=u;if(u>=55296&&u<=56319&&r+1<A.length){let a=A.charCodeAt(r+1);a>=56320&&a<=57343&&(o=(u-55296<<10)+a-56320+65536,r++)}n+=vA(o,e,t)}return n}function cA(A){let e=[],t=0,r=0;for(;r<=A.length;){if(r=A.indexOf("&",t),r<0&&(r=A.length),r!==t){let n=A.slice(t,r),u=n.indexOf("=");u<0&&(u=n.length),e.push([tA(n.slice(0,u),!0),tA(n.slice(u+1),!0)])}if(t=r+1,r===A.length)break}return e}function nA(A){let e="";for(let t=0;t<A.length;t++){let r=k(A[t][0],yA,!0),n=k(A[t][1],yA,!0);e+=t!==0?`&${r}=${n}`:`${r}=${n}`}return e}var _A=[2191,2191,3164,3164,3292,3292,6863,6877,6880,6891,8385,8385,11158,11158,42958,42959,42962,42962,42964,42964,42993,42993,64451,64466,64912,64913,64968,64974,67904,67929,69317,69319,69328,69336,69370,69371,72544,72551,73136,73179,73184,73193,93856,93880,93883,93907,94194,94198,100344,100351,101641,101662,101760,101874,118010,118012,118458,118480,118496,118512,124608,124638,124640,124661,124670,124671,128728,128728,128887,128890,129232,129240,129620,129623,129674,129674,129678,129678,129736,129736,129741,129741,129770,129770,129775,129775,130042,130042,177978,177983,183970,183981,205744,210041],YA=[7296,7297,7298,7299,7300,7301,7302,7303,7304,42958,42962,42964,42993],GA=["\u0432","\u0434","\u043E","\u0441","\u0442","\u0442","\u044A","\u0463","\uA64B","\uA7CF","\uA7D3","\uA7D5","s"],JA=[2381,2381,2509,2509,2637,2637,2765,2765,2893,2893,3021,3021,3149,3149,3277,3277,3387,3388,3405,3405,3530,3530,3642,3642,3770,3770,3972,3972,4153,4154,5908,5909,5940,5940,6098,6098,6752,6752,6980,6980,7082,7083,7154,7155,11647,11647,43014,43014,43052,43052,43204,43204,43347,43347,43456,43456,43766,43766,44013,44013,68159,68159,69702,69702,69744,69744,69759,69759,69817,69817,69939,69940,70080,70080,70197,70197,70378,70378,70477,70477,70606,70608,70722,70722,70850,70850,71103,71103,71231,71231,71350,71350,71467,71467,71737,71737,71997,71998,72160,72160,72244,72244,72263,72263,72345,72345,72767,72767,73028,73029,73111,73111,73537,73538,90415,90415];function WA(A){for(let e=0;e<A.length;e++){let t=A.codePointAt(e);if(t>65535&&e++,t<=32||t===37||t===127||t>=55296&&t<=57343||t>=128&&t<=159||t>=64976&&t<=65007||!(65534&~t)||t===65533)return!0}return!1}var[VA,XA,KA,DA]=[[[],"0,6,7,8,m,w,10,1b,1d,1f,72,73,7k,8k,dt,2rk","AAAAAAAAAAAAAAAAAAAAAP////8AAAAAAAAAAAAAAAA/AAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAwAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAADAAABwfwAAAAAAAMADAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD//w8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD//wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAhAAAAQAAAAAAAAQCAAABAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgACAAAAAAAAAAAAAAAAD//wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAP///////////////wAAAAAAAAAAAAAAAAAAAAA="],[[],"6,7,8,o,4o,7e,7f,7h,7i,7j,dl","AAAAAEF9+P/+BwAAAMAA//8AAPz/////BlADAAAAAJwAAPz///8AAADA//H/5+X8AAAAAAAAAAAA/P///wcAAAAAAAAAAAAAPv0vAD0BAABA/gAA/5/5/f8BAAAAAAAAgAAAAP//////////////AYD/////BQAAAAAAAAAAAAAAAAAAAAAAAP///////wcAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD8g+N8B+AAAAAAAAAAAAAAAAAAAAAAAAP//AwAAYAAAAAAAAAAAAAD/////CwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAANgAAAAAAAAAAAAAAAAA//8fAB4AAAD//wMAAAAAAH3/HgwAAAAAAAD//////////w8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=="],[[],"6,7,8,o,4o,7e,7f,7h,7i,7j,dl","AAAAAP3////+BwAAAMDu//////////////8vAADAAJwAAP3///8AAADg////////AAAAAAAAAAAA/P///wcAAAAAAAAAAAAA////Ab0H//9H/gAA/9////8BAAAAAAAAgAAAAP//////////////AYD/////BQAAAAAAAAAAAAAAAAAAAAAAAP///////wcAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAL/G//8T+AAAAAAAAAAAAAAAAAAAAAAAAP//AwAAfgAAAAAAAAAAAAD+////DwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAANwAAAAAAAAAAAAAAAAA//8fAB4AAAD//wMAAAAAAH3/Hg4AAAAAAAD//////////w8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=="],[[],"0,3,4,5,6,7,8,9,a,b,c,d,e,f,g,j,n,o,p,q,r,s,t,w,18,19,1c,4m,4o,4p,4q,4r,6z,72,73,75,76,77,7e,7h,7i,7j,7k,7l,7m,7n,7o,7p,7q,7r,7s,7t,7u,7v,7w,7x,7y,7z,8k,9t,a2,a3,a7,cc,cv,cx,cy,d6,dc,dd,de,dg,dh,di,dk,dl,2rk,2rl","AAAAAAAAAAAAAAAAAAAAAAAAAAAAIAAAAAAAAAAAAAD//////////////////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD4AwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/v////+/tgAAAAAAAAAAAP8XAAAAAAD4//8AAAEAAAAAAAAAAAAAAMCfnz0AAACAAgAAAP///wcAAAAAAAAAAAAAwP8BAAAAAAAA+A8gAADA++8+AAAAAAAOAAAAAAAAgP8AAAAAAPz///v///8HAAAAAAAAFP4h/gAMAAAAAgAAAAAAABAeIAAADAAAQAYAAAAAAAAQhjkCAAAAIwAGAAAAAAAAEL4hAAAMAAD8AgAAAAAAAJAeIGAADAAAAAQAAAAAAAAAASAAAAAAAAARAAAAAAAA0ME9YAAMAAAAAgAAAAAAAJBAMAAADAAAAAMAAAAAAAAYHiAAAAwAAAACAAAAAAAAAAAEXAAAAAAAAAAAAAAA8geAfwAAAAAAAAAAAAAAAPIfAH8AAAAAAAAAAAADAACgAgAAAAAAAP5/3+D//v///x9AAAAAAAAAAAAAAAAA4P1mAAAAwwEAHgBkIAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADgAAAAAAAAAAAAAAAAAAAAAAAAAAAAABwAAAAMAAAADAAAAAwAAAAAAAAAsD9A/g8gAAAAAAC4AAAAAAAAAAAAAAAAAABgAAAAAAIAAAAAAAAAAAAAAAAAAIcBBA4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIAJAAAAAAAAQH/lH/ifAAAAAAAA//////8//w8AAA8AAAAAANAXBAAAAAD4DwADAAAAPDsAAAAAAABAowMAAAAAAADwzwAAAAAAAAAAAAAAAAAAAAAAAAD3//0hEAMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD//////////wDIAAAAfAAAAAAAAB/8AAAAAAAAAAAAAAAA/////wEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAwAAAAAAAAAAAAAAAAAAAACAAAAAAAAAAAAAAAAA/////wAAAAAAPAAAAAAAAAAAAAAAAAAGAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAID3PwAAAMAAAAAAAAAAAAAAAwBECAAAYBAAAAAAAAAAAAAAAAAAAAAAAAAwAAAA//8DgAAAAADAPwAAgP8DAAAAAAAHAAAAAADIMwAAAAAgAAAAAAAAAAB+ZgAIEAAAAAAAEAAAAAAAAJ3BAgAAAAAwQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAICEAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA//8AAP//AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAMAHAAAAAAAAAAAAAAAAAAAAAG7wAAAAAACHAAAAAAAAAAAAAAAAAAAAAAAAAABgAAAAAAAAAPAAAAAAAAAAAD4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAYAAAAAAAAAAAA/AAAAAAAAAAAwP8BAAAAAAA8AAAAAAAAAAAAAAAAAAAAAgAAAAAAAP9/AAAAAAAZgAMAAAAAAHgGBAAAAAAAAAAHAAAAgO8fAAAAAAAAAAgAAwAAAAAAwH8AngAAAAAAAAAAAAAAgNNAAgAAAAAAAAAAAAAAAAAAAAAAAID4BwAAAwAAAAAAABgBAAAAwB8fAAAAAAAAAAD4AUAFAAYAAAAAAAAAAAAA/1wAAEAAAAAAAAAAAAAA+IUNAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA8sAEAADAAAAAAAAAAAAAA+KcBAAAAAAAAAAAAAAAAKL8AAAAAAAAAAAAAAACgvA8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgP8GAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFgIAAAAAAAAAAAAAAAAAAAAAADwDAEAAAD+BwAAAAD4eYAAfg4AAAAAAPx/AwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAF0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAf78AAAAAAAAAAAAA/P///G0AAAAAAAAAAAAAAAAAAAB+tL8AAAAAAAAAAACjAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABgAAwAAAAAAwAcFAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD//4H/PwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMD/4wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHwAAAAAAAAB/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIAAAAAAAAAAgAcAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGAPAAAAAAAAAAAAAAD//////z///38AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIAD+P/nDwAAADwAAAAAAAAAAAAAAAAAAAAAAAAcAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD///////9/+P//////HyAAEAAA+P7/AAAAAAAAAAAAAH////nbBwAAAAAAAAAAAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAfwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAPAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAASMAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAfwAAAAAAAAAAAAAAAADwDwAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAAA////////////////AAAAAAAAAAAAAAAAAAAAAP///////////////////////////////////////wAA"]].map(function([e,t,r]){return[e,t.split(",").map(n=>parseInt(n,36)),Uint8Array.from(atob(r),n=>n.charCodeAt(0))]});function ZA(A,e){return e===931||e===1010||e===120531||e===120589||e===120647||e===120705||e===120763?"\u03C3":e>=5112&&e<=5117?String.fromCodePoint(e-8):e>=43888&&e<=43967?String.fromCodePoint(e-38864):e>=93856&&e<=93880?String.fromCodePoint(e+27):e===837||e===890||e>=8064&&e<=8111||e>=8114&&e<=8188?A.normalize("NFD").replace(/\u0345/g,"\u03B9").normalize("NFC").toLowerCase():""}function BA(A,e){for(let t=0;t<A.length;t+=2)if(e>=A[t]&&e<=A[t+1])return!0;return!1}function x(A,e){let[t,r,n]=A,u=e>>8;for(let h=0;h<t.length;h+=2)if(u>=t[h]&&u<=t[h+1])return!0;let o=r.indexOf(u);if(o<0)return!1;let a=255&e;return!!(n[32*o+(a>>3)]&1<<(7&a))}function Ae(A){let e=Array.from(A,t=>t.codePointAt(0));for(let t=0;t<e.length;t++){let r=e[t];if(r!==8204&&r!==8205||t>0&&BA(JA,e[t-1]))continue;if(r===8205)return!1;let n=t-1;for(;n>=0&&x(DA,e[n]);)n--;let u=t+1;for(;u<e.length&&x(DA,e[u]);)u++;if(!(n>=0&&u<e.length&&x(XA,e[n])&&x(KA,e[u])))return!1}return!0}var ee=/(?![\p{Mark}\p{Decimal_Number}])[\p{Script=Arabic}\p{Script=Hebrew}]/u,te=/\p{Script=Latin}/u;function re(A){return!ee.test(A)||!te.test(A)}var z=36,F=1,sA=26,ne=38,se=700,ie=72,le=128,oe=2147483647;function CA(A){return String.fromCharCode(A+22+75*+(A<26))}function ue(A,e,t){let r=0;for(A=t?Math.floor(A/se):A>>1,A+=Math.floor(A/e);A>(z-F)*sA>>1;r+=z)A=Math.floor(A/(z-F));return Math.floor(r+(z-F+1)*A/(A+ne))}function ce(A){let e=Array.from(A,h=>h.codePointAt(0)),t="",r=0;for(let h=0;h<e.length;h++){let p=e[h];p<128&&(t+=String.fromCharCode(p),r++)}let n=r;n&&(t+="-");let u=le,o=0,a=ie;for(;r<e.length;){let h=oe;for(let p=0;p<e.length;p++){let g=e[p];g>=u&&g<h&&(h=g)}o+=(h-u)*(r+1),u=h;for(let p=0;p<e.length;p++){let g=e[p];if(g<u&&o++,g===u){let D=o;for(let S=z;;S+=z){let E=S<=a?F:S>=a+sA?sA:S-a;if(D<E)break;t+=CA(E+(D-E)%(z-E)),D=Math.floor((D-E)/(z-E))}t+=CA(D),a=ue(o,r+1,r===n),o=0,r++}}o++,u++}return t}function X(A){let e=10;if(A.length>=2&&A[0]==="0"&&(A[1]==="x"||A[1]==="X"))A=A.slice(2),e=16;else if(A.length>=2&&A[0]==="0")A=A.slice(1),e=8;else if(A==="")return-1;let t=0;for(let r=0;r<A.length;r++){let n=eA(A.charCodeAt(r));if(n>=e||n<0)return-1;t=t*e+n}return t}function bA(A){switch(A){case".":case"%2e":case"%2E":return!0;default:return!1}}function kA(A,e){return(A>=65&&A<=90||A>=97&&A<=122)&&(e===58||e===124)}function UA(A){return A.length===2&&kA(A.codePointAt(0),A.codePointAt(1))}function SA(A){return A.search(/\u0000|\u0009|\u000A|\u000D|\u0020|#|\/|:|<|>|\?|@|\[|\\|\]|\^|\|/u)!==-1}function C(A){switch(A){case"ftp":case"http":case"https":case"ws":case"wss":case"file":return!0;default:return!1}}function RA(A){switch(A){case"ftp":return 21;case"http":case"ws":return 80;case"https":case"wss":return 443;default:return null}}function iA(A,e){if(A[0]==="[")return A[A.length-1]==="]"?(function(r){let n=[0,0,0,0,0,0,0,0],u=null,o=0,a=0,h=Array.from(r,p=>p.codePointAt(0));if(h[a]===58){if(h[a+1]!==58)return null;a+=2,o++,u=o}for(;a<h.length;){if(o===8)return null;if(h[a]===58){if(u!==null)return null;a++,o++,u=o;continue}let p=0,g=0,D=0;for(;D<4&&(p=eA(h[a]))>=0;)g=(g<<4)+p,a++,D++;if(h[a]===46){if(D===0||o>6)return null;a-=D;let S=0;for(;h[a]!==void 0;){let E=0;if(S>0)if(h[a]===46&&S<4)a++;else return null;if(h[a]==null||h[a]<48||h[a]>57)return null;for(;h[a]>=48&&h[a]<=57;){if(E=10*E+eA(h[a]),E>255)return null;a++}n[o]=256*n[o]+E,S++,S%2==0&&o++}if(S!==4)return null;break}else if(h[a]===58){if(h[++a]===void 0)return null}else if(h[a]!==void 0)return null;n[o]=g,o++}if(u!==null){let p=o-u;for(o=7;o!==0&&p>0;){let g=n[u+p-1];n[u+p-1]=n[o],n[o]=g,o--,p--}}else if(u===null&&o!==8)return null;return n})(A.substring(1,A.length-1)):null;if(e)return(function(r){return SA(r)?null:k(r,O)})(A);{let t=(function(n){let u=!1,o=!1;for(let h=0;h<n.length;h++){let p=n.charCodeAt(h);if(p<=32||p===37||p===127)return null;if(p>=128){u=!0;break}p>=65&&p<=90&&(o=!0)}if(!u)return n!==""?o?n.toLowerCase():n:null;if((function(p){for(let g of p){let D=g.codePointAt(0);if(/[\p{Cn}\p{Co}\p{Cs}\p{Noncharacter_Code_Point}]/u.test(g)&&!BA(_A,D)||x(VA,D))return!0}return!1})(n))return null;let a=(n=(function(p){let g="";for(let D of p){let S=D.codePointAt(0);if(S!==8204&&S!==8205&&/\p{Default_Ignorable_Code_Point}/u.test(D))continue;let E=ZA(D,S);if(E){g+=E;continue}let dA=YA.indexOf(S);g+=dA<0?D:GA[dA]}return g})(n).normalize("NFKC").replace(/[\u3002\uff0e\uff61]/g,".").toLowerCase()).split(".");for(let h=0;h<a.length;h++){let p=a[h];if(p==="")continue;let g=/[^\0-\x7f]/.test(p);if(WA(p)||g&&(/^\p{Mark}/u.test(p)||!Ae(p)||!re(p)||p.startsWith("xn--")))return null;g&&(a[h]=`xn--${ce(p)}`)}return(n=a.join("."))!==""?n:null})(A.indexOf("%")===-1?A:tA(A));return t===null||SA(t)?null:(function(n){let u=n.length,o=n.lastIndexOf(".",u-2)+1;if(n.charCodeAt(u-1)===46&&u--,u<=o)return!1;if(X(n.slice(o,u))>=0)return!0;for(;o<u;o++){let a=n.charCodeAt(o);if(a<48||a>57)return!1}return!0})(t)?(function(n){let u=n.split("."),o=u.length;if(u[o-1]||o--,o>4)return null;let a=0;for(let p=0;p<o-1;p++){let g=X(u[p]);if(g<0||g>255)return null;a+=g*(1<<8*(3-p))}let h=X(u[o-1]);return h<0||h>=256**(5-o)?null:(a+=h,a)})(t):t}}function lA(A){return typeof A=="number"?(function(t){let n="";return n+=`${(t>>>24&255).toString(10)}.`,n+=`${(t>>>16&255).toString(10)}.`,n+=`${(t>>>8&255).toString(10)}.`,n+=(t&255).toString(10),n})(A):Array.isArray(A)?`[${(function(t){let r=(function(a){let h=-1,p=-1,g=1,D=0;for(let S=0;S<a.length;++S)a[S]!==0?(D>g&&(h=p,g=D),p=-1,D=0):(p===-1&&(p=S),++D);return D>g?p:h})(t),n="",u=!1;for(let o=0;o<=7;++o)if(!(u&&t[o]===0)){if(u&&(u=!1),r===o){n+=o===0?"::":":",u=!0;continue}n+=t[o].toString(16),o!==7&&(n+=":")}return n})(A)}]`:A}function zA(A){A.path.length>0&&(A.path.length!==1||A.scheme!=="file"||!(function(t){return/^[A-Za-z]:$/u.test(t)})(A.path[0]))&&A.path.pop()}function HA(A){return A.username!==""||A.password!==""}function K(A){return A.host===null||A.host===""||A.scheme==="file"}var s=0,i="",d="",m=null,l,_=!1,Y=!1,L=!1,b;function I(A,e,t,r){e||(A=(function(o){let a=0,h=o.length;for(;a<h&&!(o.charCodeAt(a)>32);++a);for(;h>a&&!(o.charCodeAt(h-1)>32);--h);return o.substring(a,h)})(A)),A=(function(o){let a=0;for(;a<o.length;a++){let p=o.charCodeAt(a);if(p===9||p===10||p===13)break}if(a===o.length)return o;let h=o.slice(0,a);for(;a<o.length;a++){let p=o.charCodeAt(a);p!==9&&p!==10&&p!==13&&(h+=o[a])}return h})(A),s=0,i=A,d="",m=t||null,l=e||{scheme:"",username:"",password:"",host:null,port:null,path:[],query:null,fragment:null,opaquePath:!1},_=!1,Y=!1,L=!1,b=r||0;let n=ae;switch(r){case 3:case 4:n=J;break;case 5:n=fA;break;case 6:n=N;break;case 7:n=H;break;case 8:n=U}return n(c(A,s))!==1?l:null}function f(A,e){return s+=s===A?v(e):1,s<=i.length}function c(A,e){return e<A.length?A.codePointAt(e):void 0}function v(A){return A!=null&&A>65535?2:1}function LA(A){return A==null?"":A<=65535?String.fromCharCode(A):String.fromCodePoint(A)}var ae=A=>{let e=s;if(A!=null&&(A>=65&&A<=90||A>=97&&A<=122)){let t=s+1;for(A=i.charCodeAt(t);A===43||A===45||A===46||A>=65&&A<=90||A>=97&&A<=122||A>=48&&A<=57;)t++,A=i.charCodeAt(t);return d=i.slice(s,t).toLowerCase(),s=t,fe(t<i.length?A:void 0)}else return b?1:(--s,f(e,A)?NA(c(i,s)):0)},fe=A=>{let e=s;if(A===58){if(b){if(C(l.scheme)!==C(d))return 0;if((HA(l)||l.port!==null)&&d==="file")return 0;if(l.scheme==="file"&&l.host==="")return 0}return l.scheme=d,b?(l.port===RA(l.scheme)&&(l.port=null),0):(d="",l.scheme==="file"?f(e,A)?hA(c(i,s)):0:C(l.scheme)&&m!==null&&m.scheme===l.scheme?f(e,A)?he(c(i,s)):0:C(l.scheme)?f(e,A)?de(c(i,s)):0:c(i,s+1)===47?(s++,f(e,A)?pe(c(i,s)):0):(l.path=[""],l.opaquePath=!0,f(e,A)?TA(c(i,s)):0))}else return b?1:(d="",s=-1,f(e,A)?NA(c(i,s)):0)},NA=A=>{let e=s;return m===null||m.opaquePath&&A!==35?1:m.opaquePath&&A===35?(l.scheme=m.scheme,l.path=m.path.slice(),l.opaquePath=m.opaquePath,l.query=m.query,l.fragment="",f(e,A)?U(c(i,s)):0):m.scheme==="file"?(s--,f(e,A)?hA(c(i,s)):0):(s--,f(e,A)?aA(c(i,s)):0)},he=A=>{let e=s;return A===47&&c(i,s+1)===47?(++s,f(e,A)?V(c(i,s)):0):(s--,f(e,A)?aA(c(i,s)):0)},pe=A=>{let e=s;return A===47?f(e,A)?T(c(i,s)):0:(s--,f(e,A)?q(c(i,s)):0)},aA=A=>{let e=s;return l.scheme=m.scheme,A===47||C(l.scheme)&&A===92?f(e,A)?EA(c(i,s)):0:(l.username=m.username,l.password=m.password,l.host=m.host,l.port=m.port,l.path=m.path.slice(),l.query=m.query,A===63?(l.query="",f(e,A)?H(c(i,s)):0):A===35?(l.fragment="",f(e,A)?U(c(i,s)):0):A!=null?(l.query=null,l.path.pop(),s--,f(e,A)?q(c(i,s)):0):f(e,A)?aA(c(i,s)):0)},EA=A=>{let e=s;return C(l.scheme)&&(A===47||A===92)?f(e,A)?V(c(i,s)):0:A===47?f(e,A)?T(c(i,s)):0:(l.username=m.username,l.password=m.password,l.host=m.host,l.port=m.port,s--,f(e,A)?q(c(i,s)):0)},de=A=>{let e=s;return A===47&&c(i,s+1)===47?s++:s--,f(e,A)?V(c(i,s)):0},V=A=>{let e=s;return A!==47&&A!==92?(s--,f(e,A)?T(c(i,s)):0):f(e,A)?V(c(i,s)):0},T=A=>{let e=s;if(A!=null&&A!==64&&A!==35&&A!==47&&A!==63&&(A!==92||!C(l.scheme))){let t=s+v(A);for(;t<i.length;){let r=c(i,t);if(r==null||r===64||r===35||r===47||r===63||r===92&&C(l.scheme))break;t+=v(r)}return d+=i.slice(s,t),s=t-1,f(e,A)?T(c(i,s)):0}if(A===64){_&&(d=`%40${d}`),_=!0;for(let t=0;t<d.length;t++){let r=d.codePointAt(t);if(r===58&&!Y){Y=!0;continue}let n=qA(r,G);Y?l.password+=n:l.username+=n,r!=null&&r>65535&&t++}return d="",f(e,A)?T(c(i,s)):0}else return A==null||A===35||A===47||A===63||A===92&&C(l.scheme)?_&&d===""?1:(s-=d.length+1,d="",f(e,A)?J(c(i,s)):0):(d+=LA(A),f(e,A)?T(c(i,s)):0)},J=A=>{let e=s;if(b&&l.scheme==="file")return s--,f(e,A)?pA(c(i,s)):0;if(A!=null&&A!==58&&A!==35&&A!==47&&A!==63&&(A!==92||!C(l.scheme))){let t=s+v(A);for(A===91?L=!0:A===93&&(L=!1);t<i.length;){let r=c(i,t);if(r==null||!L&&r===58||r===35||r===47||r===63||r===92&&C(l.scheme))break;r===91?L=!0:r===93&&(L=!1),t+=v(r)}return d+=i.slice(s,t),s=t-1,f(e,A)?J(c(i,s)):0}else if(A===58&&!L){if(d===""||b===4)return 1;let t=iA(d,!C(l.scheme));return t===null?1:(l.host=lA(t),d="",f(e,A)?fA(c(i,s)):0)}else if(A==null||A===35||A===47||A===63||A===92&&C(l.scheme)){if(s--,C(l.scheme)&&d==="")return 1;if(b&&d===""&&(HA(l)||l.port!==null))return 1;let t=iA(d,!C(l.scheme));return t===null?1:(l.host=lA(t),d="",b?0:f(e,A)?N(c(i,s)):0)}else return d+=LA(A),f(e,A)?J(c(i,s)):0},fA=A=>{let e=s;if(A!=null&&A>=48&&A<=57){let t=s+1;for(;t<i.length;){let r=i.charCodeAt(t);if(r<48||r>57)break;t++}return d+=i.slice(s,t),s=t-1,f(e,A)?fA(c(i,s)):0}else if(b||A==null||A===35||A===47||A===63||A===92&&C(l.scheme)){if(d!==""){let t=parseInt(d,10);if(t>65535)return 1;if(l.port=t===RA(l.scheme)?null:t,d="",b)return 0}return b?1:(s--,f(e,A)?N(c(i,s)):0)}else return 1};function $A(A,e){let t=A.length-e;if(t<2)return!1;if(kA(c(A,e),c(A,e+1))){if(t===2)return!0;{let r=c(A,e+2);return r===47||r===92||r===63||r===35}}else return!1}var hA=A=>{let e=s;return l.scheme="file",l.host="",A===47||A===92?f(e,A)?ge(c(i,s)):0:m?.scheme==="file"?(l.host=m.host,l.path=m.path.slice(),l.opaquePath=m.opaquePath,l.query=m.query,A===63?(l.query="",f(e,A)?H(c(i,s)):0):A===35?(l.fragment="",f(e,A)?U(c(i,s)):0):A!=null?(l.query=null,$A(i,s)?l.path=[]:zA(l),s--,f(e,A)?q(c(i,s)):0):f(e,A)?hA(c(i,s)):0):(s--,f(e,A)?q(c(i,s)):0)},ge=A=>{let e=s;return A===47||A===92?f(e,A)?pA(c(i,s)):0:(m!==null&&m.scheme==="file"&&(!$A(i,s)&&(function(r){if(r.length===2){let n=r.codePointAt(0),u=r.codePointAt(1);return(n>=65&&n<=90||n>=97&&n<=122)&&u===58}else return!1})(m.path[0])&&l.path.push(m.path[0]),l.host=m.host),s--,f(e,A)?q(c(i,s)):0)},pA=A=>{let e=s;if(A!=null&&A!==47&&A!==92&&A!==63&&A!==35){let t=s+v(A);for(;t<i.length;){let r=c(i,t);if(r==null||r===47||r===92||r===63||r===35)break;t+=v(r)}return d+=i.slice(s,t),s=t-1,f(e,A)?pA(c(i,s)):0}else if(A==null||A===47||A===92||A===63||A===35){if(s--,!b&&UA(d))return f(e,A)?q(c(i,s)):0;if(d==="")return l.host="",b?0:f(e,A)?N(c(i,s)):0;{let t=iA(d,!C(l.scheme));return t===null?1:(t==="localhost"&&(t=""),l.host=lA(t),d="",b?0:f(e,A)?N(c(i,s)):0)}}return 1},N=A=>{let e=s;return C(l.scheme)?(A!==92&&A!==47&&s--,f(e,A)?q(c(i,s)):0):!b&&A===63?(l.query="",f(e,A)?H(c(i,s)):0):!b&&A===35?(l.fragment="",f(e,A)?U(c(i,s)):0):A!=null?(A!==47&&s--,f(e,A)?q(c(i,s)):0):(b&&l.host===null&&l.path.push(""),f(e,A)?N(c(i,s)):0)},q=A=>{let e=s;if(A!=null&&A!==47&&(!C(l.scheme)||A!==92)&&(b||A!==63&&A!==35)){let t=s+v(A);for(;t<i.length;){let r=c(i,t);if(r==null||r===47||C(l.scheme)&&r===92||!b&&(r===63||r===35))break;t+=v(r)}d+=k(i.slice(s,t),rA),s=t,A=c(i,t)}if(A==null||A===47||C(l.scheme)&&A===92||!b&&(A===63||A===35)){let t=C(l.scheme)&&A===92;return(function(n){switch(n){case"..":case"%2e.":case"%2E.":case".%2e":case".%2E":case"%2e%2e":case"%2E%2e":case"%2e%2E":case"%2E%2E":return!0;default:return!1}})(d)?(zA(l),A!==47&&!t&&l.path.push("")):bA(d)&&A!==47&&!t?l.path.push(""):bA(d)||(l.scheme==="file"&&l.path.length===0&&UA(d)&&(d=`${d[0]}:`),l.path.push(d)),d="",A===63?(l.query="",f(e,A)?H(c(i,s)):0):A===35?(l.fragment="",f(e,A)?U(c(i,s)):0):f(e,A)?q(c(i,s)):0}else return d+=qA(A,rA),f(e,A)?q(c(i,s)):0},TA=A=>{let e=s;if(A===63)return l.query="",f(e,A)?H(c(i,s)):0;if(A===35)return l.fragment="",f(e,A)?U(c(i,s)):0;if(A!=null){let t=s+v(A);for(;t<i.length;){let n=c(i,t);if(n===63||n===35)break;t+=v(n)}let r=i.slice(s,t);if(t<i.length&&r.charCodeAt(r.length-1)===32?l.path[0]+=k(r.slice(0,-1),O)+"%20":l.path[0]+=k(r,O),s=t,(A=c(i,t))===63)return l.query="",f(e,A)?H(c(i,s)):0;if(A===35)return l.fragment="",f(e,A)?U(c(i,s)):0}return f(e,A)?TA(c(i,s)):0},H=A=>{let e=s,t=s;if(A!=null){if(b)t=i.length;else{let n=i.indexOf("#",s);t=n===-1?i.length:n}let r=C(l.scheme)?FA:uA;l.query+=k(i.slice(s,t),r)}return s=t,c(i,t)===35&&!b?(l.fragment="",f(e,A)?U(c(i,s)):0):f(e,A)?H(c(i,s)):0},U=A=>{let e=s;return A!=null&&(l.fragment+=k(i.slice(s),QA),s=i.length),f(e,A)?U(c(i,s)):0};function oA(A){if(A.opaquePath)return A.path[0];{let e="";for(let t of A.path)e+=`/${t}`;return e}}function xA(A){switch(A.scheme){case"blob":{let e=I(oA(A),null,null,0);return e===null||e.scheme!=="http"&&e.scheme!=="https"?"null":xA(e)}case"ftp":case"http":case"https":case"ws":case"wss":return(function(t){let r=`${t.scheme}://`;return r+=t.host,t.port!==null&&(r+=`:${t.port}`),r})(A);default:return"null"}}var w=Symbol("URLImpl"),j=class A{constructor(e,t){if(e===void 0&&t===void 0)throw new TypeError('The "url" argument must be specified.');e=P(e),t!=null&&(t=P(t));let r=null;if(t!=null&&(r=I(t,null,null,0),r==null))throw new TypeError(`Invalid base URL: ${t}`);let n=I(e,null,r,0);if(n==null)throw new TypeError(`Invalid URL: ${e}`);this[w]={url:n,query:null}}static createObjectURL(e){throw new TypeError("URL.createObjetURL is unsupported")}static revokeObjectURL(e){}static parse(e,t){e=P(e),t!==void 0&&(t=P(t));try{return new A(e,t)}catch{return null}}static canParse(e,t){e=P(e),t!==void 0&&(t=P(t));let r=null;return t!=null&&(r=I(t,null,null,0),r==null)?!1:I(e,null,r,0)!=null}get href(){return(function(t){let r=`${t.scheme}:`;return t.host!==null&&(r+="//",(t.username!==""||t.password!=="")&&(r+=t.username,t.password!==""&&(r+=`:${t.password}`),r+="@"),r+=t.host,t.port!==null&&(r+=`:${t.port}`)),t.host===null&&!t.opaquePath&&t.path.length>1&&t.path[0]===""&&(r+="/."),r+=oA(t),t.query!==null&&(r+=`?${t.query}`),t.fragment!==null&&(r+=`#${t.fragment}`),r})(this[w].url)}set href(e){let t=I(e=P(e),null,null,0);if(t==null)throw new TypeError(`Invalid URL: ${e}`);this[w].url=t,this[w].query&&Z(this[w].query,t.query)}get origin(){return xA(this[w].url)}get protocol(){return`${this[w].url.scheme}:`}set protocol(e){I(`${e=P(e)}:`,this[w].url,null,2)}get username(){return this[w].url.username}set username(e){e=P(e),K(this[w].url)||(function(r,n){r.username=k(n,G)})(this[w].url,e)}get password(){return this[w].url.password}set password(e){e=P(e),K(this[w].url)||(function(r,n){r.password=k(n,G)})(this[w].url,e)}get host(){let{url:e}=this[w];return e.host==null?"":e.port==null?e.host:`${e.host}:${e.port}`}set host(e){e=P(e),this[w].url.opaquePath||I(e,this[w].url,null,3)}get hostname(){let{url:e}=this[w];return e.host!=null?e.host:""}set hostname(e){e=P(e),this[w].url.opaquePath||I(e,this[w].url,null,4)}get port(){let{url:e}=this[w];return e.port!=null?`${e.port}`:""}set port(e){e=P(e);let{url:t}=this[w];K(t)||(e?I(e,t,null,5):t.port=null)}get pathname(){return oA(this[w].url)}set pathname(e){e=P(e);let{url:t}=this[w];t.opaquePath||(t.path=[],I(e,t,null,6))}get search(){let{url:e}=this[w];return e.query?`?${e.query}`:""}set search(e){e=P(e);let{url:t,query:r}=this[w];if(!e)t.query=null,r&&Z(r,null);else{let n=e[0]==="?"?e.substring(1):e;t.query="",I(n,t,null,7),r&&Z(r,t.query)}}get searchParams(){let e=this[w],t=e.query;return t==null&&(t=e.query=(function(n,u){let o=new W;return o[y].url=n,o[y].serialized=u==null,u&&(o[y].list=cA(u)),o})(this,e.url.query)),t}get hash(){let{url:e}=this[w];return e.fragment?`#${e.fragment}`:""}set hash(e){e=P(e);let{url:t}=this[w];if(!e)t.fragment=null;else{let r=e[0]==="#"?e.substring(1):e;t.fragment="",I(r,t,null,8)}}toJSON(){return this.href}toString(){return this.href}};Object.defineProperty(j.prototype,Symbol.toStringTag,{value:"URL",configurable:!0});var y=Symbol("URLSearchParamsImpl"),me=Symbol.dispose||Symbol.for("dispose");function Z(A,e){e?A[y].list=cA(e):A[y].list.length=0,A[y].serialized=e==null}function Q(A){if(A.url){let e=nA(A.list);(function(r,n){r[w].url.query=n})(A.url,e||null),A.serialized=!0}}var we=typeof Iterator<"u"?Iterator:Object,M=class extends we{constructor(e,t){super(),this[y]={ptr:e,map:t,index:0}}next(){let e=this[y];return e.index<e.ptr.list.length?{value:e.map(e.ptr.list[e.index++]),done:!1}:{value:void 0,done:!0}}[Symbol.iterator](){return this}[me](){}},W=class{constructor(e){let t=this[y]={list:[],url:null,serialized:!0},r;if(Array.isArray(e))for(let n=0;n<e.length;n++)t.list.push(wA(e[n]));else if((r=IA(e))!=null){let n;for(;!(n=AA(r.next())).done;)t.list.push(wA(n.value))}else if((typeof e=="object"||typeof e=="function")&&e!=null){let n=Object.keys(e);for(let u=0;u<n.length;u++){let o=n[u],a=OA(o),h=P(e[o]),p=t.list.find(g=>g[0]===a);p?p[1]=h:t.list.push([a,h])}}else if(e!==void 0){let n=P(e);n=n[0]==="?"?n.substring(1):n,t.list=cA(n)}}get size(){return this[y].list.length}append(e,t){e=P(e),t=P(t),this[y].list.push([e,t]);let r=this[y];r.url&&r.serialized?(function(u,o){let a=u[w].url;a.query=a.query?`${a.query}&${o}`:o})(r.url,nA([[e,t]])):Q(r)}delete(e,t){e=P(e),t=t!=null?P(t):void 0;let{list:r}=this[y],n=0;for(;n<r.length;)r[n][0]===e&&(t==null||r[n][1]===t)?r.splice(n,1):n++;Q(this[y])}get(e){e=P(e);let{list:t}=this[y];for(let r=0;r<t.length;r++)if(t[r][0]===e)return t[r][1];return null}getAll(e){e=P(e);let t=[],{list:r}=this[y];for(let n=0;n<r.length;n++)r[n][0]===e&&t.push(r[n][1]);return t}has(e,t){e=P(e),t=t!=null?P(t):void 0;let{list:r}=this[y];for(let n=0;n<r.length;n++)if(r[n][0]===e&&(t==null||r[n][1]===t))return!0;return!1}set(e,t){e=P(e),t=P(t);let{list:r}=this[y],n=!1,u=!1,o=0;for(;o<r.length;)r[o][0]===e?n?(r.splice(o,1),u=!0):(n=!0,r[o][1]!==t&&(r[o][1]=t,u=!0),o++):o++;n||(r.push([e,t]),u=!0),u&&Q(this[y])}sort(){this[y].list.sort((e,t)=>e[0]<t[0]?-1:e[0]>t[0]?1:0),Q(this[y])}forEach(e,t){if(typeof e!="function")throw new TypeError('The "callback" argument must be of type function');let{list:r}=this[y];for(let n=0;n<r.length;n++)e.call(t,r[n][1],r[n][0],this)}entries(){return new M(this[y],e=>e)}keys(){return new M(this[y],e=>e[0])}values(){return new M(this[y],e=>e[1])}toString(){return nA(this[y].list)}[Symbol.iterator](){return this.entries()}};Object.defineProperty(W.prototype,Symbol.toStringTag,{value:"URLSearchParams",configurable:!0});var Pe=$.trackUsage.request.shape.command,ye=$.trackUsage.response,De=$.checkEntitlement.request.omit({customerId:!0}).strict();function Ie(A){let e=gA.parse(A.scope),t=mA({...A,scope:e},void 0,j),r=0,n=!1;return{identify(u){if(!/^gg_ct_[A-Za-z0-9_-]{32,128}$/.test(u))throw new R("INVALID_TOKEN","A Customer Token is required");r++,t.identify(u),n=!0},reset(){r++,n=!1,t.reset()},async readHoldings(){let u=$.readHoldings;return u.response.parse(await t.request(u.path,{}))},async checkEntitlement(u){let o=$.checkEntitlement,a=De.parse(u);return o.response.parse(await t.request(o.path,a))},async trackUsage(u){if(!n)throw new R("UNAUTHENTICATED","Identify the Customer first");if(!A.usageReporter)throw new R("INVALID_REQUEST","Configure your authenticated backend usageReporter");let o=Pe.parse(u),a=r,h;try{h=await A.usageReporter(o)}catch(g){throw a!==r?new R("IDENTITY_CHANGED","Customer identity changed during usage reporting"):g}if(a!==r)throw new R("IDENTITY_CHANGED","Customer identity changed during usage reporting");let p=ye.parse(h);if(p.scope.projectId!==e.projectId||p.scope.environment!==e.environment)throw new R("INVALID_RESPONSE","Usage response scope differs");return p}}}export{R as IndianaError,Ie as createIndianaReactNative};
|
package/dist/server.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import 'zod';
|
|
2
|
-
export {
|
|
2
|
+
export { I as IndianaError } from './errors-DrdTlPwf.js';
|
|
3
3
|
export { f as AiPricingOptions, d as AiTokenQuote, b as AiTokenUsage, a as AiUsageContext, g as AiUsageMiddlewareOptions, h as AiUsageRecord, i as aiPriceSnapshotSchema, j as aiTokenQuoteSchema, c as createAiPricing, k as createAiUsageMiddleware, l as createConfiguredAiPricing } from './ai-usage-B4W5m4Ie.js';
|
|
4
4
|
import './screen-16d-xADb.js';
|
|
5
|
-
export { C as
|
|
6
|
-
|
|
5
|
+
export { h as FeatureClient, e as FeatureClientOptions, r as FunnelDecisionInput, s as FunnelDecisionTimeoutError, t as FunnelDecisionUsedInput, u as FunnelLocalEvaluation, v as FunnelLocalEvaluator, w as FunnelLocalEvaluatorOptions, x as FunnelLocalSession, y as FunnelLocalSessionOptions, i as FunnelNodeEvaluationContext, z as FunnelSignalInput, g as FunnelStartInput, A as IndianaServerOptions, L as LocalFunnelClient, k as LocalFunnelClientOptions, n as createFeatureClient, B as createFunnelCampaignClient, C as createFunnelDecisionClient, D as createFunnelLocalEvaluator, E as createFunnelOrchestrationClient, G as createFunnelStartClient, H as createGuestToken, J as createIndianaServer, o as createLocalFunnelClient, K as createNativeReceiptClient, M as createPaywallStartClient, N as createSynchronizedFunnelLocalEvaluator, q as evaluateFunnelNode, O as renewFunnelRun } from './funnel-runtime-start-sZ8ZCNlq.js';
|
|
6
|
+
export { C as ConfigurationSync, c as createConfigurationSync } from './configuration-sync-C2mytNwU.js';
|
|
7
7
|
import '@ai-sdk/provider';
|
|
8
8
|
import 'zod/v4';
|
|
9
|
+
import './growth-rules-B4YYy64R.js';
|
package/dist/server.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as j,b,c as pe,d as le,e as Se,f as de,g as me,j as fe,k as Ee,l as qe,m as Ae}from"./chunk-J7M7UH74.js";import{a as Ce,b as Re,c as Fe,d as Le}from"./chunk-M3DG6ZCT.js";import{a as q}from"./chunk-ET4NANGB.js";import{a as s}from"./chunk-5TEZEOHX.js";import"./chunk-S5TVMQRC.js";import{Fi as B,Gi as se,Ig as U,Ii as _,Ji as oe,Lg as X,Ng as Z,Qj as ie,Rh as M,Rj as ce,Tg as te,Vf as o,Wk as ue,ch as V,dh as ne,fh as re,qh as N,rh as R,sh as ae}from"./chunk-VMLGV5OS.js";import{Rb as ee}from"./chunk-RMJJOSVZ.js";import{b as Y,h as W}from"./chunk-OHDY27EI.js";import{B as $,b as H,m as J}from"./chunk-S2MSIA57.js";function p(n,r){try{return n.parse(r)}catch{throw new s("INVALID_RESPONSE","Invalid gateway response")}}function we(n){let r=le(n),t=i=>{throw new s("INVALID_RESPONSE",i)};r.nodes.size!==n.topology.nodes.length&&t("Duplicate local node identity"),r.nodes.get(n.topology.entry)?.type!=="entry"&&t("A local Funnel must start at Entry");let e=new Set(["entry","condition","feature","split","end","output"]);for(let i of r.nodes.values()){if(!e.has(i.type))throw new s("SERVER_REQUIRED","This Funnel requires authoritative server execution");if(i.type==="entry"&&i.id!==n.topology.entry&&t("Unexpected Entry node"),["entry","feature"].includes(i.type)&&!i.outputs.next&&t("Local next exit is unavailable"),i.type==="feature"){let c=i.resources.featureKey;(!c||!Object.hasOwn(n.evaluation.variables,i.writes.value)||!Object.hasOwn(r.features,c))&&t("Local Feature definition or declaration is unavailable")}if(i.type==="condition"){let c=n.conditions[i.id];(!c||!i.outputs.default||c.some((f,m)=>f.port!==`case:${m}`||!i.outputs[f.port]))&&t("Local Condition exits are unavailable")}if(i.type==="split"&&(!i.resources.experimentId||!Object.hasOwn(n.growth.experiments,i.resources.experimentId)||!i.outputs.notParticipating)&&t("Local Experiment definition or exit is unavailable"),i.type==="end"||i.type==="output"){let c=n.evaluation.terminals[i.id];if(!c)throw new s("SERVER_REQUIRED","Terminal resource delivery requires the server");Object.keys(i.outputs).length&&t("A terminal cannot have outgoing edges"),c.output?.type==="feature"&&!Object.hasOwn(r.features,c.output.featureKey)&&t("Terminal Feature definition is unavailable")}for(let c of Object.values(i.outputs))r.nodes.has(c)||t("Local target is unavailable")}let a=new Set,u=new Set;function l(i){if(u.has(i)&&t("Local graph contains a cycle"),!a.has(i)){u.add(i);for(let c of Object.values(r.nodes.get(i).outputs))l(c);u.delete(i),a.add(i)}}return l(n.topology.entry),a.size!==r.nodes.size&&t("Local graph contains unreachable nodes"),{evaluate(i){let c={},f=i.context;f.features=r.features,f.savedGroups=r.savedGroups;let m=()=>{f.attributes=Z({declarations:n.evaluation.variables,attributes:i.attributes,parameters:i.parameters,answers:{},results:c,savedGroups:r.savedGroups})};m();let I=n.topology.entry,d=0;for(;;){let w=r.nodes.get(I);if(w.type==="end"||w.type==="output"){let y=n.evaluation.terminals[I],h=y.output,v=h?.type==="feature"?r.feature(h.featureKey,f):h?.type==="variable"?te({source:"variable",key:h.key,...h.path?{path:h.path}:{}},{declarations:n.evaluation.variables,answers:{},results:c,parameters:i.parameters,attributes:i.attributes,savedGroups:r.savedGroups}):h?.value??null;return U(n.evaluation.outputSchema,v)||t("Local output does not match its declaration"),{outcome:y.outcome,value:v}}if(d++>=n.evaluation.maxTransitions)throw new s("TRANSITION_LIMIT","Local Funnel transition budget exceeded");if(w.type==="entry")I=w.outputs.next;else{let y=r.evaluate(I,f);if(w.type==="feature"){let h=w.writes.value,v=y.value??null;U(n.evaluation.variables[h],v)||t("Local Feature value does not match its declaration"),X(n.evaluation.variables,{writes:w.writes},{[h]:v}),c[h]=v,m()}I=y.target}}}}}import{z as ye}from"zod";function Ie(n,r,t){let e=J.parse(n.attributes);if(["parameters","answers","results"].some(S=>Object.hasOwn(e,S)))throw new s("INVALID_REQUEST","Flow namespaces cannot be caller attributes");let a=ee.parse(n.parameters??{}),u=ye.record(ye.string(),$).parse(n.stickyBucketAssignmentDocs??{});for(let[S,g]of Object.entries(u))if(S!==`${g.attributeName}||${g.attributeValue}`||!Object.hasOwn(e,g.attributeName)||H(e[g.attributeName])!==g.attributeValue)throw new s("INVALID_REQUEST","Sticky document identity does not match this session");let l=n.saveStickyBucketAssignmentDoc,i=n.onFeatureUsage,c=n.onExperimentViewed,f=n.onError,m=new Map,I=new Set,d={},w=Promise.resolve();function y(S){let g=w.then(()=>(t(),S()));return w=g.catch(()=>{}),g}function h(S){try{f?.(S)}catch{}}function v(S){try{let g=S();g&&typeof g.catch=="function"&&g.catch(h)}catch(g){h(g)}}async function L(){for(let[S,g]of m){if(t(),l)try{await l(structuredClone(g))}catch{throw new s("STICKY_SAVE_FAILED","Persist the pending Sticky assignment before using this evaluation")}t(),m.delete(S)}}return{evaluate(S={}){let g=S.track===!0;return y(async()=>{let D=await r();t(D);let K=new Set(I),z={...d},Q=new Map,T=[],he={stickyBucketAssignmentDocs:structuredClone(u),saveStickyBucketAssignmentDoc(E){Q.set(`${E.attributeName}||${E.attributeValue}`,structuredClone(E))},...g?{trackedExperiments:K,trackedFeatureUsage:z,onExperimentViewed(E,C){let P=structuredClone(E),ve=structuredClone(C);c&&T.push(()=>c(structuredClone(P),structuredClone(ve)))},onFeatureUsage(E,C){let P=structuredClone(C);i&&T.push(()=>i(E,structuredClone(P)))}}:{}},ge=D.program.evaluate({attributes:e,parameters:a,context:he});t(D);for(let[E,C]of Q)u[E]=C,m.set(E,C);await L(),t(D),g&&(I=K,d=z);for(let E of T)v(E);let O=D.configuration;return structuredClone({evaluationMode:"local",scope:O.scope,funnelId:O.funnelId,versionId:O.versionId,evaluationRevision:O.evaluationRevision,generation:O.growth.generation,...ge})})},flush:()=>y(L),get stickyBucketAssignmentDocs(){return t(),structuredClone(u)}}}var De=6e4;function x(n){if(typeof window<"u")throw new s("SERVER_ONLY","Local Funnel sessions run on your backend");let r=Y.parse(n.scope),t=n.funnelId,e=n.load,a,u,l,i=0,c=I=>Date.now()>=I.expiresAt;async function f(){if(u)return u;let I=i;a=void 0;let d=(async()=>{let w=await e();if(I!==i)throw new s("IDENTITY_CHANGED","Local evaluator was reset");if(w&&typeof w=="object"&&"evaluationMode"in w&&w.evaluationMode==="remote")throw p(_,w),new s("EVALUATION_MODE","This Funnel requires remote decide");let y=p(oe,w);if(I!==i)throw new s("IDENTITY_CHANGED","Local evaluator was reset");if(y.scope.projectId!==r.projectId||y.scope.environment!==r.environment||y.funnelId!==t)throw new s("SCOPE_MISMATCH","Local configuration scope changed");if(y.growth.scope.projectId!==r.projectId||y.growth.scope.environment!==r.environment||y.growth.expiresAt!==y.expiresAt)throw new s("INVALID_RESPONSE","GB configuration scope or expiry changed");let h=Math.min(Date.now()+De,y.expiresAt?Date.parse(y.expiresAt):1/0);if(Date.now()>=h)throw new s("CONFIGURATION_EXPIRED","Refresh expired local rules");let v=JSON.stringify([r.projectId,r.environment,t,y.versionId,y.evaluationRevision,y.growth.generation]),L=[y.topology,y.conditions,y.evaluation,y.growth.features,y.growth.experiments,y.growth.savedGroups];if(l?.key===v&&!pe(l.body,L))throw new s("INVALID_RESPONSE","Immutable local configuration identity changed");return l?.key!==v&&(l={key:v,body:L,program:we(y)}),a={key:v,configuration:y,expiresAt:h,program:l.program},a})();u=d;try{return await d}finally{u===d&&(u=void 0)}}function m(){return u??(a&&!c(a)?Promise.resolve(a):f())}return{session(I){let d=i;return Ie(I,m,w=>{if(n.assertUsable?.(),d!==i)throw new s("IDENTITY_CHANGED","Local evaluator was reset");if(w&&(c(w)||a?.key!==w.key))throw new s("CONFIGURATION_EXPIRED","Refresh local rules before using this result")})},async refresh(){return structuredClone((await f()).configuration)},reset(){i++,a=void 0,u=void 0,l=void 0}}}function Oe(n,r){let t=n.snapshot?.generation,e=x({scope:{projectId:n.scope.projectId,environment:n.scope.environment},funnelId:r,load:()=>n.localFunnel(r),assertUsable:()=>n.assertFunnel(r)}),a=n.subscribe(()=>{let l=n.snapshot?.generation;n.fresh&&l!==t&&(t=l,e.refresh().catch(()=>{}))}),u=e.session;return Object.assign(e,{session(l){let i=u(l),c=i.evaluate;return Object.assign(i,{async evaluate(...f){return n.fresh||await n.refresh(),c(...f)}})},destroy(){a(),e.reset()}})}function _e(n){if(typeof window<"u")throw new s("SERVER_ONLY","Secret API keys must stay on the backend");return{start:r=>fe(n,r)}}var F=class extends s{constructor(t,e){super("DECISION_PENDING","Decision is still pending; read this decision ID or retry the original request ID",202,e);this.decisionId=t;this.decisionRequestId=e}decisionId;decisionRequestId};async function k(n,r,t,e){let{decisionId:a,requestId:u}=n,l=n,i=250;for(;;){if(l.decisionId!==a||l.requestId!==u||l.decision&&!b(l.decision,r))throw new s("INVALID_RESPONSE","Decision request or customer changed");if(l.decision)return l.decision;if(l.status==="failed")throw new s("DECISION_FAILED","Decision execution failed",503,u);if(Date.now()>=t)throw new F(a,u);if(await new Promise(c=>setTimeout(c,Math.min(i,t-Date.now()))),Date.now()>=t)throw new F(a,u);i=Math.min(1e3,i*2);try{l=await e(a,t)}catch(c){if(c instanceof s&&["TIMEOUT","NETWORK_ERROR","SERVICE_UNAVAILABLE","RATE_LIMITED"].includes(c.code))continue;throw c}}}function G(n){if("remoteEval"in n)throw new s("INVALID_REQUEST","Configure evaluation mode on the Funnel; remoteEval is not supported");if(typeof window<"u")throw new s("SERVER_ONLY","Funnel decisions are requested by your backend");if(!/^gg_sk_[A-Za-z0-9_-]{32,128}$/.test(n.apiKey))throw new s("INVALID_TOKEN","A server API key is required");let r,t,e=new Map;async function a(c,f){let m=c;m.status!=="pending"&&e.delete(m.decisionId);for(let I=0;I<32&&m.evaluation;I++){let d=m.evaluation;if(d.runId!==m.decisionId)throw new s("INVALID_RESPONSE","Local evaluation Run changed");let w=e.get(m.decisionId);if(!w&&d.type==="evaluate_segment"){let h=ue.parse(await u({operation:"segment_configuration",funnelId:n.funnelId,versionId:d.versionId},f));if(h.configuration.scope.projectId!==n.scope.projectId||h.configuration.scope.environment!==n.scope.environment||h.configuration.funnelId!==n.funnelId||h.configuration.versionId!==d.versionId||h.configuration.evaluationRevision!==d.policyRevision)throw new s("SCOPE_MISMATCH","Original decision segment configuration changed");if(e.size>=128)throw new s("COMMAND_PENDING","Reconcile outstanding decisions first");w={operation:"commit_decision_segment",decisionId:m.decisionId,requestId:M(m.decisionId,d.visit,`segment:${d.revision}`),nodeId:d.nodeId,visit:d.visit,revision:d.revision,policyRevision:d.policyRevision,generation:h.configuration.growth.generation,...me(h.configuration,h.document,d)},e.set(m.decisionId,w)}if(!w){if(d.type!=="evaluate")throw new s("INVALID_RESPONSE","Unknown decision instruction");if((!t||t.versionId!==d.versionId||t.evaluationRevision!==d.policyRevision||t.expiresAt&&Date.parse(t.expiresAt)<=Date.now())&&(t=_.parse(await u({operation:"configuration",funnelId:n.funnelId,versionId:d.versionId},f))),t.scope.projectId!==n.scope.projectId||t.scope.environment!==n.scope.environment||t.funnelId!==n.funnelId)throw new s("SCOPE_MISMATCH","Local evaluation configuration scope changed");if(t.evaluationMode!=="local"||t.versionId!==d.versionId||t.evaluationRevision!==d.policyRevision)throw new s("EVALUATION_MODE","Original Local evaluation policy is unavailable");if(e.size>=128)throw new s("COMMAND_PENDING","Reconcile outstanding Local decisions first");w={operation:"evaluate_decision",decisionId:m.decisionId,requestId:M(m.decisionId,d.visit,"evaluation"),nodeId:d.nodeId,visit:d.visit,revision:d.revision,receiptId:d.receiptId,policyRevision:d.policyRevision,generation:t.growth.generation,result:de(t,d.nodeId,d)},e.set(m.decisionId,w)}let y=R.parse(await u(w,f));if(y.decisionId!==c.decisionId||y.requestId!==c.requestId)throw new s("INVALID_RESPONSE","Decision identity changed during local evaluation");e.delete(m.decisionId),m=y}return m}async function u(c,f,m=!1){let I=q({...n,fetch:(d,w)=>{let y=new Headers(w?.headers);return y.set("Accept-Encoding","identity"),m&&y.set("Prefer","respond-async"),(n.fetch??globalThis.fetch)(d,{...w,headers:y})},timeoutMs:Math.min(n.timeoutMs??1e4,f?Math.max(1,f-Date.now()):12e4)});return I.identify(n.apiKey),I.request("funnels",c)}async function l(c,f){let m=R.parse(await u(N.parse({operation:"read_decision",decisionId:c}),f));if(m.decisionId!==c)throw new s("INVALID_RESPONSE","Decision identity changed");return a(m,f)}async function i(c,f,m=!1){let I=N.options[0].parse({...c,operation:"decide",funnelId:n.funnelId}),d;try{d=R.parse(await u(I,f,m))}catch(w){throw w instanceof s&&["TIMEOUT","NETWORK_ERROR","SERVICE_UNAVAILABLE"].includes(w.code)?new s("DECISION_ACCEPTANCE_UNKNOWN","Decision acceptance is unknown; retry the original request ID and input",w.status,c.requestId):w}if(d.requestId!==c.requestId||d.decision&&!b(d.decision,I.customer))throw new s("INVALID_RESPONSE","Decision request or customer changed");return{response:await a(d,f),customer:I.customer}}return{local(){return r??=x({scope:n.scope,funnelId:n.funnelId,load:()=>u({operation:"local_configuration",funnelId:n.funnelId})})},async configuration(){let c=_.parse(await u({operation:"configuration",funnelId:n.funnelId}));if(c.scope.projectId!==n.scope.projectId||c.scope.environment!==n.scope.environment||c.funnelId!==n.funnelId)throw new s("SCOPE_MISMATCH","Configuration scope changed");return c},features(c={}){return j({...c,scope:n.scope,load:async()=>W.parse(await u({operation:"feature_config",funnelId:n.funnelId}))})},read:c=>l(c),async submit(c){return(await i(c,void 0,!0)).response},async decide(c){let f=Date.now()+3e4,m=await i(c,f);return k(m.response,m.customer,f,l)},async reportUsed(c){let f=ae.parse(await u(N.parse({...c,operation:"report_used"})));if(f.decisionId!==c.decisionId||f.eventId!==c.eventId)throw new s("INVALID_RESPONSE","Usage receipt identity changed");return f}}}function Ne(n){if(typeof window<"u")throw new s("SERVER_ONLY","Native receipts are verified by your backend");if(!/^gg_sk_[A-Za-z0-9_-]{32,128}$/.test(n.apiKey))throw new s("INVALID_TOKEN","Server API key required");let r=q({...n,timeoutMs:n.timeoutMs??35e3});return r.identify(n.apiKey),{async recover(t){let e=ie.parse(t);if(e.orderId!==e.receiptId)throw new s("INVALID_REQUEST","Native recovery requires the accepted commercial intent");let a=e.nativeEvidence,u={requestId:e.requestId,customerToken:e.customerToken,purchaseIntentId:e.orderId,...a===null?{intent:"read"}:a.provider==="apple"?{provider:"apple",signedTransaction:a.signedTransaction}:{provider:"google",purchaseToken:a.purchaseToken}},l=o.restoreNativePurchase.response.parse(await r.request(o.restoreNativePurchase.path,u));if(l.operation.requestId!==e.requestId)throw new s("INVALID_RESPONSE","Native receipt request identity changed");let i=ce.parse({scope:l.scope,requestId:e.requestId,orderId:l.operation.orderId,receiptId:l.operation.orderId,orderStatus:l.operation.status,refunded:l.operation.refunded,...l.operation.completion===null?{}:{nativeCompletion:{orderId:l.operation.orderId,receiptId:l.operation.orderId,...l.operation.completion}}});if(i.requestId!==e.requestId||i.orderId!==e.orderId||i.receiptId!==e.receiptId||i.scope.projectId!==n.scope.projectId||i.scope.environment!==n.scope.environment)throw new s("INVALID_RESPONSE","Current order receipt scope changed");return i}}}import{z as be}from"zod";var A=be.number().int().min(0).max(Number.MAX_SAFE_INTEGER);function xe(n,r){let t=A.parse(n.inputTokens.total),e=A.parse(n.outputTokens.total),a=A.parse(n.inputTokens.cacheRead??0),u=A.parse(n.inputTokens.cacheWrite??0),l=A.parse(n.outputTokens.reasoning??0);if(a+u>t||l>e||n.inputTokens.noCache!==void 0&&A.parse(n.inputTokens.noCache)!==t-a-u||n.outputTokens.text!==void 0&&A.parse(n.outputTokens.text)!==e-l)throw new s("AI_USAGE_UNAVAILABLE","Provider token counts do not conserve total usage");return{input:t-a-u,cache_read:a,cache_write:u,output:r==="output"?e:e-l,reasoning:r==="separate"?l:0,input_audio:0,output_audio:0}}function ke(n){if(typeof window<"u")throw new s("SERVER_ONLY","AI usage belongs on the trusted backend");if(!n.modelId||!["output","separate"].includes(n.reasoning))throw new s("INVALID_REQUEST","Model ID and reasoning pricing are required");async function r(e){await n.persist({context:e,modelId:n.modelId,usage:null,tokens:null,quote:null,receipt:null,phase:"incomplete"})}async function t(e,a){let u={context:e,modelId:n.modelId,usage:a,tokens:null,quote:null,receipt:null,phase:"captured"};await n.persist(u);let l=n.mapTokens?n.mapTokens(a):xe(a,n.reasoning),i=await n.pricing.quoteTokens({modelId:n.modelId,tokens:l});await n.persist({...u,tokens:l,quote:i,phase:"quoted"});let c=await n.pricing.trackTokens(n.client,{...e,quote:i});if(!c.receipt.accepted)throw new s("AI_BALANCE_REJECTED","AI usage was captured but the balance operation was rejected");await n.persist({...u,tokens:l,quote:i,receipt:c,phase:"settled"})}return{specificationVersion:"v4",async wrapGenerate({doGenerate:e}){let a=await n.context(),u;try{u=await e()}catch(l){throw await r(a),l}return await t(a,u.usage),u},async wrapStream({doStream:e}){let a=await n.context(),u;try{u=await e()}catch(m){throw await r(a),m}let l=!1,i=!1,c=u.stream.getReader();async function f(){l||i||(i=!0,await r(a))}return{...u,stream:new ReadableStream({async pull(m){try{let{value:I,done:d}=await c.read();if(d){if(!l)throw await f(),new s("AI_USAGE_UNAVAILABLE","Stream ended without final usage; no amount was invented");m.close();return}if(I.type==="finish"){if(l)throw new s("AI_USAGE_UNAVAILABLE","Provider sent more than one final usage record");l=!0,await t(a,I.usage)}m.enqueue(I)}catch(I){try{await f()}finally{m.error(I),await c.cancel(I)}}},async cancel(m){try{await f()}finally{await c.cancel(m)}}})}}}}function Te(n){if(typeof window<"u")throw new s("SERVER_ONLY","Funnel receipts are sent by your backend");if(!/^gg_sk_[A-Za-z0-9_-]{32,128}$/.test(n.apiKey))throw new s("INVALID_TOKEN","A server API key is required");let r=q(n);return r.identify(n.apiKey),{async signal(t){let e=V.parse({...t,operation:"signal"}),a=ne.parse(await r.request("funnels",e));if(a.runId!==t.runId||a.eventId!==t.eventId||a.scope.projectId!==n.scope.projectId||a.scope.environment!==n.scope.environment)throw new s("INVALID_RESPONSE","Receipt identity changed");return a},async readResults(t){let e=V.parse({operation:"read_results",runId:t}),a=re.parse(await r.request("funnels",e));if(a.runId!==t||a.scope.projectId!==n.scope.projectId||a.scope.environment!==n.scope.environment)throw new s("INVALID_RESPONSE","Result identity changed");return a}}}function Pe(n){if("remoteEval"in n)throw new s("INVALID_REQUEST","Configure evaluation mode on the Funnel; remoteEval is not supported");if(typeof window<"u")throw new s("SERVER_ONLY","Campaign entry requires your backend");if(!/^gg_sk_[A-Za-z0-9_-]{32,128}$/.test(n.apiKey))throw new s("INVALID_TOKEN","A server API key is required");let r=q({...n,timeoutMs:n.timeoutMs??35e3});return r.identify(n.apiKey),{async decide(t){let e=Date.now()+(n.timeoutMs??3e4),a=B.parse({...t,funnelId:n.funnelId,operation:"campaign_decide"}),u=q({...n,timeoutMs:Math.min(n.timeoutMs??35e3,Math.max(1,e-Date.now()))});u.identify(n.apiKey);let l=R.parse(await u.request("funnels",a));if(l.scope.projectId!==n.scope.projectId||l.scope.environment!==n.scope.environment)throw new s("SCOPE_MISMATCH","Campaign scope changed");return k(l,a.customer,e,(i,c)=>G({...n,timeoutMs:Math.min(n.timeoutMs??1e4,Math.max(1,c-Date.now()))}).read(i))},async start(t){let e=B.parse({...t,funnelId:n.funnelId,operation:"campaign_start"}),a=se.parse(await r.request("funnels",e));if(a.scope.projectId!==n.scope.projectId||a.scope.environment!==n.scope.environment)throw new s("SCOPE_MISMATCH","Campaign scope changed");if(!("suppressed"in a)&&(a.run.source.id!==n.funnelId||!a.customerId||e.customer.type==="id"&&a.customerId!==e.customer.value))throw new s("INVALID_RESPONSE","Campaign Funnel or Customer changed");return a}}}function xt(){if(typeof window<"u")throw new s("SERVER_ONLY","Guest identity is issued by your backend");let n=crypto.getRandomValues(new Uint8Array(32));return"gg_gc_"+btoa(String.fromCharCode(...n)).replaceAll("+","-").replaceAll("/","_").replaceAll("=","")}function kt(n){if(typeof window<"u")throw new s("SERVER_ONLY","Secret API keys must stay on your backend");let r=q(n);return r.identify(n.apiKey),{async listInvoiceTemplates(t={}){let e=o.listInvoiceTemplates;return p(e.response,await r.request(e.path,e.request.parse(t)))},async previewInvoice(t){let e=o.previewInvoice;return p(e.response,await r.request(e.path,e.request.parse(t)))},async createInvoice(t){let e=o.createInvoice;return p(e.response,await r.request(e.path,e.request.parse(t)))},async manageInvoice(t){let e=o.manageInvoice;return p(e.response,await r.request(e.path,e.request.parse(t)))},async readInvoiceOperation(t){let e=o.readInvoiceOperation;return p(e.response,await r.request(e.path,e.request.parse(t)))},async listInvoices(t){let e=o.listInvoices;return p(e.response,await r.request(e.path,e.request.parse(t)))},async getInvoice(t){let e=o.getInvoice;return p(e.response,await r.request(e.path,e.request.parse(t)))},async recordCouponRedemption(t){let e=o.recordCouponRedemption,a=e.request.safeParse(t);if(!a.success)throw new s("INVALID_REQUEST","Invalid Coupon redemption facts");return p(e.response,await r.request(e.path,a.data))},async getFeatures(t={}){let e=o.getFeatures;return p(e.response,await r.request(e.path,e.request.parse(t),e.method))},async evaluateFeatures(t){let e=o.evaluateFeatures;return p(e.response,await r.request(e.path,e.request.parse(t),e.method))},async trackEvents(t){let e=o.trackEvents;return p(e.response,await r.request(e.path,e.request.parse(t),e.method))},async resolvePaywall(t){let e=o.resolvePaywall;return p(e.response,await r.request(e.path,e.request.parse(t)))},async resolveOffering(t){let e=o.resolveOffering;return p(e.response,await r.request(e.path,e.request.parse(t)))},async checkEntitlement(t){let e=o.checkEntitlement;return p(e.response,await r.request(e.path,e.request.parse(t)))},async setupPayment(t){let e=o.setupPayment;return p(e.response,await r.request(e.path,e.request.parse(t)))},async readPaymentSetup(t){let e=o.readPaymentSetup;return p(e.response,await r.request(e.path,e.request.parse(t)))},async previewSubscriptionBatch(t){let e=o.previewSubscriptionBatch;return p(e.response,await r.request(e.path,e.request.parse(t)))},async confirmSubscriptionBatch(t){let e=o.confirmSubscriptionBatch;return p(e.response,await r.request(e.path,e.request.parse(t)))},async readSubscriptionBatch(t){let e=o.readSubscriptionBatch;return p(e.response,await r.request(e.path,e.request.parse(t)))},async abandonSubscriptionBatch(t){let e=o.abandonSubscriptionBatch;return p(e.response,await r.request(e.path,e.request.parse(t)))},async manageSubscriptionTrial(t){let e=o.manageSubscriptionTrial;return p(e.response,await r.request(e.path,e.request.parse(t)))},async readSubscriptionTrial(t){let e=o.readSubscriptionTrial;return p(e.response,await r.request(e.path,e.request.parse(t)))},async listSubscriptions(t){let e=o.listSubscriptions;return p(e.response,await r.request(e.path,e.request.parse(t)))},async listPurchases(t){let e=o.listPurchases;return p(e.response,await r.request(e.path,e.request.parse(t)))},async listSubscriptionConflicts(t){let e=o.listSubscriptionConflicts;return p(e.response,await r.request(e.path,e.request.parse(t)))},async retrySubscriptionConflict(t){let e=o.retrySubscriptionConflict;return p(e.response,await r.request(e.path,e.request.parse(t)))},async previewRefund(t){let e=o.previewRefund;return p(e.response,await r.request(e.path,e.request.parse(t)))},async refund(t){let e=o.refund;return p(e.response,await r.request(e.path,e.request.parse(t)))},async readRefund(t){let e=o.readRefund;return p(e.response,await r.request(e.path,e.request.parse(t)))},async previewUpdate(t){let e=o.previewUpdate;return p(e.response,await r.request(e.path,e.request.parse(t)))},async update(t){let e=o.update;return p(e.response,await r.request(e.path,e.request.parse(t)))},async readSubscriptionUpdate(t){let e=o.readSubscriptionUpdate;return p(e.response,await r.request(e.path,e.request.parse(t)))},async restoreNativePurchase(t){let e=o.restoreNativePurchase;return p(e.response,await r.request(e.path,e.request.parse(t)))},async verifySubscriptions(t){let e=o.verifySubscriptions;return p(e.response,await r.request(e.path,e.request.parse(t)))},async previewAttach(t){let e=o.previewAttach;return p(e.response,await r.request(e.path,e.request.parse(t)))},async attach(t){let e=o.attach;return p(e.response,await r.request(e.path,e.request.parse(t)))},async readSubscriptionOperation(t){let e=o.readSubscriptionOperation;return p(e.response,await r.request(e.path,e.request.parse(t)))},async readAiPricing(t){let e=o.readAiPricing;return p(e.response,await r.request(e.path,e.request.parse(t)))},async readUsage(t){let e=o.readUsage;return p(e.response,await r.request(e.path,e.request.parse(t)))},async setUsage(t){let e=o.setUsage;return p(e.response,await r.request(e.path,e.request.parse(t)))},async manageBalanceGrant(t){let e=o.manageBalanceGrant;return p(e.response,await r.request(e.path,e.request.parse(t)))},async readBalanceSource(t){let e=o.readBalanceSource;return p(e.response,await r.request(e.path,e.request.parse(t)))},async adjustBalance(t){let e=o.adjustBalance;return p(e.response,await r.request(e.path,e.request.parse(t)))},async listBalanceGrants(t){let e=o.listBalanceGrants;return p(e.response,await r.request(e.path,e.request.parse(t)))},async manageBillingLimits(t){let e=o.manageBillingLimits;return p(e.response,await r.request(e.path,e.request.parse(t)))},async readSeats(t){let e=o.readSeats;return p(e.response,await r.request(e.path,e.request.parse(t)))},async manageSeat(t){let e=o.manageSeat;return p(e.response,await r.request(e.path,e.request.parse(t)))},async manageUsageEntity(t){let e=o.manageUsageEntity;return p(e.response,await r.request(e.path,e.request.parse(t)))},async readUsageAnalytics(t){let e=o.readUsageAnalytics;return p(e.response,await r.request(e.path,e.request.parse(t)))},async readCreditAnalytics(t){let e=o.readCreditAnalytics;return p(e.response,await r.request(e.path,e.request.parse(t)))},async submitUsageBatch(t){let e=o.submitUsageBatch;return p(e.response,await r.request(e.path,e.request.parse(t)))},async readUsageBatch(t){let e=o.readUsageBatch;return p(e.response,await r.request(e.path,e.request.parse(t)))},async readHoldings(t){let e=o.readHoldings;return p(e.response,await r.request(e.path,e.request.parse(t)))},async readLedger(t){let e=o.readLedger;return p(e.response,await r.request(e.path,e.request.parse(t)))},async readBillingInvoice(t){let e=o.readBillingInvoice;return p(e.response,await r.request(e.path,e.request.parse(t)))},async readCreditStatement(t){let e=o.readCreditStatement;return p(e.response,await r.request(e.path,e.request.parse(t)))},async quoteBalance(t){let e=o.quoteBalance;return p(e.response,await r.request(e.path,e.request.parse(t)))},async trackUsage(t){let e=o.trackUsage;return p(e.response,await r.request(e.path,e.request.parse(t)))},async mutateBalance(t){let e=o.mutateBalance;return p(e.response,await r.request(e.path,e.request.parse(t)))},async getCustomer(t){let e=o.getCustomer,a=e.request.safeParse(t);if(!a.success)throw new s("INVALID_REQUEST","Invalid customer lookup");let u=e.response.safeParse(await r.request(e.path,a.data));if(!u.success)throw new s("INVALID_RESPONSE","Invalid customer response");return u.data},async listCustomers(t={}){let e=o.listCustomers,a=e.request.safeParse(t);if(!a.success)throw new s("INVALID_REQUEST","Invalid customer filters");let u=e.response.safeParse(await r.request(e.path,a.data));if(!u.success)throw new s("INVALID_RESPONSE","Invalid customer response");return u.data},async updateCustomer(t){let e=o.updateCustomer,a=e.request.safeParse(t);if(!a.success)throw new s("INVALID_REQUEST","Invalid customer patch");let u=e.response.safeParse(await r.request(e.path,a.data));if(!u.success)throw new s("INVALID_RESPONSE","Invalid customer response");return u.data},async createGuestCustomer(t){let e=o.createGuestCustomer;return e.response.parse(await r.request(e.path,e.request.parse(t)))},async resumeGuestSession(t){let e=o.resumeGuestSession;return e.response.parse(await r.request(e.path,e.request.parse(t)))},async claimGuestCustomer(t){let e=o.claimGuestCustomer;return e.response.parse(await r.request(e.path,e.request.parse(t)))},async renewCustomerSession(t){let e=o.renewSession;return e.response.parse(await r.request(e.path,e.request.parse(t)))},async revokeCustomerSessions(t){let e=o.revokeSessions;return e.response.parse(await r.request(e.path,e.request.parse(t)))},async createCustomerSession(t){let e=o.createSession.request.safeParse({customerId:t});if(!e.success)throw new s("INVALID_REQUEST","A customer ID is required");let a=o.createSession.response.safeParse(await r.request("customer-sessions",e.data));if(!a.success)throw new s("INVALID_RESPONSE","Invalid customer session response");return a.data},async getOrCreateCustomer(t){let e=o.createCustomer.request.safeParse(t);if(!e.success)throw new s("INVALID_REQUEST","Invalid customer input");let a=o.createCustomer.response.safeParse(await r.request("customers",e.data));if(!a.success)throw new s("INVALID_RESPONSE","Invalid customer response");return a.data},async grantOffer(t){let e=o.grantOffer.request.safeParse({...t,requestId:t.requestId??crypto.randomUUID()});if(!e.success||!e.data.customerId)throw new s("INVALID_REQUEST","Invalid offer grant");let a=o.grantOffer.response.safeParse(await r.request("offers/grant",e.data));if(!a.success)throw new s("INVALID_RESPONSE","Invalid offer response");return a.data}}}async function Tt(n,r){if(typeof window<"u")throw new s("SERVER_ONLY","Renewal requires your backend");let{funnelCredentialCommandSchema:t,funnelCredentialResponseSchema:e}=await import("./src-X6KT6WIH.js"),a=q(n);return a.identify(n.apiKey),e.parse(await a.request("funnels",t.parse({...r,operation:"renew_run"})))}export{F as FunnelDecisionTimeoutError,s as IndianaError,Ce as aiPriceSnapshotSchema,Re as aiTokenQuoteSchema,Fe as createAiPricing,ke as createAiUsageMiddleware,Ee as createConfigurationSync,Le as createConfiguredAiPricing,j as createFeatureClient,Pe as createFunnelCampaignClient,G as createFunnelDecisionClient,x as createFunnelLocalEvaluator,Te as createFunnelOrchestrationClient,qe as createFunnelStartClient,xt as createGuestToken,kt as createIndianaServer,Ae as createLocalFunnelClient,Ne as createNativeReceiptClient,_e as createPaywallStartClient,Oe as createSynchronizedFunnelLocalEvaluator,Se as evaluateFunnelNode,Tt as renewFunnelRun};
|
|
1
|
+
import{a as j,b,c as pe,d as le,e as de,f as me,i as fe,j as Se,k as Ee,l as qe,m as Ae}from"./chunk-63BWE27V.js";import{a as Ce,b as Re,c as Fe,d as Le}from"./chunk-2EJSV6BA.js";import{a as q}from"./chunk-QG3WUJG5.js";import{Ig as U,Ii as B,Ji as se,Lg as X,Li as _,Mi as oe,Ng as Z,Rh as M,Tg as te,Tj as ie,Uj as ce,Vf as o,ch as V,dh as ne,dl as ue,fh as re,qh as N,rh as R,sh as ae}from"./chunk-HTRQPMJO.js";import"./chunk-S5TVMQRC.js";import{b as Y,h as W}from"./chunk-ISUXYPYL.js";import"./chunk-U6S6AZM6.js";import"./chunk-4K25DELJ.js";import{a as s}from"./chunk-5TEZEOHX.js";import{Rb as ee}from"./chunk-RMJJOSVZ.js";import{B as $,b as H,m as J}from"./chunk-S2MSIA57.js";function p(n,r){try{return n.parse(r)}catch{throw new s("INVALID_RESPONSE","Invalid gateway response")}}function we(n){let r=le(n),t=i=>{throw new s("INVALID_RESPONSE",i)};r.nodes.size!==n.topology.nodes.length&&t("Duplicate local node identity"),r.nodes.get(n.topology.entry)?.type!=="entry"&&t("A local Funnel must start at Entry");let e=new Set(["entry","condition","feature","split","end","output"]);for(let i of r.nodes.values()){if(!e.has(i.type))throw new s("SERVER_REQUIRED","This Funnel requires authoritative server execution");if(i.type==="entry"&&i.id!==n.topology.entry&&t("Unexpected Entry node"),["entry","feature"].includes(i.type)&&!i.outputs.next&&t("Local next exit is unavailable"),i.type==="feature"){let c=i.resources.featureKey;(!c||!Object.hasOwn(n.evaluation.variables,i.writes.value)||!Object.hasOwn(r.features,c))&&t("Local Feature definition or declaration is unavailable")}if(i.type==="condition"){let c=n.conditions[i.id];(!c||!i.outputs.default||c.some((f,m)=>f.port!==`case:${m}`||!i.outputs[f.port]))&&t("Local Condition exits are unavailable")}if(i.type==="split"&&(!i.resources.experimentId||!Object.hasOwn(n.growth.experiments,i.resources.experimentId)||!i.outputs.notParticipating)&&t("Local Experiment definition or exit is unavailable"),i.type==="end"||i.type==="output"){let c=n.evaluation.terminals[i.id];if(!c)throw new s("SERVER_REQUIRED","Terminal resource delivery requires the server");Object.keys(i.outputs).length&&t("A terminal cannot have outgoing edges"),c.output?.type==="feature"&&!Object.hasOwn(r.features,c.output.featureKey)&&t("Terminal Feature definition is unavailable")}for(let c of Object.values(i.outputs))r.nodes.has(c)||t("Local target is unavailable")}let a=new Set,u=new Set;function l(i){if(u.has(i)&&t("Local graph contains a cycle"),!a.has(i)){u.add(i);for(let c of Object.values(r.nodes.get(i).outputs))l(c);u.delete(i),a.add(i)}}return l(n.topology.entry),a.size!==r.nodes.size&&t("Local graph contains unreachable nodes"),{evaluate(i){let c={},f=i.context;f.features=r.features,f.savedGroups=r.savedGroups;let m=()=>{f.attributes=Z({declarations:n.evaluation.variables,attributes:i.attributes,parameters:i.parameters,answers:{},results:c,savedGroups:r.savedGroups})};m();let I=n.topology.entry,d=0;for(;;){let w=r.nodes.get(I);if(w.type==="end"||w.type==="output"){let y=n.evaluation.terminals[I],h=y.output,v=h?.type==="feature"?r.feature(h.featureKey,f):h?.type==="variable"?te({source:"variable",key:h.key,...h.path?{path:h.path}:{}},{declarations:n.evaluation.variables,answers:{},results:c,parameters:i.parameters,attributes:i.attributes,savedGroups:r.savedGroups}):h?.value??null;return U(n.evaluation.outputSchema,v)||t("Local output does not match its declaration"),{outcome:y.outcome,value:v}}if(d++>=n.evaluation.maxTransitions)throw new s("TRANSITION_LIMIT","Local Funnel transition budget exceeded");if(w.type==="entry")I=w.outputs.next;else{let y=r.evaluate(I,f);if(w.type==="feature"){let h=w.writes.value,v=y.value??null;U(n.evaluation.variables[h],v)||t("Local Feature value does not match its declaration"),X(n.evaluation.variables,{writes:w.writes},{[h]:v}),c[h]=v,m()}I=y.target}}}}}import{z as ye}from"zod";function Ie(n,r,t){let e=J.parse(n.attributes);if(["parameters","answers","results"].some(S=>Object.hasOwn(e,S)))throw new s("INVALID_REQUEST","Flow namespaces cannot be caller attributes");let a=ee.parse(n.parameters??{}),u=ye.record(ye.string(),$).parse(n.stickyBucketAssignmentDocs??{});for(let[S,g]of Object.entries(u))if(S!==`${g.attributeName}||${g.attributeValue}`||!Object.hasOwn(e,g.attributeName)||H(e[g.attributeName])!==g.attributeValue)throw new s("INVALID_REQUEST","Sticky document identity does not match this session");let l=n.saveStickyBucketAssignmentDoc,i=n.onFeatureUsage,c=n.onExperimentViewed,f=n.onError,m=new Map,I=new Set,d={},w=Promise.resolve();function y(S){let g=w.then(()=>(t(),S()));return w=g.catch(()=>{}),g}function h(S){try{f?.(S)}catch{}}function v(S){try{let g=S();g&&typeof g.catch=="function"&&g.catch(h)}catch(g){h(g)}}async function L(){for(let[S,g]of m){if(t(),l)try{await l(structuredClone(g))}catch{throw new s("STICKY_SAVE_FAILED","Persist the pending Sticky assignment before using this evaluation")}t(),m.delete(S)}}return{evaluate(S={}){let g=S.track===!0;return y(async()=>{let D=await r();t(D);let K=new Set(I),z={...d},Q=new Map,T=[],he={stickyBucketAssignmentDocs:structuredClone(u),saveStickyBucketAssignmentDoc(E){Q.set(`${E.attributeName}||${E.attributeValue}`,structuredClone(E))},...g?{trackedExperiments:K,trackedFeatureUsage:z,onExperimentViewed(E,C){let P=structuredClone(E),ve=structuredClone(C);c&&T.push(()=>c(structuredClone(P),structuredClone(ve)))},onFeatureUsage(E,C){let P=structuredClone(C);i&&T.push(()=>i(E,structuredClone(P)))}}:{}},ge=D.program.evaluate({attributes:e,parameters:a,context:he});t(D);for(let[E,C]of Q)u[E]=C,m.set(E,C);await L(),t(D),g&&(I=K,d=z);for(let E of T)v(E);let O=D.configuration;return structuredClone({evaluationMode:"local",scope:O.scope,funnelId:O.funnelId,versionId:O.versionId,evaluationRevision:O.evaluationRevision,generation:O.growth.generation,...ge})})},flush:()=>y(L),get stickyBucketAssignmentDocs(){return t(),structuredClone(u)}}}var De=6e4;function x(n){if(typeof window<"u")throw new s("SERVER_ONLY","Local Funnel sessions run on your backend");let r=Y.parse(n.scope),t=n.funnelId,e=n.load,a,u,l,i=0,c=I=>Date.now()>=I.expiresAt;async function f(){if(u)return u;let I=i;a=void 0;let d=(async()=>{let w=await e();if(I!==i)throw new s("IDENTITY_CHANGED","Local evaluator was reset");if(w&&typeof w=="object"&&"evaluationMode"in w&&w.evaluationMode==="remote")throw p(_,w),new s("EVALUATION_MODE","This Funnel requires remote decide");let y=p(oe,w);if(I!==i)throw new s("IDENTITY_CHANGED","Local evaluator was reset");if(y.scope.projectId!==r.projectId||y.scope.environment!==r.environment||y.funnelId!==t)throw new s("SCOPE_MISMATCH","Local configuration scope changed");if(y.growth.scope.projectId!==r.projectId||y.growth.scope.environment!==r.environment||y.growth.expiresAt!==y.expiresAt)throw new s("INVALID_RESPONSE","GB configuration scope or expiry changed");let h=Math.min(Date.now()+De,y.expiresAt?Date.parse(y.expiresAt):1/0);if(Date.now()>=h)throw new s("CONFIGURATION_EXPIRED","Refresh expired local rules");let v=JSON.stringify([r.projectId,r.environment,t,y.versionId,y.evaluationRevision,y.growth.generation]),L=[y.topology,y.conditions,y.evaluation,y.growth.features,y.growth.experiments,y.growth.savedGroups];if(l?.key===v&&!pe(l.body,L))throw new s("INVALID_RESPONSE","Immutable local configuration identity changed");return l?.key!==v&&(l={key:v,body:L,program:we(y)}),a={key:v,configuration:y,expiresAt:h,program:l.program},a})();u=d;try{return await d}finally{u===d&&(u=void 0)}}function m(){return u??(a&&!c(a)?Promise.resolve(a):f())}return{session(I){let d=i;return Ie(I,m,w=>{if(n.assertUsable?.(),d!==i)throw new s("IDENTITY_CHANGED","Local evaluator was reset");if(w&&(c(w)||a?.key!==w.key))throw new s("CONFIGURATION_EXPIRED","Refresh local rules before using this result")})},async refresh(){return structuredClone((await f()).configuration)},reset(){i++,a=void 0,u=void 0,l=void 0}}}function Oe(n,r){let t=n.snapshot?.generation,e=x({scope:{projectId:n.scope.projectId,environment:n.scope.environment},funnelId:r,load:()=>n.localFunnel(r),assertUsable:()=>n.assertFunnel(r)}),a=n.subscribe(()=>{let l=n.snapshot?.generation;n.fresh&&l!==t&&(t=l,e.refresh().catch(()=>{}))}),u=e.session;return Object.assign(e,{session(l){let i=u(l),c=i.evaluate;return Object.assign(i,{async evaluate(...f){return n.fresh||await n.refresh(),c(...f)}})},destroy(){a(),e.reset()}})}function _e(n){if(typeof window<"u")throw new s("SERVER_ONLY","Secret API keys must stay on the backend");return{start:r=>fe(n,r)}}var F=class extends s{constructor(t,e){super("DECISION_PENDING","Decision is still pending; read this decision ID or retry the original request ID",202,e);this.decisionId=t;this.decisionRequestId=e}decisionId;decisionRequestId};async function k(n,r,t,e){let{decisionId:a,requestId:u}=n,l=n,i=250;for(;;){if(l.decisionId!==a||l.requestId!==u||l.decision&&!b(l.decision,r))throw new s("INVALID_RESPONSE","Decision request or customer changed");if(l.decision)return l.decision;if(l.status==="failed")throw new s("DECISION_FAILED","Decision execution failed",503,u);if(Date.now()>=t)throw new F(a,u);if(await new Promise(c=>setTimeout(c,Math.min(i,t-Date.now()))),Date.now()>=t)throw new F(a,u);i=Math.min(1e3,i*2);try{l=await e(a,t)}catch(c){if(c instanceof s&&["TIMEOUT","NETWORK_ERROR","SERVICE_UNAVAILABLE","RATE_LIMITED"].includes(c.code))continue;throw c}}}function G(n){if("remoteEval"in n)throw new s("INVALID_REQUEST","Configure evaluation mode on the Funnel; remoteEval is not supported");if(typeof window<"u")throw new s("SERVER_ONLY","Funnel decisions are requested by your backend");if(!/^gg_sk_[A-Za-z0-9_-]{32,128}$/.test(n.apiKey))throw new s("INVALID_TOKEN","A server API key is required");let r,t,e=new Map;async function a(c,f){let m=c;m.status!=="pending"&&e.delete(m.decisionId);for(let I=0;I<32&&m.evaluation;I++){let d=m.evaluation;if(d.runId!==m.decisionId)throw new s("INVALID_RESPONSE","Local evaluation Run changed");let w=e.get(m.decisionId);if(!w&&d.type==="evaluate_segment"){let h=ue.parse(await u({operation:"segment_configuration",funnelId:n.funnelId,versionId:d.versionId},f));if(h.configuration.scope.projectId!==n.scope.projectId||h.configuration.scope.environment!==n.scope.environment||h.configuration.funnelId!==n.funnelId||h.configuration.versionId!==d.versionId||h.configuration.evaluationRevision!==d.policyRevision)throw new s("SCOPE_MISMATCH","Original decision segment configuration changed");if(e.size>=128)throw new s("COMMAND_PENDING","Reconcile outstanding decisions first");w={operation:"commit_decision_segment",decisionId:m.decisionId,requestId:M(m.decisionId,d.visit,`segment:${d.revision}`),nodeId:d.nodeId,visit:d.visit,revision:d.revision,policyRevision:d.policyRevision,generation:h.configuration.growth.generation,...me(h.configuration,h.document,d)},e.set(m.decisionId,w)}if(!w){if(d.type!=="evaluate")throw new s("INVALID_RESPONSE","Unknown decision instruction");if((!t||t.versionId!==d.versionId||t.evaluationRevision!==d.policyRevision||t.expiresAt&&Date.parse(t.expiresAt)<=Date.now())&&(t=_.parse(await u({operation:"configuration",funnelId:n.funnelId,versionId:d.versionId},f))),t.scope.projectId!==n.scope.projectId||t.scope.environment!==n.scope.environment||t.funnelId!==n.funnelId)throw new s("SCOPE_MISMATCH","Local evaluation configuration scope changed");if(t.evaluationMode!=="local"||t.versionId!==d.versionId||t.evaluationRevision!==d.policyRevision)throw new s("EVALUATION_MODE","Original Local evaluation policy is unavailable");if(e.size>=128)throw new s("COMMAND_PENDING","Reconcile outstanding Local decisions first");w={operation:"evaluate_decision",decisionId:m.decisionId,requestId:M(m.decisionId,d.visit,"evaluation"),nodeId:d.nodeId,visit:d.visit,revision:d.revision,receiptId:d.receiptId,policyRevision:d.policyRevision,generation:t.growth.generation,result:de(t,d.nodeId,d)},e.set(m.decisionId,w)}let y=R.parse(await u(w,f));if(y.decisionId!==c.decisionId||y.requestId!==c.requestId)throw new s("INVALID_RESPONSE","Decision identity changed during local evaluation");e.delete(m.decisionId),m=y}return m}async function u(c,f,m=!1){let I=q({...n,fetch:(d,w)=>{let y=new Headers(w?.headers);return y.set("Accept-Encoding","identity"),m&&y.set("Prefer","respond-async"),(n.fetch??globalThis.fetch)(d,{...w,headers:y})},timeoutMs:Math.min(n.timeoutMs??1e4,f?Math.max(1,f-Date.now()):12e4)});return I.identify(n.apiKey),I.request("funnels",c)}async function l(c,f){let m=R.parse(await u(N.parse({operation:"read_decision",decisionId:c}),f));if(m.decisionId!==c)throw new s("INVALID_RESPONSE","Decision identity changed");return a(m,f)}async function i(c,f,m=!1){let I=N.options[0].parse({...c,operation:"decide",funnelId:n.funnelId}),d;try{d=R.parse(await u(I,f,m))}catch(w){throw w instanceof s&&["TIMEOUT","NETWORK_ERROR","SERVICE_UNAVAILABLE"].includes(w.code)?new s("DECISION_ACCEPTANCE_UNKNOWN","Decision acceptance is unknown; retry the original request ID and input",w.status,c.requestId):w}if(d.requestId!==c.requestId||d.decision&&!b(d.decision,I.customer))throw new s("INVALID_RESPONSE","Decision request or customer changed");return{response:await a(d,f),customer:I.customer}}return{local(){return r??=x({scope:n.scope,funnelId:n.funnelId,load:()=>u({operation:"local_configuration",funnelId:n.funnelId})})},async configuration(){let c=_.parse(await u({operation:"configuration",funnelId:n.funnelId}));if(c.scope.projectId!==n.scope.projectId||c.scope.environment!==n.scope.environment||c.funnelId!==n.funnelId)throw new s("SCOPE_MISMATCH","Configuration scope changed");return c},features(c={}){return j({...c,scope:n.scope,load:async()=>W.parse(await u({operation:"feature_config",funnelId:n.funnelId}))})},read:c=>l(c),async submit(c){return(await i(c,void 0,!0)).response},async decide(c){let f=Date.now()+3e4,m=await i(c,f);return k(m.response,m.customer,f,l)},async reportUsed(c){let f=ae.parse(await u(N.parse({...c,operation:"report_used"})));if(f.decisionId!==c.decisionId||f.eventId!==c.eventId)throw new s("INVALID_RESPONSE","Usage receipt identity changed");return f}}}function Ne(n){if(typeof window<"u")throw new s("SERVER_ONLY","Native receipts are verified by your backend");if(!/^gg_sk_[A-Za-z0-9_-]{32,128}$/.test(n.apiKey))throw new s("INVALID_TOKEN","Server API key required");let r=q({...n,timeoutMs:n.timeoutMs??35e3});return r.identify(n.apiKey),{async recover(t){let e=ie.parse(t);if(e.orderId!==e.receiptId)throw new s("INVALID_REQUEST","Native recovery requires the accepted commercial intent");let a=e.nativeEvidence,u={requestId:e.requestId,customerToken:e.customerToken,purchaseIntentId:e.orderId,...a===null?{intent:"read"}:a.provider==="apple"?{provider:"apple",signedTransaction:a.signedTransaction}:{provider:"google",purchaseToken:a.purchaseToken}},l=o.restoreNativePurchase.response.parse(await r.request(o.restoreNativePurchase.path,u));if(l.operation.requestId!==e.requestId)throw new s("INVALID_RESPONSE","Native receipt request identity changed");let i=ce.parse({scope:l.scope,requestId:e.requestId,orderId:l.operation.orderId,receiptId:l.operation.orderId,orderStatus:l.operation.status,refunded:l.operation.refunded,...l.operation.completion===null?{}:{nativeCompletion:{orderId:l.operation.orderId,receiptId:l.operation.orderId,...l.operation.completion}}});if(i.requestId!==e.requestId||i.orderId!==e.orderId||i.receiptId!==e.receiptId||i.scope.projectId!==n.scope.projectId||i.scope.environment!==n.scope.environment)throw new s("INVALID_RESPONSE","Current order receipt scope changed");return i}}}import{z as be}from"zod";var A=be.number().int().min(0).max(Number.MAX_SAFE_INTEGER);function xe(n,r){let t=A.parse(n.inputTokens.total),e=A.parse(n.outputTokens.total),a=A.parse(n.inputTokens.cacheRead??0),u=A.parse(n.inputTokens.cacheWrite??0),l=A.parse(n.outputTokens.reasoning??0);if(a+u>t||l>e||n.inputTokens.noCache!==void 0&&A.parse(n.inputTokens.noCache)!==t-a-u||n.outputTokens.text!==void 0&&A.parse(n.outputTokens.text)!==e-l)throw new s("AI_USAGE_UNAVAILABLE","Provider token counts do not conserve total usage");return{input:t-a-u,cache_read:a,cache_write:u,output:r==="output"?e:e-l,reasoning:r==="separate"?l:0,input_audio:0,output_audio:0}}function ke(n){if(typeof window<"u")throw new s("SERVER_ONLY","AI usage belongs on the trusted backend");if(!n.modelId||!["output","separate"].includes(n.reasoning))throw new s("INVALID_REQUEST","Model ID and reasoning pricing are required");async function r(e){await n.persist({context:e,modelId:n.modelId,usage:null,tokens:null,quote:null,receipt:null,phase:"incomplete"})}async function t(e,a){let u={context:e,modelId:n.modelId,usage:a,tokens:null,quote:null,receipt:null,phase:"captured"};await n.persist(u);let l=n.mapTokens?n.mapTokens(a):xe(a,n.reasoning),i=await n.pricing.quoteTokens({modelId:n.modelId,tokens:l});await n.persist({...u,tokens:l,quote:i,phase:"quoted"});let c=await n.pricing.trackTokens(n.client,{...e,quote:i});if(!c.receipt.accepted)throw new s("AI_BALANCE_REJECTED","AI usage was captured but the balance operation was rejected");await n.persist({...u,tokens:l,quote:i,receipt:c,phase:"settled"})}return{specificationVersion:"v4",async wrapGenerate({doGenerate:e}){let a=await n.context(),u;try{u=await e()}catch(l){throw await r(a),l}return await t(a,u.usage),u},async wrapStream({doStream:e}){let a=await n.context(),u;try{u=await e()}catch(m){throw await r(a),m}let l=!1,i=!1,c=u.stream.getReader();async function f(){l||i||(i=!0,await r(a))}return{...u,stream:new ReadableStream({async pull(m){try{let{value:I,done:d}=await c.read();if(d){if(!l)throw await f(),new s("AI_USAGE_UNAVAILABLE","Stream ended without final usage; no amount was invented");m.close();return}if(I.type==="finish"){if(l)throw new s("AI_USAGE_UNAVAILABLE","Provider sent more than one final usage record");l=!0,await t(a,I.usage)}m.enqueue(I)}catch(I){try{await f()}finally{m.error(I),await c.cancel(I)}}},async cancel(m){try{await f()}finally{await c.cancel(m)}}})}}}}function Te(n){if(typeof window<"u")throw new s("SERVER_ONLY","Funnel receipts are sent by your backend");if(!/^gg_sk_[A-Za-z0-9_-]{32,128}$/.test(n.apiKey))throw new s("INVALID_TOKEN","A server API key is required");let r=q(n);return r.identify(n.apiKey),{async signal(t){let e=V.parse({...t,operation:"signal"}),a=ne.parse(await r.request("funnels",e));if(a.runId!==t.runId||a.eventId!==t.eventId||a.scope.projectId!==n.scope.projectId||a.scope.environment!==n.scope.environment)throw new s("INVALID_RESPONSE","Receipt identity changed");return a},async readResults(t){let e=V.parse({operation:"read_results",runId:t}),a=re.parse(await r.request("funnels",e));if(a.runId!==t||a.scope.projectId!==n.scope.projectId||a.scope.environment!==n.scope.environment)throw new s("INVALID_RESPONSE","Result identity changed");return a}}}function Pe(n){if("remoteEval"in n)throw new s("INVALID_REQUEST","Configure evaluation mode on the Funnel; remoteEval is not supported");if(typeof window<"u")throw new s("SERVER_ONLY","Campaign entry requires your backend");if(!/^gg_sk_[A-Za-z0-9_-]{32,128}$/.test(n.apiKey))throw new s("INVALID_TOKEN","A server API key is required");let r=q({...n,timeoutMs:n.timeoutMs??35e3});return r.identify(n.apiKey),{async decide(t){let e=Date.now()+(n.timeoutMs??3e4),a=B.parse({...t,funnelId:n.funnelId,operation:"campaign_decide"}),u=q({...n,timeoutMs:Math.min(n.timeoutMs??35e3,Math.max(1,e-Date.now()))});u.identify(n.apiKey);let l=R.parse(await u.request("funnels",a));if(l.scope.projectId!==n.scope.projectId||l.scope.environment!==n.scope.environment)throw new s("SCOPE_MISMATCH","Campaign scope changed");return k(l,a.customer,e,(i,c)=>G({...n,timeoutMs:Math.min(n.timeoutMs??1e4,Math.max(1,c-Date.now()))}).read(i))},async start(t){let e=B.parse({...t,funnelId:n.funnelId,operation:"campaign_start"}),a=se.parse(await r.request("funnels",e));if(a.scope.projectId!==n.scope.projectId||a.scope.environment!==n.scope.environment)throw new s("SCOPE_MISMATCH","Campaign scope changed");if(!("suppressed"in a)&&(a.run.source.id!==n.funnelId||!a.customerId||e.customer.type==="id"&&a.customerId!==e.customer.value))throw new s("INVALID_RESPONSE","Campaign Funnel or Customer changed");return a}}}function xt(){if(typeof window<"u")throw new s("SERVER_ONLY","Guest identity is issued by your backend");let n=crypto.getRandomValues(new Uint8Array(32));return"gg_gc_"+btoa(String.fromCharCode(...n)).replaceAll("+","-").replaceAll("/","_").replaceAll("=","")}function kt(n){if(typeof window<"u")throw new s("SERVER_ONLY","Secret API keys must stay on your backend");let r=q(n);return r.identify(n.apiKey),{async listInvoiceTemplates(t={}){let e=o.listInvoiceTemplates;return p(e.response,await r.request(e.path,e.request.parse(t)))},async previewInvoice(t){let e=o.previewInvoice;return p(e.response,await r.request(e.path,e.request.parse(t)))},async createInvoice(t){let e=o.createInvoice;return p(e.response,await r.request(e.path,e.request.parse(t)))},async manageInvoice(t){let e=o.manageInvoice;return p(e.response,await r.request(e.path,e.request.parse(t)))},async readInvoiceOperation(t){let e=o.readInvoiceOperation;return p(e.response,await r.request(e.path,e.request.parse(t)))},async listInvoices(t){let e=o.listInvoices;return p(e.response,await r.request(e.path,e.request.parse(t)))},async getInvoice(t){let e=o.getInvoice;return p(e.response,await r.request(e.path,e.request.parse(t)))},async recordCouponRedemption(t){let e=o.recordCouponRedemption,a=e.request.safeParse(t);if(!a.success)throw new s("INVALID_REQUEST","Invalid Coupon redemption facts");return p(e.response,await r.request(e.path,a.data))},async getFeatures(t={}){let e=o.getFeatures;return p(e.response,await r.request(e.path,e.request.parse(t),e.method))},async evaluateFeatures(t){let e=o.evaluateFeatures;return p(e.response,await r.request(e.path,e.request.parse(t),e.method))},async trackEvents(t){let e=o.trackEvents;return p(e.response,await r.request(e.path,e.request.parse(t),e.method))},async resolvePaywall(t){let e=o.resolvePaywall;return p(e.response,await r.request(e.path,e.request.parse(t)))},async resolveOffering(t){let e=o.resolveOffering;return p(e.response,await r.request(e.path,e.request.parse(t)))},async checkEntitlement(t){let e=o.checkEntitlement;return p(e.response,await r.request(e.path,e.request.parse(t)))},async setupPayment(t){let e=o.setupPayment;return p(e.response,await r.request(e.path,e.request.parse(t)))},async readPaymentSetup(t){let e=o.readPaymentSetup;return p(e.response,await r.request(e.path,e.request.parse(t)))},async previewSubscriptionBatch(t){let e=o.previewSubscriptionBatch;return p(e.response,await r.request(e.path,e.request.parse(t)))},async confirmSubscriptionBatch(t){let e=o.confirmSubscriptionBatch;return p(e.response,await r.request(e.path,e.request.parse(t)))},async readSubscriptionBatch(t){let e=o.readSubscriptionBatch;return p(e.response,await r.request(e.path,e.request.parse(t)))},async abandonSubscriptionBatch(t){let e=o.abandonSubscriptionBatch;return p(e.response,await r.request(e.path,e.request.parse(t)))},async manageSubscriptionTrial(t){let e=o.manageSubscriptionTrial;return p(e.response,await r.request(e.path,e.request.parse(t)))},async readSubscriptionTrial(t){let e=o.readSubscriptionTrial;return p(e.response,await r.request(e.path,e.request.parse(t)))},async listSubscriptions(t){let e=o.listSubscriptions;return p(e.response,await r.request(e.path,e.request.parse(t)))},async listPurchases(t){let e=o.listPurchases;return p(e.response,await r.request(e.path,e.request.parse(t)))},async listSubscriptionConflicts(t){let e=o.listSubscriptionConflicts;return p(e.response,await r.request(e.path,e.request.parse(t)))},async retrySubscriptionConflict(t){let e=o.retrySubscriptionConflict;return p(e.response,await r.request(e.path,e.request.parse(t)))},async previewRefund(t){let e=o.previewRefund;return p(e.response,await r.request(e.path,e.request.parse(t)))},async refund(t){let e=o.refund;return p(e.response,await r.request(e.path,e.request.parse(t)))},async readRefund(t){let e=o.readRefund;return p(e.response,await r.request(e.path,e.request.parse(t)))},async previewUpdate(t){let e=o.previewUpdate;return p(e.response,await r.request(e.path,e.request.parse(t)))},async update(t){let e=o.update;return p(e.response,await r.request(e.path,e.request.parse(t)))},async readSubscriptionUpdate(t){let e=o.readSubscriptionUpdate;return p(e.response,await r.request(e.path,e.request.parse(t)))},async restoreNativePurchase(t){let e=o.restoreNativePurchase;return p(e.response,await r.request(e.path,e.request.parse(t)))},async verifySubscriptions(t){let e=o.verifySubscriptions;return p(e.response,await r.request(e.path,e.request.parse(t)))},async previewAttach(t){let e=o.previewAttach;return p(e.response,await r.request(e.path,e.request.parse(t)))},async attach(t){let e=o.attach;return p(e.response,await r.request(e.path,e.request.parse(t)))},async readSubscriptionOperation(t){let e=o.readSubscriptionOperation;return p(e.response,await r.request(e.path,e.request.parse(t)))},async readAiPricing(t){let e=o.readAiPricing;return p(e.response,await r.request(e.path,e.request.parse(t)))},async readUsage(t){let e=o.readUsage;return p(e.response,await r.request(e.path,e.request.parse(t)))},async setUsage(t){let e=o.setUsage;return p(e.response,await r.request(e.path,e.request.parse(t)))},async manageBalanceGrant(t){let e=o.manageBalanceGrant;return p(e.response,await r.request(e.path,e.request.parse(t)))},async readBalanceSource(t){let e=o.readBalanceSource;return p(e.response,await r.request(e.path,e.request.parse(t)))},async adjustBalance(t){let e=o.adjustBalance;return p(e.response,await r.request(e.path,e.request.parse(t)))},async listBalanceGrants(t){let e=o.listBalanceGrants;return p(e.response,await r.request(e.path,e.request.parse(t)))},async manageBillingLimits(t){let e=o.manageBillingLimits;return p(e.response,await r.request(e.path,e.request.parse(t)))},async readSeats(t){let e=o.readSeats;return p(e.response,await r.request(e.path,e.request.parse(t)))},async manageSeat(t){let e=o.manageSeat;return p(e.response,await r.request(e.path,e.request.parse(t)))},async manageUsageEntity(t){let e=o.manageUsageEntity;return p(e.response,await r.request(e.path,e.request.parse(t)))},async readUsageAnalytics(t){let e=o.readUsageAnalytics;return p(e.response,await r.request(e.path,e.request.parse(t)))},async readCreditAnalytics(t){let e=o.readCreditAnalytics;return p(e.response,await r.request(e.path,e.request.parse(t)))},async submitUsageBatch(t){let e=o.submitUsageBatch;return p(e.response,await r.request(e.path,e.request.parse(t)))},async readUsageBatch(t){let e=o.readUsageBatch;return p(e.response,await r.request(e.path,e.request.parse(t)))},async readHoldings(t){let e=o.readHoldings;return p(e.response,await r.request(e.path,e.request.parse(t)))},async readLedger(t){let e=o.readLedger;return p(e.response,await r.request(e.path,e.request.parse(t)))},async readBillingInvoice(t){let e=o.readBillingInvoice;return p(e.response,await r.request(e.path,e.request.parse(t)))},async readCreditStatement(t){let e=o.readCreditStatement;return p(e.response,await r.request(e.path,e.request.parse(t)))},async quoteBalance(t){let e=o.quoteBalance;return p(e.response,await r.request(e.path,e.request.parse(t)))},async trackUsage(t){let e=o.trackUsage;return p(e.response,await r.request(e.path,e.request.parse(t)))},async mutateBalance(t){let e=o.mutateBalance;return p(e.response,await r.request(e.path,e.request.parse(t)))},async getCustomer(t){let e=o.getCustomer,a=e.request.safeParse(t);if(!a.success)throw new s("INVALID_REQUEST","Invalid customer lookup");let u=e.response.safeParse(await r.request(e.path,a.data));if(!u.success)throw new s("INVALID_RESPONSE","Invalid customer response");return u.data},async listCustomers(t={}){let e=o.listCustomers,a=e.request.safeParse(t);if(!a.success)throw new s("INVALID_REQUEST","Invalid customer filters");let u=e.response.safeParse(await r.request(e.path,a.data));if(!u.success)throw new s("INVALID_RESPONSE","Invalid customer response");return u.data},async updateCustomer(t){let e=o.updateCustomer,a=e.request.safeParse(t);if(!a.success)throw new s("INVALID_REQUEST","Invalid customer patch");let u=e.response.safeParse(await r.request(e.path,a.data));if(!u.success)throw new s("INVALID_RESPONSE","Invalid customer response");return u.data},async createGuestCustomer(t){let e=o.createGuestCustomer;return e.response.parse(await r.request(e.path,e.request.parse(t)))},async resumeGuestSession(t){let e=o.resumeGuestSession;return e.response.parse(await r.request(e.path,e.request.parse(t)))},async claimGuestCustomer(t){let e=o.claimGuestCustomer;return e.response.parse(await r.request(e.path,e.request.parse(t)))},async renewCustomerSession(t){let e=o.renewSession;return e.response.parse(await r.request(e.path,e.request.parse(t)))},async revokeCustomerSessions(t){let e=o.revokeSessions;return e.response.parse(await r.request(e.path,e.request.parse(t)))},async createCustomerSession(t){let e=o.createSession.request.safeParse({customerId:t});if(!e.success)throw new s("INVALID_REQUEST","A customer ID is required");let a=o.createSession.response.safeParse(await r.request("customer-sessions",e.data));if(!a.success)throw new s("INVALID_RESPONSE","Invalid customer session response");return a.data},async getOrCreateCustomer(t){let e=o.createCustomer.request.safeParse(t);if(!e.success)throw new s("INVALID_REQUEST","Invalid customer input");let a=o.createCustomer.response.safeParse(await r.request("customers",e.data));if(!a.success)throw new s("INVALID_RESPONSE","Invalid customer response");return a.data},async grantOffer(t){let e=o.grantOffer.request.safeParse({...t,requestId:t.requestId??crypto.randomUUID()});if(!e.success||!e.data.customerId)throw new s("INVALID_REQUEST","Invalid offer grant");let a=o.grantOffer.response.safeParse(await r.request("offers/grant",e.data));if(!a.success)throw new s("INVALID_RESPONSE","Invalid offer response");return a.data}}}async function Tt(n,r){if(typeof window<"u")throw new s("SERVER_ONLY","Renewal requires your backend");let{funnelCredentialCommandSchema:t,funnelCredentialResponseSchema:e}=await import("./src-WV6GZYWA.js"),a=q(n);return a.identify(n.apiKey),e.parse(await a.request("funnels",t.parse({...r,operation:"renew_run"})))}export{F as FunnelDecisionTimeoutError,s as IndianaError,Ce as aiPriceSnapshotSchema,Re as aiTokenQuoteSchema,Fe as createAiPricing,ke as createAiUsageMiddleware,Se as createConfigurationSync,Le as createConfiguredAiPricing,j as createFeatureClient,Pe as createFunnelCampaignClient,G as createFunnelDecisionClient,x as createFunnelLocalEvaluator,Te as createFunnelOrchestrationClient,qe as createFunnelStartClient,xt as createGuestToken,kt as createIndianaServer,Ae as createLocalFunnelClient,Ne as createNativeReceiptClient,_e as createPaywallStartClient,Oe as createSynchronizedFunnelLocalEvaluator,Ee as evaluateFunnelNode,Tt as renewFunnelRun};
|