create-expo-updates-server 0.3.0 → 0.6.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.
- package/README.md +4 -2
- package/dist/template/Dockerfile +4 -6
- package/dist/template/README.md +5 -10
- package/dist/template/app/api/admin/device-favorites/route.test.ts +125 -0
- package/dist/template/app/api/admin/device-favorites/route.ts +91 -0
- package/dist/template/app/api/admin/distribution-history/restore/route.ts +39 -0
- package/dist/template/app/api/admin/distribution-history/route.test.ts +55 -0
- package/dist/template/app/api/admin/distribution-history/route.ts +24 -0
- package/dist/template/app/api/admin/updates/[encodedKey]/deactivate/route.ts +2 -1
- package/dist/template/app/api/admin/updates/[encodedKey]/promote/route.ts +2 -1
- package/dist/template/app/api/admin/updates/[encodedKey]/rollback/route.ts +2 -1
- package/dist/template/app/api/admin/updates/[encodedKey]/route.ts +2 -1
- package/dist/template/app/api/admin/updates/route.test.ts +21 -0
- package/dist/template/app/api/admin/updates/route.ts +12 -1
- package/dist/template/app/globals.css +65 -68
- package/dist/template/app/login/page.tsx +66 -42
- package/dist/template/app/updates/[encodedKey]/page.tsx +382 -248
- package/dist/template/app/updates/devices/page.tsx +187 -145
- package/dist/template/app/updates/embedded/page.tsx +80 -34
- package/dist/template/app/updates/emergency-redirects/page.tsx +138 -71
- package/dist/template/app/updates/layout.tsx +2 -1
- package/dist/template/app/updates/page.tsx +385 -274
- package/dist/template/app/updates/releases.test.tsx +156 -0
- package/dist/template/components/admin/admin-role.ts +5 -0
- package/dist/template/components/admin/admin-shell.tsx +166 -95
- package/dist/template/components/admin/confirm-action.tsx +123 -0
- package/dist/template/components/admin/language-switcher.tsx +27 -16
- package/dist/template/components/admin/release-badges.test.tsx +50 -0
- package/dist/template/components/admin/release-badges.tsx +101 -0
- package/dist/template/components/ui/alert.tsx +10 -3
- package/dist/template/components/ui/avatar.tsx +108 -0
- package/dist/template/components/ui/badge.tsx +2 -2
- package/dist/template/components/ui/breadcrumb.tsx +108 -0
- package/dist/template/components/ui/button.tsx +5 -5
- package/dist/template/components/ui/card.tsx +2 -2
- package/dist/template/components/ui/chart.tsx +1 -1
- package/dist/template/components/ui/collapsible.tsx +7 -0
- package/dist/template/components/ui/dialog.tsx +13 -4
- package/dist/template/components/ui/empty.tsx +103 -0
- package/dist/template/components/ui/field.tsx +248 -0
- package/dist/template/components/ui/input-group.tsx +170 -0
- package/dist/template/components/ui/input.tsx +1 -1
- package/dist/template/components/ui/native-select.tsx +1 -1
- package/dist/template/components/ui/radio-group.tsx +41 -0
- package/dist/template/components/ui/sheet.tsx +6 -2
- package/dist/template/components/ui/sidebar.tsx +62 -17
- package/dist/template/components/ui/status-tones.ts +15 -0
- package/dist/template/components/ui/table.tsx +1 -1
- package/dist/template/components/ui/textarea.tsx +1 -1
- package/dist/template/docs/admin-ui.md +22 -24
- package/dist/template/docs/device-targeting.md +6 -12
- package/dist/template/docs/doctor.md +2 -2
- package/dist/template/docs/expo-app-setup.md +9 -27
- package/dist/template/docs/getting-started.md +3 -4
- package/dist/template/docs/getting-started.ru.md +11 -544
- package/dist/template/docs/index.md +1 -1
- package/dist/template/docs/installation-telemetry.md +6 -12
- package/dist/template/docs/migrations/2026-10-16-manifest-identity.sql +5 -0
- package/dist/template/docs/migrations/2026-11-25-device-favorites.sql +53 -0
- package/dist/template/docs/migrations/2026-11-25-download-on-postpone.sql +5 -0
- package/dist/template/docs/migrations/2026-11-25-public-distribution-history.sql +283 -0
- package/dist/template/docs/migrations/schema.sql +349 -0
- package/dist/template/docs/npm-installer.md +3 -3
- package/dist/template/docs/operations-guide.md +9 -7
- package/dist/template/docs/ota-client-lifecycle.md +30 -68
- package/dist/template/docs/ota-emergency-recovery.md +34 -57
- package/dist/template/docs/ota-update-policy.md +9 -20
- package/dist/template/docs/ru/admin-ui.md +33 -0
- package/dist/template/docs/ru/device-targeting.md +59 -0
- package/dist/template/docs/ru/doctor.md +98 -0
- package/dist/template/docs/ru/expo-app-setup.md +497 -0
- package/dist/template/docs/ru/getting-started.md +391 -0
- package/dist/template/docs/ru/index.md +50 -0
- package/dist/template/docs/ru/installation-telemetry.md +125 -0
- package/dist/template/docs/ru/npm-installer.md +71 -0
- package/dist/template/docs/ru/operations-guide.md +322 -0
- package/dist/template/docs/ru/ota-client-lifecycle.md +162 -0
- package/dist/template/docs/ru/ota-emergency-recovery.md +108 -0
- package/dist/template/docs/ru/ota-update-policy.md +69 -0
- package/dist/template/docs/ru/publishing-npm-installer.md +49 -0
- package/dist/template/docs/ru/supabase-setup.md +120 -0
- package/dist/template/docs/uk/admin-ui.md +33 -0
- package/dist/template/docs/uk/device-targeting.md +59 -0
- package/dist/template/docs/uk/doctor.md +98 -0
- package/dist/template/docs/uk/expo-app-setup.md +497 -0
- package/dist/template/docs/uk/getting-started.md +391 -0
- package/dist/template/docs/uk/index.md +50 -0
- package/dist/template/docs/uk/installation-telemetry.md +125 -0
- package/dist/template/docs/uk/npm-installer.md +71 -0
- package/dist/template/docs/uk/operations-guide.md +322 -0
- package/dist/template/docs/uk/ota-client-lifecycle.md +162 -0
- package/dist/template/docs/uk/ota-emergency-recovery.md +108 -0
- package/dist/template/docs/uk/ota-update-policy.md +69 -0
- package/dist/template/docs/uk/publishing-npm-installer.md +49 -0
- package/dist/template/docs/uk/supabase-setup.md +120 -0
- package/dist/template/lib/audience-ids.ts +4 -0
- package/dist/template/package-lock.json +46 -0
- package/dist/template/package.json +4 -1
- package/dist/template/scripts/configure-expo-app.mjs +3 -3
- package/dist/template/scripts/create-access-token.mjs +1 -1
- package/dist/template/scripts/lib/doctor.mjs +10 -7
- package/dist/template/scripts/lib/doctor.test.mjs +7 -5
- package/dist/template/scripts/lib/embedded-update-registrar.test.ts +22 -7
- package/dist/template/scripts/lib/expo-app-configurator.mjs +25 -22
- package/dist/template/scripts/lib/expo-app-configurator.test.ts +37 -2
- package/dist/template/scripts/lib/ota-client-configurator.mjs +152 -55
- package/dist/template/scripts/lib/ota-client-configurator.test.ts +60 -20
- package/dist/template/scripts/lib/ota-client-package.mjs +25 -0
- package/dist/template/scripts/lib/ota-root-hook-patcher.mjs +90 -32
- package/dist/template/scripts/lib/ota-root-hook-patcher.test.ts +49 -6
- package/dist/template/scripts/tests/device-analytics-migrations.mjs +12 -1
- package/dist/template/scripts/tests/device-targeting-activation.mjs +2 -3
- package/dist/template/scripts/tests/e2e/client-lifecycle.mjs +161 -0
- package/dist/template/scripts/tests/e2e/client-lifecycle.scenario.jsx +465 -0
- package/dist/template/scripts/tests/e2e/client-vitest.mts +18 -0
- package/dist/template/scripts/tests/e2e/console.mjs +86 -0
- package/dist/template/scripts/tests/e2e/delivery.mjs +296 -0
- package/dist/template/scripts/tests/e2e/device-favorites.mjs +309 -0
- package/dist/template/scripts/tests/e2e/installations.mjs +132 -0
- package/dist/template/scripts/tests/e2e/policy.mjs +253 -0
- package/dist/template/scripts/tests/e2e/registrar-token.mjs +59 -0
- package/dist/template/scripts/tests/e2e/release-matrix.mjs +307 -0
- package/dist/template/scripts/tests/e2e/releases.mjs +162 -0
- package/dist/template/scripts/tests/e2e/run.mjs +224 -0
- package/dist/template/scripts/tests/manifest-identity.sql +7 -5
- package/dist/template/scripts/tests/public-distribution-history.mjs +102 -0
- package/dist/template/src/client/admin-api.ts +45 -10
- package/dist/template/src/client/admin-types.ts +35 -1
- package/dist/template/src/client/devices/analytics.tsx +169 -219
- package/dist/template/src/client/devices/cohorts.tsx +181 -0
- package/dist/template/src/client/devices/device-name.tsx +37 -21
- package/dist/template/src/client/devices/favorite-targets.tsx +381 -0
- package/dist/template/src/client/devices/registry.tsx +265 -233
- package/dist/template/src/client/devices/use-devices-report.test.tsx +98 -0
- package/dist/template/src/client/devices/use-devices-report.ts +53 -82
- package/dist/template/src/client/devices/version-adoption-chart.tsx +48 -38
- package/dist/template/src/client/distribution-control.tsx +98 -53
- package/dist/template/src/client/distribution-history.tsx +353 -0
- package/dist/template/src/client/guard-action-catalog.tsx +183 -0
- package/dist/template/src/client/guard-action-combobox.test.ts +16 -22
- package/dist/template/src/client/guard-action-combobox.tsx +134 -234
- package/dist/template/src/client/guard-action-options.ts +4 -6
- package/dist/template/src/client/i18n/en.json +335 -2
- package/dist/template/src/client/i18n/language-switching.test.tsx +233 -0
- package/dist/template/src/client/i18n/messages.test.ts +102 -19
- package/dist/template/src/client/i18n/messages.ts +31 -16
- package/dist/template/src/client/i18n/provider.tsx +6 -3
- package/dist/template/src/client/i18n/ru.json +619 -0
- package/dist/template/src/client/i18n/uk.json +619 -0
- package/dist/template/src/client/i18n/use-formatters.ts +5 -0
- package/dist/template/src/client/logout-button.tsx +3 -3
- package/dist/template/src/client/policy-draft.ts +138 -0
- package/dist/template/src/client/update-audience-editor.tsx +597 -199
- package/dist/template/src/client/update-policy-editor.test.ts +101 -29
- package/dist/template/src/client/update-policy-editor.tsx +466 -307
- package/dist/template/src/client/use-filtered-results.ts +55 -0
- package/dist/template/src/server/controllers/manifest.test.ts +23 -3
- package/dist/template/src/server/controllers/manifest.ts +15 -1
- package/dist/template/src/server/devices/audience.ts +9 -5
- package/dist/template/src/server/lib/admin-audience-activation.test.ts +37 -90
- package/dist/template/src/server/lib/admin-release-history.test.ts +138 -0
- package/dist/template/src/server/lib/admin-updates.ts +160 -534
- package/dist/template/src/server/lib/distribution-history.ts +97 -0
- package/dist/template/src/server/lib/supabase.js +24 -0
- package/dist/template/src/server/lib/supabase.test.ts +38 -1
- package/dist/template/src/server/lib/update-policy.test.ts +20 -0
- package/dist/template/src/server/lib/update-policy.ts +23 -10
- package/dist/template/src/server/manifest/manifest-repository.ts +11 -3
- package/dist/template/src/server/manifest/manifest-values.test.ts +2 -0
- package/dist/template/src/server/manifest/manifest-values.ts +21 -13
- package/dist/template/templates/expo-app/scripts/ota-publish/api/database-client.mjs +7 -30
- package/dist/template/templates/expo-app/scripts/ota-register-embedded/index.mjs +2 -1
- package/dist/template/tsconfig.json +2 -2
- package/dist/template-manifest.json +571 -271
- package/package.json +1 -1
- package/dist/template/scripts/lib/device-identity.test.ts +0 -29
- package/dist/template/scripts/lib/ota-client.test.ts +0 -55
- package/dist/template/scripts/lib/ota-update-controller.test.ts +0 -232
- package/dist/template/scripts/lib/ota-updates-ui.test.tsx +0 -154
- package/dist/template/scripts/tests/ota-client-types.mjs +0 -69
- package/dist/template/templates/expo-app/ota-client/README.md +0 -73
- package/dist/template/templates/expo-app/ota-client/controller.ts +0 -107
- package/dist/template/templates/expo-app/ota-client/device-identity.ts +0 -48
- package/dist/template/templates/expo-app/ota-client/docs/update-lifecycle.md +0 -61
- package/dist/template/templates/expo-app/ota-client/index.ts +0 -16
- package/dist/template/templates/expo-app/ota-client/model/hooks/useOtaUpdates.ts +0 -97
- package/dist/template/templates/expo-app/ota-client/model/update-controller.ts +0 -293
- package/dist/template/templates/expo-app/ota-client/runtime.ts +0 -153
- package/dist/template/templates/expo-app/ota-client/types.ts +0 -85
- package/dist/template/templates/expo-app/ota-client/ui/ota-update-gate.tsx +0 -25
- package/dist/template/templates/expo-app/ota-client/ui/ota-updates.tsx +0 -196
package/package.json
CHANGED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { createHash, randomUUID } from 'node:crypto';
|
|
3
|
-
import { createDeviceIdentity } from '../../templates/expo-app/ota-client/device-identity';
|
|
4
|
-
const digest = async (v: string) => createHash('sha256').update(v).digest('hex');
|
|
5
|
-
function options(platform = 'android', store = new Map<string, string>()) {
|
|
6
|
-
return { platform, scope: 'com.example:https://updates.example.com', androidId: () => 'abc123', digest,
|
|
7
|
-
uuid: randomUUID, readSecure: async (k: string) => store.get(k) ?? null, writeSecure: async (k: string, v: string) => { store.set(k, v); } };
|
|
8
|
-
}
|
|
9
|
-
describe('device identity independent of installation state', () => {
|
|
10
|
-
it('recognizes Android reinstalls, isolates app/server and signing identity changes', async () => {
|
|
11
|
-
const o = options(); const first = await createDeviceIdentity(o)();
|
|
12
|
-
expect(await createDeviceIdentity(options())()).toBe(first);
|
|
13
|
-
expect(await createDeviceIdentity({ ...o, scope: 'another-app' })()).not.toBe(first);
|
|
14
|
-
expect(await createDeviceIdentity({ ...o, androidId: () => 'changed-key' })()).not.toBe(first);
|
|
15
|
-
expect(first).toMatch(/^[a-f0-9]{64}$/); expect(first).not.toContain('abc123');
|
|
16
|
-
});
|
|
17
|
-
it('reuses iOS Keychain across reinstall, regenerates only when actually absent', async () => {
|
|
18
|
-
const store = new Map<string, string>(); const o = options('ios', store);
|
|
19
|
-
const first = await createDeviceIdentity(o)();
|
|
20
|
-
expect(await createDeviceIdentity(o)()).toBe(first);
|
|
21
|
-
expect(await createDeviceIdentity(options('ios'))()).not.toBe(first);
|
|
22
|
-
});
|
|
23
|
-
it('single-flights concurrent callers and retries Keychain errors without replacing the existing seed', async () => {
|
|
24
|
-
const store = new Map<string, string>(); const o = options('ios', store); let calls = 0;
|
|
25
|
-
const id = createDeviceIdentity({ ...o, readSecure: async (k: string) => { calls++; if (calls === 1) throw new Error('locked'); return o.readSecure(k); } });
|
|
26
|
-
await expect(id()).rejects.toThrow('locked');
|
|
27
|
-
const [a, b] = await Promise.all([id(), id()]); expect(a).toBe(b); expect(calls).toBe(2); expect(store.size).toBe(1);
|
|
28
|
-
});
|
|
29
|
-
});
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
-
import { createInstallationClient } from '../../templates/expo-app/ota-client/controller';
|
|
3
|
-
function fixture() {
|
|
4
|
-
let stored: string | null = null;
|
|
5
|
-
let counter = 0;
|
|
6
|
-
const send = vi.fn(async (event: { eventId: string; sequence: number }) => { void event; });
|
|
7
|
-
const write = vi.fn(async (value: string) => { stored = value; });
|
|
8
|
-
const deps = { read: async () => stored, write, uuid: () => `uuid-${++counter}`, snapshot: () => ({ updateId: 'launched' }), send, setIdentity: vi.fn(async (id: string) => { void id; }), now: () => '2026-10-19T12:00:00.000Z' };
|
|
9
|
-
return { deps, send, write, state: () => JSON.parse(stored!), client: createInstallationClient(deps) };
|
|
10
|
-
}
|
|
11
|
-
describe('durable installation client', () => {
|
|
12
|
-
it('keeps identity across controller restarts and increments sequence', async () => {
|
|
13
|
-
const f = fixture(); const id = await f.client.ready(); await f.client.observe();
|
|
14
|
-
const restarted = createInstallationClient(f.deps);
|
|
15
|
-
expect(await restarted.ready()).toBe(id); await restarted.observe();
|
|
16
|
-
expect(f.send.mock.calls.map(([e]) => e.sequence)).toEqual([1, 2]);
|
|
17
|
-
expect(f.state().pending).toBeNull();
|
|
18
|
-
});
|
|
19
|
-
it('retries the identical durable event after offline/restart', async () => {
|
|
20
|
-
const f = fixture(); f.send.mockRejectedValueOnce(new Error('offline'));
|
|
21
|
-
await expect(f.client.observe()).rejects.toThrow('offline');
|
|
22
|
-
const pending = f.state().pending;
|
|
23
|
-
await createInstallationClient(f.deps).flush();
|
|
24
|
-
expect(f.send.mock.calls[1][0]).toEqual(pending);
|
|
25
|
-
expect(f.state().pending).toBeNull();
|
|
26
|
-
});
|
|
27
|
-
it('does not send or expose ephemeral identity when storage fails', async () => {
|
|
28
|
-
const f = fixture(); f.write.mockRejectedValueOnce(new Error('disk'));
|
|
29
|
-
await expect(f.client.observe()).rejects.toThrow('disk'); expect(f.send).not.toHaveBeenCalled();
|
|
30
|
-
expect(f.deps.setIdentity).not.toHaveBeenCalled();
|
|
31
|
-
await f.client.observe(); expect(f.send).toHaveBeenCalledOnce();
|
|
32
|
-
});
|
|
33
|
-
it('never clears a newer pending event when an old request completes', async () => {
|
|
34
|
-
const f = fixture(); let resolve!: () => void;
|
|
35
|
-
f.send.mockImplementationOnce(() => new Promise<void>((r) => { resolve = r; }));
|
|
36
|
-
const first = f.client.observe();
|
|
37
|
-
await vi.waitFor(() => expect(f.send).toHaveBeenCalledOnce());
|
|
38
|
-
const second = f.client.observe();
|
|
39
|
-
await vi.waitFor(() => expect(f.state().sequence).toBe(2));
|
|
40
|
-
resolve(); await Promise.all([first, second]);
|
|
41
|
-
expect(f.state().pending.sequence).toBe(2);
|
|
42
|
-
await f.client.flush(); expect(f.send.mock.calls[1][0].sequence).toBe(2);
|
|
43
|
-
});
|
|
44
|
-
it('serializes concurrent observations with unique sequences', async () => {
|
|
45
|
-
const f = fixture(); await Promise.all(Array.from({ length: 10 }, () => f.client.observe()));
|
|
46
|
-
expect(f.state().sequence).toBe(10); await f.client.flush();
|
|
47
|
-
expect(f.state().pending).toBeNull();
|
|
48
|
-
});
|
|
49
|
-
it('does not lose the outbox when acknowledgement cannot persist', async () => {
|
|
50
|
-
const g = fixture(); let writes = 0; const original = g.deps.write;
|
|
51
|
-
const c = createInstallationClient({ ...g.deps, write: async (v: string) => { if (++writes === 3) throw new Error('ack disk'); await original(v); } });
|
|
52
|
-
await expect(c.observe()).rejects.toThrow('ack disk'); expect(g.state().pending.sequence).toBe(1);
|
|
53
|
-
await c.flush(); expect(g.send.mock.calls[0][0]).toEqual(g.send.mock.calls[1][0]);
|
|
54
|
-
});
|
|
55
|
-
});
|
|
@@ -1,232 +0,0 @@
|
|
|
1
|
-
import type { OtaCheckResult, OtaFetchResult, OtaOptions } from '../../templates/expo-app/ota-client/types';
|
|
2
|
-
import { describe, expect, it, vi } from 'vitest';
|
|
3
|
-
import { createUpdateController } from '../../templates/expo-app/ota-client/model/update-controller';
|
|
4
|
-
|
|
5
|
-
function manifest(id = 'update-a', delivery = 'manual', action?: string) {
|
|
6
|
-
return { id, extra: { updatePolicy: { schemaVersion: 1, policyVersion: 1, delivery,
|
|
7
|
-
...(action ? { guard: { action, payload: { message: 'Please update' } } } : {}) } } };
|
|
8
|
-
}
|
|
9
|
-
function fixture() {
|
|
10
|
-
let clock = 0;
|
|
11
|
-
const deps = {
|
|
12
|
-
enabled: true, start: vi.fn(),
|
|
13
|
-
identity: vi.fn(async () => ({ installationId: 'installation', deviceId: 'device' })),
|
|
14
|
-
check: vi.fn(async (): Promise<OtaCheckResult> => ({ isAvailable: true, manifest: manifest() })),
|
|
15
|
-
fetch: vi.fn(async (): Promise<OtaFetchResult> => ({ isNew: true, manifest: manifest() })),
|
|
16
|
-
reload: vi.fn(async () => undefined), openStore: vi.fn(async () => undefined),
|
|
17
|
-
isActive: vi.fn(() => true), now: () => clock,
|
|
18
|
-
};
|
|
19
|
-
const client = createUpdateController(deps);
|
|
20
|
-
const owner = Symbol('root');
|
|
21
|
-
const configure = (value: OtaOptions = {}) => client.configure(owner, value);
|
|
22
|
-
return { deps, client, configure, owner, advance: () => { clock += 60000; } };
|
|
23
|
-
}
|
|
24
|
-
function deferred<T>() {
|
|
25
|
-
let resolve!: (value: T) => void;
|
|
26
|
-
const promise = new Promise<T>(r => { resolve = r; });
|
|
27
|
-
return { promise, resolve };
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
describe('OTA lifecycle policy and operations', () => {
|
|
31
|
-
it('keeps manual checks separate from download and reload, initializing identity first', async () => {
|
|
32
|
-
const f = fixture();
|
|
33
|
-
const identity = deferred<{ installationId: string; deviceId: string }>();
|
|
34
|
-
f.deps.identity.mockReturnValue(identity.promise);
|
|
35
|
-
const checking = f.client.check();
|
|
36
|
-
await vi.waitFor(() => expect(f.deps.identity).toHaveBeenCalledOnce());
|
|
37
|
-
expect(f.deps.check).not.toHaveBeenCalled();
|
|
38
|
-
identity.resolve({ installationId: 'installation', deviceId: 'device' });
|
|
39
|
-
await checking;
|
|
40
|
-
expect(f.client.getSnapshot()).toMatchObject({ available: true, pending: false, status: 'idle' });
|
|
41
|
-
expect(f.deps.fetch).not.toHaveBeenCalled();
|
|
42
|
-
await f.client.download();
|
|
43
|
-
expect(f.client.getSnapshot()).toMatchObject({ pending: true });
|
|
44
|
-
expect(f.deps.reload).not.toHaveBeenCalled();
|
|
45
|
-
await f.client.reload();
|
|
46
|
-
expect(f.deps.reload).toHaveBeenCalledOnce();
|
|
47
|
-
});
|
|
48
|
-
it('automatically downloads and reloads manual candidates only with the requested flags', async () => {
|
|
49
|
-
const f = fixture(); f.configure({ autoUpdate: true, autoReload: true });
|
|
50
|
-
await f.client.check();
|
|
51
|
-
expect(f.deps.fetch).toHaveBeenCalledOnce(); expect(f.deps.reload).toHaveBeenCalledOnce();
|
|
52
|
-
});
|
|
53
|
-
it('does not repeat a manual fetch when the server withdrew the candidate', async () => {
|
|
54
|
-
const f = fixture();
|
|
55
|
-
await f.client.check();
|
|
56
|
-
f.configure({ autoUpdate: true, autoReload: true });
|
|
57
|
-
f.deps.fetch.mockResolvedValue({ isNew: false, isRollBackToEmbedded: false });
|
|
58
|
-
await f.client.download();
|
|
59
|
-
expect(f.deps.fetch).toHaveBeenCalledOnce();
|
|
60
|
-
expect(f.deps.reload).not.toHaveBeenCalled();
|
|
61
|
-
expect(f.client.getSnapshot().pending).toBe(false);
|
|
62
|
-
});
|
|
63
|
-
it('keeps legacy manifests without policy usable through the manual workflow', async () => {
|
|
64
|
-
const f = fixture(); f.configure({ autoReload: true });
|
|
65
|
-
f.deps.check.mockResolvedValue({ isAvailable: true, manifest: { id: 'legacy' } });
|
|
66
|
-
f.deps.fetch.mockResolvedValue({ isNew: true, manifest: { id: 'legacy' } });
|
|
67
|
-
await f.client.check();
|
|
68
|
-
expect(f.client.getSnapshot()).toMatchObject({ blocked: false, policy: null, available: true });
|
|
69
|
-
expect(f.deps.fetch).not.toHaveBeenCalled();
|
|
70
|
-
await f.client.download(); expect(f.deps.reload).toHaveBeenCalledOnce();
|
|
71
|
-
});
|
|
72
|
-
it('does not guess how to apply a future policy schema', async () => {
|
|
73
|
-
const f = fixture(); f.configure({ autoUpdate: true, autoReload: true });
|
|
74
|
-
const candidate = manifest(); candidate.extra.updatePolicy.schemaVersion = 2;
|
|
75
|
-
f.deps.check.mockResolvedValue({ isAvailable: true, manifest: candidate });
|
|
76
|
-
await f.client.check();
|
|
77
|
-
expect(f.client.getSnapshot()).toMatchObject({ blocked: true, blockReason: 'unsupported-policy' });
|
|
78
|
-
expect(f.deps.fetch).not.toHaveBeenCalled();
|
|
79
|
-
});
|
|
80
|
-
it('honors server background delivery even when autoUpdate is false and never auto-reloads it', async () => {
|
|
81
|
-
const f = fixture(); f.configure({ autoUpdate: false, autoReload: true });
|
|
82
|
-
f.deps.check.mockResolvedValue({ isAvailable: true, manifest: manifest('background', 'background') });
|
|
83
|
-
f.deps.fetch.mockResolvedValue({ isNew: true, manifest: manifest('background', 'background') });
|
|
84
|
-
await f.client.check();
|
|
85
|
-
expect(f.deps.fetch).toHaveBeenCalledOnce(); expect(f.deps.reload).not.toHaveBeenCalled();
|
|
86
|
-
expect(f.client.getSnapshot()).toMatchObject({ pending: true, blocked: false });
|
|
87
|
-
});
|
|
88
|
-
it('automatically downloads forced OTA but keeps a gate until explicitly applied', async () => {
|
|
89
|
-
const f = fixture();
|
|
90
|
-
f.deps.check.mockResolvedValue({ isAvailable: true, manifest: manifest('force', 'manual', 'ota-force-update') });
|
|
91
|
-
f.deps.fetch.mockResolvedValue({ isNew: true, manifest: manifest('force', 'manual', 'ota-force-update') });
|
|
92
|
-
await f.client.check();
|
|
93
|
-
expect(f.client.getSnapshot()).toMatchObject({ blocked: true, blockReason: 'ota-force-update', pending: true });
|
|
94
|
-
expect(f.deps.reload).not.toHaveBeenCalled();
|
|
95
|
-
await f.client.reload(); expect(f.deps.reload).toHaveBeenCalledOnce();
|
|
96
|
-
});
|
|
97
|
-
it('force-store guard cannot be bypassed by download, reload or automatic flags', async () => {
|
|
98
|
-
const f = fixture(); f.configure({ autoUpdate: true, autoReload: true });
|
|
99
|
-
f.deps.check.mockResolvedValue({ isAvailable: true, manifest: manifest('store', 'background', 'ota-force-store-update') });
|
|
100
|
-
await f.client.check();
|
|
101
|
-
expect(f.client.getSnapshot()).toMatchObject({ blocked: true, blockReason: 'ota-force-store-update' });
|
|
102
|
-
expect(f.deps.fetch).not.toHaveBeenCalled();
|
|
103
|
-
await expect(f.client.download()).rejects.toThrow('guard');
|
|
104
|
-
await expect(f.client.reload()).rejects.toThrow();
|
|
105
|
-
await f.client.openStore(); expect(f.deps.openStore).toHaveBeenCalledWith({ message: 'Please update' });
|
|
106
|
-
});
|
|
107
|
-
it('keeps unknown guards closed until an asynchronous handler explicitly allows the candidate', async () => {
|
|
108
|
-
const f = fixture(); f.configure({ autoUpdate: true });
|
|
109
|
-
f.deps.check.mockResolvedValue({ isAvailable: true, manifest: manifest('custom', 'manual', 'login') });
|
|
110
|
-
await f.client.check();
|
|
111
|
-
expect(f.client.getSnapshot()).toMatchObject({ blocked: true }); expect(f.deps.fetch).not.toHaveBeenCalled();
|
|
112
|
-
const decision = deferred<"allow" | "block">();
|
|
113
|
-
f.configure({ guardHandlers: { login: () => decision.promise } });
|
|
114
|
-
const checking = f.client.retry();
|
|
115
|
-
await vi.waitFor(() => expect(f.deps.check).toHaveBeenCalledTimes(2));
|
|
116
|
-
expect(f.client.getSnapshot()).toMatchObject({ blocked: true });
|
|
117
|
-
decision.resolve('allow'); await checking;
|
|
118
|
-
expect(f.client.getSnapshot()).toMatchObject({ blocked: false });
|
|
119
|
-
});
|
|
120
|
-
it('rechecks the fetched manifest guard if delivery changed between check and fetch', async () => {
|
|
121
|
-
const f = fixture(); f.configure({ autoUpdate: true, autoReload: true });
|
|
122
|
-
f.deps.fetch.mockResolvedValue({ isNew: true, manifest: manifest('different', 'manual', 'ota-force-store-update') });
|
|
123
|
-
await f.client.check();
|
|
124
|
-
expect(f.client.getSnapshot()).toMatchObject({ pending: true, blocked: true, blockReason: 'ota-force-store-update', candidate: { manifest: { id: 'different' } } });
|
|
125
|
-
expect(f.deps.reload).not.toHaveBeenCalled();
|
|
126
|
-
await expect(f.client.reload()).rejects.toThrow('guard');
|
|
127
|
-
});
|
|
128
|
-
it('supports rollback to embedded without expecting a manifest', async () => {
|
|
129
|
-
const f = fixture();
|
|
130
|
-
f.deps.check.mockResolvedValue({ isAvailable: false, isRollBackToEmbedded: true });
|
|
131
|
-
f.deps.fetch.mockResolvedValue({ isNew: false, isRollBackToEmbedded: true });
|
|
132
|
-
await f.client.check(); await f.client.download(); await f.client.reload();
|
|
133
|
-
expect(f.client.getSnapshot()).toMatchObject({ candidate: { type: 'rollback', manifest: null }, pending: true });
|
|
134
|
-
expect(f.deps.reload).toHaveBeenCalledOnce();
|
|
135
|
-
});
|
|
136
|
-
it('retries identity failure without performing an anonymous update check', async () => {
|
|
137
|
-
const f = fixture(); f.deps.identity.mockRejectedValueOnce(new Error('storage unavailable'));
|
|
138
|
-
await expect(f.client.check()).rejects.toThrow('storage unavailable');
|
|
139
|
-
expect(f.deps.check).not.toHaveBeenCalled();
|
|
140
|
-
await f.client.retry(); expect(f.deps.identity).toHaveBeenCalledTimes(2); expect(f.deps.check).toHaveBeenCalledOnce();
|
|
141
|
-
});
|
|
142
|
-
it('single-flights identical operations and rejects conflicting operations', async () => {
|
|
143
|
-
const f = fixture(); const response = deferred<OtaCheckResult>(); f.deps.check.mockReturnValue(response.promise);
|
|
144
|
-
const first = f.client.check(); const second = f.client.check();
|
|
145
|
-
expect(first).toBe(second);
|
|
146
|
-
await expect(f.client.download()).rejects.toThrow('in progress');
|
|
147
|
-
response.resolve({ isAvailable: true, manifest: manifest() }); await first;
|
|
148
|
-
expect(f.deps.check).toHaveBeenCalledOnce();
|
|
149
|
-
});
|
|
150
|
-
it('does not mark a failed download pending and supports retry', async () => {
|
|
151
|
-
const f = fixture(); await f.client.check(); f.deps.fetch.mockRejectedValueOnce(new Error('offline'));
|
|
152
|
-
await expect(f.client.download()).rejects.toThrow('offline');
|
|
153
|
-
expect(f.client.getSnapshot()).toMatchObject({ pending: false, status: 'idle' });
|
|
154
|
-
await f.client.download(); expect(f.client.getSnapshot()).toMatchObject({ pending: true, error: null });
|
|
155
|
-
});
|
|
156
|
-
it('never reloads while the native app is inactive', async () => {
|
|
157
|
-
const f = fixture(); await f.client.check(); await f.client.download(); f.deps.isActive.mockReturnValue(false);
|
|
158
|
-
await expect(f.client.reload()).rejects.toThrow('active'); expect(f.deps.reload).not.toHaveBeenCalled();
|
|
159
|
-
});
|
|
160
|
-
it('automatic checks require an active owner and obey the foreground throttle', async () => {
|
|
161
|
-
const f = fixture(); f.client.automaticCheck(); expect(f.deps.check).not.toHaveBeenCalled();
|
|
162
|
-
f.configure({ autoCheck: true }); f.client.automaticCheck();
|
|
163
|
-
await vi.waitFor(() => expect(f.client.getSnapshot().status).toBe('idle'));
|
|
164
|
-
expect(f.deps.check).toHaveBeenCalledOnce();
|
|
165
|
-
f.client.automaticCheck(); expect(f.deps.check).toHaveBeenCalledOnce();
|
|
166
|
-
f.advance(); f.deps.isActive.mockReturnValue(false); f.client.automaticCheck(); expect(f.deps.check).toHaveBeenCalledOnce();
|
|
167
|
-
f.deps.isActive.mockReturnValue(true); f.client.automaticCheck();
|
|
168
|
-
await vi.waitFor(() => expect(f.deps.check).toHaveBeenCalledTimes(2));
|
|
169
|
-
f.client.removeOwner(f.owner); f.advance(); f.client.automaticCheck(); expect(f.deps.check).toHaveBeenCalledTimes(2);
|
|
170
|
-
});
|
|
171
|
-
it('disabled builds never initialize native update operations', async () => {
|
|
172
|
-
const f = fixture(); const client = createUpdateController({ ...f.deps, enabled: false });
|
|
173
|
-
await client.initialize(); await expect(client.check()).rejects.toThrow('unavailable');
|
|
174
|
-
expect(f.deps.identity).not.toHaveBeenCalled(); expect(f.deps.check).not.toHaveBeenCalled();
|
|
175
|
-
});
|
|
176
|
-
it('preserves pending candidate policy when a later check returns another update', async () => {
|
|
177
|
-
const f = fixture(); await f.client.syncPending({ type: 'new', manifest: manifest('cached', 'manual', 'ota-force-store-update') });
|
|
178
|
-
await f.client.check();
|
|
179
|
-
expect(f.client.getSnapshot()).toMatchObject({ candidate: { manifest: { id: 'cached' } }, blocked: true });
|
|
180
|
-
});
|
|
181
|
-
it('re-evaluates a pending guard on retry after application conditions change', async () => {
|
|
182
|
-
const f = fixture();
|
|
183
|
-
await f.client.syncPending({ type: 'new', manifest: manifest('cached', 'manual', 'login') });
|
|
184
|
-
f.configure({ guardHandlers: { login: async () => 'allow' as const } });
|
|
185
|
-
await f.client.retry();
|
|
186
|
-
expect(f.client.getSnapshot()).toMatchObject({ candidate: { manifest: { id: 'cached' } }, pending: true, blocked: false });
|
|
187
|
-
});
|
|
188
|
-
it('ignores an old native pending snapshot queued while a newer download completes', async () => {
|
|
189
|
-
const f = fixture(); await f.client.check();
|
|
190
|
-
const fetched = deferred<OtaFetchResult>(); f.deps.fetch.mockReturnValue(fetched.promise);
|
|
191
|
-
const downloading = f.client.download();
|
|
192
|
-
await vi.waitFor(() => expect(f.deps.fetch).toHaveBeenCalledOnce());
|
|
193
|
-
const syncing = f.client.syncPending({ type: 'new', manifest: manifest('old') });
|
|
194
|
-
fetched.resolve({ isNew: true, manifest: manifest('latest', 'manual', 'ota-force-store-update') });
|
|
195
|
-
await Promise.all([downloading, syncing]);
|
|
196
|
-
expect(f.client.getSnapshot()).toMatchObject({ candidate: { manifest: { id: 'latest' } }, blocked: true, blockReason: 'ota-force-store-update' });
|
|
197
|
-
});
|
|
198
|
-
it('preserves force-store policy after the cached bundle cold-starts with no new update', async () => {
|
|
199
|
-
const f = fixture(); f.deps.check.mockResolvedValue({ isAvailable: false });
|
|
200
|
-
const client = createUpdateController({ ...f.deps, runningCandidate: () => ({ type: 'new', manifest: manifest('running', 'manual', 'ota-force-store-update') }) });
|
|
201
|
-
await client.initialize();
|
|
202
|
-
expect(client.getSnapshot()).toMatchObject({ blocked: true, blockReason: 'ota-force-store-update', pending: false });
|
|
203
|
-
await client.check();
|
|
204
|
-
expect(client.getSnapshot()).toMatchObject({ blocked: true, blockReason: 'ota-force-store-update', available: false });
|
|
205
|
-
expect(f.deps.fetch).not.toHaveBeenCalled();
|
|
206
|
-
});
|
|
207
|
-
it('updates policy when a later native download replaces the pending bundle outside this controller', async () => {
|
|
208
|
-
const f = fixture();
|
|
209
|
-
await f.client.syncPending({ type: 'new', manifest: manifest('old') });
|
|
210
|
-
await f.client.syncPending({ type: 'new', manifest: manifest('new-native-download', 'manual', 'ota-force-store-update') });
|
|
211
|
-
expect(f.client.getSnapshot()).toMatchObject({ candidate: { manifest: { id: 'new-native-download' } }, blocked: true, blockReason: 'ota-force-store-update' });
|
|
212
|
-
await expect(f.client.reload()).rejects.toThrow('guard');
|
|
213
|
-
expect(f.deps.reload).not.toHaveBeenCalled();
|
|
214
|
-
});
|
|
215
|
-
it('does not force a second OTA installation for an already running force-OTA bundle', async () => {
|
|
216
|
-
const f = fixture(); f.deps.check.mockResolvedValue({ isAvailable: false });
|
|
217
|
-
const client = createUpdateController({ ...f.deps, runningCandidate: () => ({ type: 'new', manifest: manifest('running', 'manual', 'ota-force-update') }) });
|
|
218
|
-
await client.initialize(); await client.check();
|
|
219
|
-
expect(client.getSnapshot()).toMatchObject({ blocked: false, pending: false, available: false });
|
|
220
|
-
expect(f.deps.fetch).not.toHaveBeenCalled();
|
|
221
|
-
});
|
|
222
|
-
it('evaluates a running custom guard using the application handler', async () => {
|
|
223
|
-
const f = fixture(); f.deps.check.mockResolvedValue({ isAvailable: false });
|
|
224
|
-
const client = createUpdateController({ ...f.deps, runningCandidate: () => ({ type: 'new', manifest: manifest('running', 'manual', 'login') }) });
|
|
225
|
-
await client.initialize(); expect(client.getSnapshot()).toMatchObject({ blocked: true, blockReason: 'login' });
|
|
226
|
-
const handler = vi.fn(async () => 'allow' as const);
|
|
227
|
-
client.configure(f.owner, { guardHandlers: { login: handler } });
|
|
228
|
-
await client.check();
|
|
229
|
-
expect(handler).toHaveBeenCalledWith(expect.objectContaining({ action: 'login', manifest: expect.objectContaining({ id: 'running' }) }));
|
|
230
|
-
expect(client.getSnapshot()).toMatchObject({ blocked: false, available: false });
|
|
231
|
-
});
|
|
232
|
-
});
|
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
// @vitest-environment jsdom
|
|
2
|
-
import { act } from "react";
|
|
3
|
-
import { createRoot, type Root } from "react-dom/client";
|
|
4
|
-
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
5
|
-
import type { OtaController } from "../../templates/expo-app/ota-client/types";
|
|
6
|
-
import { OtaUpdates } from "../../templates/expo-app/ota-client/ui/ota-updates";
|
|
7
|
-
|
|
8
|
-
const mocked = vi.hoisted(() => ({ hook: vi.fn() }));
|
|
9
|
-
vi.mock(
|
|
10
|
-
"../../templates/expo-app/ota-client/model/hooks/useOtaUpdates",
|
|
11
|
-
() => ({ useOtaUpdates: mocked.hook }),
|
|
12
|
-
);
|
|
13
|
-
|
|
14
|
-
let root: Root;
|
|
15
|
-
let container: HTMLDivElement;
|
|
16
|
-
let controller: OtaController;
|
|
17
|
-
beforeEach(() => {
|
|
18
|
-
Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true });
|
|
19
|
-
container = document.createElement("div");
|
|
20
|
-
document.body.append(container);
|
|
21
|
-
root = createRoot(container);
|
|
22
|
-
controller = {
|
|
23
|
-
enabled: true,
|
|
24
|
-
status: "idle",
|
|
25
|
-
installationId: "installation",
|
|
26
|
-
deviceId: "device",
|
|
27
|
-
available: true,
|
|
28
|
-
pending: false,
|
|
29
|
-
candidate: { type: "new", manifest: { id: "a" } },
|
|
30
|
-
policy: { schemaVersion: 1, delivery: "manual" },
|
|
31
|
-
blocked: false,
|
|
32
|
-
blockReason: null,
|
|
33
|
-
error: null,
|
|
34
|
-
isBusy: false,
|
|
35
|
-
check: vi.fn(async () => ({ isAvailable: true })),
|
|
36
|
-
download: vi.fn(async () => ({ isNew: true })),
|
|
37
|
-
reload: vi.fn(async () => {}),
|
|
38
|
-
retry: vi.fn(async () => ({ isAvailable: true })),
|
|
39
|
-
openStore: vi.fn(async () => {}),
|
|
40
|
-
};
|
|
41
|
-
mocked.hook.mockImplementation(() => controller);
|
|
42
|
-
});
|
|
43
|
-
afterEach(async () => {
|
|
44
|
-
await act(async () => root.unmount());
|
|
45
|
-
container.remove();
|
|
46
|
-
vi.clearAllMocks();
|
|
47
|
-
});
|
|
48
|
-
async function render() {
|
|
49
|
-
await act(async () =>
|
|
50
|
-
root.render(
|
|
51
|
-
<>
|
|
52
|
-
<div>Application tabs</div>
|
|
53
|
-
<OtaUpdates />
|
|
54
|
-
</>,
|
|
55
|
-
),
|
|
56
|
-
);
|
|
57
|
-
}
|
|
58
|
-
async function click(label: string) {
|
|
59
|
-
const button = [...container.querySelectorAll("button")].find(
|
|
60
|
-
(element) => element.textContent === label,
|
|
61
|
-
);
|
|
62
|
-
expect(button).toBeDefined();
|
|
63
|
-
await act(async () => button!.click());
|
|
64
|
-
}
|
|
65
|
-
describe("standalone OTA updates UI", () => {
|
|
66
|
-
it("offers manual download with autoUpdate false, then restart, without wrapping navigation", async () => {
|
|
67
|
-
await render();
|
|
68
|
-
expect(mocked.hook).toHaveBeenCalledWith(
|
|
69
|
-
expect.objectContaining({
|
|
70
|
-
autoCheck: true,
|
|
71
|
-
autoUpdate: false,
|
|
72
|
-
autoReload: false,
|
|
73
|
-
}),
|
|
74
|
-
);
|
|
75
|
-
expect(container.textContent).toContain("Update available");
|
|
76
|
-
expect(container.querySelector("[role=dialog]")?.textContent).not.toContain(
|
|
77
|
-
"Application tabs",
|
|
78
|
-
);
|
|
79
|
-
await click("Download");
|
|
80
|
-
expect(controller.download).toHaveBeenCalledOnce();
|
|
81
|
-
controller = { ...controller, pending: true };
|
|
82
|
-
await render();
|
|
83
|
-
await click("Restart");
|
|
84
|
-
expect(controller.reload).toHaveBeenCalledOnce();
|
|
85
|
-
});
|
|
86
|
-
it("dismisses an optional candidate until another candidate arrives", async () => {
|
|
87
|
-
await render();
|
|
88
|
-
await click("Later");
|
|
89
|
-
expect(container.querySelector("[role=dialog]")).toBeNull();
|
|
90
|
-
await render();
|
|
91
|
-
expect(container.querySelector("[role=dialog]")).toBeNull();
|
|
92
|
-
controller = {
|
|
93
|
-
...controller,
|
|
94
|
-
candidate: { type: "new", manifest: { id: "b" } },
|
|
95
|
-
};
|
|
96
|
-
await render();
|
|
97
|
-
expect(container.querySelector("[role=dialog]")).not.toBeNull();
|
|
98
|
-
});
|
|
99
|
-
it("keeps background updates silent, even after download", async () => {
|
|
100
|
-
controller = {
|
|
101
|
-
...controller,
|
|
102
|
-
pending: true,
|
|
103
|
-
policy: { schemaVersion: 1, delivery: "background" },
|
|
104
|
-
};
|
|
105
|
-
await render();
|
|
106
|
-
expect(container.querySelector("[role=dialog]")).toBeNull();
|
|
107
|
-
});
|
|
108
|
-
it("does not allow dismissing required updates, even for a previously dismissed candidate", async () => {
|
|
109
|
-
await render();
|
|
110
|
-
await click("Later");
|
|
111
|
-
controller = {
|
|
112
|
-
...controller,
|
|
113
|
-
blocked: true,
|
|
114
|
-
blockReason: "ota-force-update",
|
|
115
|
-
pending: true,
|
|
116
|
-
};
|
|
117
|
-
await render();
|
|
118
|
-
expect(container.textContent).toContain("Update required");
|
|
119
|
-
expect(container.textContent).not.toContain("Later");
|
|
120
|
-
await act(async () =>
|
|
121
|
-
container
|
|
122
|
-
.querySelector("[role=dialog]")!
|
|
123
|
-
.dispatchEvent(
|
|
124
|
-
new KeyboardEvent("keydown", { key: "Escape", bubbles: true }),
|
|
125
|
-
),
|
|
126
|
-
);
|
|
127
|
-
expect(container.querySelector("[role=dialog]")).not.toBeNull();
|
|
128
|
-
await click("Restart");
|
|
129
|
-
expect(controller.reload).toHaveBeenCalledOnce();
|
|
130
|
-
});
|
|
131
|
-
it("routes store guards to the store instead of download", async () => {
|
|
132
|
-
controller = {
|
|
133
|
-
...controller,
|
|
134
|
-
blocked: true,
|
|
135
|
-
blockReason: "ota-force-store-update",
|
|
136
|
-
};
|
|
137
|
-
await render();
|
|
138
|
-
await click("Open store");
|
|
139
|
-
expect(controller.openStore).toHaveBeenCalledOnce();
|
|
140
|
-
expect(controller.download).not.toHaveBeenCalled();
|
|
141
|
-
});
|
|
142
|
-
it("leaves unknown guards blocked and disables operations while busy", async () => {
|
|
143
|
-
controller = {
|
|
144
|
-
...controller,
|
|
145
|
-
blocked: true,
|
|
146
|
-
blockReason: "custom",
|
|
147
|
-
isBusy: true,
|
|
148
|
-
};
|
|
149
|
-
await render();
|
|
150
|
-
expect(container.textContent).toContain("Update needs attention");
|
|
151
|
-
expect(container.querySelector("button")?.disabled).toBe(true);
|
|
152
|
-
expect(container.textContent).not.toContain("Later");
|
|
153
|
-
});
|
|
154
|
-
});
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { cp, mkdtemp, writeFile, symlink, rm } from "node:fs/promises";
|
|
2
|
-
import { createRequire } from "node:module";
|
|
3
|
-
import { spawnSync } from "node:child_process";
|
|
4
|
-
import os from "node:os";
|
|
5
|
-
import path from "node:path";
|
|
6
|
-
import { fileURLToPath } from "node:url";
|
|
7
|
-
|
|
8
|
-
// Check the generated source against the target application's actual Expo/RN types.
|
|
9
|
-
const app = process.argv[2];
|
|
10
|
-
if (!app)
|
|
11
|
-
throw new Error(
|
|
12
|
-
"Usage: node scripts/tests/ota-client-types.mjs /path/to/expo-app",
|
|
13
|
-
);
|
|
14
|
-
const require = createRequire(path.resolve(app, "package.json"));
|
|
15
|
-
const temp = await mkdtemp(path.join(os.tmpdir(), "ota-client-types-"));
|
|
16
|
-
try {
|
|
17
|
-
const template = fileURLToPath(
|
|
18
|
-
new URL("../../templates/expo-app/ota-client", import.meta.url),
|
|
19
|
-
);
|
|
20
|
-
await cp(template, path.join(temp, "ota-client"), { recursive: true });
|
|
21
|
-
await symlink(
|
|
22
|
-
path.resolve(app, "node_modules"),
|
|
23
|
-
path.join(temp, "node_modules"),
|
|
24
|
-
"dir",
|
|
25
|
-
);
|
|
26
|
-
await writeFile(
|
|
27
|
-
path.join(temp, "ota-client/config.json"),
|
|
28
|
-
JSON.stringify({
|
|
29
|
-
channel: "test",
|
|
30
|
-
identityNamespace: "test",
|
|
31
|
-
heartbeatUrl: "https://example.org/api/device-heartbeat",
|
|
32
|
-
}),
|
|
33
|
-
);
|
|
34
|
-
await writeFile(
|
|
35
|
-
path.join(temp, "tsconfig.json"),
|
|
36
|
-
JSON.stringify({
|
|
37
|
-
compilerOptions: {
|
|
38
|
-
strict: true,
|
|
39
|
-
noEmit: true,
|
|
40
|
-
target: "ES2022",
|
|
41
|
-
module: "ESNext",
|
|
42
|
-
moduleResolution: "bundler",
|
|
43
|
-
jsx: "react-jsx",
|
|
44
|
-
esModuleInterop: true,
|
|
45
|
-
skipLibCheck: true,
|
|
46
|
-
resolveJsonModule: true,
|
|
47
|
-
types: ["react", "react-native"],
|
|
48
|
-
},
|
|
49
|
-
include: ["ota-client/**/*"],
|
|
50
|
-
}),
|
|
51
|
-
);
|
|
52
|
-
const result = spawnSync(
|
|
53
|
-
process.execPath,
|
|
54
|
-
[
|
|
55
|
-
require.resolve("typescript/bin/tsc"),
|
|
56
|
-
"--project",
|
|
57
|
-
path.join(temp, "tsconfig.json"),
|
|
58
|
-
],
|
|
59
|
-
{ stdio: "inherit" },
|
|
60
|
-
);
|
|
61
|
-
if (result.error) throw result.error;
|
|
62
|
-
if (result.status !== 0)
|
|
63
|
-
throw new Error("Generated OTA client typecheck failed.");
|
|
64
|
-
console.log(
|
|
65
|
-
"Generated OTA client passed strict TypeScript with the application dependencies.",
|
|
66
|
-
);
|
|
67
|
-
} finally {
|
|
68
|
-
await rm(temp, { recursive: true, force: true });
|
|
69
|
-
}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
# Installation telemetry client
|
|
2
|
-
|
|
3
|
-
Generated by `configure-app`; update the server template and rerun configuration to upgrade it.
|
|
4
|
-
Build and install a new native binary when first adding this client: it requires
|
|
5
|
-
expo-updates, expo-application, expo-crypto, expo-secure-store and AsyncStorage. Do not deliver newly
|
|
6
|
-
required native modules to an older binary via OTA. Keep these native dependencies
|
|
7
|
-
in the same runtime compatibility boundary as the rest of your application.
|
|
8
|
-
|
|
9
|
-
`ota-entry.js` starts telemetry without waiting, then synchronously loads the original
|
|
10
|
-
entry saved in `ota-client-entry.json`. The configurator also patches the root layout with the standalone OtaUpdates component. Development,
|
|
11
|
-
Expo Go, web and disabled-updates builds do not report. Original OTA check policy
|
|
12
|
-
remains under the application/configurator's control.
|
|
13
|
-
|
|
14
|
-
The public API exports `start()`, `getInstallationId()`, `checkForUpdateAsync()` and
|
|
15
|
-
`fetchUpdateAsync()`. The latter two wait for durable identity and the installation_id
|
|
16
|
-
Expo extra parameter. Direct Expo calls at module startup do not have this guarantee.
|
|
17
|
-
Telemetry failure never waits on network before returning identity.
|
|
18
|
-
|
|
19
|
-
State is a single AsyncStorage envelope: installation ID, increasing sequence and
|
|
20
|
-
one pending event. Writes/acks serialize; network requests have an 8-second timeout.
|
|
21
|
-
Startup and active foreground report the current launch; active timers refresh no
|
|
22
|
-
more often than once per minute. Failures retry with capped backoff (up to 5 minutes).
|
|
23
|
-
One latest pending snapshot bounds offline storage; it is not an exhaustive offline
|
|
24
|
-
transition history. Only accepted receipts refresh server last-seen time.
|
|
25
|
-
|
|
26
|
-
The ID identifies an installation, not a person or a permanent physical device.
|
|
27
|
-
Clearing app data/reinstallation may change it; OS backup/restore may copy it. Never
|
|
28
|
-
use this self-reported ID as authorization. No admin/database/storage secrets belong
|
|
29
|
-
in this directory. Heartbeat indicates JS startup, not successful smoke testing.
|
|
30
|
-
|
|
31
|
-
## Device-targeted releases
|
|
32
|
-
|
|
33
|
-
The entry bootstrap also initializes a separate Device ID automatically. Android uses a
|
|
34
|
-
SHA-256 hash of app-scoped Android ID; iOS uses a random seed in SecureStore/Keychain.
|
|
35
|
-
Both are scoped to application ID and `config.json.identityNamespace`. Keep that namespace
|
|
36
|
-
stable when changing tunnel URLs. Runtime/channel changes do not change Device ID.
|
|
37
|
-
Installation ID still changes on reinstall and remains the unit of telemetry.
|
|
38
|
-
|
|
39
|
-
Device ID may survive reinstalls, but is not guaranteed across factory reset, signing key
|
|
40
|
-
changes or iOS Keychain deletion. Raw Android IDs never leave the device. If identity is
|
|
41
|
-
unavailable, the server only offers public or explicitly installation-targeted releases.
|
|
42
|
-
|
|
43
|
-
`getDeviceId()` is optional for displaying diagnostics. `start()` is already called by the
|
|
44
|
-
generated entry; telemetry works independently of the root hook. Custom check/download UI should use the
|
|
45
|
-
exports here, which await identity initialization before calling Expo. Direct Expo calls
|
|
46
|
-
made too early are anonymous. Rebuild the native app with a new runtime after adding
|
|
47
|
-
SecureStore; do not deliver this client to older binaries lacking the native dependency.
|
|
48
|
-
|
|
49
|
-
## Update hook
|
|
50
|
-
|
|
51
|
-
`useOtaUpdates` shares identity, state and lifecycle actions across the application.
|
|
52
|
-
The configurator renders `<OtaUpdates />` beside navigation. It calls the hook
|
|
53
|
-
internally, shows optional download/restart prompts, and blocks required updates.
|
|
54
|
-
The generated implementation uses TypeScript and JSX, with no context wrapper.
|
|
55
|
-
See [Update lifecycle](./docs/update-lifecycle.md) for manual/automatic/background
|
|
56
|
-
updates, force OTA versus store upgrades, custom guards and option defaults.
|
|
57
|
-
|
|
58
|
-
For a custom root that could not be patched, see the complete
|
|
59
|
-
[manual integration guide](https://tonichiga.github.io/expo-updates-server/ota-client-lifecycle#manual-integration)
|
|
60
|
-
(or `docs/ota-client-lifecycle.md` in the server repository). It covers both an
|
|
61
|
-
already generated client and copying/configuring the client without the generator.
|
|
62
|
-
|
|
63
|
-
## Type checking
|
|
64
|
-
|
|
65
|
-
Run `npx tsc --noEmit` in the Expo application. The server itself does not depend
|
|
66
|
-
on React Native. Maintainers can check the template against an application's
|
|
67
|
-
installed Expo dependencies without changing that application:
|
|
68
|
-
|
|
69
|
-
```bash
|
|
70
|
-
node scripts/tests/ota-client-types.mjs /path/to/expo-app
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
Run that command from the server repository.
|