@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,247 @@
1
+ /**
2
+ * Reservation Query Functions
3
+ *
4
+ * Provides query functions for fetching reservation data from the GraphQL API.
5
+ */
6
+
7
+ /**
8
+ * Reservation type for query results
9
+ */
10
+ export interface Reservation {
11
+ id: string;
12
+ brandId: string;
13
+ visitId: string;
14
+ confirmationCode: string;
15
+ checkIn: string;
16
+ checkOut: string;
17
+ status: "confirmed" | "checked_in" | "checked_out" | "cancelled" | "no_show";
18
+ source?: string;
19
+ channel?: string;
20
+ roomType?: string;
21
+ room?: string;
22
+ totalAmount?: number;
23
+ currency?: string;
24
+ nights?: number;
25
+ createdAt?: string;
26
+ createdBy?: string;
27
+ updatedAt?: string;
28
+ updatedBy?: string;
29
+ deletedAt?: string | null;
30
+ deletedBy?: string | null;
31
+ }
32
+
33
+ /**
34
+ * Get a single reservation by ID
35
+ *
36
+ * @example
37
+ * ```typescript
38
+ * import { getReservation } from '@htlkg/data/queries';
39
+ * import { generateClient } from '@htlkg/data/client';
40
+ *
41
+ * const client = generateClient<Schema>();
42
+ * const reservation = await getReservation(client, 'reservation-123');
43
+ * ```
44
+ */
45
+ export async function getReservation<TClient = any>(
46
+ client: TClient,
47
+ id: string,
48
+ ): Promise<Reservation | null> {
49
+ try {
50
+ const { data, errors } = await (client as any).models.Reservation.get({ id });
51
+
52
+ if (errors) {
53
+ console.error("[getReservation] GraphQL errors:", errors);
54
+ return null;
55
+ }
56
+
57
+ return data as Reservation;
58
+ } catch (error) {
59
+ console.error("[getReservation] Error fetching reservation:", error);
60
+ throw error;
61
+ }
62
+ }
63
+
64
+ /**
65
+ * List all reservations with optional filtering and pagination
66
+ *
67
+ * @example
68
+ * ```typescript
69
+ * import { listReservations } from '@htlkg/data/queries';
70
+ * import { generateClient } from '@htlkg/data/client';
71
+ *
72
+ * const client = generateClient<Schema>();
73
+ * const reservations = await listReservations(client, {
74
+ * filter: { status: { eq: 'confirmed' } },
75
+ * limit: 50
76
+ * });
77
+ * ```
78
+ */
79
+ export async function listReservations<TClient = any>(
80
+ client: TClient,
81
+ options?: {
82
+ filter?: any;
83
+ limit?: number;
84
+ nextToken?: string;
85
+ },
86
+ ): Promise<{ items: Reservation[]; nextToken?: string }> {
87
+ try {
88
+ const { data, errors, nextToken } = await (client as any).models.Reservation.list(
89
+ options,
90
+ );
91
+
92
+ if (errors) {
93
+ console.error("[listReservations] GraphQL errors:", errors);
94
+ return { items: [], nextToken: undefined };
95
+ }
96
+
97
+ return {
98
+ items: (data || []) as Reservation[],
99
+ nextToken,
100
+ };
101
+ } catch (error) {
102
+ console.error("[listReservations] Error fetching reservations:", error);
103
+ throw error;
104
+ }
105
+ }
106
+
107
+ /**
108
+ * List reservations by brand ID
109
+ *
110
+ * @example
111
+ * ```typescript
112
+ * import { listReservationsByBrand } from '@htlkg/data/queries';
113
+ * import { generateClient } from '@htlkg/data/client';
114
+ *
115
+ * const client = generateClient<Schema>();
116
+ * const reservations = await listReservationsByBrand(client, 'brand-123', {
117
+ * limit: 100
118
+ * });
119
+ * ```
120
+ */
121
+ export async function listReservationsByBrand<TClient = any>(
122
+ client: TClient,
123
+ brandId: string,
124
+ options?: {
125
+ filter?: any;
126
+ limit?: number;
127
+ nextToken?: string;
128
+ },
129
+ ): Promise<{ items: Reservation[]; nextToken?: string }> {
130
+ const filter = options?.filter
131
+ ? { and: [{ brandId: { eq: brandId } }, options.filter] }
132
+ : { brandId: { eq: brandId } };
133
+
134
+ return listReservations(client, {
135
+ filter,
136
+ limit: options?.limit,
137
+ nextToken: options?.nextToken,
138
+ });
139
+ }
140
+
141
+ /**
142
+ * List reservations by contact/visit ID
143
+ *
144
+ * @example
145
+ * ```typescript
146
+ * import { listReservationsByContact } from '@htlkg/data/queries';
147
+ * import { generateClient } from '@htlkg/data/client';
148
+ *
149
+ * const client = generateClient<Schema>();
150
+ * const reservations = await listReservationsByContact(client, 'contact-123');
151
+ * ```
152
+ */
153
+ export async function listReservationsByContact<TClient = any>(
154
+ client: TClient,
155
+ contactId: string,
156
+ options?: {
157
+ limit?: number;
158
+ nextToken?: string;
159
+ },
160
+ ): Promise<{ items: Reservation[]; nextToken?: string }> {
161
+ return listReservations(client, {
162
+ filter: { visitId: { eq: contactId } },
163
+ ...options,
164
+ });
165
+ }
166
+
167
+ /**
168
+ * List reservations by date range for a specific brand
169
+ *
170
+ * Filters reservations where check-in date falls within the specified range.
171
+ *
172
+ * @example
173
+ * ```typescript
174
+ * import { listReservationsByDateRange } from '@htlkg/data/queries';
175
+ * import { generateClient } from '@htlkg/data/client';
176
+ *
177
+ * const client = generateClient<Schema>();
178
+ * const reservations = await listReservationsByDateRange(
179
+ * client,
180
+ * 'brand-123',
181
+ * '2024-01-01',
182
+ * '2024-01-31'
183
+ * );
184
+ * ```
185
+ */
186
+ export async function listReservationsByDateRange<TClient = any>(
187
+ client: TClient,
188
+ brandId: string,
189
+ startDate: string,
190
+ endDate: string,
191
+ options?: {
192
+ limit?: number;
193
+ nextToken?: string;
194
+ },
195
+ ): Promise<{ items: Reservation[]; nextToken?: string }> {
196
+ return listReservations(client, {
197
+ filter: {
198
+ and: [
199
+ { brandId: { eq: brandId } },
200
+ { checkIn: { ge: startDate } },
201
+ { checkIn: { le: endDate } },
202
+ ],
203
+ },
204
+ ...options,
205
+ });
206
+ }
207
+
208
+ /**
209
+ * Get a reservation by confirmation code and brand ID
210
+ *
211
+ * Returns the first matching reservation or null if not found.
212
+ *
213
+ * @example
214
+ * ```typescript
215
+ * import { getReservationByConfirmation } from '@htlkg/data/queries';
216
+ * import { generateClient } from '@htlkg/data/client';
217
+ *
218
+ * const client = generateClient<Schema>();
219
+ * const reservation = await getReservationByConfirmation(
220
+ * client,
221
+ * 'ABC123',
222
+ * 'brand-123'
223
+ * );
224
+ * ```
225
+ */
226
+ export async function getReservationByConfirmation<TClient = any>(
227
+ client: TClient,
228
+ confirmationCode: string,
229
+ brandId: string,
230
+ ): Promise<Reservation | null> {
231
+ try {
232
+ const { items } = await listReservations(client, {
233
+ filter: {
234
+ and: [
235
+ { confirmationCode: { eq: confirmationCode } },
236
+ { brandId: { eq: brandId } },
237
+ ],
238
+ },
239
+ limit: 1,
240
+ });
241
+
242
+ return items.length > 0 ? items[0] : null;
243
+ } catch (error) {
244
+ console.error("[getReservationByConfirmation] Error fetching reservation:", error);
245
+ throw error;
246
+ }
247
+ }