identity

package
v0.8.3 Latest Latest
Warning

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

Go to latest
Published: May 7, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrSlugNotFound = errors.New("slug_not_found")

ErrSlugNotFound is returned when neither the orgs/users table nor the rename history contains the requested slug.

View Source
var NamespaceCozyOrgs = uuid.MustParse("1d77e9f4-6b0c-4ee5-9e8b-2c5d0c5fa847")

NamespaceCozyOrgs is the UUID v5 namespace for org IDs. Fixed at first commit; never rotate (rotating breaks every existing reference).

View Source
var NamespaceCozyUsers = uuid.MustParse("8f1e3a2b-4d6c-4f5a-9b8c-7e2d1c3f4a5b")

NamespaceCozyUsers is the UUID v5 namespace for user IDs. Distinct from NamespaceCozyOrgs so an org and user with identical slugs map to different UUIDs.

Functions

func OrgIDFromSlug added in v0.7.0

func OrgIDFromSlug(slug string) uuid.UUID

OrgIDFromSlug returns the deterministic UUID for an org with this slug. Slug is canonicalized (trimmed, lowercased) before hashing — callers who pass already-validated slugs (which `validateOrgSlug` enforces lowercase) get a no-op canonicalization, but defending against accidental case-mismatches keeps the UUID stable.

func UserIDFromUsername added in v0.7.0

func UserIDFromUsername(username string) uuid.UUID

UserIDFromUsername returns the deterministic UUID for a user with this username. Same canonicalization rule as OrgIDFromSlug.

Types

type RenameHop added in v0.7.0

type RenameHop struct {
	FromSlug  string
	ToSlug    string
	RenamedAt time.Time
	RenamedBy string // empty when actor wasn't recorded (e.g. backfilled rows)
}

RenameHop is one entry in a row's rename history.

type Store

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

Store provides minimal identity lookups/mutations against profiles schema.

func NewStore

func NewStore(pg *pgxpool.Pool, schema string) *Store

func (*Store) ForwardOrgSlug added in v0.7.0

func (s *Store) ForwardOrgSlug(ctx context.Context, slug string) (string, error)

ForwardOrgSlug resolves any slug — current OR historical — to the current slug of the owning org. Returns ErrSlugNotFound when no row matches.

Lookup order:

  1. Direct match on orgs.slug (the typical "no rename" case).
  2. Match on org_renames.from_slug, joined to live orgs row, most-recent-rename wins (handles rename-back + post-hard-delete reuse).

func (*Store) ForwardUserUsername added in v0.7.0

func (s *Store) ForwardUserUsername(ctx context.Context, username string) (string, error)

ForwardUserUsername is the user-namespace equivalent of ForwardOrgSlug.

func (*Store) GetByID

func (s *Store) GetByID(ctx context.Context, id uuid.UUID) (*User, error)

func (*Store) GetEmailsByIDs

func (s *Store) GetEmailsByIDs(ctx context.Context, ids []uuid.UUID) (map[uuid.UUID]string, error)

GetEmailsByIDs returns user_id -> email.

func (*Store) GetIDByUsername

func (s *Store) GetIDByUsername(ctx context.Context, username string) (uuid.UUID, error)

func (*Store) GetUsernamesByIDs

func (s *Store) GetUsernamesByIDs(ctx context.Context, ids []uuid.UUID) (map[uuid.UUID]string, error)

GetUsernamesByIDs returns user_id -> username (empty if NULL).

func (*Store) GetUsersByIDs

func (s *Store) GetUsersByIDs(ctx context.Context, ids []uuid.UUID) (map[uuid.UUID]struct{ Username, Email string }, error)

GetUsersByIDs returns username+email pairs for given IDs.

func (*Store) ListOrgRenameHistory added in v0.7.0

func (s *Store) ListOrgRenameHistory(ctx context.Context, orgID string) ([]RenameHop, error)

ListOrgRenameHistory returns the recorded org slug rename rows in chronological order. Orgs with no renames return an empty slice.

func (*Store) ListUserRenameHistory added in v0.7.0

func (s *Store) ListUserRenameHistory(ctx context.Context, userID string) ([]RenameHop, error)

ListUserRenameHistory is the user equivalent. Users with no renames return an empty slice.

func (*Store) UpdateEmail

func (s *Store) UpdateEmail(ctx context.Context, id uuid.UUID, email string) error

func (*Store) UpdateUsername

func (s *Store) UpdateUsername(ctx context.Context, id uuid.UUID, username string) error

type User

type User struct {
	ID            uuid.UUID
	Email         string
	Username      *string
	EmailVerified bool
}

Jump to

Keyboard shortcuts

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