create-expo-updates-server 0.1.5 → 0.2.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/dist/template/.dockerignore +16 -0
- package/dist/template/README.md +51 -660
- package/dist/template/app/api/admin/device-targets/route.test.ts +43 -0
- package/dist/template/app/api/admin/device-targets/route.ts +91 -0
- package/dist/template/app/api/admin/devices/route.test.ts +41 -0
- package/dist/template/app/api/admin/devices/route.ts +15 -0
- package/dist/template/app/api/admin/updates/[encodedKey]/audience/route.ts +75 -0
- package/dist/template/app/api/device-heartbeat/route.ts +2 -0
- package/dist/template/app/globals.css +114 -15
- package/dist/template/app/layout.tsx +12 -4
- package/dist/template/app/login/page.tsx +22 -18
- package/dist/template/app/updates/[encodedKey]/page.tsx +112 -88
- package/dist/template/app/updates/devices/page.tsx +264 -0
- package/dist/template/app/updates/embedded/page.tsx +102 -68
- package/dist/template/app/updates/emergency-redirects/page.tsx +144 -111
- package/dist/template/app/updates/layout.tsx +6 -1
- package/dist/template/app/updates/page.tsx +262 -212
- package/dist/template/components/admin/admin-shell.tsx +196 -0
- package/dist/template/components/admin/language-switcher.tsx +25 -0
- package/dist/template/components/admin/theme-provider.tsx +15 -0
- package/dist/template/components/ui/alert.tsx +65 -0
- package/dist/template/components/ui/badge.tsx +47 -0
- package/dist/template/components/ui/button.tsx +63 -0
- package/dist/template/components/ui/card.tsx +91 -0
- package/dist/template/components/ui/chart.tsx +373 -0
- package/dist/template/components/ui/checkbox.tsx +31 -0
- package/dist/template/components/ui/dialog.tsx +158 -0
- package/dist/template/components/ui/dropdown-menu.tsx +256 -0
- package/dist/template/components/ui/input.tsx +20 -0
- package/dist/template/components/ui/label.tsx +23 -0
- package/dist/template/components/ui/native-select.tsx +61 -0
- package/dist/template/components/ui/popover.tsx +88 -0
- package/dist/template/components/ui/scroll-area.tsx +57 -0
- package/dist/template/components/ui/select.tsx +189 -0
- package/dist/template/components/ui/separator.tsx +27 -0
- package/dist/template/components/ui/sheet.tsx +142 -0
- package/dist/template/components/ui/sidebar.tsx +736 -0
- package/dist/template/components/ui/skeleton.tsx +13 -0
- package/dist/template/components/ui/switch.tsx +34 -0
- package/dist/template/components/ui/table.tsx +115 -0
- package/dist/template/components/ui/tabs.tsx +90 -0
- package/dist/template/components/ui/textarea.tsx +17 -0
- package/dist/template/components/ui/tooltip.tsx +56 -0
- package/dist/template/components.json +22 -0
- package/dist/template/docs/admin-ui.md +35 -0
- package/dist/template/docs/device-targeting.md +129 -0
- package/dist/template/docs/doctor.md +137 -0
- package/dist/template/docs/expo-app-setup.md +174 -47
- package/dist/template/docs/getting-started.md +105 -146
- package/dist/template/docs/getting-started.ru.md +106 -191
- package/dist/template/docs/index.md +14 -33
- package/dist/template/docs/installation-telemetry.md +233 -0
- package/dist/template/docs/migrations/2026-10-16-manifest-identity.sql +89 -0
- package/dist/template/docs/migrations/2026-10-19-device-heartbeat.sql +131 -0
- package/dist/template/docs/migrations/2026-10-22-device-analytics.sql +264 -0
- package/dist/template/docs/migrations/2026-10-22-device-targeting-activation.sql +108 -0
- package/dist/template/docs/migrations/2026-10-22-device-targeting.sql +130 -0
- package/dist/template/docs/migrations/2026-10-22-device-version-metadata.sql +154 -0
- package/dist/template/docs/migrations/schema.sql +868 -6
- package/dist/template/docs/npm-installer.md +15 -30
- package/dist/template/docs/operations-guide.md +87 -0
- package/dist/template/docs/ota-client-lifecycle.md +263 -0
- package/dist/template/docs/ota-update-policy.md +36 -2
- package/dist/template/docs/supabase-setup.md +4 -0
- package/dist/template/hooks/use-mobile.ts +21 -0
- package/dist/template/lib/utils.ts +6 -0
- package/dist/template/package-lock.json +2325 -101
- package/dist/template/package.json +13 -3
- package/dist/template/scripts/configure-expo-app.mjs +11 -15
- package/dist/template/scripts/doctor.mjs +51 -0
- package/dist/template/scripts/ensure-test-bucket.mjs +21 -0
- package/dist/template/scripts/lib/device-identity.test.ts +29 -0
- package/dist/template/scripts/lib/doctor-probes.mjs +139 -0
- package/dist/template/scripts/lib/doctor.mjs +208 -0
- package/dist/template/scripts/lib/doctor.test.mjs +262 -0
- package/dist/template/scripts/lib/expo-app-configurator.mjs +14 -9
- package/dist/template/scripts/lib/expo-app-configurator.test.ts +3 -2
- package/dist/template/scripts/lib/ota-client-configurator.mjs +69 -0
- package/dist/template/scripts/lib/ota-client-configurator.test.ts +88 -0
- package/dist/template/scripts/lib/ota-client.test.ts +55 -0
- package/dist/template/scripts/lib/ota-root-hook-patcher.mjs +173 -0
- package/dist/template/scripts/lib/ota-root-hook-patcher.test.ts +123 -0
- package/dist/template/scripts/lib/ota-update-controller.test.ts +231 -0
- package/dist/template/scripts/tests/device-analytics-migrations.mjs +80 -0
- package/dist/template/scripts/tests/device-analytics.mjs +126 -0
- package/dist/template/scripts/tests/device-heartbeat.mjs +86 -0
- package/dist/template/scripts/tests/device-targeting-activation.mjs +111 -0
- package/dist/template/scripts/tests/device-targeting.mjs +39 -0
- package/dist/template/scripts/tests/device-version-metadata.mjs +31 -0
- package/dist/template/scripts/tests/manifest-identity-concurrency.mjs +106 -0
- package/dist/template/scripts/tests/manifest-identity.sql +204 -0
- package/dist/template/src/client/admin-types.ts +1 -0
- package/dist/template/src/client/devices/analytics.tsx +429 -0
- package/dist/template/src/client/devices/device-name.tsx +82 -0
- package/dist/template/src/client/devices/registry.tsx +399 -0
- package/dist/template/src/client/devices/use-devices-report.ts +108 -0
- package/dist/template/src/client/devices/version-adoption-chart.tsx +269 -0
- package/dist/template/src/client/devices/version-groups.test.ts +57 -0
- package/dist/template/src/client/devices/version-groups.ts +101 -0
- package/dist/template/src/client/distribution-control.tsx +135 -81
- package/dist/template/src/client/guard-action-combobox.tsx +13 -24
- package/dist/template/src/client/i18n/en.json +286 -0
- package/dist/template/src/client/i18n/messages.test.ts +42 -0
- package/dist/template/src/client/i18n/messages.ts +31 -0
- package/dist/template/src/client/i18n/provider.tsx +55 -0
- package/dist/template/src/client/i18n/use-formatters.ts +38 -0
- package/dist/template/src/client/logout-button.tsx +3 -1
- package/dist/template/src/client/update-audience-editor.tsx +285 -0
- package/dist/template/src/client/update-policy-editor.tsx +53 -41
- package/dist/template/src/server/controllers/manifest.test.ts +250 -7
- package/dist/template/src/server/controllers/manifest.ts +39 -31
- package/dist/template/src/server/devices/audience.test.ts +48 -0
- package/dist/template/src/server/devices/audience.ts +86 -0
- package/dist/template/src/server/devices/heartbeat.test.ts +39 -0
- package/dist/template/src/server/devices/heartbeat.ts +75 -0
- package/dist/template/src/server/devices/report-types.ts +114 -0
- package/dist/template/src/server/devices/report.test.ts +29 -0
- package/dist/template/src/server/devices/report.ts +27 -0
- package/dist/template/src/server/lib/admin-audience-activation.test.ts +94 -0
- package/dist/template/src/server/lib/admin-updates.ts +32 -168
- package/dist/template/src/server/lib/distribution-control.test.ts +23 -2
- package/dist/template/src/server/lib/distribution-control.ts +13 -4
- package/dist/template/src/server/lib/supabase.js +10 -10
- package/dist/template/src/server/lib/supabase.test.ts +11 -0
- package/dist/template/src/server/manifest/manifest-identity.test.ts +30 -0
- package/dist/template/src/server/manifest/manifest-identity.ts +24 -0
- package/dist/template/src/server/manifest/manifest-repository.ts +31 -102
- package/dist/template/src/server/manifest/manifest-response.ts +1 -1
- package/dist/template/templates/expo-app/ota-client/README.md +59 -0
- package/dist/template/templates/expo-app/ota-client/controller.js +60 -0
- package/dist/template/templates/expo-app/ota-client/device-identity.js +26 -0
- package/dist/template/templates/expo-app/ota-client/docs/update-lifecycle.md +52 -0
- package/dist/template/templates/expo-app/ota-client/index.d.ts +47 -0
- package/dist/template/templates/expo-app/ota-client/index.js +3 -0
- package/dist/template/templates/expo-app/ota-client/model/hooks/useOtaUpdates.js +48 -0
- package/dist/template/templates/expo-app/ota-client/model/update-controller.js +182 -0
- package/dist/template/templates/expo-app/ota-client/runtime.js +112 -0
- package/dist/template/templates/expo-app/ota-client/ui/ota-update-gate.js +56 -0
- package/dist/template-manifest.json +582 -77
- package/lib/cli.mjs +4 -6
- package/package.json +1 -1
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { NextRequest, NextResponse } from "next/server";
|
|
3
|
+
const mocks = vi.hoisted(() => ({ session: vi.fn(), from: vi.fn(), eq: vi.fn(), single: vi.fn() }));
|
|
4
|
+
vi.mock("@/src/server/lib/admin-api", () => ({ requireAdminSession: mocks.session }));
|
|
5
|
+
vi.mock("@/src/server/lib/supabase.js", () => ({ supabase: { from: mocks.from } }));
|
|
6
|
+
import { GET } from "./route";
|
|
7
|
+
const deviceId = "a".repeat(64);
|
|
8
|
+
const request = (id = deviceId) => new NextRequest(`http://test/api/admin/device-targets?platform=android&deviceId=${id}`);
|
|
9
|
+
|
|
10
|
+
describe("exact device name lookup", () => {
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
vi.clearAllMocks();
|
|
13
|
+
mocks.session.mockResolvedValue({ role: "viewer" });
|
|
14
|
+
mocks.from.mockReturnValue({ select: () => ({ eq: mocks.eq }) });
|
|
15
|
+
mocks.eq.mockReturnValue({ maybeSingle: mocks.single });
|
|
16
|
+
mocks.single.mockResolvedValue({ data: { device_id: deviceId, name: "My old phone" }, error: null });
|
|
17
|
+
});
|
|
18
|
+
it("retrieves a named device without requiring it in the recent installation list", async () => {
|
|
19
|
+
const response = await GET(request());
|
|
20
|
+
expect(response.status).toBe(200);
|
|
21
|
+
expect(response.headers.get("cache-control")).toBe("no-store");
|
|
22
|
+
expect(await response.json()).toEqual({ deviceId, name: "My old phone" });
|
|
23
|
+
expect(mocks.from).toHaveBeenCalledExactlyOnceWith("ota_named_devices");
|
|
24
|
+
expect(mocks.eq).toHaveBeenCalledWith("device_id", deviceId);
|
|
25
|
+
});
|
|
26
|
+
it("distinguishes an unnamed device from an unavailable database", async () => {
|
|
27
|
+
mocks.single.mockResolvedValueOnce({ data: null, error: null });
|
|
28
|
+
expect(await (await GET(request())).json()).toEqual({ deviceId, name: null });
|
|
29
|
+
mocks.single.mockResolvedValueOnce({ data: null, error: { message: "sensitive database detail" } });
|
|
30
|
+
const response = await GET(request());
|
|
31
|
+
expect(response.status).toBe(503);
|
|
32
|
+
expect(await response.json()).toEqual({ error: "Device name unavailable" });
|
|
33
|
+
});
|
|
34
|
+
it("rejects malformed IDs before querying the database", async () => {
|
|
35
|
+
expect((await GET(request("invalid"))).status).toBe(400);
|
|
36
|
+
expect(mocks.from).not.toHaveBeenCalled();
|
|
37
|
+
});
|
|
38
|
+
it("requires a session before revealing a name", async () => {
|
|
39
|
+
mocks.session.mockResolvedValue(NextResponse.json({ error: "Unauthorized" }, { status: 401 }));
|
|
40
|
+
expect((await GET(request())).status).toBe(401);
|
|
41
|
+
expect(mocks.from).not.toHaveBeenCalled();
|
|
42
|
+
});
|
|
43
|
+
});
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { NextRequest, NextResponse } from "next/server";
|
|
2
|
+
import { requireAdminSession } from "@/src/server/lib/admin-api";
|
|
3
|
+
import { supabase } from "@/src/server/lib/supabase.js";
|
|
4
|
+
import { deviceIdPattern } from "@/src/server/devices/audience";
|
|
5
|
+
|
|
6
|
+
export async function GET(request: NextRequest) {
|
|
7
|
+
const access = await requireAdminSession(request);
|
|
8
|
+
if (access instanceof NextResponse) return access;
|
|
9
|
+
const platform = request.nextUrl.searchParams.get("platform");
|
|
10
|
+
if (platform !== "android" && platform !== "ios")
|
|
11
|
+
return NextResponse.json({ error: "Invalid platform" }, { status: 400 });
|
|
12
|
+
const deviceId = request.nextUrl.searchParams.get("deviceId");
|
|
13
|
+
if (deviceId !== null) {
|
|
14
|
+
if (!deviceIdPattern.test(deviceId))
|
|
15
|
+
return NextResponse.json({ error: "Invalid device ID" }, { status: 400 });
|
|
16
|
+
const { data, error } = await supabase
|
|
17
|
+
.from("ota_named_devices")
|
|
18
|
+
.select("device_id,name")
|
|
19
|
+
.eq("device_id", deviceId)
|
|
20
|
+
.maybeSingle();
|
|
21
|
+
if (error)
|
|
22
|
+
return NextResponse.json({ error: "Device name unavailable" }, { status: 503 });
|
|
23
|
+
return NextResponse.json(
|
|
24
|
+
{ deviceId, name: data?.name ?? null },
|
|
25
|
+
{ headers: { "Cache-Control": "no-store" } },
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
// Show installations from other runtimes as well: devices can upgrade their binary.
|
|
29
|
+
const [states, names] = await Promise.all([
|
|
30
|
+
supabase
|
|
31
|
+
.from("ota_device_state")
|
|
32
|
+
.select(
|
|
33
|
+
"installation_id,device_id,platform,runtime_version,channel,last_seen_at",
|
|
34
|
+
)
|
|
35
|
+
.eq("platform", platform)
|
|
36
|
+
.order("last_seen_at", { ascending: false })
|
|
37
|
+
.limit(500)
|
|
38
|
+
.execute(),
|
|
39
|
+
supabase.from("ota_named_devices").select("device_id,name").execute(),
|
|
40
|
+
]);
|
|
41
|
+
if (states.error || names.error)
|
|
42
|
+
return NextResponse.json({ error: "Devices unavailable" }, { status: 503 });
|
|
43
|
+
const labels = new Map<string, string>(
|
|
44
|
+
(names.data || []).map((d: { device_id: string; name: string }) => [
|
|
45
|
+
d.device_id,
|
|
46
|
+
d.name,
|
|
47
|
+
]),
|
|
48
|
+
);
|
|
49
|
+
return NextResponse.json(
|
|
50
|
+
{
|
|
51
|
+
devices: (states.data || []).map((d: { device_id: string | null }) => ({
|
|
52
|
+
...d,
|
|
53
|
+
name: d.device_id ? labels.get(d.device_id) || null : null,
|
|
54
|
+
})),
|
|
55
|
+
},
|
|
56
|
+
{ headers: { "Cache-Control": "no-store" } },
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
export async function PUT(request: NextRequest) {
|
|
60
|
+
const access = await requireAdminSession(request, ["admin", "operator"]);
|
|
61
|
+
if (access instanceof NextResponse) return access;
|
|
62
|
+
let body;
|
|
63
|
+
try {
|
|
64
|
+
body = await request.json();
|
|
65
|
+
} catch {
|
|
66
|
+
return NextResponse.json({ error: "Invalid JSON" }, { status: 400 });
|
|
67
|
+
}
|
|
68
|
+
if (
|
|
69
|
+
typeof body?.deviceId !== "string" ||
|
|
70
|
+
!deviceIdPattern.test(body.deviceId) ||
|
|
71
|
+
typeof body.name !== "string" ||
|
|
72
|
+
body.name.trim() !== body.name ||
|
|
73
|
+
body.name.length < 1 ||
|
|
74
|
+
body.name.length > 80 ||
|
|
75
|
+
/[\x00-\x1f\x7f]/.test(body.name)
|
|
76
|
+
)
|
|
77
|
+
return NextResponse.json({ error: "Invalid device name" }, { status: 400 });
|
|
78
|
+
const { error } = await supabase
|
|
79
|
+
.from("ota_named_devices")
|
|
80
|
+
.upsert(
|
|
81
|
+
{ device_id: body.deviceId, name: body.name },
|
|
82
|
+
{ onConflict: "device_id" },
|
|
83
|
+
)
|
|
84
|
+
.execute();
|
|
85
|
+
if (error)
|
|
86
|
+
return NextResponse.json(
|
|
87
|
+
{ error: "Failed to name device" },
|
|
88
|
+
{ status: 503 },
|
|
89
|
+
);
|
|
90
|
+
return NextResponse.json({ ok: true });
|
|
91
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
3
|
+
const mocks = vi.hoisted(() => ({ session: vi.fn(), rpc: vi.fn() }));
|
|
4
|
+
vi.mock('@/src/server/lib/admin-api', () => ({ requireAdminSession: mocks.session }));
|
|
5
|
+
vi.mock('@/src/server/lib/supabase.js', () => ({ supabase: { rpc: mocks.rpc } }));
|
|
6
|
+
import { GET } from './route';
|
|
7
|
+
describe('installation report authorization', () => {
|
|
8
|
+
beforeEach(() => { vi.clearAllMocks(); mocks.session.mockResolvedValue({ role: 'viewer' }); mocks.rpc.mockResolvedValue({ data: [{ report: { total: 0, devices: [], versions: [] } }] }); });
|
|
9
|
+
it('requires an admin session before accessing installation IDs', async () => {
|
|
10
|
+
mocks.session.mockResolvedValue(NextResponse.json({ error: 'Unauthorized' }, { status: 401 }));
|
|
11
|
+
expect((await GET(new NextRequest('http://test/api/admin/devices'))).status).toBe(401);
|
|
12
|
+
expect(mocks.rpc).not.toHaveBeenCalled();
|
|
13
|
+
});
|
|
14
|
+
it('does not use a publisher bearer token instead of the required session', async () => {
|
|
15
|
+
mocks.session.mockResolvedValue(NextResponse.json({ error: 'Unauthorized' }, { status: 401 }));
|
|
16
|
+
const request = new NextRequest('http://test/api/admin/devices?launchKind=ota&search=abc123', {
|
|
17
|
+
headers: { Authorization: 'Bearer publisher-token' },
|
|
18
|
+
});
|
|
19
|
+
expect((await GET(request)).status).toBe(401);
|
|
20
|
+
expect(mocks.session).toHaveBeenCalledWith(request, ['admin', 'operator', 'viewer']);
|
|
21
|
+
expect(mocks.rpc).not.toHaveBeenCalled();
|
|
22
|
+
});
|
|
23
|
+
it('serves a fresh scoped report to viewers', async () => {
|
|
24
|
+
const response = await GET(new NextRequest('http://test/api/admin/devices?days=30&platform=android&channel=production&runtime=1.0&launchKind=embedded&search=ABC123&offset=50'));
|
|
25
|
+
expect(response.status).toBe(200); expect(response.headers.get('cache-control')).toBe('no-store');
|
|
26
|
+
expect(mocks.rpc).toHaveBeenCalledWith('ota_devices_report_v2', { p_days: 30, p_platform: 'android', p_channel: 'production', p_runtime: '1.0', p_offset: 50, p_launch_kind: 'embedded', p_search: 'abc123' });
|
|
27
|
+
});
|
|
28
|
+
it.each(['days=-1', 'launchKind=invalid', 'launchKind=ota&launchKind=embedded', 'search=%25'])('rejects malformed filters without querying the DB: %s', async (query) => {
|
|
29
|
+
expect((await GET(new NextRequest(`http://test/api/admin/devices?${query}`))).status).toBe(400);
|
|
30
|
+
expect(mocks.rpc).not.toHaveBeenCalled();
|
|
31
|
+
});
|
|
32
|
+
it('returns a generic unavailable response when analytics storage fails', async () => {
|
|
33
|
+
mocks.rpc.mockResolvedValue({ error: { message: 'internal database details' } });
|
|
34
|
+
const log = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
35
|
+
try {
|
|
36
|
+
const response = await GET(new NextRequest('http://test/api/admin/devices'));
|
|
37
|
+
expect(response.status).toBe(503);
|
|
38
|
+
expect(await response.json()).toEqual({ error: 'Device report unavailable' });
|
|
39
|
+
} finally { log.mockRestore(); }
|
|
40
|
+
});
|
|
41
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { requireAdminSession } from "@/src/server/lib/admin-api";
|
|
2
|
+
import { getDevicesReport, parseDeviceFilters } from "@/src/server/devices/report";
|
|
3
|
+
import { NextRequest, NextResponse } from "next/server";
|
|
4
|
+
export async function GET(request: NextRequest) {
|
|
5
|
+
const session = await requireAdminSession(request, ["admin", "operator", "viewer"]);
|
|
6
|
+
if (session instanceof NextResponse) return session;
|
|
7
|
+
let filters;
|
|
8
|
+
try { filters = parseDeviceFilters(request.nextUrl.searchParams); }
|
|
9
|
+
catch { return NextResponse.json({ error: "Invalid filters" }, { status: 400 }); }
|
|
10
|
+
try { return NextResponse.json(await getDevicesReport(filters), { headers: { "Cache-Control": "no-store" } }); }
|
|
11
|
+
catch (error) {
|
|
12
|
+
console.error("Device report failed", error);
|
|
13
|
+
return NextResponse.json({ error: "Device report unavailable" }, { status: 503 });
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { NextRequest, NextResponse } from "next/server";
|
|
2
|
+
import { requireAdminAccess } from "@/src/server/lib/admin-api";
|
|
3
|
+
import {
|
|
4
|
+
decodeUpdateKey,
|
|
5
|
+
parseUpdateKey,
|
|
6
|
+
} from "@/src/server/lib/admin-updates";
|
|
7
|
+
import { jsonb, supabase } from "@/src/server/lib/supabase.js";
|
|
8
|
+
import { parseAudience } from "@/src/server/devices/audience";
|
|
9
|
+
|
|
10
|
+
type Context = { params: Promise<{ encodedKey: string }> };
|
|
11
|
+
const columns =
|
|
12
|
+
"audience_mode,audience_installation_ids,audience_device_ids,audience_version";
|
|
13
|
+
export async function GET(request: NextRequest, context: Context) {
|
|
14
|
+
const access = await requireAdminAccess(request, "updates:read");
|
|
15
|
+
if (access instanceof NextResponse) return access;
|
|
16
|
+
const { updateId } = parseUpdateKey(
|
|
17
|
+
decodeUpdateKey((await context.params).encodedKey),
|
|
18
|
+
);
|
|
19
|
+
const { data, error } = await supabase
|
|
20
|
+
.from("ota_updates")
|
|
21
|
+
.select(columns)
|
|
22
|
+
.eq("update_id", updateId)
|
|
23
|
+
.maybeSingle();
|
|
24
|
+
if (error)
|
|
25
|
+
return NextResponse.json(
|
|
26
|
+
{ error: "Audience unavailable" },
|
|
27
|
+
{ status: 503 },
|
|
28
|
+
);
|
|
29
|
+
if (!data)
|
|
30
|
+
return NextResponse.json({ error: "Update not found" }, { status: 404 });
|
|
31
|
+
return NextResponse.json(data, { headers: { "Cache-Control": "no-store" } });
|
|
32
|
+
}
|
|
33
|
+
export async function PUT(request: NextRequest, context: Context) {
|
|
34
|
+
const access = await requireAdminAccess(request, "updates:write");
|
|
35
|
+
if (access instanceof NextResponse) return access;
|
|
36
|
+
let audience;
|
|
37
|
+
try {
|
|
38
|
+
audience = parseAudience(await request.json());
|
|
39
|
+
} catch (error) {
|
|
40
|
+
return NextResponse.json(
|
|
41
|
+
{ error: (error as Error).message },
|
|
42
|
+
{ status: 400 },
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
const { updateId } = parseUpdateKey(
|
|
46
|
+
decodeUpdateKey((await context.params).encodedKey),
|
|
47
|
+
);
|
|
48
|
+
const { data, error } = await supabase.rpc("ota_replace_audience", {
|
|
49
|
+
p_update: updateId,
|
|
50
|
+
p_mode: audience.audience_mode,
|
|
51
|
+
p_installations: jsonb(audience.audience_installation_ids),
|
|
52
|
+
p_devices: jsonb(audience.audience_device_ids),
|
|
53
|
+
p_version: audience.audience_version,
|
|
54
|
+
});
|
|
55
|
+
if (error) {
|
|
56
|
+
const conflict = /AUDIENCE_CONFLICT|OTA_DISTRIBUTION_BLOCKED/.test(
|
|
57
|
+
error.message,
|
|
58
|
+
);
|
|
59
|
+
return NextResponse.json(
|
|
60
|
+
{
|
|
61
|
+
error: conflict
|
|
62
|
+
? "Audience changed or distribution blocked. Refresh and try again."
|
|
63
|
+
: "Failed to save audience",
|
|
64
|
+
},
|
|
65
|
+
{ status: conflict ? 409 : 503 },
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
const row = data[0];
|
|
69
|
+
return NextResponse.json({
|
|
70
|
+
audience_mode: row.audience_mode,
|
|
71
|
+
audience_installation_ids: row.audience_installation_ids,
|
|
72
|
+
audience_device_ids: row.audience_device_ids,
|
|
73
|
+
audience_version: row.audience_version,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
@@ -1,26 +1,125 @@
|
|
|
1
1
|
@import "tailwindcss";
|
|
2
|
-
|
|
2
|
+
@import "tw-animate-css";
|
|
3
|
+
@custom-variant dark (&:is(.dark *));
|
|
3
4
|
:root {
|
|
4
|
-
--background: #
|
|
5
|
-
--foreground: #
|
|
5
|
+
--background: #f7f8fa;
|
|
6
|
+
--foreground: #182028;
|
|
7
|
+
--card: #ffffff;
|
|
8
|
+
--card-foreground: #182028;
|
|
9
|
+
--popover: #ffffff;
|
|
10
|
+
--popover-foreground: #182028;
|
|
11
|
+
--primary: #4f46e5;
|
|
12
|
+
--primary-foreground: #ffffff;
|
|
13
|
+
--secondary: #eef0f5;
|
|
14
|
+
--secondary-foreground: #343b48;
|
|
15
|
+
--muted: #f0f2f5;
|
|
16
|
+
--muted-foreground: #626e7c;
|
|
17
|
+
--accent: #eeedff;
|
|
18
|
+
--accent-foreground: #4338ca;
|
|
19
|
+
--destructive: #c52c38;
|
|
20
|
+
--border: #e2e6ec;
|
|
21
|
+
--input: #d4dae3;
|
|
22
|
+
--ring: #6366f1;
|
|
23
|
+
--radius: 0.625rem;
|
|
24
|
+
--chart-1: #4f46e5;
|
|
25
|
+
--chart-2: #059669;
|
|
26
|
+
--chart-3: #d97706;
|
|
27
|
+
--chart-4: #64748b;
|
|
28
|
+
--chart-5: #0891b2;
|
|
29
|
+
--sidebar: #ffffff;
|
|
30
|
+
--sidebar-foreground: #626e7c;
|
|
31
|
+
--sidebar-primary: #4f46e5;
|
|
32
|
+
--sidebar-primary-foreground: #ffffff;
|
|
33
|
+
--sidebar-accent: #eeedff;
|
|
34
|
+
--sidebar-accent-foreground: #4338ca;
|
|
35
|
+
--sidebar-border: #e2e6ec;
|
|
36
|
+
--sidebar-ring: #6366f1;
|
|
37
|
+
}
|
|
38
|
+
.dark {
|
|
39
|
+
--background: #12151b;
|
|
40
|
+
--foreground: #e9edf4;
|
|
41
|
+
--card: #1c212a;
|
|
42
|
+
--card-foreground: #e9edf4;
|
|
43
|
+
--popover: #222833;
|
|
44
|
+
--popover-foreground: #e9edf4;
|
|
45
|
+
--primary: #8673f2;
|
|
46
|
+
--primary-foreground: #12151b;
|
|
47
|
+
--secondary: #333a49;
|
|
48
|
+
--secondary-foreground: #d4dce7;
|
|
49
|
+
--muted: #222833;
|
|
50
|
+
--muted-foreground: #98a4b5;
|
|
51
|
+
--accent: #302c4a;
|
|
52
|
+
--accent-foreground: #c6bffa;
|
|
53
|
+
--destructive: #fb7185;
|
|
54
|
+
--border: #323844;
|
|
55
|
+
--input: #454d5e;
|
|
56
|
+
--ring: #8673f2;
|
|
57
|
+
--chart-1: #a697ff;
|
|
58
|
+
--chart-2: #34d399;
|
|
59
|
+
--chart-3: #fbbf24;
|
|
60
|
+
--chart-4: #94a3b8;
|
|
61
|
+
--chart-5: #22d3ee;
|
|
62
|
+
--sidebar: #181c24;
|
|
63
|
+
--sidebar-foreground: #98a4b5;
|
|
64
|
+
--sidebar-primary: #8673f2;
|
|
65
|
+
--sidebar-primary-foreground: #12151b;
|
|
66
|
+
--sidebar-accent: #302c4a;
|
|
67
|
+
--sidebar-accent-foreground: #c6bffa;
|
|
68
|
+
--sidebar-border: #323844;
|
|
69
|
+
--sidebar-ring: #8673f2;
|
|
6
70
|
}
|
|
7
|
-
|
|
8
71
|
@theme inline {
|
|
9
72
|
--color-background: var(--background);
|
|
10
73
|
--color-foreground: var(--foreground);
|
|
74
|
+
--color-card: var(--card);
|
|
75
|
+
--color-card-foreground: var(--card-foreground);
|
|
76
|
+
--color-popover: var(--popover);
|
|
77
|
+
--color-popover-foreground: var(--popover-foreground);
|
|
78
|
+
--color-primary: var(--primary);
|
|
79
|
+
--color-primary-foreground: var(--primary-foreground);
|
|
80
|
+
--color-secondary: var(--secondary);
|
|
81
|
+
--color-secondary-foreground: var(--secondary-foreground);
|
|
82
|
+
--color-muted: var(--muted);
|
|
83
|
+
--color-muted-foreground: var(--muted-foreground);
|
|
84
|
+
--color-accent: var(--accent);
|
|
85
|
+
--color-accent-foreground: var(--accent-foreground);
|
|
86
|
+
--color-destructive: var(--destructive);
|
|
87
|
+
--color-border: var(--border);
|
|
88
|
+
--color-input: var(--input);
|
|
89
|
+
--color-ring: var(--ring);
|
|
90
|
+
--color-chart-1: var(--chart-1);
|
|
91
|
+
--color-chart-2: var(--chart-2);
|
|
92
|
+
--color-chart-3: var(--chart-3);
|
|
93
|
+
--color-chart-4: var(--chart-4);
|
|
94
|
+
--color-chart-5: var(--chart-5);
|
|
95
|
+
--radius-sm: calc(var(--radius) - 4px);
|
|
96
|
+
--radius-md: calc(var(--radius) - 2px);
|
|
97
|
+
--radius-lg: var(--radius);
|
|
98
|
+
--radius-xl: calc(var(--radius) + 4px);
|
|
99
|
+
--color-sidebar: var(--sidebar);
|
|
100
|
+
--color-sidebar-foreground: var(--sidebar-foreground);
|
|
101
|
+
--color-sidebar-primary: var(--sidebar-primary);
|
|
102
|
+
--color-sidebar-primary-foreground: var(--sidebar-primary-foreground);
|
|
103
|
+
--color-sidebar-accent: var(--sidebar-accent);
|
|
104
|
+
--color-sidebar-accent-foreground: var(--sidebar-accent-foreground);
|
|
105
|
+
--color-sidebar-border: var(--sidebar-border);
|
|
106
|
+
--color-sidebar-ring: var(--sidebar-ring);
|
|
11
107
|
--font-sans: var(--font-geist-sans);
|
|
12
108
|
--font-mono: var(--font-geist-mono);
|
|
13
109
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
110
|
+
@layer base {
|
|
111
|
+
* {
|
|
112
|
+
@apply border-border outline-ring/50;
|
|
113
|
+
}
|
|
114
|
+
body {
|
|
115
|
+
@apply bg-background text-foreground font-sans antialiased;
|
|
116
|
+
}
|
|
117
|
+
button:not(:disabled),
|
|
118
|
+
[role="button"]:not([aria-disabled="true"]) {
|
|
119
|
+
cursor: pointer;
|
|
120
|
+
}
|
|
121
|
+
::selection {
|
|
122
|
+
background: var(--accent);
|
|
123
|
+
color: var(--accent-foreground);
|
|
19
124
|
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
body {
|
|
23
|
-
background: var(--background);
|
|
24
|
-
color: var(--foreground);
|
|
25
|
-
font-family: Arial, Helvetica, sans-serif;
|
|
26
125
|
}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
import { cookies } from "next/headers";
|
|
2
|
+
import { LocaleProvider } from "@/src/client/i18n/provider";
|
|
3
|
+
import { LOCALE_COOKIE, resolveLocale } from "@/src/client/i18n/messages";
|
|
1
4
|
import type { Metadata } from "next";
|
|
2
5
|
import { Geist, Geist_Mono } from "next/font/google";
|
|
3
6
|
import "./globals.css";
|
|
7
|
+
import { ThemeProvider } from "@/components/admin/theme-provider";
|
|
4
8
|
|
|
5
9
|
const geistSans = Geist({
|
|
6
10
|
variable: "--font-geist-sans",
|
|
@@ -14,20 +18,24 @@ const geistMono = Geist_Mono({
|
|
|
14
18
|
|
|
15
19
|
export const metadata: Metadata = {
|
|
16
20
|
title: "OTA Update Admin Panel",
|
|
17
|
-
description:
|
|
21
|
+
description:
|
|
22
|
+
"Manage Expo OTA updates with PostgreSQL and S3-compatible storage",
|
|
18
23
|
};
|
|
19
24
|
|
|
20
|
-
export default function RootLayout({
|
|
25
|
+
export default async function RootLayout({
|
|
21
26
|
children,
|
|
22
27
|
}: Readonly<{
|
|
23
28
|
children: React.ReactNode;
|
|
24
29
|
}>) {
|
|
30
|
+
const locale = resolveLocale((await cookies()).get(LOCALE_COOKIE)?.value);
|
|
25
31
|
return (
|
|
26
|
-
<html lang=
|
|
32
|
+
<html lang={locale} suppressHydrationWarning>
|
|
27
33
|
<body
|
|
28
34
|
className={`${geistSans.variable} ${geistMono.variable} antialiased`}
|
|
29
35
|
>
|
|
30
|
-
{
|
|
36
|
+
<LocaleProvider initialLocale={locale}>
|
|
37
|
+
<ThemeProvider>{children}</ThemeProvider>
|
|
38
|
+
</LocaleProvider>
|
|
31
39
|
</body>
|
|
32
40
|
</html>
|
|
33
41
|
);
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import { LanguageSwitcher } from "@/components/admin/language-switcher";
|
|
3
|
+
import { useI18n } from "@/src/client/i18n/provider";
|
|
2
4
|
|
|
5
|
+
import { Button } from "@/components/ui/button";
|
|
6
|
+
import { Input } from "@/components/ui/input";
|
|
3
7
|
import { adminLogin } from "@/src/client/admin-api";
|
|
4
8
|
import { useRouter } from "next/navigation";
|
|
5
9
|
import { FormEvent, useState } from "react";
|
|
6
10
|
|
|
7
11
|
export default function LoginPage() {
|
|
12
|
+
const { t } = useI18n();
|
|
8
13
|
const router = useRouter();
|
|
9
14
|
const [username, setUsername] = useState("");
|
|
10
15
|
const [password, setPassword] = useState("");
|
|
@@ -27,50 +32,49 @@ export default function LoginPage() {
|
|
|
27
32
|
};
|
|
28
33
|
|
|
29
34
|
return (
|
|
30
|
-
<main className="flex min-h-screen items-center justify-center bg-
|
|
35
|
+
<main className="flex min-h-screen items-center justify-center bg-background px-4">
|
|
36
|
+
<div className="absolute right-4 top-4">
|
|
37
|
+
<LanguageSwitcher />
|
|
38
|
+
</div>
|
|
31
39
|
<form
|
|
32
40
|
onSubmit={handleSubmit}
|
|
33
|
-
className="w-full max-w-md rounded-xl border border-
|
|
41
|
+
className="w-full max-w-md rounded-xl border border-border bg-card p-6 shadow-sm"
|
|
34
42
|
>
|
|
35
43
|
<h1 className="text-2xl font-semibold">OTA Admin</h1>
|
|
36
|
-
<p className="mt-1 text-sm text-
|
|
37
|
-
Вход в панель управления обновлениями
|
|
44
|
+
<p className="mt-1 text-sm text-muted-foreground">
|
|
45
|
+
{t("Вход в панель управления обновлениями")}
|
|
38
46
|
</p>
|
|
39
47
|
|
|
40
48
|
<div className="mt-6 space-y-4">
|
|
41
49
|
<label className="block">
|
|
42
|
-
<span className="mb-1 block text-sm"
|
|
43
|
-
<
|
|
50
|
+
<span className="mb-1 block text-sm">{t("Логин")}</span>
|
|
51
|
+
<Input
|
|
44
52
|
value={username}
|
|
45
53
|
onChange={(event) => setUsername(event.target.value)}
|
|
46
|
-
|
|
54
|
+
|
|
47
55
|
autoComplete="username"
|
|
48
56
|
required
|
|
49
57
|
/>
|
|
50
58
|
</label>
|
|
51
59
|
|
|
52
60
|
<label className="block">
|
|
53
|
-
<span className="mb-1 block text-sm"
|
|
54
|
-
<
|
|
61
|
+
<span className="mb-1 block text-sm">{t("Пароль")}</span>
|
|
62
|
+
<Input
|
|
55
63
|
type="password"
|
|
56
64
|
value={password}
|
|
57
65
|
onChange={(event) => setPassword(event.target.value)}
|
|
58
|
-
|
|
66
|
+
|
|
59
67
|
autoComplete="current-password"
|
|
60
68
|
required
|
|
61
69
|
/>
|
|
62
70
|
</label>
|
|
63
71
|
</div>
|
|
64
72
|
|
|
65
|
-
{error ? <p className="mt-4 text-sm text-red-600">{error}</p> : null}
|
|
73
|
+
{error ? <p className="mt-4 text-sm text-red-600">{t(error)}</p> : null}
|
|
66
74
|
|
|
67
|
-
<
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
className="mt-6 w-full rounded-md bg-zinc-900 px-4 py-4 text-sm font-medium text-white hover:bg-zinc-700 disabled:cursor-not-allowed disabled:opacity-70 dark:bg-zinc-100 dark:text-zinc-900 dark:hover:bg-zinc-300"
|
|
71
|
-
>
|
|
72
|
-
{loading ? "Вход..." : "Войти"}
|
|
73
|
-
</button>
|
|
75
|
+
<Button type="submit" disabled={loading} className="mt-6 w-full">
|
|
76
|
+
{loading ? t("Вход...") : t("Войти")}
|
|
77
|
+
</Button>
|
|
74
78
|
</form>
|
|
75
79
|
</main>
|
|
76
80
|
);
|