Expand description
Built-in resources.
organization, membership, user, api_key and oauth_connection exist
in every app. Together they make apps multitenant out of the box: users join
organisations through memberships (which also carry their role within that
organisation), and every other resource is isolated per organisation by
default.
invitation and auth_token are the two tables behind the flows that reach
somebody through their mailbox — being invited to an organisation,
confirming an address, resetting a password. They exist in every app, and in
one with no [email] provider they simply stay empty: the endpoints that
write to them are not mounted at all.
Drop a models/<name>.toml with the same name to replace a built-in and
add fields or tweak permissions while keeping the machinery working.
Constants§
- API_
KEY_ TOML - Default
api_keyresource (global). A valid key authenticates as its owner. - AUTH_
TOKEN_ TOML - A single-use token sent to an address to prove someone reads it.
- BILLING_
CUSTOMER_ TOML - The organisation as Stripe knows it: one row per tenant, holding the customer id every charge and subscription hangs off.
- BILLING_
EVENT_ TOML - Every webhook Stripe has delivered, by its event id.
- BILLING_
PAYMENT_ TOML - One payment that happened: a one-off purchase, or an invoice a subscription generated.
- BILLING_
PRICE_ TOML - One way to pay for a product: an amount, a currency, and either a billing interval (a subscription) or none (a one-off payment).
- BILLING_
PRODUCT_ TOML - A thing the app sells. Global: the catalogue is the same for every tenant.
- BILLING_
SUBSCRIPTION_ TOML - A live (or lapsed) subscription: one organisation paying for one price on a schedule.
- INVITATION_
TOML - An invitation to join an organisation, addressed to someone who may not have an account yet.
- MEMBERSHIP_
ROLE_ TOML - A single role held by a membership.
- MEMBERSHIP_
TOML - A user’s membership in an organisation, carrying their role there. The
join table behind the N:N between
userandorganization. - OAUTH_
TOML - Default
oauth_connectionresource (global) linking a user to a provider. - ORGANIZATION_
TOML - The
organization— the tenant.globalbecause its rows are the organisations; membership (not anorganization_id) decides who sees them. - USER_
TOML - The default
user: global (users are shared across organisations) with email + password auth. Extend viamodels/users.toml.
Functions§
- billing_
builtins - The billing resources, in dependency order (product before price, customer before subscription before payment).
- builtins
- The name → embedded-TOML table of built-ins, in dependency order so foreign keys resolve (organization and user before membership/api_key/oauth).
- parse_
builtin - Parse one built-in by its embedded TOML. Panics on a malformed built-in — that would be a bug in this crate, caught by the test below.