create-expo-updates-server 0.1.6 → 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.
Files changed (139) hide show
  1. package/dist/template/.dockerignore +16 -0
  2. package/dist/template/README.md +51 -660
  3. package/dist/template/app/api/admin/device-targets/route.test.ts +43 -0
  4. package/dist/template/app/api/admin/device-targets/route.ts +91 -0
  5. package/dist/template/app/api/admin/devices/route.test.ts +41 -0
  6. package/dist/template/app/api/admin/devices/route.ts +15 -0
  7. package/dist/template/app/api/admin/updates/[encodedKey]/audience/route.ts +75 -0
  8. package/dist/template/app/api/device-heartbeat/route.ts +2 -0
  9. package/dist/template/app/globals.css +114 -15
  10. package/dist/template/app/layout.tsx +12 -4
  11. package/dist/template/app/login/page.tsx +22 -18
  12. package/dist/template/app/updates/[encodedKey]/page.tsx +112 -88
  13. package/dist/template/app/updates/devices/page.tsx +264 -0
  14. package/dist/template/app/updates/embedded/page.tsx +102 -68
  15. package/dist/template/app/updates/emergency-redirects/page.tsx +144 -111
  16. package/dist/template/app/updates/layout.tsx +6 -1
  17. package/dist/template/app/updates/page.tsx +262 -212
  18. package/dist/template/components/admin/admin-shell.tsx +196 -0
  19. package/dist/template/components/admin/language-switcher.tsx +25 -0
  20. package/dist/template/components/admin/theme-provider.tsx +15 -0
  21. package/dist/template/components/ui/alert.tsx +65 -0
  22. package/dist/template/components/ui/badge.tsx +47 -0
  23. package/dist/template/components/ui/button.tsx +63 -0
  24. package/dist/template/components/ui/card.tsx +91 -0
  25. package/dist/template/components/ui/chart.tsx +373 -0
  26. package/dist/template/components/ui/checkbox.tsx +31 -0
  27. package/dist/template/components/ui/dialog.tsx +158 -0
  28. package/dist/template/components/ui/dropdown-menu.tsx +256 -0
  29. package/dist/template/components/ui/input.tsx +20 -0
  30. package/dist/template/components/ui/label.tsx +23 -0
  31. package/dist/template/components/ui/native-select.tsx +61 -0
  32. package/dist/template/components/ui/popover.tsx +88 -0
  33. package/dist/template/components/ui/scroll-area.tsx +57 -0
  34. package/dist/template/components/ui/select.tsx +189 -0
  35. package/dist/template/components/ui/separator.tsx +27 -0
  36. package/dist/template/components/ui/sheet.tsx +142 -0
  37. package/dist/template/components/ui/sidebar.tsx +736 -0
  38. package/dist/template/components/ui/skeleton.tsx +13 -0
  39. package/dist/template/components/ui/switch.tsx +34 -0
  40. package/dist/template/components/ui/table.tsx +115 -0
  41. package/dist/template/components/ui/tabs.tsx +90 -0
  42. package/dist/template/components/ui/textarea.tsx +17 -0
  43. package/dist/template/components/ui/tooltip.tsx +56 -0
  44. package/dist/template/components.json +22 -0
  45. package/dist/template/docs/admin-ui.md +35 -0
  46. package/dist/template/docs/device-targeting.md +129 -0
  47. package/dist/template/docs/doctor.md +137 -0
  48. package/dist/template/docs/expo-app-setup.md +174 -47
  49. package/dist/template/docs/getting-started.md +105 -146
  50. package/dist/template/docs/getting-started.ru.md +106 -191
  51. package/dist/template/docs/index.md +14 -33
  52. package/dist/template/docs/installation-telemetry.md +233 -0
  53. package/dist/template/docs/migrations/2026-10-16-manifest-identity.sql +89 -0
  54. package/dist/template/docs/migrations/2026-10-19-device-heartbeat.sql +131 -0
  55. package/dist/template/docs/migrations/2026-10-22-device-analytics.sql +264 -0
  56. package/dist/template/docs/migrations/2026-10-22-device-targeting-activation.sql +108 -0
  57. package/dist/template/docs/migrations/2026-10-22-device-targeting.sql +130 -0
  58. package/dist/template/docs/migrations/2026-10-22-device-version-metadata.sql +154 -0
  59. package/dist/template/docs/migrations/schema.sql +868 -6
  60. package/dist/template/docs/npm-installer.md +15 -30
  61. package/dist/template/docs/operations-guide.md +87 -0
  62. package/dist/template/docs/ota-client-lifecycle.md +263 -0
  63. package/dist/template/docs/ota-update-policy.md +36 -2
  64. package/dist/template/docs/supabase-setup.md +4 -0
  65. package/dist/template/hooks/use-mobile.ts +21 -0
  66. package/dist/template/lib/utils.ts +6 -0
  67. package/dist/template/package-lock.json +2325 -101
  68. package/dist/template/package.json +13 -3
  69. package/dist/template/scripts/configure-expo-app.mjs +11 -15
  70. package/dist/template/scripts/doctor.mjs +51 -0
  71. package/dist/template/scripts/ensure-test-bucket.mjs +21 -0
  72. package/dist/template/scripts/lib/device-identity.test.ts +29 -0
  73. package/dist/template/scripts/lib/doctor-probes.mjs +139 -0
  74. package/dist/template/scripts/lib/doctor.mjs +208 -0
  75. package/dist/template/scripts/lib/doctor.test.mjs +262 -0
  76. package/dist/template/scripts/lib/expo-app-configurator.mjs +14 -9
  77. package/dist/template/scripts/lib/expo-app-configurator.test.ts +3 -2
  78. package/dist/template/scripts/lib/ota-client-configurator.mjs +69 -0
  79. package/dist/template/scripts/lib/ota-client-configurator.test.ts +88 -0
  80. package/dist/template/scripts/lib/ota-client.test.ts +55 -0
  81. package/dist/template/scripts/lib/ota-root-hook-patcher.mjs +173 -0
  82. package/dist/template/scripts/lib/ota-root-hook-patcher.test.ts +123 -0
  83. package/dist/template/scripts/lib/ota-update-controller.test.ts +231 -0
  84. package/dist/template/scripts/tests/device-analytics-migrations.mjs +80 -0
  85. package/dist/template/scripts/tests/device-analytics.mjs +126 -0
  86. package/dist/template/scripts/tests/device-heartbeat.mjs +86 -0
  87. package/dist/template/scripts/tests/device-targeting-activation.mjs +111 -0
  88. package/dist/template/scripts/tests/device-targeting.mjs +39 -0
  89. package/dist/template/scripts/tests/device-version-metadata.mjs +31 -0
  90. package/dist/template/scripts/tests/manifest-identity-concurrency.mjs +106 -0
  91. package/dist/template/scripts/tests/manifest-identity.sql +204 -0
  92. package/dist/template/src/client/admin-types.ts +1 -0
  93. package/dist/template/src/client/devices/analytics.tsx +429 -0
  94. package/dist/template/src/client/devices/device-name.tsx +82 -0
  95. package/dist/template/src/client/devices/registry.tsx +399 -0
  96. package/dist/template/src/client/devices/use-devices-report.ts +108 -0
  97. package/dist/template/src/client/devices/version-adoption-chart.tsx +269 -0
  98. package/dist/template/src/client/devices/version-groups.test.ts +57 -0
  99. package/dist/template/src/client/devices/version-groups.ts +101 -0
  100. package/dist/template/src/client/distribution-control.tsx +135 -81
  101. package/dist/template/src/client/guard-action-combobox.tsx +13 -24
  102. package/dist/template/src/client/i18n/en.json +286 -0
  103. package/dist/template/src/client/i18n/messages.test.ts +42 -0
  104. package/dist/template/src/client/i18n/messages.ts +31 -0
  105. package/dist/template/src/client/i18n/provider.tsx +55 -0
  106. package/dist/template/src/client/i18n/use-formatters.ts +38 -0
  107. package/dist/template/src/client/logout-button.tsx +3 -1
  108. package/dist/template/src/client/update-audience-editor.tsx +285 -0
  109. package/dist/template/src/client/update-policy-editor.tsx +53 -41
  110. package/dist/template/src/server/controllers/manifest.test.ts +250 -7
  111. package/dist/template/src/server/controllers/manifest.ts +39 -31
  112. package/dist/template/src/server/devices/audience.test.ts +48 -0
  113. package/dist/template/src/server/devices/audience.ts +86 -0
  114. package/dist/template/src/server/devices/heartbeat.test.ts +39 -0
  115. package/dist/template/src/server/devices/heartbeat.ts +75 -0
  116. package/dist/template/src/server/devices/report-types.ts +114 -0
  117. package/dist/template/src/server/devices/report.test.ts +29 -0
  118. package/dist/template/src/server/devices/report.ts +27 -0
  119. package/dist/template/src/server/lib/admin-audience-activation.test.ts +94 -0
  120. package/dist/template/src/server/lib/admin-updates.ts +32 -168
  121. package/dist/template/src/server/lib/supabase.js +10 -10
  122. package/dist/template/src/server/lib/supabase.test.ts +11 -0
  123. package/dist/template/src/server/manifest/manifest-identity.test.ts +30 -0
  124. package/dist/template/src/server/manifest/manifest-identity.ts +24 -0
  125. package/dist/template/src/server/manifest/manifest-repository.ts +31 -102
  126. package/dist/template/src/server/manifest/manifest-response.ts +1 -1
  127. package/dist/template/templates/expo-app/ota-client/README.md +59 -0
  128. package/dist/template/templates/expo-app/ota-client/controller.js +60 -0
  129. package/dist/template/templates/expo-app/ota-client/device-identity.js +26 -0
  130. package/dist/template/templates/expo-app/ota-client/docs/update-lifecycle.md +52 -0
  131. package/dist/template/templates/expo-app/ota-client/index.d.ts +47 -0
  132. package/dist/template/templates/expo-app/ota-client/index.js +3 -0
  133. package/dist/template/templates/expo-app/ota-client/model/hooks/useOtaUpdates.js +48 -0
  134. package/dist/template/templates/expo-app/ota-client/model/update-controller.js +182 -0
  135. package/dist/template/templates/expo-app/ota-client/runtime.js +112 -0
  136. package/dist/template/templates/expo-app/ota-client/ui/ota-update-gate.js +56 -0
  137. package/dist/template-manifest.json +578 -73
  138. package/lib/cli.mjs +4 -6
  139. package/package.json +1 -1
