@aippy/runtime 0.4.2-dev.3 → 0.4.2-dev.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/README.md +15 -20
- package/dist/ai/errors.d.ts +1 -1
- package/dist/ai/index.js +15 -17
- package/dist/bridge-D_-7nPNC.js +311 -0
- package/dist/container-message-DmIChz4h.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-BWszI06u.js +346 -0
- package/dist/{hooks-D5lkty5r.js → hooks-Ct9qEjM6.js} +1 -1
- package/dist/index/index.js +36 -37
- 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 +915 -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 +2 -2
- package/dist/wallet-recharge-BqOljLWn.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,915 @@
|
|
|
1
|
+
var de = Object.defineProperty;
|
|
2
|
+
var fe = (e, t, r) => t in e ? de(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
|
|
3
|
+
var w = (e, t, r) => fe(e, typeof t != "symbol" ? t + "" : t, r);
|
|
4
|
+
import { a as le, i as he, r as me, b as be, c as pe } from "../bridge-D_-7nPNC.js";
|
|
5
|
+
import { a as C, r as ye } from "../app-version-checker-Bz7FrEZz.js";
|
|
6
|
+
import { E as x } from "../errors-B3bDbQbD.js";
|
|
7
|
+
import { a as we, s as ze } from "../container-message-DmIChz4h.js";
|
|
8
|
+
import { j as ge } from "../url-c26cuIpu.js";
|
|
9
|
+
import { W as M, s as Oe, w as Ae } from "../wallet-recharge-BqOljLWn.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 B(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 j(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 j(t);
|
|
90
|
+
}
|
|
91
|
+
function T(e) {
|
|
92
|
+
const t = z(e), r = B(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, j);
|
|
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 D(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 H = 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 V() {
|
|
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 $(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 = $(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 F(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 G(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 = $(e), n = b(r.code), o = f(r.msg);
|
|
225
|
+
if (n !== 0)
|
|
226
|
+
throw F(t, {
|
|
227
|
+
reason: "server_error",
|
|
228
|
+
code: n,
|
|
229
|
+
message: o
|
|
230
|
+
});
|
|
231
|
+
const i = v(r.data, D);
|
|
232
|
+
return i.ok ? G(i.data, t) ? i : { ok: !1, reason: "authorization_required", data: i.data } : i;
|
|
233
|
+
}
|
|
234
|
+
function J(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) : F(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 Q(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 = J(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 = V();
|
|
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
|
+
}, H), g = (p) => {
|
|
319
|
+
if (he(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: Q(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 = C("userCredentials");
|
|
366
|
+
return e.envCheck.type === "new_app" && e.supported;
|
|
367
|
+
}
|
|
368
|
+
function Ce(e, t) {
|
|
369
|
+
const r = typeof window > "u" ? void 0 : window.webkit?.messageHandlers?.aippyListener;
|
|
370
|
+
if (typeof r?.postMessage != "function") {
|
|
371
|
+
const i = le();
|
|
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 = ye("userCredentials");
|
|
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 = V();
|
|
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
|
+
}, H);
|
|
422
|
+
try {
|
|
423
|
+
s = Pe(n, o, (m) => {
|
|
424
|
+
if (!a)
|
|
425
|
+
try {
|
|
426
|
+
const O = J(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: Q(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 W = /* @__PURE__ */ Symbol("ministoreScopeCheck");
|
|
478
|
+
function Z(e) {
|
|
479
|
+
let t;
|
|
480
|
+
try {
|
|
481
|
+
t = new URL(e ?? `${me()}/aisdk/v1/`);
|
|
482
|
+
} catch {
|
|
483
|
+
l("baseUrl must be a valid official Aippy API URL");
|
|
484
|
+
}
|
|
485
|
+
return (!be(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 X(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 Y(e) {
|
|
502
|
+
return JSON.parse(X(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 Be(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
|
+
Z(t.baseUrl),
|
|
519
|
+
`ministore/${e}`
|
|
520
|
+
), i = X(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[W]?.(), 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 = Be(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), ue = 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" && !ue, 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 ee(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 te(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, D)
|
|
584
|
+
);
|
|
585
|
+
}
|
|
586
|
+
function je(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
|
+
...B(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), Z(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 Ce(r, t.signal);
|
|
666
|
+
if (!n.ok) return n;
|
|
667
|
+
let o;
|
|
668
|
+
try {
|
|
669
|
+
o = await te(
|
|
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 ? G(o.data, r) ? o : {
|
|
686
|
+
ok: !1,
|
|
687
|
+
reason: "authorization_required",
|
|
688
|
+
data: o.data
|
|
689
|
+
} : o;
|
|
690
|
+
}
|
|
691
|
+
function re(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, oe = 1e3;
|
|
699
|
+
function ne(e) {
|
|
700
|
+
const t = typeof window > "u" ? void 0 : window, r = t?.location?.href, n = C("userCredentials"), 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 = pe();
|
|
709
|
+
if (!i) i = c;
|
|
710
|
+
else if (c !== i)
|
|
711
|
+
throw new DOMException("Purchase account changed", "AbortError");
|
|
712
|
+
};
|
|
713
|
+
return {
|
|
714
|
+
options: { ...e, [W]: 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 ie(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 ae(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 se(e, t, r) {
|
|
765
|
+
for (; ; ) {
|
|
766
|
+
e.check();
|
|
767
|
+
let n = oe;
|
|
768
|
+
try {
|
|
769
|
+
const o = await ee(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 ie(
|
|
776
|
+
Math.min(n, Math.max(0, r - Date.now())),
|
|
777
|
+
t.signal
|
|
778
|
+
);
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
async function $e(e, t) {
|
|
782
|
+
await ae(e, async (r, n) => {
|
|
783
|
+
for (; ; ) {
|
|
784
|
+
if (await se(e, r, n) > t) return;
|
|
785
|
+
await ie(
|
|
786
|
+
Math.min(oe, Math.max(0, n - Date.now())),
|
|
787
|
+
r.signal
|
|
788
|
+
);
|
|
789
|
+
}
|
|
790
|
+
});
|
|
791
|
+
}
|
|
792
|
+
async function ce(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
|
+
return Oe(), o;
|
|
801
|
+
t.check();
|
|
802
|
+
const i = await ae(
|
|
803
|
+
t,
|
|
804
|
+
(a, s) => se(t, a, s)
|
|
805
|
+
);
|
|
806
|
+
t.check();
|
|
807
|
+
const u = await Ae(t.options.signal);
|
|
808
|
+
if (t.check(), !u) return o;
|
|
809
|
+
await $e(t, i), t.prepareContinuation();
|
|
810
|
+
} catch (i) {
|
|
811
|
+
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";
|
|
812
|
+
throw new d(
|
|
813
|
+
a ? "abort" : "recharge",
|
|
814
|
+
a ? "Recharge continuation cancelled" : "Unable to continue purchase after recharge",
|
|
815
|
+
{
|
|
816
|
+
...u,
|
|
817
|
+
type: i instanceof M ? i.type : u.type,
|
|
818
|
+
bizOrderNo: r,
|
|
819
|
+
settlementUnknown: !1,
|
|
820
|
+
authorizationUnknown: !1,
|
|
821
|
+
cause: i
|
|
822
|
+
}
|
|
823
|
+
);
|
|
824
|
+
}
|
|
825
|
+
return e();
|
|
826
|
+
}
|
|
827
|
+
async function Fe(e, t = {}) {
|
|
828
|
+
ke(e);
|
|
829
|
+
const r = re(e.bizOrderNo), n = Y({
|
|
830
|
+
benefitKey: e.benefitKey,
|
|
831
|
+
bizOrderNo: r,
|
|
832
|
+
autoPurchase: e.autoPurchase === !0,
|
|
833
|
+
...e.quantity === void 0 ? {} : { quantity: e.quantity },
|
|
834
|
+
...e.itemIds === void 0 ? {} : { itemIds: e.itemIds }
|
|
835
|
+
}), o = ne(t);
|
|
836
|
+
return ce(
|
|
837
|
+
() => N(
|
|
838
|
+
"benefits/consume",
|
|
839
|
+
o.options,
|
|
840
|
+
{ method: "POST", bizOrderNo: r, body: n },
|
|
841
|
+
(u) => v(u, (a) => ({
|
|
842
|
+
benefit: T(a.benefit),
|
|
843
|
+
charged: b(a.charged),
|
|
844
|
+
idempotentHit: A(a.idempotentHit),
|
|
845
|
+
bizOrderNo: r,
|
|
846
|
+
..."walletBalance" in a ? { walletBalance: b(a.walletBalance, !0) } : {}
|
|
847
|
+
}))
|
|
848
|
+
),
|
|
849
|
+
o,
|
|
850
|
+
r,
|
|
851
|
+
n.autoPurchase && n.itemIds === void 0
|
|
852
|
+
);
|
|
853
|
+
}
|
|
854
|
+
function Ge() {
|
|
855
|
+
return Le();
|
|
856
|
+
}
|
|
857
|
+
async function Je(e, t = {}) {
|
|
858
|
+
Ee(e);
|
|
859
|
+
const r = e.itemValues, n = e.quantity ?? r?.length ?? 1, o = re(e.bizOrderNo), i = Y({
|
|
860
|
+
benefitKey: e.benefitKey,
|
|
861
|
+
quantity: n,
|
|
862
|
+
bizOrderNo: o,
|
|
863
|
+
...r === void 0 ? {} : { itemValues: r }
|
|
864
|
+
}), u = ne(t);
|
|
865
|
+
return ce(() => N(
|
|
866
|
+
"benefits/purchase",
|
|
867
|
+
u.options,
|
|
868
|
+
{
|
|
869
|
+
method: "POST",
|
|
870
|
+
bizOrderNo: o,
|
|
871
|
+
body: i
|
|
872
|
+
},
|
|
873
|
+
(s) => v(s, (c) => ({
|
|
874
|
+
benefit: T(c.benefit),
|
|
875
|
+
charged: b(c.charged),
|
|
876
|
+
idempotentHit: A(c.idempotentHit),
|
|
877
|
+
bizOrderNo: o,
|
|
878
|
+
..."walletBalance" in c ? { walletBalance: b(c.walletBalance, !0) } : {}
|
|
879
|
+
}))
|
|
880
|
+
), u, o);
|
|
881
|
+
}
|
|
882
|
+
async function Qe(e, t = {}) {
|
|
883
|
+
return Me(e), N(
|
|
884
|
+
"benefits/items/update",
|
|
885
|
+
t,
|
|
886
|
+
{
|
|
887
|
+
method: "POST",
|
|
888
|
+
body: {
|
|
889
|
+
benefitKey: e.benefitKey,
|
|
890
|
+
itemId: e.itemId,
|
|
891
|
+
value: e.value
|
|
892
|
+
}
|
|
893
|
+
},
|
|
894
|
+
(r) => v(r, (n) => {
|
|
895
|
+
const o = f(n.reason), i = Ne(n.item);
|
|
896
|
+
return i ? { item: i } : (o === "" && y(), {});
|
|
897
|
+
})
|
|
898
|
+
);
|
|
899
|
+
}
|
|
900
|
+
const ot = {
|
|
901
|
+
getGemBalance: ee,
|
|
902
|
+
getAuthorization: te,
|
|
903
|
+
requestAuthorization: Ve,
|
|
904
|
+
listCatalog: je,
|
|
905
|
+
listBenefits: De,
|
|
906
|
+
isPurchaseSupported: Ge,
|
|
907
|
+
purchase: Je,
|
|
908
|
+
consume: Fe,
|
|
909
|
+
updateItem: Qe,
|
|
910
|
+
listRecords: He
|
|
911
|
+
};
|
|
912
|
+
export {
|
|
913
|
+
d as MinistoreError,
|
|
914
|
+
ot as ministore
|
|
915
|
+
};
|