Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
72083b6
feat: let a seller set where an order can ship and what shipping costs
JasonYv Oct 31, 2026
b03ddec
feat: hold every payment to its order, and settle lapsed and oversold…
JasonYv Oct 31, 2026
296f644
feat: ask Stripe for what checkout needs, at a version this code was …
JasonYv Oct 31, 2026
451e457
feat: write the buyer's four emails and the seller's three notices
JasonYv Oct 31, 2026
89d6229
feat: check a cart out and pay for it with Stripe, and run an order a…
JasonYv Oct 31, 2026
d511886
feat: ship the sample to four zones, and see checkout in the shop smo…
JasonYv Oct 31, 2026
6149a83
fix: never cancel or take what was paid elsewhere, and guard checkout…
JasonYv Oct 31, 2026
830d8ed
docs: record checkout as built, the owner's decisions, and what the r…
JasonYv Oct 31, 2026
7ed4e49
feat: show the seller their customers and what sells
JasonYv Oct 31, 2026
aa04026
feat: let a buyer find every order they placed, with no account to make
JasonYv Oct 31, 2026
05c23a0
feat: offer the sample shop in Mallok's first-run wizard
JasonYv Oct 31, 2026
fad5ae9
feat: add a second theme that draws the same shop the opposite way
JasonYv Oct 31, 2026
e5a1cfd
fix: send an order link only to an address a payment was made from
JasonYv Oct 31, 2026
152294f
docs: record phase 3 as built, its parity with the old README, and th…
JasonYv Oct 31, 2026
b87aff5
fix: count an oversold order's payment in the month's sales, and once
JasonYv Oct 31, 2026
2f5a5ca
test: expect the shop's sixth migration among those Mallok applied
JasonYv Oct 31, 2026
abd381b
fix: fold an address's case one way only when finding its orders
JasonYv Oct 31, 2026
6666406
fix: answer a request for an order link in the same time, bought or not
JasonYv Oct 31, 2026
1c79b58
fix: keep what a request for an order link reads to the address it names
JasonYv Oct 31, 2026
f683256
fix: delete every expired request for an order link, not fifty an hour
JasonYv Oct 31, 2026
cf25b24
fix: draw the editorial theme whole on a site that filled in little
JasonYv Oct 31, 2026
439bb70
test: draw an order's page in every status it can be in
JasonYv Oct 31, 2026
383fc62
test: hold the lookup's limits under two requests at once, and the st…
JasonYv Oct 31, 2026
84ef9d1
fix: give a customer the country their orders ship to, not where they…
JasonYv Oct 31, 2026
6bb1f3a
docs: record what the phase 3 reviews found, and what the lookup cost…
JasonYv Oct 31, 2026
07463e1
feat: redraw the editorial theme as an engineering bulletin with pict…
JasonYv Oct 31, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,8 @@ jobs:
# The one command a newcomer runs first still ends with a filled shop
# and an admin login that works
- run: npm run preview -- --check

# The same shop drawn by the second theme, through the Mallok CLI's
# publish and a real Worker, as `npm test` cannot: tests render pages
# inside workerd, and only this publishes the sample with its pictures
- run: npm run preview -- --theme editorial --check
46 changes: 34 additions & 12 deletions CLAUDE.md

Large diffs are not rendered by default.

63 changes: 53 additions & 10 deletions README.md

Large diffs are not rendered by default.

63 changes: 53 additions & 10 deletions README.zh-CN.md

Large diffs are not rendered by default.

190 changes: 128 additions & 62 deletions SECURITY.md

Large diffs are not rendered by default.

