@freeticket/cli 0.13.1 → 0.15.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 +161 -1
- package/dist/index.js +1381 -165
- package/package.json +1 -1
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.15.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,35 +164,15 @@ var client = createClient(createConfig({
|
|
|
164
164
|
}));
|
|
165
165
|
|
|
166
166
|
// src/client/sdk.gen.ts
|
|
167
|
-
var
|
|
168
|
-
return (options
|
|
169
|
-
|
|
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
|
|
173
|
+
var postAuthDeviceToken = (options) => {
|
|
184
174
|
return (options.client ?? client).post({
|
|
185
|
-
|
|
186
|
-
{
|
|
187
|
-
name: "Authorization",
|
|
188
|
-
type: "apiKey"
|
|
189
|
-
},
|
|
190
|
-
{
|
|
191
|
-
name: "x-api-key",
|
|
192
|
-
type: "apiKey"
|
|
193
|
-
}
|
|
194
|
-
],
|
|
195
|
-
url: "/events/{id}/dates",
|
|
175
|
+
url: "/auth/device/token",
|
|
196
176
|
...options,
|
|
197
177
|
headers: {
|
|
198
178
|
"Content-Type": "application/json",
|
|
@@ -200,23 +180,17 @@ var postEventsIdDates = (options) => {
|
|
|
200
180
|
}
|
|
201
181
|
});
|
|
202
182
|
};
|
|
203
|
-
var
|
|
204
|
-
return (options
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
name: "x-api-key",
|
|
212
|
-
type: "apiKey"
|
|
213
|
-
}
|
|
214
|
-
],
|
|
215
|
-
url: "/events",
|
|
216
|
-
...options
|
|
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
|
+
}
|
|
217
191
|
});
|
|
218
192
|
};
|
|
219
|
-
var
|
|
193
|
+
var postWorkspaces = (options) => {
|
|
220
194
|
return (options.client ?? client).post({
|
|
221
195
|
security: [
|
|
222
196
|
{
|
|
@@ -228,7 +202,7 @@ var postEvents = (options) => {
|
|
|
228
202
|
type: "apiKey"
|
|
229
203
|
}
|
|
230
204
|
],
|
|
231
|
-
url: "/
|
|
205
|
+
url: "/workspaces",
|
|
232
206
|
...options,
|
|
233
207
|
headers: {
|
|
234
208
|
"Content-Type": "application/json",
|
|
@@ -236,7 +210,7 @@ var postEvents = (options) => {
|
|
|
236
210
|
}
|
|
237
211
|
});
|
|
238
212
|
};
|
|
239
|
-
var
|
|
213
|
+
var getMe = (options) => {
|
|
240
214
|
return (options?.client ?? client).get({
|
|
241
215
|
security: [
|
|
242
216
|
{
|
|
@@ -248,11 +222,11 @@ var getContentVideos = (options) => {
|
|
|
248
222
|
type: "apiKey"
|
|
249
223
|
}
|
|
250
224
|
],
|
|
251
|
-
url: "/
|
|
225
|
+
url: "/me",
|
|
252
226
|
...options
|
|
253
227
|
});
|
|
254
228
|
};
|
|
255
|
-
var
|
|
229
|
+
var getEvents = (options) => {
|
|
256
230
|
return (options?.client ?? client).get({
|
|
257
231
|
security: [
|
|
258
232
|
{
|
|
@@ -264,37 +238,11 @@ var getContentLives = (options) => {
|
|
|
264
238
|
type: "apiKey"
|
|
265
239
|
}
|
|
266
240
|
],
|
|
267
|
-
url: "/
|
|
268
|
-
...options
|
|
269
|
-
});
|
|
270
|
-
};
|
|
271
|
-
var postAuthDeviceCode = (options) => {
|
|
272
|
-
return (options?.client ?? client).post({
|
|
273
|
-
url: "/auth/device/code",
|
|
241
|
+
url: "/events",
|
|
274
242
|
...options
|
|
275
243
|
});
|
|
276
244
|
};
|
|
277
|
-
var
|
|
278
|
-
return (options.client ?? client).post({
|
|
279
|
-
url: "/auth/device/token",
|
|
280
|
-
...options,
|
|
281
|
-
headers: {
|
|
282
|
-
"Content-Type": "application/json",
|
|
283
|
-
...options?.headers
|
|
284
|
-
}
|
|
285
|
-
});
|
|
286
|
-
};
|
|
287
|
-
var postAuthSignup = (options) => {
|
|
288
|
-
return (options.client ?? client).post({
|
|
289
|
-
url: "/auth/signup",
|
|
290
|
-
...options,
|
|
291
|
-
headers: {
|
|
292
|
-
"Content-Type": "application/json",
|
|
293
|
-
...options?.headers
|
|
294
|
-
}
|
|
295
|
-
});
|
|
296
|
-
};
|
|
297
|
-
var postWorkspaces = (options) => {
|
|
245
|
+
var postEvents = (options) => {
|
|
298
246
|
return (options.client ?? client).post({
|
|
299
247
|
security: [
|
|
300
248
|
{
|
|
@@ -306,7 +254,7 @@ var postWorkspaces = (options) => {
|
|
|
306
254
|
type: "apiKey"
|
|
307
255
|
}
|
|
308
256
|
],
|
|
309
|
-
url: "/
|
|
257
|
+
url: "/events",
|
|
310
258
|
...options,
|
|
311
259
|
headers: {
|
|
312
260
|
"Content-Type": "application/json",
|
|
@@ -314,22 +262,6 @@ var postWorkspaces = (options) => {
|
|
|
314
262
|
}
|
|
315
263
|
});
|
|
316
264
|
};
|
|
317
|
-
var getMe = (options) => {
|
|
318
|
-
return (options?.client ?? client).get({
|
|
319
|
-
security: [
|
|
320
|
-
{
|
|
321
|
-
name: "Authorization",
|
|
322
|
-
type: "apiKey"
|
|
323
|
-
},
|
|
324
|
-
{
|
|
325
|
-
name: "x-api-key",
|
|
326
|
-
type: "apiKey"
|
|
327
|
-
}
|
|
328
|
-
],
|
|
329
|
-
url: "/me",
|
|
330
|
-
...options
|
|
331
|
-
});
|
|
332
|
-
};
|
|
333
265
|
var deleteEventsId = (options) => {
|
|
334
266
|
return (options.client ?? client).delete({
|
|
335
267
|
security: [
|
|
@@ -414,6 +346,42 @@ var postEventsIdCancel = (options) => {
|
|
|
414
346
|
...options
|
|
415
347
|
});
|
|
416
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
|
+
};
|
|
417
385
|
var deleteEventsIdDatesDateId = (options) => {
|
|
418
386
|
return (options.client ?? client).delete({
|
|
419
387
|
security: [
|
|
@@ -610,6 +578,26 @@ var postSalesIdCancel = (options) => {
|
|
|
610
578
|
}
|
|
611
579
|
});
|
|
612
580
|
};
|
|
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
|
+
};
|
|
613
601
|
var getMembershipPlans = (options) => {
|
|
614
602
|
return (options?.client ?? client).get({
|
|
615
603
|
security: [
|
|
@@ -1294,6 +1282,22 @@ var patchTicketsTicketCode = (options) => {
|
|
|
1294
1282
|
}
|
|
1295
1283
|
});
|
|
1296
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
|
+
};
|
|
1297
1301
|
var postTicketsTicketCodeCheckin = (options) => {
|
|
1298
1302
|
return (options.client ?? client).post({
|
|
1299
1303
|
security: [
|
|
@@ -1382,6 +1386,22 @@ var deleteApiKeysId = (options) => {
|
|
|
1382
1386
|
...options
|
|
1383
1387
|
});
|
|
1384
1388
|
};
|
|
1389
|
+
var getContentVideos = (options) => {
|
|
1390
|
+
return (options?.client ?? client).get({
|
|
1391
|
+
security: [
|
|
1392
|
+
{
|
|
1393
|
+
name: "Authorization",
|
|
1394
|
+
type: "apiKey"
|
|
1395
|
+
},
|
|
1396
|
+
{
|
|
1397
|
+
name: "x-api-key",
|
|
1398
|
+
type: "apiKey"
|
|
1399
|
+
}
|
|
1400
|
+
],
|
|
1401
|
+
url: "/content/videos",
|
|
1402
|
+
...options
|
|
1403
|
+
});
|
|
1404
|
+
};
|
|
1385
1405
|
var getContentPosts = (options) => {
|
|
1386
1406
|
return (options?.client ?? client).get({
|
|
1387
1407
|
security: [
|
|
@@ -1418,6 +1438,22 @@ var postContentPosts = (options) => {
|
|
|
1418
1438
|
}
|
|
1419
1439
|
});
|
|
1420
1440
|
};
|
|
1441
|
+
var getContentLives = (options) => {
|
|
1442
|
+
return (options?.client ?? client).get({
|
|
1443
|
+
security: [
|
|
1444
|
+
{
|
|
1445
|
+
name: "Authorization",
|
|
1446
|
+
type: "apiKey"
|
|
1447
|
+
},
|
|
1448
|
+
{
|
|
1449
|
+
name: "x-api-key",
|
|
1450
|
+
type: "apiKey"
|
|
1451
|
+
}
|
|
1452
|
+
],
|
|
1453
|
+
url: "/content/lives",
|
|
1454
|
+
...options
|
|
1455
|
+
});
|
|
1456
|
+
};
|
|
1421
1457
|
var getContentLivesId = (options) => {
|
|
1422
1458
|
return (options.client ?? client).get({
|
|
1423
1459
|
security: [
|
|
@@ -1490,6 +1526,26 @@ var postWaitlist = (options) => {
|
|
|
1490
1526
|
}
|
|
1491
1527
|
});
|
|
1492
1528
|
};
|
|
1529
|
+
var postCourtesyRequests = (options) => {
|
|
1530
|
+
return (options.client ?? client).post({
|
|
1531
|
+
security: [
|
|
1532
|
+
{
|
|
1533
|
+
name: "Authorization",
|
|
1534
|
+
type: "apiKey"
|
|
1535
|
+
},
|
|
1536
|
+
{
|
|
1537
|
+
name: "x-api-key",
|
|
1538
|
+
type: "apiKey"
|
|
1539
|
+
}
|
|
1540
|
+
],
|
|
1541
|
+
url: "/courtesy-requests",
|
|
1542
|
+
...options,
|
|
1543
|
+
headers: {
|
|
1544
|
+
"Content-Type": "application/json",
|
|
1545
|
+
...options?.headers
|
|
1546
|
+
}
|
|
1547
|
+
});
|
|
1548
|
+
};
|
|
1493
1549
|
var getMerchProducts = (options) => {
|
|
1494
1550
|
return (options?.client ?? client).get({
|
|
1495
1551
|
security: [
|
|
@@ -1586,42 +1642,6 @@ var postMerchProductsImagesUploadUrl = (options) => {
|
|
|
1586
1642
|
}
|
|
1587
1643
|
});
|
|
1588
1644
|
};
|
|
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
|
-
};
|
|
1625
1645
|
|
|
1626
1646
|
// src/commands/account.ts
|
|
1627
1647
|
import chalk4 from "chalk";
|
|
@@ -1811,15 +1831,26 @@ function configureClient(workspaceOverride, account = resolveAccount()) {
|
|
|
1811
1831
|
}
|
|
1812
1832
|
function configureAdminClient() {
|
|
1813
1833
|
const cfg = loadConfig();
|
|
1834
|
+
const baseUrl = `${cfg.apiUrl.replace(/\/$/, "")}/api/admin`;
|
|
1835
|
+
const token = process.env.FT_ADMIN_TOKEN?.trim();
|
|
1836
|
+
if (token) {
|
|
1837
|
+
client2.setConfig({
|
|
1838
|
+
baseUrl,
|
|
1839
|
+
// setConfig merges headers: null drops a credential left by an earlier call.
|
|
1840
|
+
headers: { Authorization: `Bearer ${token}`, Cookie: null }
|
|
1841
|
+
});
|
|
1842
|
+
return;
|
|
1843
|
+
}
|
|
1814
1844
|
if (!cfg.adminSession) {
|
|
1815
1845
|
fail(
|
|
1816
|
-
"No superadmin
|
|
1817
|
-
"
|
|
1846
|
+
"No superadmin credential. Export FT_ADMIN_TOKEN with a service token, or FT_ADMIN_SESSION with a SUPER_ADMIN better-auth session token.",
|
|
1847
|
+
"Mint a token with `ft admin tokens create`, or log in to the admin panel and copy the `better-auth.session_token` cookie (`ft admin login --session <token>`)."
|
|
1818
1848
|
);
|
|
1819
1849
|
}
|
|
1820
1850
|
client2.setConfig({
|
|
1821
|
-
baseUrl
|
|
1851
|
+
baseUrl,
|
|
1822
1852
|
headers: {
|
|
1853
|
+
Authorization: null,
|
|
1823
1854
|
Cookie: `better-auth.session_token=${cfg.adminSession}`
|
|
1824
1855
|
}
|
|
1825
1856
|
});
|
|
@@ -1846,7 +1877,7 @@ function unwrap(res) {
|
|
|
1846
1877
|
const lines = [
|
|
1847
1878
|
`Error ${status ?? ""} [${err.code ?? "?"}]: ${err.message ?? "unknown failure"}`.trim()
|
|
1848
1879
|
];
|
|
1849
|
-
for (const d of err.details
|
|
1880
|
+
for (const d of Array.isArray(err.details) ? err.details : [])
|
|
1850
1881
|
lines.push(` \xB7 ${d.path ?? ""}: ${d.message ?? ""}`.trimEnd());
|
|
1851
1882
|
fail(lines.join("\n"), hintFor(status));
|
|
1852
1883
|
}
|
|
@@ -2064,9 +2095,12 @@ function registerAuth(program2) {
|
|
|
2064
2095
|
).option(
|
|
2065
2096
|
"--workspace <id>",
|
|
2066
2097
|
"pin this login to one workspace (default: every workspace the account reaches)"
|
|
2098
|
+
).option(
|
|
2099
|
+
"--read-only",
|
|
2100
|
+
"ask for a read-only key (GET only; any write answers 403) and refuse to save one that is not. Not a sandbox: the real gate is the person approving in the browser"
|
|
2067
2101
|
).option("--json", "raw JSON output (confirmation goes to stderr)").action(async (opts) => {
|
|
2068
2102
|
const apiUrl = opts.url ?? process.env.FT_API_URL ?? readConfig().apiUrl ?? DEFAULT_API_URL;
|
|
2069
|
-
const apiKey = opts.key ?? await deviceLogin(apiUrl);
|
|
2103
|
+
const apiKey = opts.key ?? await deviceLogin(apiUrl, opts.readOnly);
|
|
2070
2104
|
const workspaceId = opts.workspace;
|
|
2071
2105
|
configureClient(workspaceId, {
|
|
2072
2106
|
name: opts.account ?? LEGACY_ACCOUNT,
|
|
@@ -2075,6 +2109,8 @@ function registerAuth(program2) {
|
|
|
2075
2109
|
workspaceId
|
|
2076
2110
|
});
|
|
2077
2111
|
const me = unwrap(await getMe({})).data;
|
|
2112
|
+
const refusal = readOnlyRefusal(opts.readOnly, me.scope);
|
|
2113
|
+
if (refusal) fail(refusal);
|
|
2078
2114
|
const { name, replaces } = loginTarget(
|
|
2079
2115
|
readConfig(),
|
|
2080
2116
|
me.email,
|
|
@@ -2091,7 +2127,7 @@ function registerAuth(program2) {
|
|
|
2091
2127
|
replaces
|
|
2092
2128
|
);
|
|
2093
2129
|
console.error(
|
|
2094
|
-
`${chalk3.green("\u2713")} Account ${chalk3.bold(name)} saved in ${chalk3.dim(CONFIG_PATH)}`
|
|
2130
|
+
`${chalk3.green("\u2713")} Account ${chalk3.bold(name)} saved in ${chalk3.dim(CONFIG_PATH)}` + (me.scope === "read" ? chalk3.yellow(" (read-only)") : "")
|
|
2095
2131
|
);
|
|
2096
2132
|
const { activeAccount, accounts } = readConfig();
|
|
2097
2133
|
if (activeAccount && activeAccount !== name) {
|
|
@@ -2165,6 +2201,7 @@ function registerAuth(program2) {
|
|
|
2165
2201
|
account: m.account,
|
|
2166
2202
|
email: m.email,
|
|
2167
2203
|
name: m.name,
|
|
2204
|
+
scope: m.scope,
|
|
2168
2205
|
workspaces: m.workspaces.map((w) => w.slug).join(", ")
|
|
2169
2206
|
}))
|
|
2170
2207
|
);
|
|
@@ -2223,6 +2260,15 @@ function registerAuth(program2) {
|
|
|
2223
2260
|
);
|
|
2224
2261
|
});
|
|
2225
2262
|
}
|
|
2263
|
+
function withQuery(url, key, value) {
|
|
2264
|
+
const u = new URL(url);
|
|
2265
|
+
u.searchParams.set(key, value);
|
|
2266
|
+
return u.toString();
|
|
2267
|
+
}
|
|
2268
|
+
function readOnlyRefusal(readOnly, scope) {
|
|
2269
|
+
if (!readOnly || scope === "read") return null;
|
|
2270
|
+
return "That key can write (the read-only box was unticked, or --key is a write key). Nothing was saved.";
|
|
2271
|
+
}
|
|
2226
2272
|
function mask(secret) {
|
|
2227
2273
|
return `${secret.slice(0, 12)}\u2026`;
|
|
2228
2274
|
}
|
|
@@ -2234,7 +2280,7 @@ function openBrowser(url) {
|
|
|
2234
2280
|
} catch {
|
|
2235
2281
|
}
|
|
2236
2282
|
}
|
|
2237
|
-
async function deviceLogin(baseUrl) {
|
|
2283
|
+
async function deviceLogin(baseUrl, readOnly = false) {
|
|
2238
2284
|
const apiUrl = baseUrl.replace(/\/$/, "");
|
|
2239
2285
|
client.setConfig({ baseUrl: `${apiUrl}/api/v1` });
|
|
2240
2286
|
const start = unwrap(await postAuthDeviceCode({}));
|
|
@@ -2247,7 +2293,9 @@ Open ${chalk3.cyan(start.verification_uri)} and enter the code:
|
|
|
2247
2293
|
${chalk3.dim("Opening your browser\u2026 (Ctrl+C to cancel)")}
|
|
2248
2294
|
`
|
|
2249
2295
|
);
|
|
2250
|
-
openBrowser(
|
|
2296
|
+
openBrowser(
|
|
2297
|
+
readOnly ? withQuery(start.verification_uri_complete, "scope", "read") : start.verification_uri_complete
|
|
2298
|
+
);
|
|
2251
2299
|
const deadline = Date.now() + start.expires_in * 1e3;
|
|
2252
2300
|
let interval = start.interval;
|
|
2253
2301
|
while (Date.now() < deadline) {
|
|
@@ -2343,7 +2391,7 @@ function registerAccount(program2) {
|
|
|
2343
2391
|
}
|
|
2344
2392
|
|
|
2345
2393
|
// src/commands/admin.ts
|
|
2346
|
-
import
|
|
2394
|
+
import chalk7 from "chalk";
|
|
2347
2395
|
|
|
2348
2396
|
// src/admin-client/sdk.gen.ts
|
|
2349
2397
|
var getMe2 = (options) => {
|
|
@@ -2677,7 +2725,397 @@ var getTokens = (options) => {
|
|
|
2677
2725
|
...options
|
|
2678
2726
|
});
|
|
2679
2727
|
};
|
|
2680
|
-
var postTokens = (options) => {
|
|
2728
|
+
var postTokens = (options) => {
|
|
2729
|
+
return (options.client ?? client2).post({
|
|
2730
|
+
security: [
|
|
2731
|
+
{
|
|
2732
|
+
in: "cookie",
|
|
2733
|
+
name: "better-auth.session_token",
|
|
2734
|
+
type: "apiKey"
|
|
2735
|
+
}
|
|
2736
|
+
],
|
|
2737
|
+
url: "/tokens",
|
|
2738
|
+
...options,
|
|
2739
|
+
headers: {
|
|
2740
|
+
"Content-Type": "application/json",
|
|
2741
|
+
...options?.headers
|
|
2742
|
+
}
|
|
2743
|
+
});
|
|
2744
|
+
};
|
|
2745
|
+
var deleteTokensId = (options) => {
|
|
2746
|
+
return (options.client ?? client2).delete({
|
|
2747
|
+
security: [
|
|
2748
|
+
{
|
|
2749
|
+
in: "cookie",
|
|
2750
|
+
name: "better-auth.session_token",
|
|
2751
|
+
type: "apiKey"
|
|
2752
|
+
}
|
|
2753
|
+
],
|
|
2754
|
+
url: "/tokens/{id}",
|
|
2755
|
+
...options
|
|
2756
|
+
});
|
|
2757
|
+
};
|
|
2758
|
+
var getCrmCampaigns = (options) => {
|
|
2759
|
+
return (options?.client ?? client2).get({
|
|
2760
|
+
security: [
|
|
2761
|
+
{
|
|
2762
|
+
in: "cookie",
|
|
2763
|
+
name: "better-auth.session_token",
|
|
2764
|
+
type: "apiKey"
|
|
2765
|
+
}
|
|
2766
|
+
],
|
|
2767
|
+
url: "/crm/campaigns",
|
|
2768
|
+
...options
|
|
2769
|
+
});
|
|
2770
|
+
};
|
|
2771
|
+
var postCrmCampaigns = (options) => {
|
|
2772
|
+
return (options.client ?? client2).post({
|
|
2773
|
+
security: [
|
|
2774
|
+
{
|
|
2775
|
+
in: "cookie",
|
|
2776
|
+
name: "better-auth.session_token",
|
|
2777
|
+
type: "apiKey"
|
|
2778
|
+
}
|
|
2779
|
+
],
|
|
2780
|
+
url: "/crm/campaigns",
|
|
2781
|
+
...options,
|
|
2782
|
+
headers: {
|
|
2783
|
+
"Content-Type": "application/json",
|
|
2784
|
+
...options?.headers
|
|
2785
|
+
}
|
|
2786
|
+
});
|
|
2787
|
+
};
|
|
2788
|
+
var getCrmCampaignsId = (options) => {
|
|
2789
|
+
return (options.client ?? client2).get({
|
|
2790
|
+
security: [
|
|
2791
|
+
{
|
|
2792
|
+
in: "cookie",
|
|
2793
|
+
name: "better-auth.session_token",
|
|
2794
|
+
type: "apiKey"
|
|
2795
|
+
}
|
|
2796
|
+
],
|
|
2797
|
+
url: "/crm/campaigns/{id}",
|
|
2798
|
+
...options
|
|
2799
|
+
});
|
|
2800
|
+
};
|
|
2801
|
+
var postCrmCampaignsIdBatchesNext = (options) => {
|
|
2802
|
+
return (options.client ?? client2).post({
|
|
2803
|
+
security: [
|
|
2804
|
+
{
|
|
2805
|
+
in: "cookie",
|
|
2806
|
+
name: "better-auth.session_token",
|
|
2807
|
+
type: "apiKey"
|
|
2808
|
+
}
|
|
2809
|
+
],
|
|
2810
|
+
url: "/crm/campaigns/{id}/batches/next",
|
|
2811
|
+
...options,
|
|
2812
|
+
headers: {
|
|
2813
|
+
"Content-Type": "application/json",
|
|
2814
|
+
...options?.headers
|
|
2815
|
+
}
|
|
2816
|
+
});
|
|
2817
|
+
};
|
|
2818
|
+
var postCrmCampaignsIdBatchesStop = (options) => {
|
|
2819
|
+
return (options.client ?? client2).post({
|
|
2820
|
+
security: [
|
|
2821
|
+
{
|
|
2822
|
+
in: "cookie",
|
|
2823
|
+
name: "better-auth.session_token",
|
|
2824
|
+
type: "apiKey"
|
|
2825
|
+
}
|
|
2826
|
+
],
|
|
2827
|
+
url: "/crm/campaigns/{id}/batches/stop",
|
|
2828
|
+
...options
|
|
2829
|
+
});
|
|
2830
|
+
};
|
|
2831
|
+
var postCrmCampaignsIdCancel = (options) => {
|
|
2832
|
+
return (options.client ?? client2).post({
|
|
2833
|
+
security: [
|
|
2834
|
+
{
|
|
2835
|
+
in: "cookie",
|
|
2836
|
+
name: "better-auth.session_token",
|
|
2837
|
+
type: "apiKey"
|
|
2838
|
+
}
|
|
2839
|
+
],
|
|
2840
|
+
url: "/crm/campaigns/{id}/cancel",
|
|
2841
|
+
...options
|
|
2842
|
+
});
|
|
2843
|
+
};
|
|
2844
|
+
var postCrmAudiencePreview = (options) => {
|
|
2845
|
+
return (options.client ?? client2).post({
|
|
2846
|
+
security: [
|
|
2847
|
+
{
|
|
2848
|
+
in: "cookie",
|
|
2849
|
+
name: "better-auth.session_token",
|
|
2850
|
+
type: "apiKey"
|
|
2851
|
+
}
|
|
2852
|
+
],
|
|
2853
|
+
url: "/crm/audience/preview",
|
|
2854
|
+
...options,
|
|
2855
|
+
headers: {
|
|
2856
|
+
"Content-Type": "application/json",
|
|
2857
|
+
...options?.headers
|
|
2858
|
+
}
|
|
2859
|
+
});
|
|
2860
|
+
};
|
|
2861
|
+
var getCrmQuota = (options) => {
|
|
2862
|
+
return (options?.client ?? client2).get({
|
|
2863
|
+
security: [
|
|
2864
|
+
{
|
|
2865
|
+
in: "cookie",
|
|
2866
|
+
name: "better-auth.session_token",
|
|
2867
|
+
type: "apiKey"
|
|
2868
|
+
}
|
|
2869
|
+
],
|
|
2870
|
+
url: "/crm/quota",
|
|
2871
|
+
...options
|
|
2872
|
+
});
|
|
2873
|
+
};
|
|
2874
|
+
var getCrmOptions = (options) => {
|
|
2875
|
+
return (options?.client ?? client2).get({
|
|
2876
|
+
security: [
|
|
2877
|
+
{
|
|
2878
|
+
in: "cookie",
|
|
2879
|
+
name: "better-auth.session_token",
|
|
2880
|
+
type: "apiKey"
|
|
2881
|
+
}
|
|
2882
|
+
],
|
|
2883
|
+
url: "/crm/options",
|
|
2884
|
+
...options
|
|
2885
|
+
});
|
|
2886
|
+
};
|
|
2887
|
+
var getCrmEvents = (options) => {
|
|
2888
|
+
return (options.client ?? client2).get({
|
|
2889
|
+
security: [
|
|
2890
|
+
{
|
|
2891
|
+
in: "cookie",
|
|
2892
|
+
name: "better-auth.session_token",
|
|
2893
|
+
type: "apiKey"
|
|
2894
|
+
}
|
|
2895
|
+
],
|
|
2896
|
+
url: "/crm/events",
|
|
2897
|
+
...options
|
|
2898
|
+
});
|
|
2899
|
+
};
|
|
2900
|
+
var getCrmEventDates = (options) => {
|
|
2901
|
+
return (options.client ?? client2).get({
|
|
2902
|
+
security: [
|
|
2903
|
+
{
|
|
2904
|
+
in: "cookie",
|
|
2905
|
+
name: "better-auth.session_token",
|
|
2906
|
+
type: "apiKey"
|
|
2907
|
+
}
|
|
2908
|
+
],
|
|
2909
|
+
url: "/crm/event-dates",
|
|
2910
|
+
...options
|
|
2911
|
+
});
|
|
2912
|
+
};
|
|
2913
|
+
var deleteCrmSuppressions = (options) => {
|
|
2914
|
+
return (options.client ?? client2).delete({
|
|
2915
|
+
security: [
|
|
2916
|
+
{
|
|
2917
|
+
in: "cookie",
|
|
2918
|
+
name: "better-auth.session_token",
|
|
2919
|
+
type: "apiKey"
|
|
2920
|
+
}
|
|
2921
|
+
],
|
|
2922
|
+
url: "/crm/suppressions",
|
|
2923
|
+
...options,
|
|
2924
|
+
headers: {
|
|
2925
|
+
"Content-Type": "application/json",
|
|
2926
|
+
...options?.headers
|
|
2927
|
+
}
|
|
2928
|
+
});
|
|
2929
|
+
};
|
|
2930
|
+
var getCrmSuppressions = (options) => {
|
|
2931
|
+
return (options?.client ?? client2).get({
|
|
2932
|
+
security: [
|
|
2933
|
+
{
|
|
2934
|
+
in: "cookie",
|
|
2935
|
+
name: "better-auth.session_token",
|
|
2936
|
+
type: "apiKey"
|
|
2937
|
+
}
|
|
2938
|
+
],
|
|
2939
|
+
url: "/crm/suppressions",
|
|
2940
|
+
...options
|
|
2941
|
+
});
|
|
2942
|
+
};
|
|
2943
|
+
var postCrmSuppressions = (options) => {
|
|
2944
|
+
return (options.client ?? client2).post({
|
|
2945
|
+
security: [
|
|
2946
|
+
{
|
|
2947
|
+
in: "cookie",
|
|
2948
|
+
name: "better-auth.session_token",
|
|
2949
|
+
type: "apiKey"
|
|
2950
|
+
}
|
|
2951
|
+
],
|
|
2952
|
+
url: "/crm/suppressions",
|
|
2953
|
+
...options,
|
|
2954
|
+
headers: {
|
|
2955
|
+
"Content-Type": "application/json",
|
|
2956
|
+
...options?.headers
|
|
2957
|
+
}
|
|
2958
|
+
});
|
|
2959
|
+
};
|
|
2960
|
+
var postCrmTestSend = (options) => {
|
|
2961
|
+
return (options.client ?? client2).post({
|
|
2962
|
+
security: [
|
|
2963
|
+
{
|
|
2964
|
+
in: "cookie",
|
|
2965
|
+
name: "better-auth.session_token",
|
|
2966
|
+
type: "apiKey"
|
|
2967
|
+
}
|
|
2968
|
+
],
|
|
2969
|
+
url: "/crm/test-send",
|
|
2970
|
+
...options,
|
|
2971
|
+
headers: {
|
|
2972
|
+
"Content-Type": "application/json",
|
|
2973
|
+
...options?.headers
|
|
2974
|
+
}
|
|
2975
|
+
});
|
|
2976
|
+
};
|
|
2977
|
+
var getCrmOrganizations = (options) => {
|
|
2978
|
+
return (options?.client ?? client2).get({
|
|
2979
|
+
security: [
|
|
2980
|
+
{
|
|
2981
|
+
in: "cookie",
|
|
2982
|
+
name: "better-auth.session_token",
|
|
2983
|
+
type: "apiKey"
|
|
2984
|
+
}
|
|
2985
|
+
],
|
|
2986
|
+
url: "/crm/organizations",
|
|
2987
|
+
...options
|
|
2988
|
+
});
|
|
2989
|
+
};
|
|
2990
|
+
var postCrmPeopleSearch = (options) => {
|
|
2991
|
+
return (options.client ?? client2).post({
|
|
2992
|
+
security: [
|
|
2993
|
+
{
|
|
2994
|
+
in: "cookie",
|
|
2995
|
+
name: "better-auth.session_token",
|
|
2996
|
+
type: "apiKey"
|
|
2997
|
+
}
|
|
2998
|
+
],
|
|
2999
|
+
url: "/crm/people/search",
|
|
3000
|
+
...options,
|
|
3001
|
+
headers: {
|
|
3002
|
+
"Content-Type": "application/json",
|
|
3003
|
+
...options?.headers
|
|
3004
|
+
}
|
|
3005
|
+
});
|
|
3006
|
+
};
|
|
3007
|
+
var getSettlements2 = (options) => {
|
|
3008
|
+
return (options?.client ?? client2).get({
|
|
3009
|
+
security: [
|
|
3010
|
+
{
|
|
3011
|
+
in: "cookie",
|
|
3012
|
+
name: "better-auth.session_token",
|
|
3013
|
+
type: "apiKey"
|
|
3014
|
+
}
|
|
3015
|
+
],
|
|
3016
|
+
url: "/settlements",
|
|
3017
|
+
...options
|
|
3018
|
+
});
|
|
3019
|
+
};
|
|
3020
|
+
var postSettlements = (options) => {
|
|
3021
|
+
return (options.client ?? client2).post({
|
|
3022
|
+
security: [
|
|
3023
|
+
{
|
|
3024
|
+
in: "cookie",
|
|
3025
|
+
name: "better-auth.session_token",
|
|
3026
|
+
type: "apiKey"
|
|
3027
|
+
}
|
|
3028
|
+
],
|
|
3029
|
+
url: "/settlements",
|
|
3030
|
+
...options,
|
|
3031
|
+
headers: {
|
|
3032
|
+
"Content-Type": "application/json",
|
|
3033
|
+
...options?.headers
|
|
3034
|
+
}
|
|
3035
|
+
});
|
|
3036
|
+
};
|
|
3037
|
+
var postSettlementsFiles = (options) => {
|
|
3038
|
+
return (options.client ?? client2).post({
|
|
3039
|
+
security: [
|
|
3040
|
+
{
|
|
3041
|
+
in: "cookie",
|
|
3042
|
+
name: "better-auth.session_token",
|
|
3043
|
+
type: "apiKey"
|
|
3044
|
+
}
|
|
3045
|
+
],
|
|
3046
|
+
url: "/settlements/files",
|
|
3047
|
+
...options,
|
|
3048
|
+
headers: {
|
|
3049
|
+
"Content-Type": "application/json",
|
|
3050
|
+
...options?.headers
|
|
3051
|
+
}
|
|
3052
|
+
});
|
|
3053
|
+
};
|
|
3054
|
+
var deleteSettlementsId = (options) => {
|
|
3055
|
+
return (options.client ?? client2).delete({
|
|
3056
|
+
security: [
|
|
3057
|
+
{
|
|
3058
|
+
in: "cookie",
|
|
3059
|
+
name: "better-auth.session_token",
|
|
3060
|
+
type: "apiKey"
|
|
3061
|
+
}
|
|
3062
|
+
],
|
|
3063
|
+
url: "/settlements/{id}",
|
|
3064
|
+
...options,
|
|
3065
|
+
headers: {
|
|
3066
|
+
"Content-Type": "application/json",
|
|
3067
|
+
...options?.headers
|
|
3068
|
+
}
|
|
3069
|
+
});
|
|
3070
|
+
};
|
|
3071
|
+
var getSettlementsId2 = (options) => {
|
|
3072
|
+
return (options.client ?? client2).get({
|
|
3073
|
+
security: [
|
|
3074
|
+
{
|
|
3075
|
+
in: "cookie",
|
|
3076
|
+
name: "better-auth.session_token",
|
|
3077
|
+
type: "apiKey"
|
|
3078
|
+
}
|
|
3079
|
+
],
|
|
3080
|
+
url: "/settlements/{id}",
|
|
3081
|
+
...options
|
|
3082
|
+
});
|
|
3083
|
+
};
|
|
3084
|
+
var postSettlementsIdRegenerate = (options) => {
|
|
3085
|
+
return (options.client ?? client2).post({
|
|
3086
|
+
security: [
|
|
3087
|
+
{
|
|
3088
|
+
in: "cookie",
|
|
3089
|
+
name: "better-auth.session_token",
|
|
3090
|
+
type: "apiKey"
|
|
3091
|
+
}
|
|
3092
|
+
],
|
|
3093
|
+
url: "/settlements/{id}/regenerate",
|
|
3094
|
+
...options,
|
|
3095
|
+
headers: {
|
|
3096
|
+
"Content-Type": "application/json",
|
|
3097
|
+
...options?.headers
|
|
3098
|
+
}
|
|
3099
|
+
});
|
|
3100
|
+
};
|
|
3101
|
+
var postSettlementsIdSend = (options) => {
|
|
3102
|
+
return (options.client ?? client2).post({
|
|
3103
|
+
security: [
|
|
3104
|
+
{
|
|
3105
|
+
in: "cookie",
|
|
3106
|
+
name: "better-auth.session_token",
|
|
3107
|
+
type: "apiKey"
|
|
3108
|
+
}
|
|
3109
|
+
],
|
|
3110
|
+
url: "/settlements/{id}/send",
|
|
3111
|
+
...options,
|
|
3112
|
+
headers: {
|
|
3113
|
+
"Content-Type": "application/json",
|
|
3114
|
+
...options?.headers
|
|
3115
|
+
}
|
|
3116
|
+
});
|
|
3117
|
+
};
|
|
3118
|
+
var postSettlementsIdMarkPaid = (options) => {
|
|
2681
3119
|
return (options.client ?? client2).post({
|
|
2682
3120
|
security: [
|
|
2683
3121
|
{
|
|
@@ -2686,7 +3124,7 @@ var postTokens = (options) => {
|
|
|
2686
3124
|
type: "apiKey"
|
|
2687
3125
|
}
|
|
2688
3126
|
],
|
|
2689
|
-
url: "/
|
|
3127
|
+
url: "/settlements/{id}/mark-paid",
|
|
2690
3128
|
...options,
|
|
2691
3129
|
headers: {
|
|
2692
3130
|
"Content-Type": "application/json",
|
|
@@ -2694,8 +3132,8 @@ var postTokens = (options) => {
|
|
|
2694
3132
|
}
|
|
2695
3133
|
});
|
|
2696
3134
|
};
|
|
2697
|
-
var
|
|
2698
|
-
return (options.client ?? client2).
|
|
3135
|
+
var postSettlementsIdProofs = (options) => {
|
|
3136
|
+
return (options.client ?? client2).post({
|
|
2699
3137
|
security: [
|
|
2700
3138
|
{
|
|
2701
3139
|
in: "cookie",
|
|
@@ -2703,8 +3141,12 @@ var deleteTokensId = (options) => {
|
|
|
2703
3141
|
type: "apiKey"
|
|
2704
3142
|
}
|
|
2705
3143
|
],
|
|
2706
|
-
url: "/
|
|
2707
|
-
...options
|
|
3144
|
+
url: "/settlements/{id}/proofs",
|
|
3145
|
+
...options,
|
|
3146
|
+
headers: {
|
|
3147
|
+
"Content-Type": "application/json",
|
|
3148
|
+
...options?.headers
|
|
3149
|
+
}
|
|
2708
3150
|
});
|
|
2709
3151
|
};
|
|
2710
3152
|
|
|
@@ -2765,6 +3207,732 @@ function confirm(question) {
|
|
|
2765
3207
|
});
|
|
2766
3208
|
}
|
|
2767
3209
|
|
|
3210
|
+
// src/commands/admin-crm.ts
|
|
3211
|
+
import chalk5 from "chalk";
|
|
3212
|
+
var CAMPAIGN_COLUMNS = [
|
|
3213
|
+
"id",
|
|
3214
|
+
"subject",
|
|
3215
|
+
"channel",
|
|
3216
|
+
"status",
|
|
3217
|
+
"senderName",
|
|
3218
|
+
"recipientCount",
|
|
3219
|
+
"sentCount",
|
|
3220
|
+
"failedCount",
|
|
3221
|
+
"scheduledAt",
|
|
3222
|
+
"nextBatchAt",
|
|
3223
|
+
"createdAt"
|
|
3224
|
+
];
|
|
3225
|
+
var EVENT_COLUMNS = [
|
|
3226
|
+
"id",
|
|
3227
|
+
"name",
|
|
3228
|
+
"orgName",
|
|
3229
|
+
"status",
|
|
3230
|
+
"city",
|
|
3231
|
+
"dateCount",
|
|
3232
|
+
"nextAt",
|
|
3233
|
+
"lastAt"
|
|
3234
|
+
];
|
|
3235
|
+
var DATE_COLUMNS = [
|
|
3236
|
+
"id",
|
|
3237
|
+
"eventId",
|
|
3238
|
+
"startsAt",
|
|
3239
|
+
"label",
|
|
3240
|
+
"status",
|
|
3241
|
+
"venueName",
|
|
3242
|
+
"city",
|
|
3243
|
+
"past",
|
|
3244
|
+
"buyers"
|
|
3245
|
+
];
|
|
3246
|
+
var SUPPRESSION_COLUMNS = [
|
|
3247
|
+
"emailMasked",
|
|
3248
|
+
"reason",
|
|
3249
|
+
"isGlobal",
|
|
3250
|
+
"workspaceId",
|
|
3251
|
+
"createdAt"
|
|
3252
|
+
];
|
|
3253
|
+
var ORGANIZATION_COLUMNS = ["id", "name", "slug"];
|
|
3254
|
+
var PERSON_COLUMNS = ["email", "name", "phoneMasked"];
|
|
3255
|
+
function retryAfterSeconds(res) {
|
|
3256
|
+
const raw = res?.headers.get("retry-after");
|
|
3257
|
+
if (!raw) return void 0;
|
|
3258
|
+
const n = Number(raw);
|
|
3259
|
+
if (Number.isFinite(n)) return n;
|
|
3260
|
+
const at = Date.parse(raw);
|
|
3261
|
+
return Number.isNaN(at) ? void 0 : Math.max(0, Math.round((at - Date.now()) / 1e3));
|
|
3262
|
+
}
|
|
3263
|
+
function describeWhen(seconds, now = Date.now()) {
|
|
3264
|
+
const at = new Date(now + seconds * 1e3);
|
|
3265
|
+
const local = at.toLocaleString("en-US", {
|
|
3266
|
+
timeZone: "America/Bogota",
|
|
3267
|
+
month: "short",
|
|
3268
|
+
day: "numeric",
|
|
3269
|
+
hour: "numeric",
|
|
3270
|
+
minute: "2-digit"
|
|
3271
|
+
});
|
|
3272
|
+
const mins = Math.ceil(seconds / 60);
|
|
3273
|
+
const h = Math.floor(mins / 60);
|
|
3274
|
+
const m = mins % 60;
|
|
3275
|
+
const rel = h > 0 ? `${h}h ${m}m` : `${m}m`;
|
|
3276
|
+
return `${local} (Bogot\xE1), in ${rel} \u2014 ${at.toISOString()}`;
|
|
3277
|
+
}
|
|
3278
|
+
var PAYLOAD_HINT = "The request body is over the backend limit (256 KB). Trim the JSON: long `people` email lists, a huge `body`, or ids that could be a scope instead.";
|
|
3279
|
+
function crmErrorHint(err, retryAfter) {
|
|
3280
|
+
switch (err.code) {
|
|
3281
|
+
case "OUTSIDE_SEND_WINDOW":
|
|
3282
|
+
return [
|
|
3283
|
+
retryAfter !== void 0 ? `The WhatsApp send window (9:00-20:00 Bogot\xE1) opens ${describeWhen(retryAfter)}.` : "The WhatsApp send window (9:00-20:00 Bogot\xE1) is closed.",
|
|
3284
|
+
"Retry then, or pass --ignore-window to send now."
|
|
3285
|
+
].join("\n");
|
|
3286
|
+
case "DUPLICATE_CAMPAIGN": {
|
|
3287
|
+
const id = err.details?.existingId;
|
|
3288
|
+
return id ? `A campaign with the same channel, sender and subject was launched less than 10 minutes ago: ${id}
|
|
3289
|
+
See it with \`ft admin crm campaigns get ${id}\`. Change the subject if this one is really different.` : "A campaign with the same channel, sender and subject was launched less than 10 minutes ago. Check `ft admin crm campaigns list`.";
|
|
3290
|
+
}
|
|
3291
|
+
case "QUOTA_EXHAUSTED":
|
|
3292
|
+
return retryAfter !== void 0 ? `The daily WhatsApp quota is used up. It frees up ${describeWhen(retryAfter)}. See \`ft admin crm quota\`.` : "The daily WhatsApp quota is used up. See `ft admin crm quota`.";
|
|
3293
|
+
case "INVALID_STATE":
|
|
3294
|
+
return "The campaign does not allow this right now (already sent, a batch is going out, or nothing is pending). Check it with `ft admin crm campaigns get <id>`.";
|
|
3295
|
+
case "EMPTY_AUDIENCE":
|
|
3296
|
+
return "The filter matches nobody. Adjust it and check with `ft admin crm preview`.";
|
|
3297
|
+
case "WHATSAPP_BLOCKED":
|
|
3298
|
+
return "WhatsApp sending is blocked for this template or sender. See `whatsappBlockedReason` in `ft admin crm options`.";
|
|
3299
|
+
case "PAYLOAD_TOO_LARGE":
|
|
3300
|
+
return PAYLOAD_HINT;
|
|
3301
|
+
case "CONFIRMATION_REQUIRED":
|
|
3302
|
+
return "The backend wants an explicit confirmation. The CLI sends `confirm: true` after you answer yes or pass --yes; if you built the body by hand, add it.";
|
|
3303
|
+
case "SEND_FAILED":
|
|
3304
|
+
return "The provider rejected the test message. Check the template, the sender and your profile's email/phone; nothing went to any customer.";
|
|
3305
|
+
case "RATE_LIMITED":
|
|
3306
|
+
return retryAfter !== void 0 ? `Too many requests. Wait ${retryAfter}s and run it again (the CLI never retries a write on its own).` : "Too many requests. Wait a moment and run it again (the CLI never retries a write on its own).";
|
|
3307
|
+
case "WHATSAPP_UNAVAILABLE":
|
|
3308
|
+
return "The WhatsApp provider did not answer. Safe to retry by hand in a moment - the CLI never retries a write on its own.";
|
|
3309
|
+
default:
|
|
3310
|
+
return null;
|
|
3311
|
+
}
|
|
3312
|
+
}
|
|
3313
|
+
function crmUnwrap(res, hint = crmErrorHint) {
|
|
3314
|
+
if (res.data !== void 0) return res.data;
|
|
3315
|
+
const err = res.error?.error;
|
|
3316
|
+
const status = res.response?.status;
|
|
3317
|
+
if (!err && status === 413)
|
|
3318
|
+
fail(
|
|
3319
|
+
"Error 413 [PAYLOAD_TOO_LARGE]: request body too large.",
|
|
3320
|
+
PAYLOAD_HINT
|
|
3321
|
+
);
|
|
3322
|
+
if (!err) return unwrap(res);
|
|
3323
|
+
const lines = [
|
|
3324
|
+
`Error ${status ?? ""} [${err.code ?? "?"}]: ${err.message ?? "unknown failure"}`
|
|
3325
|
+
];
|
|
3326
|
+
if (Array.isArray(err.details)) {
|
|
3327
|
+
for (const d of err.details) {
|
|
3328
|
+
const path = Array.isArray(d.path) ? d.path.join(".") : d.path ?? "";
|
|
3329
|
+
lines.push(` \xB7 ${path}: ${d.message ?? ""}`.trimEnd());
|
|
3330
|
+
}
|
|
3331
|
+
}
|
|
3332
|
+
const next = hint(err, retryAfterSeconds(res.response));
|
|
3333
|
+
if (next) fail(lines.join("\n"), next);
|
|
3334
|
+
return unwrap(res);
|
|
3335
|
+
}
|
|
3336
|
+
function parseSender(value) {
|
|
3337
|
+
const v = value.trim();
|
|
3338
|
+
if (!v) fail("Empty --sender. Use `freeticket` or a workspace id.");
|
|
3339
|
+
return v.toLowerCase() === "freeticket" ? { kind: "freeticket" } : { kind: "organization", workspaceId: v };
|
|
3340
|
+
}
|
|
3341
|
+
function senderLabel(sender) {
|
|
3342
|
+
if (!sender) return "(not set)";
|
|
3343
|
+
return sender.kind === "freeticket" ? "FreeTicket" : `organization ${sender.workspaceId}`;
|
|
3344
|
+
}
|
|
3345
|
+
function previewSummary(p, channel) {
|
|
3346
|
+
const c2 = p.counts;
|
|
3347
|
+
const lines = [
|
|
3348
|
+
`${chalk5.bold("Audience")}: ${c2.total} people`,
|
|
3349
|
+
` matched ${c2.matched} \xB7 excluded by "except" ${c2.excludedByExcept} \xB7 by frequency ${c2.excludedByFrequency} \xB7 unsubscribed ${c2.suppressed}`,
|
|
3350
|
+
` with email: ${c2.total} \xB7 reachable by WhatsApp: ${c2.reachableWhatsapp} \xB7 without phone: ${c2.withoutPhone}`
|
|
3351
|
+
];
|
|
3352
|
+
if (p.whatsappEstimate && channel !== "EMAIL") {
|
|
3353
|
+
const e = p.whatsappEstimate;
|
|
3354
|
+
lines.push(
|
|
3355
|
+
` WhatsApp: ~${e.days} day(s) to reach everyone (cap ${e.dailyCap}/day, ${e.remainingToday} left today)`
|
|
3356
|
+
);
|
|
3357
|
+
}
|
|
3358
|
+
if (p.senderChoice?.forced) {
|
|
3359
|
+
lines.push(
|
|
3360
|
+
" sender: must be FreeTicket (the scope spans several organizations)"
|
|
3361
|
+
);
|
|
3362
|
+
} else if (p.senderChoice && "organization" in p.senderChoice) {
|
|
3363
|
+
const o = p.senderChoice.organization;
|
|
3364
|
+
lines.push(` sender: can sign as FreeTicket or ${o.name} (${o.id})`);
|
|
3365
|
+
}
|
|
3366
|
+
return lines;
|
|
3367
|
+
}
|
|
3368
|
+
async function showCampaign(id) {
|
|
3369
|
+
const c2 = crmUnwrap(await getCrmCampaignsId({ path: { id } })).data;
|
|
3370
|
+
console.error(
|
|
3371
|
+
[
|
|
3372
|
+
`${chalk5.bold(c2.subject)} (${c2.id})`,
|
|
3373
|
+
` ${c2.channel} \xB7 ${c2.status} \xB7 sender ${c2.senderName}`,
|
|
3374
|
+
` recipients ${c2.recipientCount ?? "?"} \xB7 sent ${c2.sentCount ?? 0} \xB7 failed ${c2.failedCount ?? 0}`,
|
|
3375
|
+
c2.scheduledAt ? ` scheduled at ${c2.scheduledAt}` : null,
|
|
3376
|
+
c2.nextBatchAt ? ` next batch at ${c2.nextBatchAt}` : null
|
|
3377
|
+
].filter(Boolean).join("\n")
|
|
3378
|
+
);
|
|
3379
|
+
return c2;
|
|
3380
|
+
}
|
|
3381
|
+
function printRows(rows, opts, fallback) {
|
|
3382
|
+
const columns = resolveColumns(opts, fallback);
|
|
3383
|
+
if (opts.csv) {
|
|
3384
|
+
process.stdout.write(`${toCsv(rows, columns)}
|
|
3385
|
+
`);
|
|
3386
|
+
return;
|
|
3387
|
+
}
|
|
3388
|
+
print(rows, {
|
|
3389
|
+
json: opts.json,
|
|
3390
|
+
columns,
|
|
3391
|
+
columnsExplicit: Boolean(opts.columns)
|
|
3392
|
+
});
|
|
3393
|
+
}
|
|
3394
|
+
function tableOptions(cmd) {
|
|
3395
|
+
return cmd.option("--columns <list>", "comma-separated columns to display").option("--full", "show every field instead of the curated columns").option("--csv", "CSV output").option("--json", "raw JSON output");
|
|
3396
|
+
}
|
|
3397
|
+
function registerAdminCrm(admin) {
|
|
3398
|
+
const crm = admin.command("crm").description(
|
|
3399
|
+
"Master CRM: email / WhatsApp campaigns to buyers (writes send real messages)"
|
|
3400
|
+
);
|
|
3401
|
+
const campaigns = crm.command("campaigns").description("CRM campaigns");
|
|
3402
|
+
tableOptions(
|
|
3403
|
+
campaigns.command("list").description("List campaigns, newest first").option("--channel <c>", "EMAIL | WHATSAPP").option(
|
|
3404
|
+
"--status <s>",
|
|
3405
|
+
"SENT | FAILED | DENIED | PROCESSING | APPROVED | SCHEDULED | CANCELLED"
|
|
3406
|
+
).option("--limit <n>", "max results (server default 50)")
|
|
3407
|
+
).action(async (opts) => {
|
|
3408
|
+
configureAdminClient();
|
|
3409
|
+
const query = {};
|
|
3410
|
+
if (opts.channel) query.channel = String(opts.channel).toUpperCase();
|
|
3411
|
+
if (opts.status) query.status = String(opts.status).toUpperCase();
|
|
3412
|
+
if (opts.limit !== void 0) query.limit = Number(opts.limit);
|
|
3413
|
+
const body = crmUnwrap(await getCrmCampaigns({ query }));
|
|
3414
|
+
printRows(body.data, opts, CAMPAIGN_COLUMNS);
|
|
3415
|
+
});
|
|
3416
|
+
campaigns.command("get <id>").description("Campaign detail: deliveries, errors, conversions").option("--json", "raw JSON output").action(async (id, opts) => {
|
|
3417
|
+
configureAdminClient();
|
|
3418
|
+
const body = crmUnwrap(await getCrmCampaignsId({ path: { id } }));
|
|
3419
|
+
print(body.data, { json: opts.json });
|
|
3420
|
+
});
|
|
3421
|
+
campaigns.command("cancel <id>").description("Cancel a SCHEDULED campaign so it never goes out").option("--yes", "skip confirmation").option("--json", "raw JSON output").action(async (id, opts) => {
|
|
3422
|
+
configureAdminClient();
|
|
3423
|
+
await showCampaign(id);
|
|
3424
|
+
await confirmOrExit(
|
|
3425
|
+
`Cancel campaign ${id}? It will not be sent`,
|
|
3426
|
+
opts.yes
|
|
3427
|
+
);
|
|
3428
|
+
const body = crmUnwrap(await postCrmCampaignsIdCancel({ path: { id } }));
|
|
3429
|
+
print(body.data, { json: opts.json });
|
|
3430
|
+
});
|
|
3431
|
+
const batches = crm.command("batches").description("WhatsApp batch sending of a campaign");
|
|
3432
|
+
batches.command("next <id>").description("Send the next batch of pending recipients now").option("--ignore-window", "send even outside the 9:00-20:00 Bogot\xE1 window").option("--yes", "skip confirmation").option("--json", "raw JSON output").action(async (id, opts) => {
|
|
3433
|
+
configureAdminClient();
|
|
3434
|
+
await showCampaign(id);
|
|
3435
|
+
await confirmOrExit(
|
|
3436
|
+
`Send the next batch of campaign ${id}${opts.ignoreWindow ? " (ignoring the send window)" : ""}?`,
|
|
3437
|
+
opts.yes
|
|
3438
|
+
);
|
|
3439
|
+
const body = crmUnwrap(
|
|
3440
|
+
await postCrmCampaignsIdBatchesNext({
|
|
3441
|
+
path: { id },
|
|
3442
|
+
...opts.ignoreWindow ? { body: { ignoreSendWindow: true } } : {}
|
|
3443
|
+
})
|
|
3444
|
+
);
|
|
3445
|
+
print(body.data, { json: opts.json });
|
|
3446
|
+
});
|
|
3447
|
+
batches.command("stop <id>").description(
|
|
3448
|
+
"Stop batch sending: pending recipients are skipped (irreversible)"
|
|
3449
|
+
).option("--yes", "skip confirmation").option("--json", "raw JSON output").action(async (id, opts) => {
|
|
3450
|
+
configureAdminClient();
|
|
3451
|
+
await showCampaign(id);
|
|
3452
|
+
await confirmOrExit(
|
|
3453
|
+
`Stop campaign ${id}? Pending recipients will never be sent (irreversible)`,
|
|
3454
|
+
opts.yes
|
|
3455
|
+
);
|
|
3456
|
+
const body = crmUnwrap(
|
|
3457
|
+
await postCrmCampaignsIdBatchesStop({ path: { id } })
|
|
3458
|
+
);
|
|
3459
|
+
print(body.data, { json: opts.json });
|
|
3460
|
+
});
|
|
3461
|
+
const events = crm.command("events").description("Find shows and dates for a filter");
|
|
3462
|
+
tableOptions(
|
|
3463
|
+
events.command("search <query>").description("Search shows by name").option(
|
|
3464
|
+
"--purpose <p>",
|
|
3465
|
+
"scope | promote | except (promote = published shows only)",
|
|
3466
|
+
"scope"
|
|
3467
|
+
).option(
|
|
3468
|
+
"--sender <workspaceId>",
|
|
3469
|
+
"with --purpose promote: only shows of this organization"
|
|
3470
|
+
)
|
|
3471
|
+
).action(async (query, opts) => {
|
|
3472
|
+
configureAdminClient();
|
|
3473
|
+
const purpose = String(opts.purpose);
|
|
3474
|
+
if (!["scope", "promote", "except"].includes(purpose))
|
|
3475
|
+
fail(`Invalid --purpose: ${purpose}. Use scope, promote or except.`);
|
|
3476
|
+
const body = crmUnwrap(
|
|
3477
|
+
await getCrmEvents({
|
|
3478
|
+
query: {
|
|
3479
|
+
query,
|
|
3480
|
+
purpose,
|
|
3481
|
+
...opts.sender ? { senderWorkspaceId: opts.sender } : {}
|
|
3482
|
+
}
|
|
3483
|
+
})
|
|
3484
|
+
);
|
|
3485
|
+
printRows(body.data, opts, EVENT_COLUMNS);
|
|
3486
|
+
});
|
|
3487
|
+
tableOptions(
|
|
3488
|
+
events.command("dates <eventId...>").description("Dates (functions) of one or more shows, with buyer counts")
|
|
3489
|
+
).action(async (eventIds, opts) => {
|
|
3490
|
+
configureAdminClient();
|
|
3491
|
+
const ids = eventIds.flatMap((v) => v.split(",")).map((v) => v.trim()).filter(Boolean);
|
|
3492
|
+
const body = crmUnwrap(
|
|
3493
|
+
await getCrmEventDates({ query: { eventIds: ids.join(",") } })
|
|
3494
|
+
);
|
|
3495
|
+
printRows(body.data, opts, DATE_COLUMNS);
|
|
3496
|
+
});
|
|
3497
|
+
crm.command("options").description("Cities, genres/formats, plans and WhatsApp templates").option("--json", "raw JSON output").action(async (opts) => {
|
|
3498
|
+
configureAdminClient();
|
|
3499
|
+
print(crmUnwrap(await getCrmOptions({})).data, { json: opts.json });
|
|
3500
|
+
});
|
|
3501
|
+
crm.command("quota").description("WhatsApp daily quota: used, remaining, committed batches").option("--json", "raw JSON output").action(async (opts) => {
|
|
3502
|
+
configureAdminClient();
|
|
3503
|
+
print(crmUnwrap(await getCrmQuota({})).data, { json: opts.json });
|
|
3504
|
+
});
|
|
3505
|
+
const suppressions = crm.command("suppressions").description("Unsubscribed people: the master CRM never writes to them");
|
|
3506
|
+
tableOptions(
|
|
3507
|
+
suppressions.command("list").description("Unsubscribes, newest first (emails masked)").option("--query <text>", "full email or part of it").option(
|
|
3508
|
+
"--scope <s>",
|
|
3509
|
+
"global (platform only, default) | all (plus each organization's)"
|
|
3510
|
+
).option("--limit <n>", "max results 1-500 (server default 100)")
|
|
3511
|
+
).action(async (opts) => {
|
|
3512
|
+
configureAdminClient();
|
|
3513
|
+
const query = {};
|
|
3514
|
+
if (opts.query) query.query = opts.query;
|
|
3515
|
+
if (opts.scope) {
|
|
3516
|
+
const scope = String(opts.scope).toLowerCase();
|
|
3517
|
+
if (scope !== "global" && scope !== "all")
|
|
3518
|
+
fail(`Invalid --scope: ${opts.scope}. Use global or all.`);
|
|
3519
|
+
query.scope = scope;
|
|
3520
|
+
}
|
|
3521
|
+
if (opts.limit !== void 0) {
|
|
3522
|
+
const n = Number(opts.limit);
|
|
3523
|
+
if (!Number.isInteger(n) || n < 1 || n > 500)
|
|
3524
|
+
fail(`Invalid --limit: ${opts.limit}. Use an integer from 1 to 500.`);
|
|
3525
|
+
query.limit = n;
|
|
3526
|
+
}
|
|
3527
|
+
const body = crmUnwrap(await getCrmSuppressions({ query }));
|
|
3528
|
+
printRows(body.data, opts, SUPPRESSION_COLUMNS);
|
|
3529
|
+
});
|
|
3530
|
+
suppressions.command("add <email>").description(
|
|
3531
|
+
"Unsubscribe a person from master CRM campaigns (idempotent; organizers' own campaigns are not affected)"
|
|
3532
|
+
).option("--json", "raw JSON output").action(async (email, opts) => {
|
|
3533
|
+
configureAdminClient();
|
|
3534
|
+
const body = crmUnwrap(
|
|
3535
|
+
await postCrmSuppressions({ body: { email: String(email).trim() } })
|
|
3536
|
+
);
|
|
3537
|
+
print(body.data, { json: opts.json });
|
|
3538
|
+
});
|
|
3539
|
+
suppressions.command("remove <email>").description(
|
|
3540
|
+
"Remove a team-added unsubscribe: the person receives CRM campaigns again"
|
|
3541
|
+
).option("--yes", "skip confirmation").option("--json", "raw JSON output").action(async (email, opts) => {
|
|
3542
|
+
configureAdminClient();
|
|
3543
|
+
const value = String(email).trim();
|
|
3544
|
+
await confirmOrExit(
|
|
3545
|
+
`Remove the unsubscribe of ${value}? Master CRM campaigns will reach them again`,
|
|
3546
|
+
opts.yes
|
|
3547
|
+
);
|
|
3548
|
+
const body = crmUnwrap(
|
|
3549
|
+
await deleteCrmSuppressions({ body: { email: value, confirm: true } })
|
|
3550
|
+
);
|
|
3551
|
+
print(body.data, { json: opts.json });
|
|
3552
|
+
});
|
|
3553
|
+
crm.command("test-send").description(
|
|
3554
|
+
"Send the composed message to YOURSELF as [Prueba] (your email, or your staff phone by WhatsApp)"
|
|
3555
|
+
).requiredOption(
|
|
3556
|
+
"--data <json>",
|
|
3557
|
+
"message JSON: channel, sender, subject, body, templateName (WhatsApp), imageUrl, promotedEventId"
|
|
3558
|
+
).option("--sender <s>", "freeticket | <workspaceId> (overrides --data)").option("--yes", "skip confirmation").option("--json", "raw JSON output").action(async (opts) => {
|
|
3559
|
+
configureAdminClient();
|
|
3560
|
+
const raw = parseData(opts.data);
|
|
3561
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw))
|
|
3562
|
+
fail("--data must be a JSON object (channel, sender, subject, body).");
|
|
3563
|
+
const input = { ...raw };
|
|
3564
|
+
if (opts.sender) input.sender = parseSender(opts.sender);
|
|
3565
|
+
const channel = String(input.channel ?? "?");
|
|
3566
|
+
await confirmOrExit(
|
|
3567
|
+
`Send a [Prueba] of "${String(input.subject ?? "(no subject)")}" by ${channel} to yourself${channel === "WHATSAPP" ? " (uses 1 of the daily WhatsApp quota)" : ""}?`,
|
|
3568
|
+
opts.yes
|
|
3569
|
+
);
|
|
3570
|
+
const body = crmUnwrap(
|
|
3571
|
+
await postCrmTestSend({
|
|
3572
|
+
body: { ...input, confirm: true }
|
|
3573
|
+
})
|
|
3574
|
+
);
|
|
3575
|
+
print(body.data, { json: opts.json });
|
|
3576
|
+
});
|
|
3577
|
+
tableOptions(
|
|
3578
|
+
crm.command("organizations [query]").description(
|
|
3579
|
+
"Active organizations by name or slug (for scope.level orgs or sender.workspaceId)"
|
|
3580
|
+
)
|
|
3581
|
+
).action(async (query, opts) => {
|
|
3582
|
+
configureAdminClient();
|
|
3583
|
+
const body = crmUnwrap(
|
|
3584
|
+
await getCrmOrganizations({ query: query ? { query } : {} })
|
|
3585
|
+
);
|
|
3586
|
+
printRows(body.data, opts, ORGANIZATION_COLUMNS);
|
|
3587
|
+
});
|
|
3588
|
+
const people = crm.command("people").description("People inside an audience scope");
|
|
3589
|
+
tableOptions(
|
|
3590
|
+
people.command("search <query>").description(
|
|
3591
|
+
"Find people of a scope by email or name (full email: what the `people` filter condition takes)"
|
|
3592
|
+
).option(
|
|
3593
|
+
"--scope <json>",
|
|
3594
|
+
"the filter's scope object (inline JSON or @scope.json); default: the whole platform"
|
|
3595
|
+
)
|
|
3596
|
+
).action(async (query, opts) => {
|
|
3597
|
+
configureAdminClient();
|
|
3598
|
+
const input = { query: String(query) };
|
|
3599
|
+
if (opts.scope)
|
|
3600
|
+
input.scope = parseData(opts.scope);
|
|
3601
|
+
const body = crmUnwrap(await postCrmPeopleSearch({ body: input }));
|
|
3602
|
+
printRows(body.data, opts, PERSON_COLUMNS);
|
|
3603
|
+
});
|
|
3604
|
+
crm.command("preview").description("Count an audience without creating anything").requiredOption(
|
|
3605
|
+
"--filter <json>",
|
|
3606
|
+
"audience filter v2 (inline JSON or @filter.json)"
|
|
3607
|
+
).option("--sender <s>", "freeticket | <workspaceId>").option("--json", "raw JSON output").action(async (opts) => {
|
|
3608
|
+
configureAdminClient();
|
|
3609
|
+
const filter = parseData(opts.filter);
|
|
3610
|
+
const body = crmUnwrap(
|
|
3611
|
+
await postCrmAudiencePreview({
|
|
3612
|
+
body: {
|
|
3613
|
+
filter,
|
|
3614
|
+
...opts.sender ? { sender: parseSender(opts.sender) } : {}
|
|
3615
|
+
}
|
|
3616
|
+
})
|
|
3617
|
+
);
|
|
3618
|
+
if (opts.json) {
|
|
3619
|
+
print(body.data, { json: true });
|
|
3620
|
+
return;
|
|
3621
|
+
}
|
|
3622
|
+
console.log(previewSummary(body.data).join("\n"));
|
|
3623
|
+
if (body.data.sample.length > 0) {
|
|
3624
|
+
console.log(chalk5.dim("\nSample (masked):"));
|
|
3625
|
+
print(body.data.sample, {});
|
|
3626
|
+
}
|
|
3627
|
+
});
|
|
3628
|
+
crm.command("launch").description(
|
|
3629
|
+
"Create an approved campaign (timing.mode now sends right away). Previews the audience first"
|
|
3630
|
+
).requiredOption(
|
|
3631
|
+
"--data <json>",
|
|
3632
|
+
"campaign JSON: channel, sender, subject, body, filter, timing (inline or @campaign.json)"
|
|
3633
|
+
).option(
|
|
3634
|
+
"--ignore-window",
|
|
3635
|
+
"WhatsApp with timing.mode now: send even outside the 9:00-20:00 Bogot\xE1 window"
|
|
3636
|
+
).option("--yes", "skip confirmation").option("--json", "raw JSON output").action(async (opts) => {
|
|
3637
|
+
configureAdminClient();
|
|
3638
|
+
const input = parseData(opts.data);
|
|
3639
|
+
if (opts.ignoreWindow && input && typeof input === "object")
|
|
3640
|
+
input.ignoreSendWindow = true;
|
|
3641
|
+
if (!input || typeof input !== "object" || !input.filter)
|
|
3642
|
+
fail(
|
|
3643
|
+
"--data needs a `filter` (and channel, sender, subject, body, timing).",
|
|
3644
|
+
"See the `ft admin crm` section of the README for a campaign.json example."
|
|
3645
|
+
);
|
|
3646
|
+
const preview = crmUnwrap(
|
|
3647
|
+
await postCrmAudiencePreview({
|
|
3648
|
+
body: {
|
|
3649
|
+
filter: input.filter,
|
|
3650
|
+
...input.sender ? { sender: input.sender } : {}
|
|
3651
|
+
}
|
|
3652
|
+
})
|
|
3653
|
+
).data;
|
|
3654
|
+
console.error(
|
|
3655
|
+
[
|
|
3656
|
+
`${chalk5.bold(input.subject ?? "(no subject)")} \xB7 ${input.channel ?? "?"} \xB7 sender ${senderLabel(input.sender)} \xB7 timing ${input.timing?.mode ?? "?"}`,
|
|
3657
|
+
...previewSummary(preview, input.channel)
|
|
3658
|
+
].join("\n")
|
|
3659
|
+
);
|
|
3660
|
+
if (preview.counts.total === 0)
|
|
3661
|
+
fail("The audience is empty: nothing to launch.");
|
|
3662
|
+
const reach = input.channel === "WHATSAPP" ? preview.counts.reachableWhatsapp : preview.counts.total;
|
|
3663
|
+
const when = input.timing?.mode === "now" ? "right now" : input.timing?.mode === "batches" ? "in batches" : "on schedule";
|
|
3664
|
+
await confirmOrExit(
|
|
3665
|
+
`Launch to ${reach} people by ${input.channel ?? "?"}, sending ${when}${input.ignoreSendWindow ? " (ignoring the send window)" : ""}?`,
|
|
3666
|
+
opts.yes
|
|
3667
|
+
);
|
|
3668
|
+
const body = crmUnwrap(await postCrmCampaigns({ body: input }));
|
|
3669
|
+
print(body.data, { json: opts.json });
|
|
3670
|
+
if (!opts.json)
|
|
3671
|
+
console.error(
|
|
3672
|
+
chalk5.dim(
|
|
3673
|
+
`
|
|
3674
|
+
Follow it with \`ft admin crm campaigns get ${body.data.id}\``
|
|
3675
|
+
)
|
|
3676
|
+
);
|
|
3677
|
+
});
|
|
3678
|
+
}
|
|
3679
|
+
|
|
3680
|
+
// src/commands/admin-settlements.ts
|
|
3681
|
+
import { readFileSync as readFileSync4, statSync } from "fs";
|
|
3682
|
+
import { basename } from "path";
|
|
3683
|
+
import chalk6 from "chalk";
|
|
3684
|
+
var MAX_PDF_BYTES = 3 * 1024 * 1024;
|
|
3685
|
+
var settlementErrorHint = (err, retryAfter) => {
|
|
3686
|
+
switch (err.code) {
|
|
3687
|
+
case "DUPLICATE_SETTLEMENT": {
|
|
3688
|
+
const id = err.details?.existingId;
|
|
3689
|
+
return id ? `That function already has an active settlement: ${id}
|
|
3690
|
+
See it with \`ft admin settlements get ${id}\`. Delete it first if it is really wrong.` : "That function already has an active settlement. Find it with `ft admin settlements list --organization <id>`.";
|
|
3691
|
+
}
|
|
3692
|
+
case "AMOUNT_MISMATCH":
|
|
3693
|
+
return "The recalculated balance does not match the settlement amount, so nothing was written. Generate the settlement from scratch (delete + create).";
|
|
3694
|
+
case "INVALID_STATE":
|
|
3695
|
+
return "The settlement is not in the state this step needs (e.g. send needs GENERATED, mark-paid and regenerate need AWAITING_PAYMENT). Check it with `ft admin settlements get <id>`.";
|
|
3696
|
+
case "CONFIRMATION_REQUIRED":
|
|
3697
|
+
return "The backend wants `confirm: true`. The CLI adds it after you answer yes or pass --yes.";
|
|
3698
|
+
case "STORAGE_UNAVAILABLE":
|
|
3699
|
+
case "UPLOAD_FAILED":
|
|
3700
|
+
case "DRAFT_FAILED":
|
|
3701
|
+
return "Storage or PDF generation failed on the backend; nothing was created. Safe to run it again by hand in a moment.";
|
|
3702
|
+
case "PAYLOAD_TOO_LARGE":
|
|
3703
|
+
return "The PDF is over the 3 MB limit. Compress it and upload again.";
|
|
3704
|
+
case "RATE_LIMITED":
|
|
3705
|
+
return retryAfter !== void 0 ? `Too many requests. Wait ${retryAfter}s and run it again (the CLI never retries a write on its own).` : "Too many requests. Wait a moment and run it again.";
|
|
3706
|
+
default:
|
|
3707
|
+
return null;
|
|
3708
|
+
}
|
|
3709
|
+
};
|
|
3710
|
+
var unwrapS = (res) => crmUnwrap(res, settlementErrorHint);
|
|
3711
|
+
function readPdf(path, io = {}) {
|
|
3712
|
+
const size = io.size ?? ((p) => statSync(p).size);
|
|
3713
|
+
const read = io.read ?? ((p) => readFileSync4(p));
|
|
3714
|
+
let bytes;
|
|
3715
|
+
try {
|
|
3716
|
+
bytes = size(path);
|
|
3717
|
+
} catch {
|
|
3718
|
+
fail(`Cannot read ${path}: file not found.`);
|
|
3719
|
+
}
|
|
3720
|
+
if (bytes > MAX_PDF_BYTES)
|
|
3721
|
+
fail(
|
|
3722
|
+
`${path} is ${(bytes / 1024 / 1024).toFixed(1)} MB; the limit is 3 MB.`,
|
|
3723
|
+
"Compress the PDF and try again."
|
|
3724
|
+
);
|
|
3725
|
+
const buf = read(path);
|
|
3726
|
+
if (buf.subarray(0, 4).toString("latin1") !== "%PDF")
|
|
3727
|
+
fail(`${path} is not a PDF (it does not start with %PDF).`);
|
|
3728
|
+
return { fileName: basename(path), contentBase64: buf.toString("base64") };
|
|
3729
|
+
}
|
|
3730
|
+
function parseAmount(value) {
|
|
3731
|
+
const n = Number(value);
|
|
3732
|
+
if (!Number.isFinite(n) || n <= 0 || n > 999999999999e-2)
|
|
3733
|
+
fail(`Invalid --amount: ${value}. Use a positive number.`);
|
|
3734
|
+
if (Math.round(n * 100) / 100 !== n)
|
|
3735
|
+
fail(`Invalid --amount: ${value}. At most two decimals.`);
|
|
3736
|
+
return n;
|
|
3737
|
+
}
|
|
3738
|
+
function parseNumber(flag, value, max) {
|
|
3739
|
+
const n = Number(value);
|
|
3740
|
+
if (!Number.isFinite(n) || n < 0 || n > max)
|
|
3741
|
+
fail(`Invalid ${flag}: ${value}. Use a number from 0 to ${max}.`);
|
|
3742
|
+
return n;
|
|
3743
|
+
}
|
|
3744
|
+
async function upload(organizationId, path) {
|
|
3745
|
+
const file = readPdf(path);
|
|
3746
|
+
return unwrapS(
|
|
3747
|
+
await postSettlementsFiles({ body: { organizationId, ...file } })
|
|
3748
|
+
).data;
|
|
3749
|
+
}
|
|
3750
|
+
function money(amount, currency) {
|
|
3751
|
+
return `${amount.toLocaleString("en-US")} ${currency}`;
|
|
3752
|
+
}
|
|
3753
|
+
async function showSettlement(id) {
|
|
3754
|
+
const s = unwrapS(await getSettlementsId2({ path: { id } })).data;
|
|
3755
|
+
console.error(
|
|
3756
|
+
[
|
|
3757
|
+
`${chalk6.bold(s.reference)} (${s.id})`,
|
|
3758
|
+
` ${s.organization.name} \xB7 ${s.status} \xB7 ${money(s.amount, s.currency)}`,
|
|
3759
|
+
` ${s.label}${s.event ? ` \xB7 ${s.event.name}` : ""}${s.eventDate ? ` \xB7 ${s.eventDate.startsAt}` : ""}`
|
|
3760
|
+
].join("\n")
|
|
3761
|
+
);
|
|
3762
|
+
return s;
|
|
3763
|
+
}
|
|
3764
|
+
function registerAdminSettlementWrites(root) {
|
|
3765
|
+
root.command("upload <file>").description(
|
|
3766
|
+
"Upload a PDF (max 3 MB) to an organization's private settlement bucket; prints its storagePath"
|
|
3767
|
+
).requiredOption("--organization <id>", "organization the file belongs to").option("--json", "raw JSON output").action(async (file, opts) => {
|
|
3768
|
+
configureAdminClient();
|
|
3769
|
+
print(await upload(opts.organization, file), { json: opts.json });
|
|
3770
|
+
});
|
|
3771
|
+
root.command("create").description(
|
|
3772
|
+
"Create a settlement in GENERATED (does not notify the organizer). mode manual: a PDF + typed amount; mode auto: computed from a function"
|
|
3773
|
+
).requiredOption(
|
|
3774
|
+
"--data <json>",
|
|
3775
|
+
'body: {"mode":"auto","eventDateId":"..."} or {"mode":"manual","organizationId":"...","label":"...","amount":...} (inline or @file.json)'
|
|
3776
|
+
).option(
|
|
3777
|
+
"--pdf <file>",
|
|
3778
|
+
"mode manual: upload this PDF first and fill storagePath/fileName"
|
|
3779
|
+
).option("--yes", "skip confirmation").option("--json", "raw JSON output").action(async (opts) => {
|
|
3780
|
+
configureAdminClient();
|
|
3781
|
+
const raw = parseData(opts.data);
|
|
3782
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw))
|
|
3783
|
+
fail("--data must be a JSON object with `mode` (manual | auto).");
|
|
3784
|
+
const input = { ...raw };
|
|
3785
|
+
if (input.mode !== "manual" && input.mode !== "auto")
|
|
3786
|
+
fail("--data needs `mode`: manual or auto.");
|
|
3787
|
+
if (opts.pdf && input.mode !== "manual")
|
|
3788
|
+
fail("--pdf only applies to mode manual (auto generates its own PDF).");
|
|
3789
|
+
if (opts.pdf && !input.organizationId)
|
|
3790
|
+
fail("mode manual needs `organizationId` to upload the PDF.");
|
|
3791
|
+
if (opts.pdf) readPdf(opts.pdf);
|
|
3792
|
+
console.error(
|
|
3793
|
+
input.mode === "auto" ? `auto settlement of function ${String(input.eventDateId ?? "?")}${input.integrate === false ? " (EXAMPLE, not tied to the function)" : ""}` : `manual settlement "${String(input.label ?? "?")}" for ${String(input.organizationId)}: ${money(Number(input.amount), String(input.currency ?? "COP"))}`
|
|
3794
|
+
);
|
|
3795
|
+
await confirmOrExit(
|
|
3796
|
+
"Create this settlement? It starts in GENERATED and is not sent to the organizer",
|
|
3797
|
+
opts.yes
|
|
3798
|
+
);
|
|
3799
|
+
if (opts.pdf) {
|
|
3800
|
+
const file = await upload(String(input.organizationId), opts.pdf);
|
|
3801
|
+
input.storagePath = file.storagePath;
|
|
3802
|
+
input.fileName = file.fileName;
|
|
3803
|
+
}
|
|
3804
|
+
const body = unwrapS(
|
|
3805
|
+
await postSettlements({ body: input })
|
|
3806
|
+
);
|
|
3807
|
+
print(body.data, { json: opts.json });
|
|
3808
|
+
if (!opts.json)
|
|
3809
|
+
console.error(
|
|
3810
|
+
chalk6.dim(
|
|
3811
|
+
`
|
|
3812
|
+
Review it, then \`ft admin settlements send ${body.data.id}\` to notify the organizer`
|
|
3813
|
+
)
|
|
3814
|
+
);
|
|
3815
|
+
});
|
|
3816
|
+
root.command("regenerate <id>").description(
|
|
3817
|
+
"Replace the PDF of an AWAITING_PAYMENT settlement with the final one (amount never changes)"
|
|
3818
|
+
).option(
|
|
3819
|
+
"--commission-rate <pct>",
|
|
3820
|
+
"gateway commission in PERCENT before VAT (e.g. 2.9916)"
|
|
3821
|
+
).option(
|
|
3822
|
+
"--fixed-fee <cop>",
|
|
3823
|
+
"fixed fee per transaction, COP before VAT (e.g. 500)"
|
|
3824
|
+
).option("--yes", "skip confirmation").option("--json", "raw JSON output").action(async (id, opts) => {
|
|
3825
|
+
configureAdminClient();
|
|
3826
|
+
const input = {};
|
|
3827
|
+
if (opts.commissionRate !== void 0)
|
|
3828
|
+
input.commissionRate = parseNumber(
|
|
3829
|
+
"--commission-rate",
|
|
3830
|
+
opts.commissionRate,
|
|
3831
|
+
100
|
|
3832
|
+
);
|
|
3833
|
+
if (opts.fixedFee !== void 0)
|
|
3834
|
+
input.fixedFee = parseNumber("--fixed-fee", opts.fixedFee, 1e5);
|
|
3835
|
+
await showSettlement(id);
|
|
3836
|
+
await confirmOrExit(`Regenerate the PDF of settlement ${id}?`, opts.yes);
|
|
3837
|
+
const body = unwrapS(
|
|
3838
|
+
await postSettlementsIdRegenerate({ path: { id }, body: input })
|
|
3839
|
+
);
|
|
3840
|
+
print(body.data, { json: opts.json });
|
|
3841
|
+
});
|
|
3842
|
+
root.command("attach <id>").description(
|
|
3843
|
+
"Legacy DRAFT \u2192 GENERATED: attach the settlement PDF (transfer receipts go in mark-paid)"
|
|
3844
|
+
).option("--pdf <file>", "upload this PDF and attach it").option("--storage-path <path>", "an already uploaded file (see upload)").option("--file-name <name>", "file name for --storage-path").option(
|
|
3845
|
+
"--amount <n>",
|
|
3846
|
+
"also change the amount paid to the organizer (max 2 decimals)"
|
|
3847
|
+
).option("--yes", "skip confirmation").option("--json", "raw JSON output").action(async (id, opts) => {
|
|
3848
|
+
configureAdminClient();
|
|
3849
|
+
if (!opts.pdf && !opts.storagePath)
|
|
3850
|
+
fail("Pass --pdf <file> or --storage-path <path> --file-name <name>.");
|
|
3851
|
+
if (opts.storagePath && !opts.fileName)
|
|
3852
|
+
fail("--storage-path needs --file-name.");
|
|
3853
|
+
const amount = opts.amount !== void 0 ? parseAmount(opts.amount) : void 0;
|
|
3854
|
+
if (opts.pdf) readPdf(opts.pdf);
|
|
3855
|
+
const s = await showSettlement(id);
|
|
3856
|
+
await confirmOrExit(
|
|
3857
|
+
`Attach the PDF to settlement ${id}${amount !== void 0 ? ` and set the amount to ${money(amount, s.currency)}` : ""}?`,
|
|
3858
|
+
opts.yes
|
|
3859
|
+
);
|
|
3860
|
+
const file = opts.pdf ? await upload(s.organization.id, opts.pdf) : { storagePath: opts.storagePath, fileName: opts.fileName };
|
|
3861
|
+
const input = {
|
|
3862
|
+
...file,
|
|
3863
|
+
...amount !== void 0 ? { amount, confirm: true } : {}
|
|
3864
|
+
};
|
|
3865
|
+
const body = unwrapS(
|
|
3866
|
+
await postSettlementsIdProofs({ path: { id }, body: input })
|
|
3867
|
+
);
|
|
3868
|
+
print(body.data, { json: opts.json });
|
|
3869
|
+
});
|
|
3870
|
+
root.command("send <id>").description(
|
|
3871
|
+
"GENERATED \u2192 SENT: the organizer sees it, can split the payment and gets an email"
|
|
3872
|
+
).option("--yes", "skip confirmation").option("--json", "raw JSON output").action(async (id, opts) => {
|
|
3873
|
+
configureAdminClient();
|
|
3874
|
+
await showSettlement(id);
|
|
3875
|
+
await confirmOrExit(
|
|
3876
|
+
`Send settlement ${id} to the organizer? They get an email`,
|
|
3877
|
+
opts.yes
|
|
3878
|
+
);
|
|
3879
|
+
const body = unwrapS(
|
|
3880
|
+
await postSettlementsIdSend({ path: { id }, body: { confirm: true } })
|
|
3881
|
+
);
|
|
3882
|
+
print(body.data, { json: opts.json });
|
|
3883
|
+
});
|
|
3884
|
+
root.command("mark-paid <id>").description(
|
|
3885
|
+
"AWAITING_PAYMENT \u2192 PAID with the transfer receipts; emails the organizer"
|
|
3886
|
+
).option(
|
|
3887
|
+
"--proof <file...>",
|
|
3888
|
+
"receipt PDF(s), one per payout account (uploaded first)"
|
|
3889
|
+
).option(
|
|
3890
|
+
"--proofs <json>",
|
|
3891
|
+
'already uploaded receipts: [{"storagePath":"...","fileName":"..."}] (inline or @file.json)'
|
|
3892
|
+
).option("--yes", "skip confirmation").option("--json", "raw JSON output").action(async (id, opts) => {
|
|
3893
|
+
configureAdminClient();
|
|
3894
|
+
const files = opts.proof ?? [];
|
|
3895
|
+
const given = opts.proofs ? parseData(opts.proofs) : [];
|
|
3896
|
+
if (!Array.isArray(given))
|
|
3897
|
+
fail("--proofs must be a JSON array of {storagePath, fileName}.");
|
|
3898
|
+
if (files.length + given.length === 0)
|
|
3899
|
+
fail(
|
|
3900
|
+
"Pass at least one receipt: --proof <file.pdf> or --proofs <json>."
|
|
3901
|
+
);
|
|
3902
|
+
if (files.length + given.length > 20)
|
|
3903
|
+
fail("At most 20 receipts per settlement.");
|
|
3904
|
+
for (const f of files) readPdf(f);
|
|
3905
|
+
const s = await showSettlement(id);
|
|
3906
|
+
await confirmOrExit(
|
|
3907
|
+
`Mark settlement ${id} as PAID (${money(s.amount, s.currency)}) with ${files.length + given.length} receipt(s)? The organizer gets an email`,
|
|
3908
|
+
opts.yes
|
|
3909
|
+
);
|
|
3910
|
+
const proofs = [...given];
|
|
3911
|
+
for (const f of files) proofs.push(await upload(s.organization.id, f));
|
|
3912
|
+
const body = unwrapS(
|
|
3913
|
+
await postSettlementsIdMarkPaid({
|
|
3914
|
+
path: { id },
|
|
3915
|
+
body: { confirm: true, proofs }
|
|
3916
|
+
})
|
|
3917
|
+
);
|
|
3918
|
+
print(body.data, { json: opts.json });
|
|
3919
|
+
});
|
|
3920
|
+
root.command("delete <id>").description(
|
|
3921
|
+
"Delete a settlement (irreversible; membership ones only in DRAFT/GENERATED)"
|
|
3922
|
+
).option("--yes", "skip confirmation").option("--json", "raw JSON output").action(async (id, opts) => {
|
|
3923
|
+
configureAdminClient();
|
|
3924
|
+
await showSettlement(id);
|
|
3925
|
+
await confirmOrExit(
|
|
3926
|
+
`Delete settlement ${id}? This cannot be undone`,
|
|
3927
|
+
opts.yes
|
|
3928
|
+
);
|
|
3929
|
+
const body = unwrapS(
|
|
3930
|
+
await deleteSettlementsId({ path: { id }, body: { confirm: true } })
|
|
3931
|
+
);
|
|
3932
|
+
print(body.data, { json: opts.json });
|
|
3933
|
+
});
|
|
3934
|
+
}
|
|
3935
|
+
|
|
2768
3936
|
// src/commands/admin.ts
|
|
2769
3937
|
function registerAdmin(program2) {
|
|
2770
3938
|
const admin = program2.command("admin").description("Superadmin (cross-tenant) \u2014 SUPER_ADMIN session required");
|
|
@@ -2782,14 +3950,14 @@ function registerAdmin(program2) {
|
|
|
2782
3950
|
configureAdminClient();
|
|
2783
3951
|
const me = unwrap(await getMe2({})).data;
|
|
2784
3952
|
console.log(
|
|
2785
|
-
`${
|
|
3953
|
+
`${chalk7.green("\u2713")} Admin session saved in ${chalk7.dim(CONFIG_PATH)}`
|
|
2786
3954
|
);
|
|
2787
3955
|
print(me, {});
|
|
2788
3956
|
});
|
|
2789
3957
|
admin.command("logout").description("Remove the stored superadmin session").action(() => {
|
|
2790
3958
|
saveConfig({ adminSession: void 0 });
|
|
2791
3959
|
console.log(
|
|
2792
|
-
`${
|
|
3960
|
+
`${chalk7.green("\u2713")} Admin session removed from ${chalk7.dim(CONFIG_PATH)}`
|
|
2793
3961
|
);
|
|
2794
3962
|
});
|
|
2795
3963
|
admin.command("config").description("Show admin configuration (the session is masked)").action(() => {
|
|
@@ -2937,6 +4105,30 @@ function registerAdmin(program2) {
|
|
|
2937
4105
|
columns: ["id", "name", "lastUsedAt", "expiresAt", "createdAt"],
|
|
2938
4106
|
noPaging: true
|
|
2939
4107
|
},
|
|
4108
|
+
{
|
|
4109
|
+
// Admin 1.9: EVENT settlements of every organization (membership ones
|
|
4110
|
+
// are not listed here, same as the panel). Every write moves money or
|
|
4111
|
+
// notifies the organizer, so they live in admin-settlements.ts behind a
|
|
4112
|
+
// confirmation that also sends the contract's `confirm: true`.
|
|
4113
|
+
name: "settlements",
|
|
4114
|
+
describe: "Organizer settlements, cross-tenant (writes move money)",
|
|
4115
|
+
list: getSettlements2,
|
|
4116
|
+
get: getSettlementsId2,
|
|
4117
|
+
columns: ["id", "reference", "status", "amount", "currency", "createdAt"],
|
|
4118
|
+
listFlags: [
|
|
4119
|
+
{
|
|
4120
|
+
flag: "--status <s>",
|
|
4121
|
+
describe: "DRAFT | GENERATED | SENT | AWAITING_PAYMENT | PAID | REQUESTED | PENDING | REJECTED",
|
|
4122
|
+
query: "status"
|
|
4123
|
+
},
|
|
4124
|
+
{
|
|
4125
|
+
flag: "--organization <id>",
|
|
4126
|
+
describe: "only this organization's",
|
|
4127
|
+
query: "organizationId"
|
|
4128
|
+
}
|
|
4129
|
+
],
|
|
4130
|
+
extend: registerAdminSettlementWrites
|
|
4131
|
+
},
|
|
2940
4132
|
{
|
|
2941
4133
|
name: "audit-log",
|
|
2942
4134
|
describe: "Superadmin audit log",
|
|
@@ -2951,6 +4143,7 @@ function registerAdmin(program2) {
|
|
|
2951
4143
|
}
|
|
2952
4144
|
];
|
|
2953
4145
|
for (const spec of resources) registerAdminResource(admin, spec);
|
|
4146
|
+
registerAdminCrm(admin);
|
|
2954
4147
|
}
|
|
2955
4148
|
function registerAdminResource(parent, spec) {
|
|
2956
4149
|
const root = parent.command(spec.name).description(spec.describe);
|
|
@@ -2976,7 +4169,7 @@ function registerAdminResource(parent, spec) {
|
|
|
2976
4169
|
query.cursor = opts.cursor;
|
|
2977
4170
|
}
|
|
2978
4171
|
for (const f of spec.listFlags ?? []) {
|
|
2979
|
-
const v = opts[
|
|
4172
|
+
const v = opts[flagKey(f.flag)];
|
|
2980
4173
|
if (v !== void 0) query[f.query] = v;
|
|
2981
4174
|
}
|
|
2982
4175
|
const columns = resolveColumns(opts, spec.columns);
|
|
@@ -3063,13 +4256,15 @@ function registerAdminResource(parent, spec) {
|
|
|
3063
4256
|
print(body?.data ?? body ?? { ok: true }, { json: opts.json });
|
|
3064
4257
|
});
|
|
3065
4258
|
}
|
|
4259
|
+
spec.extend?.(root);
|
|
3066
4260
|
}
|
|
3067
|
-
function
|
|
3068
|
-
|
|
4261
|
+
function flagKey(flag) {
|
|
4262
|
+
const long = flag.split(/[ ,]/).find((p) => p.startsWith("--")) ?? flag;
|
|
4263
|
+
return long.replace(/^--/, "").replace(/-([a-z])/g, (_, c2) => c2.toUpperCase());
|
|
3069
4264
|
}
|
|
3070
4265
|
|
|
3071
4266
|
// src/commands/api-keys.ts
|
|
3072
|
-
import
|
|
4267
|
+
import chalk8 from "chalk";
|
|
3073
4268
|
var COLUMNS = [
|
|
3074
4269
|
"name",
|
|
3075
4270
|
"keyPrefix",
|
|
@@ -3102,13 +4297,13 @@ function registerApiKeys(program2) {
|
|
|
3102
4297
|
}
|
|
3103
4298
|
console.log(
|
|
3104
4299
|
`
|
|
3105
|
-
${
|
|
4300
|
+
${chalk8.green("\u2713")} API key "${chalk8.bold(key.name)}" created (scope: ${key.scope}).
|
|
3106
4301
|
`
|
|
3107
4302
|
);
|
|
3108
4303
|
console.log(
|
|
3109
|
-
|
|
4304
|
+
chalk8.yellow(" Copy your secret now \u2014 it will NOT be shown again:\n")
|
|
3110
4305
|
);
|
|
3111
|
-
console.log(` ${
|
|
4306
|
+
console.log(` ${chalk8.bold.cyan(key.key)}
|
|
3112
4307
|
`);
|
|
3113
4308
|
print(
|
|
3114
4309
|
{
|
|
@@ -3220,9 +4415,9 @@ import {
|
|
|
3220
4415
|
closeSync,
|
|
3221
4416
|
lstatSync,
|
|
3222
4417
|
openSync,
|
|
3223
|
-
readFileSync as
|
|
4418
|
+
readFileSync as readFileSync5,
|
|
3224
4419
|
readSync,
|
|
3225
|
-
statSync
|
|
4420
|
+
statSync as statSync2
|
|
3226
4421
|
} from "fs";
|
|
3227
4422
|
import { dirname as dirname3, isAbsolute, relative, resolve } from "path";
|
|
3228
4423
|
var MAX_IMAGE_BYTES = 6 * 1024 * 1024;
|
|
@@ -3309,7 +4504,7 @@ function checkImage(path) {
|
|
|
3309
4504
|
let size;
|
|
3310
4505
|
let head;
|
|
3311
4506
|
try {
|
|
3312
|
-
const st =
|
|
4507
|
+
const st = statSync2(path);
|
|
3313
4508
|
if (!st.isFile()) throw new Error("not a file");
|
|
3314
4509
|
size = st.size;
|
|
3315
4510
|
head = readHead(path);
|
|
@@ -3528,7 +4723,7 @@ var sdkDeps = {
|
|
|
3528
4723
|
uploadUrl: (body) => postMerchProductsImagesUploadUrl({ body }),
|
|
3529
4724
|
setImages: (id, imageUrls) => putMerchProductsIdImages({ path: { id }, body: { imageUrls } }),
|
|
3530
4725
|
setStatus: (id, status) => patchMerchProductsIdStatus({ path: { id }, body: { status } }),
|
|
3531
|
-
readFile: (path) =>
|
|
4726
|
+
readFile: (path) => readFileSync5(path),
|
|
3532
4727
|
// Signed storage URL: no Authorization header, the token is in the URL.
|
|
3533
4728
|
put: (url, body, contentType) => fetch(url, {
|
|
3534
4729
|
method: "PUT",
|
|
@@ -3600,7 +4795,7 @@ function registerMerch(program2, deps = sdkDeps) {
|
|
|
3600
4795
|
if (opts.name) fail("Use either --from-json or --name, not both.");
|
|
3601
4796
|
let raw;
|
|
3602
4797
|
try {
|
|
3603
|
-
raw =
|
|
4798
|
+
raw = readFileSync5(opts.fromJson, "utf8");
|
|
3604
4799
|
} catch {
|
|
3605
4800
|
fail(`Cannot read file: ${opts.fromJson}`);
|
|
3606
4801
|
}
|
|
@@ -3873,7 +5068,7 @@ function printExport(rows, opts) {
|
|
|
3873
5068
|
}
|
|
3874
5069
|
|
|
3875
5070
|
// src/commands/resource.ts
|
|
3876
|
-
import
|
|
5071
|
+
import chalk9 from "chalk";
|
|
3877
5072
|
function registerResource(program2, spec) {
|
|
3878
5073
|
const root = program2.command(spec.name).description(spec.describe);
|
|
3879
5074
|
const singular = spec.name.replace(/s$/, "");
|
|
@@ -3894,7 +5089,7 @@ function registerResource(program2, spec) {
|
|
|
3894
5089
|
cursor: opts.cursor
|
|
3895
5090
|
};
|
|
3896
5091
|
for (const f of spec.listFlags ?? []) {
|
|
3897
|
-
const v = opts[
|
|
5092
|
+
const v = opts[camel(f.query)];
|
|
3898
5093
|
if (v !== void 0) query[f.query] = v;
|
|
3899
5094
|
}
|
|
3900
5095
|
const targets = await listTargets(opts.workspace);
|
|
@@ -3915,7 +5110,7 @@ function registerResource(program2, spec) {
|
|
|
3915
5110
|
const res = await list({ query: { ...query, limit, cursor } });
|
|
3916
5111
|
if (res.error !== void 0) {
|
|
3917
5112
|
console.error(
|
|
3918
|
-
|
|
5113
|
+
chalk9.dim(
|
|
3919
5114
|
`(${withAccount ? `${ws.account.name} / ` : ""}${ws.name}: ${describeError(res)})`
|
|
3920
5115
|
)
|
|
3921
5116
|
);
|
|
@@ -3953,7 +5148,7 @@ function registerResource(program2, spec) {
|
|
|
3953
5148
|
});
|
|
3954
5149
|
if (out.length === 0)
|
|
3955
5150
|
console.error(
|
|
3956
|
-
|
|
5151
|
+
chalk9.dim(
|
|
3957
5152
|
`(0 results across ${targets.length} workspaces - check them with \`ft workspace list\`)`
|
|
3958
5153
|
)
|
|
3959
5154
|
);
|
|
@@ -4076,7 +5271,7 @@ function registerResource(program2, spec) {
|
|
|
4076
5271
|
}
|
|
4077
5272
|
spec.extend?.(root);
|
|
4078
5273
|
}
|
|
4079
|
-
function
|
|
5274
|
+
function camel(s) {
|
|
4080
5275
|
return s.replace(/-([a-z])/g, (_, c2) => c2.toUpperCase());
|
|
4081
5276
|
}
|
|
4082
5277
|
|
|
@@ -4128,7 +5323,7 @@ function registerTickets(program2) {
|
|
|
4128
5323
|
}
|
|
4129
5324
|
|
|
4130
5325
|
// src/commands/workspace.ts
|
|
4131
|
-
import
|
|
5326
|
+
import chalk10 from "chalk";
|
|
4132
5327
|
function registerWorkspace(program2) {
|
|
4133
5328
|
const root = program2.command("workspace").description("List, pin, unpin, show, and create workspaces");
|
|
4134
5329
|
root.command("list").alias("ls").description(
|
|
@@ -4197,7 +5392,7 @@ function registerWorkspace(program2) {
|
|
|
4197
5392
|
if (account.name !== ENV_ACCOUNT && Object.keys(readConfig().accounts ?? {}).length > 1)
|
|
4198
5393
|
saveConfig({ activeAccount: account.name });
|
|
4199
5394
|
console.log(
|
|
4200
|
-
`${
|
|
5395
|
+
`${chalk10.green("\u2713")} Active workspace: ${chalk10.bold(match.name)} ${chalk10.dim(`(${match.slug})`)}` + (accounts.length > 1 ? ` ${chalk10.dim(`via ${account.name}`)}` : "")
|
|
4201
5396
|
);
|
|
4202
5397
|
return;
|
|
4203
5398
|
}
|
|
@@ -4219,7 +5414,7 @@ function registerWorkspace(program2) {
|
|
|
4219
5414
|
if (!opts.account)
|
|
4220
5415
|
saveConfig({ activeAccount: void 0, workspaceId: void 0 });
|
|
4221
5416
|
console.log(
|
|
4222
|
-
`${
|
|
5417
|
+
`${chalk10.green("\u2713")} No workspace pinned: lists now read all of them.`
|
|
4223
5418
|
);
|
|
4224
5419
|
});
|
|
4225
5420
|
root.command("show").description("Show the active workspace").option(
|
|
@@ -4249,7 +5444,7 @@ function registerWorkspace(program2) {
|
|
|
4249
5444
|
await postWorkspaces({ body: { name: opts.name, slug: opts.slug } })
|
|
4250
5445
|
);
|
|
4251
5446
|
console.error(
|
|
4252
|
-
`${
|
|
5447
|
+
`${chalk10.green("\u2713")} Workspace ${chalk10.bold(opts.name)} created. ${chalk10.dim(`Pin it with \`ft workspace use ${opts.slug}\`.`)}`
|
|
4253
5448
|
);
|
|
4254
5449
|
print(body?.data ?? body, { json: opts.json });
|
|
4255
5450
|
});
|
|
@@ -4302,13 +5497,29 @@ registerResource(program, {
|
|
|
4302
5497
|
describe: "Settlements paid to the organizer",
|
|
4303
5498
|
list: getSettlements,
|
|
4304
5499
|
get: getSettlementsId,
|
|
4305
|
-
|
|
5500
|
+
// `kind` (contract 1.54): EVENT settlements of ticket sales or MEMBERSHIP
|
|
5501
|
+
// ones of a period; membership rows carry `period`/`membershipPlan` instead
|
|
5502
|
+
// of `event`/`eventDate`.
|
|
5503
|
+
columns: [
|
|
5504
|
+
"id",
|
|
5505
|
+
"reference",
|
|
5506
|
+
"kind",
|
|
5507
|
+
"status",
|
|
5508
|
+
"amount",
|
|
5509
|
+
"currency",
|
|
5510
|
+
"createdAt"
|
|
5511
|
+
],
|
|
4306
5512
|
listFlags: [
|
|
4307
5513
|
{ flag: "--event <id>", describe: "filter by event", query: "event" },
|
|
4308
5514
|
{
|
|
4309
5515
|
flag: "--status <s>",
|
|
4310
5516
|
describe: "SENT | AWAITING_PAYMENT | PAID",
|
|
4311
5517
|
query: "status"
|
|
5518
|
+
},
|
|
5519
|
+
{
|
|
5520
|
+
flag: "--kind <k>",
|
|
5521
|
+
describe: "EVENT | MEMBERSHIP (default: both)",
|
|
5522
|
+
query: "kind"
|
|
4312
5523
|
}
|
|
4313
5524
|
],
|
|
4314
5525
|
extend: (root) => {
|
|
@@ -4549,6 +5760,11 @@ registerResource(program, {
|
|
|
4549
5760
|
}
|
|
4550
5761
|
]
|
|
4551
5762
|
});
|
|
5763
|
+
registerResource(program, {
|
|
5764
|
+
name: "courtesy-requests",
|
|
5765
|
+
describe: "Courtesy invitation requests of an enterprise landing",
|
|
5766
|
+
create: postCourtesyRequests
|
|
5767
|
+
});
|
|
4552
5768
|
registerMerch(program);
|
|
4553
5769
|
registerTickets(program);
|
|
4554
5770
|
registerReports(program);
|