@htlkg/data 0.0.21 → 0.0.23

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 (62) hide show
  1. package/dist/hooks/index.d.ts +702 -94
  2. package/dist/hooks/index.js +793 -56
  3. package/dist/hooks/index.js.map +1 -1
  4. package/dist/index.d.ts +1 -1
  5. package/dist/index.js +802 -65
  6. package/dist/index.js.map +1 -1
  7. package/dist/mutations/index.js +4 -4
  8. package/dist/mutations/index.js.map +1 -1
  9. package/dist/queries/index.js +5 -5
  10. package/dist/queries/index.js.map +1 -1
  11. package/package.json +11 -12
  12. package/src/hooks/accounts/index.ts +2 -0
  13. package/src/hooks/{useAccounts.ts → accounts/useAccounts.ts} +48 -5
  14. package/src/hooks/accounts/usePaginatedAccounts.ts +166 -0
  15. package/src/hooks/brands/index.ts +2 -0
  16. package/src/hooks/{useBrands.ts → brands/useBrands.ts} +1 -1
  17. package/src/hooks/brands/usePaginatedBrands.ts +206 -0
  18. package/src/hooks/contacts/index.ts +2 -0
  19. package/src/hooks/contacts/useContacts.ts +176 -0
  20. package/src/hooks/contacts/usePaginatedContacts.ts +268 -0
  21. package/src/hooks/createPaginatedDataHook.ts +359 -0
  22. package/src/hooks/data-hook-errors.property.test.ts +4 -4
  23. package/src/hooks/data-hook-filters.property.test.ts +4 -4
  24. package/src/hooks/data-hooks.property.test.ts +4 -4
  25. package/src/hooks/index.ts +101 -8
  26. package/src/hooks/productInstances/index.ts +1 -0
  27. package/src/hooks/{useProductInstances.ts → productInstances/useProductInstances.ts} +9 -6
  28. package/src/hooks/products/index.ts +1 -0
  29. package/src/hooks/{useProducts.ts → products/useProducts.ts} +4 -5
  30. package/src/hooks/reservations/index.ts +2 -0
  31. package/src/hooks/reservations/usePaginatedReservations.ts +258 -0
  32. package/src/hooks/{useReservations.ts → reservations/useReservations.ts} +65 -10
  33. package/src/hooks/users/index.ts +2 -0
  34. package/src/hooks/users/usePaginatedUsers.ts +213 -0
  35. package/src/hooks/{useUsers.ts → users/useUsers.ts} +1 -1
  36. package/src/mutations/accounts/accounts.test.ts +287 -0
  37. package/src/mutations/{accounts.ts → accounts/accounts.ts} +2 -2
  38. package/src/mutations/accounts/index.ts +1 -0
  39. package/src/mutations/brands/brands.test.ts +292 -0
  40. package/src/mutations/{brands.ts → brands/brands.ts} +2 -2
  41. package/src/mutations/brands/index.ts +1 -0
  42. package/src/mutations/reservations/index.ts +1 -0
  43. package/src/mutations/{reservations.test.ts → reservations/reservations.test.ts} +1 -1
  44. package/src/mutations/{reservations.ts → reservations/reservations.ts} +2 -2
  45. package/src/mutations/users/index.ts +1 -0
  46. package/src/mutations/users/users.test.ts +289 -0
  47. package/src/mutations/{users.ts → users/users.ts} +2 -2
  48. package/src/queries/accounts/accounts.test.ts +228 -0
  49. package/src/queries/accounts/index.ts +1 -0
  50. package/src/queries/brands/brands.test.ts +288 -0
  51. package/src/queries/brands/index.ts +1 -0
  52. package/src/queries/products/index.ts +1 -0
  53. package/src/queries/products/products.test.ts +347 -0
  54. package/src/queries/reservations/index.ts +1 -0
  55. package/src/queries/users/index.ts +1 -0
  56. package/src/queries/users/users.test.ts +301 -0
  57. /package/src/queries/{accounts.ts → accounts/accounts.ts} +0 -0
  58. /package/src/queries/{brands.ts → brands/brands.ts} +0 -0
  59. /package/src/queries/{products.ts → products/products.ts} +0 -0
  60. /package/src/queries/{reservations.test.ts → reservations/reservations.test.ts} +0 -0
  61. /package/src/queries/{reservations.ts → reservations/reservations.ts} +0 -0
  62. /package/src/queries/{users.ts → users/users.ts} +0 -0
@@ -55,7 +55,7 @@ function createDataHook(config) {
55
55
  defaultLimit,
56
56
  selectionSet,
57
57
  transform,
58
- buildFilter: buildFilter7,
58
+ buildFilter: buildFilter11,
59
59
  computedProperties,
60
60
  dataPropertyName = "data"
61
61
  } = config;
