@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.
- package/LICENSE +115 -0
- package/dist/__tests__/index.test.d.ts +5 -0
- package/dist/__tests__/index.test.d.ts.map +1 -0
- package/dist/__tests__/index.test.js +85 -0
- package/dist/__tests__/index.test.js.map +1 -0
- package/dist/__tests__/planService.test.d.ts +5 -0
- package/dist/__tests__/planService.test.d.ts.map +1 -0
- package/dist/__tests__/planService.test.js +166 -0
- package/dist/__tests__/planService.test.js.map +1 -0
- package/dist/__tests__/plans.test.d.ts +5 -0
- package/dist/__tests__/plans.test.d.ts.map +1 -0
- package/dist/__tests__/plans.test.js +296 -0
- package/dist/__tests__/plans.test.js.map +1 -0
- package/dist/__tests__/recordService.test.d.ts +5 -0
- package/dist/__tests__/recordService.test.d.ts.map +1 -0
- package/dist/__tests__/recordService.test.js +214 -0
- package/dist/__tests__/recordService.test.js.map +1 -0
- package/dist/__tests__/resource.test.d.ts +5 -0
- package/dist/__tests__/resource.test.d.ts.map +1 -0
- package/dist/__tests__/resource.test.js +56 -0
- package/dist/__tests__/resource.test.js.map +1 -0
- package/dist/__tests__/schema.test.d.ts +5 -0
- package/dist/__tests__/schema.test.d.ts.map +1 -0
- package/dist/__tests__/schema.test.js +275 -0
- package/dist/__tests__/schema.test.js.map +1 -0
- package/dist/__tests__/utilities.test.d.ts +5 -0
- package/dist/__tests__/utilities.test.d.ts.map +1 -0
- package/dist/__tests__/utilities.test.js +59 -0
- package/dist/__tests__/utilities.test.js.map +1 -0
- package/dist/browser-guard.d.ts +2 -0
- package/dist/browser-guard.d.ts.map +1 -0
- package/dist/browser-guard.js +19 -0
- package/dist/browser-guard.js.map +1 -0
- package/dist/i18n.d.ts +10 -0
- package/dist/i18n.d.ts.map +1 -0
- package/dist/i18n.js +18 -0
- package/dist/i18n.js.map +1 -0
- package/dist/index.d.ts +96 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +96 -0
- package/dist/index.js.map +1 -0
- package/dist/planService.d.ts +9 -0
- package/dist/planService.d.ts.map +1 -0
- package/dist/planService.js +53 -0
- package/dist/planService.js.map +1 -0
- package/dist/plans.d.ts +34 -0
- package/dist/plans.d.ts.map +1 -0
- package/dist/plans.js +167 -0
- package/dist/plans.js.map +1 -0
- package/dist/recordService.d.ts +33 -0
- package/dist/recordService.d.ts.map +1 -0
- package/dist/recordService.js +162 -0
- package/dist/recordService.js.map +1 -0
- package/dist/resource.d.ts +4 -0
- package/dist/resource.d.ts.map +1 -0
- package/dist/resource.js +22 -0
- package/dist/resource.js.map +1 -0
- package/dist/schema.d.ts +58 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +38 -0
- package/dist/schema.js.map +1 -0
- package/dist/types.d.ts +83 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +6 -0
- package/dist/types.js.map +1 -0
- package/dist/utilities.d.ts +8 -0
- package/dist/utilities.d.ts.map +1 -0
- package/dist/utilities.js +25 -0
- package/dist/utilities.js.map +1 -0
- package/package.json +54 -0
- package/setup/payments.sql +22 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { PlanService } from '@molecule/api-payments';
|
|
2
|
+
/**
|
|
3
|
+
* PlanService implementation for the bond system.
|
|
4
|
+
*
|
|
5
|
+
* Provides plan lookup operations that other resources
|
|
6
|
+
* can use through `get('plans')` / `require('plans')`.
|
|
7
|
+
*/
|
|
8
|
+
export declare const planService: PlanService;
|
|
9
|
+
//# sourceMappingURL=planService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"planService.d.ts","sourceRoot":"","sources":["../src/planService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAQ,WAAW,EAAE,MAAM,wBAAwB,CAAA;AAK/D;;;;;GAKG;AACH,eAAO,MAAM,WAAW,EAAE,WAkDzB,CAAA"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { plans, registerPlans } from './plans.js';
|
|
2
|
+
/**
|
|
3
|
+
* PlanService implementation for the bond system.
|
|
4
|
+
*
|
|
5
|
+
* Provides plan lookup operations that other resources
|
|
6
|
+
* can use through `get('plans')` / `require('plans')`.
|
|
7
|
+
*/
|
|
8
|
+
export const planService = {
|
|
9
|
+
findPlan(planKey) {
|
|
10
|
+
return plans[planKey] ?? null;
|
|
11
|
+
},
|
|
12
|
+
findPlanByProductId(productId) {
|
|
13
|
+
if (!productId)
|
|
14
|
+
return null;
|
|
15
|
+
return (Object.values(plans).find((p) => (p.platformProductId !== '' && p.platformProductId === productId) ||
|
|
16
|
+
(p.platformPriceIds?.includes(productId) ?? false)) ?? null);
|
|
17
|
+
},
|
|
18
|
+
getDefaultPlan() {
|
|
19
|
+
return plans[''] ?? null;
|
|
20
|
+
},
|
|
21
|
+
getAllPlans() {
|
|
22
|
+
return Object.values(plans);
|
|
23
|
+
},
|
|
24
|
+
registerPlans(customPlans) {
|
|
25
|
+
// Adapt the cross-package core Plan to this resource's narrower local
|
|
26
|
+
// type: alias/period are closed vocabularies here, open strings there —
|
|
27
|
+
// anything unrecognized degrades to '' rather than failing registration.
|
|
28
|
+
const narrowed = Object.fromEntries(Object.entries(customPlans).map(([key, plan]) => {
|
|
29
|
+
const local = {
|
|
30
|
+
planKey: plan.planKey,
|
|
31
|
+
platformKey: plan.platformKey,
|
|
32
|
+
platformProductId: plan.platformProductId,
|
|
33
|
+
alias: plan.alias === 'monthly' || plan.alias === 'yearly' ? plan.alias : '',
|
|
34
|
+
period: plan.period === 'month' || plan.period === 'year' ? plan.period : '',
|
|
35
|
+
price: plan.price,
|
|
36
|
+
title: plan.title,
|
|
37
|
+
description: plan.description,
|
|
38
|
+
capabilities: { premium: plan.capabilities?.premium === true },
|
|
39
|
+
};
|
|
40
|
+
if (plan.platformPriceIds)
|
|
41
|
+
local.platformPriceIds = plan.platformPriceIds;
|
|
42
|
+
if (plan.autoRenews !== undefined)
|
|
43
|
+
local.autoRenews = plan.autoRenews;
|
|
44
|
+
if (plan.shortDescription)
|
|
45
|
+
local.shortDescription = plan.shortDescription;
|
|
46
|
+
if (plan.highlightedDescription)
|
|
47
|
+
local.highlightedDescription = plan.highlightedDescription;
|
|
48
|
+
return [key, local];
|
|
49
|
+
}));
|
|
50
|
+
registerPlans(narrowed);
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
//# sourceMappingURL=planService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"planService.js","sourceRoot":"","sources":["../src/planService.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAGjD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,WAAW,GAAgB;IACtC,QAAQ,CAAC,OAAe;QACtB,OAAO,KAAK,CAAC,OAAO,CAAC,IAAI,IAAI,CAAA;IAC/B,CAAC;IAED,mBAAmB,CAAC,SAAiB;QACnC,IAAI,CAAC,SAAS;YAAE,OAAO,IAAI,CAAA;QAC3B,OAAO,CACL,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,CACvB,CAAC,CAAC,EAAE,EAAE,CACJ,CAAC,CAAC,CAAC,iBAAiB,KAAK,EAAE,IAAI,CAAC,CAAC,iBAAiB,KAAK,SAAS,CAAC;YACjE,CAAC,CAAC,CAAC,gBAAgB,EAAE,QAAQ,CAAC,SAAS,CAAC,IAAI,KAAK,CAAC,CACrD,IAAI,IAAI,CACV,CAAA;IACH,CAAC;IAED,cAAc;QACZ,OAAO,KAAK,CAAC,EAAE,CAAC,IAAI,IAAI,CAAA;IAC1B,CAAC;IAED,WAAW;QACT,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;IAC7B,CAAC;IAED,aAAa,CAAC,WAAiC;QAC7C,sEAAsE;QACtE,wEAAwE;QACxE,yEAAyE;QACzE,MAAM,QAAQ,GAAG,MAAM,CAAC,WAAW,CACjC,MAAM,CAAC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zB,CAAC;CACF,CAAA"}
|
package/dist/plans.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { Plan } from './types.js';
|
|
2
|
+
/** Stripe monthly subscription plan ($5/month, auto-renews). */
|
|
3
|
+
export declare const stripeMonthly: Plan;
|
|
4
|
+
/** Stripe yearly subscription plan ($55/year, auto-renews). */
|
|
5
|
+
export declare const stripeYearly: Plan;
|
|
6
|
+
/** Apple App Store monthly subscription plan ($5.99/month, auto-renews). */
|
|
7
|
+
export declare const appleMonthly: Plan;
|
|
8
|
+
/** Apple App Store yearly subscription plan ($64.99/year, auto-renews). */
|
|
9
|
+
export declare const appleYearly: Plan;
|
|
10
|
+
/** Google Play monthly subscription plan ($5.99/month, auto-renews). */
|
|
11
|
+
export declare const googleMonthly: Plan;
|
|
12
|
+
/** Google Play yearly subscription plan ($64.99/year, auto-renews). */
|
|
13
|
+
export declare const googleYearly: Plan;
|
|
14
|
+
/** All available plans indexed by planKey. The empty string key `''` maps to the default free plan. */
|
|
15
|
+
export declare const plans: Record<string, Plan>;
|
|
16
|
+
/**
|
|
17
|
+
* Registers (or replaces) plans in the shared registry consumed by
|
|
18
|
+
* `planService` — keyed by `planKey`, merged into the defaults above.
|
|
19
|
+
*
|
|
20
|
+
* The built-in entries carry PLACEHOLDER platform product ids
|
|
21
|
+
* (`price_test_id` / `price_prod_id`), so `findPlanByProductId` can never
|
|
22
|
+
* match a real platform identifier until the app registers its own catalogue
|
|
23
|
+
* — typically derived from its pricing tiers with the real Stripe price ids
|
|
24
|
+
* from env (`@molecule/api-bonds-default-express`'s `createBillingRouter`
|
|
25
|
+
* does this automatically). Without registration, payment verification and
|
|
26
|
+
* webhook plan grants fail with "unknown plan" even though the charge
|
|
27
|
+
* succeeded.
|
|
28
|
+
*
|
|
29
|
+
* Idempotent: re-registering the same `planKey` overwrites that entry.
|
|
30
|
+
*
|
|
31
|
+
* @param customPlans - Plans to merge into the registry, keyed by `planKey`.
|
|
32
|
+
*/
|
|
33
|
+
export declare const registerPlans: (customPlans: Record<string, Plan>) => void;
|
|
34
|
+
//# sourceMappingURL=plans.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plans.d.ts","sourceRoot":"","sources":["../src/plans.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAsBtC,gEAAgE;AAChE,eAAO,MAAM,aAAa,EAAE,IAe3B,CAAA;AAED,+DAA+D;AAC/D,eAAO,MAAM,YAAY,EAAE,IAmB1B,CAAA;AAED,4EAA4E;AAC5E,eAAO,MAAM,YAAY,EAAE,IAe1B,CAAA;AAED,2EAA2E;AAC3E,eAAO,MAAM,WAAW,EAAE,IAmBzB,CAAA;AAED,wEAAwE;AACxE,eAAO,MAAM,aAAa,EAAE,IAe3B,CAAA;AAED,uEAAuE;AACvE,eAAO,MAAM,YAAY,EAAE,IAmB1B,CAAA;AAED,uGAAuG;AACvG,eAAO,MAAM,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAQtC,CAAA;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,aAAa,GAAI,aAAa,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,KAAG,IAIjE,CAAA"}
|
package/dist/plans.js
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { t } from '@molecule/api-i18n';
|
|
2
|
+
const defaultPlan = {
|
|
3
|
+
planKey: '',
|
|
4
|
+
platformKey: '',
|
|
5
|
+
platformProductId: '',
|
|
6
|
+
alias: '',
|
|
7
|
+
period: '',
|
|
8
|
+
price: '',
|
|
9
|
+
title: t('payment.plan.free.title', undefined, { defaultValue: 'Free' }),
|
|
10
|
+
titleKey: 'payment.plan.free.title',
|
|
11
|
+
description: t('payment.plan.free.description', undefined, {
|
|
12
|
+
defaultValue: 'Free plan with limited features',
|
|
13
|
+
}),
|
|
14
|
+
descriptionKey: 'payment.plan.free.description',
|
|
15
|
+
shortDescription: t('payment.plan.free.shortDescription', undefined, { defaultValue: 'Free' }),
|
|
16
|
+
shortDescriptionKey: 'payment.plan.free.shortDescription',
|
|
17
|
+
capabilities: {
|
|
18
|
+
premium: false,
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
/** Stripe monthly subscription plan ($5/month, auto-renews). */
|
|
22
|
+
export const stripeMonthly = {
|
|
23
|
+
planKey: 'stripeMonthly',
|
|
24
|
+
platformKey: 'stripe',
|
|
25
|
+
platformProductId: process.env.NODE_ENV === 'production' ? 'price_prod_id' : 'price_test_id',
|
|
26
|
+
alias: 'monthly',
|
|
27
|
+
period: 'month',
|
|
28
|
+
price: '$5',
|
|
29
|
+
autoRenews: true,
|
|
30
|
+
title: t('payment.plan.monthly.title', undefined, { defaultValue: 'Monthly' }),
|
|
31
|
+
titleKey: 'payment.plan.monthly.title',
|
|
32
|
+
description: t('payment.plan.premium.description', undefined, {
|
|
33
|
+
defaultValue: 'Full access to premium features',
|
|
34
|
+
}),
|
|
35
|
+
descriptionKey: 'payment.plan.premium.description',
|
|
36
|
+
capabilities: { premium: true },
|
|
37
|
+
};
|
|
38
|
+
/** Stripe yearly subscription plan ($55/year, auto-renews). */
|
|
39
|
+
export const stripeYearly = {
|
|
40
|
+
planKey: 'stripeYearly',
|
|
41
|
+
platformKey: 'stripe',
|
|
42
|
+
platformProductId: process.env.NODE_ENV === 'production' ? 'price_prod_id' : 'price_test_id',
|
|
43
|
+
alias: 'yearly',
|
|
44
|
+
period: 'year',
|
|
45
|
+
price: '$55',
|
|
46
|
+
autoRenews: true,
|
|
47
|
+
title: t('payment.plan.yearly.title', undefined, { defaultValue: 'Yearly' }),
|
|
48
|
+
titleKey: 'payment.plan.yearly.title',
|
|
49
|
+
description: t('payment.plan.premium.description', undefined, {
|
|
50
|
+
defaultValue: 'Full access to premium features',
|
|
51
|
+
}),
|
|
52
|
+
descriptionKey: 'payment.plan.premium.description',
|
|
53
|
+
highlightedDescription: t('payment.plan.yearly.highlightedDescription', undefined, {
|
|
54
|
+
defaultValue: 'Save with annual billing',
|
|
55
|
+
}),
|
|
56
|
+
highlightedDescriptionKey: 'payment.plan.yearly.highlightedDescription',
|
|
57
|
+
capabilities: { premium: true },
|
|
58
|
+
};
|
|
59
|
+
/** Apple App Store monthly subscription plan ($5.99/month, auto-renews). */
|
|
60
|
+
export const appleMonthly = {
|
|
61
|
+
planKey: 'appleMonthly',
|
|
62
|
+
platformKey: 'apple',
|
|
63
|
+
platformProductId: 'molecule_monthly_early_adopter',
|
|
64
|
+
alias: 'monthly',
|
|
65
|
+
period: 'month',
|
|
66
|
+
price: '$5.99',
|
|
67
|
+
autoRenews: true,
|
|
68
|
+
title: t('payment.plan.monthly.title', undefined, { defaultValue: 'Monthly' }),
|
|
69
|
+
titleKey: 'payment.plan.monthly.title',
|
|
70
|
+
description: t('payment.plan.premium.description', undefined, {
|
|
71
|
+
defaultValue: 'Full access to premium features',
|
|
72
|
+
}),
|
|
73
|
+
descriptionKey: 'payment.plan.premium.description',
|
|
74
|
+
capabilities: { premium: true },
|
|
75
|
+
};
|
|
76
|
+
/** Apple App Store yearly subscription plan ($64.99/year, auto-renews). */
|
|
77
|
+
export const appleYearly = {
|
|
78
|
+
planKey: 'appleYearly',
|
|
79
|
+
platformKey: 'apple',
|
|
80
|
+
platformProductId: 'molecule_yearly_early_adopter',
|
|
81
|
+
alias: 'yearly',
|
|
82
|
+
period: 'year',
|
|
83
|
+
price: '$64.99',
|
|
84
|
+
autoRenews: true,
|
|
85
|
+
title: t('payment.plan.yearly.title', undefined, { defaultValue: 'Yearly' }),
|
|
86
|
+
titleKey: 'payment.plan.yearly.title',
|
|
87
|
+
description: t('payment.plan.premium.description', undefined, {
|
|
88
|
+
defaultValue: 'Full access to premium features',
|
|
89
|
+
}),
|
|
90
|
+
descriptionKey: 'payment.plan.premium.description',
|
|
91
|
+
highlightedDescription: t('payment.plan.yearly.highlightedDescription', undefined, {
|
|
92
|
+
defaultValue: 'Save with annual billing',
|
|
93
|
+
}),
|
|
94
|
+
highlightedDescriptionKey: 'payment.plan.yearly.highlightedDescription',
|
|
95
|
+
capabilities: { premium: true },
|
|
96
|
+
};
|
|
97
|
+
/** Google Play monthly subscription plan ($5.99/month, auto-renews). */
|
|
98
|
+
export const googleMonthly = {
|
|
99
|
+
planKey: 'googleMonthly',
|
|
100
|
+
platformKey: 'google',
|
|
101
|
+
platformProductId: 'monthly_early_adopter',
|
|
102
|
+
alias: 'monthly',
|
|
103
|
+
period: 'month',
|
|
104
|
+
price: '$5.99',
|
|
105
|
+
autoRenews: true,
|
|
106
|
+
title: t('payment.plan.monthly.title', undefined, { defaultValue: 'Monthly' }),
|
|
107
|
+
titleKey: 'payment.plan.monthly.title',
|
|
108
|
+
description: t('payment.plan.premium.description', undefined, {
|
|
109
|
+
defaultValue: 'Full access to premium features',
|
|
110
|
+
}),
|
|
111
|
+
descriptionKey: 'payment.plan.premium.description',
|
|
112
|
+
capabilities: { premium: true },
|
|
113
|
+
};
|
|
114
|
+
/** Google Play yearly subscription plan ($64.99/year, auto-renews). */
|
|
115
|
+
export const googleYearly = {
|
|
116
|
+
planKey: 'googleYearly',
|
|
117
|
+
platformKey: 'google',
|
|
118
|
+
platformProductId: 'yearly_early_adopter',
|
|
119
|
+
alias: 'yearly',
|
|
120
|
+
period: 'year',
|
|
121
|
+
price: '$64.99',
|
|
122
|
+
autoRenews: true,
|
|
123
|
+
title: t('payment.plan.yearly.title', undefined, { defaultValue: 'Yearly' }),
|
|
124
|
+
titleKey: 'payment.plan.yearly.title',
|
|
125
|
+
description: t('payment.plan.premium.description', undefined, {
|
|
126
|
+
defaultValue: 'Full access to premium features',
|
|
127
|
+
}),
|
|
128
|
+
descriptionKey: 'payment.plan.premium.description',
|
|
129
|
+
highlightedDescription: t('payment.plan.yearly.highlightedDescription', undefined, {
|
|
130
|
+
defaultValue: 'Save with annual billing',
|
|
131
|
+
}),
|
|
132
|
+
highlightedDescriptionKey: 'payment.plan.yearly.highlightedDescription',
|
|
133
|
+
capabilities: { premium: true },
|
|
134
|
+
};
|
|
135
|
+
/** All available plans indexed by planKey. The empty string key `''` maps to the default free plan. */
|
|
136
|
+
export const plans = {
|
|
137
|
+
'': defaultPlan,
|
|
138
|
+
stripeMonthly,
|
|
139
|
+
stripeYearly,
|
|
140
|
+
appleMonthly,
|
|
141
|
+
appleYearly,
|
|
142
|
+
googleMonthly,
|
|
143
|
+
googleYearly,
|
|
144
|
+
};
|
|
145
|
+
/**
|
|
146
|
+
* Registers (or replaces) plans in the shared registry consumed by
|
|
147
|
+
* `planService` — keyed by `planKey`, merged into the defaults above.
|
|
148
|
+
*
|
|
149
|
+
* The built-in entries carry PLACEHOLDER platform product ids
|
|
150
|
+
* (`price_test_id` / `price_prod_id`), so `findPlanByProductId` can never
|
|
151
|
+
* match a real platform identifier until the app registers its own catalogue
|
|
152
|
+
* — typically derived from its pricing tiers with the real Stripe price ids
|
|
153
|
+
* from env (`@molecule/api-bonds-default-express`'s `createBillingRouter`
|
|
154
|
+
* does this automatically). Without registration, payment verification and
|
|
155
|
+
* webhook plan grants fail with "unknown plan" even though the charge
|
|
156
|
+
* succeeded.
|
|
157
|
+
*
|
|
158
|
+
* Idempotent: re-registering the same `planKey` overwrites that entry.
|
|
159
|
+
*
|
|
160
|
+
* @param customPlans - Plans to merge into the registry, keyed by `planKey`.
|
|
161
|
+
*/
|
|
162
|
+
export const registerPlans = (customPlans) => {
|
|
163
|
+
for (const [planKey, plan] of Object.entries(customPlans)) {
|
|
164
|
+
plans[planKey] = plan;
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
//# sourceMappingURL=plans.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plans.js","sourceRoot":"","sources":["../src/plans.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,oBAAoB,CAAA;AAItC,MAAM,WAAW,GAAS;IACxB,OAAO,EAAE,EAAE;IACX,WAAW,EAAE,EAAE;I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ACzC,KAAK,EAAE,QAAQ;IACf,MAAM,EAAE,MAAM;IACd,KAAK,EAAE,QAAQ;IACf,UAAU,EAAE,IAAI;IAChB,KAAK,EAAE,CAAC,CAAC,2BAA2B,EAAE,SAAS,EAAE,EAAE,YAAY,EAAE,QAAQ,EAAE,CAAC;IAC5E,QAAQ,EAAE,2BAA2B;IACrC,WAAW,EAAE,CAAC,CAAC,kCAAkC,EAAE,SAAS,EAAE;QAC5D,YAAY,EAAE,iCAAiC;KAChD,CAAC;IACF,cAAc,EAAE,kCAAkC;IAClD,sBAAsB,EAAE,CAAC,CAAC,4CAA4C,EAAE,SAAS,EAAE;QACjF,YAAY,EAAE,0BAA0B;KACzC,CAAC;IACF,yBAAyB,EAAE,4CAA4C;IACvE,YAAY,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE;CAChC,CAAA;AAED,uGAAuG;AACvG,MAAM,CAAC,MAAM,KAAK,GAAyB;IACzC,EAAE,EAAE,WAAW;IACf,aAAa;IACb,YAAY;IACZ,YAAY;IACZ,WAAW;IACX,aAAa;IACb,YAAY;CACb,CAAA;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,WAAiC,EAAQ,EAAE;IACvE,KAAK,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,CAAC;QAC1D,KAAK,CAAC,OAAO,CAAC,GAAG,IAAI,CAAA;IACvB,CAAC;AACH,CAAC,CAAA"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { PaymentRecordService } from '@molecule/api-payments';
|
|
2
|
+
/**
|
|
3
|
+
* Error thrown by {@link paymentRecordService.store} when inserting a payment
|
|
4
|
+
* record violates the `UNIQUE(platformKey, transactionId)` constraint — i.e. the
|
|
5
|
+
* transaction is already bound to an account.
|
|
6
|
+
*
|
|
7
|
+
* This is surfaced (not swallowed) so callers such as the user resource's
|
|
8
|
+
* `verifyPayment` handler can enforce first-claim-wins ownership and reject a
|
|
9
|
+
* replayed receipt instead of silently granting the plan to a second account.
|
|
10
|
+
*/
|
|
11
|
+
export declare class PaymentRecordConflictError extends Error {
|
|
12
|
+
/** The platform key (e.g. `'apple'`, `'google'`, `'stripe'`). */
|
|
13
|
+
readonly platformKey: string;
|
|
14
|
+
/** The transaction id that is already bound. */
|
|
15
|
+
readonly transactionId: string;
|
|
16
|
+
/**
|
|
17
|
+
* Builds the conflict error, naming the platform + transaction already bound
|
|
18
|
+
* so the caller can report which record it collided with.
|
|
19
|
+
*
|
|
20
|
+
* @param platformKey - The platform key of the conflicting record.
|
|
21
|
+
* @param transactionId - The transaction id that is already bound.
|
|
22
|
+
* @param options - Standard error options (e.g. `{ cause }`).
|
|
23
|
+
*/
|
|
24
|
+
constructor(platformKey: string, transactionId: string, options?: ErrorOptions);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* PaymentRecordService implementation for the bond system.
|
|
28
|
+
*
|
|
29
|
+
* Provides payment record CRUD operations that other resources
|
|
30
|
+
* can use through `get<PaymentRecordService>('paymentRecords')`.
|
|
31
|
+
*/
|
|
32
|
+
export declare const paymentRecordService: PaymentRecordService;
|
|
33
|
+
//# sourceMappingURL=recordService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recordService.d.ts","sourceRoot":"","sources":["../src/recordService.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AAMlE;;;;;;;;GAQG;AACH,qBAAa,0BAA2B,SAAQ,KAAK;IACnD,iEAAiE;IACjE,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;IAC5B,gDAAgD;IAChD,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAA;IAE9B;;;;;;;OAOG;gBACS,WAAW,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;CAM/E;AAmBD;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,EAAE,oBAwGlC,CAAA"}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { getAnalytics, getLogger } from '@molecule/api-bond';
|
|
2
|
+
import { create, deleteMany, findMany, findOne, query } from '@molecule/api-database';
|
|
3
|
+
const analytics = getAnalytics();
|
|
4
|
+
const logger = getLogger();
|
|
5
|
+
import { resource } from './resource.js';
|
|
6
|
+
const { tableName } = resource;
|
|
7
|
+
/**
|
|
8
|
+
* Error thrown by {@link paymentRecordService.store} when inserting a payment
|
|
9
|
+
* record violates the `UNIQUE(platformKey, transactionId)` constraint — i.e. the
|
|
10
|
+
* transaction is already bound to an account.
|
|
11
|
+
*
|
|
12
|
+
* This is surfaced (not swallowed) so callers such as the user resource's
|
|
13
|
+
* `verifyPayment` handler can enforce first-claim-wins ownership and reject a
|
|
14
|
+
* replayed receipt instead of silently granting the plan to a second account.
|
|
15
|
+
*/
|
|
16
|
+
export class PaymentRecordConflictError extends Error {
|
|
17
|
+
/** The platform key (e.g. `'apple'`, `'google'`, `'stripe'`). */
|
|
18
|
+
platformKey;
|
|
19
|
+
/** The transaction id that is already bound. */
|
|
20
|
+
transactionId;
|
|
21
|
+
/**
|
|
22
|
+
* Builds the conflict error, naming the platform + transaction already bound
|
|
23
|
+
* so the caller can report which record it collided with.
|
|
24
|
+
*
|
|
25
|
+
* @param platformKey - The platform key of the conflicting record.
|
|
26
|
+
* @param transactionId - The transaction id that is already bound.
|
|
27
|
+
* @param options - Standard error options (e.g. `{ cause }`).
|
|
28
|
+
*/
|
|
29
|
+
constructor(platformKey, transactionId, options) {
|
|
30
|
+
super(`Payment record already exists for ${platformKey} transaction ${transactionId}`, options);
|
|
31
|
+
this.name = 'PaymentRecordConflictError';
|
|
32
|
+
this.platformKey = platformKey;
|
|
33
|
+
this.transactionId = transactionId;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Detects whether a caught error is a database unique-constraint / duplicate-key
|
|
38
|
+
* violation, across the supported DataStore backends (Postgres `23505`, MySQL
|
|
39
|
+
* `ER_DUP_ENTRY`/1062, SQLite `SQLITE_CONSTRAINT`), with a message fallback.
|
|
40
|
+
* @param error - The caught error.
|
|
41
|
+
* @returns `true` if the error represents a unique/duplicate-key conflict.
|
|
42
|
+
*/
|
|
43
|
+
const isUniqueConstraintViolation = (error) => {
|
|
44
|
+
const e = error;
|
|
45
|
+
if (!e)
|
|
46
|
+
return false;
|
|
47
|
+
if (e.code === '23505' || e.code === 'ER_DUP_ENTRY' || e.code === 'SQLITE_CONSTRAINT')
|
|
48
|
+
return true;
|
|
49
|
+
if (typeof e.code === 'string' && e.code.startsWith('SQLITE_CONSTRAINT'))
|
|
50
|
+
return true;
|
|
51
|
+
if (e.errno === 1062)
|
|
52
|
+
return true;
|
|
53
|
+
return typeof e.message === 'string' && /duplicate key|unique constraint/i.test(e.message);
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* PaymentRecordService implementation for the bond system.
|
|
57
|
+
*
|
|
58
|
+
* Provides payment record CRUD operations that other resources
|
|
59
|
+
* can use through `get<PaymentRecordService>('paymentRecords')`.
|
|
60
|
+
*/
|
|
61
|
+
export const paymentRecordService = {
|
|
62
|
+
async store(record) {
|
|
63
|
+
try {
|
|
64
|
+
// Use DataStore create with try/catch for duplicate handling.
|
|
65
|
+
// The DataStore implementation handles conflicts per-database.
|
|
66
|
+
await create(tableName, {
|
|
67
|
+
userId: record.userId,
|
|
68
|
+
platformKey: record.platformKey,
|
|
69
|
+
transactionId: record.transactionId,
|
|
70
|
+
productId: record.productId,
|
|
71
|
+
data: JSON.stringify(record.data || {}),
|
|
72
|
+
receipt: record.receipt ?? null,
|
|
73
|
+
});
|
|
74
|
+
analytics
|
|
75
|
+
.track({
|
|
76
|
+
name: 'payment.record_stored',
|
|
77
|
+
userId: record.userId,
|
|
78
|
+
properties: { platformKey: record.platformKey, productId: record.productId },
|
|
79
|
+
})
|
|
80
|
+
.catch(() => { });
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
// A UNIQUE(platformKey, transactionId) violation means this transaction is
|
|
84
|
+
// already bound to an account. Surface it (do NOT swallow) so callers can
|
|
85
|
+
// enforce first-claim-wins ownership and reject a replayed receipt instead
|
|
86
|
+
// of silently granting the plan to a second account (R2-1).
|
|
87
|
+
if (isUniqueConstraintViolation(error)) {
|
|
88
|
+
analytics
|
|
89
|
+
.track({
|
|
90
|
+
name: 'payment.record_store_conflict',
|
|
91
|
+
userId: record.userId,
|
|
92
|
+
properties: { platformKey: record.platformKey, productId: record.productId },
|
|
93
|
+
})
|
|
94
|
+
.catch(() => { });
|
|
95
|
+
throw new PaymentRecordConflictError(record.platformKey, record.transactionId, {
|
|
96
|
+
cause: error,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
// Non-conflict failure (e.g. connection error): log and swallow as before —
|
|
100
|
+
// a transient storage failure must not block an otherwise-verified grant.
|
|
101
|
+
logger.error('Failed to store payment record:', error);
|
|
102
|
+
analytics
|
|
103
|
+
.track({
|
|
104
|
+
name: 'payment.record_store_failed',
|
|
105
|
+
userId: record.userId,
|
|
106
|
+
properties: { platformKey: record.platformKey, productId: record.productId },
|
|
107
|
+
})
|
|
108
|
+
.catch(() => { });
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
async findByTransaction(platformKey, transactionId) {
|
|
112
|
+
try {
|
|
113
|
+
return await findOne(tableName, [
|
|
114
|
+
{ field: 'transactionId', operator: '=', value: transactionId },
|
|
115
|
+
{ field: 'platformKey', operator: '=', value: platformKey },
|
|
116
|
+
]);
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
logger.error('Failed to find payment by transaction:', error);
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
async findByCustomerData(platformKey, key, value) {
|
|
124
|
+
try {
|
|
125
|
+
// Uses JSONB operator (->>) — not expressible via DataStore, requires raw query.
|
|
126
|
+
// This is intentionally database-specific per DataStore docs:
|
|
127
|
+
// "For complex queries not covered by this interface, use the raw DatabasePool.query() method instead."
|
|
128
|
+
const result = await query(`SELECT "userId" FROM "${tableName}" WHERE "platformKey" = $1 AND "data"->>$2 = $3 LIMIT 1`, [platformKey, key, value]);
|
|
129
|
+
return result?.rows?.[0] ?? null;
|
|
130
|
+
}
|
|
131
|
+
catch (error) {
|
|
132
|
+
logger.error('Failed to find payment by customer data:', error);
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
async findByUserId(userId, platformKey) {
|
|
137
|
+
try {
|
|
138
|
+
const results = await findMany(tableName, {
|
|
139
|
+
where: [
|
|
140
|
+
{ field: 'userId', operator: '=', value: userId },
|
|
141
|
+
{ field: 'platformKey', operator: '=', value: platformKey },
|
|
142
|
+
],
|
|
143
|
+
orderBy: [{ field: 'updatedAt', direction: 'desc' }],
|
|
144
|
+
limit: 1,
|
|
145
|
+
});
|
|
146
|
+
return results[0] ?? null;
|
|
147
|
+
}
|
|
148
|
+
catch (error) {
|
|
149
|
+
logger.error('Failed to find payment by userId:', error);
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
},
|
|
153
|
+
async deleteByUserId(userId) {
|
|
154
|
+
try {
|
|
155
|
+
await deleteMany(tableName, [{ field: 'userId', operator: '=', value: userId }]);
|
|
156
|
+
}
|
|
157
|
+
catch (error) {
|
|
158
|
+
logger.error('Failed to delete payment records:', error);
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
};
|
|
162
|
+
//# sourceMappingURL=recordService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recordService.js","sourceRoot":"","sources":["../src/recordService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC5D,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,EA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,KAAK,KAAK,KAAK,MAAM,YAAY,CAAA;AAExC,mEAAmE;AACnE,eAAO,MAAM,QAAQ,EAAE,KAAK,CAAC,QAmB5B,CAAA"}
|
package/dist/resource.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** Payment resource definition with JSON schema for validation. */
|
|
2
|
+
export const resource = {
|
|
3
|
+
name: 'Payment',
|
|
4
|
+
tableName: 'payments',
|
|
5
|
+
schema: {
|
|
6
|
+
type: 'object',
|
|
7
|
+
additionalProperties: false,
|
|
8
|
+
properties: {
|
|
9
|
+
id: { type: 'string' },
|
|
10
|
+
createdAt: { type: 'string' },
|
|
11
|
+
updatedAt: { type: 'string' },
|
|
12
|
+
userId: { type: 'string' },
|
|
13
|
+
platformKey: { type: 'string' },
|
|
14
|
+
transactionId: { type: 'string', nullable: true },
|
|
15
|
+
productId: { type: 'string' },
|
|
16
|
+
data: { type: 'object', nullable: true },
|
|
17
|
+
receipt: { type: 'string', nullable: true },
|
|
18
|
+
},
|
|
19
|
+
required: ['userId', 'platformKey', 'productId'],
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=resource.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resource.js","sourceRoot":"","sources":["../src/resource.ts"],"names":[],"mappings":"AAEA,mEAAmE;AACnE,MAAM,CAAC,MAAM,QAAQ,GAAmB;IACtC,IAAI,EAAE,SAAS;IACf,SAAS,EAAE,UAAU;IACrB,MAAM,EAAE;QACN,IAAI,EAAE,QAAQ;QACd,oBAAoB,EAAE,KAAK;QAC3B,UAAU,EAAE;YACV,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;YACtB,SAAS,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;YAC7B,SAAS,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;YAC7B,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;YAC1B,WAAW,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;YAC/B,aAAa,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE;YACjD,SAAS,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;YAC7B,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE;YACxC,OAAO,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE;SAC5C;QACD,QAAQ,EAAE,CAAC,QAAQ,EAAE,aAAa,EAAE,WAAW,CAAC;KACjD;CACF,CAAA"}
|
package/dist/schema.d.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Validation schema for props.
|
|
4
|
+
*/
|
|
5
|
+
export declare const propsSchema: z.ZodObject<{
|
|
6
|
+
id: z.ZodString;
|
|
7
|
+
createdAt: z.ZodString;
|
|
8
|
+
updatedAt: z.ZodString;
|
|
9
|
+
userId: z.ZodString;
|
|
10
|
+
platformKey: z.ZodDefault<z.ZodEnum<{
|
|
11
|
+
"": "";
|
|
12
|
+
stripe: "stripe";
|
|
13
|
+
apple: "apple";
|
|
14
|
+
google: "google";
|
|
15
|
+
}>>;
|
|
16
|
+
transactionId: z.ZodOptional<z.ZodString>;
|
|
17
|
+
productId: z.ZodString;
|
|
18
|
+
data: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
19
|
+
receipt: z.ZodOptional<z.ZodString>;
|
|
20
|
+
}, z.core.$strip>;
|
|
21
|
+
/**
|
|
22
|
+
* Full payment record properties (userId, platform, transactionId, productId, data, receipt).
|
|
23
|
+
*/
|
|
24
|
+
export type Props = z.infer<typeof propsSchema>;
|
|
25
|
+
/**
|
|
26
|
+
* Zod schema for creating a payment record (picks fields required at creation time).
|
|
27
|
+
*/
|
|
28
|
+
export declare const createPropsSchema: z.ZodObject<{
|
|
29
|
+
createdAt: z.ZodString;
|
|
30
|
+
updatedAt: z.ZodString;
|
|
31
|
+
userId: z.ZodString;
|
|
32
|
+
platformKey: z.ZodDefault<z.ZodEnum<{
|
|
33
|
+
"": "";
|
|
34
|
+
stripe: "stripe";
|
|
35
|
+
apple: "apple";
|
|
36
|
+
google: "google";
|
|
37
|
+
}>>;
|
|
38
|
+
transactionId: z.ZodOptional<z.ZodString>;
|
|
39
|
+
productId: z.ZodString;
|
|
40
|
+
data: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
41
|
+
receipt: z.ZodOptional<z.ZodString>;
|
|
42
|
+
}, z.core.$strip>;
|
|
43
|
+
/**
|
|
44
|
+
* Fields required when creating a new payment record.
|
|
45
|
+
*/
|
|
46
|
+
export type CreateProps = z.infer<typeof createPropsSchema>;
|
|
47
|
+
/**
|
|
48
|
+
* Zod schema for updating a payment record (data and receipt only).
|
|
49
|
+
*/
|
|
50
|
+
export declare const updatePropsSchema: z.ZodObject<{
|
|
51
|
+
data: z.ZodOptional<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
52
|
+
receipt: z.ZodOptional<z.ZodOptional<z.ZodString>>;
|
|
53
|
+
}, z.core.$strip>;
|
|
54
|
+
/**
|
|
55
|
+
* Updatable payment record fields (data and receipt).
|
|
56
|
+
*/
|
|
57
|
+
export type UpdateProps = z.infer<typeof updatePropsSchema>;
|
|
58
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB;;GAEG;AACH,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;iBAUtB,CAAA;AAEF;;GAEG;AACH,MAAM,MAAM,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,CAAA;AAE/C;;GAEG;AACH,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;iBAS5B,CAAA;AAEF;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAA;AAE3D;;GAEG;AACH,eAAO,MAAM,iBAAiB;;;iBAKlB,CAAA;AAEZ;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAA"}
|
package/dist/schema.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Validation schema for props.
|
|
4
|
+
*/
|
|
5
|
+
export const propsSchema = z.object({
|
|
6
|
+
id: z.string().uuid(),
|
|
7
|
+
createdAt: z.string(),
|
|
8
|
+
updatedAt: z.string(),
|
|
9
|
+
userId: z.string().uuid(),
|
|
10
|
+
platformKey: z.enum(['', 'stripe', 'apple', 'google']).default(''),
|
|
11
|
+
transactionId: z.string().optional(),
|
|
12
|
+
productId: z.string(),
|
|
13
|
+
data: z.record(z.string(), z.unknown()).optional(),
|
|
14
|
+
receipt: z.string().optional(),
|
|
15
|
+
});
|
|
16
|
+
/**
|
|
17
|
+
* Zod schema for creating a payment record (picks fields required at creation time).
|
|
18
|
+
*/
|
|
19
|
+
export const createPropsSchema = propsSchema.pick({
|
|
20
|
+
createdAt: true,
|
|
21
|
+
updatedAt: true,
|
|
22
|
+
userId: true,
|
|
23
|
+
platformKey: true,
|
|
24
|
+
transactionId: true,
|
|
25
|
+
productId: true,
|
|
26
|
+
data: true,
|
|
27
|
+
receipt: true,
|
|
28
|
+
});
|
|
29
|
+
/**
|
|
30
|
+
* Zod schema for updating a payment record (data and receipt only).
|
|
31
|
+
*/
|
|
32
|
+
export const updatePropsSchema = propsSchema
|
|
33
|
+
.pick({
|
|
34
|
+
data: true,
|
|
35
|
+
receipt: true,
|
|
36
|
+
})
|
|
37
|
+
.partial();
|
|
38
|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