All products

MarketplaceOfficial

The BitaKit marketplace: its format and catalog check, its API and shared components, and the in-app plugin that installs items.

bitakit · Plugin for every BitaKit app

Type
Package
Needs a build
Kind
Plugin
BitaKit
Works with
Any app
Every BitaKit app
Versions
2
versions
Publisher
bitakit
Official

Preview

1 picture

Marketplace

About

@bitakit/marketplace

The BitaKit marketplace: one catalog for every BitaKit product. This package holds everything the marketplace's parts share:

  • the format: the records of a catalog and one check of a whole catalog (headless, zod and semver only);
  • the read-only /v1 API: its paths, answers and a client;
  • the shared UI: item cards, featured banners, filters and an app store style item page;
  • the in-app plugin: an app's /marketplace page and the installs into the app.

Format

import { checkCatalog, listingSchema } from '@bitakit/marketplace';

const listing = listingSchema.parse(json); // one item version, bitakit.listing@1
const { catalog, issues } = checkCatalog({
  products,
  kindDecisions,
  categories,
  suggestions,
  publisherTrust,
  items,
});

| Record | Owner | Schema | | ------------------------ | ----------------------------- | ---------------------- | | Listing, one per version | Publisher; never changes | listingSchema | | Page, one per item | Publisher; can change | pageSchema | | Product profile | The product's repository | productSchema | | Kind | Declared in a product profile | kindSchema | | Kind decisions | Marketplace super admin | kindDecisionsSchema | | Categories | Marketplace super admin | categorySchema | | Suggestion map | Marketplace super admin | suggestionsSchema | | Publisher trust | Marketplace super admin | publisherTrustSchema | | Item record | Marketplace (curation) | itemRecordSchema |

A listing names its pictures: icon, cover and images (paths next to it). Cards show the cover (else the first image, else a placeholder); the item page shows them as a sideways row of pictures. It may also name up to three MP4 videos (path, optional poster picture; without one the first frame shows), which lead that row and play in place; the marketplace accepts each video up to 100 MB. A listing's optional docs (https only) becomes a Documentation link on its page.

These fields (title, summary, text, pictures, videos, documentation link) are the item's page. A listing carries the page its version came with. The publisher can change the page later without a new version: the marketplace then keeps a page record (bitakit.page@1, pageSchema) beside the item's versions and shows it at every version. What a version installs, needs and may do never changes.

A package's permissions say what it adds (adds, for the app's roles) and what its server operations check (checks), each { resource: [operations] }. Publishers do not write them: bitakit build records them in dist/plugin.permissions.json, and the marketplace reads that file from the npm tarball (packagePermissions), fills the field in and refuses a listing whose permissions differ (samePermissions). A file artifact has none.

A package's contains counts the replaceable parts of an app it fills: a frame for the app's pages (layout.app), a frame for the sign-in pages (layout.auth), a screen (screen.not-found, screen.sign-in, ...). pluginParts lists the ids; each is the part's slot name. Publishers do not write them either: bitakit build records a package's candidates in dist/plugin.slots.json, and the marketplace reads that file from the npm tarball (packageContains), fills the field in, suggests categories from it and refuses a listing whose contains differ (sameContains). So a shell or a sign-in style is an ordinary package: what it fills says what it is.

import { chooseCommand, packageContains } from '@bitakit/marketplace';

const filled = packageContains(slotRecord); // { contains: [{ id: 'layout.app', count: 2 }] }
chooseCommand(item); // 'npx bitakit shell use @acme/rail', or undefined for other items

A product profile may name its own plugins, so the requirements on item pages read as names and link to their documentation instead of showing bare ids:

"plugins": [
  {
    "id": "email-templates",
    "name": "Email templates",
    "summary": "Multilingual emails with revisions and publishing.",
    "docs": "https://example.com/docs/email-templates"
  }
]

Item types

Every kind has an install way, and people see it as the item's type (installWays):

| Type | installWay | What it is | How it gets into an app | | ------- | ------------ | ------------------------------------------------- | ------------------------------------ | | Package | build | Code, an npm package (bitakit.plugin) | Added to the app's code, built | | Instant | in-app | A file in a format the product owns (a template) | Its installer imports it at run time | | Starter | create | A complete app as one archive (bitakit.starter) | It does not: it becomes a new app |

Cards show the type as a badge, item pages name it in their facts, lists filter by it (installWay), and search finds its name. The type is not a field of its own: it is the kind's installWay, so the format stays the same.

Starters

A starter is a complete app people create with one command and continue in their own code: a storefront for a product, a blog, a BitaKit app with sign-in. Its kind is BitaKit's own bitakit.starter, its artifact one gzipped tar archive (starterFormat, bitakit.starter@1), and its product what the app connects to (* for an app of its own). A product declares no create kinds of its own.

npm create @bitakit/app@latest storefront -- --starter acme/storefront

starterCommand(item) writes that command. npx bitakit publish packs the archive from an app's folder, and create-app checks it before unpacking. What an archive may hold is one set of rules for all of them, starterCheck(): only files and folders, every path inside the project, no environment file but .env.example (starterSetupFile, whose variables are the questions a new app's creator is asked), no node_modules or .git, at most starterLimits (20,000 files, 200 MB unpacked) and a package.json at the root.

