@linked.cm/capacitor 0.3.7 → 1.1.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 (55) hide show
  1. package/CHANGELOG.md +62 -0
  2. package/lib/esm/backend.d.ts +1 -0
  3. package/lib/esm/data/capacitor.ttl +15 -0
  4. package/lib/esm/data/shapes.ttl +10 -0
  5. package/lib/esm/hooks/useAutomaticUpdates.d.ts +11 -1
  6. package/lib/esm/hooks/useAutomaticUpdates.js +35 -5
  7. package/lib/esm/hooks/useAutomaticUpdates.js.map +1 -1
  8. package/lib/esm/hooks/useMandatoryNativeUpdate.d.ts +47 -0
  9. package/lib/esm/hooks/useMandatoryNativeUpdate.js +160 -0
  10. package/lib/esm/hooks/useMandatoryNativeUpdate.js.map +1 -0
  11. package/lib/esm/hooks/useReleaseGate.d.ts +39 -0
  12. package/lib/esm/hooks/useReleaseGate.js +116 -0
  13. package/lib/esm/hooks/useReleaseGate.js.map +1 -0
  14. package/lib/esm/index.d.ts +6 -1
  15. package/lib/esm/index.js +6 -1
  16. package/lib/esm/index.js.map +1 -1
  17. package/lib/esm/ontologies/capacitor.d.ts +2 -0
  18. package/lib/esm/ontologies/capacitor.data.d.ts +8 -0
  19. package/lib/esm/ontologies/capacitor.data.js +15 -0
  20. package/lib/esm/ontologies/capacitor.data.js.map +1 -0
  21. package/lib/esm/ontologies/capacitor.js +6 -0
  22. package/lib/esm/ontologies/capacitor.js.map +1 -0
  23. package/lib/esm/ontologies/capacitor.register.js +15 -0
  24. package/lib/esm/ontologies/capacitor.register.js.map +1 -0
  25. package/lib/esm/package.d.ts +1 -1
  26. package/lib/esm/shapes/LocationUpdateAction.js +2 -2
  27. package/lib/esm/shapes/LocationUpdateAction.js.map +1 -1
  28. package/lib/esm/shapes/index.d.ts +1 -1
  29. package/lib/esm/shapes/index.js +1 -1
  30. package/lib/esm/shapes/index.js.map +1 -1
  31. package/lib/esm/utils/releaseStatus.d.ts +34 -0
  32. package/lib/esm/utils/releaseStatus.js +81 -0
  33. package/lib/esm/utils/releaseStatus.js.map +1 -0
  34. package/lib/esm/utils/releaseStatusCache.d.ts +31 -0
  35. package/lib/esm/utils/releaseStatusCache.js +48 -0
  36. package/lib/esm/utils/releaseStatusCache.js.map +1 -0
  37. package/lib/esm/utils/releaseStatusClient.d.ts +16 -0
  38. package/lib/esm/utils/releaseStatusClient.js +46 -0
  39. package/lib/esm/utils/releaseStatusClient.js.map +1 -0
  40. package/package.json +27 -17
  41. package/readme.md +98 -1
  42. package/tests/automatic-updates-gating.test.tsx +68 -0
  43. package/tests/mandatory-native-update-hook.test.tsx +179 -0
  44. package/tests/mandatory-native-update.test.mjs +94 -0
  45. package/tests/ontology.test.mjs +39 -0
  46. package/tests/release-gate.test.tsx +182 -0
  47. package/tests/release-status.test.mjs +154 -0
  48. package/vitest.config.ts +8 -0
  49. package/lib/esm/data/lincd-capacitor.json +0 -20
  50. package/lib/esm/ontologies/lincd-capacitor.d.ts +0 -30
  51. package/lib/esm/ontologies/lincd-capacitor.js +0 -28
  52. package/lib/esm/ontologies/lincd-capacitor.js.map +0 -1
  53. package/lib/esm/ontologies/lincd-capacitor.register.js +0 -15
  54. package/lib/esm/ontologies/lincd-capacitor.register.js.map +0 -1
  55. /package/lib/esm/ontologies/{lincd-capacitor.register.d.ts → capacitor.register.d.ts} +0 -0
