@burdenoff/microfe-healthybowl 2026.905.2 → 2026.905.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (139) hide show
  1. package/dist/healthybowl/HealthyBowlRoot.js +57 -56
  2. package/dist/healthybowl/HealthyBowlRoot.js.map +1 -1
  3. package/dist/healthybowl/HealthyBowlRoutes.js +48 -36
  4. package/dist/healthybowl/HealthyBowlRoutes.js.map +1 -1
  5. package/dist/healthybowl/components/CreateFarmTaskButton.js.map +1 -1
  6. package/dist/healthybowl/components/PageLayout.js +11 -10
  7. package/dist/healthybowl/components/PageLayout.js.map +1 -1
  8. package/dist/healthybowl/context/HealthyBowlContext.js +7 -7
  9. package/dist/healthybowl/context/HealthyBowlContext.js.map +1 -1
  10. package/dist/healthybowl/hooks/useAgronomyDecisions.js +79 -0
  11. package/dist/healthybowl/hooks/useAgronomyDecisions.js.map +1 -0
  12. package/dist/healthybowl/hooks/useAnalyticsReports.js +173 -0
  13. package/dist/healthybowl/hooks/useAnalyticsReports.js.map +1 -0
  14. package/dist/healthybowl/hooks/useComplianceExports.js +74 -0
  15. package/dist/healthybowl/hooks/useComplianceExports.js.map +1 -0
  16. package/dist/healthybowl/hooks/useConsultationPayments.js +59 -0
  17. package/dist/healthybowl/hooks/useConsultationPayments.js.map +1 -0
  18. package/dist/healthybowl/hooks/useHealthyBowlCompliance.js +157 -141
  19. package/dist/healthybowl/hooks/useHealthyBowlCompliance.js.map +1 -1
  20. package/dist/healthybowl/hooks/useHealthyBowlData.js +18 -0
  21. package/dist/healthybowl/hooks/useHealthyBowlData.js.map +1 -1
  22. package/dist/healthybowl/hooks/useHealthyBowlDistribution.js +52 -37
  23. package/dist/healthybowl/hooks/useHealthyBowlDistribution.js.map +1 -1
  24. package/dist/healthybowl/hooks/useHealthyBowlLivestockDepth.js +135 -78
  25. package/dist/healthybowl/hooks/useHealthyBowlLivestockDepth.js.map +1 -1
  26. package/dist/healthybowl/hooks/useIrrigationAutomation.js +1 -1
  27. package/dist/healthybowl/hooks/useIrrigationAutomation.js.map +1 -1
  28. package/dist/healthybowl/hooks/usePlantingEstimate.js +88 -0
  29. package/dist/healthybowl/hooks/usePlantingEstimate.js.map +1 -0
  30. package/dist/healthybowl/hooks/useSuccessionPlanning.js +1 -1
  31. package/dist/healthybowl/hooks/useSuccessionPlanning.js.map +1 -1
  32. package/dist/healthybowl/hooks/useWeatherIntelligence.js +1 -1
  33. package/dist/healthybowl/hooks/useWeatherIntelligence.js.map +1 -1
  34. package/dist/healthybowl/offline/HeaderOfflinePill.js +28 -0
  35. package/dist/healthybowl/offline/HeaderOfflinePill.js.map +1 -0
  36. package/dist/healthybowl/offline/OfflineStatusPill.js +40 -21
  37. package/dist/healthybowl/offline/OfflineStatusPill.js.map +1 -1
  38. package/dist/healthybowl/offline/OfflineSyncProvider.js +149 -126
  39. package/dist/healthybowl/offline/OfflineSyncProvider.js.map +1 -1
  40. package/dist/healthybowl/offline/captureCache.js +30 -0
  41. package/dist/healthybowl/offline/captureCache.js.map +1 -0
  42. package/dist/healthybowl/offline/graphql.js.map +1 -1
  43. package/dist/healthybowl/offline/headerSlot.js +24 -0
  44. package/dist/healthybowl/offline/headerSlot.js.map +1 -0
  45. package/dist/healthybowl/offline/store.js +1 -1
  46. package/dist/healthybowl/offline/syncEngine.js +2 -1
  47. package/dist/healthybowl/offline/syncEngine.js.map +1 -1
  48. package/dist/healthybowl/offline/types.js.map +1 -1
  49. package/dist/healthybowl/pages/GettingStartedPage.js +1 -0
  50. package/dist/healthybowl/pages/GettingStartedPage.js.map +1 -1
  51. package/dist/healthybowl/pages/ai/AiDecisionsPage.js +287 -0
  52. package/dist/healthybowl/pages/ai/AiDecisionsPage.js.map +1 -0
  53. package/dist/healthybowl/pages/analytics/InsightsPage.js +2 -2
  54. package/dist/healthybowl/pages/analytics/InsightsPage.js.map +1 -1
  55. package/dist/healthybowl/pages/analytics/ReportsPage.js +136 -99
  56. package/dist/healthybowl/pages/analytics/ReportsPage.js.map +1 -1
  57. package/dist/healthybowl/pages/compliance/ComplianceOverviewPage.js +204 -162
  58. package/dist/healthybowl/pages/compliance/ComplianceOverviewPage.js.map +1 -1
  59. package/dist/healthybowl/pages/compliance/IcsGroupDetailPage.js +196 -178
  60. package/dist/healthybowl/pages/compliance/IcsGroupDetailPage.js.map +1 -1
  61. package/dist/healthybowl/pages/compliance/IcsGrowerDetailPage.js +142 -141
  62. package/dist/healthybowl/pages/compliance/IcsGrowerDetailPage.js.map +1 -1
  63. package/dist/healthybowl/pages/compliance/ResidueTestsPage.js +291 -0
  64. package/dist/healthybowl/pages/compliance/ResidueTestsPage.js.map +1 -0
  65. package/dist/healthybowl/pages/compliance/SubstanceRulesPage.js +300 -0
  66. package/dist/healthybowl/pages/compliance/SubstanceRulesPage.js.map +1 -0
  67. package/dist/healthybowl/pages/compliance/substanceRuleForm.js +135 -0
  68. package/dist/healthybowl/pages/compliance/substanceRuleForm.js.map +1 -0
  69. package/dist/healthybowl/pages/crops/CropFieldsPage.js +2 -0
  70. package/dist/healthybowl/pages/crops/CropFieldsPage.js.map +1 -1
  71. package/dist/healthybowl/pages/crops/CropHarvestPage.js +316 -272
  72. package/dist/healthybowl/pages/crops/CropHarvestPage.js.map +1 -1
  73. package/dist/healthybowl/pages/crops/CropPlanningPage.js +6 -0
  74. package/dist/healthybowl/pages/crops/CropPlanningPage.js.map +1 -1
  75. package/dist/healthybowl/pages/crops/FieldDetailsPage.js +871 -846
  76. package/dist/healthybowl/pages/crops/FieldDetailsPage.js.map +1 -1
  77. package/dist/healthybowl/pages/crops/HarvestDetailsPage.js +376 -334
  78. package/dist/healthybowl/pages/crops/HarvestDetailsPage.js.map +1 -1
  79. package/dist/healthybowl/pages/distribution/CsaPlanDetailPage.js +415 -188
  80. package/dist/healthybowl/pages/distribution/CsaPlanDetailPage.js.map +1 -1
  81. package/dist/healthybowl/pages/distribution/labels.js +10 -2
  82. package/dist/healthybowl/pages/distribution/labels.js.map +1 -1
  83. package/dist/healthybowl/pages/farm/FarmProfilePage.js +1 -0
  84. package/dist/healthybowl/pages/farm/FarmProfilePage.js.map +1 -1
  85. package/dist/healthybowl/pages/field-capture/CaptureObservationForm.js +8 -8
  86. package/dist/healthybowl/pages/fields/FieldMapPage.js +2 -0
  87. package/dist/healthybowl/pages/fields/FieldMapPage.js.map +1 -1
  88. package/dist/healthybowl/pages/financial/FinancialReportsPage.js +92 -107
  89. package/dist/healthybowl/pages/financial/FinancialReportsPage.js.map +1 -1
  90. package/dist/healthybowl/pages/government-schemes/ApplicationTrackingPage.js +228 -188
  91. package/dist/healthybowl/pages/government-schemes/ApplicationTrackingPage.js.map +1 -1
  92. package/dist/healthybowl/pages/government-schemes/SchemeDetailsPage.js +261 -191
  93. package/dist/healthybowl/pages/government-schemes/SchemeDetailsPage.js.map +1 -1
  94. package/dist/healthybowl/pages/government-schemes/schemeApplicationTransitions.js +49 -0
  95. package/dist/healthybowl/pages/government-schemes/schemeApplicationTransitions.js.map +1 -0
  96. package/dist/healthybowl/pages/government-schemes/schemeDocumentSlots.js +48 -0
  97. package/dist/healthybowl/pages/government-schemes/schemeDocumentSlots.js.map +1 -0
  98. package/dist/healthybowl/pages/government-schemes/useSchemeApplicationTransition.js +54 -0
  99. package/dist/healthybowl/pages/government-schemes/useSchemeApplicationTransition.js.map +1 -0
  100. package/dist/healthybowl/pages/inputs-insurance/InputsInsuranceOverviewPage.js +14 -14
  101. package/dist/healthybowl/pages/inputs-insurance/InputsInsuranceOverviewPage.js.map +1 -1
  102. package/dist/healthybowl/pages/irrigation/IrrigationPage.js +338 -307
  103. package/dist/healthybowl/pages/irrigation/IrrigationPage.js.map +1 -1
  104. package/dist/healthybowl/pages/livestock/AnimalDepthFormModal.js +126 -102
  105. package/dist/healthybowl/pages/livestock/AnimalDepthFormModal.js.map +1 -1
  106. package/dist/healthybowl/pages/livestock/AnimalDepthPage.js +257 -215
  107. package/dist/healthybowl/pages/livestock/AnimalDepthPage.js.map +1 -1
  108. package/dist/healthybowl/pages/livestock/GrazingPage.js +1 -0
  109. package/dist/healthybowl/pages/livestock/GrazingPage.js.map +1 -1
  110. package/dist/healthybowl/pages/livestock/HerdDepthPage.js +4 -0
  111. package/dist/healthybowl/pages/livestock/HerdDepthPage.js.map +1 -1
  112. package/dist/healthybowl/pages/livestock/PedigreeTree.js +154 -0
  113. package/dist/healthybowl/pages/livestock/PedigreeTree.js.map +1 -0
  114. package/dist/healthybowl/pages/livestock/eidTagInput.js +39 -0
  115. package/dist/healthybowl/pages/livestock/eidTagInput.js.map +1 -0
  116. package/dist/healthybowl/pages/livestock/grazing/RecordGrazingMoveModal.js +8 -9
  117. package/dist/healthybowl/pages/livestock/grazing/RecordGrazingMoveModal.js.map +1 -1
  118. package/dist/healthybowl/pages/livestock/pedigreeLayout.js +68 -0
  119. package/dist/healthybowl/pages/livestock/pedigreeLayout.js.map +1 -0
  120. package/dist/healthybowl/pages/network/ExpertsPage.js +520 -419
  121. package/dist/healthybowl/pages/network/ExpertsPage.js.map +1 -1
  122. package/dist/healthybowl/pages/pest-management/AiPestDetectionPage.js +12 -12
  123. package/dist/healthybowl/pages/pest-management/AiPestDetectionPage.js.map +1 -1
  124. package/dist/healthybowl/pages/terrace/JournalEntryModal.js +165 -165
  125. package/dist/healthybowl/pages/terrace/JournalEntryModal.js.map +1 -1
  126. package/dist/healthybowl/pages/weather/WeatherAlertHistoryPage.js +129 -130
  127. package/dist/healthybowl/pages/weather/WeatherAlertHistoryPage.js.map +1 -1
  128. package/dist/healthybowl/pages/weather/WeatherSettingsPage.js +285 -237
  129. package/dist/healthybowl/pages/weather/WeatherSettingsPage.js.map +1 -1
  130. package/dist/healthybowl/pages/weather/alertDelivery.js +105 -0
  131. package/dist/healthybowl/pages/weather/alertDelivery.js.map +1 -0
  132. package/dist/healthybowl/store/healthybowlStore.js +5 -5
  133. package/dist/healthybowl/utils/icsInspection.js +18 -0
  134. package/dist/healthybowl/utils/icsInspection.js.map +1 -0
  135. package/dist/healthybowl/utils/plantingCapacity.js +10 -10
  136. package/dist/healthybowl/utils/plantingCapacity.js.map +1 -1
  137. package/dist/node_modules/fast-equals/dist/es/index.js +74 -86
  138. package/dist/node_modules/fast-equals/dist/es/index.js.map +1 -1
  139. package/package.json +2 -2
