@l4yercak3/cli 1.2.16 → 1.2.18

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.
@@ -0,0 +1,1047 @@
1
+ /**
2
+ * React Hooks Generator
3
+ * Generates React Query hooks for L4YERCAK3 data fetching
4
+ */
5
+
6
+ const fs = require('fs');
7
+ const path = require('path');
8
+ const { ensureDir, writeFileWithBackup, checkFileOverwrite } = require('../../../utils/file-utils');
9
+
10
+ class HooksGenerator {
11
+ /**
12
+ * Generate React hooks based on selected features
13
+ * @param {Object} options - Generation options
14
+ * @returns {Promise<Object>} - Generated file paths
15
+ */
16
+ async generate(options) {
17
+ const { projectPath, features = [] } = options;
18
+
19
+ const results = {};
20
+
21
+ // Determine output directory
22
+ let outputDir;
23
+ if (fs.existsSync(path.join(projectPath, 'src'))) {
24
+ outputDir = path.join(projectPath, 'src', 'lib', 'l4yercak3', 'hooks');
25
+ } else {
26
+ outputDir = path.join(projectPath, 'lib', 'l4yercak3', 'hooks');
27
+ }
28
+
29
+ ensureDir(outputDir);
30
+
31
+ // Generate hooks based on features
32
+ if (features.includes('crm')) {
33
+ results.contacts = await this.generateContactsHook(outputDir, options);
34
+ results.organizations = await this.generateOrganizationsHook(outputDir, options);
35
+ }
36
+
37
+ if (features.includes('events')) {
38
+ results.events = await this.generateEventsHook(outputDir, options);
39
+ }
40
+
41
+ if (features.includes('forms')) {
42
+ results.forms = await this.generateFormsHook(outputDir, options);
43
+ }
44
+
45
+ if (features.includes('products') || features.includes('checkout')) {
46
+ results.products = await this.generateProductsHook(outputDir, options);
47
+ }
48
+
49
+ if (features.includes('invoicing')) {
50
+ results.invoices = await this.generateInvoicesHook(outputDir, options);
51
+ }
52
+
53
+ // Generate index file
54
+ results.index = await this.generateIndex(outputDir, options, Object.keys(results));
55
+
56
+ return results;
57
+ }
58
+
59
+ async generateContactsHook(outputDir, options) {
60
+ const { isTypeScript, selectedDatabase } = options;
61
+ const extension = isTypeScript ? 'ts' : 'js';
62
+ const outputPath = path.join(outputDir, `use-contacts.${extension}`);
63
+
64
+ const action = await checkFileOverwrite(outputPath);
65
+ if (action === 'skip') {
66
+ return null;
67
+ }
68
+
69
+ const content = isTypeScript
70
+ ? this.generateContactsHookTS(selectedDatabase)
71
+ : this.generateContactsHookJS(selectedDatabase);
72
+
73
+ return writeFileWithBackup(outputPath, content, action);
74
+ }
75
+
76
+ generateContactsHookTS(database) {
77
+ const isConvex = database === 'convex';
78
+
79
+ return `/**
80
+ * Contacts Hooks
81
+ * Auto-generated by @l4yercak3/cli
82
+ */
83
+
84
+ ${isConvex ? `import { useQuery, useMutation } from "convex/react";
85
+ import { api } from "@/convex/_generated/api";
86
+ import type { Id } from "@/convex/_generated/dataModel";` : `import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
87
+ import { getL4yercak3Client } from '../client';
88
+ import type { Contact, ContactCreateInput, ContactUpdateInput } from '../types';`}
89
+
90
+ ${isConvex ? `
91
+ // ============ Convex Hooks ============
92
+
93
+ export function useContacts(options?: { status?: string; subtype?: string; limit?: number }) {
94
+ return useQuery(api.objects.list, {
95
+ type: "contact",
96
+ status: options?.status,
97
+ subtype: options?.subtype,
98
+ limit: options?.limit,
99
+ });
100
+ }
101
+
102
+ export function useContact(id: Id<"objects"> | undefined) {
103
+ return useQuery(api.objects.get, id ? { id } : "skip");
104
+ }
105
+
106
+ export function useCreateContact() {
107
+ return useMutation(api.objects.create);
108
+ }
109
+
110
+ export function useUpdateContact() {
111
+ return useMutation(api.objects.update);
112
+ }
113
+
114
+ export function useDeleteContact() {
115
+ return useMutation(api.objects.remove);
116
+ }
117
+
118
+ export function useSearchContacts(searchTerm: string) {
119
+ return useQuery(
120
+ api.objects.search,
121
+ searchTerm ? { type: "contact", searchTerm } : "skip"
122
+ );
123
+ }
124
+ ` : `
125
+ // ============ React Query Hooks ============
126
+
127
+ const client = getL4yercak3Client();
128
+
129
+ export function useContacts(options?: {
130
+ status?: 'active' | 'inactive' | 'archived';
131
+ subtype?: 'customer' | 'lead' | 'prospect' | 'partner';
132
+ search?: string;
133
+ limit?: number;
134
+ }) {
135
+ return useQuery({
136
+ queryKey: ['contacts', options],
137
+ queryFn: () => client.listContacts(options),
138
+ });
139
+ }
140
+
141
+ export function useContact(id: string | undefined, options?: {
142
+ includeActivities?: boolean;
143
+ includeNotes?: boolean;
144
+ }) {
145
+ return useQuery({
146
+ queryKey: ['contact', id, options],
147
+ queryFn: () => client.getContact(id!, options),
148
+ enabled: !!id,
149
+ });
150
+ }
151
+
152
+ export function useCreateContact() {
153
+ const queryClient = useQueryClient();
154
+
155
+ return useMutation({
156
+ mutationFn: (data: ContactCreateInput) => client.createContact(data),
157
+ onSuccess: () => {
158
+ queryClient.invalidateQueries({ queryKey: ['contacts'] });
159
+ },
160
+ });
161
+ }
162
+
163
+ export function useUpdateContact() {
164
+ const queryClient = useQueryClient();
165
+
166
+ return useMutation({
167
+ mutationFn: ({ id, data }: { id: string; data: ContactUpdateInput }) =>
168
+ client.updateContact(id, data),
169
+ onSuccess: (_, variables) => {
170
+ queryClient.invalidateQueries({ queryKey: ['contacts'] });
171
+ queryClient.invalidateQueries({ queryKey: ['contact', variables.id] });
172
+ },
173
+ });
174
+ }
175
+
176
+ export function useDeleteContact() {
177
+ const queryClient = useQueryClient();
178
+
179
+ return useMutation({
180
+ mutationFn: (id: string) => client.deleteContact(id),
181
+ onSuccess: () => {
182
+ queryClient.invalidateQueries({ queryKey: ['contacts'] });
183
+ },
184
+ });
185
+ }
186
+
187
+ export function useAddTagsToContact() {
188
+ const queryClient = useQueryClient();
189
+
190
+ return useMutation({
191
+ mutationFn: ({ id, tags }: { id: string; tags: string[] }) =>
192
+ client.addTagsToContact(id, tags),
193
+ onSuccess: (_, variables) => {
194
+ queryClient.invalidateQueries({ queryKey: ['contact', variables.id] });
195
+ },
196
+ });
197
+ }
198
+ `}`;
199
+ }
200
+
201
+ generateContactsHookJS(database) {
202
+ const isConvex = database === 'convex';
203
+
204
+ return `/**
205
+ * Contacts Hooks
206
+ * Auto-generated by @l4yercak3/cli
207
+ */
208
+
209
+ ${isConvex ? `const { useQuery, useMutation } = require("convex/react");
210
+ const { api } = require("@/convex/_generated/api");` : `const { useQuery, useMutation, useQueryClient } = require('@tanstack/react-query');
211
+ const { getL4yercak3Client } = require('../client');`}
212
+
213
+ ${isConvex ? `
214
+ // ============ Convex Hooks ============
215
+
216
+ function useContacts(options = {}) {
217
+ return useQuery(api.objects.list, {
218
+ type: "contact",
219
+ status: options.status,
220
+ subtype: options.subtype,
221
+ limit: options.limit,
222
+ });
223
+ }
224
+
225
+ function useContact(id) {
226
+ return useQuery(api.objects.get, id ? { id } : "skip");
227
+ }
228
+
229
+ function useCreateContact() {
230
+ return useMutation(api.objects.create);
231
+ }
232
+
233
+ function useUpdateContact() {
234
+ return useMutation(api.objects.update);
235
+ }
236
+
237
+ function useDeleteContact() {
238
+ return useMutation(api.objects.remove);
239
+ }
240
+
241
+ function useSearchContacts(searchTerm) {
242
+ return useQuery(
243
+ api.objects.search,
244
+ searchTerm ? { type: "contact", searchTerm } : "skip"
245
+ );
246
+ }
247
+
248
+ module.exports = {
249
+ useContacts,
250
+ useContact,
251
+ useCreateContact,
252
+ useUpdateContact,
253
+ useDeleteContact,
254
+ useSearchContacts,
255
+ };
256
+ ` : `
257
+ // ============ React Query Hooks ============
258
+
259
+ const client = getL4yercak3Client();
260
+
261
+ function useContacts(options = {}) {
262
+ return useQuery({
263
+ queryKey: ['contacts', options],
264
+ queryFn: () => client.listContacts(options),
265
+ });
266
+ }
267
+
268
+ function useContact(id, options = {}) {
269
+ return useQuery({
270
+ queryKey: ['contact', id, options],
271
+ queryFn: () => client.getContact(id, options),
272
+ enabled: !!id,
273
+ });
274
+ }
275
+
276
+ function useCreateContact() {
277
+ const queryClient = useQueryClient();
278
+
279
+ return useMutation({
280
+ mutationFn: (data) => client.createContact(data),
281
+ onSuccess: () => {
282
+ queryClient.invalidateQueries({ queryKey: ['contacts'] });
283
+ },
284
+ });
285
+ }
286
+
287
+ function useUpdateContact() {
288
+ const queryClient = useQueryClient();
289
+
290
+ return useMutation({
291
+ mutationFn: ({ id, data }) => client.updateContact(id, data),
292
+ onSuccess: (_, variables) => {
293
+ queryClient.invalidateQueries({ queryKey: ['contacts'] });
294
+ queryClient.invalidateQueries({ queryKey: ['contact', variables.id] });
295
+ },
296
+ });
297
+ }
298
+
299
+ function useDeleteContact() {
300
+ const queryClient = useQueryClient();
301
+
302
+ return useMutation({
303
+ mutationFn: (id) => client.deleteContact(id),
304
+ onSuccess: () => {
305
+ queryClient.invalidateQueries({ queryKey: ['contacts'] });
306
+ },
307
+ });
308
+ }
309
+
310
+ module.exports = {
311
+ useContacts,
312
+ useContact,
313
+ useCreateContact,
314
+ useUpdateContact,
315
+ useDeleteContact,
316
+ };
317
+ `}`;
318
+ }
319
+
320
+ async generateOrganizationsHook(outputDir, options) {
321
+ const { isTypeScript } = options;
322
+ const extension = isTypeScript ? 'ts' : 'js';
323
+ const outputPath = path.join(outputDir, `use-organizations.${extension}`);
324
+
325
+ const action = await checkFileOverwrite(outputPath);
326
+ if (action === 'skip') {
327
+ return null;
328
+ }
329
+
330
+ const content = isTypeScript
331
+ ? `/**
332
+ * Organizations Hooks
333
+ * Auto-generated by @l4yercak3/cli
334
+ */
335
+
336
+ import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
337
+ import { getL4yercak3Client } from '../client';
338
+ import type { Organization, OrganizationCreateInput } from '../types';
339
+
340
+ const client = getL4yercak3Client();
341
+
342
+ export function useOrganizations(options?: {
343
+ subtype?: 'customer' | 'prospect' | 'partner' | 'vendor';
344
+ search?: string;
345
+ limit?: number;
346
+ }) {
347
+ return useQuery({
348
+ queryKey: ['organizations', options],
349
+ queryFn: () => client.listOrganizations(options),
350
+ });
351
+ }
352
+
353
+ export function useOrganization(id: string | undefined, options?: {
354
+ includeContacts?: boolean;
355
+ }) {
356
+ return useQuery({
357
+ queryKey: ['organization', id, options],
358
+ queryFn: () => client.getOrganization(id!, options),
359
+ enabled: !!id,
360
+ });
361
+ }
362
+
363
+ export function useCreateOrganization() {
364
+ const queryClient = useQueryClient();
365
+
366
+ return useMutation({
367
+ mutationFn: (data: OrganizationCreateInput) => client.createOrganization(data),
368
+ onSuccess: () => {
369
+ queryClient.invalidateQueries({ queryKey: ['organizations'] });
370
+ },
371
+ });
372
+ }
373
+ `
374
+ : `/**
375
+ * Organizations Hooks
376
+ * Auto-generated by @l4yercak3/cli
377
+ */
378
+
379
+ const { useQuery, useMutation, useQueryClient } = require('@tanstack/react-query');
380
+ const { getL4yercak3Client } = require('../client');
381
+
382
+ const client = getL4yercak3Client();
383
+
384
+ function useOrganizations(options = {}) {
385
+ return useQuery({
386
+ queryKey: ['organizations', options],
387
+ queryFn: () => client.listOrganizations(options),
388
+ });
389
+ }
390
+
391
+ function useOrganization(id, options = {}) {
392
+ return useQuery({
393
+ queryKey: ['organization', id, options],
394
+ queryFn: () => client.getOrganization(id, options),
395
+ enabled: !!id,
396
+ });
397
+ }
398
+
399
+ function useCreateOrganization() {
400
+ const queryClient = useQueryClient();
401
+
402
+ return useMutation({
403
+ mutationFn: (data) => client.createOrganization(data),
404
+ onSuccess: () => {
405
+ queryClient.invalidateQueries({ queryKey: ['organizations'] });
406
+ },
407
+ });
408
+ }
409
+
410
+ module.exports = {
411
+ useOrganizations,
412
+ useOrganization,
413
+ useCreateOrganization,
414
+ };
415
+ `;
416
+
417
+ return writeFileWithBackup(outputPath, content, action);
418
+ }
419
+
420
+ async generateEventsHook(outputDir, options) {
421
+ const { isTypeScript } = options;
422
+ const extension = isTypeScript ? 'ts' : 'js';
423
+ const outputPath = path.join(outputDir, `use-events.${extension}`);
424
+
425
+ const action = await checkFileOverwrite(outputPath);
426
+ if (action === 'skip') {
427
+ return null;
428
+ }
429
+
430
+ const content = isTypeScript
431
+ ? `/**
432
+ * Events Hooks
433
+ * Auto-generated by @l4yercak3/cli
434
+ */
435
+
436
+ import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
437
+ import { getL4yercak3Client } from '../client';
438
+ import type { Event, EventCreateInput, Attendee } from '../types';
439
+
440
+ const client = getL4yercak3Client();
441
+
442
+ export function useEvents(options?: {
443
+ status?: 'draft' | 'published' | 'cancelled' | 'completed';
444
+ fromDate?: string;
445
+ toDate?: string;
446
+ limit?: number;
447
+ }) {
448
+ return useQuery({
449
+ queryKey: ['events', options],
450
+ queryFn: () => client.listEvents(options),
451
+ });
452
+ }
453
+
454
+ export function useEvent(id: string | undefined, options?: {
455
+ includeProducts?: boolean;
456
+ includeSponsors?: boolean;
457
+ includeForms?: boolean;
458
+ }) {
459
+ return useQuery({
460
+ queryKey: ['event', id, options],
461
+ queryFn: () => client.getEvent(id!, options),
462
+ enabled: !!id,
463
+ });
464
+ }
465
+
466
+ export function useEventAttendees(eventId: string | undefined, options?: {
467
+ status?: 'registered' | 'checked_in' | 'cancelled' | 'no_show';
468
+ limit?: number;
469
+ }) {
470
+ return useQuery({
471
+ queryKey: ['eventAttendees', eventId, options],
472
+ queryFn: () => client.getEventAttendees(eventId!, options),
473
+ enabled: !!eventId,
474
+ });
475
+ }
476
+
477
+ export function useCreateEvent() {
478
+ const queryClient = useQueryClient();
479
+
480
+ return useMutation({
481
+ mutationFn: (data: EventCreateInput) => client.createEvent(data),
482
+ onSuccess: () => {
483
+ queryClient.invalidateQueries({ queryKey: ['events'] });
484
+ },
485
+ });
486
+ }
487
+
488
+ export function useCheckInAttendee() {
489
+ const queryClient = useQueryClient();
490
+
491
+ return useMutation({
492
+ mutationFn: ({ eventId, attendeeId }: { eventId: string; attendeeId: string }) =>
493
+ client.checkInAttendee(eventId, attendeeId),
494
+ onSuccess: (_, variables) => {
495
+ queryClient.invalidateQueries({ queryKey: ['eventAttendees', variables.eventId] });
496
+ },
497
+ });
498
+ }
499
+ `
500
+ : `/**
501
+ * Events Hooks
502
+ * Auto-generated by @l4yercak3/cli
503
+ */
504
+
505
+ const { useQuery, useMutation, useQueryClient } = require('@tanstack/react-query');
506
+ const { getL4yercak3Client } = require('../client');
507
+
508
+ const client = getL4yercak3Client();
509
+
510
+ function useEvents(options = {}) {
511
+ return useQuery({
512
+ queryKey: ['events', options],
513
+ queryFn: () => client.listEvents(options),
514
+ });
515
+ }
516
+
517
+ function useEvent(id, options = {}) {
518
+ return useQuery({
519
+ queryKey: ['event', id, options],
520
+ queryFn: () => client.getEvent(id, options),
521
+ enabled: !!id,
522
+ });
523
+ }
524
+
525
+ function useEventAttendees(eventId, options = {}) {
526
+ return useQuery({
527
+ queryKey: ['eventAttendees', eventId, options],
528
+ queryFn: () => client.getEventAttendees(eventId, options),
529
+ enabled: !!eventId,
530
+ });
531
+ }
532
+
533
+ function useCreateEvent() {
534
+ const queryClient = useQueryClient();
535
+
536
+ return useMutation({
537
+ mutationFn: (data) => client.createEvent(data),
538
+ onSuccess: () => {
539
+ queryClient.invalidateQueries({ queryKey: ['events'] });
540
+ },
541
+ });
542
+ }
543
+
544
+ function useCheckInAttendee() {
545
+ const queryClient = useQueryClient();
546
+
547
+ return useMutation({
548
+ mutationFn: ({ eventId, attendeeId }) => client.checkInAttendee(eventId, attendeeId),
549
+ onSuccess: (_, variables) => {
550
+ queryClient.invalidateQueries({ queryKey: ['eventAttendees', variables.eventId] });
551
+ },
552
+ });
553
+ }
554
+
555
+ module.exports = {
556
+ useEvents,
557
+ useEvent,
558
+ useEventAttendees,
559
+ useCreateEvent,
560
+ useCheckInAttendee,
561
+ };
562
+ `;
563
+
564
+ return writeFileWithBackup(outputPath, content, action);
565
+ }
566
+
567
+ async generateFormsHook(outputDir, options) {
568
+ const { isTypeScript } = options;
569
+ const extension = isTypeScript ? 'ts' : 'js';
570
+ const outputPath = path.join(outputDir, `use-forms.${extension}`);
571
+
572
+ const action = await checkFileOverwrite(outputPath);
573
+ if (action === 'skip') {
574
+ return null;
575
+ }
576
+
577
+ const content = isTypeScript
578
+ ? `/**
579
+ * Forms Hooks
580
+ * Auto-generated by @l4yercak3/cli
581
+ */
582
+
583
+ import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
584
+ import { getL4yercak3Client } from '../client';
585
+ import type { Form, FormSubmission } from '../types';
586
+
587
+ const client = getL4yercak3Client();
588
+
589
+ export function useForms(options?: {
590
+ status?: 'draft' | 'published' | 'closed';
591
+ eventId?: string;
592
+ subtype?: 'registration' | 'survey' | 'application' | 'feedback' | 'contact';
593
+ limit?: number;
594
+ }) {
595
+ return useQuery({
596
+ queryKey: ['forms', options],
597
+ queryFn: () => client.listForms(options),
598
+ });
599
+ }
600
+
601
+ export function useForm(id: string | undefined) {
602
+ return useQuery({
603
+ queryKey: ['form', id],
604
+ queryFn: () => client.getForm(id!),
605
+ enabled: !!id,
606
+ });
607
+ }
608
+
609
+ export function useFormResponses(formId: string | undefined, options?: {
610
+ status?: 'submitted' | 'reviewed' | 'approved' | 'rejected';
611
+ limit?: number;
612
+ }) {
613
+ return useQuery({
614
+ queryKey: ['formResponses', formId, options],
615
+ queryFn: () => client.getFormResponses(formId!, options),
616
+ enabled: !!formId,
617
+ });
618
+ }
619
+
620
+ export function useSubmitForm() {
621
+ const queryClient = useQueryClient();
622
+
623
+ return useMutation({
624
+ mutationFn: ({ formId, data }: { formId: string; data: Record<string, unknown> }) =>
625
+ client.submitForm(formId, data),
626
+ onSuccess: (_, variables) => {
627
+ queryClient.invalidateQueries({ queryKey: ['formResponses', variables.formId] });
628
+ },
629
+ });
630
+ }
631
+ `
632
+ : `/**
633
+ * Forms Hooks
634
+ * Auto-generated by @l4yercak3/cli
635
+ */
636
+
637
+ const { useQuery, useMutation, useQueryClient } = require('@tanstack/react-query');
638
+ const { getL4yercak3Client } = require('../client');
639
+
640
+ const client = getL4yercak3Client();
641
+
642
+ function useForms(options = {}) {
643
+ return useQuery({
644
+ queryKey: ['forms', options],
645
+ queryFn: () => client.listForms(options),
646
+ });
647
+ }
648
+
649
+ function useForm(id) {
650
+ return useQuery({
651
+ queryKey: ['form', id],
652
+ queryFn: () => client.getForm(id),
653
+ enabled: !!id,
654
+ });
655
+ }
656
+
657
+ function useFormResponses(formId, options = {}) {
658
+ return useQuery({
659
+ queryKey: ['formResponses', formId, options],
660
+ queryFn: () => client.getFormResponses(formId, options),
661
+ enabled: !!formId,
662
+ });
663
+ }
664
+
665
+ function useSubmitForm() {
666
+ const queryClient = useQueryClient();
667
+
668
+ return useMutation({
669
+ mutationFn: ({ formId, data }) => client.submitForm(formId, data),
670
+ onSuccess: (_, variables) => {
671
+ queryClient.invalidateQueries({ queryKey: ['formResponses', variables.formId] });
672
+ },
673
+ });
674
+ }
675
+
676
+ module.exports = {
677
+ useForms,
678
+ useForm,
679
+ useFormResponses,
680
+ useSubmitForm,
681
+ };
682
+ `;
683
+
684
+ return writeFileWithBackup(outputPath, content, action);
685
+ }
686
+
687
+ async generateProductsHook(outputDir, options) {
688
+ const { isTypeScript } = options;
689
+ const extension = isTypeScript ? 'ts' : 'js';
690
+ const outputPath = path.join(outputDir, `use-products.${extension}`);
691
+
692
+ const action = await checkFileOverwrite(outputPath);
693
+ if (action === 'skip') {
694
+ return null;
695
+ }
696
+
697
+ const content = isTypeScript
698
+ ? `/**
699
+ * Products & Checkout Hooks
700
+ * Auto-generated by @l4yercak3/cli
701
+ */
702
+
703
+ import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
704
+ import { getL4yercak3Client } from '../client';
705
+ import type { Product, Order } from '../types';
706
+
707
+ const client = getL4yercak3Client();
708
+
709
+ export function useProducts(options?: {
710
+ eventId?: string;
711
+ status?: 'active' | 'sold_out' | 'hidden';
712
+ category?: string;
713
+ limit?: number;
714
+ }) {
715
+ return useQuery({
716
+ queryKey: ['products', options],
717
+ queryFn: () => client.listProducts(options),
718
+ });
719
+ }
720
+
721
+ export function useProduct(id: string | undefined) {
722
+ return useQuery({
723
+ queryKey: ['product', id],
724
+ queryFn: () => client.getProduct(id!),
725
+ enabled: !!id,
726
+ });
727
+ }
728
+
729
+ export function useOrders(options?: {
730
+ contactId?: string;
731
+ status?: 'pending' | 'paid' | 'refunded' | 'cancelled';
732
+ limit?: number;
733
+ }) {
734
+ return useQuery({
735
+ queryKey: ['orders', options],
736
+ queryFn: () => client.listOrders(options),
737
+ });
738
+ }
739
+
740
+ export function useOrder(id: string | undefined) {
741
+ return useQuery({
742
+ queryKey: ['order', id],
743
+ queryFn: () => client.getOrder(id!),
744
+ enabled: !!id,
745
+ });
746
+ }
747
+
748
+ export function useCreateCheckoutSession() {
749
+ return useMutation({
750
+ mutationFn: (data: {
751
+ items: Array<{ productId: string; quantity: number }>;
752
+ contactId?: string;
753
+ email?: string;
754
+ successUrl: string;
755
+ cancelUrl: string;
756
+ }) => client.createCheckoutSession(data),
757
+ });
758
+ }
759
+
760
+ export function useCheckoutSession(sessionId: string | undefined) {
761
+ return useQuery({
762
+ queryKey: ['checkoutSession', sessionId],
763
+ queryFn: () => client.getCheckoutSession(sessionId!),
764
+ enabled: !!sessionId,
765
+ });
766
+ }
767
+ `
768
+ : `/**
769
+ * Products & Checkout Hooks
770
+ * Auto-generated by @l4yercak3/cli
771
+ */
772
+
773
+ const { useQuery, useMutation } = require('@tanstack/react-query');
774
+ const { getL4yercak3Client } = require('../client');
775
+
776
+ const client = getL4yercak3Client();
777
+
778
+ function useProducts(options = {}) {
779
+ return useQuery({
780
+ queryKey: ['products', options],
781
+ queryFn: () => client.listProducts(options),
782
+ });
783
+ }
784
+
785
+ function useProduct(id) {
786
+ return useQuery({
787
+ queryKey: ['product', id],
788
+ queryFn: () => client.getProduct(id),
789
+ enabled: !!id,
790
+ });
791
+ }
792
+
793
+ function useOrders(options = {}) {
794
+ return useQuery({
795
+ queryKey: ['orders', options],
796
+ queryFn: () => client.listOrders(options),
797
+ });
798
+ }
799
+
800
+ function useOrder(id) {
801
+ return useQuery({
802
+ queryKey: ['order', id],
803
+ queryFn: () => client.getOrder(id),
804
+ enabled: !!id,
805
+ });
806
+ }
807
+
808
+ function useCreateCheckoutSession() {
809
+ return useMutation({
810
+ mutationFn: (data) => client.createCheckoutSession(data),
811
+ });
812
+ }
813
+
814
+ function useCheckoutSession(sessionId) {
815
+ return useQuery({
816
+ queryKey: ['checkoutSession', sessionId],
817
+ queryFn: () => client.getCheckoutSession(sessionId),
818
+ enabled: !!sessionId,
819
+ });
820
+ }
821
+
822
+ module.exports = {
823
+ useProducts,
824
+ useProduct,
825
+ useOrders,
826
+ useOrder,
827
+ useCreateCheckoutSession,
828
+ useCheckoutSession,
829
+ };
830
+ `;
831
+
832
+ return writeFileWithBackup(outputPath, content, action);
833
+ }
834
+
835
+ async generateInvoicesHook(outputDir, options) {
836
+ const { isTypeScript } = options;
837
+ const extension = isTypeScript ? 'ts' : 'js';
838
+ const outputPath = path.join(outputDir, `use-invoices.${extension}`);
839
+
840
+ const action = await checkFileOverwrite(outputPath);
841
+ if (action === 'skip') {
842
+ return null;
843
+ }
844
+
845
+ const content = isTypeScript
846
+ ? `/**
847
+ * Invoices Hooks
848
+ * Auto-generated by @l4yercak3/cli
849
+ */
850
+
851
+ import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
852
+ import { getL4yercak3Client } from '../client';
853
+ import type { Invoice, InvoiceCreateInput } from '../types';
854
+
855
+ const client = getL4yercak3Client();
856
+
857
+ export function useInvoices(options?: {
858
+ contactId?: string;
859
+ organizationId?: string;
860
+ status?: 'draft' | 'sent' | 'paid' | 'overdue' | 'cancelled';
861
+ type?: 'b2b' | 'b2c';
862
+ limit?: number;
863
+ }) {
864
+ return useQuery({
865
+ queryKey: ['invoices', options],
866
+ queryFn: () => client.listInvoices(options),
867
+ });
868
+ }
869
+
870
+ export function useInvoice(id: string | undefined) {
871
+ return useQuery({
872
+ queryKey: ['invoice', id],
873
+ queryFn: () => client.getInvoice(id!),
874
+ enabled: !!id,
875
+ });
876
+ }
877
+
878
+ export function useCreateInvoice() {
879
+ const queryClient = useQueryClient();
880
+
881
+ return useMutation({
882
+ mutationFn: (data: InvoiceCreateInput) => client.createInvoice(data),
883
+ onSuccess: () => {
884
+ queryClient.invalidateQueries({ queryKey: ['invoices'] });
885
+ },
886
+ });
887
+ }
888
+
889
+ export function useSendInvoice() {
890
+ const queryClient = useQueryClient();
891
+
892
+ return useMutation({
893
+ mutationFn: ({ id, options }: { id: string; options?: { emailTo?: string; message?: string } }) =>
894
+ client.sendInvoice(id, options),
895
+ onSuccess: (_, variables) => {
896
+ queryClient.invalidateQueries({ queryKey: ['invoice', variables.id] });
897
+ queryClient.invalidateQueries({ queryKey: ['invoices'] });
898
+ },
899
+ });
900
+ }
901
+
902
+ export function useMarkInvoicePaid() {
903
+ const queryClient = useQueryClient();
904
+
905
+ return useMutation({
906
+ mutationFn: ({ id, data }: { id: string; data?: { paidAt?: string; paymentMethod?: string } }) =>
907
+ client.markInvoicePaid(id, data),
908
+ onSuccess: (_, variables) => {
909
+ queryClient.invalidateQueries({ queryKey: ['invoice', variables.id] });
910
+ queryClient.invalidateQueries({ queryKey: ['invoices'] });
911
+ },
912
+ });
913
+ }
914
+
915
+ export function useInvoicePdf(id: string | undefined) {
916
+ return useQuery({
917
+ queryKey: ['invoicePdf', id],
918
+ queryFn: () => client.getInvoicePdf(id!),
919
+ enabled: !!id,
920
+ });
921
+ }
922
+ `
923
+ : `/**
924
+ * Invoices Hooks
925
+ * Auto-generated by @l4yercak3/cli
926
+ */
927
+
928
+ const { useQuery, useMutation, useQueryClient } = require('@tanstack/react-query');
929
+ const { getL4yercak3Client } = require('../client');
930
+
931
+ const client = getL4yercak3Client();
932
+
933
+ function useInvoices(options = {}) {
934
+ return useQuery({
935
+ queryKey: ['invoices', options],
936
+ queryFn: () => client.listInvoices(options),
937
+ });
938
+ }
939
+
940
+ function useInvoice(id) {
941
+ return useQuery({
942
+ queryKey: ['invoice', id],
943
+ queryFn: () => client.getInvoice(id),
944
+ enabled: !!id,
945
+ });
946
+ }
947
+
948
+ function useCreateInvoice() {
949
+ const queryClient = useQueryClient();
950
+
951
+ return useMutation({
952
+ mutationFn: (data) => client.createInvoice(data),
953
+ onSuccess: () => {
954
+ queryClient.invalidateQueries({ queryKey: ['invoices'] });
955
+ },
956
+ });
957
+ }
958
+
959
+ function useSendInvoice() {
960
+ const queryClient = useQueryClient();
961
+
962
+ return useMutation({
963
+ mutationFn: ({ id, options }) => client.sendInvoice(id, options),
964
+ onSuccess: (_, variables) => {
965
+ queryClient.invalidateQueries({ queryKey: ['invoice', variables.id] });
966
+ queryClient.invalidateQueries({ queryKey: ['invoices'] });
967
+ },
968
+ });
969
+ }
970
+
971
+ function useMarkInvoicePaid() {
972
+ const queryClient = useQueryClient();
973
+
974
+ return useMutation({
975
+ mutationFn: ({ id, data }) => client.markInvoicePaid(id, data),
976
+ onSuccess: (_, variables) => {
977
+ queryClient.invalidateQueries({ queryKey: ['invoice', variables.id] });
978
+ queryClient.invalidateQueries({ queryKey: ['invoices'] });
979
+ },
980
+ });
981
+ }
982
+
983
+ module.exports = {
984
+ useInvoices,
985
+ useInvoice,
986
+ useCreateInvoice,
987
+ useSendInvoice,
988
+ useMarkInvoicePaid,
989
+ };
990
+ `;
991
+
992
+ return writeFileWithBackup(outputPath, content, action);
993
+ }
994
+
995
+ async generateIndex(outputDir, options, generatedHooks) {
996
+ const { isTypeScript } = options;
997
+ const extension = isTypeScript ? 'ts' : 'js';
998
+ const outputPath = path.join(outputDir, `index.${extension}`);
999
+
1000
+ const action = await checkFileOverwrite(outputPath);
1001
+ if (action === 'skip') {
1002
+ return null;
1003
+ }
1004
+
1005
+ const exports = [];
1006
+ if (generatedHooks.includes('contacts')) {
1007
+ exports.push(isTypeScript ? "export * from './use-contacts';" : "...require('./use-contacts'),");
1008
+ }
1009
+ if (generatedHooks.includes('organizations')) {
1010
+ exports.push(isTypeScript ? "export * from './use-organizations';" : "...require('./use-organizations'),");
1011
+ }
1012
+ if (generatedHooks.includes('events')) {
1013
+ exports.push(isTypeScript ? "export * from './use-events';" : "...require('./use-events'),");
1014
+ }
1015
+ if (generatedHooks.includes('forms')) {
1016
+ exports.push(isTypeScript ? "export * from './use-forms';" : "...require('./use-forms'),");
1017
+ }
1018
+ if (generatedHooks.includes('products')) {
1019
+ exports.push(isTypeScript ? "export * from './use-products';" : "...require('./use-products'),");
1020
+ }
1021
+ if (generatedHooks.includes('invoices')) {
1022
+ exports.push(isTypeScript ? "export * from './use-invoices';" : "...require('./use-invoices'),");
1023
+ }
1024
+
1025
+ const content = isTypeScript
1026
+ ? `/**
1027
+ * L4YERCAK3 React Hooks
1028
+ * Auto-generated by @l4yercak3/cli
1029
+ */
1030
+
1031
+ ${exports.join('\n')}
1032
+ `
1033
+ : `/**
1034
+ * L4YERCAK3 React Hooks
1035
+ * Auto-generated by @l4yercak3/cli
1036
+ */
1037
+
1038
+ module.exports = {
1039
+ ${exports.join('\n ')}
1040
+ };
1041
+ `;
1042
+
1043
+ return writeFileWithBackup(outputPath, content, action);
1044
+ }
1045
+ }
1046
+
1047
+ module.exports = new HooksGenerator();