@burdenoff/microfe-healthybowl 2026.811.9 → 2026.811.10

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.
@@ -51,8 +51,12 @@ var s = "00000000-0000-0000-0000-000000000001", c = [], l = "\n commodity\n va
51
51
  mutation DeleteHealthyBowlPriceAlertRule($id: ID!, $context: ContextInput!) {
52
52
  deleteHealthyBowlPriceAlertRule(context: $context, id: $id)
53
53
  }
54
+ `, w = i`
55
+ mutation AcknowledgeHealthyBowlPriceAlert($id: ID!, $context: ContextInput!) {
56
+ acknowledgeHealthyBowlPriceAlert(context: $context, id: $id) { ${p} }
57
+ }
54
58
  `;
55
- function w(i = {}) {
59
+ function T(i = {}) {
56
60
  let { workspaceId: l } = e(), u = l || s, d = r(() => ({ workspaceId: u }), [u]), f = i.filter, p = o(m, {
57
61
  variables: {
58
62
  context: d,
@@ -62,98 +66,111 @@ function w(i = {}) {
62
66
  }), h = o(g, {
63
67
  variables: { context: d },
64
68
  fetchPolicy: "cache-and-network"
65
- }), w = o(_, {
69
+ }), T = o(_, {
66
70
  variables: { context: d },
67
71
  fetchPolicy: "cache-and-network"
68
- }), T = o(v, {
72
+ }), E = o(v, {
69
73
  variables: { context: d },
70
74
  fetchPolicy: "cache-and-network"
71
- }), E = p.refetch, D = h.refetch, O = w.refetch, k = T.refetch, A = n(async (...e) => {
75
+ }), D = p.refetch, O = h.refetch, k = T.refetch, A = E.refetch, j = n(async (...e) => {
72
76
  await Promise.all(e.map((e) => e().catch(() => void 0)));
73
- }, []), [j] = a(y), [M] = a(b), [N] = a(x), [P] = a(S), [F] = a(C), I = n((e) => ({
77
+ }, []), [M] = a(y), [N] = a(b), [P] = a(x), [F] = a(S), [I] = a(C), [L] = a(w), R = n((e) => ({
74
78
  ...e,
75
79
  context: d
76
- }), [d]), L = r(() => p.data?.getHealthyBowlMandiPrices ?? c, [p.data]);
80
+ }), [d]), z = r(() => p.data?.getHealthyBowlMandiPrices ?? c, [p.data]);
77
81
  return {
78
- prices: L,
79
- commodities: r(() => t(L), [L]),
82
+ prices: z,
83
+ commodities: r(() => t(z), [z]),
80
84
  watches: h.data?.getHealthyBowlPriceWatches ?? [],
81
- alertRules: w.data?.getHealthyBowlPriceAlertRules ?? [],
82
- alerts: T.data?.getHealthyBowlPriceAlerts ?? [],
85
+ alertRules: T.data?.getHealthyBowlPriceAlertRules ?? [],
86
+ alerts: E.data?.getHealthyBowlPriceAlerts ?? [],
83
87
  loading: p.loading,
84
88
  error: p.error ?? null,
85
89
  watchesLoading: h.loading,
86
- rulesLoading: w.loading,
87
- alertsLoading: T.loading,
88
- refetchAll: n(() => A(E, D, O, k), [
89
- A,
90
- E,
90
+ rulesLoading: T.loading,
91
+ alertsLoading: E.loading,
92
+ refetchAll: n(() => j(D, O, k, A), [
93
+ j,
91
94
  D,
92
95
  O,
93
- k
96
+ k,
97
+ A
94
98
  ]),
95
99
  createWatch: n(async (e) => {
96
- let t = await j({ variables: { input: I(e) } });
100
+ let t = await M({ variables: { input: R(e) } });
97
101
  if (t.error) throw t.error;
98
- return await A(D), t.data?.createHealthyBowlPriceWatch ?? null;
102
+ return await j(O), t.data?.createHealthyBowlPriceWatch ?? null;
99
103
  }, [
104
+ M,
105
+ R,
100
106
  j,
101
- I,
102
- A,
103
- D
107
+ O
104
108
  ]),
105
109
  deleteWatch: n(async (e) => {
106
- let t = await M({ variables: {
110
+ let t = await N({ variables: {
107
111
  id: e,
108
112
  context: d
109
113
  } });
110
114
  if (t.error) throw t.error;
111
- await A(D);
115
+ await j(O);
112
116
  }, [
113
- M,
117
+ N,
114
118
  d,
115
- A,
116
- D
119
+ j,
120
+ O
117
121
  ]),
118
122
  createRule: n(async (e) => {
119
- let t = await N({ variables: { input: I(e) } });
123
+ let t = await P({ variables: { input: R(e) } });
120
124
  if (t.error) throw t.error;
121
- return await A(O, k), t.data?.createHealthyBowlPriceAlertRule ?? null;
125
+ return await j(k, A), t.data?.createHealthyBowlPriceAlertRule ?? null;
122
126
  }, [
123
- N,
124
- I,
125
- A,
126
- O,
127
- k
127
+ P,
128
+ R,
129
+ j,
130
+ k,
131
+ A
128
132
  ]),
129
133
  updateRule: n(async (e) => {
130
- let t = await P({ variables: { input: I(e) } });
134
+ let t = await F({ variables: { input: R(e) } });
131
135
  if (t.error) throw t.error;
132
- return await A(O, k), t.data?.updateHealthyBowlPriceAlertRule ?? null;
136
+ return await j(k, A), t.data?.updateHealthyBowlPriceAlertRule ?? null;
137
+ }, [
138
+ F,
139
+ R,
140
+ j,
141
+ k,
142
+ A
143
+ ]),
144
+ deleteRule: n(async (e) => {
145
+ let t = await I({ variables: {
146
+ id: e,
147
+ context: d
148
+ } });
149
+ if (t.error) throw t.error;
150
+ await j(k);
133
151
  }, [
134
- P,
135
152
  I,
136
- A,
137
- O,
153
+ d,
154
+ j,
138
155
  k
139
156
  ]),
140
- deleteRule: n(async (e) => {
141
- let t = await F({ variables: {
157
+ acknowledgeAlert: n(async (e) => {
158
+ let t = await L({ variables: {
142
159
  id: e,
143
160
  context: d
144
161
  } });
145
162
  if (t.error) throw t.error;
146
- await A(O);
163
+ return await j(A), t.data?.acknowledgeHealthyBowlPriceAlert ?? null;
147
164
  }, [
148
- F,
165
+ L,
149
166
  d,
150
- A,
151
- O
167
+ j,
168
+ A
152
169
  ]),
153
170
  context: d
154
171
  };
155
172
  }
156
- function T(t = {}) {
173
+ function E(t = {}) {
157
174
  let { workspaceId: n } = e(), i = n || s, a = r(() => ({ workspaceId: i }), [i]), c = t.days ?? 30, l = o(h, {
158
175
  variables: {
159
176
  context: a,
@@ -171,6 +188,6 @@ function T(t = {}) {
171
188
  };
172
189
  }
173
190
  //#endregion
174
- export { T as useHealthyBowlMandiPriceTrend, w as useHealthyBowlMandiPrices };
191
+ export { E as useHealthyBowlMandiPriceTrend, T as useHealthyBowlMandiPrices };
175
192
 
176
193
  //# sourceMappingURL=useHealthyBowlMandiPrices.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useHealthyBowlMandiPrices.js","names":[],"sources":["../../../src/healthybowl/hooks/useHealthyBowlMandiPrices.ts"],"sourcesContent":["/**\n * Mandi / Market-Price Intelligence — data hook (roadmap #28 · BOFF-4715).\n *\n * Documents are declared inline with `gql` (not `src/operations/wspace/*.graphql`)\n * because codegen validates operations against the committed `graphql/wspace.graphql`\n * snapshot, which doesn't yet carry the mandi subgraph (schema:pull needs a live\n * gateway) — the same escape hatch `useHealthyBowlSensors` / `useDiseaseWarning`\n * use. Types mirror the deployed `wspace-healthybowl-svc` mandi schema.\n *\n * Reads use `cache-and-network`; every write refetches the lists it invalidates.\n * The commodity roll-up is delegated to the pure `groupPricesByCommodity` helper\n * so it stays unit-testable.\n */\n\nimport { useCallback, useMemo } from 'react';\nimport { gql } from '@apollo/client';\nimport { useMutation, useQuery } from '@apollo/client/react';\nimport { useHealthyBowl } from '../context/HealthyBowlContext';\nimport {\n groupPricesByCommodity,\n type CommodityRow,\n type MandiPrice,\n type MandiPriceTrendPoint,\n type PriceAlert,\n type PriceAlertRule,\n type PriceWatch,\n} from '../utils/mandiPrices';\n\nconst FALLBACK_WORKSPACE_ID = '00000000-0000-0000-0000-000000000001';\n\n/** Stable empty reference so downstream `useMemo`s don't recompute every render. */\nconst EMPTY_PRICES: MandiPrice[] = [];\n\ninterface HbContext {\n workspaceId: string;\n}\n\n// ── field fragments ─────────────────────────────────────────────────────────\nconst MANDI_PRICE_FIELDS = `\n commodity\n variety\n marketName\n district\n state\n minPrice\n modalPrice\n maxPrice\n arrivalQty\n unit\n priceDate\n source\n`;\n\nconst TREND_POINT_FIELDS = `\n date\n label\n minPrice\n modalPrice\n maxPrice\n`;\n\nconst WATCH_FIELDS = `\n id\n commodity\n marketName\n district\n state\n`;\n\nconst RULE_FIELDS = `\n id\n commodity\n marketName\n comparator\n threshold\n enabled\n`;\n\nconst ALERT_FIELDS = `\n id\n commodity\n marketName\n comparator\n severity\n title\n message\n value\n threshold\n status\n read\n timestamp\n actionUrl\n`;\n\n// ── documents ─────────────────────────────────────────────────────────────────\nconst GET_PRICES = gql`\n query GetHealthyBowlMandiPrices($context: ContextInput!, $filter: HealthyBowlMandiPriceFilterInput) {\n getHealthyBowlMandiPrices(context: $context, filter: $filter) { ${MANDI_PRICE_FIELDS} }\n }\n`;\n\nconst GET_TREND = gql`\n query GetHealthyBowlMandiPriceTrend(\n $context: ContextInput!\n $commodity: String!\n $marketName: String\n $days: Int\n ) {\n getHealthyBowlMandiPriceTrend(context: $context, commodity: $commodity, marketName: $marketName, days: $days) {\n ${TREND_POINT_FIELDS}\n }\n }\n`;\n\nconst GET_WATCHES = gql`\n query GetHealthyBowlPriceWatches($context: ContextInput!) {\n getHealthyBowlPriceWatches(context: $context) { ${WATCH_FIELDS} }\n }\n`;\n\nconst GET_RULES = gql`\n query GetHealthyBowlPriceAlertRules($context: ContextInput!) {\n getHealthyBowlPriceAlertRules(context: $context) { ${RULE_FIELDS} }\n }\n`;\n\nconst GET_ALERTS = gql`\n query GetHealthyBowlPriceAlerts($context: ContextInput!) {\n getHealthyBowlPriceAlerts(context: $context) { ${ALERT_FIELDS} }\n }\n`;\n\nconst CREATE_WATCH = gql`\n mutation CreateHealthyBowlPriceWatch($input: CreateHealthyBowlPriceWatchInput!) {\n createHealthyBowlPriceWatch(input: $input) { ${WATCH_FIELDS} }\n }\n`;\n\nconst DELETE_WATCH = gql`\n mutation DeleteHealthyBowlPriceWatch($id: ID!, $context: ContextInput!) {\n deleteHealthyBowlPriceWatch(context: $context, id: $id)\n }\n`;\n\nconst CREATE_RULE = gql`\n mutation CreateHealthyBowlPriceAlertRule($input: CreateHealthyBowlPriceAlertRuleInput!) {\n createHealthyBowlPriceAlertRule(input: $input) { ${RULE_FIELDS} }\n }\n`;\n\nconst UPDATE_RULE = gql`\n mutation UpdateHealthyBowlPriceAlertRule($input: UpdateHealthyBowlPriceAlertRuleInput!) {\n updateHealthyBowlPriceAlertRule(input: $input) { ${RULE_FIELDS} }\n }\n`;\n\nconst DELETE_RULE = gql`\n mutation DeleteHealthyBowlPriceAlertRule($id: ID!, $context: ContextInput!) {\n deleteHealthyBowlPriceAlertRule(context: $context, id: $id)\n }\n`;\n\nexport interface MandiPriceFilter {\n commodity?: string | null;\n marketName?: string | null;\n district?: string | null;\n state?: string | null;\n}\n\nexport interface UseMandiPricesOptions {\n /** Optional server-side filter; when omitted, all latest prices are returned. */\n filter?: MandiPriceFilter;\n}\n\nexport function useHealthyBowlMandiPrices(options: UseMandiPricesOptions = {}) {\n const { workspaceId } = useHealthyBowl();\n const effectiveWorkspaceId = workspaceId || FALLBACK_WORKSPACE_ID;\n const ctx = useMemo<HbContext>(() => ({ workspaceId: effectiveWorkspaceId }), [effectiveWorkspaceId]);\n const filter = options.filter;\n\n const pricesQuery = useQuery<\n { getHealthyBowlMandiPrices: MandiPrice[] },\n { context: HbContext; filter?: MandiPriceFilter }\n >(GET_PRICES, { variables: { context: ctx, filter }, fetchPolicy: 'cache-and-network' });\n const watchesQuery = useQuery<{ getHealthyBowlPriceWatches: PriceWatch[] }, { context: HbContext }>(GET_WATCHES, {\n variables: { context: ctx },\n fetchPolicy: 'cache-and-network',\n });\n const rulesQuery = useQuery<{ getHealthyBowlPriceAlertRules: PriceAlertRule[] }, { context: HbContext }>(GET_RULES, {\n variables: { context: ctx },\n fetchPolicy: 'cache-and-network',\n });\n const alertsQuery = useQuery<{ getHealthyBowlPriceAlerts: PriceAlert[] }, { context: HbContext }>(GET_ALERTS, {\n variables: { context: ctx },\n fetchPolicy: 'cache-and-network',\n });\n\n const refetchPrices = pricesQuery.refetch;\n const refetchWatches = watchesQuery.refetch;\n const refetchRules = rulesQuery.refetch;\n const refetchAlerts = alertsQuery.refetch;\n\n const reconcile = useCallback(async (...refetchers: Array<() => Promise<unknown>>) => {\n await Promise.all(refetchers.map((run) => run().catch(() => undefined)));\n }, []);\n\n const [createWatchMutation] = useMutation<\n { createHealthyBowlPriceWatch: PriceWatch },\n { input: Record<string, unknown> }\n >(CREATE_WATCH);\n const [deleteWatchMutation] = useMutation(DELETE_WATCH);\n const [createRuleMutation] = useMutation<\n { createHealthyBowlPriceAlertRule: PriceAlertRule },\n { input: Record<string, unknown> }\n >(CREATE_RULE);\n const [updateRuleMutation] = useMutation<\n { updateHealthyBowlPriceAlertRule: PriceAlertRule },\n { input: Record<string, unknown> }\n >(UPDATE_RULE);\n const [deleteRuleMutation] = useMutation(DELETE_RULE);\n\n const withCtx = useCallback((input: Record<string, unknown>) => ({ ...input, context: ctx }), [ctx]);\n\n const prices = useMemo(() => pricesQuery.data?.getHealthyBowlMandiPrices ?? EMPTY_PRICES, [pricesQuery.data]);\n const commodities = useMemo(() => groupPricesByCommodity(prices), [prices]);\n\n return {\n prices,\n /** Latest prices rolled up to one row per commodity. */\n commodities,\n watches: watchesQuery.data?.getHealthyBowlPriceWatches ?? [],\n alertRules: rulesQuery.data?.getHealthyBowlPriceAlertRules ?? [],\n alerts: alertsQuery.data?.getHealthyBowlPriceAlerts ?? [],\n\n loading: pricesQuery.loading,\n error: pricesQuery.error ?? null,\n watchesLoading: watchesQuery.loading,\n rulesLoading: rulesQuery.loading,\n alertsLoading: alertsQuery.loading,\n\n refetchAll: useCallback(\n () => reconcile(refetchPrices, refetchWatches, refetchRules, refetchAlerts),\n [reconcile, refetchPrices, refetchWatches, refetchRules, refetchAlerts]\n ),\n\n createWatch: useCallback(\n async (input: Record<string, unknown>): Promise<PriceWatch | null> => {\n const res = await createWatchMutation({ variables: { input: withCtx(input) } });\n if (res.error) throw res.error;\n await reconcile(refetchWatches);\n return res.data?.createHealthyBowlPriceWatch ?? null;\n },\n [createWatchMutation, withCtx, reconcile, refetchWatches]\n ),\n deleteWatch: useCallback(\n async (id: string) => {\n const res = await deleteWatchMutation({ variables: { id, context: ctx } });\n if (res.error) throw res.error;\n await reconcile(refetchWatches);\n },\n [deleteWatchMutation, ctx, reconcile, refetchWatches]\n ),\n\n createRule: useCallback(\n async (input: Record<string, unknown>): Promise<PriceAlertRule | null> => {\n const res = await createRuleMutation({ variables: { input: withCtx(input) } });\n if (res.error) throw res.error;\n await reconcile(refetchRules, refetchAlerts);\n return res.data?.createHealthyBowlPriceAlertRule ?? null;\n },\n [createRuleMutation, withCtx, reconcile, refetchRules, refetchAlerts]\n ),\n updateRule: useCallback(\n async (input: Record<string, unknown>): Promise<PriceAlertRule | null> => {\n const res = await updateRuleMutation({ variables: { input: withCtx(input) } });\n if (res.error) throw res.error;\n await reconcile(refetchRules, refetchAlerts);\n return res.data?.updateHealthyBowlPriceAlertRule ?? null;\n },\n [updateRuleMutation, withCtx, reconcile, refetchRules, refetchAlerts]\n ),\n deleteRule: useCallback(\n async (id: string) => {\n const res = await deleteRuleMutation({ variables: { id, context: ctx } });\n if (res.error) throw res.error;\n await reconcile(refetchRules);\n },\n [deleteRuleMutation, ctx, reconcile, refetchRules]\n ),\n\n context: ctx,\n };\n}\n\nexport type { CommodityRow, MandiPrice, PriceAlert, PriceAlertRule, PriceWatch };\n\n// ── price trend (lazy, per selected commodity) ───────────────────────────────\nexport interface UseTrendOptions {\n commodity?: string;\n marketName?: string | null;\n days?: number;\n skip?: boolean;\n}\n\n/**\n * Loads a per-commodity price trend (a time series of daily observations).\n * Skipped until a commodity is selected, so a wrong/unknown market never fires\n * a request on page load; the caller renders it defensively.\n */\nexport function useHealthyBowlMandiPriceTrend(options: UseTrendOptions = {}) {\n const { workspaceId } = useHealthyBowl();\n const effectiveWorkspaceId = workspaceId || FALLBACK_WORKSPACE_ID;\n const ctx = useMemo<HbContext>(() => ({ workspaceId: effectiveWorkspaceId }), [effectiveWorkspaceId]);\n const days = options.days ?? 30;\n\n const trendQuery = useQuery<\n { getHealthyBowlMandiPriceTrend: MandiPriceTrendPoint[] },\n { context: HbContext; commodity: string; marketName: string | null; days: number }\n >(GET_TREND, {\n variables: {\n context: ctx,\n commodity: options.commodity ?? '',\n marketName: options.marketName ?? null,\n days,\n },\n skip: options.skip || !options.commodity,\n fetchPolicy: 'cache-and-network',\n });\n\n return {\n points: trendQuery.data?.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ices.js","names":[],"sources":["../../../src/healthybowl/hooks/useHealthyBowlMandiPrices.ts"],"sourcesContent":["/**\n * Mandi / Market-Price Intelligence — data hook (roadmap #28 · BOFF-4715).\n *\n * Documents are declared inline with `gql` (not `src/operations/wspace/*.graphql`)\n * because codegen validates operations against the committed `graphql/wspace.graphql`\n * snapshot, which doesn't yet carry the mandi subgraph (schema:pull needs a live\n * gateway) — the same escape hatch `useHealthyBowlSensors` / `useDiseaseWarning`\n * use. Types mirror the deployed `wspace-healthybowl-svc` mandi schema.\n *\n * Reads use `cache-and-network`; every write refetches the lists it invalidates.\n * The commodity roll-up is delegated to the pure `groupPricesByCommodity` helper\n * so it stays unit-testable.\n */\n\nimport { useCallback, useMemo } from 'react';\nimport { gql } from '@apollo/client';\nimport { useMutation, useQuery } from '@apollo/client/react';\nimport { useHealthyBowl } from '../context/HealthyBowlContext';\nimport {\n groupPricesByCommodity,\n type CommodityRow,\n type MandiPrice,\n type MandiPriceTrendPoint,\n type PriceAlert,\n type PriceAlertRule,\n type PriceWatch,\n} from '../utils/mandiPrices';\n\nconst FALLBACK_WORKSPACE_ID = '00000000-0000-0000-0000-000000000001';\n\n/** Stable empty reference so downstream `useMemo`s don't recompute every render. */\nconst EMPTY_PRICES: MandiPrice[] = [];\n\ninterface HbContext {\n workspaceId: string;\n}\n\n// ── field fragments ─────────────────────────────────────────────────────────\nconst MANDI_PRICE_FIELDS = `\n commodity\n variety\n marketName\n district\n state\n minPrice\n modalPrice\n maxPrice\n arrivalQty\n unit\n priceDate\n source\n`;\n\nconst TREND_POINT_FIELDS = `\n date\n label\n minPrice\n modalPrice\n maxPrice\n`;\n\nconst WATCH_FIELDS = `\n id\n commodity\n marketName\n district\n state\n`;\n\nconst RULE_FIELDS = `\n id\n commodity\n marketName\n comparator\n threshold\n enabled\n`;\n\nconst ALERT_FIELDS = `\n id\n commodity\n marketName\n comparator\n severity\n title\n message\n value\n threshold\n status\n read\n timestamp\n actionUrl\n`;\n\n// ── documents ─────────────────────────────────────────────────────────────────\nconst GET_PRICES = gql`\n query GetHealthyBowlMandiPrices($context: ContextInput!, $filter: HealthyBowlMandiPriceFilterInput) {\n getHealthyBowlMandiPrices(context: $context, filter: $filter) { ${MANDI_PRICE_FIELDS} }\n }\n`;\n\nconst GET_TREND = gql`\n query GetHealthyBowlMandiPriceTrend(\n $context: ContextInput!\n $commodity: String!\n $marketName: String\n $days: Int\n ) {\n getHealthyBowlMandiPriceTrend(context: $context, commodity: $commodity, marketName: $marketName, days: $days) {\n ${TREND_POINT_FIELDS}\n }\n }\n`;\n\nconst GET_WATCHES = gql`\n query GetHealthyBowlPriceWatches($context: ContextInput!) {\n getHealthyBowlPriceWatches(context: $context) { ${WATCH_FIELDS} }\n }\n`;\n\nconst GET_RULES = gql`\n query GetHealthyBowlPriceAlertRules($context: ContextInput!) {\n getHealthyBowlPriceAlertRules(context: $context) { ${RULE_FIELDS} }\n }\n`;\n\nconst GET_ALERTS = gql`\n query GetHealthyBowlPriceAlerts($context: ContextInput!) {\n getHealthyBowlPriceAlerts(context: $context) { ${ALERT_FIELDS} }\n }\n`;\n\nconst CREATE_WATCH = gql`\n mutation CreateHealthyBowlPriceWatch($input: CreateHealthyBowlPriceWatchInput!) {\n createHealthyBowlPriceWatch(input: $input) { ${WATCH_FIELDS} }\n }\n`;\n\nconst DELETE_WATCH = gql`\n mutation DeleteHealthyBowlPriceWatch($id: ID!, $context: ContextInput!) {\n deleteHealthyBowlPriceWatch(context: $context, id: $id)\n }\n`;\n\nconst CREATE_RULE = gql`\n mutation CreateHealthyBowlPriceAlertRule($input: CreateHealthyBowlPriceAlertRuleInput!) {\n createHealthyBowlPriceAlertRule(input: $input) { ${RULE_FIELDS} }\n }\n`;\n\nconst UPDATE_RULE = gql`\n mutation UpdateHealthyBowlPriceAlertRule($input: UpdateHealthyBowlPriceAlertRuleInput!) {\n updateHealthyBowlPriceAlertRule(input: $input) { ${RULE_FIELDS} }\n }\n`;\n\nconst DELETE_RULE = gql`\n mutation DeleteHealthyBowlPriceAlertRule($id: ID!, $context: ContextInput!) {\n deleteHealthyBowlPriceAlertRule(context: $context, id: $id)\n }\n`;\n\n// A fired PriceAlert is a view over the HB Alert table; acknowledging flips its\n// `read` flag, which the resolver derives into status ACTIVE → ACKNOWLEDGED.\nconst ACKNOWLEDGE_ALERT = gql`\n mutation AcknowledgeHealthyBowlPriceAlert($id: ID!, $context: ContextInput!) {\n acknowledgeHealthyBowlPriceAlert(context: $context, id: $id) { ${ALERT_FIELDS} }\n }\n`;\n\nexport interface MandiPriceFilter {\n commodity?: string | null;\n marketName?: string | null;\n district?: string | null;\n state?: string | null;\n}\n\nexport interface UseMandiPricesOptions {\n /** Optional server-side filter; when omitted, all latest prices are returned. */\n filter?: MandiPriceFilter;\n}\n\nexport function useHealthyBowlMandiPrices(options: UseMandiPricesOptions = {}) {\n const { workspaceId } = useHealthyBowl();\n const effectiveWorkspaceId = workspaceId || FALLBACK_WORKSPACE_ID;\n const ctx = useMemo<HbContext>(() => ({ workspaceId: effectiveWorkspaceId }), [effectiveWorkspaceId]);\n const filter = options.filter;\n\n const pricesQuery = useQuery<\n { getHealthyBowlMandiPrices: MandiPrice[] },\n { context: HbContext; filter?: MandiPriceFilter }\n >(GET_PRICES, { variables: { context: ctx, filter }, fetchPolicy: 'cache-and-network' });\n const watchesQuery = useQuery<{ getHealthyBowlPriceWatches: PriceWatch[] }, { context: HbContext }>(GET_WATCHES, {\n variables: { context: ctx },\n fetchPolicy: 'cache-and-network',\n });\n const rulesQuery = useQuery<{ getHealthyBowlPriceAlertRules: PriceAlertRule[] }, { context: HbContext }>(GET_RULES, {\n variables: { context: ctx },\n fetchPolicy: 'cache-and-network',\n });\n const alertsQuery = useQuery<{ getHealthyBowlPriceAlerts: PriceAlert[] }, { context: HbContext }>(GET_ALERTS, {\n variables: { context: ctx },\n fetchPolicy: 'cache-and-network',\n });\n\n const refetchPrices = pricesQuery.refetch;\n const refetchWatches = watchesQuery.refetch;\n const refetchRules = rulesQuery.refetch;\n const refetchAlerts = alertsQuery.refetch;\n\n const reconcile = useCallback(async (...refetchers: Array<() => Promise<unknown>>) => {\n await Promise.all(refetchers.map((run) => run().catch(() => undefined)));\n }, []);\n\n const [createWatchMutation] = useMutation<\n { createHealthyBowlPriceWatch: PriceWatch },\n { input: Record<string, unknown> }\n >(CREATE_WATCH);\n const [deleteWatchMutation] = useMutation(DELETE_WATCH);\n const [createRuleMutation] = useMutation<\n { createHealthyBowlPriceAlertRule: PriceAlertRule },\n { input: Record<string, unknown> }\n >(CREATE_RULE);\n const [updateRuleMutation] = useMutation<\n { updateHealthyBowlPriceAlertRule: PriceAlertRule },\n { input: Record<string, unknown> }\n >(UPDATE_RULE);\n const [deleteRuleMutation] = useMutation(DELETE_RULE);\n const [acknowledgeAlertMutation] = useMutation<\n { acknowledgeHealthyBowlPriceAlert: PriceAlert },\n { id: string; context: HbContext }\n >(ACKNOWLEDGE_ALERT);\n\n const withCtx = useCallback((input: Record<string, unknown>) => ({ ...input, context: ctx }), [ctx]);\n\n const prices = useMemo(() => pricesQuery.data?.getHealthyBowlMandiPrices ?? EMPTY_PRICES, [pricesQuery.data]);\n const commodities = useMemo(() => groupPricesByCommodity(prices), [prices]);\n\n return {\n prices,\n /** Latest prices rolled up to one row per commodity. */\n commodities,\n watches: watchesQuery.data?.getHealthyBowlPriceWatches ?? [],\n alertRules: rulesQuery.data?.getHealthyBowlPriceAlertRules ?? [],\n alerts: alertsQuery.data?.getHealthyBowlPriceAlerts ?? [],\n\n loading: pricesQuery.loading,\n error: pricesQuery.error ?? null,\n watchesLoading: watchesQuery.loading,\n rulesLoading: rulesQuery.loading,\n alertsLoading: alertsQuery.loading,\n\n refetchAll: useCallback(\n () => reconcile(refetchPrices, refetchWatches, refetchRules, refetchAlerts),\n [reconcile, refetchPrices, refetchWatches, refetchRules, refetchAlerts]\n ),\n\n createWatch: useCallback(\n async (input: Record<string, unknown>): Promise<PriceWatch | null> => {\n const res = await createWatchMutation({ variables: { input: withCtx(input) } });\n if (res.error) throw res.error;\n await reconcile(refetchWatches);\n return res.data?.createHealthyBowlPriceWatch ?? null;\n },\n [createWatchMutation, withCtx, reconcile, refetchWatches]\n ),\n deleteWatch: useCallback(\n async (id: string) => {\n const res = await deleteWatchMutation({ variables: { id, context: ctx } });\n if (res.error) throw res.error;\n await reconcile(refetchWatches);\n },\n [deleteWatchMutation, ctx, reconcile, refetchWatches]\n ),\n\n createRule: useCallback(\n async (input: Record<string, unknown>): Promise<PriceAlertRule | null> => {\n const res = await createRuleMutation({ variables: { input: withCtx(input) } });\n if (res.error) throw res.error;\n await reconcile(refetchRules, refetchAlerts);\n return res.data?.createHealthyBowlPriceAlertRule ?? null;\n },\n [createRuleMutation, withCtx, reconcile, refetchRules, refetchAlerts]\n ),\n updateRule: useCallback(\n async (input: Record<string, unknown>): Promise<PriceAlertRule | null> => {\n const res = await updateRuleMutation({ variables: { input: withCtx(input) } });\n if (res.error) throw res.error;\n await reconcile(refetchRules, refetchAlerts);\n return res.data?.updateHealthyBowlPriceAlertRule ?? null;\n },\n [updateRuleMutation, withCtx, reconcile, refetchRules, refetchAlerts]\n ),\n deleteRule: useCallback(\n async (id: string) => {\n const res = await deleteRuleMutation({ variables: { id, context: ctx } });\n if (res.error) throw res.error;\n await reconcile(refetchRules);\n },\n [deleteRuleMutation, ctx, reconcile, refetchRules]\n ),\n acknowledgeAlert: useCallback(\n async (id: string): Promise<PriceAlert | null> => {\n const res = await acknowledgeAlertMutation({ variables: { id, context: ctx } });\n if (res.error) throw res.error;\n await reconcile(refetchAlerts);\n return res.data?.acknowledgeHealthyBowlPriceAlert ?? null;\n },\n [acknowledgeAlertMutation, ctx, reconcile, refetchAlerts]\n ),\n\n context: ctx,\n };\n}\n\nexport type { CommodityRow, MandiPrice, PriceAlert, PriceAlertRule, PriceWatch };\n\n// ── price trend (lazy, per selected commodity) ───────────────────────────────\nexport interface UseTrendOptions {\n commodity?: string;\n marketName?: string | null;\n days?: number;\n skip?: boolean;\n}\n\n/**\n * Loads a per-commodity price trend (a time series of daily observations).\n * Skipped until a commodity is selected, so a wrong/unknown market never fires\n * a request on page load; the caller renders it defensively.\n */\nexport function useHealthyBowlMandiPriceTrend(options: UseTrendOptions = {}) {\n const { workspaceId } = useHealthyBowl();\n const effectiveWorkspaceId = workspaceId || FALLBACK_WORKSPACE_ID;\n const ctx = useMemo<HbContext>(() => ({ workspaceId: effectiveWorkspaceId }), [effectiveWorkspaceId]);\n const days = options.days ?? 30;\n\n const trendQuery = useQuery<\n { getHealthyBowlMandiPriceTrend: MandiPriceTrendPoint[] },\n { context: HbContext; commodity: string; marketName: string | null; days: number }\n >(GET_TREND, {\n variables: {\n context: ctx,\n commodity: options.commodity ?? '',\n marketName: options.marketName ?? null,\n days,\n },\n skip: options.skip || !options.commodity,\n fetchPolicy: 'cache-and-network',\n });\n\n return {\n points: trendQuery.data?.getHealthyBowlMandiPriceTrend ?? [],\n loading: trendQuery.loading,\n error: trendQuery.error ?? null,\n };\n}\n"],"mappings":";;;;;;AA4BA,IAAM,IAAwB,wCAGxB,IAA6B,EAAE,EAO/B,IAAqB,oJAerB,IAAqB,6DAQrB,IAAe,4DAQf,IAAc,6EASd,IAAe,uJAiBf,IAAa,CAAG;;sEAEgD,EAAmB;;GAInF,IAAY,CAAG;;;;;;;;QAQb,EAAmB;;;GAKrB,IAAc,CAAG;;sDAE+B,EAAa;;GAI7D,IAAY,CAAG;;yDAEoC,EAAY;;GAI/D,IAAa,CAAG;;qDAE+B,EAAa;;GAI5D,IAAe,CAAG;;mDAE2B,EAAa;;GAI1D,IAAe,CAAG;;;;GAMlB,IAAc,CAAG;;uDAEgC,EAAY;;GAI7D,IAAc,CAAG;;uDAEgC,EAAY;;GAI7D,IAAc,CAAG;;;;GAQjB,IAAoB,CAAG;;qEAEwC,EAAa;;;AAgBlF,SAAgB,EAA0B,IAAiC,EAAE,EAAE;CAC7E,IAAM,EAAE,mBAAgB,GAAgB,EAClC,IAAuB,KAAe,GACtC,IAAM,SAA0B,E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