package/package.json CHANGED
@@ -10,8 +10,15 @@
10
10
  "type": "git",
11
11
  "url": "git+ssh://git@github.com/linked-cm/capacitor.git"
12
12
  },
13
- "version": "0.3.7",
14
- "linkedPackage": true,
13
+ "version": "1.1.0",
14
+ "linked": {
15
+ "kind": "library"
16
+ },
17
+ "linkedOntologies": {
18
+ "capacitor": {
19
+ "namespace": "https://linked.cm/ont/capacitor/"
20
+ }
21
+ },
15
22
  "type": "module",
16
23
  "main": "lib/esm/index.js",
17
24
  "module": "lib/esm/index.js",
@@ -20,10 +27,8 @@
20
27
  "license": "ISC",
21
28
  "scripts": {
22
29
  "start": "linked dev",
23
- "test": "npm run build-esm && node --test tests/*.test.mjs",
24
- "build": "rimraf ./lib && npm run build-esm && npm run copy-to-lib",
25
- "build-esm": "echo \"compiling ESM\" && rimraf ./lib/esm && tsc -p tsconfig-esm.json",
26
- "copy-to-lib": "echo 'copying CSS + JSON assets to lib folder' && copyfiles -u 1 'src/**/*.css' 'src/**/*.json' lib/esm"
30
+ "test": "npm run build && node --test tests/*.test.mjs && vitest run --config vitest.config.ts",
31
+ "build": "linked build"
27
32
  },
28
33
  "keywords": [
29
34
  "linked",
@@ -53,19 +58,19 @@
53
58
  }
54
59
  },
55
60
  "dependencies": {
56
- "@_linked/auth": "^3.1.0",
57
- "@_linked/core": "^2.27.0",
58
- "@_linked/primitives": "^1.8.0",
59
- "@_linked/react": "^2.0.0",
60
- "@_linked/schema": "^1.5.0",
61
- "@_linked/server-utils": "^1.12.0",
62
- "@_linked/sioc": "^1.4.0",
61
+ "@_linked/auth": "^3.21.0",
62
+ "@_linked/core": "^2.46.0",
63
+ "@_linked/primitives": "^1.10.0",
64
+ "@_linked/react": "^2.1.0",
65
+ "@_linked/schema": "^1.9.2",
66
+ "@_linked/server-utils": "^1.17.0",
67
+ "@_linked/sioc": "^1.6.2",
63
68
  "google-libphonenumber": "3.2.33",
64
69
  "react-international-phone": "4.0.4",
65
70
  "react-router-dom": "^6.22.3"
66
71
  },
67
72
  "devDependencies": {
68
- "@_linked/cli": "^1.2",
73
+ "@_linked/cli": "^1.61.0",
69
74
  "@capacitor/app": "^7.0.0",
70
75
  "@capacitor/core": "^7.0.0",
71
76
  "@capacitor/dialog": "^7.0.0",
@@ -76,17 +81,22 @@
76
81
  "@capgo/capacitor-updater": "^7.4.0",
77
82
  "@changesets/changelog-github": "^0.5.2",
78
83
  "@changesets/cli": "^2.29.8",
84
+ "@testing-library/dom": "10.4.2",
85
+ "@testing-library/react": "16.3.3",
79
86
  "@tolgee/react": "^5.33.0",
80
87
  "@types/node": "^20.12.7",
81
88
  "@types/react": "^19.3.0",
82
89
  "@types/react-dom": "^19.3.0",
83
90
  "capacitor-plugin-safe-area": "^4.0.3",
84
- "copyfiles": "^2.4.1",
85
- "rimraf": "^5.0.7",
91
+ "happy-dom": "20.14.6",
92
+ "react": "^19.3.1",
93
+ "react-dom": "^19.3.1",
86
94
  "typescript": "^5.7.3",
87
- "typescript-plugin-css-modules": "^5.1.0"
95
+ "typescript-plugin-css-modules": "^5.1.0",
96
+ "vitest": "2.1.9"
88
97
  },
