create-marcapony-app 0.0.1 → 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.
- package/LICENSE.md +48 -0
- package/README.md +49 -2
- package/dist/index.d.ts +21 -0
- package/dist/index.js +155 -0
- package/package.json +27 -17
- package/template/.dev.vars.example +5 -0
- package/template/README.md +59 -0
- package/template/_gitignore +5 -0
- package/template/_package.json +27 -0
- package/template/index.html +12 -0
- package/template/marcapony.json +11 -0
- package/template/scripts/dev.ts +55 -0
- package/template/src/server/index.ts +41 -0
- package/template/src/server/marcapony.ts +28 -0
- package/template/src/ui/App.tsx +55 -0
- package/template/src/ui/main.tsx +13 -0
- package/template/src/ui/styles.css +45 -0
- package/template/tsconfig.json +16 -0
- package/template/vite.config.ts +16 -0
- package/LICENSE +0 -21
- package/bin.mjs +0 -7
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,52 @@
|
|
|
1
1
|
# create-marcapony-app
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Scaffolds a Marcapony app: a Cloudflare Worker that talks to the Marcapony API
|
|
4
|
+
through the SDK, plus a React UI served as static assets.
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
```sh
|
|
7
|
+
bunx create-marcapony-app my-app
|
|
8
|
+
cd my-app
|
|
9
|
+
bun install
|
|
10
|
+
bunx marcapony app link
|
|
11
|
+
bun run dev
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
When it is ready:
|
|
15
|
+
|
|
16
|
+
```sh
|
|
17
|
+
bunx marcapony app deploy
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
No wrangler, no Cloudflare account, no git. The platform builds nothing for you
|
|
21
|
+
locally and hosts the result.
|
|
22
|
+
|
|
23
|
+
## What you get
|
|
24
|
+
|
|
25
|
+
| Path | What it is |
|
|
26
|
+
| ------------------------- | ------------------------------------------------ |
|
|
27
|
+
| `src/server/index.ts` | The Worker. Only `/api/*` reaches it |
|
|
28
|
+
| `src/server/marcapony.ts` | The only place that builds the Marcapony client |
|
|
29
|
+
| `src/ui/` | React app, built to `dist/client` |
|
|
30
|
+
| `marcapony.json` | How the platform builds and uploads the project |
|
|
31
|
+
| `.gitignore` | Already ignores `.dev.vars`, before a key exists |
|
|
32
|
+
|
|
33
|
+
The generated project has no `wrangler` dependency and no wrangler config. Local
|
|
34
|
+
dev runs the server under Bun; the deployed app runs on the Workers runtime. They
|
|
35
|
+
are close but not identical, so the generated README says to prefer plain web
|
|
36
|
+
APIs in `src/server` and to check the app after deploying a server change.
|
|
37
|
+
|
|
38
|
+
## Options
|
|
39
|
+
|
|
40
|
+
| Flag | Meaning |
|
|
41
|
+
| --------- | ----------------------------------------------------- |
|
|
42
|
+
| `--force` | Write into the directory even if it already has files |
|
|
43
|
+
| `-h` | Help |
|
|
44
|
+
|
|
45
|
+
Run without a directory argument and it asks for one.
|
|
46
|
+
|
|
47
|
+
Requires Node ≥ 20 (or Bun). Zero runtime dependencies.
|
|
48
|
+
|
|
49
|
+
## License
|
|
50
|
+
|
|
51
|
+
Proprietary tool, unrestricted output — the project it generates is yours to
|
|
52
|
+
license and ship however you like. See [LICENSE.md](./LICENSE.md).
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
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 bunx 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 bunx marcapony app link get this app's key\n bun run dev run it locally\n bunx 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
|
+
export declare function copyTemplate(from: string, to: string): void;
|
|
20
|
+
export declare function applyPackageName(dir: string, name: string): void;
|
|
21
|
+
export declare function run(argv: string[], moduleUrl: string): Promise<number>;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { cpSync, existsSync, mkdirSync, readdirSync, readFileSync, realpathSync, renameSync, 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
|
+
bunx 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
|
+
bunx marcapony app link get this app's key
|
|
65
|
+
bun run dev run it locally
|
|
66
|
+
bunx 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
|
+
' bunx marcapony app link # writes your app key into .dev.vars',
|
|
77
|
+
' bun run dev',
|
|
78
|
+
'',
|
|
79
|
+
'When it is ready:',
|
|
80
|
+
' bunx 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
|
+
export function copyTemplate(from, to) {
|
|
89
|
+
mkdirSync(to, { recursive: true });
|
|
90
|
+
cpSync(from, to, { recursive: true });
|
|
91
|
+
for (const [source, target] of Object.entries(TEMPLATE_RENAMES)) {
|
|
92
|
+
const sourcePath = join(to, source);
|
|
93
|
+
if (existsSync(sourcePath))
|
|
94
|
+
renameSync(sourcePath, join(to, target));
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
export function applyPackageName(dir, name) {
|
|
98
|
+
const path = join(dir, 'package.json');
|
|
99
|
+
const manifest = JSON.parse(readFileSync(path, 'utf8'));
|
|
100
|
+
manifest.name = name;
|
|
101
|
+
writeFileSync(path, `${JSON.stringify(manifest, null, 2)}\n`);
|
|
102
|
+
}
|
|
103
|
+
function isNonEmptyDir(dir) {
|
|
104
|
+
return existsSync(dir) && readdirSync(dir).length > 0;
|
|
105
|
+
}
|
|
106
|
+
async function promptForDir() {
|
|
107
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
108
|
+
try {
|
|
109
|
+
const answer = await rl.question(`Directory name (${DEFAULT_DIR}): `);
|
|
110
|
+
return answer.trim().length > 0 ? answer.trim() : DEFAULT_DIR;
|
|
111
|
+
}
|
|
112
|
+
finally {
|
|
113
|
+
rl.close();
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
export async function run(argv, moduleUrl) {
|
|
117
|
+
const args = parseArgs(argv);
|
|
118
|
+
if (args.help) {
|
|
119
|
+
process.stdout.write(HELP);
|
|
120
|
+
return 0;
|
|
121
|
+
}
|
|
122
|
+
const requested = args.dir ?? (process.stdin.isTTY ? await promptForDir() : DEFAULT_DIR);
|
|
123
|
+
const target = resolve(process.cwd(), requested);
|
|
124
|
+
if (isNonEmptyDir(target) && !args.force) {
|
|
125
|
+
process.stderr.write(`${requested} already has files in it. Pick another name, or pass --force to write into it anyway.\n`);
|
|
126
|
+
return 1;
|
|
127
|
+
}
|
|
128
|
+
const template = templateRoot(moduleUrl);
|
|
129
|
+
if (!existsSync(template)) {
|
|
130
|
+
process.stderr.write(`The template directory is missing from this install (looked in ${template}). Reinstall create-marcapony-app.\n`);
|
|
131
|
+
return 1;
|
|
132
|
+
}
|
|
133
|
+
copyTemplate(template, target);
|
|
134
|
+
applyPackageName(target, sanitizePackageName(basename(target)));
|
|
135
|
+
process.stdout.write(nextSteps(requested));
|
|
136
|
+
return 0;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* npm installs the bin as a symlink, so comparing argv[1] to import.meta.url
|
|
140
|
+
* directly never matches — resolve the link first. Same guard as the CLI's.
|
|
141
|
+
*/
|
|
142
|
+
function isEntrypoint() {
|
|
143
|
+
const invokedPath = process.argv[1];
|
|
144
|
+
if (!invokedPath)
|
|
145
|
+
return false;
|
|
146
|
+
try {
|
|
147
|
+
return realpathSync(invokedPath) === fileURLToPath(import.meta.url);
|
|
148
|
+
}
|
|
149
|
+
catch {
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
if (isEntrypoint()) {
|
|
154
|
+
process.exitCode = await run(process.argv.slice(2), import.meta.url);
|
|
155
|
+
}
|
package/package.json
CHANGED
|
@@ -1,27 +1,37 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-marcapony-app",
|
|
3
|
-
"version": "0.0
|
|
4
|
-
"description": "
|
|
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.0",
|
|
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": "
|
|
17
|
+
"create-marcapony-app": "dist/index.js"
|
|
18
18
|
},
|
|
19
19
|
"files": [
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"LICENSE"
|
|
20
|
+
"dist",
|
|
21
|
+
"template"
|
|
23
22
|
],
|
|
24
23
|
"engines": {
|
|
25
|
-
"node": ">=
|
|
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,59 @@
|
|
|
1
|
+
# Marcapony app
|
|
2
|
+
|
|
3
|
+
A Worker that serves this app's API and talks to Marcapony, plus a React UI
|
|
4
|
+
served as static assets.
|
|
5
|
+
|
|
6
|
+
## Get a key
|
|
7
|
+
|
|
8
|
+
```sh
|
|
9
|
+
bunx marcapony app link
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
Create the app under **My Apps** in your Marcapony dashboard, generate a pairing
|
|
13
|
+
code there, and paste it when asked. The CLI writes `MARCAPONY_API_KEY` into
|
|
14
|
+
`.dev.vars` itself — the key is never shown and never goes through a clipboard.
|
|
15
|
+
It also fills in `AGENTS.md` with the exact operations your key can perform, so
|
|
16
|
+
your AI assistant knows what this app is allowed to do.
|
|
17
|
+
|
|
18
|
+
## Develop
|
|
19
|
+
|
|
20
|
+
```sh
|
|
21
|
+
bun install
|
|
22
|
+
bun run dev
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Vite serves the UI and proxies `/api` to the Hono app in `src/server`.
|
|
26
|
+
|
|
27
|
+
One thing to know: `bun run dev` runs the server under Bun, while the deployed
|
|
28
|
+
app runs on the Workers runtime. They are close but not identical, so prefer
|
|
29
|
+
plain web APIs (`fetch`, `Request`, `Response`, `crypto`) over Node built-ins in
|
|
30
|
+
`src/server`, and check the deployed app after shipping a server change.
|
|
31
|
+
|
|
32
|
+
## Deploy
|
|
33
|
+
|
|
34
|
+
```sh
|
|
35
|
+
bunx marcapony app deploy
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
That builds the project, uploads it, and prints the hostname when it is live.
|
|
39
|
+
There is no wrangler and no Cloudflare account involved — the platform runs it
|
|
40
|
+
for you, injecting the key as a secret.
|
|
41
|
+
|
|
42
|
+
## Layout
|
|
43
|
+
|
|
44
|
+
| Path | What it is |
|
|
45
|
+
| ------------------------- | ------------------------------------------------ |
|
|
46
|
+
| `src/server/index.ts` | The Worker. Only `/api/*` reaches it |
|
|
47
|
+
| `src/server/marcapony.ts` | The only place that builds the Marcapony client |
|
|
48
|
+
| `src/ui/` | React app, built to `dist/client` |
|
|
49
|
+
| `marcapony.json` | How the platform builds and uploads this project |
|
|
50
|
+
| `.dev.vars` | Your key. Gitignored — never commit it |
|
|
51
|
+
|
|
52
|
+
## Rules that matter
|
|
53
|
+
|
|
54
|
+
- **The app key stays on the server.** The browser calls your `/api` routes;
|
|
55
|
+
those routes call Marcapony. A key in a client bundle is a public key.
|
|
56
|
+
- **Pass an `idempotencyKey` to every create call.** Retries then cannot create
|
|
57
|
+
the same order, reservation, or payment link twice.
|
|
58
|
+
- **Deployed apps are stateless.** No KV, Durable Objects, D1 or R2 — durable
|
|
59
|
+
state lives behind the Marcapony API, which your key already reaches.
|
|
@@ -0,0 +1,27 @@
|
|
|
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/react": "^19.0.0",
|
|
21
|
+
"@types/react-dom": "^19.0.0",
|
|
22
|
+
"@vitejs/plugin-react": "^5.0.0",
|
|
23
|
+
"esbuild": "^0.25.0",
|
|
24
|
+
"typescript": "^5.8.3",
|
|
25
|
+
"vite": "^7.0.0"
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -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.
|