@quickshops/cli 0.0.0-stage → 2.0.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/README.md CHANGED
@@ -1,3 +1,13 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
1
+ # `@quickshops/cli` (`qs`)
2
+
3
+ Thin CLI over the Quickshops Headless API. Same `/v1` contract as the SDK and MCP.
4
+
5
+ ```bash
6
+ npm install -g @quickshops/cli
7
+
8
+ qs login --key qk_…
9
+ qs products list
10
+ qs orders ship <orderId> --tracking 1Z… --carrier ups
11
+ ```
12
+
13
+ Env: `QUICKSHOPS_SECRET_KEY`, `HEADLESS_API_URL` (or `QUICKSHOPS_API_*`).
@@ -0,0 +1,8 @@
1
+ type QsConfig = {
2
+ apiKey?: string;
3
+ apiUrl?: string;
4
+ };
5
+ export declare function writeConfig(config: QsConfig): void;
6
+ export declare function resolveApiKey(flag?: string): string | undefined;
7
+ export declare function resolveApiUrl(flag?: string): string | undefined;
8
+ export {};
package/dist/config.js ADDED
@@ -0,0 +1,27 @@
1
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
2
+ import { homedir } from "node:os";
3
+ import { join } from "node:path";
4
+ const configDir = join(homedir(), ".config", "quickshops");
5
+ const configPath = join(configDir, "config.json");
6
+ function readConfig() {
7
+ return existsSync(configPath)
8
+ ? JSON.parse(readFileSync(configPath, "utf8"))
9
+ : {};
10
+ }
11
+ export function writeConfig(config) {
12
+ mkdirSync(configDir, { recursive: true, mode: 0o700 });
13
+ writeFileSync(configPath, `${JSON.stringify(config, null, 2)}\n`, {
14
+ mode: 0o600,
15
+ });
16
+ }
17
+ export function resolveApiKey(flag) {
18
+ return (flag ||
19
+ process.env.QUICKSHOPS_SECRET_KEY ||
20
+ readConfig().apiKey);
21
+ }
22
+ export function resolveApiUrl(flag) {
23
+ return (flag ||
24
+ process.env.HEADLESS_API_URL ||
25
+ process.env.QUICKSHOPS_API_URL ||
26
+ readConfig().apiUrl);
27
+ }
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/index.js ADDED
@@ -0,0 +1,153 @@
1
+ #!/usr/bin/env node
2
+ import { parseArgs } from "node:util";
3
+ import { createMerchantClient } from "./merchant-client.js";
4
+ import { resolveApiKey, resolveApiUrl, writeConfig } from "./config.js";
5
+ import { runInit } from "./init.js";
6
+ const HELP = `Quickshops CLI (qs)
7
+
8
+ Usage:
9
+ qs login --key qk_… [--api-url https://api.quickshops.app]
10
+ qs whoami
11
+ qs products list [--limit 20] [--include-inactive]
12
+ qs products create --name NAME --price CENTS --tax-code CODE [--type digital|physical] [--download-url URL] [--description TEXT] [--sku SKU]
13
+ qs products update <productId> [--name NAME] [--price CENTS] [--active true|false] [--description TEXT] [--tax-code CODE]
14
+ qs products delete <productId>
15
+ qs orders list [--limit 10]
16
+ qs orders get <orderId>
17
+ qs orders ship <orderId> [--tracking NUMBER] [--carrier NAME]
18
+ qs orders refund <orderId> [--line-item-id ID]… [--restock true|false]
19
+ qs init
20
+
21
+ Env:
22
+ QUICKSHOPS_SECRET_KEY
23
+ HEADLESS_API_URL / QUICKSHOPS_API_URL
24
+ `;
25
+ const OPTIONS = {
26
+ help: { type: "boolean", short: "h" },
27
+ key: { type: "string" },
28
+ "api-url": { type: "string" },
29
+ limit: { type: "string" },
30
+ "include-inactive": { type: "boolean" },
31
+ name: { type: "string" },
32
+ price: { type: "string" },
33
+ "tax-code": { type: "string" },
34
+ type: { type: "string" },
35
+ "download-url": { type: "string" },
36
+ description: { type: "string" },
37
+ sku: { type: "string" },
38
+ active: { type: "string" },
39
+ tracking: { type: "string" },
40
+ carrier: { type: "string" },
41
+ "line-item-id": { type: "string", multiple: true },
42
+ restock: { type: "string" },
43
+ };
44
+ const { values: flags, positionals } = (() => {
45
+ try {
46
+ return parseArgs({ allowPositionals: true, options: OPTIONS });
47
+ }
48
+ catch (error) {
49
+ console.error(`${error.message}. Run qs --help`);
50
+ process.exit(1);
51
+ }
52
+ })();
53
+ const [command, sub, id] = positionals;
54
+ function bool(value) {
55
+ return value === undefined ? undefined : value === "true" || value === "1";
56
+ }
57
+ function int(value) {
58
+ return value === undefined ? undefined : Number(value);
59
+ }
60
+ function requireId(label) {
61
+ if (!id)
62
+ throw new Error(`${command} ${sub} requires <${label}>`);
63
+ return id;
64
+ }
65
+ function client() {
66
+ const apiKey = resolveApiKey(flags.key);
67
+ if (!apiKey) {
68
+ throw new Error("Missing API key. Run `qs login --key qk_…` or set QUICKSHOPS_SECRET_KEY.");
69
+ }
70
+ return createMerchantClient({
71
+ apiKey,
72
+ serverURL: resolveApiUrl(flags["api-url"]),
73
+ });
74
+ }
75
+ async function run() {
76
+ switch (`${command} ${sub ?? ""}`.trim()) {
77
+ case "login": {
78
+ if (!flags.key)
79
+ throw new Error("qs login requires --key qk_…");
80
+ writeConfig({ apiKey: flags.key, apiUrl: flags["api-url"] });
81
+ return "Saved credentials to local config.";
82
+ }
83
+ case "init": {
84
+ const { written, skipped } = runInit(process.cwd());
85
+ const lines = [];
86
+ if (written.length)
87
+ lines.push(`Wrote: ${written.join(", ")}`);
88
+ if (skipped.length)
89
+ lines.push(`Skipped: ${skipped.join(", ")}`);
90
+ if (!written.length && !skipped.length)
91
+ lines.push("Nothing to do.");
92
+ lines.push("Next: copy .env.example → .env.local when you have a qk_ key, or use mock mode as-is.");
93
+ return lines.join("\n");
94
+ }
95
+ case "whoami":
96
+ return client().getStoreSettings();
97
+ case "products list":
98
+ return client().listProducts({
99
+ includeInactive: flags["include-inactive"],
100
+ limit: int(flags.limit),
101
+ });
102
+ case "products create": {
103
+ const { name, price, "tax-code": taxCode } = flags;
104
+ if (!name || !price || !taxCode) {
105
+ throw new Error("products create requires --name --price --tax-code");
106
+ }
107
+ return client().createProduct({
108
+ type: flags.type === "physical" ? "physical" : "digital",
109
+ name,
110
+ priceInCents: Number(price),
111
+ taxCode,
112
+ downloadUrl: flags["download-url"],
113
+ description: flags.description,
114
+ sku: flags.sku,
115
+ });
116
+ }
117
+ case "products update":
118
+ return client().updateProduct(requireId("productId"), {
119
+ name: flags.name,
120
+ priceInCents: int(flags.price),
121
+ isActive: bool(flags.active),
122
+ description: flags.description,
123
+ taxCode: flags["tax-code"],
124
+ });
125
+ case "products delete":
126
+ return client().deleteProduct(requireId("productId"));
127
+ case "orders list":
128
+ return client().listOrders({ limit: int(flags.limit) });
129
+ case "orders get":
130
+ return client().getOrder(requireId("orderId"));
131
+ case "orders ship":
132
+ return client().markOrderShipped(requireId("orderId"), {
133
+ trackingNumber: flags.tracking,
134
+ carrier: flags.carrier,
135
+ });
136
+ case "orders refund":
137
+ return client().refundOrder(requireId("orderId"), {
138
+ lineItemIds: flags["line-item-id"],
139
+ restockInventory: bool(flags.restock),
140
+ });
141
+ default:
142
+ throw new Error(`Unknown command: ${positionals.join(" ")}. Run qs --help`);
143
+ }
144
+ }
145
+ if (!command || command === "help" || flags.help) {
146
+ console.log(HELP);
147
+ }
148
+ else {
149
+ run().then((result) => console.log(typeof result === "string" ? result : JSON.stringify(result, null, 2)), (error) => {
150
+ console.error(error.message);
151
+ process.exitCode = 1;
152
+ });
153
+ }
package/dist/init.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ export type InitResult = {
2
+ written: string[];
3
+ skipped: string[];
4
+ };
5
+ export declare function runInit(cwd?: string): InitResult;
package/dist/init.js ADDED
@@ -0,0 +1,364 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ function detectFramework(cwd) {
4
+ const pkgPath = path.join(cwd, "package.json");
5
+ if (!fs.existsSync(pkgPath))
6
+ return "unknown";
7
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
8
+ const deps = { ...pkg.dependencies, ...pkg.devDependencies };
9
+ if (deps["next"])
10
+ return "next";
11
+ if (deps["astro"])
12
+ return "astro";
13
+ if (deps["vite"])
14
+ return "vite";
15
+ return "unknown";
16
+ }
17
+ function ensurePackageScript(cwd, name, command, written, skipped) {
18
+ const pkgPath = path.join(cwd, "package.json");
19
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
20
+ pkg.scripts ??= {};
21
+ if (!pkg.scripts[name]) {
22
+ pkg.scripts[name] = command;
23
+ fs.writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}\n`);
24
+ written.push(`package.json scripts.${name}`);
25
+ }
26
+ else if (pkg.scripts[name] !== command) {
27
+ skipped.push(`package.json scripts.${name} (exists)`);
28
+ }
29
+ }
30
+ function ensureDevDependencies(cwd, deps, written, skipped) {
31
+ const pkgPath = path.join(cwd, "package.json");
32
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
33
+ pkg.devDependencies ??= {};
34
+ let changed = false;
35
+ for (const [name, version] of Object.entries(deps)) {
36
+ if (!pkg.devDependencies[name]) {
37
+ pkg.devDependencies[name] = version;
38
+ changed = true;
39
+ written.push(`package.json devDependencies.${name}`);
40
+ }
41
+ }
42
+ if (changed) {
43
+ fs.writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}\n`);
44
+ }
45
+ else {
46
+ skipped.push("package.json devDependencies (tailwind)");
47
+ }
48
+ }
49
+ function writeIfMissing(filePath, content, cwd, written, skipped) {
50
+ if (!fs.existsSync(filePath)) {
51
+ fs.mkdirSync(path.dirname(filePath), { recursive: true });
52
+ fs.writeFileSync(filePath, content);
53
+ written.push(path.relative(cwd, filePath));
54
+ }
55
+ else {
56
+ skipped.push(path.relative(cwd, filePath));
57
+ }
58
+ }
59
+ const TAILWIND_GLOBALS_NEXT = `@import "tailwindcss";
60
+
61
+ @source "../node_modules/@quickshops/sdk/esm/**/*.js";
62
+
63
+ @custom-variant dark (&:where(.dark, .dark *));
64
+
65
+ @layer base {
66
+ body {
67
+ @apply min-h-screen bg-white text-zinc-950 antialiased dark:bg-zinc-950 dark:text-zinc-50;
68
+ }
69
+ }
70
+ `;
71
+ const POSTCSS_CONFIG = `const config = {
72
+ plugins: {
73
+ "@tailwindcss/postcss": {},
74
+ },
75
+ };
76
+
77
+ export default config;
78
+ `;
79
+ const TAILWIND_GLOBALS_ASTRO = `@import "tailwindcss";
80
+
81
+ @source "../../node_modules/@quickshops/sdk/esm/**/*.js";
82
+
83
+ @custom-variant dark (&:where(.dark, .dark *));
84
+
85
+ @layer base {
86
+ body {
87
+ @apply min-h-screen bg-white p-6 text-zinc-950 antialiased dark:bg-zinc-950 dark:text-zinc-50;
88
+ }
89
+ }
90
+ `;
91
+ const ENV_EXAMPLE = `# Server only — never NEXT_PUBLIC_ for qk_ keys
92
+ QUICKSHOPS_SECRET_KEY=
93
+ # Browser-safe publishable key for static export / SSG checkout (pk_)
94
+ NEXT_PUBLIC_QUICKSHOPS_PUBLISHABLE_KEY=
95
+ SITE_URL=http://localhost:3000
96
+ # Optional: fixture catalog for local UI without keys
97
+ # QUICKSHOPS_MOCK=1
98
+ `;
99
+ const NEXT_STORE_SHOP = `"use client";
100
+
101
+ import type { StoreProduct } from "@quickshops/sdk";
102
+ import { ProductCatalog } from "@quickshops/sdk/react";
103
+
104
+ export function StoreShop({
105
+ products,
106
+ checkout,
107
+ }: {
108
+ products: StoreProduct[];
109
+ checkout?: string;
110
+ }) {
111
+ return (
112
+ <ProductCatalog
113
+ products={products}
114
+ locale="en-US"
115
+ {...(checkout ? { checkout } : {})}
116
+ />
117
+ );
118
+ }
119
+ `;
120
+ const NEXT_PAGE = `import { Quickshops } from "@quickshops/sdk";
121
+ import { StoreShop } from "./store-shop";
122
+
123
+ export default async function Page() {
124
+ const { products } = await new Quickshops().catalog.list();
125
+ return <StoreShop products={products} checkout="/api/buy" />;
126
+ }
127
+ `;
128
+ const NEXT_THANKS = `export default function ThanksPage() {
129
+ return <main><h1>Thanks</h1></main>;
130
+ }
131
+ `;
132
+ const NEXT_STATIC_BUILD = `#!/usr/bin/env node
133
+ import { spawnSync } from "node:child_process";
134
+
135
+ process.env.NEXT_OUTPUT = "export";
136
+ const r = spawnSync("next", ["build"], { stdio: "inherit", shell: true });
137
+ process.exit(r.status ?? 1);
138
+ `;
139
+ const ASTRO_BASE_LAYOUT = `---
140
+ import "../styles/global.css";
141
+
142
+ interface Props {
143
+ title?: string;
144
+ }
145
+
146
+ const { title = "Quickshops storefront" } = Astro.props;
147
+ ---
148
+ <!doctype html>
149
+ <html lang="en">
150
+ <head>
151
+ <meta charset="utf-8" />
152
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
153
+ <title>{title}</title>
154
+ </head>
155
+ <body>
156
+ <slot />
157
+ </body>
158
+ </html>
159
+ `;
160
+ const ASTRO_INDEX = `---
161
+ import { Quickshops } from "@quickshops/sdk";
162
+ import StoreShop from "../components/StoreShop";
163
+ import Base from "../layouts/Base.astro";
164
+
165
+ const { products } = await new Quickshops().catalog.list();
166
+ ---
167
+ <Base title="Quickshops storefront">
168
+ <h1 class="mb-6 text-2xl font-semibold tracking-tight">Quickshops storefront</h1>
169
+ <StoreShop client:load products={products} checkout="/api/buy" />
170
+ </Base>
171
+ `;
172
+ const ASTRO_THANKS = `---
173
+ ---
174
+ <html lang="en">
175
+ <body>
176
+ <main><h1>Thanks</h1></main>
177
+ </body>
178
+ </html>
179
+ `;
180
+ const ASTRO_STORE_SHOP = `"use client";
181
+ import type { StoreProduct } from "@quickshops/sdk";
182
+ import { ProductCatalog } from "@quickshops/sdk/react";
183
+
184
+ export default function StoreShop({
185
+ products,
186
+ checkout,
187
+ }: {
188
+ products: StoreProduct[];
189
+ checkout?: string;
190
+ }) {
191
+ return (
192
+ <ProductCatalog
193
+ products={products}
194
+ locale="en-US"
195
+ {...(checkout ? { checkout } : {})}
196
+ />
197
+ );
198
+ }
199
+ `;
200
+ const ASTRO_CONFIG_STATIC = `import { defineConfig } from "astro/config";
201
+ import react from "@astrojs/react";
202
+
203
+ /** Static export for CDN hosting — use \`npm run build:static\` */
204
+ export default defineConfig({
205
+ output: "static",
206
+ integrations: [react()],
207
+ });
208
+ `;
209
+ const VITE_APP = `import type { StoreProduct } from "@quickshops/sdk";
210
+ import { ProductCatalog } from "@quickshops/sdk/react";
211
+
212
+ const demoProducts: StoreProduct[] = [
213
+ {
214
+ id: "prod_fixture_1",
215
+ name: "Starter Pack",
216
+ description: "Demo product",
217
+ priceInCents: 1900,
218
+ currency: "usd",
219
+ imageUrl: "https://placehold.co/400x400/png",
220
+ },
221
+ ];
222
+
223
+ export default function App() {
224
+ const path =
225
+ typeof window !== "undefined" ? window.location.pathname : "/";
226
+
227
+ if (path.startsWith("/thanks")) {
228
+ return (
229
+ <main>
230
+ <h1>Thanks</h1>
231
+ </main>
232
+ );
233
+ }
234
+
235
+ const products = demoProducts;
236
+ return (
237
+ <main>
238
+ <h1>Vite storefront</h1>
239
+ <ProductCatalog
240
+ products={products}
241
+ locale="en-US"
242
+ onBuy={async (productId) => {
243
+ window.location.assign(
244
+ \`/thanks?product=\${encodeURIComponent(productId)}\`,
245
+ );
246
+ }}
247
+ />
248
+ </main>
249
+ );
250
+ }
251
+ `;
252
+ function patchNextConfigForStaticExport(cwd, written, skipped) {
253
+ const candidates = ["next.config.ts", "next.config.mjs", "next.config.js"];
254
+ const found = candidates
255
+ .map((f) => path.join(cwd, f))
256
+ .find((p) => fs.existsSync(p));
257
+ if (!found) {
258
+ skipped.push("next.config (not found)");
259
+ return;
260
+ }
261
+ let text = fs.readFileSync(found, "utf8");
262
+ if (text.includes("NEXT_OUTPUT") || /\boutput:\s*["']export["']/.test(text)) {
263
+ skipped.push(`${path.relative(cwd, found)} (export already configured)`);
264
+ return;
265
+ }
266
+ let patched = text.replace(/(const nextConfig[^=]*=\s*\{)/, `$1\n output: process.env.NEXT_OUTPUT === "export" ? "export" : undefined,`);
267
+ patched = patched.replace(/cacheComponents:\s*true/, 'cacheComponents: process.env.NEXT_OUTPUT === "export" ? false : true');
268
+ patched = patched.replace(/partialPrefetching:\s*true/, 'partialPrefetching: process.env.NEXT_OUTPUT === "export" ? false : true');
269
+ if (patched === text) {
270
+ skipped.push(`${path.relative(cwd, found)} (could not patch — set output: 'export' manually)`);
271
+ return;
272
+ }
273
+ fs.writeFileSync(found, patched);
274
+ written.push(`${path.relative(cwd, found)} (NEXT_OUTPUT export)`);
275
+ }
276
+ export function runInit(cwd = process.cwd()) {
277
+ const framework = detectFramework(cwd);
278
+ if (framework === "unknown") {
279
+ throw new Error("Could not detect Next.js, Astro, or Vite. Run qs init from your app root after npm install.");
280
+ }
281
+ const skipped = [];
282
+ const written = [];
283
+ const envPath = path.join(cwd, ".env.example");
284
+ if (!fs.existsSync(envPath)) {
285
+ fs.writeFileSync(envPath, ENV_EXAMPLE);
286
+ written.push(".env.example");
287
+ }
288
+ else {
289
+ skipped.push(".env.example (exists)");
290
+ }
291
+ if (fs.existsSync(path.join(cwd, ".env")) ||
292
+ fs.existsSync(path.join(cwd, ".env.local"))) {
293
+ skipped.push(".env / .env.local (never touched)");
294
+ }
295
+ if (framework === "next") {
296
+ const appDir = fs.existsSync(path.join(cwd, "app"))
297
+ ? path.join(cwd, "app")
298
+ : path.join(cwd, "src/app");
299
+ if (!fs.existsSync(appDir)) {
300
+ throw new Error("Next.js app/ or src/app/ not found.");
301
+ }
302
+ writeIfMissing(path.join(appDir, "store-shop.tsx"), NEXT_STORE_SHOP, cwd, written, skipped);
303
+ writeIfMissing(path.join(appDir, "page.tsx"), NEXT_PAGE, cwd, written, skipped);
304
+ writeIfMissing(path.join(appDir, "thanks", "page.tsx"), NEXT_THANKS, cwd, written, skipped);
305
+ const staticScript = path.join(cwd, "scripts/qs-next-static-build.mjs");
306
+ writeIfMissing(staticScript, NEXT_STATIC_BUILD, cwd, written, skipped);
307
+ ensurePackageScript(cwd, "build:static", "node scripts/qs-next-static-build.mjs", written, skipped);
308
+ patchNextConfigForStaticExport(cwd, written, skipped);
309
+ const globalsPath = fs.existsSync(path.join(appDir, "globals.css"))
310
+ ? path.join(appDir, "globals.css")
311
+ : path.join(cwd, "app/globals.css");
312
+ writeIfMissing(globalsPath, TAILWIND_GLOBALS_NEXT, cwd, written, skipped);
313
+ writeIfMissing(path.join(cwd, "postcss.config.mjs"), POSTCSS_CONFIG, cwd, written, skipped);
314
+ ensureDevDependencies(cwd, {
315
+ "@tailwindcss/postcss": "^4.3.5",
316
+ tailwindcss: "^4.3.5",
317
+ }, written, skipped);
318
+ }
319
+ if (framework === "astro") {
320
+ const src = path.join(cwd, "src");
321
+ writeIfMissing(path.join(src, "components", "StoreShop.tsx"), ASTRO_STORE_SHOP, cwd, written, skipped);
322
+ writeIfMissing(path.join(src, "pages", "index.astro"), ASTRO_INDEX, cwd, written, skipped);
323
+ writeIfMissing(path.join(src, "pages", "thanks.astro"), ASTRO_THANKS, cwd, written, skipped);
324
+ writeIfMissing(path.join(cwd, "astro.config.static.mjs"), ASTRO_CONFIG_STATIC, cwd, written, skipped);
325
+ ensurePackageScript(cwd, "build:static", "astro build --config astro.config.static.mjs", written, skipped);
326
+ const pkgPath = path.join(cwd, "package.json");
327
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
328
+ const deps = { ...pkg.dependencies, ...pkg.devDependencies };
329
+ if (!deps["@astrojs/react"]) {
330
+ console.error("Astro: run `npx astro add react --yes` before dev/build if you have not already.");
331
+ }
332
+ writeIfMissing(path.join(src, "layouts", "Base.astro"), ASTRO_BASE_LAYOUT, cwd, written, skipped);
333
+ writeIfMissing(path.join(src, "styles", "global.css"), TAILWIND_GLOBALS_ASTRO, cwd, written, skipped);
334
+ ensureDevDependencies(cwd, {
335
+ "@tailwindcss/vite": "^4.3.5",
336
+ tailwindcss: "^4.3.5",
337
+ }, written, skipped);
338
+ console.error("Astro: add `import tailwindcss from \"@tailwindcss/vite\"` and `vite: { plugins: [tailwindcss()] }` to astro.config.mjs if not present.");
339
+ }
340
+ if (framework === "vite") {
341
+ const viteDoc = path.join(cwd, "QUICKSHOPS-VITE.md");
342
+ if (!fs.existsSync(viteDoc)) {
343
+ fs.writeFileSync(viteDoc, `# Quickshops on Vite
344
+
345
+ Client-only: inline demo products + \`ProductCatalog\` (demo buy → /thanks).
346
+
347
+ Vite preview serves SPA fallback on /thanks. Real checkout needs a BFF or publishable API.
348
+ `);
349
+ written.push("QUICKSHOPS-VITE.md");
350
+ }
351
+ const mainTsx = path.join(cwd, "src/main.tsx");
352
+ if (fs.existsSync(mainTsx)) {
353
+ const main = fs.readFileSync(mainTsx, "utf8");
354
+ if (!main.includes("App.tsx") && main.includes("./App")) {
355
+ // default vite template — ok
356
+ }
357
+ }
358
+ writeIfMissing(path.join(cwd, "src/App.tsx"), VITE_APP, cwd, written, skipped);
359
+ }
360
+ if (skipped.length) {
361
+ console.error(`Skipped (already exists): ${skipped.join(", ")}`);
362
+ }
363
+ return { written, skipped };
364
+ }
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Internal Headless API client for `qs` (products, orders). Not part of @quickshops/sdk.
3
+ */
4
+ export type CreateMerchantClientOptions = {
5
+ apiKey?: string;
6
+ serverURL?: string;
7
+ env?: Record<string, string | undefined>;
8
+ };
9
+ type ProductFields = {
10
+ description?: string;
11
+ imageUrl?: string;
12
+ imageKey?: string;
13
+ isActive?: boolean;
14
+ downloadUrl?: string;
15
+ fileStorageKey?: string;
16
+ fileName?: string;
17
+ fileSizeBytes?: number;
18
+ fileContentType?: string;
19
+ fileSize?: string;
20
+ sku?: string;
21
+ trackInventory?: boolean;
22
+ quantityOnHand?: number;
23
+ requiresShipping?: boolean;
24
+ category?: string;
25
+ tags?: string[];
26
+ };
27
+ export type CreateProductInput = ProductFields & {
28
+ type: "digital" | "physical";
29
+ name: string;
30
+ priceInCents: number;
31
+ taxCode: string;
32
+ seoTitle?: string;
33
+ seoDescription?: string;
34
+ };
35
+ export type UpdateProductInput = ProductFields & {
36
+ name?: string;
37
+ priceInCents?: number;
38
+ taxCode?: string;
39
+ };
40
+ export type RefundResult = {
41
+ orderId: string;
42
+ refundId: string;
43
+ amountInCents: number;
44
+ restockInventory: boolean;
45
+ lineItemIds?: string[];
46
+ };
47
+ export declare function createMerchantClient(options?: CreateMerchantClientOptions): {
48
+ getStoreSettings: () => Promise<{
49
+ storeId: string;
50
+ name: string;
51
+ description: string | null;
52
+ }>;
53
+ listProducts: ({ includeInactive, limit }?: {
54
+ includeInactive?: boolean | undefined;
55
+ limit?: number | undefined;
56
+ }) => Promise<unknown[]>;
57
+ createProduct: (input: CreateProductInput) => Promise<{
58
+ productId: string;
59
+ stripeProductId: string;
60
+ stripePriceId: string;
61
+ }>;
62
+ updateProduct: (productId: string, input: UpdateProductInput) => Promise<{
63
+ productId: string;
64
+ updated: true;
65
+ }>;
66
+ deleteProduct: (productId: string) => Promise<{
67
+ productId: string;
68
+ deleted: true;
69
+ }>;
70
+ listOrders: ({ limit }?: {
71
+ limit?: number | undefined;
72
+ }) => Promise<unknown[]>;
73
+ getOrder: (orderId: string) => Promise<unknown>;
74
+ markOrderShipped: (orderId: string, input?: {
75
+ trackingNumber?: string | undefined;
76
+ carrier?: string | undefined;
77
+ }) => Promise<{
78
+ orderId: string;
79
+ shipped: true;
80
+ }>;
81
+ refundOrder: (orderId: string, input?: {
82
+ lineItemIds?: string[] | undefined;
83
+ restockInventory?: boolean | undefined;
84
+ }) => Promise<RefundResult>;
85
+ };
86
+ export type MerchantClient = ReturnType<typeof createMerchantClient>;
87
+ export {};
@@ -0,0 +1,57 @@
1
+ import { QuickshopsError } from "@quickshops/sdk";
2
+ function missingSecretKeyMessage() {
3
+ return "Set QUICKSHOPS_SECRET_KEY (secret key, qk_…), or run `qs login --key qk_…`.";
4
+ }
5
+ function assertSecretKeyForCli(key) {
6
+ if (key.startsWith("pk_")) {
7
+ throw new Error("Publishable keys (pk_) cannot call merchant endpoints. Use a secret key (qk_).");
8
+ }
9
+ if (!key.startsWith("qk_")) {
10
+ throw new Error("API key must be a secret key with prefix qk_.");
11
+ }
12
+ }
13
+ export function createMerchantClient(options = {}) {
14
+ const env = options.env ?? process.env;
15
+ const apiKey = options.apiKey ?? env["QUICKSHOPS_SECRET_KEY"];
16
+ const serverURL = (options.serverURL ??
17
+ env["HEADLESS_API_URL"] ??
18
+ env["QUICKSHOPS_API_URL"] ??
19
+ "https://api.quickshops.app").replace(/\/$/, "");
20
+ if (!apiKey?.trim()) {
21
+ throw new Error(missingSecretKeyMessage());
22
+ }
23
+ assertSecretKeyForCli(apiKey.trim());
24
+ async function request(method, path, body) {
25
+ const response = await fetch(`${serverURL}/v1${path}`, {
26
+ method,
27
+ headers: {
28
+ Authorization: `Bearer ${apiKey}`,
29
+ "Content-Type": "application/json",
30
+ },
31
+ ...(body && { body: JSON.stringify(body) }),
32
+ });
33
+ const json = (await response.json().catch(() => ({})));
34
+ if (!response.ok) {
35
+ throw new QuickshopsError(json.error ?? `HTTP ${response.status}`, {
36
+ statusCode: response.status,
37
+ ...(json.code !== undefined ? { code: json.code } : {}),
38
+ });
39
+ }
40
+ return json.data;
41
+ }
42
+ const id = encodeURIComponent;
43
+ return {
44
+ getStoreSettings: () => request("GET", "/store/settings"),
45
+ listProducts: ({ includeInactive = false, limit = 20 } = {}) => request("GET", `/products?${new URLSearchParams({
46
+ includeInactive: String(includeInactive),
47
+ limit: String(limit),
48
+ })}`),
49
+ createProduct: (input) => request("POST", "/products", input),
50
+ updateProduct: (productId, input) => request("PATCH", `/products/${id(productId)}`, input),
51
+ deleteProduct: (productId) => request("DELETE", `/products/${id(productId)}`),
52
+ listOrders: ({ limit = 10 } = {}) => request("GET", `/orders?limit=${limit}`),
53
+ getOrder: (orderId) => request("GET", `/orders/${id(orderId)}`),
54
+ markOrderShipped: (orderId, input = {}) => request("POST", `/orders/${id(orderId)}/ship`, input),
55
+ refundOrder: (orderId, input = {}) => request("POST", `/orders/${id(orderId)}/refund`, input),
56
+ };
57
+ }
package/package.json CHANGED
@@ -1,6 +1,37 @@
1
- {
2
- "name": "@quickshops/cli",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
1
+ {
2
+ "name": "@quickshops/cli",
3
+ "version": "2.0.0",
4
+ "description": "qs: command-line client for the Quickshops Headless API",
5
+ "license": "UNLICENSED",
6
+ "type": "module",
7
+ "bin": {
8
+ "qs": "./dist/index.js"
9
+ },
10
+ "files": [
11
+ "dist"
12
+ ],
13
+ "scripts": {
14
+ "dev": "tsx src/index.ts",
15
+ "build": "tsgo",
16
+ "start": "node dist/index.js",
17
+ "typecheck": "tsgo --noEmit",
18
+ "test": "node --import tsx --test tests/**/*.test.ts",
19
+ "lint": "echo \"lint not configured for @quickshops/cli\"",
20
+ "prepublishOnly": "pnpm run build"
21
+ },
22
+ "dependencies": {
23
+ "@quickshops/sdk": "workspace:*"
24
+ },
25
+ "devDependencies": {
26
+ "@types/node": "^22.20.5",
27
+ "@typescript/native-preview": "7.0.0-dev.20260302.1",
28
+ "tsx": "^4.23.15",
29
+ "typescript": "~5.8.3"
30
+ },
31
+ "engines": {
32
+ "node": ">=20"
33
+ },
34
+ "publishConfig": {
35
+ "access": "public"
36
+ }
37
+ }