initEnv (composables/config.ts)

airi · integrations/minecraft/src/composables/config.ts · typescript · MIT
integration

Module that parses and validates environment configuration for a Minecraft bot using zod.

// Source: https://github.com/moeru-ai/airi | License: MIT | Copyright 2024-PRESENT Neko Ayaka
// Provided via justclaw.it.com; keep this notice with the code.
import type { BotOptions } from 'mineflayer'

import { env } from 'node:process'

import { z } from 'zod'

import { useLogger } from '../utils/logger'

const logger = useLogger()

const botAuthValues = ['mojang', 'microsoft', 'offline'] as const satisfies ReadonlyArray<NonNullable<BotOptions['auth']>>

function requiredString(envKey: string) {
  return z.string().trim().min(1, `${envKey} is required`)
}

function httpUrlString(envKey: string) {
  return z.url({
    error: `${envKey} must be a valid URL`,
  }).refine((value) => {
    const protocol = new URL(value).protocol
    return protocol === 'http:' || protocol === 'https:'
  }

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key