@freeticket/cli 0.12.0 → 0.13.1
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 +4 -0
- package/dist/index.js +626 -61
- 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.
|
|
6
|
+
version: "0.13.1",
|
|
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",
|
|
@@ -236,6 +236,38 @@ var postEvents = (options) => {
|
|
|
236
236
|
}
|
|
237
237
|
});
|
|
238
238
|
};
|
|
239
|
+
var getContentVideos = (options) => {
|
|
240
|
+
return (options?.client ?? client).get({
|
|
241
|
+
security: [
|
|
242
|
+
{
|
|
243
|
+
name: "Authorization",
|
|
244
|
+
type: "apiKey"
|
|
245
|
+
},
|
|
246
|
+
{
|
|
247
|
+
name: "x-api-key",
|
|
248
|
+
type: "apiKey"
|
|
249
|
+
}
|
|
250
|
+
],
|
|
251
|
+
url: "/content/videos",
|
|
252
|
+
...options
|
|
253
|
+
});
|
|
254
|
+
};
|
|
255
|
+
var getContentLives = (options) => {
|
|
256
|
+
return (options?.client ?? client).get({
|
|
257
|
+
security: [
|
|
258
|
+
{
|
|
259
|
+
name: "Authorization",
|
|
260
|
+
type: "apiKey"
|
|
261
|
+
},
|
|
262
|
+
{
|
|
263
|
+
name: "x-api-key",
|
|
264
|
+
type: "apiKey"
|
|
265
|
+
}
|
|
266
|
+
],
|
|
267
|
+
url: "/content/lives",
|
|
268
|
+
...options
|
|
269
|
+
});
|
|
270
|
+
};
|
|
239
271
|
var postAuthDeviceCode = (options) => {
|
|
240
272
|
return (options?.client ?? client).post({
|
|
241
273
|
url: "/auth/device/code",
|
|
@@ -578,26 +610,6 @@ var postSalesIdCancel = (options) => {
|
|
|
578
610
|
}
|
|
579
611
|
});
|
|
580
612
|
};
|
|
581
|
-
var postSalesIdRefund = (options) => {
|
|
582
|
-
return (options.client ?? client).post({
|
|
583
|
-
security: [
|
|
584
|
-
{
|
|
585
|
-
name: "Authorization",
|
|
586
|
-
type: "apiKey"
|
|
587
|
-
},
|
|
588
|
-
{
|
|
589
|
-
name: "x-api-key",
|
|
590
|
-
type: "apiKey"
|
|
591
|
-
}
|
|
592
|
-
],
|
|
593
|
-
url: "/sales/{id}/refund",
|
|
594
|
-
...options,
|
|
595
|
-
headers: {
|
|
596
|
-
"Content-Type": "application/json",
|
|
597
|
-
...options?.headers
|
|
598
|
-
}
|
|
599
|
-
});
|
|
600
|
-
};
|
|
601
613
|
var getMembershipPlans = (options) => {
|
|
602
614
|
return (options?.client ?? client).get({
|
|
603
615
|
security: [
|
|
@@ -1282,22 +1294,6 @@ var patchTicketsTicketCode = (options) => {
|
|
|
1282
1294
|
}
|
|
1283
1295
|
});
|
|
1284
1296
|
};
|
|
1285
|
-
var postTicketsTicketCodeResend = (options) => {
|
|
1286
|
-
return (options.client ?? client).post({
|
|
1287
|
-
security: [
|
|
1288
|
-
{
|
|
1289
|
-
name: "Authorization",
|
|
1290
|
-
type: "apiKey"
|
|
1291
|
-
},
|
|
1292
|
-
{
|
|
1293
|
-
name: "x-api-key",
|
|
1294
|
-
type: "apiKey"
|
|
1295
|
-
}
|
|
1296
|
-
],
|
|
1297
|
-
url: "/tickets/{ticketCode}/resend",
|
|
1298
|
-
...options
|
|
1299
|
-
});
|
|
1300
|
-
};
|
|
1301
1297
|
var postTicketsTicketCodeCheckin = (options) => {
|
|
1302
1298
|
return (options.client ?? client).post({
|
|
1303
1299
|
security: [
|
|
@@ -1386,7 +1382,7 @@ var deleteApiKeysId = (options) => {
|
|
|
1386
1382
|
...options
|
|
1387
1383
|
});
|
|
1388
1384
|
};
|
|
1389
|
-
var
|
|
1385
|
+
var getContentPosts = (options) => {
|
|
1390
1386
|
return (options?.client ?? client).get({
|
|
1391
1387
|
security: [
|
|
1392
1388
|
{
|
|
@@ -1398,12 +1394,12 @@ var getContentVideos = (options) => {
|
|
|
1398
1394
|
type: "apiKey"
|
|
1399
1395
|
}
|
|
1400
1396
|
],
|
|
1401
|
-
url: "/content/
|
|
1397
|
+
url: "/content/posts",
|
|
1402
1398
|
...options
|
|
1403
1399
|
});
|
|
1404
1400
|
};
|
|
1405
|
-
var
|
|
1406
|
-
return (options
|
|
1401
|
+
var postContentPosts = (options) => {
|
|
1402
|
+
return (options.client ?? client).post({
|
|
1407
1403
|
security: [
|
|
1408
1404
|
{
|
|
1409
1405
|
name: "Authorization",
|
|
@@ -1415,10 +1411,30 @@ var getContentPosts = (options) => {
|
|
|
1415
1411
|
}
|
|
1416
1412
|
],
|
|
1417
1413
|
url: "/content/posts",
|
|
1414
|
+
...options,
|
|
1415
|
+
headers: {
|
|
1416
|
+
"Content-Type": "application/json",
|
|
1417
|
+
...options?.headers
|
|
1418
|
+
}
|
|
1419
|
+
});
|
|
1420
|
+
};
|
|
1421
|
+
var getContentLivesId = (options) => {
|
|
1422
|
+
return (options.client ?? client).get({
|
|
1423
|
+
security: [
|
|
1424
|
+
{
|
|
1425
|
+
name: "Authorization",
|
|
1426
|
+
type: "apiKey"
|
|
1427
|
+
},
|
|
1428
|
+
{
|
|
1429
|
+
name: "x-api-key",
|
|
1430
|
+
type: "apiKey"
|
|
1431
|
+
}
|
|
1432
|
+
],
|
|
1433
|
+
url: "/content/lives/{id}",
|
|
1418
1434
|
...options
|
|
1419
1435
|
});
|
|
1420
1436
|
};
|
|
1421
|
-
var
|
|
1437
|
+
var postContentPlaybackToken = (options) => {
|
|
1422
1438
|
return (options.client ?? client).post({
|
|
1423
1439
|
security: [
|
|
1424
1440
|
{
|
|
@@ -1430,7 +1446,7 @@ var postContentPosts = (options) => {
|
|
|
1430
1446
|
type: "apiKey"
|
|
1431
1447
|
}
|
|
1432
1448
|
],
|
|
1433
|
-
url: "/content/
|
|
1449
|
+
url: "/content/playback-token",
|
|
1434
1450
|
...options,
|
|
1435
1451
|
headers: {
|
|
1436
1452
|
"Content-Type": "application/json",
|
|
@@ -1438,7 +1454,7 @@ var postContentPosts = (options) => {
|
|
|
1438
1454
|
}
|
|
1439
1455
|
});
|
|
1440
1456
|
};
|
|
1441
|
-
var
|
|
1457
|
+
var getWaitlist = (options) => {
|
|
1442
1458
|
return (options?.client ?? client).get({
|
|
1443
1459
|
security: [
|
|
1444
1460
|
{
|
|
@@ -1450,12 +1466,12 @@ var getContentLives = (options) => {
|
|
|
1450
1466
|
type: "apiKey"
|
|
1451
1467
|
}
|
|
1452
1468
|
],
|
|
1453
|
-
url: "/
|
|
1469
|
+
url: "/waitlist",
|
|
1454
1470
|
...options
|
|
1455
1471
|
});
|
|
1456
1472
|
};
|
|
1457
|
-
var
|
|
1458
|
-
return (options.client ?? client).
|
|
1473
|
+
var postWaitlist = (options) => {
|
|
1474
|
+
return (options.client ?? client).post({
|
|
1459
1475
|
security: [
|
|
1460
1476
|
{
|
|
1461
1477
|
name: "Authorization",
|
|
@@ -1466,11 +1482,31 @@ var getContentLivesId = (options) => {
|
|
|
1466
1482
|
type: "apiKey"
|
|
1467
1483
|
}
|
|
1468
1484
|
],
|
|
1469
|
-
url: "/
|
|
1485
|
+
url: "/waitlist",
|
|
1486
|
+
...options,
|
|
1487
|
+
headers: {
|
|
1488
|
+
"Content-Type": "application/json",
|
|
1489
|
+
...options?.headers
|
|
1490
|
+
}
|
|
1491
|
+
});
|
|
1492
|
+
};
|
|
1493
|
+
var getMerchProducts = (options) => {
|
|
1494
|
+
return (options?.client ?? client).get({
|
|
1495
|
+
security: [
|
|
1496
|
+
{
|
|
1497
|
+
name: "Authorization",
|
|
1498
|
+
type: "apiKey"
|
|
1499
|
+
},
|
|
1500
|
+
{
|
|
1501
|
+
name: "x-api-key",
|
|
1502
|
+
type: "apiKey"
|
|
1503
|
+
}
|
|
1504
|
+
],
|
|
1505
|
+
url: "/merch/products",
|
|
1470
1506
|
...options
|
|
1471
1507
|
});
|
|
1472
1508
|
};
|
|
1473
|
-
var
|
|
1509
|
+
var postMerchProducts = (options) => {
|
|
1474
1510
|
return (options.client ?? client).post({
|
|
1475
1511
|
security: [
|
|
1476
1512
|
{
|
|
@@ -1482,7 +1518,7 @@ var postContentPlaybackToken = (options) => {
|
|
|
1482
1518
|
type: "apiKey"
|
|
1483
1519
|
}
|
|
1484
1520
|
],
|
|
1485
|
-
url: "/
|
|
1521
|
+
url: "/merch/products",
|
|
1486
1522
|
...options,
|
|
1487
1523
|
headers: {
|
|
1488
1524
|
"Content-Type": "application/json",
|
|
@@ -1490,8 +1526,8 @@ var postContentPlaybackToken = (options) => {
|
|
|
1490
1526
|
}
|
|
1491
1527
|
});
|
|
1492
1528
|
};
|
|
1493
|
-
var
|
|
1494
|
-
return (options
|
|
1529
|
+
var patchMerchProductsIdStatus = (options) => {
|
|
1530
|
+
return (options.client ?? client).patch({
|
|
1495
1531
|
security: [
|
|
1496
1532
|
{
|
|
1497
1533
|
name: "Authorization",
|
|
@@ -1502,11 +1538,35 @@ var getWaitlist = (options) => {
|
|
|
1502
1538
|
type: "apiKey"
|
|
1503
1539
|
}
|
|
1504
1540
|
],
|
|
1505
|
-
url: "/
|
|
1506
|
-
...options
|
|
1541
|
+
url: "/merch/products/{id}/status",
|
|
1542
|
+
...options,
|
|
1543
|
+
headers: {
|
|
1544
|
+
"Content-Type": "application/json",
|
|
1545
|
+
...options?.headers
|
|
1546
|
+
}
|
|
1507
1547
|
});
|
|
1508
1548
|
};
|
|
1509
|
-
var
|
|
1549
|
+
var putMerchProductsIdImages = (options) => {
|
|
1550
|
+
return (options.client ?? client).put({
|
|
1551
|
+
security: [
|
|
1552
|
+
{
|
|
1553
|
+
name: "Authorization",
|
|
1554
|
+
type: "apiKey"
|
|
1555
|
+
},
|
|
1556
|
+
{
|
|
1557
|
+
name: "x-api-key",
|
|
1558
|
+
type: "apiKey"
|
|
1559
|
+
}
|
|
1560
|
+
],
|
|
1561
|
+
url: "/merch/products/{id}/images",
|
|
1562
|
+
...options,
|
|
1563
|
+
headers: {
|
|
1564
|
+
"Content-Type": "application/json",
|
|
1565
|
+
...options?.headers
|
|
1566
|
+
}
|
|
1567
|
+
});
|
|
1568
|
+
};
|
|
1569
|
+
var postMerchProductsImagesUploadUrl = (options) => {
|
|
1510
1570
|
return (options.client ?? client).post({
|
|
1511
1571
|
security: [
|
|
1512
1572
|
{
|
|
@@ -1518,7 +1578,7 @@ var postWaitlist = (options) => {
|
|
|
1518
1578
|
type: "apiKey"
|
|
1519
1579
|
}
|
|
1520
1580
|
],
|
|
1521
|
-
url: "/
|
|
1581
|
+
url: "/merch/products/images/upload-url",
|
|
1522
1582
|
...options,
|
|
1523
1583
|
headers: {
|
|
1524
1584
|
"Content-Type": "application/json",
|
|
@@ -1526,6 +1586,42 @@ var postWaitlist = (options) => {
|
|
|
1526
1586
|
}
|
|
1527
1587
|
});
|
|
1528
1588
|
};
|
|
1589
|
+
var postSalesIdRefund = (options) => {
|
|
1590
|
+
return (options.client ?? client).post({
|
|
1591
|
+
security: [
|
|
1592
|
+
{
|
|
1593
|
+
name: "Authorization",
|
|
1594
|
+
type: "apiKey"
|
|
1595
|
+
},
|
|
1596
|
+
{
|
|
1597
|
+
name: "x-api-key",
|
|
1598
|
+
type: "apiKey"
|
|
1599
|
+
}
|
|
1600
|
+
],
|
|
1601
|
+
url: "/sales/{id}/refund",
|
|
1602
|
+
...options,
|
|
1603
|
+
headers: {
|
|
1604
|
+
"Content-Type": "application/json",
|
|
1605
|
+
...options?.headers
|
|
1606
|
+
}
|
|
1607
|
+
});
|
|
1608
|
+
};
|
|
1609
|
+
var postTicketsTicketCodeResend = (options) => {
|
|
1610
|
+
return (options.client ?? client).post({
|
|
1611
|
+
security: [
|
|
1612
|
+
{
|
|
1613
|
+
name: "Authorization",
|
|
1614
|
+
type: "apiKey"
|
|
1615
|
+
},
|
|
1616
|
+
{
|
|
1617
|
+
name: "x-api-key",
|
|
1618
|
+
type: "apiKey"
|
|
1619
|
+
}
|
|
1620
|
+
],
|
|
1621
|
+
url: "/tickets/{ticketCode}/resend",
|
|
1622
|
+
...options
|
|
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
|
|
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 [
|
|
1724
|
+
return [resolve2([pick2, picked])];
|
|
1629
1725
|
}
|
|
1630
|
-
return Object.entries(accounts).map(
|
|
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((
|
|
2760
|
+
return new Promise((resolve2) => {
|
|
2665
2761
|
rl.question(`${question} [y/N] `, (answer) => {
|
|
2666
2762
|
rl.close();
|
|
2667
|
-
|
|
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