Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 2 additions & 18 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"type": "module",
"scripts": {
"generate": "umbra --openapi kronan-openapi.yaml --out generated/spec.ts --strip-prefix /api/v1",
"generate:docs": "umbra docs --openapi kronan-openapi.yaml --out COMMANDS.md --name kronan --strip-prefix /api/v1",
"docs": "umbra docs --openapi kronan-openapi.yaml --out COMMANDS.md --name kronan --strip-prefix /api/v1",
"prebuild": "bun run generate",
"build": "bun build --compile --sourcemap --define \"KRONAN_CLI_VERSION='$(jq -r .version package.json)'\" ./src/index.ts --outfile ${OUTFILE:-dist/kronan} ${TARGET:+--target=$TARGET}",
"typecheck": "bunx tsgo",
Expand All @@ -20,9 +20,7 @@
"install-local": "bun run build && mkdir -p ~/.local/bin && mv dist/kronan ~/.local/bin/kronan"
},
"dependencies": {
"@clack/prompts": "^1.2.0",
"@ihs7/umbra": "^0.5.0",
"commander": "^14.0.3",
"@ihs7/umbra": "^0.6.1",
"yaml": "^2.8.3",
"zod": "^4.3.6"
},
Expand Down
9 changes: 6 additions & 3 deletions src/commands/checkout.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,20 @@ describe("checkoutCommand", () => {
const cmd = checkoutCommand();
const params = cmd.actions.add!.params!;
expect(params).toHaveLength(2);
const skuParam = params.find((p) => p.name === "sku");
const quantityParam = params.find((p) => p.name === "quantity");
const skuParam = params.find((p: { name: string }) => p.name === "sku");
const quantityParam = params.find((p: { name: string }) => p.name === "quantity");
expect(skuParam?.required).toBe(true);
expect(skuParam?.positional).toBe(true);
expect(quantityParam?.required).toBe(false);
expect(quantityParam?.default).toBe(1);
});

test("remove action has correct params", () => {
const cmd = checkoutCommand();
const params = cmd.actions.remove!.params!;
expect(params).toHaveLength(1);
const skuParam = params.find((p) => p.name === "sku");
const skuParam = params.find((p: { name: string }) => p.name === "sku");
expect(skuParam?.required).toBe(true);
expect(skuParam?.positional).toBe(true);
});
});
21 changes: 9 additions & 12 deletions src/commands/checkout.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { checkout_lines_create, checkout_list } from "../../generated/spec";
import type { CliResource } from "@ihs7/umbra";
import type { CliCommandEntry } from "@ihs7/umbra";

export function checkoutCommand(): CliResource {
export function checkoutCommand(): CliCommandEntry {
return {
name: "checkout",
actions: {
Expand All @@ -13,23 +13,22 @@ export function checkoutCommand(): CliResource {
location: "body",
kind: "string",
required: true,
positional: true,
description: "Product SKU",
},
{
name: "quantity",
location: "body",
kind: "number",
required: false,
description: "Quantity to add (default: 1)",
default: 1,
description: "Quantity to add",
},
],
handler: async (args) => {
const body = args.body as { sku: string; quantity?: number };
const { sku, quantity } = args.body as { sku: string; quantity: number };
return checkout_lines_create.handler({
body: {
lines: [{ sku: body.sku, quantity: body.quantity ?? 1 }],
replace: false,
},
body: { lines: [{ sku, quantity }], replace: false },
});
},
},
Expand All @@ -41,6 +40,7 @@ export function checkoutCommand(): CliResource {
location: "body",
kind: "string",
required: true,
positional: true,
description: "Product SKU",
},
],
Expand All @@ -52,11 +52,8 @@ export function checkoutCommand(): CliResource {
const lines = (checkout.lines ?? []).map((l) => ({
sku: l.product.sku,
quantity: l.product.sku === sku ? 0 : l.quantity,
source: "checkout",
}));
return checkout_lines_create.handler({
body: { lines, force: false },
});
return checkout_lines_create.handler({ body: { lines, force: false } });
},
},
},
Expand Down
14 changes: 5 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,14 @@ declare const KRONAN_CLI_VERSION: string;
const version = typeof KRONAN_CLI_VERSION !== "undefined" ? KRONAN_CLI_VERSION : "dev";

const baseUrl = process.env.KRONAN_API_BASE_URL;
if (baseUrl) {
configure({ baseUrl });
}

const auth = {
keychain: "kronan-cli",
header: (token: string) => ({ Authorization: `AccessToken ${token}` }),
};
if (baseUrl) configure({ baseUrl });

await createCli({
name: "kronan",
version,
auth,
auth: {
keychain: "kronan-cli",
header: (token) => ({ Authorization: `AccessToken ${token}` }),
},
commands: [checkoutCommand()],
}).run();