@htlkg/data 0.0.14 → 0.0.16

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 (37) hide show
  1. package/README.md +72 -0
  2. package/dist/client/index.d.ts +123 -30
  3. package/dist/client/index.js +75 -1
  4. package/dist/client/index.js.map +1 -1
  5. package/dist/hooks/index.d.ts +76 -2
  6. package/dist/hooks/index.js +224 -6
  7. package/dist/hooks/index.js.map +1 -1
  8. package/dist/index.d.ts +6 -4
  9. package/dist/index.js +550 -7
  10. package/dist/index.js.map +1 -1
  11. package/dist/mutations/index.d.ts +149 -5
  12. package/dist/mutations/index.js +397 -0
  13. package/dist/mutations/index.js.map +1 -1
  14. package/dist/productInstances-CzT3NZKU.d.ts +98 -0
  15. package/dist/queries/index.d.ts +54 -2
  16. package/dist/queries/index.js +60 -1
  17. package/dist/queries/index.js.map +1 -1
  18. package/dist/server/index.d.ts +47 -0
  19. package/dist/server/index.js +59 -0
  20. package/dist/server/index.js.map +1 -0
  21. package/package.json +5 -1
  22. package/src/client/index.ts +82 -3
  23. package/src/client/proxy.ts +170 -0
  24. package/src/hooks/index.ts +1 -0
  25. package/src/hooks/useProductInstances.ts +174 -0
  26. package/src/index.ts +11 -0
  27. package/src/mutations/accounts.ts +102 -1
  28. package/src/mutations/brands.ts +102 -1
  29. package/src/mutations/index.ts +23 -0
  30. package/src/mutations/productInstances/index.ts +14 -0
  31. package/src/mutations/productInstances/productInstances.integration.test.ts +621 -0
  32. package/src/mutations/productInstances/productInstances.test.ts +680 -0
  33. package/src/mutations/productInstances/productInstances.ts +280 -0
  34. package/src/mutations/systemSettings.ts +130 -0
  35. package/src/mutations/users.ts +102 -1
  36. package/src/queries/index.ts +9 -0
  37. package/src/queries/systemSettings.ts +115 -0
@@ -1,4 +1,5 @@
1
- import { Brand, Account, User } from '@htlkg/core/types';
1
+ import { Brand, Account, User, SystemSettings } from '@htlkg/core/types';
2
+ export { C as CreateProductInstanceInput, U as UpdateProductInstanceInput, c as createProductInstance, d as deleteProductInstance, t as toggleProductInstanceEnabled, u as updateProductInstance } from '../productInstances-CzT3NZKU.js';
2
3
 
3
4
  /**
4
5
  * Brand Mutation Functions
@@ -64,7 +65,40 @@ declare function createBrand<TClient = any>(client: TClient, input: CreateBrandI
64
65
  */
65
66
  declare function updateBrand<TClient = any>(client: TClient, input: UpdateBrandInput): Promise<Brand | null>;
66
67
  /**
67
- * Delete a brand
68
+ * Soft delete a brand (sets status to "deleted" instead of removing)
69
+ *
70
+ * @example
71
+ * ```typescript
72
+ * import { softDeleteBrand } from '@htlkg/data/mutations';
73
+ * import { generateClient } from '@htlkg/data/client';
74
+ *
75
+ * const client = generateClient<Schema>();
76
+ * await softDeleteBrand(client, 'brand-123', 'admin@example.com');
77
+ * ```
78
+ */
79
+ declare function softDeleteBrand<TClient = any>(client: TClient, id: string, deletedBy: string): Promise<boolean>;
80
+ /**
81
+ * Restore a soft-deleted brand (sets status back to "active")
82
+ * Checks retention period before allowing restoration
83
+ *
84
+ * @example
85
+ * ```typescript
86
+ * import { restoreBrand } from '@htlkg/data/mutations';
87
+ * import { generateClient } from '@htlkg/data/client';
88
+ *
89
+ * const client = generateClient<Schema>();
90
+ * await restoreBrand(client, 'brand-123');
91
+ * // Or with custom retention days:
92
+ * await restoreBrand(client, 'brand-123', 60);
93
+ * ```
94
+ */
95
+ declare function restoreBrand<TClient = any>(client: TClient, id: string, retentionDays?: number): Promise<{
96
+ success: boolean;
97
+ error?: string;
98
+ }>;
99
+ /**
100
+ * Hard delete a brand (permanently removes from database)
101
+ * Use with caution - prefer softDeleteBrand for recoverable deletion
68
102
  *
69
103
  * @example
70
104
  * ```typescript
@@ -135,7 +169,40 @@ declare function createAccount<TClient = any>(client: TClient, input: CreateAcco
135
169
  */
