@dodopayments/better-auth 1.3.3 → 1.3.5
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/chunk-CRRND2EH.js +67 -0
- package/dist/chunk-CRRND2EH.js.map +1 -0
- package/dist/chunk-HHIXOUFD.js +80 -0
- package/dist/chunk-HHIXOUFD.js.map +1 -0
- package/dist/chunk-J55PDPLE.js +196 -0
- package/dist/chunk-J55PDPLE.js.map +1 -0
- package/dist/chunk-O3BTJOIO.js +177 -0
- package/dist/chunk-O3BTJOIO.js.map +1 -0
- package/dist/chunk-PXI4EHZC.js +12 -0
- package/dist/chunk-PXI4EHZC.js.map +1 -0
- package/dist/client.cjs +36 -0
- package/dist/client.cjs.map +1 -0
- package/dist/client.d.cts +7 -0
- package/dist/client.d.ts +7 -5
- package/dist/client.js +6 -5
- package/dist/client.js.map +1 -0
- package/dist/hooks/customer.cjs +92 -0
- package/dist/hooks/customer.cjs.map +1 -0
- package/dist/hooks/customer.d.cts +11 -0
- package/dist/hooks/customer.d.ts +11 -4
- package/dist/hooks/customer.js +8 -62
- package/dist/hooks/customer.js.map +1 -0
- package/dist/index.cjs +573 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +909 -0
- package/dist/index.d.ts +321 -200
- package/dist/index.js +53 -34
- package/dist/index.js.map +1 -0
- package/dist/plugins/checkout.cjs +197 -0
- package/dist/plugins/checkout.cjs.map +1 -0
- package/dist/plugins/checkout.d.cts +6 -0
- package/dist/plugins/checkout.d.ts +6 -548
- package/dist/plugins/checkout.js +6 -170
- package/dist/plugins/checkout.js.map +1 -0
- package/dist/plugins/portal.cjs +220 -0
- package/dist/plugins/portal.cjs.map +1 -0
- package/dist/plugins/portal.d.cts +6 -0
- package/dist/plugins/portal.d.ts +6 -204
- package/dist/plugins/portal.js +6 -171
- package/dist/plugins/portal.js.map +1 -0
- package/dist/plugins/webhooks.cjs +102 -0
- package/dist/plugins/webhooks.cjs.map +1 -0
- package/dist/plugins/webhooks.d.cts +6 -0
- package/dist/plugins/webhooks.d.ts +6 -41
- package/dist/plugins/webhooks.js +6 -61
- package/dist/plugins/webhooks.js.map +1 -0
- package/dist/types-yAk7fHrK.d.cts +953 -0
- package/dist/types-yAk7fHrK.d.ts +953 -0
- package/dist/types.cjs +19 -0
- package/dist/types.cjs.map +1 -0
- package/dist/types.d.cts +6 -0
- package/dist/types.d.ts +6 -52
- package/dist/types.js +1 -1
- package/dist/types.js.map +1 -0
- package/package.json +5 -10
package/dist/client.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
export { dodopaymentsClient } from './index.js';
|
|
2
|
+
import 'better-auth';
|
|
3
|
+
import './types-yAk7fHrK.js';
|
|
4
|
+
import 'dodopayments';
|
|
5
|
+
import 'better-call';
|
|
6
|
+
import 'zod/v3';
|
|
7
|
+
import '@dodopayments/core/webhook';
|
package/dist/client.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,92 @@
|
|
|
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/hooks/customer.ts
|
|
21
|
+
var customer_exports = {};
|
|
22
|
+
__export(customer_exports, {
|
|
23
|
+
onUserCreate: () => onUserCreate,
|
|
24
|
+
onUserUpdate: () => onUserUpdate
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(customer_exports);
|
|
27
|
+
var import_api = require("better-auth/api");
|
|
28
|
+
var onUserCreate = (options) => async (user, ctx) => {
|
|
29
|
+
if (ctx && options.createCustomerOnSignUp) {
|
|
30
|
+
try {
|
|
31
|
+
const customers = await options.client.customers.list({
|
|
32
|
+
email: user.email
|
|
33
|
+
});
|
|
34
|
+
const existingCustomer = customers.items[0];
|
|
35
|
+
if (existingCustomer) {
|
|
36
|
+
if (existingCustomer.email !== user.email) {
|
|
37
|
+
await options.client.customers.update(
|
|
38
|
+
existingCustomer.customer_id,
|
|
39
|
+
{
|
|
40
|
+
name: user.name
|
|
41
|
+
}
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
} else {
|
|
45
|
+
await options.client.customers.create({
|
|
46
|
+
email: user.email,
|
|
47
|
+
name: user.name
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
} catch (e) {
|
|
51
|
+
if (e instanceof Error) {
|
|
52
|
+
throw new import_api.APIError("INTERNAL_SERVER_ERROR", {
|
|
53
|
+
message: `DodoPayments customer creation failed. Error: ${e.message}`
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
throw new import_api.APIError("INTERNAL_SERVER_ERROR", {
|
|
57
|
+
message: `DodoPayments customer creation failed. Error: ${e}`
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
var onUserUpdate = (options) => async (user, ctx) => {
|
|
63
|
+
if (ctx && options.createCustomerOnSignUp) {
|
|
64
|
+
try {
|
|
65
|
+
const customers = await options.client.customers.list({
|
|
66
|
+
email: user.email
|
|
67
|
+
});
|
|
68
|
+
const existingCustomer = customers.items[0];
|
|
69
|
+
if (existingCustomer) {
|
|
70
|
+
await options.client.customers.update(existingCustomer.customer_id, {
|
|
71
|
+
name: user.name
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
} catch (e) {
|
|
75
|
+
if (e instanceof Error) {
|
|
76
|
+
ctx.context.logger.error(
|
|
77
|
+
`DodoPayments customer update failed. Error: ${e.message}`
|
|
78
|
+
);
|
|
79
|
+
} else {
|
|
80
|
+
ctx.context.logger.error(
|
|
81
|
+
`DodoPayments customer update failed. Error: ${e}`
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
88
|
+
0 && (module.exports = {
|
|
89
|
+
onUserCreate,
|
|
90
|
+
onUserUpdate
|
|
91
|
+
});
|
|
92
|
+
//# sourceMappingURL=customer.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/customer.ts"],"sourcesContent":["import type { GenericEndpointContext, User } from \"better-auth\";\nimport { APIError } from \"better-auth/api\";\nimport type { DodoPaymentsOptions } from \"../types\";\n\nexport const onUserCreate =\n (options: DodoPaymentsOptions) =>\n async (user: User, ctx?: GenericEndpointContext) => {\n if (ctx && options.createCustomerOnSignUp) {\n try {\n const customers = await options.client.customers.list({\n email: user.email,\n });\n const existingCustomer = customers.items[0];\n\n if (existingCustomer) {\n if (existingCustomer.email !== user.email) {\n await options.client.customers.update(\n existingCustomer.customer_id,\n {\n name: user.name,\n },\n );\n }\n } else {\n // TODO: Add metadata to customer object via\n // getCustomerCreateParams option when it becomes\n // available in the API\n await options.client.customers.create({\n email: user.email,\n name: user.name,\n });\n }\n } catch (e: unknown) {\n if (e instanceof Error) {\n throw new APIError(\"INTERNAL_SERVER_ERROR\", {\n message: `DodoPayments customer creation failed. Error: ${e.message}`,\n });\n }\n\n throw new APIError(\"INTERNAL_SERVER_ERROR\", {\n message: `DodoPayments customer creation failed. Error: ${e}`,\n });\n }\n }\n };\n\nexport const onUserUpdate =\n (options: DodoPaymentsOptions) =>\n async (user: User, ctx?: GenericEndpointContext) => {\n if (ctx && options.createCustomerOnSignUp) {\n try {\n const customers = await options.client.customers.list({\n email: user.email,\n });\n const existingCustomer = customers.items[0];\n\n if (existingCustomer) {\n // TODO: Add metadata to customer object via\n // getCustomerCreateParams option when it becomes\n // available in the API\n await options.client.customers.update(existingCustomer.customer_id, {\n name: user.name,\n });\n }\n } catch (e: unknown) {\n if (e instanceof Error) {\n ctx.context.logger.error(\n `DodoPayments customer update failed. Error: ${e.message}`,\n );\n } else {\n ctx.context.logger.error(\n `DodoPayments customer update failed. Error: ${e}`,\n );\n }\n }\n }\n };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,iBAAyB;AAGlB,IAAM,eACX,CAAC,YACD,OAAO,MAAY,QAAiC;AAClD,MAAI,OAAO,QAAQ,wBAAwB;AACzC,QAAI;AACF,YAAM,YAAY,MAAM,QAAQ,OAAO,UAAU,KAAK;AAAA,QACpD,OAAO,KAAK;AAAA,MACd,CAAC;AACD,YAAM,mBAAmB,UAAU,MAAM,CAAC;AAE1C,UAAI,kBAAkB;AACpB,YAAI,iBAAiB,UAAU,KAAK,OAAO;AACzC,gBAAM,QAAQ,OAAO,UAAU;AAAA,YAC7B,iBAAiB;AAAA,YACjB;AAAA,cACE,MAAM,KAAK;AAAA,YACb;AAAA,UACF;AAAA,QACF;AAAA,MACF,OAAO;AAIL,cAAM,QAAQ,OAAO,UAAU,OAAO;AAAA,UACpC,OAAO,KAAK;AAAA,UACZ,MAAM,KAAK;AAAA,QACb,CAAC;AAAA,MACH;AAAA,IACF,SAAS,GAAY;AACnB,UAAI,aAAa,OAAO;AACtB,cAAM,IAAI,oBAAS,yBAAyB;AAAA,UAC1C,SAAS,iDAAiD,EAAE,OAAO;AAAA,QACrE,CAAC;AAAA,MACH;AAEA,YAAM,IAAI,oBAAS,yBAAyB;AAAA,QAC1C,SAAS,iDAAiD,CAAC;AAAA,MAC7D,CAAC;AAAA,IACH;AAAA,EACF;AACF;AAEK,IAAM,eACX,CAAC,YACD,OAAO,MAAY,QAAiC;AAClD,MAAI,OAAO,QAAQ,wBAAwB;AACzC,QAAI;AACF,YAAM,YAAY,MAAM,QAAQ,OAAO,UAAU,KAAK;AAAA,QACpD,OAAO,KAAK;AAAA,MACd,CAAC;AACD,YAAM,mBAAmB,UAAU,MAAM,CAAC;AAE1C,UAAI,kBAAkB;AAIpB,cAAM,QAAQ,OAAO,UAAU,OAAO,iBAAiB,aAAa;AAAA,UAClE,MAAM,KAAK;AAAA,QACb,CAAC;AAAA,MACH;AAAA,IACF,SAAS,GAAY;AACnB,UAAI,aAAa,OAAO;AACtB,YAAI,QAAQ,OAAO;AAAA,UACjB,+CAA+C,EAAE,OAAO;AAAA,QAC1D;AAAA,MACF,OAAO;AACL,YAAI,QAAQ,OAAO;AAAA,UACjB,+CAA+C,CAAC;AAAA,QAClD;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { User, GenericEndpointContext } from 'better-auth';
|
|
2
|
+
import { D as DodoPaymentsOptions } from '../types-yAk7fHrK.cjs';
|
|
3
|
+
import 'dodopayments';
|
|
4
|
+
import 'better-call';
|
|
5
|
+
import 'zod/v3';
|
|
6
|
+
import '@dodopayments/core/webhook';
|
|
7
|
+
|
|
8
|
+
declare const onUserCreate: (options: DodoPaymentsOptions) => (user: User, ctx?: GenericEndpointContext) => Promise<void>;
|
|
9
|
+
declare const onUserUpdate: (options: DodoPaymentsOptions) => (user: User, ctx?: GenericEndpointContext) => Promise<void>;
|
|
10
|
+
|
|
11
|
+
export { onUserCreate, onUserUpdate };
|
package/dist/hooks/customer.d.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { User, GenericEndpointContext } from 'better-auth';
|
|
2
|
+
import { D as DodoPaymentsOptions } from '../types-yAk7fHrK.js';
|
|
3
|
+
import 'dodopayments';
|
|
4
|
+
import 'better-call';
|
|
5
|
+
import 'zod/v3';
|
|
6
|
+
import '@dodopayments/core/webhook';
|
|
7
|
+
|
|
8
|
+
declare const onUserCreate: (options: DodoPaymentsOptions) => (user: User, ctx?: GenericEndpointContext) => Promise<void>;
|
|
9
|
+
declare const onUserUpdate: (options: DodoPaymentsOptions) => (user: User, ctx?: GenericEndpointContext) => Promise<void>;
|
|
10
|
+
|
|
11
|
+
export { onUserCreate, onUserUpdate };
|
package/dist/hooks/customer.js
CHANGED
|
@@ -1,63 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const existingCustomer = customers.items[0];
|
|
9
|
-
if (existingCustomer) {
|
|
10
|
-
if (existingCustomer.email !== user.email) {
|
|
11
|
-
await options.client.customers.update(existingCustomer.customer_id, {
|
|
12
|
-
name: user.name,
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
else {
|
|
17
|
-
// TODO: Add metadata to customer object via
|
|
18
|
-
// getCustomerCreateParams option when it becomes
|
|
19
|
-
// available in the API
|
|
20
|
-
await options.client.customers.create({
|
|
21
|
-
email: user.email,
|
|
22
|
-
name: user.name,
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
catch (e) {
|
|
27
|
-
if (e instanceof Error) {
|
|
28
|
-
throw new APIError("INTERNAL_SERVER_ERROR", {
|
|
29
|
-
message: `DodoPayments customer creation failed. Error: ${e.message}`,
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
throw new APIError("INTERNAL_SERVER_ERROR", {
|
|
33
|
-
message: `DodoPayments customer creation failed. Error: ${e}`,
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
export const onUserUpdate = (options) => async (user, ctx) => {
|
|
39
|
-
if (ctx && options.createCustomerOnSignUp) {
|
|
40
|
-
try {
|
|
41
|
-
const customers = await options.client.customers.list({
|
|
42
|
-
email: user.email,
|
|
43
|
-
});
|
|
44
|
-
const existingCustomer = customers.items[0];
|
|
45
|
-
if (existingCustomer) {
|
|
46
|
-
// TODO: Add metadata to customer object via
|
|
47
|
-
// getCustomerCreateParams option when it becomes
|
|
48
|
-
// available in the API
|
|
49
|
-
await options.client.customers.update(existingCustomer.customer_id, {
|
|
50
|
-
name: user.name,
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
catch (e) {
|
|
55
|
-
if (e instanceof Error) {
|
|
56
|
-
ctx.context.logger.error(`DodoPayments customer update failed. Error: ${e.message}`);
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
ctx.context.logger.error(`DodoPayments customer update failed. Error: ${e}`);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
onUserCreate,
|
|
3
|
+
onUserUpdate
|
|
4
|
+
} from "../chunk-CRRND2EH.js";
|
|
5
|
+
export {
|
|
6
|
+
onUserCreate,
|
|
7
|
+
onUserUpdate
|
|
63
8
|
};
|
|
9
|
+
//# sourceMappingURL=customer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|