@onesub/server 0.11.4 → 0.12.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 (71) hide show
  1. package/README.md +119 -2
  2. package/dist/__tests__/cache.test.d.ts +2 -0
  3. package/dist/__tests__/cache.test.d.ts.map +1 -0
  4. package/dist/__tests__/cache.test.js +34 -0
  5. package/dist/__tests__/cache.test.js.map +1 -0
  6. package/dist/__tests__/openapi.test.d.ts +2 -0
  7. package/dist/__tests__/openapi.test.d.ts.map +1 -0
  8. package/dist/__tests__/openapi.test.js +32 -0
  9. package/dist/__tests__/openapi.test.js.map +1 -0
  10. package/dist/__tests__/redis-store.test.d.ts +2 -0
  11. package/dist/__tests__/redis-store.test.d.ts.map +1 -0
  12. package/dist/__tests__/redis-store.test.js +117 -0
  13. package/dist/__tests__/redis-store.test.js.map +1 -0
  14. package/dist/__tests__/webhook-events.test.d.ts +2 -0
  15. package/dist/__tests__/webhook-events.test.d.ts.map +1 -0
  16. package/dist/__tests__/webhook-events.test.js +36 -0
  17. package/dist/__tests__/webhook-events.test.js.map +1 -0
  18. package/dist/__tests__/webhook-queue.test.d.ts +2 -0
  19. package/dist/__tests__/webhook-queue.test.d.ts.map +1 -0
  20. package/dist/__tests__/webhook-queue.test.js +26 -0
  21. package/dist/__tests__/webhook-queue.test.js.map +1 -0
  22. package/dist/cache.d.ts +32 -0
  23. package/dist/cache.d.ts.map +1 -0
  24. package/dist/cache.js +43 -0
  25. package/dist/cache.js.map +1 -0
  26. package/dist/index.cjs +3114 -0
  27. package/dist/index.cjs.map +1 -0
  28. package/dist/index.d.ts +34 -0
  29. package/dist/index.d.ts.map +1 -1
  30. package/dist/index.js +3072 -118
  31. package/dist/index.js.map +1 -1
  32. package/dist/openapi.d.ts +41 -0
  33. package/dist/openapi.d.ts.map +1 -0
  34. package/dist/openapi.js +196 -0
  35. package/dist/openapi.js.map +1 -0
  36. package/dist/providers/apple.d.ts +1 -1
  37. package/dist/providers/apple.d.ts.map +1 -1
  38. package/dist/providers/apple.js +45 -34
  39. package/dist/providers/apple.js.map +1 -1
  40. package/dist/providers/google.d.ts.map +1 -1
  41. package/dist/providers/google.js +49 -20
  42. package/dist/providers/google.js.map +1 -1
  43. package/dist/routes/admin.d.ts +2 -1
  44. package/dist/routes/admin.d.ts.map +1 -1
  45. package/dist/routes/admin.js +37 -1
  46. package/dist/routes/admin.js.map +1 -1
  47. package/dist/routes/webhook.d.ts +2 -1
  48. package/dist/routes/webhook.d.ts.map +1 -1
  49. package/dist/routes/webhook.js +21 -1
  50. package/dist/routes/webhook.js.map +1 -1
  51. package/dist/stores/redis.d.ts +60 -0
  52. package/dist/stores/redis.d.ts.map +1 -0
  53. package/dist/stores/redis.js +255 -0
  54. package/dist/stores/redis.js.map +1 -0
  55. package/dist/stores/schema.d.ts.map +1 -1
  56. package/dist/stores/schema.js +10 -0
  57. package/dist/stores/schema.js.map +1 -1
  58. package/dist/tracing.d.ts +32 -0
  59. package/dist/tracing.d.ts.map +1 -0
  60. package/dist/tracing.js +74 -0
  61. package/dist/tracing.js.map +1 -0
  62. package/dist/webhook-events.d.ts +58 -0
  63. package/dist/webhook-events.d.ts.map +1 -0
  64. package/dist/webhook-events.js +57 -0
  65. package/dist/webhook-events.js.map +1 -0
  66. package/dist/webhook-queue.d.ts +92 -0
  67. package/dist/webhook-queue.d.ts.map +1 -0
  68. package/dist/webhook-queue.js +108 -0
  69. package/dist/webhook-queue.js.map +1 -0
  70. package/package.json +33 -4
  71. package/sql/schema.sql +10 -0
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Optional OpenTelemetry tracing.
3
+ *
4
+ * `@opentelemetry/api` is an optional peer dependency — when it's installed
5
+ * onesub wraps its hot paths in spans. When it isn't, every span helper is
6
+ * a zero-cost no-op (no dynamic import, no Promise overhead).
7
+ *
8
+ * Why a custom helper instead of @opentelemetry/instrumentation-express:
9
+ * the express instrumentation traces every request, but onesub's interesting
10
+ * spans are specific operations (Apple JWT mint, Google OAuth refresh,
11
+ * receipt validation, webhook dispatch). Hand-spanned hot paths give
12
+ * actionable traces without doubling latency-tracker overhead.
13
+ */
14
+ type Span = {
15
+ setAttribute: (key: string, value: string | number | boolean) => void;
16
+ recordException: (err: unknown) => void;
17
+ setStatus: (status: {
18
+ code: number;
19
+ message?: string;
20
+ }) => void;
21
+ end: () => void;
22
+ };
23
+ /**
24
+ * Wrap an async operation in a span. When otel isn't installed the function
25
+ * runs unmodified — no span object is allocated.
26
+ *
27
+ * Use for operations whose latency or failure rate is operationally
28
+ * interesting: receipt validation, store writes, outbound API calls.
29
+ */
30
+ export declare function withSpan<T>(name: string, attributes: Record<string, string | number | boolean>, fn: (span: Span) => Promise<T>): Promise<T>;
31
+ export {};
32
+ //# sourceMappingURL=tracing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tracing.d.ts","sourceRoot":"","sources":["../src/tracing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAMH,KAAK,IAAI,GAAG;IACV,YAAY,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,KAAK,IAAI,CAAC;IACtE,eAAe,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,IAAI,CAAC;IACxC,SAAS,EAAE,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;IAChE,GAAG,EAAE,MAAM,IAAI,CAAC;CACjB,CAAC;AAkCF;;;;;;GAMG;AACH,wBAAsB,QAAQ,CAAC,CAAC,EAC9B,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,EACrD,EAAE,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,GAC7B,OAAO,CAAC,CAAC,CAAC,CAmBZ"}
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Optional OpenTelemetry tracing.
3
+ *
4
+ * `@opentelemetry/api` is an optional peer dependency — when it's installed
5
+ * onesub wraps its hot paths in spans. When it isn't, every span helper is
6
+ * a zero-cost no-op (no dynamic import, no Promise overhead).
7
+ *
8
+ * Why a custom helper instead of @opentelemetry/instrumentation-express:
9
+ * the express instrumentation traces every request, but onesub's interesting
10
+ * spans are specific operations (Apple JWT mint, Google OAuth refresh,
11
+ * receipt validation, webhook dispatch). Hand-spanned hot paths give
12
+ * actionable traces without doubling latency-tracker overhead.
13
+ */
14
+ const NOOP_SPAN = {
15
+ setAttribute: () => { },
16
+ recordException: () => { },
17
+ setStatus: () => { },
18
+ end: () => { },
19
+ };
20
+ /**
21
+ * Lazy-loaded tracer. We don't reach for `@opentelemetry/api` until the
22
+ * first `withSpan` call so process startup pays nothing when otel is absent.
23
+ */
24
+ let cachedTracer = null;
25
+ let resolved = false;
26
+ function getTracer() {
27
+ if (resolved)
28
+ return cachedTracer;
29
+ resolved = true;
30
+ try {
31
+ // Resolve synchronously via require — otel api is CJS-friendly.
32
+ // require is undefined in pure ESM at runtime; in that case skip otel.
33
+ const req = globalThis.require;
34
+ if (!req)
35
+ return null;
36
+ const otel = req('@opentelemetry/api');
37
+ cachedTracer = otel.trace.getTracer('@onesub/server', '1.0.0');
38
+ return cachedTracer;
39
+ }
40
+ catch {
41
+ return null;
42
+ }
43
+ }
44
+ /**
45
+ * Wrap an async operation in a span. When otel isn't installed the function
46
+ * runs unmodified — no span object is allocated.
47
+ *
48
+ * Use for operations whose latency or failure rate is operationally
49
+ * interesting: receipt validation, store writes, outbound API calls.
50
+ */
51
+ export async function withSpan(name, attributes, fn) {
52
+ const tracer = getTracer();
53
+ if (!tracer)
54
+ return fn(NOOP_SPAN);
55
+ return tracer.startActiveSpan(name, async (span) => {
56
+ for (const [k, v] of Object.entries(attributes))
57
+ span.setAttribute(k, v);
58
+ try {
59
+ const result = await fn(span);
60
+ // status code 1 = OK, 2 = ERROR (avoid importing the enum from otel api)
61
+ span.setStatus({ code: 1 });
62
+ return result;
63
+ }
64
+ catch (err) {
65
+ span.recordException(err);
66
+ span.setStatus({ code: 2, message: err.message });
67
+ throw err;
68
+ }
69
+ finally {
70
+ span.end();
71
+ }
72
+ });
73
+ }
74
+ //# sourceMappingURL=tracing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tracing.js","sourceRoot":"","sources":["../src/tracing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAaH,MAAM,SAAS,GAAS;IACtB,YAAY,EAAE,GAAG,EAAE,GAAE,CAAC;IACtB,eAAe,EAAE,GAAG,EAAE,GAAE,CAAC;IACzB,SAAS,EAAE,GAAG,EAAE,GAAE,CAAC;IACnB,GAAG,EAAE,GAAG,EAAE,GAAE,CAAC;CACd,CAAC;AAEF;;;GAGG;AACH,IAAI,YAAY,GAAkB,IAAI,CAAC;AACvC,IAAI,QAAQ,GAAG,KAAK,CAAC;AAErB,SAAS,SAAS;IAChB,IAAI,QAAQ;QAAE,OAAO,YAAY,CAAC;IAClC,QAAQ,GAAG,IAAI,CAAC;IAChB,IAAI,CAAC;QACH,gEAAgE;QAChE,uEAAuE;QACvE,MAAM,GAAG,GACP,UACD,CAAC,OAAO,CAAC;QACV,IAAI,CAAC,GAAG;YAAE,OAAO,IAAI,CAAC;QACtB,MAAM,IAAI,GAAG,GAAG,CAAC,oBAAoB,CAA+D,CAAC;QACrG,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAAC;QAC/D,OAAO,YAAY,CAAC;IACtB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAC5B,IAAY,EACZ,UAAqD,EACrD,EAA8B;IAE9B,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;IAC3B,IAAI,CAAC,MAAM;QAAE,OAAO,EAAE,CAAC,SAAS,CAAC,CAAC;IAElC,OAAO,MAAM,CAAC,eAAe,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;QACjD,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC;YAAE,IAAI,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QACzE,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,IAAI,CAAC,CAAC;YAC9B,yEAAyE;YACzE,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC;YAC5B,OAAO,MAAM,CAAC;QAChB,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;YAC1B,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAG,GAAa,CAAC,OAAO,EAAE,CAAC,CAAC;YAC7D,MAAM,GAAG,CAAC;QACZ,CAAC;gBAAS,CAAC;YACT,IAAI,CAAC,GAAG,EAAE,CAAC;QACb,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,58 @@
1
+ import type { CacheAdapter } from './cache.js';
2
+ /**
3
+ * Pluggable webhook-event idempotency store.
4
+ *
5
+ * Apple sends `notificationUUID` and Google Pub/Sub sends `messageId` — both
6
+ * are guaranteed unique per notification. Apple/Google will retry on any
7
+ * non-2xx response (Apple: ~3 days, Google: configurable Pub/Sub policy), so
8
+ * the same notification can hit our handler multiple times if the previous
9
+ * response timed out, the DB was briefly down, etc. We must not double-apply
10
+ * state changes (extra subscription days, refunded purchase being deleted
11
+ * twice, consumption response being PUT twice).
12
+ *
13
+ * `markIfNew` returns `true` when the caller should process the event,
14
+ * `false` when it has been seen before. Implementations decide retention —
15
+ * once-seen IDs are kept long enough that retries from the source can't beat
16
+ * the TTL (we recommend ≥ 7 days).
17
+ */
18
+ export interface WebhookEventStore {
19
+ /**
20
+ * Atomically register the given event id. Returns `true` if it's new (first
21
+ * time we've seen it), `false` if it was already seen.
22
+ *
23
+ * `provider` lets us key by source so Apple's notificationUUID and Google's
24
+ * messageId never collide.
25
+ */
26
+ markIfNew(provider: 'apple' | 'google', eventId: string): Promise<boolean>;
27
+ }
28
+ /**
29
+ * In-memory implementation. Suitable for single-instance dev/test; for
30
+ * production multi-instance use the Redis or Postgres variants so retries to
31
+ * other nodes are still deduped.
32
+ */
33
+ export declare class InMemoryWebhookEventStore implements WebhookEventStore {
34
+ private readonly ttlSeconds;
35
+ private readonly seen;
36
+ constructor(ttlSeconds?: number);
37
+ markIfNew(provider: 'apple' | 'google', eventId: string): Promise<boolean>;
38
+ private evictExpired;
39
+ }
40
+ /**
41
+ * Cache-backed implementation — works with any `CacheAdapter`.
42
+ *
43
+ * Uses a `get` → `set` sequence, which is **not** atomic under concurrent
44
+ * retries: two simultaneous calls for the same id can both read null and
45
+ * both return `true`. The downstream store PKs / BullMQ jobId dedup catch
46
+ * this worst case.
47
+ *
48
+ * For Redis deployments prefer `RedisWebhookEventStore` (from
49
+ * `@onesub/server`) which uses a single `SET NX` command and is fully
50
+ * atomic.
51
+ */
52
+ export declare class CacheWebhookEventStore implements WebhookEventStore {
53
+ private readonly cache;
54
+ private readonly ttlSeconds;
55
+ constructor(cache: CacheAdapter, ttlSeconds?: number);
56
+ markIfNew(provider: 'apple' | 'google', eventId: string): Promise<boolean>;
57
+ }
58
+ //# sourceMappingURL=webhook-events.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webhook-events.d.ts","sourceRoot":"","sources":["../src/webhook-events.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C;;;;;;;;;;;;;;;GAeG;AACH,MAAM,WAAW,iBAAiB;IAChC;;;;;;OAMG;IACH,SAAS,CAAC,QAAQ,EAAE,OAAO,GAAG,QAAQ,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAC5E;AAKD;;;;GAIG;AACH,qBAAa,yBAA0B,YAAW,iBAAiB;IAGrD,OAAO,CAAC,QAAQ,CAAC,UAAU;IAFvC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAA6B;gBAErB,UAAU,SAAsB;IAEvD,SAAS,CAAC,QAAQ,EAAE,OAAO,GAAG,QAAQ,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAQhF,OAAO,CAAC,YAAY;CAMrB;AAED;;;;;;;;;;;GAWG;AACH,qBAAa,sBAAuB,YAAW,iBAAiB;IAE5D,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,UAAU;gBADV,KAAK,EAAE,YAAY,EACnB,UAAU,SAAsB;IAG7C,SAAS,CAAC,QAAQ,EAAE,OAAO,GAAG,QAAQ,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;CAOjF"}
@@ -0,0 +1,57 @@
1
+ /** Default 7-day retention — covers Apple's 3-day retry window plus headroom. */
2
+ const DEFAULT_TTL_SECONDS = 7 * 24 * 60 * 60;
3
+ /**
4
+ * In-memory implementation. Suitable for single-instance dev/test; for
5
+ * production multi-instance use the Redis or Postgres variants so retries to
6
+ * other nodes are still deduped.
7
+ */
8
+ export class InMemoryWebhookEventStore {
9
+ ttlSeconds;
10
+ seen = new Map();
11
+ constructor(ttlSeconds = DEFAULT_TTL_SECONDS) {
12
+ this.ttlSeconds = ttlSeconds;
13
+ }
14
+ async markIfNew(provider, eventId) {
15
+ this.evictExpired();
16
+ const key = `${provider}:${eventId}`;
17
+ if (this.seen.has(key))
18
+ return false;
19
+ this.seen.set(key, Date.now() + this.ttlSeconds * 1000);
20
+ return true;
21
+ }
22
+ evictExpired() {
23
+ const now = Date.now();
24
+ for (const [key, expiresAt] of this.seen) {
25
+ if (expiresAt < now)
26
+ this.seen.delete(key);
27
+ }
28
+ }
29
+ }
30
+ /**
31
+ * Cache-backed implementation — works with any `CacheAdapter` (including
32
+ * `RedisCacheAdapter`), so multi-instance deployments dedupe across nodes.
33
+ *
34
+ * Uses the cache's atomic `set` semantics: we call `get` then `set` with TTL.
35
+ * This is correct under low contention; for very high concurrency the
36
+ * implementation may want a backend with native SETNX. RedisCacheAdapter's
37
+ * `set` is idempotent, so concurrent first-writes converge — the behavior is
38
+ * "at-most-twice" rather than "exactly once" in the worst race, which the
39
+ * downstream store-level idempotency (`originalTransactionId` PK) catches.
40
+ */
41
+ export class CacheWebhookEventStore {
42
+ cache;
43
+ ttlSeconds;
44
+ constructor(cache, ttlSeconds = DEFAULT_TTL_SECONDS) {
45
+ this.cache = cache;
46
+ this.ttlSeconds = ttlSeconds;
47
+ }
48
+ async markIfNew(provider, eventId) {
49
+ const key = `webhook:event:${provider}:${eventId}`;
50
+ const existing = await this.cache.get(key);
51
+ if (existing)
52
+ return false;
53
+ await this.cache.set(key, '1', this.ttlSeconds);
54
+ return true;
55
+ }
56
+ }
57
+ //# sourceMappingURL=webhook-events.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webhook-events.js","sourceRoot":"","sources":["../src/webhook-events.ts"],"names":[],"mappings":"AA6BA,iFAAiF;AACjF,MAAM,mBAAmB,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;AAE7C;;;;GAIG;AACH,MAAM,OAAO,yBAAyB;IAGP;IAFZ,IAAI,GAAG,IAAI,GAAG,EAAkB,CAAC;IAElD,YAA6B,aAAa,mBAAmB;QAAhC,eAAU,GAAV,UAAU,CAAsB;IAAG,CAAC;IAEjE,KAAK,CAAC,SAAS,CAAC,QAA4B,EAAE,OAAe;QAC3D,IAAI,CAAC,YAAY,EAAE,CAAC;QACpB,MAAM,GAAG,GAAG,GAAG,QAAQ,IAAI,OAAO,EAAE,CAAC;QACrC,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;YAAE,OAAO,KAAK,CAAC;QACrC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,CAAC;QACxD,OAAO,IAAI,CAAC;IACd,CAAC;IAEO,YAAY;QAClB,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACvB,KAAK,MAAM,CAAC,GAAG,EAAE,SAAS,CAAC,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;YACzC,IAAI,SAAS,GAAG,GAAG;gBAAE,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAC7C,CAAC;IACH,CAAC;CACF;AAED;;;;;;;;;;GAUG;AACH,MAAM,OAAO,sBAAsB;IAEd;IACA;IAFnB,YACmB,KAAmB,EACnB,aAAa,mBAAmB;QADhC,UAAK,GAAL,KAAK,CAAc;QACnB,eAAU,GAAV,UAAU,CAAsB;IAChD,CAAC;IAEJ,KAAK,CAAC,SAAS,CAAC,QAA4B,EAAE,OAAe;QAC3D,MAAM,GAAG,GAAG,iBAAiB,QAAQ,IAAI,OAAO,EAAE,CAAC;QACnD,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,GAAG,CAAS,GAAG,CAAC,CAAC;QACnD,IAAI,QAAQ;YAAE,OAAO,KAAK,CAAC;QAC3B,MAAM,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;QAChD,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
@@ -0,0 +1,92 @@
1
+ /**
2
+ * Webhook processing queue.
3
+ *
4
+ * The default in-process queue runs the handler synchronously inside the HTTP
5
+ * request — the same behavior you got before this interface existed. For
6
+ * production deployments that want decoupled retries, swap in a queue-backed
7
+ * implementation (BullMQ, SQS, etc.) so a slow DB or Apple/Google API call
8
+ * doesn't block the webhook from acknowledging.
9
+ *
10
+ * Failure semantics:
11
+ * - Handler throws → queue records the failure and (for retrying queues)
12
+ * re-runs with backoff. After max attempts the job
13
+ * lands in the dead-letter store.
14
+ * - Handler returns → ack to source.
15
+ *
16
+ * The HTTP route should always 200 once the job is *enqueued*. Synchronous
17
+ * processing happens to acknowledge later only because the in-process queue
18
+ * runs inline; for any async queue the route should ack after `enqueue()`.
19
+ */
20
+ export interface WebhookJob<T = unknown> {
21
+ provider: 'apple' | 'google';
22
+ /** Source-supplied event id (notificationUUID / messageId) for tracing. */
23
+ eventId: string;
24
+ payload: T;
25
+ }
26
+ export type WebhookHandler<T = unknown> = (job: WebhookJob<T>) => Promise<void>;
27
+ export interface WebhookQueue {
28
+ /**
29
+ * Enqueue a job. Returns once the job is durably accepted (synchronous for
30
+ * in-process; persisted-to-Redis for BullMQ).
31
+ */
32
+ enqueue<T>(job: WebhookJob<T>): Promise<void>;
33
+ /** Register the worker handler. Called once during middleware setup. */
34
+ setHandler<T>(handler: WebhookHandler<T>): void;
35
+ /** Optional: list jobs in the dead-letter queue (for the admin replay UI). */
36
+ listDeadLetters?(): Promise<DeadLetterRecord[]>;
37
+ /** Optional: replay a specific dead-letter job back through the handler. */
38
+ replayDeadLetter?(id: string): Promise<void>;
39
+ /** Optional: graceful shutdown. */
40
+ close?(): Promise<void>;
41
+ }
42
+ export interface DeadLetterRecord {
43
+ id: string;
44
+ job: WebhookJob;
45
+ attempts: number;
46
+ lastError: string;
47
+ failedAt: string;
48
+ }
49
+ /**
50
+ * Synchronous, in-process implementation. Default — no extra infra required.
51
+ * Handler runs inside the HTTP request, so route latency = handler latency.
52
+ *
53
+ * Failures are NOT retried — the original Apple/Google source retry policy
54
+ * is the durability layer (4xx = no retry, 5xx = source retries). This
55
+ * matches the pre-queue behavior.
56
+ */
57
+ export declare class InProcessWebhookQueue implements WebhookQueue {
58
+ private handler;
59
+ setHandler<T>(handler: WebhookHandler<T>): void;
60
+ enqueue<T>(job: WebhookJob<T>): Promise<void>;
61
+ }
62
+ export interface BullMQWebhookQueueOptions {
63
+ /** ioredis connection (or compatible options). Required. */
64
+ connection: unknown;
65
+ /** Queue name. Defaults to 'onesub-webhooks'. */
66
+ queueName?: string;
67
+ /** Max retry attempts before sending the job to the dead-letter list. */
68
+ maxAttempts?: number;
69
+ /** Backoff (ms) between attempts. Exponential: backoffMs * 2^(attempt-1). */
70
+ backoffMs?: number;
71
+ /** Worker concurrency. Defaults to 4. */
72
+ concurrency?: number;
73
+ }
74
+ export declare class BullMQWebhookQueue implements WebhookQueue {
75
+ private queueName;
76
+ private maxAttempts;
77
+ private backoffMs;
78
+ private concurrency;
79
+ private connection;
80
+ private queuePromise;
81
+ private workerPromise;
82
+ private handler;
83
+ constructor(opts: BullMQWebhookQueueOptions);
84
+ private getBullMQ;
85
+ private getQueue;
86
+ setHandler<T>(handler: WebhookHandler<T>): void;
87
+ enqueue<T>(job: WebhookJob<T>): Promise<void>;
88
+ listDeadLetters(): Promise<DeadLetterRecord[]>;
89
+ replayDeadLetter(id: string): Promise<void>;
90
+ close(): Promise<void>;
91
+ }
92
+ //# sourceMappingURL=webhook-queue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webhook-queue.d.ts","sourceRoot":"","sources":["../src/webhook-queue.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,WAAW,UAAU,CAAC,CAAC,GAAG,OAAO;IACrC,QAAQ,EAAE,OAAO,GAAG,QAAQ,CAAC;IAC7B,2EAA2E;IAC3E,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,CAAC,CAAC;CACZ;AAED,MAAM,MAAM,cAAc,CAAC,CAAC,GAAG,OAAO,IAAI,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAE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,kBAAmB,YAAW,YAAY;IACrD,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,UAAU,CAAU;IAI5B,OAAO,CAAC,YAAY,CAAqC;IACzD,OAAO,CAAC,aAAa,CAAsC;IAC3D,OAAO,CAAC,OAAO,CAA+B;gBAElC,IAAI,EAAE,yBAAyB;YAQ7B,SAAS;IAMvB,OAAO,CAAC,QAAQ;IAUhB,UAAU,CAAC,CAAC,EAAE,OAAO,EAAE,cAAc,CAAC,CAAC,CAAC,GAAG,IAAI;IAoBzC,OAAO,CAAC,CAAC,EAAE,GAAG,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAW7C,eAAe,IAAI,OAAO,CAAC,gBAAgB,EAAE,CAAC;IAY9C,gBAAgB,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAO3C,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAU7B"}
@@ -0,0 +1,108 @@
1
+ /**
2
+ * Synchronous, in-process implementation. Default — no extra infra required.
3
+ * Handler runs inside the HTTP request, so route latency = handler latency.
4
+ *
5
+ * Failures are NOT retried — the original Apple/Google source retry policy
6
+ * is the durability layer (4xx = no retry, 5xx = source retries). This
7
+ * matches the pre-queue behavior.
8
+ */
9
+ export class InProcessWebhookQueue {
10
+ handler = null;
11
+ setHandler(handler) {
12
+ this.handler = handler;
13
+ }
14
+ async enqueue(job) {
15
+ if (!this.handler) {
16
+ throw new Error('[onesub] webhook queue has no handler registered');
17
+ }
18
+ await this.handler(job);
19
+ }
20
+ }
21
+ export class BullMQWebhookQueue {
22
+ queueName;
23
+ maxAttempts;
24
+ backoffMs;
25
+ concurrency;
26
+ connection;
27
+ // Lazy-loaded so `bullmq` doesn't have to be installed unless this class
28
+ // is instantiated.
29
+ queuePromise = null;
30
+ workerPromise = null;
31
+ handler = null;
32
+ constructor(opts) {
33
+ this.connection = opts.connection;
34
+ this.queueName = opts.queueName ?? 'onesub-webhooks';
35
+ this.maxAttempts = opts.maxAttempts ?? 5;
36
+ this.backoffMs = opts.backoffMs ?? 1000;
37
+ this.concurrency = opts.concurrency ?? 4;
38
+ }
39
+ async getBullMQ() {
40
+ return import('bullmq').catch(() => {
41
+ throw new Error('[onesub] BullMQWebhookQueue requires the `bullmq` package. Run: npm install bullmq');
42
+ });
43
+ }
44
+ getQueue() {
45
+ if (!this.queuePromise) {
46
+ this.queuePromise = (async () => {
47
+ const { Queue } = await this.getBullMQ();
48
+ return new Queue(this.queueName, { connection: this.connection });
49
+ })();
50
+ }
51
+ return this.queuePromise;
52
+ }
53
+ setHandler(handler) {
54
+ this.handler = handler;
55
+ if (!this.workerPromise) {
56
+ this.workerPromise = (async () => {
57
+ const { Worker } = await this.getBullMQ();
58
+ return new Worker(this.queueName, async (job) => {
59
+ if (!this.handler)
60
+ throw new Error('[onesub] handler not set');
61
+ await this.handler(job.data);
62
+ }, {
63
+ connection: this.connection,
64
+ concurrency: this.concurrency,
65
+ });
66
+ })();
67
+ }
68
+ }
69
+ async enqueue(job) {
70
+ const queue = await this.getQueue();
71
+ await queue.add('webhook', job, {
72
+ attempts: this.maxAttempts,
73
+ backoff: { type: 'exponential', delay: this.backoffMs },
74
+ removeOnFail: false,
75
+ removeOnComplete: { age: 24 * 60 * 60, count: 1000 },
76
+ jobId: `${job.provider}:${job.eventId}`,
77
+ });
78
+ }
79
+ async listDeadLetters() {
80
+ const queue = await this.getQueue();
81
+ const failed = await queue.getFailed();
82
+ return failed.map((j) => ({
83
+ id: String(j.id),
84
+ job: j.data,
85
+ attempts: j.attemptsMade,
86
+ lastError: j.failedReason ?? 'unknown',
87
+ failedAt: new Date(j.finishedOn ?? Date.now()).toISOString(),
88
+ }));
89
+ }
90
+ async replayDeadLetter(id) {
91
+ const queue = await this.getQueue();
92
+ const job = await queue.getJob(id);
93
+ if (!job)
94
+ throw new Error(`[onesub] dead-letter job ${id} not found`);
95
+ await job.retry();
96
+ }
97
+ async close() {
98
+ if (this.workerPromise) {
99
+ const worker = await this.workerPromise;
100
+ await worker.close();
101
+ }
102
+ if (this.queuePromise) {
103
+ const queue = await this.queuePromise;
104
+ await queue.close();
105
+ }
106
+ }
107
+ }
108
+ //# sourceMappingURL=webhook-queue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webhook-queue.js","sourceRoot":"","sources":["../src/webhook-queue.ts"],"names":[],"mappings":"AAoDA;;;;;;;GAOG;AACH,MAAM,OAAO,qBAAqB;IACxB,OAAO,GAA0B,IAAI,CAAC;IAE9C,UAAU,CAAI,OAA0B;QACtC,IAAI,CAAC,OAAO,GAAG,OAAyB,CAAC;IAC3C,CAAC;IAED,KAAK,CAAC,OAAO,CAAI,GAAkB;QACjC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;YAClB,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;QACtE,CAAC;QACD,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC1B,CAAC;CACF;AAmED,MAAM,OAAO,kBAAkB;IACrB,SAAS,CAAS;IAClB,WAAW,CAAS;IACpB,SAAS,CAAS;IAClB,WAAW,CAAS;IACpB,UAAU,CAAU;IAE5B,yEAAyE;IACzE,mBAAmB;IACX,YAAY,GAAgC,IAAI,CAAC;IACjD,aAAa,GAAiC,IAAI,CAAC;IACnD,OAAO,GAA0B,IAAI,CAAC;IAE9C,YAAY,IAA+B;QACzC,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC;QAClC,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,IAAI,iBAAiB,CAAC;QACrD,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,IAAI,CAAC,CAAC;QACzC,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,IAAI,IAAI,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GAAG,GAAG,MAAM,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QACnC,IAAI,CAAC,GAAG;YAAE,MAAM,IAAI,KAAK,CAAC,4BAA4B,EAAE,YAAY,CAAC,CAAC;QACtE,MAAM,GAAG,CAAC,KAAK,EAAE,CAAC;IACpB,CAAC;IAED,KAAK,CAAC,KAAK;QACT,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;YACvB,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC;YACxC,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;QACvB,CAAC;QACD,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;YACtB,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC;YACtC,MAAM,KAAK,CAAC,KAAK,EAAE,CAAC;QACtB,CAAC;IACH,CAAC;CACF"}
package/package.json CHANGED
@@ -1,17 +1,29 @@
1
1
  {
2
2
  "name": "@onesub/server",
3
- "version": "0.11.4",
3
+ "version": "0.12.0",
4
4
  "description": "Server-side receipt validation middleware for react-native-iap. Apple StoreKit 2 + Google Play Billing. One line.",
5
- "main": "dist/index.js",
5
+ "main": "dist/index.cjs",
6
+ "module": "dist/index.js",
6
7
  "types": "dist/index.d.ts",
7
8
  "type": "module",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js",
13
+ "require": "./dist/index.cjs"
14
+ }
15
+ },
16
+ "sideEffects": false,
8
17
  "files": [
9
18
  "dist",
10
19
  "sql"
11
20
  ],
