paddle-checkout-accelerator 2.1.0 → 2.1.1

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 (80) hide show
  1. package/dist/index.cjs +1150 -0
  2. package/dist/index.d.cts +290 -0
  3. package/dist/index.d.ts +290 -0
  4. package/dist/index.js +1079 -0
  5. package/package.json +10 -7
  6. package/recipes/nextjs/app/billing.ts +1 -1
  7. package/dist/package/index.d.ts +0 -28
  8. package/dist/package/index.js +0 -28
  9. package/dist/src/components/paddle/BillingHistory.d.ts +0 -1
  10. package/dist/src/components/paddle/BillingHistory.js +0 -17
  11. package/dist/src/components/paddle/CustomerPortal.d.ts +0 -1
  12. package/dist/src/components/paddle/CustomerPortal.js +0 -5
  13. package/dist/src/components/paddle/CustomerPortalButton.d.ts +0 -1
  14. package/dist/src/components/paddle/CustomerPortalButton.js +0 -31
  15. package/dist/src/components/paddle/InlineCheckout.d.ts +0 -5
  16. package/dist/src/components/paddle/InlineCheckout.js +0 -13
  17. package/dist/src/components/paddle/PricingTable.d.ts +0 -1
  18. package/dist/src/components/paddle/PricingTable.js +0 -27
  19. package/dist/src/components/paddle/SubscriptionCard.d.ts +0 -6
  20. package/dist/src/components/paddle/SubscriptionCard.js +0 -5
  21. package/dist/src/components/paddle/TrialBanner.d.ts +0 -5
  22. package/dist/src/components/paddle/TrialBanner.js +0 -5
  23. package/dist/src/components/paddle/UpgradeModal.d.ts +0 -11
  24. package/dist/src/components/paddle/UpgradeModal.js +0 -35
  25. package/dist/src/components/paddle/UsageMeter.d.ts +0 -6
  26. package/dist/src/components/paddle/UsageMeter.js +0 -8
  27. package/dist/src/components/paddle/gates/SubscriptionGate.d.ts +0 -7
  28. package/dist/src/components/paddle/gates/SubscriptionGate.js +0 -8
  29. package/dist/src/lib/billing/adapters/index.d.ts +0 -3
  30. package/dist/src/lib/billing/adapters/index.js +0 -3
  31. package/dist/src/lib/billing/adapters/memory.d.ts +0 -2
  32. package/dist/src/lib/billing/adapters/memory.js +0 -41
  33. package/dist/src/lib/billing/adapters/prisma/index.d.ts +0 -28
  34. package/dist/src/lib/billing/adapters/prisma/index.js +0 -80
  35. package/dist/src/lib/billing/adapters/types.d.ts +0 -13
  36. package/dist/src/lib/billing/adapters/types.js +0 -1
  37. package/dist/src/lib/billing/configure.d.ts +0 -6
  38. package/dist/src/lib/billing/configure.js +0 -13
  39. package/dist/src/lib/billing/customer-repair.d.ts +0 -4
  40. package/dist/src/lib/billing/customer-repair.js +0 -19
  41. package/dist/src/lib/billing/demo-seed.d.ts +0 -1
  42. package/dist/src/lib/billing/demo-seed.js +0 -13
  43. package/dist/src/lib/billing/entitlements.d.ts +0 -3
  44. package/dist/src/lib/billing/entitlements.js +0 -16
  45. package/dist/src/lib/billing/events.d.ts +0 -12
  46. package/dist/src/lib/billing/events.js +0 -20
  47. package/dist/src/lib/billing/plans.d.ts +0 -9
  48. package/dist/src/lib/billing/plans.js +0 -41
  49. package/dist/src/lib/billing/protection.d.ts +0 -6
  50. package/dist/src/lib/billing/protection.js +0 -16
  51. package/dist/src/lib/billing/refresh.d.ts +0 -1
  52. package/dist/src/lib/billing/refresh.js +0 -32
  53. package/dist/src/lib/billing/subscriptions.d.ts +0 -16
  54. package/dist/src/lib/billing/subscriptions.js +0 -36
  55. package/dist/src/lib/billing/teams.d.ts +0 -42
  56. package/dist/src/lib/billing/teams.js +0 -104
  57. package/dist/src/lib/billing/usage.d.ts +0 -17
  58. package/dist/src/lib/billing/usage.js +0 -40
  59. package/dist/src/lib/billing/webhook-sync.d.ts +0 -26
  60. package/dist/src/lib/billing/webhook-sync.js +0 -39
  61. package/dist/src/lib/paddle/api.d.ts +0 -1
  62. package/dist/src/lib/paddle/api.js +0 -21
  63. package/dist/src/lib/paddle/client.d.ts +0 -1
  64. package/dist/src/lib/paddle/client.js +0 -13
  65. package/dist/src/lib/paddle/customers.d.ts +0 -15
  66. package/dist/src/lib/paddle/customers.js +0 -14
  67. package/dist/src/lib/paddle/events.d.ts +0 -10
  68. package/dist/src/lib/paddle/events.js +0 -11
  69. package/dist/src/lib/paddle/hooks.d.ts +0 -4
  70. package/dist/src/lib/paddle/hooks.js +0 -11
  71. package/dist/src/lib/paddle/portal.d.ts +0 -8
  72. package/dist/src/lib/paddle/portal.js +0 -28
  73. package/dist/src/lib/paddle/subscriptions.d.ts +0 -20
  74. package/dist/src/lib/paddle/subscriptions.js +0 -10
  75. package/dist/src/lib/paddle/types.d.ts +0 -8
  76. package/dist/src/lib/paddle/types.js +0 -1
  77. package/dist/src/lib/paddle/webhook.d.ts +0 -1
  78. package/dist/src/lib/paddle/webhook.js +0 -8
  79. package/dist/src/lib/utils.d.ts +0 -2
  80. package/dist/src/lib/utils.js +0 -5
