@dymo-api/better-auth 1.2.27 → 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.
@@ -1,3 +1,4 @@
1
- export { dymoEmailPlugin } from "./plugins/emailValidation";
2
- export { dymoIPPlugin } from "./plugins/ipValidation";
3
- export { dymoPhonePlugin } from "./plugins/phoneValidation";
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,20 +1,22 @@
1
- import { EmailValidatorRules } from "dymo-api";
1
+ import { EmailValidatorRules, ResilienceConfig } from 'dymo-api';
2
2
  interface DymoEmailPluginOptions {
3
3
  apiKey: string;
4
4
  applyToLogin?: boolean;
5
5
  applyToOAuth?: boolean;
6
6
  emailRules?: Partial<EmailValidatorRules>;
7
7
  normalize?: boolean;
8
+ resilience?: ResilienceConfig;
8
9
  }
9
- export declare const dymoEmailPlugin: ({ apiKey, applyToLogin, applyToOAuth, emailRules, normalize }: DymoEmailPluginOptions) => {
10
+ export declare const dymoEmailPlugin: ({ apiKey, applyToLogin, applyToOAuth, emailRules, normalize, resilience }: DymoEmailPluginOptions) => {
10
11
  id: "dymoEmailPlugin";
11
12
  hooks: {
12
13
  before: {
13
14
  matcher: (context: any) => boolean;
14
- handler: (inputContext: import("better-auth").MiddlewareInputContext<import("better-auth").MiddlewareOptions>) => Promise<{
15
+ handler: (inputContext: import('better-call').MiddlewareInputContext<import('better-call').MiddlewareOptions>) => Promise<{
15
16
  context: any;
16
17
  }>;
17
18
  }[];
18
19
  };
19
20
  };
20
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,20 +1,22 @@
1
- import { IPValidatorRules } from "dymo-api";
1
+ import { IPValidatorRules, ResilienceConfig } from 'dymo-api';
2
2
  interface dymoIPPluginOptions {
3
3
  apiKey: string;
4
4
  applyToLogin?: boolean;
5
5
  applyToOAuth?: boolean;
6
6
  ipRules?: Partial<IPValidatorRules>;
7
7
  normalize?: boolean;
8
+ resilience?: ResilienceConfig;
8
9
  }
9
- export declare const dymoIPPlugin: ({ apiKey, applyToLogin, applyToOAuth, ipRules, normalize }: dymoIPPluginOptions) => {
10
+ export declare const dymoIPPlugin: ({ apiKey, applyToLogin, applyToOAuth, ipRules, normalize, resilience }: dymoIPPluginOptions) => {
10
11
  id: "dymoIPPlugin";
11
12
  hooks: {
12
13
  before: {
13
14
  matcher: (context: any) => boolean;
14
- handler: (inputContext: import("better-auth").MiddlewareInputContext<import("better-auth").MiddlewareOptions>) => Promise<{
15
+ handler: (inputContext: import('better-call').MiddlewareInputContext<import('better-call').MiddlewareOptions>) => Promise<{
15
16
  context: any;
16
17
  }>;
17
18
  }[];
18
19
  };
19
20
  };
20
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,20 +1,22 @@
1
- import { PhoneValidatorRules } from "dymo-api";
1
+ import { PhoneValidatorRules, ResilienceConfig } from 'dymo-api';
2
2
  interface DymoPhonePluginOptions {
3
3
  apiKey: string;
4
4
  applyToLogin?: boolean;
5
5
  applyToOAuth?: boolean;
6
6
  phoneRules?: Partial<PhoneValidatorRules>;
7
7
  normalize?: boolean;
8
+ resilience?: ResilienceConfig;
8
9
  }
9
- export declare const dymoPhonePlugin: ({ apiKey, applyToLogin, applyToOAuth, phoneRules, normalize }: DymoPhonePluginOptions) => {
10
+ export declare const dymoPhonePlugin: ({ apiKey, applyToLogin, applyToOAuth, phoneRules, normalize, resilience }: DymoPhonePluginOptions) => {
10
11
  id: "dymoPhonePlugin";
11
12
  hooks: {
12
13
  before: {
13
14
  matcher: (context: any) => boolean;
14
- handler: (inputContext: import("better-auth").MiddlewareInputContext<import("better-auth").MiddlewareOptions>) => Promise<{
15
+ handler: (inputContext: import('better-call').MiddlewareInputContext<import('better-call').MiddlewareOptions>) => Promise<{
15
16
  context: any;
16
17
  }>;
17
18
  }[];
18
19
  };
19
20
  };
20
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.27",
3
+ "version": "1.2.29",
4
4
  "description": "Flow system for Dymo API.",
5
- "main": "dist/cjs/index.js",
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:cjs": "tsc -p tsconfig.cjs.json && tsc-alias -p tsconfig.cjs.json",
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.30",
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,68 +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 }) => {
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
- });
21
- const activePaths = [
22
- "/sign-up/email",
23
- "/email-otp/verify-email",
24
- "/sign-in/email-otp",
25
- "/sign-in/magic-link",
26
- "/forget-password/email-otp",
27
- "/email-otp/reset-password",
28
- "/email-otp/create-verification-otp",
29
- "/email-otp/get-verification-otp",
30
- "/email-otp/send-verification-otp",
31
- "/forget-password",
32
- "/send-verification-email",
33
- "/change-email"
34
- ];
35
- if (applyToLogin)
36
- activePaths.push("/sign-in/email");
37
- if (applyToOAuth) {
38
- activePaths.push("/sign-up/oauth");
39
- activePaths.push("/sign-in/oauth");
40
- }
41
- return {
42
- id: "dymoEmailPlugin",
43
- hooks: {
44
- before: [
45
- {
46
- matcher: (context) => activePaths.some(path => context.path.startsWith(path)),
47
- handler: (0, api_1.createAuthMiddleware)(async (ctx) => {
48
- const email = ctx.body?.email || ctx.body?.profile?.email;
49
- if (typeof email !== "string")
50
- throw new api_1.APIError("BAD_REQUEST", { message: "Email must be a string." });
51
- const decision = await dymoClient.isValidEmail(email);
52
- if (!decision.allow) {
53
- throw new api_1.APIError("BAD_REQUEST", {
54
- message: "Email is invalid or blocked.",
55
- reasons: decision.reasons
56
- });
57
- }
58
- if (normalize)
59
- ctx.body.email = decision.email;
60
- ctx.dymoEmail = decision.response;
61
- return { context: ctx };
62
- })
63
- }
64
- ]
65
- }
66
- };
67
- };
68
- exports.dymoEmailPlugin = dymoEmailPlugin;
@@ -1,78 +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 }) => {
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
- if (normalize) {
67
- ctx.body.ip = decision.ip;
68
- ctx.request.headers.set("x-dymo-client-ip", decision.ip);
69
- }
70
- ctx.dymoIP = decision.response;
71
- return { context: ctx };
72
- })
73
- }
74
- ]
75
- }
76
- };
77
- };
78
- exports.dymoIPPlugin = dymoIPPlugin;
@@ -1,61 +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 }) => {
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
- });
21
- const activePaths = [
22
- "/sign-in/phone-number",
23
- "/phone-number/forget-password",
24
- "/phone-number/reset-password",
25
- "/phone-number/send-otp",
26
- "/phone-number/verify"
27
- ];
28
- if (applyToLogin)
29
- activePaths.push("/sign-in/email");
30
- if (applyToOAuth) {
31
- activePaths.push("/sign-up/oauth");
32
- activePaths.push("/sign-in/oauth");
33
- }
34
- return {
35
- id: "dymoPhonePlugin",
36
- hooks: {
37
- before: [
38
- {
39
- matcher: (context) => activePaths.some(path => context.path.startsWith(path)),
40
- handler: (0, api_1.createAuthMiddleware)(async (ctx) => {
41
- const phoneNumber = ctx.body?.phoneNumber || ctx.body?.profile?.phoneNumber;
42
- if (typeof phoneNumber !== "string")
43
- throw new api_1.APIError("BAD_REQUEST", { message: "Phone number must be a string." });
44
- const decision = await dymoClient.isValidPhone(phoneNumber);
45
- if (!decision.allow) {
46
- throw new api_1.APIError("BAD_REQUEST", {
47
- message: "Phone number is invalid or blocked.",
48
- reasons: decision.reasons
49
- });
50
- }
51
- if (normalize)
52
- ctx.body.phoneNumber = decision.phone;
53
- ctx.dymoPhone = decision.response;
54
- return { context: ctx };
55
- })
56
- }
57
- ]
58
- }
59
- };
60
- };
61
- exports.dymoPhonePlugin = dymoPhonePlugin;
@@ -1,61 +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 }) => {
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
- });
15
- const activePaths = [
16
- "/sign-up/email",
17
- "/email-otp/verify-email",
18
- "/sign-in/email-otp",
19
- "/sign-in/magic-link",
20
- "/forget-password/email-otp",
21
- "/email-otp/reset-password",
22
- "/email-otp/create-verification-otp",
23
- "/email-otp/get-verification-otp",
24
- "/email-otp/send-verification-otp",
25
- "/forget-password",
26
- "/send-verification-email",
27
- "/change-email"
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: "dymoEmailPlugin",
37
- hooks: {
38
- before: [
39
- {
40
- matcher: (context) => activePaths.some(path => context.path.startsWith(path)),
41
- handler: createAuthMiddleware(async (ctx) => {
42
- const email = ctx.body?.email || ctx.body?.profile?.email;
43
- if (typeof email !== "string")
44
- throw new APIError("BAD_REQUEST", { message: "Email must be a string." });
45
- const decision = await dymoClient.isValidEmail(email);
46
- if (!decision.allow) {
47
- throw new APIError("BAD_REQUEST", {
48
- message: "Email is invalid or blocked.",
49
- reasons: decision.reasons
50
- });
51
- }
52
- if (normalize)
53
- ctx.body.email = decision.email;
54
- ctx.dymoEmail = decision.response;
55
- return { context: ctx };
56
- })
57
- }
58
- ]
59
- }
60
- };
61
- };
@@ -1,71 +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 }) => {
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
- if (normalize) {
61
- ctx.body.ip = decision.ip;
62
- ctx.request.headers.set("x-dymo-client-ip", decision.ip);
63
- }
64
- ctx.dymoIP = decision.response;
65
- return { context: ctx };
66
- })
67
- }
68
- ]
69
- }
70
- };
71
- };
@@ -1,54 +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 }) => {
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
- });
15
- const activePaths = [
16
- "/sign-in/phone-number",
17
- "/phone-number/forget-password",
18
- "/phone-number/reset-password",
19
- "/phone-number/send-otp",
20
- "/phone-number/verify"
21
- ];
22
- if (applyToLogin)
23
- activePaths.push("/sign-in/email");
24
- if (applyToOAuth) {
25
- activePaths.push("/sign-up/oauth");
26
- activePaths.push("/sign-in/oauth");
27
- }
28
- return {
29
- id: "dymoPhonePlugin",
30
- hooks: {
31
- before: [
32
- {
33
- matcher: (context) => activePaths.some(path => context.path.startsWith(path)),
34
- handler: createAuthMiddleware(async (ctx) => {
35
- const phoneNumber = ctx.body?.phoneNumber || ctx.body?.profile?.phoneNumber;
36
- if (typeof phoneNumber !== "string")
37
- throw new APIError("BAD_REQUEST", { message: "Phone number must be a string." });
38
- const decision = await dymoClient.isValidPhone(phoneNumber);
39
- if (!decision.allow) {
40
- throw new APIError("BAD_REQUEST", {
41
- message: "Phone number is invalid or blocked.",
42
- reasons: decision.reasons
43
- });
44
- }
45
- if (normalize)
46
- ctx.body.phoneNumber = decision.phone;
47
- ctx.dymoPhone = decision.response;
48
- return { context: ctx };
49
- })
50
- }
51
- ]
52
- }
53
- };
54
- };