@startsimpli/integrations 0.2.104 → 0.2.106
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 +5 -5
- package/src/native/app/FoundryApp.tsx +38 -14
- package/src/native/app/__tests__/haptics.test.tsx +48 -0
- package/src/native/app/__tests__/hapticsExpo.test.ts +27 -0
- package/src/native/app/__tests__/registry.test.tsx +14 -1
- package/src/native/app/__tests__/schemaLoad.test.ts +28 -0
- package/src/native/app/config/__tests__/schema.test.ts +96 -0
- package/src/native/app/config/__tests__/validate.test.ts +12 -2
- package/src/native/app/config/defaults.ts +11 -11
- package/src/native/app/config/index.ts +1 -0
- package/src/native/app/config/schema.ts +62 -0
- package/src/native/app/config/types.ts +2 -0
- package/src/native/app/config/validate.ts +7 -1
- package/src/native/app/device.ts +5 -0
- package/src/native/app/entity/EntityTab.tsx +50 -19
- package/src/native/app/entity/__tests__/EntityTab.test.tsx +61 -0
- package/src/native/app/entity/__tests__/format.test.ts +42 -0
- package/src/native/app/entity/format.ts +38 -12
- package/src/native/app/haptics.ts +30 -0
- package/src/native/app/index.ts +1 -0
- package/src/native/app/registry.tsx +5 -2
- package/src/native/app/schemaLoad.ts +37 -0
- package/src/native/app/screens/ShellBanners.tsx +11 -6
- package/src/native/app/screens/SignInScreen.tsx +2 -2
- package/src/native/components/NoteDetailScreen.tsx +3 -2
- package/src/native/components/usePullRefresh.tsx +4 -2
- package/src/native/corpus/__tests__/display.test.ts +36 -1
- package/src/native/corpus/api.ts +12 -8
- package/src/native/corpus/display.ts +37 -1
- package/src/native/corpus/fake-tenant.ts +2 -1
- package/src/native/home/HomeScreen.tsx +7 -5
- package/src/native/home/__tests__/controller.test.ts +32 -0
- package/src/native/home/controller.ts +11 -6
- package/src/native/home/tab.tsx +2 -2
- package/src/native/recording/__tests__/recovery.test.ts +12 -0
- package/src/native/recording/recovery.ts +5 -2
- package/src/native/screens/shared/displayView.ts +19 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@startsimpli/integrations",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.106",
|
|
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",
|
|
@@ -48,11 +48,11 @@
|
|
|
48
48
|
"@tanstack/react-query": ">=5.0.0",
|
|
49
49
|
"@startsimpli/llm": ">=0.4.0",
|
|
50
50
|
"react-native": ">=0.74.0",
|
|
51
|
-
"@startsimpli/ui-native": ">=0.1.
|
|
51
|
+
"@startsimpli/ui-native": ">=0.1.11",
|
|
52
52
|
"react-native-safe-area-context": ">=4.0.0",
|
|
53
53
|
"@startsimpli/auth": "^0.4.49",
|
|
54
|
-
"@startsimpli/
|
|
55
|
-
"@startsimpli/
|
|
54
|
+
"@startsimpli/ui": "^0.4.170",
|
|
55
|
+
"@startsimpli/utils": "^0.4.17"
|
|
56
56
|
},
|
|
57
57
|
"peerDependenciesMeta": {
|
|
58
58
|
"react": {
|
|
@@ -100,7 +100,7 @@
|
|
|
100
100
|
"react-native-safe-area-context": "~5.7.0",
|
|
101
101
|
"@startsimpli/llm": "0.4.28",
|
|
102
102
|
"@startsimpli/ui": "0.4.170",
|
|
103
|
-
"@startsimpli/ui-native": "0.1.
|
|
103
|
+
"@startsimpli/ui-native": "0.1.11",
|
|
104
104
|
"@startsimpli/auth": "0.4.49",
|
|
105
105
|
"@startsimpli/utils": "0.4.17"
|
|
106
106
|
},
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { useEffect, useMemo, useRef, useState, type ReactNode } from 'react';
|
|
1
|
+
import { useCallback, useEffect, useMemo, useRef, useState, type ReactNode } from 'react';
|
|
2
2
|
import { AppState, Linking, Settings, StatusBar, useColorScheme } from 'react-native';
|
|
3
|
-
import { Spinner, ThemeProvider, darkTheme, lightTheme } from '@startsimpli/ui-native';
|
|
3
|
+
import { HapticsProvider, Spinner, type HapticKind, ThemeProvider, darkTheme, lightTheme } from '@startsimpli/ui-native';
|
|
4
4
|
import { FoundryTabsShell, type FoundryTab } from '../components/FoundryTabsShell';
|
|
5
5
|
import { createTabsNavigator, type TabsNavigator } from '../shell/navigator';
|
|
6
6
|
import type { SessionState } from '../recording/session';
|
|
@@ -13,6 +13,9 @@ import { createNavRestore, type SavedNav } from './restore';
|
|
|
13
13
|
import { createFoundryServices } from './services';
|
|
14
14
|
import { foundryStrings } from './strings';
|
|
15
15
|
import { resolveFoundryApp } from './config/validate';
|
|
16
|
+
import { applySchemaTypes, needsSchema } from './config/schema';
|
|
17
|
+
import { loadSchemaTypes } from './schemaLoad';
|
|
18
|
+
import type { SchemaTypeInfo } from '../corpus/display';
|
|
16
19
|
import type { FoundryAppConfig, FoundryAppInput } from './config/types';
|
|
17
20
|
import { DiagnosticsScreen } from './screens/DiagnosticsScreen';
|
|
18
21
|
import { RecordScreen } from './screens/RecordScreen';
|
|
@@ -41,6 +44,8 @@ function Themed({ mode, children }: { mode: FoundryAppConfig['theme']['mode'] |
|
|
|
41
44
|
function Root({ config, device, registry }: { config: FoundryAppConfig; device: FoundryDevice; registry: ReturnType<typeof createScreenRegistry> }) {
|
|
42
45
|
const launch = useMemo(() => readLaunch((k) => Settings.get(k), config), [config]);
|
|
43
46
|
const strings = useMemo(() => foundryStrings(config), [config]);
|
|
47
|
+
// The engine is the device's; a haptic that throws (no taptic hardware, simulator) never breaks a screen.
|
|
48
|
+
const haptic = useCallback((kind: HapticKind) => { try { device.haptics?.(kind); } catch { /* silent */ } }, [device]);
|
|
44
49
|
const { banners, services } = useMemo(() => {
|
|
45
50
|
const b = createBanners();
|
|
46
51
|
return { banners: b, services: createFoundryServices({ config, device, banners: b }) };
|
|
@@ -48,19 +53,36 @@ function Root({ config, device, registry }: { config: FoundryAppConfig; device:
|
|
|
48
53
|
const [auth, setAuth] = useState<SessionState>('unknown');
|
|
49
54
|
const [expired, setExpired] = useState(false);
|
|
50
55
|
const [showDiag, setShowDiag] = useState(false);
|
|
56
|
+
const data = useMemo(
|
|
57
|
+
() => createFoundryData({ config, authorizedFetch: services.session.authorizedFetch, fake: launch.fake, scenario: launch.scenario }),
|
|
58
|
+
[config, services, launch],
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
// The tenant's declared types fill what the config left to defaults (entity types, tabs, Home cards). Read once per
|
|
62
|
+
// sign-in, saved on the device for offline starts; `null` = run on the config alone.
|
|
63
|
+
const wantsSchema = useMemo(() => needsSchema(config), [config]);
|
|
64
|
+
const [schema, setSchema] = useState<SchemaTypeInfo[] | null | undefined>(wantsSchema ? undefined : null);
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
if (!wantsSchema || auth !== 'signedIn') return undefined;
|
|
67
|
+
const path = device.documentUri('schema-types.json');
|
|
68
|
+
let live = true;
|
|
69
|
+
void loadSchemaTypes({
|
|
70
|
+
read: () => data.corpus.schema.types(),
|
|
71
|
+
loadCache: async () => ((await device.files.exists(path)) ? device.files.read(path) : null),
|
|
72
|
+
saveCache: (v) => device.files.write(path, v),
|
|
73
|
+
}).then((types) => { if (live) setSchema(types); });
|
|
74
|
+
return () => { live = false; };
|
|
75
|
+
}, [wantsSchema, auth, data, device]);
|
|
76
|
+
const appConfig = useMemo(() => (schema ? applySchemaTypes(config, schema) : config), [config, schema]);
|
|
77
|
+
|
|
51
78
|
// Saved navigation is read once at launch; a launch argument or fake mode means "start where I said".
|
|
52
79
|
const restoreStore = useMemo(() => {
|
|
53
80
|
const path = device.documentUri('nav-state.json');
|
|
54
|
-
return createNavRestore({ read: async () => ((await device.files.exists(path)) ? device.files.read(path) : null), write: (v) => device.files.write(path, v) },
|
|
55
|
-
}, [
|
|
81
|
+
return createNavRestore({ read: async () => ((await device.files.exists(path)) ? device.files.read(path) : null), write: (v) => device.files.write(path, v) }, appConfig.tabs.map((t) => t.key));
|
|
82
|
+
}, [appConfig, device]);
|
|
56
83
|
const useRestore = !launch.target && !launch.fake;
|
|
57
84
|
const [saved, setSaved] = useState<SavedNav | null | undefined>(useRestore ? undefined : null);
|
|
58
|
-
useEffect(() => { if (useRestore) void restoreStore.load().then(setSaved); }, [restoreStore, useRestore]);
|
|
59
|
-
|
|
60
|
-
const data = useMemo(
|
|
61
|
-
() => createFoundryData({ config, authorizedFetch: services.session.authorizedFetch, fake: launch.fake, scenario: launch.scenario }),
|
|
62
|
-
[config, services, launch],
|
|
63
|
-
);
|
|
85
|
+
useEffect(() => { if (useRestore && schema !== undefined) void restoreStore.load().then(setSaved); }, [restoreStore, useRestore, schema]);
|
|
64
86
|
|
|
65
87
|
useEffect(() => {
|
|
66
88
|
if (launch.fake) { setAuth('signedIn'); return; }
|
|
@@ -89,14 +111,14 @@ function Root({ config, device, registry }: { config: FoundryAppConfig; device:
|
|
|
89
111
|
const recordRef = useRef<ReactNode>(record);
|
|
90
112
|
recordRef.current = record;
|
|
91
113
|
const tabs = useMemo(
|
|
92
|
-
() => buildFoundryTabs({ config, corpus: data.corpus, notes: data.notes, record: () => recordRef.current, member: data.member }, registry),
|
|
93
|
-
[
|
|
114
|
+
() => buildFoundryTabs({ config: appConfig, corpus: data.corpus, notes: data.notes, record: () => recordRef.current, member: data.member }, registry),
|
|
115
|
+
[appConfig, data, registry],
|
|
94
116
|
);
|
|
95
117
|
|
|
96
118
|
const start = launch.target ?? saved ?? null;
|
|
97
119
|
const navRef = useRef<{ for: FoundryTab[]; nav: TabsNavigator } | null>(null);
|
|
98
120
|
const nav = useMemo(() => {
|
|
99
|
-
if (saved === undefined) return null;
|
|
121
|
+
if (saved === undefined || schema === undefined) return null;
|
|
100
122
|
if (!navRef.current || navRef.current.for !== tabs) {
|
|
101
123
|
const n = createTabsNavigator({
|
|
102
124
|
tabs,
|
|
@@ -108,7 +130,7 @@ function Root({ config, device, registry }: { config: FoundryAppConfig; device:
|
|
|
108
130
|
return navRef.current.nav;
|
|
109
131
|
// `start` is only read the first time the navigator is built.
|
|
110
132
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
111
|
-
}, [tabs, saved]);
|
|
133
|
+
}, [tabs, saved, schema]);
|
|
112
134
|
useEffect(() => {
|
|
113
135
|
if (!nav) return undefined;
|
|
114
136
|
services.bindOpen((tab, id) => nav.open(tab, id ? { id } : null));
|
|
@@ -116,6 +138,7 @@ function Root({ config, device, registry }: { config: FoundryAppConfig; device:
|
|
|
116
138
|
}, [nav, services, restoreStore, launch.fake]);
|
|
117
139
|
|
|
118
140
|
return (
|
|
141
|
+
<HapticsProvider onHaptic={haptic}>
|
|
119
142
|
<Themed mode={launch.scheme ?? config.theme.mode}>
|
|
120
143
|
{auth === 'unknown' || (auth === 'signedIn' && !nav) ? <Spinner /> : null}
|
|
121
144
|
{auth === 'signedOut' ? <SignInScreen strings={strings} notice={expired ? strings.sessionExpired : null} onSignIn={(e, p) => services.session.signIn(e, p)} /> : null}
|
|
@@ -127,6 +150,7 @@ function Root({ config, device, registry }: { config: FoundryAppConfig; device:
|
|
|
127
150
|
) : null}
|
|
128
151
|
{auth === 'signedIn' && showDiag ? <DiagnosticsScreen diag={services.diag} strings={strings} onClose={() => setShowDiag(false)} /> : null}
|
|
129
152
|
</Themed>
|
|
153
|
+
</HapticsProvider>
|
|
130
154
|
);
|
|
131
155
|
}
|
|
132
156
|
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
|
|
3
|
+
const launchArgs: Record<string, string> = {};
|
|
4
|
+
vi.mock('react-native', async () => {
|
|
5
|
+
const stub = await import('../../../../../ui-native/test/rn-stub');
|
|
6
|
+
return {
|
|
7
|
+
...stub,
|
|
8
|
+
Settings: { get: (k: string) => launchArgs[k] },
|
|
9
|
+
StatusBar: 'StatusBar',
|
|
10
|
+
AppState: { currentState: 'active', addEventListener: () => ({ remove() {} }) },
|
|
11
|
+
Linking: { openURL: async () => {}, getInitialURL: async () => null, addEventListener: () => ({ remove() {} }) },
|
|
12
|
+
};
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
import { act, hostById, render } from '../../../../../ui-native/test/render';
|
|
16
|
+
import { FoundryApp } from '../FoundryApp';
|
|
17
|
+
import type { FoundryDevice } from '../device';
|
|
18
|
+
|
|
19
|
+
const tick = () => act(async () => { await new Promise((res) => setTimeout(res, 30)); });
|
|
20
|
+
const files = new Map<string, string>();
|
|
21
|
+
const device = (haptics?: FoundryDevice['haptics']): FoundryDevice => ({
|
|
22
|
+
tokenStorage: { getRefreshToken: async () => null, setRefreshToken: async () => {}, clear: async () => {} },
|
|
23
|
+
files: { exists: async (p) => files.has(p), read: async (p) => files.get(p) ?? '', write: async (p, v) => { files.set(p, v); } },
|
|
24
|
+
documentUri: (n) => `file:///docs/${n}`,
|
|
25
|
+
...(haptics ? { haptics } : {}),
|
|
26
|
+
});
|
|
27
|
+
const config = { app: { name: 'Acme Go' }, tenant: { url: 'https://acme.example.com' }, features: { recording: false, notes: false }, tabs: [{ screen: 'home' }] };
|
|
28
|
+
|
|
29
|
+
describe('the device haptics engine reaches the screens', () => {
|
|
30
|
+
it('pull to refresh on Home fires a light haptic through the engine the device supplied', async () => {
|
|
31
|
+
launchArgs.tgFakeTabs = '1';
|
|
32
|
+
const engine = vi.fn();
|
|
33
|
+
const r = render(<FoundryApp config={config} device={device(engine)} />);
|
|
34
|
+
await tick();
|
|
35
|
+
hostById(r, 'home-list').props.refreshControl.props.onRefresh();
|
|
36
|
+
expect(engine).toHaveBeenCalledWith('light');
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('an engine that throws never breaks the screen; no engine is silent', async () => {
|
|
40
|
+
launchArgs.tgFakeTabs = '1';
|
|
41
|
+
const bad = render(<FoundryApp config={config} device={device(() => { throw new Error('no taptic'); })} />);
|
|
42
|
+
await tick();
|
|
43
|
+
expect(() => hostById(bad, 'home-list').props.refreshControl.props.onRefresh()).not.toThrow();
|
|
44
|
+
const none = render(<FoundryApp config={config} device={device()} />);
|
|
45
|
+
await tick();
|
|
46
|
+
expect(() => hostById(none, 'home-list').props.refreshControl.props.onRefresh()).not.toThrow();
|
|
47
|
+
});
|
|
48
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { hapticsFromExpo } from '../haptics';
|
|
3
|
+
|
|
4
|
+
const fake = () => ({
|
|
5
|
+
selectionAsync: vi.fn(async () => {}),
|
|
6
|
+
impactAsync: vi.fn(async (_s: never) => {}),
|
|
7
|
+
notificationAsync: vi.fn(async (_t: never) => {}),
|
|
8
|
+
ImpactFeedbackStyle: { Light: 'light', Medium: 'medium' },
|
|
9
|
+
NotificationFeedbackType: { Success: 'success', Warning: 'warning', Error: 'error' },
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
describe('hapticsFromExpo', () => {
|
|
13
|
+
it('maps each kind the primitives fire to the expo-haptics call', () => {
|
|
14
|
+
const expo = fake();
|
|
15
|
+
const h = hapticsFromExpo(expo);
|
|
16
|
+
h('selection'); h('light'); h('medium'); h('success'); h('warning'); h('error');
|
|
17
|
+
expect(expo.selectionAsync).toHaveBeenCalledOnce();
|
|
18
|
+
expect(expo.impactAsync.mock.calls.map((c) => c[0])).toEqual(['light', 'medium']);
|
|
19
|
+
expect(expo.notificationAsync.mock.calls.map((c) => c[0])).toEqual(['success', 'warning', 'error']);
|
|
20
|
+
});
|
|
21
|
+
it('a rejected native call is swallowed', async () => {
|
|
22
|
+
const expo = fake();
|
|
23
|
+
expo.impactAsync = vi.fn(async () => { throw new Error('no taptic engine'); });
|
|
24
|
+
expect(() => hapticsFromExpo(expo)('light')).not.toThrow();
|
|
25
|
+
await Promise.resolve();
|
|
26
|
+
});
|
|
27
|
+
});
|
|
@@ -23,6 +23,19 @@ function deps(input: unknown, extra: string[] = []): ScreenDeps {
|
|
|
23
23
|
}
|
|
24
24
|
const base = { app: { name: 'Acme Go' }, tenant: { url: 'https://acme.example.com' } };
|
|
25
25
|
|
|
26
|
+
describe('tab icons by name', () => {
|
|
27
|
+
it('every built-in screen has a named default icon, even under a custom tab key', () => {
|
|
28
|
+
const tabs = buildFoundryTabs(deps({ ...base, tabs: [{ screen: 'home', key: 'today' }, { screen: 'tracker', key: 'todos' }, { screen: 'record', key: 'rec' }] }));
|
|
29
|
+
expect(tabs.every((t) => typeof t.icon === 'function')).toBe(true);
|
|
30
|
+
});
|
|
31
|
+
it('config icon names (home, mic, list) draw from the shared icon set, a glyph stays a glyph', () => {
|
|
32
|
+
const tabs = buildFoundryTabs(deps({ ...base, tabs: [{ screen: 'home', icon: 'list' }, { screen: 'tracker', icon: '*' }] }));
|
|
33
|
+
const draw = (i: (typeof tabs)[number]['icon']) => render(<>{i!({ color: '#000', active: true })}</>);
|
|
34
|
+
expect(draw(tabs[0].icon).root.findAll((n) => n.type === 'Path' || n.type === 'path').length).toBeGreaterThan(0);
|
|
35
|
+
expect(allText(draw(tabs[1].icon))).toBe('*');
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
|
|
26
39
|
describe('buildFoundryTabs', () => {
|
|
27
40
|
it('turns a config with no tabs into the full Foundry tab set with the bar priorities', () => {
|
|
28
41
|
const tabs = buildFoundryTabs(deps(base));
|
|
@@ -40,7 +53,7 @@ describe('buildFoundryTabs', () => {
|
|
|
40
53
|
] }));
|
|
41
54
|
expect(tabs.map((t) => [t.key, t.label, t.priority, t.description])).toEqual([['home', 'Today', 100, undefined], ['todos', 'Tasks', 5, 'My tasks']]);
|
|
42
55
|
expect(typeof tabs[0].icon).toBe('function');
|
|
43
|
-
expect(tabs[1].icon).
|
|
56
|
+
expect(typeof tabs[1].icon).toBe('function'); // the screen's default icon
|
|
44
57
|
});
|
|
45
58
|
|
|
46
59
|
it('only builds what the features leave on', () => {
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { loadSchemaTypes } from '../schemaLoad';
|
|
3
|
+
|
|
4
|
+
const types = [{ key: 'client', label: 'Client' }];
|
|
5
|
+
|
|
6
|
+
describe('loadSchemaTypes', () => {
|
|
7
|
+
it('returns the live read and saves it for next time', async () => {
|
|
8
|
+
const saveCache = vi.fn(async () => undefined);
|
|
9
|
+
expect(await loadSchemaTypes({ read: async () => types, loadCache: async () => null, saveCache })).toEqual(types);
|
|
10
|
+
expect(saveCache).toHaveBeenCalledWith(JSON.stringify(types));
|
|
11
|
+
});
|
|
12
|
+
it('offline: the saved copy', async () => {
|
|
13
|
+
const out = await loadSchemaTypes({ read: async () => { throw new Error('offline'); }, loadCache: async () => JSON.stringify(types), saveCache: async () => undefined });
|
|
14
|
+
expect(out).toEqual(types);
|
|
15
|
+
});
|
|
16
|
+
it('slow: the saved copy after the timeout', async () => {
|
|
17
|
+
const out = await loadSchemaTypes({ read: () => new Promise(() => undefined), loadCache: async () => JSON.stringify(types), saveCache: async () => undefined, timeoutMs: 5 });
|
|
18
|
+
expect(out).toEqual(types);
|
|
19
|
+
});
|
|
20
|
+
it('nothing live and nothing saved (or a corrupt save): null, never a throw', async () => {
|
|
21
|
+
expect(await loadSchemaTypes({ read: async () => { throw new Error('x'); }, loadCache: async () => null, saveCache: async () => undefined })).toBeNull();
|
|
22
|
+
expect(await loadSchemaTypes({ read: async () => { throw new Error('x'); }, loadCache: async () => '{not json', saveCache: async () => undefined })).toBeNull();
|
|
23
|
+
expect(await loadSchemaTypes({ read: async () => { throw new Error('x'); }, loadCache: async () => '[{"nokey":1}]', saveCache: async () => undefined })).toBeNull();
|
|
24
|
+
});
|
|
25
|
+
it('a failing cache write does not fail the load', async () => {
|
|
26
|
+
expect(await loadSchemaTypes({ read: async () => types, loadCache: async () => null, saveCache: async () => { throw new Error('disk'); } })).toEqual(types);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { applySchemaTypes, needsSchema } from '../schema';
|
|
3
|
+
import { resolveFoundryApp, validateFoundryApp } from '../validate';
|
|
4
|
+
|
|
5
|
+
const base = { app: { name: 'Hours Go' }, tenant: { url: 'https://hours.ai.startsimpli.com' } };
|
|
6
|
+
const types = [
|
|
7
|
+
{ key: 'client', label: 'Client', display: { title: 'name', icon: 'link' } },
|
|
8
|
+
{ key: 'time_entry', label: 'Time entry' },
|
|
9
|
+
{ key: 'project', label: 'Project' },
|
|
10
|
+
{ key: 'task', label: 'Task' },
|
|
11
|
+
{ key: 'invoice', label: 'Invoice' },
|
|
12
|
+
];
|
|
13
|
+
|
|
14
|
+
describe('applySchemaTypes: a Foundry with only a name and a tenant', () => {
|
|
15
|
+
it('shows every declared type: an entity tab each, labels from the schema, no config', () => {
|
|
16
|
+
const c = applySchemaTypes(resolveFoundryApp(base), types);
|
|
17
|
+
expect(Object.keys(c.entityTypes)).toEqual(['client', 'time_entry', 'project', 'task', 'invoice']);
|
|
18
|
+
expect(c.entityTypes.time_entry).toEqual({ label: 'Time entry', plural: 'Time entries' });
|
|
19
|
+
const entityTabs = c.tabs.filter((t) => t.screen === 'entity');
|
|
20
|
+
expect(entityTabs.map((t) => [t.key, t.label, t.options?.entityType])).toEqual([
|
|
21
|
+
['client', 'Clients', 'client'], ['time-entry', 'Time entries', 'time_entry'], ['project', 'Projects', 'project'], ['task', 'Tasks', 'task'], ['invoice', 'Invoices', 'invoice'],
|
|
22
|
+
]);
|
|
23
|
+
expect(entityTabs[0].icon).toBe('link');
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('built-in screens whose types the tenant does not declare are dropped; the ones that never need a type stay', () => {
|
|
27
|
+
const c = applySchemaTypes(resolveFoundryApp(base), types);
|
|
28
|
+
const screens = c.tabs.map((t) => t.screen);
|
|
29
|
+
expect(screens).toEqual(expect.arrayContaining(['home', 'record', 'ask', 'connections', 'connect-claude']));
|
|
30
|
+
expect(screens).not.toEqual(expect.arrayContaining(['tracker']));
|
|
31
|
+
expect(screens).not.toContain('library');
|
|
32
|
+
expect(screens).not.toContain('planning');
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('a built-in screen stays when its type is declared and does not also get an entity tab', () => {
|
|
36
|
+
const c = applySchemaTypes(resolveFoundryApp(base), [{ key: 'commitment', label: 'Item' }, { key: 'client', label: 'Client' }]);
|
|
37
|
+
expect(c.tabs.map((t) => t.screen)).toContain('tracker');
|
|
38
|
+
expect(c.tabs.some((t) => t.screen === 'entity' && t.options?.entityType === 'commitment')).toBe(false);
|
|
39
|
+
expect(c.tabs.some((t) => t.screen === 'entity' && t.options?.entityType === 'client')).toBe(true);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('Home counts the first declared types when none of the defaults exist', () => {
|
|
43
|
+
const c = applySchemaTypes(resolveFoundryApp(base), types);
|
|
44
|
+
expect(c.home.types).toEqual([{ key: 'client', label: 'Clients' }, { key: 'time_entry', label: 'Time entries' }, { key: 'project', label: 'Projects' }]);
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
describe('applySchemaTypes: explicit config wins', () => {
|
|
49
|
+
it('declared entityTypes keep their label and fields; the schema only adds the rest', () => {
|
|
50
|
+
const cfg = resolveFoundryApp({ ...base, entityTypes: { client: { label: 'Customer', titleField: 'company' } } });
|
|
51
|
+
const c = applySchemaTypes(cfg, types);
|
|
52
|
+
expect(c.entityTypes.client).toEqual({ label: 'Customer', titleField: 'company' });
|
|
53
|
+
expect(c.entityTypes.task).toEqual({ label: 'Task', plural: 'Tasks' });
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('explicit tabs are left exactly as written (no entity tab added, none dropped)', () => {
|
|
57
|
+
const cfg = resolveFoundryApp({ ...base, tabs: [{ screen: 'home' }, { screen: 'tracker' }] });
|
|
58
|
+
const c = applySchemaTypes(cfg, types);
|
|
59
|
+
expect(c.tabs.map((t) => t.key)).toEqual(['home', 'tracker']);
|
|
60
|
+
expect(c.entityTypes.client).toBeDefined();
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('explicit home types are left as written', () => {
|
|
64
|
+
const cfg = resolveFoundryApp({ ...base, home: { types: [{ key: 'task', label: 'Open' }] } });
|
|
65
|
+
expect(applySchemaTypes(cfg, types).home.types).toEqual([{ key: 'task', label: 'Open' }]);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('an unknown or empty schema changes nothing', () => {
|
|
69
|
+
const cfg = resolveFoundryApp(base);
|
|
70
|
+
expect(applySchemaTypes(cfg, [])).toBe(cfg);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('a type key that would collide with a tab key gets a prefixed tab key', () => {
|
|
74
|
+
const c = applySchemaTypes(resolveFoundryApp(base), [{ key: 'home', label: 'Home' }]);
|
|
75
|
+
expect(new Set(c.tabs.map((t) => t.key)).size).toBe(c.tabs.length);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('the result is a valid config: every entity tab names a declared entity type, and Home cards are tappable', () => {
|
|
79
|
+
const c = applySchemaTypes(resolveFoundryApp(base), types);
|
|
80
|
+
expect(resolveFoundryApp({ ...base, tabs: c.tabs, entityTypes: c.entityTypes, home: c.home }).tabs).toHaveLength(c.tabs.length);
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
describe('needsSchema', () => {
|
|
85
|
+
it('only when the config leaves something for the schema to fill', () => {
|
|
86
|
+
expect(needsSchema(resolveFoundryApp(base))).toBe(true);
|
|
87
|
+
const full = { ...base, tabs: [{ screen: 'home' }], home: { types: [{ key: 'task', label: 'Tasks' }] } };
|
|
88
|
+
expect(needsSchema(resolveFoundryApp(full))).toBe(false);
|
|
89
|
+
expect(needsSchema(resolveFoundryApp({ ...full, tabs: [{ key: 'tasks', screen: 'entity', options: { entityType: 'task' } }] }))).toBe(true);
|
|
90
|
+
expect(needsSchema(resolveFoundryApp({ ...full, entityTypes: { task: { label: 'Task' } }, tabs: [{ key: 'tasks', screen: 'entity', options: { entityType: 'task' } }] }))).toBe(false);
|
|
91
|
+
});
|
|
92
|
+
it('an entity tab for a type the config does not describe is a warning, not an error', () => {
|
|
93
|
+
const r = validateFoundryApp({ ...base, tabs: [{ key: 'tasks', screen: 'entity', options: { entityType: 'task' } }] });
|
|
94
|
+
expect(r.ok).toBe(true);
|
|
95
|
+
});
|
|
96
|
+
});
|
|
@@ -49,9 +49,10 @@ describe('validateFoundryApp', () => {
|
|
|
49
49
|
expect(validateFoundryApp(input, { extraScreens: ['map'] }).ok).toBe(true);
|
|
50
50
|
});
|
|
51
51
|
|
|
52
|
-
it('entity screens
|
|
52
|
+
it('entity screens name an entity type; the config may describe it, else the tenant schema does', () => {
|
|
53
53
|
const tabs = [{ key: 'artists', screen: 'entity', options: { entityType: 'artist' } }];
|
|
54
|
-
expect(validateFoundryApp({ ...minimal, tabs }).ok).toBe(false);
|
|
54
|
+
expect(validateFoundryApp({ ...minimal, tabs: [{ key: 'artists', screen: 'entity' }] }).ok).toBe(false);
|
|
55
|
+
expect(validateFoundryApp({ ...minimal, tabs }).ok).toBe(true);
|
|
55
56
|
const ok = resolveFoundryApp({ ...minimal, tabs, entityTypes: { artist: { label: 'Artist', titleField: 'name' } } });
|
|
56
57
|
expect(tabForEntityType(ok, 'artist')).toBe('artists');
|
|
57
58
|
});
|
|
@@ -77,3 +78,12 @@ describe('validateFoundryApp', () => {
|
|
|
77
78
|
expect(() => resolveFoundryApp({})).toThrow(/app: is required[\s\S]*tenant: is required/);
|
|
78
79
|
});
|
|
79
80
|
});
|
|
81
|
+
|
|
82
|
+
describe('tab icon names', () => {
|
|
83
|
+
it('an icon that looks like a name but is not in the icon set is a warning; a glyph or a real name is not', () => {
|
|
84
|
+
const r = validateFoundryApp({ ...minimal, tabs: [{ screen: 'home', icon: 'houze' }, { screen: 'tracker', icon: 'list' }, { screen: 'library', icon: '*' }] });
|
|
85
|
+
expect(r.ok).toBe(true);
|
|
86
|
+
const warnings = (r as { warnings: { path: string }[] }).warnings.map((w) => w.path);
|
|
87
|
+
expect(warnings.filter((w) => w.endsWith('.icon'))).toEqual(['tabs[0].icon']);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
@@ -24,17 +24,17 @@ export const DEFAULT_HOME_TYPES: FoundryHomeType[] = [
|
|
|
24
24
|
];
|
|
25
25
|
|
|
26
26
|
/** Default label / More blurb / bar priority per built-in screen. */
|
|
27
|
-
export const SCREEN_DEFAULTS: Record<string, { label: string; description?: string; priority?: number }> = {
|
|
28
|
-
home: { label: 'Home', priority: 100 },
|
|
29
|
-
record: { label: 'GO', priority: 90 },
|
|
30
|
-
notes: { label: 'Notes', priority: 80 },
|
|
31
|
-
tracker: { label: 'To-dos', priority: 70 },
|
|
32
|
-
library: { label: 'Library', description: 'Documents and recordings' },
|
|
33
|
-
ask: { label: 'Ask', description: 'Ask questions across your documents' },
|
|
34
|
-
planning: { label: 'Planning', description: 'Focuses and items' },
|
|
35
|
-
connections: { label: 'Connections', description: 'Accounts and data sources' },
|
|
36
|
-
'connect-claude': { label: 'Claude', description: 'Use your workspace from Claude' },
|
|
37
|
-
entity: { label: 'Records' },
|
|
27
|
+
export const SCREEN_DEFAULTS: Record<string, { label: string; description?: string; priority?: number; icon?: string }> = {
|
|
28
|
+
home: { label: 'Home', icon: 'home', priority: 100 },
|
|
29
|
+
record: { label: 'GO', icon: 'mic', priority: 90 },
|
|
30
|
+
notes: { label: 'Notes', icon: 'note', priority: 80 },
|
|
31
|
+
tracker: { label: 'To-dos', icon: 'check', priority: 70 },
|
|
32
|
+
library: { label: 'Library', icon: 'library', description: 'Documents and recordings' },
|
|
33
|
+
ask: { label: 'Ask', icon: 'ask', description: 'Ask questions across your documents' },
|
|
34
|
+
planning: { label: 'Planning', icon: 'planning', description: 'Focuses and items' },
|
|
35
|
+
connections: { label: 'Connections', icon: 'link', description: 'Accounts and data sources' },
|
|
36
|
+
'connect-claude': { label: 'Claude', icon: 'sparkle', description: 'Use your workspace from Claude' },
|
|
37
|
+
entity: { label: 'Records', icon: 'list' },
|
|
38
38
|
};
|
|
39
39
|
|
|
40
40
|
/** The tab each built-in screen takes when the config names no tabs. `record` keeps the key `go`. */
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { SchemaTypeInfo } from '../../corpus/display';
|
|
2
|
+
import { ICON_PATHS } from '@startsimpli/ui-native/icons';
|
|
3
|
+
import { DEFAULT_HOME_TYPES, SCREEN_ENTITY_TYPES } from './defaults';
|
|
4
|
+
import type { FoundryAppConfig, FoundryEntityType, FoundryHomeType, FoundryTabConfig } from './types';
|
|
5
|
+
|
|
6
|
+
const HOME_CARDS = 3;
|
|
7
|
+
const humanize = (key: string) => key.replace(/[_-]+/g, ' ').replace(/^./, (c) => c.toUpperCase());
|
|
8
|
+
const plural = (label: string) => (/[^aeiou]y$/i.test(label) ? `${label.slice(0, -1)}ies` : /(s|x|ch|sh)$/i.test(label) ? `${label}es` : `${label}s`);
|
|
9
|
+
const tabKey = (type: string) => type.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '');
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Fill what the config left to defaults from the tenant's declared types (`api.schema.types()`):
|
|
13
|
+
* - `entityTypes`: a label (and plural) for every declared type the config does not describe.
|
|
14
|
+
* - `tabs` (only when the config declares none): the built-in screens whose record types the tenant declares, plus an
|
|
15
|
+
* `entity` tab for every other declared type, so a new Foundry shows all its types with zero config.
|
|
16
|
+
* - `home.types` (only when the config declares none): the well-known types it has, else its first declared types.
|
|
17
|
+
* Anything the config declares is final; the schema never overrides it.
|
|
18
|
+
*/
|
|
19
|
+
export function applySchemaTypes(config: FoundryAppConfig, types: SchemaTypeInfo[]): FoundryAppConfig {
|
|
20
|
+
if (!types.length) return config;
|
|
21
|
+
const declared = new Set(types.map((t) => t.key));
|
|
22
|
+
|
|
23
|
+
const entityTypes: Record<string, FoundryEntityType> = { ...config.entityTypes };
|
|
24
|
+
for (const t of types) {
|
|
25
|
+
if (entityTypes[t.key]) continue;
|
|
26
|
+
const label = t.label ?? humanize(t.key);
|
|
27
|
+
entityTypes[t.key] = { label, plural: plural(label) };
|
|
28
|
+
}
|
|
29
|
+
const pluralOf = (type: string) => entityTypes[type].plural ?? plural(entityTypes[type].label);
|
|
30
|
+
|
|
31
|
+
let tabs = config.tabs;
|
|
32
|
+
if (config.defaulted.tabs) {
|
|
33
|
+
// Built-in screens that read a record type the tenant does not have would be empty tabs.
|
|
34
|
+
const kept = config.tabs.filter((t) => (SCREEN_ENTITY_TYPES[t.screen] ?? []).every((type) => declared.has(type)));
|
|
35
|
+
const shown = new Set(kept.flatMap((t) => SCREEN_ENTITY_TYPES[t.screen] ?? []));
|
|
36
|
+
const used = new Set(kept.map((t) => t.key));
|
|
37
|
+
const added: FoundryTabConfig[] = [];
|
|
38
|
+
for (const t of types) {
|
|
39
|
+
if (shown.has(t.key)) continue;
|
|
40
|
+
let key = tabKey(t.key) || 'type';
|
|
41
|
+
if (used.has(key)) key = `type-${key}`;
|
|
42
|
+
used.add(key);
|
|
43
|
+
const icon = t.display?.icon && t.display.icon in ICON_PATHS ? t.display.icon : undefined;
|
|
44
|
+
added.push({ key, screen: 'entity', label: pluralOf(t.key), ...(icon ? { icon } : {}), options: { entityType: t.key } });
|
|
45
|
+
}
|
|
46
|
+
tabs = [...kept, ...added];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
let home: FoundryHomeType[] = config.home.types;
|
|
50
|
+
if (config.defaulted.home) {
|
|
51
|
+
const known = DEFAULT_HOME_TYPES.filter((h) => declared.has(h.key));
|
|
52
|
+
home = known.length ? known : types.slice(0, HOME_CARDS).map((t) => ({ key: t.key, label: pluralOf(t.key) }));
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return { ...config, entityTypes, tabs, home: { types: home } };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Whether the tenant's schema can change this config at all: it leaves tabs or Home to defaults, or an entity tab names an undescribed type. */
|
|
59
|
+
export function needsSchema(config: FoundryAppConfig): boolean {
|
|
60
|
+
return config.defaulted.tabs || config.defaulted.home
|
|
61
|
+
|| config.tabs.some((t) => t.screen === 'entity' && !config.entityTypes[String(t.options?.entityType)]);
|
|
62
|
+
}
|
|
@@ -97,6 +97,8 @@ export interface FoundryAppConfig {
|
|
|
97
97
|
/** Record types the Home tab counts, in order. */
|
|
98
98
|
home: { types: FoundryHomeType[] };
|
|
99
99
|
entityTypes: Record<string, FoundryEntityType>;
|
|
100
|
+
/** What the config left to defaults. The tenant schema fills only these (`applySchemaTypes`); anything declared is final. */
|
|
101
|
+
defaulted: { tabs: boolean; home: boolean };
|
|
100
102
|
links: {
|
|
101
103
|
/** Hosts whose https links open the app (needs the associated-domains entitlement + an apple-app-site-association file). */
|
|
102
104
|
hosts: string[];
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ICON_PATHS } from '@startsimpli/ui-native/icons';
|
|
1
2
|
import { BUILTIN_SCREENS, type ConfigIssue, type FoundryAppConfig, type FoundryAppInput, type FoundryTabConfig } from './types';
|
|
2
3
|
import {
|
|
3
4
|
DEFAULT_BASE, DEFAULT_CENTRAL_URL, DEFAULT_FEATURES, DEFAULT_HOME_TYPES, SCREEN_DEFAULTS, SCREEN_ENTITY_TYPES, SCREEN_FEATURE, defaultBrandTagline, defaultTabs,
|
|
@@ -123,6 +124,10 @@ export function validateFoundryApp(input: unknown, options: ValidateOptions = {}
|
|
|
123
124
|
seen.add(key);
|
|
124
125
|
if (raw.priority !== undefined && typeof raw.priority !== 'number') bad(`${p}.priority`, 'must be a number');
|
|
125
126
|
for (const k of ['label', 'icon', 'description']) if (raw[k] !== undefined && !str(raw[k])) bad(`${p}.${k}`, 'must be a non-empty string');
|
|
127
|
+
// A lowercase word is read as an icon name; anything else (an emoji, a symbol) is drawn as written.
|
|
128
|
+
if (str(raw.icon) && /^[a-z][a-z0-9-]*$/.test(raw.icon) && !(raw.icon in ICON_PATHS)) {
|
|
129
|
+
warnings.push({ path: `${p}.icon`, message: `"${raw.icon}" is not in the icon set (${Object.keys(ICON_PATHS).join(', ')}); it will be drawn as text` });
|
|
130
|
+
}
|
|
126
131
|
if (raw.options !== undefined && !isObj(raw.options)) bad(`${p}.options`, 'must be an object');
|
|
127
132
|
tabs.push({ ...(raw as unknown as FoundryTabConfig), key, screen });
|
|
128
133
|
});
|
|
@@ -144,7 +149,7 @@ export function validateFoundryApp(input: unknown, options: ValidateOptions = {}
|
|
|
144
149
|
if (t.screen !== 'entity') return;
|
|
145
150
|
const type = t.options?.entityType;
|
|
146
151
|
if (!str(type)) bad(`tabs[${i}].options.entityType`, 'is required for the entity screen');
|
|
147
|
-
else if (!entityTypes[type])
|
|
152
|
+
else if (!entityTypes[type]) warnings.push({ path: `tabs[${i}].options.entityType`, message: `"${type}" is not in entityTypes; its label and fields come from the tenant schema` });
|
|
148
153
|
});
|
|
149
154
|
|
|
150
155
|
// home
|
|
@@ -194,6 +199,7 @@ export function validateFoundryApp(input: unknown, options: ValidateOptions = {}
|
|
|
194
199
|
tabs,
|
|
195
200
|
home: { types: homeTypes },
|
|
196
201
|
entityTypes,
|
|
202
|
+
defaulted: { tabs: !Array.isArray(tabsIn), home: homeIn.types === undefined },
|
|
197
203
|
links: { hosts: hosts as string[], routes: routes as FoundryAppConfig['links']['routes'] },
|
|
198
204
|
maxVisibleTabs: (input.maxVisibleTabs as number | undefined) ?? DEFAULT_BASE.maxVisibleTabs,
|
|
199
205
|
moreLabel: (input.moreLabel as string | undefined) ?? DEFAULT_BASE.moreLabel,
|
package/src/native/app/device.ts
CHANGED
|
@@ -33,6 +33,11 @@ export interface FoundryDevice {
|
|
|
33
33
|
tokenStorage: SecretStore;
|
|
34
34
|
files: TextFiles;
|
|
35
35
|
documentUri(name: string): string;
|
|
36
|
+
/**
|
|
37
|
+
* The haptics engine (`expo-haptics` in the template's `src/device.ts`). Optional: without one the app is silent, never broken.
|
|
38
|
+
* Fires on swipe actions, pull to refresh, record start/stop and destructive actions.
|
|
39
|
+
*/
|
|
40
|
+
haptics?: (kind: 'selection' | 'light' | 'medium' | 'success' | 'warning' | 'error') => void;
|
|
36
41
|
/** Required when `features.recording` is on. */
|
|
37
42
|
recording?: RecordingDevice;
|
|
38
43
|
}
|