create-marcapony-app 0.0.1 → 0.1.1

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.
package/LICENSE.md ADDED
@@ -0,0 +1,48 @@
1
+ # create-marcapony-app — License
2
+
3
+ Copyright © 2026 Creafolks. All rights reserved.
4
+
5
+ This software is proprietary. It is published to make installation convenient,
6
+ not to place it in the public domain or under an open-source license.
7
+
8
+ ## Permitted
9
+
10
+ You may run this software to scaffold projects, and **the project it generates
11
+ is yours**. The generated files carry no restriction from this license: build on
12
+ them, change them, license them as you see fit, and distribute and host the
13
+ result commercially.
14
+
15
+ This permission extends to your employees and contractors acting on your behalf,
16
+ and to the AI tools you use. It stands on its own.
17
+
18
+ ## Not permitted
19
+
20
+ Without prior written permission from Creafolks, you may not:
21
+
22
+ - redistribute, sublicense, sell, or host the scaffolding tool itself, modified
23
+ or not;
24
+ - remove or alter any copyright, trademark, or attribution notice in it.
25
+
26
+ The distinction is between the tool and its output. The output is yours; the tool
27
+ is not.
28
+
29
+ Note that the Marcapony SDK the generated project depends on carries its own
30
+ license (`marcapony-sdk`), which explicitly permits bundling it into your
31
+ application and shipping that application.
32
+
33
+ "Marcapony" and the Marcapony logo are trademarks of Creafolks. This license
34
+ grants no trademark rights.
35
+
36
+ ## No warranty
37
+
38
+ THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
39
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
40
+ FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT. TO THE MAXIMUM EXTENT
41
+ PERMITTED BY LAW, CREAFOLKS SHALL NOT BE LIABLE FOR ANY CLAIM, DAMAGES, OR
42
+ OTHER LIABILITY ARISING FROM, OUT OF, OR IN CONNECTION WITH THIS SOFTWARE OR
43
+ ITS USE.
44
+
45
+ ## Questions
46
+
47
+ For permissions beyond this license, contact Creafolks via
48
+ https://marcapony.com.
package/README.md CHANGED
@@ -1,5 +1,50 @@
1
1
  # create-marcapony-app
2
2
 
