@molecule/api-resource-payment 1.0.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/LICENSE +115 -0
  2. package/dist/__tests__/index.test.d.ts +5 -0
  3. package/dist/__tests__/index.test.d.ts.map +1 -0
  4. package/dist/__tests__/index.test.js +85 -0
  5. package/dist/__tests__/index.test.js.map +1 -0
  6. package/dist/__tests__/planService.test.d.ts +5 -0
  7. package/dist/__tests__/planService.test.d.ts.map +1 -0
  8. package/dist/__tests__/planService.test.js +166 -0
  9. package/dist/__tests__/planService.test.js.map +1 -0
  10. package/dist/__tests__/plans.test.d.ts +5 -0
  11. package/dist/__tests__/plans.test.d.ts.map +1 -0
  12. package/dist/__tests__/plans.test.js +296 -0
  13. package/dist/__tests__/plans.test.js.map +1 -0
  14. package/dist/__tests__/recordService.test.d.ts +5 -0
  15. package/dist/__tests__/recordService.test.d.ts.map +1 -0
  16. package/dist/__tests__/recordService.test.js +214 -0
  17. package/dist/__tests__/recordService.test.js.map +1 -0
  18. package/dist/__tests__/resource.test.d.ts +5 -0
  19. package/dist/__tests__/resource.test.d.ts.map +1 -0
  20. package/dist/__tests__/resource.test.js +56 -0
  21. package/dist/__tests__/resource.test.js.map +1 -0
  22. package/dist/__tests__/schema.test.d.ts +5 -0
  23. package/dist/__tests__/schema.test.d.ts.map +1 -0
  24. package/dist/__tests__/schema.test.js +275 -0
  25. package/dist/__tests__/schema.test.js.map +1 -0
  26. package/dist/__tests__/utilities.test.d.ts +5 -0
  27. package/dist/__tests__/utilities.test.d.ts.map +1 -0
  28. package/dist/__tests__/utilities.test.js +59 -0
  29. package/dist/__tests__/utilities.test.js.map +1 -0
  30. package/dist/browser-guard.d.ts +2 -0
  31. package/dist/browser-guard.d.ts.map +1 -0
  32. package/dist/browser-guard.js +19 -0
  33. package/dist/browser-guard.js.map +1 -0
  34. package/dist/i18n.d.ts +10 -0
  35. package/dist/i18n.d.ts.map +1 -0
  36. package/dist/i18n.js +18 -0
  37. package/dist/i18n.js.map +1 -0
  38. package/dist/index.d.ts +96 -0
  39. package/dist/index.d.ts.map +1 -0
  40. package/dist/index.js +96 -0
  41. package/dist/index.js.map +1 -0
  42. package/dist/planService.d.ts +9 -0
  43. package/dist/planService.d.ts.map +1 -0
  44. package/dist/planService.js +53 -0
  45. package/dist/planService.js.map +1 -0
  46. package/dist/plans.d.ts +34 -0
  47. package/dist/plans.d.ts.map +1 -0
  48. package/dist/plans.js +167 -0
  49. package/dist/plans.js.map +1 -0
  50. package/dist/recordService.d.ts +33 -0
  51. package/dist/recordService.d.ts.map +1 -0
  52. package/dist/recordService.js +162 -0
  53. package/dist/recordService.js.map +1 -0
  54. package/dist/resource.d.ts +4 -0
  55. package/dist/resource.d.ts.map +1 -0
  56. package/dist/resource.js +22 -0
  57. package/dist/resource.js.map +1 -0
  58. package/dist/schema.d.ts +58 -0
  59. package/dist/schema.d.ts.map +1 -0
  60. package/dist/schema.js +38 -0
  61. package/dist/schema.js.map +1 -0
  62. package/dist/types.d.ts +83 -0
  63. package/dist/types.d.ts.map +1 -0
  64. package/dist/types.js +6 -0
  65. package/dist/types.js.map +1 -0
  66. package/dist/utilities.d.ts +8 -0
  67. package/dist/utilities.d.ts.map +1 -0
  68. package/dist/utilities.js +25 -0
  69. package/dist/utilities.js.map +1 -0
  70. package/package.json +54 -0
  71. package/setup/payments.sql +22 -0