89
98
  "peerDependencies": {
99
+ "react": "^18.2.0 || ^19.0.0",
90
100
  "@capacitor/app": ">=7 <8",
91
101
  "@capacitor/core": ">=7 <8",
92
102
  "@capacitor/dialog": ">=7 <8",
package/readme.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Native app helpers for social sign-in, WhatsApp one-time codes, safe area, location, and store or bundle updates.
4
4
 
5
- The location term stays on `http://lincd.org/ont/lincd-capacitor/`. Shape registration uses `@linked.cm/capacitor`.
5
+ The location term `LocationUpdateAction` (a `schema:UpdateAction`) lives at `https://linked.cm/ont/capacitor/` (prefix `capacitor`), declared in `src/data/capacitor.ttl`, the only source of terms. `linked generate-ontology` writes the accessor modules from it (`package.json` `"linkedOntologies"`), and `linked build` fails when they are stale. Import the terms as a namespace: `import * as capacitor from '@linked.cm/capacitor/ontologies/capacitor'` (`capacitor.LocationUpdateAction`), and `ns`/`loadData` from `@linked.cm/capacitor/ontologies/capacitor.data`. Shape registration uses `@linked.cm/capacitor`.
6
6
 
7
7
  ## Public entry points
8
8
 
@@ -18,6 +18,11 @@ The location term stays on `http://lincd.org/ont/lincd-capacitor/`. Shape regist
18
18
  | `@linked.cm/capacitor/hooks/useCapacitor` | `CapacitorProvider` for deep links and native token storage |
19
19
  | `@linked.cm/capacitor/hooks/useAutomaticUpdates` | OTA bundle updates and a maintenance check |
20
20
  | `@linked.cm/capacitor/hooks/useNativeAppUpdate` | Store update prompt on iOS and Android |
21
+ | `@linked.cm/capacitor/hooks/useMandatoryNativeUpdate` | App-supplied minimum-version enforcement for installed iOS and Android binaries |
22
+ | `@linked.cm/capacitor/hooks/useReleaseGate` | Non-blocking maintenance, installed-binary, and OTA coordination |
23
+ | `@linked.cm/capacitor/utils/releaseStatus` | Shared release-status contract and validation |
24
+ | `@linked.cm/capacitor/utils/releaseStatusCache` | Last-valid server cache and framework-light status handler |
25
+ | `@linked.cm/capacitor/utils/releaseStatusClient` | Deduplicated, validated status client with last-valid fallback |
21
26
  | `@linked.cm/capacitor/shapes/LocationUpdateAction` | `LocationUpdateAction.updateUserLocation` |
22
27
  | `@linked.cm/capacitor/shapes/index` | Registers the location shape without loading the components |
23
28
  | `@linked.cm/capacitor/utils/helper` | `normalizeTelephone` and `replaceLocalhostWithSiteRoot` |
@@ -56,3 +61,95 @@ WhatsApp sign-in asks the backend to send a code, then validates it. `generateOT
56
61
  `LocationEnabler` requests the device position only when the switch turns on, then calls `LocationUpdateAction.updateUserLocation`. Turning the switch off clears `enabledLocationServices` on the current account.
57
62
 
58
63
  `useAutomaticUpdates` runs on iOS and Android. It confirms the current bundle, checks the native store version, polls `{SITE_ROOT}/__health`, and downloads a newer bundle when the server is up. `IOS_APP_STORE_ID` is the numeric store id used when opening the store.
64
+
65
+ `__health` maintenance inside `useAutomaticUpdates` is a legacy server-up
66
+ signal for Capgo OTA timing. Release-status maintenance from `/status` is a
67
+ separate product policy overlay owned by `useReleaseGate`. Apps that adopt the
68
+ release gate should treat `/status` as the source of truth for maintenance UI
69
+ and keep `__health` only as OTA infrastructure probing.
70
+
71
+ Apps that enforce their own minimum installed-binary version can pause OTA
72
+ without delaying application rendering:
73
+
74
+ ```ts
75
+ import { useAutomaticUpdates } from '@linked.cm/capacitor/hooks/useAutomaticUpdates';
76
+ import { useMandatoryNativeUpdate } from '@linked.cm/capacitor/hooks/useMandatoryNativeUpdate';
77
+
78
+ const nativeUpdate = useMandatoryNativeUpdate({
79
+ minimumVersion: status?.minimumVersion,
80
+ fallbackMinimumVersion: COMPILED_MINIMUM_NATIVE_VERSION,
81
+ iosAppStoreId: process.env.IOS_APP_STORE_ID,
82
+ androidPackageName: process.env.APP_ID,
83
+ });
84
+
85
+ useAutomaticUpdates({
86
+ enabled:
87
+ nativeUpdate.state.status === 'not-native' ||
88
+ nativeUpdate.state.status === 'supported',
89
+ checkNativeStoreVersion: false,
90
+ });
91
+ ```
92
+
93
+ While disabled, automatic updates still call `notifyAppReady()` to prevent a
94
+ working Capgo bundle from rolling back, but skip channel, health, store, and OTA
95
+ work. Both options default to the previous behavior for existing callers.
96
+
97
+ For a complete release gate, applications inject their own status loader while
98
+ the package owns the reusable lifecycle and native checks. `loadStatus` must
99
+ return an already-normalized `ReleaseStatus` (for example via
100
+ `ReleaseStatusClient` or `normalizeReleaseStatus`); the gate does not
101
+ re-validate that object.
102
+
103
+ ```ts
104
+ import { useAutomaticUpdates } from '@linked.cm/capacitor/hooks/useAutomaticUpdates';
105
+ import { useReleaseGate } from '@linked.cm/capacitor/hooks/useReleaseGate';
106
+ import { ReleaseStatusClient } from '@linked.cm/capacitor/utils/releaseStatusClient';
107
+
108
+ const statusClient = new ReleaseStatusClient({
109
+ url: () => `${API_ROOT}/status`,
110
+ headers: () => ({ 'X-App-Version': APP_VERSION }),
111
+ });
112
+
113
+ const gate = useReleaseGate({
114
+ loadStatus: () => statusClient.load(),
115
+ fallbackMinimumVersion: COMPILED_MINIMUM_NATIVE_VERSION,
116
+ iosAppStoreId: IOS_APP_STORE_ID,
117
+ androidPackageName: APP_ID,
118
+ });
119
+
120
+ useAutomaticUpdates({
121
+ enabled: gate.otaEnabled,
122
+ checkNativeStoreVersion: false,
123
+ });
124
+ ```
125
+
126
+ The app renders immediately and decides how to present `gate.state`. Web uses
127
+ maintenance only; iOS and Android also enforce the installed store-binary
128
+ version. On native, `gate.otaEnabled` stays false until status has settled and
129
+ the installed binary is confirmed against the exact effective minimum. On web
130
+ it stays true because `useAutomaticUpdates` does not run there.
131
+
132
+ On the server, inject application-owned storage into the cache. The package
133
+ does not own configuration files, locks, authorization, or route registration:
134
+
135
+ ```ts
136
+ import {
137
+ createReleaseStatusHandler,
138
+ ReleaseStatusCache,
139
+ } from '@linked.cm/capacitor/utils/releaseStatusCache';
140
+
141
+ const cache = new ReleaseStatusCache({
142
+ initialStatus: SAFE_COMPILED_STATUS,
143
+ readStatus: () => readReleaseStatusFromApplicationConfig(),
144
+ });
145
+ cache.load();
146
+ cache.start();
147
+ server.get('/status', createReleaseStatusHandler(cache));
148
+ // later, during provider/server dispose:
149
+ cache.stop();
150
+ ```
151
+
152
+ The cache refreshes every minute by default and retains its last valid snapshot
153
+ when reading or validation fails. The handler returns validated release fields
154
+ with `Cache-Control: no-store`. Call `load()` before serving `/status`, keep
155
+ `start()` running while the process is up, and `stop()` on dispose.
@@ -0,0 +1,68 @@
1
+ // @vitest-environment happy-dom
2
+ import { renderHook, waitFor } from '@testing-library/react';
3
+ import { beforeEach, describe, expect, it, vi } from 'vitest';
4
+
5
+ const mocks = vi.hoisted(() => ({
6
+ notifyAppReady: vi.fn(async () => undefined),
7
+ getChannel: vi.fn(async () => ({ channel: 'production', allowSet: false })),
8
+ setChannel: vi.fn(async () => undefined),
9
+ getLatest: vi.fn(async () => ({ error: 'no new version available' })),
10
+ getAppUpdateInfo: vi.fn(),
11
+ }));
12
+
13
+ vi.mock('@capacitor/core', () => ({
14
+ Capacitor: {
15
+ getPlatform: () => 'ios',
16
+ isNativePlatform: () => true,
17
+ },
18
+ }));
19
+
20
+ vi.mock('@capgo/capacitor-updater', () => ({
21
+ CapacitorUpdater: {
22
+ notifyAppReady: (...args: unknown[]) => mocks.notifyAppReady(...args),
23
+ getChannel: (...args: unknown[]) => mocks.getChannel(...args),
24
+ setChannel: (...args: unknown[]) => mocks.setChannel(...args),
25
+ getLatest: (...args: unknown[]) => mocks.getLatest(...args),
26
+ addListener: vi.fn(async () => ({ remove: vi.fn() })),
27
+ download: vi.fn(),
28
+ set: vi.fn(),
29
+ reload: vi.fn(),
30
+ },
31
+ }));
32
+
33
+ vi.mock('@capawesome/capacitor-app-update', () => ({
34
+ AppUpdate: {
35
+ getAppUpdateInfo: (...args: unknown[]) => mocks.getAppUpdateInfo(...args),
36
+ performImmediateUpdate: vi.fn(),
37
+ openAppStore: vi.fn(),
38
+ },
39
+ AppUpdateAvailability: { UPDATE_AVAILABLE: 2 },
40
+ AppUpdateResultCode: { OK: 0 },
41
+ }));
42
+
43
+ vi.mock('@capacitor/dialog', () => ({
44
+ Dialog: { confirm: vi.fn() },
45
+ }));
46
+
47
+ import { useAutomaticUpdates } from '../src/hooks/useAutomaticUpdates.js';
48
+
49
+ describe('useAutomaticUpdates gating', () => {
50
+ beforeEach(() => {
51
+ vi.clearAllMocks();
52
+ process.env.SITE_ROOT = 'https://example.test';
53
+ });
54
+
55
+ it('still confirms Capgo readiness when OTA work is paused', async () => {
56
+ renderHook(() =>
57
+ useAutomaticUpdates({
58
+ enabled: false,
59
+ checkNativeStoreVersion: false,
60
+ })
61
+ );
62
+
63
+ await waitFor(() => expect(mocks.notifyAppReady).toHaveBeenCalledOnce());
64
+ expect(mocks.getChannel).not.toHaveBeenCalled();
65
+ expect(mocks.getLatest).not.toHaveBeenCalled();
66
+ expect(mocks.getAppUpdateInfo).not.toHaveBeenCalled();
67
+ });
68
+ });
@@ -0,0 +1,179 @@
1
+ // @vitest-environment happy-dom
2
+ import { act, renderHook, waitFor } from '@testing-library/react';
3
+ import { beforeEach, describe, expect, it, vi } from 'vitest';
4
+ import { useMandatoryNativeUpdate } from '../src/hooks/useMandatoryNativeUpdate.js';
5
+
6
+ const runtime = vi.hoisted(() => ({
7
+ platform: 'ios' as 'web' | 'ios' | 'android',
8
+ version: '4.3.6',
9
+ listeners: [] as Array<(event: { isActive: boolean }) => void>,
10
+ getInfo: vi.fn(async () => ({ version: '4.3.6' })),
11
+ openAppStore: vi.fn(),
12
+ }));
13
+
14
+ vi.mock('@capacitor/core', () => ({
15
+ Capacitor: {
16
+ getPlatform: () => runtime.platform,
17
+ isNativePlatform: () => runtime.platform !== 'web',
18
+ },
19
+ }));
20
+
21
+ vi.mock('@capacitor/app', () => ({
22
+ App: {
23
+ getInfo: () => runtime.getInfo(),
24
+ addListener: vi.fn(async (_event, listener) => {
25
+ runtime.listeners.push(listener);
26
+ return {
27
+ remove: async () => {
28
+ runtime.listeners = runtime.listeners.filter(
29
+ (candidate) => candidate !== listener
30
+ );
31
+ },
32
+ };
33
+ }),
34
+ },
35
+ }));
36
+
37
+ vi.mock('@capawesome/capacitor-app-update', () => ({
38
+ AppUpdate: {
39
+ getAppUpdateInfo: vi.fn(),
40
+ performImmediateUpdate: vi.fn(),
41
+ openAppStore: (...args: unknown[]) => runtime.openAppStore(...args),
42
+ },
43
+ AppUpdateResultCode: { OK: 0 },
44
+ }));
45
+
46
+ describe('useMandatoryNativeUpdate lifecycle', () => {
47
+ beforeEach(() => {
48
+ runtime.platform = 'ios';
49
+ runtime.version = '4.3.6';
50
+ runtime.listeners = [];
51
+ runtime.getInfo.mockReset();
52
+ runtime.getInfo.mockImplementation(async () => ({
53
+ version: runtime.version,
54
+ }));
55
+ runtime.openAppStore.mockReset();
56
+ vi.clearAllMocks();
57
+ });
58
+
59
+ it('reads App.getInfo on mount and stays not-native on web', async () => {
60
+ runtime.platform = 'web';
61
+ const { result } = renderHook(() =>
62
+ useMandatoryNativeUpdate({ fallbackMinimumVersion: '4.3.4' })
63
+ );
64
+ expect(result.current.state.status).toBe('not-native');
65
+ expect(runtime.getInfo).not.toHaveBeenCalled();
66
+ });
67
+
68
+ it('marks an outdated installed binary as required', async () => {
69
+ runtime.version = '4.3.5';
70
+ const { result } = renderHook(() =>
71
+ useMandatoryNativeUpdate({
72
+ fallbackMinimumVersion: '4.3.4',
73
+ minimumVersion: '4.4.0',
74
+ iosAppStoreId: '1234567890',
75
+ })
76
+ );
77
+ await waitFor(() => expect(result.current.state.status).toBe('required'));
78
+ expect(runtime.getInfo).toHaveBeenCalled();
79
+ expect(result.current.state).toMatchObject({
80
+ currentVersion: '4.3.5',
81
+ minimumVersion: '4.4.0',
82
+ });
83
+ });
84
+
85
+ it('rechecks on foreground and when the minimum changes', async () => {
86
+ runtime.version = '4.3.6';
87
+ const { result, rerender } = renderHook(
88
+ ({ minimumVersion }) =>
89
+ useMandatoryNativeUpdate({
90
+ fallbackMinimumVersion: '4.3.4',
91
+ minimumVersion,
92
+ iosAppStoreId: '1234567890',
93
+ }),
94
+ { initialProps: { minimumVersion: '4.3.4' } }
95
+ );
96
+ await waitFor(() => expect(result.current.state.status).toBe('supported'));
97
+
98
+ runtime.version = '4.3.6';
99
+ rerender({ minimumVersion: '4.4.0' });
100
+ await waitFor(() => expect(result.current.state.status).toBe('required'));
101
+
102
+ runtime.version = '4.4.0';
103
+ await act(async () => {
104
+ runtime.listeners.forEach((listener) => listener({ isActive: true }));
105
+ });
106
+ await waitFor(() => expect(result.current.state.status).toBe('supported'));
107
+ expect(runtime.getInfo.mock.calls.length).toBeGreaterThanOrEqual(3);
108
+ });
109
+
110
+ it('ignores a stale App.getInfo result after a newer check', async () => {
111
+ let resolveOld!: (value: { version: string }) => void;
112
+ let resolveNew!: (value: { version: string }) => void;
113
+ runtime.getInfo
114
+ .mockImplementationOnce(
115
+ () =>
116
+ new Promise((resolve) => {
117
+ resolveOld = resolve;
118
+ })
119
+ )
120
+ .mockImplementationOnce(
121
+ () =>
122
+ new Promise((resolve) => {
123
+ resolveNew = resolve;
124
+ })
125
+ );
126
+
127
+ const { result } = renderHook(() =>
128
+ useMandatoryNativeUpdate({
129
+ fallbackMinimumVersion: '4.3.4',
130
+ minimumVersion: '4.4.0',
131
+ iosAppStoreId: '1234567890',
132
+ })
133
+ );
134
+ await act(async () => {
135
+ result.current.retryCheck();
136
+ });
137
+ await act(async () => {
138
+ resolveNew({ version: '4.4.0' });
139
+ });
140
+ await waitFor(() => expect(result.current.state.status).toBe('supported'));
141
+ await act(async () => {
142
+ resolveOld({ version: '4.3.0' });
143
+ });
144
+ expect(result.current.state.status).toBe('supported');
145
+ });
146
+
147
+ it('surfaces getInfo failures and recovers through retry', async () => {
148
+ runtime.getInfo
149
+ .mockRejectedValueOnce(new Error('unavailable'))
150
+ .mockResolvedValueOnce({ version: '4.4.0' });
151
+ const { result } = renderHook(() =>
152
+ useMandatoryNativeUpdate({
153
+ fallbackMinimumVersion: '4.3.4',
154
+ minimumVersion: '4.4.0',
155
+ })
156
+ );
157
+ await waitFor(() => expect(result.current.state.status).toBe('error'));
158
+ await act(async () => {
159
+ await result.current.retryCheck();
160
+ });
161
+ await waitFor(() => expect(result.current.state.status).toBe('supported'));
162
+ });
163
+
164
+ it('opens the App Store for a required iOS update', async () => {
165
+ runtime.version = '4.3.5';
166
+ const { result } = renderHook(() =>
167
+ useMandatoryNativeUpdate({
168
+ fallbackMinimumVersion: '4.3.4',
169
+ minimumVersion: '4.4.0',
170
+ iosAppStoreId: '1234567890',
171
+ })
172
+ );
173
+ await waitFor(() => expect(result.current.state.status).toBe('required'));
174
+ await act(async () => {
175
+ await result.current.requestUpdate();
176
+ });
177
+ expect(runtime.openAppStore).toHaveBeenCalledWith({ appId: '1234567890' });
178
+ });
179
+ });
@@ -0,0 +1,94 @@
1
+ import assert from 'node:assert/strict';
2
+ import test from 'node:test';
3
+
4
+ import {
5
+ compareNativeVersions,
6
+ effectiveMinimumVersion,
7
+ nativeUpdateRequirement,
8
+ openRequiredNativeUpdate,
9
+ } from '../lib/esm/hooks/useMandatoryNativeUpdate.js';
10
+ import { resolveAutomaticUpdateOptions } from '../lib/esm/hooks/useAutomaticUpdates.js';
11
+
12
+ test('compares stable native versions numerically', () => {
13
+ assert.equal(compareNativeVersions('4.10.0', '4.9.9'), 1);
14
+ assert.equal(compareNativeVersions('4.3.6', '4.3.6'), 0);
15
+ assert.equal(compareNativeVersions('4.3.5', '4.3.6'), -1);
16
+ assert.throws(
17
+ () => compareNativeVersions('4.3.6-beta.1', '4.3.6'),
18
+ /stable X\.Y\.Z/
19
+ );
20
+ });
21
+
22
+ test('server minimum cannot lower the compiled fallback', () => {
23
+ assert.equal(effectiveMinimumVersion('4.3.4', '4.3.0'), '4.3.4');
24
+ assert.equal(effectiveMinimumVersion('4.3.4', '4.4.0'), '4.4.0');
25
+ assert.equal(effectiveMinimumVersion('4.3.4'), '4.3.4');
26
+ assert.equal(effectiveMinimumVersion('4.3.4', 'invalid'), '4.3.4');
27
+ });
28
+
29
+ test('installed binary is checked against the effective minimum', () => {
30
+ assert.deepEqual(nativeUpdateRequirement('4.3.6', '4.3.4', '4.4.0'), {
31
+ supported: false,
32
+ minimumVersion: '4.4.0',
33
+ });
34
+ assert.deepEqual(nativeUpdateRequirement('4.3.6', '4.3.4', '4.3.0'), {
35
+ supported: true,
36
+ minimumVersion: '4.3.4',
37
+ });
38
+ });
39
+
40
+ test('automatic updates preserve defaults and accept explicit gating', () => {
41
+ assert.deepEqual(resolveAutomaticUpdateOptions(), {
42
+ enabled: true,
43
+ checkNativeStoreVersion: true,
44
+ });
45
+ assert.deepEqual(
46
+ resolveAutomaticUpdateOptions({
47
+ enabled: false,
48
+ checkNativeStoreVersion: false,
49
+ }),
50
+ { enabled: false, checkNativeStoreVersion: false }
51
+ );
52
+ });
53
+
54
+ test('Android immediate update avoids opening Google Play when successful', async () => {
55
+ const calls = [];
56
+ await openRequiredNativeUpdate(
57
+ { platform: 'android', androidPackageName: 'example.app' },
58
+ {
59
+ getAppUpdateInfo: async () => ({ immediateUpdateAllowed: true }),
60
+ performImmediateUpdate: async () => {
61
+ calls.push('immediate');
62
+ return { code: 0 };
63
+ },
64
+ openAppStore: async () => calls.push('store'),
65
+ }
66
+ );
67
+ assert.deepEqual(calls, ['immediate']);
68
+ });
69
+
70
+ test('Android cancellation falls back to Google Play', async () => {
71
+ const stores = [];
72
+ await openRequiredNativeUpdate(
73
+ { platform: 'android', androidPackageName: 'example.app' },
74
+ {
75
+ getAppUpdateInfo: async () => ({ immediateUpdateAllowed: true }),
76
+ performImmediateUpdate: async () => ({ code: 1 }),
77
+ openAppStore: async (options) => stores.push(options),
78
+ }
79
+ );
80
+ assert.deepEqual(stores, [{ androidPackageName: 'example.app' }]);
81
+ });
82
+
83
+ test('iOS opens the configured numeric App Store id', async () => {
84
+ const stores = [];
85
+ await openRequiredNativeUpdate(
86
+ { platform: 'ios', iosAppStoreId: '1234567890' },
87
+ {
88
+ getAppUpdateInfo: async () => ({}),
89
+ performImmediateUpdate: async () => ({ code: 0 }),
90
+ openAppStore: async (options) => stores.push(options),
91
+ }
92
+ );
93
+ assert.deepEqual(stores, [{ appId: '1234567890' }]);
94
+ });
@@ -0,0 +1,39 @@
1
+ // The capacitor ontology lives at https://linked.cm/ont/capacitor/, ships as Turtle, and the
2
+ // package's shapes agree with it under the shape check `linked build` runs.
3
+ import assert from 'node:assert/strict';
4
+ import test from 'node:test';
5
+
6
+ import { Prefix } from '@_linked/core/utils/Prefix';
7
+ import { definedTermsFromTurtle } from '@_linked/core/ontology/hierarchy';
8
+ import { checkShapeHierarchy } from '@_linked/core/shapes/checkShapeHierarchy';
9
+ import '@_linked/schema/shapes/index';
10
+ import * as capacitor from '../lib/esm/ontologies/capacitor.js';
11
+ import { _ontologyResource, loadData } from '../lib/esm/ontologies/capacitor.data.js';
12
+ import '../lib/esm/shapes/index.js';
13
+ import { packageName } from '../lib/esm/package.js';
14
+
15
+ const NAMESPACE = 'https://linked.cm/ont/capacitor/';
16
+
17
+ test('mints terms under https://linked.cm/ont/capacitor/ and exports only terms', () => {
18
+ assert.equal(_ontologyResource.id, NAMESPACE);
19
+ assert.equal(capacitor.LocationUpdateAction.id, `${NAMESPACE}LocationUpdateAction`);
20
+ assert.deepEqual(Object.keys(capacitor), ['LocationUpdateAction']);
21
+ assert.equal(Prefix.getFullURI('capacitor'), NAMESPACE);
22
+ });
23
+
24
+ test('declares LocationUpdateAction, a schema:UpdateAction, in its Turtle data', async () => {
25
+ const defined = await definedTermsFromTurtle(await loadData());
26
+ assert.ok(defined.has(capacitor.LocationUpdateAction.id));
27
+ });
28
+
29
+ test('passes the shape check', async () => {
30
+ const findings = await checkShapeHierarchy({
31
+ dependencies: { [packageName]: ['@_linked/core', '@_linked/schema'] },
32
+ });
33
+ assert.deepEqual(
34
+ findings
35
+ .filter((f) => f.shape?.includes('/shape/capacitor/'))
36
+ .map((f) => `${f.severity} ${f.kind}: ${f.message}`),
37
+ []
38
+ );
39
+ });