@onesub/server 0.15.0 → 0.16.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/dist/__tests__/receipt-age.test.d.ts +7 -0
- package/dist/__tests__/receipt-age.test.d.ts.map +1 -0
- package/dist/index.cjs +6 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +6 -6
- package/dist/index.js.map +1 -1
- package/dist/providers/apple.d.ts.map +1 -1
- package/dist/providers/google.d.ts.map +1 -1
- package/package.json +5 -3
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* productReceiptMaxAgeHours — the one-time-purchase replay window is
|
|
3
|
+
* configurable (default 72h) so historical receipts can be validated on
|
|
4
|
+
* purpose (backend migrations, e2e against real store transactions).
|
|
5
|
+
*/
|
|
6
|
+
export {};
|
|
7
|
+
//# sourceMappingURL=receipt-age.test.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"receipt-age.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/receipt-age.test.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
|
package/dist/index.cjs
CHANGED
|
@@ -329,7 +329,6 @@ function mockValidateGoogleProduct(receipt, productId) {
|
|
|
329
329
|
}
|
|
330
330
|
|
|
331
331
|
// src/providers/apple.ts
|
|
332
|
-
var MAX_CONSUMABLE_RECEIPT_AGE_MS = 72 * 60 * 60 * 1e3;
|
|
333
332
|
function derBase64ToPem(der) {
|
|
334
333
|
return "-----BEGIN CERTIFICATE-----\n" + (der.match(/.{1,64}/g) ?? []).join("\n") + "\n-----END CERTIFICATE-----";
|
|
335
334
|
}
|
|
@@ -477,8 +476,9 @@ async function validateAppleConsumableReceipt(signedTransaction, config, expecte
|
|
|
477
476
|
log.warn("[onesub/apple] Purchase was revoked/refunded");
|
|
478
477
|
return null;
|
|
479
478
|
}
|
|
480
|
-
|
|
481
|
-
|
|
479
|
+
const maxAgeMs = (config.productReceiptMaxAgeHours ?? 72) * 60 * 60 * 1e3;
|
|
480
|
+
if (tx.purchaseDate && Date.now() - tx.purchaseDate > maxAgeMs) {
|
|
481
|
+
log.warn(`[onesub/apple] Consumable receipt too old (>${config.productReceiptMaxAgeHours ?? 72}h)`);
|
|
482
482
|
return null;
|
|
483
483
|
}
|
|
484
484
|
const transactionId = tx.transactionId ?? tx.originalTransactionId;
|
|
@@ -767,7 +767,6 @@ var GOOGLE_NOTIFICATION_TYPE = {
|
|
|
767
767
|
SUBSCRIPTION_REVOKED: 12,
|
|
768
768
|
SUBSCRIPTION_EXPIRED: 13
|
|
769
769
|
};
|
|
770
|
-
var MAX_PRODUCT_RECEIPT_AGE_MS = 72 * 60 * 60 * 1e3;
|
|
771
770
|
var refreshPromises = /* @__PURE__ */ new Map();
|
|
772
771
|
function googleTokenCacheKey(serviceAccountKey) {
|
|
773
772
|
let hash = 0;
|
|
@@ -1044,8 +1043,9 @@ async function validateGoogleProductReceipt(purchaseToken, productId, config, ty
|
|
|
1044
1043
|
}
|
|
1045
1044
|
if (purchase.purchaseTimeMillis) {
|
|
1046
1045
|
const purchaseTime = parseInt(purchase.purchaseTimeMillis, 10);
|
|
1047
|
-
|
|
1048
|
-
|
|
1046
|
+
const maxAgeMs = (config.productReceiptMaxAgeHours ?? 72) * 60 * 60 * 1e3;
|
|
1047
|
+
if (Date.now() - purchaseTime > maxAgeMs) {
|
|
1048
|
+
log.warn(`[onesub/google] Product receipt too old (>${config.productReceiptMaxAgeHours ?? 72}h)`);
|
|
1049
1049
|
return null;
|
|
1050
1050
|
}
|
|
1051
1051
|
}
|