@flamingo-stack/openframe-frontend-core 0.0.295 → 0.0.296-snapshot.20260621021605
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.
- package/README.md +9 -0
- package/dist/{chunk-7RIYT7ZH.js → chunk-2QG57XOJ.js} +1067 -205
- package/dist/chunk-2QG57XOJ.js.map +1 -0
- package/dist/{chunk-7KXD7CWD.js → chunk-3JIQVE7T.js} +9 -15
- package/dist/{chunk-7KXD7CWD.js.map → chunk-3JIQVE7T.js.map} +1 -1
- package/dist/{chunk-FT4FCV7L.cjs → chunk-4PSQS3SW.cjs} +7 -9
- package/dist/chunk-4PSQS3SW.cjs.map +1 -0
- package/dist/{chunk-OOKKGOPQ.js → chunk-4TLE6VLU.js} +30 -24
- package/dist/chunk-4TLE6VLU.js.map +1 -0
- package/dist/{chunk-6IBA2MQV.cjs → chunk-53FUMSZ5.cjs} +40 -46
- package/dist/chunk-53FUMSZ5.cjs.map +1 -0
- package/dist/{chunk-D3LEFMOA.cjs → chunk-54KNMC2R.cjs} +3 -3
- package/dist/{chunk-D3LEFMOA.cjs.map → chunk-54KNMC2R.cjs.map} +1 -1
- package/dist/{chunk-EYEW6PTA.cjs → chunk-6C526VNN.cjs} +358 -118
- package/dist/chunk-6C526VNN.cjs.map +1 -0
- package/dist/{chunk-5O6N3BKR.cjs → chunk-7OVGB2DQ.cjs} +19 -25
- package/dist/chunk-7OVGB2DQ.cjs.map +1 -0
- package/dist/{chunk-6GCI7JOE.js → chunk-AD6C23QY.js} +8 -7
- package/dist/{chunk-6GCI7JOE.js.map → chunk-AD6C23QY.js.map} +1 -1
- package/dist/chunk-F5OB2YAL.cjs +144 -0
- package/dist/chunk-F5OB2YAL.cjs.map +1 -0
- package/dist/chunk-FBWXMMRB.cjs +2 -0
- package/dist/chunk-FBWXMMRB.cjs.map +1 -0
- package/dist/{chunk-YIGPRLQY.cjs → chunk-FCDQNTDG.cjs} +21 -20
- package/dist/chunk-FCDQNTDG.cjs.map +1 -0
- package/dist/{chunk-XXI7BNB6.cjs → chunk-FQOTC3UU.cjs} +321 -18
- package/dist/chunk-FQOTC3UU.cjs.map +1 -0
- package/dist/{chunk-INDQMNP6.cjs → chunk-GUTS7HGA.cjs} +11658 -2146
- package/dist/chunk-GUTS7HGA.cjs.map +1 -0
- package/dist/chunk-GZ4C3XW6.js +2 -0
- package/dist/chunk-GZ4C3XW6.js.map +1 -0
- package/dist/{chunk-HOVJGXF7.js → chunk-IL47XWV5.js} +8 -14
- package/dist/{chunk-HOVJGXF7.js.map → chunk-IL47XWV5.js.map} +1 -1
- package/dist/{chunk-LCNMR277.js → chunk-IZ7JSBFP.js} +1 -1
- package/dist/chunk-IZ7JSBFP.js.map +1 -0
- package/dist/{chunk-5IJ46KAV.js → chunk-JALO4TAZ.js} +360 -57
- package/dist/chunk-JALO4TAZ.js.map +1 -0
- package/dist/{chunk-AQOWFSMB.cjs → chunk-L6PSSIUQ.cjs} +1 -1
- package/dist/chunk-L6PSSIUQ.cjs.map +1 -0
- package/dist/{chunk-J3RDKZ32.js → chunk-L7ULJKG7.js} +6 -10
- package/dist/{chunk-J3RDKZ32.js.map → chunk-L7ULJKG7.js.map} +1 -1
- package/dist/{chunk-6BZEAPNT.js → chunk-PC746XCO.js} +15120 -5608
- package/dist/chunk-PC746XCO.js.map +1 -0
- package/dist/{chunk-3ZXUQQL4.js → chunk-PI4WSYQV.js} +2 -2
- package/dist/{chunk-E4XABBSU.js → chunk-PWQUAVA3.js} +338 -98
- package/dist/chunk-PWQUAVA3.js.map +1 -0
- package/dist/chunk-SA2WPJVO.js +144 -0
- package/dist/chunk-SA2WPJVO.js.map +1 -0
- package/dist/{chunk-ETACGX2A.cjs → chunk-UNVE2SDJ.cjs} +37 -31
- package/dist/chunk-UNVE2SDJ.cjs.map +1 -0
- package/dist/{chunk-5E2HOSSH.cjs → chunk-WMSTJAZT.cjs} +913 -51
- package/dist/chunk-WMSTJAZT.cjs.map +1 -0
- package/dist/{chunk-EJXHZX2E.js → chunk-X4DOXQRT.js} +4 -6
- package/dist/{chunk-EJXHZX2E.js.map → chunk-X4DOXQRT.js.map} +1 -1
- package/dist/{chunk-A2YL7QRX.cjs → chunk-YBYI62OE.cjs} +33 -37
- package/dist/chunk-YBYI62OE.cjs.map +1 -0
- package/dist/components/case-studies/index.cjs +126 -0
- package/dist/components/case-studies/index.cjs.map +1 -0
- package/dist/components/case-studies/index.d.ts +2 -0
- package/dist/components/case-studies/index.d.ts.map +1 -0
- package/dist/components/case-studies/index.js +126 -0
- package/dist/components/case-studies/index.js.map +1 -0
- package/dist/components/case-studies/share-experience-section.d.ts +48 -0
- package/dist/components/case-studies/share-experience-section.d.ts.map +1 -0
- package/dist/components/chat/chat-container.d.ts.map +1 -1
- package/dist/components/chat/error-message-display.d.ts.map +1 -1
- package/dist/components/chat/index.cjs +8 -18
- package/dist/components/chat/index.cjs.map +1 -1
- package/dist/components/chat/index.js +75 -85
- package/dist/components/chat/types/component.types.d.ts +2 -0
- package/dist/components/chat/types/component.types.d.ts.map +1 -1
- package/dist/components/contact/index.cjs +8 -15
- package/dist/components/contact/index.cjs.map +1 -1
- package/dist/components/contact/index.js +7 -14
- package/dist/components/docs/doc-viewer.d.ts +39 -2
- package/dist/components/docs/doc-viewer.d.ts.map +1 -1
- package/dist/components/docs/docs-hub-page.d.ts +46 -0
- package/dist/components/docs/docs-hub-page.d.ts.map +1 -0
- package/dist/components/docs/index.cjs +17 -9
- package/dist/components/docs/index.cjs.map +1 -1
- package/dist/components/docs/index.d.ts +4 -0
- package/dist/components/docs/index.d.ts.map +1 -1
- package/dist/components/docs/index.js +16 -8
- package/dist/components/docs/skeletons.d.ts +32 -0
- package/dist/components/docs/skeletons.d.ts.map +1 -0
- package/dist/components/docs/use-docs-resolve-link.d.ts +20 -0
- package/dist/components/docs/use-docs-resolve-link.d.ts.map +1 -0
- package/dist/components/docs/use-document-tree.d.ts.map +1 -1
- package/dist/components/embeds/embed-container.d.ts +37 -0
- package/dist/components/embeds/embed-container.d.ts.map +1 -0
- package/dist/components/embeds/embed-iframe.d.ts.map +1 -1
- package/dist/components/embeds/file-download-card.d.ts +18 -0
- package/dist/components/embeds/file-download-card.d.ts.map +1 -0
- package/dist/components/embeds/index.cjs +38 -15
- package/dist/components/embeds/index.cjs.map +1 -1
- package/dist/components/embeds/index.d.ts +8 -0
- package/dist/components/embeds/index.d.ts.map +1 -1
- package/dist/components/embeds/index.js +40 -17
- package/dist/components/embeds/linkedin-embed-client.d.ts +8 -0
- package/dist/components/embeds/linkedin-embed-client.d.ts.map +1 -0
- package/dist/components/embeds/markdown-image.d.ts +5 -0
- package/dist/components/embeds/markdown-image.d.ts.map +1 -0
- package/dist/components/embeds/reddit-embed-client.d.ts +7 -0
- package/dist/components/embeds/reddit-embed-client.d.ts.map +1 -0
- package/dist/components/embeds/rich-markdown-runtime.d.ts +46 -0
- package/dist/components/embeds/rich-markdown-runtime.d.ts.map +1 -0
- package/dist/components/embeds/twitter-embed-client.d.ts +8 -0
- package/dist/components/embeds/twitter-embed-client.d.ts.map +1 -0
- package/dist/components/faq/index.cjs +9 -16
- package/dist/components/faq/index.cjs.map +1 -1
- package/dist/components/faq/index.js +8 -15
- package/dist/components/features/index.cjs +8 -16
- package/dist/components/features/index.cjs.map +1 -1
- package/dist/components/features/index.js +24 -32
- package/dist/components/features/notifications/notification-drawer.d.ts.map +1 -1
- package/dist/components/features/notifications/notifications-context.d.ts +5 -1
- package/dist/components/features/notifications/notifications-context.d.ts.map +1 -1
- package/dist/components/index.cjs +257 -452
- package/dist/components/index.cjs.map +1 -1
- package/dist/components/index.js +781 -976
- package/dist/components/index.js.map +1 -1
- package/dist/components/layout/page-header.d.ts +78 -0
- package/dist/components/layout/page-header.d.ts.map +1 -0
- package/dist/components/layout/page-layout.d.ts +10 -1
- package/dist/components/layout/page-layout.d.ts.map +1 -1
- package/dist/components/layout/page-with-header.d.ts +67 -0
- package/dist/components/layout/page-with-header.d.ts.map +1 -0
- package/dist/components/layout/title-block.d.ts +17 -1
- package/dist/components/layout/title-block.d.ts.map +1 -1
- package/dist/components/navigation/index.cjs +7 -15
- package/dist/components/navigation/index.cjs.map +1 -1
- package/dist/components/navigation/index.js +9 -17
- package/dist/components/onboarding-guides/index.cjs +35 -36
- package/dist/components/onboarding-guides/index.cjs.map +1 -1
- package/dist/components/onboarding-guides/index.js +13 -14
- package/dist/components/onboarding-guides/index.js.map +1 -1
- package/dist/components/onboarding-guides/onboarding-guide-detail-view.d.ts +1 -1
- package/dist/components/onboarding-guides/onboarding-guide-detail-view.d.ts.map +1 -1
- package/dist/components/related-content/index.cjs +9 -16
- package/dist/components/related-content/index.cjs.map +1 -1
- package/dist/components/related-content/index.js +8 -15
- package/dist/components/shared/dev-section/dev-section-page.d.ts +9 -0
- package/dist/components/shared/dev-section/dev-section-page.d.ts.map +1 -1
- package/dist/components/shared/dev-section/dev-section-view.d.ts.map +1 -1
- package/dist/components/shared/dev-section/index.d.ts +1 -1
- package/dist/components/shared/dev-section/index.d.ts.map +1 -1
- package/dist/components/shared/doc-search/use-doc-search.d.ts.map +1 -1
- package/dist/components/shared/legal-document/legal-document-page.d.ts.map +1 -1
- package/dist/components/shared/product-release/release-detail-page.d.ts.map +1 -1
- package/dist/components/tickets/index.cjs +100 -112
- package/dist/components/tickets/index.cjs.map +1 -1
- package/dist/components/tickets/index.js +20 -32
- package/dist/components/tickets/index.js.map +1 -1
- package/dist/components/ui/button/split-button.d.ts.map +1 -1
- package/dist/components/ui/file-manager/index.cjs +50 -52
- package/dist/components/ui/file-manager/index.cjs.map +1 -1
- package/dist/components/ui/file-manager/index.js +4 -6
- package/dist/components/ui/file-manager/index.js.map +1 -1
- package/dist/components/ui/index.cjs +13 -19
- package/dist/components/ui/index.cjs.map +1 -1
- package/dist/components/ui/index.d.ts +2 -0
- package/dist/components/ui/index.d.ts.map +1 -1
- package/dist/components/ui/index.js +133 -139
- package/dist/components/ui/release-changelog-section.d.ts +6 -2
- package/dist/components/ui/release-changelog-section.d.ts.map +1 -1
- package/dist/components/ui/rich-markdown-renderer.d.ts +34 -0
- package/dist/components/ui/rich-markdown-renderer.d.ts.map +1 -0
- package/dist/components/ui/simple-markdown-renderer.d.ts +2 -8
- package/dist/components/ui/simple-markdown-renderer.d.ts.map +1 -1
- package/dist/contexts/chat-runtime-context.d.ts +14 -0
- package/dist/contexts/chat-runtime-context.d.ts.map +1 -1
- package/dist/contexts/index.cjs +3 -3
- package/dist/contexts/index.js +5 -5
- package/dist/embed-shims/index.cjs +3 -3
- package/dist/embed-shims/index.cjs.map +1 -1
- package/dist/embed-shims/index.js +4 -4
- package/dist/hooks/index.cjs +4 -9
- package/dist/hooks/index.cjs.map +1 -1
- package/dist/hooks/index.js +6 -11
- package/dist/index.cjs +14 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +362 -368
- package/dist/types/doc-source.d.ts +31 -1
- package/dist/types/doc-source.d.ts.map +1 -1
- package/dist/utils/index.cjs +4 -0
- package/dist/utils/index.cjs.map +1 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +4 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/page-header-constants.d.ts +15 -0
- package/dist/utils/page-header-constants.d.ts.map +1 -0
- package/dist/utils/social-embed-cache.d.ts +29 -0
- package/dist/utils/social-embed-cache.d.ts.map +1 -0
- package/package.json +7 -1
- package/src/components/case-studies/index.ts +4 -0
- package/src/components/case-studies/share-experience-section.tsx +185 -0
- package/src/components/chat/chat-container.tsx +5 -7
- package/src/components/chat/embeddable-chat.tsx +1 -1
- package/src/components/chat/error-message-display.tsx +49 -31
- package/src/components/chat/types/component.types.ts +2 -0
- package/src/components/docs/doc-viewer.tsx +111 -19
- package/src/components/docs/docs-hub-page.tsx +149 -0
- package/src/components/docs/index.ts +17 -0
- package/src/components/docs/skeletons.tsx +138 -0
- package/src/components/docs/use-docs-resolve-link.ts +52 -0
- package/src/components/docs/use-document-tree.ts +21 -0
- package/src/components/embeds/embed-container.tsx +80 -0
- package/src/components/embeds/embed-iframe.tsx +7 -9
- package/src/components/embeds/file-download-card.tsx +54 -0
- package/src/components/embeds/index.ts +30 -0
- package/src/components/embeds/linkedin-embed-client.tsx +100 -0
- package/src/components/embeds/markdown-image.tsx +88 -0
- package/src/components/embeds/og-link-preview.tsx +13 -13
- package/src/components/embeds/reddit-embed-client.tsx +550 -0
- package/src/components/embeds/rich-markdown-runtime.tsx +79 -0
- package/src/components/embeds/twitter-embed-client.tsx +308 -0
- package/src/components/features/notifications/notification-drawer.tsx +18 -7
- package/src/components/features/notifications/notifications-context.tsx +7 -0
- package/src/components/layout/page-header.tsx +182 -0
- package/src/components/layout/page-layout.tsx +14 -1
- package/src/components/layout/page-with-header.tsx +110 -0
- package/src/components/layout/title-block.tsx +40 -62
- package/src/components/onboarding-guides/onboarding-guide-detail-view.tsx +3 -3
- package/src/components/shared/dev-section/dev-section-page.tsx +9 -1
- package/src/components/shared/dev-section/dev-section-view.tsx +14 -9
- package/src/components/shared/dev-section/index.ts +1 -1
- package/src/components/shared/doc-search/use-doc-search.ts +7 -3
- package/src/components/shared/legal-document/legal-document-page.tsx +2 -2
- package/src/components/shared/product-release/release-detail-page.tsx +6 -4
- package/src/components/ui/button/split-button.tsx +5 -2
- package/src/components/ui/index.ts +2 -0
- package/src/components/ui/release-changelog-section.tsx +7 -2
- package/src/components/ui/rich-markdown-renderer.tsx +1203 -0
- package/src/components/ui/simple-markdown-renderer.tsx +7 -11
- package/src/contexts/chat-runtime-context.tsx +14 -0
- package/src/stories/NotificationDrawer.stories.tsx +2 -0
- package/src/types/doc-source.ts +33 -1
- package/src/utils/index.ts +1 -0
- package/src/utils/page-header-constants.ts +15 -0
- package/src/utils/social-embed-cache.ts +391 -0
- package/dist/chunk-26PKDALD.js +0 -2379
- package/dist/chunk-26PKDALD.js.map +0 -1
- package/dist/chunk-3MCHAFHB.js +0 -89
- package/dist/chunk-3MCHAFHB.js.map +0 -1
- package/dist/chunk-3XIB4VKS.cjs +0 -619
- package/dist/chunk-3XIB4VKS.cjs.map +0 -1
- package/dist/chunk-4W7NYJ3B.cjs +0 -3009
- package/dist/chunk-4W7NYJ3B.cjs.map +0 -1
- package/dist/chunk-5E2HOSSH.cjs.map +0 -1
- package/dist/chunk-5IJ46KAV.js.map +0 -1
- package/dist/chunk-5O6N3BKR.cjs.map +0 -1
- package/dist/chunk-6BZEAPNT.js.map +0 -1
- package/dist/chunk-6IBA2MQV.cjs.map +0 -1
- package/dist/chunk-6JINAOI7.cjs +0 -311
- package/dist/chunk-6JINAOI7.cjs.map +0 -1
- package/dist/chunk-7RIYT7ZH.js.map +0 -1
- package/dist/chunk-A2YL7QRX.cjs.map +0 -1
- package/dist/chunk-AQOWFSMB.cjs.map +0 -1
- package/dist/chunk-E4XABBSU.js.map +0 -1
- package/dist/chunk-ETACGX2A.cjs.map +0 -1
- package/dist/chunk-EYEW6PTA.cjs.map +0 -1
- package/dist/chunk-FQJK446R.js +0 -1606
- package/dist/chunk-FQJK446R.js.map +0 -1
- package/dist/chunk-FT4FCV7L.cjs.map +0 -1
- package/dist/chunk-INDQMNP6.cjs.map +0 -1
- package/dist/chunk-J54Z3OCR.cjs +0 -1606
- package/dist/chunk-J54Z3OCR.cjs.map +0 -1
- package/dist/chunk-KXCRGTRN.cjs +0 -2379
- package/dist/chunk-KXCRGTRN.cjs.map +0 -1
- package/dist/chunk-LCNMR277.js.map +0 -1
- package/dist/chunk-LFGGF7OT.cjs +0 -449
- package/dist/chunk-LFGGF7OT.cjs.map +0 -1
- package/dist/chunk-M2OCXTNT.js +0 -311
- package/dist/chunk-M2OCXTNT.js.map +0 -1
- package/dist/chunk-NSPOYUBH.js +0 -3009
- package/dist/chunk-NSPOYUBH.js.map +0 -1
- package/dist/chunk-OOKKGOPQ.js.map +0 -1
- package/dist/chunk-OQ6X7ZOC.js +0 -449
- package/dist/chunk-OQ6X7ZOC.js.map +0 -1
- package/dist/chunk-POKKCWKF.js +0 -354
- package/dist/chunk-POKKCWKF.js.map +0 -1
- package/dist/chunk-TFSYSWPS.cjs +0 -89
- package/dist/chunk-TFSYSWPS.cjs.map +0 -1
- package/dist/chunk-XXI7BNB6.cjs.map +0 -1
- package/dist/chunk-YD43AKI5.js +0 -619
- package/dist/chunk-YD43AKI5.js.map +0 -1
- package/dist/chunk-YETA25JW.cjs +0 -354
- package/dist/chunk-YETA25JW.cjs.map +0 -1
- package/dist/chunk-YIGPRLQY.cjs.map +0 -1
- /package/dist/{chunk-3ZXUQQL4.js.map → chunk-PI4WSYQV.js.map} +0 -0
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/embeds/embed-iframe.tsx","../src/components/embeds/pdf-viewer.tsx","../src/components/embeds/google-sheets-viewer.tsx","../src/components/embeds/figma-embed.tsx","../src/components/embeds/og-link-preview.tsx"],"sourcesContent":["\"use client\"\n\nimport React, { useState, useCallback, useRef, useEffect } from 'react'\n\n/** Loading skeleton for iframe embeds — matches project skeleton pattern */\nfunction EmbedLoadingSkeleton({ height }: { height?: string }) {\n return (\n <div\n className=\"w-full rounded-lg border border-ods-border overflow-hidden bg-ods-skeleton animate-pulse\"\n style={{ height: height || 'calc(100vh - 250px)' }}\n >\n <div className=\"flex flex-col items-center justify-center h-full gap-4\">\n <div className=\"w-12 h-12 rounded-lg bg-ods-card\" />\n <div className=\"h-4 w-48 rounded bg-ods-card\" />\n <div className=\"h-3 w-32 rounded bg-ods-card\" />\n </div>\n </div>\n )\n}\n\nexport interface EmbedIframeProps {\n /** The URL to embed */\n src: string\n /** Accessible title for the iframe */\n title: string\n /** Additional class names for the outer container */\n className?: string\n /** Container height (CSS value). Defaults to `calc(100vh - 250px)` */\n height?: string\n /** iframe `allow` attribute */\n allow?: string\n /** iframe `referrerPolicy` attribute */\n referrerPolicy?: React.IframeHTMLAttributes<HTMLIFrameElement>['referrerPolicy']\n /** iframe `loading` attribute */\n loading?: 'eager' | 'lazy'\n /** iframe `allowFullScreen` attribute */\n allowFullScreen?: boolean\n}\n\n/**\n * Base iframe wrapper with loading skeleton and proper memory cleanup.\n *\n * Prevents memory leaks by:\n * - Using `key={src}` to force full unmount/remount when src changes\n * - Setting iframe src to about:blank on unmount to release the embedded document\n * - Resetting loaded state when src changes\n */\nexport function EmbedIframe({\n src,\n title,\n className,\n height,\n allow,\n referrerPolicy,\n loading,\n allowFullScreen,\n}: EmbedIframeProps) {\n const [isLoaded, setIsLoaded] = useState(false)\n const iframeRef = useRef<HTMLIFrameElement>(null)\n const handleLoad = useCallback(() => setIsLoaded(true), [])\n\n useEffect(() => {\n setIsLoaded(false)\n }, [src])\n\n useEffect(() => {\n const iframe = iframeRef.current\n return () => {\n if (iframe) {\n try {\n iframe.src = 'about:blank'\n } catch {\n // Cross-origin iframes may throw — safe to ignore\n }\n }\n }\n }, [src])\n\n const resolvedHeight = height || 'calc(100vh - 250px)'\n\n return (\n <>\n {!isLoaded && <EmbedLoadingSkeleton height={resolvedHeight} />}\n <div\n className={`w-full rounded-lg border border-ods-border overflow-hidden ${!isLoaded ? 'h-0 overflow-hidden' : ''} ${className || ''}`}\n style={isLoaded ? { height: resolvedHeight } : undefined}\n >\n <iframe\n key={src}\n ref={iframeRef}\n src={src}\n className=\"w-full h-full border-0\"\n title={title}\n onLoad={handleLoad}\n allow={allow}\n referrerPolicy={referrerPolicy}\n loading={loading}\n allowFullScreen={allow?.includes('fullscreen') ? undefined : allowFullScreen}\n />\n </div>\n </>\n )\n}\n","\"use client\"\n\nimport React from 'react'\nimport { Button } from '../ui'\nimport { Download, Eye } from 'lucide-react'\nimport { AdobePdfIcon } from '../icons-v2-generated'\nimport { EmbedIframe } from './embed-iframe'\n\nexport interface PdfViewerProps {\n src: string\n fileName?: string\n onPreview?: () => void\n onDownload?: () => void\n height?: string\n}\n\nexport function PdfViewer({ src, fileName, onPreview, onDownload, height }: PdfViewerProps) {\n const displayName = fileName || 'PDF Document'\n\n if (!src) {\n return (\n <div className=\"flex flex-col items-center justify-center py-16 text-center\">\n <AdobePdfIcon className=\"w-16 h-16 text-ods-text-secondary mb-4\" />\n <p className=\"text-ods-text-secondary\">PDF file not available</p>\n </div>\n )\n }\n\n return (\n <div className=\"space-y-4\">\n <div className=\"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between\">\n <div className=\"flex items-center gap-2 min-w-0\">\n <AdobePdfIcon className=\"w-5 h-5 shrink-0\" />\n <h2 className=\"text-xl font-semibold text-ods-text-primary truncate\">{displayName}</h2>\n </div>\n <div className=\"flex items-center gap-2 w-full sm:w-auto\">\n <Button\n variant=\"outline\"\n size=\"small-legacy\"\n href={onPreview ? undefined : src}\n openInNewTab={!onPreview}\n onClick={onPreview}\n leftIcon={<Eye className=\"w-4 h-4\" />}\n className=\"flex-1 sm:flex-initial\"\n >\n Preview\n </Button>\n <Button\n variant=\"outline\"\n size=\"small-legacy\"\n href={onDownload ? undefined : src}\n openInNewTab={!onDownload}\n onClick={onDownload}\n leftIcon={<Download className=\"w-4 h-4\" />}\n className=\"flex-1 sm:flex-initial\"\n >\n Download\n </Button>\n </div>\n </div>\n <EmbedIframe src={src} title={displayName} height={height} />\n </div>\n )\n}\n","\"use client\"\n\nimport React from 'react'\nimport { Button } from '../ui'\nimport { ExternalLink } from 'lucide-react'\nimport { GoogleSheetsIcon } from '../icons-v2-generated'\nimport { EmbedIframe } from './embed-iframe'\nimport { toGoogleSheetsEmbedUrl, toGoogleSheetsOriginalUrl } from '../../utils/embed-url-converters'\n\nexport interface GoogleSheetsViewerProps {\n externalUrl: string\n fileName?: string\n height?: string\n}\n\nexport function GoogleSheetsViewer({ externalUrl, fileName, height }: GoogleSheetsViewerProps) {\n const displayName = fileName || 'Google Sheet'\n\n if (!externalUrl) {\n return (\n <div className=\"flex flex-col items-center justify-center py-16 text-center\">\n <GoogleSheetsIcon className=\"w-16 h-16 text-ods-text-secondary mb-4\" />\n <p className=\"text-ods-text-secondary\">Google Sheet URL not configured</p>\n </div>\n )\n }\n\n return (\n <div className=\"space-y-4\">\n <div className=\"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between\">\n <div className=\"flex items-center gap-2 min-w-0\">\n <GoogleSheetsIcon className=\"w-5 h-5 shrink-0\" />\n <h2 className=\"text-xl font-semibold text-ods-text-primary truncate\">{displayName}</h2>\n </div>\n <Button\n variant=\"outline\"\n size=\"small-legacy\"\n href={toGoogleSheetsOriginalUrl(externalUrl)}\n openInNewTab\n leftIcon={<GoogleSheetsIcon className=\"w-4 h-4\" />}\n rightIcon={<ExternalLink className=\"w-4 h-4\" />}\n className=\"w-full sm:w-auto\"\n >\n Open in Google Sheets\n </Button>\n </div>\n <EmbedIframe\n src={toGoogleSheetsEmbedUrl(externalUrl)}\n title={displayName}\n height={height}\n />\n </div>\n )\n}\n","'use client'\n\nimport { useState } from 'react'\nimport { Button, ToggleGroup, ToggleGroupItem } from '../ui'\nimport { FigmaIcon } from '../icons-v2-generated'\nimport { ExternalLink, Play, LayoutGrid } from 'lucide-react'\nimport { toFigmaEmbedUrl, toFigmaOriginalUrl, isFigmaSlidesUrl } from '../../utils/embed-url-converters'\nimport { EmbedIframe } from './embed-iframe'\n\nexport interface FigmaEmbedProps {\n /** Any Figma URL (design/file/proto/board/slides/deck) or an already-resolved embed URL. */\n url: string\n /** Heading shown above the embed. Defaults to \"Figma Design\". */\n title?: string\n /**\n * iframe height (CSS value). The data-room document viewer omits it (full\n * height, `calc(100vh - 250px)`); inline markdown passes e.g. `\"70vh\"` so the\n * embed sits naturally inside article content.\n */\n height?: string\n /** iframe loading strategy. Defaults to `\"lazy\"`; the data-room viewer passes `\"eager\"`. */\n loading?: 'eager' | 'lazy'\n}\n\ntype SlidesView = 'present' | 'browse'\n\n/**\n * Two-state present/browse toggle for Figma Slides. `present` (default) uses\n * Figma's deck viewer (full-bleed slide + `‹ n/N ›` nav bar + keyboard nav);\n * `browse` uses the thumbnail-rail + zoom viewer.\n */\nfunction SlidesViewToggle({\n view,\n onChange,\n}: {\n view: SlidesView\n onChange: (v: SlidesView) => void\n}) {\n const options: { key: SlidesView; label: string; Icon: typeof Play }[] = [\n { key: 'present', label: 'Present', Icon: Play },\n { key: 'browse', label: 'Browse', Icon: LayoutGrid },\n ]\n return (\n <ToggleGroup\n type=\"single\"\n value={view}\n onValueChange={(v: string) => {\n if (v && v !== view) onChange(v as SlidesView)\n }}\n aria-label=\"Figma slides view mode\"\n className=\"flex shrink-0 items-center gap-0.5 rounded-lg border border-ods-border bg-ods-card p-0.5\"\n >\n {options.map(({ key, label, Icon }) => {\n const active = view === key\n return (\n <ToggleGroupItem\n key={key}\n value={key}\n aria-label={label}\n className={`flex items-center gap-1.5 rounded-md px-2.5 py-1 text-sm font-medium transition-colors ${\n active\n ? 'bg-ods-accent text-ods-text-on-accent'\n : 'text-ods-text-secondary hover:text-ods-text-primary hover:bg-ods-bg-hover'\n }`}\n >\n <Icon className=\"h-4 w-4 shrink-0\" />\n {label}\n </ToggleGroupItem>\n )\n })}\n </ToggleGroup>\n )\n}\n\n/**\n * Single source of truth for every Figma surface — the data-room document viewer\n * and in-article markdown both render this. A header (icon + title + \"Open in\n * Figma\") over an interactive Figma iframe, built from the canonical\n * `toFigmaEmbedUrl` / `toFigmaOriginalUrl` converters + the shared `<EmbedIframe>`.\n * Only height/loading differ per surface.\n *\n * For Slides decks, a present/browse toggle (default = present) lets viewers flip\n * slides with Figma's native nav bar + keyboard, or switch to the thumbnail-rail\n * browse view.\n */\nexport function FigmaEmbed({ url, title, height, loading = 'lazy' }: FigmaEmbedProps) {\n const [view, setView] = useState<SlidesView>('present')\n const isSlides = url ? isFigmaSlidesUrl(url) : false\n const embedSrc = url ? toFigmaEmbedUrl(url, { slidesView: view }) : null\n const originalUrl = (() => {\n if (!url) return null\n try {\n const parsed = new URL(toFigmaOriginalUrl(url))\n const host = parsed.hostname.toLowerCase()\n const okHost = host === 'figma.com' || host.endsWith('.figma.com')\n const okProtocol = parsed.protocol === 'https:' || parsed.protocol === 'http:'\n return okHost && okProtocol ? parsed.toString() : null\n } catch {\n return null\n }\n })()\n const heading = title || 'Figma Design'\n\n return (\n <div className=\"my-6 space-y-3\">\n <div className=\"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between\">\n <div className=\"flex items-center gap-2 min-w-0\">\n <FigmaIcon className=\"w-5 h-5 shrink-0\" />\n <span className=\"font-sans text-base font-semibold text-ods-text-primary truncate\">\n {heading}\n </span>\n </div>\n <div className=\"flex flex-col gap-2 sm:flex-row sm:items-center\">\n {isSlides && embedSrc && <SlidesViewToggle view={view} onChange={setView} />}\n {originalUrl && (\n <Button\n variant=\"outline\"\n size=\"small-legacy\"\n href={originalUrl}\n openInNewTab\n leftIcon={<FigmaIcon className=\"w-4 h-4\" />}\n rightIcon={<ExternalLink className=\"w-4 h-4\" />}\n className=\"w-full sm:w-auto\"\n >\n Open in Figma\n </Button>\n )}\n </div>\n </div>\n {embedSrc ? (\n <EmbedIframe\n src={embedSrc}\n title={heading}\n allow=\"clipboard-write; clipboard-read; fullscreen\"\n loading={loading}\n height={height}\n allowFullScreen\n />\n ) : (\n <div className=\"flex flex-col items-center justify-center py-16 text-center\">\n <FigmaIcon className=\"w-16 h-16 text-ods-text-secondary mb-4\" />\n <p className=\"text-ods-text-secondary\">Figma URL not configured</p>\n </div>\n )}\n </div>\n )\n}\n","\"use client\"\n\nimport React, { useState, useEffect, Component, ReactNode } from 'react'\nimport Image from '../../embed-shims/next-image'\nimport { useImageEdgeColor } from '../../hooks'\n\n/**\n * Open-Graph metadata returned by the consumer's scrape endpoint.\n *\n * The shape MUST match the JSON the OG endpoint serves at `ogEndpointPath`.\n * The hub's `/api/blog/og-scraper` returns exactly these fields — embedders\n * with a different endpoint must return the same shape (or adapt at the\n * route boundary). Keeps the consumer surface trivial: one URL → one card.\n */\nexport interface OGData {\n title: string\n description: string\n image: string\n originalImage?: string\n url: string\n siteName: string\n type: string\n favicon: string\n}\n\ninterface ErrorBoundaryProps {\n children: ReactNode\n fallback: ReactNode\n}\n\ninterface ErrorBoundaryState {\n hasError: boolean\n}\n\n/**\n * Tiny error boundary tailored for OG link previews — caught errors quietly\n * fall back to the `fallback` prop (typically a plain hyperlink) so a single\n * broken third-party preview can't crash a whole article view.\n *\n * Named `OGLinkErrorBoundary` (not the generic `ErrorBoundary`) because the\n * lib already exports a separate `ErrorBoundary` from\n * `components/features/error-boundary.tsx`. The top-level `components/index.ts`\n * barrel re-exports both `./embeds` and `./features` via `export *`, so a\n * second `ErrorBoundary` here collides as TS2308.\n */\nexport class OGLinkErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {\n constructor(props: ErrorBoundaryProps) {\n super(props)\n this.state = { hasError: false }\n }\n\n static getDerivedStateFromError(): ErrorBoundaryState {\n return { hasError: true }\n }\n\n componentDidCatch(error: Error, errorInfo: React.ErrorInfo) {\n console.warn('Link preview error caught by boundary:', error, errorInfo)\n }\n\n render() {\n if (this.state.hasError) return this.props.fallback\n return this.props.children\n }\n}\n\n/**\n * Builds a placeholder image URL when the scrape returns no image. Hub passes\n * its own `buildOgPlaceholderUrl` (which resolves CSS-var ODS colors against\n * the platform's brand palette + hits `/api/og-placeholder`); other embedders\n * can omit the prop to disable the placeholder entirely.\n *\n * Receives the post-scrape `title` and `siteName` so the placeholder can echo\n * the actual card content, not a generic graphic.\n */\nexport type BuildPlaceholderUrl = (\n title: string,\n siteName: string,\n) => string | null\n\nexport interface OGLinkPreviewProps {\n /** The external URL to preview. */\n url: string\n /** Origin / base URL the OG endpoint is served from. Empty / undefined\n * means same-origin (hub-direct use). Embed contexts pass the hub's\n * origin here (e.g. `'https://hub.example.com'`) so the fetch hits\n * the hub instead of the embedder origin.\n *\n * Pattern matches lib's `useNatsDialogSubscription({apiBaseUrl})` +\n * `buildSuggestionUrl({apiBaseUrl})` so all embed-ready surfaces share\n * one configuration knob. */\n apiBaseUrl?: string\n /** Path of the OG endpoint on the configured base. Default\n * `'/api/blog/og-scraper'` matches the hub's route. Override if the\n * embedder serves the same `OGData` shape from a different path. */\n ogEndpointPath?: string\n /** Optional placeholder-builder. Omit to disable the placeholder image\n * (the card then degrades to a favicon+title chip when no scraped image\n * is available). The hub injects its `buildOgPlaceholderUrl` here. */\n buildPlaceholderUrl?: BuildPlaceholderUrl\n /** Override the scraped title (used by publication cards that already know\n * the title locally — e.g. a CMS-managed press link). */\n fallbackTitle?: string\n /** Override the scraped description. */\n fallbackDescription?: string\n /** Override the scraped image — useful when the scrape returns no image but\n * the embedder has a CMS-stored hero image to fall back to. */\n fallbackImage?: string\n /** Publication / source name shown alongside the favicon (e.g. \"TechCrunch\"). */\n publicationName?: string\n /** Publication logo URL shown alongside the title (defaults to favicon). */\n publicationLogo?: string\n /** Card variant. `compact` = horizontal layout (~120px tall) suited for\n * in-doc placements; `default` = larger vertical layout for press / hero\n * positions. */\n variant?: 'default' | 'compact'\n /** Disable the synthesized placeholder image even when `buildPlaceholderUrl`\n * is provided — used by the markdown renderer to keep doc cards lighter. */\n enablePlaceholder?: boolean\n}\n\nfunction getDomain(urlStr: string): string {\n try { return new URL(urlStr).hostname.replace('www.', '') }\n catch { return 'External Link' }\n}\n\nfunction domainToTitle(domain: string): string {\n return domain.split('.')[0].replace(/-/g, ' ').replace(/\\b\\w/g, c => c.toUpperCase())\n}\n\nconst ExternalLinkIcon = ({ size = 16 }: { size?: number }) => (\n <svg width={size} height={size} fill=\"none\" stroke=\"currentColor\" viewBox=\"0 0 24 24\" className=\"text-ods-text-secondary group-hover:text-ods-accent transition-colors flex-shrink-0\">\n <path strokeLinecap=\"round\" strokeLinejoin=\"round\" strokeWidth={2} d=\"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14\" />\n </svg>\n)\n\nconst Favicon = ({ src, size = 'w-6 h-6' }: { src: string; size?: string }) => (\n <img src={src} alt=\"\" className={size} onError={(e) => { (e.target as HTMLImageElement).style.display = 'none' }} />\n)\n\n/**\n * Rich Open-Graph link preview card with skeleton, fallback, and image-edge\n * background detection.\n *\n * Flow:\n * 1. Validate URL early (no network for malformed input, localhost, or\n * RFC1918 ranges — those render as plain `<a>` tags).\n * 2. `GET ogEndpointPath?url=<encoded>` — embedder serves the shape declared\n * in `OGData`.\n * 3. Resolve image: scraped og:image → `originalImage` fallback → `fallbackImage`\n * prop → `buildPlaceholderUrl(title, siteName)`. Each step has its own\n * error toggle so a 404 / CORS-tainted image gracefully degrades.\n * 4. Extract a letterbox background color from the resolved image via\n * `useImageEdgeColor`. Same-origin proxy is REQUIRED for cross-origin\n * images so the `<canvas>` extraction doesn't taint.\n * 5. Render compact (h-[120px] horizontal) or default (vertical w/ aspect-video\n * hero) variant, with image-less degraded variants for each.\n */\nexport const OGLinkPreview: React.FC<OGLinkPreviewProps> = ({\n url,\n apiBaseUrl,\n ogEndpointPath = '/api/blog/og-scraper',\n buildPlaceholderUrl,\n fallbackTitle,\n fallbackDescription,\n fallbackImage,\n publicationName,\n publicationLogo,\n variant = 'default',\n enablePlaceholder = true,\n}) => {\n const [ogData, setOgData] = useState<OGData | null>(null)\n const [loading, setLoading] = useState(true)\n const [error, setError] = useState(false)\n const [imageError, setImageError] = useState(false)\n const [originalImageError, setOriginalImageError] = useState(false)\n const [fallbackImageError, setFallbackImageError] = useState(false)\n\n let isValidUrl = true\n let isLocalhost = false\n try {\n if (url && typeof url === 'string') {\n const urlObj = new URL(url)\n if (['localhost', '127.0.0.1', '0.0.0.0'].includes(urlObj.hostname) ||\n urlObj.hostname.startsWith('192.168.') || urlObj.hostname.startsWith('10.') || urlObj.hostname.startsWith('172.')) {\n isLocalhost = true\n }\n } else {\n isValidUrl = false\n }\n } catch {\n isValidUrl = false\n }\n\n useEffect(() => {\n if (!isValidUrl || isLocalhost) return\n\n const fetchOGData = async () => {\n try {\n new URL(url)\n setLoading(true)\n // Compose `${base}${path}?url=…`. Empty base → relative path\n // (same-origin); absolute base → cross-origin embed against the hub.\n // Plain string concat is safer than `new URL(path, base)` because\n // the latter resolves `path` against the BASE's pathname when\n // `path` is relative, producing surprising URLs when the embedder\n // serves the lib from a subpath.\n const endpoint = `${apiBaseUrl ?? ''}${ogEndpointPath}?url=${encodeURIComponent(url)}`\n const response = await fetch(endpoint)\n if (response.ok) {\n const data = await response.json()\n if (data?.title && data.title !== 'Link Preview Unavailable') {\n setOgData(data)\n } else {\n setError(true)\n }\n } else {\n setError(true)\n }\n } catch {\n setError(true)\n } finally {\n setLoading(false)\n }\n }\n\n fetchOGData()\n }, [url, isValidUrl, isLocalhost, apiBaseUrl, ogEndpointPath])\n\n const isCompact = variant === 'compact'\n const domain = getDomain(url)\n\n const effectiveData: OGData | null = ogData ?? (error ? {\n title: fallbackTitle || domainToTitle(domain),\n description: fallbackDescription || domain,\n image: '',\n url,\n siteName: publicationName || domain,\n type: 'website',\n favicon: `https://www.google.com/s2/favicons?domain=${domain}&sz=32`,\n } : null)\n\n // Hub-injected placeholder builder — fires only when the post-scrape image\n // chain is empty AND `enablePlaceholder` is true. `null` when unprovided.\n const placeholderImageUrl =\n enablePlaceholder && buildPlaceholderUrl && effectiveData?.title\n ? buildPlaceholderUrl(effectiveData.title, effectiveData.siteName || domain)\n : null\n\n const resolvedImageUrl = (effectiveData?.image && !imageError)\n ? effectiveData.image\n : (effectiveData?.originalImage && !originalImageError)\n ? effectiveData.originalImage\n : (fallbackImage && !fallbackImageError)\n ? fallbackImage\n : placeholderImageUrl\n\n const hasImage = !!resolvedImageUrl\n const isFallbackImage = resolvedImageUrl === fallbackImage\n const isPlaceholder = resolvedImageUrl === placeholderImageUrl && !isFallbackImage\n const bgColor = useImageEdgeColor(resolvedImageUrl ?? null, 'var(--ods-bg-secondary)')\n\n const renderSkeleton = () => isCompact ? (\n <div className=\"my-4\">\n <div className=\"flex flex-row border border-ods-border rounded-lg overflow-hidden bg-ods-card h-[120px]\">\n <div className=\"w-[200px] h-full flex-shrink-0 bg-ods-skeleton animate-pulse\" />\n <div className=\"flex-1 p-3 flex flex-col justify-center\">\n <div className=\"bg-ods-skeleton rounded animate-pulse h-4 w-3/4 mb-2\" />\n <div className=\"bg-ods-skeleton rounded animate-pulse h-3 w-full mb-1\" />\n <div className=\"bg-ods-skeleton rounded animate-pulse h-3 w-2/3 mb-2\" />\n <div className=\"bg-ods-skeleton rounded animate-pulse h-3 w-1/3\" />\n </div>\n </div>\n </div>\n ) : (\n <div className=\"my-6\">\n <div className=\"block border border-ods-border rounded-lg overflow-hidden bg-ods-card\">\n <div className=\"aspect-video w-full bg-ods-skeleton overflow-hidden relative animate-pulse\" />\n <div className=\"p-4\">\n <div className=\"flex items-start gap-3\">\n <div className=\"w-6 h-6 bg-ods-skeleton rounded flex-shrink-0 mt-0.5 animate-pulse\" />\n <div className=\"flex-1 min-w-0\">\n <div className=\"h-[2.5rem] leading-[1.25rem] mb-2 overflow-hidden\">\n <div className=\"bg-ods-skeleton rounded animate-pulse\" style={{ height: '1.25rem', marginBottom: '0.25rem' }} />\n <div className=\"bg-ods-skeleton rounded animate-pulse w-3/4\" style={{ height: '1.25rem' }} />\n </div>\n <div className=\"h-[2.5rem] leading-[1.25rem] mb-2 overflow-hidden\">\n <div className=\"bg-ods-skeleton rounded animate-pulse\" style={{ height: '1.25rem', marginBottom: '0.25rem' }} />\n <div className=\"bg-ods-skeleton rounded animate-pulse w-5/6\" style={{ height: '1.25rem' }} />\n </div>\n <div className=\"flex items-center gap-2\">\n <div className=\"bg-ods-skeleton rounded animate-pulse\" style={{ height: '0.75rem', width: '6rem' }} />\n <div className=\"bg-ods-skeleton rounded animate-pulse\" style={{ height: '0.75rem', width: '5rem' }} />\n </div>\n </div>\n </div>\n </div>\n </div>\n </div>\n )\n\n if (!url || typeof url !== 'string' || !isValidUrl) return renderSkeleton()\n\n if (isLocalhost) {\n return (\n <div className=\"my-6\">\n <a href={url} target=\"_blank\" rel=\"noopener noreferrer\"\n className=\"inline-flex items-center gap-2 text-ods-accent hover:text-ods-accent-hover transition-colors\">\n <span className=\"underline\">{url}</span>\n <ExternalLinkIcon size={14} />\n </a>\n </div>\n )\n }\n\n if (loading) return renderSkeleton()\n if (!effectiveData) return renderSkeleton()\n\n const title = fallbackTitle || effectiveData.title\n // Empty string when the scrape returned nothing — descriptions render\n // conditionally below. Avoids the legacy `'No description available'` filler\n // that signaled \"broken card\" to users.\n const description = fallbackDescription || effectiveData.description || ''\n const ogDomain = getDomain(effectiveData.url)\n const faviconSrc = effectiveData.favicon || `https://www.google.com/s2/favicons?domain=${ogDomain}&sz=32`\n const logoSrc = publicationLogo || faviconSrc\n\n const handleImageError = () => {\n if (effectiveData.image && !imageError) setImageError(true)\n else if (effectiveData.originalImage && !originalImageError) setOriginalImageError(true)\n else setFallbackImageError(true)\n }\n\n const renderImage = () => {\n if (!resolvedImageUrl) return null\n if (isPlaceholder) {\n return (\n <img src={resolvedImageUrl} alt={title}\n className=\"absolute inset-0 w-full h-full object-cover rounded-md\" />\n )\n }\n if (isFallbackImage) {\n return (\n <Image src={resolvedImageUrl} alt={title} fill\n className=\"object-contain rounded-md group-hover:scale-105 transition-transform duration-300\"\n onError={handleImageError}\n unoptimized={resolvedImageUrl.includes('/render/image/')} />\n )\n }\n return (\n <img src={resolvedImageUrl} alt={title}\n className=\"absolute inset-0 w-full h-full object-contain rounded-md group-hover:scale-105 transition-transform duration-300\"\n onError={handleImageError} />\n )\n }\n\n if (isCompact) {\n if (!hasImage) {\n return (\n <div className=\"my-4\">\n <a href={effectiveData.url} target=\"_blank\" rel=\"noopener noreferrer\"\n className=\"flex flex-row items-center gap-3 border border-ods-border rounded-lg overflow-hidden bg-ods-card hover:border-ods-accent transition-all duration-200 group px-4 py-3\">\n <div className=\"w-8 h-8 bg-ods-bg-secondary rounded-lg flex items-center justify-center flex-shrink-0\">\n <Favicon src={faviconSrc} size=\"w-5 h-5\" />\n </div>\n <div className=\"flex-1 min-w-0\">\n <h3 className=\"font-sans text-sm font-semibold text-ods-text-primary group-hover:text-ods-accent transition-colors truncate\">{title}</h3>\n {description && (\n <p className=\"font-sans text-xs text-ods-text-secondary truncate\">{description}</p>\n )}\n </div>\n <ExternalLinkIcon size={14} />\n </a>\n </div>\n )\n }\n return (\n <div className=\"my-4\">\n <a href={effectiveData.url} target=\"_blank\" rel=\"noopener noreferrer\"\n className=\"flex flex-row border border-ods-border rounded-lg overflow-hidden bg-ods-card hover:border-ods-accent transition-colors group h-[120px]\">\n <div className=\"w-[200px] h-full flex-shrink-0 overflow-hidden relative flex items-center justify-center rounded-lg transition-colors duration-300\" style={{ backgroundColor: bgColor }}>\n {renderImage()}\n </div>\n <div className=\"flex-1 p-3 flex flex-col justify-center min-w-0\">\n <h3 className=\"font-sans text-sm font-semibold text-ods-text-primary overflow-hidden group-hover:text-ods-accent transition-colors\"\n style={{ display: '-webkit-box', WebkitLineClamp: 1, WebkitBoxOrient: 'vertical' }}>{title}</h3>\n {description && (\n <p className=\"font-sans text-xs text-ods-text-secondary overflow-hidden mt-1\"\n style={{ display: '-webkit-box', WebkitLineClamp: 2, WebkitBoxOrient: 'vertical' }}>{description}</p>\n )}\n <div className=\"text-xs text-ods-text-secondary mt-1 truncate\">{effectiveData.siteName || ogDomain}</div>\n </div>\n </a>\n </div>\n )\n }\n\n if (!hasImage) {\n return (\n <div className=\"my-6\">\n <a href={effectiveData.url} target=\"_blank\" rel=\"noopener noreferrer\"\n className=\"flex items-center gap-3 border border-ods-border rounded-lg overflow-hidden bg-ods-card hover:border-ods-accent transition-all duration-200 group px-4 py-3\">\n <div className=\"w-10 h-10 bg-ods-bg-secondary rounded-lg flex items-center justify-center flex-shrink-0\">\n <Favicon src={faviconSrc} />\n </div>\n <div className=\"flex-1 min-w-0\">\n <h3 className=\"font-sans font-semibold text-ods-text-primary text-base group-hover:text-ods-accent transition-colors truncate\">{title}</h3>\n {description && (\n <p className=\"font-sans text-sm text-ods-text-secondary truncate\">{description}</p>\n )}\n </div>\n <ExternalLinkIcon />\n </a>\n </div>\n )\n }\n\n return (\n <div className=\"my-6\">\n <a href={effectiveData.url} target=\"_blank\" rel=\"noopener noreferrer\"\n className=\"block border border-ods-border rounded-lg overflow-hidden bg-ods-card hover:border-ods-accent transition-colors group\">\n <div className=\"aspect-video w-full overflow-hidden relative flex items-center justify-center rounded-lg transition-colors duration-300\" style={{ backgroundColor: bgColor }}>\n {renderImage()}\n </div>\n <div className=\"p-4\">\n <div className=\"flex items-start gap-3\">\n <img src={logoSrc} alt={publicationName || ''} className=\"w-6 h-6 rounded object-contain flex-shrink-0 mt-0.5\"\n onError={(e) => { (e.target as HTMLImageElement).style.display = 'none' }} />\n <div className=\"flex-1 min-w-0\">\n <h3 className=\"font-sans font-semibold text-ods-text-primary text-base overflow-hidden group-hover:text-ods-accent transition-colors h-[2.5rem] leading-[1.25rem] mb-2\"\n style={{ display: '-webkit-box', WebkitLineClamp: 2, WebkitBoxOrient: 'vertical' }}>{title}</h3>\n {description && (\n <p className=\"font-sans text-sm text-ods-text-secondary overflow-hidden h-[2.5rem] leading-[1.25rem] mb-2\"\n style={{ display: '-webkit-box', WebkitLineClamp: 2, WebkitBoxOrient: 'vertical' }}>{description}</p>\n )}\n <div className=\"flex items-center gap-2 text-xs text-ods-text-secondary\">\n <span className=\"font-medium\">{effectiveData.siteName}</span>\n <span>•</span>\n <span className=\"truncate\">{ogDomain}</span>\n </div>\n </div>\n </div>\n </div>\n </a>\n </div>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,SAAgB,UAAU,aAAa,QAAQ,iBAAiB;AAS1D,SAsEF,UArEI,KADF;AANN,SAAS,qBAAqB,EAAE,OAAO,GAAwB;AAC7D,SACE;AAAA,IAAC;AAAA;AAAA,MACC,WAAU;AAAA,MACV,OAAO,EAAE,QAAQ,UAAU,sBAAsB;AAAA,MAEjD,+BAAC,SAAI,WAAU,0DACb;AAAA,4BAAC,SAAI,WAAU,oCAAmC;AAAA,QAClD,oBAAC,SAAI,WAAU,gCAA+B;AAAA,QAC9C,oBAAC,SAAI,WAAU,gCAA+B;AAAA,SAChD;AAAA;AAAA,EACF;AAEJ;AA6BO,SAAS,YAAY;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I,WAAU,2HAA0H,OAAO,EAAE,iBAAiB,QAAQ,GACxK,sBAAY,GACf;AAAA,QACA,gBAAAA,KAAC,SAAI,WAAU,OACb,0BAAAC,MAAC,SAAI,WAAU,0BACb;AAAA,0BAAAD;AAAA,YAAC;AAAA;AAAA,cAAI,KAAK;AAAA,cAAS,KAAK,mBAAmB;AAAA,cAAI,WAAU;AAAA,cACvD,SAAS,CAAC,MAAM;AAAE,gBAAC,EAAE,OAA4B,MAAM,UAAU;AAAA,cAAO;AAAA;AAAA,UAAG;AAAA,UAC7E,gBAAAC,MAAC,SAAI,WAAU,kBACb;AAAA,4BAAAD;AAAA,cAAC;AAAA;AAAA,gBAAG,WAAU;AAAA,gBACZ,OAAO,EAAE,SAAS,eAAe,iBAAiB,GAAG,iBAAiB,WAAW;AAAA,gBAAI;AAAA;AAAA,YAAM;AAAA,YAC5F,eACC,gBAAAA;AAAA,cAAC;AAAA;AAAA,gBAAE,WAAU;AAAA,gBACX,OAAO,EAAE,SAAS,eAAe,iBAAiB,GAAG,iBAAiB,WAAW;AAAA,gBAAI;AAAA;AAAA,YAAY;AAAA,YAErG,gBAAAC,MAAC,SAAI,WAAU,2DACb;AAAA,8BAAAD,KAAC,UAAK,WAAU,eAAe,wBAAc,UAAS;AAAA,cACtD,gBAAAA,KAAC,UAAK,oBAAC;AAAA,cACP,gBAAAA,KAAC,UAAK,WAAU,YAAY,oBAAS;AAAA,eACvC;AAAA,aACF;AAAA,WACF,GACF;AAAA;AAAA;AAAA,EACF,GACF;AAEJ;","names":["jsx","jsxs","jsx","jsxs","useState","ExternalLink","jsx","jsxs","useState","ExternalLink","useState","useEffect","jsx","jsxs","useState","useEffect"]}
|
package/dist/chunk-YETA25JW.cjs
DELETED
|
@@ -1,354 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }"use client";
|
|
2
|
-
|
|
3
|
-
// src/hooks/ui/use-auto-limit-tags.ts
|
|
4
|
-
var _react = require('react');
|
|
5
|
-
function useAutoLimitTags({
|
|
6
|
-
count,
|
|
7
|
-
limitTags = "auto",
|
|
8
|
-
placeholder = "",
|
|
9
|
-
reserveInputWidth = true
|
|
10
|
-
}) {
|
|
11
|
-
const middleRef = _react.useRef.call(void 0, null);
|
|
12
|
-
const measureRef = _react.useRef.call(void 0, null);
|
|
13
|
-
const textMeasureRef = _react.useRef.call(void 0, null);
|
|
14
|
-
const badgeRef = _react.useRef.call(void 0, null);
|
|
15
|
-
const inputRef = _react.useRef.call(void 0, null);
|
|
16
|
-
const [visibleCount, setVisibleCount] = _react.useState.call(void 0, count);
|
|
17
|
-
const recalculate = _react.useCallback.call(void 0, () => {
|
|
18
|
-
if (limitTags !== "auto") {
|
|
19
|
-
setVisibleCount(Math.min(limitTags, count));
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
const middle = middleRef.current;
|
|
23
|
-
const measure = measureRef.current;
|
|
24
|
-
if (!middle || !measure) {
|
|
25
|
-
setVisibleCount(count);
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
if (count === 0) {
|
|
29
|
-
setVisibleCount(0);
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
const cs = getComputedStyle(middle);
|
|
33
|
-
const padL = parseFloat(cs.paddingLeft) || 0;
|
|
34
|
-
const padR = parseFloat(cs.paddingRight) || 0;
|
|
35
|
-
const gap = parseFloat(cs.gap) || 0;
|
|
36
|
-
const middleW = middle.clientWidth;
|
|
37
|
-
let inputReservedW = 0;
|
|
38
|
-
let trailingGap = 0;
|
|
39
|
-
if (reserveInputWidth) {
|
|
40
|
-
const textW = _nullishCoalesce(_optionalChain([textMeasureRef, 'access', _ => _.current, 'optionalAccess', _2 => _2.offsetWidth]), () => ( 60));
|
|
41
|
-
const inputMinW = inputRef.current ? parseFloat(getComputedStyle(inputRef.current).minWidth) || 60 : 60;
|
|
42
|
-
inputReservedW = Math.max(textW + 8, inputMinW);
|
|
43
|
-
trailingGap = gap;
|
|
44
|
-
}
|
|
45
|
-
const available = middleW - padL - padR - inputReservedW - trailingGap;
|
|
46
|
-
const tagEls = Array.from(measure.children);
|
|
47
|
-
const widths = tagEls.map((el) => el.offsetWidth);
|
|
48
|
-
let total = 0;
|
|
49
|
-
for (let i = 0; i < widths.length; i++) {
|
|
50
|
-
total += widths[i] + (i > 0 ? gap : 0);
|
|
51
|
-
}
|
|
52
|
-
if (total <= available) {
|
|
53
|
-
setVisibleCount(count);
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
const badgeW = _nullishCoalesce(_optionalChain([badgeRef, 'access', _3 => _3.current, 'optionalAccess', _4 => _4.offsetWidth]), () => ( 40));
|
|
57
|
-
const spaceWithBadge = available - badgeW - gap;
|
|
58
|
-
let used = 0;
|
|
59
|
-
let fitCount = 0;
|
|
60
|
-
for (let i = 0; i < widths.length; i++) {
|
|
61
|
-
const need = widths[i] + (i > 0 ? gap : 0);
|
|
62
|
-
if (used + need > spaceWithBadge) break;
|
|
63
|
-
used += need;
|
|
64
|
-
fitCount++;
|
|
65
|
-
}
|
|
66
|
-
setVisibleCount(Math.max(0, fitCount));
|
|
67
|
-
}, [count, limitTags, placeholder, reserveInputWidth]);
|
|
68
|
-
_react.useEffect.call(void 0, () => {
|
|
69
|
-
recalculate();
|
|
70
|
-
}, [recalculate]);
|
|
71
|
-
_react.useEffect.call(void 0, () => {
|
|
72
|
-
const el = middleRef.current;
|
|
73
|
-
if (!el) return;
|
|
74
|
-
const ro = new ResizeObserver(recalculate);
|
|
75
|
-
ro.observe(el);
|
|
76
|
-
return () => ro.disconnect();
|
|
77
|
-
}, [recalculate]);
|
|
78
|
-
return { visibleCount, middleRef, measureRef, textMeasureRef, badgeRef, inputRef };
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// src/hooks/ui/use-debounce.ts
|
|
82
|
-
|
|
83
|
-
function useDebounce(value, delay = 500) {
|
|
84
|
-
const [debouncedValue, setDebouncedValue] = _react.useState.call(void 0, value);
|
|
85
|
-
_react.useEffect.call(void 0, () => {
|
|
86
|
-
const timer = setTimeout(() => {
|
|
87
|
-
setDebouncedValue(value);
|
|
88
|
-
}, delay);
|
|
89
|
-
return () => {
|
|
90
|
-
clearTimeout(timer);
|
|
91
|
-
};
|
|
92
|
-
}, [value, delay]);
|
|
93
|
-
return debouncedValue;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// src/utils/local-storage-adapter.ts
|
|
97
|
-
function getStorage(backend) {
|
|
98
|
-
if (typeof window === "undefined") return null;
|
|
99
|
-
try {
|
|
100
|
-
return backend === "session" ? window.sessionStorage : window.localStorage;
|
|
101
|
-
} catch (e) {
|
|
102
|
-
return null;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
function createLocalStorageAdapter(options) {
|
|
106
|
-
const tag = _nullishCoalesce(options.logTag, () => ( "[local-storage]"));
|
|
107
|
-
const backend = _nullishCoalesce(options.backend, () => ( "local"));
|
|
108
|
-
const resolveKey = () => {
|
|
109
|
-
const ns = _optionalChain([options, 'access', _5 => _5.namespace, 'optionalCall', _6 => _6()]);
|
|
110
|
-
return ns ? `${ns}.${options.key}` : options.key;
|
|
111
|
-
};
|
|
112
|
-
return {
|
|
113
|
-
resolveKey,
|
|
114
|
-
load() {
|
|
115
|
-
const storage = getStorage(backend);
|
|
116
|
-
if (!storage) return null;
|
|
117
|
-
try {
|
|
118
|
-
const raw = storage.getItem(resolveKey());
|
|
119
|
-
if (!raw) return null;
|
|
120
|
-
const parsed = JSON.parse(raw);
|
|
121
|
-
if (options.validate && !options.validate(parsed)) return null;
|
|
122
|
-
return parsed;
|
|
123
|
-
} catch (err) {
|
|
124
|
-
console.warn(`${tag} parse failed for key ${resolveKey()}:`, err);
|
|
125
|
-
return null;
|
|
126
|
-
}
|
|
127
|
-
},
|
|
128
|
-
save(value) {
|
|
129
|
-
const storage = getStorage(backend);
|
|
130
|
-
if (!storage) return;
|
|
131
|
-
try {
|
|
132
|
-
storage.setItem(resolveKey(), JSON.stringify(value));
|
|
133
|
-
} catch (err) {
|
|
134
|
-
console.warn(`${tag} write failed for key ${resolveKey()}:`, err);
|
|
135
|
-
}
|
|
136
|
-
},
|
|
137
|
-
clear() {
|
|
138
|
-
const storage = getStorage(backend);
|
|
139
|
-
if (!storage) return;
|
|
140
|
-
try {
|
|
141
|
-
storage.removeItem(resolveKey());
|
|
142
|
-
} catch (err) {
|
|
143
|
-
console.warn(`${tag} clear failed for key ${resolveKey()}:`, err);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
// src/utils/app-config.ts
|
|
150
|
-
function getAppType() {
|
|
151
|
-
return process.env.NEXT_PUBLIC_APP_TYPE || "openmsp";
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
// src/utils/embed-proxy-auth-storage.ts
|
|
155
|
-
function isValidPersistedAuth(value) {
|
|
156
|
-
if (!value || typeof value !== "object") return false;
|
|
157
|
-
const v = value;
|
|
158
|
-
if (typeof v.secret !== "string" || v.secret.trim().length === 0 || typeof v.email !== "string" || v.email.trim().length === 0) return false;
|
|
159
|
-
if (v.firstName != null && typeof v.firstName !== "string") return false;
|
|
160
|
-
if (v.lastName != null && typeof v.lastName !== "string") return false;
|
|
161
|
-
if (v.avatarUrl != null && typeof v.avatarUrl !== "string") return false;
|
|
162
|
-
return true;
|
|
163
|
-
}
|
|
164
|
-
var adapter = createLocalStorageAdapter({
|
|
165
|
-
// Storage key unchanged from the legacy chat-prefixed helper. Renaming
|
|
166
|
-
// it would silently log every existing admin out — the key is a
|
|
167
|
-
// storage contract, not a code identifier.
|
|
168
|
-
key: "chat.proxy-auth.v1",
|
|
169
|
-
namespace: () => getAppType(),
|
|
170
|
-
validate: isValidPersistedAuth,
|
|
171
|
-
logTag: "[embed-proxy-auth-storage]",
|
|
172
|
-
// localStorage — survives tab close, new tabs, and browser restarts.
|
|
173
|
-
// Admin re-pasting creds every tab cycle was the dev-experience
|
|
174
|
-
// tradeoff prior `sessionStorage` setup demanded — rejected. See
|
|
175
|
-
// file-level doc comment for the security tradeoff rationale.
|
|
176
|
-
backend: "local"
|
|
177
|
-
});
|
|
178
|
-
function normalizeOptional(value) {
|
|
179
|
-
if (!value) return void 0;
|
|
180
|
-
const trimmed = value.trim();
|
|
181
|
-
return trimmed.length > 0 ? trimmed : void 0;
|
|
182
|
-
}
|
|
183
|
-
function getEmbedProxyAuth() {
|
|
184
|
-
const persisted = adapter.load();
|
|
185
|
-
if (!persisted) return null;
|
|
186
|
-
return {
|
|
187
|
-
secret: persisted.secret,
|
|
188
|
-
email: persisted.email.trim().toLowerCase(),
|
|
189
|
-
firstName: normalizeOptional(persisted.firstName),
|
|
190
|
-
lastName: normalizeOptional(persisted.lastName),
|
|
191
|
-
avatarUrl: normalizeOptional(persisted.avatarUrl)
|
|
192
|
-
};
|
|
193
|
-
}
|
|
194
|
-
function getPersistedProxyEmail() {
|
|
195
|
-
const persisted = adapter.load();
|
|
196
|
-
return _nullishCoalesce(_optionalChain([persisted, 'optionalAccess', _7 => _7.email, 'access', _8 => _8.trim, 'call', _9 => _9(), 'access', _10 => _10.toLowerCase, 'call', _11 => _11()]), () => ( null));
|
|
197
|
-
}
|
|
198
|
-
function setEmbedProxyAuth(value) {
|
|
199
|
-
adapter.save({
|
|
200
|
-
secret: value.secret,
|
|
201
|
-
email: value.email.trim().toLowerCase(),
|
|
202
|
-
firstName: normalizeOptional(value.firstName),
|
|
203
|
-
lastName: normalizeOptional(value.lastName),
|
|
204
|
-
avatarUrl: normalizeOptional(value.avatarUrl)
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
function clearEmbedProxyAuth() {
|
|
208
|
-
adapter.clear();
|
|
209
|
-
}
|
|
210
|
-
function applyProxyAuth(url, baseHeaders = { "Content-Type": "application/json" }) {
|
|
211
|
-
const auth = getEmbedProxyAuth();
|
|
212
|
-
const headers = { ...baseHeaders };
|
|
213
|
-
if (_optionalChain([auth, 'optionalAccess', _12 => _12.secret])) {
|
|
214
|
-
headers.Authorization = `Bearer ${auth.secret}`;
|
|
215
|
-
}
|
|
216
|
-
if (_optionalChain([auth, 'optionalAccess', _13 => _13.email])) {
|
|
217
|
-
headers["X-Chat-Act-As"] = auth.email;
|
|
218
|
-
}
|
|
219
|
-
if (_optionalChain([auth, 'optionalAccess', _14 => _14.firstName])) headers["X-Chat-First-Name"] = auth.firstName;
|
|
220
|
-
if (_optionalChain([auth, 'optionalAccess', _15 => _15.lastName])) headers["X-Chat-Last-Name"] = auth.lastName;
|
|
221
|
-
if (_optionalChain([auth, 'optionalAccess', _16 => _16.avatarUrl])) headers["X-Chat-Avatar-Url"] = auth.avatarUrl;
|
|
222
|
-
return { url, headers };
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
// src/utils/embed-authed-fetch.ts
|
|
226
|
-
var ADAPTER_GLOBAL_KEY = "__embedAuthedFetchAdapter__";
|
|
227
|
-
function getRegisteredAuthAdapter() {
|
|
228
|
-
if (typeof globalThis === "undefined") return null;
|
|
229
|
-
return _nullishCoalesce(globalThis[ADAPTER_GLOBAL_KEY], () => ( null));
|
|
230
|
-
}
|
|
231
|
-
function storeRegisteredAuthAdapter(adapter2) {
|
|
232
|
-
if (typeof globalThis === "undefined") return;
|
|
233
|
-
globalThis[ADAPTER_GLOBAL_KEY] = adapter2;
|
|
234
|
-
}
|
|
235
|
-
function setEmbedAuthAdapter(adapter2) {
|
|
236
|
-
if (adapter2 && getRegisteredAuthAdapter() && process.env.NODE_ENV !== "production") {
|
|
237
|
-
console.warn(
|
|
238
|
-
"[setEmbedAuthAdapter] overwriting a previously-registered auth adapter. Two chat-runtime providers should not coexist \u2014 verify mount order and pass `null` from the unmounting provider."
|
|
239
|
-
);
|
|
240
|
-
}
|
|
241
|
-
storeRegisteredAuthAdapter(adapter2);
|
|
242
|
-
}
|
|
243
|
-
function hasEmbedAuthAdapter() {
|
|
244
|
-
return getRegisteredAuthAdapter() !== null;
|
|
245
|
-
}
|
|
246
|
-
function embedAuthedFetch(url, init = {}) {
|
|
247
|
-
assertSameOrigin(url);
|
|
248
|
-
let baseHeaders;
|
|
249
|
-
if (init.headers === void 0) {
|
|
250
|
-
baseHeaders = { "Content-Type": "application/json" };
|
|
251
|
-
} else {
|
|
252
|
-
baseHeaders = {};
|
|
253
|
-
if (init.headers instanceof Headers) {
|
|
254
|
-
init.headers.forEach((v, k) => {
|
|
255
|
-
baseHeaders[k] = v;
|
|
256
|
-
});
|
|
257
|
-
} else if (Array.isArray(init.headers)) {
|
|
258
|
-
for (const [k, v] of init.headers) baseHeaders[k] = v;
|
|
259
|
-
} else {
|
|
260
|
-
Object.assign(baseHeaders, init.headers);
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
return fetchWithRefresh(url, init, baseHeaders, false);
|
|
264
|
-
}
|
|
265
|
-
var IN_FLIGHT_REFRESH_GLOBAL_KEY = "__embedAuthedFetchInFlightRefresh__";
|
|
266
|
-
function getInFlightRefresh() {
|
|
267
|
-
if (typeof globalThis === "undefined") return null;
|
|
268
|
-
return _nullishCoalesce(globalThis[IN_FLIGHT_REFRESH_GLOBAL_KEY], () => ( null));
|
|
269
|
-
}
|
|
270
|
-
function setInFlightRefresh(refresh) {
|
|
271
|
-
if (typeof globalThis === "undefined") return;
|
|
272
|
-
globalThis[IN_FLIGHT_REFRESH_GLOBAL_KEY] = refresh;
|
|
273
|
-
}
|
|
274
|
-
function dedupedRefresh() {
|
|
275
|
-
const adapter2 = getRegisteredAuthAdapter();
|
|
276
|
-
if (!_optionalChain([adapter2, 'optionalAccess', _17 => _17.refresh])) return Promise.resolve(false);
|
|
277
|
-
let inFlightRefresh = getInFlightRefresh();
|
|
278
|
-
if (!inFlightRefresh) {
|
|
279
|
-
inFlightRefresh = Promise.resolve().then(() => adapter2.refresh()).catch(() => false).finally(() => {
|
|
280
|
-
setInFlightRefresh(null);
|
|
281
|
-
});
|
|
282
|
-
setInFlightRefresh(inFlightRefresh);
|
|
283
|
-
}
|
|
284
|
-
return inFlightRefresh;
|
|
285
|
-
}
|
|
286
|
-
async function fetchWithRefresh(url, init, baseHeaders, isRetry) {
|
|
287
|
-
const { url: authedUrl, headers } = applyProxyAuth(url, { ...baseHeaders });
|
|
288
|
-
const adapter2 = getRegisteredAuthAdapter();
|
|
289
|
-
if (_optionalChain([adapter2, 'optionalAccess', _18 => _18.getHeaders])) {
|
|
290
|
-
for (const [k, v] of Object.entries(adapter2.getHeaders())) {
|
|
291
|
-
if (v !== void 0) headers[k] = v;
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
const credentials = _nullishCoalesce(_nullishCoalesce(_optionalChain([adapter2, 'optionalAccess', _19 => _19.credentials]), () => ( init.credentials)), () => ( "same-origin"));
|
|
295
|
-
const response = await fetch(authedUrl, {
|
|
296
|
-
...init,
|
|
297
|
-
headers,
|
|
298
|
-
// Default `same-origin` carries Supabase cookies for the MPH proxy-
|
|
299
|
-
// auth model. Hosts on different origins (openframe-frontend ↔
|
|
300
|
-
// openframe gateway) register `credentials: 'include'` via the
|
|
301
|
-
// adapter to make their own cookies travel cross-origin (CORS +
|
|
302
|
-
// `SameSite=None` must be configured server-side for that to work).
|
|
303
|
-
credentials
|
|
304
|
-
});
|
|
305
|
-
if (response.status === 401 && !isRetry && _optionalChain([adapter2, 'optionalAccess', _20 => _20.refresh])) {
|
|
306
|
-
const refreshed = await dedupedRefresh();
|
|
307
|
-
if (refreshed) {
|
|
308
|
-
return fetchWithRefresh(url, init, baseHeaders, true);
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
return response;
|
|
312
|
-
}
|
|
313
|
-
function assertSameOrigin(url) {
|
|
314
|
-
if (typeof window === "undefined") return;
|
|
315
|
-
let target;
|
|
316
|
-
let pageOrigin;
|
|
317
|
-
try {
|
|
318
|
-
target = new URL(url, window.location.href);
|
|
319
|
-
pageOrigin = new URL(window.location.href).origin;
|
|
320
|
-
} catch (e2) {
|
|
321
|
-
throw new Error(`embedAuthedFetch: refusing to fetch malformed URL (${JSON.stringify(url)})`);
|
|
322
|
-
}
|
|
323
|
-
if (target.protocol !== "http:" && target.protocol !== "https:") {
|
|
324
|
-
throw new Error(
|
|
325
|
-
`embedAuthedFetch: refusing non-http(s) URL (${target.protocol}) \u2014 pass a relative /api/* path instead`
|
|
326
|
-
);
|
|
327
|
-
}
|
|
328
|
-
if (target.origin !== pageOrigin) {
|
|
329
|
-
if (process.env.NODE_ENV !== "production") {
|
|
330
|
-
console.warn(
|
|
331
|
-
`[embedAuthedFetch] cross-origin fetch to ${target.origin} allowed in dev (NODE_ENV !== 'production'). Production builds will reject this \u2014 wire a same-origin proxy before shipping.`
|
|
332
|
-
);
|
|
333
|
-
return;
|
|
334
|
-
}
|
|
335
|
-
throw new Error(
|
|
336
|
-
`embedAuthedFetch: refusing cross-origin fetch to ${target.origin} \u2014 pass a relative /api/* path instead`
|
|
337
|
-
);
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
exports.useAutoLimitTags = useAutoLimitTags; exports.useDebounce = useDebounce; exports.getAppType = getAppType; exports.getEmbedProxyAuth = getEmbedProxyAuth; exports.getPersistedProxyEmail = getPersistedProxyEmail; exports.setEmbedProxyAuth = setEmbedProxyAuth; exports.clearEmbedProxyAuth = clearEmbedProxyAuth; exports.applyProxyAuth = applyProxyAuth; exports.setEmbedAuthAdapter = setEmbedAuthAdapter; exports.hasEmbedAuthAdapter = hasEmbedAuthAdapter; exports.embedAuthedFetch = embedAuthedFetch;
|
|
354
|
-
//# sourceMappingURL=chunk-YETA25JW.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/openframe-oss-lib/openframe-oss-lib/openframe-frontend-core/dist/chunk-YETA25JW.cjs","../src/hooks/ui/use-auto-limit-tags.ts","../src/hooks/ui/use-debounce.ts","../src/utils/local-storage-adapter.ts","../src/utils/app-config.ts","../src/utils/embed-proxy-auth-storage.ts","../src/utils/embed-authed-fetch.ts"],"names":["useState","useEffect","adapter"],"mappings":"AAAA,6rBAAY;AACZ;AACA;ACAA,8BAAyD;AA2ClD,SAAS,gBAAA,CAAiB;AAAA,EAC/B,KAAA;AAAA,EACA,UAAA,EAAY,MAAA;AAAA,EACZ,YAAA,EAAc,EAAA;AAAA,EACd,kBAAA,EAAoB;AACtB,CAAA,EAAoD;AAClD,EAAA,MAAM,UAAA,EAAY,2BAAA,IAA2B,CAAA;AAC7C,EAAA,MAAM,WAAA,EAAa,2BAAA,IAA2B,CAAA;AAC9C,EAAA,MAAM,eAAA,EAAiB,2BAAA,IAA4B,CAAA;AACnD,EAAA,MAAM,SAAA,EAAW,2BAAA,IAA8B,CAAA;AAC/C,EAAA,MAAM,SAAA,EAAW,2BAAA,IAA6B,CAAA;AAC9C,EAAA,MAAM,CAAC,YAAA,EAAc,eAAe,EAAA,EAAI,6BAAA,KAAc,CAAA;AAEtD,EAAA,MAAM,YAAA,EAAc,gCAAA,CAAY,EAAA,GAAM;AAEpC,IAAA,GAAA,CAAI,UAAA,IAAc,MAAA,EAAQ;AACxB,MAAA,eAAA,CAAgB,IAAA,CAAK,GAAA,CAAI,SAAA,EAAW,KAAK,CAAC,CAAA;AAC1C,MAAA,MAAA;AAAA,IACF;AAEA,IAAA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F,EAAA;AAEO,EAAA;AACT;AAqBS;AACI,EAAA;AACP,EAAA;AACA,EAAA;AACA,EAAA;AACW,IAAA;AAKA,IAAA;AACP,EAAA;AACI,IAAA;AACZ,EAAA;AACW,EAAA;AACC,IAAA;AACR,MAAA;AACF,IAAA;AACF,EAAA;AACW,EAAA;AASG,IAAA;AACF,MAAA;AACN,QAAA;AAGF,MAAA;AACA,MAAA;AACF,IAAA;AACU,IAAA;AACR,MAAA;AACF,IAAA;AACF,EAAA;AACF;ANnCiB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/openframe-oss-lib/openframe-oss-lib/openframe-frontend-core/dist/chunk-YETA25JW.cjs","sourcesContent":[null,"\"use client\"\n\nimport { useCallback, useEffect, useRef, useState } from \"react\"\n\nexport interface UseAutoLimitTagsOptions {\n /** Total number of tags */\n count: number\n /** Fixed limit or \"auto\" for DOM-based measurement. Default \"auto\" */\n limitTags?: number | \"auto\"\n /** Placeholder text used to reserve input width (only used in \"auto\" mode) */\n placeholder?: string\n /**\n * Reserve trailing space for a text input (the autocomplete combobox). Set\n * `false` for a pure chip row that has no input — then only the chips and the\n * \"+N\" / \"⋯\" overflow badge compete for the available width. Default `true`.\n */\n reserveInputWidth?: boolean\n}\n\nexport interface UseAutoLimitTagsReturn {\n /** How many tags to show */\n visibleCount: number\n /** Ref for the zone that contains tags + input (must have overflow-hidden, gap, padding) */\n middleRef: React.RefObject<HTMLDivElement | null>\n /** Ref for the off-screen container that holds measurement copies of ALL tags */\n measureRef: React.RefObject<HTMLDivElement | null>\n /** Ref for the hidden span that measures placeholder text width */\n textMeasureRef: React.RefObject<HTMLSpanElement | null>\n /** Ref for the \"+N\" badge element (used to measure its width) */\n badgeRef: React.RefObject<HTMLButtonElement | null>\n /** Ref for the input element (used to read its min-width) */\n inputRef: React.RefObject<HTMLInputElement | null>\n}\n\n/**\n * Calculates how many tags fit in a single-line container.\n *\n * Requires three off-screen measurement elements rendered by the consumer:\n * 1. A `<div ref={measureRef}>` containing Tag copies for every item (to measure widths)\n * 2. A `<span ref={textMeasureRef}>` containing the placeholder text (to reserve input width)\n * 3. The `<button ref={badgeRef}>` for the \"+N\" badge (to measure badge width)\n *\n * The hook reads real CSS values (padding, gap) from the middleRef container,\n * so it works regardless of responsive breakpoints or custom styling.\n */\nexport function useAutoLimitTags({\n count,\n limitTags = \"auto\",\n placeholder = \"\",\n reserveInputWidth = true,\n}: UseAutoLimitTagsOptions): UseAutoLimitTagsReturn {\n const middleRef = useRef<HTMLDivElement>(null)\n const measureRef = useRef<HTMLDivElement>(null)\n const textMeasureRef = useRef<HTMLSpanElement>(null)\n const badgeRef = useRef<HTMLButtonElement>(null)\n const inputRef = useRef<HTMLInputElement>(null)\n const [visibleCount, setVisibleCount] = useState(count)\n\n const recalculate = useCallback(() => {\n // Fixed limit — skip DOM measurement\n if (limitTags !== \"auto\") {\n setVisibleCount(Math.min(limitTags, count))\n return\n }\n\n const middle = middleRef.current\n const measure = measureRef.current\n if (!middle || !measure) {\n setVisibleCount(count)\n return\n }\n if (count === 0) {\n setVisibleCount(0)\n return\n }\n\n // Read real CSS metrics from the middle zone\n const cs = getComputedStyle(middle)\n const padL = parseFloat(cs.paddingLeft) || 0\n const padR = parseFloat(cs.paddingRight) || 0\n const gap = parseFloat(cs.gap) || 0\n const middleW = middle.clientWidth\n\n // Reserve trailing space for the input (autocomplete only). A pure chip row\n // (`reserveInputWidth: false`) has no input, so nothing — and no gap before\n // it — is reserved.\n let inputReservedW = 0\n let trailingGap = 0\n if (reserveInputWidth) {\n const textW = textMeasureRef.current?.offsetWidth ?? 60\n const inputMinW = inputRef.current\n ? parseFloat(getComputedStyle(inputRef.current).minWidth) || 60\n : 60\n inputReservedW = Math.max(textW + 8, inputMinW)\n trailingGap = gap\n }\n\n // Available = middle zone − padding − input reserved − gap before input\n const available = middleW - padL - padR - inputReservedW - trailingGap\n\n // Measure every tag from the off-screen container\n const tagEls = Array.from(measure.children) as HTMLElement[]\n const widths = tagEls.map((el) => el.offsetWidth)\n\n // Fast check: do ALL tags fit?\n let total = 0\n for (let i = 0; i < widths.length; i++) {\n total += widths[i] + (i > 0 ? gap : 0)\n }\n if (total <= available) {\n setVisibleCount(count)\n return\n }\n\n // Not all fit → reserve space for the \"+N\" badge\n const badgeW = badgeRef.current?.offsetWidth ?? 40\n const spaceWithBadge = available - badgeW - gap\n\n let used = 0\n let fitCount = 0\n for (let i = 0; i < widths.length; i++) {\n const need = widths[i] + (i > 0 ? gap : 0)\n if (used + need > spaceWithBadge) break\n used += need\n fitCount++\n }\n\n setVisibleCount(Math.max(0, fitCount))\n }, [count, limitTags, placeholder, reserveInputWidth])\n\n // Recalculate when inputs change\n useEffect(() => {\n recalculate()\n }, [recalculate])\n\n // Recalculate on container resize\n useEffect(() => {\n const el = middleRef.current\n if (!el) return\n const ro = new ResizeObserver(recalculate)\n ro.observe(el)\n return () => ro.disconnect()\n }, [recalculate])\n\n return { visibleCount, middleRef, measureRef, textMeasureRef, badgeRef, inputRef }\n}\n","\"use client\"\n\nimport { useState, useEffect } from \"react\"\n\n/**\n * Hook to debounce a value\n * @param value - Value to debounce\n * @param delay - Delay in milliseconds\n * @returns Debounced value\n */\nexport function useDebounce<T>(value: T, delay = 500): T {\n const [debouncedValue, setDebouncedValue] = useState<T>(value)\n\n useEffect(() => {\n // Set up timeout to update debounced value\n const timer = setTimeout(() => {\n setDebouncedValue(value)\n }, delay)\n\n // Clean up timeout on value change or unmount\n return () => {\n clearTimeout(timer)\n }\n }, [value, delay])\n\n return debouncedValue\n}\n","/**\n * Thin JSON-typed Web-Storage adapter (localStorage or sessionStorage).\n *\n * Centralizes the SSR-guard + try/catch + silent quota-failure pattern\n * that every per-feature storage util would otherwise re-implement.\n *\n * Optional `namespace` prefix supports platform / user partitioning —\n * the resolver runs lazily at call time so the namespace can vary across\n * the lifetime of the page (e.g. proxy-auth switches user, which switches\n * the key suffix).\n *\n * Backend selection (`backend: 'local' | 'session'`):\n * - `'local'` (default): persists across browser sessions. Use for\n * UI state, chat history metadata, feature-flag opt-ins.\n * - `'session'`: cleared when the tab closes. Use for ANY auth-adjacent\n * value (bearer tokens, act-as identity, proxy credentials). Reduces\n * the XSS-exfiltration attack window from \"indefinite\" to \"until tab\n * close\" without losing per-session ergonomics.\n */\n\nexport type WebStorageBackend = 'local' | 'session'\n\nexport interface LocalStorageAdapter<T> {\n load(): T | null\n save(value: T): void\n clear(): void\n /** Resolved storage key for the current call. Useful for tests. */\n resolveKey(): string\n}\n\nexport interface LocalStorageAdapterOptions<T> {\n /** Base storage key. Combined with `namespace()` when provided. */\n key: string\n /** Optional dynamic namespace prefix appended via `.` separator.\n * Called on EVERY read/write so the key can vary across the page\n * lifetime (e.g. when the platform or user identity changes). */\n namespace?: () => string | null | undefined\n /** Runtime shape check. Falsey return → `load()` yields null. */\n validate?: (parsed: unknown) => parsed is T\n /** Diagnostic prefix written to `console.warn` on parse / write\n * failures. Defaults to `'[local-storage]'`. */\n logTag?: string\n /** Which Web-Storage backend to use. Defaults to `'local'`. Pass\n * `'session'` for anything auth-adjacent so the value evaporates\n * when the tab closes. */\n backend?: WebStorageBackend\n}\n\nfunction getStorage(backend: WebStorageBackend): Storage | null {\n if (typeof window === 'undefined') return null\n try {\n return backend === 'session' ? window.sessionStorage : window.localStorage\n } catch {\n // Some sandboxed contexts (Safari private mode older versions,\n // strict CSP) throw on storage access — treat as unavailable.\n return null\n }\n}\n\nexport function createLocalStorageAdapter<T>(\n options: LocalStorageAdapterOptions<T>,\n): LocalStorageAdapter<T> {\n const tag = options.logTag ?? '[local-storage]'\n const backend: WebStorageBackend = options.backend ?? 'local'\n const resolveKey = (): string => {\n const ns = options.namespace?.()\n return ns ? `${ns}.${options.key}` : options.key\n }\n\n return {\n resolveKey,\n load() {\n const storage = getStorage(backend)\n if (!storage) return null\n try {\n const raw = storage.getItem(resolveKey())\n if (!raw) return null\n const parsed = JSON.parse(raw) as unknown\n if (options.validate && !options.validate(parsed)) return null\n return parsed as T\n } catch (err) {\n console.warn(`${tag} parse failed for key ${resolveKey()}:`, err)\n return null\n }\n },\n save(value: T) {\n const storage = getStorage(backend)\n if (!storage) return\n try {\n storage.setItem(resolveKey(), JSON.stringify(value))\n } catch (err) {\n console.warn(`${tag} write failed for key ${resolveKey()}:`, err)\n }\n },\n clear() {\n const storage = getStorage(backend)\n if (!storage) return\n try {\n storage.removeItem(resolveKey())\n } catch (err) {\n console.warn(`${tag} clear failed for key ${resolveKey()}:`, err)\n }\n },\n }\n}\n","// Stub app config\nexport const APP_CONFIG = {\n app: {\n type: 'openmsp',\n name: 'OpenMSP',\n domain: 'openmsp.ai'\n },\n features: {\n announcements: true,\n notifications: true\n }\n} as const;\n\nexport function getAppConfig() {\n return APP_CONFIG;\n}\n\nexport function getAppType() {\n return process.env.NEXT_PUBLIC_APP_TYPE || 'openmsp';\n}","'use client'\n\n/**\n * Client-side persistence for embed-surface proxy credentials\n * (`CHAT_PROXY_SECRET` + impersonation email). Used by every embedded\n * surface — the chat widget AND the ticket center AND any future\n * embedded React component that needs to identify itself as the\n * impersonated customer.\n *\n * When set, the surface attaches the creds as\n * `Authorization: Bearer <secret>` + `X-Chat-Act-As: <email>`\n * on every call to `/api/docs/chat`, `/api/chat/*`, and any other route\n * gated by `requireChatAuth` — proving to the server that this session\n * is acting on behalf of <email>.\n *\n * **Naming history:** the wire-side header names are still `X-Chat-*`\n * and the env var is `CHAT_PROXY_SECRET`. Those are server contracts;\n * renaming them would require a coordinated deploy + customer-side\n * env-var migration. The CLIENT-side helpers were renamed `Embed*` so\n * non-chat surfaces (e.g. ticket center) don't have to import a\n * chat-prefixed symbol just to send the same headers.\n *\n * Persists to **`localStorage`** so the bearer token + act-as identity\n * survive tab close, new-tab opens, and browser restarts — the\n * `/debug` paste-creds UI is an admin tool and re-pasting every tab\n * cycle was rejected as a dev-experience tradeoff that wasn't worth\n * the security gain. An XSS sink on this origin can read the value\n * indefinitely (vs only-this-tab with sessionStorage), but `/debug`\n * is admin-gated behind the platform's `askAI.enabled` flag and the\n * impersonation header it sets is server-validated against\n * `CHAT_PROXY_SECRET` anyway. Explicit \"Clear\" button on the creds\n * bar is the supported logout path; closing the tab is no longer.\n *\n * Namespaced under `<platform>.chat.proxy-auth.v1` (the storage key is\n * unchanged from the old chat-prefixed helper — that's a storage\n * contract; renaming it would log everyone out).\n */\n\nimport { createLocalStorageAdapter } from './local-storage-adapter'\nimport { getAppType } from './app-config'\n\nexport interface EmbedProxyAuth {\n secret: string\n email: string\n /** Optional identity passthrough — empty/omitted = not sent. Server\n * parses these as `X-Chat-{First,Last}-Name` / `X-Chat-Avatar-Url` and\n * threads them through `resolveChatProxyIdentity`'s returned user. */\n firstName?: string\n lastName?: string\n avatarUrl?: string\n}\n\nfunction isValidPersistedAuth(value: unknown): value is EmbedProxyAuth {\n if (!value || typeof value !== 'object') return false\n const v = value as Record<string, unknown>\n if (\n typeof v.secret !== 'string' || v.secret.trim().length === 0 ||\n typeof v.email !== 'string' || v.email.trim().length === 0\n ) return false\n // Optional fields: when present must be strings. Empty string is treated\n // as absent later (in `getEmbedProxyAuth`).\n if (v.firstName != null && typeof v.firstName !== 'string') return false\n if (v.lastName != null && typeof v.lastName !== 'string') return false\n if (v.avatarUrl != null && typeof v.avatarUrl !== 'string') return false\n return true\n}\n\nconst adapter = createLocalStorageAdapter<EmbedProxyAuth>({\n // Storage key unchanged from the legacy chat-prefixed helper. Renaming\n // it would silently log every existing admin out — the key is a\n // storage contract, not a code identifier.\n key: 'chat.proxy-auth.v1',\n namespace: () => getAppType(),\n validate: isValidPersistedAuth,\n logTag: '[embed-proxy-auth-storage]',\n // localStorage — survives tab close, new tabs, and browser restarts.\n // Admin re-pasting creds every tab cycle was the dev-experience\n // tradeoff prior `sessionStorage` setup demanded — rejected. See\n // file-level doc comment for the security tradeoff rationale.\n backend: 'local',\n})\n\n/** Trim + null-coerce an optional identity field so consumers can do\n * `auth.firstName ?? ''` without worrying about whitespace-only strings. */\nfunction normalizeOptional(value: string | undefined): string | undefined {\n if (!value) return undefined\n const trimmed = value.trim()\n return trimmed.length > 0 ? trimmed : undefined\n}\n\n/**\n * Returns full credentials (secret + email + optional identity passthrough)\n * when secret + email are available. Returns `null` when nothing is saved —\n * callers treat that as \"fall back to cookie auth\".\n */\nexport function getEmbedProxyAuth(): EmbedProxyAuth | null {\n const persisted = adapter.load()\n if (!persisted) return null\n return {\n secret: persisted.secret,\n email: persisted.email.trim().toLowerCase(),\n firstName: normalizeOptional(persisted.firstName),\n lastName: normalizeOptional(persisted.lastName),\n avatarUrl: normalizeOptional(persisted.avatarUrl),\n }\n}\n\n/**\n * Returns the LAST email the admin saved. The proxy creds bar reads\n * this to pre-fill the email field on mount.\n */\nexport function getPersistedProxyEmail(): string | null {\n const persisted = adapter.load()\n return persisted?.email.trim().toLowerCase() ?? null\n}\n\n/** Save the proxy creds. Secret + email are required; identity-passthrough\n * fields are persisted only when non-empty. */\nexport function setEmbedProxyAuth(value: EmbedProxyAuth): void {\n adapter.save({\n secret: value.secret,\n email: value.email.trim().toLowerCase(),\n firstName: normalizeOptional(value.firstName),\n lastName: normalizeOptional(value.lastName),\n avatarUrl: normalizeOptional(value.avatarUrl),\n })\n}\n\n/** Drop the persisted creds. */\nexport function clearEmbedProxyAuth(): void {\n adapter.clear()\n}\n\n/**\n * Apply the embed-proxy auth (Bearer + X-Chat-Act-As) to a fetch call's\n * URL + headers. Used by every embedded-surface route that needs to\n * identify itself as the proxied customer (chat stream, agent-* routes,\n * ticket-center actions). When proxy auth is absent (regular\n * cookie-session users), returns the inputs unchanged so the cookie-auth\n * path still works.\n *\n * `X-Chat-Act-As` header (vs a URL query param) keeps PII out of access\n * logs, Sentry breadcrumbs, browser history, and CDN analytics.\n */\nexport function applyProxyAuth(\n url: string,\n baseHeaders: Record<string, string> = { 'Content-Type': 'application/json' },\n): { url: string; headers: Record<string, string> } {\n const auth = getEmbedProxyAuth()\n const headers = { ...baseHeaders }\n if (auth?.secret) {\n headers.Authorization = `Bearer ${auth.secret}`\n }\n if (auth?.email) {\n headers['X-Chat-Act-As'] = auth.email\n }\n // Optional identity passthrough — only attached when present so the\n // server's \"required vs optional\" header shape stays exact.\n if (auth?.firstName) headers['X-Chat-First-Name'] = auth.firstName\n if (auth?.lastName) headers['X-Chat-Last-Name'] = auth.lastName\n if (auth?.avatarUrl) headers['X-Chat-Avatar-Url'] = auth.avatarUrl\n return { url, headers }\n}\n","'use client'\n\n/**\n * Shared `fetch` wrapper for any embedded surface (chat, ticket center,\n * future widgets) that needs to carry the bearer-act-as identity\n * (proxy `Authorization` + `X-Chat-Act-As` headers from\n * `embed-proxy-auth-storage.ts`).\n *\n * Wire header names are `X-Chat-*` for historical reasons — that's a\n * server contract, not a UI namespace. The wrapper itself is generic.\n *\n * Drop-in replacement for `fetch()` — `Authorization` / `X-Chat-Act-As`\n * are merged into `init.headers` when proxy creds are stashed in\n * sessionStorage, otherwise the call falls through to the cookie-auth\n * path unchanged.\n *\n * Use this for any client-side fetch hitting `/api/chat/*`, `/api/docs/chat/*`,\n * or `/api/storage/generate-upload-url` (chat-attachment surface — shared\n * with the ticket center). Routes that do NOT need bearer-act-as\n * (e.g. `/api/profile/me`) keep using vanilla `fetch`.\n */\n\nimport { applyProxyAuth } from './embed-proxy-auth-storage'\n\n// =============================================================================\n// Host-supplied auth adapter (opt-in)\n// =============================================================================\n\n/**\n * Hosts that have their own auth model (cookie sessions, app-specific\n * JWT in localStorage, OAuth access tokens, …) can register an adapter\n * to override the lib's default `embedProxyAuth` flow. When set, the\n * adapter's `getHeaders()` result is merged onto every `embedAuthedFetch`\n * call AFTER the default proxy-auth header step (so adapter headers\n * win over both caller and proxy values), and `credentials` overrides\n * the default `'same-origin'` behaviour.\n *\n * Default (no adapter): MPH-style proxy-impersonation — bearer + act-as\n * read from localStorage, `credentials: 'same-origin'`. No consumer\n * needs to touch this unless they want a different auth model.\n *\n * Use cases:\n * - openframe-frontend has its own JWT in `localStorage.of_access_token`\n * and cookie-based session; register an adapter to attach the JWT\n * and request `credentials: 'include'` so cookies travel cross-origin\n * to the openframe gateway.\n * - Future embed hosts with OAuth access tokens, signed URLs, etc.\n *\n * Lifetime: setter is module-level (intentionally — `embedAuthedFetch`\n * is a plain utility, not a hook, so it can't read React context). Host\n * runtime providers should call `setEmbedAuthAdapter(...)` on mount and\n * `setEmbedAuthAdapter(null)` on unmount. Multiple hosts registering at\n * once is a programming error (one chat panel per app).\n */\nexport interface EmbedAuthAdapter {\n /** Headers merged onto every embedded-fetch call. Return `{}` to add\n * nothing. Called per-request so reactive token refresh sees the latest\n * value from your auth store / storage. Values typed as\n * `string | undefined` so the common narrowed shape\n * `{ Authorization: token ? 'Bearer …' : undefined }` (or a conditional\n * `token ? { Authorization: … } : {}`) assigns cleanly — `undefined`\n * values are filtered before being merged into the request headers. */\n getHeaders?: () => Record<string, string | undefined>\n /** `RequestInit.credentials` mode. Default when no adapter: callers'\n * `init.credentials` or `'same-origin'`. Use `'include'` for cookie\n * auth against a different origin (CORS + `SameSite=None` required). */\n credentials?: RequestCredentials\n /**\n * Optional 401 self-heal. When a request comes back `401`,\n * `embedAuthedFetch` calls this once, and — if it resolves `true` —\n * retries the SAME request exactly once with freshly-recomputed\n * headers (so a rotated bearer from `getHeaders()` is picked up).\n * Resolve `false` to surface the 401 to the caller unchanged.\n *\n * This is the capability the openframe `apiClient` has had all along\n * (refresh-the-access-token-then-retry); registering it here gives the\n * embedded chat/ticket surfaces the same self-healing auth instead of\n * dying on an expired token. Concurrent 401s are de-duplicated by the\n * wrapper, so this fires at most once per refresh cycle even when a\n * stampede of chat requests all expire together — your implementation\n * does NOT need its own in-flight guard (though a token-refresh manager\n * that already dedups is harmless).\n *\n * Keep it idempotent and side-effect-light: on failure the wrapper just\n * returns the original 401 — logout/redirect decisions belong to the\n * host's own auth layer, not to this fetch wrapper.\n */\n refresh?: () => Promise<boolean>\n}\n\n/**\n * The registered adapter is parked on `globalThis`, NOT in a module-private\n * `let`. Reason: this lib ships multiple entry points (`/utils`,\n * `/components/chat`, …) and a consumer's bundler can inline this file into\n * more than one chunk — giving each chunk its OWN module scope. If the host\n * calls `setEmbedAuthAdapter` from the `/utils` copy while the chat's\n * `embedAuthedFetch` runs from the `/components/chat` copy, a module-local\n * `let` would be set on one copy and read as `null` on the other (the exact\n * \"credentials: same-origin, no Bearer, no refresh\" symptom). A single\n * `globalThis` slot is shared across every copy, so registration always\n * reaches the fetch path.\n */\nconst ADAPTER_GLOBAL_KEY = '__embedAuthedFetchAdapter__'\n\nfunction getRegisteredAuthAdapter(): EmbedAuthAdapter | null {\n if (typeof globalThis === 'undefined') return null\n return (globalThis as Record<string, unknown>)[ADAPTER_GLOBAL_KEY] as EmbedAuthAdapter | null ?? null\n}\n\nfunction storeRegisteredAuthAdapter(adapter: EmbedAuthAdapter | null): void {\n if (typeof globalThis === 'undefined') return\n ;(globalThis as Record<string, unknown>)[ADAPTER_GLOBAL_KEY] = adapter\n}\n\n/**\n * Register a host-owned auth adapter for `embedAuthedFetch`. Pass `null`\n * to clear (typically on provider unmount).\n *\n * Module-level state — there is one chat panel per app, so a single\n * registration is sufficient. Calling this twice with different non-null\n * adapters replaces the previous one (the most recent registration wins);\n * a `console.warn` flags the overwrite so duplicate-provider mounts get\n * caught in dev.\n */\nexport function setEmbedAuthAdapter(adapter: EmbedAuthAdapter | null): void {\n if (adapter && getRegisteredAuthAdapter() && process.env.NODE_ENV !== 'production') {\n console.warn(\n '[setEmbedAuthAdapter] overwriting a previously-registered auth ' +\n 'adapter. Two chat-runtime providers should not coexist — verify ' +\n 'mount order and pass `null` from the unmounting provider.',\n )\n }\n storeRegisteredAuthAdapter(adapter)\n}\n\n/**\n * Whether a host auth adapter is currently registered. Lets sibling helpers\n * (e.g. `contentFetch`) route through `embedAuthedFetch` ONLY when a host has\n * opted into embedded auth, and stay a plain `fetch` otherwise — so there's a\n * single auth knob (the adapter), not a second content-fetch registration.\n */\nexport function hasEmbedAuthAdapter(): boolean {\n return getRegisteredAuthAdapter() !== null\n}\n\n/**\n * `fetch` wrapper that attaches embed-proxy bearer headers (when\n * present in sessionStorage) and forces `credentials: 'same-origin'`\n * so Supabase auth cookies travel too.\n *\n * **Header merge direction (proxy WINS over caller):** the implementation\n * spreads `baseHeaders` first inside `applyProxyAuth`, then sets the\n * `Authorization` / `X-Chat-*` keys — so the proxy values take precedence\n * over anything the caller passed. The motivation is that the bearer +\n * act-as identity is the source of truth for embedded auth; a caller\n * accidentally passing a stale `Authorization` header should NOT override\n * the live proxy creds.\n *\n * **Cross-origin defense:** the wrapper assumes a same-origin `/api/…`\n * relative URL. Absolute URLs are accepted only when their origin matches\n * the current window's origin; cross-origin URLs throw before the bearer\n * leaves the page. This is a defense-in-depth guard for future call sites\n * — there is no legitimate cross-origin use of this fetch wrapper.\n *\n * **401 self-heal:** when a registered adapter supplies `refresh`, a `401`\n * response triggers a single token refresh + retry of the same request\n * (see `EmbedAuthAdapter.refresh`). This is the openframe `apiClient`'s\n * refresh-then-retry behaviour, lifted into the lib so embedded surfaces\n * no longer need a host-side `window.fetch` monkey-patch to survive an\n * expired access token mid-chat. With no adapter (or no `refresh`), the\n * 401 passes straight through unchanged.\n */\nexport function embedAuthedFetch(url: string, init: RequestInit = {}): Promise<Response> {\n // Same-origin guard runs SYNCHRONOUSLY (not awaited inside the async\n // helper below) so a bearer-leaking cross-origin URL throws before any\n // promise is created — callers and tests rely on the synchronous throw.\n assertSameOrigin(url)\n\n // `applyProxyAuth` accepts `Record<string, string>`; normalize the\n // caller's headers to that shape ONCE, up front. RequestInit accepts\n // `HeadersInit` which is broader (Headers instance OR array of tuples).\n // We re-derive the per-request headers from this base on every attempt\n // (initial + post-refresh retry) so a rotated bearer is picked up.\n //\n // When the caller passes no headers, fall back to the same default\n // `applyProxyAuth` uses internally — `Content-Type: application/json` —\n // so JSON POSTs keep their content-type when only `embedAuthedFetch(url)`\n // is used at the call site. GET callers that explicitly want no body\n // headers can pass `init.headers = {}` to opt out.\n let baseHeaders: Record<string, string>\n if (init.headers === undefined) {\n baseHeaders = { 'Content-Type': 'application/json' }\n } else {\n baseHeaders = {}\n if (init.headers instanceof Headers) {\n init.headers.forEach((v, k) => {\n baseHeaders[k] = v\n })\n } else if (Array.isArray(init.headers)) {\n for (const [k, v] of init.headers) baseHeaders[k] = v\n } else {\n Object.assign(baseHeaders, init.headers as Record<string, string>)\n }\n }\n\n return fetchWithRefresh(url, init, baseHeaders, false)\n}\n\n/**\n * Single in-flight refresh shared across all concurrent `embedAuthedFetch`\n * callers. A stampede of chat requests that all 401 at the same moment must\n * trigger the adapter's `refresh()` ONCE, not N times — otherwise an\n * expiring session fires a thundering herd of refresh calls at the auth\n * server. Resets to `null` once settled so the next genuine expiry can\n * refresh again.\n */\n// Stored on `globalThis` rather than a module-local so the \"single refresh\"\n// guarantee survives module duplication. Bundlers can ship more than one copy\n// of this module (e.g. across chunks or a host + embedded build); a per-module\n// variable would let each copy run its own refresh cycle, re-creating the\n// thundering-herd this dedupe exists to prevent.\nconst IN_FLIGHT_REFRESH_GLOBAL_KEY = '__embedAuthedFetchInFlightRefresh__'\n\nfunction getInFlightRefresh(): Promise<boolean> | null {\n if (typeof globalThis === 'undefined') return null\n return (\n ((globalThis as Record<string, unknown>)[IN_FLIGHT_REFRESH_GLOBAL_KEY] as\n | Promise<boolean>\n | null\n | undefined) ?? null\n )\n}\n\nfunction setInFlightRefresh(refresh: Promise<boolean> | null): void {\n if (typeof globalThis === 'undefined') return\n ;(globalThis as Record<string, unknown>)[IN_FLIGHT_REFRESH_GLOBAL_KEY] = refresh\n}\n\nfunction dedupedRefresh(): Promise<boolean> {\n const adapter = getRegisteredAuthAdapter()\n if (!adapter?.refresh) return Promise.resolve(false)\n let inFlightRefresh = getInFlightRefresh()\n if (!inFlightRefresh) {\n // Wrap in `Promise.resolve` so an adapter that throws synchronously\n // (rather than rejecting) still funnels through the shared slot and\n // clears it. A rejected refresh is treated as \"could not refresh\".\n inFlightRefresh = Promise.resolve()\n .then(() => adapter.refresh!())\n .catch(() => false)\n .finally(() => {\n setInFlightRefresh(null)\n })\n setInFlightRefresh(inFlightRefresh)\n }\n return inFlightRefresh\n}\n\n/**\n * Core fetch path: merge proxy-auth + adapter headers, issue the request,\n * and — on a `401` with a refresh-capable adapter — refresh once and retry\n * the identical request a single time. Mirrors the openframe `apiClient`'s\n * refresh-then-retry contract (`isRetry` guards against infinite loops).\n */\nasync function fetchWithRefresh(\n url: string,\n init: RequestInit,\n baseHeaders: Record<string, string>,\n isRetry: boolean,\n): Promise<Response> {\n // Re-run the merge each attempt: `applyProxyAuth` reads the latest stored\n // proxy creds and `getHeaders()` reads the latest bearer, so a retry after\n // refresh carries the rotated token rather than the stale one. `{...baseHeaders}`\n // keeps the caller's normalized headers immutable across attempts.\n const { url: authedUrl, headers } = applyProxyAuth(url, { ...baseHeaders })\n\n // Host-supplied auth adapter layer. Runs AFTER the proxy-auth merge so\n // adapter headers override both caller and proxy values — the adapter\n // is the host's explicit \"this is my auth model\" override, intentionally\n // last-writer-wins. When no adapter is registered, this is a zero-cost\n // no-op (object spread of `{}`).\n const adapter = getRegisteredAuthAdapter()\n if (adapter?.getHeaders) {\n // Filter `undefined` values — the adapter type allows them so consumers\n // don't have to narrow `{ Authorization: token ? '…' : undefined }`-shaped\n // returns, but `fetch` headers must be strings.\n for (const [k, v] of Object.entries(adapter.getHeaders())) {\n if (v !== undefined) headers[k] = v\n }\n }\n const credentials = adapter?.credentials ?? init.credentials ?? 'same-origin'\n\n const response = await fetch(authedUrl, {\n ...init,\n headers,\n // Default `same-origin` carries Supabase cookies for the MPH proxy-\n // auth model. Hosts on different origins (openframe-frontend ↔\n // openframe gateway) register `credentials: 'include'` via the\n // adapter to make their own cookies travel cross-origin (CORS +\n // `SameSite=None` must be configured server-side for that to work).\n credentials,\n })\n\n // 401 self-heal: refresh the token once and retry. Only when an adapter\n // opted into `refresh`, and only on the first attempt — a 401 on the\n // retry means the fresh token is also unauthorized, so surface it.\n if (response.status === 401 && !isRetry && adapter?.refresh) {\n const refreshed = await dedupedRefresh()\n if (refreshed) {\n return fetchWithRefresh(url, init, baseHeaders, true)\n }\n }\n\n return response\n}\n\n/**\n * Reject any URL that resolves to a cross-origin destination or to a\n * non-http(s) scheme. Every input is resolved against\n * `window.location.href` so the same rule covers path-only\n * (`/api/...`), absolute (`https://...`), protocol-relative\n * (`//host/...`), AND whitespace-prefixed forms (`\\t//evil.com/...`) —\n * the WHATWG fetch spec strips leading ASCII whitespace before\n * parsing, so any regex-based \"skip relative\" shortcut is bypassable\n * with a leading `\\t`/`\\n`/`\\r`/space. We resolve unconditionally\n * instead and compare origins.\n *\n * Also blocks `javascript:` / `data:` / `blob:` etc. — only `http(s):`\n * is allowed. This is explicit allowlisting rather than relying on\n * `origin === 'null'` to fall out wrong.\n *\n * Server-side rendering: when `typeof window === 'undefined'` we skip\n * the check — the bearer comes from sessionStorage which doesn't exist\n * on the server, so there's nothing to leak anyway.\n */\nfunction assertSameOrigin(url: string): void {\n if (typeof window === 'undefined') return\n let target: URL\n let pageOrigin: string\n try {\n target = new URL(url, window.location.href)\n // Derive the page origin from `href` rather than reading\n // `window.location.origin` directly so the check works in test\n // environments that mock `window.location` to a plain object\n // without an `origin` field (jsdom setups do this).\n pageOrigin = new URL(window.location.href).origin\n } catch {\n throw new Error(`embedAuthedFetch: refusing to fetch malformed URL (${JSON.stringify(url)})`)\n }\n if (target.protocol !== 'http:' && target.protocol !== 'https:') {\n throw new Error(\n `embedAuthedFetch: refusing non-http(s) URL (${target.protocol}) — pass a relative /api/* path instead`,\n )\n }\n if (target.origin !== pageOrigin) {\n // Dev-mode escape hatch — embedded apps (e.g. openframe-frontend)\n // run on a different origin from their gateway during local dev,\n // and forcing a Next.js `rewrites()` workaround is more error-prone\n // than relaxing the guard for the dev build. In production\n // (`NODE_ENV === 'production'`) the guard stays absolute — same\n // defense-in-depth bearer-leak protection as before. The check is\n // baked at build time by Next/webpack/Turbopack so prod bundles\n // contain only the throwing branch (no dev string in the artifact).\n if (process.env.NODE_ENV !== 'production') {\n console.warn(\n `[embedAuthedFetch] cross-origin fetch to ${target.origin} ` +\n `allowed in dev (NODE_ENV !== 'production'). Production builds ` +\n `will reject this — wire a same-origin proxy before shipping.`,\n )\n return\n }\n throw new Error(\n `embedAuthedFetch: refusing cross-origin fetch to ${target.origin} — pass a relative /api/* path instead`,\n )\n }\n}\n"]}
|