@@ -0,0 +1,290 @@
1
+ import * as react from 'react';
2
+ import * as _paddle_paddle_js from '@paddle/paddle-js';
3
+
4
+ interface UpgradeModalProps {
5
+ open: boolean;
6
+ onClose: () => void;
7
+ currentPlan: string;
8
+ targetPlan: string;
9
+ targetPriceId: string;
10
+ yearlySavings?: string;
11
+ onUpgradeSuccess?: (data: unknown) => void;
12
+ }
13
+ declare function UpgradeModal({ open, onClose, currentPlan, targetPlan, targetPriceId, yearlySavings, onUpgradeSuccess, }: UpgradeModalProps): react.JSX.Element | null;
14
+
15
+ interface UsageMeterProps {
16
+ current: number;
17
+ limit: number;
18
+ }
19
+ declare function UsageMeter({ current, limit, }: UsageMeterProps): react.JSX.Element;
20
+
21
+ interface TrialBannerProps {
22
+ daysRemaining: number;
23
+ }
24
+ declare function TrialBanner({ daysRemaining, }: TrialBannerProps): react.JSX.Element;
25
+
26
+ declare function BillingHistory(): react.JSX.Element;
27
+
28
+ declare function CustomerPortalButton(): react.JSX.Element;
29
+
30
+ interface SubscriptionCardProps {
31
+ plan: string;
32
+ status: string;
33
+ }
34
+ declare function SubscriptionCard({ plan, status, }: SubscriptionCardProps): react.JSX.Element;
35
+
36
+ interface SubscriptionGateProps {
37
+ active: boolean;
38
+ children: React.ReactNode;
39
+ fallback?: React.ReactNode;
40
+ }
41
+ declare function SubscriptionGate({ active, children, fallback, }: SubscriptionGateProps): string | number | bigint | boolean | react.JSX.Element | Iterable<react.ReactNode> | Promise<string | number | bigint | boolean | react.ReactPortal | react.ReactElement<unknown, string | react.JSXElementConstructor<any>> | Iterable<react.ReactNode> | null | undefined>;
42
+
43
+ declare function openCheckout(items: {
44
+ priceId: string;
45
+ quantity: number;
46
+ }[]): Promise<void>;
47
+
48
+ declare function getPaddle(): Promise<_paddle_paddle_js.Paddle | undefined>;
49
+
50
+ interface CheckoutItem {
51
+ priceId: string;
52
+ quantity: number;
53
+ }
54
+ interface OpenCheckoutOptions {
55
+ items: CheckoutItem[];
56
+ customerEmail?: string;
57
+ }
58
+
59
+ declare function verifyPaddleWebhook(rawBody: string, signature: string): Promise<unknown>;
60
+
61
+ type PlanId = "free" | "starter" | "pro" | "business";
62
+ type FeatureKey = "checkout" | "customer_portal" | "usage_limits" | "team_members" | "api_access" | "priority_support";
63
+ declare const plans: Record<PlanId, {
64
+ name: string;
65
+ monthlyLimit: number;
66
+ seatLimit: number;
67
+ features: FeatureKey[];
68
+ }>;
69
+ declare function getPlanSeatLimit(plan: PlanId): number;
70
+
71
+ type TeamRole = "owner" | "admin" | "member";
72
+ interface TeamMember {
73
+ userId: string;
74
+ email?: string;
75
+ role: TeamRole;
76
+ joinedAt: string;
77
+ }
78
+ interface TeamRecord {
79
+ teamId: string;
80
+ name: string;
81
+ plan: PlanId;
82
+ ownerId: string;
83
+ members: TeamMember[];
84
+ }
85
+ declare function setTeamAdapter(nextAdapter: BillingAdapter): void;
86
+ declare function createTeam({ teamId, name, ownerId, plan, }: {
87
+ teamId: string;
88
+ name: string;
89
+ ownerId: string;
90
+ plan?: PlanId;
91
+ }): Promise<TeamRecord>;
92
+ declare function getTeam(teamId: string): Promise<TeamRecord | null>;
93
+ declare function updateTeamPlan(teamId: string, plan: PlanId): Promise<TeamRecord>;
94
+ declare function getSeatUsage(teamId: string): Promise<{
95
+ used: number;
96
+ limit: number;
97
+ remaining: number;
98
+ allowed: boolean;
99
+ }>;
100
+ declare function canInviteTeamMember(teamId: string): Promise<boolean>;
101
+ declare function addTeamMember({ teamId, userId, email, role, }: {
102
+ teamId: string;
103
+ userId: string;
104
+ email?: string;
105
+ role?: TeamRole;
106
+ }): Promise<TeamRecord>;
107
+ declare function removeTeamMember({ teamId, userId, }: {
108
+ teamId: string;
109
+ userId: string;
110
+ }): Promise<TeamRecord>;
111
+
112
+ type BillingEventType = "subscription_created" | "payment_succeeded" | "payment_failed" | "subscription_updated" | "subscription_paused" | "subscription_canceled" | "portal_opened" | "repair_performed";
113
+ interface BillingEvent {
114
+ id: string;
115
+ userId: string;
116
+ type: BillingEventType;
117
+ createdAt: string;
118
+ metadata?: Record<string, unknown>;
119
+ }
120
+ declare function setBillingEventAdapter(nextAdapter: BillingAdapter): void;
121
+ declare function recordBillingEvent(event: BillingEvent): Promise<BillingEvent>;
122
+ declare function getBillingEvents(userId: string): Promise<BillingEvent[]>;
123
+
124
+ interface BillingAdapter {
125
+ getSubscription(userId: string): Promise<SubscriptionRecord | null>;
126
+ upsertSubscription(record: SubscriptionRecord): Promise<SubscriptionRecord>;
127
+ getUsage(userId: string, key: string, period: string): Promise<number>;
128
+ incrementUsage(userId: string, key: string, period: string, amount: number): Promise<number>;
129
+ getTeam?(teamId: string): Promise<TeamRecord | null>;
130
+ upsertTeam?(team: TeamRecord): Promise<TeamRecord>;
131
+ recordBillingEvent?(event: BillingEvent): Promise<BillingEvent>;
132
+ getBillingEvents?(userId: string): Promise<BillingEvent[]>;
133
+ }
134
+
135
+ declare const memoryBillingAdapter: BillingAdapter;
136
+
137
+ type PrismaLike = {
138
+ subscription: {
139
+ findUnique(args: unknown): Promise<SubscriptionRecord | null>;
140
+ upsert(args: unknown): Promise<SubscriptionRecord>;
141
+ };
142
+ usageEvent: {
143
+ findUnique(args: unknown): Promise<{
144
+ count: number;
145
+ } | null>;
146
+ upsert(args: unknown): Promise<{
147
+ count: number;
148
+ }>;
149
+ };
150
+ team: {
151
+ findUnique(args: unknown): Promise<TeamRecord | null>;
152
+ upsert(args: unknown): Promise<TeamRecord>;
153
+ };
154
+ billingEvent: {
155
+ create(args: unknown): Promise<BillingEvent>;
156
+ findMany(args: unknown): Promise<BillingEvent[]>;
157
+ };
158
+ };
159
+ declare function createPrismaBillingAdapter(prisma: PrismaLike): BillingAdapter;
160
+
161
+ type SubscriptionStatus = "active" | "trialing" | "past_due" | "paused" | "canceled" | "expired" | "none";
162
+ interface SubscriptionRecord {
163
+ userId: string;
164
+ plan: PlanId;
165
+ status: SubscriptionStatus;
166
+ paddleCustomerId?: string;
167
+ paddleSubscriptionId?: string;
168
+ currentPeriodEnd?: string;
169
+ }
170
+ declare function setBillingAdapter(nextAdapter: BillingAdapter): void;
171
+ declare function getSubscription(userId: string): Promise<SubscriptionRecord>;
172
+ declare function upsertSubscription(record: SubscriptionRecord): Promise<SubscriptionRecord>;
173
+ declare function isSubscriptionActive(subscription: SubscriptionRecord): boolean;
174
+ declare function requireSubscription(userId: string, minimumPlan?: PlanId): Promise<SubscriptionRecord>;
175
+
176
+ declare function hasFeature(userId: string, feature: FeatureKey): Promise<boolean>;
177
+ declare function requireFeature(userId: string, feature: FeatureKey): Promise<boolean>;
178
+
179
+ declare function setUsageAdapter(nextAdapter: BillingAdapter): void;
180
+ declare function getUsage(userId: string, key: string): Promise<number>;
181
+ declare function getUsageLimit(userId: string): Promise<number>;
182
+ declare function canUse(userId: string, key: string): Promise<{
183
+ allowed: boolean;
184
+ used: number;
185
+ limit: number;
186
+ remaining: number;
187
+ }>;
188
+ declare function incrementUsage(userId: string, key: string, amount?: number): Promise<number>;
189
+ declare function requireUsage(userId: string, key: string): Promise<{
190
+ allowed: boolean;
191
+ used: number;
192
+ limit: number;
193
+ remaining: number;
194
+ }>;
195
+
196
+ interface PaddleEvent {
197
+ event_type?: string;
198
+ data?: {
199
+ id?: string;
200
+ status?: string;
201
+ customer_id?: string;
202
+ custom_data?: {
203
+ userId?: string;
204
+ plan?: PlanId;
205
+ };
206
+ current_billing_period?: {
207
+ ends_at?: string;
208
+ };
209
+ };
210
+ }
211
+ declare function syncPaddleEvent(event: PaddleEvent): Promise<{
212
+ synced: boolean;
213
+ reason: string;
214
+ type?: undefined;
215
+ } | {
216
+ synced: boolean;
217
+ type: string;
218
+ reason?: undefined;
219
+ }>;
220
+
221
+ declare function protectPlan(userId: string, plan: PlanId): Promise<SubscriptionRecord>;
222
+ declare function protectFeature(userId: string, feature: FeatureKey): Promise<boolean>;
223
+ declare function protectUsage(userId: string, usageKey: string, amount?: number): Promise<{
224
+ allowed: boolean;
225
+ }>;
226
+
227
+ declare function seedDemoBilling(): Promise<void>;
228
+
229
+ interface CreatePortalSessionOptions {
230
+ customerId: string;
231
+ returnUrl?: string;
232
+ }
233
+ interface PortalSessionResult {
234
+ url: string;
235
+ }
236
+ declare function createCustomerPortalSession({ customerId, returnUrl, }: CreatePortalSessionOptions): Promise<PortalSessionResult>;
237
+
238
+ declare function paddleApi<T>(path: string, options?: RequestInit): Promise<T>;
239
+
240
+ interface PaddleSubscription {
241
+ id: string;
242
+ status: string;
243
+ customer_id?: string;
244
+ current_billing_period?: {
245
+ ends_at?: string;
246
+ };
247
+ custom_data?: {
248
+ userId?: string;
249
+ plan?: "free" | "starter" | "pro" | "business";
250
+ };
251
+ }
252
+ interface PaddleSubscriptionResponse {
253
+ data?: PaddleSubscription;
254
+ }
255
+ interface PaddleSubscriptionListResponse {
256
+ data?: PaddleSubscription[];
257
+ }
258
+ declare function fetchPaddleSubscription(subscriptionId: string): Promise<PaddleSubscriptionResponse>;
259
+ declare function fetchPaddleSubscriptionsForCustomer(customerId: string): Promise<PaddleSubscriptionListResponse>;
260
+
261
+ declare function refreshSubscriptionFromPaddle(subscriptionId: string): Promise<SubscriptionRecord>;
262
+
263
+ interface PaddleCustomer {
264
+ id: string;
265
+ email?: string;
266
+ name?: string;
267
+ status?: string;
268
+ }
269
+ interface PaddleCustomerListResponse {
270
+ data?: PaddleCustomer[];
271
+ }
272
+ interface PaddleCustomerResponse {
273
+ data?: PaddleCustomer;
274
+ }
275
+ declare function fetchPaddleCustomer(customerId: string): Promise<PaddleCustomerResponse>;
276
+ declare function findPaddleCustomersByEmail(email: string): Promise<PaddleCustomerListResponse>;
277
+ declare function findFirstPaddleCustomerByEmail(email: string): Promise<PaddleCustomer | null>;
278
+
279
+ declare function repairSubscriptionByEmail(email: string): Promise<{
280
+ customer: PaddleCustomer;
281
+ subscription: SubscriptionRecord;
282
+ }>;
283
+
284
+ declare function configureBilling({ adapter, }: {
285
+ adapter: BillingAdapter;
286
+ }): {
287
+ adapterConfigured: boolean;
288
+ };
289
+
290
+ export { type BillingAdapter, type BillingEvent, type BillingEventType, BillingHistory, type CheckoutItem, type CreatePortalSessionOptions, CustomerPortalButton, type FeatureKey, type OpenCheckoutOptions, type PaddleCustomer, type PaddleCustomerListResponse, type PaddleCustomerResponse, type PaddleSubscription, type PaddleSubscriptionListResponse, type PaddleSubscriptionResponse, type PlanId, type PortalSessionResult, SubscriptionCard, SubscriptionGate, type SubscriptionRecord, type SubscriptionStatus, type TeamMember, type TeamRecord, type TeamRole, TrialBanner, UpgradeModal, UsageMeter, addTeamMember, canInviteTeamMember, canUse, configureBilling, createCustomerPortalSession, createPrismaBillingAdapter, createTeam, fetchPaddleCustomer, fetchPaddleSubscription, fetchPaddleSubscriptionsForCustomer, findFirstPaddleCustomerByEmail, findPaddleCustomersByEmail, getBillingEvents, getPaddle, getPlanSeatLimit, getSeatUsage, getSubscription, getTeam, getUsage, getUsageLimit, hasFeature, incrementUsage, isSubscriptionActive, memoryBillingAdapter, openCheckout, paddleApi, plans, protectFeature, protectPlan, protectUsage, recordBillingEvent, refreshSubscriptionFromPaddle, removeTeamMember, repairSubscriptionByEmail, requireFeature, requireSubscription, requireUsage, seedDemoBilling, setBillingAdapter, setBillingEventAdapter, setTeamAdapter, setUsageAdapter, syncPaddleEvent, updateTeamPlan, upsertSubscription, verifyPaddleWebhook };
@@ -0,0 +1,290 @@
1
+ import * as react from 'react';
2
+ import * as _paddle_paddle_js from '@paddle/paddle-js';
3
+
4
+ interface UpgradeModalProps {
5
+ open: boolean;
6
+ onClose: () => void;
7
+ currentPlan: string;
8
+ targetPlan: string;
9
+ targetPriceId: string;
10
+ yearlySavings?: string;
11
+ onUpgradeSuccess?: (data: unknown) => void;
12
+ }
13
+ declare function UpgradeModal({ open, onClose, currentPlan, targetPlan, targetPriceId, yearlySavings, onUpgradeSuccess, }: UpgradeModalProps): react.JSX.Element | null;
14
+
15
+ interface UsageMeterProps {
16
+ current: number;
17
+ limit: number;
18
+ }
19
+ declare function UsageMeter({ current, limit, }: UsageMeterProps): react.JSX.Element;
20
+
21
+ interface TrialBannerProps {
22
+ daysRemaining: number;
23
+ }
24
+ declare function TrialBanner({ daysRemaining, }: TrialBannerProps): react.JSX.Element;
25
+
26
+ declare function BillingHistory(): react.JSX.Element;
27
+
28
+ declare function CustomerPortalButton(): react.JSX.Element;
29
+
30
+ interface SubscriptionCardProps {
31
+ plan: string;
32
+ status: string;
33
+ }
34
+ declare function SubscriptionCard({ plan, status, }: SubscriptionCardProps): react.JSX.Element;
35
+
36
+ interface SubscriptionGateProps {
37
+ active: boolean;
38
+ children: React.ReactNode;
39
+ fallback?: React.ReactNode;
40
+ }
41
+ declare function SubscriptionGate({ active, children, fallback, }: SubscriptionGateProps): string | number | bigint | boolean | react.JSX.Element | Iterable<react.ReactNode> | Promise<string | number | bigint | boolean | react.ReactPortal | react.ReactElement<unknown, string | react.JSXElementConstructor<any>> | Iterable<react.ReactNode> | null | undefined>;
42
+
43
+ declare function openCheckout(items: {
44
+ priceId: string;
45
+ quantity: number;
46
+ }[]): Promise<void>;
47
+
48
+ declare function getPaddle(): Promise<_paddle_paddle_js.Paddle | undefined>;
49
+
50
+ interface CheckoutItem {
51
+ priceId: string;
52
+ quantity: number;
53
+ }
54
+ interface OpenCheckoutOptions {
55
+ items: CheckoutItem[];
56
+ customerEmail?: string;
57
+ }
58
+
59
+ declare function verifyPaddleWebhook(rawBody: string, signature: string): Promise<unknown>;
60
+
61
+ type PlanId = "free" | "starter" | "pro" | "business";
62
+ type FeatureKey = "checkout" | "customer_portal" | "usage_limits" | "team_members" | "api_access" | "priority_support";
63
+ declare const plans: Record<PlanId, {
64
+ name: string;
65
+ monthlyLimit: number;
66
+ seatLimit: number;
67
+ features: FeatureKey[];
68
+ }>;
69
+ declare function getPlanSeatLimit(plan: PlanId): number;
70
+
71
+ type TeamRole = "owner" | "admin" | "member";
72
+ interface TeamMember {
73
+ userId: string;
74
+ email?: string;
75
+ role: TeamRole;
76
+ joinedAt: string;
77
+ }
78
+ interface TeamRecord {
79
+ teamId: string;
80
+ name: string;
81
+ plan: PlanId;
82
+ ownerId: string;
83
+ members: TeamMember[];
84
+ }
85
+ declare function setTeamAdapter(nextAdapter: BillingAdapter): void;
86
+ declare function createTeam({ teamId, name, ownerId, plan, }: {
87
+ teamId: string;
88
+ name: string;
89
+ ownerId: string;
90
+ plan?: PlanId;
91
+ }): Promise<TeamRecord>;
92
+ declare function getTeam(teamId: string): Promise<TeamRecord | null>;
93
+ declare function updateTeamPlan(teamId: string, plan: PlanId): Promise<TeamRecord>;
94
+ declare function getSeatUsage(teamId: string): Promise<{
95
+ used: number;
96
+ limit: number;
97
+ remaining: number;
98
+ allowed: boolean;
99
+ }>;
100
+ declare function canInviteTeamMember(teamId: string): Promise<boolean>;
101
+ declare function addTeamMember({ teamId, userId, email, role, }: {
102
+ teamId: string;
103
+ userId: string;
104
+ email?: string;
105
+ role?: TeamRole;
106
+ }): Promise<TeamRecord>;
107
+ declare function removeTeamMember({ teamId, userId, }: {
108
+ teamId: string;
109
+ userId: string;
110
+ }): Promise<TeamRecord>;
111
+
112
+ type BillingEventType = "subscription_created" | "payment_succeeded" | "payment_failed" | "subscription_updated" | "subscription_paused" | "subscription_canceled" | "portal_opened" | "repair_performed";
113
+ interface BillingEvent {
114
+ id: string;
115
+ userId: string;
116
+ type: BillingEventType;
117
+ createdAt: string;
118
+ metadata?: Record<string, unknown>;
119
+ }
120
+ declare function setBillingEventAdapter(nextAdapter: BillingAdapter): void;
121
+ declare function recordBillingEvent(event: BillingEvent): Promise<BillingEvent>;
122
+ declare function getBillingEvents(userId: string): Promise<BillingEvent[]>;
123
+
124
+ interface BillingAdapter {
125
+ getSubscription(userId: string): Promise<SubscriptionRecord | null>;
126
+ upsertSubscription(record: SubscriptionRecord): Promise<SubscriptionRecord>;
127
+ getUsage(userId: string, key: string, period: string): Promise<number>;
128
+ incrementUsage(userId: string, key: string, period: string, amount: number): Promise<number>;
129
+ getTeam?(teamId: string): Promise<TeamRecord | null>;
130
+ upsertTeam?(team: TeamRecord): Promise<TeamRecord>;
131
+ recordBillingEvent?(event: BillingEvent): Promise<BillingEvent>;
132
+ getBillingEvents?(userId: string): Promise<BillingEvent[]>;
133
+ }
134
+
135
+ declare const memoryBillingAdapter: BillingAdapter;
136
+
137
+ type PrismaLike = {
138
+ subscription: {
139
+ findUnique(args: unknown): Promise<SubscriptionRecord | null>;
140
+ upsert(args: unknown): Promise<SubscriptionRecord>;
141
+ };
142
+ usageEvent: {
143
+ findUnique(args: unknown): Promise<{
144
+ count: number;
145
+ } | null>;
146
+ upsert(args: unknown): Promise<{
147
+ count: number;
148
+ }>;
149
+ };
150
+ team: {
151
+ findUnique(args: unknown): Promise<TeamRecord | null>;
152
+ upsert(args: unknown): Promise<TeamRecord>;
153
+ };
154
+ billingEvent: {
155
+ create(args: unknown): Promise<BillingEvent>;
156
+ findMany(args: unknown): Promise<BillingEvent[]>;
157
+ };
158
+ };
159
+ declare function createPrismaBillingAdapter(prisma: PrismaLike): BillingAdapter;
160
+
161
+ type SubscriptionStatus = "active" | "trialing" | "past_due" | "paused" | "canceled" | "expired" | "none";
162
+ interface SubscriptionRecord {
163
+ userId: string;
164
+ plan: PlanId;
165
+ status: SubscriptionStatus;
166
+ paddleCustomerId?: string;
167
+ paddleSubscriptionId?: string;
168
+ currentPeriodEnd?: string;
169
+ }
170
+ declare function setBillingAdapter(nextAdapter: BillingAdapter): void;
171
+ declare function getSubscription(userId: string): Promise<SubscriptionRecord>;
172
+ declare function upsertSubscription(record: SubscriptionRecord): Promise<SubscriptionRecord>;
173
+ declare function isSubscriptionActive(subscription: SubscriptionRecord): boolean;
174
+ declare function requireSubscription(userId: string, minimumPlan?: PlanId): Promise<SubscriptionRecord>;
175
+
176
+ declare function hasFeature(userId: string, feature: FeatureKey): Promise<boolean>;
177
+ declare function requireFeature(userId: string, feature: FeatureKey): Promise<boolean>;
178
+
179
+ declare function setUsageAdapter(nextAdapter: BillingAdapter): void;
180
+ declare function getUsage(userId: string, key: string): Promise<number>;
181
+ declare function getUsageLimit(userId: string): Promise<number>;
182
+ declare function canUse(userId: string, key: string): Promise<{
183
+ allowed: boolean;
184
+ used: number;
185
+ limit: number;
186
+ remaining: number;
187
+ }>;
188
+ declare function incrementUsage(userId: string, key: string, amount?: number): Promise<number>;
189
+ declare function requireUsage(userId: string, key: string): Promise<{
190
+ allowed: boolean;
191
+ used: number;
192
+ limit: number;
193
+ remaining: number;
194
+ }>;
195
+
196
+ interface PaddleEvent {
197
+ event_type?: string;
198
+ data?: {
199
+ id?: string;
200
+ status?: string;
201
+ customer_id?: string;
202
+ custom_data?: {
203
+ userId?: string;
204
+ plan?: PlanId;
205
+ };
206
+ current_billing_period?: {
207
+ ends_at?: string;
208
+ };
209
+ };
210
+ }
211
+ declare function syncPaddleEvent(event: PaddleEvent): Promise<{
212
+ synced: boolean;
213
+ reason: string;
214
+ type?: undefined;
215
+ } | {
216
+ synced: boolean;
217
+ type: string;
218
+ reason?: undefined;
219
+ }>;
220
+
221
+ declare function protectPlan(userId: string, plan: PlanId): Promise<SubscriptionRecord>;
222
+ declare function protectFeature(userId: string, feature: FeatureKey): Promise<boolean>;
223
+ declare function protectUsage(userId: string, usageKey: string, amount?: number): Promise<{
224
+ allowed: boolean;
225
+ }>;
226
+
227
+ declare function seedDemoBilling(): Promise<void>;
228
+
229
+ interface CreatePortalSessionOptions {
230
+ customerId: string;
231
+ returnUrl?: string;
232
+ }
233
+ interface PortalSessionResult {
234
+ url: string;
235
+ }
236
+ declare function createCustomerPortalSession({ customerId, returnUrl, }: CreatePortalSessionOptions): Promise<PortalSessionResult>;
237
+
238
+ declare function paddleApi<T>(path: string, options?: RequestInit): Promise<T>;
239
+
240
+ interface PaddleSubscription {
241
+ id: string;
242
+ status: string;
243
+ customer_id?: string;
244
+ current_billing_period?: {
245
+ ends_at?: string;
246
+ };
247
+ custom_data?: {
248
+ userId?: string;
249
+ plan?: "free" | "starter" | "pro" | "business";
250
+ };
251
+ }
252
+ interface PaddleSubscriptionResponse {
253
+ data?: PaddleSubscription;
254
+ }
255
+ interface PaddleSubscriptionListResponse {
256
+ data?: PaddleSubscription[];
257
+ }
258
+ declare function fetchPaddleSubscription(subscriptionId: string): Promise<PaddleSubscriptionResponse>;
259
+ declare function fetchPaddleSubscriptionsForCustomer(customerId: string): Promise<PaddleSubscriptionListResponse>;
260
+
261
+ declare function refreshSubscriptionFromPaddle(subscriptionId: string): Promise<SubscriptionRecord>;
262
+
263
+ interface PaddleCustomer {
264
+ id: string;
265
+ email?: string;
266
+ name?: string;
267
+ status?: string;
268
+ }
269
+ interface PaddleCustomerListResponse {
270
+ data?: PaddleCustomer[];
271
+ }
272
+ interface PaddleCustomerResponse {
273
+ data?: PaddleCustomer;
274
+ }
275
+ declare function fetchPaddleCustomer(customerId: string): Promise<PaddleCustomerResponse>;
276
+ declare function findPaddleCustomersByEmail(email: string): Promise<PaddleCustomerListResponse>;
277
+ declare function findFirstPaddleCustomerByEmail(email: string): Promise<PaddleCustomer | null>;
278
+
279
+ declare function repairSubscriptionByEmail(email: string): Promise<{
280
+ customer: PaddleCustomer;
281
+ subscription: SubscriptionRecord;
282
+ }>;
283
+
284
+ declare function configureBilling({ adapter, }: {
285
+ adapter: BillingAdapter;
286
+ }): {
287
+ adapterConfigured: boolean;
288
+ };
289
+
290
+ export { type BillingAdapter, type BillingEvent, type BillingEventType, BillingHistory, type CheckoutItem, type CreatePortalSessionOptions, CustomerPortalButton, type FeatureKey, type OpenCheckoutOptions, type PaddleCustomer, type PaddleCustomerListResponse, type PaddleCustomerResponse, type PaddleSubscription, type PaddleSubscriptionListResponse, type PaddleSubscriptionResponse, type PlanId, type PortalSessionResult, SubscriptionCard, SubscriptionGate, type SubscriptionRecord, type SubscriptionStatus, type TeamMember, type TeamRecord, type TeamRole, TrialBanner, UpgradeModal, UsageMeter, addTeamMember, canInviteTeamMember, canUse, configureBilling, createCustomerPortalSession, createPrismaBillingAdapter, createTeam, fetchPaddleCustomer, fetchPaddleSubscription, fetchPaddleSubscriptionsForCustomer, findFirstPaddleCustomerByEmail, findPaddleCustomersByEmail, getBillingEvents, getPaddle, getPlanSeatLimit, getSeatUsage, getSubscription, getTeam, getUsage, getUsageLimit, hasFeature, incrementUsage, isSubscriptionActive, memoryBillingAdapter, openCheckout, paddleApi, plans, protectFeature, protectPlan, protectUsage, recordBillingEvent, refreshSubscriptionFromPaddle, removeTeamMember, repairSubscriptionByEmail, requireFeature, requireSubscription, requireUsage, seedDemoBilling, setBillingAdapter, setBillingEventAdapter, setTeamAdapter, setUsageAdapter, syncPaddleEvent, updateTeamPlan, upsertSubscription, verifyPaddleWebhook };