@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.
Files changed (39) hide show
  1. package/dist/client/index.d.ts +257 -1
  2. package/dist/client/index.js +59 -1
  3. package/dist/client/index.js.map +1 -1
  4. package/dist/common-DSxswsZ3.d.ts +40 -0
  5. package/dist/hooks/index.d.ts +162 -10
  6. package/dist/hooks/index.js +191 -33
  7. package/dist/hooks/index.js.map +1 -1
  8. package/dist/index.d.ts +9 -5
  9. package/dist/index.js +789 -13
  10. package/dist/index.js.map +1 -1
  11. package/dist/mutations/index.d.ts +342 -4
  12. package/dist/mutations/index.js +486 -0
  13. package/dist/mutations/index.js.map +1 -1
  14. package/dist/{productInstances-BA3cNsYc.d.ts → productInstances-BpQv1oLS.d.ts} +2 -40
  15. package/dist/queries/index.d.ts +113 -2
  16. package/dist/queries/index.js +192 -1
  17. package/dist/queries/index.js.map +1 -1
  18. package/dist/reservations-C0FNm__0.d.ts +154 -0
  19. package/dist/reservations-CdDfkcZ_.d.ts +172 -0
  20. package/package.json +14 -13
  21. package/src/client/index.ts +18 -0
  22. package/src/client/reservations.ts +336 -0
  23. package/src/hooks/createDataHook.test.ts +534 -0
  24. package/src/hooks/createDataHook.ts +20 -13
  25. package/src/hooks/index.ts +2 -0
  26. package/src/hooks/useContacts.test.ts +159 -0
  27. package/src/hooks/useContacts.ts +176 -0
  28. package/src/hooks/useReservations.ts +145 -0
  29. package/src/mutations/contacts.test.ts +604 -0
  30. package/src/mutations/contacts.ts +554 -0
  31. package/src/mutations/index.ts +32 -0
  32. package/src/mutations/productInstances/productInstances.test.ts +3 -3
  33. package/src/mutations/reservations.test.ts +459 -0
  34. package/src/mutations/reservations.ts +452 -0
  35. package/src/queries/contacts.test.ts +505 -0
  36. package/src/queries/contacts.ts +237 -0
  37. package/src/queries/index.ts +21 -0
  38. package/src/queries/reservations.test.ts +374 -0
  39. package/src/queries/reservations.ts +247 -0