@@ -4,13 +4,13 @@ import { createContext as n, useCallback as r, useContext as i, useRef as a } fr
4
4
  import { MemoryRouter as o } from "react-router";
5
5
  import { jsx as s } from "react/jsx-runtime";
6
6
  //#region src/healthybowl/context/HealthyBowlContext.tsx
7
- var c = n(null);
8
- function l() {
9
- let e = i(c);
7
+ var c = "00000000-0000-0000-0000-000000000001", l = n(null);
8
+ function u() {
9
+ let e = i(l);
10
10
  if (!e) throw Error("useHealthyBowl must be used within a HealthyBowlProvider");
11
11
  return e;
12
12
  }
13
- var u = ({ children: n, basePath: i = "/", navigate: l = () => {}, currentUser: u, workspaceId: d = "", apiGatewayUrl: f = "", globalGatewayUrl: p = "", authToken: m = "", googleMapsApiKey: h, ttsEndpoint: g }) => {
13
+ var d = ({ children: n, basePath: i = "/", navigate: c = () => {}, currentUser: u, workspaceId: d = "", apiGatewayUrl: f = "", globalGatewayUrl: p = "", authToken: m = "", googleMapsApiKey: h, ttsEndpoint: g }) => {
14
14
  e({ googleMapsApiKey: h });
15
15
  let _ = a(m);
16
16
  _.current = m, t({
@@ -19,19 +19,19 @@ var u = ({ children: n, basePath: i = "/", navigate: l = () => {}, currentUser:
19
19
  });
20
20
  let v = {
21
21
  basePath: i,
22
- navigate: l,
22
+ navigate: c,
23
23
  currentUser: u,
24
24
  workspaceId: d,
25
25
  apiGatewayUrl: f,
26
26
  globalGatewayUrl: p,
27
27
  authToken: m
28
- }, y = /* @__PURE__ */ s(c.Provider, {
28
+ }, y = /* @__PURE__ */ s(l.Provider, {
29
29
  value: v,
30
30
  children: n
31
31
  });
32
32
  return i && i !== "/" ? y : /* @__PURE__ */ s(o, { children: y });
33
33
  };
34
34
  //#endregion
35
- export { u as HealthyBowlProvider, l as useHealthyBowl };
35
+ export { c as HEALTHYBOWL_FALLBACK_WORKSPACE_ID, d as HealthyBowlProvider, u as useHealthyBowl };
36
36
 
37
37
  //# sourceMappingURL=HealthyBowlContext.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"HealthyBowlContext.js","names":[],"sources":["../../../src/healthybowl/context/HealthyBowlContext.tsx"],"sourcesContent":["/**\n * HealthyBowl Context Provider\n * @module healthybowl\n */\n\nimport { createContext, useCallback, useContext, useRef, type FC, type PropsWithChildren } from 'react';\nimport { MemoryRouter } from 'react-router';\nimport type { HealthyBowlRootProps } from '../types';\nimport { configureGeocoder } from '../utils/geocode';\nimport { configureSpeechEngine } from '../../services/speech';\n\ninterface HealthyBowlContextValue {\n basePath: string;\n navigate: (path: string) => void;\n currentUser: HealthyBowlRootProps['currentUser'];\n workspaceId: string;\n apiGatewayUrl: string;\n globalGatewayUrl: string;\n authToken: string;\n}\n\nconst HealthyBowlContext = createContext<HealthyBowlContextValue | null>(null);\n\nexport function useHealthyBowl(): HealthyBowlContextValue {\n const context = useContext(HealthyBowlContext);\n if (!context) {\n throw new Error('useHealthyBowl must be used within a HealthyBowlProvider');\n }\n return context;\n}\n\nexport const HealthyBowlProvider: FC<PropsWithChildren<HealthyBowlRootProps>> = ({\n children,\n basePath = '/',\n navigate = () => {},\n currentUser,\n workspaceId = '',\n apiGatewayUrl = '',\n globalGatewayUrl = '',\n authToken = '',\n googleMapsApiKey,\n ttsEndpoint,\n}) => {\n // Inject the host app's Google Maps key into the (non-React) geocoder. Done\n // synchronously in render (not useEffect) so it's set before child map effects\n // run — child effects fire before parent effects. Idempotent module assignment.\n configureGeocoder({ googleMapsApiKey });\n\n /**\n * Point the assistant's speech stack at the hosted TTS proxy.\n *\n * Wiring it HERE, rather than exporting `configureSpeechEngine` for the host\n * to call, is what makes the feature exist at all: nothing outside this graph\n * imported it, so the published bundle had the function tree-shaken away and\n * the module-level endpoint/header slots could never be assigned. The only\n * reachable switch was `window.__HB_TTS_ENDPOINT__`, which carries no headers\n * — i.e. hosted TTS could previously only have been enabled ANONYMOUSLY,\n * against a proxy that bills per character.\n *\n * The token is read through a ref rather than captured. `configureSpeechEngine`\n * is deliberately idempotent (resetting the memoised engine every render would\n * cancel playback mid-reply), so it keeps the FIRST `getHeaders` it is given —\n * and a captured token would work right up until it refreshed, then fail in\n * the hardest place to notice. A stable identity also means this call is a\n * no-op on every render after the first.\n */\n const authTokenRef = useRef(authToken);\n authTokenRef.current = authToken;\n const getHeaders = useCallback(\n (): Record<string, string> => (authTokenRef.current ? { authorization: `Bearer ${authTokenRef.current}` } : {}),\n []\n );\n configureSpeechEngine({ ttsEndpoint, getHeaders });\n\n const contextValue: HealthyBowlContextValue = {\n basePath,\n navigate,\n currentUser,\n workspaceId,\n apiGatewayUrl,\n globalGatewayUrl,\n authToken,\n };\n\n const content = <HealthyBowlContext.Provider value={contextValue}>{children}</HealthyBowlContext.Provider>;\n\n // If basePath is provided, we're running inside the host shell (which has BrowserRouter)\n if (basePath && basePath !== '/') return content;\n\n // Standalone mode: wrap in MemoryRouter\n return <MemoryRouter>{content}</MemoryRouter>;\n};\n"],"mappings":";;;;;;AAqBA,IAAM,IAAqB,EAA8C,IAAI;AAE7E,SAAgB,IAA0C;CACxD,IAAM,IAAU,EAAW,CAAkB;CAC7C,IAAI,CAAC,GACH,MAAU,MAAM,0DAA0D;CAE5E,OAAO;AACT;AAEA,IAAa,KAAoE,EAC/E,aACA,cAAW,KACX,oBAAiB,CAAC,GAClB,gBACA,iBAAc,IACd,mBAAgB,IAChB,sBAAmB,IACnB,eAAY,IACZ,qBACA,qBACI;CAIJ,EAAkB,EAAE,oBAAiB,CAAC;CAoBtC,IAAM,IAAe,EAAO,CAAS;CAMrC,AALA,EAAa,UAAU,GAKvB,EAAsB;EAAE;EAAa,YAJlB,QACc,EAAa,UAAU,EAAE,eAAe,UAAU,EAAa,UAAU,IAAI,CAAC,GAC7G,CAAC,CAEkC;CAAW,CAAC;CAEjD,IAAM,IAAwC;EAC5C;EACA;EACA;EACA;EACA;EACA;EACA;CACF,GAEM,IAAU,kBAAC,EAAmB,UAApB;EAA6B,OAAO;EAAe;CAAsC,CAAA;CAMzG,OAHI,KAAY,MAAa,MAAY,IAGlC,kBAAC,GAAD,EAAA,UAAe,EAAsB,CAAA;AAC9C"}
1
+ {"version":3,"file":"HealthyBowlContext.js","names":[],"sources":["../../../src/healthybowl/context/HealthyBowlContext.tsx"],"sourcesContent":["/**\n * HealthyBowl Context Provider\n * @module healthybowl\n */\n\nimport { createContext, useCallback, useContext, useRef, type FC, type PropsWithChildren } from 'react';\nimport { MemoryRouter } from 'react-router';\nimport type { HealthyBowlRootProps } from '../types';\nimport { configureGeocoder } from '../utils/geocode';\nimport { configureSpeechEngine } from '../../services/speech';\n\ninterface HealthyBowlContextValue {\n basePath: string;\n navigate: (path: string) => void;\n currentUser: HealthyBowlRootProps['currentUser'];\n workspaceId: string;\n apiGatewayUrl: string;\n globalGatewayUrl: string;\n authToken: string;\n}\n\n/** Keeps standalone/default-prop data reads and mutations in the same demo workspace. */\nexport const HEALTHYBOWL_FALLBACK_WORKSPACE_ID = '00000000-0000-0000-0000-000000000001';\n\nconst HealthyBowlContext = createContext<HealthyBowlContextValue | null>(null);\n\nexport function useHealthyBowl(): HealthyBowlContextValue {\n const context = useContext(HealthyBowlContext);\n if (!context) {\n throw new Error('useHealthyBowl must be used within a HealthyBowlProvider');\n }\n return context;\n}\n\nexport const HealthyBowlProvider: FC<PropsWithChildren<HealthyBowlRootProps>> = ({\n children,\n basePath = '/',\n navigate = () => {},\n currentUser,\n workspaceId = '',\n apiGatewayUrl = '',\n globalGatewayUrl = '',\n authToken = '',\n googleMapsApiKey,\n ttsEndpoint,\n}) => {\n // Inject the host app's Google Maps key into the (non-React) geocoder. Done\n // synchronously in render (not useEffect) so it's set before child map effects\n // run — child effects fire before parent effects. Idempotent module assignment.\n configureGeocoder({ googleMapsApiKey });\n\n /**\n * Point the assistant's speech stack at the hosted TTS proxy.\n *\n * Wiring it HERE, rather than exporting `configureSpeechEngine` for the host\n * to call, is what makes the feature exist at all: nothing outside this graph\n * imported it, so the published bundle had the function tree-shaken away and\n * the module-level endpoint/header slots could never be assigned. The only\n * reachable switch was `window.__HB_TTS_ENDPOINT__`, which carries no headers\n * — i.e. hosted TTS could previously only have been enabled ANONYMOUSLY,\n * against a proxy that bills per character.\n *\n * The token is read through a ref rather than captured. `configureSpeechEngine`\n * is deliberately idempotent (resetting the memoised engine every render would\n * cancel playback mid-reply), so it keeps the FIRST `getHeaders` it is given —\n * and a captured token would work right up until it refreshed, then fail in\n * the hardest place to notice. A stable identity also means this call is a\n * no-op on every render after the first.\n */\n const authTokenRef = useRef(authToken);\n authTokenRef.current = authToken;\n const getHeaders = useCallback(\n (): Record<string, string> => (authTokenRef.current ? { authorization: `Bearer ${authTokenRef.current}` } : {}),\n []\n );\n configureSpeechEngine({ ttsEndpoint, getHeaders });\n\n const contextValue: HealthyBowlContextValue = {\n basePath,\n navigate,\n currentUser,\n workspaceId,\n apiGatewayUrl,\n globalGatewayUrl,\n authToken,\n };\n\n const content = <HealthyBowlContext.Provider value={contextValue}>{children}</HealthyBowlContext.Provider>;\n\n // If basePath is provided, we're running inside the host shell (which has BrowserRouter)\n if (basePath && basePath !== '/') return content;\n\n // Standalone mode: wrap in MemoryRouter\n return <MemoryRouter>{content}</MemoryRouter>;\n};\n"],"mappings":";;;;;;AAsBA,IAAa,IAAoC,wCAE3C,IAAqB,EAA8C,IAAI;AAE7E,SAAgB,IAA0C;CACxD,IAAM,IAAU,EAAW,CAAkB;CAC7C,IAAI,CAAC,GACH,MAAU,MAAM,0DAA0D;CAE5E,OAAO;AACT;AAEA,IAAa,KAAoE,EAC/E,aACA,cAAW,KACX,oBAAiB,CAAC,GAClB,gBACA,iBAAc,IACd,mBAAgB,IAChB,sBAAmB,IACnB,eAAY,IACZ,qBACA,qBACI;CAIJ,EAAkB,EAAE,oBAAiB,CAAC;CAoBtC,IAAM,IAAe,EAAO,CAAS;CAMrC,AALA,EAAa,UAAU,GAKvB,EAAsB;EAAE;EAAa,YAJlB,QACc,EAAa,UAAU,EAAE,eAAe,UAAU,EAAa,UAAU,IAAI,CAAC,GAC7G,CAAC,CAEkC;CAAW,CAAC;CAEjD,IAAM,IAAwC;EAC5C;EACA;EACA;EACA;EACA;EACA;EACA;CACF,GAEM,IAAU,kBAAC,EAAmB,UAApB;EAA6B,OAAO;EAAe;CAAsC,CAAA;CAMzG,OAHI,KAAY,MAAa,MAAY,IAGlC,kBAAC,GAAD,EAAA,UAAe,EAAsB,CAAA;AAC9C"}
@@ -0,0 +1,79 @@
1
+ import { useHealthyBowl as e } from "../context/HealthyBowlContext.js";
2
+ import { useCallback as t, useMemo as n } from "react";
3
+ import { gql as r } from "@apollo/client";
4
+ import { useMutation as i, useQuery as a } from "@apollo/client/react";
5
+ //#region src/healthybowl/hooks/useAgronomyDecisions.ts
6
+ var o = "\n id\n decisionType\n status\n source\n subjectId\n subjectType\n fieldId\n plantScanId\n title\n rationale\n confidence\n inputs\n railChecks {\n rail\n outcome\n detail\n }\n blockedReason\n recommendedMm\n modelProvider\n modelName\n decidedBy\n decidedAt\n createdAt\n updatedAt\n", s = r`
7
+ query GetHealthyBowlAgronomyDecisions(
8
+ $context: ContextInput!
9
+ $filter: AgronomyDecisionFilterInput
10
+ ) {
11
+ getHealthyBowlAgronomyDecisions(context: $context, filter: $filter) {
12
+ ${o}
13
+ }
14
+ }
15
+ `, c = r`
16
+ mutation ProposeHealthyBowlAgronomyDecisions($input: ProposeAgronomyDecisionsInput!) {
17
+ proposeHealthyBowlAgronomyDecisions(input: $input) {
18
+ skipped
19
+ skippedReason
20
+ decisions {
21
+ ${o}
22
+ }
23
+ }
24
+ }
25
+ `, l = r`
26
+ mutation DecideHealthyBowlAgronomyDecision($input: DecideAgronomyDecisionInput!) {
27
+ decideHealthyBowlAgronomyDecision(input: $input) {
28
+ ${o}
29
+ }
30
+ }
31
+ `;
32
+ function u() {
33
+ let { workspaceId: r } = e(), o = n(() => ({ workspaceId: r }), [r]), { data: u, loading: d, error: f, refetch: p } = a(s, {
34
+ variables: {
35
+ context: o,
36
+ filter: {}
37
+ },
38
+ skip: !r,
39
+ fetchPolicy: "cache-and-network"
40
+ }), [m, { loading: h }] = i(c), [g, { loading: _ }] = i(l), v = t(async (e) => {
41
+ let t = await m({ variables: { input: {
42
+ context: o,
43
+ decisionType: e
44
+ } } });
45
+ return await p(), t.data?.proposeHealthyBowlAgronomyDecisions ?? {
46
+ decisions: [],
47
+ skipped: 0,
48
+ skippedReason: null
49
+ };
50
+ }, [
51
+ m,
52
+ p,
53
+ o
54
+ ]), y = t(async (e, t) => {
55
+ await g({ variables: { input: {
56
+ context: o,
57
+ id: e,
58
+ verdict: t
59
+ } } }), await p();
60
+ }, [
61
+ g,
62
+ p,
63
+ o
64
+ ]);
65
+ return {
66
+ decisions: u?.getHealthyBowlAgronomyDecisions ?? [],
67
+ loading: d,
68
+ error: f,
69
+ refetch: p,
70
+ propose: v,
71
+ proposing: h,
72
+ decide: y,
73
+ deciding: _
74
+ };
75
+ }
76
+ //#endregion
77
+ export { u as useAgronomyDecisions };
78
+
79
+ //# sourceMappingURL=useAgronomyDecisions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAgronomyDecisions.js","names":[],"sources":["../../../src/healthybowl/hooks/useAgronomyDecisions.ts"],"sourcesContent":["/**\n * AI agronomic decision data hook (BOFF-3629 · HB-UC-18/19).\n *\n * Mirrors the raw-gql pattern used by `useDiseaseWarning` / `useIrrigationAutomation`: the\n * committed codegen snapshot predates the `agronomy-decision` subgraph, so these are hand-written\n * `gql` documents executed against the live gateway. Every op carries the workspace `context`.\n *\n * The backend ignores the workspace inside `context` and scopes on the `x-workspace-id` header —\n * it is threaded through anyway because the argument is non-null in the schema and every other HB\n * operation passes it the same way.\n *\n * @module healthybowl\n */\nimport { useCallback, useMemo } from 'react';\nimport { gql } from '@apollo/client';\nimport { useMutation, useQuery } from '@apollo/client/react';\nimport { useHealthyBowl } from '../context/HealthyBowlContext';\n\n/** One compliance rail and what it concluded (UC-19). */\nexport interface AgronomyRailCheck {\n /** PROHIBITED_SUBSTANCE | MEDICATION_WITHDRAWAL. */\n rail: string;\n /** PASS | BLOCKED | NOT_APPLICABLE. */\n outcome: string;\n detail: string;\n}\n\n/** A decision the engine proposed, with the evidence and rails behind it. */\nexport interface AgronomyDecision {\n id: string;\n /** IRRIGATION | TREATMENT. */\n decisionType: string;\n /** PROPOSED | ACCEPTED | REJECTED | BLOCKED. */\n status: string;\n /** MODEL | HEURISTIC — whether a model actually produced this wording. */\n source: string;\n subjectId: string;\n subjectType: string;\n fieldId?: string | null;\n plantScanId?: string | null;\n title: string;\n rationale: string;\n /** 0..1, or null when nothing honest could be reported. */\n confidence?: number | null;\n /** The real records this rests on — probe code, reading timestamp, scan id. */\n inputs?: Record<string, unknown> | null;\n railChecks: AgronomyRailCheck[];\n blockedReason?: string | null;\n recommendedMm?: number | null;\n modelProvider?: string | null;\n modelName?: string | null;\n decidedBy?: string | null;\n decidedAt?: string | null;\n createdAt: string;\n updatedAt: string;\n}\n\nexport interface AgronomySweepResult {\n decisions: AgronomyDecision[];\n skipped: number;\n skippedReason?: string | null;\n}\n\nconst DECISION_FIELDS = `\n id\n decisionType\n status\n source\n subjectId\n subjectType\n fieldId\n plantScanId\n title\n rationale\n confidence\n inputs\n railChecks {\n rail\n outcome\n detail\n }\n blockedReason\n recommendedMm\n modelProvider\n modelName\n decidedBy\n decidedAt\n createdAt\n updatedAt\n`;\n\nconst GET_AGRONOMY_DECISIONS = gql`\n query GetHealthyBowlAgronomyDecisions(\n $context: ContextInput!\n $filter: AgronomyDecisionFilterInput\n ) {\n getHealthyBowlAgronomyDecisions(context: $context, filter: $filter) {\n ${DECISION_FIELDS}\n }\n }\n`;\n\nconst PROPOSE_AGRONOMY_DECISIONS = gql`\n mutation ProposeHealthyBowlAgronomyDecisions($input: ProposeAgronomyDecisionsInput!) {\n proposeHealthyBowlAgronomyDecisions(input: $input) {\n skipped\n skippedReason\n decisions {\n ${DECISION_FIELDS}\n }\n }\n }\n`;\n\nconst DECIDE_AGRONOMY_DECISION = gql`\n mutation DecideHealthyBowlAgronomyDecision($input: DecideAgronomyDecisionInput!) {\n decideHealthyBowlAgronomyDecision(input: $input) {\n ${DECISION_FIELDS}\n }\n }\n`;\n\nexport function useAgronomyDecisions() {\n const { workspaceId } = useHealthyBowl();\n // Memoised so the callbacks below have a stable dependency. A fresh object each render would\n // make every consumer's `propose`/`decide` identity change on every render.\n const context = useMemo(() => ({ workspaceId }), [workspaceId]);\n\n const { data, loading, error, refetch } = useQuery<{\n getHealthyBowlAgronomyDecisions: AgronomyDecision[];\n }>(GET_AGRONOMY_DECISIONS, {\n variables: { context, filter: {} },\n skip: !workspaceId,\n fetchPolicy: 'cache-and-network',\n });\n\n const [proposeMutation, { loading: proposing }] = useMutation<{\n proposeHealthyBowlAgronomyDecisions: AgronomySweepResult;\n }>(PROPOSE_AGRONOMY_DECISIONS);\n\n const [decideMutation, { loading: deciding }] = useMutation<{\n decideHealthyBowlAgronomyDecision: AgronomyDecision;\n }>(DECIDE_AGRONOMY_DECISION);\n\n /** Run a sweep. Returns the result so the caller can surface `skippedReason`. */\n const propose = useCallback(\n async (decisionType: 'IRRIGATION' | 'TREATMENT'): Promise<AgronomySweepResult> => {\n const result = await proposeMutation({\n variables: { input: { context, decisionType } },\n });\n await refetch();\n return (\n result.data?.proposeHealthyBowlAgronomyDecisions ?? {\n decisions: [],\n skipped: 0,\n skippedReason: null,\n }\n );\n },\n [proposeMutation, refetch, context]\n );\n\n const decide = useCallback(\n async (id: string, verdict: 'ACCEPTED' | 'REJECTED') => {\n await decideMutation({ variables: { input: { context, id, verdict } } });\n await refetch();\n },\n [decideMutation, refetch, context]\n );\n\n return {\n decisions: data?.getHealthyBowlAgronomyDecisions ?? [],\n loading,\n error,\n refetch,\n propose,\n proposing,\n decide,\n deciding,\n };\n}\n"],"mappings":";;;;;AA+DA,IAAM,IAAkB,gUA4BlB,IAAyB,CAAG;;;;;;QAM1B,EAAgB;;;GAKlB,IAA6B,CAAG;;;;;;UAM5B,EAAgB;;;;GAMpB,IAA2B,CAAG;;;QAG5B,EAAgB;;;;AAKxB,SAAgB,IAAuB;CACrC,IAAM,EAAE,mBAAgB,EAAe,GAGjC,IAAU,SAAe,EAAE,eAAY,IAAI,CAAC,CAAW,CAAC,GAExD,EAAE,SAAM,YAAS,UAAO,eAAY,EAEvC,GAAwB;EACzB,WAAW;GAAE;GAAS,QAAQ,CAAC;EAAE;EACjC,MAAM,CAAC;EACP,aAAa;CACf,CAAC,GAEK,CAAC,GAAiB,EAAE,SAAS,OAAe,EAE/C,CAA0B,GAEvB,CAAC,GAAgB,EAAE,SAAS,OAAc,EAE7C,CAAwB,GAGrB,IAAU,EACd,OAAO,MAA2E;EAChF,IAAM,IAAS,MAAM,EAAgB,EACnC,WAAW,EAAE,OAAO;GAAE;GAAS;EAAa,EAAE,EAChD,CAAC;EAED,OADA,MAAM,EAAQ,GAEZ,EAAO,MAAM,uCAAuC;GAClD,WAAW,CAAC;GACZ,SAAS;GACT,eAAe;EACjB;CAEJ,GACA;EAAC;EAAiB;EAAS;CAAO,CACpC,GAEM,IAAS,EACb,OAAO,GAAY,MAAqC;EAEtD,AADA,MAAM,EAAe,EAAE,WAAW,EAAE,OAAO;GAAE;GAAS;GAAI;EAAQ,EAAE,EAAE,CAAC,GACvE,MAAM,EAAQ;CAChB,GACA;EAAC;EAAgB;EAAS;CAAO,CACnC;CAEA,OAAO;EACL,WAAW,GAAM,mCAAmC,CAAC;EACrD;EACA;EACA;EACA;EACA;EACA;EACA;CACF;AACF"}
@@ -0,0 +1,173 @@
1
+ import { useHealthyBowl as e } from "../context/HealthyBowlContext.js";
2
+ import { useCallback as t, useRef as n, useState as r } from "react";
3
+ import { gql as i } from "@apollo/client";
4
+ import { useApolloClient as a, useMutation as o } from "@apollo/client/react";
5
+ //#region src/healthybowl/hooks/useAnalyticsReports.ts
6
+ var s = i`
7
+ mutation GenerateHealthyBowlAnalyticsReport(
8
+ $context: ContextInput!
9
+ $title: String
10
+ $type: String!
11
+ $startDate: String!
12
+ $endDate: String!
13
+ ) {
14
+ generateHealthyBowlAnalyticsReport(
15
+ context: $context
16
+ title: $title
17
+ type: $type
18
+ startDate: $startDate
19
+ endDate: $endDate
20
+ ) {
21
+ id
22
+ title
23
+ type
24
+ status
25
+ period
26
+ createdAt
27
+ }
28
+ }
29
+ `, c = i`
30
+ query GetHealthyBowlAnalyticsReportExport($context: ContextInput!, $reportId: ID!) {
31
+ getHealthyBowlAnalyticsReportExport(context: $context, reportId: $reportId) {
32
+ format
33
+ filename
34
+ mimeType
35
+ contentBase64
36
+ }
37
+ }
38
+ `, l = [{
39
+ value: "FINANCIAL",
40
+ labelKey: "healthybowl.analytics.reports.type.financial",
41
+ labelFallback: "Financial"
42
+ }, {
43
+ value: "CROP",
44
+ labelKey: "healthybowl.analytics.reports.type.crop",
45
+ labelFallback: "Crop"
46
+ }];
47
+ function u(e) {
48
+ return l.some((t) => t.value === e);
49
+ }
50
+ function d(e, t) {
51
+ if (typeof e == "object" && e) {
52
+ let t = e;
53
+ if (Array.isArray(t.errors) && t.errors.length > 0) {
54
+ let e = t.errors[0], n = e?.extensions?.userMessage;
55
+ if (typeof n == "string" && n.length > 0) return n;
56
+ if (typeof e?.message == "string" && e.message.length > 0) return e.message;
57
+ }
58
+ if (typeof t.message == "string" && t.message.length > 0) return t.message;
59
+ }
60
+ return t;
61
+ }
62
+ function f(e) {
63
+ let t = (e) => String(e).padStart(2, "0");
64
+ return `${e.getFullYear()}-${t(e.getMonth() + 1)}-${t(e.getDate())}`;
65
+ }
66
+ function p(e) {
67
+ return {
68
+ startDate: f(new Date(e.getFullYear(), 0, 1)),
69
+ endDate: f(e)
70
+ };
71
+ }
72
+ function m(e) {
73
+ let t = e.getFullYear(), n = Math.floor(e.getMonth() / 3), r = new Date(t, n * 3, 1), i = new Date(t, (n - 1) * 3, 1), a = new Date(t, n * 3, 0);
74
+ return [
75
+ {
76
+ value: "ytd",
77
+ labelKey: "healthybowl.financial.reports.generate.periods.ytd",
78
+ labelFallback: "Year to date",
79
+ startDate: f(new Date(t, 0, 1)),
80
+ endDate: f(e)
81
+ },
82
+ {
83
+ value: "this-quarter",
84
+ labelKey: "healthybowl.financial.reports.generate.periods.thisQuarter",
85
+ labelFallback: "This quarter",
86
+ startDate: f(r),
87
+ endDate: f(e)
88
+ },
89
+ {
90
+ value: "last-quarter",
91
+ labelKey: "healthybowl.financial.reports.generate.periods.lastQuarter",
92
+ labelFallback: "Last quarter",
93
+ startDate: f(i),
94
+ endDate: f(a)
95
+ },
96
+ {
97
+ value: "last-year",
98
+ labelKey: "healthybowl.financial.reports.generate.periods.lastYear",
99
+ labelFallback: "Last year",
100
+ startDate: f(new Date(t - 1, 0, 1)),
101
+ endDate: f(new Date(t - 1, 11, 31))
102
+ }
103
+ ];
104
+ }
105
+ function h() {
106
+ let { workspaceId: i } = e(), l = i || "00000000-0000-0000-0000-000000000001", u = a(), [f] = o(s), [m, h] = r(() => /* @__PURE__ */ new Set()), g = n(!1), _ = n(/* @__PURE__ */ new Set());
107
+ return {
108
+ generate: t(async (e) => {
109
+ if (g.current) return {
110
+ ok: !0,
111
+ started: !1
112
+ };
113
+ g.current = !0;
114
+ try {
115
+ let t = p(/* @__PURE__ */ new Date());
116
+ return await f({ variables: {
117
+ context: { workspaceId: l },
118
+ title: e.title,
119
+ type: e.type,
120
+ startDate: e.startDate ?? t.startDate,
121
+ endDate: e.endDate ?? t.endDate
122
+ } }), {
123
+ ok: !0,
124
+ started: !0
125
+ };
126
+ } catch (e) {
127
+ return {
128
+ ok: !1,
129
+ started: !0,
130
+ message: d(e, "The report could not be generated.")
131
+ };
132
+ } finally {
133
+ g.current = !1;
134
+ }
135
+ }, [f, l]),
136
+ download: t(async (e) => {
137
+ if (_.current.has(e)) return {
138
+ ok: !1,
139
+ message: "This report is already being prepared."
140
+ };
141
+ _.current.add(e), h(new Set(_.current));
142
+ try {
143
+ let { data: t } = await u.query({
144
+ query: c,
145
+ variables: {
146
+ context: { workspaceId: l },
147
+ reportId: e
148
+ },
149
+ fetchPolicy: "network-only"
150
+ }), n = t?.getHealthyBowlAnalyticsReportExport;
151
+ return n?.contentBase64 ? {
152
+ ok: !0,
153
+ payload: n
154
+ } : {
155
+ ok: !1,
156
+ message: "The report file could not be produced."
157
+ };
158
+ } catch (e) {
159
+ return {
160
+ ok: !1,
161
+ message: d(e, "The report could not be downloaded.")
162
+ };
163
+ } finally {
164
+ _.current.delete(e), h(new Set(_.current));
165
+ }
166
+ }, [u, l]),
167
+ downloadingIds: m
168
+ };
169
+ }
170
+ //#endregion
171
+ export { l as GENERATABLE_REPORT_TYPES, u as isGeneratableReportType, m as reportPeriodOptions, h as useAnalyticsReports };
172
+
173
+ //# sourceMappingURL=useAnalyticsReports.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAnalyticsReports.js","names":[],"sources":["../../../src/healthybowl/hooks/useAnalyticsReports.ts"],"sourcesContent":["/**\n * Generate and download analytics reports (BOFF-6022).\n *\n * Declared as inline `gql` documents rather than entries under `src/operations/`: these ops are\n * newer than the committed `graphql/wspace.graphql` snapshot that codegen validates against, and\n * this is the escape hatch the repo uses for exactly that case.\n *\n * @module healthybowl\n */\nimport { useCallback, useRef, useState } from 'react';\nimport { gql } from '@apollo/client';\nimport { useApolloClient, useMutation } from '@apollo/client/react';\nimport { HEALTHYBOWL_FALLBACK_WORKSPACE_ID, useHealthyBowl } from '../context/HealthyBowlContext';\n\nconst GENERATE_ANALYTICS_REPORT = gql`\n mutation GenerateHealthyBowlAnalyticsReport(\n $context: ContextInput!\n $title: String\n $type: String!\n $startDate: String!\n $endDate: String!\n ) {\n generateHealthyBowlAnalyticsReport(\n context: $context\n title: $title\n type: $type\n startDate: $startDate\n endDate: $endDate\n ) {\n id\n title\n type\n status\n period\n createdAt\n }\n }\n`;\n\nconst ANALYTICS_REPORT_EXPORT = gql`\n query GetHealthyBowlAnalyticsReportExport($context: ContextInput!, $reportId: ID!) {\n getHealthyBowlAnalyticsReportExport(context: $context, reportId: $reportId) {\n format\n filename\n mimeType\n contentBase64\n }\n }\n`;\n\n/** The report types the server can actually build today. */\nexport const GENERATABLE_REPORT_TYPES = [\n { value: 'FINANCIAL', labelKey: 'healthybowl.analytics.reports.type.financial', labelFallback: 'Financial' },\n { value: 'CROP', labelKey: 'healthybowl.analytics.reports.type.crop', labelFallback: 'Crop' },\n] as const;\n\nexport type GeneratableReportType = (typeof GENERATABLE_REPORT_TYPES)[number]['value'];\n\nexport function isGeneratableReportType(value: string): value is GeneratableReportType {\n return GENERATABLE_REPORT_TYPES.some((type) => type.value === value);\n}\n\n/**\n * Read the operator-facing message off a rejected operation.\n *\n * Apollo Client v4 rejects with `CombinedGraphQLErrors`, which has no v3 `graphQLErrors` property,\n * and the server puts the readable text in `extensions.userMessage` — for these ops that is the\n * sentence naming which report types CAN be generated. `err.message` alone would render Apollo's\n * aggregate wording and throw that away.\n */\nexport function readOperationError(err: unknown, fallback: string): string {\n if (err !== null && typeof err === 'object') {\n const shaped = err as { errors?: unknown; message?: unknown };\n if (Array.isArray(shaped.errors) && shaped.errors.length > 0) {\n const first = shaped.errors[0] as { message?: unknown; extensions?: { userMessage?: unknown } | null };\n const userMessage = first?.extensions?.userMessage;\n if (typeof userMessage === 'string' && userMessage.length > 0) return userMessage;\n if (typeof first?.message === 'string' && first.message.length > 0) return first.message;\n }\n if (typeof shaped.message === 'string' && shaped.message.length > 0) return shaped.message;\n }\n return fallback;\n}\n\n/**\n * `YYYY-MM-DD` in the farmer's OWN timezone.\n *\n * `toISOString().slice(0, 10)` would convert to UTC. For a farm in IST (UTC+5:30), any time between\n * midnight and 05:30 local yields the PREVIOUS day — so a report generated before dawn, which is\n * exactly when farm work happens, would silently end a day early. On 1 January it would compute\n * last year's 1 January as the start.\n */\nexport function toLocalDateString(date: Date): string {\n const pad = (n: number) => String(n).padStart(2, '0');\n return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`;\n}\n\n/**\n * A sensible default period for a newly requested report.\n *\n * Year to date rather than \"this month\": a farmer generating a report usually wants the season so\n * far, and an empty January report would be the first thing a new user sees.\n */\nexport function defaultReportPeriod(now: Date): { startDate: string; endDate: string } {\n return { startDate: toLocalDateString(new Date(now.getFullYear(), 0, 1)), endDate: toLocalDateString(now) };\n}\n\n/**\n * Real period choices, computed from today rather than hard-coded.\n *\n * The financial page shipped a picker offering \"Q1 2025\" / \"Q4 2024\" — fixed strings that were\n * already stale and would only get staler. Generating a \"Q1 2025\" report in 2026 is worse than\n * defaulting to year-to-date, so the options are derived.\n */\nexport interface ReportPeriodOption {\n value: string;\n labelKey: string;\n labelFallback: string;\n startDate: string;\n endDate: string;\n}\n\nexport function reportPeriodOptions(now: Date): ReportPeriodOption[] {\n const year = now.getFullYear();\n const quarter = Math.floor(now.getMonth() / 3);\n const quarterStart = new Date(year, quarter * 3, 1);\n const prevQuarterStart = new Date(year, (quarter - 1) * 3, 1);\n // Day 0 of the following month is the last day of this one — no month-length table, no leap-year\n // special case.\n const prevQuarterEnd = new Date(year, quarter * 3, 0);\n\n return [\n {\n value: 'ytd',\n labelKey: 'healthybowl.financial.reports.generate.periods.ytd',\n labelFallback: 'Year to date',\n startDate: toLocalDateString(new Date(year, 0, 1)),\n endDate: toLocalDateString(now),\n },\n {\n value: 'this-quarter',\n labelKey: 'healthybowl.financial.reports.generate.periods.thisQuarter',\n labelFallback: 'This quarter',\n startDate: toLocalDateString(quarterStart),\n endDate: toLocalDateString(now),\n },\n {\n value: 'last-quarter',\n labelKey: 'healthybowl.financial.reports.generate.periods.lastQuarter',\n labelFallback: 'Last quarter',\n startDate: toLocalDateString(prevQuarterStart),\n endDate: toLocalDateString(prevQuarterEnd),\n },\n {\n value: 'last-year',\n labelKey: 'healthybowl.financial.reports.generate.periods.lastYear',\n labelFallback: 'Last year',\n startDate: toLocalDateString(new Date(year - 1, 0, 1)),\n endDate: toLocalDateString(new Date(year - 1, 11, 31)),\n },\n ];\n}\n\ninterface GenerateInput {\n title: string;\n type: GeneratableReportType;\n startDate?: string;\n endDate?: string;\n}\n\nexport interface ExportPayload {\n format: string;\n filename: string;\n mimeType: string;\n contentBase64: string;\n}\n\nexport type GenerateResult =\n { ok: true; started: true } | { ok: true; started: false } | { ok: false; started: true; message: string };\nexport type DownloadResult = { ok: true; payload: ExportPayload } | { ok: false; message: string };\n\nexport function useAnalyticsReports(): {\n generate: (input: GenerateInput) => Promise<GenerateResult>;\n download: (reportId: string) => Promise<DownloadResult>;\n downloadingIds: ReadonlySet<string>;\n} {\n const { workspaceId } = useHealthyBowl();\n const effectiveWorkspaceId = workspaceId || HEALTHYBOWL_FALLBACK_WORKSPACE_ID;\n const client = useApolloClient();\n const [mutate] = useMutation(GENERATE_ANALYTICS_REPORT);\n const [downloadingIds, setDownloadingIds] = useState<ReadonlySet<string>>(() => new Set());\n // Both operations use refs to reject duplicate same-tick clicks before React has rendered the\n // consuming page's disabled button state.\n const generatingRef = useRef(false);\n const downloadingIdsRef = useRef(new Set<string>());\n\n const generate = useCallback(\n async (input: GenerateInput) => {\n if (generatingRef.current) return { ok: true, started: false } as const;\n generatingRef.current = true;\n try {\n const period = defaultReportPeriod(new Date());\n await mutate({\n variables: {\n context: { workspaceId: effectiveWorkspaceId },\n title: input.title,\n type: input.type,\n startDate: input.startDate ?? period.startDate,\n endDate: input.endDate ?? period.endDate,\n },\n });\n return { ok: true, started: true } as const;\n } catch (err) {\n return {\n ok: false,\n started: true,\n message: readOperationError(err, 'The report could not be generated.'),\n } as const;\n } finally {\n generatingRef.current = false;\n }\n },\n [mutate, effectiveWorkspaceId]\n );\n\n const download = useCallback(\n async (reportId: string) => {\n if (downloadingIdsRef.current.has(reportId)) {\n return { ok: false, message: 'This report is already being prepared.' } as const;\n }\n downloadingIdsRef.current.add(reportId);\n setDownloadingIds(new Set(downloadingIdsRef.current));\n try {\n const { data } = await client.query({\n query: ANALYTICS_REPORT_EXPORT,\n variables: { context: { workspaceId: effectiveWorkspaceId }, reportId },\n // Always refetched: a cached copy would hand back the previous report's bytes when the\n // farmer downloads a second one in the same session.\n fetchPolicy: 'network-only',\n });\n const payload = (data as { getHealthyBowlAnalyticsReportExport?: ExportPayload } | null)\n ?.getHealthyBowlAnalyticsReportExport;\n if (!payload?.contentBase64) {\n return { ok: false, message: 'The report file could not be produced.' } as const;\n }\n return { ok: true, payload } as const;\n } catch (err) {\n return { ok: false, message: readOperationError(err, 'The report could not be downloaded.') } as const;\n } finally {\n downloadingIdsRef.current.delete(reportId);\n setDownloadingIds(new Set(downloadingIdsRef.current));\n }\n },\n [client, effectiveWorkspaceId]\n );\n\n return { generate, download, downloadingIds };\n}\n"],"mappings":"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"}
@@ -0,0 +1,74 @@
1
+ import { useHealthyBowl as e } from "../context/HealthyBowlContext.js";
2
+ import { downloadBase64 as t } from "../utils/download.js";
3
+ import { useCallback as n, useMemo as r, useState as i } from "react";
4
+ import { gql as a } from "@apollo/client";
5
+ import { useLazyQuery as o } from "@apollo/client/react";
6
+ //#region src/healthybowl/hooks/useComplianceExports.ts
7
+ var s = "\n format\n filename\n mimeType\n contentBase64\n byteSize\n", c = a`
8
+ query GetHealthyBowlCompliancePack($context: ContextInput!) {
9
+ getHealthyBowlCompliancePack(context: $context) { ${s} }
10
+ }
11
+ `, l = a`
12
+ query GetHealthyBowlIcsGroupReport($context: ContextInput!, $icsGroupId: ID!) {
13
+ getHealthyBowlIcsGroupReport(context: $context, icsGroupId: $icsGroupId) { ${s} }
14
+ }
15
+ `;
16
+ function u(e, t) {
17
+ if (typeof e == "object" && e) {
18
+ let t = e;
19
+ if (Array.isArray(t.errors) && t.errors.length > 0) {
20
+ let e = t.errors[0], n = e?.extensions?.userMessage;
21
+ if (typeof n == "string" && n.length > 0) return n;
22
+ if (typeof e?.message == "string" && e.message.length > 0) return e.message;
23
+ }
24
+ if (typeof t.message == "string" && t.message.length > 0) return t.message;
25
+ }
26
+ return t;
27
+ }
28
+ function d() {
29
+ let { workspaceId: a } = e(), s = r(() => ({ workspaceId: a }), [a]), [d, f] = i(null), [p] = o(c, { fetchPolicy: "network-only" }), [m] = o(l, { fetchPolicy: "network-only" });
30
+ return {
31
+ exportCompliancePack: n(async () => {
32
+ f("pack");
33
+ try {
34
+ let { data: e } = await p({ variables: { context: s } }), n = e?.getHealthyBowlCompliancePack;
35
+ return n?.contentBase64 ? (t(n.contentBase64, n.filename, n.mimeType), { ok: !0 }) : {
36
+ ok: !1,
37
+ message: "The compliance pack came back empty. Please try again."
38
+ };
39
+ } catch (e) {
40
+ return {
41
+ ok: !1,
42
+ message: u(e, "The compliance pack could not be generated.")
43
+ };
44
+ } finally {
45
+ f(null);
46
+ }
47
+ }, [p, s]),
48
+ exportIcsGroupReport: n(async (e) => {
49
+ f("ics");
50
+ try {
51
+ let { data: n } = await m({ variables: {
52
+ context: s,
53
+ icsGroupId: e
54
+ } }), r = n?.getHealthyBowlIcsGroupReport;
55
+ return r?.contentBase64 ? (t(r.contentBase64, r.filename, r.mimeType), { ok: !0 }) : {
56
+ ok: !1,
57
+ message: "The group report came back empty. Please try again."
58
+ };
59
+ } catch (e) {
60
+ return {
61
+ ok: !1,
62
+ message: u(e, "The group report could not be generated.")
63
+ };
64
+ } finally {
65
+ f(null);
66
+ }
67
+ }, [m, s]),
68
+ exporting: d
69
+ };
70
+ }
71
+ //#endregion
72
+ export { d as useComplianceExports };
73
+
74
+ //# sourceMappingURL=useComplianceExports.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useComplianceExports.js","names":[],"sources":["../../../src/healthybowl/hooks/useComplianceExports.ts"],"sourcesContent":["/**\n * Audit evidence downloads (BOFF-6043).\n *\n * Two lazy queries: the compliance pack for the whole workspace, and the report for one ICS group.\n * Lazy rather than eager because both render a PDF server-side — running them on every page load\n * would burn a document nobody asked for.\n *\n * Inline `gql` rather than an entry under `src/operations/`: these ops are newer than the committed\n * `graphql/wspace.graphql` snapshot codegen validates against, which is the escape hatch documented\n * in `useHealthyBowlAccounting.ts`'s header.\n *\n * @module healthybowl\n */\nimport { useCallback, useMemo, useState } from 'react';\nimport { gql } from '@apollo/client';\nimport { useLazyQuery } from '@apollo/client/react';\nimport { useHealthyBowl } from '../context/HealthyBowlContext';\nimport { downloadBase64 } from '../utils/download';\n\nexport interface ComplianceExportFile {\n format: string;\n filename: string;\n mimeType: string;\n contentBase64: string;\n byteSize: number;\n}\n\nconst EXPORT_FIELDS = `\n format\n filename\n mimeType\n contentBase64\n byteSize\n`;\n\nconst COMPLIANCE_PACK_QUERY = gql`\n query GetHealthyBowlCompliancePack($context: ContextInput!) {\n getHealthyBowlCompliancePack(context: $context) { ${EXPORT_FIELDS} }\n }\n`;\n\nconst ICS_GROUP_REPORT_QUERY = gql`\n query GetHealthyBowlIcsGroupReport($context: ContextInput!, $icsGroupId: ID!) {\n getHealthyBowlIcsGroupReport(context: $context, icsGroupId: $icsGroupId) { ${EXPORT_FIELDS} }\n }\n`;\n\n/**\n * Read the operator-facing message off a rejected export.\n *\n * Apollo v4 rejects with `CombinedGraphQLErrors`, which has no v3 `graphQLErrors` property, so\n * `err.message` alone renders the aggregate wording and throws the server's instruction away.\n */\nfunction readExportError(err: unknown, fallback: string): string {\n if (err !== null && typeof err === 'object') {\n const shaped = err as { errors?: unknown; message?: unknown };\n if (Array.isArray(shaped.errors) && shaped.errors.length > 0) {\n const first = shaped.errors[0] as { message?: unknown; extensions?: { userMessage?: unknown } | null };\n const userMessage = first?.extensions?.userMessage;\n if (typeof userMessage === 'string' && userMessage.length > 0) return userMessage;\n if (typeof first?.message === 'string' && first.message.length > 0) return first.message;\n }\n if (typeof shaped.message === 'string' && shaped.message.length > 0) return shaped.message;\n }\n return fallback;\n}\n\ntype Result = { ok: true } | { ok: false; message: string };\n\nexport function useComplianceExports(): {\n exportCompliancePack: () => Promise<Result>;\n exportIcsGroupReport: (icsGroupId: string) => Promise<Result>;\n /** Which export is in flight, so a page can disable just the button that was pressed. */\n exporting: 'pack' | 'ics' | null;\n} {\n const { workspaceId } = useHealthyBowl();\n const context = useMemo(() => ({ workspaceId }), [workspaceId]);\n const [exporting, setExporting] = useState<'pack' | 'ics' | null>(null);\n\n const [fetchPack] = useLazyQuery<{ getHealthyBowlCompliancePack?: ComplianceExportFile }>(COMPLIANCE_PACK_QUERY, {\n // A pack must reflect the checklist as it stands right now — an audit bundle served from cache\n // is exactly the stale evidence this feature exists to stop people assembling.\n fetchPolicy: 'network-only',\n });\n const [fetchIcsReport] = useLazyQuery<{ getHealthyBowlIcsGroupReport?: ComplianceExportFile }>(\n ICS_GROUP_REPORT_QUERY,\n { fetchPolicy: 'network-only' }\n );\n\n const exportCompliancePack = useCallback(async (): Promise<Result> => {\n setExporting('pack');\n try {\n const { data } = await fetchPack({ variables: { context } });\n const file = data?.getHealthyBowlCompliancePack;\n if (!file?.contentBase64) {\n return { ok: false, message: 'The compliance pack came back empty. Please try again.' };\n }\n downloadBase64(file.contentBase64, file.filename, file.mimeType);\n return { ok: true };\n } catch (err) {\n return { ok: false, message: readExportError(err, 'The compliance pack could not be generated.') };\n } finally {\n setExporting(null);\n }\n }, [fetchPack, context]);\n\n const exportIcsGroupReport = useCallback(\n async (icsGroupId: string): Promise<Result> => {\n setExporting('ics');\n try {\n const { data } = await fetchIcsReport({ variables: { context, icsGroupId } });\n const file = data?.getHealthyBowlIcsGroupReport;\n if (!file?.contentBase64) {\n return { ok: false, message: 'The group report came back empty. Please try again.' };\n }\n downloadBase64(file.contentBase64, file.filename, file.mimeType);\n return { ok: true };\n } catch (err) {\n return { ok: false, message: readExportError(err, 'The group report could not be generated.') };\n } finally {\n setExporting(null);\n }\n },\n [fetchIcsReport, context]\n );\n\n return { exportCompliancePack, exportIcsGroupReport, exporting };\n}\n"],"mappings":";;;;;;AA2BA,IAAM,IAAgB,qEAQhB,IAAwB,CAAG;;wDAEuB,EAAc;;GAIhE,IAAyB,CAAG;;iFAE+C,EAAc;;;AAU/F,SAAS,EAAgB,GAAc,GAA0B;CAC/D,IAAoB,OAAO,KAAQ,YAA/B,GAAyC;EAC3C,IAAM,IAAS;EACf,IAAI,MAAM,QAAQ,EAAO,MAAM,KAAK,EAAO,OAAO,SAAS,GAAG;GAC5D,IAAM,IAAQ,EAAO,OAAO,IACtB,IAAc,GAAO,YAAY;GACvC,IAAI,OAAO,KAAgB,YAAY,EAAY,SAAS,GAAG,OAAO;GACtE,IAAI,OAAO,GAAO,WAAY,YAAY,EAAM,QAAQ,SAAS,GAAG,OAAO,EAAM;EACnF;EACA,IAAI,OAAO,EAAO,WAAY,YAAY,EAAO,QAAQ,SAAS,GAAG,OAAO,EAAO;CACrF;CACA,OAAO;AACT;AAIA,SAAgB,IAKd;CACA,IAAM,EAAE,mBAAgB,EAAe,GACjC,IAAU,SAAe,EAAE,eAAY,IAAI,CAAC,CAAW,CAAC,GACxD,CAAC,GAAW,KAAgB,EAAgC,IAAI,GAEhE,CAAC,KAAa,EAAsE,GAAuB,EAG/G,aAAa,eACf,CAAC,GACK,CAAC,KAAkB,EACvB,GACA,EAAE,aAAa,eAAe,CAChC;CAuCA,OAAO;EAAE,sBArCoB,EAAY,YAA6B;GACpE,EAAa,MAAM;GACnB,IAAI;IACF,IAAM,EAAE,YAAS,MAAM,EAAU,EAAE,WAAW,EAAE,WAAQ,EAAE,CAAC,GACrD,IAAO,GAAM;IAKnB,OAJK,GAAM,iBAGX,EAAe,EAAK,eAAe,EAAK,UAAU,EAAK,QAAQ,GACxD,EAAE,IAAI,GAAK,KAHT;KAAE,IAAI;KAAO,SAAS;IAAyD;GAI1F,SAAS,GAAK;IACZ,OAAO;KAAE,IAAI;KAAO,SAAS,EAAgB,GAAK,6CAA6C;IAAE;GACnG,UAAU;IACR,EAAa,IAAI;GACnB;EACF,GAAG,CAAC,GAAW,CAAO,CAsBb;EAAsB,sBApBF,EAC3B,OAAO,MAAwC;GAC7C,EAAa,KAAK;GAClB,IAAI;IACF,IAAM,EAAE,YAAS,MAAM,EAAe,EAAE,WAAW;KAAE;KAAS;IAAW,EAAE,CAAC,GACtE,IAAO,GAAM;IAKnB,OAJK,GAAM,iBAGX,EAAe,EAAK,eAAe,EAAK,UAAU,EAAK,QAAQ,GACxD,EAAE,IAAI,GAAK,KAHT;KAAE,IAAI;KAAO,SAAS;IAAsD;GAIvF,SAAS,GAAK;IACZ,OAAO;KAAE,IAAI;KAAO,SAAS,EAAgB,GAAK,0CAA0C;IAAE;GAChG,UAAU;IACR,EAAa,IAAI;GACnB;EACF,GACA,CAAC,GAAgB,CAAO,CAGK;EAAsB;CAAU;AACjE"}
@@ -0,0 +1,59 @@
1
+ import { loadRazorpayCheckout as e } from "./useOrderPayments.js";
2
+ import { useCallback as t, useMemo as n } from "react";
3
+ import { gql as r } from "@apollo/client";
4
+ import { useMutation as i } from "@apollo/client/react";
5
+ //#region src/healthybowl/hooks/useConsultationPayments.ts
6
+ var a = r`
7
+ mutation CheckoutHealthyBowlConsultation($consultationId: ID!, $context: ContextInput!) {
8
+ checkoutHealthyBowlConsultation(consultationId: $consultationId, context: $context) {
9
+ consultationId
10
+ billingOrderId
11
+ provider
12
+ providerOrderId
13
+ razorpayKeyId
14
+ clientSecret
15
+ subtotal
16
+ taxAmount
17
+ total
18
+ currency
19
+ }
20
+ }
21
+ `, o = r`
22
+ mutation SyncHealthyBowlConsultationPayment($consultationId: ID!, $context: ContextInput!) {
23
+ syncHealthyBowlConsultationPayment(consultationId: $consultationId, context: $context) {
24
+ id
25
+ status
26
+ paymentStatus
27
+ paymentProvider
28
+ paymentReference
29
+ paidAmount
30
+ paidAt
31
+ }
32
+ }
33
+ `;
34
+ function s() {
35
+ let r = n(() => ({}), []), [s] = i(a), [c] = i(o);
36
+ return {
37
+ checkoutConsultation: t(async (e) => {
38
+ let t = (await s({ variables: {
39
+ consultationId: e,
40
+ context: r
41
+ } })).data?.checkoutHealthyBowlConsultation;
42
+ if (!t) throw Error("Checkout did not return a payment session");
43
+ return t;
44
+ }, [s, r]),
45
+ syncConsultationPayment: t(async (e) => {
46
+ let t = (await c({ variables: {
47
+ consultationId: e,
48
+ context: r
49
+ } })).data?.syncHealthyBowlConsultationPayment;
50
+ if (!t) throw Error("Payment sync did not return the consultation");
51
+ return t;
52
+ }, [r, c]),
53
+ loadRazorpay: e
54
+ };
55
+ }
56
+ //#endregion
57
+ export { s as useConsultationPayments };
58
+
59
+ //# sourceMappingURL=useConsultationPayments.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useConsultationPayments.js","names":[],"sources":["../../../src/healthybowl/hooks/useConsultationPayments.ts"],"sourcesContent":["/**\n * Real expert-consultation payments (BOFF-6030, slice B).\n *\n * The client starts checkout and asks HealthyBowl to settle afterwards. HealthyBowl re-reads the\n * authoritative Payment from global-billing, so this MFE never decides that money arrived or handles\n * card data. The documents stay inline because the committed workspace SDL snapshot predates these\n * operations; adding them under `src/operations/wspace` would make codegen validate them too early.\n */\nimport { gql } from '@apollo/client';\nimport { useMutation } from '@apollo/client/react';\nimport { useCallback, useMemo } from 'react';\nimport type { Consultation } from '../types';\nimport { loadRazorpayCheckout } from './useOrderPayments';\n\n/** Everything the client needs to open the payment provider's checkout for one consultation. */\nexport interface ConsultationCheckout {\n consultationId: string;\n billingOrderId: string;\n /** RAZORPAY / STRIPE — selected by platform billing. */\n provider: string;\n /** Razorpay `order_xxx`; absent when billing routes to another provider. */\n providerOrderId?: string | null;\n /** Publishable Razorpay key returned at runtime by billing, never hard-coded. */\n razorpayKeyId?: string | null;\n /** Stripe client secret; this MFE does not implement the Stripe checkout path yet. */\n clientSecret?: string | null;\n subtotal: number;\n taxAmount: number;\n total: number;\n currency: string;\n}\n\n/** Payment details mirrored by HealthyBowl only after it settles against platform billing. */\nexport type ConsultationPayment = Pick<\n Consultation,\n 'id' | 'status' | 'paymentStatus' | 'paymentProvider' | 'paymentReference' | 'paidAmount' | 'paidAt'\n>;\n\nconst CHECKOUT_CONSULTATION = gql`\n mutation CheckoutHealthyBowlConsultation($consultationId: ID!, $context: ContextInput!) {\n checkoutHealthyBowlConsultation(consultationId: $consultationId, context: $context) {\n consultationId\n billingOrderId\n provider\n providerOrderId\n razorpayKeyId\n clientSecret\n subtotal\n taxAmount\n total\n currency\n }\n }\n`;\n\nconst SYNC_CONSULTATION_PAYMENT = gql`\n mutation SyncHealthyBowlConsultationPayment($consultationId: ID!, $context: ContextInput!) {\n syncHealthyBowlConsultationPayment(consultationId: $consultationId, context: $context) {\n id\n status\n paymentStatus\n paymentProvider\n paymentReference\n paidAmount\n paidAt\n }\n }\n`;\n\ninterface CheckoutConsultationData {\n checkoutHealthyBowlConsultation: ConsultationCheckout;\n}\n\ninterface SyncConsultationPaymentData {\n syncHealthyBowlConsultationPayment: ConsultationPayment;\n}\n\ninterface ConsultationCheckoutVariables {\n consultationId: string;\n context: Record<string, never>;\n}\n\ninterface SyncConsultationPaymentVariables {\n consultationId: string;\n context: Record<string, never>;\n}\n\n/**\n * Starts idempotent platform-billing checkout sessions and settles their authoritative result.\n * `loadRazorpay` deliberately delegates to the shared lazy script loader, so marketplace and\n * consultation checkout inject at most one provider script per page.\n */\nexport function useConsultationPayments() {\n // Wspace identity is gateway-authoritative; this required GraphQL input intentionally carries no\n // client-held workspace id.\n const context = useMemo<Record<string, never>>(() => ({}), []);\n const [checkoutMutation] = useMutation<CheckoutConsultationData, ConsultationCheckoutVariables>(\n CHECKOUT_CONSULTATION\n );\n const [syncMutation] = useMutation<SyncConsultationPaymentData, SyncConsultationPaymentVariables>(\n SYNC_CONSULTATION_PAYMENT\n );\n\n const checkoutConsultation = useCallback(\n async (consultationId: string): Promise<ConsultationCheckout> => {\n const result = await checkoutMutation({ variables: { consultationId, context } });\n const checkout = result.data?.checkoutHealthyBowlConsultation;\n if (!checkout) throw new Error('Checkout did not return a payment session');\n return checkout;\n },\n [checkoutMutation, context]\n );\n\n const syncConsultationPayment = useCallback(\n async (consultationId: string): Promise<ConsultationPayment> => {\n const result = await syncMutation({ variables: { consultationId, context } });\n const consultation = result.data?.syncHealthyBowlConsultationPayment;\n if (!consultation) throw new Error('Payment sync did not return the consultation');\n return consultation;\n },\n [context, syncMutation]\n );\n\n const loadRazorpay = loadRazorpayCheckout;\n\n return { checkoutConsultation, syncConsultationPayment, loadRazorpay };\n}\n"],"mappings":";;;;;AAsCA,IAAM,IAAwB,CAAG;;;;;;;;;;;;;;;GAiB3B,IAA4B,CAAG;;;;;;;;;;;;;AAqCrC,SAAgB,IAA0B;CAGxC,IAAM,IAAU,SAAsC,CAAC,IAAI,CAAC,CAAC,GACvD,CAAC,KAAoB,EACzB,CACF,GACM,CAAC,KAAgB,EACrB,CACF;CAwBA,OAAO;EAAE,sBAtBoB,EAC3B,OAAO,MAA0D;GAE/D,IAAM,KAAW,MADI,EAAiB,EAAE,WAAW;IAAE;IAAgB;GAAQ,EAAE,CAAC,GACxD,MAAM;GAC9B,IAAI,CAAC,GAAU,MAAU,MAAM,2CAA2C;GAC1E,OAAO;EACT,GACA,CAAC,GAAkB,CAAO,CAenB;EAAsB,yBAZC,EAC9B,OAAO,MAAyD;GAE9D,IAAM,KAAe,MADA,EAAa,EAAE,WAAW;IAAE;IAAgB;GAAQ,EAAE,CAAC,GAChD,MAAM;GAClC,IAAI,CAAC,GAAc,MAAU,MAAM,8CAA8C;GACjF,OAAO;EACT,GACA,CAAC,GAAS,CAAY,CAKO;EAAyB,cAAA;CAAa;AACvE"}