import { starterCheck } from '@bitakit/marketplace';

const check = starterCheck();
for (const entry of entries) {
  // { path, type: 'File' | 'Directory' | ..., size } as a tar reader names them
  const problem = check.add(entry);
  if (problem) return problem;
}
return check.end(); // undefined: a starter; check.files lists its files

A marketplace applies it to every archive handed in and never unpacks or runs one. Lists hold starters only for starters: true (/v1/items?starters=true): a marketplace's own pages ask for them, an app's in-app marketplace does not.

Listings of plugin packages

Nobody writes the listing of an npm package by hand. Inside a plugin package, npx bitakit publish (from @bitakit/cli) writes it from package.json, npm's integrity of the version and the package's marketplace/ folder (icon, cover, screenshots/, videos/, an optional README.md and a listing.json with only the fields set by hand), and hands the version in to the marketplace as a draft. --dry-run prints the listing without sending it. For a version that is published already the command hands in only the folder's changed page, and npx bitakit marketplace pull writes a page that was edited on the website back into the folder. The CLI's README lists what each field is read from.

The /v1 API

The marketplace serves GET-only JSON, open to every origin and cacheable:

| Path | Answer | | ------------------------------------- | --------------------------------------- | | /v1/products | ProductsAnswer | | /v1/items?product=&scope=&kind=&... | ItemsAnswer (filters as in filters) | | /v1/items/<publisher>/<slug> | ItemAnswer (?version= for an older) | | /files/<id>/<version>/<file> | A file the listing or the page names |

The item filters are scope, installWay, kind, category, contains and q. Three keys come from the caller, not from a person: product (the app's bundle id), packages=false (it lists no packages; see the in-app plugin) and starters=true (a marketplace's own pages: the list then includes starters).

Errors are { "error": { "code": "NOT_FOUND" | "BAD_REQUEST", "message" } } with 404 or 400.

import { createCatalogClient } from '@bitakit/marketplace';

const marketplace = createCatalogClient({ url: 'https://marketplace.bitakit.app' });
const { items } = await marketplace.items({ product: 'knightcms', category: ['email'] });
const item = await marketplace.item('knightcms/shop-returns');
const bytes = await marketplace.artifact(item.listing); // checked against its sha256

The client never sends cookies; a failed answer is a CatalogRequestError (status, code).

Shared UI

@bitakit/marketplace/ui renders the marketplace with the app's theme (@bitakit/ui/components): ItemBrowser, FeaturedItems, SearchField, ItemGrid, ItemCard, ItemDetail, ItemTypeBadge, TrustBadge, ProductCard, Filters, Gallery, ItemIcon, ItemCover, MarkdownText and fileUrl. Every prop is plain data (but ItemDetail's install), so a server page can render them; basePath prefixes item links and filesBase is where files load from ('' on the marketplace itself, its address in an app). @bitakit/marketplace/filters holds the nuqs parsers of the filter URLs.

  • ItemBrowser: the filters beside the cards, search and count above them. While nothing narrows the list, the featured items lead it as large banners (FeaturedItems).
  • ItemDetail: laid out like an app store's item page. The head holds the icon, the title with the publisher's trust and one Install control at its right edge; a row of key facts follows (type, kind, version, product and range, contents, publisher), then the videos and pictures as a sideways row (Gallery), the README, contents, requirements, a package's permissions (each resource with what it adds and checks) and an Information section (categories, documentation, versions, file and checksum or npm package). Product ranges read as versions (>=0.1.0 <1.0.0 is 0.1.0 – 0.x); with listHref its categories link to that list, filtered.

Install is the main action of every item, a split button whose menu holds the other ways to get it:

| Item | Install | Its menu | | ------------------------ | -------------------------------------------------------- | --------------------------------- | | Package | A dialog: npm command, grant its permissions, build | Copy install command, View on npm | | Package that fills parts | The same dialog, with the command that chooses it | Copy install command, View on npm | | Instant, install given | The app's own control (an app serving the operations) | Download file (download) | | Instant, no install | A dialog: install it from the product's Marketplace page | Download file (download) | | Starter | A dialog: the command that creates the app, what follows | Copy create command, the archive |

A package that fills replaceable parts (a shell, a sign-in style, a set) gets one more step in its dialog, between installing and building: chooseCommand(item), for example npx bitakit shell use @acme/studio --all. Its Uninstall dialog adds removing the package's entries from choose in bitakit.config.ts.

The split button is ButtonGroup from @bitakit/ui/components (0.3.4). Apps discover styles.css (the typography of READMEs) automatically; a host that renders the components without the plugin imports @bitakit/marketplace/styles.css.

In-app plugin

Installing the package adds the plugin marketplace to an app:

  • pages /marketplace and /marketplace/<publisher>/<slug>;
  • marketplace.open (Shop5 icon, no placement of its own: the host places it; its badge counts the items with an update), marketplace.install and marketplace.uninstall;
  • the client service marketplace.browse, and on the server marketplace.catalog and marketplace.installers;
  • server operations marketplace.items, marketplace.item, marketplace.install and marketplace.uninstall, for members of the active organization.