@@ -0,0 +1,159 @@
1
+ /**
2
+ * useContacts Hook Tests
3
+ *
4
+ * Tests for the useContacts Vue composable including structure validation,
5
+ * computed properties, and filter building.
6
+ */
7
+
8
+ import { describe, it, expect } from "vitest";
9
+ import { useContacts } from "./useContacts";
10
+
11
+ describe("useContacts Hook", () => {
12
+ describe("structure", () => {
13
+ it("should be a function", () => {
14
+ expect(typeof useContacts).toBe("function");
15
+ });
16
+
17
+ it("should return expected properties", () => {
18
+ const result = useContacts({ autoFetch: false });
19
+
20
+ expect(result).toHaveProperty("contacts");
21
+ expect(result).toHaveProperty("consentedContacts");
22
+ expect(result).toHaveProperty("marketingContacts");
23
+ expect(result).toHaveProperty("loading");
24
+ expect(result).toHaveProperty("error");
25
+ expect(result).toHaveProperty("refetch");
26
+ expect(typeof result.refetch).toBe("function");
27
+ });
28
+ });
29
+
30
+ describe("initial state", () => {
31
+ it("should have empty contacts array initially", () => {
32
+ const result = useContacts({ autoFetch: false });
33
+
34
+ expect(result.contacts.value).toEqual([]);
35
+ });
36
+
37
+ it("should have loading as false when autoFetch is disabled", () => {
38
+ const result = useContacts({ autoFetch: false });
39
+
40
+ expect(result.loading.value).toBe(false);
41
+ });
42
+
43
+ it("should have error as null initially", () => {
44
+ const result = useContacts({ autoFetch: false });
45
+
46
+ expect(result.error.value).toBeNull();
47
+ });
48
+ });
49
+
50
+ describe("computed properties", () => {
51
+ it("should have consentedContacts computed property", () => {
52
+ const result = useContacts({ autoFetch: false });
53
+
54
+ expect(result.consentedContacts).toBeDefined();
55
+ expect(result.consentedContacts.value).toEqual([]);
56
+ });
57
+
58
+ it("should have marketingContacts computed property", () => {
59
+ const result = useContacts({ autoFetch: false });
60
+
61
+ expect(result.marketingContacts).toBeDefined();
62
+ expect(result.marketingContacts.value).toEqual([]);
63
+ });
64
+ });
65
+
66
+ describe("options", () => {
67
+ it("should accept brandId option", () => {
68
+ const result = useContacts({
69
+ brandId: "brand-123",
70
+ autoFetch: false,
71
+ });
72
+
73
+ expect(result).toBeDefined();
74
+ });
75
+
76
+ it("should accept search option", () => {
77
+ const result = useContacts({
78
+ search: "john",
79
+ autoFetch: false,
80
+ });
81
+
82
+ expect(result).toBeDefined();
83
+ });
84
+
85
+ it("should accept gdprConsent option", () => {
86
+ const result = useContacts({
87
+ gdprConsent: true,
88
+ autoFetch: false,
89
+ });
90
+
91
+ expect(result).toBeDefined();
92
+ });
93
+
94
+ it("should accept marketingOptIn option", () => {
95
+ const result = useContacts({
96
+ marketingOptIn: true,
97
+ autoFetch: false,
98
+ });
99
+
100
+ expect(result).toBeDefined();
101
+ });
102
+
103
+ it("should accept tags option", () => {
104
+ const result = useContacts({
105
+ tags: ["vip", "returning"],
106
+ autoFetch: false,
107
+ });
108
+
109
+ expect(result).toBeDefined();
110
+ });
111
+
112
+ it("should accept limit option", () => {
113
+ const result = useContacts({
114
+ limit: 50,
115
+ autoFetch: false,
116
+ });
117
+
118
+ expect(result).toBeDefined();
119
+ });
120
+
121
+ it("should accept nextToken option", () => {
122
+ const result = useContacts({
123
+ nextToken: "token-123",
124
+ autoFetch: false,
125
+ });
126
+
127
+ expect(result).toBeDefined();
128
+ });
129
+
130
+ it("should accept combined filter options", () => {
131
+ const result = useContacts({
132
+ brandId: "brand-123",
133
+ search: "john",
134
+ gdprConsent: true,
135
+ marketingOptIn: true,
136
+ tags: ["vip"],
137
+ limit: 25,
138
+ autoFetch: false,
139
+ });
140
+
141
+ expect(result).toBeDefined();
142
+ });
143
+ });
144
+
145
+ describe("refetch function", () => {
146
+ it("should be callable", () => {
147
+ const result = useContacts({ autoFetch: false });
148
+
149
+ expect(() => result.refetch()).not.toThrow();
150
+ });
151
+
152
+ it("should return a Promise", () => {
153
+ const result = useContacts({ autoFetch: false });
154
+
155
+ const refetchResult = result.refetch();
156
+ expect(refetchResult).toBeInstanceOf(Promise);
157
+ });
158
+ });
159
+ });
@@ -0,0 +1,176 @@
1
+ /**
2
+ * useContacts Hook
3
+ *
4
+ * Vue composable for fetching and managing contact data with reactive state.
5
+ * Provides loading states, error handling, search, pagination, and refetch capabilities.
6
+ */
7
+
8
+ import type { Ref, ComputedRef } from "vue";
9
+ import type { Contact } from "@htlkg/core/types";
10
+ import { createDataHook, type BaseHookOptions } from "./createDataHook";
11
+
12
+ export interface UseContactsOptions extends BaseHookOptions {
13
+ /** Filter by brand ID */
14
+ brandId?: string;
15
+ /** Search query (searches email, firstName, lastName) */
16
+ search?: string;
17
+ /** Filter by GDPR consent */
18
+ gdprConsent?: boolean;
19
+ /** Filter by marketing opt-in */
20
+ marketingOptIn?: boolean;
21
+ /** Filter by tags (contact must have at least one of these tags) */
22
+ tags?: string[];
23
+ /** Pagination token for fetching next page */
24
+ nextToken?: string;
25
+ }
26
+
27
+ export interface UseContactsReturn {
28
+ /** Reactive array of contacts */
29
+ contacts: Ref<Contact[]>;
30
+ /** Computed array of contacts with GDPR consent */
31
+ consentedContacts: ComputedRef<Contact[]>;
32
+ /** Computed array of contacts opted-in for marketing */
33
+ marketingContacts: ComputedRef<Contact[]>;
34
+ /** Loading state */
35
+ loading: Ref<boolean>;
36
+ /** Error state */
37
+ error: Ref<Error | null>;
38
+ /** Refetch contacts */
39
+ refetch: () => Promise<void>;
40
+ }
41
+
42
+ /**
43
+ * Build filter from hook options
44
+ */
45
+ function buildFilter(options: UseContactsOptions): any {
46
+ const conditions: any[] = [];
47
+
48
+ // Filter by brand
49
+ if (options.brandId) {
50
+ conditions.push({ brandId: { eq: options.brandId } });
51
+ }
52
+
53
+ // Search across email, firstName, lastName
54
+ if (options.search) {
55
+ conditions.push({
56
+ or: [
57
+ { email: { contains: options.search } },
58
+ { firstName: { contains: options.search } },
59
+ { lastName: { contains: options.search } },
60
+ ],
61
+ });
62
+ }
63
+
64
+ // Filter by GDPR consent
65
+ if (options.gdprConsent !== undefined) {
66
+ conditions.push({ gdprConsent: { eq: options.gdprConsent } });
67
+ }
68
+
69
+ // Filter by marketing opt-in
70
+ if (options.marketingOptIn !== undefined) {
71
+ conditions.push({ marketingOptIn: { eq: options.marketingOptIn } });
72
+ }
73
+
74
+ // Filter by tags (contact must have at least one of these tags)
75
+ if (options.tags && options.tags.length > 0) {
76
+ const tagConditions = options.tags.map((tag) => ({
77
+ tags: { contains: tag },
78
+ }));
79
+ conditions.push({ or: tagConditions });
80
+ }
81
+
82
+ // Include any additional custom filter
83
+ if (options.filter) {
84
+ conditions.push(options.filter);
85
+ }
86
+
87
+ if (conditions.length === 0) {
88
+ return undefined;
89
+ }
90
+
91
+ if (conditions.length === 1) {
92
+ return conditions[0];
93
+ }
94
+
95
+ return { and: conditions };
96
+ }
97
+
98
+ /**
99
+ * Internal hook created by factory
100
+ */
101
+ const useContactsInternal = createDataHook<
102
+ Contact,
103
+ UseContactsOptions,
104
+ { consentedContacts: Contact[]; marketingContacts: Contact[] }
105
+ >({
106
+ model: "Contact",
107
+ dataPropertyName: "contacts",
108
+ buildFilter,
109
+ computedProperties: {
110
+ consentedContacts: (contacts) =>
111
+ contacts.filter((c) => c.gdprConsent === true),
112
+ marketingContacts: (contacts) =>
113
+ contacts.filter((c) => c.marketingOptIn === true),
114
+ },
115
+ });
116
+
117
+ /**
118
+ * Composable for fetching and managing contacts
119
+ *
120
+ * @example
121
+ * ```typescript
122
+ * import { useContacts } from '@htlkg/data/hooks';
123
+ *
124
+ * const { contacts, loading, error, refetch } = useContacts({
125
+ * brandId: 'brand-123',
126
+ * limit: 25
127
+ * });
128
+ * ```
129
+ *
130
+ * @example With search
131
+ * ```typescript
132
+ * const { contacts, loading } = useContacts({
133
+ * brandId: 'brand-123',
134
+ * search: 'john',
135
+ * limit: 25
136
+ * });
137
+ * ```
138
+ *
139
+ * @example With GDPR and marketing filters
140
+ * ```typescript
141
+ * const { contacts, marketingContacts } = useContacts({
142
+ * brandId: 'brand-123',
143
+ * gdprConsent: true,
144
+ * marketingOptIn: true
145
+ * });
146
+ * ```
147
+ *
148
+ * @example With computed properties
149
+ * ```typescript
150
+ * const { contacts, consentedContacts, marketingContacts } = useContacts({
151
+ * brandId: 'brand-123'
152
+ * });
153
+ *
154
+ * // consentedContacts - contacts with GDPR consent
155
+ * // marketingContacts - contacts opted-in for marketing
156
+ * ```
157
+ *
158
+ * @example With tag filtering
159
+ * ```typescript
160
+ * const { contacts } = useContacts({
161
+ * brandId: 'brand-123',
162
+ * tags: ['vip', 'returning']
163
+ * });
164
+ * ```
165
+ */
166
+ export function useContacts(options: UseContactsOptions = {}): UseContactsReturn {
167
+ const result = useContactsInternal(options);
168
+ return {
169
+ contacts: result.contacts as Ref<Contact[]>,
170
+ consentedContacts: result.consentedContacts as ComputedRef<Contact[]>,
171
+ marketingContacts: result.marketingContacts as ComputedRef<Contact[]>,
172
+ loading: result.loading,
173
+ error: result.error,
174
+ refetch: result.refetch,
175
+ };
176
+ }
@@ -0,0 +1,145 @@
1
+ /**
2
+ * useReservations Hook
3
+ *
4
+ * Vue composable for fetching and managing reservation data with reactive state.
5
+ * Provides loading states, error handling, pagination, and refetch capabilities.
6
+ */
7
+
8
+ import type { Ref, ComputedRef } from "vue";
9
+ import type { Reservation } from "../queries/reservations";
10
+ import { createDataHook, type BaseHookOptions } from "./createDataHook";
11
+
12
+ export interface UseReservationsOptions extends BaseHookOptions {
13
+ /** Filter by brand ID */
14
+ brandId?: string;
15
+ /** Filter by start date (check-in date >= startDate) */
16
+ startDate?: string;
17
+ /** Filter by end date (check-in date <= endDate) */
18
+ endDate?: string;
19
+ /** Filter by reservation status */
20
+ status?: Reservation["status"];
21
+ /** Filter by contact/visit ID */
22
+ contactId?: string;
23
+ /** Pagination token for fetching next page */
24
+ nextToken?: string;
25
+ }
26
+
27
+ export interface UseReservationsReturn {
28
+ /** Reactive array of reservations */
29
+ reservations: Ref<Reservation[]>;
30
+ /** Computed array of confirmed reservations */
31
+ confirmedReservations: ComputedRef<Reservation[]>;
32
+ /** Computed array of active reservations (confirmed or checked_in) */
33
+ activeReservations: ComputedRef<Reservation[]>;
34
+ /** Loading state */
35
+ loading: Ref<boolean>;
36
+ /** Error state */
37
+ error: Ref<Error | null>;
38
+ /** Refetch reservations */
39
+ refetch: () => Promise<void>;
40
+ }
41
+
42
+ /**
43
+ * Build filter from hook options
44
+ */
45
+ function buildFilter(options: UseReservationsOptions): any {
46
+ const conditions: any[] = [];
47
+
48
+ if (options.brandId) {
49
+ conditions.push({ brandId: { eq: options.brandId } });
50
+ }
51
+
52
+ if (options.status) {
53
+ conditions.push({ status: { eq: options.status } });
54
+ }
55
+
56
+ if (options.contactId) {
57
+ conditions.push({ visitId: { eq: options.contactId } });
58
+ }
59
+
60
+ if (options.startDate) {
61
+ conditions.push({ checkIn: { ge: options.startDate } });
62
+ }
63
+
64
+ if (options.endDate) {
65
+ conditions.push({ checkIn: { le: options.endDate } });
66
+ }
67
+
68
+ if (options.filter) {
69
+ conditions.push(options.filter);
70
+ }
71
+
72
+ if (conditions.length === 0) {
73
+ return undefined;
74
+ }
75
+
76
+ if (conditions.length === 1) {
77
+ return conditions[0];
78
+ }
79
+
80
+ return { and: conditions };
81
+ }
82
+
83
+ /**
84
+ * Internal hook created by factory
85
+ */
86
+ const useReservationsInternal = createDataHook<
87
+ Reservation,
88
+ UseReservationsOptions,
89
+ { confirmedReservations: Reservation[]; activeReservations: Reservation[] }
90
+ >({
91
+ model: "Reservation",
92
+ dataPropertyName: "reservations",
93
+ buildFilter,
94
+ computedProperties: {
95
+ confirmedReservations: (reservations) =>
96
+ reservations.filter((r) => r.status === "confirmed"),
97
+ activeReservations: (reservations) =>
98
+ reservations.filter((r) => r.status === "confirmed" || r.status === "checked_in"),
99
+ },
100
+ });
101
+
102
+ /**
103
+ * Composable for fetching and managing reservations
104
+ *
105
+ * @example
106
+ * ```typescript
107
+ * import { useReservations } from '@htlkg/data/hooks';
108
+ *
109
+ * const { reservations, loading, error, refetch } = useReservations({
110
+ * brandId: 'brand-123',
111
+ * startDate: '2026-01-01',
112
+ * endDate: '2026-01-31',
113
+ * status: 'confirmed'
114
+ * });
115
+ * ```
116
+ *
117
+ * @example With contact filter
118
+ * ```typescript
119
+ * const { reservations, loading } = useReservations({
120
+ * contactId: 'contact-123',
121
+ * limit: 50
122
+ * });
123
+ * ```
124
+ *
125
+ * @example With computed properties
126
+ * ```typescript
127
+ * const { reservations, activeReservations, confirmedReservations } = useReservations({
128
+ * brandId: 'brand-123'
129
+ * });
130
+ *
131
+ * // activeReservations includes confirmed + checked_in
132
+ * // confirmedReservations includes only confirmed
133
+ * ```
134
+ */
135
+ export function useReservations(options: UseReservationsOptions = {}): UseReservationsReturn {
136
+ const result = useReservationsInternal(options);
137
+ return {
138
+ reservations: result.reservations as Ref<Reservation[]>,
139
+ confirmedReservations: result.confirmedReservations as ComputedRef<Reservation[]>,
140
+ activeReservations: result.activeReservations as ComputedRef<Reservation[]>,
141
+ loading: result.loading,
142
+ error: result.error,
143
+ refetch: result.refetch,
144
+ };
145
+ }