better-auth-mercadopago 0.1.8 → 0.2.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.
@@ -1,303 +1,6 @@
1
- import { BetterFetchOption, BetterFetch } from 'better-auth/client';
2
- import * as better_auth from 'better-auth';
3
- import { z } from 'zod';
4
-
5
- /** biome-ignore-all lint/suspicious/noExplicitAny: <no need to use any> */
6
- interface MercadoPagoPluginOptions {
7
- /**
8
- * Your Mercado Pago access token
9
- */
10
- accessToken: string;
11
- /**
12
- * Base URL for redirects and webhooks
13
- * @default process.env.APP_URL
14
- */
15
- baseUrl?: string;
16
- /**
17
- * Webhook secret for signature verification (optional)
18
- */
19
- webhookSecret?: string;
20
- /**
21
- * App ID for OAuth (required for marketplace features)
22
- * Get it from: https://www.mercadopago.com/developers/panel/app
23
- */
24
- appId?: string;
25
- /**
26
- * App Secret for OAuth (required for marketplace features)
27
- */
28
- appSecret?: string;
29
- /**
30
- * Trusted origins for OAuth redirects
31
- */
32
- trustedOrigins?: string[];
33
- /**
34
- * Callback executed when a payment status changes
35
- */
36
- onPaymentUpdate?: (data: {
37
- payment: MercadoPagoPaymentRecord;
38
- status: string;
39
- statusDetail: string;
40
- mpPayment: MercadoPagoPaymentResponse;
41
- }) => void | Promise<void>;
42
- /**
43
- * Callback executed when a subscription status changes
44
- */
45
- onSubscriptionUpdate?: (data: {
46
- subscription: MercadoPagoSubscriptionRecord;
47
- status: string;
48
- reason: string;
49
- mpPreapproval: MercadoPagoPreApprovalResponse;
50
- }) => void | Promise<void>;
51
- /**
52
- * Callback executed when a recurring payment is processed (monthly, etc.)
53
- */
54
- onSubscriptionPayment?: (data: {
55
- subscription: MercadoPagoSubscriptionRecord;
56
- payment: MercadoPagoPaymentResponse;
57
- status: string;
58
- }) => void | Promise<void>;
59
- }
60
- interface MercadoPagoCustomerRecord {
61
- id: string;
62
- userId: string;
63
- mercadoPagoId: string;
64
- email: string;
65
- createdAt: Date;
66
- updatedAt: Date;
67
- }
68
- interface MercadoPagoPaymentRecord {
69
- id: string;
70
- userId: string;
71
- mercadoPagoPaymentId: string;
72
- preferenceId: string;
73
- status: string;
74
- amount: number;
75
- currency: string;
76
- metadata?: string;
77
- createdAt: Date;
78
- updatedAt: Date;
79
- }
80
- interface MercadoPagoSubscriptionRecord {
81
- id: string;
82
- userId: string;
83
- mercadoPagoSubscriptionId: string;
84
- planId: string;
85
- status: string;
86
- reason?: string;
87
- nextPaymentDate?: Date;
88
- lastPaymentDate?: Date;
89
- summarized?: string;
90
- metadata?: string;
91
- createdAt: Date;
92
- updatedAt: Date;
93
- }
94
- interface MercadoPagoMarketplaceSplitRecord {
95
- id: string;
96
- paymentId: string;
97
- collectorId: string;
98
- collectorEmail: string;
99
- applicationFeeAmount?: number;
100
- applicationFeePercentage?: number;
101
- netAmount: number;
102
- metadata?: string;
103
- createdAt: Date;
104
- }
105
- interface MercadoPagoOAuthTokenRecord {
106
- id: string;
107
- userId: string;
108
- accessToken: string;
109
- refreshToken: string;
110
- publicKey: string;
111
- mercadoPagoUserId: string;
112
- expiresAt: Date;
113
- createdAt: Date;
114
- updatedAt: Date;
115
- }
116
- interface MercadoPagoPreapprovalPlanRecord {
117
- id: string;
118
- mercadoPagoPlanId: string;
119
- reason: string;
120
- frequency: number;
121
- frequencyType: string;
122
- transactionAmount: number;
123
- currencyId: string;
124
- repetitions?: number;
125
- freeTrial?: string;
126
- metadata?: string;
127
- createdAt: Date;
128
- updatedAt: Date;
129
- }
130
- interface PaymentItem {
131
- id: string;
132
- title: string;
133
- quantity: number;
134
- unitPrice: number;
135
- currencyId?: string;
136
- }
137
- interface MarketplaceConfig {
138
- collectorId: string;
139
- applicationFee?: number;
140
- applicationFeePercentage?: number;
141
- }
142
- interface CreatePaymentParams {
143
- items: PaymentItem[];
144
- metadata?: Record<string, any>;
145
- marketplace?: MarketplaceConfig;
146
- successUrl?: string;
147
- failureUrl?: string;
148
- pendingUrl?: string;
149
- }
150
- interface CreateSubscriptionParams {
151
- preapprovalPlanId?: string;
152
- reason?: string;
153
- autoRecurring?: {
154
- frequency: number;
155
- frequencyType: "days" | "months";
156
- transactionAmount: number;
157
- currencyId?: string;
158
- startDate?: string;
159
- endDate?: string;
160
- freeTrial?: {
161
- frequency: number;
162
- frequencyType: "days" | "months";
163
- };
164
- };
165
- backUrl?: string;
166
- metadata?: Record<string, any>;
167
- }
168
- interface CreatePreapprovalPlanParams {
169
- reason: string;
170
- autoRecurring: {
171
- frequency: number;
172
- frequencyType: "days" | "months";
173
- transactionAmount: number;
174
- currencyId?: string;
175
- freeTrial?: {
176
- frequency: number;
177
- frequencyType: "days" | "months";
178
- };
179
- };
180
- repetitions?: number;
181
- backUrl?: string;
182
- metadata?: Record<string, any>;
183
- }
184
- interface CreatePreapprovalPlanResponse {
185
- plan: MercadoPagoPreapprovalPlanRecord;
186
- }
187
- interface CreatePaymentResponse {
188
- checkoutUrl: string;
189
- preferenceId: string;
190
- payment: MercadoPagoPaymentRecord;
191
- }
192
- interface CreateSubscriptionResponse {
193
- checkoutUrl: string;
194
- subscription: MercadoPagoSubscriptionRecord;
195
- }
196
- interface OAuthUrlResponse {
197
- authUrl: string;
198
- }
199
- interface OAuthTokenResponse {
200
- success: boolean;
201
- oauthToken: {
202
- id: string;
203
- mercadoPagoUserId: string;
204
- expiresAt: Date;
205
- };
206
- }
207
- interface MercadoPagoPaymentResponse {
208
- id: number;
209
- date_created: string;
210
- date_approved: string;
211
- date_last_updated: string;
212
- money_release_date: string;
213
- payment_method_id: string;
214
- payment_type_id: string;
215
- status: string;
216
- status_detail: string;
217
- currency_id: string;
218
- description: string;
219
- live_mode: boolean;
220
- sponsor_id: number;
221
- authorization_code: string;
222
- integrator_id: string;
223
- taxes_amount: number;
224
- counter_currency: string;
225
- operation_type: string;
226
- additional_info: {
227
- items: {
228
- id: string;
229
- title: string;
230
- description: string;
231
- picture_url: string;
232
- category_id: string;
233
- quantity: string;
234
- unit_price: string;
235
- }[];
236
- payer: {
237
- first_name: string;
238
- last_name: string;
239
- phone: {
240
- area_code: string;
241
- number: string;
242
- };
243
- };
244
- ip_address: string;
245
- };
246
- external_reference: string;
247
- transaction_amount: number;
248
- transaction_amount_refunded: number;
249
- coupon_amount: number;
250
- installments: number;
251
- transaction_details: {
252
- net_received_amount: number;
253
- total_paid_amount: number;
254
- overpaid_amount: number;
255
- external_resource_url: string;
256
- installment_amount: number;
257
- financial_institution: string;
258
- payment_method_reference_id: string;
259
- };
260
- }
261
- interface MercadoPagoPreApprovalResponse {
262
- id: string;
263
- payer_id: number;
264
- payer_email: string;
265
- back_url: string;
266
- collector_id: number;
267
- application_id: number;
268
- status: string;
269
- reason: string;
270
- external_reference: string;
271
- date_created: string;
272
- last_modified: string;
273
- init_point: string;
274
- auto_recurring: {
275
- frequency: number;
276
- frequency_type: string;
277
- transaction_amount: number;
278
- currency_id: string;
279
- start_date: string;
280
- end_date: string;
281
- free_trial?: {
282
- frequency: number;
283
- frequency_type: string;
284
- };
285
- };
286
- summarized?: {
287
- quotas: number;
288
- charged_quantity: number;
289
- pending_charge_quantity: number;
290
- charged_amount: number;
291
- pending_charge_amount: number;
292
- semester: number;
293
- year: number;
294
- };
295
- next_payment_date: string;
296
- payment_method_id: string;
297
- }
298
-
299
- declare const mercadoPagoPlugin: (options: MercadoPagoPluginOptions) => {
300
- trustedOrigins?: string[] | undefined;
1
+ import { z } from "zod";
2
+ import type { MercadoPagoPaymentRecord, MercadoPagoPluginOptions } from "./types";
3
+ export declare const mercadoPagoPlugin: (options: MercadoPagoPluginOptions) => {
301
4
  id: "mercadopago";
302
5
  schema: {
303
6
  mercadoPagoCustomer: {
@@ -585,7 +288,7 @@ declare const mercadoPagoPlugin: (options: MercadoPagoPluginOptions) => {
585
288
  };
586
289
  };
587
290
  endpoints: {
588
- getOrCreateCustomer: better_auth.StrictEndpoint<"/mercado-pago/customer", {
291
+ getOrCreateCustomer: import("better-auth").StrictEndpoint<"/mercado-pago/customer", {
589
292
  method: "POST";
590
293
  requireAuth: boolean;
591
294
  body: z.ZodObject<{
@@ -604,7 +307,7 @@ declare const mercadoPagoPlugin: (options: MercadoPagoPluginOptions) => {
604
307
  }, {
605
308
  customer: {};
606
309
  }>;
607
- getOAuthUrl: better_auth.StrictEndpoint<"/mercado-pago/oauth/authorize", {
310
+ getOAuthUrl: import("better-auth").StrictEndpoint<"/mercado-pago/oauth/authorize", {
608
311
  method: "GET";
609
312
  requireAuth: boolean;
610
313
  query: z.ZodObject<{
@@ -617,7 +320,7 @@ declare const mercadoPagoPlugin: (options: MercadoPagoPluginOptions) => {
617
320
  }, {
618
321
  authUrl: string;
619
322
  }>;
620
- exchangeOAuthCode: better_auth.StrictEndpoint<"/mercado-pago/oauth/callback", {
323
+ exchangeOAuthCode: import("better-auth").StrictEndpoint<"/mercado-pago/oauth/callback", {
621
324
  method: "POST";
622
325
  requireAuth: boolean;
623
326
  body: z.ZodObject<{
@@ -638,7 +341,7 @@ declare const mercadoPagoPlugin: (options: MercadoPagoPluginOptions) => {
638
341
  expiresAt: any;
639
342
  };
640
343
  }>;
641
- createPreapprovalPlan: better_auth.StrictEndpoint<"/mercado-pago/plan/create", {
344
+ createPreapprovalPlan: import("better-auth").StrictEndpoint<"/mercado-pago/plan/create", {
642
345
  method: "POST";
643
346
  body: z.ZodObject<{
644
347
  reason: z.ZodString;
@@ -713,12 +416,12 @@ declare const mercadoPagoPlugin: (options: MercadoPagoPluginOptions) => {
713
416
  }, {
714
417
  plan: Record<string, any>;
715
418
  }>;
716
- listPreapprovalPlans: better_auth.StrictEndpoint<"/mercado-pago/plans", {
419
+ listPreapprovalPlans: import("better-auth").StrictEndpoint<"/mercado-pago/plans", {
717
420
  method: "GET";
718
421
  }, {
719
422
  plans: unknown[];
720
423
  }>;
721
- createPayment: better_auth.StrictEndpoint<"/mercado-pago/payment/create", {
424
+ createPayment: import("better-auth").StrictEndpoint<"/mercado-pago/payment/create", {
722
425
  method: "POST";
723
426
  requireAuth: boolean;
724
427
  body: z.ZodObject<{
@@ -797,7 +500,7 @@ declare const mercadoPagoPlugin: (options: MercadoPagoPluginOptions) => {
797
500
  idempotencyKey?: string | undefined;
798
501
  }>;
799
502
  }, any>;
800
- createSubscription: better_auth.StrictEndpoint<"/mercado-pago/subscription/create", {
503
+ createSubscription: import("better-auth").StrictEndpoint<"/mercado-pago/subscription/create", {
801
504
  method: "POST";
802
505
  requireAuth: boolean;
803
506
  body: z.ZodObject<{
@@ -884,7 +587,7 @@ declare const mercadoPagoPlugin: (options: MercadoPagoPluginOptions) => {
884
587
  checkoutUrl: string | undefined;
885
588
  subscription: Record<string, any>;
886
589
  }>;
887
- cancelSubscription: better_auth.StrictEndpoint<"/mercado-pago/subscription/cancel", {
590
+ cancelSubscription: import("better-auth").StrictEndpoint<"/mercado-pago/subscription/cancel", {
888
591
  method: "POST";
889
592
  requireAuth: boolean;
890
593
  body: z.ZodObject<{
@@ -897,13 +600,13 @@ declare const mercadoPagoPlugin: (options: MercadoPagoPluginOptions) => {
897
600
  }, {
898
601
  success: boolean;
899
602
  }>;
900
- getPayment: better_auth.StrictEndpoint<"/mercado-pago/payment/:id", {
603
+ getPayment: import("better-auth").StrictEndpoint<"/mercado-pago/payment/:id", {
901
604
  method: "GET";
902
605
  requireAuth: boolean;
903
606
  }, {
904
607
  payment: MercadoPagoPaymentRecord;
905
608
  }>;
906
- listPayments: better_auth.StrictEndpoint<"/mercado-pago/payments", {
609
+ listPayments: import("better-auth").StrictEndpoint<"/mercado-pago/payments", {
907
610
  method: "GET";
908
611
  requireAuth: boolean;
909
612
  query: z.ZodObject<{
@@ -919,102 +622,17 @@ declare const mercadoPagoPlugin: (options: MercadoPagoPluginOptions) => {
919
622
  }, {
920
623
  payments: unknown[];
921
624
  }>;
922
- listSubscriptions: better_auth.StrictEndpoint<"/mercado-pago/subscriptions", {
625
+ listSubscriptions: import("better-auth").StrictEndpoint<"/mercado-pago/subscriptions", {
923
626
  method: "GET";
924
627
  requireAuth: boolean;
925
628
  }, {
926
629
  subscriptions: unknown[];
927
630
  }>;
928
- webhook: better_auth.StrictEndpoint<"/mercado-pago/webhook", {
631
+ webhook: import("better-auth").StrictEndpoint<"/mercado-pago/webhook", {
929
632
  method: "POST";
930
633
  }, {
931
634
  received: boolean;
932
635
  }>;
933
636
  };
934
637
  };
935
-
936
- interface MercadoPagoClientActions {
937
- /**
938
- * Get or create a Mercado Pago customer for the authenticated user
939
- */
940
- getOrCreateCustomer: (data?: {
941
- email?: string;
942
- firstName?: string;
943
- lastName?: string;
944
- }, fetchOptions?: BetterFetchOption) => Promise<{
945
- customer: MercadoPagoCustomerRecord;
946
- }>;
947
- /**
948
- * Create a payment and get checkout URL
949
- */
950
- createPayment: (data: CreatePaymentParams, fetchOptions?: BetterFetchOption) => Promise<CreatePaymentResponse>;
951
- /**
952
- * Create a marketplace payment with automatic split
953
- */
954
- createMarketplacePayment: (data: CreatePaymentParams, fetchOptions?: BetterFetchOption) => Promise<CreatePaymentResponse>;
955
- /**
956
- * Create a subscription with recurring payments
957
- */
958
- createSubscription: (data: CreateSubscriptionParams, fetchOptions?: BetterFetchOption) => Promise<CreateSubscriptionResponse>;
959
- /**
960
- * Cancel a subscription
961
- */
962
- cancelSubscription: (data: {
963
- subscriptionId: string;
964
- }, fetchOptions?: BetterFetchOption) => Promise<{
965
- success: boolean;
966
- }>;
967
- /**
968
- * Create a reusable preapproval plan (subscription template)
969
- */
970
- createPreapprovalPlan: (data: CreatePreapprovalPlanParams, fetchOptions?: BetterFetchOption) => Promise<CreatePreapprovalPlanResponse>;
971
- /**
972
- * List all preapproval plans
973
- */
974
- listPreapprovalPlans: (fetchOptions?: BetterFetchOption) => Promise<{
975
- plans: MercadoPagoPreapprovalPlanRecord[];
976
- }>;
977
- /**
978
- * Get payment by ID
979
- */
980
- getPayment: (paymentId: string, fetchOptions?: BetterFetchOption) => Promise<{
981
- payment: MercadoPagoPaymentRecord;
982
- }>;
983
- /**
984
- * List all payments for the authenticated user
985
- */
986
- listPayments: (params?: {
987
- limit?: number;
988
- offset?: number;
989
- }, fetchOptions?: BetterFetchOption) => Promise<{
990
- payments: MercadoPagoPaymentRecord[];
991
- }>;
992
- /**
993
- * List all subscriptions for the authenticated user
994
- */
995
- listSubscriptions: (fetchOptions?: BetterFetchOption) => Promise<{
996
- subscriptions: MercadoPagoSubscriptionRecord[];
997
- }>;
998
- /**
999
- * Get OAuth authorization URL for marketplace sellers
1000
- */
1001
- getOAuthUrl: (params: {
1002
- redirectUri: string;
1003
- }, fetchOptions?: BetterFetchOption) => Promise<OAuthUrlResponse>;
1004
- /**
1005
- * Exchange OAuth code for access token
1006
- */
1007
- exchangeOAuthCode: (data: {
1008
- code: string;
1009
- redirectUri: string;
1010
- }, fetchOptions?: BetterFetchOption) => Promise<OAuthTokenResponse>;
1011
- }
1012
- type mercadopagoPlugin = typeof mercadoPagoPlugin;
1013
- type MercadoPagoClient = MercadoPagoClientActions;
1014
- declare const mercadoPagoClientPlugin: () => {
1015
- id: "mercadopago";
1016
- $InferServerPlugin: ReturnType<mercadopagoPlugin>;
1017
- getActions: ($fetch: BetterFetch) => MercadoPagoClientActions;
1018
- };
1019
-
1020
- export { type CreatePaymentParams, type CreatePaymentResponse, type CreatePreapprovalPlanParams, type CreatePreapprovalPlanResponse, type CreateSubscriptionParams, type CreateSubscriptionResponse, type MarketplaceConfig, type MercadoPagoClient, type MercadoPagoClientActions, type MercadoPagoCustomerRecord, type MercadoPagoMarketplaceSplitRecord, type MercadoPagoOAuthTokenRecord, type MercadoPagoPaymentRecord, type MercadoPagoPaymentResponse, type MercadoPagoPluginOptions, type MercadoPagoPreApprovalResponse, type MercadoPagoPreapprovalPlanRecord, type MercadoPagoSubscriptionRecord, type OAuthTokenResponse, type OAuthUrlResponse, type PaymentItem, mercadoPagoClientPlugin, mercadoPagoPlugin };
638
+ //# sourceMappingURL=server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAaxB,OAAO,KAAK,EAEX,wBAAwB,EAExB,wBAAwB,EAGxB,MAAM,SAAS,CAAC;AAEjB,eAAO,MAAM,iBAAiB,GAAI,SAAS,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAszClE,CAAC"}