@voltro/plugin-economy 0.0.0-stage → 0.87.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/CHANGELOG.md +24329 -0
- package/LICENSE +61 -0
- package/README.md +2719 -2
- package/SECURITY.md +56 -0
- package/THIRD-PARTY-NOTICES.md +9189 -0
- package/dist/amount.js +21 -0
- package/dist/appleIap.server.js +263 -0
- package/dist/appleIapNotifications.server.js +163 -0
- package/dist/appleIapTrust.server.js +31 -0
- package/dist/bundleValue.server.js +113 -0
- package/dist/canonicalDataJson.js +11 -0
- package/dist/capture.js +54 -0
- package/dist/codePort.fixture.js +124 -0
- package/dist/codeStore.server.js +440 -0
- package/dist/codeTables.entity.js +44 -0
- package/dist/codes.d.ts +150 -0
- package/dist/codes.js +83 -0
- package/dist/components.d.ts +397 -0
- package/dist/components.js +284 -0
- package/dist/consistency.server.js +116 -0
- package/dist/containerStore.server.js +688 -0
- package/dist/containerStore.testFixtures.js +76 -0
- package/dist/containerTables.entity.js +46 -0
- package/dist/containers.d.ts +311 -0
- package/dist/containers.fixture.js +129 -0
- package/dist/containers.js +215 -0
- package/dist/containers.server.js +40 -0
- package/dist/containersPort.fixture.js +75 -0
- package/dist/currency.js +33 -0
- package/dist/declarationFixtures.js +62 -0
- package/dist/economy-app/events/economy.refundReversed.event.ts +1 -0
- package/dist/economy-app/events/economy.refunded.event.ts +1 -0
- package/dist/economyPort.fixture.js +125 -0
- package/dist/errors.d.ts +14 -0
- package/dist/errors.js +22 -0
- package/dist/events.d.ts +46 -0
- package/dist/events.js +1 -0
- package/dist/googleIap.server.js +392 -0
- package/dist/googleIapNotifications.server.js +131 -0
- package/dist/googleIapSubscription.server.js +184 -0
- package/dist/iap.d.ts +309 -0
- package/dist/iap.js +304 -0
- package/dist/iap.testFixtures.js +145 -0
- package/dist/iapAccountTables.entity.js +40 -0
- package/dist/iapAccounts.server.js +201 -0
- package/dist/iapBinding.server.js +524 -0
- package/dist/iapCheckout.server.js +98 -0
- package/dist/iapCompletion.server.js +56 -0
- package/dist/iapCurrentState.server.js +108 -0
- package/dist/iapCurrentState.testFixtures.js +23 -0
- package/dist/iapCurrentStatePort.fixture.js +64 -0
- package/dist/iapEntitlements.d.ts +79 -0
- package/dist/iapEntitlements.js +58 -0
- package/dist/iapEntitlements.server.js +49 -0
- package/dist/iapEntitlementsBinding.server.js +106 -0
- package/dist/iapEntitlementsPort.fixture.js +81 -0
- package/dist/iapInstalledEntitlements.testFixtures.js +76 -0
- package/dist/iapInstalledNotifications.testFixtures.js +94 -0
- package/dist/iapInventoryRefunds.server.js +262 -0
- package/dist/iapNotificationCustodyPort.fixture.js +68 -0
- package/dist/iapNotificationPort.fixture.js +74 -0
- package/dist/iapNotificationProcessor.server.js +135 -0
- package/dist/iapNotificationProcessor.testFixtures.js +64 -0
- package/dist/iapNotificationProcessorPort.fixture.js +56 -0
- package/dist/iapNotificationSchedule.server.js +70 -0
- package/dist/iapNotificationStore.server.js +353 -0
- package/dist/iapNotificationStore.testFixtures.js +32 -0
- package/dist/iapNotificationTables.entity.js +49 -0
- package/dist/iapNotificationTarget.server.js +37 -0
- package/dist/iapNotificationTarget.testFixtures.js +30 -0
- package/dist/iapNotifications.d.ts +644 -0
- package/dist/iapNotifications.js +6 -0
- package/dist/iapNotifications.server.js +96 -0
- package/dist/iapNotificationsBinding.server.js +233 -0
- package/dist/iapNotificationsSystemPort.fixture.js +51 -0
- package/dist/iapPlugin.testFixtures.js +60 -0
- package/dist/iapPort.fixture.js +75 -0
- package/dist/iapProviderCapture.server.js +18 -0
- package/dist/iapRecovery.d.ts +146 -0
- package/dist/iapRecovery.js +90 -0
- package/dist/iapRefundEventDelivery.server.js +83 -0
- package/dist/iapRefundEvents.js +45 -0
- package/dist/iapRefundEventsPort.fixture.js +60 -0
- package/dist/iapRefundPort.fixture.js +55 -0
- package/dist/iapRefundTables.entity.js +56 -0
- package/dist/iapRefunds.d.ts +755 -0
- package/dist/iapRefunds.js +6 -0
- package/dist/iapRefunds.server.js +554 -0
- package/dist/iapRefunds.testFixtures.js +65 -0
- package/dist/iapSpendAdmission.server.js +99 -0
- package/dist/iapStore.server.js +741 -0
- package/dist/iapStore.testFixtures.js +128 -0
- package/dist/iapTables.entity.js +81 -0
- package/dist/iapVerification.server.js +121 -0
- package/dist/index.d.ts +2984 -0
- package/dist/index.js +15 -0
- package/dist/intentionRecovery.js +134 -0
- package/dist/ledger.js +78 -0
- package/dist/loyalty.d.ts +274 -0
- package/dist/loyalty.fixture.js +93 -0
- package/dist/loyalty.js +312 -0
- package/dist/loyaltyBinding.server.js +204 -0
- package/dist/loyaltyPort.fixture.js +87 -0
- package/dist/loyaltyShopSource.server.js +91 -0
- package/dist/loyaltyStore.server.js +553 -0
- package/dist/loyaltyStore.testFixtures.js +83 -0
- package/dist/loyaltyTables.entity.js +50 -0
- package/dist/offerMerchandising.fixture.js +115 -0
- package/dist/offerMerchandising.js +283 -0
- package/dist/offerPolicies.d.ts +441 -0
- package/dist/offerPolicies.fixture.js +54 -0
- package/dist/offerPolicies.js +268 -0
- package/dist/piggyBanks.d.ts +272 -0
- package/dist/piggyBanks.fixture.js +71 -0
- package/dist/piggyBanks.js +201 -0
- package/dist/piggyBinding.server.js +205 -0
- package/dist/piggyPort.fixture.js +73 -0
- package/dist/piggyStore.server.js +611 -0
- package/dist/piggyStore.testFixtures.js +98 -0
- package/dist/piggyTables.entity.js +41 -0
- package/dist/plugin.js +1048 -0
- package/dist/port.js +13 -0
- package/dist/price.d.ts +99 -0
- package/dist/price.js +144 -0
- package/dist/purchaseRecovery.js +56 -0
- package/dist/reports.server.js +115 -0
- package/dist/rpc.d.ts +3201 -0
- package/dist/rpc.js +1201 -0
- package/dist/sanctionsTradeAuthority.server.js +80 -0
- package/dist/server.d.ts +3856 -0
- package/dist/server.js +43 -0
- package/dist/shop.d.ts +279 -0
- package/dist/shop.js +196 -0
- package/dist/shop.testFixtures.js +114 -0
- package/dist/shopPort.fixture.js +72 -0
- package/dist/shopPresentation.js +68 -0
- package/dist/shopStore.server.js +624 -0
- package/dist/shopTables.entity.js +63 -0
- package/dist/shopUiCopy.js +57 -0
- package/dist/spendLimits.d.ts +140 -0
- package/dist/spendLimits.fixture.js +53 -0
- package/dist/spendLimits.js +155 -0
- package/dist/spendLimitsPort.fixture.js +120 -0
- package/dist/subscriptionBinding.server.js +211 -0
- package/dist/subscriptionStore.server.js +643 -0
- package/dist/subscriptionStore.testFixtures.js +72 -0
- package/dist/subscriptionTables.entity.js +37 -0
- package/dist/subscriptions.d.ts +394 -0
- package/dist/subscriptions.fixture.js +97 -0
- package/dist/subscriptions.js +213 -0
- package/dist/subscriptionsPort.fixture.js +76 -0
- package/dist/systemFixtures.js +89 -0
- package/dist/tables.entity.js +83 -0
- package/dist/testing.d.ts +4615 -0
- package/dist/testing.js +29 -0
- package/dist/tradeAuthority.server.js +172 -0
- package/dist/tradeBinding.server.js +201 -0
- package/dist/tradeComponents.js +342 -0
- package/dist/tradeEscrow.server.js +232 -0
- package/dist/tradeEscrow.testFixtures.js +133 -0
- package/dist/tradeExpiry.server.js +43 -0
- package/dist/tradeRecovery.js +48 -0
- package/dist/tradeStore.server.js +750 -0
- package/dist/tradeStore.testFixtures.js +73 -0
- package/dist/tradeTables.entity.js +66 -0
- package/dist/tradeUiCopy.js +79 -0
- package/dist/trades.d.ts +246 -0
- package/dist/trades.fixture.js +103 -0
- package/dist/trades.js +289 -0
- package/dist/tradesPort.fixture.js +94 -0
- package/dist/walletEscrow.js +106 -0
- package/dist/walletEscrow.server.js +376 -0
- package/dist/walletKeys.server.js +5 -0
- package/dist/walletStore.js +571 -0
- package/dist/web.d.ts +2257 -0
- package/dist/web.js +9 -0
- package/package.json +161 -4
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { defaultFlashTriggerPolicy as e, defaultPersonalizedOfferSelector as t, defineFlashOffer as n, definePersonalizedOffers as r, resolveFlashOffer as i, resolvePersonalizedOffers as a } from "./offerMerchandising.js";
|
|
2
|
+
import { Effect as o } from "effect";
|
|
3
|
+
//#region src/offerMerchandising.fixture.ts
|
|
4
|
+
var s = () => {
|
|
5
|
+
let e = [{
|
|
6
|
+
id: "test.gold",
|
|
7
|
+
kind: "soft"
|
|
8
|
+
}], t = r({
|
|
9
|
+
id: "fixture.personalized",
|
|
10
|
+
slots: 1,
|
|
11
|
+
rotationAnchorAt: 0,
|
|
12
|
+
rotationMs: 864e5,
|
|
13
|
+
pool: ["explorer", "arena"].map((e) => ({
|
|
14
|
+
offer: {
|
|
15
|
+
id: "offer." + e,
|
|
16
|
+
titleKey: "test.offer",
|
|
17
|
+
price: {
|
|
18
|
+
kind: "virtual",
|
|
19
|
+
options: [{
|
|
20
|
+
currency: "test.gold",
|
|
21
|
+
amount: "7"
|
|
22
|
+
}]
|
|
23
|
+
},
|
|
24
|
+
items: [{
|
|
25
|
+
itemId: "test." + e,
|
|
26
|
+
qty: 1
|
|
27
|
+
}]
|
|
28
|
+
},
|
|
29
|
+
affinities: [e]
|
|
30
|
+
}))
|
|
31
|
+
}, e);
|
|
32
|
+
return Object.freeze({
|
|
33
|
+
personalized: t,
|
|
34
|
+
currencies: e,
|
|
35
|
+
tenantId: "fixture",
|
|
36
|
+
key: "canonical.a",
|
|
37
|
+
at: 1,
|
|
38
|
+
ownedItemIds: ["test.explorer"],
|
|
39
|
+
playStyles: ["arena"],
|
|
40
|
+
realMoney: !1
|
|
41
|
+
});
|
|
42
|
+
}, c = () => {
|
|
43
|
+
let e = [{
|
|
44
|
+
id: "test.gold",
|
|
45
|
+
kind: "soft"
|
|
46
|
+
}], t = n({
|
|
47
|
+
id: "fixture.flash",
|
|
48
|
+
offer: {
|
|
49
|
+
id: "flash.level",
|
|
50
|
+
titleKey: "test.flash",
|
|
51
|
+
price: {
|
|
52
|
+
kind: "virtual",
|
|
53
|
+
options: [{
|
|
54
|
+
currency: "test.gold",
|
|
55
|
+
amount: "7"
|
|
56
|
+
}]
|
|
57
|
+
},
|
|
58
|
+
items: [{
|
|
59
|
+
itemId: "test.potion",
|
|
60
|
+
qty: 1
|
|
61
|
+
}]
|
|
62
|
+
},
|
|
63
|
+
triggerId: "progression.level",
|
|
64
|
+
durationMs: 1e3
|
|
65
|
+
}, e);
|
|
66
|
+
return Object.freeze({
|
|
67
|
+
flash: t,
|
|
68
|
+
currencies: e,
|
|
69
|
+
tenantId: "fixture",
|
|
70
|
+
ownerId: "a",
|
|
71
|
+
at: 100,
|
|
72
|
+
trigger: {
|
|
73
|
+
tenantId: "fixture",
|
|
74
|
+
ownerId: "a",
|
|
75
|
+
authorityId: "fixture.progression.receipts",
|
|
76
|
+
eventId: "player.level.receipt",
|
|
77
|
+
triggerId: "progression.level",
|
|
78
|
+
acceptedAt: 0
|
|
79
|
+
},
|
|
80
|
+
realMoney: !1
|
|
81
|
+
});
|
|
82
|
+
}, l = s(), u = c(), d = Object.freeze({
|
|
83
|
+
kind: "slot",
|
|
84
|
+
defaultImplementation: t,
|
|
85
|
+
defaultProbe: {
|
|
86
|
+
run: () => o.sync(() => a(l)?.offers.map((e) => e.id)),
|
|
87
|
+
expected: ["offer.arena"]
|
|
88
|
+
},
|
|
89
|
+
overrideProbe: {
|
|
90
|
+
run: () => o.sync(() => a({
|
|
91
|
+
...l,
|
|
92
|
+
rulesVersion: "test.choose.v1"
|
|
93
|
+
}, () => ["offer.explorer"])?.offers.map((e) => e.id)),
|
|
94
|
+
expected: ["offer.explorer"]
|
|
95
|
+
}
|
|
96
|
+
}), f = Object.freeze({
|
|
97
|
+
kind: "slot",
|
|
98
|
+
defaultImplementation: e,
|
|
99
|
+
defaultProbe: {
|
|
100
|
+
run: () => o.sync(() => i(u)?.until),
|
|
101
|
+
expected: 1e3
|
|
102
|
+
},
|
|
103
|
+
overrideProbe: {
|
|
104
|
+
run: () => o.sync(() => i({
|
|
105
|
+
...u,
|
|
106
|
+
rulesVersion: "test.short.v1"
|
|
107
|
+
}, () => ({
|
|
108
|
+
from: 0,
|
|
109
|
+
until: 500
|
|
110
|
+
}))?.until),
|
|
111
|
+
expected: 500
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
//#endregion
|
|
115
|
+
export { c as flashOfferFixture, f as flashTriggerSystemFixture, s as personalizedOfferFixture, d as personalizedSelectorSystemFixture };
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import { economyError as e } from "./errors.js";
|
|
2
|
+
import { dataList as t, dataObject as n, identifier as r } from "./capture.js";
|
|
3
|
+
import { captureCurrencies as i } from "./currency.js";
|
|
4
|
+
import { priceResolverContext as a, resolvePrice as o } from "./price.js";
|
|
5
|
+
import { defineShopOffer as s, shopInteger as c } from "./shop.js";
|
|
6
|
+
//#region src/offerMerchandising.ts
|
|
7
|
+
var l = (e, t) => e < t ? -1 : +(e > t), u = (n, i) => {
|
|
8
|
+
let a = t(n, i).map((e) => r(e));
|
|
9
|
+
if (new Set(a).size !== a.length) throw e("invalid_input");
|
|
10
|
+
return Object.freeze(a);
|
|
11
|
+
}, d = (...e) => {
|
|
12
|
+
let t = 2166136261;
|
|
13
|
+
for (let n of new TextEncoder().encode(JSON.stringify(e))) t = Math.imul(t ^ n, 16777619) >>> 0;
|
|
14
|
+
return t;
|
|
15
|
+
}, f = (i, a, o = !1) => {
|
|
16
|
+
let d = n(i, [
|
|
17
|
+
"id",
|
|
18
|
+
"version",
|
|
19
|
+
"slots",
|
|
20
|
+
"rotationMs",
|
|
21
|
+
"rotationAnchorAt",
|
|
22
|
+
"pool"
|
|
23
|
+
]), f = Object.freeze(t(d.pool, 128).map((e) => {
|
|
24
|
+
let t = n(e, ["offer", "affinities"]);
|
|
25
|
+
return Object.freeze({
|
|
26
|
+
offer: s(t.offer, a, o),
|
|
27
|
+
affinities: u(t.affinities ?? [], 128)
|
|
28
|
+
});
|
|
29
|
+
}).sort((e, t) => l(e.offer.id, t.offer.id)));
|
|
30
|
+
if (!f.length || new Set(f.map((e) => e.offer.id)).size !== f.length) throw e("invalid_input");
|
|
31
|
+
return Object.freeze({
|
|
32
|
+
id: r(d.id),
|
|
33
|
+
version: r(d.version ?? "1"),
|
|
34
|
+
slots: c(d.slots, 1, Math.min(32, f.length)),
|
|
35
|
+
rotationMs: c(d.rotationMs, 1, 316224e5),
|
|
36
|
+
rotationAnchorAt: c(d.rotationAnchorAt, 0, 864e13),
|
|
37
|
+
pool: f
|
|
38
|
+
});
|
|
39
|
+
}, p = (e) => {
|
|
40
|
+
let t = new Set(e.ownedItemIds), n = new Set(e.playStyles);
|
|
41
|
+
return e.personalized.pool.map((r) => ({
|
|
42
|
+
id: r.offer.id,
|
|
43
|
+
score: r.offer.items.filter((e) => !t.has(e.itemId)).length + 2 * r.affinities.filter((e) => n.has(e)).length,
|
|
44
|
+
tie: d(e.tenantId, e.key, e.personalized.id, e.personalized.version, String(e.rotation), r.offer.id)
|
|
45
|
+
})).sort((e, t) => t.score - e.score || e.tie - t.tie || l(e.id, t.id)).slice(0, e.personalized.slots).map((e) => e.id);
|
|
46
|
+
}, m = (t, a = p) => {
|
|
47
|
+
let o = n(t, [
|
|
48
|
+
"personalized",
|
|
49
|
+
"currencies",
|
|
50
|
+
"realMoney",
|
|
51
|
+
"tenantId",
|
|
52
|
+
"key",
|
|
53
|
+
"at",
|
|
54
|
+
"ownedItemIds",
|
|
55
|
+
"playStyles",
|
|
56
|
+
"rulesVersion"
|
|
57
|
+
]), s = i(o.currencies), l = o.realMoney ?? !1;
|
|
58
|
+
if (typeof l != "boolean" || typeof a != "function") throw e("invalid_input");
|
|
59
|
+
let d = f(o.personalized, s, l), m = c(o.at, 0, 864e13), h = Object.freeze({
|
|
60
|
+
personalized: d,
|
|
61
|
+
currencies: s,
|
|
62
|
+
realMoney: l,
|
|
63
|
+
tenantId: r(o.tenantId),
|
|
64
|
+
key: r(o.key),
|
|
65
|
+
at: m,
|
|
66
|
+
ownedItemIds: u(o.ownedItemIds, 1e4),
|
|
67
|
+
playStyles: u(o.playStyles, 128),
|
|
68
|
+
rulesVersion: r(o.rulesVersion ?? "default.v1"),
|
|
69
|
+
rotation: Math.floor((m - d.rotationAnchorAt) / d.rotationMs)
|
|
70
|
+
});
|
|
71
|
+
if (a !== p && h.rulesVersion === "default.v1") throw e("invalid_input");
|
|
72
|
+
if (m < d.rotationAnchorAt) return null;
|
|
73
|
+
let g = d.rotationAnchorAt + h.rotation * d.rotationMs, _ = Math.min(g + d.rotationMs, 864e13);
|
|
74
|
+
if (g >= _) return null;
|
|
75
|
+
let v = u(a(h), d.slots).map((t) => {
|
|
76
|
+
let n = d.pool.find((e) => e.offer.id === t);
|
|
77
|
+
if (!n) throw e("invalid_input");
|
|
78
|
+
return n.offer;
|
|
79
|
+
});
|
|
80
|
+
return Object.freeze({
|
|
81
|
+
id: d.id,
|
|
82
|
+
version: d.version,
|
|
83
|
+
rotation: h.rotation,
|
|
84
|
+
from: g,
|
|
85
|
+
until: _,
|
|
86
|
+
offers: Object.freeze(v)
|
|
87
|
+
});
|
|
88
|
+
}, h = (t, i, a = !1) => {
|
|
89
|
+
let o = n(t, [
|
|
90
|
+
"id",
|
|
91
|
+
"version",
|
|
92
|
+
"offer",
|
|
93
|
+
"triggerId",
|
|
94
|
+
"durationMs"
|
|
95
|
+
]), l = s(o.offer, i, a);
|
|
96
|
+
if (l.maxQuantity !== 1 || l.limits.perPlayer !== null && l.limits.perPlayer !== 1) throw e("invalid_input");
|
|
97
|
+
let u = s({
|
|
98
|
+
...l,
|
|
99
|
+
oneTime: !0,
|
|
100
|
+
limits: {
|
|
101
|
+
...l.limits,
|
|
102
|
+
perPlayer: 1
|
|
103
|
+
}
|
|
104
|
+
}, i, a);
|
|
105
|
+
return Object.freeze({
|
|
106
|
+
id: r(o.id),
|
|
107
|
+
version: r(o.version ?? "1"),
|
|
108
|
+
offer: u,
|
|
109
|
+
triggerId: r(o.triggerId),
|
|
110
|
+
durationMs: c(o.durationMs, 1, 316224e5)
|
|
111
|
+
});
|
|
112
|
+
}, g = (e) => {
|
|
113
|
+
let t = n(e, [
|
|
114
|
+
"tenantId",
|
|
115
|
+
"ownerId",
|
|
116
|
+
"authorityId",
|
|
117
|
+
"eventId",
|
|
118
|
+
"triggerId",
|
|
119
|
+
"acceptedAt"
|
|
120
|
+
]);
|
|
121
|
+
return Object.freeze({
|
|
122
|
+
tenantId: r(t.tenantId),
|
|
123
|
+
ownerId: r(t.ownerId),
|
|
124
|
+
authorityId: r(t.authorityId),
|
|
125
|
+
eventId: r(t.eventId),
|
|
126
|
+
triggerId: r(t.triggerId),
|
|
127
|
+
acceptedAt: c(t.acceptedAt, 0, 864e13)
|
|
128
|
+
});
|
|
129
|
+
}, _ = ({ flash: e, trigger: t }) => {
|
|
130
|
+
if (!t) return null;
|
|
131
|
+
let n = Math.max(t.acceptedAt, e.offer.from ?? 0), r = Math.min(t.acceptedAt + e.durationMs, e.offer.until ?? 864e13, 864e13);
|
|
132
|
+
return n < r ? Object.freeze({
|
|
133
|
+
from: n,
|
|
134
|
+
until: r
|
|
135
|
+
}) : null;
|
|
136
|
+
}, v = (t, a = _) => {
|
|
137
|
+
let o = n(t, [
|
|
138
|
+
"flash",
|
|
139
|
+
"currencies",
|
|
140
|
+
"realMoney",
|
|
141
|
+
"tenantId",
|
|
142
|
+
"ownerId",
|
|
143
|
+
"at",
|
|
144
|
+
"trigger",
|
|
145
|
+
"rulesVersion"
|
|
146
|
+
]), s = i(o.currencies), l = o.realMoney ?? !1;
|
|
147
|
+
if (typeof l != "boolean" || typeof a != "function") throw e("invalid_input");
|
|
148
|
+
let u = h(o.flash, s, l), d = r(o.tenantId), f = r(o.ownerId), p = c(o.at, 0, 864e13), m = o.trigger === null ? null : g(o.trigger), v = r(o.rulesVersion ?? "default.v1");
|
|
149
|
+
if (a !== _ && v === "default.v1") throw e("invalid_input");
|
|
150
|
+
if (m && (m.tenantId !== d || m.ownerId !== f || m.triggerId !== u.triggerId || m.acceptedAt > p)) throw e("invalid_record");
|
|
151
|
+
let y = Object.freeze({
|
|
152
|
+
flash: u,
|
|
153
|
+
currencies: s,
|
|
154
|
+
realMoney: l,
|
|
155
|
+
tenantId: d,
|
|
156
|
+
ownerId: f,
|
|
157
|
+
at: p,
|
|
158
|
+
trigger: m,
|
|
159
|
+
rulesVersion: v
|
|
160
|
+
}), b = _(y);
|
|
161
|
+
if (!b) return null;
|
|
162
|
+
let x = a(y);
|
|
163
|
+
if (x === null) return null;
|
|
164
|
+
let S = n(x, ["from", "until"]), C = c(S.from, b.from, b.until), w = c(S.until, C + 1, b.until);
|
|
165
|
+
return p < C || p >= w ? null : Object.freeze({
|
|
166
|
+
id: u.id,
|
|
167
|
+
version: u.version,
|
|
168
|
+
offer: u.offer,
|
|
169
|
+
trigger: m,
|
|
170
|
+
from: C,
|
|
171
|
+
until: w
|
|
172
|
+
});
|
|
173
|
+
}, y = (r, i, a = !1) => {
|
|
174
|
+
let o = n(r, [
|
|
175
|
+
"offer",
|
|
176
|
+
"parts",
|
|
177
|
+
"showValue"
|
|
178
|
+
]), u = s(o.offer, i, a);
|
|
179
|
+
if (o.showValue !== "sumOfParts") throw e("invalid_input");
|
|
180
|
+
let d = Object.freeze(t(o.parts, 32).map((e) => {
|
|
181
|
+
let t = n(e, ["offer", "qty"]);
|
|
182
|
+
return Object.freeze({
|
|
183
|
+
offer: s(t.offer, i, a),
|
|
184
|
+
qty: c(t.qty, 1, 1e3)
|
|
185
|
+
});
|
|
186
|
+
}).sort((e, t) => l(e.offer.id, t.offer.id)));
|
|
187
|
+
if (!d.length || d.some((e) => e.offer.id === u.id) || new Set(d.map((e) => e.offer.id)).size !== d.length) throw e("invalid_input");
|
|
188
|
+
let f = /* @__PURE__ */ new Map(), p = /* @__PURE__ */ new Map();
|
|
189
|
+
for (let e of d) {
|
|
190
|
+
for (let t of e.offer.items) f.set(t.itemId, (f.get(t.itemId) ?? 0n) + BigInt(t.qty) * BigInt(e.qty));
|
|
191
|
+
for (let t of e.offer.currencies) p.set(t.currency, (p.get(t.currency) ?? 0n) + BigInt(t.amount) * BigInt(e.qty));
|
|
192
|
+
}
|
|
193
|
+
if (f.size !== u.items.length || p.size !== u.currencies.length || u.items.some((e) => f.get(e.itemId) !== BigInt(e.qty)) || u.currencies.some((e) => p.get(e.currency) !== BigInt(e.amount))) throw e("invalid_input");
|
|
194
|
+
return Object.freeze({
|
|
195
|
+
offer: u,
|
|
196
|
+
parts: d,
|
|
197
|
+
showValue: "sumOfParts"
|
|
198
|
+
});
|
|
199
|
+
}, b = (s) => {
|
|
200
|
+
let l = n(s, [
|
|
201
|
+
"bundle",
|
|
202
|
+
"currencies",
|
|
203
|
+
"realMoney",
|
|
204
|
+
"at",
|
|
205
|
+
"maxPriceAgeMs",
|
|
206
|
+
"prices",
|
|
207
|
+
"bundlePrice"
|
|
208
|
+
]), u = i(l.currencies), d = l.realMoney ?? !1;
|
|
209
|
+
if (typeof d != "boolean") throw e("invalid_input");
|
|
210
|
+
let f = y(l.bundle, u, d), p = c(l.at, 0, 864e13), m = c(l.maxPriceAgeMs, 0, 316224e5), h = o(a(f.offer.price, u, d), () => l.bundlePrice), g = t(l.prices, 32).map((t) => {
|
|
211
|
+
let i = n(t, [
|
|
212
|
+
"offerId",
|
|
213
|
+
"offerVersion",
|
|
214
|
+
"referenceId",
|
|
215
|
+
"observedAt",
|
|
216
|
+
"price"
|
|
217
|
+
]), s = r(i.offerId), l = f.parts.find((e) => e.offer.id === s), h = c(i.observedAt, 0, p);
|
|
218
|
+
if (!l || i.offerVersion !== l.offer.version || p - h > m) throw e("invalid_record");
|
|
219
|
+
return Object.freeze({
|
|
220
|
+
offerId: s,
|
|
221
|
+
offerVersion: l.offer.version,
|
|
222
|
+
referenceId: r(i.referenceId),
|
|
223
|
+
observedAt: h,
|
|
224
|
+
price: o(a(l.offer.price, u, d), () => i.price),
|
|
225
|
+
qty: l.qty
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
if (g.length !== f.parts.length || new Set(g.map((e) => e.offerId)).size !== g.length) throw e("invalid_record");
|
|
229
|
+
let _ = (e) => e.kind === "virtual" ? e.options : e.kind === "mixed" ? e.virtual : [], v = (e) => e.kind === "real" ? e.prices : e.kind === "mixed" ? e.real.prices : null, b = [];
|
|
230
|
+
for (let e of _(h)) {
|
|
231
|
+
let t = 0n, n = !0;
|
|
232
|
+
for (let r of g) {
|
|
233
|
+
if (r.price.kind === "free") continue;
|
|
234
|
+
let i = _(r.price).find((t) => t.currency === e.currency);
|
|
235
|
+
if (!i) {
|
|
236
|
+
n = !1;
|
|
237
|
+
break;
|
|
238
|
+
}
|
|
239
|
+
t += BigInt(i.amount) * BigInt(r.qty);
|
|
240
|
+
}
|
|
241
|
+
n && b.push(Object.freeze({
|
|
242
|
+
kind: "virtual",
|
|
243
|
+
currency: e.currency,
|
|
244
|
+
partsValue: t.toString(),
|
|
245
|
+
bundleAmount: e.amount,
|
|
246
|
+
saving: (t - BigInt(e.amount)).toString()
|
|
247
|
+
}));
|
|
248
|
+
}
|
|
249
|
+
for (let [e, t] of Object.entries(v(h) ?? {})) {
|
|
250
|
+
let n = 0n, r = !0;
|
|
251
|
+
for (let t of g) {
|
|
252
|
+
if (t.price.kind === "free") continue;
|
|
253
|
+
let i = v(t.price)?.[e];
|
|
254
|
+
if (i === void 0) {
|
|
255
|
+
r = !1;
|
|
256
|
+
break;
|
|
257
|
+
}
|
|
258
|
+
n += BigInt(i) * BigInt(t.qty);
|
|
259
|
+
}
|
|
260
|
+
r && b.push(Object.freeze({
|
|
261
|
+
kind: "real",
|
|
262
|
+
currency: e,
|
|
263
|
+
partsValue: n.toString(),
|
|
264
|
+
bundleAmount: String(t),
|
|
265
|
+
saving: (n - BigInt(t)).toString()
|
|
266
|
+
}));
|
|
267
|
+
}
|
|
268
|
+
return Object.freeze({
|
|
269
|
+
offerId: f.offer.id,
|
|
270
|
+
offerVersion: f.offer.version,
|
|
271
|
+
comparison: "sumOfParts",
|
|
272
|
+
capturedAt: p,
|
|
273
|
+
sources: Object.freeze(g.map(({ offerId: e, offerVersion: t, referenceId: n, observedAt: r }) => Object.freeze({
|
|
274
|
+
offerId: e,
|
|
275
|
+
offerVersion: t,
|
|
276
|
+
referenceId: n,
|
|
277
|
+
observedAt: r
|
|
278
|
+
}))),
|
|
279
|
+
comparisons: Object.freeze(b)
|
|
280
|
+
});
|
|
281
|
+
};
|
|
282
|
+
//#endregion
|
|
283
|
+
export { g as captureFlashTriggerReceipt, _ as defaultFlashTriggerPolicy, p as defaultPersonalizedOfferSelector, y as defineBundle, h as defineFlashOffer, f as definePersonalizedOffers, b as projectBundleValue, v as resolveFlashOffer, m as resolvePersonalizedOffers };
|