@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,172 @@
1
+ import { C as CreateAuditFields, a as UpdateWithSoftDeleteFields } from './common-DSxswsZ3.js';
2
+
3
+ /**
4
+ * Reservation Mutation Functions
5
+ *
6
+ * Provides type-safe mutation functions for creating, updating, and deleting reservations.
7
+ * Includes date validation and status transition rules.
8
+ */
9
+
10
+ /**
11
+ * Reservation status type
12
+ */
13
+ type ReservationStatus = "confirmed" | "checked_in" | "checked_out" | "cancelled" | "no_show";
14
+ /**
15
+ * Validation error class for reservation operations
16
+ */
17
+ declare class ReservationValidationError extends Error {
18
+ constructor(message: string);
19
+ }
20
+ /**
21
+ * Input type for creating a reservation
22
+ */
23
+ interface CreateReservationInput extends CreateAuditFields {
24
+ brandId: string;
25
+ visitId: string;
26
+ confirmationCode: string;
27
+ checkIn: string;
28
+ checkOut: string;
29
+ status?: "confirmed" | "checked_in" | "checked_out" | "cancelled" | "no_show";
30
+ source?: string;
31
+ channel?: string;
32
+ roomType?: string;
33
+ room?: string;
34
+ totalAmount?: number;
35
+ currency?: string;
36
+ nights?: number;
37
+ }
38
+ /**
39
+ * Input type for updating a reservation
40
+ */
41
+ interface UpdateReservationInput extends UpdateWithSoftDeleteFields {
42
+ id: string;
43
+ brandId?: string;
44
+ visitId?: string;
45
+ confirmationCode?: string;
46
+ checkIn?: string;
47
+ checkOut?: string;
48
+ status?: "confirmed" | "checked_in" | "checked_out" | "cancelled" | "no_show";
49
+ source?: string;
50
+ channel?: string;
51
+ roomType?: string;
52
+ room?: string;
53
+ totalAmount?: number;
54
+ currency?: string;
55
+ nights?: number;
56
+ }
57
+ /**
58
+ * Create a new reservation with date validation
59
+ *
60
+ * @throws {ReservationValidationError} if dates are invalid
61
+ *
62
+ * @example
63
+ * ```typescript
64
+ * import { createReservation } from '@htlkg/data/mutations';
65
+ * import { generateClient } from '@htlkg/data/client';
66
+ *
67
+ * const client = generateClient<Schema>();
68
+ * const reservation = await createReservation(client, {
69
+ * brandId: 'brand-123',
70
+ * visitId: 'visit-456',
71
+ * confirmationCode: 'ABC123',
72
+ * checkIn: '2024-01-01',
73
+ * checkOut: '2024-01-05',
74
+ * status: 'confirmed'
75
+ * });
76
+ * ```
77
+ */
78
+ declare function createReservation<TClient = any>(client: TClient, input: CreateReservationInput): Promise<any | null>;
79
+ /**
80
+ * Update an existing reservation with validation
81
+ *
82
+ * @throws {ReservationValidationError} if dates or status transition is invalid
83
+ *
84
+ * @example
85
+ * ```typescript
86
+ * import { updateReservation } from '@htlkg/data/mutations';
87
+ * import { generateClient } from '@htlkg/data/client';
88
+ *
89
+ * const client = generateClient<Schema>();
90
+ * const reservation = await updateReservation(client, {
91
+ * id: 'reservation-123',
92
+ * status: 'checked_in',
93
+ * room: '201'
94
+ * });
95
+ * ```
96
+ */
97
+ declare function updateReservation<TClient = any>(client: TClient, input: UpdateReservationInput): Promise<any | null>;
98
+ /**
99
+ * Soft delete a reservation (sets deletedAt/deletedBy instead of removing)
100
+ *
101
+ * @example
102
+ * ```typescript
103
+ * import { softDeleteReservation } from '@htlkg/data/mutations';
104
+ * import { generateClient } from '@htlkg/data/client';
105
+ *
106
+ * const client = generateClient<Schema>();
107
+ * await softDeleteReservation(client, 'reservation-123', 'admin@example.com');
108
+ * ```
109
+ */
110
+ declare function softDeleteReservation<TClient = any>(client: TClient, id: string, deletedBy: string): Promise<boolean>;
111
+ /**
112
+ * Restore a soft-deleted reservation
113
+ * Checks retention period before allowing restoration
114
+ *
115
+ * @example
116
+ * ```typescript
117
+ * import { restoreReservation } from '@htlkg/data/mutations';
118
+ * import { generateClient } from '@htlkg/data/client';
119
+ *
120
+ * const client = generateClient<Schema>();
121
+ * await restoreReservation(client, 'reservation-123');
122
+ * // Or with custom retention days:
123
+ * await restoreReservation(client, 'reservation-123', 60);
124
+ * ```
125
+ */
126
+ declare function restoreReservation<TClient = any>(client: TClient, id: string, retentionDays?: number): Promise<{
127
+ success: boolean;
128
+ error?: string;
129
+ }>;
130
+ /**
131
+ * Hard delete a reservation (permanently removes from database)
132
+ * Use with caution - prefer softDeleteReservation for recoverable deletion
133
+ *
134
+ * @example
135
+ * ```typescript
136
+ * import { deleteReservation } from '@htlkg/data/mutations';
137
+ * import { generateClient } from '@htlkg/data/client';
138
+ *
139
+ * const client = generateClient<Schema>();
140
+ * await deleteReservation(client, 'reservation-123');
141
+ * ```
142
+ */
143
+ declare function deleteReservation<TClient = any>(client: TClient, id: string): Promise<boolean>;
144
+ /**
145
+ * Update reservation status with validation
146
+ *
147
+ * Validates that the status transition is allowed based on current status.
148
+ * Status transition rules:
149
+ * - confirmed → checked_in, cancelled, no_show
150
+ * - checked_in → checked_out, cancelled
151
+ * - checked_out → (terminal state, no transitions)
152
+ * - cancelled → (terminal state, no transitions)
153
+ * - no_show → (terminal state, no transitions)
154
+ *
155
+ * @throws {ReservationValidationError} if status transition is invalid
156
+ *
157
+ * @example
158
+ * ```typescript
159
+ * import { updateReservationStatus } from '@htlkg/data/mutations';
160
+ * import { generateClient } from '@htlkg/data/client';
161
+ *
162
+ * const client = generateClient<Schema>();
163
+ * const reservation = await updateReservationStatus(
164
+ * client,
165
+ * 'reservation-123',
166
+ * 'checked_in'
167
+ * );
168
+ * ```
169
+ */
170
+ declare function updateReservationStatus<TClient = any>(client: TClient, id: string, newStatus: ReservationStatus): Promise<any | null>;
171
+
172
+ export { type CreateReservationInput as C, ReservationValidationError as R, type UpdateReservationInput as U, updateReservationStatus as a, type ReservationStatus as b, createReservation as c, deleteReservation as d, restoreReservation as r, softDeleteReservation as s, updateReservation as u };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@htlkg/data",
3
- "version": "0.0.19",
3
+ "version": "0.0.21",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -40,10 +40,20 @@
40
40
  "src",
