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
4 changes: 2 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ Do not introduce additional credential storage paths without an explicit require

Generated API commands enforce two protections:

- **Write gate:** Write operations on live sites require confirmation: an interactive yes/no prompt, or `-y/--yes`. Without a terminal (or on a CI runner, or in `--json` mode) and without `--yes`, the write is refused with exit code 6. Test sites, reads, and non-mutating POSTs (estimates, exports, hosted-page URLs, PDF downloads) never prompt.
- **Write gate:** Write operations on live sites require confirmation: an interactive yes/no prompt, or `--allow-write`. Without a terminal (or on a CI runner, or in `--json` mode) and without `--allow-write`, the write is refused with exit code 6. Test sites, reads, and non-mutating POSTs (estimates, exports, hosted-page URLs, PDF downloads) never prompt.
- **Catalog gate:** Product Catalog-specific operations are blocked when they do not match the configured site's catalog version.

For `--code-sample`, the **write gate does not apply** because no API request is executed. The **catalog gate still applies** so generated code matches the site's Product Catalog version.
Expand Down Expand Up @@ -146,7 +146,7 @@ Run live tests with:
bun run test:live
```

Never permit successful writes on live Chargebee sites in automated tests, and never pass `--yes` to a live-site write in live tests. Live-site customer-create tests must assert the CLI write gate refuses the unconfirmed operation; use a dedicated validation site and read-only key. Successful remote writes are limited to customer creation and cleanup deletion on test sites.
Never permit successful writes on live Chargebee sites in automated tests, and never pass `--allow-write` to a live-site write in live tests. Live-site customer-create tests must assert the CLI write gate refuses the unconfirmed operation; use a dedicated validation site and read-only key. Successful remote writes are limited to customer creation and cleanup deletion on test sites.

Shared test helpers belong in `src/lib/test-support/` and must never be imported by production entry points or commands.

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export CHARGEBEE_API_KEY=test_xxxxxxxxxxxx

Create API keys from **Settings → Configure Chargebee → API Keys** in the Chargebee Dashboard.

> Write operations on live sites ask for confirmation before they run. In scripts, CI, or `--json` mode, add `--yes` to confirm; without it the command exits with code `6`. Use a test site when building or testing integrations.
> Write operations on live sites ask for confirmation before they run. In scripts, CI, or `--json` mode, add `--allow-write` to confirm; without it the command exits with code `6`. Use a test site when building or testing integrations.

## Quick Example

Expand Down
4 changes: 2 additions & 2 deletions src/commands/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,8 @@ ${sectionTitle("EXAMPLES")}
chargebee auth add Connect a site interactively
chargebee auth add --profile staging Save credentials as staging

Writes on live sites ask for confirmation (or need --yes): a site whose name
doesn't end in -test, unless its API key starts with test_. Prefer
Writes on live sites ask for confirmation (or need --allow-write): a site
whose name doesn't end in -test, unless its API key starts with test_. Prefer
CHARGEBEE_API_KEY over --api-key so the secret is not stored in shell history.

--region (${REGIONS.join(" | ")}) records where the site is hosted and is used to
Expand Down
35 changes: 20 additions & 15 deletions src/commands/generated/addon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ export function registerAddon(parent: Command): void {
.option("-d, --data <pairs...>", "Request parameters in key=value format; repeat for multiple fields")
.option("-s, --code-sample <lang>", "Generate code sample (curl, python, nodejs, go, ruby, java, php, dotnet, list)")
.addOption(new Option("--pc-version <version>", "Product catalog version for the code sample (v1 or v2)").hideHelp())
.option("-y, --yes", "Skip the confirmation prompt for writes on a live site")
.option("--allow-write", "Allow this write on a live site without a confirmation prompt")
.addOption(new Option("-y, --yes", "Deprecated alias for --allow-write").hideHelp())
.addHelpText("after", "\n\u001b[1mDOCUMENTATION\u001b[0m\n chargebee docs addon copy\n")
.action(async (json: string | undefined, opts: { data?: string[]; codeSample?: string; pcVersion?: string; yes?: boolean }, command: Command) => {
.action(async (json: string | undefined, opts: { data?: string[]; codeSample?: string; pcVersion?: string; allowWrite?: boolean; yes?: boolean }, command: Command) => {
const fromStdin = readJsonMarker(json, command);
const params = await loadOperationParams(opts.data ?? [], fromStdin, command, { method: "POST", jsonInput: false, opIdV2: "", opIdV1: "copy_an_addon", pcVersionFlag: opts.pcVersion });
if (opts.codeSample !== "list") await ensureCatalogAllowed("pc1", "addon copy");
if (opts.codeSample) return handleCodeSample({ lang: opts.codeSample, opIdV2: "", opIdV1: "copy_an_addon", method: "POST", uri: "/addons/copy", dataFlags: opts.data ?? [], params, pcVersionFlag: opts.pcVersion });
await ensureWriteAllowed("POST", "addon copy", opts.yes === true);
await ensureWriteAllowed("POST", "addon copy", opts);
try {
const client = await getClient();
const result = await (client as any).addon.copy(params);
Expand All @@ -45,14 +46,15 @@ export function registerAddon(parent: Command): void {
.option("-d, --data <pairs...>", "Request parameters in key=value format; repeat for multiple fields")
.option("-s, --code-sample <lang>", "Generate code sample (curl, python, nodejs, go, ruby, java, php, dotnet, list)")
.addOption(new Option("--pc-version <version>", "Product catalog version for the code sample (v1 or v2)").hideHelp())
.option("-y, --yes", "Skip the confirmation prompt for writes on a live site")
.option("--allow-write", "Allow this write on a live site without a confirmation prompt")
.addOption(new Option("-y, --yes", "Deprecated alias for --allow-write").hideHelp())
.addHelpText("after", "\n\u001b[1mDOCUMENTATION\u001b[0m\n chargebee docs addon create\n")
.action(async (json: string | undefined, opts: { data?: string[]; codeSample?: string; pcVersion?: string; yes?: boolean }, command: Command) => {
.action(async (json: string | undefined, opts: { data?: string[]; codeSample?: string; pcVersion?: string; allowWrite?: boolean; yes?: boolean }, command: Command) => {
const fromStdin = readJsonMarker(json, command);
const params = await loadOperationParams(opts.data ?? [], fromStdin, command, { method: "POST", jsonInput: false, opIdV2: "", opIdV1: "create_an_addon", pcVersionFlag: opts.pcVersion });
if (opts.codeSample !== "list") await ensureCatalogAllowed("pc1", "addon create");
if (opts.codeSample) return handleCodeSample({ lang: opts.codeSample, opIdV2: "", opIdV1: "create_an_addon", method: "POST", uri: "/addons", dataFlags: opts.data ?? [], params, pcVersionFlag: opts.pcVersion });
await ensureWriteAllowed("POST", "addon create", opts.yes === true);
await ensureWriteAllowed("POST", "addon create", opts);
try {
const client = await getClient();
const result = await (client as any).addon.create(params);
Expand All @@ -68,16 +70,17 @@ export function registerAddon(parent: Command): void {
.option("-d, --data <pairs...>", "Request parameters in key=value format; repeat for multiple fields")
.option("-s, --code-sample <lang>", "Generate code sample (curl, python, nodejs, go, ruby, java, php, dotnet, list)")
.addOption(new Option("--pc-version <version>", "Product catalog version for the code sample (v1 or v2)").hideHelp())
.option("-y, --yes", "Skip the confirmation prompt for writes on a live site")
.option("--allow-write", "Allow this write on a live site without a confirmation prompt")
.addOption(new Option("-y, --yes", "Deprecated alias for --allow-write").hideHelp())
.addHelpText("after", "\n\u001b[1mDOCUMENTATION\u001b[0m\n chargebee docs addon delete\n")
.action(async (id: string | undefined, json: string | undefined, opts: { data?: string[]; codeSample?: string; pcVersion?: string; yes?: boolean }, command: Command) => {
.action(async (id: string | undefined, json: string | undefined, opts: { data?: string[]; codeSample?: string; pcVersion?: string; allowWrite?: boolean; yes?: boolean }, command: Command) => {
const resource = takeResourceId(id, json, command);
const params = await loadOperationParams(opts.data ?? [], resource.fromStdin, command, { method: "POST", jsonInput: false, opIdV2: "", opIdV1: "delete_an_addon", pcVersionFlag: opts.pcVersion });
if (opts.codeSample !== "list") await ensureCatalogAllowed("pc1", "addon delete");
if (opts.codeSample) return handleCodeSample({ lang: opts.codeSample, opIdV2: "", opIdV1: "delete_an_addon", method: "POST", uri: "/addons/{id}/delete", dataFlags: opts.data ?? [], params, resourceId: resource.id, pathParamName: "addon-id", pcVersionFlag: opts.pcVersion });
if (!resource.id) command.error("error: missing required argument 'addon-id'");
assertResourceId(resource.id, command);
await ensureWriteAllowed("POST", "addon delete", opts.yes === true);
await ensureWriteAllowed("POST", "addon delete", opts);
try {
const client = await getClient();
const result = await (client as any).addon.delete(resource.id, params);
Expand Down Expand Up @@ -139,16 +142,17 @@ export function registerAddon(parent: Command): void {
.option("-d, --data <pairs...>", "Request parameters in key=value format; repeat for multiple fields")
.option("-s, --code-sample <lang>", "Generate code sample (curl, python, nodejs, go, ruby, java, php, dotnet, list)")
.addOption(new Option("--pc-version <version>", "Product catalog version for the code sample (v1 or v2)").hideHelp())
.option("-y, --yes", "Skip the confirmation prompt for writes on a live site")
.option("--allow-write", "Allow this write on a live site without a confirmation prompt")
.addOption(new Option("-y, --yes", "Deprecated alias for --allow-write").hideHelp())
.addHelpText("after", "\n\u001b[1mDOCUMENTATION\u001b[0m\n chargebee docs addon unarchive\n")
.action(async (id: string | undefined, json: string | undefined, opts: { data?: string[]; codeSample?: string; pcVersion?: string; yes?: boolean }, command: Command) => {
.action(async (id: string | undefined, json: string | undefined, opts: { data?: string[]; codeSample?: string; pcVersion?: string; allowWrite?: boolean; yes?: boolean }, command: Command) => {
const resource = takeResourceId(id, json, command);
const params = await loadOperationParams(opts.data ?? [], resource.fromStdin, command, { method: "POST", jsonInput: false, opIdV2: "", opIdV1: "unarchive_an_addon", pcVersionFlag: opts.pcVersion });
if (opts.codeSample !== "list") await ensureCatalogAllowed("pc1", "addon unarchive");
if (opts.codeSample) return handleCodeSample({ lang: opts.codeSample, opIdV2: "", opIdV1: "unarchive_an_addon", method: "POST", uri: "/addons/{id}/unarchive", dataFlags: opts.data ?? [], params, resourceId: resource.id, pathParamName: "addon-id", pcVersionFlag: opts.pcVersion });
if (!resource.id) command.error("error: missing required argument 'addon-id'");
assertResourceId(resource.id, command);
await ensureWriteAllowed("POST", "addon unarchive", opts.yes === true);
await ensureWriteAllowed("POST", "addon unarchive", opts);
try {
const client = await getClient();
const result = await (client as any).addon.unarchive(resource.id, params);
Expand All @@ -164,16 +168,17 @@ export function registerAddon(parent: Command): void {
.option("-d, --data <pairs...>", "Request parameters in key=value format; repeat for multiple fields")
.option("-s, --code-sample <lang>", "Generate code sample (curl, python, nodejs, go, ruby, java, php, dotnet, list)")
.addOption(new Option("--pc-version <version>", "Product catalog version for the code sample (v1 or v2)").hideHelp())
.option("-y, --yes", "Skip the confirmation prompt for writes on a live site")
.option("--allow-write", "Allow this write on a live site without a confirmation prompt")
.addOption(new Option("-y, --yes", "Deprecated alias for --allow-write").hideHelp())
.addHelpText("after", "\n\u001b[1mDOCUMENTATION\u001b[0m\n chargebee docs addon update\n")
.action(async (id: string | undefined, json: string | undefined, opts: { data?: string[]; codeSample?: string; pcVersion?: string; yes?: boolean }, command: Command) => {
.action(async (id: string | undefined, json: string | undefined, opts: { data?: string[]; codeSample?: string; pcVersion?: string; allowWrite?: boolean; yes?: boolean }, command: Command) => {
const resource = takeResourceId(id, json, command);
const params = await loadOperationParams(opts.data ?? [], resource.fromStdin, command, { method: "POST", jsonInput: false, opIdV2: "", opIdV1: "update_an_addon", pcVersionFlag: opts.pcVersion });
if (opts.codeSample !== "list") await ensureCatalogAllowed("pc1", "addon update");
if (opts.codeSample) return handleCodeSample({ lang: opts.codeSample, opIdV2: "", opIdV1: "update_an_addon", method: "POST", uri: "/addons/{id}", dataFlags: opts.data ?? [], params, resourceId: resource.id, pathParamName: "addon-id", pcVersionFlag: opts.pcVersion });
if (!resource.id) command.error("error: missing required argument 'addon-id'");
assertResourceId(resource.id, command);
await ensureWriteAllowed("POST", "addon update", opts.yes === true);
await ensureWriteAllowed("POST", "addon update", opts);
try {
const client = await getClient();
const result = await (client as any).addon.update(resource.id, params);
Expand Down
7 changes: 4 additions & 3 deletions src/commands/generated/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,14 @@ export function registerAddress(parent: Command): void {
.option("-d, --data <pairs...>", "Request parameters in key=value format; repeat for multiple fields")
.option("-s, --code-sample <lang>", "Generate code sample (curl, python, nodejs, go, ruby, java, php, dotnet, list)")
.addOption(new Option("--pc-version <version>", "Product catalog version for the code sample (v1 or v2)").hideHelp())
.option("-y, --yes", "Skip the confirmation prompt for writes on a live site")
.option("--allow-write", "Allow this write on a live site without a confirmation prompt")
.addOption(new Option("-y, --yes", "Deprecated alias for --allow-write").hideHelp())
.addHelpText("after", "\n\u001b[1mDOCUMENTATION\u001b[0m\n chargebee docs address update\n")
.action(async (json: string | undefined, opts: { data?: string[]; codeSample?: string; pcVersion?: string; yes?: boolean }, command: Command) => {
.action(async (json: string | undefined, opts: { data?: string[]; codeSample?: string; pcVersion?: string; allowWrite?: boolean; yes?: boolean }, command: Command) => {
const fromStdin = readJsonMarker(json, command);
const params = await loadOperationParams(opts.data ?? [], fromStdin, command, { method: "POST", jsonInput: false, opIdV2: "update_an_address", opIdV1: "update_an_address", pcVersionFlag: opts.pcVersion });
if (opts.codeSample) return handleCodeSample({ lang: opts.codeSample, opIdV2: "update_an_address", opIdV1: "update_an_address", method: "POST", uri: "/addresses", dataFlags: opts.data ?? [], params, pcVersionFlag: opts.pcVersion });
await ensureWriteAllowed("POST", "address update", opts.yes === true);
await ensureWriteAllowed("POST", "address update", opts);
try {
const client = await getClient();
const result = await (client as any).address.update(params);
Expand Down
Loading
Loading