@burdenoff/microfe-healthybowl 2026.1008.1 → 2026.1009.1

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.
@@ -1,13 +1,14 @@
1
+ import { normaliseRecordName as e } from "@burdenoff/fe-libs/shared/assistant/uiActions/recordNames";
1
2
  //#region src/components/assistant/recordAdapters.ts
2
- var e = "\n query AssistantFindAnimals($context: ContextInput!) {\n getHealthyBowlLivestockData(context: $context) {\n animals { id name tagNumber }\n }\n }\n", t = "\n query AssistantFindListings($context: ContextInput!) {\n getHealthyBowlMarketplaceData(context: $context) {\n marketplaceProducts { id name }\n }\n }\n", n = {
3
+ var t = "\n query AssistantFindAnimals($context: ContextInput!) {\n getHealthyBowlLivestockData(context: $context) {\n animals { id name tagNumber }\n }\n }\n", n = "\n query AssistantFindListings($context: ContextInput!) {\n getHealthyBowlMarketplaceData(context: $context) {\n marketplaceProducts { id name }\n }\n }\n", r = {
3
4
  graphqlFetch: async (e) => (await import("@burdenoff/fe-libs/shared/graphql")).graphqlFetch(e),
4
5
  getWorkspaceId: async () => (await import("@burdenoff/fe-libs/shared/graphql")).getStoredWorkspaceId()
5
- }, r = (e) => typeof e == "string" && e.trim().length > 0 ? e.trim() : null, i = (e) => e.normalize("NFKC").toLowerCase().replace(/[^\p{L}\p{N}\s]/gu, " ").replace(/\s+/g, " ").trim();
6
- function a(e, t) {
7
- let n = i(e);
8
- if (!n) return !1;
9
- let r = i(t).split(" ");
10
- return n.split(" ").every((e) => r.some((t) => t.startsWith(e)));
6
+ }, i = (e) => typeof e == "string" && e.trim().length > 0 ? e.trim() : null;
7
+ function a(t, n) {
8
+ let r = e(t);
9
+ if (!r) return !1;
10
+ let i = e(n).split(" ");
11
+ return r.split(" ").every((e) => i.some((t) => t.startsWith(e)));
11
12
  }
12
13
  async function o(e, t, n, r, i, o, s, c) {
13
14
  let l = await e.getWorkspaceId();
@@ -37,7 +38,7 @@ async function o(e, t, n, r, i, o, s, c) {
37
38
  }
38
39
  return f;
39
40
  }
40
- function s(i = n) {
41
+ function s(e = r) {
41
42
  return [{
42
43
  id: "healthybowl-animal",
43
44
  nouns: ["animal", "animals"],
@@ -46,7 +47,7 @@ function s(i = n) {
46
47
  fallback: "animal"
47
48
  },
48
49
  entityRouteId: "healthybowl-animal",
49
- find: (t, n) => o(i, e, "AssistantFindAnimals", "getHealthyBowlLivestockData", "animals", t, n, (e) => r(e.name) ?? r(e.tagNumber))
50
+ find: (n, r) => o(e, t, "AssistantFindAnimals", "getHealthyBowlLivestockData", "animals", n, r, (e) => i(e.name) ?? i(e.tagNumber))
50
51
  }, {
51
52
  id: "healthybowl-listing",
52
53
  nouns: [
@@ -62,7 +63,7 @@ function s(i = n) {
62
63
  fallback: "marketplace listing"
63
64
  },
64
65
  entityRouteId: "healthybowl-listing",
65
- find: (e, n) => o(i, t, "AssistantFindListings", "getHealthyBowlMarketplaceData", "marketplaceProducts", e, n, (e) => r(e.name))
66
+ find: (t, r) => o(e, n, "AssistantFindListings", "getHealthyBowlMarketplaceData", "marketplaceProducts", t, r, (e) => i(e.name))
66
67
  }];
67
68
  }
68
69
  var c = s();
@@ -1 +1 @@
1
- {"version":3,"file":"recordAdapters.js","names":[],"sources":["../../../src/components/assistant/recordAdapters.ts"],"sourcesContent":["/**\n * HealthyBowl's named-record adapters for the shared assistant (BOFF-8060 N1b):\n * \"open Bella the cow\", \"open the organic tomatoes listing\".\n *\n * Two kinds, chosen because the product's own pages already read them and because\n * neither sits in the crop / field / catalog area that BOFF-7151 is changing:\n * - animals, from `getHealthyBowlLivestockData` (the Animal Registry's read);\n * - marketplace listings, from `getHealthyBowlMarketplaceData` (the Marketplace read).\n * Crops, fields, plans and harvests are deliberately NOT adapted here.\n *\n * An adapter only LOOKS A RECORD UP BY NAME, as the signed-in person: the workspace\n * token is theirs and the gateway's `@rbac` decides what the read returns. It\n * produces route params, never a path: fe-libs fills the entity route declared in\n * `assistantProductOptions.ts` (`ENTITY_ROUTES`), re-validates it, and only for a\n * person who can see the route's sidebar entry.\n *\n * ★ Neither read has a name search, so the adapter selects only id + name (the\n * existing queries select far more) and matches the name HERE. It must filter\n * itself: fe-libs caps what an adapter may return.\n *\n * ★★ A LEAF like `assistantProductOptions.ts`, which imports this: the fe-libs\n * graphql module is loaded lazily, on the first lookup, never at import time.\n *\n * ★ Nothing here writes, opens a form, or touches the DOM.\n */\nimport type {\n AssistantRecordAdapter,\n AssistantRecordMatch,\n} from '@burdenoff/fe-libs/shared/assistant/uiActions/recordNames';\nimport type { graphqlFetch as GraphqlFetch } from '@burdenoff/fe-libs/shared/graphql';\n\nexport const LIST_ANIMALS_FOR_ASSISTANT = `\n query AssistantFindAnimals($context: ContextInput!) {\n getHealthyBowlLivestockData(context: $context) {\n animals { id name tagNumber }\n }\n }\n`;\n\nexport const LIST_LISTINGS_FOR_ASSISTANT = `\n query AssistantFindListings($context: ContextInput!) {\n getHealthyBowlMarketplaceData(context: $context) {\n marketplaceProducts { id name }\n }\n }\n`;\n\n/** The two things the adapters need from the app; injectable so tests run without a network. */\nexport interface RecordAdapterDeps {\n graphqlFetch: typeof GraphqlFetch;\n getWorkspaceId: () => string | null | Promise<string | null>;\n}\nconst LIVE_DEPS: RecordAdapterDeps = {\n graphqlFetch: async (options) => (await import('@burdenoff/fe-libs/shared/graphql')).graphqlFetch(options),\n getWorkspaceId: async () => (await import('@burdenoff/fe-libs/shared/graphql')).getStoredWorkspaceId(),\n};\n\ninterface RawRow {\n id?: unknown;\n name?: unknown;\n tagNumber?: unknown;\n}\n\nconst text = (value: unknown): string | null =>\n typeof value === 'string' && value.trim().length > 0 ? value.trim() : null;\n\nconst normalise = (value: string): string =>\n value\n .normalize('NFKC')\n .toLowerCase()\n .replace(/[^\\p{L}\\p{N}\\s]/gu, ' ')\n .replace(/\\s+/g, ' ')\n .trim();\n\n/** Every word said is the start of a word in the name (the rule fe-libs plans with). */\nexport function nameFits(said: string, name: string): boolean {\n const wanted = normalise(said);\n if (!wanted) return false;\n const words = normalise(name).split(' ');\n return wanted.split(' ').every((word) => words.some((candidate) => candidate.startsWith(word)));\n}\n\nasync function findByName(\n deps: RecordAdapterDeps,\n query: string,\n operationName: string,\n field: string,\n rowsKey: string,\n name: string,\n signal: AbortSignal,\n label: (row: RawRow) => string | null\n): Promise<readonly AssistantRecordMatch[]> {\n const workspaceId = await deps.getWorkspaceId();\n if (!workspaceId) return [];\n const result = await deps.graphqlFetch<Record<string, Record<string, unknown> | null | undefined>>({\n gateway: 'workspace',\n query,\n operationName,\n variables: { context: { workspaceId } },\n // The person's own workspace token, minted for THIS workspace.\n workspaceToken: true,\n workspaceId,\n organizationId: true,\n signal,\n suppressGlobalErrorEvent: true,\n });\n if (result.errors?.length) return [];\n const rows = result.data?.[field]?.[rowsKey];\n if (!Array.isArray(rows)) return [];\n const matches: AssistantRecordMatch[] = [];\n for (const row of rows as Array<RawRow | null>) {\n if (!row || typeof row.id !== 'string' || row.id.length === 0) continue;\n const shown = label(row);\n if (shown === null || !nameFits(name, shown)) continue;\n matches.push({ params: { id: row.id }, name: shown });\n }\n return matches;\n}\n\nexport function createHealthyBowlRecordAdapters(\n deps: RecordAdapterDeps = LIVE_DEPS\n): readonly AssistantRecordAdapter[] {\n const animals: AssistantRecordAdapter = {\n id: 'healthybowl-animal',\n nouns: ['animal', 'animals'],\n noun: { key: 'entity.animal', fallback: 'animal' },\n entityRouteId: 'healthybowl-animal',\n find: (name, signal) =>\n findByName(\n deps,\n LIST_ANIMALS_FOR_ASSISTANT,\n 'AssistantFindAnimals',\n 'getHealthyBowlLivestockData',\n 'animals',\n name,\n signal,\n // An animal with no name is called by its tag.\n (row) => text(row.name) ?? text(row.tagNumber)\n ),\n };\n const listings: AssistantRecordAdapter = {\n id: 'healthybowl-listing',\n nouns: ['listing', 'listings', 'marketplace listing', 'marketplace listings', 'product', 'products'],\n noun: { key: 'entity.listing', fallback: 'marketplace listing' },\n entityRouteId: 'healthybowl-listing',\n find: (name, signal) =>\n findByName(\n deps,\n LIST_LISTINGS_FOR_ASSISTANT,\n 'AssistantFindListings',\n 'getHealthyBowlMarketplaceData',\n 'marketplaceProducts',\n name,\n signal,\n (row) => text(row.name)\n ),\n };\n return [animals, listings];\n}\n\nexport const HEALTHYBOWL_RECORD_ADAPTERS: readonly AssistantRecordAdapter[] = createHealthyBowlRecordAdapters();\n"],"mappings":";AA+BA,IAAa,IAA6B,sKAQ7B,IAA8B,2KAarC,IAA+B;CACnC,cAAc,OAAO,OAAa,MAAM,OAAO,sCAAsC,aAAa,CAAO;CACzG,gBAAgB,aAAa,MAAM,OAAO,sCAAsC,qBAAqB;AACvG,GAQM,KAAQ,MACZ,OAAO,KAAU,YAAY,EAAM,KAAK,EAAE,SAAS,IAAI,EAAM,KAAK,IAAI,MAElE,KAAa,MACjB,EACG,UAAU,MAAM,EAChB,YAAY,EACZ,QAAQ,qBAAqB,GAAG,EAChC,QAAQ,QAAQ,GAAG,EACnB,KAAK;AAGV,SAAgB,EAAS,GAAc,GAAuB;CAC5D,IAAM,IAAS,EAAU,CAAI;CAC7B,IAAI,CAAC,GAAQ,OAAO;CACpB,IAAM,IAAQ,EAAU,CAAI,EAAE,MAAM,GAAG;CACvC,OAAO,EAAO,MAAM,GAAG,EAAE,OAAO,MAAS,EAAM,MAAM,MAAc,EAAU,WAAW,CAAI,CAAC,CAAC;AAChG;AAEA,eAAe,EACb,GACA,GACA,GACA,GACA,GACA,GACA,GACA,GAC0C;CAC1C,IAAM,IAAc,MAAM,EAAK,eAAe;CAC9C,IAAI,CAAC,GAAa,OAAO,CAAC;CAC1B,IAAM,IAAS,MAAM,EAAK,aAAyE;EACjG,SAAS;EACT;EACA;EACA,WAAW,EAAE,SAAS,EAAE,eAAY,EAAE;EAEtC,gBAAgB;EAChB;EACA,gBAAgB;EAChB;EACA,0BAA0B;CAC5B,CAAC;CACD,IAAI,EAAO,QAAQ,QAAQ,OAAO,CAAC;CACnC,IAAM,IAAO,EAAO,OAAO,KAAS;CACpC,IAAI,CAAC,MAAM,QAAQ,CAAI,GAAG,OAAO,CAAC;CAClC,IAAM,IAAkC,CAAC;CACzC,KAAK,IAAM,KAAO,GAA8B;EAC9C,IAAI,CAAC,KAAO,OAAO,EAAI,MAAO,YAAY,EAAI,GAAG,WAAW,GAAG;EAC/D,IAAM,IAAQ,EAAM,CAAG;EACnB,MAAU,QAAQ,CAAC,EAAS,GAAM,CAAK,KAC3C,EAAQ,KAAK;GAAE,QAAQ,EAAE,IAAI,EAAI,GAAG;GAAG,MAAM;EAAM,CAAC;CACtD;CACA,OAAO;AACT;AAEA,SAAgB,EACd,IAA0B,GACS;CAoCnC,OAAO,CAAC;EAlCN,IAAI;EACJ,OAAO,CAAC,UAAU,SAAS;EAC3B,MAAM;GAAE,KAAK;GAAiB,UAAU;EAAS;EACjD,eAAe;EACf,OAAO,GAAM,MACX,EACE,GACA,GACA,wBACA,+BACA,WACA,GACA,IAEC,MAAQ,EAAK,EAAI,IAAI,KAAK,EAAK,EAAI,SAAS,CAC/C;CAmBI,GAAS;EAhBf,IAAI;EACJ,OAAO;GAAC;GAAW;GAAY;GAAuB;GAAwB;GAAW;EAAU;EACnG,MAAM;GAAE,KAAK;GAAkB,UAAU;EAAsB;EAC/D,eAAe;EACf,OAAO,GAAM,MACX,EACE,GACA,GACA,yBACA,iCACA,uBACA,GACA,IACC,MAAQ,EAAK,EAAI,IAAI,CACxB;CAEa,CAAQ;AAC3B;AAEA,IAAa,IAAiE,EAAgC"}
1
+ {"version":3,"file":"recordAdapters.js","names":[],"sources":["../../../src/components/assistant/recordAdapters.ts"],"sourcesContent":["/**\n * HealthyBowl's named-record adapters for the shared assistant (BOFF-8060 N1b):\n * \"open Bella the cow\", \"open the organic tomatoes listing\".\n *\n * Two kinds, chosen because the product's own pages already read them and because\n * neither sits in the crop / field / catalog area that BOFF-7151 is changing:\n * - animals, from `getHealthyBowlLivestockData` (the Animal Registry's read);\n * - marketplace listings, from `getHealthyBowlMarketplaceData` (the Marketplace read).\n * Crops, fields, plans and harvests are deliberately NOT adapted here.\n *\n * An adapter only LOOKS A RECORD UP BY NAME, as the signed-in person: the workspace\n * token is theirs and the gateway's `@rbac` decides what the read returns. It\n * produces route params, never a path: fe-libs fills the entity route declared in\n * `assistantProductOptions.ts` (`ENTITY_ROUTES`), re-validates it, and only for a\n * person who can see the route's sidebar entry.\n *\n * ★ Neither read has a name search, so the adapter selects only id + name (the\n * existing queries select far more) and matches the name HERE. It must filter\n * itself: fe-libs caps what an adapter may return.\n *\n * ★★ A LEAF like `assistantProductOptions.ts`, which imports this: the fe-libs\n * graphql module is loaded lazily, on the first lookup, never at import time.\n *\n * ★ Nothing here writes, opens a form, or touches the DOM.\n */\nimport { normaliseRecordName } from '@burdenoff/fe-libs/shared/assistant/uiActions/recordNames';\nimport type {\n AssistantRecordAdapter,\n AssistantRecordMatch,\n} from '@burdenoff/fe-libs/shared/assistant/uiActions/recordNames';\nimport type { graphqlFetch as GraphqlFetch } from '@burdenoff/fe-libs/shared/graphql';\n\nexport const LIST_ANIMALS_FOR_ASSISTANT = `\n query AssistantFindAnimals($context: ContextInput!) {\n getHealthyBowlLivestockData(context: $context) {\n animals { id name tagNumber }\n }\n }\n`;\n\nexport const LIST_LISTINGS_FOR_ASSISTANT = `\n query AssistantFindListings($context: ContextInput!) {\n getHealthyBowlMarketplaceData(context: $context) {\n marketplaceProducts { id name }\n }\n }\n`;\n\n/** The two things the adapters need from the app; injectable so tests run without a network. */\nexport interface RecordAdapterDeps {\n graphqlFetch: typeof GraphqlFetch;\n getWorkspaceId: () => string | null | Promise<string | null>;\n}\nconst LIVE_DEPS: RecordAdapterDeps = {\n graphqlFetch: async (options) => (await import('@burdenoff/fe-libs/shared/graphql')).graphqlFetch(options),\n getWorkspaceId: async () => (await import('@burdenoff/fe-libs/shared/graphql')).getStoredWorkspaceId(),\n};\n\ninterface RawRow {\n id?: unknown;\n name?: unknown;\n tagNumber?: unknown;\n}\n\nconst text = (value: unknown): string | null =>\n typeof value === 'string' && value.trim().length > 0 ? value.trim() : null;\n\n/** Every word said is the start of a word in the name (the rule fe-libs plans with). */\nexport function nameFits(said: string, name: string): boolean {\n // Use the command parser's canonical form: '&' means 'and', and vowel marks stay intact.\n const wanted = normaliseRecordName(said);\n if (!wanted) return false;\n const words = normaliseRecordName(name).split(' ');\n return wanted.split(' ').every((word) => words.some((candidate) => candidate.startsWith(word)));\n}\n\nasync function findByName(\n deps: RecordAdapterDeps,\n query: string,\n operationName: string,\n field: string,\n rowsKey: string,\n name: string,\n signal: AbortSignal,\n label: (row: RawRow) => string | null\n): Promise<readonly AssistantRecordMatch[]> {\n const workspaceId = await deps.getWorkspaceId();\n if (!workspaceId) return [];\n const result = await deps.graphqlFetch<Record<string, Record<string, unknown> | null | undefined>>({\n gateway: 'workspace',\n query,\n operationName,\n variables: { context: { workspaceId } },\n // The person's own workspace token, minted for THIS workspace.\n workspaceToken: true,\n workspaceId,\n organizationId: true,\n signal,\n suppressGlobalErrorEvent: true,\n });\n if (result.errors?.length) return [];\n const rows = result.data?.[field]?.[rowsKey];\n if (!Array.isArray(rows)) return [];\n const matches: AssistantRecordMatch[] = [];\n for (const row of rows as Array<RawRow | null>) {\n if (!row || typeof row.id !== 'string' || row.id.length === 0) continue;\n const shown = label(row);\n if (shown === null || !nameFits(name, shown)) continue;\n matches.push({ params: { id: row.id }, name: shown });\n }\n return matches;\n}\n\nexport function createHealthyBowlRecordAdapters(\n deps: RecordAdapterDeps = LIVE_DEPS\n): readonly AssistantRecordAdapter[] {\n const animals: AssistantRecordAdapter = {\n id: 'healthybowl-animal',\n nouns: ['animal', 'animals'],\n noun: { key: 'entity.animal', fallback: 'animal' },\n entityRouteId: 'healthybowl-animal',\n find: (name, signal) =>\n findByName(\n deps,\n LIST_ANIMALS_FOR_ASSISTANT,\n 'AssistantFindAnimals',\n 'getHealthyBowlLivestockData',\n 'animals',\n name,\n signal,\n // An animal with no name is called by its tag.\n (row) => text(row.name) ?? text(row.tagNumber)\n ),\n };\n const listings: AssistantRecordAdapter = {\n id: 'healthybowl-listing',\n nouns: ['listing', 'listings', 'marketplace listing', 'marketplace listings', 'product', 'products'],\n noun: { key: 'entity.listing', fallback: 'marketplace listing' },\n entityRouteId: 'healthybowl-listing',\n find: (name, signal) =>\n findByName(\n deps,\n LIST_LISTINGS_FOR_ASSISTANT,\n 'AssistantFindListings',\n 'getHealthyBowlMarketplaceData',\n 'marketplaceProducts',\n name,\n signal,\n (row) => text(row.name)\n ),\n };\n return [animals, listings];\n}\n\nexport const HEALTHYBOWL_RECORD_ADAPTERS: readonly AssistantRecordAdapter[] = createHealthyBowlRecordAdapters();\n"],"mappings":";;AAgCA,IAAa,IAA6B,sKAQ7B,IAA8B,2KAarC,IAA+B;CACnC,cAAc,OAAO,OAAa,MAAM,OAAO,sCAAsC,aAAa,CAAO;CACzG,gBAAgB,aAAa,MAAM,OAAO,sCAAsC,qBAAqB;AACvG,GAQM,KAAQ,MACZ,OAAO,KAAU,YAAY,EAAM,KAAK,EAAE,SAAS,IAAI,EAAM,KAAK,IAAI;AAGxE,SAAgB,EAAS,GAAc,GAAuB;CAE5D,IAAM,IAAS,EAAoB,CAAI;CACvC,IAAI,CAAC,GAAQ,OAAO;CACpB,IAAM,IAAQ,EAAoB,CAAI,EAAE,MAAM,GAAG;CACjD,OAAO,EAAO,MAAM,GAAG,EAAE,OAAO,MAAS,EAAM,MAAM,MAAc,EAAU,WAAW,CAAI,CAAC,CAAC;AAChG;AAEA,eAAe,EACb,GACA,GACA,GACA,GACA,GACA,GACA,GACA,GAC0C;CAC1C,IAAM,IAAc,MAAM,EAAK,eAAe;CAC9C,IAAI,CAAC,GAAa,OAAO,CAAC;CAC1B,IAAM,IAAS,MAAM,EAAK,aAAyE;EACjG,SAAS;EACT;EACA;EACA,WAAW,EAAE,SAAS,EAAE,eAAY,EAAE;EAEtC,gBAAgB;EAChB;EACA,gBAAgB;EAChB;EACA,0BAA0B;CAC5B,CAAC;CACD,IAAI,EAAO,QAAQ,QAAQ,OAAO,CAAC;CACnC,IAAM,IAAO,EAAO,OAAO,KAAS;CACpC,IAAI,CAAC,MAAM,QAAQ,CAAI,GAAG,OAAO,CAAC;CAClC,IAAM,IAAkC,CAAC;CACzC,KAAK,IAAM,KAAO,GAA8B;EAC9C,IAAI,CAAC,KAAO,OAAO,EAAI,MAAO,YAAY,EAAI,GAAG,WAAW,GAAG;EAC/D,IAAM,IAAQ,EAAM,CAAG;EACnB,MAAU,QAAQ,CAAC,EAAS,GAAM,CAAK,KAC3C,EAAQ,KAAK;GAAE,QAAQ,EAAE,IAAI,EAAI,GAAG;GAAG,MAAM;EAAM,CAAC;CACtD;CACA,OAAO;AACT;AAEA,SAAgB,EACd,IAA0B,GACS;CAoCnC,OAAO,CAAC;EAlCN,IAAI;EACJ,OAAO,CAAC,UAAU,SAAS;EAC3B,MAAM;GAAE,KAAK;GAAiB,UAAU;EAAS;EACjD,eAAe;EACf,OAAO,GAAM,MACX,EACE,GACA,GACA,wBACA,+BACA,WACA,GACA,IAEC,MAAQ,EAAK,EAAI,IAAI,KAAK,EAAK,EAAI,SAAS,CAC/C;CAmBI,GAAS;EAhBf,IAAI;EACJ,OAAO;GAAC;GAAW;GAAY;GAAuB;GAAwB;GAAW;EAAU;EACnG,MAAM;GAAE,KAAK;GAAkB,UAAU;EAAsB;EAC/D,eAAe;EACf,OAAO,GAAM,MACX,EACE,GACA,GACA,yBACA,iCACA,uBACA,GACA,IACC,MAAQ,EAAK,EAAI,IAAI,CACxB;CAEa,CAAQ;AAC3B;AAEA,IAAa,IAAiE,EAAgC"}
@@ -43,7 +43,9 @@ function p(e, t = l()) {
43
43
  return new Intl.NumberFormat(t).format(e);
44
44
  }
45
45
  function m(e, t = l()) {
46
- return new Date(e).toLocaleDateString(t, {
46
+ if (!e) return "—";
47
+ let n = new Date(e);
48
+ return Number.isNaN(n.getTime()) ? "—" : n.toLocaleDateString(t, {
47
49
  year: "numeric",
48
50
  month: "short",
49
51
  day: "numeric"
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.js","names":[],"sources":["../../../src/healthybowl/utils/helpers.ts"],"sourcesContent":["/**\n * HealthyBowl Utility Helpers\n * @module healthybowl\n */\n\nimport { clsx, type ClassValue } from 'clsx';\nimport { twMerge } from 'tailwind-merge';\n\n/** Merge Tailwind classes safely */\nexport function cn(...inputs: ClassValue[]) {\n return twMerge(clsx(inputs));\n}\n\n/** Join path segments safely */\nexport function joinPath(base: string, path: string): string {\n const cleanBase = base.endsWith('/') ? base.slice(0, -1) : base;\n const cleanPath = path.startsWith('/') ? path : `/${path}`;\n return cleanBase + cleanPath;\n}\n\n/**\n * Normalize a base path: strip a trailing slash but keep '/' for the root.\n * (e.g. '/healthybowl/' → '/healthybowl', '/' → '/'). Shared by useBasePath\n * and HealthyBowlRoot so the rule lives in one place.\n */\nexport function normalizeBasePath(base: string): string {\n return base.endsWith('/') ? base.slice(0, -1) || '/' : base;\n}\n\n/**\n * The currency HealthyBowl's own money is denominated in — the fallback for any\n * amount that arrives without one.\n *\n * This is a deliberate hardcode, not a lookup (BOFF-6000). HealthyBowl's ledger\n * amounts (`DashboardStats.netProfit`/`totalExpenses`, budgets, invoice totals,\n * feed and harvest costs …) come back from the subgraph as bare `Float`s, and\n * nothing in the platform says what they are denominated in: neither `Workspace`\n * nor any organisation-settings type carries a currency, and the HealthyBowl\n * dashboard payload has no currency field either. The product itself states\n * rupees throughout — the wallet prices credits at \"₹1 = 1 credit\", order entry\n * is labelled \"Amount (₹)\", the accounting tables head their columns \"(₹)\" — so\n * ₹ is the only defensible label for an unlabelled HealthyBowl amount.\n *\n * Deliberately NOT sourced from `useGeography().currency` in the app shell: that\n * is a per-user display preference which auto-detects and defaults to USD, and\n * nothing in the product converts between currencies. Reading it would relabel\n * the very same rupee amount as \"$\" for a farmer whose browser resolves to the\n * US — the same bug wearing a different hat.\n *\n * Any amount that DOES carry a real currency (platform store products, CSA\n * plans, loan facilitations, the credits wallet's billing account) must pass\n * that value instead of this constant. When a workspace- or organisation-level\n * currency setting ships, wire it in here — this is the single place to change.\n */\nexport const HB_DEFAULT_CURRENCY = 'INR';\n\n/**\n * BCP-47 locale the Intl.* formatters below use when a call site doesn't pass\n * one explicitly. The old hardcoded `'en-US'` grouped every amount the western\n * way (`₹1,234,567.00`); HealthyBowl is an India-first product (INR default\n * currency, ₹ labels, PMFBY / Indian government schemes), so the correct\n * default is the Indian numbering system (`₹12,34,567.00`) — BOFF-6202, the\n * scope-item-4 residual of BOFF-6000.\n *\n * `en-IN` — English is the product's lingua franca and its farmers are in\n * India, so the base language pairs with the India region for grouping while\n * keeping English month/label text.\n */\nexport const HB_DEFAULT_FORMAT_LOCALE = 'en-IN';\n\n/**\n * The shell exposes short language codes (`useI18n().locale`: 'en' | 'hi' |\n * 'ta' | …). The three India-region product languages map to their `-IN`\n * locale so grouping is Indian; every other language passes through unchanged\n * so it keeps its own conventions (German `1.234.567`, etc.).\n */\nconst SHELL_LOCALE_TO_BCP47: Record<string, string> = {\n en: 'en-IN',\n hi: 'hi-IN',\n ta: 'ta-IN',\n};\n\n/**\n * Ambient locale read by the formatters. The formatters are plain (non-hook)\n * functions called from ~130 files / ~490 call sites, so they can't call\n * `useI18n()` themselves. {@link HealthyBowlRoot} keeps this in sync with the\n * shell's active language via {@link setHbFormatLocale}, which makes every call\n * site locale-aware without threading a `locale` argument through all of them.\n */\nlet activeFormatLocale: string = HB_DEFAULT_FORMAT_LOCALE;\n\n/**\n * Point the ambient formatter locale at the shell's active language. Called\n * with the raw `useI18n().locale` short code; falsy input is ignored (keeps the\n * India-first default). Idempotent.\n */\nexport function setHbFormatLocale(shellLocale: string | null | undefined): void {\n if (!shellLocale) return;\n activeFormatLocale = SHELL_LOCALE_TO_BCP47[shellLocale] ?? shellLocale;\n}\n\n/** The locale the formatters currently use — the ambient value or an override. */\nexport function getHbFormatLocale(): string {\n return activeFormatLocale;\n}\n\n/**\n * Format an amount as currency.\n *\n * `currency` is required (ISO 4217) on purpose: an omitted argument used to fall\n * back to USD, which silently rendered rupee amounts as dollars. Pass the\n * record's own currency when it has one, otherwise {@link HB_DEFAULT_CURRENCY}.\n *\n * `locale` defaults to the ambient shell locale (Indian grouping out of the\n * box); pass one only to override a single call.\n */\nexport function formatCurrency(amount: number, currency: string, locale: string = getHbFormatLocale()): string {\n return new Intl.NumberFormat(locale, { style: 'currency', currency }).format(amount);\n}\n\n/**\n * Compact money for chart axes and other tight labels — `₹12K`, `₹12L` (the\n * India-first `en-IN` default groups into lakh/crore, not millions). Same\n * required-`currency` contract as {@link formatCurrency}; the axis ticks that\n * hand-rolled `` `$${v / 1000}k` `` are why this exists.\n */\nexport function formatCompactCurrency(amount: number, currency: string, locale: string = getHbFormatLocale()): string {\n return new Intl.NumberFormat(locale, {\n style: 'currency',\n currency,\n notation: 'compact',\n maximumFractionDigits: 1,\n }).format(amount);\n}\n\n/**\n * The currency a total over `lines` should be labelled with: the one currency\n * they all agree on, or {@link HB_DEFAULT_CURRENCY} when they carry none or\n * disagree (nothing in the product converts between currencies, so a mixed\n * total can only be labelled with the workspace default).\n */\nexport function resolveLineCurrency(lines: readonly { currency?: string }[]): string {\n const [first, ...rest] = lines.map((line) => line.currency ?? HB_DEFAULT_CURRENCY);\n if (!first) return HB_DEFAULT_CURRENCY;\n return rest.every((currency) => currency === first) ? first : HB_DEFAULT_CURRENCY;\n}\n\n/** Format number with locale-aware grouping (Indian by default). */\nexport function formatNumber(num: number, locale: string = getHbFormatLocale()): string {\n return new Intl.NumberFormat(locale).format(num);\n}\n\n/** Format date */\nexport function formatDate(dateStr: string, locale: string = getHbFormatLocale()): string {\n return new Date(dateStr).toLocaleDateString(locale, {\n year: 'numeric',\n month: 'short',\n day: 'numeric',\n });\n}\n\n/**\n * Format a date-only string (YYYY-MM-DD) without timezone conversion.\n * Using `new Date('2026-06-06')` parses as UTC midnight and shifts backward a\n * day in western (negative-offset) zones. Parsing the parts into a local Date\n * keeps the calendar date intact.\n */\nexport function formatDateOnly(dateStr: string, locale: string = getHbFormatLocale()): string {\n const match = /^(\\d{4})-(\\d{2})-(\\d{2})/.exec(dateStr);\n if (!match) return dateStr;\n const [, year, month, day] = match;\n return new Date(Number(year), Number(month) - 1, Number(day)).toLocaleDateString(locale, {\n year: 'numeric',\n month: 'short',\n day: 'numeric',\n });\n}\n\n/**\n * Today's calendar date as YYYY-MM-DD in the user's *local* timezone.\n * `new Date().toISOString()` is UTC, so for users west of UTC in the evening it has\n * already rolled to tomorrow — using it as a date-input `min` then wrongly blocks today.\n */\nexport function todayLocalDate(): string {\n const now = new Date();\n const year = now.getFullYear();\n const month = String(now.getMonth() + 1).padStart(2, '0');\n const day = String(now.getDate()).padStart(2, '0');\n return `${year}-${month}-${day}`;\n}\n\n/** Midnight of `d` in the viewer's own timezone. */\nfunction startOfLocalDay(d: Date): number {\n return new Date(d.getFullYear(), d.getMonth(), d.getDate()).getTime();\n}\n\n/** `2 days`, `1 week` — singular when the count is one. */\nfunction pluralDays(count: number, unit: string): string {\n return `${count} ${unit}${count === 1 ? '' : 's'}`;\n}\n\n/**\n * Get relative time string, in either direction.\n *\n * The past-only version floored a negative day delta and fell through the `< 7` branch, so a\n * snooze set for tomorrow rendered as \"snoozed until -1 days ago\" on the weather alert-history\n * feed. Anything HealthyBowl stores as a deadline (snoozedUntil, next irrigation run,\n * certification expiry) is naturally in the future, so both directions have to read correctly.\n *\n * The delta is counted in whole *calendar* days in the viewer's timezone, not in 24h blocks:\n * \"Tomorrow\" has to mean the next calendar date. An alert snoozed until 18:00 today is still\n * \"Today\" at noon, and something logged at 23:00 last night is \"Yesterday\" at 19:00 today —\n * a raw millisecond delta gets both of those wrong. `Math.round` absorbs the 23h/25h days\n * either side of a DST change.\n */\nexport function getRelativeTime(dateStr: string): string {\n const date = new Date(dateStr);\n const now = new Date();\n const dayMs = 1000 * 60 * 60 * 24;\n const days = Math.round((startOfLocalDay(date) - startOfLocalDay(now)) / dayMs);\n\n if (days === 0) return 'Today';\n if (days === 1) return 'Tomorrow';\n if (days === -1) return 'Yesterday';\n\n if (days > 0) {\n if (days < 7) return `in ${pluralDays(days, 'day')}`;\n if (days < 30) return `in ${pluralDays(Math.floor(days / 7), 'week')}`;\n if (days < 365) return `in ${pluralDays(Math.floor(days / 30), 'month')}`;\n return `in ${pluralDays(Math.floor(days / 365), 'year')}`;\n }\n\n const ago = -days;\n if (ago < 7) return `${pluralDays(ago, 'day')} ago`;\n if (ago < 30) return `${pluralDays(Math.floor(ago / 7), 'week')} ago`;\n if (ago < 365) return `${pluralDays(Math.floor(ago / 30), 'month')} ago`;\n return `${pluralDays(Math.floor(ago / 365), 'year')} ago`;\n}\n\n/** Get percentage change */\nexport function getPercentChange(current: number, previous: number): number {\n if (previous === 0) return current > 0 ? 100 : 0;\n return Math.round(((current - previous) / previous) * 100);\n}\n\n/** Truncate text */\nexport function truncate(text: string, maxLength: number): string {\n if (text.length <= maxLength) return text;\n return text.slice(0, maxLength) + '...';\n}\n\n/** Simulate async delay (for mock data) */\nexport function delay(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n"],"mappings":";;;AASA,SAAgB,EAAG,GAAG,GAAsB;CAC1C,OAAO,EAAQ,EAAK,CAAM,CAAC;AAC7B;AAGA,SAAgB,EAAS,GAAc,GAAsB;CAG3D,QAFkB,EAAK,SAAS,GAAG,IAAI,EAAK,MAAM,GAAG,EAAE,IAAI,MACzC,EAAK,WAAW,GAAG,IAAI,IAAO,IAAI;AAEtD;AAOA,SAAgB,EAAkB,GAAsB;CACtD,OAAO,EAAK,SAAS,GAAG,IAAI,EAAK,MAAM,GAAG,EAAE,KAAK,MAAM;AACzD;AAyCA,IAAa,IAA2B,SAQlC,IAAgD;CACpD,IAAI;CACJ,IAAI;CACJ,IAAI;AACN,GASI,IAA6B;AAOjC,SAAgB,EAAkB,GAA8C;CACzE,MACL,IAAqB,EAAsB,MAAgB;AAC7D;AAGA,SAAgB,IAA4B;CAC1C,OAAO;AACT;AAYA,SAAgB,EAAe,GAAgB,GAAkB,IAAiB,EAAkB,GAAW;CAC7G,O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ACxC,OAAO,IAAI,KAAK,EAAE,YAAY,GAAG,EAAE,SAAS,GAAG,EAAE,QAAQ,CAAC,EAAE,QAAQ;AACtE;AAGA,SAAS,EAAW,GAAe,GAAsB;CACvD,OAAO,GAAG,EAAM,GAAG,IAAO,MAAU,IAAI,KAAK;AAC/C;AAgBA,SAAgB,EAAgB,GAAyB;CACvD,IAAM,IAAO,IAAI,KAAK,CAAO,GACvB,oBAAM,IAAI,KAAK,GAEf,IAAO,KAAK,OAAO,EAAgB,CAAI,IAAI,EAAgB,CAAG,MADtD,MAAO,KAAK,KAAK,GAC+C;CAE9E,IAAI,MAAS,GAAG,OAAO;CACvB,IAAI,MAAS,GAAG,OAAO;CACvB,IAAI,MAAS,IAAI,OAAO;CAExB,IAAI,IAAO,GAIT,OAHI,IAAO,IAAU,MAAM,EAAW,GAAM,KAAK,MAC7C,IAAO,KAAW,MAAM,EAAW,KAAK,MAAM,IAAO,CAAC,GAAG,MAAM,MAC/D,IAAO,MAAY,MAAM,EAAW,KAAK,MAAM,IAAO,EAAE,GAAG,OAAO,MAC/D,MAAM,EAAW,KAAK,MAAM,IAAO,GAAG,GAAG,MAAM;CAGxD,IAAM,IAAM,CAAC;CAIb,OAHI,IAAM,IAAU,GAAG,EAAW,GAAK,KAAK,EAAE,QAC1C,IAAM,KAAW,GAAG,EAAW,KAAK,MAAM,IAAM,CAAC,GAAG,MAAM,EAAE,QAC5D,IAAM,MAAY,GAAG,EAAW,KAAK,MAAM,IAAM,EAAE,GAAG,OAAO,EAAE,QAC5D,GAAG,EAAW,KAAK,MAAM,IAAM,GAAG,GAAG,MAAM,EAAE;AACtD"}
1
+ {"version":3,"file":"helpers.js","names":[],"sources":["../../../src/healthybowl/utils/helpers.ts"],"sourcesContent":["/**\n * HealthyBowl Utility Helpers\n * @module healthybowl\n */\n\nimport { clsx, type ClassValue } from 'clsx';\nimport { twMerge } from 'tailwind-merge';\n\n/** Merge Tailwind classes safely */\nexport function cn(...inputs: ClassValue[]) {\n return twMerge(clsx(inputs));\n}\n\n/** Join path segments safely */\nexport function joinPath(base: string, path: string): string {\n const cleanBase = base.endsWith('/') ? base.slice(0, -1) : base;\n const cleanPath = path.startsWith('/') ? path : `/${path}`;\n return cleanBase + cleanPath;\n}\n\n/**\n * Normalize a base path: strip a trailing slash but keep '/' for the root.\n * (e.g. '/healthybowl/' → '/healthybowl', '/' → '/'). Shared by useBasePath\n * and HealthyBowlRoot so the rule lives in one place.\n */\nexport function normalizeBasePath(base: string): string {\n return base.endsWith('/') ? base.slice(0, -1) || '/' : base;\n}\n\n/**\n * The currency HealthyBowl's own money is denominated in — the fallback for any\n * amount that arrives without one.\n *\n * This is a deliberate hardcode, not a lookup (BOFF-6000). HealthyBowl's ledger\n * amounts (`DashboardStats.netProfit`/`totalExpenses`, budgets, invoice totals,\n * feed and harvest costs …) come back from the subgraph as bare `Float`s, and\n * nothing in the platform says what they are denominated in: neither `Workspace`\n * nor any organisation-settings type carries a currency, and the HealthyBowl\n * dashboard payload has no currency field either. The product itself states\n * rupees throughout — the wallet prices credits at \"₹1 = 1 credit\", order entry\n * is labelled \"Amount (₹)\", the accounting tables head their columns \"(₹)\" — so\n * ₹ is the only defensible label for an unlabelled HealthyBowl amount.\n *\n * Deliberately NOT sourced from `useGeography().currency` in the app shell: that\n * is a per-user display preference which auto-detects and defaults to USD, and\n * nothing in the product converts between currencies. Reading it would relabel\n * the very same rupee amount as \"$\" for a farmer whose browser resolves to the\n * US — the same bug wearing a different hat.\n *\n * Any amount that DOES carry a real currency (platform store products, CSA\n * plans, loan facilitations, the credits wallet's billing account) must pass\n * that value instead of this constant. When a workspace- or organisation-level\n * currency setting ships, wire it in here — this is the single place to change.\n */\nexport const HB_DEFAULT_CURRENCY = 'INR';\n\n/**\n * BCP-47 locale the Intl.* formatters below use when a call site doesn't pass\n * one explicitly. The old hardcoded `'en-US'` grouped every amount the western\n * way (`₹1,234,567.00`); HealthyBowl is an India-first product (INR default\n * currency, ₹ labels, PMFBY / Indian government schemes), so the correct\n * default is the Indian numbering system (`₹12,34,567.00`) — BOFF-6202, the\n * scope-item-4 residual of BOFF-6000.\n *\n * `en-IN` — English is the product's lingua franca and its farmers are in\n * India, so the base language pairs with the India region for grouping while\n * keeping English month/label text.\n */\nexport const HB_DEFAULT_FORMAT_LOCALE = 'en-IN';\n\n/**\n * The shell exposes short language codes (`useI18n().locale`: 'en' | 'hi' |\n * 'ta' | …). The three India-region product languages map to their `-IN`\n * locale so grouping is Indian; every other language passes through unchanged\n * so it keeps its own conventions (German `1.234.567`, etc.).\n */\nconst SHELL_LOCALE_TO_BCP47: Record<string, string> = {\n en: 'en-IN',\n hi: 'hi-IN',\n ta: 'ta-IN',\n};\n\n/**\n * Ambient locale read by the formatters. The formatters are plain (non-hook)\n * functions called from ~130 files / ~490 call sites, so they can't call\n * `useI18n()` themselves. {@link HealthyBowlRoot} keeps this in sync with the\n * shell's active language via {@link setHbFormatLocale}, which makes every call\n * site locale-aware without threading a `locale` argument through all of them.\n */\nlet activeFormatLocale: string = HB_DEFAULT_FORMAT_LOCALE;\n\n/**\n * Point the ambient formatter locale at the shell's active language. Called\n * with the raw `useI18n().locale` short code; falsy input is ignored (keeps the\n * India-first default). Idempotent.\n */\nexport function setHbFormatLocale(shellLocale: string | null | undefined): void {\n if (!shellLocale) return;\n activeFormatLocale = SHELL_LOCALE_TO_BCP47[shellLocale] ?? shellLocale;\n}\n\n/** The locale the formatters currently use — the ambient value or an override. */\nexport function getHbFormatLocale(): string {\n return activeFormatLocale;\n}\n\n/**\n * Format an amount as currency.\n *\n * `currency` is required (ISO 4217) on purpose: an omitted argument used to fall\n * back to USD, which silently rendered rupee amounts as dollars. Pass the\n * record's own currency when it has one, otherwise {@link HB_DEFAULT_CURRENCY}.\n *\n * `locale` defaults to the ambient shell locale (Indian grouping out of the\n * box); pass one only to override a single call.\n */\nexport function formatCurrency(amount: number, currency: string, locale: string = getHbFormatLocale()): string {\n return new Intl.NumberFormat(locale, { style: 'currency', currency }).format(amount);\n}\n\n/**\n * Compact money for chart axes and other tight labels — `₹12K`, `₹12L` (the\n * India-first `en-IN` default groups into lakh/crore, not millions). Same\n * required-`currency` contract as {@link formatCurrency}; the axis ticks that\n * hand-rolled `` `$${v / 1000}k` `` are why this exists.\n */\nexport function formatCompactCurrency(amount: number, currency: string, locale: string = getHbFormatLocale()): string {\n return new Intl.NumberFormat(locale, {\n style: 'currency',\n currency,\n notation: 'compact',\n maximumFractionDigits: 1,\n }).format(amount);\n}\n\n/**\n * The currency a total over `lines` should be labelled with: the one currency\n * they all agree on, or {@link HB_DEFAULT_CURRENCY} when they carry none or\n * disagree (nothing in the product converts between currencies, so a mixed\n * total can only be labelled with the workspace default).\n */\nexport function resolveLineCurrency(lines: readonly { currency?: string }[]): string {\n const [first, ...rest] = lines.map((line) => line.currency ?? HB_DEFAULT_CURRENCY);\n if (!first) return HB_DEFAULT_CURRENCY;\n return rest.every((currency) => currency === first) ? first : HB_DEFAULT_CURRENCY;\n}\n\n/** Format number with locale-aware grouping (Indian by default). */\nexport function formatNumber(num: number, locale: string = getHbFormatLocale()): string {\n return new Intl.NumberFormat(locale).format(num);\n}\n\n/**\n * What a date that is absent or unreadable shows. An em dash is language-neutral, so it needs no translation key,\n * and it is the placeholder the livestock pages already use for an empty value.\n */\nexport const NO_DATE_PLACEHOLDER = '—';\n\n/**\n * Format a date. A missing or unreadable value (null, undefined, \"\", garbage) shows `NO_DATE_PLACEHOLDER`,\n * never the browser's \"Invalid Date\": many dates are optional (an animal's date of birth, a last checkup), and\n * `new Date(null)` is 1970 while `new Date(undefined)` and `new Date(\"garbage\")` are invalid.\n */\nexport function formatDate(dateStr: string | null | undefined, locale: string = getHbFormatLocale()): string {\n if (!dateStr) return NO_DATE_PLACEHOLDER;\n const date = new Date(dateStr);\n if (Number.isNaN(date.getTime())) return NO_DATE_PLACEHOLDER;\n return date.toLocaleDateString(locale, {\n year: 'numeric',\n month: 'short',\n day: 'numeric',\n });\n}\n\n/**\n * Format a date-only string (YYYY-MM-DD) without timezone conversion.\n * Using `new Date('2026-06-06')` parses as UTC midnight and shifts backward a\n * day in western (negative-offset) zones. Parsing the parts into a local Date\n * keeps the calendar date intact.\n */\nexport function formatDateOnly(dateStr: string, locale: string = getHbFormatLocale()): string {\n const match = /^(\\d{4})-(\\d{2})-(\\d{2})/.exec(dateStr);\n if (!match) return dateStr;\n const [, year, month, day] = match;\n return new Date(Number(year), Number(month) - 1, Number(day)).toLocaleDateString(locale, {\n year: 'numeric',\n month: 'short',\n day: 'numeric',\n });\n}\n\n/**\n * Today's calendar date as YYYY-MM-DD in the user's *local* timezone.\n * `new Date().toISOString()` is UTC, so for users west of UTC in the evening it has\n * already rolled to tomorrow — using it as a date-input `min` then wrongly blocks today.\n */\nexport function todayLocalDate(): string {\n const now = new Date();\n const year = now.getFullYear();\n const month = String(now.getMonth() + 1).padStart(2, '0');\n const day = String(now.getDate()).padStart(2, '0');\n return `${year}-${month}-${day}`;\n}\n\n/** Midnight of `d` in the viewer's own timezone. */\nfunction startOfLocalDay(d: Date): number {\n return new Date(d.getFullYear(), d.getMonth(), d.getDate()).getTime();\n}\n\n/** `2 days`, `1 week` — singular when the count is one. */\nfunction pluralDays(count: number, unit: string): string {\n return `${count} ${unit}${count === 1 ? '' : 's'}`;\n}\n\n/**\n * Get relative time string, in either direction.\n *\n * The past-only version floored a negative day delta and fell through the `< 7` branch, so a\n * snooze set for tomorrow rendered as \"snoozed until -1 days ago\" on the weather alert-history\n * feed. Anything HealthyBowl stores as a deadline (snoozedUntil, next irrigation run,\n * certification expiry) is naturally in the future, so both directions have to read correctly.\n *\n * The delta is counted in whole *calendar* days in the viewer's timezone, not in 24h blocks:\n * \"Tomorrow\" has to mean the next calendar date. An alert snoozed until 18:00 today is still\n * \"Today\" at noon, and something logged at 23:00 last night is \"Yesterday\" at 19:00 today —\n * a raw millisecond delta gets both of those wrong. `Math.round` absorbs the 23h/25h days\n * either side of a DST change.\n */\nexport function getRelativeTime(dateStr: string): string {\n const date = new Date(dateStr);\n const now = new Date();\n const dayMs = 1000 * 60 * 60 * 24;\n const days = Math.round((startOfLocalDay(date) - startOfLocalDay(now)) / dayMs);\n\n if (days === 0) return 'Today';\n if (days === 1) return 'Tomorrow';\n if (days === -1) return 'Yesterday';\n\n if (days > 0) {\n if (days < 7) return `in ${pluralDays(days, 'day')}`;\n if (days < 30) return `in ${pluralDays(Math.floor(days / 7), 'week')}`;\n if (days < 365) return `in ${pluralDays(Math.floor(days / 30), 'month')}`;\n return `in ${pluralDays(Math.floor(days / 365), 'year')}`;\n }\n\n const ago = -days;\n if (ago < 7) return `${pluralDays(ago, 'day')} ago`;\n if (ago < 30) return `${pluralDays(Math.floor(ago / 7), 'week')} ago`;\n if (ago < 365) return `${pluralDays(Math.floor(ago / 30), 'month')} ago`;\n return `${pluralDays(Math.floor(ago / 365), 'year')} ago`;\n}\n\n/** Get percentage change */\nexport function getPercentChange(current: number, previous: number): number {\n if (previous === 0) return current > 0 ? 100 : 0;\n return Math.round(((current - previous) / previous) * 100);\n}\n\n/** Truncate text */\nexport function truncate(text: string, maxLength: number): string {\n if (text.length <= maxLength) return text;\n return text.slice(0, maxLength) + '...';\n}\n\n/** Simulate async delay (for mock data) */\nexport function delay(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n"],"mappings":";;;AASA,SAAgB,EAAG,GAAG,GAAsB;CAC1C,OAAO,EAAQ,EAAK,CAAM,CAAC;AAC7B;AAGA,SAAgB,EAAS,GAAc,GAAsB;CAG3D,QAFkB,EAAK,SAAS,GAAG,IAAI,EAAK,MAAM,GAAG,EAAE,IAAI,MACzC,EAAK,WAAW,GAAG,IAAI,IAAO,IAAI;AAEtD;AAOA,SAAgB,EAAkB,GAAsB;CACtD,OAAO,EAAK,SAAS,GAAG,IAAI,EAAK,MAAM,GAAG,EAAE,KAAK,MAAM;AACzD;AAyCA,IAAa,IAA2B,SAQlC,IAAgD;CACpD,IAAI;CACJ,IAAI;CACJ,IAAI;AACN,GASI,I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AK,MAAM,IAAM,GAAG,GAAG,MAAM,EAAE;AACtD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@burdenoff/microfe-healthybowl",
3
- "version": "2026.1008.1",
3
+ "version": "2026.1009.1",
4
4
  "description": "Burdenoff HealthyBowl Microfrontend - Comprehensive organic farming and agro-foods management platform",
5
5
  "type": "module",
6
6
  "files": [