@ekanos/sdk 0.3.0 → 0.5.0

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 (63) hide show
  1. package/README.md +171 -75
  2. package/api-report.md +8 -3
  3. package/dist/components/base-activation-dialog.d.ts +15 -5
  4. package/dist/components/base-activation-dialog.js +31 -5
  5. package/dist/components/base-activation-dialog.js.map +1 -1
  6. package/dist/components/base-activation-form.d.ts +20 -5
  7. package/dist/components/base-activation-form.js +12 -5
  8. package/dist/components/base-activation-form.js.map +1 -1
  9. package/dist/components/base-marketplace-tile.js +12 -10
  10. package/dist/components/base-marketplace-tile.js.map +1 -1
  11. package/dist/components/index.d.ts +1 -1
  12. package/dist/components/index.js.map +1 -1
  13. package/dist/components/oauth-activation-form.d.ts +23 -16
  14. package/dist/components/oauth-activation-form.js +34 -20
  15. package/dist/components/oauth-activation-form.js.map +1 -1
  16. package/dist/components/widgets/ai-prompt-chip.js +2 -2
  17. package/dist/components/widgets/ai-prompt-chip.js.map +1 -1
  18. package/dist/components/widgets/use-relative-time.d.ts +7 -0
  19. package/dist/components/widgets/use-relative-time.js +55 -0
  20. package/dist/components/widgets/use-relative-time.js.map +1 -0
  21. package/dist/components/widgets/widget-ask-bar.js +1 -1
  22. package/dist/components/widgets/widget-ask-bar.js.map +1 -1
  23. package/dist/components/widgets/widget-context.d.ts +21 -0
  24. package/dist/components/widgets/widget-context.js.map +1 -1
  25. package/dist/components/widgets/widget-preview-provider.d.ts +1 -1
  26. package/dist/components/widgets/widget-preview-provider.js +1 -1
  27. package/dist/components/widgets/widget-preview-provider.js.map +1 -1
  28. package/dist/components/widgets/widget-state-components.d.ts +4 -1
  29. package/dist/components/widgets/widget-state-components.js +6 -4
  30. package/dist/components/widgets/widget-state-components.js.map +1 -1
  31. package/dist/components/widgets/widget.d.ts +47 -2
  32. package/dist/components/widgets/widget.js +111 -23
  33. package/dist/components/widgets/widget.js.map +1 -1
  34. package/dist/context/egress.js.map +1 -1
  35. package/dist/context/storage-validation.d.ts +24 -4
  36. package/dist/context/storage-validation.js +5 -2
  37. package/dist/context/storage-validation.js.map +1 -1
  38. package/dist/hooks/ask-assistant-context.js.map +1 -1
  39. package/dist/hooks/fetch-integration-storage.js.map +1 -1
  40. package/dist/hooks/partner-oauth.js +3 -0
  41. package/dist/hooks/partner-oauth.js.map +1 -1
  42. package/dist/hooks/use-integration-action.js.map +1 -1
  43. package/dist/hooks/use-oauth-connection-status.d.ts +78 -78
  44. package/dist/hooks/use-oauth-connection-status.js +17 -10
  45. package/dist/hooks/use-oauth-connection-status.js.map +1 -1
  46. package/dist/hooks/widget-event-context.js.map +1 -1
  47. package/dist/integration/event-surfaces.js.map +1 -1
  48. package/dist/integration/index.d.ts +2 -2
  49. package/dist/integration/index.js +1 -1
  50. package/dist/integration/index.js.map +1 -1
  51. package/dist/testing/invoke.js +9 -5
  52. package/dist/testing/invoke.js.map +1 -1
  53. package/dist/testing/mock-context.js +43 -8
  54. package/dist/testing/mock-context.js.map +1 -1
  55. package/dist/testing/mock-fetch-provider.js.map +1 -1
  56. package/dist/types/integration.d.ts +27 -21
  57. package/dist/types/integration.js.map +1 -1
  58. package/dist/types/widget-ask-context.d.ts +9 -0
  59. package/dist/types/widget-ask-context.js.map +1 -1
  60. package/dist/types/workspace-target.d.ts +3 -2
  61. package/dist/types/workspace-target.js.map +1 -1
  62. package/eslint.preset.mjs +9 -8
  63. package/package.json +37 -41
@@ -1,13 +1,16 @@
1
1
  'use client';
2
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
- import { Component, use, useMemo } from 'react';
2
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { Component, use, useMemo, } from 'react';
4
+ import Link from 'next/link.js';
4
5
  import { Button } from '@ekanos/ui/button';
5
6
  import { Card, CardContent, CardFooter, CardHeader, CardTitle, } from '@ekanos/ui/card';
7
+ import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger, } from '@ekanos/ui/dropdown-menu';
6
8
  import { Icon } from '@ekanos/ui/icon';
7
9
  import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, } from '@ekanos/ui/tooltip';
8
10
  import { Trans } from '@ekanos/ui/trans';
9
11
  import { cn } from '@ekanos/ui/utils';
10
12
  import { useAnimatedHeight } from './use-animated-height.js';
13
+ import { useRelativeTime } from './use-relative-time.js';
11
14
  import { WidgetAskBar } from './widget-ask-bar.js';
12
15
  import { WidgetContext } from './widget-context.js';
13
16
  import { WidgetDisabledState, WidgetErrorState, WidgetInactiveState, WidgetLoadingState, } from './widget-state-components.js';
