@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
package/dist/testing.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { ledgerTransferFixture as e, priceResolverFixture as t, shopOfferFixture as n } from "./declarationFixtures.js";
|
|
2
|
+
import { economyPortFixture as r } from "./economyPort.fixture.js";
|
|
3
|
+
import { economyFakeLayer as i, economyPortSystemFixture as a, priceResolverSystemFixture as o } from "./systemFixtures.js";
|
|
4
|
+
import { containerEligibilitySystemFixture as s, containerFixture as c, containerProbabilitySystemFixture as l, containerRandomFakeLayer as u, containerRandomPortSystemFixture as d, containerRollSystemFixture as f } from "./containers.fixture.js";
|
|
5
|
+
import { experimentBucketSystemFixture as p, offerExperimentFixture as m } from "./offerPolicies.fixture.js";
|
|
6
|
+
import { codeEligibilityFixture as h, codeEligibilitySystemFixture as g, codePortFixture as _, codePortSystemFixture as v, codesFakeLayer as y } from "./codePort.fixture.js";
|
|
7
|
+
import { shopFakeLayer as b, shopPortFixture as x, shopPortSystemFixture as S } from "./shopPort.fixture.js";
|
|
8
|
+
import { containersFakeLayer as C, containersPortFixture as w, containersPortSystemFixture as T } from "./containersPort.fixture.js";
|
|
9
|
+
import { subscriptionDailySystemFixture as E, subscriptionFixture as D, subscriptionPeriodSystemFixture as O } from "./subscriptions.fixture.js";
|
|
10
|
+
import { subscriptionsFakeLayer as k, subscriptionsPortFixture as A, subscriptionsPortSystemFixture as j } from "./subscriptionsPort.fixture.js";
|
|
11
|
+
import { loyaltyFixture as M, loyaltyPerksSystemFixture as N, loyaltyTierSystemFixture as P } from "./loyalty.fixture.js";
|
|
12
|
+
import { loyaltyFakeLayer as F, loyaltyPortFixture as I, loyaltyPortSystemFixture as L } from "./loyaltyPort.fixture.js";
|
|
13
|
+
import { piggyBankFixture as R, piggyFillSystemFixture as z, piggyResetSystemFixture as B } from "./piggyBanks.fixture.js";
|
|
14
|
+
import { piggyBanksFakeLayer as V, piggyBanksPortSystemFixture as H, piggyPortFixture as U } from "./piggyPort.fixture.js";
|
|
15
|
+
import { flashOfferFixture as W, flashTriggerSystemFixture as G, personalizedOfferFixture as K, personalizedSelectorSystemFixture as q } from "./offerMerchandising.fixture.js";
|
|
16
|
+
import { spendLimitFixture as J, spendLimitPolicySystemFixture as Y } from "./spendLimits.fixture.js";
|
|
17
|
+
import { spendLimitsFakeLayer as X, spendLimitsPortFixture as Z, spendLimitsPortSystemFixture as Q } from "./spendLimitsPort.fixture.js";
|
|
18
|
+
import { tradeEligibilitySystemFixture as $, tradeFixture as ee, tradeTaxSystemFixture as te } from "./trades.fixture.js";
|
|
19
|
+
import { tradesFakeLayer as ne, tradesPortFixture as re, tradesPortSystemFixture as ie } from "./tradesPort.fixture.js";
|
|
20
|
+
import { iapFakeLayer as ae, iapPortFixture as oe, iapPortSystemFixture as se, iapSystemPortSystemFixture as ce } from "./iapPort.fixture.js";
|
|
21
|
+
import { iapNotificationFakeLayer as le, iapNotificationPortFixture as ue, iapNotificationPortSystemFixture as de } from "./iapNotificationPort.fixture.js";
|
|
22
|
+
import { iapCurrentStateFakeLayer as fe, iapCurrentStatePortFixture as pe, iapCurrentStatePortSystemFixture as me } from "./iapCurrentStatePort.fixture.js";
|
|
23
|
+
import { iapNotificationCustodyFakeLayer as he, iapNotificationCustodyPortFixture as ge, iapNotificationCustodyPortSystemFixture as _e } from "./iapNotificationCustodyPort.fixture.js";
|
|
24
|
+
import { iapRefundFakeLayer as ve, iapRefundPortFixture as ye, iapRefundPortSystemFixture as be } from "./iapRefundPort.fixture.js";
|
|
25
|
+
import { iapNotificationProcessorFakeLayer as xe, iapNotificationProcessorPortFixture as Se, iapNotificationProcessorPortSystemFixture as Ce } from "./iapNotificationProcessorPort.fixture.js";
|
|
26
|
+
import { iapNotificationsSystemFakeLayer as we, iapNotificationsSystemPortFixture as Te, iapNotificationsSystemPortSystemFixture as Ee } from "./iapNotificationsSystemPort.fixture.js";
|
|
27
|
+
import { iapRefundEventsFakeLayer as De, iapRefundEventsPortFixture as Oe, iapRefundEventsPortSystemFixture as ke } from "./iapRefundEventsPort.fixture.js";
|
|
28
|
+
import { iapEntitlementPolicyFixture as Ae, iapEntitlementPolicySystemFixture as je, iapEntitlementsFakeLayer as Me, iapEntitlementsPortFixture as Ne, iapEntitlementsPortSystemFixture as Pe } from "./iapEntitlementsPort.fixture.js";
|
|
29
|
+
export { h as codeEligibilityFixture, g as codeEligibilitySystemFixture, _ as codePortFixture, v as codePortSystemFixture, y as codesFakeLayer, s as containerEligibilitySystemFixture, c as containerFixture, l as containerProbabilitySystemFixture, u as containerRandomFakeLayer, d as containerRandomPortSystemFixture, f as containerRollSystemFixture, C as containersFakeLayer, w as containersPortFixture, T as containersPortSystemFixture, i as economyFakeLayer, r as economyPortFixture, a as economyPortSystemFixture, p as experimentBucketSystemFixture, W as flashOfferFixture, G as flashTriggerSystemFixture, fe as iapCurrentStateFakeLayer, pe as iapCurrentStatePortFixture, me as iapCurrentStatePortSystemFixture, Ae as iapEntitlementPolicyFixture, je as iapEntitlementPolicySystemFixture, Me as iapEntitlementsFakeLayer, Ne as iapEntitlementsPortFixture, Pe as iapEntitlementsPortSystemFixture, ae as iapFakeLayer, he as iapNotificationCustodyFakeLayer, ge as iapNotificationCustodyPortFixture, _e as iapNotificationCustodyPortSystemFixture, le as iapNotificationFakeLayer, ue as iapNotificationPortFixture, de as iapNotificationPortSystemFixture, xe as iapNotificationProcessorFakeLayer, Se as iapNotificationProcessorPortFixture, Ce as iapNotificationProcessorPortSystemFixture, we as iapNotificationsSystemFakeLayer, Te as iapNotificationsSystemPortFixture, Ee as iapNotificationsSystemPortSystemFixture, oe as iapPortFixture, se as iapPortSystemFixture, De as iapRefundEventsFakeLayer, Oe as iapRefundEventsPortFixture, ke as iapRefundEventsPortSystemFixture, ve as iapRefundFakeLayer, ye as iapRefundPortFixture, be as iapRefundPortSystemFixture, ce as iapSystemPortSystemFixture, e as ledgerTransferFixture, F as loyaltyFakeLayer, M as loyaltyFixture, N as loyaltyPerksSystemFixture, I as loyaltyPortFixture, L as loyaltyPortSystemFixture, P as loyaltyTierSystemFixture, m as offerExperimentFixture, K as personalizedOfferFixture, q as personalizedSelectorSystemFixture, R as piggyBankFixture, V as piggyBanksFakeLayer, H as piggyBanksPortSystemFixture, z as piggyFillSystemFixture, U as piggyPortFixture, B as piggyResetSystemFixture, t as priceResolverFixture, o as priceResolverSystemFixture, b as shopFakeLayer, n as shopOfferFixture, x as shopPortFixture, S as shopPortSystemFixture, J as spendLimitFixture, Y as spendLimitPolicySystemFixture, X as spendLimitsFakeLayer, Z as spendLimitsPortFixture, Q as spendLimitsPortSystemFixture, E as subscriptionDailySystemFixture, D as subscriptionFixture, O as subscriptionPeriodSystemFixture, k as subscriptionsFakeLayer, A as subscriptionsPortFixture, j as subscriptionsPortSystemFixture, $ as tradeEligibilitySystemFixture, ee as tradeFixture, te as tradeTaxSystemFixture, ne as tradesFakeLayer, re as tradesPortFixture, ie as tradesPortSystemFixture };
|
|
@@ -0,0 +1,171 @@
|
|
|
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 { shopInteger as a } from "./shop.js";
|
|
4
|
+
import { captureTradeParticipantAuthority as o } from "./trades.js";
|
|
5
|
+
import { Effect as s } from "effect";
|
|
6
|
+
import { systemSubject as c } from "@voltro/protocol";
|
|
7
|
+
import { prepareSqlMutationGroup as l } from "@voltro/database/sql";
|
|
8
|
+
import { defineItem as u } from "@voltro/plugin-inventory/items";
|
|
9
|
+
// src/tradeAuthority.server.ts
|
|
10
|
+
var d = (e) => a(e, 0, 864e13), f = (e) => {
|
|
11
|
+
let t = r(e, [
|
|
12
|
+
"tenantId",
|
|
13
|
+
"ownerId",
|
|
14
|
+
"tradeId",
|
|
15
|
+
"at"
|
|
16
|
+
]);
|
|
17
|
+
return Object.freeze({
|
|
18
|
+
tenantId: i(t.tenantId),
|
|
19
|
+
ownerId: i(t.ownerId),
|
|
20
|
+
tradeId: i(t.tradeId),
|
|
21
|
+
at: d(t.at)
|
|
22
|
+
});
|
|
23
|
+
}, p = (t, n, i) => {
|
|
24
|
+
let o = r(t, [
|
|
25
|
+
"tenantId",
|
|
26
|
+
"ownerId",
|
|
27
|
+
"allowed",
|
|
28
|
+
"trustScore"
|
|
29
|
+
], "invalid_record");
|
|
30
|
+
if (o.tenantId !== n || o.ownerId !== i || typeof o.allowed != "boolean") throw e("invalid_record");
|
|
31
|
+
return Object.freeze({
|
|
32
|
+
tenantId: n,
|
|
33
|
+
ownerId: i,
|
|
34
|
+
allowed: o.allowed,
|
|
35
|
+
trustScore: a(o.trustScore, 0, 1e6)
|
|
36
|
+
});
|
|
37
|
+
}, m = (t) => {
|
|
38
|
+
let a = r(t, [
|
|
39
|
+
"tenantId",
|
|
40
|
+
"tradeId",
|
|
41
|
+
"phase",
|
|
42
|
+
"at",
|
|
43
|
+
"expiresAt",
|
|
44
|
+
"participants"
|
|
45
|
+
]), s = i(a.tenantId), c = i(a.tradeId), l = d(a.at), u = d(a.expiresAt);
|
|
46
|
+
if (a.phase !== "propose" && a.phase !== "accept" || l >= u) throw e("invalid_input");
|
|
47
|
+
let f = Object.freeze(n(a.participants, 2).map((e) => {
|
|
48
|
+
let t = r(e, [
|
|
49
|
+
"tenantId",
|
|
50
|
+
"ownerId",
|
|
51
|
+
"allowed",
|
|
52
|
+
"trustScore",
|
|
53
|
+
"items"
|
|
54
|
+
], "invalid_record");
|
|
55
|
+
return o(e, s, i(t.ownerId));
|
|
56
|
+
}));
|
|
57
|
+
if (f.length !== (a.phase === "propose" ? 1 : 2) || new Set(f.map((e) => e.ownerId)).size !== f.length) throw e("invalid_input");
|
|
58
|
+
return Object.freeze({
|
|
59
|
+
tenantId: s,
|
|
60
|
+
tradeId: c,
|
|
61
|
+
phase: a.phase,
|
|
62
|
+
at: l,
|
|
63
|
+
expiresAt: u,
|
|
64
|
+
participants: f
|
|
65
|
+
});
|
|
66
|
+
}, h = (t) => {
|
|
67
|
+
try {
|
|
68
|
+
return t();
|
|
69
|
+
} catch {
|
|
70
|
+
return s.fail(e("invalid_input"));
|
|
71
|
+
}
|
|
72
|
+
}, g = (g, _) => {
|
|
73
|
+
let v = r(_, [
|
|
74
|
+
"permissions",
|
|
75
|
+
"inventory",
|
|
76
|
+
"items"
|
|
77
|
+
]), y = t(v.permissions, ["read", "prepare"]), b = t(v.inventory, ["mine", "reservationEvidence"]), x = n(v.items, 1e4).map((e) => u(e)), S = new Map(x.map((e) => [JSON.stringify([e.id, e.schemaVersion]), e]));
|
|
78
|
+
if (S.size !== x.length) throw e("invalid_input");
|
|
79
|
+
let C = c("economy.trade-authority");
|
|
80
|
+
return Object.freeze({
|
|
81
|
+
read: (t) => h(() => {
|
|
82
|
+
let c = f(t);
|
|
83
|
+
return s.gen(function* () {
|
|
84
|
+
let t = p(yield* y.read(c), c.tenantId, c.ownerId), l = yield* b.mine({
|
|
85
|
+
type: "user",
|
|
86
|
+
id: c.ownerId,
|
|
87
|
+
tenantId: c.tenantId
|
|
88
|
+
}).pipe(s.mapError(() => e("unavailable"))), u = yield* b.reservationEvidence(C, {
|
|
89
|
+
tenantId: c.tenantId,
|
|
90
|
+
owner: {
|
|
91
|
+
ownerKind: "player",
|
|
92
|
+
ownerId: c.ownerId
|
|
93
|
+
},
|
|
94
|
+
reservationId: c.tradeId
|
|
95
|
+
}).pipe(s.mapError(() => e("unavailable"))), f = r(u, [
|
|
96
|
+
"reservationId",
|
|
97
|
+
"state",
|
|
98
|
+
"items",
|
|
99
|
+
"reserve",
|
|
100
|
+
"release",
|
|
101
|
+
"transfer"
|
|
102
|
+
], "invalid_record");
|
|
103
|
+
if (f.reservationId !== c.tradeId || ![
|
|
104
|
+
"not-observed",
|
|
105
|
+
"reserved",
|
|
106
|
+
"released",
|
|
107
|
+
"transferred"
|
|
108
|
+
].includes(String(f.state))) throw e("invalid_record");
|
|
109
|
+
let m = /* @__PURE__ */ new Set();
|
|
110
|
+
for (let t of n(f.items, 32, "invalid_record")) {
|
|
111
|
+
let n = r(t, ["qty", "instance"], "invalid_record"), o = r(n.instance, [
|
|
112
|
+
"id",
|
|
113
|
+
"itemId",
|
|
114
|
+
"schemaVersion",
|
|
115
|
+
"qty",
|
|
116
|
+
"attributes",
|
|
117
|
+
"acquiredAt",
|
|
118
|
+
"expiresAt",
|
|
119
|
+
"locked",
|
|
120
|
+
"source"
|
|
121
|
+
], "invalid_record"), s = i(o.id), c = a(n.qty, 1, 1e6);
|
|
122
|
+
if (m.has(s) || c > a(o.qty, 1, 1e6)) throw e("invalid_record");
|
|
123
|
+
m.add(s);
|
|
124
|
+
}
|
|
125
|
+
let h = n(l, 1e4, "invalid_record").map((t) => {
|
|
126
|
+
let n = r(t, [
|
|
127
|
+
"id",
|
|
128
|
+
"itemId",
|
|
129
|
+
"schemaVersion",
|
|
130
|
+
"qty",
|
|
131
|
+
"attributes",
|
|
132
|
+
"acquiredAt",
|
|
133
|
+
"expiresAt",
|
|
134
|
+
"locked",
|
|
135
|
+
"source"
|
|
136
|
+
], "invalid_record"), o = i(n.id), s = i(n.itemId), l = a(n.schemaVersion, 1, 1e6), u = S.get(JSON.stringify([s, l])), p = a(n.qty, 1, 1e6), h = d(n.acquiredAt), g = n.expiresAt === null ? null : d(n.expiresAt);
|
|
137
|
+
if (!u || p > u.maxStack || typeof n.locked != "boolean" || h > c.at || g !== null && g <= h) throw e("invalid_record");
|
|
138
|
+
return Object.freeze({
|
|
139
|
+
instanceId: o,
|
|
140
|
+
itemId: s,
|
|
141
|
+
qty: p,
|
|
142
|
+
tradable: u.tradable,
|
|
143
|
+
locked: n.locked,
|
|
144
|
+
reservationId: n.locked && f.state === "reserved" && m.has(o) ? c.tradeId : null,
|
|
145
|
+
expiresAt: g
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
return o({
|
|
149
|
+
...t,
|
|
150
|
+
items: h
|
|
151
|
+
}, c.tenantId, c.ownerId);
|
|
152
|
+
}).pipe(s.catchDefect(() => s.fail(e("invalid_record"))));
|
|
153
|
+
}),
|
|
154
|
+
prepare: (t) => h(() => {
|
|
155
|
+
let n = m(t), r = Object.freeze({
|
|
156
|
+
...n,
|
|
157
|
+
participants: Object.freeze(n.participants.map((e) => p({
|
|
158
|
+
tenantId: e.tenantId,
|
|
159
|
+
ownerId: e.ownerId,
|
|
160
|
+
allowed: e.allowed,
|
|
161
|
+
trustScore: e.trustScore
|
|
162
|
+
}, n.tenantId, e.ownerId)))
|
|
163
|
+
});
|
|
164
|
+
return r.participants.some((e) => !e.allowed) ? s.fail(e("forbidden")) : y.prepare(r).pipe(s.flatMap((t) => s.try({
|
|
165
|
+
try: () => l(g, [t], async () => {}),
|
|
166
|
+
catch: () => e("invalid_record")
|
|
167
|
+
})));
|
|
168
|
+
})
|
|
169
|
+
});
|
|
170
|
+
};
|
|
171
|
+
export { m as captureTradeAuthorityAdmission, f as captureTradeAuthorityRead, g as inventoryTradeAuthoritySource };
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { EconomyError as e, economyError as t } from "./errors.js";
|
|
2
|
+
import { captureQueryTables as n, dataObject as r, declaredSources as i, identifier as a } from "./capture.js";
|
|
3
|
+
import { TradesPort as o, captureTradeProposeIntention as s, captureTradesService as c, defaultTradeEligibilityPolicy as l, defaultTradeTaxPolicy as u, defineTradeRules as d, tradeAcceptIntent as f, tradeCancelIntent as p } from "./trades.js";
|
|
4
|
+
import { tradeAcceptDescriptor as m, tradeCancelDescriptor as h, tradeProposeDescriptor as g, tradeReceiptDescriptor as _, tradesMineDescriptor as v, tradesRpcClientImports as y } from "./rpc.js";
|
|
5
|
+
import { captureTradeExpiryInput as b } from "./tradeExpiry.server.js";
|
|
6
|
+
import { tradeTables as x } from "./tradeTables.entity.js";
|
|
7
|
+
import { dataStoreTrades as S, resolveTradeStoreOptions as C } from "./tradeStore.server.js";
|
|
8
|
+
import { Effect as w, Layer as T } from "effect";
|
|
9
|
+
// src/tradeBinding.server.ts
|
|
10
|
+
var E = () => w.fail(t("unavailable")), D = Object.freeze({
|
|
11
|
+
propose: E,
|
|
12
|
+
accept: E,
|
|
13
|
+
cancel: E,
|
|
14
|
+
mine: E,
|
|
15
|
+
receipt: E,
|
|
16
|
+
rebuild: E,
|
|
17
|
+
exportSubject: E,
|
|
18
|
+
eraseSubject: E
|
|
19
|
+
}), O = (E, D) => {
|
|
20
|
+
if (E === void 0) return;
|
|
21
|
+
let O = r(E, [
|
|
22
|
+
"rules",
|
|
23
|
+
"taxPolicy",
|
|
24
|
+
"inventory",
|
|
25
|
+
"allowedServices",
|
|
26
|
+
"authority",
|
|
27
|
+
"eligibility",
|
|
28
|
+
"maxHistoryRows",
|
|
29
|
+
"now",
|
|
30
|
+
"service",
|
|
31
|
+
"querySources"
|
|
32
|
+
]), k = O.service === void 0 ? void 0 : c(O.service);
|
|
33
|
+
if (D.replacedWallet && !k || k && [
|
|
34
|
+
"taxPolicy",
|
|
35
|
+
"inventory",
|
|
36
|
+
"allowedServices",
|
|
37
|
+
"authority",
|
|
38
|
+
"eligibility",
|
|
39
|
+
"maxHistoryRows",
|
|
40
|
+
"now"
|
|
41
|
+
].some((e) => O[e] !== void 0)) throw t("invalid_input");
|
|
42
|
+
let A = d(O.rules), j = O.querySources === void 0 ? void 0 : r(O.querySources, ["mine", "receipt"]);
|
|
43
|
+
if (k && !j) throw t("invalid_input");
|
|
44
|
+
let M = j ? Object.freeze({
|
|
45
|
+
mine: n(j.mine),
|
|
46
|
+
receipt: n(j.receipt)
|
|
47
|
+
}) : void 0, N = k ? void 0 : C({
|
|
48
|
+
currencies: D.currencies,
|
|
49
|
+
rules: A,
|
|
50
|
+
economy: D.economy,
|
|
51
|
+
inventory: O.inventory,
|
|
52
|
+
authority: O.authority,
|
|
53
|
+
taxPolicy: O.taxPolicy,
|
|
54
|
+
eligibility: O.eligibility,
|
|
55
|
+
allowedServices: O.allowedServices ?? D.allowedServices,
|
|
56
|
+
now: O.now ?? D.now,
|
|
57
|
+
maxHistoryRows: O.maxHistoryRows
|
|
58
|
+
}), P = new Set(N?.allowedServices ?? D.allowedServices), F, I = !1, L, R = (e) => w.suspend(() => {
|
|
59
|
+
let n = k ?? F;
|
|
60
|
+
return I && n ? e(n) : w.fail(t("unavailable"));
|
|
61
|
+
}), z = (n) => {
|
|
62
|
+
try {
|
|
63
|
+
return n();
|
|
64
|
+
} catch (n) {
|
|
65
|
+
return w.fail(n instanceof e ? n : t("invalid_input"));
|
|
66
|
+
}
|
|
67
|
+
}, B = (e) => {
|
|
68
|
+
let n = structuredClone(e);
|
|
69
|
+
if (n.type !== "user") throw t("forbidden");
|
|
70
|
+
return a(n.id), a(n.tenantId), n;
|
|
71
|
+
}, V = (e) => {
|
|
72
|
+
let n = structuredClone(e);
|
|
73
|
+
if (n.type !== "system" && (n.type !== "service" || !P.has(n.service))) throw t("forbidden");
|
|
74
|
+
return n;
|
|
75
|
+
}, H = (e) => {
|
|
76
|
+
let n = r(e, [
|
|
77
|
+
"tenantId",
|
|
78
|
+
"subjectId",
|
|
79
|
+
"kind"
|
|
80
|
+
]);
|
|
81
|
+
if (n.kind !== "guest" && n.kind !== "user") throw t("invalid_input");
|
|
82
|
+
return Object.freeze({
|
|
83
|
+
tenantId: a(n.tenantId),
|
|
84
|
+
subjectId: a(n.subjectId),
|
|
85
|
+
kind: n.kind
|
|
86
|
+
});
|
|
87
|
+
}, U = (e) => {
|
|
88
|
+
let t = r(e, ["tenantId", "tradeId"]);
|
|
89
|
+
return Object.freeze({
|
|
90
|
+
tenantId: a(t.tenantId),
|
|
91
|
+
tradeId: a(t.tradeId)
|
|
92
|
+
});
|
|
93
|
+
}, W = Object.freeze({
|
|
94
|
+
propose: (e, t) => z(() => {
|
|
95
|
+
let n = B(e), r = s(t);
|
|
96
|
+
return R((e) => e.propose(n, r));
|
|
97
|
+
}),
|
|
98
|
+
accept: (e, t) => z(() => {
|
|
99
|
+
let n = B(e), r = f(t);
|
|
100
|
+
return R((e) => e.accept(n, r));
|
|
101
|
+
}),
|
|
102
|
+
cancel: (e, t) => z(() => {
|
|
103
|
+
let n = B(e), r = p(t);
|
|
104
|
+
return R((e) => e.cancel(n, r));
|
|
105
|
+
}),
|
|
106
|
+
mine: (e) => z(() => {
|
|
107
|
+
let t = B(e);
|
|
108
|
+
return R((e) => e.mine(t));
|
|
109
|
+
}),
|
|
110
|
+
receipt: (e, t) => z(() => {
|
|
111
|
+
let n = B(e), i = r(t, ["requestId"]), o = Object.freeze({ requestId: a(i.requestId) });
|
|
112
|
+
return R((e) => e.receipt(n, o));
|
|
113
|
+
}),
|
|
114
|
+
rebuild: (e, t) => z(() => {
|
|
115
|
+
let n = V(e), r = U(t);
|
|
116
|
+
return R((e) => e.rebuild(n, r));
|
|
117
|
+
}),
|
|
118
|
+
exportSubject: (e) => z(() => {
|
|
119
|
+
let t = H(e);
|
|
120
|
+
return R((e) => e.exportSubject(t));
|
|
121
|
+
}),
|
|
122
|
+
eraseSubject: (e) => z(() => {
|
|
123
|
+
let t = H(e);
|
|
124
|
+
return R((e) => e.eraseSubject(t));
|
|
125
|
+
})
|
|
126
|
+
}), G = (e, n) => z(() => {
|
|
127
|
+
let r = V(e), i = U(n);
|
|
128
|
+
return w.suspend(() => I && F && !k ? F.expire(r, i) : w.fail(t("unavailable")));
|
|
129
|
+
}), K = (e, n) => z(() => {
|
|
130
|
+
let r = V(e), i = b(n);
|
|
131
|
+
return w.suspend(() => I && F && !k ? F.expireDue(r, i) : w.fail(t("unavailable")));
|
|
132
|
+
}), q = (e, t) => k ? M[e] : [.../* @__PURE__ */ new Set([...t.filter((e) => N?.inventory !== void 0 || !e.startsWith("voltro_inv_")), ...M?.[e] ?? []])], J = [
|
|
133
|
+
{
|
|
134
|
+
...v,
|
|
135
|
+
source: q("mine", i(v.source)),
|
|
136
|
+
execute: (e, t) => W.mine(t.request.subject)
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
..._,
|
|
140
|
+
source: q("receipt", i(_.source)),
|
|
141
|
+
execute: (e, t) => W.receipt(t.request.subject, e)
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
...g,
|
|
145
|
+
execute: (e, t) => W.propose(t.request.subject, e)
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
...m,
|
|
149
|
+
execute: (e, t) => W.accept(t.request.subject, e)
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
...h,
|
|
153
|
+
execute: (e, t) => W.cancel(t.request.subject, e)
|
|
154
|
+
}
|
|
155
|
+
], Y = Object.freeze({
|
|
156
|
+
backend: k ? "custom" : "sql",
|
|
157
|
+
version: A.version,
|
|
158
|
+
rules: Object.freeze({
|
|
159
|
+
taxBps: A.taxBps,
|
|
160
|
+
maxDurationMs: A.maxDurationMs,
|
|
161
|
+
minTrustScore: A.minTrustScore
|
|
162
|
+
}),
|
|
163
|
+
slots: Object.freeze({
|
|
164
|
+
eligibility: k || N?.eligibility !== l ? "custom" : "default",
|
|
165
|
+
tax: k || N?.taxPolicy !== u ? "custom" : "default"
|
|
166
|
+
}),
|
|
167
|
+
authoritySource: k ? "app-owned" : "custom",
|
|
168
|
+
itemParticipant: k ? "app-owned" : N?.inventory ? "prepared-sql" : "none",
|
|
169
|
+
budgets: k ? null : Object.freeze({ historyRows: N.maxHistoryRows }),
|
|
170
|
+
virtualExchangeInstalled: !0,
|
|
171
|
+
automaticExpiryInstalled: !1,
|
|
172
|
+
marketplaceInstalled: !1,
|
|
173
|
+
clientRecoveryInstalled: !1,
|
|
174
|
+
gmActionsInstalled: !1
|
|
175
|
+
});
|
|
176
|
+
return Object.freeze({
|
|
177
|
+
service: W,
|
|
178
|
+
expire: G,
|
|
179
|
+
expireDue: K,
|
|
180
|
+
layer: T.succeed(o, W),
|
|
181
|
+
tables: N ? x : [],
|
|
182
|
+
routes: J,
|
|
183
|
+
status: Y,
|
|
184
|
+
rpcClientDescriptors: y,
|
|
185
|
+
roles: N ? [
|
|
186
|
+
"tradeTenants",
|
|
187
|
+
"tradeSubjects",
|
|
188
|
+
"trades",
|
|
189
|
+
"tradeOperations"
|
|
190
|
+
] : [],
|
|
191
|
+
bind: (e) => {
|
|
192
|
+
if (L !== void 0 && L !== e) throw Error("Trade system cannot cross app stores");
|
|
193
|
+
L = e, N && (F = S(e, N)), I = !0;
|
|
194
|
+
},
|
|
195
|
+
deactivate: () => {
|
|
196
|
+
I = !1, F = void 0;
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
};
|
|
200
|
+
export { O as bindTradesSystem, D as unavailableTrades };
|