create-pincast 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,12 @@
1
+ {
2
+ "app": "lantern-walk",
3
+ "set": "old-town-lanterns",
4
+ "held": { "lantern": 5 },
5
+ "cards": [
6
+ { "key": "lantern:ferry-steps", "type": "lantern", "parent": null, "via": null, "collectedAt": "2026-10-03T18:12:00.000Z", "lastCollectedAt": "2026-10-03T18:12:00.000Z", "count": 1, "source": "anonymous" },
7
+ { "key": "lantern:chandlers-corner", "type": "lantern", "parent": null, "via": null, "collectedAt": "2026-10-03T18:31:00.000Z", "lastCollectedAt": "2026-10-03T18:31:00.000Z", "count": 1, "source": "anonymous" },
8
+ { "key": "lantern:market-cross", "type": "lantern", "parent": null, "via": null, "collectedAt": "2026-10-03T18:47:00.000Z", "lastCollectedAt": "2026-10-03T18:47:00.000Z", "count": 1, "source": "anonymous" },
9
+ { "key": "lantern:bell-yard", "type": "lantern", "parent": null, "via": null, "collectedAt": "2026-10-10T17:58:00.000Z", "lastCollectedAt": "2026-10-10T17:58:00.000Z", "count": 2, "source": "anonymous" },
10
+ { "key": "lantern:harbor-light", "type": "lantern", "parent": null, "via": null, "collectedAt": "2026-10-10T18:40:00.000Z", "lastCollectedAt": "2026-10-10T18:40:00.000Z", "count": 1, "source": "anonymous" }
11
+ ]
12
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "name": "Old Town",
3
+ "meta": { "face": "lantern", "listed": false },
4
+ "cards": [
5
+ { "key": "lantern:ferry-steps", "type": "lantern", "title": "Ferry Steps", "subtitle": "Harbor Road", "fact": "Lit at dusk since 1889", "rarity": "Common", "url": "https://example.org/lanterns/ferry-steps", "data": { "number": 1, "story": "The first lantern on the walk. Ferry crews trimmed its wick before the evening crossing." } },
6
+ { "key": "lantern:chandlers-corner", "type": "lantern", "title": "Chandler's Corner", "subtitle": "Rope Lane", "fact": "Burned whale oil until 1902", "rarity": "Common", "url": "https://example.org/lanterns/chandlers-corner", "data": { "number": 2, "story": "A candle maker kept this one lit to show his shop was open after dark." } },
7
+ { "key": "lantern:mill-bridge", "type": "lantern", "title": "Mill Bridge", "subtitle": "Weir Street", "fact": "Hangs over the water", "rarity": "Common", "url": "https://example.org/lanterns/mill-bridge", "data": { "number": 3, "story": "Its bracket was forged at the mill, and the river has never once reached it." } },
8
+ { "key": "lantern:market-cross", "type": "lantern", "title": "Market Cross", "subtitle": "Market Square", "fact": "Four panes, one for each road", "rarity": "Uncommon", "url": "https://example.org/lanterns/market-cross", "data": { "number": 4, "story": "Traders met under it to settle the day's accounts." } },
9
+ { "key": "lantern:bell-yard", "type": "lantern", "title": "Bell Yard", "subtitle": "Chapel Row", "fact": "Rings when the wind turns", "rarity": "Uncommon", "url": "https://example.org/lanterns/bell-yard", "data": { "number": 5, "story": "A small brass bell hangs from its frame and sounds in a north wind." } },
10
+ { "key": "lantern:tinkers-arch", "type": "lantern", "title": "Tinker's Arch", "subtitle": "Kettle Passage", "fact": "Patched with eleven metals", "rarity": "Uncommon", "url": "https://example.org/lanterns/tinkers-arch", "data": { "number": 6, "story": "Every repair used whatever the tinker had that week, and you can count them." } },
11
+ { "key": "lantern:harbor-light", "type": "lantern", "title": "Harbor Light", "subtitle": "The Long Quay", "fact": "Seen from two miles out", "rarity": "Rare", "url": "https://example.org/lanterns/harbor-light", "data": { "number": 7, "story": "The tallest on the walk. Boats still steer by it on foggy nights." } },
12
+ { "key": "lantern:the-last-wick", "type": "lantern", "title": "The Last Wick", "subtitle": "Lamplighter's Close", "fact": "Still lit by hand", "rarity": "Rare", "url": "https://example.org/lanterns/the-last-wick", "data": { "number": 8, "story": "The one lantern in town with no gas line. A neighbor lights it every evening." } }
13
+ ]
14
+ }
@@ -0,0 +1,12 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" />
6
+ <title>Lantern Walk</title>
7
+ </head>
8
+ <body>
9
+ <div id="app"></div>
10
+ <script type="module" src="/src/main.js"></script>
11
+ </body>
12
+ </html>
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "pincast-kit-example",
3
+ "version": "1.0.0",
4
+ "private": true,
5
+ "description": "A small app that shows its cards on the Placecard kit's card table. Runs with no account, then goes live with a key.",
6
+ "license": "MIT",
7
+ "type": "module",
8
+ "engines": {
9
+ "node": ">=20.12"
10
+ },
11
+ "scripts": {
12
+ "dev": "vite",
13
+ "build": "vite build",
14
+ "start": "node server/index.js",
15
+ "test": "vitest run"
16
+ },
17
+ "dependencies": {
18
+ "@pincast/placecard-kit": "1.6.0",
19
+ "vue": "^3.5.0"
20
+ },
21
+ "devDependencies": {
22
+ "@electric-sql/pglite": "^0.5.0",
23
+ "@vitejs/plugin-vue": "^5.2.0",
24
+ "jsdom": "^25.0.0",
25
+ "vite": "^5.4.0",
26
+ "vitest": "^2.1.0"
27
+ }
28
+ }
@@ -0,0 +1,23 @@
1
+ import { readFileSync } from 'node:fs'
2
+ import { dirname, join } from 'node:path'
3
+ import { fileURLToPath } from 'node:url'
4
+ import { ttFromAppSet } from '@pincast/placecard-kit/registry'
5
+ import { APP, FACES, RARITIES, SET_ID } from '../shared/app.js'
6
+
7
+ const dataDir = join(dirname(fileURLToPath(import.meta.url)), '..', 'data')
8
+ const readData = file => JSON.parse(readFileSync(join(dataDir, file), 'utf8'))
9
+
10
+ // The API doesn't return a set's cards, so the app keeps the set it sent to PUT /v1/sets/:set.
11
+ export const set = { id: SET_ID, app: APP.id, ...readData('set.json') }
12
+
13
+ // A saved answer of GET /v1/sets/:set/collects, so the app runs with no key.
14
+ export const sampleCollects = { ...readData('sample-collects.json'), app: APP.id, set: SET_ID }
15
+
16
+ // One person's collects (or null when no one is signed in) as the collection the table draws.
17
+ export const toCollection = collects => ttFromAppSet(set, collects, {
18
+ apps: [APP],
19
+ faces: FACES,
20
+ rarities: { [APP.id]: RARITIES },
21
+ // The open card's button. Unset, it reads "Open in Lanterns", which a phone cuts off in a wide font.
22
+ rules: { [APP.id]: { set: () => ({ action: 'Open' }) } },
23
+ })
@@ -0,0 +1,45 @@
1
+ // The production server: the built page from dist, and the one API route.
2
+ import { createReadStream, existsSync, statSync } from 'node:fs'
3
+ import { createServer } from 'node:http'
4
+ import { dirname, extname, join, normalize, sep } from 'node:path'
5
+ import { fileURLToPath } from 'node:url'
6
+ import { collectionRoute } from './route.js'
7
+
8
+ if (existsSync('.env')) process.loadEnvFile('.env')
9
+
10
+ const dist = join(dirname(fileURLToPath(import.meta.url)), '..', 'dist')
11
+ const TYPES = { '.html': 'text/html; charset=utf-8', '.js': 'text/javascript; charset=utf-8', '.css': 'text/css; charset=utf-8', '.svg': 'image/svg+xml', '.png': 'image/png', '.woff2': 'font/woff2', '.map': 'application/json' }
12
+ const route = collectionRoute(process.env)
13
+
14
+ function serveFile(req, res) {
15
+ let path
16
+ try {
17
+ path = normalize(join(dist, decodeURIComponent(new URL(req.url, 'http://local').pathname)))
18
+ } catch {
19
+ res.writeHead(400).end()
20
+ return
21
+ }
22
+ if (path !== dist && !path.startsWith(dist + sep)) {
23
+ res.writeHead(403).end()
24
+ return
25
+ }
26
+ if (!existsSync(path) || !statSync(path).isFile()) path = join(dist, 'index.html')
27
+ if (!existsSync(path)) {
28
+ res.writeHead(500, { 'Content-Type': 'text/plain' }).end('No build yet: run npm run build first.\n')
29
+ return
30
+ }
31
+ res.writeHead(200, { 'Content-Type': TYPES[extname(path)] || 'application/octet-stream' })
32
+ if (req.method === 'HEAD') res.end()
33
+ else createReadStream(path).pipe(res)
34
+ }
35
+
36
+ const server = createServer((req, res) => {
37
+ const { pathname } = new URL(req.url, 'http://local')
38
+ if (pathname === '/api/collection') return route(req, res)
39
+ if (req.method !== 'GET' && req.method !== 'HEAD') return res.writeHead(405, { Allow: 'GET, HEAD' }).end()
40
+ return serveFile(req, res)
41
+ })
42
+
43
+ const port = Number(process.env.PORT) || 4173
44
+ const host = process.env.HOST || '127.0.0.1'
45
+ server.listen(port, host, () => console.log(`Lantern Walk: http://${host}:${port}`))
@@ -0,0 +1,74 @@
1
+ import { APP, SET_ID } from '../shared/app.js'
2
+ import { sampleCollects, toCollection } from './collection.js'
3
+
4
+ const DEFAULT_API = 'https://api.pincast.fm/v1'
5
+ const TIMEOUT_MS = 8000
6
+
7
+ const REFUSED = {
8
+ 401: 'The Pincast API got no key.',
9
+ 403: 'The Pincast API refused this key. Check PINCAST_KEY.',
10
+ 404: `Set ${SET_ID} isn't registered for this app yet. Send it with PUT /v1/sets/${SET_ID} first.`,
11
+ 429: 'Too many calls to the Pincast API. Wait a moment and reload.',
12
+ }
13
+
14
+ // A key reads pck_<app id>_<secret>. The app id is the only part this file ever repeats.
15
+ const keyApp = key => /^pck_([a-z0-9-]{1,32})_/.exec(key)?.[1] ?? null
16
+
17
+ /**
18
+ * What GET /api/collection answers: { status, body, retryAfter? }.
19
+ * With no key it answers from the sample and makes no network call.
20
+ */
21
+ export async function readCollection(env = process.env, fetchImpl = fetch) {
22
+ const key = (env.PINCAST_KEY || '').trim()
23
+ if (!key) return { status: 200, body: { source: 'sample', collection: toCollection(sampleCollects) } }
24
+
25
+ const owner = keyApp(key)
26
+ if (owner !== APP.id) {
27
+ const found = owner ? `This key is for the app ${owner}. ` : "This key doesn't have the shape pck_<app id>_<secret>. "
28
+ return { status: 500, body: { error: `${found}Set APP.id in shared/app.js to your app's id.` } }
29
+ }
30
+
31
+ // In a real app the person comes from your own sign-in session. Never take this id from the browser:
32
+ // anyone could then read anyone's cards through your key.
33
+ const actor = (env.PINCAST_ACTOR || '').trim()
34
+ if (!actor) return { status: 200, body: { source: 'live', signedIn: false, collection: toCollection(null) } }
35
+
36
+ const api = (env.PINCAST_API || DEFAULT_API).replace(/\/+$/, '')
37
+ const url = `${api}/sets/${encodeURIComponent(SET_ID)}/collects?actor=${encodeURIComponent(actor)}`
38
+ let res
39
+ try {
40
+ res = await fetchImpl(url, { headers: { 'X-Pincast-Key': key }, signal: AbortSignal.timeout(TIMEOUT_MS) })
41
+ } catch {
42
+ return { status: 502, body: { error: "Couldn't reach the Pincast API." } }
43
+ }
44
+ if (!res.ok) {
45
+ const error = REFUSED[res.status] || `The Pincast API answered ${res.status}.`
46
+ if (res.status === 429) return { status: 429, retryAfter: res.headers.get('retry-after'), body: { error } }
47
+ return { status: 502, body: { error } }
48
+ }
49
+ let collects
50
+ try {
51
+ collects = await res.json()
52
+ return { status: 200, body: { source: 'live', signedIn: true, collection: toCollection(collects) } }
53
+ } catch {
54
+ return { status: 502, body: { error: 'The Pincast API sent an answer this app could not read.' } }
55
+ }
56
+ }
57
+
58
+ /** The route as Node middleware: Vite mounts it in dev, server/index.js in production. */
59
+ export function collectionRoute(env = process.env, fetchImpl = fetch) {
60
+ return async (req, res) => {
61
+ res.setHeader('Content-Type', 'application/json; charset=utf-8')
62
+ res.setHeader('Cache-Control', 'no-store')
63
+ if (req.method !== 'GET' && req.method !== 'HEAD') {
64
+ res.statusCode = 405
65
+ res.setHeader('Allow', 'GET, HEAD')
66
+ res.end(JSON.stringify({ error: 'Use GET.' }))
67
+ return
68
+ }
69
+ const { status, body, retryAfter } = await readCollection(env, fetchImpl)
70
+ res.statusCode = status
71
+ if (retryAfter) res.setHeader('Retry-After', retryAfter)
72
+ res.end(req.method === 'HEAD' ? undefined : JSON.stringify(body))
73
+ }
74
+ }
@@ -0,0 +1,11 @@
1
+ // Who this app is. To go live, change `id` to the app id in your key.
2
+ export const APP = { id: 'lantern-walk', name: 'Lanterns', color: '#B4532A' }
3
+
4
+ // The set this app shows, as it's named in /v1/sets/:set.
5
+ export const SET_ID = 'old-town-lanterns'
6
+
7
+ // The app's own face: the kit's destination face draws it, under the id `lantern`.
8
+ export const FACES = { lantern: { base: 'destination' } }
9
+
10
+ // The rarity words on this set's cards, low to high.
11
+ export const RARITIES = ['Common', 'Uncommon', 'Rare']
@@ -0,0 +1,19 @@
1
+ <script setup>
2
+ import { computed } from 'vue'
3
+ import { Tabletop, createTabletop } from '@pincast/placecard-kit/vue'
4
+ import { config, signedIn, source } from './tabletop.js'
5
+
6
+ const tabletop = createTabletop(config)
7
+ const note = computed(() => {
8
+ if (tabletop.error.value) return tabletop.error.value.message || String(tabletop.error.value)
9
+ if (source.value === 'sample') return 'Sample cards. Add a key to go live.'
10
+ if (source.value === 'live' && !signedIn.value) return 'Live, with no person set. Add PINCAST_ACTOR to show their cards.'
11
+ if (source.value === 'live') return 'Live from the Pincast API.'
12
+ return 'Loading the cards.'
13
+ })
14
+ </script>
15
+
16
+ <template>
17
+ <p class="lantern-note" :class="{ 'is-error': tabletop.error.value }" role="status">{{ note }}</p>
18
+ <Tabletop :tabletop="tabletop" />
19
+ </template>
@@ -0,0 +1,35 @@
1
+ /* The app's theme: the Card room's tokens, with this app's colors and system type. */
2
+ .tt.lantern-theme {
3
+ --ground: #1b1a22;
4
+ --ground-2: #24222d;
5
+ --surface: #2d2a37;
6
+ --gold: #e8a33d;
7
+ --gold-2: #f3c477;
8
+ --spot: #b4532a;
9
+ --font-display: Georgia, "Times New Roman", serif;
10
+ --font-text: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
11
+ --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
12
+ }
13
+
14
+ /* The app's own face. The kit's destination face draws it, under data-face="lantern". */
15
+ .ttf[data-face="lantern"].ttf-typo .ttf-art {
16
+ background: radial-gradient(circle at 50% 30%, #f6d48f 0, #d98a3a 16%, #7a3d2a 38%, #2a2230 72%);
17
+ }
18
+
19
+ html, body {
20
+ margin: 0;
21
+ background: #1b1a22;
22
+ }
23
+
24
+ .lantern-note {
25
+ margin: 0;
26
+ padding: 8px 16px;
27
+ background: #2d2a37;
28
+ color: #f3c477;
29
+ font: 500 13px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
30
+ }
31
+
32
+ .lantern-note.is-error {
33
+ background: #5a1f1f;
34
+ color: #ffd9d4;
35
+ }
@@ -0,0 +1,7 @@
1
+ import { createApp } from 'vue'
2
+ import { setTtHost, ttHtmlLock } from '@pincast/placecard-kit/vue'
3
+ import App from './App.vue'
4
+ import './lantern.css'
5
+
6
+ setTtHost({ lock: ttHtmlLock })
7
+ createApp(App).mount('#app')
@@ -0,0 +1,27 @@
1
+ import { ref } from 'vue'
2
+ import { APP, FACES, SET_ID } from '../shared/app.js'
3
+
4
+ // Where the cards came from: 'sample' or 'live'. The page prints it.
5
+ export const source = ref(null)
6
+ export const signedIn = ref(true)
7
+
8
+ export async function loadCollection() {
9
+ const res = await fetch('/api/collection')
10
+ const body = await res.json().catch(() => ({}))
11
+ if (!res.ok) throw new Error(body.error || "Couldn't load the cards.")
12
+ source.value = body.source
13
+ signedIn.value = body.signedIn !== false
14
+ return body.collection
15
+ }
16
+
17
+ export const config = {
18
+ contract: 1,
19
+ app: APP.id,
20
+ source: { load: loadCollection },
21
+ faces: FACES,
22
+ theme: { class: 'lantern-theme', fonts: [] },
23
+ hand: { key: 'lantern_walk_hand', scope: SET_ID },
24
+ modes: { collection: true },
25
+ // The kit always draws this link at the top left, so it points somewhere useful.
26
+ links: { back: { label: 'The kit', href: 'https://github.com/pincastFM/placecard-kit-public' } },
27
+ }
@@ -0,0 +1,18 @@
1
+ // @vitest-environment jsdom
2
+ import { readFileSync } from 'node:fs'
3
+ import { dirname, resolve } from 'node:path'
4
+ import { fileURLToPath } from 'node:url'
5
+ import { ttConformance } from '@pincast/placecard-kit/conformance'
6
+ import { sampleCollects, toCollection } from '../server/collection.js'
7
+ import { config } from '../src/tabletop.js'
8
+
9
+ const here = dirname(fileURLToPath(import.meta.url))
10
+
11
+ ttConformance({
12
+ name: 'lantern-walk',
13
+ config,
14
+ collection: toCollection(sampleCollects),
15
+ css: [{ name: 'lantern.css', text: readFileSync(resolve(here, '../src/lantern.css'), 'utf8') }],
16
+ base: 'cardroom',
17
+ goldens: resolve(here, 'goldens'),
18
+ })