ckweb-cli 0.7.0 → 0.8.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
@@ -127,7 +127,7 @@ Payout profile note: current `claudekit-web` payout profile endpoints are browse
127
127
  | `admin invites` | list, create, get, delete, resend, accept, validate |
128
128
  | `admin admins` | list, get, promote, demote, permissions |
129
129
  | `admin discounts` | list, create, update, delete, sync-status, export |
130
- | `admin discount-groups` | list, get, create, update, delete |
130
+ | `admin discount-groups` | list, get, create (--generate), generate, update, delete |
131
131
  | `admin tiers` | list |
132
132
 
133
133
  Admin payout note: backend payout PII/actions such as `/api/admin/payouts`, `/api/admin/payout-requests`, and `/api/admin/payout-vneid-requests` intentionally require an interactive browser admin session. The CLI documents those as unsupported by API-key auth instead of pretending they are safe automation commands.
package/dist/index.js CHANGED
@@ -211,7 +211,7 @@ function buildUrl(path2, params) {
211
211
  }
212
212
  function buildHeaders(apiKey, hasBody) {
213
213
  const headers = {
214
- "User-Agent": `ckweb-cli/${"0.7.0"}`
214
+ "User-Agent": `ckweb-cli/${"0.8.0"}`
215
215
  };
216
216
  if (hasBody) {
217
217
  headers["Content-Type"] = "application/json";
@@ -3095,6 +3095,14 @@ var GROUP_COLUMNS = [
3095
3095
  { key: "codesUsed", header: "Used", width: 8 },
3096
3096
  { key: "createdAt", header: "Created", width: 22 }
3097
3097
  ];
3098
+ function parseGenerateCount(value, optionName = "--count") {
3099
+ if (value === void 0) return void 0;
3100
+ const count = Number(value);
3101
+ if (!Number.isInteger(count) || count < 1 || count > 100) {
3102
+ throw new CliError(`${optionName} must be an integer from 1 to 100`);
3103
+ }
3104
+ return count;
3105
+ }
3098
3106
  function buildGroupBody(opts) {
3099
3107
  const body = {};
3100
3108
  if (opts.name !== void 0) body["name"] = opts.name;
@@ -3135,6 +3143,12 @@ function buildGroupBody(opts) {
3135
3143
  if (opts.ends !== void 0) body["endsAt"] = opts.ends;
3136
3144
  return body;
3137
3145
  }
3146
+ async function generateDiscountGroupCodes(id, count) {
3147
+ return fetchApi("POST", `/admin/discount-groups/${id}/codes`, {
3148
+ adminAuth: true,
3149
+ body: { count }
3150
+ });
3151
+ }
3138
3152
  function registerAdminDiscountGroupsCommand(admin) {
3139
3153
  const groups = admin.command("discount-groups").description("Discount group management");
3140
3154
  groups.command("list").description("List discount groups").option("--query <text>", "Search by name or prefix").option("--page <n>", "Page number", "1").option("--limit <n>", "Page size", "50").action(async function() {
@@ -3162,15 +3176,37 @@ function registerAdminDiscountGroupsCommand(admin) {
3162
3176
  handleError(err);
3163
3177
  }
3164
3178
  });
3165
- groups.command("create").description("Create a discount group template").requiredOption("--name <name>", "Group name").requiredOption("--prefix <prefix>", "Code prefix (3-20 chars, uppercased)").requiredOption("--type <percentage|fixed>", "Discount type").option("--amount <n>", "Amount in cents (fixed type)").option("--basis-points <n>", "Basis points (percentage type, 0..10000)").option("--duration <once|repeating|forever>", "Discount duration").option("--duration-in-months <n>", "Months for repeating duration (1..24)").option("--max-redemptions-per-code <n>", "Per-code redemption cap").option("--starts <date>", "Start date (ISO 8601)").option("--ends <date>", "End date (ISO 8601)").action(async function() {
3179
+ groups.command("create").description("Create a discount group template").requiredOption("--name <name>", "Group name").requiredOption("--prefix <prefix>", "Code prefix (3-20 chars, uppercased)").requiredOption("--type <percentage|fixed>", "Discount type").option("--amount <n>", "Amount in cents (fixed type)").option("--basis-points <n>", "Basis points (percentage type, 0..10000)").option("--duration <once|repeating|forever>", "Discount duration").option("--duration-in-months <n>", "Months for repeating duration (1..24)").option("--max-redemptions-per-code <n>", "Per-code redemption cap").option("--starts <date>", "Start date (ISO 8601)").option("--ends <date>", "End date (ISO 8601)").option("--generate <n>", "Generate N discount codes after creating the group (1..100)").action(async function() {
3166
3180
  try {
3167
3181
  ensureAdminAuth();
3168
- const body = buildGroupBody(this.opts());
3182
+ const opts = this.opts();
3183
+ const generateCount = parseGenerateCount(opts.generate, "--generate");
3184
+ const body = buildGroupBody(opts);
3169
3185
  const data = await fetchApi("POST", "/admin/discount-groups", {
3170
3186
  adminAuth: true,
3171
3187
  body
3172
3188
  });
3173
3189
  printSuccess(`Discount group created: ${data?.group?.id ?? ""}`);
3190
+ if (generateCount !== void 0) {
3191
+ const id = data?.group?.id;
3192
+ if (!id) throw new CliError("Backend did not return a discount group ID for code generation.");
3193
+ const generated = await generateDiscountGroupCodes(id, generateCount);
3194
+ printSuccess(`Generated ${generated.generated} discount code(s).`);
3195
+ formatOutput({ ...data, ...generated }, getOutputOpts(this));
3196
+ return;
3197
+ }
3198
+ formatOutput(data, getOutputOpts(this));
3199
+ } catch (err) {
3200
+ handleError(err);
3201
+ }
3202
+ });
3203
+ groups.command("generate <id>").description("Generate discount codes for a group").requiredOption("--count <n>", "Number of codes to generate (1..100)").action(async function(id) {
3204
+ try {
3205
+ ensureAdminAuth();
3206
+ validateId(id, "discount group ID");
3207
+ const count = parseGenerateCount(this.opts().count);
3208
+ const data = await generateDiscountGroupCodes(id, count);
3209
+ printSuccess(`Generated ${data.generated} discount code(s).`);
3174
3210
  formatOutput(data, getOutputOpts(this));
3175
3211
  } catch (err) {
3176
3212
  handleError(err);
@@ -3257,7 +3293,7 @@ function registerAdminCommand(program2) {
3257
3293
  // src/index.ts
3258
3294
  loadDotenvFiles();
3259
3295
  var program = new Command();
3260
- program.name("ckweb").description("CLI for interacting with ClaudeKit.cc API").version("0.7.0");
3296
+ program.name("ckweb").description("CLI for interacting with ClaudeKit.cc API").version("0.8.0");
3261
3297
  program.option("--json", "Output as JSON").option("--table", "Output as table").option("--quiet", "Minimal output");
3262
3298
  registerAuthCommand(program);
3263
3299
  registerHealthCommand(program);