@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,200 @@
|
|
|
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 { nonNegativeAmount as a, positiveAmount as o } from "./amount.js";
|
|
4
|
+
import { captureCurrencies as s } from "./currency.js";
|
|
5
|
+
import { definePrice as c } from "./price.js";
|
|
6
|
+
import { shopInteger as l } from "./shop.js";
|
|
7
|
+
import { Context as u } from "effect";
|
|
8
|
+
// src/piggyBanks.ts
|
|
9
|
+
var d = (t, a, l = !1) => {
|
|
10
|
+
let u = r(t, [
|
|
11
|
+
"id",
|
|
12
|
+
"version",
|
|
13
|
+
"titleKey",
|
|
14
|
+
"currency",
|
|
15
|
+
"cap",
|
|
16
|
+
"unlock",
|
|
17
|
+
"fillFrom",
|
|
18
|
+
"reset"
|
|
19
|
+
]), d = s(a), f = i(u.currency), p = d.find((e) => e.id === f);
|
|
20
|
+
if (!p) throw e("invalid_currency");
|
|
21
|
+
let m = o(u.cap).toString(), h = Object.freeze(n(u.fillFrom, 32).map((e) => i(e)));
|
|
22
|
+
if (BigInt(m) > BigInt(p.cap) || !h.length || new Set(h).size !== h.length || u.reset !== void 0 && u.reset !== "onUnlock") throw e("invalid_input");
|
|
23
|
+
return Object.freeze({
|
|
24
|
+
id: i(u.id),
|
|
25
|
+
version: i(u.version ?? "1"),
|
|
26
|
+
titleKey: i(u.titleKey),
|
|
27
|
+
currency: f,
|
|
28
|
+
cap: m,
|
|
29
|
+
unlock: c(u.unlock, d, l),
|
|
30
|
+
fillFrom: h,
|
|
31
|
+
reset: "onUnlock"
|
|
32
|
+
});
|
|
33
|
+
}, f = ({ bank: e, available: t, acceptedAmount: n }) => {
|
|
34
|
+
let r = BigInt(e.cap) - a(t), i = a(n);
|
|
35
|
+
return r < i ? r : i;
|
|
36
|
+
}, p = () => "0", m = (t) => {
|
|
37
|
+
let n = r(t, [
|
|
38
|
+
"bank",
|
|
39
|
+
"currencies",
|
|
40
|
+
"realMoney",
|
|
41
|
+
"available",
|
|
42
|
+
"rulesVersion"
|
|
43
|
+
]), o = s(n.currencies), c = n.realMoney ?? !1;
|
|
44
|
+
if (typeof c != "boolean") throw e("invalid_input");
|
|
45
|
+
let l = d(n.bank, o, c), u = a(n.available).toString(), f = i(n.rulesVersion ?? "default.v1");
|
|
46
|
+
if (BigInt(u) > BigInt(l.cap)) throw e("invalid_record");
|
|
47
|
+
return Object.freeze({
|
|
48
|
+
bank: l,
|
|
49
|
+
currencies: o,
|
|
50
|
+
realMoney: c,
|
|
51
|
+
available: u,
|
|
52
|
+
rulesVersion: f
|
|
53
|
+
});
|
|
54
|
+
}, h = (t, n = f) => {
|
|
55
|
+
let { acceptedAmount: i, ...o } = r(t, [
|
|
56
|
+
"bank",
|
|
57
|
+
"currencies",
|
|
58
|
+
"realMoney",
|
|
59
|
+
"available",
|
|
60
|
+
"rulesVersion",
|
|
61
|
+
"acceptedAmount"
|
|
62
|
+
]), s = Object.freeze({
|
|
63
|
+
...m(o),
|
|
64
|
+
acceptedAmount: a(i).toString()
|
|
65
|
+
});
|
|
66
|
+
if (typeof n != "function" || n !== f && s.rulesVersion === "default.v1") throw e("invalid_input");
|
|
67
|
+
let c = a(n(s));
|
|
68
|
+
if (c > a(f(s))) throw e("invalid_input");
|
|
69
|
+
return c.toString();
|
|
70
|
+
}, g = (t, n = p) => {
|
|
71
|
+
let r = m(t);
|
|
72
|
+
if (typeof n != "function" || n !== p && r.rulesVersion === "default.v1") throw e("invalid_input");
|
|
73
|
+
let i = a(n(r)), o = a(r.available);
|
|
74
|
+
if (o === 0n || i >= o) throw e("invalid_input");
|
|
75
|
+
return Object.freeze({
|
|
76
|
+
remaining: i.toString(),
|
|
77
|
+
amount: (o - i).toString()
|
|
78
|
+
});
|
|
79
|
+
}, _ = (t, s) => {
|
|
80
|
+
let c = r(t, [
|
|
81
|
+
"cap",
|
|
82
|
+
"fillFrom",
|
|
83
|
+
"id",
|
|
84
|
+
"version",
|
|
85
|
+
"titleKey",
|
|
86
|
+
"currency",
|
|
87
|
+
"unlock",
|
|
88
|
+
"reset"
|
|
89
|
+
]), u = o(c.cap), d = n(c.fillFrom, 32).map((e) => i(e)), f = /* @__PURE__ */ new Set(), p = /* @__PURE__ */ new Set(), m = 0n, h = 0, g = 0, _ = (t) => {
|
|
90
|
+
if (typeof t != "string" || a(t).toString() !== t) throw e("invalid_record");
|
|
91
|
+
return BigInt(t);
|
|
92
|
+
}, v = Object.freeze(n(s, 1e5, "invalid_record").map((t, n) => {
|
|
93
|
+
let a = r(t, [
|
|
94
|
+
"id",
|
|
95
|
+
"sequence",
|
|
96
|
+
"kind",
|
|
97
|
+
"at",
|
|
98
|
+
"authorityId",
|
|
99
|
+
"eventId",
|
|
100
|
+
"sourceId",
|
|
101
|
+
"acceptedAmount",
|
|
102
|
+
"delta",
|
|
103
|
+
"amount",
|
|
104
|
+
"remaining"
|
|
105
|
+
], "invalid_record"), o = i(a.id), s = l(a.sequence, 1, 1e5), c = l(a.at, 0, 864e13);
|
|
106
|
+
if (f.has(o) || s !== n + 1 || c < g) throw e("invalid_record");
|
|
107
|
+
if (f.add(o), g = c, a.kind === "fill") {
|
|
108
|
+
r(t, [
|
|
109
|
+
"id",
|
|
110
|
+
"sequence",
|
|
111
|
+
"kind",
|
|
112
|
+
"at",
|
|
113
|
+
"authorityId",
|
|
114
|
+
"eventId",
|
|
115
|
+
"sourceId",
|
|
116
|
+
"acceptedAmount",
|
|
117
|
+
"delta"
|
|
118
|
+
], "invalid_record");
|
|
119
|
+
let n = i(a.authorityId), l = i(a.eventId), f = i(a.sourceId), h = _(a.acceptedAmount), g = _(a.delta), v = JSON.stringify([n, l]);
|
|
120
|
+
if (!d.includes(f) || p.has(v) || g > h || m + g > u) throw e("invalid_record");
|
|
121
|
+
return p.add(v), m += g, Object.freeze({
|
|
122
|
+
id: o,
|
|
123
|
+
sequence: s,
|
|
124
|
+
kind: "fill",
|
|
125
|
+
at: c,
|
|
126
|
+
authorityId: n,
|
|
127
|
+
eventId: l,
|
|
128
|
+
sourceId: f,
|
|
129
|
+
acceptedAmount: h.toString(),
|
|
130
|
+
delta: g.toString()
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
if (a.kind !== "unlock") throw e("invalid_record");
|
|
134
|
+
r(t, [
|
|
135
|
+
"id",
|
|
136
|
+
"sequence",
|
|
137
|
+
"kind",
|
|
138
|
+
"at",
|
|
139
|
+
"amount",
|
|
140
|
+
"remaining"
|
|
141
|
+
], "invalid_record");
|
|
142
|
+
let v = _(a.amount), y = _(a.remaining);
|
|
143
|
+
if (!v || v + y !== m) throw e("invalid_record");
|
|
144
|
+
return m = y, h++, Object.freeze({
|
|
145
|
+
id: o,
|
|
146
|
+
sequence: s,
|
|
147
|
+
kind: "unlock",
|
|
148
|
+
at: c,
|
|
149
|
+
amount: v.toString(),
|
|
150
|
+
remaining: y.toString()
|
|
151
|
+
});
|
|
152
|
+
}));
|
|
153
|
+
return Object.freeze({
|
|
154
|
+
events: v,
|
|
155
|
+
available: m.toString(),
|
|
156
|
+
cycles: h
|
|
157
|
+
});
|
|
158
|
+
}, v = class extends u.Service()("@voltro/PiggyBanksPort") {}, y = (e) => t(e, [
|
|
159
|
+
"list",
|
|
160
|
+
"fill",
|
|
161
|
+
"unlock",
|
|
162
|
+
"receipt",
|
|
163
|
+
"rebuild",
|
|
164
|
+
"exportSubject",
|
|
165
|
+
"eraseSubject"
|
|
166
|
+
]), b = (e) => {
|
|
167
|
+
let t = r(e, [
|
|
168
|
+
"tenantId",
|
|
169
|
+
"ownerId",
|
|
170
|
+
"bankId",
|
|
171
|
+
"sourceId",
|
|
172
|
+
"eventId",
|
|
173
|
+
"requestId"
|
|
174
|
+
]);
|
|
175
|
+
return Object.freeze({
|
|
176
|
+
tenantId: i(t.tenantId),
|
|
177
|
+
ownerId: i(t.ownerId),
|
|
178
|
+
bankId: i(t.bankId),
|
|
179
|
+
sourceId: i(t.sourceId),
|
|
180
|
+
eventId: i(t.eventId),
|
|
181
|
+
requestId: i(t.requestId)
|
|
182
|
+
});
|
|
183
|
+
}, x = (t) => {
|
|
184
|
+
let n = r(t, [
|
|
185
|
+
"bankId",
|
|
186
|
+
"bankVersion",
|
|
187
|
+
"bankDigest",
|
|
188
|
+
"requestId",
|
|
189
|
+
"currency"
|
|
190
|
+
]);
|
|
191
|
+
if (typeof n.bankDigest != "string" || !/^[a-f0-9]{64}$/.test(n.bankDigest)) throw e("invalid_input");
|
|
192
|
+
return Object.freeze({
|
|
193
|
+
bankId: i(n.bankId),
|
|
194
|
+
bankVersion: i(n.bankVersion),
|
|
195
|
+
bankDigest: n.bankDigest,
|
|
196
|
+
requestId: i(n.requestId),
|
|
197
|
+
currency: n.currency === void 0 ? null : i(n.currency)
|
|
198
|
+
});
|
|
199
|
+
};
|
|
200
|
+
export { v as PiggyBanksPort, y as capturePiggyBanksService, f as defaultPiggyFill, p as defaultPiggyReset, d as definePiggyBank, b as piggyFillIntent, x as piggyUnlockIntent, _ as projectPiggyBank, h as resolvePiggyFill, g as resolvePiggyReset };
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import { EconomyError as e, economyError as t } from "./errors.js";
|
|
2
|
+
import { captureQueryTables as n, dataList as r, dataObject as i, declaredSources as a, identifier as o } from "./capture.js";
|
|
3
|
+
import { defaultPriceResolver as s } from "./price.js";
|
|
4
|
+
import { piggyListDescriptor as c, piggyReceiptDescriptor as l, piggyRpcClientImports as u, piggyUnlockDescriptor as d } from "./rpc.js";
|
|
5
|
+
import { PiggyBanksPort as f, capturePiggyBanksService as p, defaultPiggyFill as m, defaultPiggyReset as h, definePiggyBank as g, piggyFillIntent as _, piggyUnlockIntent as v } from "./piggyBanks.js";
|
|
6
|
+
import { piggyTables as y } from "./piggyTables.entity.js";
|
|
7
|
+
import { dataStorePiggyBanks as b, resolvePiggyStoreOptions as x } from "./piggyStore.server.js";
|
|
8
|
+
import { Effect as S, Layer as C } from "effect";
|
|
9
|
+
// src/piggyBinding.server.ts
|
|
10
|
+
var w = () => S.fail(t("unavailable")), T = Object.freeze({
|
|
11
|
+
list: w,
|
|
12
|
+
fill: w,
|
|
13
|
+
unlock: w,
|
|
14
|
+
receipt: w,
|
|
15
|
+
rebuild: w,
|
|
16
|
+
exportSubject: w,
|
|
17
|
+
eraseSubject: w
|
|
18
|
+
}), E = (w, T) => {
|
|
19
|
+
if (w === void 0) return;
|
|
20
|
+
let E = i(w, [
|
|
21
|
+
"banks",
|
|
22
|
+
"fillSource",
|
|
23
|
+
"unlockSource",
|
|
24
|
+
"version",
|
|
25
|
+
"fill",
|
|
26
|
+
"reset",
|
|
27
|
+
"priceResolver",
|
|
28
|
+
"systemAccount",
|
|
29
|
+
"allowedServices",
|
|
30
|
+
"maxHistoryRows",
|
|
31
|
+
"now",
|
|
32
|
+
"service",
|
|
33
|
+
"querySources"
|
|
34
|
+
]), D = E.service === void 0 ? void 0 : p(E.service);
|
|
35
|
+
if (T.replacedWallet && !D || D && [
|
|
36
|
+
"fillSource",
|
|
37
|
+
"unlockSource",
|
|
38
|
+
"fill",
|
|
39
|
+
"reset",
|
|
40
|
+
"priceResolver",
|
|
41
|
+
"systemAccount",
|
|
42
|
+
"allowedServices",
|
|
43
|
+
"maxHistoryRows",
|
|
44
|
+
"now"
|
|
45
|
+
].some((e) => E[e] !== void 0)) throw t("invalid_input");
|
|
46
|
+
let O = E.querySources === void 0 ? void 0 : i(E.querySources, ["list", "receipt"]);
|
|
47
|
+
if (D && !O) throw t("invalid_input");
|
|
48
|
+
let k = O ? Object.freeze({
|
|
49
|
+
list: n(O.list),
|
|
50
|
+
receipt: n(O.receipt)
|
|
51
|
+
}) : void 0, A = D ? void 0 : x({
|
|
52
|
+
currencies: T.currencies,
|
|
53
|
+
realMoney: T.realMoney,
|
|
54
|
+
economy: T.economy,
|
|
55
|
+
banks: E.banks,
|
|
56
|
+
fillSource: E.fillSource,
|
|
57
|
+
unlockSource: E.unlockSource,
|
|
58
|
+
version: E.version,
|
|
59
|
+
fill: E.fill,
|
|
60
|
+
reset: E.reset,
|
|
61
|
+
priceResolver: E.priceResolver ?? T.priceResolver,
|
|
62
|
+
systemAccount: E.systemAccount,
|
|
63
|
+
allowedServices: E.allowedServices ?? T.allowedServices,
|
|
64
|
+
maxHistoryRows: E.maxHistoryRows,
|
|
65
|
+
now: E.now ?? T.now
|
|
66
|
+
}), j = A?.banks ?? Object.freeze(r(E.banks, 32).map((e) => g(e, T.currencies, T.realMoney)));
|
|
67
|
+
if (!j.length || new Set(j.map((e) => e.id)).size !== j.length) throw t("invalid_input");
|
|
68
|
+
let M = A?.version ?? o(E.version);
|
|
69
|
+
if (M === "default.v1") throw t("invalid_input");
|
|
70
|
+
let N = new Set(A?.allowedServices ?? T.allowedServices), P, F = !1, I, L = (e) => S.suspend(() => {
|
|
71
|
+
let n = D ?? P;
|
|
72
|
+
return F && n ? e(n) : S.fail(t("unavailable"));
|
|
73
|
+
}), R = (n) => {
|
|
74
|
+
try {
|
|
75
|
+
return n();
|
|
76
|
+
} catch (n) {
|
|
77
|
+
return S.fail(n instanceof e ? n : t("invalid_input"));
|
|
78
|
+
}
|
|
79
|
+
}, z = (e) => {
|
|
80
|
+
let n = structuredClone(e);
|
|
81
|
+
if (n.type !== "user") throw t("forbidden");
|
|
82
|
+
return o(n.id), o(n.tenantId), n;
|
|
83
|
+
}, B = (e) => {
|
|
84
|
+
let n = structuredClone(e);
|
|
85
|
+
if (n.type !== "system" && (n.type !== "service" || !N.has(n.service))) throw t("forbidden");
|
|
86
|
+
return n;
|
|
87
|
+
}, V = (e) => {
|
|
88
|
+
let n = i(e, [
|
|
89
|
+
"tenantId",
|
|
90
|
+
"subjectId",
|
|
91
|
+
"kind"
|
|
92
|
+
]);
|
|
93
|
+
if (n.kind !== "guest" && n.kind !== "user") throw t("invalid_input");
|
|
94
|
+
return Object.freeze({
|
|
95
|
+
tenantId: o(n.tenantId),
|
|
96
|
+
subjectId: o(n.subjectId),
|
|
97
|
+
kind: n.kind
|
|
98
|
+
});
|
|
99
|
+
}, H = (e) => {
|
|
100
|
+
let t = i(e, ["requestId"]);
|
|
101
|
+
return Object.freeze({ requestId: o(t.requestId) });
|
|
102
|
+
}, U = Object.freeze({
|
|
103
|
+
list: (e) => R(() => {
|
|
104
|
+
let t = z(e);
|
|
105
|
+
return L((e) => e.list(t));
|
|
106
|
+
}),
|
|
107
|
+
fill: (e, t) => R(() => {
|
|
108
|
+
let n = B(e), r = _(t);
|
|
109
|
+
return L((e) => e.fill(n, r));
|
|
110
|
+
}),
|
|
111
|
+
unlock: (e, t) => R(() => {
|
|
112
|
+
let n = z(e), r = v(t), i = Object.freeze({
|
|
113
|
+
...r,
|
|
114
|
+
currency: r.currency ?? void 0
|
|
115
|
+
});
|
|
116
|
+
return L((e) => e.unlock(n, i));
|
|
117
|
+
}),
|
|
118
|
+
receipt: (e, t) => R(() => {
|
|
119
|
+
let n = z(e), r = H(t);
|
|
120
|
+
return L((e) => e.receipt(n, r));
|
|
121
|
+
}),
|
|
122
|
+
rebuild: (e, t) => R(() => {
|
|
123
|
+
let n = B(e), r = i(t, [
|
|
124
|
+
"tenantId",
|
|
125
|
+
"ownerId",
|
|
126
|
+
"bankId"
|
|
127
|
+
]), a = Object.freeze({
|
|
128
|
+
tenantId: o(r.tenantId),
|
|
129
|
+
ownerId: o(r.ownerId),
|
|
130
|
+
bankId: o(r.bankId)
|
|
131
|
+
});
|
|
132
|
+
return L((e) => e.rebuild(n, a));
|
|
133
|
+
}),
|
|
134
|
+
exportSubject: (e) => R(() => {
|
|
135
|
+
let t = V(e);
|
|
136
|
+
return L((e) => e.exportSubject(t));
|
|
137
|
+
}),
|
|
138
|
+
eraseSubject: (e) => R(() => {
|
|
139
|
+
let t = V(e);
|
|
140
|
+
return L((e) => e.eraseSubject(t));
|
|
141
|
+
})
|
|
142
|
+
}), W = (e, t) => D ? k[e] : [.../* @__PURE__ */ new Set([...t, ...k?.[e] ?? []])], G = [
|
|
143
|
+
{
|
|
144
|
+
...c,
|
|
145
|
+
source: W("list", a(c.source)),
|
|
146
|
+
execute: (e, t) => U.list(t.request.subject)
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
...l,
|
|
150
|
+
source: W("receipt", a(l.source)),
|
|
151
|
+
execute: (e, t) => U.receipt(t.request.subject, e)
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
...d,
|
|
155
|
+
execute: (e, t) => U.unlock(t.request.subject, e)
|
|
156
|
+
}
|
|
157
|
+
], K = A ? y : [], q = Object.freeze({
|
|
158
|
+
backend: D ? "custom" : "sql",
|
|
159
|
+
version: M,
|
|
160
|
+
slots: Object.freeze({
|
|
161
|
+
fill: D || A?.fill !== m ? "custom" : "default",
|
|
162
|
+
reset: D || A?.reset !== h ? "custom" : "default",
|
|
163
|
+
priceResolver: D || A?.priceResolver !== s ? "custom" : "default"
|
|
164
|
+
}),
|
|
165
|
+
fillSource: D ? "app-owned" : "custom",
|
|
166
|
+
unlockSource: D ? "app-owned" : "custom",
|
|
167
|
+
banks: Object.freeze(j.map((e) => Object.freeze({
|
|
168
|
+
id: e.id,
|
|
169
|
+
version: e.version,
|
|
170
|
+
currency: e.currency,
|
|
171
|
+
cap: e.cap,
|
|
172
|
+
kind: e.unlock.kind,
|
|
173
|
+
sourceKinds: e.fillFrom.length
|
|
174
|
+
}))),
|
|
175
|
+
budgets: D ? null : Object.freeze({ historyRows: A.maxHistoryRows }),
|
|
176
|
+
virtualUnlockInstalled: !0,
|
|
177
|
+
realPaymentInstalled: !1,
|
|
178
|
+
automaticFillInstalled: !1,
|
|
179
|
+
clientRecoveryInstalled: !1,
|
|
180
|
+
gmActionsInstalled: !1
|
|
181
|
+
});
|
|
182
|
+
return Object.freeze({
|
|
183
|
+
service: U,
|
|
184
|
+
layer: C.succeed(f, U),
|
|
185
|
+
tables: K,
|
|
186
|
+
routes: G,
|
|
187
|
+
status: q,
|
|
188
|
+
rpcClientDescriptors: u,
|
|
189
|
+
roles: A ? [
|
|
190
|
+
"piggyTenants",
|
|
191
|
+
"piggyDefinitions",
|
|
192
|
+
"piggySubjects",
|
|
193
|
+
"piggyEvents"
|
|
194
|
+
] : [],
|
|
195
|
+
bind: (e) => {
|
|
196
|
+
if (I !== void 0 && I !== e) throw Error("Piggy-bank system cannot cross app stores");
|
|
197
|
+
I = e, A && (P = b(e, A)), F = !0;
|
|
198
|
+
},
|
|
199
|
+
deactivate: () => {
|
|
200
|
+
F = !1, P = void 0;
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
};
|
|
204
|
+
export { E as bindPiggyBanksSystem, T as unavailablePiggyBanks };
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { PiggyBanksPort as e } from "./piggyBanks.js";
|
|
2
|
+
import { EconomyPort as t } from "./port.js";
|
|
3
|
+
import { economyPlugin as n } from "./plugin.js";
|
|
4
|
+
import { shopMachine as r } from "./shop.testFixtures.js";
|
|
5
|
+
import { piggyFixtureUnlock as i, piggyStoreFixture as a } from "./piggyStore.testFixtures.js";
|
|
6
|
+
import { Effect as o, Layer as s } from "effect";
|
|
7
|
+
import { InMemoryDataStore as c } from "@voltro/runtime";
|
|
8
|
+
// src/piggyPort.fixture.ts
|
|
9
|
+
var l = {
|
|
10
|
+
app: {
|
|
11
|
+
name: "piggy-fixture",
|
|
12
|
+
type: "api",
|
|
13
|
+
voltroVersion: "0.83.1"
|
|
14
|
+
},
|
|
15
|
+
config: {},
|
|
16
|
+
env: {},
|
|
17
|
+
logger: {
|
|
18
|
+
info() {},
|
|
19
|
+
warn() {},
|
|
20
|
+
error() {},
|
|
21
|
+
debug() {}
|
|
22
|
+
}
|
|
23
|
+
}, u = o.gen(function* () {
|
|
24
|
+
let e = new c(), t = yield* o.promise(() => a(e, "fixture")), { currencies: s, economy: u, ...d } = t.options, f = n({
|
|
25
|
+
currencies: s,
|
|
26
|
+
now: d.now,
|
|
27
|
+
piggyBanks: d
|
|
28
|
+
});
|
|
29
|
+
yield* o.promise(async () => {
|
|
30
|
+
await f.bindDataStore?.(e);
|
|
31
|
+
});
|
|
32
|
+
let p = f.economy.piggyBanks();
|
|
33
|
+
yield* p.fill(r, t.fill("reward.1")), yield* p.fill(r, t.fill("reward.2"));
|
|
34
|
+
let m = (yield* p.list(t.user))[0];
|
|
35
|
+
return Object.freeze({
|
|
36
|
+
store: e,
|
|
37
|
+
base: t,
|
|
38
|
+
plugin: f,
|
|
39
|
+
view: m,
|
|
40
|
+
unlock: i(m),
|
|
41
|
+
close: o.suspend(() => f.onDeactivate?.(l))
|
|
42
|
+
});
|
|
43
|
+
}), d = s.effectContext(o.acquireRelease(u, (e) => e.close).pipe(o.flatMap((e) => s.build(e.plugin.services)))), f = Object.freeze({
|
|
44
|
+
kind: "port",
|
|
45
|
+
tag: e,
|
|
46
|
+
fakeLayer: d,
|
|
47
|
+
probe: {
|
|
48
|
+
run: () => o.scoped(o.gen(function* () {
|
|
49
|
+
let n = yield* e, r = yield* t, a = {
|
|
50
|
+
type: "user",
|
|
51
|
+
id: "a",
|
|
52
|
+
tenantId: "fixture",
|
|
53
|
+
kind: "guest"
|
|
54
|
+
}, o = (yield* n.list(a))[0], s = i(o), c = yield* n.unlock(a, s), l = yield* n.unlock(a, s), u = yield* n.receipt(a, { requestId: s.requestId }), d = (yield* n.list(a))[0], f = yield* r.mine(a);
|
|
55
|
+
return {
|
|
56
|
+
same: c.operationId === l.operationId,
|
|
57
|
+
observed: u.state,
|
|
58
|
+
available: d.available,
|
|
59
|
+
cycles: d.cycles,
|
|
60
|
+
balance: f[0].balance
|
|
61
|
+
};
|
|
62
|
+
}).pipe(o.provide(d))),
|
|
63
|
+
expected: {
|
|
64
|
+
same: !0,
|
|
65
|
+
observed: "fulfilled",
|
|
66
|
+
available: "0",
|
|
67
|
+
cycles: 1,
|
|
68
|
+
balance: "115"
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
export { d as piggyBanksFakeLayer, f as piggyBanksPortSystemFixture, u as piggyPortFixture };
|