@voltro/plugin-economy 0.0.0-stage → 0.87.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 +24329 -0
- package/LICENSE +61 -0
- package/README.md +2719 -2
- package/SECURITY.md +56 -0
- package/THIRD-PARTY-NOTICES.md +9189 -0
- package/dist/amount.js +21 -0
- package/dist/appleIap.server.js +263 -0
- package/dist/appleIapNotifications.server.js +163 -0
- package/dist/appleIapTrust.server.js +31 -0
- package/dist/bundleValue.server.js +113 -0
- package/dist/canonicalDataJson.js +11 -0
- package/dist/capture.js +54 -0
- package/dist/codePort.fixture.js +124 -0
- package/dist/codeStore.server.js +440 -0
- package/dist/codeTables.entity.js +44 -0
- package/dist/codes.d.ts +150 -0
- package/dist/codes.js +83 -0
- package/dist/components.d.ts +397 -0
- package/dist/components.js +284 -0
- package/dist/consistency.server.js +116 -0
- package/dist/containerStore.server.js +688 -0
- package/dist/containerStore.testFixtures.js +76 -0
- package/dist/containerTables.entity.js +46 -0
- package/dist/containers.d.ts +311 -0
- package/dist/containers.fixture.js +129 -0
- package/dist/containers.js +215 -0
- package/dist/containers.server.js +40 -0
- package/dist/containersPort.fixture.js +75 -0
- package/dist/currency.js +33 -0
- package/dist/declarationFixtures.js +62 -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 +125 -0
- package/dist/errors.d.ts +14 -0
- package/dist/errors.js +22 -0
- package/dist/events.d.ts +46 -0
- package/dist/events.js +1 -0
- package/dist/googleIap.server.js +392 -0
- package/dist/googleIapNotifications.server.js +131 -0
- package/dist/googleIapSubscription.server.js +184 -0
- package/dist/iap.d.ts +309 -0
- package/dist/iap.js +304 -0
- package/dist/iap.testFixtures.js +145 -0
- package/dist/iapAccountTables.entity.js +40 -0
- package/dist/iapAccounts.server.js +201 -0
- package/dist/iapBinding.server.js +524 -0
- package/dist/iapCheckout.server.js +98 -0
- package/dist/iapCompletion.server.js +56 -0
- package/dist/iapCurrentState.server.js +108 -0
- package/dist/iapCurrentState.testFixtures.js +23 -0
- package/dist/iapCurrentStatePort.fixture.js +64 -0
- package/dist/iapEntitlements.d.ts +79 -0
- package/dist/iapEntitlements.js +58 -0
- package/dist/iapEntitlements.server.js +49 -0
- package/dist/iapEntitlementsBinding.server.js +106 -0
- package/dist/iapEntitlementsPort.fixture.js +81 -0
- package/dist/iapInstalledEntitlements.testFixtures.js +76 -0
- package/dist/iapInstalledNotifications.testFixtures.js +94 -0
- package/dist/iapInventoryRefunds.server.js +262 -0
- package/dist/iapNotificationCustodyPort.fixture.js +68 -0
- package/dist/iapNotificationPort.fixture.js +74 -0
- package/dist/iapNotificationProcessor.server.js +135 -0
- package/dist/iapNotificationProcessor.testFixtures.js +64 -0
- package/dist/iapNotificationProcessorPort.fixture.js +56 -0
- package/dist/iapNotificationSchedule.server.js +70 -0
- package/dist/iapNotificationStore.server.js +353 -0
- package/dist/iapNotificationStore.testFixtures.js +32 -0
- package/dist/iapNotificationTables.entity.js +49 -0
- package/dist/iapNotificationTarget.server.js +37 -0
- package/dist/iapNotificationTarget.testFixtures.js +30 -0
- package/dist/iapNotifications.d.ts +644 -0
- package/dist/iapNotifications.js +6 -0
- package/dist/iapNotifications.server.js +96 -0
- package/dist/iapNotificationsBinding.server.js +233 -0
- package/dist/iapNotificationsSystemPort.fixture.js +51 -0
- package/dist/iapPlugin.testFixtures.js +60 -0
- package/dist/iapPort.fixture.js +75 -0
- package/dist/iapProviderCapture.server.js +18 -0
- package/dist/iapRecovery.d.ts +146 -0
- package/dist/iapRecovery.js +90 -0
- package/dist/iapRefundEventDelivery.server.js +83 -0
- package/dist/iapRefundEvents.js +45 -0
- package/dist/iapRefundEventsPort.fixture.js +60 -0
- package/dist/iapRefundPort.fixture.js +55 -0
- package/dist/iapRefundTables.entity.js +56 -0
- package/dist/iapRefunds.d.ts +755 -0
- package/dist/iapRefunds.js +6 -0
- package/dist/iapRefunds.server.js +554 -0
- package/dist/iapRefunds.testFixtures.js +65 -0
- package/dist/iapSpendAdmission.server.js +99 -0
- package/dist/iapStore.server.js +741 -0
- package/dist/iapStore.testFixtures.js +128 -0
- package/dist/iapTables.entity.js +81 -0
- package/dist/iapVerification.server.js +121 -0
- package/dist/index.d.ts +2984 -0
- package/dist/index.js +15 -0
- package/dist/intentionRecovery.js +134 -0
- package/dist/ledger.js +78 -0
- package/dist/loyalty.d.ts +274 -0
- package/dist/loyalty.fixture.js +93 -0
- package/dist/loyalty.js +312 -0
- package/dist/loyaltyBinding.server.js +204 -0
- package/dist/loyaltyPort.fixture.js +87 -0
- package/dist/loyaltyShopSource.server.js +91 -0
- package/dist/loyaltyStore.server.js +553 -0
- package/dist/loyaltyStore.testFixtures.js +83 -0
- package/dist/loyaltyTables.entity.js +50 -0
- package/dist/offerMerchandising.fixture.js +115 -0
- package/dist/offerMerchandising.js +283 -0
- package/dist/offerPolicies.d.ts +441 -0
- package/dist/offerPolicies.fixture.js +54 -0
- package/dist/offerPolicies.js +268 -0
- package/dist/piggyBanks.d.ts +272 -0
- package/dist/piggyBanks.fixture.js +71 -0
- package/dist/piggyBanks.js +201 -0
- package/dist/piggyBinding.server.js +205 -0
- package/dist/piggyPort.fixture.js +73 -0
- package/dist/piggyStore.server.js +611 -0
- package/dist/piggyStore.testFixtures.js +98 -0
- package/dist/piggyTables.entity.js +41 -0
- package/dist/plugin.js +1048 -0
- package/dist/port.js +13 -0
- package/dist/price.d.ts +99 -0
- package/dist/price.js +144 -0
- package/dist/purchaseRecovery.js +56 -0
- package/dist/reports.server.js +115 -0
- package/dist/rpc.d.ts +3201 -0
- package/dist/rpc.js +1201 -0
- package/dist/sanctionsTradeAuthority.server.js +80 -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 +196 -0
- package/dist/shop.testFixtures.js +114 -0
- package/dist/shopPort.fixture.js +72 -0
- package/dist/shopPresentation.js +68 -0
- package/dist/shopStore.server.js +624 -0
- package/dist/shopTables.entity.js +63 -0
- package/dist/shopUiCopy.js +57 -0
- package/dist/spendLimits.d.ts +140 -0
- package/dist/spendLimits.fixture.js +53 -0
- package/dist/spendLimits.js +155 -0
- package/dist/spendLimitsPort.fixture.js +120 -0
- package/dist/subscriptionBinding.server.js +211 -0
- package/dist/subscriptionStore.server.js +643 -0
- package/dist/subscriptionStore.testFixtures.js +72 -0
- package/dist/subscriptionTables.entity.js +37 -0
- package/dist/subscriptions.d.ts +394 -0
- package/dist/subscriptions.fixture.js +97 -0
- package/dist/subscriptions.js +213 -0
- package/dist/subscriptionsPort.fixture.js +76 -0
- package/dist/systemFixtures.js +89 -0
- package/dist/tables.entity.js +83 -0
- package/dist/testing.d.ts +4615 -0
- package/dist/testing.js +29 -0
- package/dist/tradeAuthority.server.js +172 -0
- package/dist/tradeBinding.server.js +201 -0
- package/dist/tradeComponents.js +342 -0
- package/dist/tradeEscrow.server.js +232 -0
- package/dist/tradeEscrow.testFixtures.js +133 -0
- package/dist/tradeExpiry.server.js +43 -0
- package/dist/tradeRecovery.js +48 -0
- package/dist/tradeStore.server.js +750 -0
- package/dist/tradeStore.testFixtures.js +73 -0
- package/dist/tradeTables.entity.js +66 -0
- package/dist/tradeUiCopy.js +79 -0
- package/dist/trades.d.ts +246 -0
- package/dist/trades.fixture.js +103 -0
- package/dist/trades.js +289 -0
- package/dist/tradesPort.fixture.js +94 -0
- package/dist/walletEscrow.js +106 -0
- package/dist/walletEscrow.server.js +376 -0
- package/dist/walletKeys.server.js +5 -0
- package/dist/walletStore.js +571 -0
- package/dist/web.d.ts +2257 -0
- package/dist/web.js +9 -0
- package/package.json +161 -4
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
import { EconomyError as e, economyError as t } from "./errors.js";
|
|
2
|
+
import { captureBoundMethods as n, dataList as r, dataObject as i } from "./capture.js";
|
|
3
|
+
import { captureCurrencies as a } from "./currency.js";
|
|
4
|
+
import { shopInteger as o } from "./shop.js";
|
|
5
|
+
import { defineIapCatalog as s, iapEnvironment as c, iapTimestamp as l } from "./iap.js";
|
|
6
|
+
import { canonicalDataJson as u } from "./canonicalDataJson.js";
|
|
7
|
+
import { readVerifiedIapNotification as d } from "./iapNotifications.server.js";
|
|
8
|
+
import { iapCurrentStatePort as f } from "./iapCurrentState.server.js";
|
|
9
|
+
import { captureIapTransactionFacts as p, iapVerificationPort as m } from "./iapVerification.server.js";
|
|
10
|
+
import { iapCompletionPort as h } from "./iapCompletion.server.js";
|
|
11
|
+
import { iapProviderRecord as g, iapProviderText as _, iapProviderTimestamp as v } from "./iapProviderCapture.server.js";
|
|
12
|
+
import { captureGoogleSubscription as y, captureGoogleSubscriptionOrder as b, captureGoogleSubscriptionPlans as x, projectGoogleIapSubscription as S, projectGoogleIapSubscriptionCurrentState as C } from "./googleIapSubscription.server.js";
|
|
13
|
+
import { googleIapNotificationPort as w } from "./googleIapNotifications.server.js";
|
|
14
|
+
import { Effect as T } from "effect";
|
|
15
|
+
import { createHash as E } from "node:crypto";
|
|
16
|
+
//#region src/googleIap.server.ts
|
|
17
|
+
var D = (e) => {
|
|
18
|
+
if (e.length > 4096 || !/^[A-Za-z0-9._~+\/-]+={0,2}$/.test(e)) throw t("invalid_input");
|
|
19
|
+
return e;
|
|
20
|
+
}, O = (e) => {
|
|
21
|
+
let n = _(e, 8192);
|
|
22
|
+
if (!/^[A-Za-z0-9._~+\/-]+={0,2}$/.test(n)) throw t("unavailable");
|
|
23
|
+
return n;
|
|
24
|
+
}, k = (e, n, i, a) => {
|
|
25
|
+
let s = g(e), c = g(s.purchaseStateContext);
|
|
26
|
+
if (c.purchaseState !== "PURCHASED" && c.purchaseState !== "CANCELLED" || s.obfuscatedExternalAccountId !== n.accountToken || n.product.kind === "subscription") throw t("forbidden");
|
|
27
|
+
let l = s.testPurchaseContext === void 0 ? null : g(s.testPurchaseContext);
|
|
28
|
+
if (a === "sandbox" ? l?.fopType !== "TEST" : l !== null) throw t("forbidden");
|
|
29
|
+
let u = r(s.productLineItem, 32);
|
|
30
|
+
if (u.length !== 1) throw t("forbidden");
|
|
31
|
+
let d = g(u[0]), f = g(d.productOfferDetails);
|
|
32
|
+
if (d.productId !== n.product.storeProductId || f.rentOfferDetails !== void 0 || f.preorderOfferDetails !== void 0) throw t("forbidden");
|
|
33
|
+
let m = o(f.quantity, 1, n.product.offer.maxQuantity), h = o(f.refundableQuantity, 0, m);
|
|
34
|
+
if (f.consumptionState !== "CONSUMPTION_STATE_YET_TO_BE_CONSUMED" && f.consumptionState !== "CONSUMPTION_STATE_CONSUMED") throw t("forbidden");
|
|
35
|
+
let _ = s.acknowledgementState === "ACKNOWLEDGEMENT_STATE_PENDING" ? "pending" : s.acknowledgementState === "ACKNOWLEDGEMENT_STATE_ACKNOWLEDGED" ? "acknowledged" : null;
|
|
36
|
+
if (_ === null) throw t("invalid_record");
|
|
37
|
+
let y = E("sha256").update(D(n.intent.receipt)).digest("hex"), b = p({
|
|
38
|
+
channel: "android",
|
|
39
|
+
environment: a,
|
|
40
|
+
applicationId: i,
|
|
41
|
+
transactionId: y,
|
|
42
|
+
originalTransactionId: null,
|
|
43
|
+
storeProductId: n.product.storeProductId,
|
|
44
|
+
kind: n.product.kind,
|
|
45
|
+
quantity: m,
|
|
46
|
+
purchasedAt: v(s.purchaseCompletionTime),
|
|
47
|
+
expiresAt: null,
|
|
48
|
+
paid: null,
|
|
49
|
+
acknowledgement: _,
|
|
50
|
+
consumption: f.consumptionState === "CONSUMPTION_STATE_CONSUMED" ? "consumed" : "available"
|
|
51
|
+
});
|
|
52
|
+
return Object.freeze({
|
|
53
|
+
facts: b,
|
|
54
|
+
purchaseState: c.purchaseState,
|
|
55
|
+
refundableQuantity: h
|
|
56
|
+
});
|
|
57
|
+
}, A = (e, n, r, i) => {
|
|
58
|
+
let a = k(e, n, r, i);
|
|
59
|
+
if (a.purchaseState !== "PURCHASED" || a.refundableQuantity !== a.facts.quantity) throw t("forbidden");
|
|
60
|
+
return a.facts;
|
|
61
|
+
}, j = async (e, n) => {
|
|
62
|
+
if (!(e.headers.get("content-type") ?? "").toLowerCase().startsWith("application/json") || e.body === null) throw t("invalid_record");
|
|
63
|
+
let r = e.body.getReader(), i = new TextDecoder("utf-8", { fatal: !0 }), a = 0, o = "";
|
|
64
|
+
try {
|
|
65
|
+
for (;;) {
|
|
66
|
+
let e = await r.read();
|
|
67
|
+
if (e.done) break;
|
|
68
|
+
if (a += e.value.byteLength, a > n) throw t("limit_exceeded");
|
|
69
|
+
o += i.decode(e.value, { stream: !0 });
|
|
70
|
+
}
|
|
71
|
+
return o += i.decode(), JSON.parse(o);
|
|
72
|
+
} finally {
|
|
73
|
+
await r.cancel().catch(() => void 0), r.releaseLock();
|
|
74
|
+
}
|
|
75
|
+
}, M = (e) => {
|
|
76
|
+
if (typeof e.applicationId != "string" || !/^[A-Za-z][A-Za-z0-9_]*(?:\.[A-Za-z][A-Za-z0-9_]*)+$/.test(e.applicationId)) throw t("invalid_input");
|
|
77
|
+
let r = n(e.accessTokens, ["read"]), i = o(e.timeoutMs ?? 1e4, 1, 6e4), a = o(e.maxResponseBytes ?? 65536, 1024, 1048576);
|
|
78
|
+
return Object.freeze({
|
|
79
|
+
tokens: r,
|
|
80
|
+
timeoutMs: i,
|
|
81
|
+
maximum: a
|
|
82
|
+
});
|
|
83
|
+
}, N = (e) => {
|
|
84
|
+
let n = i(e, [
|
|
85
|
+
"realMoney",
|
|
86
|
+
"environment",
|
|
87
|
+
"applicationId",
|
|
88
|
+
"products",
|
|
89
|
+
"currencies",
|
|
90
|
+
"accounts",
|
|
91
|
+
"now",
|
|
92
|
+
"accessTokens",
|
|
93
|
+
"timeoutMs",
|
|
94
|
+
"maxResponseBytes",
|
|
95
|
+
"subscriptionPlans"
|
|
96
|
+
]);
|
|
97
|
+
if (n.realMoney !== !0) throw t(n.realMoney === !1 ? "real_money_disabled" : "invalid_input");
|
|
98
|
+
let { tokens: r, timeoutMs: o, maximum: c } = M(n), l = {
|
|
99
|
+
realMoney: n.realMoney,
|
|
100
|
+
channel: "android",
|
|
101
|
+
environment: n.environment,
|
|
102
|
+
applicationId: n.applicationId,
|
|
103
|
+
products: n.products,
|
|
104
|
+
currencies: n.currencies,
|
|
105
|
+
accounts: n.accounts,
|
|
106
|
+
...n.now === void 0 ? {} : { now: n.now }
|
|
107
|
+
}, u = x(n.subscriptionPlans), d = s(l.products, a(l.currencies), !0);
|
|
108
|
+
if (d.some((e) => e.kind === "subscription" && !u.some((t) => t.offerId === e.offer.id && t.offerVersion === e.offer.version)) || u.some((e) => !d.some((t) => t.kind === "subscription" && t.offer.id === e.offerId && t.offer.version === e.offerVersion))) throw t("invalid_input");
|
|
109
|
+
return Object.freeze({
|
|
110
|
+
common: l,
|
|
111
|
+
tokens: r,
|
|
112
|
+
timeoutMs: o,
|
|
113
|
+
maximum: c,
|
|
114
|
+
subscriptionPlans: u
|
|
115
|
+
});
|
|
116
|
+
}, P = (e) => e.read().pipe(T.flatMap((e) => T.try({
|
|
117
|
+
try: () => {
|
|
118
|
+
O(e);
|
|
119
|
+
},
|
|
120
|
+
catch: () => t("unavailable")
|
|
121
|
+
}))), F = (e, t) => AbortSignal.any([t, AbortSignal.timeout(e)]), I = async (e, n, r, i, a, o) => {
|
|
122
|
+
let s = `https://androidpublisher.googleapis.com/androidpublisher/v3/applications/${encodeURIComponent(e)}/${n}`, c = await fetch(s, {
|
|
123
|
+
method: "GET",
|
|
124
|
+
headers: {
|
|
125
|
+
authorization: `Bearer ${r}`,
|
|
126
|
+
accept: "application/json"
|
|
127
|
+
},
|
|
128
|
+
redirect: "error",
|
|
129
|
+
signal: F(i, o)
|
|
130
|
+
});
|
|
131
|
+
if (!c.ok) throw await c.body?.cancel(), t(c.status === 404 || c.status === 410 ? "not_found" : "unavailable");
|
|
132
|
+
return j(c, a);
|
|
133
|
+
}, L = (e, t, n, r, i, a) => I(e, `purchases/productsv2/tokens/${encodeURIComponent(t)}`, n, r, i, a), R = async (e, t, n, r, i, a, o, s, c) => {
|
|
134
|
+
let l = await I(t, `purchases/subscriptionsv2/tokens/${encodeURIComponent(e.intent.receipt)}`, r, i, a, o), u = y(l, e, n, s);
|
|
135
|
+
return {
|
|
136
|
+
subscription: l,
|
|
137
|
+
order: await I(t, `orders/${encodeURIComponent(c ?? u.orderId)}`, r, i, a, o),
|
|
138
|
+
admitted: u
|
|
139
|
+
};
|
|
140
|
+
}, z = (n) => {
|
|
141
|
+
let { common: r, tokens: i, timeoutMs: a, maximum: o, subscriptionPlans: s } = N(n);
|
|
142
|
+
return m(r, {
|
|
143
|
+
initialize: () => P(i),
|
|
144
|
+
verify: (n) => T.try({
|
|
145
|
+
try: () => D(n.intent.receipt),
|
|
146
|
+
catch: () => t("invalid_input")
|
|
147
|
+
}).pipe(T.flatMap((c) => i.read().pipe(T.flatMap((i) => T.tryPromise({
|
|
148
|
+
try: async (e) => {
|
|
149
|
+
let t = O(i);
|
|
150
|
+
if (n.product.kind === "subscription") {
|
|
151
|
+
let i = await R(n, r.applicationId, r.environment, t, a, o, e, s);
|
|
152
|
+
return S(i.subscription, i.order, n, r.applicationId, r.environment, s);
|
|
153
|
+
}
|
|
154
|
+
return A(await L(r.applicationId, c, t, a, o, e), n, r.applicationId, r.environment);
|
|
155
|
+
},
|
|
156
|
+
catch: (n) => n instanceof e ? n : t("unavailable")
|
|
157
|
+
})))))
|
|
158
|
+
});
|
|
159
|
+
}, B = (e, t) => JSON.stringify({
|
|
160
|
+
...e,
|
|
161
|
+
acknowledgement: "none",
|
|
162
|
+
consumption: "none"
|
|
163
|
+
}) === JSON.stringify({
|
|
164
|
+
...t,
|
|
165
|
+
acknowledgement: "none",
|
|
166
|
+
consumption: "none"
|
|
167
|
+
}), V = (e, n) => {
|
|
168
|
+
if (!B(e.facts, n)) throw t("conflict");
|
|
169
|
+
if (e.product.kind === "consumable") return n.consumption === "consumed";
|
|
170
|
+
if (e.product.kind !== "non-consumable" && e.product.kind !== "subscription" || n.consumption === "consumed") throw t("forbidden");
|
|
171
|
+
return n.acknowledgement === "acknowledged";
|
|
172
|
+
}, H = (n) => {
|
|
173
|
+
let { common: i, tokens: a, timeoutMs: o, maximum: s, subscriptionPlans: c } = N(n);
|
|
174
|
+
return h(i, {
|
|
175
|
+
initialize: () => P(a),
|
|
176
|
+
complete: (n) => T.try({
|
|
177
|
+
try: () => D(n.intent.receipt),
|
|
178
|
+
catch: () => t("invalid_input")
|
|
179
|
+
}).pipe(T.flatMap((u) => a.read().pipe(T.flatMap((a) => T.tryPromise({
|
|
180
|
+
try: async (e) => {
|
|
181
|
+
let d = O(a), f = async () => {
|
|
182
|
+
if (n.product.kind !== "subscription") return A(await L(i.applicationId, u, d, o, s, e), n, i.applicationId, i.environment);
|
|
183
|
+
if (E("sha256").update(u).digest("hex") !== n.facts.originalTransactionId) throw t("forbidden");
|
|
184
|
+
let a = await R(n, i.applicationId, i.environment, d, o, s, e, c, n.facts.transactionId), l = b(a.order, n, a.admitted, i.applicationId, i.environment, c, n.facts.transactionId);
|
|
185
|
+
if (l.orderState !== "PROCESSED" || l.history.refundEvent !== void 0 || r(l.history.partialRefundEvents ?? [], 1e3, "invalid_record").length !== 0) throw t("forbidden");
|
|
186
|
+
return l.facts;
|
|
187
|
+
}, p = n.product.kind === "consumable" ? "consume" : "acknowledge";
|
|
188
|
+
if (!V(n, await f())) {
|
|
189
|
+
let r = `https://androidpublisher.googleapis.com/androidpublisher/v3/applications/${encodeURIComponent(i.applicationId)}/purchases/${n.product.kind === "subscription" ? "subscriptions" : "products"}/${encodeURIComponent(n.product.storeProductId)}/tokens/${encodeURIComponent(u)}:${p}`;
|
|
190
|
+
try {
|
|
191
|
+
await (await fetch(r, {
|
|
192
|
+
method: "POST",
|
|
193
|
+
headers: {
|
|
194
|
+
authorization: `Bearer ${d}`,
|
|
195
|
+
accept: "application/json",
|
|
196
|
+
...p === "acknowledge" ? { "content-type": "application/json" } : {}
|
|
197
|
+
},
|
|
198
|
+
...p === "acknowledge" ? { body: "{}" } : {},
|
|
199
|
+
redirect: "error",
|
|
200
|
+
signal: F(o, e)
|
|
201
|
+
})).body?.cancel();
|
|
202
|
+
} catch {
|
|
203
|
+
if (e.aborted) throw t("unavailable");
|
|
204
|
+
}
|
|
205
|
+
if (!V(n, await f())) throw t("unavailable");
|
|
206
|
+
}
|
|
207
|
+
return Object.freeze({
|
|
208
|
+
orderId: n.orderId,
|
|
209
|
+
channel: "android",
|
|
210
|
+
operation: p,
|
|
211
|
+
observedAt: l((i.now ?? Date.now)())
|
|
212
|
+
});
|
|
213
|
+
},
|
|
214
|
+
catch: (n) => n instanceof e ? n : t("unavailable")
|
|
215
|
+
})))))
|
|
216
|
+
});
|
|
217
|
+
}, U = (e) => {
|
|
218
|
+
let r = i(e, [
|
|
219
|
+
"environment",
|
|
220
|
+
"applicationId",
|
|
221
|
+
"accessTokens",
|
|
222
|
+
"timeoutMs",
|
|
223
|
+
"maxResponseBytes",
|
|
224
|
+
"subscriptionPlans",
|
|
225
|
+
"notifications"
|
|
226
|
+
]), a = c(r.environment);
|
|
227
|
+
if (typeof r.applicationId != "string" || !/^[A-Za-z][A-Za-z0-9_]*(?:\.[A-Za-z][A-Za-z0-9_]*)+$/.test(r.applicationId)) throw t("invalid_input");
|
|
228
|
+
let s = x(r.subscriptionPlans), l = r.applicationId, u = n(r.accessTokens, ["read"]), d = o(r.timeoutMs ?? 1e4, 1, 6e4), f = o(r.maxResponseBytes ?? 65536, 1024, 1048576), p = r.notifications === void 0 ? void 0 : i(r.notifications, [
|
|
229
|
+
"audience",
|
|
230
|
+
"serviceAccountEmail",
|
|
231
|
+
"subscription",
|
|
232
|
+
"maxBodyBytes"
|
|
233
|
+
]), m = (e) => {
|
|
234
|
+
let { channel: n, ...r } = e;
|
|
235
|
+
if (n !== "android" || r.realMoney !== !0 || r.applicationId !== l || r.environment !== a) throw t("forbidden");
|
|
236
|
+
return {
|
|
237
|
+
...r,
|
|
238
|
+
accessTokens: u,
|
|
239
|
+
timeoutMs: d,
|
|
240
|
+
maxResponseBytes: f,
|
|
241
|
+
subscriptionPlans: s
|
|
242
|
+
};
|
|
243
|
+
};
|
|
244
|
+
return Object.freeze({
|
|
245
|
+
channel: "android",
|
|
246
|
+
environment: a,
|
|
247
|
+
applicationId: l,
|
|
248
|
+
create: (e) => z(m(e)),
|
|
249
|
+
createCompletion: (e) => H(m(e)),
|
|
250
|
+
createCurrentState: (e) => {
|
|
251
|
+
let { products: t, currencies: n, ...r } = m(e);
|
|
252
|
+
return G({
|
|
253
|
+
...r,
|
|
254
|
+
accounts: e.accounts
|
|
255
|
+
});
|
|
256
|
+
},
|
|
257
|
+
...p === void 0 ? {} : {
|
|
258
|
+
createNotifications: (e) => (m(e), w({
|
|
259
|
+
realMoney: !0,
|
|
260
|
+
applicationId: l,
|
|
261
|
+
...p,
|
|
262
|
+
now: e.now
|
|
263
|
+
})),
|
|
264
|
+
createDeliveries: (e) => K({
|
|
265
|
+
notifications: {
|
|
266
|
+
realMoney: !0,
|
|
267
|
+
applicationId: l,
|
|
268
|
+
...p,
|
|
269
|
+
now: e.now
|
|
270
|
+
},
|
|
271
|
+
verification: m(e)
|
|
272
|
+
})
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
}, W = (e, n, r, i, a) => {
|
|
276
|
+
let o = g(n.material.detail), s = D(_(o.purchaseToken, 4096));
|
|
277
|
+
if (E("sha256").update(s).digest("hex") !== n.facts.transactionId) throw t("forbidden");
|
|
278
|
+
let c = {
|
|
279
|
+
channel: "android",
|
|
280
|
+
offerId: n.product.offer.id,
|
|
281
|
+
offerVersion: n.product.offer.version,
|
|
282
|
+
requestId: n.orderId,
|
|
283
|
+
receipt: s
|
|
284
|
+
}, d = k(e, {
|
|
285
|
+
scope: n.scope,
|
|
286
|
+
product: n.product,
|
|
287
|
+
intent: c,
|
|
288
|
+
accountToken: n.accountToken,
|
|
289
|
+
at: n.at
|
|
290
|
+
}, r, i), f = (e) => u({
|
|
291
|
+
...e,
|
|
292
|
+
acknowledgement: "none",
|
|
293
|
+
consumption: "none"
|
|
294
|
+
});
|
|
295
|
+
if (f(d.facts) !== f(n.facts)) throw t("conflict");
|
|
296
|
+
let p = d.facts.quantity - d.refundableQuantity, m = d.facts.quantity;
|
|
297
|
+
if (d.purchaseState === "CANCELLED" && p !== m) throw t("unavailable");
|
|
298
|
+
return Object.freeze({
|
|
299
|
+
orderId: n.orderId,
|
|
300
|
+
channel: "android",
|
|
301
|
+
state: p === 0 ? "active" : p === m ? "revoked" : "partially-refunded",
|
|
302
|
+
refundNumerator: p,
|
|
303
|
+
refundDenominator: m,
|
|
304
|
+
observedAt: l(a),
|
|
305
|
+
revokedAt: null
|
|
306
|
+
});
|
|
307
|
+
}, G = (n) => {
|
|
308
|
+
let r = i(n, [
|
|
309
|
+
"realMoney",
|
|
310
|
+
"environment",
|
|
311
|
+
"applicationId",
|
|
312
|
+
"accounts",
|
|
313
|
+
"maxAgeMs",
|
|
314
|
+
"now",
|
|
315
|
+
"accessTokens",
|
|
316
|
+
"timeoutMs",
|
|
317
|
+
"maxResponseBytes",
|
|
318
|
+
"subscriptionPlans"
|
|
319
|
+
]);
|
|
320
|
+
if (r.realMoney !== !0) throw t(r.realMoney === !1 ? "real_money_disabled" : "invalid_input");
|
|
321
|
+
let { tokens: a, timeoutMs: o, maximum: s } = M(r), u = x(r.subscriptionPlans), d = r.applicationId, p = c(r.environment), m = r.now ?? Date.now;
|
|
322
|
+
if (typeof m != "function") throw t("invalid_input");
|
|
323
|
+
let h = {
|
|
324
|
+
realMoney: !0,
|
|
325
|
+
channel: "android",
|
|
326
|
+
applicationId: d,
|
|
327
|
+
environment: p,
|
|
328
|
+
accounts: r.accounts,
|
|
329
|
+
...r.maxAgeMs === void 0 ? {} : { maxAgeMs: r.maxAgeMs },
|
|
330
|
+
now: m
|
|
331
|
+
};
|
|
332
|
+
return f(h, {
|
|
333
|
+
initialize: () => P(a),
|
|
334
|
+
read: (n) => T.try({
|
|
335
|
+
try: () => {
|
|
336
|
+
let e = g(n.material.detail), r = D(_(e.purchaseToken, 4096));
|
|
337
|
+
if (E("sha256").update(r).digest("hex") !== (n.product.kind === "subscription" ? n.facts.originalTransactionId : n.facts.transactionId)) throw t("forbidden");
|
|
338
|
+
return r;
|
|
339
|
+
},
|
|
340
|
+
catch: (n) => n instanceof e ? n : t("invalid_record")
|
|
341
|
+
}).pipe(T.flatMap((r) => a.read().pipe(T.flatMap((i) => T.tryPromise({
|
|
342
|
+
try: async (e) => {
|
|
343
|
+
let t = O(i);
|
|
344
|
+
if (n.product.kind === "subscription") {
|
|
345
|
+
let i = await R({
|
|
346
|
+
scope: n.scope,
|
|
347
|
+
product: n.product,
|
|
348
|
+
accountToken: n.accountToken,
|
|
349
|
+
at: n.at,
|
|
350
|
+
intent: {
|
|
351
|
+
channel: "android",
|
|
352
|
+
offerId: n.product.offer.id,
|
|
353
|
+
offerVersion: n.product.offer.version,
|
|
354
|
+
requestId: n.orderId,
|
|
355
|
+
receipt: r
|
|
356
|
+
}
|
|
357
|
+
}, d, p, t, o, s, e, u, n.facts.transactionId);
|
|
358
|
+
return C(i.subscription, i.order, n, d, p, l(m()), u);
|
|
359
|
+
}
|
|
360
|
+
return W(await L(d, r, t, o, s, e), n, d, p, l(m()));
|
|
361
|
+
},
|
|
362
|
+
catch: (n) => n instanceof e ? n : t("unavailable")
|
|
363
|
+
})))))
|
|
364
|
+
});
|
|
365
|
+
}, K = (n) => {
|
|
366
|
+
let i = w(n.notifications), { common: o, tokens: c, timeoutMs: l, maximum: u, subscriptionPlans: f } = N(n.verification), p = s(o.products, a(o.currencies), !0);
|
|
367
|
+
return Object.freeze({
|
|
368
|
+
initialize: () => i.initialize().pipe(T.flatMap(() => P(c))),
|
|
369
|
+
read: (n) => i.verify(n).pipe(T.flatMap((n) => {
|
|
370
|
+
let { notice: i, material: a } = d(n);
|
|
371
|
+
if (i.sourceType !== "android.subscription.2" && i.sourceType !== "android.subscription.1") return T.succeed(null);
|
|
372
|
+
let s = D(_(g(a.detail).purchaseToken, 4096));
|
|
373
|
+
return c.read().pipe(T.flatMap((n) => T.tryPromise({
|
|
374
|
+
try: async (e) => {
|
|
375
|
+
let t = g(await I(o.applicationId, `purchases/subscriptionsv2/tokens/${encodeURIComponent(s)}`, O(n), l, u, e)), i = t.externalAccountIdentifiers === void 0 ? {} : g(t.externalAccountIdentifiers), a = r(t.lineItems, 32, "invalid_record");
|
|
376
|
+
if (a.length !== 1 || typeof i.obfuscatedExternalAccountId != "string") return null;
|
|
377
|
+
let c = g(a[0]), d = c.offerDetails === void 0 ? {} : g(c.offerDetails), m = p.find((e) => e.channel === "android" && e.kind === "subscription" && e.storeProductId === c.productId && f.some((t) => t.offerId === e.offer.id && t.offerVersion === e.offer.version && t.basePlanId === d.basePlanId && t.storeOfferId === (d.offerId ?? null)));
|
|
378
|
+
return !m || typeof c.latestSuccessfulOrderId != "string" ? null : {
|
|
379
|
+
accountToken: i.obfuscatedExternalAccountId,
|
|
380
|
+
offerId: m.offer.id,
|
|
381
|
+
offerVersion: m.offer.version,
|
|
382
|
+
requestId: "renew.android." + _(c.latestSuccessfulOrderId, 100),
|
|
383
|
+
receipt: s
|
|
384
|
+
};
|
|
385
|
+
},
|
|
386
|
+
catch: (n) => n instanceof e ? n : t("unavailable")
|
|
387
|
+
})));
|
|
388
|
+
}), T.catchDefect(() => T.fail(t("unavailable"))))
|
|
389
|
+
});
|
|
390
|
+
};
|
|
391
|
+
//#endregion
|
|
392
|
+
export { H as googleIapCompletionPort, G as googleIapCurrentStatePort, K as googleIapDeliveryPort, U as googleIapProvider, z as googleIapVerificationPort, W as projectGoogleIapCurrentState, A as projectGoogleIapProduct };
|
|
@@ -0,0 +1,131 @@
|
|
|
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 { iapTimestamp as a } from "./iap.js";
|
|
5
|
+
import { captureNotificationInput as o, issueVerifiedIapNotification as s, notificationTime as c } from "./iapNotifications.server.js";
|
|
6
|
+
import { iapProviderRecord as l, iapProviderText as u } from "./iapProviderCapture.server.js";
|
|
7
|
+
import { Effect as d } from "effect";
|
|
8
|
+
import { Buffer as f } from "node:buffer";
|
|
9
|
+
import { createHash as p } from "node:crypto";
|
|
10
|
+
import { JwtVerifyError as m, verifyJwt as h } from "@voltro/protocol/jwt";
|
|
11
|
+
//#region src/googleIapNotifications.server.ts
|
|
12
|
+
var g = (e, n, a, o) => {
|
|
13
|
+
let s = l(e), d = l(s.message);
|
|
14
|
+
if (s.subscription !== a) throw t("forbidden");
|
|
15
|
+
let m = u(d.messageId, 128), h = u(d.data, 1048576);
|
|
16
|
+
if (!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(h)) throw t("invalid_record");
|
|
17
|
+
let g = f.from(h, "base64");
|
|
18
|
+
if (g.toString("base64") !== h) throw t("invalid_record");
|
|
19
|
+
let _ = l(JSON.parse(new TextDecoder("utf-8", { fatal: !0 }).decode(g)));
|
|
20
|
+
if (_.packageName !== n || _.version !== "1.0" || typeof _.eventTimeMillis != "string" || !/^(0|[1-9][0-9]{0,15})$/.test(_.eventTimeMillis)) throw t("forbidden");
|
|
21
|
+
let v = c(Number(_.eventTimeMillis), o), y = [
|
|
22
|
+
"oneTimeProductNotification",
|
|
23
|
+
"subscriptionNotification",
|
|
24
|
+
"voidedPurchaseNotification",
|
|
25
|
+
"pendingRefundReviewNotification",
|
|
26
|
+
"testNotification"
|
|
27
|
+
].filter((e) => _[e] !== void 0);
|
|
28
|
+
if (y.length !== 1) throw t("invalid_record");
|
|
29
|
+
let b = y[0], x = l(_[b]), S, C, w = null, T = null, E = null;
|
|
30
|
+
if (b === "testNotification") {
|
|
31
|
+
if (x.version !== "1.0") throw t("invalid_record");
|
|
32
|
+
S = "test", C = "android.test";
|
|
33
|
+
} else if (b === "pendingRefundReviewNotification") {
|
|
34
|
+
if (x.version !== "1.0" || x.refundReason !== 7) throw t("invalid_record");
|
|
35
|
+
u(x.pendingRefundToken, 4096), u(x.orderId, 128), S = "review", C = "android.pending-refund-review";
|
|
36
|
+
} else {
|
|
37
|
+
let e = u(x.purchaseToken, 4096);
|
|
38
|
+
if (!/^[A-Za-z0-9._~+\/-]+={0,2}$/.test(e)) throw t("invalid_record");
|
|
39
|
+
if (w = p("sha256").update(e).digest("hex"), b === "voidedPurchaseNotification") i(x.productType, 1, 2), i(x.refundType, 1, 2), u(x.orderId, 128), x.productType === 1 && (T = w, w = u(x.orderId, 128)), S = "voided", C = "android.voided." + x.productType + "." + x.refundType;
|
|
40
|
+
else {
|
|
41
|
+
if (x.version !== "1.0") throw t("invalid_record");
|
|
42
|
+
if (b === "oneTimeProductNotification") S = "one-time", C = "android.one-time." + i(x.notificationType, 1, 2), E = r(x.sku);
|
|
43
|
+
else {
|
|
44
|
+
let e = i(x.notificationType, 1, 22);
|
|
45
|
+
if (![
|
|
46
|
+
1,
|
|
47
|
+
2,
|
|
48
|
+
3,
|
|
49
|
+
4,
|
|
50
|
+
5,
|
|
51
|
+
6,
|
|
52
|
+
7,
|
|
53
|
+
8,
|
|
54
|
+
9,
|
|
55
|
+
10,
|
|
56
|
+
11,
|
|
57
|
+
12,
|
|
58
|
+
13,
|
|
59
|
+
17,
|
|
60
|
+
18,
|
|
61
|
+
19,
|
|
62
|
+
20,
|
|
63
|
+
22
|
|
64
|
+
].includes(e)) throw t("invalid_record");
|
|
65
|
+
T = w, w = null, S = "subscription", C = "android.subscription." + e;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return Object.freeze({
|
|
70
|
+
notice: Object.freeze({
|
|
71
|
+
channel: "android",
|
|
72
|
+
applicationId: n,
|
|
73
|
+
environment: null,
|
|
74
|
+
noticeId: m,
|
|
75
|
+
sourceType: C,
|
|
76
|
+
kind: S,
|
|
77
|
+
occurredAt: v,
|
|
78
|
+
transactionId: w,
|
|
79
|
+
originalTransactionId: T,
|
|
80
|
+
storeProductId: E
|
|
81
|
+
}),
|
|
82
|
+
material: Object.freeze({ detail: structuredClone(x) })
|
|
83
|
+
});
|
|
84
|
+
}, _ = (c) => {
|
|
85
|
+
let l = n(c, [
|
|
86
|
+
"realMoney",
|
|
87
|
+
"applicationId",
|
|
88
|
+
"audience",
|
|
89
|
+
"serviceAccountEmail",
|
|
90
|
+
"subscription",
|
|
91
|
+
"maxBodyBytes",
|
|
92
|
+
"now"
|
|
93
|
+
]);
|
|
94
|
+
if (l.realMoney !== !0) throw t(l.realMoney === !1 ? "real_money_disabled" : "invalid_input");
|
|
95
|
+
let f = r(l.applicationId), p = u(l.audience, 2048), _ = u(l.serviceAccountEmail, 254), v = u(l.subscription, 512);
|
|
96
|
+
if (!/^[A-Za-z][A-Za-z0-9_]*(?:\.[A-Za-z][A-Za-z0-9_]*)+$/.test(f) || !/^[A-Za-z0-9][A-Za-z0-9._+-]*@[A-Za-z0-9.-]+\.gserviceaccount\.com$/.test(_) || !/^projects\/[A-Za-z0-9._-]+\/subscriptions\/[A-Za-z0-9._~-]+$/.test(v)) throw t("invalid_input");
|
|
97
|
+
let y = new URL(p);
|
|
98
|
+
if (y.protocol !== "https:" || y.username || y.password || y.search || y.hash) throw t("invalid_input");
|
|
99
|
+
let b = i(l.maxBodyBytes ?? 65536, 1024, 1048576), x = l.now ?? Date.now;
|
|
100
|
+
if (typeof x != "function") throw t("invalid_input");
|
|
101
|
+
return Object.freeze({
|
|
102
|
+
initialize: () => d.void,
|
|
103
|
+
verify: (n) => {
|
|
104
|
+
let r, i;
|
|
105
|
+
try {
|
|
106
|
+
r = o(n, b);
|
|
107
|
+
let e = r.authorization?.match(/^Bearer ([A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+)$/);
|
|
108
|
+
if (!e) throw t("forbidden");
|
|
109
|
+
i = e[1];
|
|
110
|
+
} catch (n) {
|
|
111
|
+
return d.fail(n instanceof e ? n : t("invalid_input"));
|
|
112
|
+
}
|
|
113
|
+
return d.tryPromise({
|
|
114
|
+
try: async () => {
|
|
115
|
+
let e = await h(i, "https://www.googleapis.com/oauth2/v3/certs", {
|
|
116
|
+
issuer: ["https://accounts.google.com", "accounts.google.com"],
|
|
117
|
+
audience: p,
|
|
118
|
+
algorithms: ["RS256"],
|
|
119
|
+
clockToleranceS: 60
|
|
120
|
+
});
|
|
121
|
+
if (e.email !== _ || e.email_verified !== !0 || typeof e.sub != "string" || !/^[0-9]{1,128}$/.test(e.sub)) throw t("forbidden");
|
|
122
|
+
let n = g(JSON.parse(r.body), f, v, a(x()));
|
|
123
|
+
return s(n.notice, n.material);
|
|
124
|
+
},
|
|
125
|
+
catch: (n) => n instanceof e ? n : n instanceof m ? t(n.code === "jwks_unreachable" ? "unavailable" : "forbidden") : t("invalid_record")
|
|
126
|
+
}).pipe(d.catchDefect(() => d.fail(t("unavailable"))));
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
};
|
|
130
|
+
//#endregion
|
|
131
|
+
export { _ as googleIapNotificationPort, g as projectGoogleIapNotification };
|