@burdenoff/microfe-store 2026.703.1 → 2026.703.2
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.
- package/dist/components/InstallAppModal.js +153 -127
- package/dist/components/InstallAppModal.js.map +1 -1
- package/dist/generated/global-operations.js +6 -0
- package/dist/generated/global-operations.js.map +1 -1
- package/dist/generated/global-types.js.map +1 -1
- package/dist/hooks/useInstallations.js.map +1 -1
- package/dist/hooks/useStoreGraphQL.js +42 -34
- package/dist/hooks/useStoreGraphQL.js.map +1 -1
- package/dist/hooks/useStoreGraphQLWithContext.js +10 -7
- package/dist/hooks/useStoreGraphQLWithContext.js.map +1 -1
- package/dist/pages/AdminDashboardPage.js +451 -378
- package/dist/pages/AdminDashboardPage.js.map +1 -1
- package/dist/pages/AdminReviewModerationPage.js +182 -150
- package/dist/pages/AdminReviewModerationPage.js.map +1 -1
- package/dist/pages/AdminStoresPage.js.map +1 -1
- package/dist/pages/AdminSubmissionsQueuePage.js +642 -305
- package/dist/pages/AdminSubmissionsQueuePage.js.map +1 -1
- package/dist/pages/AppDetailPage.js.map +1 -1
- package/dist/pages/AppSettingsPage.js.map +1 -1
- package/dist/pages/CartPage.js.map +1 -1
- package/dist/pages/MyLicensesPage.js.map +1 -1
- package/dist/pages/OrdersPage.js +5 -5
- package/dist/pages/ProductDetailPage.js +504 -451
- package/dist/pages/ProductDetailPage.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useInstallations.js","names":[],"sources":["../../src/hooks/useInstallations.ts"],"sourcesContent":["import { useCallback, useEffect, useMemo, useState } from 'react';\nimport { useApolloClient } from '@apollo/client/react';\nimport {\n GetMyStoreInstallationsDocument,\n GetStoreAppInstallationDocument,\n RecordAppUninstallationDocument,\n} from '../generated/global-operations';\nimport type { StoreInstallationStatus, InstallationFilterInput } from '../generated/global-types';\nimport { useStoreGraphQLWithContext } from './useStoreGraphQLWithContext';\n\nexport interface InstalledApp {\n id: string;\n productId: string;\n workspaceId: string;\n organizationId?: string | null;\n status: StoreInstallationStatus;\n installedAt: string;\n version?: string | null;\n updatedAt: string;\n workspaceName?: string | null;\n workspaceType?: string | null;\n installedById: string;\n manifest?: Record<string, unknown> | null;\n metadata?: Record<string, unknown> | null;\n context?: Record<string, unknown> | null;\n uninstalledAt?: string | null;\n uninstalledById?: string | null;\n}\n\ninterface InstallationsState {\n installations: InstalledApp[];\n totalCount: number;\n hasMore: boolean;\n loading: boolean;\n error: Error | null;\n uninstallingIds: Set<string>;\n refetch: () => Promise<void>;\n loadMore: () => void;\n uninstall: (\n installation: Pick<InstalledApp, 'workspaceId' | 'productId'>,\n reason?: string\n ) => Promise<boolean>;\n}\n\ntype InstallationsQueryData = {\n myStoreAppInstallations: {\n total: number;\n hasMore: boolean;\n items: Array<{\n id: string;\n productId: string;\n workspaceId: string;\n organizationId?: string | null;\n status: StoreInstallationStatus;\n installedAt: string;\n version?: string | null;\n updatedAt: string;\n workspaceName?: string | null;\n workspaceType?: string | null;\n installedById: string;\n }>;\n };\n};\n\ntype UninstallMutationData = {\n recordAppUninstallation?: {\n id: string;\n } | null;\n};\n\ntype InstallationQueryData = {\n storeAppInstallation?: InstalledApp | null;\n};\n\nexport function useInstallations(options?: {\n filter?: InstallationFilterInput;\n limit?: number;\n offset?: number;\n}): InstallationsState {\n const {\n query: queryWithContext,\n mutate: mutateWithContext,\n hasOrganizationContext,\n } = useStoreGraphQLWithContext();\n const globalClient = useApolloClient();\n\n const [installations, setInstallations] = useState<InstalledApp[]>([]);\n const [allInstallations, setAllInstallations] = useState<InstalledApp[]>([]);\n const [totalCount, setTotalCount] = useState(0);\n const [hasMore, setHasMore] = useState(false);\n const [currentOffset, setCurrentOffset] = useState(options?.offset ?? 0);\n const [loading, setLoading] = useState(true);\n const [error, setError] = useState<Error | null>(null);\n const [uninstallingIds, setUninstallingIds] = useState<Set<string>>(new Set());\n const pageSize = options?.limit ?? 50;\n\n const variables = useMemo(\n () => ({\n limit: pageSize,\n offset: options?.offset ?? 0,\n filter: options?.filter,\n }),\n [pageSize, options?.offset, options?.filter]\n );\n\n const fetchInstallations = useCallback(\n async (fetchOffset = 0, append = false) => {\n setLoading(true);\n setError(null);\n\n try {\n const fetchVars = { ...variables, offset: fetchOffset };\n let result;\n if (hasOrganizationContext) {\n result = (await queryWithContext({\n query: GetMyStoreInstallationsDocument,\n variables: fetchVars,\n fetchPolicy: 'network-only',\n })) as { data?: InstallationsQueryData };\n } else {\n result = await globalClient.query<InstallationsQueryData>({\n query: GetMyStoreInstallationsDocument,\n variables: fetchVars,\n fetchPolicy: 'network-only',\n });\n }\n\n const items = result.data?.myStoreAppInstallations?.items ?? [];\n const more = result.data?.myStoreAppInstallations?.hasMore ?? false;\n if (append) {\n setAllInstallations((prev) => [...prev, ...items]);\n } else {\n setAllInstallations(items);\n }\n setInstallations(items);\n setTotalCount(result.data?.myStoreAppInstallations?.total ?? 0);\n setHasMore(more);\n setCurrentOffset(fetchOffset);\n } catch (err) {\n setError(err as Error);\n } finally {\n setLoading(false);\n }\n },\n [globalClient, hasOrganizationContext, queryWithContext, variables]\n );\n\n useEffect(() => {\n fetchInstallations(0);\n }, [fetchInstallations]);\n\n const loadMore = useCallback(() => {\n if (!hasMore || loading) return;\n fetchInstallations(currentOffset + pageSize, true);\n }, [fetchInstallations, hasMore, loading, currentOffset, pageSize]);\n\n const uninstall = useCallback(\n async (\n installation: Pick<InstalledApp, 'workspaceId' | 'productId'>,\n reason?: string\n ): Promise<boolean> => {\n const installationKey = `${installation.workspaceId}:${installation.productId}`;\n setUninstallingIds((prev) => new Set(prev).add(installationKey));\n try {\n void reason;\n let result: { data?: UninstallMutationData };\n if (hasOrganizationContext) {\n result = (await mutateWithContext({\n mutation: RecordAppUninstallationDocument,\n variables: {\n workspaceId: installation.workspaceId,\n productId: installation.productId,\n },\n })) as { data?: UninstallMutationData };\n } else {\n result = await globalClient.mutate<UninstallMutationData>({\n mutation: RecordAppUninstallationDocument,\n variables: {\n workspaceId: installation.workspaceId,\n productId: installation.productId,\n },\n });\n }\n\n const success = Boolean(result.data?.recordAppUninstallation?.id);\n if (success) {\n await fetchInstallations();\n }\n return success;\n } catch {\n return false;\n } finally {\n setUninstallingIds((prev) => {\n const next = new Set(prev);\n next.delete(installationKey);\n return next;\n });\n }\n },\n [fetchInstallations, globalClient, hasOrganizationContext, mutateWithContext]\n );\n\n return {\n installations: allInstallations,\n totalCount,\n hasMore,\n loading,\n error,\n uninstallingIds,\n refetch: () => fetchInstallations(0),\n loadMore,\n uninstall,\n };\n}\n\nexport function useInstallation(installationId?: string) {\n const { query: queryWithContext, hasOrganizationContext } = useStoreGraphQLWithContext();\n const globalClient = useApolloClient();\n const [installation, setInstallation] = useState<InstalledApp | null>(null);\n const [loading, setLoading] = useState(Boolean(installationId));\n const [error, setError] = useState<Error | null>(null);\n\n const fetchInstallation = useCallback(async () => {\n if (!installationId) {\n setInstallation(null);\n setLoading(false);\n return;\n }\n\n setLoading(true);\n setError(null);\n\n try {\n let result;\n if (hasOrganizationContext) {\n result = (await queryWithContext({\n query: GetStoreAppInstallationDocument,\n variables: { id: installationId },\n fetchPolicy: 'network-only',\n })) as { data?: InstallationQueryData };\n } else {\n result = await globalClient.query<InstallationQueryData>({\n query: GetStoreAppInstallationDocument,\n variables: { id: installationId },\n fetchPolicy: 'network-only',\n });\n }\n\n setInstallation(result.data?.storeAppInstallation ?? null);\n } catch (err) {\n setError(err as Error);\n } finally {\n setLoading(false);\n }\n }, [globalClient, hasOrganizationContext, installationId, queryWithContext]);\n\n useEffect(() => {\n fetchInstallation();\n }, [fetchInstallation]);\n\n return {\n installation,\n loading,\n error,\n refetch: fetchInstallation,\n };\n}\n"],"mappings":";;;;;AA0EA,SAAgB,EAAiB,GAIV;CACrB,IAAM,EACJ,OAAO,GACP,QAAQ,GACR,8BACE,GAA4B,EAC1B,IAAe,GAAiB,EAEhC,CAAC,GAAe,KAAoB,EAAyB,EAAE,CAAC,EACh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W,EAAE,IAAI,GAAgB;IACjC,aAAa;IACd,CAAC,GAEO,MAAM,EAAa,MAA6B;IACvD,OAAO;IACP,WAAW,EAAE,IAAI,GAAgB;IACjC,aAAa;IACd,CAAC,EAGJ,EAAgB,EAAO,MAAM,wBAAwB,KAAK;WACnD,GAAK;AACZ,KAAS,EAAa;YACd;AACR,KAAW,GAAM;;IAElB;EAAC;EAAc;EAAwB;EAAgB;EAAiB,CAAC;AAM5E,QAJA,QAAgB;AACd,KAAmB;IAClB,CAAC,EAAkB,CAAC,EAEhB;EACL;EACA;EACA;EACA,SAAS;EACV"}
|
|
1
|
+
{"version":3,"file":"useInstallations.js","names":[],"sources":["../../src/hooks/useInstallations.ts"],"sourcesContent":["import { useCallback, useEffect, useMemo, useState } from 'react';\nimport { useApolloClient } from '@apollo/client/react';\nimport {\n GetMyStoreInstallationsDocument,\n GetStoreAppInstallationDocument,\n RecordAppUninstallationDocument,\n} from '../generated/global-operations';\nimport type { StoreInstallationStatus, InstallationFilterInput } from '../generated/global-types';\nimport { useStoreGraphQLWithContext } from './useStoreGraphQLWithContext';\n\nexport interface InstalledApp {\n id: string;\n productId: string;\n workspaceId: string;\n organizationId?: string | null;\n status: StoreInstallationStatus;\n installedAt: string;\n version?: string | null;\n updatedAt: string;\n workspaceName?: string | null;\n workspaceType?: string | null;\n installedById: string;\n manifest?: Record<string, unknown> | null;\n metadata?: Record<string, unknown> | null;\n context?: Record<string, unknown> | null;\n grantedPermissions?: Array<{ resource: string; level: 'read' | 'write' }> | null;\n uninstalledAt?: string | null;\n uninstalledById?: string | null;\n}\n\ninterface InstallationsState {\n installations: InstalledApp[];\n totalCount: number;\n hasMore: boolean;\n loading: boolean;\n error: Error | null;\n uninstallingIds: Set<string>;\n refetch: () => Promise<void>;\n loadMore: () => void;\n uninstall: (\n installation: Pick<InstalledApp, 'workspaceId' | 'productId'>,\n reason?: string\n ) => Promise<boolean>;\n}\n\ntype InstallationsQueryData = {\n myStoreAppInstallations: {\n total: number;\n hasMore: boolean;\n items: Array<{\n id: string;\n productId: string;\n workspaceId: string;\n organizationId?: string | null;\n status: StoreInstallationStatus;\n installedAt: string;\n version?: string | null;\n updatedAt: string;\n workspaceName?: string | null;\n workspaceType?: string | null;\n installedById: string;\n }>;\n };\n};\n\ntype UninstallMutationData = {\n recordAppUninstallation?: {\n id: string;\n } | null;\n};\n\ntype InstallationQueryData = {\n storeAppInstallation?: InstalledApp | null;\n};\n\nexport function useInstallations(options?: {\n filter?: InstallationFilterInput;\n limit?: number;\n offset?: number;\n}): InstallationsState {\n const {\n query: queryWithContext,\n mutate: mutateWithContext,\n hasOrganizationContext,\n } = useStoreGraphQLWithContext();\n const globalClient = useApolloClient();\n\n const [installations, setInstallations] = useState<InstalledApp[]>([]);\n const [allInstallations, setAllInstallations] = useState<InstalledApp[]>([]);\n const [totalCount, setTotalCount] = useState(0);\n const [hasMore, setHasMore] = useState(false);\n const [currentOffset, setCurrentOffset] = useState(options?.offset ?? 0);\n const [loading, setLoading] = useState(true);\n const [error, setError] = useState<Error | null>(null);\n const [uninstallingIds, setUninstallingIds] = useState<Set<string>>(new Set());\n const pageSize = options?.limit ?? 50;\n\n const variables = useMemo(\n () => ({\n limit: pageSize,\n offset: options?.offset ?? 0,\n filter: options?.filter,\n }),\n [pageSize, options?.offset, options?.filter]\n );\n\n const fetchInstallations = useCallback(\n async (fetchOffset = 0, append = false) => {\n setLoading(true);\n setError(null);\n\n try {\n const fetchVars = { ...variables, offset: fetchOffset };\n let result;\n if (hasOrganizationContext) {\n result = (await queryWithContext({\n query: GetMyStoreInstallationsDocument,\n variables: fetchVars,\n fetchPolicy: 'network-only',\n })) as { data?: InstallationsQueryData };\n } else {\n result = await globalClient.query<InstallationsQueryData>({\n query: GetMyStoreInstallationsDocument,\n variables: fetchVars,\n fetchPolicy: 'network-only',\n });\n }\n\n const items = result.data?.myStoreAppInstallations?.items ?? [];\n const more = result.data?.myStoreAppInstallations?.hasMore ?? false;\n if (append) {\n setAllInstallations((prev) => [...prev, ...items]);\n } else {\n setAllInstallations(items);\n }\n setInstallations(items);\n setTotalCount(result.data?.myStoreAppInstallations?.total ?? 0);\n setHasMore(more);\n setCurrentOffset(fetchOffset);\n } catch (err) {\n setError(err as Error);\n } finally {\n setLoading(false);\n }\n },\n [globalClient, hasOrganizationContext, queryWithContext, variables]\n );\n\n useEffect(() => {\n fetchInstallations(0);\n }, [fetchInstallations]);\n\n const loadMore = useCallback(() => {\n if (!hasMore || loading) return;\n fetchInstallations(currentOffset + pageSize, true);\n }, [fetchInstallations, hasMore, loading, currentOffset, pageSize]);\n\n const uninstall = useCallback(\n async (\n installation: Pick<InstalledApp, 'workspaceId' | 'productId'>,\n reason?: string\n ): Promise<boolean> => {\n const installationKey = `${installation.workspaceId}:${installation.productId}`;\n setUninstallingIds((prev) => new Set(prev).add(installationKey));\n try {\n void reason;\n let result: { data?: UninstallMutationData };\n if (hasOrganizationContext) {\n result = (await mutateWithContext({\n mutation: RecordAppUninstallationDocument,\n variables: {\n workspaceId: installation.workspaceId,\n productId: installation.productId,\n },\n })) as { data?: UninstallMutationData };\n } else {\n result = await globalClient.mutate<UninstallMutationData>({\n mutation: RecordAppUninstallationDocument,\n variables: {\n workspaceId: installation.workspaceId,\n productId: installation.productId,\n },\n });\n }\n\n const success = Boolean(result.data?.recordAppUninstallation?.id);\n if (success) {\n await fetchInstallations();\n }\n return success;\n } catch {\n return false;\n } finally {\n setUninstallingIds((prev) => {\n const next = new Set(prev);\n next.delete(installationKey);\n return next;\n });\n }\n },\n [fetchInstallations, globalClient, hasOrganizationContext, mutateWithContext]\n );\n\n return {\n installations: allInstallations,\n totalCount,\n hasMore,\n loading,\n error,\n uninstallingIds,\n refetch: () => fetchInstallations(0),\n loadMore,\n uninstall,\n };\n}\n\nexport function useInstallation(installationId?: string) {\n const { query: queryWithContext, hasOrganizationContext } = useStoreGraphQLWithContext();\n const globalClient = useApolloClient();\n const [installation, setInstallation] = useState<InstalledApp | null>(null);\n const [loading, setLoading] = useState(Boolean(installationId));\n const [error, setError] = useState<Error | null>(null);\n\n const fetchInstallation = useCallback(async () => {\n if (!installationId) {\n setInstallation(null);\n setLoading(false);\n return;\n }\n\n setLoading(true);\n setError(null);\n\n try {\n let result;\n if (hasOrganizationContext) {\n result = (await queryWithContext({\n query: GetStoreAppInstallationDocument,\n variables: { id: installationId },\n fetchPolicy: 'network-only',\n })) as { data?: InstallationQueryData };\n } else {\n result = await globalClient.query<InstallationQueryData>({\n query: GetStoreAppInstallationDocument,\n variables: { id: installationId },\n fetchPolicy: 'network-only',\n });\n }\n\n setInstallation(result.data?.storeAppInstallation ?? null);\n } catch (err) {\n setError(err as Error);\n } finally {\n setLoading(false);\n }\n }, [globalClient, hasOrganizationContext, installationId, queryWithContext]);\n\n useEffect(() => {\n fetchInstallation();\n }, [fetchInstallation]);\n\n return {\n installation,\n loading,\n error,\n refetch: fetchInstallation,\n };\n}\n"],"mappings":";;;;;AA2EA,SAAgB,EAAiB,GAIV;CACrB,IAAM,EACJ,OAAO,GACP,QAAQ,GACR,8BACE,GAA4B,EAC1B,IAAe,GAAiB,EAEhC,CAAC,GAAe,KAAoB,EAAyB,EAAE,CAAC,EAChE,CAAC,GAAkB,KAAuB,EAAyB,EAAE,CAAC,EACtE,CAAC,GAAY,KAAiB,EAAS,EAAE,EACzC,CAAC,GAAS,KAAc,EAAS,GAAM,EACvC,CAAC,GAAe,KAAoB,EAAS,GAAS,UAAU,EAAE,EAClE,CAAC,GAAS,KAAc,EAAS,GAAK,EACtC,CAAC,GAAO,KAAY,EAAuB,KAAK,EAChD,CAAC,GAAiB,KAAsB,kBAAsB,IAAI,KAAK,CAAC,EACxE,IAAW,GAAS,SAAS,IAE7B,IAAY,SACT;EACL,OAAO;EACP,QAAQ,GAAS,UAAU;EAC3B,QAAQ,GAAS;EAClB,GACD;EAAC;EAAU,GAAS;EAAQ,GAAS;EAAO,CAC7C,EAEK,IAAqB,EACzB,OAAO,IAAc,GAAG,IAAS,OAAU;AAEzC,EADA,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(null), [i, o] = C(!1), [s, c] = C(null);
|
|
479
479
|
return {
|
|
480
480
|
createReview: y(async (t) => {
|
|
481
|
-
|
|
481
|
+
o(!0), c(null);
|
|
482
482
|
try {
|
|
483
|
-
let
|
|
483
|
+
let n = (await e({
|
|
484
484
|
mutation: a,
|
|
485
485
|
variables: { input: t }
|
|
486
486
|
})).data?.createReview ?? null;
|
|
487
|
-
return n
|
|
487
|
+
return r(n), {
|
|
488
|
+
data: n,
|
|
489
|
+
errorMessage: null
|
|
490
|
+
};
|
|
488
491
|
} catch (e) {
|
|
489
|
-
|
|
492
|
+
c(e);
|
|
493
|
+
let t = e;
|
|
494
|
+
return {
|
|
495
|
+
data: null,
|
|
496
|
+
errorMessage: t.graphQLErrors?.[0]?.message ?? t.message ?? "We could not save your review. Please try again."
|
|
497
|
+
};
|
|
490
498
|
} finally {
|
|
491
|
-
|
|
499
|
+
o(!1);
|
|
492
500
|
}
|
|
493
501
|
}, [e]),
|
|
494
|
-
review:
|
|
495
|
-
loading:
|
|
496
|
-
error:
|
|
502
|
+
review: n,
|
|
503
|
+
loading: i,
|
|
504
|
+
error: s
|
|
497
505
|
};
|
|
498
506
|
}
|
|
499
507
|
function V() {
|
|
500
|
-
let e =
|
|
508
|
+
let { mutate: e } = t(), [n, r] = C(null), [i, a] = C(!1), [o, s] = C(null);
|
|
501
509
|
return {
|
|
502
|
-
updateReview: y(async (t,
|
|
503
|
-
|
|
510
|
+
updateReview: y(async (t, n) => {
|
|
511
|
+
a(!0), s(null);
|
|
504
512
|
try {
|
|
505
|
-
let i = (await e
|
|
513
|
+
let i = (await e({
|
|
506
514
|
mutation: g,
|
|
507
515
|
variables: {
|
|
508
516
|
id: t,
|
|
509
|
-
input:
|
|
517
|
+
input: n
|
|
510
518
|
}
|
|
511
519
|
})).data?.updateReview ?? null;
|
|
512
|
-
return
|
|
520
|
+
return r(i), i;
|
|
513
521
|
} catch (e) {
|
|
514
|
-
return
|
|
522
|
+
return s(e), null;
|
|
515
523
|
} finally {
|
|
516
|
-
|
|
524
|
+
a(!1);
|
|
517
525
|
}
|
|
518
526
|
}, [e]),
|
|
519
|
-
review:
|
|
520
|
-
loading:
|
|
521
|
-
error:
|
|
527
|
+
review: n,
|
|
528
|
+
loading: i,
|
|
529
|
+
error: o
|
|
522
530
|
};
|
|
523
531
|
}
|
|
524
532
|
function H() {
|
|
525
|
-
let e =
|
|
533
|
+
let { mutate: e } = t(), [n, r] = C(!1), [i, a] = C(null);
|
|
526
534
|
return {
|
|
527
535
|
deleteReview: y(async (t) => {
|
|
528
|
-
|
|
536
|
+
r(!0), a(null);
|
|
529
537
|
try {
|
|
530
|
-
return (await e
|
|
538
|
+
return (await e({
|
|
531
539
|
mutation: o,
|
|
532
540
|
variables: { id: t }
|
|
533
541
|
})).data?.deleteReview ?? !1;
|
|
534
542
|
} catch (e) {
|
|
535
|
-
return
|
|
543
|
+
return a(e), !1;
|
|
536
544
|
} finally {
|
|
537
|
-
|
|
545
|
+
r(!1);
|
|
538
546
|
}
|
|
539
547
|
}, [e]),
|
|
540
|
-
loading:
|
|
541
|
-
error:
|
|
548
|
+
loading: n,
|
|
549
|
+
error: i
|
|
542
550
|
};
|
|
543
551
|
}
|
|
544
552
|
function U() {
|
|
545
|
-
let e =
|
|
553
|
+
let { mutate: e } = t(), [n, r] = C(!1), [i, a] = C(null);
|
|
546
554
|
return {
|
|
547
555
|
markHelpful: y(async (t) => {
|
|
548
|
-
|
|
556
|
+
r(!0), a(null);
|
|
549
557
|
try {
|
|
550
|
-
return (await e
|
|
558
|
+
return (await e({
|
|
551
559
|
mutation: u,
|
|
552
560
|
variables: { id: t }
|
|
553
561
|
})).data?.markReviewHelpful ?? null;
|
|
554
562
|
} catch (e) {
|
|
555
|
-
return
|
|
563
|
+
return a(e), null;
|
|
556
564
|
} finally {
|
|
557
|
-
|
|
565
|
+
r(!1);
|
|
558
566
|
}
|
|
559
567
|
}, [e]),
|
|
560
|
-
loading:
|
|
561
|
-
error:
|
|
568
|
+
loading: n,
|
|
569
|
+
error: i
|
|
562
570
|
};
|
|
563
571
|
}
|
|
564
572
|
function W() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useStoreGraphQL.js","names":[],"sources":["../../src/hooks/useStoreGraphQL.ts"],"sourcesContent":["import { useState, useEffect, useCallback, useRef, useMemo } from 'react';\nimport { useApolloClient } from '@apollo/client/react';\nimport { useStore } from '../providers/StoreProvider';\nimport { useStoreGraphQLWithContext } from './useStoreGraphQLWithContext';\nimport {\n BrowseStoreDocument,\n StoreProductDetailsDocument,\n HomeGroupedProductsDocument,\n} from '../generated/global-operations';\nimport { type BrowseStoreInput, type StoreProductDetailsInput } from '../generated/global-types';\n\n// Local type definitions until schema is fully defined\ntype ProductType = 'APP' | 'TEMPLATE' | 'THEME' | 'INTEGRATION' | 'WIDGET' | 'DATASET';\ntype CreateReviewInput = { productId: string; rating: number; title?: string; comment?: string };\ntype UpdateReviewInput = { rating?: number; title?: string; comment?: string };\n\n// Import generated document nodes for operations extracted to .graphql files\nimport {\n FeaturedProductsDocument,\n SearchSuggestionsDocument,\n TrendingSearchesDocument,\n FilterOptionsDocument,\n CategoriesDocument,\n ProductReviewsDocument,\n UserReviewForProductDocument,\n MyEntitlementsDocument,\n CheckEntitlementDocument,\n WorkspaceStoreOrdersDocument,\n MyPublishedProductsDocument,\n DeveloperEarningsDocument,\n CreateReviewDocument,\n UpdateReviewDocument,\n DeleteReviewDocument,\n MarkReviewHelpfulDocument,\n} from '../generated/global-operations';\n\n// ============================================================================\n// Helper to get Apollo Client\n// ============================================================================\n\n/**\n * Hook to get the store Apollo client from the shell's GatewayRoute context.\n * The Store route is wrapped with <GatewayRoute gateway=\"global\"> in the app shell,\n * so useApolloClient() returns the global gateway client.\n */\nfunction useStoreClient() {\n return useApolloClient();\n}\n\n// ============================================================================\n// Type Definitions\n// ============================================================================\n\ninterface StoreProduct {\n id: string;\n name: string;\n slug: string;\n type: string;\n nature: string;\n status: string;\n description?: string;\n pricingModel: string;\n price: number;\n currency: string;\n icon?: string;\n screenshots: string[];\n rating?: number;\n reviewCount: number;\n downloads: number;\n featured: boolean;\n category?: string;\n tags?: string[];\n publishedAt?: string;\n publisher?: {\n id: string;\n name: string;\n isVerified: boolean;\n logoUrl?: string;\n };\n}\n\ninterface BrowseStoreResult {\n products: StoreProduct[];\n totalCount: number;\n hasMore: boolean;\n nextCursor?: string;\n facets?: {\n types: { value: string; count: number }[];\n subTypes: { value: string; count: number }[];\n categories: { value: string; count: number }[];\n pricingModels: { value: string; count: number }[];\n licenses: { value: string; count: number }[];\n priceRange?: { min: number; max: number };\n ratingDistribution?: {\n fiveStars: number;\n fourStars: number;\n threeStars: number;\n twoStars: number;\n oneStar: number;\n };\n };\n}\n\ninterface ProductReview {\n id: string;\n productId: string;\n userId: string;\n rating: number;\n title?: string;\n comment?: string;\n status: string;\n helpful: number;\n createdAt: string;\n updatedAt: string;\n}\n\ninterface ProductCategory {\n id: string;\n name: string;\n slug: string;\n description?: string;\n icon?: string;\n parentId?: string;\n}\n\ninterface SearchSuggestion {\n term: string;\n type: string;\n count: number;\n highlight?: string;\n}\n\ninterface GroupedProducts {\n featured: StoreProduct[];\n mostDownloaded: StoreProduct[];\n recentlyAdded: StoreProduct[];\n freeItems: StoreProduct[];\n}\n\n// GraphQL Query Result Types\ninterface StoreProductDetailsData {\n storeProductDetails?: {\n product: StoreProduct;\n publisher?: {\n id: string;\n name: string;\n isVerified: boolean;\n logoUrl?: string;\n };\n relatedProducts?: StoreProduct[];\n reviews?: ProductReview[];\n } | null;\n}\n\ninterface FilterOptionsData {\n filterOptions?: {\n types: { value: string; count: number }[];\n subTypes: { value: string; count: number }[];\n categories: { value: string; count: number }[];\n pricingModels: { value: string; count: number }[];\n licenses: { value: string; count: number }[];\n priceRange?: { min: number; max: number };\n } | null;\n}\n\ninterface CheckEntitlementData {\n checkEntitlement?: {\n hasAccess: boolean;\n entitlement?: {\n id: string;\n productId: string;\n type: string;\n status: string;\n expiresAt?: string;\n };\n } | null;\n}\n\ninterface DeveloperEarningsData {\n developerEarnings?: {\n totalEarnings: number;\n pendingPayout: number;\n periodEarnings: number;\n currency: string;\n transactions?: Array<{\n id: string;\n amount: number;\n type: string;\n status: string;\n createdAt: string;\n }>;\n } | null;\n}\n\n// ============================================================================\n// Browse & Search Hooks\n// ============================================================================\n\n/**\n * Hook to browse/search store products with filters\n * Uses Apollo Client from context\n */\nexport function useBrowseStore(input: BrowseStoreInput = {}) {\n const client = useStoreClient();\n const [products, setProducts] = useState<StoreProduct[]>([]);\n const [totalCount, setTotalCount] = useState(0);\n const [hasMore, setHasMore] = useState(false);\n const [facets, setFacets] = useState<BrowseStoreResult['facets']>(undefined);\n const [loading, setLoading] = useState(true);\n const [error, setError] = useState<Error | null>(null);\n\n // Stringify input to use as stable dependency\n const inputKey = JSON.stringify(input);\n\n const fetchData = useCallback(async () => {\n setLoading(true);\n setError(null);\n try {\n const result = await client.query<{ browseStore: BrowseStoreResult }>({\n query: BrowseStoreDocument,\n variables: { input: JSON.parse(inputKey) },\n fetchPolicy: 'network-only',\n });\n setProducts(result.data?.browseStore?.products ?? []);\n setTotalCount(result.data?.browseStore?.totalCount ?? 0);\n setHasMore(result.data?.browseStore?.hasMore ?? false);\n setFacets(result.data?.browseStore?.facets);\n } catch (err) {\n setError(err as Error);\n } finally {\n setLoading(false);\n }\n }, [client, inputKey]);\n\n useEffect(() => {\n fetchData();\n }, [fetchData]);\n\n return {\n products,\n totalCount,\n hasMore,\n facets,\n loading,\n error,\n refetch: fetchData,\n };\n}\n\n/**\n * Hook to browse/search store products with organization context.\n * Uses organization-aware GraphQL client with automatic headers.\n * Automatically applies defaultCompatibleWith from store context\n * to the filter if not already specified in the input.\n */\nexport function useBrowseStoreWithContext(\n input: BrowseStoreInput = {},\n options?: { skip?: boolean }\n) {\n const { query: queryWithContext, hasOrganizationContext } = useStoreGraphQLWithContext();\n const globalClient = useApolloClient();\n const { defaultCompatibleWith } = useStore();\n const [allProducts, setAllProducts] = useState<StoreProduct[]>([]);\n const [totalCount, setTotalCount] = useState(0);\n const [hasMore, setHasMore] = useState(false);\n const [facets, setFacets] = useState<BrowseStoreResult['facets']>(undefined);\n const [loading, setLoading] = useState(!options?.skip);\n const [error, setError] = useState<Error | null>(null);\n const [currentOffset, setCurrentOffset] = useState(input.pagination?.offset ?? 0);\n\n const skip = options?.skip;\n\n // Merge defaultCompatibleWith into the input filter if not already set\n const mergedInput = useMemo(() => {\n if (!defaultCompatibleWith) return input;\n const merged = { ...input };\n if (merged.filter) {\n merged.filter = { ...merged.filter };\n if (!merged.filter.compatibleWith) {\n merged.filter.compatibleWith = defaultCompatibleWith;\n }\n } else {\n merged.filter = { compatibleWith: defaultCompatibleWith };\n }\n return merged;\n }, [input, defaultCompatibleWith]);\n\n // Stringify only filter/sort/type parts (NOT offset) as stable dependency\n // so changing offset for loadMore doesn't retrigger the effect\n const filterKey = useMemo(() => {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { pagination, ...rest } = mergedInput;\n return JSON.stringify(rest);\n }, [mergedInput]);\n\n const pageLimit = input.pagination?.limit ?? 30;\n\n const fetchData = useCallback(\n async (fetchOffset: number, append: boolean) => {\n if (skip) {\n setLoading(false);\n return;\n }\n setLoading(true);\n setError(null);\n try {\n const queryInput: BrowseStoreInput = {\n ...(JSON.parse(filterKey) as BrowseStoreInput),\n pagination: { ...mergedInput.pagination, limit: pageLimit, offset: fetchOffset },\n };\n\n let result;\n\n if (hasOrganizationContext) {\n // Use organization-aware query\n result = (await queryWithContext({\n query: BrowseStoreDocument,\n variables: { input: queryInput },\n fetchPolicy: 'network-only',\n })) as { data?: { browseStore: BrowseStoreResult } };\n } else {\n // Fallback to global client without organization context\n result = await globalClient.query<{ browseStore: BrowseStoreResult }>({\n query: BrowseStoreDocument,\n variables: { input: queryInput },\n fetchPolicy: 'network-only',\n });\n }\n\n const fetched = result.data?.browseStore?.products ?? [];\n if (append) {\n setAllProducts((prev) => [...prev, ...fetched]);\n } else {\n setAllProducts(fetched);\n }\n setTotalCount(result.data?.browseStore?.totalCount ?? 0);\n setHasMore(result.data?.browseStore?.hasMore ?? false);\n setFacets(result.data?.browseStore?.facets);\n setCurrentOffset(fetchOffset + fetched.length);\n } catch (err) {\n setError(err as Error);\n } finally {\n setLoading(false);\n }\n },\n [\n queryWithContext,\n globalClient,\n hasOrganizationContext,\n filterKey,\n skip,\n pageLimit,\n mergedInput.pagination,\n ]\n );\n\n // Re-fetch from offset 0 whenever filters/sort change. fetchData and pagination\n // offset are intentionally read via refs to avoid refetch loops on stable changes.\n const fetchDataRef = useRef(fetchData);\n fetchDataRef.current = fetchData;\n const offsetRef = useRef(input.pagination?.offset ?? 0);\n offsetRef.current = input.pagination?.offset ?? 0;\n useEffect(() => {\n void fetchDataRef.current(offsetRef.current, false);\n }, [filterKey, skip]);\n\n const loadMore = useCallback(() => {\n if (!hasMore || loading) return;\n void fetchData(currentOffset, true);\n }, [fetchData, hasMore, loading, currentOffset]);\n\n return {\n products: allProducts,\n totalCount,\n hasMore,\n facets,\n loading,\n error,\n refetch: () => fetchData(input.pagination?.offset ?? 0, false),\n loadMore,\n };\n}\n\n/**\n * Lazy hook to browse store on demand\n */\nexport function useLazyBrowseStore() {\n const client = useStoreClient();\n const [products, setProducts] = useState<StoreProduct[]>([]);\n const [totalCount, setTotalCount] = useState(0);\n const [hasMore, setHasMore] = useState(false);\n const [facets, setFacets] = useState<BrowseStoreResult['facets']>(undefined);\n const [loading, setLoading] = useState(false);\n const [error, setError] = useState<Error | null>(null);\n\n const browseStore = useCallback(\n async (input: BrowseStoreInput = {}) => {\n setLoading(true);\n setError(null);\n try {\n const result = await client.query<{ browseStore: BrowseStoreResult }>({\n query: BrowseStoreDocument,\n variables: { input },\n fetchPolicy: 'network-only',\n });\n const data = result.data?.browseStore;\n setProducts(data?.products ?? []);\n setTotalCount(data?.totalCount ?? 0);\n setHasMore(data?.hasMore ?? false);\n setFacets(data?.facets);\n return data;\n } catch (err) {\n setError(err as Error);\n return null;\n } finally {\n setLoading(false);\n }\n },\n [client]\n );\n\n return {\n browseStore,\n products,\n totalCount,\n hasMore,\n facets,\n loading,\n error,\n };\n}\n\n/**\n * Hook to fetch product details for product page\n */\nexport function useStoreProductDetails(input: StoreProductDetailsInput) {\n const { query: queryWithContext, hasOrganizationContext } = useStoreGraphQLWithContext();\n const globalClient = useApolloClient();\n const [data, setData] = useState<unknown>(null);\n const [loading, setLoading] = useState(true);\n const [error, setError] = useState<Error | null>(null);\n\n const shouldSkip = !input.id && !input.slug;\n\n // Stringify input to use as stable dependency (prevents infinite loops)\n const inputKey = JSON.stringify(input);\n\n // Track if fetch has been attempted for this input\n const fetchedRef = useRef<string | null>(null);\n\n const fetchData = useCallback(async () => {\n if (shouldSkip) {\n setLoading(false);\n return;\n }\n\n // Skip if already fetched for this input\n if (fetchedRef.current === inputKey) {\n return;\n }\n fetchedRef.current = inputKey;\n\n setLoading(true);\n setError(null);\n try {\n const result = hasOrganizationContext\n ? ((await queryWithContext({\n query: StoreProductDetailsDocument,\n variables: { input: JSON.parse(inputKey) },\n fetchPolicy: 'network-only',\n })) as { data?: StoreProductDetailsData })\n : await globalClient.query<StoreProductDetailsData>({\n query: StoreProductDetailsDocument,\n variables: { input: JSON.parse(inputKey) },\n fetchPolicy: 'network-only',\n });\n setData(result.data?.storeProductDetails ?? null);\n } catch (err) {\n setError(err as Error);\n } finally {\n setLoading(false);\n }\n }, [globalClient, hasOrganizationContext, inputKey, queryWithContext, shouldSkip]);\n\n useEffect(() => {\n fetchData();\n }, [fetchData]);\n\n return {\n data,\n loading,\n error,\n refetch: () => {\n fetchedRef.current = null; // Reset to allow refetch\n return fetchData();\n },\n };\n}\n\n/**\n * Lazy hook to fetch product details on demand\n */\nexport function useLazyStoreProductDetails() {\n const { query: queryWithContext, hasOrganizationContext } = useStoreGraphQLWithContext();\n const globalClient = useApolloClient();\n const [data, setData] = useState<unknown>(null);\n const [loading, setLoading] = useState(false);\n const [error, setError] = useState<Error | null>(null);\n\n const getProductDetails = useCallback(\n async (input: StoreProductDetailsInput) => {\n setLoading(true);\n setError(null);\n try {\n const result = hasOrganizationContext\n ? ((await queryWithContext({\n query: StoreProductDetailsDocument,\n variables: { input },\n })) as { data?: StoreProductDetailsData })\n : await globalClient.query<StoreProductDetailsData>({\n query: StoreProductDetailsDocument,\n variables: { input },\n });\n const details = result.data?.storeProductDetails ?? null;\n setData(details);\n return details;\n } catch (err) {\n setError(err as Error);\n return null;\n } finally {\n setLoading(false);\n }\n },\n [globalClient, hasOrganizationContext, queryWithContext]\n );\n\n return {\n getProductDetails,\n data,\n loading,\n error,\n };\n}\n\n/**\n * Hook to fetch grouped products for homepage.\n */\nexport function useHomeGroupedProducts(options?: { skip?: boolean }) {\n const client = useStoreClient();\n const { defaultCompatibleWith } = useStore();\n const [data, setData] = useState<GroupedProducts | null>(null);\n const [loading, setLoading] = useState(!options?.skip);\n const [error, setError] = useState<Error | null>(null);\n\n const skip = options?.skip;\n\n const fetchData = useCallback(async () => {\n if (skip) {\n setLoading(false);\n return;\n }\n setLoading(true);\n setError(null);\n try {\n const result = await client.query<{ homeGroupedProducts: GroupedProducts }>({\n query: HomeGroupedProductsDocument,\n variables: { compatibleWith: defaultCompatibleWith ?? null },\n fetchPolicy: 'cache-first',\n });\n setData(result.data?.homeGroupedProducts ?? null);\n } catch (err) {\n setError(err as Error);\n } finally {\n setLoading(false);\n }\n }, [client, defaultCompatibleWith, skip]);\n\n useEffect(() => {\n fetchData();\n }, [fetchData]);\n\n return {\n data,\n featured: data?.featured ?? [],\n mostDownloaded: data?.mostDownloaded ?? [],\n recentlyAdded: data?.recentlyAdded ?? [],\n freeItems: data?.freeItems ?? [],\n loading,\n error,\n refetch: fetchData,\n };\n}\n\n/**\n * Hook to fetch featured products\n */\nexport function useFeaturedProducts(limit?: number) {\n const client = useStoreClient();\n const [products, setProducts] = useState<StoreProduct[]>([]);\n const [loading, setLoading] = useState(true);\n const [error, setError] = useState<Error | null>(null);\n\n const fetchData = useCallback(async () => {\n setLoading(true);\n setError(null);\n try {\n const result = await client.query<{ featuredProducts: StoreProduct[] }>({\n query: FeaturedProductsDocument,\n variables: { limit },\n fetchPolicy: 'cache-first',\n });\n setProducts(result.data?.featuredProducts ?? []);\n } catch (err) {\n setError(err as Error);\n } finally {\n setLoading(false);\n }\n }, [client, limit]);\n\n useEffect(() => {\n fetchData();\n }, [fetchData]);\n\n return {\n products,\n loading,\n error,\n refetch: fetchData,\n };\n}\n\n/**\n * Hook to fetch search suggestions for autocomplete\n */\nexport function useSearchSuggestions(\n query: string,\n options?: { limit?: number; types?: string[] }\n) {\n const client = useStoreClient();\n const [suggestions, setSuggestions] = useState<SearchSuggestion[]>([]);\n const [loading, setLoading] = useState(false);\n const [error, setError] = useState<Error | null>(null);\n\n const shouldSkip = query.length < 2;\n\n const fetchData = useCallback(async () => {\n if (shouldSkip) {\n setSuggestions([]);\n return;\n }\n\n setLoading(true);\n setError(null);\n try {\n const result = await client.query<{ searchSuggestions: SearchSuggestion[] }>({\n query: SearchSuggestionsDocument,\n variables: { query, limit: options?.limit, types: options?.types },\n fetchPolicy: 'network-only',\n });\n setSuggestions(result.data?.searchSuggestions ?? []);\n } catch (err) {\n setError(err as Error);\n } finally {\n setLoading(false);\n }\n }, [client, query, options?.limit, options?.types, shouldSkip]);\n\n useEffect(() => {\n fetchData();\n }, [fetchData]);\n\n return {\n suggestions,\n loading,\n error,\n refetch: fetchData,\n };\n}\n\n/**\n * Lazy hook to fetch search suggestions on demand\n */\nexport function useLazySearchSuggestions() {\n const client = useStoreClient();\n const [suggestions, setSuggestions] = useState<SearchSuggestion[]>([]);\n const [loading, setLoading] = useState(false);\n const [error, setError] = useState<Error | null>(null);\n\n const getSuggestions = useCallback(\n async (query: string, options?: { limit?: number; types?: string[] }) => {\n if (query.length < 2) {\n setSuggestions([]);\n return [];\n }\n\n setLoading(true);\n setError(null);\n try {\n const result = await client.query<{ searchSuggestions: SearchSuggestion[] }>({\n query: SearchSuggestionsDocument,\n variables: { query, limit: options?.limit, types: options?.types },\n fetchPolicy: 'network-only',\n });\n const data = result.data?.searchSuggestions ?? [];\n setSuggestions(data);\n return data;\n } catch (err) {\n setError(err as Error);\n return [];\n } finally {\n setLoading(false);\n }\n },\n [client]\n );\n\n return {\n getSuggestions,\n suggestions,\n loading,\n error,\n };\n}\n\n/**\n * Hook to fetch trending search terms\n */\nexport function useTrendingSearches(options?: { limit?: number; type?: ProductType }) {\n const client = useStoreClient();\n const [terms, setTerms] = useState<string[]>([]);\n const [loading, setLoading] = useState(true);\n const [error, setError] = useState<Error | null>(null);\n\n const fetchData = useCallback(async () => {\n setLoading(true);\n setError(null);\n try {\n const result = await client.query<{ trendingSearches: string[] }>({\n query: TrendingSearchesDocument,\n variables: { limit: options?.limit, type: options?.type },\n fetchPolicy: 'cache-first',\n });\n setTerms(result.data?.trendingSearches ?? []);\n } catch (err) {\n setError(err as Error);\n } finally {\n setLoading(false);\n }\n }, [client, options?.limit, options?.type]);\n\n useEffect(() => {\n fetchData();\n }, [fetchData]);\n\n return {\n terms,\n loading,\n error,\n refetch: fetchData,\n };\n}\n\n/**\n * Hook to fetch filter options for dropdowns\n */\nexport function useFilterOptions(options?: { type?: ProductType; withProducts?: boolean }) {\n const client = useStoreClient();\n const [filterOptions, setFilterOptions] = useState<unknown>(null);\n const [loading, setLoading] = useState(true);\n const [error, setError] = useState<Error | null>(null);\n\n const fetchData = useCallback(async () => {\n setLoading(true);\n setError(null);\n try {\n const result = await client.query<FilterOptionsData>({\n query: FilterOptionsDocument,\n variables: { type: options?.type, withProducts: options?.withProducts },\n fetchPolicy: 'cache-first',\n });\n setFilterOptions(result.data?.filterOptions ?? null);\n } catch (err) {\n setError(err as Error);\n } finally {\n setLoading(false);\n }\n }, [client, options?.type, options?.withProducts]);\n\n useEffect(() => {\n fetchData();\n }, [fetchData]);\n\n return {\n filterOptions,\n loading,\n error,\n refetch: fetchData,\n };\n}\n\n// ============================================================================\n// Category Hooks\n// ============================================================================\n\n/**\n * Hook to fetch all categories\n */\nexport function useCategories() {\n const client = useStoreClient();\n const [categories, setCategories] = useState<ProductCategory[]>([]);\n const [loading, setLoading] = useState(true);\n const [error, setError] = useState<Error | null>(null);\n\n const fetchData = useCallback(async () => {\n setLoading(true);\n setError(null);\n try {\n const result = await client.query<{ categories: ProductCategory[] }>({\n query: CategoriesDocument,\n fetchPolicy: 'cache-first',\n });\n setCategories(result.data?.categories ?? []);\n } catch (err) {\n setError(err as Error);\n } finally {\n setLoading(false);\n }\n }, [client]);\n\n useEffect(() => {\n fetchData();\n }, [fetchData]);\n\n return {\n categories,\n loading,\n error,\n refetch: fetchData,\n };\n}\n\n// ============================================================================\n// Review Hooks\n// ============================================================================\n\n/**\n * Hook to fetch reviews for a product\n */\nexport function useProductReviews(productId: string, options?: { status?: string }) {\n const client = useStoreClient();\n const [reviews, setReviews] = useState<ProductReview[]>([]);\n const [loading, setLoading] = useState(true);\n const [error, setError] = useState<Error | null>(null);\n\n const fetchData = useCallback(async () => {\n if (!productId) {\n setLoading(false);\n return;\n }\n\n setLoading(true);\n setError(null);\n try {\n const result = await client.query<{ productReviews: ProductReview[] }>({\n query: ProductReviewsDocument,\n variables: { productId, status: options?.status },\n fetchPolicy: 'cache-first',\n });\n setReviews(result.data?.productReviews ?? []);\n } catch (err) {\n setError(err as Error);\n } finally {\n setLoading(false);\n }\n }, [client, productId, options?.status]);\n\n useEffect(() => {\n fetchData();\n }, [fetchData]);\n\n return {\n reviews,\n loading,\n error,\n refetch: fetchData,\n };\n}\n\n/**\n * Hook to fetch current user's review for a product\n */\nexport function useUserReviewForProduct(productId: string) {\n const client = useStoreClient();\n const [review, setReview] = useState<ProductReview | null>(null);\n const [loading, setLoading] = useState(true);\n const [error, setError] = useState<Error | null>(null);\n\n const fetchData = useCallback(async () => {\n if (!productId) {\n setLoading(false);\n return;\n }\n\n setLoading(true);\n setError(null);\n try {\n const result = await client.query<{ userReviewForProduct: ProductReview | null }>({\n query: UserReviewForProductDocument,\n variables: { productId },\n fetchPolicy: 'network-only',\n });\n setReview(result.data?.userReviewForProduct ?? null);\n } catch (err) {\n setError(err as Error);\n } finally {\n setLoading(false);\n }\n }, [client, productId]);\n\n useEffect(() => {\n fetchData();\n }, [fetchData]);\n\n return {\n review,\n loading,\n error,\n refetch: fetchData,\n };\n}\n\n/**\n * Hook to create a review\n */\nexport function useCreateReview() {\n const client = useStoreClient();\n const [review, setReview] = useState<ProductReview | null>(null);\n const [loading, setLoading] = useState(false);\n const [error, setError] = useState<Error | null>(null);\n\n const createReview = useCallback(\n async (input: CreateReviewInput) => {\n setLoading(true);\n setError(null);\n try {\n const result = await client.mutate<{ createReview: ProductReview }>({\n mutation: CreateReviewDocument,\n variables: { input },\n });\n const data = result.data?.createReview ?? null;\n setReview(data);\n return data;\n } catch (err) {\n setError(err as Error);\n return null;\n } finally {\n setLoading(false);\n }\n },\n [client]\n );\n\n return {\n createReview,\n review,\n loading,\n error,\n };\n}\n\n/**\n * Hook to update a review\n */\nexport function useUpdateReview() {\n const client = useStoreClient();\n const [review, setReview] = useState<ProductReview | null>(null);\n const [loading, setLoading] = useState(false);\n const [error, setError] = useState<Error | null>(null);\n\n const updateReview = useCallback(\n async (id: string, input: UpdateReviewInput) => {\n setLoading(true);\n setError(null);\n try {\n const result = await client.mutate<{ updateReview: ProductReview }>({\n mutation: UpdateReviewDocument,\n variables: { id, input },\n });\n const data = result.data?.updateReview ?? null;\n setReview(data);\n return data;\n } catch (err) {\n setError(err as Error);\n return null;\n } finally {\n setLoading(false);\n }\n },\n [client]\n );\n\n return {\n updateReview,\n review,\n loading,\n error,\n };\n}\n\n/**\n * Hook to delete a review\n */\nexport function useDeleteReview() {\n const client = useStoreClient();\n const [loading, setLoading] = useState(false);\n const [error, setError] = useState<Error | null>(null);\n\n const deleteReview = useCallback(\n async (id: string) => {\n setLoading(true);\n setError(null);\n try {\n const result = await client.mutate<{ deleteReview: boolean }>({\n mutation: DeleteReviewDocument,\n variables: { id },\n });\n return result.data?.deleteReview ?? false;\n } catch (err) {\n setError(err as Error);\n return false;\n } finally {\n setLoading(false);\n }\n },\n [client]\n );\n\n return {\n deleteReview,\n loading,\n error,\n };\n}\n\n/**\n * Hook to mark review as helpful\n */\nexport function useMarkReviewHelpful() {\n const client = useStoreClient();\n const [loading, setLoading] = useState(false);\n const [error, setError] = useState<Error | null>(null);\n\n const markHelpful = useCallback(\n async (id: string) => {\n setLoading(true);\n setError(null);\n try {\n const result = await client.mutate<{ markReviewHelpful: { id: string; helpful: number } }>({\n mutation: MarkReviewHelpfulDocument,\n variables: { id },\n });\n return result.data?.markReviewHelpful ?? null;\n } catch (err) {\n setError(err as Error);\n return null;\n } finally {\n setLoading(false);\n }\n },\n [client]\n );\n\n return {\n markHelpful,\n loading,\n error,\n };\n}\n\n// ============================================================================\n// Entitlement Hooks\n// ============================================================================\n\n/**\n * Hook to fetch current user's entitlements\n */\nexport function useMyEntitlements() {\n const { query: queryWithContext, hasOrganizationContext } = useStoreGraphQLWithContext();\n const globalClient = useApolloClient();\n const PAGE_SIZE = 20;\n const [allEntitlements, setAllEntitlements] = useState<unknown[]>([]);\n const [hasMore, setHasMore] = useState(false);\n const [currentOffset, setCurrentOffset] = useState(0);\n const [loading, setLoading] = useState(true);\n const [error, setError] = useState<Error | null>(null);\n\n const fetchData = useCallback(\n async (fetchOffset = 0, append = false) => {\n setLoading(true);\n setError(null);\n try {\n const variables = { limit: PAGE_SIZE, offset: fetchOffset };\n const result = hasOrganizationContext\n ? ((await queryWithContext({\n query: MyEntitlementsDocument,\n variables,\n fetchPolicy: 'network-only',\n })) as { data?: { myEntitlements: unknown[] } })\n : await globalClient.query<{ myEntitlements: unknown[] }>({\n query: MyEntitlementsDocument,\n variables,\n fetchPolicy: 'network-only',\n });\n const fetched = result.data?.myEntitlements ?? [];\n if (append) {\n setAllEntitlements((prev) => [...prev, ...fetched]);\n } else {\n setAllEntitlements(fetched);\n }\n setHasMore(fetched.length === PAGE_SIZE);\n setCurrentOffset(fetchOffset);\n } catch (err) {\n setError(err as Error);\n } finally {\n setLoading(false);\n }\n },\n [globalClient, hasOrganizationContext, queryWithContext]\n );\n\n useEffect(() => {\n fetchData(0);\n }, [fetchData]);\n\n const loadMore = useCallback(() => {\n if (!hasMore || loading) return;\n fetchData(currentOffset + PAGE_SIZE, true);\n }, [fetchData, hasMore, loading, currentOffset]);\n\n return {\n entitlements: allEntitlements,\n hasMore,\n loading,\n error,\n refetch: () => fetchData(0),\n loadMore,\n };\n}\n\n/**\n * Hook to check entitlement for a product\n */\nexport function useCheckEntitlement(productId: string) {\n const client = useStoreClient();\n const [entitlement, setEntitlement] = useState<unknown>(null);\n const [loading, setLoading] = useState(true);\n const [error, setError] = useState<Error | null>(null);\n\n const fetchData = useCallback(async () => {\n if (!productId) {\n setLoading(false);\n return;\n }\n\n setLoading(true);\n setError(null);\n try {\n const result = await client.query<CheckEntitlementData>({\n query: CheckEntitlementDocument,\n variables: { productId },\n fetchPolicy: 'network-only',\n });\n setEntitlement(result.data?.checkEntitlement ?? null);\n } catch (err) {\n setError(err as Error);\n } finally {\n setLoading(false);\n }\n }, [client, productId]);\n\n useEffect(() => {\n fetchData();\n }, [fetchData]);\n\n return {\n entitlement,\n loading,\n error,\n refetch: fetchData,\n };\n}\n\n// ============================================================================\n// Order Hooks\n// ============================================================================\n\n/**\n * Hook to fetch workspace store orders\n */\nexport function useWorkspaceStoreOrders(\n billingAccountId: string,\n page: number,\n limit: number,\n options?: { status?: string; search?: string }\n) {\n const client = useStoreClient();\n const [orders, setOrders] = useState<unknown[]>([]);\n const [total, setTotal] = useState(0);\n const [loading, setLoading] = useState(true);\n const [error, setError] = useState<Error | null>(null);\n\n const fetchData = useCallback(async () => {\n if (!billingAccountId) {\n setLoading(false);\n return;\n }\n\n setLoading(true);\n setError(null);\n try {\n const result = await client.query<{\n workspaceStoreOrders: { total: number; orders: unknown[] };\n }>({\n query: WorkspaceStoreOrdersDocument,\n variables: {\n billingAccountId,\n page,\n limit,\n status: options?.status,\n search: options?.search,\n },\n fetchPolicy: 'network-only',\n });\n setOrders(result.data?.workspaceStoreOrders?.orders ?? []);\n setTotal(result.data?.workspaceStoreOrders?.total ?? 0);\n } catch (err) {\n setError(err as Error);\n } finally {\n setLoading(false);\n }\n }, [client, billingAccountId, page, limit, options?.status, options?.search]);\n\n useEffect(() => {\n fetchData();\n }, [fetchData]);\n\n return {\n orders,\n total,\n loading,\n error,\n refetch: fetchData,\n };\n}\n\n// ============================================================================\n// Publisher Hooks\n// ============================================================================\n\n/**\n * Hook to fetch publisher's products\n */\nexport function useMyPublishedProducts() {\n const client = useStoreClient();\n const [allProducts, setAllProducts] = useState<StoreProduct[]>([]);\n const [hasMore, setHasMore] = useState(false);\n const [currentOffset, setCurrentOffset] = useState(0);\n const [loading, setLoading] = useState(true);\n const [error, setError] = useState<Error | null>(null);\n\n const PAGE_SIZE = 20;\n\n const fetchData = useCallback(\n async (fetchOffset = 0, append = false) => {\n setLoading(true);\n setError(null);\n try {\n const result = await client.query<{ publishedProducts: StoreProduct[] }>({\n query: MyPublishedProductsDocument,\n variables: { limit: PAGE_SIZE, offset: fetchOffset },\n fetchPolicy: 'network-only',\n });\n const fetched = result.data?.publishedProducts ?? [];\n if (append) {\n setAllProducts((prev) => [...prev, ...fetched]);\n } else {\n setAllProducts(fetched);\n }\n setHasMore(fetched.length === PAGE_SIZE);\n setCurrentOffset(fetchOffset + fetched.length);\n } catch (err) {\n setError(err as Error);\n } finally {\n setLoading(false);\n }\n },\n [client]\n );\n\n const loadMore = useCallback(() => {\n if (!hasMore || loading) return;\n void fetchData(currentOffset, true);\n }, [fetchData, hasMore, loading, currentOffset]);\n\n useEffect(() => {\n void fetchData(0, false);\n }, [fetchData]);\n\n return {\n products: allProducts,\n hasMore,\n loading,\n error,\n refetch: () => fetchData(0, false),\n loadMore,\n };\n}\n\n/**\n * Hook to fetch developer earnings\n */\nexport function useDeveloperEarnings(options?: {\n period?: string;\n startDate?: string;\n endDate?: string;\n}) {\n const { query: queryWithContext, hasOrganizationContext } = useStoreGraphQLWithContext();\n const globalClient = useApolloClient();\n const [earnings, setEarnings] = useState<unknown>(null);\n const [loading, setLoading] = useState(true);\n const [error, setError] = useState<Error | null>(null);\n\n const fetchData = useCallback(async () => {\n setLoading(true);\n setError(null);\n try {\n const result = hasOrganizationContext\n ? ((await queryWithContext({\n query: DeveloperEarningsDocument,\n variables: { input: options },\n fetchPolicy: 'network-only',\n })) as { data?: DeveloperEarningsData })\n : await globalClient.query<DeveloperEarningsData>({\n query: DeveloperEarningsDocument,\n variables: { input: options },\n fetchPolicy: 'network-only',\n });\n setEarnings(result.data?.developerEarnings ?? null);\n } catch (err) {\n setError(err as Error);\n } finally {\n setLoading(false);\n }\n }, [globalClient, hasOrganizationContext, options, queryWithContext]);\n\n useEffect(() => {\n fetchData();\n }, [fetchData]);\n\n return {\n earnings,\n loading,\n error,\n refetch: fetchData,\n };\n}\n\n// ============================================================================\n// Re-export types for convenience\n// ============================================================================\n\nexport type {\n BrowseStoreInput,\n StoreProductDetailsInput,\n ProductType,\n CreateReviewInput,\n UpdateReviewInput,\n StoreProduct,\n ProductReview,\n ProductCategory,\n SearchSuggestion,\n GroupedProducts,\n BrowseStoreResult,\n};\n"],"mappings":";;;;;;AA6CA,SAAS,IAAiB;AACxB,QAAO,GAAiB;;AA4J1B,SAAgB,EAAe,IAA0B,EAAE,EAAE;CAC3D,IAAM,IAAS,GAAgB,EACzB,CAAC,GAAU,KAAe,EAAyB,EAAE,CAAC,EACtD,CAAC,GAAY,KAAiB,EAAS,EAAE,EACzC,CAAC,GAAS,KAAc,EAAS,GAAM,EACvC,CAAC,GAAQ,KAAa,EAAsC,KAAA,EAAU,EACtE,CAAC,GAAS,KAAc,EAAS,GAAK,EACtC,CAAC,GAAO,KAAY,EAAuB,KAAK,EAGhD,IAAW,KAAK,UAAU,EAAM,EAEhC,IAAY,EAAY,YAAY;AAExC,EADA,EAAW,GAAK,EAChB,EAAS,KAAK;AACd,MAAI;GACF,IAAM,IAAS,MA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jB;;AAIF,EADA,EAAW,GAAK,EAChB,EAAS,KAAK;AACd,MAAI;AAMF,MALe,MAAM,EAAO,MAA4B;IACtD,OAAO;IACP,WAAW,EAAE,cAAW;IACxB,aAAa;IACd,CAAC,EACoB,MAAM,oBAAoB,KAAK;WAC9C,GAAK;AACZ,KAAS,EAAa;YACd;AACR,KAAW,GAAM;;IAElB,CAAC,GAAQ,EAAU,CAAC;AAMvB,QAJA,QAAgB;AACd,KAAW;IACV,CAAC,EAAU,CAAC,EAER;EACL;EACA;EACA;EACA,SAAS;EACV;;AAUH,SAAgB,EACd,GACA,GACA,GACA,GACA;CACA,IAAM,IAAS,GAAgB,EACzB,CAAC,GAAQ,KAAa,EAAoB,EAAE,CAAC,EAC7C,CAAC,GAAO,KAAY,EAAS,EAAE,EAC/B,CAAC,GAAS,KAAc,EAAS,GAAK,EACtC,CAAC,GAAO,KAAY,EAAuB,KAAK,EAEhD,IAAY,EAAY,YAAY;AACxC,MAAI,CAAC,GAAkB;AACrB,KAAW,GAAM;AACjB;;AAIF,EADA,EAAW,GAAK,EAChB,EAAS,KAAK;AACd,MAAI;GACF,IAAM,IAAS,MAAM,EAAO,MAEzB;IACD,OAAO;IACP,WAAW;KACT;KACA;KACA;KACA,QAAQ,GAAS;KACjB,QAAQ,GAAS;KAClB;IACD,aAAa;IACd,CAAC;AAEF,GADA,EAAU,EAAO,MAAM,sBAAsB,UAAU,EAAE,CAAC,EAC1D,EAAS,EAAO,MAAM,sBAAsB,SAAS,EAAE;WAChD,GAAK;AACZ,KAAS,EAAa;YACd;AACR,KAAW,GAAM;;IAElB;EAAC;EAAQ;EAAkB;EAAM;EAAO,GAAS;EAAQ,GAAS;EAAO,CAAC;AAM7E,QAJA,QAAgB;AACd,KAAW;IACV,CAAC,EAAU,CAAC,EAER;EACL;EACA;EACA;EACA;EACA,SAAS;EACV"}
|
|
1
|
+
{"version":3,"file":"useStoreGraphQL.js","names":[],"sources":["../../src/hooks/useStoreGraphQL.ts"],"sourcesContent":["import { useState, useEffect, useCallback, useRef, useMemo } from 'react';\nimport { useApolloClient } from '@apollo/client/react';\nimport { useStore } from '../providers/StoreProvider';\nimport { useStoreGraphQLWithContext } from './useStoreGraphQLWithContext';\nimport {\n BrowseStoreDocument,\n StoreProductDetailsDocument,\n HomeGroupedProductsDocument,\n} from '../generated/global-operations';\nimport { type BrowseStoreInput, type StoreProductDetailsInput } from '../generated/global-types';\n\n// Local type definitions until schema is fully defined\ntype ProductType = 'APP' | 'TEMPLATE' | 'THEME' | 'INTEGRATION' | 'WIDGET' | 'DATASET';\ntype CreateReviewInput = { productId: string; rating: number; title?: string; comment?: string };\ntype UpdateReviewInput = { rating?: number; title?: string; comment?: string };\n\n// Import generated document nodes for operations extracted to .graphql files\nimport {\n FeaturedProductsDocument,\n SearchSuggestionsDocument,\n TrendingSearchesDocument,\n FilterOptionsDocument,\n CategoriesDocument,\n ProductReviewsDocument,\n UserReviewForProductDocument,\n MyEntitlementsDocument,\n CheckEntitlementDocument,\n WorkspaceStoreOrdersDocument,\n MyPublishedProductsDocument,\n DeveloperEarningsDocument,\n CreateReviewDocument,\n UpdateReviewDocument,\n DeleteReviewDocument,\n MarkReviewHelpfulDocument,\n} from '../generated/global-operations';\n\n// ============================================================================\n// Helper to get Apollo Client\n// ============================================================================\n\n/**\n * Hook to get the store Apollo client from the shell's GatewayRoute context.\n * The Store route is wrapped with <GatewayRoute gateway=\"global\"> in the app shell,\n * so useApolloClient() returns the global gateway client.\n */\nfunction useStoreClient() {\n return useApolloClient();\n}\n\n// ============================================================================\n// Type Definitions\n// ============================================================================\n\ninterface StoreProduct {\n id: string;\n name: string;\n slug: string;\n type: string;\n nature: string;\n status: string;\n description?: string;\n pricingModel: string;\n price: number;\n currency: string;\n icon?: string;\n screenshots: string[];\n rating?: number;\n reviewCount: number;\n downloads: number;\n featured: boolean;\n category?: string;\n tags?: string[];\n publishedAt?: string;\n publisher?: {\n id: string;\n name: string;\n isVerified: boolean;\n logoUrl?: string;\n };\n}\n\ninterface BrowseStoreResult {\n products: StoreProduct[];\n totalCount: number;\n hasMore: boolean;\n nextCursor?: string;\n facets?: {\n types: { value: string; count: number }[];\n subTypes: { value: string; count: number }[];\n categories: { value: string; count: number }[];\n pricingModels: { value: string; count: number }[];\n licenses: { value: string; count: number }[];\n priceRange?: { min: number; max: number };\n ratingDistribution?: {\n fiveStars: number;\n fourStars: number;\n threeStars: number;\n twoStars: number;\n oneStar: number;\n };\n };\n}\n\ninterface ProductReview {\n id: string;\n productId: string;\n userId: string;\n rating: number;\n title?: string;\n comment?: string;\n status: string;\n helpful: number;\n createdAt: string;\n updatedAt: string;\n}\n\ninterface ProductCategory {\n id: string;\n name: string;\n slug: string;\n description?: string;\n icon?: string;\n parentId?: string;\n}\n\ninterface SearchSuggestion {\n term: string;\n type: string;\n count: number;\n highlight?: string;\n}\n\ninterface GroupedProducts {\n featured: StoreProduct[];\n mostDownloaded: StoreProduct[];\n recentlyAdded: StoreProduct[];\n freeItems: StoreProduct[];\n}\n\n// GraphQL Query Result Types\ninterface StoreProductDetailsData {\n storeProductDetails?: {\n product: StoreProduct;\n publisher?: {\n id: string;\n name: string;\n isVerified: boolean;\n logoUrl?: string;\n };\n relatedProducts?: StoreProduct[];\n reviews?: ProductReview[];\n } | null;\n}\n\ninterface FilterOptionsData {\n filterOptions?: {\n types: { value: string; count: number }[];\n subTypes: { value: string; count: number }[];\n categories: { value: string; count: number }[];\n pricingModels: { value: string; count: number }[];\n licenses: { value: string; count: number }[];\n priceRange?: { min: number; max: number };\n } | null;\n}\n\ninterface CheckEntitlementData {\n checkEntitlement?: {\n hasAccess: boolean;\n entitlement?: {\n id: string;\n productId: string;\n type: string;\n status: string;\n expiresAt?: string;\n };\n } | null;\n}\n\ninterface DeveloperEarningsData {\n developerEarnings?: {\n totalEarnings: number;\n pendingPayout: number;\n periodEarnings: number;\n currency: string;\n transactions?: Array<{\n id: string;\n amount: number;\n type: string;\n status: string;\n createdAt: string;\n }>;\n } | null;\n}\n\n// ============================================================================\n// Browse & Search Hooks\n// ============================================================================\n\n/**\n * Hook to browse/search store products with filters\n * Uses Apollo Client from context\n */\nexport function useBrowseStore(input: BrowseStoreInput = {}) {\n const client = useStoreClient();\n const [products, setProducts] = useState<StoreProduct[]>([]);\n const [totalCount, setTotalCount] = useState(0);\n const [hasMore, setHasMore] = useState(false);\n const [facets, setFacets] = useState<BrowseStoreResult['facets']>(undefined);\n const [loading, setLoading] = useState(true);\n const [error, setError] = useState<Error | null>(null);\n\n // Stringify input to use as stable dependency\n const inputKey = JSON.stringify(input);\n\n const fetchData = useCallback(async () => {\n setLoading(true);\n setError(null);\n try {\n const result = await client.query<{ browseStore: BrowseStoreResult }>({\n query: BrowseStoreDocument,\n variables: { input: JSON.parse(inputKey) },\n fetchPolicy: 'network-only',\n });\n setProducts(result.data?.browseStore?.products ?? []);\n setTotalCount(result.data?.browseStore?.totalCount ?? 0);\n setHasMore(result.data?.browseStore?.hasMore ?? false);\n setFacets(result.data?.browseStore?.facets);\n } catch (err) {\n setError(err as Error);\n } finally {\n setLoading(false);\n }\n }, [client, inputKey]);\n\n useEffect(() => {\n fetchData();\n }, [fetchData]);\n\n return {\n products,\n totalCount,\n hasMore,\n facets,\n loading,\n error,\n refetch: fetchData,\n };\n}\n\n/**\n * Hook to browse/search store products with organization context.\n * Uses organization-aware GraphQL client with automatic headers.\n * Automatically applies defaultCompatibleWith from store context\n * to the filter if not already specified in the input.\n */\nexport function useBrowseStoreWithContext(\n input: BrowseStoreInput = {},\n options?: { skip?: boolean }\n) {\n const { query: queryWithContext, hasOrganizationContext } = useStoreGraphQLWithContext();\n const globalClient = useApolloClient();\n const { defaultCompatibleWith } = useStore();\n const [allProducts, setAllProducts] = useState<StoreProduct[]>([]);\n const [totalCount, setTotalCount] = useState(0);\n const [hasMore, setHasMore] = useState(false);\n const [facets, setFacets] = useState<BrowseStoreResult['facets']>(undefined);\n const [loading, setLoading] = useState(!options?.skip);\n const [error, setError] = useState<Error | null>(null);\n const [currentOffset, setCurrentOffset] = useState(input.pagination?.offset ?? 0);\n\n const skip = options?.skip;\n\n // Merge defaultCompatibleWith into the input filter if not already set\n const mergedInput = useMemo(() => {\n if (!defaultCompatibleWith) return input;\n const merged = { ...input };\n if (merged.filter) {\n merged.filter = { ...merged.filter };\n if (!merged.filter.compatibleWith) {\n merged.filter.compatibleWith = defaultCompatibleWith;\n }\n } else {\n merged.filter = { compatibleWith: defaultCompatibleWith };\n }\n return merged;\n }, [input, defaultCompatibleWith]);\n\n // Stringify only filter/sort/type parts (NOT offset) as stable dependency\n // so changing offset for loadMore doesn't retrigger the effect\n const filterKey = useMemo(() => {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { pagination, ...rest } = mergedInput;\n return JSON.stringify(rest);\n }, [mergedInput]);\n\n const pageLimit = input.pagination?.limit ?? 30;\n\n const fetchData = useCallback(\n async (fetchOffset: number, append: boolean) => {\n if (skip) {\n setLoading(false);\n return;\n }\n setLoading(true);\n setError(null);\n try {\n const queryInput: BrowseStoreInput = {\n ...(JSON.parse(filterKey) as BrowseStoreInput),\n pagination: { ...mergedInput.pagination, limit: pageLimit, offset: fetchOffset },\n };\n\n let result;\n\n if (hasOrganizationContext) {\n // Use organization-aware query\n result = (await queryWithContext({\n query: BrowseStoreDocument,\n variables: { input: queryInput },\n fetchPolicy: 'network-only',\n })) as { data?: { browseStore: BrowseStoreResult } };\n } else {\n // Fallback to global client without organization context\n result = await globalClient.query<{ browseStore: BrowseStoreResult }>({\n query: BrowseStoreDocument,\n variables: { input: queryInput },\n fetchPolicy: 'network-only',\n });\n }\n\n const fetched = result.data?.browseStore?.products ?? [];\n if (append) {\n setAllProducts((prev) => [...prev, ...fetched]);\n } else {\n setAllProducts(fetched);\n }\n setTotalCount(result.data?.browseStore?.totalCount ?? 0);\n setHasMore(result.data?.browseStore?.hasMore ?? false);\n setFacets(result.data?.browseStore?.facets);\n setCurrentOffset(fetchOffset + fetched.length);\n } catch (err) {\n setError(err as Error);\n } finally {\n setLoading(false);\n }\n },\n [\n queryWithContext,\n globalClient,\n hasOrganizationContext,\n filterKey,\n skip,\n pageLimit,\n mergedInput.pagination,\n ]\n );\n\n // Re-fetch from offset 0 whenever filters/sort change. fetchData and pagination\n // offset are intentionally read via refs to avoid refetch loops on stable changes.\n const fetchDataRef = useRef(fetchData);\n fetchDataRef.current = fetchData;\n const offsetRef = useRef(input.pagination?.offset ?? 0);\n offsetRef.current = input.pagination?.offset ?? 0;\n useEffect(() => {\n void fetchDataRef.current(offsetRef.current, false);\n }, [filterKey, skip]);\n\n const loadMore = useCallback(() => {\n if (!hasMore || loading) return;\n void fetchData(currentOffset, true);\n }, [fetchData, hasMore, loading, currentOffset]);\n\n return {\n products: allProducts,\n totalCount,\n hasMore,\n facets,\n loading,\n error,\n refetch: () => fetchData(input.pagination?.offset ?? 0, false),\n loadMore,\n };\n}\n\n/**\n * Lazy hook to browse store on demand\n */\nexport function useLazyBrowseStore() {\n const client = useStoreClient();\n const [products, setProducts] = useState<StoreProduct[]>([]);\n const [totalCount, setTotalCount] = useState(0);\n const [hasMore, setHasMore] = useState(false);\n const [facets, setFacets] = useState<BrowseStoreResult['facets']>(undefined);\n const [loading, setLoading] = useState(false);\n const [error, setError] = useState<Error | null>(null);\n\n const browseStore = useCallback(\n async (input: BrowseStoreInput = {}) => {\n setLoading(true);\n setError(null);\n try {\n const result = await client.query<{ browseStore: BrowseStoreResult }>({\n query: BrowseStoreDocument,\n variables: { input },\n fetchPolicy: 'network-only',\n });\n const data = result.data?.browseStore;\n setProducts(data?.products ?? []);\n setTotalCount(data?.totalCount ?? 0);\n setHasMore(data?.hasMore ?? false);\n setFacets(data?.facets);\n return data;\n } catch (err) {\n setError(err as Error);\n return null;\n } finally {\n setLoading(false);\n }\n },\n [client]\n );\n\n return {\n browseStore,\n products,\n totalCount,\n hasMore,\n facets,\n loading,\n error,\n };\n}\n\n/**\n * Hook to fetch product details for product page\n */\nexport function useStoreProductDetails(input: StoreProductDetailsInput) {\n const { query: queryWithContext, hasOrganizationContext } = useStoreGraphQLWithContext();\n const globalClient = useApolloClient();\n const [data, setData] = useState<unknown>(null);\n const [loading, setLoading] = useState(true);\n const [error, setError] = useState<Error | null>(null);\n\n const shouldSkip = !input.id && !input.slug;\n\n // Stringify input to use as stable dependency (prevents infinite loops)\n const inputKey = JSON.stringify(input);\n\n // Track if fetch has been attempted for this input\n const fetchedRef = useRef<string | null>(null);\n\n const fetchData = useCallback(async () => {\n if (shouldSkip) {\n setLoading(false);\n return;\n }\n\n // Skip if already fetched for this input\n if (fetchedRef.current === inputKey) {\n return;\n }\n fetchedRef.current = inputKey;\n\n setLoading(true);\n setError(null);\n try {\n const result = hasOrganizationContext\n ? ((await queryWithContext({\n query: StoreProductDetailsDocument,\n variables: { input: JSON.parse(inputKey) },\n fetchPolicy: 'network-only',\n })) as { data?: StoreProductDetailsData })\n : await globalClient.query<StoreProductDetailsData>({\n query: StoreProductDetailsDocument,\n variables: { input: JSON.parse(inputKey) },\n fetchPolicy: 'network-only',\n });\n setData(result.data?.storeProductDetails ?? null);\n } catch (err) {\n setError(err as Error);\n } finally {\n setLoading(false);\n }\n }, [globalClient, hasOrganizationContext, inputKey, queryWithContext, shouldSkip]);\n\n useEffect(() => {\n fetchData();\n }, [fetchData]);\n\n return {\n data,\n loading,\n error,\n refetch: () => {\n fetchedRef.current = null; // Reset to allow refetch\n return fetchData();\n },\n };\n}\n\n/**\n * Lazy hook to fetch product details on demand\n */\nexport function useLazyStoreProductDetails() {\n const { query: queryWithContext, hasOrganizationContext } = useStoreGraphQLWithContext();\n const globalClient = useApolloClient();\n const [data, setData] = useState<unknown>(null);\n const [loading, setLoading] = useState(false);\n const [error, setError] = useState<Error | null>(null);\n\n const getProductDetails = useCallback(\n async (input: StoreProductDetailsInput) => {\n setLoading(true);\n setError(null);\n try {\n const result = hasOrganizationContext\n ? ((await queryWithContext({\n query: StoreProductDetailsDocument,\n variables: { input },\n })) as { data?: StoreProductDetailsData })\n : await globalClient.query<StoreProductDetailsData>({\n query: StoreProductDetailsDocument,\n variables: { input },\n });\n const details = result.data?.storeProductDetails ?? null;\n setData(details);\n return details;\n } catch (err) {\n setError(err as Error);\n return null;\n } finally {\n setLoading(false);\n }\n },\n [globalClient, hasOrganizationContext, queryWithContext]\n );\n\n return {\n getProductDetails,\n data,\n loading,\n error,\n };\n}\n\n/**\n * Hook to fetch grouped products for homepage.\n */\nexport function useHomeGroupedProducts(options?: { skip?: boolean }) {\n const client = useStoreClient();\n const { defaultCompatibleWith } = useStore();\n const [data, setData] = useState<GroupedProducts | null>(null);\n const [loading, setLoading] = useState(!options?.skip);\n const [error, setError] = useState<Error | null>(null);\n\n const skip = options?.skip;\n\n const fetchData = useCallback(async () => {\n if (skip) {\n setLoading(false);\n return;\n }\n setLoading(true);\n setError(null);\n try {\n const result = await client.query<{ homeGroupedProducts: GroupedProducts }>({\n query: HomeGroupedProductsDocument,\n variables: { compatibleWith: defaultCompatibleWith ?? null },\n fetchPolicy: 'cache-first',\n });\n setData(result.data?.homeGroupedProducts ?? null);\n } catch (err) {\n setError(err as Error);\n } finally {\n setLoading(false);\n }\n }, [client, defaultCompatibleWith, skip]);\n\n useEffect(() => {\n fetchData();\n }, [fetchData]);\n\n return {\n data,\n featured: data?.featured ?? [],\n mostDownloaded: data?.mostDownloaded ?? [],\n recentlyAdded: data?.recentlyAdded ?? [],\n freeItems: data?.freeItems ?? [],\n loading,\n error,\n refetch: fetchData,\n };\n}\n\n/**\n * Hook to fetch featured products\n */\nexport function useFeaturedProducts(limit?: number) {\n const client = useStoreClient();\n const [products, setProducts] = useState<StoreProduct[]>([]);\n const [loading, setLoading] = useState(true);\n const [error, setError] = useState<Error | null>(null);\n\n const fetchData = useCallback(async () => {\n setLoading(true);\n setError(null);\n try {\n const result = await client.query<{ featuredProducts: StoreProduct[] }>({\n query: FeaturedProductsDocument,\n variables: { limit },\n fetchPolicy: 'cache-first',\n });\n setProducts(result.data?.featuredProducts ?? []);\n } catch (err) {\n setError(err as Error);\n } finally {\n setLoading(false);\n }\n }, [client, limit]);\n\n useEffect(() => {\n fetchData();\n }, [fetchData]);\n\n return {\n products,\n loading,\n error,\n refetch: fetchData,\n };\n}\n\n/**\n * Hook to fetch search suggestions for autocomplete\n */\nexport function useSearchSuggestions(\n query: string,\n options?: { limit?: number; types?: string[] }\n) {\n const client = useStoreClient();\n const [suggestions, setSuggestions] = useState<SearchSuggestion[]>([]);\n const [loading, setLoading] = useState(false);\n const [error, setError] = useState<Error | null>(null);\n\n const shouldSkip = query.length < 2;\n\n const fetchData = useCallback(async () => {\n if (shouldSkip) {\n setSuggestions([]);\n return;\n }\n\n setLoading(true);\n setError(null);\n try {\n const result = await client.query<{ searchSuggestions: SearchSuggestion[] }>({\n query: SearchSuggestionsDocument,\n variables: { query, limit: options?.limit, types: options?.types },\n fetchPolicy: 'network-only',\n });\n setSuggestions(result.data?.searchSuggestions ?? []);\n } catch (err) {\n setError(err as Error);\n } finally {\n setLoading(false);\n }\n }, [client, query, options?.limit, options?.types, shouldSkip]);\n\n useEffect(() => {\n fetchData();\n }, [fetchData]);\n\n return {\n suggestions,\n loading,\n error,\n refetch: fetchData,\n };\n}\n\n/**\n * Lazy hook to fetch search suggestions on demand\n */\nexport function useLazySearchSuggestions() {\n const client = useStoreClient();\n const [suggestions, setSuggestions] = useState<SearchSuggestion[]>([]);\n const [loading, setLoading] = useState(false);\n const [error, setError] = useState<Error | null>(null);\n\n const getSuggestions = useCallback(\n async (query: string, options?: { limit?: number; types?: string[] }) => {\n if (query.length < 2) {\n setSuggestions([]);\n return [];\n }\n\n setLoading(true);\n setError(null);\n try {\n const result = await client.query<{ searchSuggestions: SearchSuggestion[] }>({\n query: SearchSuggestionsDocument,\n variables: { query, limit: options?.limit, types: options?.types },\n fetchPolicy: 'network-only',\n });\n const data = result.data?.searchSuggestions ?? [];\n setSuggestions(data);\n return data;\n } catch (err) {\n setError(err as Error);\n return [];\n } finally {\n setLoading(false);\n }\n },\n [client]\n );\n\n return {\n getSuggestions,\n suggestions,\n loading,\n error,\n };\n}\n\n/**\n * Hook to fetch trending search terms\n */\nexport function useTrendingSearches(options?: { limit?: number; type?: ProductType }) {\n const client = useStoreClient();\n const [terms, setTerms] = useState<string[]>([]);\n const [loading, setLoading] = useState(true);\n const [error, setError] = useState<Error | null>(null);\n\n const fetchData = useCallback(async () => {\n setLoading(true);\n setError(null);\n try {\n const result = await client.query<{ trendingSearches: string[] }>({\n query: TrendingSearchesDocument,\n variables: { limit: options?.limit, type: options?.type },\n fetchPolicy: 'cache-first',\n });\n setTerms(result.data?.trendingSearches ?? []);\n } catch (err) {\n setError(err as Error);\n } finally {\n setLoading(false);\n }\n }, [client, options?.limit, options?.type]);\n\n useEffect(() => {\n fetchData();\n }, [fetchData]);\n\n return {\n terms,\n loading,\n error,\n refetch: fetchData,\n };\n}\n\n/**\n * Hook to fetch filter options for dropdowns\n */\nexport function useFilterOptions(options?: { type?: ProductType; withProducts?: boolean }) {\n const client = useStoreClient();\n const [filterOptions, setFilterOptions] = useState<unknown>(null);\n const [loading, setLoading] = useState(true);\n const [error, setError] = useState<Error | null>(null);\n\n const fetchData = useCallback(async () => {\n setLoading(true);\n setError(null);\n try {\n const result = await client.query<FilterOptionsData>({\n query: FilterOptionsDocument,\n variables: { type: options?.type, withProducts: options?.withProducts },\n fetchPolicy: 'cache-first',\n });\n setFilterOptions(result.data?.filterOptions ?? null);\n } catch (err) {\n setError(err as Error);\n } finally {\n setLoading(false);\n }\n }, [client, options?.type, options?.withProducts]);\n\n useEffect(() => {\n fetchData();\n }, [fetchData]);\n\n return {\n filterOptions,\n loading,\n error,\n refetch: fetchData,\n };\n}\n\n// ============================================================================\n// Category Hooks\n// ============================================================================\n\n/**\n * Hook to fetch all categories\n */\nexport function useCategories() {\n const client = useStoreClient();\n const [categories, setCategories] = useState<ProductCategory[]>([]);\n const [loading, setLoading] = useState(true);\n const [error, setError] = useState<Error | null>(null);\n\n const fetchData = useCallback(async () => {\n setLoading(true);\n setError(null);\n try {\n const result = await client.query<{ categories: ProductCategory[] }>({\n query: CategoriesDocument,\n fetchPolicy: 'cache-first',\n });\n setCategories(result.data?.categories ?? []);\n } catch (err) {\n setError(err as Error);\n } finally {\n setLoading(false);\n }\n }, [client]);\n\n useEffect(() => {\n fetchData();\n }, [fetchData]);\n\n return {\n categories,\n loading,\n error,\n refetch: fetchData,\n };\n}\n\n// ============================================================================\n// Review Hooks\n// ============================================================================\n\n/**\n * Hook to fetch reviews for a product\n */\nexport function useProductReviews(productId: string, options?: { status?: string }) {\n const client = useStoreClient();\n const [reviews, setReviews] = useState<ProductReview[]>([]);\n const [loading, setLoading] = useState(true);\n const [error, setError] = useState<Error | null>(null);\n\n const fetchData = useCallback(async () => {\n if (!productId) {\n setLoading(false);\n return;\n }\n\n setLoading(true);\n setError(null);\n try {\n const result = await client.query<{ productReviews: ProductReview[] }>({\n query: ProductReviewsDocument,\n variables: { productId, status: options?.status },\n fetchPolicy: 'cache-first',\n });\n setReviews(result.data?.productReviews ?? []);\n } catch (err) {\n setError(err as Error);\n } finally {\n setLoading(false);\n }\n }, [client, productId, options?.status]);\n\n useEffect(() => {\n fetchData();\n }, [fetchData]);\n\n return {\n reviews,\n loading,\n error,\n refetch: fetchData,\n };\n}\n\n/**\n * Hook to fetch current user's review for a product\n */\nexport function useUserReviewForProduct(productId: string) {\n const client = useStoreClient();\n const [review, setReview] = useState<ProductReview | null>(null);\n const [loading, setLoading] = useState(true);\n const [error, setError] = useState<Error | null>(null);\n\n const fetchData = useCallback(async () => {\n if (!productId) {\n setLoading(false);\n return;\n }\n\n setLoading(true);\n setError(null);\n try {\n const result = await client.query<{ userReviewForProduct: ProductReview | null }>({\n query: UserReviewForProductDocument,\n variables: { productId },\n fetchPolicy: 'network-only',\n });\n setReview(result.data?.userReviewForProduct ?? null);\n } catch (err) {\n setError(err as Error);\n } finally {\n setLoading(false);\n }\n }, [client, productId]);\n\n useEffect(() => {\n fetchData();\n }, [fetchData]);\n\n return {\n review,\n loading,\n error,\n refetch: fetchData,\n };\n}\n\n/**\n * Hook to create a review\n */\nexport function useCreateReview() {\n const { mutate: mutateWithContext } = useStoreGraphQLWithContext();\n const [review, setReview] = useState<ProductReview | null>(null);\n const [loading, setLoading] = useState(false);\n const [error, setError] = useState<Error | null>(null);\n\n const createReview = useCallback(\n async (input: CreateReviewInput) => {\n setLoading(true);\n setError(null);\n try {\n const result = await mutateWithContext<{ createReview: ProductReview }>({\n mutation: CreateReviewDocument,\n variables: { input },\n });\n const data = result.data?.createReview ?? null;\n setReview(data);\n return { data, errorMessage: null };\n } catch (err) {\n setError(err as Error);\n const apolloErr = err as { graphQLErrors?: { message: string }[]; message?: string };\n const errorMessage =\n apolloErr.graphQLErrors?.[0]?.message ??\n apolloErr.message ??\n 'We could not save your review. Please try again.';\n return { data: null, errorMessage };\n } finally {\n setLoading(false);\n }\n },\n [mutateWithContext]\n );\n\n return {\n createReview,\n review,\n loading,\n error,\n };\n}\n\n/**\n * Hook to update a review\n */\nexport function useUpdateReview() {\n const { mutate: mutateWithContext } = useStoreGraphQLWithContext();\n const [review, setReview] = useState<ProductReview | null>(null);\n const [loading, setLoading] = useState(false);\n const [error, setError] = useState<Error | null>(null);\n\n const updateReview = useCallback(\n async (id: string, input: UpdateReviewInput) => {\n setLoading(true);\n setError(null);\n try {\n const result = await mutateWithContext<{ updateReview: ProductReview }>({\n mutation: UpdateReviewDocument,\n variables: { id, input },\n });\n const data = result.data?.updateReview ?? null;\n setReview(data);\n return data;\n } catch (err) {\n setError(err as Error);\n return null;\n } finally {\n setLoading(false);\n }\n },\n [mutateWithContext]\n );\n\n return {\n updateReview,\n review,\n loading,\n error,\n };\n}\n\n/**\n * Hook to delete a review\n */\nexport function useDeleteReview() {\n const { mutate: mutateWithContext } = useStoreGraphQLWithContext();\n const [loading, setLoading] = useState(false);\n const [error, setError] = useState<Error | null>(null);\n\n const deleteReview = useCallback(\n async (id: string) => {\n setLoading(true);\n setError(null);\n try {\n const result = await mutateWithContext<{ deleteReview: boolean }>({\n mutation: DeleteReviewDocument,\n variables: { id },\n });\n return result.data?.deleteReview ?? false;\n } catch (err) {\n setError(err as Error);\n return false;\n } finally {\n setLoading(false);\n }\n },\n [mutateWithContext]\n );\n\n return {\n deleteReview,\n loading,\n error,\n };\n}\n\n/**\n * Hook to mark review as helpful\n */\nexport function useMarkReviewHelpful() {\n const { mutate: mutateWithContext } = useStoreGraphQLWithContext();\n const [loading, setLoading] = useState(false);\n const [error, setError] = useState<Error | null>(null);\n\n const markHelpful = useCallback(\n async (id: string) => {\n setLoading(true);\n setError(null);\n try {\n const result = await mutateWithContext<{\n markReviewHelpful: { id: string; helpful: number };\n }>({\n mutation: MarkReviewHelpfulDocument,\n variables: { id },\n });\n return result.data?.markReviewHelpful ?? null;\n } catch (err) {\n setError(err as Error);\n return null;\n } finally {\n setLoading(false);\n }\n },\n [mutateWithContext]\n );\n\n return {\n markHelpful,\n loading,\n error,\n };\n}\n\n// ============================================================================\n// Entitlement Hooks\n// ============================================================================\n\n/**\n * Hook to fetch current user's entitlements\n */\nexport function useMyEntitlements() {\n const { query: queryWithContext, hasOrganizationContext } = useStoreGraphQLWithContext();\n const globalClient = useApolloClient();\n const PAGE_SIZE = 20;\n const [allEntitlements, setAllEntitlements] = useState<unknown[]>([]);\n const [hasMore, setHasMore] = useState(false);\n const [currentOffset, setCurrentOffset] = useState(0);\n const [loading, setLoading] = useState(true);\n const [error, setError] = useState<Error | null>(null);\n\n const fetchData = useCallback(\n async (fetchOffset = 0, append = false) => {\n setLoading(true);\n setError(null);\n try {\n const variables = { limit: PAGE_SIZE, offset: fetchOffset };\n const result = hasOrganizationContext\n ? ((await queryWithContext({\n query: MyEntitlementsDocument,\n variables,\n fetchPolicy: 'network-only',\n })) as { data?: { myEntitlements: unknown[] } })\n : await globalClient.query<{ myEntitlements: unknown[] }>({\n query: MyEntitlementsDocument,\n variables,\n fetchPolicy: 'network-only',\n });\n const fetched = result.data?.myEntitlements ?? [];\n if (append) {\n setAllEntitlements((prev) => [...prev, ...fetched]);\n } else {\n setAllEntitlements(fetched);\n }\n setHasMore(fetched.length === PAGE_SIZE);\n setCurrentOffset(fetchOffset);\n } catch (err) {\n setError(err as Error);\n } finally {\n setLoading(false);\n }\n },\n [globalClient, hasOrganizationContext, queryWithContext]\n );\n\n useEffect(() => {\n fetchData(0);\n }, [fetchData]);\n\n const loadMore = useCallback(() => {\n if (!hasMore || loading) return;\n fetchData(currentOffset + PAGE_SIZE, true);\n }, [fetchData, hasMore, loading, currentOffset]);\n\n return {\n entitlements: allEntitlements,\n hasMore,\n loading,\n error,\n refetch: () => fetchData(0),\n loadMore,\n };\n}\n\n/**\n * Hook to check entitlement for a product\n */\nexport function useCheckEntitlement(productId: string) {\n const client = useStoreClient();\n const [entitlement, setEntitlement] = useState<unknown>(null);\n const [loading, setLoading] = useState(true);\n const [error, setError] = useState<Error | null>(null);\n\n const fetchData = useCallback(async () => {\n if (!productId) {\n setLoading(false);\n return;\n }\n\n setLoading(true);\n setError(null);\n try {\n const result = await client.query<CheckEntitlementData>({\n query: CheckEntitlementDocument,\n variables: { productId },\n fetchPolicy: 'network-only',\n });\n setEntitlement(result.data?.checkEntitlement ?? null);\n } catch (err) {\n setError(err as Error);\n } finally {\n setLoading(false);\n }\n }, [client, productId]);\n\n useEffect(() => {\n fetchData();\n }, [fetchData]);\n\n return {\n entitlement,\n loading,\n error,\n refetch: fetchData,\n };\n}\n\n// ============================================================================\n// Order Hooks\n// ============================================================================\n\n/**\n * Hook to fetch workspace store orders\n */\nexport function useWorkspaceStoreOrders(\n billingAccountId: string,\n page: number,\n limit: number,\n options?: { status?: string; search?: string }\n) {\n const client = useStoreClient();\n const [orders, setOrders] = useState<unknown[]>([]);\n const [total, setTotal] = useState(0);\n const [loading, setLoading] = useState(true);\n const [error, setError] = useState<Error | null>(null);\n\n const fetchData = useCallback(async () => {\n if (!billingAccountId) {\n setLoading(false);\n return;\n }\n\n setLoading(true);\n setError(null);\n try {\n const result = await client.query<{\n workspaceStoreOrders: { total: number; orders: unknown[] };\n }>({\n query: WorkspaceStoreOrdersDocument,\n variables: {\n billingAccountId,\n page,\n limit,\n status: options?.status,\n search: options?.search,\n },\n fetchPolicy: 'network-only',\n });\n setOrders(result.data?.workspaceStoreOrders?.orders ?? []);\n setTotal(result.data?.workspaceStoreOrders?.total ?? 0);\n } catch (err) {\n setError(err as Error);\n } finally {\n setLoading(false);\n }\n }, [client, billingAccountId, page, limit, options?.status, options?.search]);\n\n useEffect(() => {\n fetchData();\n }, [fetchData]);\n\n return {\n orders,\n total,\n loading,\n error,\n refetch: fetchData,\n };\n}\n\n// ============================================================================\n// Publisher Hooks\n// ============================================================================\n\n/**\n * Hook to fetch publisher's products\n */\nexport function useMyPublishedProducts() {\n const client = useStoreClient();\n const [allProducts, setAllProducts] = useState<StoreProduct[]>([]);\n const [hasMore, setHasMore] = useState(false);\n const [currentOffset, setCurrentOffset] = useState(0);\n const [loading, setLoading] = useState(true);\n const [error, setError] = useState<Error | null>(null);\n\n const PAGE_SIZE = 20;\n\n const fetchData = useCallback(\n async (fetchOffset = 0, append = false) => {\n setLoading(true);\n setError(null);\n try {\n const result = await client.query<{ publishedProducts: StoreProduct[] }>({\n query: MyPublishedProductsDocument,\n variables: { limit: PAGE_SIZE, offset: fetchOffset },\n fetchPolicy: 'network-only',\n });\n const fetched = result.data?.publishedProducts ?? [];\n if (append) {\n setAllProducts((prev) => [...prev, ...fetched]);\n } else {\n setAllProducts(fetched);\n }\n setHasMore(fetched.length === PAGE_SIZE);\n setCurrentOffset(fetchOffset + fetched.length);\n } catch (err) {\n setError(err as Error);\n } finally {\n setLoading(false);\n }\n },\n [client]\n );\n\n const loadMore = useCallback(() => {\n if (!hasMore || loading) return;\n void fetchData(currentOffset, true);\n }, [fetchData, hasMore, loading, currentOffset]);\n\n useEffect(() => {\n void fetchData(0, false);\n }, [fetchData]);\n\n return {\n products: allProducts,\n hasMore,\n loading,\n error,\n refetch: () => fetchData(0, false),\n loadMore,\n };\n}\n\n/**\n * Hook to fetch developer earnings\n */\nexport function useDeveloperEarnings(options?: {\n period?: string;\n startDate?: string;\n endDate?: string;\n}) {\n const { query: queryWithContext, hasOrganizationContext } = useStoreGraphQLWithContext();\n const globalClient = useApolloClient();\n const [earnings, setEarnings] = useState<unknown>(null);\n const [loading, setLoading] = useState(true);\n const [error, setError] = useState<Error | null>(null);\n\n const fetchData = useCallback(async () => {\n setLoading(true);\n setError(null);\n try {\n const result = hasOrganizationContext\n ? ((await queryWithContext({\n query: DeveloperEarningsDocument,\n variables: { input: options },\n fetchPolicy: 'network-only',\n })) as { data?: DeveloperEarningsData })\n : await globalClient.query<DeveloperEarningsData>({\n query: DeveloperEarningsDocument,\n variables: { input: options },\n fetchPolicy: 'network-only',\n });\n setEarnings(result.data?.developerEarnings ?? null);\n } catch (err) {\n setError(err as Error);\n } finally {\n setLoading(false);\n }\n }, [globalClient, hasOrganizationContext, options, queryWithContext]);\n\n useEffect(() => {\n fetchData();\n }, [fetchData]);\n\n return {\n earnings,\n loading,\n error,\n refetch: fetchData,\n };\n}\n\n// ============================================================================\n// Re-export types for convenience\n// ============================================================================\n\nexport type {\n BrowseStoreInput,\n StoreProductDetailsInput,\n ProductType,\n CreateReviewInput,\n UpdateReviewInput,\n StoreProduct,\n ProductReview,\n ProductCategory,\n SearchSuggestion,\n GroupedProducts,\n BrowseStoreResult,\n};\n"],"mappings":";;;;;;AA6CA,SAAS,IAAiB;AACxB,QAAO,GAAiB;;AA4J1B,SAAgB,EAAe,IAA0B,EAAE,EAAE;CAC3D,IAAM,IAAS,GAAgB,EACzB,CAAC,GAAU,KAAe,EAAyB,EAAE,CAAC,EACtD,CAAC,GAAY,KAAiB,EAAS,EAAE,EACzC,CAAC,GAAS,KAAc,EAAS,GAAM,EACvC,CAAC,GAAQ,KAAa,EAAsC,KAAA,EAAU,EACtE,CAAC,GAAS,KAAc,EAAS,GAAK,EACtC,CAAC,GAAO,KAAY,EAAuB,KAAK,EAGhD,IAAW,KAAK,UAAU,EAAM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AAW,GAAM;;IAElB;EAAC;EAAQ;EAAkB;EAAM;EAAO,GAAS;EAAQ,GAAS;EAAO,CAAC;AAM7E,QAJA,QAAgB;AACd,KAAW;IACV,CAAC,EAAU,CAAC,EAER;EACL;EACA;EACA;EACA;EACA,SAAS;EACV"}
|
|
@@ -3,32 +3,35 @@ import { useCallback as t } from "react";
|
|
|
3
3
|
import { useApolloClient as n } from "@apollo/client/react";
|
|
4
4
|
//#region src/hooks/useStoreGraphQLWithContext.ts
|
|
5
5
|
function r() {
|
|
6
|
-
let r = n(), { organizationId: i,
|
|
6
|
+
let r = n(), { organizationId: i, workspaceId: a, user: o, authToken: s } = e(), c = t(() => {
|
|
7
7
|
let e = {};
|
|
8
|
-
|
|
8
|
+
i && (e["x-org-id"] = i), o?.id && (e["x-actor-id"] = o.id, e["x-actor-type"] = "user");
|
|
9
|
+
let t = o?.workspaceId ?? a;
|
|
10
|
+
return t && (e["x-workspace-id"] = t), s && (e.Authorization = `Bearer ${s}`), e;
|
|
9
11
|
}, [
|
|
10
12
|
i,
|
|
11
13
|
a,
|
|
12
|
-
o
|
|
14
|
+
o,
|
|
15
|
+
s
|
|
13
16
|
]);
|
|
14
17
|
return {
|
|
15
18
|
query: t(async (e) => {
|
|
16
|
-
let t =
|
|
19
|
+
let t = c();
|
|
17
20
|
return r.query({
|
|
18
21
|
query: e.query,
|
|
19
22
|
variables: e.variables,
|
|
20
23
|
fetchPolicy: e.fetchPolicy,
|
|
21
24
|
context: { headers: t }
|
|
22
25
|
});
|
|
23
|
-
}, [r,
|
|
26
|
+
}, [r, c]),
|
|
24
27
|
mutate: t(async (e) => {
|
|
25
|
-
let t =
|
|
28
|
+
let t = c();
|
|
26
29
|
return r.mutate({
|
|
27
30
|
mutation: e.mutation,
|
|
28
31
|
variables: e.variables,
|
|
29
32
|
context: { headers: t }
|
|
30
33
|
});
|
|
31
|
-
}, [r,
|
|
34
|
+
}, [r, c]),
|
|
32
35
|
organizationId: i,
|
|
33
36
|
hasOrganizationContext: !!i
|
|
34
37
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useStoreGraphQLWithContext.js","names":[],"sources":["../../src/hooks/useStoreGraphQLWithContext.ts"],"sourcesContent":["import { useCallback } from 'react';\nimport { useApolloClient } from '@apollo/client/react';\nimport type { DocumentNode, OperationVariables, TypedDocumentNode } from '@apollo/client/core';\nimport { useStore } from '../providers/StoreProvider';\n\ntype GraphQLDocument = DocumentNode | TypedDocumentNode<unknown, OperationVariables>;\n\ninterface QueryWithContextOptions<TVariables extends OperationVariables = OperationVariables> {\n query: GraphQLDocument;\n variables?: TVariables;\n fetchPolicy?: 'cache-first' | 'network-only' | 'cache-only' | 'no-cache';\n context?: { headers?: Record<string, string> };\n}\n\ninterface MutationWithContextOptions<TVariables extends OperationVariables = OperationVariables> {\n mutation: GraphQLDocument;\n variables?: TVariables;\n context?: { headers?: Record<string, string> };\n}\n\n/**\n * Enhanced GraphQL client hook that automatically includes organization context\n * in all requests to ensure proper organization-scoped licensing.\n */\nexport function useStoreGraphQLWithContext() {\n const client = useApolloClient();\n const { organizationId, user, authToken } = useStore();\n\n /**\n * Get context headers for organization-scoped requests\n */\n const getContextHeaders = useCallback(() => {\n const contextHeaders: Record<string, string> = {};\n\n // Add organization ID header for organization-scoped licensing\n if (organizationId) {\n contextHeaders['x-org-id'] = organizationId;\n }\n\n // Add user context if available\n if (user?.id) {\n contextHeaders['x-actor-id'] = user.id;\n contextHeaders['x-actor-type'] = 'user';\n }\n\n // Add workspace context
|
|
1
|
+
{"version":3,"file":"useStoreGraphQLWithContext.js","names":[],"sources":["../../src/hooks/useStoreGraphQLWithContext.ts"],"sourcesContent":["import { useCallback } from 'react';\nimport { useApolloClient } from '@apollo/client/react';\nimport type { DocumentNode, OperationVariables, TypedDocumentNode } from '@apollo/client/core';\nimport { useStore } from '../providers/StoreProvider';\n\ntype GraphQLDocument = DocumentNode | TypedDocumentNode<unknown, OperationVariables>;\n\ninterface QueryWithContextOptions<TVariables extends OperationVariables = OperationVariables> {\n query: GraphQLDocument;\n variables?: TVariables;\n fetchPolicy?: 'cache-first' | 'network-only' | 'cache-only' | 'no-cache';\n context?: { headers?: Record<string, string> };\n}\n\ninterface MutationWithContextOptions<TVariables extends OperationVariables = OperationVariables> {\n mutation: GraphQLDocument;\n variables?: TVariables;\n context?: { headers?: Record<string, string> };\n}\n\n/**\n * Enhanced GraphQL client hook that automatically includes organization context\n * in all requests to ensure proper organization-scoped licensing.\n */\nexport function useStoreGraphQLWithContext() {\n const client = useApolloClient();\n const { organizationId, workspaceId: contextWorkspaceId, user, authToken } = useStore();\n\n /**\n * Get context headers for organization-scoped requests\n */\n const getContextHeaders = useCallback(() => {\n const contextHeaders: Record<string, string> = {};\n\n // Add organization ID header for organization-scoped licensing\n if (organizationId) {\n contextHeaders['x-org-id'] = organizationId;\n }\n\n // Add user context if available\n if (user?.id) {\n contextHeaders['x-actor-id'] = user.id;\n contextHeaders['x-actor-type'] = 'user';\n }\n\n // Add workspace context — prefer user.workspaceId but fall back to the\n // top-level workspaceId prop passed by the app shell (e.g. for review mutations\n // that go through the global gateway and need workspace context for the\n // conversations service).\n const resolvedWorkspaceId = user?.workspaceId ?? contextWorkspaceId;\n if (resolvedWorkspaceId) {\n contextHeaders['x-workspace-id'] = resolvedWorkspaceId;\n }\n\n // Add auth token if available\n if (authToken) {\n contextHeaders['Authorization'] = `Bearer ${authToken}`;\n }\n\n return contextHeaders;\n }, [organizationId, contextWorkspaceId, user, authToken]);\n\n /**\n * Execute a GraphQL query with organization context headers\n */\n const queryWithContext = useCallback(\n async <TVariables extends OperationVariables = OperationVariables>(\n options: QueryWithContextOptions<TVariables>\n ) => {\n const contextHeaders = getContextHeaders();\n\n return client.query({\n query: options.query,\n variables: options.variables,\n fetchPolicy: options.fetchPolicy,\n context: {\n headers: contextHeaders,\n },\n });\n },\n [client, getContextHeaders]\n );\n\n /**\n * Execute a GraphQL mutation with organization context headers\n */\n const mutateWithContext = useCallback(\n async <TData = unknown, TVariables extends OperationVariables = OperationVariables>(\n options: MutationWithContextOptions<TVariables>\n ) => {\n const contextHeaders = getContextHeaders();\n\n return client.mutate<TData>({\n mutation: options.mutation,\n variables: options.variables,\n context: {\n headers: contextHeaders,\n },\n });\n },\n [client, getContextHeaders]\n );\n\n return {\n query: queryWithContext,\n mutate: mutateWithContext,\n organizationId,\n hasOrganizationContext: Boolean(organizationId),\n };\n}\n"],"mappings":";;;;AAwBA,SAAgB,IAA6B;CAC3C,IAAM,IAAS,GAAiB,EAC1B,EAAE,mBAAgB,aAAa,GAAoB,SAAM,iBAAc,GAAU,EAKjF,IAAoB,QAAkB;EAC1C,IAAM,IAAyC,EAAE;AAQjD,EALI,MACF,EAAe,cAAc,IAI3B,GAAM,OACR,EAAe,gBAAgB,EAAK,IACpC,EAAe,kBAAkB;EAOnC,IAAM,IAAsB,GAAM,eAAe;AAUjD,SATI,MACF,EAAe,oBAAoB,IAIjC,MACF,EAAe,gBAAmB,UAAU,MAGvC;IACN;EAAC;EAAgB;EAAoB;EAAM;EAAU,CAAC;AA2CzD,QAAO;EACL,OAvCuB,EACvB,OACE,MACG;GACH,IAAM,IAAiB,GAAmB;AAE1C,UAAO,EAAO,MAAM;IAClB,OAAO,EAAQ;IACf,WAAW,EAAQ;IACnB,aAAa,EAAQ;IACrB,SAAS,EACP,SAAS,GACV;IACF,CAAC;KAEJ,CAAC,GAAQ,EAAkB,CAC5B;EAwBC,QAnBwB,EACxB,OACE,MACG;GACH,IAAM,IAAiB,GAAmB;AAE1C,UAAO,EAAO,OAAc;IAC1B,UAAU,EAAQ;IAClB,WAAW,EAAQ;IACnB,SAAS,EACP,SAAS,GACV;IACF,CAAC;KAEJ,CAAC,GAAQ,EAAkB,CAC5B;EAKC;EACA,wBAAwB,EAAQ;EACjC"}
|