@@ -16,6 +19,11 @@ class WidgetErrorBoundary extends Component {
16
19
  constructor() {
17
20
  super(...arguments);
18
21
  this.state = { hasError: false };
22
+ this.retry = () => {
23
+ var _a, _b;
24
+ (_b = (_a = this.props).onRetry) === null || _b === void 0 ? void 0 : _b.call(_a);
25
+ this.setState({ hasError: false });
26
+ };
19
27
  }
20
28
  static getDerivedStateFromError() {
21
29
  return { hasError: true };
@@ -25,7 +33,7 @@ class WidgetErrorBoundary extends Component {
25
33
  }
26
34
  render() {
27
35
  if (this.state.hasError) {
28
- return (_jsxs("div", { className: "flex flex-1 flex-col items-center justify-center gap-3 p-8", children: [_jsx("div", { className: "bg-destructive/10 flex h-16 w-16 items-center justify-center rounded-full", children: _jsx(Icon, { name: "fa-light fa-circle-exclamation", className: "text-destructive h-8 w-8" }) }), _jsx("p", { className: "text-muted-foreground text-base font-medium", children: _jsx(Trans, { i18nKey: "dashboard:widgetCrashedTitle", defaults: "Something went wrong" }) }), _jsx("p", { className: "text-muted-foreground max-w-xs text-center text-sm", children: _jsx(Trans, { i18nKey: "dashboard:widgetCrashedBody", defaults: "This widget encountered an error. Try refreshing the page." }) })] }));
36
+ return (_jsxs("div", { role: "alert", className: "flex flex-1 flex-col items-center justify-center gap-3 px-5 py-8 text-center", children: [_jsx("div", { className: "bg-destructive/10 flex h-10 w-10 items-center justify-center rounded-full", children: _jsx(Icon, { name: "fa-light fa-circle-exclamation", className: "text-destructive h-5 w-5", "aria-hidden": true }) }), _jsxs("div", { className: "space-y-1", children: [_jsx("p", { className: "text-foreground text-sm font-medium", children: _jsx(Trans, { i18nKey: "dashboard:widgetCrashedTitle", defaults: "This widget ran into a problem" }) }), _jsx("p", { className: "text-muted-foreground max-w-xs text-sm", children: _jsx(Trans, { i18nKey: "dashboard:widgetCrashedBody", defaults: "Try again. If it keeps happening, reload the page." }) })] }), _jsxs(Button, { type: "button", variant: "outline", size: "sm", onClick: this.retry, "data-test": "widget-crash-retry", children: [_jsx(Icon, { name: "fa-light fa-arrows-rotate", className: "h-4 w-4", "aria-hidden": true }), _jsx(Trans, { i18nKey: "dashboard:widgetRetry", defaults: "Try again" })] })] }));
29
37
  }
30
38
  return this.props.children;
31
39
  }
@@ -35,7 +43,7 @@ function useWidget() {
35
43
  const ctx = use(WidgetContext);
36
44
  if (!ctx) {
37
45
  throw new Error('Widget.* compound components must be rendered inside a widget provider. ' +
38
- 'On the Fusion dashboard the host supplies one. Anywhere else — your own ' +
46
+ 'On the Ekanos dashboard the host supplies one. Anywhere else — your own ' +
39
47
  'app, a story, a component test — wrap the widget in ' +
40
48
  "`WidgetPreviewProvider` from '@ekanos/sdk/components'.");
41
49
  }
@@ -44,10 +52,10 @@ function useWidget() {
44
52
  // ─── Card ───────────────────────────────────────────────────────────────────
45
53
  function WidgetCard({ children }) {
46
54
  const { meta } = useWidget();
47
- return (_jsx(Card, { className: cn(
55
+ return (_jsxs(Card, { className: cn(
48
56
  // Neutralize the shadcn card's own py-6/gap-6 box model — widget
49
57
  // chrome owns all vertical spacing via its header/content/footer.
50
- 'shadow-widget relative flex h-full flex-col gap-0 overflow-hidden rounded-lg border-0 py-0', meta.className), "data-widget-id": meta.widgetId, children: children }));
58
+ 'shadow-widget relative flex h-full flex-col gap-0 overflow-hidden rounded-lg border-0 py-0', meta.className), "data-widget-id": meta.widgetId, children: [children, _jsx(WidgetFreshness, {})] }));
51
59
  }
52
60
  // ─── Header ─────────────────────────────────────────────────────────────────
53
61
  function CollapseButton() {
@@ -55,26 +63,68 @@ function CollapseButton() {
55
63
  const { state, actions, meta } = useWidget();
56
64
  return (_jsx(Button, { variant: "outline", size: "icon", onClick: actions.toggleCollapsed, disabled: state.pendingCollapse, className: "bg-background dark:bg-secondary relative h-6 w-6 rounded-full before:absolute before:top-1/2 before:left-1/2 before:h-11 before:w-11 before:-translate-x-1/2 before:-translate-y-1/2 before:content-['']", "aria-expanded": !state.collapsed, "aria-controls": `widget-content-${meta.widgetId}`, "aria-label": state.collapsed
57
65
  ? `Expand ${(_a = meta.title) !== null && _a !== void 0 ? _a : 'widget'}`
58
- : `Collapse ${(_b = meta.title) !== null && _b !== void 0 ? _b : 'widget'}`, children: _jsx(Icon, { name: "fa-light fa-chevron-right", className: cn('h-4 w-4 transition-transform duration-200 ease-[cubic-bezier(0.25,1,0.5,1)] motion-reduce:transition-none', !state.collapsed && 'rotate-90') }) }));
66
+ : `Collapse ${(_b = meta.title) !== null && _b !== void 0 ? _b : 'widget'}`, children: _jsx(Icon, { name: "fa-light fa-chevron-right", className: cn('ease-out-strong h-4 w-4 transition-transform duration-200 motion-reduce:transition-none', !state.collapsed && 'rotate-90') }) }));
59
67
  }
60
- function WidgetHeader({ title, subtitle, description, children, }) {
68
+ function WidgetHeader({ title, subtitle, description, menu, children, }) {
61
69
  const { meta } = useWidget();
62
70
  const effectiveTitle = title !== null && title !== void 0 ? title : meta.title;
63
71
  const effectiveSubtitle = subtitle !== null && subtitle !== void 0 ? subtitle : meta.subtitle;
64
72
  const effectiveDescription = description !== null && description !== void 0 ? description : meta.description;
65
73
  if (!effectiveTitle)
66
74
  return null;
67
- return (_jsx(CardHeader, { className: "flex-shrink-0 border-b pt-6 pb-4 [.border-b]:pb-4", children: _jsxs("div", { className: "flex items-start justify-between gap-2", children: [_jsxs("div", { className: "flex items-center gap-2", children: [meta.isCollapsible ? _jsx(CollapseButton, {}) : null, effectiveDescription ? (_jsxs(_Fragment, { children: [_jsx(TooltipProvider, { children: _jsxs(Tooltip, { children: [_jsx(TooltipTrigger, { render: _jsx(CardTitle, { className: "cursor-help text-lg font-semibold" }), children: effectiveTitle }), _jsx(TooltipContent, { children: _jsx("p", { children: effectiveDescription }) })] }) }), _jsx("span", { className: "sr-only", children: effectiveDescription })] })) : (_jsx(CardTitle, { className: "text-lg font-semibold", children: effectiveTitle })), effectiveSubtitle && (_jsx("span", { className: "text-muted-foreground text-base font-medium", children: effectiveSubtitle }))] }), children && (_jsx("div", { className: "flex shrink-0 items-center gap-2", children: children }))] }) }));
75
+ return (_jsx(CardHeader, { className: "flex-shrink-0 border-b pt-6 pb-4 [.border-b]:pb-4", children: _jsxs("div", { className: "flex items-start justify-between gap-2", children: [_jsxs("div", { className: "flex items-center gap-2", children: [meta.isCollapsible ? _jsx(CollapseButton, {}) : null, effectiveDescription ? (_jsxs(_Fragment, { children: [_jsx(TooltipProvider, { children: _jsxs(Tooltip, { children: [_jsx(TooltipTrigger, { render: _jsx(CardTitle, { className: "cursor-help text-lg font-semibold" }), children: effectiveTitle }), _jsx(TooltipContent, { children: _jsx("p", { children: effectiveDescription }) })] }) }), _jsx("span", { className: "sr-only", children: effectiveDescription })] })) : (_jsx(CardTitle, { className: "text-lg font-semibold", children: effectiveTitle })), effectiveSubtitle && (_jsx("span", { className: "text-muted-foreground text-base font-medium", children: effectiveSubtitle }))] }), _jsxs("div", { className: "flex shrink-0 items-center gap-2", children: [children, _jsx(WidgetMenu, { items: menu })] })] }) }));
76
+ }
77
+ /**
78
+ * The actions every widget shares, whatever it renders: open its full
79
+ * surface, reload it, pin or unpin it. Each item needs something from the host
80
+ * or the widget's data layer, so the menu shows only what applies — and
81
+ * nothing at all when nothing does.
82
+ */
83
+ function WidgetMenu({ items }) {
84
+ var _a;
85
+ const { state, actions, meta, data } = useWidget();
86
+ const refresh = state.state === 'active' ? data === null || data === void 0 ? void 0 : data.refresh : undefined;
87
+ const hasNavigation = !!items || !!meta.openHref || !!refresh;
88
+ if (!hasNavigation && !meta.isPinnable)
89
+ return null;
90
+ const title = (_a = meta.title) !== null && _a !== void 0 ? _a : 'widget';
91
+ return (_jsxs(DropdownMenu, { children: [_jsx(DropdownMenuTrigger, { render: _jsx(Button, { variant: "ghost", size: "icon-sm", className: "text-muted-foreground hover:text-foreground", "aria-label": `Actions for ${title}`, "data-test": `widget-menu-${meta.widgetId}` }), children: _jsx(Icon, { name: "fa-light fa-ellipsis", className: "h-4 w-4", "aria-hidden": true }) }), _jsxs(DropdownMenuContent, { align: "end", className: "min-w-48", children: [items, meta.openHref ? (_jsxs(DropdownMenuItem, { render: _jsx(Link, { href: meta.openHref }), children: [_jsx(Icon, { name: "fa-light fa-arrow-up-right-from-square", "aria-hidden": true }), _jsx(Trans, { i18nKey: "dashboard:widgetOpenInWorkspace", defaults: "Open in workspace" })] })) : null, refresh ? (_jsxs(DropdownMenuItem, { onClick: refresh, disabled: data === null || data === void 0 ? void 0 : data.refreshing, children: [_jsx(Icon, { name: "fa-light fa-arrows-rotate", "aria-hidden": true }), _jsx(Trans, { i18nKey: "dashboard:widgetRefresh", defaults: "Refresh" })] })) : null, hasNavigation && meta.isPinnable ? _jsx(DropdownMenuSeparator, {}) : null, meta.isPinnable ? (_jsxs(DropdownMenuItem, { onClick: actions.togglePinned, disabled: state.pendingPin, "data-test": `widget-menu-pin-${meta.widgetId}`, children: [_jsx(Icon, { name: state.pinned
92
+ ? 'fa-light fa-thumbtack-slash'
93
+ : 'fa-light fa-thumbtack', "aria-hidden": true }), state.pinned ? (_jsx(Trans, { i18nKey: "dashboard:widgetUnpin", defaults: "Unpin from board" })) : (_jsx(Trans, { i18nKey: "dashboard:widgetPin", defaults: "Pin to board" }))] })) : null] })] }));
94
+ }
95
+ /**
96
+ * One widget-specific entry in the header's ⋯ menu; pass it through
97
+ * `Widget.Header`'s `menu` prop. With `href` it is a link, opened in a new tab
98
+ * when `external`; otherwise it runs `onSelect`.
99
+ */
100
+ function WidgetMenuItem({ icon, href, external = false, onSelect, disabled, children, }) {
101
+ const link = !href ? undefined : external ? (_jsx("a", { href: href, target: "_blank", rel: "noopener noreferrer" })) : (_jsx(Link, { href: href }));
102
+ return (_jsxs(DropdownMenuItem, { render: link, onClick: onSelect, disabled: disabled, children: [_jsx(Icon, { name: icon !== null && icon !== void 0 ? icon : (external
103
+ ? 'fa-light fa-arrow-up-right-from-square'
104
+ : 'fa-light fa-arrow-right'), "aria-hidden": true }), children] }));
105
+ }
106
+ /**
107
+ * "Updated 3 minutes ago" under an active widget whose data layer reports
108
+ * when it last loaded (see `Widget.DataState`'s `updatedAt`).
109
+ */
110
+ function WidgetFreshness() {
111
+ const { state, data } = useWidget();
112
+ const updated = useRelativeTime(data === null || data === void 0 ? void 0 : data.updatedAt);
113
+ if (state.state !== 'active' || state.collapsed || !updated)
114
+ return null;
115
+ return (_jsx("div", { className: "text-muted-foreground border-border/60 flex shrink-0 items-center gap-1.5 border-t px-5 py-2.5 text-xs", "aria-live": "polite", children: (data === null || data === void 0 ? void 0 : data.refreshing) ? (_jsxs(_Fragment, { children: [_jsx(Icon, { name: "fa-light fa-arrows-rotate", className: "h-3 w-3 animate-spin", "aria-hidden": true }), _jsx(Trans, { i18nKey: "dashboard:widgetRefreshing", defaults: "Refreshing\u2026" })] })) : (_jsx(Trans, { i18nKey: "dashboard:widgetUpdated", defaults: "Updated {{time}}", values: { time: updated } })) }));
68
116
  }
69
117
  // ─── State-gated content ────────────────────────────────────────────────────
70
118
  function CollapsibleBody({ collapsed, maxContentHeight, widgetId, children, }) {
71
- return (_jsx("div", { className: cn('grid min-h-0 flex-1 transition-[grid-template-rows] duration-300 ease-[cubic-bezier(0.25,1,0.5,1)] motion-reduce:transition-none', collapsed ? 'grid-rows-[0fr]' : 'grid-rows-[1fr]'), children: _jsx("div", { className: "min-h-0 overflow-hidden", children: _jsx(CardContent, { id: `widget-content-${widgetId}`, className: cn('flex h-full min-h-0 flex-1 flex-col overflow-y-auto p-0', 'transition-opacity duration-200 ease-[cubic-bezier(0.25,1,0.5,1)] motion-reduce:transition-none', collapsed ? 'opacity-0' : 'opacity-100'), style: maxContentHeight ? { maxHeight: maxContentHeight } : undefined, children: children }) }) }));
119
+ return (_jsx("div", { className: cn('ease-out-strong grid min-h-0 flex-1 transition-all duration-300 motion-reduce:transition-none', collapsed ? 'grid-rows-[0fr]' : 'grid-rows-[1fr]'), children: _jsx("div", { className: "min-h-0 overflow-hidden", children: _jsx(CardContent, { id: `widget-content-${widgetId}`, className: cn('flex h-full min-h-0 flex-1 flex-col overflow-y-auto p-0', 'ease-out-strong transition-opacity duration-200 motion-reduce:transition-none', collapsed ? 'opacity-0' : 'opacity-100', maxContentHeight && 'max-h-(--widget-max-height)'), style: maxContentHeight
120
+ ? { '--widget-max-height': maxContentHeight }
121
+ : undefined, children: children }) }) }));
72
122
  }
73
123
  function StaticBody({ maxContentHeight, children, }) {
74
124
  const { innerRef, height } = useAnimatedHeight();
75
- return (_jsx(CardContent, { className: "flex min-h-0 flex-1 flex-col p-0", children: _jsx("div", { className: "overflow-hidden transition-[height] duration-250 ease-out motion-reduce:transition-none", style: {
76
- height: height === 'auto' ? 'auto' : height,
77
- maxHeight: maxContentHeight !== null && maxContentHeight !== void 0 ? maxContentHeight : undefined,
125
+ return (_jsx(CardContent, { className: "flex min-h-0 flex-1 flex-col p-0", children: _jsx("div", { className: cn('h-(--body-height) overflow-hidden transition-all duration-250 ease-out motion-reduce:transition-none', maxContentHeight && 'max-h-(--widget-max-height)'), style: {
126
+ '--body-height': height === 'auto' ? 'auto' : `${height}px`,
127
+ '--widget-max-height': maxContentHeight,
78
128
  }, children: _jsx("div", { ref: innerRef, children: children }) }) }));
79
129
  }
80
130
  /**
@@ -111,10 +161,10 @@ function WidgetBody({ className, children, }) {
111
161
  * `Widget.Body` rather than hand-rolling a `px-*` wrapper.
112
162
  */
113
163
  function WidgetActive({ children }) {
114
- const { state, meta } = useWidget();
164
+ const { state, meta, data } = useWidget();
115
165
  if (state.state !== 'active')
116
166
  return null;
117
- const body = (_jsx(WidgetErrorBoundary, { widgetId: meta.widgetId, children: children }));
167
+ const body = (_jsx(WidgetErrorBoundary, { widgetId: meta.widgetId, onRetry: data === null || data === void 0 ? void 0 : data.refresh, children: children }));
118
168
  return meta.isCollapsible ? (_jsx(CollapsibleBody, { collapsed: state.collapsed, maxContentHeight: meta.maxContentHeight, widgetId: meta.widgetId, children: body })) : (_jsx(StaticBody, { maxContentHeight: meta.maxContentHeight, children: body }));
119
169
  }
120
170
  function WidgetLoading({ children }) {
@@ -124,10 +174,10 @@ function WidgetLoading({ children }) {
124
174
  return (_jsx(CardContent, { className: "flex min-h-0 flex-1 flex-col p-0", children: children !== null && children !== void 0 ? children : _jsx(WidgetLoadingState, {}) }));
125
175
  }
126
176
  function WidgetError({ children }) {
127
- const { state } = useWidget();
177
+ const { state, data } = useWidget();
128
178
  if (state.state !== 'error')
129
179
  return null;
130
- return (_jsx(CardContent, { className: "flex min-h-0 flex-1 flex-col p-0", children: children !== null && children !== void 0 ? children : _jsx(WidgetErrorState, {}) }));
180
+ return (_jsx(CardContent, { className: "flex min-h-0 flex-1 flex-col p-0", children: children !== null && children !== void 0 ? children : (_jsx(WidgetErrorState, { onRetry: data === null || data === void 0 ? void 0 : data.refresh, retrying: data === null || data === void 0 ? void 0 : data.refreshing })) }));
131
181
  }
132
182
  function WidgetInactive({ children }) {
133
183
  const { state } = useWidget();
@@ -146,7 +196,7 @@ function WidgetFooter({ children }) {
146
196
  const { state, meta } = useWidget();
147
197
  if (state.state !== 'active')
148
198
  return null;
149
- return (_jsx(CardFooter, { className: cn('flex-shrink-0 pb-6 transition-opacity duration-200 ease-[cubic-bezier(0.25,1,0.5,1)] motion-reduce:transition-none', meta.isCollapsible && state.collapsed
199
+ return (_jsx(CardFooter, { className: cn('ease-out-strong flex-shrink-0 pb-6 transition-opacity duration-200 motion-reduce:transition-none', meta.isCollapsible && state.collapsed
150
200
  ? 'pointer-events-none opacity-0'
151
201
  : 'opacity-100'), "aria-hidden": meta.isCollapsible && state.collapsed, children: children }));
152
202
  }
@@ -175,14 +225,22 @@ function WidgetAskFooter({ context }) {
175
225
  * instead, so this only fires for the degraded middle ground.
176
226
  */
177
227
  function WidgetHealthFooter() {
178
- var _a;
228
+ var _a, _b;
179
229
  const { state, meta } = useWidget();
230
+ const lastSuccessAt = toEpochMs((_a = meta.health) === null || _a === void 0 ? void 0 : _a.lastSuccessAt);
231
+ const lastSynced = useRelativeTime(lastSuccessAt);
180
232
  const shouldShow = state.state === 'active' &&
181
233
  !state.collapsed &&
182
- ((_a = meta.health) === null || _a === void 0 ? void 0 : _a.status) === 'degraded';
234
+ ((_b = meta.health) === null || _b === void 0 ? void 0 : _b.status) === 'degraded';
183
235
  if (!shouldShow)
184
236
  return null;
185
- return (_jsxs("div", { className: "text-warning border-warning/30 bg-warning/5 flex items-center gap-2 border-t px-4 py-2 text-xs", children: [_jsx(Icon, { name: "fa-light fa-circle-exclamation", className: "h-4 w-4 shrink-0", "aria-hidden": true }), _jsx("span", { children: _jsx(Trans, { i18nKey: "common:integrationHealth.degradedWidgetNotice", defaults: "This integration is degraded \u2014 data may be stale." }) })] }));
237
+ return (_jsxs("div", { className: "text-warning border-warning/30 bg-warning/5 flex items-center gap-2 border-t px-4 py-2 text-xs", children: [_jsx(Icon, { name: "fa-light fa-circle-exclamation", className: "h-4 w-4 shrink-0", "aria-hidden": true }), _jsx("span", { children: lastSynced ? (_jsx(Trans, { i18nKey: "common:integrationHealth.degradedWidgetNoticeSince", defaults: "Data may be out of date. Last synced {{time}}.", values: { time: lastSynced } })) : (_jsx(Trans, { i18nKey: "common:integrationHealth.degradedWidgetNotice", defaults: "This integration is degraded \u2014 data may be stale." })) })] }));
238
+ }
239
+ function toEpochMs(value) {
240
+ if (value === null || value === undefined)
241
+ return undefined;
242
+ const ms = value instanceof Date ? value.getTime() : new Date(value).getTime();
243
+ return Number.isFinite(ms) && ms > 0 ? ms : undefined;
186
244
  }
187
245
  // ─── Data state override ────────────────────────────────────────────────────
188
246
  /**
@@ -204,8 +262,22 @@ function WidgetHealthFooter() {
204
262
  * </Widget.DataState>
205
263
  * );
206
264
  * ```
265
+ *
266
+ * Pass `onRefresh`, `refreshing` and `updatedAt` to give the widget the
267
+ * shared Refresh menu item, a Try again button on its error view, and an
268
+ * "Updated 3 minutes ago" footer. With TanStack Query:
269
+ *
270
+ * ```tsx
271
+ * <Widget.DataState
272
+ * loading={query.isLoading}
273
+ * error={query.isError}
274
+ * onRefresh={() => void query.refetch()}
275
+ * refreshing={query.isFetching}
276
+ * updatedAt={query.dataUpdatedAt}
277
+ * >
278
+ * ```
207
279
  */
208
- function WidgetDataState({ loading, error, inactive, children, }) {
280
+ function WidgetDataState({ loading, error, inactive, onRefresh, refreshing = false, updatedAt, children, }) {
209
281
  const parent = useWidget();
210
282
  const overrideState = parent.state.state !== 'active'
211
283
  ? parent.state.state
@@ -216,17 +288,33 @@ function WidgetDataState({ loading, error, inactive, children, }) {
216
288
  : error
217
289
  ? 'error'
218
290
  : 'active';
291
+ const updatedAtMs = toEpochMs(updatedAt);
292
+ const reportsData = onRefresh !== undefined || updatedAtMs !== undefined;
219
293
  const value = useMemo(() => ({
220
294
  state: Object.assign(Object.assign({}, parent.state), { state: overrideState }),
221
295
  actions: parent.actions,
222
296
  meta: parent.meta,
223
- }), [parent.state, parent.actions, parent.meta, overrideState]);
297
+ data: reportsData
298
+ ? { updatedAt: updatedAtMs, refreshing, refresh: onRefresh }
299
+ : parent.data,
300
+ }), [
301
+ parent.state,
302
+ parent.actions,
303
+ parent.meta,
304
+ parent.data,
305
+ overrideState,
306
+ reportsData,
307
+ updatedAtMs,
308
+ refreshing,
309
+ onRefresh,
310
+ ]);
224
311
  return _jsx(WidgetContext, { value: value, children: children });
225
312
  }
226
313
  // ─── Compound export ────────────────────────────────────────────────────────
227
314
  export const Widget = {
228
315
  Card: WidgetCard,
229
316
  Header: WidgetHeader,
317
+ MenuItem: WidgetMenuItem,
230
318
  DataState: WidgetDataState,
231
319
  Active: WidgetActive,
232
320
  Body: WidgetBody,
@@ -1 +1 @@
1
- {"version":3,"file":"widget.js","sourceRoot":"","sources":["../../../src/components/widgets/widget.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EAAE,SAAS,EAAkB,GAAG,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAEhE,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EACL,IAAI,EACJ,WAAW,EACX,UAAU,EACV,UAAU,EACV,SAAS,GACV,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACvC,OAAO,EACL,OAAO,EACP,cAAc,EACd,eAAe,EACf,cAAc,GACf,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAGtC,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,aAAa,EAA0B,MAAM,kBAAkB,CAAC;AACzE,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,2BAA2B,CAAC;AAEnC,+EAA+E;AAE/E,MAAM,mBAAoB,SAAQ,SAGjC;IAHD;;QAIE,UAAK,GAAG,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;IAkC9B,CAAC;IAjCC,MAAM,CAAC,wBAAwB;QAC7B,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;IAC5B,CAAC;IACD,iBAAiB,CAAC,KAAY,EAAE,IAAqB;QACnD,OAAO,CAAC,KAAK,CAAC,WAAW,IAAI,CAAC,KAAK,CAAC,QAAQ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,MAAM,CAAC,KAAK,KAAE,KAAK,EAAE,aAAa,GAAE;QAChD,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,IAAI,EAAE,MAAM,CAAC,IAAI;KAClB,CAAC,EACF,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,IAAI,EAAE,aAAa,CAAC,CAC3D,CAAC;IACF,OAAO,KAAC,aAAa,IAAC,KAAK,EAAE,KAAK,YAAG,QAAQ,GAAiB,CAAC;AACjE,CAAC;AAED,+EAA+E;AAE/E,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,IAAI,EAAE,UAAU;IAChB,MAAM,EAAE,YAAY;IACpB,SAAS,EAAE,eAAe;IAC1B,MAAM,EAAE,YAAY;IACpB,IAAI,EAAE,UAAU;IAChB,OAAO,EAAE,aAAa;IACtB,KAAK,EAAE,WAAW;IAClB,QAAQ,EAAE,cAAc;IACxB,QAAQ,EAAE,cAAc;IACxB,MAAM,EAAE,YAAY;IACpB,OAAO,EAAE,aAAa;IACtB,SAAS,EAAE,eAAe;IAC1B,YAAY,EAAE,kBAAkB;CACjC,CAAC","sourcesContent":["'use client';\n\nimport { Component, type ReactNode, use, useMemo } from 'react';\n\nimport { Button } from '@ekanos/ui/button';\nimport {\n Card,\n CardContent,\n CardFooter,\n CardHeader,\n CardTitle,\n} from '@ekanos/ui/card';\nimport { Icon } from '@ekanos/ui/icon';\nimport {\n Tooltip,\n TooltipContent,\n TooltipProvider,\n TooltipTrigger,\n} from '@ekanos/ui/tooltip';\nimport { Trans } from '@ekanos/ui/trans';\nimport { cn } from '@ekanos/ui/utils';\n\nimport type { WidgetAskContext } from '../../types/widget-ask-context';\nimport { useAnimatedHeight } from './use-animated-height';\nimport { WidgetAskBar } from './widget-ask-bar';\nimport { WidgetContext, type WidgetRenderState } from './widget-context';\nimport {\n WidgetDisabledState,\n WidgetErrorState,\n WidgetInactiveState,\n WidgetLoadingState,\n} from './widget-state-components';\n\n// ─── Error Boundary ─────────────────────────────────────────────────────────\n\nclass WidgetErrorBoundary extends Component<\n { widgetId: string; children: ReactNode },\n { hasError: boolean }\n> {\n state = { hasError: false };\n static getDerivedStateFromError() {\n return { hasError: true };\n }\n componentDidCatch(error: Error, info: React.ErrorInfo) {\n console.error(`Widget \"${this.props.widgetId}\" crashed:`, error, info);\n }\n render() {\n if (this.state.hasError) {\n return (\n <div className=\"flex flex-1 flex-col items-center justify-center gap-3 p-8\">\n <div className=\"bg-destructive/10 flex h-16 w-16 items-center justify-center rounded-full\">\n <Icon\n name=\"fa-light fa-circle-exclamation\"\n className=\"text-destructive h-8 w-8\"\n />\n </div>\n <p className=\"text-muted-foreground text-base font-medium\">\n <Trans\n i18nKey=\"dashboard:widgetCrashedTitle\"\n defaults=\"Something went wrong\"\n />\n </p>\n <p className=\"text-muted-foreground max-w-xs text-center text-sm\">\n <Trans\n i18nKey=\"dashboard:widgetCrashedBody\"\n defaults=\"This widget encountered an error. Try refreshing the page.\"\n />\n </p>\n </div>\n );\n }\n return this.props.children;\n }\n}\n\n// ─── Hook ───────────────────────────────────────────────────────────────────\n\nfunction useWidget() {\n const ctx = use(WidgetContext);\n if (!ctx) {\n throw new Error(\n 'Widget.* compound components must be rendered inside a widget provider. ' +\n 'On the Fusion dashboard the host supplies one. Anywhere else — your own ' +\n 'app, a story, a component test — wrap the widget in ' +\n \"`WidgetPreviewProvider` from '@ekanos/sdk/components'.\",\n );\n }\n return ctx;\n}\n\n// ─── Card ───────────────────────────────────────────────────────────────────\n\nfunction WidgetCard({ children }: { children: ReactNode }) {\n const { meta } = useWidget();\n return (\n <Card\n className={cn(\n // Neutralize the shadcn card's own py-6/gap-6 box model — widget\n // chrome owns all vertical spacing via its header/content/footer.\n 'shadow-widget relative flex h-full flex-col gap-0 overflow-hidden rounded-lg border-0 py-0',\n meta.className,\n )}\n data-widget-id={meta.widgetId}\n >\n {children}\n </Card>\n );\n}\n\n// ─── Header ─────────────────────────────────────────────────────────────────\n\nfunction CollapseButton() {\n const { state, actions, meta } = useWidget();\n return (\n <Button\n variant=\"outline\"\n size=\"icon\"\n onClick={actions.toggleCollapsed}\n disabled={state.pendingCollapse}\n className=\"bg-background dark:bg-secondary relative h-6 w-6 rounded-full before:absolute before:top-1/2 before:left-1/2 before:h-11 before:w-11 before:-translate-x-1/2 before:-translate-y-1/2 before:content-['']\"\n aria-expanded={!state.collapsed}\n aria-controls={`widget-content-${meta.widgetId}`}\n aria-label={\n state.collapsed\n ? `Expand ${meta.title ?? 'widget'}`\n : `Collapse ${meta.title ?? 'widget'}`\n }\n >\n <Icon\n name=\"fa-light fa-chevron-right\"\n className={cn(\n 'h-4 w-4 transition-transform duration-200 ease-[cubic-bezier(0.25,1,0.5,1)] motion-reduce:transition-none',\n !state.collapsed && 'rotate-90',\n )}\n />\n </Button>\n );\n}\n\nfunction WidgetHeader({\n title,\n subtitle,\n description,\n children,\n}: {\n /** Override the provider's title — useful when the rendered name differs from the config name. */\n title?: string;\n /** Override the provider's subtitle — useful for widget-computed values. */\n subtitle?: string;\n /** Override the provider's description — useful for widget-computed values. */\n description?: string;\n children?: ReactNode;\n}) {\n const { meta } = useWidget();\n const effectiveTitle = title ?? meta.title;\n const effectiveSubtitle = subtitle ?? meta.subtitle;\n const effectiveDescription = description ?? meta.description;\n if (!effectiveTitle) return null;\n return (\n <CardHeader className=\"flex-shrink-0 border-b pt-6 pb-4 [.border-b]:pb-4\">\n <div className=\"flex items-start justify-between gap-2\">\n <div className=\"flex items-center gap-2\">\n {meta.isCollapsible ? <CollapseButton /> : null}\n {effectiveDescription ? (\n <>\n <TooltipProvider>\n <Tooltip>\n <TooltipTrigger\n render={\n <CardTitle className=\"cursor-help text-lg font-semibold\" />\n }\n >\n {effectiveTitle}\n </TooltipTrigger>\n <TooltipContent>\n <p>{effectiveDescription}</p>\n </TooltipContent>\n </Tooltip>\n </TooltipProvider>\n <span className=\"sr-only\">{effectiveDescription}</span>\n </>\n ) : (\n <CardTitle className=\"text-lg font-semibold\">\n {effectiveTitle}\n </CardTitle>\n )}\n {effectiveSubtitle && (\n <span className=\"text-muted-foreground text-base font-medium\">\n {effectiveSubtitle}\n </span>\n )}\n </div>\n {children && (\n <div className=\"flex shrink-0 items-center gap-2\">{children}</div>\n )}\n </div>\n </CardHeader>\n );\n}\n\n// ─── State-gated content ────────────────────────────────────────────────────\n\nfunction CollapsibleBody({\n collapsed,\n maxContentHeight,\n widgetId,\n children,\n}: {\n collapsed: boolean;\n maxContentHeight?: string;\n widgetId: string;\n children: ReactNode;\n}) {\n return (\n <div\n className={cn(\n 'grid min-h-0 flex-1 transition-[grid-template-rows] duration-300 ease-[cubic-bezier(0.25,1,0.5,1)] motion-reduce:transition-none',\n collapsed ? 'grid-rows-[0fr]' : 'grid-rows-[1fr]',\n )}\n >\n <div className=\"min-h-0 overflow-hidden\">\n <CardContent\n id={`widget-content-${widgetId}`}\n className={cn(\n 'flex h-full min-h-0 flex-1 flex-col overflow-y-auto p-0',\n 'transition-opacity duration-200 ease-[cubic-bezier(0.25,1,0.5,1)] motion-reduce:transition-none',\n collapsed ? 'opacity-0' : 'opacity-100',\n )}\n style={maxContentHeight ? { maxHeight: maxContentHeight } : undefined}\n >\n {children}\n </CardContent>\n </div>\n </div>\n );\n}\n\nfunction StaticBody({\n maxContentHeight,\n children,\n}: {\n maxContentHeight?: string;\n children: ReactNode;\n}) {\n const { innerRef, height } = useAnimatedHeight();\n return (\n <CardContent className=\"flex min-h-0 flex-1 flex-col p-0\">\n <div\n className=\"overflow-hidden transition-[height] duration-250 ease-out motion-reduce:transition-none\"\n style={{\n height: height === 'auto' ? ('auto' as const) : height,\n maxHeight: maxContentHeight ?? undefined,\n }}\n >\n <div ref={innerRef}>{children}</div>\n </div>\n </CardContent>\n );\n}\n\n/**\n * The standard padded body for content rendered inside `Widget.Active`.\n *\n * `Widget.Active`'s own `CardContent` renders `p-0` — deliberately, so a\n * full-bleed chart or table can run edge-to-edge inside the card. That means\n * ordinary content (text, rows, a KPI readout) is left flush against the\n * card's sides while `Widget.Header` stays inset (`px-5`) unless the body\n * supplies its own padding. `Widget.Body` is that padding: `px-5` matches\n * the header's horizontal inset so header and body align, `pt-4 pb-5`\n * balances the header's `pb-4`/card's bottom edge.\n *\n * Use it for any widget whose content is NOT already full-bleed:\n *\n * ```tsx\n * <Widget.Active>\n * <Widget.Body>{/* rows, text, a KPI readout *\\/}</Widget.Body>\n * </Widget.Active>\n * ```\n *\n * Skip it — render children directly inside `Widget.Active` — when the\n * content itself needs to run flush to the card edges (a chart, a table with\n * its own header row, an image).\n */\nfunction WidgetBody({\n className,\n children,\n}: {\n className?: string;\n children: ReactNode;\n}) {\n return (\n <div className={cn('flex flex-1 flex-col gap-4 px-5 pt-4 pb-5', className)}>\n {children}\n </div>\n );\n}\n\n/**\n * Renders `children` once the widget's state is `active`. Intentionally\n * flush: its `CardContent` renders `p-0` (no horizontal/vertical inset) so a\n * chart, table, or other full-bleed content can run edge-to-edge — existing\n * widgets depend on this. For ordinary padded content, wrap `children` in\n * `Widget.Body` rather than hand-rolling a `px-*` wrapper.\n */\nfunction WidgetActive({ children }: { children: ReactNode }) {\n const { state, meta } = useWidget();\n if (state.state !== 'active') return null;\n const body = (\n <WidgetErrorBoundary widgetId={meta.widgetId}>\n {children}\n </WidgetErrorBoundary>\n );\n return meta.isCollapsible ? (\n <CollapsibleBody\n collapsed={state.collapsed}\n maxContentHeight={meta.maxContentHeight}\n widgetId={meta.widgetId}\n >\n {body}\n </CollapsibleBody>\n ) : (\n <StaticBody maxContentHeight={meta.maxContentHeight}>{body}</StaticBody>\n );\n}\n\nfunction WidgetLoading({ children }: { children?: ReactNode }) {\n const { state } = useWidget();\n if (state.state !== 'loading') return null;\n return (\n <CardContent className=\"flex min-h-0 flex-1 flex-col p-0\">\n {children ?? <WidgetLoadingState />}\n </CardContent>\n );\n}\n\nfunction WidgetError({ children }: { children?: ReactNode }) {\n const { state } = useWidget();\n if (state.state !== 'error') return null;\n return (\n <CardContent className=\"flex min-h-0 flex-1 flex-col p-0\">\n {children ?? <WidgetErrorState />}\n </CardContent>\n );\n}\n\nfunction WidgetInactive({ children }: { children?: ReactNode }) {\n const { state } = useWidget();\n if (state.state !== 'inactive') return null;\n return (\n <CardContent className=\"flex min-h-0 flex-1 flex-col p-0\">\n {children ?? <WidgetInactiveState />}\n </CardContent>\n );\n}\n\nfunction WidgetDisabled({ children }: { children?: ReactNode }) {\n const { state } = useWidget();\n if (state.state !== 'disabled') return null;\n return (\n <CardContent className=\"flex min-h-0 flex-1 flex-col p-0\">\n {children ?? <WidgetDisabledState />}\n </CardContent>\n );\n}\n\n// ─── Footers ────────────────────────────────────────────────────────────────\n\nfunction WidgetFooter({ children }: { children: ReactNode }) {\n const { state, meta } = useWidget();\n if (state.state !== 'active') return null;\n return (\n <CardFooter\n className={cn(\n 'flex-shrink-0 pb-6 transition-opacity duration-200 ease-[cubic-bezier(0.25,1,0.5,1)] motion-reduce:transition-none',\n meta.isCollapsible && state.collapsed\n ? 'pointer-events-none opacity-0'\n : 'opacity-100',\n )}\n aria-hidden={meta.isCollapsible && state.collapsed}\n >\n {children}\n </CardFooter>\n );\n}\n\nfunction WidgetActions({ children }: { children: ReactNode }) {\n return (\n <CardFooter className=\"bg-muted flex-shrink-0 justify-end border-t py-3\">\n {children}\n </CardFooter>\n );\n}\n\nfunction WidgetAskFooter({ context }: { context?: WidgetAskContext }) {\n const { state, meta } = useWidget();\n const effectiveContext = context ?? meta.askContext;\n const shouldShow =\n (meta.aiFooterEnabled || !!effectiveContext) &&\n state.state === 'active' &&\n !state.collapsed;\n if (!shouldShow) return null;\n return (\n <WidgetAskBar\n context={\n effectiveContext ?? {\n widgetId: meta.widgetId,\n title: meta.title ?? meta.widgetId,\n snapshot: null,\n suggestedPrompt: `Tell me about ${meta.title ?? 'this widget'}.`,\n }\n }\n />\n );\n}\n\n/**\n * Renders a subtle \"data may be stale\" banner when the widget's integration is\n * `degraded` (but still active). Unhealthy integrations route to `disabled`\n * instead, so this only fires for the degraded middle ground.\n */\nfunction WidgetHealthFooter() {\n const { state, meta } = useWidget();\n const shouldShow =\n state.state === 'active' &&\n !state.collapsed &&\n meta.health?.status === 'degraded';\n if (!shouldShow) return null;\n return (\n <div className=\"text-warning border-warning/30 bg-warning/5 flex items-center gap-2 border-t px-4 py-2 text-xs\">\n <Icon\n name=\"fa-light fa-circle-exclamation\"\n className=\"h-4 w-4 shrink-0\"\n aria-hidden\n />\n <span>\n <Trans\n i18nKey=\"common:integrationHealth.degradedWidgetNotice\"\n defaults=\"This integration is degraded — data may be stale.\"\n />\n </span>\n </div>\n );\n}\n\n// ─── Data state override ────────────────────────────────────────────────────\n\n/**\n * Wraps children in a sub-provider that overrides the effective render state\n * with the widget's own data loading / error state. Only overrides when the\n * parent state is `active` — so the integration's `inactive` / `disabled` /\n * `loading` (initial) states still win.\n *\n * Read the parent integration state BEFORE wrapping in this component if you\n * need it to gate data fetching:\n *\n * ```tsx\n * const { state } = use(WidgetContext);\n * const integrationActive = state.state === 'active';\n * const { isLoading, isError } = useMyData(accountId, integrationActive);\n * return (\n * <Widget.DataState loading={isLoading} error={isError}>\n * <Widget.Card>…</Widget.Card>\n * </Widget.DataState>\n * );\n * ```\n */\nfunction WidgetDataState({\n loading,\n error,\n inactive,\n children,\n}: {\n loading?: boolean;\n error?: boolean;\n /**\n * Force the `inactive` render state even though the integration itself is\n * active. Use for widget-level \"not connected\" states (e.g. the product is\n * activated but the upstream OAuth connection is missing). Takes priority\n * over `loading` / `error`.\n */\n inactive?: boolean;\n children: ReactNode;\n}) {\n const parent = useWidget();\n const overrideState: WidgetRenderState =\n parent.state.state !== 'active'\n ? parent.state.state\n : inactive\n ? 'inactive'\n : loading\n ? 'loading'\n : error\n ? 'error'\n : 'active';\n const value = useMemo(\n () => ({\n state: { ...parent.state, state: overrideState },\n actions: parent.actions,\n meta: parent.meta,\n }),\n [parent.state, parent.actions, parent.meta, overrideState],\n );\n return <WidgetContext value={value}>{children}</WidgetContext>;\n}\n\n// ─── Compound export ────────────────────────────────────────────────────────\n\nexport const Widget = {\n Card: WidgetCard,\n Header: WidgetHeader,\n DataState: WidgetDataState,\n Active: WidgetActive,\n Body: WidgetBody,\n Loading: WidgetLoading,\n Error: WidgetError,\n Inactive: WidgetInactive,\n Disabled: WidgetDisabled,\n Footer: WidgetFooter,\n Actions: WidgetActions,\n AskFooter: WidgetAskFooter,\n HealthFooter: WidgetHealthFooter,\n};\n"]}
1
+ {"version":3,"file":"widget.js","sourceRoot":"","sources":["../../../src/components/widgets/widget.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EACL,SAAS,EAGT,GAAG,EACH,OAAO,GACR,MAAM,OAAO,CAAC;AAEf,OAAO,IAAI,MAAM,cAAc,CAAC;AAEhC,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EACL,IAAI,EACJ,WAAW,EACX,UAAU,EACV,UAAU,EACV,SAAS,GACV,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,YAAY,EACZ,mBAAmB,EACnB,gBAAgB,EAChB,qBAAqB,EACrB,mBAAmB,GACpB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACvC,OAAO,EACL,OAAO,EACP,cAAc,EACd,eAAe,EACf,cAAc,GACf,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAGtC,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,aAAa,EAA0B,MAAM,kBAAkB,CAAC;AACzE,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,mBAAmB,EACnB,kBAAkB,GACnB,M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,CAAC,OAAO;QACd,MAAM,CAAC,IAAI;QACX,MAAM,CAAC,IAAI;QACX,aAAa;QACb,WAAW;QACX,WAAW;QACX,UAAU;QACV,SAAS;KACV,CACF,CAAC;IACF,OAAO,KAAC,aAAa,IAAC,KAAK,EAAE,KAAK,YAAG,QAAQ,GAAiB,CAAC;AACjE,CAAC;AAED,+EAA+E;AAE/E,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,IAAI,EAAE,UAAU;IAChB,MAAM,EAAE,YAAY;IACpB,QAAQ,EAAE,cAAc;IACxB,SAAS,EAAE,eAAe;IAC1B,MAAM,EAAE,YAAY;IACpB,IAAI,EAAE,UAAU;IAChB,OAAO,EAAE,aAAa;IACtB,KAAK,EAAE,WAAW;IAClB,QAAQ,EAAE,cAAc;IACxB,QAAQ,EAAE,cAAc;IACxB,MAAM,EAAE,YAAY;IACpB,OAAO,EAAE,aAAa;IACtB,SAAS,EAAE,eAAe;IAC1B,YAAY,EAAE,kBAAkB;CACjC,CAAC","sourcesContent":["'use client';\n\nimport {\n Component,\n type CSSProperties,\n type ReactNode,\n use,\n useMemo,\n} from 'react';\n\nimport Link from 'next/link.js';\n\nimport { Button } from '@ekanos/ui/button';\nimport {\n Card,\n CardContent,\n CardFooter,\n CardHeader,\n CardTitle,\n} from '@ekanos/ui/card';\nimport {\n DropdownMenu,\n DropdownMenuContent,\n DropdownMenuItem,\n DropdownMenuSeparator,\n DropdownMenuTrigger,\n} from '@ekanos/ui/dropdown-menu';\nimport { Icon } from '@ekanos/ui/icon';\nimport {\n Tooltip,\n TooltipContent,\n TooltipProvider,\n TooltipTrigger,\n} from '@ekanos/ui/tooltip';\nimport { Trans } from '@ekanos/ui/trans';\nimport { cn } from '@ekanos/ui/utils';\n\nimport type { WidgetAskContext } from '../../types/widget-ask-context';\nimport { useAnimatedHeight } from './use-animated-height';\nimport { useRelativeTime } from './use-relative-time';\nimport { WidgetAskBar } from './widget-ask-bar';\nimport { WidgetContext, type WidgetRenderState } from './widget-context';\nimport {\n WidgetDisabledState,\n WidgetErrorState,\n WidgetInactiveState,\n WidgetLoadingState,\n} from './widget-state-components';\n\n// ─── Error Boundary ─────────────────────────────────────────────────────────\n\nclass WidgetErrorBoundary extends Component<\n { widgetId: string; onRetry?: () => void; children: ReactNode },\n { hasError: boolean }\n> {\n state = { hasError: false };\n static getDerivedStateFromError() {\n return { hasError: true };\n }\n componentDidCatch(error: Error, info: React.ErrorInfo) {\n console.error(`Widget \"${this.props.widgetId}\" crashed:`, error, info);\n }\n retry = () => {\n this.props.onRetry?.();\n this.setState({ hasError: false });\n };\n render() {\n if (this.state.hasError) {\n return (\n <div\n role=\"alert\"\n className=\"flex flex-1 flex-col items-center justify-center gap-3 px-5 py-8 text-center\"\n >\n <div className=\"bg-destructive/10 flex h-10 w-10 items-center justify-center rounded-full\">\n <Icon\n name=\"fa-light fa-circle-exclamation\"\n className=\"text-destructive h-5 w-5\"\n aria-hidden\n />\n </div>\n <div className=\"space-y-1\">\n <p className=\"text-foreground text-sm font-medium\">\n <Trans\n i18nKey=\"dashboard:widgetCrashedTitle\"\n defaults=\"This widget ran into a problem\"\n />\n </p>\n <p className=\"text-muted-foreground max-w-xs text-sm\">\n <Trans\n i18nKey=\"dashboard:widgetCrashedBody\"\n defaults=\"Try again. If it keeps happening, reload the page.\"\n />\n </p>\n </div>\n <Button\n type=\"button\"\n variant=\"outline\"\n size=\"sm\"\n onClick={this.retry}\n data-test=\"widget-crash-retry\"\n >\n <Icon\n name=\"fa-light fa-arrows-rotate\"\n className=\"h-4 w-4\"\n aria-hidden\n />\n <Trans i18nKey=\"dashboard:widgetRetry\" defaults=\"Try again\" />\n </Button>\n </div>\n );\n }\n return this.props.children;\n }\n}\n\n// ─── Hook ───────────────────────────────────────────────────────────────────\n\nfunction useWidget() {\n const ctx = use(WidgetContext);\n if (!ctx) {\n throw new Error(\n 'Widget.* compound components must be rendered inside a widget provider. ' +\n 'On the Ekanos dashboard the host supplies one. Anywhere else — your own ' +\n 'app, a story, a component test — wrap the widget in ' +\n \"`WidgetPreviewProvider` from '@ekanos/sdk/components'.\",\n );\n }\n return ctx;\n}\n\n// ─── Card ───────────────────────────────────────────────────────────────────\n\nfunction WidgetCard({ children }: { children: ReactNode }) {\n const { meta } = useWidget();\n return (\n <Card\n className={cn(\n // Neutralize the shadcn card's own py-6/gap-6 box model — widget\n // chrome owns all vertical spacing via its header/content/footer.\n 'shadow-widget relative flex h-full flex-col gap-0 overflow-hidden rounded-lg border-0 py-0',\n meta.className,\n )}\n data-widget-id={meta.widgetId}\n >\n {children}\n <WidgetFreshness />\n </Card>\n );\n}\n\n// ─── Header ─────────────────────────────────────────────────────────────────\n\nfunction CollapseButton() {\n const { state, actions, meta } = useWidget();\n return (\n <Button\n variant=\"outline\"\n size=\"icon\"\n onClick={actions.toggleCollapsed}\n disabled={state.pendingCollapse}\n className=\"bg-background dark:bg-secondary relative h-6 w-6 rounded-full before:absolute before:top-1/2 before:left-1/2 before:h-11 before:w-11 before:-translate-x-1/2 before:-translate-y-1/2 before:content-['']\"\n aria-expanded={!state.collapsed}\n aria-controls={`widget-content-${meta.widgetId}`}\n aria-label={\n state.collapsed\n ? `Expand ${meta.title ?? 'widget'}`\n : `Collapse ${meta.title ?? 'widget'}`\n }\n >\n <Icon\n name=\"fa-light fa-chevron-right\"\n className={cn(\n 'ease-out-strong h-4 w-4 transition-transform duration-200 motion-reduce:transition-none',\n !state.collapsed && 'rotate-90',\n )}\n />\n </Button>\n );\n}\n\nfunction WidgetHeader({\n title,\n subtitle,\n description,\n menu,\n children,\n}: {\n /** Override the provider's title — useful when the rendered name differs from the config name. */\n title?: string;\n /** Override the provider's subtitle — useful for widget-computed values. */\n subtitle?: string;\n /** Override the provider's description — useful for widget-computed values. */\n description?: string;\n /**\n * `Widget.MenuItem`s placed at the top of the header's ⋯ menu. Use it for\n * occasional actions — \"Open in QuickBooks\", \"Open in Outlook\" — and keep\n * `children` for the controls people reach for every visit, like filters.\n */\n menu?: ReactNode;\n children?: ReactNode;\n}) {\n const { meta } = useWidget();\n const effectiveTitle = title ?? meta.title;\n const effectiveSubtitle = subtitle ?? meta.subtitle;\n const effectiveDescription = description ?? meta.description;\n if (!effectiveTitle) return null;\n return (\n <CardHeader className=\"flex-shrink-0 border-b pt-6 pb-4 [.border-b]:pb-4\">\n <div className=\"flex items-start justify-between gap-2\">\n <div className=\"flex items-center gap-2\">\n {meta.isCollapsible ? <CollapseButton /> : null}\n {effectiveDescription ? (\n <>\n <TooltipProvider>\n <Tooltip>\n <TooltipTrigger\n render={\n <CardTitle className=\"cursor-help text-lg font-semibold\" />\n }\n >\n {effectiveTitle}\n </TooltipTrigger>\n <TooltipContent>\n <p>{effectiveDescription}</p>\n </TooltipContent>\n </Tooltip>\n </TooltipProvider>\n <span className=\"sr-only\">{effectiveDescription}</span>\n </>\n ) : (\n <CardTitle className=\"text-lg font-semibold\">\n {effectiveTitle}\n </CardTitle>\n )}\n {effectiveSubtitle && (\n <span className=\"text-muted-foreground text-base font-medium\">\n {effectiveSubtitle}\n </span>\n )}\n </div>\n <div className=\"flex shrink-0 items-center gap-2\">\n {children}\n <WidgetMenu items={menu} />\n </div>\n </div>\n </CardHeader>\n );\n}\n\n/**\n * The actions every widget shares, whatever it renders: open its full\n * surface, reload it, pin or unpin it. Each item needs something from the host\n * or the widget's data layer, so the menu shows only what applies — and\n * nothing at all when nothing does.\n */\nfunction WidgetMenu({ items }: { items?: ReactNode }) {\n const { state, actions, meta, data } = useWidget();\n const refresh = state.state === 'active' ? data?.refresh : undefined;\n const hasNavigation = !!items || !!meta.openHref || !!refresh;\n\n if (!hasNavigation && !meta.isPinnable) return null;\n\n const title = meta.title ?? 'widget';\n\n return (\n <DropdownMenu>\n <DropdownMenuTrigger\n render={\n <Button\n variant=\"ghost\"\n size=\"icon-sm\"\n className=\"text-muted-foreground hover:text-foreground\"\n aria-label={`Actions for ${title}`}\n data-test={`widget-menu-${meta.widgetId}`}\n />\n }\n >\n <Icon name=\"fa-light fa-ellipsis\" className=\"h-4 w-4\" aria-hidden />\n </DropdownMenuTrigger>\n <DropdownMenuContent align=\"end\" className=\"min-w-48\">\n {items}\n {meta.openHref ? (\n <DropdownMenuItem render={<Link href={meta.openHref} />}>\n <Icon name=\"fa-light fa-arrow-up-right-from-square\" aria-hidden />\n <Trans\n i18nKey=\"dashboard:widgetOpenInWorkspace\"\n defaults=\"Open in workspace\"\n />\n </DropdownMenuItem>\n ) : null}\n {refresh ? (\n <DropdownMenuItem onClick={refresh} disabled={data?.refreshing}>\n <Icon name=\"fa-light fa-arrows-rotate\" aria-hidden />\n <Trans i18nKey=\"dashboard:widgetRefresh\" defaults=\"Refresh\" />\n </DropdownMenuItem>\n ) : null}\n {hasNavigation && meta.isPinnable ? <DropdownMenuSeparator /> : null}\n {meta.isPinnable ? (\n <DropdownMenuItem\n onClick={actions.togglePinned}\n disabled={state.pendingPin}\n data-test={`widget-menu-pin-${meta.widgetId}`}\n >\n <Icon\n name={\n state.pinned\n ? 'fa-light fa-thumbtack-slash'\n : 'fa-light fa-thumbtack'\n }\n aria-hidden\n />\n {state.pinned ? (\n <Trans\n i18nKey=\"dashboard:widgetUnpin\"\n defaults=\"Unpin from board\"\n />\n ) : (\n <Trans i18nKey=\"dashboard:widgetPin\" defaults=\"Pin to board\" />\n )}\n </DropdownMenuItem>\n ) : null}\n </DropdownMenuContent>\n </DropdownMenu>\n );\n}\n\n/**\n * One widget-specific entry in the header's ⋯ menu; pass it through\n * `Widget.Header`'s `menu` prop. With `href` it is a link, opened in a new tab\n * when `external`; otherwise it runs `onSelect`.\n */\nfunction WidgetMenuItem({\n icon,\n href,\n external = false,\n onSelect,\n disabled,\n children,\n}: {\n /** A Font Awesome class, e.g. `fa-light fa-envelope`. */\n icon?: string;\n href?: string;\n external?: boolean;\n onSelect?: () => void;\n disabled?: boolean;\n children: ReactNode;\n}) {\n const link = !href ? undefined : external ? (\n <a href={href} target=\"_blank\" rel=\"noopener noreferrer\" />\n ) : (\n <Link href={href} />\n );\n\n return (\n <DropdownMenuItem render={link} onClick={onSelect} disabled={disabled}>\n <Icon\n name={\n icon ??\n (external\n ? 'fa-light fa-arrow-up-right-from-square'\n : 'fa-light fa-arrow-right')\n }\n aria-hidden\n />\n {children}\n </DropdownMenuItem>\n );\n}\n\n/**\n * \"Updated 3 minutes ago\" under an active widget whose data layer reports\n * when it last loaded (see `Widget.DataState`'s `updatedAt`).\n */\nfunction WidgetFreshness() {\n const { state, data } = useWidget();\n const updated = useRelativeTime(data?.updatedAt);\n\n if (state.state !== 'active' || state.collapsed || !updated) return null;\n\n return (\n <div\n className=\"text-muted-foreground border-border/60 flex shrink-0 items-center gap-1.5 border-t px-5 py-2.5 text-xs\"\n aria-live=\"polite\"\n >\n {data?.refreshing ? (\n <>\n <Icon\n name=\"fa-light fa-arrows-rotate\"\n className=\"h-3 w-3 animate-spin\"\n aria-hidden\n />\n <Trans i18nKey=\"dashboard:widgetRefreshing\" defaults=\"Refreshing…\" />\n </>\n ) : (\n <Trans\n i18nKey=\"dashboard:widgetUpdated\"\n defaults=\"Updated {{time}}\"\n values={{ time: updated }}\n />\n )}\n </div>\n );\n}\n\n// ─── State-gated content ────────────────────────────────────────────────────\n\nfunction CollapsibleBody({\n collapsed,\n maxContentHeight,\n widgetId,\n children,\n}: {\n collapsed: boolean;\n maxContentHeight?: string;\n widgetId: string;\n children: ReactNode;\n}) {\n return (\n <div\n className={cn(\n 'ease-out-strong grid min-h-0 flex-1 transition-all duration-300 motion-reduce:transition-none',\n collapsed ? 'grid-rows-[0fr]' : 'grid-rows-[1fr]',\n )}\n >\n <div className=\"min-h-0 overflow-hidden\">\n <CardContent\n id={`widget-content-${widgetId}`}\n className={cn(\n 'flex h-full min-h-0 flex-1 flex-col overflow-y-auto p-0',\n 'ease-out-strong transition-opacity duration-200 motion-reduce:transition-none',\n collapsed ? 'opacity-0' : 'opacity-100',\n maxContentHeight && 'max-h-(--widget-max-height)',\n )}\n style={\n maxContentHeight\n ? ({ '--widget-max-height': maxContentHeight } as CSSProperties)\n : undefined\n }\n >\n {children}\n </CardContent>\n </div>\n </div>\n );\n}\n\nfunction StaticBody({\n maxContentHeight,\n children,\n}: {\n maxContentHeight?: string;\n children: ReactNode;\n}) {\n const { innerRef, height } = useAnimatedHeight();\n return (\n <CardContent className=\"flex min-h-0 flex-1 flex-col p-0\">\n <div\n className={cn(\n 'h-(--body-height) overflow-hidden transition-all duration-250 ease-out motion-reduce:transition-none',\n maxContentHeight && 'max-h-(--widget-max-height)',\n )}\n style={\n {\n '--body-height': height === 'auto' ? 'auto' : `${height}px`,\n '--widget-max-height': maxContentHeight,\n } as CSSProperties\n }\n >\n <div ref={innerRef}>{children}</div>\n </div>\n </CardContent>\n );\n}\n\n/**\n * The standard padded body for content rendered inside `Widget.Active`.\n *\n * `Widget.Active`'s own `CardContent` renders `p-0` — deliberately, so a\n * full-bleed chart or table can run edge-to-edge inside the card. That means\n * ordinary content (text, rows, a KPI readout) is left flush against the\n * card's sides while `Widget.Header` stays inset (`px-5`) unless the body\n * supplies its own padding. `Widget.Body` is that padding: `px-5` matches\n * the header's horizontal inset so header and body align, `pt-4 pb-5`\n * balances the header's `pb-4`/card's bottom edge.\n *\n * Use it for any widget whose content is NOT already full-bleed:\n *\n * ```tsx\n * <Widget.Active>\n * <Widget.Body>{/* rows, text, a KPI readout *\\/}</Widget.Body>\n * </Widget.Active>\n * ```\n *\n * Skip it — render children directly inside `Widget.Active` — when the\n * content itself needs to run flush to the card edges (a chart, a table with\n * its own header row, an image).\n */\nfunction WidgetBody({\n className,\n children,\n}: {\n className?: string;\n children: ReactNode;\n}) {\n return (\n <div className={cn('flex flex-1 flex-col gap-4 px-5 pt-4 pb-5', className)}>\n {children}\n </div>\n );\n}\n\n/**\n * Renders `children` once the widget's state is `active`. Intentionally\n * flush: its `CardContent` renders `p-0` (no horizontal/vertical inset) so a\n * chart, table, or other full-bleed content can run edge-to-edge — existing\n * widgets depend on this. For ordinary padded content, wrap `children` in\n * `Widget.Body` rather than hand-rolling a `px-*` wrapper.\n */\nfunction WidgetActive({ children }: { children: ReactNode }) {\n const { state, meta, data } = useWidget();\n if (state.state !== 'active') return null;\n const body = (\n <WidgetErrorBoundary widgetId={meta.widgetId} onRetry={data?.refresh}>\n {children}\n </WidgetErrorBoundary>\n );\n return meta.isCollapsible ? (\n <CollapsibleBody\n collapsed={state.collapsed}\n maxContentHeight={meta.maxContentHeight}\n widgetId={meta.widgetId}\n >\n {body}\n </CollapsibleBody>\n ) : (\n <StaticBody maxContentHeight={meta.maxContentHeight}>{body}</StaticBody>\n );\n}\n\nfunction WidgetLoading({ children }: { children?: ReactNode }) {\n const { state } = useWidget();\n if (state.state !== 'loading') return null;\n return (\n <CardContent className=\"flex min-h-0 flex-1 flex-col p-0\">\n {children ?? <WidgetLoadingState />}\n </CardContent>\n );\n}\n\nfunction WidgetError({ children }: { children?: ReactNode }) {\n const { state, data } = useWidget();\n if (state.state !== 'error') return null;\n return (\n <CardContent className=\"flex min-h-0 flex-1 flex-col p-0\">\n {children ?? (\n <WidgetErrorState onRetry={data?.refresh} retrying={data?.refreshing} />\n )}\n </CardContent>\n );\n}\n\nfunction WidgetInactive({ children }: { children?: ReactNode }) {\n const { state } = useWidget();\n if (state.state !== 'inactive') return null;\n return (\n <CardContent className=\"flex min-h-0 flex-1 flex-col p-0\">\n {children ?? <WidgetInactiveState />}\n </CardContent>\n );\n}\n\nfunction WidgetDisabled({ children }: { children?: ReactNode }) {\n const { state } = useWidget();\n if (state.state !== 'disabled') return null;\n return (\n <CardContent className=\"flex min-h-0 flex-1 flex-col p-0\">\n {children ?? <WidgetDisabledState />}\n </CardContent>\n );\n}\n\n// ─── Footers ────────────────────────────────────────────────────────────────\n\nfunction WidgetFooter({ children }: { children: ReactNode }) {\n const { state, meta } = useWidget();\n if (state.state !== 'active') return null;\n return (\n <CardFooter\n className={cn(\n 'ease-out-strong flex-shrink-0 pb-6 transition-opacity duration-200 motion-reduce:transition-none',\n meta.isCollapsible && state.collapsed\n ? 'pointer-events-none opacity-0'\n : 'opacity-100',\n )}\n aria-hidden={meta.isCollapsible && state.collapsed}\n >\n {children}\n </CardFooter>\n );\n}\n\nfunction WidgetActions({ children }: { children: ReactNode }) {\n return (\n <CardFooter className=\"bg-muted flex-shrink-0 justify-end border-t py-3\">\n {children}\n </CardFooter>\n );\n}\n\nfunction WidgetAskFooter({ context }: { context?: WidgetAskContext }) {\n const { state, meta } = useWidget();\n const effectiveContext = context ?? meta.askContext;\n const shouldShow =\n (meta.aiFooterEnabled || !!effectiveContext) &&\n state.state === 'active' &&\n !state.collapsed;\n if (!shouldShow) return null;\n return (\n <WidgetAskBar\n context={\n effectiveContext ?? {\n widgetId: meta.widgetId,\n title: meta.title ?? meta.widgetId,\n snapshot: null,\n suggestedPrompt: `Tell me about ${meta.title ?? 'this widget'}.`,\n }\n }\n />\n );\n}\n\n/**\n * Renders a subtle \"data may be stale\" banner when the widget's integration is\n * `degraded` (but still active). Unhealthy integrations route to `disabled`\n * instead, so this only fires for the degraded middle ground.\n */\nfunction WidgetHealthFooter() {\n const { state, meta } = useWidget();\n const lastSuccessAt = toEpochMs(meta.health?.lastSuccessAt);\n const lastSynced = useRelativeTime(lastSuccessAt);\n const shouldShow =\n state.state === 'active' &&\n !state.collapsed &&\n meta.health?.status === 'degraded';\n if (!shouldShow) return null;\n return (\n <div className=\"text-warning border-warning/30 bg-warning/5 flex items-center gap-2 border-t px-4 py-2 text-xs\">\n <Icon\n name=\"fa-light fa-circle-exclamation\"\n className=\"h-4 w-4 shrink-0\"\n aria-hidden\n />\n <span>\n {lastSynced ? (\n <Trans\n i18nKey=\"common:integrationHealth.degradedWidgetNoticeSince\"\n defaults=\"Data may be out of date. Last synced {{time}}.\"\n values={{ time: lastSynced }}\n />\n ) : (\n <Trans\n i18nKey=\"common:integrationHealth.degradedWidgetNotice\"\n defaults=\"This integration is degraded — data may be stale.\"\n />\n )}\n </span>\n </div>\n );\n}\n\nfunction toEpochMs(\n value: number | string | Date | null | undefined,\n): number | undefined {\n if (value === null || value === undefined) return undefined;\n const ms =\n value instanceof Date ? value.getTime() : new Date(value).getTime();\n return Number.isFinite(ms) && ms > 0 ? ms : undefined;\n}\n\n// ─── Data state override ────────────────────────────────────────────────────\n\n/**\n * Wraps children in a sub-provider that overrides the effective render state\n * with the widget's own data loading / error state. Only overrides when the\n * parent state is `active` — so the integration's `inactive` / `disabled` /\n * `loading` (initial) states still win.\n *\n * Read the parent integration state BEFORE wrapping in this component if you\n * need it to gate data fetching:\n *\n * ```tsx\n * const { state } = use(WidgetContext);\n * const integrationActive = state.state === 'active';\n * const { isLoading, isError } = useMyData(accountId, integrationActive);\n * return (\n * <Widget.DataState loading={isLoading} error={isError}>\n * <Widget.Card>…</Widget.Card>\n * </Widget.DataState>\n * );\n * ```\n *\n * Pass `onRefresh`, `refreshing` and `updatedAt` to give the widget the\n * shared Refresh menu item, a Try again button on its error view, and an\n * \"Updated 3 minutes ago\" footer. With TanStack Query:\n *\n * ```tsx\n * <Widget.DataState\n * loading={query.isLoading}\n * error={query.isError}\n * onRefresh={() => void query.refetch()}\n * refreshing={query.isFetching}\n * updatedAt={query.dataUpdatedAt}\n * >\n * ```\n */\nfunction WidgetDataState({\n loading,\n error,\n inactive,\n onRefresh,\n refreshing = false,\n updatedAt,\n children,\n}: {\n loading?: boolean;\n error?: boolean;\n /**\n * Force the `inactive` render state even though the integration itself is\n * active. Use for widget-level \"not connected\" states (e.g. the product is\n * activated but the upstream OAuth connection is missing). Takes priority\n * over `loading` / `error`.\n */\n inactive?: boolean;\n /** Reloads the widget's data. */\n onRefresh?: () => void;\n /** A reload is in flight. */\n refreshing?: boolean;\n /**\n * When the data on screen last loaded successfully: epoch milliseconds, an\n * ISO string or a `Date`. `0` means never, which TanStack Query's\n * `dataUpdatedAt` reports before the first success.\n */\n updatedAt?: number | string | Date | null;\n children: ReactNode;\n}) {\n const parent = useWidget();\n const overrideState: WidgetRenderState =\n parent.state.state !== 'active'\n ? parent.state.state\n : inactive\n ? 'inactive'\n : loading\n ? 'loading'\n : error\n ? 'error'\n : 'active';\n const updatedAtMs = toEpochMs(updatedAt);\n const reportsData = onRefresh !== undefined || updatedAtMs !== undefined;\n const value = useMemo(\n () => ({\n state: { ...parent.state, state: overrideState },\n actions: parent.actions,\n meta: parent.meta,\n data: reportsData\n ? { updatedAt: updatedAtMs, refreshing, refresh: onRefresh }\n : parent.data,\n }),\n [\n parent.state,\n parent.actions,\n parent.meta,\n parent.data,\n overrideState,\n reportsData,\n updatedAtMs,\n refreshing,\n onRefresh,\n ],\n );\n return <WidgetContext value={value}>{children}</WidgetContext>;\n}\n\n// ─── Compound export ────────────────────────────────────────────────────────\n\nexport const Widget = {\n Card: WidgetCard,\n Header: WidgetHeader,\n MenuItem: WidgetMenuItem,\n DataState: WidgetDataState,\n Active: WidgetActive,\n Body: WidgetBody,\n Loading: WidgetLoading,\n Error: WidgetError,\n Inactive: WidgetInactive,\n Disabled: WidgetDisabled,\n Footer: WidgetFooter,\n Actions: WidgetActions,\n AskFooter: WidgetAskFooter,\n HealthFooter: WidgetHealthFooter,\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"egress.js","sourceRoot":"","sources":["../../src/context/egress.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,eAAe,GAAG,OAAO,CAAC;AAShC,SAAS,YAAY,CAAC,KAAa,EAAE,MAAc;IACjD,OAAO,IAAI,SAAS,CAClB,2BAA2B,KAAK,iBAAiB,MAAM,IAAI;QACzD,kEAAkE;QAClE,yEAAyE;QACzE,mEAAmE;QACnE,mCAAmC,CACtC,CAAC;AACJ,CAAC;AAED,SAAS,UAAU,CAAC,KAAa;IAC/B,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAC;IACjD,MAAM,SAAS,GAAG,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,eAAe,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IAE3E,IAAI,MA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IAAI,MAAM,CAAC,QAAQ,KAAK,MAAM,CAAC,QAAQ;YAAE,OAAO,KAAK,CAAC;QACtD,IAAI,MAAM,CAAC,IAAI,KAAK,MAAM,CAAC,IAAI;YAAE,OAAO,KAAK,CAAC;QAC9C,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC;YACpB,OAAO,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC;QACzD,CAAC;QACD,OAAO,MAAM,CAAC,QAAQ,KAAK,MAAM,CAAC,QAAQ,CAAC;IAC7C,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["/**\n * The egress allowlist matcher (ruling 3) — ONE pure function, shared by the\n * harness mock, the promote-gate check, and the production `ctx.fetch`\n * wrapper, so a test that passes the mock cannot be an egress surprise later.\n */\n\nconst WILDCARD_MARKER = '://*.';\n\ninterface ParsedEntry {\n protocol: string;\n hostname: string;\n port: string;\n wildcard: boolean;\n}\n\nfunction invalidEntry(entry: string, detail: string): TypeError {\n return new TypeError(\n `Egress allowlist entry \"${entry}\" is invalid: ${detail}. ` +\n `Entries are origins only — \"https://api.example.com\" (exact) or ` +\n `\"https://*.example.com\" (subdomain wildcard); scheme + host + optional ` +\n `port, no path, query, hash, or credentials. Fix the entry in the ` +\n `integration's egress declaration.`,\n );\n}\n\nfunction parseEntry(entry: string): ParsedEntry {\n const wildcard = entry.includes(WILDCARD_MARKER);\n const candidate = wildcard ? entry.replace(WILDCARD_MARKER, '://') : entry;\n\n let parsed: URL;\n try {\n parsed = new URL(candidate);\n } catch {\n throw invalidEntry(entry, 'it does not parse as a URL origin');\n }\n\n if (parsed.hostname.includes('*')) {\n throw invalidEntry(\n entry,\n 'wildcards are only supported as a leading \"*.\" on the hostname',\n );\n }\n if (parsed.pathname !== '/' || parsed.search !== '' || parsed.hash !== '') {\n throw invalidEntry(entry, 'it carries a path, query, or hash');\n }\n if (parsed.username !== '' || parsed.password !== '') {\n throw invalidEntry(entry, 'it carries credentials');\n }\n if (parsed.hostname === '') {\n throw invalidEntry(entry, 'it has no hostname');\n }\n\n return {\n protocol: parsed.protocol,\n hostname: parsed.hostname,\n port: parsed.port,\n wildcard,\n };\n}\n\n/**\n * Returns whether `url`'s ORIGIN is covered by the egress allowlist.\n *\n * Semantics (ruling 3 — origin-only, explicit subdomain wildcards):\n * - Matching is on the origin (scheme + host + port) of the RESOLVED URL;\n * path, query, and hash never participate. Default ports are normalized\n * (`https://x.com:443` and `https://x.com` are the same origin).\n * - An exact entry (`https://api.example.com`) matches that origin only.\n * - A wildcard entry (`https://*.example.com`) matches subdomains at any\n * depth (`api.example.com`, `a.b.example.com`) but NOT the apex\n * (`example.com`) — list the apex explicitly if it is also allowed. This\n * keeps the reviewed surface literal: a wildcard grant is a statement\n * about hosts UNDER a domain, never silently about the domain itself.\n * - Scheme and port must match exactly; a wildcard never crosses either.\n *\n * Redirects: this function checks one URL. The caller (the fetch wrapper)\n * must re-check the target origin of every redirect hop — a redirect to a\n * non-allowlisted origin is also a denial.\n *\n * Throws `TypeError` (with remediation) on a malformed `url` — the same\n * input `fetch` would reject — or on a malformed allowlist entry, so a typo\n * in the egress declaration fails loudly in the harness rather than\n * silently never matching.\n */\nexport function isEgressAllowed(\n url: string | URL,\n allowlist: readonly string[],\n): boolean {\n const target = new URL(url);\n\n return allowlist.some((entry) => {\n const parsed = parseEntry(entry);\n if (parsed.protocol !== target.protocol) return false;\n if (parsed.port !== target.port) return false;\n if (parsed.wildcard) {\n return target.hostname.endsWith(`.${parsed.hostname}`);\n }\n return target.hostname === parsed.hostname;\n });\n}\n"]}
1
+ {"version":3,"file":"egress.js","sourceRoot":"","sources":["../../src/context/egress.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,eAAe,GAAG,OAAO,CAAC;AAShC,SAAS,YAAY,CAAC,KAAa,EAAE,MAAc;IACjD,OAAO,IAAI,SAAS,CAClB,2BAA2B,KAAK,iBAAiB,MAAM,IAAI;Q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,IAAI;QACjB,QAAQ;KACT,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,UAAU,eAAe,CAC7B,GAAiB,EACjB,SAA4B;IAE5B,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;IAE5B,OAAO,SAAS,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE;QAC9B,MAAM,MAAM,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC;QACjC,IAAI,MAAM,CAAC,QAAQ,KAAK,MAAM,CAAC,QAAQ;YAAE,OAAO,KAAK,CAAC;QACtD,IAAI,MAAM,CAAC,IAAI,KAAK,MAAM,CAAC,IAAI;YAAE,OAAO,KAAK,CAAC;QAC9C,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC;YACpB,OAAO,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC;QACzD,CAAC;QACD,OAAO,MAAM,CAAC,QAAQ,KAAK,MAAM,CAAC,QAAQ,CAAC;IAC7C,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["/**\n * The egress allowlist matcher (ruling 3) — ONE pure function, shared by the\n * harness mock, the promote-gate check, and the production `ctx.fetch`\n * wrapper, so a test that passes the mock cannot be an egress surprise later.\n */\n\nconst WILDCARD_MARKER = '://*.';\n\ninterface ParsedEntry {\n protocol: string;\n hostname: string;\n port: string;\n wildcard: boolean;\n}\n\nfunction invalidEntry(entry: string, detail: string): TypeError {\n return new TypeError(\n `Egress allowlist entry \"${entry}\" is invalid: ${detail}. ` +\n `Entries are origins only — \"https://api.example.com\" (exact) or ` +\n `\"https://*.example.com\" (subdomain wildcard); scheme + host + optional ` +\n `port, no path, query, hash, or credentials. Fix the entry in the ` +\n `integration's egress declaration.`,\n );\n}\n\nfunction parseEntry(entry: string): ParsedEntry {\n const wildcard = entry.includes(WILDCARD_MARKER);\n const candidate = wildcard ? entry.replace(WILDCARD_MARKER, '://') : entry;\n\n let parsed: URL;\n try {\n parsed = new URL(candidate);\n } catch {\n throw invalidEntry(entry, 'it does not parse as a URL origin');\n }\n\n if (parsed.hostname.includes('*')) {\n throw invalidEntry(\n entry,\n 'wildcards are only supported as a leading \"*.\" on the hostname',\n );\n }\n if (parsed.pathname !== '/' || parsed.search !== '' || parsed.hash !== '') {\n throw invalidEntry(entry, 'it carries a path, query, or hash');\n }\n if (parsed.username !== '' || parsed.password !== '') {\n throw invalidEntry(entry, 'it carries credentials');\n }\n if (parsed.hostname === '') {\n throw invalidEntry(entry, 'it has no hostname');\n }\n\n return {\n protocol: parsed.protocol,\n hostname: parsed.hostname,\n port: parsed.port,\n wildcard,\n };\n}\n\n/**\n * Returns whether `url`'s ORIGIN is covered by the egress allowlist.\n *\n * Semantics (ruling 3 — origin-only, explicit subdomain wildcards):\n * - Matching is on the origin (scheme + host + port) of the RESOLVED URL;\n * path, query, and hash never participate. Default ports are normalized\n * (`https://x.com:443` and `https://x.com` are the same origin).\n * - An exact entry (`https://api.example.com`) matches that origin only.\n * - A wildcard entry (`https://*.example.com`) matches subdomains at any\n * depth (`api.example.com`, `a.b.example.com`) but NOT the apex\n * (`example.com`) — list the apex explicitly if it is also allowed. This\n * keeps the reviewed surface literal: a wildcard grant is a statement\n * about hosts UNDER a domain, never silently about the domain itself.\n * - Scheme and port must match exactly; a wildcard never crosses either.\n *\n * Redirects: this function checks one URL. The caller (the fetch wrapper)\n * must re-check the target origin of every redirect hop — a redirect to a\n * non-allowlisted origin is also a denial.\n *\n * Throws `TypeError` (with remediation) on a malformed `url` — the same\n * input `fetch` would reject — or on a malformed allowlist entry, so a typo\n * in the egress declaration fails loudly in the harness rather than\n * silently never matching.\n */\nexport function isEgressAllowed(\n url: string | URL,\n allowlist: readonly string[],\n): boolean {\n const target = new URL(url);\n\n return allowlist.some((entry) => {\n const parsed = parseEntry(entry);\n if (parsed.protocol !== target.protocol) return false;\n if (parsed.port !== target.port) return false;\n if (parsed.wildcard) {\n return target.hostname.endsWith(`.${parsed.hostname}`);\n }\n return target.hostname === parsed.hostname;\n });\n}\n"]}
@@ -1,10 +1,30 @@
1
+ import type { StorageKeyDeclarationInput, StorageSchemaMap } from './types.js';
1
2
  /**
2
3
  * The shared storage validator (ruling 1) — ONE implementation, used by the
3
4
  * `@ekanos/sdk/testing` mock today and the production `ctx.storage` wrapper
4
5
  * when host wiring lands, so the mock enforces exactly what prod enforces.
5
6
  */
6
- import type { z } from 'zod';
7
- import type { StorageKeyDeclarationInput, StorageSchemaMap } from './types.js';
7
+ /**
8
+ * The synchronous parse every zod schema provides, in both majors.
9
+ * Declarations are typed as Standard Schema (see `@ekanos/integration-schema`)
10
+ * so a partner's zod 3 schema satisfies them in a zod 4 host; storage reads
11
+ * and writes are synchronous, and definition parsing already refuses a schema
12
+ * without `safeParse`, so this is what the storage path calls.
13
+ */
14
+ interface SafeParseSchema {
15
+ safeParse(value: unknown): {
16
+ success: true;
17
+ data: unknown;
18
+ } | {
19
+ success: false;
20
+ error: {
21
+ issues: ReadonlyArray<{
22
+ path: ReadonlyArray<PropertyKey>;
23
+ message: string;
24
+ }>;
25
+ };
26
+ };
27
+ }
8
28
  type StorageScope = 'account' | 'user';
9
29
  /**
10
30
  * Normalizes either declaration form — a bare zod schema, or a
@@ -21,7 +41,7 @@ type StorageScope = 'account' | 'user';
21
41
  * both resolve to `false`. Widening exposure is always an explicit act.
22
42
  */
23
43
  export declare function resolveStorageKeyDeclaration(declaration: StorageKeyDeclarationInput): {
24
- schema: z.ZodType;
44
+ schema: SafeParseSchema;
25
45
  clientReadable: boolean;
26
46
  };
27
47
  /**
@@ -43,7 +63,7 @@ export declare function assertStorageKeyDeclared(args: {
43
63
  scope: StorageScope;
44
64
  key: string;
45
65
  schemas: StorageSchemaMap | undefined;
46
- }): z.ZodType;
66
+ }): SafeParseSchema;
47
67
  /**
48
68
  * Rejects writes and deletes against host-managed read-only data_types
49
69
  * (finding C). ONE implementation for the `@ekanos/sdk/testing` mock and the
@@ -13,7 +13,7 @@ const READ_ONLY_ACCOUNT_DATA_TYPES = new Set(['activation']);
13
13
  function formatIssues(issues) {
14
14
  return issues
15
15
  .map((issue) => {
16
- const path = issue.path.length > 0 ? issue.path.join('.') : '(root)';
16
+ const path = issue.path.length > 0 ? issue.path.map(String).join('.') : '(root)';
17
17
  return ` - ${path}: ${issue.message}`;
18
18
  })
19
19
  .join('\n');
@@ -35,7 +35,10 @@ function formatIssues(issues) {
35
35
  export function resolveStorageKeyDeclaration(declaration) {
36
36
  if (typeof (declaration === null || declaration === void 0 ? void 0 : declaration.safeParse) ===
37
37
  'function') {
38
- return { schema: declaration, clientReadable: false };
38
+ return {
39
+ schema: declaration,
40
+ clientReadable: false,
41
+ };
39
42
  }
40
43
  const descriptor = declaration;
41
44
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"storage-validation.js","sourceRoot":"","sources":["../../src/context/storage-validation.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AASlD;;;;;;;;;GASG;AACH,MAAM,4BAA4B,GAAG,IAAI,GAAG,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC;AAE7D,SAAS,YAAY,CAAC,MAA6B;IACjD,OAAO,MAAM;SACV,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;QACb,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;QACrE,OAAO,OAAO,IAAI,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC;IACzC,CAAC,CAAC;SACD,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,4BAA4B,CAC1C,WAAuC;IAEvC,IACE,OAAO,CAAC,WAA8C,aAA9C,WAAW,u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C;QAC1E,MAAM,IAAI,sBAAsB,CAAC;YAC/B,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,GAAG,EAAE,IAAI,CAAC,GAAG;YACb,IAAI;SACL,CAAC,CAAC;IACL,CAAC;IAED,OAAO,MAAM,CAAC,IAAI,CAAC;AACrB,CAAC","sourcesContent":["/**\n * The shared storage validator (ruling 1) — ONE implementation, used by the\n * `@ekanos/sdk/testing` mock today and the production `ctx.storage` wrapper\n * when host wiring lands, so the mock enforces exactly what prod enforces.\n */\nimport type { z } from 'zod';\n\nimport { StorageValidationError } from './errors';\nimport type {\n StorageKeyDeclaration,\n StorageKeyDeclarationInput,\n StorageSchemaMap,\n} from './types';\n\ntype StorageScope = 'account' | 'user';\n\n/**\n * Account data_types a partner may READ through `ctx.storage` but never\n * write or delete (authz-hardening finding C). `activation` rows are host\n * lifecycle state: the activation flow creates them and admin deactivation\n * removes them. A partner that could write `activation` (any subtype) could\n * re-create its own activation row after an admin deactivated it —\n * self-reactivation. Reads stay allowed: the capability-context proposal\n * (§2.1) deliberately exposes the non-secret activation payload through\n * `ctx.storage.account.get('activation')`.\n */\nconst READ_ONLY_ACCOUNT_DATA_TYPES = new Set(['activation']);\n\nfunction formatIssues(issues: readonly z.ZodIssue[]): string {\n return issues\n .map((issue) => {\n const path = issue.path.length > 0 ? issue.path.join('.') : '(root)';\n return ` - ${path}: ${issue.message}`;\n })\n .join('\\n');\n}\n\n/**\n * Normalizes either declaration form — a bare zod schema, or a\n * `{ schema, clientReadable }` descriptor — into the resolved pair. ONE\n * implementation, so the mock, the production `ctx.storage` wrapper, and the\n * browser-facing storage route all read a declaration the same way.\n *\n * The zod-schema test is duck-typed on `safeParse` rather than `instanceof\n * z.ZodType` on purpose: a partner package may bundle its own zod copy, and a\n * cross-realm schema must not be misread as a descriptor (which would then\n * fail the descriptor branch and report a nonsense error).\n *\n * `clientReadable` FAILS CLOSED: the bare-schema form and an omitted flag\n * both resolve to `false`. Widening exposure is always an explicit act.\n */\nexport function resolveStorageKeyDeclaration(\n declaration: StorageKeyDeclarationInput,\n): { schema: z.ZodType; clientReadable: boolean } {\n if (\n typeof (declaration as { safeParse?: unknown } | null)?.safeParse ===\n 'function'\n ) {\n return { schema: declaration as z.ZodType, clientReadable: false };\n }\n\n const descriptor = declaration as StorageKeyDeclaration;\n\n return {\n schema: descriptor.schema,\n clientReadable: descriptor.clientReadable === true,\n };\n}\n\n/**\n * Whether a declared key opted in to the generic browser-readable storage\n * route. An UNDECLARED key and a declared-but-not-opted-in key both answer\n * `false` — the route must not distinguish them, or it becomes an existence\n * oracle for a partner's server-only key names.\n */\nexport function isStorageKeyClientReadable(args: {\n key: string;\n schemas: StorageSchemaMap | undefined;\n}): boolean {\n const declaration = args.schemas?.[args.key];\n if (!declaration) return false;\n\n return resolveStorageKeyDeclaration(declaration).clientReadable;\n}\n\n/**\n * Resolves the declared schema for a storage key, throwing\n * `StorageValidationError` when the key is undeclared (strict keys). Used\n * directly by `delete`, and by `parseStorageValue` for reads and writes.\n */\nexport function assertStorageKeyDeclared(args: {\n scope: StorageScope;\n key: string;\n schemas: StorageSchemaMap | undefined;\n}): z.ZodType {\n const declaration = args.schemas?.[args.key];\n if (!declaration) {\n throw new StorageValidationError({\n scope: args.scope,\n key: args.key,\n hint:\n `No schema is declared for ${args.scope} storage key \"${args.key}\". ` +\n `Storage keys are strict: declare the key and its zod schema in ` +\n `defineIntegration({ storage: { ${args.scope}: { '${args.key}': z.object({ … }) } } }) ` +\n `(or in createMockContext({ storageSchemas }) in tests) before reading, ` +\n `writing, or deleting it.`,\n });\n }\n\n return resolveStorageKeyDeclaration(declaration).schema;\n}\n\n/**\n * Rejects writes and deletes against host-managed read-only data_types\n * (finding C). ONE implementation for the `@ekanos/sdk/testing` mock and the\n * production `ctx.storage` wrapper, so a write that prod refuses also fails\n * in partner tests. Runs BEFORE the declared-key check so a read-only key\n * reports the real reason rather than \"undeclared\".\n */\nexport function assertStorageKeyWritable(args: {\n scope: StorageScope;\n key: string;\n}): void {\n if (args.scope !== 'account') return;\n\n const slashIndex = args.key.indexOf('/');\n const dataType = slashIndex === -1 ? args.key : args.key.slice(0, slashIndex);\n\n if (READ_ONLY_ACCOUNT_DATA_TYPES.has(dataType)) {\n throw new StorageValidationError({\n scope: args.scope,\n key: args.key,\n hint:\n `Storage key \"${args.key}\" uses the host-managed \"${dataType}\" ` +\n `data_type, which ctx.storage can read but never write or delete. ` +\n `Activation rows are created by the host activation flow and ` +\n `removed by deactivation — an integration cannot (re)create or ` +\n `drop its own activation. Persist integration state under a ` +\n `\"settings\", \"sync_state\", \"metrics_summary\", or \"cache\" key instead.`,\n });\n }\n}\n\n/**\n * Validates one storage value against its declared schema and returns the\n * schema's OUTPUT value (defaults and transforms applied). Throws\n * `StorageValidationError` on an undeclared key or a schema mismatch, with\n * the zod issues formatted into the remediation hint.\n */\nexport function parseStorageValue(args: {\n scope: StorageScope;\n key: string;\n operation: 'read' | 'write';\n schemas: StorageSchemaMap | undefined;\n value: unknown;\n}): unknown {\n const schema = assertStorageKeyDeclared(args);\n const result = schema.safeParse(args.value);\n\n if (!result.success) {\n const issues = formatIssues(result.error.issues);\n const hint =\n args.operation === 'write'\n ? `The value written to ${args.scope} storage key \"${args.key}\" fails ` +\n `its declared schema. Fix the write payload to match the schema ` +\n `declared in defineIntegration({ storage }):\\n${issues}`\n : `The data stored at ${args.scope} storage key \"${args.key}\" no longer ` +\n `matches its declared schema. Handle schema evolution explicitly: ` +\n `widen the schema (z.union with the legacy shape) or migrate to a ` +\n `versioned key, then rewrite the row via set(). Issues:\\n${issues}`;\n throw new StorageValidationError({\n scope: args.scope,\n key: args.key,\n hint,\n });\n }\n\n return result.data;\n}\n"]}
1
+ {"version":3,"file":"storage-validation.js","sourceRoot":"","sources":["../../src/context/storage-validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAmClD;;;;;;;;;GASG;AACH,MAAM,4BAA4B,GAAG,IAAI,GAAG,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AAwB,CAAC,IAAI,CAAC,CAAC;IAC9C,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAE5C,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACpB,MAAM,MAAM,GAAG,YAAY,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QACjD,MAAM,IAAI,GACR,IAAI,CAAC,SAAS,KAAK,OAAO;YACxB,CAAC,CAAC,wBAAwB,IAAI,CAAC,KAAK,iBAAiB,IAAI,CAAC,GAAG,UAAU;gBACrE,iEAAiE;gBACjE,gDAAgD,MAAM,EAAE;YAC1D,CAAC,CAAC,sBAAsB,IAAI,CAAC,KAAK,iBAAiB,IAAI,CAAC,GAAG,cAAc;gBACvE,mEAAmE;gBACnE,mEAAmE;gBACnE,2DAA2D,MAAM,EAAE,CAAC;QAC1E,MAAM,IAAI,sBAAsB,CAAC;YAC/B,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,GAAG,EAAE,IAAI,CAAC,GAAG;YACb,IAAI;SACL,CAAC,CAAC;IACL,CAAC;IAED,OAAO,MAAM,CAAC,IAAI,CAAC;AACrB,CAAC","sourcesContent":["import { StorageValidationError } from './errors';\nimport type {\n StorageKeyDeclaration,\n StorageKeyDeclarationInput,\n StorageSchemaMap,\n} from './types';\n\n/**\n * The shared storage validator (ruling 1) — ONE implementation, used by the\n * `@ekanos/sdk/testing` mock today and the production `ctx.storage` wrapper\n * when host wiring lands, so the mock enforces exactly what prod enforces.\n */\n/**\n * The synchronous parse every zod schema provides, in both majors.\n * Declarations are typed as Standard Schema (see `@ekanos/integration-schema`)\n * so a partner's zod 3 schema satisfies them in a zod 4 host; storage reads\n * and writes are synchronous, and definition parsing already refuses a schema\n * without `safeParse`, so this is what the storage path calls.\n */\ninterface SafeParseSchema {\n safeParse(value: unknown):\n | { success: true; data: unknown }\n | {\n success: false;\n error: {\n issues: ReadonlyArray<{\n path: ReadonlyArray<PropertyKey>;\n message: string;\n }>;\n };\n };\n}\n\ntype StorageScope = 'account' | 'user';\n\n/**\n * Account data_types a partner may READ through `ctx.storage` but never\n * write or delete (authz-hardening finding C). `activation` rows are host\n * lifecycle state: the activation flow creates them and admin deactivation\n * removes them. A partner that could write `activation` (any subtype) could\n * re-create its own activation row after an admin deactivated it —\n * self-reactivation. Reads stay allowed: the capability-context proposal\n * (§2.1) deliberately exposes the non-secret activation payload through\n * `ctx.storage.account.get('activation')`.\n */\nconst READ_ONLY_ACCOUNT_DATA_TYPES = new Set(['activation']);\n\nfunction formatIssues(\n issues: ReadonlyArray<{ path: ReadonlyArray<PropertyKey>; message: string }>,\n): string {\n return issues\n .map((issue) => {\n const path =\n issue.path.length > 0 ? issue.path.map(String).join('.') : '(root)';\n return ` - ${path}: ${issue.message}`;\n })\n .join('\\n');\n}\n\n/**\n * Normalizes either declaration form — a bare zod schema, or a\n * `{ schema, clientReadable }` descriptor — into the resolved pair. ONE\n * implementation, so the mock, the production `ctx.storage` wrapper, and the\n * browser-facing storage route all read a declaration the same way.\n *\n * The zod-schema test is duck-typed on `safeParse` rather than `instanceof\n * z.ZodType` on purpose: a partner package may bundle its own zod copy, and a\n * cross-realm schema must not be misread as a descriptor (which would then\n * fail the descriptor branch and report a nonsense error).\n *\n * `clientReadable` FAILS CLOSED: the bare-schema form and an omitted flag\n * both resolve to `false`. Widening exposure is always an explicit act.\n */\nexport function resolveStorageKeyDeclaration(\n declaration: StorageKeyDeclarationInput,\n): { schema: SafeParseSchema; clientReadable: boolean } {\n if (\n typeof (declaration as { safeParse?: unknown } | null)?.safeParse ===\n 'function'\n ) {\n return {\n schema: declaration as unknown as SafeParseSchema,\n clientReadable: false,\n };\n }\n\n const descriptor = declaration as StorageKeyDeclaration;\n\n return {\n schema: descriptor.schema as unknown as SafeParseSchema,\n clientReadable: descriptor.clientReadable === true,\n };\n}\n\n/**\n * Whether a declared key opted in to the generic browser-readable storage\n * route. An UNDECLARED key and a declared-but-not-opted-in key both answer\n * `false` — the route must not distinguish them, or it becomes an existence\n * oracle for a partner's server-only key names.\n */\nexport function isStorageKeyClientReadable(args: {\n key: string;\n schemas: StorageSchemaMap | undefined;\n}): boolean {\n const declaration = args.schemas?.[args.key];\n if (!declaration) return false;\n\n return resolveStorageKeyDeclaration(declaration).clientReadable;\n}\n\n/**\n * Resolves the declared schema for a storage key, throwing\n * `StorageValidationError` when the key is undeclared (strict keys). Used\n * directly by `delete`, and by `parseStorageValue` for reads and writes.\n */\nexport function assertStorageKeyDeclared(args: {\n scope: StorageScope;\n key: string;\n schemas: StorageSchemaMap | undefined;\n}): SafeParseSchema {\n const declaration = args.schemas?.[args.key];\n if (!declaration) {\n throw new StorageValidationError({\n scope: args.scope,\n key: args.key,\n hint:\n `No schema is declared for ${args.scope} storage key \"${args.key}\". ` +\n `Storage keys are strict: declare the key and its zod schema in ` +\n `defineIntegration({ storage: { ${args.scope}: { '${args.key}': z.object({ … }) } } }) ` +\n `(or in createMockContext({ storageSchemas }) in tests) before reading, ` +\n `writing, or deleting it.`,\n });\n }\n\n return resolveStorageKeyDeclaration(declaration).schema;\n}\n\n/**\n * Rejects writes and deletes against host-managed read-only data_types\n * (finding C). ONE implementation for the `@ekanos/sdk/testing` mock and the\n * production `ctx.storage` wrapper, so a write that prod refuses also fails\n * in partner tests. Runs BEFORE the declared-key check so a read-only key\n * reports the real reason rather than \"undeclared\".\n */\nexport function assertStorageKeyWritable(args: {\n scope: StorageScope;\n key: string;\n}): void {\n if (args.scope !== 'account') return;\n\n const slashIndex = args.key.indexOf('/');\n const dataType = slashIndex === -1 ? args.key : args.key.slice(0, slashIndex);\n\n if (READ_ONLY_ACCOUNT_DATA_TYPES.has(dataType)) {\n throw new StorageValidationError({\n scope: args.scope,\n key: args.key,\n hint:\n `Storage key \"${args.key}\" uses the host-managed \"${dataType}\" ` +\n `data_type, which ctx.storage can read but never write or delete. ` +\n `Activation rows are created by the host activation flow and ` +\n `removed by deactivation — an integration cannot (re)create or ` +\n `drop its own activation. Persist integration state under a ` +\n `\"settings\", \"sync_state\", \"metrics_summary\", or \"cache\" key instead.`,\n });\n }\n}\n\n/**\n * Validates one storage value against its declared schema and returns the\n * schema's OUTPUT value (defaults and transforms applied). Throws\n * `StorageValidationError` on an undeclared key or a schema mismatch, with\n * the zod issues formatted into the remediation hint.\n */\nexport function parseStorageValue(args: {\n scope: StorageScope;\n key: string;\n operation: 'read' | 'write';\n schemas: StorageSchemaMap | undefined;\n value: unknown;\n}): unknown {\n const schema = assertStorageKeyDeclared(args);\n const result = schema.safeParse(args.value);\n\n if (!result.success) {\n const issues = formatIssues(result.error.issues);\n const hint =\n args.operation === 'write'\n ? `The value written to ${args.scope} storage key \"${args.key}\" fails ` +\n `its declared schema. Fix the write payload to match the schema ` +\n `declared in defineIntegration({ storage }):\\n${issues}`\n : `The data stored at ${args.scope} storage key \"${args.key}\" no longer ` +\n `matches its declared schema. Handle schema evolution explicitly: ` +\n `widen the schema (z.union with the legacy shape) or migrate to a ` +\n `versioned key, then rewrite the row via set(). Issues:\\n${issues}`;\n throw new StorageValidationError({\n scope: args.scope,\n key: args.key,\n hint,\n });\n }\n\n return result.data;\n}\n"]}