@aippy/runtime 0.4.1-dev.1 → 0.4.2-beta.0
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/README.md +35 -6
- package/dist/ai/errors.d.ts +1 -0
- package/dist/ai/index.d.ts +2 -0
- package/dist/ai/index.js +22 -17
- package/dist/ai/viggle/generate.d.ts +67 -0
- package/dist/ai/viggle/models.d.ts +46 -0
- package/dist/ai/viggle/recovery.d.ts +12 -0
- package/dist/{app-version-checker-Bz7FrEZz.js → app-version-checker-YVIFbytA.js} +18 -17
- package/dist/bridge-K3HqQwdj.js +311 -0
- package/dist/container-message-gRiGPin4.js +56 -0
- package/dist/core/env.d.ts +2 -0
- package/dist/core/index.js +2 -2
- package/dist/core/parent-message.d.ts +5 -0
- package/dist/core/wallet-recharge.d.ts +16 -0
- package/dist/helper-CJ3YV3nf.js +748 -0
- package/dist/{hooks-D5lkty5r.js → hooks-CMKwSLcQ.js} +1 -1
- package/dist/index/index.js +66 -56
- package/dist/index.d.ts +1 -0
- package/dist/ministore/app-authorization.d.ts +9 -0
- package/dist/ministore/authorization.d.ts +6 -0
- package/dist/ministore/consume.d.ts +3 -0
- package/dist/ministore/errors.d.ts +18 -0
- package/dist/ministore/index.d.ts +19 -0
- package/dist/ministore/index.js +99 -0
- package/dist/ministore/order.d.ts +1 -0
- package/dist/ministore/purchase.d.ts +5 -0
- package/dist/ministore/queries.d.ts +14 -0
- package/dist/ministore/recharge.d.ts +12 -0
- package/dist/ministore/transport.d.ts +14 -0
- package/dist/ministore/types.d.ts +177 -0
- package/dist/ministore/update-item.d.ts +3 -0
- package/dist/ministore/validation.d.ts +19 -0
- package/dist/ministore.d.ts +2 -0
- package/dist/recharge-o5P-y8eV.js +1036 -0
- package/dist/tweaks/index.js +1 -1
- package/dist/{useTweaks-v5wEZGGm.js → useTweaks-C7BEMpV3.js} +21 -27
- package/dist/user/bridge.d.ts +3 -8
- package/dist/user/config.d.ts +2 -0
- package/dist/user/index.js +3 -3
- package/dist/utils/app-version-requirements.json.d.ts +4 -0
- package/dist/utils/index.js +1 -1
- package/package.json +15 -3
- package/dist/bridge-CtB9L5kL.js +0 -259
- package/dist/container-message-KgL1paGV.js +0 -56
- package/dist/helper-CZqFi-QF.js +0 -241
|
@@ -0,0 +1,1036 @@
|
|
|
1
|
+
var fe = Object.defineProperty;
|
|
2
|
+
var le = (e, t, r) => t in e ? fe(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
|
|
3
|
+
var z = (e, t, r) => le(e, typeof t != "symbol" ? t + "" : t, r);
|
|
4
|
+
import { a as D, i as he, r as pe, b as me, c as be } from "./bridge-K3HqQwdj.js";
|
|
5
|
+
import { a as B, r as $ } from "./app-version-checker-YVIFbytA.js";
|
|
6
|
+
import { E as x } from "./errors-B3bDbQbD.js";
|
|
7
|
+
import { a as ye, s as ge } from "./container-message-gRiGPin4.js";
|
|
8
|
+
import { j as we } from "./url-c26cuIpu.js";
|
|
9
|
+
class l extends Error {
|
|
10
|
+
constructor(r, o, n = {}) {
|
|
11
|
+
super(
|
|
12
|
+
`${r === "validation" ? x.CODE : x.RUNTIME} ${o}`
|
|
13
|
+
);
|
|
14
|
+
z(this, "kind");
|
|
15
|
+
z(this, "httpStatus");
|
|
16
|
+
z(this, "code");
|
|
17
|
+
z(this, "type");
|
|
18
|
+
z(this, "reason");
|
|
19
|
+
z(this, "appMessage");
|
|
20
|
+
z(this, "traceId");
|
|
21
|
+
z(this, "retryAfterMs");
|
|
22
|
+
z(this, "bizOrderNo");
|
|
23
|
+
z(this, "settlementUnknown");
|
|
24
|
+
z(this, "authorizationUnknown");
|
|
25
|
+
z(this, "cause");
|
|
26
|
+
this.name = "MinistoreError", this.kind = r, this.httpStatus = n.httpStatus, this.code = n.code, this.type = n.type, this.reason = n.reason, this.appMessage = n.appMessage, this.traceId = n.traceId, this.retryAfterMs = n.retryAfterMs, this.bizOrderNo = n.bizOrderNo, this.settlementUnknown = n.settlementUnknown ?? !1, this.authorizationUnknown = n.authorizationUnknown ?? !1, this.cause = n.cause;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function c(e) {
|
|
30
|
+
throw new l("validation", e);
|
|
31
|
+
}
|
|
32
|
+
function y() {
|
|
33
|
+
throw new l("protocol", "Invalid ministore response");
|
|
34
|
+
}
|
|
35
|
+
function v(e) {
|
|
36
|
+
return (!e || typeof e != "object" || Array.isArray(e)) && y(), e;
|
|
37
|
+
}
|
|
38
|
+
function h(e) {
|
|
39
|
+
return typeof e != "string" && y(), e;
|
|
40
|
+
}
|
|
41
|
+
function b(e, t = !1) {
|
|
42
|
+
return (!Number.isSafeInteger(e) || !t && e < 0) && y(), e;
|
|
43
|
+
}
|
|
44
|
+
function N(e) {
|
|
45
|
+
return typeof e != "boolean" && y(), e;
|
|
46
|
+
}
|
|
47
|
+
function E(e, t) {
|
|
48
|
+
return Array.isArray(e) || y(), e.map(t);
|
|
49
|
+
}
|
|
50
|
+
function ze(e) {
|
|
51
|
+
const t = v(e);
|
|
52
|
+
return {
|
|
53
|
+
title: h(t.title),
|
|
54
|
+
subtitle: h(t.subtitle),
|
|
55
|
+
iconUrl: h(t.iconUrl)
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function G(e) {
|
|
59
|
+
const t = v(e);
|
|
60
|
+
return "value" in t || y(), {
|
|
61
|
+
benefitKey: h(t.benefitKey),
|
|
62
|
+
kind: h(t.kind),
|
|
63
|
+
value: t.value,
|
|
64
|
+
quantity: b(t.quantity),
|
|
65
|
+
used: b(t.used),
|
|
66
|
+
display: ze(t.display)
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
function F(e) {
|
|
70
|
+
const t = v(e);
|
|
71
|
+
"value" in t || y();
|
|
72
|
+
const r = h(t.itemId);
|
|
73
|
+
_(r) || y();
|
|
74
|
+
const o = h(t.orderId);
|
|
75
|
+
return o !== "" && !k(o) && y(), {
|
|
76
|
+
itemId: r,
|
|
77
|
+
value: t.value,
|
|
78
|
+
orderId: o,
|
|
79
|
+
bizOrderNo: h(t.bizOrderNo),
|
|
80
|
+
createdAt: h(t.createdAt),
|
|
81
|
+
updatedAt: h(t.updatedAt)
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
function We(e) {
|
|
85
|
+
if (e == null) return;
|
|
86
|
+
const t = v(e);
|
|
87
|
+
if (!(t.itemId === "" || Object.keys(t).length === 0))
|
|
88
|
+
return F(t);
|
|
89
|
+
}
|
|
90
|
+
function ve(e) {
|
|
91
|
+
const t = v(e), r = G(t), o = r.quantity === 0 && r.used === 0 && (t.holdings === null || t.holdings === void 0) && (t.items === null || t.items === void 0), n = o || t.holdings === null || t.holdings === void 0 ? [] : E(t.holdings, (u) => {
|
|
92
|
+
const a = v(u), s = h(a.orderId), d = a.source === void 0 ? "" : h(a.source);
|
|
93
|
+
return (!k(s) && !(s === "" && d === "FREE") || !("value" in a)) && y(), {
|
|
94
|
+
orderId: s,
|
|
95
|
+
bizOrderNo: h(a.bizOrderNo),
|
|
96
|
+
value: a.value,
|
|
97
|
+
quantity: b(a.quantity),
|
|
98
|
+
createdAt: h(a.createdAt),
|
|
99
|
+
source: d
|
|
100
|
+
};
|
|
101
|
+
}), i = o || t.items === null || t.items === void 0 ? [] : E(t.items, F);
|
|
102
|
+
return { ...r, holdings: n, items: i };
|
|
103
|
+
}
|
|
104
|
+
function I(e, t) {
|
|
105
|
+
const r = v(e), o = h(r.reason), n = t(r);
|
|
106
|
+
return o === "" ? { ok: !0, data: n } : { ok: !1, reason: o, data: n };
|
|
107
|
+
}
|
|
108
|
+
function W(e) {
|
|
109
|
+
return {
|
|
110
|
+
benefitKey: h(e.benefitKey),
|
|
111
|
+
authMode: h(e.authMode),
|
|
112
|
+
authorized: N(e.authorized),
|
|
113
|
+
authorizedAt: h(e.authorizedAt),
|
|
114
|
+
bizOrderNo: h(e.bizOrderNo),
|
|
115
|
+
quantity: b(e.quantity),
|
|
116
|
+
amount: b(e.amount),
|
|
117
|
+
expireAt: h(e.expireAt),
|
|
118
|
+
used: N(e.used)
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
function K(e) {
|
|
122
|
+
(!e || typeof e != "object") && c("An action is required"), (typeof e.benefitKey != "string" || [...e.benefitKey].length < 1 || [...e.benefitKey].length > 64) && c("benefitKey must contain 1–64 Unicode code points"), e.bizOrderNo !== void 0 && (O(e.bizOrderNo, "bizOrderNo", 64), e.bizOrderNo.startsWith("aisdk:managed:") && c("bizOrderNo uses a reserved backend order prefix"));
|
|
123
|
+
}
|
|
124
|
+
function Ae(e) {
|
|
125
|
+
(!Array.isArray(e) || e.length < 1 || e.length > 99) && c("itemIds must contain 1 to 99 item IDs");
|
|
126
|
+
const t = /* @__PURE__ */ new Set();
|
|
127
|
+
for (const r of e) {
|
|
128
|
+
(typeof r != "string" || !_(r)) && c("itemIds must contain positive uint64 decimal strings");
|
|
129
|
+
const o = BigInt(r).toString();
|
|
130
|
+
t.has(o) && c("itemIds must not contain duplicates"), t.add(o);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
function Je(e) {
|
|
134
|
+
if (K(e), e.autoPurchase !== void 0 && typeof e.autoPurchase != "boolean" && c("autoPurchase must be a boolean"), e.quantity !== void 0 && C(e.quantity), e.itemIds !== void 0 && (Ae(e.itemIds), e.quantity !== void 0 && e.quantity !== e.itemIds.length && c("quantity must equal itemIds length")), e.itemValues !== void 0) {
|
|
135
|
+
(!Array.isArray(e.itemValues) || e.itemValues.length < 1 || e.itemValues.length > 99) && c("itemValues must contain 1 to 99 item values"), e.itemValues.some((r) => r == null) && c("itemValues must contain JSON values");
|
|
136
|
+
const t = e.quantity ?? e.itemIds?.length ?? 1;
|
|
137
|
+
(e.itemValues.length > t || (e.autoPurchase !== !0 || e.itemIds !== void 0) && e.itemValues.length !== t) && c(
|
|
138
|
+
"itemValues must match consumed items or the automatic purchase deficit"
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
function Qe(e) {
|
|
143
|
+
K(e), e.quantity !== void 0 && C(e.quantity), e.itemValues !== void 0 && ((!Array.isArray(e.itemValues) || e.itemValues.length < 1 || e.itemValues.length > 99) && c("itemValues must contain 1 to 99 item values"), e.itemValues.some((t) => t == null) && c("itemValues must contain JSON values"), e.quantity !== void 0 && e.quantity !== e.itemValues.length && c("quantity must equal itemValues length"));
|
|
144
|
+
}
|
|
145
|
+
function Ze(e) {
|
|
146
|
+
K(e), (typeof e.itemId != "string" || !_(e.itemId)) && c("itemId must be a positive uint64 decimal string"), (e.value === null || e.value === void 0) && c("value is required");
|
|
147
|
+
}
|
|
148
|
+
function O(e, t, r = 128) {
|
|
149
|
+
(typeof e != "string" || [...e].length < 1 || [...e].length > r) && c(`${t} must contain a bounded Unicode string`);
|
|
150
|
+
}
|
|
151
|
+
function C(e) {
|
|
152
|
+
return (!Number.isSafeInteger(e) || e < 1 || e > 99) && c("quantity must be an integer from 1 to 99"), e;
|
|
153
|
+
}
|
|
154
|
+
function k(e) {
|
|
155
|
+
return /^[0-9]+$/.test(e) && BigInt(e) <= 18446744073709551615n;
|
|
156
|
+
}
|
|
157
|
+
function _(e) {
|
|
158
|
+
return k(e) && BigInt(e) > 0n;
|
|
159
|
+
}
|
|
160
|
+
const J = 3e4, L = /* @__PURE__ */ Symbol("authorization-pending"), Oe = "wallet.authorize-result", Ne = "wallet.authorize-alive", ke = "wallet.authorize-alive-ack";
|
|
161
|
+
let Ee = 0;
|
|
162
|
+
function Q() {
|
|
163
|
+
return typeof globalThis.crypto?.randomUUID == "function" ? globalThis.crypto.randomUUID() : `ministore-${Date.now().toString(36)}-${++Ee}-${Math.random().toString(36).slice(2)}`;
|
|
164
|
+
}
|
|
165
|
+
const U = /* @__PURE__ */ new WeakMap();
|
|
166
|
+
function Z(e) {
|
|
167
|
+
return v(typeof e == "string" ? JSON.parse(e) : e);
|
|
168
|
+
}
|
|
169
|
+
function Ie(e, t, r) {
|
|
170
|
+
let o = U.get(e);
|
|
171
|
+
if (o) {
|
|
172
|
+
if (e.processAuthorizeResult !== o.dispatch)
|
|
173
|
+
throw new Error("The App authorization callback was replaced");
|
|
174
|
+
} else {
|
|
175
|
+
const i = /* @__PURE__ */ new Map(), u = e.processAuthorizeResult, a = (s) => {
|
|
176
|
+
let d;
|
|
177
|
+
try {
|
|
178
|
+
d = Z(s);
|
|
179
|
+
} catch {
|
|
180
|
+
u?.call(e, s);
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
const f = typeof d.requestId == "string" ? i.get(d.requestId) : void 0;
|
|
184
|
+
f ? f(d) : u?.call(e, s);
|
|
185
|
+
};
|
|
186
|
+
o = {
|
|
187
|
+
previous: u,
|
|
188
|
+
hadPrevious: Object.prototype.hasOwnProperty.call(
|
|
189
|
+
e,
|
|
190
|
+
"processAuthorizeResult"
|
|
191
|
+
),
|
|
192
|
+
dispatch: a,
|
|
193
|
+
pending: i
|
|
194
|
+
}, e.processAuthorizeResult = a, U.set(e, o);
|
|
195
|
+
}
|
|
196
|
+
o.pending.set(t, r);
|
|
197
|
+
const n = o;
|
|
198
|
+
return () => {
|
|
199
|
+
n.pending.delete(t), n.pending.size === 0 && (e.processAuthorizeResult === n.dispatch && (n.hadPrevious ? e.processAuthorizeResult = n.previous : delete e.processAuthorizeResult), U.delete(e));
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
function X(e, t) {
|
|
203
|
+
const r = typeof t.code == "number" || typeof t.code == "string" ? t.code : void 0, o = typeof t.reason == "string" ? t.reason : void 0, n = ["unsupported_type", "invalid_params", "busy"].includes(o ?? "") || o === "server_error" && [1001, 2e4, 1002, 1003, 1004, 401, 11001, 10001].includes(
|
|
204
|
+
Number(r)
|
|
205
|
+
);
|
|
206
|
+
return new l("authorization", "App authorization failed", {
|
|
207
|
+
bizOrderNo: e.bizOrderNo,
|
|
208
|
+
code: r,
|
|
209
|
+
type: o,
|
|
210
|
+
appMessage: typeof t.message == "string" ? t.message : void 0,
|
|
211
|
+
authorizationUnknown: !n
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
function Y(e, t) {
|
|
215
|
+
return e.benefitKey !== t.benefitKey || !e.authorized ? !1 : e.authMode === "none" || e.authMode === "once" ? !0 : e.authMode === "every" && e.bizOrderNo === t.bizOrderNo && e.quantity >= t.quantity && e.quantity <= 99 && !e.used;
|
|
216
|
+
}
|
|
217
|
+
function Re(e, t) {
|
|
218
|
+
const r = v(t.data), o = h(r.reason);
|
|
219
|
+
return !o && r.authorized !== !1 && !(r.authMode === "every" && r.used === !0) && y(), new l("authorization", "App authorization rejected", {
|
|
220
|
+
bizOrderNo: e.bizOrderNo,
|
|
221
|
+
type: "rejected",
|
|
222
|
+
reason: o || "authorization_required",
|
|
223
|
+
code: typeof t.code == "number" || typeof t.code == "string" ? t.code : void 0,
|
|
224
|
+
appMessage: typeof t.message == "string" ? t.message : void 0,
|
|
225
|
+
authorizationUnknown: !1
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
function Me(e, t) {
|
|
229
|
+
const r = Z(e), o = b(r.code), n = h(r.msg);
|
|
230
|
+
if (o !== 0)
|
|
231
|
+
throw X(t, {
|
|
232
|
+
reason: "server_error",
|
|
233
|
+
code: o,
|
|
234
|
+
message: n
|
|
235
|
+
});
|
|
236
|
+
const i = I(r.data, W);
|
|
237
|
+
return i.ok ? Y(i.data, t) ? i : { ok: !1, reason: "authorization_required", data: i.data } : i;
|
|
238
|
+
}
|
|
239
|
+
function ee(e, t) {
|
|
240
|
+
const r = v(e);
|
|
241
|
+
switch (r.status) {
|
|
242
|
+
case "closed":
|
|
243
|
+
if (r.requesting === !0) return L;
|
|
244
|
+
throw r.requesting !== !1 && y(), new l("authorization", "App authorization closed", {
|
|
245
|
+
bizOrderNo: t.bizOrderNo,
|
|
246
|
+
type: "closed"
|
|
247
|
+
});
|
|
248
|
+
case "failed":
|
|
249
|
+
throw r.reason === "rejected" ? Re(t, r) : X(t, r);
|
|
250
|
+
case "timeout":
|
|
251
|
+
throw new l("authorization", "App authorization timed out", {
|
|
252
|
+
bizOrderNo: t.bizOrderNo,
|
|
253
|
+
type: "timeout",
|
|
254
|
+
authorizationUnknown: !0
|
|
255
|
+
});
|
|
256
|
+
case "success":
|
|
257
|
+
return Me(r.data, t);
|
|
258
|
+
default:
|
|
259
|
+
y();
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
function te(e, t) {
|
|
263
|
+
return {
|
|
264
|
+
type: "authorize",
|
|
265
|
+
title: e.title,
|
|
266
|
+
buttonText: e.buttonText,
|
|
267
|
+
...e.content !== void 0 ? { content: e.content } : {},
|
|
268
|
+
payload: {
|
|
269
|
+
benefitKey: e.benefitKey,
|
|
270
|
+
bizOrderNo: e.bizOrderNo,
|
|
271
|
+
quantity: e.quantity
|
|
272
|
+
},
|
|
273
|
+
requestId: t
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
function Ue(e, t, r, o, n) {
|
|
277
|
+
if (!r)
|
|
278
|
+
try {
|
|
279
|
+
const i = ee(e, t);
|
|
280
|
+
if (i === L) return;
|
|
281
|
+
o(), n(i);
|
|
282
|
+
} catch (i) {
|
|
283
|
+
o(
|
|
284
|
+
i instanceof l && i.kind === "authorization" ? i : new l("protocol", "Invalid App authorization result", {
|
|
285
|
+
bizOrderNo: t.bizOrderNo,
|
|
286
|
+
authorizationUnknown: !0,
|
|
287
|
+
cause: i
|
|
288
|
+
})
|
|
289
|
+
);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
function Se(e, t, r) {
|
|
293
|
+
if (t?.aborted)
|
|
294
|
+
return Promise.reject(
|
|
295
|
+
new l("abort", "App authorization cancelled", {
|
|
296
|
+
bizOrderNo: e.bizOrderNo
|
|
297
|
+
})
|
|
298
|
+
);
|
|
299
|
+
const o = Q();
|
|
300
|
+
return new Promise((n, i) => {
|
|
301
|
+
let u = !1;
|
|
302
|
+
const a = () => {
|
|
303
|
+
clearTimeout(f), window.removeEventListener("message", g), t?.removeEventListener("abort", d);
|
|
304
|
+
}, s = (p) => {
|
|
305
|
+
u || (u = !0, a(), i(p));
|
|
306
|
+
}, d = () => s(
|
|
307
|
+
new l("abort", "App authorization cancelled", {
|
|
308
|
+
bizOrderNo: e.bizOrderNo,
|
|
309
|
+
authorizationUnknown: !0
|
|
310
|
+
})
|
|
311
|
+
), f = setTimeout(() => {
|
|
312
|
+
s(
|
|
313
|
+
new l(
|
|
314
|
+
"authorization",
|
|
315
|
+
"App authorization response timed out",
|
|
316
|
+
{
|
|
317
|
+
bizOrderNo: e.bizOrderNo,
|
|
318
|
+
type: "timeout",
|
|
319
|
+
authorizationUnknown: !0
|
|
320
|
+
}
|
|
321
|
+
)
|
|
322
|
+
);
|
|
323
|
+
}, J), g = (p) => {
|
|
324
|
+
if (he(p, r)) {
|
|
325
|
+
if (p.data.type === Ne && p.data.requestId === o) {
|
|
326
|
+
window.parent.postMessage(
|
|
327
|
+
{ type: ke, requestId: o },
|
|
328
|
+
r
|
|
329
|
+
);
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
p.data.type === Oe && p.data.requestId === o && Ue(
|
|
333
|
+
p.data,
|
|
334
|
+
e,
|
|
335
|
+
u,
|
|
336
|
+
(m) => {
|
|
337
|
+
m ? s(m) : (u = !0, a());
|
|
338
|
+
},
|
|
339
|
+
n
|
|
340
|
+
);
|
|
341
|
+
}
|
|
342
|
+
};
|
|
343
|
+
window.addEventListener("message", g), t?.addEventListener("abort", d, { once: !0 });
|
|
344
|
+
try {
|
|
345
|
+
window.parent.postMessage(
|
|
346
|
+
{
|
|
347
|
+
type: "wallet.authorize",
|
|
348
|
+
parameters: te(e, o)
|
|
349
|
+
},
|
|
350
|
+
r
|
|
351
|
+
);
|
|
352
|
+
} catch (p) {
|
|
353
|
+
s(
|
|
354
|
+
new l(
|
|
355
|
+
"authorization",
|
|
356
|
+
"App authorization request failed",
|
|
357
|
+
{
|
|
358
|
+
bizOrderNo: e.bizOrderNo,
|
|
359
|
+
authorizationUnknown: !0,
|
|
360
|
+
cause: p
|
|
361
|
+
}
|
|
362
|
+
)
|
|
363
|
+
);
|
|
364
|
+
}
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
function Xe() {
|
|
368
|
+
if (typeof window > "u" || typeof navigator > "u" || typeof window.webkit?.messageHandlers?.aippyListener?.postMessage != "function")
|
|
369
|
+
return !1;
|
|
370
|
+
const e = B("ministore");
|
|
371
|
+
return e.envCheck.type === "new_app" && e.supported;
|
|
372
|
+
}
|
|
373
|
+
function Te(e, t) {
|
|
374
|
+
const r = typeof window > "u" ? void 0 : window.webkit?.messageHandlers?.aippyListener;
|
|
375
|
+
if (typeof r?.postMessage != "function") {
|
|
376
|
+
const i = D();
|
|
377
|
+
return i ? Se(e, t, i) : Promise.reject(
|
|
378
|
+
new l("unsupported", "App authorization is unavailable", {
|
|
379
|
+
bizOrderNo: e.bizOrderNo
|
|
380
|
+
})
|
|
381
|
+
);
|
|
382
|
+
}
|
|
383
|
+
if (t?.aborted)
|
|
384
|
+
return Promise.reject(
|
|
385
|
+
new l("abort", "App authorization cancelled", {
|
|
386
|
+
bizOrderNo: e.bizOrderNo
|
|
387
|
+
})
|
|
388
|
+
);
|
|
389
|
+
try {
|
|
390
|
+
const i = $("ministore");
|
|
391
|
+
if (i.envCheck.type !== "new_app" || !i.supported)
|
|
392
|
+
throw new Error("Native App authorization is unavailable");
|
|
393
|
+
} catch (i) {
|
|
394
|
+
return Promise.reject(
|
|
395
|
+
new l("unsupported", "App authorization is unavailable", {
|
|
396
|
+
bizOrderNo: e.bizOrderNo,
|
|
397
|
+
cause: i
|
|
398
|
+
})
|
|
399
|
+
);
|
|
400
|
+
}
|
|
401
|
+
const o = window, n = Q();
|
|
402
|
+
return new Promise((i, u) => {
|
|
403
|
+
let a = !1, s = () => {
|
|
404
|
+
};
|
|
405
|
+
const d = () => {
|
|
406
|
+
clearTimeout(p), s(), t?.removeEventListener("abort", g);
|
|
407
|
+
}, f = (m) => {
|
|
408
|
+
a || (a = !0, d(), u(m));
|
|
409
|
+
}, g = () => f(
|
|
410
|
+
new l("abort", "App authorization cancelled", {
|
|
411
|
+
bizOrderNo: e.bizOrderNo,
|
|
412
|
+
authorizationUnknown: !0
|
|
413
|
+
})
|
|
414
|
+
), p = setTimeout(() => {
|
|
415
|
+
f(
|
|
416
|
+
new l(
|
|
417
|
+
"authorization",
|
|
418
|
+
"App authorization response timed out",
|
|
419
|
+
{
|
|
420
|
+
bizOrderNo: e.bizOrderNo,
|
|
421
|
+
type: "timeout",
|
|
422
|
+
authorizationUnknown: !0
|
|
423
|
+
}
|
|
424
|
+
)
|
|
425
|
+
);
|
|
426
|
+
}, J);
|
|
427
|
+
try {
|
|
428
|
+
s = Ie(o, n, (m) => {
|
|
429
|
+
if (!a)
|
|
430
|
+
try {
|
|
431
|
+
const A = ee(m, e);
|
|
432
|
+
if (A === L) return;
|
|
433
|
+
a = !0, d(), i(A);
|
|
434
|
+
} catch (A) {
|
|
435
|
+
f(
|
|
436
|
+
A instanceof l && A.kind === "authorization" ? A : new l(
|
|
437
|
+
"protocol",
|
|
438
|
+
"Invalid App authorization result",
|
|
439
|
+
{
|
|
440
|
+
bizOrderNo: e.bizOrderNo,
|
|
441
|
+
authorizationUnknown: !0,
|
|
442
|
+
cause: A
|
|
443
|
+
}
|
|
444
|
+
)
|
|
445
|
+
);
|
|
446
|
+
}
|
|
447
|
+
});
|
|
448
|
+
} catch (m) {
|
|
449
|
+
f(
|
|
450
|
+
new l(
|
|
451
|
+
"unsupported",
|
|
452
|
+
"App authorization callback unavailable",
|
|
453
|
+
{
|
|
454
|
+
bizOrderNo: e.bizOrderNo,
|
|
455
|
+
cause: m
|
|
456
|
+
}
|
|
457
|
+
)
|
|
458
|
+
);
|
|
459
|
+
return;
|
|
460
|
+
}
|
|
461
|
+
t?.addEventListener("abort", g, { once: !0 });
|
|
462
|
+
try {
|
|
463
|
+
r.postMessage({
|
|
464
|
+
command: "wallet.authorize",
|
|
465
|
+
parameters: te(e, n)
|
|
466
|
+
});
|
|
467
|
+
} catch (m) {
|
|
468
|
+
f(
|
|
469
|
+
new l(
|
|
470
|
+
"authorization",
|
|
471
|
+
"App authorization request failed",
|
|
472
|
+
{
|
|
473
|
+
bizOrderNo: e.bizOrderNo,
|
|
474
|
+
authorizationUnknown: !0,
|
|
475
|
+
cause: m
|
|
476
|
+
}
|
|
477
|
+
)
|
|
478
|
+
);
|
|
479
|
+
}
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
const T = /* @__PURE__ */ Symbol("ministoreScopeCheck");
|
|
483
|
+
function re(e) {
|
|
484
|
+
let t;
|
|
485
|
+
try {
|
|
486
|
+
t = new URL(e ?? `${pe()}/aisdk/v1/`);
|
|
487
|
+
} catch {
|
|
488
|
+
c("baseUrl must be a valid official Aippy API URL");
|
|
489
|
+
}
|
|
490
|
+
return (!me(t.origin) || t.username || t.password || t.search || t.hash || t.pathname !== "/aisdk/v1" && t.pathname !== "/aisdk/v1/") && c(
|
|
491
|
+
"baseUrl must use an official HTTPS Aippy API origin and /aisdk/v1/"
|
|
492
|
+
), t.href;
|
|
493
|
+
}
|
|
494
|
+
function ne(e) {
|
|
495
|
+
if (e !== void 0)
|
|
496
|
+
try {
|
|
497
|
+
return JSON.stringify(e, (t, r) => {
|
|
498
|
+
if (["undefined", "bigint", "function", "symbol"].includes(typeof r) || typeof r == "number" && !Number.isFinite(r))
|
|
499
|
+
throw new TypeError("Non-JSON request value");
|
|
500
|
+
return r;
|
|
501
|
+
});
|
|
502
|
+
} catch {
|
|
503
|
+
c("Request body must contain finite, non-cyclic JSON values");
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
function qe(e, t) {
|
|
507
|
+
if (t === void 0) return;
|
|
508
|
+
const r = JSON.parse(t), o = e === "benefits/items/update" ? [r.value] : e === "benefits/purchase" || e === "benefits/consume" ? r.itemValues ?? [] : [], n = new TextEncoder();
|
|
509
|
+
for (const i of o) {
|
|
510
|
+
let u = JSON.stringify(i);
|
|
511
|
+
if (typeof i == "string")
|
|
512
|
+
try {
|
|
513
|
+
JSON.parse(i), u = i;
|
|
514
|
+
} catch {
|
|
515
|
+
}
|
|
516
|
+
n.encode(u).byteLength > 2048 && c("Each item value must encode to at most 2048 UTF-8 bytes");
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
function Ye(e) {
|
|
520
|
+
return JSON.parse(ne(e));
|
|
521
|
+
}
|
|
522
|
+
function S(e) {
|
|
523
|
+
if (e?.aborted)
|
|
524
|
+
throw e.reason ?? new DOMException("Aborted", "AbortError");
|
|
525
|
+
}
|
|
526
|
+
function j(e) {
|
|
527
|
+
return e !== null && typeof e == "object" && !Array.isArray(e) ? e : void 0;
|
|
528
|
+
}
|
|
529
|
+
function Pe(e) {
|
|
530
|
+
if (!e) return;
|
|
531
|
+
const t = Number(e), r = Number.isFinite(t) ? t * 1e3 : Date.parse(e) - Date.now();
|
|
532
|
+
return Number.isFinite(r) && r >= 0 ? r : void 0;
|
|
533
|
+
}
|
|
534
|
+
async function R(e, t, r, o) {
|
|
535
|
+
const n = we(
|
|
536
|
+
re(t.baseUrl),
|
|
537
|
+
`ministore/${e}`
|
|
538
|
+
), i = ne(r.body);
|
|
539
|
+
qe(e, i);
|
|
540
|
+
let u = !1, a, s = "auth";
|
|
541
|
+
const d = {
|
|
542
|
+
bizOrderNo: r.bizOrderNo
|
|
543
|
+
};
|
|
544
|
+
try {
|
|
545
|
+
S(t.signal);
|
|
546
|
+
const f = await ye();
|
|
547
|
+
S(t.signal), t[T]?.(), t.language && f.set("App-Language", t.language), r.body !== void 0 && f.set("Content-Type", "application/json"), s = "network", u = !0, a = await globalThis.fetch(n, {
|
|
548
|
+
method: r.method,
|
|
549
|
+
headers: f,
|
|
550
|
+
cache: "no-store",
|
|
551
|
+
credentials: "omit",
|
|
552
|
+
redirect: "error",
|
|
553
|
+
signal: t.signal,
|
|
554
|
+
body: i
|
|
555
|
+
}), d.httpStatus = a.status, d.traceId = a.headers.get("X-Trace-Id") ?? void 0, d.retryAfterMs = Pe(a.headers.get("Retry-After")), s = "protocol";
|
|
556
|
+
const g = await a.json().catch((p) => {
|
|
557
|
+
if (a.ok) throw p;
|
|
558
|
+
});
|
|
559
|
+
if (S(t.signal), a.status !== 200) {
|
|
560
|
+
const p = j(g), m = j(p?.error), de = typeof m?.message == "string" && (typeof m.code == "number" || typeof m.code == "string") && [400, 401, 403, 429].includes(a.status);
|
|
561
|
+
if (d.settlementUnknown = r.method === "POST" && !de, d.code = typeof m?.code == "number" || typeof m?.code == "string" ? m.code : void 0, d.type = typeof m?.type == "string" ? m.type : void 0, d.appMessage = typeof p?.appMessage == "string" ? p.appMessage : void 0, d.appMessage)
|
|
562
|
+
try {
|
|
563
|
+
ge(d.appMessage);
|
|
564
|
+
} catch {
|
|
565
|
+
}
|
|
566
|
+
throw new l(
|
|
567
|
+
"http",
|
|
568
|
+
typeof m?.message == "string" ? m.message : `Ministore request failed (${a.status})`,
|
|
569
|
+
d
|
|
570
|
+
);
|
|
571
|
+
}
|
|
572
|
+
return o(g);
|
|
573
|
+
} catch (f) {
|
|
574
|
+
if (f instanceof l && f.kind === "http") throw f;
|
|
575
|
+
d.settlementUnknown = u && r.method === "POST", d.cause = f;
|
|
576
|
+
const g = t.signal?.aborted || f instanceof Error && f.name === "AbortError";
|
|
577
|
+
throw new l(
|
|
578
|
+
g ? "abort" : s,
|
|
579
|
+
g ? "Ministore request cancelled" : s === "auth" ? "Ministore authentication unavailable" : s === "network" ? "Ministore network request failed" : "Invalid ministore response",
|
|
580
|
+
d
|
|
581
|
+
);
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
function Ke(e = {}) {
|
|
585
|
+
return R(
|
|
586
|
+
"wallet/balance",
|
|
587
|
+
e,
|
|
588
|
+
{ method: "GET" },
|
|
589
|
+
(t) => {
|
|
590
|
+
const r = v(t);
|
|
591
|
+
return r.assetType !== "GEM" && y(), b(r.balance, !0);
|
|
592
|
+
}
|
|
593
|
+
);
|
|
594
|
+
}
|
|
595
|
+
async function Ce(e, t = {}) {
|
|
596
|
+
(!e || typeof e != "object") && c("An authorization query is required"), O(e.benefitKey, "benefitKey", 64), e.bizOrderNo !== void 0 && O(e.bizOrderNo, "bizOrderNo", 64);
|
|
597
|
+
const r = new URLSearchParams({ benefitKey: e.benefitKey });
|
|
598
|
+
return e.bizOrderNo && r.set("bizOrderNo", e.bizOrderNo), R(
|
|
599
|
+
`benefits/authorization?${r}`,
|
|
600
|
+
t,
|
|
601
|
+
{ method: "GET", bizOrderNo: e.bizOrderNo },
|
|
602
|
+
(o) => I(o, W)
|
|
603
|
+
);
|
|
604
|
+
}
|
|
605
|
+
function et(e = {}) {
|
|
606
|
+
return R(
|
|
607
|
+
"catalog",
|
|
608
|
+
e,
|
|
609
|
+
{ method: "GET" },
|
|
610
|
+
(t) => I(t, (r) => ({
|
|
611
|
+
enabled: N(r.enabled),
|
|
612
|
+
items: E(r.items, (o) => {
|
|
613
|
+
const n = v(o);
|
|
614
|
+
return {
|
|
615
|
+
...G(n),
|
|
616
|
+
price: b(n.price),
|
|
617
|
+
freeQuota: b(n.freeQuota),
|
|
618
|
+
maxQuantity: b(n.maxQuantity),
|
|
619
|
+
consumable: N(n.consumable),
|
|
620
|
+
maxUserPurchase: b(n.maxUserPurchase),
|
|
621
|
+
userPurchased: b(n.userPurchased),
|
|
622
|
+
maxTotalPurchase: b(n.maxTotalPurchase),
|
|
623
|
+
totalSold: b(n.totalSold),
|
|
624
|
+
authMode: h(n.authMode),
|
|
625
|
+
authRequired: N(n.authRequired),
|
|
626
|
+
authorized: N(n.authorized),
|
|
627
|
+
authorizedAt: h(n.authorizedAt)
|
|
628
|
+
};
|
|
629
|
+
})
|
|
630
|
+
}))
|
|
631
|
+
);
|
|
632
|
+
}
|
|
633
|
+
function tt(e = {}) {
|
|
634
|
+
return R(
|
|
635
|
+
"benefits",
|
|
636
|
+
e,
|
|
637
|
+
{ method: "GET" },
|
|
638
|
+
(t) => I(t, (r) => ({ benefits: E(r.benefits, ve) }))
|
|
639
|
+
);
|
|
640
|
+
}
|
|
641
|
+
function q(e) {
|
|
642
|
+
return e.replace(/^\p{White_Space}+|\p{White_Space}+$/gu, "");
|
|
643
|
+
}
|
|
644
|
+
function H(e, t) {
|
|
645
|
+
if (e === void 0) return [];
|
|
646
|
+
Array.isArray(e) || c(`${t} must be a string array`);
|
|
647
|
+
const r = /* @__PURE__ */ new Set();
|
|
648
|
+
for (const o of e) {
|
|
649
|
+
typeof o != "string" && c(`${t} must contain strings`);
|
|
650
|
+
for (const n of o.split(",")) {
|
|
651
|
+
const i = q(n);
|
|
652
|
+
i && r.add(i);
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
return [...r];
|
|
656
|
+
}
|
|
657
|
+
async function rt(e = {}, t = {}) {
|
|
658
|
+
(!e || typeof e != "object" || Array.isArray(e)) && c("A records query must be an object"), e.benefitKey !== void 0 && O(e.benefitKey, "benefitKey", 64);
|
|
659
|
+
const r = H(e.benefitKeys, "benefitKeys");
|
|
660
|
+
e.benefitKeys?.length && r.length === 0 && c("benefitKeys must contain at least one non-blank key");
|
|
661
|
+
for (const s of r) O(s, "benefitKeys", 64);
|
|
662
|
+
const o = e.benefitKey === void 0 ? void 0 : q(e.benefitKey);
|
|
663
|
+
o === "" && c("benefitKey must not be blank"), (/* @__PURE__ */ new Set([...r, ...o ? [o] : []])).size > 50 && c("At most 50 distinct benefit keys are allowed");
|
|
664
|
+
const n = [
|
|
665
|
+
...new Set(H(e.ops, "ops").map((s) => s.toUpperCase()))
|
|
666
|
+
];
|
|
667
|
+
n.some((s) => s !== "PURCHASE" && s !== "CONSUME") && c("ops must contain PURCHASE or CONSUME"), e.charge !== void 0 && typeof e.charge != "string" && c("charge must be CHARGED or UNCHARGED");
|
|
668
|
+
const i = e.charge === void 0 ? void 0 : q(e.charge).toUpperCase();
|
|
669
|
+
i && i !== "CHARGED" && i !== "UNCHARGED" && c("charge must be CHARGED or UNCHARGED");
|
|
670
|
+
const u = e.limit ?? 20;
|
|
671
|
+
(!Number.isInteger(u) || u < 1 || u > 50) && c("limit must be an integer from 1 to 50"), e.cursor !== void 0 && (typeof e.cursor != "string" || e.cursor !== "" && !k(e.cursor)) && c("cursor must be a uint64 decimal string");
|
|
672
|
+
const a = new URLSearchParams({ limit: String(u) });
|
|
673
|
+
e.cursor && a.set("cursor", e.cursor), e.benefitKey !== void 0 && a.set("benefitKey", e.benefitKey);
|
|
674
|
+
for (const s of r) a.append("benefitKeys", s);
|
|
675
|
+
for (const s of n) a.append("ops", s);
|
|
676
|
+
return i && a.set("charge", i), R(
|
|
677
|
+
`records?${a}`,
|
|
678
|
+
t,
|
|
679
|
+
{ method: "GET" },
|
|
680
|
+
(s) => I(s, (d) => {
|
|
681
|
+
const f = h(d.nextCursor);
|
|
682
|
+
return f !== "" && !k(f) && y(), {
|
|
683
|
+
nextCursor: f,
|
|
684
|
+
records: E(d.records, (g) => {
|
|
685
|
+
const p = v(g), m = h(p.id);
|
|
686
|
+
return (!k(m) || !("value" in p)) && y(), {
|
|
687
|
+
id: m,
|
|
688
|
+
op: h(p.op),
|
|
689
|
+
benefitKey: h(p.benefitKey),
|
|
690
|
+
quantity: b(p.quantity),
|
|
691
|
+
charged: b(p.charged),
|
|
692
|
+
projectName: h(p.projectName),
|
|
693
|
+
createdAt: h(p.createdAt),
|
|
694
|
+
bizOrderNo: h(p.bizOrderNo),
|
|
695
|
+
value: p.value
|
|
696
|
+
};
|
|
697
|
+
})
|
|
698
|
+
};
|
|
699
|
+
})
|
|
700
|
+
);
|
|
701
|
+
}
|
|
702
|
+
async function nt(e, t = {}) {
|
|
703
|
+
(!e || typeof e != "object") && c("An authorization input is required"), e.operation !== "purchase" && e.operation !== "consume" && c("Invalid authorization operation"), O(e.benefitKey, "benefitKey", 64), O(e.bizOrderNo, "bizOrderNo", 64), C(e.quantity), re(t.baseUrl);
|
|
704
|
+
for (const i of ["title", "buttonText"])
|
|
705
|
+
(typeof e[i] != "string" || e[i].trim() === "") && c(`${i} must be a nonempty string`);
|
|
706
|
+
e.content !== void 0 && typeof e.content != "string" && c("content must be a string");
|
|
707
|
+
const r = {
|
|
708
|
+
operation: e.operation,
|
|
709
|
+
benefitKey: e.benefitKey,
|
|
710
|
+
quantity: e.quantity,
|
|
711
|
+
bizOrderNo: e.bizOrderNo,
|
|
712
|
+
title: e.title,
|
|
713
|
+
buttonText: e.buttonText,
|
|
714
|
+
...e.content !== void 0 ? { content: e.content } : {}
|
|
715
|
+
}, o = await Te(r, t.signal);
|
|
716
|
+
if (!o.ok) return o;
|
|
717
|
+
let n;
|
|
718
|
+
try {
|
|
719
|
+
n = await Ce(
|
|
720
|
+
{ benefitKey: r.benefitKey, bizOrderNo: r.bizOrderNo },
|
|
721
|
+
t
|
|
722
|
+
);
|
|
723
|
+
} catch (i) {
|
|
724
|
+
throw new l(
|
|
725
|
+
i instanceof l ? i.kind : "authorization",
|
|
726
|
+
"Unable to verify App authorization",
|
|
727
|
+
{
|
|
728
|
+
...i instanceof l ? i : {},
|
|
729
|
+
bizOrderNo: r.bizOrderNo,
|
|
730
|
+
authorizationUnknown: !0,
|
|
731
|
+
cause: i
|
|
732
|
+
}
|
|
733
|
+
);
|
|
734
|
+
}
|
|
735
|
+
return n.ok ? Y(n.data, r) ? n : {
|
|
736
|
+
ok: !1,
|
|
737
|
+
reason: "authorization_required",
|
|
738
|
+
data: n.data
|
|
739
|
+
} : n;
|
|
740
|
+
}
|
|
741
|
+
const P = "wallet.showRecharge", _e = 3e5;
|
|
742
|
+
class w extends Error {
|
|
743
|
+
constructor(t, r) {
|
|
744
|
+
super(r), this.type = t, this.name = "WalletRechargeError";
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
const M = /* @__PURE__ */ new WeakMap();
|
|
748
|
+
function oe() {
|
|
749
|
+
if (typeof window > "u" || typeof document < "u" && document.visibilityState === "hidden")
|
|
750
|
+
return;
|
|
751
|
+
const e = window.webkit?.messageHandlers?.aippyListener;
|
|
752
|
+
if (typeof e?.postMessage == "function")
|
|
753
|
+
return { host: window, listener: e };
|
|
754
|
+
}
|
|
755
|
+
function Le(e) {
|
|
756
|
+
e.host.processRechargeResult === e.dispatch && (e.hadPrevious ? e.host.processRechargeResult = e.previous : delete e.host.processRechargeResult), M.delete(e.host);
|
|
757
|
+
}
|
|
758
|
+
function ie(e) {
|
|
759
|
+
const t = {
|
|
760
|
+
host: e,
|
|
761
|
+
previous: e.processRechargeResult,
|
|
762
|
+
hadPrevious: Object.prototype.hasOwnProperty.call(
|
|
763
|
+
e,
|
|
764
|
+
"processRechargeResult"
|
|
765
|
+
),
|
|
766
|
+
dispatch: (r) => {
|
|
767
|
+
const o = r && typeof r == "object" && !Array.isArray(r) ? r : void 0;
|
|
768
|
+
if (o?.status === "success" ? t.succeeded = !0 : o?.status === "closed" && typeof o.purchased == "boolean" ? (Le(t), t.succeeded && !o.purchased ? t.waiter?.reject(
|
|
769
|
+
new w("protocol", "Inconsistent recharge closure")
|
|
770
|
+
) : t.waiter?.resolve(o.purchased)) : (t.quarantined = !0, t.waiter?.reject(
|
|
771
|
+
new w("protocol", "Invalid recharge result")
|
|
772
|
+
)), typeof t.previous == "function")
|
|
773
|
+
try {
|
|
774
|
+
t.previous.call(e, r);
|
|
775
|
+
} catch {
|
|
776
|
+
console.warn("Native recharge observer failed");
|
|
777
|
+
}
|
|
778
|
+
},
|
|
779
|
+
succeeded: !1,
|
|
780
|
+
quarantined: !1
|
|
781
|
+
};
|
|
782
|
+
return e.processRechargeResult = t.dispatch, M.set(e, t), t;
|
|
783
|
+
}
|
|
784
|
+
function xe() {
|
|
785
|
+
let e;
|
|
786
|
+
try {
|
|
787
|
+
if (typeof document < "u" && document.visibilityState === "hidden")
|
|
788
|
+
return;
|
|
789
|
+
const t = oe();
|
|
790
|
+
if (t) {
|
|
791
|
+
if (M.has(t.host)) return;
|
|
792
|
+
e = ie(t.host), t.listener.postMessage({ command: P });
|
|
793
|
+
return;
|
|
794
|
+
}
|
|
795
|
+
const r = D();
|
|
796
|
+
if (!r) return;
|
|
797
|
+
window.parent.postMessage({ type: P }, r);
|
|
798
|
+
} catch {
|
|
799
|
+
e && (e.quarantined = !0), console.warn("Failed to request native recharge");
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
function je(e) {
|
|
803
|
+
return new Promise((t, r) => {
|
|
804
|
+
if (e?.aborted) {
|
|
805
|
+
r(new w("cancelled", "Recharge wait cancelled"));
|
|
806
|
+
return;
|
|
807
|
+
}
|
|
808
|
+
const o = oe();
|
|
809
|
+
if (!o) {
|
|
810
|
+
r(
|
|
811
|
+
new w("unavailable", "Native recharge is unavailable")
|
|
812
|
+
);
|
|
813
|
+
return;
|
|
814
|
+
}
|
|
815
|
+
let n = M.get(o.host);
|
|
816
|
+
if (n?.waiter || n?.quarantined) {
|
|
817
|
+
r(
|
|
818
|
+
new w(
|
|
819
|
+
"busy",
|
|
820
|
+
"Another recharge continuation is active"
|
|
821
|
+
)
|
|
822
|
+
);
|
|
823
|
+
return;
|
|
824
|
+
}
|
|
825
|
+
if (n && o.host.processRechargeResult !== n.dispatch) {
|
|
826
|
+
n.quarantined = !0, r(
|
|
827
|
+
new w(
|
|
828
|
+
"protocol",
|
|
829
|
+
"Native recharge callback was replaced"
|
|
830
|
+
)
|
|
831
|
+
);
|
|
832
|
+
return;
|
|
833
|
+
}
|
|
834
|
+
const i = !n;
|
|
835
|
+
try {
|
|
836
|
+
n ?? (n = ie(o.host));
|
|
837
|
+
} catch {
|
|
838
|
+
r(
|
|
839
|
+
new w(
|
|
840
|
+
"unavailable",
|
|
841
|
+
"Native recharge callback is unavailable"
|
|
842
|
+
)
|
|
843
|
+
);
|
|
844
|
+
return;
|
|
845
|
+
}
|
|
846
|
+
let u = !1;
|
|
847
|
+
const a = (f, g = !1) => {
|
|
848
|
+
f && (n.quarantined = !0), !u && (u = !0, clearTimeout(d), e?.removeEventListener("abort", s), f ? r(f) : t(g));
|
|
849
|
+
}, s = () => a(new w("cancelled", "Recharge wait cancelled")), d = setTimeout(
|
|
850
|
+
() => a(
|
|
851
|
+
new w(
|
|
852
|
+
"timeout",
|
|
853
|
+
"Recharge closure was not received"
|
|
854
|
+
)
|
|
855
|
+
),
|
|
856
|
+
_e
|
|
857
|
+
);
|
|
858
|
+
if (n.waiter = {
|
|
859
|
+
resolve: (f) => a(void 0, f),
|
|
860
|
+
reject: (f) => a(f)
|
|
861
|
+
}, e?.addEventListener("abort", s, { once: !0 }), e?.aborted) {
|
|
862
|
+
s();
|
|
863
|
+
return;
|
|
864
|
+
}
|
|
865
|
+
if (i)
|
|
866
|
+
try {
|
|
867
|
+
o.listener.postMessage({ command: P });
|
|
868
|
+
} catch {
|
|
869
|
+
a(
|
|
870
|
+
new w("bridge", "Native recharge request failed")
|
|
871
|
+
);
|
|
872
|
+
}
|
|
873
|
+
});
|
|
874
|
+
}
|
|
875
|
+
const V = 6e4, ae = 1e3;
|
|
876
|
+
function ot(e) {
|
|
877
|
+
const t = typeof window > "u" ? void 0 : window, r = t?.location?.href, o = B("ministore"), n = o.supported && o.envCheck.type === "new_app";
|
|
878
|
+
let i = null, u = !1;
|
|
879
|
+
const a = () => {
|
|
880
|
+
if (e[T]?.(), !n) return;
|
|
881
|
+
if (typeof window > "u" || window !== t || t?.location?.href !== r)
|
|
882
|
+
throw new DOMException("Purchase page changed", "AbortError");
|
|
883
|
+
if (u && typeof document < "u" && document.visibilityState === "hidden")
|
|
884
|
+
throw new DOMException("Purchase page is not visible", "AbortError");
|
|
885
|
+
const d = be();
|
|
886
|
+
if (!i) i = d;
|
|
887
|
+
else if (d !== i)
|
|
888
|
+
throw new DOMException("Purchase account changed", "AbortError");
|
|
889
|
+
};
|
|
890
|
+
return {
|
|
891
|
+
options: { ...e, [T]: a },
|
|
892
|
+
check: a,
|
|
893
|
+
prepareContinuation: () => {
|
|
894
|
+
u = !0, a();
|
|
895
|
+
},
|
|
896
|
+
available: () => n && !!i && typeof t?.webkit?.messageHandlers?.aippyListener?.postMessage == "function" && !(typeof document < "u" && document.visibilityState === "hidden")
|
|
897
|
+
};
|
|
898
|
+
}
|
|
899
|
+
function se(e, t) {
|
|
900
|
+
return new Promise((r, o) => {
|
|
901
|
+
if (t.aborted) {
|
|
902
|
+
o(t.reason);
|
|
903
|
+
return;
|
|
904
|
+
}
|
|
905
|
+
const n = () => {
|
|
906
|
+
clearTimeout(i), o(t.reason);
|
|
907
|
+
}, i = setTimeout(() => {
|
|
908
|
+
t.removeEventListener("abort", n), r();
|
|
909
|
+
}, e);
|
|
910
|
+
t.addEventListener("abort", n, { once: !0 });
|
|
911
|
+
});
|
|
912
|
+
}
|
|
913
|
+
async function ce(e, t) {
|
|
914
|
+
const r = new AbortController(), o = e.options.signal, n = () => r.abort(o?.reason);
|
|
915
|
+
o?.addEventListener("abort", n, { once: !0 }), o?.aborted && n();
|
|
916
|
+
const i = Date.now() + V;
|
|
917
|
+
let u = !1;
|
|
918
|
+
const a = setTimeout(() => {
|
|
919
|
+
u = !0, r.abort(
|
|
920
|
+
new DOMException("Recharge balance update timed out", "TimeoutError")
|
|
921
|
+
);
|
|
922
|
+
}, V);
|
|
923
|
+
try {
|
|
924
|
+
return await t(
|
|
925
|
+
{ ...e.options, signal: r.signal },
|
|
926
|
+
i
|
|
927
|
+
);
|
|
928
|
+
} catch (s) {
|
|
929
|
+
throw o?.aborted ? new w(
|
|
930
|
+
"cancelled",
|
|
931
|
+
"Recharge continuation cancelled"
|
|
932
|
+
) : u ? new l(
|
|
933
|
+
"recharge",
|
|
934
|
+
"Recharge balance update was not observed",
|
|
935
|
+
{ type: "balance_timeout" }
|
|
936
|
+
) : s;
|
|
937
|
+
} finally {
|
|
938
|
+
clearTimeout(a), o?.removeEventListener("abort", n);
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
async function ue(e, t, r) {
|
|
942
|
+
for (; ; ) {
|
|
943
|
+
e.check();
|
|
944
|
+
let o = ae;
|
|
945
|
+
try {
|
|
946
|
+
const n = await Ke(t);
|
|
947
|
+
return e.check(), n;
|
|
948
|
+
} catch (n) {
|
|
949
|
+
if (!(n instanceof l && (n.kind === "network" || n.kind === "http" && (n.httpStatus === 429 || (n.httpStatus ?? 0) >= 500)))) throw n;
|
|
950
|
+
o = Math.max(o, n.retryAfterMs ?? 0);
|
|
951
|
+
}
|
|
952
|
+
await se(
|
|
953
|
+
Math.min(o, Math.max(0, r - Date.now())),
|
|
954
|
+
t.signal
|
|
955
|
+
);
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
async function He(e, t) {
|
|
959
|
+
await ce(e, async (r, o) => {
|
|
960
|
+
for (; ; ) {
|
|
961
|
+
if (await ue(e, r, o) > t) return;
|
|
962
|
+
await se(
|
|
963
|
+
Math.min(ae, Math.max(0, o - Date.now())),
|
|
964
|
+
r.signal
|
|
965
|
+
);
|
|
966
|
+
}
|
|
967
|
+
});
|
|
968
|
+
}
|
|
969
|
+
async function it(e, t, r, o = !0) {
|
|
970
|
+
const n = await e();
|
|
971
|
+
if (n.ok || n.reason !== "insufficient_balance" || !o)
|
|
972
|
+
return n;
|
|
973
|
+
try {
|
|
974
|
+
if (t.options.signal?.aborted)
|
|
975
|
+
throw new w("cancelled", "Recharge action cancelled");
|
|
976
|
+
if (!t.available()) {
|
|
977
|
+
try {
|
|
978
|
+
$("ministore");
|
|
979
|
+
} catch {
|
|
980
|
+
return n;
|
|
981
|
+
}
|
|
982
|
+
return xe(), n;
|
|
983
|
+
}
|
|
984
|
+
t.check();
|
|
985
|
+
const i = await ce(
|
|
986
|
+
t,
|
|
987
|
+
(a, s) => ue(t, a, s)
|
|
988
|
+
);
|
|
989
|
+
t.check();
|
|
990
|
+
const u = await je(t.options.signal);
|
|
991
|
+
if (t.check(), !u) return n;
|
|
992
|
+
await He(t, i), t.prepareContinuation();
|
|
993
|
+
} catch (i) {
|
|
994
|
+
const u = i instanceof l ? i : {}, a = t.options.signal?.aborted || i instanceof w && i.type === "cancelled" || i instanceof l && i.kind === "abort" || i instanceof Error && i.name === "AbortError";
|
|
995
|
+
throw new l(
|
|
996
|
+
a ? "abort" : "recharge",
|
|
997
|
+
a ? "Recharge continuation cancelled" : "Unable to continue purchase after recharge",
|
|
998
|
+
{
|
|
999
|
+
...u,
|
|
1000
|
+
type: i instanceof w ? i.type : u.type,
|
|
1001
|
+
bizOrderNo: r,
|
|
1002
|
+
settlementUnknown: !1,
|
|
1003
|
+
authorizationUnknown: !1,
|
|
1004
|
+
cause: i
|
|
1005
|
+
}
|
|
1006
|
+
);
|
|
1007
|
+
}
|
|
1008
|
+
return e();
|
|
1009
|
+
}
|
|
1010
|
+
export {
|
|
1011
|
+
l as M,
|
|
1012
|
+
T as R,
|
|
1013
|
+
c as a,
|
|
1014
|
+
Je as b,
|
|
1015
|
+
R as c,
|
|
1016
|
+
I as d,
|
|
1017
|
+
b as e,
|
|
1018
|
+
N as f,
|
|
1019
|
+
ve as g,
|
|
1020
|
+
Xe as h,
|
|
1021
|
+
O as i,
|
|
1022
|
+
h as j,
|
|
1023
|
+
y as k,
|
|
1024
|
+
rt as l,
|
|
1025
|
+
tt as m,
|
|
1026
|
+
et as n,
|
|
1027
|
+
We as o,
|
|
1028
|
+
Qe as p,
|
|
1029
|
+
nt as q,
|
|
1030
|
+
ot as r,
|
|
1031
|
+
Ye as s,
|
|
1032
|
+
Ce as t,
|
|
1033
|
+
Ze as u,
|
|
1034
|
+
Ke as v,
|
|
1035
|
+
it as w
|
|
1036
|
+
};
|