@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,94 @@
|
|
|
1
|
+
import { economyError as e } from "./errors.js";
|
|
2
|
+
import { iapNotificationTables as t } from "./iapNotificationTables.entity.js";
|
|
3
|
+
import { iapCurrentStatePort as n } from "./iapCurrentState.server.js";
|
|
4
|
+
import { iapRefundTables as r } from "./iapRefundTables.entity.js";
|
|
5
|
+
import { economyPlugin as i } from "./plugin.js";
|
|
6
|
+
import { iapFixtureLifecycle as a, iapPluginFixture as o } from "./iapPlugin.testFixtures.js";
|
|
7
|
+
import { iapSqlNoticeFixture as s } from "./iapNotificationTarget.testFixtures.js";
|
|
8
|
+
import { inventoryIapRefundAssets as c } from "./iapInventoryRefunds.server.js";
|
|
9
|
+
import { Effect as l } from "effect";
|
|
10
|
+
import { randomBytes as u } from "node:crypto";
|
|
11
|
+
import { ensureTableRegistered as d } from "@voltro/database";
|
|
12
|
+
import { makeFieldCipher as f } from "@voltro/runtime";
|
|
13
|
+
//#region src/iapInstalledNotifications.testFixtures.ts
|
|
14
|
+
var p = async (p, m = "test.installed.notices", h) => {
|
|
15
|
+
let g = await o(p, void 0, m), _ = g.base;
|
|
16
|
+
await l.runPromise(g.close), [...t, ...r].forEach(d);
|
|
17
|
+
let v = s(_), y = u(24).toString("base64url"), b = f(u(32).toString("base64url")), x = _.at + 1, S = 1, C = 0, w = 0, T = !1, E, D = {
|
|
18
|
+
...g.options.providers[0],
|
|
19
|
+
createNotifications: () => ({
|
|
20
|
+
initialize: () => l.sync(() => {
|
|
21
|
+
C++;
|
|
22
|
+
}),
|
|
23
|
+
verify: (t) => t.body === y ? l.succeed(v.evidence) : l.fail(e("forbidden"))
|
|
24
|
+
}),
|
|
25
|
+
createCurrentState: (t) => n({
|
|
26
|
+
realMoney: !0,
|
|
27
|
+
channel: "ios",
|
|
28
|
+
environment: t.environment,
|
|
29
|
+
applicationId: t.applicationId,
|
|
30
|
+
accounts: t.accounts,
|
|
31
|
+
now: t.now
|
|
32
|
+
}, {
|
|
33
|
+
initialize: () => l.sync(() => {
|
|
34
|
+
C++;
|
|
35
|
+
}),
|
|
36
|
+
read: (t) => l.suspend(() => (w++, T ? l.fail(e("unavailable")) : (E ? E() : l.void).pipe(l.map(() => ({
|
|
37
|
+
orderId: t.orderId,
|
|
38
|
+
channel: "ios",
|
|
39
|
+
state: S === 0 ? "active" : "revoked",
|
|
40
|
+
refundNumerator: S,
|
|
41
|
+
refundDenominator: 1,
|
|
42
|
+
observedAt: t.at,
|
|
43
|
+
revokedAt: null
|
|
44
|
+
})))))
|
|
45
|
+
})
|
|
46
|
+
}, O = {
|
|
47
|
+
...g.options,
|
|
48
|
+
now: () => x,
|
|
49
|
+
providers: [D],
|
|
50
|
+
notifications: {
|
|
51
|
+
version: "notices.fixture.v1",
|
|
52
|
+
bodyRetentionMs: 1e3,
|
|
53
|
+
debtPolicy: "blockSpend",
|
|
54
|
+
assets: c(p, {
|
|
55
|
+
inventory: _.inventory,
|
|
56
|
+
disposition: "requireAll"
|
|
57
|
+
}),
|
|
58
|
+
assetsVersion: "items.fixture.v1",
|
|
59
|
+
cipher: { read: () => b },
|
|
60
|
+
...h ? { onChange: h } : {}
|
|
61
|
+
}
|
|
62
|
+
}, k = i({
|
|
63
|
+
currencies: _.currencies,
|
|
64
|
+
realMoney: !0,
|
|
65
|
+
now: () => x,
|
|
66
|
+
iap: O
|
|
67
|
+
});
|
|
68
|
+
return await k.bindDataStore?.(p), {
|
|
69
|
+
base: _,
|
|
70
|
+
store: p,
|
|
71
|
+
plugin: k,
|
|
72
|
+
options: O,
|
|
73
|
+
body: y,
|
|
74
|
+
notice: v,
|
|
75
|
+
activate: () => k.onActivate(a),
|
|
76
|
+
close: () => k.onDeactivate(a),
|
|
77
|
+
ready: () => C,
|
|
78
|
+
reads: () => w,
|
|
79
|
+
failProvider: (e) => {
|
|
80
|
+
T = e;
|
|
81
|
+
},
|
|
82
|
+
beforeRead: (e) => {
|
|
83
|
+
E = e;
|
|
84
|
+
},
|
|
85
|
+
advance: (e) => {
|
|
86
|
+
x += e;
|
|
87
|
+
},
|
|
88
|
+
currentRefund: (e) => {
|
|
89
|
+
S = e, x++;
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
//#endregion
|
|
94
|
+
export { p as iapInstalledNotificationsFixture };
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
import { EconomyError as e, economyError as t } from "./errors.js";
|
|
2
|
+
import { captureBoundMethods as n, dataList as r, dataObject as i, identifier as a } from "./capture.js";
|
|
3
|
+
import { shopInteger as o } from "./shop.js";
|
|
4
|
+
import { canonicalDataJson as s } from "./canonicalDataJson.js";
|
|
5
|
+
import { Effect as c, Result as l } from "effect";
|
|
6
|
+
import { systemSubject as u } from "@voltro/protocol";
|
|
7
|
+
import { createHash as d } from "node:crypto";
|
|
8
|
+
import { and as f, eq as p, queryFor as m } from "@voltro/database";
|
|
9
|
+
import { prepareSqlMutation as h, prepareSqlMutationGroup as g } from "@voltro/database/sql";
|
|
10
|
+
import { inventoryItemsTable as _, inventoryLedgerTable as v, inventoryOperationsTable as y, inventorySubjectsTable as b } from "@voltro/plugin-inventory/server";
|
|
11
|
+
//#region src/iapInventoryRefunds.server.ts
|
|
12
|
+
var x = (n) => n instanceof e ? n : t("unavailable"), S = async (e) => {
|
|
13
|
+
let n = await c.runPromise(e.pipe(c.result));
|
|
14
|
+
if (l.isFailure(n)) throw t(n.failure.code === "erased" ? "erased" : "unavailable");
|
|
15
|
+
return n.success;
|
|
16
|
+
}, C = (e) => d("sha256").update(s(JSON.parse(JSON.stringify(e)))).digest("hex"), w = (e) => {
|
|
17
|
+
let n = i(e, [
|
|
18
|
+
"operationId",
|
|
19
|
+
"kind",
|
|
20
|
+
"changes",
|
|
21
|
+
"at"
|
|
22
|
+
], "invalid_record");
|
|
23
|
+
if (n.kind !== "consume" && n.kind !== "grant") throw t("invalid_record");
|
|
24
|
+
let s = Object.freeze(r(n.changes, 4096, "invalid_record").map((e) => {
|
|
25
|
+
let r = i(e, ["instanceId", "delta"], "invalid_record"), s = o(r.delta, -1e6, 1e6);
|
|
26
|
+
if (s === 0 || n.kind === "consume" && s > 0 || n.kind === "grant" && s < 0) throw t("invalid_record");
|
|
27
|
+
return Object.freeze({
|
|
28
|
+
instanceId: a(r.instanceId),
|
|
29
|
+
delta: s
|
|
30
|
+
});
|
|
31
|
+
}));
|
|
32
|
+
if (new Set(s.map((e) => e.instanceId)).size !== s.length) throw t("invalid_record");
|
|
33
|
+
return Object.freeze({
|
|
34
|
+
operationId: a(n.operationId),
|
|
35
|
+
kind: n.kind,
|
|
36
|
+
changes: s,
|
|
37
|
+
at: o(n.at, 0, 864e13)
|
|
38
|
+
});
|
|
39
|
+
}, T = (e) => {
|
|
40
|
+
let n = i(e, [
|
|
41
|
+
"disposition",
|
|
42
|
+
"items",
|
|
43
|
+
"operations",
|
|
44
|
+
"targets"
|
|
45
|
+
], "invalid_record");
|
|
46
|
+
if (n.disposition !== "requireAll" && n.disposition !== "recoverRemaining") throw t("invalid_record");
|
|
47
|
+
let s = Object.freeze(r(n.items, 4096, "invalid_record").map((e) => {
|
|
48
|
+
let s = i(e, [
|
|
49
|
+
"grantId",
|
|
50
|
+
"instanceId",
|
|
51
|
+
"itemId",
|
|
52
|
+
"original",
|
|
53
|
+
"requested",
|
|
54
|
+
"recovered",
|
|
55
|
+
"unrecoverable",
|
|
56
|
+
"candidates"
|
|
57
|
+
], "invalid_record"), c = o(s.original, 1, 1e6), l = o(s.requested, 0, c), u = o(s.recovered, 0, l), d = o(s.unrecoverable, 0, l);
|
|
58
|
+
if (u + d !== l || n.disposition === "requireAll" && d !== 0) throw t("invalid_record");
|
|
59
|
+
let f = Object.freeze(r(s.candidates, 4096, "invalid_record").map((e) => a(e)));
|
|
60
|
+
if (!f.length || new Set(f).size !== f.length) throw t("invalid_record");
|
|
61
|
+
return Object.freeze({
|
|
62
|
+
candidates: f,
|
|
63
|
+
grantId: a(s.grantId),
|
|
64
|
+
instanceId: a(s.instanceId),
|
|
65
|
+
itemId: a(s.itemId),
|
|
66
|
+
original: c,
|
|
67
|
+
requested: l,
|
|
68
|
+
recovered: u,
|
|
69
|
+
unrecoverable: d
|
|
70
|
+
});
|
|
71
|
+
}));
|
|
72
|
+
if (new Set(s.map((e) => e.grantId + ":" + e.instanceId)).size !== s.length) throw t("invalid_record");
|
|
73
|
+
let c = Object.freeze(r(n.operations, 4096, "invalid_record").map(w));
|
|
74
|
+
if (new Set(c.map((e) => e.operationId)).size !== c.length) throw t("invalid_record");
|
|
75
|
+
let l = Object.freeze(r(n.targets, 4096, "invalid_record").map((e) => o(e, 0, s.length - 1)));
|
|
76
|
+
if (l.length !== c.length) throw t("invalid_record");
|
|
77
|
+
return Object.freeze({
|
|
78
|
+
disposition: n.disposition,
|
|
79
|
+
items: s,
|
|
80
|
+
operations: c,
|
|
81
|
+
targets: l
|
|
82
|
+
});
|
|
83
|
+
}, E = (e, r) => {
|
|
84
|
+
let l = i(r, ["inventory", "disposition"]), E = n(l.inventory, ["prepareConsume", "prepareGrant"]);
|
|
85
|
+
if (l.disposition !== "requireAll" && l.disposition !== "recoverRemaining") throw t("invalid_input");
|
|
86
|
+
let D = l.disposition, O = u("economy.iap-item-refunds"), k = async (e, n, r = !0) => {
|
|
87
|
+
let { original: i } = n, a = i.scope, o = (await e.query(m(b).where(f(p("tenantId", a.tenantId), p("ownerKind", "player"), p("ownerId", a.ownerId))).limit(2).descriptor))[0];
|
|
88
|
+
if (!o) throw t("erased");
|
|
89
|
+
if (r && await e.updateMany(b.tableName, { admission: 0 }, { where: p("id", o.id) }) !== 1) throw t("unavailable");
|
|
90
|
+
let c = (await e.query(m(b).where(p("id", o.id)).limit(1).descriptor))[0];
|
|
91
|
+
if (!c || c.erased !== !1 || c.ownerId !== a.ownerId || c.tenantId !== a.tenantId || c.ownerKind !== "player") throw t("erased");
|
|
92
|
+
let l = [];
|
|
93
|
+
for (let n of i.receipt.grants) {
|
|
94
|
+
let r = (await e.query(m(y).where(p("id", n.operationId)).limit(1).descriptor))[0];
|
|
95
|
+
if (!r || r.tenantId !== a.tenantId || r.ownerKey !== o.id || r.state !== "committed" || s(r.receipt) !== s(n)) throw t("invalid_record");
|
|
96
|
+
let c = await e.query(m(v).where(f(p("tenantId", a.tenantId), p("operationId", n.operationId))).limit(n.changes.length + 1).descriptor);
|
|
97
|
+
if (c.length !== n.changes.length) throw t("invalid_record");
|
|
98
|
+
for (let r of n.changes) {
|
|
99
|
+
let o = c.find((e) => e.instanceId === r.instanceId);
|
|
100
|
+
if (!o || o.ownerId !== a.ownerId || o.ownerKind !== "player" || o.delta !== r.delta || o.reason !== "iap.fulfill" || o.refKind !== "iap-order" || o.refId !== i.orderId || o.after === null) throw t("invalid_record");
|
|
101
|
+
let s = (await e.query(m(_).where(p("id", r.instanceId)).limit(1).descriptor))[0];
|
|
102
|
+
l.push({
|
|
103
|
+
grantId: n.operationId,
|
|
104
|
+
original: o,
|
|
105
|
+
current: s?.tenantId === a.tenantId && s.ownerId === a.ownerId && s.ownerKind === "player" ? s : null,
|
|
106
|
+
delta: r.delta
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (l.length > 4096) throw t("limit_exceeded");
|
|
111
|
+
return l;
|
|
112
|
+
}, A = (e, n) => {
|
|
113
|
+
let r = T(n), i = e.previous?.assets === null || !e.previous ? null : T(e.previous.assets);
|
|
114
|
+
if (r.disposition !== D || r.items.length !== e.original.receipt.grants.reduce((e, t) => e + t.changes.length, 0)) throw t("invalid_record");
|
|
115
|
+
let a = 0, o = 0;
|
|
116
|
+
for (let [n, c] of r.items.entries()) {
|
|
117
|
+
let l = e.original.receipt.grants.find((e) => e.operationId === c.grantId)?.changes.find((e) => e.instanceId === c.instanceId), u = e.original.receipt.grants.findIndex((e) => e.operationId === c.grantId);
|
|
118
|
+
if (e.original.product.offer.items[u]?.itemId !== c.itemId || !l || l.delta !== c.original || c.requested !== Number(BigInt(c.original) * BigInt(e.state.refundNumerator) / BigInt(e.state.refundDenominator))) throw t("invalid_record");
|
|
119
|
+
let d = i?.items.find((e) => e.grantId === c.grantId && e.instanceId === c.instanceId), f = new Set(d?.candidates ?? [c.instanceId]);
|
|
120
|
+
for (let [e, t] of r.operations.entries()) if (r.targets[e] === n && t.kind === "grant") for (let e of t.changes) f.add(e.instanceId);
|
|
121
|
+
if (s([...f].sort()) !== s([...c.candidates].sort())) throw t("invalid_record");
|
|
122
|
+
let p = c.recovered - (d?.recovered ?? 0);
|
|
123
|
+
if (p !== r.operations.reduce((e, t, i) => r.targets[i] === n ? e + t.changes.reduce((e, t) => e - t.delta, 0) : e, 0)) throw t("invalid_record");
|
|
124
|
+
p > 0 ? a += p : o -= p;
|
|
125
|
+
}
|
|
126
|
+
let c = r.operations.filter((e) => e.kind === "consume").reduce((e, t) => e + t.changes.reduce((e, t) => e - t.delta, 0), 0), l = r.operations.filter((e) => e.kind === "grant").reduce((e, t) => e + t.changes.reduce((e, t) => e + t.delta, 0), 0);
|
|
127
|
+
if (a !== c || o !== l) throw t("invalid_record");
|
|
128
|
+
return r;
|
|
129
|
+
};
|
|
130
|
+
return Object.freeze({
|
|
131
|
+
prepare: (n) => c.tryPromise({
|
|
132
|
+
catch: x,
|
|
133
|
+
try: async () => {
|
|
134
|
+
let r = n.previous?.assets === null || !n.previous ? null : T(n.previous.assets), c = async (e) => {
|
|
135
|
+
let t = await k(e, n), i = [];
|
|
136
|
+
for (let a of t) {
|
|
137
|
+
let t = r?.items.find((e) => e.grantId === a.grantId && e.instanceId === a.original.instanceId), o = [];
|
|
138
|
+
for (let r of t?.candidates ?? [String(a.original.instanceId)]) {
|
|
139
|
+
let t = (await e.query(m(_).where(p("id", r)).limit(1).descriptor))[0];
|
|
140
|
+
o.push(t?.tenantId === n.original.scope.tenantId && t.ownerId === n.original.scope.ownerId && t.ownerKind === "player" ? t : null);
|
|
141
|
+
}
|
|
142
|
+
i.push({
|
|
143
|
+
...a,
|
|
144
|
+
positions: o
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
return i;
|
|
148
|
+
}, l = await e.transactional(c), u = [], f = [], v = [], y = h(e, async (e) => {
|
|
149
|
+
if (C(await c(e)) !== C(l)) throw t("conflict");
|
|
150
|
+
return null;
|
|
151
|
+
});
|
|
152
|
+
f.push(y);
|
|
153
|
+
for (let e of l) {
|
|
154
|
+
let c = e.grantId, l = a(e.original.instanceId), p = a(e.original.itemId), m = r?.items.find((e) => e.grantId === c && e.instanceId === l), h = Number(BigInt(e.delta) * BigInt(n.state.refundNumerator) / BigInt(n.state.refundDenominator)), g = h - (m?.requested ?? 0), _ = m?.recovered ?? 0, y = "ifa_" + d("sha256").update(s([
|
|
155
|
+
n.original.orderId,
|
|
156
|
+
n.sequence,
|
|
157
|
+
c,
|
|
158
|
+
l
|
|
159
|
+
])).digest("hex").slice(0, 56), b = {
|
|
160
|
+
tenantId: n.original.scope.tenantId,
|
|
161
|
+
owner: {
|
|
162
|
+
ownerKind: "player",
|
|
163
|
+
ownerId: n.original.scope.ownerId
|
|
164
|
+
},
|
|
165
|
+
requestId: y,
|
|
166
|
+
ref: {
|
|
167
|
+
kind: "iap-order",
|
|
168
|
+
id: n.original.orderId
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
if (g > 0) {
|
|
172
|
+
let n = i(e.original.after, [
|
|
173
|
+
"id",
|
|
174
|
+
"itemId",
|
|
175
|
+
"schemaVersion",
|
|
176
|
+
"qty",
|
|
177
|
+
"attributes",
|
|
178
|
+
"acquiredAt",
|
|
179
|
+
"expiresAt",
|
|
180
|
+
"locked",
|
|
181
|
+
"source"
|
|
182
|
+
], "invalid_record"), r = g;
|
|
183
|
+
for (let t of e.positions) {
|
|
184
|
+
if (!r) break;
|
|
185
|
+
let e = t && t.itemId === p && t.locked === !1 && s(t.attributes) === s(n.attributes) ? o(t.qty, 1, 1e6) : 0, i = Math.min(r, e);
|
|
186
|
+
i && (f.push(await S(E.prepareConsume(O, {
|
|
187
|
+
...b,
|
|
188
|
+
requestId: b.requestId + "." + v.length,
|
|
189
|
+
instanceId: a(t.id),
|
|
190
|
+
qty: i,
|
|
191
|
+
reason: "iap.refund"
|
|
192
|
+
}))), v.push(u.length)), _ += i, r -= i;
|
|
193
|
+
}
|
|
194
|
+
if (D === "requireAll" && r) throw t("unavailable");
|
|
195
|
+
} else if (g < 0) {
|
|
196
|
+
let t = Math.max(0, _ - h);
|
|
197
|
+
if (t) {
|
|
198
|
+
let n = i(e.original.after, [
|
|
199
|
+
"id",
|
|
200
|
+
"itemId",
|
|
201
|
+
"schemaVersion",
|
|
202
|
+
"qty",
|
|
203
|
+
"attributes",
|
|
204
|
+
"acquiredAt",
|
|
205
|
+
"expiresAt",
|
|
206
|
+
"locked",
|
|
207
|
+
"source"
|
|
208
|
+
], "invalid_record");
|
|
209
|
+
f.push(await S(E.prepareGrant(O, {
|
|
210
|
+
...b,
|
|
211
|
+
itemId: p,
|
|
212
|
+
qty: t,
|
|
213
|
+
attributes: n.attributes,
|
|
214
|
+
reason: "iap.refund-reversed"
|
|
215
|
+
}))), v.push(u.length);
|
|
216
|
+
}
|
|
217
|
+
_ -= t;
|
|
218
|
+
}
|
|
219
|
+
u.push(Object.freeze({
|
|
220
|
+
candidates: m?.candidates ?? [l],
|
|
221
|
+
grantId: c,
|
|
222
|
+
instanceId: l,
|
|
223
|
+
itemId: p,
|
|
224
|
+
original: e.delta,
|
|
225
|
+
requested: h,
|
|
226
|
+
recovered: _,
|
|
227
|
+
unrecoverable: h - _
|
|
228
|
+
}));
|
|
229
|
+
}
|
|
230
|
+
return g(e, f, async (e, t) => {
|
|
231
|
+
let r = t.slice(1).map(w), i = u.map((e, t) => ({
|
|
232
|
+
...e,
|
|
233
|
+
candidates: [.../* @__PURE__ */ new Set([...e.candidates, ...r.flatMap((e, n) => e.kind === "grant" && v[n] === t ? e.changes.map((e) => e.instanceId) : [])])]
|
|
234
|
+
}));
|
|
235
|
+
return A(n, {
|
|
236
|
+
disposition: D,
|
|
237
|
+
items: i,
|
|
238
|
+
operations: r,
|
|
239
|
+
targets: v
|
|
240
|
+
});
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
}),
|
|
244
|
+
validate: A,
|
|
245
|
+
audit: async (e, n, r) => {
|
|
246
|
+
let i = A(n, r), a = n.original.scope;
|
|
247
|
+
await k(e, n, !1);
|
|
248
|
+
for (let [r, o] of i.operations.entries()) {
|
|
249
|
+
let c = (await e.query(m(y).where(p("id", o.operationId)).limit(1).descriptor))[0];
|
|
250
|
+
if (!c || c.state !== "committed" || c.tenantId !== a.tenantId || s(c.receipt) !== s(o)) throw t("invalid_record");
|
|
251
|
+
let l = await e.query(m(v).where(f(p("tenantId", a.tenantId), p("operationId", o.operationId))).limit(o.changes.length + 1).descriptor);
|
|
252
|
+
if (l.length !== o.changes.length) throw t("invalid_record");
|
|
253
|
+
for (let e of o.changes) {
|
|
254
|
+
let s = l.find((t) => t.instanceId === e.instanceId);
|
|
255
|
+
if (!s || s.itemId !== i.items[i.targets[r]].itemId || s.delta !== e.delta || s.ownerId !== a.ownerId || s.ownerKind !== "player" || s.reason !== (o.kind === "consume" ? "iap.refund" : "iap.refund-reversed") || s.refKind !== "iap-order" || s.refId !== n.original.orderId) throw t("invalid_record");
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
};
|
|
261
|
+
//#endregion
|
|
262
|
+
export { E as inventoryIapRefundAssets };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { economyError as e } from "./errors.js";
|
|
2
|
+
import { iapNotificationNotice as t } from "./iapNotifications.server.js";
|
|
3
|
+
import { IapNotificationCustodyPort as n } from "./iapNotificationStore.server.js";
|
|
4
|
+
import { iapNotificationStoreFixture as r } from "./iapNotificationStore.testFixtures.js";
|
|
5
|
+
import { Effect as i, Layer as a } from "effect";
|
|
6
|
+
import { randomBytes as o } from "node:crypto";
|
|
7
|
+
import { InMemoryDataStore as s, makeFieldCipher as c } from "@voltro/runtime";
|
|
8
|
+
//#region src/iapNotificationCustodyPort.fixture.ts
|
|
9
|
+
var l = /* @__PURE__ */ new WeakMap(), u = i.tryPromise({
|
|
10
|
+
try: async () => {
|
|
11
|
+
let e = c(o(32).toString("base64url")), t = { value: !0 };
|
|
12
|
+
return {
|
|
13
|
+
...await r(new s(), "fixture.notice", { cipher: { read: () => t.value ? e : void 0 } }),
|
|
14
|
+
alive: t
|
|
15
|
+
};
|
|
16
|
+
},
|
|
17
|
+
catch: () => e("unavailable")
|
|
18
|
+
}).pipe(i.map((t) => {
|
|
19
|
+
let n = !0, r = (t) => i.suspend(() => n ? t : i.fail(e("unavailable"))), a = Object.freeze({
|
|
20
|
+
initialize: () => r(t.custody.initialize()),
|
|
21
|
+
retain: (e) => r(t.custody.retain(e)),
|
|
22
|
+
restore: (e) => r(t.custody.restore(e)),
|
|
23
|
+
markProcessed: (e, n) => r(t.custody.markProcessed(e, n)),
|
|
24
|
+
pending: () => r(t.custody.pending()),
|
|
25
|
+
prune: () => r(t.custody.prune()),
|
|
26
|
+
exportSubject: (e) => r(t.custody.exportSubject(e)),
|
|
27
|
+
eraseSubject: (e) => r(t.custody.eraseSubject(e))
|
|
28
|
+
});
|
|
29
|
+
return l.set(a, {
|
|
30
|
+
evidence: t.n.evidence,
|
|
31
|
+
orderId: t.original.orderId
|
|
32
|
+
}), Object.freeze({
|
|
33
|
+
service: a,
|
|
34
|
+
evidence: t.n.evidence,
|
|
35
|
+
privacy: t.privacy,
|
|
36
|
+
close: i.sync(() => {
|
|
37
|
+
n = !1, t.alive.value = !1;
|
|
38
|
+
})
|
|
39
|
+
});
|
|
40
|
+
})), d = a.effect(n, i.acquireRelease(u, (e) => e.close).pipe(i.map((e) => e.service))), f = Object.freeze({
|
|
41
|
+
kind: "port",
|
|
42
|
+
tag: n,
|
|
43
|
+
fakeLayer: d,
|
|
44
|
+
probe: {
|
|
45
|
+
run: () => i.scoped(i.gen(function* () {
|
|
46
|
+
let r = yield* n, a = l.get(r);
|
|
47
|
+
if (!a) return yield* i.fail(e("unavailable"));
|
|
48
|
+
yield* r.initialize();
|
|
49
|
+
let o = yield* r.retain(a.evidence), s = yield* r.retain(a.evidence), c = yield* r.restore(o.id), u = yield* r.pending();
|
|
50
|
+
return {
|
|
51
|
+
state: o.state,
|
|
52
|
+
actualOrder: o.orderId === a.orderId,
|
|
53
|
+
stableIdentity: o.id === s.id,
|
|
54
|
+
restoredChannel: t(c).channel,
|
|
55
|
+
pending: u.length
|
|
56
|
+
};
|
|
57
|
+
}).pipe(i.provide(d))),
|
|
58
|
+
expected: {
|
|
59
|
+
state: "pending",
|
|
60
|
+
actualOrder: !0,
|
|
61
|
+
stableIdentity: !0,
|
|
62
|
+
restoredChannel: "ios",
|
|
63
|
+
pending: 1
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
//#endregion
|
|
68
|
+
export { d as iapNotificationCustodyFakeLayer, u as iapNotificationCustodyPortFixture, f as iapNotificationCustodyPortSystemFixture };
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { EconomyError as e, economyError as t } from "./errors.js";
|
|
2
|
+
import { dataObject as n } from "./capture.js";
|
|
3
|
+
import { IapNotificationPort as r, captureNotificationInput as i, iapNotificationNotice as a, issueVerifiedIapNotification as o } from "./iapNotifications.server.js";
|
|
4
|
+
import { Effect as s, Layer as c } from "effect";
|
|
5
|
+
import { randomUUID as l } from "node:crypto";
|
|
6
|
+
//#region src/iapNotificationPort.fixture.ts
|
|
7
|
+
var u = s.sync(() => {
|
|
8
|
+
let r = l(), a = Date.now(), c = !1, u = !1, d = Object.freeze({
|
|
9
|
+
initialize: () => s.suspend(() => u ? s.fail(t("unavailable")) : s.sync(() => {
|
|
10
|
+
c = !0;
|
|
11
|
+
})),
|
|
12
|
+
verify: (l) => {
|
|
13
|
+
let d;
|
|
14
|
+
try {
|
|
15
|
+
d = i(l, 2048);
|
|
16
|
+
} catch (n) {
|
|
17
|
+
return s.fail(n instanceof e ? n : t("invalid_input"));
|
|
18
|
+
}
|
|
19
|
+
return s.try({
|
|
20
|
+
try: () => {
|
|
21
|
+
if (!c || u) throw t("unavailable");
|
|
22
|
+
if (n(JSON.parse(d.body), ["event"], "invalid_record").event !== "fixture") throw t("forbidden");
|
|
23
|
+
return o({
|
|
24
|
+
channel: "ios",
|
|
25
|
+
applicationId: "fixture.application",
|
|
26
|
+
environment: "sandbox",
|
|
27
|
+
noticeId: r,
|
|
28
|
+
sourceType: "fixture.notification",
|
|
29
|
+
kind: "test",
|
|
30
|
+
occurredAt: a,
|
|
31
|
+
transactionId: null,
|
|
32
|
+
originalTransactionId: null,
|
|
33
|
+
storeProductId: null
|
|
34
|
+
}, {});
|
|
35
|
+
},
|
|
36
|
+
catch: (n) => n instanceof e ? n : t("invalid_record")
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
return Object.freeze({
|
|
41
|
+
service: d,
|
|
42
|
+
close: s.sync(() => {
|
|
43
|
+
c = !1, u = !0;
|
|
44
|
+
})
|
|
45
|
+
});
|
|
46
|
+
}).pipe(s.tap((e) => e.service.initialize())), d = c.effect(r, s.acquireRelease(u, (e) => e.close).pipe(s.map((e) => e.service))), f = Object.freeze({
|
|
47
|
+
kind: "port",
|
|
48
|
+
tag: r,
|
|
49
|
+
fakeLayer: d,
|
|
50
|
+
probe: {
|
|
51
|
+
run: () => s.scoped(s.gen(function* () {
|
|
52
|
+
let e = yield* (yield* r).verify({ body: JSON.stringify({ event: "fixture" }) }), t = a(e), n = !1;
|
|
53
|
+
try {
|
|
54
|
+
a({ ...e });
|
|
55
|
+
} catch {
|
|
56
|
+
n = !0;
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
kind: t.kind,
|
|
60
|
+
channel: t.channel,
|
|
61
|
+
copiedRefused: n,
|
|
62
|
+
noPurchaseAuthority: t.transactionId === null
|
|
63
|
+
};
|
|
64
|
+
}).pipe(s.provide(d))),
|
|
65
|
+
expected: {
|
|
66
|
+
kind: "test",
|
|
67
|
+
channel: "ios",
|
|
68
|
+
copiedRefused: !0,
|
|
69
|
+
noPurchaseAuthority: !0
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
//#endregion
|
|
74
|
+
export { d as iapNotificationFakeLayer, u as iapNotificationPortFixture, f as iapNotificationPortSystemFixture };
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { EconomyError as e, economyError as t } from "./errors.js";
|
|
2
|
+
import { captureBoundMethods as n, dataObject as r, identifier as i } from "./capture.js";
|
|
3
|
+
import { shopInteger as a } from "./shop.js";
|
|
4
|
+
import { captureIapNotificationService as o, readVerifiedIapNotification as s } from "./iapNotifications.server.js";
|
|
5
|
+
import { captureIapNotificationTargetOptions as c, readAcceptedIapNotificationTarget as l } from "./iapNotificationTarget.server.js";
|
|
6
|
+
import { captureIapCurrentStateService as u } from "./iapCurrentState.server.js";
|
|
7
|
+
import { captureIapRefundService as d } from "./iapRefunds.server.js";
|
|
8
|
+
import { captureIapNotificationCustodyService as f } from "./iapNotificationStore.server.js";
|
|
9
|
+
import { Context as p, Effect as m, Result as h } from "effect";
|
|
10
|
+
import { TextDecoder as g } from "node:util";
|
|
11
|
+
//#region src/iapNotificationProcessor.server.ts
|
|
12
|
+
var _ = class extends p.Service()("@voltro/IapNotificationProcessorPort") {}, v = (e) => n(e, [
|
|
13
|
+
"initialize",
|
|
14
|
+
"ingest",
|
|
15
|
+
"process",
|
|
16
|
+
"pending",
|
|
17
|
+
"prune",
|
|
18
|
+
"exportSubject",
|
|
19
|
+
"eraseSubject"
|
|
20
|
+
]), y = (e) => {
|
|
21
|
+
let a = r(e, [
|
|
22
|
+
"deployment",
|
|
23
|
+
"notifications",
|
|
24
|
+
"current",
|
|
25
|
+
"custody",
|
|
26
|
+
"refunds",
|
|
27
|
+
"orders",
|
|
28
|
+
"changed"
|
|
29
|
+
]);
|
|
30
|
+
if (a.changed !== void 0 && typeof a.changed != "function") throw t("invalid_input");
|
|
31
|
+
let p = a.changed, h = c(a.deployment), g = o(a.notifications), _ = u(a.current), v = f(a.custody), y = d(a.refunds), b = n(a.orders, ["prepareNotification"]), x = (e) => p === void 0 ? m.succeed(null) : l(e).pipe(m.map((e) => ({
|
|
32
|
+
tenantId: e.scope.tenantId,
|
|
33
|
+
ownerId: e.scope.ownerId,
|
|
34
|
+
offerId: e.receipt.offerId,
|
|
35
|
+
offerVersion: e.receipt.offerVersion
|
|
36
|
+
}))), S = (e, t) => p === void 0 || e === null ? m.void : m.suspend(() => p(Object.freeze({
|
|
37
|
+
...e,
|
|
38
|
+
orderId: t.orderId,
|
|
39
|
+
state: t.state
|
|
40
|
+
}))).pipe(m.catchCause(() => m.void)), C = (e) => m.try({
|
|
41
|
+
try: () => i(e),
|
|
42
|
+
catch: () => t("invalid_input")
|
|
43
|
+
}).pipe(m.flatMap((e) => v.restore(e).pipe(m.flatMap((e) => b.prepareNotification(h, e)), m.flatMap((t) => x(t).pipe(m.flatMap((n) => _.read(t).pipe(m.flatMap((e) => y.reconcile(e)), m.flatMap((t) => v.markProcessed(e, t).pipe(m.tap(() => S(n, t)))))))))), m.catchDefect(() => m.fail(t("unavailable"))));
|
|
44
|
+
return Object.freeze({
|
|
45
|
+
initialize: () => m.gen(function* () {
|
|
46
|
+
yield* v.initialize(), yield* g.initialize(), yield* _.initialize();
|
|
47
|
+
}).pipe(m.catchDefect(() => m.fail(t("unavailable")))),
|
|
48
|
+
ingest: (e) => g.verify(e).pipe(m.flatMap((e) => s(e).notice.kind === "test" ? m.succeed(null) : v.retain(e).pipe(m.flatMap((e) => e.state === "processed" ? m.succeed(e) : e.state === "pending" ? C(e.id) : m.fail(t(e.state === "erased" ? "erased" : "unavailable"))))), m.catchDefect(() => m.fail(t("unavailable")))),
|
|
49
|
+
process: C,
|
|
50
|
+
pending: v.pending,
|
|
51
|
+
prune: v.prune,
|
|
52
|
+
exportSubject: (e) => m.gen(function* () {
|
|
53
|
+
return {
|
|
54
|
+
notifications: yield* v.exportSubject(e),
|
|
55
|
+
refunds: yield* y.exportSubject(e)
|
|
56
|
+
};
|
|
57
|
+
}),
|
|
58
|
+
eraseSubject: (e) => v.eraseSubject(e).pipe(m.flatMap(() => y.eraseSubject(e)))
|
|
59
|
+
});
|
|
60
|
+
}, b = (n) => {
|
|
61
|
+
let i = r(n, [
|
|
62
|
+
"path",
|
|
63
|
+
"maxBodyBytes",
|
|
64
|
+
"processor",
|
|
65
|
+
"deliver"
|
|
66
|
+
]);
|
|
67
|
+
if (typeof i.path != "string" || !/^\/(?:[A-Za-z0-9_-]+\/)*[A-Za-z0-9_-]+$/.test(i.path) || i.path.length > 240) throw t("invalid_input");
|
|
68
|
+
let o = i.path, s = a(i.maxBodyBytes, 1024, 1048576), c = v(i.processor);
|
|
69
|
+
if (i.deliver !== void 0 && typeof i.deliver != "function") throw t("invalid_input");
|
|
70
|
+
let l = i.deliver;
|
|
71
|
+
return Object.freeze({
|
|
72
|
+
path: o,
|
|
73
|
+
method: "POST",
|
|
74
|
+
match: "exact",
|
|
75
|
+
answersOtherMethods: !0,
|
|
76
|
+
originGuard: "exempt",
|
|
77
|
+
maxBodyBytes: s,
|
|
78
|
+
handle: async (n) => {
|
|
79
|
+
let r = {
|
|
80
|
+
"cache-control": "no-store",
|
|
81
|
+
"x-content-type-options": "nosniff"
|
|
82
|
+
};
|
|
83
|
+
if (n.path !== o) return {
|
|
84
|
+
status: 404,
|
|
85
|
+
headers: r
|
|
86
|
+
};
|
|
87
|
+
if (n.method !== "POST") return {
|
|
88
|
+
status: 405,
|
|
89
|
+
headers: {
|
|
90
|
+
...r,
|
|
91
|
+
allow: "POST"
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
if (n.rawBody.byteLength > s) return {
|
|
95
|
+
status: 413,
|
|
96
|
+
headers: r
|
|
97
|
+
};
|
|
98
|
+
if (n.query || n.headers["content-encoding"] && n.headers["content-encoding"] !== "identity") return {
|
|
99
|
+
status: 400,
|
|
100
|
+
headers: r
|
|
101
|
+
};
|
|
102
|
+
let i;
|
|
103
|
+
try {
|
|
104
|
+
i = new g("utf-8", { fatal: !0 }).decode(n.rawBody);
|
|
105
|
+
} catch {
|
|
106
|
+
return {
|
|
107
|
+
status: 400,
|
|
108
|
+
headers: r
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
if (!i.length) return {
|
|
112
|
+
status: 400,
|
|
113
|
+
headers: r
|
|
114
|
+
};
|
|
115
|
+
let a = {
|
|
116
|
+
body: i,
|
|
117
|
+
...n.headers.authorization === void 0 ? {} : { authorization: n.headers.authorization },
|
|
118
|
+
headers: Object.fromEntries(Object.entries(n.headers).filter((e) => e[0] !== "authorization" && typeof e[1] == "string").slice(0, 64))
|
|
119
|
+
}, u = (l ? l(a) : m.succeed(!1)).pipe(m.flatMap((e) => e ? m.void : m.asVoid(c.ingest(a)))), d = await m.runPromise(u.pipe(m.result)).catch(() => h.fail(t("unavailable")));
|
|
120
|
+
if (h.isSuccess(d)) return {
|
|
121
|
+
status: 204,
|
|
122
|
+
headers: r
|
|
123
|
+
};
|
|
124
|
+
let f = d.failure;
|
|
125
|
+
return {
|
|
126
|
+
status: f instanceof e && f.code === "forbidden" ? 401 : f instanceof e && f.code === "limit_exceeded" ? 413 : f instanceof e && f.code === "invalid_input" ? 400 : 503,
|
|
127
|
+
headers: r,
|
|
128
|
+
body: "IAP notification refused",
|
|
129
|
+
contentType: "text/plain; charset=utf-8"
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
};
|
|
134
|
+
//#endregion
|
|
135
|
+
export { _ as IapNotificationProcessorPort, v as captureIapNotificationProcessorService, b as iapNotificationHttpRoute, y as iapNotificationProcessor };
|