package config import ( "fmt" "net/url" "regexp" "strings" ) // OficinaApp is one of the team's Oficina apps, listed on Home. type OficinaApp struct { ID string // one of OficinaIDs Name string // the name Base gives it Origin string // https and a hostname, no trailing slash } // oficinaApps are the Oficina apps Base knows, with their names. var oficinaApps = []struct{ id, name string }{ {"calendar", "Calendar"}, {"docs", "Docs"}, {"sheets", "Sheets"}, {"slides", "Slides"}, {"memoria", "Memoria"}, {"calls", "Calls"}, {"fichas", "Fichas"}, {"equipo", "Equipo"}, } // BundleID is the app's native bundle ID on the Mac and iPhone: every // Oficina native app is works.oficina. (ruled 2026-11-14). Base's own // native app opens the app by it when it is installed. func (o OficinaApp) BundleID() string { return "works.oficina." + o.ID } // oficinaSchemes are the URL schemes that open an Oficina app's native app // on the iPhone, for the apps whose app can be opened by one today. Docs, // Sheets, Calendar and Memoria answer only …://signin until their apps take // the kit's …://open, so they open on the web until then. var oficinaSchemes = map[string]string{"calls": "oficina-calls", "equipo": "works.oficina.equipo"} // Scheme is the URL scheme that opens the app's native app, or "" when it // opens on the web. func (o OficinaApp) Scheme() string { return oficinaSchemes[o.ID] } // OficinaIDs is every app id BASE_OFICINA_APPS accepts. func OficinaIDs() []string { ids := make([]string, len(oficinaApps)) for i, a := range oficinaApps { ids[i] = a.id } return ids } // hostRE is a DNS hostname with at least two labels and a top-level label // that starts with a letter, so no IP address passes. var hostRE = regexp.MustCompile(`^([a-z0-9]([a-z0-9-]*[a-z0-9])?\.)+[a-z]([a-z0-9-]*[a-z0-9])?$`) // parseOficinaApps reads BASE_OFICINA_APPS: comma-separated id=origin // pairs, each id one Base knows and each origin https and a hostname only. // Empty is no apps. func parseOficinaApps(raw string) ([]OficinaApp, error) { var out []OficinaApp seen := map[string]bool{} for _, item := range strings.Split(raw, ",") { item = strings.TrimSpace(item) if item == "" { continue } id, origin, ok := strings.Cut(item, "=") id, origin = strings.TrimSpace(id), strings.ToLower(strings.TrimRight(strings.TrimSpace(origin), "/")) if !ok || id == "" { return nil, fmt.Errorf("BASE_OFICINA_APPS: %q must be an app and its address, such as calendar=https://calendar.example.com", item) } name := "" for _, a := range oficinaApps { if a.id == id { name = a.name } } if name == "" { return nil, fmt.Errorf("BASE_OFICINA_APPS: unknown app %q; Base knows %s", id, strings.Join(OficinaIDs(), ", ")) } if seen[id] { return nil, fmt.Errorf("BASE_OFICINA_APPS lists %s twice", id) } seen[id] = true u, err := url.Parse(origin) if err != nil || u.Scheme != "https" || u.User != nil || u.Path != "" || u.RawQuery != "" || u.ForceQuery || u.Fragment != "" || u.Port() != "" || !hostRE.MatchString(u.Host) { return nil, fmt.Errorf("BASE_OFICINA_APPS: %s's address %q must be https:// and a hostname only", id, origin) } out = append(out, OficinaApp{ID: id, Name: name, Origin: origin}) } return out, nil }