# Build a phone app for Osogbo Life

You are building a small app for Osogbo Life (https://osogbolife.app), a life-simulation game set in Osogbo, Nigeria. Every player carries a phone with an app store on it. Build one app for that store, in this folder.

Ask me what the app should do if I have not said; if you cannot ask, build the first of these. Good first apps are small: a price list, a tip jar, a quiz, a countdown, a notebook.

THE FRAME. Your app is ONE HTML file, at most 200,000 characters (counted as JavaScript counts them, the file's length as a string), with its CSS in <style> and its JavaScript in <script>. It runs inside the player's phone in a locked frame:
- No network at all: no fetch, XMLHttpRequest, WebSocket, no scripts, stylesheets, fonts or images from any address. Pictures go in as data: URLs; the device's own fonts and emoji are fine, though emoji look different from phone to phone.
- No cookies, no localStorage or sessionStorage, no forms that submit (an <input> or a <button> outside a <form> is fine), no new windows, and it cannot move the page. It cannot send anything out. The only way to reach the game is the bridge below.
- Design for a screen about 360 px wide and 416 px tall. That is your app's own area: a strip above it always shows its name and its developer. Taller content scrolls.
- Plain HTML, CSS and JavaScript only. No framework, no build step, no modules, no imports.

THE BRIDGE. The phone adds a global object, ibadan, before your code runs. Every call returns a promise; a refusal rejects it with an Error whose message you can show the player. Use only these calls. There are no others.
- ibadan.player() resolves with { name, area }: the player's username and the short name of the area they are in (for example "bodija"). The phone asks the player once; if they say no, it rejects.
- ibadan.charge(amount, note) asks the player to pay you a whole number from 1 to ₳5,000. The game's money is Ẹyọ, written ₳: show prices as ₳50, ₳1,500. The phone shows its own sheet with your app's name, the amount and your note (at most 80 characters) every time: that sheet is the confirmation, so do not add one of your own. It resolves with nothing once paid, and rejects if they decline or cannot pay. A player can be charged at most ₳20,000 a day by one app. A charge is yours in full. (You may also set a price for installing the app when you publish it; you keep 70% of that.)
- ibadan.storage.get(key) resolves with a string or null. ibadan.storage.set(key, value) saves a string for this player: keys up to 40 characters, values up to 2,000, 20 keys per player. Past a limit, set rejects with a message.
- ibadan.toast(text) shows a short message over your app for 3 seconds (120 characters). It is a call like the others, so for an error it is safer to write the message into the page.
- ibadan.close() closes your app.
Three more, each behind its own switch in the city and the player's yes (while a switch is off the call rejects with a message saying so; show it):
- ibadan.shared.list(collection, { limit, before }) resolves with [{ id, by, data, at, mine }], newest first, 1 to 50 rows (20 when you give no limit): a board every player of your app shares. ibadan.shared.put(collection, data) adds a row and resolves with { id }; data is plain JSON of at most 2,000 characters, 100 rows per player. ibadan.shared.update(id, data) and ibadan.shared.remove(id) change or delete only the player's own rows. ibadan.shared.report(id) reports a row and resolves with { reported }; enough reports hide it. A collection name is 1 to 40 of a-z, 0-9, _ or -.
- ibadan.here(place) resolves with { here, place }: whether the player is at that place in the game right now (within about 60 m, by the game's own reading), and its name. Only yes or no: you are never told where the player is.
- ibadan.mine.homes() resolves with { owned, renting }: the player's own homes and the home they rent. ibadan.mine.sales() resolves with { business, rows: [{ at, kind, amount }] }: their business and its sales. Read only.
At most 20 calls in any 10 seconds. When you publish you tick what the app needs, from three boxes: the player's name and area (for player), asking to pay (for charge), keeping data (for storage, reading as well as writing). A call whose box is not ticked is refused, so tell me which to tick. The app's name, its one-line description and its icon are typed in when publishing; they are not in the file.

WHAT GETS AN APP TURNED DOWN OR TAKEN DOWN. Pretending to be the game. Asking for a password. Hiding what a payment is for. Heavy work in the background. 3 reports from different players hide an app until staff have looked.

A WORKING EXAMPLE, to copy the shape of:
```html
<!doctype html>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>body{font:16px system-ui;margin:16px;color:#f3e9d7;background:#1b2430}button{font:inherit;padding:10px 14px;border-radius:12px;border:0;background:#9fe0b8}</style>
<h2 id="hi">Hello</h2>
<button id="buy">Buy pure water (50)</button>
<script>
  ibadan.player().then(function (p) { document.getElementById("hi").textContent = "Hello " + p.name + " in " + p.area; }).catch(function () {});
  document.getElementById("buy").onclick = function () {
    ibadan.charge(50, "Pure water").then(function () { ibadan.toast("Paid. Cold one coming."); }).catch(function (e) { ibadan.toast(e.message); });
  };
</script>
```

WHAT TO WRITE. Two files (the second writes a third when it runs):
1. app.html: the app. Handle every rejected promise: show the message, never leave a blank screen.
2. check.mjs: exactly the script below. Then run "node check.mjs" and fix app.html until its line starts with "ok:". It looks for these words anywhere in the file, comments and visible text included, so keep them out: fetch, XMLHttpRequest, WebSocket, EventSource, sendBeacon, importScripts, localStorage, sessionStorage, indexedDB, document.cookie. If you cannot open a browser, say so: "ok:" means the file may be submitted, not that you saw it run. It also writes harness.html, which runs the app in a frame like the phone's, with a stand-in for the bridge; open that in a browser to try it.

```js
// check.mjs: run with  node check.mjs  beside app.html. It prints what the store would turn down, and writes
// harness.html: your app in the same kind of locked frame, with a stand-in for the phone's bridge. Open it in a browser.
import { readFileSync, writeFileSync } from "node:fs";
const src = readFileSync("app.html", "utf8"), bad = [];
if (src.length > 200000) bad.push("over 200000 characters: " + src.length);
if (/<script[^>]+\bsrc\s*=/i.test(src)) bad.push("a script loaded from another file");
if (/<link[^>]+\bhref\s*=\s*["']?(?!data:)/i.test(src)) bad.push("a linked stylesheet or font");
if (/\b(?:src|href|poster)\s*=\s*["']?\s*(?:https?:)?\/\//i.test(src) || /url\(\s*["']?\s*(?:https?:)?\/\//i.test(src)) bad.push("something loaded from another address");
if (/\b(?:fetch|XMLHttpRequest|WebSocket|EventSource|sendBeacon|importScripts)\b/.test(src)) bad.push("a network call");
if (/\b(?:localStorage|sessionStorage|indexedDB|document\.cookie)\b/.test(src)) bad.push("the browser's own storage");
if (/<form\b/i.test(src)) bad.push("a <form>");
console.log(bad.length ? "WOULD BE TURNED DOWN: " + bad.join("; ") : "ok: " + src.length + " characters, one file, no network");
const MOCK = '<script>(function(){var kv={},ok=function(v){return new Promise(function(y){setTimeout(function(){y(v)},60)})};window.ibadan={player:function(){return ok({name:"ade",area:"bodija"})},charge:function(a,n){return confirm("Pay "+a+" for "+n+"?")?ok():Promise.reject(new Error("The player said no."))},storage:{get:function(k){return ok(k in kv?kv[k]:null)},set:function(k,v){kv[k]=String(v);return ok()}},toast:function(t){console.log("toast:",t);return ok()},close:function(){console.log("close");return ok()},shared:{list:function(c,o){var r=(window.__sh||[]).filter(function(x){return x.c===c}).reverse();return ok(r.slice(0,(o&&o.limit)||20).map(function(x){return {id:x.id,by:"ade",data:x.data,at:x.at,mine:true}}))},put:function(c,d){var r=window.__sh=window.__sh||[],id=r.length+1;r.push({id:id,c:c,data:d,at:new Date().toISOString()});return ok({id:id})},update:function(i,d){(window.__sh||[]).forEach(function(x){if(x.id===i)x.data=d});return ok()},remove:function(i){window.__sh=(window.__sh||[]).filter(function(x){return x.id!==i});return ok()},report:function(){return ok({reported:true})}},here:function(p){return ok({here:true,place:String(p)})},mine:{homes:function(){return ok({owned:[],renting:null})},sales:function(){return ok({business:null,rows:[]})}}};})();<\/script>';
const policy = "default-src 'none'; script-src 'unsafe-inline'; style-src 'unsafe-inline'; img-src data:; font-src data:; media-src data:; connect-src 'none'; form-action 'none'";
const page = '<meta http-equiv="Content-Security-Policy" content="' + policy + '">' + MOCK + src;
// The real frame is sandbox="allow-scripts" only. allow-modals is added HERE alone, for a stand-in that asks a question with confirm().
writeFileSync("harness.html", '<!doctype html><title>harness</title><body style="margin:0;background:#222;display:grid;place-items:center;height:100vh"><iframe sandbox="allow-scripts allow-modals" style="width:360px;height:416px;border:0;border-radius:16px;background:#fff" srcdoc="' + page.replace(/&/g, "&amp;").replace(/"/g, "&quot;") + '"></iframe>');
process.exit(bad.length ? 1 : 0);
```

HOW IT IS SUBMITTED. In Osogbo Life, take the App developer job (it needs a laptop), open the phone's store, go to its second tab (Play Console on Android, Developer on an iPhone), choose "Upload code", paste app.html and tick what it needs. The first 3 apps are free to publish; after that each costs ₳20,000. Only app.html is submitted. Staff read and try every app before it is listed. The full guide is at https://osogbolife.app/developers.

When you finish, tell me: what the app does, which boxes to tick, and what check.mjs printed.
