//go:build js && wasm package hp_ipn import ( "errors" "syscall/js" ) // Represents the options needed to initialize the TsWasmNet module. type TsWasmNetOptions struct { // Tailscale control URL, e.g., "https://controlplane.tailscale.com" ControlURL string // Pre-authentication key for the Tailnet PreAuthKey string // Optional hostname, autogenerated if not provided. Hostname string } // Parses the provided JS object to validate and extract the TsWasmNetOptions. func ParseTsWasmNetOptions(obj js.Value) (*TsWasmNetOptions, error) { if obj.IsUndefined() || obj.IsNull() { return nil, errors.New("TsWasmNetOptions cannot be undefined or null") } cUrl := safeString("ControlURL", obj) preAuthKey := safeString("PreAuthKey", obj) hostname := safeString("Hostname", obj) if cUrl == "" || preAuthKey == "" || hostname == "" { return nil, errors.New("missing required fields in TsWasmNetOptions") } return &TsWasmNetOptions{ ControlURL: cUrl, PreAuthKey: preAuthKey, Hostname: hostname, }, nil } // Retrieves a string value from a JS object safely. func safeString(key string, obj js.Value) string { if obj.IsUndefined() || obj.IsNull() { return "" } val := obj.Get(key) if val.IsUndefined() || val.IsNull() { return "" } return val.String() }