license

package
v0.167.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: Apache-2.0 Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package license decides whether paid features are on.

A key is a string the customer pastes into settings after paying. It carries its own expiry and is checked here, on the machine, with no network call and no signature — see ADR-022. The binary is Apache-2.0, so anyone determined to have the features can delete this file and rebuild; the key exists to make paying work, not to make not-paying fail.

What that buys is reliability in the direction that matters. With no paying customers yet, the failure worth engineering against is not somebody stealing a feature — it is somebody paying and not receiving one. A check that needs nothing but the string cannot fail on a plane, behind a proxy, or while our servers are down, because there are none.

Index

Constants

View Source
const Grace = 7 * 24 * time.Hour

Grace is how long features keep working after a key expires.

A card that did not go through, a bank sitting on a renewal, an address that changed — none of those are a customer deciding to stop paying, and being cut off by their bank's timing produces an angry email that costs more than a week of features given away.

View Source
const Prefix = "CR-"

Prefix marks a Caprock key. Present so a user who pastes the wrong string — a Stripe receipt id, an API key — is told what is wrong rather than just "invalid".

Variables

This section is empty.

Functions

func Issue

func Issue(until time.Time, rand func() string) string

Issue mints a key valid until `until`, in the same format the Stripe webhook produces (caprock-web/functions/api/stripe-webhook.ts).

It exists because the webhook was the only thing that could make a key, and that leaves the owner unable to serve the cases payment rails do not cover: a customer who paid another way, a refund reissued, a friend, a conference. A business with no manual override is one that fails its first unusual customer.

The randomness is not a secret — nothing verifies it. It exists so two keys issued on the same day are distinguishable when someone quotes one in an email.

func RandomSuffix

func RandomSuffix() string

RandomSuffix is the default Issue suffix: eight uppercase hex characters.

Types

type State

type State struct {
	// Active is the only field a feature check should read.
	Active bool `json:"active"`
	// InGrace is true when the key expired but Grace has not run out. Features
	// are on; the dashboard says so.
	InGrace bool `json:"in_grace"`
	// ExpiresAt is the key's own date, absent when there is no valid key.
	//
	// A pointer because `omitempty` does not omit a zero time.Time — it
	// serialises as 0001-01-01, and a dashboard that reads the field to say
	// "renews …" would print the year one at anybody without a key.
	ExpiresAt *time.Time `json:"expires_at,omitempty"`
	// Reason explains an inactive state in words a person can act on.
	Reason string `json:"reason,omitempty"`
}

State is what the dashboard needs to know about a key.

func Parse

func Parse(key string, now time.Time) State

Parse reads a key and reports what it grants at time `now`.

The format is `CR-YYYY-MM-DD-XXXXXXXX`: a prefix, the expiry date, and eight characters of randomness so two keys issued on the same day differ. The date is in the key rather than in a database because there is no database — the key IS the record.

Jump to

Keyboard shortcuts

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