@onesub/server 0.19.0 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/README.md +1 -0
  2. package/dist/__tests__/apple-jws-cache.test.d.ts +16 -0
  3. package/dist/__tests__/apple-jws-cache.test.d.ts.map +1 -0
  4. package/dist/__tests__/metrics-aggregate.test.d.ts +10 -0
  5. package/dist/__tests__/metrics-aggregate.test.d.ts.map +1 -0
  6. package/dist/__tests__/metrics-cache.test.d.ts +11 -0
  7. package/dist/__tests__/metrics-cache.test.d.ts.map +1 -0
  8. package/dist/__tests__/purchase-product-lookup.test.d.ts +17 -0
  9. package/dist/__tests__/purchase-product-lookup.test.d.ts.map +1 -0
  10. package/dist/__tests__/verified-key-cache.test.d.ts +18 -0
  11. package/dist/__tests__/verified-key-cache.test.d.ts.map +1 -0
  12. package/dist/http.d.ts.map +1 -1
  13. package/dist/index.cjs +341 -199
  14. package/dist/index.cjs.map +1 -1
  15. package/dist/index.d.ts +1 -1
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +342 -201
  18. package/dist/index.js.map +1 -1
  19. package/dist/metrics-aggregate.d.ts +82 -0
  20. package/dist/metrics-aggregate.d.ts.map +1 -0
  21. package/dist/metrics-cache.d.ts +20 -0
  22. package/dist/metrics-cache.d.ts.map +1 -0
  23. package/dist/providers/apple.d.ts +2 -0
  24. package/dist/providers/apple.d.ts.map +1 -1
  25. package/dist/providers/verified-key-cache.d.ts +75 -0
  26. package/dist/providers/verified-key-cache.d.ts.map +1 -0
  27. package/dist/routes/admin.d.ts.map +1 -1
  28. package/dist/routes/entitlements.d.ts +18 -1
  29. package/dist/routes/entitlements.d.ts.map +1 -1
  30. package/dist/routes/metrics.d.ts +8 -3
  31. package/dist/routes/metrics.d.ts.map +1 -1
  32. package/dist/routes/purchase.d.ts.map +1 -1
  33. package/dist/store.d.ts +25 -2
  34. package/dist/store.d.ts.map +1 -1
  35. package/dist/stores/postgres.d.ts +10 -0
  36. package/dist/stores/postgres.d.ts.map +1 -1
  37. package/dist/stores/redis.d.ts +12 -0
  38. package/dist/stores/redis.d.ts.map +1 -1
  39. package/package.json +2 -2
package/README.md CHANGED
@@ -47,6 +47,7 @@ app.use(createOneSubMiddleware({
47
47
  adminSecret: process.env.ADMIN_SECRET, // enables admin + metrics routes
48
48
  logger: require('pino')(), // any { info, warn, error } logger
49
49
  refundPolicy: 'immediate', // 'immediate' (default) | 'until_expiry'
50
+ metricsCacheTtlSeconds: 30, // 30 (default) | 0 to disable
50
51
  }));
51
52
 
52
53
  app.listen(4100);
