@dymo-api/better-auth 1.2.23 → 1.2.24

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.
@@ -1,5 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.dymoEmailPlugin = void 0;
3
+ exports.dymoPhonePlugin = exports.dymoIPPlugin = exports.dymoEmailPlugin = void 0;
4
4
  var emailValidation_1 = require("./plugins/emailValidation/index.cjs");
5
5
  Object.defineProperty(exports, "dymoEmailPlugin", { enumerable: true, get: function () { return emailValidation_1.dymoEmailPlugin; } });
6
+ var ipValidation_1 = require("./plugins/ipValidation/index.cjs");
7
+ Object.defineProperty(exports, "dymoIPPlugin", { enumerable: true, get: function () { return ipValidation_1.dymoIPPlugin; } });
8
+ var phoneValidation_1 = require("./plugins/phoneValidation/index.cjs");
9
+ Object.defineProperty(exports, "dymoPhonePlugin", { enumerable: true, get: function () { return phoneValidation_1.dymoPhonePlugin; } });
@@ -0,0 +1,76 @@
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 }) => {
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
+ });
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: "dymoIPPlugin",
44
+ hooks: {
45
+ before: [
46
+ {
47
+ matcher: (context) => activePaths.some(path => context.path.startsWith(path)),
48
+ handler: (0, api_1.createAuthMiddleware)(async (ctx) => {
49
+ let ip = null;
50
+ for (const header of ipHeaders) {
51
+ const value = ctx.request.headers.get(header);
52
+ if (value) {
53
+ ip = value.split(",")[0].trim();
54
+ break;
55
+ }
56
+ }
57
+ if (typeof ip !== "string")
58
+ throw new api_1.APIError("BAD_REQUEST", { message: "IP must be a string." });
59
+ const decision = await dymoClient.isValidIP(ip);
60
+ if (!decision.allow) {
61
+ throw new api_1.APIError("BAD_REQUEST", {
62
+ message: "IP is invalid or blocked.",
63
+ reasons: decision.reasons
64
+ });
65
+ }
66
+ ctx.body.ip = decision.ip;
67
+ ctx.request.headers.set("x-dymo-client-ip", decision.ip);
68
+ ctx.dymoIP = decision.response;
69
+ return { context: ctx };
70
+ })
71
+ }
72
+ ]
73
+ }
74
+ };
75
+ };
76
+ exports.dymoIPPlugin = dymoIPPlugin;
package/dist/esm/index.js CHANGED
@@ -1 +1,3 @@
1
1
  export { dymoEmailPlugin } from "./plugins/emailValidation";
2
+ export { dymoIPPlugin } from "./plugins/ipValidation";
3
+ export { dymoPhonePlugin } from "./plugins/phoneValidation";
@@ -0,0 +1,69 @@
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 }) => {
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
+ });
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: "dymoIPPlugin",
38
+ hooks: {
39
+ before: [
40
+ {
41
+ matcher: (context) => activePaths.some(path => context.path.startsWith(path)),
42
+ handler: createAuthMiddleware(async (ctx) => {
43
+ let ip = null;
44
+ for (const header of ipHeaders) {
45
+ const value = ctx.request.headers.get(header);
46
+ if (value) {
47
+ ip = value.split(",")[0].trim();
48
+ break;
49
+ }
50
+ }
51
+ if (typeof ip !== "string")
52
+ throw new APIError("BAD_REQUEST", { message: "IP must be a string." });
53
+ const decision = await dymoClient.isValidIP(ip);
54
+ if (!decision.allow) {
55
+ throw new APIError("BAD_REQUEST", {
56
+ message: "IP is invalid or blocked.",
57
+ reasons: decision.reasons
58
+ });
59
+ }
60
+ ctx.body.ip = decision.ip;
61
+ ctx.request.headers.set("x-dymo-client-ip", decision.ip);
62
+ ctx.dymoIP = decision.response;
63
+ return { context: ctx };
64
+ })
65
+ }
66
+ ]
67
+ }
68
+ };
69
+ };
@@ -1 +1,3 @@
1
1
  export { dymoEmailPlugin } from "./plugins/emailValidation";
2
+ export { dymoIPPlugin } from "./plugins/ipValidation";
3
+ export { dymoPhonePlugin } from "./plugins/phoneValidation";
@@ -0,0 +1,19 @@
1
+ import { IPValidatorRules } from "dymo-api";
2
+ interface dymoIPPluginOptions {
3
+ apiKey: string;
4
+ applyToLogin?: boolean;
5
+ applyToOAuth?: boolean;
6
+ ipRules?: Partial<IPValidatorRules>;
7
+ }
8
+ export declare const dymoIPPlugin: ({ apiKey, applyToLogin, applyToOAuth, ipRules }: dymoIPPluginOptions) => {
9
+ id: "dymoIPPlugin";
10
+ hooks: {
11
+ before: {
12
+ matcher: (context: any) => boolean;
13
+ handler: (inputContext: import("better-auth").MiddlewareInputContext<import("better-auth").MiddlewareOptions>) => Promise<{
14
+ context: any;
15
+ }>;
16
+ }[];
17
+ };
18
+ };
19
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dymo-api/better-auth",
3
- "version": "1.2.23",
3
+ "version": "1.2.24",
4
4
  "description": "Flow system for Dymo API.",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -59,7 +59,7 @@
59
59
  "homepage": "https://dymo.tpeoficial.com",
60
60
  "dependencies": {
61
61
  "better-auth": "^1.3.23",
62
- "dymo-api": "^1.2.23",
62
+ "dymo-api": "^1.2.29",
63
63
  "path": "^0.12.7"
64
64
  },
65
65
  "contributors": [