@@ -65,8 +65,8 @@ function createDataHook(config) {
65
65
  const loading = ref(false);
66
66
  const error = ref(null);
67
67
  const getFilter = () => {
68
- if (buildFilter7) {
69
- return buildFilter7(options);
68
+ if (buildFilter11) {
69
+ return buildFilter11(options);
70
70
  }
71
71
  return baseFilter && Object.keys(baseFilter).length > 0 ? baseFilter : void 0;
72
72
  };
@@ -126,7 +126,171 @@ function createDataHook(config) {
126
126
  };
127
127
  }
128
128
 
129
- // src/hooks/useBrands.ts
129
+ // src/hooks/createPaginatedDataHook.ts
130
+ import { ref as ref2, computed as computed2, onMounted as onMounted2 } from "vue";
131
+ var ACTIVE_FILTER = {
132
+ or: [{ deletedAt: { attributeExists: false } }, { deletedAt: { eq: null } }]
133
+ };
134
+ var DELETED_FILTER = {
135
+ deletedAt: { gt: "" }
136
+ };
137
+ function createPaginatedDataHook(config) {
138
+ const {
139
+ model,
140
+ defaultPageSize = 25,
141
+ selectionSet,
142
+ transform,
143
+ buildFilter: buildFilter11,
144
+ dataPropertyName = "data",
145
+ baseFilter
146
+ } = config;
147
+ return function usePaginatedData(options = {}) {
148
+ const { filter: additionalFilter, pageSize = defaultPageSize, autoFetch = true } = options;
149
+ const data = ref2([]);
150
+ const loading = ref2(false);
151
+ const initialLoading = ref2(false);
152
+ const loadingMore = ref2(false);
153
+ const error = ref2(null);
154
+ const pagination = ref2({
155
+ nextToken: null,
156
+ hasMore: true,
157
+ loadedCount: 0
158
+ });
159
+ const searchFilter = ref2(null);
160
+ const hasMore = computed2(() => pagination.value.hasMore);
161
+ const getFilter = () => {
162
+ const filters = [];
163
+ if (baseFilter) {
164
+ filters.push(baseFilter);
165
+ }
166
+ if (buildFilter11) {
167
+ const customFilter = buildFilter11(options);
168
+ if (customFilter) {
169
+ filters.push(customFilter);
170
+ }
171
+ }
172
+ if (additionalFilter && Object.keys(additionalFilter).length > 0) {
173
+ filters.push(additionalFilter);
174
+ }
175
+ if (searchFilter.value && Object.keys(searchFilter.value).length > 0) {
176
+ filters.push(searchFilter.value);
177
+ }
178
+ if (filters.length === 0) {
179
+ return void 0;
180
+ }
181
+ if (filters.length === 1) {
182
+ return filters[0];
183
+ }
184
+ return { and: filters };
185
+ };
186
+ async function fetchPage(nextToken, append = false) {
187
+ if (!append) {
188
+ initialLoading.value = true;
189
+ } else {
190
+ loadingMore.value = true;
191
+ }
192
+ loading.value = true;
193
+ error.value = null;
194
+ try {
195
+ const queryOptions = {
196
+ limit: pageSize
197
+ };
198
+ const filter = getFilter();
199
+ if (filter) {
200
+ queryOptions.filter = filter;
201
+ }
202
+ if (nextToken) {
203
+ queryOptions.nextToken = nextToken;
204
+ }
205
+ if (selectionSet) {
206
+ queryOptions.selectionSet = selectionSet;
207
+ }
208
+ const response = await query(model, "list", queryOptions);
209
+ if (hasErrors(response)) {
210
+ throw new Error(getErrorMessage(response) || `Failed to fetch ${model}`);
211
+ }
212
+ const items = response.data || [];
213
+ const transformedItems = transform ? items.map(transform) : items;
214
+ if (append) {
215
+ data.value = [...data.value, ...transformedItems];
216
+ } else {
217
+ data.value = transformedItems;
218
+ }
219
+ const responseNextToken = response.nextToken;
220
+ pagination.value = {
221
+ nextToken: responseNextToken || null,
222
+ hasMore: !!responseNextToken,
223
+ loadedCount: data.value.length
224
+ };
225
+ } catch (e) {
226
+ error.value = e;
227
+ console.error(`[use${model}] Error fetching ${model}:`, e);
228
+ } finally {
229
+ loading.value = false;
230
+ initialLoading.value = false;
231
+ loadingMore.value = false;
232
+ }
233
+ }
234
+ async function loadMore() {
235
+ if (loadingMore.value || !pagination.value.hasMore) {
236
+ return;
237
+ }
238
+ await fetchPage(pagination.value.nextToken, true);
239
+ }
240
+ async function refetch() {
241
+ pagination.value = {
242
+ nextToken: null,
243
+ hasMore: true,
244
+ loadedCount: 0
245
+ };
246
+ await fetchPage(null, false);
247
+ }
248
+ function reset() {
249
+ data.value = [];
250
+ error.value = null;
251
+ searchFilter.value = null;
252
+ pagination.value = {
253
+ nextToken: null,
254
+ hasMore: true,
255
+ loadedCount: 0
256
+ };
257
+ }
258
+ async function setSearchFilter(filter) {
259
+ searchFilter.value = filter;
260
+ pagination.value = {
261
+ nextToken: null,
262
+ hasMore: true,
263
+ loadedCount: 0
264
+ };
265
+ await fetchPage(null, false);
266
+ }
267
+ if (autoFetch) {
268
+ onMounted2(() => {
269
+ fetchPage(null, false);
270
+ });
271
+ }
272
+ const result = {
273
+ data,
274
+ loading,
275
+ initialLoading,
276
+ loadingMore,
277
+ error,
278
+ pagination,
279
+ hasMore,
280
+ loadMore,
281
+ refetch,
282
+ reset,
283
+ setSearchFilter,
284
+ searchFilter
285
+ };
286
+ if (dataPropertyName !== "data") {
287
+ result[dataPropertyName] = data;
288
+ }
289
+ return result;
290
+ };
291
+ }
292
+
293
+ // src/hooks/brands/useBrands.ts
130
294
  function buildFilter(options) {
131
295
  let filter = options.filter || {};
132
296
  if (options.accountId) {
@@ -156,23 +320,96 @@ function useBrands(options = {}) {
156
320
  };
157
321
  }
158
322
 
159
- // src/hooks/useAccounts.ts
160
- var useAccountsInternal = createDataHook({
161
- model: "Account",
162
- dataPropertyName: "accounts"
323
+ // src/hooks/brands/usePaginatedBrands.ts
324
+ function buildFilter2(options) {
325
+ const conditions = [];
326
+ if (options.accountId) {
327
+ conditions.push({ accountId: { eq: options.accountId } });
328
+ }
329
+ if (options.filter && Object.keys(options.filter).length > 0) {
330
+ conditions.push(options.filter);
331
+ }
332
+ if (conditions.length === 0) {
333
+ return void 0;
334
+ }
335
+ if (conditions.length === 1) {
336
+ return conditions[0];
337
+ }
338
+ return { and: conditions };
339
+ }
340
+ function transformBrand(brand) {
341
+ return {
342
+ ...brand,
343
+ accountName: brand.account?.name || ""
344
+ };
345
+ }
346
+ var BRAND_SELECTION_SET = [
347
+ "id",
348
+ "name",
349
+ "accountId",
350
+ "logo",
351
+ "timezone",
352
+ "status",
353
+ "settings",
354
+ "deletedAt",
355
+ "deletedBy",
356
+ "account.name"
357
+ ];
358
+ var useActiveBrandsInternal = createPaginatedDataHook({
359
+ model: "Brand",
360
+ dataPropertyName: "brands",
361
+ defaultPageSize: 25,
362
+ selectionSet: BRAND_SELECTION_SET,
363
+ transform: transformBrand,
364
+ buildFilter: buildFilter2,
365
+ baseFilter: ACTIVE_FILTER
163
366
  });
164
- function useAccounts(options = {}) {
165
- const result = useAccountsInternal(options);
367
+ var useDeletedBrandsInternal = createPaginatedDataHook({
368
+ model: "Brand",
369
+ dataPropertyName: "brands",
370
+ defaultPageSize: 25,
371
+ selectionSet: BRAND_SELECTION_SET,
372
+ transform: transformBrand,
373
+ buildFilter: buildFilter2,
374
+ baseFilter: DELETED_FILTER
375
+ });
376
+ function useActiveBrands(options = {}) {
377
+ const result = useActiveBrandsInternal(options);
166
378
  return {
167
- accounts: result.accounts,
379
+ brands: result.brands,
168
380
  loading: result.loading,
381
+ initialLoading: result.initialLoading,
382
+ loadingMore: result.loadingMore,
169
383
  error: result.error,
170
- refetch: result.refetch
384
+ pagination: result.pagination,
385
+ hasMore: result.hasMore,
386
+ loadMore: result.loadMore,
387
+ refetch: result.refetch,
388
+ reset: result.reset,
389
+ setSearchFilter: result.setSearchFilter,
390
+ searchFilter: result.searchFilter
391
+ };
392
+ }
393
+ function useDeletedBrands(options = {}) {
394
+ const result = useDeletedBrandsInternal(options);
395
+ return {
396
+ brands: result.brands,
397
+ loading: result.loading,
398
+ initialLoading: result.initialLoading,
399
+ loadingMore: result.loadingMore,
400
+ error: result.error,
401
+ pagination: result.pagination,
402
+ hasMore: result.hasMore,
403
+ loadMore: result.loadMore,
404
+ refetch: result.refetch,
405
+ reset: result.reset,
406
+ setSearchFilter: result.setSearchFilter,
407
+ searchFilter: result.searchFilter
171
408
  };
172
409
  }
173
410
 
174
- // src/hooks/useUsers.ts
175
- function buildFilter2(options) {
411
+ // src/hooks/users/useUsers.ts
412
+ function buildFilter3(options) {
176
413
  let filter = options.filter || {};
177
414
  if (options.brandId) {
178
415
  filter = { ...filter, brandIds: { contains: options.brandId } };
@@ -185,7 +422,7 @@ function buildFilter2(options) {
185
422
  var useUsersInternal = createDataHook({
186
423
  model: "User",
187
424
  dataPropertyName: "users",
188
- buildFilter: buildFilter2
425
+ buildFilter: buildFilter3
189
426
  });
190
427
  function useUsers(options = {}) {
191
428
  const result = useUsersInternal(options);
@@ -197,8 +434,419 @@ function useUsers(options = {}) {
197
434
  };
198
435
  }
199
436
 
200
- // src/hooks/useProducts.ts
201
- function buildFilter3(options) {
437
+ // src/hooks/users/usePaginatedUsers.ts
438
+ function buildFilter4(options) {
439
+ const conditions = [];
440
+ if (options.brandId) {
441
+ conditions.push({ brandIds: { contains: options.brandId } });
442
+ }
443
+ if (options.accountId) {
444
+ conditions.push({ accountId: { eq: options.accountId } });
445
+ }
446
+ if (options.filter && Object.keys(options.filter).length > 0) {
447
+ conditions.push(options.filter);
448
+ }
449
+ if (conditions.length === 0) {
450
+ return void 0;
451
+ }
452
+ if (conditions.length === 1) {
453
+ return conditions[0];
454
+ }
455
+ return { and: conditions };
456
+ }
457
+ function transformUser(user) {
458
+ return {
459
+ ...user,
460
+ accountName: user.account?.name || ""
461
+ };
462
+ }
463
+ var USER_SELECTION_SET = [
464
+ "id",
465
+ "email",
466
+ "accountId",
467
+ "brandIds",
468
+ "roles",
469
+ "status",
470
+ "lastLogin",
471
+ "createdAt",
472
+ "deletedAt",
473
+ "deletedBy",
474
+ "account.name"
475
+ ];
476
+ var useActiveUsersInternal = createPaginatedDataHook({
477
+ model: "User",
478
+ dataPropertyName: "users",
479
+ defaultPageSize: 25,
480
+ selectionSet: USER_SELECTION_SET,
481
+ transform: transformUser,
482
+ buildFilter: buildFilter4,
483
+ baseFilter: ACTIVE_FILTER
484
+ });
485
+ var useDeletedUsersInternal = createPaginatedDataHook({
486
+ model: "User",
487
+ dataPropertyName: "users",
488
+ defaultPageSize: 25,
489
+ selectionSet: USER_SELECTION_SET,
490
+ transform: transformUser,
491
+ buildFilter: buildFilter4,
492
+ baseFilter: DELETED_FILTER
493
+ });
494
+ function useActiveUsers(options = {}) {
495
+ const result = useActiveUsersInternal(options);
496
+ return {
497
+ users: result.users,
498
+ loading: result.loading,
499
+ initialLoading: result.initialLoading,
500
+ loadingMore: result.loadingMore,
501
+ error: result.error,
502
+ pagination: result.pagination,
503
+ hasMore: result.hasMore,
504
+ loadMore: result.loadMore,
505
+ refetch: result.refetch,
506
+ reset: result.reset,
507
+ setSearchFilter: result.setSearchFilter,
508
+ searchFilter: result.searchFilter
509
+ };
510
+ }
511
+ function useDeletedUsers(options = {}) {
512
+ const result = useDeletedUsersInternal(options);
513
+ return {
514
+ users: result.users,
515
+ loading: result.loading,
516
+ initialLoading: result.initialLoading,
517
+ loadingMore: result.loadingMore,
518
+ error: result.error,
519
+ pagination: result.pagination,
520
+ hasMore: result.hasMore,
521
+ loadMore: result.loadMore,
522
+ refetch: result.refetch,
523
+ reset: result.reset,
524
+ setSearchFilter: result.setSearchFilter,
525
+ searchFilter: result.searchFilter
526
+ };
527
+ }
528
+
529
+ // src/hooks/accounts/useAccounts.ts
530
+ function transformAccount(account) {
531
+ const brands = account.brands || [];
532
+ return {
533
+ ...account,
534
+ brands,
535
+ brandCount: brands.length
536
+ };
537
+ }
538
+ var useAccountsInternal = createDataHook({
539
+ model: "Account",
540
+ dataPropertyName: "accounts",
541
+ // Include brands relationship for brand display
542
+ selectionSet: [
543
+ "id",
544
+ "name",
545
+ "logo",
546
+ "subscription",
547
+ "settings",
548
+ "status",
549
+ "deletedAt",
550
+ "deletedBy",
551
+ "brands.id",
552
+ "brands.name",
553
+ "brands.status"
554
+ ],
555
+ transform: transformAccount
556
+ });
557
+ function useAccounts(options = {}) {
558
+ const result = useAccountsInternal(options);
559
+ return {
560
+ accounts: result.accounts,
561
+ loading: result.loading,
562
+ error: result.error,
563
+ refetch: result.refetch
564
+ };
565
+ }
566
+
567
+ // src/hooks/accounts/usePaginatedAccounts.ts
568
+ function transformAccount2(account) {
569
+ const brands = account.brands || [];
570
+ return {
571
+ ...account,
572
+ brands,
573
+ brandCount: brands.length
574
+ };
575
+ }
576
+ var ACCOUNT_SELECTION_SET = [
577
+ "id",
578
+ "name",
579
+ "logo",
580
+ "subscription",
581
+ "settings",
582
+ "status",
583
+ "deletedAt",
584
+ "deletedBy",
585
+ "brands.id",
586
+ "brands.name",
587
+ "brands.status"
588
+ ];
589
+ var useActiveAccountsInternal = createPaginatedDataHook({
590
+ model: "Account",
591
+ dataPropertyName: "accounts",
592
+ defaultPageSize: 25,
593
+ selectionSet: ACCOUNT_SELECTION_SET,
594
+ transform: transformAccount2,
595
+ baseFilter: ACTIVE_FILTER
596
+ });
597
+ var useDeletedAccountsInternal = createPaginatedDataHook({
598
+ model: "Account",
599
+ dataPropertyName: "accounts",
600
+ defaultPageSize: 25,
601
+ selectionSet: ACCOUNT_SELECTION_SET,
602
+ transform: transformAccount2,
603
+ baseFilter: DELETED_FILTER
604
+ });
605
+ function useActiveAccounts(options = {}) {
606
+ const result = useActiveAccountsInternal(options);
607
+ return {
608
+ accounts: result.accounts,
609
+ loading: result.loading,
610
+ initialLoading: result.initialLoading,
611
+ loadingMore: result.loadingMore,
612
+ error: result.error,
613
+ pagination: result.pagination,
614
+ hasMore: result.hasMore,
615
+ loadMore: result.loadMore,
616
+ refetch: result.refetch,
617
+ reset: result.reset,
618
+ setSearchFilter: result.setSearchFilter,
619
+ searchFilter: result.searchFilter
620
+ };
621
+ }
622
+ function useDeletedAccounts(options = {}) {
623
+ const result = useDeletedAccountsInternal(options);
624
+ return {
625
+ accounts: result.accounts,
626
+ loading: result.loading,
627
+ initialLoading: result.initialLoading,
628
+ loadingMore: result.loadingMore,
629
+ error: result.error,
630
+ pagination: result.pagination,
631
+ hasMore: result.hasMore,
632
+ loadMore: result.loadMore,
633
+ refetch: result.refetch,
634
+ reset: result.reset,
635
+ setSearchFilter: result.setSearchFilter,
636
+ searchFilter: result.searchFilter
637
+ };
638
+ }
639
+
640
+ // src/hooks/reservations/useReservations.ts
641
+ function buildFilter5(options) {
642
+ const conditions = [];
643
+ if (options.brandId) {
644
+ conditions.push({ brandId: { eq: options.brandId } });
645
+ }
646
+ if (options.status) {
647
+ conditions.push({ status: { eq: options.status } });
648
+ }
649
+ if (options.contactId) {
650
+ conditions.push({ visitId: { eq: options.contactId } });
651
+ }
652
+ if (options.startDate) {
653
+ conditions.push({ checkIn: { ge: options.startDate } });
654
+ }
655
+ if (options.endDate) {
656
+ conditions.push({ checkIn: { le: options.endDate } });
657
+ }
658
+ if (options.filter) {
659
+ conditions.push(options.filter);
660
+ }
661
+ if (conditions.length === 0) {
662
+ return void 0;
663
+ }
664
+ if (conditions.length === 1) {
665
+ return conditions[0];
666
+ }
667
+ return { and: conditions };
668
+ }
669
+ function transformReservation(r) {
670
+ let snapshot = r.visit?.snapshot;
671
+ if (typeof snapshot === "string") {
672
+ try {
673
+ snapshot = JSON.parse(snapshot);
674
+ } catch {
675
+ snapshot = null;
676
+ }
677
+ }
678
+ return {
679
+ ...r,
680
+ brandName: r.brand?.name || "Unknown Brand",
681
+ guestName: snapshot ? `${snapshot.firstName || ""} ${snapshot.lastName || ""}`.trim() || "Unknown Guest" : "Unknown Guest",
682
+ guestEmail: snapshot?.email || "",
683
+ guestPhone: snapshot?.phone || ""
684
+ };
685
+ }
686
+ var useReservationsInternal = createDataHook({
687
+ model: "Reservation",
688
+ dataPropertyName: "reservations",
689
+ buildFilter: buildFilter5,
690
+ // Include related data for brand name and guest info
691
+ selectionSet: [
692
+ "id",
693
+ "brandId",
694
+ "visitId",
695
+ "checkIn",
696
+ "checkOut",
697
+ "room",
698
+ "roomType",
699
+ "status",
700
+ "source",
701
+ "channel",
702
+ "confirmationCode",
703
+ "totalAmount",
704
+ "currency",
705
+ "nights",
706
+ "deletedAt",
707
+ "deletedBy",
708
+ "brand.name",
709
+ "visit.snapshot"
710
+ ],
711
+ transform: transformReservation,
712
+ computedProperties: {
713
+ confirmedReservations: (reservations) => reservations.filter((r) => r.status === "confirmed"),
714
+ activeReservations: (reservations) => reservations.filter((r) => r.status === "confirmed" || r.status === "checked_in")
715
+ }
716
+ });
717
+ function useReservations(options = {}) {
718
+ const result = useReservationsInternal(options);
719
+ return {
720
+ reservations: result.reservations,
721
+ confirmedReservations: result.confirmedReservations,
722
+ activeReservations: result.activeReservations,
723
+ loading: result.loading,
724
+ error: result.error,
725
+ refetch: result.refetch
726
+ };
727
+ }
728
+
729
+ // src/hooks/reservations/usePaginatedReservations.ts
730
+ function buildFilter6(options) {
731
+ const conditions = [];
732
+ if (options.brandId) {
733
+ conditions.push({ brandId: { eq: options.brandId } });
734
+ }
735
+ if (options.status) {
736
+ conditions.push({ status: { eq: options.status } });
737
+ }
738
+ if (options.contactId) {
739
+ conditions.push({ visitId: { eq: options.contactId } });
740
+ }
741
+ if (options.startDate) {
742
+ conditions.push({ checkIn: { ge: options.startDate } });
743
+ }
744
+ if (options.endDate) {
745
+ conditions.push({ checkIn: { le: options.endDate } });
746
+ }
747
+ if (options.filter && Object.keys(options.filter).length > 0) {
748
+ conditions.push(options.filter);
749
+ }
750
+ if (conditions.length === 0) {
751
+ return void 0;
752
+ }
753
+ if (conditions.length === 1) {
754
+ return conditions[0];
755
+ }
756
+ return { and: conditions };
757
+ }
758
+ function transformReservation2(r) {
759
+ let snapshot = r.visit?.snapshot;
760
+ if (typeof snapshot === "string") {
761
+ try {
762
+ snapshot = JSON.parse(snapshot);
763
+ } catch {
764
+ snapshot = null;
765
+ }
766
+ }
767
+ return {
768
+ ...r,
769
+ brandName: r.brand?.name || "Unknown Brand",
770
+ guestName: snapshot ? `${snapshot.firstName || ""} ${snapshot.lastName || ""}`.trim() || "Unknown Guest" : "Unknown Guest",
771
+ guestEmail: snapshot?.email || "",
772
+ guestPhone: snapshot?.phone || ""
773
+ };
774
+ }
775
+ var RESERVATION_SELECTION_SET = [
776
+ "id",
777
+ "brandId",
778
+ "visitId",
779
+ "checkIn",
780
+ "checkOut",
781
+ "room",
782
+ "roomType",
783
+ "status",
784
+ "source",
785
+ "channel",
786
+ "confirmationCode",
787
+ "totalAmount",
788
+ "currency",
789
+ "nights",
790
+ "deletedAt",
791
+ "deletedBy",
792
+ "brand.name",
793
+ "visit.snapshot"
794
+ ];
795
+ var useActiveReservationsInternal = createPaginatedDataHook({
796
+ model: "Reservation",
797
+ dataPropertyName: "reservations",
798
+ defaultPageSize: 25,
799
+ selectionSet: RESERVATION_SELECTION_SET,
800
+ transform: transformReservation2,
801
+ buildFilter: buildFilter6,
802
+ baseFilter: ACTIVE_FILTER
803
+ });
804
+ var useDeletedReservationsInternal = createPaginatedDataHook({
805
+ model: "Reservation",
806
+ dataPropertyName: "reservations",
807
+ defaultPageSize: 25,
808
+ selectionSet: RESERVATION_SELECTION_SET,
809
+ transform: transformReservation2,
810
+ buildFilter: buildFilter6,
811
+ baseFilter: DELETED_FILTER
812
+ });
813
+ function useActiveReservations(options = {}) {
814
+ const result = useActiveReservationsInternal(options);
815
+ return {
816
+ reservations: result.reservations,
817
+ loading: result.loading,
818
+ initialLoading: result.initialLoading,
819
+ loadingMore: result.loadingMore,
820
+ error: result.error,
821
+ pagination: result.pagination,
822
+ hasMore: result.hasMore,
823
+ loadMore: result.loadMore,
824
+ refetch: result.refetch,
825
+ reset: result.reset,
826
+ setSearchFilter: result.setSearchFilter,
827
+ searchFilter: result.searchFilter
828
+ };
829
+ }
830
+ function useDeletedReservations(options = {}) {
831
+ const result = useDeletedReservationsInternal(options);
832
+ return {
833
+ reservations: result.reservations,
834
+ loading: result.loading,
835
+ initialLoading: result.initialLoading,
836
+ loadingMore: result.loadingMore,
837
+ error: result.error,
838
+ pagination: result.pagination,
839
+ hasMore: result.hasMore,
840
+ loadMore: result.loadMore,
841
+ refetch: result.refetch,
842
+ reset: result.reset,
843
+ setSearchFilter: result.setSearchFilter,
844
+ searchFilter: result.searchFilter
845
+ };
846
+ }
847
+
848
+ // src/hooks/products/useProducts.ts
849
+ function buildFilter7(options) {
202
850
  let filter = options.filter || {};
203
851
  if (options.activeOnly) {
204
852
  filter = { ...filter, isActive: { eq: true } };
@@ -208,7 +856,7 @@ function buildFilter3(options) {
208
856
  var useProductsInternal = createDataHook({
209
857
  model: "Product",
210
858
  dataPropertyName: "products",
211
- buildFilter: buildFilter3,
859
+ buildFilter: buildFilter7,
212
860
  computedProperties: {
213
861
  activeProducts: (products) => products.filter((p) => p.isActive === true)
214
862
  }
@@ -397,8 +1045,8 @@ async function toggleProductInstanceEnabled(client, id, enabled) {
397
1045
  }
398
1046
  }
399
1047
 
400
- // src/hooks/useProductInstances.ts
401
- function buildFilter4(options) {
1048
+ // src/hooks/productInstances/useProductInstances.ts
1049
+ function buildFilter8(options) {
402
1050
  let filter = options.filter || {};
403
1051
  if (options.brandId) {
404
1052
  filter = { ...filter, brandId: { eq: options.brandId } };
@@ -417,7 +1065,7 @@ function buildFilter4(options) {
417
1065
  var useProductInstancesInternal = createDataHook({
418
1066
  model: "ProductInstance",
419
1067
  dataPropertyName: "instances",
420
- buildFilter: buildFilter4,
1068
+ buildFilter: buildFilter8,
421
1069
  computedProperties: {
422
1070
  enabledInstances: (instances) => instances.filter((i) => i.enabled)
423
1071
  }
@@ -465,23 +1113,32 @@ function useProductInstances(options = {}) {
465
1113
  };
466
1114
  }
467
1115
 
468
- // src/hooks/useReservations.ts
469
- function buildFilter5(options) {
1116
+ // src/hooks/contacts/useContacts.ts
1117
+ function buildFilter9(options) {
470
1118
  const conditions = [];
471
1119
  if (options.brandId) {
472
1120
  conditions.push({ brandId: { eq: options.brandId } });
473
1121
  }
474
- if (options.status) {
475
- conditions.push({ status: { eq: options.status } });
1122
+ if (options.search) {
1123
+ conditions.push({
1124
+ or: [
1125
+ { email: { contains: options.search } },
1126
+ { firstName: { contains: options.search } },
1127
+ { lastName: { contains: options.search } }
1128
+ ]
1129
+ });
476
1130
  }
477
- if (options.contactId) {
478
- conditions.push({ visitId: { eq: options.contactId } });
1131
+ if (options.gdprConsent !== void 0) {
1132
+ conditions.push({ gdprConsent: { eq: options.gdprConsent } });
479
1133
  }
480
- if (options.startDate) {
481
- conditions.push({ checkIn: { ge: options.startDate } });
1134
+ if (options.marketingOptIn !== void 0) {
1135
+ conditions.push({ marketingOptIn: { eq: options.marketingOptIn } });
482
1136
  }
483
- if (options.endDate) {
484
- conditions.push({ checkIn: { le: options.endDate } });
1137
+ if (options.tags && options.tags.length > 0) {
1138
+ const tagConditions = options.tags.map((tag) => ({
1139
+ tags: { contains: tag }
1140
+ }));
1141
+ conditions.push({ or: tagConditions });
485
1142
  }
486
1143
  if (options.filter) {
487
1144
  conditions.push(options.filter);
@@ -494,33 +1151,36 @@ function buildFilter5(options) {
494
1151
  }
495
1152
  return { and: conditions };
496
1153
  }
497
- var useReservationsInternal = createDataHook({
498
- model: "Reservation",
499
- dataPropertyName: "reservations",
500
- buildFilter: buildFilter5,
1154
+ var useContactsInternal = createDataHook({
1155
+ model: "Contact",
1156
+ dataPropertyName: "contacts",
1157
+ buildFilter: buildFilter9,
501
1158
  computedProperties: {
502
- confirmedReservations: (reservations) => reservations.filter((r) => r.status === "confirmed"),
503
- activeReservations: (reservations) => reservations.filter((r) => r.status === "confirmed" || r.status === "checked_in")
1159
+ consentedContacts: (contacts) => contacts.filter((c) => c.gdprConsent === true),
1160
+ marketingContacts: (contacts) => contacts.filter((c) => c.marketingOptIn === true)
504
1161
  }
505
1162
  });
506
- function useReservations(options = {}) {
507
- const result = useReservationsInternal(options);
1163
+ function useContacts(options = {}) {
1164
+ const result = useContactsInternal(options);
508
1165
  return {
509
- reservations: result.reservations,
510
- confirmedReservations: result.confirmedReservations,
511
- activeReservations: result.activeReservations,
1166
+ contacts: result.contacts,
1167
+ consentedContacts: result.consentedContacts,
1168
+ marketingContacts: result.marketingContacts,
512
1169
  loading: result.loading,
513
1170
  error: result.error,
514
1171
  refetch: result.refetch
515
1172
  };
516
1173
  }
517
1174
 
518
- // src/hooks/useContacts.ts
519
- function buildFilter6(options) {
1175
+ // src/hooks/contacts/usePaginatedContacts.ts
1176
+ function buildFilter10(options) {
520
1177
  const conditions = [];
521
1178
  if (options.brandId) {
522
1179
  conditions.push({ brandId: { eq: options.brandId } });
523
1180
  }
1181
+ if (options.accountId) {
1182
+ conditions.push({ accountId: { eq: options.accountId } });
1183
+ }
524
1184
  if (options.search) {
525
1185
  conditions.push({
526
1186
  or: [
@@ -542,7 +1202,7 @@ function buildFilter6(options) {
542
1202
  }));
543
1203
  conditions.push({ or: tagConditions });
544
1204
  }
545
- if (options.filter) {
1205
+ if (options.filter && Object.keys(options.filter).length > 0) {
546
1206
  conditions.push(options.filter);
547
1207
  }
548
1208
  if (conditions.length === 0) {
@@ -553,32 +1213,109 @@ function buildFilter6(options) {
553
1213
  }
554
1214
  return { and: conditions };
555
1215
  }
556
- var useContactsInternal = createDataHook({
1216
+ function transformContact(contact) {
1217
+ return {
1218
+ ...contact,
1219
+ name: `${contact.firstName || ""} ${contact.lastName || ""}`.trim() || contact.email,
1220
+ brandName: contact.brand?.name || ""
1221
+ };
1222
+ }
1223
+ var CONTACT_SELECTION_SET = [
1224
+ "id",
1225
+ "email",
1226
+ "phone",
1227
+ "firstName",
1228
+ "lastName",
1229
+ "locale",
1230
+ "brandId",
1231
+ "accountId",
1232
+ "gdprConsent",
1233
+ "gdprConsentDate",
1234
+ "marketingOptIn",
1235
+ "preferences",
1236
+ "tags",
1237
+ "totalVisits",
1238
+ "lastVisitDate",
1239
+ "firstVisitDate",
1240
+ "source",
1241
+ "status",
1242
+ "createdAt",
1243
+ "updatedAt",
1244
+ "deletedAt",
1245
+ "deletedBy",
1246
+ "brand.name"
1247
+ ];
1248
+ var useActiveContactsInternal = createPaginatedDataHook({
557
1249
  model: "Contact",
558
1250
  dataPropertyName: "contacts",
559
- buildFilter: buildFilter6,
560
- computedProperties: {
561
- consentedContacts: (contacts) => contacts.filter((c) => c.gdprConsent === true),
562
- marketingContacts: (contacts) => contacts.filter((c) => c.marketingOptIn === true)
563
- }
1251
+ defaultPageSize: 25,
1252
+ selectionSet: CONTACT_SELECTION_SET,
1253
+ transform: transformContact,
1254
+ buildFilter: buildFilter10,
1255
+ baseFilter: ACTIVE_FILTER
564
1256
  });
565
- function useContacts(options = {}) {
566
- const result = useContactsInternal(options);
1257
+ var useDeletedContactsInternal = createPaginatedDataHook({
1258
+ model: "Contact",
1259
+ dataPropertyName: "contacts",
1260
+ defaultPageSize: 25,
1261
+ selectionSet: CONTACT_SELECTION_SET,
1262
+ transform: transformContact,
1263
+ buildFilter: buildFilter10,
1264
+ baseFilter: DELETED_FILTER
1265
+ });
1266
+ function useActiveContacts(options = {}) {
1267
+ const result = useActiveContactsInternal(options);
567
1268
  return {
568
1269
  contacts: result.contacts,
569
- consentedContacts: result.consentedContacts,
570
- marketingContacts: result.marketingContacts,
571
1270
  loading: result.loading,
1271
+ initialLoading: result.initialLoading,
1272
+ loadingMore: result.loadingMore,
572
1273
  error: result.error,
573
- refetch: result.refetch
1274
+ pagination: result.pagination,
1275
+ hasMore: result.hasMore,
1276
+ loadMore: result.loadMore,
1277
+ refetch: result.refetch,
1278
+ reset: result.reset,
1279
+ setSearchFilter: result.setSearchFilter,
1280
+ searchFilter: result.searchFilter
1281
+ };
1282
+ }
1283
+ function useDeletedContacts(options = {}) {
1284
+ const result = useDeletedContactsInternal(options);
1285
+ return {
1286
+ contacts: result.contacts,
1287
+ loading: result.loading,
1288
+ initialLoading: result.initialLoading,
1289
+ loadingMore: result.loadingMore,
1290
+ error: result.error,
1291
+ pagination: result.pagination,
1292
+ hasMore: result.hasMore,
1293
+ loadMore: result.loadMore,
1294
+ refetch: result.refetch,
1295
+ reset: result.reset,
1296
+ setSearchFilter: result.setSearchFilter,
1297
+ searchFilter: result.searchFilter
574
1298
  };
575
1299
  }
576
1300
  export {
1301
+ ACTIVE_FILTER,
1302
+ DELETED_FILTER,
577
1303
  createDataHook,
1304
+ createPaginatedDataHook,
578
1305
  resetClientInstance,
579
1306
  useAccounts,
1307
+ useActiveAccounts,
1308
+ useActiveBrands,
1309
+ useActiveContacts,
1310
+ useActiveReservations,
1311
+ useActiveUsers,
580
1312
  useBrands,
581
1313
  useContacts,
1314
+ useDeletedAccounts,
1315
+ useDeletedBrands,
1316
+ useDeletedContacts,
1317
+ useDeletedReservations,
1318
+ useDeletedUsers,
582
1319
  useProductInstances,
583
1320
  useProducts,
584
1321
  useReservations,