@better-auth/stripe 1.5.0-beta.6 → 1.5.0-beta.7

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,5 +1,5 @@
1
1
 
2
- > @better-auth/stripe@1.5.0-beta.6 build /home/runner/work/better-auth/better-auth/packages/stripe
2
+ > @better-auth/stripe@1.5.0-beta.7 build /home/runner/work/better-auth/better-auth/packages/stripe
3
3
  > tsdown
4
4
 
5
5
  ℹ tsdown v0.19.0 powered by rolldown v1.0.0-beta.59
@@ -12,6 +12,6 @@
12
12
  ℹ dist/error-codes-Clj-xYDP.mjs  1.62 kB │ gzip: 0.75 kB
13
13
  ℹ dist/client.d.mts  6.71 kB │ gzip: 1.32 kB
14
14
  ℹ dist/index.d.mts  0.21 kB │ gzip: 0.14 kB
15
- ℹ dist/index-BnHmwMru.d.mts 30.07 kB │ gzip: 5.20 kB
16
- ℹ 6 files, total: 94.90 kB
17
- ✔ Build complete in 23791ms
15
+ ℹ dist/index-CkImGy5x.d.mts 31.76 kB │ gzip: 5.34 kB
16
+ ℹ 6 files, total: 96.59 kB
17
+ ✔ Build complete in 21218ms
package/dist/client.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { n as stripe } from "./index-BnHmwMru.mjs";
1
+ import { n as stripe } from "./index-CkImGy5x.mjs";
2
2
 
3
3
  //#region src/error-codes.d.ts
4
4
  declare const STRIPE_ERROR_CODES: {
@@ -836,7 +836,91 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
836
836
  };
837
837
  };
838
838
  } | undefined;
839
- schema: {};
839
+ schema: {
840
+ user: {
841
+ fields: {
842
+ stripeCustomerId: {
843
+ type: "string";
844
+ required: false;
845
+ };
846
+ };
847
+ };
848
+ } & (O["subscription"] extends {
849
+ enabled: true;
850
+ } ? {
851
+ subscription: {
852
+ fields: {
853
+ plan: {
854
+ type: "string";
855
+ required: true;
856
+ };
857
+ referenceId: {
858
+ type: "string";
859
+ required: true;
860
+ };
861
+ stripeCustomerId: {
862
+ type: "string";
863
+ required: false;
864
+ };
865
+ stripeSubscriptionId: {
866
+ type: "string";
867
+ required: false;
868
+ };
869
+ status: {
870
+ type: "string";
871
+ defaultValue: string;
872
+ };
873
+ periodStart: {
874
+ type: "date";
875
+ required: false;
876
+ };
877
+ periodEnd: {
878
+ type: "date";
879
+ required: false;
880
+ };
881
+ trialStart: {
882
+ type: "date";
883
+ required: false;
884
+ };
885
+ trialEnd: {
886
+ type: "date";
887
+ required: false;
888
+ };
889
+ cancelAtPeriodEnd: {
890
+ type: "boolean";
891
+ required: false;
892
+ defaultValue: false;
893
+ };
894
+ cancelAt: {
895
+ type: "date";
896
+ required: false;
897
+ };
898
+ canceledAt: {
899
+ type: "date";
900
+ required: false;
901
+ };
902
+ endedAt: {
903
+ type: "date";
904
+ required: false;
905
+ };
906
+ seats: {
907
+ type: "number";
908
+ required: false;
909
+ };
910
+ };
911
+ };
912
+ } : {}) & (O["organization"] extends {
913
+ enabled: true;
914
+ } ? {
915
+ organization: {
916
+ fields: {
917
+ stripeCustomerId: {
918
+ type: "string";
919
+ required: false;
920
+ };
921
+ };
922
+ };
923
+ } : {});
840
924
  options: NoInfer<O>;