@@ -0,0 +1,204 @@
1
+ -- Run only in a disposable database after schema.sql and the identity migration:
2
+ -- psql "$OTA_TEST_DATABASE_URL" -v ON_ERROR_STOP=1 -f scripts/tests/manifest-identity.sql
3
+ -- All test fixtures and switch changes are rolled back.
4
+ begin;
5
+
6
+ do $$
7
+ declare
8
+ update_a uuid := gen_random_uuid();
9
+ update_b uuid := gen_random_uuid();
10
+ manifest_id uuid := gen_random_uuid();
11
+ test_scope text := 'manifest-identity-test-' || gen_random_uuid()::text;
12
+ previous_epoch uuid;
13
+ previous_time timestamptz;
14
+ current_channel public.ota_update_channels%rowtype;
15
+ original_mapping public.ota_served_manifest_log%rowtype;
16
+ field_name text;
17
+ replacement text;
18
+ begin
19
+ update public.ota_distribution_control
20
+ set blocked = false, reason = null
21
+ where singleton_id = 1;
22
+
23
+ insert into public.ota_updates (
24
+ update_id, build_id, runtime_version, channel, platform, created_at,
25
+ created_at_path, storage_bucket, storage_base_path, manifest
26
+ )
27
+ values
28
+ (update_a, update_a, test_scope, test_scope, 'android', now() - interval '2 days',
29
+ 'a', 'test', 'a', '{}'),
30
+ (update_b, update_b, test_scope, test_scope, 'android', now() - interval '1 day',
31
+ 'b', 'test', 'b', '{}');
32
+
33
+ insert into public.ota_update_channels (
34
+ runtime_version, channel, platform, latest_update_id
35
+ ) values (test_scope, test_scope, 'android', update_a);
36
+
37
+ update public.ota_updates set is_active = true where update_id = update_a;
38
+ select * into strict current_channel from public.ota_update_channels
39
+ where runtime_version = test_scope;
40
+ previous_epoch := current_channel.served_manifest_id;
41
+ previous_time := current_channel.served_manifest_changed_at;
42
+
43
+ -- A repeated activation must not create a new publication.
44
+ update public.ota_updates set is_active = true where update_id = update_a;
45
+ select * into strict current_channel from public.ota_update_channels
46
+ where runtime_version = test_scope;
47
+ if current_channel.served_manifest_id <> previous_epoch
48
+ or current_channel.served_manifest_changed_at <> previous_time then
49
+ raise exception 'No-op activation rotated the epoch';
50
+ end if;
51
+
52
+ -- Uploading draft B moves latest; A is still the active fallback.
53
+ update public.ota_update_channels set latest_update_id = update_b
54
+ where runtime_version = test_scope;
55
+ select * into strict current_channel from public.ota_update_channels
56
+ where runtime_version = test_scope;
57
+ if current_channel.served_manifest_id = previous_epoch
58
+ or date_trunc('milliseconds', current_channel.served_manifest_changed_at)
59
+ <= date_trunc('milliseconds', previous_time) then
60
+ raise exception 'Draft upload did not advance the epoch';
61
+ end if;
62
+ previous_epoch := current_channel.served_manifest_id;
63
+ previous_time := current_channel.served_manifest_changed_at;
64
+
65
+ update public.ota_updates set is_active = false where update_id = update_a;
66
+ update public.ota_updates set is_active = true where update_id = update_b;
67
+ select * into strict current_channel from public.ota_update_channels
68
+ where runtime_version = test_scope;
69
+ if current_channel.latest_update_id <> update_b
70
+ or current_channel.active_update_id is not null
71
+ or current_channel.served_manifest_id = previous_epoch
72
+ or date_trunc('milliseconds', current_channel.served_manifest_changed_at)
73
+ <= date_trunc('milliseconds', previous_time) then
74
+ raise exception 'Draft activation with unchanged pointers did not advance the epoch';
75
+ end if;
76
+
77
+ -- Clock skew and repeated operations inside one transaction remain monotonic.
78
+ update public.ota_update_channels
79
+ set served_manifest_changed_at = clock_timestamp() + interval '1 day'
80
+ where runtime_version = test_scope;
81
+ select served_manifest_changed_at into previous_time from public.ota_update_channels
82
+ where runtime_version = test_scope;
83
+ update public.ota_update_channels
84
+ set active_update_id = update_a, active_changed_at = clock_timestamp()
85
+ where runtime_version = test_scope;
86
+ select * into strict current_channel from public.ota_update_channels
87
+ where runtime_version = test_scope;
88
+ if date_trunc('milliseconds', current_channel.served_manifest_changed_at)
89
+ <= date_trunc('milliseconds', previous_time) then
90
+ raise exception 'Pointer rotation moved publication time backwards';
91
+ end if;
92
+ previous_epoch := current_channel.served_manifest_id;
93
+ previous_time := current_channel.served_manifest_changed_at;
94
+ update public.ota_update_channels
95
+ set active_changed_at = active_changed_at + interval '1 millisecond'
96
+ where runtime_version = test_scope;
97
+ select * into strict current_channel from public.ota_update_channels
98
+ where runtime_version = test_scope;
99
+ if current_channel.served_manifest_id = previous_epoch
100
+ or date_trunc('milliseconds', current_channel.served_manifest_changed_at)
101
+ <= date_trunc('milliseconds', previous_time) then
102
+ raise exception 'Repeated rollback did not advance identity and time';
103
+ end if;
104
+
105
+ -- The emergency distribution guard still wins; no epoch mutation on failure.
106
+ previous_epoch := current_channel.served_manifest_id;
107
+ previous_time := current_channel.served_manifest_changed_at;
108
+ update public.ota_updates set is_active = false where update_id = update_b;
109
+ update public.ota_distribution_control
110
+ set blocked = true, reason = 'manifest identity test'
111
+ where singleton_id = 1;
112
+ begin
113
+ update public.ota_updates set is_active = true where update_id = update_a;
114
+ raise exception 'Blocked activation unexpectedly succeeded';
115
+ exception when sqlstate 'P0OTA' then
116
+ null;
117
+ end;
118
+ select * into strict current_channel from public.ota_update_channels
119
+ where runtime_version = test_scope;
120
+ if current_channel.served_manifest_id <> previous_epoch
121
+ or current_channel.served_manifest_changed_at <> previous_time then
122
+ raise exception 'Blocked activation changed channel identity';
123
+ end if;
124
+ update public.ota_distribution_control set blocked = false, reason = null
125
+ where singleton_id = 1;
126
+
127
+ insert into public.ota_served_manifest_log (
128
+ served_manifest_id, update_id, runtime_version, channel, platform, reason
129
+ ) values (manifest_id, update_a, test_scope, test_scope, 'android', 'deploy');
130
+ select * into strict original_mapping from public.ota_served_manifest_log
131
+ where served_manifest_id = manifest_id;
132
+
133
+ -- Equivalent retries (including ON CONFLICT) succeed and preserve first-seen.
134
+ insert into public.ota_served_manifest_log (
135
+ served_manifest_id, update_id, runtime_version, channel, platform, reason, created_at
136
+ ) values (manifest_id, update_a, test_scope, test_scope, 'android', 'rollback', now() + interval '1 hour')
137
+ on conflict (served_manifest_id) do update set
138
+ update_id = excluded.update_id, runtime_version = excluded.runtime_version,
139
+ channel = excluded.channel, platform = excluded.platform,
140
+ reason = excluded.reason, created_at = excluded.created_at;
141
+ if (select created_at from public.ota_served_manifest_log where served_manifest_id = manifest_id)
142
+ <> original_mapping.created_at then
143
+ raise exception 'Mapping retry changed the first-recorded time';
144
+ end if;
145
+
146
+ -- A conflicting upsert cannot silently relabel previously served devices.
147
+ begin
148
+ insert into public.ota_served_manifest_log (
149
+ served_manifest_id, update_id, runtime_version, channel, platform
150
+ ) values (manifest_id, update_b, test_scope, test_scope, 'android')
151
+ on conflict (served_manifest_id) do update set update_id = excluded.update_id;
152
+ raise exception 'Conflicting mapping upsert unexpectedly succeeded';
153
+ exception when check_violation then
154
+ if sqlerrm not like 'OTA_MANIFEST_IDENTITY_CONFLICT:%' then raise; end if;
155
+ end;
156
+
157
+ foreach field_name in array array[
158
+ 'served_manifest_id', 'update_id', 'runtime_version', 'channel', 'platform'
159
+ ] loop
160
+ replacement := case field_name
161
+ when 'served_manifest_id' then gen_random_uuid()::text
162
+ when 'update_id' then update_b::text
163
+ when 'platform' then 'ios'
164
+ else 'changed'
165
+ end;
166
+ begin
167
+ execute format(
168
+ 'update public.ota_served_manifest_log set %I = %L where served_manifest_id = %L',
169
+ field_name, replacement, manifest_id
170
+ );
171
+ raise exception 'Changing identity field % unexpectedly succeeded', field_name;
172
+ exception when check_violation then
173
+ if sqlerrm not like 'OTA_MANIFEST_IDENTITY_CONFLICT:%' then raise; end if;
174
+ end;
175
+ end loop;
176
+
177
+ if (select update_id from public.ota_served_manifest_log where served_manifest_id = manifest_id)
178
+ <> update_a then
179
+ raise exception 'Historical mapping was modified';
180
+ end if;
181
+
182
+ -- Direct active inserts also rotate an already existing empty channel.
183
+ insert into public.ota_update_channels (runtime_version, channel, platform)
184
+ values (test_scope, test_scope || '-insert', 'android')
185
+ returning served_manifest_id, served_manifest_changed_at
186
+ into previous_epoch, previous_time;
187
+ insert into public.ota_updates (
188
+ update_id, build_id, runtime_version, channel, platform, created_at,
189
+ created_at_path, storage_bucket, storage_base_path, manifest, is_active
190
+ ) values (
191
+ gen_random_uuid(), gen_random_uuid(), test_scope, test_scope || '-insert',
192
+ 'android', now(), 'insert', 'test', 'insert', '{}', true
193
+ );
194
+ select * into strict current_channel from public.ota_update_channels
195
+ where runtime_version = test_scope and channel = test_scope || '-insert';
196
+ if current_channel.served_manifest_id = previous_epoch
197
+ or date_trunc('milliseconds', current_channel.served_manifest_changed_at)
198
+ <= date_trunc('milliseconds', previous_time) then
199
+ raise exception 'Active insert did not advance an existing channel epoch';
200
+ end if;
201
+ end;
202
+ $$;
203
+
204
+ rollback;
@@ -11,6 +11,7 @@ export type UpdateItem = {
11
11
  updateId: string;
12
12
  createdAt: string;
13
13
  status: "active" | "disabled";
14
+ audienceMode: "all" | "devices";
14
15
  isLatest: boolean;
15
16
  isRollbackActive: boolean;
16
17
  autoDeliveryEnabled: boolean;
@@ -0,0 +1,429 @@
1
+ "use client";
2
+ import { useFormatters } from "@/src/client/i18n/use-formatters";
3
+ import { useI18n } from "@/src/client/i18n/provider";
4
+
5
+ import { Area, AreaChart, CartesianGrid, XAxis, YAxis } from "recharts";
6
+ import {
7
+ ChartContainer,
8
+ ChartTooltip,
9
+ ChartTooltipContent,
10
+ } from "@/components/ui/chart";
11
+ import {
12
+ Card,
13
+ CardContent,
14
+ CardDescription,
15
+ CardHeader,
16
+ CardTitle,
17
+ } from "@/components/ui/card";
18
+ import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
19
+ import {
20
+ Table,
21
+ TableBody,
22
+ TableCell,
23
+ TableHead,
24
+ TableHeader,
25
+ TableRow,
26
+ } from "@/components/ui/table";
27
+ import { VersionAdoptionChart } from "./version-adoption-chart";
28
+ import type { DevicesReport } from "@/src/server/devices/report-types";
29
+ export const percent = (n: number, total: number) =>
30
+ total ? `${Math.round((n / total) * 100)}%` : "—";
31
+ export function useKindNames() {
32
+ const { t } = useI18n();
33
+ return {
34
+ ota: "OTA",
35
+ embedded: "Embedded",
36
+ unknown: t("Не определён"),
37
+ };
38
+ }
39
+ export function Analytics({ report }: { report: DevicesReport }) {
40
+ const { number, date } = useFormatters();
41
+ const { t } = useI18n();
42
+ const { summary: s } = report;
43
+ const kinds = [
44
+ { label: "OTA", value: s.otaInstallations, color: "var(--chart-1)" },
45
+ {
46
+ label: "Embedded",
47
+ value: s.embeddedInstallations,
48
+ color: "var(--chart-2)",
49
+ },
50
+ {
51
+ label: t("Не определён"),
52
+ value: s.unknownInstallations,
53
+ color: "var(--chart-3)",
54
+ },
55
+ ];
56
+ return (
57
+ <>
58
+ <div className="grid gap-4 sm:grid-cols-2 xl:grid-cols-4">
59
+ {[
60
+ {
61
+ label: t("Активные установки"),
62
+ value: number(s.activeInstallations),
63
+ detail: t("Heartbeat за последние {0}", [
64
+ report.filters.days === 1
65
+ ? t("24 часа")
66
+ : t("{0} дней", [report.filters.days]),
67
+ ]),
68
+ },
69
+ {
70
+ label: t("Используют OTA"),
71
+ value: percent(s.otaInstallations, s.activeInstallations),
72
+ detail: t("{0} из {1} установок", [
73
+ number(s.otaInstallations),
74
+ number(s.activeInstallations),
75
+ ]),
76
+ },
77
+ {
78
+ label: t("Встроенная версия"),
79
+ value: number(s.embeddedInstallations),
80
+ detail: t("Сочетаний версий в выборке: {0}", [
81
+ number(s.reportedVersions),
82
+ ]),
83
+ },
84
+ {
85
+ label: t("Аварийный запуск"),
86
+ value: number(s.emergencyInstallations),
87
+ detail: t("Не определён тип запуска: {0}", [
88
+ number(s.unknownInstallations),
89
+ ]),
90
+ },
91
+ ].map((kpi) => (
92
+ <Card key={kpi.label} className="gap-3 py-5 shadow-none">
93
+ <CardHeader className="px-5">
94
+ <CardDescription>{kpi.label}</CardDescription>
95
+ <CardTitle className="text-3xl font-semibold tracking-tight tabular-nums">
96
+ {kpi.value}
97
+ </CardTitle>
98
+ </CardHeader>
99
+ <CardContent className="px-5 text-xs text-muted-foreground">
100
+ {kpi.detail}
101
+ </CardContent>
102
+ </Card>
103
+ ))}
104
+ </div>
105
+ <VersionAdoptionChart report={report} />
106
+ <div className="grid min-w-0 gap-4 xl:grid-cols-[1.25fr_1fr]">
107
+ <Card className="min-w-0 shadow-none">
108
+ <CardHeader>
109
+ <CardTitle>{t("Активность установок")}</CardTitle>
110
+ <CardDescription>
111
+ {t("Уникальные установки с heartbeat за день · UTC")}
112
+ </CardDescription>
113
+ </CardHeader>
114
+ <CardContent>
115
+ <ChartContainer
116
+ config={{
117
+ activeInstallations: {
118
+ label: t("Активные"),
119
+ color: "var(--chart-1)",
120
+ },
121
+ newInstallations: {
122
+ label: t("Новые"),
123
+ color: "var(--chart-2)",
124
+ },
125
+ }}
126
+ className="h-52 w-full"
127
+ aria-label={t("График ежедневных активных и новых установок")}
128
+ >
129
+ <AreaChart
130
+ accessibilityLayer
131
+ data={report.activity}
132
+ margin={{ top: 12, right: 12, left: -24, bottom: 0 }}
133
+ >
134
+ <CartesianGrid vertical={false} />
135
+ <XAxis
136
+ dataKey="date"
137
+ tickFormatter={date}
138
+ axisLine={false}
139
+ tickLine={false}
140
+ tick={{ fill: "var(--muted-foreground)" }}
141
+ minTickGap={24}
142
+ />
143
+ <YAxis
144
+ allowDecimals={false}
145
+ axisLine={false}
146
+ tickLine={false}
147
+ tick={{ fill: "var(--muted-foreground)" }}
148
+ />
149
+ <ChartTooltip
150
+ content={
151
+ <ChartTooltipContent
152
+ labelFormatter={(value) => date(String(value))}
153
+ />
154
+ }
155
+ />
156
+ <Area
157
+ type="linear"
158
+ dataKey="activeInstallations"
159
+ stroke="var(--color-activeInstallations)"
160
+ fill="var(--color-activeInstallations)"
161
+ fillOpacity={0.12}
162
+ strokeWidth={2}
163
+ dot={{ r: 3 }}
164
+ connectNulls={false}
165
+ isAnimationActive={false}
166
+ />
167
+ <Area
168
+ type="linear"
169
+ dataKey="newInstallations"
170
+ stroke="var(--color-newInstallations)"
171
+ fill="var(--color-newInstallations)"
172
+ fillOpacity={0.05}
173
+ strokeWidth={2}
174
+ dot={{ r: 2 }}
175
+ connectNulls={false}
176
+ isAnimationActive={false}
177
+ />
178
+ </AreaChart>
179
+ </ChartContainer>
180
+ <div className="mt-3 flex flex-wrap gap-4 text-xs text-muted-foreground">
181
+ <span>
182
+ <i className="mr-2 inline-block size-2 rounded-full bg-chart-1" />
183
+ {t("Активные")}
184
+ </span>
185
+ <span>
186
+ <i className="mr-2 inline-block size-2 rounded-full bg-chart-2" />
187
+ {t("Новые")}
188
+ </span>
189
+ </div>
190
+ <p className="mt-3 text-xs leading-5 text-muted-foreground">
191
+ {t("Сбор с ")}
192
+ {date(report.coverage.collectionStartedAt)}{" "}
193
+ {t(
194
+ " · Сегодня — неполный день. До начала сбора данных нет; история хранится 90 дней.",
195
+ )}
196
+ </p>
197
+ <details className="mt-3 text-xs text-muted-foreground">
198
+ <summary className="cursor-pointer">
199
+ {t("Показать значения по дням")}
200
+ </summary>
201
+ <Table className="mt-2">
202
+ <TableHeader>
203
+ <TableRow>
204
+ <TableHead>{t("Дата UTC")}</TableHead>
205
+ <TableHead>{t("Активные")}</TableHead>
206
+ <TableHead>{t("Новые")}</TableHead>
207
+ <TableHead>{t("Покрытие")}</TableHead>
208
+ </TableRow>
209
+ </TableHeader>
210
+ <TableBody>
211
+ {report.activity.map((day) => (
212
+ <TableRow key={day.date}>
213
+ <TableCell>{date(day.date)}</TableCell>
214
+ <TableCell>{day.activeInstallations ?? "—"}</TableCell>
215
+ <TableCell>{day.newInstallations ?? "—"}</TableCell>
216
+ <TableCell>
217
+ {day.coverage === "complete"
218
+ ? t("Полный день")
219
+ : day.coverage === "partial"
220
+ ? t("Неполный день")
221
+ : t("Нет данных")}
222
+ </TableCell>
223
+ </TableRow>
224
+ ))}
225
+ </TableBody>
226
+ </Table>
227
+ </details>
228
+ </CardContent>
229
+ </Card>
230
+ <Card className="min-w-0 shadow-none">
231
+ <CardHeader>
232
+ <CardTitle>{t("Тип запуска")}</CardTitle>
233
+ <CardDescription>
234
+ {t("Текущее состояние активных установок")}
235
+ </CardDescription>
236
+ </CardHeader>
237
+ <CardContent className="space-y-5">
238
+ <div
239
+ className="flex h-3 overflow-hidden rounded-full bg-muted"
240
+ role="img"
241
+ aria-label={kinds.map((k) => `${k.label}: ${k.value}`).join(", ")}
242
+ >
243
+ {kinds.map((k) => (
244
+ <div
245
+ key={k.label}
246
+ style={{
247
+ width: s.activeInstallations
248
+ ? `${(k.value / s.activeInstallations) * 100}%`
249
+ : 0,
250
+ background: k.color,
251
+ }}
252
+ />
253
+ ))}
254
+ </div>
255
+ <div className="grid grid-cols-3 gap-2">
256
+ {kinds.map((k) => (
257
+ <div key={k.label}>
258
+ <p className="text-xs text-muted-foreground">
259
+ <i
260
+ className="mr-1.5 inline-block size-2 rounded-full"
261
+ style={{ background: k.color }}
262
+ />
263
+ {k.label}
264
+ </p>
265
+ <p className="mt-1 text-lg font-semibold tabular-nums">
266
+ {number(k.value)}{" "}
267
+ <span className="text-xs font-normal text-muted-foreground">
268
+ {percent(k.value, s.activeInstallations)}
269
+ </span>
270
+ </p>
271
+ </div>
272
+ ))}
273
+ </div>
274
+ {!report.total && (
275
+ <p className="text-sm text-muted-foreground">
276
+ {t("Нет установок с выбранными фильтрами.")}
277
+ </p>
278
+ )}
279
+ </CardContent>
280
+ </Card>
281
+ </div>
282
+ <Card className="min-w-0 shadow-none">
283
+ <CardHeader>
284
+ <CardTitle>{t("Когорты установок")}</CardTitle>
285
+ <CardDescription>
286
+ {t(
287
+ "Группы по неделе первого heartbeat. Одна установка — одна запись, переустановка может создать новую.",
288
+ )}
289
+ </CardDescription>
290
+ </CardHeader>
291
+ <CardContent>
292
+ <Tabs defaultValue="adoption">
293
+ <TabsList className="mb-4">
294
+ <TabsTrigger value="adoption">{t("Текущие версии")}</TabsTrigger>
295
+ <TabsTrigger value="retention">{t("Возвращаемость")}</TabsTrigger>
296
+ </TabsList>
297
+ <TabsContent value="adoption">
298
+ <p className="mb-3 text-xs text-muted-foreground">
299
+ {t(
300
+ "Активные за выбранный период, сгруппированные по неделе первого появления. Проценты внутри каждой когорты.",
301
+ )}
302
+ </p>
303
+ <Table>
304
+ <TableHeader>
305
+ <TableRow>
306
+ <TableHead>{t("Неделя · UTC")}</TableHead>
307
+ <TableHead>{t("Установки")}</TableHead>
308
+ <TableHead>OTA</TableHead>
309
+ <TableHead>Embedded</TableHead>
310
+ <TableHead>{t("Не определён")}</TableHead>
311
+ </TableRow>
312
+ </TableHeader>
313
+ <TableBody>
314
+ {report.adoptionCohorts.map((c) => (
315
+ <TableRow key={c.weekStart}>
316
+ <TableCell className="font-medium">
317
+ {date(c.weekStart)}
318
+ </TableCell>
319
+ <TableCell className="tabular-nums">
320
+ {number(c.installations)}
321
+ </TableCell>
322
+ {[
323
+ c.otaInstallations,
324
+ c.embeddedInstallations,
325
+ c.unknownInstallations,
326
+ ].map((count, i) => (
327
+ <TableCell key={i}>
328
+ <div
329
+ className="rounded-md px-3 py-2 text-center tabular-nums"
330
+ style={{
331
+ background: `color-mix(in srgb, var(--chart-${i + 1}) ${c.installations ? 5 + (count / c.installations) * 20 : 0}%, transparent)`,
332
+ }}
333
+ >
334
+ {percent(count, c.installations)}{" "}
335
+ <span className="ml-1 text-xs text-muted-foreground">
336
+ ({number(count)})
337
+ </span>
338
+ </div>
339
+ </TableCell>
340
+ ))}
341
+ </TableRow>
342
+ ))}
343
+ </TableBody>
344
+ </Table>
345
+ {!report.adoptionCohorts.length && (
346
+ <p className="py-6 text-center text-sm text-muted-foreground">
347
+ {t("Пока нет когорт для этой выборки.")}
348
+ </p>
349
+ )}
350
+ </TabsContent>
351
+ <TabsContent value="retention">
352
+ <p className="mb-3 max-w-4xl text-xs leading-5 text-muted-foreground">
353
+ {t(
354
+ "Новые установки за последние 90 дней после начала сбора. Фильтры платформы, канала, runtime и типа запуска применяются на момент первого heartbeat. D1/D7 — heartbeat ровно через 1/7 дней, даже если версия изменилась. D0 — исходная когорта (100%); для D1 и дальше неполные дни исключены. «—» означает, что день ещё не наблюдался полностью.",
355
+ )}
356
+ </p>
357
+ <Table>
358
+ <TableHeader>
359
+ <TableRow>
360
+ <TableHead>{t("Неделя · UTC")}</TableHead>
361
+ <TableHead>{t("Новые")}</TableHead>
362
+ {[0, 1, 7, 14, 30].map((d) => (
363
+ <TableHead key={d} className="text-center">
364
+ D{d}
365
+ </TableHead>
366
+ ))}
367
+ </TableRow>
368
+ </TableHeader>
369
+ <TableBody>
370
+ {report.cohorts.map((c) => (
371
+ <TableRow key={c.weekStart}>
372
+ <TableCell>{date(c.weekStart)}</TableCell>
373
+ <TableCell>{number(c.installations)}</TableCell>
374
+ {c.cells.map((cell) => (
375
+ <TableCell key={cell.day}>
376
+ <div
377
+ className="rounded-md px-2 py-2 text-center tabular-nums"
378
+ title={
379
+ cell.rate === null
380
+ ? t("Нет полностью наблюдаемых дней")
381
+ : cell.day === 0
382
+ ? t(
383
+ "D0: исходная когорта, включая сегодняшние установки",
384
+ )
385
+ : t(
386
+ "{0} из {1} установок с полностью наблюдаемым днём",
387
+ [
388
+ cell.retainedInstallations,
389
+ cell.eligibleInstallations,
390
+ ],
391
+ )
392
+ }
393
+ style={{
394
+ background:
395
+ cell.rate === null
396
+ ? "var(--muted)"
397
+ : `color-mix(in srgb, var(--chart-1) ${5 + cell.rate * 25}%, transparent)`,
398
+ }}
399
+ >
400
+ {cell.rate === null
401
+ ? "—"
402
+ : `${Math.round(cell.rate * 100)}%`}
403
+ <span className="block text-[10px] text-muted-foreground">
404
+ {cell.rate === null
405
+ ? t("нет данных")
406
+ : `${cell.retainedInstallations}/${cell.eligibleInstallations}`}
407
+ </span>
408
+ </div>
409
+ </TableCell>
410
+ ))}
411
+ </TableRow>
412
+ ))}
413
+ </TableBody>
414
+ </Table>
415
+ {!report.cohorts.length && (
416
+ <p className="py-6 text-center text-sm text-muted-foreground">
417
+ {t(
418
+ "Возвращаемость появится для новых установок после начала сбора",
419
+ )}{" "}
420
+ {date(report.coverage.collectionStartedAt)}.
421
+ </p>
422
+ )}
423
+ </TabsContent>
424
+ </Tabs>
425
+ </CardContent>
426
+ </Card>
427
+ </>
428
+ );
429
+ }