Documentation
¶
Overview ¶
Package fields declares the example application's custom account fields.
The declaration is the single source for storage, validation, the API contract and the generated Go and TypeScript types. Run `go generate ./examples/profile/...` after adding a version, then review and commit fields_gen.go, api/openapi.json and web/generated/.
Index ¶
Constants ¶
const ProfileFingerprint = "54e202cedabbf98b383a1358438793833490e5f7057acdbe47befd9f0ef0bbe4"
ProfileFingerprint identifies the extension declaration these types were generated from.
Variables ¶
var Schema = userfields.Schema{ ID: "profile", Versions: []userfields.Version{ {Name: "initial", Fields: []userfields.Field{ {Name: "displayName", Kind: userfields.String, Access: userfields.ReadWrite, MaxLength: 64, Description: "Name shown to other members; empty until the user sets one."}, {Name: "locale", Kind: userfields.Enum, Access: userfields.ReadWrite, Values: []string{"en", "de", "fr", "ja"}, Default: "en", Description: "Preferred language for mail and UI."}, {Name: "plan", Kind: userfields.Enum, Access: userfields.ReadOnly, Values: []string{"free", "pro", "team"}, Default: "free", Description: "Subscription tier; changed only by billing code."}, {Name: "billingCustomerId", Kind: userfields.String, Access: userfields.Private, MaxLength: 64, Description: "Payment provider customer reference; never sent to browsers."}, }}, {Name: "consent", Fields: []userfields.Field{ {Name: "marketingEmails", Kind: userfields.Boolean, Access: userfields.ReadWrite, Description: "Opt-in to product news; defaults to off."}, {Name: "termsAcceptedAt", Kind: userfields.Timestamp, Access: userfields.ReadOnly, Description: "When the current terms were accepted; null until then."}, {Name: "riskScore", Kind: userfields.Integer, Access: userfields.Private, Minimum: 0, Maximum: 100, Description: "Fraud review score maintained by back-office code."}, }}, }, }
Schema is append-only: released versions and fields never change.
Functions ¶
func CheckProfile ¶
func CheckProfile(p *userfields.Plugin) error
CheckProfile fails unless p was compiled from the declaration these types describe.
func New ¶
func New() (*userfields.Plugin, error)
New compiles the schema and checks that the generated types match it.
Types ¶
type Profile ¶
type Profile struct {
// DisplayName is read_write (a string of 0 to 64 characters). Name shown to other members; empty until the user sets one.
DisplayName string
// Locale is read_write (one of en, de, fr, ja). Preferred language for mail and UI.
Locale string
// Plan is read_only (one of free, pro, team). Subscription tier; changed only by billing code.
Plan string
// BillingCustomerId is private (a string of 0 to 64 characters). Payment provider customer reference; never sent to browsers.
BillingCustomerId string
// MarketingEmails is read_write (a boolean). Opt-in to product news; defaults to off.
MarketingEmails bool
// TermsAcceptedAt is read_only (a timestamp; the zero time is null). When the current terms were accepted; null until then.
TermsAcceptedAt time.Time
// RiskScore is private (an integer from 0 to 100). Fraud review score maintained by back-office code.
RiskScore int64
}
Profile holds every field of the "profile" extension, including private ones. Automatic serialization (encoding/json, fmt, log/slog) renders only public fields.
func ProfileFrom ¶
func ProfileFrom(v userfields.Values) (Profile, error)
ProfileFrom converts Values read from the matching extension.
func (Profile) MarshalJSON ¶
MarshalJSON renders only the public fields, matching the HTTP response.
type ProfileUpdate ¶
type ProfileUpdate struct {
DisplayName *string
Locale *string
Plan *string
BillingCustomerId *string
MarketingEmails *bool
TermsAcceptedAt *time.Time
RiskScore *int64
}
ProfileUpdate is a partial update for Write; nil fields are left unchanged. For timestamps, a non-nil zero time stores null.
func (ProfileUpdate) Changes ¶
func (f ProfileUpdate) Changes() map[string]any
Changes returns the set fields for Write.