@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
package/dist/amount.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { economyError as e } from "./errors.js";
|
|
2
|
+
//#region src/amount.ts
|
|
3
|
+
var t = -(1n << 63n), n = (1n << 63n) - 1n, r = (r) => {
|
|
4
|
+
let i;
|
|
5
|
+
if (typeof r == "bigint") i = r;
|
|
6
|
+
else if (typeof r == "number" && Number.isSafeInteger(r) && !Object.is(r, -0)) i = BigInt(r);
|
|
7
|
+
else if (typeof r == "string" && r.length <= 20 && /^(?:0|-?[1-9][0-9]*)$/.test(r)) i = BigInt(r);
|
|
8
|
+
else throw e("invalid_amount");
|
|
9
|
+
if (i < t || i > n) throw e("overflow");
|
|
10
|
+
return i;
|
|
11
|
+
}, i = (e) => r(e).toString(), a = (t) => {
|
|
12
|
+
let n = r(t);
|
|
13
|
+
if (n < 0n) throw e("invalid_amount");
|
|
14
|
+
return n;
|
|
15
|
+
}, o = (t) => {
|
|
16
|
+
let n = r(t);
|
|
17
|
+
if (n <= 0n) throw e("invalid_amount");
|
|
18
|
+
return n;
|
|
19
|
+
};
|
|
20
|
+
//#endregion
|
|
21
|
+
export { r as economyAmount, i as economyAmountString, a as nonNegativeAmount, o as positiveAmount };
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import { EconomyError as e, economyError as t } from "./errors.js";
|
|
2
|
+
import { captureBoundMethods as n, dataObject as r } from "./capture.js";
|
|
3
|
+
import { shopInteger as i } from "./shop.js";
|
|
4
|
+
import { iapTimestamp as a } from "./iap.js";
|
|
5
|
+
import { canonicalDataJson as o } from "./canonicalDataJson.js";
|
|
6
|
+
import { iapCurrentStatePort as s } from "./iapCurrentState.server.js";
|
|
7
|
+
import { captureIapTransactionFacts as c, iapVerificationPort as l } from "./iapVerification.server.js";
|
|
8
|
+
import { iapProviderRecord as u, iapProviderText as d } from "./iapProviderCapture.server.js";
|
|
9
|
+
import { captureAppleIapTrust as f } from "./appleIapTrust.server.js";
|
|
10
|
+
import { appleIapDeliveryPort as p, appleIapNotificationPort as m } from "./appleIapNotifications.server.js";
|
|
11
|
+
import { Effect as h } from "effect";
|
|
12
|
+
import { createPrivateKey as g } from "node:crypto";
|
|
13
|
+
//#region src/appleIap.server.ts
|
|
14
|
+
var _ = (e) => {
|
|
15
|
+
if (typeof e != "string" || !/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(e)) throw t("invalid_record");
|
|
16
|
+
return e.toLowerCase();
|
|
17
|
+
}, v = (e) => {
|
|
18
|
+
let n = d(e, 128);
|
|
19
|
+
if (!/^[1-9][0-9]*$/.test(n)) throw t("invalid_record");
|
|
20
|
+
return n;
|
|
21
|
+
}, y = (e, n, r, o) => {
|
|
22
|
+
let s = u(e);
|
|
23
|
+
if (s.bundleId !== r || s.environment !== (o === "sandbox" ? "Sandbox" : "Production") || _(s.appAccountToken) !== _(n.accountToken) || s.inAppOwnershipType !== "PURCHASED" || s.revocationDate !== void 0 || s.revocationReason !== void 0 || s.revocationType !== void 0 || s.revocationPercentage !== void 0 || s.isUpgraded === !0 || s.advancedCommerceInfo !== void 0) throw t("forbidden");
|
|
24
|
+
let l = typeof s.type == "string" ? {
|
|
25
|
+
Consumable: "consumable",
|
|
26
|
+
"Non-Consumable": "non-consumable",
|
|
27
|
+
"Auto-Renewable Subscription": "subscription",
|
|
28
|
+
"Non-Renewing Subscription": "subscription"
|
|
29
|
+
}[s.type] : void 0;
|
|
30
|
+
if (l === void 0 || l !== n.product.kind || s.productId !== n.product.storeProductId) throw t("forbidden");
|
|
31
|
+
let d = a(s.purchaseDate), f = a(s.signedDate);
|
|
32
|
+
if (d > f || f > n.at + 6e4) throw t("invalid_record");
|
|
33
|
+
let p = null;
|
|
34
|
+
if (s.price !== void 0 || s.currency !== void 0) {
|
|
35
|
+
if (typeof s.currency != "string" || !/^[A-Z]{3}$/.test(s.currency)) throw t("invalid_record");
|
|
36
|
+
p = {
|
|
37
|
+
currency: s.currency,
|
|
38
|
+
units: String(i(s.price, 0, 2 ** 53 - 1)),
|
|
39
|
+
scale: 3
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
return c({
|
|
43
|
+
channel: "ios",
|
|
44
|
+
environment: o,
|
|
45
|
+
applicationId: r,
|
|
46
|
+
transactionId: v(s.transactionId),
|
|
47
|
+
originalTransactionId: v(s.originalTransactionId),
|
|
48
|
+
storeProductId: n.product.storeProductId,
|
|
49
|
+
kind: l,
|
|
50
|
+
quantity: i(s.quantity, 1, n.product.offer.maxQuantity),
|
|
51
|
+
purchasedAt: d,
|
|
52
|
+
expiresAt: l === "subscription" ? a(s.expiresDate) : null,
|
|
53
|
+
paid: p,
|
|
54
|
+
acknowledgement: "none",
|
|
55
|
+
consumption: "none"
|
|
56
|
+
});
|
|
57
|
+
}, b = (e) => {
|
|
58
|
+
let n = r(e, [
|
|
59
|
+
"signingKey",
|
|
60
|
+
"keyId",
|
|
61
|
+
"issuerId"
|
|
62
|
+
], "invalid_record");
|
|
63
|
+
if (typeof n.signingKey != "string" || n.signingKey.length === 0 || n.signingKey.length > 16384 || typeof n.keyId != "string" || !/^[A-Z0-9]{10}$/.test(n.keyId)) throw t("invalid_record");
|
|
64
|
+
let i = g(n.signingKey);
|
|
65
|
+
if (i.asymmetricKeyType !== "ec" || i.asymmetricKeyDetails?.namedCurve !== "prime256v1") throw t("invalid_record");
|
|
66
|
+
return Object.freeze({
|
|
67
|
+
signingKey: n.signingKey,
|
|
68
|
+
keyId: n.keyId,
|
|
69
|
+
issuerId: _(n.issuerId)
|
|
70
|
+
});
|
|
71
|
+
}, x = (e) => {
|
|
72
|
+
let t = f({
|
|
73
|
+
realMoney: e.realMoney,
|
|
74
|
+
environment: e.environment,
|
|
75
|
+
applicationId: e.applicationId,
|
|
76
|
+
appleRootCertificates: e.appleRootCertificates,
|
|
77
|
+
appAppleId: e.appAppleId
|
|
78
|
+
});
|
|
79
|
+
return Object.freeze({
|
|
80
|
+
...t,
|
|
81
|
+
credentials: n(e.credentials, ["read"])
|
|
82
|
+
});
|
|
83
|
+
}, S = (n) => {
|
|
84
|
+
let i = r(n, [
|
|
85
|
+
"realMoney",
|
|
86
|
+
"environment",
|
|
87
|
+
"applicationId",
|
|
88
|
+
"products",
|
|
89
|
+
"currencies",
|
|
90
|
+
"accounts",
|
|
91
|
+
"now",
|
|
92
|
+
"appleRootCertificates",
|
|
93
|
+
"appAppleId",
|
|
94
|
+
"credentials"
|
|
95
|
+
]), { roots: a, credentials: o, appAppleId: s, environment: c, applicationId: u } = x(i), d = {
|
|
96
|
+
realMoney: !0,
|
|
97
|
+
channel: "ios",
|
|
98
|
+
environment: c,
|
|
99
|
+
applicationId: u,
|
|
100
|
+
products: i.products,
|
|
101
|
+
currencies: i.currencies,
|
|
102
|
+
accounts: i.accounts,
|
|
103
|
+
...i.now === void 0 ? {} : { now: i.now }
|
|
104
|
+
};
|
|
105
|
+
return l(d, {
|
|
106
|
+
initialize: () => o.read().pipe(h.flatMap((e) => h.try({
|
|
107
|
+
try: () => b(e),
|
|
108
|
+
catch: () => t("unavailable")
|
|
109
|
+
})), h.flatMap(() => h.tryPromise({
|
|
110
|
+
try: async () => {
|
|
111
|
+
let e = await import("@apple/app-store-server-library"), t = d.environment === "sandbox" ? e.Environment.SANDBOX : e.Environment.PRODUCTION;
|
|
112
|
+
new e.SignedDataVerifier(a, !0, t, d.applicationId, s);
|
|
113
|
+
},
|
|
114
|
+
catch: () => t("unavailable")
|
|
115
|
+
}))),
|
|
116
|
+
verify: (n) => o.read().pipe(h.flatMap((e) => h.try({
|
|
117
|
+
try: () => b(e),
|
|
118
|
+
catch: () => t("unavailable")
|
|
119
|
+
})), h.flatMap((r) => h.tryPromise({
|
|
120
|
+
try: async () => {
|
|
121
|
+
let e = await import("@apple/app-store-server-library"), i = d.environment === "sandbox" ? e.Environment.SANDBOX : e.Environment.PRODUCTION, o = new e.SignedDataVerifier(a, !0, i, d.applicationId, s), c = y(await o.verifyAndDecodeTransaction(n.intent.receipt), n, d.applicationId, d.environment), l = await new e.AppStoreServerAPIClient(r.signingKey, r.keyId, r.issuerId, d.applicationId, i).getTransactionInfo(c.transactionId);
|
|
122
|
+
if (typeof l.signedTransactionInfo != "string") throw t("invalid_record");
|
|
123
|
+
let u = y(await o.verifyAndDecodeTransaction(l.signedTransactionInfo), n, d.applicationId, d.environment);
|
|
124
|
+
if (JSON.stringify(u) !== JSON.stringify(c)) throw t("conflict");
|
|
125
|
+
return u;
|
|
126
|
+
},
|
|
127
|
+
catch: (n) => n instanceof e ? n : t("unavailable")
|
|
128
|
+
})))
|
|
129
|
+
});
|
|
130
|
+
}, C = (e) => {
|
|
131
|
+
let n = x({
|
|
132
|
+
...r(e, [
|
|
133
|
+
"environment",
|
|
134
|
+
"applicationId",
|
|
135
|
+
"appleRootCertificates",
|
|
136
|
+
"appAppleId",
|
|
137
|
+
"credentials"
|
|
138
|
+
]),
|
|
139
|
+
realMoney: !0
|
|
140
|
+
}), i = (e) => {
|
|
141
|
+
let { channel: r, ...i } = e;
|
|
142
|
+
if (r !== "ios" || i.realMoney !== !0 || i.applicationId !== n.applicationId || i.environment !== n.environment) throw t("forbidden");
|
|
143
|
+
return {
|
|
144
|
+
...i,
|
|
145
|
+
appleRootCertificates: n.roots,
|
|
146
|
+
appAppleId: n.appAppleId,
|
|
147
|
+
credentials: n.credentials
|
|
148
|
+
};
|
|
149
|
+
};
|
|
150
|
+
return Object.freeze({
|
|
151
|
+
channel: "ios",
|
|
152
|
+
environment: n.environment,
|
|
153
|
+
applicationId: n.applicationId,
|
|
154
|
+
create: (e) => S(i(e)),
|
|
155
|
+
createCurrentState: (e) => {
|
|
156
|
+
let { products: t, currencies: n, ...r } = i(e);
|
|
157
|
+
return T({
|
|
158
|
+
...r,
|
|
159
|
+
accounts: e.accounts
|
|
160
|
+
});
|
|
161
|
+
},
|
|
162
|
+
createNotifications: (e) => {
|
|
163
|
+
let { products: t, currencies: n, accounts: r, credentials: a, ...o } = i(e);
|
|
164
|
+
return m(o);
|
|
165
|
+
},
|
|
166
|
+
createDeliveries: (e) => {
|
|
167
|
+
let { products: t, currencies: n, accounts: r, credentials: a, ...o } = i(e);
|
|
168
|
+
return p({
|
|
169
|
+
...o,
|
|
170
|
+
products: t
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
}, w = (e, n, r, s, c) => {
|
|
175
|
+
let l = u(e), d = l.revocationDate === void 0 ? null : a(l.revocationDate), f = 0, p = 1;
|
|
176
|
+
if (d === null) {
|
|
177
|
+
if (l.revocationReason !== void 0 || l.revocationType !== void 0 || l.revocationPercentage !== void 0) throw t("invalid_record");
|
|
178
|
+
} else {
|
|
179
|
+
let e = a(l.signedDate);
|
|
180
|
+
if (d < n.facts.purchasedAt || d > e || d > c || l.revocationReason !== void 0 && l.revocationReason !== 0 && l.revocationReason !== 1) throw t("invalid_record");
|
|
181
|
+
if (l.revocationType === "REFUND_PRORATED") p = 1e5, f = i(l.revocationPercentage, 1, p - 1);
|
|
182
|
+
else if (l.revocationType === void 0 || l.revocationType === "REFUND_FULL") {
|
|
183
|
+
if (l.revocationPercentage !== void 0 && l.revocationPercentage !== 1e5) throw t("invalid_record");
|
|
184
|
+
f = 1;
|
|
185
|
+
} else throw t("forbidden");
|
|
186
|
+
}
|
|
187
|
+
let m = {
|
|
188
|
+
...l,
|
|
189
|
+
revocationDate: void 0,
|
|
190
|
+
revocationReason: void 0,
|
|
191
|
+
revocationType: void 0,
|
|
192
|
+
revocationPercentage: void 0
|
|
193
|
+
}, h = {
|
|
194
|
+
channel: "ios",
|
|
195
|
+
offerId: n.product.offer.id,
|
|
196
|
+
offerVersion: n.product.offer.version,
|
|
197
|
+
requestId: n.orderId,
|
|
198
|
+
receipt: n.orderId
|
|
199
|
+
}, g = y(m, {
|
|
200
|
+
scope: n.scope,
|
|
201
|
+
product: n.product,
|
|
202
|
+
intent: h,
|
|
203
|
+
accountToken: n.accountToken,
|
|
204
|
+
at: c
|
|
205
|
+
}, r, s);
|
|
206
|
+
if (o(g) !== o(n.facts)) throw t("conflict");
|
|
207
|
+
return Object.freeze({
|
|
208
|
+
orderId: n.orderId,
|
|
209
|
+
channel: "ios",
|
|
210
|
+
state: f === 0 ? "active" : f === p ? "revoked" : "partially-refunded",
|
|
211
|
+
refundNumerator: f,
|
|
212
|
+
refundDenominator: p,
|
|
213
|
+
observedAt: a(c),
|
|
214
|
+
revokedAt: d
|
|
215
|
+
});
|
|
216
|
+
}, T = (n) => {
|
|
217
|
+
let i = r(n, [
|
|
218
|
+
"realMoney",
|
|
219
|
+
"environment",
|
|
220
|
+
"applicationId",
|
|
221
|
+
"accounts",
|
|
222
|
+
"maxAgeMs",
|
|
223
|
+
"now",
|
|
224
|
+
"appleRootCertificates",
|
|
225
|
+
"appAppleId",
|
|
226
|
+
"credentials"
|
|
227
|
+
]), { roots: o, credentials: c, appAppleId: l, environment: u, applicationId: d } = x(i), f = i.now ?? Date.now;
|
|
228
|
+
if (typeof f != "function") throw t("invalid_input");
|
|
229
|
+
let p = {
|
|
230
|
+
realMoney: !0,
|
|
231
|
+
channel: "ios",
|
|
232
|
+
environment: u,
|
|
233
|
+
applicationId: d,
|
|
234
|
+
accounts: i.accounts,
|
|
235
|
+
...i.maxAgeMs === void 0 ? {} : { maxAgeMs: i.maxAgeMs },
|
|
236
|
+
now: f
|
|
237
|
+
};
|
|
238
|
+
return s(p, {
|
|
239
|
+
initialize: () => c.read().pipe(h.flatMap((e) => h.try({
|
|
240
|
+
try: () => b(e),
|
|
241
|
+
catch: () => t("unavailable")
|
|
242
|
+
})), h.flatMap(() => h.tryPromise({
|
|
243
|
+
try: async () => {
|
|
244
|
+
let e = await import("@apple/app-store-server-library"), t = u === "sandbox" ? e.Environment.SANDBOX : e.Environment.PRODUCTION;
|
|
245
|
+
new e.SignedDataVerifier(o, !0, t, d, l);
|
|
246
|
+
},
|
|
247
|
+
catch: () => t("unavailable")
|
|
248
|
+
}))),
|
|
249
|
+
read: (n) => c.read().pipe(h.flatMap((e) => h.try({
|
|
250
|
+
try: () => b(e),
|
|
251
|
+
catch: () => t("unavailable")
|
|
252
|
+
})), h.flatMap((r) => h.tryPromise({
|
|
253
|
+
try: async () => {
|
|
254
|
+
let e = await import("@apple/app-store-server-library"), i = u === "sandbox" ? e.Environment.SANDBOX : e.Environment.PRODUCTION, s = new e.SignedDataVerifier(o, !0, i, d, l), c = await new e.AppStoreServerAPIClient(r.signingKey, r.keyId, r.issuerId, d, i).getTransactionInfo(v(n.facts.transactionId));
|
|
255
|
+
if (typeof c.signedTransactionInfo != "string") throw t("invalid_record");
|
|
256
|
+
return w(await s.verifyAndDecodeTransaction(c.signedTransactionInfo), n, d, u, a(f()));
|
|
257
|
+
},
|
|
258
|
+
catch: (n) => n instanceof e ? n : t("unavailable")
|
|
259
|
+
})))
|
|
260
|
+
});
|
|
261
|
+
};
|
|
262
|
+
//#endregion
|
|
263
|
+
export { T as appleIapCurrentStatePort, C as appleIapProvider, S as appleIapVerificationPort, w as projectAppleIapCurrentState, y as projectAppleIapTransaction };
|
|
@@ -0,0 +1,163 @@
|
|
|
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 { captureAppleIapTrust as d } from "./appleIapTrust.server.js";
|
|
8
|
+
import { Effect as f } from "effect";
|
|
9
|
+
//#region src/appleIapNotifications.server.ts
|
|
10
|
+
var p = (e) => {
|
|
11
|
+
let n = u(e, 128);
|
|
12
|
+
if (!/^[1-9][0-9]*$/.test(n)) throw t("invalid_record");
|
|
13
|
+
return n;
|
|
14
|
+
}, m = (e) => {
|
|
15
|
+
let n = u(e, 65536);
|
|
16
|
+
if (!/^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/.test(n)) throw t("invalid_record");
|
|
17
|
+
return n;
|
|
18
|
+
}, h = (e, n, i, o, s, d) => {
|
|
19
|
+
let f = l(e), m = l(f.data), h = o === "sandbox" ? "Sandbox" : "Production";
|
|
20
|
+
if (f.version !== "2.0" || m.bundleId !== i || m.environment !== h || s !== void 0 && m.appAppleId !== s || f.summary !== void 0 || f.externalPurchaseToken !== void 0 || f.appData !== void 0) throw t("forbidden");
|
|
21
|
+
let g = u(f.notificationUUID, 36).toLowerCase(), _ = u(f.notificationType, 128), v = f.subtype === void 0 ? null : u(f.subtype, 128);
|
|
22
|
+
if (!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/.test(g) || !/^[A-Z][A-Z0-9_]*$/.test(_) || v !== null && !/^[A-Z][A-Z0-9_]*$/.test(v)) throw t("invalid_record");
|
|
23
|
+
let y = c(f.signedDate, d), b = "ios." + _ + (v === null ? "" : "." + v);
|
|
24
|
+
if (_ === "TEST") {
|
|
25
|
+
if (n !== void 0) throw t("invalid_record");
|
|
26
|
+
return Object.freeze({
|
|
27
|
+
channel: "ios",
|
|
28
|
+
applicationId: i,
|
|
29
|
+
environment: o,
|
|
30
|
+
noticeId: g,
|
|
31
|
+
sourceType: b,
|
|
32
|
+
kind: "test",
|
|
33
|
+
occurredAt: y,
|
|
34
|
+
transactionId: null,
|
|
35
|
+
originalTransactionId: null,
|
|
36
|
+
storeProductId: null
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
let x = l(n);
|
|
40
|
+
if (x.bundleId !== i || x.environment !== h || x.advancedCommerceInfo !== void 0) throw t("forbidden");
|
|
41
|
+
let S = c(x.signedDate, d);
|
|
42
|
+
if (a(x.purchaseDate) > S) throw t("invalid_record");
|
|
43
|
+
let C = x.type === "Consumable" || x.type === "Non-Consumable" ? "one-time" : x.type === "Auto-Renewable Subscription" || x.type === "Non-Renewing Subscription" ? "subscription" : null;
|
|
44
|
+
if (C === null) throw t("invalid_record");
|
|
45
|
+
return Object.freeze({
|
|
46
|
+
channel: "ios",
|
|
47
|
+
applicationId: i,
|
|
48
|
+
environment: o,
|
|
49
|
+
noticeId: g,
|
|
50
|
+
sourceType: b,
|
|
51
|
+
kind: C,
|
|
52
|
+
occurredAt: y,
|
|
53
|
+
transactionId: p(x.transactionId),
|
|
54
|
+
originalTransactionId: x.originalTransactionId === void 0 ? null : p(x.originalTransactionId),
|
|
55
|
+
storeProductId: r(x.productId)
|
|
56
|
+
});
|
|
57
|
+
}, g = (r) => {
|
|
58
|
+
let c = n(r, [
|
|
59
|
+
"realMoney",
|
|
60
|
+
"environment",
|
|
61
|
+
"applicationId",
|
|
62
|
+
"appleRootCertificates",
|
|
63
|
+
"appAppleId",
|
|
64
|
+
"maxBodyBytes",
|
|
65
|
+
"now"
|
|
66
|
+
]), u = d({
|
|
67
|
+
realMoney: c.realMoney,
|
|
68
|
+
environment: c.environment,
|
|
69
|
+
applicationId: c.applicationId,
|
|
70
|
+
appleRootCertificates: c.appleRootCertificates,
|
|
71
|
+
appAppleId: c.appAppleId
|
|
72
|
+
}), g = i(c.maxBodyBytes ?? 65536, 1024, 1048576), _ = c.now ?? Date.now;
|
|
73
|
+
if (typeof _ != "function") throw t("invalid_input");
|
|
74
|
+
let v = async () => {
|
|
75
|
+
let e = await import("@apple/app-store-server-library");
|
|
76
|
+
return new e.SignedDataVerifier(u.roots, !0, u.environment === "sandbox" ? e.Environment.SANDBOX : e.Environment.PRODUCTION, u.applicationId, u.appAppleId);
|
|
77
|
+
};
|
|
78
|
+
return Object.freeze({
|
|
79
|
+
initialize: () => f.tryPromise({
|
|
80
|
+
try: async () => {
|
|
81
|
+
await v();
|
|
82
|
+
},
|
|
83
|
+
catch: () => t("unavailable")
|
|
84
|
+
}),
|
|
85
|
+
verify: (r) => {
|
|
86
|
+
let i;
|
|
87
|
+
try {
|
|
88
|
+
let e = o(r, g);
|
|
89
|
+
i = m(n(JSON.parse(e.body), ["signedPayload"], "invalid_record").signedPayload);
|
|
90
|
+
} catch (n) {
|
|
91
|
+
return f.fail(n instanceof e ? n : t("invalid_record"));
|
|
92
|
+
}
|
|
93
|
+
return f.tryPromise({
|
|
94
|
+
try: async () => {
|
|
95
|
+
let e = await v(), n = await e.verifyAndDecodeNotification(i), r = l(n.data), o = r.signedTransactionInfo === void 0 ? void 0 : await e.verifyAndDecodeTransaction(m(r.signedTransactionInfo)), c = r.signedRenewalInfo === void 0 ? void 0 : await e.verifyAndDecodeRenewalInfo(m(r.signedRenewalInfo));
|
|
96
|
+
if (c !== void 0) {
|
|
97
|
+
let e = l(c), n = l(o);
|
|
98
|
+
if (e.environment !== (u.environment === "sandbox" ? "Sandbox" : "Production") || p(e.originalTransactionId) !== p(n.originalTransactionId)) throw t("forbidden");
|
|
99
|
+
}
|
|
100
|
+
let d = h(n, o, u.applicationId, u.environment, u.appAppleId, a(_()));
|
|
101
|
+
return s(d, {
|
|
102
|
+
...o === void 0 ? {} : { transaction: o },
|
|
103
|
+
...c === void 0 ? {} : { renewal: c }
|
|
104
|
+
});
|
|
105
|
+
},
|
|
106
|
+
catch: (n) => n instanceof e ? n : t("unavailable")
|
|
107
|
+
}).pipe(f.catchDefect(() => f.fail(t("unavailable"))));
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
}, _ = (r) => {
|
|
111
|
+
let { products: a, ...s } = r, c = n(s, [
|
|
112
|
+
"realMoney",
|
|
113
|
+
"environment",
|
|
114
|
+
"applicationId",
|
|
115
|
+
"appleRootCertificates",
|
|
116
|
+
"appAppleId",
|
|
117
|
+
"maxBodyBytes",
|
|
118
|
+
"now"
|
|
119
|
+
]), u = d({
|
|
120
|
+
realMoney: c.realMoney,
|
|
121
|
+
environment: c.environment,
|
|
122
|
+
applicationId: c.applicationId,
|
|
123
|
+
appleRootCertificates: c.appleRootCertificates,
|
|
124
|
+
...c.appAppleId === void 0 ? {} : { appAppleId: c.appAppleId }
|
|
125
|
+
}), h = i(c.maxBodyBytes ?? 65536, 1024, 1048576), g = async () => {
|
|
126
|
+
let e = await import("@apple/app-store-server-library");
|
|
127
|
+
return new e.SignedDataVerifier(u.roots, !0, u.environment === "sandbox" ? e.Environment.SANDBOX : e.Environment.PRODUCTION, u.applicationId, u.appAppleId);
|
|
128
|
+
};
|
|
129
|
+
return Object.freeze({
|
|
130
|
+
initialize: () => f.tryPromise({
|
|
131
|
+
try: async () => {
|
|
132
|
+
await g();
|
|
133
|
+
},
|
|
134
|
+
catch: () => t("unavailable")
|
|
135
|
+
}),
|
|
136
|
+
read: (r) => {
|
|
137
|
+
let i;
|
|
138
|
+
try {
|
|
139
|
+
let e = o(r, h);
|
|
140
|
+
i = m(n(JSON.parse(e.body), ["signedPayload"], "invalid_record").signedPayload);
|
|
141
|
+
} catch (n) {
|
|
142
|
+
return f.fail(n instanceof e ? n : t("invalid_record"));
|
|
143
|
+
}
|
|
144
|
+
return f.tryPromise({
|
|
145
|
+
try: async () => {
|
|
146
|
+
let e = await g(), t = l(await e.verifyAndDecodeNotification(i)), n = l(t.data);
|
|
147
|
+
if (t.notificationType !== "DID_RENEW" || n.bundleId !== u.applicationId || n.environment !== (u.environment === "sandbox" ? "Sandbox" : "Production") || typeof n.signedTransactionInfo != "string") return null;
|
|
148
|
+
let r = m(n.signedTransactionInfo), o = l(await e.verifyAndDecodeTransaction(r)), s = a.find((e) => e.channel === "ios" && e.kind === "subscription" && e.offer.price.kind !== "virtual" && e.offer.price.kind !== "free" && (e.offer.price.kind === "real" ? e.offer.price : e.offer.price.real).storeProductIds.ios === o.productId);
|
|
149
|
+
return !s || typeof o.appAccountToken != "string" ? null : {
|
|
150
|
+
accountToken: o.appAccountToken.toLowerCase(),
|
|
151
|
+
offerId: s.offer.id,
|
|
152
|
+
offerVersion: s.offer.version ?? "1",
|
|
153
|
+
requestId: "renew.ios." + p(o.transactionId),
|
|
154
|
+
receipt: r
|
|
155
|
+
};
|
|
156
|
+
},
|
|
157
|
+
catch: (n) => n instanceof e ? n : t("unavailable")
|
|
158
|
+
}).pipe(f.catchDefect(() => f.fail(t("unavailable"))));
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
};
|
|
162
|
+
//#endregion
|
|
163
|
+
export { _ as appleIapDeliveryPort, g as appleIapNotificationPort, h as projectAppleIapNotification };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { economyError as e } from "./errors.js";
|
|
2
|
+
import { dataList as t, dataObject as n, identifier as r } from "./capture.js";
|
|
3
|
+
import { shopInteger as i } from "./shop.js";
|
|
4
|
+
import { iapEnvironment as a } from "./iap.js";
|
|
5
|
+
import { Buffer as o } from "node:buffer";
|
|
6
|
+
//#region src/appleIapTrust.server.ts
|
|
7
|
+
var s = (s) => {
|
|
8
|
+
let c = n(s, [
|
|
9
|
+
"realMoney",
|
|
10
|
+
"environment",
|
|
11
|
+
"applicationId",
|
|
12
|
+
"appleRootCertificates",
|
|
13
|
+
"appAppleId"
|
|
14
|
+
]);
|
|
15
|
+
if (c.realMoney !== !0) throw e(c.realMoney === !1 ? "real_money_disabled" : "invalid_input");
|
|
16
|
+
let l = a(c.environment), u = r(c.applicationId), d = t(c.appleRootCertificates, 8).map((t) => {
|
|
17
|
+
if (!(t instanceof Uint8Array) || t.byteLength < 128 || t.byteLength > 16384) throw e("invalid_input");
|
|
18
|
+
return o.from(Uint8Array.prototype.slice.call(t));
|
|
19
|
+
});
|
|
20
|
+
if (d.length === 0) throw e("invalid_input");
|
|
21
|
+
let f = c.appAppleId === void 0 ? void 0 : i(c.appAppleId, 1, 2 ** 53 - 1);
|
|
22
|
+
if (l === "production" && f === void 0) throw e("invalid_input");
|
|
23
|
+
return Object.freeze({
|
|
24
|
+
roots: d,
|
|
25
|
+
appAppleId: f,
|
|
26
|
+
environment: l,
|
|
27
|
+
applicationId: u
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
//#endregion
|
|
31
|
+
export { s as captureAppleIapTrust };
|
|
@@ -0,0 +1,113 @@
|
|
|
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 { captureCurrencies as o } from "./currency.js";
|
|
4
|
+
import { definePrice as s } from "./price.js";
|
|
5
|
+
import { captureShopOrderReceipt as c, shopBuyIntent as l, shopInteger as u } from "./shop.js";
|
|
6
|
+
import { shopOfferDigest as d } from "./shopStore.server.js";
|
|
7
|
+
import { defineBundle as f, projectBundleValue as p } from "./offerMerchandising.js";
|
|
8
|
+
import { Effect as m } from "effect";
|
|
9
|
+
//#region src/bundleValue.server.ts
|
|
10
|
+
var h = (h) => {
|
|
11
|
+
let g = i(h, [
|
|
12
|
+
"shop",
|
|
13
|
+
"bundle",
|
|
14
|
+
"currencies",
|
|
15
|
+
"realMoney",
|
|
16
|
+
"version",
|
|
17
|
+
"maxPriceAgeMs"
|
|
18
|
+
]), _ = n(g.shop, ["receipt"]), v = o(g.currencies), y = g.realMoney ?? !1;
|
|
19
|
+
if (typeof y != "boolean") throw t("invalid_input");
|
|
20
|
+
let b = f(g.bundle, v, y), x = a(g.version), S = u(g.maxPriceAgeMs, 0, 316224e5);
|
|
21
|
+
if (b.parts.some((e) => e.offer.price.kind !== "free" && (e.offer.price.kind !== "virtual" || e.offer.price.options.length !== 1))) throw t("invalid_price");
|
|
22
|
+
return Object.freeze({ read: (n, o) => {
|
|
23
|
+
try {
|
|
24
|
+
let f = i(n, [
|
|
25
|
+
"type",
|
|
26
|
+
"id",
|
|
27
|
+
"tenantId",
|
|
28
|
+
"kind",
|
|
29
|
+
"scopes",
|
|
30
|
+
"metadata"
|
|
31
|
+
]);
|
|
32
|
+
if (f.type !== "user" || f.kind !== void 0 && f.kind !== "guest") throw t("forbidden");
|
|
33
|
+
let h = Object.freeze({
|
|
34
|
+
type: "user",
|
|
35
|
+
tenantId: a(f.tenantId),
|
|
36
|
+
id: a(f.id),
|
|
37
|
+
...f.kind === "guest" ? { kind: "guest" } : {}
|
|
38
|
+
}), g = i(o, [
|
|
39
|
+
"at",
|
|
40
|
+
"bundlePrice",
|
|
41
|
+
"originals"
|
|
42
|
+
]), C = u(g.at, 0, 864e13), w = s(g.bundlePrice, v, y), T = Object.freeze(r(g.originals, 32).map((e) => {
|
|
43
|
+
let t = l(e);
|
|
44
|
+
return Object.freeze({
|
|
45
|
+
...t,
|
|
46
|
+
currency: t.currency ?? void 0
|
|
47
|
+
});
|
|
48
|
+
}));
|
|
49
|
+
if (T.length !== b.parts.length || new Set(T.map((e) => e.offerId)).size !== T.length) throw t("invalid_input");
|
|
50
|
+
return m.gen(function* () {
|
|
51
|
+
let n = [];
|
|
52
|
+
for (let r of T) {
|
|
53
|
+
let a = b.parts.find((e) => e.offer.id === r.offerId);
|
|
54
|
+
if (!a || r.qty !== 1 || r.offerVersion !== a.offer.version || r.offerDigest !== d(a.offer, x)) return yield* m.fail(t("conflict"));
|
|
55
|
+
let o = yield* m.try({
|
|
56
|
+
try: () => _.receipt(h, r),
|
|
57
|
+
catch: (n) => n instanceof e ? n : t("unavailable")
|
|
58
|
+
});
|
|
59
|
+
if (!m.isEffect(o)) return yield* m.fail(t("invalid_record"));
|
|
60
|
+
let s = yield* o, l = yield* m.try({
|
|
61
|
+
try: () => i(s, [
|
|
62
|
+
"requestId",
|
|
63
|
+
"state",
|
|
64
|
+
"receipt"
|
|
65
|
+
], "invalid_record"),
|
|
66
|
+
catch: (n) => n instanceof e ? n : t("invalid_record")
|
|
67
|
+
});
|
|
68
|
+
if (l.requestId !== r.requestId || ![
|
|
69
|
+
"not-observed",
|
|
70
|
+
"pending",
|
|
71
|
+
"fulfilled"
|
|
72
|
+
].includes(String(l.state))) return yield* m.fail(t("invalid_record"));
|
|
73
|
+
if (l.state !== "fulfilled") return yield* m.fail(t("not_found"));
|
|
74
|
+
let u = yield* m.try({
|
|
75
|
+
try: () => c(l.receipt),
|
|
76
|
+
catch: (n) => n instanceof e ? n : t("invalid_record")
|
|
77
|
+
});
|
|
78
|
+
if (u.offerId !== a.offer.id || u.offerVersion !== a.offer.version || u.offerDigest !== r.offerDigest || u.quantity !== 1) return yield* m.fail(t("invalid_record"));
|
|
79
|
+
let f = u.pricePaid, p = f.kind === "free" ? Object.freeze({ kind: "free" }) : Object.freeze({
|
|
80
|
+
kind: "virtual",
|
|
81
|
+
options: Object.freeze([Object.freeze({
|
|
82
|
+
currency: f.currency,
|
|
83
|
+
amount: f.amount
|
|
84
|
+
})])
|
|
85
|
+
});
|
|
86
|
+
n.push(Object.freeze({
|
|
87
|
+
offerId: a.offer.id,
|
|
88
|
+
offerVersion: a.offer.version,
|
|
89
|
+
referenceId: u.orderId,
|
|
90
|
+
observedAt: u.at,
|
|
91
|
+
price: p
|
|
92
|
+
}));
|
|
93
|
+
}
|
|
94
|
+
return yield* m.try({
|
|
95
|
+
try: () => p({
|
|
96
|
+
bundle: b,
|
|
97
|
+
currencies: v,
|
|
98
|
+
realMoney: y,
|
|
99
|
+
at: C,
|
|
100
|
+
maxPriceAgeMs: S,
|
|
101
|
+
bundlePrice: w,
|
|
102
|
+
prices: n
|
|
103
|
+
}),
|
|
104
|
+
catch: (n) => n instanceof e ? n : t("invalid_record")
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
} catch (n) {
|
|
108
|
+
return m.fail(n instanceof e ? n : t("invalid_input"));
|
|
109
|
+
}
|
|
110
|
+
} });
|
|
111
|
+
};
|
|
112
|
+
//#endregion
|
|
113
|
+
export { h as bundleValueFromShopReceipts };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { economyError as e } from "./errors.js";
|
|
2
|
+
//#region src/canonicalDataJson.ts
|
|
3
|
+
var t = (n) => {
|
|
4
|
+
if (Array.isArray(n)) return "[" + n.map(t).join(",") + "]";
|
|
5
|
+
if (typeof n == "object" && n) return "{" + Object.keys(n).sort().map((e) => JSON.stringify(e) + ":" + t(n[e])).join(",") + "}";
|
|
6
|
+
let r = JSON.stringify(n);
|
|
7
|
+
if (r === void 0) throw e("invalid_record");
|
|
8
|
+
return r;
|
|
9
|
+
};
|
|
10
|
+
//#endregion
|
|
11
|
+
export { t as canonicalDataJson };
|
package/dist/capture.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { economyError as e } from "./errors.js";
|
|
2
|
+
//#region src/capture.ts
|
|
3
|
+
var t = (t, n, r = "invalid_input") => {
|
|
4
|
+
if (typeof t != "object" || !t || Array.isArray(t)) throw e(r);
|
|
5
|
+
let i = Object.getPrototypeOf(t);
|
|
6
|
+
if (i !== Object.prototype && i !== null) throw e(r);
|
|
7
|
+
let a = Object.getOwnPropertyDescriptors(t), o = Object.create(null);
|
|
8
|
+
for (let t of Reflect.ownKeys(a)) {
|
|
9
|
+
if (typeof t != "string" || !n.includes(t)) throw e(r);
|
|
10
|
+
let i = a[t];
|
|
11
|
+
if (!i || !("value" in i) || !i.enumerable) throw e(r);
|
|
12
|
+
o[t] = i.value;
|
|
13
|
+
}
|
|
14
|
+
return Object.freeze(o);
|
|
15
|
+
}, n = (t, n = "invalid_input") => {
|
|
16
|
+
if (typeof t != "string" || t.length > 120 || !/^[A-Za-z0-9][A-Za-z0-9._:-]*$/.test(t)) throw e(n);
|
|
17
|
+
return t;
|
|
18
|
+
}, r = (t, n, r = "invalid_input") => {
|
|
19
|
+
if (!Array.isArray(t) || t.length > n) throw e(r);
|
|
20
|
+
let i = Object.getOwnPropertyDescriptors(t);
|
|
21
|
+
if (Reflect.ownKeys(i).length !== t.length + 1) throw e(r);
|
|
22
|
+
let a = [];
|
|
23
|
+
for (let n = 0; n < t.length; n++) {
|
|
24
|
+
let t = i[String(n)];
|
|
25
|
+
if (!t || !("value" in t) || !t.enumerable) throw e(r);
|
|
26
|
+
a.push(t.value);
|
|
27
|
+
}
|
|
28
|
+
return Object.freeze(a);
|
|
29
|
+
}, i = (t, n) => {
|
|
30
|
+
if (typeof t != "object" || !t || Array.isArray(t)) throw e("invalid_input");
|
|
31
|
+
let r = Object.create(null);
|
|
32
|
+
for (let i of n) {
|
|
33
|
+
let n = t, a = !1;
|
|
34
|
+
for (let o = 0; n !== null && o < 8; o++, n = Object.getPrototypeOf(n)) {
|
|
35
|
+
let o = Object.getOwnPropertyDescriptor(n, i);
|
|
36
|
+
if (o !== void 0) {
|
|
37
|
+
if (!("value" in o) || typeof o.value != "function") throw e("invalid_input");
|
|
38
|
+
r[i] = o.value.bind(t), a = !0;
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (!a) throw e("invalid_input");
|
|
43
|
+
}
|
|
44
|
+
return Object.freeze(r);
|
|
45
|
+
}, a = (t) => {
|
|
46
|
+
let n = r(t, 32).map((t) => {
|
|
47
|
+
if (typeof t != "string" || t.length > 120 || !/^[A-Za-z_][A-Za-z0-9_]*$/.test(t)) throw e("invalid_input");
|
|
48
|
+
return t;
|
|
49
|
+
});
|
|
50
|
+
if (n.length === 0 || new Set(n).size !== n.length) throw e("invalid_input");
|
|
51
|
+
return Object.freeze(n);
|
|
52
|
+
}, o = (e) => e === void 0 ? [] : typeof e == "string" ? [e] : e;
|
|
53
|
+
//#endregion
|
|
54
|
+
export { i as captureBoundMethods, a as captureQueryTables, r as dataList, t as dataObject, o as declaredSources, n as identifier };
|