@burdenoff/microfe-healthybowl 2026.1008.1 → 2026.1008.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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,EA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AAK,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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AK,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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@burdenoff/microfe-healthybowl",
3
- "version": "2026.1008.1",
3
+ "version": "2026.1008.2",
4
4
  "description": "Burdenoff HealthyBowl Microfrontend - Comprehensive organic farming and agro-foods management platform",
5
5
  "type": "module",
6
6
  "files": [