@startsimpli/integrations 0.2.100 → 0.2.101

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/package.json +5 -5
  2. package/src/native/app/FoundryApp.tsx +144 -0
  3. package/src/native/app/__tests__/FoundryApp.test.tsx +61 -0
  4. package/src/native/app/__tests__/ShellBanners.test.tsx +37 -0
  5. package/src/native/app/__tests__/banners-restore.test.ts +65 -0
  6. package/src/native/app/__tests__/launch.test.ts +31 -0
  7. package/src/native/app/__tests__/registry.test.tsx +102 -0
  8. package/src/native/app/banners.ts +46 -0
  9. package/src/native/app/config/__tests__/links.test.ts +43 -0
  10. package/src/native/app/config/__tests__/validate.test.ts +71 -0
  11. package/src/native/app/config/defaults.ts +51 -0
  12. package/src/native/app/config/index.ts +4 -0
  13. package/src/native/app/config/links.ts +75 -0
  14. package/src/native/app/config/types.ts +127 -0
  15. package/src/native/app/config/validate.ts +221 -0
  16. package/src/native/app/data.ts +48 -0
  17. package/src/native/app/device.ts +38 -0
  18. package/src/native/app/entity/EntityTab.tsx +90 -0
  19. package/src/native/app/entity/format.ts +35 -0
  20. package/src/native/app/icon.tsx +7 -0
  21. package/src/native/app/index.ts +11 -0
  22. package/src/native/app/launch.ts +42 -0
  23. package/src/native/app/registry.tsx +104 -0
  24. package/src/native/app/restore.ts +42 -0
  25. package/src/native/app/screens/DiagnosticsScreen.tsx +22 -0
  26. package/src/native/app/screens/RecordScreen.tsx +93 -0
  27. package/src/native/app/screens/ShellBanners.tsx +18 -0
  28. package/src/native/app/screens/SignInScreen.tsx +34 -0
  29. package/src/native/app/services.ts +150 -0
  30. package/src/native/app/strings.ts +74 -0
  31. package/src/native/components/FoundryTabsShell.tsx +4 -1
  32. package/src/native/home/tab.tsx +3 -8
  33. package/src/native/index.ts +2 -1
  34. package/src/native/recording/__tests__/authRefresh.test.ts +1 -1
  35. package/src/native/recording/__tests__/deeplink.test.ts +18 -3
  36. package/src/native/recording/__tests__/diagnostics.test.ts +2 -2
  37. package/src/native/recording/__tests__/session.test.ts +27 -1
  38. package/src/native/recording/deeplink.ts +25 -20
  39. package/src/native/recording/diagnostics.ts +3 -3
  40. package/src/native/recording/session.ts +20 -6
@@ -48,6 +48,8 @@ export interface FoundryTabsShellProps {
48
48
  maxVisible?: number;
49
49
  /** Label of the overflow tab. Default "More". */
50
50
  moreLabel?: string;
51
+ /** Shell-level strip (offline, waiting to send) shown above the tab bar on every tab. */
52
+ banner?: ReactNode;
51
53
  }
52
54
 
53
55
  /**
@@ -55,7 +57,7 @@ export interface FoundryTabsShellProps {
55
57
  * tab is mounted the first time it is shown and then kept mounted (hidden) so
56
58
  * its state - and a recording on the GO tab - survives switching away.
57
59
  */