149 changes: 149 additions & 0 deletions docs/superpowers/specs/2026-09-30-nundar-on-mallok-design.md

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"test:project": "node --experimental-strip-types --test \"test/*.test.ts\"",
"test:shop": "vitest run",
"seed:local": "wrangler d1 execute DB --local --file=seed/shop-sample.sql",
"smoke:shop": "node scripts/smoke-shop.mjs"
"smoke:shop": "node scripts/smoke-shop.mjs",
"starter:documents": "node scripts/starter-documents.mjs"
},
"dependencies": {
"mallok": "0.1.0-rc.11",
Expand Down
7 changes: 5 additions & 2 deletions scripts/lib/local-shop.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,14 @@ export function portInUse(port) {

/**
* Starts `wrangler dev` on `port`, keeping its database, its files and its
* cache under `state`.
* cache under `state`. `main` is the Worker to run, when it is not the one
* `wrangler.jsonc` names — `src/worker/editorial.ts`, the same site with the
* second theme.
*
* `ready` resolves once the Worker answers. `stopped` resolves if it exits on
* its own. `stop` ends it and everything it started.
*/
export function startWorker({ port, state }) {
export function startWorker({ port, state, main }) {
const processGroup = process.platform !== 'win32';
const base = `http://127.0.0.1:${port}`;

Expand All @@ -78,6 +80,7 @@ export function startWorker({ port, state }) {
[
wrangler,
'dev',
...(main === undefined ? [] : [main]),
'--local',
'--port',
String(port),
Expand Down
21 changes: 19 additions & 2 deletions scripts/preview.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
*
* npm run preview on port 8799
* npm run preview -- --port 8800 on another port
* npm run preview -- --theme editorial
* the same shop, drawn by the second
* theme (src/theme-editorial)
* npm run preview -- --check bring it up, check it, take it down
*
* It brings the shop up through the same code as `npm run smoke:shop`, which
Expand All @@ -39,9 +42,21 @@ import {
const { values } = parseArgs({
options: {
port: { type: 'string' },
theme: { type: 'string', default: 'nundar' },
check: { type: 'boolean', default: false },
},
});
/** The Worker each theme is built into: one site, two ways of drawing it. */
const WORKERS = {
nundar: undefined,
editorial: 'src/worker/editorial.ts',
};
if (!Object.hasOwn(WORKERS, values.theme)) {
process.stderr.write(
`preview: there is no theme "${values.theme}". Use ${Object.keys(WORKERS).join(' or ')}.\n`,
);
process.exit(1);
}
// A person wants an address they can come back to; a check wants whatever
// port is free, so that it can run beside a preview someone has open.
const port =
Expand All @@ -64,7 +79,7 @@ if (await portInUse(port)) {

const say = (line) => process.stdout.write(`${line}\n`);
const state = await mkdtemp(join(tmpdir(), 'nundar-preview-'));
const worker = startWorker({ port, state });
const worker = startWorker({ port, state, main: WORKERS[values.theme] });
const { base } = worker;

let stopping = false;
Expand Down Expand Up @@ -105,8 +120,10 @@ async function check(login) {
home.html.includes(escaped(site.themeOptions.hero_title)),
'the home page does not carry the headline in site.json',
);
// Asked of the links, not of one theme's table, so that either theme
// passes for the same catalogue.
expect(
(home.html.match(/<tr role="row">/g) ?? []).length > 1,
new Set(home.html.match(/href="\/products\/[^"]+"/g) ?? []).size > 1,
'the home page lists no products',
);
for (const locale of site.locales) {
Expand Down
113 changes: 109 additions & 4 deletions scripts/smoke-shop.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
* 3. load the sample variants from `seed/shop-sample.sql`;
* 4. request every kind of page, follow the navigation in every language,
* and fetch the theme's own files;
* 5. add to the cart with the form a product page offers, and read the
* cart page it leads to;
* 6. add a variant the way the admin's form does, and delete it.
* 5. add to the cart with the form a product page offers, read the cart
* page it leads to, and go on to checkout, which quotes shipping and,
* with no Stripe keys set, takes no payment;
* 6. add a variant the way the admin's form does, and delete it;
* 7. send the cart as a request for a quote;
* 8. export the site, and find the shop's data in it.
*
* It exists because the unit tests, thorough as they are, run each piece in
* isolation. This is the one place the theme, the plugin, the content and the
Expand Down Expand Up @@ -592,6 +595,86 @@ try {
'the German cart page does not show the same cart in German and in euros',
);

// 5b. Checkout, the way the cart page leads to it. The run sets no Stripe
// keys, so the shop takes no payment: the cart offers no checkout, the
// checkout page says so and places nothing, and Stripe's deliveries
// are turned away for Stripe to deliver again.
expect(
!germanCart.includes('/_mallok/p/shop/de/checkout'),
'the cart page offers checkout though the shop cannot take a payment',
);
const checkoutPage = await fetch(
`${base}/_mallok/p/shop/de/checkout?country=DE`,
{ headers: { cookie: cartCookie }, signal: timeout() },
);
const checkout = await checkoutPage.text();
expect(
checkoutPage.status === 200 &&
checkout.includes('<h1 class="detail-title">Kasse</h1>') &&
/<option value="DE" selected>Deutschland<\/option>/.test(checkout) &&
/Versand · Europe<\/dt><dd><span class="price">25,00\s€<\/span>/.test(
checkout,
) &&
/class="checkout-total"><dt>Gesamt<\/dt><dd><span class="price">235,00\s€<\/span>/.test(
checkout,
) &&
checkout.includes('Online-Zahlung ist derzeit nicht verfügbar.') &&
!checkout.includes('name="recipient"') &&
!/<script\b/.test(checkout),
`the German checkout page does not quote shipping to Germany, or offers a payment it cannot take (${checkoutPage.status})`,
);
const placeAttempt = await fetch(`${base}/_mallok/p/shop/de/checkout/place`, {
method: 'POST',
headers: {
'content-type': 'application/x-www-form-urlencoded',
origin: base,
cookie: cartCookie,
},
body: new URLSearchParams({
email: 'buyer@smoke.example',
company: 'Smoke GmbH',
recipient: 'Smoke Buyer',
line1: 'Hafenstraße 1',
city: 'Hamburg',
country: 'DE',
}).toString(),
redirect: 'manual',
signal: timeout(),
});
expect(
placeAttempt.status === 303 &&
placeAttempt.headers.get('location') ===
'/_mallok/p/shop/de/checkout?checkout=payments_unavailable&country=DE',
`placing an order without Stripe's keys returned ${placeAttempt.status} to ${placeAttempt.headers.get('location')}`,
);
const unpaid = await query('SELECT COUNT(*) AS n FROM p_shop_order');
expect(
unpaid[0].n === 0,
'an order was placed though no payment can be taken',
);
const delivery = await fetch(`${base}/_mallok/p/shop/stripe/webhook`, {
method: 'POST',
headers: {
'content-type': 'application/json',
'stripe-signature': 't=1,v1=00',
},
body: '{}',
signal: timeout(),
});
expect(
delivery.status === 503,
`a delivery from Stripe before its signing secret is set returned ${delivery.status}`,
);
const noOrder = await fetch(
`${base}/_mallok/p/shop/order/ND-261031-AAAAAAAA?k=${'A'.repeat(43)}`,
{ signal: timeout() },
);
expect(
noOrder.status === 404 &&
(await noOrder.text()).includes('This order cannot be shown.'),
`a link that opens no order returned ${noOrder.status}`,
);

// The header's way to the cart is on a public page, the same for everyone.
expect(
/<a class="cart-link" href="\/_mallok\/p\/shop\/cart">/.test(home.html),
Expand Down Expand Up @@ -668,6 +751,28 @@ try {
`deleting the variant returned ${removed.status} and left ${left[0].n} behind`,
);

// The admin's lists of what checkout keeps: the sample's shipping zones,
// and orders and refused payments, of which there are none.
const shopPanel = async (id) => {
const response = await fetch(
`${base}/_mallok/api/plugins/shop/panels/${id}`,
{ headers: authorised, signal: timeout() },
);
return { status: response.status, rows: (await response.json()).rows };
};
const zones = await shopPanel('shipping');
const orderList = await shopPanel('orders');
const refusedList = await shopPanel('refused-payments');
expect(
zones.status === 200 &&
zones.rows.length === 4 &&
orderList.status === 200 &&
orderList.rows.length === 0 &&
refusedList.status === 200 &&
refusedList.rows.length === 0,
`the admin's shop lists answered ${zones.status} (${zones.rows?.length} zones), ${orderList.status} and ${refusedList.status}`,
);

const lines = await query(
'SELECT variant_id, quantity FROM p_shop_cart_line',
);
Expand Down Expand Up @@ -847,7 +952,7 @@ try {
);

process.stdout.write(
`smoke:shop: ok (settings, publish, seed, every kind of page, ${followed} navigation links in ${site.locales.length} languages, ${shipped.length} theme files, cart, variants in the admin, a cart sent as an inquiry, the shop in the site's export) on ${base}\n`,
`smoke:shop: ok (settings, publish, seed, every kind of page, ${followed} navigation links in ${site.locales.length} languages, ${shipped.length} theme files, cart, checkout with no payment taken, variants in the admin, a cart sent as an inquiry, the shop in the site's export) on ${base}\n`,
);
} catch (error) {
failure = error;
Expand Down
2 changes: 2 additions & 0 deletions scripts/starter-documents.d.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/** The text of `src/starter/documents.generated.ts`, from `content/` now. */
export function renderStarterDocuments(): Promise<string>;
132 changes: 132 additions & 0 deletions scripts/starter-documents.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/**
* Writes `src/starter/documents.generated.ts`: every bundle of `content/`, as
* imports of its Markdown files, for the starter Mallok's first-run wizard
* offers (`src/starter/index.ts`).
*
* node scripts/starter-documents.mjs
*
* Generated rather than written by hand because there are a hundred and more
* files, and a list kept by hand drifts from the directory it lists:
* `test/starter.test.ts` fails when the file is not what this writes.
*
* A bundle is a directory of `content/<kind>/`; `index.md` is the default
* language, whose slug is the directory's name, and `index.<locale>.md` a
* translation, whose slug is in its front matter.
*/

import { readdir, readFile, writeFile } from 'node:fs/promises';
import { join } from 'node:path';
import { fileURLToPath } from 'node:url';

const ROOT = fileURLToPath(new URL('..', import.meta.url));
const CONTENT = join(ROOT, 'content');
const OUTPUT = join(ROOT, 'src', 'starter', 'documents.generated.ts');

/** The value of a top-level key in a file's front matter, or null. */
function frontMatterValue(text, key) {
const end = text.indexOf('\n---', 3);
const head = text.startsWith('---') && end !== -1 ? text.slice(0, end) : '';
const line = head
.split('\n')
.find((candidate) => candidate.startsWith(`${key}:`));
if (line === undefined) {
return null;
}
return line
.slice(key.length + 1)
.trim()
.replace(/^"(.*)"$/, '$1');
}

/** The module's text, from what is in `content/` now. */
export async function renderStarterDocuments() {
const imports = [];
const bundles = [];
for (const kind of (await readdir(CONTENT)).sort()) {
const kindDir = join(CONTENT, kind);
const dirs = (await readdir(kindDir, { withFileTypes: true }))
.filter((entry) => entry.isDirectory())
.map((entry) => entry.name)
.sort();
for (const dir of dirs) {
const files = (await readdir(join(kindDir, dir)))
.filter((name) =>
/^index(\.[a-z]{2}(-[A-Za-z]{2,4})?)?\.md$/.test(name),
)
.sort();
if (!files.includes('index.md')) {
continue;
}
const languages = [];
for (const file of files) {
const name = `d${imports.length}`;
imports.push(
`import ${name} from '../../content/${kind}/${dir}/${file}';`,
);
const locale = /^index\.(.+)\.md$/.exec(file)?.[1] ?? null;
const slug =
locale === null
? dir
: frontMatterValue(
await readFile(join(kindDir, dir, file), 'utf8'),
'slug',
);
if (slug === null) {
throw new Error(`content/${kind}/${dir}/${file} names no slug`);
}
languages.push({ locale, slug, name });
}
bundles.push({ kind, languages });
}
}

const entry = (bundle) => {
const own = bundle.languages.find((language) => language.locale === null);
const translations = bundle.languages.filter(
(language) => language.locale !== null,
);
return [
' {',
` kind: '${bundle.kind}',`,
` slug: '${own.slug}',`,
` markdown: ${own.name},`,
' translations: {',
// Written as Biome formats it, so that the file passes the lint as
// it is generated.
...translations.flatMap((language) => [
` ${/^[a-z]+$/.test(language.locale) ? language.locale : `'${language.locale}'`}: {`,
` slug: '${language.slug}',`,
` markdown: ${language.name},`,
' },',
]),
' },',
' },',
].join('\n');
};

return [
'// Generated by scripts/starter-documents.mjs from content/. Do not edit:',
'// run `node scripts/starter-documents.mjs` after changing content/.',
'',
...imports,
'',
'export interface SampleBundle {',
' readonly kind: string;',
' readonly slug: string;',
' readonly markdown: string;',
' readonly translations: Readonly<',
' Record<string, { readonly slug: string; readonly markdown: string }>',
' >;',
'}',
'',
'export const SAMPLE_BUNDLES: readonly SampleBundle[] = [',
...bundles.map(entry),
'];',
'',
].join('\n');
}

if (process.argv[1] === fileURLToPath(import.meta.url)) {
await writeFile(OUTPUT, await renderStarterDocuments());
console.log(`Wrote ${OUTPUT}`);
}
Loading
Loading