@dymo-api/better-auth 1.2.28 → 1.2.29
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/cjs/index.cjs +15334 -8
- package/dist/esm/index.js +15335 -3
- package/dist/types/index.d.ts +4 -3
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/plugins/emailValidation/index.d.ts +3 -2
- package/dist/types/plugins/emailValidation/index.d.ts.map +1 -0
- package/dist/types/plugins/ipValidation/index.d.ts +3 -2
- package/dist/types/plugins/ipValidation/index.d.ts.map +1 -0
- package/dist/types/plugins/phoneValidation/index.d.ts +3 -2
- package/dist/types/plugins/phoneValidation/index.d.ts.map +1 -0
- package/package.json +8 -9
- package/dist/cjs/plugins/emailValidation/index.cjs +0 -69
- package/dist/cjs/plugins/ipValidation/index.cjs +0 -79
- package/dist/cjs/plugins/phoneValidation/index.cjs +0 -62
- package/dist/esm/plugins/emailValidation/index.js +0 -62
- package/dist/esm/plugins/ipValidation/index.js +0 -72
- package/dist/esm/plugins/phoneValidation/index.js +0 -55
package/dist/types/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
export { dymoEmailPlugin } from
|
|
2
|
-
export { dymoIPPlugin } from
|
|
3
|
-
export { dymoPhonePlugin } from
|
|
1
|
+
export { dymoEmailPlugin } from './plugins/emailValidation';
|
|
2
|
+
export { dymoIPPlugin } from './plugins/ipValidation';
|
|
3
|
+
export { dymoPhonePlugin } from './plugins/phoneValidation';
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EmailValidatorRules, ResilienceConfig } from
|
|
1
|
+
import { EmailValidatorRules, ResilienceConfig } from 'dymo-api';
|
|
2
2
|
interface DymoEmailPluginOptions {
|
|
3
3
|
apiKey: string;
|
|
4
4
|
applyToLogin?: boolean;
|
|
@@ -12,10 +12,11 @@ export declare const dymoEmailPlugin: ({ apiKey, applyToLogin, applyToOAuth, ema
|
|
|
12
12
|
hooks: {
|
|
13
13
|
before: {
|
|
14
14
|
matcher: (context: any) => boolean;
|
|
15
|
-
handler: (inputContext: import(
|
|
15
|
+
handler: (inputContext: import('better-call').MiddlewareInputContext<import('better-call').MiddlewareOptions>) => Promise<{
|
|
16
16
|
context: any;
|
|
17
17
|
}>;
|
|
18
18
|
}[];
|
|
19
19
|
};
|
|
20
20
|
};
|
|
21
21
|
export {};
|
|
22
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/plugins/emailValidation/index.ts"],"names":[],"mappings":"AAEA,OAAgB,EAAsB,mBAAmB,EAA+B,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE3H,UAAU,sBAAsB;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,UAAU,CAAC,EAAE,OAAO,CAAC,mBAAmB,CAAC,CAAC;IAC1C,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,UAAU,CAAC,EAAE,gBAAgB,CAAC;CACjC;AAED,eAAO,MAAM,eAAe,GAAI,2EAO7B,sBAAsB;;;;+BAwCc,GAAG;;;;;;CAwBzC,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IPValidatorRules, ResilienceConfig } from
|
|
1
|
+
import { IPValidatorRules, ResilienceConfig } from 'dymo-api';
|
|
2
2
|
interface dymoIPPluginOptions {
|
|
3
3
|
apiKey: string;
|
|
4
4
|
applyToLogin?: boolean;
|
|
@@ -12,10 +12,11 @@ export declare const dymoIPPlugin: ({ apiKey, applyToLogin, applyToOAuth, ipRule
|
|
|
12
12
|
hooks: {
|
|
13
13
|
before: {
|
|
14
14
|
matcher: (context: any) => boolean;
|
|
15
|
-
handler: (inputContext: import(
|
|
15
|
+
handler: (inputContext: import('better-call').MiddlewareInputContext<import('better-call').MiddlewareOptions>) => Promise<{
|
|
16
16
|
context: any;
|
|
17
17
|
}>;
|
|
18
18
|
}[];
|
|
19
19
|
};
|
|
20
20
|
};
|
|
21
21
|
export {};
|
|
22
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/plugins/ipValidation/index.ts"],"names":[],"mappings":"AAEA,OAAgB,EAAmB,gBAAgB,EAA4B,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAElH,UAAU,mBAAmB;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,OAAO,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC,CAAC;IACpC,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,UAAU,CAAC,EAAE,gBAAgB,CAAC;CACjC;AAID,eAAO,MAAM,YAAY,GAAI,wEAO1B,mBAAmB;;;;+BAwCiB,GAAG;;;;;;CAkCzC,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PhoneValidatorRules, ResilienceConfig } from
|
|
1
|
+
import { PhoneValidatorRules, ResilienceConfig } from 'dymo-api';
|
|
2
2
|
interface DymoPhonePluginOptions {
|
|
3
3
|
apiKey: string;
|
|
4
4
|
applyToLogin?: boolean;
|
|
@@ -12,10 +12,11 @@ export declare const dymoPhonePlugin: ({ apiKey, applyToLogin, applyToOAuth, pho
|
|
|
12
12
|
hooks: {
|
|
13
13
|
before: {
|
|
14
14
|
matcher: (context: any) => boolean;
|
|
15
|
-
handler: (inputContext: import(
|
|
15
|
+
handler: (inputContext: import('better-call').MiddlewareInputContext<import('better-call').MiddlewareOptions>) => Promise<{
|
|
16
16
|
context: any;
|
|
17
17
|
}>;
|
|
18
18
|
}[];
|
|
19
19
|
};
|
|
20
20
|
};
|
|
21
21
|
export {};
|
|
22
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/plugins/phoneValidation/index.ts"],"names":[],"mappings":"AAEA,OAAgB,EAAsB,mBAAmB,EAA+B,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE3H,UAAU,sBAAsB;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,UAAU,CAAC,EAAE,OAAO,CAAC,mBAAmB,CAAC,CAAC;IAC1C,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,UAAU,CAAC,EAAE,gBAAgB,CAAC;CACjC;AAED,eAAO,MAAM,eAAe,GAAI,2EAO7B,sBAAsB;;;;+BAiCc,GAAG;;;;;;CAwBzC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dymo-api/better-auth",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.29",
|
|
4
4
|
"description": "Flow system for Dymo API.",
|
|
5
|
-
"main": "dist/cjs/index.
|
|
5
|
+
"main": "dist/cjs/index.cjs",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
7
7
|
"types": "dist/types/index.d.ts",
|
|
8
8
|
"type": "module",
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
|
+
"types": "./dist/types/index.d.ts",
|
|
11
12
|
"require": "./dist/cjs/index.cjs",
|
|
12
|
-
"import": "./dist/esm/index.js"
|
|
13
|
-
"types": "./dist/types/index.d.ts"
|
|
13
|
+
"import": "./dist/esm/index.js"
|
|
14
14
|
},
|
|
15
15
|
"./*": {
|
|
16
16
|
"require": "./dist/cjs/**/*.cjs",
|
|
@@ -24,9 +24,7 @@
|
|
|
24
24
|
],
|
|
25
25
|
"scripts": {
|
|
26
26
|
"clean": "rimraf dist",
|
|
27
|
-
"build
|
|
28
|
-
"build:esm": "tsc -p tsconfig.esm.json && tsc-alias -p tsconfig.esm.json",
|
|
29
|
-
"build": "npm run clean && npm run build:cjs && npm run build:esm && node ./scripts/rename.js",
|
|
27
|
+
"build": "npm run clean && vite build",
|
|
30
28
|
"start": "ts-node src/index.ts",
|
|
31
29
|
"prepublishOnly": "npm run build",
|
|
32
30
|
"test": "vitest"
|
|
@@ -59,7 +57,7 @@
|
|
|
59
57
|
"homepage": "https://dymo.tpeoficial.com",
|
|
60
58
|
"dependencies": {
|
|
61
59
|
"better-auth": "^1.3.23",
|
|
62
|
-
"dymo-api": "^1.2.
|
|
60
|
+
"dymo-api": "^1.2.35",
|
|
63
61
|
"path": "^0.12.7"
|
|
64
62
|
},
|
|
65
63
|
"contributors": [
|
|
@@ -74,8 +72,9 @@
|
|
|
74
72
|
"rimraf": "^6.0.1",
|
|
75
73
|
"ts-jest": "^29.4.4",
|
|
76
74
|
"ts-node": "^10.9.2",
|
|
77
|
-
"tsc-alias": "^1.8.16",
|
|
78
75
|
"typescript": "^5.5.4",
|
|
76
|
+
"vite": "^6.4.1",
|
|
77
|
+
"vite-plugin-dts": "^4.5.4",
|
|
79
78
|
"vitest": "^3.2.4"
|
|
80
79
|
},
|
|
81
80
|
"prettier": {
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.dymoEmailPlugin = void 0;
|
|
7
|
-
const api_1 = require("better-auth/api");
|
|
8
|
-
const dymo_api_1 = __importDefault(require("dymo-api"));
|
|
9
|
-
const dymoEmailPlugin = ({ apiKey, applyToLogin = false, applyToOAuth = true, emailRules, normalize = true, resilience }) => {
|
|
10
|
-
const defaultRules = {
|
|
11
|
-
deny: ["FRAUD", "INVALID", "NO_MX_RECORDS", "NO_REPLY_EMAIL"]
|
|
12
|
-
};
|
|
13
|
-
const dymoClient = new dymo_api_1.default({
|
|
14
|
-
apiKey,
|
|
15
|
-
rules: {
|
|
16
|
-
email: {
|
|
17
|
-
deny: emailRules?.deny ?? defaultRules.deny
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
resilience
|
|
21
|
-
});
|
|
22
|
-
const activePaths = [
|
|
23
|
-
"/sign-up/email",
|
|
24
|
-
"/email-otp/verify-email",
|
|
25
|
-
"/sign-in/email-otp",
|
|
26
|
-
"/sign-in/magic-link",
|
|
27
|
-
"/forget-password/email-otp",
|
|
28
|
-
"/email-otp/reset-password",
|
|
29
|
-
"/email-otp/create-verification-otp",
|
|
30
|
-
"/email-otp/get-verification-otp",
|
|
31
|
-
"/email-otp/send-verification-otp",
|
|
32
|
-
"/forget-password",
|
|
33
|
-
"/send-verification-email",
|
|
34
|
-
"/change-email"
|
|
35
|
-
];
|
|
36
|
-
if (applyToLogin)
|
|
37
|
-
activePaths.push("/sign-in/email");
|
|
38
|
-
if (applyToOAuth) {
|
|
39
|
-
activePaths.push("/sign-up/oauth");
|
|
40
|
-
activePaths.push("/sign-in/oauth");
|
|
41
|
-
}
|
|
42
|
-
return {
|
|
43
|
-
id: "dymoEmailPlugin",
|
|
44
|
-
hooks: {
|
|
45
|
-
before: [
|
|
46
|
-
{
|
|
47
|
-
matcher: (context) => activePaths.some(path => context.path.startsWith(path)),
|
|
48
|
-
handler: (0, api_1.createAuthMiddleware)(async (ctx) => {
|
|
49
|
-
const email = ctx.body?.email || ctx.body?.profile?.email;
|
|
50
|
-
if (typeof email !== "string")
|
|
51
|
-
throw new api_1.APIError("BAD_REQUEST", { message: "Email must be a string." });
|
|
52
|
-
const decision = await dymoClient.isValidEmail(email);
|
|
53
|
-
if (!decision.allow) {
|
|
54
|
-
throw new api_1.APIError("BAD_REQUEST", {
|
|
55
|
-
message: "Email is invalid or blocked.",
|
|
56
|
-
reasons: decision.reasons
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
if (normalize)
|
|
60
|
-
ctx.body.email = decision.email;
|
|
61
|
-
ctx.dymoEmail = decision.response;
|
|
62
|
-
return { context: ctx };
|
|
63
|
-
})
|
|
64
|
-
}
|
|
65
|
-
]
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
};
|
|
69
|
-
exports.dymoEmailPlugin = dymoEmailPlugin;
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.dymoIPPlugin = void 0;
|
|
7
|
-
const api_1 = require("better-auth/api");
|
|
8
|
-
const dymo_api_1 = __importDefault(require("dymo-api"));
|
|
9
|
-
const ipHeaders = ["x-forwarded-for", "cf-connecting-ip", "x-vercel-forwarded-for", "x-real-ip"];
|
|
10
|
-
const dymoIPPlugin = ({ apiKey, applyToLogin = false, applyToOAuth = true, ipRules, normalize = true, resilience }) => {
|
|
11
|
-
const defaultRules = {
|
|
12
|
-
deny: ["FRAUD", "INVALID", "TOR_NETWORK"]
|
|
13
|
-
};
|
|
14
|
-
const dymoClient = new dymo_api_1.default({
|
|
15
|
-
apiKey,
|
|
16
|
-
rules: {
|
|
17
|
-
ip: {
|
|
18
|
-
deny: ipRules?.deny ?? defaultRules.deny
|
|
19
|
-
}
|
|
20
|
-
},
|
|
21
|
-
resilience
|
|
22
|
-
});
|
|
23
|
-
const activePaths = [
|
|
24
|
-
"/sign-up/email",
|
|
25
|
-
"/email-otp/verify-email",
|
|
26
|
-
"/sign-in/email-otp",
|
|
27
|
-
"/sign-in/magic-link",
|
|
28
|
-
"/forget-password/email-otp",
|
|
29
|
-
"/email-otp/reset-password",
|
|
30
|
-
"/email-otp/create-verification-otp",
|
|
31
|
-
"/email-otp/get-verification-otp",
|
|
32
|
-
"/email-otp/send-verification-otp",
|
|
33
|
-
"/forget-password",
|
|
34
|
-
"/send-verification-email",
|
|
35
|
-
"/change-email"
|
|
36
|
-
];
|
|
37
|
-
if (applyToLogin)
|
|
38
|
-
activePaths.push("/sign-in/email");
|
|
39
|
-
if (applyToOAuth) {
|
|
40
|
-
activePaths.push("/sign-up/oauth");
|
|
41
|
-
activePaths.push("/sign-in/oauth");
|
|
42
|
-
}
|
|
43
|
-
return {
|
|
44
|
-
id: "dymoIPPlugin",
|
|
45
|
-
hooks: {
|
|
46
|
-
before: [
|
|
47
|
-
{
|
|
48
|
-
matcher: (context) => activePaths.some(path => context.path.startsWith(path)),
|
|
49
|
-
handler: (0, api_1.createAuthMiddleware)(async (ctx) => {
|
|
50
|
-
let ip = null;
|
|
51
|
-
for (const header of ipHeaders) {
|
|
52
|
-
const value = ctx.request.headers.get(header);
|
|
53
|
-
if (value) {
|
|
54
|
-
ip = value.split(",")[0].trim();
|
|
55
|
-
break;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
if (typeof ip !== "string")
|
|
59
|
-
throw new api_1.APIError("BAD_REQUEST", { message: "IP must be a string." });
|
|
60
|
-
const decision = await dymoClient.isValidIP(ip);
|
|
61
|
-
if (!decision.allow) {
|
|
62
|
-
throw new api_1.APIError("BAD_REQUEST", {
|
|
63
|
-
message: "IP is invalid or blocked.",
|
|
64
|
-
reasons: decision.reasons
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
if (normalize) {
|
|
68
|
-
ctx.body.ip = decision.ip;
|
|
69
|
-
ctx.request.headers.set("x-dymo-client-ip", decision.ip);
|
|
70
|
-
}
|
|
71
|
-
ctx.dymoIP = decision.response;
|
|
72
|
-
return { context: ctx };
|
|
73
|
-
})
|
|
74
|
-
}
|
|
75
|
-
]
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
};
|
|
79
|
-
exports.dymoIPPlugin = dymoIPPlugin;
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.dymoPhonePlugin = void 0;
|
|
7
|
-
const api_1 = require("better-auth/api");
|
|
8
|
-
const dymo_api_1 = __importDefault(require("dymo-api"));
|
|
9
|
-
const dymoPhonePlugin = ({ apiKey, applyToLogin = false, applyToOAuth = true, phoneRules, normalize = true, resilience }) => {
|
|
10
|
-
const defaultRules = {
|
|
11
|
-
deny: ["FRAUD", "INVALID"]
|
|
12
|
-
};
|
|
13
|
-
const dymoClient = new dymo_api_1.default({
|
|
14
|
-
apiKey,
|
|
15
|
-
rules: {
|
|
16
|
-
phone: {
|
|
17
|
-
deny: phoneRules?.deny ?? defaultRules.deny
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
resilience
|
|
21
|
-
});
|
|
22
|
-
const activePaths = [
|
|
23
|
-
"/sign-in/phone-number",
|
|
24
|
-
"/phone-number/forget-password",
|
|
25
|
-
"/phone-number/reset-password",
|
|
26
|
-
"/phone-number/send-otp",
|
|
27
|
-
"/phone-number/verify"
|
|
28
|
-
];
|
|
29
|
-
if (applyToLogin)
|
|
30
|
-
activePaths.push("/sign-in/email");
|
|
31
|
-
if (applyToOAuth) {
|
|
32
|
-
activePaths.push("/sign-up/oauth");
|
|
33
|
-
activePaths.push("/sign-in/oauth");
|
|
34
|
-
}
|
|
35
|
-
return {
|
|
36
|
-
id: "dymoPhonePlugin",
|
|
37
|
-
hooks: {
|
|
38
|
-
before: [
|
|
39
|
-
{
|
|
40
|
-
matcher: (context) => activePaths.some(path => context.path.startsWith(path)),
|
|
41
|
-
handler: (0, api_1.createAuthMiddleware)(async (ctx) => {
|
|
42
|
-
const phoneNumber = ctx.body?.phoneNumber || ctx.body?.profile?.phoneNumber;
|
|
43
|
-
if (typeof phoneNumber !== "string")
|
|
44
|
-
throw new api_1.APIError("BAD_REQUEST", { message: "Phone number must be a string." });
|
|
45
|
-
const decision = await dymoClient.isValidPhone(phoneNumber);
|
|
46
|
-
if (!decision.allow) {
|
|
47
|
-
throw new api_1.APIError("BAD_REQUEST", {
|
|
48
|
-
message: "Phone number is invalid or blocked.",
|
|
49
|
-
reasons: decision.reasons
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
if (normalize)
|
|
53
|
-
ctx.body.phoneNumber = decision.phone;
|
|
54
|
-
ctx.dymoPhone = decision.response;
|
|
55
|
-
return { context: ctx };
|
|
56
|
-
})
|
|
57
|
-
}
|
|
58
|
-
]
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
};
|
|
62
|
-
exports.dymoPhonePlugin = dymoPhonePlugin;
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { APIError, createAuthMiddleware } from "better-auth/api";
|
|
2
|
-
import DymoAPI from "dymo-api";
|
|
3
|
-
export const dymoEmailPlugin = ({ apiKey, applyToLogin = false, applyToOAuth = true, emailRules, normalize = true, resilience }) => {
|
|
4
|
-
const defaultRules = {
|
|
5
|
-
deny: ["FRAUD", "INVALID", "NO_MX_RECORDS", "NO_REPLY_EMAIL"]
|
|
6
|
-
};
|
|
7
|
-
const dymoClient = new DymoAPI({
|
|
8
|
-
apiKey,
|
|
9
|
-
rules: {
|
|
10
|
-
email: {
|
|
11
|
-
deny: emailRules?.deny ?? defaultRules.deny
|
|
12
|
-
}
|
|
13
|
-
},
|
|
14
|
-
resilience
|
|
15
|
-
});
|
|
16
|
-
const activePaths = [
|
|
17
|
-
"/sign-up/email",
|
|
18
|
-
"/email-otp/verify-email",
|
|
19
|
-
"/sign-in/email-otp",
|
|
20
|
-
"/sign-in/magic-link",
|
|
21
|
-
"/forget-password/email-otp",
|
|
22
|
-
"/email-otp/reset-password",
|
|
23
|
-
"/email-otp/create-verification-otp",
|
|
24
|
-
"/email-otp/get-verification-otp",
|
|
25
|
-
"/email-otp/send-verification-otp",
|
|
26
|
-
"/forget-password",
|
|
27
|
-
"/send-verification-email",
|
|
28
|
-
"/change-email"
|
|
29
|
-
];
|
|
30
|
-
if (applyToLogin)
|
|
31
|
-
activePaths.push("/sign-in/email");
|
|
32
|
-
if (applyToOAuth) {
|
|
33
|
-
activePaths.push("/sign-up/oauth");
|
|
34
|
-
activePaths.push("/sign-in/oauth");
|
|
35
|
-
}
|
|
36
|
-
return {
|
|
37
|
-
id: "dymoEmailPlugin",
|
|
38
|
-
hooks: {
|
|
39
|
-
before: [
|
|
40
|
-
{
|
|
41
|
-
matcher: (context) => activePaths.some(path => context.path.startsWith(path)),
|
|
42
|
-
handler: createAuthMiddleware(async (ctx) => {
|
|
43
|
-
const email = ctx.body?.email || ctx.body?.profile?.email;
|
|
44
|
-
if (typeof email !== "string")
|
|
45
|
-
throw new APIError("BAD_REQUEST", { message: "Email must be a string." });
|
|
46
|
-
const decision = await dymoClient.isValidEmail(email);
|
|
47
|
-
if (!decision.allow) {
|
|
48
|
-
throw new APIError("BAD_REQUEST", {
|
|
49
|
-
message: "Email is invalid or blocked.",
|
|
50
|
-
reasons: decision.reasons
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
if (normalize)
|
|
54
|
-
ctx.body.email = decision.email;
|
|
55
|
-
ctx.dymoEmail = decision.response;
|
|
56
|
-
return { context: ctx };
|
|
57
|
-
})
|
|
58
|
-
}
|
|
59
|
-
]
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
};
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { APIError, createAuthMiddleware } from "better-auth/api";
|
|
2
|
-
import DymoAPI from "dymo-api";
|
|
3
|
-
const ipHeaders = ["x-forwarded-for", "cf-connecting-ip", "x-vercel-forwarded-for", "x-real-ip"];
|
|
4
|
-
export const dymoIPPlugin = ({ apiKey, applyToLogin = false, applyToOAuth = true, ipRules, normalize = true, resilience }) => {
|
|
5
|
-
const defaultRules = {
|
|
6
|
-
deny: ["FRAUD", "INVALID", "TOR_NETWORK"]
|
|
7
|
-
};
|
|
8
|
-
const dymoClient = new DymoAPI({
|
|
9
|
-
apiKey,
|
|
10
|
-
rules: {
|
|
11
|
-
ip: {
|
|
12
|
-
deny: ipRules?.deny ?? defaultRules.deny
|
|
13
|
-
}
|
|
14
|
-
},
|
|
15
|
-
resilience
|
|
16
|
-
});
|
|
17
|
-
const activePaths = [
|
|
18
|
-
"/sign-up/email",
|
|
19
|
-
"/email-otp/verify-email",
|
|
20
|
-
"/sign-in/email-otp",
|
|
21
|
-
"/sign-in/magic-link",
|
|
22
|
-
"/forget-password/email-otp",
|
|
23
|
-
"/email-otp/reset-password",
|
|
24
|
-
"/email-otp/create-verification-otp",
|
|
25
|
-
"/email-otp/get-verification-otp",
|
|
26
|
-
"/email-otp/send-verification-otp",
|
|
27
|
-
"/forget-password",
|
|
28
|
-
"/send-verification-email",
|
|
29
|
-
"/change-email"
|
|
30
|
-
];
|
|
31
|
-
if (applyToLogin)
|
|
32
|
-
activePaths.push("/sign-in/email");
|
|
33
|
-
if (applyToOAuth) {
|
|
34
|
-
activePaths.push("/sign-up/oauth");
|
|
35
|
-
activePaths.push("/sign-in/oauth");
|
|
36
|
-
}
|
|
37
|
-
return {
|
|
38
|
-
id: "dymoIPPlugin",
|
|
39
|
-
hooks: {
|
|
40
|
-
before: [
|
|
41
|
-
{
|
|
42
|
-
matcher: (context) => activePaths.some(path => context.path.startsWith(path)),
|
|
43
|
-
handler: createAuthMiddleware(async (ctx) => {
|
|
44
|
-
let ip = null;
|
|
45
|
-
for (const header of ipHeaders) {
|
|
46
|
-
const value = ctx.request.headers.get(header);
|
|
47
|
-
if (value) {
|
|
48
|
-
ip = value.split(",")[0].trim();
|
|
49
|
-
break;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
if (typeof ip !== "string")
|
|
53
|
-
throw new APIError("BAD_REQUEST", { message: "IP must be a string." });
|
|
54
|
-
const decision = await dymoClient.isValidIP(ip);
|
|
55
|
-
if (!decision.allow) {
|
|
56
|
-
throw new APIError("BAD_REQUEST", {
|
|
57
|
-
message: "IP is invalid or blocked.",
|
|
58
|
-
reasons: decision.reasons
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
if (normalize) {
|
|
62
|
-
ctx.body.ip = decision.ip;
|
|
63
|
-
ctx.request.headers.set("x-dymo-client-ip", decision.ip);
|
|
64
|
-
}
|
|
65
|
-
ctx.dymoIP = decision.response;
|
|
66
|
-
return { context: ctx };
|
|
67
|
-
})
|
|
68
|
-
}
|
|
69
|
-
]
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
};
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { APIError, createAuthMiddleware } from "better-auth/api";
|
|
2
|
-
import DymoAPI from "dymo-api";
|
|
3
|
-
export const dymoPhonePlugin = ({ apiKey, applyToLogin = false, applyToOAuth = true, phoneRules, normalize = true, resilience }) => {
|
|
4
|
-
const defaultRules = {
|
|
5
|
-
deny: ["FRAUD", "INVALID"]
|
|
6
|
-
};
|
|
7
|
-
const dymoClient = new DymoAPI({
|
|
8
|
-
apiKey,
|
|
9
|
-
rules: {
|
|
10
|
-
phone: {
|
|
11
|
-
deny: phoneRules?.deny ?? defaultRules.deny
|
|
12
|
-
}
|
|
13
|
-
},
|
|
14
|
-
resilience
|
|
15
|
-
});
|
|
16
|
-
const activePaths = [
|
|
17
|
-
"/sign-in/phone-number",
|
|
18
|
-
"/phone-number/forget-password",
|
|
19
|
-
"/phone-number/reset-password",
|
|
20
|
-
"/phone-number/send-otp",
|
|
21
|
-
"/phone-number/verify"
|
|
22
|
-
];
|
|
23
|
-
if (applyToLogin)
|
|
24
|
-
activePaths.push("/sign-in/email");
|
|
25
|
-
if (applyToOAuth) {
|
|
26
|
-
activePaths.push("/sign-up/oauth");
|
|
27
|
-
activePaths.push("/sign-in/oauth");
|
|
28
|
-
}
|
|
29
|
-
return {
|
|
30
|
-
id: "dymoPhonePlugin",
|
|
31
|
-
hooks: {
|
|
32
|
-
before: [
|
|
33
|
-
{
|
|
34
|
-
matcher: (context) => activePaths.some(path => context.path.startsWith(path)),
|
|
35
|
-
handler: createAuthMiddleware(async (ctx) => {
|
|
36
|
-
const phoneNumber = ctx.body?.phoneNumber || ctx.body?.profile?.phoneNumber;
|
|
37
|
-
if (typeof phoneNumber !== "string")
|
|
38
|
-
throw new APIError("BAD_REQUEST", { message: "Phone number must be a string." });
|
|
39
|
-
const decision = await dymoClient.isValidPhone(phoneNumber);
|
|
40
|
-
if (!decision.allow) {
|
|
41
|
-
throw new APIError("BAD_REQUEST", {
|
|
42
|
-
message: "Phone number is invalid or blocked.",
|
|
43
|
-
reasons: decision.reasons
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
if (normalize)
|
|
47
|
-
ctx.body.phoneNumber = decision.phone;
|
|
48
|
-
ctx.dymoPhone = decision.response;
|
|
49
|
-
return { context: ctx };
|
|
50
|
-
})
|
|
51
|
-
}
|
|
52
|
-
]
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
};
|