841
925
  $ERROR_CODES: {
842
926
  readonly UNAUTHORIZED: {
package/dist/index.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { a as SubscriptionOptions, i as Subscription, n as stripe, r as StripePlan, t as StripePlugin } from "./index-BnHmwMru.mjs";
1
+ import { a as SubscriptionOptions, i as Subscription, n as stripe, r as StripePlan, t as StripePlugin } from "./index-CkImGy5x.mjs";
2
2
  export { StripePlan, StripePlugin, Subscription, SubscriptionOptions, stripe };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@better-auth/stripe",
3
3
  "author": "Bereket Engida",
4
- "version": "1.5.0-beta.6",
4
+ "version": "1.5.0-beta.7",
5
5
  "type": "module",
6
6
  "main": "dist/index.mjs",
7
7
  "types": "dist/index.d.mts",
@@ -50,15 +50,15 @@
50
50
  },
51
51
  "peerDependencies": {
52
52
  "stripe": "^18 || ^19 || ^20",
53
- "@better-auth/core": "1.5.0-beta.6",
54
- "better-auth": "1.5.0-beta.6"
53
+ "@better-auth/core": "1.5.0-beta.7",
54
+ "better-auth": "1.5.0-beta.7"
55
55
  },
56
56
  "devDependencies": {
57
57
  "better-call": "1.1.8",
58
58
  "stripe": "^20.0.0",
59
59
  "tsdown": "^0.19.0",
60
- "@better-auth/core": "1.5.0-beta.6",
61
- "better-auth": "1.5.0-beta.6"
60
+ "@better-auth/core": "1.5.0-beta.7",
61
+ "better-auth": "1.5.0-beta.7"
62
62
  },
63
63
  "scripts": {
64
64
  "test": "vitest",
package/src/routes.ts CHANGED
@@ -162,7 +162,7 @@ const upgradeSubscriptionBodySchema = z.object({
162
162
  })
163
163
  .optional(),
164
164
  /**
165
- * Success URL to redirect back after successful subscription
165
+ * The URL to which Stripe should send customers when payment or setup is complete.
166
166
  */
167
167
  successUrl: z
168
168
  .string()
@@ -172,7 +172,7 @@ const upgradeSubscriptionBodySchema = z.object({
172
172
  })
173
173
  .default("/"),
174
174
  /**
175
- * Cancel URL
175
+ * If set, checkout shows a back button and customers will be directed here if they cancel payment.
176
176
  */
177
177
  cancelUrl: z
178
178
  .string()
@@ -182,7 +182,7 @@ const upgradeSubscriptionBodySchema = z.object({
182
182
  })
183
183
  .default("/"),
184
184
  /**
185
- * Return URL
185
+ * The URL to return to from the Billing Portal (used when upgrading existing subscriptions)
186
186
  */
187
187
  returnUrl: z
188
188
  .string()
package/src/schema.ts CHANGED
@@ -88,8 +88,14 @@ export const organization = {
88
88
  },
89
89
  } satisfies BetterAuthPluginDBSchema;
90
90
 
91
- export const getSchema = (options: StripeOptions) => {
92
- let baseSchema = {};
91
+ type GetSchemaResult<O extends StripeOptions> = typeof user &
92
+ (O["subscription"] extends { enabled: true } ? typeof subscriptions : {}) &
93
+ (O["organization"] extends { enabled: true } ? typeof organization : {});
94
+
95
+ export const getSchema = <O extends StripeOptions>(
96
+ options: O,
97
+ ): GetSchemaResult<O> => {
98
+ let baseSchema: BetterAuthPluginDBSchema = {};
93
99
 
94
100
  if (options.subscription?.enabled) {
95
101
  baseSchema = {
@@ -115,8 +121,8 @@ export const getSchema = (options: StripeOptions) => {
115
121
  "subscription" in options.schema
116
122
  ) {
117
123
  const { subscription: _subscription, ...restSchema } = options.schema;
118
- return mergeSchema(baseSchema, restSchema);
124
+ return mergeSchema(baseSchema, restSchema) as GetSchemaResult<O>;
119
125
  }
120
126
 
121
- return mergeSchema(baseSchema, options.schema);
127
+ return mergeSchema(baseSchema, options.schema) as GetSchemaResult<O>;
122
128
  };
@@ -58,6 +58,45 @@ describe("stripe type", () => {
58
58
  expectTypeOf<MyAuth["api"]["upgradeSubscription"]>().toBeFunction();
59
59
  expectTypeOf<MyAuth["api"]["createBillingPortal"]>().toBeFunction();
60
60
  });
61
+
62
+ it("should infer plugin schema fields on user type", async () => {
63
+ const { auth } = await getTestInstance({
64
+ plugins: [
65
+ stripe({
66
+ stripeClient: {} as Stripe,
67
+ stripeWebhookSecret: "test",
68
+ }),
69
+ ],
70
+ });
71
+ expectTypeOf<
72
+ (typeof auth)["$Infer"]["Session"]["user"]["stripeCustomerId"]
73
+ >().toEqualTypeOf<string | null | undefined>();
74
+ });
75
+
76
+ it("should infer plugin schema fields alongside additional user fields", async () => {
77
+ const { auth } = await getTestInstance({
78
+ plugins: [
79
+ stripe({
80
+ stripeClient: {} as Stripe,
81
+ stripeWebhookSecret: "test",
82
+ }),
83
+ ],
84
+ user: {
85
+ additionalFields: {
86
+ customField: {
87
+ type: "string",
88
+ required: false,
89
+ },
90
+ },
91
+ },
92
+ });
93
+ expectTypeOf<
94
+ (typeof auth)["$Infer"]["Session"]["user"]["stripeCustomerId"]
95
+ >().toEqualTypeOf<string | null | undefined>();
96
+ expectTypeOf<
97
+ (typeof auth)["$Infer"]["Session"]["user"]["customField"]
98
+ >().toEqualTypeOf<string | null | undefined>();
99
+ });
61
100
  });
62
101
 
63
102
  describe("stripe", () => {