@devicai/ui 0.38.1 → 0.39.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/README.md +28 -4
  2. package/dist/cjs/components/ChatDrawer/ChatDrawer.js +19 -12
  3. package/dist/cjs/components/ChatDrawer/ChatDrawer.js.map +1 -1
  4. package/dist/cjs/components/IntegrationsModal/IntegrationLogo.js +23 -0
  5. package/dist/cjs/components/IntegrationsModal/IntegrationLogo.js.map +1 -0
  6. package/dist/cjs/components/IntegrationsModal/IntegrationsLauncher.js +68 -0
  7. package/dist/cjs/components/IntegrationsModal/IntegrationsLauncher.js.map +1 -0
  8. package/dist/cjs/components/IntegrationsModal/IntegrationsModal.js +73 -78
  9. package/dist/cjs/components/IntegrationsModal/IntegrationsModal.js.map +1 -1
  10. package/dist/cjs/components/IntegrationsModal/useIntegrations.js +106 -0
  11. package/dist/cjs/components/IntegrationsModal/useIntegrations.js.map +1 -0
  12. package/dist/cjs/components/theme.js +40 -0
  13. package/dist/cjs/components/theme.js.map +1 -1
  14. package/dist/cjs/index.js +7 -0
  15. package/dist/cjs/index.js.map +1 -1
  16. package/dist/cjs/styles.css +1 -1
  17. package/dist/esm/components/ChatDrawer/ChatDrawer.js +19 -12
  18. package/dist/esm/components/ChatDrawer/ChatDrawer.js.map +1 -1
  19. package/dist/esm/components/ChatDrawer/ChatDrawer.types.d.ts +15 -7
  20. package/dist/esm/components/IntegrationsModal/IntegrationLogo.d.ts +16 -0
  21. package/dist/esm/components/IntegrationsModal/IntegrationLogo.js +21 -0
  22. package/dist/esm/components/IntegrationsModal/IntegrationLogo.js.map +1 -0
  23. package/dist/esm/components/IntegrationsModal/IntegrationsLauncher.d.ts +31 -0
  24. package/dist/esm/components/IntegrationsModal/IntegrationsLauncher.js +65 -0
  25. package/dist/esm/components/IntegrationsModal/IntegrationsLauncher.js.map +1 -0
  26. package/dist/esm/components/IntegrationsModal/IntegrationsModal.d.ts +10 -1
  27. package/dist/esm/components/IntegrationsModal/IntegrationsModal.js +73 -78
  28. package/dist/esm/components/IntegrationsModal/IntegrationsModal.js.map +1 -1
  29. package/dist/esm/components/IntegrationsModal/index.d.ts +6 -0
  30. package/dist/esm/components/IntegrationsModal/useIntegrations.d.ts +49 -0
  31. package/dist/esm/components/IntegrationsModal/useIntegrations.js +104 -0
  32. package/dist/esm/components/IntegrationsModal/useIntegrations.js.map +1 -0
  33. package/dist/esm/components/theme.d.ts +9 -0
  34. package/dist/esm/components/theme.js +40 -1
  35. package/dist/esm/components/theme.js.map +1 -1
  36. package/dist/esm/index.d.ts +3 -3
  37. package/dist/esm/index.js +4 -1
  38. package/dist/esm/index.js.map +1 -1
  39. package/dist/esm/styles.css +1 -1
  40. package/package.json +1 -1
@@ -1,13 +1,16 @@
1
1
  import { jsx, jsxs } from 'react/jsx-runtime';
2
- import { useMemo, useState, useCallback, useRef, useEffect } from 'react';
2
+ import { useState, useMemo, useRef, useEffect, useCallback } from 'react';
3
3
  import { createPortal } from 'react-dom';
4
- import { DevicApiClient } from '../../api/client.js';
5
- import { useOptionalDevicContext } from '../../provider/DevicContext.js';
6
- import { themeVars } from '../theme.js';
4
+ import { isDarkTheme, themeVars } from '../theme.js';
5
+ import { IntegrationLogo } from './IntegrationLogo.js';
6
+ import { useIntegrations } from './useIntegrations.js';
7
7
 
