@startsimpli/integrations 0.2.208 → 0.2.210

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@startsimpli/integrations",
3
- "version": "0.2.208",
3
+ "version": "0.2.210",
4
4
  "description": "Provider-agnostic types, API clients, hooks, and UI primitives for email + calendar integrations across StartSimpli apps, plus foundry customer email (subpath ./comms).",
5
5
  "license": "MIT",
6
6
  "homepage": "https://startsimpli.com",
@@ -52,7 +52,7 @@
52
52
  "react-native-safe-area-context": ">=4.0.0",
53
53
  "@startsimpli/auth": "^0.4.58",
54
54
  "@startsimpli/utils": "^0.4.21",
55
- "@startsimpli/ui": "^0.4.199"
55
+ "@startsimpli/ui": "^0.4.201"
56
56
  },
57
57
  "peerDependenciesMeta": {
58
58
  "react": {
@@ -99,7 +99,7 @@
99
99
  "react-native": "0.85.3",
100
100
  "react-native-safe-area-context": "~5.7.0",
101
101
  "@startsimpli/llm": "0.4.31",
102
- "@startsimpli/ui": "0.4.199",
102
+ "@startsimpli/ui": "0.4.201",
103
103
  "@startsimpli/ui-native": "0.1.15",
104
104
  "@startsimpli/auth": "0.4.58",
105
105
  "@startsimpli/utils": "0.4.21"
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Sources sync on the Connections page: ONE table (source, status, records, last sync, next sync, one action),
3
+ * folded into the existing connected-accounts list. The action opens that connection's own card, so every
4
+ * maintenance control is still one click away and none is shown twice (bd startsim-c93vd).
5
+ */
6
+ import { describe, expect, it, vi } from 'vitest';
7
+ import { render, screen, within } from '@testing-library/react';
8
+ import userEvent from '@testing-library/user-event';
9
+
10
+ import { ConnectionsPage } from '../components/pages/ConnectionsPage';
11
+ import type { ConnectionsApi } from '../components/pages/types';
12
+
13
+ const minutes = (n: number) => new Date(Date.now() + n * 60_000).toISOString();
14
+
15
+ function connection(id: string, name: string, extra: Record<string, unknown> = {}) {
16
+ return {
17
+ id, public_id: `pub-${id}`, name, connector_key: name.toLowerCase(), connector_name: name, external_account_id: '',
18
+ account_label: '', capabilities_enabled: [], config: {}, status: 'connected', health: 'ok', auth_mode: 'oauth', ...extra,
19
+ };
20
+ }
21
+
22
+ function api(results: unknown[]): ConnectionsApi {
23
+ return {
24
+ connectorCatalog: vi.fn().mockResolvedValue({ results: [] }),
25
+ connections: vi.fn().mockResolvedValue({ results, permissions: { view: true, manage: true, issue_tokens: false } }),
26
+ checkConnection: vi.fn().mockResolvedValue({ ok: true, account_label: '', detail: 'ok' }),
27
+ disconnect: vi.fn().mockResolvedValue(undefined),
28
+ connectionRuns: vi.fn().mockResolvedValue({ results: [] }),
29
+ } as unknown as ConnectionsApi;
30
+ }
31
+
32
+ const GOOGLE = connection('g1', 'Google', {
33
+ sync: { state: 'limited', note: 'The provider is limiting requests; it resumes on its own', records: 72,
34
+ last_attempt_at: minutes(-3), last_success_at: minutes(-3), next_sync_at: minutes(9), interval_minutes: 10, window_days: 14 },
35
+ });
36
+ const MICROSOFT = connection('m1', 'Microsoft', {
37
+ status: 'needs_reauth',
38
+ sync: { state: 'reauth', note: 'Reconnect this account to resume syncing', records: 0, last_attempt_at: null,
39
+ last_success_at: null, next_sync_at: null, interval_minutes: null, window_days: 14 },
40
+ });
41
+
42
+ describe('ConnectionsPage — the sources sync table', () => {
43
+ it('lists each synced connection as a row: status, records with its window, last and next sync', async () => {
44
+ render(<ConnectionsPage mode="personal" api={api([GOOGLE, MICROSOFT])} />);
45
+ const table = await screen.findByRole('region', { name: 'Source freshness' });
46
+ const google = within(table).getByText('Google').closest('tr')!;
47
+ expect(within(google).getByText('Slowed by the provider')).toBeInTheDocument();
48
+ expect(within(google).getByText('72')).toBeInTheDocument();
49
+ expect(within(google).getByText('last 14 days')).toBeInTheDocument();
50
+ expect(within(google).getByText(/In 9 min/)).toBeInTheDocument();
51
+ const microsoft = within(table).getByText('Microsoft').closest('tr')!;
52
+ expect(within(microsoft).getByText('Reconnect needed')).toBeInTheDocument();
53
+ expect(within(microsoft).getByRole('button', { name: 'Reconnect' })).toBeInTheDocument();
54
+ });
55
+
56
+ it('shows no card until the one action is used, then opens that connection\'s own controls', async () => {
57
+ const user = userEvent.setup();
58
+ render(<ConnectionsPage mode="personal" api={api([GOOGLE, MICROSOFT])} />);
59
+ const table = await screen.findByRole('region', { name: 'Source freshness' });
60
+ expect(screen.queryByRole('button', { name: /disconnect/i })).toBeNull();
61
+ await user.click(within(within(table).getByText('Google').closest('tr')!).getByRole('button', { name: 'Manage' }));
62
+ expect(await screen.findByRole('button', { name: /disconnect/i })).toBeInTheDocument();
63
+ });
64
+
65
+ it('keeps the card list for a connection whose server sends no sync block', async () => {
66
+ render(<ConnectionsPage mode="personal" api={api([connection('c1', 'Granola')])} />);
67
+ expect((await screen.findAllByRole('button', { name: /disconnect|test/i })).length).toBeGreaterThan(0);
68
+ expect(screen.queryByRole('region', { name: 'Source freshness' })).toBeNull();
69
+ });
70
+ });
@@ -43,6 +43,9 @@ import { bindApi } from './connections/bound-api';
43
43
  import { DEFAULTS, readFailureMessage } from './connections/copy';
44
44
  import { CatalogCard } from './connections/CatalogCard';
45
45
  import { ConnectionCard } from './connections/ConnectionCard';
46
+ import { SourcesTable } from './library/SourcesTable';
47
+ import { readSync } from '../../corpus/client';
48
+ import type { SourceFreshness } from '../../corpus/types';
46
49
  import type { ConnectionsPageProps } from './connections/bound-api';
47
50
  export type { ConnectionsPageProps } from './connections/bound-api';
48
51
 
@@ -68,6 +71,8 @@ export function ConnectionsPage(props: ConnectionsPageProps) {
68
71
  });
69
72
  const [loadError, setLoadError] = React.useState<string>('');
70
73
  const [loading, setLoading] = React.useState(true);
74
+ /** The synced connection whose own card is open (the table's one action). */
75
+ const [openId, setOpenId] = React.useState<string | null>(null);
71
76
 
72
77
  const reload = React.useCallback(async () => {
73
78
  setLoading(true);
@@ -92,6 +97,21 @@ export function ConnectionsPage(props: ConnectionsPageProps) {
92
97
 
93
98
  React.useEffect(() => { void reload(); }, [reload]);
94
99
 
100
+ const syncRows: SourceFreshness[] = connections.flatMap((connection) => {
101
+ const sync = readSync(connection as unknown as Record<string, unknown>);
102
+ if (!sync) return [];
103
+ return [{
104
+ source: connection.id,
105
+ label: connection.account_label && connection.account_label !== connection.connector_name
106
+ ? `${connection.connector_name} (${connection.account_label})` : connection.connector_name,
107
+ documentCount: sync.records,
108
+ lastSyncedAt: sync.lastSuccessAt,
109
+ lastAttemptAt: sync.lastAttemptAt,
110
+ status: connection.status === 'connected' ? 'ok' : 'error',
111
+ sync,
112
+ } as SourceFreshness];
113
+ });
114
+
95
115
  if (loadError) {
96
116
  return <LoadError what="your connections" message={loadError} onRetry={() => { setLoadError(''); void reload(); }} />;
97
117
  }
@@ -114,7 +134,15 @@ export function ConnectionsPage(props: ConnectionsPageProps) {
114
134
  : 'Nothing connected yet.'}
115
135
  </p>
116
136
  ) : null}
117
- {connections.map((connection) => (
137
+ {/* A connection whose server sends its sync row is one line of the table; its own card (test, replace
138
+ the key, disconnect, discovery) opens from the row's one action. One that does not keeps its card. */}
139
+ <SourcesTable
140
+ sources={syncRows}
141
+ now={Date.now()}
142
+ onManage={(id) => setOpenId((current) => (current === id ? null : id))}
143
+ classNames={cn}
144
+ />
145
+ {connections.filter((c) => !readSync(c as unknown as Record<string, unknown>) || c.id === openId).map((connection) => (
118
146
  <ConnectionCard
119
147
  key={connection.id}
120
148
  api={api}
@@ -85,7 +85,7 @@ export function SourcesTable({
85
85
  const td = 'px-3 py-2 text-sm text-gray-800 dark:text-gray-100';
86
86
  return (
87
87
  <section className={classNames.section} aria-label="Source freshness">
88
- <div className="overflow-x-auto rounded-lg border border-gray-200 dark:border-gray-700">
88
+ <div className="max-w-full overflow-x-auto rounded-lg border bg-white dark:bg-gray-900 border-gray-200 dark:border-gray-700">
89
89
  <table className="min-w-full divide-y divide-gray-200 dark:divide-gray-700">
90
90
  <thead>
91
91
  <tr>
@@ -94,7 +94,7 @@ export function SourcesTable({
94
94
  <th className={`${th} text-right`} scope="col">Records</th>
95
95
  <th className={th} scope="col">Last sync</th>
96
96
  <th className={th} scope="col">Next sync</th>
97
- <th className={th} scope="col"><span className="sr-only">Action</span></th>
97
+ <th className={`${th} sticky right-0 bg-white dark:bg-gray-900`} scope="col"><span className="sr-only">Action</span></th>
98
98
  </tr>
99
99
  </thead>
100
100
  <tbody className="divide-y divide-gray-100 dark:divide-gray-800">
@@ -103,16 +103,16 @@ export function SourcesTable({
103
103
  const attention = source.sync ? source.sync.state === 'failing' || source.sync.state === 'reauth' : source.status === 'error';
104
104
  return (
105
105
  <tr key={source.source}>
106
- <th scope="row" className={`${td} font-medium`}>{source.label}</th>
106
+ <th scope="row" className={`${td} text-left font-medium`}>{source.label}</th>
107
107
  <td className={attention ? `${td} font-medium text-amber-700 dark:text-amber-400` : td}>{statusText(source)}</td>
108
108
  <td className={`${td} text-right tabular-nums`}>{records === null ? '—' : records}
109
109
  {source.sync?.windowDays ? (
110
- <span className="block text-xs font-normal text-gray-500 dark:text-gray-400">last {source.sync.windowDays} days</span>
110
+ <span className="block whitespace-nowrap text-xs font-normal text-gray-500 dark:text-gray-400">last {source.sync.windowDays} days</span>
111
111
  ) : null}
112
112
  </td>
113
113
  <td className={td}>{lastSyncText(source, now)}</td>
114
114
  <td className={td}>{nextSyncText(source, now)}</td>
115
- <td className={`${td} text-right`}>
115
+ <td className={`${td} sticky right-0 bg-white text-right shadow-[-8px_0_8px_-8px_rgba(0,0,0,0.12)] dark:bg-gray-900`}>
116
116
  {onManage && source.sync?.state !== 'passive' ? (
117
117
  <button
118
118
  type="button"
@@ -154,6 +154,8 @@ export interface Connection {
154
154
  health: string;
155
155
  auth_mode: string;
156
156
  check_error?: string;
157
+ /** The server's own plain-language sync row (state, sentence, records, last attempt, next sync, window); absent on an older server. */
158
+ sync?: Record<string, unknown>;
157
159
  /** Why the newest sync run failed or only partly worked, scrubbed; '' when it was clean. */
158
160
  last_error?: string;
159
161
  last_checked_at?: string | null;
@@ -1055,7 +1055,7 @@ export function createCorpusApi(
1055
1055
  };
1056
1056
  }
1057
1057
 
1058
- function readSync(connection: Record<string, unknown>): SourceSync | undefined {
1058
+ export function readSync(connection: Record<string, unknown>): SourceSync | undefined {
1059
1059
  const raw = connection.sync as Record<string, unknown> | undefined;
1060
1060
  if (!raw || typeof raw !== 'object') return undefined;
1061
1061
  const pick = (snake: string, camel: string) => raw[snake] ?? raw[camel];