formavailability

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: AGPL-3.0 Imports: 19 Imported by: 0

Documentation

Overview

Package formavailability serves the live check behind a name field: a person types the name of something they are ordering — a SharePoint site, a Microsoft 365 group — and the form says at once whether that name is still free (ADR-0519).

It is ADR-0473's ephemeral worker query asked a narrower question. A directory field searches and offers a page; an availability field asks one value lookup per source the field names and learns one bit from each: is there something under this name. The answer the browser receives is that bit, folded over every source, and nothing else — no id, no display name, nothing about what holds the name.

**What the request may say** is the value typed and nothing more. Which Worker, which tenant, which resource, which SharePoint host and managed path — all of that is read from the stored form and checked against the provider table below, at save and again here, and a request naming any of it is refused.

**The check is a courtesy, not the rule.** Two people can be told the same name is free a second apart, and a name can be taken between the order and its provisioning. The process that creates the object asks again and owns the refusal; this check only spares a person an order that was going to come back.

**This area owns no state** (I3): its collaborators are the server's, a query waits on the request's own goroutine, and nothing here reaches the log, the processor or recovery.

Index

Constants

View Source
const DefaultTimeout = 8 * time.Second

DefaultTimeout is what a person waits for at most. The checks run side by side, so a field with three sources waits as long as its slowest one.

View Source
const Member = "atlasAvailability"

Member is the component member that makes a textfield an availability field.

View Source
const Version = 1

Version is the one version of the block this server reads.

Variables

View Source
var Codes = []string{
	"not_found", "invalid_query", "invalid_value", "invalid_configuration", "forbidden", "rate_limited",
	"worker_unavailable", "worker_busy", "provider_throttled", "provider_unavailable", "provider_refused", "timeout",
}

Codes are the machine-readable codes a check answers with beside its message.

View Source
var FieldTypes = []string{"textfield"}

FieldTypes are the form-js fields an availability field may be: the one that holds a typed name.

Functions

func CheckSchema

func CheckSchema(schema []byte) error

CheckSchema is the save-time check: a form whose availability blocks this server could not serve is refused with the reason, rather than saved and failing when somebody types.

func Normalize

func Normalize(v string) string

Normalize is the value as it is checked: trimmed and lower-cased. A Microsoft 365 alias and a SharePoint site address are both case-insensitive, so "Dev-HuDa" is taken when "dev-huda" is.

Types

type Answer

type Answer struct {
	Value     string `json:"value"`
	Available bool   `json:"available"`
}

Answer is what a check answers: the value as it was checked, and whether every source the field names reports it free.

type Check

type Check struct {
	WorkerType string `json:"workerType"`
	Worker     string `json:"worker"`
	Resource   string `json:"resource"`
	// Host and ManagedPath locate a SharePoint site: https://<host>/<managedPath>/<name>.
	Host        string `json:"host,omitempty"`
	ManagedPath string `json:"managedPath,omitempty"`
}

Check is one source as a block names it.

type Config

type Config struct {
	// Worker resolves a Worker by name from the Worker store.
	Worker func(name string) (Worker, bool, error)
	// Ask puts a query to a Worker Instance and waits for its answer.
	Ask func(ctx context.Context, jobType, connector string, q lookup.Query, timeout time.Duration) (lookup.Page, error)
	// Allow is the per-person rate limit.
	Allow func(key string) bool
	// Principal names the caller, for the rate limit. Empty when the server runs
	// without authentication.
	Principal func(r *http.Request) string
	// Timeout bounds one query.
	Timeout time.Duration
	// MaxBody bounds a request's body.
	MaxBody int64
}

Config is the server's half of this area.

type Field

type Field struct {
	Key       string
	Source    Source
	Providers []Provider
}

Field is one availability field of a form, checked.

func (Field) MinLength

func (f Field) MinLength() int

MinLength is the field's threshold.

type Form

type Form struct {
	Fields map[string]Field
}

Form is the availability fields of one form, by key.

func Parse

func Parse(schema []byte) (*Form, error)

Parse reads a form's availability fields and checks every block. A form without any parses to an empty set; one with a malformed block is an error naming the field.

func (*Form) Field

func (f *Form) Field(key string) (Field, bool)

Field finds a field by key.

type Provider

type Provider struct {
	WorkerType string `json:"workerType"`
	Resource   string `json:"resource"`
	// JobType routes the query to Worker Instances serving this Worker Type.
	JobType string `json:"-"`
	// Label names the source to a model author.
	Label string `json:"label"`
	// Property is what the source returns about a record that holds the name; it is
	// asked for so the Worker has something to project, and never passed on.
	Property string `json:"-"`
	// Located marks a source that needs a host — SharePoint, whose sites are addressed
	// under the tenant's host and a managed path.
	Located bool `json:"located,omitempty"`
	// ValueFormat says in words what a value must look like, for an error message.
	ValueFormat string `json:"valueFormat"`
	// contains filtered or unexported fields
}

Provider is one source a field may ask: a resource of a Worker Type, answered by a value lookup.

func Providers

func Providers() []Provider

Providers lists the sources this server offers, for the editor and for the Worker switch that opens a Worker to form lookups.

func (Provider) Valid

func (p Provider) Valid(v string) bool

Valid reports whether v has the shape of a name this source can hold.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service answers availability checks. Build it with New.

func New

func New(cfg Config) *Service

New builds the service.

func (*Service) WriteCheck

func (s *Service) WriteCheck(w http.ResponseWriter, r *http.Request, schema []byte, fieldKey string)

WriteCheck answers a check of one field of a stored form, read by the caller from wherever the form is reached — a form id, a task. The request names only the value.

type Source

type Source struct {
	Version int     `json:"version"`
	Checks  []Check `json:"checks"`
	// MinLength is how many characters a value needs before it is checked. Absent
	// means 3.
	MinLength *int `json:"minLength,omitempty"`
}

Source is the atlasAvailability block as a form states it.

type Worker

type Worker struct {
	WorkerType string
	Enabled    bool
	// FormLookups is the Worker's own switch (ADR-0473): its editors decide whether a
	// form may ask anything through its credential. An availability check asks less
	// than a directory search, but through the same credential, so it needs the same
	// consent.
	FormLookups bool
}

Worker is a configured Worker as this area judges it: no endpoint and nowhere to put a credential.

Jump to

Keyboard shortcuts

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