@parsrun/payments 0.1.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/README.md +184 -0
- package/dist/billing/index.d.ts +121 -0
- package/dist/billing/index.js +1082 -0
- package/dist/billing/index.js.map +1 -0
- package/dist/billing-service-LsAFesou.d.ts +578 -0
- package/dist/dunning/index.d.ts +310 -0
- package/dist/dunning/index.js +2677 -0
- package/dist/dunning/index.js.map +1 -0
- package/dist/index.d.ts +185 -0
- package/dist/index.js +7698 -0
- package/dist/index.js.map +1 -0
- package/dist/providers/index.d.ts +5 -0
- package/dist/providers/index.js +1396 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/providers/iyzico.d.ts +250 -0
- package/dist/providers/iyzico.js +469 -0
- package/dist/providers/iyzico.js.map +1 -0
- package/dist/providers/paddle.d.ts +66 -0
- package/dist/providers/paddle.js +437 -0
- package/dist/providers/paddle.js.map +1 -0
- package/dist/providers/stripe.d.ts +122 -0
- package/dist/providers/stripe.js +586 -0
- package/dist/providers/stripe.js.map +1 -0
- package/dist/schema-C5Zcju_j.d.ts +4191 -0
- package/dist/types.d.ts +388 -0
- package/dist/types.js +74 -0
- package/dist/types.js.map +1 -0
- package/dist/usage/index.d.ts +2674 -0
- package/dist/usage/index.js +2916 -0
- package/dist/usage/index.js.map +1 -0
- package/dist/webhooks/index.d.ts +89 -0
- package/dist/webhooks/index.js +188 -0
- package/dist/webhooks/index.js.map +1 -0
- package/package.json +91 -0
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
import { L as DunningContext, X as DunningLogger, Q as DunningNotification, S as NotificationResult } from '../schema-C5Zcju_j.js';
|
|
2
|
+
export { ah as DrizzleDb, z as DrizzleDunningStorage, a0 as DrizzleDunningStorageConfig, F as DunningAction, U as DunningEvent, V as DunningEventHandler, ad as DunningEventRow, T as DunningEventType, D as DunningManager, W as DunningManagerConfig, b as DunningScheduler, Z as DunningSchedulerConfig, H as DunningSequence, h as DunningSequenceBuilder, a1 as DunningSequenceRow, J as DunningState, a7 as DunningStateRow, I as DunningStatus, G as DunningStep, g as DunningStepBuilder, a3 as DunningStepRow, Y as DunningStorage, _ as ErrorCodeMapping, K as ExecutedStep, a9 as ExecutedStepRow, M as MemoryDunningStorage, ae as NewDunningEvent, a2 as NewDunningSequence, a8 as NewDunningState, a4 as NewDunningStep, aa as NewExecutedStep, a6 as NewPaymentFailure, ag as NewRetryStrategy, ac as NewScheduledStep, N as NotificationChannel, E as PaymentFailure, C as PaymentFailureCategory, a5 as PaymentFailureRow, p as PaymentRetrier, $ as PaymentRetrierConfig, P as PaymentRetryCalculator, O as RetryResult, R as RetryStrategy, af as RetryStrategyRow, ab as ScheduledStepRow, k as aggressiveSequence, x as allErrorCodeMappings, a as createDefaultDunningConfig, A as createDrizzleDunningStorage, e as createDunningCronHandler, f as createDunningEdgeHandler, c as createDunningManager, d as createDunningScheduler, y as createMemoryDunningStorage, r as createPaymentRetrier, q as createPaymentRetryCalculator, t as defaultRetryStrategies, n as defaultSequences, ao as dunningEvents, B as dunningSchema, ai as dunningSequences, al as dunningStates, aj as dunningSteps, am as executedSteps, o as getSequenceByTier, w as iyzicoErrorCodes, l as lenientSequence, m as minimalSequence, v as paddleErrorCodes, ak as paymentFailures, ap as retryStrategies, an as scheduledSteps, i as sequence, j as standardSaasSequence, s as step, u as stripeErrorCodes } from '../schema-C5Zcju_j.js';
|
|
3
|
+
import '../types.js';
|
|
4
|
+
import '@parsrun/types';
|
|
5
|
+
import 'drizzle-orm/pg-core';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @parsrun/payments - Dunning Email Templates
|
|
9
|
+
* Pre-built email templates for dunning notifications
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Dunning email template data
|
|
14
|
+
*/
|
|
15
|
+
interface DunningEmailData {
|
|
16
|
+
/** Customer name */
|
|
17
|
+
customerName?: string;
|
|
18
|
+
/** Amount owed in display format */
|
|
19
|
+
amount: string;
|
|
20
|
+
/** Currency code */
|
|
21
|
+
currency: string;
|
|
22
|
+
/** Days since initial failure */
|
|
23
|
+
daysSinceFailure: number;
|
|
24
|
+
/** Days until features are limited */
|
|
25
|
+
daysUntilLimit?: number;
|
|
26
|
+
/** Days until suspension */
|
|
27
|
+
daysUntilSuspension?: number;
|
|
28
|
+
/** Days until cancellation */
|
|
29
|
+
daysUntilCancellation?: number;
|
|
30
|
+
/** URL to update payment method */
|
|
31
|
+
updatePaymentUrl?: string;
|
|
32
|
+
/** URL to view invoice */
|
|
33
|
+
invoiceUrl?: string;
|
|
34
|
+
/** URL for support */
|
|
35
|
+
supportUrl?: string;
|
|
36
|
+
/** Brand name */
|
|
37
|
+
brandName?: string;
|
|
38
|
+
/** Brand color */
|
|
39
|
+
brandColor?: string;
|
|
40
|
+
/** Last 4 digits of card */
|
|
41
|
+
cardLast4?: string;
|
|
42
|
+
/** Card brand (Visa, Mastercard, etc.) */
|
|
43
|
+
cardBrand?: string;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Rendered email template
|
|
47
|
+
*/
|
|
48
|
+
interface RenderedEmail {
|
|
49
|
+
subject: string;
|
|
50
|
+
html: string;
|
|
51
|
+
text: string;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Dunning email template
|
|
55
|
+
*/
|
|
56
|
+
interface DunningEmailTemplate {
|
|
57
|
+
/** Template ID */
|
|
58
|
+
id: string;
|
|
59
|
+
/** Template name */
|
|
60
|
+
name: string;
|
|
61
|
+
/** Subject template */
|
|
62
|
+
subject: string;
|
|
63
|
+
/** HTML template */
|
|
64
|
+
html: string;
|
|
65
|
+
/** Plain text template */
|
|
66
|
+
text: string;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Format currency amount for display
|
|
70
|
+
*/
|
|
71
|
+
declare function formatAmount(amountCents: number, currency: string): string;
|
|
72
|
+
/**
|
|
73
|
+
* Payment failed - immediate notification
|
|
74
|
+
*/
|
|
75
|
+
declare const paymentFailedTemplate: DunningEmailTemplate;
|
|
76
|
+
/**
|
|
77
|
+
* Payment reminder - gentle reminder
|
|
78
|
+
*/
|
|
79
|
+
declare const paymentReminderTemplate: DunningEmailTemplate;
|
|
80
|
+
/**
|
|
81
|
+
* Payment warning - features may be limited
|
|
82
|
+
*/
|
|
83
|
+
declare const paymentWarningTemplate: DunningEmailTemplate;
|
|
84
|
+
/**
|
|
85
|
+
* Features limited notification
|
|
86
|
+
*/
|
|
87
|
+
declare const featuresLimitedTemplate: DunningEmailTemplate;
|
|
88
|
+
/**
|
|
89
|
+
* Account suspension notification
|
|
90
|
+
*/
|
|
91
|
+
declare const accountSuspendedTemplate: DunningEmailTemplate;
|
|
92
|
+
/**
|
|
93
|
+
* Final warning before cancellation
|
|
94
|
+
*/
|
|
95
|
+
declare const finalWarningTemplate: DunningEmailTemplate;
|
|
96
|
+
/**
|
|
97
|
+
* Subscription canceled
|
|
98
|
+
*/
|
|
99
|
+
declare const subscriptionCanceledTemplate: DunningEmailTemplate;
|
|
100
|
+
/**
|
|
101
|
+
* Payment recovered - success notification
|
|
102
|
+
*/
|
|
103
|
+
declare const paymentRecoveredTemplate: DunningEmailTemplate;
|
|
104
|
+
/**
|
|
105
|
+
* All default dunning templates
|
|
106
|
+
*/
|
|
107
|
+
declare const dunningEmailTemplates: Record<string, DunningEmailTemplate>;
|
|
108
|
+
/**
|
|
109
|
+
* Render a dunning email template
|
|
110
|
+
*/
|
|
111
|
+
declare function renderDunningEmail(templateId: string, data: DunningEmailData, customTemplates?: Record<string, DunningEmailTemplate>): RenderedEmail;
|
|
112
|
+
/**
|
|
113
|
+
* Build template data from dunning context
|
|
114
|
+
*/
|
|
115
|
+
declare function buildTemplateData(context: DunningContext, options?: {
|
|
116
|
+
brandName?: string;
|
|
117
|
+
brandColor?: string;
|
|
118
|
+
updatePaymentUrl?: string;
|
|
119
|
+
invoiceUrl?: string;
|
|
120
|
+
supportUrl?: string;
|
|
121
|
+
daysUntilLimit?: number;
|
|
122
|
+
daysUntilSuspension?: number;
|
|
123
|
+
daysUntilCancellation?: number;
|
|
124
|
+
}): DunningEmailData;
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* @parsrun/payments - Dunning Email Integration
|
|
128
|
+
* Built-in integration with @parsrun/email for sending dunning notifications
|
|
129
|
+
*/
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Email service interface (compatible with @parsrun/email)
|
|
133
|
+
* This allows using @parsrun/email or any compatible email service
|
|
134
|
+
*/
|
|
135
|
+
interface EmailServiceLike {
|
|
136
|
+
send(options: {
|
|
137
|
+
to: string | string[];
|
|
138
|
+
subject: string;
|
|
139
|
+
html: string;
|
|
140
|
+
text?: string;
|
|
141
|
+
replyTo?: string;
|
|
142
|
+
tags?: string[];
|
|
143
|
+
}): Promise<{
|
|
144
|
+
success: boolean;
|
|
145
|
+
messageId?: string;
|
|
146
|
+
error?: string;
|
|
147
|
+
}>;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Configuration for dunning email integration
|
|
151
|
+
*/
|
|
152
|
+
interface DunningEmailIntegrationConfig {
|
|
153
|
+
/** Email service instance (from @parsrun/email or compatible) */
|
|
154
|
+
emailService: EmailServiceLike;
|
|
155
|
+
/** Brand configuration */
|
|
156
|
+
brand?: {
|
|
157
|
+
name?: string;
|
|
158
|
+
color?: string;
|
|
159
|
+
logoUrl?: string;
|
|
160
|
+
};
|
|
161
|
+
/** URLs for dunning emails */
|
|
162
|
+
urls?: {
|
|
163
|
+
updatePayment?: string | ((customerId: string) => string);
|
|
164
|
+
viewInvoice?: string | ((invoiceId: string) => string);
|
|
165
|
+
support?: string;
|
|
166
|
+
unsubscribe?: string | ((customerId: string) => string);
|
|
167
|
+
};
|
|
168
|
+
/** Reply-to email address */
|
|
169
|
+
replyTo?: string;
|
|
170
|
+
/** Email tags for tracking */
|
|
171
|
+
tags?: string[];
|
|
172
|
+
/** Custom email templates (override defaults) */
|
|
173
|
+
customTemplates?: Record<string, DunningEmailTemplate>;
|
|
174
|
+
/** Data enrichment function */
|
|
175
|
+
enrichData?: (data: DunningEmailData, context: DunningContext) => DunningEmailData;
|
|
176
|
+
/** Logger */
|
|
177
|
+
logger?: DunningLogger;
|
|
178
|
+
/** Skip sending to specific customers */
|
|
179
|
+
skip?: (notification: DunningNotification) => boolean;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Dunning email notification handler result
|
|
183
|
+
*/
|
|
184
|
+
interface DunningEmailHandler {
|
|
185
|
+
/** Notification handler to use in DunningManagerConfig */
|
|
186
|
+
handler: (notification: DunningNotification) => Promise<NotificationResult>;
|
|
187
|
+
/** Send a one-off dunning email */
|
|
188
|
+
sendEmail: (templateId: string, to: string, context: DunningContext) => Promise<NotificationResult>;
|
|
189
|
+
/** Send recovery success email */
|
|
190
|
+
sendRecoveryEmail: (to: string, context: DunningContext) => Promise<NotificationResult>;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Create a dunning email notification handler
|
|
194
|
+
*
|
|
195
|
+
* @example
|
|
196
|
+
* ```typescript
|
|
197
|
+
* import { createEmailService } from '@parsrun/email';
|
|
198
|
+
* import { createDunningManager, createDunningEmailHandler } from '@parsrun/payments/dunning';
|
|
199
|
+
*
|
|
200
|
+
* const emailService = createEmailService({
|
|
201
|
+
* provider: 'resend',
|
|
202
|
+
* apiKey: process.env.RESEND_API_KEY,
|
|
203
|
+
* fromEmail: 'billing@example.com',
|
|
204
|
+
* fromName: 'Billing',
|
|
205
|
+
* });
|
|
206
|
+
*
|
|
207
|
+
* const dunningEmail = createDunningEmailHandler({
|
|
208
|
+
* emailService,
|
|
209
|
+
* brand: { name: 'MyApp', color: '#0070f3' },
|
|
210
|
+
* urls: {
|
|
211
|
+
* updatePayment: (customerId) => `https://app.example.com/billing?customer=${customerId}`,
|
|
212
|
+
* support: 'https://app.example.com/support',
|
|
213
|
+
* },
|
|
214
|
+
* });
|
|
215
|
+
*
|
|
216
|
+
* const dunningManager = createDunningManager({
|
|
217
|
+
* defaultSequence: standardSaasSequence,
|
|
218
|
+
* storage,
|
|
219
|
+
* onNotification: dunningEmail.handler,
|
|
220
|
+
* });
|
|
221
|
+
* ```
|
|
222
|
+
*/
|
|
223
|
+
declare function createDunningEmailHandler(config: DunningEmailIntegrationConfig): DunningEmailHandler;
|
|
224
|
+
/**
|
|
225
|
+
* SMS service interface (for future SMS integration)
|
|
226
|
+
*/
|
|
227
|
+
interface SmsServiceLike {
|
|
228
|
+
send(options: {
|
|
229
|
+
to: string;
|
|
230
|
+
message: string;
|
|
231
|
+
}): Promise<{
|
|
232
|
+
success: boolean;
|
|
233
|
+
messageId?: string;
|
|
234
|
+
error?: string;
|
|
235
|
+
}>;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Configuration for multi-channel dunning notifications
|
|
239
|
+
*/
|
|
240
|
+
interface MultiChannelDunningConfig {
|
|
241
|
+
/** Email service */
|
|
242
|
+
email?: DunningEmailIntegrationConfig;
|
|
243
|
+
/** SMS service (future) */
|
|
244
|
+
sms?: {
|
|
245
|
+
service: SmsServiceLike;
|
|
246
|
+
templates?: Record<string, string>;
|
|
247
|
+
};
|
|
248
|
+
/** In-app notification handler */
|
|
249
|
+
inApp?: (notification: DunningNotification) => Promise<NotificationResult>;
|
|
250
|
+
/** Webhook handler */
|
|
251
|
+
webhook?: (notification: DunningNotification) => Promise<NotificationResult>;
|
|
252
|
+
/** Push notification handler */
|
|
253
|
+
push?: (notification: DunningNotification) => Promise<NotificationResult>;
|
|
254
|
+
/** Logger */
|
|
255
|
+
logger?: DunningLogger;
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Create a multi-channel notification handler
|
|
259
|
+
*
|
|
260
|
+
* @example
|
|
261
|
+
* ```typescript
|
|
262
|
+
* const notificationHandler = createMultiChannelHandler({
|
|
263
|
+
* email: {
|
|
264
|
+
* emailService,
|
|
265
|
+
* brand: { name: 'MyApp' },
|
|
266
|
+
* },
|
|
267
|
+
* inApp: async (notification) => {
|
|
268
|
+
* await pushToInAppNotifications(notification);
|
|
269
|
+
* return { success: true, channel: 'in_app', sentAt: new Date() };
|
|
270
|
+
* },
|
|
271
|
+
* });
|
|
272
|
+
*
|
|
273
|
+
* const dunningManager = createDunningManager({
|
|
274
|
+
* defaultSequence: standardSaasSequence,
|
|
275
|
+
* storage,
|
|
276
|
+
* onNotification: notificationHandler,
|
|
277
|
+
* });
|
|
278
|
+
* ```
|
|
279
|
+
*/
|
|
280
|
+
declare function createMultiChannelHandler(config: MultiChannelDunningConfig): (notification: DunningNotification) => Promise<NotificationResult>;
|
|
281
|
+
/**
|
|
282
|
+
* Create a simple email-only notification handler
|
|
283
|
+
* Convenience wrapper for common use case
|
|
284
|
+
*
|
|
285
|
+
* @example
|
|
286
|
+
* ```typescript
|
|
287
|
+
* import { createEmailService } from '@parsrun/email';
|
|
288
|
+
* import { createDunningManager, simpleEmailHandler } from '@parsrun/payments/dunning';
|
|
289
|
+
*
|
|
290
|
+
* const emailService = createEmailService({ ... });
|
|
291
|
+
*
|
|
292
|
+
* const dunningManager = createDunningManager({
|
|
293
|
+
* defaultSequence: standardSaasSequence,
|
|
294
|
+
* storage,
|
|
295
|
+
* onNotification: simpleEmailHandler(emailService, {
|
|
296
|
+
* brandName: 'MyApp',
|
|
297
|
+
* updatePaymentUrl: 'https://app.example.com/billing',
|
|
298
|
+
* }),
|
|
299
|
+
* });
|
|
300
|
+
* ```
|
|
301
|
+
*/
|
|
302
|
+
declare function simpleEmailHandler(emailService: EmailServiceLike, options?: {
|
|
303
|
+
brandName?: string;
|
|
304
|
+
brandColor?: string;
|
|
305
|
+
updatePaymentUrl?: string;
|
|
306
|
+
supportUrl?: string;
|
|
307
|
+
replyTo?: string;
|
|
308
|
+
}): (notification: DunningNotification) => Promise<NotificationResult>;
|
|
309
|
+
|
|
310
|
+
export { DunningContext, type DunningEmailData, type DunningEmailHandler, type DunningEmailIntegrationConfig, type DunningEmailTemplate, DunningLogger, DunningNotification, type EmailServiceLike, type MultiChannelDunningConfig, NotificationResult, type RenderedEmail, type SmsServiceLike, accountSuspendedTemplate, buildTemplateData, createDunningEmailHandler, createMultiChannelHandler, dunningEmailTemplates, featuresLimitedTemplate, finalWarningTemplate, formatAmount, paymentFailedTemplate, paymentRecoveredTemplate, paymentReminderTemplate, paymentWarningTemplate, renderDunningEmail, simpleEmailHandler, subscriptionCanceledTemplate };
|