@onesub/server 0.14.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.
Files changed (140) hide show
  1. package/dist/__tests__/google-subscriptions-v2.test.d.ts +1 -1
  2. package/dist/__tests__/receipt-age.test.d.ts +7 -0
  3. package/dist/__tests__/receipt-age.test.d.ts.map +1 -0
  4. package/dist/__tests__/tracing.test.d.ts +2 -0
  5. package/dist/__tests__/tracing.test.d.ts.map +1 -0
  6. package/dist/cache.d.ts +5 -0
  7. package/dist/cache.d.ts.map +1 -1
  8. package/dist/index.cjs +178 -55
  9. package/dist/index.cjs.map +1 -1
  10. package/dist/index.js +178 -55
  11. package/dist/index.js.map +1 -1
  12. package/dist/providers/apple.d.ts.map +1 -1
  13. package/dist/providers/google.d.ts.map +1 -1
  14. package/dist/providers/mock.d.ts.map +1 -1
  15. package/dist/routes/admin.d.ts.map +1 -1
  16. package/dist/routes/purchase.d.ts.map +1 -1
  17. package/dist/routes/validate.d.ts.map +1 -1
  18. package/dist/routes/webhook-apple.d.ts.map +1 -1
  19. package/dist/routes/webhook-google.d.ts +1 -1
  20. package/dist/routes/webhook-google.d.ts.map +1 -1
  21. package/dist/store.d.ts.map +1 -1
  22. package/dist/stores/postgres.d.ts.map +1 -1
  23. package/dist/stores/redis.d.ts +1 -0
  24. package/dist/stores/redis.d.ts.map +1 -1
  25. package/dist/tracing.d.ts.map +1 -1
  26. package/dist/webhook-events.d.ts +10 -0
  27. package/dist/webhook-events.d.ts.map +1 -1
  28. package/package.json +5 -3
  29. package/dist/__tests__/admin-customer-detail.test.js +0 -146
  30. package/dist/__tests__/admin-customer-detail.test.js.map +0 -1
  31. package/dist/__tests__/admin-list-subscriptions.test.js +0 -192
  32. package/dist/__tests__/admin-list-subscriptions.test.js.map +0 -1
  33. package/dist/__tests__/admin-subscription-detail.test.js +0 -112
  34. package/dist/__tests__/admin-subscription-detail.test.js.map +0 -1
  35. package/dist/__tests__/apple-root-ca.test.js +0 -41
  36. package/dist/__tests__/apple-root-ca.test.js.map +0 -1
  37. package/dist/__tests__/apple-status-api.test.js +0 -345
  38. package/dist/__tests__/apple-status-api.test.js.map +0 -1
  39. package/dist/__tests__/cache.test.js +0 -34
  40. package/dist/__tests__/cache.test.js.map +0 -1
  41. package/dist/__tests__/entitlements.test.js +0 -268
  42. package/dist/__tests__/entitlements.test.js.map +0 -1
  43. package/dist/__tests__/error-codes.test.js +0 -173
  44. package/dist/__tests__/error-codes.test.js.map +0 -1
  45. package/dist/__tests__/fetch-hardening.test.js +0 -192
  46. package/dist/__tests__/fetch-hardening.test.js.map +0 -1
  47. package/dist/__tests__/google-paused.test.js +0 -126
  48. package/dist/__tests__/google-paused.test.js.map +0 -1
  49. package/dist/__tests__/google-price-change.test.js +0 -186
  50. package/dist/__tests__/google-price-change.test.js.map +0 -1
  51. package/dist/__tests__/google-subscriptions-v2.test.js +0 -206
  52. package/dist/__tests__/google-subscriptions-v2.test.js.map +0 -1
  53. package/dist/__tests__/lifecycle-scenarios.test.js +0 -579
  54. package/dist/__tests__/lifecycle-scenarios.test.js.map +0 -1
  55. package/dist/__tests__/lifecycle-states.test.js +0 -423
  56. package/dist/__tests__/lifecycle-states.test.js.map +0 -1
  57. package/dist/__tests__/linked-purchase-token.test.js +0 -227
  58. package/dist/__tests__/linked-purchase-token.test.js.map +0 -1
  59. package/dist/__tests__/metrics.test.js +0 -340
  60. package/dist/__tests__/metrics.test.js.map +0 -1
  61. package/dist/__tests__/mock-provider.test.js +0 -188
  62. package/dist/__tests__/mock-provider.test.js.map +0 -1
  63. package/dist/__tests__/openapi.test.js +0 -32
  64. package/dist/__tests__/openapi.test.js.map +0 -1
  65. package/dist/__tests__/paused-auto-resume.test.js +0 -162
  66. package/dist/__tests__/paused-auto-resume.test.js.map +0 -1
  67. package/dist/__tests__/providers.test.js +0 -321
  68. package/dist/__tests__/providers.test.js.map +0 -1
  69. package/dist/__tests__/redis-store.test.js +0 -166
  70. package/dist/__tests__/redis-store.test.js.map +0 -1
  71. package/dist/__tests__/refund-policy.test.js +0 -317
  72. package/dist/__tests__/refund-policy.test.js.map +0 -1
  73. package/dist/__tests__/schema.test.js +0 -46
  74. package/dist/__tests__/schema.test.js.map +0 -1
  75. package/dist/__tests__/store.test.js +0 -172
  76. package/dist/__tests__/store.test.js.map +0 -1
  77. package/dist/__tests__/test-utils.js +0 -30
  78. package/dist/__tests__/test-utils.js.map +0 -1
  79. package/dist/__tests__/webhook-apple.test.js +0 -247
  80. package/dist/__tests__/webhook-apple.test.js.map +0 -1
  81. package/dist/__tests__/webhook-events.test.js +0 -36
  82. package/dist/__tests__/webhook-events.test.js.map +0 -1
  83. package/dist/__tests__/webhook-google.test.js +0 -255
  84. package/dist/__tests__/webhook-google.test.js.map +0 -1
  85. package/dist/__tests__/webhook-queue.test.js +0 -26
  86. package/dist/__tests__/webhook-queue.test.js.map +0 -1
  87. package/dist/__tests__/webhook-refund.test.js +0 -313
  88. package/dist/__tests__/webhook-refund.test.js.map +0 -1
  89. package/dist/cache.js +0 -39
  90. package/dist/cache.js.map +0 -1
  91. package/dist/errors.js +0 -19
  92. package/dist/errors.js.map +0 -1
  93. package/dist/http.js +0 -36
  94. package/dist/http.js.map +0 -1
  95. package/dist/logger.js +0 -20
  96. package/dist/logger.js.map +0 -1
  97. package/dist/openapi.js +0 -196
  98. package/dist/openapi.js.map +0 -1
  99. package/dist/providers/apple-root-ca.js +0 -38
  100. package/dist/providers/apple-root-ca.js.map +0 -1
  101. package/dist/providers/apple.js +0 -630
  102. package/dist/providers/apple.js.map +0 -1
  103. package/dist/providers/google.js +0 -564
  104. package/dist/providers/google.js.map +0 -1
  105. package/dist/providers/mock.js +0 -93
  106. package/dist/providers/mock.js.map +0 -1
  107. package/dist/routes/admin.js +0 -327
  108. package/dist/routes/admin.js.map +0 -1
  109. package/dist/routes/apple-offer.js +0 -72
  110. package/dist/routes/apple-offer.js.map +0 -1
  111. package/dist/routes/entitlements.js +0 -130
  112. package/dist/routes/entitlements.js.map +0 -1
  113. package/dist/routes/metrics.js +0 -281
  114. package/dist/routes/metrics.js.map +0 -1
  115. package/dist/routes/purchase.js +0 -204
  116. package/dist/routes/purchase.js.map +0 -1
  117. package/dist/routes/status.js +0 -55
  118. package/dist/routes/status.js.map +0 -1
  119. package/dist/routes/validate.js +0 -70
  120. package/dist/routes/validate.js.map +0 -1
  121. package/dist/routes/webhook-apple.js +0 -145
  122. package/dist/routes/webhook-apple.js.map +0 -1
  123. package/dist/routes/webhook-google.js +0 -204
  124. package/dist/routes/webhook-google.js.map +0 -1
  125. package/dist/routes/webhook.js +0 -19
  126. package/dist/routes/webhook.js.map +0 -1
  127. package/dist/store.js +0 -145
  128. package/dist/store.js.map +0 -1
  129. package/dist/stores/postgres.js +0 -329
  130. package/dist/stores/postgres.js.map +0 -1
  131. package/dist/stores/redis.js +0 -297
  132. package/dist/stores/redis.js.map +0 -1
  133. package/dist/stores/schema.js +0 -67
  134. package/dist/stores/schema.js.map +0 -1
  135. package/dist/tracing.js +0 -74
  136. package/dist/tracing.js.map +0 -1
  137. package/dist/webhook-events.js +0 -58
  138. package/dist/webhook-events.js.map +0 -1
  139. package/dist/webhook-queue.js +0 -108
  140. package/dist/webhook-queue.js.map +0 -1
