infrasniff

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 23, 2026 License: MIT Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package infrasniff inspects a Next.js project's source tree and package.json to infer which Cloudflare resources it needs (D1, R2, KV, Workers AI, Hyperdrive, Vectorize, Queues), which server-side secrets it references, and whether it has an auth layer worth protecting. It powers the `nextdeploy init` "use my existing app" path, prefilling nextdeploy.yml instead of asking the user to hand-write bindings.

It is intentionally heuristic and read-only: signals are best-effort hints a human reviews, never silent infrastructure mutations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Resource

type Resource string

Resource is a Cloudflare resource kind the sniffer can detect.

const (
	ResD1         Resource = "d1"
	ResR2         Resource = "r2"
	ResKV         Resource = "kv"
	ResAI         Resource = "ai"
	ResHyperdrive Resource = "hyperdrive"
	ResVectorize  Resource = "vectorize"
	ResQueue      Resource = "queue"
	ResDO         Resource = "durable_object"
)

type Result

type Result struct {
	Signals     []Signal // one per (resource, reason); dedup with Resources()
	Secrets     []string // server-side env var names referenced (NEXT_PUBLIC_* excluded), sorted
	Auth        bool     // an auth library was detected → suggest a protection.auth block
	FilesParsed int
	// Wrangler is the parsed wrangler config when the project ships one. Its
	// bindings are authoritative (real names + IDs) and should be preferred
	// over heuristic signals when prefilling nextdeploy.yml.
	Wrangler *WranglerConfig
	// MigrationsDir is an existing SQL migrations directory found on disk
	// (e.g. "migrations" or "drizzle"). Empty when none exists so render
	// doesn't emit a non-existent migrations_dir that breaks `plan`/`apply`.
	MigrationsDir string
	// Warnings collects non-fatal diagnostics (e.g. malformed wrangler config).
	Warnings []string
}

Result is the full sniff outcome.

func Sniff

func Sniff(projectDir string) (*Result, error)

Sniff scans projectDir and returns the inferred infrastructure. Missing files / unreadable entries are skipped, not fatal — partial signal is useful.

func (*Result) RenderNextDeployYAML

func (r *Result) RenderNextDeployYAML(appName string) string

RenderNextDeployYAML composes a complete nextdeploy.yml for the "use my existing app" path: app + serverless headers plus the detected cloudflare block (or a minimal stub when nothing was detected).

func (*Result) Resources

func (r *Result) Resources() []Resource

Resources returns the unique detected resources, sorted.

func (*Result) SecretsChecklist

func (r *Result) SecretsChecklist() []string

SecretsChecklist returns the detected secrets sorted, for a post-init "set these with `nextdeploy secrets set`" reminder.

func (*Result) SuggestedCloudflareBlock

func (r *Result) SuggestedCloudflareBlock() string

SuggestedCloudflareBlock renders a `cloudflare:` YAML block (indented to sit under `serverless:`) from the sniff result. Authoritative wrangler bindings are emitted with real names/IDs; heuristic-only detections become resource declarations + ref bindings the user can complete. Returns "" when nothing was detected.

func (*Result) Summary

func (r *Result) Summary() string

Summary is a short human-readable report of what was detected, for printing during `nextdeploy init`.

type Signal

type Signal struct {
	Resource Resource
	Reason   string // human-readable evidence, e.g. `dep "drizzle-orm/d1"` or `type R2Bucket`
}

Signal is one detected resource need with the evidence behind it.

type WranglerBinding

type WranglerBinding struct {
	Name          string // JS binding variable (e.g. "DB")
	Resource      string // database_name / bucket_name / index_name / queue
	ID            string // database_id / namespace id / hyperdrive id
	MigrationsDir string // D1 migrations_dir when declared in wrangler config
}

WranglerBinding is one declared binding. Fields are populated per kind; unused ones stay empty (e.g. R2 has Resource=bucket_name, ID empty).

type WranglerConfig

type WranglerConfig struct {
	Source             string                  // file the config was read from
	Name               string                  // worker name
	CompatibilityDate  string                  // compatibility date
	CompatibilityFlags []string                // compatibility flags
	D1                 []WranglerBinding       // binding + database_name + database_id
	KV                 []WranglerBinding       // binding + id
	R2                 []WranglerBinding       // binding + bucket_name
	Hyperdrive         []WranglerBinding       // binding + id
	Vectorize          []WranglerBinding       // binding + index_name
	Queues             []WranglerBinding       // producer binding + queue
	QueueConsumers     []WranglerQueueConsumer // consumer queue settings
	AI                 string                  // AI binding name (empty when absent)
	DurableObjects     []WranglerDOBinding     // durable object bindings
	Migrations         []WranglerMigration     // durable object SQLite migrations
	Crons              []string                // cron triggers
	CustomDomains      []string                // custom domains
	Vars               []string                // plain-text var names (not secrets)
}

WranglerConfig is the subset of a wrangler config the sniffer understands. Unlike the heuristic source scan, these bindings are authoritative: the user already declared exact names and resource IDs, so init can prefill them verbatim instead of guessing.

type WranglerDOBinding added in v1.0.0

type WranglerDOBinding struct {
	Name      string
	ClassName string
	Script    string
}

type WranglerMigration added in v1.0.0

type WranglerMigration struct {
	Tag              string
	NewSQLiteClasses []string
	NewClasses       []string
	DeletedClasses   []string
}

type WranglerQueueConsumer added in v1.0.0

type WranglerQueueConsumer struct {
	Queue           string
	MaxBatchSize    int
	MaxBatchTimeout int
	MaxRetries      int
	DeadLetterQueue string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL