@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 +1 @@
1
- {"version":3,"sources":["../../src/mutations/brands.ts","../../src/mutations/accounts.ts","../../src/mutations/users.ts"],"sourcesContent":["/**\n * Brand Mutation Functions\n *\n * Provides mutation functions for creating, updating, and deleting brands.\n */\n\nimport type { Brand } from \"@htlkg/core/types\";\n\n/**\n * Input type for creating a brand\n */\nexport interface CreateBrandInput {\n\taccountId: string;\n\tname: string;\n\tlogo?: string;\n\ttimezone?: string;\n\tstatus?: \"active\" | \"inactive\" | \"maintenance\" | \"suspended\";\n\tsettings?: Record<string, any>;\n}\n\n/**\n * Input type for updating a brand\n */\nexport interface UpdateBrandInput {\n\tid: string;\n\tname?: string;\n\tlogo?: string;\n\ttimezone?: string;\n\tstatus?: \"active\" | \"inactive\" | \"maintenance\" | \"suspended\";\n\tsettings?: Record<string, any>;\n}\n\n/**\n * Create a new brand\n *\n * @example\n * ```typescript\n * import { createBrand } from '@htlkg/data/mutations';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * const brand = await createBrand(client, {\n * accountId: 'account-123',\n * name: 'My Brand',\n * timezone: 'America/New_York',\n * status: 'active'\n * });\n * ```\n */\nexport async function createBrand<TClient = any>(\n\tclient: TClient,\n\tinput: CreateBrandInput,\n): Promise<Brand | null> {\n\ttry {\n\t\tconst { data, errors } = await (client as any).models.Brand.create(input);\n\n\t\tif (errors) {\n\t\t\tconsole.error(\"[createBrand] GraphQL errors:\", errors);\n\t\t\treturn null;\n\t\t}\n\n\t\treturn data as Brand;\n\t} catch (error) {\n\t\tconsole.error(\"[createBrand] Error creating brand:\", error);\n\t\tthrow error;\n\t}\n}\n\n/**\n * Update an existing brand\n *\n * @example\n * ```typescript\n * import { updateBrand } from '@htlkg/data/mutations';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * const brand = await updateBrand(client, {\n * id: 'brand-123',\n * name: 'Updated Brand Name',\n * status: 'maintenance'\n * });\n * ```\n */\nexport async function updateBrand<TClient = any>(\n\tclient: TClient,\n\tinput: UpdateBrandInput,\n): Promise<Brand | null> {\n\ttry {\n\t\tconst { data, errors } = await (client as any).models.Brand.update(input);\n\n\t\tif (errors) {\n\t\t\tconsole.error(\"[updateBrand] GraphQL errors:\", errors);\n\t\t\treturn null;\n\t\t}\n\n\t\treturn data as Brand;\n\t} catch (error) {\n\t\tconsole.error(\"[updateBrand] Error updating brand:\", error);\n\t\tthrow error;\n\t}\n}\n\n/**\n * Delete a brand\n *\n * @example\n * ```typescript\n * import { deleteBrand } from '@htlkg/data/mutations';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * await deleteBrand(client, 'brand-123');\n * ```\n */\nexport async function deleteBrand<TClient = any>(\n\tclient: TClient,\n\tid: string,\n): Promise<boolean> {\n\ttry {\n\t\tconst { errors } = await (client as any).models.Brand.delete({ id });\n\n\t\tif (errors) {\n\t\t\tconsole.error(\"[deleteBrand] GraphQL errors:\", errors);\n\t\t\treturn false;\n\t\t}\n\n\t\treturn true;\n\t} catch (error) {\n\t\tconsole.error(\"[deleteBrand] Error deleting brand:\", error);\n\t\tthrow error;\n\t}\n}\n","/**\n * Account Mutation Functions\n *\n * Provides mutation functions for creating, updating, and deleting accounts.\n */\n\nimport type { Account } from \"@htlkg/core/types\";\n\n/**\n * Input type for creating an account\n */\nexport interface CreateAccountInput {\n\tname: string;\n\tlogo?: string;\n\tsubscription?: Record<string, any>;\n\tsettings?: Record<string, any>;\n}\n\n/**\n * Input type for updating an account\n */\nexport interface UpdateAccountInput {\n\tid: string;\n\tname?: string;\n\tlogo?: string;\n\tsubscription?: Record<string, any>;\n\tsettings?: Record<string, any>;\n}\n\n/**\n * Create a new account\n *\n * @example\n * ```typescript\n * import { createAccount } from '@htlkg/data/mutations';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * const account = await createAccount(client, {\n * name: 'My Account',\n * subscription: { plan: 'premium' }\n * });\n * ```\n */\nexport async function createAccount<TClient = any>(\n\tclient: TClient,\n\tinput: CreateAccountInput,\n): Promise<Account | null> {\n\ttry {\n\t\tconst { data, errors } = await (client as any).models.Account.create(input);\n\n\t\tif (errors) {\n\t\t\tconsole.error(\"[createAccount] GraphQL errors:\", errors);\n\t\t\treturn null;\n\t\t}\n\n\t\treturn data as Account;\n\t} catch (error) {\n\t\tconsole.error(\"[createAccount] Error creating account:\", error);\n\t\tthrow error;\n\t}\n}\n\n/**\n * Update an existing account\n *\n * @example\n * ```typescript\n * import { updateAccount } from '@htlkg/data/mutations';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * const account = await updateAccount(client, {\n * id: 'account-123',\n * name: 'Updated Account Name'\n * });\n * ```\n */\nexport async function updateAccount<TClient = any>(\n\tclient: TClient,\n\tinput: UpdateAccountInput,\n): Promise<Account | null> {\n\ttry {\n\t\tconst { data, errors } = await (client as any).models.Account.update(input);\n\n\t\tif (errors) {\n\t\t\tconsole.error(\"[updateAccount] GraphQL errors:\", errors);\n\t\t\treturn null;\n\t\t}\n\n\t\treturn data as Account;\n\t} catch (error) {\n\t\tconsole.error(\"[updateAccount] Error updating account:\", error);\n\t\tthrow error;\n\t}\n}\n\n/**\n * Delete an account\n *\n * @example\n * ```typescript\n * import { deleteAccount } from '@htlkg/data/mutations';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * await deleteAccount(client, 'account-123');\n * ```\n */\nexport async function deleteAccount<TClient = any>(\n\tclient: TClient,\n\tid: string,\n): Promise<boolean> {\n\ttry {\n\t\tconst { errors } = await (client as any).models.Account.delete({ id });\n\n\t\tif (errors) {\n\t\t\tconsole.error(\"[deleteAccount] GraphQL errors:\", errors);\n\t\t\treturn false;\n\t\t}\n\n\t\treturn true;\n\t} catch (error) {\n\t\tconsole.error(\"[deleteAccount] Error deleting account:\", error);\n\t\tthrow error;\n\t}\n}\n","/**\n * User Mutation Functions\n *\n * Provides mutation functions for creating, updating, and deleting users.\n */\n\nimport type { User } from \"@htlkg/core/types\";\n\n/**\n * Input type for creating a user\n */\nexport interface CreateUserInput {\n\tcognitoId: string;\n\temail: string;\n\taccountId: string;\n\tbrandIds?: string[];\n\troles?: string[];\n\tpermissions?: Record<string, any>;\n\tstatus?: \"active\" | \"inactive\" | \"pending\" | \"suspended\";\n}\n\n/**\n * Input type for updating a user\n */\nexport interface UpdateUserInput {\n\tid: string;\n\temail?: string;\n\tbrandIds?: string[];\n\troles?: string[];\n\tpermissions?: Record<string, any>;\n\tlastLogin?: string;\n\tstatus?: \"active\" | \"inactive\" | \"pending\" | \"suspended\";\n}\n\n/**\n * Create a new user\n *\n * @example\n * ```typescript\n * import { createUser } from '@htlkg/data/mutations';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * const user = await createUser(client, {\n * cognitoId: 'cognito-123',\n * email: 'user@example.com',\n * accountId: 'account-123',\n * roles: ['BRAND_ADMIN'],\n * status: 'active'\n * });\n * ```\n */\nexport async function createUser<TClient = any>(\n\tclient: TClient,\n\tinput: CreateUserInput,\n): Promise<User | null> {\n\ttry {\n\t\tconst { data, errors } = await (client as any).models.User.create(input);\n\n\t\tif (errors) {\n\t\t\tconsole.error(\"[createUser] GraphQL errors:\", errors);\n\t\t\treturn null;\n\t\t}\n\n\t\treturn data as User;\n\t} catch (error) {\n\t\tconsole.error(\"[createUser] Error creating user:\", error);\n\t\tthrow error;\n\t}\n}\n\n/**\n * Update an existing user\n *\n * @example\n * ```typescript\n * import { updateUser } from '@htlkg/data/mutations';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * const user = await updateUser(client, {\n * id: 'user-123',\n * roles: ['BRAND_ADMIN', 'ACCOUNT_ADMIN'],\n * status: 'active'\n * });\n * ```\n */\nexport async function updateUser<TClient = any>(\n\tclient: TClient,\n\tinput: UpdateUserInput,\n): Promise<User | null> {\n\ttry {\n\t\tconst { data, errors } = await (client as any).models.User.update(input);\n\n\t\tif (errors) {\n\t\t\tconsole.error(\"[updateUser] GraphQL errors:\", errors);\n\t\t\treturn null;\n\t\t}\n\n\t\treturn data as User;\n\t} catch (error) {\n\t\tconsole.error(\"[updateUser] Error updating user:\", error);\n\t\tthrow error;\n\t}\n}\n\n/**\n * Delete a user\n *\n * @example\n * ```typescript\n * import { deleteUser } from '@htlkg/data/mutations';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * await deleteUser(client, 'user-123');\n * ```\n */\nexport async function deleteUser<TClient = any>(\n\tclient: TClient,\n\tid: string,\n): Promise<boolean> {\n\ttry {\n\t\tconst { errors } = await (client as any).models.User.delete({ id });\n\n\t\tif (errors) {\n\t\t\tconsole.error(\"[deleteUser] GraphQL errors:\", errors);\n\t\t\treturn false;\n\t\t}\n\n\t\treturn true;\n\t} catch (error) {\n\t\tconsole.error(\"[deleteUser] Error deleting user:\", error);\n\t\tthrow error;\n\t}\n}\n"],"mappings":";AAiDA,eAAsB,YACrB,QACA,OACwB;AACxB,MAAI;AACH,UAAM,EAAE,MAAM,OAAO,IAAI,MAAO,OAAe,OAAO,MAAM,OAAO,KAAK;AAExE,QAAI,QAAQ;AACX,cAAQ,MAAM,iCAAiC,MAAM;AACrD,aAAO;AAAA,IACR;AAEA,WAAO;AAAA,EACR,SAAS,OAAO;AACf,YAAQ,MAAM,uCAAuC,KAAK;AAC1D,UAAM;AAAA,EACP;AACD;AAkBA,eAAsB,YACrB,QACA,OACwB;AACxB,MAAI;AACH,UAAM,EAAE,MAAM,OAAO,IAAI,MAAO,OAAe,OAAO,MAAM,OAAO,KAAK;AAExE,QAAI,QAAQ;AACX,cAAQ,MAAM,iCAAiC,MAAM;AACrD,aAAO;AAAA,IACR;AAEA,WAAO;AAAA,EACR,SAAS,OAAO;AACf,YAAQ,MAAM,uCAAuC,KAAK;AAC1D,UAAM;AAAA,EACP;AACD;AAcA,eAAsB,YACrB,QACA,IACmB;AACnB,MAAI;AACH,UAAM,EAAE,OAAO,IAAI,MAAO,OAAe,OAAO,MAAM,OAAO,EAAE,GAAG,CAAC;AAEnE,QAAI,QAAQ;AACX,cAAQ,MAAM,iCAAiC,MAAM;AACrD,aAAO;AAAA,IACR;AAEA,WA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;AAAA,EACP;AACD;AAkBA,eAAsB,WACrB,QACA,OACuB;AACvB,MAAI;AACH,UAAM,EAAE,MAAM,OAAO,IAAI,MAAO,OAAe,OAAO,KAAK,OAAO,KAAK;AAEvE,QAAI,QAAQ;AACX,cAAQ,MAAM,gCAAgC,MAAM;AACpD,aAAO;AAAA,IACR;AAEA,WAAO;AAAA,EACR,SAAS,OAAO;AACf,YAAQ,MAAM,qCAAqC,KAAK;AACxD,UAAM;AAAA,EACP;AACD;AAcA,eAAsB,WACrB,QACA,IACmB;AACnB,MAAI;AACH,UAAM,EAAE,OAAO,IAAI,MAAO,OAAe,OAAO,KAAK,OAAO,EAAE,GAAG,CAAC;AAElE,QAAI,QAAQ;AACX,cAAQ,MAAM,gCAAgC,MAAM;AACpD,aAAO;AAAA,IACR;AAEA,WAAO;AAAA,EACR,SAAS,OAAO;AACf,YAAQ,MAAM,qCAAqC,KAAK;AACxD,UAAM;AAAA,EACP;AACD;","names":[]}
1
+ {"version":3,"sources":["../../src/queries/systemSettings.ts","../../src/mutations/brands.ts","../../src/mutations/accounts.ts","../../src/mutations/users.ts","../../src/mutations/productInstances/productInstances.ts","../../src/mutations/systemSettings.ts"],"sourcesContent":["/**\n * SystemSettings Query Functions\n *\n * Provides query functions for fetching system settings from the GraphQL API.\n */\n\nimport type { SystemSettings } from \"@htlkg/core/types\";\n\n/** Default retention days if no settings exist */\nexport const DEFAULT_SOFT_DELETE_RETENTION_DAYS = 30;\n\n/** The key used for global system settings */\nexport const SYSTEM_SETTINGS_KEY = \"GLOBAL\";\n\n/**\n * Get system settings\n *\n * @example\n * ```typescript\n * import { getSystemSettings } from '@htlkg/data/queries';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * const settings = await getSystemSettings(client);\n * ```\n */\nexport async function getSystemSettings<TClient = any>(\n\tclient: TClient,\n): Promise<SystemSettings | null> {\n\ttry {\n\t\tconst { data, errors } = await (client as any).models.SystemSettings.get({\n\t\t\tkey: SYSTEM_SETTINGS_KEY,\n\t\t});\n\n\t\tif (errors) {\n\t\t\tconsole.error(\"[getSystemSettings] GraphQL errors:\", errors);\n\t\t\treturn null;\n\t\t}\n\n\t\treturn data as SystemSettings;\n\t} catch (error) {\n\t\tconsole.error(\"[getSystemSettings] Error fetching system settings:\", error);\n\t\tthrow error;\n\t}\n}\n\n/**\n * Get the soft delete retention days from system settings\n * Returns the default (30 days) if settings don't exist\n *\n * @example\n * ```typescript\n * import { getSoftDeleteRetentionDays } from '@htlkg/data/queries';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * const days = await getSoftDeleteRetentionDays(client);\n * ```\n */\nexport async function getSoftDeleteRetentionDays<TClient = any>(\n\tclient: TClient,\n): Promise<number> {\n\tconst settings = await getSystemSettings(client);\n\treturn settings?.softDeleteRetentionDays ?? DEFAULT_SOFT_DELETE_RETENTION_DAYS;\n}\n\n/**\n * Check if a soft-deleted item can still be restored based on retention period\n *\n * @param deletedAt - The ISO date string when the item was deleted\n * @param retentionDays - Number of days items can be restored\n * @returns Object with canRestore flag and daysRemaining/daysExpired\n */\nexport function checkRestoreEligibility(\n\tdeletedAt: string | undefined | null,\n\tretentionDays: number,\n): {\n\tcanRestore: boolean;\n\tdaysRemaining: number;\n\tdaysExpired: number;\n\texpiresAt: Date | null;\n} {\n\tif (!deletedAt) {\n\t\treturn {\n\t\t\tcanRestore: false,\n\t\t\tdaysRemaining: 0,\n\t\t\tdaysExpired: 0,\n\t\t\texpiresAt: null,\n\t\t};\n\t}\n\n\tconst deletedDate = new Date(deletedAt);\n\tconst expiresAt = new Date(deletedDate);\n\texpiresAt.setDate(expiresAt.getDate() + retentionDays);\n\n\tconst now = new Date();\n\tconst msRemaining = expiresAt.getTime() - now.getTime();\n\tconst daysRemaining = Math.ceil(msRemaining / (1000 * 60 * 60 * 24));\n\n\tif (daysRemaining <= 0) {\n\t\treturn {\n\t\t\tcanRestore: false,\n\t\t\tdaysRemaining: 0,\n\t\t\tdaysExpired: Math.abs(daysRemaining),\n\t\t\texpiresAt,\n\t\t};\n\t}\n\n\treturn {\n\t\tcanRestore: true,\n\t\tdaysRemaining,\n\t\tdaysExpired: 0,\n\t\texpiresAt,\n\t};\n}\n","/**\n * Brand Mutation Functions\n *\n * Provides mutation functions for creating, updating, and deleting brands.\n */\n\nimport type { Brand } from \"@htlkg/core/types\";\nimport {\n\tcheckRestoreEligibility,\n\tDEFAULT_SOFT_DELETE_RETENTION_DAYS,\n} from \"../queries/systemSettings\";\n\n/**\n * Input type for creating a brand\n */\nexport interface CreateBrandInput {\n\taccountId: string;\n\tname: string;\n\tlogo?: string;\n\ttimezone?: string;\n\tstatus?: \"active\" | \"inactive\" | \"maintenance\" | \"suspended\";\n\tsettings?: Record<string, any>;\n}\n\n/**\n * Input type for updating a brand\n */\nexport interface UpdateBrandInput {\n\tid: string;\n\tname?: string;\n\tlogo?: string;\n\ttimezone?: string;\n\tstatus?: \"active\" | \"inactive\" | \"maintenance\" | \"suspended\";\n\tsettings?: Record<string, any>;\n}\n\n/**\n * Create a new brand\n *\n * @example\n * ```typescript\n * import { createBrand } from '@htlkg/data/mutations';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * const brand = await createBrand(client, {\n * accountId: 'account-123',\n * name: 'My Brand',\n * timezone: 'America/New_York',\n * status: 'active'\n * });\n * ```\n */\nexport async function createBrand<TClient = any>(\n\tclient: TClient,\n\tinput: CreateBrandInput,\n): Promise<Brand | null> {\n\ttry {\n\t\tconst { data, errors } = await (client as any).models.Brand.create(input);\n\n\t\tif (errors) {\n\t\t\tconsole.error(\"[createBrand] GraphQL errors:\", errors);\n\t\t\treturn null;\n\t\t}\n\n\t\treturn data as Brand;\n\t} catch (error) {\n\t\tconsole.error(\"[createBrand] Error creating brand:\", error);\n\t\tthrow error;\n\t}\n}\n\n/**\n * Update an existing brand\n *\n * @example\n * ```typescript\n * import { updateBrand } from '@htlkg/data/mutations';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * const brand = await updateBrand(client, {\n * id: 'brand-123',\n * name: 'Updated Brand Name',\n * status: 'maintenance'\n * });\n * ```\n */\nexport async function updateBrand<TClient = any>(\n\tclient: TClient,\n\tinput: UpdateBrandInput,\n): Promise<Brand | null> {\n\ttry {\n\t\tconst { data, errors } = await (client as any).models.Brand.update(input);\n\n\t\tif (errors) {\n\t\t\tconsole.error(\"[updateBrand] GraphQL errors:\", errors);\n\t\t\treturn null;\n\t\t}\n\n\t\treturn data as Brand;\n\t} catch (error) {\n\t\tconsole.error(\"[updateBrand] Error updating brand:\", error);\n\t\tthrow error;\n\t}\n}\n\n/**\n * Soft delete a brand (sets status to \"deleted\" instead of removing)\n *\n * @example\n * ```typescript\n * import { softDeleteBrand } from '@htlkg/data/mutations';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * await softDeleteBrand(client, 'brand-123', 'admin@example.com');\n * ```\n */\nexport async function softDeleteBrand<TClient = any>(\n\tclient: TClient,\n\tid: string,\n\tdeletedBy: string,\n): Promise<boolean> {\n\ttry {\n\t\tconst { errors } = await (client as any).models.Brand.update({\n\t\t\tid,\n\t\t\tstatus: \"deleted\",\n\t\t\tdeletedAt: new Date().toISOString(),\n\t\t\tdeletedBy,\n\t\t});\n\n\t\tif (errors) {\n\t\t\tconsole.error(\"[softDeleteBrand] GraphQL errors:\", errors);\n\t\t\treturn false;\n\t\t}\n\n\t\treturn true;\n\t} catch (error) {\n\t\tconsole.error(\"[softDeleteBrand] Error soft-deleting brand:\", error);\n\t\tthrow error;\n\t}\n}\n\n/**\n * Restore a soft-deleted brand (sets status back to \"active\")\n * Checks retention period before allowing restoration\n *\n * @example\n * ```typescript\n * import { restoreBrand } from '@htlkg/data/mutations';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * await restoreBrand(client, 'brand-123');\n * // Or with custom retention days:\n * await restoreBrand(client, 'brand-123', 60);\n * ```\n */\nexport async function restoreBrand<TClient = any>(\n\tclient: TClient,\n\tid: string,\n\tretentionDays: number = DEFAULT_SOFT_DELETE_RETENTION_DAYS,\n): Promise<{ success: boolean; error?: string }> {\n\ttry {\n\t\t// First, get the brand to check its deletedAt timestamp\n\t\tconst { data: brand, errors: getErrors } = await (\n\t\t\tclient as any\n\t\t).models.Brand.get({ id });\n\n\t\tif (getErrors || !brand) {\n\t\t\tconsole.error(\"[restoreBrand] Error fetching brand:\", getErrors);\n\t\t\treturn { success: false, error: \"Brand not found\" };\n\t\t}\n\n\t\t// Check if restoration is allowed based on retention period\n\t\tconst eligibility = checkRestoreEligibility(brand.deletedAt, retentionDays);\n\n\t\tif (!eligibility.canRestore) {\n\t\t\tconst errorMsg = `Cannot restore brand. Retention period of ${retentionDays} days has expired. Item was deleted ${eligibility.daysExpired} days ago.`;\n\t\t\tconsole.error(\"[restoreBrand]\", errorMsg);\n\t\t\treturn { success: false, error: errorMsg };\n\t\t}\n\n\t\tconst { errors } = await (client as any).models.Brand.update({\n\t\t\tid,\n\t\t\tstatus: \"active\",\n\t\t\tdeletedAt: null,\n\t\t\tdeletedBy: null,\n\t\t});\n\n\t\tif (errors) {\n\t\t\tconsole.error(\"[restoreBrand] GraphQL errors:\", errors);\n\t\t\treturn { success: false, error: \"Failed to restore brand\" };\n\t\t}\n\n\t\treturn { success: true };\n\t} catch (error) {\n\t\tconsole.error(\"[restoreBrand] Error restoring brand:\", error);\n\t\tthrow error;\n\t}\n}\n\n/**\n * Hard delete a brand (permanently removes from database)\n * Use with caution - prefer softDeleteBrand for recoverable deletion\n *\n * @example\n * ```typescript\n * import { deleteBrand } from '@htlkg/data/mutations';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * await deleteBrand(client, 'brand-123');\n * ```\n */\nexport async function deleteBrand<TClient = any>(\n\tclient: TClient,\n\tid: string,\n): Promise<boolean> {\n\ttry {\n\t\tconst { errors } = await (client as any).models.Brand.delete({ id });\n\n\t\tif (errors) {\n\t\t\tconsole.error(\"[deleteBrand] GraphQL errors:\", errors);\n\t\t\treturn false;\n\t\t}\n\n\t\treturn true;\n\t} catch (error) {\n\t\tconsole.error(\"[deleteBrand] Error deleting brand:\", error);\n\t\tthrow error;\n\t}\n}\n","/**\n * Account Mutation Functions\n *\n * Provides mutation functions for creating, updating, and deleting accounts.\n */\n\nimport type { Account } from \"@htlkg/core/types\";\nimport {\n\tcheckRestoreEligibility,\n\tDEFAULT_SOFT_DELETE_RETENTION_DAYS,\n} from \"../queries/systemSettings\";\n\n/**\n * Input type for creating an account\n */\nexport interface CreateAccountInput {\n\tname: string;\n\tlogo?: string;\n\tsubscription?: Record<string, any>;\n\tsettings?: Record<string, any>;\n}\n\n/**\n * Input type for updating an account\n */\nexport interface UpdateAccountInput {\n\tid: string;\n\tname?: string;\n\tlogo?: string;\n\tsubscription?: Record<string, any>;\n\tsettings?: Record<string, any>;\n}\n\n/**\n * Create a new account\n *\n * @example\n * ```typescript\n * import { createAccount } from '@htlkg/data/mutations';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * const account = await createAccount(client, {\n * name: 'My Account',\n * subscription: { plan: 'premium' }\n * });\n * ```\n */\nexport async function createAccount<TClient = any>(\n\tclient: TClient,\n\tinput: CreateAccountInput,\n): Promise<Account | null> {\n\ttry {\n\t\tconst { data, errors } = await (client as any).models.Account.create(input);\n\n\t\tif (errors) {\n\t\t\tconsole.error(\"[createAccount] GraphQL errors:\", errors);\n\t\t\treturn null;\n\t\t}\n\n\t\treturn data as Account;\n\t} catch (error) {\n\t\tconsole.error(\"[createAccount] Error creating account:\", error);\n\t\tthrow error;\n\t}\n}\n\n/**\n * Update an existing account\n *\n * @example\n * ```typescript\n * import { updateAccount } from '@htlkg/data/mutations';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * const account = await updateAccount(client, {\n * id: 'account-123',\n * name: 'Updated Account Name'\n * });\n * ```\n */\nexport async function updateAccount<TClient = any>(\n\tclient: TClient,\n\tinput: UpdateAccountInput,\n): Promise<Account | null> {\n\ttry {\n\t\tconst { data, errors } = await (client as any).models.Account.update(input);\n\n\t\tif (errors) {\n\t\t\tconsole.error(\"[updateAccount] GraphQL errors:\", errors);\n\t\t\treturn null;\n\t\t}\n\n\t\treturn data as Account;\n\t} catch (error) {\n\t\tconsole.error(\"[updateAccount] Error updating account:\", error);\n\t\tthrow error;\n\t}\n}\n\n/**\n * Soft delete an account (sets status to \"deleted\" instead of removing)\n *\n * @example\n * ```typescript\n * import { softDeleteAccount } from '@htlkg/data/mutations';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * await softDeleteAccount(client, 'account-123', 'admin@example.com');\n * ```\n */\nexport async function softDeleteAccount<TClient = any>(\n\tclient: TClient,\n\tid: string,\n\tdeletedBy: string,\n): Promise<boolean> {\n\ttry {\n\t\tconst { errors } = await (client as any).models.Account.update({\n\t\t\tid,\n\t\t\tstatus: \"deleted\",\n\t\t\tdeletedAt: new Date().toISOString(),\n\t\t\tdeletedBy,\n\t\t});\n\n\t\tif (errors) {\n\t\t\tconsole.error(\"[softDeleteAccount] GraphQL errors:\", errors);\n\t\t\treturn false;\n\t\t}\n\n\t\treturn true;\n\t} catch (error) {\n\t\tconsole.error(\"[softDeleteAccount] Error soft-deleting account:\", error);\n\t\tthrow error;\n\t}\n}\n\n/**\n * Restore a soft-deleted account (sets status back to \"active\")\n * Checks retention period before allowing restoration\n *\n * @example\n * ```typescript\n * import { restoreAccount } from '@htlkg/data/mutations';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * await restoreAccount(client, 'account-123');\n * // Or with custom retention days:\n * await restoreAccount(client, 'account-123', 60);\n * ```\n */\nexport async function restoreAccount<TClient = any>(\n\tclient: TClient,\n\tid: string,\n\tretentionDays: number = DEFAULT_SOFT_DELETE_RETENTION_DAYS,\n): Promise<{ success: boolean; error?: string }> {\n\ttry {\n\t\t// First, get the account to check its deletedAt timestamp\n\t\tconst { data: account, errors: getErrors } = await (\n\t\t\tclient as any\n\t\t).models.Account.get({ id });\n\n\t\tif (getErrors || !account) {\n\t\t\tconsole.error(\"[restoreAccount] Error fetching account:\", getErrors);\n\t\t\treturn { success: false, error: \"Account not found\" };\n\t\t}\n\n\t\t// Check if restoration is allowed based on retention period\n\t\tconst eligibility = checkRestoreEligibility(account.deletedAt, retentionDays);\n\n\t\tif (!eligibility.canRestore) {\n\t\t\tconst errorMsg = `Cannot restore account. Retention period of ${retentionDays} days has expired. Item was deleted ${eligibility.daysExpired} days ago.`;\n\t\t\tconsole.error(\"[restoreAccount]\", errorMsg);\n\t\t\treturn { success: false, error: errorMsg };\n\t\t}\n\n\t\tconst { errors } = await (client as any).models.Account.update({\n\t\t\tid,\n\t\t\tstatus: \"active\",\n\t\t\tdeletedAt: null,\n\t\t\tdeletedBy: null,\n\t\t});\n\n\t\tif (errors) {\n\t\t\tconsole.error(\"[restoreAccount] GraphQL errors:\", errors);\n\t\t\treturn { success: false, error: \"Failed to restore account\" };\n\t\t}\n\n\t\treturn { success: true };\n\t} catch (error) {\n\t\tconsole.error(\"[restoreAccount] Error restoring account:\", error);\n\t\tthrow error;\n\t}\n}\n\n/**\n * Hard delete an account (permanently removes from database)\n * Use with caution - prefer softDeleteAccount for recoverable deletion\n *\n * @example\n * ```typescript\n * import { deleteAccount } from '@htlkg/data/mutations';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * await deleteAccount(client, 'account-123');\n * ```\n */\nexport async function deleteAccount<TClient = any>(\n\tclient: TClient,\n\tid: string,\n): Promise<boolean> {\n\ttry {\n\t\tconst { errors } = await (client as any).models.Account.delete({ id });\n\n\t\tif (errors) {\n\t\t\tconsole.error(\"[deleteAccount] GraphQL errors:\", errors);\n\t\t\treturn false;\n\t\t}\n\n\t\treturn true;\n\t} catch (error) {\n\t\tconsole.error(\"[deleteAccount] Error deleting account:\", error);\n\t\tthrow error;\n\t}\n}\n","/**\n * User Mutation Functions\n *\n * Provides mutation functions for creating, updating, and deleting users.\n */\n\nimport type { User } from \"@htlkg/core/types\";\nimport {\n\tcheckRestoreEligibility,\n\tDEFAULT_SOFT_DELETE_RETENTION_DAYS,\n} from \"../queries/systemSettings\";\n\n/**\n * Input type for creating a user\n */\nexport interface CreateUserInput {\n\tcognitoId: string;\n\temail: string;\n\taccountId: string;\n\tbrandIds?: string[];\n\troles?: string[];\n\tpermissions?: Record<string, any>;\n\tstatus?: \"active\" | \"inactive\" | \"pending\" | \"suspended\";\n}\n\n/**\n * Input type for updating a user\n */\nexport interface UpdateUserInput {\n\tid: string;\n\temail?: string;\n\tbrandIds?: string[];\n\troles?: string[];\n\tpermissions?: Record<string, any>;\n\tlastLogin?: string;\n\tstatus?: \"active\" | \"inactive\" | \"pending\" | \"suspended\";\n}\n\n/**\n * Create a new user\n *\n * @example\n * ```typescript\n * import { createUser } from '@htlkg/data/mutations';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * const user = await createUser(client, {\n * cognitoId: 'cognito-123',\n * email: 'user@example.com',\n * accountId: 'account-123',\n * roles: ['BRAND_ADMIN'],\n * status: 'active'\n * });\n * ```\n */\nexport async function createUser<TClient = any>(\n\tclient: TClient,\n\tinput: CreateUserInput,\n): Promise<User | null> {\n\ttry {\n\t\tconst { data, errors } = await (client as any).models.User.create(input);\n\n\t\tif (errors) {\n\t\t\tconsole.error(\"[createUser] GraphQL errors:\", errors);\n\t\t\treturn null;\n\t\t}\n\n\t\treturn data as User;\n\t} catch (error) {\n\t\tconsole.error(\"[createUser] Error creating user:\", error);\n\t\tthrow error;\n\t}\n}\n\n/**\n * Update an existing user\n *\n * @example\n * ```typescript\n * import { updateUser } from '@htlkg/data/mutations';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * const user = await updateUser(client, {\n * id: 'user-123',\n * roles: ['BRAND_ADMIN', 'ACCOUNT_ADMIN'],\n * status: 'active'\n * });\n * ```\n */\nexport async function updateUser<TClient = any>(\n\tclient: TClient,\n\tinput: UpdateUserInput,\n): Promise<User | null> {\n\ttry {\n\t\tconst { data, errors } = await (client as any).models.User.update(input);\n\n\t\tif (errors) {\n\t\t\tconsole.error(\"[updateUser] GraphQL errors:\", errors);\n\t\t\treturn null;\n\t\t}\n\n\t\treturn data as User;\n\t} catch (error) {\n\t\tconsole.error(\"[updateUser] Error updating user:\", error);\n\t\tthrow error;\n\t}\n}\n\n/**\n * Soft delete a user (sets status to \"deleted\" instead of removing)\n *\n * @example\n * ```typescript\n * import { softDeleteUser } from '@htlkg/data/mutations';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * await softDeleteUser(client, 'user-123', 'admin@example.com');\n * ```\n */\nexport async function softDeleteUser<TClient = any>(\n\tclient: TClient,\n\tid: string,\n\tdeletedBy: string,\n): Promise<boolean> {\n\ttry {\n\t\tconst { errors } = await (client as any).models.User.update({\n\t\t\tid,\n\t\t\tstatus: \"deleted\",\n\t\t\tdeletedAt: new Date().toISOString(),\n\t\t\tdeletedBy,\n\t\t});\n\n\t\tif (errors) {\n\t\t\tconsole.error(\"[softDeleteUser] GraphQL errors:\", errors);\n\t\t\treturn false;\n\t\t}\n\n\t\treturn true;\n\t} catch (error) {\n\t\tconsole.error(\"[softDeleteUser] Error soft-deleting user:\", error);\n\t\tthrow error;\n\t}\n}\n\n/**\n * Restore a soft-deleted user (sets status back to \"active\")\n * Checks retention period before allowing restoration\n *\n * @example\n * ```typescript\n * import { restoreUser } from '@htlkg/data/mutations';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * await restoreUser(client, 'user-123');\n * // Or with custom retention days:\n * await restoreUser(client, 'user-123', 60);\n * ```\n */\nexport async function restoreUser<TClient = any>(\n\tclient: TClient,\n\tid: string,\n\tretentionDays: number = DEFAULT_SOFT_DELETE_RETENTION_DAYS,\n): Promise<{ success: boolean; error?: string }> {\n\ttry {\n\t\t// First, get the user to check its deletedAt timestamp\n\t\tconst { data: user, errors: getErrors } = await (\n\t\t\tclient as any\n\t\t).models.User.get({ id });\n\n\t\tif (getErrors || !user) {\n\t\t\tconsole.error(\"[restoreUser] Error fetching user:\", getErrors);\n\t\t\treturn { success: false, error: \"User not found\" };\n\t\t}\n\n\t\t// Check if restoration is allowed based on retention period\n\t\tconst eligibility = checkRestoreEligibility(user.deletedAt, retentionDays);\n\n\t\tif (!eligibility.canRestore) {\n\t\t\tconst errorMsg = `Cannot restore user. Retention period of ${retentionDays} days has expired. Item was deleted ${eligibility.daysExpired} days ago.`;\n\t\t\tconsole.error(\"[restoreUser]\", errorMsg);\n\t\t\treturn { success: false, error: errorMsg };\n\t\t}\n\n\t\tconst { errors } = await (client as any).models.User.update({\n\t\t\tid,\n\t\t\tstatus: \"active\",\n\t\t\tdeletedAt: null,\n\t\t\tdeletedBy: null,\n\t\t});\n\n\t\tif (errors) {\n\t\t\tconsole.error(\"[restoreUser] GraphQL errors:\", errors);\n\t\t\treturn { success: false, error: \"Failed to restore user\" };\n\t\t}\n\n\t\treturn { success: true };\n\t} catch (error) {\n\t\tconsole.error(\"[restoreUser] Error restoring user:\", error);\n\t\tthrow error;\n\t}\n}\n\n/**\n * Hard delete a user (permanently removes from database)\n * Use with caution - prefer softDeleteUser for recoverable deletion\n *\n * @example\n * ```typescript\n * import { deleteUser } from '@htlkg/data/mutations';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * await deleteUser(client, 'user-123');\n * ```\n */\nexport async function deleteUser<TClient = any>(\n\tclient: TClient,\n\tid: string,\n): Promise<boolean> {\n\ttry {\n\t\tconst { errors } = await (client as any).models.User.delete({ id });\n\n\t\tif (errors) {\n\t\t\tconsole.error(\"[deleteUser] GraphQL errors:\", errors);\n\t\t\treturn false;\n\t\t}\n\n\t\treturn true;\n\t} catch (error) {\n\t\tconsole.error(\"[deleteUser] Error deleting user:\", error);\n\t\tthrow error;\n\t}\n}\n","/**\n * ProductInstance Mutation Functions\n *\n * Provides mutation functions for creating, updating, and deleting product instances.\n * Product instances represent enabled products for a specific brand with their configuration.\n */\n\nimport type { ProductInstance } from \"@htlkg/core/types\";\nimport { getClientUser } from \"@htlkg/core/auth\";\nimport { getCurrentTimestamp } from \"@htlkg/core/utils\";\nimport { AppError } from \"@htlkg/core/errors\";\n\n/**\n * Get current user identifier for audit trails\n * Uses getClientUser() and returns email or username, falling back to \"system\"\n */\nasync function getUserIdentifier(fallback = \"system\"): Promise<string> {\n\ttry {\n\t\tconst user = await getClientUser();\n\t\tif (user) {\n\t\t\treturn user.email || user.username || fallback;\n\t\t}\n\t\treturn fallback;\n\t} catch {\n\t\treturn fallback;\n\t}\n}\n\n/**\n * Input type for creating a product instance\n */\nexport interface CreateProductInstanceInput {\n\tproductId: string;\n\tbrandId: string;\n\taccountId: string;\n\tproductName: string;\n\tenabled: boolean;\n\tconfig?: Record<string, any>;\n\tversion?: string;\n\tlastUpdated?: string;\n\tupdatedBy?: string;\n}\n\n/**\n * Input type for updating a product instance\n */\nexport interface UpdateProductInstanceInput {\n\tid: string;\n\tenabled?: boolean;\n\tconfig?: Record<string, any>;\n\tversion?: string;\n\tlastUpdated?: string;\n\tupdatedBy?: string;\n}\n\n/**\n * Create a new product instance\n *\n * @example\n * ```typescript\n * import { createProductInstance } from '@htlkg/data/mutations';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * const instance = await createProductInstance(client, {\n * productId: 'product-123',\n * brandId: 'brand-456',\n * accountId: 'account-789',\n * enabled: true,\n * config: { apiKey: 'xxx', maxRequests: 100 }\n * });\n * ```\n */\nexport async function createProductInstance<TClient = any>(\n\tclient: TClient,\n\tinput: CreateProductInstanceInput,\n): Promise<ProductInstance | null> {\n\ttry {\n\t\t// Build input - manually construct to avoid Vue Proxy issues\n\t\tconst createInput: any = {\n\t\t\tproductId: input.productId,\n\t\t\tproductName: input.productName,\n\t\t\tbrandId: input.brandId,\n\t\t\taccountId: input.accountId,\n\t\t\tenabled: input.enabled,\n\t\t\tversion: input.version,\n\t\t\tlastUpdated: input.lastUpdated || getCurrentTimestamp(),\n\t\t\tupdatedBy: input.updatedBy || await getUserIdentifier(),\n\t\t};\n\n\t\t// AWSJSON type requires JSON STRING\n\t\tif (input.config) {\n\t\t\t// Double stringify: first to strip Vue Proxy, second to create JSON string\n\t\t\tcreateInput.config = JSON.stringify(JSON.parse(JSON.stringify(input.config)));\n\t\t}\n\n\t\tconsole.log(\"[createProductInstance] Config as string:\", createInput.config);\n\t\tconsole.log(\"[createProductInstance] Config type:\", typeof createInput.config);\n\n\t\tconst { data, errors } = await (client as any).models.ProductInstance.create(createInput);\n\n\t\tif (errors) {\n\t\t\tconsole.error(\"[createProductInstance] GraphQL errors:\", errors);\n\t\t\tthrow new AppError(\n\t\t\t\t\"Failed to create product instance\",\n\t\t\t\t\"PRODUCT_INSTANCE_CREATE_ERROR\",\n\t\t\t\t500,\n\t\t\t\t{ errors }\n\t\t\t);\n\t\t}\n\n\t\treturn data as ProductInstance;\n\t} catch (error) {\n\t\tconsole.error(\"[createProductInstance] Error creating product instance:\", error);\n\t\tif (error instanceof AppError) {\n\t\t\tthrow error;\n\t\t}\n\t\tthrow new AppError(\n\t\t\t\"Failed to create product instance\",\n\t\t\t\"PRODUCT_INSTANCE_CREATE_ERROR\",\n\t\t\t500,\n\t\t\t{ originalError: error }\n\t\t);\n\t}\n}\n\n/**\n * Update an existing product instance\n *\n * @example\n * ```typescript\n * import { updateProductInstance } from '@htlkg/data/mutations';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * const instance = await updateProductInstance(client, {\n * id: 'instance-123',\n * enabled: false,\n * config: { apiKey: 'new-key', maxRequests: 200 }\n * });\n * ```\n */\nexport async function updateProductInstance<TClient = any>(\n\tclient: TClient,\n\tinput: UpdateProductInstanceInput,\n): Promise<ProductInstance | null> {\n\ttry {\n\t\t// Add timestamp and user metadata if not provided\n\t\t// Convert config from Vue Proxy to plain object\n\t\tconst updateInput: any = {\n\t\t\t...input,\n\t\t\tlastUpdated: input.lastUpdated || getCurrentTimestamp(),\n\t\t\tupdatedBy: input.updatedBy || await getUserIdentifier(),\n\t\t};\n\n\t\t// AWSJSON type requires JSON STRING\n\t\tif (input.config) {\n\t\t\tupdateInput.config = JSON.stringify(JSON.parse(JSON.stringify(input.config)));\n\t\t}\n\n\t\tconst { data, errors } = await (client as any).models.ProductInstance.update(updateInput);\n\n\t\tif (errors) {\n\t\t\tconsole.error(\"[updateProductInstance] GraphQL errors:\", errors);\n\t\t\tthrow new AppError(\n\t\t\t\t\"Failed to update product instance\",\n\t\t\t\t\"PRODUCT_INSTANCE_UPDATE_ERROR\",\n\t\t\t\t500,\n\t\t\t\t{ errors }\n\t\t\t);\n\t\t}\n\n\t\treturn data as ProductInstance;\n\t} catch (error) {\n\t\tconsole.error(\"[updateProductInstance] Error updating product instance:\", error);\n\t\tif (error instanceof AppError) {\n\t\t\tthrow error;\n\t\t}\n\t\tthrow new AppError(\n\t\t\t\"Failed to update product instance\",\n\t\t\t\"PRODUCT_INSTANCE_UPDATE_ERROR\",\n\t\t\t500,\n\t\t\t{ originalError: error }\n\t\t);\n\t}\n}\n\n/**\n * Delete a product instance\n *\n * @example\n * ```typescript\n * import { deleteProductInstance } from '@htlkg/data/mutations';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * await deleteProductInstance(client, 'instance-123');\n * ```\n */\nexport async function deleteProductInstance<TClient = any>(\n\tclient: TClient,\n\tid: string,\n): Promise<boolean> {\n\ttry {\n\t\tconst { errors } = await (client as any).models.ProductInstance.delete({ id });\n\n\t\tif (errors) {\n\t\t\tconsole.error(\"[deleteProductInstance] GraphQL errors:\", errors);\n\t\t\tthrow new AppError(\n\t\t\t\t\"Failed to delete product instance\",\n\t\t\t\t\"PRODUCT_INSTANCE_DELETE_ERROR\",\n\t\t\t\t500,\n\t\t\t\t{ errors }\n\t\t\t);\n\t\t}\n\n\t\treturn true;\n\t} catch (error) {\n\t\tconsole.error(\"[deleteProductInstance] Error deleting product instance:\", error);\n\t\tif (error instanceof AppError) {\n\t\t\tthrow error;\n\t\t}\n\t\tthrow new AppError(\n\t\t\t\"Failed to delete product instance\",\n\t\t\t\"PRODUCT_INSTANCE_DELETE_ERROR\",\n\t\t\t500,\n\t\t\t{ originalError: error }\n\t\t);\n\t}\n}\n\n/**\n * Toggle the enabled status of a product instance\n *\n * @example\n * ```typescript\n * import { toggleProductInstanceEnabled } from '@htlkg/data/mutations';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * const instance = await toggleProductInstanceEnabled(client, 'instance-123', true);\n * ```\n */\nexport async function toggleProductInstanceEnabled<TClient = any>(\n\tclient: TClient,\n\tid: string,\n\tenabled: boolean,\n): Promise<ProductInstance | null> {\n\ttry {\n\t\tconst { data, errors } = await (client as any).models.ProductInstance.update({\n\t\t\tid,\n\t\t\tenabled,\n\t\t\tlastUpdated: getCurrentTimestamp(),\n\t\t\tupdatedBy: await getUserIdentifier(),\n\t\t});\n\n\t\tif (errors) {\n\t\t\tconsole.error(\"[toggleProductInstanceEnabled] GraphQL errors:\", errors);\n\t\t\tthrow new AppError(\n\t\t\t\t\"Failed to toggle product instance\",\n\t\t\t\t\"PRODUCT_INSTANCE_TOGGLE_ERROR\",\n\t\t\t\t500,\n\t\t\t\t{ errors }\n\t\t\t);\n\t\t}\n\n\t\treturn data as ProductInstance;\n\t} catch (error) {\n\t\tconsole.error(\"[toggleProductInstanceEnabled] Error toggling product instance:\", error);\n\t\tif (error instanceof AppError) {\n\t\t\tthrow error;\n\t\t}\n\t\tthrow new AppError(\n\t\t\t\"Failed to toggle product instance\",\n\t\t\t\"PRODUCT_INSTANCE_TOGGLE_ERROR\",\n\t\t\t500,\n\t\t\t{ originalError: error }\n\t\t);\n\t}\n}\n","/**\n * SystemSettings Mutation Functions\n *\n * Provides mutation functions for managing system settings.\n */\n\nimport type { SystemSettings } from \"@htlkg/core/types\";\nimport {\n\tSYSTEM_SETTINGS_KEY,\n\tDEFAULT_SOFT_DELETE_RETENTION_DAYS,\n} from \"../queries/systemSettings\";\n\n/**\n * Input type for updating system settings\n */\nexport interface UpdateSystemSettingsInput {\n\tsoftDeleteRetentionDays: number;\n\tupdatedBy: string;\n}\n\n/**\n * Update or create system settings\n * Only SUPER_ADMINS can update system settings\n *\n * @example\n * ```typescript\n * import { updateSystemSettings } from '@htlkg/data/mutations';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * const settings = await updateSystemSettings(client, {\n * softDeleteRetentionDays: 60,\n * updatedBy: 'admin@example.com'\n * });\n * ```\n */\nexport async function updateSystemSettings<TClient = any>(\n\tclient: TClient,\n\tinput: UpdateSystemSettingsInput,\n): Promise<SystemSettings | null> {\n\ttry {\n\t\t// Validate retention days (minimum 1 day, maximum 365 days)\n\t\tif (input.softDeleteRetentionDays < 1 || input.softDeleteRetentionDays > 365) {\n\t\t\tconsole.error(\n\t\t\t\t\"[updateSystemSettings] Invalid retention days. Must be between 1 and 365.\",\n\t\t\t);\n\t\t\treturn null;\n\t\t}\n\n\t\t// First, try to get existing settings\n\t\tconst { data: existing } = await (client as any).models.SystemSettings.get({\n\t\t\tkey: SYSTEM_SETTINGS_KEY,\n\t\t});\n\n\t\tconst settingsData = {\n\t\t\tkey: SYSTEM_SETTINGS_KEY,\n\t\t\tsoftDeleteRetentionDays: input.softDeleteRetentionDays,\n\t\t\tupdatedAt: new Date().toISOString(),\n\t\t\tupdatedBy: input.updatedBy,\n\t\t};\n\n\t\tlet result;\n\t\tif (existing) {\n\t\t\t// Update existing settings\n\t\t\tresult = await (client as any).models.SystemSettings.update(settingsData);\n\t\t} else {\n\t\t\t// Create new settings\n\t\t\tresult = await (client as any).models.SystemSettings.create(settingsData);\n\t\t}\n\n\t\tif (result.errors) {\n\t\t\tconsole.error(\"[updateSystemSettings] GraphQL errors:\", result.errors);\n\t\t\treturn null;\n\t\t}\n\n\t\treturn result.data as SystemSettings;\n\t} catch (error) {\n\t\tconsole.error(\"[updateSystemSettings] Error updating system settings:\", error);\n\t\tthrow error;\n\t}\n}\n\n/**\n * Initialize system settings with default values if they don't exist\n *\n * @example\n * ```typescript\n * import { initializeSystemSettings } from '@htlkg/data/mutations';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * const settings = await initializeSystemSettings(client, 'system@hotelinking.com');\n * ```\n */\nexport async function initializeSystemSettings<TClient = any>(\n\tclient: TClient,\n\tinitializedBy: string,\n): Promise<SystemSettings | null> {\n\ttry {\n\t\t// Check if settings already exist\n\t\tconst { data: existing } = await (client as any).models.SystemSettings.get({\n\t\t\tkey: SYSTEM_SETTINGS_KEY,\n\t\t});\n\n\t\tif (existing) {\n\t\t\treturn existing as SystemSettings;\n\t\t}\n\n\t\t// Create default settings\n\t\tconst { data, errors } = await (client as any).models.SystemSettings.create({\n\t\t\tkey: SYSTEM_SETTINGS_KEY,\n\t\t\tsoftDeleteRetentionDays: DEFAULT_SOFT_DELETE_RETENTION_DAYS,\n\t\t\tupdatedAt: new Date().toISOString(),\n\t\t\tupdatedBy: initializedBy,\n\t\t});\n\n\t\tif (errors) {\n\t\t\tconsole.error(\"[initializeSystemSettings] GraphQL errors:\", errors);\n\t\t\treturn null;\n\t\t}\n\n\t\treturn data as SystemSettings;\n\t} catch (error) {\n\t\tconsole.error(\n\t\t\t\"[initializeSystemSettings] Error initializing system settings:\",\n\t\t\terror,\n\t\t);\n\t\tthrow error;\n\t}\n}\n"],"mappings":";AASO,IAAM,qCAAqC;AAG3C,IAAM,sBAAsB;AA6D5B,SAAS,wBACf,WACA,eAMC;AACD,MAAI,CAAC,WAAW;AACf,WAAO;AAAA,MACN,YAAY;AAAA,MACZ,eAAe;AAAA,MACf,aAAa;AAAA,MACb,WAAW;AAAA,IACZ;AAAA,EACD;AAEA,QAAM,cAAc,IAAI,KAAK,SAAS;AACtC,QAAM,YAAY,IAAI,K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ACD;","names":[]}
@@ -0,0 +1,98 @@
1
+ import { ProductInstance } from '@htlkg/core/types';
2
+
3
+ /**
4
+ * ProductInstance Mutation Functions
5
+ *
6
+ * Provides mutation functions for creating, updating, and deleting product instances.
7
+ * Product instances represent enabled products for a specific brand with their configuration.
8
+ */
9
+
10
+ /**
11
+ * Input type for creating a product instance
12
+ */
13
+ interface CreateProductInstanceInput {
14
+ productId: string;
15
+ brandId: string;
16
+ accountId: string;
17
+ productName: string;
18
+ enabled: boolean;
19
+ config?: Record<string, any>;
20
+ version?: string;
21
+ lastUpdated?: string;
22
+ updatedBy?: string;
23
+ }
24
+ /**
25
+ * Input type for updating a product instance
26
+ */
27
+ interface UpdateProductInstanceInput {
28
+ id: string;
29
+ enabled?: boolean;
30
+ config?: Record<string, any>;
31
+ version?: string;
32
+ lastUpdated?: string;
33
+ updatedBy?: string;
34
+ }
35
+ /**
36
+ * Create a new product instance
37
+ *
38
+ * @example
39
+ * ```typescript
40
+ * import { createProductInstance } from '@htlkg/data/mutations';
41
+ * import { generateClient } from '@htlkg/data/client';
42
+ *
43
+ * const client = generateClient<Schema>();
44
+ * const instance = await createProductInstance(client, {
45
+ * productId: 'product-123',
46
+ * brandId: 'brand-456',
47
+ * accountId: 'account-789',
48
+ * enabled: true,
49
+ * config: { apiKey: 'xxx', maxRequests: 100 }
50
+ * });
51
+ * ```
52
+ */
53
+ declare function createProductInstance<TClient = any>(client: TClient, input: CreateProductInstanceInput): Promise<ProductInstance | null>;
54
+ /**
55
+ * Update an existing product instance
56
+ *
57
+ * @example
58
+ * ```typescript
59
+ * import { updateProductInstance } from '@htlkg/data/mutations';
60
+ * import { generateClient } from '@htlkg/data/client';
61
+ *
62
+ * const client = generateClient<Schema>();
63
+ * const instance = await updateProductInstance(client, {
64
+ * id: 'instance-123',
65
+ * enabled: false,
66
+ * config: { apiKey: 'new-key', maxRequests: 200 }
67
+ * });
68
+ * ```
69
+ */
70
+ declare function updateProductInstance<TClient = any>(client: TClient, input: UpdateProductInstanceInput): Promise<ProductInstance | null>;
71
+ /**
72
+ * Delete a product instance
73
+ *
74
+ * @example
75
+ * ```typescript
76
+ * import { deleteProductInstance } from '@htlkg/data/mutations';
77
+ * import { generateClient } from '@htlkg/data/client';
78
+ *
79
+ * const client = generateClient<Schema>();
80
+ * await deleteProductInstance(client, 'instance-123');
81
+ * ```
82
+ */
83
+ declare function deleteProductInstance<TClient = any>(client: TClient, id: string): Promise<boolean>;
84
+ /**
85
+ * Toggle the enabled status of a product instance
86
+ *
87
+ * @example
88
+ * ```typescript
89
+ * import { toggleProductInstanceEnabled } from '@htlkg/data/mutations';
90
+ * import { generateClient } from '@htlkg/data/client';
91
+ *
92
+ * const client = generateClient<Schema>();
93
+ * const instance = await toggleProductInstanceEnabled(client, 'instance-123', true);
94
+ * ```
95
+ */
96
+ declare function toggleProductInstanceEnabled<TClient = any>(client: TClient, id: string, enabled: boolean): Promise<ProductInstance | null>;
97
+
98
+ export { type CreateProductInstanceInput as C, type UpdateProductInstanceInput as U, createProductInstance as c, deleteProductInstance as d, toggleProductInstanceEnabled as t, updateProductInstance as u };
@@ -1,8 +1,9 @@
1
- import { Brand, Account, User, Product, ProductInstance } from '@htlkg/core/types';
1
+ import { Brand, Account, User, Product, ProductInstance, SystemSettings } from '@htlkg/core/types';
2
2
  import { AstroGlobal } from 'astro';
3
3
  import { generateServerClient } from '../client/index.js';
4
4
  import 'aws-amplify/data';
5
5
  import 'aws-amplify';
6
+ import '../server/index.js';
6
7
  import 'aws-amplify/api/internals';
7
8
 
8
9
  /**
@@ -460,4 +461,55 @@ declare function executeServerQuery<TSchema extends Record<string, unknown>, TRe
460
461
  */
461
462
  declare function executePublicQuery<TSchema extends Record<string, unknown>, TResult>(astro: AstroGlobal, runWithAmplifyServerContext: RunWithAmplifyServerContext, operation: (client: ReturnType<typeof generateServerClient<TSchema>>) => Promise<TResult>): Promise<TResult>;
462
463
 
463
- export { executePublicQuery, executeServerQuery, getAccount, getAccountWithBrands, getBrand, getBrandWithProducts, getProduct, getProductInstance, getUser, getUserByCognitoId, getUserByEmail, listAccounts, listActiveBrands, listActiveProducts, listActiveUsers, listBrands, listBrandsByAccount, listEnabledProductInstancesByBrand, listProductInstancesByAccount, listProductInstancesByBrand, listProducts, listUsers, listUsersByAccount };
464
+ /**
465
+ * SystemSettings Query Functions
466
+ *
467
+ * Provides query functions for fetching system settings from the GraphQL API.
468
+ */
469
+
470
+ /** Default retention days if no settings exist */
471
+ declare const DEFAULT_SOFT_DELETE_RETENTION_DAYS = 30;
472
+ /** The key used for global system settings */
473
+ declare const SYSTEM_SETTINGS_KEY = "GLOBAL";
474
+ /**
475
+ * Get system settings
476
+ *
477
+ * @example
478
+ * ```typescript
479
+ * import { getSystemSettings } from '@htlkg/data/queries';
480
+ * import { generateClient } from '@htlkg/data/client';
481
+ *
482
+ * const client = generateClient<Schema>();
483
+ * const settings = await getSystemSettings(client);
484
+ * ```
485
+ */
486
+ declare function getSystemSettings<TClient = any>(client: TClient): Promise<SystemSettings | null>;
487
+ /**
488
+ * Get the soft delete retention days from system settings
489
+ * Returns the default (30 days) if settings don't exist
490
+ *
491
+ * @example
492
+ * ```typescript
493
+ * import { getSoftDeleteRetentionDays } from '@htlkg/data/queries';
494
+ * import { generateClient } from '@htlkg/data/client';
495
+ *
496
+ * const client = generateClient<Schema>();
497
+ * const days = await getSoftDeleteRetentionDays(client);
498
+ * ```
499
+ */
500
+ declare function getSoftDeleteRetentionDays<TClient = any>(client: TClient): Promise<number>;
501
+ /**
502
+ * Check if a soft-deleted item can still be restored based on retention period
503
+ *
504
+ * @param deletedAt - The ISO date string when the item was deleted
505
+ * @param retentionDays - Number of days items can be restored
506
+ * @returns Object with canRestore flag and daysRemaining/daysExpired
507
+ */
508
+ declare function checkRestoreEligibility(deletedAt: string | undefined | null, retentionDays: number): {
509
+ canRestore: boolean;
510
+ daysRemaining: number;
511
+ daysExpired: number;
512
+ expiresAt: Date | null;
513
+ };
514
+
515
+ export { DEFAULT_SOFT_DELETE_RETENTION_DAYS, SYSTEM_SETTINGS_KEY, checkRestoreEligibility, executePublicQuery, executeServerQuery, getAccount, getAccountWithBrands, getBrand, getBrandWithProducts, getProduct, getProductInstance, getSoftDeleteRetentionDays, getSystemSettings, getUser, getUserByCognitoId, getUserByEmail, listAccounts, listActiveBrands, listActiveProducts, listActiveUsers, listBrands, listBrandsByAccount, listEnabledProductInstancesByBrand, listProductInstancesByAccount, listProductInstancesByBrand, listProducts, listUsers, listUsersByAccount };
@@ -329,6 +329,7 @@ async function listEnabledProductInstancesByBrand(client, brandId, options) {
329
329
 
330
330
  // src/client/index.ts
331
331
  import { generateClient as generateDataClient } from "aws-amplify/data";
332
+ import { Amplify } from "aws-amplify";
332
333
 
333
334
  // src/client/server.ts
334
335
  import {
@@ -339,7 +340,7 @@ import { createRunWithAmplifyServerContext, createLogger } from "@htlkg/core/amp
339
340
  var log = createLogger("server-client");
340
341
 
341
342
  // src/client/index.ts
342
- function generateServerClient(options) {
343
+ function generateServerClient(_options) {
343
344
  const client = generateDataClient();
344
345
  return client;
345
346
  }
@@ -371,7 +372,63 @@ async function executePublicQuery(astro, runWithAmplifyServerContext, operation)
371
372
  });
372
373
  return result;
373
374
  }
375
+
376
+ // src/queries/systemSettings.ts
377
+ var DEFAULT_SOFT_DELETE_RETENTION_DAYS = 30;
378
+ var SYSTEM_SETTINGS_KEY = "GLOBAL";
379
+ async function getSystemSettings(client) {
380
+ try {
381
+ const { data, errors } = await client.models.SystemSettings.get({
382
+ key: SYSTEM_SETTINGS_KEY
383
+ });
384
+ if (errors) {
385
+ console.error("[getSystemSettings] GraphQL errors:", errors);
386
+ return null;
387
+ }
388
+ return data;
389
+ } catch (error) {
390
+ console.error("[getSystemSettings] Error fetching system settings:", error);
391
+ throw error;
392
+ }
393
+ }
394
+ async function getSoftDeleteRetentionDays(client) {
395
+ const settings = await getSystemSettings(client);
396
+ return settings?.softDeleteRetentionDays ?? DEFAULT_SOFT_DELETE_RETENTION_DAYS;
397
+ }
398
+ function checkRestoreEligibility(deletedAt, retentionDays) {
399
+ if (!deletedAt) {
400
+ return {
401
+ canRestore: false,
402
+ daysRemaining: 0,
403
+ daysExpired: 0,
404
+ expiresAt: null
405
+ };
406
+ }
407
+ const deletedDate = new Date(deletedAt);
408
+ const expiresAt = new Date(deletedDate);
409
+ expiresAt.setDate(expiresAt.getDate() + retentionDays);
410
+ const now = /* @__PURE__ */ new Date();
411
+ const msRemaining = expiresAt.getTime() - now.getTime();
412
+ const daysRemaining = Math.ceil(msRemaining / (1e3 * 60 * 60 * 24));
413
+ if (daysRemaining <= 0) {
414
+ return {
415
+ canRestore: false,
416
+ daysRemaining: 0,
417
+ daysExpired: Math.abs(daysRemaining),
418
+ expiresAt
419
+ };
420
+ }
421
+ return {
422
+ canRestore: true,
423
+ daysRemaining,
424
+ daysExpired: 0,
425
+ expiresAt
426
+ };
427
+ }
374
428
  export {
429
+ DEFAULT_SOFT_DELETE_RETENTION_DAYS,
430
+ SYSTEM_SETTINGS_KEY,
431
+ checkRestoreEligibility,
375
432
  executePublicQuery,
376
433
  executeServerQuery,
377
434
  getAccount,
@@ -380,6 +437,8 @@ export {
380
437
  getBrandWithProducts,
381
438
  getProduct,
382
439
  getProductInstance,
440
+ getSoftDeleteRetentionDays,
441
+ getSystemSettings,
383
442
  getUser,
384
443
  getUserByCognitoId,
385
444
  getUserByEmail,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/queries/brands.ts","../../src/queries/accounts.ts","../../src/queries/users.ts","../../src/queries/products.ts","../../src/client/index.ts","../../src/client/server.ts","../../src/queries/server-helpers.ts"],"sourcesContent":["/**\n * Brand Query Functions\n *\n * Provides query functions for fetching brand data from the GraphQL API.\n */\n\nimport type { Brand } from \"@htlkg/core/types\";\n\n/**\n * Get a single brand by ID\n *\n * @example\n * ```typescript\n * import { getBrand } from '@htlkg/data/queries';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * const brand = await getBrand(client, 'brand-123');\n * ```\n */\nexport async function getBrand<TClient = any>(\n\tclient: TClient,\n\tid: string,\n): Promise<Brand | null> {\n\ttry {\n\t\tconst { data, errors } = await (client as any).models.Brand.get({ id });\n\n\t\tif (errors) {\n\t\t\tconsole.error(\"[getBrand] GraphQL errors:\", errors);\n\t\t\treturn null;\n\t\t}\n\n\t\treturn data as Brand;\n\t} catch (error) {\n\t\tconsole.error(\"[getBrand] Error fetching brand:\", error);\n\t\tthrow error;\n\t}\n}\n\n/**\n * List all brands with optional filtering\n *\n * @example\n * ```typescript\n * import { listBrands } from '@htlkg/data/queries';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * const brands = await listBrands(client, {\n * filter: { status: { eq: 'active' } }\n * });\n * ```\n */\nexport async function listBrands<TClient = any>(\n\tclient: TClient,\n\toptions?: {\n\t\tfilter?: any;\n\t\tlimit?: number;\n\t\tnextToken?: string;\n\t},\n): Promise<{ items: Brand[]; nextToken?: string }> {\n\ttry {\n\t\tconst { data, errors, nextToken } = await (client as any).models.Brand.list(\n\t\t\toptions,\n\t\t);\n\n\t\tif (errors) {\n\t\t\tconsole.error(\"[listBrands] GraphQL errors:\", errors);\n\t\t\treturn { items: [], nextToken: undefined };\n\t\t}\n\n\t\treturn {\n\t\t\titems: (data || []) as Brand[],\n\t\t\tnextToken,\n\t\t};\n\t} catch (error) {\n\t\tconsole.error(\"[listBrands] Error fetching brands:\", error);\n\t\tthrow error;\n\t}\n}\n\n/**\n * Get a brand with its product instances\n *\n * @example\n * ```typescript\n * import { getBrandWithProducts } from '@htlkg/data/queries';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * const brand = await getBrandWithProducts(client, 'brand-123');\n * ```\n */\nexport async function getBrandWithProducts<TClient = any>(\n\tclient: TClient,\n\tid: string,\n): Promise<Brand | null> {\n\ttry {\n\t\tconst { data, errors } = await (client as any).models.Brand.get(\n\t\t\t{ id },\n\t\t\t{\n\t\t\t\tselectionSet: [\n\t\t\t\t\t\"id\",\n\t\t\t\t\t\"name\",\n\t\t\t\t\t\"accountId\",\n\t\t\t\t\t\"logo\",\n\t\t\t\t\t\"timezone\",\n\t\t\t\t\t\"status\",\n\t\t\t\t\t\"settings\",\n\t\t\t\t\t\"productInstances.*\",\n\t\t\t\t],\n\t\t\t},\n\t\t);\n\n\t\tif (errors) {\n\t\t\tconsole.error(\"[getBrandWithProducts] GraphQL errors:\", errors);\n\t\t\treturn null;\n\t\t}\n\n\t\treturn data as Brand;\n\t} catch (error) {\n\t\tconsole.error(\"[getBrandWithProducts] Error fetching brand:\", error);\n\t\tthrow error;\n\t}\n}\n\n/**\n * List brands by account ID\n *\n * @example\n * ```typescript\n * import { listBrandsByAccount } from '@htlkg/data/queries';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * const brands = await listBrandsByAccount(client, 'account-123');\n * ```\n */\nexport async function listBrandsByAccount<TClient = any>(\n\tclient: TClient,\n\taccountId: string,\n\toptions?: {\n\t\tlimit?: number;\n\t\tnextToken?: string;\n\t},\n): Promise<{ items: Brand[]; nextToken?: string }> {\n\treturn listBrands(client, {\n\t\tfilter: { accountId: { eq: accountId } },\n\t\t...options,\n\t});\n}\n\n/**\n * List active brands\n *\n * @example\n * ```typescript\n * import { listActiveBrands } from '@htlkg/data/queries';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * const brands = await listActiveBrands(client);\n * ```\n */\nexport async function listActiveBrands<TClient = any>(\n\tclient: TClient,\n\toptions?: {\n\t\tlimit?: number;\n\t\tnextToken?: string;\n\t},\n): Promise<{ items: Brand[]; nextToken?: string }> {\n\treturn listBrands(client, {\n\t\tfilter: { status: { eq: \"active\" } },\n\t\t...options,\n\t});\n}\n","/**\n * Account Query Functions\n *\n * Provides query functions for fetching account data from the GraphQL API.\n */\n\nimport type { Account } from \"@htlkg/core/types\";\n\n/**\n * Get a single account by ID\n *\n * @example\n * ```typescript\n * import { getAccount } from '@htlkg/data/queries';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * const account = await getAccount(client, 'account-123');\n * ```\n */\nexport async function getAccount<TClient = any>(\n\tclient: TClient,\n\tid: string,\n): Promise<Account | null> {\n\ttry {\n\t\tconst { data, errors } = await (client as any).models.Account.get({ id });\n\n\t\tif (errors) {\n\t\t\tconsole.error(\"[getAccount] GraphQL errors:\", errors);\n\t\t\treturn null;\n\t\t}\n\n\t\treturn data as Account;\n\t} catch (error) {\n\t\tconsole.error(\"[getAccount] Error fetching account:\", error);\n\t\tthrow error;\n\t}\n}\n\n/**\n * List all accounts with optional filtering\n *\n * @example\n * ```typescript\n * import { listAccounts } from '@htlkg/data/queries';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * const accounts = await listAccounts(client);\n * ```\n */\nexport async function listAccounts<TClient = any>(\n\tclient: TClient,\n\toptions?: {\n\t\tfilter?: any;\n\t\tlimit?: number;\n\t\tnextToken?: string;\n\t},\n): Promise<{ items: Account[]; nextToken?: string }> {\n\ttry {\n\t\tconst { data, errors, nextToken } = await (\n\t\t\tclient as any\n\t\t).models.Account.list(options);\n\n\t\tif (errors) {\n\t\t\tconsole.error(\"[listAccounts] GraphQL errors:\", errors);\n\t\t\treturn { items: [], nextToken: undefined };\n\t\t}\n\n\t\treturn {\n\t\t\titems: (data || []) as Account[],\n\t\t\tnextToken,\n\t\t};\n\t} catch (error) {\n\t\tconsole.error(\"[listAccounts] Error fetching accounts:\", error);\n\t\tthrow error;\n\t}\n}\n\n/**\n * Get an account with its brands\n *\n * @example\n * ```typescript\n * import { getAccountWithBrands } from '@htlkg/data/queries';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * const account = await getAccountWithBrands(client, 'account-123');\n * ```\n */\nexport async function getAccountWithBrands<TClient = any>(\n\tclient: TClient,\n\tid: string,\n): Promise<Account | null> {\n\ttry {\n\t\tconst { data, errors } = await (client as any).models.Account.get(\n\t\t\t{ id },\n\t\t\t{\n\t\t\t\tselectionSet: [\n\t\t\t\t\t\"id\",\n\t\t\t\t\t\"name\",\n\t\t\t\t\t\"logo\",\n\t\t\t\t\t\"subscription\",\n\t\t\t\t\t\"settings\",\n\t\t\t\t\t\"brands.*\",\n\t\t\t\t],\n\t\t\t},\n\t\t);\n\n\t\tif (errors) {\n\t\t\tconsole.error(\"[getAccountWithBrands] GraphQL errors:\", errors);\n\t\t\treturn null;\n\t\t}\n\n\t\treturn data as Account;\n\t} catch (error) {\n\t\tconsole.error(\"[getAccountWithBrands] Error fetching account:\", error);\n\t\tthrow error;\n\t}\n}\n","/**\n * User Query Functions\n *\n * Provides query functions for fetching user data from the GraphQL API.\n */\n\nimport type { User } from \"@htlkg/core/types\";\n\n/**\n * Get a single user by ID\n *\n * @example\n * ```typescript\n * import { getUser } from '@htlkg/data/queries';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * const user = await getUser(client, 'user-123');\n * ```\n */\nexport async function getUser<TClient = any>(\n\tclient: TClient,\n\tid: string,\n): Promise<User | null> {\n\ttry {\n\t\tconst { data, errors } = await (client as any).models.User.get({ id });\n\n\t\tif (errors) {\n\t\t\tconsole.error(\"[getUser] GraphQL errors:\", errors);\n\t\t\treturn null;\n\t\t}\n\n\t\treturn data as User;\n\t} catch (error) {\n\t\tconsole.error(\"[getUser] Error fetching user:\", error);\n\t\tthrow error;\n\t}\n}\n\n/**\n * Get a user by Cognito ID\n *\n * @example\n * ```typescript\n * import { getUserByCognitoId } from '@htlkg/data/queries';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * const user = await getUserByCognitoId(client, 'cognito-id-123');\n * ```\n */\nexport async function getUserByCognitoId<TClient = any>(\n\tclient: TClient,\n\tcognitoId: string,\n): Promise<User | null> {\n\ttry {\n\t\tconst { data, errors } = await (client as any).models.User.list({\n\t\t\tfilter: { cognitoId: { eq: cognitoId } },\n\t\t\tlimit: 1,\n\t\t});\n\n\t\tif (errors) {\n\t\t\tconsole.error(\"[getUserByCognitoId] GraphQL errors:\", errors);\n\t\t\treturn null;\n\t\t}\n\n\t\treturn data?.[0] as User | null;\n\t} catch (error) {\n\t\tconsole.error(\"[getUserByCognitoId] Error fetching user:\", error);\n\t\tthrow error;\n\t}\n}\n\n/**\n * Get a user by email\n *\n * @example\n * ```typescript\n * import { getUserByEmail } from '@htlkg/data/queries';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * const user = await getUserByEmail(client, 'user@example.com');\n * ```\n */\nexport async function getUserByEmail<TClient = any>(\n\tclient: TClient,\n\temail: string,\n): Promise<User | null> {\n\ttry {\n\t\tconst { data, errors } = await (client as any).models.User.list({\n\t\t\tfilter: { email: { eq: email } },\n\t\t\tlimit: 1,\n\t\t});\n\n\t\tif (errors) {\n\t\t\tconsole.error(\"[getUserByEmail] GraphQL errors:\", errors);\n\t\t\treturn null;\n\t\t}\n\n\t\treturn data?.[0] as User | null;\n\t} catch (error) {\n\t\tconsole.error(\"[getUserByEmail] Error fetching user:\", error);\n\t\tthrow error;\n\t}\n}\n\n/**\n * List all users with optional filtering\n *\n * @example\n * ```typescript\n * import { listUsers } from '@htlkg/data/queries';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * const users = await listUsers(client, {\n * filter: { status: { eq: 'active' } }\n * });\n * ```\n */\nexport async function listUsers<TClient = any>(\n\tclient: TClient,\n\toptions?: {\n\t\tfilter?: any;\n\t\tlimit?: number;\n\t\tnextToken?: string;\n\t},\n): Promise<{ items: User[]; nextToken?: string }> {\n\ttry {\n\t\tconst { data, errors, nextToken } = await (client as any).models.User.list(\n\t\t\toptions,\n\t\t);\n\n\t\tif (errors) {\n\t\t\tconsole.error(\"[listUsers] GraphQL errors:\", errors);\n\t\t\treturn { items: [], nextToken: undefined };\n\t\t}\n\n\t\treturn {\n\t\t\titems: (data || []) as User[],\n\t\t\tnextToken,\n\t\t};\n\t} catch (error) {\n\t\tconsole.error(\"[listUsers] Error fetching users:\", error);\n\t\tthrow error;\n\t}\n}\n\n/**\n * List users by account ID\n *\n * @example\n * ```typescript\n * import { listUsersByAccount } from '@htlkg/data/queries';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * const users = await listUsersByAccount(client, 'account-123');\n * ```\n */\nexport async function listUsersByAccount<TClient = any>(\n\tclient: TClient,\n\taccountId: string,\n\toptions?: {\n\t\tlimit?: number;\n\t\tnextToken?: string;\n\t},\n): Promise<{ items: User[]; nextToken?: string }> {\n\treturn listUsers(client, {\n\t\tfilter: { accountId: { eq: accountId } },\n\t\t...options,\n\t});\n}\n\n/**\n * List active users\n *\n * @example\n * ```typescript\n * import { listActiveUsers } from '@htlkg/data/queries';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * const users = await listActiveUsers(client);\n * ```\n */\nexport async function listActiveUsers<TClient = any>(\n\tclient: TClient,\n\toptions?: {\n\t\tlimit?: number;\n\t\tnextToken?: string;\n\t},\n): Promise<{ items: User[]; nextToken?: string }> {\n\treturn listUsers(client, {\n\t\tfilter: { status: { eq: \"active\" } },\n\t\t...options,\n\t});\n}\n","/**\n * Product Query Functions\n *\n * Provides query functions for fetching product and product instance data from the GraphQL API.\n */\n\nimport type { Product, ProductInstance } from \"@htlkg/core/types\";\n\n/**\n * Get a single product by ID\n *\n * @example\n * ```typescript\n * import { getProduct } from '@htlkg/data/queries';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * const product = await getProduct(client, 'product-123');\n * ```\n */\nexport async function getProduct<TClient = any>(\n\tclient: TClient,\n\tid: string,\n): Promise<Product | null> {\n\ttry {\n\t\tconst { data, errors } = await (client as any).models.Product.get({ id });\n\n\t\tif (errors) {\n\t\t\tconsole.error(\"[getProduct] GraphQL errors:\", errors);\n\t\t\treturn null;\n\t\t}\n\n\t\treturn data as Product;\n\t} catch (error) {\n\t\tconsole.error(\"[getProduct] Error fetching product:\", error);\n\t\tthrow error;\n\t}\n}\n\n/**\n * List all products with optional filtering\n *\n * @example\n * ```typescript\n * import { listProducts } from '@htlkg/data/queries';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * const products = await listProducts(client, {\n * filter: { isActive: { eq: true } }\n * });\n * ```\n */\nexport async function listProducts<TClient = any>(\n\tclient: TClient,\n\toptions?: {\n\t\tfilter?: any;\n\t\tlimit?: number;\n\t\tnextToken?: string;\n\t},\n): Promise<{ items: Product[]; nextToken?: string }> {\n\ttry {\n\t\tconst { data, errors, nextToken } = await (\n\t\t\tclient as any\n\t\t).models.Product.list(options);\n\n\t\tif (errors) {\n\t\t\tconsole.error(\"[listProducts] GraphQL errors:\", errors);\n\t\t\treturn { items: [], nextToken: undefined };\n\t\t}\n\n\t\treturn {\n\t\t\titems: (data || []) as Product[],\n\t\t\tnextToken,\n\t\t};\n\t} catch (error) {\n\t\tconsole.error(\"[listProducts] Error fetching products:\", error);\n\t\tthrow error;\n\t}\n}\n\n/**\n * List active products\n *\n * @example\n * ```typescript\n * import { listActiveProducts } from '@htlkg/data/queries';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * const products = await listActiveProducts(client);\n * ```\n */\nexport async function listActiveProducts<TClient = any>(\n\tclient: TClient,\n\toptions?: {\n\t\tlimit?: number;\n\t\tnextToken?: string;\n\t},\n): Promise<{ items: Product[]; nextToken?: string }> {\n\treturn listProducts(client, {\n\t\tfilter: { isActive: { eq: true } },\n\t\t...options,\n\t});\n}\n\n/**\n * Get a single product instance by ID\n *\n * @example\n * ```typescript\n * import { getProductInstance } from '@htlkg/data/queries';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * const instance = await getProductInstance(client, 'instance-123');\n * ```\n */\nexport async function getProductInstance<TClient = any>(\n\tclient: TClient,\n\tid: string,\n): Promise<ProductInstance | null> {\n\ttry {\n\t\tconst { data, errors } = await (client as any).models.ProductInstance.get({\n\t\t\tid,\n\t\t});\n\n\t\tif (errors) {\n\t\t\tconsole.error(\"[getProductInstance] GraphQL errors:\", errors);\n\t\t\treturn null;\n\t\t}\n\n\t\treturn data as ProductInstance;\n\t} catch (error) {\n\t\tconsole.error(\"[getProductInstance] Error fetching product instance:\", error);\n\t\tthrow error;\n\t}\n}\n\n/**\n * List product instances by brand ID\n *\n * @example\n * ```typescript\n * import { listProductInstancesByBrand } from '@htlkg/data/queries';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * const instances = await listProductInstancesByBrand(client, 'brand-123');\n * ```\n */\nexport async function listProductInstancesByBrand<TClient = any>(\n\tclient: TClient,\n\tbrandId: string,\n\toptions?: {\n\t\tlimit?: number;\n\t\tnextToken?: string;\n\t},\n): Promise<{ items: ProductInstance[]; nextToken?: string }> {\n\ttry {\n\t\tconst { data, errors, nextToken } = await (\n\t\t\tclient as any\n\t\t).models.ProductInstance.list({\n\t\t\tfilter: { brandId: { eq: brandId } },\n\t\t\t...options,\n\t\t});\n\n\t\tif (errors) {\n\t\t\tconsole.error(\"[listProductInstancesByBrand] GraphQL errors:\", errors);\n\t\t\treturn { items: [], nextToken: undefined };\n\t\t}\n\n\t\treturn {\n\t\t\titems: (data || []) as ProductInstance[],\n\t\t\tnextToken,\n\t\t};\n\t} catch (error) {\n\t\tconsole.error(\n\t\t\t\"[listProductInstancesByBrand] Error fetching product instances:\",\n\t\t\terror,\n\t\t);\n\t\tthrow error;\n\t}\n}\n\n/**\n * List product instances by account ID\n *\n * @example\n * ```typescript\n * import { listProductInstancesByAccount } from '@htlkg/data/queries';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * const instances = await listProductInstancesByAccount(client, 'account-123');\n * ```\n */\nexport async function listProductInstancesByAccount<TClient = any>(\n\tclient: TClient,\n\taccountId: string,\n\toptions?: {\n\t\tlimit?: number;\n\t\tnextToken?: string;\n\t},\n): Promise<{ items: ProductInstance[]; nextToken?: string }> {\n\ttry {\n\t\tconst { data, errors, nextToken } = await (\n\t\t\tclient as any\n\t\t).models.ProductInstance.list({\n\t\t\tfilter: { accountId: { eq: accountId } },\n\t\t\t...options,\n\t\t});\n\n\t\tif (errors) {\n\t\t\tconsole.error(\"[listProductInstancesByAccount] GraphQL errors:\", errors);\n\t\t\treturn { items: [], nextToken: undefined };\n\t\t}\n\n\t\treturn {\n\t\t\titems: (data || []) as ProductInstance[],\n\t\t\tnextToken,\n\t\t};\n\t} catch (error) {\n\t\tconsole.error(\n\t\t\t\"[listProductInstancesByAccount] Error fetching product instances:\",\n\t\t\terror,\n\t\t);\n\t\tthrow error;\n\t}\n}\n\n/**\n * List enabled product instances by brand ID\n *\n * @example\n * ```typescript\n * import { listEnabledProductInstancesByBrand } from '@htlkg/data/queries';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * const instances = await listEnabledProductInstancesByBrand(client, 'brand-123');\n * ```\n */\nexport async function listEnabledProductInstancesByBrand<TClient = any>(\n\tclient: TClient,\n\tbrandId: string,\n\toptions?: {\n\t\tlimit?: number;\n\t\tnextToken?: string;\n\t},\n): Promise<{ items: ProductInstance[]; nextToken?: string }> {\n\ttry {\n\t\tconst { data, errors, nextToken } = await (\n\t\t\tclient as any\n\t\t).models.ProductInstance.list({\n\t\t\tfilter: {\n\t\t\t\tbrandId: { eq: brandId },\n\t\t\t\tenabled: { eq: true },\n\t\t\t},\n\t\t\t...options,\n\t\t});\n\n\t\tif (errors) {\n\t\t\tconsole.error(\n\t\t\t\t\"[listEnabledProductInstancesByBrand] GraphQL errors:\",\n\t\t\t\terrors,\n\t\t\t);\n\t\t\treturn { items: [], nextToken: undefined };\n\t\t}\n\n\t\treturn {\n\t\t\titems: (data || []) as ProductInstance[],\n\t\t\tnextToken,\n\t\t};\n\t} catch (error) {\n\t\tconsole.error(\n\t\t\t\"[listEnabledProductInstancesByBrand] Error fetching product instances:\",\n\t\t\terror,\n\t\t);\n\t\tthrow error;\n\t}\n}\n","/**\n * GraphQL Client for @htlkg/data\n *\n * Provides both client-side and server-side GraphQL capabilities using AWS Amplify Data.\n * The server-side functions use the Amplify Astro adapter for proper SSR support.\n */\n\nimport { generateClient as generateDataClient } from \"aws-amplify/data\";\nimport type { ResourcesConfig } from \"aws-amplify\";\n\n// Re-export server-side client generation\nexport { generateServerClientUsingCookies } from \"./server\";\n\n// Singleton client instance for client-side fetching\nlet sharedClientInstance: any = null;\n\n/**\n * Get or create the shared GraphQL client instance (singleton pattern)\n * Use this for client-side fetching to avoid creating multiple client instances.\n *\n * @example\n * ```typescript\n * const client = getSharedClient<Schema>();\n * const { data } = await client.models.Account.list();\n * ```\n */\nexport function getSharedClient<\n\tTSchema extends Record<string, unknown> = Record<string, unknown>,\n>(): ReturnType<typeof generateDataClient<TSchema>> {\n\tif (!sharedClientInstance) {\n\t\tsharedClientInstance = generateDataClient<TSchema>();\n\t}\n\treturn sharedClientInstance;\n}\n\n/**\n * Reset the shared client instance (useful for testing or auth state changes)\n */\nexport function resetSharedClient(): void {\n\tsharedClientInstance = null;\n}\n\n/**\n * Generate a client-side GraphQL client for use in Vue components and browser contexts\n * This is SSR-safe and should be called within a component's setup function or after hydration\n *\n * @example\n * ```typescript\n * import type { Schema } from '@backend/data/resource';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * const { data: brands } = await client.models.Brand.list();\n * ```\n */\nexport function generateClient<\n\tTSchema extends Record<string, unknown> = Record<string, unknown>,\n>(): ReturnType<typeof generateDataClient<TSchema>> {\n\treturn generateDataClient<TSchema>();\n}\n\n/**\n * Configuration for Amplify (matches amplify_outputs.json format)\n */\nexport type AstroAmplifyConfig = ResourcesConfig;\n\n/**\n * Authentication mode for server-side GraphQL client\n */\nexport type ServerAuthMode = 'userPool' | 'apiKey';\n\n/**\n * Options for generating a server-side GraphQL client\n */\nexport interface GenerateServerClientOptions {\n\t/** Authentication mode - 'userPool' (default) uses JWT from cookies, 'apiKey' uses API key */\n\tauthMode?: ServerAuthMode;\n}\n\n/**\n * Generate a server-side GraphQL client for use within runWithAmplifyServerContext\n * \n * This function creates a GraphQL client that can be used for server-side data fetching in Astro.\n * It MUST be called within runWithAmplifyServerContext to access JWT tokens from cookies.\n * \n * The client supports two authentication modes:\n * - 'userPool' (default): Uses JWT tokens from cookies (requires runWithAmplifyServerContext)\n * - 'apiKey': Uses API key for public/unauthenticated requests\n *\n * **Important**: \n * - Amplify.configure() must be called once at app startup (e.g., in amplify-server.ts)\n * - This function must be called INSIDE the operation function of runWithAmplifyServerContext\n * - The context automatically provides the token provider that reads JWT tokens from cookies\n *\n * @example\n * ```typescript\n * // In your Astro page\n * import type { Schema } from '../amplify/data/resource';\n * import { generateServerClient } from '@htlkg/data/client';\n * import { createRunWithAmplifyServerContext } from '@htlkg/core/amplify-astro-adapter';\n * import outputs from '../amplify_outputs.json';\n *\n * const runWithAmplifyServerContext = createRunWithAmplifyServerContext({ config: outputs });\n *\n * // Fetch data with authentication\n * const result = await runWithAmplifyServerContext({\n * astroServerContext: {\n * cookies: Astro.cookies,\n * request: Astro.request\n * },\n * operation: async (contextSpec) => {\n * // Generate client INSIDE the operation\n * const client = generateServerClient<Schema>({ authMode: 'userPool' });\n * return await client.models.User.list();\n * }\n * });\n * \n * const users = result.data || [];\n * ```\n * \n * @example Using API key for public data\n * ```typescript\n * const result = await runWithAmplifyServerContext({\n * astroServerContext: {\n * cookies: Astro.cookies,\n * request: Astro.request\n * },\n * operation: async (contextSpec) => {\n * const client = generateServerClient<Schema>({ authMode: 'apiKey' });\n * return await client.models.Brand.list();\n * }\n * });\n * ```\n */\nexport function generateServerClient<\n\tTSchema extends Record<string, unknown> = Record<string, unknown>,\n>(options?: GenerateServerClientOptions): ReturnType<typeof generateDataClient<TSchema>> {\n\t// Generate the client without authMode parameter\n\t// When called within runWithAmplifyServerContext, it will automatically use the token provider\n\t// from the context (which reads JWT tokens from cookies)\n\t// The authMode should be specified per-operation, not at client creation\n\tconst client = generateDataClient<TSchema>();\n\t\n\treturn client;\n}\n","/**\n * Server-side data client for Astro\n *\n * Provides a client generator similar to Next.js's generateServerClientUsingCookies\n * using generateClientWithAmplifyInstance for proper server context integration.\n */\n\nimport type { AstroGlobal } from \"astro\";\nimport type { ResourcesConfig } from \"aws-amplify\";\nimport {\n\tCommonPublicClientOptions,\n\tDefaultCommonClientOptions,\n\tV6ClientSSRCookies,\n\tgenerateClientWithAmplifyInstance,\n} from \"aws-amplify/api/internals\";\nimport { getAmplifyServerContext } from \"aws-amplify/adapter-core/internals\";\nimport { createRunWithAmplifyServerContext, createLogger } from \"@htlkg/core/amplify-astro-adapter\";\n\nconst log = createLogger('server-client');\n\ninterface AstroCookiesClientParams {\n\tcookies: AstroGlobal[\"cookies\"];\n\trequest: AstroGlobal[\"request\"];\n\tconfig: ResourcesConfig;\n}\n\n/**\n * Generates a server-side data client for Astro (matches Next.js implementation)\n *\n * This function creates a client that automatically wraps all operations in the Amplify server context,\n * ensuring that authentication tokens from cookies are properly used.\n *\n * @example\n * ```typescript\n * import type { Schema } from '../amplify/data/resource';\n * import { generateServerClientUsingCookies } from '@htlkg/data/client';\n * import { parseAmplifyConfig } from 'aws-amplify/utils';\n * import outputs from '../amplify_outputs.json';\n *\n * const amplifyConfig = parseAmplifyConfig(outputs);\n *\n * const client = generateServerClientUsingCookies<Schema>({\n * config: amplifyConfig,\n * cookies: Astro.cookies,\n * request: Astro.request,\n * });\n *\n * // Use the client directly - operations are automatically wrapped\n * const result = await client.models.User.list({\n * selectionSet: ['id', 'email'],\n * limit: 100,\n * });\n * ```\n */\nexport function generateServerClientUsingCookies<\n\tT extends Record<any, any> = never,\n\tOptions extends CommonPublicClientOptions &\n\t\tAstroCookiesClientParams = DefaultCommonClientOptions &\n\t\tAstroCookiesClientParams,\n>(options: Options): V6ClientSSRCookies<T, Options> {\n\tconst runWithAmplifyServerContext = createRunWithAmplifyServerContext({\n\t\tconfig: options.config,\n\t});\n\n\tconst resourcesConfig = options.config;\n\n\t// This function reference gets passed down to InternalGraphQLAPI.ts.graphql\n\t// where this._graphql is passed in as the `fn` argument\n\t// causing it to always get invoked inside `runWithAmplifyServerContext`\n\tconst getAmplify = (fn: (amplify: any) => Promise<any>) => {\n\t\treturn runWithAmplifyServerContext({\n\t\t\tastroServerContext: {\n\t\t\t\tcookies: options.cookies,\n\t\t\t\trequest: options.request,\n\t\t\t},\n\t\t\toperation: async (contextSpec: any) => {\n\t\t\t\tconst amplifyInstance = getAmplifyServerContext(contextSpec).amplify;\n\t\t\t\t\n\t\t\t\t// Debug logging (only when DEBUG=true)\n\t\t\t\ttry {\n\t\t\t\t\tconst config = amplifyInstance.getConfig();\n\t\t\t\t\tlog.debug('Amplify config from instance:', {\n\t\t\t\t\t\thasAPI: !!config.API,\n\t\t\t\t\t\thasGraphQL: !!config.API?.GraphQL,\n\t\t\t\t\t\tendpoint: config.API?.GraphQL?.endpoint,\n\t\t\t\t\t\tdefaultAuthMode: config.API?.GraphQL?.defaultAuthMode,\n\t\t\t\t\t\tregion: config.API?.GraphQL?.region,\n\t\t\t\t\t});\n\t\t\t\t\t\n\t\t\t\t\tconst session = await amplifyInstance.Auth.fetchAuthSession();\n\t\t\t\t\tlog.debug('Auth session:', {\n\t\t\t\t\t\thasTokens: !!session.tokens,\n\t\t\t\t\t\thasAccessToken: !!session.tokens?.accessToken,\n\t\t\t\t\t\thasIdToken: !!session.tokens?.idToken,\n\t\t\t\t\t\thasCredentials: !!session.credentials,\n\t\t\t\t\t});\n\t\t\t\t} catch (e: any) {\n\t\t\t\t\tlog.debug('Error fetching session:', e.message);\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\treturn fn(amplifyInstance);\n\t\t\t},\n\t\t});\n\t};\n\n\tconst {\n\t\tcookies: _cookies,\n\t\trequest: _request,\n\t\tconfig: _config,\n\t\t...params\n\t} = options;\n\n\treturn generateClientWithAmplifyInstance<T, V6ClientSSRCookies<T, Options>>({\n\t\tamplify: getAmplify,\n\t\tconfig: resourcesConfig,\n\t\t...params,\n\t} as any);\n}\n","/**\n * Server-Side Query Helpers\n *\n * Convenience functions for executing server-side queries in Astro pages.\n * These helpers simplify the common pattern of using runWithAmplifyServerContext.\n */\n\nimport type { AstroGlobal } from \"astro\";\nimport { generateServerClient } from \"../client\";\n\n/**\n * Type for the runWithAmplifyServerContext function\n */\ntype RunWithAmplifyServerContext = (options: {\n\tastroServerContext: {\n\t\tcookies: AstroGlobal[\"cookies\"];\n\t\trequest: AstroGlobal[\"request\"];\n\t};\n\toperation: (contextSpec: unknown) => Promise<unknown>;\n}) => Promise<unknown>;\n\n/**\n * Helper to execute server-side queries in Astro pages\n *\n * This function wraps the common pattern of using runWithAmplifyServerContext\n * with generateServerClient, making it easier to fetch data server-side.\n *\n * **Note**: This requires `createRunWithAmplifyServerContext` from `@htlkg/core/amplify-astro-adapter`.\n * If you need more control, use the full pattern directly.\n *\n * @example\n * ```typescript\n * import type { Schema } from '../amplify/data/resource';\n * import { executeServerQuery } from '@htlkg/data/queries/server-helpers';\n * import { createRunWithAmplifyServerContext } from '@htlkg/core/amplify-astro-adapter';\n * import outputs from '../amplify_outputs.json';\n *\n * const runWithAmplifyServerContext = createRunWithAmplifyServerContext({ config: outputs });\n *\n * const users = await executeServerQuery<Schema>(\n * Astro,\n * runWithAmplifyServerContext,\n * async (client) => {\n * const result = await client.models.User.list();\n * return result.data || [];\n * }\n * );\n * ```\n */\nexport async function executeServerQuery<\n\tTSchema extends Record<string, unknown>,\n\tTResult,\n>(\n\tastro: AstroGlobal,\n\trunWithAmplifyServerContext: RunWithAmplifyServerContext,\n\toperation: (client: ReturnType<typeof generateServerClient<TSchema>>) => Promise<TResult>,\n): Promise<TResult> {\n\tconst result = await runWithAmplifyServerContext({\n\t\tastroServerContext: {\n\t\t\tcookies: astro.cookies,\n\t\t\trequest: astro.request,\n\t\t},\n\t\toperation: async (contextSpec: unknown) => {\n\t\t\tconst client = generateServerClient<TSchema>();\n\t\t\treturn await operation(client);\n\t\t},\n\t});\n\treturn result as TResult;\n}\n\n/**\n * Helper to execute server-side queries with API key authentication (public data)\n *\n * Use this for fetching public data that doesn't require user authentication.\n *\n * @example\n * ```typescript\n * import type { Schema } from '../amplify/data/resource';\n * import { executePublicQuery } from '@htlkg/data/queries/server-helpers';\n * import { createRunWithAmplifyServerContext } from '@htlkg/core/amplify-astro-adapter';\n * import outputs from '../amplify_outputs.json';\n *\n * const runWithAmplifyServerContext = createRunWithAmplifyServerContext({ config: outputs });\n *\n * const brands = await executePublicQuery<Schema>(\n * Astro,\n * runWithAmplifyServerContext,\n * async (client) => {\n * const result = await client.models.Brand.list();\n * return result.data || [];\n * }\n * );\n * ```\n */\nexport async function executePublicQuery<\n\tTSchema extends Record<string, unknown>,\n\tTResult,\n>(\n\tastro: AstroGlobal,\n\trunWithAmplifyServerContext: RunWithAmplifyServerContext,\n\toperation: (client: ReturnType<typeof generateServerClient<TSchema>>) => Promise<TResult>,\n): Promise<TResult> {\n\tconst result = await runWithAmplifyServerContext({\n\t\tastroServerContext: {\n\t\t\tcookies: astro.cookies,\n\t\t\trequest: astro.request,\n\t\t},\n\t\toperation: async (_contextSpec: unknown) => {\n\t\t\tconst client = generateServerClient<TSchema>({ authMode: \"apiKey\" });\n\t\t\treturn await operation(client);\n\t\t},\n\t});\n\treturn result as TResult;\n}\n"],"mappings":";AAoBA,eAAsB,SACrB,QACA,IACwB;AACxB,MAAI;AACH,UAAM,EAAE,MAAM,OAAO,IAAI,MAAO,OAAe,OAAO,MAAM,IAAI,EAAE,GAAG,CAAC;AAEtE,QAAI,QAAQ;AACX,cAAQ,MAAM,8BAA8B,MAAM;AAClD,aAAO;AAAA,IACR;AAEA,WAAO;AAAA,EACR,SAAS,OAAO;AACf,YAAQ,MAAM,oCAAoC,KAAK;AACvD,UAAM;AAAA,EACP;AACD;AAgBA,eAAsB,WACrB,QACA,SAKkD;AAClD,MAAI;AACH,UAAM,EAAE,MAAM,QAAQ,UAAU,IAAI,MAAO,OAAe,OAAO,M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;AAAA,IAC9B;AAAA,EACD,CAAC;AACD,SAAO;AACR;","names":[]}
1
+ {"version":3,"sources":["../../src/queries/brands.ts","../../src/queries/accounts.ts","../../src/queries/users.ts","../../src/queries/products.ts","../../src/client/index.ts","../../src/client/server.ts","../../src/queries/server-helpers.ts","../../src/queries/systemSettings.ts"],"sourcesContent":["/**\n * Brand Query Functions\n *\n * Provides query functions for fetching brand data from the GraphQL API.\n */\n\nimport type { Brand } from \"@htlkg/core/types\";\n\n/**\n * Get a single brand by ID\n *\n * @example\n * ```typescript\n * import { getBrand } from '@htlkg/data/queries';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * const brand = await getBrand(client, 'brand-123');\n * ```\n */\nexport async function getBrand<TClient = any>(\n\tclient: TClient,\n\tid: string,\n): Promise<Brand | null> {\n\ttry {\n\t\tconst { data, errors } = await (client as any).models.Brand.get({ id });\n\n\t\tif (errors) {\n\t\t\tconsole.error(\"[getBrand] GraphQL errors:\", errors);\n\t\t\treturn null;\n\t\t}\n\n\t\treturn data as Brand;\n\t} catch (error) {\n\t\tconsole.error(\"[getBrand] Error fetching brand:\", error);\n\t\tthrow error;\n\t}\n}\n\n/**\n * List all brands with optional filtering\n *\n * @example\n * ```typescript\n * import { listBrands } from '@htlkg/data/queries';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * const brands = await listBrands(client, {\n * filter: { status: { eq: 'active' } }\n * });\n * ```\n */\nexport async function listBrands<TClient = any>(\n\tclient: TClient,\n\toptions?: {\n\t\tfilter?: any;\n\t\tlimit?: number;\n\t\tnextToken?: string;\n\t},\n): Promise<{ items: Brand[]; nextToken?: string }> {\n\ttry {\n\t\tconst { data, errors, nextToken } = await (client as any).models.Brand.list(\n\t\t\toptions,\n\t\t);\n\n\t\tif (errors) {\n\t\t\tconsole.error(\"[listBrands] GraphQL errors:\", errors);\n\t\t\treturn { items: [], nextToken: undefined };\n\t\t}\n\n\t\treturn {\n\t\t\titems: (data || []) as Brand[],\n\t\t\tnextToken,\n\t\t};\n\t} catch (error) {\n\t\tconsole.error(\"[listBrands] Error fetching brands:\", error);\n\t\tthrow error;\n\t}\n}\n\n/**\n * Get a brand with its product instances\n *\n * @example\n * ```typescript\n * import { getBrandWithProducts } from '@htlkg/data/queries';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * const brand = await getBrandWithProducts(client, 'brand-123');\n * ```\n */\nexport async function getBrandWithProducts<TClient = any>(\n\tclient: TClient,\n\tid: string,\n): Promise<Brand | null> {\n\ttry {\n\t\tconst { data, errors } = await (client as any).models.Brand.get(\n\t\t\t{ id },\n\t\t\t{\n\t\t\t\tselectionSet: [\n\t\t\t\t\t\"id\",\n\t\t\t\t\t\"name\",\n\t\t\t\t\t\"accountId\",\n\t\t\t\t\t\"logo\",\n\t\t\t\t\t\"timezone\",\n\t\t\t\t\t\"status\",\n\t\t\t\t\t\"settings\",\n\t\t\t\t\t\"productInstances.*\",\n\t\t\t\t],\n\t\t\t},\n\t\t);\n\n\t\tif (errors) {\n\t\t\tconsole.error(\"[getBrandWithProducts] GraphQL errors:\", errors);\n\t\t\treturn null;\n\t\t}\n\n\t\treturn data as Brand;\n\t} catch (error) {\n\t\tconsole.error(\"[getBrandWithProducts] Error fetching brand:\", error);\n\t\tthrow error;\n\t}\n}\n\n/**\n * List brands by account ID\n *\n * @example\n * ```typescript\n * import { listBrandsByAccount } from '@htlkg/data/queries';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * const brands = await listBrandsByAccount(client, 'account-123');\n * ```\n */\nexport async function listBrandsByAccount<TClient = any>(\n\tclient: TClient,\n\taccountId: string,\n\toptions?: {\n\t\tlimit?: number;\n\t\tnextToken?: string;\n\t},\n): Promise<{ items: Brand[]; nextToken?: string }> {\n\treturn listBrands(client, {\n\t\tfilter: { accountId: { eq: accountId } },\n\t\t...options,\n\t});\n}\n\n/**\n * List active brands\n *\n * @example\n * ```typescript\n * import { listActiveBrands } from '@htlkg/data/queries';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * const brands = await listActiveBrands(client);\n * ```\n */\nexport async function listActiveBrands<TClient = any>(\n\tclient: TClient,\n\toptions?: {\n\t\tlimit?: number;\n\t\tnextToken?: string;\n\t},\n): Promise<{ items: Brand[]; nextToken?: string }> {\n\treturn listBrands(client, {\n\t\tfilter: { status: { eq: \"active\" } },\n\t\t...options,\n\t});\n}\n","/**\n * Account Query Functions\n *\n * Provides query functions for fetching account data from the GraphQL API.\n */\n\nimport type { Account } from \"@htlkg/core/types\";\n\n/**\n * Get a single account by ID\n *\n * @example\n * ```typescript\n * import { getAccount } from '@htlkg/data/queries';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * const account = await getAccount(client, 'account-123');\n * ```\n */\nexport async function getAccount<TClient = any>(\n\tclient: TClient,\n\tid: string,\n): Promise<Account | null> {\n\ttry {\n\t\tconst { data, errors } = await (client as any).models.Account.get({ id });\n\n\t\tif (errors) {\n\t\t\tconsole.error(\"[getAccount] GraphQL errors:\", errors);\n\t\t\treturn null;\n\t\t}\n\n\t\treturn data as Account;\n\t} catch (error) {\n\t\tconsole.error(\"[getAccount] Error fetching account:\", error);\n\t\tthrow error;\n\t}\n}\n\n/**\n * List all accounts with optional filtering\n *\n * @example\n * ```typescript\n * import { listAccounts } from '@htlkg/data/queries';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * const accounts = await listAccounts(client);\n * ```\n */\nexport async function listAccounts<TClient = any>(\n\tclient: TClient,\n\toptions?: {\n\t\tfilter?: any;\n\t\tlimit?: number;\n\t\tnextToken?: string;\n\t},\n): Promise<{ items: Account[]; nextToken?: string }> {\n\ttry {\n\t\tconst { data, errors, nextToken } = await (\n\t\t\tclient as any\n\t\t).models.Account.list(options);\n\n\t\tif (errors) {\n\t\t\tconsole.error(\"[listAccounts] GraphQL errors:\", errors);\n\t\t\treturn { items: [], nextToken: undefined };\n\t\t}\n\n\t\treturn {\n\t\t\titems: (data || []) as Account[],\n\t\t\tnextToken,\n\t\t};\n\t} catch (error) {\n\t\tconsole.error(\"[listAccounts] Error fetching accounts:\", error);\n\t\tthrow error;\n\t}\n}\n\n/**\n * Get an account with its brands\n *\n * @example\n * ```typescript\n * import { getAccountWithBrands } from '@htlkg/data/queries';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * const account = await getAccountWithBrands(client, 'account-123');\n * ```\n */\nexport async function getAccountWithBrands<TClient = any>(\n\tclient: TClient,\n\tid: string,\n): Promise<Account | null> {\n\ttry {\n\t\tconst { data, errors } = await (client as any).models.Account.get(\n\t\t\t{ id },\n\t\t\t{\n\t\t\t\tselectionSet: [\n\t\t\t\t\t\"id\",\n\t\t\t\t\t\"name\",\n\t\t\t\t\t\"logo\",\n\t\t\t\t\t\"subscription\",\n\t\t\t\t\t\"settings\",\n\t\t\t\t\t\"brands.*\",\n\t\t\t\t],\n\t\t\t},\n\t\t);\n\n\t\tif (errors) {\n\t\t\tconsole.error(\"[getAccountWithBrands] GraphQL errors:\", errors);\n\t\t\treturn null;\n\t\t}\n\n\t\treturn data as Account;\n\t} catch (error) {\n\t\tconsole.error(\"[getAccountWithBrands] Error fetching account:\", error);\n\t\tthrow error;\n\t}\n}\n","/**\n * User Query Functions\n *\n * Provides query functions for fetching user data from the GraphQL API.\n */\n\nimport type { User } from \"@htlkg/core/types\";\n\n/**\n * Get a single user by ID\n *\n * @example\n * ```typescript\n * import { getUser } from '@htlkg/data/queries';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * const user = await getUser(client, 'user-123');\n * ```\n */\nexport async function getUser<TClient = any>(\n\tclient: TClient,\n\tid: string,\n): Promise<User | null> {\n\ttry {\n\t\tconst { data, errors } = await (client as any).models.User.get({ id });\n\n\t\tif (errors) {\n\t\t\tconsole.error(\"[getUser] GraphQL errors:\", errors);\n\t\t\treturn null;\n\t\t}\n\n\t\treturn data as User;\n\t} catch (error) {\n\t\tconsole.error(\"[getUser] Error fetching user:\", error);\n\t\tthrow error;\n\t}\n}\n\n/**\n * Get a user by Cognito ID\n *\n * @example\n * ```typescript\n * import { getUserByCognitoId } from '@htlkg/data/queries';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * const user = await getUserByCognitoId(client, 'cognito-id-123');\n * ```\n */\nexport async function getUserByCognitoId<TClient = any>(\n\tclient: TClient,\n\tcognitoId: string,\n): Promise<User | null> {\n\ttry {\n\t\tconst { data, errors } = await (client as any).models.User.list({\n\t\t\tfilter: { cognitoId: { eq: cognitoId } },\n\t\t\tlimit: 1,\n\t\t});\n\n\t\tif (errors) {\n\t\t\tconsole.error(\"[getUserByCognitoId] GraphQL errors:\", errors);\n\t\t\treturn null;\n\t\t}\n\n\t\treturn data?.[0] as User | null;\n\t} catch (error) {\n\t\tconsole.error(\"[getUserByCognitoId] Error fetching user:\", error);\n\t\tthrow error;\n\t}\n}\n\n/**\n * Get a user by email\n *\n * @example\n * ```typescript\n * import { getUserByEmail } from '@htlkg/data/queries';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * const user = await getUserByEmail(client, 'user@example.com');\n * ```\n */\nexport async function getUserByEmail<TClient = any>(\n\tclient: TClient,\n\temail: string,\n): Promise<User | null> {\n\ttry {\n\t\tconst { data, errors } = await (client as any).models.User.list({\n\t\t\tfilter: { email: { eq: email } },\n\t\t\tlimit: 1,\n\t\t});\n\n\t\tif (errors) {\n\t\t\tconsole.error(\"[getUserByEmail] GraphQL errors:\", errors);\n\t\t\treturn null;\n\t\t}\n\n\t\treturn data?.[0] as User | null;\n\t} catch (error) {\n\t\tconsole.error(\"[getUserByEmail] Error fetching user:\", error);\n\t\tthrow error;\n\t}\n}\n\n/**\n * List all users with optional filtering\n *\n * @example\n * ```typescript\n * import { listUsers } from '@htlkg/data/queries';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * const users = await listUsers(client, {\n * filter: { status: { eq: 'active' } }\n * });\n * ```\n */\nexport async function listUsers<TClient = any>(\n\tclient: TClient,\n\toptions?: {\n\t\tfilter?: any;\n\t\tlimit?: number;\n\t\tnextToken?: string;\n\t},\n): Promise<{ items: User[]; nextToken?: string }> {\n\ttry {\n\t\tconst { data, errors, nextToken } = await (client as any).models.User.list(\n\t\t\toptions,\n\t\t);\n\n\t\tif (errors) {\n\t\t\tconsole.error(\"[listUsers] GraphQL errors:\", errors);\n\t\t\treturn { items: [], nextToken: undefined };\n\t\t}\n\n\t\treturn {\n\t\t\titems: (data || []) as User[],\n\t\t\tnextToken,\n\t\t};\n\t} catch (error) {\n\t\tconsole.error(\"[listUsers] Error fetching users:\", error);\n\t\tthrow error;\n\t}\n}\n\n/**\n * List users by account ID\n *\n * @example\n * ```typescript\n * import { listUsersByAccount } from '@htlkg/data/queries';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * const users = await listUsersByAccount(client, 'account-123');\n * ```\n */\nexport async function listUsersByAccount<TClient = any>(\n\tclient: TClient,\n\taccountId: string,\n\toptions?: {\n\t\tlimit?: number;\n\t\tnextToken?: string;\n\t},\n): Promise<{ items: User[]; nextToken?: string }> {\n\treturn listUsers(client, {\n\t\tfilter: { accountId: { eq: accountId } },\n\t\t...options,\n\t});\n}\n\n/**\n * List active users\n *\n * @example\n * ```typescript\n * import { listActiveUsers } from '@htlkg/data/queries';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * const users = await listActiveUsers(client);\n * ```\n */\nexport async function listActiveUsers<TClient = any>(\n\tclient: TClient,\n\toptions?: {\n\t\tlimit?: number;\n\t\tnextToken?: string;\n\t},\n): Promise<{ items: User[]; nextToken?: string }> {\n\treturn listUsers(client, {\n\t\tfilter: { status: { eq: \"active\" } },\n\t\t...options,\n\t});\n}\n","/**\n * Product Query Functions\n *\n * Provides query functions for fetching product and product instance data from the GraphQL API.\n */\n\nimport type { Product, ProductInstance } from \"@htlkg/core/types\";\n\n/**\n * Get a single product by ID\n *\n * @example\n * ```typescript\n * import { getProduct } from '@htlkg/data/queries';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * const product = await getProduct(client, 'product-123');\n * ```\n */\nexport async function getProduct<TClient = any>(\n\tclient: TClient,\n\tid: string,\n): Promise<Product | null> {\n\ttry {\n\t\tconst { data, errors } = await (client as any).models.Product.get({ id });\n\n\t\tif (errors) {\n\t\t\tconsole.error(\"[getProduct] GraphQL errors:\", errors);\n\t\t\treturn null;\n\t\t}\n\n\t\treturn data as Product;\n\t} catch (error) {\n\t\tconsole.error(\"[getProduct] Error fetching product:\", error);\n\t\tthrow error;\n\t}\n}\n\n/**\n * List all products with optional filtering\n *\n * @example\n * ```typescript\n * import { listProducts } from '@htlkg/data/queries';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * const products = await listProducts(client, {\n * filter: { isActive: { eq: true } }\n * });\n * ```\n */\nexport async function listProducts<TClient = any>(\n\tclient: TClient,\n\toptions?: {\n\t\tfilter?: any;\n\t\tlimit?: number;\n\t\tnextToken?: string;\n\t},\n): Promise<{ items: Product[]; nextToken?: string }> {\n\ttry {\n\t\tconst { data, errors, nextToken } = await (\n\t\t\tclient as any\n\t\t).models.Product.list(options);\n\n\t\tif (errors) {\n\t\t\tconsole.error(\"[listProducts] GraphQL errors:\", errors);\n\t\t\treturn { items: [], nextToken: undefined };\n\t\t}\n\n\t\treturn {\n\t\t\titems: (data || []) as Product[],\n\t\t\tnextToken,\n\t\t};\n\t} catch (error) {\n\t\tconsole.error(\"[listProducts] Error fetching products:\", error);\n\t\tthrow error;\n\t}\n}\n\n/**\n * List active products\n *\n * @example\n * ```typescript\n * import { listActiveProducts } from '@htlkg/data/queries';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * const products = await listActiveProducts(client);\n * ```\n */\nexport async function listActiveProducts<TClient = any>(\n\tclient: TClient,\n\toptions?: {\n\t\tlimit?: number;\n\t\tnextToken?: string;\n\t},\n): Promise<{ items: Product[]; nextToken?: string }> {\n\treturn listProducts(client, {\n\t\tfilter: { isActive: { eq: true } },\n\t\t...options,\n\t});\n}\n\n/**\n * Get a single product instance by ID\n *\n * @example\n * ```typescript\n * import { getProductInstance } from '@htlkg/data/queries';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * const instance = await getProductInstance(client, 'instance-123');\n * ```\n */\nexport async function getProductInstance<TClient = any>(\n\tclient: TClient,\n\tid: string,\n): Promise<ProductInstance | null> {\n\ttry {\n\t\tconst { data, errors } = await (client as any).models.ProductInstance.get({\n\t\t\tid,\n\t\t});\n\n\t\tif (errors) {\n\t\t\tconsole.error(\"[getProductInstance] GraphQL errors:\", errors);\n\t\t\treturn null;\n\t\t}\n\n\t\treturn data as ProductInstance;\n\t} catch (error) {\n\t\tconsole.error(\"[getProductInstance] Error fetching product instance:\", error);\n\t\tthrow error;\n\t}\n}\n\n/**\n * List product instances by brand ID\n *\n * @example\n * ```typescript\n * import { listProductInstancesByBrand } from '@htlkg/data/queries';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * const instances = await listProductInstancesByBrand(client, 'brand-123');\n * ```\n */\nexport async function listProductInstancesByBrand<TClient = any>(\n\tclient: TClient,\n\tbrandId: string,\n\toptions?: {\n\t\tlimit?: number;\n\t\tnextToken?: string;\n\t},\n): Promise<{ items: ProductInstance[]; nextToken?: string }> {\n\ttry {\n\t\tconst { data, errors, nextToken } = await (\n\t\t\tclient as any\n\t\t).models.ProductInstance.list({\n\t\t\tfilter: { brandId: { eq: brandId } },\n\t\t\t...options,\n\t\t});\n\n\t\tif (errors) {\n\t\t\tconsole.error(\"[listProductInstancesByBrand] GraphQL errors:\", errors);\n\t\t\treturn { items: [], nextToken: undefined };\n\t\t}\n\n\t\treturn {\n\t\t\titems: (data || []) as ProductInstance[],\n\t\t\tnextToken,\n\t\t};\n\t} catch (error) {\n\t\tconsole.error(\n\t\t\t\"[listProductInstancesByBrand] Error fetching product instances:\",\n\t\t\terror,\n\t\t);\n\t\tthrow error;\n\t}\n}\n\n/**\n * List product instances by account ID\n *\n * @example\n * ```typescript\n * import { listProductInstancesByAccount } from '@htlkg/data/queries';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * const instances = await listProductInstancesByAccount(client, 'account-123');\n * ```\n */\nexport async function listProductInstancesByAccount<TClient = any>(\n\tclient: TClient,\n\taccountId: string,\n\toptions?: {\n\t\tlimit?: number;\n\t\tnextToken?: string;\n\t},\n): Promise<{ items: ProductInstance[]; nextToken?: string }> {\n\ttry {\n\t\tconst { data, errors, nextToken } = await (\n\t\t\tclient as any\n\t\t).models.ProductInstance.list({\n\t\t\tfilter: { accountId: { eq: accountId } },\n\t\t\t...options,\n\t\t});\n\n\t\tif (errors) {\n\t\t\tconsole.error(\"[listProductInstancesByAccount] GraphQL errors:\", errors);\n\t\t\treturn { items: [], nextToken: undefined };\n\t\t}\n\n\t\treturn {\n\t\t\titems: (data || []) as ProductInstance[],\n\t\t\tnextToken,\n\t\t};\n\t} catch (error) {\n\t\tconsole.error(\n\t\t\t\"[listProductInstancesByAccount] Error fetching product instances:\",\n\t\t\terror,\n\t\t);\n\t\tthrow error;\n\t}\n}\n\n/**\n * List enabled product instances by brand ID\n *\n * @example\n * ```typescript\n * import { listEnabledProductInstancesByBrand } from '@htlkg/data/queries';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * const instances = await listEnabledProductInstancesByBrand(client, 'brand-123');\n * ```\n */\nexport async function listEnabledProductInstancesByBrand<TClient = any>(\n\tclient: TClient,\n\tbrandId: string,\n\toptions?: {\n\t\tlimit?: number;\n\t\tnextToken?: string;\n\t},\n): Promise<{ items: ProductInstance[]; nextToken?: string }> {\n\ttry {\n\t\tconst { data, errors, nextToken } = await (\n\t\t\tclient as any\n\t\t).models.ProductInstance.list({\n\t\t\tfilter: {\n\t\t\t\tbrandId: { eq: brandId },\n\t\t\t\tenabled: { eq: true },\n\t\t\t},\n\t\t\t...options,\n\t\t});\n\n\t\tif (errors) {\n\t\t\tconsole.error(\n\t\t\t\t\"[listEnabledProductInstancesByBrand] GraphQL errors:\",\n\t\t\t\terrors,\n\t\t\t);\n\t\t\treturn { items: [], nextToken: undefined };\n\t\t}\n\n\t\treturn {\n\t\t\titems: (data || []) as ProductInstance[],\n\t\t\tnextToken,\n\t\t};\n\t} catch (error) {\n\t\tconsole.error(\n\t\t\t\"[listEnabledProductInstancesByBrand] Error fetching product instances:\",\n\t\t\terror,\n\t\t);\n\t\tthrow error;\n\t}\n}\n","/**\n * GraphQL Client for @htlkg/data\n *\n * Provides both client-side and server-side GraphQL capabilities using AWS Amplify Data.\n * The server-side functions use the Amplify Astro adapter for proper SSR support.\n *\n * For server-side usage, use `Astro.locals.amplifyClient` (zero-config, injected by middleware).\n */\n\nimport { generateClient as generateDataClient } from \"aws-amplify/data\";\nimport { Amplify } from \"aws-amplify\";\nimport type { ResourcesConfig } from \"aws-amplify\";\nimport { generateServerClientUsingCookies } from \"./server\";\n\n// Re-export server-side client generation (used internally by middleware)\nexport { generateServerClientUsingCookies } from \"./server\";\n\n// Re-export proxy functions for authenticated client-side operations\nexport {\n\tmutate,\n\tquery,\n\thasErrors,\n\tgetErrorMessage,\n\ttype Operation,\n\ttype GraphQLResponse,\n\ttype ProxyOptions,\n} from \"./proxy\";\n\n/**\n * Type for the server-side Amplify client (for use in type declarations)\n * This represents the client returned by generateServerClientUsingCookies\n */\nexport type AmplifyServerClient<TSchema extends Record<string, unknown> = Record<string, unknown>> =\n\tReturnType<typeof generateServerClientUsingCookies<TSchema>>;\n\n// Singleton client instance for client-side fetching\nlet sharedClientInstance: any = null;\n\n/**\n * Get or create the shared GraphQL client instance (singleton pattern)\n * Use this for client-side fetching to avoid creating multiple client instances.\n *\n * @example\n * ```typescript\n * const client = getSharedClient<Schema>();\n * const { data } = await client.models.Account.list();\n * ```\n */\nexport function getSharedClient<\n\tTSchema extends Record<string, unknown> = Record<string, unknown>,\n>(): ReturnType<typeof generateDataClient<TSchema>> {\n\tif (!sharedClientInstance) {\n\t\tsharedClientInstance = generateDataClient<TSchema>();\n\t}\n\treturn sharedClientInstance;\n}\n\n/**\n * Reset the shared client instance (useful for testing or auth state changes)\n */\nexport function resetSharedClient(): void {\n\tsharedClientInstance = null;\n}\n\n/**\n * Generate a client-side GraphQL client for use in Vue components and browser contexts\n * This is SSR-safe and should be called within a component's setup function or after hydration\n *\n * @example\n * ```typescript\n * import type { Schema } from '@backend/data/resource';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * const { data: brands } = await client.models.Brand.list();\n * ```\n */\nexport function generateClient<\n\tTSchema extends Record<string, unknown> = Record<string, unknown>,\n>(): ReturnType<typeof generateDataClient<TSchema>> {\n\treturn generateDataClient<TSchema>();\n}\n\n/**\n * Configuration for Amplify (matches amplify_outputs.json format)\n */\nexport type AstroAmplifyConfig = ResourcesConfig;\n\n/**\n * Authentication mode for server-side GraphQL client\n */\nexport type ServerAuthMode = 'userPool' | 'apiKey';\n\n/**\n * Options for generating a server-side GraphQL client\n */\nexport interface GenerateServerClientOptions {\n\t/** Authentication mode - 'userPool' (default) uses JWT from cookies, 'apiKey' uses API key */\n\tauthMode?: ServerAuthMode;\n}\n\n/**\n * Generate a server-side GraphQL client for use within runWithAmplifyServerContext\n * \n * This function creates a GraphQL client that can be used for server-side data fetching in Astro.\n * It MUST be called within runWithAmplifyServerContext to access JWT tokens from cookies.\n * \n * The client supports two authentication modes:\n * - 'userPool' (default): Uses JWT tokens from cookies (requires runWithAmplifyServerContext)\n * - 'apiKey': Uses API key for public/unauthenticated requests\n *\n * **Important**: \n * - Amplify.configure() must be called once at app startup (e.g., in amplify-server.ts)\n * - This function must be called INSIDE the operation function of runWithAmplifyServerContext\n * - The context automatically provides the token provider that reads JWT tokens from cookies\n *\n * @example\n * ```typescript\n * // In your Astro page\n * import type { Schema } from '../amplify/data/resource';\n * import { generateServerClient } from '@htlkg/data/client';\n * import { createRunWithAmplifyServerContext } from '@htlkg/core/amplify-astro-adapter';\n * import outputs from '../amplify_outputs.json';\n *\n * const runWithAmplifyServerContext = createRunWithAmplifyServerContext({ config: outputs });\n *\n * // Fetch data with authentication\n * const result = await runWithAmplifyServerContext({\n * astroServerContext: {\n * cookies: Astro.cookies,\n * request: Astro.request\n * },\n * operation: async (contextSpec) => {\n * // Generate client INSIDE the operation\n * const client = generateServerClient<Schema>({ authMode: 'userPool' });\n * return await client.models.User.list();\n * }\n * });\n * \n * const users = result.data || [];\n * ```\n * \n * @example Using API key for public data\n * ```typescript\n * const result = await runWithAmplifyServerContext({\n * astroServerContext: {\n * cookies: Astro.cookies,\n * request: Astro.request\n * },\n * operation: async (contextSpec) => {\n * const client = generateServerClient<Schema>({ authMode: 'apiKey' });\n * return await client.models.Brand.list();\n * }\n * });\n * ```\n */\nexport function generateServerClient<\n\tTSchema extends Record<string, unknown> = Record<string, unknown>,\n>(_options?: GenerateServerClientOptions): ReturnType<typeof generateDataClient<TSchema>> {\n\t// Generate the client without authMode parameter\n\t// When called within runWithAmplifyServerContext, it will automatically use the token provider\n\t// from the context (which reads JWT tokens from cookies)\n\t// The authMode should be specified per-operation, not at client creation\n\tconst client = generateDataClient<TSchema>();\n\n\treturn client;\n}\n\n/**\n * Context required for getting a server client in API routes\n */\nexport interface ServerClientContext {\n\tlocals: { amplifyClient?: any; user?: any };\n\tcookies: any;\n\trequest: Request;\n}\n\n/**\n * Get the server client from Astro context\n *\n * Uses locals.amplifyClient if available (set by middleware),\n * otherwise creates a new client using Amplify's global config.\n * No config parameter needed - uses the config set by the middleware.\n *\n * @example\n * ```typescript\n * import { getServerClient } from '@htlkg/data/client';\n *\n * export const POST: APIRoute = async (context) => {\n * const client = getServerClient(context);\n * if (!client) return new Response('Not authenticated', { status: 401 });\n *\n * const result = await client.models.User.list();\n * };\n * ```\n */\nexport function getServerClient<TSchema extends Record<string, unknown> = Record<string, unknown>>(\n\tcontext: ServerClientContext,\n): ReturnType<typeof generateServerClientUsingCookies<TSchema>> | null {\n\t// Try to use client from middleware first\n\tif (context.locals.amplifyClient) {\n\t\treturn context.locals.amplifyClient as ReturnType<typeof generateServerClientUsingCookies<TSchema>>;\n\t}\n\n\t// If no client from middleware and user is authenticated, create one using global Amplify config\n\tif (context.locals.user) {\n\t\ttry {\n\t\t\t// Get config from Amplify (set by middleware)\n\t\t\tconst amplifyConfig = Amplify.getConfig();\n\t\t\tif (amplifyConfig) {\n\t\t\t\treturn generateServerClientUsingCookies<TSchema>({\n\t\t\t\t\tconfig: amplifyConfig,\n\t\t\t\t\tcookies: context.cookies,\n\t\t\t\t\trequest: context.request,\n\t\t\t\t});\n\t\t\t}\n\t\t} catch (e) {\n\t\t\tconsole.error('[getServerClient] Failed to get Amplify config:', e);\n\t\t}\n\t}\n\n\t// No authentication available\n\treturn null;\n}\n","/**\n * Server-side data client for Astro\n *\n * Provides a client generator similar to Next.js's generateServerClientUsingCookies\n * using generateClientWithAmplifyInstance for proper server context integration.\n */\n\nimport type { AstroGlobal } from \"astro\";\nimport type { ResourcesConfig } from \"aws-amplify\";\nimport {\n\tCommonPublicClientOptions,\n\tDefaultCommonClientOptions,\n\tV6ClientSSRCookies,\n\tgenerateClientWithAmplifyInstance,\n} from \"aws-amplify/api/internals\";\nimport { getAmplifyServerContext } from \"aws-amplify/adapter-core/internals\";\nimport { createRunWithAmplifyServerContext, createLogger } from \"@htlkg/core/amplify-astro-adapter\";\n\nconst log = createLogger('server-client');\n\ninterface AstroCookiesClientParams {\n\tcookies: AstroGlobal[\"cookies\"];\n\trequest: AstroGlobal[\"request\"];\n\tconfig: ResourcesConfig;\n}\n\n/**\n * Generates a server-side data client for Astro (matches Next.js implementation)\n *\n * This function creates a client that automatically wraps all operations in the Amplify server context,\n * ensuring that authentication tokens from cookies are properly used.\n *\n * @example\n * ```typescript\n * import type { Schema } from '../amplify/data/resource';\n * import { generateServerClientUsingCookies } from '@htlkg/data/client';\n * import { parseAmplifyConfig } from 'aws-amplify/utils';\n * import outputs from '../amplify_outputs.json';\n *\n * const amplifyConfig = parseAmplifyConfig(outputs);\n *\n * const client = generateServerClientUsingCookies<Schema>({\n * config: amplifyConfig,\n * cookies: Astro.cookies,\n * request: Astro.request,\n * });\n *\n * // Use the client directly - operations are automatically wrapped\n * const result = await client.models.User.list({\n * selectionSet: ['id', 'email'],\n * limit: 100,\n * });\n * ```\n */\nexport function generateServerClientUsingCookies<\n\tT extends Record<any, any> = never,\n\tOptions extends CommonPublicClientOptions &\n\t\tAstroCookiesClientParams = DefaultCommonClientOptions &\n\t\tAstroCookiesClientParams,\n>(options: Options): V6ClientSSRCookies<T, Options> {\n\tconst runWithAmplifyServerContext = createRunWithAmplifyServerContext({\n\t\tconfig: options.config,\n\t});\n\n\tconst resourcesConfig = options.config;\n\n\t// This function reference gets passed down to InternalGraphQLAPI.ts.graphql\n\t// where this._graphql is passed in as the `fn` argument\n\t// causing it to always get invoked inside `runWithAmplifyServerContext`\n\tconst getAmplify = (fn: (amplify: any) => Promise<any>) => {\n\t\treturn runWithAmplifyServerContext({\n\t\t\tastroServerContext: {\n\t\t\t\tcookies: options.cookies,\n\t\t\t\trequest: options.request,\n\t\t\t},\n\t\t\toperation: async (contextSpec: any) => {\n\t\t\t\tconst amplifyInstance = getAmplifyServerContext(contextSpec).amplify;\n\t\t\t\t\n\t\t\t\t// Debug logging (only when DEBUG=true)\n\t\t\t\ttry {\n\t\t\t\t\tconst config = amplifyInstance.getConfig();\n\t\t\t\t\tlog.debug('Amplify config from instance:', {\n\t\t\t\t\t\thasAPI: !!config.API,\n\t\t\t\t\t\thasGraphQL: !!config.API?.GraphQL,\n\t\t\t\t\t\tendpoint: config.API?.GraphQL?.endpoint,\n\t\t\t\t\t\tdefaultAuthMode: config.API?.GraphQL?.defaultAuthMode,\n\t\t\t\t\t\tregion: config.API?.GraphQL?.region,\n\t\t\t\t\t});\n\t\t\t\t\t\n\t\t\t\t\tconst session = await amplifyInstance.Auth.fetchAuthSession();\n\t\t\t\t\tlog.debug('Auth session:', {\n\t\t\t\t\t\thasTokens: !!session.tokens,\n\t\t\t\t\t\thasAccessToken: !!session.tokens?.accessToken,\n\t\t\t\t\t\thasIdToken: !!session.tokens?.idToken,\n\t\t\t\t\t\thasCredentials: !!session.credentials,\n\t\t\t\t\t});\n\t\t\t\t} catch (e: any) {\n\t\t\t\t\tlog.debug('Error fetching session:', e.message);\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\treturn fn(amplifyInstance);\n\t\t\t},\n\t\t});\n\t};\n\n\tconst {\n\t\tcookies: _cookies,\n\t\trequest: _request,\n\t\tconfig: _config,\n\t\t...params\n\t} = options;\n\n\treturn generateClientWithAmplifyInstance<T, V6ClientSSRCookies<T, Options>>({\n\t\tamplify: getAmplify,\n\t\tconfig: resourcesConfig,\n\t\t...params,\n\t} as any);\n}\n","/**\n * Server-Side Query Helpers\n *\n * Convenience functions for executing server-side queries in Astro pages.\n * These helpers simplify the common pattern of using runWithAmplifyServerContext.\n */\n\nimport type { AstroGlobal } from \"astro\";\nimport { generateServerClient } from \"../client\";\n\n/**\n * Type for the runWithAmplifyServerContext function\n */\ntype RunWithAmplifyServerContext = (options: {\n\tastroServerContext: {\n\t\tcookies: AstroGlobal[\"cookies\"];\n\t\trequest: AstroGlobal[\"request\"];\n\t};\n\toperation: (contextSpec: unknown) => Promise<unknown>;\n}) => Promise<unknown>;\n\n/**\n * Helper to execute server-side queries in Astro pages\n *\n * This function wraps the common pattern of using runWithAmplifyServerContext\n * with generateServerClient, making it easier to fetch data server-side.\n *\n * **Note**: This requires `createRunWithAmplifyServerContext` from `@htlkg/core/amplify-astro-adapter`.\n * If you need more control, use the full pattern directly.\n *\n * @example\n * ```typescript\n * import type { Schema } from '../amplify/data/resource';\n * import { executeServerQuery } from '@htlkg/data/queries/server-helpers';\n * import { createRunWithAmplifyServerContext } from '@htlkg/core/amplify-astro-adapter';\n * import outputs from '../amplify_outputs.json';\n *\n * const runWithAmplifyServerContext = createRunWithAmplifyServerContext({ config: outputs });\n *\n * const users = await executeServerQuery<Schema>(\n * Astro,\n * runWithAmplifyServerContext,\n * async (client) => {\n * const result = await client.models.User.list();\n * return result.data || [];\n * }\n * );\n * ```\n */\nexport async function executeServerQuery<\n\tTSchema extends Record<string, unknown>,\n\tTResult,\n>(\n\tastro: AstroGlobal,\n\trunWithAmplifyServerContext: RunWithAmplifyServerContext,\n\toperation: (client: ReturnType<typeof generateServerClient<TSchema>>) => Promise<TResult>,\n): Promise<TResult> {\n\tconst result = await runWithAmplifyServerContext({\n\t\tastroServerContext: {\n\t\t\tcookies: astro.cookies,\n\t\t\trequest: astro.request,\n\t\t},\n\t\toperation: async (contextSpec: unknown) => {\n\t\t\tconst client = generateServerClient<TSchema>();\n\t\t\treturn await operation(client);\n\t\t},\n\t});\n\treturn result as TResult;\n}\n\n/**\n * Helper to execute server-side queries with API key authentication (public data)\n *\n * Use this for fetching public data that doesn't require user authentication.\n *\n * @example\n * ```typescript\n * import type { Schema } from '../amplify/data/resource';\n * import { executePublicQuery } from '@htlkg/data/queries/server-helpers';\n * import { createRunWithAmplifyServerContext } from '@htlkg/core/amplify-astro-adapter';\n * import outputs from '../amplify_outputs.json';\n *\n * const runWithAmplifyServerContext = createRunWithAmplifyServerContext({ config: outputs });\n *\n * const brands = await executePublicQuery<Schema>(\n * Astro,\n * runWithAmplifyServerContext,\n * async (client) => {\n * const result = await client.models.Brand.list();\n * return result.data || [];\n * }\n * );\n * ```\n */\nexport async function executePublicQuery<\n\tTSchema extends Record<string, unknown>,\n\tTResult,\n>(\n\tastro: AstroGlobal,\n\trunWithAmplifyServerContext: RunWithAmplifyServerContext,\n\toperation: (client: ReturnType<typeof generateServerClient<TSchema>>) => Promise<TResult>,\n): Promise<TResult> {\n\tconst result = await runWithAmplifyServerContext({\n\t\tastroServerContext: {\n\t\t\tcookies: astro.cookies,\n\t\t\trequest: astro.request,\n\t\t},\n\t\toperation: async (_contextSpec: unknown) => {\n\t\t\tconst client = generateServerClient<TSchema>({ authMode: \"apiKey\" });\n\t\t\treturn await operation(client);\n\t\t},\n\t});\n\treturn result as TResult;\n}\n","/**\n * SystemSettings Query Functions\n *\n * Provides query functions for fetching system settings from the GraphQL API.\n */\n\nimport type { SystemSettings } from \"@htlkg/core/types\";\n\n/** Default retention days if no settings exist */\nexport const DEFAULT_SOFT_DELETE_RETENTION_DAYS = 30;\n\n/** The key used for global system settings */\nexport const SYSTEM_SETTINGS_KEY = \"GLOBAL\";\n\n/**\n * Get system settings\n *\n * @example\n * ```typescript\n * import { getSystemSettings } from '@htlkg/data/queries';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * const settings = await getSystemSettings(client);\n * ```\n */\nexport async function getSystemSettings<TClient = any>(\n\tclient: TClient,\n): Promise<SystemSettings | null> {\n\ttry {\n\t\tconst { data, errors } = await (client as any).models.SystemSettings.get({\n\t\t\tkey: SYSTEM_SETTINGS_KEY,\n\t\t});\n\n\t\tif (errors) {\n\t\t\tconsole.error(\"[getSystemSettings] GraphQL errors:\", errors);\n\t\t\treturn null;\n\t\t}\n\n\t\treturn data as SystemSettings;\n\t} catch (error) {\n\t\tconsole.error(\"[getSystemSettings] Error fetching system settings:\", error);\n\t\tthrow error;\n\t}\n}\n\n/**\n * Get the soft delete retention days from system settings\n * Returns the default (30 days) if settings don't exist\n *\n * @example\n * ```typescript\n * import { getSoftDeleteRetentionDays } from '@htlkg/data/queries';\n * import { generateClient } from '@htlkg/data/client';\n *\n * const client = generateClient<Schema>();\n * const days = await getSoftDeleteRetentionDays(client);\n * ```\n */\nexport async function getSoftDeleteRetentionDays<TClient = any>(\n\tclient: TClient,\n): Promise<number> {\n\tconst settings = await getSystemSettings(client);\n\treturn settings?.softDeleteRetentionDays ?? DEFAULT_SOFT_DELETE_RETENTION_DAYS;\n}\n\n/**\n * Check if a soft-deleted item can still be restored based on retention period\n *\n * @param deletedAt - The ISO date string when the item was deleted\n * @param retentionDays - Number of days items can be restored\n * @returns Object with canRestore flag and daysRemaining/daysExpired\n */\nexport function checkRestoreEligibility(\n\tdeletedAt: string | undefined | null,\n\tretentionDays: number,\n): {\n\tcanRestore: boolean;\n\tdaysRemaining: number;\n\tdaysExpired: number;\n\texpiresAt: Date | null;\n} {\n\tif (!deletedAt) {\n\t\treturn {\n\t\t\tcanRestore: false,\n\t\t\tdaysRemaining: 0,\n\t\t\tdaysExpired: 0,\n\t\t\texpiresAt: null,\n\t\t};\n\t}\n\n\tconst deletedDate = new Date(deletedAt);\n\tconst expiresAt = new Date(deletedDate);\n\texpiresAt.setDate(expiresAt.getDate() + retentionDays);\n\n\tconst now = new Date();\n\tconst msRemaining = expiresAt.getTime() - now.getTime();\n\tconst daysRemaining = Math.ceil(msRemaining / (1000 * 60 * 60 * 24));\n\n\tif (daysRemaining <= 0) {\n\t\treturn {\n\t\t\tcanRestore: false,\n\t\t\tdaysRemaining: 0,\n\t\t\tdaysExpired: Math.abs(daysRemaining),\n\t\t\texpiresAt,\n\t\t};\n\t}\n\n\treturn {\n\t\tcanRestore: true,\n\t\tdaysRemaining,\n\t\tdaysExpired: 0,\n\t\texpiresAt,\n\t};\n}\n"],"mappings":";AAoBA,eAAsB,SACrB,QACA,IACwB;AACxB,MAAI;AACH,UAAM,EAAE,MAAM,OAAO,IAAI,MAAO,OAAe,OAAO,MAAM,IAAI,EAAE,GAAG,CAAC;AAEtE,QAAI,QAAQ;AACX,cAAQ,MAAM,8BAA8B,MAAM;AAClD,aAAO;AAAA,IACR;AAEA,WAAO;AAAA,EACR,SAAS,OAAO;AACf,YAAQ,MAAM,oCAAoC,KAAK;AACvD,UAAM;AAAA,EACP;AACD;AAgBA,eAAsB,WACrB,QACA,SAKkD;AAClD,MAAI;AACH,UAAM,EAAE,MAAM,QAAQ,UAAU,IAAI,MAAO,OAAe,OAAO,M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