@umohpyro/better-auth-nuvion 0.0.0-stage → 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.
@@ -0,0 +1,470 @@
1
+ import { f as Leg, b as PaymentStatus, a as PaymentLeg } from './types-BWF8YNYE.cjs';
2
+ import * as better_auth from 'better-auth';
3
+ import * as z from 'zod';
4
+
5
+ /** Fields Nuvion requires on a business counterparty besides its name. */
6
+ interface CounterpartyProfile {
7
+ email: string;
8
+ relationship: string;
9
+ address: {
10
+ line1: string;
11
+ city: string;
12
+ country: string;
13
+ postal_code?: string;
14
+ };
15
+ }
16
+
17
+ interface NuvionPluginOptions {
18
+ apiKey: string;
19
+ webhookSecret: string;
20
+ baseUrl?: string;
21
+ fetch?: typeof fetch;
22
+ webhookToleranceMs?: number;
23
+ /** Contact details for the counterparties created for book transfers. Defaults are placeholders; set real ones. */
24
+ counterparty?: Partial<CounterpartyProfile>;
25
+ }
26
+ declare const nuvion: (opts: NuvionPluginOptions) => {
27
+ id: "nuvion";
28
+ schema: {
29
+ organization: {
30
+ fields: {
31
+ parentOrganizationId: {
32
+ type: "string";
33
+ required: false;
34
+ input: false;
35
+ };
36
+ };
37
+ };
38
+ nuvionBinding: {
39
+ fields: {
40
+ organizationId: {
41
+ unique: true;
42
+ type: "string";
43
+ required: boolean;
44
+ };
45
+ entityId: {
46
+ type: "string";
47
+ required: boolean;
48
+ };
49
+ accountId: {
50
+ type: "string";
51
+ required: boolean;
52
+ };
53
+ };
54
+ };
55
+ nuvionDestination: {
56
+ fields: {
57
+ fromOrganizationId: {
58
+ index: boolean;
59
+ type: "string";
60
+ required: boolean;
61
+ };
62
+ toOrganizationId: {
63
+ type: "string";
64
+ required: boolean;
65
+ };
66
+ counterpartyId: {
67
+ type: "string";
68
+ required: boolean;
69
+ };
70
+ paymentDetailId: {
71
+ type: "string";
72
+ required: boolean;
73
+ };
74
+ };
75
+ };
76
+ nuvionFeeRule: {
77
+ fields: {
78
+ organizationId: {
79
+ unique: true;
80
+ type: "string";
81
+ required: boolean;
82
+ };
83
+ flatMinor: {
84
+ type: "number";
85
+ required: boolean;
86
+ bigint: boolean;
87
+ };
88
+ bps: {
89
+ type: "number";
90
+ required: boolean;
91
+ bigint: boolean;
92
+ };
93
+ minMinor: {
94
+ type: "number";
95
+ required: boolean;
96
+ bigint: boolean;
97
+ };
98
+ capMinor: {
99
+ type: "number";
100
+ required: boolean;
101
+ bigint: boolean;
102
+ };
103
+ bearer: {
104
+ type: "string";
105
+ required: boolean;
106
+ };
107
+ };
108
+ };
109
+ nuvionPayment: {
110
+ fields: {
111
+ organizationId: {
112
+ index: boolean;
113
+ type: "string";
114
+ required: boolean;
115
+ };
116
+ reference: {
117
+ unique: true;
118
+ type: "string";
119
+ required: boolean;
120
+ };
121
+ providerSessionId: {
122
+ type: "string";
123
+ required: false;
124
+ };
125
+ baseMinor: {
126
+ type: "number";
127
+ required: boolean;
128
+ bigint: boolean;
129
+ };
130
+ chargedMinor: {
131
+ type: "number";
132
+ required: boolean;
133
+ bigint: boolean;
134
+ };
135
+ currency: {
136
+ type: "string";
137
+ required: boolean;
138
+ };
139
+ status: {
140
+ type: "string";
141
+ required: boolean;
142
+ };
143
+ createdAt: {
144
+ type: "number";
145
+ required: boolean;
146
+ bigint: boolean;
147
+ };
148
+ };
149
+ };
150
+ nuvionLeg: {
151
+ fields: {
152
+ paymentId: {
153
+ index: boolean;
154
+ type: "string";
155
+ required: boolean;
156
+ };
157
+ kind: {
158
+ type: "string";
159
+ required: boolean;
160
+ };
161
+ fromOrganizationId: {
162
+ type: "string";
163
+ required: boolean;
164
+ };
165
+ toOrganizationId: {
166
+ type: "string";
167
+ required: boolean;
168
+ };
169
+ amountMinor: {
170
+ type: "number";
171
+ required: boolean;
172
+ bigint: boolean;
173
+ };
174
+ state: {
175
+ type: "string";
176
+ required: boolean;
177
+ };
178
+ attempt: {
179
+ type: "number";
180
+ required: true;
181
+ };
182
+ providerRef: {
183
+ type: "string";
184
+ required: false;
185
+ };
186
+ error: {
187
+ type: "string";
188
+ required: false;
189
+ };
190
+ };
191
+ };
192
+ nuvionEvent: {
193
+ fields: {
194
+ eventId: {
195
+ unique: true;
196
+ type: "string";
197
+ required: boolean;
198
+ };
199
+ receivedAt: {
200
+ type: "number";
201
+ required: boolean;
202
+ bigint: boolean;
203
+ };
204
+ };
205
+ };
206
+ };
207
+ onRequest(request: Request, ctx: better_auth.AuthContext): Promise<{
208
+ response: Response;
209
+ } | undefined>;
210
+ endpoints: {
211
+ setParent: better_auth.StrictEndpoint<"/nuvion/organization/parent", {
212
+ method: "POST";
213
+ use: better_auth.Middleware<better_auth.MiddlewareOptions, (inputContext: better_auth.MiddlewareInputContext<better_auth.MiddlewareOptions>) => Promise<{
214
+ session: {
215
+ session: Record<string, any> & {
216
+ id: string;
217
+ createdAt: Date;
218
+ updatedAt: Date;
219
+ userId: string;
220
+ expiresAt: Date;
221
+ token: string;
222
+ ipAddress?: string | null | undefined;
223
+ userAgent?: string | null | undefined;
224
+ };
225
+ user: Record<string, any> & {
226
+ id: string;
227
+ createdAt: Date;
228
+ updatedAt: Date;
229
+ email: string;
230
+ emailVerified: boolean;
231
+ name: string;
232
+ image?: string | null | undefined;
233
+ };
234
+ };
235
+ }>>[];
236
+ body: z.ZodObject<{
237
+ organizationId: z.ZodString;
238
+ parentOrganizationId: z.ZodNullable<z.ZodString>;
239
+ }, z.core.$strip>;
240
+ }, {
241
+ ok: boolean;
242
+ }>;
243
+ bindEntity: better_auth.StrictEndpoint<"/nuvion/organization/bind", {
244
+ method: "POST";
245
+ use: better_auth.Middleware<better_auth.MiddlewareOptions, (inputContext: better_auth.MiddlewareInputContext<better_auth.MiddlewareOptions>) => Promise<{
246
+ session: {
247
+ session: Record<string, any> & {
248
+ id: string;
249
+ createdAt: Date;
250
+ updatedAt: Date;
251
+ userId: string;
252
+ expiresAt: Date;
253
+ token: string;
254
+ ipAddress?: string | null | undefined;
255
+ userAgent?: string | null | undefined;
256
+ };
257
+ user: Record<string, any> & {
258
+ id: string;
259
+ createdAt: Date;
260
+ updatedAt: Date;
261
+ email: string;
262
+ emailVerified: boolean;
263
+ name: string;
264
+ image?: string | null | undefined;
265
+ };
266
+ };
267
+ }>>[];
268
+ body: z.ZodObject<{
269
+ organizationId: z.ZodString;
270
+ entityId: z.ZodString;
271
+ accountId: z.ZodString;
272
+ }, z.core.$strip>;
273
+ }, {
274
+ ok: boolean;
275
+ }>;
276
+ /**
277
+ * Create the book-transfer counterparties for an organization's splits (it -> each ancestor) now, instead of on the first
278
+ * transfer, so a missing or shared Nuvion account shows up here and not as a failed leg. Safe to call again: pairs that
279
+ * already exist are reused. Refund reversals (ancestor -> it) are created when a refund first needs them.
280
+ */
281
+ provisionDestinations: better_auth.StrictEndpoint<"/nuvion/organization/destinations", {
282
+ method: "POST";
283
+ use: better_auth.Middleware<better_auth.MiddlewareOptions, (inputContext: better_auth.MiddlewareInputContext<better_auth.MiddlewareOptions>) => Promise<{
284
+ session: {
285
+ session: Record<string, any> & {
286
+ id: string;
287
+ createdAt: Date;
288
+ updatedAt: Date;
289
+ userId: string;
290
+ expiresAt: Date;
291
+ token: string;
292
+ ipAddress?: string | null | undefined;
293
+ userAgent?: string | null | undefined;
294
+ };
295
+ user: Record<string, any> & {
296
+ id: string;
297
+ createdAt: Date;
298
+ updatedAt: Date;
299
+ email: string;
300
+ emailVerified: boolean;
301
+ name: string;
302
+ image?: string | null | undefined;
303
+ };
304
+ };
305
+ }>>[];
306
+ body: z.ZodObject<{
307
+ organizationId: z.ZodString;
308
+ }, z.core.$strip>;
309
+ }, {
310
+ results: {
311
+ toOrganizationId: string;
312
+ status: "ready" | "error";
313
+ message?: string;
314
+ }[];
315
+ }>;
316
+ /** The PARENT's admin sets what the parent takes from a child's payments. */
317
+ setFeeRule: better_auth.StrictEndpoint<"/nuvion/fee-rule", {
318
+ method: "POST";
319
+ use: better_auth.Middleware<better_auth.MiddlewareOptions, (inputContext: better_auth.MiddlewareInputContext<better_auth.MiddlewareOptions>) => Promise<{
320
+ session: {
321
+ session: Record<string, any> & {
322
+ id: string;
323
+ createdAt: Date;
324
+ updatedAt: Date;
325
+ userId: string;
326
+ expiresAt: Date;
327
+ token: string;
328
+ ipAddress?: string | null | undefined;
329
+ userAgent?: string | null | undefined;
330
+ };
331
+ user: Record<string, any> & {
332
+ id: string;
333
+ createdAt: Date;
334
+ updatedAt: Date;
335
+ email: string;
336
+ emailVerified: boolean;
337
+ name: string;
338
+ image?: string | null | undefined;
339
+ };
340
+ };
341
+ }>>[];
342
+ body: z.ZodObject<{
343
+ organizationId: z.ZodString;
344
+ flatMinor: z.ZodDefault<z.ZodNumber>;
345
+ bps: z.ZodDefault<z.ZodNumber>;
346
+ minMinor: z.ZodOptional<z.ZodNumber>;
347
+ capMinor: z.ZodOptional<z.ZodNumber>;
348
+ bearer: z.ZodDefault<z.ZodEnum<{
349
+ payer: "payer";
350
+ merchant: "merchant";
351
+ }>>;
352
+ }, z.core.$strip>;
353
+ }, {
354
+ ok: boolean;
355
+ }>;
356
+ createPayment: better_auth.StrictEndpoint<"/nuvion/payments", {
357
+ method: "POST";
358
+ use: better_auth.Middleware<better_auth.MiddlewareOptions, (inputContext: better_auth.MiddlewareInputContext<better_auth.MiddlewareOptions>) => Promise<{
359
+ session: {
360
+ session: Record<string, any> & {
361
+ id: string;
362
+ createdAt: Date;
363
+ updatedAt: Date;
364
+ userId: string;
365
+ expiresAt: Date;
366
+ token: string;
367
+ ipAddress?: string | null | undefined;
368
+ userAgent?: string | null | undefined;
369
+ };
370
+ user: Record<string, any> & {
371
+ id: string;
372
+ createdAt: Date;
373
+ updatedAt: Date;
374
+ email: string;
375
+ emailVerified: boolean;
376
+ name: string;
377
+ image?: string | null | undefined;
378
+ };
379
+ };
380
+ }>>[];
381
+ body: z.ZodObject<{
382
+ organizationId: z.ZodString;
383
+ amountMinor: z.ZodNumber;
384
+ currency: z.ZodString;
385
+ redirectUrl: z.ZodString;
386
+ }, z.core.$strip>;
387
+ }, {
388
+ paymentId: string;
389
+ checkoutUrl: string;
390
+ chargedMinor: number;
391
+ legs: Leg[];
392
+ }>;
393
+ /** Retry stuck legs (partial failure). Call from a cron or an admin action. */
394
+ retryLegs: better_auth.StrictEndpoint<"/nuvion/payments/retry", {
395
+ method: "POST";
396
+ use: better_auth.Middleware<better_auth.MiddlewareOptions, (inputContext: better_auth.MiddlewareInputContext<better_auth.MiddlewareOptions>) => Promise<{
397
+ session: {
398
+ session: Record<string, any> & {
399
+ id: string;
400
+ createdAt: Date;
401
+ updatedAt: Date;
402
+ userId: string;
403
+ expiresAt: Date;
404
+ token: string;
405
+ ipAddress?: string | null | undefined;
406
+ userAgent?: string | null | undefined;
407
+ };
408
+ user: Record<string, any> & {
409
+ id: string;
410
+ createdAt: Date;
411
+ updatedAt: Date;
412
+ email: string;
413
+ emailVerified: boolean;
414
+ name: string;
415
+ image?: string | null | undefined;
416
+ };
417
+ };
418
+ }>>[];
419
+ body: z.ZodObject<{
420
+ paymentId: z.ZodString;
421
+ }, z.core.$strip>;
422
+ }, {
423
+ paymentStatus: PaymentStatus;
424
+ legs: PaymentLeg[];
425
+ }>;
426
+ /**
427
+ * Start a refund: unsent legs are cancelled and every moved leg gets a reversal leg (beneficiary -> payer-side org),
428
+ * so the merchant account is made whole. Paying the customer back is outside the plugin: Nuvion documents no refund
429
+ * API for funding-session inflows. Each (beneficiary -> origin) pair needs a counterparty, like the forward legs.
430
+ */
431
+ refundPayment: better_auth.StrictEndpoint<"/nuvion/payments/refund", {
432
+ method: "POST";
433
+ use: better_auth.Middleware<better_auth.MiddlewareOptions, (inputContext: better_auth.MiddlewareInputContext<better_auth.MiddlewareOptions>) => Promise<{
434
+ session: {
435
+ session: Record<string, any> & {
436
+ id: string;
437
+ createdAt: Date;
438
+ updatedAt: Date;
439
+ userId: string;
440
+ expiresAt: Date;
441
+ token: string;
442
+ ipAddress?: string | null | undefined;
443
+ userAgent?: string | null | undefined;
444
+ };
445
+ user: Record<string, any> & {
446
+ id: string;
447
+ createdAt: Date;
448
+ updatedAt: Date;
449
+ email: string;
450
+ emailVerified: boolean;
451
+ name: string;
452
+ image?: string | null | undefined;
453
+ };
454
+ };
455
+ }>>[];
456
+ body: z.ZodObject<{
457
+ paymentId: z.ZodString;
458
+ }, z.core.$strip>;
459
+ }, {
460
+ status: "already-refunded";
461
+ } | {
462
+ paymentStatus: PaymentStatus;
463
+ legs: PaymentLeg[];
464
+ status: "refund-started";
465
+ reversals: number;
466
+ }>;
467
+ };
468
+ };
469
+
470
+ export { type NuvionPluginOptions, nuvion };