Developers

Build a Block

Blocks are interactive simulators that creators build lessons out of: a chess board for tactics, a market replay for trade decisions, a quiz. Creators set up a scenario in your block's editor without writing code; their learners practice in it and YooB tracks progress.

A block is a small static web app: HTML, CSS and JavaScript (WebAssembly too). YooB serves each version from a separate origin and runs it in a sandboxed iframe, so it can't touch the YooB page, its cookies, or the network. Everything a block needs (the creator's scenario, the learner's saved state, scores, data feeds) comes through the Blocks SDK.

Quick start

The kit has the yoob-blocks CLI (Node 18+, no dependencies), the SDK, and a local copy of the YooB host. dev runs your block exactly the way YooB will: on a separate origin, in the same sandbox, with the production security policy. Switch between editor, preview and player modes, light and dark, and desktop or mobile widths from its toolbar.

# Download and unzip the kit, then:
node yoob-blocks/cli/yoob-blocks.mjs init poker-trainer
node yoob-blocks/cli/yoob-blocks.mjs dev poker-trainer        # http://localhost:4400
node yoob-blocks/cli/yoob-blocks.mjs validate poker-trainer
node yoob-blocks/cli/yoob-blocks.mjs publish poker-trainer --key yoob_sk_… --submit

publish needs an API key from Developers in the studio. You can also upload a folder from the block's page under Blocks.

The sandbox

Every block runs in <iframe sandbox="allow-scripts allow-forms"> on the blocks origin, and every file in your bundle is served with a strict Content Security Policy. In practice:

  • No network. Scripts, styles, images, fonts and fetch() only work for files in your own bundle (use relative URLs) plus /sdk/. CDNs, analytics and outside APIs are blocked, so bundle every dependency.
  • No inline scripts, onclick= attributes, eval or new Function. Put code in .js files. Inline styles are fine.
  • No cookies, localStorage, sessionStorage or IndexedDB. The frame has an opaque origin. Use YoobBlock.saveState().
  • No popups, alerts, new tabs or navigating the page. Build your own dialogs.
  • Forms work but never submit. Listen for submit and call preventDefault().
  • No camera, microphone, location, payments or other device APIs.

ES modules, Web Workers from your bundle, WebAssembly, canvas and WebGL all work. Blocks never see who the learner is: learner.id is an opaque id, stable per learner per block, with no name or email.

Bundle and manifest

A bundle is a folder with yoob-block.json at the top. Every upload is a new, immutable version, and lessons pin the version they were built with.

{
  "manifestVersion": 1,
  "slug": "poker-trainer",
  "name": "Poker Trainer",
  "version": "1.0.0",
  "tagline": "Drill preflop ranges and postflop spots.",
  "description": "Longer text for the Blocks directory.",
  "category": "games",
  "icon": "icon.svg",
  "entry": { "player": "player.html", "editor": "editor.html" },
  "capabilities": ["state", "progress"],
  "display": { "height": 600, "minHeight": 420 },
  "defaultConfig": "default-config.json"
}
FieldNotes
slug
3–40 lowercase letters, digits and dashes. Unique across YooB; your first upload claims it.
version
Like 1.2.0. Each upload needs a higher version.
entry.player
The page learners see. Required.
entry.editor
The page creators use to build a scenario. Without one, every lesson using your block is the same.
capabilities
state: Save each learner's progress so they can pick up where they left off.progress: Report scores and mark the lesson complete.data:market: Read historical market bars (stocks, ETFs, crypto) from YooB's licensed data feed.
display.height
Frame height in a lesson, 240–2000px (default 560). Change it at runtime with YoobBlock.resize().
defaultConfig
A sample scenario. Used for "Try it" in the directory and as the starting point for new lessons.
category
finance, games, quizzes, coding, language, music, science, business, health, creative, other
icon
48×48 .svg, .png or .webp for the directory.

Limits: 200 files, 5 MB per file, 10 MB per bundle. Scenarios (config) can be up to 512 KB and learner state up to 64 KB.

SDK reference

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="/sdk/v1.css">
  <script src="/sdk/v1.js"></script>
  <script type="module" src="player.js"></script>
</head>
<body>…</body>
</html>

Context

await YoobBlock.ready() connects to YooB and resolves with the context:

