@htlkg/data 0.0.19 → 0.0.21
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/dist/client/index.d.ts +257 -1
- package/dist/client/index.js +59 -1
- package/dist/client/index.js.map +1 -1
- package/dist/common-DSxswsZ3.d.ts +40 -0
- package/dist/hooks/index.d.ts +162 -10
- package/dist/hooks/index.js +191 -33
- package/dist/hooks/index.js.map +1 -1
- package/dist/index.d.ts +9 -5
- package/dist/index.js +789 -13
- package/dist/index.js.map +1 -1
- package/dist/mutations/index.d.ts +342 -4
- package/dist/mutations/index.js +486 -0
- package/dist/mutations/index.js.map +1 -1
- package/dist/{productInstances-BA3cNsYc.d.ts → productInstances-BpQv1oLS.d.ts} +2 -40
- package/dist/queries/index.d.ts +113 -2
- package/dist/queries/index.js +192 -1
- package/dist/queries/index.js.map +1 -1
- package/dist/reservations-C0FNm__0.d.ts +154 -0
- package/dist/reservations-CdDfkcZ_.d.ts +172 -0
- package/package.json +14 -13
- package/src/client/index.ts +18 -0
- package/src/client/reservations.ts +336 -0
- package/src/hooks/createDataHook.test.ts +534 -0
- package/src/hooks/createDataHook.ts +20 -13
- package/src/hooks/index.ts +2 -0
- package/src/hooks/useContacts.test.ts +159 -0
- package/src/hooks/useContacts.ts +176 -0
- package/src/hooks/useReservations.ts +145 -0
- package/src/mutations/contacts.test.ts +604 -0
- package/src/mutations/contacts.ts +554 -0
- package/src/mutations/index.ts +32 -0
- package/src/mutations/productInstances/productInstances.test.ts +3 -3
- package/src/mutations/reservations.test.ts +459 -0
- package/src/mutations/reservations.ts +452 -0
- package/src/queries/contacts.test.ts +505 -0
- package/src/queries/contacts.ts +237 -0
- package/src/queries/index.ts +21 -0
- package/src/queries/reservations.test.ts +374 -0
- package/src/queries/reservations.ts +247 -0
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import { C as CreateAuditFields, a as UpdateWithSoftDeleteFields } from '../
|
|
2
|
-
export {
|
|
3
|
-
import { Brand, Account, User, SystemSettings } from '@htlkg/core/types';
|
|
1
|
+
import { C as CreateAuditFields, a as UpdateWithSoftDeleteFields } from '../common-DSxswsZ3.js';
|
|
2
|
+
export { S as SoftDeleteFields, U as UpdateAuditFields } from '../common-DSxswsZ3.js';
|
|
3
|
+
import { Brand, Account, User, SystemSettings, Contact } from '@htlkg/core/types';
|
|
4
|
+
export { C as CreateProductInstanceInput, U as UpdateProductInstanceInput, c as createProductInstance, d as deleteProductInstance, t as toggleProductInstanceEnabled, u as updateProductInstance } from '../productInstances-BpQv1oLS.js';
|
|
5
|
+
export { C as CreateReservationInput, b as ReservationStatus, R as ReservationValidationError, U as UpdateReservationInput, c as createReservation, d as deleteReservation, r as restoreReservation, s as softDeleteReservation, u as updateReservation, a as updateReservationStatus } from '../reservations-CdDfkcZ_.js';
|
|
6
|
+
import { z } from 'zod';
|
|
4
7
|
|
|
5
8
|
/**
|
|
6
9
|
* Brand Mutation Functions
|
|
@@ -375,4 +378,339 @@ declare function updateSystemSettings<TClient = any>(client: TClient, input: Upd
|
|
|
375
378
|
*/
|
|
376
379
|
declare function initializeSystemSettings<TClient = any>(client: TClient, initializedBy: string): Promise<SystemSettings | null>;
|
|
377
380
|
|
|
378
|
-
|
|
381
|
+
/**
|
|
382
|
+
* Contact Mutation Functions
|
|
383
|
+
*
|
|
384
|
+
* Provides type-safe mutation functions for creating, updating, and deleting contacts.
|
|
385
|
+
* Includes Zod validation for input data before mutations.
|
|
386
|
+
*/
|
|
387
|
+
|
|
388
|
+
/**
|
|
389
|
+
* Zod schema for creating a contact
|
|
390
|
+
*/
|
|
391
|
+
declare const createContactSchema: z.ZodObject<{
|
|
392
|
+
brandId: z.ZodString;
|
|
393
|
+
email: z.ZodString;
|
|
394
|
+
phone: z.ZodOptional<z.ZodString>;
|
|
395
|
+
firstName: z.ZodString;
|
|
396
|
+
lastName: z.ZodString;
|
|
397
|
+
locale: z.ZodOptional<z.ZodString>;
|
|
398
|
+
gdprConsent: z.ZodBoolean;
|
|
399
|
+
gdprConsentDate: z.ZodOptional<z.ZodString>;
|
|
400
|
+
marketingOptIn: z.ZodOptional<z.ZodBoolean>;
|
|
401
|
+
preferences: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
402
|
+
tags: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
403
|
+
totalVisits: z.ZodOptional<z.ZodNumber>;
|
|
404
|
+
lastVisitDate: z.ZodOptional<z.ZodString>;
|
|
405
|
+
firstVisitDate: z.ZodOptional<z.ZodString>;
|
|
406
|
+
legacyId: z.ZodOptional<z.ZodString>;
|
|
407
|
+
createdAt: z.ZodOptional<z.ZodString>;
|
|
408
|
+
createdBy: z.ZodOptional<z.ZodString>;
|
|
409
|
+
updatedAt: z.ZodOptional<z.ZodString>;
|
|
410
|
+
updatedBy: z.ZodOptional<z.ZodString>;
|
|
411
|
+
}, "strip", z.ZodTypeAny, {
|
|
412
|
+
brandId: string;
|
|
413
|
+
email: string;
|
|
414
|
+
lastName: string;
|
|
415
|
+
firstName: string;
|
|
416
|
+
gdprConsent: boolean;
|
|
417
|
+
updatedAt?: string | undefined;
|
|
418
|
+
updatedBy?: string | undefined;
|
|
419
|
+
phone?: string | undefined;
|
|
420
|
+
locale?: string | undefined;
|
|
421
|
+
gdprConsentDate?: string | undefined;
|
|
422
|
+
marketingOptIn?: boolean | undefined;
|
|
423
|
+
preferences?: Record<string, any> | undefined;
|
|
424
|
+
tags?: string[] | undefined;
|
|
425
|
+
totalVisits?: number | undefined;
|
|
426
|
+
lastVisitDate?: string | undefined;
|
|
427
|
+
firstVisitDate?: string | undefined;
|
|
428
|
+
legacyId?: string | undefined;
|
|
429
|
+
createdAt?: string | undefined;
|
|
430
|
+
createdBy?: string | undefined;
|
|
431
|
+
}, {
|
|
432
|
+
brandId: string;
|
|
433
|
+
email: string;
|
|
434
|
+
lastName: string;
|
|
435
|
+
firstName: string;
|
|
436
|
+
gdprConsent: boolean;
|
|
437
|
+
updatedAt?: string | undefined;
|
|
438
|
+
updatedBy?: string | undefined;
|
|
439
|
+
phone?: string | undefined;
|
|
440
|
+
locale?: string | undefined;
|
|
441
|
+
gdprConsentDate?: string | undefined;
|
|
442
|
+
marketingOptIn?: boolean | undefined;
|
|
443
|
+
preferences?: Record<string, any> | undefined;
|
|
444
|
+
tags?: string[] | undefined;
|
|
445
|
+
totalVisits?: number | undefined;
|
|
446
|
+
lastVisitDate?: string | undefined;
|
|
447
|
+
firstVisitDate?: string | undefined;
|
|
448
|
+
legacyId?: string | undefined;
|
|
449
|
+
createdAt?: string | undefined;
|
|
450
|
+
createdBy?: string | undefined;
|
|
451
|
+
}>;
|
|
452
|
+
/**
|
|
453
|
+
* Zod schema for updating a contact
|
|
454
|
+
*/
|
|
455
|
+
declare const updateContactSchema: z.ZodObject<{
|
|
456
|
+
id: z.ZodString;
|
|
457
|
+
brandId: z.ZodOptional<z.ZodString>;
|
|
458
|
+
email: z.ZodOptional<z.ZodString>;
|
|
459
|
+
phone: z.ZodOptional<z.ZodString>;
|
|
460
|
+
firstName: z.ZodOptional<z.ZodString>;
|
|
461
|
+
lastName: z.ZodOptional<z.ZodString>;
|
|
462
|
+
locale: z.ZodOptional<z.ZodString>;
|
|
463
|
+
gdprConsent: z.ZodOptional<z.ZodBoolean>;
|
|
464
|
+
gdprConsentDate: z.ZodOptional<z.ZodString>;
|
|
465
|
+
marketingOptIn: z.ZodOptional<z.ZodBoolean>;
|
|
466
|
+
preferences: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
467
|
+
tags: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
468
|
+
totalVisits: z.ZodOptional<z.ZodNumber>;
|
|
469
|
+
lastVisitDate: z.ZodOptional<z.ZodString>;
|
|
470
|
+
firstVisitDate: z.ZodOptional<z.ZodString>;
|
|
471
|
+
legacyId: z.ZodOptional<z.ZodString>;
|
|
472
|
+
updatedAt: z.ZodOptional<z.ZodString>;
|
|
473
|
+
updatedBy: z.ZodOptional<z.ZodString>;
|
|
474
|
+
deletedAt: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
475
|
+
deletedBy: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
476
|
+
}, "strip", z.ZodTypeAny, {
|
|
477
|
+
id: string;
|
|
478
|
+
updatedAt?: string | undefined;
|
|
479
|
+
updatedBy?: string | undefined;
|
|
480
|
+
brandId?: string | undefined;
|
|
481
|
+
deletedAt?: string | null | undefined;
|
|
482
|
+
deletedBy?: string | null | undefined;
|
|
483
|
+
email?: string | undefined;
|
|
484
|
+
phone?: string | undefined;
|
|
485
|
+
lastName?: string | undefined;
|
|
486
|
+
firstName?: string | undefined;
|
|
487
|
+
locale?: string | undefined;
|
|
488
|
+
gdprConsent?: boolean | undefined;
|
|
489
|
+
gdprConsentDate?: string | undefined;
|
|
490
|
+
marketingOptIn?: boolean | undefined;
|
|
491
|
+
preferences?: Record<string, any> | undefined;
|
|
492
|
+
tags?: string[] | undefined;
|
|
493
|
+
totalVisits?: number | undefined;
|
|
494
|
+
lastVisitDate?: string | undefined;
|
|
495
|
+
firstVisitDate?: string | undefined;
|
|
496
|
+
legacyId?: string | undefined;
|
|
497
|
+
}, {
|
|
498
|
+
id: string;
|
|
499
|
+
updatedAt?: string | undefined;
|
|
500
|
+
updatedBy?: string | undefined;
|
|
501
|
+
brandId?: string | undefined;
|
|
502
|
+
deletedAt?: string | null | undefined;
|
|
503
|
+
deletedBy?: string | null | undefined;
|
|
504
|
+
email?: string | undefined;
|
|
505
|
+
phone?: string | undefined;
|
|
506
|
+
lastName?: string | undefined;
|
|
507
|
+
firstName?: string | undefined;
|
|
508
|
+
locale?: string | undefined;
|
|
509
|
+
gdprConsent?: boolean | undefined;
|
|
510
|
+
gdprConsentDate?: string | undefined;
|
|
511
|
+
marketingOptIn?: boolean | undefined;
|
|
512
|
+
preferences?: Record<string, any> | undefined;
|
|
513
|
+
tags?: string[] | undefined;
|
|
514
|
+
totalVisits?: number | undefined;
|
|
515
|
+
lastVisitDate?: string | undefined;
|
|
516
|
+
firstVisitDate?: string | undefined;
|
|
517
|
+
legacyId?: string | undefined;
|
|
518
|
+
}>;
|
|
519
|
+
/**
|
|
520
|
+
* Zod schema for merging contacts
|
|
521
|
+
*/
|
|
522
|
+
declare const mergeContactsSchema: z.ZodObject<{
|
|
523
|
+
primaryId: z.ZodString;
|
|
524
|
+
duplicateIds: z.ZodArray<z.ZodString, "many">;
|
|
525
|
+
}, "strip", z.ZodTypeAny, {
|
|
526
|
+
primaryId: string;
|
|
527
|
+
duplicateIds: string[];
|
|
528
|
+
}, {
|
|
529
|
+
primaryId: string;
|
|
530
|
+
duplicateIds: string[];
|
|
531
|
+
}>;
|
|
532
|
+
/**
|
|
533
|
+
* Validation error class for contact operations
|
|
534
|
+
*/
|
|
535
|
+
declare class ContactValidationError extends Error {
|
|
536
|
+
readonly issues: z.ZodIssue[];
|
|
537
|
+
constructor(message: string, issues?: z.ZodIssue[]);
|
|
538
|
+
}
|
|
539
|
+
/**
|
|
540
|
+
* Input type for creating a contact
|
|
541
|
+
*/
|
|
542
|
+
interface CreateContactInput extends CreateAuditFields {
|
|
543
|
+
brandId: string;
|
|
544
|
+
email: string;
|
|
545
|
+
phone?: string;
|
|
546
|
+
firstName: string;
|
|
547
|
+
lastName: string;
|
|
548
|
+
locale?: string;
|
|
549
|
+
gdprConsent: boolean;
|
|
550
|
+
gdprConsentDate?: string;
|
|
551
|
+
marketingOptIn?: boolean;
|
|
552
|
+
preferences?: Record<string, any>;
|
|
553
|
+
tags?: string[];
|
|
554
|
+
totalVisits?: number;
|
|
555
|
+
lastVisitDate?: string;
|
|
556
|
+
firstVisitDate?: string;
|
|
557
|
+
legacyId?: string;
|
|
558
|
+
}
|
|
559
|
+
/**
|
|
560
|
+
* Input type for updating a contact
|
|
561
|
+
*/
|
|
562
|
+
interface UpdateContactInput extends UpdateWithSoftDeleteFields {
|
|
563
|
+
id: string;
|
|
564
|
+
brandId?: string;
|
|
565
|
+
email?: string;
|
|
566
|
+
phone?: string;
|
|
567
|
+
firstName?: string;
|
|
568
|
+
lastName?: string;
|
|
569
|
+
locale?: string;
|
|
570
|
+
gdprConsent?: boolean;
|
|
571
|
+
gdprConsentDate?: string;
|
|
572
|
+
marketingOptIn?: boolean;
|
|
573
|
+
preferences?: Record<string, any>;
|
|
574
|
+
tags?: string[];
|
|
575
|
+
totalVisits?: number;
|
|
576
|
+
lastVisitDate?: string;
|
|
577
|
+
firstVisitDate?: string;
|
|
578
|
+
legacyId?: string;
|
|
579
|
+
}
|
|
580
|
+
/**
|
|
581
|
+
* Input type for merging contacts
|
|
582
|
+
*/
|
|
583
|
+
interface MergeContactsInput {
|
|
584
|
+
primaryId: string;
|
|
585
|
+
duplicateIds: string[];
|
|
586
|
+
}
|
|
587
|
+
/**
|
|
588
|
+
* Result type for merge operation
|
|
589
|
+
*/
|
|
590
|
+
interface MergeContactsResult {
|
|
591
|
+
success: boolean;
|
|
592
|
+
mergedContact?: Contact;
|
|
593
|
+
deletedIds?: string[];
|
|
594
|
+
error?: string;
|
|
595
|
+
}
|
|
596
|
+
/**
|
|
597
|
+
* Create a new contact with Zod validation
|
|
598
|
+
*
|
|
599
|
+
* @throws {ContactValidationError} if input validation fails
|
|
600
|
+
*
|
|
601
|
+
* @example
|
|
602
|
+
* ```typescript
|
|
603
|
+
* import { createContact } from '@htlkg/data/mutations';
|
|
604
|
+
* import { generateClient } from '@htlkg/data/client';
|
|
605
|
+
*
|
|
606
|
+
* const client = generateClient<Schema>();
|
|
607
|
+
* const contact = await createContact(client, {
|
|
608
|
+
* brandId: 'brand-123',
|
|
609
|
+
* email: 'guest@example.com',
|
|
610
|
+
* firstName: 'John',
|
|
611
|
+
* lastName: 'Doe',
|
|
612
|
+
* gdprConsent: true,
|
|
613
|
+
* gdprConsentDate: new Date().toISOString()
|
|
614
|
+
* });
|
|
615
|
+
* ```
|
|
616
|
+
*/
|
|
617
|
+
declare function createContact<TClient = any>(client: TClient, input: CreateContactInput): Promise<Contact | null>;
|
|
618
|
+
/**
|
|
619
|
+
* Update an existing contact with Zod validation
|
|
620
|
+
*
|
|
621
|
+
* @throws {ContactValidationError} if input validation fails
|
|
622
|
+
*
|
|
623
|
+
* @example
|
|
624
|
+
* ```typescript
|
|
625
|
+
* import { updateContact } from '@htlkg/data/mutations';
|
|
626
|
+
* import { generateClient } from '@htlkg/data/client';
|
|
627
|
+
*
|
|
628
|
+
* const client = generateClient<Schema>();
|
|
629
|
+
* const contact = await updateContact(client, {
|
|
630
|
+
* id: 'contact-123',
|
|
631
|
+
* firstName: 'Jane',
|
|
632
|
+
* marketingOptIn: true
|
|
633
|
+
* });
|
|
634
|
+
* ```
|
|
635
|
+
*/
|
|
636
|
+
declare function updateContact<TClient = any>(client: TClient, input: UpdateContactInput): Promise<Contact | null>;
|
|
637
|
+
/**
|
|
638
|
+
* Soft delete a contact (sets deletedAt/deletedBy instead of removing)
|
|
639
|
+
*
|
|
640
|
+
* @example
|
|
641
|
+
* ```typescript
|
|
642
|
+
* import { softDeleteContact } from '@htlkg/data/mutations';
|
|
643
|
+
* import { generateClient } from '@htlkg/data/client';
|
|
644
|
+
*
|
|
645
|
+
* const client = generateClient<Schema>();
|
|
646
|
+
* await softDeleteContact(client, 'contact-123', 'admin@example.com');
|
|
647
|
+
* ```
|
|
648
|
+
*/
|
|
649
|
+
declare function softDeleteContact<TClient = any>(client: TClient, id: string, deletedBy: string): Promise<boolean>;
|
|
650
|
+
/**
|
|
651
|
+
* Restore a soft-deleted contact
|
|
652
|
+
* Checks retention period before allowing restoration
|
|
653
|
+
*
|
|
654
|
+
* @example
|
|
655
|
+
* ```typescript
|
|
656
|
+
* import { restoreContact } from '@htlkg/data/mutations';
|
|
657
|
+
* import { generateClient } from '@htlkg/data/client';
|
|
658
|
+
*
|
|
659
|
+
* const client = generateClient<Schema>();
|
|
660
|
+
* await restoreContact(client, 'contact-123');
|
|
661
|
+
* // Or with custom retention days:
|
|
662
|
+
* await restoreContact(client, 'contact-123', 60);
|
|
663
|
+
* ```
|
|
664
|
+
*/
|
|
665
|
+
declare function restoreContact<TClient = any>(client: TClient, id: string, retentionDays?: number): Promise<{
|
|
666
|
+
success: boolean;
|
|
667
|
+
error?: string;
|
|
668
|
+
}>;
|
|
669
|
+
/**
|
|
670
|
+
* Hard delete a contact (permanently removes from database)
|
|
671
|
+
* Use with caution - prefer softDeleteContact for recoverable deletion
|
|
672
|
+
*
|
|
673
|
+
* @example
|
|
674
|
+
* ```typescript
|
|
675
|
+
* import { deleteContact } from '@htlkg/data/mutations';
|
|
676
|
+
* import { generateClient } from '@htlkg/data/client';
|
|
677
|
+
*
|
|
678
|
+
* const client = generateClient<Schema>();
|
|
679
|
+
* await deleteContact(client, 'contact-123');
|
|
680
|
+
* ```
|
|
681
|
+
*/
|
|
682
|
+
declare function deleteContact<TClient = any>(client: TClient, id: string): Promise<boolean>;
|
|
683
|
+
/**
|
|
684
|
+
* Merge duplicate contacts into a primary contact
|
|
685
|
+
*
|
|
686
|
+
* This function:
|
|
687
|
+
* 1. Validates all contact IDs exist
|
|
688
|
+
* 2. Aggregates data from duplicates into the primary contact
|
|
689
|
+
* 3. Soft deletes the duplicate contacts
|
|
690
|
+
* 4. Returns the updated primary contact
|
|
691
|
+
*
|
|
692
|
+
* Merge strategy:
|
|
693
|
+
* - totalVisits: Sum of all contacts
|
|
694
|
+
* - firstVisitDate: Earliest date across all contacts
|
|
695
|
+
* - lastVisitDate: Latest date across all contacts
|
|
696
|
+
* - tags: Merged unique tags from all contacts
|
|
697
|
+
* - preferences: Primary contact preferences take precedence
|
|
698
|
+
* - Other fields: Primary contact values are preserved
|
|
699
|
+
*
|
|
700
|
+
* @throws {ContactValidationError} if input validation fails
|
|
701
|
+
*
|
|
702
|
+
* @example
|
|
703
|
+
* ```typescript
|
|
704
|
+
* import { mergeContacts } from '@htlkg/data/mutations';
|
|
705
|
+
* import { generateClient } from '@htlkg/data/client';
|
|
706
|
+
*
|
|
707
|
+
* const client = generateClient<Schema>();
|
|
708
|
+
* const result = await mergeContacts(client, {
|
|
709
|
+
* primaryId: 'contact-primary',
|
|
710
|
+
* duplicateIds: ['contact-dup-1', 'contact-dup-2']
|
|
711
|
+
* }, 'admin@example.com');
|
|
712
|
+
* ```
|
|
713
|
+
*/
|
|
714
|
+
declare function mergeContacts<TClient = any>(client: TClient, input: MergeContactsInput, mergedBy: string): Promise<MergeContactsResult>;
|
|
715
|
+
|
|
716
|
+
export { ContactValidationError, type CreateAccountInput, CreateAuditFields, type CreateBrandInput, type CreateContactInput, type CreateUserInput, type MergeContactsInput, type MergeContactsResult, type UpdateAccountInput, type UpdateBrandInput, type UpdateContactInput, type UpdateSystemSettingsInput, type UpdateUserInput, UpdateWithSoftDeleteFields, createAccount, createBrand, createContact, createContactSchema, createUser, deleteAccount, deleteBrand, deleteContact, deleteUser, initializeSystemSettings, mergeContacts, mergeContactsSchema, restoreAccount, restoreBrand, restoreContact, restoreUser, softDeleteAccount, softDeleteBrand, softDeleteContact, softDeleteUser, updateAccount, updateBrand, updateContact, updateContactSchema, updateSystemSettings, updateUser };
|