@freeticket/cli 0.12.0 → 0.13.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.
Files changed (3) hide show
  1. package/README.md +4 -0
  2. package/dist/index.js +638 -73
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -122,6 +122,10 @@ ft sales list --status CONFIRMED --json
122
122
  | `ft settlements list` · `get <id>` · `document <id>` | Settlements paid to the organizer · signed download URL for the PDF, 5 min TTL (`--proof <fileName>` for a payment proof) | ADMIN |
123
123
  | `ft content-videos list` · `content-posts list\|create` · `content-lives list\|get\|playback-token` | Organization content; `content-posts create --data` publishes a post or article | ADMIN |
124
124
  | `ft waitlist list [--city <name>]` · `waitlist create --data` | Per-city waitlist of an enterprise landing (export with personal data); `create` needs an enterprise service key | ADMIN |
125
+ | `ft merch products list` | Merch store products of the workspace's organization, DRAFT and PUBLISHED, with variants (Legend plan) | ADMIN / MERCH_MANAGER |
126
+ | `ft merch products create` | Create product(s) as DRAFT: `--name` `--price <cop>` `--sizes XS,S,M` `--stock <n>` `--image <path>` (repeatable, uploaded through a signed URL) `--publish`; `--from-json <file>` for several (image paths relative to the file, no symlinks). The whole batch is validated first; `--json` prints `{ created, failed }` | ADMIN / MERCH_MANAGER |
127
+ | `ft merch products images <id> --image <path>…` | Replace a product's photos with local files (repairs a partial `create`) | ADMIN / MERCH_MANAGER |
128
+ | `ft merch products publish <id>` · `unpublish <id>` | Show / hide a product in the store (publishing needs the store setup done and an active variant) | ADMIN / MERCH_MANAGER |
125
129
  | `ft api-keys create <name>` · `list` · `revoke <id>` | Self-service API keys (the secret is shown once, never stored) | ADMIN |
126
130
  | `ft admin login` · `me` · `workspaces` · `users` · `plans` · `feature-flags` · `tokens` · `audit-log` | Superadmin, cross-tenant — needs a SUPER_ADMIN session, not an API key. Includes `admin workspaces plan <id>` (assisted plan assignment), `plan-show <id>` (current plan) and `delete <id>` (soft delete; suspend first) and `webTemplate` / `customDomain` on `update` | SUPER_ADMIN |
127
131
 
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@
3
3
  // package.json