136
170
  declare function updateAccount<TClient = any>(client: TClient, input: UpdateAccountInput): Promise<Account | null>;
137
171
  /**
138
- * Delete an account
172
+ * Soft delete an account (sets status to "deleted" instead of removing)
173
+ *
174
+ * @example
175
+ * ```typescript
176
+ * import { softDeleteAccount } from '@htlkg/data/mutations';
177
+ * import { generateClient } from '@htlkg/data/client';
178
+ *
179
+ * const client = generateClient<Schema>();
180
+ * await softDeleteAccount(client, 'account-123', 'admin@example.com');
181
+ * ```
182
+ */
183
+ declare function softDeleteAccount<TClient = any>(client: TClient, id: string, deletedBy: string): Promise<boolean>;
184
+ /**
185
+ * Restore a soft-deleted account (sets status back to "active")
186
+ * Checks retention period before allowing restoration
187
+ *
188
+ * @example
189
+ * ```typescript
190
+ * import { restoreAccount } from '@htlkg/data/mutations';
191
+ * import { generateClient } from '@htlkg/data/client';
192
+ *
193
+ * const client = generateClient<Schema>();
194
+ * await restoreAccount(client, 'account-123');
195
+ * // Or with custom retention days:
196
+ * await restoreAccount(client, 'account-123', 60);
197
+ * ```
198
+ */
199
+ declare function restoreAccount<TClient = any>(client: TClient, id: string, retentionDays?: number): Promise<{
200
+ success: boolean;
201
+ error?: string;
202
+ }>;
203
+ /**
204
+ * Hard delete an account (permanently removes from database)
205
+ * Use with caution - prefer softDeleteAccount for recoverable deletion
139
206
  *
140
207
  * @example
141
208
  * ```typescript
@@ -215,7 +282,40 @@ declare function createUser<TClient = any>(client: TClient, input: CreateUserInp
215
282
  */
216
283
  declare function updateUser<TClient = any>(client: TClient, input: UpdateUserInput): Promise<User | null>;
217
284
  /**
218
- * Delete a user
285
+ * Soft delete a user (sets status to "deleted" instead of removing)
286
+ *
287
+ * @example
288
+ * ```typescript
289
+ * import { softDeleteUser } from '@htlkg/data/mutations';
290
+ * import { generateClient } from '@htlkg/data/client';
291
+ *
292
+ * const client = generateClient<Schema>();
293
+ * await softDeleteUser(client, 'user-123', 'admin@example.com');
294
+ * ```
295
+ */
296
+ declare function softDeleteUser<TClient = any>(client: TClient, id: string, deletedBy: string): Promise<boolean>;
297
+ /**
298
+ * Restore a soft-deleted user (sets status back to "active")
299
+ * Checks retention period before allowing restoration
300
+ *
301
+ * @example
302
+ * ```typescript
303
+ * import { restoreUser } from '@htlkg/data/mutations';
304
+ * import { generateClient } from '@htlkg/data/client';
305
+ *
306
+ * const client = generateClient<Schema>();
307
+ * await restoreUser(client, 'user-123');
308
+ * // Or with custom retention days:
309
+ * await restoreUser(client, 'user-123', 60);
310
+ * ```
311
+ */
312
+ declare function restoreUser<TClient = any>(client: TClient, id: string, retentionDays?: number): Promise<{
313
+ success: boolean;
314
+ error?: string;
315
+ }>;
316
+ /**
317
+ * Hard delete a user (permanently removes from database)
318
+ * Use with caution - prefer softDeleteUser for recoverable deletion
219
319
  *
220
320
  * @example
221
321
  * ```typescript
@@ -228,4 +328,48 @@ declare function updateUser<TClient = any>(client: TClient, input: UpdateUserInp
228
328
  */