12
21
  "scripts": {
13
- "build": "tsc",
22
+ "build": "npm run build:types && npm run build:bundle",
23
+ "build:types": "tsc --emitDeclarationOnly",
24
+ "build:bundle": "tsup",
14
25
  "dev": "tsc --watch",
26
+ "size": "size-limit",
15
27
  "start": "node dist/index.js"
16
28
  },
17
29
  "keywords": [
@@ -41,24 +53,41 @@
41
53
  },
42
54
  "license": "MIT",
43
55
  "dependencies": {
44
- "@onesub/shared": "0.7.4",
56
+ "@onesub/shared": "0.7.5",
45
57
  "jose": "^6.2.2",
46
58
  "zod": "^4.3.6"
47
59
  },
48
60
  "peerDependencies": {
61
+ "@opentelemetry/api": ">=1.7.0",
62
+ "bullmq": ">=5.0.0",
49
63
  "express": "^4.17.0 || ^5.0.0",
64
+ "ioredis": ">=5.0.0",
50
65
  "pg": ">=8.0.0"
51
66
  },
52
67
  "peerDependenciesMeta": {
68
+ "@opentelemetry/api": {
69
+ "optional": true
70
+ },
71
+ "bullmq": {
72
+ "optional": true
73
+ },
74
+ "ioredis": {
75
+ "optional": true
76
+ },
53
77
  "pg": {
54
78
  "optional": true
55
79
  }
56
80
  },
