@faire-auth/stripe 1.0.3 → 1.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/.turbo/turbo-build.log +27 -22
- package/dist/client.cjs +3 -5
- package/dist/client.d.cts +2 -24
- package/dist/client.d.mts +2 -24
- package/dist/client.mjs +2 -4
- package/dist/index.cjs +192 -124
- package/dist/index.d.cts +315 -2
- package/dist/index.d.mts +315 -2
- package/dist/index.mjs +128 -59
- package/package.json +12 -12
- package/tsdown.config.ts +10 -8
- package/.turbo/turbo-test.log +0 -1578
- package/.turbo/turbo-typecheck.log +0 -4
- package/dist/index-6UTHxaqg.d.cts +0 -1110
- package/dist/index-CYV4awaB.d.mts +0 -1110
package/dist/index.mjs
CHANGED
|
@@ -3,24 +3,21 @@ import { False, True } from "@faire-auth/core/static";
|
|
|
3
3
|
import { logger } from "faire-auth";
|
|
4
4
|
import { getSessionFromCtx, originCheck, sessionMiddleware } from "faire-auth/middleware";
|
|
5
5
|
import { createEndpoint, createMiddleware } from "faire-auth/plugins";
|
|
6
|
-
import
|
|
6
|
+
import "stripe";
|
|
7
7
|
import * as z from "zod";
|
|
8
8
|
import { mergeSchema } from "faire-auth/db";
|
|
9
|
-
|
|
10
|
-
//#region src/utils.ts
|
|
9
|
+
// src/utils.ts
|
|
11
10
|
async function getPlans(subscriptionOptions) {
|
|
12
11
|
if (subscriptionOptions?.enabled) return typeof subscriptionOptions.plans === "function" ? await subscriptionOptions.plans() : subscriptionOptions.plans;
|
|
13
12
|
throw new Error("Subscriptions are not enabled in the Stripe options.");
|
|
14
13
|
}
|
|
15
14
|
async function getPlanByPriceInfo(options, priceId, priceLookupKey) {
|
|
16
|
-
return await getPlans(options.subscription).then((res
|
|
15
|
+
return await getPlans(options.subscription).then((res) => res?.find((plan) => plan.priceId === priceId || plan.annualDiscountPriceId === priceId || priceLookupKey && (plan.lookupKey === priceLookupKey || plan.annualDiscountLookupKey === priceLookupKey)));
|
|
17
16
|
}
|
|
18
17
|
async function getPlanByName(options, name) {
|
|
19
|
-
return await getPlans(options.subscription).then((res
|
|
18
|
+
return await getPlans(options.subscription).then((res) => res?.find((plan) => plan.name.toLowerCase() === name.toLowerCase()));
|
|
20
19
|
}
|
|
21
|
-
|
|
22
|
-
//#endregion
|
|
23
|
-
//#region src/hooks.ts
|
|
20
|
+
// src/hooks.ts
|
|
24
21
|
async function onCheckoutSessionCompleted(ctx, options, event) {
|
|
25
22
|
try {
|
|
26
23
|
const client = options.stripeClient;
|
|
@@ -184,9 +181,7 @@ async function onSubscriptionDeleted(ctx, options, event) {
|
|
|
184
181
|
logger.error(`Stripe webhook failed. Error: ${error}`);
|
|
185
182
|
}
|
|
186
183
|
}
|
|
187
|
-
|
|
188
|
-
//#endregion
|
|
189
|
-
//#region src/schema.ts
|
|
184
|
+
// src/schema.ts
|
|
190
185
|
const subscriptions = { subscription: { fields: {
|
|
191
186
|
plan: {
|
|
192
187
|
type: "string",
|
|
@@ -246,14 +241,12 @@ const getSchema = (options) => {
|
|
|
246
241
|
};
|
|
247
242
|
else baseSchema = { ...user };
|
|
248
243
|
if (options.schema && !options.subscription?.enabled && "subscription" in options.schema) {
|
|
249
|
-
const { subscription
|
|
244
|
+
const { subscription, ...restSchema } = options.schema;
|
|
250
245
|
return mergeSchema(baseSchema, restSchema);
|
|
251
246
|
}
|
|
252
247
|
return mergeSchema(baseSchema, options.schema);
|
|
253
248
|
};
|
|
254
|
-
|
|
255
|
-
//#endregion
|
|
256
|
-
//#region src/index.ts
|
|
249
|
+
// src/index.ts
|
|
257
250
|
const STRIPE_ERROR_CODES = {
|
|
258
251
|
SUBSCRIPTION_NOT_FOUND: "Subscription not found",
|
|
259
252
|
SUBSCRIPTION_PLAN_NOT_FOUND: "Subscription plan not found",
|
|
@@ -308,6 +301,21 @@ const stripe = (options) => {
|
|
|
308
301
|
return await next();
|
|
309
302
|
});
|
|
310
303
|
const subscriptionEndpoints = {
|
|
304
|
+
/**
|
|
305
|
+
* ### Endpoint
|
|
306
|
+
*
|
|
307
|
+
* POST `/subscription/upgrade`
|
|
308
|
+
*
|
|
309
|
+
* ### API Methods
|
|
310
|
+
*
|
|
311
|
+
* **server:**
|
|
312
|
+
* `auth.api.upgradeSubscription`
|
|
313
|
+
*
|
|
314
|
+
* **client:**
|
|
315
|
+
* `authClient.subscription.upgrade`
|
|
316
|
+
*
|
|
317
|
+
* @see [Read our docs to learn more.](https://faire-auth.com/docs/plugins/stripe#api-method-subscription-upgrade)
|
|
318
|
+
*/
|
|
311
319
|
upgradeSubscription: createEndpoint(createRoute({
|
|
312
320
|
operationId: "upgradeSubscription",
|
|
313
321
|
method: "post",
|
|
@@ -321,15 +329,50 @@ const stripe = (options) => {
|
|
|
321
329
|
referenceMiddleware("upgrade-subscription")
|
|
322
330
|
],
|
|
323
331
|
request: req().bdy(z.object({
|
|
332
|
+
/**
|
|
333
|
+
* The name of the plan to subscribe
|
|
334
|
+
*/
|
|
324
335
|
plan: z.string().meta({ description: "The name of the plan to upgrade to. Eg: \"pro\"" }),
|
|
336
|
+
/**
|
|
337
|
+
* If annual plan should be applied.
|
|
338
|
+
*/
|
|
325
339
|
annual: z.boolean().meta({ description: "Whether to upgrade to an annual plan. Eg: true" }).optional(),
|
|
340
|
+
/**
|
|
341
|
+
* Reference id of the subscription to upgrade
|
|
342
|
+
* This is used to identify the subscription to upgrade
|
|
343
|
+
* If not provided, the user's id will be used
|
|
344
|
+
*/
|
|
326
345
|
referenceId: z.string().meta({ description: "Reference id of the subscription to upgrade. Eg: \"123\"" }).optional(),
|
|
346
|
+
/**
|
|
347
|
+
* This is to allow a specific subscription to be upgrade.
|
|
348
|
+
* If subscription id is provided, and subscription isn't found,
|
|
349
|
+
* it'll throw an error.
|
|
350
|
+
*/
|
|
327
351
|
subscriptionId: z.string().meta({ description: "The id of the subscription to upgrade. Eg: \"sub_123\"" }).optional(),
|
|
352
|
+
/**
|
|
353
|
+
* Any additional data you want to store in your database
|
|
354
|
+
* subscriptions
|
|
355
|
+
*/
|
|
328
356
|
metadata: z.record(z.string(), z.any()).optional(),
|
|
357
|
+
/**
|
|
358
|
+
* If a subscription
|
|
359
|
+
*/
|
|
329
360
|
seats: z.number().meta({ description: "Number of seats to upgrade to (if applicable). Eg: 1" }).optional(),
|
|
361
|
+
/**
|
|
362
|
+
* Success URL to redirect back after successful subscription
|
|
363
|
+
*/
|
|
330
364
|
successUrl: z.string().meta({ description: "Callback URL to redirect back after successful subscription. Eg: \"https://example.com/success\"" }).default("/"),
|
|
365
|
+
/**
|
|
366
|
+
* Cancel URL
|
|
367
|
+
*/
|
|
331
368
|
cancelUrl: z.string().meta({ description: "If set, checkout shows a back button and customers will be directed here if they cancel payment. Eg: \"https://example.com/pricing\"" }).default("/"),
|
|
369
|
+
/**
|
|
370
|
+
* Return URL
|
|
371
|
+
*/
|
|
332
372
|
returnUrl: z.string().meta({ description: "URL to take customers to when they click on the billing portal’s link to return to your website. Eg: \"https://example.com/dashboard\"" }).optional(),
|
|
373
|
+
/**
|
|
374
|
+
* Disable Redirect
|
|
375
|
+
*/
|
|
333
376
|
disableRedirect: z.boolean().meta({ description: "Disable redirect after successful subscription. Eg: true" }).default(false)
|
|
334
377
|
})).bld(),
|
|
335
378
|
responses: res(z.intersection(redirectUrlSchema, z.record(z.string(), z.any()))).err(400).err(401).err(500).bld()
|
|
@@ -338,12 +381,12 @@ const stripe = (options) => {
|
|
|
338
381
|
logger.error(`Subscription actions are not enabled in your stripe plugin config.`);
|
|
339
382
|
return ctx.json({ success: False }, 400);
|
|
340
383
|
}
|
|
341
|
-
const { user
|
|
342
|
-
if (!user
|
|
384
|
+
const { user, session } = ctx.get("session");
|
|
385
|
+
if (!user.emailVerified && options.subscription?.enabled && options.subscription.requireEmailVerification) return ctx.json({
|
|
343
386
|
success: False,
|
|
344
387
|
message: STRIPE_ERROR_CODES.EMAIL_VERIFICATION_REQUIRED
|
|
345
388
|
}, 400);
|
|
346
|
-
const { referenceId = user
|
|
389
|
+
const { referenceId = user.id, plan: requestPlan, subscriptionId, metadata, seats, returnUrl, cancelUrl, disableRedirect, successUrl, annual } = ctx.req.valid("json");
|
|
347
390
|
const plan = await getPlanByName(options, requestPlan);
|
|
348
391
|
if (!plan) return ctx.json({
|
|
349
392
|
success: False,
|
|
@@ -371,18 +414,18 @@ const stripe = (options) => {
|
|
|
371
414
|
success: False,
|
|
372
415
|
message: STRIPE_ERROR_CODES.SUBSCRIPTION_NOT_FOUND
|
|
373
416
|
}, 400);
|
|
374
|
-
let customerId = subscriptionToUpdate?.stripeCustomerId || user
|
|
417
|
+
let customerId = subscriptionToUpdate?.stripeCustomerId || user.stripeCustomerId;
|
|
375
418
|
if (!customerId) try {
|
|
376
419
|
let stripeCustomer = (await client.customers.list({
|
|
377
|
-
email: user
|
|
420
|
+
email: user.email,
|
|
378
421
|
limit: 1
|
|
379
422
|
})).data[0];
|
|
380
423
|
if (!stripeCustomer) stripeCustomer = await client.customers.create({
|
|
381
|
-
email: user
|
|
382
|
-
...user
|
|
424
|
+
email: user.email,
|
|
425
|
+
...user.name && { name: user.name },
|
|
383
426
|
metadata: {
|
|
384
427
|
...metadata,
|
|
385
|
-
userId: user
|
|
428
|
+
userId: user.id
|
|
386
429
|
}
|
|
387
430
|
});
|
|
388
431
|
await ctx.get("context").adapter.update({
|
|
@@ -390,7 +433,7 @@ const stripe = (options) => {
|
|
|
390
433
|
update: { stripeCustomerId: stripeCustomer.id },
|
|
391
434
|
where: [{
|
|
392
435
|
field: "id",
|
|
393
|
-
value: user
|
|
436
|
+
value: user.id
|
|
394
437
|
}]
|
|
395
438
|
});
|
|
396
439
|
customerId = stripeCustomer.id;
|
|
@@ -401,22 +444,22 @@ const stripe = (options) => {
|
|
|
401
444
|
message: STRIPE_ERROR_CODES.UNABLE_TO_CREATE_CUSTOMER
|
|
402
445
|
}, 400);
|
|
403
446
|
}
|
|
404
|
-
const activeSubscription = (await client.subscriptions.list({ customer: customerId }).then((res
|
|
405
|
-
const subscriptions
|
|
447
|
+
const activeSubscription = (await client.subscriptions.list({ customer: customerId }).then((res) => res.data.filter((sub) => sub.status === "active" || sub.status === "trialing"))).find((sub) => subscriptionToUpdate?.stripeSubscriptionId || subscriptionId ? sub.id === subscriptionToUpdate?.stripeSubscriptionId || sub.id === subscriptionId : false);
|
|
448
|
+
const subscriptions = subscriptionToUpdate ? [subscriptionToUpdate] : await ctx.get("context").adapter.findMany({
|
|
406
449
|
model: "subscription",
|
|
407
450
|
where: [{
|
|
408
451
|
field: "referenceId",
|
|
409
|
-
value: referenceId || user
|
|
452
|
+
value: referenceId || user.id
|
|
410
453
|
}]
|
|
411
454
|
});
|
|
412
|
-
const activeOrTrialingSubscription = subscriptions
|
|
413
|
-
const incompleteSubscription = subscriptions
|
|
455
|
+
const activeOrTrialingSubscription = subscriptions.find((sub) => sub.status === "active" || sub.status === "trialing");
|
|
456
|
+
const incompleteSubscription = subscriptions.find((sub) => sub.status === "incomplete");
|
|
414
457
|
if (activeOrTrialingSubscription && activeOrTrialingSubscription.status === "active" && activeOrTrialingSubscription.plan === requestPlan && activeOrTrialingSubscription.seats === (seats || 1)) return ctx.json({
|
|
415
458
|
success: False,
|
|
416
459
|
message: STRIPE_ERROR_CODES.ALREADY_SUBSCRIBED_PLAN
|
|
417
460
|
}, 400);
|
|
418
461
|
if (activeSubscription && customerId) {
|
|
419
|
-
const res
|
|
462
|
+
const res = await client.billingPortal.sessions.create({
|
|
420
463
|
customer: customerId,
|
|
421
464
|
return_url: getUrl(authOptions, returnUrl || "/"),
|
|
422
465
|
flow_data: {
|
|
@@ -439,9 +482,9 @@ const stripe = (options) => {
|
|
|
439
482
|
message: e.message,
|
|
440
483
|
code: e.code
|
|
441
484
|
}, 400));
|
|
442
|
-
if (res
|
|
485
|
+
if (res instanceof Response) return res;
|
|
443
486
|
return ctx.json({
|
|
444
|
-
url: res
|
|
487
|
+
url: res.url,
|
|
445
488
|
redirect: True
|
|
446
489
|
}, 200);
|
|
447
490
|
}
|
|
@@ -473,12 +516,12 @@ const stripe = (options) => {
|
|
|
473
516
|
return ctx.json({ success: False }, 500);
|
|
474
517
|
}
|
|
475
518
|
const params = await options.subscription?.getCheckoutSessionParams?.({
|
|
476
|
-
user
|
|
519
|
+
user,
|
|
477
520
|
session,
|
|
478
521
|
plan,
|
|
479
522
|
subscription
|
|
480
523
|
}, ctx);
|
|
481
|
-
const freeTrial = !subscriptions
|
|
524
|
+
const freeTrial = !subscriptions.some((s) => {
|
|
482
525
|
return !!(s.trialStart || s.trialEnd) || s.status === "trialing";
|
|
483
526
|
}) && plan.freeTrial ? { trial_period_days: plan.freeTrial.days } : void 0;
|
|
484
527
|
let priceIdToUse = void 0;
|
|
@@ -496,7 +539,7 @@ const stripe = (options) => {
|
|
|
496
539
|
name: "auto",
|
|
497
540
|
address: "auto"
|
|
498
541
|
}
|
|
499
|
-
} : { customer_email: user
|
|
542
|
+
} : { customer_email: user.email },
|
|
500
543
|
success_url: getUrl(authOptions, `${ctx.get("context").baseURL}/subscription/success?callbackURL=${encodeURIComponent(successUrl)}&subscriptionId=${encodeURIComponent(subscription.id)}`),
|
|
501
544
|
cancel_url: getUrl(authOptions, cancelUrl),
|
|
502
545
|
line_items: [{
|
|
@@ -508,7 +551,7 @@ const stripe = (options) => {
|
|
|
508
551
|
client_reference_id: referenceId,
|
|
509
552
|
...params?.params,
|
|
510
553
|
metadata: {
|
|
511
|
-
userId: user
|
|
554
|
+
userId: user.id,
|
|
512
555
|
subscriptionId: subscription.id,
|
|
513
556
|
referenceId,
|
|
514
557
|
...params?.params?.metadata
|
|
@@ -580,6 +623,21 @@ const stripe = (options) => {
|
|
|
580
623
|
}
|
|
581
624
|
return ctx.redirect(getUrl(authOptions, callbackURL), 302);
|
|
582
625
|
}),
|
|
626
|
+
/**
|
|
627
|
+
* ### Endpoint
|
|
628
|
+
*
|
|
629
|
+
* POST `/subscription/cancel`
|
|
630
|
+
*
|
|
631
|
+
* ### API Methods
|
|
632
|
+
*
|
|
633
|
+
* **server:**
|
|
634
|
+
* `auth.api.cancelSubscription`
|
|
635
|
+
*
|
|
636
|
+
* **client:**
|
|
637
|
+
* `authClient.subscription.cancel`
|
|
638
|
+
*
|
|
639
|
+
* @see [Read our docs to learn more.](https://faire-auth.com/docs/plugins/stripe#api-method-subscription-cancel)
|
|
640
|
+
*/
|
|
583
641
|
cancelSubscription: createEndpoint(createRoute({
|
|
584
642
|
operationId: "cancelSubscription",
|
|
585
643
|
method: "post",
|
|
@@ -618,7 +676,7 @@ const stripe = (options) => {
|
|
|
618
676
|
success: False,
|
|
619
677
|
message: STRIPE_ERROR_CODES.SUBSCRIPTION_NOT_FOUND
|
|
620
678
|
}, 400);
|
|
621
|
-
const activeSubscriptions = await client.subscriptions.list({ customer: subscription.stripeCustomerId }).then((res
|
|
679
|
+
const activeSubscriptions = await client.subscriptions.list({ customer: subscription.stripeCustomerId }).then((res) => res.data.filter((sub) => sub.status === "active" || sub.status === "trialing"));
|
|
622
680
|
if (!activeSubscriptions.length) {
|
|
623
681
|
/**
|
|
624
682
|
* If the subscription is not found, we need to delete the subscription
|
|
@@ -641,7 +699,7 @@ const stripe = (options) => {
|
|
|
641
699
|
success: False,
|
|
642
700
|
message: STRIPE_ERROR_CODES.SUBSCRIPTION_NOT_FOUND
|
|
643
701
|
}, 400);
|
|
644
|
-
const res
|
|
702
|
+
const res = await client.billingPortal.sessions.create({
|
|
645
703
|
customer: subscription.stripeCustomerId,
|
|
646
704
|
return_url: getUrl(authOptions, `${ctx.get("context").baseURL}/subscription/cancel/callback?callbackURL=${encodeURIComponent(returnUrl || "/")}&subscriptionId=${encodeURIComponent(subscription.id)}`),
|
|
647
705
|
flow_data: {
|
|
@@ -669,9 +727,9 @@ const stripe = (options) => {
|
|
|
669
727
|
code: e.code
|
|
670
728
|
}, 400);
|
|
671
729
|
});
|
|
672
|
-
if (res
|
|
730
|
+
if (res instanceof Response) return res;
|
|
673
731
|
return ctx.json({
|
|
674
|
-
url: res
|
|
732
|
+
url: res.url,
|
|
675
733
|
redirect: True
|
|
676
734
|
}, 200);
|
|
677
735
|
}),
|
|
@@ -713,7 +771,7 @@ const stripe = (options) => {
|
|
|
713
771
|
success: False,
|
|
714
772
|
message: STRIPE_ERROR_CODES.SUBSCRIPTION_NOT_SCHEDULED_FOR_CANCELLATION
|
|
715
773
|
}, 400);
|
|
716
|
-
const activeSubscription = await client.subscriptions.list({ customer: subscription.stripeCustomerId }).then((res
|
|
774
|
+
const activeSubscription = await client.subscriptions.list({ customer: subscription.stripeCustomerId }).then((res) => res.data.filter((sub) => sub.status === "active" || sub.status === "trialing")[0]);
|
|
717
775
|
if (!activeSubscription) return ctx.json({
|
|
718
776
|
success: False,
|
|
719
777
|
message: STRIPE_ERROR_CODES.SUBSCRIPTION_NOT_FOUND
|
|
@@ -740,6 +798,21 @@ const stripe = (options) => {
|
|
|
740
798
|
}, 400);
|
|
741
799
|
}
|
|
742
800
|
}),
|
|
801
|
+
/**
|
|
802
|
+
* ### Endpoint
|
|
803
|
+
*
|
|
804
|
+
* GET `/subscription/list`
|
|
805
|
+
*
|
|
806
|
+
* ### API Methods
|
|
807
|
+
*
|
|
808
|
+
* **server:**
|
|
809
|
+
* `auth.api.listActiveSubscriptions`
|
|
810
|
+
*
|
|
811
|
+
* **client:**
|
|
812
|
+
* `authClient.subscription.list`
|
|
813
|
+
*
|
|
814
|
+
* @see [Read our docs to learn more.](https://faire-auth.com/docs/plugins/stripe#api-method-subscription-list)
|
|
815
|
+
*/
|
|
743
816
|
listActiveSubscriptions: createEndpoint(createRoute({
|
|
744
817
|
operationId: "listActiveSubscriptions",
|
|
745
818
|
method: "get",
|
|
@@ -754,17 +827,17 @@ const stripe = (options) => {
|
|
|
754
827
|
}
|
|
755
828
|
const session = ctx.get("session");
|
|
756
829
|
const { referenceId = session.user.id } = ctx.req.valid("query");
|
|
757
|
-
const subscriptions
|
|
830
|
+
const subscriptions = await ctx.get("context").adapter.findMany({
|
|
758
831
|
model: "subscription",
|
|
759
832
|
where: [{
|
|
760
833
|
field: "referenceId",
|
|
761
834
|
value: referenceId
|
|
762
835
|
}]
|
|
763
836
|
});
|
|
764
|
-
if (!subscriptions
|
|
837
|
+
if (!subscriptions.length) return ctx.json([], 200);
|
|
765
838
|
const plans = await getPlans(options.subscription);
|
|
766
839
|
if (!plans) return ctx.json([], 200);
|
|
767
|
-
const subs = subscriptions
|
|
840
|
+
const subs = subscriptions.map((sub) => {
|
|
768
841
|
const plan = plans.find((p) => p.name.toLowerCase() === sub.plan.toLowerCase());
|
|
769
842
|
return {
|
|
770
843
|
...sub,
|
|
@@ -802,7 +875,7 @@ const stripe = (options) => {
|
|
|
802
875
|
const stripeSubscription = await client.subscriptions.list({
|
|
803
876
|
customer: customerId,
|
|
804
877
|
status: "active"
|
|
805
|
-
}).then((res
|
|
878
|
+
}).then((res) => res.data[0]);
|
|
806
879
|
if (stripeSubscription) {
|
|
807
880
|
const firstItem = stripeSubscription.items.data[0];
|
|
808
881
|
if (firstItem) {
|
|
@@ -929,9 +1002,7 @@ const stripe = (options) => {
|
|
|
929
1002
|
await onSubscriptionDeleted(ctx, options, event);
|
|
930
1003
|
await options.onEvent?.(event);
|
|
931
1004
|
break;
|
|
932
|
-
default:
|
|
933
|
-
await options.onEvent?.(event);
|
|
934
|
-
break;
|
|
1005
|
+
default: await options.onEvent?.(event);
|
|
935
1006
|
}
|
|
936
1007
|
} catch (e) {
|
|
937
1008
|
ctx.get("context").logger.error(`Stripe webhook failed. Error: ${e.message}`);
|
|
@@ -945,24 +1016,22 @@ const stripe = (options) => {
|
|
|
945
1016
|
...options.subscription?.enabled ? subscriptionEndpoints : {}
|
|
946
1017
|
},
|
|
947
1018
|
init(ctx) {
|
|
948
|
-
return { options: { databaseHooks: { user: { create: { async after(user
|
|
949
|
-
if (ctx
|
|
1019
|
+
return { options: { databaseHooks: { user: { create: { async after(user, ctx) {
|
|
1020
|
+
if (ctx && options.createCustomerOnSignUp) {
|
|
950
1021
|
const stripeCustomer = await client.customers.create({
|
|
951
|
-
email: user
|
|
952
|
-
...user
|
|
953
|
-
metadata: { userId: user
|
|
1022
|
+
email: user.email,
|
|
1023
|
+
...user.name && { name: user.name },
|
|
1024
|
+
metadata: { userId: user.id }
|
|
954
1025
|
});
|
|
955
|
-
if (!await ctx
|
|
1026
|
+
if (!await ctx.get("context").internalAdapter.updateUser(user.id, { stripeCustomerId: stripeCustomer.id })) logger.error("#FAIRE_AUTH: Failed to create customer");
|
|
956
1027
|
else if (options.onCustomerCreate) await options.onCustomerCreate({
|
|
957
1028
|
stripeCustomer,
|
|
958
|
-
user
|
|
959
|
-
}, ctx
|
|
1029
|
+
user
|
|
1030
|
+
}, ctx);
|
|
960
1031
|
}
|
|
961
1032
|
} } } } } };
|
|
962
1033
|
},
|
|
963
1034
|
schema: getSchema(options)
|
|
964
1035
|
};
|
|
965
1036
|
};
|
|
966
|
-
|
|
967
|
-
//#endregion
|
|
968
|
-
export { stripe };
|
|
1037
|
+
export { stripe };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@faire-auth/stripe",
|
|
3
3
|
"author": "Bereket Engida",
|
|
4
|
-
"version": "1.0
|
|
4
|
+
"version": "1.1.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"keywords": [
|
|
@@ -44,21 +44,21 @@
|
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
},
|
|
47
|
-
"
|
|
48
|
-
"
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"hono": "^4.13.16",
|
|
49
|
+
"publint": "^0.3.25",
|
|
50
|
+
"stripe": "^18.5.0",
|
|
51
|
+
"tsdown": "^0.23.7",
|
|
52
|
+
"zod": "^4.6.7",
|
|
53
|
+
"@faire-auth/core": "1.1.0",
|
|
54
|
+
"faire-auth": "1.1.0"
|
|
49
55
|
},
|
|
50
56
|
"peerDependencies": {
|
|
51
57
|
"stripe": "^18 || ^19",
|
|
52
58
|
"hono": ">=4.3.6",
|
|
53
|
-
"
|
|
54
|
-
"faire-auth": "1.0
|
|
55
|
-
|
|
56
|
-
"devDependencies": {
|
|
57
|
-
"stripe": "^18.5.0",
|
|
58
|
-
"tsdown": "^0.16.0",
|
|
59
|
-
"publint": "^0.3.15",
|
|
60
|
-
"@faire-auth/core": "1.0.3",
|
|
61
|
-
"faire-auth": "1.0.3"
|
|
59
|
+
"zod": "^4.1.12",
|
|
60
|
+
"@faire-auth/core": "1.1.0",
|
|
61
|
+
"faire-auth": "1.1.0"
|
|
62
62
|
},
|
|
63
63
|
"scripts": {
|
|
64
64
|
"test": "vitest",
|
package/tsdown.config.ts
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import { defineConfig } from "tsdown";
|
|
2
2
|
|
|
3
3
|
export default defineConfig({
|
|
4
|
-
dts: { build: true, incremental: true },
|
|
4
|
+
dts: { tsc: { build: true, incremental: true } },
|
|
5
5
|
format: ["esm", "cjs"],
|
|
6
6
|
entry: ["./src/index.ts", "./src/client.ts"],
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
deps: {
|
|
8
|
+
neverBundle: [
|
|
9
|
+
"faire-auth",
|
|
10
|
+
"better-call",
|
|
11
|
+
"@better-fetch/fetch",
|
|
12
|
+
"stripe",
|
|
13
|
+
"hono",
|
|
14
|
+
],
|
|
15
|
+
},
|
|
14
16
|
nodeProtocol: true,
|
|
15
17
|
publint: true,
|
|
16
18
|
});
|