58
- export function FoundryTabsShell({ tabs, initialTab, initialDetail, navigator, maxVisible = DEFAULT_MAX_VISIBLE, moreLabel = 'More' }: FoundryTabsShellProps) {
60
+ export function FoundryTabsShell({ tabs, initialTab, initialDetail, navigator, maxVisible = DEFAULT_MAX_VISIBLE, moreLabel = 'More', banner }: FoundryTabsShellProps) {
59
61
  const theme = useTheme();
60
62
  const insets = useSafeAreaInsets();
61
63
  const nav = useMemo(
@@ -119,6 +121,7 @@ export function FoundryTabsShell({ tabs, initialTab, initialDetail, navigator, m
119
121
  </View>
120
122
  );
121
123
  })}
124
+ {banner}
122
125
  <TabBar
123
126
  items={items}
124
127
  activeKey={inMore ? MORE_KEY : state.activeKey}
@@ -3,19 +3,14 @@ import type { NativeCorpusApi } from '../corpus/api';
3
3
  import { createHomeController, type HomeController, type HomeType } from './controller';
4
4
  import { HomeScreen } from './HomeScreen';
5
5
 
6
- export const DEFAULT_HOME_TYPES: HomeType[] = [
7
- { key: 'commitment', label: 'To-dos' },
8
- { key: 'source_document', label: 'Documents' },
9
- { key: 'focus', label: 'Projects' },
10
- ];
11
-
12
6
  export interface HomeTabOptions {
13
7
  api: Pick<NativeCorpusApi, 'entities'>;
14
8
  brand: string;
15
9
  tagline?: string;
16
10
  key?: string;
17
11
  label?: string;
18
- types?: HomeType[];
12
+ /** Which record types the Home counts (from the app config's `home.types`). */
13
+ types: HomeType[];
19
14
  controller?: HomeController;
20
15
  /** Tab keys by record type, e.g. `{ commitment: 'tracker', source_document: 'library' }`. A type with no tab is not tappable. */
21
16
  tabs?: Record<string, string>;
@@ -24,7 +19,7 @@ export interface HomeTabOptions {
24
19
  }
25
20
 
26
21
  /** The Home tab as one `FoundryTabsShell` entry. */
27
- export function homeTab({ api, brand, tagline, key = 'home', label = 'Home', types = DEFAULT_HOME_TYPES, controller = createHomeController({ api, types }), tabs = {}, recordKey }: HomeTabOptions): FoundryTab {
22
+ export function homeTab({ api, brand, tagline, key = 'home', label = 'Home', types, controller = createHomeController({ api, types }), tabs = {}, recordKey }: HomeTabOptions): FoundryTab {
28
23
  return {
29
24
  key, label,
30
25
  render: ({ openTab, active }) => (
@@ -15,6 +15,7 @@ export { NoteDetailScreen, type NoteDetailScreenProps } from './components/NoteD
15
15
  export { NotesShell, type NotesShellProps } from './components/NotesShell';
16
16
  export { FoundryTabsShell, type FoundryTab, type FoundryTabsShellProps, type TabContext } from './components/FoundryTabsShell';
17
17
  export * from './recording';
18
+ export * from './app';
18
19
  export * from './shell/navigator';
19
20
  export * from './shell/overflow';
20
21
  export * from './corpus/api';
@@ -34,7 +35,7 @@ export { TrackerDetailScreen, type TrackerDetailScreenProps } from './tracker/Tr
34
35
  export { trackerTab, type TrackerTabOptions } from './tracker/tab';
35
36
  export * from './home/controller';
36
37
  export { HomeScreen, type HomeScreenProps } from './home/HomeScreen';
37
- export { homeTab, DEFAULT_HOME_TYPES, type HomeTabOptions } from './home/tab';
38
+ export { homeTab, type HomeTabOptions } from './home/tab';
38
39
  export { createStore, errorMessage } from './screens/store';
39
40
  export * from './screens/library/controller';
40
41
  export * from './screens/library/fake-library';
@@ -27,7 +27,7 @@ function setup(handler: (url: string, init: RequestInit, n: { refresh: number; a
27
27
  return handler(String(url), init ?? {}, n);
28
28
  });
29
29
  const diag = { log: vi.fn() };
30
- const session = createSession({ centralUrl: 'http://central', storage, fetch: fetchMock as never, diag });
30
+ const session = createSession({ app: 'tandem', centralUrl: 'http://central', storage, fetch: fetchMock as never, diag });
31
31
  return { session, fetchMock, diag, data, n };
32
32
  }
33
33
 
@@ -1,10 +1,15 @@
1
1
  import { describe, expect, it, vi } from 'vitest';
2
+ import { createLinkResolver } from '../../app/config/links';
3
+ import { resolveFoundryApp } from '../../app/config/validate';
2
4
  import { createDeepLink } from '../deeplink';
3
5
 
6
+ const resolver = createLinkResolver(resolveFoundryApp({ app: { name: 'Tandem Go', scheme: 'tandemgo' }, tenant: { url: 'https://t.example.com' } }));
7
+
4
8
  function setup(phase: string = 'idle') {
5
9
  const go = vi.fn().mockResolvedValue(undefined);
6
- const link = createDeepLink({ getPhase: () => phase, go, log: vi.fn() });
7
- return { link, go };
10
+ const open = vi.fn();
11
+ const link = createDeepLink({ resolver, getPhase: () => phase, go, open, log: vi.fn() });
12
+ return { link, go, open };
8
13
  }
9
14
 
10
15
  describe('deep link tandemgo://record', () => {
@@ -41,6 +46,16 @@ describe('deep link tandemgo://record', () => {
41
46
  expect(go).not.toHaveBeenCalled();
42
47
  });
43
48
 
49
+ it('opens a tab link once ready, and holds it until then', async () => {
50
+ const { link, open } = setup();
51
+ link.handle('tandemgo://tab/notes/n1');
52
+ expect(open).not.toHaveBeenCalled();
53
+ await link.sessionReady();
54
+ expect(open).toHaveBeenCalledWith('notes', 'n1');
55
+ link.handle('tandemgo://tab/tracker');
56
+ expect(open).toHaveBeenLastCalledWith('tracker', undefined);
57
+ });
58
+
44
59
  it('sign-out forgets readiness', async () => {
45
60
  const { link, go } = setup();
46
61
  await link.sessionReady();
@@ -84,7 +99,7 @@ describe('deep link autostop test hook', () => {
84
99
 
85
100
  it('logs every link it receives, including ignored ones', async () => {
86
101
  const log = vi.fn();
87
- const link = createDeepLink({ getPhase: () => 'recording', go: vi.fn(), log });
102
+ const link = createDeepLink({ resolver, getPhase: () => 'recording', go: vi.fn(), log });
88
103
  await link.sessionReady();
89
104
  link.handle('tandemgo://record');
90
105
  expect(log).toHaveBeenCalledWith('deeplink', expect.objectContaining({ url: 'tandemgo://record', action: 'ignored-recording' }));
@@ -9,8 +9,8 @@ describe('diagnostics', () => {
9
9
  d.log('record.start', { id: 'n1', sampleRate: 44100 });
10
10
  expect(d.entries()).toEqual([{ t: 100, event: 'record.start', id: 'n1', sampleRate: 44100 }]);
11
11
  const line = sink.mock.calls[0][0] as string;
12
- expect(line.startsWith('[tandemgo] ')).toBe(true);
13
- expect(JSON.parse(line.replace('[tandemgo] ', ''))).toEqual(d.entries()[0]);
12
+ expect(line.startsWith('[app] ')).toBe(true);
13
+ expect(JSON.parse(line.replace('[app] ', ''))).toEqual(d.entries()[0]);
14
14
  });
15
15
 
16
16
  it('keeps only the newest N entries', () => {
@@ -22,7 +22,7 @@ function setup(handler: (url: string, init: RequestInit) => Response) {
22
22
  const fetchMock = vi.fn(async (url: string, init: RequestInit) => handler(String(url), init ?? {}));
23
23
  const storage = vault();
24
24
  const states: string[] = [];
25
- const session = createSession({ centralUrl: 'http://central', storage, fetch: fetchMock as never });
25
+ const session = createSession({ app: 'tandem', centralUrl: 'http://central', storage, fetch: fetchMock as never });
26
26
  session.subscribe((s) => states.push(s));
27
27
  return { session, fetchMock, storage, states };
28
28
  }
@@ -117,4 +117,30 @@ describe('session', () => {
117
117
  expect(session.getState()).toBe('signedOut');
118
118
  });
119
119
  });
120
+
121
+ it('reports why the session ended: a rejected refresh is expiry, signOut is not', async () => {
122
+ const { session, storage } = setup((url) => (url.endsWith('/token/refresh/') ? ok({ detail: 'expired' }, 401) : ok({}, 200)));
123
+ await storage.setRefreshToken('R1');
124
+ await session.restore();
125
+ expect(session.getState()).toBe('signedOut');
126
+ expect(session.endedBy()).toBe('expired');
127
+ });
128
+
129
+ it('tells the network watcher whether the server answered', async () => {
130
+ const seen: boolean[] = [];
131
+ const storage = vault();
132
+ await storage.setRefreshToken('R1');
133
+ let down = false;
134
+ const fetchMock = vi.fn(async (url: string) => {
135
+ if (down) throw new TypeError('Network request failed');
136
+ return String(url).endsWith('/token/refresh/') ? ok({ access: jwt(), refresh: 'R2' }) : ok({ fine: true });
137
+ });
138
+ const session = createSession({ app: 'x', centralUrl: 'http://central', storage, fetch: fetchMock as never, onNetwork: (r) => seen.push(r) });
139
+ await session.restore();
140
+ await session.authorizedFetch('http://tenant/api/v1/x');
141
+ down = true;
142
+ await expect(session.authorizedFetch('http://tenant/api/v1/x')).rejects.toThrow();
143
+ expect(seen).toEqual([true, false]);
144
+ expect(session.getState()).toBe('signedIn');
145
+ });
120
146
  });
@@ -1,53 +1,58 @@
1
+ import type { LinkAction, LinkResolver } from '../app/config/links';
1
2
  import type { GoOptions } from './recorder';
2
3
 
3
4
  /**
4
- * tandemgo://record start recording (manual STOP)
5
- * tandemgo://record?autostop=N start, and stop+upload after N seconds (device test hook)
6
- * Held until the session is ready; ignored while already recording.
5
+ * Routes app links once the session is ready. What a link means lives in one table (`createLinkResolver`, from the
6
+ * app config); this holds a link that arrives before sign-in, starts recording (ignored while already recording) and
7
+ * hands tab links to `open`. The latest held link wins.
7
8
  */
8
9
  export function createDeepLink(deps: {
9
- getPhase: () => string;
10
- go: (options: GoOptions) => Promise<void> | void;
10
+ resolver: LinkResolver;
11
+ getPhase?: () => string;
12
+ go?: (options: GoOptions) => Promise<void> | void;
13
+ /** Open a tab (optionally on one record): the shell navigator. */
14
+ open?: (tab: string, id?: string) => void;
11
15
  log?: (event: string, fields?: Record<string, unknown>) => void;
12
- /** The app's URL scheme (default 'tandemgo'). */
13
- scheme?: string;
14
16
  }) {
15
17
  const log = deps.log ?? (() => undefined);
16
- const scheme = deps.scheme ?? 'tandemgo';
17
18
  let ready = false;
18
- let pending: GoOptions | null = null;
19
+ let pending: { action: LinkAction; url: string } | null = null;
19
20
 
20
- const run = (options: GoOptions, url: string) => {
21
- if (deps.getPhase() === 'recording') {
21
+ const run = (action: LinkAction, url: string) => {
22
+ if (action.kind === 'open') {
23
+ log('deeplink', { url, action: 'open', tab: action.tab, id: action.id });
24
+ deps.open?.(action.tab, action.id);
25
+ return;
26
+ }
27
+ if (deps.getPhase?.() === 'recording') {
22
28
  log('deeplink', { url, action: 'ignored-recording' });
23
29
  return;
24
30
  }
31
+ const options: GoOptions = action.autostop ? { autostopSeconds: action.autostop } : {};
25
32
  log('deeplink', { url, action: 'start', ...options });
26
- void deps.go(options);
33
+ void deps.go?.(options);
27
34
  };
28
35
 
29
36
  return {
30
37
  handle(url: string) {
31
- const match = new RegExp(`^${scheme}://record(?:\\?(.*))?$`).exec(url);
32
- if (!match) {
38
+ const action = deps.resolver.resolve(url);
39
+ if (!action) {
33
40
  log('deeplink', { url, action: 'ignored-url' });
34
41
  return;
35
42
  }
36
- const seconds = Number(new URLSearchParams(match[1] ?? '').get('autostop'));
37
- const options: GoOptions = Number.isFinite(seconds) && seconds > 0 ? { autostopSeconds: seconds } : {};
38
43
  if (!ready) {
39
- pending = options;
44
+ pending = { action, url };
40
45
  log('deeplink', { url, action: 'waiting-for-session' });
41
46
  return;
42
47
  }
43
- run(options, url);
48
+ run(action, url);
44
49
  },
45
50
  async sessionReady() {
46
51
  ready = true;
47
52
  if (pending) {
48
- const options = pending;
53
+ const held = pending;
49
54
  pending = null;
50
- run(options, `${scheme}://record`);
55
+ run(held.action, held.url);
51
56
  }
52
57
  },
53
58
  sessionLost() {
@@ -15,7 +15,7 @@ const SECRET = /password|token|authorization|secret/i;
15
15
 
16
16
  /**
17
17
  * Always-on structured log. Each entry is also printed as ONE console line
18
- * `[tandemgo] {json}` so a device run can be read with log streaming.
18
+ * `[<tag>] {json}` so a device run can be read with log streaming.
19
19
  */
20
20
  export function createDiagnostics(options: {
21
21
  sink?: (line: string) => void;
@@ -24,10 +24,10 @@ export function createDiagnostics(options: {
24
24
  persist?: (json: string) => Promise<void>;
25
25
  /** Reads the persisted log so earlier launches survive a relaunch (evidence for kill/relaunch tests). */
26
26
  load?: () => Promise<string | null>;
27
- /** The console prefix (default 'tandemgo'). */
27
+ /** The console prefix (default 'app'). */
28
28
  tag?: string;
29
29
  } = {}): Diagnostics {
30
- const tag = options.tag ?? 'tandemgo';
30
+ const tag = options.tag ?? 'app';
31
31
  const sink = options.sink ?? ((line: string) => console.log(line));
32
32
  const now = options.now ?? Date.now;
33
33
  const max = options.max ?? 500;
@@ -4,11 +4,11 @@ export type SecretStore = TokenStorage;
4
4
  export type SessionState = 'unknown' | 'signedOut' | 'signedIn';
5
5
 
6
6
  /**
7
- * Tandem sign-in on the shared token client. Only the refresh token is kept
7
+ * Foundry sign-in on the shared token client. Only the refresh token is kept
8
8
  * (in the Keychain); the password is used once and never stored. A failed
9
9
  * refresh clears everything and flips to signedOut (the sign-in screen).
10
10
  */
11
- export function createSession(deps: { centralUrl: string; storage: SecretStore; fetch?: typeof fetch; /** The app slug central auth knows (default 'tandem'). */ app?: string; /** Receives 'auth.refresh' (ok, status or error - never a token). */ diag?: { log(event: string, fields?: Record<string, unknown>): void } }) {
11
+ export function createSession(deps: { centralUrl: string; storage: SecretStore; fetch?: typeof fetch; /** The app slug central auth knows (from the app config). */ app: string; /** Receives 'auth.refresh' (ok, status or error - never a token). */ diag?: { log(event: string, fields?: Record<string, unknown>): void }; /** Called after every authorized request: true when the server answered, false when the network failed. */ onNetwork?: (reachable: boolean) => void }) {
12
12
  const loggedFetch: typeof fetch = async (input, init) => {
13
13
  const isRefresh = String(input).endsWith('/auth/token/refresh/');
14
14
  try {
@@ -24,9 +24,11 @@ export function createSession(deps: { centralUrl: string; storage: SecretStore;
24
24
  apiBaseUrl: deps.centralUrl,
25
25
  storage: deps.storage,
26
26
  fetch: loggedFetch,
27
- app: deps.app ?? 'tandem',
27
+ app: deps.app,
28
28
  });
29
29
  let state: SessionState = 'unknown';
30
+ /** Why the session ended: the server rejected the refresh token ('expired') or the person signed out. */
31
+ let ended: 'expired' | 'signOut' | null = null;
30
32
  const listeners = new Set<(s: SessionState) => void>();
31
33
  const set = (next: SessionState) => {
32
34
  if (next === state) return;
@@ -40,7 +42,9 @@ export function createSession(deps: { centralUrl: string; storage: SecretStore;
40
42
  listeners.add(listener);
41
43
  return () => { listeners.delete(listener); };
42
44
  },
45
+ endedBy: () => ended,
43
46
  async signIn(email: string, password: string) {
47
+ ended = null;
44
48
  try {
45
49
  await auth.login(email, password);
46
50
  } catch (e) {
@@ -57,18 +61,28 @@ export function createSession(deps: { centralUrl: string; storage: SecretStore;
57
61
  } catch {
58
62
  // Rejected by the server -> the shared client cleared the token: sign in again.
59
63
  // Network failure -> the token is intact: stay signed in, uploads queue until online.
60
- set((await deps.storage.getRefreshToken()) ? 'signedIn' : 'signedOut');
64
+ if (await deps.storage.getRefreshToken()) set('signedIn');
65
+ else { ended = 'expired'; set('signedOut'); }
61
66
  }
62
67
  },
63
68
  async signOut() {
64
69
  await auth.logout();
70
+ ended = 'signOut';
65
71
  set('signedOut');
66
72
  },
67
73
  async authorizedFetch(url: string, init?: RequestInit) {
68
74
  try {
69
- return await auth.authorizedFetch(url, init);
75
+ const res = await auth.authorizedFetch(url, init);
76
+ deps.onNetwork?.(true);
77
+ return res;
70
78
  } catch (e) {
71
- if (!(await deps.storage.getRefreshToken())) set('signedOut');
79
+ if (!(await deps.storage.getRefreshToken())) {
80
+ ended = 'expired';
81
+ set('signedOut');
82
+ } else {
83
+ // A rejected refresh clears the token (above); an intact token with a thrown request means the network is down.
84
+ deps.onNetwork?.(false);
85
+ }
72
86
  throw e;
73
87
  }
74
88
  },