WayrApp Backend & Ecosystem Documentation - v1.0.0
    Preparing search index...

    Variable CountryCodeSchemaConst

    CountryCodeSchema: ZodString = ...

    Country code validation schema following ISO 3166-1 alpha-2 standard

    Strict country code validation that enforces the ISO 3166-1 alpha-2 standard for country identification. This schema ensures consistent geographic data representation throughout the application, supporting features like user location tracking, content regionalization, and compliance with geographic restrictions or regulations.

    The validation enforces the exact two-character uppercase format required by the ISO standard, preventing common errors like lowercase codes, full country names, or numeric codes. This strict validation ensures compatibility with international systems and maintains data consistency across distributed services and third-party integrations.

    Security considerations include prevention of injection attacks through strict pattern matching, elimination of malformed geographic data that could cause localization errors, and consistent data format that supports geographic analytics and compliance reporting. The schema maintains compatibility with standard geographic databases and mapping services.

    // Valid country codes
    const validCodes = ['US', 'CA', 'MX', 'BR', 'AR', 'ES', 'FR', 'DE', 'JP', 'AU'];
    validCodes.forEach(code => {
    const result = CountryCodeSchema.parse(code);
    console.log(`${code} is valid`);
    });
    // User profile with country validation
    const UserProfileSchema = z.object({
    name: z.string(),
    email: EmailSchema,
    country: CountryCodeSchema.optional(),
    timezone: z.string().optional()
    });
    // Geographic content filtering
    router.get('/content/regional', validate({
    query: z.object({ country: CountryCodeSchema.optional() })
    }), (req, res) => {
    const { country } = req.query;
    const content = await contentService.getRegionalContent(country);
    res.json({ content, region: country });
    });
    // Error handling for invalid country codes
    try {
    CountryCodeSchema.parse('usa'); // Invalid: lowercase and too long
    } catch (error) {
    // Throws: "Country code must be uppercase letters"
    }