41
41
  "dist"
42
42
  ],
43
+ "scripts": {
44
+ "build": "tsup",
45
+ "dev": "tsup --watch",
46
+ "test": "vitest run",
47
+ "test:watch": "vitest",
48
+ "prepublishOnly": "pnpm build",
49
+ "version:patch": "pnpm version patch --no-git-tag-version",
50
+ "version:minor": "pnpm version minor --no-git-tag-version",
51
+ "version:major": "pnpm version major --no-git-tag-version"
52
+ },
43
53
  "dependencies": {
44
54
  "@aws-amplify/api": "^6.0.0",
45
- "zod": "^3.22.0",
46
- "@htlkg/core": "0.0.13"
55
+ "@htlkg/core": "^0.0.15",
56
+ "zod": "^3.22.0"
47
57
  },
48
58
  "peerDependencies": {
49
59
  "vue": "^3.5.0"
@@ -58,14 +68,5 @@
58
68
  "tsup": "^8.0.0",
59
69
  "typescript": "^5.9.2",
60
70
  "vitest": "^3.2.4"
61
- },
62
- "scripts": {
63
- "build": "tsup",
64
- "dev": "tsup --watch",
65
- "test": "vitest run",
66
- "test:watch": "vitest",
67
- "version:patch": "pnpm version patch --no-git-tag-version",
68
- "version:minor": "pnpm version minor --no-git-tag-version",
69
- "version:major": "pnpm version major --no-git-tag-version"
70
71
  }
