@freeticket/cli 0.11.1 → 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.
- package/README.md +5 -0
- package/dist/index.js +672 -47
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -121,6 +121,11 @@ ft sales list --status CONFIRMED --json
|
|
|
121
121
|
| `ft reports reconciliation` · `financials` | CFO reconciliation (Mercado Pago vs sale vs Siigo invoice) · per-function P&L | ADMIN |
|
|
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
|
+
| `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 |
|
|
124
129
|
| `ft api-keys create <name>` · `list` · `revoke <id>` | Self-service API keys (the secret is shown once, never stored) | ADMIN |
|
|
125
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 |
|
|
126
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.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,42 +164,6 @@ 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",
|
|
180
|
-
...options
|
|
181
|
-
});
|
|
182
|
-
};
|
|
183
|
-
var postEventsIdDates = (options) => {
|
|
184
|
-
return (options.client ?? client).post({
|
|
185
|
-
security: [
|
|
186
|
-
{
|
|
187
|
-
name: "Authorization",
|
|
188
|
-
type: "apiKey"
|
|
189
|
-
},
|
|
190
|
-
{
|
|
191
|
-
name: "x-api-key",
|
|
192
|
-
type: "apiKey"
|
|
193
|
-
}
|
|
194
|
-
],
|
|
195
|
-
url: "/events/{id}/dates",
|
|
196
|
-
...options,
|
|
197
|
-
headers: {
|
|
198
|
-
"Content-Type": "application/json",
|
|
199
|
-
...options?.headers
|
|
200
|
-
}
|
|
201
|
-
});
|
|
202
|
-
};
|
|
203
167
|
var postAuthDeviceCode = (options) => {
|
|
204
168
|
return (options?.client ?? client).post({
|
|
205
169
|
url: "/auth/device/code",
|
|
@@ -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: [
|
|
@@ -1282,6 +1282,22 @@ var patchTicketsTicketCode = (options) => {
|
|
|
1282
1282
|
}
|
|
1283
1283
|
});
|
|
1284
1284
|
};
|
|
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
|
+
};
|
|
1285
1301
|
var postTicketsTicketCodeCheckin = (options) => {
|
|
1286
1302
|
return (options.client ?? client).post({
|
|
1287
1303
|
security: [
|
|
@@ -1474,7 +1490,23 @@ var postContentPlaybackToken = (options) => {
|
|
|
1474
1490
|
}
|
|
1475
1491
|
});
|
|
1476
1492
|
};
|
|
1477
|
-
var
|
|
1493
|
+
var getWaitlist = (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: "/waitlist",
|
|
1506
|
+
...options
|
|
1507
|
+
});
|
|
1508
|
+
};
|
|
1509
|
+
var postWaitlist = (options) => {
|
|
1478
1510
|
return (options.client ?? client).post({
|
|
1479
1511
|
security: [
|
|
1480
1512
|
{
|
|
@@ -1486,10 +1518,110 @@ var postTicketsTicketCodeResend = (options) => {
|
|
|
1486
1518
|
type: "apiKey"
|
|
1487
1519
|
}
|
|
1488
1520
|
],
|
|
1489
|
-
url: "/
|
|
1521
|
+
url: "/waitlist",
|
|
1522
|
+
...options,
|
|
1523
|
+
headers: {
|
|
1524
|
+
"Content-Type": "application/json",
|
|
1525
|
+
...options?.headers
|
|
1526
|
+
}
|
|
1527
|
+
});
|
|
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",
|
|
1490
1542
|
...options
|
|
1491
1543
|
});
|
|
1492
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
|
+
};
|
|
1493
1625
|
|
|
1494
1626
|
// src/commands/account.ts
|
|
1495
1627
|
import chalk4 from "chalk";
|
|
@@ -1574,7 +1706,7 @@ function resolveAccounts(file, env, accountFlag2) {
|
|
|
1574
1706
|
];
|
|
1575
1707
|
}
|
|
1576
1708
|
const accounts = file.accounts ?? {};
|
|
1577
|
-
const
|
|
1709
|
+
const resolve2 = ([name, a]) => ({
|
|
1578
1710
|
name,
|
|
1579
1711
|
apiUrl: apiUrl(a),
|
|
1580
1712
|
apiKey: a.apiKey,
|
|
@@ -1589,9 +1721,9 @@ function resolveAccounts(file, env, accountFlag2) {
|
|
|
1589
1721
|
`No account named "${pick2}". Stored: ${names || "(none)"}`
|
|
1590
1722
|
);
|
|
1591
1723
|
}
|
|
1592
|
-
return [
|
|
1724
|
+
return [resolve2([pick2, picked])];
|
|
1593
1725
|
}
|
|
1594
|
-
return Object.entries(accounts).map(
|
|
1726
|
+
return Object.entries(accounts).map(resolve2);
|
|
1595
1727
|
}
|
|
1596
1728
|
function effectiveAccounts(accountFlag2) {
|
|
1597
1729
|
return resolveAccounts(readFile(), process.env, accountFlag2);
|
|
@@ -2579,6 +2711,15 @@ var deleteTokensId = (options) => {
|
|
|
2579
2711
|
// src/lib/input.ts
|
|
2580
2712
|
import { readFileSync as readFileSync3 } from "fs";
|
|
2581
2713
|
import * as readline from "readline";
|
|
2714
|
+
function parseLimit(input) {
|
|
2715
|
+
const n = Number(input);
|
|
2716
|
+
if (!Number.isInteger(n) || n < 1 || n > 100)
|
|
2717
|
+
fail(
|
|
2718
|
+
`Invalid --limit: ${input}. Use an integer from 1 to 100.`,
|
|
2719
|
+
"For more rows, add --all to walk every page."
|
|
2720
|
+
);
|
|
2721
|
+
return n;
|
|
2722
|
+
}
|
|
2582
2723
|
function parseData(input) {
|
|
2583
2724
|
if (!input) {
|
|
2584
2725
|
fail(
|
|
@@ -2616,10 +2757,10 @@ function confirm(question) {
|
|
|
2616
2757
|
input: process.stdin,
|
|
2617
2758
|
output: process.stderr
|
|
2618
2759
|
});
|
|
2619
|
-
return new Promise((
|
|
2760
|
+
return new Promise((resolve2) => {
|
|
2620
2761
|
rl.question(`${question} [y/N] `, (answer) => {
|
|
2621
2762
|
rl.close();
|
|
2622
|
-
|
|
2763
|
+
resolve2(/^y(es)?$/i.test(answer.trim()));
|
|
2623
2764
|
});
|
|
2624
2765
|
});
|
|
2625
2766
|
}
|
|
@@ -2831,7 +2972,7 @@ function registerAdminResource(parent, spec) {
|
|
|
2831
2972
|
configureAdminClient();
|
|
2832
2973
|
const query = {};
|
|
2833
2974
|
if (!spec.noPaging) {
|
|
2834
|
-
query.limit =
|
|
2975
|
+
query.limit = parseLimit(opts.limit);
|
|
2835
2976
|
query.cursor = opts.cursor;
|
|
2836
2977
|
}
|
|
2837
2978
|
for (const f of spec.listFlags ?? []) {
|
|
@@ -2985,7 +3126,7 @@ ${chalk6.green("\u2713")} API key "${chalk6.bold(key.name)}" created (scope: ${k
|
|
|
2985
3126
|
configureClient(opts.workspace);
|
|
2986
3127
|
const columns = resolveColumns(opts, COLUMNS);
|
|
2987
3128
|
const query = {
|
|
2988
|
-
limit: opts.limit,
|
|
3129
|
+
limit: parseLimit(opts.limit),
|
|
2989
3130
|
cursor: opts.cursor
|
|
2990
3131
|
};
|
|
2991
3132
|
if (opts.all) {
|
|
@@ -3074,6 +3215,474 @@ function registerEventDates(program2, spec) {
|
|
|
3074
3215
|
});
|
|
3075
3216
|
}
|
|
3076
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
|
+
|
|
3077
3686
|
// src/commands/reports.ts
|
|
3078
3687
|
async function reportRows(workspaceFlag, call) {
|
|
3079
3688
|
const targets = await listTargets(workspaceFlag);
|
|
@@ -3279,8 +3888,9 @@ function registerResource(program2, spec) {
|
|
|
3279
3888
|
for (const f of spec.listFlags ?? []) cmd.option(f.flag, f.describe);
|
|
3280
3889
|
cmd.action(async (opts) => {
|
|
3281
3890
|
let columns = resolveColumns(opts, spec.columns);
|
|
3891
|
+
opts.limit = parseLimit(opts.limit);
|
|
3282
3892
|
const query = {
|
|
3283
|
-
limit:
|
|
3893
|
+
limit: opts.limit,
|
|
3284
3894
|
cursor: opts.cursor
|
|
3285
3895
|
};
|
|
3286
3896
|
for (const f of spec.listFlags ?? []) {
|
|
@@ -3925,6 +4535,21 @@ registerResource(program, {
|
|
|
3925
4535
|
});
|
|
3926
4536
|
}
|
|
3927
4537
|
});
|
|
4538
|
+
registerResource(program, {
|
|
4539
|
+
name: "waitlist",
|
|
4540
|
+
describe: "Per-city waitlist entries of an enterprise landing",
|
|
4541
|
+
list: getWaitlist,
|
|
4542
|
+
create: postWaitlist,
|
|
4543
|
+
columns: ["id", "city", "name", "contact", "source", "createdAt"],
|
|
4544
|
+
listFlags: [
|
|
4545
|
+
{
|
|
4546
|
+
flag: "--city <name>",
|
|
4547
|
+
describe: "filter by city (accents/case ignored)",
|
|
4548
|
+
query: "city"
|
|
4549
|
+
}
|
|
4550
|
+
]
|
|
4551
|
+
});
|
|
4552
|
+
registerMerch(program);
|
|
3928
4553
|
registerTickets(program);
|
|
3929
4554
|
registerReports(program);
|
|
3930
4555
|
registerApiKeys(program);
|
package/package.json
CHANGED