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