3
- This package name is reserved for the official app scaffolder of the [Marcapony](https://marcapony.com) website-builder platform. Once released, `npm create marcapony-app` will bootstrap a new Marcapony project in seconds.
3
+ Creates a new Marcapony app — a small web app with its own backend, already
4
+ connected to your Marcapony account.
4
5
 
5
- It is not ready yet — this is a placeholder release. Learn more at [marcapony.com](https://marcapony.com).
6
+ ```sh
7
+ npx create-marcapony-app my-app
8
+ cd my-app
9
+ bun install
10
+ npx marcapony app link
11
+ bun run dev
12
+ ```
13
+
14
+ When it is ready:
15
+
16
+ ```sh
17
+ npx marcapony app deploy
18
+ ```
19
+
20
+ Marcapony hosts it. There is nothing to set up and no other account to sign up
21
+ for.
22
+
23
+ ## What you get
24
+
25
+ | Path | What it is |
26
+ | ------------------------- | ------------------------------------------- |
27
+ | `src/server/index.ts` | Your backend. Handles `/api/*` |
28
+ | `src/server/marcapony.ts` | The only place that talks to Marcapony |
29
+ | `src/ui/` | Your interface |
30
+ | `marcapony.json` | How Marcapony builds and publishes your app |
31
+
32
+ `npx marcapony app link` puts your app key in place and writes an `AGENTS.md`
33
+ listing exactly what this app is allowed to do — so an AI assistant can pick the
34
+ project up and start building on it.
35
+
36
+ ## Options
37
+
38
+ | Flag | Meaning |
39
+ | --------- | ----------------------------------------------------- |
40
+ | `--force` | Write into the directory even if it already has files |
41
+ | `-h` | Help |
42
+
43
+ Run without a directory name and it asks for one.
44
+
45
+ Requires Node 20 or newer, or Bun. No runtime dependencies.
46
+
47
+ ## License
48
+
49
+ Proprietary tool, unrestricted output — the app it creates is yours to license
50
+ and ship however you like. See [LICENSE.md](./LICENSE.md).
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * npm refuses to load a package whose name breaks its rules, and the name here
4
+ * comes from a directory the user typed. Keep the recognizable part, drop the
5
+ * rest, and fall back rather than emit something npm will reject.
6
+ */
7
+ export declare function sanitizePackageName(input: string): string;
8
+ export declare function templateTargetName(name: string): string;
9
+ export interface ParsedArgs {
10
+ dir?: string;
11
+ force: boolean;
12
+ help: boolean;
13
+ }
14
+ export declare function parseArgs(argv: string[]): ParsedArgs;
15
+ export declare const HELP = "create-marcapony-app \u2014 scaffold a Marcapony app\n\nUsage\n npx create-marcapony-app [directory] [--force]\n\nOptions\n --force Write into the directory even if it already has files\n -h Show this help\n\nNext, in the new directory:\n npx marcapony app link get this app's key\n bun run dev run it locally\n npx marcapony app deploy put it live\n";
16
+ export declare function nextSteps(dir: string): string;
17
+ /** Resolve `template/` relative to the compiled entry, not the cwd. */
18
+ export declare function templateRoot(moduleUrl: string): string;
19
+ /**
20
+ * Copy the template, never overwriting a file that is already there.
21
+ *
22
+ * That matters most with `--force`, which is how someone lands here with a
23
+ * directory that already has content. Clobbering would destroy exactly the files
24
+ * you cannot get back: `.dev.vars` holds a key the platform will not show again,
25
+ * and `marcapony.json` holds the app slug `marcapony app link` wrote. Filling in
26
+ * only what is missing is both safer and the more useful meaning of --force.
27
+ */
28
+ export declare function copyTemplate(from: string, to: string): void;
29
+ export declare function applyPackageName(dir: string, name: string): void;
30
+ export declare function run(argv: string[], moduleUrl: string): Promise<number>;
package/dist/index.js ADDED
@@ -0,0 +1,188 @@
1
+ #!/usr/bin/env node
2
+ import { cpSync, existsSync, mkdirSync, readdirSync, readFileSync, realpathSync, renameSync, rmSync, writeFileSync, } from 'node:fs';
3
+ import { basename, dirname, join, resolve } from 'node:path';
4
+ import { fileURLToPath } from 'node:url';
5
+ import { createInterface } from 'node:readline/promises';
6
+ /**
7
+ * `create-marcapony-app` — copies the template in `template/` into a new
8
+ * directory and points its package.json at the chosen name. Deliberately does
9
+ * no key handling and no deploy: `marcapony app link` mints the key and
10
+ * `marcapony app deploy` ships the project, and both work on any project, not
11
+ * just a scaffolded one.
12
+ */
13
+ const DEFAULT_DIR = 'marcapony-app';
14
+ /**
15
+ * npm refuses to load a package whose name breaks its rules, and the name here
16
+ * comes from a directory the user typed. Keep the recognizable part, drop the
17
+ * rest, and fall back rather than emit something npm will reject.
18
+ */
19
+ export function sanitizePackageName(input) {
20
+ const cleaned = input
21
+ .trim()
22
+ .toLowerCase()
23
+ .replace(/[^a-z0-9._-]+/g, '-')
24
+ .replace(/^[._-]+/, '')
25
+ .replace(/-+$/, '')
26
+ .slice(0, 214);
27
+ return cleaned.length > 0 ? cleaned : DEFAULT_DIR;
28
+ }
29
+ /**
30
+ * npm strips `.gitignore` out of published tarballs and a nested `package.json`
31
+ * confuses tooling that walks the tree, so both ship under an underscore and are
32
+ * restored on copy — the same convention `create-vite` uses.
33
+ */
34
+ const TEMPLATE_RENAMES = {
35
+ _gitignore: '.gitignore',
36
+ _package_json: 'package.json',
37
+ '_package.json': 'package.json',
38
+ };
39
+ export function templateTargetName(name) {
40
+ return TEMPLATE_RENAMES[name] ?? name;
41
+ }
42
+ export function parseArgs(argv) {
43
+ const out = { force: false, help: false };
44
+ for (const arg of argv) {
45
+ if (arg === '--force')
46
+ out.force = true;
47
+ else if (arg === '--help' || arg === '-h')
48
+ out.help = true;
49
+ else if (!arg.startsWith('-') && out.dir === undefined)
50
+ out.dir = arg;
51
+ }
52
+ return out;
53
+ }
54
+ export const HELP = `create-marcapony-app — scaffold a Marcapony app
55
+
56
+ Usage
57
+ npx create-marcapony-app [directory] [--force]
58
+
59
+ Options
60
+ --force Write into the directory even if it already has files
61
+ -h Show this help
62
+
63
+ Next, in the new directory:
64
+ npx marcapony app link get this app's key
65
+ bun run dev run it locally
66
+ npx marcapony app deploy put it live
67
+ `;
68
+ export function nextSteps(dir) {
69
+ return [
70
+ '',
71
+ `Created ${dir}.`,
72
+ '',
73
+ 'Next:',
74
+ ` cd ${dir}`,
75
+ ' bun install',
76
+ ' npx marcapony app link # writes your app key into .dev.vars',
77
+ ' bun run dev',
78
+ '',
79
+ 'When it is ready:',
80
+ ' npx marcapony app deploy',
81
+ '',
82
+ ].join('\n');
83
+ }
84
+ /** Resolve `template/` relative to the compiled entry, not the cwd. */
85
+ export function templateRoot(moduleUrl) {
86
+ return resolve(dirname(fileURLToPath(moduleUrl)), '..', 'template');
87
+ }
88
+ /**
89
+ * Copy the template, never overwriting a file that is already there.
90
+ *
91
+ * That matters most with `--force`, which is how someone lands here with a
92
+ * directory that already has content. Clobbering would destroy exactly the files
93
+ * you cannot get back: `.dev.vars` holds a key the platform will not show again,
94
+ * and `marcapony.json` holds the app slug `marcapony app link` wrote. Filling in
95
+ * only what is missing is both safer and the more useful meaning of --force.
96
+ */
97
+ export function copyTemplate(from, to) {
98
+ mkdirSync(to, { recursive: true });
99
+ cpSync(from, to, {
100
+ recursive: true,
101
+ force: false,
102
+ errorOnExist: false,
103
+ // Skip a template file when its destination — under the name it will
104
+ // actually land as — already exists.
105
+ filter: (source) => {
106
+ const relative = source.slice(from.length).replace(/^[/\\]/, '');
107
+ if (relative.length === 0)
108
+ return true;
109
+ const segments = relative.split(/[/\\]/);
110
+ const last = segments[segments.length - 1];
111
+ if (last === undefined)
112
+ return true;
113
+ segments[segments.length - 1] = templateTargetName(last);
114
+ return !existsSync(join(to, ...segments));
115
+ },
116
+ });
117
+ for (const [source, target] of Object.entries(TEMPLATE_RENAMES)) {
118
+ const sourcePath = join(to, source);
119
+ if (!existsSync(sourcePath))
120
+ continue;
121
+ const targetPath = join(to, target);
122
+ if (existsSync(targetPath)) {
123
+ // The real name was already present, so the underscore copy is redundant.
124
+ rmSync(sourcePath);
125
+ continue;
126
+ }
127
+ renameSync(sourcePath, targetPath);
128
+ }
129
+ }
130
+ export function applyPackageName(dir, name) {
131
+ const path = join(dir, 'package.json');
132
+ const manifest = JSON.parse(readFileSync(path, 'utf8'));
133
+ manifest.name = name;
134
+ writeFileSync(path, `${JSON.stringify(manifest, null, 2)}\n`);
135
+ }
136
+ function isNonEmptyDir(dir) {
137
+ return existsSync(dir) && readdirSync(dir).length > 0;
138
+ }
139
+ async function promptForDir() {
140
+ const rl = createInterface({ input: process.stdin, output: process.stdout });
141
+ try {
142
+ const answer = await rl.question(`Directory name (${DEFAULT_DIR}): `);
143
+ return answer.trim().length > 0 ? answer.trim() : DEFAULT_DIR;
144
+ }
145
+ finally {
146
+ rl.close();
147
+ }
148
+ }
149
+ export async function run(argv, moduleUrl) {
150
+ const args = parseArgs(argv);
151
+ if (args.help) {
152
+ process.stdout.write(HELP);
153
+ return 0;
154
+ }
155
+ const requested = args.dir ?? (process.stdin.isTTY ? await promptForDir() : DEFAULT_DIR);
156
+ const target = resolve(process.cwd(), requested);
157
+ if (isNonEmptyDir(target) && !args.force) {
158
+ process.stderr.write(`${requested} already has files in it. Pick another name, or pass --force to write into it anyway.\n`);
159
+ return 1;
160
+ }
161
+ const template = templateRoot(moduleUrl);
162
+ if (!existsSync(template)) {
163
+ process.stderr.write(`The template directory is missing from this install (looked in ${template}). Reinstall create-marcapony-app.\n`);
164
+ return 1;
165
+ }
166
+ copyTemplate(template, target);
167
+ applyPackageName(target, sanitizePackageName(basename(target)));
168
+ process.stdout.write(nextSteps(requested));
169
+ return 0;
170
+ }
171
+ /**
172
+ * npm installs the bin as a symlink, so comparing argv[1] to import.meta.url
173
+ * directly never matches — resolve the link first. Same guard as the CLI's.
174
+ */
175
+ function isEntrypoint() {
176
+ const invokedPath = process.argv[1];
177
+ if (!invokedPath)
178
+ return false;
179
+ try {
180
+ return realpathSync(invokedPath) === fileURLToPath(import.meta.url);
181
+ }
182
+ catch {
183
+ return false;
184
+ }
185
+ }
186
+ if (isEntrypoint()) {
187
+ process.exitCode = await run(process.argv.slice(2), import.meta.url);
188
+ }
package/package.json CHANGED
@@ -1,27 +1,37 @@
1
1
  {
2
2
  "name": "create-marcapony-app",
3
- "version": "0.0.1",
4
- "description": "Name placeholder for the upcoming Marcapony app scaffolder. The real create-marcapony-app is on its way — see https://marcapony.com.",
5
- "keywords": [
6
- "marcapony",
7
- "create",
8
- "scaffold",
9
- "website-builder",
10
- "placeholder"
11
- ],
12
- "homepage": "https://marcapony.com",
13
- "license": "MIT",
14
- "author": "Creafolks",
3
+ "version": "0.1.1",
4
+ "description": "Scaffold a Marcapony app — a Worker backed by the Marcapony API, ready for `marcapony app link` and `marcapony app deploy`",
15
5
  "type": "module",
6
+ "license": "SEE LICENSE IN LICENSE.md",
7
+ "homepage": "https://marcapony.com",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/creafolks/marcapony-api.git",
11
+ "directory": "create-app"
12
+ },
13
+ "publishConfig": {
14
+ "access": "public"
15
+ },
16
16
  "bin": {
17
- "create-marcapony-app": "bin.mjs"
17
+ "create-marcapony-app": "dist/index.js"
18
18
  },
19
19
  "files": [
20
- "bin.mjs",
21
- "README.md",
22
- "LICENSE"
20
+ "dist",
21
+ "template"
23
22
  ],
24
23
  "engines": {
25
- "node": ">=18"
24
+ "node": ">=20"
25
+ },
26
+ "scripts": {
27
+ "build": "tsc -p tsconfig.build.json",
28
+ "typecheck": "tsc --noEmit",
29
+ "test": "bun test",
30
+ "prepublishOnly": "bun run build"
31
+ },
32
+ "devDependencies": {
33
+ "@types/bun": "^1.3.14",
34
+ "@types/node": "^22.10.2",
35
+ "typescript": "^5.8.3"
26
36
  }
27
37
  }
@@ -0,0 +1,5 @@
1
+ # `bunx marcapony app link` writes the real values into `.dev.vars` for you —
2
+ # the key is minted fresh and never passes through a clipboard. This file is
3
+ # only here to document what ends up there.
4
+ MARCAPONY_API_KEY=mpk_...
5
+ MARCAPONY_API_URL=https://api.marcapony.com/ext/v1
@@ -0,0 +1,57 @@
1
+ # Marcapony app
2
+
3
+ A small web app with its own backend, connected to your Marcapony account.
4
+
5
+ ## Get a key
6
+
7
+ ```sh
8
+ npx marcapony app link
9
+ ```
10
+
11
+ Create the app under **My Apps** in your Marcapony dashboard, generate a
12
+ connection code there, and paste it when asked. The key is written into
13
+ `.dev.vars` for you — it is never shown and never goes through your clipboard.
14
+ An `AGENTS.md` is written too, listing exactly what this app is allowed to do, so
15
+ your AI assistant knows what it can build.
16
+
17
+ ## Develop
18
+
19
+ ```sh
20
+ bun install
21
+ bun run dev
22
+ ```
23
+
24
+ Your interface and your `/api` routes both run locally.
25
+
26
+ One thing to know: local development and the published app run in slightly
27
+ different environments. Stick to standard web APIs in `src/server` — `fetch`,
28
+ `Request`, `Response`, `crypto` — since those behave identically in both, and
29
+ check the published app after you change something on the backend.
30
+
31
+ ## Publish
32
+
33
+ ```sh
34
+ npx marcapony app deploy
35
+ ```
36
+
37
+ That builds your app, publishes it, and prints its address. Marcapony hosts it
38
+ and supplies the key at runtime; there is nothing for you to configure.
39
+
40
+ ## Layout
41
+
42
+ | Path | What it is |
43
+ | ------------------------- | ------------------------------------------- |
44
+ | `src/server/index.ts` | Your backend. Handles `/api/*` |
45
+ | `src/server/marcapony.ts` | The only place that talks to Marcapony |
46
+ | `src/ui/` | Your interface |
47
+ | `marcapony.json` | How Marcapony builds and publishes your app |
48
+ | `.dev.vars` | Your key. Never commit it |
49
+
50
+ ## Rules that matter
51
+
52
+ - **The key stays on the backend.** Your interface calls your own `/api` routes,
53
+ and those routes call Marcapony. A key sent to the browser is a public key.
54
+ - **Pass an `idempotencyKey` to every create call.** Retries then cannot create
55
+ the same order, reservation, or payment link twice.
56
+ - **Apps keep no storage of their own.** Anything that has to persist lives in
57
+ Marcapony, which your key already reaches.
@@ -0,0 +1,5 @@
1
+ node_modules
2
+ dist
3
+
4
+ # Holds a live Marcapony app key — `marcapony app link` writes it here.
5
+ .dev.vars
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "marcapony-app",
3
+ "version": "0.0.0",
4
+ "private": true,
5
+ "type": "module",
6
+ "scripts": {
7
+ "dev": "bun run scripts/dev.ts",
8
+ "build": "bun run build:client && bun run build:worker",
9
+ "build:client": "vite build",
10
+ "build:worker": "esbuild src/server/index.ts --bundle --format=esm --platform=neutral --conditions=worker,browser --target=es2022 --outfile=dist/worker/index.js",
11
+ "typecheck": "tsc --noEmit"
12
+ },
13
+ "dependencies": {
14
+ "hono": "^4.6.14",
15
+ "marcapony-sdk": "^0.2.0",
16
+ "react": "^19.0.0",
17
+ "react-dom": "^19.0.0"
18
+ },
19
+ "devDependencies": {
20
+ "@types/bun": "^1.3.14",
21
+ "@types/react": "^19.0.0",
22
+ "@types/react-dom": "^19.0.0",
23
+ "@vitejs/plugin-react": "^5.0.0",
24
+ "esbuild": "^0.25.0",
25
+ "typescript": "^5.8.3",
26
+ "vite": "^7.0.0"
27
+ }
28
+ }
@@ -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.0" />
6
+ <title>Marcapony app</title>
7
+ </head>
8
+ <body>
9
+ <div id="root"></div>
10
+ <script type="module" src="/src/ui/main.tsx"></script>
11
+ </body>
12
+ </html>
@@ -0,0 +1,11 @@
1
+ {
2
+ "build": "bun run build",
3
+ "worker": "dist/worker/index.js",
4
+ "assets": "dist/client",
5
+ "assetsConfig": {
6
+ "not_found_handling": "single-page-application",
7
+ "run_worker_first": ["/api/*"]
8
+ },
9
+ "compatibilityDate": "2025-05-10",
10
+ "compatibilityFlags": ["nodejs_compat"]
11
+ }
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Local dev: Vite serves the UI and proxies `/api` here, where the same Hono app
3
+ * that ships to production handles the request.
4
+ *
5
+ * Caveat worth knowing: this runs under Bun, not the Workers runtime. The two
6
+ * are close but not identical, so a deployed app can still surface something
7
+ * local dev did not. Verify after `bunx marcapony app deploy`, and prefer plain
8
+ * web APIs (fetch, Request, Response, crypto) over Node built-ins in
9
+ * `src/server` — those are the ones that behave the same in both.
10
+ */
11
+ import { readFileSync, existsSync } from 'node:fs'
12
+ import app from '../src/server/index'
13
+
14
+ const API_PORT = 8787
15
+ const ENV_FILE = '.dev.vars'
16
+
17
+ function loadDevVars(): Record<string, string> {
18
+ if (!existsSync(ENV_FILE)) return {}
19
+ const out: Record<string, string> = {}
20
+ for (const line of readFileSync(ENV_FILE, 'utf8').split('\n')) {
21
+ const trimmed = line.trim()
22
+ if (!trimmed || trimmed.startsWith('#')) continue
23
+ const eq = trimmed.indexOf('=')
24
+ if (eq <= 0) continue
25
+ out[trimmed.slice(0, eq).trim()] = trimmed.slice(eq + 1).trim()
26
+ }
27
+ return out
28
+ }
29
+
30
+ const env = loadDevVars()
31
+ if (!env.MARCAPONY_API_KEY) {
32
+ console.warn(
33
+ `No MARCAPONY_API_KEY in ${ENV_FILE} — /api routes that call Marcapony will fail.\nRun \`bunx marcapony app link\` to get one.`,
34
+ )
35
+ }
36
+
37
+ const vite = Bun.spawn(['bunx', 'vite', 'dev'], { stdout: 'inherit', stderr: 'inherit' })
38
+
39
+ const server = Bun.serve({
40
+ port: API_PORT,
41
+ fetch: (request) => app.fetch(request, env),
42
+ })
43
+
44
+ console.info(`API on http://localhost:${server.port} — open the URL Vite prints above.`)
45
+
46
+ for (const signal of ['SIGINT', 'SIGTERM'] as const) {
47
+ process.on(signal, () => {
48
+ vite.kill()
49
+ server.stop()
50
+ process.exit(0)
51
+ })
52
+ }
53
+
54
+ await vite.exited
55
+ server.stop()
@@ -0,0 +1,41 @@
1
+ import { Hono } from 'hono'
2
+ import { marcaponyFromEnv, type MarcaponyBindings } from './marcapony'
3
+
4
+ /**
5
+ * The app's server. Only `/api/*` reaches this worker — everything else is
6
+ * served from `dist/client` by the platform (see `run_worker_first` in
7
+ * marcapony.json), so there is no static-file handling to write here.
8
+ */
9
+ const app = new Hono<{ Bindings: MarcaponyBindings }>()
10
+
11
+ app.get('/api/health', (c) => c.json({ ok: true }))
12
+
13
+ /**
14
+ * Example read. The app key never leaves the server: the browser calls this
15
+ * route, and this route calls Marcapony.
16
+ */
17
+ app.get('/api/products', async (c) => {
18
+ const mp = marcaponyFromEnv(c.env)
19
+ const page = await mp.products.list({ perPage: 12 })
20
+ return c.json({ products: page.data, total: page.meta.total })
21
+ })
22
+
23
+ /**
24
+ * Every non-GET call to Marcapony should carry an idempotency key so a retry
25
+ * (yours or the SDK's) cannot create the same thing twice. Derive it from
26
+ * something stable about the request, never from a fresh random per attempt.
27
+ *
28
+ * app.post('/api/orders', async (c) => {
29
+ * const body = await c.req.json()
30
+ * const mp = marcaponyFromEnv(c.env)
31
+ * const order = await mp.orders.create(body, { idempotencyKey: body.requestId })
32
+ * return c.json(order, 201)
33
+ * })
34
+ */
35
+
36
+ app.onError((err, c) => {
37
+ console.error(err)
38
+ return c.json({ error: err instanceof Error ? err.message : 'Unexpected error' }, 500)
39
+ })
40
+
41
+ export default app
@@ -0,0 +1,28 @@
1
+ import { createClient } from 'marcapony-sdk'
2
+
3
+ /**
4
+ * The one place that owns the Marcapony env contract and builds the client.
5
+ * Keep it that way: a second `createClient` call somewhere else is how a key
6
+ * ends up read from the wrong place, or bundled into the browser.
7
+ */
8
+ export interface MarcaponyBindings {
9
+ /** Scoped app key (`mpk_...`). Written into `.dev.vars` by `marcapony app link`. */
10
+ MARCAPONY_API_KEY?: string
11
+ /** API root. Also written by `app link`; the SDK defaults to production. */
12
+ MARCAPONY_API_URL?: string
13
+ }
14
+
15
+ export type Marcapony = ReturnType<typeof createClient>
16
+
17
+ /**
18
+ * Workers env is request-scoped, so build the client per request. The SDK is
19
+ * zero-dependency and holds no connections, so construction is effectively free.
20
+ */
21
+ export function marcaponyFromEnv(env: MarcaponyBindings): Marcapony {
22
+ if (!env.MARCAPONY_API_KEY) {
23
+ throw new Error(
24
+ 'MARCAPONY_API_KEY is missing. Run `bunx marcapony app link` in this project — it writes the key into .dev.vars for you.',
25
+ )
26
+ }
27
+ return createClient({ apiKey: env.MARCAPONY_API_KEY, baseUrl: env.MARCAPONY_API_URL })
28
+ }
@@ -0,0 +1,55 @@
1
+ import { useEffect, useState } from 'react'
2
+
3
+ interface Product {
4
+ id: string
5
+ name: string
6
+ // Nullable in the API: a product does not have to carry a price.
7
+ price: number | null
8
+ currency: string | null
9
+ }
10
+
11
+ function formatPrice({ price, currency }: Product): string {
12
+ if (price === null) return '—'
13
+ return currency ? `${price} ${currency}` : String(price)
14
+ }
15
+
16
+ /**
17
+ * Calls this app's own `/api` route, never Marcapony directly — the app key
18
+ * lives on the server and must stay there.
19
+ */
20
+ export function App() {
21
+ const [products, setProducts] = useState<Product[] | null>(null)
22
+ const [error, setError] = useState<string | null>(null)
23
+
24
+ useEffect(() => {
25
+ fetch('/api/products')
26
+ .then(async (res) => {
27
+ const body = (await res.json()) as { products?: Product[]; error?: string }
28
+ if (!res.ok) throw new Error(body.error ?? `Request failed with status ${res.status}`)
29
+ setProducts(body.products ?? [])
30
+ })
31
+ .catch((err: unknown) => setError(err instanceof Error ? err.message : 'Request failed'))
32
+ }, [])
33
+
34
+ return (
35
+ <main>
36
+ <h1>Your Marcapony app</h1>
37
+ <p>
38
+ Edit <code>src/ui/App.tsx</code> for the UI and <code>src/server/index.ts</code> for the
39
+ API.
40
+ </p>
41
+
42
+ <h2>Products</h2>
43
+ {error ? <p className="error">{error}</p> : null}
44
+ {!error && products === null ? <p>Loading…</p> : null}
45
+ {products?.length === 0 ? <p>No products in this account yet.</p> : null}
46
+ <ul>
47
+ {products?.map((product) => (
48
+ <li key={product.id}>
49
+ {product.name} — {formatPrice(product)}
50
+ </li>
51
+ ))}
52
+ </ul>
53
+ </main>
54
+ )
55
+ }
@@ -0,0 +1,13 @@
1
+ import { StrictMode } from 'react'
2
+ import { createRoot } from 'react-dom/client'
3
+ import { App } from './App'
4
+ import './styles.css'
5
+
6
+ const root = document.getElementById('root')
7
+ if (!root) throw new Error('#root is missing from index.html')
8
+
9
+ createRoot(root).render(
10
+ <StrictMode>
11
+ <App />
12
+ </StrictMode>,
13
+ )
@@ -0,0 +1,45 @@
1
+ :root {
2
+ color-scheme: light dark;
3
+ font-family:
4
+ ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
5
+ line-height: 1.5;
6
+ }
7
+
8
+ body {
9
+ margin: 0;
10
+ }
11
+
12
+ main {
13
+ max-width: 42rem;
14
+ margin: 0 auto;
15
+ padding: 3rem 1.5rem;
16
+ }
17
+
18
+ h1 {
19
+ font-size: 1.5rem;
20
+ margin-bottom: 0.5rem;
21
+ }
22
+
23
+ h2 {
24
+ font-size: 1.125rem;
25
+ margin-top: 2rem;
26
+ }
27
+
28
+ code {
29
+ font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
30
+ font-size: 0.875em;
31
+ }
32
+
33
+ ul {
34
+ padding-left: 1.25rem;
35
+ }
36
+
37
+ .error {
38
+ color: #b91c1c;
39
+ }
40
+
41
+ @media (prefers-color-scheme: dark) {
42
+ .error {
43
+ color: #fca5a5;
44
+ }
45
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "ESNext",
5
+ "moduleResolution": "bundler",
6
+ "lib": ["ES2022", "DOM", "DOM.Iterable"],
7
+ "jsx": "react-jsx",
8
+ "strict": true,
9
+ "noUncheckedIndexedAccess": true,
10
+ "skipLibCheck": true,
11
+ "isolatedModules": true,
12
+ "noEmit": true,
13
+ "types": ["bun"]
14
+ },
15
+ "include": ["src", "scripts", "vite.config.ts"]
16
+ }
@@ -0,0 +1,16 @@
1
+ import { defineConfig } from 'vite'
2
+ import react from '@vitejs/plugin-react'
3
+
4
+ export default defineConfig({
5
+ plugins: [react()],
6
+ build: {
7
+ // `marcapony.json` uploads this directory as the app's static assets.
8
+ outDir: 'dist/client',
9
+ emptyOutDir: true,
10
+ },
11
+ server: {
12
+ // `bun run dev` serves the Hono app on 8787; in production the platform
13
+ // routes /api/* to the worker instead (see run_worker_first).
14
+ proxy: { '/api': 'http://localhost:8787' },
15
+ },
16
+ })
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 Creafolks
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
package/bin.mjs DELETED
@@ -1,7 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- console.log(
4
- "create-marcapony-app is coming soon — see https://marcapony.com"
5
- );
6
-
7
- process.exit(0);