Documentation
¶
Overview ¶
Package serverapi implements moth.server.v1 — the services the developer's own backend calls with the project secret key (`x-moth-key: sk_...`): online token introspection and programmatic user management.
Index ¶
- Constants
- func NewSecretKeyInterceptor(st store.ProjectStore) connect.UnaryInterceptorFunc
- type EntitlementHandler
- type EntitlementStore
- type PushHandler
- func (h *PushHandler) ListPushDevices(ctx context.Context, req *connect.Request[serverv1.ListPushDevicesRequest]) (*connect.Response[serverv1.ListPushDevicesResponse], error)
- func (h *PushHandler) ListUserPushDevices(ctx context.Context, req *connect.Request[serverv1.ListUserPushDevicesRequest]) (*connect.Response[serverv1.ListUserPushDevicesResponse], error)
- func (h *PushHandler) RevokePushDevice(ctx context.Context, req *connect.Request[serverv1.RevokePushDeviceRequest]) (*connect.Response[serverv1.RevokePushDeviceResponse], error)
- type PushStore
- type Store
- type TokenHandler
- type UserHandler
- func (h *UserHandler) CreateUser(ctx context.Context, req *connect.Request[serverv1.CreateUserRequest]) (*connect.Response[serverv1.CreateUserResponse], error)
- func (h *UserHandler) DeleteUser(ctx context.Context, req *connect.Request[serverv1.DeleteUserRequest]) (*connect.Response[serverv1.DeleteUserResponse], error)
- func (h *UserHandler) DisableUser(ctx context.Context, req *connect.Request[serverv1.DisableUserRequest]) (*connect.Response[serverv1.DisableUserResponse], error)
- func (h *UserHandler) EnableUser(ctx context.Context, req *connect.Request[serverv1.EnableUserRequest]) (*connect.Response[serverv1.EnableUserResponse], error)
- func (h *UserHandler) GetUser(ctx context.Context, req *connect.Request[serverv1.GetUserRequest]) (*connect.Response[serverv1.GetUserResponse], error)
- func (h *UserHandler) ListUsers(ctx context.Context, _ *connect.Request[serverv1.ListUsersRequest]) (*connect.Response[serverv1.ListUsersResponse], error)
- func (h *UserHandler) RevokeUserSessions(ctx context.Context, req *connect.Request[serverv1.RevokeUserSessionsRequest]) (*connect.Response[serverv1.RevokeUserSessionsResponse], error)
- func (h *UserHandler) UpdateUser(ctx context.Context, req *connect.Request[serverv1.UpdateUserRequest]) (*connect.Response[serverv1.UpdateUserResponse], error)
Constants ¶
const ( InactiveMalformed = "MALFORMED" InactiveInvalidSignature = "INVALID_SIGNATURE" InactiveExpired = "EXPIRED" InactiveUserNotFound = "USER_NOT_FOUND" InactiveUserDisabled = "USER_DISABLED" )
Machine-readable causes for inactive introspection results.
Variables ¶
This section is empty.
Functions ¶
func NewSecretKeyInterceptor ¶
func NewSecretKeyInterceptor(st store.ProjectStore) connect.UnaryInterceptorFunc
NewSecretKeyInterceptor authenticates moth.server.v1 calls: it resolves the project from the secret key in x-moth-key metadata and injects it into the context (same context slot as the auth service, so helpers are shared).
Types ¶
type EntitlementHandler ¶
type EntitlementHandler struct {
// contains filtered or unexported fields
}
EntitlementHandler implements moth.server.v1.EntitlementService: it hands the developer's own backend the same derived entitlement set the client sees, so server-side feature gating never has to trust the client.
func NewEntitlementHandler ¶
func NewEntitlementHandler(st EntitlementStore, now func() time.Time) *EntitlementHandler
NewEntitlementHandler builds the service. now is injectable for tests; nil means time.Now.
func (*EntitlementHandler) GetUserEntitlements ¶
func (h *EntitlementHandler) GetUserEntitlements(ctx context.Context, req *connect.Request[serverv1.GetUserEntitlementsRequest]) (*connect.Response[serverv1.GetUserEntitlementsResponse], error)
GetUserEntitlements returns the user's currently-held entitlements. A user with no subscription and no grant returns an empty set (the free `none` state), never an error.
type EntitlementStore ¶
type EntitlementStore interface {
store.UserStore
store.EntitlementStore
store.ProductStore
store.SubscriptionStore
store.SubscriptionGrantStore
}
EntitlementStore is what the developer-backend entitlement service reads.
type PushHandler ¶
type PushHandler struct {
// contains filtered or unexported fields
}
PushHandler implements moth.server.v1.PushService: it hands the developer's backend — the sender — the project's active push registrations, credentials included, and takes dead-credential reports back (the feedback loop). This is the only surface that ever returns tokens; project scoping comes from the secret key resolved by the interceptor, so one project's sender can never see another's registrations.
func NewPushHandler ¶
func NewPushHandler(st PushStore, now func() time.Time) *PushHandler
NewPushHandler builds the service. now is injectable for tests; nil means time.Now.
func (*PushHandler) ListPushDevices ¶
func (h *PushHandler) ListPushDevices(ctx context.Context, req *connect.Request[serverv1.ListPushDevicesRequest]) (*connect.Response[serverv1.ListPushDevicesResponse], error)
ListPushDevices pages through the project's active registrations, newest first, optionally filtered by target. The page token is the id of the last row of the previous page (ids are UUIDv7, so id order is creation order).
func (*PushHandler) ListUserPushDevices ¶
func (h *PushHandler) ListUserPushDevices(ctx context.Context, req *connect.Request[serverv1.ListUserPushDevicesRequest]) (*connect.Response[serverv1.ListUserPushDevicesResponse], error)
ListUserPushDevices returns one user's active registrations, most recently seen first. A bad user id is NotFound; a user with no registrations is an empty list, never an error.
func (*PushHandler) RevokePushDevice ¶
func (h *PushHandler) RevokePushDevice(ctx context.Context, req *connect.Request[serverv1.RevokePushDeviceRequest]) (*connect.Response[serverv1.RevokePushDeviceResponse], error)
RevokePushDevice is the feedback loop: the sender reports a credential the push service rejected (by token or by installation device_id) and moth revokes it (`reported_invalid`) so it never serves it again. Idempotent: unknown or already-revoked credentials succeed.
type PushStore ¶
type PushStore interface {
store.UserStore
store.PushDeviceStore
}
PushStore is what the developer-backend push service reads and revokes.
type Store ¶
type Store interface {
store.ProjectStore
store.UserStore
store.RefreshTokenStore
}
Store is everything the server API needs from persistence.
type TokenHandler ¶
type TokenHandler struct {
// contains filtered or unexported fields
}
TokenHandler implements moth.server.v1.TokenService.
func NewTokenHandler ¶
func NewTokenHandler(st Store, now func() time.Time) *TokenHandler
NewTokenHandler builds the token service. now is injectable for tests; nil means time.Now.
func (*TokenHandler) IntrospectToken ¶
func (h *TokenHandler) IntrospectToken(ctx context.Context, req *connect.Request[serverv1.IntrospectTokenRequest]) (*connect.Response[serverv1.IntrospectTokenResponse], error)
type UserHandler ¶
type UserHandler struct {
// contains filtered or unexported fields
}
UserHandler implements moth.server.v1.UserService.
func NewUserHandler ¶
func NewUserHandler(st Store, now func() time.Time) *UserHandler
NewUserHandler builds the user management service. now is injectable for tests; nil means time.Now.
func (*UserHandler) CreateUser ¶
func (h *UserHandler) CreateUser(ctx context.Context, req *connect.Request[serverv1.CreateUserRequest]) (*connect.Response[serverv1.CreateUserResponse], error)
func (*UserHandler) DeleteUser ¶
func (h *UserHandler) DeleteUser(ctx context.Context, req *connect.Request[serverv1.DeleteUserRequest]) (*connect.Response[serverv1.DeleteUserResponse], error)
func (*UserHandler) DisableUser ¶
func (h *UserHandler) DisableUser(ctx context.Context, req *connect.Request[serverv1.DisableUserRequest]) (*connect.Response[serverv1.DisableUserResponse], error)
func (*UserHandler) EnableUser ¶
func (h *UserHandler) EnableUser(ctx context.Context, req *connect.Request[serverv1.EnableUserRequest]) (*connect.Response[serverv1.EnableUserResponse], error)
func (*UserHandler) GetUser ¶
func (h *UserHandler) GetUser(ctx context.Context, req *connect.Request[serverv1.GetUserRequest]) (*connect.Response[serverv1.GetUserResponse], error)
func (*UserHandler) ListUsers ¶
func (h *UserHandler) ListUsers(ctx context.Context, _ *connect.Request[serverv1.ListUsersRequest]) (*connect.Response[serverv1.ListUsersResponse], error)
func (*UserHandler) RevokeUserSessions ¶
func (h *UserHandler) RevokeUserSessions(ctx context.Context, req *connect.Request[serverv1.RevokeUserSessionsRequest]) (*connect.Response[serverv1.RevokeUserSessionsResponse], error)
func (*UserHandler) UpdateUser ¶
func (h *UserHandler) UpdateUser(ctx context.Context, req *connect.Request[serverv1.UpdateUserRequest]) (*connect.Response[serverv1.UpdateUserResponse], error)