@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,212 @@
|
|
|
1
|
+
import { economyError as e } from "./errors.js";
|
|
2
|
+
import { captureBoundMethods as t, dataList as n, dataObject as r, identifier as i } from "./capture.js";
|
|
3
|
+
import { captureCurrencies as a } from "./currency.js";
|
|
4
|
+
import { definePrice as o } from "./price.js";
|
|
5
|
+
import { defineShopOffer as s, shopInteger as c } from "./shop.js";
|
|
6
|
+
import { Context as l } from "effect";
|
|
7
|
+
// src/subscriptions.ts
|
|
8
|
+
var u = (e, t) => {
|
|
9
|
+
let i = r(e ?? {}, ["items", "currencies"]), a = n(i.items ?? [], 16), o = n(i.currencies ?? [], 16);
|
|
10
|
+
if (!a.length && !o.length) return Object.freeze({
|
|
11
|
+
items: Object.freeze([]),
|
|
12
|
+
currencies: Object.freeze([])
|
|
13
|
+
});
|
|
14
|
+
let c = s({
|
|
15
|
+
id: "subscription.gift",
|
|
16
|
+
titleKey: "subscription.gift",
|
|
17
|
+
price: { kind: "free" },
|
|
18
|
+
items: a,
|
|
19
|
+
currencies: o
|
|
20
|
+
}, t);
|
|
21
|
+
return Object.freeze({
|
|
22
|
+
items: c.items,
|
|
23
|
+
currencies: c.currencies
|
|
24
|
+
});
|
|
25
|
+
}, d = (t, n, s = !1) => {
|
|
26
|
+
let l = r(t, [
|
|
27
|
+
"id",
|
|
28
|
+
"version",
|
|
29
|
+
"titleKey",
|
|
30
|
+
"price",
|
|
31
|
+
"period",
|
|
32
|
+
"grants",
|
|
33
|
+
"graceDays",
|
|
34
|
+
"coolingOff",
|
|
35
|
+
"disclosure"
|
|
36
|
+
]), d = a(n), f = r(l.period, ["unit", "count"]);
|
|
37
|
+
if (f.unit !== "day" && f.unit !== "week" && f.unit !== "month") throw e("invalid_input");
|
|
38
|
+
let p = c(f.count, 1, 12), m = r(l.grants, ["onPurchase", "daily"]), h = c(l.graceDays ?? 0, 0, 30), g = r(l.coolingOff ?? { days: 14 }, ["days", "overrideReason"]), _ = c(g.days, 0, 365), v = g.overrideReason ?? null;
|
|
39
|
+
if (v !== null && (typeof v != "string" || v.trim() !== v || v.length < 8 || v.length > 1e3) || _ < 14 && v === null) throw e("invalid_input");
|
|
40
|
+
let y = r(l.disclosure, [
|
|
41
|
+
"durationKey",
|
|
42
|
+
"renewalKey",
|
|
43
|
+
"cancellationPath"
|
|
44
|
+
]), b = y.cancellationPath;
|
|
45
|
+
if (typeof b != "string" || b.length > 512 || !/^\/(?!\/)[A-Za-z0-9/_-]*$/.test(b) || b === "/") throw e("invalid_input");
|
|
46
|
+
return Object.freeze({
|
|
47
|
+
id: i(l.id),
|
|
48
|
+
version: i(l.version ?? "1"),
|
|
49
|
+
titleKey: i(l.titleKey),
|
|
50
|
+
price: o(l.price, d, s),
|
|
51
|
+
period: Object.freeze({
|
|
52
|
+
unit: f.unit,
|
|
53
|
+
count: p
|
|
54
|
+
}),
|
|
55
|
+
grants: Object.freeze({
|
|
56
|
+
onPurchase: u(m.onPurchase, d),
|
|
57
|
+
daily: u(m.daily, d)
|
|
58
|
+
}),
|
|
59
|
+
graceDays: h,
|
|
60
|
+
coolingOff: Object.freeze({
|
|
61
|
+
days: _,
|
|
62
|
+
overrideReason: v
|
|
63
|
+
}),
|
|
64
|
+
disclosure: Object.freeze({
|
|
65
|
+
durationKey: i(y.durationKey),
|
|
66
|
+
renewalKey: i(y.renewalKey),
|
|
67
|
+
cancellationPath: b
|
|
68
|
+
})
|
|
69
|
+
});
|
|
70
|
+
}, f = (e) => c(e, 0, 864e13), p = (t) => {
|
|
71
|
+
let n = r(t, [
|
|
72
|
+
"subscription",
|
|
73
|
+
"currencies",
|
|
74
|
+
"realMoney",
|
|
75
|
+
"originAt",
|
|
76
|
+
"index",
|
|
77
|
+
"rulesVersion"
|
|
78
|
+
]), o = a(n.currencies), s = n.realMoney ?? !1;
|
|
79
|
+
if (typeof s != "boolean") throw e("invalid_input");
|
|
80
|
+
return Object.freeze({
|
|
81
|
+
subscription: d(n.subscription, o, s),
|
|
82
|
+
currencies: o,
|
|
83
|
+
realMoney: s,
|
|
84
|
+
originAt: f(n.originAt),
|
|
85
|
+
index: c(n.index, 0, 1e5),
|
|
86
|
+
rulesVersion: i(n.rulesVersion ?? "default.v1")
|
|
87
|
+
});
|
|
88
|
+
}, m = (t, n, r) => {
|
|
89
|
+
if (n.unit !== "month") {
|
|
90
|
+
let i = BigInt(t) + BigInt(n.count) * BigInt(r) * BigInt(n.unit === "week" ? 7 : 1) * 86400000n;
|
|
91
|
+
if (i > 8640000000000000n) throw e("invalid_input");
|
|
92
|
+
return Number(i);
|
|
93
|
+
}
|
|
94
|
+
let i = new Date(t), a = i.getUTCFullYear() * 12 + i.getUTCMonth() + n.count * r, o = Math.floor(a / 12), s = a % 12, c = new Date(t);
|
|
95
|
+
c.setUTCDate(1), c.setUTCFullYear(o, s, 1);
|
|
96
|
+
let l = new Date(c);
|
|
97
|
+
if (l.setUTCMonth(s + 1, 0), !Number.isFinite(c.getTime()) || !Number.isFinite(l.getTime())) throw e("invalid_input");
|
|
98
|
+
return c.setUTCDate(Math.min(i.getUTCDate(), l.getUTCDate())), f(c.getTime());
|
|
99
|
+
}, h = (e) => {
|
|
100
|
+
let t = p(e);
|
|
101
|
+
return Object.freeze({
|
|
102
|
+
startsAt: m(t.originAt, t.subscription.period, t.index),
|
|
103
|
+
expiresAt: m(t.originAt, t.subscription.period, t.index + 1)
|
|
104
|
+
});
|
|
105
|
+
}, g = (t, n = h) => {
|
|
106
|
+
if (typeof n != "function") throw e("invalid_input");
|
|
107
|
+
let i = p(t);
|
|
108
|
+
if (n !== h && i.rulesVersion === "default.v1") throw e("invalid_input");
|
|
109
|
+
let a = h(i), o = r(n(i), ["startsAt", "expiresAt"]), s = f(o.startsAt), c = f(o.expiresAt);
|
|
110
|
+
if (s >= c || s < a.startsAt || c > a.expiresAt) throw e("invalid_input");
|
|
111
|
+
return Object.freeze({
|
|
112
|
+
startsAt: s,
|
|
113
|
+
expiresAt: c
|
|
114
|
+
});
|
|
115
|
+
}, _ = ({ entitlement: e, at: t, claimedDays: n }) => t >= e.startsAt && (e.state === "active" && t < e.expiresAt || e.state === "grace" && t >= e.expiresAt && t < e.graceUntil) && !n.includes(Math.floor(t / 864e5)), v = (t, a = _) => {
|
|
116
|
+
if (typeof a != "function") throw e("invalid_input");
|
|
117
|
+
let o = r(t, [
|
|
118
|
+
"entitlement",
|
|
119
|
+
"at",
|
|
120
|
+
"claimedDays",
|
|
121
|
+
"rulesVersion"
|
|
122
|
+
]), s = r(o.entitlement, [
|
|
123
|
+
"startsAt",
|
|
124
|
+
"expiresAt",
|
|
125
|
+
"graceUntil",
|
|
126
|
+
"state"
|
|
127
|
+
]), l = i(o.rulesVersion ?? "default.v1");
|
|
128
|
+
if (a !== _ && l === "default.v1") throw e("invalid_input");
|
|
129
|
+
let u = f(s.startsAt), d = f(s.expiresAt), p = f(s.graceUntil), m = s.state;
|
|
130
|
+
if (u >= d || p < d || m !== "active" && m !== "grace" && m !== "expired") throw e("invalid_input");
|
|
131
|
+
let h = f(o.at), g = Object.freeze(n(o.claimedDays, 1e5).map((e) => c(e, 0, 1e8)));
|
|
132
|
+
if (new Set(g).size !== g.length) throw e("invalid_input");
|
|
133
|
+
let v = Object.freeze({
|
|
134
|
+
startsAt: u,
|
|
135
|
+
expiresAt: d,
|
|
136
|
+
graceUntil: p,
|
|
137
|
+
state: m
|
|
138
|
+
}), y = Object.freeze({
|
|
139
|
+
entitlement: v,
|
|
140
|
+
at: h,
|
|
141
|
+
claimedDays: g,
|
|
142
|
+
rulesVersion: l
|
|
143
|
+
}), b = a(y);
|
|
144
|
+
if (typeof b != "boolean") throw e("invalid_input");
|
|
145
|
+
return Object.freeze({
|
|
146
|
+
eligible: b && _(y),
|
|
147
|
+
day: Math.floor(h / 864e5)
|
|
148
|
+
});
|
|
149
|
+
}, y = class extends l.Service()("@voltro/SubscriptionsPort") {}, b = (e) => t(e, [
|
|
150
|
+
"list",
|
|
151
|
+
"active",
|
|
152
|
+
"start",
|
|
153
|
+
"renew",
|
|
154
|
+
"claimDaily",
|
|
155
|
+
"cancel",
|
|
156
|
+
"receipt",
|
|
157
|
+
"exportSubject",
|
|
158
|
+
"eraseSubject"
|
|
159
|
+
]), x = (t) => {
|
|
160
|
+
let n = r(t, [
|
|
161
|
+
"subscriptionId",
|
|
162
|
+
"subscriptionVersion",
|
|
163
|
+
"subscriptionDigest",
|
|
164
|
+
"requestId",
|
|
165
|
+
"currency"
|
|
166
|
+
]);
|
|
167
|
+
if (typeof n.subscriptionDigest != "string" || !/^[a-f0-9]{64}$/.test(n.subscriptionDigest)) throw e("invalid_input");
|
|
168
|
+
return Object.freeze({
|
|
169
|
+
subscriptionId: i(n.subscriptionId),
|
|
170
|
+
subscriptionVersion: i(n.subscriptionVersion),
|
|
171
|
+
subscriptionDigest: n.subscriptionDigest,
|
|
172
|
+
requestId: i(n.requestId),
|
|
173
|
+
currency: n.currency === void 0 ? null : i(n.currency)
|
|
174
|
+
});
|
|
175
|
+
}, S = (e) => {
|
|
176
|
+
let t = r(e, ["entitlementId", "requestId"]);
|
|
177
|
+
return Object.freeze({
|
|
178
|
+
entitlementId: i(t.entitlementId),
|
|
179
|
+
requestId: i(t.requestId)
|
|
180
|
+
});
|
|
181
|
+
}, C = (e) => {
|
|
182
|
+
let t = r(e, [
|
|
183
|
+
"tenantId",
|
|
184
|
+
"ownerId",
|
|
185
|
+
"entitlementId",
|
|
186
|
+
"requestId"
|
|
187
|
+
]);
|
|
188
|
+
return Object.freeze({
|
|
189
|
+
tenantId: i(t.tenantId),
|
|
190
|
+
ownerId: i(t.ownerId),
|
|
191
|
+
entitlementId: i(t.entitlementId),
|
|
192
|
+
requestId: i(t.requestId)
|
|
193
|
+
});
|
|
194
|
+
}, w = (t) => {
|
|
195
|
+
let n = r(t, ["kind", "intent"]);
|
|
196
|
+
if (n.kind === "start") {
|
|
197
|
+
let e = x(n.intent);
|
|
198
|
+
return Object.freeze({
|
|
199
|
+
kind: "start",
|
|
200
|
+
intent: Object.freeze({
|
|
201
|
+
...e,
|
|
202
|
+
currency: e.currency ?? void 0
|
|
203
|
+
})
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
if (n.kind !== "renew" && n.kind !== "daily" && n.kind !== "cancel") throw e("invalid_input");
|
|
207
|
+
return Object.freeze({
|
|
208
|
+
kind: n.kind,
|
|
209
|
+
intent: S(n.intent)
|
|
210
|
+
});
|
|
211
|
+
};
|
|
212
|
+
export { y as SubscriptionsPort, w as captureSubscriptionReceiptIntent, b as captureSubscriptionsService, _ as defaultSubscriptionDailyGrant, h as defaultSubscriptionPeriod, d as defineSubscription, v as resolveSubscriptionDailyGrant, g as resolveSubscriptionPeriod, S as subscriptionEntitlementIntent, C as subscriptionRenewIntent, x as subscriptionStartIntent };
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { SubscriptionsPort as e } from "./subscriptions.js";
|
|
2
|
+
import { EconomyPort as t } from "./port.js";
|
|
3
|
+
import { economyPlugin as n } from "./plugin.js";
|
|
4
|
+
import { subscriptionFixtureStart as r, subscriptionStoreFixture as i } from "./subscriptionStore.testFixtures.js";
|
|
5
|
+
import { Effect as a, Layer as o } from "effect";
|
|
6
|
+
import { InMemoryDataStore as s } from "@voltro/runtime";
|
|
7
|
+
// src/subscriptionsPort.fixture.ts
|
|
8
|
+
var c = {
|
|
9
|
+
app: {
|
|
10
|
+
name: "subscriptions-fixture",
|
|
11
|
+
type: "api",
|
|
12
|
+
voltroVersion: "0.83.1"
|
|
13
|
+
},
|
|
14
|
+
config: {},
|
|
15
|
+
env: {},
|
|
16
|
+
logger: {
|
|
17
|
+
info() {},
|
|
18
|
+
warn() {},
|
|
19
|
+
error() {},
|
|
20
|
+
debug() {}
|
|
21
|
+
}
|
|
22
|
+
}, l = a.gen(function* () {
|
|
23
|
+
let e = new s(), t = yield* a.promise(() => i(e, "fixture")), r = t.options, o = n({
|
|
24
|
+
currencies: r.currencies,
|
|
25
|
+
now: r.now,
|
|
26
|
+
subscriptions: {
|
|
27
|
+
subscriptions: r.subscriptions,
|
|
28
|
+
inventory: r.inventory,
|
|
29
|
+
accessSource: r.accessSource,
|
|
30
|
+
version: r.version,
|
|
31
|
+
period: r.period,
|
|
32
|
+
daily: r.daily,
|
|
33
|
+
priceResolver: r.priceResolver,
|
|
34
|
+
systemAccount: r.systemAccount,
|
|
35
|
+
maxHistoryRows: r.maxHistoryRows,
|
|
36
|
+
now: r.now
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
return yield* a.promise(async () => {
|
|
40
|
+
await o.bindDataStore?.(e);
|
|
41
|
+
}), Object.freeze({
|
|
42
|
+
store: e,
|
|
43
|
+
plugin: o,
|
|
44
|
+
base: t,
|
|
45
|
+
close: a.suspend(() => o.onDeactivate?.(c))
|
|
46
|
+
});
|
|
47
|
+
}), u = o.effectContext(a.acquireRelease(l, (e) => e.close).pipe(a.flatMap((e) => o.build(e.plugin.services)))), d = Object.freeze({
|
|
48
|
+
kind: "port",
|
|
49
|
+
tag: e,
|
|
50
|
+
fakeLayer: u,
|
|
51
|
+
probe: {
|
|
52
|
+
run: () => a.scoped(a.gen(function* () {
|
|
53
|
+
let n = yield* e, i = yield* t, a = {
|
|
54
|
+
type: "user",
|
|
55
|
+
id: "a",
|
|
56
|
+
tenantId: "fixture",
|
|
57
|
+
kind: "guest"
|
|
58
|
+
}, o = (yield* n.list(a))[0], s = r(o), c = yield* n.start(a, s), l = yield* n.start(a, s), u = yield* n.claimDaily(a, {
|
|
59
|
+
entitlementId: c.entitlementId,
|
|
60
|
+
requestId: "daily"
|
|
61
|
+
}), d = yield* i.mine(a);
|
|
62
|
+
return {
|
|
63
|
+
same: c.operationId === l.operationId,
|
|
64
|
+
daily: u.kind,
|
|
65
|
+
balance: d[0]?.balance
|
|
66
|
+
};
|
|
67
|
+
}).pipe(a.provide(u))),
|
|
68
|
+
expected: {
|
|
69
|
+
same: !0,
|
|
70
|
+
daily: "daily",
|
|
71
|
+
balance: "93"
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
export { u as subscriptionsFakeLayer, l as subscriptionsPortFixture, d as subscriptionsPortSystemFixture };
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { defaultPriceResolver as e, resolvePrice as t } from "./price.js";
|
|
2
|
+
import { EconomyPort as n } from "./port.js";
|
|
3
|
+
import { priceResolverFixture as r } from "./declarationFixtures.js";
|
|
4
|
+
import { economyPortFixture as i } from "./economyPort.fixture.js";
|
|
5
|
+
import { Effect as a, Layer as o } from "effect";
|
|
6
|
+
import { systemSubject as s } from "@voltro/protocol";
|
|
7
|
+
// src/systemFixtures.ts
|
|
8
|
+
var c = r(), l = Object.freeze({
|
|
9
|
+
kind: "slot",
|
|
10
|
+
defaultImplementation: e,
|
|
11
|
+
defaultProbe: {
|
|
12
|
+
run: () => a.sync(() => t(c.context)),
|
|
13
|
+
expected: {
|
|
14
|
+
kind: "virtual",
|
|
15
|
+
options: [{
|
|
16
|
+
currency: "test.gold",
|
|
17
|
+
amount: "6"
|
|
18
|
+
}]
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
overrideProbe: {
|
|
22
|
+
run: () => a.sync(() => t(c.context, (t) => e({
|
|
23
|
+
...t,
|
|
24
|
+
adjustments: [{
|
|
25
|
+
currency: "test.gold",
|
|
26
|
+
discountBps: 6e3,
|
|
27
|
+
minimum: "2"
|
|
28
|
+
}]
|
|
29
|
+
}))),
|
|
30
|
+
expected: {
|
|
31
|
+
kind: "virtual",
|
|
32
|
+
options: [{
|
|
33
|
+
currency: "test.gold",
|
|
34
|
+
amount: "5"
|
|
35
|
+
}]
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}), u = o.effect(n, a.acquireRelease(a.sync(() => i({
|
|
39
|
+
currencies: [{
|
|
40
|
+
id: "test.gold",
|
|
41
|
+
kind: "soft",
|
|
42
|
+
cap: "1000"
|
|
43
|
+
}],
|
|
44
|
+
now: () => 0
|
|
45
|
+
})), (e) => e.close).pipe(a.map((e) => e.service))), d = s("economy.system.fixture"), f = {
|
|
46
|
+
type: "user",
|
|
47
|
+
id: "a",
|
|
48
|
+
tenantId: "fixture"
|
|
49
|
+
}, p = Object.freeze({
|
|
50
|
+
kind: "port",
|
|
51
|
+
tag: n,
|
|
52
|
+
fakeLayer: u,
|
|
53
|
+
probe: {
|
|
54
|
+
run: () => a.scoped(a.gen(function* () {
|
|
55
|
+
let e = yield* n, t = {
|
|
56
|
+
tenantId: "fixture",
|
|
57
|
+
requestId: "reward",
|
|
58
|
+
currency: "test.gold",
|
|
59
|
+
amount: "7",
|
|
60
|
+
from: {
|
|
61
|
+
kind: "system",
|
|
62
|
+
id: "fixture"
|
|
63
|
+
},
|
|
64
|
+
to: {
|
|
65
|
+
kind: "wallet",
|
|
66
|
+
ownerKind: "player",
|
|
67
|
+
ownerId: "a"
|
|
68
|
+
},
|
|
69
|
+
reason: "fixture",
|
|
70
|
+
ref: {
|
|
71
|
+
kind: "fixture",
|
|
72
|
+
id: "reward"
|
|
73
|
+
}
|
|
74
|
+
}, r = yield* e.transfer(d, t), i = yield* e.transfer(d, t), a = yield* e.mine(f), o = yield* e.auditWallet(d, "fixture", t.to, t.currency);
|
|
75
|
+
return {
|
|
76
|
+
original: r.txId === i.txId,
|
|
77
|
+
balance: a[0]?.balance,
|
|
78
|
+
matches: o.matches
|
|
79
|
+
};
|
|
80
|
+
}).pipe(a.provide(u))),
|
|
81
|
+
expected: {
|
|
82
|
+
original: !0,
|
|
83
|
+
balance: "7",
|
|
84
|
+
matches: !0
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
export { u as economyFakeLayer, p as economyPortSystemFixture, l as priceResolverSystemFixture };
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { bigint as e, boolean as t, id as n, integer as r, json as i, table as a, text as o, timestamp as s } from "@voltro/database";
|
|
2
|
+
// src/tables.entity.ts
|
|
3
|
+
var c = () => o().maxLength(120).externalId().sensitive("pii"), l = a("_voltro_eco_currencies", {
|
|
4
|
+
id: n({ prefix: "ecc" }),
|
|
5
|
+
tenantId: c(),
|
|
6
|
+
currency: o().maxLength(120).safe(),
|
|
7
|
+
config: i().safe(),
|
|
8
|
+
admission: r().serverOnly()
|
|
9
|
+
}).index(["tenantId", "currency"]), u = a("_voltro_eco_wallets", {
|
|
10
|
+
id: n({ prefix: "ecw" }),
|
|
11
|
+
tenantId: c(),
|
|
12
|
+
ownerId: o().maxLength(120).externalId().sensitive("pii"),
|
|
13
|
+
ownerKind: o().maxLength(16).oneOf(["player", "guild"]).safe(),
|
|
14
|
+
currency: o().maxLength(120).safe(),
|
|
15
|
+
balance: e().safe(),
|
|
16
|
+
updatedAt: s().safe(),
|
|
17
|
+
debtPolicy: o().maxLength(16).oneOf(["allowNegative", "blockSpend"]).nullable().serverOnly()
|
|
18
|
+
}).index([
|
|
19
|
+
"tenantId",
|
|
20
|
+
"ownerKind",
|
|
21
|
+
"ownerId",
|
|
22
|
+
"currency"
|
|
23
|
+
]), d = a("_voltro_eco_ledger", {
|
|
24
|
+
id: n({ prefix: "ecl" }),
|
|
25
|
+
tenantId: c(),
|
|
26
|
+
txId: o().maxLength(64).safe(),
|
|
27
|
+
currency: o().maxLength(120).safe(),
|
|
28
|
+
accountKind: o().maxLength(16).oneOf(["wallet", "system"]).safe(),
|
|
29
|
+
ownerId: o().maxLength(120).nullable().externalId().sensitive("pii"),
|
|
30
|
+
ownerKind: o().maxLength(16).oneOf(["player", "guild"]).nullable().safe(),
|
|
31
|
+
walletKey: o().maxLength(64).nullable().serverOnly(),
|
|
32
|
+
systemAccount: o().maxLength(120).nullable().safe(),
|
|
33
|
+
ownerSequence: r().nullable().serverOnly(),
|
|
34
|
+
debtPolicy: o().maxLength(16).oneOf(["allowNegative", "blockSpend"]).nullable().serverOnly(),
|
|
35
|
+
debit: e().safe(),
|
|
36
|
+
credit: e().safe(),
|
|
37
|
+
reason: o().maxLength(120).safe(),
|
|
38
|
+
refKind: o().maxLength(120).nullable().sensitive("pii"),
|
|
39
|
+
refId: o().maxLength(120).nullable().sensitive("pii"),
|
|
40
|
+
actor: o().maxLength(120).nullable().sensitive("pii"),
|
|
41
|
+
at: s().safe()
|
|
42
|
+
}).index([
|
|
43
|
+
"tenantId",
|
|
44
|
+
"ownerKind",
|
|
45
|
+
"ownerId"
|
|
46
|
+
]).index(["tenantId", "txId"]).index([
|
|
47
|
+
"tenantId",
|
|
48
|
+
"currency",
|
|
49
|
+
"walletKey"
|
|
50
|
+
]), f = a("_voltro_eco_tx", {
|
|
51
|
+
id: n({ prefix: "ect" }),
|
|
52
|
+
tenantId: c(),
|
|
53
|
+
state: o().maxLength(16).oneOf([
|
|
54
|
+
"pending",
|
|
55
|
+
"committed",
|
|
56
|
+
"erased"
|
|
57
|
+
]).serverOnly(),
|
|
58
|
+
digest: o().maxLength(64).nullable().serverOnly(),
|
|
59
|
+
receipt: i().nullable().safe(),
|
|
60
|
+
escrow: i().nullable().serverOnly(),
|
|
61
|
+
admission: r().serverOnly(),
|
|
62
|
+
createdAt: s().safe()
|
|
63
|
+
}).index(["tenantId", "state"]), p = a("_voltro_eco_subjects", {
|
|
64
|
+
id: n({ prefix: "ecs" }),
|
|
65
|
+
tenantId: c(),
|
|
66
|
+
ownerKind: o().maxLength(16).oneOf(["player", "guild"]).safe(),
|
|
67
|
+
ownerId: o().maxLength(120).nullable().externalId().sensitive("pii"),
|
|
68
|
+
erased: t().serverOnly(),
|
|
69
|
+
admission: r().serverOnly(),
|
|
70
|
+
entriesCount: r().serverOnly()
|
|
71
|
+
}).index([
|
|
72
|
+
"tenantId",
|
|
73
|
+
"ownerKind",
|
|
74
|
+
"ownerId"
|
|
75
|
+
]), m = [
|
|
76
|
+
l,
|
|
77
|
+
u,
|
|
78
|
+
d,
|
|
79
|
+
f,
|
|
80
|
+
p
|
|
81
|
+
];
|
|
82
|
+
export { l as economyCurrenciesTable, d as economyLedgerTable, p as economySubjectsTable, m as economyTables, f as economyTransactionsTable, u as economyWalletsTable };
|