71
- }
72
+ }
@@ -26,6 +26,24 @@ export {
26
26
  type ProxyOptions,
27
27
  } from "./proxy";
28
28
 
29
+ // Re-export type-safe client-side Reservation operations
30
+ export {
31
+ createReservation,
32
+ updateReservation,
33
+ softDeleteReservation,
34
+ restoreReservation,
35
+ deleteReservation,
36
+ getReservation,
37
+ listReservations,
38
+ updateReservationStatus,
39
+ bulkSoftDeleteReservations,
40
+ bulkRestoreReservations,
41
+ bulkDeleteReservations,
42
+ bulkUpdateReservationStatus,
43
+ type Reservation,
44
+ type ReservationStatus,
45
+ } from "./reservations";
46
+
29
47
  /**
30
48
  * Type for the server-side Amplify client (for use in type declarations)
31
49
  * This represents the client returned by generateServerClientUsingCookies
@@ -0,0 +1,336 @@
1
+ /**
2
+ * Type-safe Client-Side Reservation Operations
3
+ *
4
+ * Provides type-safe wrappers around the GraphQL proxy for reservation operations.
5
+ * These functions can be used directly in Vue components while maintaining type safety.
6
+ * Includes client-side validation for dates and status transitions.
7
+ */
8
+
9
+ import { mutate, query, type GraphQLResponse } from "./proxy";
10
+ import type {
11
+ CreateReservationInput,
12
+ UpdateReservationInput,
13
+ ReservationStatus,
14
+ } from "../mutations/reservations";
15
+
16
+ /**
17
+ * Reservation type (simplified for client-side use)
18
+ */
19
+ export interface Reservation {
20
+ id: string;
21
+ brandId: string;
22
+ visitId: string;
23
+ confirmationCode: string;
24
+ checkIn: string;
25
+ checkOut: string;
26
+ status: ReservationStatus;
27
+ source?: string;
28
+ channel?: string;
29
+ roomType?: string;
30
+ room?: string;
31
+ totalAmount?: number;
32
+ currency?: string;
33
+ nights?: number;
34
+ deletedAt?: string;
35
+ deletedBy?: string;
36
+ createdAt?: string;
37
+ createdBy?: string;
38
+ updatedAt?: string;
39
+ updatedBy?: string;
40
+ }
41
+
42
+ /**
43
+ * Re-export ReservationStatus type for convenience
44
+ */
45
+ export type { ReservationStatus } from "../mutations/reservations";
46
+
47
+ /**
48
+ * Create a new reservation (client-side)
49
+ *
50
+ * @example
51
+ * ```typescript
52
+ * import { createReservation } from '@htlkg/data/client';
53
+ *
54
+ * const result = await createReservation({
55
+ * brandId: 'brand-123',
56
+ * visitId: 'visit-456',
57
+ * confirmationCode: 'ABC123',
58
+ * checkIn: '2024-01-01',
59
+ * checkOut: '2024-01-05',
60
+ * status: 'confirmed'
61
+ * });
62
+ *
63
+ * if (!result.errors) {
64
+ * console.log('Created:', result.data);
65
+ * }
66
+ * ```
67
+ */
68
+ export async function createReservation(
69
+ input: CreateReservationInput,
70
+ ): Promise<GraphQLResponse<Reservation>> {
71
+ return mutate<Reservation>("Reservation", "create", input);
72
+ }
73
+
74
+ /**
75
+ * Update an existing reservation (client-side)
76
+ *
77
+ * @example
78
+ * ```typescript
79
+ * import { updateReservation } from '@htlkg/data/client';
80
+ *
81
+ * const result = await updateReservation({
82
+ * id: 'reservation-123',
83
+ * status: 'checked_in',
84
+ * room: '201'
85
+ * });
86
+ *
87
+ * if (!result.errors) {
88
+ * console.log('Updated:', result.data);
89
+ * }
90
+ * ```
91
+ */
92
+ export async function updateReservation(
93
+ input: UpdateReservationInput,
94
+ ): Promise<GraphQLResponse<Reservation>> {
95
+ return mutate<Reservation>("Reservation", "update", input);
96
+ }
97
+
98
+ /**
99
+ * Soft delete a reservation (sets deletedAt/deletedBy)
100
+ *
101
+ * @example
102
+ * ```typescript
103
+ * import { softDeleteReservation } from '@htlkg/data/client';
104
+ *
105
+ * const result = await softDeleteReservation('reservation-123', 'admin@example.com');
106
+ *
107
+ * if (!result.errors) {
108
+ * console.log('Soft deleted');
109
+ * }
110
+ * ```
111
+ */
112
+ export async function softDeleteReservation(
113
+ id: string,
114
+ deletedBy: string,
115
+ ): Promise<GraphQLResponse<Reservation>> {
116
+ return mutate<Reservation>("Reservation", "update", {
117
+ id,
118
+ deletedAt: new Date().toISOString(),
119
+ deletedBy,
120
+ });
121
+ }
122
+
123
+ /**
124
+ * Restore a soft-deleted reservation
125
+ *
126
+ * @example
127
+ * ```typescript
128
+ * import { restoreReservation } from '@htlkg/data/client';
129
+ *
130
+ * const result = await restoreReservation('reservation-123');
131
+ *
132
+ * if (!result.errors) {
133
+ * console.log('Restored');
134
+ * }
135
+ * ```
136
+ */
137
+ export async function restoreReservation(
138
+ id: string,
139
+ ): Promise<GraphQLResponse<Reservation>> {
140
+ return mutate<Reservation>("Reservation", "update", {
141
+ id,
142
+ deletedAt: null,
143
+ deletedBy: null,
144
+ });
145
+ }
146
+
147
+ /**
148
+ * Permanently delete a reservation (removes from database)
149
+ *
150
+ * @example
151
+ * ```typescript
152
+ * import { deleteReservation } from '@htlkg/data/client';
153
+ *
154
+ * const result = await deleteReservation('reservation-123');
155
+ *
156
+ * if (!result.errors) {
157
+ * console.log('Permanently deleted');
158
+ * }
159
+ * ```
160
+ */
161
+ export async function deleteReservation(
162
+ id: string,
163
+ ): Promise<GraphQLResponse<Reservation>> {
164
+ return mutate<Reservation>("Reservation", "delete", { id });
165
+ }
166
+
167
+ /**
168
+ * Get a single reservation by ID
169
+ *
170
+ * @example
171
+ * ```typescript
172
+ * import { getReservation } from '@htlkg/data/client';
173
+ *
174
+ * const result = await getReservation('reservation-123');
175
+ *
176
+ * if (!result.errors && result.data) {
177
+ * console.log('Reservation:', result.data);
178
+ * }
179
+ * ```
180
+ */
181
+ export async function getReservation(
182
+ id: string,
183
+ ): Promise<GraphQLResponse<Reservation>> {
184
+ return query<Reservation>("Reservation", "get", { id });
185
+ }
186
+
187
+ /**
188
+ * List reservations with optional filters
189
+ *
190
+ * @example
191
+ * ```typescript
192
+ * import { listReservations } from '@htlkg/data/client';
193
+ *
194
+ * const result = await listReservations({
195
+ * filter: { brandId: { eq: 'brand-123' } },
196
+ * limit: 100
197
+ * });
198
+ *
199
+ * if (!result.errors && result.data) {
200
+ * console.log('Reservations:', result.data);
201
+ * }
202
+ * ```
203
+ */
204
+ export async function listReservations(
205
+ options?: {
206
+ filter?: Record<string, any>;
207
+ limit?: number;
208
+ nextToken?: string;
209
+ selectionSet?: string[];
210
+ },
211
+ ): Promise<GraphQLResponse<Reservation[]>> {
212
+ return query<Reservation[]>("Reservation", "list", options);
213
+ }
214
+
215
+ /**
216
+ * Update reservation status (with server-side validation)
217
+ *
218
+ * The server will validate status transitions:
219
+ * - confirmed → checked_in, cancelled, no_show
220
+ * - checked_in → checked_out, cancelled
221
+ * - checked_out, cancelled, no_show → (terminal states, no transitions)
222
+ *
223
+ * @example
224
+ * ```typescript
225
+ * import { updateReservationStatus } from '@htlkg/data/client';
226
+ *
227
+ * const result = await updateReservationStatus('reservation-123', 'checked_in');
228
+ *
229
+ * if (!result.errors) {
230
+ * console.log('Status updated');
231
+ * } else {
232
+ * console.error('Status transition not allowed:', result.errors[0].message);
233
+ * }
234
+ * ```
235
+ */
236
+ export async function updateReservationStatus(
237
+ id: string,
238
+ status: ReservationStatus,
239
+ ): Promise<GraphQLResponse<Reservation>> {
240
+ return mutate<Reservation>("Reservation", "update", { id, status });
241
+ }
242
+
243
+ /**
244
+ * Bulk soft delete reservations
245
+ *
246
+ * @example
247
+ * ```typescript
248
+ * import { bulkSoftDeleteReservations } from '@htlkg/data/client';
249
+ *
250
+ * const results = await bulkSoftDeleteReservations(
251
+ * ['res-1', 'res-2', 'res-3'],
252
+ * 'admin@example.com'
253
+ * );
254
+ *
255
+ * results.forEach(result => {
256
+ * if (!result.errors) console.log('Deleted:', result.data?.id);
257
+ * });
258
+ * ```
259
+ */
260
+ export async function bulkSoftDeleteReservations(
261
+ ids: string[],
262
+ deletedBy: string,
263
+ ): Promise<GraphQLResponse<Reservation>[]> {
264
+ return Promise.all(ids.map((id) => softDeleteReservation(id, deletedBy)));
265
+ }
266
+
267
+ /**
268
+ * Bulk restore reservations
269
+ *
270
+ * @example
271
+ * ```typescript
272
+ * import { bulkRestoreReservations } from '@htlkg/data/client';
273
+ *
274
+ * const results = await bulkRestoreReservations(['res-1', 'res-2', 'res-3']);
275
+ *
276
+ * results.forEach(result => {
277
+ * if (!result.errors) console.log('Restored:', result.data?.id);
278
+ * });
279
+ * ```
280
+ */
281
+ export async function bulkRestoreReservations(
282
+ ids: string[],
283
+ ): Promise<GraphQLResponse<Reservation>[]> {
284
+ return Promise.all(ids.map((id) => restoreReservation(id)));
285
+ }
286
+
287
+ /**
288
+ * Bulk permanently delete reservations
289
+ *
290
+ * @example
291
+ * ```typescript
292
+ * import { bulkDeleteReservations } from '@htlkg/data/client';
293
+ *
294
+ * const results = await bulkDeleteReservations(['res-1', 'res-2', 'res-3']);
295
+ *
296
+ * results.forEach(result => {
297
+ * if (!result.errors) console.log('Permanently deleted:', result.data?.id);
298
+ * });
299
+ * ```
300
+ */
301
+ export async function bulkDeleteReservations(
302
+ ids: string[],
303
+ ): Promise<GraphQLResponse<Reservation>[]> {
304
+ return Promise.all(ids.map((id) => deleteReservation(id)));
305
+ }
306
+
307
+ /**
308
+ * Bulk update reservation status (with server-side validation per reservation)
309
+ *
310
+ * Note: Each reservation's status transition is validated independently.
311
+ * Some may succeed while others fail if their current status doesn't allow the transition.
312
+ *
313
+ * @example
314
+ * ```typescript
315
+ * import { bulkUpdateReservationStatus } from '@htlkg/data/client';
316
+ *
317
+ * const results = await bulkUpdateReservationStatus(
318
+ * ['res-1', 'res-2', 'res-3'],
319
+ * 'checked_in'
320
+ * );
321
+ *
322
+ * results.forEach(result => {
323
+ * if (!result.errors) {
324
+ * console.log('Updated:', result.data?.id);
325
+ * } else {
326
+ * console.error('Failed:', result.errors[0].message);
327
+ * }
328
+ * });
329
+ * ```
330
+ */
331
+ export async function bulkUpdateReservationStatus(
332
+ ids: string[],
333
+ status: ReservationStatus,
334
+ ): Promise<GraphQLResponse<Reservation>[]> {
335
+ return Promise.all(ids.map((id) => updateReservationStatus(id, status)));
336
+ }