4
4
  var package_default = {
5
5
  name: "@freeticket/cli",
6
- version: "0.12.0",
6
+ version: "0.13.0",
7
7
  description: "Official FreeTicket CLI \u2014 consumes the B2B REST API for events, sales, tickets, memberships, venues, staff, and reports.",
8
8
  keywords: [
9
9
  "freeticket",
@@ -164,23 +164,33 @@ var client = createClient(createConfig({
164
164
  }));
165
165
 
166
166
  // src/client/sdk.gen.ts
167
- var getEventsIdDates = (options) => {
168
- return (options.client ?? client).get({
169
- security: [
170
- {
171
- name: "Authorization",
172
- type: "apiKey"
173
- },
174
- {
175
- name: "x-api-key",
176
- type: "apiKey"
177
- }
178
- ],
179
- url: "/events/{id}/dates",
167
+ var postAuthDeviceCode = (options) => {
168
+ return (options?.client ?? client).post({
169
+ url: "/auth/device/code",
180
170
  ...options
181
171
  });
182
172
  };
183
- var postEventsIdDates = (options) => {
173
+ var postAuthDeviceToken = (options) => {
174
+ return (options.client ?? client).post({
175
+ url: "/auth/device/token",
176
+ ...options,
177
+ headers: {
178
+ "Content-Type": "application/json",
179
+ ...options?.headers
180
+ }
181
+ });
182
+ };
183
+ var postAuthSignup = (options) => {
184
+ return (options.client ?? client).post({
185
+ url: "/auth/signup",
186
+ ...options,
187
+ headers: {
188
+ "Content-Type": "application/json",
189
+ ...options?.headers
190
+ }
191
+ });
192
+ };
193
+ var postWorkspaces = (options) => {
184
194
  return (options.client ?? client).post({
185
195
  security: [
186
196
  {
@@ -192,7 +202,7 @@ var postEventsIdDates = (options) => {
192
202
  type: "apiKey"
193
203
  }
194
204
  ],
195
- url: "/events/{id}/dates",
205
+ url: "/workspaces",
196
206
  ...options,
197
207
  headers: {
198
208
  "Content-Type": "application/json",
@@ -200,7 +210,7 @@ var postEventsIdDates = (options) => {
200
210
  }
201
211
  });
202
212
  };
203
- var getEvents = (options) => {
213
+ var getMe = (options) => {
204
214
  return (options?.client ?? client).get({
205
215
  security: [
206
216
  {
@@ -212,12 +222,12 @@ var getEvents = (options) => {
212
222
  type: "apiKey"
213
223
  }
214
224
  ],
215
- url: "/events",
225
+ url: "/me",
216
226
  ...options
217
227
  });
218
228
  };
219
- var postEvents = (options) => {
220
- return (options.client ?? client).post({
229
+ var getEvents = (options) => {
230
+ return (options?.client ?? client).get({
221
231
  security: [
222
232
  {
223
233
  name: "Authorization",
@@ -229,40 +239,10 @@ var postEvents = (options) => {
229
239
  }
230
240
  ],
231
241
  url: "/events",
232
- ...options,
233
- headers: {
234
- "Content-Type": "application/json",
235
- ...options?.headers
236
- }
237
- });
238
- };
239
- var postAuthDeviceCode = (options) => {
240
- return (options?.client ?? client).post({
241
- url: "/auth/device/code",
242
242
  ...options
243
243
  });
244
244
  };
245
- var postAuthDeviceToken = (options) => {
246
- return (options.client ?? client).post({
247
- url: "/auth/device/token",
248
- ...options,
249
- headers: {
250
- "Content-Type": "application/json",
251
- ...options?.headers
252
- }
253
- });
254
- };
255
- var postAuthSignup = (options) => {
256
- return (options.client ?? client).post({
257
- url: "/auth/signup",
258
- ...options,
259
- headers: {
260
- "Content-Type": "application/json",
261
- ...options?.headers
262
- }
263
- });
264
- };
265
- var postWorkspaces = (options) => {
245
+ var postEvents = (options) => {
266
246
  return (options.client ?? client).post({
267
247
  security: [
268
248
  {
@@ -274,7 +254,7 @@ var postWorkspaces = (options) => {
274
254
  type: "apiKey"
275
255
  }
276
256
  ],
277
- url: "/workspaces",
257
+ url: "/events",
278
258
  ...options,
279
259
  headers: {
280
260
  "Content-Type": "application/json",
@@ -282,22 +262,6 @@ var postWorkspaces = (options) => {
282
262
  }
283
263
  });
284
264
  };
285
- var getMe = (options) => {
286
- return (options?.client ?? client).get({
287
- security: [
288
- {
289
- name: "Authorization",
290
- type: "apiKey"
291
- },
292
- {
293
- name: "x-api-key",
294
- type: "apiKey"
295
- }
296
- ],
297
- url: "/me",
298
- ...options
299
- });
300
- };
301
265
  var deleteEventsId = (options) => {
302
266
  return (options.client ?? client).delete({
303
267
  security: [
@@ -382,6 +346,42 @@ var postEventsIdCancel = (options) => {
382
346
  ...options
383
347
  });
384
348
  };
349
+ var getEventsIdDates = (options) => {
350
+ return (options.client ?? client).get({
351
+ security: [
352
+ {
353
+ name: "Authorization",
354
+ type: "apiKey"
355
+ },
356
+ {
357
+ name: "x-api-key",
358
+ type: "apiKey"
359
+ }
360
+ ],
361
+ url: "/events/{id}/dates",
362
+ ...options
363
+ });
364
+ };
365
+ var postEventsIdDates = (options) => {
366
+ return (options.client ?? client).post({
367
+ security: [
368
+ {
369
+ name: "Authorization",
370
+ type: "apiKey"
371
+ },
372
+ {
373
+ name: "x-api-key",
374
+ type: "apiKey"
375
+ }
376
+ ],
377
+ url: "/events/{id}/dates",
378
+ ...options,
379
+ headers: {
380
+ "Content-Type": "application/json",
381
+ ...options?.headers
382
+ }
383
+ });
384
+ };
385
385
  var deleteEventsIdDatesDateId = (options) => {
386
386
  return (options.client ?? client).delete({
387
387
  security: [
@@ -1526,6 +1526,102 @@ var postWaitlist = (options) => {
1526
1526
  }
1527
1527
  });
1528
1528
  };
1529
+ var getMerchProducts = (options) => {
1530
+ return (options?.client ?? client).get({
1531
+ security: [
1532
+ {
1533
+ name: "Authorization",
1534
+ type: "apiKey"
1535
+ },
1536
+ {
1537
+ name: "x-api-key",
1538
+ type: "apiKey"
1539
+ }
1540
+ ],
1541
+ url: "/merch/products",
1542
+ ...options
1543
+ });
1544
+ };
1545
+ var postMerchProducts = (options) => {
1546
+ return (options.client ?? client).post({
1547
+ security: [
1548
+ {
1549
+ name: "Authorization",
1550
+ type: "apiKey"
1551
+ },
1552
+ {
1553
+ name: "x-api-key",
1554
+ type: "apiKey"
1555
+ }
1556
+ ],
1557
+ url: "/merch/products",
1558
+ ...options,
1559
+ headers: {
1560
+ "Content-Type": "application/json",
1561
+ ...options?.headers
1562
+ }
1563
+ });
1564
+ };
1565
+ var patchMerchProductsIdStatus = (options) => {
1566
+ return (options.client ?? client).patch({
1567
+ security: [
1568
+ {
1569
+ name: "Authorization",
1570
+ type: "apiKey"
1571
+ },
1572
+ {
1573
+ name: "x-api-key",
1574
+ type: "apiKey"
1575
+ }
1576
+ ],
1577
+ url: "/merch/products/{id}/status",
1578
+ ...options,
1579
+ headers: {
1580
+ "Content-Type": "application/json",
1581
+ ...options?.headers
1582
+ }
1583
+ });
1584
+ };
1585
+ var putMerchProductsIdImages = (options) => {
1586
+ return (options.client ?? client).put({
1587
+ security: [
1588
+ {
1589
+ name: "Authorization",
1590
+ type: "apiKey"
1591
+ },
1592
+ {
1593
+ name: "x-api-key",
1594
+ type: "apiKey"
1595
+ }
1596
+ ],
1597
+ url: "/merch/products/{id}/images",
1598
+ ...options,
1599
+ headers: {
1600
+ "Content-Type": "application/json",
1601
+ ...options?.headers
1602
+ }
1603
+ });
1604
+ };
1605
+ var postMerchProductsImagesUploadUrl = (options) => {
1606
+ return (options.client ?? client).post({
1607
+ security: [
1608
+ {
1609
+ name: "Authorization",
1610
+ type: "apiKey"
1611
+ },
1612
+ {
1613
+ name: "x-api-key",
1614
+ type: "apiKey"
1615
+ }
1616
+ ],
1617
+ url: "/merch/products/images/upload-url",
1618
+ ...options,
1619
+ headers: {
1620
+ "Content-Type": "application/json",
1621
+ ...options?.headers
1622
+ }
1623
+ });
1624
+ };
1529
1625
 
1530
1626
  // src/commands/account.ts
1531
1627
  import chalk4 from "chalk";
@@ -1610,7 +1706,7 @@ function resolveAccounts(file, env, accountFlag2) {
1610
1706
  ];
1611
1707
  }
1612
1708
  const accounts = file.accounts ?? {};
1613
- const resolve = ([name, a]) => ({
1709
+ const resolve2 = ([name, a]) => ({
1614
1710
  name,
1615
1711
  apiUrl: apiUrl(a),
1616
1712
  apiKey: a.apiKey,
@@ -1625,9 +1721,9 @@ function resolveAccounts(file, env, accountFlag2) {
1625
1721
  `No account named "${pick2}". Stored: ${names || "(none)"}`
1626
1722
  );
1627
1723
  }
1628
- return [resolve([pick2, picked])];
1724
+ return [resolve2([pick2, picked])];
1629
1725
  }
1630
- return Object.entries(accounts).map(resolve);
1726
+ return Object.entries(accounts).map(resolve2);
1631
1727
  }
1632
1728
  function effectiveAccounts(accountFlag2) {
1633
1729
  return resolveAccounts(readFile(), process.env, accountFlag2);
@@ -2661,10 +2757,10 @@ function confirm(question) {
2661
2757
  input: process.stdin,
2662
2758
  output: process.stderr
2663
2759
  });
2664
- return new Promise((resolve) => {
2760
+ return new Promise((resolve2) => {
2665
2761
  rl.question(`${question} [y/N] `, (answer) => {
2666
2762
  rl.close();
2667
- resolve(/^y(es)?$/i.test(answer.trim()));
2763
+ resolve2(/^y(es)?$/i.test(answer.trim()));
2668
2764
  });
2669
2765
  });
2670
2766
  }
@@ -3119,6 +3215,474 @@ function registerEventDates(program2, spec) {
3119
3215
  });
3120
3216
  }
3121
3217
 
3218
+ // src/commands/merch.ts
3219
+ import {
3220
+ closeSync,
3221
+ lstatSync,
3222
+ openSync,
3223
+ readFileSync as readFileSync4,
3224
+ readSync,
3225
+ statSync
3226
+ } from "fs";
3227
+ import { dirname as dirname3, isAbsolute, relative, resolve } from "path";
3228
+ var MAX_IMAGE_BYTES = 6 * 1024 * 1024;
3229
+ var MAX_IMAGES = 10;
3230
+ var LIST_COLUMNS = ["id", "name", "status", "variants", "stock", "price"];
3231
+ function skuPart(value) {
3232
+ return value.toLowerCase().normalize("NFD").replace(/[̀-ͯ]/g, "").replace(/[^a-z0-9\s-]/g, "").replace(/\s+/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "").toUpperCase();
3233
+ }
3234
+ function skuBaseFrom(name) {
3235
+ return skuPart(name).slice(0, 40).replace(/-+$/, "") || "SKU";
3236
+ }
3237
+ function stockFor(spec, size) {
3238
+ const { stock } = spec;
3239
+ if (stock === void 0) return 0;
3240
+ if (typeof stock === "number") return stock;
3241
+ if (size === void 0) {
3242
+ throw new Error(
3243
+ `"${spec.name}": stock per size needs "sizes"; use a number instead.`
3244
+ );
3245
+ }
3246
+ return stock[size] ?? 0;
3247
+ }
3248
+ function buildProductBody(spec) {
3249
+ if (!spec.name?.trim()) throw new Error("A product needs a name.");
3250
+ if (!Number.isInteger(spec.price) || spec.price < 0) {
3251
+ throw new Error(`"${spec.name}": price must be an integer in COP.`);
3252
+ }
3253
+ const sizes = (spec.sizes ?? []).map((s) => s.trim()).filter(Boolean);
3254
+ const upper = sizes.map((s) => s.toLocaleUpperCase("es"));
3255
+ if (new Set(upper).size !== upper.length) {
3256
+ throw new Error(`"${spec.name}": repeated size.`);
3257
+ }
3258
+ if (spec.stock && typeof spec.stock === "object") {
3259
+ const unknown = Object.keys(spec.stock).filter((k) => !sizes.includes(k));
3260
+ if (unknown.length > 0) {
3261
+ throw new Error(
3262
+ `"${spec.name}": stock for unknown size(s): ${unknown.join(", ")}.`
3263
+ );
3264
+ }
3265
+ }
3266
+ const base = spec.sku ? spec.sku.trim() : skuBaseFrom(spec.name);
3267
+ const optionName = spec.optionName?.trim() || "Talla";
3268
+ const variant = (sku, stock, attributes = {}) => ({
3269
+ attributes,
3270
+ sku,
3271
+ price: spec.price,
3272
+ compareAtPrice: spec.compareAtPrice ?? null,
3273
+ stock
3274
+ });
3275
+ return {
3276
+ name: spec.name.trim(),
3277
+ ...spec.description ? { description: spec.description } : {},
3278
+ ...spec.slug ? { slug: spec.slug } : {},
3279
+ maxPerOrder: spec.maxPerOrder ?? 10,
3280
+ options: sizes.length > 0 ? [{ name: optionName, values: sizes }] : [],
3281
+ variants: sizes.length > 0 ? sizes.map(
3282
+ (size) => variant(`${base}-${skuPart(size) || size}`, stockFor(spec, size), {
3283
+ [optionName]: size
3284
+ })
3285
+ ) : [variant(base, stockFor(spec))]
3286
+ };
3287
+ }
3288
+ var JPEG = [255, 216, 255];
3289
+ var PNG = [137, 80, 78, 71, 13, 10, 26, 10];
3290
+ function sniffImage(head) {
3291
+ const starts = (sig, at = 0) => sig.every((b, i) => head[at + i] === b);
3292
+ if (starts(JPEG)) return "image/jpeg";
3293
+ if (starts(PNG)) return "image/png";
3294
+ if (starts([82, 73, 70, 70]) && starts([87, 69, 66, 80], 8))
3295
+ return "image/webp";
3296
+ return null;
3297
+ }
3298
+ function readHead(path) {
3299
+ const fd = openSync(path, "r");
3300
+ try {
3301
+ const buf = new Uint8Array(12);
3302
+ const n = readSync(fd, buf, 0, 12, 0);
3303
+ return buf.subarray(0, n);
3304
+ } finally {
3305
+ closeSync(fd);
3306
+ }
3307
+ }
3308
+ function checkImage(path) {
3309
+ let size;
3310
+ let head;
3311
+ try {
3312
+ const st = statSync(path);
3313
+ if (!st.isFile()) throw new Error("not a file");
3314
+ size = st.size;
3315
+ head = readHead(path);
3316
+ } catch {
3317
+ throw new Error(`${path}: cannot read the file.`);
3318
+ }
3319
+ if (size === 0) throw new Error(`${path}: the file is empty.`);
3320
+ if (size > MAX_IMAGE_BYTES) {
3321
+ throw new Error(`${path}: the photo cannot exceed 6 MB.`);
3322
+ }
3323
+ const mime = sniffImage(head);
3324
+ if (!mime) {
3325
+ throw new Error(`${path}: the photo must be a JPG, PNG or WebP file.`);
3326
+ }
3327
+ return mime;
3328
+ }
3329
+ var isInt = (v, min = 0) => typeof v === "number" && Number.isInteger(v) && v >= min;
3330
+ var optString = (v) => v === void 0 || typeof v === "string";
3331
+ function validateSpec(raw, label) {
3332
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
3333
+ throw new Error(`${label}: must be an object.`);
3334
+ }
3335
+ const p = raw;
3336
+ const bad = (field, want) => new Error(`${label}: "${field}" must be ${want}.`);
3337
+ if (typeof p.name !== "string" || !p.name.trim())
3338
+ throw bad("name", "a non-empty string");
3339
+ if (!isInt(p.price)) throw bad("price", "a non-negative integer (COP)");
3340
+ if (p.compareAtPrice != null && !isInt(p.compareAtPrice))
3341
+ throw bad("compareAtPrice", "a non-negative integer or null");
3342
+ if (p.description != null && typeof p.description !== "string")
3343
+ throw bad("description", "a string");
3344
+ for (const f of ["optionName", "sku", "slug"])
3345
+ if (!optString(p[f])) throw bad(f, "a string");
3346
+ if (p.maxPerOrder !== void 0 && !isInt(p.maxPerOrder, 1))
3347
+ throw bad("maxPerOrder", "an integer of at least 1");
3348
+ if (p.sizes !== void 0 && (!Array.isArray(p.sizes) || !p.sizes.every((s) => typeof s === "string")))
3349
+ throw bad("sizes", "an array of strings");
3350
+ if (p.stock !== void 0 && !isInt(p.stock) && !(p.stock && typeof p.stock === "object" && !Array.isArray(p.stock) && Object.values(p.stock).every((n) => isInt(n))))
3351
+ throw bad(
3352
+ "stock",
3353
+ "a non-negative integer or { size: non-negative integer }"
3354
+ );
3355
+ if (p.images !== void 0 && (!Array.isArray(p.images) || !p.images.every((s) => typeof s === "string")))
3356
+ throw bad("images", "an array of paths");
3357
+ if ((p.images?.length ?? 0) > MAX_IMAGES)
3358
+ throw new Error(`${label}: at most ${MAX_IMAGES} photos.`);
3359
+ if (p.publish !== void 0 && typeof p.publish !== "boolean")
3360
+ throw bad("publish", "true or false");
3361
+ return p;
3362
+ }
3363
+ function resolveJsonImage(dir, img, label) {
3364
+ if (isAbsolute(img)) {
3365
+ throw new Error(
3366
+ `${label}: image "${img}" must be relative to the JSON file.`
3367
+ );
3368
+ }
3369
+ const full = resolve(dir, img);
3370
+ const rel = relative(dir, full);
3371
+ if (rel === "" || rel.startsWith("..") || isAbsolute(rel)) {
3372
+ throw new Error(
3373
+ `${label}: image "${img}" is outside the JSON file's folder.`
3374
+ );
3375
+ }
3376
+ let link = false;
3377
+ try {
3378
+ link = lstatSync(full).isSymbolicLink();
3379
+ } catch {
3380
+ throw new Error(`${label}: image "${img}": cannot read the file.`);
3381
+ }
3382
+ if (link) throw new Error(`${label}: image "${img}" is a symlink.`);
3383
+ return full;
3384
+ }
3385
+ function parseProductsFile(raw, file) {
3386
+ let parsed;
3387
+ try {
3388
+ parsed = JSON.parse(raw);
3389
+ } catch {
3390
+ throw new Error(`Invalid JSON in ${file}.`);
3391
+ }
3392
+ const list = Array.isArray(parsed) ? parsed : parsed?.products;
3393
+ if (!Array.isArray(list) || list.length === 0) {
3394
+ throw new Error(
3395
+ `${file}: expected { "products": [ ... ] } or an array with at least one product.`
3396
+ );
3397
+ }
3398
+ const dir = dirname3(resolve(file));
3399
+ return list.map((p, i) => {
3400
+ const label = `${file}: product #${i + 1}`;
3401
+ const spec = validateSpec(p, label);
3402
+ return {
3403
+ ...spec,
3404
+ images: (spec.images ?? []).map(
3405
+ (img) => resolveJsonImage(dir, img, label)
3406
+ )
3407
+ };
3408
+ });
3409
+ }
3410
+ function validateBatch(specs) {
3411
+ for (const [i, s] of specs.entries()) {
3412
+ validateSpec(s, `product #${i + 1}`);
3413
+ buildProductBody(s);
3414
+ for (const img of s.images ?? []) checkImage(img);
3415
+ }
3416
+ }
3417
+ var MerchStepError = class extends Error {
3418
+ constructor(step, message, productId) {
3419
+ super(message);
3420
+ this.step = step;
3421
+ this.productId = productId;
3422
+ }
3423
+ step;
3424
+ productId;
3425
+ };
3426
+ var errorCode = (res) => res.error?.error?.code;
3427
+ function ok(res, step, what, productId) {
3428
+ if (res.data !== void 0) return res.data;
3429
+ throw new MerchStepError(step, `${what}: ${describeError(res)}`, productId);
3430
+ }
3431
+ var MAX_RETRY_AFTER_MS = 10 * 6e4;
3432
+ function retryAfterMs(res) {
3433
+ const raw = res?.headers.get("Retry-After");
3434
+ if (!raw) return 6e4;
3435
+ const secs = Number(raw);
3436
+ const ms = Number.isFinite(secs) ? secs * 1e3 : Math.max(0, Date.parse(raw) - Date.now());
3437
+ return Math.min(Number.isNaN(ms) ? 6e4 : ms, MAX_RETRY_AFTER_MS);
3438
+ }
3439
+ async function uploadImages(paths, deps, at, productId) {
3440
+ const urls = [];
3441
+ for (const path of paths) {
3442
+ const mimeType = checkImage(path);
3443
+ const bytes = deps.readFile(path);
3444
+ const body = { mimeType, sizeBytes: bytes.byteLength };
3445
+ let res = await deps.uploadUrl(body);
3446
+ if (res.data === void 0 && res.response?.status === 429) {
3447
+ const wait = retryAfterMs(res.response);
3448
+ console.error(
3449
+ `Rate limited asking for an upload URL; retrying in ${Math.ceil(wait / 1e3)} s\u2026`
3450
+ );
3451
+ await deps.sleep(wait);
3452
+ res = await deps.uploadUrl(body);
3453
+ }
3454
+ const signed = ok(
3455
+ res,
3456
+ "upload-url",
3457
+ `${at} upload-url for ${path}`,
3458
+ productId
3459
+ ).data;
3460
+ const put = await deps.put(signed.uploadUrl, bytes, mimeType);
3461
+ if (!put.ok) {
3462
+ throw new MerchStepError(
3463
+ "upload",
3464
+ `${at} uploading ${path}: storage answered ${put.status}`,
3465
+ productId
3466
+ );
3467
+ }
3468
+ urls.push(signed.publicUrl);
3469
+ }
3470
+ return urls;
3471
+ }
3472
+ var RECOVER_HINT = "Probably created by an earlier run: find it with `ft merch products list`, then `ft merch products images <id> --image \u2026` and `ft merch products publish <id>`; or use another --sku / slug for a new product.";
3473
+ async function createProduct(spec, deps) {
3474
+ const body = buildProductBody(spec);
3475
+ const images = spec.images ?? [];
3476
+ const res = await deps.create(body);
3477
+ if (res.data === void 0) {
3478
+ const code = errorCode(res);
3479
+ const hint = code === "SKU_TAKEN" || code === "SLUG_TAKEN" ? ` ${RECOVER_HINT}` : "";
3480
+ throw new MerchStepError(
3481
+ "create",
3482
+ `"${spec.name}" create: ${describeError(res)}.${hint}`
3483
+ );
3484
+ }
3485
+ const product = res.data.data;
3486
+ const at = `"${spec.name}" (created as ${product.id}, DRAFT)`;
3487
+ if (images.length > 0) {
3488
+ const urls = await uploadImages(images, deps, at, product.id);
3489
+ ok(
3490
+ await deps.setImages(product.id, urls),
3491
+ "set-images",
3492
+ `${at} set images`,
3493
+ product.id
3494
+ );
3495
+ product.imageUrls = urls;
3496
+ }
3497
+ if (spec.publish) {
3498
+ ok(
3499
+ await deps.setStatus(product.id, "PUBLISHED"),
3500
+ "publish",
3501
+ `${at} publish`,
3502
+ product.id
3503
+ );
3504
+ product.status = "PUBLISHED";
3505
+ }
3506
+ return product;
3507
+ }
3508
+ async function createBatch(specs, deps) {
3509
+ const created = [];
3510
+ const failed = [];
3511
+ for (const spec of specs) {
3512
+ try {
3513
+ created.push(await createProduct(spec, deps));
3514
+ } catch (err) {
3515
+ const e = err;
3516
+ failed.push({
3517
+ name: spec.name,
3518
+ ...err instanceof MerchStepError && err.productId ? { productId: err.productId } : {},
3519
+ step: err instanceof MerchStepError ? err.step : "validate",
3520
+ error: e.message
3521
+ });
3522
+ }
3523
+ }
3524
+ return { created, failed };
3525
+ }
3526
+ var sdkDeps = {
3527
+ create: (body) => postMerchProducts({ body }),
3528
+ uploadUrl: (body) => postMerchProductsImagesUploadUrl({ body }),
3529
+ setImages: (id, imageUrls) => putMerchProductsIdImages({ path: { id }, body: { imageUrls } }),
3530
+ setStatus: (id, status) => patchMerchProductsIdStatus({ path: { id }, body: { status } }),
3531
+ readFile: (path) => readFileSync4(path),
3532
+ // Signed storage URL: no Authorization header, the token is in the URL.
3533
+ put: (url, body, contentType) => fetch(url, {
3534
+ method: "PUT",
3535
+ headers: { "Content-Type": contentType },
3536
+ body
3537
+ }),
3538
+ sleep: (ms) => new Promise((r) => setTimeout(r, ms))
3539
+ };
3540
+ function summarize(p) {
3541
+ const prices = p.variants.map((v) => v.price);
3542
+ const min = Math.min(...prices);
3543
+ const max = Math.max(...prices);
3544
+ return {
3545
+ id: p.id,
3546
+ name: p.name,
3547
+ status: p.status,
3548
+ variants: p.variants.map((v) => v.label).join(" "),
3549
+ stock: p.variants.reduce((n, v) => n + v.stock, 0),
3550
+ price: prices.length === 0 ? null : min === max ? min : `${min}-${max}`
3551
+ };
3552
+ }
3553
+ var collect = (value, prev = []) => [...prev, value];
3554
+ function intFlag(name) {
3555
+ return (value) => {
3556
+ const n = Number(value);
3557
+ if (!Number.isInteger(n) || n < 0) {
3558
+ fail(`${name} must be a non-negative integer (got "${value}").`);
3559
+ }
3560
+ return n;
3561
+ };
3562
+ }
3563
+ function registerMerch(program2, deps = sdkDeps) {
3564
+ const merch = program2.command("merch").description("Merch store (Legend plan): products, photos, publishing");
3565
+ const products = merch.command("products").description("Merch store products of the workspace's organization");
3566
+ products.command("list").description("List every product (DRAFT and PUBLISHED) with its variants").option("--workspace <id>", "workspace override").option("--json", "raw JSON output").action(async (opts) => {
3567
+ configureClient(opts.workspace);
3568
+ const body = unwrap(await getMerchProducts());
3569
+ const rows = body.data ?? [];
3570
+ print(opts.json ? rows : rows.map(summarize), {
3571
+ json: opts.json,
3572
+ columns: LIST_COLUMNS
3573
+ });
3574
+ });
3575
+ products.command("create").description(
3576
+ "Create product(s) as DRAFT: sizes become variants, local photos are uploaded"
3577
+ ).option("--name <name>", "product name").option("--description <text>", "description").option(
3578
+ "--price <cop>",
3579
+ "price in COP (integer, VAT included)",
3580
+ intFlag("--price")
3581
+ ).option(
3582
+ "--compare-at <cop>",
3583
+ "strikethrough price in COP (greater than --price)",
3584
+ intFlag("--compare-at")
3585
+ ).option("--sizes <list>", "comma-separated sizes, e.g. XS,S,M,L,XL,2XL").option("--option-name <name>", "name of the size option", "Talla").option("--stock <n>", "units per variant", intFlag("--stock")).option(
3586
+ "--sku <prefix>",
3587
+ "SKU prefix (default: from the name); sizes append -<SIZE>"
3588
+ ).option(
3589
+ "--max-per-order <n>",
3590
+ "max units per order (default 10)",
3591
+ intFlag("--max-per-order")
3592
+ ).option("--slug <slug>", "URL slug (default: from the name)").option(
3593
+ "--image <path>",
3594
+ "local photo, repeatable (first = cover)",
3595
+ collect
3596
+ ).option("--publish", "publish right after creating").option("--from-json <file>", "create several products from a JSON file").option("--workspace <id>", "workspace override").option("--json", "raw JSON output").action(async (opts) => {
3597
+ let specs;
3598
+ try {
3599
+ if (opts.fromJson) {
3600
+ if (opts.name) fail("Use either --from-json or --name, not both.");
3601
+ let raw;
3602
+ try {
3603
+ raw = readFileSync4(opts.fromJson, "utf8");
3604
+ } catch {
3605
+ fail(`Cannot read file: ${opts.fromJson}`);
3606
+ }
3607
+ specs = parseProductsFile(raw, opts.fromJson);
3608
+ } else {
3609
+ if (!opts.name || opts.price === void 0) {
3610
+ fail(
3611
+ "Missing --name or --price (or pass --from-json <file>).",
3612
+ 'Example: ft merch products create --name "Camiseta Tour" --price 80000 --sizes S,M,L --stock 10 --image front.jpg'
3613
+ );
3614
+ }
3615
+ specs = [
3616
+ {
3617
+ name: opts.name,
3618
+ description: opts.description,
3619
+ price: opts.price,
3620
+ compareAtPrice: opts.compareAt,
3621
+ sizes: opts.sizes ? String(opts.sizes).split(",") : void 0,
3622
+ optionName: opts.optionName,
3623
+ stock: opts.stock,
3624
+ sku: opts.sku,
3625
+ maxPerOrder: opts.maxPerOrder,
3626
+ slug: opts.slug,
3627
+ images: opts.image ?? [],
3628
+ publish: Boolean(opts.publish)
3629
+ }
3630
+ ];
3631
+ }
3632
+ validateBatch(specs);
3633
+ } catch (err) {
3634
+ fail(err.message);
3635
+ }
3636
+ configureClient(opts.workspace);
3637
+ const { created, failed } = await createBatch(specs, deps);
3638
+ if (opts.json) print({ created, failed }, { json: true });
3639
+ else if (created.length > 0)
3640
+ print(created.map(summarize), { columns: LIST_COLUMNS });
3641
+ if (failed.length > 0) {
3642
+ fail(
3643
+ `${failed.length} of ${specs.length} product(s) failed:
3644
+ ${failed.map((f) => ` \xB7 [${f.step}] ${f.error}`).join("\n")}`
3645
+ );
3646
+ }
3647
+ });
3648
+ products.command("images <id>").description(
3649
+ "Replace a product's photos with local files (in order; first = cover)"
3650
+ ).requiredOption(
3651
+ "--image <path>",
3652
+ "local photo, repeatable (first = cover)",
3653
+ collect
3654
+ ).option("--workspace <id>", "workspace override").option("--json", "raw JSON output").action(async (id, opts) => {
3655
+ const paths = opts.image;
3656
+ try {
3657
+ if (paths.length > MAX_IMAGES) {
3658
+ throw new Error(`At most ${MAX_IMAGES} photos.`);
3659
+ }
3660
+ for (const img of paths) checkImage(img);
3661
+ } catch (err) {
3662
+ fail(err.message);
3663
+ }
3664
+ configureClient(opts.workspace);
3665
+ let urls;
3666
+ try {
3667
+ urls = await uploadImages(paths, deps, `Product ${id}`, id);
3668
+ } catch (err) {
3669
+ fail(err.message);
3670
+ }
3671
+ const body = unwrap(await deps.setImages(id, urls));
3672
+ print(body.data ?? body, { json: opts.json });
3673
+ });
3674
+ for (const [name, status, describe] of [
3675
+ ["publish", "PUBLISHED", "Publish a product (shows it in the store)"],
3676
+ ["unpublish", "DRAFT", "Unpublish a product (back to DRAFT)"]
3677
+ ]) {
3678
+ products.command(`${name} <id>`).description(describe).option("--workspace <id>", "workspace override").option("--json", "raw JSON output").action(async (id, opts) => {
3679
+ configureClient(opts.workspace);
3680
+ const body = unwrap(await deps.setStatus(id, status));
3681
+ print(body.data ?? body, { json: opts.json });
3682
+ });
3683
+ }
3684
+ }
3685
+
3122
3686
  // src/commands/reports.ts
3123
3687
  async function reportRows(workspaceFlag, call) {
3124
3688
  const targets = await listTargets(workspaceFlag);
@@ -3985,6 +4549,7 @@ registerResource(program, {
3985
4549
  }
3986
4550
  ]
3987
4551
  });
4552
+ registerMerch(program);
3988
4553
  registerTickets(program);
3989
4554
  registerReports(program);
3990
4555
  registerApiKeys(program);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@freeticket/cli",
3
- "version": "0.12.0",
3
+ "version": "0.13.0",
4
4
  "description": "Official FreeTicket CLI — consumes the B2B REST API for events, sales, tickets, memberships, venues, staff, and reports.",
5
5
  "keywords": [
6
6
  "freeticket",