@freeticket/cli 0.1.1 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +9 -9
  2. package/dist/index.js +1174 -79
  3. package/package.json +13 -4
package/dist/index.js CHANGED
@@ -6,9 +6,15 @@ import { Command } from "commander";
6
6
  // package.json
7
7
  var package_default = {
8
8
  name: "@freeticket/cli",
9
- version: "0.1.1",
9
+ version: "0.4.1",
10
10
  description: "Official FreeTicket CLI \u2014 consumes the B2B REST API for events, sales, tickets, memberships, venues, staff, and reports.",
11
- keywords: ["freeticket", "cli", "ticketing", "events", "api"],
11
+ keywords: [
12
+ "freeticket",
13
+ "cli",
14
+ "ticketing",
15
+ "events",
16
+ "api"
17
+ ],
12
18
  homepage: "https://github.com/AppFreeticket/freeticket-cli#readme",
13
19
  bugs: "https://github.com/AppFreeticket/freeticket-cli/issues",
14
20
  repository: {
@@ -22,7 +28,9 @@ var package_default = {
22
28
  bin: {
23
29
  ft: "dist/index.js"
24
30
  },
25
- files: ["dist"],
31
+ files: [
32
+ "dist"
33
+ ],
26
34
  engines: {
27
35
  node: ">=20"
28
36
  },
@@ -32,8 +40,9 @@ var package_default = {
32
40
  scripts: {
33
41
  build: "tsup",
34
42
  dev: "tsup --watch",
35
- generate: "openapi-ts",
43
+ generate: "openapi-ts && openapi-ts -f openapi-ts.admin.config.ts",
36
44
  "sync-openapi": "tsx scripts/sync-openapi.ts",
45
+ "sync-openapi:admin": "FT_OPENAPI_URL=${FT_ADMIN_OPENAPI_URL:-https://admin.appfreeticket.com/api/admin/openapi.json} FT_OPENAPI_OUT=admin-openapi.json tsx scripts/sync-openapi.ts",
37
46
  lint: "biome check .",
38
47
  format: "biome check --write .",
39
48
  test: "vitest run",
@@ -61,10 +70,26 @@ var package_default = {
61
70
  // src/client/client.gen.ts
62
71
  import { createClient, createConfig } from "@hey-api/client-fetch";
63
72
  var client = createClient(createConfig({
64
- baseUrl: "http://localhost:3000/api/v1"
73
+ baseUrl: "https://admin.appfreeticket.com/api/v1"
65
74
  }));
66
75
 
67
76
  // src/client/sdk.gen.ts
77
+ var postAuthDeviceCode = (options) => {
78
+ return (options?.client ?? client).post({
79
+ url: "/auth/device/code",
80
+ ...options
81
+ });
82
+ };
83
+ var postAuthDeviceToken = (options) => {
84
+ return (options.client ?? client).post({
85
+ url: "/auth/device/token",
86
+ ...options,
87
+ headers: {
88
+ "Content-Type": "application/json",
89
+ ...options?.headers
90
+ }
91
+ });
92
+ };
68
93
  var getMe = (options) => {
69
94
  return (options?.client ?? client).get({
70
95
  security: [
@@ -73,182 +98,766 @@ var getMe = (options) => {
73
98
  type: "apiKey"
74
99
  }
75
100
  ],
76
- url: "/me",
101
+ url: "/me",
102
+ ...options
103
+ });
104
+ };
105
+ var getEvents = (options) => {
106
+ return (options?.client ?? client).get({
107
+ security: [
108
+ {
109
+ name: "Authorization",
110
+ type: "apiKey"
111
+ }
112
+ ],
113
+ url: "/events",
114
+ ...options
115
+ });
116
+ };
117
+ var postEvents = (options) => {
118
+ return (options.client ?? client).post({
119
+ security: [
120
+ {
121
+ name: "Authorization",
122
+ type: "apiKey"
123
+ }
124
+ ],
125
+ url: "/events",
126
+ ...options,
127
+ headers: {
128
+ "Content-Type": "application/json",
129
+ ...options?.headers
130
+ }
131
+ });
132
+ };
133
+ var deleteEventsId = (options) => {
134
+ return (options.client ?? client).delete({
135
+ security: [
136
+ {
137
+ name: "Authorization",
138
+ type: "apiKey"
139
+ }
140
+ ],
141
+ url: "/events/{id}",
142
+ ...options
143
+ });
144
+ };
145
+ var getEventsId = (options) => {
146
+ return (options.client ?? client).get({
147
+ security: [
148
+ {
149
+ name: "Authorization",
150
+ type: "apiKey"
151
+ }
152
+ ],
153
+ url: "/events/{id}",
154
+ ...options
155
+ });
156
+ };
157
+ var patchEventsId = (options) => {
158
+ return (options.client ?? client).patch({
159
+ security: [
160
+ {
161
+ name: "Authorization",
162
+ type: "apiKey"
163
+ }
164
+ ],
165
+ url: "/events/{id}",
166
+ ...options,
167
+ headers: {
168
+ "Content-Type": "application/json",
169
+ ...options?.headers
170
+ }
171
+ });
172
+ };
173
+ var postEventsIdPublish = (options) => {
174
+ return (options.client ?? client).post({
175
+ security: [
176
+ {
177
+ name: "Authorization",
178
+ type: "apiKey"
179
+ }
180
+ ],
181
+ url: "/events/{id}/publish",
182
+ ...options
183
+ });
184
+ };
185
+ var getEventsIdDates = (options) => {
186
+ return (options.client ?? client).get({
187
+ security: [
188
+ {
189
+ name: "Authorization",
190
+ type: "apiKey"
191
+ }
192
+ ],
193
+ url: "/events/{id}/dates",
194
+ ...options
195
+ });
196
+ };
197
+ var postEventsIdDates = (options) => {
198
+ return (options.client ?? client).post({
199
+ security: [
200
+ {
201
+ name: "Authorization",
202
+ type: "apiKey"
203
+ }
204
+ ],
205
+ url: "/events/{id}/dates",
206
+ ...options
207
+ });
208
+ };
209
+ var deleteEventsIdDatesDateId = (options) => {
210
+ return (options.client ?? client).delete({
211
+ security: [
212
+ {
213
+ name: "Authorization",
214
+ type: "apiKey"
215
+ }
216
+ ],
217
+ url: "/events/{id}/dates/{dateId}",
218
+ ...options
219
+ });
220
+ };
221
+ var patchEventsIdDatesDateId = (options) => {
222
+ return (options.client ?? client).patch({
223
+ security: [
224
+ {
225
+ name: "Authorization",
226
+ type: "apiKey"
227
+ }
228
+ ],
229
+ url: "/events/{id}/dates/{dateId}",
230
+ ...options
231
+ });
232
+ };
233
+ var getTicketTypes = (options) => {
234
+ return (options?.client ?? client).get({
235
+ security: [
236
+ {
237
+ name: "Authorization",
238
+ type: "apiKey"
239
+ }
240
+ ],
241
+ url: "/ticket-types",
242
+ ...options
243
+ });
244
+ };
245
+ var postTicketTypes = (options) => {
246
+ return (options.client ?? client).post({
247
+ security: [
248
+ {
249
+ name: "Authorization",
250
+ type: "apiKey"
251
+ }
252
+ ],
253
+ url: "/ticket-types",
254
+ ...options,
255
+ headers: {
256
+ "Content-Type": "application/json",
257
+ ...options?.headers
258
+ }
259
+ });
260
+ };
261
+ var deleteTicketTypesId = (options) => {
262
+ return (options.client ?? client).delete({
263
+ security: [
264
+ {
265
+ name: "Authorization",
266
+ type: "apiKey"
267
+ }
268
+ ],
269
+ url: "/ticket-types/{id}",
270
+ ...options
271
+ });
272
+ };
273
+ var getTicketTypesId = (options) => {
274
+ return (options.client ?? client).get({
275
+ security: [
276
+ {
277
+ name: "Authorization",
278
+ type: "apiKey"
279
+ }
280
+ ],
281
+ url: "/ticket-types/{id}",
282
+ ...options
283
+ });
284
+ };
285
+ var patchTicketTypesId = (options) => {
286
+ return (options.client ?? client).patch({
287
+ security: [
288
+ {
289
+ name: "Authorization",
290
+ type: "apiKey"
291
+ }
292
+ ],
293
+ url: "/ticket-types/{id}",
294
+ ...options
295
+ });
296
+ };
297
+ var getSales = (options) => {
298
+ return (options?.client ?? client).get({
299
+ security: [
300
+ {
301
+ name: "Authorization",
302
+ type: "apiKey"
303
+ }
304
+ ],
305
+ url: "/sales",
306
+ ...options
307
+ });
308
+ };
309
+ var getSalesId = (options) => {
310
+ return (options.client ?? client).get({
311
+ security: [
312
+ {
313
+ name: "Authorization",
314
+ type: "apiKey"
315
+ }
316
+ ],
317
+ url: "/sales/{id}",
318
+ ...options
319
+ });
320
+ };
321
+ var postSalesIdCancel = (options) => {
322
+ return (options.client ?? client).post({
323
+ security: [
324
+ {
325
+ name: "Authorization",
326
+ type: "apiKey"
327
+ }
328
+ ],
329
+ url: "/sales/{id}/cancel",
330
+ ...options
331
+ });
332
+ };
333
+ var postSalesIdRefund = (options) => {
334
+ return (options.client ?? client).post({
335
+ security: [
336
+ {
337
+ name: "Authorization",
338
+ type: "apiKey"
339
+ }
340
+ ],
341
+ url: "/sales/{id}/refund",
342
+ ...options
343
+ });
344
+ };
345
+ var getMembershipPlans = (options) => {
346
+ return (options?.client ?? client).get({
347
+ security: [
348
+ {
349
+ name: "Authorization",
350
+ type: "apiKey"
351
+ }
352
+ ],
353
+ url: "/membership-plans",
354
+ ...options
355
+ });
356
+ };
357
+ var postMembershipPlans = (options) => {
358
+ return (options.client ?? client).post({
359
+ security: [
360
+ {
361
+ name: "Authorization",
362
+ type: "apiKey"
363
+ }
364
+ ],
365
+ url: "/membership-plans",
366
+ ...options,
367
+ headers: {
368
+ "Content-Type": "application/json",
369
+ ...options?.headers
370
+ }
371
+ });
372
+ };
373
+ var deleteMembershipPlansId = (options) => {
374
+ return (options.client ?? client).delete({
375
+ security: [
376
+ {
377
+ name: "Authorization",
378
+ type: "apiKey"
379
+ }
380
+ ],
381
+ url: "/membership-plans/{id}",
382
+ ...options
383
+ });
384
+ };
385
+ var getMembershipPlansId = (options) => {
386
+ return (options.client ?? client).get({
387
+ security: [
388
+ {
389
+ name: "Authorization",
390
+ type: "apiKey"
391
+ }
392
+ ],
393
+ url: "/membership-plans/{id}",
394
+ ...options
395
+ });
396
+ };
397
+ var patchMembershipPlansId = (options) => {
398
+ return (options.client ?? client).patch({
399
+ security: [
400
+ {
401
+ name: "Authorization",
402
+ type: "apiKey"
403
+ }
404
+ ],
405
+ url: "/membership-plans/{id}",
406
+ ...options
407
+ });
408
+ };
409
+ var getVenues = (options) => {
410
+ return (options?.client ?? client).get({
411
+ security: [
412
+ {
413
+ name: "Authorization",
414
+ type: "apiKey"
415
+ }
416
+ ],
417
+ url: "/venues",
418
+ ...options
419
+ });
420
+ };
421
+ var postVenues = (options) => {
422
+ return (options.client ?? client).post({
423
+ security: [
424
+ {
425
+ name: "Authorization",
426
+ type: "apiKey"
427
+ }
428
+ ],
429
+ url: "/venues",
430
+ ...options,
431
+ headers: {
432
+ "Content-Type": "application/json",
433
+ ...options?.headers
434
+ }
435
+ });
436
+ };
437
+ var deleteVenuesId = (options) => {
438
+ return (options.client ?? client).delete({
439
+ security: [
440
+ {
441
+ name: "Authorization",
442
+ type: "apiKey"
443
+ }
444
+ ],
445
+ url: "/venues/{id}",
446
+ ...options
447
+ });
448
+ };
449
+ var getVenuesId = (options) => {
450
+ return (options.client ?? client).get({
451
+ security: [
452
+ {
453
+ name: "Authorization",
454
+ type: "apiKey"
455
+ }
456
+ ],
457
+ url: "/venues/{id}",
458
+ ...options
459
+ });
460
+ };
461
+ var patchVenuesId = (options) => {
462
+ return (options.client ?? client).patch({
463
+ security: [
464
+ {
465
+ name: "Authorization",
466
+ type: "apiKey"
467
+ }
468
+ ],
469
+ url: "/venues/{id}",
470
+ ...options
471
+ });
472
+ };
473
+ var getStaff = (options) => {
474
+ return (options?.client ?? client).get({
475
+ security: [
476
+ {
477
+ name: "Authorization",
478
+ type: "apiKey"
479
+ }
480
+ ],
481
+ url: "/staff",
482
+ ...options
483
+ });
484
+ };
485
+ var postStaff = (options) => {
486
+ return (options.client ?? client).post({
487
+ security: [
488
+ {
489
+ name: "Authorization",
490
+ type: "apiKey"
491
+ }
492
+ ],
493
+ url: "/staff",
494
+ ...options,
495
+ headers: {
496
+ "Content-Type": "application/json",
497
+ ...options?.headers
498
+ }
499
+ });
500
+ };
501
+ var patchStaffIdRole = (options) => {
502
+ return (options.client ?? client).patch({
503
+ security: [
504
+ {
505
+ name: "Authorization",
506
+ type: "apiKey"
507
+ }
508
+ ],
509
+ url: "/staff/{id}/role",
510
+ ...options,
511
+ headers: {
512
+ "Content-Type": "application/json",
513
+ ...options?.headers
514
+ }
515
+ });
516
+ };
517
+ var getReportsSummary = (options) => {
518
+ return (options?.client ?? client).get({
519
+ security: [
520
+ {
521
+ name: "Authorization",
522
+ type: "apiKey"
523
+ }
524
+ ],
525
+ url: "/reports/summary",
526
+ ...options
527
+ });
528
+ };
529
+ var getReportsReconciliation = (options) => {
530
+ return (options.client ?? client).get({
531
+ security: [
532
+ {
533
+ name: "Authorization",
534
+ type: "apiKey"
535
+ }
536
+ ],
537
+ url: "/reports/reconciliation",
538
+ ...options
539
+ });
540
+ };
541
+ var getReportsExportsReconciliation = (options) => {
542
+ return (options.client ?? client).get({
543
+ security: [
544
+ {
545
+ name: "Authorization",
546
+ type: "apiKey"
547
+ }
548
+ ],
549
+ url: "/reports/exports/reconciliation",
550
+ ...options
551
+ });
552
+ };
553
+ var getReportsExportsBuyers = (options) => {
554
+ return (options?.client ?? client).get({
555
+ security: [
556
+ {
557
+ name: "Authorization",
558
+ type: "apiKey"
559
+ }
560
+ ],
561
+ url: "/reports/exports/buyers",
562
+ ...options
563
+ });
564
+ };
565
+ var getReportsExportsSubscribers = (options) => {
566
+ return (options?.client ?? client).get({
567
+ security: [
568
+ {
569
+ name: "Authorization",
570
+ type: "apiKey"
571
+ }
572
+ ],
573
+ url: "/reports/exports/subscribers",
77
574
  ...options
78
575
  });
79
576
  };
80
- var getEvents = (options) => {
81
- return (options?.client ?? client).get({
577
+
578
+ // src/admin-client/client.gen.ts
579
+ import { createClient as createClient2, createConfig as createConfig2 } from "@hey-api/client-fetch";
580
+ var client2 = createClient2(createConfig2({
581
+ baseUrl: "https://admin.appfreeticket.com/api/admin"
582
+ }));
583
+
584
+ // src/admin-client/sdk.gen.ts
585
+ var getMe2 = (options) => {
586
+ return (options?.client ?? client2).get({
82
587
  security: [
83
588
  {
84
- name: "Authorization",
589
+ in: "cookie",
590
+ name: "better-auth.session_token",
85
591
  type: "apiKey"
86
592
  }
87
593
  ],
88
- url: "/events",
594
+ url: "/me",
89
595
  ...options
90
596
  });
91
597
  };
92
- var getEventsId = (options) => {
93
- return (options.client ?? client).get({
598
+ var getWorkspaces = (options) => {
599
+ return (options?.client ?? client2).get({
94
600
  security: [
95
601
  {
96
- name: "Authorization",
602
+ in: "cookie",
603
+ name: "better-auth.session_token",
97
604
  type: "apiKey"
98
605
  }
99
606
  ],
100
- url: "/events/{id}",
607
+ url: "/workspaces",
101
608
  ...options
102
609
  });
103
610
  };
104
- var getTicketTypes = (options) => {
105
- return (options?.client ?? client).get({
611
+ var postWorkspaces = (options) => {
612
+ return (options.client ?? client2).post({
106
613
  security: [
107
614
  {
108
- name: "Authorization",
615
+ in: "cookie",
616
+ name: "better-auth.session_token",
109
617
  type: "apiKey"
110
618
  }
111
619
  ],
112
- url: "/ticket-types",
113
- ...options
620
+ url: "/workspaces",
621
+ ...options,
622
+ headers: {
623
+ "Content-Type": "application/json",
624
+ ...options?.headers
625
+ }
114
626
  });
115
627
  };
116
- var getTicketTypesId = (options) => {
117
- return (options.client ?? client).get({
628
+ var getWorkspacesId = (options) => {
629
+ return (options.client ?? client2).get({
118
630
  security: [
119
631
  {
120
- name: "Authorization",
632
+ in: "cookie",
633
+ name: "better-auth.session_token",
121
634
  type: "apiKey"
122
635
  }
123
636
  ],
124
- url: "/ticket-types/{id}",
637
+ url: "/workspaces/{id}",
125
638
  ...options
126
639
  });
127
640
  };
128
- var getSales = (options) => {
129
- return (options?.client ?? client).get({
641
+ var patchWorkspacesId = (options) => {
642
+ return (options.client ?? client2).patch({
130
643
  security: [
131
644
  {
132
- name: "Authorization",
645
+ in: "cookie",
646
+ name: "better-auth.session_token",
133
647
  type: "apiKey"
134
648
  }
135
649
  ],
136
- url: "/sales",
137
- ...options
650
+ url: "/workspaces/{id}",
651
+ ...options,
652
+ headers: {
653
+ "Content-Type": "application/json",
654
+ ...options?.headers
655
+ }
138
656
  });
139
657
  };
140
- var getSalesId = (options) => {
141
- return (options.client ?? client).get({
658
+ var postWorkspacesIdSuspend = (options) => {
659
+ return (options.client ?? client2).post({
142
660
  security: [
143
661
  {
144
- name: "Authorization",
662
+ in: "cookie",
663
+ name: "better-auth.session_token",
145
664
  type: "apiKey"
146
665
  }
147
666
  ],
148
- url: "/sales/{id}",
667
+ url: "/workspaces/{id}/suspend",
149
668
  ...options
150
669
  });
151
670
  };
152
- var getMembershipPlans = (options) => {
153
- return (options?.client ?? client).get({
671
+ var postWorkspacesIdRestore = (options) => {
672
+ return (options.client ?? client2).post({
154
673
  security: [
155
674
  {
156
- name: "Authorization",
675
+ in: "cookie",
676
+ name: "better-auth.session_token",
157
677
  type: "apiKey"
158
678
  }
159
679
  ],
160
- url: "/membership-plans",
680
+ url: "/workspaces/{id}/restore",
161
681
  ...options
162
682
  });
163
683
  };
164
- var getMembershipPlansId = (options) => {
165
- return (options.client ?? client).get({
684
+ var getUsers = (options) => {
685
+ return (options?.client ?? client2).get({
166
686
  security: [
167
687
  {
168
- name: "Authorization",
688
+ in: "cookie",
689
+ name: "better-auth.session_token",
169
690
  type: "apiKey"
170
691
  }
171
692
  ],
172
- url: "/membership-plans/{id}",
693
+ url: "/users",
173
694
  ...options
174
695
  });
175
696
  };
176
- var getVenues = (options) => {
177
- return (options?.client ?? client).get({
697
+ var getUsersId = (options) => {
698
+ return (options.client ?? client2).get({
178
699
  security: [
179
700
  {
180
- name: "Authorization",
701
+ in: "cookie",
702
+ name: "better-auth.session_token",
181
703
  type: "apiKey"
182
704
  }
183
705
  ],
184
- url: "/venues",
706
+ url: "/users/{id}",
185
707
  ...options
186
708
  });
187
709
  };
188
- var getVenuesId = (options) => {
189
- return (options.client ?? client).get({
710
+ var patchUsersId = (options) => {
711
+ return (options.client ?? client2).patch({
190
712
  security: [
191
713
  {
192
- name: "Authorization",
714
+ in: "cookie",
715
+ name: "better-auth.session_token",
193
716
  type: "apiKey"
194
717
  }
195
718
  ],
196
- url: "/venues/{id}",
719
+ url: "/users/{id}",
720
+ ...options,
721
+ headers: {
722
+ "Content-Type": "application/json",
723
+ ...options?.headers
724
+ }
725
+ });
726
+ };
727
+ var postImpersonate = (options) => {
728
+ return (options.client ?? client2).post({
729
+ security: [
730
+ {
731
+ in: "cookie",
732
+ name: "better-auth.session_token",
733
+ type: "apiKey"
734
+ }
735
+ ],
736
+ url: "/impersonate",
737
+ ...options,
738
+ headers: {
739
+ "Content-Type": "application/json",
740
+ ...options?.headers
741
+ }
742
+ });
743
+ };
744
+ var postImpersonateStop = (options) => {
745
+ return (options?.client ?? client2).post({
746
+ security: [
747
+ {
748
+ in: "cookie",
749
+ name: "better-auth.session_token",
750
+ type: "apiKey"
751
+ }
752
+ ],
753
+ url: "/impersonate/stop",
197
754
  ...options
198
755
  });
199
756
  };
200
- var getStaff = (options) => {
201
- return (options?.client ?? client).get({
757
+ var getPlatformPlans = (options) => {
758
+ return (options?.client ?? client2).get({
202
759
  security: [
203
760
  {
204
- name: "Authorization",
761
+ in: "cookie",
762
+ name: "better-auth.session_token",
205
763
  type: "apiKey"
206
764
  }
207
765
  ],
208
- url: "/staff",
766
+ url: "/platform-plans",
209
767
  ...options
210
768
  });
211
769
  };
212
- var getReportsSummary = (options) => {
213
- return (options?.client ?? client).get({
770
+ var postPlatformPlans = (options) => {
771
+ return (options.client ?? client2).post({
214
772
  security: [
215
773
  {
216
- name: "Authorization",
774
+ in: "cookie",
775
+ name: "better-auth.session_token",
217
776
  type: "apiKey"
218
777
  }
219
778
  ],
220
- url: "/reports/summary",
779
+ url: "/platform-plans",
780
+ ...options,
781
+ headers: {
782
+ "Content-Type": "application/json",
783
+ ...options?.headers
784
+ }
785
+ });
786
+ };
787
+ var getPlatformPlansId = (options) => {
788
+ return (options.client ?? client2).get({
789
+ security: [
790
+ {
791
+ in: "cookie",
792
+ name: "better-auth.session_token",
793
+ type: "apiKey"
794
+ }
795
+ ],
796
+ url: "/platform-plans/{id}",
221
797
  ...options
222
798
  });
223
799
  };
224
- var getReportsExportsBuyers = (options) => {
225
- return (options?.client ?? client).get({
800
+ var patchPlatformPlansId = (options) => {
801
+ return (options.client ?? client2).patch({
226
802
  security: [
227
803
  {
228
- name: "Authorization",
804
+ in: "cookie",
805
+ name: "better-auth.session_token",
229
806
  type: "apiKey"
230
807
  }
231
808
  ],
232
- url: "/reports/exports/buyers",
809
+ url: "/platform-plans/{id}",
810
+ ...options,
811
+ headers: {
812
+ "Content-Type": "application/json",
813
+ ...options?.headers
814
+ }
815
+ });
816
+ };
817
+ var getFeatureFlags = (options) => {
818
+ return (options?.client ?? client2).get({
819
+ security: [
820
+ {
821
+ in: "cookie",
822
+ name: "better-auth.session_token",
823
+ type: "apiKey"
824
+ }
825
+ ],
826
+ url: "/feature-flags",
233
827
  ...options
234
828
  });
235
829
  };
236
- var getReportsExportsSubscribers = (options) => {
237
- return (options?.client ?? client).get({
830
+ var putFeatureFlagsKey = (options) => {
831
+ return (options.client ?? client2).put({
238
832
  security: [
239
833
  {
240
- name: "Authorization",
834
+ in: "cookie",
835
+ name: "better-auth.session_token",
241
836
  type: "apiKey"
242
837
  }
243
838
  ],
244
- url: "/reports/exports/subscribers",
839
+ url: "/feature-flags/{key}",
840
+ ...options,
841
+ headers: {
842
+ "Content-Type": "application/json",
843
+ ...options?.headers
844
+ }
845
+ });
846
+ };
847
+ var getAuditLog = (options) => {
848
+ return (options?.client ?? client2).get({
849
+ security: [
850
+ {
851
+ in: "cookie",
852
+ name: "better-auth.session_token",
853
+ type: "apiKey"
854
+ }
855
+ ],
856
+ url: "/audit-log",
245
857
  ...options
246
858
  });
247
859
  };
248
860
 
249
- // src/commands/auth.ts
250
- import chalk2 from "chalk";
251
-
252
861
  // src/lib/config.ts
253
862
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
254
863
  import { homedir } from "os";
@@ -269,7 +878,8 @@ function loadConfig() {
269
878
  return {
270
879
  apiUrl: process.env.FT_API_URL ?? file.apiUrl ?? DEFAULT_API_URL,
271
880
  apiKey: process.env.FT_API_KEY ?? file.apiKey,
272
- workspaceId: process.env.FT_WORKSPACE_ID ?? file.workspaceId
881
+ workspaceId: process.env.FT_WORKSPACE_ID ?? file.workspaceId,
882
+ adminSession: process.env.FT_ADMIN_SESSION ?? file.adminSession
273
883
  };
274
884
  }
275
885
  function saveConfig(patch) {
@@ -296,6 +906,21 @@ function configureClient(workspaceOverride) {
296
906
  }
297
907
  });
298
908
  }
909
+ function configureAdminClient() {
910
+ const cfg = loadConfig();
911
+ if (!cfg.adminSession) {
912
+ fail(
913
+ "No superadmin session. Export FT_ADMIN_SESSION with a SUPER_ADMIN better-auth session token.",
914
+ "Log in to the admin panel in your browser and copy the `better-auth.session_token` cookie."
915
+ );
916
+ }
917
+ client2.setConfig({
918
+ baseUrl: `${cfg.apiUrl.replace(/\/$/, "")}/api/admin`,
919
+ headers: {
920
+ Cookie: `better-auth.session_token=${cfg.adminSession}`
921
+ }
922
+ });
923
+ }
299
924
  function unwrap(res) {
300
925
  if (res.data !== void 0) return res.data;
301
926
  const status = res.response?.status;
@@ -331,6 +956,44 @@ ${hint}`);
331
956
  process.exit(1);
332
957
  }
333
958
 
959
+ // src/lib/input.ts
960
+ import { readFileSync as readFileSync2 } from "fs";
961
+ import * as readline from "readline";
962
+ function parseData(input) {
963
+ if (!input) {
964
+ fail(
965
+ "Missing --data. Pass inline JSON or @path/to/file.json.",
966
+ `Example: --data '{"name":"My event"}' or --data @event.json`
967
+ );
968
+ }
969
+ let raw = input;
970
+ if (raw.startsWith("@")) {
971
+ try {
972
+ raw = readFileSync2(raw.slice(1), "utf8");
973
+ } catch {
974
+ fail(`Cannot read file: ${raw.slice(1)}`);
975
+ }
976
+ }
977
+ try {
978
+ return JSON.parse(raw);
979
+ } catch {
980
+ return fail("Invalid JSON in --data.");
981
+ }
982
+ }
983
+ function confirm(question) {
984
+ if (!process.stdin.isTTY) return Promise.resolve(false);
985
+ const rl = readline.createInterface({
986
+ input: process.stdin,
987
+ output: process.stderr
988
+ });
989
+ return new Promise((resolve) => {
990
+ rl.question(`${question} [y/N] `, (answer) => {
991
+ rl.close();
992
+ resolve(/^y(es)?$/i.test(answer.trim()));
993
+ });
994
+ });
995
+ }
996
+
334
997
  // src/lib/output.ts
335
998
  import chalk from "chalk";
336
999
  import Table from "cli-table3";
@@ -356,6 +1019,20 @@ function print(data, opts = {}) {
356
1019
  process.stdout.write(`${JSON.stringify(data, null, 2)}
357
1020
  `);
358
1021
  }
1022
+ function toCsv(rows, columns) {
1023
+ if (!Array.isArray(rows) || rows.length === 0) return "";
1024
+ const cols = columns ?? Object.keys(rows[0]);
1025
+ const esc = (v) => {
1026
+ if (v === null || v === void 0) return "";
1027
+ const s = typeof v === "object" ? JSON.stringify(v) : String(v);
1028
+ return /[",\n\r]/.test(s) ? `"${s.replace(/"/g, '""')}"` : s;
1029
+ };
1030
+ const head = cols.map(esc).join(",");
1031
+ const body = rows.map(
1032
+ (r) => cols.map((c2) => esc(r[c2])).join(",")
1033
+ );
1034
+ return [head, ...body].join("\n");
1035
+ }
359
1036
  function printNextCursor(page) {
360
1037
  if (page?.nextCursor) {
361
1038
  console.error(chalk.dim(`
@@ -371,21 +1048,213 @@ function fmt(v) {
371
1048
  return String(v);
372
1049
  }
373
1050
 
1051
+ // src/commands/admin.ts
1052
+ function registerAdmin(program2) {
1053
+ const admin = program2.command("admin").description("Superadmin (cross-tenant) \u2014 requires FT_ADMIN_SESSION");
1054
+ admin.command("me").description("Current superadmin identity (GET /api/admin/me)").option("--json", "raw JSON output").action(async (opts) => {
1055
+ configureAdminClient();
1056
+ const body = unwrap(await getMe2({}));
1057
+ print(body.data, { json: opts.json });
1058
+ });
1059
+ admin.command("impersonate").description(`Start impersonation (--data '{"targetUserId":"..."}')`).requiredOption("--data <json>", "JSON body (inline or @file.json)").option("--json", "raw JSON output").action(async (opts) => {
1060
+ configureAdminClient();
1061
+ const body = unwrap(
1062
+ await postImpersonate({ body: parseData(opts.data) })
1063
+ );
1064
+ print(body?.data ?? body, { json: opts.json });
1065
+ });
1066
+ admin.command("impersonate-stop").description("Stop the current impersonation").option("--json", "raw JSON output").action(async (opts) => {
1067
+ configureAdminClient();
1068
+ const body = unwrap(await postImpersonateStop({}));
1069
+ print(body?.data ?? { ok: true }, { json: opts.json });
1070
+ });
1071
+ const resources = [
1072
+ {
1073
+ name: "workspaces",
1074
+ describe: "Tenants / workspaces",
1075
+ list: getWorkspaces,
1076
+ get: getWorkspacesId,
1077
+ create: postWorkspaces,
1078
+ update: patchWorkspacesId,
1079
+ actions: [
1080
+ {
1081
+ name: "suspend",
1082
+ describe: "Suspend a workspace",
1083
+ fn: postWorkspacesIdSuspend,
1084
+ confirm: true
1085
+ },
1086
+ {
1087
+ name: "restore",
1088
+ describe: "Restore a suspended workspace",
1089
+ fn: postWorkspacesIdRestore
1090
+ }
1091
+ ],
1092
+ columns: ["id", "name", "type", "country", "suspended", "createdAt"],
1093
+ listFlags: [
1094
+ { flag: "--status <s>", describe: "filter by status", query: "status" },
1095
+ { flag: "--q <text>", describe: "search by name/slug", query: "q" }
1096
+ ]
1097
+ },
1098
+ {
1099
+ name: "users",
1100
+ describe: "Global users (cross-tenant)",
1101
+ list: getUsers,
1102
+ get: getUsersId,
1103
+ update: patchUsersId,
1104
+ columns: ["id", "name", "email", "role", "banned", "createdAt"],
1105
+ listFlags: [
1106
+ { flag: "--q <text>", describe: "search by name/email", query: "q" },
1107
+ { flag: "--role <r>", describe: "filter by role", query: "role" },
1108
+ {
1109
+ flag: "--workspace <id>",
1110
+ describe: "filter by workspace",
1111
+ query: "workspaceId"
1112
+ }
1113
+ ]
1114
+ },
1115
+ {
1116
+ name: "plans",
1117
+ describe: "Platform plans",
1118
+ list: getPlatformPlans,
1119
+ get: getPlatformPlansId,
1120
+ create: postPlatformPlans,
1121
+ update: patchPlatformPlansId,
1122
+ columns: ["id", "name", "price", "currency", "interval"]
1123
+ },
1124
+ {
1125
+ name: "feature-flags",
1126
+ describe: "Feature flags",
1127
+ list: getFeatureFlags,
1128
+ actions: [
1129
+ {
1130
+ name: "set",
1131
+ describe: `Set a flag (--data '{"scope":"...","enabled":true}')`,
1132
+ fn: putFeatureFlagsKey,
1133
+ body: true,
1134
+ param: "key"
1135
+ }
1136
+ ],
1137
+ columns: ["key", "enabled", "description"],
1138
+ noPaging: true
1139
+ },
1140
+ {
1141
+ name: "audit-log",
1142
+ describe: "Superadmin audit log",
1143
+ list: getAuditLog,
1144
+ columns: ["id", "actorId", "action", "targetType", "createdAt"],
1145
+ listFlags: [
1146
+ { flag: "--actor <id>", describe: "filter by actor", query: "actorId" },
1147
+ { flag: "--action <a>", describe: "filter by action", query: "action" },
1148
+ { flag: "--from <date>", describe: "from (ISO 8601)", query: "from" },
1149
+ { flag: "--to <date>", describe: "to (ISO 8601)", query: "to" }
1150
+ ]
1151
+ }
1152
+ ];
1153
+ for (const spec of resources) registerAdminResource(admin, spec);
1154
+ }
1155
+ function registerAdminResource(parent, spec) {
1156
+ const root = parent.command(spec.name).description(spec.describe);
1157
+ const singular = spec.name.replace(/s$/, "");
1158
+ if (spec.list) {
1159
+ const list = spec.list;
1160
+ const cmd = root.command("list").description(`List ${spec.name}`);
1161
+ if (!spec.noPaging) {
1162
+ cmd.option("--limit <n>", "results per page (1-100)", "20").option("--cursor <id>", "pagination cursor");
1163
+ }
1164
+ for (const f of spec.listFlags ?? []) cmd.option(f.flag, f.describe);
1165
+ cmd.option("--csv", "CSV output");
1166
+ cmd.option("--json", "raw JSON output");
1167
+ cmd.action(async (opts) => {
1168
+ configureAdminClient();
1169
+ const query = {};
1170
+ if (!spec.noPaging) {
1171
+ query.limit = Number(opts.limit);
1172
+ query.cursor = opts.cursor;
1173
+ }
1174
+ for (const f of spec.listFlags ?? []) {
1175
+ const v = opts[camel(f.query)];
1176
+ if (v !== void 0) query[f.query] = v;
1177
+ }
1178
+ const body = unwrap(await list({ query }));
1179
+ if (opts.csv) {
1180
+ process.stdout.write(`${toCsv(body.data, spec.columns)}
1181
+ `);
1182
+ return;
1183
+ }
1184
+ print(body.data, { json: opts.json, columns: spec.columns });
1185
+ if (!opts.json && !spec.noPaging) printNextCursor(body.page);
1186
+ });
1187
+ }
1188
+ if (spec.get) {
1189
+ const get = spec.get;
1190
+ root.command("get <id>").description(`Get one ${singular} by id`).option("--json", "raw JSON output").action(async (id, opts) => {
1191
+ configureAdminClient();
1192
+ const body = unwrap(await get({ path: { id } }));
1193
+ print(body.data, { json: opts.json });
1194
+ });
1195
+ }
1196
+ if (spec.create) {
1197
+ const create = spec.create;
1198
+ root.command("create").description(`Create a ${singular}`).requiredOption("--data <json>", "JSON body (inline or @file.json)").option("--json", "raw JSON output").action(async (opts) => {
1199
+ configureAdminClient();
1200
+ const body = unwrap(await create({ body: parseData(opts.data) }));
1201
+ print(body?.data ?? body, { json: opts.json });
1202
+ });
1203
+ }
1204
+ if (spec.update) {
1205
+ const update = spec.update;
1206
+ root.command("update <id>").description(`Update a ${singular} by id`).requiredOption("--data <json>", "JSON body (inline or @file.json)").option("--json", "raw JSON output").action(async (id, opts) => {
1207
+ configureAdminClient();
1208
+ const body = unwrap(
1209
+ await update({ path: { id }, body: parseData(opts.data) })
1210
+ );
1211
+ print(body?.data ?? body, { json: opts.json });
1212
+ });
1213
+ }
1214
+ for (const action of spec.actions ?? []) {
1215
+ const param = action.param ?? "id";
1216
+ const cmd = root.command(`${action.name} <${param}>`).description(action.describe).option("--yes", "skip confirmation").option("--json", "raw JSON output");
1217
+ if (action.body) {
1218
+ cmd.option("--data <json>", "JSON body (inline or @file.json)");
1219
+ }
1220
+ cmd.action(async (value, opts) => {
1221
+ if (action.confirm && !opts.yes && !await confirm(`${action.name} ${singular} ${value}?`)) {
1222
+ console.error("Aborted.");
1223
+ return;
1224
+ }
1225
+ configureAdminClient();
1226
+ const payload = { path: { [param]: value } };
1227
+ if (action.body && opts.data) payload.body = parseData(opts.data);
1228
+ const body = unwrap(await action.fn(payload));
1229
+ print(body?.data ?? body ?? { ok: true }, { json: opts.json });
1230
+ });
1231
+ }
1232
+ }
1233
+ function camel(s) {
1234
+ return s.replace(/-([a-z])/g, (_, c2) => c2.toUpperCase());
1235
+ }
1236
+
374
1237
  // src/commands/auth.ts
1238
+ import { spawn } from "child_process";
1239
+ import chalk2 from "chalk";
375
1240
  function registerAuth(program2) {
376
- program2.command("login").description("Store the API key and workspace in ~/.freeticket/config.json").requiredOption(
1241
+ program2.command("login").description(
1242
+ "Log in via the browser (device flow) and store the session in ~/.freeticket/config.json"
1243
+ ).option(
377
1244
  "--key <ft_live_\u2026>",
378
- "API key issued in the backend (pnpm api:key)"
1245
+ "Skip the browser and use an API key issued in the backend (CI / automation)"
379
1246
  ).option(
380
1247
  "--url <url>",
381
1248
  "API base URL (default: https://admin.appfreeticket.com)"
382
1249
  ).option("--workspace <id>", "default active workspace").action(async (opts) => {
1250
+ if (opts.url) saveConfig({ apiUrl: opts.url });
1251
+ const cred = opts.key ? { apiKey: opts.key, workspaceId: void 0 } : await deviceLogin();
1252
+ const workspaceId = opts.workspace ?? cred.workspaceId;
383
1253
  saveConfig({
384
- apiKey: opts.key,
385
- ...opts.url ? { apiUrl: opts.url } : {},
386
- ...opts.workspace ? { workspaceId: opts.workspace } : {}
1254
+ apiKey: cred.apiKey,
1255
+ ...workspaceId ? { workspaceId } : {}
387
1256
  });
388
- configureClient(opts.workspace);
1257
+ configureClient(workspaceId);
389
1258
  const me = unwrap(await getMe({})).data;
390
1259
  console.log(
391
1260
  `${chalk2.green("\u2713")} Session saved in ${chalk2.dim(CONFIG_PATH)}`
@@ -415,6 +1284,110 @@ function registerAuth(program2) {
415
1284
  );
416
1285
  });
417
1286
  }
1287
+ var sleep = (ms) => new Promise((r) => setTimeout(r, ms));
1288
+ function openBrowser(url) {
1289
+ const cmd = process.platform === "darwin" ? "open" : process.platform === "win32" ? "start" : "xdg-open";
1290
+ try {
1291
+ spawn(cmd, [url], { stdio: "ignore", detached: true }).unref();
1292
+ } catch {
1293
+ }
1294
+ }
1295
+ async function deviceLogin() {
1296
+ const apiUrl = loadConfig().apiUrl.replace(/\/$/, "");
1297
+ client.setConfig({ baseUrl: `${apiUrl}/api/v1` });
1298
+ const start = unwrap(await postAuthDeviceCode({}));
1299
+ console.log(
1300
+ `
1301
+ Open ${chalk2.cyan(start.verification_uri)} and enter the code:
1302
+
1303
+ ${chalk2.bold(start.user_code)}
1304
+
1305
+ ${chalk2.dim("Opening your browser\u2026 (Ctrl+C to cancel)")}
1306
+ `
1307
+ );
1308
+ openBrowser(start.verification_uri_complete);
1309
+ const deadline = Date.now() + start.expires_in * 1e3;
1310
+ let interval = start.interval;
1311
+ while (Date.now() < deadline) {
1312
+ await sleep(interval * 1e3);
1313
+ const res = await postAuthDeviceToken({
1314
+ body: {
1315
+ device_code: start.device_code,
1316
+ grant_type: "urn:ietf:params:oauth:grant-type:device_code"
1317
+ }
1318
+ });
1319
+ if (res.data) {
1320
+ const { access_token, workspaces } = res.data;
1321
+ const active = workspaces[0];
1322
+ if (workspaces.length > 1 && active) {
1323
+ console.log(
1324
+ `
1325
+ ${chalk2.dim("Workspaces:")} ${workspaces.map((w) => w.slug).join(", ")} ${chalk2.dim(`(using ${active.slug}; switch with --workspace)`)}`
1326
+ );
1327
+ }
1328
+ return { apiKey: access_token, workspaceId: active?.id };
1329
+ }
1330
+ switch (res.error?.error) {
1331
+ case "authorization_pending":
1332
+ break;
1333
+ // keep polling at the same cadence
1334
+ case "slow_down":
1335
+ interval += 5;
1336
+ break;
1337
+ case "access_denied":
1338
+ fail("Login was denied in the browser.");
1339
+ break;
1340
+ case "expired_token":
1341
+ fail("The code expired before approval. Run `ft login` again.");
1342
+ break;
1343
+ default:
1344
+ fail(`Device login failed: ${res.error?.error ?? "unknown error"}.`);
1345
+ }
1346
+ }
1347
+ return fail("The code expired before approval. Run `ft login` again.");
1348
+ }
1349
+
1350
+ // src/commands/event-dates.ts
1351
+ function registerEventDates(program2, spec) {
1352
+ const root = program2.command("event-dates").description("Event dates (sessions of an event)");
1353
+ root.command("list <eventId>").description("List dates of an event").option("--workspace <id>", "workspace override").option("--json", "raw JSON output").action(async (eventId, opts) => {
1354
+ configureClient(opts.workspace);
1355
+ const body = unwrap(await spec.list({ path: { id: eventId } }));
1356
+ print(body.data ?? body, {
1357
+ json: opts.json,
1358
+ columns: ["id", "startsAt", "endsAt", "status"]
1359
+ });
1360
+ });
1361
+ root.command("create <eventId>").description("Add a date to an event").requiredOption("--data <json>", "JSON body (inline or @file.json)").option("--workspace <id>", "workspace override").option("--json", "raw JSON output").action(async (eventId, opts) => {
1362
+ configureClient(opts.workspace);
1363
+ const body = unwrap(
1364
+ await spec.create({
1365
+ path: { id: eventId },
1366
+ body: parseData(opts.data)
1367
+ })
1368
+ );
1369
+ print(body.data ?? body, { json: opts.json });
1370
+ });
1371
+ root.command("update <eventId> <dateId>").description("Update an event date").requiredOption("--data <json>", "JSON body (inline or @file.json)").option("--workspace <id>", "workspace override").option("--json", "raw JSON output").action(async (eventId, dateId, opts) => {
1372
+ configureClient(opts.workspace);
1373
+ const body = unwrap(
1374
+ await spec.update({
1375
+ path: { id: eventId, dateId },
1376
+ body: parseData(opts.data)
1377
+ })
1378
+ );
1379
+ print(body.data ?? body, { json: opts.json });
1380
+ });
1381
+ root.command("delete <eventId> <dateId>").description("Delete an event date").option("--yes", "skip confirmation").option("--workspace <id>", "workspace override").option("--json", "raw JSON output").action(async (eventId, dateId, opts) => {
1382
+ if (!opts.yes && !await confirm(`Delete date ${dateId}?`)) {
1383
+ console.error("Aborted.");
1384
+ return;
1385
+ }
1386
+ configureClient(opts.workspace);
1387
+ const body = unwrap(await spec.del({ path: { id: eventId, dateId } }));
1388
+ print(body?.data ?? { deleted: dateId }, { json: opts.json });
1389
+ });
1390
+ }
418
1391
 
419
1392
  // src/commands/reports.ts
420
1393
  function registerReports(program2) {
@@ -426,7 +1399,40 @@ function registerReports(program2) {
426
1399
  );
427
1400
  print(body.data, { json: opts.json });
428
1401
  });
429
- const exp = root.command("export").description("Export buyers or subscribers (CSV)");
1402
+ root.command("reconciliation").description("CFO reconciliation: Mercado Pago vs sale vs Siigo invoice").requiredOption("--from <date>", "date_from (ISO 8601)").requiredOption("--to <date>", "date_to (ISO 8601)").option(
1403
+ "--match <status>",
1404
+ "OK | MISSING_INVOICE | MISSING_CUFE | AMOUNT_MISMATCH | MISSING_PAYMENT"
1405
+ ).option("--provider <p>", "filter by payment provider").option("--page <n>", "page number").option("--page-size <n>", "rows per page").option("--workspace <id>", "workspace override").option("--json", "raw JSON output").action(async (opts) => {
1406
+ configureClient(opts.workspace);
1407
+ const body = unwrap(
1408
+ await getReportsReconciliation({
1409
+ query: {
1410
+ date_from: opts.from,
1411
+ date_to: opts.to,
1412
+ match_status: opts.match,
1413
+ provider: opts.provider,
1414
+ page: opts.page,
1415
+ page_size: opts.pageSize
1416
+ }
1417
+ })
1418
+ );
1419
+ print(body.data, { json: opts.json });
1420
+ });
1421
+ const exp = root.command("export").description("Export buyers, subscribers or reconciliation (CSV)");
1422
+ exp.command("reconciliation").description("Export reconciliation (CSV) for accounting").requiredOption("--from <date>", "date_from (ISO 8601)").requiredOption("--to <date>", "date_to (ISO 8601)").option("--match <status>", "filter by match_status").option("--provider <p>", "filter by payment provider").option("--workspace <id>", "workspace override").option("--json", "raw JSON output").action(async (opts) => {
1423
+ configureClient(opts.workspace);
1424
+ const body = unwrap(
1425
+ await getReportsExportsReconciliation({
1426
+ query: {
1427
+ date_from: opts.from,
1428
+ date_to: opts.to,
1429
+ match_status: opts.match,
1430
+ provider: opts.provider
1431
+ }
1432
+ })
1433
+ );
1434
+ print(body.data ?? body, { json: opts.json });
1435
+ });
430
1436
  for (const [name, fn, label] of [
431
1437
  ["buyers", getReportsExportsBuyers, "buyers"],
432
1438
  ["subscribers", getReportsExportsSubscribers, "subscribers"]
@@ -442,9 +1448,10 @@ function registerReports(program2) {
442
1448
  // src/commands/resource.ts
443
1449
  function registerResource(program2, spec) {
444
1450
  const root = program2.command(spec.name).description(spec.describe);
1451
+ const singular = spec.name.replace(/s$/, "");
445
1452
  if (spec.list) {
446
1453
  const list = spec.list;
447
- const cmd = root.command("list").description(`List ${spec.name} from the active workspace`).option("--limit <n>", "results per page (1-100)", "20").option("--cursor <id>", "pagination cursor").option("--workspace <id>", "workspace override").option("--json", "raw JSON output");
1454
+ const cmd = root.command("list").description(`List ${spec.name} from the active workspace`).option("--limit <n>", "results per page (1-100)", "20").option("--cursor <id>", "pagination cursor").option("--workspace <id>", "workspace override").option("--csv", "CSV output (for spreadsheets/accounting)").option("--json", "raw JSON output");
448
1455
  for (const f of spec.listFlags ?? []) cmd.option(f.flag, f.describe);
449
1456
  cmd.action(async (opts) => {
450
1457
  configureClient(opts.workspace);
@@ -453,24 +1460,72 @@ function registerResource(program2, spec) {
453
1460
  cursor: opts.cursor
454
1461
  };
455
1462
  for (const f of spec.listFlags ?? []) {
456
- const v = opts[camel(f.query)];
1463
+ const v = opts[camel2(f.query)];
457
1464
  if (v !== void 0) query[f.query] = v;
458
1465
  }
459
1466
  const body = unwrap(await list({ query }));
1467
+ if (opts.csv) {
1468
+ process.stdout.write(`${toCsv(body.data, spec.columns)}
1469
+ `);
1470
+ return;
1471
+ }
460
1472
  print(body.data, { json: opts.json, columns: spec.columns });
461
1473
  if (!opts.json) printNextCursor(body.page);
462
1474
  });
463
1475
  }
464
1476
  if (spec.get) {
465
1477
  const get = spec.get;
466
- root.command("get <id>").description(`Get one ${spec.name.replace(/s$/, "")} by id`).option("--workspace <id>", "workspace override").option("--json", "raw JSON output").action(async (id, opts) => {
1478
+ root.command("get <id>").description(`Get one ${singular} by id`).option("--workspace <id>", "workspace override").option("--json", "raw JSON output").action(async (id, opts) => {
467
1479
  configureClient(opts.workspace);
468
1480
  const body = unwrap(await get({ path: { id } }));
469
1481
  print(body.data, { json: opts.json });
470
1482
  });
471
1483
  }
1484
+ if (spec.create) {
1485
+ const create = spec.create;
1486
+ root.command("create").description(`Create a ${singular}`).requiredOption("--data <json>", "JSON body (inline or @file.json)").option("--workspace <id>", "workspace override").option("--json", "raw JSON output").action(async (opts) => {
1487
+ configureClient(opts.workspace);
1488
+ const body = unwrap(await create({ body: parseData(opts.data) }));
1489
+ print(body.data ?? body, { json: opts.json });
1490
+ });
1491
+ }
1492
+ if (spec.update) {
1493
+ const update = spec.update;
1494
+ root.command("update <id>").description(`Update a ${singular} by id`).requiredOption("--data <json>", "JSON body (inline or @file.json)").option("--workspace <id>", "workspace override").option("--json", "raw JSON output").action(async (id, opts) => {
1495
+ configureClient(opts.workspace);
1496
+ const body = unwrap(
1497
+ await update({ path: { id }, body: parseData(opts.data) })
1498
+ );
1499
+ print(body.data ?? body, { json: opts.json });
1500
+ });
1501
+ }
1502
+ if (spec.del) {
1503
+ const del = spec.del;
1504
+ root.command("delete <id>").description(`Delete a ${singular} by id`).option("--yes", "skip confirmation").option("--workspace <id>", "workspace override").option("--json", "raw JSON output").action(async (id, opts) => {
1505
+ if (!opts.yes && !await confirm(`Delete ${singular} ${id}?`)) {
1506
+ console.error("Aborted.");
1507
+ return;
1508
+ }
1509
+ configureClient(opts.workspace);
1510
+ const body = unwrap(await del({ path: { id } }));
1511
+ print(body?.data ?? { deleted: id }, { json: opts.json });
1512
+ });
1513
+ }
1514
+ for (const action of spec.actions ?? []) {
1515
+ const cmd = root.command(`${action.name} <id>`).description(action.describe).option("--workspace <id>", "workspace override").option("--json", "raw JSON output");
1516
+ if (action.body) {
1517
+ cmd.option("--data <json>", "JSON body (inline or @file.json)");
1518
+ }
1519
+ cmd.action(async (id, opts) => {
1520
+ configureClient(opts.workspace);
1521
+ const payload = { path: { id } };
1522
+ if (action.body && opts.data) payload.body = parseData(opts.data);
1523
+ const body = unwrap(await action.fn(payload));
1524
+ print(body?.data ?? body ?? { ok: true, id }, { json: opts.json });
1525
+ });
1526
+ }
472
1527
  }
473
- function camel(s) {
1528
+ function camel2(s) {
474
1529
  return s.replace(/-([a-z])/g, (_, c2) => c2.toUpperCase());
475
1530
  }
476
1531
 
@@ -501,13 +1556,34 @@ registerResource(program, {
501
1556
  describe: "Events",
502
1557
  list: getEvents,
503
1558
  get: getEventsId,
1559
+ create: postEvents,
1560
+ update: patchEventsId,
1561
+ del: deleteEventsId,
1562
+ actions: [
1563
+ { name: "publish", describe: "Publish an event", fn: postEventsIdPublish }
1564
+ ],
504
1565
  columns: ["id", "name", "status", "startsAt"]
505
1566
  });
1567
+ registerEventDates(program, {
1568
+ list: getEventsIdDates,
1569
+ create: postEventsIdDates,
1570
+ update: patchEventsIdDatesDateId,
1571
+ del: deleteEventsIdDatesDateId
1572
+ });
506
1573
  registerResource(program, {
507
1574
  name: "sales",
508
1575
  describe: "Sales",
509
1576
  list: getSales,
510
1577
  get: getSalesId,
1578
+ actions: [
1579
+ { name: "cancel", describe: "Cancel a sale", fn: postSalesIdCancel },
1580
+ {
1581
+ name: "refund",
1582
+ describe: "Refund a sale (--data for partial amount)",
1583
+ fn: postSalesIdRefund,
1584
+ body: true
1585
+ }
1586
+ ],
511
1587
  columns: ["id", "reference", "status", "total", "currency", "createdAt"],
512
1588
  listFlags: [
513
1589
  { flag: "--status <s>", describe: "filter by status", query: "status" }
@@ -518,6 +1594,9 @@ registerResource(program, {
518
1594
  describe: "Ticket types",
519
1595
  list: getTicketTypes,
520
1596
  get: getTicketTypesId,
1597
+ create: postTicketTypes,
1598
+ update: patchTicketTypesId,
1599
+ del: deleteTicketTypesId,
521
1600
  columns: ["id", "name", "price", "currency", "stock"],
522
1601
  listFlags: [
523
1602
  {
@@ -532,6 +1611,9 @@ registerResource(program, {
532
1611
  describe: "Membership plans",
533
1612
  list: getMembershipPlans,
534
1613
  get: getMembershipPlansId,
1614
+ create: postMembershipPlans,
1615
+ update: patchMembershipPlansId,
1616
+ del: deleteMembershipPlansId,
535
1617
  columns: ["id", "name", "price", "currency", "interval"]
536
1618
  });
537
1619
  registerResource(program, {
@@ -539,15 +1621,28 @@ registerResource(program, {
539
1621
  describe: "Venues",
540
1622
  list: getVenues,
541
1623
  get: getVenuesId,
1624
+ create: postVenues,
1625
+ update: patchVenuesId,
1626
+ del: deleteVenuesId,
542
1627
  columns: ["id", "name", "city"]
543
1628
  });
544
1629
  registerResource(program, {
545
1630
  name: "staff",
546
1631
  describe: "Workspace staff",
547
1632
  list: getStaff,
1633
+ create: postStaff,
1634
+ actions: [
1635
+ {
1636
+ name: "set-role",
1637
+ describe: `Change a staff member's role (--data '{"role":"..."}')`,
1638
+ fn: patchStaffIdRole,
1639
+ body: true
1640
+ }
1641
+ ],
548
1642
  columns: ["id", "name", "email", "role"]
549
1643
  });
550
1644
  registerReports(program);
1645
+ registerAdmin(program);
551
1646
  if (process.argv.length <= 2) {
552
1647
  console.log(banner());
553
1648
  program.outputHelp();