create-expo-updates-server 0.4.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 +4 -9
- 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 +375 -263
- package/dist/template/app/updates/devices/page.tsx +188 -152
- package/dist/template/app/updates/embedded/page.tsx +63 -29
- package/dist/template/app/updates/emergency-redirects/page.tsx +93 -58
- package/dist/template/app/updates/layout.tsx +2 -1
- package/dist/template/app/updates/page.tsx +381 -283
- 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 -101
- package/dist/template/components/admin/confirm-action.tsx +123 -0
- package/dist/template/components/admin/language-switcher.tsx +25 -17
- 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/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/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 +7 -3
- package/dist/template/docs/device-targeting.md +2 -7
- 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/installation-telemetry.md +2 -8
- 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 +8 -6
- package/dist/template/docs/ota-client-lifecycle.md +30 -68
- package/dist/template/docs/ota-update-policy.md +9 -20
- package/dist/template/docs/ru/admin-ui.md +7 -3
- package/dist/template/docs/ru/device-targeting.md +2 -2
- package/dist/template/docs/ru/doctor.md +2 -2
- package/dist/template/docs/ru/expo-app-setup.md +9 -9
- package/dist/template/docs/ru/getting-started.md +3 -3
- package/dist/template/docs/ru/installation-telemetry.md +2 -2
- package/dist/template/docs/ru/npm-installer.md +3 -3
- package/dist/template/docs/ru/operations-guide.md +8 -3
- package/dist/template/docs/ru/ota-client-lifecycle.md +30 -35
- package/dist/template/docs/ru/ota-update-policy.md +9 -7
- package/dist/template/docs/ru/publishing-npm-installer.md +2 -2
- package/dist/template/docs/uk/admin-ui.md +7 -3
- package/dist/template/docs/uk/device-targeting.md +2 -2
- package/dist/template/docs/uk/doctor.md +2 -2
- package/dist/template/docs/uk/expo-app-setup.md +9 -9
- package/dist/template/docs/uk/getting-started.md +3 -3
- package/dist/template/docs/uk/installation-telemetry.md +2 -2
- package/dist/template/docs/uk/npm-installer.md +3 -3
- package/dist/template/docs/uk/operations-guide.md +8 -3
- package/dist/template/docs/uk/ota-client-lifecycle.md +30 -35
- package/dist/template/docs/uk/ota-update-policy.md +9 -7
- package/dist/template/docs/uk/publishing-npm-installer.md +2 -2
- package/dist/template/lib/audience-ids.ts +4 -0
- package/dist/template/package-lock.json +46 -0
- package/dist/template/package.json +3 -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 +168 -231
- package/dist/template/src/client/devices/cohorts.tsx +181 -0
- package/dist/template/src/client/devices/device-name.tsx +37 -23
- package/dist/template/src/client/devices/favorite-targets.tsx +381 -0
- package/dist/template/src/client/devices/registry.tsx +258 -245
- 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 +47 -49
- package/dist/template/src/client/distribution-control.tsx +89 -57
- 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 +133 -239
- package/dist/template/src/client/guard-action-options.ts +4 -6
- package/dist/template/src/client/i18n/en.json +133 -2
- package/dist/template/src/client/i18n/language-switching.test.tsx +12 -3
- package/dist/template/src/client/i18n/ru.json +133 -2
- package/dist/template/src/client/i18n/uk.json +133 -2
- 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 -206
- package/dist/template/src/client/update-policy-editor.test.ts +101 -29
- package/dist/template/src/client/update-policy-editor.tsx +454 -320
- 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 +446 -301
- 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/README.md
CHANGED
|
@@ -4,7 +4,7 @@ Create a standalone, self-hosted Expo Updates Server project from the
|
|
|
4
4
|
versioned template bundled in this npm package.
|
|
5
5
|
|
|
6
6
|
```bash
|
|
7
|
-
npx create-expo-updates-server@
|
|
7
|
+
npx create-expo-updates-server@0.6.0 my-server
|
|
8
8
|
cd my-server
|
|
9
9
|
```
|
|
10
10
|
|
|
@@ -13,7 +13,7 @@ To scaffold into an empty current directory instead:
|
|
|
13
13
|
```bash
|
|
14
14
|
mkdir my-server
|
|
15
15
|
cd my-server
|
|
16
|
-
npx create-expo-updates-server@
|
|
16
|
+
npx create-expo-updates-server@0.6.0 .
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
The initializer performs no network requests, dependency installation, Git
|
|
@@ -29,6 +29,8 @@ Successful output provides numbered Docker and npm paths. When `.` is used,
|
|
|
29
29
|
those steps start directly with configuration or installation instead of
|
|
30
30
|
asking you to change into the directory again.
|
|
31
31
|
|
|
32
|
+
After setting up the server, run `npm ci` and `npm run configure-app` in the server directory. The configurator installs `expo-updates-server-client@0.1.0` and its Expo-compatible native dependencies in your application, initializes the client and mounts its update component in supported roots. Follow the [Expo application setup guide](https://github.com/tonichiga/expo-updates-server/blob/main/docs/expo-app-setup.md).
|
|
33
|
+
|
|
32
34
|
See the
|
|
33
35
|
[installer documentation](https://github.com/tonichiga/expo-updates-server/blob/main/docs/npm-installer.md)
|
|
34
36
|
for Docker and npm setup instructions.
|
package/dist/template/Dockerfile
CHANGED
|
@@ -2,28 +2,27 @@ FROM node:24-alpine AS dependencies
|
|
|
2
2
|
|
|
3
3
|
WORKDIR /app
|
|
4
4
|
COPY package.json package-lock.json ./
|
|
5
|
-
RUN npm ci
|
|
5
|
+
RUN npm ci --no-audit --no-fund && npm cache clean --force
|
|
6
6
|
|
|
7
7
|
FROM node:24-alpine AS production-dependencies
|
|
8
8
|
|
|
9
9
|
WORKDIR /app
|
|
10
10
|
COPY package.json package-lock.json ./
|
|
11
|
-
RUN npm ci --omit=dev
|
|
11
|
+
RUN npm ci --omit=dev --no-audit --no-fund && npm cache clean --force
|
|
12
12
|
|
|
13
13
|
FROM production-dependencies AS storage-init
|
|
14
14
|
COPY scripts/ensure-storage-bucket.mjs ./scripts/ensure-storage-bucket.mjs
|
|
15
15
|
USER node
|
|
16
16
|
ENTRYPOINT ["node", "/app/scripts/ensure-storage-bucket.mjs"]
|
|
17
17
|
|
|
18
|
-
FROM
|
|
18
|
+
FROM dependencies AS builder
|
|
19
19
|
|
|
20
20
|
WORKDIR /app
|
|
21
21
|
ENV NEXT_TELEMETRY_DISABLED=1
|
|
22
|
-
COPY --from=dependencies /app/node_modules ./node_modules
|
|
23
22
|
COPY . .
|
|
24
23
|
RUN npm run build
|
|
25
24
|
|
|
26
|
-
FROM
|
|
25
|
+
FROM production-dependencies AS runner
|
|
27
26
|
|
|
28
27
|
WORKDIR /app
|
|
29
28
|
ENV NODE_ENV=production
|
|
@@ -37,7 +36,6 @@ RUN addgroup --system --gid 1001 nodejs \
|
|
|
37
36
|
COPY --from=builder --chown=nextjs:nodejs /app/public ./public
|
|
38
37
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
|
39
38
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
|
40
|
-
COPY --from=production-dependencies --chown=nextjs:nodejs /app/node_modules ./node_modules
|
|
41
39
|
COPY --from=builder --chown=nextjs:nodejs /app/scripts ./scripts
|
|
42
40
|
COPY --from=builder --chown=nextjs:nodejs /app/package.json ./package.json
|
|
43
41
|
|
package/dist/template/README.md
CHANGED
|
@@ -6,8 +6,7 @@ panel, device targeting and installation analytics.
|
|
|
6
6
|
- Publish inactive updates, review their audience, then activate them.
|
|
7
7
|
- Track running app versions by runtime, channel and platform.
|
|
8
8
|
- Test a release on selected devices before making it available to everyone.
|
|
9
|
-
- Integrate identity, telemetry and manual/automatic updates through
|
|
10
|
-
`useOtaUpdates` hook, including background delivery and required-update policies.
|
|
9
|
+
- Integrate identity, telemetry and manual/automatic updates through the `expo-updates-server-client` package, including background delivery and required-update policies.
|
|
11
10
|
- Run PostgreSQL and S3-compatible storage locally with Docker, or use Supabase.
|
|
12
11
|
|
|
13
12
|
## Start here
|
|
@@ -15,7 +14,7 @@ panel, device targeting and installation analytics.
|
|
|
15
14
|
Create a server project:
|
|
16
15
|
|
|
17
16
|
```bash
|
|
18
|
-
npx create-expo-updates-server@
|
|
17
|
+
npx create-expo-updates-server@0.6.0 my-server
|
|
19
18
|
cd my-server
|
|
20
19
|
```
|
|
21
20
|
|
|
@@ -40,13 +39,9 @@ checkout. For initializer options and filesystem behavior, see
|
|
|
40
39
|
## Application integration
|
|
41
40
|
|
|
42
41
|
Run `npm ci` in the **server directory** before `npm run configure-app`.
|
|
43
|
-
The configurator supports static `app.json` projects
|
|
44
|
-
root hook, publisher and embedded-build registration scripts. See
|
|
45
|
-
[Expo application setup](docs/expo-app-setup.md) for supported roots and flags.
|
|
42
|
+
The configurator supports static `app.json` projects. It installs `expo-updates-server-client@0.1.0` and its native dependencies with `expo install`, writes the public settings to `ota-client/config.json`, and initializes the client before loading your original entry. In supported roots it imports and mounts `<OtaUpdates />` beside navigation. It also installs publisher and embedded-build registration scripts. See [Expo application setup](docs/expo-app-setup.md).
|
|
46
43
|
|
|
47
|
-
|
|
48
|
-
This fallback wires the client; publisher/build registration still require
|
|
49
|
-
separate setup. Expo Go cannot validate the release OTA lifecycle.
|
|
44
|
+
For a custom root or dynamic app configuration, follow [manual client integration](docs/ota-client-lifecycle.md#manual-integration). The guide covers initialization, the built-in component, and the headless hook. Configure publishing and build registration separately for a manual setup. Test the OTA lifecycle in a native release build.
|
|
50
45
|
|
|
51
46
|
## Check your setup
|
|
52
47
|
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { NextRequest, NextResponse } from "next/server";
|
|
2
|
+
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
3
|
+
|
|
4
|
+
const auth = vi.hoisted(() => vi.fn());
|
|
5
|
+
const db = vi.hoisted(() => ({ from: vi.fn(), rpc: vi.fn() }));
|
|
6
|
+
vi.mock("@/src/server/lib/admin-api", () => ({ requireAdminSession: auth }));
|
|
7
|
+
vi.mock("@/src/server/lib/supabase.js", () => ({ supabase: db }));
|
|
8
|
+
import { DELETE, GET, PUT } from "./route";
|
|
9
|
+
|
|
10
|
+
const user = { id: "admin-a", role: "admin" };
|
|
11
|
+
const target = {
|
|
12
|
+
platform: "ios",
|
|
13
|
+
target_kind: "device",
|
|
14
|
+
target_id: "a".repeat(64),
|
|
15
|
+
};
|
|
16
|
+
const payload = { ...target, name: "Personal phone", user_id: "admin-b" };
|
|
17
|
+
const request = (method = "GET", body?: unknown) =>
|
|
18
|
+
new NextRequest(
|
|
19
|
+
"http://test/api/admin/device-favorites?platform=ios&user_id=admin-b",
|
|
20
|
+
{
|
|
21
|
+
method,
|
|
22
|
+
body: body === undefined ? undefined : JSON.stringify(body),
|
|
23
|
+
},
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
describe("personal audience favorites", () => {
|
|
27
|
+
const state = {
|
|
28
|
+
select: vi.fn().mockReturnThis(),
|
|
29
|
+
eq: vi.fn().mockReturnThis(),
|
|
30
|
+
limit: vi.fn().mockReturnThis(),
|
|
31
|
+
maybeSingle: vi.fn(),
|
|
32
|
+
};
|
|
33
|
+
const favorites = {
|
|
34
|
+
delete: vi.fn().mockReturnThis(),
|
|
35
|
+
eq: vi.fn().mockReturnThis(),
|
|
36
|
+
upsert: vi.fn().mockReturnThis(),
|
|
37
|
+
execute: vi.fn(),
|
|
38
|
+
};
|
|
39
|
+
beforeEach(() => {
|
|
40
|
+
vi.clearAllMocks();
|
|
41
|
+
auth.mockResolvedValue(user);
|
|
42
|
+
db.from.mockImplementation((name) =>
|
|
43
|
+
name === "ota_device_state" ? state : favorites,
|
|
44
|
+
);
|
|
45
|
+
state.maybeSingle.mockResolvedValue({
|
|
46
|
+
data: { device_id: target.target_id },
|
|
47
|
+
});
|
|
48
|
+
favorites.execute.mockResolvedValue({ error: null });
|
|
49
|
+
db.rpc.mockResolvedValue({ data: [] });
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("derives owner from the session on every access", async () => {
|
|
53
|
+
const list = await GET(request());
|
|
54
|
+
expect(list.headers.get("cache-control")).toContain("no-store");
|
|
55
|
+
expect(db.rpc).toHaveBeenCalledWith("ota_list_device_favorites", {
|
|
56
|
+
p_user: user.id,
|
|
57
|
+
p_platform: "ios",
|
|
58
|
+
});
|
|
59
|
+
expect((await PUT(request("PUT", payload))).status).toBe(200);
|
|
60
|
+
expect(favorites.upsert).toHaveBeenCalledWith(
|
|
61
|
+
{ ...payload, user_id: user.id },
|
|
62
|
+
{ onConflict: "user_id,platform,target_kind,target_id" },
|
|
63
|
+
);
|
|
64
|
+
expect((await DELETE(request("DELETE", payload))).status).toBe(200);
|
|
65
|
+
expect(favorites.eq.mock.calls).toEqual([
|
|
66
|
+
["user_id", user.id],
|
|
67
|
+
["platform", "ios"],
|
|
68
|
+
["target_kind", "device"],
|
|
69
|
+
["target_id", target.target_id],
|
|
70
|
+
]);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it.each([
|
|
74
|
+
{ platform: "macos" },
|
|
75
|
+
{ target_kind: "other" },
|
|
76
|
+
{ target_kind: "installation" },
|
|
77
|
+
{ target_id: "" },
|
|
78
|
+
{ name: "" },
|
|
79
|
+
{ name: " padded " },
|
|
80
|
+
{ name: "abc\n123" },
|
|
81
|
+
{ name: "x".repeat(81) },
|
|
82
|
+
])("rejects invalid input before querying targets: %j", async (invalid) => {
|
|
83
|
+
expect((await PUT(request("PUT", { ...payload, ...invalid }))).status).toBe(
|
|
84
|
+
400,
|
|
85
|
+
);
|
|
86
|
+
expect(db.from).not.toHaveBeenCalled();
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it("lets registration disappear without losing the ability to remove a favorite", async () => {
|
|
90
|
+
state.maybeSingle.mockResolvedValueOnce({ data: null });
|
|
91
|
+
expect((await PUT(request("PUT", payload))).status).toBe(404);
|
|
92
|
+
expect(favorites.upsert).not.toHaveBeenCalled();
|
|
93
|
+
expect((await DELETE(request("DELETE", target))).status).toBe(200);
|
|
94
|
+
expect(state.maybeSingle).toHaveBeenCalledTimes(1);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it("distinguishes storage errors from missing targets without leaking database details", async () => {
|
|
98
|
+
const internal = { error: { message: "internal detail" } };
|
|
99
|
+
state.maybeSingle.mockResolvedValueOnce(internal);
|
|
100
|
+
db.rpc.mockResolvedValueOnce(internal);
|
|
101
|
+
favorites.execute.mockResolvedValueOnce(internal);
|
|
102
|
+
for (const res of [
|
|
103
|
+
await GET(request()),
|
|
104
|
+
await PUT(request("PUT", payload)),
|
|
105
|
+
await DELETE(request("DELETE", target)),
|
|
106
|
+
]) {
|
|
107
|
+
expect(res.status).toBe(503);
|
|
108
|
+
expect(await res.text()).not.toContain("internal detail");
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
it("requires a signed-in account and rejects viewer mutations before parsing", async () => {
|
|
112
|
+
auth.mockResolvedValueOnce(NextResponse.json({}, { status: 401 }));
|
|
113
|
+
expect((await GET(request())).status).toBe(401);
|
|
114
|
+
auth.mockResolvedValue(NextResponse.json({}, { status: 403 }));
|
|
115
|
+
expect((await PUT(request("PUT", payload))).status).toBe(403);
|
|
116
|
+
expect((await DELETE(request("DELETE", target))).status).toBe(403);
|
|
117
|
+
expect(
|
|
118
|
+
auth.mock.calls
|
|
119
|
+
.slice(1)
|
|
120
|
+
.every(([, roles]) => roles.join() === "admin,operator"),
|
|
121
|
+
).toBe(true);
|
|
122
|
+
expect(db.from).not.toHaveBeenCalled();
|
|
123
|
+
expect(db.rpc).not.toHaveBeenCalled();
|
|
124
|
+
});
|
|
125
|
+
});
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { NextRequest, NextResponse } from "next/server";
|
|
2
|
+
import { requireAdminSession } from "@/src/server/lib/admin-api";
|
|
3
|
+
import {
|
|
4
|
+
deviceIdPattern,
|
|
5
|
+
installationIdPattern,
|
|
6
|
+
} from "@/src/server/devices/audience";
|
|
7
|
+
import { supabase } from "@/src/server/lib/supabase.js";
|
|
8
|
+
|
|
9
|
+
const table = "ota_device_favorites";
|
|
10
|
+
const error = (message: string, status: number) =>
|
|
11
|
+
NextResponse.json({ error: message }, { status });
|
|
12
|
+
const validPlatform = (value: unknown) =>
|
|
13
|
+
value === "android" || value === "ios";
|
|
14
|
+
|
|
15
|
+
export async function GET(request: NextRequest) {
|
|
16
|
+
const user = await requireAdminSession(request);
|
|
17
|
+
if (user instanceof NextResponse) return user;
|
|
18
|
+
const platform = request.nextUrl.searchParams.get("platform");
|
|
19
|
+
if (!validPlatform(platform)) return error("Invalid platform", 400);
|
|
20
|
+
const result = await supabase.rpc("ota_list_device_favorites", {
|
|
21
|
+
p_user: user.id,
|
|
22
|
+
p_platform: platform,
|
|
23
|
+
});
|
|
24
|
+
if (result.error) return error("Favorites unavailable", 503);
|
|
25
|
+
return NextResponse.json(
|
|
26
|
+
{ favorites: result.data },
|
|
27
|
+
{ headers: { "Cache-Control": "private, no-store" } },
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async function mutate(request: NextRequest, remove: boolean) {
|
|
32
|
+
const user = await requireAdminSession(request, ["admin", "operator"]);
|
|
33
|
+
if (user instanceof NextResponse) return user;
|
|
34
|
+
const body = await request.json().catch(() => null);
|
|
35
|
+
const { platform, target_kind: kind, target_id: id, name } = body ?? {};
|
|
36
|
+
if (
|
|
37
|
+
!validPlatform(platform) ||
|
|
38
|
+
(kind !== "device" && kind !== "installation") ||
|
|
39
|
+
typeof id !== "string" ||
|
|
40
|
+
!(kind === "device" ? deviceIdPattern : installationIdPattern).test(id)
|
|
41
|
+
)
|
|
42
|
+
return error("Invalid favorite target", 400);
|
|
43
|
+
if (remove) {
|
|
44
|
+
const result = await supabase
|
|
45
|
+
.from(table)
|
|
46
|
+
.delete()
|
|
47
|
+
.eq("user_id", user.id)
|
|
48
|
+
.eq("platform", platform)
|
|
49
|
+
.eq("target_kind", kind)
|
|
50
|
+
.eq("target_id", id)
|
|
51
|
+
.execute();
|
|
52
|
+
if (result.error) return error("Could not remove favorite", 503);
|
|
53
|
+
} else {
|
|
54
|
+
if (
|
|
55
|
+
typeof name !== "string" ||
|
|
56
|
+
!name.trim() ||
|
|
57
|
+
name !== name.trim() ||
|
|
58
|
+
name.length > 80 ||
|
|
59
|
+
/[\x00-\x1f\x7f]/.test(name)
|
|
60
|
+
)
|
|
61
|
+
return error("Invalid favorite name", 400);
|
|
62
|
+
const column = kind === "device" ? "device_id" : "installation_id";
|
|
63
|
+
const state = await supabase
|
|
64
|
+
.from("ota_device_state")
|
|
65
|
+
.select(column)
|
|
66
|
+
.eq("platform", platform)
|
|
67
|
+
.eq(column, id)
|
|
68
|
+
.limit(1)
|
|
69
|
+
.maybeSingle();
|
|
70
|
+
if (state.error) return error("Favorites unavailable", 503);
|
|
71
|
+
if (!state.data) return error("Target is no longer in the registry", 404);
|
|
72
|
+
const result = await supabase
|
|
73
|
+
.from(table)
|
|
74
|
+
.upsert(
|
|
75
|
+
{
|
|
76
|
+
user_id: user.id,
|
|
77
|
+
platform,
|
|
78
|
+
target_kind: kind,
|
|
79
|
+
target_id: id,
|
|
80
|
+
name,
|
|
81
|
+
},
|
|
82
|
+
{ onConflict: "user_id,platform,target_kind,target_id" },
|
|
83
|
+
)
|
|
84
|
+
.execute();
|
|
85
|
+
if (result.error) return error("Could not save favorite", 503);
|
|
86
|
+
}
|
|
87
|
+
return NextResponse.json({ ok: true });
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export const PUT = (request: NextRequest) => mutate(request, false);
|
|
91
|
+
export const DELETE = (request: NextRequest) => mutate(request, true);
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { NextRequest, NextResponse } from "next/server";
|
|
2
|
+
import { requireAdminAccess } from "@/src/server/lib/admin-api";
|
|
3
|
+
import {
|
|
4
|
+
changeDistribution,
|
|
5
|
+
DistributionHistoryConflictError,
|
|
6
|
+
} from "@/src/server/lib/distribution-history";
|
|
7
|
+
import { OtaDistributionBlockedError } from "@/src/server/lib/distribution-control";
|
|
8
|
+
|
|
9
|
+
export async function POST(request: NextRequest) {
|
|
10
|
+
const principal = await requireAdminAccess(request, "updates:write");
|
|
11
|
+
if (principal instanceof NextResponse) return principal;
|
|
12
|
+
const body = await request.json().catch(() => null);
|
|
13
|
+
if (
|
|
14
|
+
typeof body?.updateId !== "string" ||
|
|
15
|
+
!/^[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i.test(body.updateId) ||
|
|
16
|
+
typeof body.expectedRevision !== "string" ||
|
|
17
|
+
!/^\d{1,20}$/.test(body.expectedRevision)
|
|
18
|
+
) {
|
|
19
|
+
return NextResponse.json(
|
|
20
|
+
{ error: "A release ID and expected revision are required." },
|
|
21
|
+
{ status: 400 },
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
try {
|
|
25
|
+
await changeDistribution(body.updateId, "restore", body.expectedRevision);
|
|
26
|
+
return NextResponse.json({ ok: true });
|
|
27
|
+
} catch (error) {
|
|
28
|
+
if (
|
|
29
|
+
error instanceof DistributionHistoryConflictError ||
|
|
30
|
+
error instanceof OtaDistributionBlockedError
|
|
31
|
+
)
|
|
32
|
+
return NextResponse.json({ error: error.message }, { status: 409 });
|
|
33
|
+
console.error("Failed to restore public release", error);
|
|
34
|
+
return NextResponse.json(
|
|
35
|
+
{ error: "Failed to restore public release." },
|
|
36
|
+
{ status: 500 },
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { NextRequest, NextResponse } from "next/server";
|
|
2
|
+
import { beforeEach, expect, it, vi } from "vitest";
|
|
3
|
+
|
|
4
|
+
const access = vi.hoisted(() => vi.fn());
|
|
5
|
+
const scopes = vi.hoisted(() => vi.fn());
|
|
6
|
+
const change = vi.hoisted(() => vi.fn());
|
|
7
|
+
vi.mock("@/src/server/lib/admin-api", () => ({ requireAdminAccess: access }));
|
|
8
|
+
vi.mock("@/src/server/lib/distribution-history", async (original) => ({
|
|
9
|
+
...(await original<typeof import("@/src/server/lib/distribution-history")>()),
|
|
10
|
+
getDistributionHistory: scopes, changeDistribution: change,
|
|
11
|
+
}));
|
|
12
|
+
|
|
13
|
+
import { DistributionHistoryConflictError } from "@/src/server/lib/distribution-history";
|
|
14
|
+
import { GET } from "./route";
|
|
15
|
+
import { POST } from "./restore/route";
|
|
16
|
+
|
|
17
|
+
const id = "11111111-1111-4111-8111-111111111111";
|
|
18
|
+
const url = "http://localhost/api/admin/distribution-history";
|
|
19
|
+
const post = (body: unknown) => new NextRequest(url + "/restore", { method: "POST", body: JSON.stringify(body) });
|
|
20
|
+
|
|
21
|
+
beforeEach(() => {
|
|
22
|
+
vi.resetAllMocks();
|
|
23
|
+
access.mockResolvedValue({ type: "session", role: "operator" });
|
|
24
|
+
scopes.mockResolvedValue([]);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it.each([
|
|
28
|
+
[{ type: "session", role: "viewer" }, false],
|
|
29
|
+
[{ type: "session", role: "operator" }, true],
|
|
30
|
+
[{ type: "access-token", scopes: ["updates:read"] }, false],
|
|
31
|
+
])("reads history with the principal's write capability", async (principal, canWrite) => {
|
|
32
|
+
access.mockResolvedValue(principal);
|
|
33
|
+
const req = new NextRequest(url);
|
|
34
|
+
expect(await (await GET(req)).json()).toEqual({ canWrite, scopes: [] });
|
|
35
|
+
expect(access).toHaveBeenCalledWith(req, "updates:read");
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("requires write permission before parsing or applying a restore", async () => {
|
|
39
|
+
access.mockResolvedValue(NextResponse.json({}, { status: 403 }));
|
|
40
|
+
const req = post({ updateId: id, expectedRevision: "0" });
|
|
41
|
+
expect((await POST(req)).status).toBe(403);
|
|
42
|
+
expect(access).toHaveBeenCalledWith(req, "updates:write");
|
|
43
|
+
expect(change).not.toHaveBeenCalled();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it.each([{ updateId: id }, { updateId: "invalid", expectedRevision: "17" }])("rejects an invalid restore", async (body) => {
|
|
47
|
+
expect((await POST(post(body))).status).toBe(400);
|
|
48
|
+
expect(change).not.toHaveBeenCalled();
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("passes the observed revision to the database and signals a conflict on stale history", async () => {
|
|
52
|
+
change.mockRejectedValue(new DistributionHistoryConflictError("Refresh."));
|
|
53
|
+
expect((await POST(post({ updateId: id, expectedRevision: "17" }))).status).toBe(409);
|
|
54
|
+
expect(change).toHaveBeenCalledWith(id, "restore", "17");
|
|
55
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { NextRequest, NextResponse } from "next/server";
|
|
2
|
+
import { requireAdminAccess } from "@/src/server/lib/admin-api";
|
|
3
|
+
import { getDistributionHistory } from "@/src/server/lib/distribution-history";
|
|
4
|
+
|
|
5
|
+
export async function GET(request: NextRequest) {
|
|
6
|
+
const principal = await requireAdminAccess(request, "updates:read");
|
|
7
|
+
if (principal instanceof NextResponse) return principal;
|
|
8
|
+
const canWrite =
|
|
9
|
+
principal.type === "session"
|
|
10
|
+
? principal.role !== "viewer"
|
|
11
|
+
: principal.scopes.includes("updates:write");
|
|
12
|
+
try {
|
|
13
|
+
return NextResponse.json({
|
|
14
|
+
canWrite,
|
|
15
|
+
scopes: await getDistributionHistory(),
|
|
16
|
+
});
|
|
17
|
+
} catch (error) {
|
|
18
|
+
console.error("Failed to read public distribution history", error);
|
|
19
|
+
return NextResponse.json(
|
|
20
|
+
{ error: "Failed to read distribution history." },
|
|
21
|
+
{ status: 500 },
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DistributionHistoryConflictError } from "@/src/server/lib/distribution-history";
|
|
1
2
|
import { requireAdminAccess } from "@/src/server/lib/admin-api";
|
|
2
3
|
import {
|
|
3
4
|
decodeUpdateKey,
|
|
@@ -29,7 +30,7 @@ export async function POST(request: NextRequest, context: RouteContext) {
|
|
|
29
30
|
return NextResponse.json(
|
|
30
31
|
{ error: (error as Error).message || "Failed to deactivate update" },
|
|
31
32
|
{
|
|
32
|
-
status: error instanceof OtaDistributionBlockedError ? 409 : 500,
|
|
33
|
+
status: error instanceof OtaDistributionBlockedError || error instanceof DistributionHistoryConflictError ? 409 : 500,
|
|
33
34
|
},
|
|
34
35
|
);
|
|
35
36
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DistributionHistoryConflictError } from "@/src/server/lib/distribution-history";
|
|
1
2
|
import { requireAdminAccess } from "@/src/server/lib/admin-api";
|
|
2
3
|
import {
|
|
3
4
|
decodeUpdateKey,
|
|
@@ -25,7 +26,7 @@ export async function POST(request: NextRequest, context: RouteContext) {
|
|
|
25
26
|
return NextResponse.json(
|
|
26
27
|
{ error: (error as Error).message || "Failed to promote latest update" },
|
|
27
28
|
{
|
|
28
|
-
status: error instanceof OtaDistributionBlockedError ? 409 : 500,
|
|
29
|
+
status: error instanceof OtaDistributionBlockedError || error instanceof DistributionHistoryConflictError ? 409 : 500,
|
|
29
30
|
},
|
|
30
31
|
);
|
|
31
32
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DistributionHistoryConflictError } from "@/src/server/lib/distribution-history";
|
|
1
2
|
import { requireAdminAccess } from "@/src/server/lib/admin-api";
|
|
2
3
|
import {
|
|
3
4
|
decodeUpdateKey,
|
|
@@ -25,7 +26,7 @@ export async function POST(request: NextRequest, context: RouteContext) {
|
|
|
25
26
|
return NextResponse.json(
|
|
26
27
|
{ error: (error as Error).message || "Failed to rollback update" },
|
|
27
28
|
{
|
|
28
|
-
status: error instanceof OtaDistributionBlockedError ? 409 : 500,
|
|
29
|
+
status: error instanceof OtaDistributionBlockedError || error instanceof DistributionHistoryConflictError ? 409 : 500,
|
|
29
30
|
},
|
|
30
31
|
);
|
|
31
32
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DistributionHistoryConflictError } from "@/src/server/lib/distribution-history";
|
|
1
2
|
import { requireAdminAccess } from "@/src/server/lib/admin-api";
|
|
2
3
|
import {
|
|
3
4
|
decodeUpdateKey,
|
|
@@ -92,7 +93,7 @@ export async function PATCH(request: NextRequest, context: RouteContext) {
|
|
|
92
93
|
return NextResponse.json(
|
|
93
94
|
{ error: (error as Error).message || "Failed to update JSON" },
|
|
94
95
|
{
|
|
95
|
-
status: error instanceof OtaDistributionBlockedError ? 409 : 500,
|
|
96
|
+
status: error instanceof OtaDistributionBlockedError || error instanceof DistributionHistoryConflictError ? 409 : 500,
|
|
96
97
|
},
|
|
97
98
|
);
|
|
98
99
|
}
|
|
@@ -96,6 +96,27 @@ describe("GET /api/admin/updates authorization", () => {
|
|
|
96
96
|
expect(getUpdatesPage).toHaveBeenCalledOnce();
|
|
97
97
|
});
|
|
98
98
|
|
|
99
|
+
it("forwards search and release filters to the history query", async () => {
|
|
100
|
+
sessionAuth.result = { id: "viewer", username: "reader", role: "viewer" };
|
|
101
|
+
const { GET } = await import("./route");
|
|
102
|
+
const response = await GET(
|
|
103
|
+
new NextRequest(
|
|
104
|
+
"https://updates.example.com/api/admin/updates?q=2.4&channel=beta&runtime=2&platform=ios&audience=devices&status=draft",
|
|
105
|
+
),
|
|
106
|
+
);
|
|
107
|
+
expect(response.status).toBe(200);
|
|
108
|
+
expect(getUpdatesPage).toHaveBeenCalledWith(
|
|
109
|
+
expect.objectContaining({
|
|
110
|
+
q: "2.4",
|
|
111
|
+
channel: "beta",
|
|
112
|
+
runtime: "2",
|
|
113
|
+
platform: "ios",
|
|
114
|
+
audience: "devices",
|
|
115
|
+
status: "draft",
|
|
116
|
+
}),
|
|
117
|
+
);
|
|
118
|
+
});
|
|
119
|
+
|
|
99
120
|
it("returns the app version associated with each update", async () => {
|
|
100
121
|
tokenAuth.result = {
|
|
101
122
|
id: "token-id",
|
|
@@ -21,7 +21,18 @@ export async function GET(request: NextRequest) {
|
|
|
21
21
|
const sortBy = normalizeSortBy(searchParams.get("sortBy"));
|
|
22
22
|
const order = normalizeSortOrder(searchParams.get("order"));
|
|
23
23
|
|
|
24
|
-
const result = await getUpdatesPage({
|
|
24
|
+
const result = await getUpdatesPage({
|
|
25
|
+
page,
|
|
26
|
+
pageSize,
|
|
27
|
+
sortBy,
|
|
28
|
+
order,
|
|
29
|
+
q: searchParams.get("q") ?? "",
|
|
30
|
+
platform: searchParams.get("platform") ?? "",
|
|
31
|
+
channel: searchParams.get("channel") ?? "",
|
|
32
|
+
runtime: searchParams.get("runtime") ?? "",
|
|
33
|
+
status: searchParams.get("status") ?? "",
|
|
34
|
+
audience: searchParams.get("audience") ?? "",
|
|
35
|
+
});
|
|
25
36
|
return NextResponse.json(result);
|
|
26
37
|
} catch (error: unknown) {
|
|
27
38
|
return NextResponse.json(
|