57
81
  "devDependencies": {
82
+ "@size-limit/file": "^11.1.6",
58
83
  "@types/express": "^5.0.6",
84
+ "@types/ioredis-mock": "^8.2.5",
59
85
  "@types/node": "^20.17.0",
60
86
  "@types/pg": "^8.20.0",
61
87
  "express": "^5.2.1",
88
+ "ioredis-mock": "^8.9.0",
89
+ "size-limit": "^11.1.6",
90
+ "tsup": "^8.3.5",
62
91
  "typescript": "^5.7.0"
63
92
  },
64
93
  "engines": {
package/sql/schema.sql CHANGED
@@ -32,6 +32,16 @@ CREATE TABLE IF NOT EXISTS onesub_subscriptions (
32
32
  CREATE INDEX IF NOT EXISTS idx_onesub_subscriptions_user_id
33
33
  ON onesub_subscriptions (user_id, updated_at DESC);
34
34
 
35
+ -- Filter-helper indexes for /onesub/admin/subscriptions. Each filter column
36
+ -- is paired with updated_at DESC so the planner can serve "latest matching"
37
+ -- without sorting the full table once row count grows.
38
+ CREATE INDEX IF NOT EXISTS idx_onesub_subscriptions_status_updated
39
+ ON onesub_subscriptions (status, updated_at DESC);
40
+ CREATE INDEX IF NOT EXISTS idx_onesub_subscriptions_platform_updated
41
+ ON onesub_subscriptions (platform, updated_at DESC);
42
+ CREATE INDEX IF NOT EXISTS idx_onesub_subscriptions_product
43
+ ON onesub_subscriptions (product_id, updated_at DESC);
44
+
35
45
  -- Backfill columns for installs that already created the table from an older
36
46
  -- schema. Safe to re-run.
37
47
  ALTER TABLE onesub_subscriptions ADD COLUMN IF NOT EXISTS linked_purchase_token TEXT;