The app's product is its bitakit.bundle; the list shows that product's items and those for every BitaKit app. Configure the marketplace's address and publish the operations in bitakit.config.ts:

export default defineBitaKit({
  configOverrides: { marketplace: { catalog: { url: 'https://marketplace.bitakit.app' } } },
  server: { publish: ['marketplace.*'] },
});

With the operations published, the page shows this organization's install state and Install installs (or reads Installed, or Update to the newer version); Uninstall in its menu removes the item again. Without them it is browse-only: it reads the public API from the browser, and Install explains the steps; the file is in its menu.

The app's packages are recognized in both modes: the page matches its runtime inventory against the items' npm packages, so a package reads Installed or Update to the newer version, and its Uninstall shows the steps to remove it. A Status filter beside the list narrows it to installed items or those with an update.

Packages need a build, so an app whose people cannot build it, such as a shared cloud, leaves them out of its lists with configOverrides: { marketplace: { catalog: { packages: false } } }. Their pages still open by address and say how to install them. By default (true) lists show packages with their npm command.

Wherever the host places marketplace.open (a navigation slot, a toolbar, a menu), it shows how many items have an update as a badge, for example "Marketplace 2", with "2 updates available" as its hint. Once the app starts, the plugin loads the list one time and counts packages with a newer version and, with the operations published, Instant items with an update. It counts again after an install or uninstall and when the signed-in person or the active organization changes. catalog: { updates: false } turns the count and the badge off. The badge needs @bitakit/core 0.3.7 and a renderer that shows Action badges: Shell 0.3.3 or @bitakit/ui 0.3.4 components.

Installers

The plugin installs nothing itself. The plugin that owns a format adds one file per kind:

// src/plugins/templates/server/contributions/marketplace-installers/template.ts
import { defineMarketplaceInstaller } from '@bitakit/marketplace';

export default defineMarketplaceInstaller({
  kind: 'knightcms.template',
  // [{ id, version }] this organization has: drives "installed" and "update"
  installed: ({ ctx, services }) => services.templates.fromMarketplace(ctx.organization.id),
  // only for items not installed yet; leave it out for "installable"
  check: (listing, { services }) =>
    services.mail.ready() ? undefined : { state: 'needs', reasons: ['A mail sender'] },
  // file: the artifact's bytes, already checked against the listing's sha256
  install: async ({ listing, file }, { ctx, services }) => {
    const template = await services.templates.import(file!, ctx);
    return { href: `/templates/${template.id}`, message: `${listing.title} is installed.` };
  },
  // optional: removes an item `installed` lists, also one the catalog no longer lists
  uninstall: async ({ id }, { ctx, services }) => {
    await services.templates.removeFromMarketplace(id, ctx);
    return { message: 'The template is removed.' };
  },
});

An item whose kind has no installer shows as unavailable. A package (build kind) is unavailable to installers too; cards and pages show its type and npm command instead of that state. The operations only require a member of the active organization: install and uninstall check the person's own permission.

Source responsibilities

| File | Owns | | ---------------------------- | ---------------------------------------------------------------- | | src/ids.ts | Id, version, range and path shapes | | src/kind.ts | Kinds, their status and BitaKit's own kinds | | src/install-ways.ts | Install ways, the item types people see, a starter's command | | src/starter.ts | What a starter archive may hold (starterCheck) | | src/product.ts | Product profiles | | src/listing.ts | Listings and artifacts | | src/page.ts | An item's page: the fields a listing and a page record share | | src/listing-permissions.ts | A package's permissions, read from its build | | src/listing-contains.ts | The parts a package fills, read from its build; chooseCommand | | src/curation.ts | Categories, item records, suggestions, kind decisions | | src/catalog.ts | checkCatalog: references between records, the resolved catalog | | src/catalog-views.ts | Lists, facets and item pages from a resolved catalog | | src/api.ts | The /v1 paths, answers and client | | src/filters.ts | The filter URL parsers (nuqs) | | src/installed.ts | The app's packages and the Installed / Update list | | src/range-text.ts | Version ranges in words for the item page | | src/installer.ts | The installer contract and its contribution kind | | src/index.ts | Public exports and jsonSchemas() | | src/configs/catalog.ts | The address, whether lists show packages, the update count | | src/services/browse.ts | The page's data and the update count, from either source | | src/ui/providers/ | Starts the update count with the app's packages | | src/actions/ | marketplace.open, .install and .uninstall | | src/server/ | Catalog client, installers registry, the four operations | | src/ui/components/ | The shared UI (@bitakit/marketplace/ui) | | src/ui/pages/ | The in-app pages | | discovery.mjs | The marketplace.installers contribution kind |

See AGENTS.md for the rules.

Permissions

It adds and checks no permissions.

Information

Publisher
bitakit · Official
Type
PackageNeeds installation: add it to the app's code and build the app.
Kind
Plugin
Works with
Every BitaKit app
Versions
0.3.60.3.4
Marketplace · BitaKit Marketplace