@dodopayments/better-auth 1.5.0 → 1.6.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/README.md +75 -5
- package/dist/{chunk-R5TTSJK4.js → chunk-527Y7FSE.js} +28 -19
- package/dist/chunk-527Y7FSE.js.map +1 -0
- package/dist/{chunk-65YIVTFE.js → chunk-6VDYFSNJ.js} +6 -6
- package/dist/chunk-6VDYFSNJ.js.map +1 -0
- package/dist/{chunk-TOPOAYYO.js → chunk-EGRIWRWP.js} +6 -3
- package/dist/chunk-EGRIWRWP.js.map +1 -0
- package/dist/{chunk-HHIXOUFD.js → chunk-XXIDSJPK.js} +4 -4
- package/dist/chunk-XXIDSJPK.js.map +1 -0
- package/dist/{chunk-DTOB4IQZ.js → chunk-YCUWFLKK.js} +15 -12
- package/dist/chunk-YCUWFLKK.js.map +1 -0
- package/dist/{chunk-ARA27DRZ.js → chunk-ZA3TNX5K.js} +11 -9
- package/dist/chunk-ZA3TNX5K.js.map +1 -0
- package/dist/client.d.cts +1 -2
- package/dist/client.d.ts +1 -2
- package/dist/hooks/customer.cjs +27 -18
- package/dist/hooks/customer.cjs.map +1 -1
- package/dist/hooks/customer.d.cts +1 -2
- package/dist/hooks/customer.d.ts +1 -2
- package/dist/hooks/customer.js +1 -1
- package/dist/index.cjs +63 -46
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -3
- package/dist/index.d.ts +2 -3
- package/dist/index.js +7 -7
- package/dist/index.js.map +1 -1
- package/dist/plugins/checkout.cjs +5 -5
- package/dist/plugins/checkout.cjs.map +1 -1
- package/dist/plugins/checkout.d.cts +2 -3
- package/dist/plugins/checkout.d.ts +2 -3
- package/dist/plugins/checkout.js +1 -1
- package/dist/plugins/portal.cjs +18 -12
- package/dist/plugins/portal.cjs.map +1 -1
- package/dist/plugins/portal.d.cts +2 -3
- package/dist/plugins/portal.d.ts +2 -3
- package/dist/plugins/portal.js +2 -2
- package/dist/plugins/usage.cjs +14 -9
- package/dist/plugins/usage.cjs.map +1 -1
- package/dist/plugins/usage.d.cts +6 -107
- package/dist/plugins/usage.d.ts +6 -107
- package/dist/plugins/usage.js +2 -2
- package/dist/plugins/webhooks.cjs +3 -3
- package/dist/plugins/webhooks.cjs.map +1 -1
- package/dist/plugins/webhooks.d.cts +2 -3
- package/dist/plugins/webhooks.d.ts +2 -3
- package/dist/plugins/webhooks.js +1 -1
- package/dist/{types-4JE4OwKb.d.cts → types-D0tVSLaf.d.cts} +122 -10
- package/dist/{types-B9rx1bt7.d.ts → types-D0tVSLaf.d.ts} +122 -10
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +1 -2
- package/dist/types.d.ts +1 -2
- package/dist/utils.cjs +5 -2
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +8 -1
- package/dist/utils.d.ts +8 -1
- package/dist/utils.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-65YIVTFE.js.map +0 -1
- package/dist/chunk-ARA27DRZ.js.map +0 -1
- package/dist/chunk-DTOB4IQZ.js.map +0 -1
- package/dist/chunk-HHIXOUFD.js.map +0 -1
- package/dist/chunk-R5TTSJK4.js.map +0 -1
- package/dist/chunk-TOPOAYYO.js.map +0 -1
|
@@ -26,7 +26,7 @@ module.exports = __toCommonJS(checkout_exports);
|
|
|
26
26
|
var import_api = require("better-auth/api");
|
|
27
27
|
var import_v3 = require("zod/v3");
|
|
28
28
|
var import_checkout = require("@dodopayments/core/checkout");
|
|
29
|
-
var checkout = (checkoutOptions = {}) => (
|
|
29
|
+
var checkout = (checkoutOptions = {}) => (options) => {
|
|
30
30
|
return {
|
|
31
31
|
/**
|
|
32
32
|
* @deprecated
|
|
@@ -84,8 +84,8 @@ var checkout = (checkoutOptions = {}) => (dodopayments) => {
|
|
|
84
84
|
...ctx.body.metadata
|
|
85
85
|
} : ctx.body.metadata
|
|
86
86
|
},
|
|
87
|
-
bearerToken:
|
|
88
|
-
environment:
|
|
87
|
+
bearerToken: options.client.bearerToken,
|
|
88
|
+
environment: options.client.baseURL.includes("test") ? "test_mode" : "live_mode",
|
|
89
89
|
returnUrl: checkoutOptions.successUrl ? new URL(
|
|
90
90
|
checkoutOptions.successUrl,
|
|
91
91
|
ctx.request?.url
|
|
@@ -165,8 +165,8 @@ var checkout = (checkoutOptions = {}) => (dodopayments) => {
|
|
|
165
165
|
ctx.request?.url
|
|
166
166
|
).toString() : void 0
|
|
167
167
|
},
|
|
168
|
-
bearerToken:
|
|
169
|
-
environment:
|
|
168
|
+
bearerToken: options.client.bearerToken,
|
|
169
|
+
environment: options.client.baseURL.includes("test") ? "test_mode" : "live_mode",
|
|
170
170
|
type: "session"
|
|
171
171
|
});
|
|
172
172
|
const redirectUrl = new URL(checkoutUrl);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/plugins/checkout.ts"],"sourcesContent":["import type DodoPayments from \"dodopayments\";\nimport { APIError, createAuthEndpoint, getSessionFromCtx } from \"better-auth/api\";\nimport { z } from \"zod/v3\";\nimport type { CreateCheckoutResponse, Product } from \"../types\";\nimport {\n buildCheckoutUrl,\n checkoutSessionPayloadSchema,\n dynamicCheckoutBodySchema,\n} from \"@dodopayments/core/checkout\";\n\nexport interface CheckoutOptions {\n /**\n * Optional list of slug -> productId mappings for easy slug checkouts\n */\n products?: Product[] | (() => Promise<Product[]>);\n /**\n * Checkout Success URL\n */\n successUrl?: string;\n /**\n * Only allow authenticated customers to checkout\n */\n authenticatedUsersOnly?: boolean;\n}\n\nexport const checkout =\n (checkoutOptions: CheckoutOptions = {}) =>\n (dodopayments: DodoPayments) => {\n return {\n /**\n * @deprecated\n */\n dodoCheckout: createAuthEndpoint(\n \"/dodopayments/checkout\",\n {\n method: \"POST\",\n body: dynamicCheckoutBodySchema.extend({\n slug: z.string().optional(),\n referenceId: z.string().optional(),\n }),\n requireRequest: true,\n },\n async (ctx): Promise<CreateCheckoutResponse> => {\n const session = await getSessionFromCtx(ctx);\n\n let dodoPaymentsProductId: string | undefined;\n\n if (ctx.body?.slug) {\n const resolvedProducts =\n typeof checkoutOptions.products === \"function\"\n ? await checkoutOptions.products()\n : checkoutOptions.products;\n\n const productId = resolvedProducts?.find(\n (product) => product.slug === ctx.body.slug,\n )?.productId;\n\n if (!productId) {\n throw new APIError(\"BAD_REQUEST\", {\n message: \"Product not found\",\n });\n }\n\n dodoPaymentsProductId = productId;\n } else {\n dodoPaymentsProductId = ctx.body.product_id;\n }\n\n if (checkoutOptions.authenticatedUsersOnly && !session?.user.id) {\n throw new APIError(\"UNAUTHORIZED\", {\n message: \"You must be logged in to checkout\",\n });\n }\n\n try {\n const checkoutUrl = await buildCheckoutUrl({\n body: {\n ...ctx.body,\n product_id: dodoPaymentsProductId,\n customer: {\n email: session?.user.email,\n name: session?.user.name,\n ...ctx.body.customer,\n },\n product_cart: dodoPaymentsProductId\n ? [\n {\n product_id: dodoPaymentsProductId,\n quantity: 1,\n },\n ]\n : undefined,\n metadata: ctx.body.referenceId\n ? {\n referenceId: ctx.body.referenceId,\n ...ctx.body.metadata,\n }\n : ctx.body.metadata,\n },\n bearerToken: dodopayments.bearerToken,\n environment: dodopayments.baseURL.includes(\"test\")\n ? \"test_mode\"\n : \"live_mode\",\n returnUrl: checkoutOptions.successUrl\n ? new URL(\n checkoutOptions.successUrl,\n ctx.request?.url,\n ).toString()\n : undefined,\n type: \"dynamic\",\n });\n\n const redirectUrl = new URL(checkoutUrl);\n\n return ctx.json({\n url: redirectUrl.toString(),\n redirect: true,\n });\n } catch (e: unknown) {\n if (e instanceof Error) {\n ctx.context.logger.error(\n `DodoPayments checkout creation failed. Error: ${e.message}`,\n );\n }\n\n throw new APIError(\"INTERNAL_SERVER_ERROR\", {\n message: \"Checkout creation failed\",\n });\n }\n },\n ),\n dodoCheckoutSession: createAuthEndpoint(\n \"/dodopayments/checkout-session\",\n {\n method: \"POST\",\n body: checkoutSessionPayloadSchema\n .extend({\n slug: z.string().optional(),\n referenceId: z.string().optional(),\n })\n .partial({\n product_cart: true,\n }),\n requireRequest: true,\n },\n async (ctx): Promise<CreateCheckoutResponse> => {\n const session = await getSessionFromCtx(ctx);\n\n let dodoPaymentsProductId: string | undefined;\n\n if (ctx.body?.slug) {\n const resolvedProducts =\n typeof checkoutOptions.products === \"function\"\n ? await checkoutOptions.products()\n : checkoutOptions.products;\n\n const productId = resolvedProducts?.find(\n (product) => product.slug === ctx.body.slug,\n )?.productId;\n\n if (!productId) {\n throw new APIError(\"BAD_REQUEST\", {\n message: \"Product not found\",\n });\n }\n\n dodoPaymentsProductId = productId;\n }\n\n if (checkoutOptions.authenticatedUsersOnly && !session?.user.id) {\n throw new APIError(\"UNAUTHORIZED\", {\n message: \"You must be logged in to checkout\",\n });\n }\n\n // Ensure we have a product_cart\n const product_cart = dodoPaymentsProductId\n ? [{ product_id: dodoPaymentsProductId, quantity: 1 }]\n : ctx.body.product_cart;\n\n if (!product_cart || product_cart.length === 0) {\n throw new APIError(\"BAD_REQUEST\", {\n message: \"Neither product_cart nor slug was provided\",\n });\n }\n\n try {\n const checkoutUrl = await buildCheckoutUrl({\n sessionPayload: {\n ...ctx.body,\n product_cart,\n customer: session?.user.email\n ? {\n email: session?.user.email,\n name: session?.user.name,\n }\n : ctx.body.customer,\n metadata: ctx.body.referenceId\n ? {\n referenceId: ctx.body.referenceId,\n ...ctx.body.metadata,\n }\n : ctx.body.metadata,\n return_url: checkoutOptions.successUrl\n ? new URL(\n checkoutOptions.successUrl,\n ctx.request?.url,\n ).toString()\n : undefined,\n },\n bearerToken: dodopayments.bearerToken,\n environment: dodopayments.baseURL.includes(\"test\")\n ? \"test_mode\"\n : \"live_mode\",\n type: \"session\",\n });\n\n const redirectUrl = new URL(checkoutUrl);\n\n return ctx.json({\n url: redirectUrl.toString(),\n redirect: true,\n });\n } catch (e: unknown) {\n if (e instanceof Error) {\n ctx.context.logger.error(\n `DodoPayments checkout creation failed. Error: ${e.message}`,\n );\n }\n\n throw new APIError(\"INTERNAL_SERVER_ERROR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YACJ,MAAM;AAAA,UACR,CAAC;AAED,gBAAM,cAAc,IAAI,IAAI,WAAW;AAEvC,iBAAO,IAAI,KAAK;AAAA,YACd,KAAK,YAAY,SAAS;AAAA,YAC1B,UAAU;AAAA,UACZ,CAAC;AAAA,QACH,SAAS,GAAY;AACnB,cAAI,aAAa,OAAO;AACtB,gBAAI,QAAQ,OAAO;AAAA,cACjB,iDAAiD,EAAE,OAAO;AAAA,YAC5D;AAAA,UACF;AAEA,gBAAM,IAAI,oBAAS,yBAAyB;AAAA,YAC1C,SAAS;AAAA,UACX,CAAC;AAAA,QACH;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/plugins/checkout.ts"],"sourcesContent":["import type { DodoPaymentsOptions } from \"../types\";\nimport { APIError, createAuthEndpoint, getSessionFromCtx } from \"better-auth/api\";\nimport { z } from \"zod/v3\";\nimport type { CreateCheckoutResponse, Product } from \"../types\";\nimport {\n buildCheckoutUrl,\n checkoutSessionPayloadSchema,\n dynamicCheckoutBodySchema,\n} from \"@dodopayments/core/checkout\";\n\nexport interface CheckoutOptions {\n /**\n * Optional list of slug -> productId mappings for easy slug checkouts\n */\n products?: Product[] | (() => Promise<Product[]>);\n /**\n * Checkout Success URL\n */\n successUrl?: string;\n /**\n * Only allow authenticated customers to checkout\n */\n authenticatedUsersOnly?: boolean;\n}\n\nexport const checkout =\n (checkoutOptions: CheckoutOptions = {}) =>\n (options: DodoPaymentsOptions) => {\n return {\n /**\n * @deprecated\n */\n dodoCheckout: createAuthEndpoint(\n \"/dodopayments/checkout\",\n {\n method: \"POST\",\n body: dynamicCheckoutBodySchema.extend({\n slug: z.string().optional(),\n referenceId: z.string().optional(),\n }),\n requireRequest: true,\n },\n async (ctx): Promise<CreateCheckoutResponse> => {\n const session = await getSessionFromCtx(ctx);\n\n let dodoPaymentsProductId: string | undefined;\n\n if (ctx.body?.slug) {\n const resolvedProducts =\n typeof checkoutOptions.products === \"function\"\n ? await checkoutOptions.products()\n : checkoutOptions.products;\n\n const productId = resolvedProducts?.find(\n (product) => product.slug === ctx.body.slug,\n )?.productId;\n\n if (!productId) {\n throw new APIError(\"BAD_REQUEST\", {\n message: \"Product not found\",\n });\n }\n\n dodoPaymentsProductId = productId;\n } else {\n dodoPaymentsProductId = ctx.body.product_id;\n }\n\n if (checkoutOptions.authenticatedUsersOnly && !session?.user.id) {\n throw new APIError(\"UNAUTHORIZED\", {\n message: \"You must be logged in to checkout\",\n });\n }\n\n try {\n const checkoutUrl = await buildCheckoutUrl({\n body: {\n ...ctx.body,\n product_id: dodoPaymentsProductId,\n customer: {\n email: session?.user.email,\n name: session?.user.name,\n ...ctx.body.customer,\n },\n product_cart: dodoPaymentsProductId\n ? [\n {\n product_id: dodoPaymentsProductId,\n quantity: 1,\n },\n ]\n : undefined,\n metadata: ctx.body.referenceId\n ? {\n referenceId: ctx.body.referenceId,\n ...ctx.body.metadata,\n }\n : ctx.body.metadata,\n },\n bearerToken: options.client.bearerToken,\n environment: options.client.baseURL.includes(\"test\")\n ? \"test_mode\"\n : \"live_mode\",\n returnUrl: checkoutOptions.successUrl\n ? new URL(\n checkoutOptions.successUrl,\n ctx.request?.url,\n ).toString()\n : undefined,\n type: \"dynamic\",\n });\n\n const redirectUrl = new URL(checkoutUrl);\n\n return ctx.json({\n url: redirectUrl.toString(),\n redirect: true,\n });\n } catch (e: unknown) {\n if (e instanceof Error) {\n ctx.context.logger.error(\n `DodoPayments checkout creation failed. Error: ${e.message}`,\n );\n }\n\n throw new APIError(\"INTERNAL_SERVER_ERROR\", {\n message: \"Checkout creation failed\",\n });\n }\n },\n ),\n dodoCheckoutSession: createAuthEndpoint(\n \"/dodopayments/checkout-session\",\n {\n method: \"POST\",\n body: checkoutSessionPayloadSchema\n .extend({\n slug: z.string().optional(),\n referenceId: z.string().optional(),\n })\n .partial({\n product_cart: true,\n }),\n requireRequest: true,\n },\n async (ctx): Promise<CreateCheckoutResponse> => {\n const session = await getSessionFromCtx(ctx);\n\n let dodoPaymentsProductId: string | undefined;\n\n if (ctx.body?.slug) {\n const resolvedProducts =\n typeof checkoutOptions.products === \"function\"\n ? await checkoutOptions.products()\n : checkoutOptions.products;\n\n const productId = resolvedProducts?.find(\n (product) => product.slug === ctx.body.slug,\n )?.productId;\n\n if (!productId) {\n throw new APIError(\"BAD_REQUEST\", {\n message: \"Product not found\",\n });\n }\n\n dodoPaymentsProductId = productId;\n }\n\n if (checkoutOptions.authenticatedUsersOnly && !session?.user.id) {\n throw new APIError(\"UNAUTHORIZED\", {\n message: \"You must be logged in to checkout\",\n });\n }\n\n // Ensure we have a product_cart\n const product_cart = dodoPaymentsProductId\n ? [{ product_id: dodoPaymentsProductId, quantity: 1 }]\n : ctx.body.product_cart;\n\n if (!product_cart || product_cart.length === 0) {\n throw new APIError(\"BAD_REQUEST\", {\n message: \"Neither product_cart nor slug was provided\",\n });\n }\n\n try {\n const checkoutUrl = await buildCheckoutUrl({\n sessionPayload: {\n ...ctx.body,\n product_cart,\n customer: session?.user.email\n ? {\n email: session?.user.email,\n name: session?.user.name,\n }\n : ctx.body.customer,\n metadata: ctx.body.referenceId\n ? {\n referenceId: ctx.body.referenceId,\n ...ctx.body.metadata,\n }\n : ctx.body.metadata,\n return_url: checkoutOptions.successUrl\n ? new URL(\n checkoutOptions.successUrl,\n ctx.request?.url,\n ).toString()\n : undefined,\n },\n bearerToken: options.client.bearerToken,\n environment: options.client.baseURL.includes(\"test\")\n ? \"test_mode\"\n : \"live_mode\",\n type: \"session\",\n });\n\n const redirectUrl = new URL(checkoutUrl);\n\n return ctx.json({\n url: redirectUrl.toString(),\n redirect: true,\n });\n } catch (e: unknown) {\n if (e instanceof Error) {\n ctx.context.logger.error(\n `DodoPayments checkout creation failed. Error: ${e.message}`,\n );\n }\n\n throw new APIError(\"INTERNAL_SERVER_ERROR\", {\n message: \"Checkout session creation failed\",\n });\n }\n },\n ),\n };\n };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAA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WAAW;AAEvC,iBAAO,IAAI,KAAK;AAAA,YACd,KAAK,YAAY,SAAS;AAAA,YAC1B,UAAU;AAAA,UACZ,CAAC;AAAA,QACH,SAAS,GAAY;AACnB,cAAI,aAAa,OAAO;AACtB,gBAAI,QAAQ,OAAO;AAAA,cACjB,iDAAiD,EAAE,OAAO;AAAA,YAC5D;AAAA,UACF;AAEA,gBAAM,IAAI,oBAAS,yBAAyB;AAAA,YAC1C,SAAS;AAAA,UACX,CAAC;AAAA,QACH;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import 'better-auth';
|
|
2
|
-
|
|
2
|
+
export { g as CheckoutOptions, f as checkout } from '../types-D0tVSLaf.cjs';
|
|
3
3
|
import 'zod/v3';
|
|
4
|
-
|
|
4
|
+
import 'dodopayments';
|
|
5
5
|
import '@dodopayments/core/webhook';
|
|
6
|
-
import './usage.cjs';
|
|
7
6
|
import 'dodopayments/resources/usage-events.mjs';
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import 'better-auth';
|
|
2
|
-
|
|
2
|
+
export { g as CheckoutOptions, f as checkout } from '../types-D0tVSLaf.js';
|
|
3
3
|
import 'zod/v3';
|
|
4
|
-
|
|
4
|
+
import 'dodopayments';
|
|
5
5
|
import '@dodopayments/core/webhook';
|
|
6
|
-
import './usage.js';
|
|
7
6
|
import 'dodopayments/resources/usage-events.mjs';
|
package/dist/plugins/checkout.js
CHANGED
package/dist/plugins/portal.cjs
CHANGED
|
@@ -27,7 +27,7 @@ var import_api = require("better-auth/api");
|
|
|
27
27
|
var import_v3 = require("zod/v3");
|
|
28
28
|
|
|
29
29
|
// src/utils.ts
|
|
30
|
-
async function getOrCreateCustomerId(dodopayments, session, internalAdapter) {
|
|
30
|
+
async function getOrCreateCustomerId(dodopayments, session, internalAdapter, getCustomerParams) {
|
|
31
31
|
const dodoCustomerId = session.user["dodoCustomerId"];
|
|
32
32
|
if (dodoCustomerId) return dodoCustomerId;
|
|
33
33
|
const customers = await dodopayments.customers.list({
|
|
@@ -35,9 +35,12 @@ async function getOrCreateCustomerId(dodopayments, session, internalAdapter) {
|
|
|
35
35
|
});
|
|
36
36
|
let customer = customers.items[0];
|
|
37
37
|
if (!customer) {
|
|
38
|
+
const additionalParams = getCustomerParams ? await getCustomerParams(session.user) : void 0;
|
|
38
39
|
customer = await dodopayments.customers.create({
|
|
39
40
|
email: session.user.email,
|
|
40
|
-
name: session.user.name
|
|
41
|
+
name: session.user.name,
|
|
42
|
+
metadata: additionalParams?.metadata,
|
|
43
|
+
phone_number: additionalParams?.phone_number
|
|
41
44
|
}, { idempotencyKey: session.user.id });
|
|
42
45
|
}
|
|
43
46
|
internalAdapter.updateUser(session.user.id, { dodoCustomerId: customer.customer_id }).catch(() => {
|
|
@@ -46,7 +49,7 @@ async function getOrCreateCustomerId(dodopayments, session, internalAdapter) {
|
|
|
46
49
|
}
|
|
47
50
|
|
|
48
51
|
// src/plugins/portal.ts
|
|
49
|
-
var portal = () => (
|
|
52
|
+
var portal = () => (options) => {
|
|
50
53
|
return {
|
|
51
54
|
dodoPortal: (0, import_api.createAuthEndpoint)(
|
|
52
55
|
"/dodopayments/customer/portal",
|
|
@@ -67,11 +70,12 @@ var portal = () => (dodopayments) => {
|
|
|
67
70
|
}
|
|
68
71
|
try {
|
|
69
72
|
const customerId = await getOrCreateCustomerId(
|
|
70
|
-
|
|
73
|
+
options.client,
|
|
71
74
|
ctx.context.session,
|
|
72
|
-
ctx.context.internalAdapter
|
|
75
|
+
ctx.context.internalAdapter,
|
|
76
|
+
options.getCustomerParams
|
|
73
77
|
);
|
|
74
|
-
const customerSession = await
|
|
78
|
+
const customerSession = await options.client.customers.customerPortal.create(customerId);
|
|
75
79
|
return ctx.json({
|
|
76
80
|
url: customerSession.link,
|
|
77
81
|
redirect: true
|
|
@@ -119,11 +123,12 @@ var portal = () => (dodopayments) => {
|
|
|
119
123
|
}
|
|
120
124
|
try {
|
|
121
125
|
const customerId = await getOrCreateCustomerId(
|
|
122
|
-
|
|
126
|
+
options.client,
|
|
123
127
|
ctx.context.session,
|
|
124
|
-
ctx.context.internalAdapter
|
|
128
|
+
ctx.context.internalAdapter,
|
|
129
|
+
options.getCustomerParams
|
|
125
130
|
);
|
|
126
|
-
const subscriptions = await
|
|
131
|
+
const subscriptions = await options.client.subscriptions.list({
|
|
127
132
|
customer_id: customerId,
|
|
128
133
|
// page number is 0-indexed
|
|
129
134
|
page_number: ctx.query?.page ? ctx.query.page - 1 : void 0,
|
|
@@ -179,11 +184,12 @@ var portal = () => (dodopayments) => {
|
|
|
179
184
|
}
|
|
180
185
|
try {
|
|
181
186
|
const customerId = await getOrCreateCustomerId(
|
|
182
|
-
|
|
187
|
+
options.client,
|
|
183
188
|
ctx.context.session,
|
|
184
|
-
ctx.context.internalAdapter
|
|
189
|
+
ctx.context.internalAdapter,
|
|
190
|
+
options.getCustomerParams
|
|
185
191
|
);
|
|
186
|
-
const payments = await
|
|
192
|
+
const payments = await options.client.payments.list({
|
|
187
193
|
customer_id: customerId,
|
|
188
194
|
// page number is 0-indexed
|
|
189
195
|
page_number: ctx.query?.page ? ctx.query.page - 1 : void 0,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/plugins/portal.ts","../../src/utils.ts"],"sourcesContent":["import type { DodoPayments } from \"dodopayments\";\nimport { APIError, createAuthEndpoint, sessionMiddleware } from \"better-auth/api\";\nimport { z } from \"zod/v3\";\nimport {\n CustomerPortalResponse,\n PaymentItems,\n SubscriptionItems,\n} from \"../types\";\nimport { getOrCreateCustomerId } from \"../utils\";\n\nexport const portal = () => (dodopayments: DodoPayments) => {\n return {\n dodoPortal: createAuthEndpoint(\n \"/dodopayments/customer/portal\",\n {\n method: \"GET\",\n use: [sessionMiddleware],\n },\n async (ctx): Promise<CustomerPortalResponse> => {\n if (!ctx.context.session?.user.id) {\n throw new APIError(\"BAD_REQUEST\", {\n message: \"User not found\",\n });\n }\n\n if (!ctx.context.session?.user.emailVerified) {\n throw new APIError(\"UNAUTHORIZED\", {\n message: \"User email not verified\",\n });\n }\n\n try {\n const customerId = await getOrCreateCustomerId(\n dodopayments,\n ctx.context.session,\n ctx.context.internalAdapter,\n );\n\n const customerSession =\n await dodopayments.customers.customerPortal.create(customerId);\n\n return ctx.json({\n url: customerSession.link,\n redirect: true,\n });\n } catch (e: unknown) {\n if (e instanceof Error) {\n ctx.context.logger.error(\n `DodoPayments customer portal creation failed. Error: ${e.message}`,\n );\n }\n\n throw new APIError(\"INTERNAL_SERVER_ERROR\", {\n message: \"Customer portal creation failed\",\n });\n }\n },\n ),\n dodoSubscriptions: createAuthEndpoint(\n \"/dodopayments/customer/subscriptions/list\",\n {\n method: \"GET\",\n query: z\n .object({\n page: z.coerce.number().optional(),\n limit: z.coerce.number().optional(),\n status: z\n .enum([\n \"active\",\n \"cancelled\",\n \"on_hold\",\n \"pending\",\n \"failed\",\n \"expired\",\n ])\n .optional(),\n })\n .optional(),\n use: [sessionMiddleware],\n },\n async (ctx): Promise<SubscriptionItems> => {\n if (!ctx.context.session.user.id) {\n throw new APIError(\"BAD_REQUEST\", {\n message: \"User not found\",\n });\n }\n\n if (!ctx.context.session?.user.emailVerified) {\n throw new APIError(\"UNAUTHORIZED\", {\n message: \"User email not verified\",\n });\n }\n\n try {\n const customerId = await getOrCreateCustomerId(\n dodopayments,\n ctx.context.session,\n ctx.context.internalAdapter,\n );\n\n const subscriptions = await dodopayments.subscriptions.list({\n customer_id: customerId,\n // page number is 0-indexed\n page_number: ctx.query?.page ? ctx.query.page - 1 : undefined,\n page_size: ctx.query?.limit,\n status: ctx.query?.status,\n });\n\n return ctx.json({ items: subscriptions.items });\n } catch (e: unknown) {\n if (e instanceof Error) {\n ctx.context.logger.error(\n `DodoPayments subscriptions list failed. Error: ${e.message}`,\n );\n }\n\n throw new APIError(\"INTERNAL_SERVER_ERROR\", {\n message: \"DodoPayments subscriptions list failed\",\n });\n }\n },\n ),\n dodoPayments: createAuthEndpoint(\n \"/dodopayments/customer/payments/list\",\n {\n method: \"GET\",\n query: z\n .object({\n page: z.coerce.number().optional(),\n limit: z.coerce.number().optional(),\n status: z\n .enum([\n \"succeeded\",\n \"failed\",\n \"cancelled\",\n \"processing\",\n \"requires_customer_action\",\n \"requires_merchant_action\",\n \"requires_payment_method\",\n \"requires_confirmation\",\n \"requires_capture\",\n \"partially_captured\",\n \"partially_captured_and_capturable\",\n ])\n .optional(),\n })\n .optional(),\n use: [sessionMiddleware],\n },\n async (ctx): Promise<PaymentItems> => {\n if (!ctx.context.session.user.id) {\n throw new APIError(\"BAD_REQUEST\", {\n message: \"User not found\",\n });\n }\n\n if (!ctx.context.session?.user.emailVerified) {\n throw new APIError(\"UNAUTHORIZED\", {\n message: \"User email not verified\",\n });\n }\n\n try {\n const customerId = await getOrCreateCustomerId(\n dodopayments,\n ctx.context.session,\n ctx.context.internalAdapter,\n );\n\n const payments = await dodopayments.payments.list({\n customer_id: customerId,\n // page number is 0-indexed\n page_number: ctx.query?.page ? ctx.query.page - 1 : undefined,\n page_size: ctx.query?.limit,\n status: ctx.query?.status,\n });\n\n return ctx.json({ items: payments.items });\n } catch (e: unknown) {\n if (e instanceof Error) {\n ctx.context.logger.error(\n `DodoPayments orders list failed. Error: ${e.message}`,\n );\n }\n\n throw new APIError(\"INTERNAL_SERVER_ERROR\", {\n message: \"Orders list failed\",\n });\n }\n },\n ),\n };\n};\n\n","import type { DodoPayments } from \"dodopayments\";\n\nexport async function getOrCreateCustomerId(\n dodopayments: DodoPayments,\n session: { user: { id: string; email: string; name: string } & Record<string, unknown> },\n internalAdapter: { updateUser: (id: string, data: Record<string, unknown>) => Promise<unknown> },\n): Promise<string> {\n const dodoCustomerId = session.user[\"dodoCustomerId\"] as string | undefined;\n if (dodoCustomerId) return dodoCustomerId;\n\n // Fallback to get customer from email if dodoCustomerId doesn't exist\n const customers = await dodopayments.customers.list({\n email: session.user.email,\n });\n let customer = customers.items[0];\n\n if (!customer) {\n customer = await dodopayments.customers.create({\n email: session.user.email,\n name: session.user.name,\n }, { idempotencyKey: session.user.id });\n }\n\n internalAdapter\n .updateUser(session.user.id, { dodoCustomerId: customer.customer_id })\n .catch(() => {});\n\n return customer.customer_id;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,iBAAgE;AAChE,gBAAkB;;;ACAlB,eAAsB,sBACpB,cACA,SACA,iBACiB;AACjB,QAAM,iBAAiB,QAAQ,KAAK,gBAAgB;AACpD,MAAI,eAAgB,QAAO;AAG3B,QAAM,YAAY,MAAM,aAAa,UAAU,KAAK;AAAA,IAClD,OAAO,QAAQ,KAAK;AAAA,EACtB,CAAC;AACD,MAAI,WAAW,UAAU,MAAM,CAAC;AAEhC,MAAI,CAAC,UAAU;AACb,eAAW,MAAM,aAAa,UAAU,OAAO;AAAA,MAC7C,OAAO,QAAQ,KAAK;AAAA,MACpB,MAAM,QAAQ,KAAK;AAAA,IACrB,GAAG,EAAE,gBAAgB,QAAQ,KAAK,GAAG,CAAC;AAAA,EACxC;AAEA,kBACG,WAAW,QAAQ,KAAK,IAAI,EAAE,gBAAgB,SAAS,YAAY,CAAC,EACpE,MAAM,MAAM;AAAA,EAAC,CAAC;AAEjB,SAAO,SAAS;AAClB;;;ADlBO,IAAM,SAAS,MAAM,CAAC,iBAA+B;AAC1D,SAAO;AAAA,IACL,gBAAY;AAAA,MACV;AAAA,MACA;AAAA,QACE,QAAQ;AAAA,QACR,KAAK,CAAC,4BAAiB;AAAA,MACzB;AAAA,MACA,OAAO,QAAyC;AAC9C,YAAI,CAAC,IAAI,QAAQ,SAAS,KAAK,IAAI;AACjC,gBAAM,IAAI,oBAAS,eAAe;AAAA,YAChC,SAAS;AAAA,UACX,CAAC;AAAA,QACH;AAEA,YAAI,CAAC,IAAI,QAAQ,SAAS,KAAK,eAAe;AAC5C,gBAAM,IAAI,oBAAS,gBAAgB;AAAA,YACjC,SAAS;AAAA,UACX,C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AA,UACX,CAAC;AAAA,QACH;AAEA,YAAI;AACF,gBAAM,aAAa,MAAM;AAAA,YACvB;AAAA,YACA,IAAI,QAAQ;AAAA,YACZ,IAAI,QAAQ;AAAA,UACd;AAEA,gBAAM,WAAW,MAAM,aAAa,SAAS,KAAK;AAAA,YAChD,aAAa;AAAA;AAAA,YAEb,aAAa,IAAI,OAAO,OAAO,IAAI,MAAM,OAAO,IAAI;AAAA,YACpD,WAAW,IAAI,OAAO;AAAA,YACtB,QAAQ,IAAI,OAAO;AAAA,UACrB,CAAC;AAED,iBAAO,IAAI,KAAK,EAAE,OAAO,SAAS,MAAM,CAAC;AAAA,QAC3C,SAAS,GAAY;AACnB,cAAI,aAAa,OAAO;AACtB,gBAAI,QAAQ,OAAO;AAAA,cACjB,2CAA2C,EAAE,OAAO;AAAA,YACtD;AAAA,UACF;AAEA,gBAAM,IAAI,oBAAS,yBAAyB;AAAA,YAC1C,SAAS;AAAA,UACX,CAAC;AAAA,QACH;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/plugins/portal.ts","../../src/utils.ts"],"sourcesContent":["import { APIError, createAuthEndpoint, sessionMiddleware } from \"better-auth/api\";\nimport { z } from \"zod/v3\";\nimport type {\n CustomerPortalResponse,\n DodoPaymentsOptions,\n PaymentItems,\n SubscriptionItems,\n} from \"../types\";\nimport { getOrCreateCustomerId } from \"../utils\";\n\nexport const portal = () => (options: DodoPaymentsOptions) => {\n return {\n dodoPortal: createAuthEndpoint(\n \"/dodopayments/customer/portal\",\n {\n method: \"GET\",\n use: [sessionMiddleware],\n },\n async (ctx): Promise<CustomerPortalResponse> => {\n if (!ctx.context.session?.user.id) {\n throw new APIError(\"BAD_REQUEST\", {\n message: \"User not found\",\n });\n }\n\n if (!ctx.context.session?.user.emailVerified) {\n throw new APIError(\"UNAUTHORIZED\", {\n message: \"User email not verified\",\n });\n }\n\n try {\n const customerId = await getOrCreateCustomerId(\n options.client,\n ctx.context.session,\n ctx.context.internalAdapter,\n options.getCustomerParams,\n );\n\n const customerSession =\n await options.client.customers.customerPortal.create(customerId);\n\n return ctx.json({\n url: customerSession.link,\n redirect: true,\n });\n } catch (e: unknown) {\n if (e instanceof Error) {\n ctx.context.logger.error(\n `DodoPayments customer portal creation failed. Error: ${e.message}`,\n );\n }\n\n throw new APIError(\"INTERNAL_SERVER_ERROR\", {\n message: \"Customer portal creation failed\",\n });\n }\n },\n ),\n dodoSubscriptions: createAuthEndpoint(\n \"/dodopayments/customer/subscriptions/list\",\n {\n method: \"GET\",\n query: z\n .object({\n page: z.coerce.number().optional(),\n limit: z.coerce.number().optional(),\n status: z\n .enum([\n \"active\",\n \"cancelled\",\n \"on_hold\",\n \"pending\",\n \"failed\",\n \"expired\",\n ])\n .optional(),\n })\n .optional(),\n use: [sessionMiddleware],\n },\n async (ctx): Promise<SubscriptionItems> => {\n if (!ctx.context.session.user.id) {\n throw new APIError(\"BAD_REQUEST\", {\n message: \"User not found\",\n });\n }\n\n if (!ctx.context.session?.user.emailVerified) {\n throw new APIError(\"UNAUTHORIZED\", {\n message: \"User email not verified\",\n });\n }\n\n try {\n const customerId = await getOrCreateCustomerId(\n options.client,\n ctx.context.session,\n ctx.context.internalAdapter,\n options.getCustomerParams,\n );\n\n const subscriptions = await options.client.subscriptions.list({\n customer_id: customerId,\n // page number is 0-indexed\n page_number: ctx.query?.page ? ctx.query.page - 1 : undefined,\n page_size: ctx.query?.limit,\n status: ctx.query?.status,\n });\n\n return ctx.json({ items: subscriptions.items });\n } catch (e: unknown) {\n if (e instanceof Error) {\n ctx.context.logger.error(\n `DodoPayments subscriptions list failed. Error: ${e.message}`,\n );\n }\n\n throw new APIError(\"INTERNAL_SERVER_ERROR\", {\n message: \"DodoPayments subscriptions list failed\",\n });\n }\n },\n ),\n dodoPayments: createAuthEndpoint(\n \"/dodopayments/customer/payments/list\",\n {\n method: \"GET\",\n query: z\n .object({\n page: z.coerce.number().optional(),\n limit: z.coerce.number().optional(),\n status: z\n .enum([\n \"succeeded\",\n \"failed\",\n \"cancelled\",\n \"processing\",\n \"requires_customer_action\",\n \"requires_merchant_action\",\n \"requires_payment_method\",\n \"requires_confirmation\",\n \"requires_capture\",\n \"partially_captured\",\n \"partially_captured_and_capturable\",\n ])\n .optional(),\n })\n .optional(),\n use: [sessionMiddleware],\n },\n async (ctx): Promise<PaymentItems> => {\n if (!ctx.context.session.user.id) {\n throw new APIError(\"BAD_REQUEST\", {\n message: \"User not found\",\n });\n }\n\n if (!ctx.context.session?.user.emailVerified) {\n throw new APIError(\"UNAUTHORIZED\", {\n message: \"User email not verified\",\n });\n }\n\n try {\n const customerId = await getOrCreateCustomerId(\n options.client,\n ctx.context.session,\n ctx.context.internalAdapter,\n options.getCustomerParams,\n );\n\n const payments = await options.client.payments.list({\n customer_id: customerId,\n // page number is 0-indexed\n page_number: ctx.query?.page ? ctx.query.page - 1 : undefined,\n page_size: ctx.query?.limit,\n status: ctx.query?.status,\n });\n\n return ctx.json({ items: payments.items });\n } catch (e: unknown) {\n if (e instanceof Error) {\n ctx.context.logger.error(\n `DodoPayments orders list failed. Error: ${e.message}`,\n );\n }\n\n throw new APIError(\"INTERNAL_SERVER_ERROR\", {\n message: \"Orders list failed\",\n });\n }\n },\n ),\n };\n};\n\n","import type { DodoPayments } from \"dodopayments\";\nimport type { User } from \"better-auth\";\n\nexport async function getOrCreateCustomerId(\n dodopayments: DodoPayments,\n session: { user: { id: string; email: string; name: string } & Record<string, unknown> },\n internalAdapter: { updateUser: (id: string, data: Record<string, unknown>) => Promise<unknown> },\n getCustomerParams?: (user: User) => { metadata?: Record<string, string>; phone_number?: string | null } | Promise<{ metadata?: Record<string, string>; phone_number?: string | null }>,\n): Promise<string> {\n const dodoCustomerId = session.user[\"dodoCustomerId\"] as string | undefined;\n if (dodoCustomerId) return dodoCustomerId;\n\n // Fallback to get customer from email if dodoCustomerId doesn't exist\n const customers = await dodopayments.customers.list({\n email: session.user.email,\n });\n let customer = customers.items[0];\n\n if (!customer) {\n const additionalParams = getCustomerParams\n ? await getCustomerParams(session.user as User)\n : undefined;\n\n customer = await dodopayments.customers.create({\n email: session.user.email,\n name: session.user.name,\n metadata: additionalParams?.metadata,\n phone_number: additionalParams?.phone_number,\n }, { idempotencyKey: session.user.id });\n }\n\n internalAdapter\n .updateUser(session.user.id, { dodoCustomerId: customer.customer_id })\n .catch(() => {});\n\n return customer.customer_id;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAAgE;AAChE,gBAAkB;;;ACElB,eAAsB,sBACpB,cACA,SACA,iBACA,mBACiB;AACjB,QAAM,iBAAiB,QAAQ,KAAK,gBAAgB;AACpD,MAAI,eAAgB,QAAO;AAG3B,QAAM,YAAY,MAAM,aAAa,UAAU,KAAK;AAAA,IAClD,OAAO,QAAQ,KAAK;AAAA,EACtB,CAAC;AACD,MAAI,WAAW,UAAU,MAAM,CAAC;AAEhC,MAAI,CAAC,UAAU;AACb,UAAM,mBAAmB,oBACrB,MAAM,kBAAkB,QAAQ,IAAY,IAC5C;AAEJ,eAAW,MAAM,aAAa,UAAU,OAAO;AAAA,MAC7C,OAAO,QAAQ,KAAK;AAAA,MACpB,MAAM,QAAQ,KAAK;AAAA,MACnB,UAAU,kBAAkB;AAAA,MAC5B,cAAc,kBAAkB;AAAA,IAClC,GAAG,EAAE,gBAAgB,QAAQ,KAAK,GAAG,CAAC;AAAA,EACxC;AAEA,kBACG,WAAW,QAAQ,KAAK,IAAI,EAAE,gBAAgB,SAAS,YAAY,CAAC,EACpE,MAAM,MAAM;AAAA,EAAC,CAAC;AAEjB,SAAO,SAAS;AAClB;;;AD1BO,IAAM,SAAS,MAAM,CAAC,YAAiC;AAC5D,SAAO;AAAA,IACL,gBAAY;AAAA,MACV;AAAA,MACA;AAAA,QACE,QAAQ;AAAA,QACR,KAAK,CAAC,4BAAiB;AAAA,MACzB;AAAA,MACA,OAAO,QAAyC;AAC9C,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;AAAA,QACZ,KAAK,CAAC,4BAAiB;AAAA,MACzB;AAAA,MACA,OAAO,QAA+B;AACpC,YAAI,CAAC,IAAI,QAAQ,QAAQ,KAAK,IAAI;AAChC,gBAAM,IAAI,oBAAS,eAAe;AAAA,YAChC,SAAS;AAAA,UACX,CAAC;AAAA,QACH;AAEA,YAAI,CAAC,IAAI,QAAQ,SAAS,KAAK,eAAe;AAC5C,gBAAM,IAAI,oBAAS,gBAAgB;AAAA,YACjC,SAAS;AAAA,UACX,CAAC;AAAA,QACH;AAEA,YAAI;AACF,gBAAM,aAAa,MAAM;AAAA,YACvB,QAAQ;AAAA,YACR,IAAI,QAAQ;AAAA,YACZ,IAAI,QAAQ;AAAA,YACZ,QAAQ;AAAA,UACV;AAEA,gBAAM,WAAW,MAAM,QAAQ,OAAO,SAAS,KAAK;AAAA,YAClD,aAAa;AAAA;AAAA,YAEb,aAAa,IAAI,OAAO,OAAO,IAAI,MAAM,OAAO,IAAI;AAAA,YACpD,WAAW,IAAI,OAAO;AAAA,YACtB,QAAQ,IAAI,OAAO;AAAA,UACrB,CAAC;AAED,iBAAO,IAAI,KAAK,EAAE,OAAO,SAAS,MAAM,CAAC;AAAA,QAC3C,SAAS,GAAY;AACnB,cAAI,aAAa,OAAO;AACtB,gBAAI,QAAQ,OAAO;AAAA,cACjB,2CAA2C,EAAE,OAAO;AAAA,YACtD;AAAA,UACF;AAEA,gBAAM,IAAI,oBAAS,yBAAyB;AAAA,YAC1C,SAAS;AAAA,UACX,CAAC;AAAA,QACH;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import 'better-auth';
|
|
2
|
-
import 'dodopayments';
|
|
3
2
|
import 'zod/v3';
|
|
4
|
-
export { p as portal } from '../types-
|
|
3
|
+
export { p as portal } from '../types-D0tVSLaf.cjs';
|
|
4
|
+
import 'dodopayments';
|
|
5
5
|
import '@dodopayments/core/webhook';
|
|
6
|
-
import './usage.cjs';
|
|
7
6
|
import 'dodopayments/resources/usage-events.mjs';
|
package/dist/plugins/portal.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import 'better-auth';
|
|
2
|
-
import 'dodopayments';
|
|
3
2
|
import 'zod/v3';
|
|
4
|
-
export { p as portal } from '../types-
|
|
3
|
+
export { p as portal } from '../types-D0tVSLaf.js';
|
|
4
|
+
import 'dodopayments';
|
|
5
5
|
import '@dodopayments/core/webhook';
|
|
6
|
-
import './usage.js';
|
|
7
6
|
import 'dodopayments/resources/usage-events.mjs';
|
package/dist/plugins/portal.js
CHANGED
package/dist/plugins/usage.cjs
CHANGED
|
@@ -27,7 +27,7 @@ var import_api = require("better-auth/api");
|
|
|
27
27
|
var import_v3 = require("zod/v3");
|
|
28
28
|
|
|
29
29
|
// src/utils.ts
|
|
30
|
-
async function getOrCreateCustomerId(dodopayments, session, internalAdapter) {
|
|
30
|
+
async function getOrCreateCustomerId(dodopayments, session, internalAdapter, getCustomerParams) {
|
|
31
31
|
const dodoCustomerId = session.user["dodoCustomerId"];
|
|
32
32
|
if (dodoCustomerId) return dodoCustomerId;
|
|
33
33
|
const customers = await dodopayments.customers.list({
|
|
@@ -35,9 +35,12 @@ async function getOrCreateCustomerId(dodopayments, session, internalAdapter) {
|
|
|
35
35
|
});
|
|
36
36
|
let customer = customers.items[0];
|
|
37
37
|
if (!customer) {
|
|
38
|
+
const additionalParams = getCustomerParams ? await getCustomerParams(session.user) : void 0;
|
|
38
39
|
customer = await dodopayments.customers.create({
|
|
39
40
|
email: session.user.email,
|
|
40
|
-
name: session.user.name
|
|
41
|
+
name: session.user.name,
|
|
42
|
+
metadata: additionalParams?.metadata,
|
|
43
|
+
phone_number: additionalParams?.phone_number
|
|
41
44
|
}, { idempotencyKey: session.user.id });
|
|
42
45
|
}
|
|
43
46
|
internalAdapter.updateUser(session.user.id, { dodoCustomerId: customer.customer_id }).catch(() => {
|
|
@@ -54,7 +57,7 @@ var EventInputSchema = import_v3.z.object({
|
|
|
54
57
|
"Custom Timestamp. Defaults to current timestamp in UTC. Timestamps that are older that 1 hour or after 5 mins from current timestamp will be rejected."
|
|
55
58
|
)
|
|
56
59
|
});
|
|
57
|
-
var usage = () => (
|
|
60
|
+
var usage = () => (options) => {
|
|
58
61
|
return {
|
|
59
62
|
// Ingest usage data
|
|
60
63
|
dodoUsageIngest: (0, import_api.createAuthEndpoint)(
|
|
@@ -77,11 +80,12 @@ var usage = () => (dodopayments) => {
|
|
|
77
80
|
}
|
|
78
81
|
try {
|
|
79
82
|
const customerId = await getOrCreateCustomerId(
|
|
80
|
-
|
|
83
|
+
options.client,
|
|
81
84
|
ctx.context.session,
|
|
82
|
-
ctx.context.internalAdapter
|
|
85
|
+
ctx.context.internalAdapter,
|
|
86
|
+
options.getCustomerParams
|
|
83
87
|
);
|
|
84
|
-
const result = await
|
|
88
|
+
const result = await options.client.usageEvents.ingest({
|
|
85
89
|
events: [
|
|
86
90
|
{
|
|
87
91
|
event_id: ctx.body.event_id,
|
|
@@ -133,11 +137,12 @@ var usage = () => (dodopayments) => {
|
|
|
133
137
|
}
|
|
134
138
|
try {
|
|
135
139
|
const customerId = await getOrCreateCustomerId(
|
|
136
|
-
|
|
140
|
+
options.client,
|
|
137
141
|
ctx.context.session,
|
|
138
|
-
ctx.context.internalAdapter
|
|
142
|
+
ctx.context.internalAdapter,
|
|
143
|
+
options.getCustomerParams
|
|
139
144
|
);
|
|
140
|
-
const meters = await
|
|
145
|
+
const meters = await options.client.usageEvents.list({
|
|
141
146
|
customer_id: customerId,
|
|
142
147
|
...ctx.query
|
|
143
148
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/plugins/usage.ts","../../src/utils.ts"],"sourcesContent":["import {\n APIError,\n createAuthEndpoint,\n sessionMiddleware,\n} from \"better-auth/api\";\nimport type {
|
|
1
|
+
{"version":3,"sources":["../../src/plugins/usage.ts","../../src/utils.ts"],"sourcesContent":["import {\n APIError,\n createAuthEndpoint,\n sessionMiddleware,\n} from \"better-auth/api\";\nimport type { DodoPaymentsOptions } from \"../types\";\nimport { Event } from \"dodopayments/resources/usage-events.mjs\";\nimport { z } from \"zod/v3\";\nimport { getOrCreateCustomerId } from \"../utils\";\n\nconst EventInputSchema = z.object({\n event_id: z.string(),\n event_name: z.string(),\n metadata: z\n .record(z.union([z.string(), z.number(), z.boolean()]))\n .nullable()\n .optional(),\n timestamp: z\n // NOTE: coerce because the date object gets converted to a string over network requests\n // but we still want to enforce that it's a Date type\n .date({ coerce: true })\n .transform((d) => d.toISOString())\n .optional()\n .describe(\n \"Custom Timestamp. Defaults to current timestamp in UTC.\\\n Timestamps that are older that 1 hour or after 5 mins from\\\n current timestamp will be rejected.\",\n ),\n});\n\nexport const usage = () => (options: DodoPaymentsOptions) => {\n return {\n // Ingest usage data\n dodoUsageIngest: createAuthEndpoint(\n \"/dodopayments/usage/ingest\",\n {\n method: \"POST\",\n body: EventInputSchema,\n use: [sessionMiddleware],\n },\n async (ctx): Promise<{ ingested_count: number }> => {\n if (!ctx.context.session?.user?.id) {\n throw new APIError(\"BAD_REQUEST\", {\n message: \"User not found\",\n });\n }\n\n if (!ctx.context.session?.user.emailVerified) {\n throw new APIError(\"UNAUTHORIZED\", {\n message: \"User email not verified\",\n });\n }\n\n try {\n const customerId = await getOrCreateCustomerId(\n options.client,\n ctx.context.session,\n ctx.context.internalAdapter,\n options.getCustomerParams,\n );\n\n const result = await options.client.usageEvents.ingest({\n events: [\n {\n event_id: ctx.body.event_id,\n customer_id: customerId,\n event_name: ctx.body.event_name,\n timestamp: ctx.body.timestamp,\n metadata: ctx.body.metadata,\n },\n ],\n });\n\n return ctx.json({ ingested_count: result.ingested_count });\n } catch (e: unknown) {\n if (e instanceof Error) {\n ctx.context.logger.error(\n `User usage ingestion error: ${e.message}`,\n );\n }\n\n throw new APIError(\"INTERNAL_SERVER_ERROR\", {\n message: \"Failed to record the user usage\",\n });\n }\n },\n ),\n\n // List usage meters\n dodoUsageMetersList: createAuthEndpoint(\n \"/dodopayments/usage/meters/list\",\n {\n method: \"GET\",\n query: z\n .object({\n page_number: z.coerce.number().optional(),\n page_size: z.coerce.number().optional(),\n event_name: z.string().optional(),\n meter_id: z.string().optional(),\n start: z.string().optional(),\n end: z.string().optional(),\n })\n .optional(),\n use: [sessionMiddleware],\n },\n async (ctx): Promise<{ items: Event[] }> => {\n if (!ctx.context.session?.user?.id) {\n throw new APIError(\"BAD_REQUEST\", {\n message: \"User not found\",\n });\n }\n\n if (!ctx.context.session?.user.emailVerified) {\n throw new APIError(\"UNAUTHORIZED\", {\n message: \"User email not verified\",\n });\n }\n\n try {\n const customerId = await getOrCreateCustomerId(\n options.client,\n ctx.context.session,\n ctx.context.internalAdapter,\n options.getCustomerParams,\n );\n\n const meters = await options.client.usageEvents.list({\n customer_id: customerId,\n ...ctx.query,\n });\n\n return ctx.json({ items: meters.items });\n } catch (e: unknown) {\n if (e instanceof Error) {\n ctx.context.logger.error(\n `User usage meter list error: ${e.message}`,\n );\n }\n\n throw new APIError(\"INTERNAL_SERVER_ERROR\", {\n message: \"Failed to fetch the user usage\",\n });\n }\n },\n ),\n };\n};\n\n","import type { DodoPayments } from \"dodopayments\";\nimport type { User } from \"better-auth\";\n\nexport async function getOrCreateCustomerId(\n dodopayments: DodoPayments,\n session: { user: { id: string; email: string; name: string } & Record<string, unknown> },\n internalAdapter: { updateUser: (id: string, data: Record<string, unknown>) => Promise<unknown> },\n getCustomerParams?: (user: User) => { metadata?: Record<string, string>; phone_number?: string | null } | Promise<{ metadata?: Record<string, string>; phone_number?: string | null }>,\n): Promise<string> {\n const dodoCustomerId = session.user[\"dodoCustomerId\"] as string | undefined;\n if (dodoCustomerId) return dodoCustomerId;\n\n // Fallback to get customer from email if dodoCustomerId doesn't exist\n const customers = await dodopayments.customers.list({\n email: session.user.email,\n });\n let customer = customers.items[0];\n\n if (!customer) {\n const additionalParams = getCustomerParams\n ? await getCustomerParams(session.user as User)\n : undefined;\n\n customer = await dodopayments.customers.create({\n email: session.user.email,\n name: session.user.name,\n metadata: additionalParams?.metadata,\n phone_number: additionalParams?.phone_number,\n }, { idempotencyKey: session.user.id });\n }\n\n internalAdapter\n .updateUser(session.user.id, { dodoCustomerId: customer.customer_id })\n .catch(() => {});\n\n return customer.customer_id;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAIO;AAGP,gBAAkB;;;ACJlB,eAAsB,sBACpB,cACA,SACA,iBACA,mBACiB;AACjB,QAAM,iBAAiB,QAAQ,KAAK,gBAAgB;AACpD,MAAI,eAAgB,QAAO;AAG3B,QAAM,YAAY,MAAM,aAAa,UAAU,KAAK;AAAA,IAClD,OAAO,QAAQ,KAAK;AAAA,EACtB,CAAC;AACD,MAAI,WAAW,UAAU,MAAM,CAAC;AAEhC,MAAI,CAAC,UAAU;AACb,UAAM,mBAAmB,oBACrB,MAAM,kBAAkB,QAAQ,IAAY,IAC5C;AAEJ,eAAW,MAAM,aAAa,UAAU,OAAO;AAAA,MAC7C,OAAO,QAAQ,KAAK;AAAA,MACpB,MAAM,QAAQ,KAAK;AAAA,MACnB,UAAU,kBAAkB;AAAA,MAC5B,cAAc,kBAAkB;AAAA,IAClC,GAAG,EAAE,gBAAgB,QAAQ,KAAK,GAAG,CAAC;AAAA,EACxC;AAEA,kBACG,WAAW,QAAQ,KAAK,IAAI,EAAE,gBAAgB,SAAS,YAAY,CAAC,EACpE,MAAM,MAAM;AAAA,EAAC,CAAC;AAEjB,SAAO,SAAS;AAClB;;;AD1BA,IAAM,mBAAmB,YAAE,OAAO;AAAA,EAChC,UAAU,YAAE,OAAO;AAAA,EACnB,YAAY,YAAE,OAAO;AAAA,EACrB,UAAU,YACP,OAAO,YAAE,MAAM,CAAC,YAAE,OAAO,GAAG,YAAE,OAAO,GAAG,YAAE,QAAQ,CAAC,CAAC,CAAC,EACrD,SAAS,EACT,SAAS;AAAA,EACZ,WAAW,YAGR,KAAK,E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,SAAS;AAAA,UACX,CAAC;AAAA,QACH;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
package/dist/plugins/usage.d.cts
CHANGED
|
@@ -1,107 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
dodoUsageIngest: better_auth.StrictEndpoint<"/dodopayments/usage/ingest", {
|
|
8
|
-
method: "POST";
|
|
9
|
-
body: z.ZodObject<{
|
|
10
|
-
event_id: z.ZodString;
|
|
11
|
-
event_name: z.ZodString;
|
|
12
|
-
metadata: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean]>>>>;
|
|
13
|
-
timestamp: z.ZodOptional<z.ZodEffects<z.ZodDate, string, Date>>;
|
|
14
|
-
}, "strip", z.ZodTypeAny, {
|
|
15
|
-
event_id: string;
|
|
16
|
-
event_name: string;
|
|
17
|
-
metadata?: Record<string, string | number | boolean> | null | undefined;
|
|
18
|
-
timestamp?: string | undefined;
|
|
19
|
-
}, {
|
|
20
|
-
event_id: string;
|
|
21
|
-
event_name: string;
|
|
22
|
-
metadata?: Record<string, string | number | boolean> | null | undefined;
|
|
23
|
-
timestamp?: Date | undefined;
|
|
24
|
-
}>;
|
|
25
|
-
use: ((inputContext: better_auth.MiddlewareInputContext<better_auth.MiddlewareOptions>) => Promise<{
|
|
26
|
-
session: {
|
|
27
|
-
session: Record<string, any> & {
|
|
28
|
-
id: string;
|
|
29
|
-
createdAt: Date;
|
|
30
|
-
updatedAt: Date;
|
|
31
|
-
userId: string;
|
|
32
|
-
expiresAt: Date;
|
|
33
|
-
token: string;
|
|
34
|
-
ipAddress?: string | null | undefined;
|
|
35
|
-
userAgent?: string | null | undefined;
|
|
36
|
-
};
|
|
37
|
-
user: Record<string, any> & {
|
|
38
|
-
id: string;
|
|
39
|
-
createdAt: Date;
|
|
40
|
-
updatedAt: Date;
|
|
41
|
-
email: string;
|
|
42
|
-
emailVerified: boolean;
|
|
43
|
-
name: string;
|
|
44
|
-
image?: string | null | undefined;
|
|
45
|
-
};
|
|
46
|
-
};
|
|
47
|
-
}>)[];
|
|
48
|
-
} & {
|
|
49
|
-
use: any[];
|
|
50
|
-
}, {
|
|
51
|
-
ingested_count: number;
|
|
52
|
-
}>;
|
|
53
|
-
dodoUsageMetersList: better_auth.StrictEndpoint<"/dodopayments/usage/meters/list", {
|
|
54
|
-
method: "GET";
|
|
55
|
-
query: z.ZodOptional<z.ZodObject<{
|
|
56
|
-
page_number: z.ZodOptional<z.ZodNumber>;
|
|
57
|
-
page_size: z.ZodOptional<z.ZodNumber>;
|
|
58
|
-
event_name: z.ZodOptional<z.ZodString>;
|
|
59
|
-
meter_id: z.ZodOptional<z.ZodString>;
|
|
60
|
-
start: z.ZodOptional<z.ZodString>;
|
|
61
|
-
end: z.ZodOptional<z.ZodString>;
|
|
62
|
-
}, "strip", z.ZodTypeAny, {
|
|
63
|
-
event_name?: string | undefined;
|
|
64
|
-
page_number?: number | undefined;
|
|
65
|
-
page_size?: number | undefined;
|
|
66
|
-
meter_id?: string | undefined;
|
|
67
|
-
start?: string | undefined;
|
|
68
|
-
end?: string | undefined;
|
|
69
|
-
}, {
|
|
70
|
-
event_name?: string | undefined;
|
|
71
|
-
page_number?: number | undefined;
|
|
72
|
-
page_size?: number | undefined;
|
|
73
|
-
meter_id?: string | undefined;
|
|
74
|
-
start?: string | undefined;
|
|
75
|
-
end?: string | undefined;
|
|
76
|
-
}>>;
|
|
77
|
-
use: ((inputContext: better_auth.MiddlewareInputContext<better_auth.MiddlewareOptions>) => Promise<{
|
|
78
|
-
session: {
|
|
79
|
-
session: Record<string, any> & {
|
|
80
|
-
id: string;
|
|
81
|
-
createdAt: Date;
|
|
82
|
-
updatedAt: Date;
|
|
83
|
-
userId: string;
|
|
84
|
-
expiresAt: Date;
|
|
85
|
-
token: string;
|
|
86
|
-
ipAddress?: string | null | undefined;
|
|
87
|
-
userAgent?: string | null | undefined;
|
|
88
|
-
};
|
|
89
|
-
user: Record<string, any> & {
|
|
90
|
-
id: string;
|
|
91
|
-
createdAt: Date;
|
|
92
|
-
updatedAt: Date;
|
|
93
|
-
email: string;
|
|
94
|
-
emailVerified: boolean;
|
|
95
|
-
name: string;
|
|
96
|
-
image?: string | null | undefined;
|
|
97
|
-
};
|
|
98
|
-
};
|
|
99
|
-
}>)[];
|
|
100
|
-
} & {
|
|
101
|
-
use: any[];
|
|
102
|
-
}, {
|
|
103
|
-
items: Event[];
|
|
104
|
-
}>;
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
export { usage };
|
|
1
|
+
import 'better-auth';
|
|
2
|
+
export { u as usage } from '../types-D0tVSLaf.cjs';
|
|
3
|
+
import 'dodopayments/resources/usage-events.mjs';
|
|
4
|
+
import 'zod/v3';
|
|
5
|
+
import 'dodopayments';
|
|
6
|
+
import '@dodopayments/core/webhook';
|
package/dist/plugins/usage.d.ts
CHANGED
|
@@ -1,107 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
dodoUsageIngest: better_auth.StrictEndpoint<"/dodopayments/usage/ingest", {
|
|
8
|
-
method: "POST";
|
|
9
|
-
body: z.ZodObject<{
|
|
10
|
-
event_id: z.ZodString;
|
|
11
|
-
event_name: z.ZodString;
|
|
12
|
-
metadata: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean]>>>>;
|
|
13
|
-
timestamp: z.ZodOptional<z.ZodEffects<z.ZodDate, string, Date>>;
|
|
14
|
-
}, "strip", z.ZodTypeAny, {
|
|
15
|
-
event_id: string;
|
|
16
|
-
event_name: string;
|
|
17
|
-
metadata?: Record<string, string | number | boolean> | null | undefined;
|
|
18
|
-
timestamp?: string | undefined;
|
|
19
|
-
}, {
|
|
20
|
-
event_id: string;
|
|
21
|
-
event_name: string;
|
|
22
|
-
metadata?: Record<string, string | number | boolean> | null | undefined;
|
|
23
|
-
timestamp?: Date | undefined;
|
|
24
|
-
}>;
|
|
25
|
-
use: ((inputContext: better_auth.MiddlewareInputContext<better_auth.MiddlewareOptions>) => Promise<{
|
|
26
|
-
session: {
|
|
27
|
-
session: Record<string, any> & {
|
|
28
|
-
id: string;
|
|
29
|
-
createdAt: Date;
|
|
30
|
-
updatedAt: Date;
|
|
31
|
-
userId: string;
|
|
32
|
-
expiresAt: Date;
|
|
33
|
-
token: string;
|
|
34
|
-
ipAddress?: string | null | undefined;
|
|
35
|
-
userAgent?: string | null | undefined;
|
|
36
|
-
};
|
|
37
|
-
user: Record<string, any> & {
|
|
38
|
-
id: string;
|
|
39
|
-
createdAt: Date;
|
|
40
|
-
updatedAt: Date;
|
|
41
|
-
email: string;
|
|
42
|
-
emailVerified: boolean;
|
|
43
|
-
name: string;
|
|
44
|
-
image?: string | null | undefined;
|
|
45
|
-
};
|
|
46
|
-
};
|
|
47
|
-
}>)[];
|
|
48
|
-
} & {
|
|
49
|
-
use: any[];
|
|
50
|
-
}, {
|
|
51
|
-
ingested_count: number;
|
|
52
|
-
}>;
|
|
53
|
-
dodoUsageMetersList: better_auth.StrictEndpoint<"/dodopayments/usage/meters/list", {
|
|
54
|
-
method: "GET";
|
|
55
|
-
query: z.ZodOptional<z.ZodObject<{
|
|
56
|
-
page_number: z.ZodOptional<z.ZodNumber>;
|
|
57
|
-
page_size: z.ZodOptional<z.ZodNumber>;
|
|
58
|
-
event_name: z.ZodOptional<z.ZodString>;
|
|
59
|
-
meter_id: z.ZodOptional<z.ZodString>;
|
|
60
|
-
start: z.ZodOptional<z.ZodString>;
|
|
61
|
-
end: z.ZodOptional<z.ZodString>;
|
|
62
|
-
}, "strip", z.ZodTypeAny, {
|
|
63
|
-
event_name?: string | undefined;
|
|
64
|
-
page_number?: number | undefined;
|
|
65
|
-
page_size?: number | undefined;
|
|
66
|
-
meter_id?: string | undefined;
|
|
67
|
-
start?: string | undefined;
|
|
68
|
-
end?: string | undefined;
|
|
69
|
-
}, {
|
|
70
|
-
event_name?: string | undefined;
|
|
71
|
-
page_number?: number | undefined;
|
|
72
|
-
page_size?: number | undefined;
|
|
73
|
-
meter_id?: string | undefined;
|
|
74
|
-
start?: string | undefined;
|
|
75
|
-
end?: string | undefined;
|
|
76
|
-
}>>;
|
|
77
|
-
use: ((inputContext: better_auth.MiddlewareInputContext<better_auth.MiddlewareOptions>) => Promise<{
|
|
78
|
-
session: {
|
|
79
|
-
session: Record<string, any> & {
|
|
80
|
-
id: string;
|
|
81
|
-
createdAt: Date;
|
|
82
|
-
updatedAt: Date;
|
|
83
|
-
userId: string;
|
|
84
|
-
expiresAt: Date;
|
|
85
|
-
token: string;
|
|
86
|
-
ipAddress?: string | null | undefined;
|
|
87
|
-
userAgent?: string | null | undefined;
|
|
88
|
-
};
|
|
89
|
-
user: Record<string, any> & {
|
|
90
|
-
id: string;
|
|
91
|
-
createdAt: Date;
|
|
92
|
-
updatedAt: Date;
|
|
93
|
-
email: string;
|
|
94
|
-
emailVerified: boolean;
|
|
95
|
-
name: string;
|
|
96
|
-
image?: string | null | undefined;
|
|
97
|
-
};
|
|
98
|
-
};
|
|
99
|
-
}>)[];
|
|
100
|
-
} & {
|
|
101
|
-
use: any[];
|
|
102
|
-
}, {
|
|
103
|
-
items: Event[];
|
|
104
|
-
}>;
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
export { usage };
|
|
1
|
+
import 'better-auth';
|
|
2
|
+
export { u as usage } from '../types-D0tVSLaf.js';
|
|
3
|
+
import 'dodopayments/resources/usage-events.mjs';
|
|
4
|
+
import 'zod/v3';
|
|
5
|
+
import 'dodopayments';
|
|
6
|
+
import '@dodopayments/core/webhook';
|