@@ -0,0 +1,16 @@
1
+ /**
2
+ * decodeJws — the cached chain-verification wiring.
3
+ *
4
+ * The success path cannot be exercised here: a chain that passes
5
+ * `verifyAppleCertChain` must be signed by Apple's private keys, and the
6
+ * verifier correctly refuses everything else. The cache's own behaviour is
7
+ * tested in isolation in `verified-key-cache.test.ts` (with an injected
8
+ * verifier). What this file pins down is the part that only the real function
9
+ * can show — that introducing a cache did not weaken rejection:
10
+ *
11
+ * - a chain that fails verification is rejected EVERY time, not remembered
12
+ * - a missing x5c is still rejected
13
+ * - `skipVerification` still bypasses the whole path
14
+ */
15
+ export {};
16
+ //# sourceMappingURL=apple-jws-cache.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apple-jws-cache.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/apple-jws-cache.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * metrics-aggregate — the reduction behind every /onesub/metrics/* response.
3
+ *
4
+ * These semantics were previously only reachable through four HTTP handlers, so
5
+ * the fiddly parts (inclusive window edges, UTC bucket assignment, which records
6
+ * a distribution counts) had no direct coverage. They do now, and they are the
7
+ * contract any future SQL-side aggregation has to reproduce.
8
+ */
9
+ export {};
10
+ //# sourceMappingURL=metrics-aggregate.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metrics-aggregate.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/metrics-aggregate.test.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * createMetricsCache — the freshness bound on aggregate metrics responses.
3
+ *
4
+ * Every metrics endpoint reduces the whole store, so this cache is what stops a
5
+ * dashboard refresh loop from re-scanning it. The behaviours worth pinning down
6
+ * are the ones that would either defeat the purpose (a key that never repeats)
7
+ * or serve something wrong (a stale hit past its TTL, a shared entry between
8
+ * unrelated stores, a remembered failure).
9
+ */
10
+ export {};
11
+ //# sourceMappingURL=metrics-cache.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metrics-cache.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/metrics-cache.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Product-scoped purchase lookup — `PurchaseStore.getPurchasesForProduct`.
3
+ *
4
+ * Non-consumable validation used to read a user's entire purchase history and
5
+ * filter it in process, so an account with a long consumable history paid for
6
+ * every one of those rows on each lifetime-product purchase. The optional
7
+ * store method pushes the filter into an index instead.
8
+ *
9
+ * Covered here:
10
+ * - the store contract, including the most-recent-first ordering all three
11
+ * built-in stores must agree on
12
+ * - that the route actually uses the index-backed method when a store has one
13
+ * (responses are identical either way, so only a call count shows it)
14
+ * - that a store without the method still works, since it is optional
15
+ */
16
+ export {};
17
+ //# sourceMappingURL=purchase-product-lookup.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"purchase-product-lookup.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/purchase-product-lookup.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * VerifiedKeyCache — the memo behind Apple x5c chain verification.
3
+ *
4
+ * This cache sits directly on a security boundary: it decides when an
5
+ * expensive chain verification may be skipped. The real Apple path cannot be
6
+ * driven end-to-end in tests (a passing chain must be signed by Apple's private
7
+ * keys, and `verifyAppleCertChain` correctly refuses anything else), so the
8
+ * cache takes its verification as an injected function and the invariants are
9
+ * tested here directly:
10
+ *
11
+ * - a hit skips verification, a miss does not
12
+ * - every input participates in the entry identity (chain AND alg)
13
+ * - a failed verification is never remembered
14
+ * - no entry outlives the certificate chain that produced it
15
+ * - eviction never hands back a stale key
16
+ */
17
+ export {};
18
+ //# sourceMappingURL=verified-key-cache.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verified-key-cache.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/verified-key-cache.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG"}
@@ -1 +1 @@
1
- {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,oDAAoD;AACpD,eAAO,MAAM,wBAAwB,QAAS,CAAC;AAE/C;;;;GAIG;AACH,wBAAsB,gBAAgB,CACpC,KAAK,EAAE,WAAW,GAAG,GAAG,EACxB,IAAI,CAAC,EAAE,WAAW,EAClB,SAAS,SAA2B,GACnC,OAAO,CAAC,QAAQ,CAAC,CAkBnB"}
1
+ {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,oDAAoD;AACpD,eAAO,MAAM,wBAAwB,QAAS,CAAC;AAE/C;;;;GAIG;AACH,wBAAsB,gBAAgB,CACpC,KAAK,EAAE,WAAW,GAAG,GAAG,EACxB,IAAI,CAAC,EAAE,WAAW,EAClB,SAAS,SAA2B,GACnC,OAAO,CAAC,QAAQ,CAAC,CA2BnB"}