@@ -1,313 +0,0 @@
1
- /**
2
- * Refund / voided-purchase webhook tests.
3
- *
4
- * Covers:
5
- * - Apple webhook REFUND for IAP (Consumable / Non-Consumable) →
6
- * PurchaseStore row removed, SubscriptionStore untouched.
7
- * - Apple webhook REFUND for subscriptions still updates SubscriptionStore.
8
- * - Google voidedPurchaseNotification productType=2 → IAP row removed.
9
- * - Google voidedPurchaseNotification productType=1 → subscription canceled.
10
- * - decodeGoogleVoidedNotification recognises voided payload, ignores other kinds.
11
- */
12
- import { describe, it, expect, beforeEach } from 'vitest';
13
- import express from 'express';
14
- import { SUBSCRIPTION_STATUS } from '@onesub/shared';
15
- import { createWebhookRouter } from '../routes/webhook.js';
16
- import { InMemorySubscriptionStore, InMemoryPurchaseStore } from '../store.js';
17
- import { decodeGoogleVoidedNotification } from '../providers/google.js';
18
- // ── helpers ─────────────────────────────────────────────────────────────────
19
- function makeJws(payload) {
20
- const header = Buffer.from(JSON.stringify({ alg: 'ES256' })).toString('base64url');
21
- const body = Buffer.from(JSON.stringify(payload)).toString('base64url');
22
- return `${header}.${body}.fakesig`;
23
- }
24
- function appleConfig() {
25
- return {
26
- apple: { bundleId: 'com.example.app', skipJwsVerification: true },
27
- database: { url: '' },
28
- };
29
- }
30
- function googleConfig() {
31
- return {
32
- google: { packageName: 'com.example.app' },
33
- database: { url: '' },
34
- };
35
- }
36
- function buildServer(config, store, purchaseStore) {
37
- const app = express();
38
- app.use(express.json());
39
- app.use(createWebhookRouter(config, store, purchaseStore));
40
- return {
41
- async request(path, body) {
42
- // Use Node http directly for a lightweight test server.
43
- const server = app.listen(0);
44
- const address = server.address();
45
- const port = typeof address === 'object' && address ? address.port : 0;
46
- try {
47
- const resp = await fetch(`http://127.0.0.1:${port}${path}`, {
48
- method: 'POST',
49
- headers: { 'Content-Type': 'application/json' },
50
- body: JSON.stringify(body),
51
- });
52
- const text = await resp.text();
53
- let parsed = text;
54
- try {
55
- parsed = JSON.parse(text);
56
- }
57
- catch { /* keep as text */ }
58
- return { status: resp.status, body: parsed };
59
- }
60
- finally {
61
- await new Promise((resolve) => server.close(() => resolve()));
62
- }
63
- },
64
- };
65
- }
66
- const samplePurchase = (overrides) => ({
67
- userId: 'user_1',
68
- productId: 'credits_100',
69
- platform: 'apple',
70
- type: 'consumable',
71
- transactionId: 'txn_apple_consumable_001',
72
- purchasedAt: '2026-01-01T00:00:00.000Z',
73
- quantity: 1,
74
- ...overrides,
75
- });
76
- const sampleSub = (overrides) => ({
77
- userId: 'user_sub',
78
- productId: 'pro_monthly',
79
- platform: 'google',
80
- status: 'active',
81
- expiresAt: '2027-01-01T00:00:00.000Z',
82
- originalTransactionId: 'token_google_sub_xyz',
83
- purchasedAt: '2026-01-01T00:00:00.000Z',
84
- willRenew: true,
85
- ...overrides,
86
- });
87
- // ── Apple webhook: IAP REFUND ───────────────────────────────────────────────
88
- describe('Apple webhook — IAP REFUND', () => {
89
- let store;
90
- let purchaseStore;
91
- let server;
92
- beforeEach(() => {
93
- store = new InMemorySubscriptionStore();
94
- purchaseStore = new InMemoryPurchaseStore();
95
- server = buildServer(appleConfig(), store, purchaseStore);
96
- });
97
- it('removes the consumable purchase row on REFUND', async () => {
98
- await purchaseStore.savePurchase(samplePurchase({ transactionId: 'txn_consumable_a' }));
99
- const signedTransactionInfo = makeJws({
100
- bundleId: 'com.example.app',
101
- type: 'Consumable',
102
- productId: 'credits_100',
103
- transactionId: 'txn_consumable_a',
104
- originalTransactionId: 'orig_consumable_a',
105
- purchaseDate: Date.now(),
106
- });
107
- const signedRenewalInfo = makeJws({});
108
- const signedPayload = makeJws({
109
- notificationType: 'REFUND',
110
- data: { signedTransactionInfo, signedRenewalInfo },
111
- });
112
- const resp = await server.request('/onesub/webhook/apple', { signedPayload });
113
- expect(resp.status).toBe(200);
114
- expect(await purchaseStore.getPurchaseByTransactionId('txn_consumable_a')).toBeNull();
115
- });
116
- it('removes the non-consumable purchase row on REVOKE', async () => {
117
- await purchaseStore.savePurchase(samplePurchase({
118
- transactionId: 'txn_nc_a',
119
- type: 'non_consumable',
120
- productId: 'premium_unlock',
121
- }));
122
- const signedTransactionInfo = makeJws({
123
- bundleId: 'com.example.app',
124
- type: 'Non-Consumable',
125
- productId: 'premium_unlock',
126
- transactionId: 'txn_nc_a',
127
- originalTransactionId: 'txn_nc_a',
128
- purchaseDate: Date.now(),
129
- });
130
- const signedPayload = makeJws({
131
- notificationType: 'REVOKE',
132
- data: { signedTransactionInfo, signedRenewalInfo: makeJws({}) },
133
- });
134
- const resp = await server.request('/onesub/webhook/apple', { signedPayload });
135
- expect(resp.status).toBe(200);
136
- expect(await purchaseStore.getPurchaseByTransactionId('txn_nc_a')).toBeNull();
137
- });
138
- it('does not touch the SubscriptionStore on IAP REFUND', async () => {
139
- await store.save(sampleSub({ originalTransactionId: 'orig_sub_untouched' }));
140
- await purchaseStore.savePurchase(samplePurchase({ transactionId: 'iap_only' }));
141
- const signedTransactionInfo = makeJws({
142
- bundleId: 'com.example.app',
143
- type: 'Consumable',
144
- productId: 'credits_100',
145
- transactionId: 'iap_only',
146
- originalTransactionId: 'iap_only',
147
- purchaseDate: Date.now(),
148
- });
149
- const signedPayload = makeJws({
150
- notificationType: 'REFUND',
151
- data: { signedTransactionInfo, signedRenewalInfo: makeJws({}) },
152
- });
153
- await server.request('/onesub/webhook/apple', { signedPayload });
154
- expect(await store.getByTransactionId('orig_sub_untouched')).not.toBeNull();
155
- });
156
- it('still routes subscription REFUND through the SubscriptionStore', async () => {
157
- await store.save(sampleSub({
158
- platform: 'apple',
159
- originalTransactionId: 'orig_sub_apple',
160
- status: 'active',
161
- }));
162
- const signedTransactionInfo = makeJws({
163
- bundleId: 'com.example.app',
164
- type: 'Auto-Renewable Subscription',
165
- productId: 'pro_monthly',
166
- transactionId: 'tx_sub_apple_1',
167
- originalTransactionId: 'orig_sub_apple',
168
- purchaseDate: Date.now(),
169
- expiresDate: Date.now() + 86400000,
170
- });
171
- const signedPayload = makeJws({
172
- notificationType: 'REFUND',
173
- data: { signedTransactionInfo, signedRenewalInfo: makeJws({}) },
174
- });
175
- const resp = await server.request('/onesub/webhook/apple', { signedPayload });
176
- expect(resp.status).toBe(200);
177
- const updated = await store.getByTransactionId('orig_sub_apple');
178
- expect(updated?.status).toBe(SUBSCRIPTION_STATUS.CANCELED);
179
- });
180
- });
181
- // ── Google webhook: voidedPurchaseNotification ──────────────────────────────
182
- function makeVoidedPushBody(notification) {
183
- const json = JSON.stringify({
184
- version: '1.0',
185
- eventTimeMillis: String(Date.now()),
186
- ...notification,
187
- });
188
- return {
189
- message: {
190
- data: Buffer.from(json, 'utf-8').toString('base64'),
191
- messageId: '1',
192
- },
193
- subscription: 'projects/x/subscriptions/y',
194
- };
195
- }
196
- describe('Google webhook — voidedPurchaseNotification', () => {
197
- let store;
198
- let purchaseStore;
199
- let server;
200
- beforeEach(() => {
201
- store = new InMemorySubscriptionStore();
202
- purchaseStore = new InMemoryPurchaseStore();
203
- server = buildServer(googleConfig(), store, purchaseStore);
204
- });
205
- it('removes IAP row when productType=2 (one-time product refund)', async () => {
206
- await purchaseStore.savePurchase(samplePurchase({
207
- platform: 'google',
208
- transactionId: 'GPA.refunded_order',
209
- }));
210
- const resp = await server.request('/onesub/webhook/google', makeVoidedPushBody({
211
- packageName: 'com.example.app',
212
- voidedPurchaseNotification: {
213
- purchaseToken: 'tok_x',
214
- orderId: 'GPA.refunded_order',
215
- productType: 2,
216
- refundType: 1,
217
- },
218
- }));
219
- expect(resp.status).toBe(200);
220
- expect(await purchaseStore.getPurchaseByTransactionId('GPA.refunded_order')).toBeNull();
221
- });
222
- it('cancels subscription when productType=1', async () => {
223
- await store.save(sampleSub({ originalTransactionId: 'tok_sub' }));
224
- const resp = await server.request('/onesub/webhook/google', makeVoidedPushBody({
225
- packageName: 'com.example.app',
226
- voidedPurchaseNotification: {
227
- purchaseToken: 'tok_sub',
228
- orderId: 'GPA.sub_order',
229
- productType: 1,
230
- refundType: 1,
231
- },
232
- }));
233
- expect(resp.status).toBe(200);
234
- const updated = await store.getByTransactionId('tok_sub');
235
- expect(updated?.status).toBe(SUBSCRIPTION_STATUS.CANCELED);
236
- });
237
- it('rejects voided notification when packageName mismatches', async () => {
238
- const resp = await server.request('/onesub/webhook/google', makeVoidedPushBody({
239
- packageName: 'com.attacker.app',
240
- voidedPurchaseNotification: {
241
- purchaseToken: 'tok',
242
- orderId: 'GPA.x',
243
- productType: 2,
244
- refundType: 1,
245
- },
246
- }));
247
- expect(resp.status).toBe(400);
248
- });
249
- it('acknowledges with 200 even when the orderId is unknown', async () => {
250
- // Idempotent ack semantics — Google retries until 2xx; we don't want loops
251
- // when the row was already removed.
252
- const resp = await server.request('/onesub/webhook/google', makeVoidedPushBody({
253
- packageName: 'com.example.app',
254
- voidedPurchaseNotification: {
255
- purchaseToken: 'tok',
256
- orderId: 'GPA.unknown',
257
- productType: 2,
258
- refundType: 1,
259
- },
260
- }));
261
- expect(resp.status).toBe(200);
262
- });
263
- });
264
- // ── decodeGoogleVoidedNotification unit ─────────────────────────────────────
265
- describe('decodeGoogleVoidedNotification', () => {
266
- it('returns null for subscription notifications', () => {
267
- const json = JSON.stringify({
268
- packageName: 'com.example.app',
269
- eventTimeMillis: '0',
270
- subscriptionNotification: {
271
- version: '1.0',
272
- notificationType: 4,
273
- purchaseToken: 't',
274
- subscriptionId: 'p',
275
- },
276
- });
277
- const result = decodeGoogleVoidedNotification({
278
- message: { data: Buffer.from(json).toString('base64'), messageId: '1' },
279
- subscription: 's',
280
- });
281
- expect(result).toBeNull();
282
- });
283
- it('extracts voided payload fields', () => {
284
- const json = JSON.stringify({
285
- packageName: 'com.example.app',
286
- eventTimeMillis: '0',
287
- voidedPurchaseNotification: {
288
- purchaseToken: 'tok123',
289
- orderId: 'GPA.xyz',
290
- productType: 2,
291
- refundType: 1,
292
- },
293
- });
294
- const result = decodeGoogleVoidedNotification({
295
- message: { data: Buffer.from(json).toString('base64'), messageId: '1' },
296
- subscription: 's',
297
- });
298
- expect(result).toEqual({
299
- purchaseToken: 'tok123',
300
- orderId: 'GPA.xyz',
301
- productType: 2,
302
- refundType: 1,
303
- packageName: 'com.example.app',
304
- });
305
- });
306
- it('returns null for malformed base64', () => {
307
- expect(decodeGoogleVoidedNotification({
308
- message: { data: '!!!not-base64!!!', messageId: '1' },
309
- subscription: 's',
310
- })).toBeNull();
311
- });
312
- });
313
- //# sourceMappingURL=webhook-refund.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"webhook-refund.test.js","sourceRoot":"","sources":["../../src/__tests__/webhook-refund.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAC1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AC,CAAC;QACH,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC;YACrB,aAAa,EAAE,QAAQ;YACvB,OAAO,EAAE,SAAS;YAClB,WAAW,EAAE,CAAC;YACd,UAAU,EAAE,CAAC;YACb,WAAW,EAAE,iBAAiB;SAC/B,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,mCAAmC,EAAE,GAAG,EAAE;QAC3C,MAAM,CAAC,8BAA8B,CAAC;YACpC,OAAO,EAAE,EAAE,IAAI,EAAE,kBAAkB,EAAE,SAAS,EAAE,GAAG,EAAE;YACrD,YAAY,EAAE,GAAG;SAClB,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;IACjB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
package/dist/cache.js DELETED
@@ -1,39 +0,0 @@
1
- /**
2
- * Process-local in-memory cache. Default for single-instance deployments.
3
- */
4
- export class InMemoryCacheAdapter {
5
- entries = new Map();
6
- async get(key) {
7
- const entry = this.entries.get(key);
8
- if (!entry)
9
- return null;
10
- if (entry.expiresAt !== 0 && entry.expiresAt < Date.now()) {
11
- this.entries.delete(key);
12
- return null;
13
- }
14
- return entry.value;
15
- }
16
- async set(key, value, ttlSeconds) {
17
- const expiresAt = ttlSeconds && ttlSeconds > 0 ? Date.now() + ttlSeconds * 1000 : 0;
18
- this.entries.set(key, { value, expiresAt });
19
- }
20
- async del(key) {
21
- this.entries.delete(key);
22
- }
23
- /** Test helper — clear everything. Not part of the public CacheAdapter contract. */
24
- clear() {
25
- this.entries.clear();
26
- }
27
- }
28
- /**
29
- * Module-level singleton used by providers when no per-call adapter is
30
- * supplied. Keeps the existing single-instance behavior with zero config.
31
- */
32
- let defaultAdapter = new InMemoryCacheAdapter();
33
- export function getDefaultCache() {
34
- return defaultAdapter;
35
- }
36
- export function setDefaultCache(adapter) {
37
- defaultAdapter = adapter;
38
- }
39
- //# sourceMappingURL=cache.js.map
package/dist/cache.js.map DELETED
@@ -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U,eAAe,CAAC,OAAqB;IACnD,cAAc,GAAG,OAAO,CAAC;AAC3B,CAAC"}
package/dist/errors.js DELETED
@@ -1,19 +0,0 @@
1
- import { ONESUB_ERROR_CODE } from '@onesub/shared';
2
- /**
3
- * Send a structured error response. Every onesub HTTP endpoint uses this
4
- * so consumers can rely on `errorCode` being present on every 4xx/5xx body.
5
- *
6
- * `extra` lets callers inject route-specific defaults (e.g. `purchase: null`
7
- * for ValidatePurchaseResponse shape compatibility).
8
- */
9
- export function sendError(res, status, code, error, extra = {}) {
10
- res.status(status).json({ ...extra, error, errorCode: code });
11
- }
12
- /**
13
- * 400 response for a failed zod parse. The ZodError's per-issue messages
14
- * are joined for the human-readable `error` field.
15
- */
16
- export function sendZodError(res, err, extra = {}) {
17
- sendError(res, 400, ONESUB_ERROR_CODE.INVALID_INPUT, err.issues.map((e) => e.message).join(', '), extra);
18
- }
19
- //# sourceMappingURL=errors.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAEnD;;;;;;GAMG;AACH,MAAM,UAAU,SAAS,CACvB,GAAa,EACb,MAAc,EACd,IAAqB,EACrB,KAAa,EACb,QAAiC,EAAE;IAEnC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,EAAE,GAAG,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;AAChE,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,YAAY,CAC1B,GAAa,EACb,GAAe,EACf,QAAiC,EAAE;IAEnC,SAAS,CACP,GAAG,EACH,GAAG,EACH,iBAAiB,CAAC,aAAa,EAC/B,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAsB,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAChE,KAAK,CACN,CAAC;AACJ,CAAC"}
package/dist/http.js DELETED
@@ -1,36 +0,0 @@
1
- /**
2
- * Outbound HTTP helpers shared by Apple/Google providers.
3
- *
4
- * Why timeouts: Node's global fetch has no default timeout. If the upstream
5
- * (Apple App Store Server API, Google Play Developer API, Google OAuth) hangs,
6
- * webhook handlers and validate routes hang with it — Apple/Google retry on
7
- * their side, so a hung outbound call cascades into request pile-up here.
8
- */
9
- /** Default timeout for outbound API calls (10s). */
10
- export const DEFAULT_FETCH_TIMEOUT_MS = 10_000;
11
- /**
12
- * fetch with an `AbortController`-based timeout. Throws an `AbortError`-like
13
- * Error when the timer fires. Caller is expected to catch and decide
14
- * (return null, log, propagate as 5xx, etc.).
15
- */
16
- export async function fetchWithTimeout(input, init, timeoutMs = DEFAULT_FETCH_TIMEOUT_MS) {
17
- const controller = new AbortController();
18
- // Allow caller-provided signal to compose with our timeout.
19
- const callerSignal = init?.signal;
20
- if (callerSignal) {
21
- if (callerSignal.aborted)
22
- controller.abort(callerSignal.reason);
23
- else
24
- callerSignal.addEventListener('abort', () => controller.abort(callerSignal.reason), { once: true });
25
- }
26
- const timer = setTimeout(() => {
27
- controller.abort(new Error(`[onesub] fetch timed out after ${timeoutMs}ms`));
28
- }, timeoutMs);
29
- try {
30
- return await fetch(input, { ...init, signal: controller.signal });
31
- }
32
- finally {
33
- clearTimeout(timer);
34
- }
35
- }
36
- //# sourceMappingURL=http.js.map
package/dist/http.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"http.js","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,oDAAoD;AACpD,MAAM,CAAC,MAAM,wBAAwB,GAAG,MAAM,CAAC;AAE/C;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,KAAwB,EACxB,IAAkB,EAClB,SAAS,GAAG,wBAAwB;IAEpC,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAC;IACzC,4DAA4D;IAC5D,MAAM,YAAY,GAAG,IAAI,EAAE,MAAM,CAAC;IAClC,IAAI,YAAY,EAAE,CAAC;QACjB,IAAI,YAAY,CAAC,OAAO;YAAE,UAAU,CAAC,KAAK,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;;YAC3D,YAAY,CAAC,gBAAgB,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;IAC3G,CAAC;IAED,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE;QAC5B,UAAU,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,kCAAkC,SAAS,IAAI,CAAC,CAAC,CAAC;IAC/E,CAAC,EAAE,SAAS,CAAC,CAAC;IAEd,IAAI,CAAC;QACH,OAAO,MAAM,KAAK,CAAC,KAAK,EAAE,EAAE,GAAG,IAAI,EAAE,MAAM,EAAE,UAAU,CAAC,MAAM,EAAE,CAAC,CAAC;IACpE,CAAC;YAAS,CAAC;QACT,YAAY,CAAC,KAAK,CAAC,CAAC;IACtB,CAAC;AACH,CAAC"}
package/dist/logger.js DELETED
@@ -1,20 +0,0 @@
1
- /**
2
- * Process-wide logger used by @onesub/server's providers and routes.
3
- *
4
- * Defaults to `console`. `createOneSubMiddleware()` calls `setLogger()` once
5
- * during setup if `config.logger` is provided. All internal call sites should
6
- * import `log` from this module instead of calling `console.*` directly so
7
- * operators can redirect logs (pino / winston / bunyan) with a single config
8
- * setting.
9
- */
10
- let current = console;
11
- export function setLogger(logger) {
12
- if (logger)
13
- current = logger;
14
- }
15
- export const log = {
16
- info: (...args) => current.info(...args),
17
- warn: (...args) => current.warn(...args),
18
- error: (...args) => current.error(...args),
19
- };
20
- //# sourceMappingURL=logger.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AAEH,IAAI,OAAO,GAAiB,OAAO,CAAC;AAEpC,MAAM,UAAU,SAAS,CAAC,MAAgC;IACxD,IAAI,MAAM;QAAE,OAAO,GAAG,MAAM,CAAC;AAC/B,CAAC;AAED,MAAM,CAAC,MAAM,GAAG,GAAiB;IAC/B,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IACxC,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IACxC,KAAK,EAAE,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC;CAC3C,CAAC"}
package/dist/openapi.js DELETED
@@ -1,196 +0,0 @@
1
- /**
2
- * OpenAPI 3.1 spec for the onesub HTTP surface.
3
- *
4
- * Hand-maintained — kept in sync with the routes by a parity test (see
5
- * __tests__/openapi.test.ts) that asserts every mounted path is described
6
- * here. Generated clients live downstream:
7
- *
8
- * - swagger-typescript-api → typed fetch client
9
- * - openapi-generator-cli → Kotlin/Swift/etc. clients
10
- *
11
- * Why hand-maintained instead of zod-to-openapi: the routes use zod for
12
- * input validation but the request/response shapes the public docs need are
13
- * a thin slice of those internal types. Hand-writing keeps the doc readable
14
- * without coupling client output to internal validation strictness changes.
15
- */
16
- import { ROUTES } from '@onesub/shared';
17
- export const ONESUB_OPENAPI = {
18
- openapi: '3.1.0',
19
- info: {
20
- title: 'onesub HTTP API',
21
- version: '1.0.0',
22
- description: 'Receipt validation, subscription status, webhooks, and admin endpoints exposed by `createOneSubMiddleware`.',
23
- },
24
- servers: [
25
- { url: 'http://localhost:4100', description: 'Local dev (examples/server)' },
26
- ],
27
- paths: {
28
- [ROUTES.VALIDATE]: {
29
- post: {
30
- summary: 'Validate an Apple/Google receipt and persist subscription state.',
31
- requestBody: {
32
- required: true,
33
- content: { 'application/json': { schema: { $ref: '#/components/schemas/ValidateRequest' } } },
34
- },
35
- responses: {
36
- 200: { description: 'Validation succeeded; subscription state persisted.', content: { 'application/json': { schema: { $ref: '#/components/schemas/ValidateResponse' } } } },
37
- 400: { description: 'Bad request — missing fields, malformed receipt, package mismatch.' },
38
- },
39
- },
40
- },
41
- [ROUTES.STATUS]: {
42
- get: {
43
- summary: 'Fetch the most recent subscription state for a user.',
44
- parameters: [{ in: 'query', name: 'userId', required: true, schema: { type: 'string' } }],
45
- responses: {
46
- 200: { description: 'OK', content: { 'application/json': { schema: { $ref: '#/components/schemas/StatusResponse' } } } },
47
- },
48
- },
49
- },
50
- [ROUTES.WEBHOOK_APPLE]: {
51
- post: {
52
- summary: 'Apple App Store Server Notification V2 receiver.',
53
- description: 'Apple POSTs `{ signedPayload }`. JWS-verified, idempotent when `webhookEventStore` is configured.',
54
- responses: {
55
- 200: { description: 'Acknowledged.' },
56
- 400: { description: 'Missing or invalid signedPayload.' },
57
- },
58
- },
59
- },
60
- [ROUTES.WEBHOOK_GOOGLE]: {
61
- post: {
62
- summary: 'Google Play Real-Time Developer Notification (Pub/Sub push) receiver.',
63
- responses: {
64
- 200: { description: 'Acknowledged.' },
65
- 400: { description: 'Missing message.data or package mismatch.' },
66
- 401: { description: 'pushAudience configured and JWT verification failed.' },
67
- },
68
- },
69
- },
70
- [ROUTES.ENTITLEMENTS]: {
71
- get: {
72
- summary: 'Evaluate every configured entitlement for a user.',
73
- parameters: [{ in: 'query', name: 'userId', required: true, schema: { type: 'string' } }],
74
- responses: {
75
- 200: { description: 'Map of entitlementId → { granted, source }.' },
76
- },
77
- },
78
- },
79
- [ROUTES.ADMIN_SUBSCRIPTIONS]: {
80
- get: {
81
- summary: 'Filtered, paginated subscription list (admin).',
82
- parameters: [
83
- { in: 'header', name: 'X-Admin-Secret', required: true, schema: { type: 'string' } },
84
- { in: 'query', name: 'userId', schema: { type: 'string' } },
85
- { in: 'query', name: 'status', schema: { type: 'string', enum: ['active', 'grace_period', 'on_hold', 'paused', 'expired', 'canceled', 'none'] } },
86
- { in: 'query', name: 'productId', schema: { type: 'string' } },
87
- { in: 'query', name: 'platform', schema: { type: 'string', enum: ['apple', 'google'] } },
88
- { in: 'query', name: 'limit', schema: { type: 'integer', minimum: 1, maximum: 200 } },
89
- { in: 'query', name: 'offset', schema: { type: 'integer', minimum: 0 } },
90
- ],
91
- responses: { 200: { description: 'OK' }, 401: { description: 'Invalid admin secret' } },
92
- },
93
- },
94
- '/onesub/admin/customers/{userId}': {
95
- get: {
96
- summary: 'Customer profile bundle: subscriptions + purchases + entitlements (admin).',
97
- parameters: [
98
- { in: 'header', name: 'X-Admin-Secret', required: true, schema: { type: 'string' } },
99
- { in: 'path', name: 'userId', required: true, schema: { type: 'string' } },
100
- ],
101
- responses: { 200: { description: 'OK' }, 401: { description: 'Invalid admin secret' } },
102
- },
103
- },
104
- '/onesub/admin/webhook-deadletters': {
105
- get: {
106
- summary: 'List failed webhook jobs (when a queue with DLQ support is configured).',
107
- parameters: [{ in: 'header', name: 'X-Admin-Secret', required: true, schema: { type: 'string' } }],
108
- responses: { 200: { description: 'OK' }, 401: { description: 'Invalid admin secret' } },
109
- },
110
- },
111
- '/onesub/admin/webhook-replay/{id}': {
112
- post: {
113
- summary: 'Replay a dead-letter job through the webhook handler.',
114
- parameters: [
115
- { in: 'header', name: 'X-Admin-Secret', required: true, schema: { type: 'string' } },
116
- { in: 'path', name: 'id', required: true, schema: { type: 'string' } },
117
- ],
118
- responses: { 200: { description: 'OK' }, 401: { description: 'Invalid admin secret' } },
119
- },
120
- },
121
- },
122
- components: {
123
- schemas: {
124
- ValidateRequest: {
125
- type: 'object',
126
- required: ['userId', 'platform', 'productId', 'receipt'],
127
- properties: {
128
- userId: { type: 'string' },
129
- platform: { type: 'string', enum: ['apple', 'google'] },
130
- productId: { type: 'string' },
131
- receipt: { type: 'string', description: 'Apple JWS or Google purchaseToken' },
132
- purchaseType: { type: 'string', enum: ['subscription', 'consumable', 'non_consumable'] },
133
- },
134
- },
135
- ValidateResponse: {
136
- type: 'object',
137
- properties: {
138
- valid: { type: 'boolean' },
139
- subscription: { $ref: '#/components/schemas/SubscriptionInfo' },
140
- purchase: { $ref: '#/components/schemas/PurchaseInfo' },
141
- },
142
- },
143
- StatusResponse: {
144
- type: 'object',
145
- properties: {
146
- active: { type: 'boolean' },
147
- subscription: { $ref: '#/components/schemas/SubscriptionInfo' },
148
- },
149
- },
150
- SubscriptionInfo: {
151
- type: 'object',
152
- properties: {
153
- originalTransactionId: { type: 'string' },
154
- userId: { type: 'string' },
155
- productId: { type: 'string' },
156
- platform: { type: 'string', enum: ['apple', 'google'] },
157
- status: { type: 'string', enum: ['active', 'grace_period', 'on_hold', 'paused', 'expired', 'canceled', 'none'] },
158
- expiresAt: { type: 'string', format: 'date-time' },
159
- purchasedAt: { type: 'string', format: 'date-time' },
160
- willRenew: { type: 'boolean' },
161
- },
162
- },
163
- PurchaseInfo: {
164
- type: 'object',
165
- properties: {
166
- transactionId: { type: 'string' },
167
- userId: { type: 'string' },
168
- productId: { type: 'string' },
169
- platform: { type: 'string', enum: ['apple', 'google'] },
170
- type: { type: 'string', enum: ['consumable', 'non_consumable'] },
171
- quantity: { type: 'integer' },
172
- purchasedAt: { type: 'string', format: 'date-time' },
173
- },
174
- },
175
- },
176
- securitySchemes: {
177
- AdminSecret: {
178
- type: 'apiKey',
179
- in: 'header',
180
- name: 'X-Admin-Secret',
181
- },
182
- },
183
- },
184
- };
185
- /**
186
- * Mount a route that serves the OpenAPI document. Useful for hosts that want
187
- * to expose `/openapi.json` to API explorers / SDK generators.
188
- *
189
- * app.use('/openapi.json', openapiHandler());
190
- */
191
- export function openapiHandler() {
192
- return (_req, res) => {
193
- res.json(ONESUB_OPENAPI);
194
- };
195
- }
196
- //# sourceMappingURL=openapi.js.map