229
329
  declare function deleteUser<TClient = any>(client: TClient, id: string): Promise<boolean>;
230
330
 
231
- export { type CreateAccountInput, type CreateBrandInput, type CreateUserInput, type UpdateAccountInput, type UpdateBrandInput, type UpdateUserInput, createAccount, createBrand, createUser, deleteAccount, deleteBrand, deleteUser, updateAccount, updateBrand, updateUser };
331
+ /**
332
+ * SystemSettings Mutation Functions
333
+ *
334
+ * Provides mutation functions for managing system settings.
335
+ */
336
+
337
+ /**
338
+ * Input type for updating system settings
339
+ */
340
+ interface UpdateSystemSettingsInput {
341
+ softDeleteRetentionDays: number;
342
+ updatedBy: string;
343
+ }
344
+ /**
345
+ * Update or create system settings
346
+ * Only SUPER_ADMINS can update system settings
347
+ *
348
+ * @example
349
+ * ```typescript
350
+ * import { updateSystemSettings } from '@htlkg/data/mutations';
351
+ * import { generateClient } from '@htlkg/data/client';
352
+ *
353
+ * const client = generateClient<Schema>();
354
+ * const settings = await updateSystemSettings(client, {
355
+ * softDeleteRetentionDays: 60,
356
+ * updatedBy: 'admin@example.com'
357
+ * });
358
+ * ```
359
+ */
360
+ declare function updateSystemSettings<TClient = any>(client: TClient, input: UpdateSystemSettingsInput): Promise<SystemSettings | null>;
361
+ /**
362
+ * Initialize system settings with default values if they don't exist
363
+ *
364
+ * @example
365
+ * ```typescript
366
+ * import { initializeSystemSettings } from '@htlkg/data/mutations';
367
+ * import { generateClient } from '@htlkg/data/client';
368
+ *
369
+ * const client = generateClient<Schema>();
370
+ * const settings = await initializeSystemSettings(client, 'system@hotelinking.com');
371
+ * ```
372
+ */
373
+ declare function initializeSystemSettings<TClient = any>(client: TClient, initializedBy: string): Promise<SystemSettings | null>;
374
+
375
+ export { type CreateAccountInput, type CreateBrandInput, type CreateUserInput, type UpdateAccountInput, type UpdateBrandInput, type UpdateSystemSettingsInput, type UpdateUserInput, createAccount, createBrand, createUser, deleteAccount, deleteBrand, deleteUser, initializeSystemSettings, restoreAccount, restoreBrand, restoreUser, softDeleteAccount, softDeleteBrand, softDeleteUser, updateAccount, updateBrand, updateSystemSettings, updateUser };
@@ -1,3 +1,37 @@
1
+ // src/queries/systemSettings.ts
2
+ var DEFAULT_SOFT_DELETE_RETENTION_DAYS = 30;
3
+ var SYSTEM_SETTINGS_KEY = "GLOBAL";
4
+ function checkRestoreEligibility(deletedAt, retentionDays) {
5
+ if (!deletedAt) {
6
+ return {
7
+ canRestore: false,
8
+ daysRemaining: 0,
9
+ daysExpired: 0,
10
+ expiresAt: null
11
+ };
12
+ }
13
+ const deletedDate = new Date(deletedAt);
14
+ const expiresAt = new Date(deletedDate);
15
+ expiresAt.setDate(expiresAt.getDate() + retentionDays);
16
+ const now = /* @__PURE__ */ new Date();
17
+ const msRemaining = expiresAt.getTime() - now.getTime();
18
+ const daysRemaining = Math.ceil(msRemaining / (1e3 * 60 * 60 * 24));
19
+ if (daysRemaining <= 0) {
20
+ return {
21
+ canRestore: false,
22
+ daysRemaining: 0,
23
+ daysExpired: Math.abs(daysRemaining),
24
+ expiresAt
25
+ };
26
+ }
27
+ return {
28
+ canRestore: true,
29
+ daysRemaining,
30
+ daysExpired: 0,
31
+ expiresAt
32
+ };
33
+ }
34
+
1
35
  // src/mutations/brands.ts