KeyValue
mode
player (a learner in a lesson), editor (a creator building the scenario) or preview (the creator trying it; nothing is saved).
layout
inline inside a lesson at your display height (the frame's viewport is that height), or fill for full screen and the studio editor.
config
The creator's scenario, or null if they haven't built one.
state
This learner's saved state, or null on a first visit. Always null in the editor.
learner
{ id }, opaque and stable per learner per block. null in the editor.
theme
{ scheme, tokens }. The SDK applies the tokens as --yb-* CSS variables and follows light/dark changes.
block
{ id, slug, name, version }
capabilities
What your manifest asked for.

Methods

MethodWhat it does
setConfig(config)
Editor only. The scenario changed (a JSON object). Call it on every change; YooB's Save button stores it with the lesson.
saveState(state)
Any JSON up to 64 KB, persisted for this learner in player mode. Needs state. Save at meaningful moments, not every frame.
reportProgress(p)
{ score, passed, completed, summary }, score from 0 to 1. Creators see scores per learner. Needs progress.
complete(r)
Shorthand for reportProgress({ completed: true, ... }). Marks the lesson complete in YooB; it can't be undone.
resize(height)
Inline layout: ask for a frame height. YooB clamps it.
autoResize()
Keep the frame as tall as your document.
fetchData(feed, params)
Read a platform data feed, e.g. market.bars. Needs the feed's capability.
on(event, fn)
theme when the learner switches light or dark.
const ctx = await YoobBlock.ready();
const scenario = ctx.config;          // what the creator built in your editor
let progress = ctx.state ?? { step: 0 }; // where this learner left off

async function onAnswer(correct) {
  progress.step++;
  await YoobBlock.saveState(progress);
  await YoobBlock.reportProgress({ score: progress.correct / progress.step });
  if (progress.step === scenario.steps.length) {
    await YoobBlock.complete({ score: progress.correct / progress.step, passed: true });
  }
}
const ctx = await YoobBlock.ready();   // ctx.mode === "editor"
const config = ctx.config ?? { steps: [] };

titleInput.addEventListener("input", () => {
  config.title = titleInput.value;
  YoobBlock.setConfig(config);       // YooB's Save button stores it with the lesson
});

Errors

Failed calls reject with an error that has a code: capability_denied, not_allowed_in_mode, invalid_params, too_large, rate_limited, unknown_feed, not_configured, unavailable, timeout or no_host.

Modes and layouts

  • Editor runs full screen in the studio for non-technical creators. Make it a friendly tool, not a JSON form. If config is null, start from your default scenario.
  • Player runs inline in a lesson (about 480–700 px tall, from phone to desktop width) or full screen. Design for both; the data-yb-layout attribute on <html> lets your CSS adapt.
  • Preview should behave exactly like player. YooB just doesn't keep anything.

Handle a null config in player mode with a friendly empty state, and treat config and state defensively: an older lesson may hand a newer version of your block an older scenario.

Data feeds

Blocks can't reach the internet, so YooB provides licensed data through the SDK. YooB fetches and caches it, and learners never talk to the provider.

const res = await YoobBlock.fetchData("market.bars", {
  symbol: "AAPL", interval: "1d", from: "2024-01-02", to: "2024-06-28",
});
// { symbol, interval, from, to, source, attribution,
//   bars: [{ t, o, h, l, c, v }] }        t = bar open time, Unix ms (UTC)

market.bars needs the data:market capability. interval is 1m, 5m, 15m, 1h, 1d or 1w, with up to 5,000 bars per request and no future dates. Show attribution near the chart. If historical data isn't enabled on this YooB, the call fails with not_configured, so offer another source (simulated data, or bars the creator pastes in). The dev harness returns synthetic bars.

Style kit

/sdk/v1.css is optional and gives your block YooB's look in light and dark. Colors are CSS variables: --yb-canvas, --yb-surface, --yb-fg, --yb-muted, --yb-line, --yb-brand, --yb-accent (the creator's page color), --yb-success, --yb-danger and more. Classes include yb-btn (with -primary, -ghost, -sm), yb-input, yb-select, yb-card, yb-badge, yb-callout, yb-segmented and yb-progress. The kit's README lists them all.

Review and publishing

  1. Upload. The bundle is validated (manifest, file types, sizes) and scanned. Findings such as outside URLs, inline scripts, or password and card fields are shown to you and to reviewers.
  2. Test. A new version is a draft. Run it from the block's page, or attach it to an unpublished lesson in one of your own products.
  3. Submit. YooB reviews the version: it runs it, reads the source, and checks it against the rules below. You get approved or rejected with notes.
  4. Live. Approved public blocks appear in the directory for every creator. Private blocks stay usable only by you.

Rejected outright: anything that asks for passwords, card details or other credentials; imitates YooB or another brand; deceives learners; or hides what it does (obfuscated code). YooB can disable an approved version at any time, which stops it loading in every lesson immediately.

API

The CLI uses these endpoints. They authenticate with a secret key like the rest of the API.

EndpointWhat it does
GET /blocks
Your blocks. ?directory=true lists every block you can use in lessons.
POST /blocks
Reserve a slug: { slug, name, visibility }.
POST /blocks/versions
Upload a bundle as multipart form data, one part per file named f:<path>. The manifest's slug picks (or creates) the block.
GET /blocks/{id}
A block you own, with every version and its review checks.
PATCH /blocks/{id}
{ visibility }: public or private.
POST /blocks/{id}/versions/{versionId}/submit
Send a draft for review.
POST /content
Create a lesson with type: "block", block_version_id and block_config.
curl https://yoob.app/api/v1/blocks/versions \
  -H "Authorization: Bearer yoob_sk_…" \
  -F "f:[email protected]" \
  -F "f:[email protected]" \
  -F "f:js/player.js=@js/player.js" \
  -F "changelog=First version"