@@ -0,0 +1,275 @@
1
+ /**
2
+ * Tests for the Payment Zod schemas.
3
+ */
4
+ import { describe, expect, it } from 'vitest';
5
+ import { createPropsSchema, propsSchema, updatePropsSchema } from '../schema.js';
6
+ describe('propsSchema', () => {
7
+ const validProps = {
8
+ id: '550e8400-e29b-41d4-a716-446655440000',
9
+ createdAt: '2024-01-01T00:00:00.000Z',
10
+ updatedAt: '2024-01-01T00:00:00.000Z',
11
+ userId: '660e8400-e29b-41d4-a716-446655440000',
12
+ platformKey: 'stripe',
13
+ transactionId: 'txn_123',
14
+ productId: 'price_test_id',
15
+ data: { customerId: 'cus_123' },
16
+ receipt: 'receipt_data',
17
+ };
18
+ it('should validate valid full props', () => {
19
+ const result = propsSchema.safeParse(validProps);
20
+ expect(result.success).toBe(true);
21
+ });
22
+ it('should validate minimal required props', () => {
23
+ const minimal = {
24
+ id: '550e8400-e29b-41d4-a716-446655440000',
25
+ createdAt: '2024-01-01T00:00:00.000Z',
26
+ updatedAt: '2024-01-01T00:00:00.000Z',
27
+ userId: '660e8400-e29b-41d4-a716-446655440000',
28
+ productId: 'price_test_id',
29
+ };
30
+ const result = propsSchema.safeParse(minimal);
31
+ expect(result.success).toBe(true);
32
+ });
33
+ it('should default platformKey to empty string', () => {
34
+ const withoutPlatformKey = {
35
+ id: '550e8400-e29b-41d4-a716-446655440000',
36
+ createdAt: '2024-01-01T00:00:00.000Z',
37
+ updatedAt: '2024-01-01T00:00:00.000Z',
38
+ userId: '660e8400-e29b-41d4-a716-446655440000',
39
+ productId: 'price_test_id',
40
+ };
41
+ const result = propsSchema.safeParse(withoutPlatformKey);
42
+ expect(result.success).toBe(true);
43
+ if (result.success) {
44
+ expect(result.data.platformKey).toBe('');
45
+ }
46
+ });
47
+ it('should reject invalid UUID for id', () => {
48
+ const invalid = { ...validProps, id: 'not-a-uuid' };
49
+ const result = propsSchema.safeParse(invalid);
50
+ expect(result.success).toBe(false);
51
+ });
52
+ it('should reject invalid UUID for userId', () => {
53
+ const invalid = { ...validProps, userId: 'not-a-uuid' };
54
+ const result = propsSchema.safeParse(invalid);
55
+ expect(result.success).toBe(false);
56
+ });
57
+ it('should reject missing id', () => {
58
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
59
+ const { id, ...rest } = validProps;
60
+ const result = propsSchema.safeParse(rest);
61
+ expect(result.success).toBe(false);
62
+ });
63
+ it('should reject missing createdAt', () => {
64
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
65
+ const { createdAt, ...rest } = validProps;
66
+ const result = propsSchema.safeParse(rest);
67
+ expect(result.success).toBe(false);
68
+ });
69
+ it('should reject missing updatedAt', () => {
70
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
71
+ const { updatedAt, ...rest } = validProps;
72
+ const result = propsSchema.safeParse(rest);
73
+ expect(result.success).toBe(false);
74
+ });
75
+ it('should reject missing userId', () => {
76
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
77
+ const { userId, ...rest } = validProps;
78
+ const result = propsSchema.safeParse(rest);
79
+ expect(result.success).toBe(false);
80
+ });
81
+ it('should reject missing productId', () => {
82
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
83
+ const { productId, ...rest } = validProps;
84
+ const result = propsSchema.safeParse(rest);
85
+ expect(result.success).toBe(false);
86
+ });
87
+ it('should accept platformKey "stripe"', () => {
88
+ const result = propsSchema.safeParse({ ...validProps, platformKey: 'stripe' });
89
+ expect(result.success).toBe(true);
90
+ });
91
+ it('should accept platformKey "apple"', () => {
92
+ const result = propsSchema.safeParse({ ...validProps, platformKey: 'apple' });
93
+ expect(result.success).toBe(true);
94
+ });
95
+ it('should accept platformKey "google"', () => {
96
+ const result = propsSchema.safeParse({ ...validProps, platformKey: 'google' });
97
+ expect(result.success).toBe(true);
98
+ });
99
+ it('should accept platformKey "" (empty string)', () => {
100
+ const result = propsSchema.safeParse({ ...validProps, platformKey: '' });
101
+ expect(result.success).toBe(true);
102
+ });
103
+ it('should reject invalid platformKey', () => {
104
+ const result = propsSchema.safeParse({ ...validProps, platformKey: 'paypal' });
105
+ expect(result.success).toBe(false);
106
+ });
107
+ it('should accept optional transactionId', () => {
108
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
109
+ const { transactionId, ...rest } = validProps;
110
+ const result = propsSchema.safeParse(rest);
111
+ expect(result.success).toBe(true);
112
+ if (result.success) {
113
+ expect(result.data.transactionId).toBeUndefined();
114
+ }
115
+ });
116
+ it('should accept optional data', () => {
117
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
118
+ const { data, ...rest } = validProps;
119
+ const result = propsSchema.safeParse(rest);
120
+ expect(result.success).toBe(true);
121
+ if (result.success) {
122
+ expect(result.data.data).toBeUndefined();
123
+ }
124
+ });
125
+ it('should accept optional receipt', () => {
126
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
127
+ const { receipt, ...rest } = validProps;
128
+ const result = propsSchema.safeParse(rest);
129
+ expect(result.success).toBe(true);
130
+ if (result.success) {
131
+ expect(result.data.receipt).toBeUndefined();
132
+ }
133
+ });
134
+ it('should accept data as a record of unknowns', () => {
135
+ const result = propsSchema.safeParse({
136
+ ...validProps,
137
+ data: { foo: 'bar', nested: { deep: true }, count: 42 },
138
+ });
139
+ expect(result.success).toBe(true);
140
+ });
141
+ });
142
+ describe('createPropsSchema', () => {
143
+ const validCreateProps = {
144
+ createdAt: '2024-01-01T00:00:00.000Z',
145
+ updatedAt: '2024-01-01T00:00:00.000Z',
146
+ userId: '660e8400-e29b-41d4-a716-446655440000',
147
+ platformKey: 'stripe',
148
+ transactionId: 'txn_123',
149
+ productId: 'price_test_id',
150
+ data: { customerId: 'cus_123' },
151
+ receipt: 'receipt_data',
152
+ };
153
+ it('should validate valid create props', () => {
154
+ const result = createPropsSchema.safeParse(validCreateProps);
155
+ expect(result.success).toBe(true);
156
+ });
157
+ it('should validate minimal create props', () => {
158
+ const minimal = {
159
+ createdAt: '2024-01-01T00:00:00.000Z',
160
+ updatedAt: '2024-01-01T00:00:00.000Z',
161
+ userId: '660e8400-e29b-41d4-a716-446655440000',
162
+ productId: 'price_test_id',
163
+ };
164
+ const result = createPropsSchema.safeParse(minimal);
165
+ expect(result.success).toBe(true);
166
+ });
167
+ it('should not include id field', () => {
168
+ const withId = {
169
+ id: '550e8400-e29b-41d4-a716-446655440000',
170
+ ...validCreateProps,
171
+ };
172
+ const result = createPropsSchema.safeParse(withId);
173
+ expect(result.success).toBe(true);
174
+ if (result.success) {
175
+ expect(result.data).not.toHaveProperty('id');
176
+ }
177
+ });
178
+ it('should require createdAt', () => {
179
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
180
+ const { createdAt, ...rest } = validCreateProps;
181
+ const result = createPropsSchema.safeParse(rest);
182
+ expect(result.success).toBe(false);
183
+ });
184
+ it('should require updatedAt', () => {
185
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
186
+ const { updatedAt, ...rest } = validCreateProps;
187
+ const result = createPropsSchema.safeParse(rest);
188
+ expect(result.success).toBe(false);
189
+ });
190
+ it('should require userId', () => {
191
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
192
+ const { userId, ...rest } = validCreateProps;
193
+ const result = createPropsSchema.safeParse(rest);
194
+ expect(result.success).toBe(false);
195
+ });
196
+ it('should require productId', () => {
197
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
198
+ const { productId, ...rest } = validCreateProps;
199
+ const result = createPropsSchema.safeParse(rest);
200
+ expect(result.success).toBe(false);
201
+ });
202
+ it('should accept optional transactionId', () => {
203
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
204
+ const { transactionId, ...rest } = validCreateProps;
205
+ const result = createPropsSchema.safeParse(rest);
206
+ expect(result.success).toBe(true);
207
+ });
208
+ it('should accept optional data', () => {
209
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
210
+ const { data, ...rest } = validCreateProps;
211
+ const result = createPropsSchema.safeParse(rest);
212
+ expect(result.success).toBe(true);
213
+ });
214
+ it('should accept optional receipt', () => {
215
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
216
+ const { receipt, ...rest } = validCreateProps;
217
+ const result = createPropsSchema.safeParse(rest);
218
+ expect(result.success).toBe(true);
219
+ });
220
+ });
221
+ describe('updatePropsSchema', () => {
222
+ it('should validate valid update props with data', () => {
223
+ const result = updatePropsSchema.safeParse({ data: { foo: 'bar' } });
224
+ expect(result.success).toBe(true);
225
+ });
226
+ it('should validate valid update props with receipt', () => {
227
+ const result = updatePropsSchema.safeParse({ receipt: 'new-receipt' });
228
+ expect(result.success).toBe(true);
229
+ });
230
+ it('should validate both data and receipt', () => {
231
+ const result = updatePropsSchema.safeParse({
232
+ data: { updated: true },
233
+ receipt: 'new-receipt',
234
+ });
235
+ expect(result.success).toBe(true);
236
+ });
237
+ it('should validate empty update (all fields partial)', () => {
238
+ const result = updatePropsSchema.safeParse({});
239
+ expect(result.success).toBe(true);
240
+ });
241
+ it('should not include userId field', () => {
242
+ const propsWithUserId = {
243
+ userId: '660e8400-e29b-41d4-a716-446655440000',
244
+ data: { foo: 'bar' },
245
+ };
246
+ const result = updatePropsSchema.safeParse(propsWithUserId);
247
+ expect(result.success).toBe(true);
248
+ if (result.success) {
249
+ expect(result.data).not.toHaveProperty('userId');
250
+ }
251
+ });
252
+ it('should not include platformKey field', () => {
253
+ const propsWithPlatformKey = {
254
+ platformKey: 'stripe',
255
+ data: { foo: 'bar' },
256
+ };
257
+ const result = updatePropsSchema.safeParse(propsWithPlatformKey);
258
+ expect(result.success).toBe(true);
259
+ if (result.success) {
260
+ expect(result.data).not.toHaveProperty('platformKey');
261
+ }
262
+ });
263
+ it('should not include transactionId field', () => {
264
+ const propsWithTxId = {
265
+ transactionId: 'txn_123',
266
+ receipt: 'rcpt',
267
+ };
268
+ const result = updatePropsSchema.safeParse(propsWithTxId);
269
+ expect(result.success).toBe(true);
270
+ if (result.success) {
271
+ expect(result.data).not.toHaveProperty('transactionId');
272
+ }
273
+ });
274
+ });
275
+ //# sourceMappingURL=schema.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.test.js","sourceRoot":"","sources":["../../src/__tests__/schema.test.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAE7C,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAEhF,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;IAC3B,MAAM,UAAU,GAAG;QACjB,EAAE,EAAE,sCAAsC;QAC1C,SAAS,E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 /**
2
+ * Tests for the payment utility functions.
3
+ */
4
+ export {};
5
+ //# sourceMappingURL=utilities.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utilities.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/utilities.test.ts"],"names":[],"mappings":"AAAA;;GAEG"}
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Tests for the payment utility functions.
3
+ */
4
+ import { describe, expect, it } from 'vitest';
5
+ import { getPeriodTime } from '../utilities.js';
6
+ describe('getPeriodTime', () => {
7
+ it('should return a positive number for "month"', () => {
8
+ const result = getPeriodTime('month');
9
+ expect(result).toBeGreaterThan(0);
10
+ });
11
+ it('should return a positive number for "year"', () => {
12
+ const result = getPeriodTime('year');
13
+ expect(result).toBeGreaterThan(0);
14
+ });
15
+ it('should return 0 for empty string period', () => {
16
+ const result = getPeriodTime('');
17
+ expect(result).toBe(0);
18
+ });
19
+ it('should return approximately 1/12 of a year for "month"', () => {
20
+ const monthTime = getPeriodTime('month');
21
+ const yearTime = getPeriodTime('year');
22
+ // monthTime should be approximately yearTime / 12
23
+ const expectedMonthTime = Math.round(yearTime / 12);
24
+ expect(monthTime).toBe(expectedMonthTime);
25
+ });
26
+ it('should return approximately 365.25 days in milliseconds for "year"', () => {
27
+ const yearTime = getPeriodTime('year');
28
+ // A year is approximately 365-366 days in milliseconds
29
+ // Allow up to 1 hour less than 365 days due to DST transitions
30
+ const minYear = 365 * 24 * 60 * 60 * 1000 - 60 * 60 * 1000; // 365 days minus 1 hour
31
+ const maxYear = 366 * 24 * 60 * 60 * 1000 + 60 * 60 * 1000; // 366 days plus 1 hour
32
+ expect(yearTime).toBeGreaterThanOrEqual(minYear);
33
+ expect(yearTime).toBeLessThanOrEqual(maxYear);
34
+ });
35
+ it('should return approximately 28-31 days in milliseconds for "month"', () => {
36
+ const monthTime = getPeriodTime('month');
37
+ // A month is approximately 28-31 days in milliseconds
38
+ const minMonth = 28 * 24 * 60 * 60 * 1000; // 28 days
39
+ const maxMonth = 31 * 24 * 60 * 60 * 1000; // 31 days
40
+ expect(monthTime).toBeGreaterThanOrEqual(minMonth);
41
+ expect(monthTime).toBeLessThanOrEqual(maxMonth);
42
+ });
43
+ it('should return year time exactly 12 times the month time', () => {
44
+ const monthTime = getPeriodTime('month');
45
+ const yearTime = getPeriodTime('year');
46
+ // Due to rounding, monthTime * 12 should be very close to yearTime
47
+ // The difference is from Math.round in getOneMonthTime
48
+ const difference = Math.abs(yearTime - monthTime * 12);
49
+ // Allow up to 11ms difference due to rounding (at most 1 per round)
50
+ expect(difference).toBeLessThanOrEqual(11);
51
+ });
52
+ it('should return consistent values across multiple calls', () => {
53
+ const first = getPeriodTime('month');
54
+ const second = getPeriodTime('month');
55
+ // Values should be very close (within a few ms due to time passing between calls)
56
+ expect(Math.abs(first - second)).toBeLessThan(1000);
57
+ });
58
+ });
59
+ //# sourceMappingURL=utilities.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utilities.test.js","sourceRoot":"","sources":["../../src/__tests__/utilities.test.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAE7C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAE/C,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;IAC7B,EAAE,CAAC,6CAA6C,EAAE,GAAG,EAAE;QACrD,MAAM,MAAM,GAAG,aAAa,CAAC,OAAO,CAAC,CAAA;QACrC,MAAM,CAAC,MAAM,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,CAAA;IACnC,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,4CAA4C,EAAE,GAAG,EAAE;QACpD,MAAM,MAAM,GAAG,aAAa,CAAC,MAAM,CAAC,CAAA;QACpC,MAAM,CAAC,MAAM,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,CAAA;IACnC,CAAC,CAAC,CAAA;IAEF,EAAE,CA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1,19 @@
1
+ /**
2
+ * Browser guard — `@molecule/api-resource-payment` is SERVER-ONLY.
3
+ *
4
+ * Generated by scripts/gen-browser-guards.mjs (workspace root) — edit THAT, not this.
5
+ * Evaluating a server package in a browser bundle is always an import-graph mistake
6
+ * (node APIs, secrets); without this guard it surfaces as a cryptic downstream crash
7
+ * ("Buffer is not defined") far from the culprit. Throwing here names the package and
8
+ * the fix at the exact moment the client bundle evaluates it. jsdom tests and SSR are
9
+ * unaffected: the throw requires browser globals AND the absence of a node runtime.
10
+ */
11
+ const g = globalThis;
12
+ if (g.window !== undefined && g.document !== undefined && !g.process?.versions?.node) {
13
+ throw new Error('@molecule/api-resource-payment is SERVER-ONLY: it was bundled into browser/client code. Import it only ' +
14
+ 'from server code (a server route/function or your API), or dynamic-import it inside ' +
15
+ 'the server handler — never from components or shared client modules, and never ' +
16
+ 'polyfill Buffer/process to silence this.');
17
+ }
18
+ export {};
19
+ //# sourceMappingURL=browser-guard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser-guard.js","sourceRoot":"","sources":["../src/browser-guard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,CAAC,GAAG,UAIT,CAAA;AACD,IAAI,CAAC,CAAC,MAAM,KAAK,SAAS,IAAI,CAAC,CAAC,QAAQ,KAAK,SAAS,IAAI,CAAC,CAAC,CAAC,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;IACrF,MAAM,IAAI,KAAK,CACb,yGAAyG;QACvG,sFAAsF;QACtF,iFAAiF;QACjF,0CAA0C,CAC7C,CAAA;AACH,CAAC"}
package/dist/i18n.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Locale registration for the payment resource.
3
+ *
4
+ * @module
5
+ */
6
+ /**
7
+ * The i18n registered.
8
+ */
9
+ export declare const i18nRegistered = true;
10
+ //# sourceMappingURL=i18n.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"i18n.d.ts","sourceRoot":"","sources":["../src/i18n.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAWH;;GAEG;AACH,eAAO,MAAM,cAAc,OAAO,CAAA"}
package/dist/i18n.js ADDED
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Locale registration for the payment resource.
3
+ *
4
+ * @module
5
+ */
6
+ import { registerLocaleModule } from '@molecule/api-i18n';
7
+ try {
8
+ const locales = await import('@molecule/api-locales-payment');
9
+ registerLocaleModule(locales);
10
+ }
11
+ catch (_error) {
12
+ // Locale package not available — translations will fall back to defaults
13
+ }
14
+ /**
15
+ * The i18n registered.
16
+ */
17
+ export const i18nRegistered = true;
18
+ //# sourceMappingURL=i18n.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"i18n.js","sourceRoot":"","sources":["../src/i18n.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAA;AAEzD,IAAI,CAAC;IACH,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,+BAA+B,CAAC,CAAA;IAC7D,oBAAoB,CAAC,OAAO,CAAC,CAAA;AAC/B,CAAC;AAAC,OAAO,MAAM,EAAE,CAAC;IAChB,yEAAyE;AAC3E,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,CAAA"}
@@ -0,0 +1,96 @@
1
+ /**
2
+ * Payment resource with subscription plan management.
3
+ *
4
+ * @remarks
5
+ * A plan/entitlement is granted ONLY after a SERVER-VERIFIED payment — never from anything
6
+ * the client reports. The flow (implemented by the user resource's `verifyPayment` handler):
7
+ *
8
+ * 1. **Verify** the provider token/receipt server-side via the bonded payments provider
9
+ * (`@molecule/api-payments` — read its docs). Trust only its normalized result.
10
+ * 2. **Record** it with {@link paymentRecordService}`.store`, which enforces
11
+ * `UNIQUE(platformKey, transactionId)` so one receipt binds to exactly ONE account.
12
+ * 3. **Resolve** the plan from the verified product/price id against the registered
13
+ * {@link plans} (match BOTH `productId` and `priceId`), then grant it.
14
+ *
15
+ * Weak-integration mistakes to avoid:
16
+ * - **Never trust a client-sent plan / subscription / "isPro".** The plan is derived from
17
+ * the verified provider result, not a request field.
18
+ * - **Never swallow the duplicate-record error.** {@link paymentRecordService}`.store`
19
+ * THROWS when a `transactionId` is already claimed — that is the replay guard
20
+ * (first-claim-wins). Catch it and REJECT; do not grant the plan to a second account.
21
+ * - **Register your catalogue** with {@link registerPlans} using YOUR price/product ids
22
+ * (the env-configured `price_…`), and resolve by BOTH product and price id — providers
23
+ * report the product on a subscription while checkout uses the price.
24
+ * - Re-verify entitlement server-side wherever it gates access; never cache "is subscribed"
25
+ * somewhere the client can set.
26
+ *
27
+ * The `payments` table ships in `setup/payments.sql` — an mlcl-scaffolded API
28
+ * copies and replays it automatically on migrate; anywhere else run it once.
29
+ * Missing it surfaces as `relation "payments" does not exist` on the first
30
+ * billing call — nothing at runtime creates the table.
31
+ *
32
+ * @e2e
33
+ * Integration checklist — drive the real UI (live preview, no mocks), adapt
34
+ * each item to this app's actual billing screens/flows, and check every box
35
+ * off one by one. A box you can't check is an integration bug to fix — not a
36
+ * skip. This resource RECORDS a server-verified provider result (a receipt or
37
+ * subscription id verified via `@molecule/api-payments`) and resolves the plan
38
+ * — it does NOT charge cards and has no amount/status column, so drive the
39
+ * provider's real verify path; never fabricate a record or a status:
40
+ * - [ ] A completed purchase/subscribe flow reflects in the account: the paid
41
+ * tier's capabilities unlock and a payment record binds to THIS user with the
42
+ * right platformKey (stripe/apple/google), productId/priceId, and
43
+ * transactionId — and it appears in the user's own billing/subscription view.
44
+ * - [ ] The plan and price shown match what was actually purchased: the tier is
45
+ * resolved from the VERIFIED product/price id against the registered plans,
46
+ * and any amount/currency shown comes from that plan (its `price`) or the
47
+ * provider's verified `data` — never a client-sent field. An amount renders
48
+ * formatted with its currency, not as a raw smallest-unit integer.
49
+ * - [ ] Status follows the provider, not the client: a verified payment grants
50
+ * the plan (pending is granted only once it succeeds), and a provider
51
+ * cancellation/refund/expiry webhook (`handlePaymentNotification`) REVOKES it
52
+ * so the user loses premium. No request field (`planKey`, `isPro`, a bare
53
+ * `subscriptionId`) lets the client set or keep an active/paid status.
54
+ * - [ ] Replay and re-complete guard: one receipt/subscription transaction
55
+ * binds to exactly ONE account (UNIQUE(platformKey, transactionId),
56
+ * first-claim-wins) — replaying the same receipt into a second account is
57
+ * REJECTED, re-verifying your own is idempotent (no double grant), and a
58
+ * refunded/canceled entitlement can't be reclaimed without a NEW verified
59
+ * payment.
60
+ * - [ ] Authorization — a user sees only THEIR OWN payments: guessing another
61
+ * user's payment/transaction id returns nothing (records scope by userId), and
62
+ * NO endpoint lets a user mark their own payment succeeded/refunded or set
63
+ * their own plan/isPro to spoof having paid — only the verified provider
64
+ * result grants the tier.
65
+ * - [ ] The provider secret (e.g. STRIPE_SECRET_KEY / APPLE_SHARED_SECRET /
66
+ * GOOGLE_API_SERVICE_KEY_OBJECT) is used only server-side for verification and
67
+ * never reaches the browser bundle or a client request — this resource is
68
+ * SERVER-ONLY.
69
+ *
70
+ * @example
71
+ * ```ts
72
+ * import { registerPlans, stripeMonthly, stripeYearly } from '@molecule/api-resource-payment'
73
+ *
74
+ * // Register your plan catalogue at startup. The keys are YOUR plan ids; the ready-made
75
+ * // Plan objects carry the env-configured Stripe price/product ids (also register the
76
+ * // apple and google plan exports when you support those providers):
77
+ * registerPlans({ monthly: stripeMonthly, yearly: stripeYearly })
78
+ *
79
+ * // Then grant a plan ONLY after a SERVER-VERIFIED payment — never from a client field.
80
+ * // The full verify → record (replay-guarded) → resolve → grant flow lives in the scaffolded
81
+ * // user `verifyPayment` handler; verify receipts against @molecule/api-payments and store
82
+ * // them with `paymentRecordService.store` (it THROWS on a replayed transactionId — reject).
83
+ * ```
84
+ *
85
+ * @module `@molecule/api-resource-payment`
86
+ */
87
+ export * from './browser-guard.js';
88
+ export * from './i18n.js';
89
+ export * from './plans.js';
90
+ export * from './planService.js';
91
+ export * from './recordService.js';
92
+ export * from './resource.js';
93
+ export * from './schema.js';
94
+ export * as types from './types.js';
95
+ export * from './utilities.js';
96
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqFG;AAEH,cAAc,oBAAoB,CAAA;AAClC,cAAc,WAAW,CAAA;AACzB,cAAc,YAAY,CAAA;AAC1B,cAAc,kBAAkB,CAAA;AAChC,cAAc,oBAAoB,CAAA;AAClC,cAAc,eAAe,CAAA;AAC7B,cAAc,aAAa,CAAA;AAC3B,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AACnC,cAAc,gBAAgB,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,96 @@
1
+ /**
2
+ * Payment resource with subscription plan management.
3
+ *
4
+ * @remarks
5
+ * A plan/entitlement is granted ONLY after a SERVER-VERIFIED payment — never from anything
6
+ * the client reports. The flow (implemented by the user resource's `verifyPayment` handler):
7
+ *
8
+ * 1. **Verify** the provider token/receipt server-side via the bonded payments provider
9
+ * (`@molecule/api-payments` — read its docs). Trust only its normalized result.
10
+ * 2. **Record** it with {@link paymentRecordService}`.store`, which enforces
11
+ * `UNIQUE(platformKey, transactionId)` so one receipt binds to exactly ONE account.
12
+ * 3. **Resolve** the plan from the verified product/price id against the registered
13
+ * {@link plans} (match BOTH `productId` and `priceId`), then grant it.
14
+ *
15
+ * Weak-integration mistakes to avoid:
16
+ * - **Never trust a client-sent plan / subscription / "isPro".** The plan is derived from
17
+ * the verified provider result, not a request field.
18
+ * - **Never swallow the duplicate-record error.** {@link paymentRecordService}`.store`
19
+ * THROWS when a `transactionId` is already claimed — that is the replay guard
20
+ * (first-claim-wins). Catch it and REJECT; do not grant the plan to a second account.
21
+ * - **Register your catalogue** with {@link registerPlans} using YOUR price/product ids
22
+ * (the env-configured `price_…`), and resolve by BOTH product and price id — providers
23
+ * report the product on a subscription while checkout uses the price.
24
+ * - Re-verify entitlement server-side wherever it gates access; never cache "is subscribed"
25
+ * somewhere the client can set.
26
+ *
27
+ * The `payments` table ships in `setup/payments.sql` — an mlcl-scaffolded API
28
+ * copies and replays it automatically on migrate; anywhere else run it once.
29
+ * Missing it surfaces as `relation "payments" does not exist` on the first
30
+ * billing call — nothing at runtime creates the table.
31
+ *
32
+ * @e2e
33
+ * Integration checklist — drive the real UI (live preview, no mocks), adapt
34
+ * each item to this app's actual billing screens/flows, and check every box
35
+ * off one by one. A box you can't check is an integration bug to fix — not a
36
+ * skip. This resource RECORDS a server-verified provider result (a receipt or
37
+ * subscription id verified via `@molecule/api-payments`) and resolves the plan
38
+ * — it does NOT charge cards and has no amount/status column, so drive the
39
+ * provider's real verify path; never fabricate a record or a status:
40
+ * - [ ] A completed purchase/subscribe flow reflects in the account: the paid
41
+ * tier's capabilities unlock and a payment record binds to THIS user with the
42
+ * right platformKey (stripe/apple/google), productId/priceId, and
43
+ * transactionId — and it appears in the user's own billing/subscription view.
44
+ * - [ ] The plan and price shown match what was actually purchased: the tier is
45
+ * resolved from the VERIFIED product/price id against the registered plans,
46
+ * and any amount/currency shown comes from that plan (its `price`) or the
47
+ * provider's verified `data` — never a client-sent field. An amount renders
48
+ * formatted with its currency, not as a raw smallest-unit integer.
49
+ * - [ ] Status follows the provider, not the client: a verified payment grants
50
+ * the plan (pending is granted only once it succeeds), and a provider
51
+ * cancellation/refund/expiry webhook (`handlePaymentNotification`) REVOKES it
52
+ * so the user loses premium. No request field (`planKey`, `isPro`, a bare
53
+ * `subscriptionId`) lets the client set or keep an active/paid status.
54
+ * - [ ] Replay and re-complete guard: one receipt/subscription transaction
55
+ * binds to exactly ONE account (UNIQUE(platformKey, transactionId),
56
+ * first-claim-wins) — replaying the same receipt into a second account is
57
+ * REJECTED, re-verifying your own is idempotent (no double grant), and a
58
+ * refunded/canceled entitlement can't be reclaimed without a NEW verified
59
+ * payment.
60
+ * - [ ] Authorization — a user sees only THEIR OWN payments: guessing another
61
+ * user's payment/transaction id returns nothing (records scope by userId), and
62
+ * NO endpoint lets a user mark their own payment succeeded/refunded or set
63
+ * their own plan/isPro to spoof having paid — only the verified provider
64
+ * result grants the tier.
65
+ * - [ ] The provider secret (e.g. STRIPE_SECRET_KEY / APPLE_SHARED_SECRET /
66
+ * GOOGLE_API_SERVICE_KEY_OBJECT) is used only server-side for verification and
67
+ * never reaches the browser bundle or a client request — this resource is
68
+ * SERVER-ONLY.
69
+ *
70
+ * @example
71
+ * ```ts
72
+ * import { registerPlans, stripeMonthly, stripeYearly } from '@molecule/api-resource-payment'
73
+ *
74
+ * // Register your plan catalogue at startup. The keys are YOUR plan ids; the ready-made
75
+ * // Plan objects carry the env-configured Stripe price/product ids (also register the
76
+ * // apple and google plan exports when you support those providers):
77
+ * registerPlans({ monthly: stripeMonthly, yearly: stripeYearly })
78
+ *
79
+ * // Then grant a plan ONLY after a SERVER-VERIFIED payment — never from a client field.
80
+ * // The full verify → record (replay-guarded) → resolve → grant flow lives in the scaffolded
81
+ * // user `verifyPayment` handler; verify receipts against @molecule/api-payments and store
82
+ * // them with `paymentRecordService.store` (it THROWS on a replayed transactionId — reject).
83
+ * ```
84
+ *
85
+ * @module `@molecule/api-resource-payment`
86
+ */
87
+ export * from './browser-guard.js';
88
+ export * from './i18n.js';
89
+ export * from './plans.js';
90
+ export * from './planService.js';
91
+ export * from './recordService.js';
92
+ export * from './resource.js';
93
+ export * from './schema.js';
94
+ export * as types from './types.js';
95
+ export * from './utilities.js';
96
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqFG;AAEH,cAAc,oBAAoB,CAAA;AAClC,cAAc,WAAW,CAAA;AACzB,cAAc,YAAY,CAAA;AAC1B,cAAc,kBAAkB,CAAA;AAChC,cAAc,oBAAoB,CAAA;AAClC,cAAc,eAAe,CAAA;AAC7B,cAAc,aAAa,CAAA;AAC3B,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AACnC,cAAc,gBAAgB,CAAA"}