8
8
  function PlugIcon() {
9
9
  return (jsxs("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: [jsx("path", { d: "M12 22v-5" }), jsx("path", { d: "M9 8V2" }), jsx("path", { d: "M15 8V2" }), jsx("path", { d: "M18 8v5a4 4 0 0 1-4 4h-4a4 4 0 0 1-4-4V8Z" })] }));
10
10
  }
11
+ function SearchIcon() {
12
+ return (jsxs("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: [jsx("circle", { cx: "11", cy: "11", r: "7" }), jsx("path", { d: "m20 20-3.5-3.5" })] }));
13
+ }
11
14
  /** A random value tying an OAuth round trip to the window that started it. */
12
15
  function newNonce() {
13
16
  const c = typeof crypto !== "undefined" ? crypto : undefined;
@@ -32,6 +35,14 @@ function accountLabel(account) {
32
35
  return account.status.toLowerCase();
33
36
  return `connected ${when.toLocaleDateString()}`;
34
37
  }
38
+ function matches(integration, query) {
39
+ const q = query.trim().toLowerCase();
40
+ if (!q)
41
+ return true;
42
+ return (integration.name.toLowerCase().includes(q) ||
43
+ integration.app.toLowerCase().includes(q) ||
44
+ (integration.description ?? "").toLowerCase().includes(q));
45
+ }
35
46
  /**
36
47
  * Modal where the END USER of an application manages their *own* third-party
37
48
  * accounts: the apps the developer offered to tenants of this assistant, each
@@ -48,70 +59,55 @@ function accountLabel(account) {
48
59
  * after the round trip is what gets it blocked. When it is blocked anyway, the
49
60
  * URL is offered as a link instead.
50
61
  */
51
- function IntegrationsModal({ isOpen, onClose, assistantId, tenantId, subtenantId, apiKey, baseUrl, title = "Connected apps", onChange, theme, }) {
52
- const context = useOptionalDevicContext();
53
- const resolvedApiKey = apiKey || context?.apiKey;
54
- const resolvedBaseUrl = baseUrl || context?.baseUrl || "https://api.devic.ai";
55
- const resolvedTenantId = tenantId || context?.tenantId;
56
- const resolvedSubtenantId = subtenantId || context?.subtenantId;
57
- const client = useMemo(() => resolvedApiKey
58
- ? new DevicApiClient({
59
- apiKey: resolvedApiKey,
60
- baseUrl: resolvedBaseUrl,
61
- })
62
- : null, [resolvedApiKey, resolvedBaseUrl]);
63
- const scopeOptions = useMemo(() => ({
62
+ function IntegrationsModal({ isOpen, onClose, assistantId, tenantId, subtenantId, apiKey, baseUrl, title = "Connected apps", searchPlaceholder = "Search connected apps", onChange, theme, state, }) {
63
+ // Hooks cannot be skipped, so the fallback is always built and only fetches
64
+ // when nobody handed a listing down.
65
+ const own = useIntegrations({
64
66
  assistantId,
65
- tenantId: resolvedTenantId || undefined,
66
- subtenantId: resolvedSubtenantId || undefined,
67
- }), [assistantId, resolvedTenantId, resolvedSubtenantId]);
68
- const [loading, setLoading] = useState(false);
69
- const [integrations, setIntegrations] = useState([]);
70
- const [error, setError] = useState(null);
67
+ tenantId,
68
+ subtenantId,
69
+ apiKey,
70
+ baseUrl,
71
+ enabled: isOpen && !state,
72
+ });
73
+ const { integrations, loading, error: loadError, refresh, client, scope } = state ?? own;
74
+ /** Errors from connecting or disconnecting, kept apart from load failures. */
75
+ const [actionError, setActionError] = useState(null);
76
+ const error = actionError ?? loadError;
71
77
  /** App slug with a connect/disconnect in flight, so only its card is busy. */
72
78
  const [busyApp, setBusyApp] = useState(null);
73
79
  /** Authorization URL surfaced as a link when the popup was blocked. */
74
80
  const [blockedUrl, setBlockedUrl] = useState(null);
75
- /**
76
- * Apps whose logo failed to load. The URL comes from the provider and is
77
- * fetched from whatever host it names, so a broken one is a matter of when,
78
- * not if and a broken-image icon in someone else's product looks like our
79
- * bug.
80
- */
81
- const [brokenLogos, setBrokenLogos] = useState([]);
82
- const refresh = useCallback(async (dropCache = false) => {
83
- if (!client) {
84
- setError("API key not configured");
85
- return;
86
- }
87
- setLoading(true);
88
- setError(null);
89
- try {
90
- // The server caches a scope's connections briefly; after an OAuth round
91
- // trip that cache is exactly one step behind, so drop it first.
92
- if (dropCache) {
93
- await client.refreshIntegrations(scopeOptions).catch(() => undefined);
94
- }
95
- const list = await client.getIntegrations(scopeOptions);
96
- setIntegrations(list);
97
- onChange?.(list);
98
- }
99
- catch (err) {
100
- setError(err instanceof Error ? err.message : String(err));
101
- }
102
- finally {
103
- setLoading(false);
104
- }
105
- }, [client, scopeOptions, onChange]);
106
- // Fetch on every open: accounts may have been connected or revoked elsewhere.
81
+ const [query, setQuery] = useState("");
82
+ const visible = useMemo(() => integrations.filter((i) => matches(i, query)), [integrations, query]);
83
+ // Report the listing without making the caller's identity part of the
84
+ // dependency: an inline arrow would fire this on every render.
85
+ const onChangeRef = useRef(onChange);
86
+ onChangeRef.current = onChange;
87
+ useEffect(() => {
88
+ if (integrations.length)
89
+ onChangeRef.current?.(integrations);
90
+ }, [integrations]);
91
+ // Reopening starts clean, and re-reads: accounts may have been connected or
92
+ // revoked elsewhere since the last look.
107
93
  const wasOpenRef = useRef(false);
94
+ const openedBeforeRef = useRef(false);
108
95
  useEffect(() => {
109
96
  if (isOpen && !wasOpenRef.current) {
110
97
  setBlockedUrl(null);
111
- void refresh();
98
+ setActionError(null);
99
+ setQuery("");
100
+ // The very first open of an uncontrolled modal is already covered by the
101
+ // hook switching on; asking again here would double every first open.
102
+ if (state || openedBeforeRef.current)
103
+ void refresh();
104
+ openedBeforeRef.current = true;
112
105
  }
113
106
  wasOpenRef.current = isOpen;
114
- }, [isOpen, refresh]);
107
+ // `state.refresh` is stable per scope; re-running on every render of the
108
+ // owner is exactly what this must not do.
109
+ // eslint-disable-next-line react-hooks/exhaustive-deps
110
+ }, [isOpen]);
115
111
  // Escape closes
116
112
  useEffect(() => {
117
113
  if (!isOpen)
@@ -166,7 +162,7 @@ function IntegrationsModal({ isOpen, onClose, assistantId, tenantId, subtenantId
166
162
  const handleConnect = async (integration) => {
167
163
  if (!client || busyApp)
168
164
  return;
169
- setError(null);
165
+ setActionError(null);
170
166
  setBlockedUrl(null);
171
167
  setBusyApp(integration.app);
172
168
  const nonce = newNonce();
@@ -174,7 +170,7 @@ function IntegrationsModal({ isOpen, onClose, assistantId, tenantId, subtenantId
174
170
  // Opened empty inside the click, navigated once the URL is known.
175
171
  const popup = window.open("", "devic-oauth", "width=520,height=680,menubar=no,toolbar=no");
176
172
  try {
177
- const { authorizationUrl } = await client.connectIntegration(integration.app, { ...scopeOptions, returnTo });
173
+ const { authorizationUrl } = await client.connectIntegration(integration.app, { ...scope, returnTo });
178
174
  pendingRef.current = { app: integration.app, returnTo };
179
175
  if (popup && !popup.closed) {
180
176
  popupRef.current = popup;
@@ -197,7 +193,7 @@ function IntegrationsModal({ isOpen, onClose, assistantId, tenantId, subtenantId
197
193
  catch (err) {
198
194
  popup?.close();
199
195
  pendingRef.current = null;
200
- setError(err instanceof Error ? err.message : String(err));
196
+ setActionError(err instanceof Error ? err.message : String(err));
201
197
  setBusyApp(null);
202
198
  }
203
199
  };
@@ -205,13 +201,13 @@ function IntegrationsModal({ isOpen, onClose, assistantId, tenantId, subtenantId
205
201
  if (!client || busyApp)
206
202
  return;
207
203
  setBusyApp(app);
208
- setError(null);
204
+ setActionError(null);
209
205
  try {
210
- await client.disconnectIntegration(account.id, scopeOptions);
206
+ await client.disconnectIntegration(account.id, scope);
211
207
  await refresh(true);
212
208
  }
213
209
  catch (err) {
214
- setError(err instanceof Error ? err.message : String(err));
210
+ setActionError(err instanceof Error ? err.message : String(err));
215
211
  }
216
212
  finally {
217
213
  setBusyApp(null);
@@ -223,23 +219,22 @@ function IntegrationsModal({ isOpen, onClose, assistantId, tenantId, subtenantId
223
219
  // The variables go on the overlay, not on the modal: the backdrop is part
224
220
  // of the dialog, and a portal inherits nothing from the drawer that opened
225
221
  // it.
226
- jsx("div", { className: "devic-int-overlay", style: themeVars(theme), onClick: onClose, children: jsxs("div", { className: "devic-int-modal", role: "dialog", "aria-modal": "true", "aria-label": title, onClick: (e) => e.stopPropagation(), children: [jsxs("div", { className: "devic-int-header", children: [jsxs("h3", { className: "devic-int-title", children: [jsx(PlugIcon, {}), title] }), jsx("button", { className: "devic-int-close", onClick: onClose, type: "button", "aria-label": "Close", children: "\u00D7" })] }), jsxs("div", { className: "devic-int-body", children: [error && jsx("div", { className: "devic-int-error", children: error }), blockedUrl && (jsxs("div", { className: "devic-int-notice", children: ["Your browser blocked the pop-up.", " ", jsx("a", { href: blockedUrl.url, target: "_blank", rel: "noopener noreferrer", onClick: () => {
222
+ jsx("div", { className: "devic-int-overlay", style: themeVars(theme), "data-dark": isDarkTheme(theme), onClick: onClose, children: jsxs("div", { className: "devic-int-modal", role: "dialog", "aria-modal": "true", "aria-label": title, onClick: (e) => e.stopPropagation(), children: [jsxs("div", { className: "devic-int-header", children: [jsxs("h3", { className: "devic-int-title", children: [jsx(PlugIcon, {}), title] }), jsx("button", { className: "devic-int-close", onClick: onClose, type: "button", "aria-label": "Close", children: "\u00D7" })] }), jsxs("div", { className: "devic-int-search", children: [jsx(SearchIcon, {}), jsx("input", { type: "search", value: query, onChange: (e) => setQuery(e.target.value), placeholder: searchPlaceholder, "aria-label": searchPlaceholder, autoComplete: "off" })] }), jsxs("div", { className: "devic-int-body", children: [error && jsx("div", { className: "devic-int-error", children: error }), blockedUrl && (jsxs("div", { className: "devic-int-notice", children: ["Your browser blocked the pop-up.", " ", jsx("a", { href: blockedUrl.url, target: "_blank", rel: "noopener noreferrer", onClick: () => {
227
223
  pendingRef.current = null;
228
224
  setBlockedUrl(null);
229
- }, children: "Open the authorisation page" }), " ", "and come back \u2014 then use Refresh."] })), loading && integrations.length === 0 ? (jsx("div", { className: "devic-int-loading", children: "Loading apps\u2026" })) : integrations.length === 0 ? (jsx("div", { className: "devic-int-empty", children: "No apps available here yet." })) : (integrations.map((integration) => {
230
- const state = stateOf(integration);
231
- const busy = busyApp === integration.app;
232
- return (jsxs("div", { className: "devic-int-card", "data-state": state.key, children: [jsxs("div", { className: "devic-int-card-head", children: [integration.logo &&
233
- !brokenLogos.includes(integration.app) ? (jsx("img", { className: "devic-int-logo", src: integration.logo, alt: "", "aria-hidden": "true", onError: () => setBrokenLogos((prev) => prev.includes(integration.app)
234
- ? prev
235
- : [...prev, integration.app]) })) : (jsx("span", { className: "devic-int-logo devic-int-logo-fallback", children: integration.name.charAt(0).toUpperCase() })), jsxs("div", { className: "devic-int-card-text", children: [jsx("div", { className: "devic-int-name", children: integration.name }), jsx("div", { className: "devic-int-state", children: state.label })] }), jsx("button", { type: "button", className: `devic-int-btn${state.key === "connected" ? "" : " devic-int-btn-primary"}`, onClick: () => handleConnect(integration), disabled: busy || !!busyApp, children: busy
236
- ? "Waiting…"
237
- : state.key === "disconnected"
238
- ? "Connect"
239
- : state.key === "reconnect"
240
- ? "Reconnect"
241
- : "Add account" })] }), integration.description && (jsx("div", { className: "devic-int-description", children: integration.description })), integration.accounts.length > 0 && (jsx("ul", { className: "devic-int-accounts", children: integration.accounts.map((account) => (jsxs("li", { className: "devic-int-account", children: [jsx("span", { className: "devic-int-dot", "data-ok": !account.needsReconnect, "aria-hidden": "true" }), jsxs("span", { className: "devic-int-account-label", children: [accountLabel(account), account.needsReconnect && (jsxs("span", { className: "devic-int-account-warn", children: [" ", "\u00B7 reconnect required"] }))] }), jsx("button", { type: "button", className: "devic-int-btn devic-int-btn-small devic-int-btn-danger", onClick: () => handleDisconnect(integration.app, account), disabled: !!busyApp, children: "Disconnect" })] }, account.id))) }))] }, integration.app));
242
- }))] }), jsxs("div", { className: "devic-int-footer", children: [jsx("span", { children: "Only you can see and use the accounts you connect here." }), jsx("button", { type: "button", className: "devic-int-btn devic-int-btn-small", onClick: () => void refresh(true), disabled: loading || !!busyApp, children: "Refresh" })] })] }) }), document.body);
225
+ }, children: "Open the authorisation page" }), " ", "and come back \u2014 then use Refresh."] })), loading && integrations.length === 0 ? (jsx("div", { className: "devic-int-loading", children: "Loading apps\u2026" })) : integrations.length === 0 ? (jsx("div", { className: "devic-int-empty", children: "No apps available here yet." })) : visible.length === 0 ? (jsxs("div", { className: "devic-int-empty", children: ["No apps match \u201C", query.trim(), "\u201D."] })) : (jsx("div", { className: "devic-int-grid", children: visible.map((integration) => {
226
+ const cardState = stateOf(integration);
227
+ const busy = busyApp === integration.app;
228
+ return (jsxs("div", { className: "devic-int-card", "data-state": cardState.key, children: [jsxs("div", { className: "devic-int-card-head", children: [jsx(IntegrationLogo, { integration: integration }), jsxs("span", { className: "devic-int-state", children: [jsx("span", { className: "devic-int-dot", "data-ok": cardState.key === "connected", "data-off": cardState.key === "disconnected", "aria-hidden": "true" }), cardState.label] })] }), jsx("div", { className: "devic-int-name", title: integration.name, children: integration.name }), integration.description && (jsx("div", { className: "devic-int-description", title: integration.description, children: integration.description })), jsx("button", { type: "button", className: `devic-int-btn devic-int-btn-block${cardState.key === "connected"
229
+ ? ""
230
+ : " devic-int-btn-primary"}`, onClick: () => handleConnect(integration), disabled: busy || !!busyApp, children: busy
231
+ ? "Waiting…"
232
+ : cardState.key === "disconnected"
233
+ ? "Connect"
234
+ : cardState.key === "reconnect"
235
+ ? "Reconnect"
236
+ : "Add account" }), integration.accounts.length > 0 && (jsx("ul", { className: "devic-int-accounts", children: integration.accounts.map((account) => (jsxs("li", { className: "devic-int-account", children: [jsx("span", { className: "devic-int-dot", "data-ok": !account.needsReconnect, "aria-hidden": "true" }), jsxs("span", { className: "devic-int-account-label", children: [accountLabel(account), account.needsReconnect && (jsxs("span", { className: "devic-int-account-warn", children: [" ", "\u00B7 reconnect required"] }))] }), jsx("button", { type: "button", className: "devic-int-unlink", onClick: () => handleDisconnect(integration.app, account), disabled: !!busyApp, title: "Disconnect this account", "aria-label": `Disconnect ${integration.name}`, children: "\u00D7" })] }, account.id))) }))] }, integration.app));
237
+ }) }))] }), jsxs("div", { className: "devic-int-footer", children: [jsx("span", { children: "Only you can see and use the accounts you connect here." }), jsx("button", { type: "button", className: "devic-int-btn devic-int-btn-small", onClick: () => void refresh(true), disabled: loading || !!busyApp, children: "Refresh" })] })] }) }), document.body);
243
238
  }
244
239
 
245
240
  export { IntegrationsModal };
@@ -1 +1 @@
1
- {"version":3,"file":"IntegrationsModal.js","sources":["../../../../src/components/IntegrationsModal/IntegrationsModal.tsx"],"sourcesContent":["import {\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n type JSX,\n} from \"react\";\nimport { createPortal } from \"react-dom\";\nimport { DevicApiClient } from \"../../api/client\";\nimport type { Integration, IntegrationAccount } from \"../../api/types\";\nimport { useOptionalDevicContext } from \"../../provider\";\nimport { themeVars, type DevicTheme } from \"../theme\";\nimport \"./IntegrationsModal.css\";\n\n/** Message the OAuth callback page posts back to this window when it is done. */\ninterface CallbackMessage {\n source?: string;\n type?: string;\n app?: string;\n status?: string;\n returnTo?: string;\n}\n\nexport interface IntegrationsModalProps {\n /** Whether the modal is visible. */\n isOpen: boolean;\n onClose: () => void;\n /** Assistant whose offered apps are shown. */\n assistantId: string;\n /** Tenant of the end user (falls back to the provider's tenantId). */\n tenantId?: string;\n /** Subtenant of the end user (falls back to the provider's subtenantId). */\n subtenantId?: string;\n /** API key override (falls back to the provider's). */\n apiKey?: string;\n /** Base URL override (falls back to the provider's). */\n baseUrl?: string;\n /** Modal title. @default \"Connected apps\" */\n title?: string;\n /** Called after an account is connected or disconnected. */\n onChange?: (integrations: Integration[]) => void;\n /**\n * Colours and font. Same names as the drawer's style options, and the drawer\n * passes its own down — a dialog opening in the default light palette over a\n * themed application is the one thing this must not do.\n */\n theme?: DevicTheme;\n}\n\nfunction PlugIcon(): JSX.Element {\n return (\n <svg\n width=\"16\"\n height=\"16\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n aria-hidden=\"true\"\n >\n <path d=\"M12 22v-5\" />\n <path d=\"M9 8V2\" />\n <path d=\"M15 8V2\" />\n <path d=\"M18 8v5a4 4 0 0 1-4 4h-4a4 4 0 0 1-4-4V8Z\" />\n </svg>\n );\n}\n\n/** A random value tying an OAuth round trip to the window that started it. */\nfunction newNonce(): string {\n const c = typeof crypto !== \"undefined\" ? crypto : undefined;\n if (c?.randomUUID) return c.randomUUID();\n return `${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;\n}\n\n/** How the card describes an app at a glance. */\nfunction stateOf(integration: Integration): {\n key: \"connected\" | \"reconnect\" | \"disconnected\";\n label: string;\n} {\n if (integration.connected) return { key: \"connected\", label: \"Connected\" };\n if (integration.accounts.some((a) => a.needsReconnect)) {\n return { key: \"reconnect\", label: \"Needs reconnection\" };\n }\n return { key: \"disconnected\", label: \"Not connected\" };\n}\n\nfunction accountLabel(account: IntegrationAccount): string {\n if (!account.connectedAt) return account.status.toLowerCase();\n const when = new Date(account.connectedAt);\n if (Number.isNaN(when.getTime())) return account.status.toLowerCase();\n return `connected ${when.toLocaleDateString()}`;\n}\n\n/**\n * Modal where the END USER of an application manages their *own* third-party\n * accounts: the apps the developer offered to tenants of this assistant, each\n * with the accounts this tenant has connected, and the buttons to add or\n * remove one.\n *\n * Backed by `/api/v1/tenant-integrations`, which resolves the tenant\n * server-side, so what is listed here is only ever this tenant's — never the\n * workspace-wide accounts an admin connected, and never another tenant's.\n *\n * Connecting opens the provider's consent screen in a popup. The popup is\n * opened empty *before* the request that produces its URL, because browsers\n * only honour `window.open` inside the gesture that triggered it: opening it\n * after the round trip is what gets it blocked. When it is blocked anyway, the\n * URL is offered as a link instead.\n */\nexport function IntegrationsModal({\n isOpen,\n onClose,\n assistantId,\n tenantId,\n subtenantId,\n apiKey,\n baseUrl,\n title = \"Connected apps\",\n onChange,\n theme,\n}: IntegrationsModalProps): JSX.Element | null {\n const context = useOptionalDevicContext();\n const resolvedApiKey = apiKey || context?.apiKey;\n const resolvedBaseUrl = baseUrl || context?.baseUrl || \"https://api.devic.ai\";\n const resolvedTenantId = tenantId || context?.tenantId;\n const resolvedSubtenantId = subtenantId || context?.subtenantId;\n\n const client = useMemo(\n () =>\n resolvedApiKey\n ? new DevicApiClient({\n apiKey: resolvedApiKey,\n baseUrl: resolvedBaseUrl,\n })\n : null,\n [resolvedApiKey, resolvedBaseUrl]\n );\n\n const scopeOptions = useMemo(\n () => ({\n assistantId,\n tenantId: resolvedTenantId || undefined,\n subtenantId: resolvedSubtenantId || undefined,\n }),\n [assistantId, resolvedTenantId, resolvedSubtenantId]\n );\n\n const [loading, setLoading] = useState(false);\n const [integrations, setIntegrations] = useState<Integration[]>([]);\n const [error, setError] = useState<string | null>(null);\n /** App slug with a connect/disconnect in flight, so only its card is busy. */\n const [busyApp, setBusyApp] = useState<string | null>(null);\n /** Authorization URL surfaced as a link when the popup was blocked. */\n const [blockedUrl, setBlockedUrl] = useState<{ app: string; url: string } | null>(\n null\n );\n /**\n * Apps whose logo failed to load. The URL comes from the provider and is\n * fetched from whatever host it names, so a broken one is a matter of when,\n * not if — and a broken-image icon in someone else's product looks like our\n * bug.\n */\n const [brokenLogos, setBrokenLogos] = useState<string[]>([]);\n\n const refresh = useCallback(\n async (dropCache = false) => {\n if (!client) {\n setError(\"API key not configured\");\n return;\n }\n setLoading(true);\n setError(null);\n try {\n // The server caches a scope's connections briefly; after an OAuth round\n // trip that cache is exactly one step behind, so drop it first.\n if (dropCache) {\n await client.refreshIntegrations(scopeOptions).catch(() => undefined);\n }\n const list = await client.getIntegrations(scopeOptions);\n setIntegrations(list);\n onChange?.(list);\n } catch (err) {\n setError(err instanceof Error ? err.message : String(err));\n } finally {\n setLoading(false);\n }\n },\n [client, scopeOptions, onChange]\n );\n\n // Fetch on every open: accounts may have been connected or revoked elsewhere.\n const wasOpenRef = useRef(false);\n useEffect(() => {\n if (isOpen && !wasOpenRef.current) {\n setBlockedUrl(null);\n void refresh();\n }\n wasOpenRef.current = isOpen;\n }, [isOpen, refresh]);\n\n // Escape closes\n useEffect(() => {\n if (!isOpen) return;\n const onKey = (e: KeyboardEvent) => {\n if (e.key === \"Escape\") onClose();\n };\n document.addEventListener(\"keydown\", onKey);\n return () => document.removeEventListener(\"keydown\", onKey);\n }, [isOpen, onClose]);\n\n /** The round trip currently in flight, if any. */\n const pendingRef = useRef<{ app: string; returnTo: string } | null>(null);\n const popupRef = useRef<Window | null>(null);\n const pollRef = useRef<number | null>(null);\n\n const finishConnect = useCallback(() => {\n if (pollRef.current !== null) {\n window.clearInterval(pollRef.current);\n pollRef.current = null;\n }\n pendingRef.current = null;\n popupRef.current = null;\n setBusyApp(null);\n void refresh(true);\n }, [refresh]);\n\n // The callback page tells us it is done. Treat the message as a nudge, never\n // as the result: what is displayed comes from re-reading the server, so a\n // forged message can at worst cause one redundant fetch.\n useEffect(() => {\n if (!isOpen) return;\n const onMessage = (event: MessageEvent) => {\n const data = event.data as CallbackMessage | undefined;\n if (!data || data.source !== \"devic\") return;\n if (data.type !== \"integration-connected\") return;\n const pending = pendingRef.current;\n if (!pending || data.returnTo !== pending.returnTo) return;\n popupRef.current?.close();\n finishConnect();\n };\n window.addEventListener(\"message\", onMessage);\n return () => window.removeEventListener(\"message\", onMessage);\n }, [isOpen, finishConnect]);\n\n // Stop polling if the modal goes away mid-flow.\n useEffect(\n () => () => {\n if (pollRef.current !== null) window.clearInterval(pollRef.current);\n },\n []\n );\n\n const handleConnect = async (integration: Integration) => {\n if (!client || busyApp) return;\n setError(null);\n setBlockedUrl(null);\n setBusyApp(integration.app);\n\n const nonce = newNonce();\n const returnTo = `${window.location.origin}/?devic_oauth=${nonce}`;\n // Opened empty inside the click, navigated once the URL is known.\n const popup = window.open(\n \"\",\n \"devic-oauth\",\n \"width=520,height=680,menubar=no,toolbar=no\"\n );\n\n try {\n const { authorizationUrl } = await client.connectIntegration(\n integration.app,\n { ...scopeOptions, returnTo }\n );\n pendingRef.current = { app: integration.app, returnTo };\n if (popup && !popup.closed) {\n popupRef.current = popup;\n popup.location.href = authorizationUrl;\n // The user may close the popup without the callback ever posting back\n // — a cancelled consent screen, or a provider that lands somewhere\n // else. Watching for the close is what keeps the card from staying\n // busy forever.\n pollRef.current = window.setInterval(() => {\n if (popup.closed) finishConnect();\n }, 700);\n } else {\n // Blocked (Safari, in-app browsers, extensions): hand over the URL.\n setBlockedUrl({ app: integration.app, url: authorizationUrl });\n setBusyApp(null);\n }\n } catch (err) {\n popup?.close();\n pendingRef.current = null;\n setError(err instanceof Error ? err.message : String(err));\n setBusyApp(null);\n }\n };\n\n const handleDisconnect = async (app: string, account: IntegrationAccount) => {\n if (!client || busyApp) return;\n setBusyApp(app);\n setError(null);\n try {\n await client.disconnectIntegration(account.id, scopeOptions);\n await refresh(true);\n } catch (err) {\n setError(err instanceof Error ? err.message : String(err));\n } finally {\n setBusyApp(null);\n }\n };\n\n if (!isOpen) return null;\n\n return createPortal(\n // The variables go on the overlay, not on the modal: the backdrop is part\n // of the dialog, and a portal inherits nothing from the drawer that opened\n // it.\n <div\n className=\"devic-int-overlay\"\n style={themeVars(theme)}\n onClick={onClose}\n >\n <div\n className=\"devic-int-modal\"\n role=\"dialog\"\n aria-modal=\"true\"\n aria-label={title}\n onClick={(e) => e.stopPropagation()}\n >\n <div className=\"devic-int-header\">\n <h3 className=\"devic-int-title\">\n <PlugIcon />\n {title}\n </h3>\n <button\n className=\"devic-int-close\"\n onClick={onClose}\n type=\"button\"\n aria-label=\"Close\"\n >\n ×\n </button>\n </div>\n\n <div className=\"devic-int-body\">\n {error && <div className=\"devic-int-error\">{error}</div>}\n\n {blockedUrl && (\n <div className=\"devic-int-notice\">\n Your browser blocked the pop-up.{\" \"}\n <a\n href={blockedUrl.url}\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n onClick={() => {\n pendingRef.current = null;\n setBlockedUrl(null);\n }}\n >\n Open the authorisation page\n </a>{\" \"}\n and come back — then use Refresh.\n </div>\n )}\n\n {loading && integrations.length === 0 ? (\n <div className=\"devic-int-loading\">Loading apps…</div>\n ) : integrations.length === 0 ? (\n <div className=\"devic-int-empty\">\n No apps available here yet.\n </div>\n ) : (\n integrations.map((integration) => {\n const state = stateOf(integration);\n const busy = busyApp === integration.app;\n return (\n <div\n key={integration.app}\n className=\"devic-int-card\"\n data-state={state.key}\n >\n <div className=\"devic-int-card-head\">\n {integration.logo &&\n !brokenLogos.includes(integration.app) ? (\n <img\n className=\"devic-int-logo\"\n src={integration.logo}\n alt=\"\"\n aria-hidden=\"true\"\n onError={() =>\n setBrokenLogos((prev) =>\n prev.includes(integration.app)\n ? prev\n : [...prev, integration.app]\n )\n }\n />\n ) : (\n <span className=\"devic-int-logo devic-int-logo-fallback\">\n {integration.name.charAt(0).toUpperCase()}\n </span>\n )}\n <div className=\"devic-int-card-text\">\n <div className=\"devic-int-name\">{integration.name}</div>\n <div className=\"devic-int-state\">{state.label}</div>\n </div>\n <button\n type=\"button\"\n className={`devic-int-btn${\n state.key === \"connected\" ? \"\" : \" devic-int-btn-primary\"\n }`}\n onClick={() => handleConnect(integration)}\n disabled={busy || !!busyApp}\n >\n {busy\n ? \"Waiting…\"\n : state.key === \"disconnected\"\n ? \"Connect\"\n : state.key === \"reconnect\"\n ? \"Reconnect\"\n : \"Add account\"}\n </button>\n </div>\n\n {integration.description && (\n <div className=\"devic-int-description\">\n {integration.description}\n </div>\n )}\n\n {integration.accounts.length > 0 && (\n <ul className=\"devic-int-accounts\">\n {integration.accounts.map((account) => (\n <li key={account.id} className=\"devic-int-account\">\n <span\n className=\"devic-int-dot\"\n data-ok={!account.needsReconnect}\n aria-hidden=\"true\"\n />\n <span className=\"devic-int-account-label\">\n {accountLabel(account)}\n {account.needsReconnect && (\n <span className=\"devic-int-account-warn\">\n {\" \"}\n · reconnect required\n </span>\n )}\n </span>\n <button\n type=\"button\"\n className=\"devic-int-btn devic-int-btn-small devic-int-btn-danger\"\n onClick={() =>\n handleDisconnect(integration.app, account)\n }\n disabled={!!busyApp}\n >\n Disconnect\n </button>\n </li>\n ))}\n </ul>\n )}\n </div>\n );\n })\n )}\n </div>\n\n <div className=\"devic-int-footer\">\n <span>Only you can see and use the accounts you connect here.</span>\n <button\n type=\"button\"\n className=\"devic-int-btn devic-int-btn-small\"\n onClick={() => void refresh(true)}\n disabled={loading || !!busyApp}\n >\n Refresh\n </button>\n </div>\n </div>\n </div>,\n document.body\n );\n}\n\nexport default IntegrationsModal;\n"],"names":["_jsxs","_jsx"],"mappings":";;;;;;;AAkDA,SAAS,QAAQ,GAAA;AACf,IAAA,QACEA,IAAA,CAAA,KAAA,EAAA,EACE,KAAK,EAAC,IAAI,EACV,MAAM,EAAC,IAAI,EACX,OAAO,EAAC,WAAW,EACnB,IAAI,EAAC,MAAM,EACX,MAAM,EAAC,cAAc,EACrB,WAAW,EAAC,GAAG,EACf,aAAa,EAAC,OAAO,EACrB,cAAc,EAAC,OAAO,EAAA,aAAA,EACV,MAAM,EA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mC,EAC7C,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,EACjC,QAAQ,EAAE,OAAO,IAAI,CAAC,CAAC,OAAO,EAAA,QAAA,EAAA,SAAA,EAAA,CAGvB,IACL,CAAA,EAAA,CACF,EAAA,CACF,EACN,QAAQ,CAAC,IAAI,CACd;AACH;;;;"}
1
+ {"version":3,"file":"IntegrationsModal.js","sources":["../../../../src/components/IntegrationsModal/IntegrationsModal.tsx"],"sourcesContent":["import {\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n type JSX,\n} from \"react\";\nimport { createPortal } from \"react-dom\";\nimport type { Integration, IntegrationAccount } from \"../../api/types\";\nimport { isDarkTheme, themeVars, type DevicTheme } from \"../theme\";\nimport { IntegrationLogo } from \"./IntegrationLogo\";\nimport { useIntegrations, type IntegrationsState } from \"./useIntegrations\";\nimport \"./IntegrationsModal.css\";\n\n/** Message the OAuth callback page posts back to this window when it is done. */\ninterface CallbackMessage {\n source?: string;\n type?: string;\n app?: string;\n status?: string;\n returnTo?: string;\n}\n\nexport interface IntegrationsModalProps {\n /** Whether the modal is visible. */\n isOpen: boolean;\n onClose: () => void;\n /** Assistant whose offered apps are shown. */\n assistantId: string;\n /** Tenant of the end user (falls back to the provider's tenantId). */\n tenantId?: string;\n /** Subtenant of the end user (falls back to the provider's subtenantId). */\n subtenantId?: string;\n /** API key override (falls back to the provider's). */\n apiKey?: string;\n /** Base URL override (falls back to the provider's). */\n baseUrl?: string;\n /** Modal title. @default \"Connected apps\" */\n title?: string;\n /** Search field placeholder. @default \"Search connected apps\" */\n searchPlaceholder?: string;\n /** Called after an account is connected or disconnected. */\n onChange?: (integrations: Integration[]) => void;\n /**\n * Colours and font. Same names as the drawer's style options, and the drawer\n * passes its own down — a dialog opening in the default light palette over a\n * themed application is the one thing this must not do.\n */\n theme?: DevicTheme;\n /**\n * Listing loaded elsewhere (see `useIntegrations`). The drawer already has to\n * load it to decide whether its button exists, and passing it down is what\n * keeps opening the modal from asking for the very same thing again.\n */\n state?: IntegrationsState;\n}\n\nfunction PlugIcon(): JSX.Element {\n return (\n <svg\n width=\"16\"\n height=\"16\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n aria-hidden=\"true\"\n >\n <path d=\"M12 22v-5\" />\n <path d=\"M9 8V2\" />\n <path d=\"M15 8V2\" />\n <path d=\"M18 8v5a4 4 0 0 1-4 4h-4a4 4 0 0 1-4-4V8Z\" />\n </svg>\n );\n}\n\nfunction SearchIcon(): JSX.Element {\n return (\n <svg\n width=\"14\"\n height=\"14\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n aria-hidden=\"true\"\n >\n <circle cx=\"11\" cy=\"11\" r=\"7\" />\n <path d=\"m20 20-3.5-3.5\" />\n </svg>\n );\n}\n\n/** A random value tying an OAuth round trip to the window that started it. */\nfunction newNonce(): string {\n const c = typeof crypto !== \"undefined\" ? crypto : undefined;\n if (c?.randomUUID) return c.randomUUID();\n return `${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;\n}\n\n/** How the card describes an app at a glance. */\nfunction stateOf(integration: Integration): {\n key: \"connected\" | \"reconnect\" | \"disconnected\";\n label: string;\n} {\n if (integration.connected) return { key: \"connected\", label: \"Connected\" };\n if (integration.accounts.some((a) => a.needsReconnect)) {\n return { key: \"reconnect\", label: \"Needs reconnection\" };\n }\n return { key: \"disconnected\", label: \"Not connected\" };\n}\n\nfunction accountLabel(account: IntegrationAccount): string {\n if (!account.connectedAt) return account.status.toLowerCase();\n const when = new Date(account.connectedAt);\n if (Number.isNaN(when.getTime())) return account.status.toLowerCase();\n return `connected ${when.toLocaleDateString()}`;\n}\n\nfunction matches(integration: Integration, query: string): boolean {\n const q = query.trim().toLowerCase();\n if (!q) return true;\n return (\n integration.name.toLowerCase().includes(q) ||\n integration.app.toLowerCase().includes(q) ||\n (integration.description ?? \"\").toLowerCase().includes(q)\n );\n}\n\n/**\n * Modal where the END USER of an application manages their *own* third-party\n * accounts: the apps the developer offered to tenants of this assistant, each\n * with the accounts this tenant has connected, and the buttons to add or\n * remove one.\n *\n * Backed by `/api/v1/tenant-integrations`, which resolves the tenant\n * server-side, so what is listed here is only ever this tenant's — never the\n * workspace-wide accounts an admin connected, and never another tenant's.\n *\n * Connecting opens the provider's consent screen in a popup. The popup is\n * opened empty *before* the request that produces its URL, because browsers\n * only honour `window.open` inside the gesture that triggered it: opening it\n * after the round trip is what gets it blocked. When it is blocked anyway, the\n * URL is offered as a link instead.\n */\nexport function IntegrationsModal({\n isOpen,\n onClose,\n assistantId,\n tenantId,\n subtenantId,\n apiKey,\n baseUrl,\n title = \"Connected apps\",\n searchPlaceholder = \"Search connected apps\",\n onChange,\n theme,\n state,\n}: IntegrationsModalProps): JSX.Element | null {\n // Hooks cannot be skipped, so the fallback is always built and only fetches\n // when nobody handed a listing down.\n const own = useIntegrations({\n assistantId,\n tenantId,\n subtenantId,\n apiKey,\n baseUrl,\n enabled: isOpen && !state,\n });\n const { integrations, loading, error: loadError, refresh, client, scope } =\n state ?? own;\n\n /** Errors from connecting or disconnecting, kept apart from load failures. */\n const [actionError, setActionError] = useState<string | null>(null);\n const error = actionError ?? loadError;\n /** App slug with a connect/disconnect in flight, so only its card is busy. */\n const [busyApp, setBusyApp] = useState<string | null>(null);\n /** Authorization URL surfaced as a link when the popup was blocked. */\n const [blockedUrl, setBlockedUrl] = useState<{ app: string; url: string } | null>(\n null\n );\n const [query, setQuery] = useState(\"\");\n\n const visible = useMemo(\n () => integrations.filter((i) => matches(i, query)),\n [integrations, query]\n );\n\n // Report the listing without making the caller's identity part of the\n // dependency: an inline arrow would fire this on every render.\n const onChangeRef = useRef(onChange);\n onChangeRef.current = onChange;\n useEffect(() => {\n if (integrations.length) onChangeRef.current?.(integrations);\n }, [integrations]);\n\n // Reopening starts clean, and re-reads: accounts may have been connected or\n // revoked elsewhere since the last look.\n const wasOpenRef = useRef(false);\n const openedBeforeRef = useRef(false);\n useEffect(() => {\n if (isOpen && !wasOpenRef.current) {\n setBlockedUrl(null);\n setActionError(null);\n setQuery(\"\");\n // The very first open of an uncontrolled modal is already covered by the\n // hook switching on; asking again here would double every first open.\n if (state || openedBeforeRef.current) void refresh();\n openedBeforeRef.current = true;\n }\n wasOpenRef.current = isOpen;\n // `state.refresh` is stable per scope; re-running on every render of the\n // owner is exactly what this must not do.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [isOpen]);\n\n // Escape closes\n useEffect(() => {\n if (!isOpen) return;\n const onKey = (e: KeyboardEvent) => {\n if (e.key === \"Escape\") onClose();\n };\n document.addEventListener(\"keydown\", onKey);\n return () => document.removeEventListener(\"keydown\", onKey);\n }, [isOpen, onClose]);\n\n /** The round trip currently in flight, if any. */\n const pendingRef = useRef<{ app: string; returnTo: string } | null>(null);\n const popupRef = useRef<Window | null>(null);\n const pollRef = useRef<number | null>(null);\n\n const finishConnect = useCallback(() => {\n if (pollRef.current !== null) {\n window.clearInterval(pollRef.current);\n pollRef.current = null;\n }\n pendingRef.current = null;\n popupRef.current = null;\n setBusyApp(null);\n void refresh(true);\n }, [refresh]);\n\n // The callback page tells us it is done. Treat the message as a nudge, never\n // as the result: what is displayed comes from re-reading the server, so a\n // forged message can at worst cause one redundant fetch.\n useEffect(() => {\n if (!isOpen) return;\n const onMessage = (event: MessageEvent) => {\n const data = event.data as CallbackMessage | undefined;\n if (!data || data.source !== \"devic\") return;\n if (data.type !== \"integration-connected\") return;\n const pending = pendingRef.current;\n if (!pending || data.returnTo !== pending.returnTo) return;\n popupRef.current?.close();\n finishConnect();\n };\n window.addEventListener(\"message\", onMessage);\n return () => window.removeEventListener(\"message\", onMessage);\n }, [isOpen, finishConnect]);\n\n // Stop polling if the modal goes away mid-flow.\n useEffect(\n () => () => {\n if (pollRef.current !== null) window.clearInterval(pollRef.current);\n },\n []\n );\n\n const handleConnect = async (integration: Integration) => {\n if (!client || busyApp) return;\n setActionError(null);\n setBlockedUrl(null);\n setBusyApp(integration.app);\n\n const nonce = newNonce();\n const returnTo = `${window.location.origin}/?devic_oauth=${nonce}`;\n // Opened empty inside the click, navigated once the URL is known.\n const popup = window.open(\n \"\",\n \"devic-oauth\",\n \"width=520,height=680,menubar=no,toolbar=no\"\n );\n\n try {\n const { authorizationUrl } = await client.connectIntegration(\n integration.app,\n { ...scope, returnTo }\n );\n pendingRef.current = { app: integration.app, returnTo };\n if (popup && !popup.closed) {\n popupRef.current = popup;\n popup.location.href = authorizationUrl;\n // The user may close the popup without the callback ever posting back\n // — a cancelled consent screen, or a provider that lands somewhere\n // else. Watching for the close is what keeps the card from staying\n // busy forever.\n pollRef.current = window.setInterval(() => {\n if (popup.closed) finishConnect();\n }, 700);\n } else {\n // Blocked (Safari, in-app browsers, extensions): hand over the URL.\n setBlockedUrl({ app: integration.app, url: authorizationUrl });\n setBusyApp(null);\n }\n } catch (err) {\n popup?.close();\n pendingRef.current = null;\n setActionError(err instanceof Error ? err.message : String(err));\n setBusyApp(null);\n }\n };\n\n const handleDisconnect = async (app: string, account: IntegrationAccount) => {\n if (!client || busyApp) return;\n setBusyApp(app);\n setActionError(null);\n try {\n await client.disconnectIntegration(account.id, scope);\n await refresh(true);\n } catch (err) {\n setActionError(err instanceof Error ? err.message : String(err));\n } finally {\n setBusyApp(null);\n }\n };\n\n if (!isOpen) return null;\n\n return createPortal(\n // The variables go on the overlay, not on the modal: the backdrop is part\n // of the dialog, and a portal inherits nothing from the drawer that opened\n // it.\n <div\n className=\"devic-int-overlay\"\n style={themeVars(theme)}\n data-dark={isDarkTheme(theme)}\n onClick={onClose}\n >\n <div\n className=\"devic-int-modal\"\n role=\"dialog\"\n aria-modal=\"true\"\n aria-label={title}\n onClick={(e) => e.stopPropagation()}\n >\n <div className=\"devic-int-header\">\n <h3 className=\"devic-int-title\">\n <PlugIcon />\n {title}\n </h3>\n <button\n className=\"devic-int-close\"\n onClick={onClose}\n type=\"button\"\n aria-label=\"Close\"\n >\n ×\n </button>\n </div>\n\n <div className=\"devic-int-search\">\n <SearchIcon />\n <input\n type=\"search\"\n value={query}\n onChange={(e) => setQuery(e.target.value)}\n placeholder={searchPlaceholder}\n aria-label={searchPlaceholder}\n autoComplete=\"off\"\n />\n </div>\n\n <div className=\"devic-int-body\">\n {error && <div className=\"devic-int-error\">{error}</div>}\n\n {blockedUrl && (\n <div className=\"devic-int-notice\">\n Your browser blocked the pop-up.{\" \"}\n <a\n href={blockedUrl.url}\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n onClick={() => {\n pendingRef.current = null;\n setBlockedUrl(null);\n }}\n >\n Open the authorisation page\n </a>{\" \"}\n and come back — then use Refresh.\n </div>\n )}\n\n {loading && integrations.length === 0 ? (\n <div className=\"devic-int-loading\">Loading apps…</div>\n ) : integrations.length === 0 ? (\n <div className=\"devic-int-empty\">No apps available here yet.</div>\n ) : visible.length === 0 ? (\n <div className=\"devic-int-empty\">\n No apps match “{query.trim()}”.\n </div>\n ) : (\n <div className=\"devic-int-grid\">\n {visible.map((integration) => {\n const cardState = stateOf(integration);\n const busy = busyApp === integration.app;\n return (\n <div\n key={integration.app}\n className=\"devic-int-card\"\n data-state={cardState.key}\n >\n <div className=\"devic-int-card-head\">\n <IntegrationLogo integration={integration} />\n <span className=\"devic-int-state\">\n <span\n className=\"devic-int-dot\"\n data-ok={cardState.key === \"connected\"}\n data-off={cardState.key === \"disconnected\"}\n aria-hidden=\"true\"\n />\n {cardState.label}\n </span>\n </div>\n\n <div className=\"devic-int-name\" title={integration.name}>\n {integration.name}\n </div>\n\n {integration.description && (\n <div\n className=\"devic-int-description\"\n title={integration.description}\n >\n {integration.description}\n </div>\n )}\n\n <button\n type=\"button\"\n className={`devic-int-btn devic-int-btn-block${\n cardState.key === \"connected\"\n ? \"\"\n : \" devic-int-btn-primary\"\n }`}\n onClick={() => handleConnect(integration)}\n disabled={busy || !!busyApp}\n >\n {busy\n ? \"Waiting…\"\n : cardState.key === \"disconnected\"\n ? \"Connect\"\n : cardState.key === \"reconnect\"\n ? \"Reconnect\"\n : \"Add account\"}\n </button>\n\n {integration.accounts.length > 0 && (\n <ul className=\"devic-int-accounts\">\n {integration.accounts.map((account) => (\n <li key={account.id} className=\"devic-int-account\">\n <span\n className=\"devic-int-dot\"\n data-ok={!account.needsReconnect}\n aria-hidden=\"true\"\n />\n <span className=\"devic-int-account-label\">\n {accountLabel(account)}\n {account.needsReconnect && (\n <span className=\"devic-int-account-warn\">\n {\" \"}\n · reconnect required\n </span>\n )}\n </span>\n <button\n type=\"button\"\n className=\"devic-int-unlink\"\n onClick={() =>\n handleDisconnect(integration.app, account)\n }\n disabled={!!busyApp}\n title=\"Disconnect this account\"\n aria-label={`Disconnect ${integration.name}`}\n >\n ×\n </button>\n </li>\n ))}\n </ul>\n )}\n </div>\n );\n })}\n </div>\n )}\n </div>\n\n <div className=\"devic-int-footer\">\n <span>Only you can see and use the accounts you connect here.</span>\n <button\n type=\"button\"\n className=\"devic-int-btn devic-int-btn-small\"\n onClick={() => void refresh(true)}\n disabled={loading || !!busyApp}\n >\n Refresh\n </button>\n </div>\n </div>\n </div>,\n document.body\n );\n}\n\nexport default IntegrationsModal;\n"],"names":["_jsxs","_jsx"],"mappings":";;;;;;;AA0DA,SAAS,QAAQ,GAAA;AACf,IAAA,QACEA,IAAA,CAAA,KAAA,EAAA,EACE,KAAK,EAAC,IAAI,EACV,MAAM,EAAC,IAAI,EACX,OAAO,EAAC,WAAW,EACnB,IAAI,EAAC,MAAM,EACX,MAAM,EAAC,cAAc,EACrB,WAAW,EAAC,GAAG,EACf,aAAa,EAAC,OAAO,EACrB,cAAc,EAAC,OAAO,EAAA,aAAA,EACV,MAAM,EAAA,QAAA,EAAA,CAElBC,GAAA,CAAA,MAAA,EAAA,EAAM,CAAC,EAAC,WAAW,EAAA,CAAG,EACtBA,GAAA,CAAA,MAAA,EAAA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EACnB,KAAK,EAAC,yBAAyB,EAAA,YAAA,EACnB,CAAA,WAAA,EAAc,WAAW,CAAC,IAAI,CAAA,CAAE,EAAA,QAAA,EAAA,QAAA,EAAA,CAGrC,CAAA,EAAA,EA1BF,OAAO,CAAC,EAAE,CA2Bd,CACN,CAAC,EAAA,CACC,CACN,CAAA,EAAA,EAlFI,WAAW,CAAC,GAAG,CAmFhB;4BAEV,CAAC,CAAC,GACE,CACP,CAAA,EAAA,CACG,EAEND,IAAA,CAAA,KAAA,EAAA,EAAK,SAAS,EAAC,kBAAkB,EAAA,QAAA,EAAA,CAC/BC,GAAA,CAAA,MAAA,EAAA,EAAA,QAAA,EAAA,yDAAA,EAAA,CAAoE,EACpEA,GAAA,CAAA,QAAA,EAAA,EACE,IAAI,EAAC,QAAQ,EACb,SAAS,EAAC,mCAAmC,EAC7C,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,EACjC,QAAQ,EAAE,OAAO,IAAI,CAAC,CAAC,OAAO,EAAA,QAAA,EAAA,SAAA,EAAA,CAGvB,IACL,CAAA,EAAA,CACF,EAAA,CACF,EACN,QAAQ,CAAC,IAAI,CACd;AACH;;;;"}
@@ -1,2 +1,8 @@
1
1
  export { IntegrationsModal, default } from "./IntegrationsModal";
2
2
  export type { IntegrationsModalProps } from "./IntegrationsModal";
3
+ export { IntegrationsLauncher, DEFAULT_MAX_LOGOS } from "./IntegrationsLauncher";
4
+ export type { IntegrationsLauncherProps } from "./IntegrationsLauncher";
5
+ export { IntegrationLogo } from "./IntegrationLogo";
6
+ export type { IntegrationLogoProps } from "./IntegrationLogo";
7
+ export { useIntegrations } from "./useIntegrations";
8
+ export type { IntegrationsState, IntegrationsScope, UseIntegrationsOptions, } from "./useIntegrations";
@@ -0,0 +1,49 @@
1
+ import { DevicApiClient } from "../../api/client";
2
+ import type { Integration } from "../../api/types";
3
+ /** What identifies the end user in front of the widget. */
4
+ export interface IntegrationsScope {
5
+ assistantId: string;
6
+ tenantId?: string;
7
+ subtenantId?: string;
8
+ }
9
+ export interface UseIntegrationsOptions extends IntegrationsScope {
10
+ /** API key override (falls back to the provider's). */
11
+ apiKey?: string;
12
+ /** Base URL override (falls back to the provider's). */
13
+ baseUrl?: string;
14
+ /**
15
+ * Fetch when this turns true, and only then. The launcher passes the drawer's
16
+ * open state so a widget nobody opens costs no request at all.
17
+ */
18
+ enabled?: boolean;
19
+ }
20
+ export interface IntegrationsState {
21
+ integrations: Integration[];
22
+ loading: boolean;
23
+ error: string | null;
24
+ /**
25
+ * Whether this assistant offers connected apps to its tenants at all.
26
+ *
27
+ * False before the first answer arrives, and false again if the server said
28
+ * no — which it does for a disabled catalogue, a missing tenant, and an
29
+ * assistant that does not exist, deliberately without distinguishing them.
30
+ * Anything that hangs off this flag stays hidden until the server has said
31
+ * yes, so nothing ever appears and then disappears.
32
+ */
33
+ offered: boolean;
34
+ /** True once a first answer (or refusal) has arrived. */
35
+ settled: boolean;
36
+ refresh: (dropCache?: boolean) => Promise<void>;
37
+ client: DevicApiClient | null;
38
+ scope: IntegrationsScope;
39
+ }
40
+ /**
41
+ * The apps an assistant offers to its tenants, with the accounts THIS tenant
42
+ * has connected — loaded once and shared.
43
+ *
44
+ * Both the header button and the modal need the same listing: the button to
45
+ * know whether it should exist and which logos to show, the modal to fill
46
+ * itself. Fetching it in each of them would double every round trip and let the
47
+ * two disagree for a moment after connecting an account.
48
+ */
49
+ export declare function useIntegrations(options: UseIntegrationsOptions): IntegrationsState;
@@ -0,0 +1,104 @@
1
+ import { useMemo, useState, useCallback, useRef, useEffect } from 'react';
2
+ import { DevicApiClient } from '../../api/client.js';
3
+ import 'react/jsx-runtime';
4
+ import { useOptionalDevicContext } from '../../provider/DevicContext.js';
5
+
6
+ /** A 4xx here means "not for you", not "something broke". */
7
+ function isRefusal(err) {
8
+ const status = err?.statusCode;
9
+ return typeof status === "number" && status >= 400 && status < 500;
10
+ }
11
+ /**
12
+ * The apps an assistant offers to its tenants, with the accounts THIS tenant
13
+ * has connected — loaded once and shared.
14
+ *
15
+ * Both the header button and the modal need the same listing: the button to
16
+ * know whether it should exist and which logos to show, the modal to fill
17
+ * itself. Fetching it in each of them would double every round trip and let the
18
+ * two disagree for a moment after connecting an account.
19
+ */
20
+ function useIntegrations(options) {
21
+ const { assistantId, tenantId, subtenantId, apiKey, baseUrl, enabled = true, } = options;
22
+ const context = useOptionalDevicContext();
23
+ const resolvedApiKey = apiKey || context?.apiKey;
24
+ const resolvedBaseUrl = baseUrl || context?.baseUrl || "https://api.devic.ai";
25
+ const resolvedTenantId = tenantId || context?.tenantId;
26
+ const resolvedSubtenantId = subtenantId || context?.subtenantId;
27
+ const client = useMemo(() => resolvedApiKey
28
+ ? new DevicApiClient({ apiKey: resolvedApiKey, baseUrl: resolvedBaseUrl })
29
+ : null, [resolvedApiKey, resolvedBaseUrl]);
30
+ const scope = useMemo(() => ({
31
+ assistantId,
32
+ tenantId: resolvedTenantId || undefined,
33
+ subtenantId: resolvedSubtenantId || undefined,
34
+ }), [assistantId, resolvedTenantId, resolvedSubtenantId]);
35
+ const [integrations, setIntegrations] = useState([]);
36
+ const [loading, setLoading] = useState(false);
37
+ const [error, setError] = useState(null);
38
+ const [offered, setOffered] = useState(false);
39
+ const [settled, setSettled] = useState(false);
40
+ const refresh = useCallback(async (dropCache = false) => {
41
+ if (!client) {
42
+ setError("API key not configured");
43
+ setSettled(true);
44
+ return;
45
+ }
46
+ setLoading(true);
47
+ setError(null);
48
+ try {
49
+ // The server caches a scope's connections briefly; after an OAuth round
50
+ // trip that cache is exactly one step behind, so drop it first.
51
+ if (dropCache) {
52
+ await client.refreshIntegrations(scope).catch(() => undefined);
53
+ }
54
+ const list = await client.getIntegrations(scope);
55
+ setIntegrations(list);
56
+ setOffered(list.length > 0);
57
+ }
58
+ catch (err) {
59
+ setIntegrations([]);
60
+ setOffered(false);
61
+ setError(err instanceof Error ? err.message : String(err));
62
+ if (!isRefusal(err)) {
63
+ // A refusal is an ordinary answer and stays quiet. A 500 or a dead
64
+ // network is not, and swallowing it entirely would leave an
65
+ // integrator with a button that never appears and no reason why.
66
+ console.warn("[devic-ui] could not load connected apps", err);
67
+ }
68
+ }
69
+ finally {
70
+ setLoading(false);
71
+ setSettled(true);
72
+ }
73
+ }, [client, scope]);
74
+ // Once per scope, not once per render of whatever switched it on. A new
75
+ // assistant or tenant is a different listing altogether, so it loads again —
76
+ // and the previous tenant's apps are dropped first, because showing them
77
+ // while the new ones arrive would name accounts that are not this user's.
78
+ const key = `${client ? "k" : "-"}|${scope.assistantId}|${scope.tenantId ?? ""}|${scope.subtenantId ?? ""}`;
79
+ const loadedKeyRef = useRef(null);
80
+ useEffect(() => {
81
+ if (!enabled || loadedKeyRef.current === key)
82
+ return;
83
+ if (loadedKeyRef.current !== null) {
84
+ setIntegrations([]);
85
+ setOffered(false);
86
+ setSettled(false);
87
+ }
88
+ loadedKeyRef.current = key;
89
+ void refresh();
90
+ }, [enabled, key, refresh]);
91
+ return {
92
+ integrations,
93
+ loading,
94
+ error,
95
+ offered,
96
+ settled,
97
+ refresh,
98
+ client,
99
+ scope,
100
+ };
101
+ }
102
+
103
+ export { useIntegrations };
104
+ //# sourceMappingURL=useIntegrations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useIntegrations.js","sources":["../../../../src/components/IntegrationsModal/useIntegrations.ts"],"sourcesContent":["import { useCallback, useEffect, useMemo, useRef, useState } from \"react\";\nimport { DevicApiClient } from \"../../api/client\";\nimport type { DevicApiError } from \"../../api/client\";\nimport type { Integration } from \"../../api/types\";\nimport { useOptionalDevicContext } from \"../../provider\";\n\n/** What identifies the end user in front of the widget. */\nexport interface IntegrationsScope {\n assistantId: string;\n tenantId?: string;\n subtenantId?: string;\n}\n\nexport interface UseIntegrationsOptions extends IntegrationsScope {\n /** API key override (falls back to the provider's). */\n apiKey?: string;\n /** Base URL override (falls back to the provider's). */\n baseUrl?: string;\n /**\n * Fetch when this turns true, and only then. The launcher passes the drawer's\n * open state so a widget nobody opens costs no request at all.\n */\n enabled?: boolean;\n}\n\nexport interface IntegrationsState {\n integrations: Integration[];\n loading: boolean;\n error: string | null;\n /**\n * Whether this assistant offers connected apps to its tenants at all.\n *\n * False before the first answer arrives, and false again if the server said\n * no — which it does for a disabled catalogue, a missing tenant, and an\n * assistant that does not exist, deliberately without distinguishing them.\n * Anything that hangs off this flag stays hidden until the server has said\n * yes, so nothing ever appears and then disappears.\n */\n offered: boolean;\n /** True once a first answer (or refusal) has arrived. */\n settled: boolean;\n refresh: (dropCache?: boolean) => Promise<void>;\n client: DevicApiClient | null;\n scope: IntegrationsScope;\n}\n\n/** A 4xx here means \"not for you\", not \"something broke\". */\nfunction isRefusal(err: unknown): boolean {\n const status = (err as DevicApiError)?.statusCode;\n return typeof status === \"number\" && status >= 400 && status < 500;\n}\n\n/**\n * The apps an assistant offers to its tenants, with the accounts THIS tenant\n * has connected — loaded once and shared.\n *\n * Both the header button and the modal need the same listing: the button to\n * know whether it should exist and which logos to show, the modal to fill\n * itself. Fetching it in each of them would double every round trip and let the\n * two disagree for a moment after connecting an account.\n */\nexport function useIntegrations(\n options: UseIntegrationsOptions\n): IntegrationsState {\n const {\n assistantId,\n tenantId,\n subtenantId,\n apiKey,\n baseUrl,\n enabled = true,\n } = options;\n\n const context = useOptionalDevicContext();\n const resolvedApiKey = apiKey || context?.apiKey;\n const resolvedBaseUrl = baseUrl || context?.baseUrl || \"https://api.devic.ai\";\n const resolvedTenantId = tenantId || context?.tenantId;\n const resolvedSubtenantId = subtenantId || context?.subtenantId;\n\n const client = useMemo(\n () =>\n resolvedApiKey\n ? new DevicApiClient({ apiKey: resolvedApiKey, baseUrl: resolvedBaseUrl })\n : null,\n [resolvedApiKey, resolvedBaseUrl]\n );\n\n const scope = useMemo(\n () => ({\n assistantId,\n tenantId: resolvedTenantId || undefined,\n subtenantId: resolvedSubtenantId || undefined,\n }),\n [assistantId, resolvedTenantId, resolvedSubtenantId]\n );\n\n const [integrations, setIntegrations] = useState<Integration[]>([]);\n const [loading, setLoading] = useState(false);\n const [error, setError] = useState<string | null>(null);\n const [offered, setOffered] = useState(false);\n const [settled, setSettled] = useState(false);\n\n const refresh = useCallback(\n async (dropCache = false) => {\n if (!client) {\n setError(\"API key not configured\");\n setSettled(true);\n return;\n }\n setLoading(true);\n setError(null);\n try {\n // The server caches a scope's connections briefly; after an OAuth round\n // trip that cache is exactly one step behind, so drop it first.\n if (dropCache) {\n await client.refreshIntegrations(scope).catch(() => undefined);\n }\n const list = await client.getIntegrations(scope);\n setIntegrations(list);\n setOffered(list.length > 0);\n } catch (err) {\n setIntegrations([]);\n setOffered(false);\n setError(err instanceof Error ? err.message : String(err));\n if (!isRefusal(err)) {\n // A refusal is an ordinary answer and stays quiet. A 500 or a dead\n // network is not, and swallowing it entirely would leave an\n // integrator with a button that never appears and no reason why.\n console.warn(\"[devic-ui] could not load connected apps\", err);\n }\n } finally {\n setLoading(false);\n setSettled(true);\n }\n },\n [client, scope]\n );\n\n // Once per scope, not once per render of whatever switched it on. A new\n // assistant or tenant is a different listing altogether, so it loads again —\n // and the previous tenant's apps are dropped first, because showing them\n // while the new ones arrive would name accounts that are not this user's.\n const key = `${client ? \"k\" : \"-\"}|${scope.assistantId}|${scope.tenantId ?? \"\"}|${scope.subtenantId ?? \"\"}`;\n const loadedKeyRef = useRef<string | null>(null);\n useEffect(() => {\n if (!enabled || loadedKeyRef.current === key) return;\n if (loadedKeyRef.current !== null) {\n setIntegrations([]);\n setOffered(false);\n setSettled(false);\n }\n loadedKeyRef.current = key;\n void refresh();\n }, [enabled, key, refresh]);\n\n return {\n integrations,\n loading,\n error,\n offered,\n settled,\n refresh,\n client,\n scope,\n };\n}\n"],"names":[],"mappings":";;;;;AA8CA;AACA,SAAS,SAAS,CAAC,GAAY,EAAA;AAC7B,IAAA,MAAM,MAAM,GAAI,GAAqB,EAAE,UAAU;AACjD,IAAA,OAAO,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,IAAI,GAAG,IAAI,MAAM,GAAG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AAA,MAAM,YAAY,GAAG,MAAM,CAAgB,IAAI,CAAC;IAChD,SAAS,CAAC,MAAK;AACb,QAAA,IAAI,CAAC,OAAO,IAAI,YAAY,CAAC,OAAO,KAAK,GAAG;YAAE;AAC9C,QAAA,IAAI,YAAY,CAAC,OAAO,KAAK,IAAI,EAAE;YACjC,eAAe,CAAC,EAAE,CAAC;YACnB,UAAU,CAAC,KAAK,CAAC;YACjB,UAAU,CAAC,KAAK,CAAC;QACnB;AACA,QAAA,YAAY,CAAC,OAAO,GAAG,GAAG;QAC1B,KAAK,OAAO,EAAE;IAChB,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC;IAE3B,OAAO;QACL,YAAY;QACZ,OAAO;QACP,KAAK;QACL,OAAO;QACP,OAAO;QACP,OAAO;QACP,MAAM;QACN,KAAK;KACN;AACH;;;;"}
@@ -31,3 +31,12 @@ export interface DevicTheme {
31
31
  * to the stylesheet default rather than be pinned to `undefined`.
32
32
  */
33
33
  export declare function themeVars(theme?: DevicTheme): CSSProperties;
34
+ /**
35
+ * Whether this theme paints on a dark surface.
36
+ *
37
+ * Used for the one thing CSS variables cannot express: third-party app logos.
38
+ * Many are solid black with a transparent background, and on a dark chip they
39
+ * turn into a smudge — so on a dark theme the chip behind them goes light.
40
+ * Unknown or unreadable colours count as light, which is the default anyway.
41
+ */
42
+ export declare function isDarkTheme(theme?: DevicTheme): boolean;