@polar-sh/better-auth 0.0.2

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/dist/index.js ADDED
@@ -0,0 +1,411 @@
1
+ // src/endpoints/checkout.ts
2
+ import { APIError, getSessionFromCtx } from "better-auth/api";
3
+ import { createAuthEndpoint } from "better-auth/plugins";
4
+ import { z } from "zod";
5
+ var checkout = (options) => createAuthEndpoint(
6
+ "/checkout/:slug",
7
+ {
8
+ method: "GET",
9
+ query: z.object({
10
+ productId: z.string().optional()
11
+ })
12
+ },
13
+ async (ctx) => {
14
+ if (!options.checkout?.enabled) {
15
+ throw new APIError("BAD_REQUEST", {
16
+ message: "Checkout is not enabled"
17
+ });
18
+ }
19
+ let productId = ctx.query?.productId;
20
+ if (ctx.params.slug) {
21
+ const products = await (typeof options.checkout.products === "function" ? options.checkout.products() : options.checkout.products);
22
+ productId = products.find(
23
+ (product) => product.slug === ctx.params.slug
24
+ )?.productId;
25
+ }
26
+ if (!productId) {
27
+ throw new APIError("BAD_REQUEST", {
28
+ message: "Product Id not found"
29
+ });
30
+ }
31
+ const session = await getSessionFromCtx(ctx);
32
+ try {
33
+ const checkout2 = await options.client.checkouts.create({
34
+ customerExternalId: session?.user.id,
35
+ productId,
36
+ successUrl: options.checkout.successUrl ? new URL(options.checkout.successUrl, ctx.request?.url).toString() : void 0
37
+ });
38
+ return ctx.redirect(checkout2.url);
39
+ } catch (e) {
40
+ if (e instanceof Error) {
41
+ ctx.context.logger.error(
42
+ `Polar checkout creation failed. Error: ${e.message}`
43
+ );
44
+ }
45
+ throw new APIError("INTERNAL_SERVER_ERROR", {
46
+ message: "Checkout creation failed"
47
+ });
48
+ }
49
+ }
50
+ );
51
+
52
+ // src/endpoints/customerPortal.ts
53
+ import { APIError as APIError2, sessionMiddleware } from "better-auth/api";
54
+ import { createAuthEndpoint as createAuthEndpoint2 } from "better-auth/plugins";
55
+ var customerPortal = (options) => createAuthEndpoint2(
56
+ "/portal",
57
+ {
58
+ method: "GET",
59
+ use: [sessionMiddleware]
60
+ },
61
+ async (ctx) => {
62
+ if (!options.enableCustomerPortal) {
63
+ throw new APIError2("BAD_REQUEST", {
64
+ message: "Customer portal is not enabled"
65
+ });
66
+ }
67
+ if (!ctx.context.session?.user.id) {
68
+ throw new APIError2("BAD_REQUEST", {
69
+ message: "User not found"
70
+ });
71
+ }
72
+ try {
73
+ const customerSession = await options.client.customerSessions.create({
74
+ customerExternalId: ctx.context.session?.user.id
75
+ });
76
+ return ctx.redirect(customerSession.customerPortalUrl);
77
+ } catch (e) {
78
+ if (e instanceof Error) {
79
+ ctx.context.logger.error(
80
+ `Polar customer portal creation failed. Error: ${e.message}`
81
+ );
82
+ }
83
+ throw new APIError2("INTERNAL_SERVER_ERROR", {
84
+ message: "Customer portal creation failed"
85
+ });
86
+ }
87
+ }
88
+ );
89
+
90
+ // src/endpoints/subscriptions.ts
91
+ import { APIError as APIError3, sessionMiddleware as sessionMiddleware2 } from "better-auth/api";
92
+ import { createAuthEndpoint as createAuthEndpoint3 } from "better-auth/plugins";
93
+ var subscriptions = (options) => createAuthEndpoint3(
94
+ "/subscriptions/list",
95
+ {
96
+ method: "GET",
97
+ use: [sessionMiddleware2]
98
+ },
99
+ async (ctx) => {
100
+ if (!ctx.context.session.user.id) {
101
+ throw new APIError3("BAD_REQUEST", {
102
+ message: "User not found"
103
+ });
104
+ }
105
+ try {
106
+ const { token } = await options.client.customerSessions.create({
107
+ customerExternalId: ctx.context.session?.user.id
108
+ });
109
+ const subscriptions2 = await options.client.customerPortal.subscriptions.list(
110
+ {
111
+ customerSession: token
112
+ },
113
+ {
114
+ active: true
115
+ }
116
+ );
117
+ return ctx.json(subscriptions2);
118
+ } catch (e) {
119
+ if (e instanceof Error) {
120
+ ctx.context.logger.error(
121
+ `Polar subscriptions list failed. Error: ${e.message}`
122
+ );
123
+ }
124
+ throw new APIError3("INTERNAL_SERVER_ERROR", {
125
+ message: "Subscriptions list failed"
126
+ });
127
+ }
128
+ }
129
+ );
130
+
131
+ // src/endpoints/webhooks.ts
132
+ import { validateEvent } from "@polar-sh/sdk/webhooks.js";
133
+ import { APIError as APIError4 } from "better-auth/api";
134
+ import { createAuthEndpoint as createAuthEndpoint4 } from "better-auth/plugins";
135
+ var webhooks = (options) => createAuthEndpoint4(
136
+ "/polar/webhooks",
137
+ {
138
+ method: "POST",
139
+ metadata: {
140
+ isAction: false
141
+ },
142
+ cloneRequest: true
143
+ },
144
+ async (ctx) => {
145
+ const { webhooks: webhooks2 } = options;
146
+ if (!webhooks2) {
147
+ throw new APIError4("NOT_FOUND", {
148
+ message: "Webhooks not enabled"
149
+ });
150
+ }
151
+ const {
152
+ secret,
153
+ onPayload,
154
+ onCheckoutCreated,
155
+ onCheckoutUpdated,
156
+ onOrderCreated,
157
+ onOrderRefunded,
158
+ onRefundCreated,
159
+ onRefundUpdated,
160
+ onSubscriptionCreated,
161
+ onSubscriptionUpdated,
162
+ onSubscriptionActive,
163
+ onSubscriptionCanceled,
164
+ onSubscriptionRevoked,
165
+ onSubscriptionUncanceled,
166
+ onProductCreated,
167
+ onProductUpdated,
168
+ onOrganizationUpdated,
169
+ onBenefitCreated,
170
+ onBenefitUpdated,
171
+ onBenefitGrantCreated,
172
+ onBenefitGrantUpdated,
173
+ onBenefitGrantRevoked
174
+ } = webhooks2;
175
+ if (!ctx.request?.body) {
176
+ throw new APIError4("INTERNAL_SERVER_ERROR");
177
+ }
178
+ const buf = await ctx.request.text();
179
+ let event;
180
+ try {
181
+ if (!secret) {
182
+ throw new APIError4("INTERNAL_SERVER_ERROR", {
183
+ message: "Polar webhook secret not found"
184
+ });
185
+ }
186
+ const headers = {
187
+ "webhook-id": ctx.request.headers.get("webhook-id"),
188
+ "webhook-timestamp": ctx.request.headers.get(
189
+ "webhook-timestamp"
190
+ ),
191
+ "webhook-signature": ctx.request.headers.get(
192
+ "webhook-signature"
193
+ )
194
+ };
195
+ event = validateEvent(buf, headers, secret);
196
+ } catch (err) {
197
+ if (err instanceof Error) {
198
+ ctx.context.logger.error(`${err.message}`);
199
+ throw new APIError4("BAD_REQUEST", {
200
+ message: `Webhook Error: ${err.message}`
201
+ });
202
+ }
203
+ throw new APIError4("BAD_REQUEST", {
204
+ message: `Webhook Error: ${err}`
205
+ });
206
+ }
207
+ try {
208
+ if (onPayload) {
209
+ onPayload(event);
210
+ }
211
+ switch (event.type) {
212
+ case "checkout.created":
213
+ if (onCheckoutCreated) {
214
+ onCheckoutCreated(event);
215
+ }
216
+ break;
217
+ case "checkout.updated":
218
+ if (onCheckoutUpdated) {
219
+ onCheckoutUpdated(event);
220
+ }
221
+ break;
222
+ case "order.created":
223
+ if (onOrderCreated) {
224
+ onOrderCreated(event);
225
+ }
226
+ break;
227
+ case "subscription.created":
228
+ if (onSubscriptionCreated) {
229
+ onSubscriptionCreated(event);
230
+ }
231
+ break;
232
+ case "subscription.updated":
233
+ if (onSubscriptionUpdated) {
234
+ onSubscriptionUpdated(event);
235
+ }
236
+ break;
237
+ case "subscription.active":
238
+ if (onSubscriptionActive) {
239
+ onSubscriptionActive(event);
240
+ }
241
+ break;
242
+ case "subscription.canceled":
243
+ if (onSubscriptionCanceled) {
244
+ onSubscriptionCanceled(event);
245
+ }
246
+ break;
247
+ case "subscription.uncanceled":
248
+ if (onSubscriptionUncanceled) {
249
+ onSubscriptionUncanceled(event);
250
+ }
251
+ break;
252
+ case "subscription.revoked":
253
+ if (onSubscriptionRevoked) {
254
+ onSubscriptionRevoked(event);
255
+ }
256
+ break;
257
+ case "product.created":
258
+ if (onProductCreated) {
259
+ onProductCreated(event);
260
+ }
261
+ break;
262
+ case "product.updated":
263
+ if (onProductUpdated) {
264
+ onProductUpdated(event);
265
+ }
266
+ break;
267
+ case "organization.updated":
268
+ if (onOrganizationUpdated) {
269
+ onOrganizationUpdated(event);
270
+ }
271
+ break;
272
+ case "benefit.created":
273
+ if (onBenefitCreated) {
274
+ onBenefitCreated(event);
275
+ }
276
+ break;
277
+ case "benefit.updated":
278
+ if (onBenefitUpdated) {
279
+ onBenefitUpdated(event);
280
+ }
281
+ break;
282
+ case "benefit_grant.created":
283
+ if (onBenefitGrantCreated) {
284
+ onBenefitGrantCreated(event);
285
+ }
286
+ break;
287
+ case "benefit_grant.updated":
288
+ if (onBenefitGrantUpdated) {
289
+ onBenefitGrantUpdated(event);
290
+ }
291
+ break;
292
+ case "benefit_grant.revoked":
293
+ if (onBenefitGrantRevoked) {
294
+ onBenefitGrantRevoked(event);
295
+ }
296
+ break;
297
+ case "order.refunded":
298
+ if (onOrderRefunded) {
299
+ onOrderRefunded(event);
300
+ }
301
+ break;
302
+ case "refund.created":
303
+ if (onRefundCreated) {
304
+ onRefundCreated(event);
305
+ }
306
+ break;
307
+ case "refund.updated":
308
+ if (onRefundUpdated) {
309
+ onRefundUpdated(event);
310
+ }
311
+ break;
312
+ }
313
+ } catch (e) {
314
+ if (e instanceof Error) {
315
+ ctx.context.logger.error(`Polar webhook failed. Error: ${e.message}`);
316
+ } else {
317
+ ctx.context.logger.error(`Polar webhook failed. Error: ${e}`);
318
+ }
319
+ throw new APIError4("BAD_REQUEST", {
320
+ message: "Webhook error: See server logs for more information."
321
+ });
322
+ }
323
+ return ctx.json({ received: true });
324
+ }
325
+ );
326
+
327
+ // src/hooks/customer.ts
328
+ import { APIError as APIError5 } from "better-auth/api";
329
+ var onUserCreate = (options) => async (user, ctx) => {
330
+ if (ctx && options.createCustomerOnSignUp) {
331
+ try {
332
+ const params = options.getCustomerCreateParams && ctx.context.session ? await options.getCustomerCreateParams({
333
+ user,
334
+ session: ctx.context.session.session
335
+ }) : {};
336
+ await options.client.customers.create({
337
+ ...params,
338
+ email: user.email,
339
+ name: user.name,
340
+ externalId: user.id
341
+ });
342
+ } catch (e) {
343
+ if (e instanceof Error) {
344
+ ctx.context.logger.error(
345
+ `Polar customer creation failed. Error: ${e.message}`
346
+ );
347
+ } else {
348
+ ctx.context.logger.error(
349
+ `Polar customer creation failed. Error: ${e}`
350
+ );
351
+ }
352
+ throw new APIError5("BAD_REQUEST", {
353
+ message: "Polar customer creation failed. See server logs for more information."
354
+ });
355
+ }
356
+ }
357
+ };
358
+ var onUserUpdate = (options) => async (user, ctx) => {
359
+ if (ctx && options.createCustomerOnSignUp) {
360
+ try {
361
+ await options.client.customers.updateExternal({
362
+ externalId: user.id,
363
+ customerUpdate: {
364
+ email: user.email,
365
+ name: user.name
366
+ }
367
+ });
368
+ } catch (e) {
369
+ if (e instanceof Error) {
370
+ ctx.context.logger.error(
371
+ `Polar customer update failed. Error: ${e.message}`
372
+ );
373
+ } else {
374
+ ctx.context.logger.error(`Polar customer update failed. Error: ${e}`);
375
+ }
376
+ }
377
+ }
378
+ };
379
+
380
+ // src/index.ts
381
+ var polar = (options) => {
382
+ return {
383
+ id: "polar",
384
+ endpoints: {
385
+ polarCheckout: checkout(options),
386
+ polarWebhooks: webhooks(options),
387
+ polarCustomerPortal: customerPortal(options),
388
+ polarSubscriptions: subscriptions(options)
389
+ },
390
+ init() {
391
+ return {
392
+ options: {
393
+ databaseHooks: {
394
+ user: {
395
+ create: {
396
+ after: onUserCreate(options)
397
+ },
398
+ update: {
399
+ after: onUserUpdate(options)
400
+ }
401
+ }
402
+ }
403
+ }
404
+ };
405
+ }
406
+ };
407
+ };
408
+ export {
409
+ polar
410
+ };
411
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/endpoints/checkout.ts","../src/endpoints/customerPortal.ts","../src/endpoints/subscriptions.ts","../src/endpoints/webhooks.ts","../src/hooks/customer.ts","../src/index.ts"],"sourcesContent":["import { APIError, getSessionFromCtx } from \"better-auth/api\";\nimport { createAuthEndpoint } from \"better-auth/plugins\";\nimport { z } from \"zod\";\nimport type { PolarOptions } from \"../types\";\n\nexport const checkout = (options: PolarOptions) =>\n\tcreateAuthEndpoint(\n\t\t\"/checkout/:slug\",\n\t\t{\n\t\t\tmethod: \"GET\",\n\t\t\tquery: z.object({\n\t\t\t\tproductId: z.string().optional(),\n\t\t\t}),\n\t\t},\n\t\tasync (ctx) => {\n\t\t\tif (!options.checkout?.enabled) {\n\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\tmessage: \"Checkout is not enabled\",\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tlet productId = ctx.query?.productId;\n\n\t\t\tif (ctx.params.slug) {\n\t\t\t\tconst products = await (typeof options.checkout.products === \"function\"\n\t\t\t\t\t? options.checkout.products()\n\t\t\t\t\t: options.checkout.products);\n\n\t\t\t\tproductId = products.find(\n\t\t\t\t\t(product) => product.slug === ctx.params.slug,\n\t\t\t\t)?.productId;\n\t\t\t}\n\n\t\t\tif (!productId) {\n\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\tmessage: \"Product Id not found\",\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst session = await getSessionFromCtx(ctx);\n\n\t\t\ttry {\n\t\t\t\tconst checkout = await options.client.checkouts.create({\n\t\t\t\t\tcustomerExternalId: session?.user.id,\n\t\t\t\t\tproductId,\n\t\t\t\t\tsuccessUrl: options.checkout.successUrl\n\t\t\t\t\t\t? new URL(options.checkout.successUrl, ctx.request?.url).toString()\n\t\t\t\t\t\t: undefined,\n\t\t\t\t});\n\n\t\t\t\treturn ctx.redirect(checkout.url);\n\t\t\t} catch (e: unknown) {\n\t\t\t\tif (e instanceof Error) {\n\t\t\t\t\tctx.context.logger.error(\n\t\t\t\t\t\t`Polar checkout creation failed. Error: ${e.message}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tthrow new APIError(\"INTERNAL_SERVER_ERROR\", {\n\t\t\t\t\tmessage: \"Checkout creation failed\",\n\t\t\t\t});\n\t\t\t}\n\t\t},\n\t);\n","import { APIError, sessionMiddleware } from \"better-auth/api\";\nimport { createAuthEndpoint } from \"better-auth/plugins\";\nimport type { PolarOptions } from \"../types\";\n\nexport const customerPortal = (options: PolarOptions) =>\n\tcreateAuthEndpoint(\n\t\t\"/portal\",\n\t\t{\n\t\t\tmethod: \"GET\",\n\t\t\tuse: [sessionMiddleware],\n\t\t},\n\t\tasync (ctx) => {\n\t\t\tif (!options.enableCustomerPortal) {\n\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\tmessage: \"Customer portal is not enabled\",\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tif (!ctx.context.session?.user.id) {\n\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\tmessage: \"User not found\",\n\t\t\t\t});\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\tconst customerSession = await options.client.customerSessions.create({\n\t\t\t\t\tcustomerExternalId: ctx.context.session?.user.id,\n\t\t\t\t});\n\n\t\t\t\treturn ctx.redirect(customerSession.customerPortalUrl);\n\t\t\t} catch (e: unknown) {\n\t\t\t\tif (e instanceof Error) {\n\t\t\t\t\tctx.context.logger.error(\n\t\t\t\t\t\t`Polar customer portal creation failed. Error: ${e.message}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tthrow new APIError(\"INTERNAL_SERVER_ERROR\", {\n\t\t\t\t\tmessage: \"Customer portal creation failed\",\n\t\t\t\t});\n\t\t\t}\n\t\t},\n\t);\n","import { APIError, sessionMiddleware } from \"better-auth/api\";\nimport { createAuthEndpoint } from \"better-auth/plugins\";\nimport type { PolarOptions } from \"../types\";\n\nexport const subscriptions = (options: PolarOptions) =>\n\tcreateAuthEndpoint(\n\t\t\"/subscriptions/list\",\n\t\t{\n\t\t\tmethod: \"GET\",\n\t\t\tuse: [sessionMiddleware],\n\t\t},\n\t\tasync (ctx) => {\n\t\t\tif (!ctx.context.session.user.id) {\n\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\tmessage: \"User not found\",\n\t\t\t\t});\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\tconst { token } = await options.client.customerSessions.create({\n\t\t\t\t\tcustomerExternalId: ctx.context.session?.user.id,\n\t\t\t\t});\n\n\t\t\t\tconst subscriptions =\n\t\t\t\t\tawait options.client.customerPortal.subscriptions.list(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcustomerSession: token,\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tactive: true,\n\t\t\t\t\t\t},\n\t\t\t\t\t);\n\n\t\t\t\treturn ctx.json(subscriptions);\n\t\t\t} catch (e: unknown) {\n\t\t\t\tif (e instanceof Error) {\n\t\t\t\t\tctx.context.logger.error(\n\t\t\t\t\t\t`Polar subscriptions list failed. Error: ${e.message}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tthrow new APIError(\"INTERNAL_SERVER_ERROR\", {\n\t\t\t\t\tmessage: \"Subscriptions list failed\",\n\t\t\t\t});\n\t\t\t}\n\t\t},\n\t);\n","import { validateEvent } from \"@polar-sh/sdk/webhooks.js\";\nimport { APIError } from \"better-auth/api\";\nimport { createAuthEndpoint } from \"better-auth/plugins\";\nimport type { PolarOptions } from \"../types\";\n\nexport const webhooks = (options: PolarOptions) =>\n\tcreateAuthEndpoint(\n\t\t\"/polar/webhooks\",\n\t\t{\n\t\t\tmethod: \"POST\",\n\t\t\tmetadata: {\n\t\t\t\tisAction: false,\n\t\t\t},\n\t\t\tcloneRequest: true,\n\t\t},\n\t\tasync (ctx) => {\n\t\t\tconst { webhooks } = options;\n\n\t\t\tif (!webhooks) {\n\t\t\t\tthrow new APIError(\"NOT_FOUND\", {\n\t\t\t\t\tmessage: \"Webhooks not enabled\",\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst {\n\t\t\t\tsecret,\n\t\t\t\tonPayload,\n\t\t\t\tonCheckoutCreated,\n\t\t\t\tonCheckoutUpdated,\n\t\t\t\tonOrderCreated,\n\t\t\t\tonOrderRefunded,\n\t\t\t\tonRefundCreated,\n\t\t\t\tonRefundUpdated,\n\t\t\t\tonSubscriptionCreated,\n\t\t\t\tonSubscriptionUpdated,\n\t\t\t\tonSubscriptionActive,\n\t\t\t\tonSubscriptionCanceled,\n\t\t\t\tonSubscriptionRevoked,\n\t\t\t\tonSubscriptionUncanceled,\n\t\t\t\tonProductCreated,\n\t\t\t\tonProductUpdated,\n\t\t\t\tonOrganizationUpdated,\n\t\t\t\tonBenefitCreated,\n\t\t\t\tonBenefitUpdated,\n\t\t\t\tonBenefitGrantCreated,\n\t\t\t\tonBenefitGrantUpdated,\n\t\t\t\tonBenefitGrantRevoked,\n\t\t\t} = webhooks;\n\n\t\t\tif (!ctx.request?.body) {\n\t\t\t\tthrow new APIError(\"INTERNAL_SERVER_ERROR\");\n\t\t\t}\n\t\t\tconst buf = await ctx.request.text();\n\t\t\tlet event: ReturnType<typeof validateEvent>;\n\t\t\ttry {\n\t\t\t\tif (!secret) {\n\t\t\t\t\tthrow new APIError(\"INTERNAL_SERVER_ERROR\", {\n\t\t\t\t\t\tmessage: \"Polar webhook secret not found\",\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tconst headers = {\n\t\t\t\t\t\"webhook-id\": ctx.request.headers.get(\"webhook-id\") as string,\n\t\t\t\t\t\"webhook-timestamp\": ctx.request.headers.get(\n\t\t\t\t\t\t\"webhook-timestamp\",\n\t\t\t\t\t) as string,\n\t\t\t\t\t\"webhook-signature\": ctx.request.headers.get(\n\t\t\t\t\t\t\"webhook-signature\",\n\t\t\t\t\t) as string,\n\t\t\t\t};\n\n\t\t\t\tevent = validateEvent(buf, headers, secret);\n\t\t\t} catch (err: unknown) {\n\t\t\t\tif (err instanceof Error) {\n\t\t\t\t\tctx.context.logger.error(`${err.message}`);\n\t\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\t\tmessage: `Webhook Error: ${err.message}`,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\tmessage: `Webhook Error: ${err}`,\n\t\t\t\t});\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tif (onPayload) {\n\t\t\t\t\tonPayload(event);\n\t\t\t\t}\n\n\t\t\t\tswitch (event.type) {\n\t\t\t\t\tcase \"checkout.created\":\n\t\t\t\t\t\tif (onCheckoutCreated) {\n\t\t\t\t\t\t\tonCheckoutCreated(event);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"checkout.updated\":\n\t\t\t\t\t\tif (onCheckoutUpdated) {\n\t\t\t\t\t\t\tonCheckoutUpdated(event);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"order.created\":\n\t\t\t\t\t\tif (onOrderCreated) {\n\t\t\t\t\t\t\tonOrderCreated(event);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"subscription.created\":\n\t\t\t\t\t\tif (onSubscriptionCreated) {\n\t\t\t\t\t\t\tonSubscriptionCreated(event);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"subscription.updated\":\n\t\t\t\t\t\tif (onSubscriptionUpdated) {\n\t\t\t\t\t\t\tonSubscriptionUpdated(event);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"subscription.active\":\n\t\t\t\t\t\tif (onSubscriptionActive) {\n\t\t\t\t\t\t\tonSubscriptionActive(event);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"subscription.canceled\":\n\t\t\t\t\t\tif (onSubscriptionCanceled) {\n\t\t\t\t\t\t\tonSubscriptionCanceled(event);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"subscription.uncanceled\":\n\t\t\t\t\t\tif (onSubscriptionUncanceled) {\n\t\t\t\t\t\t\tonSubscriptionUncanceled(event);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"subscription.revoked\":\n\t\t\t\t\t\tif (onSubscriptionRevoked) {\n\t\t\t\t\t\t\tonSubscriptionRevoked(event);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"product.created\":\n\t\t\t\t\t\tif (onProductCreated) {\n\t\t\t\t\t\t\tonProductCreated(event);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"product.updated\":\n\t\t\t\t\t\tif (onProductUpdated) {\n\t\t\t\t\t\t\tonProductUpdated(event);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"organization.updated\":\n\t\t\t\t\t\tif (onOrganizationUpdated) {\n\t\t\t\t\t\t\tonOrganizationUpdated(event);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"benefit.created\":\n\t\t\t\t\t\tif (onBenefitCreated) {\n\t\t\t\t\t\t\tonBenefitCreated(event);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"benefit.updated\":\n\t\t\t\t\t\tif (onBenefitUpdated) {\n\t\t\t\t\t\t\tonBenefitUpdated(event);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"benefit_grant.created\":\n\t\t\t\t\t\tif (onBenefitGrantCreated) {\n\t\t\t\t\t\t\tonBenefitGrantCreated(event);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"benefit_grant.updated\":\n\t\t\t\t\t\tif (onBenefitGrantUpdated) {\n\t\t\t\t\t\t\tonBenefitGrantUpdated(event);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"benefit_grant.revoked\":\n\t\t\t\t\t\tif (onBenefitGrantRevoked) {\n\t\t\t\t\t\t\tonBenefitGrantRevoked(event);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"order.refunded\":\n\t\t\t\t\t\tif (onOrderRefunded) {\n\t\t\t\t\t\t\tonOrderRefunded(event);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"refund.created\":\n\t\t\t\t\t\tif (onRefundCreated) {\n\t\t\t\t\t\t\tonRefundCreated(event);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"refund.updated\":\n\t\t\t\t\t\tif (onRefundUpdated) {\n\t\t\t\t\t\t\tonRefundUpdated(event);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t} catch (e: unknown) {\n\t\t\t\tif (e instanceof Error) {\n\t\t\t\t\tctx.context.logger.error(`Polar webhook failed. Error: ${e.message}`);\n\t\t\t\t} else {\n\t\t\t\t\tctx.context.logger.error(`Polar webhook failed. Error: ${e}`);\n\t\t\t\t}\n\n\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\tmessage: \"Webhook error: See server logs for more information.\",\n\t\t\t\t});\n\t\t\t}\n\n\t\t\treturn ctx.json({ received: true });\n\t\t},\n\t);\n","import type { GenericEndpointContext, User } from \"better-auth\";\nimport { APIError } from \"better-auth/api\";\nimport type { PolarOptions } from \"../types\";\n\nexport const onUserCreate =\n\t(options: PolarOptions) =>\n\tasync (user: User, ctx?: GenericEndpointContext) => {\n\t\tif (ctx && options.createCustomerOnSignUp) {\n\t\t\ttry {\n\t\t\t\tconst params =\n\t\t\t\t\toptions.getCustomerCreateParams && ctx.context.session\n\t\t\t\t\t\t? await options.getCustomerCreateParams({\n\t\t\t\t\t\t\t\tuser,\n\t\t\t\t\t\t\t\tsession: ctx.context.session.session,\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t: {};\n\n\t\t\t\tawait options.client.customers.create({\n\t\t\t\t\t...params,\n\t\t\t\t\temail: user.email,\n\t\t\t\t\tname: user.name,\n\t\t\t\t\texternalId: user.id,\n\t\t\t\t});\n\t\t\t} catch (e: unknown) {\n\t\t\t\tif (e instanceof Error) {\n\t\t\t\t\tctx.context.logger.error(\n\t\t\t\t\t\t`Polar customer creation failed. Error: ${e.message}`,\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tctx.context.logger.error(\n\t\t\t\t\t\t`Polar customer creation failed. Error: ${e}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tthrow new APIError(\"BAD_REQUEST\", {\n\t\t\t\t\tmessage:\n\t\t\t\t\t\t\"Polar customer creation failed. See server logs for more information.\",\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t};\n\nexport const onUserUpdate =\n\t(options: PolarOptions) =>\n\tasync (user: User, ctx?: GenericEndpointContext) => {\n\t\tif (ctx && options.createCustomerOnSignUp) {\n\t\t\ttry {\n\t\t\t\tawait options.client.customers.updateExternal({\n\t\t\t\t\texternalId: user.id,\n\t\t\t\t\tcustomerUpdate: {\n\t\t\t\t\t\temail: user.email,\n\t\t\t\t\t\tname: user.name,\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t} catch (e: unknown) {\n\t\t\t\tif (e instanceof Error) {\n\t\t\t\t\tctx.context.logger.error(\n\t\t\t\t\t\t`Polar customer update failed. Error: ${e.message}`,\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tctx.context.logger.error(`Polar customer update failed. Error: ${e}`);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t};\n","import type { BetterAuthPlugin } from \"better-auth\";\nimport { checkout } from \"./endpoints/checkout\";\nimport { customerPortal } from \"./endpoints/customerPortal\";\nimport { subscriptions } from \"./endpoints/subscriptions\";\nimport { webhooks } from \"./endpoints/webhooks\";\nimport { onUserCreate, onUserUpdate } from \"./hooks/customer\";\nimport type { PolarOptions } from \"./types\";\n\nexport const polar = <O extends PolarOptions>(options: O) => {\n\treturn {\n\t\tid: \"polar\",\n\t\tendpoints: {\n\t\t\tpolarCheckout: checkout(options),\n\t\t\tpolarWebhooks: webhooks(options),\n\t\t\tpolarCustomerPortal: customerPortal(options),\n\t\t\tpolarSubscriptions: subscriptions(options),\n\t\t},\n\t\tinit() {\n\t\t\treturn {\n\t\t\t\toptions: {\n\t\t\t\t\tdatabaseHooks: {\n\t\t\t\t\t\tuser: {\n\t\t\t\t\t\t\tcreate: {\n\t\t\t\t\t\t\t\tafter: onUserCreate(options),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tupdate: {\n\t\t\t\t\t\t\t\tafter: onUserUpdate(options),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t};\n\t\t},\n\t} satisfies BetterAuthPlugin;\n};\n"],"mappings":";AAAA,SAAS,UAAU,yBAAyB;AAC5C,SAAS,0BAA0B;AACnC,SAAS,SAAS;AAGX,IAAM,WAAW,CAAC,YACxB;AAAA,EACC;AAAA,EACA;AAAA,IACC,QAAQ;AAAA,IACR,OAAO,EAAE,OAAO;AAAA,MACf,WAAW,EAAE,OAAO,EAAE,SAAS;AAAA,IAChC,CAAC;AAAA,EACF;AAAA,EACA,OAAO,QAAQ;AACd,QAAI,CAAC,QAAQ,UAAU,SAAS;AAC/B,YAAM,IAAI,SAAS,eAAe;AAAA,QACjC,SAAS;AAAA,MACV,CAAC;AAAA,IACF;AAEA,QAAI,YAAY,IAAI,OAAO;AAE3B,QAAI,IAAI,OAAO,MAAM;AACpB,YAAM,WAAW,OAAO,OAAO,QAAQ,SAAS,aAAa,aAC1D,QAAQ,SAAS,SAAS,IAC1B,QAAQ,SAAS;AAEpB,kBAAY,SAAS;AAAA,QACpB,CAAC,YAAY,QAAQ,SAAS,IAAI,OAAO;AAAA,MAC1C,GAAG;AAAA,IACJ;AAEA,QAAI,CAAC,WAAW;AACf,YAAM,IAAI,SAAS,eAAe;AAAA,QACjC,SAAS;AAAA,MACV,CAAC;AAAA,IACF;AAEA,UAAM,UAAU,MAAM,kBAAkB,GAAG;AAE3C,QAAI;AACH,YAAMA,YAAW,MAAM,QAAQ,OAAO,UAAU,OAAO;AAAA,QACtD,oBAAoB,SAAS,KAAK;AAAA,Q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AAAA,QACjC,SACC;AAAA,MACF,CAAC;AAAA,IACF;AAAA,EACD;AACD;AAEM,IAAM,eACZ,CAAC,YACD,OAAO,MAAY,QAAiC;AACnD,MAAI,OAAO,QAAQ,wBAAwB;AAC1C,QAAI;AACH,YAAM,QAAQ,OAAO,UAAU,eAAe;AAAA,QAC7C,YAAY,KAAK;AAAA,QACjB,gBAAgB;AAAA,UACf,OAAO,KAAK;AAAA,UACZ,MAAM,KAAK;AAAA,QACZ;AAAA,MACD,CAAC;AAAA,IACF,SAAS,GAAY;AACpB,UAAI,aAAa,OAAO;AACvB,YAAI,QAAQ,OAAO;AAAA,UAClB,wCAAwC,EAAE,OAAO;AAAA,QAClD;AAAA,MACD,OAAO;AACN,YAAI,QAAQ,OAAO,MAAM,wCAAwC,CAAC,EAAE;AAAA,MACrE;AAAA,IACD;AAAA,EACD;AACD;;;ACxDM,IAAM,QAAQ,CAAyB,YAAe;AAC5D,SAAO;AAAA,IACN,IAAI;AAAA,IACJ,WAAW;AAAA,MACV,eAAe,SAAS,OAAO;AAAA,MAC/B,eAAe,SAAS,OAAO;AAAA,MAC/B,qBAAqB,eAAe,OAAO;AAAA,MAC3C,oBAAoB,cAAc,OAAO;AAAA,IAC1C;AAAA,IACA,OAAO;AACN,aAAO;AAAA,QACN,SAAS;AAAA,UACR,eAAe;AAAA,YACd,MAAM;AAAA,cACL,QAAQ;AAAA,gBACP,OAAO,aAAa,OAAO;AAAA,cAC5B;AAAA,cACA,QAAQ;AAAA,gBACP,OAAO,aAAa,OAAO;AAAA,cAC5B;AAAA,YACD;AAAA,UACD;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAAA,EACD;AACD;","names":["checkout","APIError","createAuthEndpoint","APIError","sessionMiddleware","createAuthEndpoint","subscriptions","APIError","createAuthEndpoint","webhooks","APIError"]}
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@polar-sh/better-auth",
3
+ "version": "0.0.2",
4
+ "description": "Polar integration for better-auth",
5
+ "main": "./dist/index.cjs",
6
+ "module": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ "import": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ },
13
+ "require": {
14
+ "types": "./dist/index.d.cts",
15
+ "require": "./dist/index.cjs"
16
+ }
17
+ },
18
+ "type": "module",
19
+ "engines": {
20
+ "node": ">=16"
21
+ },
22
+ "files": [
23
+ "dist"
24
+ ],
25
+ "keywords": [
26
+ "polar",
27
+ "better-auth",
28
+ "payments",
29
+ "subscriptions"
30
+ ],
31
+ "devDependencies": {
32
+ "@biomejs/biome": "1.9.4",
33
+ "@sindresorhus/tsconfig": "^7.0.0",
34
+ "@types/node": "^20.0.0",
35
+ "better-auth": "^1.2.0",
36
+ "tsup": "^8.3.5",
37
+ "vitest": "^2.1.8"
38
+ },
39
+ "dependencies": {
40
+ "@polar-sh/sdk": "^0.28.0",
41
+ "zod": "^3.24.2"
42
+ },
43
+ "peerDependencies": {
44
+ "better-auth": "^1.2.0"
45
+ },
46
+ "scripts": {
47
+ "test": "vitest",
48
+ "build": "tsup ./src/index.ts --format esm,cjs --dts --clean --sourcemap",
49
+ "dev": "tsc --watch",
50
+ "check": "biome check --write ./src"
51
+ }
52
+ }