serverapi

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: MIT Imports: 20 Imported by: 0

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

View Source
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

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

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

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

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

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

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.

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.

Jump to

Keyboard shortcuts

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