SpaceMIX v0.1.0

Marketplace

experimentalfor bothsince protocol 1

The paid Marketplace in SpaceMIX Hub: the /v1/market/* routes and their types, prices in minor units and times in Unix seconds, which versions are free and which are paid, a server's signed requests, entitlements and their grace period, and what a server does with an extension that isn't paid for.

The Marketplace is where developers sell extensions and people buy them, in SpaceMIX Hub. It sits on top of the registry: a listing is the same listing, with a price. A purchase covers one server, and everyone on that server uses it. The JSON shapes are in packages/sdk/src/registry.ts, camelCase on the wire.

Use this page when you sell an extension, or when you write a client or a server that buys, downloads or checks paid ones. How to set a price on SpaceMIX Hub's own site is in Publishing.

Stability: everything on this page is experimental while the Marketplace is being built: the routes, the types (ListingPrice, PriceModel, PriceInterval, PriceInput, MarketConfig, SellerStatus, DuplicatePurchase, CheckoutRequest, EntitlementStatus, Purchase, ServerEntitlement, ServerEntitlements), the registry fields Listing.price, VersionInfo.paid and UpdateInfo.paid, the signed-request format and the grace period.

How selling works

  • The developer is the seller. Each developer connects a Stripe Connect Standard account. Every charge is a direct charge on that account, so the developer is the merchant of record and handles tax and refunds in their own Stripe dashboard.
  • SpaceMIX takes a fee. It is Stripe's application fee: the percentage feePercent in Config of each charge, default 20. For a one-time price it is the amount times the percentage, rounded down, in minor units; for a subscription it is Stripe's application_fee_percent.
  • A price is one of three models (PriceModel): free, one_time, or recurring (per month or per year).
  • A purchase covers one server. It is recorded per server id and extension id, whoever on that server bought it.
  • The publisher's servers get it free. A server the listing's publisher was let into within the last 30 days may download and run every paid version, with no purchase.
  • Paid listings are never essentials. GET /v1/registry/defaults leaves out every listing with a price.

On a SpaceMIX Hub with no payments set up, every /v1/market/* route answers 503 with code market_disabled and The Marketplace isn't set up on this SpaceMIX Hub. Free listings work as before; paid versions stay behind the entitlements already recorded.

Conventions

Different from the rest of the registry:

  • Money is an integer in minor units (cents): 500 with eur is €5.00.
  • Times are Unix seconds, like Stripe's. The registry's own times (Listing.createdAt, VersionInfo.publishedAt) stay milliseconds.

The same as the registry:

  • Auth. Routes marked signed in take Authorization: Bearer <refreshToken> (see Registry conventions).
  • Errors are JSON { "error": "<sentence>", "code": "<name>" }; the sentence is for people, the code is for clients to act on. Some carry more fields (listingId, stripeCode).
  • A Stripe failure answers 502 stripe_error with Stripe couldn't do that right now. Try again later. On the seller's own routes (seller/onboarding and the price routes) it also carries stripeCode, Stripe's own error code, which their Stripe dashboard explains.

Routes

Method and path Auth Does
GET /v1/market/config public The fee, currencies, intervals, price bounds and grace period
GET /v1/market/seller signed in The caller's Stripe account and the duplicate payments on it
POST /v1/market/seller/onboarding signed in A Stripe onboarding link, connecting an account first if there is none
PUT /v1/market/listings/{id}/price publisher Set the listing's price
DELETE /v1/market/listings/{id}/price publisher Make the listing free
POST /v1/market/checkout signed in A Stripe Checkout for one extension on one server
GET /v1/market/purchases signed in What the caller bought
POST /v1/market/portal signed in Stripe's Billing Portal for one of the caller's subscriptions
GET /v1/market/entitlements?server=<id> the server's signed request What a server may run

Config

GET /v1/market/config
→ 200 MarketConfig

Today: feePercent as the Hub sets it (20 by default), currencies ["eur", "usd", "gbp"], intervals ["month", "year"], minAmount 100, maxAmount 100000 (1.00 to 1,000.00 in every currency), graceSeconds 604800 (7 days).

Seller

GET /v1/market/seller
→ 200 { seller: SellerStatus, duplicates: DuplicatePurchase[] }

POST /v1/market/seller/onboarding
{ returnUrl?: string, refreshUrl?: string }
→ 200 { url: string, seller: SellerStatus }
  • GET refreshes chargesEnabled and detailsSubmitted from Stripe when an account is connected. duplicates are the newest 100 checkouts paid for a server that already had the extension; the seller refunds them in Stripe.
  • Onboarding makes one Standard account per SpaceMIX ID (pressing twice reuses it), or a new one after the seller disconnected the old one, then returns Stripe's onboarding link. Send the browser to url.
  • returnUrl and refreshUrl must be on the Hub's return address; refreshUrl defaults to returnUrl.
  • Prices can be set once chargesEnabled is true.

Price

PUT /v1/market/listings/{id}/price
PriceInput
→ 200 { id: string, price: ListingPrice }

DELETE /v1/market/listings/{id}/price
→ 200 { id: string, price: null }

Only the listing's publisher. PUT with model: "free" does what DELETE does.

  • A paid price needs currency (eur, usd or gbp, any case), amount (100 to 100,000 minor units) and, for recurring, interval (month or year). A one_time price has no interval.
  • The same price again changes nothing. A new price is a new Stripe Price; the old one stops being offered, and subscribers keep paying the old one.
  • Setting a price decides which versions become paid; see Free and paid versions.
  • Making a listing free is refused while subscriptions to it still run.
Status Error
400 The model is free, one_time or recurring., The currency is one of eur, usd, gbp., Give the amount in minor units (cents)., The amount is 100 to 100000 in minor units (cents)., A recurring price is per month or per year., A one-time price has no interval.
403 Only the extension's publisher can set its price., This extension was taken down.
404 There's no extension with that id in the registry.
409 seller_not_ready: Finish setting up payments with Stripe before you set a price. active_subscriptions (on clearing): People still subscribe to this extension. Cancel their subscriptions in Stripe before you make it free.

Checkout

POST /v1/market/checkout
CheckoutRequest
→ 200 { url: string, sessionId: string }

Opens a Stripe Checkout Session on the seller's account for the listing's current price, for serverId. Send the browser to url. A new checkout expires the caller's own open checkouts for the same server and extension from the last 24 hours, so nobody pays twice from two tabs. The purchase is recorded when Stripe tells the Hub it was paid, not when the browser comes back.

Status Code Error
400 The server id should be 32 lowercase hex characters.
400 bad_return_url Return addresses must be on <return address>.
403 not_on_server Sign in to that server with this SpaceMIX ID first, then buy the extension for it. The caller must have been let into the server (the server's signed receipt at POST /v1/me/servers/{id}/connected).
404 There's no extension with that id in the registry. (also for a taken-down one)
409 own_listing This is your own extension: it's free on every server you're on.
409 not_for_sale This extension is free: install it, there's nothing to buy.
409 seller_not_ready The publisher can't take payments right now. Try again later.
409 publisher_server This extension's publisher is on that server, so it's free there already.
409 already_entitled That server already has this extension. A lapsed purchase, even one still in its grace period, can be bought again.
409 checkout_in_progress A checkout for this is being opened already. Try again in a moment.

Purchases and the Billing Portal

GET /v1/market/purchases
→ 200 { items: Purchase[] }          // newest first

POST /v1/market/portal
{ extensionId: string, serverId: string, returnUrl?: string }
→ 200 { url: string }

The portal opens on the seller's account for the caller's own subscription (Purchase.manageable). 404 You didn't buy that extension for that server.; 409 not_a_subscription That purchase isn't a subscription.

Entitlements

GET /v1/market/entitlements?server=<server id>
→ 200 ServerEntitlements

Only on the server's own signed request with the purpose GET /v1/market/entitlements; without the headers, 401 server_proof_required Sign the request with the server's key. Every purchase recorded for that server, plus one kind: "publisher" entry for each paid listing whose publisher was let into the server within the last 30 days (unless a purchase already covers it).

Return addresses

Stripe sends people back to the Hub's return address, by default the Hub's own address. A returnUrl, refreshUrl or cancelUrl must be that address itself or start with it followed by /, ? or #, be at most 2,048 characters, and hold no spaces or control characters. Left out, it is that address.

Free and paid versions

Each version of a listing is free or paid (VersionInfo.paid, absent when free):

  • A version published while the listing has a price is paid. One published while the listing was free stays free when a price is set later, so a server that got it free keeps it.
  • Before anyone else has it, a price makes every version paid. If no server except the publisher's own has ever reported the listing installed (POST /v1/registry/installs), setting a price marks every version paid. The first report from another server makes the listing shared for good; after that, versions published while it was free stay free.
  • Clearing the price makes every version free. A version is shown and served as paid only while the listing has a price. Clearing it also unmarks every version, so setting a price again only makes the versions published from then on paid (or all of them, if no server but the publisher's own ever installed the listing).
  • A listing whose seller can't take payments (onboarding unfinished, or the account disconnected) keeps its price with forSale: false: it can't be bought now, and its paid versions still need an entitlement.

Downloading a paid version

GET /v1/registry/extensions/{id}/versions/{version}?server=<server id> serves a paid version only when all of these hold:

  1. server is 32 lowercase hex characters;
  2. the request is signed by that server with the purpose GET /v1/registry/extensions/{id}/versions/{version} (the raw id and version, no query);
  3. the server has an entitlement that is entitled now, or the listing's publisher was let into that server within the last 30 days.

Anything less answers 402:

{ "error": "This extension is paid. Buy it for this server in the Marketplace first.", "code": "payment_required", "listingId": "<id>" }

Free versions download as before, with or without the headers. The Download section has the other answers.

Signed server requests

A server proves who it is to the Marketplace with its Ed25519 key, the one its id is the fingerprint of. Every request carries four headers:

Header Value
Spacemix-Server-Key The server's public key: base64url, no padding, the raw 32 bytes.
Spacemix-Server-Time Now, in Unix seconds, decimal.
Spacemix-Server-Nonce 64 lowercase hex characters, fresh for every request.
Spacemix-Server-Signature base64url Ed25519 by that key over the signing input below.

The signing input is five length-prefixed fields (each a 4-byte big-endian length, then UTF-8): spacemix-server-market/v1, the server id, the purpose ("<METHOD> <path>", the path without its query), the time as sent, and the nonce (market_request_input in spacemix-auth/src/server.rs).

The Hub checks, in order:

Status Code Error
400 Send the server's key, time, nonce and signature together. (some headers but not all), The server id should be 32 lowercase hex characters., The nonce should be 64 lowercase hex characters., The time should be Unix seconds.
403 server_clock_skew The server's clock is too far from ours. Check its time. More than 300 seconds either way.
403 server_proof_failed That request isn't signed by the server's key.
403 server_unknown This SpaceMIX Hub doesn't know that server yet. Sign in to it with a SpaceMIX ID first. The key must be the one the server proved itself with at a /v1/token sign-in.
429 rate_limited Too many requests from this server. Wait a minute. At most 60 signed requests a minute per server, entitlement reads and paid downloads together.
403 server_proof_replayed That request was already used. Each nonce is accepted once.

Entitlements and the grace period

An entitlement is one server's purchase of one extension. Its status (EntitlementStatus) is active or past_due while it runs, and canceled or refunded once it has ended; those two are final. entitled says whether the server may run the extension now.

What happens in Stripe Entitlement
The checkout is paid active; for a subscription, up to the end of the period paid for.
A renewal fails (Stripe keeps retrying) past_due, still entitled.
Stripe stops retrying and marks the subscription unpaid or paused past_due and lapsed (revokedAt); it comes back when it is paid.
The subscription ends canceled, lapsed.
A one-time charge is fully refunded, or any charge is disputed refunded, lapsed. A partial refund changes nothing.
The seller disconnects their Stripe account from SpaceMIX They can't sell; each running subscription lapses at the end of its period.
  • Grace period. A lapsed entitlement stays entitled for 7 days after revokedAt (graceEndsAt), then the server turns the extension off.
  • Subscriptions run out on their own. A subscription stops being entitled 7 days after its currentPeriodEnd, renewal event or not; a renewal moves the period end.
  • Duplicate payments. A checkout paid for a server whose entitlement is still running grants nothing; it is listed in the seller's duplicates for them to refund.

What a server does

apps/desktop/src-tauri/src/market.rs and registry.rs, on a SpaceMIX server. With the Hub off it asks nothing, and only what it already knows applies:

  • Asks for its entitlements with a signed GET /v1/market/entitlements: at startup and about every 6 hours once it has anything installed and uses the Hub, after installing or updating a paid extension, and when the owner asks (POST /api/extensions/entitlements/refresh, owner only; the app calls it right after a purchase). After a 429 it waits 2 minutes. The last good answer is kept (kv _server/marketEntitlements). A Hub that is down, or answers market_disabled, server_unknown or rate_limited, never turns anything off by itself; the deadlines in the last answer still apply, checked every 10 minutes against the server's own clock.
  • Looks up each installed extension's listing to know whether it is paid (kv _server/marketListingFacts), once it uses the Hub. On a server that doesn't, nothing is asked; only what it already knows applies. Only a 200 replaces what it knew. The Hub's 404 with code: "not_found" counts as "not listed" only when nothing was known before; any other failure keeps what was known. An id with no known price runs.
  • The licence follows the id on a server that uses the Hub, whatever installed it (on one that doesn't, nothing is asked; only what it already knows applies. It can know something because using the Hub is current state: a server that stops using it keeps its last answers, and they still apply every 10 minutes. And an owner arriving at an extension's page from the Hub runs the check in POST /api/extensions/entitlements/refresh, which can turn a paid file off): the registry, a package file, the Studio or a build on this machine. An installed package whose version and hash match a published free version is free. Any other build of a priced listing (an unreleased version number, or a changed package) counts as paid.
  • Turns an extension off when it is paid and the Hub's answer doesn't cover this server, when the Hub says it isn't entitled, or when a deadline (graceEndsAt, or a subscription's period end plus the grace period) has passed. It runs again as soon as an answer says it is entitled. What turned off means for an extension is in Turned off until it's paid for.
  • Signs every download with its key, so a paid version it has bought comes through. Installing a paid version it hasn't bought fails with 402 { error, code: "payment_required", listingId, hint } (<id> is a paid extension this server hasn't bought. Buy it in the Marketplace, then try again.), or 403 with code: "server_unknown" when nobody has signed in to the server with a SpaceMIX ID yet.
  • Holds paid updates. An update whose UpdateInfo.paid is true, for an extension this server isn't entitled to, is held as a PendingUpdate row with paymentRequired: true without downloading it, and the people who manage extensions get <Name> <version> is available. It's paid: buy it for this server in the Marketplace to update. It is tried again once the Hub says the server has it.
  • Tells the owner when a paid extension's purchase lapses (<Name>'s purchase for this server has lapsed. It turns off in <n> days unless it's renewed in the Marketplace.), when it is turned off, when a paid version this server hasn't bought is turned off, and when it is on again. These notices come from source core.extensions with the target license/<extension id>, which opens that extension's page in Extensions. A build made on this server under a paid listing's id gets its own wording, since it isn't for sale: <Name> is a build made on this server, and a paid extension in the Marketplace has the same id, so it's turned off. Its data is kept. See Updates in Extensions. That listing waits for the owner (see When a listing takes a build's id).

Types

type PriceModel = "free" | "one_time" | "recurring";
type PriceInterval = "month" | "year";
type EntitlementStatus = "active" | "past_due" | "canceled" | "refunded";

interface ListingPrice {           // Listing.price; absent when free
  model: "one_time" | "recurring";
  amount: number;                  // minor units
  currency: string;                // lowercase ISO code, one of MarketConfig.currencies
  interval?: PriceInterval;        // for recurring
  forSale?: boolean;               // present, and false, only while the seller can't take payments
}

interface PriceInput { model: PriceModel; amount?: number; currency?: string; interval?: PriceInterval }

interface MarketConfig {
  feePercent: number;
  currencies: string[];
  intervals: PriceInterval[];
  minAmount: number;               // minor units, the same for every currency
  maxAmount: number;
  graceSeconds: number;
}

interface SellerStatus {
  connected: boolean;              // a Stripe account is connected; onboarding may be unfinished
  stripeAccountId?: string;
  chargesEnabled: boolean;         // prices can be set
  detailsSubmitted: boolean;
  disconnectedAt?: number;         // the seller disconnected it then; connected is false
}

interface DuplicatePurchase {
  sessionId: string;
  extensionId: string;
  serverId: string;
  kind: "one_time" | "recurring";
  amount: number;
  currency: string;
  paymentIntentId?: string;
  subscriptionId?: string;
  createdAt: number;
}

interface CheckoutRequest {
  extensionId: string;
  serverId: string;                // the buyer must have signed in there
  returnUrl?: string;
  cancelUrl?: string;              // defaults to returnUrl
}

interface Purchase {
  extensionId: string;
  name: string;                    // the listing's name now, or the id when it's gone
  serverId: string;
  kind: "one_time" | "recurring";
  status: EntitlementStatus;
  entitled: boolean;               // the server may run it now
  currentPeriodEnd?: number;
  revokedAt?: number;              // when it lapsed
  graceEndsAt?: number;            // revokedAt plus the grace period
  amount: number;
  currency: string;
  interval?: PriceInterval;
  manageable: boolean;             // a subscription the Billing Portal can manage
  createdAt: number;
  updatedAt: number;
}

interface ServerEntitlement {
  extensionId: string;
  kind: "one_time" | "recurring" | "publisher";
  status: EntitlementStatus;
  entitled: boolean;
  currentPeriodEnd?: number;
  revokedAt?: number;
  graceEndsAt?: number;            // turn the extension off from then on
  buyerAccountId?: string;
  updatedAt: number;
}

interface ServerEntitlements {
  server: string;
  now: number;                     // the Hub's clock
  graceSeconds: number;
  items: ServerEntitlement[];
}

A publisher entry has no period, revoke or buyer, and stays entitled while the publisher keeps signing in to that server. A server should treat a kind it doesn't know by its entitled and deadlines alone.

This page as markdown · All pages as one file