@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.
Files changed (177) hide show
  1. package/CHANGELOG.md +24492 -0
  2. package/LICENSE +61 -0
  3. package/README.md +2719 -2
  4. package/SECURITY.md +56 -0
  5. package/THIRD-PARTY-NOTICES.md +9841 -0
  6. package/dist/amount.js +20 -0
  7. package/dist/appleIap.server.js +262 -0
  8. package/dist/appleIapNotifications.server.js +162 -0
  9. package/dist/appleIapTrust.server.js +30 -0
  10. package/dist/bundleValue.server.js +112 -0
  11. package/dist/canonicalDataJson.js +10 -0
  12. package/dist/capture.js +53 -0
  13. package/dist/codePort.fixture.js +123 -0
  14. package/dist/codeStore.server.js +439 -0
  15. package/dist/codeTables.entity.js +43 -0
  16. package/dist/codes.d.ts +150 -0
  17. package/dist/codes.js +82 -0
  18. package/dist/components.d.ts +397 -0
  19. package/dist/components.js +283 -0
  20. package/dist/consistency.server.js +115 -0
  21. package/dist/containerStore.server.js +687 -0
  22. package/dist/containerStore.testFixtures.js +75 -0
  23. package/dist/containerTables.entity.js +45 -0
  24. package/dist/containers.d.ts +311 -0
  25. package/dist/containers.fixture.js +128 -0
  26. package/dist/containers.js +214 -0
  27. package/dist/containers.server.js +39 -0
  28. package/dist/containersPort.fixture.js +74 -0
  29. package/dist/currency.js +32 -0
  30. package/dist/declarationFixtures.js +61 -0
  31. package/dist/economy-app/events/economy.refundReversed.event.ts +1 -0
  32. package/dist/economy-app/events/economy.refunded.event.ts +1 -0
  33. package/dist/economyPort.fixture.js +124 -0
  34. package/dist/errors.d.ts +14 -0
  35. package/dist/errors.js +21 -0
  36. package/dist/events.d.ts +46 -0
  37. package/dist/events.js +1 -0
  38. package/dist/googleIap.server.js +391 -0
  39. package/dist/googleIapNotifications.server.js +130 -0
  40. package/dist/googleIapSubscription.server.js +183 -0
  41. package/dist/iap.d.ts +309 -0
  42. package/dist/iap.js +303 -0
  43. package/dist/iap.testFixtures.js +144 -0
  44. package/dist/iapAccountTables.entity.js +39 -0
  45. package/dist/iapAccounts.server.js +200 -0
  46. package/dist/iapBinding.server.js +523 -0
  47. package/dist/iapCheckout.server.js +97 -0
  48. package/dist/iapCompletion.server.js +55 -0
  49. package/dist/iapCurrentState.server.js +107 -0
  50. package/dist/iapCurrentState.testFixtures.js +22 -0
  51. package/dist/iapCurrentStatePort.fixture.js +63 -0
  52. package/dist/iapEntitlements.d.ts +79 -0
  53. package/dist/iapEntitlements.js +57 -0
  54. package/dist/iapEntitlements.server.js +48 -0
  55. package/dist/iapEntitlementsBinding.server.js +105 -0
  56. package/dist/iapEntitlementsPort.fixture.js +80 -0
  57. package/dist/iapInstalledEntitlements.testFixtures.js +75 -0
  58. package/dist/iapInstalledNotifications.testFixtures.js +93 -0
  59. package/dist/iapInventoryRefunds.server.js +261 -0
  60. package/dist/iapNotificationCustodyPort.fixture.js +67 -0
  61. package/dist/iapNotificationPort.fixture.js +73 -0
  62. package/dist/iapNotificationProcessor.server.js +134 -0
  63. package/dist/iapNotificationProcessor.testFixtures.js +63 -0
  64. package/dist/iapNotificationProcessorPort.fixture.js +55 -0
  65. package/dist/iapNotificationSchedule.server.js +69 -0
  66. package/dist/iapNotificationStore.server.js +352 -0
  67. package/dist/iapNotificationStore.testFixtures.js +31 -0
  68. package/dist/iapNotificationTables.entity.js +48 -0
  69. package/dist/iapNotificationTarget.server.js +36 -0
  70. package/dist/iapNotificationTarget.testFixtures.js +29 -0
  71. package/dist/iapNotifications.d.ts +644 -0
  72. package/dist/iapNotifications.js +6 -0
  73. package/dist/iapNotifications.server.js +95 -0
  74. package/dist/iapNotificationsBinding.server.js +232 -0
  75. package/dist/iapNotificationsSystemPort.fixture.js +50 -0
  76. package/dist/iapPlugin.testFixtures.js +59 -0
  77. package/dist/iapPort.fixture.js +74 -0
  78. package/dist/iapProviderCapture.server.js +17 -0
  79. package/dist/iapRecovery.d.ts +146 -0
  80. package/dist/iapRecovery.js +89 -0
  81. package/dist/iapRefundEventDelivery.server.js +82 -0
  82. package/dist/iapRefundEvents.js +44 -0
  83. package/dist/iapRefundEventsPort.fixture.js +59 -0
  84. package/dist/iapRefundPort.fixture.js +54 -0
  85. package/dist/iapRefundTables.entity.js +55 -0
  86. package/dist/iapRefunds.d.ts +755 -0
  87. package/dist/iapRefunds.js +6 -0
  88. package/dist/iapRefunds.server.js +553 -0
  89. package/dist/iapRefunds.testFixtures.js +64 -0
  90. package/dist/iapSpendAdmission.server.js +98 -0
  91. package/dist/iapStore.server.js +740 -0
  92. package/dist/iapStore.testFixtures.js +127 -0
  93. package/dist/iapTables.entity.js +80 -0
  94. package/dist/iapVerification.server.js +120 -0
  95. package/dist/index.d.ts +2984 -0
  96. package/dist/index.js +15 -0
  97. package/dist/intentionRecovery.js +133 -0
  98. package/dist/ledger.js +77 -0
  99. package/dist/loyalty.d.ts +274 -0
  100. package/dist/loyalty.fixture.js +92 -0
  101. package/dist/loyalty.js +311 -0
  102. package/dist/loyaltyBinding.server.js +203 -0
  103. package/dist/loyaltyPort.fixture.js +86 -0
  104. package/dist/loyaltyShopSource.server.js +90 -0
  105. package/dist/loyaltyStore.server.js +552 -0
  106. package/dist/loyaltyStore.testFixtures.js +82 -0
  107. package/dist/loyaltyTables.entity.js +49 -0
  108. package/dist/offerMerchandising.fixture.js +114 -0
  109. package/dist/offerMerchandising.js +282 -0
  110. package/dist/offerPolicies.d.ts +441 -0
  111. package/dist/offerPolicies.fixture.js +53 -0
  112. package/dist/offerPolicies.js +267 -0
  113. package/dist/piggyBanks.d.ts +272 -0
  114. package/dist/piggyBanks.fixture.js +70 -0
  115. package/dist/piggyBanks.js +200 -0
  116. package/dist/piggyBinding.server.js +204 -0
  117. package/dist/piggyPort.fixture.js +72 -0
  118. package/dist/piggyStore.server.js +610 -0
  119. package/dist/piggyStore.testFixtures.js +97 -0
  120. package/dist/piggyTables.entity.js +40 -0
  121. package/dist/plugin.js +1047 -0
  122. package/dist/port.js +12 -0
  123. package/dist/price.d.ts +99 -0
  124. package/dist/price.js +143 -0
  125. package/dist/purchaseRecovery.js +55 -0
  126. package/dist/reports.server.js +114 -0
  127. package/dist/rpc.d.ts +3201 -0
  128. package/dist/rpc.js +1200 -0
  129. package/dist/sanctionsTradeAuthority.server.js +79 -0
  130. package/dist/server.d.ts +3856 -0
  131. package/dist/server.js +43 -0
  132. package/dist/shop.d.ts +279 -0
  133. package/dist/shop.js +195 -0
  134. package/dist/shop.testFixtures.js +113 -0
  135. package/dist/shopPort.fixture.js +71 -0
  136. package/dist/shopPresentation.js +67 -0
  137. package/dist/shopStore.server.js +623 -0
  138. package/dist/shopTables.entity.js +62 -0
  139. package/dist/shopUiCopy.js +56 -0
  140. package/dist/spendLimits.d.ts +140 -0
  141. package/dist/spendLimits.fixture.js +52 -0
  142. package/dist/spendLimits.js +154 -0
  143. package/dist/spendLimitsPort.fixture.js +119 -0
  144. package/dist/subscriptionBinding.server.js +210 -0
  145. package/dist/subscriptionStore.server.js +642 -0
  146. package/dist/subscriptionStore.testFixtures.js +71 -0
  147. package/dist/subscriptionTables.entity.js +36 -0
  148. package/dist/subscriptions.d.ts +394 -0
  149. package/dist/subscriptions.fixture.js +96 -0
  150. package/dist/subscriptions.js +212 -0
  151. package/dist/subscriptionsPort.fixture.js +75 -0
  152. package/dist/systemFixtures.js +88 -0
  153. package/dist/tables.entity.js +82 -0
  154. package/dist/testing.d.ts +4615 -0
  155. package/dist/testing.js +29 -0
  156. package/dist/tradeAuthority.server.js +171 -0
  157. package/dist/tradeBinding.server.js +200 -0
  158. package/dist/tradeComponents.js +341 -0
  159. package/dist/tradeEscrow.server.js +231 -0
  160. package/dist/tradeEscrow.testFixtures.js +132 -0
  161. package/dist/tradeExpiry.server.js +42 -0
  162. package/dist/tradeRecovery.js +47 -0
  163. package/dist/tradeStore.server.js +749 -0
  164. package/dist/tradeStore.testFixtures.js +72 -0
  165. package/dist/tradeTables.entity.js +65 -0
  166. package/dist/tradeUiCopy.js +78 -0
  167. package/dist/trades.d.ts +246 -0
  168. package/dist/trades.fixture.js +102 -0
  169. package/dist/trades.js +288 -0
  170. package/dist/tradesPort.fixture.js +93 -0
  171. package/dist/walletEscrow.js +105 -0
  172. package/dist/walletEscrow.server.js +375 -0
  173. package/dist/walletKeys.server.js +4 -0
  174. package/dist/walletStore.js +570 -0
  175. package/dist/web.d.ts +2257 -0
  176. package/dist/web.js +8 -0
  177. 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 };