@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.cjs ADDED
@@ -0,0 +1,438 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ polar: () => polar
24
+ });
25
+ module.exports = __toCommonJS(index_exports);
26
+
27
+ // src/endpoints/checkout.ts
28
+ var import_api = require("better-auth/api");
29
+ var import_plugins = require("better-auth/plugins");
30
+ var import_zod = require("zod");
31
+ var checkout = (options) => (0, import_plugins.createAuthEndpoint)(
32
+ "/checkout/:slug",
33
+ {
34
+ method: "GET",
35
+ query: import_zod.z.object({
36
+ productId: import_zod.z.string().optional()
37
+ })
38
+ },
39
+ async (ctx) => {
40
+ if (!options.checkout?.enabled) {
41
+ throw new import_api.APIError("BAD_REQUEST", {
42
+ message: "Checkout is not enabled"
43
+ });
44
+ }
45
+ let productId = ctx.query?.productId;
46
+ if (ctx.params.slug) {
47
+ const products = await (typeof options.checkout.products === "function" ? options.checkout.products() : options.checkout.products);
48
+ productId = products.find(
49
+ (product) => product.slug === ctx.params.slug
50
+ )?.productId;
51
+ }
52
+ if (!productId) {
53
+ throw new import_api.APIError("BAD_REQUEST", {
54
+ message: "Product Id not found"
55
+ });
56
+ }
57
+ const session = await (0, import_api.getSessionFromCtx)(ctx);
58
+ try {
59
+ const checkout2 = await options.client.checkouts.create({
60
+ customerExternalId: session?.user.id,
61
+ productId,
62
+ successUrl: options.checkout.successUrl ? new URL(options.checkout.successUrl, ctx.request?.url).toString() : void 0
63
+ });
64
+ return ctx.redirect(checkout2.url);
65
+ } catch (e) {
66
+ if (e instanceof Error) {
67
+ ctx.context.logger.error(
68
+ `Polar checkout creation failed. Error: ${e.message}`
69
+ );
70
+ }
71
+ throw new import_api.APIError("INTERNAL_SERVER_ERROR", {
72
+ message: "Checkout creation failed"
73
+ });
74
+ }
75
+ }
76
+ );
77
+
78
+ // src/endpoints/customerPortal.ts
79
+ var import_api2 = require("better-auth/api");
80
+ var import_plugins2 = require("better-auth/plugins");
81
+ var customerPortal = (options) => (0, import_plugins2.createAuthEndpoint)(
82
+ "/portal",
83
+ {
84
+ method: "GET",
85
+ use: [import_api2.sessionMiddleware]
86
+ },
87
+ async (ctx) => {
88
+ if (!options.enableCustomerPortal) {
89
+ throw new import_api2.APIError("BAD_REQUEST", {
90
+ message: "Customer portal is not enabled"
91
+ });
92
+ }
93
+ if (!ctx.context.session?.user.id) {
94
+ throw new import_api2.APIError("BAD_REQUEST", {
95
+ message: "User not found"
96
+ });
97
+ }
98
+ try {
99
+ const customerSession = await options.client.customerSessions.create({
100
+ customerExternalId: ctx.context.session?.user.id
101
+ });
102
+ return ctx.redirect(customerSession.customerPortalUrl);
103
+ } catch (e) {
104
+ if (e instanceof Error) {
105
+ ctx.context.logger.error(
106
+ `Polar customer portal creation failed. Error: ${e.message}`
107
+ );
108
+ }
109
+ throw new import_api2.APIError("INTERNAL_SERVER_ERROR", {
110
+ message: "Customer portal creation failed"
111
+ });
112
+ }
113
+ }
114
+ );
115
+
116
+ // src/endpoints/subscriptions.ts
117
+ var import_api3 = require("better-auth/api");
118
+ var import_plugins3 = require("better-auth/plugins");
119
+ var subscriptions = (options) => (0, import_plugins3.createAuthEndpoint)(
120
+ "/subscriptions/list",
121
+ {
122
+ method: "GET",
123
+ use: [import_api3.sessionMiddleware]
124
+ },
125
+ async (ctx) => {
126
+ if (!ctx.context.session.user.id) {
127
+ throw new import_api3.APIError("BAD_REQUEST", {
128
+ message: "User not found"
129
+ });
130
+ }
131
+ try {
132
+ const { token } = await options.client.customerSessions.create({
133
+ customerExternalId: ctx.context.session?.user.id
134
+ });
135
+ const subscriptions2 = await options.client.customerPortal.subscriptions.list(
136
+ {
137
+ customerSession: token
138
+ },
139
+ {
140
+ active: true
141
+ }
142
+ );
143
+ return ctx.json(subscriptions2);
144
+ } catch (e) {
145
+ if (e instanceof Error) {
146
+ ctx.context.logger.error(
147
+ `Polar subscriptions list failed. Error: ${e.message}`
148
+ );
149
+ }
150
+ throw new import_api3.APIError("INTERNAL_SERVER_ERROR", {
151
+ message: "Subscriptions list failed"
152
+ });
153
+ }
154
+ }
155
+ );
156
+
157
+ // src/endpoints/webhooks.ts
158
+ var import_webhooks = require("@polar-sh/sdk/webhooks.js");
159
+ var import_api4 = require("better-auth/api");
160
+ var import_plugins4 = require("better-auth/plugins");
161
+ var webhooks = (options) => (0, import_plugins4.createAuthEndpoint)(
162
+ "/polar/webhooks",
163
+ {
164
+ method: "POST",
165
+ metadata: {
166
+ isAction: false
167
+ },
168
+ cloneRequest: true
169
+ },
170
+ async (ctx) => {
171
+ const { webhooks: webhooks2 } = options;
172
+ if (!webhooks2) {
173
+ throw new import_api4.APIError("NOT_FOUND", {
174
+ message: "Webhooks not enabled"
175
+ });
176
+ }
177
+ const {
178
+ secret,
179
+ onPayload,
180
+ onCheckoutCreated,
181
+ onCheckoutUpdated,
182
+ onOrderCreated,
183
+ onOrderRefunded,
184
+ onRefundCreated,
185
+ onRefundUpdated,
186
+ onSubscriptionCreated,
187
+ onSubscriptionUpdated,
188
+ onSubscriptionActive,
189
+ onSubscriptionCanceled,
190
+ onSubscriptionRevoked,
191
+ onSubscriptionUncanceled,
192
+ onProductCreated,
193
+ onProductUpdated,
194
+ onOrganizationUpdated,
195
+ onBenefitCreated,
196
+ onBenefitUpdated,
197
+ onBenefitGrantCreated,
198
+ onBenefitGrantUpdated,
199
+ onBenefitGrantRevoked
200
+ } = webhooks2;
201
+ if (!ctx.request?.body) {
202
+ throw new import_api4.APIError("INTERNAL_SERVER_ERROR");
203
+ }
204
+ const buf = await ctx.request.text();
205
+ let event;
206
+ try {
207
+ if (!secret) {
208
+ throw new import_api4.APIError("INTERNAL_SERVER_ERROR", {
209
+ message: "Polar webhook secret not found"
210
+ });
211
+ }
212
+ const headers = {
213
+ "webhook-id": ctx.request.headers.get("webhook-id"),
214
+ "webhook-timestamp": ctx.request.headers.get(
215
+ "webhook-timestamp"
216
+ ),
217
+ "webhook-signature": ctx.request.headers.get(
218
+ "webhook-signature"
219
+ )
220
+ };
221
+ event = (0, import_webhooks.validateEvent)(buf, headers, secret);
222
+ } catch (err) {
223
+ if (err instanceof Error) {
224
+ ctx.context.logger.error(`${err.message}`);
225
+ throw new import_api4.APIError("BAD_REQUEST", {
226
+ message: `Webhook Error: ${err.message}`
227
+ });
228
+ }
229
+ throw new import_api4.APIError("BAD_REQUEST", {
230
+ message: `Webhook Error: ${err}`
231
+ });
232
+ }
233
+ try {
234
+ if (onPayload) {
235
+ onPayload(event);
236
+ }
237
+ switch (event.type) {
238
+ case "checkout.created":
239
+ if (onCheckoutCreated) {
240
+ onCheckoutCreated(event);
241
+ }
242
+ break;
243
+ case "checkout.updated":
244
+ if (onCheckoutUpdated) {
245
+ onCheckoutUpdated(event);
246
+ }
247
+ break;
248
+ case "order.created":
249
+ if (onOrderCreated) {
250
+ onOrderCreated(event);
251
+ }
252
+ break;
253
+ case "subscription.created":
254
+ if (onSubscriptionCreated) {
255
+ onSubscriptionCreated(event);
256
+ }
257
+ break;
258
+ case "subscription.updated":
259
+ if (onSubscriptionUpdated) {
260
+ onSubscriptionUpdated(event);
261
+ }
262
+ break;
263
+ case "subscription.active":
264
+ if (onSubscriptionActive) {
265
+ onSubscriptionActive(event);
266
+ }
267
+ break;
268
+ case "subscription.canceled":
269
+ if (onSubscriptionCanceled) {
270
+ onSubscriptionCanceled(event);
271
+ }
272
+ break;
273
+ case "subscription.uncanceled":
274
+ if (onSubscriptionUncanceled) {
275
+ onSubscriptionUncanceled(event);
276
+ }
277
+ break;
278
+ case "subscription.revoked":
279
+ if (onSubscriptionRevoked) {
280
+ onSubscriptionRevoked(event);
281
+ }
282
+ break;
283
+ case "product.created":
284
+ if (onProductCreated) {
285
+ onProductCreated(event);
286
+ }
287
+ break;
288
+ case "product.updated":
289
+ if (onProductUpdated) {
290
+ onProductUpdated(event);
291
+ }
292
+ break;
293
+ case "organization.updated":
294
+ if (onOrganizationUpdated) {
295
+ onOrganizationUpdated(event);
296
+ }
297
+ break;
298
+ case "benefit.created":
299
+ if (onBenefitCreated) {
300
+ onBenefitCreated(event);
301
+ }
302
+ break;
303
+ case "benefit.updated":
304
+ if (onBenefitUpdated) {
305
+ onBenefitUpdated(event);
306
+ }
307
+ break;
308
+ case "benefit_grant.created":
309
+ if (onBenefitGrantCreated) {
310
+ onBenefitGrantCreated(event);
311
+ }
312
+ break;
313
+ case "benefit_grant.updated":
314
+ if (onBenefitGrantUpdated) {
315
+ onBenefitGrantUpdated(event);
316
+ }
317
+ break;
318
+ case "benefit_grant.revoked":
319
+ if (onBenefitGrantRevoked) {
320
+ onBenefitGrantRevoked(event);
321
+ }
322
+ break;
323
+ case "order.refunded":
324
+ if (onOrderRefunded) {
325
+ onOrderRefunded(event);
326
+ }
327
+ break;
328
+ case "refund.created":
329
+ if (onRefundCreated) {
330
+ onRefundCreated(event);
331
+ }
332
+ break;
333
+ case "refund.updated":
334
+ if (onRefundUpdated) {
335
+ onRefundUpdated(event);
336
+ }
337
+ break;
338
+ }
339
+ } catch (e) {
340
+ if (e instanceof Error) {
341
+ ctx.context.logger.error(`Polar webhook failed. Error: ${e.message}`);
342
+ } else {
343
+ ctx.context.logger.error(`Polar webhook failed. Error: ${e}`);
344
+ }
345
+ throw new import_api4.APIError("BAD_REQUEST", {
346
+ message: "Webhook error: See server logs for more information."
347
+ });
348
+ }
349
+ return ctx.json({ received: true });
350
+ }
351
+ );
352
+
353
+ // src/hooks/customer.ts
354
+ var import_api5 = require("better-auth/api");
355
+ var onUserCreate = (options) => async (user, ctx) => {
356
+ if (ctx && options.createCustomerOnSignUp) {
357
+ try {
358
+ const params = options.getCustomerCreateParams && ctx.context.session ? await options.getCustomerCreateParams({
359
+ user,
360
+ session: ctx.context.session.session
361
+ }) : {};
362
+ await options.client.customers.create({
363
+ ...params,
364
+ email: user.email,
365
+ name: user.name,
366
+ externalId: user.id
367
+ });
368
+ } catch (e) {
369
+ if (e instanceof Error) {
370
+ ctx.context.logger.error(
371
+ `Polar customer creation failed. Error: ${e.message}`
372
+ );
373
+ } else {
374
+ ctx.context.logger.error(
375
+ `Polar customer creation failed. Error: ${e}`
376
+ );
377
+ }
378
+ throw new import_api5.APIError("BAD_REQUEST", {
379
+ message: "Polar customer creation failed. See server logs for more information."
380
+ });
381
+ }
382
+ }
383
+ };
384
+ var onUserUpdate = (options) => async (user, ctx) => {
385
+ if (ctx && options.createCustomerOnSignUp) {
386
+ try {
387
+ await options.client.customers.updateExternal({
388
+ externalId: user.id,
389
+ customerUpdate: {
390
+ email: user.email,
391
+ name: user.name
392
+ }
393
+ });
394
+ } catch (e) {
395
+ if (e instanceof Error) {
396
+ ctx.context.logger.error(
397
+ `Polar customer update failed. Error: ${e.message}`
398
+ );
399
+ } else {
400
+ ctx.context.logger.error(`Polar customer update failed. Error: ${e}`);
401
+ }
402
+ }
403
+ }
404
+ };
405
+
406
+ // src/index.ts
407
+ var polar = (options) => {
408
+ return {
409
+ id: "polar",
410
+ endpoints: {
411
+ polarCheckout: checkout(options),
412
+ polarWebhooks: webhooks(options),
413
+ polarCustomerPortal: customerPortal(options),
414
+ polarSubscriptions: subscriptions(options)
415
+ },
416
+ init() {
417
+ return {
418
+ options: {
419
+ databaseHooks: {
420
+ user: {
421
+ create: {
422
+ after: onUserCreate(options)
423
+ },
424
+ update: {
425
+ after: onUserUpdate(options)
426
+ }
427
+ }
428
+ }
429
+ }
430
+ };
431
+ }
432
+ };
433
+ };
434
+ // Annotate the CommonJS export names for ESM import in node:
435
+ 0 && (module.exports = {
436
+ polar
437
+ });
438
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/endpoints/checkout.ts","../src/endpoints/customerPortal.ts","../src/endpoints/subscriptions.ts","../src/endpoints/webhooks.ts","../src/hooks/customer.ts"],"sourcesContent":["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","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"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,iBAA4C;AAC5C,qBAAmC;AACnC,iBAAkB;AAGX,IAAM,WAAW,CAAC,gBACxB;AAAA,EACC;AAAA,EACA;AAAA,IACC,QAAQ;AAAA,IACR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D,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","import_api","import_plugins","import_api","import_plugins","subscriptions","import_api","import_plugins","webhooks","import_api"]}