2
36
  async function createBrand(client, input) {
3
37
  try {
@@ -25,6 +59,53 @@ async function updateBrand(client, input) {
25
59
  throw error;
26
60
  }
27
61
  }
62
+ async function softDeleteBrand(client, id, deletedBy) {
63
+ try {
64
+ const { errors } = await client.models.Brand.update({
65
+ id,
66
+ status: "deleted",
67
+ deletedAt: (/* @__PURE__ */ new Date()).toISOString(),
68
+ deletedBy
69
+ });
70
+ if (errors) {
71
+ console.error("[softDeleteBrand] GraphQL errors:", errors);
72
+ return false;
73
+ }
74
+ return true;
75
+ } catch (error) {
76
+ console.error("[softDeleteBrand] Error soft-deleting brand:", error);
77
+ throw error;
78
+ }
79
+ }
80
+ async function restoreBrand(client, id, retentionDays = DEFAULT_SOFT_DELETE_RETENTION_DAYS) {
81
+ try {
82
+ const { data: brand, errors: getErrors } = await client.models.Brand.get({ id });
83
+ if (getErrors || !brand) {
84
+ console.error("[restoreBrand] Error fetching brand:", getErrors);
85
+ return { success: false, error: "Brand not found" };
86
+ }
87
+ const eligibility = checkRestoreEligibility(brand.deletedAt, retentionDays);
88
+ if (!eligibility.canRestore) {
89
+ const errorMsg = `Cannot restore brand. Retention period of ${retentionDays} days has expired. Item was deleted ${eligibility.daysExpired} days ago.`;
90
+ console.error("[restoreBrand]", errorMsg);
91
+ return { success: false, error: errorMsg };
92
+ }
93
+ const { errors } = await client.models.Brand.update({
94
+ id,
95
+ status: "active",
96
+ deletedAt: null,
97
+ deletedBy: null
98
+ });
99
+ if (errors) {
100
+ console.error("[restoreBrand] GraphQL errors:", errors);
101
+ return { success: false, error: "Failed to restore brand" };
102
+ }
103
+ return { success: true };
104
+ } catch (error) {
105
+ console.error("[restoreBrand] Error restoring brand:", error);
106
+ throw error;
107
+ }
108
+ }
28
109
  async function deleteBrand(client, id) {
29
110
  try {
30
111
  const { errors } = await client.models.Brand.delete({ id });
@@ -66,6 +147,53 @@ async function updateAccount(client, input) {
66
147
  throw error;
67
148
  }
68
149
  }
150
+ async function softDeleteAccount(client, id, deletedBy) {
151
+ try {
152
+ const { errors } = await client.models.Account.update({
153
+ id,
154
+ status: "deleted",
155
+ deletedAt: (/* @__PURE__ */ new Date()).toISOString(),
156
+ deletedBy
157
+ });
158
+ if (errors) {
159
+ console.error("[softDeleteAccount] GraphQL errors:", errors);
160
+ return false;
161
+ }
162
+ return true;
163
+ } catch (error) {
164
+ console.error("[softDeleteAccount] Error soft-deleting account:", error);
165
+ throw error;
166
+ }
167
+ }
168
+ async function restoreAccount(client, id, retentionDays = DEFAULT_SOFT_DELETE_RETENTION_DAYS) {
169
+ try {
170
+ const { data: account, errors: getErrors } = await client.models.Account.get({ id });
171
+ if (getErrors || !account) {
172
+ console.error("[restoreAccount] Error fetching account:", getErrors);
173
+ return { success: false, error: "Account not found" };
174
+ }
175
+ const eligibility = checkRestoreEligibility(account.deletedAt, retentionDays);
176
+ if (!eligibility.canRestore) {
177
+ const errorMsg = `Cannot restore account. Retention period of ${retentionDays} days has expired. Item was deleted ${eligibility.daysExpired} days ago.`;
178
+ console.error("[restoreAccount]", errorMsg);
179
+ return { success: false, error: errorMsg };
180
+ }
181
+ const { errors } = await client.models.Account.update({
182
+ id,
183
+ status: "active",
184
+ deletedAt: null,
185
+ deletedBy: null
186
+ });
187
+ if (errors) {
188
+ console.error("[restoreAccount] GraphQL errors:", errors);
189
+ return { success: false, error: "Failed to restore account" };
190
+ }
191
+ return { success: true };
192
+ } catch (error) {
193
+ console.error("[restoreAccount] Error restoring account:", error);
194
+ throw error;
195
+ }
196
+ }
69
197
  async function deleteAccount(client, id) {
70
198
  try {
71
199
  const { errors } = await client.models.Account.delete({ id });
@@ -107,6 +235,53 @@ async function updateUser(client, input) {
107
235
  throw error;
108
236
  }
109
237
  }
238
+ async function softDeleteUser(client, id, deletedBy) {
239
+ try {
240
+ const { errors } = await client.models.User.update({
241
+ id,
242
+ status: "deleted",
243
+ deletedAt: (/* @__PURE__ */ new Date()).toISOString(),
244
+ deletedBy
245
+ });
246
+ if (errors) {
247
+ console.error("[softDeleteUser] GraphQL errors:", errors);
248
+ return false;
249
+ }
250
+ return true;
251
+ } catch (error) {
252
+ console.error("[softDeleteUser] Error soft-deleting user:", error);
253
+ throw error;
254
+ }
255
+ }
256
+ async function restoreUser(client, id, retentionDays = DEFAULT_SOFT_DELETE_RETENTION_DAYS) {
257
+ try {
258
+ const { data: user, errors: getErrors } = await client.models.User.get({ id });
259
+ if (getErrors || !user) {
260
+ console.error("[restoreUser] Error fetching user:", getErrors);
261
+ return { success: false, error: "User not found" };
262
+ }
263
+ const eligibility = checkRestoreEligibility(user.deletedAt, retentionDays);
264
+ if (!eligibility.canRestore) {
265
+ const errorMsg = `Cannot restore user. Retention period of ${retentionDays} days has expired. Item was deleted ${eligibility.daysExpired} days ago.`;
266
+ console.error("[restoreUser]", errorMsg);
267
+ return { success: false, error: errorMsg };
268
+ }
269
+ const { errors } = await client.models.User.update({
270
+ id,
271
+ status: "active",
272
+ deletedAt: null,
273
+ deletedBy: null
274
+ });
275
+ if (errors) {
276
+ console.error("[restoreUser] GraphQL errors:", errors);
277
+ return { success: false, error: "Failed to restore user" };
278
+ }
279
+ return { success: true };
280
+ } catch (error) {
281
+ console.error("[restoreUser] Error restoring user:", error);
282
+ throw error;
283
+ }
284
+ }
110
285
  async function deleteUser(client, id) {
111
286
  try {
112
287
  const { errors } = await client.models.User.delete({ id });
@@ -120,15 +295,237 @@ async function deleteUser(client, id) {
120
295
  throw error;
121
296
  }
122
297
  }
298
+
299
+ // src/mutations/productInstances/productInstances.ts
300
+ import { getClientUser } from "@htlkg/core/auth";
301
+ import { getCurrentTimestamp } from "@htlkg/core/utils";
302
+ import { AppError } from "@htlkg/core/errors";
303
+ async function getUserIdentifier(fallback = "system") {
304
+ try {
305
+ const user = await getClientUser();
306
+ if (user) {
307
+ return user.email || user.username || fallback;
308
+ }
309
+ return fallback;
310
+ } catch {
311
+ return fallback;
312
+ }
313
+ }
314
+ async function createProductInstance(client, input) {
315
+ try {
316
+ const createInput = {
317
+ productId: input.productId,
318
+ productName: input.productName,
319
+ brandId: input.brandId,
320
+ accountId: input.accountId,
321
+ enabled: input.enabled,
322
+ version: input.version,
323
+ lastUpdated: input.lastUpdated || getCurrentTimestamp(),
324
+ updatedBy: input.updatedBy || await getUserIdentifier()
325
+ };
326
+ if (input.config) {
327
+ createInput.config = JSON.stringify(JSON.parse(JSON.stringify(input.config)));
328
+ }
329
+ console.log("[createProductInstance] Config as string:", createInput.config);
330
+ console.log("[createProductInstance] Config type:", typeof createInput.config);
331
+ const { data, errors } = await client.models.ProductInstance.create(createInput);
332
+ if (errors) {
333
+ console.error("[createProductInstance] GraphQL errors:", errors);
334
+ throw new AppError(
335
+ "Failed to create product instance",
336
+ "PRODUCT_INSTANCE_CREATE_ERROR",
337
+ 500,
338
+ { errors }
339
+ );
340
+ }
341
+ return data;
342
+ } catch (error) {
343
+ console.error("[createProductInstance] Error creating product instance:", error);
344
+ if (error instanceof AppError) {
345
+ throw error;
346
+ }
347
+ throw new AppError(
348
+ "Failed to create product instance",
349
+ "PRODUCT_INSTANCE_CREATE_ERROR",
350
+ 500,
351
+ { originalError: error }
352
+ );
353
+ }
354
+ }
355
+ async function updateProductInstance(client, input) {
356
+ try {
357
+ const updateInput = {
358
+ ...input,
359
+ lastUpdated: input.lastUpdated || getCurrentTimestamp(),
360
+ updatedBy: input.updatedBy || await getUserIdentifier()
361
+ };
362
+ if (input.config) {
363
+ updateInput.config = JSON.stringify(JSON.parse(JSON.stringify(input.config)));
364
+ }
365
+ const { data, errors } = await client.models.ProductInstance.update(updateInput);
366
+ if (errors) {
367
+ console.error("[updateProductInstance] GraphQL errors:", errors);
368
+ throw new AppError(
369
+ "Failed to update product instance",
370
+ "PRODUCT_INSTANCE_UPDATE_ERROR",
371
+ 500,
372
+ { errors }
373
+ );
374
+ }
375
+ return data;
376
+ } catch (error) {
377
+ console.error("[updateProductInstance] Error updating product instance:", error);
378
+ if (error instanceof AppError) {
379
+ throw error;
380
+ }
381
+ throw new AppError(
382
+ "Failed to update product instance",
383
+ "PRODUCT_INSTANCE_UPDATE_ERROR",
384
+ 500,
385
+ { originalError: error }
386
+ );
387
+ }
388
+ }
389
+ async function deleteProductInstance(client, id) {
390
+ try {
391
+ const { errors } = await client.models.ProductInstance.delete({ id });
392
+ if (errors) {
393
+ console.error("[deleteProductInstance] GraphQL errors:", errors);
394
+ throw new AppError(
395
+ "Failed to delete product instance",
396
+ "PRODUCT_INSTANCE_DELETE_ERROR",
397
+ 500,
398
+ { errors }
399
+ );
400
+ }
401
+ return true;
402
+ } catch (error) {
403
+ console.error("[deleteProductInstance] Error deleting product instance:", error);
404
+ if (error instanceof AppError) {
405
+ throw error;
406
+ }
407
+ throw new AppError(
408
+ "Failed to delete product instance",
409
+ "PRODUCT_INSTANCE_DELETE_ERROR",
410
+ 500,
411
+ { originalError: error }
412
+ );
413
+ }
414
+ }
415
+ async function toggleProductInstanceEnabled(client, id, enabled) {
416
+ try {
417
+ const { data, errors } = await client.models.ProductInstance.update({
418
+ id,
419
+ enabled,
420
+ lastUpdated: getCurrentTimestamp(),
421
+ updatedBy: await getUserIdentifier()
422
+ });
423
+ if (errors) {
424
+ console.error("[toggleProductInstanceEnabled] GraphQL errors:", errors);
425
+ throw new AppError(
426
+ "Failed to toggle product instance",
427
+ "PRODUCT_INSTANCE_TOGGLE_ERROR",
428
+ 500,
429
+ { errors }
430
+ );
431
+ }
432
+ return data;
433
+ } catch (error) {
434
+ console.error("[toggleProductInstanceEnabled] Error toggling product instance:", error);
435
+ if (error instanceof AppError) {
436
+ throw error;
437
+ }
438
+ throw new AppError(
439
+ "Failed to toggle product instance",
440
+ "PRODUCT_INSTANCE_TOGGLE_ERROR",
441
+ 500,
442
+ { originalError: error }
443
+ );
444
+ }
445
+ }
446
+
447
+ // src/mutations/systemSettings.ts
448
+ async function updateSystemSettings(client, input) {
449
+ try {
450
+ if (input.softDeleteRetentionDays < 1 || input.softDeleteRetentionDays > 365) {
451
+ console.error(
452
+ "[updateSystemSettings] Invalid retention days. Must be between 1 and 365."
453
+ );
454
+ return null;
455
+ }
456
+ const { data: existing } = await client.models.SystemSettings.get({
457
+ key: SYSTEM_SETTINGS_KEY
458
+ });
459
+ const settingsData = {
460
+ key: SYSTEM_SETTINGS_KEY,
461
+ softDeleteRetentionDays: input.softDeleteRetentionDays,
462
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
463
+ updatedBy: input.updatedBy
464
+ };
465
+ let result;
466
+ if (existing) {
467
+ result = await client.models.SystemSettings.update(settingsData);
468
+ } else {
469
+ result = await client.models.SystemSettings.create(settingsData);
470
+ }
471
+ if (result.errors) {
472
+ console.error("[updateSystemSettings] GraphQL errors:", result.errors);
473
+ return null;
474
+ }
475
+ return result.data;
476
+ } catch (error) {
477
+ console.error("[updateSystemSettings] Error updating system settings:", error);
478
+ throw error;
479
+ }
480
+ }
481
+ async function initializeSystemSettings(client, initializedBy) {
482
+ try {
483
+ const { data: existing } = await client.models.SystemSettings.get({
484
+ key: SYSTEM_SETTINGS_KEY
485
+ });
486
+ if (existing) {
487
+ return existing;
488
+ }
489
+ const { data, errors } = await client.models.SystemSettings.create({
490
+ key: SYSTEM_SETTINGS_KEY,
491
+ softDeleteRetentionDays: DEFAULT_SOFT_DELETE_RETENTION_DAYS,
492
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
493
+ updatedBy: initializedBy
494
+ });
495
+ if (errors) {
496
+ console.error("[initializeSystemSettings] GraphQL errors:", errors);
497
+ return null;
498
+ }
499
+ return data;
500
+ } catch (error) {
501
+ console.error(
502
+ "[initializeSystemSettings] Error initializing system settings:",
503
+ error
504
+ );
505
+ throw error;
506
+ }
507
+ }
123
508
  export {
124
509
  createAccount,
125
510
  createBrand,
511
+ createProductInstance,
126
512
  createUser,
127
513
  deleteAccount,
128
514
  deleteBrand,
515
+ deleteProductInstance,
129
516
  deleteUser,
517
+ initializeSystemSettings,
518
+ restoreAccount,
519
+ restoreBrand,
520
+ restoreUser,
521
+ softDeleteAccount,
522
+ softDeleteBrand,
523
+ softDeleteUser,
524
+ toggleProductInstanceEnabled,
130
525
  updateAccount,
131
526
  updateBrand,
527
+ updateProductInstance,
528
+ updateSystemSettings,
132
529
  updateUser
133
530
  };
134
531
  //# sourceMappingURL=index.js.map