@voltro/plugin-economy 0.0.0-stage → 0.88.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 +24492 -0
- package/LICENSE +61 -0
- package/README.md +2719 -2
- package/SECURITY.md +56 -0
- package/THIRD-PARTY-NOTICES.md +9841 -0
- package/dist/amount.js +20 -0
- package/dist/appleIap.server.js +262 -0
- package/dist/appleIapNotifications.server.js +162 -0
- package/dist/appleIapTrust.server.js +30 -0
- package/dist/bundleValue.server.js +112 -0
- package/dist/canonicalDataJson.js +10 -0
- package/dist/capture.js +53 -0
- package/dist/codePort.fixture.js +123 -0
- package/dist/codeStore.server.js +439 -0
- package/dist/codeTables.entity.js +43 -0
- package/dist/codes.d.ts +150 -0
- package/dist/codes.js +82 -0
- package/dist/components.d.ts +397 -0
- package/dist/components.js +283 -0
- package/dist/consistency.server.js +115 -0
- package/dist/containerStore.server.js +687 -0
- package/dist/containerStore.testFixtures.js +75 -0
- package/dist/containerTables.entity.js +45 -0
- package/dist/containers.d.ts +311 -0
- package/dist/containers.fixture.js +128 -0
- package/dist/containers.js +214 -0
- package/dist/containers.server.js +39 -0
- package/dist/containersPort.fixture.js +74 -0
- package/dist/currency.js +32 -0
- package/dist/declarationFixtures.js +61 -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 +124 -0
- package/dist/errors.d.ts +14 -0
- package/dist/errors.js +21 -0
- package/dist/events.d.ts +46 -0
- package/dist/events.js +1 -0
- package/dist/googleIap.server.js +391 -0
- package/dist/googleIapNotifications.server.js +130 -0
- package/dist/googleIapSubscription.server.js +183 -0
- package/dist/iap.d.ts +309 -0
- package/dist/iap.js +303 -0
- package/dist/iap.testFixtures.js +144 -0
- package/dist/iapAccountTables.entity.js +39 -0
- package/dist/iapAccounts.server.js +200 -0
- package/dist/iapBinding.server.js +523 -0
- package/dist/iapCheckout.server.js +97 -0
- package/dist/iapCompletion.server.js +55 -0
- package/dist/iapCurrentState.server.js +107 -0
- package/dist/iapCurrentState.testFixtures.js +22 -0
- package/dist/iapCurrentStatePort.fixture.js +63 -0
- package/dist/iapEntitlements.d.ts +79 -0
- package/dist/iapEntitlements.js +57 -0
- package/dist/iapEntitlements.server.js +48 -0
- package/dist/iapEntitlementsBinding.server.js +105 -0
- package/dist/iapEntitlementsPort.fixture.js +80 -0
- package/dist/iapInstalledEntitlements.testFixtures.js +75 -0
- package/dist/iapInstalledNotifications.testFixtures.js +93 -0
- package/dist/iapInventoryRefunds.server.js +261 -0
- package/dist/iapNotificationCustodyPort.fixture.js +67 -0
- package/dist/iapNotificationPort.fixture.js +73 -0
- package/dist/iapNotificationProcessor.server.js +134 -0
- package/dist/iapNotificationProcessor.testFixtures.js +63 -0
- package/dist/iapNotificationProcessorPort.fixture.js +55 -0
- package/dist/iapNotificationSchedule.server.js +69 -0
- package/dist/iapNotificationStore.server.js +352 -0
- package/dist/iapNotificationStore.testFixtures.js +31 -0
- package/dist/iapNotificationTables.entity.js +48 -0
- package/dist/iapNotificationTarget.server.js +36 -0
- package/dist/iapNotificationTarget.testFixtures.js +29 -0
- package/dist/iapNotifications.d.ts +644 -0
- package/dist/iapNotifications.js +6 -0
- package/dist/iapNotifications.server.js +95 -0
- package/dist/iapNotificationsBinding.server.js +232 -0
- package/dist/iapNotificationsSystemPort.fixture.js +50 -0
- package/dist/iapPlugin.testFixtures.js +59 -0
- package/dist/iapPort.fixture.js +74 -0
- package/dist/iapProviderCapture.server.js +17 -0
- package/dist/iapRecovery.d.ts +146 -0
- package/dist/iapRecovery.js +89 -0
- package/dist/iapRefundEventDelivery.server.js +82 -0
- package/dist/iapRefundEvents.js +44 -0
- package/dist/iapRefundEventsPort.fixture.js +59 -0
- package/dist/iapRefundPort.fixture.js +54 -0
- package/dist/iapRefundTables.entity.js +55 -0
- package/dist/iapRefunds.d.ts +755 -0
- package/dist/iapRefunds.js +6 -0
- package/dist/iapRefunds.server.js +553 -0
- package/dist/iapRefunds.testFixtures.js +64 -0
- package/dist/iapSpendAdmission.server.js +98 -0
- package/dist/iapStore.server.js +740 -0
- package/dist/iapStore.testFixtures.js +127 -0
- package/dist/iapTables.entity.js +80 -0
- package/dist/iapVerification.server.js +120 -0
- package/dist/index.d.ts +2984 -0
- package/dist/index.js +15 -0
- package/dist/intentionRecovery.js +133 -0
- package/dist/ledger.js +77 -0
- package/dist/loyalty.d.ts +274 -0
- package/dist/loyalty.fixture.js +92 -0
- package/dist/loyalty.js +311 -0
- package/dist/loyaltyBinding.server.js +203 -0
- package/dist/loyaltyPort.fixture.js +86 -0
- package/dist/loyaltyShopSource.server.js +90 -0
- package/dist/loyaltyStore.server.js +552 -0
- package/dist/loyaltyStore.testFixtures.js +82 -0
- package/dist/loyaltyTables.entity.js +49 -0
- package/dist/offerMerchandising.fixture.js +114 -0
- package/dist/offerMerchandising.js +282 -0
- package/dist/offerPolicies.d.ts +441 -0
- package/dist/offerPolicies.fixture.js +53 -0
- package/dist/offerPolicies.js +267 -0
- package/dist/piggyBanks.d.ts +272 -0
- package/dist/piggyBanks.fixture.js +70 -0
- package/dist/piggyBanks.js +200 -0
- package/dist/piggyBinding.server.js +204 -0
- package/dist/piggyPort.fixture.js +72 -0
- package/dist/piggyStore.server.js +610 -0
- package/dist/piggyStore.testFixtures.js +97 -0
- package/dist/piggyTables.entity.js +40 -0
- package/dist/plugin.js +1047 -0
- package/dist/port.js +12 -0
- package/dist/price.d.ts +99 -0
- package/dist/price.js +143 -0
- package/dist/purchaseRecovery.js +55 -0
- package/dist/reports.server.js +114 -0
- package/dist/rpc.d.ts +3201 -0
- package/dist/rpc.js +1200 -0
- package/dist/sanctionsTradeAuthority.server.js +79 -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 +195 -0
- package/dist/shop.testFixtures.js +113 -0
- package/dist/shopPort.fixture.js +71 -0
- package/dist/shopPresentation.js +67 -0
- package/dist/shopStore.server.js +623 -0
- package/dist/shopTables.entity.js +62 -0
- package/dist/shopUiCopy.js +56 -0
- package/dist/spendLimits.d.ts +140 -0
- package/dist/spendLimits.fixture.js +52 -0
- package/dist/spendLimits.js +154 -0
- package/dist/spendLimitsPort.fixture.js +119 -0
- package/dist/subscriptionBinding.server.js +210 -0
- package/dist/subscriptionStore.server.js +642 -0
- package/dist/subscriptionStore.testFixtures.js +71 -0
- package/dist/subscriptionTables.entity.js +36 -0
- package/dist/subscriptions.d.ts +394 -0
- package/dist/subscriptions.fixture.js +96 -0
- package/dist/subscriptions.js +212 -0
- package/dist/subscriptionsPort.fixture.js +75 -0
- package/dist/systemFixtures.js +88 -0
- package/dist/tables.entity.js +82 -0
- package/dist/testing.d.ts +4615 -0
- package/dist/testing.js +29 -0
- package/dist/tradeAuthority.server.js +171 -0
- package/dist/tradeBinding.server.js +200 -0
- package/dist/tradeComponents.js +341 -0
- package/dist/tradeEscrow.server.js +231 -0
- package/dist/tradeEscrow.testFixtures.js +132 -0
- package/dist/tradeExpiry.server.js +42 -0
- package/dist/tradeRecovery.js +47 -0
- package/dist/tradeStore.server.js +749 -0
- package/dist/tradeStore.testFixtures.js +72 -0
- package/dist/tradeTables.entity.js +65 -0
- package/dist/tradeUiCopy.js +78 -0
- package/dist/trades.d.ts +246 -0
- package/dist/trades.fixture.js +102 -0
- package/dist/trades.js +288 -0
- package/dist/tradesPort.fixture.js +93 -0
- package/dist/walletEscrow.js +105 -0
- package/dist/walletEscrow.server.js +375 -0
- package/dist/walletKeys.server.js +4 -0
- package/dist/walletStore.js +570 -0
- package/dist/web.d.ts +2257 -0
- package/dist/web.js +8 -0
- package/package.json +161 -4
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { EconomyError as e, economyError as t } from "./errors.js";
|
|
2
|
+
import { dataObject as n, identifier as r } from "./capture.js";
|
|
3
|
+
import { shopInteger as i } from "./shop.js";
|
|
4
|
+
import { captureIapOrderReceipt as a } from "./iap.js";
|
|
5
|
+
import { iapOrdersTable as o } from "./iapTables.entity.js";
|
|
6
|
+
import { Effect as s } from "effect";
|
|
7
|
+
import { and as c, eq as l } from "@voltro/database";
|
|
8
|
+
import { prepareSqlMutation as u } from "@voltro/database/sql";
|
|
9
|
+
// src/iapSpendAdmission.server.ts
|
|
10
|
+
var d = (e, t) => BigInt(e.units) * 10n ** BigInt(t - e.scale), f = (e) => new Intl.NumberFormat("en", {
|
|
11
|
+
style: "currency",
|
|
12
|
+
currency: e
|
|
13
|
+
}).resolvedOptions().maximumFractionDigits ?? 2, p = (e) => {
|
|
14
|
+
let t = new Date(e);
|
|
15
|
+
return [Date.UTC(t.getUTCFullYear(), t.getUTCMonth(), 1), Date.UTC(t.getUTCFullYear(), t.getUTCMonth() + 1, 1)];
|
|
16
|
+
}, m = (m, h) => {
|
|
17
|
+
let g = n(h, [
|
|
18
|
+
"namespace",
|
|
19
|
+
"monthlyLimits",
|
|
20
|
+
"eligible",
|
|
21
|
+
"maxOrdersPerMonth"
|
|
22
|
+
]), _ = r(g.namespace), v = i(g.maxOrdersPerMonth ?? 1e3, 1, 1e5);
|
|
23
|
+
if (typeof g.eligible != "function") throw t("invalid_input");
|
|
24
|
+
let y = g.eligible, b = n(g.monthlyLimits, Object.keys(g.monthlyLimits)), x = /* @__PURE__ */ new Map();
|
|
25
|
+
for (let [e, r] of Object.entries(b)) {
|
|
26
|
+
if (!/^[A-Z]{3}$/.test(e)) throw t("invalid_input");
|
|
27
|
+
let a = n(r, ["units", "scale"]);
|
|
28
|
+
if (typeof a.units != "string" || !/^(0|[1-9]\d{0,30})$/.test(a.units)) throw t("invalid_input");
|
|
29
|
+
x.set(e, Object.freeze({
|
|
30
|
+
units: a.units,
|
|
31
|
+
scale: i(a.scale, 0, 9)
|
|
32
|
+
}));
|
|
33
|
+
}
|
|
34
|
+
if (x.size === 0) throw t("invalid_input");
|
|
35
|
+
let S = async (e, n, r, i, s) => {
|
|
36
|
+
let [u, f] = p(r), m = await e.query({
|
|
37
|
+
table: o.tableName,
|
|
38
|
+
predicate: c(l("namespace", _), l("tenantId", n.tenantId), l("ownerId", n.ownerId), l("state", "fulfilled")),
|
|
39
|
+
order: [],
|
|
40
|
+
take: v + 1,
|
|
41
|
+
skip: void 0,
|
|
42
|
+
projection: ["receipt", "fulfilledAt"]
|
|
43
|
+
});
|
|
44
|
+
if (m.length > v) throw t("limit_exceeded");
|
|
45
|
+
let h = 0n;
|
|
46
|
+
for (let e of m) {
|
|
47
|
+
let t = e.fulfilledAt instanceof Date ? e.fulfilledAt.getTime() : typeof e.fulfilledAt == "string" ? Date.parse(e.fulfilledAt) : NaN;
|
|
48
|
+
if (!(t >= u && t < f)) continue;
|
|
49
|
+
let n = a(e.receipt).pricePaid;
|
|
50
|
+
n?.currency === i && (h += d(n, Math.max(s, n.scale)) / 10n ** BigInt(Math.max(s, n.scale) - s));
|
|
51
|
+
}
|
|
52
|
+
return h;
|
|
53
|
+
}, C = async (e, t, n) => n.kind !== "subscription" || n.originalTransactionId === null ? !1 : (await e.query({
|
|
54
|
+
table: o.tableName,
|
|
55
|
+
predicate: c(l("namespace", _), l("tenantId", t.tenantId), l("ownerId", t.ownerId), l("state", "fulfilled")),
|
|
56
|
+
order: [],
|
|
57
|
+
take: v + 1,
|
|
58
|
+
skip: void 0,
|
|
59
|
+
projection: ["snapshot"]
|
|
60
|
+
})).some((e) => {
|
|
61
|
+
let t = e.snapshot;
|
|
62
|
+
return t?.facts?.originalTransactionId === n.originalTransactionId && t.facts.channel === n.channel;
|
|
63
|
+
}), w = (n) => s.fail(n instanceof e ? n : t("unavailable"));
|
|
64
|
+
return Object.freeze({
|
|
65
|
+
prepare: (e) => s.sync(() => u(m, async (n) => {
|
|
66
|
+
if (await y(n, e) !== !0) throw t("forbidden");
|
|
67
|
+
let r = e.facts.paid, i = r ? x.get(r.currency) : void 0;
|
|
68
|
+
if (!r || !i) throw t("forbidden");
|
|
69
|
+
if (await C(n, e.scope, e.facts)) return;
|
|
70
|
+
let a = Math.max(i.scale, r.scale);
|
|
71
|
+
if (await S(n, e.scope, e.at, r.currency, a) + d(r, a) > d(i, a)) throw t("limit_exceeded");
|
|
72
|
+
})).pipe(s.catchDefect(w)),
|
|
73
|
+
checkout: (n) => s.tryPromise({
|
|
74
|
+
try: async () => {
|
|
75
|
+
if (await y(m, n) !== !0) throw t("forbidden");
|
|
76
|
+
let e = n.product.offer.price, r = e.kind === "real" ? e.prices : e.kind === "mixed" ? e.real.prices : {}, i = Object.entries(r).flatMap(([e, t]) => {
|
|
77
|
+
let n = x.get(e);
|
|
78
|
+
return n ? [{
|
|
79
|
+
currency: e,
|
|
80
|
+
limit: n,
|
|
81
|
+
paid: {
|
|
82
|
+
units: String(t),
|
|
83
|
+
scale: f(e)
|
|
84
|
+
}
|
|
85
|
+
}] : [];
|
|
86
|
+
});
|
|
87
|
+
if (i.length === 0) throw t("forbidden");
|
|
88
|
+
for (let { currency: e, limit: t, paid: r } of i) {
|
|
89
|
+
let i = Math.max(t.scale, r.scale);
|
|
90
|
+
if (await S(m, n.scope, n.at, e, i) + d(r, i) <= d(t, i)) return;
|
|
91
|
+
}
|
|
92
|
+
throw t("limit_exceeded");
|
|
93
|
+
},
|
|
94
|
+
catch: (n) => n instanceof e ? n : t("unavailable")
|
|
95
|
+
})
|
|
96
|
+
});
|
|
97
|
+
};
|
|
98
|
+
export { m as iapSpendAdmission };
|