-
Notifications
You must be signed in to change notification settings - Fork 1
feat(space): support self-hosted invite links #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
- Accept invite links from custom hosts (http(s)://<host>/<cid>#<key>) - Add persisted config networkId and use it as default for space join - Document self-hosted usage in README Tests: go test ./...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds support for self-hosted invite links, allowing users to accept invites from custom hosts instead of being restricted to the hard-coded invite.any.coop domain. The implementation includes configuration persistence, fallback behavior, comprehensive tests, and updated documentation.
- Adds a persisted
networkIdfield to the config.json file with getter/setter helper functions - Updates invite link parsing to accept any valid HTTP/HTTPS host instead of validating against a hard-coded domain
- Implements network ID fallback logic: command flag → stored config → default Anytype network
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| core/config/config.go | Adds NetworkId field to Config struct and SetNetworkId method to ConfigManager |
| core/config/config_helper.go | Implements GetNetworkIdFromConfig and SetNetworkIdToConfig helper functions |
| core/config/config_test.go | Adds test coverage for NetworkId field persistence |
| core/config/config_helper_test.go | Adds comprehensive tests for NetworkId helpers and improves existing test assertions |
| cmd/space/join/join.go | Refactors invite parsing to support custom hosts and implements networkId fallback logic |
| cmd/space/join/join_test.go | Adds comprehensive tests for invite link parsing with various host patterns |
| cmd/config/set/set.go | Adds networkId as a settable config key |
| cmd/config/get/get.go | Adds networkId to config output display |
| README.md | Documents self-hosted network usage patterns |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
cmd/space/join/join.go
Outdated
| return output.Error("invite link missing Cid") | ||
| if inviteCid == "" { | ||
| if parsedCid == "" { | ||
| return output.Error("invalid invite link: invite link missing Cid in path") |
Copilot
AI
Dec 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message contains redundant text. The phrase "invalid invite link: invite link missing Cid in path" repeats "invite link" unnecessarily. Consider simplifying to "invalid invite link: missing Cid in path" for clarity and conciseness.
| return output.Error("invalid invite link: invite link missing Cid in path") | |
| return output.Error("invalid invite link: missing Cid in path") |
cmd/space/join/join.go
Outdated
| if err != nil { | ||
| return output.Error("Failed to view invite: %w", err) | ||
| if parsedKey == "" { | ||
| return output.Error("invalid invite link: invite link missing key (should be after #)") |
Copilot
AI
Dec 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message contains redundant text. The phrase "invalid invite link: invite link missing key" repeats "invite link" unnecessarily. Consider simplifying to "invalid invite link: missing key (should be after #)" for clarity and conciseness.
| return output.Error("invalid invite link: invite link missing key (should be after #)") | |
| return output.Error("invalid invite link: missing key (should be after #)") |
| func parseInviteLink(input string) (string, string, error) { | ||
| cid, key, err := parseInviteLinkParts(input) | ||
| if err != nil { | ||
| return "", "", err | ||
| } | ||
| if cid == "" { | ||
| return "", "", fmt.Errorf("invite link missing Cid in path") | ||
| } | ||
| if key == "" { | ||
| return "", "", fmt.Errorf("invite link missing key (should be after #)") | ||
| } | ||
| return cid, key, nil | ||
| } |
Copilot
AI
Dec 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function parseInviteLink appears to be defined solely for testing purposes but is not used in the main command logic. The actual command uses parseInviteLinkParts and performs validation inline. Consider either using parseInviteLink in the command logic (lines 41-57) to reduce code duplication and improve maintainability, or add a comment explaining that parseInviteLink is a convenience wrapper for testing.
| if u.Scheme != "https" && u.Scheme != "http" { | ||
| return "", "", fmt.Errorf("unsupported scheme %q (expected http or https)", u.Scheme) |
Copilot
AI
Dec 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code allows both HTTP and HTTPS schemes for invite links, which could pose a security risk. Invite links may contain sensitive information (CID and key), and allowing HTTP means this data could be transmitted in plaintext over unencrypted connections. Consider adding a warning when HTTP is used, restricting HTTP to localhost/development environments only, or requiring HTTPS for production use to protect sensitive invite data.
| if u.Scheme != "https" && u.Scheme != "http" { | |
| return "", "", fmt.Errorf("unsupported scheme %q (expected http or https)", u.Scheme) | |
| // Only allow https for invite links in general. | |
| // Permit http only for localhost/loopback to support development environments. | |
| if u.Scheme != "https" { | |
| isLocalhost := u.Host == "localhost" || strings.HasPrefix(u.Host, "127.0.0.1") || u.Host == "[::1]" | |
| if !(u.Scheme == "http" && isLocalhost) { | |
| return "", "", fmt.Errorf("unsupported scheme %q (expected https, or http only for localhost)", u.Scheme) | |
| } |
|
Fixed the lint issues |
Summary
networkId(via existing ~/.anytype/config.json) and use it as the default foranytype space joinwhen--networkisn't providedProblem
Self-hosted invites are rejected with:
invalid invite link format, expected: https://invite.any.coop/{cid}#{key}Fixes #6
Testing
/Users/raj/sdk/go1.24.6/bin/go test ./...