@molecule/api-resource-payment 1.0.2 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +111 -24
- package/README.md +222 -87
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/package.json +7 -7
- /package/{setup → src/__setup__}/payments.sql +0 -0
package/LICENSE
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
|
|
1
2
|
Apache License
|
|
2
3
|
Version 2.0, January 2004
|
|
3
4
|
http://www.apache.org/licenses/
|
|
@@ -34,21 +35,33 @@
|
|
|
34
35
|
|
|
35
36
|
"Work" shall mean the work of authorship, whether in Source or
|
|
36
37
|
Object form, made available under the License, as indicated by a
|
|
37
|
-
copyright notice that is included in or attached to the work
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
38
40
|
|
|
39
41
|
"Derivative Works" shall mean any work, whether in Source or Object
|
|
40
42
|
form, that is based on (or derived from) the Work and for which the
|
|
41
43
|
editorial revisions, annotations, elaborations, or other modifications
|
|
42
|
-
represent, as a whole, an original work of authorship.
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
49
62
|
|
|
50
63
|
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
51
|
-
on behalf of whom a Contribution has been received by
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
52
65
|
subsequently incorporated within the Work.
|
|
53
66
|
|
|
54
67
|
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
@@ -61,8 +74,18 @@
|
|
|
61
74
|
3. Grant of Patent License. Subject to the terms and conditions of
|
|
62
75
|
this License, each Contributor hereby grants to You a perpetual,
|
|
63
76
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
64
|
-
|
|
65
|
-
and otherwise transfer the Work
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
66
89
|
|
|
67
90
|
4. Redistribution. You may reproduce and distribute copies of the
|
|
68
91
|
Work or Derivative Works thereof in any medium, with or without
|
|
@@ -84,23 +107,87 @@
|
|
|
84
107
|
(d) If the Work includes a "NOTICE" text file as part of its
|
|
85
108
|
distribution, then any Derivative Works that You distribute must
|
|
86
109
|
include a readable copy of the attribution notices contained
|
|
87
|
-
within such NOTICE file
|
|
88
|
-
|
|
89
|
-
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
90
138
|
|
|
91
139
|
6. Trademarks. This License does not grant permission to use the trade
|
|
92
|
-
names, trademarks, service marks, or product names of the Licensor
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
93
143
|
|
|
94
144
|
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
95
|
-
agreed to in writing, Licensor provides the Work
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
104
191
|
|
|
105
192
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
106
193
|
you may not use this file except in compliance with the License.
|
package/README.md
CHANGED
|
@@ -3,17 +3,17 @@ AUTO-GENERATED — DO NOT EDIT THIS FILE.
|
|
|
3
3
|
Generated by `mlcl sync-docs` from the package's src/index.ts JSDoc + mlcl/registry.json.
|
|
4
4
|
Edits here are overwritten on the next commit (molecule's pre-commit hook regenerates).
|
|
5
5
|
To change this document, edit the module-level JSDoc in src/index.ts.
|
|
6
|
-
Generated: 2026-
|
|
6
|
+
Generated: 2026-10-17T19:17:38.278Z
|
|
7
7
|
-->
|
|
8
8
|
|
|
9
9
|
# @molecule/api-resource-payment
|
|
10
10
|
|
|
11
|
+
Payment resource with subscription plan management.
|
|
12
|
+
|
|
11
13
|
> **Auto-generated, AI-first package reference** for the [molecule.dev](https://molecule.dev) ecosystem.
|
|
12
14
|
> It is written to be read by coding agents as much as by people, and is generated from this
|
|
13
15
|
> package's source — edit `src/index.ts` JSDoc, not this file.
|
|
14
16
|
|
|
15
|
-
Payment resource with subscription plan management.
|
|
16
|
-
|
|
17
17
|
## Quick Start
|
|
18
18
|
|
|
19
19
|
```ts
|
|
@@ -44,20 +44,20 @@ npm install @molecule/api-resource-payment @molecule/api-bond @molecule/api-data
|
|
|
44
44
|
|
|
45
45
|
### Types
|
|
46
46
|
|
|
47
|
-
#### `
|
|
47
|
+
#### `Props`
|
|
48
48
|
|
|
49
|
-
|
|
49
|
+
Full payment record properties (userId, platform, transactionId, productId, data, receipt).
|
|
50
50
|
|
|
51
51
|
```typescript
|
|
52
|
-
type
|
|
52
|
+
type Props = z.infer<typeof propsSchema>
|
|
53
53
|
```
|
|
54
54
|
|
|
55
|
-
#### `
|
|
55
|
+
#### `CreateProps`
|
|
56
56
|
|
|
57
|
-
|
|
57
|
+
Fields required when creating a new payment record.
|
|
58
58
|
|
|
59
59
|
```typescript
|
|
60
|
-
type
|
|
60
|
+
type CreateProps = z.infer<typeof createPropsSchema>
|
|
61
61
|
```
|
|
62
62
|
|
|
63
63
|
#### `UpdateProps`
|
|
@@ -80,19 +80,31 @@ This is surfaced (not swallowed) so callers such as the user resource's
|
|
|
80
80
|
`verifyPayment` handler can enforce first-claim-wins ownership and reject a
|
|
81
81
|
replayed receipt instead of silently granting the plan to a second account.
|
|
82
82
|
|
|
83
|
-
### Functions
|
|
84
|
-
|
|
85
|
-
#### `getPeriodTime(period)`
|
|
86
|
-
|
|
87
|
-
Get the duration in milliseconds for a billing period.
|
|
88
|
-
|
|
89
83
|
```typescript
|
|
90
|
-
|
|
84
|
+
class PaymentRecordConflictError extends Error {
|
|
85
|
+
/** The platform key (e.g. `'apple'`, `'google'`, `'stripe'`). */
|
|
86
|
+
readonly platformKey: string
|
|
87
|
+
/** The transaction id that is already bound. */
|
|
88
|
+
readonly transactionId: string
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Builds the conflict error, naming the platform + transaction already bound
|
|
92
|
+
* so the caller can report which record it collided with.
|
|
93
|
+
*
|
|
94
|
+
* @param platformKey - The platform key of the conflicting record.
|
|
95
|
+
* @param transactionId - The transaction id that is already bound.
|
|
96
|
+
* @param options - Standard error options (e.g. `{ cause }`).
|
|
97
|
+
*/
|
|
98
|
+
constructor(platformKey: string, transactionId: string, options?: ErrorOptions) {
|
|
99
|
+
super(`Payment record already exists for ${platformKey} transaction ${transactionId}`, options)
|
|
100
|
+
this.name = 'PaymentRecordConflictError'
|
|
101
|
+
this.platformKey = platformKey
|
|
102
|
+
this.transactionId = transactionId
|
|
103
|
+
}
|
|
104
|
+
}
|
|
91
105
|
```
|
|
92
106
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
**Returns:** The period duration in milliseconds.
|
|
107
|
+
### Functions
|
|
96
108
|
|
|
97
109
|
#### `registerPlans(customPlans)`
|
|
98
110
|
|
|
@@ -116,8 +128,55 @@ function registerPlans(customPlans: Record<string, Plan>): void
|
|
|
116
128
|
|
|
117
129
|
- `customPlans` — Plans to merge into the registry, keyed by `planKey`.
|
|
118
130
|
|
|
131
|
+
#### `getPeriodTime(period)`
|
|
132
|
+
|
|
133
|
+
Get the duration in milliseconds for a billing period.
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
function getPeriodTime(period: PlanPeriod): number
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
- `period` — The billing period ('month' or 'year').
|
|
140
|
+
|
|
141
|
+
**Returns:** The period duration in milliseconds.
|
|
142
|
+
|
|
119
143
|
### Constants
|
|
120
144
|
|
|
145
|
+
#### `i18nRegistered`
|
|
146
|
+
|
|
147
|
+
The i18n registered.
|
|
148
|
+
|
|
149
|
+
```typescript
|
|
150
|
+
const i18nRegistered: true
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
#### `planService`
|
|
154
|
+
|
|
155
|
+
PlanService implementation for the bond system.
|
|
156
|
+
|
|
157
|
+
Provides plan lookup operations that other resources
|
|
158
|
+
can use through `get('plans')` / `require('plans')`.
|
|
159
|
+
|
|
160
|
+
```typescript
|
|
161
|
+
const planService: PlanService
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
#### `stripeMonthly`
|
|
165
|
+
|
|
166
|
+
Stripe monthly subscription plan ($5/month, auto-renews).
|
|
167
|
+
|
|
168
|
+
```typescript
|
|
169
|
+
const stripeMonthly: Plan
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
#### `stripeYearly`
|
|
173
|
+
|
|
174
|
+
Stripe yearly subscription plan ($55/year, auto-renews).
|
|
175
|
+
|
|
176
|
+
```typescript
|
|
177
|
+
const stripeYearly: Plan
|
|
178
|
+
```
|
|
179
|
+
|
|
121
180
|
#### `appleMonthly`
|
|
122
181
|
|
|
123
182
|
Apple App Store monthly subscription plan ($5.99/month, auto-renews).
|
|
@@ -134,28 +193,6 @@ Apple App Store yearly subscription plan ($64.99/year, auto-renews).
|
|
|
134
193
|
const appleYearly: Plan
|
|
135
194
|
```
|
|
136
195
|
|
|
137
|
-
#### `createPropsSchema`
|
|
138
|
-
|
|
139
|
-
Zod schema for creating a payment record (picks fields required at creation time).
|
|
140
|
-
|
|
141
|
-
```typescript
|
|
142
|
-
const createPropsSchema: z.ZodObject<
|
|
143
|
-
{
|
|
144
|
-
createdAt: z.ZodString
|
|
145
|
-
updatedAt: z.ZodString
|
|
146
|
-
userId: z.ZodString
|
|
147
|
-
platformKey: z.ZodDefault<
|
|
148
|
-
z.ZodEnum<{ '': ''; stripe: 'stripe'; apple: 'apple'; google: 'google' }>
|
|
149
|
-
>
|
|
150
|
-
transactionId: z.ZodOptional<z.ZodString>
|
|
151
|
-
productId: z.ZodString
|
|
152
|
-
data: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>
|
|
153
|
-
receipt: z.ZodOptional<z.ZodString>
|
|
154
|
-
},
|
|
155
|
-
z.core.$strip
|
|
156
|
-
>
|
|
157
|
-
```
|
|
158
|
-
|
|
159
196
|
#### `googleMonthly`
|
|
160
197
|
|
|
161
198
|
Google Play monthly subscription plan ($5.99/month, auto-renews).
|
|
@@ -172,12 +209,12 @@ Google Play yearly subscription plan ($64.99/year, auto-renews).
|
|
|
172
209
|
const googleYearly: Plan
|
|
173
210
|
```
|
|
174
211
|
|
|
175
|
-
#### `
|
|
212
|
+
#### `plans`
|
|
176
213
|
|
|
177
|
-
The
|
|
214
|
+
All available plans indexed by planKey. The empty string key `''` maps to the default free plan.
|
|
178
215
|
|
|
179
216
|
```typescript
|
|
180
|
-
const
|
|
217
|
+
const plans: Record<string, Plan>
|
|
181
218
|
```
|
|
182
219
|
|
|
183
220
|
#### `paymentRecordService`
|
|
@@ -191,33 +228,44 @@ can use through `get<PaymentRecordService>('paymentRecords')`.
|
|
|
191
228
|
const paymentRecordService: PaymentRecordService
|
|
192
229
|
```
|
|
193
230
|
|
|
194
|
-
#### `
|
|
231
|
+
#### `resource`
|
|
195
232
|
|
|
196
|
-
|
|
233
|
+
Payment resource definition with JSON schema for validation.
|
|
197
234
|
|
|
198
235
|
```typescript
|
|
199
|
-
const
|
|
236
|
+
const resource: types.Resource
|
|
200
237
|
```
|
|
201
238
|
|
|
202
|
-
#### `
|
|
203
|
-
|
|
204
|
-
PlanService implementation for the bond system.
|
|
239
|
+
#### `propsSchema`
|
|
205
240
|
|
|
206
|
-
|
|
207
|
-
can use through `get('plans')` / `require('plans')`.
|
|
241
|
+
Validation schema for props.
|
|
208
242
|
|
|
209
243
|
```typescript
|
|
210
|
-
const
|
|
244
|
+
const propsSchema: z.ZodObject<
|
|
245
|
+
{
|
|
246
|
+
id: z.ZodString
|
|
247
|
+
createdAt: z.ZodString
|
|
248
|
+
updatedAt: z.ZodString
|
|
249
|
+
userId: z.ZodString
|
|
250
|
+
platformKey: z.ZodDefault<
|
|
251
|
+
z.ZodEnum<{ '': ''; stripe: 'stripe'; apple: 'apple'; google: 'google' }>
|
|
252
|
+
>
|
|
253
|
+
transactionId: z.ZodOptional<z.ZodString>
|
|
254
|
+
productId: z.ZodString
|
|
255
|
+
data: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>
|
|
256
|
+
receipt: z.ZodOptional<z.ZodString>
|
|
257
|
+
},
|
|
258
|
+
z.core.$strip
|
|
259
|
+
>
|
|
211
260
|
```
|
|
212
261
|
|
|
213
|
-
#### `
|
|
262
|
+
#### `createPropsSchema`
|
|
214
263
|
|
|
215
|
-
|
|
264
|
+
Zod schema for creating a payment record (picks fields required at creation time).
|
|
216
265
|
|
|
217
266
|
```typescript
|
|
218
|
-
const
|
|
267
|
+
const createPropsSchema: z.ZodObject<
|
|
219
268
|
{
|
|
220
|
-
id: z.ZodString
|
|
221
269
|
createdAt: z.ZodString
|
|
222
270
|
updatedAt: z.ZodString
|
|
223
271
|
userId: z.ZodString
|
|
@@ -233,58 +281,145 @@ const propsSchema: z.ZodObject<
|
|
|
233
281
|
>
|
|
234
282
|
```
|
|
235
283
|
|
|
236
|
-
#### `
|
|
284
|
+
#### `updatePropsSchema`
|
|
237
285
|
|
|
238
|
-
|
|
286
|
+
Zod schema for updating a payment record (data and receipt only).
|
|
239
287
|
|
|
240
288
|
```typescript
|
|
241
|
-
const
|
|
289
|
+
const updatePropsSchema: z.ZodObject<
|
|
290
|
+
{
|
|
291
|
+
data: z.ZodOptional<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>>
|
|
292
|
+
receipt: z.ZodOptional<z.ZodOptional<z.ZodString>>
|
|
293
|
+
},
|
|
294
|
+
z.core.$strip
|
|
295
|
+
>
|
|
242
296
|
```
|
|
243
297
|
|
|
244
|
-
|
|
298
|
+
### Namespaces
|
|
245
299
|
|
|
246
|
-
|
|
300
|
+
#### `types`
|
|
301
|
+
|
|
302
|
+
Re-exported as a namespace — reach every member below through it (e.g. `types.<name>`).
|
|
303
|
+
|
|
304
|
+
##### `types.PlatformKey`
|
|
305
|
+
|
|
306
|
+
Every available platform.
|
|
307
|
+
|
|
308
|
+
Open string type so new payment platforms can be added without modifying
|
|
309
|
+
this package. Well-known values include 'stripe', 'apple', and 'google'.
|
|
247
310
|
|
|
248
311
|
```typescript
|
|
249
|
-
|
|
312
|
+
type PlatformKey = string
|
|
250
313
|
```
|
|
251
314
|
|
|
252
|
-
|
|
315
|
+
##### `types.PlanAlias`
|
|
253
316
|
|
|
254
|
-
|
|
317
|
+
Every available plan alias.
|
|
255
318
|
|
|
256
319
|
```typescript
|
|
257
|
-
|
|
320
|
+
type PlanAlias = '' | 'monthly' | 'yearly'
|
|
258
321
|
```
|
|
259
322
|
|
|
260
|
-
|
|
323
|
+
##### `types.PlanPeriod`
|
|
261
324
|
|
|
262
|
-
|
|
325
|
+
Every available plan period.
|
|
263
326
|
|
|
264
327
|
```typescript
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
328
|
+
type PlanPeriod = '' | 'month' | 'year'
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
##### `types.Props`
|
|
332
|
+
|
|
333
|
+
The payment's properties.
|
|
334
|
+
|
|
335
|
+
```typescript
|
|
336
|
+
interface Props {
|
|
337
|
+
id: string
|
|
338
|
+
createdAt: string
|
|
339
|
+
updatedAt: string
|
|
340
|
+
userId: string
|
|
341
|
+
platformKey: PlatformKey
|
|
342
|
+
transactionId?: string
|
|
343
|
+
productId: string
|
|
344
|
+
data?: Record<string, unknown>
|
|
345
|
+
receipt?: string
|
|
346
|
+
}
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
##### `types.CreateProps`
|
|
350
|
+
|
|
351
|
+
Properties when creating a payment.
|
|
352
|
+
|
|
353
|
+
```typescript
|
|
354
|
+
type CreateProps = Pick<
|
|
355
|
+
Props,
|
|
356
|
+
| 'createdAt'
|
|
357
|
+
| 'updatedAt'
|
|
358
|
+
| 'userId'
|
|
359
|
+
| 'platformKey'
|
|
360
|
+
| 'transactionId'
|
|
361
|
+
| 'productId'
|
|
362
|
+
| 'data'
|
|
363
|
+
| 'receipt'
|
|
271
364
|
>
|
|
272
365
|
```
|
|
273
366
|
|
|
274
|
-
|
|
367
|
+
##### `types.UpdateProps`
|
|
275
368
|
|
|
276
|
-
|
|
369
|
+
Properties when updating a payment.
|
|
370
|
+
|
|
371
|
+
```typescript
|
|
372
|
+
type UpdateProps = Partial<Pick<Props, 'data' | 'receipt'>>
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
##### `types.Plan`
|
|
376
|
+
|
|
377
|
+
A plan's properties.
|
|
277
378
|
|
|
278
|
-
|
|
379
|
+
```typescript
|
|
380
|
+
interface Plan {
|
|
381
|
+
planKey: string
|
|
382
|
+
platformKey: PlatformKey
|
|
383
|
+
platformProductId: string
|
|
384
|
+
/**
|
|
385
|
+
* The platform's PRICE identifiers that grant this plan (e.g. Stripe
|
|
386
|
+
* `price_…` ids). Apps configure prices — not products — in their env
|
|
387
|
+
* (`STRIPE_<APP>_PRO_MONTHLY` etc.), so plan resolution matches an
|
|
388
|
+
* incoming platform identifier against `platformProductId` OR membership
|
|
389
|
+
* in this list.
|
|
390
|
+
*/
|
|
391
|
+
platformPriceIds?: string[]
|
|
392
|
+
alias: PlanAlias
|
|
393
|
+
period: PlanPeriod
|
|
394
|
+
price: string
|
|
395
|
+
autoRenews?: boolean
|
|
396
|
+
title: string
|
|
397
|
+
/** i18n key for {@link Plan.title}. Optional — plans registered cross-package (e.g. by a billing router bridging its tiers) carry plain text only. */
|
|
398
|
+
titleKey?: string
|
|
399
|
+
description: string
|
|
400
|
+
/** i18n key for {@link Plan.description}. Optional — see {@link Plan.titleKey}. */
|
|
401
|
+
descriptionKey?: string
|
|
402
|
+
shortDescription?: string
|
|
403
|
+
shortDescriptionKey?: string
|
|
404
|
+
highlightedDescription?: string
|
|
405
|
+
highlightedDescriptionKey?: string
|
|
406
|
+
capabilities: {
|
|
407
|
+
premium: boolean
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
```
|
|
411
|
+
|
|
412
|
+
##### `types.Resource`
|
|
279
413
|
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
414
|
+
Resource type.
|
|
415
|
+
|
|
416
|
+
```typescript
|
|
417
|
+
interface Resource {
|
|
418
|
+
name: string
|
|
419
|
+
tableName: string
|
|
420
|
+
schema: unknown
|
|
421
|
+
}
|
|
422
|
+
```
|
|
288
423
|
|
|
289
424
|
## Services
|
|
290
425
|
|
|
@@ -346,8 +481,8 @@ Weak-integration mistakes to avoid:
|
|
|
346
481
|
- Re-verify entitlement server-side wherever it gates access; never cache "is subscribed"
|
|
347
482
|
somewhere the client can set.
|
|
348
483
|
|
|
349
|
-
The `payments` table ships in `
|
|
350
|
-
copies and replays it automatically on migrate; anywhere else run it once.
|
|
484
|
+
The `payments` table ships in `src/__setup__/payments.sql` — an mlcl-scaffolded
|
|
485
|
+
API copies and replays it automatically on migrate; anywhere else run it once.
|
|
351
486
|
Missing it surfaces as `relation "payments" does not exist` on the first
|
|
352
487
|
billing call — nothing at runtime creates the table.
|
|
353
488
|
|
package/dist/index.d.ts
CHANGED
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
* - Re-verify entitlement server-side wherever it gates access; never cache "is subscribed"
|
|
25
25
|
* somewhere the client can set.
|
|
26
26
|
*
|
|
27
|
-
* The `payments` table ships in `
|
|
28
|
-
* copies and replays it automatically on migrate; anywhere else run it once.
|
|
27
|
+
* The `payments` table ships in `src/__setup__/payments.sql` — an mlcl-scaffolded
|
|
28
|
+
* API copies and replays it automatically on migrate; anywhere else run it once.
|
|
29
29
|
* Missing it surfaces as `relation "payments" does not exist` on the first
|
|
30
30
|
* billing call — nothing at runtime creates the table.
|
|
31
31
|
*
|
package/dist/index.js
CHANGED
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
* - Re-verify entitlement server-side wherever it gates access; never cache "is subscribed"
|
|
25
25
|
* somewhere the client can set.
|
|
26
26
|
*
|
|
27
|
-
* The `payments` table ships in `
|
|
28
|
-
* copies and replays it automatically on migrate; anywhere else run it once.
|
|
27
|
+
* The `payments` table ships in `src/__setup__/payments.sql` — an mlcl-scaffolded
|
|
28
|
+
* API copies and replays it automatically on migrate; anywhere else run it once.
|
|
29
29
|
* Missing it surfaces as `relation "payments" does not exist` on the first
|
|
30
30
|
* billing call — nothing at runtime creates the table.
|
|
31
31
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@molecule/api-resource-payment",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "Payment resource with subscription plan management",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -18,20 +18,20 @@
|
|
|
18
18
|
},
|
|
19
19
|
"files": [
|
|
20
20
|
"dist",
|
|
21
|
-
"
|
|
21
|
+
"src/__setup__",
|
|
22
22
|
"README.md"
|
|
23
23
|
],
|
|
24
24
|
"license": "Apache-2.0",
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"zod": "4.
|
|
26
|
+
"zod": "4.6.7"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@molecule/api-bond": "1.0.
|
|
29
|
+
"@molecule/api-bond": "1.0.3",
|
|
30
30
|
"@molecule/api-locales-payment": "1.0.2",
|
|
31
|
-
"@molecule/api-payments": "1.2.
|
|
32
|
-
"@types/node": "26.
|
|
31
|
+
"@molecule/api-payments": "1.2.2",
|
|
32
|
+
"@types/node": "26.6.5",
|
|
33
33
|
"typescript": "6.0.3",
|
|
34
|
-
"vitest": "4.1.
|
|
34
|
+
"vitest": "4.1.12"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
37
|
"@molecule/api-bond": "^1.0.1",
|
|
File without changes
|