πŸ“ IP Validation in Zod

Easily validate IPs in your project with Dymo API integrated with Zod.

A better, simpler way to validate IPs with Dymo API + Zod in a single line of code!

About IP Validation

What is IP Validation?

IP validation uses Dymo API to check for fraud, invalid addresses, and more. All async validations require parseAsync().

Usage

To start validating emails in your project with Zod, create a schema using dymoClient.ipSchema():

import { z } from "zod";
import DymoAPIZod from "@dymo-api/zod";

const dymoClient = new DymoAPIZod({ apiKey: "" });

const userSchema = z.object({
    ip: dymoClient.ipSchema(),
    email: dymoClient.emailSchema(),
    username: z.string().min(3),
    age: z.number().int().min(0)
});

Validating Data

(async () => {
    const validatedUser = await userSchema.parseAsync({
        ip: "52.94.236.248",
        email: "[email protected]",
        username: "build",
        age: 10
    });

    console.log(validatedUser);
    /*
    {
      ip: "52.94.236.248",
      email: "[email protected]", // normalized by Dymo API
      username: "build",
      age: 10
    }
    */
})();

Handling Invalid Emails

The schema will automatically throw an error if the email is fraudulent or invalid:

try {
    await userSchema.parseAsync({
        ip: "228.49.142.11",
        email: "[email protected]",
        username: "build",
        age: 10
    });
} catch (err) {
    console.error("Validation failed:", err.errors);
    /*
    [
        { path: ["ip"], message: "Invalid IP" }
    ]
    */
}

Optional Flags (for direct plugin-style usage)

You can pass options when creating the DymoAPIZod instance to customize behavior:

const dymoClient = new DymoAPIZod({
    apiKey: "",
    rules: {
        ip: {
            deny: ["FRAUD", "INVALID", "TOR_NETWORK"]
        }
    }
});
  • rules: Customize which IP rules to apply.
  • parseAsync() must be used because the validator queries the Dymo API.

Examples with Other Validators

You can also create schemas for IPs, phones, and passwords:

const userSchema = z.object({
    email: dymoClient.emailSchema(),
    ip: dymoClient.ipSchema(),
    phone: dymoClient.phoneSchema(),

    // Coming Soon.
    password: dymoClient.passwordSchema()
});

Important: All async validators require parseAsync() because they make API requests.


IP Rules

RuleDefaultPremiumDescription
FRAUDβœ…βŒFraud detection
INVALIDβœ…βŒInvalid IP format
TOR_NETWORKβœ…βœ…Tor network detection
COUNTRY:<COUNTRY_CODE>❌❌Block an IP based on its country; you must use ISO 3166-1 alpha-2.
HIGH_RISK_SCOREβŒβœ…High risk score detection

Parameters

ParameterTypeRequiredDescription
apiKeyStringβœ…Your Dymo API key
rulesRules❌Customize which rules to apply
parseAsync()Functionβœ…Must be called to validate async email rules

πŸ’‘ Tip: Using DymoAPIZod with Zod lets you combine real-time fraud checks with normal Zod validations in a single schema for secure, consistent, and easy-to-maintain validation.